          SUBROUTINE (OID,GEN,LOG.MV,NEW.ORDER,REDISP,ESC.PATH,VONLY,REQRD,POST.ENTRY)
** Version# 239.0001[5] - 09/19/2011 - 11:58pm - SMITJR - eclipse
*** V239.0001 Change - Custom Coding .. - 09/19/2011 - SMITJR - eclipse

*** Subroutine: SOE.HEADER
*-------------------------------------------------------------------------*
*** This routine displays and lets user edit all of the header info for the
*** order such as billto/shipto address, customer po number, tax info,
*** in/out salesperson, ordered by, etc.
*-------------------------------------------------------------------------*
*** OID      - sales order number                                 (IN)
*** GEN      - generation of order                                (IN)
*** LOG.MV   - a record of the changed generations                (IN)
*** NEW.ORDER- flag for new order                                 (IN)
*** REDISP   - flag set for any changes made on this screen that need to be
***            changed on order body screen                       (OUT)
*** ESC.PATH - prints at bottom next to hotkeys to let user know
***          - when they hit escape, what screen they will go to  (IN)
*** VONLY    - <1,1> flag for view.only orders                    (IN)
***            <1,2> flag to allow editing of notes when the view
***                  only flag is set. This should only be set when
***                  the ledger record has been previously locked.
*** REQRD    - flag for verification of shipping address          (IN)
*** POST.ENTRY - flag for Post Entry for SOE                      (IN)
*-------------------------------------------------------------------------*
*** Other important variables:
***       UPD.GEN.MV - This is passed to SOE.HEADER.ADDL.KEYS, so it can
*** then be passed on to SOE.HEADER.ADDL, specifically for recording ALL
*** the gens that will need to be updated because of changes in the Header
*** Add'l Info screen.
*-------------------------------------------------------------------------*
*** Common Variables:
*** OE.LOCKED.DIR$ is used in this routine
*-------------------------------------------------------------------------*
          $INCLUDE CC CBTST.EQUATES
          DIM CBTST.VARS(6)

          CHECK.KEY 'SOE.EDIT.VIEW.ONLY.NOTES',NOTES.OK
          READ COPY.NTS FROM CTRLFILE,'INT.NOTES.COPY' ELSE COPY.NTS = ''

          VIEW.ONLY = VONLY<1,1>
          VEDIT.OK  = VONLY<1,2>

          QUIT = NO
          WINDOW 0,1,,,9,'SOE.HEADER'
          PRINT @(69,21):'Esc-':ESC.PATH "L#6":

          * If we are not using Eclipse Forms, the Print Style field
          * will be used.
          IF NOT(USE.ECLIPSE.FORMS$) THEN
             PRINT @(2,14):"Print Style     : "
          END

          * Get input from any trigger (before displaying the screen)
          OE.TRIGGERS 1,OID,GEN,NEW.ORDER,,VIEW.ONLY

          OLDB       = ''
          B          = ''
          UPD.GEN.MV = ''
          ATB.NUM    = ''
          ATB.DESCS  = ''
          COPY.IT    = ''
          COPY.TAX   = NO

          GOSUB INIT
          GOSUB LOAD.HOTKEYS

          GOSUB CHK.FGHT.EXMPT
          GOSUB DISPLAY

          BEGIN CASE
          CASE (LED(128)<1,1>)
             PRINT @(30,0):BLINK$:"Master Job Bid":NORM$
          CASE (LED(129)<1,1>)
             OFMT      = "L#":OID.LGTH$
             MASTER.ID = LED(129)<1,1>
             NVER      = 28 - ((OID.LGTH$ - 8) / 2)
             PRINT @(NVER,0):BLINK$:"Junior To-":MASTER.ID OFMT:NORM$
          CASE LED(129)<1,2>
             OFMT      = "L#":OID.LGTH$
             MASTER.ID = LED(129)<1,2>
             NVER      = 28 - ((OID.LGTH$ - 8) / 2)
             PRINT @(NVER,0):BLINK$:"Change For-":MASTER.ID OFMT:NORM$
          CASE OTHERWISE
             PRINT @(27,0):"様様様様様様冤様様様"
          END CASE

          * Check to see if we are entering with the ability to edit
          * the Header Screen in a Closed G/L Period. If so, check for
          * a lock on LEDGER. If there is one, default to View Only.
          OE.HEADER.UPD.VIEW.ONLY OID,,1,VIEW.ONLY

          IF VIEW.ONLY THEN
             * Print the invoice date if we are in view only mode
             * don't have to worry about other error messages
             * overriding our message
             GOSUB PRT.INV.DT
             IF VIEW.ONLY = 2 THEN
                PRINT @(2,0):BLINK$:'Closed Period':NORM$
             END ELSE
                PRINT @(2,0):BLINK$:'View Only':NORM$
                SV.OID.DATA = OID.DATA$
                GOSUB CHK.LED.LOCK
                IF LOCK.MSG THEN
                   GOSUB LOAD.HOTKEYS
                   UT.GET.PROMPT '%103',PRESS.ENTER
IN$$17:            INP.PROMPT ,LOCK.MSG:AM:PRESS.ENTER,,0
                END ELSE
                   IF NOT(PREV.LOCKED) THEN
                      OE.UNLOCK.LED OID
                   END
                END
                OID.DATA$ = SV.OID.DATA
                GOTO IN.OTHER.INST
             END
          END

          *** If they want to require a product catalog pop it up now...
          CTRB.ID = "SOE.REQR.CATALOG~":LED(2)<1,GEN,2>
          READV CAT.REQD FROM CTRBFILE,CTRB.ID,1 ELSE CAT.REQD = ''
          IF CAT.REQD AND LED(111) = '' THEN
             PCAT = LED(111)
REQ.PCAT:    INP.PROMPT PCAT,'Product Catalog : ','MCU',7,'C:VALID.CATS'
             *** if the Prod Cat is required, they have to enter in a
             *** product catalog!
             IF PCAT = '' THEN PRINT BELL:; GOTO REQ.PCAT
             LED(111) = PCAT
          END

          IF LED(33)<1,GEN> THEN TRIG = 11 ELSE TRIG = 2
          BT.CN = LED(1)<1,GEN>
          ST.CN = LED(5)<1,GEN>
          REMINDER.VIEW BT.CN,,TRIG,80,23
          IF ST.CN # BT.CN THEN
             REMINDER.VIEW ST.CN,,TRIG,80,23
          END

          IF (VIEW.ONLY = 2) THEN
             GOTO IN.PO
          END

          IF REQRD = 1 THEN
             MESS 20,8,BELL:'Shipping Address Verification Required'
             GOTO INADR1
          END
          GOSUB CHK.PO
          GOSUB CHK.FREIGHT.IN
          GOSUB CHK.FREIGHT.OUT
          GOSUB CHK.REL
          GOSUB CHK.AUTH
          GOSUB CHK.GEO
          * Done displaying any potential required field messages. Now
          * display the invoice date.
          * We know that if the user has changed a customers
          * required field after the invoice is printed and
          * the order header is accessed the invoice print
          * date will not display. This is because we can only
          * display one message at a time and the required
          * field message takes precendence.
          GOSUB PRT.INV.DT
          GOTO IN.PO
*-------------------------------------------------------------------------*
EDIT:     *
*-------------------------------------------------------------------------*
IN.BRCH:  BRCHG.NOT.OK = NO
          LOCATE LED(2)<1,GEN,1> IN SECURITY<9> SETTING POS THEN
         !   LOCATE 'SUPERUSER' IN SECURITY<10> SETTING NADA ELSE
                CHECK.KEY 'SOE.DISALLOW.PRCBR.CHG',BRCHG.NOT.OK
         !   END
          END ELSE
             POS = ''
          END
          IF POS AND NOT(BRCHG.NOT.OK) THEN
             IF NOT(OE.LOCKED.DIR$) THEN
IN$$2:          INP.BR 20,7,4,BR,NAME,,'10'

                *** get the price class for this prc br
                GOSUB GET.PRC.CLASS

                IF LED(2)<1,GEN,1>#BR THEN
                   IF NOT(BR) THEN
                      PRINT @(20,7):LED(2)<1,GEN,1>"L#4":BELL
                      GOTO IN.BRCH
                   END
                   *** See if the billto is authorized for this branch
                   ENTITY.BR.CHK.AUTH LED(1)<1,GEN>,BR,AUTH.OK
                   IF NOT(AUTH.OK) THEN
                      *** Check the shipto
                      ENTITY.BR.CHK.AUTH LED(5)<1,GEN>,BR,AUTH.OK
                      IF NOT(AUTH.OK) THEN
                         MSG = "Customer Is Not Authorized For Branch : "
                         ERR.MESS 19,5,BELL:MSG:BR
                         BR = LED(2)<1,GEN,1>
                         S.MSG = '** Non Existing Branch **'
                         READV S.DSC FROM TERRFILE,BR,1 ELSE S.DSC = S.MSG
                         PRINT @(20,7):BR"L#4":'-':S.DSC "L#13"
                         GOTO IN.BRCH
                      END
                   END
                   REDISP          = YES
                   LED(2)<1,GEN,1> = BR
                   READV SNAME FROM TERRFILE,BR,1 ELSE SNAME = ''
                   PRINT @(20,7):BR"L#4":'-':SNAME "L#13"
                END
             END
          END
          IF QUIT THEN GOTO FILEIT
          ON MOVE+1 GOTO IN.ODATE, IN.ODATE, INADR3, IN.REL, IN.ODATE, IN.ODATE
*-------------------------------------------------------------------------*
IN.ODATE: INP B,20,8,10,'D4/'
          IF CHANGED THEN
             IF B+0<1 THEN
                PRINT @(20,8):OCONV(LED(4)<1,GEN>,'D4/')"L#10":BELL:
                GOTO IN.ODATE
             END
             OLD.ODT = LED(4)<1,GEN>
             LED(4)<1,GEN> = B
             CMNT = 'Changed Order Date from ':OCONV(OLD.ODT,'D4/'):' to ':OCONV(B,'D4/')
             OE.ADD.COMMENT OID,GEN,CMNT
             IF NEW.ORDER AND POST.ENTRY THEN
                * If new and in Post Entry then set pricing date to
                * order date for foreign exchange rate
                LED(22)<1,GEN> = B
             END
             ATB = 4; ATB.DESC = 'Date Ordered'; GOSUB CHK.COPY.MODE

          END
          IF QUIT THEN GOTO FILEIT
          ON MOVE+1 GOTO IN.ODATE,IN.ODATE,IN.BRCH,IN.OBY,IN.PICK,IN.PICK
*-------------------------------------------------------------------------*
IN.PICK:  *** Picked By
          IF PICK.ALL.BRS THEN
             *** Allow picker with any home branch
IN$$14:      INP B,20,9,10,'MCU',V_'S:VERF.PICKER'
          END ELSE
IN$$16:      INP B,20,9,10,'MCU',V_'S:VERF.PICKER,':LED(2)<1,GEN,2>
          END
          IF CHANGED THEN
             OLD.PICK = LED(66)<1,GEN>
             LED(66)<1,GEN> = B
             CMNT = 'Changed Picked By from ':OLD.PICK:' to ':B
             OE.ADD.COMMENT OID,GEN,CMNT
             ATB = 66; ATB.DESC = 'Picked By'; GOSUB CHK.COPY.MODE
             END
          IF QUIT THEN GOTO FILEIT
          ON MOVE+1 GOTO IN.PICK,IN.PICK,IN.ODATE,IN.PHN,IN.WRTR,IN.WRTR
