# #!/usr/bin/sh  

# Delete previous "junk" files
rm -f $PRODPATH/junk.log

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

if [ $SPLBILL_CALLED_SWITCH != Y ]
   then
#   else
     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 COMMAND LINE.                    *
     echo *                                                                             *
     echo * Instead, this bat file is meant to be executed by being called from another *
     echo * .sh file.                                                                   *
     echo *                                                                             *
     echo * On the Command Line, execute a Master Command File                          *
     echo ==============================================================================*
     exit 16
fi

# ***********************************************************************************
#  Platform:      Unix - AIX / SUN / HP / Linux                                     *
#  Printstream:   AFP, PDF, or PostScript                                           *
#  Installation:  Base Template Package                                             *
#  Application:   SPL Bill Print                                                    *
#         NOTE:   Supports for Batch Bill Printing and Online ("Display Bill")      *
# ==================================================================================*
#  Command File called to execute integrated DOC1 / Code-1 / MailStream             *
#  for SPL to produce Bills                                                         *
# ==================================================================================*
#  This Command File should NOT be run from the command line; instead, a Master     *
#  Command file is run on the command line; the Master Command File will call       *
#  this command file.                                                               *
# ==================================================================================*
#  The Master Command File must set the following symbols prior to calling this     *
#  command file:                                                                    *
#                                                                                   *
#    The following switches which enable certain steps to be bypassed               *
#    P R O C E S S I N G   C O N T R O L S                                          *
#    =====================================                                          *
#      PRINTFILES                                                                   *
#              - May be:  Y or N                                                    *
#              - "N" prevents files from being copied into InfoPrint Hotfolders     *
#      RUN_TYPE                                                                     *
#              - Indicates that this execution is for batch billing rather than     *
#                online billing;                                                    *
#              - Acceptable values are BATCH and ONLINE; use BATCH for Batch Bill   *
#                Print (ONLINE is for SPL-invoked "Display Bill" button)            *
#              - value of RUN_TYPE=BATCH enables all steps within the called Unix   *
#                shell script to be run                                             *
#      CODE1                                                                        *
#              - May be:  Y or N                                                    *
#              - "N" allows Code-1 Plus to be bypassed                              *
#      MSTREAM                                                                      *
#              - May be:  Y or N                                                    *
#              - "N" allows MailStream Plus to be bypassed                          *
#      DELETEFILES                                                                  *
#              - May be:  Y or N                                                    *
#              - "N" prevents intSPLediate work files from being deleted            *
#                                                                                   *
#    G E N E R A L   S Y M B O L S                                                  *
#    =============================                                                  *
#      LOGFILE                                                                      *
#              - Name of a log file to be created by this process                   *
#              - Previous version of file will be replaced                          *
#              - File will be written to $PRODPATH directory                        *
#              - Sample coding:  LOGFILE=spl-bill.log                               *
#      SPLBILL_CALLED_SWITCH                                                        *
#              - Must be set to "Y"                                                 *
#              - This process will reset to "N"                                     *
#              - Used by to insure that this process was invoked by a Master        *
#                Command File                                                       *
#      PRODPATH                                                                     *
#              - Names directory for output files from Sort, DOC1, Code-1,          *
#                and MailStream; there will be a few exceptions of files that       *
#                both Code-1 and MailStream write to their own root directories     *
#                $G1C1P/data and $G1MSP/data                                        *
#              - Sample coding: PRODPATH=/DOC1/Prodfiles                            *
#                                                                                   *
#    D O C 1   S Y M B O L S                                                        *
#    =======================                                                        *
#      D1HOST                                                                       *
#              - Names root directory where the DOC1 Generate was installed         *
#              - Typical value:                                                     *
#                D1HOST=/Group1/Doc1 Suite                                          *
#      D1APPATH                                                                     *
#              - Names directory containing HIP, INI, CTL, OPS, ETS                 *
#              - Sample coding:                                                     *
#                D1APPATH=/Group1/DOC1 Suite/resource/bill                          *
#      GEN_OPS                                                                      *
#              - Names DOC1 Generate Initialization file for Format Bills           *
#              - Sample value: GEN_OPS=splbill_s5_v3_doc1gen.ops                    *
#              - File must be present in the $D1APPATH directory                    *
#      GEN_HIP                                                                      *
#              - Name of DOC1 Generate Application Rules (.HIP)                     *
#              - Sample value: GEN_HIP=splbill_s5_v3_doc1gen_pdf.hip                *
#              - File must be present in the $D1APPATH directory                    *
#      GEN_ETS                                                                      *
#              - Names Look-Up file                                                 *
#              - Sample value: GEN_ETS=splbill_s5_v3_doc1gen.ets                    *
#              - File must be present in the $D1APPATH directory                    *
#      GEN_CNTL                                                                     *
#              - Names Look-Up file with controls distinguishing ONLINE vs. BATCH   *
#              - Sample value: GEN_CNTL=splbill_s5_v3_doc1gen_control_pdf.ets       *
#              - File must be present in the $D1APPATH directory                    *
#      FRGN_PCE_INI                                                                 *
#              - Names DOC1PCE Initialization file for Foreign step                 *
#              - Sample value: FRGN_PCE_INI=splbill_s5_v3_frgnsplt_pce.ini          *
#              - File must be present in the $D1APPATH directory                    *
#      FRGN_PCE_CTL                                                                 *
#              - Names DOC1PCE Rules file for Foreign step                          *
#              - Sample value: FRGN_PCE_CTL=splbill_s5_v3_frgnsplt_pce.ctl          *
#              - File must be present in the $D1APPATH directory                    *
#      SPCL_PCE_INI                                                                 *
#              - Names DOC1PCE Initialization file for Special Handling step        *
#              - Sample value: SPCL_PCE_INI=splbill_s5_v3_spcsplt_pce.ini           *
#              - File must be present in the $D1APPATH directory                    *
#      SPCL_PCE_CTL                                                                 *
#              - Names DOC1PCE Rules file for Special Handling step                 *
#              - Sample value: SPCL_PCE_CTL=splbill_s5_v3_spcsplt_pce.ctl           *
#              - File must be present in the $D1APPATH directory                    *
#      CPRT_PCE_INI                                                                 *
#              - Names DOC1PCE Initialization file for Create Print step            *
#              - Sample value: CPRT_PCE_INI=splbill_s5_v3_createprt_pce.ini         *
#              - File must be present in the $D1APPATH directory                    *
#      CPRT_PCE_CTL                                                                 *
#              - Names DOC1PCE Rules file for Create Print step                     *
#              - Sample value: CPRT_PCE_CTL=splbill_s5_v3_createprt_pce.ctl         *
#              - File must be present in the $D1APPATH directory                    *
#      MAXAUTO                                                                      *
#              - Identifies the maximum number of sheets that a Bill may            *
#                contain and still be considered an Automated Bill; if a Bill       *
#                has more sheets than the MAXAUTO value, the Bill will be           *
#                classified as an Oversized Bill                                    *
#              - Sample value: MAXAUTO=6                                            *
#                                                                                   *                                                                                   *
#    S P L   S Y M B O L S                                                          *
#    =====================                                                          *
#      XTRCTPTH                                                                     *
#              - Names directory containing SPL Bill Print Extract                  *
#              - Sample coding: XTRCTPTH=/SPL/data                                  *
#      SPL_UNSORTED_EXTRACT                                                         *
#              - Names SPL Bill Print Extract                                       *
#              - Typical coding SPL_UNSORTED_EXTRACT=bpxtr01.dat                    *
#                                                                                   *
#    P R I N T   S Y M B O L S                                                      *
#    =========================                                                      *
#      PRINTFILES                                                                   *
#              - May be:  Y or N                                                    *
#              - "N" prevents files from being sent to PADDR printer                *
#      PSTREAM                                                                      *
#              - May be AFPDS or PostScript                                         *
#              - Controls type of print description language for output             *
#                                                                                   *
#    C O D E - 1 / M A I L S T R E A M   S Y M B O L S                              *
#    =================================================                              *
#      G1C1P                                                                        *
#              - Names directory where Code-1 Plus was installed                    *
#              - Code-1 installation sets as an environment variable                *
#              - Typical value: G1C1P=/Group1/C1P                                   *
#              - The following file must be in the $G1C1P/data directory:           *
#                  - G1LMLIC                                                        *
#              - The following file must be in the $G1C1P/DLL directory:            *
#                  - C1BM00                                                         *
#      G1C1PDB                                                                      *
#              - Names directory containing Code-1 databases                        *
#              - Code-1/MailStream installations set as an environment variable     *
#              - Typical value: G1DC1PDB=/12a2/group1/c1p/db                        *
#              - The following Code-1 files must be in the $G1C1DB directory:       *
#                  - CITYDB      - CITYNM      - COUNTY      - DTLDB                *
#                  - LCLDB       - LTMASTR     - PTRDB       - ZIPIDX               *
#                  - Z4CHNG      - G1C1AUX     - DPVLCD      - DPVMST               *
#      C1PRM                                                                        *
#              - Name of the Code-1 Parameter File                                  *
#              - Sample value: C1PRM=splbill_s5_v3_code1.prm                        *
#              - File must be present in the $D1APPATH directory                    *
#      G1MSP                                                                        *
#              - Names directory where MailStream Plus was installed                *
#              - MailStream installation sets as an environment variable            *
#              - Typical value: G1MSP=C:\Program Files\Group1\MSP                   *
#              - The following file must be in the $G1MSP/CMDS directory:           *
#                  - MSPRUN.VBS                                                     *
#      G1MSPDB                                                                      *
#              - Names directory containing MailStream databases                    *
#              - Code-1/MailStream installations set as an environment variable     *
#              - Typical value: G1MSPDB=/12a2/group1/msp/db                         *
#              - The following MailStream files must be in the $G1MSPDB directory:  *
#                  - PRFDLVCT    - PRFDSTNM    - PRFMXCTY    - PRFRTMAP             *
#                  - PRFSQREF    - PRFZIPDR    - PRFZONES    - PRFPSTMT             *
#      MSPRM                                                                        *
#              - Name of the MailStream Parameter File                              *
#              - Sample value: MSPRM=splbill_s5_v3_mstream.prm                      *
#              - File must be present in the $D1APPATH directory                    *
# ==================================================================================*
#  Step 01:  Sort SPL extract to re-arrange records within document                 *
#  Step 02:  Format Bills (DOC1GEN)                                                 *
#  Step 03:  Identify Foreign Addressed Bills (DOC1PCE)                             *
#  Step 04:  Sort Foreign Address Journal Records                                   *
#  Step 05:  Address Correction (Code-1)                                            *
#  Step 06:  Identify Special Handling Bills (DOC1PCE)                              *
#  Step 07:  Sort Special Handling Journal Records                                  *
#  Step 08:  Postal Pre-Sort (MailStream)                                           *
#  Step 09:  Create Print Files (DOC1PCE)                                           *
#  Termination:  Delete Files                                                       *
# ==================================================================================*

