          SUBROUTINE (OID,GEN,PSTYLE.OVRD,PRT.ON,DRPT,NUM.PGS)
** Version# 111.0109[17] - 04/08/2016 - 10:22am - TSMITH - eclipse
*** V111.0109 Change - Custom Coding . - 04/08/2016 - TSMITH - eclipse
*** V111.0108 Change - Custom Coding . - 06/11/2015 - TSMITH - eclipse
*** V111.0107 Change - Custom Coding CUSTOM - 12/23/2014 - TSMITH - eclipse
*** V111.0106 Change - Custom Coding . - 10/29/2013 - TSMITH - eclipse
*** V111.0105 Change - Custom Coding CVZ972 - 02/05/2008 - HEATHERY - UPGRADE
*** V111.0104 Change - Custom Coding CVA790 - 06/26/2007 - SPANDA - UPGRADE
** Version# 111.0103 - 07/31/2006 - 04:15pm - JONW - UPGRADE
*** V111.0103 Change - Custom Coding CTQ190 - 07/31/2006 - JONW - UPGRADE
*** V111.0102 Change - Custom Coding DKJ405 - 09/15/2005 - HEMALATHA - UPGRADE
*** V111.0101 Change - Add FULL Ver 8 - 02/25/2005 - ELIZR - eclipse
** Copied from BP SOE.PRINT.INVOICE Version# 111.01 - 05/13/2004 - 03:38pm - CHRISG - r8.0base

*** Subroutine - SOE.PRINT.INVOICE
*-------------------------------------------------------------------------*
*** This subroutine prints/faxes the Invoice form.
*-------------------------------------------------------------------------*
*** OID         - Order Id we're printing an Invoice for.             [IN]
*** GEN         - Order Generation we're printing an Invoice for.     [IN]
*** PSTYLE.OVRD - Print Style Override.                               (IN)
*** PRT.ON      - Flag which indicates whether we have already
***               turned our printer on.                              (IN)
*** DRPT        - REPORTS Record values.                              [IN]
*** NUM.PGS     - Number of pages printed                            (OUT)
*-------------------------------------------------------------------------*
*** COMMON: LED, LD, PRD, PRD.BR, CUS, and CUSS are read but not written.
***         JAVA.PROC$, INVOICE.COPY.CT$, and PHANTOM.PROC are used but
***         not written.
*------------------------------------------------------------------------*
          SKIP.TRIGS = OID<2>  ;* Set to YES if you don't want to run the
          OID        = OID<1>  ;* T022 "Invoice Print" trigger

          DIM PSTYL(10)
          UT.OPEN.FILE "PRINT.STYLES",PSTYLFILE,ERR.MSG
          IF ERR.MSG THEN RETURN

          PG.LGTH = 32
          SSPC    = 1
          NUM.PGS = 0

          IF DRPT<29> THEN FAX.FLAG = YES ELSE FAX.FLAG = NO
*         IF FAX.FLAG THEN
*            PG.LGTH    = 30
             FTR.MSG    = "Subtotal"
             FTR.MSG<2> = "S&H CHGS"
             FTR.MSG<3> = "Sales Tax"
             FTR.MSG<4> = "Amount Due"
*         END ELSE
*            FTR.MSG    = ''
*         END

          BOD.LINES  = 30

          *** If this isn't running as a Phantom Process, our printer
          *** isn't alreay on and we're in via Java...
          IF NOT(PHANTOM.PROC) AND NOT(PRT.ON) AND NOT(JAVA.PROC$) THEN
             WINDOW 15,8,50,5
             IF DRPT<29> = '' THEN
                PRINT @(0,1):'Printing .... ':OID
             END ELSE
                PRINT @(0,1):'Faxing .... ':OID
             END
          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

          IF LED(8)<1,GEN> = '' THEN
             LDIDS = LED(49)
             CONVERT VM TO SVM IN LDIDS
          END ELSE
             LDIDS = LED(48)<1,GEN>
          END

          *** If our printer hasn't already been turned on, do it now...

          IF NOT(PRT.ON) THEN
             PRINTER.ON "INVOICE",RPT.DFLT=DRPT
          END

          *** Go initialize our report data layout...
          GOSUB INIT

    * Compile column heading line from print style record
          TOTAL.SPACES   = COL.START
          FMT            = 'L#':COL.START
          COLUMN.HEADING = COLUMN.HEADING 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.HEADING = COLUMN.HEADING:COL.HEADS<1,COL> FRMT
          NEXT COL

          TOTAL.FMT = 'L#':TOTAL.SPACES

          PRINT CHAR(27):"&l1e6D":NORM:

          GOSUB HEADER

* Sort Items in location order -------------------------------------------*
*            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
*                  PRDD.BR.GET.VAL STK.BR,PN,8,LOCS
*                  LOC = LOCS<1,1>
*                  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
*-------------------------------------------------------------------------*
          SV.GEN   = GEN

          ATTACHED = ''

          LD.GCT = DCOUNT(LDID.GENS,AM)
          FOR LD.GEN = 1 TO LD.GCT
             GEN = LDID.GENS<LD.GEN>
             IF LED(8)<1,GEN> = '' THEN
                LDIDS = LED(49)
                CONVERT VM TO SVM IN LDIDS
             END ELSE
                LDIDS = LED(48)<1,GEN>
             END
             * Prepass for subtotal pricing detail Y/N
             NO.PRICING = ''
             FRST.DET   = 1
             LD.CT      = DCOUNT(LDIDS,SVM)

             FOR LD.NO = 1 TO LD.CT
                LDID = LDIDS<1,1,LD.NO>
                LD.GET LDID
                IF LD(1) = 'S' THEN
                   IF LD(21) = '' THEN
             * NO PRICING
                      FOR DL = FRST.DET TO LD.NO
                         NO.PRICING<DL> = YES
                      NEXT DL
                   END
                   FRST.DET = LD.NO + 1
                END
             NEXT LD.NO

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

          GEN = SV.GEN

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

          *** If they are using Credit Card check order to print receipt
          *** Check if site is authorized
          UT.SEC3 9,AUTH.OK,,NO
          CC.AMT = OCONV(OE.TOTL,'MR2')
          IF AUTH.OK THEN GOSUB CHKCC

          *** Print tracking information
          ***

          CARRIER     = TRANS('LEDGER.LOG',ORD.ID,23,'X')
          TRACKING.NO = TRANS('LEDGER.LOG',ORD.ID,24,'X')




          IF TRACKING.NO # "" AND CARRIER # "" THEN GOSUB PRTTRK



*** Make sure there is room for the signature in the body.
          CHECK.FOR.IMAGES ORD.ID,'L',IMAGE.FLAG
          IF IMAGE.FLAG THEN
             FOR XX = 1 TO 8
                BLINE += 1
                BOD<BLINE> = ''
             NEXT XX
          END

          GOSUB PRINT.TOTALS

          PGS = INT((BLINE + BOD.LINES-1)/BOD.LINES)

          GOSUB PRTBOD

          IF NOT(PRT.ON) THEN
             PRINTER.OFF
          END

          NUM.PGS = PAGE

          IF NOT(SKIP.TRIGS) THEN GOSUB ACT.TRIG

          GOTO FINISH
