          PH.ARGS DRPT,CT.ID,START.ID,END.ID,TYPE,BRK.ON,SORT
** Version# 56.0003[8] - 10/25/2010 - 12:24pm - SMITJR - eclipse
*** V56.0003 Change - Custom Coding .. - 10/25/2010 - SMITJR - eclipse
** Copied from UBP PHYS.PHR.PRINT.SHEET Version# 56.0001 - 02/17/2010 - 09:08am - JONW - UPGRADE
*** V56.0001 Change - Custom Coding DEX714 - 12/13/2002 - JEFFG - eclipse
** was Version# 56 - 05/07/2007 - 04:01pm - ZACHW - main

*** Subroutine - PHYS.PHR.PRINT.SHEET
*-------------------------------------------------------------------------*
*** This is the Phantom routine for printing Count Sheets (or Cards),
*** which are used to do physical inventories.
*-------------------------------------------------------------------------*
*** DRPT     - Report printing defaults                               [IN]
*** CT.ID    - Count Id                                               [IN]
*** START.ID - Start Id                                               (IN)
*** END.ID   - End Id                                                 (IN)
*** TYPE     - Type (Sheets or Cards)                                 [IN]
*** BRK      - Break On (No Page Breaks or Line)                      [IN]
*** SORT     - Sort By                                                [IN]
*-------------------------------------------------------------------------*
*** Common: None
*-------------------------------------------------------------------------*

          PH.STATUS 'Initializing...'
          GOSUB INIT

          IF COL.RECORD = '' THEN
             MSG = "Missing report data for Eclipse Count Sheets Report. Contact your support representative"
             SEND.MESSAGE 'Phantom',USER.ID,MSG
             STOP
          END

          * Create tempfile for sorting
          UT.TEMPFILE.CREATE SORTFLNM,SORTFILE
          GOSUB SORT

          * set PRINTER.ON based on Sheet vs. Card
          IF TYPE = 'Sheets' THEN
             GOSUB SHT.HDR              ;* Creates sheet header
          END ELSE
             GOSUB CRD.HDR              ;* Creates card header
          END
          GOSUB PRT.TYPE                ;* Print Sheet or Card info
          PRINTER.OFF

          UT.TEMPFILE.DELETE SORTFLNM

          RETURN
*-------------------------------------------------------------------------*
INIT:     *** Make sure sort is specified and initialize sort by sell group

          RECORD.PREFIX = 'COUNT.SHEET.SETUP'
          REPORT.V.COL.GET.DATA RECORD.PREFIX,DRPT<56>,COL.RECORD
          IF COL.RECORD = '' THEN RETURN

          PRT.MORE = NO
          PHYS.ID  = 'PHYS:':CT.ID"R%5"
          OPEN PHYS.ID TO PHYSFILE ELSE
             SEND.MESSAGE 'Phantom',USER.ID,'Count File not Found : ':PHYS.ID
             STOP
          END

          IF BRK.ON # "No Page Breaks" AND BRK.ON # "Line" THEN
             LOC.BRK = 1
          END ELSE
             LOC.BRK = 0
          END

          READ PHYS FROM WORKFILE,PHYS.ID ELSE PHYS = ''
          BR = PHYS<2>

          * Set up for breaking on user selection
          IF LOC.BRK THEN
             READ LAYOUT FROM CTRLFILE,'PROD.LOCATION.LAYOUT~':BR ELSE
                LAYOUT = ''
             END
             LOCATE BRK.ON IN LAYOUT<5> SETTING BPOS ELSE BPOS = 1
             IF LAYOUT<3> # '' THEN DELIM = 1 ELSE DELIM = 0
             START.POS = ''
             THRU.POS  = ''
             FOR LPOS = 1 TO BPOS
                IF LAYOUT<6,LPOS>+0 = 0 THEN CONTINUE
                START.POS<LPOS> = 2

                FOR DPOS = 1 TO (LPOS-1)
                   START.POS<LPOS> += (LAYOUT<6,DPOS>+DELIM)
                NEXT DPOS

                START.POS<LPOS> += 1
                THRU.POS<LPOS>   = LAYOUT<6,LPOS>
             NEXT LPOS
          END ELSE
             LAYOUT = ''
          END

          NEXT.ID = PHYS<6>
          LAST.ID = NEXT.ID - 1

          * Sets default Sort to by Ctrl#
          IF SORT='' THEN SORT='Ctrl#'
          IF INDEX(SORT,'SellGroup',1) THEN
             SORT.BY.SELLGROUP = YES
          END ELSE
             SORT.BY.SELLGROUP = NO
          END

          * Read in control record that says if the users want to have
          * the tag locn info omitted.
          READ PHYS.EXCL.TAG FROM CTRLFILE,'PHYS.EXCLUDE.TAGS' ELSE
             PHYS.EXCL.TAG = NO
          END

          RETURN
