          SUBROUTINE (OID,GEN,LDID,OLD.STAT,NEW.STAT,OVRD.LD)
** Version# 5.0001[4] - 02/15/2010 - 09:53pm - SMITJR - eclipse
*** V5.0001 Change - Custom Coding CUSTOM - 02/15/2010 - SMITJR - eclipse

*** Subroutine : OE.CHECK.OVRD.AUTH
*-------------------------------------------------------------------------*
*** This routine checks to see if the user has the authority to keep manual
*** Cost/COGS overrides on an order when it is changed to and from a
*** direct. The user must have the proper auth keys (COGS.EDIT, for
*** example) as well as the proper level (10 or above) in order to keep an
*** override on an order when changing between Direct and Non-Directs.
***
*** NOTE - LD (Ledger Detail) must be active when this routine is called
*-------------------------------------------------------------------------*
*** Parameters:
*** OID      - Order ID                                               [IN]
*** GEN      - Generation ID                                          [IN]
*** LDID     - Ledger Detail ID                                       [IN]
*** OLD.STAT - Old Order Status                                       [IN]
*** NEW.STAT - New Order Status                                       [IN]
*** OVRD.LD  - Indicates if OE.UPDATE.LDID should be called to        (IN)
***            update Ledger Detail (will update if set to yes)
*-------------------------------------------------------------------------*
*** Common:
*** LED - Ledger
*** LD  - Ledger Detail
*-------------------------------------------------------------------------*

          MODE = OID[1,1]

          MATREAD PLNE FROM PLNEFILE,PRD(9)<1,1> ELSE MAT PLNE = ""
          COGS.BASIS = PLNE(10)<1,3>+0
          IF COGS.BASIS = 0 THEN
             LOCATE 'REP-COST' IN PLNE(2)<1> SETTING COGS.BASIS ELSE
                COGS.BASIS = 1
             END
          END

          BEGIN CASE
          CASE COGS.BASIS = 21; SEC.LEVEL = PLNE(4)<1,9> + 0
          CASE COGS.BASIS = 22; SEC.LEVEL = PLNE(4)<1,8> + 0
          CASE OTHERWISE;       SEC.LEVEL = PLNE(4)<1,COGS.BASIS> + 0
          END CASE

          IF NEW.STAT = 'D' AND OLD.STAT # 'D' THEN
             CHECK.KEY MODE:'OE.COST.EDIT.DIRECT',KEEP.DSTK.COST,DS.COST.LVL
             CHECK.KEY 'COGS.EDIT.DIRECT',KEEP.DSTK.COGS,DS.COGS.LVL

             IF (NOT(KEEP.DSTK.COST) OR (DS.COST.LVL < SEC.LEVEL)) THEN
                IF LD(28)<1,GEN> # '' THEN
                   LD(27)<1,GEN> = LD(28)<1,GEN>
                   LD(28)<1,GEN> = ''
                END
             END
             IF (NOT(KEEP.DSTK.COGS) OR (DS.COGS.LVL < SEC.LEVEL)) THEN
                IF LD(11)<1,GEN> # '' THEN
                   LD(10)<1,GEN> = LD(11)<1,GEN>
                   LD(11)<1,GEN> = ''
                END
             END
          END

          IF OLD.STAT = 'D' AND NEW.STAT # 'D' THEN
             CHECK.KEY 'UD.OE.DIR.COST.COPY$',KEEP.STK.COST,STK.COST.LVL
             CHECK.KEY MODE:'OE.COST.EDIT.NONSTOCK',KEEP.NSTK.COST,NSTK.COST.LVL
             CHECK.KEY 'UD.OE.DIR.COGS.COPY$',KEEP.STK.COGS,STK.COGS.LVL
             CHECK.KEY 'COGS.EDIT.NONSTOCK',KEEP.NSTK.COGS,NSTK.COGS.LVL

             IF PRD(3) = 2 THEN
                IF (NOT(KEEP.NSTK.COST) OR (NSTK.COST.LVL < SEC.LEVEL)) THEN
                   IF LD(28)<1,GEN> # '' THEN
                      LD(27)<1,GEN> = LD(28)<1,GEN>
                      LD(28)<1,GEN> = ''
                   END
                END
                IF (NOT(KEEP.NSTK.COGS) OR (NSTK.COGS.LVL < SEC.LEVEL)) THEN
                   IF LD(11)<1,GEN> # '' THEN
                      LD(10)<1,GEN> = LD(10)<1,GEN>
                      LD(11)<1,GEN> = ''
                   END
                END
             END ELSE
                IF (NOT(KEEP.STK.COST) OR (STK.COST.LVL < SEC.LEVEL)) THEN
                   IF LD(28)<1,GEN> # '' THEN
                      LD(27)<1,GEN> = LD(28)<1,GEN>
                      LD(28)<1,GEN> = ''
                   END
                END
                IF (NOT(KEEP.STK.COGS) OR (STK.COGS.LVL < SEC.LEVEL)) THEN
                   IF LD(11)<1,GEN> # '' THEN
                      LD(10)<1,GEN> = LD(10)<1,GEN>
                      LD(11)<1,GEN> = ''
                   END
                END
             END
          END

          IF OVRD.LD THEN
             OE.GET.QSIGN QSIGN,OID,GEN
             OE.UPDATE.LDID LDID,OID,GEN,,QSIGN
          END

          RETURN
!SMITJR~02/15/10~21:53
