          SUBROUTINE (OID,GEN,NUM.PGS,STATUS,PSTYLE.OVRD,PRT.ON,DRPT,DOC.ID,LOC.OVRD)
** Version# 15.0311[2] - 02/19/2010 - 09:26am - SMITJR - eclipse
*** V15.0311 Change - Custom Coding CUSTOM - 02/19/2010 - SMITJR - eclipse
*** V15.031 Change - Custom Coding FORMS.MOD - 11/13/2008 - ROYO - eclipse
** Copied from UBP SOE.PRINT.ORDER Version# 15.0309 - 10/22/2008 - 09:19am - BILLB - eclipse
*** V15.0309 Change - Custom Coding CYK597 - 10/22/2008 - BILLB - eclipse
*** V15.0308 Change - Custom Coding HDB282 - 10/17/2007 - HEATHERY - UPGRADE
*** V15.0307 Change - Custom Coding CUH372 - 06/04/2007 - MNAVEEN - eclipse
*** V15.0307 Change - Custom Coding CUH372 - 05/24/2007 - MNAVEEN - eclipse
*** V15.0307 Change - Custom Coding CUH372 - 05/23/2007 - MNAVEEN - eclipse
*** V15.0307 Change - Custom Coding CUH372 - 05/16/2007 - MNAVEEN - eclipse
*** V15.0307 Change - Custom Coding CUH372 - 05/15/2007 - MNAVEEN - eclipse
*** V15.0306 Change - Custom Coding HEJ984 - 04/06/2005 - BARSPA - eclipse
*** V15.0306 Change - Custom Coding HEJ984 - 04/05/2005 - BARSPA - eclipse
*** V15.0305 Change - Custom Coding DIW234 - 11/03/2004 - BARSPA - eclipse
*** V15.0304 Change - Custom Coding CRX856 - 08/17/2004 - JONW - UPGRADE
*** V15.0303 Change - Custom Coding BCL412 - 08/08/2002 - JONW - UPGRADE
*** V15.0302 Change - Custom Coding DAU330 - 05/15/2001 - ROELANTV - eclipse
*** V15.0301 Change - Custom Coding DAU330 - 05/03/2001 - ROELANTV - eclipse

*** Subroutine - SOE.PRINT.ORDER
*-------------------------------------------------------------------------*
*** Prints ship tickets, acks, bids, pick tickets, work tickets.
*** All subroutines that need to print invoices, bids, ship tickets, pick
*** tickets and acks should call this subroutine.
*** This subroutine will then either print the form call the appropriate
*** subroutine to print the form requested.
*** Uses page 1 of n logic.
*-------------------------------------------------------------------------*
*** Variables:
***       OID         - Order ID                                      [In]
***       GEN         - Order generation                              [In]
***       NO.PT       - Variable Not Being Used                       [In]
***       STATUS      - Print status determines which form will print [In]
***       PSTYLE.OVRD - Print style override                          [In]
***       PRT.ON      - Printer on flag                               [In]
***       DRPT        - Report Defaults                               [In]
***       LOC.OVRD    - Location Override, if this is set then the    (IN)
***                     location will not be changed when printing
***                     ship tickets.
*-------------------------------------------------------------------------*
*** Common: LED, LD, CUS, CUSS, PRD, DRPT, PHANTOM.PROC
*-------------------------------------------------------------------------*

          DIM PSTYL(10)

          IF STATUS = 'O' THEN STATUS = 'T'

          IF STATUS='I' THEN
             SOE.PRINT.INVOICE.OLD OID,GEN,PSTYLE.OVRD,PRT.ON,DRPT,NUM.PGS
             RETURN
          END

          IF STATUS='B' THEN
             SOE.PRINT.BID.OLD OID,GEN,PSTYLE.OVRD,PRT.ON,DRPT
             RETURN
          END


    * Force last column to be Net for Cash Sales and Invoices
          ST.CN = LED(5)<1,GEN>

          SOE.CREDIT.CHECK ST.CN,,COD,PRT.MSG,NO.SHIP,,,OID,GEN
          CASH.SALE  = NO

          BEGIN CASE
          CASE COD
             STYLE.ID = 'NET'
          CASE CASH.SALE AND STATUS = 'T'
             IF LED(77)<1,GEN>='B' THEN STYLE.ID = 'BN' ELSE STYLE.ID = 'N'
          CASE PSTYLE.OVRD#''
             STYLE.ID = PSTYLE.OVRD
          CASE OTHERWISE
             STYLE.ID = LED(77)<1,GEN>
          END CASE

          IF STYLE.ID = 'CONSOLIDAT' THEN
             SOE.PRINT.ORDER.CUST OID,GEN,NUM.PGS,STATUS,PSTYLE.OVRD,PRT.ON,DRPT,LOC.OVRD

             RETURN
          END



          UT.OPEN.FILE "PRINT.STYLES",PSTYLFILE,ERR.MSG
          IF ERR.MSG THEN RETURN
          SV.LOC = LOCATION
                                                                           
          PG.LGTH = 66

          IF NOT(PHANTOM.PROC) AND NOT(PRT.ON) THEN
             WINDOW 15,8,50,5
             PRINT @(0,1):'Printing .... ':OID
          END

          MATREAD LED FROM LEDFILE,OID ELSE GOTO FINISH