if [ $RUN_TYPE = ONLINE ]

   then
     PRINT=PDF;                                            export PRINT
     PSTREAM=PDF;                                          export PSTREAM
     UV1=0;                                                export UV1

   else

     PRINT=PS;                                             export PRINT
     PSTREAM=PostScript;                                   export PSTREAM
     UV1=1;                                                export UV1

fi

# ***********************************************************************************
#    Step 01:  Sort SPL extract to re-arrange records within document               *
# ==================================================================================*
#  The SPL Bill Print Extract must be sorted to re-arrange records within each      *
#  Bill.  The sorting will re-arrange Service Agreements according to the print     *
#  priority assigned within SPL.   Additionally, different blocks of                *
#  information are re-sequence within the data to match the sequence the            *
#  information is to be printed on the Bill; for example, the message records       *
#  are moved ahead of the Premise / Service Agreement data.                         *
# ==================================================================================*
#   Input Files                                                                     *
#      SPL_UNSORTED_EXTRACT                                                         *
#              - Name of the Billing data extracted from SPL                        *
#              - This file must be in the $XTRCTPTH directory prior to running      *
#                this .SH process                                                   *
#   Output Files                                                                    *
#      SPL_SORTED_EXTRACT                                                           *
#              - Name of Sorted SPL Extract containing Bill data                    *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#   Configuration Files                                                             *
#      -- none --                                                                   *
# ***********************************************************************************
SPL_SORTED_EXTRACT=bill_sorted.svd;                                                     export SPL_SORTED_EXTRACT

echo "Step 01:  Sort SPL extract to re-arrange records within document"
echo "Step 01:  Sort SPL extract to re-arrange records within document"                 >> $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 "          --------------------------------------------------------------"         >> $PRODPATH/$LOGFILE

# Delete Sort output files
rm -f $PRODPATH/$SPL_SORTED_EXTRACT

$D1APPATH/splbill_s5_v3_called_svd_sort.sh

if [ $? -ne 0 ]
   then     
     echo           Sort Error - Process Halting
     echo           Sort Error - Process Halting             				                    >> $PRODPATH/$LOGFILE
     exit 16
fi

echo "Step 01:  Sort Complete - SPL Extract Sorted"          			                     	>> $PRODPATH/$LOGFILE
echo "========================================================================"         >> $PRODPATH/$LOGFILE

# ***********************************************************************************
#    Step 02:  Format Bills (DOC1GEN)                                               *
# ==================================================================================*
#  The DOC1 Generate module (DOC1GEN) applies the DOC1 Application Rules            *
#  against the Sorted SPL Bill Print Extract (output from Step 01) to create an     *
#  Print File of all Bills contained in the Bill Print Extract.                     *
#                                                                                   *
#  For Batch bill print, the IntSPLediate Print File will be post-processed and     *
#  divided into different print files according to operational processing           *
#  requirements.                                                                    *
#                                                                                   *
#  For Online Billing, this process will end with this step; SPL will invoke        *
#  Adobe Acrobat Reader to view the single bill produced by this step               *
# ==================================================================================*
#   Input Files                                                                     *
#      SPL_SORTED_EXTRACT                                                           *
#              - Name of Sorted SPL Extract containing Bill data                    *
#              - This file was output into the $PRODPATH directory by Step 01       *
#   Configuration Files                                                             *
#      GEN_OPS                                                                      *
#              - Name of the DOC1GEN Initialization File                            *
#              - This file must be in the $D1APPATH directory prior to running      *
#                this .SH process                                                   *
#      GEN_HIP                                                                      *
#              - Name of the DOC1GEN Application Rules                              *
#              - This file must be in the $D1APPATH directory prior to running      *
#                this .SH process                                                   *
#      GEN_ETS                                                                      *
#              - Name of the Look-Up File with Country Names                        *
#              - This file must be in the $D1APPATH directory prior to running      *
#                this .SH process                                                   *
#      GEN_CNTL                                                                     *
#              - Name of the Look-Up File with Controls (online vs. batch)          *
#              - This file must be in the $D1APPATH directory prior to running      *
#                this .SH process                                                   *
#      LOGOXML                                                                      *
#              - Names XML file that identifies the bitmap used for a company       *
#                logo and contains sizing attributes of the bitmap                  *
#              - File must be present in the $D1APPATH directory                    *
#   Output Files                                                                    *
#      NAME_ADDRESS_JOURNAL                                                         *
#              - Name of the Name-Address Journal file containing Address data      *
#                and Output detSPLination data triggers                             *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#      INTERMEDIATE_PRINT                                                           *
#              - Name of the file containing all formatted Bills                    *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
# ***********************************************************************************
NAME_ADDRESS_JOURNAL=bill_name_address_journal.jrn.jrn;                                 export NAME_ADDRESS_JOURNAL
INTERMEDIATE_PRINT=bill_INTERMEDIATE_PRINT.$PRINT;                                      export INTERMEDIATE_PRINT
DOC1GEN_DIJ=bill_e2_journal.dij;                                                        export DOC1GEN_DIJ
UV2=0;                                                                                  export UV2

echo "Step 02:  Format Bills (DOC1GEN)" 
echo "Step 02:  Format Bills (DOC1GEN)"                                                 >> $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 "             INTERMEDIATE_PRINT = $INTERMEDIATE_PRINT"                            >> $PRODPATH/$LOGFILE
echo "             NAME_ADDRESS_JOURNAL = $NAME_ADDRESS_JOURNAL"                        >> $PRODPATH/$LOGFILE
echo "             DOC1GEN_DIJ = $DOC1GEN_DIJ"                                          >> $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 "             LOGOXML = $LOGOXML"                                                  >> $PRODPATH/$LOGFILE
echo "          Printer Settings:"                                                      >> $PRODPATH/$LOGFILE
echo "             PSTREAM = $PSTREAM"                                                  >> $PRODPATH/$LOGFILE
echo "          Control Settings:"                                                      >> $PRODPATH/$LOGFILE
echo "             UV1 = $UV1"                                                          >> $PRODPATH/$LOGFILE
echo "             UV2 = $UV2"                                                          >> $PRODPATH/$LOGFILE
echo "          --------------------------------------------------------------"         >> $PRODPATH/$LOGFILE

# delete Step 02 Output Files from previous run
rm -f $PRODPATH/$INTERMEDIATE_PRINT
rm -f $PRODPATH/$NAME_ADDRESS_JOURNAL
rm -f $PRODPATH/$DOC1GEN_DIJ

$D1APPATH/splbill_s5_v3_called_doc1gen.sh

if [ $? -ne 0 ]
   then     
     echo "DOC1GEN Error (Format Bills) - Process Halting"
     echo "DOC1GEN Error (Format Bills) - Process Halting"                              >> $PRODPATH/$LOGFILE
     exit 16
fi

echo "Step 02:  DOC1GEN Complete - Bills Formatted"                                     >> $PRODPATH/$LOGFILE
echo "=============================================================================="   >> $PRODPATH/$LOGFILE

if [ $RUN_TYPE = ONLINE ]
   then
     echo "-------- Copying PDF $PRODPATH/$INTERMEDIATE_PRINT to $ONLINE_PDF"           >> $PRODPATH/$LOGFILE
     cp  $PRODPATH/$INTERMEDIATE_PRINT $ONLINE_PDF
     echo "cp  $PRODPATH/$INTERMEDIATE_PRINT $ONLINE_PDF "                              >> $PRODPATH/$LOGFILE
     if [ $DELETEFILES = Y ]
#dgs
     then
       #dgs   rm -f $PRODPATH/$SPL_SORTED_EXTRACT
          rm -f $PRODPATH/$INTERMEDIATE_PRINT
          rm -f $PRODPATH/$NAME_ADDRESS_JOURNAL
     fi
     echo "--------------------------Process Completed-----------------------------------"
     exit 0
fi

