          SUBROUTINE (PASSER)
** Version# 94.0002[4] - 08/24/2012 - 11:52am - TSMITH - eclipse
*** V94.0002 Change - Custom Coding . - 08/24/2012 - TSMITH - eclipse
** Copied from BP INV.DVR.INV.VALUE Version# 94 - 08/25/2011 - 12:15pm - EILEENM - main

*** Subroutine - INV.DVR.INV.VALUE
*-------------------------------------------------------------------------*
*** This is the Driver routine for running the Inventory Valuation report,
*** which is used to show the value of a products within a Price or Buy
*** Line, a group of Price or Buy Lines, or all Price or Buy Lines
*** within one or more Branches.
*-------------------------------------------------------------------------*
***           !!! IMPORTANT NOTE WHENEVER MAKING CHANGES !!!
*** This routine will call one of TWO Phantom routines for running the
*** report. When the 'Cost Basis' is set to 'FIFO-COST' the
*** FIFO.PHR.INV.VALUE routine will be called. For any other Cost Basis,
*** the INV.PHR.INV.VALUE routine will be called. It is very important
*** that any enhancements or bug-fixes are incorporated into BOTH phantom
*** routines, when applicable.
*-------------------------------------------------------------------------*
*** PASSER - System Queue ID                                          (IN)
*-------------------------------------------------------------------------*
*** COMMON Variables Used: DRPT$
*-------------------------------------------------------------------------*

          SCREEN

          *** Go initialize the variables we'll need to run this program...
          GOSUB INIT
*-------------------------------------------------------------------------*
*** Branch Input...
INBR:     INP.BR 15,3,10,BR,NAME,BRCHS,TERR.TYPE
          IF F12 THEN GOTO FINISH
          ON MOVE+1 GOTO INBR,INBR,INBR,INBR
*-------------------------------------------------------------------------*
*** As of Date Input...
INAOD:    INP AOD,62,3,10,'VD4/'
          IF F12 THEN GOTO FINISH
          ON MOVE+1 GOTO INAOD,INBR,INBR,INAOD
*-------------------------------------------------------------------------*
*** Select by Input...
INSLCT:   MULTI.ACTIVE = ''
          GOSUB LOAD.HOTKEYS
IN$$4:    INP SLCT,15,4,20,V_'D:':SEL.LIST
          PRINT @(2,5):SLCT "L#11"
          IF F12 THEN GOTO FINISH

          IF CHANGED THEN
             SLIST = ''
             PRINT @(15,5):SPACE(22)
          END

          SMV = 0
          IF SLCT THEN
             LOCATE SLCT IN SEL.LIST<1> SETTING SMV ELSE GOTO INSLCT
          END

          *** Go load our hotkeys...
          GOSUB LOAD.HOTKEYS

          IF SLCT # '' THEN
             ON MOVE+1 GOTO INSLCT,INSLCT,INAOD,INSLCT
          END ELSE
             ON MOVE+1 GOTO INSLCT,INSLCT,INAOD,INSLCT,INCAOD,INCAOD
          END
*-------------------------------------------------------------------------*
*** Select by 'Entity' Input...
INSLIST:  MULTI.ACTIVE = 1
          GOSUB LOAD.HOTKEYS
IN$$9:    INP TSLIST,15,5,22,SEL.CONV<1,SMV>,V_SEL.VALD<SMV>
          IF CHANGED THEN SLIST = TSLIST
          MULTI.ACTIVE = ''
          GOSUB LOAD.HOTKEYS

          IF F12 THEN GOTO FINISH
          ON MOVE+1 GOTO INSLIST,INSLIST,INSLCT,INSLIST
*-------------------------------------------------------------------------*
*** Cost As of Date Input...
INCAOD:   INP CAOD,20,6,10,'VD4/'
          IF F12 THEN GOTO FINISH
          IF SLCT # '' THEN
             ON MOVE+1 GOTO INCAOD,INCAOD,INSLIST,INCAOD
          END ELSE
             ON MOVE+1 GOTO INCAOD,INCAOD,INSLCT,INCAOD
          END
*-------------------------------------------------------------------------*
*** Detail/Summary Input...
INDET:    *
          RPT.TYPS = 'Summary':VM:'Summary by Branch':VM:'Summary by Branch (No Totals)'
          RPT.TYPS:= VM:'Summary by Product':VM:'Detail':VM:'Detail by Branch'
IN$$7:    INP DET,20,7,30,V_'D:':RPT.TYPS
          IF F12 THEN GOTO FINISH

          ON MOVE+1 GOTO INDET,INDET,INCAOD,INSRT,INSRT,INSRT
*-------------------------------------------------------------------------*
*** Sort by Line/Prod GL Code Input...
INSRT:    INP SORTBY,29,8,12,V_'D:':SORTBY.OPTS
          IF F12 THEN GOTO FINISH
          ON MOVE+1 GOTO INSRT,INSRT,INDET,INSRT