*LOT
          IF LED(98)<1,GEN> THEN LOT.FLAG = YES ELSE LOT.FLAG = NO

          OE.GET.QSIGN QSIGN,OID,GEN
          BR    = LED(2)<1,GEN,1>
          STK.BR= LED(2)<1,GEN,2>
          BT.CN = LED(1)<1,GEN>
          ST.CN = LED(5)<1,GEN>
          GET.CUS BR,BT.CN,ST.CN,QSIGN

          CLOSED.GEN = (LED(8)<1,GEN> OR LED(6)<1,GEN>='T')
          IF NOT(CLOSED.GEN) THEN
             LDIDS = LED(49)
             CONVERT VM TO SVM IN LDIDS
          END ELSE
             LDIDS = LED(48)<1,GEN>
          END

          IF NOT(PRT.ON) THEN
             IF STATUS = 'O' OR STATUS = 'T' THEN
                PL.OPTS    = ''   ;* used to specify specific location
                                  ;* to be returned.
                PL.OPTS<1> = YES  ;* get loc for shipticket branch
                PL.OPTS<2> = YES  ;* return first match
                PL.OPTS<4> = LED(70)<1,GEN> ;* shipvia for loc override
                UT.GET.PTR.LOCS LED(2)<1,GEN,2>,LOCATION,PL.OPTS,ERR.MSG
                IF LOCATION = "HERE" THEN
                   LOCATION = SV.LOC
                END
             END
             IF LOC.OVRD THEN
                LOCATION = LOC.OVRD
             END
             PRINTER.ON "SALES.ORDER",RPT.DFLT=DRPT
          END

          GOSUB INIT
          GOSUB HEADER

      ** Sort Items in location order
          IF LED(6)<1,GEN>='T' THEN
             SRT.LOCS  = ''
             SRT.LDIDS = ''
             LD.CT = DCOUNT(LDIDS,SVM)
             FOR J = 1 TO LD.CT
                LDID  = LDIDS<1,1,J>
                LD.GETV PN, LDID, 1
                IF PN#'' AND NUM(PN) THEN
                   * Release 8 start
                   * READV LOCS FROM PRDDFILE,PN,8 ELSE LOCS = ''
                   * LOC = LOCS<1,STK.BR,1>
                   READV LOCS FROM PRDDFILE,PN:"*":STK.BR,8 ELSE LOCS = ''
                   LOC = LOCS<1,1>
                   * release 8 end
                   LOCATE LOC IN SRT.LOCS BY 'AL' SETTING POS ELSE NULL
                   SRT.LOCS  = INSERT(SRT.LOCS,POS;LOC)
                   SRT.LDIDS = INSERT(SRT.LDIDS,1,1,POS;LDID)
                END
             NEXT J
             LDIDS = SRT.LDIDS
          END

          LDID.CT = DCOUNT(LDIDS,SVM)
          FOR LD.NO = 1 TO LDID.CT
             LDID   = LDIDS<1,1,LD.NO>
             GOSUB PRT.LINE
          NEXT LD.NO

          IF NOT(NO.TOLS) THEN
             SUBT.DESC = 'ORDER TOTAL   '
             GOSUB SUBTOTALS
             LINE.CT -= 2
          END

          RUNNING.TOTAL = COL.TOTAL<1,COL.CT>

          GOSUB FOOTER

          IF NOT(PRT.ON) THEN
             PRINTER.OFF
          END
                                                                           
          GOTO FINISH
