          SUBROUTINE ( CN,MODE,LINE.DATA)
** Version# 7.0001[1] - 08/19/2010 - 05:01pm - SMITJR - eclipse

*** Subroutine - INQ.SUMMARY.DATA
*-------------------------------------------------------------------------*
*** Subroutine to get data for both AR.INQ.SUMMARY and AP.INQ.SUMMARY
*-------------------------------------------------------------------------*
*** CN        - Entity ID                                             [IN]
***              > Vendor   if MODE = A/P
***              > Customer if MODE = A/R
*** MODE      - 'A/R' for AR INQ, 'A/P' for AP INQ                    [IN]
*** LINE.DATA - display data                                         (OUT)
*-------------------------------------------------------------------------*
*** COMMON Variables: CUS, CUSS (reset when done)
*-------------------------------------------------------------------------*
*** JAVA FRIENDLY: YES YES YES
*-------------------------------------------------------------------------*

          CUS.SAVE  = ''
          CUSS.SAVE = ''
          MATBUILD CUSS.SAVE FROM CUSS
          MATBUILD CUS.SAVE FROM CUS

          BEGIN CASE
          CASE MODE = 'A/R'
             GOSUB AR.INIT
             GOSUB AR.GET.DATA
          CASE MODE = 'A/P'
             GOSUB AP.INIT
             GOSUB AP.GET.DATA
          CASE OTHERWISE
             RETURN
          END CASE

          *** Change all null amounts to zero to keep consistency across
          *** all columns in the Inquiry Summary screen in java.
          DATACT = DCOUNT(LINE.DATA,AM)
          FOR DAT = 1 TO DATACT
             FOR LINE.DAT = 4 TO 8
                IF LINE.DATA<DAT,LINE.DAT> = "" THEN
                   LINE.DATA<DAT,LINE.DAT> = 0
                END
             NEXT LINE.DAT
          NEXT CUS.CT

          MATPARSE CUS FROM CUS.SAVE
          MATPARSE CUSS FROM CUSS.SAVE

          RETURN
*-------------------------------------------------------------------------*
AP.INIT:  *** Initialize the data we'll need for retrieving the AP info...
          PT        = GET.PT.AP(CN)
          MATREAD CUS FROM CUSFILE,PT ELSE MAT CUS= ''
          SH.FRS    = CUS(12)
          LINE.DATA = ''
          RETURN
*-------------------------------------------------------------------------*
AP.GET.DATA:***

          READV AUTH.BR.ONLY FROM CTRLFILE,'AR.AP.INQ.BRS',1 ELSE
             AUTH.BR.ONLY = ''
          END

          IF AUTH.BR.ONLY THEN INQ.BRS = SECURITY<9> ELSE INQ.BRS = ''
          MATREAD CUS FROM CUSFILE,PT ELSE MAT CUS = ''
          ASUB.DATA.GET AGT,DTIDS,,,PT,,,INQ.BRS,2
          TOT.AR = SUMMATION(AGT)*(-1)

          LINE.DATA<1,1> = '*'
          LINE.DATA<1,2> = PT:SVM:CUS(9)
          LINE.DATA<1,3> = TOT.AR
          LINE.DATA<1,4> = -AGT<2>
          LINE.DATA<1,5> = -AGT<3>
          LINE.DATA<1,6> = -AGT<4>
          LINE.DATA<1,7> = -AGT<5> - AGT<6>
          LINE.DATA<1,8> = -AGT<1>

          CT = DCOUNT(SH.FRS,VM)
          II = 2
          FOR I = 1 TO CT
             MATREAD CUS FROM CUSFILE,SH.FRS<1,I> ELSE MAT CUS = ''

             *** Make sure we only get data for Orders where the Vendor is
             *** the Ship-From on the Order. This is especially important
             *** for the 2nd line of data on the Summary Screen...
             SHIP.FROM = SH.FRS<1,I>:AM:SH.FRS<1,I>
             ASUB.DATA.GET AGT,DTIDS,,,SHIP.FROM,,,INQ.BRS,2

             TOT.AR = SUMMATION(AGT)*(-1)

             LINE.DATA<II,1> = ''
             LINE.DATA<II,2> = SH.FRS<1,I>:SVM:CUS(9)
             LINE.DATA<II,3> = TOT.AR
             LINE.DATA<II,4> = -AGT<2>
             LINE.DATA<II,5> = -AGT<3>
             LINE.DATA<II,6> = -AGT<4>
             LINE.DATA<II,7> = -AGT<5> - AGT<6>
             LINE.DATA<II,8> = -AGT<1>
             II += 1
