@ECHO OFF

rem *******************************************************************************
rem                                 W A R N I N G:                                *
rem                                 W A R N I N G:                                *
rem                                 W A R N I N G:                                *
rem                                 W A R N I N G:                                *
rem ==============================================================================*
rem  DO NOT EXECUTE THIS FILE DIRECTLY FROM THE DOS COMMAND LINE.                 *
rem                                                                               *
rem  DO NOT EXECUTE THIS FILE DIRECTLY FROM THE DOS COMMAND LINE.                 *
rem                                                                               *
rem  Instead, this bat file is meant to be executed by being called from another  *
rem  .bat file.                                                                   *
rem ==============================================================================*

IF .%SPLSTMT-CALLED-SWITCH% == .Y                                  GOTO  CALLED-OKAY
ECHO *******************************************************************************
ECHO *                               W A R N I N G:                                *
ECHO *                               W A R N I N G:                                *
ECHO *                               W A R N I N G:                                *
ECHO *                               W A R N I N G:                                *
ECHO *=============================================================================*
ECHO * DO NOT EXECUTE THIS FILE DIRECTLY FROM THE DOS COMMAND LINE.                *
ECHO *                                                                             *
ECHO * Instead, this bat file is meant to be executed by being called from another *
ECHO * .bat file.                                                                  *
ECHO *                                                                             *
ECHO * On the Command Line, execute a Master Command File                          *
ECHO ==============================================================================*
PAUSE
SET    DOC1-STMT-RC=100
GOTO ENDRUN

:CALLED-OKAY
SET   "SPLSTMT-CALLED-SWITCH=N"
SET    DOC1-STMT-RC=0

rem *******************************************************************************
rem  Platform:      NT                                                            *
rem  Printstream:   PostScript, PDF, AFP                                          *
rem  Application:   SPL Statement Print                                           *
rem ==============================================================================*
rem  Master Command File called by one of the above .bat files to run Sort,       *
rem  DOC1GEN, DOC1PCE, and Copy the DOC1 print files to a printer                 *
rem ==============================================================================*
rem  The Master Command File must set the following symbols prior to calling this *
rem  command file:                                                                *
rem                                                                               *
rem    G E N E R A L   S Y M B O L S                                              *
rem    =============================                                              *
rem      LOGFILE                                                                  *
rem              - Name of a log file to be created by this process               *
rem              - Previous version of file will be replaced                      *
rem              - File will be written to %PRODPATH% directory                   *
rem              - Sample coding:  LOGFILE=SPL-stmt.log                           *
rem      SPLSTMT-CALLED-SWITCH                                                    *
rem              - Must be set to "Y"                                             *
rem              - This process will reset to "N"                                 *
rem              - Used by to insure that this process was invoked by a Master    *
rem                Command File                                                   *
rem      PRODPATH                                                                 *
rem              - Names directory for output files from Sort and DOC1            *
rem              - Sample coding: PRODPATH=C:\Doc1 Production Files               *
rem      WEBPATH                                                                  *
rem              - Needed only for Letter-on-Demand                               *
rem              - Names directory for output PDF                                 *
rem              - Sample coding: WEBPATH=C:\Doc1 Production Files                *
rem      PRODPATH                                                                 *
rem              - Names directory where the Master Log file will be archived     *
rem              - Sample coding: PRODPATH=C:\DOC1\Logfiles                       *
rem      OUTPUTBASENAME                                                           *
rem              - Needed only for Statement-on-Demand                            *
rem              - Filename (w/o extension) of PDF to be created                  *
rem              - Sample value: OUTPUTBASENAME=bwilson_012347890                 *
rem              - This process will create %OUTPUTBASENAME%.pdf in the %WEBPATH% *
rem                directory                                                      *
rem                                                                               *
rem    D O C 1   S Y M B O L S                                                    *
rem    =======================                                                    *
rem      D1HOST                                                                   *
rem              - Names root directory where the DOC1 Generate was installed     *
rem              - Typical value:                                                 *
rem                D1HOST=C:\Program Files\DOC1 Suite\Production Engines          *
rem      D1APPATH                                                                 *
rem              - Names directory containing HIP, RPK, INI, CTL, OPS             *
rem              - Sample coding:                                                 *
rem                D1APPATH=C:\Program Files\DOC1 Suite\Designer\resource\stmt    *
rem      GEN_OPS                                                                  *
rem              - Names DOC1Gen OPS file for Format Statements step              *
rem              - Sample value: GEN_OPS=splstmt-s5-v3.ops                        *
rem              - File must be present in the %D1APPATH% directory               *
rem      GEN_HIP                                                                  *
rem              - Names of DOC1Gen Application Rules                             *
rem              - Sample value: GEN_HIP=splstmt-s5-v3.hip                        *
rem              - File must be present in the %D1APPATH% directory               *
rem      GEN_ETS                                                                  *
rem              - Names Extended Text Substitution file                          *
rem              - Sample value: GEN_ETS=splstmt-s5-v3.ets                        *
rem              - File must be present in the %D1APPATH% directory               *
rem      LETR-PCE-INI                                                             *
rem              - Names DOC1PCE Initialization file                              *
rem              - Sample value: LETR-PCE-INI=splstmt-pce-s5-v3.ini               *
rem              - File must be present in the %D1APPATH% directory               *
rem      LETR-PCE-CTL                                                             *
rem              - Names DOC1PCE Rules file                                       *
rem              - Sample value: LETR-PCE-CTL=splstmt-s5-v1.ctl                   *
rem              - File must be present in the %D1APPATH% directory               *
rem                                                                               *
rem    S P L   S Y M B O L S                                                      *
rem    =====================                                                      *
rem      XTRCTPTH                                                                 *
rem              - Names directory containing SPL Statement Print Extract         *
rem              - Sample coding: XTRCTPTH=C:\SPL\EXTRACT                         *
rem      SPL_UNSORTED_EXTRACT                                                     *
rem              - Names SPL Statement Print Extract                              *
rem              - Typical coding SPL_UNSORTED_EXTRACT=stxtr01.dat                *
rem                                                                               *
rem    P R I N T   S Y M B O L S                                                  *
rem    =========================                                                  *
rem      PADDR-PRTOUT-01                                                          *
rem              - IP Address where Statements in Print File 01 will be printed   *
rem              - Sample coding: PADDR-PRTOUT-01=186.240.132.132                 *
rem      PRINTFILES                                                               *
rem              - May be:  Y or N                                                *
rem              - "N" prevents files from being sent to PADDR printer            *
rem      PSTREAM                                                                  *
rem              - May be AFPDS or PostScript                                     *
rem              - Controls type of print description language for output         *
rem ==============================================================================*
rem    Step 01:  Sort PeopleSoft extract to re-arrange records within document    *
rem    Step 02:  Run DOC1GEN to format documents                                  *
rem    Step 03:  Run DOC1PCE to separate Foreign Addressed Statements             *
rem    Step 04:  Run Code-1 Plus for USA Addressed Statements                     *
rem    Step 05:  Run Sort to group Statements by Template Code                    *
rem    Step 06:  Run DOC1PCE to Add Corrected Addresses to Statements             *
rem    Step 07:  Copy output files to printer                                     *
rem *******************************************************************************

