          SUBROUTINE (PASSER)
** Version# 14.0001[1] - 09/26/2011 - 04:41pm - SMITJR - eclipse


*** Subroutine: CUS.SALES.HIST
*-------------------------------------------------------------------------*
*** This will display the sales history for a given customer for two
*** consecutive years, for the given branches.
*-------------------------------------------------------------------------*
*** Parameters:
***  PASSER - PASSER<1> - customer number                             (IN)
***           PASSER<2> - branch or branches in VM-delimited list     (IN)
*-------------------------------------------------------------------------*
*** Common Vars: NONE
*-------------------------------------------------------------------------*
*** Phantom friendly - no
*** Java friendly - no
*-------------------------------------------------------------------------*

          CHECK.KEY 'CUST.SALES.HIST.ALLOWED',ENTRY.OK
          IF NOT(ENTRY.OK) THEN RETURN

          CN        = PASSER<1>
          BRS       = PASSER<2>
          DFLT.ABC  = PASSER<3>
          PASSER<3> = ''

          ABC.ENABLED = NO
          IF ABC.ENABLED$ THEN
             CT = DCOUNT(BRS,VM)
             FOR I = 1 TO CT
                CTRB.ID = 'ABC.ENABLED~':BRS<1,I>
                READV TMP FROM CTRBFILE,CTRB.ID,1 THEN
                   IF TMP THEN
                      ABC.ENABLED = YES
                      EXIT
                   END
                END
             NEXT I
          END
          IF ABC.ENABLED THEN GOSUB CHECK.ABC

          SCREEN

          *** allow the user to input of a customer ID directly.
          IF CN = '' THEN
             *** set the defalut value
             BRS      = SECURITY<9>
             DFLT.ABC = 1

INCUS:       INP CN,14,1,30,'TENTITY;X;1;1',V_'S:VERF.CUS.ID'
          END

          CHECK.KEY 'SUPERUSER',GP.OK

          MENU.LOAD  2,18,8,1,','
          MENU.LOAD 10,18,7,7,'.'

          YR = OCONV(DATE(),'D4/')[7,4]-1
          GOSUB DISPLAY
          IF QUIT THEN GOTO FINISH

          IF PASSER<1> THEN
INA:         INP A,0,0,0
             IF QUIT THEN GOTO FINISH
             PRINT BELL:
             GOTO INA
          END ELSE
             GOTO INCUS
          END
*-------------------------------------------------------------------------*
FINISH:   WINDOW.CLOSE
          RETURN
*-------------------------------------------------------------------------*
DISPLAY:  READV NAME FROM CUSFILE,CN,1 ELSE NAME = ''
          PRINT @(14,1):NAME  "L#35"

          GOSUB GET.DATA

          ** Display the years at the tops of the columns
          PRINT @(13,2):YR                 "R#4"
          PRINT @(36,2):YR+1               "R#4"

          ** Display the headers for the GP% columns
          IF GP.OK THEN
             PRINT @(25,2):'GP%'
             PRINT @(48,2):'GP%'
          END

          FOR MTH = 1 TO 12
             FOR YRA = 0 TO 1
                PRINT @(7+23*YRA,2+MTH):SLS<YRA+1,MTH> ;* month sales $

                IF GP.OK THEN
                   PRINT @(21+23*YRA,2+MTH):GPS<YRA+1,MTH> ;* month GP%
                END

             NEXT YRA

             ** print the difference in sales for the 2 months
             PRINT @(55,2+MTH):DFFS<MTH>
          NEXT MTH

          ** print total sales $ for the 2 years
          PRINT @(7, 16):T.SLS<1>
          PRINT @(30,16):T.SLS<2>

          IF GP.OK THEN
             ** Print total GP% for the 2 years
             PRINT @(21,16):T.GPS<1>
             PRINT @(44,16):T.GPS<2>
          END

          *** Print the % difference in sales for the 2 years
          PRINT @(55,16):T.DIF

          RETURN
*-------------------------------------------------------------------------*
GET.DATA: *** get the data to display
          CUS.SALES.HIST.GET.DATA CN,BRS,YR,SLS,GPS,DFFS,T.SLS,T.GPS,T.DIF
          RETURN
*-------------------------------------------------------------------------*
SUBS:     ON OPTION GOTO SUB.YR, ADD.YR
*-------------------------------------------------------------------------*
SUB.YR:   YR -= 1
          GOSUB DISPLAY
          RETURN
*-------------------------------------------------------------------------*
ADD.YR:   YR += 1
          GOSUB DISPLAY
          RETURN
*-------------------------------------------------------------------------*
CHECK.ABC:*
          ITEMS      = 'Standard Sales History'
          ITEMS<1,2> = 'Activity Based History'

          IF NOT(DFLT.ABC) THEN
             WORD = ''
             MENU.TABLE WORD,,,1,2,22,,,ITEMS
          END ELSE WORD = ITEMS<1,DFLT.ABC>

          IF WORD[1,1] = 'A' THEN
             CN.STR = PASSER<1>:VM:PASSER<4>; * Cust# and billto only flag
             ABC.CUS.SALES.INQ CN.STR
             RETURN TO LEAVE
          END

LEAVE:    RETURN
*-------------------------------------------------------------------------*
!SMITJR~09/26/11~16:41