*-------------------------------------------------------------------------*
SORT:     *** Write entries to sortfile.

          SELECT PHYSFILE
          LOOP
             READNEXT CN ELSE EXIT

             * Skip if this record is not in the range we want to see
             IF CN < START.ID OR CN > END.ID THEN
                CONTINUE
             END

             READ RECORD FROM PHYSFILE,CN ELSE
                PRINT 'Error reading:':CN
                CONTINUE
             END

             * Create the sort ID - the possible sorts are:
             *  'Ctrl#
             *  'Buy Line'
             *  'Price Line By Description'
             *  'Location by Ctrl#'
             *  'Location by PLine by Desc'
             *  'Location by PLine by SellGroup'
             *  'Location by Description'
             MATREAD PRD FROM PRDFILE,RECORD<1> ELSE MAT PRD = ''
             PRICE.LINE   = PRD(9)<1>
             BUY.LINE     = PRD(12)<1>
             SELL.GROUP   = PRD(73)<1>
             DESCRIPTION  = PRD(1)<1,1>[1,20]
             PRD.LOCATION = FIELD(RECORD<2>,'~',2)

             * added code to sort correctly if there isn't a location
             IF PRD.LOCATION = '' THEN PRD.LOCATION = ' '

             SORT.ID = ''
             BEGIN CASE
             CASE SORT = 'Buy Line'
                SORT.ID = BUY.LINE
             CASE SORT = 'Price Line By Description'
                SORT.ID := PRICE.LINE:'~':DESCRIPTION
             CASE SORT = 'Location by Ctrl#'
                SORT.ID = PRD.LOCATION
             CASE SORT = 'Location by PLine by Desc'
                SORT.ID := PRD.LOCATION:'~':PRICE.LINE:'~':DESCRIPTION
             CASE SORT = 'Location by PLine by SellGroup'
                SORT.ID := PRD.LOCATION:'~':PRICE.LINE:'~':SELL.GROUP
             CASE SORT = 'Location by Description'
                SORT.ID := PRD.LOCATION:'~':DESCRIPTION
             END CASE

             * added a RJ to the CN for proper sorting
             SORT.ID := '~':CN'R%10' ;* Always put the CN at the end.

             * All we need to write is the ID, we are just doing this for
             * sorting purposes. All data will ramain in the PHYS.ID file
             WRITE '' ON SORTFILE,SORT.ID
          REPEAT

          RETURN