*-------------------------------------------------------------------------*
INIT:     *
          PAGE       = 0
          BOD        = ''
          BLINE      = 0
          SUBT.LINES = 0
          SUBT.SW    = NO
          IN.FOOTER  = NO
     !!   FRONT      = CHAR(27):'&f901y4X'

          SLPI   = CHAR(27):"&l6D"
          ELPI   = CHAR(27):"&l8D"

          *** Changed this code to reference the entity from the
          *** territory file
          READV B.NINE FROM TERRFILE,BR,5 ELSE B.NINE = ''
          IF B.NINE THEN
             BR.EN = B.NINE
          END ELSE
             READV BR.EN FROM TERRFILE,BR,4 ELSE BR.EN = ''
          END

          MATBUILD CUS.SAVE FROM CUS
          MATBUILD CUSS.SAVE FROM CUSS
          GET.CUS BR,BR.EN
          MATBUILD REM.BR FROM CUS
          MATPARSE CUS FROM CUS.SAVE
          MATPARSE CUSS FROM CUSS.SAVE

          *** Build the Branch address info for the 'Remit To' section
          *** of our Invoice Heading...
          GET.BR.REMIT.ADDR ST.CN,BR,R.ADDR
          IF BR = '4' THEN
          REMIT = ''
          END ELSE
          *** Code to print "Greensboro Plumbing Supply".
          OLD.COMP = TRANS('LEDGER.GPS',OID,9,'X')
          SHP.DATE = LED(9)<1,GEN>
          IF SHP.DATE < 16938 THEN
          *IF OLD.COMP = '1' THEN
          REMIT = 'GREENSBORO PLUMBING SUPPLY'
          END ELSE
          REMIT = R.ADDR<1>
          END


          REMIT<-1> = R.ADDR<2,1>
          REMIT<-1> = R.ADDR<2,2>
          REMIT<-1> = R.ADDR<3>:' ':R.ADDR<4>:' ':R.ADDR<5>
          REMIT<-1> = 'Phone: 336-274-7615'
          END

          *** Build the Branch address info for the Letter Head section
          *** of our Invoice Heading...
          READV BR.EN FROM TERRFILE,BR,4 ELSE BR.EN = ''
          READ CUS.BR FROM CUSFILE,BR.EN ELSE CUS.BR = ''

          IF SHP.DATE < 16938 THEN
          BR.ADDR = 'GREENSBORO PLUMBING SUPPLY'
          END ELSE
          BR.ADDR =  CUS.BR<1>
          END
          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>


          *** Add the Fax number if there is one...
          CONTACTS = RAISE(OCONV(CUS.BR<16>,"MCU"))
          FINDSTR "FAX" IN CONTACTS SETTING PPOS ELSE PPOS = 0
          IF PPOS THEN
             IF CUS.BR<17,PPOS> # '' THEN
                FAX.PHONE = '  Fax ':CUS.BR<17,PPOS>
             END ELSE FAX.PHONE = ''
          END ELSE FAX.PHONE = ''
          BR.ADDR<-1> = CUS.BR<17,1>:FAX.PHONE

          PRINT.PICK = NO
          CASH.SALE  = NO
          ITEM.CT    = 0
          INVN       = LED(8)<1,GEN>
          ORD.ID     = OID:'.':INVN"R%3"
          DOC.ID     = '    Invoice   '
          DOC.TYPE   = 'I'

          *** Check whether this Order is flagged for 'Single Invoicing'
          IF LED(86) AND LED(30)<1,GEN>[1,2] # 'CR' THEN
             SNGL.INV = 1
             GN.CT    = DCOUNT(LED(12),VM)

             *** Loop through each Gen on the Order to determine if the
             *** Order Gen we're printing the Invoice for is the first
             *** shipment...
             FOR J = 1 TO GN.CT
                *** Get the Invoice Status...
                ST = LED(6)<1,J>
                STATUS.OK = (ST # 'X' AND ST # 'Y' AND ST # '$' AND ST#'B')
                IF LED(8)<1,J> AND STATUS.OK THEN
                   *** If the Order Gen we're printing an Invoice for
                   *** is NOT the first shipment, we'll set our
                   *** variable designating that fact. Subsequently we'll
                   *** only include certain data on the document we're
                   *** printing since the Customer was technically already
                   *** 'Invoiced' when the first shipment went out.
                   IF LED(8)<1,J> < INVN THEN SNGL.INV = 2; EXIT
                END
             NEXT J
          END ELSE
             SNGL.INV = 0
          END

          *** Set up some variables to use for setting text fonts...
          SMALL      = CHAR(27):'(8U'
          SMALL     := CHAR(27):'(s0p16.67h8.5v0s0b0T'
          MED        = CHAR(27):"(8U":CHAR(27):'(s0p12h0s3b3T'
          SUP.SMALL  = CHAR(27):"(8U":CHAR(27):'(s0p20h0s0b0T'
          NORM       = CHAR(27):'(8U'
          NORM      := CHAR(27):'(s0p10h12v0s0b3T'
          NORM.BOLD  = CHAR(27):'(8U'
          NORM.BOLD := CHAR(27):'(s0p10h12v0s1b3T'
          LARGE      = CHAR(27):'(8U'
          LARGE     := CHAR(27):'(s1p10h14v0s3b3T'
          XLARGE     = CHAR(27):'(8U'
          XLARGE    := CHAR(27):'(s0p8h8v0s3b3T'
          SUP.SM.BLD = CHAR(27):"(8U":CHAR(27):'(s0p20h0s1b0T'
          *SUP.SM.BLD:= CHAR(27):'(s0p10h12v0s1b3T'


*         IF DRPT<50> AND DRPT<29> = '' THEN
*            GRAPHICS   = CHAR(27):'(10U'
*            GRAPHICS  := CHAR(27):'(s0p10h12v0s0b3T'
*            LN.CHAR    = CHAR(220)
*            LN.CHAR    = CHAR(196)
*            OCR.FLAG   = DRPT<50>
*            OCR.RIGHT  = SPACE(40):"    "
*            OCR.RIGHT := GRAPHICS:LN.CHAR:LN.CHAR:NORM:SPACE(11)
*            OCR.LEFT   = SPACE(40):" "
*            OCR.LEFT  := GRAPHICS:LN.CHAR:LN.CHAR:NORM:SPACE(14)

*            IF OCR.FLAG  = 1 THEN
**BEGIN SET
*               OCR.MARK1 = OCR.RIGHT
*               OCR.MARK2 = OCR.LEFT
*            END ELSE
*               OCR.MARK1 = OCR.LEFT
*               OCR.MARK2 = OCR.RIGHT
*            END
*         END ELSE
             OCR.FLAG = NO
             OCR.MARK1 = SPACE(55)
             OCR.MARK2 = SPACE(55)
*         END

          GOSUB GET.TOTALS

          IF OE.TOTL < 0 THEN DOC.ID = "  Credit Memo "

          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

          BEGIN CASE
          CASE PSTYLE.OVRD # ''
             STYLE.ID = PSTYLE.OVRD
          CASE LED(77)<1,GEN> # ''
             STYLE.ID = LED(77)<1,GEN>
          CASE OTHERWISE
             STYLE.ID = 'INVOICE'
          END CASE

          CHANGE.STYLE = (STYLE.ID = 'BLIND' OR STYLE.ID = 'NET' OR STYLE.ID='B')
          IF CHANGE.STYLE THEN STYLE.ID = 'INVOICE'

          GOSUB GET.PSTYLE

          DOC.FORM.SPEC = ''
          READ DOC.FORM.REC FROM CTRLFILE,'INVOICE.FORM' THEN
             GOSUB CNVRT.FORM
          END ELSE
             DOC.FORM.REC = ''
          END

          COLUMN.HEADING  = 'Line':SPACE(10):'Description':SPACE(16)
          COLUMN.HEADING := 'UM Ordered Shipped'

          COLUMN.HEADING2 = '---- ':STR('-',35):' -- ------- -------'

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

          MATREAD AR FROM ARFILE,ORD.ID ELSE MAT AR = ''

          IF AR(9)<1,1,2>='' THEN
             DISC.AMT = AR(9)+0
          END ELSE
             DISC.AMT = 0
          END

          DISC.DT  = AR(11)
          DUE.DT   = AR(12)
          WRITER   = LED(73)<1,GEN>
          READV WRITER  FROM INIFILE,WRITER,3 ELSE NULL
          SALESMAN = LED(72)<1,GEN>
          READV SALESMAN FROM INIFILE,SALESMAN,3 ELSE NULL

          SHIP.VIA = LED(70)<1,GEN>
          ORD.DATE = LED(4)<1,GEN>
          INV.DATE = LED(9)<1,GEN>
          SHP.DATE = LED(9)<1,GEN>
          ORD.WITH = LED(68)<1,GEN>
          EXP.DATE = LED(31)<1,GEN>
          PHONE.NO = CUS(17)<1,1>

          TERMS.ID = LED(29)<1,GEN>
          READV TERMS.DESC FROM TERMSFILE,TERMS.ID,1 ELSE
             TERMS.DESC = TERMS.ID
          END
          READV TERMS.DISC FROM TERMSFILE,TERMS.ID,2 ELSE TERMS.DISC = ''
          IF TERMS.DISC[1,1] = "P" THEN PASS.THRU = YES ELSE PASS.THRU=NO

*         READV SCPC FROM TERMSFILE,CUS(28),22 ELSE SCPC=0
          TERMS.VALUE SCPC,CUS(28),22,INV.DATE,ERRS
          IF ERRS THEN SCPC = 0

          SHIP.ADDR      = LED(78)<1,GEN,6>
          IF NOT(SHIP.ADDR) THEN SHIP.ADDR = CUSS(1)
          SHIP.ADDR<-1>  = LED(78)<1,GEN,1>
          SHIP.ADDR<-1>  = LED(78)<1,GEN,2>
          SHIP.ADDR<-1>  = TRIM(LED(78)<1,GEN,3>):" ":LED(75)<1,GEN> "L#10"

          BEGIN CASE

          *** If the ShipTo is flagged to use the ShipTo for the billing
          *** address...
          CASE CUSS(97)
             BILL.ADDR = SHIP.ADDR<1>
             IF CUSS(2)<1,1> # '' THEN BILL.ADDR<-1> = CUSS(2)<1,1>
             IF CUSS(2)<1,2> # '' THEN BILL.ADDR<-1> = CUSS(2)<1,2>
             BILL.ADDR<-1> = TRIM(CUSS(3)):", ":CUSS(4)"L#4":CUSS(5)"L#14"
          *** If the ShipTo is flagged to use an Alternate ShipTo...
          CASE CUSS(91)<1,1>
             BILL.ADDR = CUSS(91)<1,1>
             IF CUSS(92)<1,1> # '' THEN BILL.ADDR<-1> = CUSS(92)<1,1>
             IF CUSS(92)<1,2> # '' THEN BILL.ADDR<-1> = CUSS(92)<1,2>
             ADDR.STRING  = TRIM(CUSS(93)):", ":CUSS(94) "L#4"
             ADDR.STRING := CUSS(95)"L#14"
             BILL.ADDR<-1> = ADDR.STRING
          *** If the BillTo is flagged to use an Alternate BillTo...
          CASE CUS(91)<1,1>
             BILL.ADDR = CUS(91)<1,1>
             IF CUS(92)<1,1> # '' THEN BILL.ADDR<-1> = CUS(92)<1,1>
             IF CUS(92)<1,2> # '' THEN BILL.ADDR<-1> = CUS(92)<1,2>
             BILL.ADDR<-1> = TRIM(CUS(93)):", ":CUS(94)"L#4":CUS(95)"L#14"
          *** Otherwise, use normal billing address...
          CASE OTHERWISE
             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> = TRIM(CUS(3)):", ":CUS(4)"L#4":CUS(5)"L#14"
          END CASE

          IF CUS(28) = "COD" THEN COD.MSG = "*** C O D ***" ELSE COD.MSG=''

          ITEM.TAG.INFO  = '' ;* Item tag info
          OE.ITEM.TAG.READ OID,,,,ITEM.TAG.INFO

          SHP.INST = LED(74)<1,GEN>
*         SORT.FLAG = YES
          IF SHP.INST<1,1,1>[1,1] = "!" THEN
             SHP.INST1 = SHP.INST<1,1,1>
*            IF INDEX(SHP.INST1,"NOSORT",1) THEN SORT.FLAG = NO
             IF INDEX(SHP.INST1,"NOBO",1) THEN BO.FLAG = NO
*            SHP.INST = DELETE(SHP.INST,1,1,1)
          END
          SHP.INST = ''

          CUS.PO   = LED(13)<1,GEN>
          CUS.JOB  = LED(65)<1,GEN>
          ORD      = FIELD(ORD.ID,'.',1)
          GN       = FIELD(ORD.ID,'.',2)
*** This TAX stuff is special for Canada...They have to split it up.
*         PST.RATE = 0
*         SHP.DATE = LED(9)<1,GEN>
*         IF TAX.AMT2 + 0 # 0 THEN
*            TXCD = LED(79)<1,GEN,1>
*            MATREAD TAX FROM TAXFILE,TXCD ELSE MAT TAX=''
*            LOCATE SHP.DATE IN TAX(7)<1> BY 'AR' SETTING TAX.EFF ELSE
*               TAX.EFF += -1
*               IF TAX.EFF<1 THEN TAX.EFF=1
*            END
*
*            GL.IDS   = TAX(2)<1,TAX.EFF>
*            GL.RATES = TAX(3)<1,TAX.EFF>
*            RATE.CT  = DCOUNT(GL.RATES,SVM)
*            PST.RATE = 0
*            FOR RATE.INDX = 1 TO RATE.CT
* *** The number in quotes should be rec 2 of GST only record in TAX.CODES
*               IF GL.IDS<1,1,RATE.INDX> # "74" THEN
*                  PST.RATE += GL.RATES<1,1,RATE.INDX>
*               END
*            NEXT RATE.INDX
*            IF PST.RATE THEN
*               PST.RATE = OCONV(PST.RATE,'MR3')
*               FT.LGTH += 2
*            END
*         END
          US.FUNDS = LED(92)<1,GEN,2>
          IF US.FUNDS # '' AND NOT(NUM(US.FUNDS)) THEN US.FUNDS = ''

          RETURN
*-------------------------------------------------------------------------*
GET.PSTYLE: * Get the 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
*-------------------------------------------------------------------------*
CHECK.SPLIT: * This routine will go through the AR record for each gen on
             * on an order loop through the cash receipt record back to
             * the sales order to check for the 'SPT' flag in the ledger
          IS.SPLIT     = NO
          SPLIT.ORDERS = ''

          READV AR.TWO FROM ARFILE,AR.ID,2 ELSE RETURN

          CT = DCOUNT(AR.TWO,VM)
          FOR I = 1 TO CT
             *** check the ar record for this gen on the OID.
             IF AR.TWO<1,I> = '' THEN CONTINUE

             *** setup the second AR ID to read from the arfile.
             AR.TWO.CR     = FIELD(AR.TWO<1,I>,'.',2,3)
             READV AR.THIRD FROM ARFILE,AR.TWO.CR,2 ELSE RETURN

             S.CT = DCOUNT(AR.THIRD,VM)
             FOR J = 1 TO S.CT
                *** check the ar record for the CR of this OID GEN.
                IF AR.THIRD<1,J> = '' THEN CONTINUE
                AR.KEY = FIELD(AR.THIRD<1,J>,'.',2,3)
                IF FIELD(AR.KEY,'.',1,1) # OID THEN CONTINUE

                READ AR.INFO FROM ARFILE,AR.KEY ELSE CONTINUE
                IF AR.INFO<18> = 'SPT' THEN
                   IS.SPLIT = YES
                   LOCATE AR.KEY IN SPLIT.ORDERS<1> SETTING POS ELSE
                      SPLIT.ORDERS<1,-1> = AR.KEY
                   END
                END
             NEXT J
          NEXT I

          RETURN
*-------------------------------------------------------------------------*
PRINT.SPLIT: *** Print Split Terms

          IF LED(48)<1,GEN> = '' THEN
             READ AR.INFO FROM ARFILE,AR.ID ELSE RETURN
             IF AR.INFO<18> # 'SPT' THEN RETURN
             SPLIT.DT      = AR.INFO<12>
             SPLIT.AMT     = AR.INFO<8>
             TOTAL.COMMENT = 'Amount Due on ':OCONV(SPLIT.DT,'D2/')"L#8"
             TOTAL.AMT     = OCONV(SPLIT.AMT,"MR2")
             IF TOTAL.AMT THEN
                GOSUB PRINT.TOTAL
                RUNNING.TOTAL += TOTAL.AMT
             END
          END ELSE
             SPLIT.ORDERS = AR.ID:VM:SPLIT.ORDERS
             NUM.ORDERS = DCOUNT(SPLIT.ORDERS,VM)
             FOR CTR = 1 TO NUM.ORDERS
                AR.KEY = SPLIT.ORDERS<1,CTR>
                READ AR.INFO FROM ARFILE,AR.KEY ELSE CONTINUE
                SPLIT.DT      = AR.INFO<12>
                SPLIT.AMT     = AR.INFO<8>
                TOTAL.COMMENT = 'Amount Due on ':OCONV(SPLIT.DT,'D2/')"L#8"
                TOTAL.AMT     = OCONV(SPLIT.AMT,"MR2")
                IF TOTAL.AMT THEN
                   GOSUB PRINT.TOTAL
                END
             NEXT CTR
          END

          RETURN
*-------------------------------------------------------------------------*
CNVRT.FORM: * Convert the values we picked up from our Form overlay
            * Control Record AND from the Print Style Id we're using,
            * that was set up in Print Style Maintenance...

*** Get data out from the Form Overlay Control Record we're using...

          *** We should find this string in the Row where our Invoice's
          *** data columns were set up...
          FINDSTR '@PRINT.STYLE' IN DOC.FORM.REC SETTING AMC THEN
             *** Get the Print Style Width....
             FORM.STYLE.WIDTH = FIELD(DOC.FORM.REC<AMC>,',',2)
             *** Initialize our Total Width to be the Print Style Width...
             TOTAL.WIDTH      = FORM.STYLE.WIDTH

             TAMC = AMC - 1
             *** Go through each data column that's been set up in the
             *** current row...
             LOOP
             UNTIL DOC.FORM.REC<TAMC>[1,1] # '"' DO
             *** Add the width from each column to our Total Width...
             TOTAL.WIDTH += FIELD(DOC.FORM.REC<TAMC>,',',2)
             TAMC -= 1
             REPEAT

             *** Set our Start Column, where we'll be printing the values
             *** determined by our print style Id...
             COL.START    = TOTAL.WIDTH - FORM.STYLE.WIDTH
             DEL DOC.FORM.REC<AMC>

*** Now we'll go through the columns that were set up for the Print
*** Style Id we're using (set up in Print Style Maintenance)...

             STYLE.WIDTH  = 0
             WIDTH.INSERT = ''

             FOR CC = 1 TO COL.CT
                TWIDTH           = FIELD(COL.FRMTS<1,CC>,'#',2)
                WIDTH.INSERT<CC> = TWIDTH
                STYLE.WIDTH     += TWIDTH
             NEXT CC

             BEGIN CASE
             *** If the actual width of our Print Style Id columns is less
             *** than the width that our Form Overlay Control Record
             *** stated that it needed to be...
             CASE STYLE.WIDTH < FORM.STYLE.WIDTH
                CC = COL.CT
                LOOP
                UNTIL STYLE.WIDTH >= FORM.STYLE.WIDTH DO
                *** Increase a columns width...
                WIDTH.INSERT<CC> += 1
                NEW.FRMT  = FIELD(COL.FRMTS<1,CC>,'#',1):'#'
                NEW.FRMT := WIDTH.INSERT<CC>
                COL.FRMTS<1,CC> = NEW.FRMT

                CC -= 1
                *** If we've already increased each columns width
                *** once, start with the first one again...
                IF CC < 1 THEN CC = COL.CT
                STYLE.WIDTH += 1
                REPEAT
             *** If the actual width of our Print Style Id columns is
             *** greater than the width that our Form Overlay Control
             *** Record stated that it needed to be...
             CASE STYLE.WIDTH > FORM.STYLE.WIDTH
                CC = 1
                LOOP
                UNTIL STYLE.WIDTH <= FORM.STYLE.WIDTH DO
                *** Decrease a columns width...
                WIDTH.INSERT<CC> -= 1
                NEW.FRMT  = FIELD(COL.FRMTS<1,CC>,'#',1):'#'
                NEW.FRMT := WIDTH.INSERT<CC>
                COL.FRMTS<1,CC> = NEW.FRMT

                CC += 1
                *** If we've already decreased each columns width
                *** once, start with the first one again...
                IF CC > COL.CT THEN CC = 1
                STYLE.WIDTH -= 1
                REPEAT
             END CASE

             FOR CC = 1 TO COL.CT
                TINSERT  = '"':COL.HEADS<1,CC>:'",'
                TINSERT := WIDTH.INSERT<CC>

                INS TINSERT BEFORE DOC.FORM.REC<AMC+CC-1>
             NEXT CC

             FTR.TEXT.LGTH = 79-WIDTH.INSERT<COL.CT>
             FTR.FMT       = 'R2#':WIDTH.INSERT<COL.CT>
          END

          RETURN
*-------------------------------------------------------------------------*
HEADER:   *

          PAGE    = PAGE + 1
          IF NUM(GN) THEN GN = GN+0

*         IF FAX.FLAG THEN
*            PRINT '@+IMAGE[INV]'
*            PRINT CHAR(27):"*p0Y":
*         END

          *** Print the macro
          MACRO.ID = 'INVOICE~':STYLE.ID
          GOSUB SET.MACRO

 *** Print the logo

              *** Print the logo
          *IF USER.ID = 'TSMITH' THEN
            IF NOT(JAVA.PROC$) THEN
          PRINT CHAR(27):"*p25y*p50X":
          PTR.MACRO.PRINT ERR.MSG, 'HUB3', DRPT
          PRINT CHAR(27):"*p0Y":
          PRINT NORM:SLPI:
          PRINT ; PRINT
          END ELSE
          PRINT CHAR(27):"*p25y*p50X":
          PTR.MACRO.PRINT ERR.MSG, 'HUB', DRPT
          PRINT CHAR(27):"*p0Y":
          PRINT NORM:SLPI:
          PRINT ; PRINT
          END
          *END ELSE
          *PRINT CHAR(27):"*p25y*p50X":
          *PTR.MACRO.PRINT ERR.MSG, 'PICK', DRPT
          *PRINT CHAR(27):"*p0Y":
          *PRINT NORM:SLPI:
          *PRINT ; PRINT
          *END

    PRINT CHAR(27):"*p0Y":
          PRINT NORM:SLPI:
          PRINT
          IF INVOICE.COPY.CT$ > 1 THEN
             PRINT SPACE(58):'**  DUPLICATE **'
          END ELSE
             PRINT
          END
          PRINT SPACE(57):XLARGE:DOC.ID:NORM


          PRINT CHAR(27):"*p50Y":SLPI

          PRINT ''
          PRINT ''
          PRINT ''
          FOR I = 1 TO 5
             PRINT '' "L#1":LARGE:  REMIT<I>:NORM
          NEXT I




          PRINT CHAR(27):"*p165Y":SLPI
          PRINT
          PRINT OCR.MARK1
          PRINT OCR.MARK2 :OCONV(INV.DATE,'D2/')   "L#10":
          PRINT ORD.ID                 "L#14"
*         IF OCR.FLAG AND PAGE = 1 THEN
*            OCR.MARK1 = OCR.LEFT
*            OCR.MARK2 = OCR.RIGHT
*         END

          PRINT CHAR(27):"*p315Y"
          IF BR = '4' THEN
          PRINT '' "L#55":SMALL:"":NORM:ELPI
          END ELSE
          PRINT '' "L#55":SMALL:"REMIT TO:":NORM:ELPI
          END
          PRINT NORM.BOLD:
          PRINT '' "L#55":SUP.SM.BLD:REMIT<1> "L#30":NORM
          PRINT '' "L#55":SUP.SM.BLD:REMIT<2> "L#30":NORM
          PRINT '' "L#55":SUP.SM.BLD:REMIT<3> "L#30":NORM:PAGE  "R#7"
          PRINT '' "L#55":SUP.SM.BLD:REMIT<4> "L#30":NORM

          PRINT CHAR(27):"*p565Y":SLPI
          PRINT SPACE(7):SMALL:"BILL TO:":NORM:
          PRINT CHAR(27):"*p565Y":SLPI
          PRINT SPACE(45):SMALL:"SHIP TO:":NORM

          FOR I = 1 TO 4
             PRINT SPACE(7):BILL.ADDR<I>'L#38': SHIP.ADDR<I>
          NEXT I

*------Header Info------*
          PRINT CHAR(27):"*p890Y"
          PRINT
          PRINT
          PRINT '    ':ST.CN          "L#9 ":
          PRINT CUS.PO                "L#22 ":
          PRINT CUS.JOB               "L#21 ":
*         PRINT ORD.WITH              "L#19 ":
*         PRINT BR                    "R#2":'   ':
          PRINT SALESMAN              "L#20"
          PRINT
          PRINT
          PRINT ' ':WRITER            "L#22 ":
          PRINT SHIP.VIA              "L#17 ":
          PRINT TERMS.DESC            "L#16 ":
          PRINT OCONV(INV.DATE,'D2/') "L#10 ":
          PRINT OCONV(ORD.DATE,'D2/')
*         IF SNGL.INV=2 THEN
*            PRINT SMALL:SPACE(25):"DESCRIPTION":SPACE(28):"   SHIPPED                  ":SPACE(6):"NET UNIT PRICE":SPACE(8):"NET AMOUNT":NORM
*         END ELSE
             PRINT
*         END

*         PRINT

          IF SHP.INST # '' AND PAGE = 1 THEN
             BLINE += 1
             BOD<BLINE> = SPACE(1):'******** Shipping Instructions ********'
             CT = DCOUNT(SHP.INST,SVM)

             FOR JJ = 1 TO CT
                BLINE += 1
                BOD<BLINE> =  SPACE(1):"*":SHP.INST<1,1,JJ>"L#38"
             NEXT JJ

             BLINE += 1
             BOD<BLINE> = SPACE(1):STR('*',39)

             BLINE += 1
             BOD<BLINE> = ''

          END

          BO.HEADING = NO

          RETURN
*-------------------------------------------------------------------------*
PRTBOD:   *
          PLINE = 1
          LINEX = 0

          LOOP
             LINEX += 1
             IF LINEX > BLINE THEN EXIT
             IF PLINE > BOD.LINES THEN GOSUB TOP; PLINE=1
             PRINT BOD<LINEX>
             PLINE += 1
          REPEAT
          GOSUB FOOTER
          GOSUB FFEED
          RETURN
*-------------------------------------------------------------------------*
TOP:    *
          GOSUB FFEED
          GOSUB HEADER

          RETURN
*-------------------------------------------------------------------------*
SUBTOTALS:*
          PRT.STR1 = SPACE(COL.START)
          PRT.STR2 = (SUBT.DESC "R#36") FMT
          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-1))
                IF SUBT.SW THEN
                   PRT.STR2 = PRT.STR2:SUB.TOTAL<1,COL> COL.FRMTS<1,COL>
                END ELSE
                   PRT.STR2 = PRT.STR2:COL.TOTAL<1,COL> COL.FRMTS<1,COL>
                END
             END ELSE
                PRT.STR1 = PRT.STR1:SPACE(LGTH)
                PRT.STR2 = PRT.STR2:SPACE(LGTH)
             END
          NEXT COL

          BLINE += 1
          BOD<BLINE> = PRT.STR1
          BLINE += 1
          BOD<BLINE> = PRT.STR2

          RETURN
