          SUBROUTINE (OID,GEN,LDID,LBL.NO,TOL.QTY,UDATA)
** Version# 11.0012[58] - 06/09/2017 - 03:31pm - TSMITH - eclipse
*** V11.0012 Change - Custom Coding . - 06/09/2017 - TSMITH - eclipse
*** V11.0011 Change - Custom Coding . - 01/18/2017 - TSMITH - eclipse
*** V11.001 Change - Custom Coding . - 06/11/2015 - TSMITH - eclipse
*** V11.0009 Change - Custom Coding 12 - 01/16/2015 - TSMITH - eclipse
*** V11.0008 Change - Custom Coding 12 - 01/13/2015 - TSMITH - eclipse
*** V11.0007 Change - Custom Coding . - 02/18/2014 - TSMITH - eclipse
*** V11.0006 Change - Custom Coding . - 10/29/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

          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>,'MCT'):', ':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
          CONVERT "." TO " " IN CUST


          *CONVERT "&" TO "AND" IN CUST
          TODAY = DATE()
          ORD.DATE = OCONV(OCONV(TODAY,'DMA'),'MCT'):' ':FIELD(OCONV(TODAY,'D4/'),'/',2):', ':OCONV(TODAY,'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

          CONVERT "/" TO "-" IN JOB
          CONVERT "&" TO " " IN JOB
          CONVERT " " TO "_" IN JOB

          JOB = TRIM(JOB)

          IF BR = '3' THEN
          HEADER = 'red.pdf'
          END ELSE
          HEADER = 'mech_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'
            IF PROG.CHECK # '1' THEN
          DATA<-1> = 'mode con: cols=80 lines=4'
          END ELSE
          DATA<-1> = 'mode con: cols=80 lines=70'
          END


          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> = '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'

          JOB1 = JOB
          CONVERT "_" TO " " IN JOB1


          *CONVERT "_" TO " " IN JOB
          DIV.CT = TRANS('LEDGER.GPS',OID,37,'X')
          DIVIDES = TRANS('LEDGER.GPS',OID,38,'X')
          FOR DIV.CTR = 1 TO DIV.CT
          DATA<-1> = 'copy x:\':DIVIDER:' c:\pdf\':'"':JOB:'"\divider_':DIV.CTR:'.pdf >nul 2>&1'
          SECTION = 'divider_':DIV.CTR:'.pdf'
          DATA<-1> = 'echo ^<?xml version="1.0" encoding="UTF-8"?^>^<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"^>^<f href="divider_'DIV.CTR:'.pdf"/^>^<fields^> > "':SECTION:'".xfdf'
          DATA<-1> = 'echo ^<field name="<job name>"^>^<value^>':JOB1:'^</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,'MCT'):'^</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^>':DIVIDES<1,1,DIV.CTR>:'^</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 divider_':DIV.CTR:'.pdf fill_form ':'"':SECTION:'"':'.xfdf output divider_':DIVIDES<1,1,DIV.CTR>:'.pdf flatten  >nul 2>&1'
          NEXT DIV.CTR


          DATA<-1> = 'del divider_1.pdf divider_2.pdf divider_3.pdf divider_4.pdf divider_5.pdf divider_6.pdf divider_7.pdf divider_8.pdf divider_9.pdf divider_10.pdf'
          DATA<-1> = 'IF NOT EXIST c:\pdf\batesmaster.exe copy x:\batesmaster.exe c:\pdf'


          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^>':JOB1:'^</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

*-------------------------------------------------------------------------*
          *** Comment Code
          OE.GET.LDID.COMM OID,GEN,,PRD.LIST
          SEC.HEADER = PRD.LIST
          CONVERT "/" TO "-" IN SEC.HEADER

*-------------------------------------------------------------------------*

          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)
*          MECH.TYPE = TRANS('PRICE.LINE',TRANS('PRODUCT',PN,9,'X'),50,'X')
*          IF MECH.TYPE = '' THEN
*          MECH.TYPE = '09-MISC'
*          END
           SECTION  =  RAISE(RAISE(LD(3)<1,1,2>))
          SECTION2 =  RAISE(RAISE(LD(3)<1,1,3>))
          SECTION3 =  RAISE(RAISE(LD(3)<1,1,4>))
          IF SECTION3[1,1]#'*' AND SECTION2[1,1]#"*" THEN
          SECTION  = SECTION
          SECTION := ' ':SECTION2
          SECTION := ' ':SECTION3
          END

          IF SECTION2[1,1]#'*' THEN
          SECTION  = SECTION
          SECTION := ' ':SECTION2
          END



          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




          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 = "00":POSITION
          END ELSE
          IF POSITION > 9 AND POSITION < 100 THEN
          POSITION = "0":POSITION
          END ELSE
          POSITION = POSITION
          END
          END

          MECH.TYPE = TRANS('IMG.XREF',REC.VAL,1,'X')<1,1,1>;
          CONVERT " " TO "_" IN MECH.TYPE

          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'
          *** Testing
          DATA<-1> = 'ren c:\pdf\':'"':JOB:'"\':REC.VAL:'.':TYPE:' "':MECH.TYPE:'" >nul 2>&1'
          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:'_':'mech_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,'MCT'):'^</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:'_mech_divider.pdf'
          DATA<-1> = 'del ':POSITION:'_':FIELD(DIVIDER,'.',1):'_XXX.pdf'
          END