*-------------------------------------------------------------------------*
SHT.HDR:  *** Set up the header for printing sheets

          * First line of the header count id, count desc and sort by
          HDR = '   Count ID # ':CT.ID"R%5":'   --   ':PHYS<1>:'  --  Sort By ':SORT:SPACE(8):"Page^####"

          * Second line of header - branch, counted by and count date
          HDR<1,2> = '   Branch # ':BR"L#4":'      --   Counted by : ___________  Count Date : ____________'

          * Third and Fourth lines of Header based upon users selections
          UL.STRING  = ''
          HDR.STRING = ''
          REPORT.LAYOUT.V.PRINT.STR '','H',COL.RECORD,UL.STRING,HDR.STRING

          HDR<1,-1> = LOWER(HDR.STRING)
          CONVERT 'H' TO '-' IN UL.STRING
          HDR<1,-1> = UL.STRING

          * If there is no description for this count id make a
          * descriptive title.
          TITLE = PHYS<1>
          IF TITLE = '' AND DRPT<27> = 'HOLD' THEN
             TITLE = 'Physical Inv Sheets for ':CT.ID:' by ':SORT
          END

          * Determine length of header to resize print
          WIDTH  = LEN(HDR<1,4>); *This length changes - column selections
          H.WDTH = LEN(HDR<1,1>); *This line is fixed in length

          * Take the greater of the two.
          IF WIDTH > H.WDTH THEN WIDTH = WIDTH ELSE WIDTH = H.WDTH
          PWIDTH = WIDTH
          WIDTH += 3
          PRINTER.ON WIDTH,TITLE,DOC.ID,HDR,RPT.DFLT=DRPT
          PRT.CARD = NO

          RETURN
*-------------------------------------------------------------------------*
CRD.HDR:  *** Set up the header for printing cards

          IF DRPT<27> = 'HOLD' THEN
             TITLE = 'Physical Inv Cards for ':CT.ID
          END ELSE
             TITLE = ''
          END

          PRINTER.ON 'PHYSICAL.CARD',TITLE,RPT.DFLT=DRPT
          PRT.CARD = YES

          RETURN
*-------------------------------------------------------------------------*
PRT.TYPE: *** Determine if we are printing cards or sheets

          LAST.BRK = '@@'
          IF LOC.BRK THEN
             FOR LPOS = 2 TO BPOS
                LAST.BRK<LPOS> = '@@'
             NEXT LPOS
          END

          * Determine if we are printing cards or sheets
          HIGH.CN = 0
          CT      = 0
          BEGIN CASE
          CASE PRT.CARD
             FOR CN = START.ID TO END.ID
                GOSUB PRT.CARD
           ** Custom Begin
           **   CT += 1
           **
           **   * print 4 cards on each page
           **   IF NOT(MOD(CT,4)) THEN
           **      PRINT CHAR(12):
           **   END
           ** Custom End
             NEXT CN
          CASE SORT[1,1] = 'C' AND NOT(LOC.BRK)
             FOR CN = START.ID TO END.ID
                GOSUB PRT.SHEET
                CT += 1
             NEXT CN
          CASE OTHERWISE
             * Since we are printing sheets we need to sort first
             PH.STATUS 'Selecting...'
             SSELECT SORTFILE
             PH.STATUS 'Spooling...'

              LOOP
                READNEXT SORT.ID ELSE EXIT

                * The CN is the last part of the sort ID
                LAST.PART = DCOUNT(SORT.ID,'~')
                CN = FIELD(SORT.ID,'~',LAST.PART)
                GOSUB PRT.SHEET
                CT += 1
             REPEAT

             FOR XX = HIGH.CN + 1 TO END.ID
                CN = XX
                GOSUB PRT.SHEET
             NEXT XX
          END CASE

          IF END.ID >  LAST.ID THEN
             PHYS<6> = END.ID+1
             WRITE PHYS ON WORKFILE,PHYS.ID
          END

          MSG = PHYS<1>:' Printing Complete - ':CT:' Items Printed'
          SEND.MESSAGE  'Phantom',USER.ID,MSG
          UT.PH.CLEANUP

          RETURN
*-------------------------------------------------------------------------*
PRT.CARD: *** print card info

          PHYS.PHR.PRINT.CARD CN,BR,PHYSFILE

          RETURN
