          SUBROUTINE (BRCHS,BNK.ID,F.TYPE,SD,ED,VN,DOC.ID,VN.TYP)
** Version# 11.0001[30] - 01/10/2014 - 03:43pm - TSMITH - eclipse
*** V11.0001 Change - Custom Coding . - 01/10/2014 - TSMITH - eclipse

*** Subroutine: CD.ECHK.PREVIEW
*-------------------------------------------------------------------------*
*** This routine is designed to display a list of EFT checks that met the
*** selection criteria the user entered to transmit to the bank.
*-------------------------------------------------------------------------*
*** BRCHKS    - Branch                                       (IN)
*** BNK.ID    - Bank ID                                      (IN)
*** F.TYPE    - Form Type                                    (IN)
*** SD        - Start Post Date                              (IN)
*** ED        - End Post Date                                (IN)
*** VN        - Vendor Id                                    (IN)
*** DOC.ID    - Document ID used by Java to preview report   (OUT)
*** VN.TYP    - Vendor Type                                  (IN)
*-------------------------------------------------------------------------*
*** COMMON VARIABLE: None specified
*-------------------------------------------------------------------------*
          *** Open EFT.STAGING file, this is the file that hold all the
          *** checks that are ready to be released to the bank

          *** Solar does not do conversion to upper case
          VN.TYP = OCONVS(VN.TYP,'MCU')
          UT.OPEN.FILE 'EFT.STAGING',ESTGFILE,ERR.MSG
          IF ERR.MSG THEN RETURN
          DELIM = CHAR(44)
          IDS         = ''           ;* List of all check ID, disbursements
          GTOL.APPR   = 0            ;* Grand Total Approved Amt
          GTOL.DEDUCT = 0            ;* Grand Total Deduction Amt
          GTOL.DISC   = 0            ;* Grand Total Discount Amt
          BR.LST      = BRCHS        ;* A list of valid branches
          SORT.IDS    = ''           ;* Temp array for sorting

          CONVERT VM TO ',' IN BR.LST

          *** Allow user to select between viewing or printing the report
          VP = 'V'
          IF NOT(JAVA.PROC$) THEN
IN$$2:       INP.PROMPT VP,'<V>iew or <P>rint : ',,1,'D:V':VM:'P'
             IF F12 THEN RETURN
             WINDOW ,,40,3,3
             COMPILE.MSG = 'Compiling Report.... Please Wait... '
             PRINT @(0,1):BLINK$:COMPILE.MSG:NORM$
          END


          *** Select recs from the EFT.STAGING file and check each one to
          *** see if it meets the users criteria.
          GOSUB SEL.IDS

          *** Set up the heading for this report
          *HDG  = 'Check Preview Report for ':OCONV(SD,'D4/'):' to '
          *HDG := OCONV(ED,'D4/')
          *HDG<1,2>  = 'Branches : ':BR.LST
          HDG<1,3>  = 'Check #':DELIM:'Vendor Name':DELIM
          HDG<1,3> := 'Invoice #':DELIM:'Inv Date':DELIM:'Apprv Amt':DELIM
          HDG<1,3> := 'Deduct Amt':DELIM:'Disc Amt':DELIM:'PayOn':DELIM:'DiscDate':DELIM
          HDG<1,3> := 'Amt to Pay'

          WDTH      = LEN(HDG<1,3>)
          HDG1.WDTH = LEN(HDG<1,1>)
          *** Tack the page number onto the first line of our heading...
          HDG<1,1> := SPACE(WDTH - HDG1.WDTH - 13):'Page : ^#####'

          PRINTER.ON WDTH,'EFT Check Preview',DOC.ID,HDG

          *** Print out each of the disbursement rec, checks, that met the
          *** user's criteria,
          CHK.CT   = DCOUNT(IDS,AM)
          FOR CHK  = 1 TO CHK.CT
             C.IDS = IDS<CHK>
             GOSUB PRINT.ONE
          NEXT CHK

          *** Print out the grand totals for the approved amounts, deduct
          *** amounts, and the discount amounts
          GOSUB PRT.GTOTALS

          IF VP = 'V' THEN LOCA = 'HOLD' ELSE LOCA = LOCATION

          PRINTER.OFF DOC.ID,LOCA

          IF NOT(JAVA.PROC$) THEN
             WINDOW.CLOSE
          END

          ** If this is a java proc, simply hold the file.  Don't delete
          ** it or view it.
          IF VP = 'V' THEN
             IF NOT(JAVA.PROC$) THEN
                VIEW.PRINT DOC.ID
        *        SPOOLER.DELETE DOC.ID
             END
          END

          GOTO FINISH
