          SUBROUTINE (OE.VARS.DYN,CLOSE.TYPE,ABORT,MISC.DATA,UPD.LOC,MSG.FLAG,MSGS,RESPS,OE.STATE.DYN,OLD.STAT,CC.ERR.MSG,RET.AUTH.OK)
** Version# 72.0001[76] - 01/23/2015 - 12:05pm - TSMITH - eclipse
*** V72.0001 Change - Custom Coding . - 01/23/2015 - TSMITH - eclipse

*** Subroutine - JAVA.LEDGER.CLOSE
*---------------------------Program Description---------------------------*
*** This routine should be called when the user leaves the body tab or
*** exits an order.
*--------------------------Parameter Definition---------------------------*
*** OE.VARS.DYN - OID, GEN, etc. (see CC OE.EQUATES)               [IN/OUT]
*** CLOSE.TYPE  - This routine is broken into two halves: 1)       [IN]
***             - Leaving OE Body 2) Closing the order This flag
***             - let the routine know which half to do: 0 = Exit
***             - the body only 1 = Exit the body and close the
***             - order 2 = Close the order only
*** ABORT       - Boolean, true if the body can't be exited or if  (OUT)
***             - the order can't be closed.
*** MISC.DATA   - On input, the activte.triggers value for new     (IN/OUT)
***             - order triggers.
***             -  On ouput an array of misc data to pass back:
***             - MISC.DATA<1> = Price Key MISC.DATA<2> = Quantity
***             - Key MISC.DATA<3> = Quantity Change Key
***             - MISC.DATA<4> = Ship-To Entity Record (lowered)
***             - MISC.DATA<5> = Bill-To Entity Record (lowered)
***             - Note: the MISC.DATA is only passed back if we
***             - are just exiting the body or if ABORT is true.
*** UPD.LOC     - A vairable used to re-enter the routine          [IN/OUT]
*** MSG.FLAG    - Boolean, true if re-entry is required.           (OUT)
*** MSGS        - The actions array                                [IN/OUT]
*** RESPS       - The resonces array OE.STATE.DYN- See CC          [IN/OUT]
***             - OE.EQUATES                                [IN]
*** OE.STATE.DYN- Information for the OE.STATE array defined in    [IN/OUT]
***               CC~OE.EQUATES.  Currently the only variable
***               defined is EXTRA.LOCKS%.
*** CC.ERR.MSG  - Err message from cc authorization                (OUT)
*** RET.AUTH.OK - Indicates if a return is allowed to be           (IN)
***             - authorized
*----------------------------Common Variables-----------------------------*
*** All the common variables used to edit an order are loaded and changed
*** in this routine (LED, PRD, PRDD, PRDD.BR, CUS, CUSS, and many more).
*-------------------------------------------------------------------------*

          $INCLUDE CC OE.EQUATES
          $INCLUDE CC DIM.EQUATES

          CC.ERR.MSG = ''
          ***Default RET.AUTH.OK to true if blank passed in
          IF RET.AUTH.OK = '' THEN
             RET.AUTH.OK = NO
          END
          EQU CLOSE.BODY    TO 0
          EQU FULL.CLOSE    TO 1
          EQU CLOSE.ORDER   TO 2

          GOSUB INIT

          * If there are cut products on the order then a work order
          * must be created and processed (if not AUTO-PROCESS shipvia).
          IF NOT(VIEW.ONLY%) AND (LED(140) # '') AND (CLOSE.TYPE = 2) AND (MODE% = 'S' OR (MODE% = 'T' AND GEN% = 1)) THEN
             GOSUB CHECK.AUTO.PROC;* Check for auto-process ship via

             IF AUTO.PROC.SVIA THEN ;* If svia has been changed to an
                IF NOT(NEW.ORDER%) THEN
                   GOSUB CHK.DELETE.WO  ;* auto-process then any work order
                END
             END ELSE               ;* that has been created must be
                GOSUB CREATE.WO     ;* deleted.
             END
          END

          BEGIN CASE
          CASE UPD.LOC = PRE:'1';          GOTO UPD.1
          CASE UPD.LOC = PRE:'2';          GOTO UPD.2
          CASE UPD.LOC = PRE:'3';          GOTO UPD.3
          CASE UPD.LOC = PRE:'4';          GOTO UPD.4
          CASE UPD.LOC = PRE:'5';          GOTO UPD.5
          CASE UPD.LOC = PRE:'6';          GOTO UPD.6
          CASE UPD.LOC = PRE:'7';          GOTO UPD.7
          CASE CLOSE.TYPE = CLOSE.ORDER;   GOTO CLOSE.ORDER.ONLY
          END CASE

          GOSUB DEL.NULL.LINES
UPD.1:    GOSUB ZERO.PRC.CHECK
          GOSUB MIRROR.REQ.DTS
          GOSUB UPDATE.PAF

          UPDATE.LEDGER OID%

          OLD.GID = ''
          IF CLOSE.TYPE # CLOSE.BODY THEN
             GOSUB DEL.NULL.GENS
          END

          GOSUB RECALLIT
UPD.2:    GOSUB CHECK.VIEW.ONLY
UPD.3:    * GOSUB CHECK.CREDIT  *do not need credit check per line item
UPD.4:    GOSUB TRIGGERS
          IF CLOSE.TYPE = CLOSE.BODY THEN
             *** If we are only leaving the body, we don't need to
             *** execute the rest of this routine.
             GOSUB GET.MISC.DATA
             GOTO FINISH
          END
          *if user is leaving the body (not closing the order) we
          *don't want to add the action for the freight term check.
          *this is because the client does this check and takes user
          *to the POE header already.
          *However, the user closes the order, we want to make sure that
          *the freight terms for all gens is checked correctly.
          GOSUB CHECK.FREIGHT.TERMS

CLOSE.ORDER.ONLY:***

UPD.5:    GOSUB VERF.SHIP.ADDR
          IF MSG.FLAG THEN RETURN TO FINISH
          GOSUB CHECK.REQ.NUMS
          GOSUB CHECK.GEOCODE
          GOSUB CHECK.FREIGHT.TERMS
          IF MODE%='S' THEN
             GOSUB CHECK.CC
             GOSUB CHECK.CASH.REQD
          END

UPD.6:    GOSUB ADD.COMMENT
          GOSUB REMOTE.LOG
          GOSUB CHECK.UET
          GOSUB CHECK.ABC
          IF NEW.ORDER% OR ACTIVATE.TRIGGERS THEN
             SV.GEN = GEN%
             GEN.CT = DCOUNT(LED(9),VM)
             FOR GEN = 1 TO GEN.CT
                GEN% = GEN
                OE.ACTIVITY.TRIGGER MAT OE.VARS,MSG.FLAG,MSGS,RESPS
             NEXT GEN
             GEN% = SV.GEN
             IF MSG.FLAG THEN RETURN TO FINISH
          END

UPD.7:
          GOSUB PRINT.DOCS
          GOSUB UNLOCK.LED
          GOSUB GET.MISC.DATA
          IF CNCL.WOIDS THEN
             GOSUB DELETE.WO
          END
FINISH:

          MATBUILD OE.VARS.DYN FROM OE.VARS
          MATBUILD OE.STATE.DYN FROM OE.STATE
          RETURN
*-------------------------------------------------------------------------*
INIT:     *** Initialize some variables and make some equates.

          DIM OE.VARS(DIM.OE.VARS.SIZE%)
          MATPARSE OE.VARS FROM OE.VARS.DYN
          DIM OE.STATE(150)    ;* Variables Used to Maintain the State
                               ;* Inside of OE.
          MATPARSE OE.STATE FROM OE.STATE.DYN
          OE.GET.LDID.LIST LDID.LIST,OID%,GEN%

          CURR.STAT = LED(6)<1,GEN%>
          IF CURR.STAT = 'I' AND CURR.STAT # OLD.STAT THEN
             CHK.CASH.REQ = YES
          END ELSE
             CHK.CASH.REQ = NO
          END
          PRE        = 'OE.CLOSE.ORDER~'
          ABORT      = NO
          MSG.FLAG   = NO
          LOCKED.LED = NOT(VIEW.ONLY%)
          * This is a variable passed to the various doc printing routines
          * to restrict the ways that a document is delivered.
          DELIVERY.ACTION = ""

          ACTIVATE.TRIGGERS = MISC.DATA
          ACTIVATE.TRIGGERS = NO

          CNCL.WOIDS = ''

          RETURN
*-------------------------------------------------------------------------*
DEL.NULL.LINES: *** This will remove any empty lines from the LDID.LIST
                *** for the current gen.

          OE.DEL.NULL.LINES OID%,GEN%,LDID.LIST

          RETURN
*-------------------------------------------------------------------------*
ZERO.PRC.CHECK: *** This checks to see if there are any line items w/o
                *** a price defined and prompts the user if there are.

          UPD.LOC = PRE:'1'
          OE.ZERO.PRC.CHK.MSG LDID.LIST,CONT.OK,MSG.FLAG,MSGS,RESPS

          *** User input required
          IF MSG.FLAG THEN RETURN TO FINISH

          IF NOT(CONT.OK) THEN
             *** The user wants to cancel the exit.
             ABORT = YES
             RETURN TO FINISH
          END

          RETURN
*-------------------------------------------------------------------------*
CHECK.ABC:
          IF MODE% # 'S'       THEN RETURN
          IF NOT(NEW.ORDER%)   THEN RETURN
          OE.UPDATE.ABC OID%
          RETURN
*-------------------------------------------------------------------------*
MIRROR.REQ.DTS:*** If the control record is set, this will set the
          *** required date to the ship date for new sales orders.  Note,
          *** if the customer has a lead time days specified, then the
          *** required date is actually set to the ship date + the lead
          *** time days.

          IF MODE% # 'S'       THEN RETURN
          IF NOT(NEW.ORDER%)   THEN RETURN

          REQ.DT.CT = DCOUNT(LED(10),VM)
          FOR REQ.DTX = 1 TO REQ.DT.CT
             CTRB.ID = 'MIRROR.REQ.DT~':LED(2)<1,REQ.DTX,2>
             READV MIRROR FROM CTRBFILE,CTRB.ID,1 ELSE MIRROR = ''
             IF NOT(MIRROR) THEN CONTINUE

             *** If there are lead time days spec'd for ST, add them
             IF CUSS(75) THEN
                LED(10)<1,REQ.DTX> = LED(9)<1,REQ.DTX> + CUSS(75)
             END ELSE
                LED(10)<1,REQ.DTX> = LED(9)<1,REQ.DTX>
             END
          NEXT REQ.DTX

          RETURN
*-------------------------------------------------------------------------*
UPDATE.PAF:*** Not sure what to do here yet...

          RETURN
*-------------------------------------------------------------------------*
DEL.NULL.GENS:*** This removes any gens that have no products or other
              *** usefull information.
          OLD.GID = LED(12)<1,GEN%>
          OE.DEL.NULL.GENS OID%,GEN%

          * After deletion, locate old gid in the updated led(12).
          * If not found, it indicates that the old gen is deleted.
          * Therefore set the GEN% default to 1
          LOCATE OLD.GID IN LED(12)<1> SETTING GEN% ELSE GEN% = 1
          RETURN
*-------------------------------------------------------------------------*
RECALLIT: *** The order is recalled here to make sure everything is kosher.
          *** This will make sure that the user still has the proper
          *** authority, even if the gen changed earier in this routine.
          *** Note, the UPD.LOC doesn't return to this internal subroutine.
          *** Instead, it returns to CHECK.VIEW.ONLY to parse the RESPS
          *** array to see if there was a failed auth check.

          UPD.LOC    = PRE:'2'
          REC.MSGS   = ''

          IF NOT(VIEW.ONLY%) AND LED(12)<1,GEN%>#OLD.GID THEN
             IF LED(8)<1,GEN%> THEN
                OE.RECALLIT MAT OE.VARS,LOCKED.LED,LDID.LIST,ABORT,EXTRA.LOCKS%,NO,REC.MSGS,,,,YES
                IF REC.MSGS THEN
                   MSG.FLAG = YES
                   MSGS<-1> = REC.MSGS

                   RETURN TO FINISH
                END
             END
          END
          RETURN
*-------------------------------------------------------------------------*
CHECK.VIEW.ONLY:*** This makes sure that the order can still be edited by
                *** the user (chaning the gen can change the view only
                *** status).

          IF VIEW.ONLY% THEN RETURN

          ACT.ID = 'OE.RECALLIT~AUTH'
          LOCATE ACT.ID IN RESPS<1> SETTING RESP.POS THEN
             AUTHED = RESPS<2,RESP.POS,1>
             IF NOT(AUTHED) THEN
                *** The order was in edit mode after OE.RECALLIT, but the
                *** user failed some auth check and so now it must be
                *** put into view only mode.

                VIEW.ONLY% = YES
                GOSUB UNLOCK.LED
             END
          END

          RETURN
*-------------------------------------------------------------------------*
CHECK.CREDIT:*** Not sure what to do here...
          UPD.LOC = PRE:'3'
          IF MODE% # 'S'          THEN RETURN

          NO.OE.OVRD$ = NO
          BT.CN = LED(1)<1,GEN%>
          ST.CN = LED(5)<1,GEN%>
          SOE.CHECK.NO.OE.MSG BT.CN,ST.CN,OE.OK,NO.OE,MSG.FLAG,MSGS,RESPS,OID%,GEN%
          IF MSG.FLAG THEN
             RETURN TO FINISH
          END

          IF NOT(OE.OK) THEN
             ABORT = YES
             RETURN TO FINISH
          END

          RETURN
*-------------------------------------------------------------------------*
VERF.SHIP.ADDR:*** If the verify shipping address control record is set,
               *** then this will add an action to display the header
               *** as a dialog.
          IF CLOSE.TYPE # CLOSE.BODY THEN
             UPD.LOC = PRE:'5'
          END
          IF MODE% # 'S'          THEN RETURN
          IF NOT(NEW.ORDER%)      THEN RETURN
          IF NOT(VERF.SHIP.ADDR$) THEN RETURN

          ACT.TYPE = 'ST.ADDRESS.VERF'
          LOCATE ACT.TYPE IN RESPS<1> SETTING RESP.POS ELSE
             DATA = YES  ;* Flag saying that the verify shipping address
                         ;* message needs to be displayed when the heser
                         ;* is opened.

             ACTION.ADD MSGS,ACT.TYPE,,NO,,,DATA

             MSG.FLAG = YES
             RETURN TO FINISH
          END

          RETURN
*-------------------------------------------------------------------------*
CREATE.WO:
          IF LED(70)<1,GEN%> = '' THEN
             RETURN
          END
          PRT.INFO = ''
          IF MODE% = 'S' THEN
             CUT.ERR = ''
             CUT.PROD.CHK.PROCURE CUT.ERR
             IF TRIM(CUT.ERR) THEN
                * need to be able to display the message here and if all
                * items have not been procured then we should not let them
                * leave.
                CONVERT AM TO ' ' IN CUT.ERR
                CONVERT VM TO ' ' IN CUT.ERR
                CONVERT SVM TO ' ' IN CUT.ERR
                ACT.ID   = "CUT.PRODUCT.ERR"
                MSG.FLAG = YES
                MSG      = CUT.ERR
                ACTION.ADD MSGS,ACT.ID,,,MSG,YES
                RETURN
             END
             LD.CT = DCOUNT(LDID.LIST,VM)
             FOR LDX = 1 TO LD.CT
                LD.GET LDID.LIST<1,LDX>
                IF LD(118) # '' THEN
                   MOD.LOG.UPDATE OID%,LDID.LIST<1,LDX>
                END
             NEXT LDX
          END

          IF NEW.ORDER% THEN
             IF MODE% = 'S' THEN
                CHK.CUT.ORDER.STAT OID%,CR.WRK,ALDIDS,NEW.ORDER%
                IF CR.WRK THEN
                   IF ALDIDS = 'ALL' THEN
                      CUT.WORK.ORDER.CREATE.PRE OID%,,,PRT.INFO,GEN%
                   END ELSE
                      CUT.WORK.ORDER.CREATE.PRE OID%,ALDIDS,,PRT.INFO,GEN%
                   END
                END
             END ELSE
                CUT.WORK.ORDER.CREATE.PRE OID%,,YES,PRT.INFO,GEN%
             END
          END ELSE
             IF MODE% = 'S' THEN
                CUT.WORK.ORDER.UPDATE OID%,CR.WRK,ALDIDS
                IF ALDIDS = 'ALL' THEN
                   CUT.WORK.ORDER.CREATE.PRE OID%,,,PRT.INFO,GEN%
                END ELSE
                   CUT.WORK.ORDER.CREATE.PRE OID%,ALDIDS,,PRT.INFO,GEN%
                END
             END ELSE
                CUT.WORK.ORDER.CREATE.PRE OID%,,,PRT.INFO,GEN%
             END
          END

          * We may have documents to print if ship-via is set for
          * auto-process
          IF PRT.INFO # '' THEN
             ACT.ID = 'WORK.ORDER.PRINT'
             ACTION.ADD MSGS,ACT.ID,ACT.ID,,,,LOWER(PRT.INFO)
          END

          RETURN
*-------------------------------------------------------------------------*
CHECK.REQ.NUMS:*** If either the release number or the P/O number are
               *** required and not filled in, this will stop the user
               *** from exiting the order and let them know what they
               *** have to fill in.
          ST.CN = LED(5)<1,GEN%>
          UPD.LOC = PRE:'5'
          IF NOT(FULL.CLOSE)      THEN RETURN
          IF MODE% # 'S'          THEN RETURN
          IF LED(6)<1,GEN%> = 'B' AND ST.CN # '4503' THEN RETURN
          IF LED(6)<1,GEN%> = 'X' THEN RETURN
          IF LED(6)<1,GEN%> = '$' THEN RETURN
          LOCATE 'PO.REL.REQD' IN RESPS<1> SETTING POS THEN RETURN

          * If this is the po side of a direct then we need to
          * check the customer, not the vendor.
          NPRB = ''
          SALES.GEN = GEN%
          IF LED(6)<1,GEN%> = 'Y' THEN
             GOSUB GET.DIRECT.GEN
             DIRECT.CUSS.ID = LED(5)<1,DIRECT.GEN>

             READV CUS.PO.REQ FROM CUSFILE,DIRECT.CUSS.ID,45 ELSE CUS.PO.REQ = ''
             NPRB = CUS.PO.REQ<1,1>
             IF DIRECT.GEN # "" THEN
                SALES.GEN = DIRECT.GEN
             END
          END ELSE
             NPRB = CUSS(45)<1,1>
          END

          NAME  = FIELD(TRANS('INITIALS',USER.ID,3,'X'),' ',1)
          ST.CN = LED(5)<1,GEN%>
          FLWUP.ID = TRANS('LEDGER.LOG',OID%,12,'X')
          FLWUP.CHK  = (ST.CN='4503' AND NOT(FLWUP.ID))
          NPRB.OK    = (NPRB#'' AND NPRB#'R' AND NPRB#0 AND NPRB#'N')
          PO.CHK     = (NPRB.OK AND LED(13)<1,SALES.GEN>='')
          REL.CHK    = (NPRB='R' OR NPRB='B' AND LED(65)<1,SALES.GEN>='')
          AUTH.CHK   = (CUSS(27) AND LED(68)<1,SALES.GEN>='')
          * We will throw a message based on a hierarchy. The first
          * message will be PO Number Required, followed by Release
          * Number Required, and then Ordered By Required.
          * This is examined in Solar in OEActionManager.java.
          BEGIN CASE
          CASE PO.CHK
             ACT.ID   = "PO.REL.REQD"
             MSG.FLAG = YES
             MSG      = "%204"       ;* PO Number Required Message
             ACTION.ADD MSGS,ACT.ID,,,MSG,1,"PO"
             RETURN TO FINISH
          CASE REL.CHK
             ACT.ID   = "PO.REL.REQD"
             MSG.FLAG = YES
             MSG      = "%202"       ;* Release Number Required Message
             ACTION.ADD MSGS,ACT.ID,,,MSG,1,"REL"
             RETURN TO FINISH
          CASE AUTH.CHK
             ACT.ID   = "PO.REL.REQD"
             MSG.FLAG = YES
             MSG      = "%145"       ;* Ordered By Required Message
             ACTION.ADD MSGS,ACT.ID,,,MSG,1,"ORDERBY"
             RETURN TO FINISH
          CASE FLWUP.CHK
             ACT.ID   = "PROMPT"
             MSG.FLAG = YES
             CLOSE.TYPE = CLOSE.BODY
             MSG      = "%158"       ;* Bid Follow-Up Message
             *ACTION.ADD MSGS,ACT.ID,,,MSG,1,"FOLLOWUP"
             ACTION.ADD.PROMPT MSGS,ACT.ID,YES,MSG,SOUND,VERF,'YN',"From Status page: Edit=>Bid Follow Up",'Y'
             *ACTION.ADD.CONFIRM MSGS,ACT.ID,ABORT.OK,MSG,SOUND,PLACE,"YES_NO"
             RETURN TO FINISH
          END CASE

          RETURN
*-------------------------------------------------------------------------*
CHECK.GEOCODE:*** If the geocode field is required and hasn't been filled
              *** in yet, stop the user from exiting the order and let
              *** them know they have to fill it in.

          IF NOT(FULL.CLOSE) THEN RETURN
          IF MODE% # "S" THEN RETURN

          * If this is the PO side of a direct then we need to check the
          * tax jurisdiction on the sales side.
          IF LED(6)<1,GEN%> = 'Y' THEN
             GOSUB GET.DIRECT.GEN
             SHP.DT = LED(9)<1,DIRECT.GEN>
             TAX.JUR = LED(79)<1,DIRECT.GEN,1>
          END ELSE
             SHP.DT = LED(9)<1,GEN%>
             TAX.JUR = LED(79)<1,GEN%,1>
          END

          USE.STAX = (USE.STAX$ AND USE.STAX$ <= SHP.DT)
          IF NOT(USE.STAX) THEN RETURN

          IF TAX.JUR THEN
             ROOT = TAX.JUR:'~':DATE()
             BSCAN GG FROM STAXFILE,ROOT USING '&INDEX&' BY 'D' THEN
                IF FIELD(GG,'~',1) = TAX.JUR THEN RETURN
             END
          END

          ACT.ID = 'GEOCODE.REQD'
          LOCATE ACT.ID IN RESPS<1> SETTING POS THEN RETURN
          MSG.FLAG = YES
          !ACTION.ADD.MSG MSGS,ACT.ID,,'%205',,1,YES
          ACTION.ADD MSGS,ACT.ID,,,'%205',1,'GEOCODE'

          RETURN TO FINISH
*-------------------------------------------------------------------------*
CHECK.FREIGHT.TERMS:*** If freight terms are being used, then they are
                    *** required fields...

          IF NOT(FULL.CLOSE)      THEN RETURN
          IF MODE% # 'P'          THEN RETURN
          IF LED(69)<1,GEN%,1>#'' THEN RETURN

          CTRL.ID = 'VENDOR.FREIGHT.TERMS'
          READV FRT.TERMS FROM CTRLFILE,CTRL.ID,1 ELSE FRT.TERMS = ''
          IF NOT(FRT.TERMS) THEN RETURN

          ACT.ID = 'FGHT.TERMS.REQD'
          MSG = '%206'
          ACTION.ADD MSGS,ACT.ID,,,MSG
          MSG.FLAG = YES
          ABORT = NO

          RETURN TO FINISH

*-------------------------------------------------------------------------*
CHECK.CC: * Check that default credit card info is fulfilled on order
          UPD.LOC = PRE:'5'
          LOCATE 'CC.REQUIRED' IN RESPS<1> SETTING POS THEN RETURN
          SV.GEN = GEN%
          OE.NEXT.SHIPDATE GEN%

*** If there is not a future shipment of material but current generation
*** has been changed to invoice, still check credit card required
          IF GEN% = 0 AND (LED(8)<1,SV.GEN> AND CHK.CASH.REQ) THEN
             GEN% = SV.GEN
          END

          IF GEN%   # 0 THEN
             GN.CT  = DCOUNT(LED(9),VM)
             FOR GN = 1 TO GN.CT
                IF LED(6)<1,GN,1> = 'P' THEN GEN% = GN
             NEXT GN

             GET.CUS LED(2)<1,GEN%,1>,LED(1)<1,GEN%>,LED(5)<1,GEN%>,QSIGN%
             NADDL    = LED(1)<1,GEN%>   ;* BillTo
             NADDL<2> = LED(5)<1,GEN%>   ;* ShipTo
             CC.NEED.DFLT.INFO NEW.ORDER%,DFLT.NEEDED,PAY.CC,NADDL
             IF DFLT.NEEDED THEN
             SOE.CALC.CASH OID%,GEN%,AMT.DUE
             OE.ORDER.TOTAL OID%,GEN%,QSIGN%,TOT.AMT,SUB.TOL,,,TAX.TOL
                CHECK.REQD = YES
                *** Reference tracker CRN860 for why the action was
                *** added. Then entire flow here does not match the
                *** flow in OE.STATUS. Because credit card is a low
                *** issue for Solar Rel 1, we are spawning a tracker
                *** to fix this.
                ACT.ID = 'CC.REQUIRED'
                ACTION.ADD MSGS,ACT.ID,,,,1,YES
                MSG.FLAG = YES
                RETURN TO FINISH
                CHECK.REQD = NO
             END ELSE
                CHECK.REQD = YES
             END
          END

          GEN% = SV.GEN

          RETURN
*-------------------------------------------------------------------------*
CHECK.CASH.REQD:
          UPD.LOC = PRE:'5'
          LOCATE 'CASH.REQUIRED' IN RESPS<1> SETTING POS THEN RETURN
          SV.GEN = GEN%
          OE.NEXT.SHIPDATE GEN%
          PSTAT = ''
          LOCATE 'P' IN LED(6)<1> SETTING PSTAT ELSE
             PSTAT = ''
          END
*** If there is not a future shipment of material but current generation
*** has been changed to invoice, still check cash required
          IF GEN% = 0 AND (LED(8)<1,SV.GEN> AND CHK.CASH.REQ) THEN
             GEN% = SV.GEN
          END

          IF GEN%   # 0 THEN
             GN.CT  = DCOUNT(LED(9),VM)
             FOR GN = 1 TO GN.CT
                IF LED(6)<1,GN,1> = 'P' THEN GEN% = GN
             NEXT GN

             GET.CUS LED(2)<1,GEN%,1>,LED(1)<1,GEN%>,LED(5)<1,GEN%>,QSIGN%
             SOE.CALC.CASH OID%,GEN%,AMT.DUE
             OE.ORDER.TOTAL OID%,GEN%,QSIGN%,TOT.AMT,SUB.TOL,,,TAX.TOL
             IF (AMT.DUE#0 AND TOT.AMT#0) THEN
                IF AMT.DUE < 0 THEN
                   SOE.CREDIT.CHECK LED(5)<1,GEN%>,,COD,,,,,OID%,GEN%
                   IF NOT(COD) THEN GOTO SKIP.NEGS
                END

                *** If no ship via then see if the control default is set
                *** to ignore cash required.
                READ SVIA.CASH FROM CTRLFILE,'SOE.CASH.REQD.CHECK' ELSE
                   SVIA.CASH = ''
                END
                IF LED(70)<1,GEN%> = '' AND SVIA.CASH THEN GOTO SKIP.NEGS

                READV SKP.NEGS FROM SVIAFILE,LED(70)<1,GEN%>,5 ELSE
                   SKP.NEGS = NO
                END
                IF SKP.NEGS = 'Y' OR (SKP.NEGS = 'P' AND PSTAT > 0) THEN
                   GOTO SKIP.NEGS
                END
                CASH.GEN = GEN%
                GEN% = SV.GEN
                *** CHECK.REQD will be set to NO if we already went into
                *** the TOTALS screen for CHECK.CC
                IF CHECK.REQD THEN
                   ACT.ID = 'CASH.REQUIRED'
                   *we need to pass the cash gen back to the client.
                   *if the current gen set on the client is different from
                   *the cash gen, the total screen be opened for the cash
                   *required gen
                   ACTION.ADD MSGS,ACT.ID,,,,1,CASH.GEN
                   MSG.FLAG = YES
                   RETURN TO FINISH
                END
             END
SKIP.NEGS:
          END

          GEN% = SV.GEN
          RETURN
*-------------------------------------------------------------------------*
TRIGGERS: *** This will add the "TRIGGER" action to the action array if
          *** there is a trigger defined for either the bill-to or ship-
          *** to when leaving the order.

          IF MODE% # 'S' THEN RETURN

          TNUM = 4 ;* 4 specifies that we are leaving the body

          OE.TRIGGER.GET.PROMPTS TNUM,OID%,GEN%,NEW.ORDER%,LDID%,,TR.DATA

          IF (TR.DATA<1,1,1> # '') THEN
             ACTION.ADD MSGS,'TRIGGER',,,,,4
          END

          RETURN
*-------------------------------------------------------------------------*
ADD.COMMENT:*** This will prompt the user for a change reason if they have
            *** changed an existing order.

          UPD.LOC = PRE:'6'

          *** Logic to add Order to the User History List
          BEGIN CASE
          CASE MODE% = 'S'
             USER.LOG.HISTORY '1',OID%
          CASE MODE% = 'P'
             USER.LOG.HISTORY '2',OID%
          CASE MODE% = 'T'
             USER.LOG.HISTORY '3',OID%
          END CASE

          IF NEW.ORDER%  THEN RETURN
          IF LOG.MV%=''  THEN RETURN


          ACT.ID   = 'OE.CLOSE.ORDER~ADD.COMMENT'
          LOCATE ACT.ID IN RESPS<1> SETTING RESP.POS THEN
             DATA  = LOWER(RESPS<2,RESP.POS>)
             OE.ADD.COMMENT OID%,LOG.MV%,DATA
          END ELSE
             MSG.FLAG  = YES
             FDESC     = 'Reason for Change'  ;* Title
             ACTION.ADD.FREEFORM MSGS,ACT.ID,NO,,,FDESC,NO,60

             RETURN TO FINISH
          END

          RETURN
*-------------------------------------------------------------------------*
REMOTE.LOG:*** If a user is entering an order or a bid as a remote
           *** customer, this program will be called to notify a list
           *** of users that the customer has created a bid or order.
           *** The list of users is customer specific.

          IF REMOTE.CUST THEN
             OE.REMOTE.LOG OID%,GEN%,LOG.MV%,NEW.ORDER%,LED(5)<1,GEN%>
          END

          RETURN
*-------------------------------------------------------------------------*
CHECK.UET:*** Check to see if any UET codes need to be logged

          * Check for UET for new orders
          UET.ENABLED.BR% = NO
          IF UET.ENABLED$ THEN
             CTRB.ID = 'UET.ENABLED~':LED(2)<1,GEN%,2>
             READV UET.ENABLED.BR% FROM CTRBFILE,CTRB.ID,1 ELSE UET.ENABLED.BR%=NO
          END
          IF UET.ENABLED.BR% THEN
             JAVA.UET.CHECK.NEW.ORDER OID%,GEN%,MSGS
          END

          RETURN
*-------------------------------------------------------------------------*
PRINT.DOCS: *** Based on print status, setup fax, printing, and email
          UPD.LOC = PRE:'7'

          JAVA.PRINT.DOCS OID%,MODE%,VIEW.ONLY%,MSGS,RESPS,MSG.FLAG,CC.ERR.MSG,RET.AUTH.OK
          IF MSG.FLAG THEN
             RETURN TO FINISH
          END
          RETURN
*-------------------------------------------------------------------------*
UNLOCK.LED:*** This will unlock the ledger iff it is locked.
          CT     = DCOUNT(EXTRA.LOCKS%,VM)
          FOR JX = 1 TO CT
             EL.OID = EXTRA.LOCKS%<1,JX>
             IF EL.OID # '' THEN
                OE.UNLOCK.LED EL.OID
             END
          NEXT JX
          EXTRA.LOCKS% = ''

          CHECK.RECORD.LOCK LEDFILE,OID%,IS.LOCKED,USER.LOCKED
          IF USER.LOCKED = USER.ID THEN
             OE.UNLOCK.LED OID%
          END

          RETURN
*-------------------------------------------------------------------------*
GET.MISC.DATA:***

          IF NOT(ABORT) AND CLOSE.TYPE # CLOSE.BODY THEN RETURN

          OE.GET.KEYS OID%,GEN%,NEW.ORDER%,VIEW.ONLY%,PRC.KEY,QTY.KEY,LOCKED.LED
          OE.QTY.CHNG.OK OID%,GEN%,QTY.KEY,VIEW.ONLY%,QTY.CHNG.OK
          IF PRC.KEY AND LED(110)<1,1>='S' THEN PRC.KEY=NO

          MATBUILD TMP.ST FROM CUSS
          MATBUILD TMP.BT FROM CUS

          MISC.DATA    = PRC.KEY
          MISC.DATA<2> = QTY.KEY
          MISC.DATA<3> = QTY.CHNG.OK
          MISC.DATA<5> = LOWER(TMP.ST)
          MISC.DATA<4> = LOWER(TMP.BT)

          RETURN
*-------------------------------------------------------------------------*
GET.DIRECT.GEN:*** Get the sales side of a Direct.

          * Find the gid in the direct reference field
          LOCATE GEN% IN LED(12)<1> SETTING PO.DIRECT.GID ELSE PO.DIRECT.GID = ''
          LOCATE PO.DIRECT.GID IN LED(33)<1> SETTING DIRECT.XREF ELSE DIRECT.XREF = ''

          * find the sales side gen of the po
          LOCATE DIRECT.XREF IN LED(12)<1> SETTING DIRECT.GEN ELSE DIRECT.GEN = ''

          RETURN
*-------------------------------------------------------------------------*
CHK.DELETE.WO: * Delete work orders previously created for cut products

          LD.CT = DCOUNT(LDID.LIST,VM)
          CNCL.WOIDS = ''
          FOR LDX = 1 TO LD.CT
             LD.GET LDID.LIST<1,LDX>
             IF LD(118) # '' THEN
                DCNT = DCOUNT(LD(7)<1,GEN%>,SVM)
                FOR DX = 1 TO DCNT
                   TLOC = LD(7)<1,GEN%,DX>
                   IF INDEX(TLOC,'^',1) THEN
                      WOID = FIELD(FIELD(TLOC,'^',2),'.',1)
                      LOCATE WOID IN CNCL.WOIDS SETTING WPOS ELSE
                         CNCL.WOIDS<-1> = WOID
                         FINDSTR WOID IN LD(118) SETTING X1,Y1,Z1 THEN
                            LD(118) = DELETE(LD(118),1,4,Z1)
                            LD.PUT LDID.LIST<1,LDX>
                         END
                      END
                   END
                NEXT DX
             END
          NEXT LDX

          IF CNCL.WOIDS THEN
             UPDATE.LEDGER OID%
             GOSUB RECALLIT
          END

          RETURN
*-------------------------------------------------------------------------*
DELETE.WO: * Delete work orders
          DCNT = DCOUNT(CNCL.WOIDS,AM)
          FOR DX = 1 TO DCNT
             WOID = CNCL.WOIDS<DX>
             CNCL.CUT.WORK.ORDER WOID,OID%
          NEXT DX

          RETURN
*-------------------------------------------------------------------------*
CHECK.AUTO.PROC: *
          AUTO.PROC.SVIA = NO
          READ CUT.CNTRL FROM CTRLFILE,'CUT.PRODUCTS' ELSE
             CUT.CNTRL = ""
          END
          CHK.GEN = GEN%
          IF CHK.GEN = '' OR OID%[1,1] = 'T' THEN
             CHK.GEN = 1; * Check shipping gen only for transfers
          END
          LOCATE LED(70)<1,CHK.GEN> IN CUT.CNTRL<3> SETTING SV.POS THEN
             AUTO.PROC.SVIA = YES
          END

          RETURN
*-------------------------------------------------------------------------*
!TSMITH~01/23/15~12:05