*-------------------------------------------------------------------------*
PRT.SHEET: *** Adds the products being counted to the report

          OH  = ''
          UM  = ''
          CN += 0 ;* remove leading zeros from the CN by adding 0

          READ CREC FROM PHYSFILE,CN ELSE CREC = ''
          IF CN > HIGH.CN THEN HIGH.CN = CN

          PN     = CREC<1>
          LOC    = CREC<2>
          SV.LOC = FIELD(LOC,'~',1)
          PLOC   = FIELD(LOC,'~',2)
          NEW.CN = CREC<5>
          IF NEW.CN THEN DESC := '+'
          READV DESC  FROM PRDFILE,PN,1 ELSE DESC = ''
          READV PLINE FROM PRDFILE,PN,9 ELSE PLINE = ''
          READV UPC   FROM PRDFILE,PN,63 ELSE UPC = ''
          UPC = UPC<1,1>

          * If the price line or aisle has changed put in a page break
          BEGIN CASE
          CASE BRK.ON = 'Line'
             * For a page break on price line
             READV PLINE FROM PRDFILE,PN,9 ELSE PLINE = ''
             IF PLINE # LAST.BRK<1> THEN
                IF LAST.BRK<1> # '@@' THEN PRINT CHAR(12)
                LAST.BRK<1> = PLINE
             END
          CASE LOC.BRK
             * For a page break on location heading
             FND.BRK = NO
             FOR LPOS = BPOS TO 1 STEP -1
                IF START.POS<LPOS>+0 = 0 THEN CONTINUE
                IF LOC[START.POS<LPOS>,THRU.POS<LPOS>]#LAST.BRK<LPOS> THEN
                   IF LAST.BRK<LPOS> # '@@' THEN FND.BRK = YES
                   LAST.BRK<LPOS> = LOC[START.POS<LPOS>,THRU.POS<LPOS>]
                END
             NEXT LPOS
             IF FND.BRK THEN PRINT CHAR(12)
          END CASE

          GOSUB GET.UMS

          RETURN
*-------------------------------------------------------------------------*
GET.UMS:  *** Get a list of all ums for this product.

          UMS = ''
          MATREAD PRD FROM  PRDFILE,PN      ELSE MAT PRD = ''
          MATREAD PLNE FROM PLNEFILE,PRD(9) ELSE MAT PLNE = ''
          UMT = PLNE(3)
          UMT.DFLT = PLNE(6)
          IF PRD(15) # ''THEN
             UMT = PRD(15)
             UMT.DFLT = PRD(16)
          END

          * Put the units in descending order
          UM.CT    = 1
          FOR UMN  = 1 TO 5
             IF UMT<1,UMN> # '' THEN
                UMS<UM.CT> = UMT<1,UMN>
                UM.CT += 1
             END
          NEXT UMN

          * Get dflt UOM *
          INV.POS = UMT.DFLT<1,5>
          IF INV.POS < 1 THEN INV.POS = 1
          DFLT.UM= UMT<1,INV.POS>
          UMS = LOWER(UMS)

          * Print selected items to report
          VDATA = DESC<1,1>
          PRT.MORE = REPORT.V.COLUMN.USED(COL.RECORD,1)
          VDATA<2> = PLOC
          VDATA<3> = PLINE
          IF UMS<1,1>#'' THEN
             VDATA<4> = '________':(UMS<1,1> "L#2")
          END
          IF UMS<1,2>#'' THEN
             VDATA<5> = '________':(UMS<1,2> "L#2")
          END
          IF UMS<1,3>#'' THEN
             VDATA<6> = '________':(UMS<1,3> "L#2")
          END
          IF UMS<1,4>#'' THEN
             VDATA<7> = '________':(UMS<1,4> "L#2")
          END
          IF UMS<1,5>#'' THEN
             VDATA<8> = '________':(UMS<1,5> "L#2")
          END
          VDATA<9> = CN "R#6"
          PRDD.BR.GET BR,PN
          LOCATE LOC IN PRDD.BR(8)<1> SETTING QPOS ELSE NULL
          OH = PRDD.BR(1)<1,QPOS>
          GOSUB SET.UM
          VDATA<10> = OH.ALPHA
          MSC.C  = FIELD(PRD(4),' ', 2)[1,7]
          VDATA<11> = MSC.C "L#7"
          PRD.BR.GET.VAL BR,PN,24,BRANCH.SELL.GROUP
          VDATA<12> = BRANCH.SELL.GROUP
          IF DFLT.UM#'' THEN
             VDATA<13> = '________':(DFLT.UM 'L#3')
          END
          VDATA<14> = UPC
          VDATA<15> = SV.LOC

          TAG = ''
          GOSUB GET.TAG
          VDATA<16> = TAG

          PRINT.STRING = ''
          REPORT.LAYOUT.V.PRINT.STR VDATA,'',COL.RECORD,'',PRINT.STRING
          PRINT PRINT.STRING

          * Print extra lines of Description
          IF PRT.MORE = YES THEN
             XCT   = DCOUNT(DESC,VM)
             FOR J = 2 TO XCT
                VDATA = DESC<1,J>
                PRINT.STRING = ''
                REPORT.LAYOUT.V.PRINT.STR VDATA,'',COL.RECORD,'',PRINT.STRING
                PRINT PRINT.STRING
             NEXT J
          END

          GOSUB EXCLD.IT

          RETURN
