          PH.ARGS DRPT,SDT,STM,EDT,ETM,BRCHS,BRS,LOC.ID,USR.ID,SORT,VER,FITEM
** Version# 32.0001[1] - 08/17/2010 - 11:50pm - SMITJR - eclipse
** Copied from BP CR.PHR.CASHBOX.JRL Version# 32 - 01/09/2009 - 12:25pm - BILLW - main

*** Subroutine:  CR.PHR.CASHBOX.JRL
*-------------------------------------------------------------------------*
*** This routine creates a report that shows all Cash Box Transactions.
*-------------------------------------------------------------------------*
*** DRPT        - Name of Report                                      [IN]
*** SDT         - Start Date                                          (IN)
*** STM         - Start Time                                          (IN)
*** EDT         - End Date                                            (IN)
*** ETM         - End Time                                            (IN)
*** BRCHS       - Branches to be included in report                   (IN)
*** BRS         - Literal entered by user for branches                (IN)
*** LOC.ID      - Location                                            (IN)
*** USER.ID     - User Id  (Optional)                                 (IN)
*** SORT        - Sort Option (User or Customer)                      (IN)
*** VER         - Version - (Narrow or Wide)                          (IN)
*** FITEM       - Extended Sort Item                                  (IN)
*-------------------------------------------------------------------------*

          TGT      = ''
          CURR.FLG = NO
          BASE.CUR = YES
          IF DRPT<51> THEN
             READ BASEC FROM CTRLFILE,"BASE.CURRENCY" ELSE BASEC = ''
             IF DRPT<51> # BASEC THEN
                TGT = DRPT<51>
                CURR.FLG = YES
                BASE.CUR = NO
             END
          END

          ST.ID    = SDT"R%5":STM"R%5"
          IF ETM   = '' THEN ETM = 60*60*24
          IF FITEM = '' THEN FILTER.FLAG = NO ELSE FILTER.FLAG = YES
          ED.ID    = EDT"R%5":ETM"R%5"
          LONG.VER = (VER[1,1]='W')

          LOCATION = DRPT<27>
          SORT = SORT[1,1]

          WRITE 'Selecting...' ON PHSTFILE,PID$
          GOSUB SEL.IDS
          WRITE 'Spooling...' ON PHSTFILE,PID$
*-------------------------------------------------------------------------*
          INTIT = 'Cash Box Journal'
          RPT.DFLT = DRPT
          JRL.UPD.STAMP 0,SDT,EDT,JID,BRCHS,BRS,INTIT,TITLE,HDG
          HDG<1,2>= 'Cash Box Journal for ':OCONV(SDT,'D4/'):'-':OCONV(STM,'MTH'):TIME.ZONE$:' to ':OCONV(EDT,'D4/'):'-':OCONV(ETM,'MTH'):TIME.ZONE$
          IF LONG.VER THEN HDG<1,2> = HDG<1,2>:SPACE(35)
          IF LONG.VER OR LOCATION = 'HOLD' THEN
             BRANCH.ALLOW = 134
          END ELSE
             BRANCH.ALLOW = 79
          END
          IF LEN(BRS) > BRANCH.ALLOW THEN BRS = BRS[1,BRANCH.ALLOW]:'...'
          HDG<1,3> = 'Branches:  ':BRS
          IF LOC.ID#'' THEN HDG<1,4> = 'Location:  ':LOC.ID
          IF USR.ID#'' THEN HDG<1,4> := '   -    User ID:  ':USR.ID
          IF CURR.FLG THEN HDG<1,4> := '   -    Report Currency:  ':TGT
          HDG<1,5> =  'Br   User    Order #          PostDate  Customer             '
          IF LONG.VER THEN HDG<1,5> := '       Cash      Check      CCard'
          HDG<1,5> := '      Total     Open Bal'
          IF LONG.VER THEN HDG<1,5> := ' Payment Info        Location'
          IF DRPT<33> = '' THEN
             TITLE='Cash Box Journal ':OCONV(SDT,'D0/'):' - ':OCONV(EDT,'D0/')
          END ELSE
             TITLE= DRPT<33>:' ':OCONV(SDT,'D0/'):' - ':OCONV(EDT,'D0/')
          END
          IF LONG.VER OR LOCATION='HOLD' THEN
             PRINTER.ON 147,TITLE,DOC.ID,HDG,RPT.DFLT=DRPT
          END ELSE
             PRINTER.ON  92,TITLE,DOC.ID,HDG,RPT.DFLT=DRPT
          END

          FILTER.PRINT 'S',FITEM
          LAST.BRKON = '@@'
          GCASH.AMT  = 0
          GCHECK.AMT = 0
          GCARD.AMT  = 0
          GTOTAL     = 0
          GBAL       = 0

          IDN = DCOUNT(IDS,AM)
          FOR IDX=1 TO IDN
          GOSUB PRINT.ONE
          NEXT ID

          IF SORT # 'I' THEN
             GOSUB PRT.TOTALS
          END ELSE
             PRINT
          END
          GOSUB PRT.GTOTALS

          PRINTER.OFF

          UT.PH.CLEANUP
          SEND.MESSAGE 'SPOOLER',USER.ID,TITLE:' is complete'

          STOP
