          VVBROUTINE (OID,GEN,PSTYLE.OVRD,PRT.ON,DRPT,NUM.PGS)
** Version# 1.0621[3] - 09/07/2010 - 09:23am - SMITJR - eclipse
*** V1.0621 Change - Custom Coding CUSTOM - 09/07/2010 - SMITJR - eclipse
*** V1.062 Change - Custom Coding CZU355 - 04/21/2010 - PETERG - eclipse
*** V1.0619 Change - Custom Coding CZV696 - 02/17/2010 - JONW - UPGRADE
*** V1.0618 Change - Custom Coding CZH329 - 10/23/2009 - MATTD - eclipse
*** V1.0617 Change - Custom Coding CZK327 - 10/21/2009 - MATTD - eclipse
*** V1.0616 Change - Custom Coding CZK327 - 09/03/2009 - GREGS - eclipse
*** V1.0615 Change - Custom Coding CZA866 - 04/27/2009 - GREGS - eclipse
*** V1.0614 Change - Custom Coding CYU917 - 03/31/2009 - MATTD - eclipse
*** V1.0613 Change - Custom Coding CYJ853 - 02/17/2009 - GREGS - eclipse
*** V1.0612 Change - Custom Coding HDB282 - 10/16/2007 - HEATHERY - UPGRADE
*** V1.0611 Change - Custom Coding CUJ837 - 02/06/2007 - MNAVEEN - eclipse
*** V1.0610 Change - Custom Coding CSS602 - 08/01/2005 - HAZELTON - eclipse
*** V1.0609 Change - Custom Coding CRX856 - 08/17/2004 - JONW - UPGRADE
*** V1.0608 Change - Custom Coding HCW526 - 06/16/2004 - KRIVERA - eclipse
*** V1.0607 Change - Custom Coding HBN511 - 06/27/2003 - JMROCH - eclipse
*** V1.0606 Change - Custom Coding HBN511 - 06/25/2003 - JMROCH - eclipse
*** V1.0605 Change - Custom Coding HBN511 - 06/19/2003 - JMROCH - eclipse
*** V1.0604 Change - Custom Coding HBN511 - 06/13/2003 - JMROCH - eclipse
*** V0.0001 Change - Custom Coding HBN511 - 06/13/2003 - JMROCH - eclipse
*** V48.15 Change - Add PARTIAL Ver 98 - 05/02/2003 - JOHNG - r7.basecode
*** V48.14 Change - Add PARTIAL Ver 80 - 04/04/2003 - KRISF - r7.basecode
*** V48.13 Change - Add FULL Ver 85,91 - 04/01/2003 - JOHNG - r7.basecode
*** V48.12 Change - Add FULL Ver 58 - 03/31/2003 - KRISF - r7.basecode
*** V48.11 Change - Add PARTIAL Ver 90 - 01/27/2003 - JOHNG - r7.basecode
*** V48.10 Change - Add FULL Ver 74 - 01/17/2003 - JOHNG - r7.basecode
*** V48.09 Change - Add FULL Ver 87 - 11/21/2002 - CHUCKW - r7.basecode
*** V48.08 Change - Add FULL Ver 71 - 08/13/2002 - JOHNG - r7.basecode
*** V48.07 Change - Add PARTIAL Ver 70 - 07/29/2002 - ERINZ - r7.basecode
*** V48.06 Change - Add FULL Ver 75 - 07/22/2002 - JOHNG - r7.basecode
*** V48.05 Change - Add FULL Ver 65 - 03/13/2002 - ERINZ - r7.basecode
*** V48.05 Change - Add PARTIAL Ver 1 - 03/13/2002 - ERINZ - r7.basecode
*** V48.04 Change - Add PARTIAL Ver 62 - 01/15/2002 - ROELANTV - r7.basecode
*** V48.04 Change - Custom Coding COH065 - 01/14/2002 - ROELANTV - r7.basecode
*** V48.03 Change - Custom Coding COF065 - 12/27/2001 - KRISF - r7.basecode
*** V48.02 Change - Custom Coding COF065 - 12/07/2001 - ROELANTV - r7.basecode
*** V48.01 Change - Custom Coding COF065 - 12/05/2001 - MARCW - r7.basecode
*** Subroutine - SOE.PRINT.INVOICE
*-------------------------------------------------------------------------*
*** This subroutine prints or faxes an invoice
*-------------------------------------------------------------------------*
*** Variables:
***       OID         - Order Id we're printing an Invoice for.       [In]
***       GEN         - Order Generation we're printing Invoice for.  [In]
***       PSTYLE.OVRD - Print Style Override.                         [In]
***       PRT.ON      - Flag indicating if printer already turned on. [In]
***       DRPT        - REPORTS Record values.                        [In]
***       NUM.PGS     - Number of Pages Printed                      [Out]
*-------------------------------------------------------------------------*
*** Common: LED, LD, CUS, CUSS, PRD, PLNE, DRPT, AR, PHANTOM.PROC
***         INVOICE.COPY.CT$, JAVA.PROC$
*-------------------------------------------------------------------------*

          DIM PSTYL(10)

          UT.OPEN.FILE "PRINT.STYLES",PSTYLFILE,ERR.MSG
          IF ERR.MSG THEN RETURN

          UT.OPEN.FILE "CUST.INVOICE.CMT",CUSTCMTFILE,ERR.MSG

          PG.LGTH = 30

          IF DRPT<29> THEN FAX.FLAG = YES ELSE FAX.FLAG = NO

          FTR.MSG    = "Subtotal"
          FTR.MSG<2> = "S&H CHGS"
          FTR.MSG<3> = "Sales Tax"
          FTR.MSG<4> = "Amt Due"

          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

          IF DRPT<27> # 'HOLD' THEN
             PTR.ID = FIELD(PRINTER.ID[3,99],'-',1)
             DRPT<27> = TRIM(PTR.ID)
          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

          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
                      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

          GOSUB FOOTER

          GOSUB PRINT.GL.PAGE

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

          NUM.PGS = PAGE

          GOTO FINISH