*-------------------------------------------------------------------------*
*** Group by Product Ranks Input...
INGROUP:  INP GROUP.RANKS,29,9,1,'YN'

          IF F12 THEN GOTO FINISH

          *** If they're not Grouping by Product Ranks, we have to
          *** Subtotal on the sortby...
          IF NOT(GROUP.RANKS) THEN
             SUBT.ON.SORTBY = YES
             PRINT @(29,10):'Y' "L#1"
          END

          IF GROUP.RANKS AND DET # 'Detail' THEN
             GROUP.MSG   = 'Can only Group by Product Ranks for Detail '
             GROUP.MSG  := 'Report'
             ERR.MESS 15,5,GROUP.MSG
             GROUP.RANKS = NO
             PRINT @(29,9):'N'
          END

          ON MOVE+1 GOTO INGROUP,INGROUP,INSRT
*-------------------------------------------------------------------------*
*** Subtotal on Sort by option...
INSUBT:   INP SUBT.ON.SORTBY,29,10,1,'YN'

          IF F12 THEN GOTO FINISH

          IF NOT(SUBT.ON.SORTBY) AND NOT(GROUP.RANKS) THEN
             SSMSG  = 'Must Subtotal on Sort by when ':AM
             SSMSG := 'Not Grouping by Product Ranks!'
             ERR.MESS 23,5,SSMSG
             SUBT.ON.SORTBY = YES
             PRINT @(29,10):'Y'
          END

          ON MOVE+1 GOTO INSUBT,INSUBT,INGROUP
*-------------------------------------------------------------------------*
*** Nonstocks (Inc/Exc/Only) Input...
INEXNS:   INP EX.NS,29,11,10,V_'D:Include':VM:'Exclude':VM:'Only'
          IF F12 THEN GOTO FINISH
          ON MOVE+1 GOTO INEXNS,INEXNS,INSUBT,INEXNS
*-------------------------------------------------------------------------*
*** Only Detail for Extended Values > Input...
INEXZ:    INP EXT.AMT,38,12,6,'R'
          IF F12 THEN GOTO FINISH
          ON MOVE+1 GOTO INEXZ,INEXZ,INEXNS,INEXZ
*-------------------------------------------------------------------------*
*** Neg On-Hand Qtys (Inc/Exc/Only) Input...
INNEG:    INP NEG,38,13,7,V_'D:Include':VM:'Exclude':VM:'Only'
          IF F12 THEN GOTO FINISH
          ON MOVE+1 GOTO INNEG,INNEG,INEXZ,INNEG
*-------------------------------------------------------------------------*
*** Quantity Types Input...
INQTYP:   INP QTYPES,38,14,17,V_'*1D:,':VALID.TYPES
          IF F12 THEN GOTO FINISH

          GOSUB DISP.QTYPES

          ON MOVE+1 GOTO INQTYP,INQTYP,INNEG,INQTYP,INZERO,INZERO
*-------------------------------------------------------------------------*
*** Zero On-Hand Qtys (Inc/Exc) Input...
INZERO:   INP ZERO,38,15,7,V_'D:Include':VM:'Exclude'
          IF F12 THEN GOTO FINISH
          IF BASIS.OPT = "FIFO" THEN
             ON MOVE+1 GOTO INZERO,INZERO,INQTYP,INZERO,INZERO,INZERO
          END ELSE
             ON MOVE+1 GOTO INZERO,INZERO,INQTYP,INZERO
          END
*-------------------------------------------------------------------------*
*** Show $0 Average Costs input.. If Average Cost is 0, use REP-COST
INAVG:    INP AVG.CST,38,16,1,'YN'
          IF F12 THEN GOTO FINISH
          ON MOVE+1 GOTO INAVG,INAVG,INZERO,INAVG
*-------------------------------------------------------------------------*
*** Inventory Account to Include
INPACCT:  MULTI.ACTIVE = 2
          GOSUB LOAD.HOTKEYS
INPACCT1: INP INV.ACCT,38,17,20,'TGENLED;X;3;3',V_'S:VERF.GL,ALL~INVP~~1~1'
          IF CHANGED THEN INV.ACCT.LIST = INV.ACCT
          MULTI.ACTIVE = ''
          GOSUB LOAD.HOTKEYS

          IF F12 THEN GOTO FINISH
          ON MOVE+1 GOTO INPACCT,INPACCT,INAVG,INPACCT,INPACCT,INPACCT
*-------------------------------------------------------------------------*
SUBS:     ON OPTION GOTO DOIT,DOIT,DOIT,MULTI,INRANKS,ADDLSEL,COLUMN,LAYOUT,DOIT
*-------------------------------------------------------------------------*
DOIT:     * Validate the Inputs and call the Phantom to run the report...

