          SUBROUTINE (PASSER)
** Version# 67.0002[1] - 07/05/2012 - 02:28pm - TSMITH - eclipse
** Copied from BP AR.DVR.AGING Version# 67 - 08/03/2011 - 10:28am - EILEENM - main

*** Subroutine - AR.DVR.AGING
*-------------------------------------------------------------------------*
*** The main purpose of the A/R Aging report is to report how much money
*** the User's customers owe their company and how long the money has been
*** owed. It can also shows the date of the customer's last payment and the
*** amount last paid. The field prompts in the Driver let the User modify
*** the report according to the kind and extent of information desired.
*-------------------------------------------------------------------------*
*** PASSER - Customer Information -> @AM1 = Customer#, @AM2 = Level  [IN]
*-------------------------------------------------------------------------*
*** Common Variables: DRPT$
*-------------------------------------------------------------------------*
          * Go initialize the data we'll need to run this program...
          GOSUB INIT
          REENTER.POINT = 2
*-------------------------------------------------------------------------*
HEADER:   *** Standard aging header information regarding branch,dates,etc
          MULTI.ITEM = ''
          GOSUB LOAD.HKEYS
INP.HDR:  AGING.HEADER ASOF,AGDT,HBRCHS,HOPT,SBRCHS,AGP.POS,1,REENTER.POINT
          IF REENTER.POINT > 100 THEN
             OPTION = INT(MOD(REENTER.POINT,100)/10)
             REENTER.POINT = MOD(REENTER.POINT,10)
             GOSUB SUBS
             GOTO INP.HDR
          END
          IF F12 THEN GOTO FINISH
*-------------------------------------------------------------------------*
INCUS:    *** Customer Input
          MULTI.ITEM = 1
          GOSUB LOAD.HKEYS
INPCUS:   INP TCN,29,8,34,'TENTITY;X;9;9',V_'S:VERF.CUS.BT'
          IF F12 THEN GOTO FINISH
          IF CHANGED THEN SLCT.CNS = TCN
          REENTER.POINT = 5
          ON MOVE+1 GOTO INCUS,INCUS,HEADER,INCUS
*-------------------------------------------------------------------------*
INLEVEL:  *** Specifiy the Customer Type you want to display data for
          MULTI.ITEM = ''
          GOSUB LOAD.HKEYS
INLVL:    INP LEVEL,29,9,7,V_'D:,Ship-To,Bill-To,Parent'
          IF F12 THEN GOTO FINISH
          ON MOVE+1 GOTO INLEVEL,INLEVEL,INCUS,INLEVEL
*-------------------------------------------------------------------------*
INCMGR:   *** Credit Manager Input
          MULTI.ITEM = 2
          GOSUB LOAD.HKEYS
INCRD:    INP TSLCTCRD,29,10,34,'MCU',V_'S:VERF.USER.ID'
          IF F12 THEN GOTO FINISH
          IF CHANGED THEN SLCTCRD = TSLCTCRD
          ON MOVE+1 GOTO INCMGR,INCMGR,INLEVEL,INCMGR
*-------------------------------------------------------------------------*
INOPT:    *** Report format Input
          MULTI.ITEM = ''
          GOSUB LOAD.HKEYS
INPOPT:   INP OPT,29,11,10,V_'D:Detail':VM:'Summary':VM:'Unapplied'
          IF CHANGED AND (OPT[1,1] = 'S' OR OPT[1,1] = 'U')THEN
             PRINT @(43,20):'N'
             O.TERMS = NO
          END

          * Use Type 1 for 6 bucket names
          BUCKETS    = AR.AGING.BUCKET.NAMES(1)
          SORT.LIST  = 'D:Customer':VM:LOWER(BUCKETS):VM:'Deposit':VM
          SORT.LIST := 'Home Branch':VM:'Sale Branch':VM:'Balance'

          IF OPT = 'Summary' AND INV.STAT # '' THEN
             ERR.MSG  = 'You must run report in detail if selecting '
             ERR.MSG := 'invoice status codes.'
             ERR.MESS 2,1,BELL:ERR.MSG
             OPT = "Detail"
             PRINT @(29,11):OPT "L#10"
             GOTO INOPT
          END

          IF F12 THEN GOTO FINISH
          IF OPT = 'Summary' THEN RESPECT.BFWD = NO
          ON MOVE+1 GOTO INOPT,INOPT,INCMGR,INOPT
