          SUBROUTINE (HDR,TITLE,WDTH,HDR.VARS,COL.RECORD)
** Version# 0.0002[30] - 10/18/2013 - 10:48am - TSMITH - eclipse
*** V0.0002 Change - Custom Coding CUSTOM - 10/18/2013 - TSMITH - eclipse
** Copied from BP AR.AGING.BUILD.HDR Version# 5 - 09/21/2009 - 01:22pm - MIKEF - main

*** Subroutine: AR.AGING.BUILD.HDR
*-------------------------------------------------------------------------*
*** Simple routine to build the header for an AR Aging report
*-------------------------------------------------------------------------*
*** HDR        - Built header                                    [OUT]
*** WDTH       - Calculated width of the report to be output     [OUT]
*** HDR.VARS   - Any variables needed to build the report header [IN]
*** COL.RECORD - Column definition record                        [IN]
*-------------------------------------------------------------------------*
*** Common Variables: None used
*-------------------------------------------------------------------------*
          GOSUB LOAD.VARS

          HDR = DET:" Sam's Aging Report by ":REAL.LEVEL:' as of: ':ASOF

          BEGIN CASE
          CASE SRV.CHRG.TYP = 'O'
             HDR := ' - ** Service Charges Only **'
          CASE SRV.CHRG.TYP = 'E'
             HDR := ' - ** Excluding Service Charges **'
          CASE OTHERWISE; NULL
          END CASE

          IF OPT = 'U' THEN HDR := ' - ** Unapplied C/R Only **'

          IF STATS THEN
             STATS.HDR = ' - Status: '
             IF DCOUNT(STATS,VM) > 1 THEN
                STATS.HDR := '*Multi*'
             END ELSE
                STATS.HDR := STATS
             END
             HDR := STATS.HDR
          END

          HDR<1,2> = 'Home Branches: ':HBRS:'; Sale Branches: ':SBRS
          HDR<1,3> = SRT.ORDER:' Sort by: ':SORT.BY

          IF ACT.DT THEN
             IF ACT.SRC THEN
                HDR<1,3> := "; Activity Comments with Source: ":ACT.SRC
                HDR<1,3> := " Entered After: ":OCONV(ACT.DT,'D4/')
             END ELSE
                HDR<1,3> := "; Activity Comments Entered After: "
                HDR<1,3> := OCONV(ACT.DT,'D4/')
             END
          END

          BEGIN CASE
          CASE CURR.FLG AND VCURR
             HDR<1,3> := ' - Report Currency:  ':XCURR
             HDR<1,3> := ' - Customer Currency:  ':VCURR
          CASE VCURR
             HDR<1,3> := ' - Customer Currency:  ':VCURR
          CASE CURR.FLG
             HDR<1,3> := ' - Report Currency:  ':XCURR
          END CASE

          * Build the column headings...
          IF DETAIL THEN
             COL.HDG  = 'ID.... Customer............ Limit.. '
             COL.HDG := 'Srv.. Inv Date.. Invoice#...... '
          END ELSE
             COL.HDG  = 'Days... ':'Customer.......................Srv '
          END

          REPORT.LAYOUT.V.PRINT.STR '','H',COL.RECORD,'',COL.HDG
          COL.HDG = LOWER(COL.HDG)

          IF NOT(DETAIL) THEN
             COL.HDG := '  Credit Limit.Terms'
          END

          * Determine the width of our report based on the column
          * headings we'll be displaying. Use the last value mark data
          * as any column headings are longer than what they are allocated
          * to then the headings will wrap and that data will be in
          * the value mark positions
          WDTH = LEN(COL.HDG<1,DCOUNT(COL.HDG,VM)>)

          IF TERMS THEN
             HDR3.LENGTH  = LEN(HDR<1,3>)
             HDR3.ALLOWED = WDTH - HDR3.LENGTH - 30
             HDR<1,3>    := ' - Customer Terms Code(s): '
             HDR<1,3>    := HDR.TERMS[1,HDR3.ALLOWED]
             IF HDR.TERMS[1,HDR3.ALLOWED] # HDR.TERMS THEN
                HDR<1,3> := '...'
             END
          END

          * If Credit Managers have been selected then add then to our
          * heading...
          IF SLCT.CRD # '' THEN
             CRD.MGRS = SLCT.CRD
             CONVERT VM TO ',' IN CRD.MGRS

             * Calculate the max width for what we can display of the
             * selected Credit Managers...
             MAX.CMGRS   = WDTH - 20

             IF LEN(CRD.MGRS) > MAX.CMGRS THEN
                CRD.MGRS = CRD.MGRS[1,MAX.CMGRS]:'...'
             END
             HDR<1,4> := 'Credit Managers: ':CRD.MGRS<1,1>
             LN = 5
          END ELSE LN = 4

          * Now add the column headings to the header...
          HDR<1,LN>   = COL.HDG

          * Tack the page number onto the first line of our Heading...
          HDR1.LNGTH = LEN(HDR<1,1>)

          * Only print enough data to match maximum width of page
          IF WDTH > MAX.WDTH THEN WDTH = MAX.WDTH

          * Prevent the Page numbers from printing off the page
          * This will accommidate printing in landscape or portrait layouts
          IF WDTH > MAX.PAGE.WDTH THEN
             PAGE.WDTH = MAX.PAGE.WDTH
          END ELSE PAGE.WDTH = WDTH

          * Setup the page counter to fit in portrait layout
          HDR<1,1> := SPACE(PAGE.WDTH - HDR1.LNGTH - 12):'Page :^#####'

          IF DRPT.TITLE = '' THEN
             TITLE = DET:" Sam's Aging Report for ":HBRS
          END ELSE
             TITLE = DRPT.TITLE
          END
          RETURN
*-------------------------------------------------------------------------*
LOAD.VARS:*** Load vars needed to build header
          MAX.WDTH      = 223
          MAX.PAGE.WDTH = 132

          DETAIL       = HDR.VARS<1>
          LEVEL        = HDR.VARS<2>
          * Mask for display purposes
          REAL.LEVEL = LEVEL
          IF LEVEL[1,1] = 'P' THEN
             LEVEL = 'Bill-To'
          END

          ASOF         = HDR.VARS<3>
          SRV.CHRG.TYP = HDR.VARS<4>
          STATS        = HDR.VARS<5>
          HBRS         = HDR.VARS<6>
          SBRS         = HDR.VARS<7>
          SRT.ORDER    = HDR.VARS<8,1>
          SORT.BY      = HDR.VARS<8,2>
          ACT.DT       = HDR.VARS<9,1>
          ACT.SRC      = HDR.VARS<9,2>
          CURR.FLG     = HDR.VARS<10,1>
          VCURR        = HDR.VARS<10,2>
          XCURR        = HDR.VARS<10,3>
          TERMS        = HDR.VARS<11>
          SLCT.CRD     = HDR.VARS<12>
          OPT          = HDR.VARS<13>
          DRPT.TITLE   = HDR.VARS<14>
          SRV.CHG      = HDR.VARS<15>
          IF DETAIL THEN DET = 'Detail' ELSE DET = 'Summary'
          HDR.TERMS = TERMS
          CONVERT VM TO ',' IN HDR.TERMS
          RETURN
*-------------------------------------------------------------------------*
!TSMITH~10/18/13~10:48