*-------------------------------------------------------------------------*
PRINT.ONE: *
          BRKON = FIELD(SORTBYS<IDX>,'!',1)
          IF LAST.BRKON # BRKON AND SORT # 'I' THEN GOSUB PRT.TOTALS
          ORN   = IDS<IDX>
          OID   = FIELD(ORN,'.',1)
          INVN  = FIELD(ORN,'.',2)+0
          MATREAD LED FROM LEDFILE,OID ELSE            RETURN
          LOCATE  INVN IN LED(8)<1> SETTING GEN ELSE   RETURN
          READV   NAME FROM CUSFILE,LED(1)<1,GEN>,1 ELSE NAME=''

          IF CURR.FLG THEN
             CONV.CURR.LED TGT,GEN
          END

          LOCATE 'CASHBOX' IN LED(24)<1,GEN> SETTING POS THEN POS = 1

          CBR       = FIELD(LED(25)<1,GEN,POS>,'~',1)
          CASH.AMT  = LED(45)<1,GEN,1>
          CHECK.AMT = LED(45)<1,GEN,2>
          CARD.AMT  = LED(45)<1,GEN,3>
          CHECKN    = LED(46)<1,GEN,2>
          * Send mutlitval the subvals values needed
          * to get cc paid info from LEDGER.CC fld 20
          IF LED(46)<1,GEN,3> THEN
             FLD.ARGS      = 3   ;* card#
             FLD.ARGS<1,2> = 5   ;* card type
             GET.LEDCC.VAL LEDCC.DATA,FLD.ARGS,OID,GEN
             CCARDN  = LEDCC.DATA<1,1>
             CCTYPE  = LEDCC.DATA<1,2>
          END ELSE
             CCARDN  = ''
             CCTYPE  = ''
          END
          TOTAL     = SUM(LED(45)<1,GEN>)

*** If site does not have the credit card mod, get CC info from LED(121)
          UT.SEC3 9,HAS.CC,,NO
          IF NOT(HAS.CC) THEN
             *** If the credit card was not found then we need to find the
             *** the default credit card information.
             UT.OPEN.FILE 'LEDGER.CC',LEDCCFILE,ERR.MSG,YES
             IF CCTYPE = '' THEN
                IF NOT(ERR.MSG) THEN
                   READV CCTYPE FROM LEDCCFILE,OID,1 ELSE CCTYPE = ''
                   CCTYPE = OCONV(CCTYPE,'MCU')
                END
             END
             IF CCARDN = '' THEN
                IF NOT(ERR.MSG) THEN
                   READV CCARDN FROM LEDCCFILE,OID,2 ELSE CCARDN = ''
                END
             END
          END

*** Mask the number for printing
          CREDIT.CARD.MASK MASK.ID,CCARDN


          ID.NUM    = ""
          IF CASH.AMT THEN
             ID.NUM = "Cash"
          END
          IF CHECK.AMT THEN
             ID.NUM<-1> = "Chk#":CHECKN
          END
          IF CARD.AMT THEN
             ID.NUM<-1> = CCTYPE:"#":MASK.ID
          END

          MATREAD AR FROM ARFILE,ORN ELSE MAT AR = ''
          IF CURR.FLG THEN
             CONV.CURR.AR TGT
          END
          BAL = -AR(8)<1,1>

          ODT = OCONV(LED(23)<1,GEN>,'D2/')
          PRINT CBR             'L#5':
          PRINT LED(27)<1,GEN,1>'L#6':'  ':
          PRINT ORN             "L#14":
          *-- Prints image indicator if images exist. --*
          IF INVN+0 = 0 THEN
            CHK.ORN = OID
          END ELSE
            CHK.ORN = ORN
          END
          CHECK.FOR.IMAGES CHK.ORN, 'L', IMAGE.FLAG
          IF IMAGE.FLAG THEN
             PRINT ' * ':
          END ELSE
             PRINT '   ':
          END
          *--                                           --*
          PRINT ODT             'L#10':
          PRINT NAME            'L#20':' ':
          IF LONG.VER THEN
             PRINT CASH.AMT        'R26#11':
             PRINT CHECK.AMT       'R26#11':
             PRINT CARD.AMT        'R26#11':
          END
          PRINT TOTAL           'R26#11':'  ':
          PRINT BAL             'R26#11':' ':
          IF LONG.VER THEN
             PMT.CT = DCOUNT(ID.NUM,AM)
             FOR PMT = 1 TO PMT.CT
             IF PMT > 1 THEN PRINT SPACE(110):
             PRINT ID.NUM<PMT> "L#19":' ':
             IF PMT = 1 THEN PRINT LED(27)<1,GEN,2> "L#15" ELSE PRINT
             NEXT PMT
          END ELSE
             PRINT
          END

          ITM.CT     += 1
          TCASH.AMT  += CASH.AMT
          TCHECK.AMT += CHECK.AMT
          TCARD.AMT  += CARD.AMT
          TTOTAL     += TOTAL
          TBAL       += BAL
          GCASH.AMT  += CASH.AMT
          GCHECK.AMT += CHECK.AMT
          GCARD.AMT  += CARD.AMT
          GTOTAL     += TOTAL
          GBAL       += BAL
          USR         = LED(27)<1,GEN,1>

          RETURN
