          SUBROUTINE (OID,GEN,STAT.CODE,INIT.PRT,INVALID.STAT,USE.PO.DFLT.STAT)
** Version# 41.0001[1] - 01/29/2016 - 01:28pm - TSMITH - eclipse

*** Subroutine - OE.STATUS.INIT
*-------------------------------------------------------------------------*
*** This program will set up the default print status according to the
*** current status of the order and whether we are working with a sales
*** order, purchase order, or transfer.
*-------------------------------------------------------------------------*
*** OID          - Order Id Number                                     [IN]
*** GEN          - Order Generation                                    [IN]
*** STAT.CODE    - Current Order Status                                [IN]
*** INIT.PRT     - If Set to 'Y' then we are going to override the     (IN)
***              - current print status with the default status for
***              - that order status
*** INVALID.STAT - Set to 'Y' if the status was invalid               (OUT)
*-------------------------------------------------------------------------*
          MODE         = OID[1,1]

          INVALID.STAT = NO

          ORD.STAT     = STAT.CODE<1,1,1>
          READ LEDL FROM LEDLFILE,OID ELSE LEDL = ''
          PRT.STAT     = LEDL<9,GEN>
          OPRT.STAT    = PRT.STAT

          IF PRT.STAT = '' THEN INIT.PRT = YES

          BEGIN CASE
          CASE MODE = 'S'
             GOSUB SOE.INIT
          CASE MODE = 'P'
             GOSUB POE.INIT
          CASE MODE = 'T'
             GOSUB TOE.INIT
          END CASE

          IF OPRT.STAT # PRT.STAT THEN
             OE.UPD.PRINT.STAT OID,GEN,PRT.STAT
          END ELSE
             * On transfers when the gen is re-opened reset print status
             IF MODE = 'T' AND ORD.STAT = 'O' AND OLED(6)<1,GEN> = 'S' THEN
                OE.UPD.PRINT.STAT OID,GEN,PRT.STAT
             END
          END

          RETURN
*-------------------------------------------------------------------------*
SOE.INIT: BEGIN CASE
          CASE ORD.STAT = 'P'
          CASE ORD.STAT = 'L'
             IF INIT.PRT THEN DFLT.NO = 3; GOSUB INIT.PRT
          CASE ORD.STAT = 'A'
             IF INIT.PRT THEN DFLT.NO = 4; GOSUB INIT.PRT
          CASE ORD.STAT = 'S'
             IF INIT.PRT THEN DFLT.NO = 9; GOSUB INIT.PRT
          CASE ORD.STAT = 'H'
             IF INIT.PRT THEN DFLT.NO = 7; GOSUB INIT.PRT
          CASE ORD.STAT = 'C'
             IF INIT.PRT THEN DFLT.NO = 6; GOSUB INIT.PRT
          CASE ORD.STAT = 'X'
          CASE ORD.STAT = 'B'
             IF INIT.PRT THEN DFLT.NO = 2; GOSUB INIT.PRT
          CASE ORD.STAT = 'M'
             IF INIT.PRT THEN DFLT.NO = 5; GOSUB INIT.PRT
          CASE ORD.STAT = 'I'
             IF INIT.PRT THEN
                STAT.SET = NO
                *** For Directs use default print status when available
                IF LEDL<19,GEN> = 'D' THEN
                   DFLT.NO = 18; GOSUB INIT.PRT
                   IF PRT.STAT # '' THEN STAT.SET = YES
                END
                IF NOT(STAT.SET) THEN
                   IF OPRT.STAT = 'M' AND LEDL<17,GEN>#'' THEN
                      CTRB.ID = 'MANIFEST.CLOSE.PRT.OVRD~':LED(2)<1,GEN,2>
                      READV PRT.OVRD FROM CTRBFILE,CTRB.ID,1 ELSE PRT.OVRD=''
                      IF PRT.OVRD = 'M' THEN PRT.OVRD = ''
                      IF PRT.OVRD THEN
                         PRT.STAT = PRT.OVRD
                         STAT.SET = YES
                      END
                   END
                   IF PRT.STAT="P" OR PRT.STAT="B" OR PRT.STAT="N" THEN STAT.SET = NO

                   IF OPRT.STAT # 'M' THEN
                      READV PRT.STAT.V FROM SVIAFILE,LED(70)<1,GEN>,10 ELSE
                         PRT.STAT.V = ''
                      END
                      IF PRT.STAT.V # '' THEN
                         PRT.STAT = PRT.STAT.V
                         STAT.SET = YES
                      END
                   END
                   IF NOT(STAT.SET) THEN
                      DFLT.NO = 17; GOSUB INIT.PRT
                   END
                END

                CREDIT.CARD.CHK.PRT.ST PRT.STAT,OID,GEN

                *** This control record eliminates orders getting sent
                *** to invoice preview queue if invoice print copies is
                *** set to 0 in customer maint
                READ SEND.TO FROM CTRLFILE,'OE.PREVIEW.ZERO.COPIES' ELSE
                   SEND.TO = NO
                END

                PRT.IT = YES
                BEGIN CASE
                CASE PRT.STAT = 'Q' AND NOT(SEND.TO); PRT.IT = NO
                CASE PRT.STAT = 'Q';                  NULL
                CASE PRT.STAT # 'M';                  PRT.IT = NO
                END CASE

                IF NOT(PRT.IT) THEN