*-------------------------------------------------------------------------*
PRINT.ONE: *** Print out each of the disbursement rec, checks, that met the
           *** user's criteria,
          TOL.APPR   = 0       ;* Total Approved Amt
          TOL.DEDUCT = 0       ;* Total Deduction Amt
          TOL.DISC   = 0       ;* Total Discount Amt

          FIRST.LN   = YES     ;* Flag to indicate in first line

          *** Read the AR file of the disbursement ID to get all necessary
          *** data, like check amount, discount, etc
          READ ARREC FROM ARFILE,C.IDS ELSE ARREC = ''
          IF FIRST.LN THEN
             *** Print the EFT check number
             ECHK.NO = FIELD(ARREC<1>,'~',2)
             CONVERT 'E' TO '' IN ECHK.NO
             PRINT 'E':ECHK.NO                  "R%6":DELIM:

             *** Print the Vendor name
             VEN.NM  = ARREC<10>
             READV VNAME FROM CUSFILE,VEN.NM,1 ELSE VNAME = ''
             CONVERT "," TO " " IN VNAME
             PRINT VNAME                        :DELIM:
          END ELSE
             PRINT SPACE(36):
          END

          PAY.IDS = ARREC<2>
          PAY.CT  = DCOUNT(PAY.IDS,VM)
          FOR PCT = 2 TO PAY.CT
             ONE.PAY = FIELD(PAY.IDS<1,PCT>,'.',2,2)
             READ PAR FROM ARFILE,ONE.PAY ELSE PAR = ''

             *** Get the invoice number
             INV.NUM = PAR<1>

             *** Get the invoice date
             LDID = FIELD(ONE.PAY,'.',1)
             READV INV.DT FROM LEDFILE,LDID,10 ELSE INV.DT = ''

             DISC.DT = PAR<11>    ;* Discount Date

             *** If foreign check, use foreign amounts
             IF PAR<31,1,1> THEN
                AR.AMTS      = RAISE(PAR<33,1>)
                AR.AMTS<1,4> = PAR<21,4>
             END ELSE
                AR.AMTS      = PAR<21>
             END

             CIDS = AR.AMTS<1,4>
             CCT  = DCOUNT(CIDS,SVM)
             FOR CID.POS = 1 TO CCT
                IF C.IDS = CIDS<1,1,CID.POS> THEN
                   PAY.DT   = PAR<22,CID.POS>        ;* Pay On Date
                   DEDUCT   = AR.AMTS<1,3,CID.POS>   ;* Deduct Amt
                   DISC.AMT = AR.AMTS<1,2,CID.POS>   ;* Discount Amt
                   PAY.AMT  = AR.AMTS<1,1,CID.POS>   ;* Pay Amt

                   GOSUB PRT.LN
                END
             NEXT CID.POS
          NEXT PCT

          TOL  = TOL.APPR - TOL.DISC - TOL.DEDUCT
          *PRINT SPACE(47):'CHECK # E':ECHK.NO"R%6":' ---':


          *PRINT TOL.APPR    "R26#12":
          *PRINT TOL.DEDUCT  "R26#12":
          *PRINT TOL.DISC    "R26#12":
          *PRINT ""          "L#20":
          *PRINT TOL         "R26#12"

          PRINT

          GTOL.APPR    += TOL.APPR
          GTOL.DEDUCT  += TOL.DEDUCT
          GTOL.DISC    += TOL.DISC

          RETURN
*-------------------------------------------------------------------------*
PRT.LN:   *** Print preview line and add amounts to the totals

          INV.AMT  = PAY.AMT + DISC.AMT + DEDUCT     ;*Apprv Amt

          IF NOT(FIRST.LN) THEN
             PRINT SPACE(36):
          END
          FIRST.LN = NO

          CONVERT "," TO " " IN INV.NUM



          PRINT INV.NUM                       :DELIM:
          PRINT OCONV(INV.DT,'D2/')           :DELIM:
          PRINT OCONV(INV.AMT,'MR2')          :DELIM:
          PRINT OCONV(DEDUCT,'MR2')           :DELIM:
          PRINT OCONV(DISC.AMT,'MR2')         :DELIM:

          *PRINT INV.NUM                       "L#22":DELIM:
          *PRINT OCONV(INV.DT,'D2/')           "L#8":DELIM:
          *PRINT INV.AMT                       "R26#12":DELIM:
          *PRINT DEDUCT                        "R26#12":DELIM:
          *PRINT DISC.AMT                      "R26#12":'  ':DELIM:



          PRINT OCONV(PAY.DT,'D2/')           :DELIM:
          PRINT OCONV(DISC.DT,'D2/')          :DELIM:
          PRINT OCONV(PAY.AMT,'MR2')

          TOL.APPR     += INV.AMT
          TOL.DEDUCT   += DEDUCT
          TOL.DISC     += DISC.AMT

          RETURN
