          SUBROUTINE (PASSER)
** Version# 3.0002[1] - 06/06/2014 - 09:50am - TSMITH - eclipse
** Copied from BP SOE.DVR.CREDIT.REASON Version# 3 - 05/27/2011 - 04:35pm - NKURTH - main

*** Subroutine: SOE.DVR.CREDIT.REASON
*-------------------------------------------------------------------------*
*** This is the Driver routine for the Credit Reason Report, which
*** summarizes the credits that have been entered into the system along
*** with the reason for their return.
***
*** The Customer and Salesperson/Writer Select options are used to filter
*** the ORIGINAL Sales Order that an item is returned from.
***
*** When the User has specified that they want to see returns where the
*** original Sales Order was from the warehouse AND where the orinal order
*** was a Direct, the data will be broken out separately for both.
*** Anotherwords, if Customer X returned items from two separate orders,
*** where one was a Direct and the other was sold from the warehouse,
*** there would be one line on the report for the Direct order and one for
*** the warehouse sale. There will also be two subtotal lines, one for the
*** Direct and one for the warehouse sale.
***
*** Since the User has the option of 'Page Breaking' on Sort by, 'Grand
*** Totals' for the report are not printed. Instead the report prints a
*** 'Sales Source Summary' for the whole report, which is essentially the
*** same thing, just displayed in a different manner.
*-------------------------------------------------------------------------*
*** Parameter: PASSER (Not used).                                    (IN)
*-------------------------------------------------------------------------*
*** COMMON Variables Used: DRPT$
*-------------------------------------------------------------------------*

          *** Go load all the data that we need for this program...
          GOSUB INIT

*-------------------------------------------------------------------------*
INBR:     *** The Branch/TR/All Input...

          MFIELD = ''

IN$$1:    INP.BR 15,3,10,BR,NAME,BRCHS,TERR.TYPE
          IF F12 THEN GOTO FINISH
          ON MOVE+1 GOTO INBR,INBR,INBR,INBR
*-------------------------------------------------------------------------*
INSD:     *** Start Date Input...

          MFIELD = ''

IN$$2:    INP SD,15,4,10,'VD4/'
          IF F12 THEN GOTO FINISH
          IF ED = '' THEN
             ED = SD
             PRINT @(15,5):OCONV(ED,'D4/')
          END
          ON MOVE+1 GOTO INSD,INSD,INBR,INSD
*-------------------------------------------------------------------------*
INED:     *** End Date Input...

          MFIELD = ''

IN$$3:    INP ED,15,5,10,'VD4/'
          IF F12 THEN GOTO FINISH
          ON MOVE+1 GOTO INED,INED,INSD,INED
*-------------------------------------------------------------------------*
INSLCT:   *** Select and Sort by Input...

          MFIELD = ''

          *** Go deactive the Multi Hotkey...
          GOSUB LOAD.HKEYS

IN$$4:    INP SLCT,24,6,19,V_'D:':SLCT.OPTS

          IF F12 THEN GOTO FINISH

          IF CHANGED THEN
             *** Clear out the Salesperson/Writer Entity in case one
             *** was alread selected...
             SLIST = ''
             PRINT @(24,7):SLIST "L#22"

             PRINT @(2,7) :SLCT  "L#19"
          END

          SMV = 0
          IF SLCT THEN
             LOCATE SLCT IN MFIELDS SETTING SMV ELSE GOTO INSLCT
          END ELSE
             PRINT BELL:; GOTO INSLCT
          END

          ON MOVE+1 GOTO INSLCT,INSLCT,INED,INSLCT
*-------------------------------------------------------------------------*
INSLIST:  *** Inside/Outside Salesperson or Writer Input...

          MFIELD = MFIELDS<SMV>

          *** Go activate the Multi Hotkey...
          GOSUB LOAD.HKEYS

IN$$5:    INP TSLIST,24,7,22,CONVERT<SMV>,V_VERIFY<SMV>

          IF F12 THEN GOTO FINISH

          IF CHANGED THEN
             SLIST            = TSLIST
             SELECT.ITEM<SMV> = SLIST
          END

          ON MOVE+1 GOTO INSLIST,INSLIST,INSLCT,INSLIST
*-------------------------------------------------------------------------*
INPGBK:   *** Page Break on Sort by Input...

          MFIELD = ''

          *** Go deactive the Multi Hotkey in case we're coming in
          *** here from the Salesperson/Writer Entity Input...
          GOSUB LOAD.HKEYS

IN$$6:    INP PG.BREAK,29,8,1,'YN'

          IF F12 THEN GOTO FINISH

          ON MOVE+1 GOTO INPGBK,INPGBK,INSLIST,INPGBK