*-------------------------------------------------------------------------*
IN.WRTR:  CHECK.KEY 'SOE.WRITER.EDIT',EDIT.OK,LEVEL
          IF LEVEL >= 2 OR (LED(73)<1,GEN> = USER.ID AND (REMOTE.CUST OR LEVEL = 1)) THEN
IN$$3:       INP B,20,10,10,'MCU',V_'S:VERF.USER.ID',H_"IH#21"
             IF CHANGED THEN
                   OE.ADD.COMMENT OID,GEN,'Changed Writer from : ':LED(73)<1,GEN>:' to : ':B
                LED(73)<1,GEN> = B
                ATB = 73; ATB.DESC = 'Written By'; GOSUB CHK.COPY.MODE
                SOE.UPD.COMM.PLAN OID,GEN,ATB
             END
          END ELSE IF MOVE=0 OR MOVE=1 THEN MOVE = 5
          IF QUIT THEN GOTO FILEIT
          ON MOVE+1 GOTO IN.WRTR,IN.WRTR,IN.PICK,IN.TERMS,IN.SLSP,IN.SLSP
*-------------------------------------------------------------------------*
IN.SLSP:  CHECK.KEY 'SOE.SALESPERSON.EDIT',EDIT.OK
          IF EDIT.OK OR LED(72)<1,GEN>=USER.ID THEN
             B = LED(72)<1,GEN>
IN$$4:       INP B,20,11,10,'MCU',V_'S:VERF.SALESMAN',H_"IH#22"
             IF CHANGED THEN
                OE.ADD.COMMENT OID,GEN,'Changed Out Salesperson from : ':LED(72)<1,GEN>:' to : ':B
                REDISP = YES
                LED(72)<1,GEN> = B
                ATB = 72; ATB.DESC = 'Out Salesperson'; GOSUB CHK.COPY.MODE
                SOE.UPD.COMM.PLAN OID,GEN,ATB
             END
          END ELSE IF MOVE=0 OR MOVE=1 OR MOVE=4 THEN MOVE = 5
          IF QUIT THEN GOTO FILEIT
          ON MOVE+1 GOTO IN.SLSP,IN.SLSP,IN.WRTR,IN.TAX.JUR,IN.ISLSP,IN.ISLSP
*-------------------------------------------------------------------------*
IN.ISLSP: CHECK.KEY 'SOE.SALESPERSON.EDIT',EDIT.OK
          IF EDIT.OK OR LED(34)<1,GEN>=USER.ID THEN
             B = LED(34)<1,GEN>
IN$$5:       INP B,20,12,10,'MCU',V_'S:VERF.SALESMAN',H_"IH#23"
             IF CHANGED THEN
                OE.ADD.COMMENT OID,GEN,'Changed In Salesperson from : ':LED(34)<1,GEN>:' to : ':B
                LED(34)<1,GEN> = B
                ATB = 34; ATB.DESC = 'In Salesperson'; GOSUB CHK.COPY.MODE
                SOE.UPD.COMM.PLAN OID,GEN,ATB
             END
          END ELSE IF MOVE=0 OR MOVE=1 OR MOVE=4 THEN MOVE=5
          IF QUIT THEN GOTO FILEIT
          ON MOVE+1 GOTO IN.ISLSP,IN.ISLSP,IN.SLSP,IN.TAX.EX,IN.FI,IN.FI
*-------------------------------------------------------------------------*
IN.FI:  * IF REMOTE.CUST THEN LN = 0 ELSE LN = 1
IN$$27:   INP FI,21,13,1,'YN_',H_"IH#28"
          IF CHANGED THEN
             IF FI = '' THEN
                FI               = CUSS(39)<1,2>    ;* Freight In Exempt
                LED(69)<1,GEN,2> = FI
                LED(69)<1,GEN,4> = NO
                FI.OVD           = ''
                FI.MSG  = 'Freight in exempt flag returned to default : '
                FI.MSG := YN[FI+1,1]
             END ELSE
                * Subvalue 4 holds a flag indicating that this field was
                * manually overridden
                LED(69)<1,GEN,2> = FI
                LED(69)<1,GEN,4> = YES
                FI.OVD           = '*'
                FI.MSG  = 'Freight in exempt flag changed from : '
                FI.MSG := YN[LED(69)<1,GEN,2>+1,1]:' to : ':YN[FI+1,1]
             END
             OE.ADD.COMMENT OID,GEN,FI.MSG
             ATB = 69; ATB.DESC='Freight In Exempt'; GOSUB CHK.COPY.MODE
             PRINT @(21,13):YN[FI+1,1]                 "L#1"
             PRINT @(22,13):FI.OVD                     "L#1"
          END
          IF QUIT THEN GOTO FILEIT
          ON MOVE+1 GOTO IN.FI,IN.FI,IN.ISLSP,IN.FO,IN.STYLE,IN.FO
*-------------------------------------------------------------------------*
IN.FO:  * IF REMOTE.CUST THEN LN = 0 ELSE LN = 1
          ADD.INSTR = NO
IN$$13:   INP FO,30,13,1,'YN_',H_"IH#28"
          IF CHANGED THEN
             IF FO = '' THEN
                OE.GET.FEX FO,OID,GEN
                LED(69)<1,GEN,1> = FO
                LED(69)<1,GEN,3> = NO
                FO.OVD           = ''
                FO.MSG  = 'Freight out exempt flag returned to default : '
                FO.MSG := YN[FO+1,1]
             END ELSE
                * Subvalue 3 holds a flag indicating that this field was
                * manually overridden
                LED(69)<1,GEN,1> = FO
                LED(69)<1,GEN,3> = YES
                FO.OVD           = '*'
                FO.MSG  = 'Freight out exempt flag changed from : '
                FO.MSG := YN[LED(69)<1,GEN,1>+1,1]:' to : ':YN[FO+1,1]
             END
             OE.ADD.COMMENT OID,GEN,FO.MSG
             ATB = 69; ATB.DESC = 'Freight Out Exempt'
             GOSUB CHK.COPY.MODE
             PRINT @(30,13):YN[LED(69)<1,GEN,1>+1,1]   "L#1"
             PRINT @(31,13):FO.OVD                     "L#1"
          END
          IF QUIT THEN GOTO FILEIT
          ON MOVE+1 GOTO IN.FO,IN.FI,IN.ISLSP,IN.TAX.CD,IN.STYLE,IN.STYLE
*-------------------------------------------------------------------------*
IN.STYLE: *** Print Style
          * If Eclipse Forms are enabled, we are not going to hit the
          * Print Style input. This logic will allow us to skip over it
          * and proceed to the next field gracefully.
          IF USE.ECLIPSE.FORMS$ THEN
             BEGIN CASE
             CASE (MOVE = 4); GOTO IN.SHP.INST
             CASE (MOVE = 5); GOTO IN.PO
             CASE OTHERWISE;  GOTO IN.FI
             END CASE
          END
IN$$8:    INP STYLE,20,14,10,'MCU',V_'PRINT.STYLES,1',H_"IH#26"
          IF CHANGED THEN
             OE.ADD.COMMENT OID,GEN,'Changed Print Style from : ':LED(77)<1,GEN>:' to : ':STYLE
             LED(77)<1,GEN> = STYLE
             ATB = 77; ATB.DESC='Print Style'; GOSUB CHK.COPY.MODE
          END
          IF QUIT THEN GOTO FILEIT
          ON MOVE+1 GOTO IN.STYLE,IN.STYLE,IN.FI,IN.SRC,IN.SHP.INST,IN.PO
*-------------------------------------------------------------------------*
IN.SRC:   ADD.NOTE = NO
          LOCATE LED(3)<1,GEN> IN GL.SALES.TYPE<1> SETTING POS THEN
          OLDB = LED(3)<1,GEN>
          END
          IF REMOTE.CUST THEN
IN$$6:       INP B,50,14,0,H_"IH#24"
          END ELSE
IN$$7:       INP B,50,14,29,H_"IH#25"
             IF CHANGED OR HELP THEN
                IF OE.LOCKED.DIR$ THEN
                   ERR.MESS 14,10,BELL:"Cannot Change Sale Source On Reconciled Direct Order"
                   LOCATE LED(3)<1,GEN> IN GL.SALES.TYPE<2> SETTING POS THEN
                    DISP.SRC = GL.SALES.TYPE<1,POS>
                   END ELSE DISP.SRC = ''

                   PRINT @(50,14):DISP.SRC "L#29"
                   GOTO IN.SRC
                END
                VERIFY = 'D:':VALID.SRCS
                VALIDATE.INP B,50,14,29,VERIFY
                IF OLDB # B THEN CHANGED = 1
                PRINT @(50,14):B"L#29"
             END
          END
          IF CHANGED THEN
             LOCATE B IN GL.SALES.TYPE<1> SETTING POS THEN
                B = GL.SALES.TYPE<2,POS>
             END ELSE B = ''
             IF B='' THEN
                PRINT @(50,14):SRC"L#29"; PRINT BELL:; GOTO IN.SRC
             END
             LED(3)<1,GEN> = B
             ATB = 3; ATB.DESC = 'Sale Source'; GOSUB CHK.COPY.MODE
          END

          IF QUIT THEN GOTO FILEIT
          ON MOVE+1 GOTO IN.SRC,IN.STYLE,IN.TAX.CD,IN.SRC,IN.OTHER.INST,IN.OTHER.INST
*-------------------------------------------------------------------------*
IN.PO:    INP B,56,6,20,V_"S:VERF.CUS.PO.NUM,":LED(5)<1,GEN>
          IF CHANGED THEN
             IF IS.JOB THEN
                IF NOT(JM.EDIT) THEN
                   MSG = "You are not Authorized to change the PO number on a Job Management Order!"
                   ERR.MESS 5,4,BELL:MSG
                   PRINT @(56,6):LED(13)<1,GEN>              "L#20"
                   GOTO IN.PO
                END
             END
             PO.OK = YES
             PMPT = ''
             CHECK.DUP.CUS.PO B, LED(5)<1,GEN>,PMPT
             IF PMPT # '' THEN
                PO.OK = "N"
INPOCHK:        INP.PROMPT PO.OK,PMPT,'YN',1
             END
             IF PO.OK THEN
                LED(13)<1,GEN> = B
                ATB = 13; ATB.DESC = 'Customer P/O #'; GOSUB CHK.COPY.MODE
             END ELSE
                B = ""
                PRINT @(56,6):"" "L#20"
                GOTO IN.PO
             END
          END
          IF QUIT THEN GOTO FILEIT
          IF VIEW.ONLY = 2 THEN
             ON MOVE+1 GOTO IN.PO,IN.PO,IN.PO,IN.PO,IN.REL,IN.REL
          END ELSE
             ON MOVE+1 GOTO IN.PO,IN.BRCH,INADR3,IN.PO,IN.REL,IN.REL
          END
*-------------------------------------------------------------------------*
IN.REL:   INP B,56,7,20
          IF CHANGED THEN
             LED(65)<1,GEN> = B
             ATB = 65; ATB.DESC = 'Customer Rel #';GOSUB CHK.COPY.MODE
          END
          IF QUIT THEN GOTO FILEIT
          IF VIEW.ONLY = 2 THEN
             ON MOVE+1 GOTO IN.REL,IN.REL,IN.PO,IN.REL,IN.OBY,IN.OBY
          END ELSE
             ON MOVE+1 GOTO IN.REL,IN.BRCH,IN.PO,IN.REL,IN.OBY,IN.OBY
          END
*-------------------------------------------------------------------------*
IN.OBY:   * Input order by, validating against Customer Contact (if
          * OE.VAL.CUS.CONTACT control record set) or against CUSS file