*-------------------------------------------------------------------------*
GET.TOTALS: *
          SOE.CALC.CASH OID,GEN,AMT.DUE,AMT.PAID,CASH.DISC
          * Get WOE.DISC for Web orders
          SOE.CALC.DISC OID,GEN,,,WOE.DISC
          OE.ORDER.TOTAL OID,GEN,QSIGN,OE.TOTL,,FREIGHT,HANDLING,TAX.AMT,FET.AMT
*         AMT.PAID  = OCONV(AMT.PAID,'MR2')
          FREIGHT   = OCONV(FREIGHT,'MR2')
          HANDLING  = OCONV(HANDLING,'MR2')
          TAX.AMT   = OCONV(TAX.AMT,'MR2')
          FET.AMT   = OCONV(FET.AMT,'MR2')
          CASH.DISC = OCONV(CASH.DISC,'MR2')

          LDID.GENS   = GEN
          IF SNGL.INV = 1 THEN
             GN.CT = DCOUNT(LED(12),VM)
             FOR J = 1 TO GN.CT
                ST = LED(6)<1,J>
                IF J # GEN AND ST # 'X' AND ST # 'B' AND ST # '$' AND ST # 'Y' THEN
                   LDID.GENS<-1> = J
                   OE.ORDER.TOTAL OID,J,QSIGN,,,FRT.TOL,HAND.TOL,TAX.TOL,FET.TOL
                   TAX.AMT  += OCONV(TAX.TOL,'MR2')
                   FREIGHT  += OCONV(FRT.TOL,'MR2')
                   HANDLING += OCONV(HAND.TOL,'MR2')
                END
             NEXT J
          END

  * 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

          IF SNGL.INV = 1 THEN
             UNEARN.AMT = 0
          END ELSE
             LOCATE 'UNEARN' IN LED(24)<1,GEN> SETTING POS THEN
                UNEARN.AMT = OCONV(LED(26)<1,GEN,POS>,'MR2')
             END ELSE
                UNEARN.AMT = 0
             END
          END