IF    %PSTREAM% == PDF                                             GOTO    SYMCHK-LOGFILE-DELETED
IF    EXIST "%PRODPATH%\%LOGFILE%"                                 DEL "%PRODPATH%\%LOGFILE%"
:SYMCHK-LOGFILE-DELETED

rem *******************************************************************************
rem ** Validate General Symbols (PRODPATH and LOGFILE) before anything can begin  *
rem *******************************************************************************

IF    NOT ".%PRODPATH%" == .                                       GOTO    SYMCHK-PRODPATH-CODED
ECHO No value set for the symbol PRODPATH - Job cannot be run
GOTO  ENDRUN

:SYMCHK-PRODPATH-CODED

IF    EXIST "%PRODPATH%"                                           GOTO    SYMCHK-PRODPATH-PRESENT
ECHO Directory %PRODPATH% not found - Job cannot be run
GOTO  ENDRUN

:SYMCHK-PRODPATH-PRESENT

IF    NOT ".%LOGFILE%" == .                                        GOTO    SYMCHK-LOGFILE-CODED
ECHO No value set for the symbol PRODPATH - Job cannot be run
GOTO  ENDRUN

:SYMCHK-LOGFILE-CODED

IF    EXIST "%PRODPATH%\%LOGFILE%"                                 DEL     "%PRODPATH%\%LOGFILE%"

SET  "RUN-DATE=%DATE%"
SET  "RUN-TIME=%TIME%"

IF    %PSTREAM% == PDF                                             GOTO ECH1
ECHO Begin Print Job for SPL Print
:ECH1
ECHO Begin Print Job for SPL Print                                                                  >> "%PRODPATH%\%LOGFILE%"
ECHO    Run Date = %RUN-DATE%                                                                       >> "%PRODPATH%\%LOGFILE%"
ECHO    Run Time = %RUN-TIME%                                                                       >> "%PRODPATH%\%LOGFILE%"
ECHO "=============================================================================="               >> "%PRODPATH%\%LOGFILE%"
ECHO    Step 01:  Sort PeopleSoft extract to re-arrange records within document    *                >> "%PRODPATH%\%LOGFILE%"
ECHO    Step 02:  Run DOC1GEN to format documents                                  *                >> "%PRODPATH%\%LOGFILE%"
IF %RUN_TYPE% == ONLINE                                            GOTO   DOECHO-DONE
ECHO    Step 03:  Run DOC1PCE to separate Foreign Addressed Statements             *                >> "%PRODPATH%\%LOGFILE%"
ECHO    Step 04:  Run Code-1 Plus for USA Addressed Statements                     *                >> "%PRODPATH%\%LOGFILE%"
ECHO    Step 05:  Run Sort to group Statements by Template Code                    *                >> "%PRODPATH%\%LOGFILE%"
ECHO    Step 06:  Run DOC1PCE to Add Corrected Addresses to Statements             *                >> "%PRODPATH%\%LOGFILE%"
ECHO    Step 07:  Copy output files to printer                                     *                >> "%PRODPATH%\%LOGFILE%"

:DOECHO-DONE
ECHO "=============================================================================="               >> "%PRODPATH%\%LOGFILE%"

ECHO Begin Symbol Validation                                                                        >> "%PRODPATH%\%LOGFILE%"
ECHO      PRODPATH = %PRODPATH%                                                                     >> "%PRODPATH%\%LOGFILE%"
ECHO      LOGFILE = %LOGFILE%                                                                       >> "%PRODPATH%\%LOGFILE%"

SET   FATALERR=N

rem *******************************************************************************
rem ** Validate DOC1 Symbols                                                      *
rem *******************************************************************************

ECHO      D1HOST = %D1HOST%                                                                         >> "%PRODPATH%\%LOGFILE%"

IF    NOT ".%D1HOST%" == .                                         GOTO    SYMCHK-D1HOST-CODED
ECHO No value set for the symbol D1HOST                                                             >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y
GOTO  SYMCHK-D1HOST-DONE

:SYMCHK-D1HOST-CODED
IF    EXIST "%D1HOST%"                                             GOTO    SYMCHK-D1HOST-PRESENT
ECHO Doc1 Generate Directory "%D1HOST%" not found                                                   >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y
GOTO  SYMCHK-D1HOST-DONE

:SYMCHK-D1HOST-PRESENT

IF    EXIST "%D1HOST%\DOC1GEN.exe"                                 GOTO    SYMCHK-DOC1GEN.EXE-PRESENT
ECHO DOC1GEN.EXE not found in directory "%D1HOST%"  
ECHO DOC1GEN.EXE not found in directory "%D1HOST%"                                                  >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y

:SYMCHK-DOC1GEN.EXE-PRESENT

IF    EXIST "%D1HOST%\doc1pce.exe"                                 GOTO    SYMCHK-DOC1PCE.EXE-PRESENT
ECHO DOC1PCE.EXE not found in directory "%D1HOST%"                                                  >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y

:SYMCHK-DOC1PCE.EXE-PRESENT

:SYMCHK-D1HOST-DONE

ECHO      D1APPATH = %D1APPATH%                                                                     >> "%PRODPATH%\%LOGFILE%"

IF    NOT ".%D1APPATH%" == .                                       GOTO    SYMCHK-D1APPATH-CODED
ECHO No value set for the symbol D1APPATH                                                           >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y
GOTO  SYMCHK-D1APPATH-DONE

:SYMCHK-D1APPATH-CODED
IF    EXIST "%D1APPATH%"                                           GOTO    SYMCHK-D1APPATH-PRESENT
ECHO Doc1 Application Directory "%D1APPATH%" not found                                              >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y
GOTO  SYMCHK-D1APPATH-DONE

:SYMCHK-D1APPATH-PRESENT

ECHO Directory content of Doc1 Application Directory follows:                                       >> "%PRODPATH%\%LOGFILE%"
DIR "%D1APPATH%"                                                                                    >> "%PRODPATH%\%LOGFILE%"

ECHO      GEN_OPS = %GEN_OPS%                                                                       >> "%PRODPATH%\%LOGFILE%"

IF    EXIST "%D1APPATH%\%GEN_OPS%"                                GOTO   SYMCHK-GEN_OPS-PRESENT
ECHO DOC1GEN OPS file "%D1APPATH%\%GEN_OPS%" not found 
ECHO DOC1GEN OPS file "%D1APPATH%\%GEN_OPS%" not found                                              >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y

:SYMCHK-GEN_OPS-PRESENT

ECHO      GEN_HIP = %GEN_HIP%                                                                       >> "%PRODPATH%\%LOGFILE%"

IF    EXIST "%D1APPATH%\%GEN_HIP%"                              GOTO   SYMCHK-GEN_HIP-PRESENT
ECHO DOC1GEN Application Rules file "%D1APPATH%\%GEN_HIP%" not found 
ECHO DOC1GEN Application Rules file "%D1APPATH%\%GEN_HIP%" not found                                >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y

:SYMCHK-GEN_HIP-PRESENT

ECHO      GEN_ETS = %GEN_ETS%                                                                       >> "%PRODPATH%\%LOGFILE%"