# ***********************************************************************************
#    Step 03:  Identify Foreign Addressed Bills (DOC1PCE)                           *
# ==================================================================================*
#  Bills being mailed to a non-USA address are identified and removed from the      *
#  Code-1 input to prevent Code-1 from marking those addresses as invalid.          *
#  This PCE application will read the Name / Address Journal (created in Step       *
#  02) and create two output journals - one with USA addresses and the other        *
#  containing all other addresses.                                                  *
# ==================================================================================*
#   Input Files                                                                     *
#      NAME_ADDRESS_JOURNAL                                                         *
#              - Name of the Name-Address Journal file containing Address data      *
#                and Output detSPLination data triggers                             *
#              - This file was output into the $PRODPATH directory by Step 02       *
#   Configuration Files                                                             *
#      FRGN_PCE_INI                                                                 *
#              - Name of the DOC1PCE Initialization File                            *
#              - This file must be in the $D1APPATH directory prior to running      *
#                this .SH process                                                   *
#      FRGN_PCE_CTL                                                                 *
#              - Name of the DOC1PCE Rules to separate Foreign Addressed Bills      *
#              - This file must be in the $D1APPATH directory prior to running      *
#                this .SH process                                                   *
#   Output Files                                                                    *
#      USA_NAME_ADDRESS_JOURNAL                                                     *
#              - Name of the Name-Address Journal file containing USA addressed     *
#                Bills and Output detSPLination data triggers                       *
#              - This file will be a subset of the NAME_ADDRESS_JOURNAL input       *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#      FRGN_NAME_ADDRESS_JOURNAL                                                    *
#              - Name of the Name-Address Journal containing foreign addressed      *
#                Bills (or Letters) and Output detSPLination data triggers          *
#              - This file will be a subset of the NAME_ADDRESS_JOURNAL input       *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#      FRGN_SPLIT_LOGFILE                                                           *
#              - Name of the file containing messages from the PCE process          *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
# ***********************************************************************************
USA_NAME_ADDRESS_JOURNAL=bill_usa_name_address_journal.jrn;                             export USA_NAME_ADDRESS_JOURNAL
FRGN_NAME_ADDRESS_JOURNAL=bill_foreign_name_address_journal.jrn;                        export FRGN_NAME_ADDRESS_JOURNAL
FRGN_SPLIT_LOGFILE=bill_foreign_split_logfile.log;                                      export FRGN_SPLIT_LOGFILE

echo "Step 03:  Identify Foreign Addressed Bills (DOC1PCE)" 
echo "Step 03:  Identify Foreign Addressed Bills (DOC1PCE)"                             >> $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 "             NAME_ADDRESS_JOURNAL = $NAME_ADDRESS_JOURNAL"                        >> $PRODPATH/$LOGFILE
echo "          Output Files:"                                                          >> $PRODPATH/$LOGFILE
echo "             USA_NAME_ADDRESS_JOURNAL = $USA_NAME_ADDRESS_JOURNAL"                >> $PRODPATH/$LOGFILE
echo "             FRGN_NAME_ADDRESS_JOURNAL = $FRGN_NAME_ADDRESS_JOURNAL"              >> $PRODPATH/$LOGFILE
echo "             FRGN_SPLIT_LOGFILE = $FRGN_SPLIT_LOGFILE"                            >> $PRODPATH/$LOGFILE
echo "          Configuration Files:"                                                   >> $PRODPATH/$LOGFILE
echo "             FRGN_PCE_INI = $FRGN_PCE_INI"                                        >> $PRODPATH/$LOGFILE
echo "             FRGN_PCE_CTL = $FRGN_PCE_CTL"                                        >> $PRODPATH/$LOGFILE
echo "          --------------------------------------------------------------"         >> $PRODPATH/$LOGFILE

# delete Step 03 Output Files from previous run
rm -f $PRODPATH/$USA_NAME_ADDRESS_JOURNAL
rm -f $PRODPATH/$FRGN_NAME_ADDRESS_JOURNAL
rm -f $PRODPATH/$FRGN_SPLIT_LOGFILE

$D1APPATH/splbill_s5_v3_called_frgnsplt_pce.sh

if [ $? -ne 0 ]
   then     
     cat $PRODPATH/$FRGN_SPLIT_LOGFILE >> $PRODPATH/$LOGFILE
     echo "DOC1PCE Error (Separate Foreign Bills) - Process Halting"
     echo "DOC1PCE Error (Separate Foreign Bills) - Process Halting"                    >> $PRODPATH/$LOGFILE
     exit 16
fi

cat $PRODPATH/$FRGN_SPLIT_LOGFILE >> $PRODPATH/$LOGFILE
echo "Step 03:  DOC1PCE Complete - Foreign Bills Separated"                             >> $PRODPATH/$LOGFILE
echo "========================================================================"         >> $PRODPATH/$LOGFILE

# ***********************************************************************************
#    Step 04:  Sort Foreign Address Journal Records                                 *
# ==================================================================================*
#  The Foreign Address Journal output in Step 03 is sorted by Country Code so       *
#  that these Bills, when printed, will be printed in Country Code order.           *
# ==================================================================================*
#   Input Files                                                                     *
#      FRGN_NAME_ADDRESS_JOURNAL                                                    *
#              - Name of the Name-Address Journal containing foreign addressed      *
#                Bills and Output detSPLination data triggers                       *
#   Output Files                                                                    *
#      FRGN_SORTED_NAME_ADDRESS_JOURNAL                                             *
#              - Name of the Name-Address Journal now sorted by Country Code        *
#              - This file will be written to the PRODPATH directory                *
#              - This .SH process will delete previous versions of this file        *
#   Configuration Files                                                             *
#      -- none --                                                                   *
# ***********************************************************************************
FRGN_SORTED_NAME_ADDRESS_JOURNAL=bill_frgn_sorted_name_address_journal.jrn;             export FRGN_SORTED_NAME_ADDRESS_JOURNAL

echo "Step 04:  Sort Foreign Address Journal Records"
echo "Step 04:  Sort Foreign Address Journal Records"                                   >> $PRODPATH/$LOGFILE
echo "          Directories:"                                                           >> $PRODPATH/$LOGFILE
echo "             PRODPATH = $PRODPATH"                                                >> $PRODPATH/$LOGFILE
echo "          Input Files:"                                                           >> $PRODPATH/$LOGFILE
echo "             FRGN_NAME_ADDRESS_JOURNAL = $FRGN_NAME_ADDRESS_JOURNAL"              >> $PRODPATH/$LOGFILE
echo "          Output Files:"                                                          >> $PRODPATH/$LOGFILE
echo "             FRGN_SORTED_NAME_ADDRESS_JOURNAL = $FRGN_SORTED_NAME_ADDRESS_JOURNAL" >> $PRODPATH/$LOGFILE
echo "          --------------------------------------------------------------"         >> $PRODPATH/$LOGFILE

# Delete Sort output files
rm -f $PRODPATH/$FRGN_SORTED_NAME_ADDRESS_JOURNAL

$D1APPATH/splbill_s5_v3_called_foreign_sort.sh

if [ $? -ne 0 ]
   then     
     echo "        Sort Error (Sort Foreign Bill Journal) - Process Halting"
     echo "        Sort Error (Sort Foreign Bill Journal) - Process Halting"            >> $PRODPATH/$LOGFILE
     exit 16
fi

echo "Step 04:  Sort Complete - Foreign Bill Journal Sorted"          			>> $PRODPATH/$LOGFILE
echo "======================================================================== "	>> $PRODPATH/$LOGFILE

# ***********************************************************************************
#    Step 05:  Address Correction (Code-1)                                          *
# ==================================================================================*
#  Code-1 Plus is the Group1 product that performs the address correction,          *
#  formatting, and validation required by the USPS to qualify for Postal            *
#  Discounts.   In  the output journal, Code-1 will add address directionals        *
#  N - North, S - South, etc.), street suffixes (LN, DR, ST, etc.), assign a        *
#  Zip+4 Zip Code, identify the Carrier Route, and detSPLine the content of the     *
#  Delivery Point Bar Code.  The Step 10 PCE application will place the Code-1      *
#  formatted address and Delivery Point Bar Code on the Bill Remittance Coupon.     *
#  Code-1 Plus also produces a USPS CASS report.                                    *
# ==================================================================================*
#   Input Files                                                                     *
#      USA_NAME_ADDRESS_JOURNAL (aka DD_C1BMNAM)                                    *
#              - Name of the Name-Address Journal file containing USA addressed     *
#                Bills (or Letters) and Output detSPLination data triggers          *
#              - This file was output into the $PRODPATH directory by Step 03       *
#   Configuration Files                                                             *
#      DD_C1BMPRM                                                                   *
#              - Name of the Code-1 Parameter File                                  *
#              - This file must be in the data sub-directory within the $G1C1P      *
#                directory prior to running this .SH process                        *
#      DD_G1LICEN                                                                   *
#              - Name of the Code-1 License Management File                         *
#              - This file must be in the data sub-directory within the $G1C1P      *
#                directory prior to running this .SH process                        *
#   Code-1 Database Files                                                           *
#      DD_CITYDB                                                                    *
#      DD_CITYNM                                                                    *
#      DD_COUNTY                                                                    *
#      DD_DTLDB                                                                     *
#      DD_LCLDB                                                                     *
#      DD_LTMASTR                                                                   *
#      DD_PTRDB                                                                     *
#      DD_ZIPIDX                                                                    *
#      DD_Z4CMSTR                                                                   *
#              - All of these files must be in the $G1C1PDB directory prior to      *
#                running this .SH process                                           *
#              - Note that all of these files must be updated regularly; these      *
#                files contain time sensitive data with an expiration date;         *
#                once the data expires, Code-1 will cease to produce the            *
#                desired results.                                                   *
#   Output Files                                                                    *
#      CORRECTED_NAME_ADDRESS_JOURNAL (aka DD_C1BMCOK)                              *
#              - Name of the USA Name-Address Journal file containing USA           *
#                addressed records where the address has been corrected (if         *
#                needed), formatted per USPS requirements, a Carrier Route has      *
#                been identified, a 12-byte Delivery Point Bar Code (DPBC) has      *
#                been identified, and Output detSPLination data triggers            *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#      REJECTED_NAME_ADDRESS_JOURNAL (aka DD_C1BMNCO)                               *
#              - Name of the USA Name-Address Journal file containing USA           *
#                addressed records where the address has been rejected because      *
#                it could not be identified                                         *
#          NOTE: This file is output only if a FILEDF is present in the Code-1      *
#                Parameter file; otherwise; ALL Code-1 output, including the        *
#                records not correctable, will be written to DD_C1BMCOK             *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#      DD_PRNTCAS                                                                   *
#              - Name of the Code-1 USPS 3553 CASS Report                           *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#      DD_PRNTRPT                                                                   *
#              - Name of the Code-1 Statistics Report                               *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#      DD_PRNTXLG                                                                   *
#              - Name of the Code-1 Execution Log                                   *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#      DD_CBLOUT                                                                    *
#              - Contains messages that would be displayed on the tSPLinal          *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
# ==================================================================================*
#  NOTE:  This step may be bypassed by coding CODE1=N in the master .SH file        *
#         When coded, this SH will simply make a COPY of the input file to          *
#         the output file name.                                                     *
# ***********************************************************************************