*** Check for any blank required fields...
          REQ.FLDS        = ''
          IF AOD          = '' THEN REQ.FLDS<-1> = 'As of Date'
          IF SLCT         = '' THEN REQ.FLDS<-1> = 'Select by'
          IF DET          = '' THEN REQ.FLDS<-1> = 'Detail/Summary'
          IF SORTBY       = '' THEN REQ.FLDS<-1> = 'Sort by'
          IF EX.NS        = '' THEN REQ.FLDS<-1>='Nonstocks (Inc/Exc/Only)'
          IF NEG          = '' THEN
             REQ.FLDS<-1> = 'Neg On-Hand Qtys (Inc/Exc/Only)'
          END
          IF ZERO         = '' THEN
             REQ.FLDS<-1> = 'Zero On-Hand Qtys (Inc/Exc/Only)'
          END

          IF REQ.FLDS # '' THEN
             ERR.MESS 8,3,BELL:'Missing Required Field(s): ':AM:REQ.FLDS
IN$$5:       INPNO A,,,0

             BEGIN CASE
             CASE REQ.FLDS<1> = 'As of Date'
                REQ.FLDS = ''
                RETURN TO INAOD
             CASE REQ.FLDS<1> = 'Select by'
                REQ.FLDS = ''
                RETURN TO INSLCT
             CASE REQ.FLDS<1> = 'Detail/Summary'
                REQ.FLDS = ''
                RETURN TO INDET
             CASE REQ.FLDS<1> = 'Sort by'
                REQ.FLDS = ''
                RETURN TO INSRT
             CASE REQ.FLDS<1> = 'Nonstocks (Inc/Exc/Only)'
                REQ.FLDS = ''
                RETURN TO INEXNS
             CASE REQ.FLDS<1> = 'Neg On-Hand Qtys (Inc/Exc/Only)'
                REQ.FLDS = ''
                RETURN TO INNEG
             CASE REQ.FLDS<1> = 'Zero On-Hand Qtys (Inc/Exc/Only)'
                REQ.FLDS = ''
                RETURN TO INZERO
             END CASE
          END
          * If there is no cost basis on user's report then don't allow
          * report to run.
          IF BASIS.OPT = "NONE" THEN
             MSG = 'There is no Cost Basis selected on report!'
             ERR.MESS 8,3,BELL:MSG,YES
             RETURN TO INBR
          END

          * Check if they have selected all Consignments...
          SV.OPTION = OPTION
          IF (VCSGN = 'Only' OR CCSGN = 'Only') AND CCN = '' THEN
             VAR    = ''
             MSG    = 'Are you sure you want all Consignments (Y/N) : '
IN$$2:       INP.PROMPT VAR,BELL:MSG,'YN',1
             IF NOT(VAR) THEN
                START.IN.ENTITY = YES
                GOSUB ADDLSEL
                START.IN.ENTITY = NO
                RETURN TO INBR
             END
          END

          IF SV.OPTION = 9 THEN
             * Do not allow extract to be run for more than one branch
             IF DCOUNT(BRCHS,VM) > 1 THEN
                MSG  = 'Inventory Modeling Extract cannot be run for more '
                MSG := 'than one branch!'
                ERR.MESS 8,3,BELL:MSG
IN$$11:         INPNO A,,,0
                RETURN TO INBR
             END

             * Do not allow extract to be run for FIFO-COST
             IF BASIS.OPT = "FIFO" OR BASIS.OPT = "BOTH" THEN
                MSG = 'Inventory Modeling Extract cannot be run for '
                MSG:= 'FIFO-COST!'
                ERR.MESS 8,3,BELL:MSG,YES
                RETURN TO INBR
             END

             * Do not allow extract to be run for multiple Cost Basis.
             IF MULTI.NON.FIFO = YES THEN
                MSG = 'Inventory Modeling Extract cannot be run for '
                MSG:= 'multiple Cost Basis!'
                ERR.MESS 8,3,BELL:MSG,YES
                RETURN TO INBR
             END

          END