** Never want Amounts to show
          IF SNGL.INV = 2 THEN
             UNEARN.AMT = 0
             TAX.AMT    = 0
             FREIGHT    = 0
             HANDLING   = 0
          END

          RETURN
*-------------------------------------------------------------------------*
PRINT.TOTALS: *
*         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
          IF UNEARN.AMT THEN
*            TOTAL.COMMENT  = 'Advanced Billing'
             TOTAL.COMMENT  = ''
             TOTAL.AMT      = -UNEARN.AMT
             GOSUB PRINT.TOTAL
             RUNNING.TOTAL += TOTAL.AMT
          END

          IF FET.AMT THEN
             TOTAL.COMMENT  = 'F.E.T.'
             TOTAL.AMT      = FET.AMT
             GOSUB PRINT.TOTAL
             RUNNING.TOTAL += TOTAL.AMT
          END

          PRINT.AMT.DUE = NO
          IF AMT.PAID THEN
             PRINT.AMT.DUE    = YES
             IF LED(8)<1,GEN> = '' THEN
                TOTAL.COMMENT = 'Less cash paid'
                IF US.FUNDS THEN
                   AMT.PAID   = ICONV(AMT.PAID/OCONV(US.FUNDS,'MR4'),"MR0")
                END
                TOTAL.AMT     = OCONV(AMT.PAID,"MR2")
                GOSUB PRINT.TOTAL
                RUNNING.TOTAL = RUNNING.TOTAL + TOTAL.AMT
             END

             AR.ID = OID:'.':LED(8)<1,GEN>"R%3"
             SOE.PAYMENTS.DISC AR.ID,PAY.IDS,PAY.DTS,PAY.AMTS,DISC.TAKEN

             * Check if it is a split term
             GOSUB CHECK.SPLIT

             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 IS.SPLIT AND PYN <= DCOUNT(SPLIT.ORDERS,VM) THEN CONTINUE
                IF LED(8)<1,GEN> # '' THEN
                  IF PAY.DT=DATE() THEN
                     TOTAL.COMMENT = 'Amount paid today # ':PAY.ID
                  END ELSE
                    TOTAL.COMMENT  = 'Prior Deposit on '
                    TOTAL.COMMENT := OCONV(PAY.DT,'D2/')"L#8"
                  END
                END

                IF US.FUNDS THEN
                   PAY.AMT = ICONV(PAY.AMT/OCONV(US.FUNDS,'MR4'),"MR0")
                END

                TOTAL.AMT = OCONV(PAY.AMT,"MR2")
                IF TOTAL.AMT THEN
                   GOSUB PRINT.TOTAL
                   RUNNING.TOTAL = RUNNING.TOTAL + TOTAL.AMT
                END
             NEXT PYN

             IF IS.SPLIT THEN
                * Print split terms
                GOSUB PRINT.SPLIT
             END

             IF DISC.TAKEN # 0 THEN
                TOTAL.COMMENT = 'Discount Taken'
                IF US.FUNDS THEN
                   DISC.TAKEN=ICONV(DISC.TAKEN/OCONV(US.FUNDS,'MR4'),"MR0")
                END
                TOTAL.AMT = OCONV(DISC.TAKEN,"MR2")
                GOSUB PRINT.TOTAL
                RUNNING.TOTAL += TOTAL.AMT
                *** Subtract the Discount amount already taken from the
                *** total possible Discount amount...
                IF DISC.AMT THEN
                   DISC.AMT -= OCONV(DISC.TAKEN,"MR2")
                END
             END
          END

          IF DISC.AMT > 0 AND RUNNING.TOTAL < 0 THEN
             TOTAL.COMMENT  = 'Discount Taken'
             TOTAL.AMT      = OCONV(DISC.AMT,'MR2')

             GOSUB PRINT.TOTAL

             RUNNING.TOTAL += TOTAL.AMT
             DISC.AMT       = 0
          END

          * If there is a web order discount then display the web order
          * discount and add  to Running Total.
          IF WOE.DISC THEN
                TOTAL.COMMENT = 'Web Order Discount'
                TOTAL.AMT = OCONV(WOE.DISC,'MR2')
                GOSUB PRINT.TOTAL
                RUNNING.TOTAL += TOTAL.AMT
                WOE.DISC = 0
          END

          RETURN