*-------------------------------------------------------------------------*
PRT.GTOTALS: *
       *   PRINT SPACE(50):'Grand Total --- ':

          GTOL  = GTOL.APPR - GTOL.DEDUCT - GTOL.DISC
        *  PRINT GTOL.APPR    "R26#12":
        *  PRINT GTOL.DEDUCT  "R26#12":
        *  PRINT GTOL.DISC    "R26#12":
        *  PRINT ''           "L#20":
        *  PRINT GTOL         "R26#12"

          RETURN
*-------------------------------------------------------------------------*
SEL.IDS:  *** Select recs from the EFT.STAGING file and check each one to
          *** see if it meets the users criteria.
          SELECT ESTGFILE
          READLIST DISB.ID ELSE GOTO FINISH

          DISB.CT = DCOUNT(DISB.ID,AM)
          FOR D.CT = 1 TO DISB.CT
             DID = DISB.ID<D.CT>
             GOSUB CHK.ONE
          NEXT D.CT

          RETURN
*-------------------------------------------------------------------------*
CHK.ONE:  *** Check if this rec meets the users criteria.  If it does save
          *** it in a temp location to later sort by vendor

          *** Get vendor and form type from the EFT.STAGING file
          READ ESTG FROM ESTGFILE,DID ELSE RETURN
          VEN   = ESTG<1>      ;* Vendor
          FTYPE = ESTG<2>      ;* Form Type

          READ ARREC FROM ARFILE,DID ELSE ARREC = ''
          BCHK    = ARREC<1>
          VOID    = ARREC<20>
          REV.IDS = ARREC<2>

          *** Check if the form type for the disbursement rec currently
          *** looking at is the same as the form type the user entered. If
          *** it is not return and check the next d rec from EFT.STAGING
          *** file
          IF FTYPE # F.TYPE THEN RETURN

          *** Get the bank ID of the disb rec
          DBNK.ID = FIELD(BCHK,'~',1)
          IF DBNK.ID # BNK.ID THEN RETURN

          *** Get the ledger ID
          LDID = FIELD(DID,'.',1)

          *** Get the branch ID for the disb rec
          READV BR.ID FROM LEDFILE,LDID,2 ELSE BR.ID = ''
          LOCATE BR.ID<1,1,3> IN BRCHS<1> SETTING NADA ELSE RETURN

          *** Get the post date of the disbursement record
          READV PDATE FROM LEDFILE,LDID,9 ELSE PDATE = ''
          *** If a Start Date was entered by the user and the post date
          *** is less than the start date, return and check next disb. rec
          IF SD # '' THEN
             IF PDATE < SD THEN RETURN
          END

          *** If a End Date was entered by the user and the post date
          *** is greater than the start date, return and check next disb.
          *** rec
          IF ED # '' THEN
             IF PDATE > ED THEN RETURN
          END

          *** If user entered a vendor make sure the vendor the user
          *** entered is the same as the
          IF VN # '' THEN
             READV DVEN FROM LEDFILE,LDID,1 ELSE DVEN = ''
             IF VN # DVEN THEN RETURN
          END ELSE
             * If user entered vendor type (and vendor was left null),
             * filter by the vendor type
             BEGIN CASE
             CASE VN.TYP = 'ALL'
             CASE VN.TYP
                READV EVN.TYP FROM ENTFILE, VEN, 35 ELSE EVN.TYP = ''
                LOCATE EVN.TYP IN VN.TYP<1> SETTING XPOS ELSE RETURN
             CASE VN.TYP = ''
                READV EVN.TYP FROM ENTFILE, VEN, 35 ELSE EVN.TYP = ''
                IF EVN.TYP # '' THEN RETURN
             END CASE
          END

          *** Check to make sure the EFT check has not been voided or
          *** reversed.  If a check has been voided/reversed it should not
          *** be in the EFT.STAGING file, but this is just a final check
          IF VOID # '' THEN RETURN

          * Check if check has been reversed
          * Old method was checking for disburesement in second position
          * new method is to check status of CREV.  Doing both for
          * backward compatablity
          REV.ID = FIELD(REV.IDS<1,2>,'.',2,2)
          IS.REVERSAL = (REV.ID[1,1] = 'D') OR (ARREC<18,1> = 'CREV')
          IF NOT(IS.REVERSAL) THEN
             * newer reversal has ar18= CREV on reversed check
             * and ar35 has CREV:Dnnnnn.001 on both "chk to reverse" and
             * reversed check.
             IS.REVARSAL = ARREC<35,1>[1,4] = "CREV"
          END
          IF IS.REVERSAL THEN RETURN

          TCHK = FIELD(BCHK,'~',2)[2,999]
          LOCATE TCHK IN SORT.IDS BY 'AL' SETTING POS ELSE NULL
          SORT.IDS = INSERT(SORT.IDS,POS;TCHK)
          IDS      = INSERT(IDS,POS;DID)

          RETURN
*-------------------------------------------------------------------------*
FINISH:   *
          RETURN
*-------------------------------------------------------------------------*
!TSMITH~01/10/14~15:43