CORRECTED_NAME_ADDRESS_JOURNAL=bill_correctedaddress_journal.jrn;                       export CORRECTED_NAME_ADDRESS_JOURNAL

# Code-1 Parameter and License Files
DD_C1BMPRM=$D1APPATH/$C1PRM;                                                            export DD_C1BMPRM  # Parameter File
DD_G1LICEN=$G1C1P/data/g1lmlic;                                                         export DD_G1LICEN  # License File
                                                                                        
# Code-1 Input File                                                                     
DD_C1BMNAM=$PRODPATH/$USA_NAME_ADDRESS_JOURNAL;                                         export DD_C1BMNAM  # Created by Step 3
                                                                                        
# Code-1 Output Files                                                                   
DD_C1BMCOK=$PRODPATH/$CORRECTED_NAME_ADDRESS_JOURNAL;                                   export DD_C1BMCOK  # Corrected Records
DD_C1BMNCO=$PRODPATH/bill_rejected_name_address_journal.jrn;                            export DD_C1BMNCO  # Uncorrectable Records
                                                                                        
# Code-1 Output Report Files                                                            
DD_PRNTCAS=$PRODPATH/bill_USPS_3553_CASS.cas;                                           export DD_PRNTCAS  # USPS 3553 CASS Report
DD_PRNTRPT=$PRODPATH/bill_code1_stats.rpt;                                              export DD_PRNTRPT  # Statistics Report
DD_PRNTXLG=$PRODPATH/bill_code1_execution_log.xlg;                                      export DD_PRNTXLG  # Execution Log
DD_C1BMIZP=$PRODPATH/bill_code1.izp;                                                    export DD_C1BMIZP 
DD_C1BMZP4=$PRODPATH/bill_code1.zp4;                                                    export DD_C1BMZP4
DD_CBLOUT=$PRODPATH/bill_code1_tSPLinal_messages.log;                                   export DD_CBLOUT 
                                                                                        
# Code-1 Database Files                                                                 
DD_ZIPIDX=$G1C1PDB/zipidx;                                                              export DD_ZIPIDX
DD_CITYDB=$G1C1PDB/citydb;                                                              export DD_CITYDB
DD_CITYNM=$G1C1PDB/citynm;                                                              export DD_CITYNM
DD_COUNTY=$G1C1PDB/county;                                                              export DD_COUNTY
DD_Z4CMSTR=$G1C1PDB/z4chng;                                                             export DD_Z4CMSTR
DD_LCLDB=$G1C1PDB/lcldb;                                                                export DD_LCLDB
DD_DTLDB=$G1C1PDB/dtldb;                                                                export DD_DTLDB
DD_G1CPFDF=$G1C1PDB/g1cpfdf;                                                            export DD_G1CPFDF
DD_LTMASTR=$G1C1PDB/ltmastr;                                                            export DD_LTMASTR
DD_C1STRDB=$G1C1PDB/c1strdb;                                                            export DD_C1STRDB
DD_PTRDB=$G1C1PDB/ptrdb;                                                                export DD_PTRDB
                                                                                        
#     Delivery Point Validation files                                                   
#     Please Note:  The two (2) DPV input files must exist                              
#                   before DPV processing can proceed.                                  
# DD_DPVLCD="$G1C1PDB"/dpvlcd;                                                            export DD_DPVLCD
# DD_DPVMST="$G1C1PDB"/dpvmst;                                                            export DD_DPVMST
# DD_RDIMSTR=$G1C1PDB/rdimstr;               	                                          export DD_RDIMSTR
                                                                                        
#     EWS file                                                                          
# DD_G1C1AUX=$G1C1PDB/g1c1aux;			                                          export DD_G1C1AUX

# DPV Seed Output file
# DD_DPVSEED="$G1C1P/data/$G1JOB.sed" # DPV SEED output file
# export DD_DPVSEED


# delete Step 05 Output Files from previous run
rm -f $DD_C1BMCOK        # Corrected Recods
rm -f $DD_C1BMNCO        # Uncorrectable Records
rm -f $DD_PRNTCAS        # CASS Report
rm -f $DD_PRNTRPT        # Statistics Report
rm -f $DD_PRNTXLG        # Execution Log
rm -f $DD_CBLOUT
rm -f $DD_C1BMIZP
rm -f $DD_C1BMZP4

if [ $CODE1 = N ]

   then

     echo "Step 05:  Code1 bypassed - COPY substituted"
     echo "Step 05:  Code1 bypassed - COPY substituted"                                 >> $PRODPATH/$LOGFILE

     echo "cp $PRODPATH/$USA_NAME_ADDRESS_JOURNAL $DD_C1BMCOK"                          >> $PRODPATH/$LOGFILE
     cp $PRODPATH/$USA_NAME_ADDRESS_JOURNAL $DD_C1BMCOK
   
     echo "Step 05:  $PRODPATH/$USA_NAME_ADDRESS_JOURNAL copied to $DD_C1BMCOK"         >> $PRODPATH/$LOGFILE
     echo "=========================================================================="  >> $PRODPATH/$LOGFILE

   else

     echo "Step 05:  Address Correction (Code-1)"
     echo "Step 05:  Address Correction (Code-1)"                                       >> $PRODPATH/$LOGFILE
     echo "          Code-1 Directories:"                                               >> $PRODPATH/$LOGFILE
     echo "             G1C1P = $G1C1P"                                                 >> $PRODPATH/$LOGFILE
     echo "             G1C1PDB = $G1C1PDB"                                             >> $PRODPATH/$LOGFILE
     echo "          Input Files:"                                                      >> $PRODPATH/$LOGFILE
     echo "             DD_C1BMNAM = $DD_C1BMNAM"                                       >> $PRODPATH/$LOGFILE
     echo "          Output Files:"                                                     >> $PRODPATH/$LOGFILE
     echo "             DD_C1BMCOK = $DD_C1BMCOK"                                       >> $PRODPATH/$LOGFILE
     echo "             DD_C1BMNCO = $DD_C1BMNCO"                                       >> $PRODPATH/$LOGFILE
     echo "             DD_PRNTCAS = $DD_PRNTCAS"                                       >> $PRODPATH/$LOGFILE
     echo "             DD_PRNTRPT = $DD_PRNTRPT"                                       >> $PRODPATH/$LOGFILE
     echo "             DD_PRNTXLG = $DD_PRNTXLG"                                       >> $PRODPATH/$LOGFILE
     echo "             DD_C1BMIZP = $DD_C1BMIZP"                                       >> $PRODPATH/$LOGFILE
     echo "             DD_C1BMZP4 = $DD_C1BMZP4"                                       >> $PRODPATH/$LOGFILE
     echo "             DD_CBLOUT = $DD_CBLOUT"                                         >> $PRODPATH/$LOGFILE
     echo "          Parameter and License Files:"                                      >> $PRODPATH/$LOGFILE
     echo "             DD_C1BMPRM = $DD_C1BMPRM"                                       >> $PRODPATH/$LOGFILE
     echo "             DD_G1LICEN = $DD_G1LICEN"                                       >> $PRODPATH/$LOGFILE
     echo "          Code-1 Database Files:"                                            >> $PRODPATH/$LOGFILE
     echo "             DD_CITYDB = $DD_CITYDB"                                         >> $PRODPATH/$LOGFILE
     echo "             DD_CITYNM = $DD_CITYNM"                                         >> $PRODPATH/$LOGFILE
     echo "             DD_COUNTY = $DD_COUNTY"                                         >> $PRODPATH/$LOGFILE
     echo "             DD_DTLDB = $DD_DTLDB"                                           >> $PRODPATH/$LOGFILE
     echo "             DD_LCLDB = $DD_LCLDB"                                           >> $PRODPATH/$LOGFILE
     echo "             DD_LTMASTR = $DD_LTMASTR"                                       >> $PRODPATH/$LOGFILE
     echo "             DD_PTRDB = $DD_PTRDB"                                           >> $PRODPATH/$LOGFILE
     echo "             DD_ZIPIDX = $DD_ZIPIDX"                                         >> $PRODPATH/$LOGFILE
     echo "             DD_Z4CMSTR = $DD_Z4CMSTR"                                       >> $PRODPATH/$LOGFILE
     echo "          -----------------------------------------------------------------" >> $PRODPATH/$LOGFILE
     
     . $D1APPATH/splbill_s5_v3_called_code1_setup.sh
     $D1APPATH/splbill_s5_v3_called_code1.sh
    # sleep 30

     # Check if the Code1 process has stopped, if so, continue 
     #while ps -ef | grep -v grep | grep splbill_s5_v3_called_code1.sh                   >> $PRODPATH/junk.log
     while ps -ef | grep -v grep | grep runc1bm00                  >> $PRODPATH/junk.log
     do
       wait
     done 

     echo "Step 05:  Address Cleansing complete"                                        >> $PRODPATH/$LOGFILE
     echo "===========================================================================" >> $PRODPATH/$LOGFILE