IF    EXIST "%D1APPATH%\%GEN_ETS%"                            GOTO   SYMCHK-GEN_ETS-PRESENT
ECHO Extended Text Substitution file "%D1APPATH%\%GEN_ETS%" not found
ECHO Extended Text Substitution file "%D1APPATH%\%GEN_ETS%" not found                               >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y

:SYMCHK-GEN_ETS-PRESENT

ECHO      SPLIT_PCE_INI = %SPLIT_PCE_INI%                                                               >> "%PRODPATH%\%LOGFILE%"

IF    EXIST "%D1APPATH%\%SPLIT_PCE_INI%"                           GOTO   SYMCHK-SPLIT_PCE_INI-PRESENT
ECHO DOC1PCE Post Process Initialization file "%D1APPATH%\%SPLIT_PCE_INI%" not found                  >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y

:SYMCHK-SPLIT_PCE_INI-PRESENT

ECHO      SPLIT_PCE_CTL = %SPLIT_PCE_CTL%                                                               >> "%PRODPATH%\%LOGFILE%"

IF    EXIST "%D1APPATH%\%SPLIT_PCE_CTL%"                           GOTO   SYMCHK-SPLIT_PCE_CTL-PRESENT
ECHO DOC1PCE Post Process Rules file "%D1APPATH%\%SPLIT_PCE_CTL%" not found                           >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y

:SYMCHK-SPLIT_PCE_CTL-PRESENT

:SYMCHK-D1APPATH-DONE

rem *******************************************************************************
rem ** Validate SPL Symbols                                                       *
rem *******************************************************************************

ECHO      XTRCTPTH = %XTRCTPTH%                                                                     >> "%PRODPATH%\%LOGFILE%"

IF    NOT ".%XTRCTPTH%" == .                                       GOTO    SYMCHK-XTRCTPTH-CODED
ECHO No value set for the symbol XTRCTPTH                                                           >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y
GOTO  SYMCHK-SPL-DONE

:SYMCHK-XTRCTPTH-CODED
IF    EXIST "%XTRCTPTH%"                                           GOTO    SYMCHK-XTRCTPTH-PRESENT
ECHO SPL Extract Directory "%XTRCTPTH%" not found                                                   >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y
GOTO  SYMCHK-SPL-DONE

:SYMCHK-XTRCTPTH-PRESENT

ECHO      SPL_UNSORTED_EXTRACT = %SPL_UNSORTED_EXTRACT%                                             >> "%PRODPATH%\%LOGFILE%"

IF    NOT ".%SPL_UNSORTED_EXTRACT%" == .                           GOTO    SYMCHK-SPL_UNSORTED_EXTRACT-CODED
ECHO No value set for the symbol SPL_UNSORTED_EXTRACT                                               >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y
GOTO  SYMCHK-SPL_UNSORTED_EXTRACT-DONE

:SYMCHK-SPL_UNSORTED_EXTRACT-CODED
IF    EXIST "%XTRCTPTH%\%SPL_UNSORTED_EXTRACT%"                    GOTO    SYMCHK-SPL_UNSORTED_EXTRACT-DONE
ECHO SPL Extract file not found "%XTRCTPTH%\%SPL_UNSORTED_EXTRACT%"                                 >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y

:SYMCHK-SPL_UNSORTED_EXTRACT-DONE

:SYMCHK-SPL-DONE

rem *******************************************************************************
rem ** Validate Print Symbols                                                     *
rem *******************************************************************************

IF    NOT .%PRINTFILES% == .                                       GOTO    SYMCHK-PRINTFILES-CODED
ECHO No value set for the symbol PRINTFILES                                                         >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y
GOTO  SYMCHK-SKIP-PRINT

:SYMCHK-PRINTFILES-CODED
IF    %PRINTFILES% == Y                                            GOTO    SYMCHK-PRINTFILES-DONE
IF    %PRINTFILES% == N                                            GOTO    SYMCHK-PRINTFILES-DONE

ECHO Invalid value set for PRINTFILES - Must be either Y or N                                       >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y
GOTO  SYMCHK-SKIP-PRINT

:SYMCHK-PRINTFILES-DONE

IF    NOT .%PSTREAM% == .                                          GOTO    SYMCHK-PSTREAMS-CODED
ECHO No value set for the symbol PSTREAM                                                            >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y
GOTO  SSYMCHK-PSTREAM-DONE

:SYMCHK-PSTREAMS-CODED
IF    %PSTREAM% == AFPDS                                           GOTO    SYMCHK-PSTREAM-AFPDS
IF    %PSTREAM% == PostScript                                      GOTO    SYMCHK-PSTREAM-POSTSCRIPT
IF    %PSTREAM% == PDF                                             GOTO    SYMCHK-PSTREAM-PDF
IF    %PSTREAM% == Metacode                                        GOTO    SYMCHK-PSTREAM-METACODE

ECHO Invalid value set for PSTREAM - Must be either AFPDS, Metacode or PostScript                   >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y
GOTO  SYMCHK-PSTREAM-DONE

:SYMCHK-PSTREAM-AFPDS
SET   PRES=240
SET   XLATE=AsciiToAfpds=41
SET   PRINT=AFP
GOTO  SYMCHK-PSTREAM-DONE

:SYMCHK-PSTREAM-POSTSCRIPT
SET   PRES=72
SET   XLATE=AsciiToPostScript=0
SET   PRINT=PS
GOTO  SYMCHK-PSTREAM-DONE

:SYMCHK-PSTREAM-PDF
SET   PRES=72
SET   XLATE=AsciiToPDF=0
SET   PRINT=PDF
GOTO  SYMCHK-PSTREAM-DONE

:SYMCHK-PSTREAM-METACODE

SET   PRES=300
SET   XLATE=AsciiToMetacode=50
SET   PRINT=MET
GOTO  SYMCHK-PSTREAM-DONE

:SYMCHK-PSTREAM-DONE

rem If PRINTFILES=N coded, bypass checking for other Printing parameters

IF    %PRINTFILES% == N                                            GOTO    SYMCHK-SKIP-PRINT

IF    NOT .%PADDR-PRTOUT-01% == .                                  GOTO    SYMCHK-PADDR-PRINT-01-CODED
ECHO No value set for the symbol PADDR-PRTOUT-01                                                    >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y

:SYMCHK-PADDR-PRINT-01-CODED

:SYMCHK-SKIP-PRINT

rem *******************************************************************************
rem ** Validate Bill-on-Demand Symbols - PDF only                                 *
rem *******************************************************************************

IF    %PSTREAM% == PDF                                             GOTO    SYMCHK-LETTER-ON-DEMAND
GOTO  SYMCHK-LETTER-ON-DEMAND-DONE 

:SYMCHK-LETTER-ON-DEMAND

ECHO      WEBPATH = %WEBPATH%                                                                       >> "%PRODPATH%\%LOGFILE%"

IF    NOT ".%WEBPTH%" == .                                         GOTO    SYMCHK-WEBPATH-CODED
ECHO No value set for the symbol WEBPATH                                                            >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y
GOTO  SYMCHK-WEBPATH-DONE

:SYMCHK-WEBPATH-CODED
IF    EXIST "%WEBPATH%"                                            GOTO    SYMCHK-WEBPATH-PRESENT
ECHO OFP-on-Demand Display Directory "%WEBPATH%" not found                                          >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y
GOTO  SYMCHK-WEBPATH-DONE