*** This following logic must match the corresponding code in
*** SOE.PRINT.INVOICES...  To find it there, search on "REFERENCE".
                   * Check ST first
                   DUP.CT = CUSS(50)<1,1>
                   FAX.CT = CUSS(50)<1,2>
                   USE.SHIPTO = YES

                   * If NULL use BT
                   IF DUP.CT = '' THEN DUP.CT = CUS(50)<1,1>
                   IF FAX.CT = '' THEN
                      FAX.CT = CUS(50)<1,2>
                      USE.SHIPTO = NO
                   END

                   IF DUP.CT = '' AND FAX.CT = '' THEN
                      DUP.CT = 1
                      FAX.CT = 0
                   END ELSE
                      *  Use EDI
                      IF FAX.CT = 'E' THEN
                         IF USE.SHIPTO THEN EDI.PROFILE = CUSS(15)
                         ELSE EDI.PROFILE = CUS(15)
                         UT.EDI.OUTBOUND.GRP.OK EDI.OK,EDI.PROFILE,0
                         IF EDI.OK THEN FAX.CT = 100
                         ELSE
                            FAX.CT = 0
                            E.MSG  = 'Invoice Fax Copies field is set to "E" with no outbound 810 or 857 set up in Trading Partner Maintenance OID='
                            E.MSG := OID:'.':GEN "R%3"
                            SEND.MESSAGE 'EDI','EDI.ADM',E.MSG
                         END
                      END
                      * Do not use Fax
                      IF FAX.CT = '' OR NOT(NUM(FAX.CT)) THEN
                        FAX.CT = 0
                      END
                   END
*** *******************************************************************

                   * Cash/COD and Paid in Full tickets will fall in here
                   BEGIN CASE
                   CASE PRT.STAT = 'B' AND FAX.CT = 0 AND DUP.CT < 0
                      PRT.STAT = 'N'
                   CASE DUP.CT = 0 AND FAX.CT = 0
                      IF NOT(SEND.TO) THEN
                         PRT.STAT = 'N'
                      END
                   END CASE
                   IF PRT.STAT = 'N' THEN
                      OE.UPD.PICK.CONFIRM OID,GEN
                   END
                END
             END
          CASE ORD.STAT = 'D'
             IF INIT.PRT THEN DFLT.NO = 10; GOSUB INIT.PRT
          CASE ORD.STAT = 'Y'
             IF INIT.PRT THEN
                READ USE.VEN FROM CTRLFILE,'USE.VEN.PSTAT.ON.DIRECT' ELSE
                   USE.VEN = ''
                END
                READV PRNT.STAT FROM CUSFILE,LED(5)<1,GEN>,147 ELSE PRNT.STAT =''
                IF PRNT.STAT AND USE.VEN THEN
                   PRT.STAT = PRNT.STAT
                END ELSE
                   READ DFLT.EDI FROM CTRLFILE,'DFLT.EDI.VEN.PSTAT' ELSE
                      DFLT.EDI = ''
                   END
                   READV EDI.VEN FROM CUSFILE,LED(5)<1,GEN>,15 ELSE
                      EDI.VEN = ''
                   END
                   IF DFLT.EDI AND EDI.VEN THEN
                      PRT.STAT = 'E'
                   END ELSE
                      DFLT.NO = 11
                      GOSUB INIT.PRT
                   END
                END
                INVALID.STAT = YES
             END
          CASE ORD.STAT = 'W'
             IF INIT.PRT THEN DFLT.NO = 8; GOSUB INIT.PRT
          CASE ORD.STAT = 'T'
             IF INIT.PRT THEN DFLT.NO = 5; GOSUB INIT.PRT
          CASE OTHERWISE
             INVALID.STAT = YES
          END CASE

          RETURN
