          SUBROUTINE (PASSER)
** Version# 115.0004[2] - 06/10/2016 - 04:33pm - TSMITH - eclipse
*** V115.0004 Change - Custom Coding . - 06/10/2016 - TSMITH - eclipse
*** V115.0003 Change - Custom Coding . - 04/01/2016 - TSMITH - eclipse
*** V115.0002 Change - Custom Coding . - 12/23/2014 - TSMITH - eclipse
*** V115.0001 Change - Custom Coding . - 02/17/2014 - TSMITH - eclipse

*** SUBROUTINE - SOE.MANIFEST.QUEUE
*-------------------------------------------------------------------------*
*** This is the main subroutine for the shipping manifest queue.  New
*** shipping manifest can be created, existing manifests can be changed
*** shipping manifest can be created, existing manifests can be changed (ie
*-------------------------------------------------------------------------*
*** PASSER<1,1> - OMNF.ID - Manifest ID
*** PASSER<1,2> - VIEW.ONLY flag, 1 =  View.Only status
*** PASSER<1,3> - VIEW - View hot key, displays differen screen view
***               VIEW =1 Shipping Packages
***               VIEW =2 Expected Time
***               VIEW =3 Actual Time
***               VIEW =5 Dollars, Load Factor and Weight
***               VIEW =6 Expected Time/Actual Time
***               VIEW =7 Stage Locations and Hold Picking
***               VIEW =8 Stage Locations and Shipment ID
*-------------------------------------------------------------------------*
*** COMMON VARIABLES
***       DRPT$ = 'Shipping Manifest'
***       OID.DATA$ - Used to pass ID to imaging for attachments
*-------------------------------------------------------------------------*

          UT.OPEN.FILE 'MANIFESTS',MNFSTFILE,ERR.MSG
          IF ERR.MSG THEN RETURN
          UT.OPEN.FILE 'OPEN.TOTES',OTOTEFILE,ERR.MSG
          IF ERR.MSG THEN RETURN
          UT.OPEN.FILE 'CARTON.DETAIL',CTN.FILE,ERR.MSG
          IF ERR.MSG THEN RETURN

          SCREEN

          THIS.ROUTINE = "SOE.MANIFEST.QUEUE"
          CONVERT ',' TO VM IN PASSER
          OMNF.ID   = PASSER<1,1>
          VIEW.ONLY = PASSER<1,2>
          VIEW      = PASSER<1,3>
          IF VIEW = '' THEN VIEW = 1

          IF OMNF.ID # '' THEN
             READV XXX FROM MNFSTFILE,OMNF.ID,1 ELSE
                PRINT @(13,1):OMNF.ID   "L#8"
                MESS 10,5,'Manifest is not in file. Press <Enter>'
                GOTO FINISH
             END
          END

          W.FMT  = 'MR':PRD.WGHT$

          VSCROLL.DEFINE 1,1,5,78,14
          VSCROLL.SET 1

          CHECK.KEY "SOE.MANIFEST.EDIT",EDIT.OK,EDIT.LVL
          IF NOT(EDIT.OK) THEN VIEW.ONLY = YES

          *** Save view only and orignal manifest id for restart
          SV.VIEW.ONLY = VIEW.ONLY
          SV.OMNF.ID   = OMNF.ID
          STG.LOC = ''
          READV PKG.TYPS FROM CTRLFILE,'PACKAGE.TYPES',1 ELSE PKG.TYPS = ''

          * When control MNFST.LOCKED is set then the user is not allowed
          * to edit a locked manifest.
          READV NO.EDIT FROM CTRLFILE,'MNFST.LOCKED',1 ELSE NO.EDIT = ''

          SHIPMENT.MAINT.ENABLED = NO

          * MNFST<1>  = ship via
          * MNFST<2>  = ship date
          * MNFST<3>  = branch
          * MNFST<4>  = start time
          * MNFST<5>  = first delivery time
          * MNFST<6>  = delivery interval minutes
          * MNFST<7>  = closed flag
          * MNFST<8>  = dirver userid
          * MNFST<10> = stop info/override for stop
          * MNFST<11> = delivery time for stop #
          * MNFST<14> = time block list in order
          * MNFST<15> = value is stop # and subvalue is list of tickets on
          *             manifest for that stop
          * MNFST<16> = comments for ticket position matched with <5>
          * MNFST<18> = Flag to indicate time was manually changed

RESTART:  CLEAR.SCREEN
          MANIFEST.ID   = ''
          MNFST         = ''
          BR            = ''
          VIA           = ''
          SHIP.DT       = ''
          LINE          = 1
          NEW.MNFST     = NO
          SEP.CHR       = ''
          HDG.SET       = NO
          VIEW.ONLY     = SV.VIEW.ONLY
          OMNF.ID       = SV.OMNF.ID

START:    *
          MENU.CLEAR
          PRINT @(2,0):'อออออออออ' ;* Over write View Only display
          PRINT @(55,0):'อออออออออออออ' ;* Over write picks holding display
          PRINT @(73,0):'ออออออ'   ;* Over write Locked display
          IF OMNF.ID # '' THEN
             MANIFEST.ID = OMNF.ID
             PRINT @(13,1):TRIM(MANIFEST.ID)
          END

          GOSUB SETUP.MANIFEST
          IF F12 THEN GOTO FILEIT
          IF MANIFEST.ID = '' THEN GOTO FINISH
          IF MNFST<7> THEN
             WINDOW 10,10,60,1,3
             PRINT @(1,0):BELL:'This Manifest is Closed. Press <Enter>.':
IN$$2:       INP A,,,0,H_"IH#37"
             WINDOW.CLOSE
             VIEW.ONLY = YES
             RELEASE MNFSTFILE,MANIFEST.ID
             GOSUB CALC.TOT
          END

          IF NOT(VIEW.ONLY) THEN
             * Check to see if the user is already editting the manifest
             LOCK.MSG = ''
             LOCATE MANIFEST.ID IN LOCKED.LEDS SETTING POS THEN
                LOCK.MSG = 'You are already editing ':MANIFEST.ID:'.'
                IF NOT(JAVA.PROC$) THEN
                   LOCK.MSG := '  Press <Enter> to view.'
                END
             END

             IF LOCK.MSG THEN
                MESS 5,10,BELL:LOCK.MSG
                VIEW.ONLY = YES
             END ELSE
                LOCKED.LEDS<-1> = MANIFEST.ID
             END
          END

          IF VIEW.ONLY THEN
             PRINT @(2,0):BLINK$:'View Only':NORM$
             GOTO SKIP.HEADING
          END
          GOSUB CALC.TOT          ;* display totals for default screen
          IF MNFST<15> # '' THEN GOTO SKIP.HEADING
*-------------------------------------------------------------------------*
INDVR:    INP DRIVER,71,2,8,V_'INITIALS'
          IF F12 THEN GOTO FILEIT
          IF CHANGED THEN MNFST<8> = DRIVER
          IF QUIT THEN GOTO FILEIT
          ON MOVE+1 GOTO INDVR,INDVR,INDVR,INDVR
*-------------------------------------------------------------------------*
INSTTM:   INP STRT.TM,13,3,7,'MTH'
          IF F12 THEN GOTO FILEIT
          IF STRT.TM = '' THEN PRINT BELL:; GOTO INSTTM
          IF QUIT THEN GOTO FILEIT
          ON MOVE+1 GOTO INSTTM,INSTTM,INDVR,INFDTM,TIME.SET,INFDTM
*-------------------------------------------------------------------------*
INFDTM:   INP FDEL.TM,40,3,7,'MTH'
          IF F12 THEN GOTO FILEIT
          IF FDEL.TM='' OR FDEL.TM < STRT.TM THEN PRINT BELL:; GOTO INFDTM
          IF QUIT THEN GOTO FILEIT
          ON MOVE+1 GOTO INFDTM,INSTTM,INFDTM,ININTVL,TIME.SET,ININTVL
*-------------------------------------------------------------------------*
ININTVL:  INP INTVL,71,3,3,'R'
          IF F12 THEN GOTO FILEIT
          IF INTVL+0 = 0 THEN
             IF INTVL # MNFST<6> THEN
                VAR = ''
IN$$11:         INP.PROMPT VAR,BELL:'Warning - an interval of 0 will mean no automatic recalculating of':AM:'delivery times if stops/times changed. OK? Y/N : ','YN',1
                IF NOT(VAR) THEN GOTO ININTVL
             END
          END
          IF QUIT THEN GOTO FILEIT
          ON MOVE+1 GOTO ININTVL,INFDTM,ININTVL,ININTVL
*-------------------------------------------------------------------------*
TIME.SET: *
          IF STRT.TM#MNFST<4> OR FDEL.TM#MNFST<5> OR INTVL#MNFST<6> THEN
             GOSUB RECALC.TIME
             GOSUB DISP.LNS
          END
*-------------------------------------------------------------------------*
SKIP.HEADING:*
          GOSUB LOAD.HOTKEYS
*-------------------------------------------------------------------------*
MOVENEXT: IF QUIT THEN GOTO FILEIT
          REDISPLAY.ALL = YES
          NEWOK = NO
          PARSEMOVE COL,LINE,COLS,MAX.LNS,15,YES,NEWOK,BORDERMOVE
          IF BORDERMOVE=2 AND NOT(VIEW.ONLY) THEN GOTO INSTTM
          IF MOVE=2 THEN GOSUB GET.VALID.LINE.REV ELSE GOSUB GET.VALID.LINE
          VSCROLL.MOVE LINE
          IF VIEW.ONLY THEN COL = 2

          MSG = ''
          *IF LN.ERRS<LINE,1> THEN
             *MSG<1> = 'Branch, Ship-date, or Ship-via no longer matches Manifest'
          *END
         * IF LN.ERRS<LINE,2> THEN
         *    MSG<2> = 'Open ticket now invoiced and must be changed.'
         * END
         * IF LN.ERRS<LINE,3> THEN
         *    MSG<3> = 'Ticket in a closed accounting period. '
         *    MSG<4> = 'Branch, Ship-date, or Ship-via will not be updated.'
         * END

          MSG = TRIM(MSG,AM)
          IF MSG # '' THEN
             IF E.MESS.<WINDOW.LEVEL> THEN
                WINDOW 15,10,50,1,3
                PRINT @(1,0):BELL:'Press <Enter> to display next message : ':
IN$$3:          INP B,,,0,H_"IH#38"
                WINDOW.CLOSE
             END
             MESS 10,2,MSG
          END


          IF FIELD(LN.IDS<LINE>,'~',1) = 'NEW' OR VIEW.ONLY THEN COL = 2
          ON COL GOTO INSTOP,INTKT1,INDELTM,INCOL4,INCOL5,INCOL6,INCOL7
*-------------------------------------------------------------------------*
INSTOP:   INPV SEQ,0,LINE,3,'R'
          IF F12 THEN GOTO FILEIT
          IF CHANGED THEN
             STP.CT  = DCOUNT(MNFST<10>,VM)
             OLD.STP = FIELD(LN.IDS<LINE>,'~',1)
             IF OLD.STP = SEQ THEN
                VPRINT 0,LINE,OLD.STP   "R#3"
                GOTO INSTOP
             END
             IF SEQ < 1 OR SEQ > STP.CT THEN
                VPRINT 0,LINE,OLD.STP   "R#3"
                MESS 10,3,BELL:'Stop ':SEQ:' does not exist. Cannot move.'
                GOTO INSTOP
             END
             ANS = ''
IN$$4:       INP.PROMPT ANS,'Are you SURE you want to add this ticket to stop ':SEQ:' (Y/N) : ','YN'
             IF NOT(ANS) THEN
                VPRINT 0,LINE,OLD.STP    "R#3"
                GOTO INSTOP
             END
             * move ticket to another stop
             TK = FIELD(LN.IDS<LINE>,'~',2)
             TICKET = MNFST<15,STP,TK>
             LOCATE TICKET IN MNFST<15,SEQ> SETTING POS ELSE
                MNFST = INSERT(MNFST,15,SEQ,POS;TICKET)
                MNFST = INSERT(MNFST,16,SEQ,POS;MNFST<16,STP,TK>)
             END
             REFRESHED = NO
             MOVE.TKT  = YES
             GOSUB DEL.LN
             MOVE.TKT  = NO
             IF NOT(REFRESHED) THEN GOSUB DISP.LNS
          END

          GOTO MOVENEXT
*-------------------------------------------------------------------------*
INTKT1:   *** Input Ticket
          IF NO.EDIT AND MNFST<17> THEN
             IF FIELD(LN.IDS<LINE>,'~',1)='NEW' THEN
                MSG = 'Manifest is Locked From Changes. Do Not Add Ticket.'
                MESS 10,2,BELL:MSG,NO
             END
IN$$1:       INPV X,4,LINE,0
             GOTO MOVENEXT
          END ELSE
INTKT:       INPV TICKET.ID,4,LINE,15,'MCU'
          END
          IF F12 THEN GOTO FILEIT
          IF VIEW.ONLY THEN GOTO MOVENEXT
          IF NOT(CHANGED) THEN GOTO MOVENEXT
          OLD.STP   = FIELD(LN.IDS<LINE>,'~',1)
          OLD.TK    = FIELD(LN.IDS<LINE>,'~',2)

          IF OLD.STP # 'NEW' THEN
             VPRINT 4,LINE,MNFST<15,OLD.STP,OLD.TK>    "L#15"
          END ELSE
             VPRINT 4,LINE,''                          "L#15"
          END

          OID      = FIELD(TICKET.ID,'.',1)
          ERR.MESS = ''
          IF LEN(OID) # OID.LGTH$ AND LEN(OID) # 8 THEN
             ERR.MESS = ' is in an invalid format'
             GOTO ERRTKT.CHK
          END
          READV GENS FROM LEDFILE,OID,8 ELSE
             ERR.MESS = ' is an invalid order'
             GOTO ERRTKT.CHK
          END
          INVN  = FIELD(TICKET.ID,'.',2)+0
          IF NOT(NUM(INVN)) THEN INVN = 0
          IF INVN > 0 THEN LOCATE INVN IN GENS<1> SETTING GEN ELSE INVN = 0
          LED.READ.OK = NO
          IF INVN > 0 THEN
             INVN = INVN "R%3"
          END ELSE
             MATREAD LED FROM LEDFILE,OID ELSE MAT LED = ''
             * Flag we have read the LED
             LED.READ.OK = YES
             OE.SELECT.SHIPDATE OID,GEN
             IF F12 THEN GOTO INTKT
             IF NOT(GEN) THEN GOTO INTKT
             INVN = LED(8)<1,GEN>+0
             IF INVN > 0 THEN
                INVN = INVN 'R%3'
             END ELSE
                INVN = LED(12)<1,GEN> 'R%4'
             END
          END
ERRTKT.CHK:*
          IF ERR.MESS THEN
             MESS 10,2,BELL:TICKET.ID:ERR.MESS
             GOTO INTKT
          END
          IF NOT(LED.READ.OK) THEN
             * Need to make sure LED is read so we can check gl.date
             * and test for change in ship date of ship via
             MATREAD LED FROM LEDFILE,OID ELSE MAT LED = ''
          END

          IF LED(70)<1,GEN> NE MNFST<1> OR LED(9)<1,GEN> NE MNFST<2> THEN
             * Need to check gl closed period and warn user of no updates.
             * 3rd argument is used for payments which are not allowed, so
             * 3rd arg not needed.
             GL.CLOSE.DT.GET OID,GL.CLOSE.DT
             IF LED(23)<1,GEN> AND LED(23)<1,GEN> < GL.CLOSE.DT THEN
                WARN.MESS  = ' is in a closed period.  Updates to'
                WARN.MESS := ' Branch, Ship Via, Dollar amounts, etc. on'
                WARN.MESS := ' Ticket will not be made.'
                MESS 10,2,BELL:TICKET.ID:WARN.MESS
             END
          END

          FND.TICKET.ID = OID:'.':INVN
          TICKET.ID     = FND.TICKET.ID
FINDTKT.LP: *
          DATA          = MNFST<15>
          * see if search is requested
          FINDSTR FND.TICKET.ID IN DATA SETTING XXX,STP,TK THEN
             LOCATE STP:'~':TK IN LN.IDS SETTING POS ELSE POS = LINE
             LINE = POS
             VSCROLL.MOVE LINE
             IF VIEW = 1 THEN
                IF PKG.TYPS = '' THEN
                   GOTO INTKT1
                END ELSE
                   COL = 4
                   GOTO INCOL4
                END
             END ELSE
                GOTO INTKT1
             END
          END

          IF VIEW.ONLY THEN
             PRINT BELL:
             GOTO MOVENEXT
          END

          IF TICKET.ID # '' THEN
             * try to add the ticket
             GOSUB SELCT
             QUIT      = 0
             LASTKEY   = 0
             MOVE      = 0
             TICKET.ID = ''
             GOTO FINDTKT.LP
          END
          GOTO MOVENEXT
*-------------------------------------------------------------------------*
INDELTM:  INPV DEL.TM,51,LINE,7,'MTH'
          IF F12 THEN GOTO FILEIT
          IF CHANGED THEN
             STP    = FIELD(LN.IDS<LINE>,'~',1)
             TK     = FIELD(LN.IDS<LINE>,'~',2)
             TKT.CT = DCOUNT(MNFST<15,STP>,SVM)
             OLD.DEL.TM = MNFST<11,STP>

             * Cannot move delivery time on an already loaded stop
             MSTATUS = MNFST<39,STP>
             IF MSTATUS='LOADED' OR MSTATUS='DELIVERED' THEN
                STOP.MSG     = 'Stop is ':MSTATUS:' and Cannot Be Moved.'
                STOP.MSG<-1> = 'Press <Enter>'
IN$$13:         INP.PROMPT ,BELL:STOP.MSG,,0
                VPRINT 51,LINE,OCONV(MNFST<11,STP>,'MTH') "L#7"
                GOTO INDELTM
             END

             ANS = 'E'
             IF TKT.CT > 1 THEN
IN$$5:          INP.PROMPT ANS,'Do you want to move the ENTIRE stop/Ticket/Nothing (E/T/N) : ','MCU',1,'D:E':VM:'T':VM:'N'
                IF ANS = 'N' THEN
                   VPRINT 51,LINE,OCONV(MNFST<11,STP>,'MTH') "L#7"
                   GOTO INDELTM
                END
                IF ANS = 'T' THEN
                   IF MNFST<47> AND NOT(MNFST<37,STP>) THEN
IN$$16:               INP.PROMPT ,BELL:'Stop is released. Must move stop.':AM:'Press <Enter>',,0
                      GOTO IN$$5
                   END
                END
             END
             LOCATE DEL.TM IN MNFST<11> BY 'AR' SETTING NEW.STP ELSE NULL
             IF MNFST<47> AND NEW.STP > 1 THEN
                MSTATUS = MNFST<39,NEW.STP-1>
                IF MSTATUS='LOADED' OR MSTATUS='DELIVERED' THEN
IN$$17:            INP.PROMPT ,BELL:'Prior Stop is ':MSTATUS:'. Cannot move to new Stop.':AM:'Press <Enter>',,0
                   GOTO IN$$5
                END
             END
             IF ANS = 'E' THEN
                SAVE.DELV = MNFST<12,STP>
                SAVE.TKTS = MNFST<15,STP>
                SAVE.CMTS = MNFST<16,STP>
                SAVE.STOP = MNFST<10,STP>
                SAVE.LOCS = MNFST<36,STP>
                SAVE.HOLD = MNFST<37,STP>
                SAVE.TOTE = MNFST<38,STP>
                SAVE.STAT = MNFST<39,STP>
                SAVE.SPMT = MNFST<41,STP>
                SAVE.PKGS = MNFST<42,STP>
                SAVE.ITMS = MNFST<43,STP>
                SAVE.QTYS = MNFST<44,STP>
                SAVE.STID = MNFST<45,STP>
                MNFST = DELETE(MNFST,12,STP)
                MNFST = DELETE(MNFST,15,STP)
                MNFST = DELETE(MNFST,16,STP)
                MNFST = DELETE(MNFST,10,STP)
                MNFST = DELETE(MNFST,11,STP)
                MNFST = DELETE(MNFST,18,STP)
                MNFST = DELETE(MNFST,36,STP)
                MNFST = DELETE(MNFST,37,STP)
                MNFST = DELETE(MNFST,38,STP)
                MNFST = DELETE(MNFST,39,STP)
                MNFST = DELETE(MNFST,41,STP)
                MNFST = DELETE(MNFST,42,STP)
                MNFST = DELETE(MNFST,43,STP)
                MNFST = DELETE(MNFST,44,STP)
                MNFST = DELETE(MNFST,45,STP)
             END ELSE
                SAVE.DELV = ''
                SAVE.TKTS = MNFST<15,STP,TK>
                SAVE.CMTS = MNFST<16,STP,TK>
                SAVE.STOP = ''
                SAVE.LOCS = MNFST<36,STP>
                SAVE.HOLD = MNFST<37,STP>
                SAVE.TOTE = ''
                SAVE.STAT = ''
                SAVE.SPMT = ''
                SAVE.PKGS = ''
                SAVE.ITMS = ''
                SAVE.QTYS = ''
                SAVE.STID = ''
                MNFST = DELETE(MNFST,15,STP,TK)
                MNFST = DELETE(MNFST,16,STP,TK)
             END
             LOCATE DEL.TM IN MNFST<11> BY 'AR' SETTING NEW.STP ELSE NULL
             MNFST = INSERT(MNFST,12,NEW.STP;SAVE.DELV)
             MNFST = INSERT(MNFST,15,NEW.STP;SAVE.TKTS)
             MNFST = INSERT(MNFST,16,NEW.STP;SAVE.CMTS)
             MNFST = INSERT(MNFST,10,NEW.STP;SAVE.STOP)
             MNFST = INSERT(MNFST,11,NEW.STP;DEL.TM)
             MNFST = INSERT(MNFST,18,NEW.STP;'')
             MNFST = INSERT(MNFST,36,NEW.STP;SAVE.LOCS)
             MNFST = INSERT(MNFST,37,NEW.STP;SAVE.HOLD)
             MNFST = INSERT(MNFST,38,NEW.STP;SAVE.TOTE)
             MNFST = INSERT(MNFST,39,NEW.STP;SAVE.STAT)
             MNFST = INSERT(MNFST,41,NEW.STP;SAVE.SPMT)
             MNFST = INSERT(MNFST,42,NEW.STP;SAVE.PKGS)
             MNFST = INSERT(MNFST,43,NEW.STP;SAVE.ITMS)
             MNFST = INSERT(MNFST,44,NEW.STP;SAVE.QTYS)
             MNFST = INSERT(MNFST,45,NEW.STP;SAVE.STID)
             MNFST<18> = 1; * Flag to indicate del times manually changed

             GOSUB RECALC.TIME
             GOSUB DISP.LNS
             LOCATE NEW.STP:'~1' IN LN.IDS SETTING LINE ELSE LINE = 1
             MOVE = 0; LASTKEY = 0
             IF MNFST<11,NEW.STP+1> = ICONV('12:59pm','MTH') THEN MOVE = 4
          END
          GOTO MOVENEXT
*-------------------------------------------------------------------------*
INCOL4:   *
          BEGIN CASE
          CASE VIEW = 1
INPKG1:   INPV PKG.QTY,59,LINE,4,'R'
          IF F12 THEN GOTO FILEIT
          IF CHANGED THEN
             PKG.COL = 1
             GOSUB POST.PKG
             IF ERR.MESS THEN
                VPRINT 59,LINE,'' "L#4"
                GOTO INPKG1
             END
          END

          CASE VIEW = 7

INLOCN:   INPV STG.LOC,59,LINE,15

          IF F12 THEN GOTO FILEIT
          IF CHANGED THEN
             PKG.COL = 5
             STP   = FIELD(LN.IDS<LINE>,'~',1)
             *GOSUB STAGING.LOCATION
          END




          CASE OTHERWISE
INACTTM:  INPV ACT.TM,60,LINE,7,'MTH'
          IF F12 THEN GOTO FILEIT
          IF CHANGED THEN
             STP   = FIELD(LN.IDS<LINE>,'~',1)
             TK    = FIELD(LN.IDS<LINE>,'~',2)
             TKT   = MNFST<15,STP,TK>
             OID   = FIELD(TKT,'.',1)
             INVN  = FIELD(TKT,'.',2)
             ERR.MESS = ''
             IF LEN(INVN) = 3 THEN
                READV GENS FROM LEDFILE,OID,8 ELSE GENS = ''
                LOCATE INVN+0 IN GENS<1> SETTING GEN ELSE
                   ERR.MESS = 'Error posting to ledger.log file'
                END
             END ELSE
                ERR.MESS = 'Cannot post actual delivery time to open order'
             END
             IF ERR.MESS THEN
                VPRINT 60,LINE,''  "L#7"
                ACT.TM = ''
                MESS 10,2,BELL:ERR.MESS
                GOTO INACTTM
             END

             READVU D.TIMES FROM LEDLFILE,OID,16 ELSE D.TIMES = ''
             D.TIMES<1,GEN,2> = ACT.TM
             WRITEV D.TIMES ON LEDLFILE,OID,16

             IF ACT.TM THEN
                VPRINT 69,LINE,(MNFST<11,STP>-ACT.TM)/60  "R0#5":' min'
             END ELSE
                VPRINT 69,LINE,''                         "L#9"
             END
          END
          END CASE

          GOTO MOVENEXT
*-------------------------------------------------------------------------*
INCOL5:   INPV PKG.QTY,64,LINE,4,'R'
          IF F12 THEN GOTO FILEIT
          IF CHANGED THEN
             PKG.COL = 2
             GOSUB POST.PKG
             IF ERR.MESS THEN
                VPRINT 64,LINE,'' "L#4"
                GOTO INCOL5
             END
          END

          GOTO MOVENEXT
*-------------------------------------------------------------------------*
INCOL6:   INPV PKG.QTY,69,LINE,4,'R'
          IF F12 THEN GOTO FILEIT
          IF CHANGED THEN
             PKG.COL = 3
             GOSUB POST.PKG
             IF ERR.MESS THEN
                VPRINT 69,LINE,'' "L#4"
                GOTO INCOL6
             END
          END

          GOTO MOVENEXT
*-------------------------------------------------------------------------*
INCOL7:   INPV PKG.QTY,74,LINE,4,'R'
          IF F12 THEN GOTO FILEIT
          IF CHANGED THEN
             PKG.COL = 4
             GOSUB POST.PKG
             IF ERR.MESS THEN
                VPRINT 74,LINE,'' "L#4"
                GOTO INCOL7
             END
          END

          GOTO MOVENEXT
*-------------------------------------------------------------------------*
LOAD.HOTKEYS: *
          MENU.CLEAR
          MENU.LOAD  1,21, 5,1,'P'
          MENU.LOAD  7,21, 4,1,'E'
          MENU.LOAD 12,21, 4,1,'V'
          IF NO.EDIT AND MNFST<17> THEN
             MENU.LOAD
          END ELSE
             MENU.LOAD 17,21, 9,1,'S'
          END
          MENU.LOAD 24,21,12,1,'B'
          MENU.LOAD 35,21, 6,1,'C'
          MENU.LOAD 42,21,13,1,'A'
          IF AUTOSCHED THEN
             PRINT @(52,21):'On '
          END ELSE
             PRINT @(52,21):'Off'
          END
          IF MNFST<7> THEN
             PRINT @(56,21):' Open'
             MENU.LOAD
             IF EDIT.LVL > 1 THEN
                MENU.LOAD 57,21,5,1,'O'
             END ELSE
                MENU.LOAD
             END
          END ELSE
             PRINT @(56,21):'CLose'
             MENU.LOAD 56,21,5,2,'L'
             MENU.LOAD
          END
          IF MNFST<17> THEN
             PRINT @(73,0):BLINK$:'Locked':NORM$
             PRINT @(62,21):'Unl'
          END ELSE
             PRINT @(73,0):'ออออออ' ;* Over write Locked display
             PRINT @(62,21):'  L'
          END
          MENU.LOAD 62,21,6,6,'K'
          IF MNFST<35> THEN
             PRINT @(55,0):BLINK$:'Picks Holding':NORM$
             PRINT @(70,21):BLINK$:'elPk':NORM$
             MENU.LOAD 69,21,1,1,'R'
          END ELSE
             PRINT @(55,0):'อออออออออออออ' ;* Over write picks holding disp
             PRINT @(70,21):'elPk'
             MENU.LOAD
          END
          MENU.LOAD ,,,,INSERT.KEY
          MENU.LOAD ,,,,DELETE.KEY
          MENU.LOAD 75,21,4,2,'T'

          COL = 1; LINE = 1; LASTKEY = 0; MOVE = 0; QUIT = 0; COLS = 7
          BEGIN CASE
          CASE VIEW = 2               ;COLS = 4
          CASE VIEW = 3               ;COLS = 5
          CASE VIEW = 4               ;COLS = 4
          CASE VIEW = 5               ;COLS = 3
          CASE VIEW = 6               ;COLS = 2
          CASE VIEW = 7               ;COLS = 4
          END CASE
          IF VIEW.ONLY THEN
             COLS = 1
             PRINT @(2,0):BLINK$:'View Only':NORM$
          END
          RETURN
*-------------------------------------------------------------------------*
GET.VALID.LINE: * make sure this is first display line for ticket forward
          FOR L = LINE TO MAX.LNS
          STP = FIELD(LN.IDS<L>,'~',1)
          IF STP # '' AND STP # 'MSC' THEN EXIT
          NEXT L

          IF L > MAX.LNS THEN
             IF LINE > 1 THEN GOSUB GET.VALID.LINE.REV
          END ELSE
             LINE = L
          END

          RETURN
*-------------------------------------------------------------------------*
GET.VALID.LINE.REV: *make sure this is first display line for ticket before
          IF LINE = 1 THEN GOSUB GET.VALID.LINE; RETURN
          FOR L = LINE TO 1 STEP -1
          STP = FIELD(LN.IDS<L>,'~',1)
          IF STP # '' AND STP # 'MSC' THEN EXIT
          NEXT L

          IF L < 1 THEN LINE = 1; GOSUB GET.VALID.LINE ELSE LINE = L

          RETURN
*-------------------------------------------------------------------------*
POST.PKG: STP   = FIELD(LN.IDS<LINE>,'~',1)
          TK    = FIELD(LN.IDS<LINE>,'~',2)
          TKT   = MNFST<15,STP,TK>
          OID   = FIELD(TKT,'.',1)
          INVN  = FIELD(TKT,'.',2)
          ERR.MESS = ''
          IF LEN(INVN) > 3 THEN
             MESS 10,2,BELL:'Cannot post package qtys to open orders.'
             ERR.MESS = YES
             RETURN
          END
          IF SUMMATION(MNFST<42,STP>) # 0 THEN
             MESS 10,2,BELL:'Cannot post package qtys to whole stop picks.'
             ERR.MESS = YES
             RETURN
          END
          READV GENS FROM LEDFILE,OID,8 ELSE GENS = ''
          LOCATE INVN+0 IN GENS<1> SETTING GEN THEN
             READVU QTYS FROM LEDLFILE,OID,18 ELSE QTYS = ''
             QTYS<1,GEN,PKG.COL> = PKG.QTY
             WRITEV QTYS ON LEDLFILE,OID,18
          END ELSE
             MESS 10,2,BELL:'Could not update ledger.log file'
             ERR.MESS = YES
          END

          GOSUB CALC.TOT          ;* update totals for 'shipping packages'

          RETURN
*-------------------------------------------------------------------------*
SETUP.MANIFEST: *
          SOE.MANIFEST.SETUP MNFST,MANIFEST.ID,NEW.MNFST,OMNF.ID,VIEW.ONLY
          IF F12 THEN RETURN
          IF MANIFEST.ID = '' THEN RETURN
          OLD.MNFST = MNFST

          VIA      = MNFST<1>
          SHIP.DT  = MNFST<2>
          BR       = MNFST<3>
          STRT.TM  = MNFST<4>
          FDEL.TM  = MNFST<5>
          INTVL    = MNFST<6>
          DRIVER   = MNFST<8>

          SOE.MANIFEST.AUTOSCHED AUTOSCHED,BR,VIA

          IF AUTOSCHED THEN
             PRINT @(52,21):'On '
          END ELSE
             PRINT @(52,21):'Off'
          END
          READ SHIPMENT.MAINT.ENABLED FROM CTRBFILE,'RF.RECV.856.ADV.SHIP~':BR ELSE
             SHIPMENT.MAINT.ENABLED = NO
          END

          READ RECALC.DEL.TIME FROM CTRLFILE,'RECALC.DEL.TIME' ELSE
             RECALC.DEL.TIME = 'Y'
          END

          REDISPLAY.ALL = YES
          GOSUB RECALC.TIME
          GOSUB DISP.LNS
          GOSUB DISP.IMG

          RETURN
*-------------------------------------------------------------------------*
DISP.LNS: *
          IF HDG.SET THEN NEW.VIEW = '' ELSE NEW.VIEW = VIEW

          SOE.MANIFEST.DISP.LNS LN.IDS,MAX.LNS,LN.ERRS,REDISPLAY.ALL:VM:LINE,MNFST,MANIFEST.ID,VIEW,NEW.VIEW
          IF VIEW = 5 THEN GOSUB CALC.TOT  ;* Display totals for Wght,load
          HDG.SET   = YES
          REFRESHED = YES
          REDISPLAY.ALL = YES

          RETURN
*-------------------------------------------------------------------------*
DISP.IMG:
          * Displays image indicator if images exist.
          CHECK.FOR.IMAGES MANIFEST.ID, 'MFST', IMAGE.FLAG
          IF IMAGE.FLAG THEN
             PRINT @(69,0):BLINK$:'*i*':NORM$
          END ELSE
             PRINT @(69,0):'อออ'
          END

          * Set the ID for image attachments
          OID.DATA$<13> = MANIFEST.ID

          RETURN
*-------------------------------------------------------------------------*
RECALC.TIME: * recalc delivery times based on start parameters, interval
          *    and around any blocks. Do not recheck stops.
          MNFST<4> = STRT.TM
          MNFST<5> = FDEL.TM
          MNFST<6> = INTVL
          IF INTVL = 0 THEN RETURN
          NXT.TM   = FDEL.TM
          BLK.CT   = DCOUNT(MNFST<14>,VM)
          BLK.FRM  = MNFST<14,1,1>
          BLK.TO   = MNFST<14,1,2>
          BLK.NO   = 1
          STP.CT = DCOUNT(MNFST<15>,VM)
          RECALC.OK = YES
          IF RECALC.DEL.TIME = 'N' AND MNFST<18> THEN
             RECALC.OK = NO
          END
          IF RECALC.OK THEN
             FOR STP = 1 TO STP.CT
                GOSUB CHK.BLK
                MNFST<11,STP> = NXT.TM
                NXT.TM += INTVL*60
             NEXT STP
          END

          RETURN
*-------------------------------------------------------------------------*
CHK.BLK:  * note - no provision for extra travel around block
          IF BLK.NO > BLK.CT OR NXT.TM < BLK.FRM THEN RETURN
          NXT.TM = BLK.TO + (NXT.TM - BLK.FRM)
          BLK.NO += 1
          BLK.FRM = MNFST<14,BLK.NO,1>
          BLK.TO  = MNFST<14,BLK.NO,2>
          GOTO CHK.BLK

          RETURN
*-------------------------------------------------------------------------*
CLR.LINE: *
          VPRINT 0,LINE,SEP.CHR         "L#3"
          VPRINT 4,LINE,SEP.CHR         "L#15"
          VPRINT 20,LINE,SEP.CHR        "L#30"
          VPRINT 51,LINE,SEP.CHR        "L#7"
          BEGIN CASE
          CASE VIEW = 1
             VPRINT 59,LINE,SEP.CHR     "L#4"
             VPRINT 64,LINE,SEP.CHR     "L#4"
             VPRINT 69,LINE,SEP.CHR     "L#4"
             VPRINT 74,LINE,SEP.CHR     "L#4"
          CASE VIEW = 7
             VPRINT 59,LINE,SEP.CHR     "L#15":'ณ'
             VPRINT 75,LINE,SEP.CHR     "L#3"
          CASE OTHERWISE
             VPRINT 59,LINE,SEP.CHR     "L#9":'ณ'
             VPRINT 69,LINE,SEP.CHR     "L#9"
          END CASE

          RETURN
*-------------------------------------------------------------------------*
DEL.TKT:  *
          REDISPLAY = YES
          MNFST     = DELETE(MNFST,15,STP,TK)
          MNFST     = DELETE(MNFST,16,STP,TK)
          IF MNFST<15,STP> = '' THEN
             GOSUB DEL.STP
             REDISPLAY = YES
          END
          IF NOT(MOVE.TKT) AND (LEN(DEL.INVN) = 3 OR LEN(DEL.INVN) = 4) THEN
             READ LREC FROM LEDFILE,DEL.OID ELSE LREC = ''
             IF LEN(DEL.INVN) = 3 THEN
                LOCATE DEL.INVN+0 IN LREC<8> SETTING GEN ELSE GEN = 1
             END ELSE
                LOCATE DEL.INVN+0 IN LREC<12> SETTING GEN ELSE GEN = 1
             END

             READVU LEDL17 FROM LEDLFILE,DEL.OID,17 ELSE LEDL17 = ''
             IF LEDL17<1,GEN> = MANIFEST.ID THEN
                LEDL17<1,GEN> = ''
                WRITEV LEDL17 ON LEDLFILE,DEL.OID,17
                PICK.CONFIRM.UPD.PRVW DEL.OID,DEL.INVN,1
                *** Log in the Order's Change log that it was removed...
                REMOVE.CMT='Removed from Manifest ':MANIFEST.ID
                *** Code to revert ticket to "Q" status when removed from a manifest.
               PRT.STAT = DEL.OID<9,GEN>
                PRT.STAT = 'Q'
                OE.UPD.PRINT.STAT DEL.OID,GEN,PRT.STAT
                OE.ADD.COMMENT DEL.OID,GEN,REMOVE.CMT
                CHK.OID = DEL.OID:'.':LREC<12,GEN>

                GOSUB UPDATE.CARTONS
             END ELSE
                RELEASE LEDLFILE,DEL.OID
             END
          END

          RETURN
*-------------------------------------------------------------------------*
DEL.STP:  *
          MNFST = DELETE(MNFST,12,STP)
          MNFST = DELETE(MNFST,15,STP)
          MNFST = DELETE(MNFST,16,STP)
          MNFST = DELETE(MNFST,10,STP)
          MNFST = DELETE(MNFST,11,STP)
          MNFST = DELETE(MNFST,36,STP)
          MNFST = DELETE(MNFST,37,STP)
          MNFST = DELETE(MNFST,38,STP)
          MNFST = DELETE(MNFST,39,STP)
          MNFST = DELETE(MNFST,41,STP)
          MNFST = DELETE(MNFST,42,STP)
          MNFST = DELETE(MNFST,43,STP)
          MNFST = DELETE(MNFST,44,STP)
          MNFST = DELETE(MNFST,45,STP)

          RETURN
*-------------------------------------------------------------------------*
SUBS:     MOVE.TKT = NO; TICKET.ID = ''
          ON OPTION GOTO PRT.IT,EDIT.IT,VIEW.IT,SELCT,BLK.TM,CMNT,AUTO.SCHED,CLOSE.IT,OPEN.IT,LOCK.IT,REL.PICKS,INS.LN,DEL.LN,CTN.STATUS
*-------------------------------------------------------------------------*
INS.LN:   *
          IF VIEW.ONLY THEN PRINT BELL:; RETURN
          IF NO.EDIT AND MNFST<17> THEN
             MSG = 'Manifest is Locked From Changes. Do Not Insert Ticket.'
             MESS 10,2,BELL:MSG
             RETURN
          END

          LN.IDS   = INSERT(LN.IDS,LINE;'NEW')
          LN.ERRS  = INSERT(LN.ERRS,LINE;'')
          MAX.LNS += 1
          VINS LINE

          RETURN TO INTKT1
*-------------------------------------------------------------------------*
DEL.LN:   *
          IF VIEW.ONLY THEN PRINT BELL:; RETURN
          IF NO.EDIT AND MNFST<17> THEN
             MSG = 'Manifest is Locked From Changes. Do Not Delete Ticket.'
             MESS 10,2,BELL:MSG
             RETURN
          END

          IF LINE = MAX.LNS THEN RETURN
          STP      = FIELD(LN.IDS<LINE>,'~',1)
          IF STP = '' OR STP = 'MSC' THEN PRINT BELL:; RETURN
          IF STP = 'NEW' THEN
             LN.IDS  = DELETE(LN.IDS,LINE)
             LN.ERRS = DELETE(LN.ERRS,LINE)
             MAX.LNS = MAX.LNS-1
             VDEL LINE
             IF LINE > MAX.LNS THEN LINE = MAX.LNS
             RETURN
          END
          SV.LINE  = LINE
          TK       = FIELD(LN.IDS<LINE>,'~',2)
          DEL.OID  = FIELD(MNFST<15,STP,TK>,'.',1)
          DEL.INVN = FIELD(MNFST<15,STP,TK>,'.',2)
          STOP.ID = MNFST<45,STP>
          IF STOP.ID # '' THEN
             IF LEN(DEL.INVN) = 3 THEN
                * can delete manifest pick order if it is cancelled
                READ LREC FROM LEDFILE,DEL.OID ELSE LREC = ''
                LOCATE DEL.INVN+0 IN LREC<8> SETTING DEL.GEN THEN
                   IF LREC<6,DEL.GEN> = 'I' OR LREC<6,DEL.GEN> = 'S' THEN
                      GOSUB CHECK.PICKED
                      IF F12 THEN RETURN
                      IF MOVED.STOP THEN
                         REDISPLAY = YES
                         GOTO DEL.DONE
                      END
                   END
                END
             END
          END
          GOSUB DEL.TKT
          UPDATE.MANIFEST MANIFEST.ID,MNFST,,,THIS.ROUTINE:"-1"
DEL.DONE: *
          IF REDISPLAY THEN
             GOSUB RECALC.TIME
          END
          IF REDISPLAY OR TK = 1 THEN
             REDISPLAY.ALL = YES
             GOSUB DISP.LNS
             GOSUB CALC.TOT
          END ELSE
DEL.SCRN.LP: *
             LN.IDS = DELETE(LN.IDS,LINE)
             LN.ERRS= DELETE(LN.ERRS,LINE)
             VDEL LINE
             MAX.LNS = MAX.LNS-1
             IF LINE <= MAX.LNS AND FIELD(LN.IDS<LINE>,'~',1) = '' THEN
                GOTO DEL.SCRN.LP
             END
             IF LINE > MAX.LNS THEN LINE = MAX.LNS
          END
          LINE = SV.LINE
          IF LINE > MAX.LNS THEN LINE = MAX.LNS
          UPDATE.MANIFEST MANIFEST.ID,MNFST,,,THIS.ROUTINE:"-2"
          RETURN
*-------------------------------------------------------------------------*
PRINT.ASN: * Reprint ASN document
          STOP.NO = FIELD(LN.IDS<LINE>,'~',1)
          IF STOP.NO = '' OR NOT(NUM(STOP.NO)) THEN PRINT BELL:; RETURN

          IF MNFST<41,STOP.NO> = '' THEN
             MESS 10,5,'No Shipment onfile for this stop.'
          END ELSE
             RF.PRINT.MAN.PACKLIST MANIFEST.ID,STOP.NO,YES
          END

          RETURN
*-------------------------------------------------------------------------*
CTN.STATUS: * Display carton/tote status screeN

          MANIFEST.STATUS MANIFEST.ID,MNFST

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

CHECK.PICKED:*
          MOVED.STOP    = NO
          FUNCTION.LIST = 'Delete Ticket from Manifest':VM:'Delete Stop from Manifest':VM:'Move Stop to another Manifest':VM:'Nothing'
          VAR = ''
IN$$14:   INP.PROMPT VAR,BELL:'Stop is locked.':AM:'What do you want to do (Press F10)? ',,30,'D:':FUNCTION.LIST
          IF F12 THEN RETURN
          LOCATE VAR IN FUNCTION.LIST<1> SETTING POS ELSE GOTO CHECK.PICKED
          BEGIN CASE
          CASE POS = 4
             F12 = YES
             RETURN
          CASE POS = 2
             GOSUB DELETE.STOP
             RETURN
          CASE POS = 3
             GOSUB MOVE.STOP
             RETURN
          END CASE
          * deleting only this ticket
          WK.ORD = DEL.OID:'.':LREC<12,DEL.GEN>
          * if anything picked for the ticket - see if seperate
          BSCAN WRK,WKIDS FROM WHQFILE,WK.ORD:'~P' USING '&INDEX&.ORDERID' BY 'A' ELSE RETURN
          IF WRK # WK.ORD:'~P' THEN RETURN
          TOTES = ''
          W.CT = DCOUNT(WKIDS,AM)
          FOR W = 1 TO W.CT
             WKID = WKIDS<W>
             * clear mnfst id from picked whq records while we're at it
             READU WHQ FROM WHQFILE,WKID ELSE
                RELEASE WHQFILE,WKID
                CONTINUE
             END
             IF WHQ<15> # '' THEN
                WHQ<15> = ''
                WRITE WHQ ON WHQFILE,WKID
             END ELSE
                RELEASE WHQFILE,WKID
             END
             * get all entries with that tote to be sure only this ticket
             TOTE    = WHQ<7>
             IF TOTE = '' THEN CONTINUE
             LOCATE TOTE IN TOTES SETTING POS THEN CONTINUE
             ROOT      = 'TT~':BR:'~':TOTE:'~'
             SAVE.ROOT = ROOT
             LEN.ROOT  = LEN(ROOT)
             LOOP
                BSCAN WRK FROM WHQFILE,ROOT USING '&INDEX&.SPCL' BY 'A' ELSE EXIT
                IF WRK[1,LEN.ROOT] # SAVE.ROOT THEN EXIT
                ROOT = ''
                IF FIELD(WRK,'~',4) # WK.ORD THEN
                   * must clear stop id for all tickets on stop
                   PRINT BELL:
IN$$19:            INP.PROMPT ,'Ticket is combined with other picks on stop.':AM:'Material must be removed from totes manually.':AM:'Press <Enter>',,0
                   CLEARSELECT
                   GOSUB CONVERT.STOP.ID
                   RETURN
                END
             REPEAT
             TOTES<-1> = TOTE
             TOTE.ID = BR:'~':TOTE:'~T'
             * clear mnfst id from tote record
             READU OTOTE.REC FROM OTOTEFILE,TOTE.ID THEN
                OTOTE.REC<1> = WK.ORD
                OTOTE.REC<12> = ''
                WRITE OTOTE.REC ON OTOTEFILE,TOTE.ID
             END ELSE
                RELEASE OTOTEFILE,TOTE.ID
             END
          NEXT T
          * clear mnfst id from unpicked whq entries
          ROOT      = 'NT~':WK.ORD:'~'
          SAVE.ROOT = ROOT
          LEN.ROOT  = LEN(ROOT)
          LOOP
             BSCAN WRK,WKIDS FROM WHQFILE,ROOT USING '&INDEX&.SPCL' BY 'A' ELSE EXIT
             IF WRK[1,LEN.ROOT] # SAVE.ROOT THEN EXIT
             ROOT = ''
             SELECT WKIDS
             LOOP
                READNEXT WID ELSE EXIT
                READU WHQ FROM WHQFILE,WID THEN
                   WHQ<15> = ''
                   WRITE WHQ ON WHQFILE,WID
                END ELSE
                   RELEASE WHQFILE,WID
                END
             REPEAT
          REPEAT

          RETURN
*-------------------------------------------------------------------------*
DELETE.STOP:*
          GOSUB CONVERT.STOP.ID
          MOVE.TKT = NO
          TICKETS = RAISE(RAISE(MNFST<15,STP>))
          T.CT = DCOUNT(TICKETS,AM)
          * delete all tickets but the first - will be done on return
          FOR TK = 2 TO T.CT
             DEL.OID  = FIELD(TICKETS<TK>,'.',1)
             DEL.INVN = FIELD(TICKETS<TK>,'.',2)
             GOSUB DEL.TKT
          NEXT TK
          * set up last ticket on stop to be deleted
          TK       = 1
          DEL.OID  = FIELD(TICKETS<1>,'.',1)
          DEL.INVN = FIELD(TICKETS<1>,'.',2)

          RETURN
*-------------------------------------------------------------------------*
MOVE.STOP:*
          NEW.MNFST = ''
IN$$20:   INP.PROMPT NEW.MNFST,'Enter Manifest to go to : ','MCU',OID.LGTH$
          IF F12 THEN RETURN
          IF NEW.MNFST = '' THEN F12 = YES; RETURN
          IF NEW.MNFST = MANIFEST.ID THEN PRINT BELL:; GOTO MOVE.STOP
          READU NMNFST FROM MNFSTFILE,NEW.MNFST ELSE
             RELEASE MNFSTFILE,NEW.MNFST
             PRINT BELL:
             GOTO MOVE.STOP
          END

          STOP.INFO = MNFST<10,STP,1>
          S.CT = DCOUNT(NMNFST<10>,VM)
          FOR S = 1 TO S.CT
             IF NMNFST<10,S,1> > STOP.INFO THEN EXIT
          NEXT S
          NMNFST = INSERT(NMNFST,10,S,1;STOP.INFO)
          NMNFST = INSERT(NMNFST,11,S;MNFST<11,STP>)
          NMNFST = INSERT(NMNFST,12,S;MNFST<12,STP>)
          NMNFST = INSERT(NMNFST,15,S;MNFST<15,STP>)
          NMNFST = INSERT(NMNFST,16,S;MNFST<16,STP>)
          NMNFST = INSERT(NMNFST,36,S;MNFST<36,STP>)
          NMNFST = INSERT(NMNFST,37,S;MNFST<37,STP>)
          NMNFST = INSERT(NMNFST,38,S;MNFST<38,STP>)
          NMNFST = INSERT(NMNFST,39,S;MNFST<39,STP>)
          NMNFST = INSERT(NMNFST,41,S;MNFST<41,STP>)
          NMNFST = INSERT(NMNFST,42,S;MNFST<42,STP>)
          NMNFST = INSERT(NMNFST,43,S;MNFST<43,STP>)
          NMNFST = INSERT(NMNFST,44,S;MNFST<44,STP>)
          NMNFST = INSERT(NMNFST,45,S;MNFST<45,STP>)
          UPDATE.MANIFEST NEW.MNFST,NMNFST,YES,,THIS.ROUTINE:"-3"
          GOSUB DEL.STP
          MOVED.STOP = YES
          * now change ledger.log records
          OIDS = RAISE(RAISE(NMNFST<15,S>))
          O.CT = DCOUNT(OIDS,AM)
          FOR O = 1 TO O.CT
             DEL.OID  = FIELD(OIDS<O>,'.',1)
             DEL.INVN = FIELD(OIDS<O>,'.',2)
             IF LEN(DEL.INVN) = 3 THEN
                READV DEL.GENS FROM LEDFILE,DEL.OID,8 ELSE DEL.GENS = ''
             END ELSE
                READV DEL.GENS FROM LEDFILE,DEL.OID,12 ELSE DEL.GENS = ''
             END
             LOCATE DEL.INVN+0 IN DEL.GENS<1> SETTING DEL.GEN THEN
                READVU LEDL17 FROM LEDLFILE,DEL.OID,17 ELSE LEDL17 = ''
                IF LEDL17<1,DEL.GEN> = MANIFEST.ID THEN
                   LEDL17<1,DEL.GEN> = NEW.MNFST
                   WRITEV LEDL17 ON LEDLFILE,DEL.OID,17
                END ELSE
                   RELEASE LEDLFILE,DEL.OID
                END
             END
          NEXT O
          RETURN
*-------------------------------------------------------------------------*
CONVERT.STOP.ID:* ??
          IF MNFST = '' THEN RETURN
          TOTES.DONE = ''
          * get all whq entries with this stop id to clear it out
          ROOT       = 'MF~':STOP.ID:'~'
          SAVE.ROOT  = ROOT
          LEN.ROOT   = LEN(ROOT)
          LOOP
             BSCAN WRK,WKIDS FROM WHQFILE,ROOT USING '&INDEX&.SPCL' BY 'A' ELSE EXIT
             ROOT = ''
             IF WRK[1,LEN.ROOT] # SAVE.ROOT THEN EXIT
             CLEARSELECT
             SELECT WKIDS
             LOOP
                READNEXT WID ELSE EXIT
                READU WHQ FROM WHQFILE,WID ELSE
                   RELEASE WHQFILE,WID
                   CONTINUE
                END
                WHQ<15> = ''
                WRITE WHQ ON WHQFILE,WID
                TOTE = WHQ<7>
                * if no tote - done
                IF TOTE = '' THEN CONTINUE
                TOTE.ID = WHQ<4>:'~':TOTE:'~T'
                WK.ORD  = FIELD(FIELD(WID,'~',3),'.',1,2)
                WK.ID   = TOTE.ID:'~':WK.ORD
                LOCATE WK.ID IN TOTES.DONE SETTING POS THEN CONTINUE
                TOTES.DONE<POS> = WK.ID
                READU TOTE.REC FROM OTOTEFILE,TOTE.ID ELSE TOTE.REC = ''
                IF TOTE.REC<1,1> = STOP.ID THEN
                   TOTE.REC = DELETE(TOTE.REC,1,1)
                END
                LOCATE WK.ORD IN TOTE.REC<1> SETTING POS ELSE
                   TOTE.REC<1,POS> = WK.ORD
                END
                TOTE.REC<12> = ''
                WRITE TOTE.REC ON OTOTEFILE,TOTE.ID
             REPEAT
          REPEAT
          * now delete any totes left under stop.id
          ROOT = 'GI~':BR:'~T~':STOP.ID
          BSCAN WRK,WKIDS FROM OTOTEFILE,ROOT USING '&INDEX&.SPCL' BY 'A' ELSE RETURN
          IF WRK # ROOT THEN RETURN
          SELECT WKIDS
          LOOP
          READNEXT WKID ELSE EXIT
             DELETE OTOTEFILE,WKID
          REPEAT

          RETURN
*-------------------------------------------------------------------------*
PRT.IT:   * print shipping manifest
   *      IF VIEW.ONLY THEN PRINT BELL:; RETURN

          IF NOT(VIEW.ONLY) THEN
             UPDATE.MANIFEST MANIFEST.ID,MNFST,,,THIS.ROUTINE:"-4"
          END

          SOE.MANIFEST.RPTS MNFST,MANIFEST.ID,ERR.MESS

       *  WINDOW ,,40,3,3
       *  PRINT @(1,1):BLINK$:'Submitting report...':NORM$:
       *  DRPT$ = 'Shipping Manifest'

          * to match change in dev4.0 version
      *   PRINT @(1,1):BLINK$:'Running report...':NORM$:

      *   SOE.MANIFEST.REPORT  MANIFEST.ID,ERR.MESS
          IF ERR.MESS THEN
             MESS 10,2,BELL:ERR.MESS:' Press <Enter>'
IN$$6:       INP A,,,0,H_"IH#39"
          END

       *  WINDOW.CLOSE

          RETURN
*-------------------------------------------------------------------------*
EDIT.IT:  * edit ledger for line
          STP = FIELD(LN.IDS<LINE>,'~',1)
          IF STP = 'NEW' THEN RETURN
          TK  = FIELD(LN.IDS<LINE>,'~',2)
          ID  = MNFST<15,STP,TK>
          OID = FIELD(ID,'.',1)
          INVN= FIELD(ID,'.',2)
          IF LEN(INVN) = 3 THEN
             READV INVNS FROM LEDFILE,OID,8  ELSE INVNS = ''
          END ELSE
             READV INVNS FROM LEDFILE,OID,12 ELSE INVNS = ''
          END
          LOCATE INVN+0 IN INVNS<1> SETTING GEN ELSE PRINT BELL:; RETURN

          VIEW.EDIT.LED OID,GEN,VIEW.ONLY
          IF NOT(VIEW.ONLY) THEN GOSUB DISP.LNS

          * need to recheck error flags
          MATREAD LED FROM LEDFILE,OID ELSE MAT LED = ''
          ERR.FLAG = ''
          IF LED(70)<1,GEN>#VIA OR LED(2)<1,GEN,2>#BR OR LED(9)<1,GEN>#SHIP.DT THEN
             ERR.FLAG<1,1> = YES
             * Check if changes would be made in a close period and if
             * so, then add error message.
             GL.CLOSE.DT.GET OID,GL.CLOSE.DT
             IF LED(23)<1,GEN> AND LED(23)<1,GEN> < GL.CLOSE.DT THEN
                ERR.FLAG<1,3> = YES
             END
          END
          IF LEN(INVN) # 3 AND LED(8)<1,GEN>#'' THEN
             ERR.FLAG<1,2> = YES
          END

          LN.ERRS<LINE> = ERR.FLAG

          RETURN
*-------------------------------------------------------------------------*
VIEW.IT:  * change screen views

          VIEW.TBL = 'Shipping Packages':VM:'Expected Time':VM:'Actual Time':VM:'Expected Time - Display Max Lines':VM:'Dollars, Load Factor and Weight':VM:'Expected Time / Actual Time':VM:'Stage Location and Hold Picks'
          IF SHIPMENT.MAINT.ENABLED THEN
             VIEW.TBL<1,-1> = 'Shipment#'
          END
          MENU.TABLE VAR,30,10,1,8,35,,,VIEW.TBL,'View Choices',VIEW
          LOCATE VAR IN VIEW.TBL<1> SETTING NEW.VIEW ELSE NEW.VIEW = VIEW
DISP.NEW.VIEW: *
          IF NEW.VIEW = VIEW THEN RETURN

          SOE.MANIFEST.DISP.LNS LN.IDS,MAX.LNS,LN.ERRS,LINE,MNFST,MANIFEST.ID,VIEW,NEW.VIEW

          BEGIN CASE
          CASE VIEW.ONLY
             COLS = 1
             IF VIEW = 1 THEN GOSUB CALC.TOT      ;* display totals
             IF VIEW = 5 THEN GOSUB CALC.TOT
          CASE VIEW = 1
             COLS = 7
             GOSUB CALC.TOT                       ;* display totals
          CASE VIEW = 2              ; COLS = 3
          CASE VIEW = 3              ; COLS = 4
          CASE VIEW = 4              ; COLS = 3
          CASE VIEW = 5
             COLS = 3
             GOSUB CALC.TOT                       ;* display totals
          CASE VIEW = 6              ; COLS = 2
          CASE VIEW = 7              ; COLS = 4
          CASE OTHERWISE             ; COLS = 3
          END CASE

          IF COL > COLS THEN
             MOVE    = 0
             LASTKEY = 0
             COL     = COLS
             RETURN TO MOVENEXT
          END
          RETURN
*-------------------------------------------------------------------------*
SELCT:    * get un-manifested tickets
          IF VIEW.ONLY THEN PRINT BELL:; RETURN
          MNFST.SAVE = MNFST
          AUTOSTP = ''

          IF NOT(AUTOSCHED) THEN
             AUTOSTP = LN.IDS<LINE>
             IF AUTOSTP = 'NEW' THEN
                SAVE.LINE = LINE
                LINE      = LINE-1
                GOSUB GET.VALID.LINE.REV
                IF LINE < SAVE.LINE THEN
                   AUTOSTP = LN.IDS<LINE>
                END ELSE
                   AUTOSTP = 0
                END
                LINE = SAVE.LINE
             END
          END

          * If import routine is being used due to <S>elect Tickets
          * option then we need to redisplay entire queue when coming
          * back in.  If it is being used only to import one ticket
          * then only need to redisplay that one ticket.
          SEL.TICKETS = NO
          IF NOT(TICKET.ID) THEN
             SEL.TICKETS = YES
          END

          SOE.MANIFEST.IMPORT MNFST,MANIFEST.ID,TICKET.ID,,AUTOSCHED,AUTOSTP,ERR.MSG,ERR.TYPE

          BEGIN CASE
          CASE ERR.MSG
             * Fatal error message - Cannot add order to manifest
IN.ERR:      INP.PROMPT ,BELL:ERR.MSG:AM:'Press <Enter>',,0
          CASE ERR.TYPE
             * Give user warning message
             MSG = ''
             BEGIN CASE
             CASE ERR.TYPE = 6
                MSG = 'Order Already Picked - Not Setting to Pick Hold'
             CASE ERR.TYPE = 7
                MSG = 'Selected for Picking - Not Setting to Pick Hold'
             END CASE
             IF MSG THEN
IN$$8:          INP.PROMPT ,BELL:MSG:AM:'Press <Enter> to Continue',,0
             END
          END CASE

          IF MNFST # MNFST.SAVE THEN
             GOSUB RECALC.TIME
             GOSUB CALC.TOT

             * If AutSched is not activated and we are adding to the queue
             * then we need only display the info for the item that was
             * just entered for faster screen repaints
             IF NOT(AUTOSCHED) AND NOT(SEL.TICKETS) AND (LINE = DCOUNT(LN.IDS,AM)) THEN
                REDISPLAY.ALL = NO
             END
             GOSUB DISP.LNS
          END

          RETURN
*-------------------------------------------------------------------------*
BLK.TM:   * set up a time block in mnfst<14>; with no overlaps
          IF VIEW.ONLY THEN PRINT BELL:; RETURN
          BLK.DATA = MNFST<14>
          SOE.MANIFEST.BLOCK BLK.DATA
          IF BLK.DATA # MNFST<14> THEN
             MNFST<14> = BLK.DATA
             GOSUB RECALC.TIME
             GOSUB DISP.LNS
          END

          RETURN
*-------------------------------------------------------------------------*
CMNT:     * put a comment for the ticket in mnfst<16> aligned with <15>
          IF VIEW.ONLY THEN PRINT BELL:; RETURN
          STP = FIELD(LN.IDS<LINE>,'~',1)
          IF STP = 'NEW' THEN PRINT BELL:; RETURN
          TK  = FIELD(LN.IDS<LINE>,'~',2)
          DATA = RAISE(RAISE(MNFST<16,STP,TK>))
          SOE.MANIFEST.COMMENTS 1,DATA
          XXX = LOWER(LOWER(DATA))
          IF MNFST<16,STP,TK> = XXX THEN RETURN
          MNFST<16,STP,TK> = LOWER(LOWER(DATA))

          *  remove old comment lines
          FOR L = LINE+1 TO MAX.LNS
          IF FIELD(LN.IDS<L>,'~',1) # '' THEN EXIT
          IF FIELD(LN.IDS<L>,'~',3) = 'C' THEN
             VDEL L
             LN.IDS  = DELETE(LN.IDS,L)
             LN.ERRS = DELETE(LN.ERRS,L)
             L       = L-1
             MAX.LNS = MAX.LNS-1
          END
          NEXT L

          * put in new comment lines
          TK        = FIELD(LN.IDS<LINE>,'~',2)
          CMNT      = RAISE(RAISE(MNFST<16,STP,TK>))
          CMNT.CT   = DCOUNT(CMNT,VM)
          SAVE.LINE = LINE
          LINE      = L
          IF CMNT # '' THEN
             IF FIELD(CMNT,VM,1) = "** EManifest Comments **" THEN
                STR = FIELD(CMNT,VM,2,CMNT.CT)
             END ELSE
                STR = CMNT
             END
             CONVERT VM TO ' ' IN STR
             STR = TRIM(STR)
             FOLD STR,31,NEW.CMNT,VCT
             IF FIELD(CMNT,VM,1) = "** EManifest Comments **" THEN
                NEW.CMNT = FIELD(CMNT,VM,1):VM:NEW.CMNT
             END
          END ELSE
             NEW.CMNT = CMNT
          END
          NEW.CMNT.CT = DCOUNT(NEW.CMNT,VM)
          FOR C = 1 TO NEW.CMNT.CT
          VINS LINE
          GOSUB CLR.LINE
          VPRINT 19,LINE,NEW.CMNT<1,C> "L#31"
          LN.IDS  = INSERT(LN.IDS,LINE;'~~C')
          LN.ERRS = INSERT(LN.ERRS,LINE;'')
          MAX.LNS += 1
          LINE    += 1
          NEXT C
          LINE = SAVE.LINE

          RETURN
*-------------------------------------------------------------------------*
AUTO.SCHED: * change flag for automatic stop scheduling
          IF AUTOSCHED THEN AUTOSCHED = NO ELSE AUTOSCHED = YES
          IF AUTOSCHED THEN
             PRINT @(52,21):'On '
          END ELSE
             PRINT @(52,21):'Off'
          END

          RETURN
*-------------------------------------------------------------------------*
CLOSE.IT: *
          IF VIEW.ONLY THEN PRINT BELL:; RETURN
          SURE = ''
          PRMPT.MSG = ''
          PM.FLD    = 1
          CP.CNT    = 0     ;* Closed period count
          * Check to see if there were any closed period errors set in
          * SOE.MANIFEST.DISP.LNS
          LECT = DCOUNT(LN.ERRS,AM)
          FOR LEC = 1 TO LECT
             IF LN.ERRS<LEC,3> THEN
                CP.CNT += 1
             END
          NEXT LEC
          IF CP.CNT THEN
             IF CP.CNT = 1 THEN
                PRMPT.MSG<PM.FLD> = CP.CNT:' Ticket'
             END ELSE
                PRMPT.MSG<PM.FLD> = CP.CNT:' Tickets'
             END

             PRMPT.MSG<PM.FLD> := ' in a closed accounting period. '
             PM.FLD += 1
             PRMPT.MSG<PM.FLD>  = 'Branch, Ship-date, or Ship-via'
             PRMPT.MSG<PM.FLD> := ' will not be updated.'
             PM.FLD += 1
          END
          PRMPT.MSG<PM.FLD>  = 'Are you SURE you want to CLOSE'
          PRMPT.MSG<PM.FLD> := ' this manifest (Y/N) : '
IN$$7:    INP.PROMPT SURE,PRMPT.MSG,'YN'

          IF NOT(SURE) THEN RETURN

          *** Grab all of the oids
          TOIDS = ''
          OIDS.VMN = DCOUNT(MNFST<15>,VM)
          FOR VMN = 1 TO OIDS.VMN
             OIDS.SVMN = DCOUNT(MNFST<15,VMN>,SVM)
             FOR SVMN = 1 TO OIDS.SVMN
                TOIDS<-1> = MNFST<15,VMN,SVMN>
             NEXT SVMN
          NEXT VMN

          *** Check to see if tax info will change and prompt user
          NO.COPY.TAX = ''
          SURE = ''
          OIDS.CT = DCOUNT(TOIDS,AM)
          FOR OID.CTR = 1 TO OIDS.CT
             TOID = FIELD(TOIDS<OID.CTR>,'.',1)
             TINVN = FIELD(TOIDS<OID.CTR>,'.',2)
             READV TINVNS FROM LEDFILE,TOID,8 ELSE TINVNS = ''
             LOCATE TINVN IN TINVNS<1> SETTING TGEN ELSE TGEN = ''
             OE.CHECK.TAX.STATUS.CHNG TOID,TGEN,MNFST<1>,CHNG
             IF CHNG THEN
                CHNG.MSG = 'Copy Over New Tax Exempt Status? (Y/N): '
IN$$10:         INP.PROMPT SURE,CHNG.MSG,'YN'
                IF SURE THEN NO.COPY.TAX = NO ELSE NO.COPY.TAX = YES
                EXIT
             END
          NEXT OID.CTR

          SOE.MANIFEST.CLOSE ERR.TKT,ERR.MESS,MNFST,MANIFEST.ID,NO.COPY.TAX

          IF ERR.TKT # '' THEN
             FINDSTR ERR.TKT IN MNFST<15> SETTING XXX,STP,TK THEN
                LOCATE STP:'~':TK IN LN.IDS SETTING LINE THEN
                   VSCROLL.MOVE LINE
                END
             END
          END

          IF ERR.MESS THEN
             MESS 10,10,BELL:ERR.MESS
          END ELSE
             OMNF.ID = MANIFEST.ID
             VIEW.ONLY = YES
             RELEASE MNFSTFILE,MANIFEST.ID

             LOCATE MANIFEST.ID IN LOCKED.LEDS SETTING POS THEN
                LOCKED.LEDS = DELETE(LOCKED.LEDS,POS)
             END

             RETURN TO START
          END

          RETURN
*-------------------------------------------------------------------------*
OPEN.IT:  *
          IF NOT(EDIT.OK) THEN PRINT BELL; RETURN
          IF NOT(MNFST<7>) THEN
             MESS 10,10,BELL:'Manifest is not Closed'
             RETURN
          END

          MNFST<7> = ''
          UPDATE.MANIFEST MANIFEST.ID,MNFST,,,THIS.ROUTINE:"-5"
          MESS 10,10,BELL:'Manifest is now Open.'
          OMNF.ID = MANIFEST.ID
          VIEW.ONLY = NO

          RETURN TO START
*-------------------------------------------------------------------------*
LOCK.IT:  *
          IF VIEW.ONLY THEN PRINT BELL; RETURN

          *** Go through each order on each stop and see if the ship to
          *** customer has a trigger set up, if so call ACTIVITY.TRIGGER
          *** to execute each activity tied to that trigger.
          IF MNFST<17> # YES THEN
             STPCNT = DCOUNT(MNFST<15>,VM)
             FOR STP = 1 TO STPCNT
                ORDCNT = DCOUNT(MNFST<15,STP>,SVM)
                FOR ORD = 1 TO ORDCNT
                   OID = FIELD(MNFST<15,STP,ORD>,'.',1)
                   INVN = FIELD(MNFST<15,STP,ORD>,'.',2)
                   MATREAD LED FROM LEDFILE,OID ELSE MAT LED = ''
                   IF LEN(INVN) > 3 THEN
                      GID = INVN + 0
                      LOCATE GID IN LED(12)<1> SETTING GEN ELSE
                         GEN = 1
                      END
                   END ELSE
                      INVN += 0
                      LOCATE INVN IN LED(8)<1> SETTING GEN ELSE
                         GEN = 1
                      END
                   END
                   GID = LED(12)<1,GEN>

                   ST.CN       = LED(5)<1,GEN>
                   MID         = MANIFEST.ID
                   AT.ID       = 'T018'
                   AT.DATA     = ''
                   AT.DATA<2>  = LED(5)<1,GEN>:VM:LED(1)<1,GEN>
                   AT.DATA<3>  = LED(2)<1,GEN,2>
                   AT.DATA<4>  = OID
                   AT.DATA<5>  = GEN
                   AT.DATA<6>  = OID:'.':INVN"R%3"
                   AT.DATA<7>  = LED(6)<1,GEN>
                   AT.DATA<12> = MID[2,LEN(MID)]:VM:STP:VM:ORD

                   DOCS.PRDCD = ''
                   ACTIVITY.TRIGGER AT.ID,AT.DATA,DOCS.PRDCD
                NEXT ORD
             NEXT STP
          END
          IF MNFST<17> THEN
             MNFST<17> = ''
             MSG = 'Manifest now Open to '
             PRINT @(73,0):'ออออออ' ;* Over write Locked display
             PRINT @(62,21):'  L'
          END ELSE
             MNFST<17> = YES
             MSG = 'Manifest now Closed to '
             PRINT @(73,0):BLINK$:'Locked':NORM$
             PRINT @(62,21):'Unl'
          END

          GOSUB LOAD.HOTKEYS

          UPDATE.MANIFEST MANIFEST.ID,MNFST,,,THIS.ROUTINE:"-6"

          IF NO.EDIT THEN
             MSG := 'Changes and Auto Manifest Loading.'
          END ELSE
             MSG := 'Auto Manifest Loading.'
          END
          MESS 10,10,BELL:MSG

          RETURN TO INSTOP
*-------------------------------------------------------------------------*
REL.PICKS:*
          GOSUB CHECK.LOCK
          IF NOT(MNFST.LOCKED) THEN
             RETURN
          END
          STP = FIELD(LN.IDS<LINE>,'~',1)
          VAR = ''
IN$$12:   INP.PROMPT VAR,'Release All Stops/Only Stop ':STP:'/None? (A/O/N): ','MCU',1,'D:,A,O,N'
          BEGIN CASE
          CASE VAR = 'N'
             RETURN
          CASE VAR = 'O'
             IF STP = '' OR NOT(NUM(STP)) THEN RETURN
          CASE VAR = 'A'
             * if any valid stops - lock stops
             FOR L = LINE TO MAX.LNS
                WKSTP = FIELD(LN.IDS<L>,'~',1)
                IF WKSTP # '' AND NUM(WKSTP) THEN EXIT
             NEXT L
             IF L <= MAX.LNS THEN
                MNFST<47> = 1
             END
          CASE OTHERWISE
             RETURN
          END CASE

          * verify ship via priority
          SHIP.VIA.GET.PICK.PRI BR,VIA,PRI
          IF PRI = '' THEN PRI = 99
          MNFST<40> = PRI

          IF VAR = 'O' THEN
             GOSUB RELEASE.PICKS
          END ELSE
             MNFST<35> = ''
             STP.CT = DCOUNT(MNFST<15>,VM)
             FOR STP = 1 TO STP.CT
                GOSUB RELEASE.PICKS
             NEXT STP
          END
          IF VIEW = 7 THEN
             REDISPLAY.ALL = YES
             GOSUB DISP.LNS
          END
          GOSUB LOAD.HOTKEYS
          RETURN
*-------------------------------------------------------------------------*
RELEASE.PICKS:*
          * do nothing if a pickup stop
          IF LEN(FIELD(MNFST<15,STP,1>,'.',2)) = 4 THEN RETURN
          MNFST<37,STP> = ''

          * If we have a stop ID, don't re-assign a new one as some tickets
          * on this stop could have been picked and so to maintain the
          * relationships between the manifest record and the open totes
          * file, we need to keep the stops in sync.
          IF MNFST<45,STP> = '' THEN
             GET.NEW.ID 'NEXT.PICK.NO',STOP.ID,'MP',,,YES
             MNFST<45,STP> = STOP.ID
          END

          UPDATE.MANIFEST MANIFEST.ID,MNFST,,,THIS.ROUTINE:"-7"
          TK.CT = DCOUNT(MNFST<15,STP>,SVM)
          FOR T = 1 TO TK.CT
             ID   = MNFST<15,STP,T>
             OID  = FIELD(ID,'.',1)
             INVN = FIELD(ID,'.',2)
             IF LEN(INVN) = 3 THEN
                READ LREC FROM LEDFILE,OID ELSE LREC = ''
                LOCATE INVN+0 IN LREC<8> SETTING GEN ELSE CONTINUE
                GID = LREC<12,GEN>
             END ELSE
                GID = INVN+0
             END
             * change flag in print.review record
             PRVW.ID = OID:'.':GID"R%4"
             READU PRVW FROM PRVWFILE,PRVW.ID ELSE PRVW = 'PICKING'
             * if not holding pick - skip
             IF PRVW<19> = 'N' THEN
                RELEASE PRVWFILE,PRVW.ID
                CONTINUE
             END
             PRVW<19> = 'N'
             * append log info
             LPOS = DCOUNT(PRVW<22>,VM)+1
             PRVW<22,LPOS,1> = "SOE.MANIFEST.QUEUE"
             PRVW<22,LPOS,2> = DATE()
             PRVW<22,LPOS,3> = INT(TIME())
             PRVW<22,LPOS,4> = "OK to Pick"
             WRITE PRVW ON PRVWFILE,PRVW.ID
             * get wid for order and set flag
             ROOT      = 'NT~':OID:'.':GID:'~'
             SAVE.ROOT = ROOT
             LEN.ROOT  = LEN(ROOT)
             LOOP
                BSCAN WRK,WKIDS FROM WHQFILE,ROOT USING '&INDEX&.SPCL' BY 'A' ELSE EXIT
                IF WRK[1,LEN.ROOT] # SAVE.ROOT THEN EXIT
                ROOT = ''
                SELECT WKIDS
                LOOP
                   READNEXT WID ELSE EXIT
                   READU WHQ FROM WHQFILE,WID THEN
                      WHQ<15> = MNFST<45,STP>
                      WHQ<18> = ''
                      WRITE WHQ ON WHQFILE,WID
                   END ELSE
                      RELEASE WHQFILE,WID
                   END
                REPEAT
             REPEAT
          NEXT T

          RETURN
*-------------------------------------------------------------------------*
CALC.TOT: * Calculate total fields where applicable
          BEGIN CASE

*** Shipping Packages View
          CASE VIEW = 1
          BOX.TOT = 0
          BAG.TOT = 0
          BND.TOT = 0
          LEN.TOT = 0
          ST.CT   = DCOUNT(MNFST<15>,VM)
          FOR STP = 1 TO ST.CT
             PKGS = RAISE(RAISE(MNFST<42,STP>))
             * manifest pick pkgs by tote, reg by ticket
             IF SUMMATION(PKGS) # 0 THEN
                T.CT = DCOUNT(PKGS,AM)
                FOR T = 1 TO T.CT
                   BOX.TOT += PKGS<T,1>+0
                   BAG.TOT += PKGS<T,2>+0
                   BND.TOT += PKGS<T,3>+0
                   LEN.TOT += PKGS<T,4>+0
                NEXT T
             END ELSE
                IDS         = MNFST<15,STP>
                TK.CT       = DCOUNT(IDS,SVM)
                FOR TK = 1 TO TK.CT
                   TICKET.ID   = IDS<1,1,TK>
                   OID         = FIELD(TICKET.ID,'.',1)
                   INVN        = FIELD(TICKET.ID,'.',2) + 0
                   READV LED8 FROM LEDFILE,OID,8 ELSE
                      LED8 = ''
                   END
                   LOCATE(INVN,LED8,1;PGN) ELSE PGN = 1
                   READV PACKAGES FROM LEDLFILE,OID,18 ELSE PACKAGES=''
                   PACKAGES = PACKAGES<1,PGN>
                   BOX.TOT += PACKAGES<1,1,1>
                   BAG.TOT += PACKAGES<1,1,2>
                   BND.TOT += PACKAGES<1,1,3>
                   LEN.TOT += PACKAGES<1,1,4>
                NEXT TK
             END
          NEXT STP
          BOX.TOT = RIGHT("    ":BOX.TOT,4)
          BAG.TOT = RIGHT("    ":BAG.TOT,4)
          BND.TOT = RIGHT("    ":BND.TOT,4)
          LEN.TOT = RIGHT("    ":LEN.TOT,4)
          PRINT @(60,19):REV$:BOX.TOT:'ณ':NORM$
          PRINT @(65,19):REV$:BAG.TOT:'ณ':NORM$
          PRINT @(70,19):REV$:BND.TOT:'ณ':NORM$
          PRINT @(75,19):REV$:LEN.TOT:NORM$

*** Dollars, Load Factor and Weight Screen
          CASE VIEW = 5
          QSIGN    = -1
          WGHT.TOT = 0
          LOAD.TOT = 0
          DOLR.TOT = 0
          ST.CT   = DCOUNT(MNFST<15>,VM)
          FOR STP = 1 TO ST.CT
             IDS    = MNFST<15,STP>
             TK.CT  = DCOUNT(IDS,SVM)
             FOR TK = 1 TO TK.CT
                TICKET.ID = IDS<1,1,TK>
                OID       = FIELD(TICKET.ID,'.',1)
                INVN      = FIELD(TICKET.ID,'.',2)
                MATREAD LED FROM LEDFILE,OID ELSE MAT LED = ''
                LOCATE INVN+0 IN LED(8)<1> SETTING GEN ELSE GEN = 1
                OE.GET.WEIGHT OID,GEN,TOL.PCS,TOL.WGHT,TOL.LOAD
                OE.ORDER.TOTAL OID,GEN,QSIGN,TOTAL
                DOLR.TOT += TOTAL
                WGHT.TOT += TOL.WGHT
                LOAD.TOT += TOL.LOAD
             NEXT TK
          NEXT STP
          * Display decimals if there is room
          IF OCONV(LOAD.TOT, 'MD14') > 999 THEN
             LOAD.TOT = RIGHT("     ":OCONV(LOAD.TOT,'MD04'),5)
          END ELSE
             LOAD.TOT = RIGHT("     ":OCONV(LOAD.TOT,'MD14'),5)
          END
          DOLR.TOT = RIGHT("       ":OCONV(DOLR.TOT,'MD02'),7)
          WGHT.TOT = RIGHT("     ":ICONV(OCONV(WGHT.TOT,W.FMT),'MR0'),5)
          PRINT @(60,19):REV$:DOLR.TOT:'ณ':NORM$
          PRINT @(68,19):REV$:LOAD.TOT:'ณ':NORM$
          PRINT @(74,19):REV$:WGHT.TOT:NORM$

          END CASE

          RETURN
*-------------------------------------------------------------------------*
CHECK.LOCK: * When releasing picks check that manifest has been locked.
            * If not locked then picks cannot be released

          MNFST.LOCKED = YES
          IF NOT(MNFST<17>) THEN
             MNFST.LOCKED = NO
             MSG = 'Manifest must be locked before picks can be released. <Return> '
             ANS = ''
IN$$21:      INP.PROMPT ANS,BELL:MSG
          END

          RETURN
*-------------------------------------------------------------------------*
CHK.LEDL:*If aborting need to remove manifest#s from any LEDGER.LOG records
          OLD.INVNS = OLD.MNFST<15>
          INVN.CNT  = DCOUNT(MNFST<15>,VM)
          FOR I = 1 TO INVN.CNT
             I.CNT = DCOUNT(MNFST<15,I>,SVM)
             FOR II = 1 TO I.CNT
                CHK.INVN = MNFST<15,I,II>
                CHK.OID  = FIELD(CHK.INVN,'.',1)
                DEL.INVN = FIELD(CHK.INVN,'.',2)
                FINDSTR CHK.INVN IN OLD.INVNS SETTING X,Y,Z ELSE
                   READ LREC FROM LEDFILE,CHK.OID ELSE
                      LREC = ''
                   END
                   IF LEN(DEL.INVN) = 3 THEN
                      LOCATE DEL.INVN+0 IN LREC<8> SETTING CHK.GEN ELSE
                         CHK.GEN = 1
                      END
                   END ELSE
                      LOCATE DEL.INVN+0 IN LREC<12> SETTING CHK.GEN ELSE
                         CHK.GEN = 1
                      END
                   END
                   READVU LEDL17 FROM LEDLFILE,CHK.OID,17 ELSE
                      LEDL17 = ''
                   END
                   IF LEDL17<1,CHK.GEN> = MANIFEST.ID THEN
                      LEDL17<1,CHK.GEN> = ''
                      WRITEV LEDL17 ON LEDLFILE,CHK.OID,17
                      REMOVE.CMT = 'Aborted from Manifest# ':MANIFEST.ID
                      OE.ADD.COMMENT CHK.OID,CHK.GEN,REMOVE.CMT
                   END ELSE
                      RELEASE LEDLFILE,CHK.OID
                   END
                END
             NEXT II
          NEXT I

          RETURN
*-------------------------------------------------------------------------*
UPDATE.CARTONS: *
          ROOT = CHK.OID
          BSCAN WRK,WKIDS FROM CTN.FILE,ROOT USING '&INDEX&.ORD.ID' ELSE
             WRK = ''
          END
          IF WRK = ROOT THEN
             CCNT = DCOUNT(WKIDS,AM)
             FOR CC = 1 TO CCNT
                READU CTN.REC FROM CTN.FILE,WKIDS<CC> THEN
                   IF CTN.REC<10> = CHK.OID THEN
                      CTN.REC<15> = ''
                      WRITE CTN.REC ON CTN.FILE,WKIDS<CC>
                   END
                END
                RELEASE CTN.FILE,WKIDS<CC>
             NEXT CC
          END

          RETURN
*-------------------------------------------------------------------------*
FILEIT:   *
          BEGIN CASE
          CASE VIEW.ONLY
             USER.LOG.HISTORY 20,MANIFEST.ID
          CASE F12
             IF NEW.MNFST THEN
             IF STRT.TM#MNFST<4> OR FDEL.TM#MNFST<5> OR INTVL#MNFST<6> THEN
                GOSUB RECALC.TIME
             END
             END
             UPDATE.MANIFEST MANIFEST.ID,MNFST,YES,,THIS.ROUTINE:"-9"
*IN$$9:          INP.PROMPT ANS,BELL:'Delete this manifest (Y/N) : ','YN',1
*                IF NEW.MNFST THEN
*                ANS = ''
*                IF ANS THEN
*                   IF MNFST<15> # '' THEN
                      *** Run through each order on the manifest and
*                      *** Remove from ledger log.
*                      STP.CT  = DCOUNT(MNFST<15>,VM)
*                      FOR STP = 1 TO STP.CT
*                         TKT.CT  = DCOUNT(MNFST<15,STP>,SVM)
*                         FOR TKT = 1 TO TKT.CT
*                            OID   = FIELD(MNFST<15,STP,TKT>,'.',1)
*                            INVN  = FIELD(MNFST<15,STP,TKT>,'.',2)
*                            READU LEDLREC FROM LEDLFILE,OID ELSE LEDL.REC = ''
*                            IF LEDLREC # '' THEN
*                               LEDLREC<16> = ''
*                               LEDLREC<17> = ''
*                               WRITE LEDLREC ON LEDLFILE,OID
*                               IF LEN(INVN) = 3 THEN
*                                  READV GENS FROM LEDFILE,OID,8 ELSE GENS = ''
*                               END ELSE
*                                  READV GENS FROM LEDFILE,OID,12 ELSE GENS = ''
*                               END
*                               LOCATE INVN+0 IN GENS<1> SETTING GEN ELSE GEN = 1
*                               REMOVE.CMT='Manifest Aborted. Order Removed from Manifest ':MANIFEST.ID
*                               OE.ADD.COMMENT OID,GEN,REMOVE.CMT
*                            END
*                            RELEASE LEDLFILE,OID
*                         NEXT OID.CT
*                      NEXT STP
*                      UPDATE.MANIFEST MANIFEST.ID,,YES,YES,THIS.ROUTINE:"-8"
*                      MANIFEST.ID = ''
*                   END
*                END ELSE
*                   IF MNFST = '' THEN GOTO START ELSE GOTO INSTTM
*                END
*             END ELSE
*                CONFIRM.ABORT SURE
*                IF NOT(SURE) THEN
*                   IF MNFST = '' THEN GOTO START ELSE GOTO INSTTM
*                END
*             END
*             IF MANIFEST.ID # '' THEN
*                RELEASE MNFSTFILE,MANIFEST.ID

*                GOSUB CHK.LEDL; * Remove man# from LEDGER.LOG records
*             END
          CASE OTHERWISE
             IF STRT.TM#MNFST<4> OR FDEL.TM#MNFST<5> OR INTVL#MNFST<6> THEN
                GOSUB RECALC.TIME
             END
             UPDATE.MANIFEST MANIFEST.ID,MNFST,YES,,THIS.ROUTINE:"-9"
          END CASE

          * Make sure to remove the Manifest ID from LOCKED.LEDS
          IF NOT(VIEW.ONLY) THEN
             LOCATE MANIFEST.ID IN LOCKED.LEDS SETTING POS THEN
                LOCKED.LEDS = DELETE(LOCKED.LEDS,POS)
             END
          END
          *** If manifest id was not passed in (ie from menu) then restart
          IF SV.OMNF.ID = '' THEN
             GOTO RESTART
          END
*-------------------------------------------------------------------------*
*STAGING.LOCATION: STP   = FIELD(LN.IDS<LINE>,'~',1)
*                  TK    = FIELD(LN.IDS<LINE>,'~',2)
*                  TKT   = MNFST<15,STP,TK>
*                  OID   = FIELD(TKT,'.',1)
*                  INVN  = FIELD(TKT,'.',2)
*          READV GENS FROM LEDFILE,OID,8 ELSE GENS = ''
*          LOCATE INVN+0 IN GENS<1> SETTING GEN THEN
*         READVU STAGE.LOC FROM LEDLFILE,OID,22 ELSE STAGE.LOC = ''
*             STAGE.LOC<1,GEN> = STG.LOC
*             WRITEV STAGE.LOC ON LEDLFILE,OID,22
*          END

*          RETURN
*-------------------------------------------------------------------------*
FINISH:   WINDOW.CLOSE
          RETURN