:SYMCHK-WEBPATH-PRESENT
:SYMCHK-WEBPATH-DONE

ECHO      OUTPUTBASENAME = %OUTPUTBASENAME%                                                         >> "%PRODPATH%\%LOGFILE%"

IF    NOT .%OUTPUTBASENAME% == .                                   GOTO    SYMCHK-OUTPUTBASENAME-CODED
ECHO No value set for the symbol OUTPUTBASENAME                                                       >> "%PRODPATH%\%LOGFILE%"
SET   FATALERR=Y

:SYMCHK-OUTPUTBASENAME-CODED

:SYMCHK-LETTER-ON-DEMAND-DONE 

IF    %FATALERR% == N                                              GOTO    SYMCHK-DONE

IF    %PSTREAM% == PDF                                             GOTO SYMCHK-ECH2
ECHO Fatal Symbol Error Encountered - Process Aborting
:SYMCHK-ECH2
ECHO Fatal Symbol Error Encountered - Process Aborting                                              >> "%PRODPATH%\%LOGFILE%"
ECHO "=============================================================================="               >> "%PRODPATH%\%LOGFILE%"
SET    DOC1-STMT-RC=200
GOTO  ENDRUN

:SYMCHK-DONE
ECHO Symbol Validation Complete                                                                     >> "%PRODPATH%\%LOGFILE%"
ECHO "=============================================================================="               >> "%PRODPATH%\%LOGFILE%"

:DOSORT-DAT

rem *******************************************************************************
rem    Step 01:  Sort SPL extract to re-arrange records within document           *
rem ==============================================================================*
rem  The SPL Statement Print Extract must be sorted to re-arrange records within  *
rem  each Statement.                                                              *
rem ==============================================================================*
rem   Input Files                                                                 *
rem      SPL_UNSORTED_EXTRACT                                                     *
rem              - Name of the Statement data extracted from SPL                  *
rem              - This file must be in the XTRCTPTH directory prior to running   *
rem                this .BAT process                                              *
rem   Output Files                                                                *
rem      SPL_SORTED_EXTRACT                                                       *
rem              - Name of Sorted SPL Extract containing Quote data               *
rem              - This file will be written to the PRODPATH directory            *
rem              - This .BAT process will delete previous versions of this file   *
rem   Configuration Files                                                         *
rem      -- none --                                                               *
rem *******************************************************************************
SET   "SPL_SORTED_EXTRACT=%FNP%stmt-sorted.svd"
SET   "STEP01-DATE=%DATE%"
SET   "STEP01-TIME=%TIME%"

IF    %PSTREAM% == PDF                                             GOTO DOSORT-DAT-ECH1
ECHO Step 01:  Sort SPL Statement Extract
:DOSORT-DAT-ECH1
ECHO Step 01:  Sort SPL Statement Extract                                                           >> "%PRODPATH%\%LOGFILE%"
ECHO           Start on %STEP01-DATE% at %STEP01-TIME%                                              >> "%PRODPATH%\%LOGFILE%"
ECHO           Directories:                                                                         >> "%PRODPATH%\%LOGFILE%"
ECHO              XTRCTPTH = %XTRCTPTH%                                                             >> "%PRODPATH%\%LOGFILE%"
ECHO              PRODPATH = %PRODPATH%                                                             >> "%PRODPATH%\%LOGFILE%"
ECHO           Input Files:                                                                         >> "%PRODPATH%\%LOGFILE%"
ECHO              SPL_UNSORTED_EXTRACT = %SPL_UNSORTED_EXTRACT%                                     >> "%PRODPATH%\%LOGFILE%"
ECHO           Output Files:                                                                        >> "%PRODPATH%\%LOGFILE%"
ECHO              SPL_SORTED_EXTRACT = %SPL_SORTED_EXTRACT%                                         >> "%PRODPATH%\%LOGFILE%"
ECHO           Configuration Files:                                                                 >> "%PRODPATH%\%LOGFILE%"
ECHO               -- none --                                                                       >> "%PRODPATH%\%LOGFILE%"
ECHO           ------------------------------------------------------------------------------------ >> "%PRODPATH%\%LOGFILE%"

rem Delete Step 01 Output File from previous run
IF    EXIST "%PRODPATH%\%SPL_SORTED_EXTRACT%"                      GOTO  DOSORT-DAT-DEL-SORTED-EXTRACT
GOTO DOSORT-DAT-DEL-SORTED-EXTRACT-DONE

:DOSORT-DAT-DEL-SORTED-EXTRACT
ECHO           Deleting Prior Sorted Extract "%PRODPATH%\%SPL_SORTED_EXTRACT%"                      >> "%PRODPATH%\%LOGFILE%"  
DEL "%PRODPATH%\%SPL_SORTED_EXTRACT%"

:DOSORT-DAT-DEL-SORTED-EXTRACT-DONE

ECHO "%SORTPATH%\SORT.EXE" /+5 "%XTRCTPTH%\%SPL_UNSORTED_EXTRACT%" /O "%PRODPATH%\%SPL_SORTED_EXTRACT%" 1>> "%PRODPATH%\%LOGFILE%" 2>"%PRODPATH%\junk.file"
"%SORTPATH%\SORT.EXE" /+5 "%XTRCTPTH%\%SPL_UNSORTED_EXTRACT%" /O "%PRODPATH%\%SPL_SORTED_EXTRACT%" 1>> "%PRODPATH%\%LOGFILE%" 2>"%PRODPATH%\junk.file"

IF %ERRORLEVEL% == 0                                               GOTO  DOSORT-DAT-SORT-OKAY
SET    DOC1-STMT-RC=%ERRORLEVEL%
IF    %PSTREAM% == PDF                                             GOTO  DOSORT-DAT-ECH2
ECHO           Sort Error - Process Halting
:DOSORT-DAT-ECH2
ECHO           Sort Error - Process Halting                                                         >> "%PRODPATH%\%LOGFILE%"
GOTO ENDRUN

:DOSORT-DAT-SORT-OKAY
ECHO Step 01:  DOS Sort Complete - SPL Extract Sorted                                               >> "%PRODPATH%\%LOGFILE%"
ECHO "=============================================================================="               >> "%PRODPATH%\%LOGFILE%"

:DOGEN