*-------------------------------------------------------------------------*
INSTAT:   *** Status Code Input
          MULTI.ITEM = 3
          GOSUB LOAD.HKEYS
INPSTAT:  INP TINV.STAT,29,12,7,V_'C:VALID.USER.INV.STATUSES,1,2'
          IF F12 THEN GOTO FINISH
          IF CHANGED THEN
             INV.STAT = TINV.STAT
             IF OPT = 'Summary' AND INV.STAT # '' THEN
                ERR.MSG  = 'You must run report in detail if selecting '
                ERR.MSG := 'invoice status codes.'
                INV.STAT = ''; TINV.STAT = ''
                PRINT @(29,12):INV.STAT "L#7"
                GOTO INOPT
             END
          END
          ON MOVE+1 GOTO INSTAT,INSTAT,INOPT,INSTAT
*-------------------------------------------------------------------------*
INTERMS:  *** Customer Terms Code Input
          MULTI.ITEM = 4
          GOSUB LOAD.HKEYS
INPTERMS: INP TTERMS,29,13,14,'MCU',V_'S:VERF.INP.STERMS'
          IF F12 THEN GOTO FINISH
          IF CHANGED THEN TERMS = TTERMS
          ON MOVE+1 GOTO INTERMS,INTERMS,INSTAT,INTERMS
*-------------------------------------------------------------------------*
INVCUR:   *** Customer Currency Input
          MULTI.ITEM = ''
          GOSUB LOAD.HKEYS
INPCUR:   INP VCURR,23,14,6,V_'S:VERF.XCURR.ID.RPTS'
          IF F12 THEN GOTO FINISH
          ON MOVE+1 GOTO INVCUR,INVCUR,INTERMS,INCURR,INSRT
*-------------------------------------------------------------------------*
INCURR:   *** Report Currency Input
INPCURR:  INP XCURR,54,14,6,V_'S:VERF.XCURR.ID'
          IF F12 THEN GOTO FINISH
          ON MOVE+1 GOTO INCURR,INVCUR,INTERMS,INCURR,INORDER
*-------------------------------------------------------------------------*
INSRT:    *** Sort by Input
INPSRT:   INP SORT.BY,23,15,11,V_SORT.LIST
          IF F12 THEN GOTO FINISH
          IF OPT = "Summary" THEN
             BEGIN CASE
             CASE SORT.BY = "Home Branch"
                ERR.MSG  = 'When running the report in Summary mode and '
                ERR.MSG := 'sorting by Home ':AM:'Branch, Home Br must be '
                ERR.MSG := 'included on the report.'
                ERR.MESS 2,1,BELL:ERR.MSG
             CASE SORT.BY = "Sale Branch"
                ERR.MSG  = 'When running the report in Summary mode and '
                ERR.MSG := 'sorting by Sale ':AM:'Branch, Sale Br must be '
                ERR.MSG := 'included on the report.'
                ERR.MESS 2,1,BELL:ERR.MSG
             CASE OTHERWISE; NULL
             END CASE
          END
          ON MOVE+1 GOTO INSRT,INSRT,INVCUR,INORDER,INSC
*-------------------------------------------------------------------------*
INORDER:  *** Sort Order Input
INPORDER: INP SRT.ORDER,54,15,10,V_ORDER.LIST
          IF F12 THEN GOTO FINISH
          ON MOVE+1 GOTO INORDER,INSRT,INCURR,INORDER