*-------------------------------------------------------------------------*
INIT:     *
          SSPC       = 12
          PAGE       = 0
          IN.FOOTER  = NO
          PRINT.PICK = NO
          CASH.SALE  = NO
          LNE        = 0

          BEGIN CASE
          CASE STATUS = 'T'
             INVN    = LED(8)<1,GEN>
             IF INVN THEN
                ORD.ID  = OID:'.':INVN"R%3"
             END ELSE ORD.ID = OID
             DOC.ID    = 'S H I P P I N G    O R D E R'
             DOC.TYPE = 'T'
          CASE OTHERWISE
             DOC.ID   = 'A C K N O W L E D G E M E N T'
             ORD.ID   = OID
             DOC.TYPE = 'S'
          END CASE

          IF DRPT<27> ='HOLD' THEN  ;* Override printer error if hold/email
             OE.LOG.PRINT OID,GEN,DOC.TYPE:VM:1,DOC.ID,REPRINT
          END ELSE
             OE.LOG.PRINT OID,GEN,DOC.TYPE,DOC.ID,REPRINT
          END

          SOE.CREDIT.CHECK ST.CN,,COD,PRT.MSG,NO.SHIP,,,OID,GEN

    * Force last column to be Net for Cash Sales and Invoices
          BEGIN CASE
          CASE COD
             STYLE.ID = 'NET'
          CASE CASH.SALE AND STATUS = 'T'
             IF LED(77)<1,GEN>='B' THEN STYLE.ID = 'BN' ELSE STYLE.ID = 'N'
          CASE PSTYLE.OVRD#''
             STYLE.ID = PSTYLE.OVRD
          CASE OTHERWISE
             STYLE.ID = LED(77)<1,GEN>
          END CASE

          GOSUB GET.PSTYLE

          COLUMN.HEADING1 = SPACE(12):'Product':SPACE(24):'Bin    Qty   Qty     Qty'
          COLUMN.HEADING2 = 'Ln Code-No. Description                    Loc    Order To Pick Shippd'

     **   CONVERT ' ' TO '-' IN COLUMN.HEADING2

    * Compile column heading line from print style record
          TOTAL.SPACES = COL.START
          FMT = 'L#':COL.START
          COLUMN.HEADING2 = COLUMN.HEADING2 FMT

          FOR COL = 1 TO COL.CT
             LGTH = FIELD(COL.FRMTS<1,COL>,'#',2)+0
             FRMT = 'L#':LGTH
             IF COL=COL.CT THEN
                TOTAL.FRMT = COL.FRMTS<1,COL>
             END ELSE
                TOTAL.SPACES = TOTAL.SPACES + LGTH
             END
             COLUMN.HEADING2 = COLUMN.HEADING2:COL.HEADS<1,COL> FRMT
          NEXT COL

          NO.TOLS  = NOT(COL.EXTDS<1,COL.CT>)
          NET.TOLS = (COL.BASIS<1,COL.CT>=1 OR COL.BASIS<1,COL.CT>=2)

          GOSUB GET.TOTALS

          PRINT.CREDIT.MSG = (PRT.MSG AND STATUS = 'T')

          RETURN
*-------------------------------------------------------------------------*
GET.PSTYLE: * Get Print style record
          MATREAD PSTYL FROM PSTYLFILE,STYLE.ID ELSE
             MATREAD PSTYL FROM PSTYLFILE,'DEFAULT' ELSE
                MAT PSTYL = ''
                PSTYL(3) = 69
                PSTYL(4) = 'R2#10'
                PSTYL(5) = 1
                PSTYL(6) = 1
                PSTYL(7) = 'Net Price'
             END
          END

          COL.START = PSTYL(3)
          COL.FRMTS = PSTYL(4)
          COL.BASIS = PSTYL(5)
          COL.EXTDS = PSTYL(6)
          COL.HEADS = PSTYL(7)
          ALT.DESC  = PSTYL(8)
          COL.CT    = DCOUNT(COL.BASIS,VM)
          COL.TOTAL = ''
          SUB.TOTAL = ''

          RETURN
*-------------------------------------------------------------------------*
HEADER:   *
          PAGE     = PAGE + 1
          LINE.CT  = PG.LGTH
          CUS.PO   = LED(13)<1,GEN>
          JOB.NO   = LED(65)<1,GEN>
          IF JOB.NO = "" THEN JOB.NO = LED(65)<1,1>
          SALESMAN = LED(72)<1,GEN>
          SHIP.VIA = LED(70)<1,GEN>
          ORD.DATE = LED(4)<1,GEN>
          SHP.DATE = LED(9)<1,GEN>
          EXP.DATE = LED(31)<1,GEN>
          WRITER   = LED(73)<1,GEN>
          TAX.CD   = LED(79)<1,GEN>
          OE.GET.WEIGHT OID,GEN,TOL.PCS,TOL.WGHT,TOL.LOAD

          IF LED(69)<1,GEN,1> THEN
             FRGT.ALLWD = 'YES'
          END ELSE
             FRGT.ALLWD = 'NO'
          END

          READV BR.EN FROM TERRFILE,BR,4 ELSE BR.EN = ''
          READ CUS.BR FROM CUSFILE,BR.EN ELSE CUS.BR = ''
          BR.ADDR = CUS.BR<1>
          IF CUS.BR<2,1> # '' THEN BR.ADDR<-1> = CUS.BR<2,1>
          IF CUS.BR<2,2> # '' THEN BR.ADDR<-1> = CUS.BR<2,2>
          BR.ADDR<-1> = CUS.BR<3>:' ':CUS.BR<4>:' ':CUS.BR<5>

          PRINT SPACE(40-INT(LEN(DOC.ID)/2)):DOC.ID
          PRINT

          FOR B = 1 TO 4
             PRINT SPACE(30):BR.ADDR<B>"L#35"
          NEXT B

          IF COD THEN
             PRINT SPACE(30):'** C.O.D. ** C.O.D. ** C.O.D. **'
          END ELSE
             PRINT
          END

          TERMS.ID = LED(29)<1,GEN>
          READV TERMS.DESC FROM TERMSFILE,TERMS.ID,1 ELSE TERMS.DESC=''