rem *******************************************************************************
rem    Step 02:  Format Statements (DOC1GEN)                                      *
rem ==============================================================================*
rem  The DOC1 Generate module (DOC1GEN) applies the DOC1 Application Rules        *
rem  against the Sorted SPL Statement Extract (output from Step 01) to create an  *
rem  Intermediate Print File of Statements.  The Intermediate Print File will be  *
rem  post-processed in Step 05 with corrected addresses added to the Statements.  *
rem ==============================================================================*
rem   Input Files                                                                 *
rem      SPL_SORTED_EXTRACT                                                       *
rem              - Name of Sorted SPL Extract containing QStatementuote data      *
rem              - This file was output into the PRODPATH directory by Step 01    *
rem   Configuration Files                                                         *
rem      GEN_OPS                                                                  *
rem              - Name of the DOC1GEN Initialization File                        *
rem              - This file must be in the D1APPATH directory prior to running   *
rem                this .BAT process                                              *
rem      GEN_HIP                                                                  *
rem              - Name of the compiled set of DOC1GEN Host Rules (.HIP)          *
rem              - This file must be in the D1APPATH directory prior to running   *
rem                this .BAT process                                              *
rem      GEN_ETS                                                                  *
rem              - Name of the Extended Text Substitution File                    *
rem              - This file must be in the D1APPATH directory prior to running   *
rem                this .BAT process                                              *
rem   Output Files                                                                *
rem      GENJRN                                                                   *
rem              - Name of the Journal file containing Address Data               *
rem              - This file will be written to the PRODPATH directory            *
rem              - This .BAT process will delete previous versions of this file   *
rem      GENPRT                                                                   *
rem              - Name of the file containing all formatted Quotes               *
rem              - This file will be written to the PRODPATH directory            *
rem              - This .BAT process will delete previous versions of this file   *
rem *******************************************************************************
SET   "GENJRN=%FNP%stmt-journal.jrn"
SET   "GENPRT=%FNP%stmt-intermediate-print.%PRINT%"
SET   "GENDIJ=%FNP%stmt_e2_journal.dij"
SET   "STEP02-DATE=%DATE%"
SET   "STEP02-TIME=%TIME%"

IF    %PSTREAM% == PDF                                             GOTO DOGEN-ECH1
ECHO Step 02:  Format Statements (DOC1GEN) 
:DOGEN-ECH1
ECHO Step 02:  Format Statements (DOC1GEN)                                                          >> "%PRODPATH%\%LOGFILE%"
ECHO           Start on %STEP02-DATE% at %STEP02-TIME%                                              >> "%PRODPATH%\%LOGFILE%"
ECHO           Directories:                                                                         >> "%PRODPATH%\%LOGFILE%"
ECHO                D1HOST = %D1HOST%                                                               >> "%PRODPATH%\%LOGFILE%"
ECHO              D1APPATH = %D1APPATH%                                                             >> "%PRODPATH%\%LOGFILE%"
ECHO              PRODPATH = %PRODPATH%                                                             >> "%PRODPATH%\%LOGFILE%"
ECHO           Input Files:                                                                         >> "%PRODPATH%\%LOGFILE%"
ECHO              SPL_SORTED_EXTRACT = %SPL_SORTED_EXTRACT%                                         >> "%PRODPATH%\%LOGFILE%"
ECHO           Output Files:                                                                        >> "%PRODPATH%\%LOGFILE%"
ECHO                GENPRT = %GENPRT%                                                               >> "%PRODPATH%\%LOGFILE%"
ECHO                GENJRN = %GENJRN%                                                               >> "%PRODPATH%\%LOGFILE%"
ECHO                GENDIJ = %GENDIJ%                                                               >> "%PRODPATH%\%LOGFILE%"
ECHO           Configuration Files:                                                                 >> "%PRODPATH%\%LOGFILE%"
ECHO               GEN_OPS = %GEN_OPS%                                                              >> "%PRODPATH%\%LOGFILE%"
ECHO               GEN_HIP = %GEN_HIP%                                                              >> "%PRODPATH%\%LOGFILE%"
ECHO               GEN_ETS = %GEN_ETS%                                                              >> "%PRODPATH%\%LOGFILE%"
ECHO              GEN_CNTL = %GEN_CNTL%                                                             >> "%PRODPATH%\%LOGFILE%"
ECHO           ------------------------------------------------------------------------------------ >> "%PRODPATH%\%LOGFILE%"

rem delete DOC1GEN Printstream, Journal, and Logfile
IF    EXIST "%PRODPATH%\%GENPRT%"                                  GOTO  DOGEN-DEL-GENPRT
GOTO DOGEN-DEL-GENPRT-DONE

:DOGEN-DEL-GENPRT
ECHO           Deleting Prior DOC1 Generate Intermediate Printstream "%PRODPATH%\%GENPRT%"          >> "%PRODPATH%\%LOGFILE%"  
DEL "%PRODPATH%\%GENPRT%"

:DOGEN-DEL-GENPRT-DONE

IF    EXIST "%PRODPATH%\%GENJRN%"                                  GOTO  DOGEN-DEL-GENJRN
GOTO DOGEN-DEL-GENJRN-DONE

:DOGEN-DEL-GENJRN
ECHO           Deleting Prior DOC1 Generate Journal "%PRODPATH%\%GENJRN%"                           >> "%PRODPATH%\%LOGFILE%"  
DEL "%PRODPATH%\%GENJRN%"

:DOGEN-DEL-GENJRN-DONE

IF    EXIST "%PRODPATH%\%GENDIJ%"                                  GOTO  DOEMFE-DEL-GENDIJ
GOTO DOEMFE-DEL-GENDIJ-DONE

:DOEMFE-DEL-GENDIJ
ECHO           Deleting Prior DOC1 Generate DIJ "%PRODPATH%\%GENDIJ%"                               >> "%PRODPATH%\%LOGFILE%"  
DEL "%PRODPATH%\%GENDIJ%"

:DOEMFE-DEL-GENDIJ-DONE

IF %RUN_TYPE% == BATCH                                             GOTO   DOGEN
COPY "%D1APPATH%\SPL.BMP" .                                                                            > "%PRODPATH%\junk.file"

:DOGEN

ECHO "%D1HOST%\DOC1GEN" "%D1APPATH%\%GEN_HIP%" ops="%D1APPATH%\%GEN_OPS%" d1appath="%D1APPATH%" indata="%PRODPATH%\%SPL_SORTED_EXTRACT%" genprt="%PRODPATH%\%genprt%" genjrn="%PRODPATH%\%genjrn%" gendij="%PRODPATH%\%gendij%" gen_cntl="%D1APPATH%\%GEN_CNTL%" ets=%GEN_ETS% logoxml=%LOGOXML% >> "%PRODPATH%\%LOGFILE%"
"%D1HOST%\DOC1GEN" "%D1APPATH%\%GEN_HIP%" ops="%D1APPATH%\%GEN_OPS%" d1appath="%D1APPATH%" indata="%PRODPATH%\%SPL_SORTED_EXTRACT%" genprt="%PRODPATH%\%genprt%" genjrn="%PRODPATH%\%genjrn%" gendij="%PRODPATH%\%gendij%" gen_cntl="%D1APPATH%\%GEN_CNTL%" ets=%GEN_ETS% logoxml=%LOGOXML% >> "%PRODPATH%\%LOGFILE%"

IF %ERRORLEVEL% == 0                                               GOTO  DOGEN-OKAY
SET    DOC1-STMT-RC=%ERRORLEVEL%
IF    %PSTREAM% == PDF                                             GOTO DOGEN-ECH2
ECHO           DOC1GEN Error (Format Statements) - Process Halting
:DOGEN-ECH2
ECHO           DOC1GEN Error (Format Statements) - Process Halting                                  >> "%PRODPATH%\%LOGFILE%"
GOTO  ENDRUN

:DOGEN-OKAY
ECHO           DOC1GEN to format Statements completed successfully                                  >> "%PRODPATH%\%LOGFILE%"
ECHO ==============================================================================                 >> "%PRODPATH%\%LOGFILE%"

IF %RUN_TYPE% == ONLINE                                            GOTO   DOFORMAT-PDF-COPY
GOTO  DOFORMAT-DONE