*** Build valid parameters for passing our variables...
          *** If QTYPES is NULL, set to ALL by default
          IF QTYPES = '' THEN
             QTYPES = ALL.QTYPES
          END

          *** Make our Price/Buy Line data part of the same parameter...
          SEL.DATA      = LOWER(SLIST)
          SEL.DATA<1,2> = SLCT

          *** Make our Consignment data part of the same parameter...
          ADDL.DATA        = VCSGN
          ADDL.DATA<1,1,2> = CCSGN
          ADDL.DATA<1,1,3> = CCN
          ADDL.DATA<1,1,4> = VPBK
          ADDL.DATA<1,1,5> = CPBK
          ADDL.DATA<1,1,7> = VPRC
          ADDL.DATA<1,1,8> = HIST.YEARS
          ADDL.DATA<1,1,9> = INCL.ADJ

          IF VCSGN = 'Only' THEN QTYPES = 'V'
          IF CCSGN = 'Only' THEN QTYPES = 'C'
          IF VCSGN = 'Include' THEN
             LOCATE 'V' IN QTYPES<1> SETTING QTPOS ELSE
                QTYPES<1,-1> = 'V'
             END
          END
          IF CCSGN = 'Include' THEN
             LOCATE 'C' IN QTYPES<1> SETTING QTPOS ELSE
                QTYPES<1,-1> = 'C'
             END
          END

          INC.EXC.DATA         = ''
          INC.EXC.DATA<1,1>    = EX.NS
          INC.EXC.DATA<1,2>    = NEG
          INC.EXC.DATA<1,3>    = ZERO

          GROUP.RANK.DATA = ''
          GROUP.RANK.DATA<1,1> = GROUP.RANKS
          GROUP.RANK.DATA<1,2> = SUBT.ON.SORTBY

          *** If the User has just selected the 'Print' or 'Hold'
          *** Hotkeys...
          IF SV.OPTION < 3 THEN
             IF SQ.ID THEN
                PH.DEL.ARGS ARG.ERR,SQ.ID
                IF ARG.ERR THEN
                   ERR.MESS 8,3,BELL:ARG.ERR
                   RETURN
                END
             END

             *** If they want to 'Group by Product Ranks' but they have
             *** also selected the FIFO-COST Cost Basis, we need to prompt
             *** them for a single Branch to use...
             IF GROUP.RANKS AND (BASIS.OPT = "FIFO" OR BASIS.OPT = "BOTH") THEN
                *** Not specifying a starting column and row
                *** number will center our window...
                WINDOW ,,51,3,3
                FIFO.MSG  = 'Branch to Use for Grouping by Product Ranks: '
                PRINT @(1,1):FIFO.MSG:FIFO.BR
INFIFO.BR:      INP.BR 46,1,4,FIFO.BR,FIFO.NAME,FIFO.BRCHS
                IF NOT(FIFO.BR) AND NOT(F12) THEN
                   PRINT BELL:; RETURN TO INFIFO.BR
                END
                WINDOW.CLOSE
                IF F12 THEN RETURN
                GROUP.RANK.DATA<1,3> = FIFO.BR
             END

             * Save users options
             UOPTS       = ''
             IF NOT(NUM(AOD))  THEN UOPTS<1,1>  = AOD
             UOPTS<1,2>  = SLCT
             IF NOT(NUM(CAOD)) THEN UOPTS<1,4>  = CAOD
             UOPTS<1,5>  = DET
             UOPTS<1,7>  = SORTBY
             UOPTS<1,8>  = GROUP.RANKS
             UOPTS<1,9>  = SUBT.ON.SORTBY
             UOPTS<1,10> = EX.NS
             UOPTS<1,11> = EXT.AMT
             UOPTS<1,12> = NEG
             UOPTS<1,13> = ZERO
             UOPTS<1,15> = AVG.CST
             UOPTS<1,17> = LOWER(INV.ACCT.LIST)
             SET.SCREEN.INFO 'INV.DVR.INV.VALUE.LM','OPTS',UOPTS
             SET.SCREEN.INFO 'INV.DVR.INV.VALUE.LM','ADDL',ADDL.DATA
          END

          OPTION    = SV.OPTION
          MISC.DATA = ANY.ALL:VM:VM:LOWER(INV.ACCT.LIST):VM:AVG.CST

          IF SV.OPTION = 9 THEN
             * Force report to be run in Detail
             DET = 'Detail'

             * Set flag to generate the XML file
             MISC.DATA<1,5> = 'XML'

             * Set flag indicating that the user has outbound email.
             UT.SEC3 22,OUTBOUND.EMAIL

             IF OUTBOUND.EMAIL THEN
                RESP  = 'E'
                PRMPT = 'Send extract via Email or Holdfile? (E/H): '
IN$$12:         INP.PROMPT RESP,PRMPT,'MCU',1,'D:E':VM:'H'

                IF RESP = 'E' THEN
                   MISC.DATA<1,6> = OUTBOUND.EMAIL

                   * Get email information
                   READV EMAIL.ADDR FROM INIFILE,USER.ID,55 ELSE
                      EMAIL.ADDR = ''
                   END

                   MSG.DT     = OCONV(AOD,'D4/')
                   O.BODY     = ''
                   PASSER     = ''
                   PASSER<1>  = EMAIL.ADDR
                   PASSER<5>  = 'Inventory Modeling: Br ':BR:'  ':MSG.DT
                   PASSER<10> = 1

                   LOOP
                      EMAIL.SEND PASSER,O.BODY
                      IF F12 THEN EXIT

                      IF PASSER<1> THEN
                         EXIT
                      END ELSE
                         MSG = 'Email Address must be entered!'

                         ERR.MESS 8,3,BELL:MSG