*-------------------------------------------------------------------------*
POE.INIT: *** get print status according to the order status

          READV OVRD.PRT.STAT FROM CUSFILE,LED(5)<1,GEN>,147 ELSE
             OVRD.PRT.STAT = ''
          END

          IF LED(96) THEN
             *** if an 850 has already been sent on the original gen, then
             *** LED(96) will be flagged -- if it is flagged AND the vendor
             *** override print style is 'E' for EDI, then don't reset the
             *** print style as we don't want to send another 850.
             IF OVRD.PRT.STAT AND OVRD.PRT.STAT # 'E' THEN
                PRT.STAT = OVRD.PRT.STAT
                RETURN
             END
          END ELSE
             *** ok to check the control file 'EDI Set Status to "E"...'
             *** as long as LED(96) has not been set.
             READ DFLT.EDI FROM CTRLFILE,'DFLT.EDI.VEN.PSTAT' ELSE
                DFLT.EDI = ''
             END
             READV EDI.VEN FROM CUSFILE,LED(5)<1,GEN>,15 ELSE
                EDI.VEN = ''
             END
             IF DFLT.EDI AND EDI.VEN THEN
                PRT.STAT = 'E'
                RETURN
             END
          END
          ***if there's a print status override set on the vendor
          ***we want to use it as the print status
          IF OVRD.PRT.STAT AND USE.PO.DFLT.STAT THEN
             PRT.STAT = OVRD.PRT.STAT
             RETURN
          END
          BEGIN CASE
          CASE ORD.STAT = 'O'
             IF INIT.PRT THEN DFLT.NO = 12; GOSUB INIT.PRT
          CASE ORD.STAT = 'V'
             IF INIT.PRT THEN DFLT.NO = 12; GOSUB INIT.PRT
          CASE ORD.STAT = 'R'
             IF INIT.PRT THEN
                IF TTY.DATA<6>='R' THEN PRT.STAT='N' ELSE
                   DFLT.NO = 13
                   GOSUB INIT.PRT
                END
             END
          CASE ORD.STAT = 'X'
          CASE ORD.STAT = 'B'
             IF INIT.PRT THEN DFLT.NO = 1; GOSUB INIT.PRT
          CASE OTHERWISE
             INVALID.STAT = YES
          END CASE

          RETURN
*-------------------------------------------------------------------------*
TOE.INIT: BEGIN CASE
          CASE ORD.STAT = 'O'
             IF INIT.PRT THEN DFLT.NO = 14; GOSUB INIT.PRT
          CASE ORD.STAT = 'S'
             IF INIT.PRT THEN
                STAT.SET = NO
                IF OPRT.STAT = 'M' THEN
                   CTRB.ID = 'MANIFEST.CLOSE.PRT.OVRD~':LED(2)<1,GEN,2>
                   READV PRT.OVRD FROM CTRBFILE,CTRB.ID,1 ELSE PRT.OVRD=''
                   IF PRT.OVRD = 'M' THEN PRT.OVRD = ''
                   IF PRT.OVRD THEN
                      PRT.STAT = PRT.OVRD
                      STAT.SET = YES
                   END
                END
                IF OPRT.STAT # 'M' THEN
                   READV PRT.STAT.V FROM SVIAFILE,LED(70)<1,GEN>,10 ELSE
                      PRT.STAT.V = ''
                   END
                   OE.PRT.STATUS.GET OID,GEN,'NO',ORD.STAT,NO,PRT.OPTS
                   PRT.OPTS.CT = DCOUNT(PRT.OPTS,VM)
                   FOR PRT.OPTSX = 1 TO PRT.OPTS.CT
                      PRT.OPTS<1,PRT.OPTSX> = PRT.OPTS<1,PRT.OPTSX>[1,1]
                   NEXT PRT.OPTSX
                   IF PRT.STAT.V # '' THEN
                      LOCATE PRT.STAT.V IN PRT.OPTS<1> SETTING JUNK THEN
                         PRT.STAT = PRT.STAT.V
                         STAT.SET = YES
                      END

                   END
                END
                IF NOT(STAT.SET) THEN
                   DFLT.NO = 15; GOSUB INIT.PRT
                END
             END
          CASE ORD.STAT = 'R'
             IF INIT.PRT THEN
                IF TTY.DATA<6>='R' THEN
                   *** When the item is recieved using RF, don't set the
                   *** status to anything but 'N'.
                   PRT.STAT = 'N'
                END ELSE
                   DFLT.NO = 16
                   GOSUB INIT.PRT
                END
             END
          CASE ORD.STAT = 'X'
          CASE OTHERWISE
             INVALID.STAT = YES
          END CASE
          RETURN
*-------------------------------------------------------------------------*
INIT.PRT: IF REMOTE.CUST THEN
             PRT.STAT='N'
          END ELSE
             READ PRT.DFLTS FROM CTRLFILE,'STATUS.PRINT.DFLTS' ELSE DFLT=''
             PRT.STAT = PRT.DFLTS<1,1,DFLT.NO>
             IF PRT.STAT = '' AND DFLT.NO = 10 THEN PRT.STAT = 'N'
          END
          RETURN
!TSMITH~01/29/16~13:28