NEXTI:    NEXT I

          RETURN
*-------------------------------------------------------------------------*
AR.INIT:  *** Initialize the data we'll need for retrieving the AR info...

          BT        = GET.BT.AR(CN)
          GET.CUS '',BT,CN
          XDATE     = DATE()
          IF CUSS(90) THEN
             XCURR.RATE.GET XRATE,CUSS(90),XDATE
             XRATE  = OCONV(XRATE,'MR4')
             XTYPE  = CUSS(90)
          END ELSE
             XRATE  = 1
             XTYPE  = ''
          END

          SHTOS     = CUS(14)
          LINE.DATA = ''

          RETURN
*-------------------------------------------------------------------------*
AR.GET.DATA:
          READV AUTH.BR.ONLY FROM CTRLFILE,'AR.AP.INQ.BRS',1 ELSE AUTH.BR.ONLY=''
          IF AUTH.BR.ONLY THEN INQ.BRS = SECURITY<9> ELSE INQ.BRS = ''

          ASUB.DATA.GET.PARENT AGT,DTIDS,,,BT,,DATE(),INQ.BRS,1,,,XTYPE
          TOT.AR = SUMMATION(AGT)

          IF (CUS(80)<1,2> # '') THEN
             LINE.DATA<1,1> = '^'
          END ELSE
             LINE.DATA<1,1> = '*'
          END
          LINE.DATA<1,2> = BT:SVM:CUS(9)
          LINE.DATA<1,3> = TOT.AR
          LINE.DATA<1,4> = AGT<2>
          LINE.DATA<1,5> = AGT<3>
          LINE.DATA<1,6> = AGT<4>
          LINE.DATA<1,7> = AGT<5> + AGT<6>
          LINE.DATA<1,8> = AGT<1>

          SAVE.BT = BT
          CT = 0

          CHILDREN = RAISE(RAISE(CUS(80)<1,2>))
          CHILDREN = INSERT(CHILDREN,1;BT)
          CHILD.CT = DCOUNT(CHILDREN,AM)

          II = 2

          FOR CHILD.X =1 TO CHILD.CT

             CH.CN = CHILDREN<CHILD.X>
             BT        = GET.BT.AR(CH.CN)
             GET.CUS '',BT,CH.CN
             IF CUSS(90) THEN
                XCURR.RATE.GET XRATE,CUSS(90),XDATE
                XRATE  = OCONV(XRATE,'MR4')
                XTYPE  = CUSS(90)
             END ELSE
                XRATE  = 1
                XTYPE  = ''
             END

             SHTOS     = CUS(14)

             LOCATE BT IN SHTOS<1> SETTING POS ELSE
                SHTOS = INSERT(SHTOS,1,1;BT)
             END
             II += CT ; * Add the previous number of lines to the display
             CT = DCOUNT(SHTOS,VM)
             FOR I = 1 TO CT
                GET.CUS '',BT,SHTOS<1,I>
                IF I = 1 THEN
                   ASUB.DATA.GET AGT,DTIDS,,,SHTOS<1,I>,,DATE(),INQ.BRS,1,,,XTYPE
                END ELSE
                   ASUB.DATA.GET AGT,DTIDS,,,SHTOS<1,I>:AM:SHTOS<1,I>,,DATE(),INQ.BRS,1,,,XTYPE
                END
                TOT.AR = SUMMATION(AGT)
                IF BT = SHTOS<1,I> THEN
                   LINE.DATA<II,1> = '*'
                END ELSE
                   LINE.DATA<II,1> = ''
                END
                LINE.DATA<II,2> = SHTOS<1,I>:SVM:CUSS(9)
                LINE.DATA<II,3> = TOT.AR
                ***Current
                LINE.DATA<II,4> = AGT<2>
                *** 31-60
                LINE.DATA<II,5> = AGT<3>
                *** 61- 90
                LINE.DATA<II,6> = AGT<4>
                *** over 90
                LINE.DATA<II,7> = AGT<5> + AGT<6>
                *** future
                LINE.DATA<II,8> = AGT<1>
                II += 1
             NEXT I

          NEXT CHILD.X

          RETURN
*-------------------------------------------------------------------------*
!SMITJR~08/19/10~17:01