*-------------------------------------------------------------------------*
PRT.TOTALS: *
          IF LAST.BRKON#'@@' THEN
             IF ITM.CT>1 THEN
                SPC = 30
                IF SORT = 'U' THEN
                   PRINT SPACE(SPC):'Total for ':USR"L#15":' -----':
                END ELSE
                   PRINT SPACE(SPC):'Total for ':NAME"L#15":' -----':
                END
                IF LONG.VER THEN
                   PRINT TCASH.AMT  'R26#11':
                   PRINT TCHECK.AMT 'R26#11':
                   PRINT TCARD.AMT  'R26#11':
                   END
                PRINT TTOTAL     'R26#11':'  ':
                PRINT TBAL       'R26#11'
                END
             PRINT
             END
          LAST.BRKON = BRKON
          TCASH.AMT  = 0
          TCHECK.AMT = 0
          TCARD.AMT  = 0
          TTOTAL     = 0
          TBAL       = 0
          ITM.CT     = 0
          RETURN
*-------------------------------------------------------------------------*
PRT.GTOTALS: *
          SPC = 35
          PRINT SPACE(SPC):'Grand Totals    ------    ':
          IF LONG.VER THEN
             PRINT GCASH.AMT  'R26#11':
             PRINT GCHECK.AMT 'R26#11':
             PRINT GCARD.AMT  'R26#11':
             END
          PRINT GTOTAL     'R26#11':
          IF NOT(LONG.VER) THEN PRINT SPACE(2): ELSE PRINT SPACE(2):
          PRINT GBAL       'R26#11'

          RETURN
*-------------------------------------------------------------------------*
SEL.IDS:  SORTBYS = ''
          IDS     = ''

          FOR D=SDT TO EDT
          L = JLI.READ.EMU('3*':D)
          LLN = DCOUNT(L,AM)
          FOR LLX=1 TO LLN
          ORN  = L<LLX>
          OID  = FIELD(ORN,'.',1)
          INVN = FIELD(ORN,'.',2)+0
          MATREAD LED FROM LEDFILE,OID                     ELSE GOTO SKIPIT
          LOCATE INVN IN LED(8)<1> SETTING GEN             ELSE GOTO SKIPIT
          LOCATE 'CASHBOX' IN LED(24)<1,GEN> SETTING POS   ELSE GOTO SKIPIT
          CASH.BR = FIELD(LED(25)<1,GEN,POS>,'~',1)
          LOCATE CASH.BR IN BRCHS<1> SETTING POS           ELSE GOTO SKIPIT
          STAT = LED(6)<1,GEN,1>
          IF STAT='X'                                      THEN GOTO SKIPIT
          IF USR.ID#'' AND USR.ID#LED(27)<1,GEN,1>         THEN GOTO SKIPIT
          IF LOC.ID#'' AND LOC.ID#LED(27)<1,GEN,2>         THEN GOTO SKIPIT
          TM.ID = D"R%5":INT(LED(27)<1,GEN,3>)"R%5"
          IF TM.ID < ST.ID OR TM.ID > ED.ID                THEN GOTO SKIPIT
          IF FILTER.FLAG THEN
             FILTER.SELECT SKIP.FLAG,OID,GEN,FITEM
             IF SKIP.FLAG THEN GOTO SKIPIT
          END

          GOSUB SORT.ID

SKIPIT:   NEXT LLX
          NEXT D

          RETURN
*-------------------------------------------------------------------------*
SORT.ID:  *
          BEGIN CASE
          CASE SORT='C'
             READV CS FROM CUSFILE,LED(1)<1,GEN>,8 ELSE CS=''
             SORTBY = CS:LED(1)<1,GEN>:'!':ORN
          CASE SORT = 'U'
             SORTBY = LED(27)<1,GEN,1>
          CASE SORT = 'I'
             SORTBY = ORN
          END CASE
          LOCATE SORTBY IN SORTBYS BY 'AL' SETTING POS ELSE NULL
          SORTBYS = INSERT(SORTBYS,POS;SORTBY)
          IDS     = INSERT(IDS,POS;ORN)

          RETURN
!SMITJR~08/17/10~23:50