INOBY1:   INP OBY,56,8,23,V_'S:VERF.ORDERED.BY,':ST.CN,H_'SOE.HEADER~IN.OBY'
          IF OBY = '' THEN
             * Authorization is required
             IF CUSS(27) THEN
                * If control record is turned on, require entry. If control
                * record is turned off, require entry if there are
                * authorized personnel in Customer Credit Maint.
                VAL.CONT = OE.VAL.CUS.CONTACT
                IF VAL.CONT OR ( NOT(VAL.CONT) AND CUSS(29) ) THEN
                   ERR.MESS 19,6,"Customer Requires Order Authorization."
                   GOTO INOBY1
                END
             END
          END
          IF OBY[1,1] = '#' THEN
             READ CREC FROM CFILE,TRIM(OBY[2,99]) THEN
                COPY.CONTACT = YES
                CONTACT      = OBY
                GOSUB SET.CONTACT
             END
          END
          IF CHANGED THEN
             OLD.OBY = LED(68)<1,GEN>
             LED(68)<1,GEN> = OBY
             CMNT = 'Changed Ordered By from ':OLD.OBY:' to ':OBY
             OE.ADD.COMMENT OID,GEN,CMNT
             ATB = 68; ATB.DESC = 'Ordered By'; GOSUB CHK.COPY.MODE
          END
          IF QUIT THEN GOTO FILEIT
          IF VIEW.ONLY = 2 THEN
             ON MOVE+1 GOTO IN.OBY,IN.OBY,IN.REL,IN.OBY,IN.PHN,IN.PHN
          END ELSE
             ON MOVE+1 GOTO IN.OBY,IN.ODATE,IN.REL,IN.OBY,IN.PHN,IN.PHN
          END
*-------------------------------------------------------------------------*
          * Input Order By Phone, validating against Customer Contact if
          * OE.VAL.CUS.CONTACT control record set to 'Y'
IN.PHN:   ADD.INSTR = NO
          ADD.NOTE  = NO
          IF OE.VAL.CUS.CONTACT THEN
IN$$20:      INP PHN,56,9,20,V_'D:':VALID.PHONES,H_'SOE.HEADER~IN.PHN'
          END ELSE
IN$$21:      INP PHN,56,9,20,H_'SOE.HEADER~IN.PHN'
          END
          IF CHANGED THEN
             OLD.PHN = LED(71)<1,GEN>
             LED(71)<1,GEN,1> = PHN
             CMNT = 'Changed Phone Number from ':OLD.PHN:' to ':PHN
             OE.ADD.COMMENT OID,GEN,CMNT
             ATB = 71; ATB.DESC = 'Phone Number'; GOSUB CHK.COPY.MODE
          END
          IF QUIT THEN GOTO FILEIT
          IF VIEW.ONLY = 2 THEN
             ON MOVE+1 GOTO IN.PHN,IN.PHN,IN.OBY,IN.PHN,IN.OTHER.INST,IN.OTHER.INST
          END ELSE
             ON MOVE+1 GOTO IN.PHN,IN.PICK,IN.OBY,IN.PHN,IN.TERMS,IN.TERMS
          END
*-------------------------------------------------------------------------*
IN.TERMS: CHECK.KEY 'SOE.PAYMENT.TERMS.EDIT',EDIT.OK
          IF EDIT.OK THEN
IN$$9:    INP B,56,10,12,'MCU',V_'S:VERF.INP.STERMS',H_"IH#27"
             IF CHANGED THEN
                READV SPLIT.IT FROM TERMSFILE,B,33 ELSE SPLIT.IT = ''

                IF LED(8)<1,GEN> AND SPLIT.IT THEN
                   MSG = 'You can not Change Terms to Split Terms on an Invoiced Gen.'
                   MSG<2> = 'Please Reopen the Gen Before Changing to Split Terms!!'
                   MESS 12,10,MSG
IN$$22:            INP A,0,0,0
                   B = LED(29)<1,GEN>
                   PRINT @(56,10): B 'L#12'
                   GOTO IN.TERMS


                END


                OE.CALC.HNDL OID,GEN,HNDL
                OE.ADD.COMMENT OID,GEN,'Changed Terms from : ':LED(29)<1,GEN>:' to ':B
                LED(29)<1,GEN> = B
                PRINT @(56,10):B"L#12"
                PRINT @(68,10):OCONV(B,'TTERMS;X;1;1') "L#10"
                ATB = 29; ATB.DESC = 'Payment Terms'; GOSUB CHK.COPY.MODE
                OE.CALC.TERMS OID,GEN
                OE.CALC.HNDL OID,GEN,NHNDL
                IF NHNDL # HNDL THEN
                   LED(36)<1,GEN,2> = ''
                   GOSUB CLR.HNDL
                END
             END
          END ELSE IF MOVE=0 OR MOVE=3 THEN MOVE = 5
          IF QUIT THEN GOTO FILEIT
          ON MOVE+1 GOTO IN.TERMS,IN.WRTR,IN.PHN,IN.TERMS,IN.TAX.JUR
*-------------------------------------------------------------------------*
IN.TAX.JUR:*
          CHECK.KEY 'SOE.TAX.EDIT',EDIT.OK,EDIT.LVL
          IF EDIT.LVL>1 THEN
             IF USE.STAX THEN TJVERF = 'S:VERF.GEOCODE' ELSE
                TJVERF = 'TAX.CODES'
             END
IN.TJUR:     INP B,56,11,10,,,,,TJVERF
             IF CHANGED THEN
                OE.ADD.COMMENT OID,GEN,'Tax Jurisdiction changed from : ':LED(79)<1,GEN,1>:' to ':B
                IF B = '' THEN
                   IF USE.STAX THEN PRINT BELL:; GOTO IN.TJUR
                   LED(79)<1,GEN> = ''
                   * set the order level split tax flag set at the customer
                   LED(79)<1,GEN,5> = CUSS(183)
                END ELSE
                   LED(79)<1,GEN,1> = B
                   LED(79)<1,GEN,2> = YES
                   IF USE.STAX THEN LED(79)<1,GEN,3> = YES
                END
                LED(64)<1,GEN> = ''
                OE.TAX.CALC OID,GEN,QSIGN,TAX.AMTS,JUR.IDS

                STR = LED(79)<1,GEN,1> "L#10":" *"[LED(79)<1,GEN,2>+1,1]
                PRINT @(56,11):STR

                ATB = 79; ATB.DESC = 'Tax Jurisdiction'
                GOSUB CHK.COPY.MODE
             END
             IF QUIT THEN GOTO FILEIT
             ON MOVE+1 GOTO IN.TJUR,IN.SLSP,IN.TERMS,IN.TEXP,IN.TEXP
          END ELSE
             ON MOVE+1 GOTO IN.TERMS,IN.TERMS,IN.TERMS
          END
*-------------------------------------------------------------------------*
IN.TAX.EX:CHECK.KEY 'SOE.TAX.EDIT',EDIT.OK,EDIT.LVL
          IF EDIT.LVL>0 THEN
IN.TEXP:     INP B,56,12,20
             IF CHANGED THEN
                OLD.EXP = LED(61)<1,GEN,1>
                OE.ORDER.TOTAL OID,GEN,QSIGN,,,,,OLD.TAX,OLD.FET
                LED(61)<1,GEN,1> = TRIM(B)
                LED(61)<1,GEN,2> = 1
                LED(61)<1,GEN,3> = ''
                LED(64)<1,GEN>   = ''
                OE.TAX.CALC OID,GEN,QSIGN
                IF LED(61)<1,GEN,3> THEN
                   PRINT @(77,12): '*'
                END ELSE
                   PRINT @(77,12): SPACE(1)
                END
                OE.ORDER.TOTAL OID,GEN,QSIGN,,,,,NEW.TAX,NEW.FET
                CMNT = 'Change Tax Exp # from ':OLD.EXP:' to ':B:' - Tax Amt : ':OCONV(OLD.TAX,'MR2')"R2#10":' to ':OCONV(NEW.TAX,'MR2')"R2#10"
                OE.ADD.COMMENT OID,GEN,CMNT
                ATB = 61; ATB.DESC = 'Tax Exempt ID #'
                GOSUB CHK.COPY.MODE
             END
             IF QUIT THEN GOTO FILEIT
             ON MOVE+1 GOTO IN.TEXP, IN.ISLSP, IN.TAX.JUR, IN.TEXP
          END ELSE
             ON MOVE+1 GOTO IN.TAX.JUR,IN.ISLSP,IN.TAX.JUR
          END
*-------------------------------------------------------------------------*
IN.TAX.CD:CHECK.KEY 'SOE.TAX.EDIT',EDIT.OK,EDIT.LVL
          IF EDIT.LVL>0 THEN
INTXCD:      INP TXCODE,56,13,10,V_"C:VALID.TAX.EXEMPT.TYPES"
             IF CHANGED THEN
                OLD.TXCD = LED(101)<1,GEN>
                LED(101)<1,GEN> = TXCODE
                CMNT = 'Changed Tax Exempt Code from ':OLD.TXCD:' to ':TXCODE
                OE.ADD.COMMENT OID,GEN,CMNT
                ATB = 101; ATB.DESC = 'Tax Exempt Code'
                GOSUB CHK.COPY.MODE
             END
             IF QUIT THEN GOTO FILEIT
             ON MOVE+1 GOTO IN.TAX.CD,IN.FO,IN.TAX.EX,IN.TAX.CD,IN.SRC,IN.SRC
          END ELSE
             ON MOVE+1 GOTO IN.TEXP,IN.FO,IN.TAX.JUR,IN.SRC,IN.SRC
          END
*-------------------------------------------------------------------------*
IN.SHP.INST: *
          ADD.NOTE = NO
          B = LED(74)<1,GEN>
          CONVERT SVM TO VM IN B
          ADD.INSTR = YES
          *** Need to reset the WP.INFO variable because otherwise it is
          *** still using the input from the previous word processing
          *** space.  We save and restore just to be safe.
          SV.WP.INFO = WP.INFO$
          WP.INFO$ = ''
IN$$11:   INPWP B,1,16,38,4,99,'0110'
          CONVERT VM TO SVM IN B
          IF B # LED(74)<1,GEN> THEN
             IF (NOT(VIEW.ONLY) OR (VIEW.ONLY = 2)) THEN
                LED(74)<1,GEN> = B
                ATB = 74; ATB.DESC = 'Shipping Instructions'
                GOSUB CHK.COPY.MODE
                ABC.ENABLED = NO
                IF ABC.ENABLED$ THEN
                   CTRB.ID = "ABC.ENABLED~":LED(2)<1,GEN,2>
                   READV ABC.ENABLED FROM CTRBFILE,CTRB.ID,1 ELSE
                      ABC.ENABLED = NO
                   END
                END
                IF ABC.ENABLED THEN
                   ACD = 'SHINST'
                   LOCATE ACD IN LED(120)<1> SETTING XX ELSE
                      GOSUB SET.DATA
                      GOSUB LOG.ABC
                      LED(120)<1,-1> = ACD
                   END
                END
             END ELSE
                GOSUB PRT.CMTS;* redisplay comments
                ERR.MSG  = 'View Only!':AM:'Updating Shipping'
                ERR.MSG := ' Instructions is Not Allowed.'
                UT.GET.PROMPT '%103',PRESS.ENTER