IN$$10:                  INPNO A,,,0
                      END
                   REPEAT

                   IF F12 THEN RETURN

                   PASSER    = LOWER(PASSER)
                   DRPT$<57> = O.BODY
                   DRPT$<58> = PASSER
                END
             END
          END

          PH.SETUP.BR.ARGS BR,,TERR.TYPE,,BRDISP,BRLIST
          PH.EXE PROG.NAMES,BRLIST,BRDISP,AOD,SEL.DATA,LOWER(BASIS.LIST),DET,SORTBY,EXT.AMT,INC.EXC.DATA,QTYPES,CAOD,ADDL.DATA,RANKS,MISC.DATA,GROUP.RANK.DATA

          IF F12 THEN RETURN

          RETURN TO FINISH
*-------------------------------------------------------------------------*
MULTI:    * This is a window for inputting Multiple Selection
          BEGIN CASE
          CASE MULTI.ACTIVE = 1
             BEGIN CASE
             CASE SLCT = 'Price Line'
                PHYS.PLINE.SELECT SLIST
             CASE SLCT = 'Buy Line'
                PHYS.BLINE.SELECT SLIST
             CASE OTHERWISE
                MTITLE = 'Multiple ':SLCT
IN$$3:          INP.MULTI SLIST,99,'L',SEL.VALD<SMV>,SEL.CONV<1,SMV>,MTITLE
             END CASE

             GOSUB DISP.SLIST

          CASE MULTI.ACTIVE  = 2
IN$$8:       INP.MULTI INV.ACCT.LIST,99,'L','S:VERF.GL,ALL~INVP~~1~1','TGENLED;X;3;3','Inventory Accounts'

             GOSUB DISP.ACCT.LIST

          END CASE

          RETURN
*-------------------------------------------------------------------------*
INRANKS:  * Product Rank Input Window...
          RANK.INPUT RANKS,ANY.ALL
          RETURN
*-------------------------------------------------------------------------*
ADDLSEL:  *** Call the Input Screen for Consignment Criteria...

          INV.VALUE.ADDL.SEL VCSGN,VPBK,CCSGN,CPBK,CCN,START.IN.ENTITY,HIST.YEARS,INCL.ADJ,BASIS.OPT,VPRC

          RETURN
*-------------------------------------------------------------------------*
COLUMN:   *** Setup Report Columns
          TITLE = "Inventory Valuation Report"
          REPORT.LAYOUT.V.MAINT TITLE,RECORD.PREFIX,MODIFIED
          RETURN
*-------------------------------------------------------------------------*
LAYOUT:   ***
          PH.EXE.GET.UD.COLUMNS COL.SAVE.ID,RECORD.PREFIX,YES,ABORTED,COL.RECORD
          IF ABORTED THEN RETURN
          GOSUB SETUP.LAYOUT
          GOSUB GET.CBASIS.SEL
          RETURN