*-------------------------------------------------------------------------*
INBS:     *** Customer Level Input...

          MFIELD = ''

          *** Go deactive the Multi Hotkey in case we're coming in
          *** here from the Customer Entity Input...
          GOSUB LOAD.HKEYS

IN$$7:    INP LEVEL,29,9,7,V_'D:Ship-To':VM:'Bill-To'

          IF F12 THEN GOTO FINISH

          IF CHANGED THEN
             *** Clear out the Customer Entity if one was already selected.
             CUSLIST = ''
             PRINT @(29,10):CUSLIST "L#27"

             PRINT @(2,10) :LEVEL   "L#7"
          END

          BSMV = 0
          IF LEVEL THEN
             LOCATE LEVEL IN MFIELDS SETTING BSMV ELSE GOTO INBS
          END ELSE
             PRINT BELL:; GOTO INBS
          END

          ON MOVE+1 GOTO INBS,INBS,INPGBK,INBS
*-------------------------------------------------------------------------*
INCUS:    *** Customer Input...

          MFIELD = MFIELDS<BSMV>

          *** Go activate the Multi Hotkey...
          GOSUB LOAD.HKEYS

IN$$8:    INP TCUS,29,10,27,CONVERT<BSMV>,V_VERIFY<BSMV>

          IF F12 THEN GOTO FINISH

          IF CHANGED THEN
             CUSLIST           = TCUS
             SELECT.ITEM<BSMV> = CUSLIST
          END

          ON MOVE+1 GOTO INCUS,INCUS,INBS,INCUS
*-------------------------------------------------------------------------*
INSOURCE: *** Sales Source option - Warehouse, Direct or Both...

          MFIELD = ''

          *** Go deactive the Multi Hotkey...
          GOSUB LOAD.HKEYS

IN$$9:    INP SOURCE,29,11,9,V_'D:Warehouse':VM:'Direct':VM:'Both'

          IF F12 THEN GOTO FINISH

          ON MOVE+1 GOTO INSOURCE,INSOURCE,INCUS,INSOURCE,INSOURCE,INSOURCE
*-------------------------------------------------------------------------*
SUBS:     ON OPTION GOTO DOIT,DOIT,DOIT,FSEL,MULTI
*------------------------------------------------------------------------*
DOIT:     * Validate the Inputs and run the report...

          *** Validate the Start and End Dates...
          REQ.FLDS = ''
          IF NUM(SD) AND NUM(ED) THEN
             *** If they haven't entered an End Date...
             IF ED + 0 < 1 THEN
                REQ.FLDS<-1> = 'End Date'
             END ELSE
                IF SD > ED THEN
                   ERR.MESS 4,1,BELL:' Start Date must be before End Date'
                   RETURN TO INSD
                END
             END

             *** If they haven't entered a Start Date...
             IF SD + 0 < 1 THEN REQ.FLDS<-1> = 'Start Date'
          END

          IF SOURCE = '' THEN REQ.FLDS<-1> = 'Warehouse/Direct/Both'

          IF REQ.FLDS # '' THEN

             ERR.MESS 8,3,BELL:'Missing Required Field(s):  ':AM:REQ.FLDS

IN$$10:      INPNO A,,,0

             BEGIN CASE
             CASE REQ.FLDS<1> = 'Start Date'            ;RETURN TO INSD
             CASE REQ.FLDS<1> = 'End Date'              ;RETURN TO INED
             CASE REQ.FLDS<1> = 'Warehouse/Direct/Both' ;RETURN TO INSOURCE
             END CASE
          END

          PH.SETUP.BR.ARGS BR,,TERR.TYPE,,BRDISP,BRLIST

          *** Generate the report...
          PH.EXE 'SOE.PHR.CREDIT.REASON.GPS',BRLIST,BRDISP,SD,ED,SLCT,SLIST,PG.BREAK,LEVEL,CUSLIST,SOURCE,FITEM

          IF F12 THEN RETURN

          RETURN TO FINISH
*-------------------------------------------------------------------------*
MULTI:    * Multiples Input Window...

          LOCATE MFIELD IN MFIELDS SETTING MPOS THEN
             VERF   = VERIFY<MPOS>
             CONV   = CONVERT<MPOS>
             MTITLE = 'Multiple ':MFIELDS<MPOS>
             FLCODE = FLCODES<MPOS>

IN$$11:      INP.MULTI SELECT.ITEM<MPOS>,99,'L',VERF,CONV,MTITLE,FLCODE

             *** Redisplay what was selected to the Driver...

             IF DCOUNT(SELECT.ITEM<MPOS>,VM) > 1 THEN
                PRINT @(HORIZNTL<MPOS>,VERTICLE<MPOS>):'*Multi*' FMTS<MPOS>
             END ELSE
                SEL.ITEM = OCONV(SELECT.ITEM<MPOS>,CONVERT<MPOS>)
                PRINT @(HORIZNTL<MPOS>,VERTICLE<MPOS>):SEL.ITEM FMTS<MPOS>
             END

             IF MPOS < 4 THEN
                SLIST   = SELECT.ITEM<MPOS>
             END ELSE
                CUSLIST = SELECT.ITEM<MPOS>
             END
          END

          RETURN