*-------------------------------------------------------------------------*
PRINT.TOTAL: *

          PRT.STR  = TOTAL.COMMENT "R#36" TOTAL.FMT
          PRT.STR := TOTAL.AMT TOTAL.FRMT

          BLINE += 1
          BOD<BLINE> = PRT.STR

          RETURN
*-------------------------------------------------------------------------*
PRINT.TOTAL.LINE: *

          LGTH    = FIELD(TOTAL.FRMT,"#",2)
          PRT.STR = SPACE(TOTAL.SPACES):" ":STR('-',(LGTH-1))

          BLINE += 1
          BOD<BLINE> = 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'
             IF SNGL.INV = 1 THEN
                LOCATE LDID IN ATTACHED SETTING NOTHING THEN
                   RETURN
                END ELSE
                   ATTACHED<-1> = LDID
                   OE.DESC.GET DESC,ALT.DESC,"Invoice Printing"
                   GOSUB PRT.XDESC
                END
             END ELSE
                OE.DESC.GET DESC,ALT.DESC,"Invoice Printing"
                GOSUB PRT.XDESC
             END
          CASE PN = 'S'
             GOSUB PRT.SUBT
          END CASE

          RETURN
*-------------------------------------------------------------------------*
PRT.PN:   *
          SUBT.LINES += 1

          *** Load all of our Product and Pricing arrays for this product
          GET.ALL.PRD BR,PN,QSIGN,GROUP