*-------------------------------------------------------------------------*
INSC:     *** Service Charges Only Option
INPSC:    INP SERV.CHRG,43,16,7,V_'D:Include':VM:'Exclude':VM:'Only'
          IF QUIT THEN GOTO FINISH
          ON MOVE+1 GOTO INSC,INSC,INSRT,INSC
*-------------------------------------------------------------------------*
INBFWD:   *** Respect Balance Forward Flags Option
INPBFWD:  INP RESPECT.BFWD,43,17,1,'YN'
          IF F12 THEN GOTO FINISH
          ON MOVE+1 GOTO INBFWD,INBFWD,INSC,INBFWD
*-------------------------------------------------------------------------*
INIZBC:   *** Include Zero Balance Customers Option
INPIZBC:  INP IZBC,43,18,1,'YN'
          IF F12 THEN GOTO FINISH
          ON MOVE+1 GOTO INIZBC,INIZBC,INBFWD,INIZBC
*-------------------------------------------------------------------------*
INSRC:    *** Print Activity Comments w/Source Input
INPSRC:   INP ACT.SRC,27,19,10,V_'C:VALID.CUST.SOURCES'
          IF F12 THEN GOTO FINISH
          ON MOVE+1 GOTO INSRC,INSRC,INIZBC,INSRC,INADT,INADT
*-------------------------------------------------------------------------*
INADT:    *** Comments Entered After Date
INPADT:   INP ACT.DT,54,19,10,'VD4/'
          IF OPT[1,1] = 'D' THEN
             ON MOVE+1 GOTO INADT,INADT,INSRC,INADT
          END ELSE
             ON MOVE+1 GOTO INADT,INADT,INSRC,INADT,INADT,INADT
          END
*-------------------------------------------------------------------------*
INTERM:   *** Use terms from order level
          IF OPT[1,1] = 'D' THEN
INPTERM:     INP O.TERMS,43,20,1,'YN'
             IF F12 THEN GOTO FINISH
             ON MOVE+1 GOTO INTERM,INTERM,INADT,INTERM,INTERM,INTERM
          END
*-------------------------------------------------------------------------*
SUBS:     ON OPTION GOTO DOIT,DOIT,DOIT,FSEL,MULTI,COLUMN
*-------------------------------------------------------------------------*
FSEL:     *** Additional Select Criteria Input Window
          FILTER.INPUT "S",FITEM
          RETURN
*-------------------------------------------------------------------------*
DOIT:     *** Validate the Inputs and then run the report...

          REQ.FLDS   = '' ;* Required fields to run
          IF SORT.BY = '' THEN REQ.FLDS<-1> = 'Sort By'
          IF SBRCHS  = '' THEN REQ.FLDS<-1> = 'Sale Branches'
          IF OPT     = '' THEN REQ.FLDS<-1> = 'Report Format'
          IF LEVEL   = '' THEN REQ.FLDS<-1> = 'Customer Level'

          IF REQ.FLDS # '' THEN
             ERR.MESS 8,3,BELL:'Missing Required Field(s):   ':AM:REQ.FLDS