SKIP.LD:  NEXT LDID

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


          DATA<-1> = 'echo ^<field name="Section"^>^<field name="0"^>^<value^>':FIELD(SEC.HEADER,"~",1):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="1"^>^<value^>':FIELD(SEC.HEADER,"~",2):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="2"^>^<value^>':FIELD(SEC.HEADER,"~",3):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="3"^>^<value^>':FIELD(SEC.HEADER,"~",4):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="4"^>^<value^>':FIELD(SEC.HEADER,"~",5):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="5"^>^<value^>':FIELD(SEC.HEADER,"~",6):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="6"^>^<value^>':FIELD(SEC.HEADER,"~",7):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="7"^>^<value^>':FIELD(SEC.HEADER,"~",8):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="8"^>^<value^>':FIELD(SEC.HEADER,"~",9):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="9"^>^<value^>':FIELD(SEC.HEADER,"~",10):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="10"^>^<value^>':FIELD(SEC.HEADER,"~",11):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="11"^>^<value^>':FIELD(SEC.HEADER,"~",12):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="12"^>^<value^>':FIELD(SEC.HEADER,"~",13):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="13"^>^<value^>':FIELD(SEC.HEADER,"~",14):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="14"^>^<value^>':FIELD(SEC.HEADER,"~",15):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="15"^>^<value^>':FIELD(SEC.HEADER,"~",16):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="16"^>^<value^>':FIELD(SEC.HEADER,"~",17):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="17"^>^<value^>':FIELD(SEC.HEADER,"~",18):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="18"^>^<value^>':FIELD(SEC.HEADER,"~",19):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^<field name="19"^>^<value^>':FIELD(SEC.HEADER,"~",20):'^</value^>^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^</field^> >> index.xfdf'
          DATA<-1> = 'echo ^</fields^> >> index.xfdf'
          DATA<-1> = 'echo ^<ids original="0600CF25A82DC9348DF89F5BBDEA4236" modified="C81A900B7C296640A85E76DD78672390"/^> >> index.xfdf'
          DATA<-1> = 'echo ^</xfdf^> >> index.xfdf'
          *DATA<-1> = 'c:\pdf\pdftk toc.pdf fill_form index.xfdf output 000a_toc.pdf'

          DATA<-1> = 'copy x:\':HEADER:' c:\pdf\':'"':JOB:'" >nul 2>&1'

          DATA<-1> = 'c:\pdf\pdftk ':HEADER:' fill_form submittal.xfdf output 000_header.pdf'
          DATA<-1> = 'c:\pdf\pdftk 000_header.pdf output header.pdf flatten >nul 2>&1'


          DATA<-1> = 'del ':HEADER






*-------------------------------------------------------------------------*
          *** Suppress Page Numbering
          IF NO.PAGES = '1' THEN
          GOSUB PAGE.NO
          END ELSE
         * DATA<-1> = 'c:\pdf\batesmaster --inpdf "':OCONV(CUST,'MCT'):'_':JOB:'_incomplete.pdf" --pdfout "':OCONV(CUST,'MCT'):'_':JOB:'_final.pdf" --format="%%d" --origin 4 -xoffset=-40 -yoffset=-775 --seed=2'
          * >nul 2>&1'
          END
*-------------------------------------------------------------------------*







          DATA<-1> = 'del submittal.xfdf >nul 2>&1'
          FILENAME = OCONV(CUST,'MCT'):'_':JOB
          CONVERT " " TO "_" IN FILENAME
          CONVERT "^" TO "" IN FILENAME
          CONVERT "&" TO "" IN FILENAME

          DATA<-1> = 'del *_incomplete.pdf *final.pdf *final2.pdf *toc.pdf 002_smart_solar.pdf toc.pdf *.xfdf bb.jpg 000*.pdf >nul 2>&1'
          DATA<-1> = 'del index.htm *.old'


          DATA<-1> = 'start c:\pdf\':JOB


          DATA<-1> = 'exit'

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

          PRINT DATA<J>
          NEXT J

FINISH:   RETURN
*-------------------------------------------------------------------------*
USERPATH:

          BEGIN CASE
          CASE USER.ID = 'BRANDTB'
          PATH = 'c:\documents and settings\brandtb.GREENSBOROPLUMB\Documents\'
          CASE USER.ID = 'TSMITH'
          PATH = 'c:\users\tsmith.GREENSBOROPLUMB\Documents\'
          END CASE

          RETURN
*-------------------------------------------------------------------------*

PAGE.NO:  DATA<-1> = 'ren "':OCONV(CUST,'MCT'):'_':JOB:'_incomplete.pdf" "':OCONV(CUST,'MCT'):'_':JOB:'_final.pdf" >nul 2>&1'

          RETURN
*-------------------------------------------------------------------------*
!TSMITH~06/09/17~15:31