*** pass along discount
          IF PASS.THRU THEN
             CD = PRD.BR(38)
             IF CD = '' THEN
                PLNE.BR.GET.VAL BR,PRD(9),3,CD
             END
             IF CD # "" THEN CD = OCONV(CD,"MR1")
          END ELSE
             CD = ''
          END

          OE.DESC.GET DESC,ALT.DESC,"Invoice Printing"
          IF LD(36)<1,GEN,1> # '' THEN DESC<1,-1> = LD(36)<1,GEN,1>

          *** If there is customer client pricing for this line item
          *** we will add it to the description
          IF LED(144)<1,2> THEN
             IF LD(127)<1,GEN> THEN
                READV CUSCL FROM ENTFILE,LED(144)<1,2>,1 ELSE
                   CUSCL = LED(144)<1,2>
                END
                CUSCL = CUSCL<1,1>
                CUS.PRC = ICONV(OCONV(LD(127)<1,GEN>,'MR9'),'MR3')
                CUS.PRC = OCONV(CUS.PRC,'MR3')
                DESC<1,-1> = CUSCL:"'s price - ":CUS.PRC
             END
          END

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

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

          IF SERIAL. AND SERIAL. # "N" THEN
             SN.LIST = LD(32)<1,GEN>
             SN.CT   = DCOUNT(SN.LIST,SVM)
             FOR SN  = 1 TO SN.CT
                IF SN.LIST<1,1,SN> THEN
                   DESC<1,-1> = 'Serial#: ':SN.LIST<1,1,SN>
                END
             NEXT SN
          END

*------Kits
          BEGIN CASE
          CASE CUS(74) = "Yes"
             IF LD(31) # '' THEN
                DESC<1,-1> = '************** Kit Components **************'
                KITMS = DCOUNT(LD(31),VM)
                FOR K = 1 TO KITMS
                   KQTY  = LD(30)<1,K>
                   READV KCMP FROM PRDFILE,LD(31)<1,K>,1 ELSE KCMP=''
                   KDSCS = DCOUNT(KCMP,VM)
                   FOR KD = 1 TO KDSCS
                      IF KD = 1 THEN
                         KSP = LEN(KQTY)
                         KLN = 42-(5+KSP)
                         KFMT = "L#":KLN
                         DESC<1,-1> = '* ':KQTY:' - ':KCMP<1,KD> KFMT:' *'
                      END ELSE
                         KFRMT = "L#":KSP
                         KIT.STRING  = '* ':'' KFRMT:'   '
                         KIT.STRING := KCMP<1,KD> KFMT:' *'
                         DESC<1,-1>  = KIT.STRING
                      END
                   NEXT KD
                NEXT K
                DESC<1,-1> = STR('*',44)
             END
          CASE CUS(74) = "Default" OR CUS(74) = ''
             IF LD(31) # '' AND LD(38)<1,2>   = '1' THEN
                DESC<1,-1> = '************** Kit Components **************'
                KITMS = DCOUNT(LD(31),VM)
                FOR K = 1 TO KITMS
                   KQTY = LD(30)<1,K>
                   READV KCMP FROM PRDFILE,LD(31)<1,K>,1 ELSE KCMP=''
                   KDSCS = DCOUNT(KCMP,VM)
                   FOR KD = 1 TO KDSCS
                      IF KD = 1 THEN
                         KSP  = LEN(KQTY)
                         KLN  = 42-(5+KSP)
                         KFMT = "L#":KLN
                         DESC<1,-1> = '* ':KQTY:' - ':KCMP<1,KD> KFMT:' *'
                      END ELSE
                         KFRMT       = "L#":KSP
                         KIT.STRING  = '* ':'' KFRMT:'   '
                         KIT.STRING := KCMP<1,KD> KFMT:' *'
                         DESC<1,-1>  = KIT.STRING
                      END
                   NEXT KD
                NEXT K
                DESC<1,-1> = STR('*',44)
             END
          CASE OTHERWISE
             NULL
          END CASE

          ITEM.CT += 1
          PRT.STR  = ' '
          PRT.STR  = PRT.STR:DESC<1,1>   "L#35"
          IF SNGL.INV = 2 THEN
             IQ.TO.ALPHA PLNE(3),PRD(7),LD(23),QS,Q1,U1,Q2,U2,QS.ALPHA
             PRT.STR  = PRT.STR:OCONV(Q1,"MR0,")   "R#9"
             PRT.STR  = PRT.STR:''      "R#9"
             QS       = ''
          END ELSE
             IQ.TO.ALPHA PLNE(3),PRD(7),LD(23),QOPEN,Q1,U1,Q2,U2,QS.ALPHA
             PRT.STR  = PRT.STR:OCONV(Q1,"MR0,")   "R#9"
             IQ.TO.ALPHA PLNE(3),PRD(7),LD(23),QS,Q1,U1,Q2,U2,QS.ALPHA
             PRT.STR  = PRT.STR:OCONV(Q1,"MR0,")      "R#9"
          END
          IF ITEM.TAG.INFO THEN
             * Let user know how many labels go with this line
             OE.ITEM.TAG.GET.FORM.CMT OID,GEN,LDID,LBL.DATA
             LBL.CT = DCOUNT(LBL.DATA,AM)
             FOR LBL.NO = 2 TO LBL.CT
                DESC<1,-1> = LBL.DATA<LBL.NO>
             NEXT LBL.NO
          END
          SAVE.LINE = PRT.STR
*LOT
          IF LOT.FLAG THEN
             FORMS.GET.LOT.PRC "INV",LDID,GEN,'',UNT.PRC
             PRT.STR := UNT.PRC"R3#11"
             PRT.STR := UNT.PRC"R2#12"
             COL.TOTAL<1,COL.CT> += UNT.PRC
          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

          IF NO.PRICING<LD.NO> THEN PRT.STR = SAVE.LINE
          BLINE += 1
          BOD<BLINE> = PRT.STR
          DESC    = DELETE(DESC,1,1)

          GOSUB PRT.XDESC
*LOT
          IF LOT.FLAG THEN
             OE.LOT.PRINT.SETUP OID,GEN,'S','I',BLINE,SSPC,BOD,,'',LDID
          END

          RETURN
*-------------------------------------------------------------------------*
PRT.XDESC: *
          DESC.CT = DCOUNT(DESC,VM)
          FOR DLN = 1 TO DESC.CT
             PRT.STR = SPACE(SSPC):DESC<1,DLN>"L#44"
             BLINE += 1
             BOD<BLINE> = PRT.STR
          NEXT DLN

          RETURN
*-------------------------------------------------------------------------*
PRT.SUBT: *
          IF SUBT.LINES THEN
             SUBT.SW = YES
             OE.DESC.GET DESC,ALT.DESC,"Invoice Printing"
             SUBT.DESC = DESC<1,1>
             GOSUB SUBTOTALS
             DESC = DELETE(DESC,1,1)
             GOSUB PRT.XDESC
             SUBT.LINES = 0
             SUBT.SW    = NO
             SUB.TOTAL  = ''
          END

          RETURN