*-------------------------------------------------------------------------*
INIT:     *** Set up variables

          * Make sure report colums are define else abort
          RECORD.PREFIX = "INV.VALUE"
          REPORT.V.COL.GET.DATA RECORD.PREFIX,'*DEFAULT',DEFAULT.RECORD
          IF DEFAULT.RECORD = '' THEN
             ERR.MSG = 'No column default data exists for this report'
             ERR.MESS 2,1,BELL:ERR.MSG,YES
             RETURN TO FINISH
          END

          * Setup program names info for phantom processing.
          PROG.NAMES = ''
          PROG.NAMES<1,1> = 'INV.PHR.INV.VALUE.LM'
          PROG.NAMES<1,2> = 'INV.DVR.INV.VALUE.LM'
          PROG.NAMES<1,3> = 'com.eclipseinc.reports.purchase.InventoryValuationReport'

          SEL.LIST       = 'Buy Line'
          SEL.VALD       = 'S:VERF.BLNE.ID'
          SEL.CONV       = ''
          SEL.LIST<1,2>  = 'Buy Group'
          SEL.VALD<2>    = 'PRICE-GRP,1'
          SEL.LIST<1,3>  = 'Price Line'
          SEL.VALD<3>    = 'PRICE.LINE'
          SEL.LIST<1,4>  = 'Sell Group'
          SEL.VALD<4>    = 'PRICE-GRP,1'
          SEL.LIST<1,5>  = 'Product'
          SEL.VALD<5>    = 'S:VERF.PRD.ID'
          SEL.CONV<1,5>  = 'TPRODUCT;X;1;1'



          FCODE          = ''
          FCODE<1,5>     = 'PNLIST'

          SORTBY.OPTS  = 'Price Line':VM:'Buy Line':VM:'Sell Group':VM
          SORTBY.OPTS := 'Buy Group':VM:'Prod GL Code':VM:'Prod ID'

          VALID.TYPES  = 'S - Stock':VM:'F - DeFective':VM
          VALID.TYPES := 'O - Over Shipment':VM:'R - Review':VM
          VALID.TYPES := 'L - DispLay':VM:'T - Tagged'

          ALL.QTYPES = ''
          QCNT = DCOUNT(VALID.TYPES,VM)
          FOR X = 1 TO QCNT
             ALL.QTYPES<1,X> = VALID.TYPES<1,X>[1,1]
          NEXT X

          TERR.TYPE       = 1
          MULTI.ACTIVE    = ''
          MULTI.NON.FIFO  = NO
          START.IN.ENTITY = NO

          SQ.ID = '' ;* System Queue id
          IF PASSER THEN
             UT.OPEN.FILE 'SYSTEM.QUEUE',SQFILE,ERR.MSG
             IF ERR.MSG THEN RETURN
             READV TEST.NAMES FROM SQFILE,PASSER,2 ELSE TEST.NAMES = ''
             IF TEST.NAMES<1,1> = PROG.NAMES<1,1> THEN SQ.ID = PASSER
          END

          IF SQ.ID THEN
             GOSUB RECALLSQ
             IF ERR.MSG THEN
                ERR.MESS ,,ERR.MSG,YES
                GOTO FINISH
             END
          END ELSE
             COL.SAVE.ID = "reports.purchase.InventoryValuationReport"
             DRPT$       = 'Inven Value Report'
             DRPT$<62,1> = COL.SAVE.ID
             DRPT$<62,2> = RECORD.PREFIX
             BRCHS       = ''
             BR          = ''
             QTYPES      = ''
             RANKS       = ''
             ANY.ALL     = ''
             SLIST       = ''
             FIFO.BR     = ''

             * Typically this routine would not be called by report driver
             * directly. However, the Inventory Valuation Report must know
             * what columns will be included on it when the driver loads.
             PH.EXE.GET.UD.COLUMNS COL.SAVE.ID,RECORD.PREFIX,NO,ABORTED,COL.RECORD
             IF ABORTED THEN
                MSG  = "A column layout must be selected":AM
                MSG := "to setup the report."
                MESS ,,MSG,YES
                RETURN TO FINISH
             END

             GOSUB SETUP.LAYOUT
             GOSUB GET.CBASIS.SEL

             LOCATE 'INVTY' IN GL.AUTO<1> SETTING POS THEN
                GLID = GL.AUTO<2,POS,1>
             END ELSE
                GLID = ""
             END

             * Get users last options
             GET.SCREEN.INFO 'INV.DVR.INV.VALUE.LM','OPTS',UOPTS
             IF UOPTS THEN
                AOD             = UOPTS<1,1>
                IF AOD = '' THEN AOD = DATE()
                SLCT            = UOPTS<1,2>
                CAOD            = UOPTS<1,4>
                IF CAOD = '' THEN CAOD = DATE()
                DET             = UOPTS<1,5>
                SORTBY          = UOPTS<1,7>
                GROUP.RANKS     = UOPTS<1,8>
                SUBT.ON.SORTBY  = UOPTS<1,9>
                EX.NS           = UOPTS<1,10>
                EXT.AMT         = UOPTS<1,11>
                NEG             = UOPTS<1,12>
                ZERO            = UOPTS<1,13>
                AVG.CST         = UOPTS<1,15>
                INV.ACCT.LIST   = RAISE(UOPTS<1,17>)
             END ELSE
                AOD              = DATE()
                SLCT            = ''
                CAOD            = DATE()
                DET             = 'Summary'
                SORTBY          = 'Price Line'
                GROUP.RANKS     = ''
                SUBT.ON.SORTBY  = YES
                EX.NS           = 'Include'
                EXT.AMT         = ''
                NEG             = 'Include'
                ZERO            = 'Include'
                AVG.CST         = NO
                INV.ACCT.LIST   = GLID
             END

             GET.SCREEN.INFO 'INV.DVR.INV.VALUE.LM','ADDL',ADDL.DATA
             IF ADDL.DATA THEN
                VCSGN      = ADDL.DATA<1,1,1>
                CCSGN      = ADDL.DATA<1,1,2>
                CCN        = ADDL.DATA<1,1,3>
                VPBK       = ADDL.DATA<1,1,4>
                CPBK       = ADDL.DATA<1,1,5>
                VPRC       = ADDL.DATA<1,1,7>
                HIST.YEARS = ADDL.DATA<1,1,8>
                IF HIST.YEARS = '' THEN HIST.YEARS = 5
                INCL.ADJ   = ADDL.DATA<1,1,9>
             END ELSE
                VCSGN      = ''
                IF BASIS.OPT = "FIFO" THEN
                   CCSGN   = 'Exclude'
                END ELSE
                   CCSGN   = 'Include'
                END
                CCN        = ''
                VPBK       = NO
                VPRC       = NO
                CPBK       = NO
                HIST.YEARS = 5
                INCL.ADJ   = NO
             END
          END

          GOSUB DISPLAY
          GOSUB LOAD.HOTKEYS

          RETURN