:DOFORMAT-PDF-COPY
echo "-------- Copying PDF %PRODPATH%\%GENPRT% to %outputpath% %outputbasename%.pdf"                >> "%PRODPATH%\%LOGFILE%"
COPY "%PRODPATH%\%GENPRT%" "%outputpath%%outputbasename%.pdf"                                       >> "%PRODPATH%\%LOGFILE%"
echo COPY "%PRODPATH%\%GENPRT%" "%outputpath%%OUTPUTBASENAME%.pdf"                                  >> "%PRODPATH%\%LOGFILE%"
DEL spl.bmp
ECHO "=============================================================================="               >> "%PRODPATH%\%LOGFILE%"
GOTO  DODELETE-CHECK

:DOFORMAT-DONE

:DOSORT-JRN

rem *******************************************************************************
rem    Step 03:  Sort Journal to Group Statements by Print File Number            *
rem ==============================================================================*
rem   Input Files                                                                 *
rem      GENJRN                                                                   *
rem              - Name of the Journal created by Doc1Gen (step 02)               *
rem              - This file must be in the PRODPATH directory prior to running   *
rem                this .BAT process                                              *
rem   Output Files                                                                *
rem      SORTJRN                                                                  *
rem              - Name of Sorted Journal                                         *
rem              - This file will be written to the PRODPATH directory            *
rem              - This .BAT process will delete previous versions of this file   *
rem   Configuration Files                                                         *
rem      -- none --                                                               *
rem *******************************************************************************
SET   "SORTJRN=%FNP%stmt-sorted.jrn"
SET   "STEP03-DATE=%DATE%"
SET   "STEP03-TIME=%TIME%"

ECHO Step 03:  Sort Journal
:DOSORT-JRN-ECH1
ECHO Step 03:  Sort Journal                                                                         >> "%PRODPATH%\%LOGFILE%"
ECHO           Start on %STEP03-DATE% at %STEP03-TIME%                                              >> "%PRODPATH%\%LOGFILE%"
ECHO           Directories:                                                                         >> "%PRODPATH%\%LOGFILE%"
ECHO              PRODPATH = %PRODPATH%                                                             >> "%PRODPATH%\%LOGFILE%"
ECHO           Input Files:                                                                         >> "%PRODPATH%\%LOGFILE%"
ECHO              GENJRN = %GENJRN%                                                                 >> "%PRODPATH%\%LOGFILE%"
ECHO           Output Files:                                                                        >> "%PRODPATH%\%LOGFILE%"
ECHO              SORTJRN = %SORTJRN%                                                               >> "%PRODPATH%\%LOGFILE%"
ECHO           Configuration Files:                                                                 >> "%PRODPATH%\%LOGFILE%"
ECHO               -- none --                                                                       >> "%PRODPATH%\%LOGFILE%"
ECHO           ------------------------------------------------------------------------------------ >> "%PRODPATH%\%LOGFILE%"

rem Delete Step 03 Output File from previous run
IF    EXIST "%PRODPATH%\%SORTJRN%"                      GOTO  DOSORT-JRN-DEL-SORTED-EXTRACT
GOTO DOSORT-JRN-DEL-SORTED-EXTRACT-DONE

:DOSORT-JRN-DEL-SORTED-EXTRACT
ECHO           Deleting Prior Sorted Journal "%PRODPATH%\%SORTJRN%"                                 >> "%PRODPATH%\%LOGFILE%"  
DEL "%PRODPATH%\%SORTJRN%"

:DOSORT-JRN-DEL-SORTED-EXTRACT-DONE

ECHO "%SORTPATH%\SORT.EXE" /+109 "%PRODPATH%\%genjrn%" /O "%PRODPATH%\%SORTJRN%" 1>> "%PRODPATH%\%LOGFILE%" 2>"%PRODPATH%\junk.file"
"%SORTPATH%\SORT.EXE" /+109 "%PRODPATH%\%genjrn%" /O "%PRODPATH%\%SORTJRN%" 1>> "%PRODPATH%\%LOGFILE%" 2>"%PRODPATH%\junk.file"

IF %ERRORLEVEL% == 0                                               GOTO  DOSORT-JRN-SORT-OKAY
SET    DOC1-STMT-RC=%ERRORLEVEL%
IF    %PSTREAM% == PDF                                             GOTO  DOSORT-JRN-ECH2
ECHO           Sort Error - Process Halting
:DOSORT-JRN-ECH2
ECHO           Sort Error - Process Halting                                                         >> "%PRODPATH%\%LOGFILE%"
GOTO ENDRUN

:DOSORT-JRN-SORT-OKAY
ECHO Step 03:  DOS Sort Complete - Journal Sorted                                                   >> "%PRODPATH%\%LOGFILE%"
ECHO "=============================================================================="               >> "%PRODPATH%\%LOGFILE%"

:DOPCE

rem *******************************************************************************
rem    Step 04:  Run DOC1PCE to add corrected addresses to Statements             *
rem ==============================================================================*
rem  This PCE application creates the final print files.                          *
rem ==============================================================================*
rem   Input Files                                                                 *
rem      GENPRT                                                                   *
rem              - Name of the file containing all formatted Statements           *
rem              - This file was output into the PRODPATH directory by Step 02    *
rem      SORTJRN                                                                  *
rem              - Name of the Journal mirroring genprt                           *
rem              - Was sorted in Step 03                                          *
rem              - This file was output into the PRODPATH directory by Step 03    *
rem   Configuration Files                                                         *
rem      POSTP_PCE_INI                                                            *
rem              - Name of the DOC1PCE Initialization File                        *
rem              - This file must be in the D1APPATH directory prior to running   *
rem                this .BAT process                                              *
rem      POSTP_PCE_CTL                                                            *
rem              - Name of the DOC1PCE Rules to create Print Files                *
rem              - This file must be in the D1APPATH directory prior to running   *
rem                this .BAT process                                              *
rem      RPK                                                                      *
rem              - Name of the Printer Resource Pack File                         *
rem              - This file must be in the D1APPATH directory prior to running   *
rem                this .BAT process                                              *
rem   Output Files                                                                *
rem      PRTOUT-01                                                                *
rem              - Name of the formatted Print file containing Statements         *
rem                to be printed together in batch 01                             *
rem              - This file will be written to the PRODPATH directory            *
rem              - This .BAT process will delete previous versions of this file   *
rem      PCELOG                                                                   *
rem              - Name of the file containing messages from the PCE process      *
rem              - This file will be written to the PRODPATH directory            *
rem              - This .BAT process will delete previous versions of this file   *
rem *******************************************************************************

IF    %PSTREAM% == PDF                                             GOTO DOPCE-BYPASS
GOTO  DOPCE-ECHO

:DOPCE-BYPASS
ECHO *******  PSTREAM=PDF Coded - Steps 04 - 05 bypassed                                            >> "%PRODPATH%\%LOGFILE%"
GOTO  PDFTSPL

:DOPCE-ECHO

SET   "STEP04-DATE=%DATE%"
SET   "STEP04-TIME=%TIME%"
SET   "PRTOUT-01=%FNP%stmt-final-print.%PRINT%"
SET   "AUDIT=%FNP%stmt-audit.txt%"
SET   "PCELOG=%FNP%splstmt_postp.log"