fi


# ***********************************************************************************
#    Step 06:  Identify Special Handling Bills (DOC1PCE)                            *
# ==================================================================================*
#  There are two possible types of special handling Bills:  Oversized Bills and     *
#  "Intercepted" Bills.  Oversized bills contain more pages than the inserter       *
#  can fit into an envelope and must be manually handled.  The SPL marks a Bill     *
#  for review because of some event that has occurred with the account - the        *
#  Intercepted Bill is to be reviewed by a Customer Service Representative          *
#  prior to mailing.  Because these two types of special handling bills are not     *
#  included with the automated mailing, they must be excluded from the input to     *
#  MailStream; otherwise, MailStream postage calculations would not accurately      *
#  reflect the mailing.  A PCE application will read the Corrected USA              *
#  Name/Address Journal (created in Step 04) and create two output journals -       *
#  one for special handling and the other containing all automated bills.           *
# ==================================================================================*
#   Input Files                                                                     *
#      CORRECTED_NAME_ADDRESS_JOURNAL                                               *
#              - Name of the USA Name-Address Journal file containing USA           *
#                addressed records where the address has been corrected (if         *
#                needed), formatted per USPS requirements, a Carrier Route has      *
#                been identified, a 12-byte Delivery Point Bar Code (DPBC) has      *
#                been identified, and Output detSPLination data triggers            *
#              - This file was output into the PRODPATH directory by Step 04        *
#   Configuration Files                                                             *
#      SPCL_PCE_INI                                                                 *
#              - Name of the DOC1PCE Initialization File                            *
#              - This file must be in the D1APPATH directory prior to running       *
#                this .SH process                                                   *
#      SPCL_PCE_CTL                                                                 *
#              - Name of the DOC1PCE Rules to separate Special Handling Bills       *
#              - This file must be in the D1APPATH directory prior to running       *
#                this .SH process                                                   *
#   Output Files                                                                    *
#      AUTOMATED_NAME_ADDRESS_JOURNAL                                               *
#              - Name of the Name-Address Journal file containing USA addressed     *
#                Bills (or Letters) that require no special handling;               *
#              - This file will be written to the PRODPATH directory                *
#              - This .SH process will delete previous versions of this file        *
#      SPCLHNDL_NAME_ADDRESS_JOURNAL                                          *
#              - Name of the Name-Address Journal containing foreign addressed      *
#                Bills (or Letters) and Output detSPLination data triggers          *
#              - This file will be a subset of the NAME-ADDRESS-JOURNAL input       *
#              - This file will be written to the PRODPATH directory                *
#              - This .SH process will delete previous versions of this file        *
#      SPCLHNDL_SPLIT_LOGFILE                                                 *
#              - Name of the file containing messages from the PCE process          *
#              - This file will be written to the PRODPATH directory                *
#              - This .SH process will delete previous versions of this file        *
# ***********************************************************************************

AUTOMATED_NAME_ADDRESS_JOURNAL=bill_automated_name_address_journal.jrn;                 export AUTOMATED_NAME_ADDRESS_JOURNAL
SPCLHNDL_NAME_ADDRESS_JOURNAL=bill_special_handle_name_address_journal.jrn;             export SPCLHNDL_NAME_ADDRESS_JOURNAL
SPCLHNDL_SPLIT_LOGFILE=bill_special_handle_name_address_journal.log;                    export SPCLHNDL_SPLIT_LOGFILE

echo "Step 06:  Identify Special Handling Bills (DOC1PCE)" 
echo "Step 06:  Identify Special Handling Bills (DOC1PCE)"                              >> $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 "             CORRECTED_NAME_ADDRESS_JOURNAL = $CORRECTED_NAME_ADDRESS_JOURNAL"    >> $PRODPATH/$LOGFILE
echo "          Output Files:"                                         	                >> $PRODPATH/$LOGFILE
echo "             AUTOMATED_NAME_ADDRESS_JOURNAL = $AUTOMATED_NAME_ADDRESS_JOURNAL"    >> $PRODPATH/$LOGFILE
echo "             SPCLHNDL_NAME_ADDRESS_JOURNAL = $SPCLHNDL_NAME_ADDRESS_JOURNAL"      >> $PRODPATH/$LOGFILE
echo "             SPCLHNDL_SPLIT_LOGFILE = $SPCLHNDL_SPLIT_LOGFILE"                    >> $PRODPATH/$LOGFILE
echo "          Configuration Files:"                                                   >> $PRODPATH/$LOGFILE
echo "             SPCL_PCE_INI = $SPCL_PCE_INI"                                        >> $PRODPATH/$LOGFILE
echo "             SPCL_PCE_CTL = $SPCL_PCE_CTL"                                        >> $PRODPATH/$LOGFILE
echo "             FMETRIC = $FMETRIC"                                                  >> $PRODPATH/$LOGFILE
echo "          Control Settings:"                                                      >> $PRODPATH/$LOGFILE
echo "             MAXAUTO = $MAXAUTO"                                                  >> $PRODPATH/$LOGFILE
echo "          -------------------------------------------------------------------"    >> $PRODPATH/$LOGFILE

# delete Step 06 Output Files from previous run
rm -f $PRODPATH/$AUTOMATED_NAME_ADDRESS_JOURNAL
rm -f $PRODPATH/$SPCLHNDL_NAME_ADDRESS_JOURNAL
rm -f $PRODPATH/$SPCLHNDL_SPLIT_LOGFILE

$D1APPATH/splbill_s5_v3_called_spclsplt_pce.sh

if [ $? -ne 0 ]
   then     
     cat $PRODPATH/$SPCLHNDL_SPLIT_LOGFILE >> $PRODPATH/$LOGFILE
     echo "DOC1PCE Error (Separate Special Handle Bills) - Process Halting"
     echo "DOC1PCE Error (Separate Special Handle Bills) - Process Halting"             >> $PRODPATH/$LOGFILE
     exit 
fi

cat $PRODPATH/$SPCLHNDL_SPLIT_LOGFILE >> $PRODPATH/$LOGFILE
echo "Step 06:  DOC1PCE Complete - Special Handle Bills Separated"                      >> $PRODPATH/$LOGFILE
echo "=============================================================================="   >> $PRODPATH/$LOGFILE

# ***********************************************************************************
#    Step 07:  Sort Special Handling Journal Records                                *
# ==================================================================================*
#  The Special Handling Journal output in Step 06 is sorted by Country Code so      *
#  that these Bills, when printed, will be printed in Country Code order.           *
# ==================================================================================*
#   Input Files                                                                     *
#      SPCLHNDL_NAME_ADDRESS_JOURNAL                                                *
#              - Name of the Name-Address Journal containing Special Handling       *
#                Bills and Output detSPLination data triggers                       *
#   Output Files                                                                    *
#      SPCLHNDL_SORTED_NAME_ADDRESS_JOURNAL                                         *
#              - Name of the Name-Address Journal now sorted by Country Code        *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#   Configuration Files                                                             *
#      -- none --                                                                   *
# ***********************************************************************************
SPCLHNDL_SORTED_NAME_ADDRESS_JOURNAL=bill_special_handle_sorted_name_address_journal.jrn; export SPCLHNDL_SORTED_NAME_ADDRESS_JOURNAL

echo "Step 09:  Sort Special Handling Journal Records"
echo "Step 09:  Sort Special Handling Journal Records"                                  >> $PRODPATH/$LOGFILE
echo "          Directories:"                                                           >> $PRODPATH/$LOGFILE
echo "             PRODPATH = $PRODPATH"                                                >> $PRODPATH/$LOGFILE
echo "          Input Files:"                                                           >> $PRODPATH/$LOGFILE
echo "             SPCLHNDL_NAME_ADDRESS_JOURNAL = $SPCLHNDL_NAME_ADDRESS_JOURNAL"      >> $PRODPATH/$LOGFILE
echo "          Output Files:"                                                          >> $PRODPATH/$LOGFILE
echo "             SPCLHNDL_SORTED_NAME_ADDRESS_JOURNAL = $SPCLHNDL_SORTED_NAME_ADDRESS_JOURNAL" >> $PRODPATH/$LOGFILE
echo "          --------------------------------------------------------------"         >> $PRODPATH/$LOGFILE

# Delete Sort output files
rm -f $PRODPATH/$SPCLHNDL_SORTED_NAME_ADDRESS_JOURNAL

$D1APPATH/splbill_s5_v3_called_special_sort.sh

if [ $? -ne 0 ]
   then     
     echo "        Sort Error (Sort Special Handling Journal) - Process Halting"
     echo "        Sort Error (Sort Special Handling Journal) - Process Halting"        >> $PRODPATH/$LOGFILE
     exit 16
fi

echo "Step 07:  Sort Complete - Special Handling Bill Journal Sorted"          	        >> $PRODPATH/$LOGFILE
echo "======================================================================== "	>> $PRODPATH/$LOGFILE

