          SUBROUTINE (MNFST,MANIFEST.NO,DRPT,PRT.ADDR,PRT.SHIP,PRT.SHP.TKTS,ERR.MESS,DOC.IDS)
** Version# 46.0002[49] - 12/15/2010 - 11:25am - SMITJR - eclipse
*** V46.0002 Change - Custom Coding .. - 12/15/2010 - SMITJR - eclipse
** Copied from CBP SOE.MANIFEST.REPORT Version# 46.0001[15] - 08/10/2010 - 11:25am - SMITJR - eclipse
*** V46.0001 Change - Custom Coding . - 08/10/2010 - SMITJR - eclipse

*-------------------------------------------------------------------------*
*** This routine will print the Shipping Manifest Report.
*-------------------------------------------------------------------------*
*** MNFST - Manifest Controls                                       (IN)
***         MNFST<1>  = ship via
***         MNFST<2>  = ship date
***         MNFST<3>  = branch
***         MNFST<4>  = start time
***         MNFST<5>  = first delivery time
***         MNFST<6>  = delivery interval minutes
***         MNFST<7>  = closed flag
***         MNFST<8>  = dirver userid
***         MNFST<10> = stop info/override for stop
***         MNFST<11> = delivery time for stop #
***         MNFST<14> = time block list in order
***         MNFST<15> = value is stop # and subvalue is list of tickets
***                     on manifest for that stop
***         MNFST<16> = comments for ticket position matched with <5>
***
*** MANIFEST.NO - Manfest Number                                  (IN)
*** DRPT        -                                                 (IN)
*** PRT.ADDR    - Flag to Print Address                           (IN)
*** PRT.SHIP    - Flag to print shipping instructions             (IN)
*** PRT.SHP.TKTS- Flag to print ship tickets                      [IN
*** ERR.MESS    - Error Message                                   (OUT)
*** DOC.IDS     - AM list of doc ids that are printed             <OUT>
*-------------------------------------------------------------------------*
          GOSUB INIT

          TITLE = "Shipping Manifest ":MANIFEST.NO
          PRINTER.ON "MANIFEST.BC",TITLE,DOC.ID,,,RPT.DFLT=DRPT

          IF JAVA.PROC$ THEN
             JAVA.DOC.ID = FIELD(JAVA.PASSER$<JP.DOC.ID$>,'#',2)
             JAVA.FORM   = FIELD(JAVA.PASSER$<JP.FORM$>,'#',2)
             DOC.IDS<-1> = JAVA.DOC.ID:VM:JAVA.FORM
          END ELSE
             DOC.IDS<-1> = DOC.ID
          END

          GOSUB HEADER
          GOSUB DO.REPORT
          GOSUB FOOTER

          PRINTER.OFF
          IF PRT.SHP.TKTS THEN GOSUB SHIP.TICK
          SEND.MESSAGE 'Phantom',USER.ID,TITLE:' is Complete'

          RETURN
*-------------------------------------------------------------------------*
INIT:
          TITLE   = 'Shipping Manifest ':MANIFEST.NO
          MED     = CHAR(27):'(8U'
          MED    := CHAR(27):'(s0p12h0s0b3T'
          ELPI    = CHAR(27):"&l8D"
          VIA     = MNFST<1>
          SHIP.DT = MNFST<2>
          BR      = MNFST<3>
          STRT.TM = MNFST<4>
          FDEL.TM = MNFST<5>
          INTVL   = MNFST<6>
          DRIVER  = MNFST<8>
          PKG.ID  =''; PKG.HDG = ''
          LINE    = 0; BOX.TOT = 0; BAG.TOT = 0; BND.TOT = 0;   PAGE = 0
          WGT.TOT = 0; LOD.TOT = 0; STP.ADR =''; LEN.TOT = 0;OLD.STP ='@@@'
          BOD.LNS =45; PRT.STR =''; LINE.CT = 0; STR.CNT = 0; HDG.CT = 0

          RETURN
*-------------------------------------------------------------------------*
HEADER:   *** Build the header array and print. This is called every time
          *** we page break so we need to reset the vars each time...
          PAGE    +=1
          HDG.STR  = ''; CTR.CT = 0; SPC = 0;DRIVER.TXT = ''
          P.DATA   = ''; PKG.ID = ''; PKG.CT = 0; PKG.WD = 0
          PG.WIDTH = 0; PKG.HDG = ''

          READV BR.EN FROM TERRFILE,BR,4 ELSE BR.EN = ''
          READV BNAME FROM CUSFILE,BR.EN,1 ELSE BNAME = ''
          READV DRIVER.NAME FROM INIFILE,DRIVER,3 ELSE DRIVER.NAME = ''
          READV PACKAGES FROM CTRLFILE,'PACKAGE.TYPES',1 ELSE PACKAGES = ''

          HDG.STR<-1> = '  ':MANIFEST.NO"L#10":SPACE(58):MANIFEST.NO
          CTR.CT  = INT(((35-LEN(BNAME))/2)+.5)
          CTR.CT += 23
          HDG.STR<-1> = SPACE(CTR.CT):BNAME
          HDG.STR<-1> = ' '
          HDG.STR<-1> = SPACE(23):'S H I P P I N G    M A N I F E S T'
          SPC = (44 - (LEN(VIA) + 10))/2
          HDG.STR<-1> = ' '
          HDG.STR<-1> = '   Manifest #: ':MANIFEST.NO"L#10"
          HDG.STR := SPACE(SPC):'Ship Via: ':VIA:SPACE(SPC):'Page ':PAGE
          HDG.STR<-1> = ' '
          DRIVER.TXT  = DRIVER:'  ':DRIVER.NAME
          HDG.STR<-1> = '   Driver: ':DRIVER.TXT"L#34"
          HDG.STR := SPACE(8):'Delivery Date: ':SHIP.DT"D4/"

          FOR P = 1 TO 4
             P.DATA = PACKAGES<1,P>
             IF P.DATA # '' THEN
                PKG.HDG := PACKAGES<1,P>"R#5":' '
                PKG.ID<-1> = P
             END
          NEXT P
          PKG.CT   = DCOUNT(PKG.ID,AM)

          HDG.STR<-1> = ' '
          HDG.STR<-1> = 'Stop Customer  Ticket-Number            Customer Signature   '
          HDG.STR := PKG.HDG:' Pkg Count'
          PKG.WD   = PKG.CT*6
          PG.WIDTH = 63+(PKG.WD)
          IF PG.WIDTH < 80 THEN PG.WIDTH = 80
          HDG.STR<-1> = STR('=',96)
          HDG.STR<-1> = ' '
          IF PAGE = 1 THEN
             HDG.STR<-1> = '    **** DEPARTURE ':OCONV(STRT.TM,"MTH")
             HDG.STR :=' ':TIME.ZONE$'L#3':' ****'
             HDG.STR<-1> = ' '
             HDG.CT = 14;BOD.LNS = 45
          END ELSE
             HDG.CT = 12; BOD.LNS = 47
          END

          FOR HH = 1 TO HDG.CT
             PRINT MED:HDG.STR<HH>
          NEXT HH

          RETURN
*-------------------------------------------------------------------------*
DO.REPORT:*** Build our print stings for each stop, then go to PRT.STP to
          *** determine if there's enough room left on the page to print
          *** the entire stop on one page...
          BLK.CT  = DCOUNT(MNFST<14>,VM)
          BLK.FRM = MNFST<14,1,1>
          BLK.NO  = 1

          ST.CT   = DCOUNT(MNFST<15>,VM)
          FOR STP = 1 TO ST.CT
             DEL.TM  = MNFST<11,STP>
BLK.LP:      * For time blocks
             IF BLK.NO <= BLK.CT AND DEL.TM > BLK.FRM THEN
                GOSUB DISP.BLK
                GOTO BLK.LP
             END
             IDS   = MNFST<15,STP>
             CMNTS = MNFST<16,STP>
             PKGS  = RAISE(RAISE(MNFST<42,STP>))
             * manifest pick pkgs by tote, reg by ticket
             ORDER.PKGS = YES
             IF SUMMATION(PKGS) # 0 THEN ORDER.PKGS = NO
             TK.CT  = DCOUNT(IDS,SVM)

             *** Go thru each ticket for this Stop gathering all our info..
             FOR TK = 1 TO TK.CT
                TICKET.ID = IDS<1,1,TK>
                CMNT      = RAISE(RAISE(CMNTS<1,1,TK>))
                OID       = FIELD(TICKET.ID,'.',1)
                INVN      = FIELD(TICKET.ID,'.',2)
                ERR.ENTRY = ''
                MATREAD LED FROM LEDFILE,OID ELSE GOTO DISP.NEXT.TKT
                IF LEN(INVN) = 3 THEN
                   LOCATE INVN+0 IN LED(8)<1> SETTING GEN ELSE GOTO DISP.NEXT.TKT
                END ELSE
                   LOCATE INVN+0 IN LED(12)<1> SETTING GEN ELSE GOTO DISP.NEXT.TKT
                END

                IF STP # OLD.STP THEN
                   READV CNAME FROM CUSFILE,LED(5)<1,GEN>,1 ELSE CNAME = LED(5)<1,GEN>
                   PRT.STR<-1> = STP            "R#3":'. '
                   PRT.STR := CNAME             "L#35"
                   IF PRT.ADDR THEN
                     *ADDR = RAISE(LED(78,1)<1,GEN>)
                     ADDR       = RAISE(LED(78)<1,GEN>)
                     ADDR<1,3> := ' ':LED(75)<1,GEN>
                     ADDR = TRIM(FIELD(ADDR,VM,1,3),VM)
                      FOR J = 1 TO DCOUNT(ADDR,VM)
                         PRT.STR<-1> = SPACE(5):ADDR<1,J> "L35"
                      NEXT J
                   END
                END
                *** Activate our CUS and CUSS arrays...
                PRC.BR = LED(2)<1,GEN,1>
                BT.CN  = LED(1)<1,GEN>
                ST.CN  = LED(5)<1,GEN>
                OE.GET.QSIGN QSIGN,OID,GEN
                GET.CUS BR,BT.CN,ST.CN,QSIGN
                *** See if the Order is flagged for COD...
                SOE.CREDIT.CHECK ST.CN,,COD,,,,,OID,GEN,
                IF COD THEN
                   READV COD.MSG FROM CTRLFILE,'MANIFEST.COD.MSG',1 ELSE
                      COD.MSG = ''
                   END
                   IF COD.MSG THEN
                      COD.CT = DCOUNT(COD.MSG, VM)
                      *** Print a line of !s...
                      PRT.STR<-1> = SPACE(5):STR('!',32)
                      *** Print the COD message...
                      FOR CC = 1 TO COD.CT
                         PRT.STR<-1>= SPACE(5):"!":COD.MSG<1,CC> "L#30":"!"
                      NEXT CC

                      *** Go determine the amount due on the order
                      *** to innclude with our COD message...
                      GOSUB GET.COD.TOTAL

                      *** Print the Order Total...
                      COD.TOTAL.MSG = "COD Order Total : ":OCONV(COD.TOTAL,'MR2')
                      PRT.STR<-1> = SPACE(5):"!":COD.TOTAL.MSG"L#30":"!"
                      *** Print a line of !s...
                      PRT.STR<-1> = SPACE(5):STR('!',32)
                   END
                END
                READV EXP.TM.DATA FROM LEDLFILE,OID,16 ELSE EXP.TM.DATA= ''
                EXP.TM = EXP.TM.DATA<1,GEN,1>
                ACT.TM = EXP.TM.DATA<1,GEN,2>
                PRT.STR<-1> = SPACE(5):TICKET.ID                "L#34":SPACE(22)

*                PRT.STR := STR('_',21)
                IF ORDER.PKGS THEN
                   READ LEDL FROM LEDLFILE,OID ELSE LEDL = ''
                   PACKAGES = LEDL<18>
                   FOR P = 1 TO PKG.CT
                      *** Keep track of package totals
                      BEGIN CASE
                      CASE P = 1
                         BOX.TOT += PACKAGES<1,GEN,P>
                      CASE P = 2
                         BAG.TOT += PACKAGES<1,GEN,P>
                      CASE P = 3
                         BND.TOT += PACKAGES<1,GEN,P>
                      CASE P = 4
                         LEN.TOT += PACKAGES<1,GEN,P>
                      END CASE
                      PRT.STR := PACKAGES<1,GEN,P>               "R#5":' '
                      *** End of package totals
                   NEXT P
                END ELSE
                   PRT.STR := SPACE(6*PKG.CT)
                END
                *PRT.STR := OCONV(DEL.TM,'MTH')"L#7":' '
                *PRT.STR := TIME.ZONE$'L#3':' '
                PRT.STR := ' ':STR('_',12)

                *** Get the weight and load totals
                MATREAD LED FROM LEDFILE,OID ELSE MAT LED = ''
                OE.GET.WEIGHT OID,GEN,TOL.PCS,TOL.WGHT,TOL.LOAD
                WGT.TOT += TOL.WGHT
                LOD.TOT += TOL.LOAD
                *** End of weight

                *** Shipping instructions if flagged
                IF PRT.SHIP AND LED(74)<1,GEN> THEN
                   SHIP.INSTR.LINES = DCOUNT(LED(74)<1,GEN>,SVM)
                   FOR INSTR.LINE   = 1 TO SHIP.INSTR.LINES
                      PRT.STR<-1> = SPACE(5):LED(74)<1,GEN,INSTR.LINE>
                   NEXT INSTR.LINE
                END

                *** Manifest comments
                CMNT.CT = DCOUNT(CMNT,VM)
                FOR L = 1 TO CMNT.CT
                   PRT.STR<-1> = SPACE(15):CMNT<1,L>
                NEXT L

                IF ORDER.PKGS THEN
                   PCKS = RAISE(RAISE(LEDL<20,GEN>))
                   LOCS = RAISE(RAISE(LEDL<22,GEN>))
                   CONVERT AM TO VM IN LOCS
                   LOCS = RAISE(LOCS)
                   QTYS = RAISE(RAISE(LEDL<23,GEN>))
                   CONVERT AM TO VM IN QTYS
                   QTYS = RAISE(QTYS)
                   L.CT = DCOUNT(LOCS,AM)
                   FOR L = 1 TO L.CT
                      PRT.STR<-1> = SPACE(5):('Staging Loc:':LOCS<L>)            "L#28"
                      FOR P = 1 TO PKG.CT
                         PRT.STR := QTYS<L,P>                    "R#5":' '
                      NEXT P
                      PRT.STR<-1> = ' '
                      PRT.STR<-1> = SPACE(10):('Pckd By:':PCKS<L,1>) "R#15":SPACE(9)


                   NEXT L
                END
                PRT.STR<-1> = SPACE(40):STR('_',21)
                PRT.STR<-1> = SPACE(80)
                PRT.STR<-1> = SPACE(34):'Print:':STR('_',21)
                PRT.STR<-1> = ' '
                PRT.STR<-1> = ' '
DISP.NEXT.TKT: *** Move on to the next ticket...
             NEXT TK

DISP.NEXT.STP: *** Move on to the next stop...
             IF NOT(ORDER.PKGS) THEN
                LOCS  = RAISE(RAISE(MNFST<36,STP>))
                TOTES = RAISE(RAISE(MNFST<38,STP>))
                T.CT = DCOUNT(TOTES,AM)
                FOR T = 1 TO T.CT
                   BOX.TOT += PKGS<T,1>+0
                   BAG.TOT += PKGS<T,2>+0
                   BND.TOT += PKGS<T,3>+0
                   LEN.TOT += PKGS<T,4>+0
                   PRT.STR<-1> = SPACE(12):LOCS<T>               "R#15":' '
                   FOR P = 1 TO PKG.CT
                      PRT.STR := PKGS<T,P>                       "R#5":' '
                   NEXT P
                   PRT.STR<-1> = ' '
                   PRT.STR<-1> = SPACE(12):TOTES<T>              "R#15"
                NEXT T
             END
             GOSUB PRT.STP
          NEXT STP

          FOR L = BLK.NO TO BLK.CT
             GOSUB DISP.BLK
             GOSUB PRT.STP
          NEXT L

          RETURN
*-------------------------------------------------------------------------*
PRT.STP:  *** Print out our stop checking to see if there is enough room
          *** to print the entire stop. If there isn't enough room then we
          *** page break, reset counters and start printing.
          *** If STP = 1 then we don't want to page break even if it's
          *** larger than the avail space, we only want to break when
          *** we've reached the body limit for stop 1.
          STR.CNT = DCOUNT(PRT.STR,AM)
          IF STP = 1 THEN
          *** Start printing stop #1 and keep track of the lines printed.
          *** If we exceed the avail bod lines, we'll page break,
          *** print the header and resume printing.
             FOR JJ = 1 TO STR.CNT
                LINE.CT +=1
                PRINT PRT.STR<JJ>
                IF LINE.CT = BOD.LNS THEN
                   PRINT CHAR(12)
                   GOSUB HEADER
                   LINE.CT = 0
                END
             NEXT JJ
             BOD.LNS = (BOD.LNS - LINE.CT)
          END ELSE
             *** Start printing stops > 2.
             *** Not enough room to print the enire stop.
             IF STR.CNT > BOD.LNS THEN
                IF BOD.LNS # 0 THEN GOSUB BARCODE
                GOSUB HEADER
                LINE.CT = 0
                FOR JJ  = 1 TO STR.CNT
                   LINE.CT +=1
                   PRINT PRT.STR<JJ>
                   *** If our stop is greater than 68 lines we'll break at
                   *** 68, print out the header and resume printing stop.
                   IF LINE.CT = BOD.LNS THEN
                      PRINT CHAR(12)
                      GOSUB HEADER
                      LINE.CT = 0
                   END
                NEXT JJ
                BOD.LNS = (BOD.LNS - LINE.CT)
          *** Enough room to print the entire stop.
             END ELSE
                FOR JJ = 1 TO STR.CNT
                   LINE.CT +=1
                   PRINT PRT.STR<JJ>
                NEXT JJ
                BOD.LNS = (BOD.LNS - LINE.CT)
             END
          END
          *** Clean up and get out.
          PRT.STR = ''; LINE.CT = 0

          RETURN
*-------------------------------------------------------------------------*
BARCODE:  ORD.ID = MANIFEST.NO
          PRINT CHAR(27):"*p1750x*p3175Y":
          UT.PRINT.BARCODE ERR.CODE,'CODE128',150,25,7,ORD.ID
          PRINT CHAR(12)
          RETURN
*-------------------------------------------------------------------------*
FOOTER:   *** Build the Totals strings...
          PRT.STR<1> = STR(' ', 62):'----- ----- ----- -----'
          PRT.STR<2> = '     Totals:':STR(' ', 15)
          PRT.STR := 'Weight:':OCONV(WGT.TOT, 'MR2':PRD.WGHT$) 'L#10'
          PRT.STR := '  Load:':OCONV(LOD.TOT, 'MR4') 'L#10'
          PRT.STR := BOX.TOT 'R#5':' '
          PRT.STR := BAG.TOT 'R#5':' '
          PRT.STR := BND.TOT 'R#5':' '
          PRT.STR := LEN.TOT 'R#5':' '
          PRINT PRT.STR<1>
          PRINT PRT.STR<2>
          PRT.STR = ''
          IF PAGE = 1 THEN
          GOSUB BARCODE
          END
          RETURN
*-------------------------------------------------------------------------*
SHIP.TICK:*** Print out ship tickets if flagged...
          ST.CT   = DCOUNT(MNFST<15>,VM)
          FOR STP = 1 TO ST.CT
             IDS         = MNFST<15,STP>
             TK.CT       = DCOUNT(IDS,SVM)
             FOR TK = 1 TO TK.CT
                TICKET.ID   = IDS<1,1,TK>
                OID         = FIELD(TICKET.ID,'.',1)
                INVN        = FIELD(TICKET.ID,'.',2)
                MATREAD LED FROM LEDFILE,OID ELSE GOTO NXT.TKT
                IF LEN(INVN) = 3 THEN
                   LOCATE INVN+0 IN LED(8)<1> SETTING GEN ELSE GOTO NXT.TKT
                END ELSE
                   LOCATE INVN+0 IN LED(12)<1> SETTING GEN ELSE GOTO NXT.TKT
                END
                MODE = OID[1,1]
                BEGIN CASE
                CASE MODE = 'T'
                   TOE.PRINT.ORDER OID,GEN,,'O'
                CASE MODE = 'P'
                   PRINT.HAZMAT = YES
                   POE.PRINT.ORDER OID,GEN,,'O',,,PRINT.HAZMAT
                CASE OTHERWISE
                   SOE.PRINT.ORDER OID,GEN,,'O'
                END CASE

                IF JAVA.PROC$ THEN
                   JAVA.DOC.ID = FIELD(JAVA.PASSER$<JP.DOC.ID$>,'#',2)
                   JAVA.FORM   = FIELD(JAVA.PASSER$<JP.FORM$>,'#',2)
                   DOC.IDS<-1> = JAVA.DOC.ID:VM:JAVA.FORM
                END

                * Print 'Yard Ticket'
                SOE.PRINT.YARD OID,GEN,,'T'
                IF JAVA.PROC$ THEN
                   YARD.DOC.ID = FIELD(JAVA.PASSER$<JP.DOC.ID$>,'#',2)
                   * If a Yard Ticket printed, then we should have a new
                   * Doc ID in Java Passer
                   IF YARD.DOC.ID # JAVA.DOC.ID THEN
                      JAVA.FORM   = FIELD(JAVA.PASSER$<JP.FORM$>,'#',2)
                      DOC.IDS<-1> = YARD.DOC.ID:VM:JAVA.FORM
                   END
                END

NXT.TKT:     NEXT TK
          NEXT STP

          RETURN
*-------------------------------------------------------------------------*
DISP.BLK: *  display block out record

          PRT.STR<-1> = '     ***** TIME BLOCKED - '
          PRT.STR := MNFST<14,BLK.NO,3>      "L#35"

          PRT.STR<-1>= SPACE(24+PKG.WD):OCONV(BLK.FRM,'MTH') "L#7":' thru '
          PRT.STR := OCONV(MNFST<14,BLK.NO,2>,'MTH') "L#7"
          PRT.STR := ' ':TIME.ZONE$'L#3'
          PRT.STR<-1> = ' '
          PRT.STR<-1> = ' '

          BLK.NO += 1
          BLK.FRM = MNFST<14,BLK.NO,1>

          RETURN
*-------------------------------------------------------------------------*
GET.COD.TOTAL: * Calculate the amount due for COD Orders...

          OE.ORDER.TOTAL OID,GEN,QSIGN,TOTAL,SUB.TOL,FGHT,HNDL,TAX.TOL
          SOE.CALC.CASH OID,GEN,ORIG.AMT.DUE,AMT.PAID,CASH.DISC

          *** Get WOE.DISC
          SOE.CALC.DISC OID,GEN,,,WOE.DISC
          CASH.DISC += WOE.DISC

          IF AMT.PAID THEN
             AR.ID = OID:'.':LED(8)<1,GEN>"R%3"
             READ ARREC2 FROM ARFILE,AR.ID ELSE ARREC2 = ''
             CASH.DISC.PAID = ASUB.GET.AMT(ARREC2,,,GL.AUTO.DISCG)
             IF CASH.DISC.PAID > 0 THEN AMT.PAID += CASH.DISC.PAID
          END

          *** Get the Federal Excise Tax...
          FET.MODE = 'S'
          OE.CALC.FET.AMT FET.MODE,OID,GEN,QSIGN,FET

          *** Calculate the amount due for this COD order...
          COD.TOTAL = SUB.TOL+FGHT+HNDL+TAX.TOL+AMT.PAID+CASH.DISC+FET
          IF COD.TOTAL = CASH.DISC THEN COD.TOTAL = 0

          RETURN
*-------------------------------------------------------------------------*
!SMITJR~12/15/10~11:25