*-------------------------------------------------------------------------*
INIT:     *
          SSPC       = 1
          PAGE       = 0
          SUBT.LINES = 0
          SUBT.SW    = NO
          IN.FOOTER  = NO
          ORIG.DISC.TAKEN = 0
          NUM.PGS    = 0

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

          *** Build the Branch address info for the 'Remit To' section
          *** of our Invoice Heading...
          GET.BR.REMIT.ADDR ST.CN,BR,REM.BR

          REMIT = REM.BR<1>
          IF REM.BR<2,1> # '' THEN REMIT<-1> = REM.BR<2,1>
          IF REM.BR<2,2> # '' THEN REMIT<-1> = REM.BR<2,2>
          REMIT<-1> = TRIM(REM.BR<3>):', ':REM.BR<4>:' ':REM.BR<5>

          BR.ADDR2 =  ""
          FOR X = 1 TO 6
             READV BR.EN FROM TERRFILE,X,4 ELSE BR.EN = ''
             IF X = 6 THEN BR.EN = '14523'
             READ CUS.BR FROM CUSFILE,BR.EN ELSE CUS.BR = ''

             BR.ADDR2<X> = CUS.BR<2,1>
             IF CUS.BR<2,2> # '' THEN BR.ADDR2<X> := " - ": CUS.BR<2,2>
             BR.ADDR2<X> := " - ": TRIM(CUS.BR<3>):', ':CUS.BR<4>:' ':CUS.BR<5>
             BR.ADDR2<X> := " - ": CUS.BR<17,1>
          NEXT X


          *** 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 = ''

          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> = TRIM(CUS.BR<3>):', ':CUS.BR<4>:' ':CUS.BR<5>

          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
          END ELSE
             FAX.PHONE = ''
          END

          BR.ADDR<-1> = CUS.BR<17,1>:FAX.PHONE

          PRINT.PICK = NO
          CASH.SALE  = NO
          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) 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 JJ = 1 TO GN.CT
                *** Get the Invoice Status...
                ST = LED(6)<1,JJ>
                STATUS.OK = (ST # 'X' AND ST # 'Y' AND ST # '$' AND ST # 'B')
                IF LED(8)<1,JJ> 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,JJ> < INVN THEN SNGL.INV = 2; EXIT
                END
             NEXT JJ
          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"
          MED       := CHAR(27):'(s0p12h0s3b3T'
          LBL.SMALL  = CHAR(27):"(8U":CHAR(27):'(s0p20h8.5v0s7b6T'
          SUP.SMALL  = CHAR(27):"(8U"
          SUP.SMALL := CHAR(27):'(s0p20h0s0b0T'
          HDR.SMALL  = CHAR(27):"(8U":CHAR(27):'(s0p14h0s1b3T'
          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'

          OCR.FLAG  = NO
          OCR.MARK1 = SPACE(57)
          OCR.MARK2 = SPACE(57)

          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

          STYLE.ID = 'INVOICE'

          GOSUB GET.PSTYLE

          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>
          SHIP.VIA = LED(70)<1,GEN>
          ORD.DATE = LED(4)<1,GEN>
          INV.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
*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"

          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>
          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

          READV INV.CMT FROM CUSTCMTFILE,ST.CN,1 ELSE INV.CMT = ''
          FOLD.STRING INV.CMT,30,NEWSTRING,VCT
          INV.CMT = NEWSTRING

          SHP.INST = ''
          CUS.PO   = LED(13)<1,GEN>
          CUS.JOB  = LED(65)<1,GEN>
          ORD      = FIELD(ORD.ID,'.',1)
          GN       = FIELD(ORD.ID,'.',2)

          US.FUNDS = LED(92)<1,GEN,2>
          IF US.FUNDS # '' AND NOT(NUM(US.FUNDS)) THEN US.FUNDS = ''

          GL.PAGE = NO

          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
*-------------------------------------------------------------------------*
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
                IF COL.HEADS<1,CC> = '' THEN COL.HEADS<1,CC> = ' '
                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:   *
          IF NOT(GL.PAGE) THEN
             CTRL.ID = 'INVOICE.FORM.GL'
          END ELSE
             CTRL.ID = 'INVOICE.FORM.GL.FINAL'
          END

          DOC.FORM.SPEC = ''
          READ DOC.FORM.REC FROM CTRLFILE,CTRL.ID ELSE
             DOC.FORM.REC = ''
          END

          PRINT CHAR(27):"*p0Y":
          *** Set MACRO.ID to be unique to this overlay
          MACRO.ID = 'INVOICE~':STYLE.ID
          GOSUB SET.MACRO

          PAGE = PAGE + 1
          LINE.CT = PG.LGTH
          IF NUM(GN) THEN GN = GN+0

          PRINT CHAR(27):"*p30x30y":
          IF BR # '6' THEN
             PTR.MACRO.PRINT ERR.MSG, 'MURRAYINV', DRPT
             IF ERR.MSG THEN PRINT ERR.MSG
          END ELSE
             PTR.MACRO.PRINT ERR.MSG, 'FULLER', DRPT
             IF ERR.MSG THEN PRINT ERR.MSG
          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(60):LARGE:DOC.ID:NORM

          PRINT CHAR(27):"*p165Y":SLPI
          PRINT
          PRINT OCR.MARK1
          PRINT OCR.MARK2 :OCONV(INV.DATE,'D2/')   "L#10":
          PRINT ORD.ID                             "L#12"

          PRINT CHAR(27):"*p315Y"
          PRINT '' "L#57":SMALL:"REMIT TO:":NORM:ELPI
          PRINT '' "L#57":SUP.SMALL:'MURRAY SUPPLY COMPANY' "L#30":NORM
          PRINT '' "L#57":SUP.SMALL:'P.O. BOX 15023' "L#30":NORM
          PRINT '' "L#57":SUP.SMALL:'WINSTON-SALEM NC 27113' "L#30":NORM:PAGE  "R#5"
          PRINT '' "L#57":SUP.SMALL:' ' "L#30":NORM

          PRINT CHAR(27):"*p565Y":SLPI
          PRINT SPACE(7):SMALL:"BILL TO:":NORM:
          PRINT SPACE(32):SMALL:SPACE(2):"SHIP TO:":NORM
          FOR II = 1 TO 4
             PRINT SPACE(7):BILL.ADDR<II>'L#38':SHIP.ADDR<II>
          NEXT II

          PRINT CHAR(27):"*p1185Y"
          PRINT SPACE(62):

          IF NOT(GL.PAGE)  THEN
             PRINT LBL.SMALL:"NET UNIT PRICE      NET AMOUNT":NORM
          END

       *------Header Info------*
          PRINT CHAR(27):"*p890Y"
          PRINT ; PRINT

          PRINT '    ':BT.CN          "L#10":
          PRINT CUS.PO                "L#23":
          PRINT CUS.JOB               "L#23":
          PRINT OCONV(ORD.DATE,'D2/') "L#10":
          PRINT OCONV(INV.DATE,'D2/') "L#10"

          PRINT ; PRINT

          PRINT ' ':ORD.ID            "L#13":
          PRINT SHIP.VIA              "L#23":
          PRINT WRITER                "L#23":
          PRINT SPACE(4):STK.BR       "L#6":
          PRINT SALESMAN              "L#10"

          PRINT

          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)
             GOSUB SUBT.ONE
             PRINT
          END

          IF INV.CMT # '' AND PAGE = 1 THEN
             GOSUB SUBT.ONE
             PRINT SPACE(10):'******** Invoice Comment *********'
             CT = DCOUNT(INV.CMT,VM)
             FOR JJ = 1 TO CT
                GOSUB SUBT.ONE
                PRINT SPACE(10):"* ":INV.CMT<1,JJ>"L#30":" *"
             NEXT JJ
             GOSUB SUBT.ONE
             PRINT SPACE(10):STR('*',34)
             GOSUB SUBT.ONE
             PRINT
          END

          BO.HEADING = NO

          PRINT MED:

          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

          IF LINE.CT = 1 THEN
             LINE.CT -= 1
             PRINT
          END

          GOSUB SUBT.ONE
          PRINT PRT.STR1
          GOSUB SUBT.ONE
          PRINT 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,SUB.TOL,FREIGHT,HANDLING,TAX.AMT,FET.AMT
          FREIGHT   = OCONV(FREIGHT,'MR2')
          HANDLING  = OCONV(HANDLING,'MR2')
          TAX.AMT   = OCONV(TAX.AMT,'MR2')
          CASH.DISC = OCONV(CASH.DISC,'MR2')

          LDID.GENS   = GEN
          IF SNGL.INV = 1 THEN
             GN.CT = DCOUNT(LED(12),VM)
             FOR JJ = 1 TO GN.CT
                ST = LED(6)<1,JJ>
                IF JJ # GEN AND ST # 'X' AND ST # 'B' AND ST # '$' AND ST # 'Y' THEN
                   LDID.GENS<-1> = JJ
                   OE.ORDER.TOTAL OID,JJ,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 JJ
          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 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

          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 ELSE
                AR.ID = OID:'.':LED(8)<1,GEN>"R%3"
                SOE.PAYMENTS.DISC AR.ID,PAY.IDS,PAY.DTS,PAY.AMTS,DISC.TAKEN
                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 # ':PAY.ID
                   END ELSE
                      *TOTAL.COMMENT  = 'Prior Deposit on '
                      *TOTAL.COMMENT := OCONV(PAY.DT,'D2/')"L#8"
                   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
             END
             DISC.AMT = 0
          END

          ** If this is a return, check to see if they took a discount
          ** If so, then factor in the discount on this return form.
          BEGIN CASE

             ** If there was a credit on the same order number, then
             ** search the LEDGER.LOG to find the Original OID
             ** then check to see if there was a discount taken.
             CASE LED(30)<1,GEN> [1,2]= 'CR' AND LED(30)<1,GEN>#'CRD'
                READV FIND.ORIG FROM LEDLFILE,OID,10 ELSE FIND.ORIG = ''
                FINDSTR '** Original #' IN FIND.ORIG SETTING A,V,S ELSE NULL
                LOG.STR = FIND.ORIG<A,V,S>
                START.LETTER = INDEX(LOG.STR,'Original #',1)

                ** OID.LGTH$ only works in Rel 8 or higher
                ** For v7 - replace OID.LGTH$+4 with 8+4
                ORIG.OID = LOG.STR[START.LETTER+10,8+4]
                ORIG.AR.ID = ORIG.OID
                ** Get discount taken on the orginal order, if one.
                SOE.PAYMENTS.DISC ORIG.AR.ID,,,,ORIG.DISC.TAKEN

             ** If the return was on a seperate OID, then find the
             ** original OID and see if a discount was taken.
             CASE LD(44)
                ORIG.INVN = FIELD(LD(44),'.',2)
                ORIG.OID  = FIELD(LD(44),'.',1)
                ORIG.AR.ID = ORIG.OID:'.':ORIG.INVN  "R%3"
                ** Get discount on the original order, if one.
                SOE.PAYMENTS.DISC ORIG.AR.ID,,,,ORIG.TOTAL.DISC
                IF ORIG.TOTAL.DISC THEN
                     SOE.CALC.DISC OID,GEN,ORIG.DISC.TAKEN
                END
          END CASE

          IF ORIG.DISC.TAKEN THEN
             ORIG.DISC.TAKEN = -ORIG.DISC.TAKEN
             TOTAL.COMMENT  = 'Discount Taken On Returned Item'
             IF US.FUNDS THEN
                ORIG.DISC.TAKEN=ICONV(ORIG.DISC.TAKEN/OCONV(US.FUNDS,'MR4'),"MR0")
             END
             ORIG.DISC.TAKEN = ORIG.DISC.TAKEN * -1
             TOTAL.AMT      = OCONV(ORIG.DISC.TAKEN,'MR2')
             GOSUB PRINT.TOTAL
             RUNNING.TOTAL += TOTAL.AMT
             DISC.AMT       = 0
          END

          * If there is a web order discount then display it and
          * add to the 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: *
          GOSUB SUBT.ONE

          PRT.STR  = (TOTAL.COMMENT "R#36") TOTAL.FMT
          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-1))

          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'
             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

          UM      = LD(23)
          UM.LIST = PLNE(3)
          LOCATE UM IN UM.LIST<1> SETTING UM.POS ELSE UM.POS = 1
          PER     = PRD (7)<1,UM.POS>
          IF NOT(NUM(PER)) THEN PER = 1
          IF PER < 1 THEN PER = 1
          KEY     = FIELD(PRD(4)," ",2)

      ** 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>

          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

          QBO = QOPEN - QS

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

          IF SERIAL.TRACKING AND SERIAL.TRACKING # "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>
             NEXT SN
          END

          BEGIN CASE
          CASE CUS(74) = "Yes"
             IF LD(31) # '' THEN
                DESC<1,-1> = '************** Kit Components **************'
                KITMS = DCOUNT(LD(31),VM)
                FOR KK = 1 TO KITMS
                   KQTY  = LD(30)<1,KK>
                   READV KCMP FROM PRDFILE,LD(31)<1,KK>,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 KK
                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 KK = 1 TO KITMS
                   KQTY = LD(30)<1,KK>
                   READV KCMP FROM PRDFILE,LD(31)<1,KK>,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 KK
                DESC<1,-1> = STR('*',44)
             END
          CASE OTHERWISE
             NULL
          END CASE

          PRT.STR = ' '
          QS.STR  = ''
          PRT.STR = PRT.STR:KEY                     "L#8 "
          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
             IF Q2 THEN
                QS.STR = OCONV(Q1,"MR0,"):' ':OCONV(Q2,"MR0,")
             END ELSE
                QS.STR = OCONV(Q1,"MR0,")
             END
             QS.STR = QS.STR "R#5"
             PRT.STR  = PRT.STR:QS.STR
             PRT.STR  = PRT.STR:''                  "R#5"
             PRT.STR  = PRT.STR:''                  "R#5"
             QS       = ''
          END ELSE
             PRD.SEL = PRD(19)
             PRT.STR  = PRT.STR:" ":PRD.SEL         "L#20"
             IQ.TO.ALPHA PLNE(3),PRD(7),LD(23),QS,Q1,U1,Q2,U2,QS.ALPHA
             IF Q2 THEN
                QS.STR = OCONV(Q1,"MR0,"):' ':OCONV(Q2,"MR0,")
             END ELSE
                QS.STR = OCONV(Q1,"MR0,")
             END
             QS.STR = QS.STR "R#7"
             PRT.STR  = PRT.STR:QS.STR
          END

          GOSUB SUBT.ONE

          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
             OE.LOT.GET.XCURR ,,,,GEN,,LXRT
             PRT.STR := OCONV(LD(8)<1,GEN,1>/LXRT,'MR9') "R3#12"
             PRT.STR := OCONV(LD(8)<1,GEN,1>/LXRT,'MR9') "R2#11"
             COL.TOTAL<1,COL.CT> += OCONV(LD(8)<1,GEN,1>/LXRT,'MR9')
          END ELSE
             PRC.STR = ''
             OE.GET.PSTYLE OID,GEN,COL.START,COL.FRMTS,COL.BASIS,COL.EXTDS,COL.CT,QS,PRC.STR,COL.TOTAL,SUB.TOTAL
             PRC.STR = TRIM(PRC.STR)
             CONVERT '/' TO AM IN PRC.STR
             CONVERT ' ' TO AM IN PRC.STR
             PRT.STR := PRC.STR<1> "R3#11"
             PRT.STR := PRC.STR<2> "R2#11"
          END

          OE.CUS.PN.CMT.GET LED(1)<1,GEN>,LED(5)<1,GEN>,CUSS(66),PN,CMT

          IF NO.PRICING<LD.NO> THEN PRT.STR = SAVE.LINE

          PRINT MED:PRT.STR:NORM
          DESC = DELETE(DESC,1,1)
          GOSUB PRT.XDESC