# ***********************************************************************************
#    Step 08:  Postal Pre-Sort (MailStream)                                         *
# ==================================================================================*
#  MailStream Plus is the Group1 product that detSPLines USPS Pre-Sorting and       *
#  calculates postage.  MailStream also adds the USPS Manifest data to its          *
#  output journal.  The Step 09 PCE application will use the MailStream             *
#  produced journal to place the Manifest data on the bills and produce an          *
#  automated print file in the Pre-Sort sequence.  The USPS Postage Report is       *
#  produced by MailStream.                                                          *
# ==================================================================================*
#   Input Files                                                                     *
#      AUTOMATED_NAME_ADDRESS_JOURNAL                                               *
#              - Name of the Name-Address Journal file containing USA addressed     *
#                Bills that require no special handling;                            *
#              - This file was output into the $PRODPATH directory by Step 05       *
#   Configuration Files                                                             *
#      MSPRM                                                                        *
#              - Name of the MailStream Parameter File                              *
#              - This file must be in the $D1APPATH directory                       *
#   Output Files                                                                    *
#      PRESORTED_JOURNAL                                                            *
#              - Name of the USA Name-Address Journal file containing USA           *
#                addressed records where the address has been corrected and         *
#                Pre-Sorted to qualify for USPS discounted postage                  *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#      MSRSM                                                                        *
#              - Name of the MailStream USPS Postage 3600 Report                    *
#              - This file will be written to the $G1MSP/data/ directory            *
#              - This .SH process will delete previous versions of this file        *
#      MSTREAM_STATISTICS                                                           *
#              - Name of the MailStream Statistics Report                           *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#      MSTREAM_RLG                                                                  *
#              - Name of the MailStream Log                                         *
#              - This file will be written to the $G1MSP/data/ directory            *
#              - This .SH process will delete previous versions of this file        *
# ==================================================================================*
#  NOTE:  This step may be bypassed by coding MSTREAM=N in the master .SH file      *
#         When coded, this SH will simply make a COPY of the input file to          *
#         the output file name.                                                     *
# ***********************************************************************************

MSTREAM_JOB=bill;                                                                       export MSTREAM_JOB
PRESORTED_JOURNAL=bill_presorted_usa_name_address_journal.jrn;                          export PRESORTED_JOURNAL
MSRSM=$G1MSP/data/$MSTREAM_JOB.RSM;                                                     export MSRSM
USPS_POSTAGE_REPORT=bill_USPS_3600_postage_report.rsm;                                  export USPS_POSTAGE_REPORT
MSTREAM_STATISTICS=bill_mstream_stats.rna;                                              export MSTREAM_STATISTICS
MSTREAM_RLG=$G1MSP/data/$MSTREAM_JOB.rlg;                                               export MSTREAM_RLG

MSTREAM_XLG=bill_mailstream_log.xlg;                                                    export MSTREAM_XLG
MSTREAM_MANIFEST=bill_mstream_manifest.rrp;                                             export MSTREAM_MANIFEST

# Report Files                                                                             
DD_MSRPFAC="$PRODPATH/${MSTREAM_JOB}.rfs";	                                            export DD_MSRPFAC
DD_MSRPPLT="$PRODPATH/${MSTREAM_JOB}.plt";	                                            export DD_MSRPPLT
DD_MSRPRPT="$PRODPATH/$MSTREAM_STATISTICS";	                                            export DD_MSRPRPT
DD_MSRPSTM="$PRODPATH/$USPS_POSTAGE_REPORT";	                                          export DD_MSRPSTM
DD_MSRPTAG="$PRODPATH/${MSTREAM_JOB}.rbt";	                                            export DD_MSRPTAG
DD_MSRDBTF="$PRODPATH/${MSTREAM_JOB}.btf";                                              export DD_MSRDBTF

# Alternate Print files
DD_AUDITTRL="$PRODPATH/${MSTREAM_JOB}_audittrl.rpt";	                                export DD_AUDITTRL
DD_CONFIRM="$PRODPATH/${MSTREAM_JOB}_confirm.rpt";	                                  export DD_CONFIRM
DD_CRRTWALK="$PRODPATH/${MSTREAM_JOB}_crrtwalk.rpt";	                                export DD_CRRTWALK
DD_DETAIL="$PRODPATH/${MSTREAM_JOB}_detail.rpt";		                                  export DD_DETAIL
DD_MAILDAT="$PRODPATH/${MSTREAM_JOB}_maildat.rpt";	                                export DD_MAILDAT
DD_PALSUMM="$PRODPATH/${MSTREAM_JOB}_palsumm.rpt";	                                export DD_PALSUMM
DD_MANIFEST="$PRODPATH/${MSTREAM_JOB}_manifest.rpt";                                    export DD_MANIFEST
DD_RUNSTATS="$PRODPATH/${MSTREAM_JOB}_runstats.rpt";	                                export DD_RUNSTATS
DD_SUMMARY="$PRODPATH/${MSTREAM_JOB}_summary.rpt";	                                export DD_SUMMARY
DD_ZONESUMM="$PRODPATH/${MSTREAM_JOB}_zonesumm.rpt";	                                export DD_ZONESUMM
DD_ZSDETAIL="$PRODPATH/${MSTREAM_JOB}_zsdetail.rpt";	                                export DD_ZSDETAIL
                                                                               
DD_MSSTIN="$PRODPATH/$AUTOMATED_NAME_ADDRESS_JOURNAL";	                                export DD_MSSTIN    # Name and Address Input
DD_MSNAON="$PRODPATH/$PRESORTED_JOURNAL";		                                export DD_MSNAON
DD_MSRPXLG="$PRODPATH/$MSTREAM_XLG";		                                        export DD_MSRPXLG
DD_MANIFEST="$PRODPATH/$MSTREAM_MANIFEST";		                                export DD_MANIFEST
DD_USPSQUAL="$PRODPATH/$MSTREAM_STATISTICS";	                                        export DD_USPSQUAL
DD_USPSSTMT="$PRODPATH/$USPS_POSTAGE_REPORT";	                                        export DD_USPSSTMT
DD_G1LICEN=${G1MSP}/data/G1LMLIC;                                                       export DD_G1LICEN

# NOTE: The following 2 lines are used to create the Mail.dat file names
G1MDPC="AAAA";			                                                        export G1MDPC
G1MDFS="0001";			                                                        export G1MDFS
                                                                                   
# Postal Reference Files
DD_MSRFDC=$G1DB/PRFDLVCT;                                                               export DD_MSRFDC
DD_MSRFDI=$G1DB/PRFDSTNM;                                                               export DD_MSRFDI
DD_MSRFMP=$G1DB/PRFRTMAP;                                                               export DD_MSRFMP
DD_MSRFPS=$G1DB/PRFPSTMT;                                                               export DD_MSRFPS
DD_MSRFSQ=$G1DB/PRFSQREF;                                                               export DD_MSRFSQ
DD_MSRFZD=$G1DB/PRFZIPDR;                                                               export DD_MSRFZD
DD_MSRFZM=$G1DB/PRFZONES;                                                               export DD_MSRFZM
DD_MSRFGH=$G1DB/PRFGRAY.TXT;                                                            export DD_MSRFGH

# Parm File                                                                        
DD_MSPRICP="$D1APPATH/$MSPRM";                                                          export DD_MSPRICP
                                                                                   
# Generated Files                                                                                                                 
DD_MSSTON="$PRODPATH/${MSTREAM_JOB}.son";		                                export DD_MSSTON
DD_MSSTOR="$PRODPATH/${MSTREAM_JOB}.sor";		                                export DD_MSSTOR
DD_MSWKCF="$PRODPATH/${MSTREAM_JOB}.ctl";		                                export DD_MSWKCF
DD_MSWKCM="$PRODPATH/${MSTREAM_JOB}.rsf";		                                export DD_MSWKCM
DD_MSWKES="$PRODPATH/${MSTREAM_JOB}.dwf";		                                export DD_MSWKES
DD_MSWKNRC="$PRODPATH/${MSTREAM_JOB}.nrc";	                                        export DD_MSWKNRC
DD_MSWKMS="$PRODPATH/${MSTREAM_JOB}.mdt";		                                export DD_MSWKMS
DD_MSWKSS="$PRODPATH/${MSTREAM_JOB}.sos";		                                export DD_MSWKSS
DD_MSRDBAG="$PRODPATH/${MSTREAM_JOB}.bar";	                                        export DD_MSRDBAG
DD_MSRDPLT="$PRODPATH/${MSTREAM_JOB}.lab";	                                        export DD_MSRDPLT
DD_MSRDTRA="$PRODPATH/${MSTREAM_JOB}.tra";	                                        export DD_MSRDTRA
                                                                                                                                                                         