INNADA:      INPNO A,,,0
             BEGIN CASE
             CASE REQ.FLDS<1> = 'Sort By'
                REQ.FLDS = ''
                RETURN TO INSRT
             CASE REQ.FLDS<1> = 'Sale Branches'
                REQ.FLDS = ''
                REENTER.POINT   = 5
                RETURN TO HEADER
             CASE REQ.FLDS<1> = 'Report Format'
                REQ.FLDS = ''
                RETURN TO INOPT
             CASE REQ.FLDS<1> = 'Customer Level'
                REQ.FLDS = ''
                RETURN TO INLEVEL
             END CASE
          END

          * Save user screen data
          IF OPTION < 3 THEN
             UOPTS       = ''
             UOPTS<1,1>  = ASOF
             IF NOT(NUM(AGDT)) THEN UOPTS<1,2> = AGDT
             UOPTS<1,3>  = HOPT
             UOPTS<1,4>  = LEVEL
             UOPTS<1,5>  = OPT
             UOPTS<1,6>  = O.TERMS
             UOPTS<1,7>  = SORT.BY
             UOPTS<1,8>  = SRT.ORDER
             UOPTS<1,9>  = SERV.CHRG
             UOPTS<1,10> = RESPECT.BFWD
             UOPTS<1,11> = IZBC
             SET.SCREEN.INFO 'AR.DVR.AGING','OPTS',UOPTS
          END

          OPT1 = OPT[1,1]
          IF ASOF = '' THEN
             QUICK = YES; ASOFX = DATE()
          END ELSE
             QUICK = NO;  ASOFX = ASOF
          END

          EXTRA.DATA  = LEVEL:VM:RESPECT.BFWD:VM:SORT.BY:VM:SRT.ORDER:VM
          EXTRA.DATA := LOWER(TERMS):VM:LOWER(SLCTCRD):VM:O.TERMS
          EXTRA.DATA := VM:ACT.SRC:VM:ACT.DT:VM:IZBC:VM:HOPT:VM:OPT1

          PHBRS = HBRCHS<2> ;* Home Branch Literal
          PSBRS = SBRCHS<2> ;* Sale Branch Literal
          PH.SETUP.BR.ARGS PHBRS,1,TERR.TYPE,ALL.OK,BRDISP1,BRLIST1
          PH.SETUP.BR.ARGS PSBRS,2,TERR.TYPE,ALL.OK,BRDISP2,BRLIST2

          PH.EXE 'AR.PHR.AGING.BETA',ASOFX,AGDT,BRLIST1,BRDISP1,BRLIST2,BRDISP2,SERV.CHRG,QUICK,INV.STAT,VCURR,XCURR,YES,SLCT.CNS,FITEM,EXTRA.DATA

          IF F12 THEN RETURN

          RETURN TO FINISH
*-----------------------------------------------------------------------*
MULTI:    *** Multiples Input Window for Bill-To Customers, Status Codes,
          *** Credit Managers, or Customer Terms Codes, depending on which
          *** depending on which Input field the cursor is in when the
          *** Multi Hotkey is selected.
          VERIFY  = VERFS<1,MULTI.ITEM>
          CONVERT = CONVS<1,MULTI.ITEM>
          TITLE   = TITLES<1,MULTI.ITEM>
          FLCODE  = FLCODES<1,MULTI.ITEM>

          BEGIN CASE
          CASE MULTI.ITEM = 1; MLIST = SLCT.CNS
          CASE MULTI.ITEM = 2; MLIST = SLCTCRD
          CASE MULTI.ITEM = 3; MLIST = INV.STAT
          CASE MULTI.ITEM = 4; MLIST = TERMS
          CASE OTHERWISE;      MLIST = ''
          END CASE

INPMLIST: INP.MULTI MLIST,35,'L',VERIFY,CONVERT,TITLE,FLCODE

          BEGIN CASE
          CASE MULTI.ITEM = 1; SLCT.CNS = MLIST
          CASE MULTI.ITEM = 2; SLCTCRD  = MLIST
          CASE MULTI.ITEM = 3
             INV.STAT = MLIST
             IF OPT = 'Summary' AND INV.STAT # '' THEN
                ERR.MSG  = 'You must run report in detail if selecting '
                ERR.MSG := 'invoice status codes.'
                ERR.MESS 2,1,BELL:ERR.MSG
                INV.STAT = ''; MLIST = ''
             END
          CASE MULTI.ITEM = 4; TERMS = MLIST
          CASE OTHERWISE; NULL
          END CASE

          IF DCOUNT(MLIST,VM) > 1 THEN
             PRINT.MLIST = '*Multi*'
          END ELSE
             PRINT.MLIST = OCONV(MLIST,CONVS<1,MULTI.ITEM>)
          END

          PRINT @(29,DISP.POS<1,MULTI.ITEM>):PRINT.MLIST FMTS<1,MULTI.ITEM>
          RETURN