*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
             IF DESC<1,DLN>[1,4] # 'Your'THEN
                PRINT MED:SPACE(10):DESC<1,DLN>"L#35":NORM
             END
          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
*-------------------------------------------------------------------------*
SUBT.ONE: *
          IF LINE.CT < 1 THEN
             GOSUB FFEED
             GOSUB HEADER
          END

          LINE.CT -= 1

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

          GOSUB PRINT.TOTALS

          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

          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
          END ELSE
             DISC.MSG = ''
          END
          DUE.MSG := "."

          IF RUNNING.TOTAL < 0 THEN
             DISC.MSG = ''
             DUE.MSG  = ''
          END

          IF DUE.MSG # '' THEN
             FOLD.STRING DUE.MSG,35,NEWSTRING,VCT
             DUE.MSG = NEWSTRING
          END
          DCT = DCOUNT(DUE.MSG,VM)

          FT.LGTH = MCT
          IF REPRINT.MSG THEN FT.LGTH += 1
          IF DUE.MSG     THEN FT.LGTH += DCT
          LN.CT   =  LINE.CT - FT.LGTH

          CHECK.FOR.IMAGES ORD.ID,'L',IMAGE.FLAG

          IF IMAGE.FLAG THEN LINES.NEEDED = 8 ELSE LINES.NEEDED = 0

          IF LN.CT < LINES.NEEDED THEN
             LN.CT = LINE.CT
             FOR J = 1 TO LN.CT
                PRINT
                LINE.CT -= 1
             NEXT J
             GOSUB SUBT.ONE
             PRINT
             LN.CT = LINE.CT - FT.LGTH
          END

          FOR J = 1 TO LN.CT
             PRINT
          NEXT J

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

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

          IF REPRINT.MSG THEN
             PRINT SPACE(9):REPRINT.MSG
          END

          FOR JJ = 1 TO DCT
             PRINT SPACE(9):DUE.MSG<1,JJ>"L#79"
          NEXT JJ

          PRINT NORM.BOLD:
          PRINT CHAR(27):"*p2840Y":
          PRINT SPACE(62): MED:FTR.MSG<1>:NORM
          PRINT CHAR(27):"*p2840Y":
          PRINT SPACE(70): MED:RUNNING.TOTAL      "R2#11":NORM

          PRINT CHAR(27):"*p2885Y":
          PRINT SPACE(62): MED:FTR.MSG<2>:NORM
          PRINT CHAR(27):"*p2885Y":
          PRINT SPACE(70): MED:(FREIGHT+HANDLING) "R2#11":NORM
          RUNNING.TOTAL += (FREIGHT + HANDLING)

          PRINT CHAR(27):"*p2930Y":
          PRINT SPACE(62): MED:FTR.MSG<3>:NORM
          PRINT CHAR(27):"*p2930Y":
          PRINT SPACE(70): MED:TAX.AMT            "R2#11":NORM
          RUNNING.TOTAL += TAX.AMT

          PRINT CHAR(27):"*p3030Y":
          PRINT SPACE(62): MED:FTR.MSG<4>:NORM
          PRINT CHAR(27):"*p3030Y":
          PRINT SPACE(70): MED:RUNNING.TOTAL      "R2#11":NORM