IF    %PSTREAM% == PDF                                             GOTO DOPCE-ECH1
ECHO Step 04:  Run DOC1PCE for adding Corrected Addresses to Statements
:DOPCE-ECH1
ECHO Step 04:  Run DOC1PCE for adding Corrected Addresses to Statements                             >> "%PRODPATH%\%LOGFILE%"
ECHO           Start on %STEP04-DATE% at %STEP04-TIME%                                              >> "%PRODPATH%\%LOGFILE%"
ECHO           Directories:                                                                         >> "%PRODPATH%\%LOGFILE%"
ECHO              D1HOST = %D1HOST%                                                                 >> "%PRODPATH%\%LOGFILE%"
ECHO              D1APPATH = %D1APPATH%                                                             >> "%PRODPATH%\%LOGFILE%"
ECHO              PRODPATH = %PRODPATH%                                                             >> "%PRODPATH%\%LOGFILE%"
ECHO           Input Files:                                                                         >> "%PRODPATH%\%LOGFILE%"
ECHO              SORTJRN = %SORTJRN%                                                               >> "%PRODPATH%\%LOGFILE%"
ECHO               GENPRT = %genprt%                                                                >> "%PRODPATH%\%LOGFILE%"
ECHO           Output Files:                                                                        >> "%PRODPATH%\%LOGFILE%"
ECHO              PRTOUT-01 = %PRTOUT-01%                                                           >> "%PRODPATH%\%LOGFILE%"
ECHO                  AUDIT = %AUDIT%                                                               >> "%PRODPATH%\%LOGFILE%"
ECHO                 PCELOG = %PCELOG%                                                              >> "%PRODPATH%\%LOGFILE%"
ECHO           Configuration Files:                                                                 >> "%PRODPATH%\%LOGFILE%"
ECHO              POSTP_PCE_INI = %POSTP_PCE_INI%                                                   >> "%PRODPATH%\%LOGFILE%"
ECHO              POSTP_PCE_CTL = %POSTP_PCE_CTL%                                                   >> "%PRODPATH%\%LOGFILE%"
ECHO           Printer Settings:                                                                    >> "%PRODPATH%\%LOGFILE%"
ECHO              PSTREAM = %PSTREAM%                                                               >> "%PRODPATH%\%LOGFILE%"
ECHO              XLATE = %XLATE%                                                                   >> "%PRODPATH%\%LOGFILE%"
ECHO              PRES = %PRES%                                                                     >> "%PRODPATH%\%LOGFILE%"
ECHO              PRINT = %PRINT%                                                                   >> "%PRODPATH%\%LOGFILE%"
ECHO           ------------------------------------------------------------------------------------ >> "%PRODPATH%\%LOGFILE%"

rem delete DOC1PCE Printstreams
IF    EXIST "%PRODPATH%\%PRTOUT-01%"                               GOTO  DOPCE-DEL-PRTOUT-01
GOTO DOPCE-DEL-PRTOUT-01-DONE

:DOPCE-DEL-PRTOUT-01
ECHO           Deleting Prior Print 01 Printstream "%PRODPATH%\%PRTOUT-01%"                         >> "%PRODPATH%\%LOGFILE%"  
DEL "%PRODPATH%\%PRTOUT-01%"

:DOPCE-DEL-PRTOUT-01-DONE

IF    EXIST "%PRODPATH%\%AUDIT%"                                   GOTO DOPCE-DEL-AUDIT
GOTO DOPCE-DEL-AUDIT-DONE

:DOPCE-DEL-AUDIT
ECHO           Deleting DOC1PCE Audit File                                                          >> "%PRODPATH%\%LOGFILE%"
DEL "%PRODPATH%\%AUDIT%"

:DOPCE-DEL-AUDIT-DONE

IF    EXIST "%PRODPATH%\%PCELOG%"                                  GOTO DOPCE-DEL-PCELOG
GOTO DOPCE-DEL-PCELOG-DONE

:DOPCE-DEL-PCELOG
ECHO           Deleting DOC1PCE Log File                                                            >> "%PRODPATH%\%LOGFILE%"
DEL "%PRODPATH%\%PCELOG%"

:DOPCE-DEL-PCELOG-DONE

ECHO "%D1HOST%\doc1pce" ini="%D1APPATH%\%POSTP_PCE_INI%" logfile="%PRODPATH%\%PCELOG%" audit="%PRODPATH%\%audit%" PRTOUT-01="%PRODPATH%\%PRTOUT-01%" d1appath="%D1APPATH%" d1host="%D1HOST%" prodpath="%PRODPATH%" print=%PRINT% pstream=%PSTREAM% pres=%PRES% ctlname="%POSTP_PCE_CTL%" genjrn="%PRODPATH%\%SORTJRN%" genprt="%PRODPATH%\%genprt%" >> "%PRODPATH%\%LOGFILE%"
"%D1HOST%\doc1pce" ini="%D1APPATH%\%POSTP_PCE_INI%" logfile="%PRODPATH%\%PCELOG%" audit="%PRODPATH%\%audit%" PRTOUT-01="%PRODPATH%\%PRTOUT-01%" d1appath="%D1APPATH%" d1host="%D1HOST%" prodpath="%PRODPATH%" print=%PRINT% pstream=%PSTREAM% pres=%PRES% ctlname="%POSTP_PCE_CTL%" genjrn="%PRODPATH%\%SORTJRN%" genprt="%PRODPATH%\%genprt%" >> "%PRODPATH%\%LOGFILE%"

IF %ERRORLEVEL% == 0                                               GOTO  DOPCE-OKAY
SET    DOC1-STMT-RC=%ERRORLEVEL%
COPY "%PRODPATH%\%LOGFILE%" + "%PRODPATH%\%PCELOG%" "%PRODPATH%\%LOGFILE%"                          >> "%PRODPATH%\JUNK.FIL"
IF    %PSTREAM% == PDF                                             GOTO DOPCE-ECH2
ECHO           DOC1PCE Error (Add Corrected Addresses to Statements) - Process Halting
:DOPCE-ECH2
ECHO           DOC1PCE Error (Add Corrected Addresses to Statements) - Process Halting              >> "%PRODPATH%\%LOGFILE%"
GOTO  ENDRUN

:DOPCE-OKAY
COPY "%PRODPATH%\%LOGFILE%" + "%PRODPATH%\%PCELOG%" "%PRODPATH%\%LOGFILE%"                          >> "%PRODPATH%\JUNK.FILE"
ECHO           DOC1PCE to create Quote Print files completed successfully                           >> "%PRODPATH%\%LOGFILE%"
ECHO ==============================================================================                 >> "%PRODPATH%\%LOGFILE%"

rem *******************************************************************************
rem    Step 05:  Copy Print Files to Printer                                      *
rem ==============================================================================*
rem   Input Files                                                                 *
rem      PRTOUT-01                                                                *
rem              - Name of the formatted Print file containing Statements         *
rem                to be printed together in batch 01                             *
rem              - This file was output into the PRODPATH directory by Step 03    *
rem   Control Variables                                                           *
rem      PRINTFILES                                                               *
rem              - Value of "N" will prevent the files from being copied to       *
rem                printers                                                       *
rem              - Variable is set in the Master Command file                     *
rem      PADDR-PRTOUT-01                                                          *
rem              - IP Address of the printer for Print File 01                    *
rem              - Variable is set in the Master Command file                     *
rem *******************************************************************************
SET   "STEP05-DATE=%DATE%"
SET   "STEP05-TIME=%TIME%"
:DOPRINT