*-------------------------------------------------------------------------*
RECALLSQ: *** Recall System Queue defaults.

          PH.READ.ARGS ERR.MSG,SQ.ID,RPT.DFLT,USR.ID,BRLIST,BRDISP,AOD,SEL.DATA,BASIS.LIST,DET,SORTBY,EXT.AMT,INC.EXC.DATA,QTYPES,CAOD,ADDL.DATA,RANKS,MISC.DATA,GROUP.RANK.DATA

          DRPT$         = RPT.DFLT
          COL.RECORD    = RAISE(DRPT$<56>)
          COL.SAVE.ID   = DRPT$<62,1>
          RECORD.PREFIX = DRPT$<62,2>

          GOSUB SETUP.LAYOUT
          GOSUB GET.CBASIS.SEL

          * Setup branch/territory list
          IF BRLIST[1,8] = "$BRLIST$" THEN
             ARGS     = ''
             ARGS<3>  = USR.ID
             ARGS<10> = BRLIST
             ARGS<11> = BRDISP
             PH.PARSE.BR.LIST ARGS
             BR    = ARGS<11> ;* branch display
             BRCHS = ARGS<10> ;* branch list
          END ELSE
             BR    = BRDISP
             BRCHS = BRLIST
          END

          SLIST = RAISE(SEL.DATA<1,1>)
          SLCT  = SEL.DATA<1,2>
          EX.NS = INC.EXC.DATA<1,1>
          NEG   = INC.EXC.DATA<1,2>
          ZERO  = INC.EXC.DATA<1,3>

          * Adjust Qty Types.
          * Remove vendor/customer consignment stock types. They are
          * added back later in DOIT if ventory/customer consignment
          * is set to Only or Include.
          LOCATE 'V' IN QTYPES<1> SETTING QTPOS THEN
             QTYPES = DELETE(QTYPES,1,QTPOS)
          END
          LOCATE 'C' IN QTYPES<1> SETTING QTPOS THEN
             QTYPES = DELETE(QTYPES,1,QTPOS)
          END
          * If all qty types set to null (Null=All)
          IF QTYPES = ALL.QTYPES THEN
             QTYPES = ''
          END

          VCSGN          = ADDL.DATA<1,1,1>
          CCSGN          = ADDL.DATA<1,1,2>
          CCN            = ADDL.DATA<1,1,3>
          VPBK           = ADDL.DATA<1,1,4>
          CPBK           = ADDL.DATA<1,1,5>
          VPRC           = ADDL.DATA<1,1,7>
          HIST.YEARS     = ADDL.DATA<1,1,8>
          INCL.ADJ       = ADDL.DATA<1,1,9>

          GROUP.RANKS    = GROUP.RANK.DATA<1,1>
          SUBT.ON.SORTBY = GROUP.RANK.DATA<1,2>
          FIFO.BR        = GROUP.RANK.DATA<1,3>

          ANY.ALL        = MISC.DATA<1,1>
          INV.ACCT.LIST  = RAISE(MISC.DATA<1,3>)
          AVG.CST        = MISC.DATA<1,4>

          RETURN
*-------------------------------------------------------------------------*
DISPLAY:  *** Display screen

          PRINT @(69,0) :REV$:"Save":NORM$:
          PRINT @(15,3) :BR                     "L#10"
          PRINT @(62,3) :OCONV(AOD,'D4/')       "L#10"
          PRINT @(15,4) :SLCT                   "L#20"
          PRINT @(2,5)  :SLCT                   "L#11"

          GOSUB DISP.SLIST

          PRINT @(20,6) :OCONV(CAOD,'D4/')      "L#10"
          PRINT @(20,7) :DET                    "L#30"
          PRINT @(29,8) :SORTBY                 "L#12"
          PRINT @(29,9) :YN[GROUP.RANKS+1,1]    "L#1"
          PRINT @(29,10):YN[SUBT.ON.SORTBY+1,1] "L#1"
          PRINT @(29,11):EX.NS                  "L#10"
          PRINT @(38,12):EXT.AMT                "L#10"
          PRINT @(38,13):NEG                    "L#10"

          GOSUB DISP.QTYPES

          PRINT @(38,15):ZERO                   "L#10"
          PRINT @(38,16):YN[AVG.CST+1,1]        "L#1"

          GOSUB DISP.ACCT.LIST

          PRINT @(44,20):'Addl Sel'
          PRINT @(55,20):'ColumN'

          * See if they are authorized for Inventory Modeling.
          UT.SEC3 81,INV.MODEL.OK
          IF INV.MODEL.OK THEN
             PRINT @(64,20):'Extract  '
          END

          RETURN
*-------------------------------------------------------------------------*
DISP.SLIST:*** Display select by list

          IF DCOUNT(SLIST,VM) > 1 THEN
             TSLIST = '*Multi*'
          END ELSE
             TSLIST = SLIST
          END

          PRINT @(15,5):TSLIST "L#22"

          RETURN