FOOTER.MESSAGE:

          PRINT CHAR(27):"*p2785Y"
          PRINT ELPI:SUP.SMALL:
          PRINT " Interest on amounts due shall be at the rate of 1.5% per month or 18% per year.   Customers and Murray Supply Company"
          PRINT " agree that this rate of interest shall apply and remain in force after judgement, pursuant to N.C.G.S.24-5(a). Murray"
          PRINT " Supply Company does not manufacture the goods it sells and makes no express warranties thereon. Murray Supply Company"
          PRINT " disclaims all implied warranties including any implied warranty of merchantability or fitness for a particular use.": SLPI
          PRINT SMALL:" RETURNED MERCHANDISE OR CLAIMS ARE SUBJECT TO THE CONDITIONS AS SHOWN ON SALES TICKET."
          PRINT SPACE(11):NORM.BOLD:DISC.MSG:NORM

          *** Page Break...
          PRINT CHAR(12):

          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
          BOD    = ''
          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  = LEFT(CCARD.NO,4):STR('X',LEN(CCARD.NO)-8):RIGHT(CCARD.NO,4)

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

          LN = 0
          IF LINE.CT < 11 THEN
             GOSUB FFEED
             GOSUB HEADER
          END

          CC.TOTL = OCONV(OE.TOTL,'MR2')
          IF CC.TOTL = CHGAMT THEN
             PAID.IN.FULL = YES
          END ELSE
             PAID.IN.FULL = NO
          END

          BOD<LN+1>   = ' '
          BOD<LN+2>   = '    *********************** Credit Card '
          BOD<LN+2>  := 'Information ************************'
          BOD<LN+3>   = '    *'                            "L#75":'*'
          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+5>  := '  Exp.: ':EXP.DT                  "L#8":'*'
          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>   = '    *'                            "L#75":'*'

          IF PAID.IN.FULL THEN
             BOD<LN+9> = '    *':SPACE(28):'PAID IN FULL':SPACE(30):'*'
          END ELSE
             BOD<LN+9> = '    *'                           "L#75":'*'
          END

          BOD<LN+10>  = '    *':STR('*', 71)

          FOR BLINE = 1 TO 13
             GOSUB SUBT.ONE
             PRINT BOD<BLINE>
          NEXT BLINE

          RETURN