*B2B
          SHIP.ADDR = LED(78)<1,GEN,6>
          IF NOT(SHIP.ADDR) THEN SHIP.ADDR = CUSS(1)
          IF LED(78)<1,GEN,1> # '' THEN SHIP.ADDR<-1> = LED(78)<1,GEN,1>
          IF LED(78)<1,GEN,2> # '' THEN SHIP.ADDR<-1> = LED(78)<1,GEN,2>
          SHIP.ADDR<-1> = TRIM(LED(78)<1,GEN,3>):" ":LED(75)<1,GEN>"L#10"

          BILL.ADDR = CUS(1)
          IF CUS(2)<1,1> # '' THEN BILL.ADDR<-1> = CUS(2)<1,1>
          IF CUS(2)<1,2> # '' THEN BILL.ADDR<-1> = CUS(2)<1,2>
          BILL.ADDR<-1> = CUS(3):' ':CUS(4):' ':CUS(5)

     * Header Bill To / Ship To
          PRINT 'SOLD TO:':SPACE(12):
          PRINT SPACE(5):SPACE(15):'SHIP TO:':CHAR(13):
          PRINT STR(CHAR(95),38):SPACE(2):STR(CHAR(95),38)

          FOR B = 1 TO 4
             PRINT "| ":BILL.ADDR<B>'L#35':"|":SPACE(2):"| ":SHIP.ADDR<B>'L#35':"|"
          NEXT B

          PRINT "| ":SPACE(35):"|":SPACE(2):"| ":SPACE(35):'|':CHAR(13):
          PRINT STR(CHAR(95),38):SPACE(2):STR(CHAR(95),38)

          PRINT STR(CHAR(95),80)

      * Header Information Line# 1
          PRINT '|Order Date| Sales Ticket No.| Customer P.O. #     | Writer| Slsmn | Tx-Cde    |'
          PRINT '|':OCONV(ORD.DATE,'D2/')'L#10':'|':ORD.ID'L#17':'|':CUS.PO'L#21':'|':WRITER 'L#7':'|':SALESMAN "L#7":"|":TAX.CD 'L#11':'|'
          PRINT '|          |                 |                     |       |       |           |':CHAR(13):
          PRINT STR(CHAR(95),80)

      * Header Information Line# 2
          PRINT '|Date Shipped| Ship Via      | Frt Allow| Weight  | Job Name                   |'
          PRINT '|':OCONV(SHP.DATE,'D2/') "L#12":"|":
          PRINT SHIP.VIA "L#15":"|":
          PRINT "    ":FRGT.ALLWD "L#6":'|':
          PRINT OCONV(TOL.WGHT,'MR4') "L1#9":"|":
          PRINT JOB.NO "L#28":'|'
          PRINT '|            |               |          |         |                            |':CHAR(13):
          PRINT STR(CHAR(95),80)

      * Column Headings
          PRINT
          PRINT COLUMN.HEADING1
          PRINT COLUMN.HEADING2:CHAR(13):STR(CHAR(95),80)
                                                                           
          LINE.CT -= 23

          SHP.INST = LED(74)<1,GEN>

          BO.FLAG = YES

          SHIP.INST = SHP.INST<1,1,1>
          SHIP.INST = UPCASE(SHIP.INST)
          IF SHIP.INST = "!NOBO" THEN
             BO.FLAG = NO
             SHP.INST    = DELETE(SHP.INST,1,1,1)
          END



          IF SHP.INST#'' AND PAGE=1 THEN
             GOSUB SUBT.ONE
             PRINT SPACE(SSPC):'********* Shipping Instructions **********'
             CT = DCOUNT(SHP.INST,SVM)
             FOR JJ=1 TO CT
                GOSUB SUBT.ONE
                PRINT SPACE(SSPC):'* ':SHP.INST<1,1,JJ>"L#38":' *'
             NEXT JJ
             GOSUB SUBT.ONE
             PRINT SPACE(SSPC):STR('*',42)
          END

          BO.HEADING = NO

          RETURN
*-------------------------------------------------------------------------*
SUBTOTALS: *
          PRT.STR1 = SPACE(COL.START)
          PRT.STR2 = SPACE(COL.START-LEN(SUBT.DESC)):SUBT.DESC

          FOR COL = 1 TO COL.CT
             LGTH = FIELD(COL.FRMTS<1,COL>,'#',2)
             IF COL.EXTDS<1,COL> THEN
                PRT.STR1 = PRT.STR1:STR('-',LGTH)
                PRT.STR2 = PRT.STR2:COL.TOTAL<1,COL> COL.FRMTS<1,COL>
             END ELSE
                PRT.STR1 = PRT.STR1:SPACE(LGTH)
                PRT.STR2 = PRT.STR2:SPACE(LGTH)
             END
          NEXT COL

          PRINT PRT.STR1
          PRINT PRT.STR2

          RETURN
*-------------------------------------------------------------------------*
GET.TOTALS: *
          SOE.CALC.CASH OID,GEN,AMT.DUE,AMT.PAID,CASH.DISC
          OE.ORDER.TOTAL OID,GEN,QSIGN,,,FREIGHT,HANDLING,TAX.AMT
          IF STATUS='B' OR STATUS = "T" THEN CASH.DISC = 0
          AMT.PAID  = OCONV(AMT.PAID,'MR2')
          FREIGHT   = OCONV(FREIGHT,'MR2')
          HANDLING  = OCONV(HANDLING,'MR2')
          TAX.AMT   = OCONV(TAX.AMT,'MR2')
          CASH.DISC = OCONV(CASH.DISC,'MR2')

  * Find service Charges , put in OE.ORDER.TOTAL when possible
          LOCATE 'SC' IN LED(24)<1,GEN> SETTING POS THEN
             SERV.CHRG = -OCONV(LED(26)<1,GEN,POS>,'MR2')
          END ELSE
             SERV.CHRG = 0
          END

          RETURN