*-------------------------------------------------------------------------*
FOOTER:   *
          IN.FOOTER = YES

          READV INV.MSG FROM CTRLFILE,'INVOICE.MESSAGE:':BR,1 ELSE
             INV.MSG = ''
          END

          IF INV.MSG # '' THEN
             FOLD.STRING INV.MSG,35,NEWSTRING,VCT
             INV.MSG = NEWSTRING
          END

          MCT = DCOUNT(INV.MSG,VM)
          IF OE.TOTL < 0 THEN CM = 'CUSTOMER CREDIT' ELSE CM = ''
          REPRINT.MSG = ''
          IF REPRINT THEN
             REPRINT.MSG = ' ** Reprint ** Reprint ** Reprint **':CM'R#27'
          END ELSE
             IF CM THEN REPRINT.MSG = CM'R#78'
          END
          FT.LGTH = MCT

          IF REPRINT.MSG THEN FT.LGTH += 1


          IF IMAGE.FLAG THEN
             GOSUB PRT.SIG
          END





          ** PLINE is the next blank line number to print on
          ** Dont page feed unless we have more to print here
          IF ((PLINE + MCT) > BOD.LINES) AND (MCT # 0) THEN
             GOSUB FFEED
             GOSUB HEADER
          END

          PRINT CHAR(27):"*p0x":(2800-FT.LGTH*50):"Y":NORM

          FOR J = 1 TO MCT
             PRINT SPACE(1):INV.MSG<1,J> "L#79"
          NEXT J

          PRINT CHAR(27):"*p2790Y":NORM

          PRINT NORM.BOLD:
          TFTR = SPACE(79)
          TFTR[79-WIDTH.INSERT<COL.CT>-LEN(FTR.MSG<1>)+1,LEN(FTR.MSG<1>)] = FTR.MSG<1>
          TFTR[79-WIDTH.INSERT<COL.CT>+1,WIDTH.INSERT<COL.CT>] = RUNNING.TOTAL FTR.FMT
          PRINT TFTR
          DUE.MSG = " Invoice is due by ":OCONV(DUE.DT,"D2/")
          IF DISC.AMT < 0 THEN
             DISC.AMT = DISC.AMT * -1
             DISC.AMT = OCONV(DISC.AMT,'MR2')
             IF US.FUNDS THEN
                DISC.AMT = DISC.AMT/OCONV(US.FUNDS,'MR4') "MR2"
             END
             PRT.DATE = OCONV(DISC.DT,'D2/')
             DISC.MSG = " If paid by ":PRT.DATE :" you may deduct ":'$':DISC.AMT
             DUE.MSG := " net of any cash discount."
          END ELSE
             DISC.MSG = ''
             DUE.MSG := "."
          END
          IF RUNNING.TOTAL < 0 THEN
             DISC.MSG = ''
             DUE.MSG  = ''
          END
          TFTR = DISC.MSG 'L#79'
          TFTR[79-WIDTH.INSERT<COL.CT>-LEN(FTR.MSG<2>)+1,LEN(FTR.MSG<2>)] = FTR.MSG<2>
          TFTR[79-WIDTH.INSERT<COL.CT>+1,WIDTH.INSERT<COL.CT>] = (FREIGHT + HANDLING) FTR.FMT
          PRINT TFTR
          RUNNING.TOTAL += (FREIGHT + HANDLING)
          TFTR = DUE.MSG "L#79"
          TFTR[79-WIDTH.INSERT<COL.CT>-LEN(FTR.MSG<3>)+1,LEN(FTR.MSG<3>)] = FTR.MSG<3>
          TFTR[79-WIDTH.INSERT<COL.CT>+1,WIDTH.INSERT<COL.CT>] = TAX.AMT FTR.FMT
          PRINT TFTR

!!!!!!This TAX stuff is special for Canada...They have to split it up.
!         IF PST.RATE THEN
!            TAX.CHECK = OCONV(ICONV(RUNNING.TOTAL * PST.RATE,"MR0"),"MR2")
!            IF TAX.CHECK = TAX.AMT2 THEN
!               TAXABLE.AMT = RUNNING.TOTAL
!            END ELSE
!            TAXABLE.AMT = OCONV(ICONV((TAX.AMT2*10000/PST.RATE),"MR0"),"MR2")
!            IF TAXABLE.AMT > 0 THEN
!               IF TAXABLE.AMT > RUNNING.TOTAL THEN
!                  TAXABLE.AMT = RUNNING.TOTAL
!               END
!            END ELSE
!               IF TAXABLE.AMT < RUNNING.TOTAL THEN
!                  TAXABLE.AMT = RUNNING.TOTAL
!               END
!            END
!            END
!            NONTAX.AMT  = RUNNING.TOTAL - TAXABLE.AMT
!            TAXABLE.AMT = OCONV(ICONV(TAXABLE.AMT,"MR2"),"MR2")
!            NONTAX.AMT = OCONV(ICONV(NONTAX.AMT,"MR2"),"MR2")
!            PRINT " PST Taxable $":TAXABLE.AMT:
!            PRINT "   PST Exempt $":NONTAX.AMT
!            PRINT
!         END

          RUNNING.TOTAL += TAX.AMT

*         PRINT'' "L#58" :MED:ORD.ID :NORM.BOLD

          PRINT
          TFTR = SPACE(79)
          TFTR[79-WIDTH.INSERT<COL.CT>-LEN(FTR.MSG<4>)+1,LEN(FTR.MSG<4>)] = FTR.MSG<4>
          TFTR[79-WIDTH.INSERT<COL.CT>+1,WIDTH.INSERT<COL.CT>] = RUNNING.TOTAL FTR.FMT
          PRINT TFTR
          PRINT CHAR(27):"*p2940Y"

          *** Line one of the shortage claim message...
          SHORT.MSG1  = 'All claims for shortage or errors must be made '
          SHORT.MSG1 := 'at once. Returns require written authorization'
          PRINT ELPI:SUP.SMALL:SHORT.MSG1

          *** Line two of the shortage claim message...
          SHORT.MSG2  =  'and are subject to handling charges.   '
          SHORT.MSG2 :=  'Special orders are non-returnable. '
          PRINT SHORT.MSG2

          READV SERV.RATE FROM CTRLFILE,'DEFAULT.SERVICE.CHG.PCT',1 ELSE SERV.RATE = '150'

          SERV.RATE = OCONV(SERV.RATE,'MR2')
          SERV1     = FIELD(SERV.RATE,'.',1)-0
          SERV2     = FIELD(SERV.RATE,'.',2)-0
          IF SERV2  = 0 THEN SERV.RATE = SERV1

          PAST.DUE.MSG  = 'Past due invoices may be subject to ':SERV.RATE:'% '
          PAST.DUE.MSG := ' or $5 late charge, whichever is more.'
          PRINT SMALL:PAST.DUE.MSG:

          PRINT SLPI:NORM:

          RETURN
*-------------------------------------------------------------------------*
PRT.SIG:  * These parameters must be set at each client location
          *
          PROF.IDS = ''
          POS.CMDS = ''
          BOUNDS   = ''
          XSCALES  = ''
          YSCALES  = ''

          PROF.IDS<1> = 'EMAN'
          *** Change the position to print the signature box based
          *** on the number of lines in the footer. This will make sure
          *** the signature box prints above any invoice/reprint messages
          POS.CMDS<1> = CHAR(27):"*p10x":(2500-FT.LGTH*50):"Y"
          BOUNDS<1,1> = 1200                     ; * Maximum width
          BOUNDS<1,2> = 300                      ; * Maximum height
          BOUNDS<1,5> = 1                        ; * If true, scale bitmap
          XSCALES<1>  = 6
          YSCALES<1>  = 6

          PROF.IDS<2> = 'EPAD'
          *** Change the position to print the signature box based
          *** on the number of lines in the footer. This will make sure
          *** the signature box prints above any invoice/reprint messages
          POS.CMDS<2> = CHAR(27):"*p10x":(2500-FT.LGTH*50):"Y"
          BOUNDS<2,1> = 1200                     ; * Maximum width
          BOUNDS<2,2> = 300                      ; * Maximum height
          BOUNDS<2,5> = 1                        ; * If true, scale bitmap
          XSCALES<1>  = 6
          YSCALES<1>  = 6

          SOE.PRINT.SIG ORD.ID,PROF.IDS,POS.CMDS,BOUNDS,XSCALES,YSCALES,ERR.MSG,SIG.PRTED
          RETURN
*-------------------------------------------------------------------------*
PRTTRK:    * Print  Number Information


             IF TRACKING.NO # '' AND PAGE = 1 THEN
             BLINE += 1
             BOD<BLINE> = SPACE(1):'****** Tracking Information *******'
             BLINE += 1
             BOD<BLINE> = SPACE(1):'* Carrier: ':CARRIER


             CT = DCOUNT(TRACKING.NO,SVM)

             FOR JJ = 1 TO CT
                BLINE += 1
                BOD<BLINE> =  SPACE(1):"* ":TRACKING.NO<1,1,JJ>"L#35"
             NEXT JJ

             BLINE += 1
             BOD<BLINE> = SPACE(1):STR('*',35)

             BLINE += 1
             BOD<BLINE> = ''

          END


          RETURN
*-------------------------------------------------------------------------*
CHKCC:    * Check for Credit Card information

          *** Get any Payments that apply to this order...
          SOE.FORMS.GET.CC.INFO OID,GEN,CC.AMT,PAYMENT.IDS

          IF PAYMENT.IDS THEN
             *** Open Credit Card Payment file
             UT.OPEN.FILE "CC.PAYMENTS",CCPFILE,ERR.MSG
             IF ERR.MSG THEN RETURN

             PAYMENT.CT = DCOUNT(PAYMENT.IDS,VM)

             FOR PC = 1 TO PAYMENT.CT
                READ CC FROM CCPFILE,PAYMENT.IDS<1,PC> ELSE CC = ''
                IF CC THEN GOSUB PRTCC
             NEXT PC
          END

          RETURN
*-------------------------------------------------------------------------*
PRTCC:    * Print Credit Card Information
          AUTHDT = OCONV(CC<2>, 'D4/')        ;* Date of Authorization
          AUTH   = CC<3>                      ;* Auth Code
          CHGAMT = OCONV(CC<6>,'MR2')         ;* Amount Charged
          BBATCH = CC<12>                     ;* Banks Batch Reference
          TERMID = CC<15>                     ;* Terminal ID
          MRCHID = CC<16>                     ;* Merchant ID
          REF    = CC<17>                     ;* Item Number
          SWIPE  = CC<20>                     ;* Swipe info

*** Break out swiped data
          IF SWIPE THEN
             CREDIT.CARD.READ.SWIPE SWIPE,TRACK1,TRACK2,CCARD.NO,EXP.DT,CNAME,ERR.MSG
          END ELSE
             CCARD.NO   = CC<4,1>
             EXP.DT     = CC<4,2>
             CNAME      = CC<32>                     ;* Credit Card Holder
          END

          CREDIT.CARD.GET.DEFINE CCARD.NO,TYPE

*** Mask card with X's - only display last 4 numbers
          CCARD.NO  = STR('X',LEN(CCARD.NO)-4):RIGHT(CCARD.NO,4)

*** Print the Credit Card Information on same page, need 13 lines
*** Calculate the number of lines left on page


          OE.TOTL    = OCONV(OE.TOTL,'MR2')

          IF OE.TOTL = CHGAMT THEN
             PAID.IN.FULL = YES
          END ELSE
             PAID.IN.FULL = NO
          END

          LNSLEFT = BOD.LINES - MOD(BLINE, BOD.LINES)
          IF LNSLEFT < 10 THEN
             FOR FILL = 1 TO LNSLEFT
                BLINE     += 1
                BOD<BLINE> = ''
             NEXT FILL
          END

          LN = BLINE

          BOD<LN+1>    = ' '
          BOD<LN+2>    = '    ':STR('*',23):' Credit Card Information '
          BOD<LN+2>   := STR('*',24)
          BOD<LN+3>    = '    *':SPACE(70):'*'
          BOD<LN+4>    = '    * Merchant ID# : ':MRCHID     "L#20"
          BOD<LN+4>   := ' Time/Date: ':TIMEDATE()          "L#22":'*'
          BOD<LN+5>    = '    * Card Number  : ':CCARD.NO   "L#20"
          BOD<LN+5>   := ' Card Type: ':TYPE                "L#6"
          BOD<LN+6>    = '    * Card Holder  : ':CNAME      "L#20"
          BOD<LN+6>   := ' Auth Code: ':AUTH                "L#22":'*'
          BOD<LN+7>    = '    * Charge Amount: $':CHGAMT    "L#19"
          BOD<LN+7>   := ' Charge Date: ':AUTHDT            "L#20":'*'
          BOD<LN+8>    = '    *':SPACE(70):'*'

          IF PAID.IN.FULL THEN
             BOD<LN+9> = '    *':SPACE(28):'PAID IN FULL':SPACE(30):'*'
             BOD<LN+10>   = '    *':STR('*', 71)
          END ELSE
             BOD<LN+9>   = '    *':STR('*', 71)
          END


          BLINE += 10

          RETURN
*-------------------------------------------------------------------------*
FFEED:    *
     *    PRINT
          IF REPRINT THEN
             PRINT CHAR(27):"*p3050Y"
             PRINT SPACE(57):SMALL:'** Reprint ** Reprint ** Reprint **':NORM:
          END
          *** Page Break...
          PRINT CHAR(12):

          RETURN
*-------------------------------------------------------------------------*
DRAWSHADING: *** Draw shaded boxes to fill in headers

          PERC = 11   ;* Shade at 11%
          REST = 100  ;* Restore to 100%
          HGHT = 1    ;* All boxes are 1 char height

          FORMS.PRINT.SHADE PERC,1621, 190,2.5,HGHT,REST  ;* Inv Dt/Number
          FORMS.PRINT.SHADE PERC,2101, 340,0.9,HGHT,REST  ;* Page Number
          FORMS.PRINT.SHADE PERC,   0, 910,7.9,HGHT,REST  ;* 1st full line
          FORMS.PRINT.SHADE PERC,   0,1060,7.9,HGHT,REST  ;* 2nd full line
          FORMS.PRINT.SHADE PERC,   0,1210,7.9,HGHT,REST  ;* 3rd full line

          RETURN
*-------------------------------------------------------------------------*
SET.MACRO: *** Print macro or create if necessary

          MACRO.OK = ''

          *** Check to see if this macro is already loaded
          PTR.MACRO.ACTIVE MACRO.ID,PRT.SEQ

          *** If a sequence is returned, use to print macro immediately
          IF PRT.SEQ THEN GOTO PRT.MACRO

          *** Begin saving macro (suspend physical printing)
          PTR.MACRO.SAVE.ON MACRO.ID,MACRO.OK

          *** 'Print' the overlay - this does NOT physically print,
          *** anything between SAVE statements is only saved to macro
          DOC.FORM.CONVERT DOC.FORM.REC,DOC.FORM.SPEC
          DOC.FORM.PRINT DOC.FORM.SPEC,"1"
          GOSUB DRAWSHADING

          *** Stop saving macro (resume physical printing)
          PTR.MACRO.SAVE.OFF MACRO.ID,MACRO.OK,PRT.SEQ

PRT.MACRO: *** Print the macro with saved or newly created sequence

          IF PRT.SEQ THEN
             *** For each !, print CHAR(27) and the following characters
             CONVERT '!' TO AM IN PRT.SEQ
             ESC.CT = DCOUNT(PRT.SEQ,AM)
             FOR XX = 2 TO ESC.CT
                PRINT CHAR(27):PRT.SEQ<XX>:
             NEXT XX
             PRINT
          END

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

          RETURN
*-------------------------------------------------------------------------*
ACT.TRIG: *** Activate the "Invoice Print" trigger, T022

          DOCS.PRDCD = ''

          * Don't call the trigger if we are coming in from a VSIFax email
          IF DRPT<27> = 'HOLD' THEN RETURN

          AT.ID        = 'T022'
          AT.DATA      = ''
          AT.DATA<2,1> = LED(5)<1,GEN>
          AT.DATA<2,2> = LED(1)<1,GEN>
          AT.DATA<3>   = LED(2)<1,GEN,1>
          AT.DATA<4>   = OID
          AT.DATA<5>   = GEN
          AT.DATA<6>   = LED(8)<1,GEN>
          AT.DATA<7>   = LED(6)<1,GEN>

          IF PRT.ON THEN
             SV.PPROC = PHANTOM.PROC
             PHANTOM.PROC = YES
             ACTIVITY.TRIGGER AT.ID,AT.DATA,DOCS.PRDCD
             PHANTOM.PROC = SV.PPROC
          END ELSE
             ACTIVITY.TRIGGER AT.ID,AT.DATA,DOCS.PRDCD
          END

          RETURN
*-------------------------------------------------------------------------*
!TSMITH~04/08/16~10:22