*-------------------------------------------------------------------------*
FFEED:    *
          PRINT
          PRINT '   *** Continued on Next Page ***':
          LINE.CT = 0
          *** Page Break...
          PRINT CHAR(12):

          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

          OE.LOT.GET.XCURR ,,,,GEN,,S.XRATE
          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>/S.XRATE,'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

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

NO.PARTS: *
          NEXT CT

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

          SHADE1  = CHAR(27):'*v2T'
          SHADE1 := CHAR(27):'*c11G'    ;* 11% Shading
          SHADE1 := CHAR(27):'*c'
          SHADEH  = '720'               ;* SET TO 720 X # INCHES WIDE
          SHADE2  = 'H':CHAR(27):'*c'
          SHADEV  = '360'               ;* SET TO 720 X # INCHES HIGH
          SHADE3  = 'V':CHAR(27):'*p1R' ;* KEEP PATTERN FIXED
          SHADE3 := CHAR(27):'*c2P'     ;* 1 = SOLID  2 = SHADED ETC
          SHADE3 := CHAR(27):'*v0T'
          SHADE3 := CHAR(27):'*c100G'   ;* 100% Shade (RESTORE SOLID CHAR)

          PRINT CHAR(27):"*p1686X":    ;* BOX AT 1680
          PRINT CHAR(27):"*p184Y":     ;* BOX AT  190   190  - 6 = 184
          SHADEH = 2.3*720             ;* BOX 2.3"   WIDTH
          SHADEV = 720/6               ;* BOX 1 CHAR HEIGHT
          SHADE  = SHADE1:SHADEH:SHADE2:SHADEV:SHADE3
          PRINT SHADE

          PRINT CHAR(27):"*p2166X":    ;* BOX AT 2160
          PRINT CHAR(27):"*p334Y":     ;* BOX AT  340   340  - 6 = 334
          SHADEH = .7*720              ;* BOX .7"   WIDTH
          SHADEV = 720/6               ;* BOX 1 CHAR HEIGHT
          SHADE  = SHADE1:SHADEH:SHADE2:SHADEV:SHADE3
          PRINT SHADE

          PRINT CHAR(27):"*p6X":       ;* BOX AT 0
          PRINT CHAR(27):"*p904Y":     ;* BOX AT  910   910  - 6 = 910
          SHADEH = 7.9*720             ;* BOX 7.9"   WIDTH
          SHADEV = 720/6               ;* BOX 1 CHAR HEIGHT
          SHADE  = SHADE1:SHADEH:SHADE2:SHADEV:SHADE3
          PRINT SHADE

          PRINT CHAR(27):"*p6X":       ;* BOX AT 0
          PRINT CHAR(27):"*p1054Y":    ;* BOX AT  1160  1160 - 6 = 1160
          SHADEH = 7.9*720             ;* BOX 7.9"   WIDTH
          SHADEV = 720/6               ;* BOX 1 CHAR HEIGHT
          SHADE  = SHADE1:SHADEH:SHADE2:SHADEV:SHADE3
          PRINT SHADE

          PRINT CHAR(27):"*p6X":       ;* BOX AT 0
          PRINT CHAR(27):"*p1204Y":    ;* BOX AT  1210  1210 - 6 = 1204
          SHADEH = 7.9*720             ;* BOX 7.9"   WIDTH
          SHADEV = 720/6               ;* BOX 1 CHAR HEIGHT
          SHADE  = SHADE1:SHADEH:SHADE2:SHADEV:SHADE3
          PRINT SHADE

          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