IN$$18:         INP.PROMPT ,ERR.MSG:AM:PRESS.ENTER,,0
             END
          END

          *** Restore your word processing info just to be safe.
          WP.INFO$ = SV.WP.INFO
          IF QUIT THEN
             IF NOT(VIEW.ONLY) OR VIEW.ONLY = 2 OR VEDIT.OK THEN
                GOTO FILEIT
             END ELSE
                GOTO FINISH
             END
          END
          BEGIN CASE
          CASE NOT(VIEW.ONLY)
             ON MOVE+1 GOTO IN.SHP.INST,IN.SHP.INST,IN.STYLE,IN.OTHER.INST,IN.SHP.INST,IN.SHP.INST
          CASE VIEW.ONLY = 2
             ON MOVE+1 GOTO IN.SHP.INST,IN.SHP.INST,IN.PHN,IN.OTHER.INST,IN.SHP.INST,IN.SHP.INST
          CASE OTHERWISE
             ON MOVE+1 GOTO IN.SHP.INST,IN.SHP.INST,IN.SHP.INST,IN.OTHER.INST,IN.SHP.INST,IN.SHP.INST
          END CASE
*-------------------------------------------------------------------------*
IN.OTHER.INST: *** Internal Notes

          IF NOT(REMOTE.CUST) THEN
             B = LED(80)<1,GEN>
          END ELSE
             B = ''
          END
          SV.LED80 = B
IN.INST:  CONVERT SVM TO VM IN B

          ADD.INSTR = NO
          ADD.NOTE = YES

          *** Need to reset the WP.INFO variable because otherwise it is
          *** still using the input from the previous word processing
          *** space.  We save and restore just to be safe.
          SV.WP.INFO = WP.INFO$
          WP.INFO$ = ''

IN$$12:   INPWP B,40,16,38,4,99,'1100'
          CONVERT VM TO SVM IN B
          IF REMOTE.CUST THEN B = ''
          IF B # LED(80)<1,GEN> AND NOT(REMOTE.CUST) THEN
             IF (NOT(VIEW.ONLY) OR (VIEW.ONLY = 2))  THEN
                LED(80)<1,GEN> = B
                VERF.COPY = YES; ATB = 80
                ATB.DESC = 'Internal Notes'
                IF LED(6)<1,GEN> = 'D' AND COPY.NTS THEN
                   GOSUB COPY.NOTES
                END ELSE
                   GOSUB CHK.COPY.MODE
                END
             END ELSE
                *** If user has autorization let them update the notes
                *** for the order even if view only.
                ERR.MSG = ''
                IF NOTES.OK THEN
                   *** Checks to see if the ledger is available for update.
                   GOSUB CHK.LED.LOCK
                   IF LOCK.MSG THEN
                      ERR.MSG = LOCK.MSG
                   END ELSE
                      LED(80)<1,GEN> = B
                      VERF.COPY      = YES
                      ATB            = 80
                      ATB.DESC       = 'Internal Notes'
                      IF LED(6)<1,GEN> = 'D' AND COPY.NTS THEN
                         GOSUB COPY.NOTES
                      END ELSE
                         GOSUB CHK.COPY.MODE
                      END
                      IF NOT(PREV.LOCKED) THEN
                         WRITEV LED(80) ON LEDFILE,OID,80
                         OE.UNLOCK.LED OID
                      END
                      CMT = 'Change to Internal Notes in View Only Mode'
                      OE.ADD.COMMENT OID,GEN,CMT
                   END
                END ELSE
                   ERR.MSG = 'View Only!'
                END
                IF ERR.MSG # '' THEN
                   LED(80)<1,GEN> = SV.LED80
                   GOSUB PRT.CMTS;* redisplay comments
                   ERR.MSG := AM:'Updating Internal Notes is Not Allowed.'
                   UT.GET.PROMPT '%103',PRESS.ENTER
IN$$19:            INP.PROMPT ,ERR.MSG:AM:PRESS.ENTER,,0
                END
             END
          END

          *** Restore your word processing info just to be safe.
          WP.INFO$ = SV.WP.INFO
          IF QUIT THEN
             IF NOT(VIEW.ONLY) OR VIEW.ONLY = 2 OR VEDIT.OK THEN
                GOTO FILEIT
             END ELSE
                GOTO FINISH
             END
          END

          BEGIN CASE
          CASE NOT(VIEW.ONLY)
             ON MOVE+1 GOTO IN.OTHER.INST,IN.SHP.INST,IN.SRC,IN.OTHER.INST,IN.OTHER.INST,IN.OTHER.INST
          CASE VIEW.ONLY = 2
             ON MOVE+1 GOTO IN.OTHER.INST,IN.SHP.INST,IN.PHN,IN.OTHER.INST,IN.OTHER.INST,IN.OTHER.INST
          CASE OTHERWISE
             ON MOVE+1 GOTO IN.OTHER.INST,IN.SHP.INST,IN.OTHER.INST,IN.OTHER.INST,IN.OTHER.INST,IN.OTHER.INST
          END CASE
*-------------------------------------------------------------------------*
     * Copy data to all GENs if new order
COPY.ALL:
          GEN.CT = DCOUNT(LED(9),VM)
          FOR GN = 1 TO GEN.CT
             IF GN#GEN AND LED(8)<1,GN>='' AND LED(6)<1,GN>#'Y' AND LED(6)<1,GN>#'$' THEN
                BEGIN CASE
                CASE ATB = 78
                   LED(ATB)<1,GN> = LED(ATB)<1,GEN>
                   GOSUB UPD.ZIP
                CASE ATB = 79
                   LED(ATB)<1,GN,1> = LED(ATB)<1,GEN,1>
                   LED(ATB)<1,GN,2> = LED(ATB)<1,GEN,2>
                   LED(64)<1,GN> = ''
                   OE.TAX.CALC OID,GEN,QSIGN,TAX.AMTS,JUR.IDS
                   OE.ADD.COMMENT OID,GEN,'Tax Jurisdiction changed from : ':LED(ATB)<1,GN,1>:' to ':LED(ATB)<1,GN,1>
                CASE ATB = 61
*** Copy the tax exempt and tax info to all gens.
                   OLD.EXP = LED(61)<1,GN,1>
                   OE.ORDER.TOTAL OID,GN,QSIGN,,,,,OLD.TAX,OLD.FET
                   LED(ATB)<1,GN,1> = LED(ATB)<1,GEN,1>
                   LED(ATB)<1,GN,2> = LED(ATB)<1,GEN,2>
                   LED(64)<1,GN>   = ''
                   OE.TAX.CALC OID,GN,QSIGN
                   OE.ORDER.TOTAL OID,GN,QSIGN,,,,,NEW.TAX,NEW.FET
                   CMNT = 'Change Tax Exp # from ':OLD.EXP:' to ':B:' - Tax Amt : ':OCONV(OLD.TAX,'MR2')"R2#10":' to ':OCONV(NEW.TAX,'MR2')"R2#10"
                   OE.ADD.COMMENT OID,GN,CMNT
                CASE ATB = 69
                   IF ATB.DESC = "Freight In Exempt" THEN
                      LED(ATB)<1,GN,2> = LED(ATB)<1,GEN,2>
                      LED(ATB)<1,GN,4> = LED(ATB)<1,GEN,4>
                   END ELSE
                      LED(ATB)<1,GN,1> = LED(ATB)<1,GEN,1>
                      LED(ATB)<1,GN,3> = LED(ATB)<1,GEN,3>
                   END
                CASE OTHERWISE
                   LED(ATB)<1,GN> = LED(ATB)<1,GEN>
                END CASE
             END
          NEXT GN
          RETURN
*-------------------------------------------------------------------------*
CHK.COPY.MODE: *** figures out what copy mode we are in and copys
               *** to all gens accordingly.
          BEGIN CASE
          CASE VIEW.ONLY = 2
          CASE COPY.OPT = 'On'
             GOSUB COPY.ALL
          CASE COPY.OPT = 'Prompt'
             LOCATE ATB.DESC IN ATB.DESCS SETTING POS ELSE
                ATB.NUM<POS>   = ATB
                ATB.DESCS<POS> = ATB.DESC
             END
          END CASE
          RETURN
*-------------------------------------------------------------------------*
*** Make the freight in exempt flag backwards compatible with release 6
*** We now store this flag at the ledger record in case we need to
*** override it - we used to store in the customer record
CHK.FGHT.EXMPT:
          IF DCOUNT(LED(69)<1,GEN>,SVM) > 1 THEN
             FI.EXMPT = LED(69)<1,GEN,2>
          END ELSE
             FI.EXMPT = CUSS(39)<1,2>
          END

          RETURN
*-------------------------------------------------------------------------*
CLR.HNDL: FOR XX = 1 TO 4
          IF LED(36)<1,GEN,2> THEN
             LED(36)<1,GEN,(XX+6)> = 0
          END ELSE
             LED(36)<1,GEN,(XX+6)> = ''
          END
          NEXT XX

          LED(36)<1,GEN,8> = NHNDL*QSIGN

          IF LED(8)<1,GEN> THEN
             OE.POST.FGHT.HNDL OID,GEN,QSIGN
             *** Set up balancing entries.  Need to store LED values
             *** in variables first because it won't update otherwise
             GL.IDS  = LED(24)<1,GEN>
             GL.NOS  = LED(25)<1,GEN>
             GL.AMTS = LED(26)<1,GEN>
             OE.UPD.GL.AR OID,GEN,GL.IDS,GL.NOS,GL.AMTS
             LED(24)<1,GEN> = GL.IDS
             LED(25)<1,GEN> = GL.NOS
             LED(26)<1,GEN> = GL.AMTS
             OE.UPDATE.INVOICE OID,GEN,QSIGN
          END
          RETURN