*-------------------------------------------------------------------------*
SET.UM:   *** Sets the Unit of Measure

          MATREAD PRD FROM  PRDFILE,PN      ELSE MAT PRD = ''
          MATREAD PLNE FROM PLNEFILE,PRD(9) ELSE MAT PLNE = ''
          PLINE   = PRD(9)
          UM.QTYS = PRD(7)
          UM.TBL  = PLNE(3)
          DATA    = PLNE(6)
          IF PRD(15) # '' THEN UM.TBL = PRD(15)
          IF PRD(16) # '' THEN DATA   = PRD(16)
          POS       = DATA<1,5>
          UM.MAX    = UM.TBL<1,POS>
          IF OH+0 = 0 THEN
             UM.PER = UM.MAX
             UM.QTY = UM.QTYS<1,POS>
             OH.ALPHA = 0 "R#5":UM.PER"L#2"
          END ELSE
             IQ.TO.ALPHA UM.TBL,UM.QTYS,UM.MAX,OH,Q1,U1,Q2,U2,OH.ALPHA
          END

          RETURN
*-------------------------------------------------------------------------*
GET.TAG:  *** get the tags for the location

          IF SV.LOC = 'S' THEN
             QTYS = PRDD.BR(1)
             LOCS = PRDD.BR(8)
             LCT  = DCOUNT(QTYS<1>,VM)

             FOR LCN = 1 TO LCT
                OH = QTYS<1,LCN>
                LTYPE = FIELD(LOCS<1,LCN>,'~',1)
                LPLOC = FIELD(LOCS<1,LCN>,'~',2)

                IF OH > 0 AND LTYPE#'P' AND LTYPE#'S' AND LPLOC = PLOC THEN
                   TAG = FIELD(FIELD(LOCS<1,LCN>,'~',3),'^',2)
                END
             NEXT LCN
          END

          RETURN
*-------------------------------------------------------------------------*
EXCLD.IT: *** Check for exclude tag and draw detail line between items

          IF SV.LOC = 'S' THEN
             PRDD.BR.GET BR,PN
             QTYS = PRDD.BR(1)
             LOCS = PRDD.BR(8)
             LCT  = DCOUNT(QTYS<1>,VM)
             FOR LCN = 1 TO LCT
                LTYPE = FIELD(LOCS<1,LCN>,'~',1)
                IF LTYPE#'P' AND LTYPE#'S' THEN
                   OH = QTYS<1,LCN>
                   IF OH > 0 THEN
                      GOSUB SET.UM
                      IF NOT(PHYS.EXCL.TAG) THEN
                         PRINT SPACE(6):'** Tag/Review: ':LOCS<1,LCN>:' - Qty: ':OH.ALPHA"L#12":' ** Do NOT Include in Count!! **'
                      END
                   END
                END
             NEXT LCN
          END

          * Print the detail lines
          PRINT SPACE(3):STR('-',PWIDTH)

          RETURN
!SMITJR~10/25/10~12:24