# Mail.dat Files
DD_MSMDCLR="${G1MSP}/data/${G1MDPC}${G1MDFS}.clr";	                                export DD_MSMDCLR
DD_MSMDCPT="${G1MSP}/data/${G1MDPC}${G1MDFS}.cpt";	                                export DD_MSMDCPT
DD_MSMDCQT="${G1MSP}/data/${G1MDPC}${G1MDFS}.cqt";	                                export DD_MSMDCQT
DD_MSMDCSM="${G1MSP}/data/${G1MDPC}${G1MDFS}.csm";	                                export DD_MSMDCSM
DD_MSMDHDR="${G1MSP}/data/${G1MDPC}${G1MDFS}.hdr";	                                export DD_MSMDHDR
DD_MSMDICR="${G1MSP}/data/${G1MDPC}${G1MDFS}.icr";                                      export DD_MSMDICR
DD_MSMDMCR="${G1MSP}/data/${G1MDPC}${G1MDFS}.mcr";	                                export DD_MSMDMCR
DD_MSMDMIR="${G1MSP}/data/${G1MDPC}${G1MDFS}.mir";	                                export DD_MSMDMIR
DD_MSMDMPA="${G1MSP}/data/${G1MDPC}${G1MDFS}.mpa";                                      export DD_MSMDMPA
DD_MSMDMPU="${G1MSP}/data/${G1MDPC}${G1MDFS}.mpu";	                                export DD_MSMDMPU
DD_MSMDPDR="${G1MSP}/data/${G1MDPC}${G1MDFS}.pdr";                                      export DD_MSMDPDR
DD_MSMDPLR="${G1MSP}/data/${G1MDPC}${G1MDFS}.plr";	                                export DD_MSMDPLR
DD_MSMDPQT="${G1MSP}/data/${G1MDPC}${G1MDFS}.pqt";	                                export DD_MSMDPQT
DD_MSMDSEG="${G1MSP}/data/${G1MDPC}${G1MDFS}.seg";	                                export DD_MSMDSEG
DD_MSMDSNR="${G1MSP}/data/${G1MDPC}${G1MDFS}.snr";	                                export DD_MSMDSNR
DD_MSMDSPR="${G1MSP}/data/${G1MDPC}${G1MDFS}.spr";	                                export DD_MSMDSPR
DD_MSMDWSR="${G1MSP}/data/${G1MDPC}${G1MDFS}.wsr";	                                export DD_MSMDWSR
DD_MSRDCF="${G1MSP}/data/${G1MDPC}${G1MDFS}.dcf";	                                export DD_MSRDCF
DD_MSRDEM="${G1MSP}/data/${G1MDPC}${G1MDFS}.emd";	                                export DD_MSRDEM

# Temporary Files
DD_MSWKDT="$PRODPATH/${MSTREAM_JOB}.pdt";			                        export DD_MSWKDT
DD_MSWKNS="$PRODPATH/${MSTREAM_JOB}.nns";			                        export DD_MSWKNS
DD_MSWKQS="$PRODPATH/${MSTREAM_JOB}.qso";			                        export DD_MSWKQS
DD_MSWKZS="$PRODPATH/${MSTREAM_JOB}.rzs";			                        export DD_MSWKZS
DD_MSWKS1="$PRODPATH/${MSTREAM_JOB}.ws1";			                        export DD_MSWKS1
DD_MSWKS2="$PRODPATH/${MSTREAM_JOB}.ws2";			                        export DD_MSWKS2
DD_MSWKS3="$PRODPATH/${MSTREAM_JOB}.ws3";			                        export DD_MSWKS3
DD_MSWKTMP="$PRODPATH/${MSTREAM_JOB}.tmp";			                        export DD_MSWKTMP
DD_MSWKZ1="$PRODPATH/${MSTREAM_JOB}.wz1";			                        export DD_MSWKZ1
DD_MSWKZ2="$PRODPATH/${MSTREAM_JOB}.wz2";			                        export DD_MSWKZ2
DD_MSWKWK="$PRODPATH/${MSTREAM_JOB}.tbl";			                        export DD_MSWKWK

# delete Step 09 Output Files from previous run
rm -f $PRODPATH/$PRESORTED_JOURNAL
rm -f $PRODPATH/$MSTREAM_STATISTICS
rm -f $PRODPATH/$MSRSM

if [ $MSTREAM = N ]

   then

     echo "Step 08:  Mailstream bypassed - COPY substituted"
     echo "Step 08:  Mailstream bypassed - COPY substituted"                   		>> $PRODPATH/$LOGFILE

     echo " cp $PRODPATH/$AUTOMATED_NAME_ADDRESS_JOURNAL  $PRODPATH/$PRESORTED_JOURNAL" >> $PRODPATH/$LOGFILE
     cp $PRODPATH/$AUTOMATED_NAME_ADDRESS_JOURNAL  $PRODPATH/$PRESORTED_JOURNAL

     echo "Step 08:  $PRODPATH/$AUTOMATED_NAME_ADDRESS_JOURNAL copied $PRODPATH/$PRESORTED_JOURNAL"   >> $PRODPATH/$LOGFILE
     echo "=============================================================================="          >> $PRODPATH/$LOGFILE
     
   else

     echo "Step 08:  Postal Pre-Sort (MailStream)"
     echo "Step 08:  Postal Pre-Sort (MailStream)"                                      >> $PRODPATH/$LOGFILE
     echo "          Directories:"                                                        >> $PRODPATH/$LOGFILE
     echo "             G1MSP = $G1MSP"                                                   >> $PRODPATH/$LOGFILE
     echo "             G1MSPDB = $G1MSPDB"                                               >> $PRODPATH/$LOGFILE
     echo "             PRODPATH = $PRODPATH"                                             >> $PRODPATH/$LOGFILE
     echo "          Input Files:"                                                        >> $PRODPATH/$LOGFILE
     echo "             AUTOMATED_NAME_ADDRESS_JOURNAL = $AUTOMATED_NAME_ADDRESS_JOURNAL" >> $PRODPATH/$LOGFILE
     echo "          Output Files:"                                                       >> $PRODPATH/$LOGFILE
     echo "             PRESORTED_JOURNAL = $PRESORTED_JOURNAL"                           >> $PRODPATH/$LOGFILE
     echo "             USPS_POSTAGE_REPORT = $MSRSM"                                     >> $PRODPATH/$LOGFILE
     echo "             MSTREAM_STATISTICS = $MSTREAM_STATISTICS"                         >> $PRODPATH/$LOGFILE
     echo "             MSTREAM_RLG = $MSTREAM_RLG"                                       >> $PRODPATH/$LOGFILE
     echo "          Report Files:"                                                       >> $PRODPATH/$LOGFILE
     echo "             DD_MSRPFAC = $DD_MSRPFAC"                                         >> $PRODPATH/$LOGFILE
     echo "             DD_MSRPPLT = $DD_MSRPPLT"                                         >> $PRODPATH/$LOGFILE
     echo "             DD_MSRPRPT = $DD_MSRPRPT"                                         >> $PRODPATH/$LOGFILE
     echo "             DD_MSRPSTM = $DD_MSRPSTM"                                         >> $PRODPATH/$LOGFILE
     echo "             DD_MSRPTAG = $DD_MSRPTAG"                                         >> $PRODPATH/$LOGFILE
     echo "             DD_MSRPXLG = $DD_MSRPXLG"                                         >> $PRODPATH/$LOGFILE
     echo "          MailStream Parameter File:"                                          >> $PRODPATH/$LOGFILE
     echo "             DD_MSPRICP = $DD_MSPRICP"                                         >> $PRODPATH/$LOGFILE
     echo "          Temporary Files:"                                                    >> $PRODPATH/$LOGFILE
     echo "             DD_MSWKDT = $DD_MSWKDT"                                           >> $PRODPATH/$LOGFILE
     echo "             DD_MSWKNS = $DD_MSWKNS"                                           >> $PRODPATH/$LOGFILE
     echo "             DD_MSWKQS = $DD_MSWKQS"                                           >> $PRODPATH/$LOGFILE
     echo "             DD_MSWKZS = $DD_MSWKZS"                                           >> $PRODPATH/$LOGFILE
     echo "             DD_MSWKS1 = $DD_MSWKS1"                                           >> $PRODPATH/$LOGFILE
     echo "             DD_MSWKS2 = $DD_MSWKS2"                                           >> $PRODPATH/$LOGFILE
     echo "             DD_MSWKS3 = $DD_MSWKS3"                                           >> $PRODPATH/$LOGFILE
     echo "             DD_MSWKTMP = $DD_MSWKTMP"                                         >> $PRODPATH/$LOGFILE
     echo "             DD_MSWKZ1 = $DD_MSWKZ1"                                           >> $PRODPATH/$LOGFILE
     echo "             DD_MSWKZ2 = $DD_MSWKZ2"                                           >> $PRODPATH/$LOGFILE
     echo "             DD_MSWKWK = $DD_MSWKWK"                                           >> $PRODPATH/$LOGFILE
     echo "          -------------------------------------------------------------------" >> $PRODPATH/$LOGFILE

     . $D1APPATH/splbill_s5_v3_called_mstream_setup.sh
     . $D1APPATH/splbill_s5_v3_called_runmsp.sh $MSPRM


     #while ps -ef | grep -v grep | grep MS                    >> $PRODPATH/junk.log
     #do
     #  wait
     #done 
     sleep 120

     if [ $? -ne 0 ]
        then     
          cat $PRODPATH/$MSTREAM_XLG               >> $PRODPATH/$LOGFILE
          cat $PRODPATH/$MSTREAM_STATISTICS        >> $PRODPATH/$LOGFILE
          cat $PRODPATH/$USPS_POSTAGE_REPORT       >> $PRODPATH/$LOGFILE
          echo "MailStream Error - Process Halting"
          echo "MailStream Error - Process Halting"                                     >> $PRODPATH/$LOGFILE
          exit 16
     fi

     cat $PRODPATH/$MSTREAM_XLG         >> $PRODPATH/$LOGFILE
     cat $PRODPATH/$MSTREAM_STATISTICS  >> $PRODPATH/$LOGFILE
     cat $PRODPATH/$USPS_POSTAGE_REPORT >> $PRODPATH/$LOGFILE

     echo "Step 08:  USPS Pre-Sort complete"                                            >> $PRODPATH/$LOGFILE
     echo "==============================================================================" >> $PRODPATH/$LOGFILE