*-------------------------------------------------------------------------*
INIT:     QSIGN      = -1
          LOCK.MSG   = ''
          REDISP     = NO
          CVERF.REQ  = NO
          WAS.CV.REQ = NO
          ADD.INSTR  = NO
          ADD.NOTE   = NO
          ADDR.CHANGE.ALLOWED = NO
          CITY       = LED(78)<1,GEN,4>
          ST         = LED(78)<1,GEN,5>
          ZIP        = LED(75)<1,GEN>
          SV.ADDR1 = ''; SV.ADDR2 = ''; SV.CITYST = ''; SV.ZIP = ''
          READ CITY.VERF FROM CTRLFILE,'OE.CITY.VERF' ELSE CITY.VERF = NO
          READ GL.SALES.TYPE FROM CTRLFILE,'GL.SALES.TYPE' ELSE GL.SALES.TYPE = ''
          VALID.SRCS = SECURITY<18>
          GET.CUS LED(2)<1,GEN,1>,LED(1)<1,GEN>,LED(5)<1,GEN>,QSIGN
          PO.CHK  = (CUSS(45)<1,1>#'' AND CUSS(45)<1,1>#'R' AND CUSS(45)<1,1>#0 AND CUSS(45)<1,1>#'N')
          REL.CHK = (CUSS(45)<1,1>='R' OR CUSS(45)<1,1>='B')
          AUTH.CHK = CUSS(27)
          SVIA = LED(70)<1,GEN>
          SVIA.FGT=TRANS('SHIP.VIAS',SVIA,50,'X')

          GOSUB FREIGHT.SETUP


          *** Determine whether to validate against customer contacts
          READ OE.VAL.CUS.CONTACT FROM CTRLFILE,'OE.VAL.CUS.CONTACT' ELSE
             OE.VAL.CUS.CONTACT = ''
          END

          * If Job Management Order only certain things they can do.
          IS.JOB = LED(83)<1,1>[1,7] = "@JOBNO="
          IF IS.JOB THEN
             CHECK.KEY 'JOB.MGMT.SUPERUSER',JM.EDIT
          END

          UT.OPEN.COMMON.FILE 'CONTACT',CHNDL
          IF CHNDL THEN
             CFILE = FILES(CHNDL)
          END ELSE
             FILE.ERR = YES
          END

          IF OE.VAL.CUS.CONTACT OR LED(68)<1,GEN>[1,1] = '#' THEN
             CONTACT.DISP = ''
             CREC         = ''
             VALID.PHONES = ''
             OBY          = ''
             COPY.CONTACT = NO
             BT.CN        = LED(1)<1,GEN>
             ST.CN        = LED(5)<1,GEN>
             CONTACT      = LED(68)<1,GEN>
             PHN          = LED(71)<1,GEN>
             CONTACT.ID = CONTACT
             IF CONTACT[1,1] = '#' THEN CONTACT.ID = TRIM(CONTACT[2,99])
             READ CREC FROM CFILE,CONTACT.ID THEN
                GOSUB SET.CONTACT
             END ELSE
                CONTACT.DISP = CONTACT
             END
          END

          *** figure out what the default setting should be for the copy
          *** changes function.
          READ COPY.CHGS FROM CTRLFILE,'OE.COPY.CHNGS' ELSE COPY.CHGS = ''
          IF COPY.CHGS THEN
             PRINT @(61,21): COPY.CHGS
             COPY.OPT = COPY.CHGS
          END ELSE
             PRINT @(61,21): 'Off'
             COPY.OPT = 'Off'
          END

          *** Determine if system should use NST mod in determining tax
          *** rates
          USE.STAX = (USE.STAX$ AND USE.STAX$ <= LED(9)<1,GEN>)

          *** Check if picker can have any home branch
          READV PICK.ALL.BRS FROM CTRLFILE,'OE.ALLOW.PICKER.ALL.BRS',1 ELSE
             PICK.ALL.BRS = NO
          END

          RETURN
*-------------------------------------------------------------------------*
LOAD.HOTKEYS:*** Load the hotkeys

          MENU.CLEAR
          IF NOT(REMOTE.CUST) THEN
             MENU.LOAD  2,21, 5, 1,'A'    ;* Addl
             MENU.LOAD 10,21, 7, 1,'C'    ;* Chg Log
             MENU.LOAD 20,21, 8, 1,'S'    ;* Shipping
             IF NOT(VIEW.ONLY) THEN
                MENU.LOAD 31,21, 5, 1,'I' ;* Instr
             END ELSE
                MENU.LOAD ,,,,''
             END
             IF NOT(VIEW.ONLY) OR (NOTES.OK AND NOT(LOCK.MSG)) THEN
                MENU.LOAD 39,21, 5, 1,'N' ;* Notes
             END ELSE
                MENU.LOAD ,,,,''
             END
             MENU.LOAD 47,21,13, 3,'P'    ;* CoPy
          END ELSE
             PRINT @(10,21):SPACE(7)
             PRINT @(20,21):SPACE(8)
             PRINT @(39,21):SPACE(5)
             MENU.LOAD  2,21, 5,1,'A'     ;* Addl
             MENU.LOAD ,,,,''
             MENU.LOAD ,,,,''
             MENU.LOAD 31,21, 5, 1,'I'    ;* Instr
             MENU.LOAD ,,,,''             ;* <Notes>
             MENU.LOAD ,,,,''             ;* <CoPy>
          END

          RETURN
*-------------------------------------------------------------------------*
CHK.LED.LOCK: *** Check if ledger record is locked.

          LOCK.MSG    = ''
          PREV.LOCKED = NO
          READV TST FROM LEDFILE,OID,0 THEN
             IF VIEW.ONLY THEN
                CHECK.RECORD.LOCK LEDFILE,OID,IS.LOCKED,USER.LOCKED
                IF IS.LOCKED = YES AND USER.LOCKED = USER.ID THEN
                   * User is already editing record
                   IF VEDIT.OK THEN
                      PREV.LOCKED = YES
                   END ELSE
                      UT.GET.PROMPT '%163':AM:OID,LOCK.MSG
                   END
                END
             END
          END ELSE
             LOCK.MSG = 'Can Not Locate ':OID
          END

          IF NOT(LOCK.MSG) THEN
             OE.LOCK.LED.ATTB OID,80,BLAH,LOCK.MSG,YES,,,YES
             IF LOCK.MSG THEN
                * Record is locked by another user
                CHECK.RECORD.LOCK LEDFILE,OID,IS.LOCKED,UID
                UT.GET.PROMPT '%162':AM:OID:AM:UID,LOCK.MSG
             END
          END

          RETURN
*-------------------------------------------------------------------------*
DISPLAY:  *
          OE.DISP.BT.ST GEN
          OE.ORN.CONV OID,GEN,ORN
          LOCATE LED(3)<1,GEN> IN GL.SALES.TYPE<2> SETTING POS THEN
             SRC = GL.SALES.TYPE<1,POS>
          END ELSE SRC = ''
          IF LED(69)<1,GEN,3> THEN FO.OVD = "*" ELSE FO.OVD = ''
          IF LED(69)<1,GEN,4> THEN FI.OVD = "*" ELSE FI.OVD = ''
          BR = LED(2)<1,GEN,1>
          PRINT @(20,6):ORN                         "L#14"
          READV SNAME FROM TERRFILE,BR,1 ELSE SNAME = ''
          PRINT @(20,7):BR"L#4":'-':SNAME           "L#13"
          PRINT @(20,8):OCONV(LED(4)<1,GEN>,'D4/')  "L#10"
          PRINT @(20,9):LED(66)<1,GEN>              "L#10"
          PRINT @(20,10):LED(73)<1,GEN>             "L#10"
          PRINT @(20,11):LED(72)<1,GEN>             "L#10"
          PRINT @(20,12):LED(34)<1,GEN>             "L#10"
          PRINT @(21,13):YN[FI.EXMPT+1,1]           "L#1"
          PRINT @(22,13):FI.OVD                     "L#1"
          PRINT @(30,13):YN[LED(69)<1,GEN,1>+1,1]   "L#1"
          PRINT @(31,13):FO.OVD                     "L#1"
          IF NOT(USE.ECLIPSE.FORMS$) THEN
             PRINT @(20,14):LED(77)<1,GEN>          "L#10"
          END

          PRINT @(56,6):LED(13)<1,GEN>              "L#20"
          PRINT @(56,7):LED(65)<1,GEN>              "L#20"
          IF OE.VAL.CUS.CONTACT OR LED(68)<1,GEN>[1,1] = '#' THEN
             PRINT @(56,8):CONTACT.DISP             "L#23"
             PRINT @(56,9):PHN                     "L#20"
          END ELSE
             PRINT @(56,8):LED(68)<1,GEN>          "L#23"
             PRINT @(56,9):LED(71)<1,GEN,1>        "L#20"
          END
          PRINT @(56,10):LED(29)<1,GEN>            "L#12"
          PRINT @(68,10):OCONV(LED(29)<1,GEN>,'TTERMS;X;1;1') "L#10"
          PRINT @(56,11):LED(79)<1,GEN,1> "L#10":" *"[LED(79)<1,GEN,2>+1,1]
          PRINT @(56,12):LED(61)<1,GEN,1>           "L#20"

          IF NOT(LED(73)<1,GEN>) AND LED(30)<1,GEN> = 'EDI' THEN
             MESS 1,6,BELL:'Written by field is not set'
          END

          IF LED(61)<1,GEN,3> THEN
             PRINT @(77,12): '*'
          END
          PRINT @(56,13):LED(101)<1,GEN>            "L#10"
          PRINT @(50,14):SRC                        "L#29"

PRT.CMTS: SHP.INST = LED(74)<1,GEN>
          CT = DCOUNT(SHP.INST,SVM)
          IF CT>4 THEN CT = 4; PRINT @(28,20):'More'
          IF CT<4 THEN CT = 4
          FOR J=1 TO CT
          PRINT @(1,15+J):SHP.INST<1,1,J>           "L#38"
          NEXT J

          * This won't let REMOTE custs see the internal notes.
          IF NOT(REMOTE.CUST) THEN
             OTHER.INST = LED(80)<1,GEN>
             CT = DCOUNT(OTHER.INST,SVM)
             IF CT>4 THEN PRINT @(70,20):'More'
             FOR J = 1 TO 4
             PRINT @(40,15+J):OTHER.INST<1,1,J>        "L#38"
             NEXT J
          END


          RETURN
*-------------------------------------------------------------------------*
CHNG.BT:  IF REMOTE.CUST THEN GOTO INADR1

          *** If any of the gens in this order have been invoiced
          *** we need to check the auth key to allow users to change
          *** the customer Bill To. We need to do this check even if
          *** this is a new order.
          IF LED(8)<1> # '' THEN
             AUTH.KEY = 'SOE.CLOSED.ORDER.EDIT'
             CHECK.OE.CLOSED.AUTH.KEYS OID,GEN,AUTH.KEY,EDIT.OK,YES
             IF NOT(EDIT.OK) THEN
                MESS 25,5,BELL:'Not Authorized to Change Customer on Invoiced Order'
                GOTO INADR1
             END
          END

          MESS 34,5,'Enter new Bill/Ship To or press <ESC> to Exit'
          PRINT @(41,1):''"L#35"

          PREV.BT = LED(1)<1,GEN>
          PREV.ST = LED(5)<1,GEN>
          BR      = LED(2)<1,GEN,1>

          SOE.SELECT.CUS BR,BT.CN,ST.CN,BTA
          IF QUIT THEN
             GOSUB RELOAD.CUS
             GOTO INADR1
          END

          GET.CUS BR,BT.CN,ST.CN,QSIGN

          NO.OE.OVRD.SV = NO.OE.OVRD$
          NO.OE.OVRD$ = NO
          SOE.CHECK.NO.OE BT.CN,ST.CN,OE.OK,NO.OE

          IF OE.OK AND (PREV.BT # BT.CN OR PREV.ST # ST.CN) THEN
             NO.OE.OVRD$ = NO.OE.OVRD.SV
             MSGS           =  ""
             RESPS          =  ""
             REENTRY        =  NO
             ORDER.INFO              = ""
             ORDER.INFO<CBTST.OID%>  = OID
             ORDER.INFO<CBTST.GEN%>  = GEN
             ORDER.INFO<CBTST.BR%>   = BR
             ORDER.INFO<CBTST.BTCN%> = BT.CN
             ORDER.INFO<CBTST.STCN%> = ST.CN
             ORDER.INFO<CBTST.QSIGN%>= QSIGN

             * This section will ask user all relevant questions about
             * changing the bill to or the ship to on this order
             LOOP
                OE.CHG.BT.ST.CHK ORDER.INFO,LOG.MV,IDS.TO.CHNG,MSGS,RESPS,REENTRY
                IF REENTRY OR MSGS THEN
                   ACTION.DISPLAY MSGS,ABORTED,RESPS
                END
                WHILE REENTRY AND NOT(ABORTED)
             REPEAT

             CHNG.ERR = ABORTED
             IF NOT(ABORTED) THEN
                * Update the bill to and ship to information
                OE.CHG.BT.ST.UPD ORDER.INFO,LOG.MV,IDS.TO.CHNG,MSGS,RESPS
             END

             IF CHNG.ERR THEN
                GOSUB RELOAD.CUS
                GOTO INADR1
             END ELSE
                * Modify Sales Source if Ship to changes (first check
                * Customer override then check TTY)
                IF PREV.ST # ST.CN THEN
                   READV SS.OVRD FROM CUSFILE,ST.CN,72 ELSE SS.OVRD = ''
                   IF SS.OVRD THEN
                      LED(3)<1,GEN> = SS.OVRD
                      ATB.DESC = 'Sale Source'
                      ATB = 3; GOSUB CHK.COPY.MODE
                   END ELSE
                      IF NOT(LED(8)<1,GEN>) THEN
                         GET.TTY TTY.BR,TTY.LOCA,TTY.SOURCE,TTY.SHIPVIA,TTY.RELOG
                         SOE.SELECT.SOURCE SLS.SRC,TTY.SOURCE,TTY.LOCA
                         IF SLS.SRC THEN
                            LED(3)<1,GEN> = SLS.SRC
                            ATB.DESC = 'Sale Source'
                            ATB = 3; GOSUB CHK.COPY.MODE
                         END
                      END
                   END
                END
             END
          END

          GOSUB CHK.FGHT.EXMPT
          GOSUB INIT
          GOSUB DISPLAY
          REDISP = YES
          *** Null out the override since a valid ship to was selected
          LED(78)<1,GEN,6> = ''


          IF CUSS(73)<1,2> AND CUSS(73)<1,2> # LED(2)<1,GEN,1> THEN
             MSG  = "New Ship-To Customer's Pricing Branch Override"
             MSG := " for Branch ":CUSS(73)<1,2>:AM
             MSG := "Does Not Match Current Pricing Branch!"
             MESS 13,7,MSG
IN$$1:       INP A,0,0,0
          END

          IF CUSS(73)<1,1> AND CUSS(73)<1,1> # LED(2)<1,GEN,2> THEN
             MSG  = "New Ship-To Customer's Shipping Branch Override":AM
             MSG := 'Does Not Match Current Shipping Branch!'
             MESS 13,7,MSG
IN$$24:      INP A,0,0,0
          END

          GOTO INADR1
*-------------------------------------------------------------------------*
RELOAD.CUS: * `
          BT.CN = PREV.BT
          ST.CN = PREV.ST
          GET.CUS BR,BT.CN,ST.CN,QSIGN
          LED(78)<1,GEN,6> = ''
          OE.DISP.BT.ST GEN
          RETURN
*-------------------------------------------------------------------------*
INADR1:   INP B,41,2,35
          IF B = '' THEN
             IF LED(78)<1,GEN,2> = '' THEN
                LED(78)<1,GEN,1> = CUSS(2)<1,1>
                LED(78)<1,GEN,2> = CUSS(2)<1,2>
                IF CUSS(2)<1,3> OR CUSS(2)<1,4> OR CUSS(2)<1,5> THEN
                   ADD.ADDR = CUSS(2)<1,3>:VM:CUSS(2)<1,4>:VM:CUSS(2)<1,5>
                   ADD.ADDR = TRIM(ADD.ADDR<1>,VM,'T')
                   LED(78)<1,GEN,7> = LOWER(LOWER(ADD.ADDR))
                END ELSE
                   LED(78)<1,GEN,7> = ''
                END
                REDISP = YES
                GOSUB DISPLAY
             END ELSE
                LED(78)<1,GEN,1> = ''
             END
          END

          IF CHANGED THEN
             REDISP = YES
             IF SV.ADDR1 = '' THEN SV.ADDR1 = LED(78)<1,GEN,1>

             * If customer has flag set not to change addr and user does not
             * have auth.key SOE.ALLOW.ADDR.CHANGE, then skip over this
             * section completely.
             GOSUB CHANGE.ADDR.ALLOWED
             IF ADDR.CHANGE.ALLOWED = NO THEN
                GOSUB DISPLAY
                GOTO IN.PO
             END
             IF B # '' THEN
                LED(78)<1,GEN,1> = B
             END
             ATB.DESC = 'Address'
             ATB = 78; GOSUB CHK.COPY.MODE
             GOSUB FIND.ZIP4
             IF CITY.VERF THEN
                IF SV.ADDR2 = '' THEN SV.ADDR2  = LED(78)<1,GEN,2>
                IF SV.CITYST= '' THEN SV.CITYST = LED(78)<1,GEN,3>
                IF SV.ZIP   = '' THEN SV.ZIP    = LED(75)<1,GEN>
                PRINT @(41,3):SPACE(35); LED(78)<1,GEN,2> = ''
                PRINT @(41,4):SPACE(38); LED(78)<1,GEN,3> = ''
                LED(75)<1,GEN> = ''
                CVERF.REQ = YES
                GOTO INADR2
             END
          END
          IF HELP THEN GOSUB ZIP4
          IF QUIT AND CVERF.REQ THEN
             IF F12 THEN
                LED(78)<1,GEN,1> = SV.ADDR1;  SV.ADDR1 = ''
                LED(78)<1,GEN,2> = SV.ADDR2;  SV.ADDR2 = ''
                LED(78)<1,GEN,3> = SV.CITYST; SV.CITYST = ''
                LED(75)<1,GEN>   = SV.ZIP;    SV.ZIP = ''
                CVERF.REQ = NO
                GOSUB DISPLAY
             END ELSE
                GOTO INADR3
             END
          END
          IF QUIT THEN GOTO FILEIT
          ON MOVE+1 GOTO INADR1,INADR1,CHNG.BT,INADR1,INADR2,INADR2
*-------------------------------------------------------------------------*
INADR2:   INP B,41,3,35
          IF B = '' THEN
             IF LED(78)<1,GEN,1> = '' THEN
                LED(78)<1,GEN,1> = CUSS(2)<1,1>
                LED(78)<1,GEN,2> = CUSS(2)<1,2>
                IF CUSS(2)<1,3> OR CUSS(2)<1,4> OR CUSS(2)<1,5> THEN
                   ADD.ADDR = CUSS(2)<1,3>:VM:CUSS(2)<1,4>:VM:CUSS(2)<1,5>
                   ADD.ADDR = TRIM(ADD.ADDR<1>,VM,'T')
                   LED(78)<1,GEN,7> = LOWER(LOWER(ADD.ADDR))
                END ELSE
                   LED(78)<1,GEN,7> = ''
                END
                REDISP = YES
                GOSUB DISPLAY
             END ELSE
                LED(78)<1,GEN,2> = ''
             END
          END

          IF CHANGED THEN
             REDISP = YES
             IF SV.ADDR2 = '' THEN SV.ADDR2 = LED(78)<1,GEN,2>
             GOSUB CHANGE.ADDR.ALLOWED
             IF ADDR.CHANGE.ALLOWED = NO THEN
                GOSUB DISPLAY
                GOTO IN.PO
             END
             IF B # '' THEN
                LED(78)<1,GEN,2> = B
             END
             ATB.DESC = 'Address'
             ATB = 78; GOSUB CHK.COPY.MODE
             GOSUB FIND.ZIP4
             IF CITY.VERF THEN
                IF SV.ADDR1 = '' THEN SV.ADDR1 = LED(78)<1,GEN,1>
                IF SV.CITYST= '' THEN SV.CITYST= LED(78)<1,GEN,3>
                IF SV.ZIP   = '' THEN SV.ZIP   = LED(75)<1,GEN>
                PRINT @(41,4):SPACE(38); LED(78)<1,GEN,3> = ''
                LED(75)<1,GEN> = ''
                CVERF.REQ = YES
                GOTO INADR3
             END
          END
          IF QUIT AND CVERF.REQ THEN
             IF F12 THEN
                LED(78)<1,GEN,1> = SV.ADDR1;  SV.ADDR1 = ''
                LED(78)<1,GEN,2> = SV.ADDR2;  SV.ADDR2 = ''
                LED(78)<1,GEN,3> = SV.CITYST; SV.CITYST = ''
                LED(75)<1,GEN>   = SV.ZIP;    SV.ZIP = ''
                CVERF.REQ = NO
                GOSUB DISPLAY
             END ELSE
                GOTO INADR3
             END
          END
          IF QUIT THEN GOTO FILEIT
          ON MOVE+1 GOTO INADR2,INADR2,INADR1,INADR2,INADR3,INADR3
*-------------------------------------------------------------------------*
INADR3:
          IF CVERF.REQ THEN
             SV.ADDR1 = ''; SV.ADDR2 = ''; SV.CITYST = ''; SV.ZIP = ''
             WAS.CV.REQ = YES
             CVERF.REQ  = NO
             MESS 24,7,'Shipping Address Changed. City Verification Required.'
          END
          SRCH.ID = LED(78)<1,GEN,4>
IN.ADR3:  INP SRCH.ID,41,4,27,'MCU'
          SRCH.ID = TRIM(SRCH.ID,VM,'T')
          IF SRCH.ID='' THEN GOTO INADR3
          IF CHANGED THEN
             REDISP = YES
             GOSUB CHANGE.ADDR.ALLOWED
             IF ADDR.CHANGE.ALLOWED = NO THEN
                GOSUB DISPLAY
                GOTO IN.PO
             END

             OLD.ZIP = LED(75)<1,GEN>
             ZIP.CODE.GET SRCH.ID,CITY,ST,ZIP
             IF SRCH.ID='' OR ZIP='' THEN
                PRINT @(41,4):SPACE(20)
                CITY = ''
                ST   = ''
                IF WAS.CV.REQ THEN
                   WAS.CV.REQ = NO
                   CVERF.REQ = YES
                END
                GOTO INADR3
             END
             *
             IF ZIP # OLD.ZIP AND LED(8)<1,GEN> # '' THEN
                GET.CUS BR,BT.CN,ST.CN,QSIGN
                LED(75)<1,GEN> = ZIP
                OE.GET.TAXJUR OID,GEN,,TAX.INFO
                IF LED(61)<1,GEN> # TAX.INFO<1> THEN
                   UT.GET.PROMPT '%248',PRMPT
                   COPY.TAX = 'Y'
IN$$26:            INP.PROMPT COPY.TAX,RAISE(PRMPT),'YN'
                END
             END
             *

             GN = GEN
             GOSUB UPD.ZIP
             ATB = 78; ATB.DESC = 'Address'
             GOSUB CHK.COPY.MODE
             GOSUB DISPLAY
             GOSUB FIND.ZIP4
          END
          IF HELP THEN GOSUB ZIP4
          IF QUIT THEN GOTO FILEIT
          ON MOVE+1 GOTO INADR3,INADR3,INADR2,INADR3,IN.PO,IN.PO
*-------------------------------------------------------------------------*
     * Copy ZIP to all GENs if new order
COPY.ZIP: COPY.IT = ''
          GEN.CT = DCOUNT(LED(9),VM)
          FOR GN = 1 TO GEN.CT
          IF GN#GEN AND LED(8)<1,GN>='' AND LED(6)<1,GN>#'Y' THEN
             IF COPY.IT='' THEN
                SV.QUIT = QUIT
                SV.F12  = F12
                PROMPT = 'Copy Change to all Open Shipments (Y/N) : '
IN$$15:   INP.PROMPT COPY.IT,PROMPT,'YN',1
                QUIT = SV.QUIT
                F12  = SV.F12
                IF NOT(COPY.IT) THEN EXIT
                END
             GOSUB UPD.ZIP
             END
          NEXT GN
          RETURN
*-------------------------------------------------------------------------*
UPD.ZIP:  LED(78)<1,GN,3> = CITY[1,22]:','
          LED(78)<1,GN,3> = LED(78)<1,GN,3>"L#23 ":ST"L#3"
          LED(78)<1,GN,4> = CITY
          LED(78)<1,GN,5> = ST
          JAVA.OE.UPD.ZIP OID,GN,ZIP,COPY.TAX
          COPY.TAX = NO

          RETURN
*-------------------------------------------------------------------------*
SUBS:     ON OPTION GOTO ADDL,CHANGE.LOG,INTSHIP,INSTR,NOTES,COPY.TOGGLE
*-------------------------------------------------------------------------*
ADDL:     *
          SOE.HEADER.ADDL.KEYS REMOTE.CUST,OID,GEN,REDISP,VIEW.ONLY,LOG.MV,UPD.GEN.MV

          BEGIN CASE
          CASE (LED(128)<1,1>)
             PRINT @(30,0):BLINK$:"Master Job Bid":NORM$
          CASE (LED(129)<1,1>)
             OFMT      = "L#":OID.LGTH$
             MASTER.ID = LED(129)<1,1>
             NVER      = 28 - ((OID.LGTH$ - 8) / 2)
             PRINT @(NVER,0):BLINK$:"Junior To-":MASTER.ID OFMT:NORM$
          CASE LED(129)<1,2>
             OFMT      = "L#":OID.LGTH$
             MASTER.ID = LED(129)<1,2>
             NVER      = 28 - ((OID.LGTH$ - 8) / 2)
             PRINT @(NVER,0):BLINK$:"Change For-":MASTER.ID OFMT:NORM$
          CASE OTHERWISE
             PRINT @(27,0):"様様様様様様冤様様様"
          END CASE
          ADDR.CHANGED = NO
          *** In case changes were made in the additional address screen,
          *** we need to redisplay the shipping information.
          IF (OLED(78)<1,GEN,1> # LED(78)<1,GEN,1>) OR (OLED(78)<1,GEN,2> #LED(78)<1,GEN,2>) OR (OLED(78)<1,GEN,7> # LED(78)<1,GEN,7>) THEN
             ATB.DESC = 'Address'
             ATB = 78
             GOSUB CHK.COPY.MODE
             IF CITY.VERF THEN
                ADDR.CHANGED = YES
             END
          END
          *** check to see if they changed the name
          IF (OLED(78)<1,GEN,6> # LED(78)<1,GEN,6>) THEN
             ATB.DESC = 'Name'
             ATB      = 78
             GOSUB CHK.COPY.MODE
          END
          OE.DISP.BT.ST GEN
          REDISP = YES
          IF ADDR.CHANGED THEN
             PRINT @(41,4):SPACE(38); LED(78)<1,GEN,3> = ''
             LED(75)<1,GEN> = ''
             CVERF.REQ = YES
             RETURN TO INADR3
          END
          RETURN
*-------------------------------------------------------------------------*
BODY:     IF VIEW.ONLY THEN RETURN
          MOVE = 2
          RETURN TO FILEIT
*-------------------------------------------------------------------------*
CHANGE.LOG: *
          OE.VIEW.COMMENTS OID,GEN
          RETURN
*-------------------------------------------------------------------------*
INSTR:    * Standard Shipping Intructions

          * Make sure to save off shipping intruction if hotkey was used
          * prior to exiting input.
          IF ADD.INSTR THEN
             CONVERT VM TO SVM IN B
             LED(74)<1,GEN> = B
             CONVERT SVM TO VM IN B
             ADD.INSTR = NO
          END

          ENTITY.STD.CMTS.DISP 'C',74,GEN,ABRT

          IF NOT(ABRT) THEN
             GOSUB PRT.CMTS
             ATB = 74; ATB.DESC = 'Shipping Instructions'
             GOSUB CHK.COPY.MODE
             ACD = 'SAINST'
             LOCATE ACD IN LED(120)<1> SETTING XX ELSE
                GOSUB SET.DATA
                GOSUB LOG.ABC
                LED(120)<1,-1> = ACD
             END
          END
          RETURN TO IN.SHP.INST
*-------------------------------------------------------------------------*
NOTES:    * Standard Internal Notes

          * Make sure to save off shipping intruction if hotkey was used
          * prior to exiting input.
          IF ADD.INSTR THEN
             CONVERT VM TO SVM IN B
             LED(74)<1,GEN> = B
             CONVERT SVM TO VM IN B
             ADD.INSTR = NO
          END

          * Saves off internal note if hotkey was used prior to exiting
          * input.
          IF ADD.NOTE THEN
             CONVERT VM TO SVM IN B
             LED(80)<1,GEN> = B
             CONVERT SVM TO VM IN B
             ADD.NOTE = NO
          END ELSE
             SV.LED80 = LED(80)<1,GEN>
          END

          ENTITY.STD.CMTS.DISP 'C',80,GEN,ABRT

          IF NOT(ABRT) THEN
             GOSUB PRT.CMTS
             ATB = 80
             ATB.DESC = 'Internal Notes'
             IF LED(6)<1,GEN> = 'D' AND COPY.NTS THEN
                GOSUB COPY.NOTES
             END ELSE
                GOSUB CHK.COPY.MODE
             END
             B = LED(80)<1,GEN>
             RETURN TO IN.INST
          END

          RETURN TO IN.OTHER.INST
*-------------------------------------------------------------------------*
COPY.TOGGLE: *** toggle between the three options for copying changes to
             *** all gens

          OPT.LIST = 'On':VM:'Off':VM:'Prompt'
IN.OPT:   INP COPY.OPT,61,21,6,V_'D:':OPT.LIST
          RETURN
*-------------------------------------------------------------------------*
CHK.PO:   IF LED(6)<1,GEN>#'B' AND LED(6)<1,GEN>#'X' AND LED(13)<1,GEN>='' THEN
             IF PO.CHK THEN
                SHOW.PO.ERR = NO
                * Only show PO required on Job Management orders if they
                * have the authorization to do anything about it.
                IF NOT(IS.JOB) THEN
                  SHOW.PO.ERR = YES
                END ELSE
                   IF JM.EDIT THEN
                      SHOW.PO.ERR = YES
                   END
                END
                IF SHOW.PO.ERR THEN
                   ERR.MESS 40,9,BELL:'PO Number is Required'
                   RETURN TO IN.PO
                END
             END
          END
          *** If PO has been changed then log it.
          IF OLED(13)<1,GEN>#LED(13)<1,GEN> THEN
             CMNT  = 'Changed Customer P/O # from '
             CMNT := OLED(13)<1,GEN>:' to ':LED(13)<1,GEN>
             OE.ADD.COMMENT OID,GEN,CMNT
          END

          RETURN
*-------------------------------------------------------------------------*

CHK.REL:  IF LED(6)<1,GEN>#'B' AND LED(65)<1,GEN>='' THEN
             IF REL.CHK THEN
                ERR.MESS 40,10,BELL:'Release Number is Required'
                RETURN TO IN.REL
             END
          END

          IF OLED(65)<1,GEN>#LED(65)<1,GEN> THEN
             CMNT  = 'Changed Customer Rel # from '
             CMNT := OLED(65)<1,GEN>:' to ':LED(65)<1,GEN>
             OE.ADD.COMMENT OID,GEN,CMNT
          END

          RETURN
*-------------------------------------------------------------------------*
CHK.AUTH: *** Checks if authorization is required.
          IF LED(68)<1,GEN> = '' THEN
             IF AUTH.CHK THEN
                * If control record is turned on, require entry. If control
                * record is turned off, require entry if there are
                * authorized personnel in Customer Credit Maint.
                VAL.CONT = OE.VAL.CUS.CONTACT
                IF VAL.CONT OR ( NOT(VAL.CONT) AND CUSS(29) ) THEN
                   ERR.MESS 40,5,BELL:'Ordered By is Required'
                   RETURN TO IN.OBY
                END
             END
          END
          RETURN
*-------------------------------------------------------------------------*
CHANGE.ADDR.ALLOWED: *** Determine if this customer allows the change
          *** of the address field, if not then look to the auth key
          *** SOE.ALLOW.ADDR.CHANGE
          IF CUSS(7)<1,11> = YES AND ADDR.CHANGE.ALLOWED = NO THEN
             * Customer is set to not allow - now check auth key.
             KEY.REQUIRED   = 'SOE.ALLOW.ADDR.CHANGE'
             CHECK.KEY KEY.REQUIRED,ADDR.CHANGE.ALLOWED
             IF ADDR.CHANGE.ALLOWED = NO THEN
                PROMPT.COMMENT = 'Change ship to address'
                OE.GET.AUTH OID,PROMPT.COMMENT,KEY.REQUIRED,ADDR.CHANGE.ALLOWED
             END
          END ELSE
             ADDR.CHANGE.ALLOWED = YES
          END
          RETURN
*-------------------------------------------------------------------------*
CHK.GEO:  IF NOT(USE.STAX) THEN RETURN

          IF LED(79)<1,GEN,1>='' THEN
             ERR.MESS 40,14,BELL:'Geocode is Required'
             RETURN TO IN.TAX.JUR
          END

          *** If Geocode has been changed then log it.
          IF OLED(79)<1,GEN,1>#LED(79)<1,GEN,1> THEN
             CMNT  = 'Changed Geocode from '
             CMNT := OLED(79)<1,GEN,1>:' to ':LED(79)<1,GEN,1>
             OE.ADD.COMMENT OID,GEN,CMNT
          END

          RETURN
*-------------------------------------------------------------------------*
CHK.FREIGHT.IN:
CUS.FREIGHT.IN = CUSS(39)<1,2>
SHOW.FI.ERROR=NO
SVIA = LED(70)<1,GEN>
SVIA.FGT=TRANS('SHIP.VIAS',SVIA,50,'X')
PRT.DT=TRANS('LEDGER.LOG',OID<1,GEN>,39,'X')
IF FI.OVD = '' AND CUS.FREIGHT.IN=2 AND SVIA.FGT#2 AND PRT.DT='' THEN SHOW.FI.ERROR=YES
IF SHOW.FI.ERROR THEN
ERR.MESS 21,11,BELL:'Freight In field must be filled in!'
RETURN TO IN.FI
          END

          RETURN
*-------------------------------------------------------------------------*
CHK.FREIGHT.OUT:
SHOW.FO.ERROR=NO
CUS.FREIGHT.OUT = CUSS(39)<1,1>
IF FO.OVD = '' AND CUS.FREIGHT.OUT=2 AND SVIA.FGT=1 AND PRT.DT='' THEN SHOW.FO.ERROR=YES
IF SHOW.FO.ERROR THEN
ERR.MESS 21,11,BELL:'Freight Out field must be filled in!'
RETURN TO IN.FO
          END

          RETURN
*-------------------------------------------------------------------------*
INTSHIP:  *
          OE.WEB.SHIP OID,GEN

          RETURN
*-------------------------------------------------------------------------*
FILEIT:   IF F12 THEN GOSUB DISPLAY

          IF (NOT(VIEW.ONLY) OR (VIEW.ONLY = 2)) THEN
             GOSUB CHK.PO
             GOSUB CHK.FREIGHT.IN
             GOSUB CHK.FREIGHT.OUT
             GOSUB CHK.REL
             GOSUB CHK.AUTH
          END

          IF NOT(VIEW.ONLY) THEN
             GOSUB CHK.GEO
          END

          IF F12 THEN
             IF (VIEW.ONLY = 2) THEN
                MAT LED = MAT OLED
                GOTO FINISH
             END ELSE
                QUIT = NO; F12 = NO
                PRINT BELL:; GOTO EDIT
             END
          END ELSE
             BEGIN CASE

             * VIEW.ONLY = 2 means we are in a Closed G/L Period but a
             * special update is allowed
             CASE (VIEW.ONLY = 2)

                * Attempt to update the order
                OE.HEADER.UPD.VIEW.ONLY OID,GEN,2,VIEW.ONLY,ERR.MSG

                * Display any errors encountered
                IF (ERR.MSG # "") THEN
IN$$25:            INP.PROMPT ,ERR.MSG,,0
                END
                GOTO FINISH

             * Branch number OR Sales Source changed, update all items
             * on all GENs
             CASE OLED(2)<1,GEN,1>#LED(2)<1,GEN,1> OR LED(3)<1,GEN>#OLED(3)<1,GEN>
                REPRICE = (LED(2)<1,GEN,1>#OLED(2)<1,GEN,1>)
                OLD.BR  = OLED(2)<1,GEN,1>
                OE.UPD.ALL.LDIDS OID,GEN,QSIGN,LOG.MV
                IF REPRICE THEN
                   BR.CMT  = USER.ID:' Changed Price Branch from : ':OLD.BR
                   OE.ADD.COMMENT OID,GEN,BR.CMT
                   *** To maintain backward compatibility, this control
                   *** record uses a double negative: Y means do not
                   *** reprice, N means reprice (or no, don't not reprice),
                   *** P means prompt
                   READ NO.RPC FROM CTRLFILE,'NO.REPRICE.HDR.BR.CHG' ELSE
                      NO.RPC = 'N'
                   END
                   IF NO.RPC = 'P' THEN
                      REP.OK = ''
                      REP.PROMPT = 'Reprice All Items (Y/N) :'
IN$$23:               INP.PROMPT REP.OK,REP.PROMPT,'YN',1
                      IF REP.OK THEN
                         NO.RPC = 'N'         ; * Reprice
                      END ELSE
                         NO.RPC = 'Y'         ; * Do not reprice
                      END
                   END
                   IF NO.RPC # 'Y' THEN
                      GET.CUS LED(2)<1,GEN,1>,LED(1)<1,GEN>,LED(5)<1,GEN>,QSIGN
                      LED(37)<1,GEN,1> = CUSS(13)
                      OE.REPRICE.ALL OID,GEN,QSIGN,LOG.MV
                   END ELSE
                      OE.REPRICE.ALL.COMM OID,GEN,QSIGN,LOG.MV
                      OE.REPRICE.ALL.COGS OID,GEN,QSIGN,LOG.MV
                   END
                END
             CASE OTHERWISE

*** Build XGEN.MV, a multi-valued list of gens that need to be updated.
                IF UPD.GEN.MV THEN
                   XGEN.MV = UPD.GEN.MV
                   LOCATE GEN IN UPD.GEN.MV<1> SETTING TRASH ELSE
                      XGEN.MV<1,-1> = GEN
                   END
                END ELSE
                   XGEN.MV = GEN
                END
                UPDATE.LEDGER OID,XGEN.MV
             END CASE
*            READV CUSS23 FROM TERMSFILE,LED(29)<1,GEN>,28 ELSE CUSS23=''
             TMP = LED(23)<1,GEN>
             IF TMP+0 = 0 THEN TMP = LED(9)<1,GEN>
             TERMS.VALUE CUSS23,LED(29)<1,GEN>,28,TMP,ERRS
             IF CUSS23 THEN CUSS(23) = CUSS23

             *** If they have chosen to prompt for copy then
             *** we need to display the list of things that have
             *** changed and allow them to choose which ones they
             *** want to change
             GEN.CT = DCOUNT(LED(9),VM)
             IF COPY.OPT = 'Prompt' AND GEN.CT > 1 AND ATB.NUM THEN

                * check if there is any open gen
                HAS.OPEN.GEN = NO
                GEN.CT = DCOUNT(LED(9),VM)
                FOR GN = 1 TO GEN.CT
                   IF GN#GEN AND LED(8)<1,GN>='' AND LED(6)<1,GN>#'Y' AND LED(6)<1,GN>#'$' THEN
                      HAS.OPEN.GEN = YES
                      EXIT
                   END
                NEXT GN

                * only show CopyAllGen if there is any open gen.
                IF HAS.OPEN.GEN THEN
                   MATBUILD LED.REC FROM LED
                   COPY.CHANGES = ''
                   OE.HEADER.COPY.CHANGES ATB.NUM,ATB.DESCS,LED.REC,GEN,COPY.CHANGES
                   ATB.CNT = DCOUNT(ATB.NUM,AM)
                   FOR ATTB = 1 TO ATB.CNT
                     IF COPY.CHANGES<ATTB> THEN
                        ATB = ATB.NUM<ATTB>
                        ATB.DESC = ATB.DESCS<ATTB>
                        GOSUB COPY.ALL
                     END
                   NEXT ATTB
                END
             END
             GEN.MV2 = GEN
             UPDATE.LEDGER OID,GEN.MV2
          END
*-------------------------------------------------------------------------*
FINISH:   WINDOW.CLOSE
          OE.TRIGGERS 2,OID,GEN,NEW.ORDER,,VIEW.ONLY
          RETURN
*-------------------------------------------------------------------------*
SET.CONTACT: * Get Contact info if OE.VAL.CUS.CONTACT control record set

          CREC<17>      = OCONV(CREC<17>,'MCU')
          PHONE.CT      = DCOUNT(CREC<17>,VM)
          VALID.PHONES  = ''
          IF CREC<14> THEN
             VALID.PHONES  = CREC<14>
          END
          IF CUSS(17)<1,1> THEN
             VALID.PHONES  = CUSS(17)<1,1>:VM:VALID.PHONES
          END
          VALID.PHONES = TRIM(VALID.PHONES,VM,'T')
          PHONE.LIST    = ''


          LOCATE 'WORK' IN CREC<17> SETTING POS THEN
             TPHONE = CREC<14,POS>
          END ELSE
             TPHONE = CREC<14,1>
          END
          CONVERT SVM TO '-' IN TPHONE
          IF TPHONE[1,1] = '-' THEN TPHONE[1,1] = ''

          IF CONTACT = '' THEN
             CONTACT.DISP = ''
             TPHONE       = ''
          END ELSE
             CONTACT.DISP  = TRIM(CREC<3>):', ':TRIM(CREC<1>):' '
             CONTACT.DISP := TRIM(CREC<2>)
          END
          PRINT @(56,8):CONTACT.DISP[1,23] "L#23"

          IF COPY.CONTACT THEN
             IF TPHONE THEN
                PHN = TRIM(TPHONE)
                PRINT @(56,9):PHN[1,20] "L#20"
                LED(71)<1,GEN> = PHN
             END
             LED(68)<1,GEN> = OBY
             ATB.DESC = 'Ordered By'
             ATB = 68; GOSUB CHK.COPY.MODE
             ATB.DESC = 'Phone Number'
             ATB = 71; GOSUB CHK.COPY.MODE
             CHANGED = NO
          END
          OBY = CONTACT
          RETURN
*-------------------------------------------------------------------------*
ZIP4:     ZIP = LED(75)<1,GEN>
          ADDR1 = LED(78)<1,GEN,1>
          ADDR2 = LED(78)<1,GEN,2>
          IF NOT(CITY) OR NOT(ST) THEN
             CITY = LED(78)<1,GEN,4>
             ST   = LED(78)<1,GEN,5>
          END
          VERIFY.ZIP4 ADDR1,ADDR2,CITY,ST,ZIP
          LED(78)<1,GEN,1> = ADDR1
          LED(78)<1,GEN,2> = ADDR2
          LED(75)<1,GEN>   = ZIP
          GN = GEN
          GOSUB UPD.ZIP
          ATB = 78 ; ATB.DESC = 'Address'
          GOSUB CHK.COPY.MODE
          GOSUB DISPLAY
          REDISP = YES
          RETURN
*-------------------------------------------------------------------------*
FIND.ZIP4:** Tries to find an exact match
          IF NOT(USE.ZIP4$) THEN RETURN
          IF NOT(LED(75)<1,GEN> AND LED(78)<1,GEN>) THEN RETURN
          SRCH.ID = LED(78)<1,GEN,1>:VM:LED(78)<1,GEN,2>

          S.CITY  = LED(78)<1,GEN,4>
          IF NOT(S.CITY) THEN              ;* Rel 6 backwards compatible
             CITY = TRIM(LED(78)<1,GEN,3>)
             CONVERT ',' TO '' IN CITY
             CITY = TRIM(CITY[1,LEN(CITY)-2])
          END
          SV.CITY = S.CITY

          S.ST    = LED(78)<1,GEN,5>
          IF NOT(S.ST) THEN                ;* Rel 6 backwards compatible
             ST = TRIM(LED(78)<1,GEN,3>)
             ST = ST[LEN(ST)-1,2]
             ZIP = LED(75)<1,GEN>
          END
          SV.ST   = S.ST

          S.ZIP   = LED(75)<1,GEN>
          ZIP.CODE.GET SRCH.ID,S.CITY,S.ST,S.ZIP
          IF FIELD(S.ZIP,'-',1) # FIELD(LED(75)<1,GEN>,'-',1) THEN RETURN
          IF TRIM(OCONV(S.CITY,'MCU')) # OCONV(SV.CITY,'MCU') THEN RETURN
          IF S.ST # SV.ST THEN RETURN
          LED(75)<1,GEN> = S.ZIP
          ZIP = S.ZIP
          GN  = GEN
          GOSUB UPD.ZIP
          ATB = 78 ; ATB.DESC = 'Address'
          GOSUB CHK.COPY.MODE
          GOSUB DISPLAY
          REDISP = YES
          RETURN
*-------------------------------------------------------------------------*
SET.DATA:
          OID.DATA$ = ''
          OID.DATA$<1> = OID
          OID.DATA$<2> = GEN
          OID.DATA$<4> = LED(5)<1,GEN>

          RETURN
*-------------------------------------------------------------------------*
PRT.INV.DT:
          *** Display the date the invoice printed when DISP.INV.DT.IN.SOE
          *** is set
          READ DISP.INV.DT FROM CTRLFILE,'DISP.INV.DATE.IN.SOE' ELSE DISP.INV.DT = NO
          IF DISP.INV.DT THEN
             READV PRT.STATS FROM LEDLFILE,OID,1 ELSE PRT.STATS = ''
             READV PRT.DTS   FROM LEDLFILE,OID,39 ELSE PRT.DTS  = ''
             PRT.FLAG.FOUND = YES
             LOCATE 'I' IN PRT.STATS<1,GEN> SETTING POS ELSE
                LOCATE 'E810' IN PRT.STATS<1,GEN> SETTING POS ELSE
                   LOCATE 'E857' IN PRT.STATS<1,GEN> SETTING POS ELSE
                      PRT.FLAG.FOUND = NO
                   END
                END
             END
             IF PRT.FLAG.FOUND THEN
                PRT.DT = PRT.DTS<1,GEN,POS>
                MSG = 'Invoice Print Date : ':OCONV(PRT.DT,'D4/')
                MESS 20,4,MSG
             END
          END

          RETURN
*-------------------------------------------------------------------------*
LOG.ABC:
          ABC.LOG.AUTO ACD

          RETURN
*-------------------------------------------------------------------------*
FREIGHT.SETUP:
          USR.BR=TRANS('INITIALS',USER.ID,7,'X')
          PRT.DT=TRANS('LEDGER.LOG',OID<1,GEN>,39,'X')
          IF PRT.DT#'' THEN RETURN

          FIR.OVD= LED(69)<1,GEN,4>
          IF FIR.OVD#1 THEN
          IF SVIA.FGT=2 THEN
          LED(69)<1,GEN,2>=0
          LED(69)<1,GEN,1>=0
          END
          END

          FOR.OVD= LED(69)<1,GEN,3>
          IF FOR.OVD#1 THEN
          IF SVIA.FGT#1 THEN
          LED(69)<1,GEN,1>=0
          END
          END
          RETURN
*-------------------------------------------------------------------------*
*** Copy internal notes to PO side if a Direct and control file flagged
COPY.NOTES: *
          LOCATE LED(33)<1,GEN> IN LED(12)<1> SETTING DGEN THEN
             LED(80)<1,DGEN> = B
          END

          RETURN
*-------------------------------------------------------------------------*
GET.PRC.CLASS: *** get the prc class for the prc br, check the folling:
               *** ST Branch Override Price Class
               *** ST Default Price Class

          PRC.CLASS = ""
          GET.CUS.BR.VAL BR,ST.CN,13,PRC.CLASS
          IF PRC.CLASS = "" THEN PRC.CLASS = CUSS(13)
          LED(37)<1,GEN,1> = PRC.CLASS

          RETURN
*-------------------------------------------------------------------------*
!SMITJR~09/19/11~23:58