*-------------------------------------------------------------------------*
COLUMN:   *** Setup Report Columns
          TITLE = "A/R Aging Report Column Setup"
          REPORT.LAYOUT.V.MAINT TITLE,RECORD.PREFIX,MODIFIED
          RETURN
*-------------------------------------------------------------------------*
INIT:     *** Initialized the data we'll need to run this program...
          *** Call the Driver Screen...
          SCREEN

          DRPT$         = 'Detail A/R Aging'   ;* Standard report vars
          * Make sure report colums are define else abort
          RECORD.PREFIX = "AR.AGING"
          COL.SAVE.ID   = "reports.ar.ARAging"
          DRPT$<62,1>   = COL.SAVE.ID
          DRPT$<62,2>   = RECORD.PREFIX

          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

          * Set the Xpos, Ypos, Lgth for each report
          AGP.POS       = 29:VM:3:VM:10        ;* As of date
          AGP.POS<2>    = 29:VM:4:VM:10        ;* Age as of date
          AGP.POS<3>    = 29:VM:5:VM:34        ;* Home Branches
          AGP.POS<4>    = 29:VM:6:VM:1         ;* Include blank home branch
          AGP.POS<5>    = 29:VM:7:VM:34        ;* Sales branches

          DRPT$<61,1>   = 1                    ;* Allow multi-threading
          DRPT$<61,4>   = 0                    ;* Allow regeneration

          ORDER.LIST    = 'D:Ascending':VM:'Descending'

          * Build arrays for use by our Multi Hotkey subroutine
          VERFS         = 'S:VERF.CUS.BT'
          CONVS         = 'TENTITY;X;9;9'
          TITLES        = 'Multiple Bill-To Customer'
          FLCODES       = 'BTCN'
          DISP.POS      = 8
          FMTS          = "L#34"

          VERFS<1,2>    =  'S:VERF.USER.ID'
          CONVS<1,2>    = 'MCU'
          TITLES<1,2>   = 'Multiple Credit Managers'
          FLCODES<1,2>  = 'CR.MANAGERS'
          DISP.POS<1,2> = 10
          FMTS<1,2>     = "L#34"

          VERFS<1,3>    = 'C:VALID.USER.INV.STATUSES,1,2'
          CONVS<1,3>    = ''
          TITLES<1,3>   = 'Multiple Status Codes'
          FLCODES<1,3>  = 'STAT.CODES'
          DISP.POS<1,3> = 12
          FMTS<1,3>     = "L#7"

          VERFS<1,4>    = 'S:VERF.INP.STERMS'
          CONVS<1,4>    = 'MCU'
          TITLES<1,4>   = 'Multiple Customer Terms Code'
          FLCODES<1,4>  = 'TERMS'
          DISP.POS<1,4> = 13
          FMTS<1,4>     = "L#14"

          READV AUTH.BR.ONLY FROM CTRLFILE,'AR.AP.INQ.BRS',1 ELSE
             AUTH.BR.ONLY = ''
          END
          IF AUTH.BR.ONLY THEN ALL.OK = NO ELSE ALL.OK = YES

          TERR.TYPE = 1          ;* Territory type, allow multi br/terr
          HBRCHS    = ''         ;* Home branch string
          SBRCHS    = ''         ;* Sale branch string
          SLCT.CNS  = PASSER<1>  ;* Bill-To Customer
          SLCTCRD   = ''         ;* Multi credit manager list
          TSLCTCRD  = ''
          INV.STAT  = ''         ;* Invoice status codes
          TINV.STAT = ''
          TERMS     = ''         ;* Customer terms codes
          TTERMS    = ''
          VCURR     = ''         ;* Customer currencey
          XCURR     = ''         ;* Report currencey
          ACT.SRC   = ''         ;* Activity comment source
          ACT.DT    = ''         ;* Activity comment date
          FITEM     = ''         ;* Filtered items

          GET.SCREEN.INFO 'AR.DVR.AGING','OPTS',UOPTS
          IF UOPTS THEN
             ASOF         = UOPTS<1,1>
             AGDT         = UOPTS<1,2>
             HOPT         = UOPTS<1,3>
             IF HOPT = '' THEN HOPT = NO
             LEVEL        = UOPTS<1,4>
             OPT          = UOPTS<1,5>
             O.TERMS      = UOPTS<1,6>
             SORT.BY      = UOPTS<1,7>
             SRT.ORDER    = UOPTS<1,8>
             SERV.CHRG    = UOPTS<1,9>
             RESPECT.BFWD = UOPTS<1,10>
             IZBC         = UOPTS<1,11>
          END ELSE
             ASOF         = ''           ;* As of date
             AGDT         = ''           ;* Age as of date
             HOPT         = YES          ;* Home branch option
             ST.LEVEL     = PASSER<2>    ;* Initial Customer level
             IF TRIM(ST.LEVEL) # '' THEN
                LEVEL = 'Ship-To'
             END ELSE
                LEVEL = 'Bill-To'
             END
             OPT          = 'Summary'    ;* Detail/Summary/Unapplied
             O.TERMS      = NO           ;* Old terms
             SORT.BY      = 'Customer'   ;* Sort by option
             SRT.ORDER    = 'Ascending'  ;* Sort order
             SERV.CHRG    = 'Include'    ;* Service charge option
             RESPECT.BFWD = NO           ;* Respect balance flag
             IZBC         = NO           ;* Incl Zero balance CUS
          END

          IF ASOF = '' THEN
             TASOF = 'All Dates'
          END ELSE
             TASOF = OCONV(ASOF,'D4/')
          END

          IF DCOUNT(SLCT.CNS,VM) > 1 THEN
             TCN = '*Multi*'
          END ELSE
             READV TCN FROM CUSFILE,SLCT.CNS,1 ELSE TCN = SLCT.CNS
          END

          PRINT @(61,0) :REV$:"Save":NORM$:
          PRINT @(29,3) :TASOF                "L#10"
          PRINT @(29,4) :OCONV(AGDT,'D4/')    "L#10"
          PRINT @(29,6) :YN[HOPT+1,1]         "L#1"
          PRINT @(29,8) :TCN                  "L#34"
          PRINT @(29,9) :LEVEL                "L#10"
          PRINT @(29,11):OPT                  "L#10"
          PRINT @(23,15):SORT.BY              "L#11"
          PRINT @(54,15):SRT.ORDER            "L#10"
          PRINT @(43,16):SERV.CHRG            "L#10"
          PRINT @(43,17):YN[RESPECT.BFWD+1,1] "L#1"
          PRINT @(43,18):YN[IZBC+1,1]         "L#1"
          PRINT @(43,20):YN[O.TERMS+1,1]      "L#1"

          RETURN
*-------------------------------------------------------------------------*
LOAD.HKEYS:*** Load the Hotkeys
          MENU.CLEAR
          MENU.LOAD  2,22, 5,1,'P'
          MENU.LOAD 10,22, 4,1,'H'
          MENU.LOAD 17,22, 4,1,'O'
          MENU.LOAD 24,22, 4,1,'S'

          * We'll only allow the Multi Hotkey to be selected if they're
          * in an input that allows multiples
          IF MULTI.ITEM THEN
             MENU.LOAD 31,22,5,1,'M'
          END ELSE
             MENU.LOAD ,,,,
          END

          MENU.LOAD 39,22,6,1,'C'
          RETURN
*-------------------------------------------------------------------------*
FINISH:   *** Close the Report Driver Screen and exit the program...
          WINDOW.CLOSE
          RETURN
*-------------------------------------------------------------------------*
!TSMITH~07/05/12~14:28