*-------------------------------------------------------------------------*
PRINT.GL.PAGE:
          *** Print footer page showing totals by Product Select code.
          *** Site is using product select code to store a GL code for
          *** their customers.
          ***
          *** The tax amount will be prorated based on the material total
          *** of the select code

          *** Use GL.CALC print style to get EXT amount for each line
          STYLE.ID = "GL.CALC"
          GOSUB GET.PSTYLE

          DOC.ID     = ' ** GL TOTALS **  '

          *** Reconvert .FORM so that column headers use GL.CALC print styl
          DOC.FORM.SPEC = ''
          READ DOC.FORM.REC FROM CTRLFILE,'INVOICE.FORM.GL.LAST' ELSE
             DOC.FORM.REC = ''
          END

          *** Get amounts by GL code/Product select code
          GOSUB CALC.GL.BUCKETS

          GL.PAGE = YES

          *** Print header of GL totals page
          GOSUB HEADER

          PRT.STR  = SPACE(10)
          PRT.STR := STR("*",34)
          GOSUB SUBT.ONE
          PRINT PRT.STR
          PRT.STR  = SPACE(10)
          PRT.STR := "         GL Totals"
          GOSUB SUBT.ONE
          PRINT PRT.STR
          PRT.STR  = SPACE(10)
          PRT.STR := STR("*",34)
          GOSUB SUBT.ONE
          PRINT PRT.STR

          *** Loop thry GL codes and print amounts
          GL.CODE.CT = DCOUNT(GL.CODES,AM)
          FOR GG = 1 TO GL.CODE.CT
             PRT.STR  = SPACE(10)
             PRT.STR := GL.CODES<GG>        "L#35"
             PRT.STR := SPACE(17)
             PRT.STR := GL.AMOUNTS<GG>      "R2#11"
             PRT.STR := GL.TAX.AMOUNTS<GG>  "R2#11"
             PRT.STR := GL.AMOUNTS<GG> + GL.TAX.AMOUNTS<GG> "R2#11"

             GOSUB SUBT.ONE
             PRINT PRT.STR
          NEXT GG

          *** Print footer message but not order totals
          GOSUB FOOTER.MESSAGE

          RETURN