IF %PRINTFILES% == Y                                               GOTO  DOPRINT-PRINT-FILES
ECHO *******   PRINTFILES=N Coded; Step 05 to print Statements bypassed
ECHO *******   PRINTFILES=N Coded; Step 05 to print Statements bypassed                             >> "%PRODPATH%\%LOGFILE%"
ECHO ==============================================================================                 >> "%PRODPATH%\%LOGFILE%"
GOTO  DOPRINT-DONE

:DOPRINT-PRINT-FILES

ECHO Step 05:  Copy output files to printer
ECHO Step 05:  Copy output files to printer                                                         >> "%PRODPATH%\%LOGFILE%"
ECHO           Start on %STEP05-DATE% at %STEP05-TIME%                                              >> "%PRODPATH%\%LOGFILE%"
ECHO           Directories:                                                                         >> "%PRODPATH%\%LOGFILE%"
ECHO              PRODPATH = %PRODPATH%                                                             >> "%PRODPATH%\%LOGFILE%"
ECHO           Input Files:                                                                         >> "%PRODPATH%\%LOGFILE%"
ECHO              PRTOUT-01 = %PRTOUT-01%                                                           >> "%PRODPATH%\%LOGFILE%"
ECHO           Printer Address:                                                                     >> "%PRODPATH%\%LOGFILE%"
ECHO              PADDR-PRTOUT-01 = %PADDR-PRTOUT-01%                                               >> "%PRODPATH%\%LOGFILE%"
ECHO           ------------------------------------------------------------------------------------ >> "%PRODPATH%\%LOGFILE%"

IF    EXIST "%PRODPATH%\%PRTOUT-01%"                               GOTO DOPRINT-PRINT-PRTOUT-01
ECHO           No Quotes Produced for Print File 01                                                 >> "%PRODPATH%\%LOGFILE%"
GOTO  DOPRINT-PRINT-PRTOUT-01-DONE

:DOPRINT-PRINT-PRTOUT-01
ECHO LPR -o l -S %PADDR-PRTOUT-01% -P %PADDR-PRTOUT-01% "%PRODPATH%\%PRTOUT-01%"                    >> "%PRODPATH%\%LOGFILE%"
LPR -o l -S %PADDR-PRTOUT-01% -P %PADDR-PRTOUT-01% "%PRODPATH%\%PRTOUT-01%"                         >> "%PRODPATH%\%LOGFILE%"
ECHO          Letter Print File 01 "%PRODPATH%\%PRTOUT-01%"                                         >> "%PRODPATH%\%LOGFILE%"
ECHO          Sent to printer %PADDR-PRTOUT-01%                                                     >> "%PRODPATH%\%LOGFILE%"

:DOPRINT-PRINT-PRTOUT-01-DONE

:DOPRINT-DONE
GOTO  ENDRUN

:PDFTSPL
rem *******************************************************************************
rem    Termination: Delete Work Files                                             *
rem ==============================================================================*
rem  This optional step deletes intermediate work files.  This step may be        *
rem  bypassed by setting "DELETEFILES=N" in the Master Command File               *
rem ==============================================================================*
rem   Step  01 Files                                                              *
rem      SPL_SORTED_EXTRACT                                                       *
rem                                                                               *
rem   Step  02 Files                                                              *
rem      NAME-ADDRESS-JOURNAL                                                     *
rem      INTERMEDIATE-PRINT                                                       *
rem                                                                               *
rem   Step  03 Files                                                              *
rem      SORTED-AUDIT-INPUT-JOURNAL                                               *
rem                                                                               *
rem ==============================================================================*
rem   Files NOT Deleted:                                                          *
rem                                                                               *
rem   Step  03 Files                                                              *
rem      AUTOMATED-BILLS-PRINT                                                    *
rem      FOREIGN-BILLS-PRINT                                                      *
rem      INTERCEPTED-BILLS-PRINT                                                  *
rem      OVERSIZED-BILLS-PRINT                                                    *
rem      AUDIT-FILE                                                               *
rem *******************************************************************************

:DODELETE-CHECK

IF %DELETEFILES% == Y                                              GOTO  DODELETE
ECHO *******   DELETEFILES=N coded - File Deletion bypassed                                         >> "%PRODPATH%\%LOGFILE%"
IF    %PSTREAM% == PDF                                             GOTO  DODELETE-DONE
ECHO *******   DELETEFILES=N coded - File Deletion bypassed
GOTO DODELETE-DONE

:DODELETE

rem Delete Step 01 Files
IF    EXIST "%PRODPATH%\%SPL_SORTED_EXTRACT%"                      ECHO           Deleting Step 01 Sorted Extract "%PRODPATH%\%SPL_SORTED_EXTRACT%" >> "%PRODPATH%\%LOGFILE%"
IF    EXIST "%PRODPATH%\%SPL_SORTED_EXTRACT%"                      DEL     "%PRODPATH%\%SPL_SORTED_EXTRACT%"

rem Delete Step 02 Files
IF    EXIST "%PRODPATH%\%genprt%"                                  ECHO           Deleting Step 02 Intermediate Print "%PRODPATH%\%genprt%" >> "%PRODPATH%\%LOGFILE%"
IF    EXIST "%PRODPATH%\%genprt%"                                  DEL     "%PRODPATH%\%genprt%"
IF    EXIST "%PRODPATH%\%genjrn%"                                  ECHO           Deleting Step 02 Name-Address Journal "%PRODPATH%\%genjrn%" >> "%PRODPATH%\%LOGFILE%"
IF    EXIST "%PRODPATH%\%genjrn%"                                  DEL     "%PRODPATH%\%genjrn%"

IF %RUN_TYPE% == ONLINE                                            GOTO   DODELETE-DONE

rem Delete Step 03 Files SORTJRN
IF    EXIST "%PRODPATH%\%SORTJRN%"                                 ECHO           Deleting Step 03 Sorted Journal "%PRODPATH%\%SORTJRN%" >> "%PRODPATH%\%LOGFILE%"
IF    EXIST "%PRODPATH%\%SORTJRN%"                                 DEL     "%PRODPATH%\%SORTJRN%"

:DODELETE-DONE

:ENDRUN
SET   "END-DATE=%DATE%"
SET   "END-TIME=%TIME%"

ECHO "=============================================================================="               >> "%PRODPATH%\%LOGFILE%"
ECHO Process Ended on %END-DATE% at %END-TIME%                                                      >> "%PRODPATH%\%LOGFILE%"
IF    %PSTREAM% == PDF                                             GOTO ECHZ
ECHO Process Ended on %END-DATE% at %END-TIME%
ECHO Process Ended with Completion Code %DOC1-STMT-RC%
:ECHZ
ECHO Process Ended with Completion Code %DOC1-STMT-RC%                                               >> "%PRODPATH%\%LOGFILE%"

IF    EXIST "%PRODPATH%\junk.file"                                 DEL     "%PRODPATH%\junk.file"