*-------------------------------------------------------------------------*
DISP.ACCT.LIST:*** Display inventory accounts list

          INV.ACCT = INV.ACCT.LIST
          IF DCOUNT(INV.ACCT,VM) > 1 THEN
             INV.ACCT = '*Multi*'
          END ELSE
             INV.ACCT = OCONV(INV.ACCT.LIST,'TGENLED;X;3;3')
          END
          PRINT @(38,17):INV.ACCT "L#22"

          RETURN
*-------------------------------------------------------------------------*
DISP.QTYPES:*** Display quantity types

          BEGIN CASE
          CASE QTYPES = 'S'; QTYP = 'S - Stock'
          CASE QTYPES = 'F'; QTYP = 'F - DeFective'
          CASE QTYPES = 'O'; QTYP = 'O - Over Shipment'
          CASE QTYPES = 'R'; QTYP = 'R - Review'
          CASE QTYPES = 'L'; QTYP = 'L - DispLay'
          CASE QTYPES = 'T'; QTYP = 'T - Tagged'
          CASE OTHERWISE   ; QTYP = ''
          END CASE

          PRINT @(38,14):QTYP 'L#17'

          RETURN
*-------------------------------------------------------------------------*
SETUP.LAYOUT: *** Sets DRPT$<56> with the column layout value and
          *** displays the layout on the screen.

          DRPT$<56> = LOWER(COL.RECORD)
          PRINT @(1,0):REV$:"Column Layout:":NORM$ COL.RECORD<4,1>:NORM$
          LAYOUT.LEN = LEN(COL.RECORD<4,1>)
          PRINT @(15,0):REV$:COL.RECORD<4,1>:NORM$
          PRINT @(15+LAYOUT.LEN,0):STR("Í",(35-LAYOUT.LEN))

          RETURN
*-------------------------------------------------------------------------*
LOAD.HOTKEYS: *** Load hotkeys
          MENU.CLEAR

          MENU.LOAD  2,20, 5,1,'P'      ;* Print
          MENU.LOAD 10,20, 4,1,'H'      ;* Hold
          MENU.LOAD 17,20, 4,1,'O'      ;* Opts
          IF MULTI.ACTIVE THEN
             MENU.LOAD 24,20, 5,1,'M'   ;* Multi
          END ELSE
             MENU.LOAD ,,,,
          END
          MENU.LOAD 32,20,9,6,'R'       ;* Prod Rank
          IF BASIS.OPT = "NONE" THEN
             MENU.LOAD ,,,,
          END ELSE
             MENU.LOAD 44,20,8,1,'A'    ;* Addl Sel
          END
          IF SQ.ID THEN
             MENU.LOAD ,,,,
             MENU.LOAD ,,,,
             MENU.LOAD ,,,,
          END ELSE
             MENU.LOAD 55,20,5,1,'C'    ;* Column Setup
             MENU.LOAD 60,20,1,1,"N"    ;* Column Layout Selection
             IF INV.MODEL.OK THEN
                MENU.LOAD 64,20,7,1,'E' ;* Extract
             END
          END

          RETURN
*-------------------------------------------------------------------------*
GET.CBASIS.SEL: *** Get the cost basis' that are on the user's report

          FIFO.FOUND     = NO
          NON.FIFO.FOUND = NO
          MULTI.NON.FIFO = NO
          BASIS.OPT  = "NONE"
          BASIS.LIST = ""

          INV.VAL.GET.COST.BASIS "",BASIS.LIST,DRPT$<56>

          BCNT = DCOUNT(BASIS.LIST,AM)
          IF BCNT > 0 THEN
             FINDSTR "1001" IN BASIS.LIST SETTING FPOS,X,Y THEN
                IF ((X = 1) AND (Y = 1)) THEN
                   FIFO.FOUND = YES
                   BCNT-=1
                END
             END
          END

          IF BCNT > 0 THEN
             NON.FIFO.FOUND = YES
          END

          IF NON.FIFO.FOUND THEN
             IF BCNT > 1 THEN
                MULTI.NON.FIFO = YES
             END
          END

          BEGIN CASE
             CASE FIFO.FOUND AND NON.FIFO.FOUND
                BASIS.OPT = "BOTH"
             CASE FIFO.FOUND AND NOT(NON.FIFO.FOUND)
                BASIS.OPT = "FIFO"
             CASE NOT(FIFO.FOUND) AND NON.FIFO.FOUND
                BASIS.OPT = "NON-FIFO"
          END CASE

          RETURN
*-------------------------------------------------------------------------*
FINISH:   *** Close our window and exit the subroutine...
          WINDOW.CLOSE
          RETURN
*-------------------------------------------------------------------------*
!TSMITH~08/24/12~11:52