*-------------------------------------------------------------------------*
CALC.GL.BUCKETS:
          GL.CODES          = ""
          GL.AMOUNTS        = ""
          GL.TAX.AMOUNTS    = ""

          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

             LDID.CT = DCOUNT(LDIDS,SVM)
             FOR LD.NO = 1 TO LDID.CT
                LDID = LDIDS<1,1,LD.NO>
                LD.GET LDID
                PN   = LD(1)
                IF NOT(NUM(PN)) THEN CONTINUE

                SHIP.BR = LED(2)<1,LD.GEN,2>
                GET.ALL.PRD SHIP.BR,PN,QSIGN
                GOSUB CALC.GL.AMOUNT
             NEXT LD.NO
          NEXT LD.GEN

          GOSUB PRORATE.TAX

          RETURN
*-------------------------------------------------------------------------*
CALC.GL.AMOUNT: *

          *** Gl code is product select code
          GL.CODE = PRD(19)
          !!! Start Custom CZU355
          IF GL.CODE = 'White Goods' THEN RETURN
          !!! End Custom CZU355
          *** Use GL.CALC print style to get extended amount
          PRC.STR = ""
          QS = (SUM(LD(5)<1,GEN>) + SUM(LD(6)<1,GEN>)) * QSIGN
          OE.GET.PSTYLE OID,GEN,COL.START,COL.FRMTS,COL.BASIS,COL.EXTDS,COL.CT,QS,PRC.STR,COL.TOTAL,SUB.TOTAL

          *** Remove spaces and put in extranal format.  Print style is
          *** set to R2#15
          EXT.AMOUNT = TRIM(PRC.STR)
          EXT.AMOUNT = EXT.AMOUNT COL.FRMTS<1,1>

          LOCATE GL.CODE IN GL.CODES SETTING POS THEN
             GL.AMOUNTS<POS> += EXT.AMOUNT
          END ELSE
             GL.CODES<POS>    = GL.CODE
             GL.AMOUNTS<POS>  = EXT.AMOUNT
          END

          RETURN