*-------------------------------------------------------------------------*
FSEL:     *** Additional Select Criteria...
          FILTER.INPUT "S",FITEM
          RETURN
*-------------------------------------------------------------------------*
INIT:     * Load all the data that we need for this program....

*** Load the screen this program uses...
          SCREEN

*** Initialize our variables...
          DRPT$       = 'Credit Reason Report'

          *** For our Branch/Territory Input, we'll allow the User to
          *** enter multiple Branches & multiple Territories...
          TERR.TYPE   = 1

          SD          = DATE()
          ED          = SD
          SLCT        = 'Outside Salesperson'
          SLIST       = ''
          PG.BREAK    = YES
          LEVEL       = 'Bill-To'
          CUSLIST     = ''
          SOURCE      = 'Both'
          SELECT.ITEM = ''
          FITEM       = ''
          MFIELD      = ''

*** Go load our Hotkeys...
          GOSUB LOAD.HKEYS

*** Print the defaults to the screen...
          PRINT @(15, 4):OCONV(SD,'D4/')  "L#10"
          PRINT @(15, 5):OCONV(ED,'D4/')  "L#10"
          PRINT @(24, 6):SLCT             "L#19"
          PRINT @(2 , 7):SLCT             "L#19"
          PRINT @(29, 8):'Y'              "L#1"
          PRINT @(29, 9):LEVEL            "L#7"
          PRINT @(2 ,10):LEVEL            "L#7"
          PRINT @(29,11):SOURCE           "L#9"

*** 'Select and Sort by' validation list...
          SLCT.OPTS  = 'Writer':VM:'Inside Salesperson':VM
          SLCT.OPTS := 'Outside Salesperson'

*** Build arrays for use by the 'Multi Items' Hotkey...
          *** The Value they're entering Multiples for...
          MFIELDS     = 'Outside Salesperson'
          MFIELDS<2>  = 'Inside Salesperson'
          MFIELDS<3>  = 'Writer'
          MFIELDS<4>  = 'Bill-To'
          MFIELDS<5>  = 'Ship-To'
          *** What to use to validate the Inputs...
          VERIFY      = 'S:VERF.SALESMAN'
          VERIFY<2>   = 'S:VERF.SALESMAN'
          VERIFY<3>   = 'INITIALS'
          VERIFY<4>   = 'S:VERF.CUS.BT'
          VERIFY<5>   = 'S:VERF.CUS.ST'
          *** How to Convert the Inputs...
          CONVERT     = ''
          CONVERT<2>  = ''
          CONVERT<3>  = ''
          CONVERT<4>  = 'TENTITY;X;9;9'
          CONVERT<5>  = 'TENTITY;X;9;9'
          *** Code to use for storing 'recall' lists...
          FLCODES     = 'SP'
          FLCODES<2>  = 'SP'
          FLCODES<3>  = 'WRITER'
          FLCODES<4>  = 'BT'
          FLCODES<5>  = 'ST'
          *** The Verticle Line where results will reprint on the Driver...
          VERTICLE    = 7
          VERTICLE<2> = 7
          VERTICLE<3> = 7
          VERTICLE<4> = 10
          VERTICLE<5> = 10
          *** The Horizontal Line where results will reprint on the Driver
          HORIZNTL    = 24
          HORIZNTL<2> = 24
          HORIZNTL<3> = 24
          HORIZNTL<4> = 29
          HORIZNTL<5> = 29
          *** Formats to use when reprinting values to the Driver...
          FMTS        = "L#19"
          FMTS<2>     = "L#19"
          FMTS<3>     = "L#19"
          FMTS<4>     = "L#27"
          FMTS<5>     = "L#27"

          RETURN
*-------------------------------------------------------------------------*
LOAD.HKEYS: * Load our Hotkeys...

          MENU.CLEAR

          MENU.LOAD  2,13,5,1,'P'
          MENU.LOAD 10,13,4,1,'H'
          MENU.LOAD 17,13,4,1,'O'
          MENU.LOAD 24,13,4,1,'S'
          IF MFIELD THEN
             MENU.LOAD 31,13,5,1,'M'
          END ELSE
             MENU.LOAD ,,,,
          END

          RETURN
*-------------------------------------------------------------------------*
FINISH:   *** Close our Driver window and exit the program...
          WINDOW.CLOSE
          RETURN
*-------------------------------------------------------------------------*
!TSMITH~06/06/14~09:50