fi

# ***********************************************************************************
#    Step 09:  Create Print Files (DOC1PCE)                                         *
# ==================================================================================*
#  This PCE application creates the final print files.  The Automated Bills         *
#  will be printed in USPS Pre-Sort sequence and will have OMR Marks for the        *
#  inserter.  The Foreign Address Bills, Intercepted Bills, and Oversized Bills     *
#  will not contain OMR Marks and will be printed in their original sequence        *
#  into DOC1GEN.                                                                    *
# ==================================================================================*
#   Input Files                                                                     *
#      INTERMEDIATE_PRINT                                                           *
#              - Name of the file containing all formatted Bills (or Letters)       *
#              - This file was output into the $PRODPATH directory by Step 02       *
#      FRGN_SORTED_NAME_ADDRESS_JOURNAL                                             *
#              - Name of the Name-Address Journal now sorted by Country Code        *
#              - This file was output into the $PRODPATH directory by Step 04       *
#      SPCLHNDL_SORTED_NAME_ADDRESS_JOURNAL                                         * 
#              - Name of the Name-Address Journal now sorted by Country Code        *
#              - This file was output into the $PRODPATH directory by Step 08       *
#      PRESORTED_JOURNAL                                                            *
#              - Name of the USA Name-Address Journal file containing USA           *
#                addressed records where the address has been corrected and         *
#                Pre-Sorted to qualify for USPS discounted postage                  *
#              - This file was output into the $PRODPATH directory by Step 06       *
#   Configuration Files                                                             *
#      CPRT_PCE_INI                                                                 *
#              - Name of the DOC1PCE Initialization File                            *
#              - This file must be in the $D1APPATH directory prior to running      *
#                this .SH process                                                   *
#      CPRT_PCE_CTL                                                                 *
#              - Name of the DOC1PCE Rules to create Print Files                    *
#              - This file must be in the $D1APPATH directory prior to running      *
#                this .SH process                                                   *
#      GEN_HIP                                                                      *
#              - Name of the HIP file containing font metric info                   *
#              - This file must be in the $D1APPATH directory prior to running      *
#                this .SH process                                                   *
#   Output Files                                                                    *
#      AUTOMATED-BILLS-PRINT                                                        *
#              - Name of the formatted Print file containing Automated Bills        *
#                that require no special handling;                                  *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#      REJECTED-BILLS-PRINT                                                         *
#              - Name of the formatted Print file containing Rejected Address       *
#                Bills (or Letters) that require manual intervention                *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#      FOREIGN-BILLS-PRINT                                                          *
#              - Name of the formatted Print file containing Foreign Addressed      *
#                Bills (or Letters) that do require special handling;               *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#      INTERCEPTED-BILLS-PRINT                                                      *
#              - Name of the formatted Print file containing Intercepted Bills      *
#                (or Letters) that do require special handling;                     *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#      OVERSIZED-BILLS-PRINT                                                        *
#              - Name of the formatted Print file containing Oversized Bills        *
#                (or Letters) that do require special handling;                     *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#      FINALCB-BILLS-PRINT                                                          *
#              - Name of the formatted Print file containing Final Bills with a     *
#                Credit Balance that do require special handling;                   *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#      AUDIT-FILE                                                                   *
#              - Name of the file containing messages from the PCE process          *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
#      POST-PROCESS-LOGFILE                                                         *
#              - Name of the file containing messages from the PCE process          *
#              - This file will be written to the $PRODPATH directory               *
#              - This .SH process will delete previous versions of this file        *
# ***********************************************************************************
TIMESTAMP=`date +%Y%m%d%H%M%S`                                                          export  TIMESTAMP

AUTOMATED_BILLS_PRINT=bill_automated_print_$TIMESTAMP.ps;                                          export AUTOMATED_BILLS_PRINT
REJECTED_BILLS_PRINT=bill_rejected_print_$TIMESTAMP.ps;                                            export REJECTED_BILLS_PRINT
INTERCEPTED_BILLS_PRINT=bill_intercepted_print_$TIMESTAMP.ps;                                      export INTERCEPTED_BILLS_PRINT
FRGN_BILLS_PRINT=bill_foreign_print_$TIMESTAMP.ps;                                                 export FRGN_BILLS_PRINT
FRGN_JOURNAL=bill_frgn_name_address_journal_$TIMESTAMP.jrn;                                        export FRGN_JOURNAL
OVERSIZED_BILLS_PRINT=bill_oversized_print_$TIMESTAMP.ps;                                          export OVERSIZED_BILLS_PRINT
FINALCB_BILLS_PRINT=bill_finalcb_print_$TIMESTAMP.ps;                                              export FINALCB_BILLS_PRINT
AUDIT_FILE=bill_special_audit_file_$TIMESTAMP.adt;                                                 export AUDIT_FILE
POST_PROCESS_LOGFILE=bill_create_print_logfile.log;                                     export POST_PROCESS_LOGFILE

echo "Step 09:  Create Print Files (DOC1PCE)" 
echo "Step 09:  Create Print Files (DOC1PCE)"                                                     >> $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 "             INTERMEDIATE_PRINT = $INTERMEDIATE_PRINT"                                      >> $PRODPATH/$LOGFILE
echo "             FRGN_SORTED_NAME_ADDRESS_JOURNAL = $FRGN_SORTED_NAME_ADDRESS_JOURNAL"          >> $PRODPATH/$LOGFILE
echo "             SPCLHNDL_SORTED_NAME_ADDRESS_JOURNAL = $SPCLHNDL_SORTED_NAME_ADDRESS_JOURNAL"  >> $PRODPATH/$LOGFILE
echo "             REJECTED_ADDRESS_JOURNAL = $NCO_JOURNAL"                                       >> $PRODPATH/$LOGFILE
echo "             PRESORTED_JOURNAL = $PRESORTED_JOURNAL"                                        >> $PRODPATH/$LOGFILE
echo "          Output Files:"                                                                    >> $PRODPATH/$LOGFILE
echo "             AUTOMATED_BILLS_PRINT = $AUTOMATED_BILLS_PRINT"                                >> $PRODPATH/$LOGFILE
echo "             FRGN_BILLS_PRINT = $FRGN_BILLS_PRINT"                                          >> $PRODPATH/$LOGFILE
echo "             INTERCEPTED_BILLS_PRINT = $INTERCEPTED_BILLS_PRINT"                            >> $PRODPATH/$LOGFILE
echo "             OVERSIZED_BILLS_PRINT = $OVERSIZED_BILLS_PRINT"                                >> $PRODPATH/$LOGFILE
echo "             FINALCB_BILLS_PRINT = $FINALCB_BILLS_PRINT"                                    >> $PRODPATH/$LOGFILE
echo "             REJECTED_BILLS_PRINT = $REJECTED_BILLS_PRINT"                                  >> $PRODPATH/$LOGFILE
echo "             AUDIT_FILE = $AUDIT_FILE"                                                      >> $PRODPATH/$LOGFILE
echo "             POST_PROCESS_LOGFILE = $POST_PROCESS_LOGFILE"                                  >> $PRODPATH/$LOGFILE
echo "          Configuration Files:"                                                             >> $PRODPATH/$LOGFILE
echo "             CPRT_PCE_INI = $CPRT_PCE_INI"                                                  >> $PRODPATH/$LOGFILE
echo "             CPRT_PCE_CTL = $CPRT_PCE_CTL"                                                  >> $PRODPATH/$LOGFILE
echo "          Printer Settings:"                                                                >> $PRODPATH/$LOGFILE
echo "             PSTREAM = $PSTREAM"                                                            >> $PRODPATH/$LOGFILE
echo "             PRES = $PRES"                                                                  >> $PRODPATH/$LOGFILE
echo "             PRINT = $PRINT"                                                                >> $PRODPATH/$LOGFILE
echo "          Control Settings:"                                                                >> $PRODPATH/$LOGFILE
echo "             MAXAUTO = $MAXAUTO"                                                            >> $PRODPATH/$LOGFILE
echo "          ---------------------------------------------------------------------------"      >> $PRODPATH/$LOGFILE

# delete Step 09 Output Files from previous run
# since we time stamp the prit files we do not delete them
#rm -f $PRODPATH/$AUTOMATED_BILLS_PRINT
#rm -f $PRODPATH/$REJECTED_BILLS_PRINT
#rm -f $PRODPATH/$FRGN_BILLS_PRINT
#rm -f $PRODPATH/$INTERCEPTED_BILLS_PRINT
#rm -f $PRODPATH/$OVERSIZED_BILLS_PRINT
#rm -f $PRODPATH/$FINALCB_BILLS_PRINT
#rm -f $PRODPATH/$AUDIT_FILE
#rm -f $PRODPATH/$POST_PROCESS_LOGFILE

$D1APPATH/splbill_s5_v3_called_createprt_pce.sh

if [ $? -ne 0 ]
   then     
     cat $PRODPATH/$POST_PROCESS_LOGFILE >>$PRODPATH/$LOGFILE
     echo "DOC1PCE Error (Create Print Files) - Process Halting"
     echo "DOC1PCE Error (Create Print Files) - Process Halting"                        >> $PRODPATH/$LOGFILE
     exit 16
fi

cat $PRODPATH/$POST_PROCESS_LOGFILE >>$PRODPATH/$LOGFILE
echo "Step 09:  Print Files Created"                                                    >> $PRODPATH/$LOGFILE
echo "=============================================================================="   >> $PRODPATH/$LOGFILE

echo "=============================================================================="
echo ""
echo "--------------------------Process Completed-----------------------------------"
echo ""