*-------------------------------------------------------------------------*
PRORATE.TAX:
          *** loop thru GL buckets and prorate tax between them based on
          *** meterial total

          *** No tax... nothing to prorate
          IF TAX.AMT+0  = 0 THEN RETURN

          TAX.ALLOCATED = 0
          SUB.TOL   = OCONV(SUB.TOL,"MR2")

          *** Loop thry GL codes and asses tax percent
          GL.CODE.CT = DCOUNT(GL.CODES,AM)
          FOR GG     = 1 TO GL.CODE.CT-1

             *** Current GL amount
             CUR.GL.AMT  = GL.AMOUNTS<GG>

             *** Determine % that current GL buckt is of total sale
             MATERIAL.PERCENT = CUR.GL.AMT / SUB.TOL

             *** Assign that % of tax to the GL bucket
             CUR.TAX.TOL      = TRIM((TAX.AMT * MATERIAL.PERCENT) "R2#14")
             GL.TAX.AMOUNTS<GG>   = CUR.TAX.TOL

             *** Keep track of allocated tax to determine final bucket tax.
             *** This is better than doing a number calculation and then
             *** the totals of the buckets being off by a penny (rounding
             *** errors)
             TAX.ALLOCATED += CUR.TAX.TOL
          NEXT GG

          *** Add remaining tax
          GL.TAX.AMOUNTS<GL.CODE.CT> += TAX.AMT - TAX.ALLOCATED

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

          RETURN
*-------------------------------------------------------------------------*
!SMITJR~09/07/10~09:23