*-------------------------------------------------------------------------*
PRINT.TOTALS: *
          IF TAX.AMT THEN
             TOTAL.COMMENT = 'Sales tax'
             TOTAL.AMT     = TAX.AMT
             GOSUB PRINT.TOTAL
             RUNNING.TOTAL += TOTAL.AMT
          END

          IF FREIGHT THEN
             TOTAL.COMMENT = 'Freight'
             TOTAL.AMT     = FREIGHT
             GOSUB PRINT.TOTAL
             RUNNING.TOTAL += TOTAL.AMT
          END

          IF HANDLING THEN
             TOTAL.COMMENT = 'Handling'
             TOTAL.AMT     = HANDLING
             GOSUB PRINT.TOTAL
             RUNNING.TOTAL += TOTAL.AMT
          END

          IF SERV.CHRG THEN
             TOTAL.COMMENT = 'Service Charge'
             TOTAL.AMT     = SERV.CHRG
             GOSUB PRINT.TOTAL
             RUNNING.TOTAL += TOTAL.AMT
          END
                                                                           
          GOSUB PRINT.TOTAL.LINE
          TOTAL.COMMENT = 'Invoice Amount'
          TOTAL.AMT     = RUNNING.TOTAL
          GOSUB PRINT.TOTAL

          PRINT.AMT.DUE = NO
          CASH.DISC2    = CASH.DISC
          IF CASH.DISC AND NET.TOLS AND (STATUS#'I' OR RUNNING.TOTAL+CASH.DISC=0) THEN
             TOTAL.COMMENT = 'Less cash disc'
             TOTAL.AMT     = CASH.DISC
             CASH.DISC     = 0
             GOSUB PRINT.TOTAL
             RUNNING.TOTAL = RUNNING.TOTAL + TOTAL.AMT
             PRINT.AMT.DUE = YES
          END

          IF AMT.PAID THEN
             PRINT.AMT.DUE = YES
             IF LED(8)<1,GEN>='' THEN
                TOTAL.COMMENT = 'Less cash paid'
                TOTAL.AMT     = AMT.PAID
                GOSUB PRINT.TOTAL
                RUNNING.TOTAL = RUNNING.TOTAL + TOTAL.AMT
             END ELSE
                AR.ID = OID:'.':LED(8)<1,GEN>"R%3"
                SOE.PAYMENTS.DISC AR.ID,PAY.IDS,PAY.DTS,PAY.AMTS,DISC.TAKEN
                IF DISC.TAKEN THEN
                   TOTAL.COMMENT = 'Less discount taken'
                   TOTAL.AMT     = OCONV(DISC.TAKEN,"MR2")
                   CASH.DISC     = 0
                   GOSUB PRINT.TOTAL
                   RUNNING.TOTAL = RUNNING.TOTAL + TOTAL.AMT
                END

                PCT = DCOUNT(PAY.IDS,VM)

                FOR PYN = 1 TO PCT
                   PAY.ID  = PAY.IDS<1,PYN>
                   PAY.DT  = PAY.DTS<1,PYN>
                   PAY.AMT = PAY.AMTS<1,PYN>
                   IF PAY.DT=DATE() THEN
                      TOTAL.COMMENT = 'Amount paid today - Payment # ':PAY.ID"L#12"
                   END ELSE
                      TOTAL.COMMENT = 'Prior Deposit on ':OCONV(PAY.DT,'D2/')"L#8" :' - Payment # ':PAY.ID"L#12"
                   END
                   TOTAL.AMT = OCONV(PAY.AMT,"MR2")
                   GOSUB PRINT.TOTAL
                   RUNNING.TOTAL = RUNNING.TOTAL + TOTAL.AMT
                NEXT PYN
             END
          END

          IF PRINT.AMT.DUE THEN
             GOSUB PRINT.TOTAL.LINE
             TOTAL.COMMENT = '** AMOUNT DUE **'
             TOTAL.AMT     = RUNNING.TOTAL
             GOSUB PRINT.TOTAL
          END
                                                                           
          RETURN
*-------------------------------------------------------------------------*
PRINT.TOTAL: *
          GOSUB SUBT.ONE
          PRT.STR = SPACE(TOTAL.SPACES-LEN(TOTAL.COMMENT)-13)
          PRT.STR = PRT.STR:TOTAL.COMMENT:''"L#13"
          PRT.STR = PRT.STR:TOTAL.AMT TOTAL.FRMT
          PRINT PRT.STR

          RETURN
*-------------------------------------------------------------------------*
PRINT.TOTAL.LINE: *
          GOSUB SUBT.ONE
          LGTH = FIELD(TOTAL.FRMT,"#",2)
          PRT.STR = SPACE(TOTAL.SPACES):STR('-',LGTH)
          PRINT PRT.STR

          RETURN
*-------------------------------------------------------------------------*
PRT.LINE: *
          LD.GET LDID
          PN = LD(1)

          BEGIN CASE
          CASE NUM(PN)
             QS = (SUM(LD(5)<1,GEN>) + SUM(LD(6)<1,GEN>)) * QSIGN
             IF QS#0 THEN GOSUB PRT.PN
          CASE PN='C'
             OE.DESC.GET DESC,ALT.DESC,"SOE Printing"
             GOSUB PRT.XDESC
*LOT
          CASE PN = 'S'
             IF NOT(LOT.FLAG) THEN
                SUBT.SW   = YES
                GOSUB PRT.SUBT
                SUBT.SW   = NO
                SUB.TOTAL = ''
             END
          END CASE

          RETURN
*-------------------------------------------------------------------------*
PRT.PN:   *
          GET.ALL.PRD BR,PN,QSIGN,GROUP

          DFLT.PER.GET OID[1,1],PER,UM
          SHP.TYP.LOCS = LD(7)<1,GEN>
          LOC.CT  = DCOUNT(SHP.TYP.LOCS,SVM)

          *** Check whether the product is flagged for Serial Number
          *** Tracking at the Shipping Branch...
          PRD.BR.GET.VAL STK.BR,PN,25,SERIAL.TRACKING

          FOR LOC = 1 TO LOC.CT

          QS   = (LD(5)<1,GEN,LOC> + LD(6)<1,GEN,LOC>) * QSIGN
          IF QS=0 THEN GOTO NO.PTR

          OE.DESC.GET DESC,ALT.DESC,"SOE Printing"

          CODE    = FIELD(PRD(4)," ",2)

          IF STATUS # 'B' AND SERIAL.TRACKING AND SERIAL.TRACKING # "N" THEN
             FOR XX=1 TO QS
                DESC<1,-1> = 'Serial#____________________________'
             NEXT XX
          END

 *----Kits                                                                 
          BEGIN CASE
              CASE CUS(74) = "Yes"
                  IF LD(31) # '' THEN
                      KCMPS = LD(31)
                      KQTYS = LD(30)
                      KCMTS = LD(37)
                      GET.KIT.COMPS.LOC.ALT KCMPS,KQTYS,KCMTS,45,DESC,STK.BR,ALT.DESC,GEN.QS
                   END
              CASE CUS(74) = "Default" OR CUS(74) = ''
                   IF LD(31) # '' AND LD(38)<1,2> = '1' THEN
                         KCMPS = LD(31)
                         KCMTS = LD(37)
                         KQTYS = LD(30)
                         GET.KIT.COMPS.LOC.ALT KCMPS,KQTYS,KCMTS,45,DESC,STK.BR,ALT.DESC,GEN,QS
                    END
              CASE OTHERWISE
              END CASE

          IF LED(8)<1,GEN> = '' THEN
             QOPEN = QS
             DQS    = ''
          END ELSE
             OE.CALC.QOPEN OID,QSIGN,QOPEN
             IF LED(8)<1,GEN> THEN QOPEN += ((SUM(LD(5)<1,GEN>) + SUM(LD(6)<1,GEN>)) * QSIGN)
             DQS = QS
          END
*LOT
          IF LOT.FLAG THEN
             DQS   = 1
             QS    = 1
             QOPEN = 1
          END

          SHP.TYP.LOC = SHP.TYP.LOCS<1,1,LOC>
          LOCA    = FIELD(FIELD(SHP.TYP.LOC,'~',2),'^',1)
          TYPE    = FIELD(SHP.TYP.LOC,'~',1)
          IF LOCA = 'WHSE' THEN PRINT.PICK = YES

          IF TYPE = 'T' THEN
             TAG = FIELD(SHP.TYP.LOC,'^',2)
             TAG = FIELD(TAG,'.',1)
             DESC<1,-1> = '<<** ':QS:' Tagged to ':TAG[1,OID.LGTH$]:' **>>'
          END

          BEGIN CASE
          CASE QS<0 AND TYPE='F';  LOCA = '**DEF '
          CASE QS>0 AND TYPE='D';  LOCA = '**DIR '
          CASE QS<0;               LOCA = '**RTN '
          CASE OTHERWISE;          LOCA = LOCA"L#7"
          END CASE

          LNE +=1
          IF PER THEN QOPEN = QOPEN/PER
          IF LOC > 1 THEN QOPEN = '"'

          PRT.STR = LNE                 "R#2":' '
          PRT.STR = PRT.STR:CODE        "L#8":' '
          PRT.STR = PRT.STR:DESC<1,1>   "L#30":' '
          PRT.STR = PRT.STR:LOCA        "L#7":' '
          PRT.STR = PRT.STR:QOPEN       "R#4":' '

          IF PER THEN
             PRT.STR = PRT.STR:DQS/PER  "R#7":' '
          END ELSE
             PRT.STR = PRT.STR:DQS      "R#7":' '
          END

          PRT.STR = PRT.STR:''          "L#5"

          GOSUB SUBT.ONE
*LOT
          IF LOT.FLAG THEN
             PRT.STR  := SPACE(6)
             IF LED(8)<1,GEN> = '' THEN
                PRT.STR := OCONV(LD(67)<1,1>,'MR9') "R3#11"
                PRT.STR := OCONV(LD(67)<1,1>,'MR9') "R2#10"
                COL.TOTAL<1,COL.CT> += OCONV(LD(67)<1,1>,'MR9')
             END ELSE
                PRT.STR := (OCONV(LD(8)<1,GEN,1>,'MR9')) "R3#11"
                PRT.STR := (OCONV(LD(8)<1,GEN,1>,'MR9')) "R2#10"
                COL.TOTAL<1,COL.CT> += (OCONV(LD(8)<1,GEN,1>,'MR9'))
             END
          END ELSE
             OE.GET.PSTYLE OID,GEN,COL.START,COL.FRMTS,COL.BASIS,COL.EXTDS,COL.CT,QS,PRT.STR,COL.TOTAL,SUB.TOTAL
          END

          PRINT PRT.STR:
          PRINT CHAR(13):SPACE(50):STR("_",21)
          DESC = DELETE(DESC,1,1)
          GOSUB PRT.XDESC

NO.PTR:   NEXT LOC
*LOT
          IF LOT.FLAG THEN
             GOSUB LOT.SUB
          END

          RETURN
*-------------------------------------------------------------------------*
PRT.XDESC: *
          DESC.CT = DCOUNT(DESC,VM)
          FOR DLN = 1 TO DESC.CT
             GOSUB SUBT.ONE
             PRINT SPACE(SSPC):DESC<1,DLN>"L#35"
          NEXT DLN

          RETURN
*-------------------------------------------------------------------------*
PRT.SUBT: *
          OE.DESC.GET DESC,ALT.DESC,"SOE Printing"
          SUBT.DESC = DESC<1,1>
          LINE.CT -= 2
          GOSUB SUBTOTALS
          DESC = DELETE(DESC,1,1)
          GOSUB PRT.XDESC

          RETURN
*-------------------------------------------------------------------------*
PRT.BO:   *
          GN.CT  = DCOUNT(LED(12),VM)

          FOR GN = 1 TO GN.CT
             BO.HEADING = NO
             STAT   = LED(6)<1,GN,1>
             OBR = LED(2)<1,GN,1>
             SBR = LED(2)<1,GN,2>
             IF LED(8)<1,GN>='' AND STAT#'T' AND STAT#'X' AND STAT#'$' AND STAT#'B' AND STAT#'Y' AND STAT#'D' THEN
                LDIDS = LED(48)<1,GN>
                LD.CT = DCOUNT(LDIDS,SVM)
                FOR LLN = 1 TO LD.CT
                   LDID  = LDIDS<1,1,LLN>
                   LD.GET LDID
                   QTY   =  (SUM(LD(5)<1,GN>) + SUM(LD(6)<1,GN>)) * QSIGN
                   IF NUM(LDID) AND LDID#'' AND QTY AND STK.BR=SBR THEN
                      PN = LD(1)
                      GET.ALL.PRD BR,PN,QSIGN,GROUP
                      OE.DESC.GET DESC,ALT.DESC,"SOE Printing"
                      IF NOT(BO.HEADING) THEN
                         GOSUB SUBT.ONE
                         PRINT
                         GOSUB SUBT.ONE
                         PRINT SPACE(10):'** The following are backordered **'
                         BO.HEADING = YES
                      END
                      GOSUB SUBT.ONE
                      PRINT SPACE(20):QTY"R#6":' - ':DESC<1,1>"L#35"
                      DESC = DELETE(DESC,1,1)
                      GOSUB PRT.XDESC
                   END
                NEXT LLN
             END
          NEXT GN

          RETURN
*-------------------------------------------------------------------------*
SUBT.ONE: *
          IF LINE.CT<18 THEN
             IF NOT(IN.FOOTER) AND PN#'S' AND NOT(NO.TOLS) THEN
                SUBT.DESC = 'Subtotal Thru Page # ':PAGE:' ---- '
                GOSUB SUBTOTALS
                LINE.CT -= 2
             END ELSE
                PRINT
                PRINT SPACE(50):'*** Continued on Next Page ***'
                LINE.CT -= 2
             END
             GOSUB FFEED
             GOSUB HEADER
          END

          LINE.CT -= 1

          RETURN
*-------------------------------------------------------------------------*
FOOTER:   *
          IN.FOOTER = YES
          IF NOT(NO.TOLS) THEN GOSUB PRINT.TOTALS

          IF STATUS='T' AND BO.FLAG THEN GOSUB PRT.BO

          IF PRINT.CREDIT.MSG THEN
             PRINT STR('+ ',35)
             PRINT '+   Thank You For Your Business __________'
             PRINT STR('+ ',35)
             LINE.CT -= 3
          END

          GOSUB FFEED

          RETURN
*-------------------------------------------------------------------------*
FFEED:    *
          LN.CT = LINE.CT - 20
          FOR Z = 1 TO LN.CT
             PRINT
             LINE.CT -= 1
          NEXT Z

          IF REPRINT THEN
             PRINT SPACE(35):'.. Reprint .. Reprint .. Reprint .. Reprint ..'
          END ELSE
             PRINT
          END
          LINE.CT -= 1

          IF STATUS = 'T' THEN
             PRINT STR(CHAR(95),73)
             PRINT '|    Before material can be returned our consent must be obtained.      |'
             PRINT '|    No goods accepted for return without this Ticket or Ticket Number. |'
             PRINT '|    Re-handling Charges will be made on All Returned Material.         |':CHAR(13):
             PRINT STR(CHAR(95),73)
             PRINT
             PRINT 'ORDER FILLED BY:_______________________          RECEIVED BY:___________________'
             PRINT SPACE(49):'DATE:       ___________________'

          END ELSE
             FOR X = 1 TO 7
                PRINT
             NEXT X
          END

          LINE.CT -= 8
          LN.CT = LINE.CT - 14

          FOR Y = 1 TO LN.CT
             PRINT
             LINE.CT -= 1
          NEXT Y

          FOR W = 1 TO LINE.CT
             PRINT
          NEXT W

          PRINT

          LINE.CT = 0

          RETURN
*-------------------------------------------------------------------------*
LOT.SUB:  *LOT
          PARTS.CT = DCOUNT(LD(59),VM)

          ORD.STAT1 = LED(6)<1,GEN,1>
          IF ORD.STAT1 # "D" THEN
             TOTAL.PARTS.SHP = 0
             FOR CT = 1 TO PARTS.CT
                TOTAL.PARTS.SHP += LD(61)<1,CT,GEN>
             NEXT CT
          END ELSE
             TOTAL.PARTS.SHP = 1
          END

          IF TOTAL.PARTS.SHP = 0 THEN
             PRINT
             GOSUB SUBT.ONE
             PRT.STR = SPACE(SSPC):"This specific Lot Shipment has no"
             GOSUB SUBT.ONE
             PRINT PRT.STR
             PRT.STR = SPACE(SSPC):"related material detail defined."
             GOSUB SUBT.ONE
             PRINT PRT.STR
             RETURN
          END

          IF PARTS.CT THEN
             GOSUB SUBT.ONE
             PRINT
             GOSUB SUBT.ONE
             PRT.STR = SPACE(SSPC):"This Lot Consists of the following:"
             PRINT PRT.STR
             GOSUB SUBT.ONE
             IF ORD.STAT1 # "D" THEN
                PRT.STR = SPACE(SSPC):"Shp Qty  Description"
             END ELSE
                PRT.STR = SPACE(SSPC):"Ord Qty  Description"
             END
             PRINT PRT.STR
             GOSUB SUBT.ONE
             PRT.STR = SPACE(SSPC):"------- ---------------------------"
             PRINT PRT.STR
          END

          FOR CT = 1 TO PARTS.CT
             PARTS.NUM = LD(59)<1,CT>
             PARTS.ORD = LD(60)<1,CT>
             PARTS.SHP = LD(61)<1,CT,GEN>
             PARTS.CST = OCONV(LD(63)<1,CT>,'MR3')
             PARTS.EXT = PARTS.CST * PARTS.ORD

             IF ORD.STAT1 # "D" THEN
                IF NOT(PARTS.SHP) THEN GOTO NO.PARTS
             END

             IF PARTS.NUM[1,1] = "/" THEN
                PN = PARTS.NUM[2,LEN(PARTS.NUM)-1]
                MATREAD PRD FROM PRDFILE,PN ELSE RETURN
                DESC = PRD(1)
                FOLD.STRING DESC,27,NEWSTRING,VCT
                DESC = NEWSTRING
             END ELSE
                PARTS.NUM = RAISE(PARTS.NUM)
                DESC = PARTS.NUM
                FOLD.STRING DESC,27,NEWSTRING,VCT
                DESC = NEWSTRING
             END

             PRT.STR  = SPACE(SSPC)
             IF ORD.STAT1 # "D" THEN
                IF PARTS.SHP THEN
                   PRT.STR := PARTS.SHP "R#7 "
                END ELSE
                   GOTO NO.PARTS
                END
             END ELSE
                IF PARTS.ORD THEN
                   PRT.STR := PARTS.ORD "R#7 "
                END ELSE
                   GOTO NO.PARTS
                END
             END
             PRT.STR := DESC<1,1> "L#35"

             GOSUB SUBT.ONE
             PRINT PRT.STR
             DESC = DELETE(DESC,1,1)

             OE.CUS.PN.CMT.GET LED(1)<1,GEN>,LED(5)<1,GEN>,CUSS(66),PARTS.NUM,CMT
             IF CMT<1> THEN
                DESC<1,-1> = '    Your PN: ':CMT<1> "L#15"
             END

             SAV.SSPC = SSPC
             SSPC    += 8        ;* INV
             GOSUB PRT.XDESC
             SSPC = SAV.SSPC

NO.PARTS: *
          NEXT CT

          RETURN
*-------------------------------------------------------------------------*
FINISH:   *
          IF NOT(PHANTOM.PROC) AND NOT(PRT.ON) THEN
             WINDOW.CLOSE
          END

          LOCATION = SV.LOC
          RETURN
*-------------------------------------------------------------------------*
