          SUBROUTINE (OID,GEN,STATUS,RESP,PSTYLE.OVRD)
** Version# 136.0001[5] - 08/03/2012 - 12:58am - TSMITH - eclipse
*** V136.0001 Change - Custom Coding .. - 08/03/2012 - TSMITH - eclipse

*** Subroutine - SOE.MBX.ORDER.HTML
*-------------------------------------------------------------------------*
*** This routine will create an html document to send as an email
*** attachment from the calling program.  The document will be formatted
*** to display an Eclipse order (bid, open, shipping ticket, invoiced).
*-------------------------------------------------------------------------*
*** OID    - Order ID                                                 (IN)
*** GEN    - Generation of Order                                      (IN)
*** STATUS - Old Status of order                                      (IN)
*** RESP   - HTML response created through this program              (OUT)
*-------------------------------------------------------------------------*

          *** Return if Email Orders as Tiff Attachments is active
          EMAIL.CHECK.TIFF 'INV',OID,GEN,,EMAIL.TIFF

          IF EMAIL.TIFF THEN
             RESP = ''
             RETURN
          END

          GOSUB INIT              ;* Open web forms file and read in form
          GOSUB GET.BR.INFO       ;* Gets branch info -- rel7 and rel8
          GOSUB SET.LOGO          ;* Set up logo and color
          GOSUB SET.HDR           ;* Set up order header information
          GOSUB SET.LINES         ;* Set up line item information
          GOSUB SET.TOTALS        ;* Set up total information

          RETURN
*-------------------------------------------------------------------------*
INIT: *** Read in form to display order and setup neccesary variables.

          *** Status comes into this program as the order status, save this
          *** order status in ORD.STAT variable for HTML.GET.PSTYLE.
          ORD.STAT = STATUS

          *** Set the status to a email print status, email only splits
          *** statuses into 4 types of orders.
          IF STATUS # "B" AND STATUS # "I" AND STATUS # "T" AND STATUS # "O" AND STATUS # "M" THEN
             *** If it is not a bid, invoice, or ship ticket it's an ack.
             STATUS = "A"
          END

          *** Set up FORM.TYPE for FORMS.GET.LOT.PRC
          BEGIN CASE
          CASE STATUS = "A"
             FORM.TYPE = "ACK"
          CASE STATUS = "B"
             FORM.TYPE = "BID"
          CASE STATUS = "M"
             FORM.TYPE = "SUM"
          CASE STATUS = "I"
             FORM.TYPE = "INV"
          CASE STATUS = "T" OR STATUS = "O"
             FORM.TYPE = "SHIP"
          END CASE

          *** If this is a bid make it say "Quote To" instead of "Bill to"
          BEGIN CASE
          CASE STATUS = 'B'
             BILL.TITLE = 'QUOTE TO'
          CASE STATUS = 'I'
             BILL.TITLE = 'BILL TO'
          CASE OTHERWISE
             BILL.TITLE = 'SOLD TO'
          END CASE
          MODE     = OID[1,1]

          *** determine whether the order is a transfer or not
          IF OID[1,1] = 'T' THEN XFER.FLAG = YES ELSE XFER.FLAG = NO

          MATREAD LED FROM LEDFILE,OID ELSE MAT LED = ''
          BT.CN      = LED(1)<1,GEN>
          ST.CN      = LED(5)<1,GEN>
          PRC.BR     = LED(2)<1,GEN,1>
          SHIP.BR    = LED(2)<1,GEN,2>
          TERMS.ID   = LED(29)<1,GEN>
          FRGHT.ALLW = LED(69)<1,GEN,1>
          LOT.FLAG   = LED(98)<1,GEN>
          LD.GEN     = GEN
          AR.ID = OID:'.':LED(8)<1,GEN>"R%3"
          IF FRGHT.ALLW THEN
             FRGHT.ALLW = 'Yes'
          END ELSE
             FRGHT.ALLW = 'No'
          END
          OE.GET.QSIGN QSIGN,OID,GEN
          READV TERMS.DESC FROM TERMSFILE,TERMS.ID,1 ELSE
             TERMS.DESC=TERMS.ID
          END

          *** Check if user has the control record set to enable printing
          *** all gens on the acknowledgement
          READ PRT.ALL.GENS FROM CTRLFILE,'FRST.PRT.ALL.GENS' ELSE
             PRT.ALL.GENS = NO
          END

          *** Get the site's base currency.
          READV BASEC FROM CTRLFILE,'BASE.CURRENCY',1 ELSE BASEC = ''
          IF BASEC # "CAN$" THEN
             TAX.DESC  = '<tr><td><b>Tax</b></td>'
             TAX.DESC := '<td align="RIGHT"><b>&TAX&</b></td></tr>'
          END ELSE
             TAX.DESC  = '<tr><td><b>GST</b></td>'
             TAX.DESC := '<td align="RIGHT"><b>&GST.TAX&</b></td></tr>'
             TAX.DESC := '<tr><td><b>PST</b></td>'
             TAX.DESC := '<td align="RIGHT"><b>&PST.TAX&</b></td></tr>'
          END

          *** Check if this is the First Print. If this is the first print
          *** in the acknowledgement email, display all gens. If not the
          *** first print, display the gen specific one.
          IF PRT.ALL.GENS AND STATUS = 'A' THEN
             READV PRT.HIST FROM LEDLFILE,OID,1 ELSE PRT.HIST = ''
             PRT.HIST = RAISE(PRT.HIST)
             FPOS1=''; FPOS2=''; FPOS3='';
             *** Must locate in all elements since each gen can have
             *** multiple print histories per gen.
             FIND 'S' IN PRT.HIST SETTING FPOS1,FPOS2,FPOS3 THEN
                PRT.ALL.GENS = NO
             END
          END ELSE
             PRT.ALL.GENS = NO
          END

          IF STATUS # 'B' AND NOT(PRT.ALL.GENS) THEN
              SHP.QTY.RESP ='<td align="right" valign="top">&SHP.QTY&</td>'
              SHP.QTY.HEADER =  '<td bgcolor="&HDRCLR&" align="center"><small>Ship Qty</small></td>'
              ORD.COLSPAN = 1
          END ELSE
              SHP.QTY.RESP   = ''
              SHP.QTY.HEADER = ''
              ORD.COLSPAN = 2
          END

          *** Invoice printed as ack.
          IF LED(8)<1,GEN> # '' THEN PRT.ALL.GENS = NO
          PRC.BR     = LED(2)<1,GEN,1>
          IF PRC.BR='3' THEN
          FORM.NAME = 'SOE Email Order RED'
          END ELSE
          FORM.NAME = 'SOE Email Order'
          END



          WOE.GET.FORM.RESP 'E',FORM.NAME,RESP

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

          IF STATUS = "I" OR STATUS = "B" THEN
             ITEM.TAG.INFO  = '' ;* Item tag info
             OE.ITEM.TAG.READ OID,,,,ITEM.TAG.INFO
          END

          RETURN
*-------------------------------------------------------------------------*
GET.BR.INFO: *** gets the branch info

          *** remove this code once ALL our clients are on release 8
          $IFDEF REL8$
             IF STATUS # 'B' THEN
                READV BR.EN FROM TERRFILE,SHIP.BR,4 ELSE BR.EN = ''
             END ELSE
                READV BR.EN FROM TERRFILE,PRC.BR,4 ELSE BR.EN = ''
             END
             READ CUS.BR FROM CUSFILE,BR.EN ELSE CUS.BR = ''

             IF STATUS = 'I' THEN
                GET.BR.REMIT.ADDR ST.CN,PRC.BR,R.ADDR
             END ELSE
                R.ADDR = CUS.BR
             END
          $ELSE
             READ BRCH.REC FROM CTRLFILE,'BRANCHES' ELSE BRCH.REC = ''
             *** Check for an Alternate Remit-To Entity for this Branch...
             IF STATUS = 'I' THEN
                IF BRCH.REC<9,PRC.BR> THEN
                   REM.EN = BRCH.REC<9,PRC.BR>
                END ELSE
                   REM.EN = BRCH.REC<1,PRC.BR>
                END
             END ELSE
                REM.EN = BRCH.REC<1,PRC.BR>
             END

             *** get remit-to/order-to address
             READ R.ADDR FROM CUSFILE,REM.EN ELSE R.ADDR = ''
             BR.EN = BRCH.REC<1,PRC.BR>
             *** Get branch address
             READ CUS.BR FROM CUSFILE,BR.EN ELSE CUS.BR = ''
          $ENDIF
          *** end release 7/8 code

          RETURN
*-------------------------------------------------------------------------*
SET.LOGO: *** set the logo and color to be used in the html doc

          LOGO = ''
          LOGO.PATH = ''
          DATA = ''
          $IFDEF REL8$
             READ DATA FROM CTRBFILE,'EMAIL.DOC.LOGO.BR~':PRC.BR ELSE DATA=''
          $ENDIF

          IF DATA THEN
             LOGO.PATH = DATA<1>
             HDRCLR    = DATA<2>
             IF HDRCLR = '' THEN HDRCLR = '#CCCCCC'
             IF LOGO.PATH[1,7] # "http://" THEN LOGO.PATH = "http://":LOGO.PATH
             DOMAIN = 1
             GOTO SKIP.DOM
          END

          READ DATA FROM CTRLFILE,'EMAIL.DOC.LOGO' ELSE DATA = ''

          DOMAIN      = DATA<1>
          IMG.PATH    = DATA<2>
          HDRCLR      = DATA<3>
          IF HDRCLR = '' THEN HDRCLR = '#CCCCCC'

          *** make sure that the domain begins with http or https
          GOOD.DOMAIN = ''
          IF OCONV(DOMAIN,'MCU')[1,4] = 'HTTP' THEN
             GOOD.DOMAIN = DOMAIN
          END

          LOGO.PATH = ''
          IF GOOD.DOMAIN AND IMG.PATH THEN
             *** strip off the ending '/' from the domain if it exists.
             DOMAIN.LEN = LEN(GOOD.DOMAIN)
             IF GOOD.DOMAIN[DOMAIN.LEN,DOMAIN.LEN] = '/' THEN
                GOOD.DOMAIN = GOOD.DOMAIN[1,DOMAIN.LEN-1]
             END

             *** if image path does not begin with '/', add it.
             IF IMG.PATH[1,1] # '/' THEN
                IMG.PATH = '/':IMG.PATH
             END
             LOGO.PATH = GOOD.DOMAIN:IMG.PATH
          END

SKIP.DOM: *** skip the 'wack' check if we already have a good domain

          IF LOGO.PATH THEN
             LOGO := '<table border=0 cellpadding=0 cellspacing=0>'
             LOGO := '  <tr>'
             LOGO := '    <td align="center">'
             LOGO := '      <img src="':LOGO.PATH:'" border=0>'
             LOGO := '    </td>'
             LOGO := '  </tr>'
             LOGO := '</table>'
          END

          *** Build branch address for upper-left corner
          BR.ADDR = CUS.BR<1>
          IF CUS.BR<2,1> # '' THEN BR.ADDR<-1> = CUS.BR<2,1>
          IF CUS.BR<2,2> # '' THEN BR.ADDR<-1> = CUS.BR<2,2>
          BR.ADDR<-1> = CUS.BR<3>:', ':CUS.BR<4>:' ':CUS.BR<5>

          *** 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
          UT.REP.STR BR.ADDR,AM,'<br>'

          *** Only an invoice should say "remit to:"
          IF STATUS = 'I' THEN
             REMIT.HDR = 'REMIT TO:'
             PHONE  = R.ADDR<7,1>
          END ELSE
             REMIT.HDR = 'ORDER TO:'
             PHONE  = R.ADDR<17,1>
          END

          *** Build the Branch address info for the 'Remit To' section
          *** of our Invoice Heading
          REMIT1 = R.ADDR<1>
          REMIT2 = R.ADDR<2,1>
          IF R.ADDR<2,2> # '' THEN
             REMIT3 = R.ADDR<2,2>
             REMIT4 = R.ADDR<3>:', ':R.ADDR<4>:' ':R.ADDR<5>
             REMIT5 = 'Phone: ':PHONE<1,1>
          END ELSE
             REMIT3 = R.ADDR<3>:', ':R.ADDR<4>:' ':R.ADDR<5>
             REMIT4 = 'Phone: ':PHONE<1,1>
             REMIT5 = ''
          END

          REMIT.INFO  = ''
          REMIT.INFO :=  REMIT1:'<br>'
          REMIT.INFO :=  REMIT2:'<br>'
          REMIT.INFO :=  REMIT3:'<br>'
          REMIT.INFO :=  REMIT4
          IF REMIT5 THEN
             REMIT.INFO := '<br>':REMIT5
          END

          UT.REP.STR RESP,'&LOGO&',LOGO
          UT.REP.STR RESP,'&BR.ADDR&',BR.ADDR
          UT.REP.STR RESP,'&REMIT.HDR&',REMIT.HDR
          UT.REP.STR RESP,'&REMIT.INFO&',REMIT.INFO

          RETURN
*-------------------------------------------------------------------------*
SET.HDR:  *** Set up order header information

          GET.CUS PRC.BR,BT.CN,ST.CN,QSIGN

          *** We need to convert SVM to <br> in the shipping instructions
          *** to format properly
          SHIP.INS = TRIM(LED(74)<1,GEN>)
          IF SHIP.INS AND STATUS # 'I' THEN
             CONVERT SVM TO ' ' IN SHIP.INS
             SHIP.INS = '<b>Shipping Instructions:</b><br>':SHIP.INS:'<br><br>'
          END ELSE
             SHIP.INS = '<br>'
          END

          *** Get the invoice message for this branch.
          INV.MSG = ''
          IF STATUS = 'I' THEN
             READV INV.MSG FROM CTRLFILE,'INVOICE.MESSAGE:':PRC.BR,1 ELSE
                INV.MSG = ''
             END
             IF INV.MSG THEN INV.MSG := '<br><br>'
          END

          *** Set up the bid message if this is a bid.
          BID.MSG = ''
          IF STATUS = 'B' THEN
             READ BID.MSG FROM CTRLFILE,'EMAIL.BID.MSG' ELSE BID.MSG = ''
             IF BID.MSG THEN
                BID.MSG := '<br><br>'
             END
          END

          *** Format the bid msg
          *** convert 2 SVM's (2 returns) to a new paragraph
          UT.REP.STR BID.MSG,SVM:' ':SVM,'<p>'
          UT.REP.STR BID.MSG,VM:' ':VM,'<p>'

          *** convert 2 SVM's (2 returns) to a new paragraph
          UT.REP.STR BID.MSG,SVM:SVM,'<p>'
          UT.REP.STR BID.MSG,VM:VM,'<p>'

          *** need to zap out any remaining SVM's before sending out
          CONVERT SVM TO ' ' IN BID.MSG
          CONVERT VM TO ' ' IN BID.MSG

          CLAIM.MSG = ''
          IF STATUS = 'I' THEN
             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

             CLAIM.MSG = 'All claims for shortage or errors must be made at once, returns require written authorization and are subject to handling charges.  Special orders are non-returnable.<br>Past due invoices may be subject to ':SERV.RATE:'% late charge.'
          END

          *** Shipment tracking message.
          TRK.MSG = ''
          IF STATUS # 'B' THEN
             GOSUB GET.TRACKING.INFO
          END

          *** Set up order type description that will be seen at the
          *** header of the email
          ORDNO = OID
          BEGIN CASE
          CASE STATUS  = 'A'
             TYPE.DESC = 'Acknowledgement'
             DOC.TYPE  = 'Order'
             TOT.MSG   = 'Total'
             DOC.TP    = 'S'
          CASE STATUS  = 'B'
             TYPE.DESC = 'Quotation'
             DOC.TYPE  = 'Order'
             TOT.MSG   = 'Total'
             DOC.TP    = 'B'
          CASE STATUS  = 'I'
             TYPE.DESC = 'Invoice'
             INVN      = LED(8)<1,GEN>+0
             ORDNO    := '.':INVN "R%3"
             DOC.TYPE  = 'Invoice'
             TOT.MSG   = 'Amount&nbsp;Due'
             DOC.TP    = 'I'
          CASE STATUS  = 'T'
             TYPE.DESC = 'Ship Ticket'
             INVN      = LED(8)<1,GEN>+0
             ORDNO    := '.':INVN "R%3"
             DOC.TYPE  = 'Order'
             TOT.MSG   = 'Total'
             DOC.TP    = 'T'
          CASE OTHERWISE
             TYPE.DESC = 'Order'
             DOC.TYPE  = 'Order'
             TOT.MSG   = 'Total'
             DOC.TP    = 'S'
          END CASE
          BEGIN CASE
          CASE CUSS(97)
             *** USE SHIP TO FOR BILLING ADDRESS
             BILL.NAME = CUSS(1)
             IF CUSS(2)<1,1> # '' THEN BILL.ADDR1 = CUSS(2)<1,1>
             IF CUSS(2)<1,2> # '' THEN BILL.ADDR2 = CUSS(2)<1,2>:'<br>'
             BILL.CITY = TRIM(CUSS(3))
             BILL.ST   = CUSS(4)"L#4"
             BILL.ZIP  = CUSS(5)"L#14"
          CASE CUSS(91)<1,1>
             *** USE ALTERNATE SHIPTO IN SHIPTO RECORD
             BILL.NAME = CUSS(91)<1,1>
             IF CUSS(92)<1,1> # '' THEN BILL.ADDR1 = CUSS(92)<1,1>
             IF CUSS(92)<1,2> # '' THEN BILL.ADDR2 = CUSS(92)<1,2>:'<br>'
             BILL.CITY = TRIM(CUSS(93))
             BILL.ST   = CUSS(94)"L#4"
             BILL.ZIP  = CUSS(95)"L#14"
          CASE CUS(91)<1,1>
             *** USE BILL TO ALTERNATE ADDRESS
             BILL.NAME = CUS(91)<1,1>
             IF CUS(92)<1,1> # '' THEN BILL.ADDR1 = CUS(92)<1,1>
             IF CUS(92)<1,2> # '' THEN BILL.ADDR2 = CUS(92)<1,2>:'<br>'
             BILL.CITY = TRIM(CUS(93))
             BILL.ST   = CUS(94)"L#4"
             BILL.ZIP  = CUS(95)"L#14"
          CASE OTHERWISE
             *** USE BILLTO NORMAL METHOD
             BILL.NAME = CUS(1)
             IF CUS(2)<1,1> # '' THEN BILL.ADDR1 = CUS(2)<1,1>
             IF CUS(2)<1,2> # '' THEN BILL.ADDR2 = CUS(2)<1,2>:'<br>'
             BILL.CITY = TRIM(CUS(3))
             BILL.ST   = CUS(4)"L#4"
             BILL.ZIP  = CUS(5)"L#14"
          END CASE
          UT.REP.STR RESP,'&BT.NAME&' ,BILL.NAME         ;* Bill to Name
          UT.REP.STR RESP,'&BT.ADD1&' ,BILL.ADDR1        ;* Bill to Addr1
          UT.REP.STR RESP,'&BT.ADD2&' ,BILL.ADDR2        ;* Bill to Addr2
          UT.REP.STR RESP,'&BT.CITY&' ,BILL.CITY         ;* Bill to City
          UT.REP.STR RESP,'&BT.ST&'   ,BILL.ST           ;* Bill to State
          UT.REP.STR RESP,'&BT.ZIP&'  ,BILL.ZIP          ;* Bill to Zip
          UT.REP.STR RESP,'&ST.NAME&' ,CUSS(1)           ;* Ship to Name
          UT.REP.STR RESP,'&ST.ADD1&' ,LED(78)<1,GEN,1>  ;* Ship to Addr1
          UT.REP.STR RESP,'&ST.ADD2&' ,LED(78)<1,GEN,2>  ;* Ship to Addr2

          *** Allow for change between r6 and r7 format for the way
          *** Ship to city and state are stored
          IF LED(78)<1,GEN,3> = '' THEN
             UT.REP.STR RESP,'&ST.CITY&',LED(78)<1,GEN,4>
             UT.REP.STR RESP,'&ST.ST&'  ,LED(78)<1,GEN,5>
          END ELSE
             UT.REP.STR RESP,'&ST.CITY&',FIELD(LED(78)<1,GEN,3>,',',1,1)
             UT.REP.STR RESP,'&ST.ST&'  ,FIELD(LED(78)<1,GEN,3>,',',2,1)
          END

          UT.REP.STR RESP,'&ST.ZIP&'    ,LED(75)<1,GEN>  ;* Ship to Zip
          UT.REP.STR RESP,'&BILL.TITLE&',BILL.TITLE      ;* "Bill to"
          UT.REP.STR RESP,'&DOC.TYPE&'  ,DOC.TYPE        ;* Doc Type
          UT.REP.STR RESP,'&TOT.MSG&'   ,TOT.MSG         ;* Total Msg
          UT.REP.STR RESP,'&ORD.NO&'    ,ORDNO           ;* Order Number
          UT.REP.STR RESP,'&INV.MSG&'   ,INV.MSG         ;* Invoice msg
          UT.REP.STR RESP,'&BID.MSG&'   ,BID.MSG         ;* Bid msg
          UT.REP.STR RESP,'&CLAIM.MSG&' ,CLAIM.MSG       ;* Claim msg
          UT.REP.STR RESP,'&TRK.MSG&'   ,TRK.MSG         ;* Tracking msg
          UT.REP.STR RESP,'&SHIP.INS&'  ,SHIP.INS        ;* Ship Instrucs

          *** Check for values that may be blank and add space so that
          *** table fields don't look messed up
          SHIPVIA = LED(70)<1,GEN>
          IF SHIPVIA = '' THEN SHIPVIA = '&nbsp;'
          ORD.BY = LED(68)<1,GEN>
          IF ORD.BY = '' THEN ORD.BY = '&nbsp;'
          PO.NO = LED(13)<1,GEN>
          IF PO.NO = '' THEN PO.NO = '&nbsp;'
          REL.NO = LED(65)<1,GEN>
          IF REL.NO = '' THEN REL.NO = '&nbsp;'
          READV SLSPERSON FROM INIFILE,LED(72)<1,GEN>,3 ELSE SLSPERSON = LED(72)<1,GEN>
          IF SLSPERSON = '' THEN SLSPERSON = '&nbsp;'
          WRITER = LED(73)<1,GEN>
          * Use the actual User Name instead of the User ID on the printout
          READV WRITER FROM INIFILE,WRITER,3 ELSE NULL
          IF WRITER     = '' THEN WRITER     = '&nbsp;'
          IF TERMS.DESC = '' THEN TERMS.DESC = '&nbsp;'

          UT.REP.STR RESP,'&SHIPVIA&'  ,SHIPVIA           ;* Ship Via
          UT.REP.STR RESP,'&ORD.BY&'   ,ORD.BY            ;* Ordered By
          UT.REP.STR RESP,'&CUS.NO&'   ,LED(1)<1,GEN>     ;* Customer
          UT.REP.STR RESP,'&PO.NO&'    ,PO.NO             ;* PO Number
          UT.REP.STR RESP,'&REL.NO&'   ,REL.NO            ;* Release Number
          UT.REP.STR RESP,'&SLSPERSON&',SLSPERSON         ;* Salesperson
          UT.REP.STR RESP,'&WRITER&'   ,WRITER            ;* Writer
          UT.REP.STR RESP,'&TERMS&'    ,TERMS.DESC        ;* Terms

          GOSUB GET.STAT.DESC
          UT.REP.STR RESP,'&STATUS&'   ,STAT.DESC         ;* Status Desc

          IF STATUS = 'I' THEN
             UT.REP.STR RESP,'&INV.DATE&',OCONV(LED(9)<1,GEN>, 'D4/')
             UT.REP.STR RESP,'&DT.FRGHT.TITLE&','Order Date'
             UT.REP.STR RESP,'&DT.FRGHT&' ,OCONV(LED(4)<1,GEN>, 'D4/')
          END ELSE
             UT.REP.STR RESP,'&INV.DATE&',OCONV(LED(4)<1,GEN>, 'D4/')
             UT.REP.STR RESP,'&DT.FRGHT.TITLE&','Freight Allowed'
             UT.REP.STR RESP,'&DT.FRGHT&',FRGHT.ALLW
          END
          UT.REP.STR RESP,'&REQ.DATE&' ,OCONV(LED(10)<1,GEN>,'D4/')
          IF STATUS = 'B' THEN
             *** Expiration Date for bids.
             UT.REP.STR RESP,'&SHP.DT.TITLE&','Expr Date'
             UT.REP.STR RESP,'&SHP.DATE&' ,OCONV(LED(31)<1,GEN>, 'D4/')
          END ELSE
             UT.REP.STR RESP,'&SHP.DT.TITLE&','Ship Date'
             UT.REP.STR RESP,'&SHP.DATE&' ,OCONV(LED(9)<1,GEN>, 'D4/')
          END

          *** Check if the zip code has a defined delivery time, to check
          *** for delivery time look at the Zip Code Maint screen, F1-Z.
          *** If delivery time is defined, instead of displaying warehouse
          *** info in the acknowledgement printout, display delivery time
          DLV.TIME = ''
          IF LED(75)<1,GEN> # '' THEN
             READV DLVR.TM FROM ZIPFILE,LED(75)<1,GEN>,8 ELSE DLVR.TM = ''
             IF DLVR.TM # '' THEN DLV.TIME = 1
          END

          IF DLV.TIME THEN
          *** If delivery time is defined, instead of displaying warehouse
          *** info in the acknowledgement printout, display delivery time
             DLV.STATUS = 'Delivery Time'
             DLV.TIME   = OCONV(DLVR.TM,'MTH')
          END ELSE
             SHIP.BR    = LED(2)<1,GEN,2>
             DLV.STATUS = 'Warehouse'

             IF XFER.FLAG THEN
                DLV.TIME = 'From: ':SHIP.BR:' - To: ':LED(2)<1,GEN+1,2>
             END ELSE
                DLV.TIME = 'Shp: ':SHIP.BR:' - Prc: ':PRC.BR
             END
          END

          UT.REP.STR RESP,'&DLV.STATUS&',DLV.STATUS
          UT.REP.STR RESP,'&DLV.TIME&'  ,DLV.TIME

          RETURN
*-------------------------------------------------------------------------*
GET.STAT.DESC: *** Get Eclipse standard desc of status to display in email

          OE.STATUS.CONV OID,GEN,LED(6)<1,GEN>,STAT.DESC
          P.POS = INDEX(STAT.DESC,'Prt',1)
          IF P.POS THEN
             STAT.DESC = STAT.DESC[1,P.POS - 1]
          END

          RETURN
*-------------------------------------------------------------------------*
SET.LINES: *** Set up each line item on gen to display

          INS.POS   = 0
          UT.REP.STR RESP,'&SHP.QTY.RESP&',SHP.QTY.RESP
          UT.REP.STR RESP,'&SHP.QTY.HEADER&',SHP.QTY.HEADER
          UT.REP.STR RESP,'&ORD.COLSPAN&',ORD.COLSPAN
          START.VAR = '&PN.LOOP.BEG&'
          END.VAR   = '&PN.LOOP.END&'
          WOE.GET.LOOP.RESP START.VAR,END.VAR,RESP,LOOP.RESP,INS.POS

          SHP.BR     = LED(2)<1,GEN,2>

          IF LED(8)<1,GEN> = '' OR PRT.ALL.GENS THEN
             *** Get the open and GEN LDIDs, we will combine them
             OPN.LDIDS     = RAISE(LED(49))
             GEN.LDIDS     = RAISE(RAISE(LED(48)<1,GEN>))
             LDIDS         = ''

             *** Loop over the open LDIDs, adding each one to the list to
             *** print if it is either on this GEN or if it is comment.
             OPN.LDID.CT = DCOUNT(OPN.LDIDS,AM)
             FOR LDN = 1 TO OPN.LDID.CT
                LDID = OPN.LDIDS<LDN>
                LD.GET LDID

                IF LD(1) = 'C' OR LD(1) = 'S' THEN
                   *** Comment line or Subtotal.
                   LDIDS<-1> = LDID
                END ELSE
                   *** Not a comment, see if it's on this gen
                   IF PRT.ALL.GENS THEN
                      GEN.CT = DCOUNT(LED(1)<1>,VM)
                      *** Loop through each gen to get correct LDIDS
                      FOR GX = 1 TO GEN.CT
                         GEN.LDIDS = RAISE(RAISE(LED(48)<1,GX>))
                         GSTAT     = LED(6)<1,GX>
                         LOCATE LDID IN GEN.LDIDS SETTING GPOS ELSE GPOS=''
                         *** Add ldid unless it is a direct or cancelled
                         IF GSTAT # 'X' AND GSTAT # 'Y' AND GSTAT#'B' THEN
                            LOCATE LDID IN LDIDS SETTING LPOS ELSE
                               *** Add LDID if another gen hasn't already
                               LDIDS<-1> = LDID
                            END
                         END
                      NEXT GX
                   END ELSE
                      *** It's on this gen, or we should print all gens.
                      LOCATE LDID IN GEN.LDIDS SETTING GPOS ELSE GPOS = ''
                      IF GPOS THEN
                         LDIDS<-1> = LDID
                      END
                   END
                END
             NEXT LDN
          END ELSE
             * Invoice; the comment LDIDs are already in LED(48), in order
             LDIDS = RAISE(RAISE(LED(48)<1,GEN>))
          END

          *** Check for pricing above subtotals
          NO.PRICING = ''
          LAST.SUBT.POS = 1
          LD.CT = DCOUNT(LDIDS,AM)
          FOR LDN = 1 TO LD.CT
             LDID  = LDIDS<LDN>
             LD.GET LDID
             IF LD(1) = 'S' THEN
                IF LD(21) = '' THEN
                   *** No Pricing
                   FOR DL = LAST.SUBT.POS TO LDN
                      NO.PRICING<DL> = YES
                   NEXT DL
                END
                LAST.SUBT.POS = LDN+1
             END
          NEXT LDN

          *** Loop through each line item on gen to find description, qty,
          *** price, and extended price to display in email
          SHOW.TOTS  = NO ;* Initializes/default to not show totals.
          RUN.SUBTOT = 0.00
          RUN.TOT    = 0.00
          LDID.CT    = DCOUNT(LDIDS,AM)
          FOR LDN = 1 TO LDID.CT
             LDID = LDIDS<LDN>
             LD.GET LDID
             PN  = LD(1)

             *** If this is the First Print, get sum for all gens, if not,
             *** sum for the gen user specified
             BEGIN CASE
             CASE PRT.ALL.GENS
                LOT.FLAG = NO
                ORD.QTY = 0; SHP.QTY = 0
                GEN.CT = DCOUNT(LED(1)<1>,VM)
                FOR GX = 1 TO GEN.CT
                   GSTAT  = LED(6)<1,GX>
                   IF GSTAT # 'X' AND GSTAT # 'Y' AND GSTAT # 'B' THEN
                      SHP.QTY += (SUM(LD(5)<1,GX>)+SUM(LD(6)<1,GX>))*QSIGN
                   END
                   *** Set gen-specific lot flag and lot gen to be used
                   *** by OBE.GET.HTML.LOT.DESC. This is necessary so that
                   *** lot items can print along with non-lot items on the
                   *** same order with the Print All Gens option.
                   LOCATE LDID IN LED(48)<1,GX> SETTING FOUND THEN
                      IF LED(98)<1,GX> THEN
                         LOT.FLAG = YES
                      END
                      LD.GEN   = GX
                   END
                NEXT GX
                ORD.QTY = SHP.QTY ;* all open gens are accounted for.
             CASE STATUS = 'B'
                *** No Shipped qty on a bid.
                ORD.QTY = (SUM(LD(5)<1,GEN>)+SUM(LD(6)<1,GEN>)) * QSIGN
                SHP.QTY = ''
             CASE OTHERWISE
                ORD.QTY = 0
                GEN.CT = DCOUNT(LED(1)<1>,VM)
                FOR GX = 1 TO GEN.CT
                   GSTAT  = LED(6)<1,GX>
                   IF GSTAT # 'X' AND GSTAT # 'Y' AND GSTAT # 'B' THEN
                      ORD.QTY += (SUM(LD(5)<1,GX>)+SUM(LD(6)<1,GX>))*QSIGN
                   END
                NEXT GX
                SHP.QTY = (SUM(LD(5)<1,GEN>)+ SUM(LD(6)<1,GEN>)) * QSIGN
             END CASE

             *** Lot item pricing product can only have a quantity of 1.
             IF LOT.FLAG THEN
                ORD.QTY = 1
                IF STATUS # 'B' THEN
                   SHP.QTY = 1
                END
             END

             * Include Job Management Items
             LOT.JOB = (PN[1,2] = "L#")

             IF ORD.QTY + 0 = 0 AND (NUM(PN) OR LOT.JOB) THEN CONTINUE

             PRC.RESP = ''; PRC.HEADER = ''

             **In case this is nver set
             PSTYLE.COL.CT = 2

             IF NUM(PN) OR LOT.JOB THEN
                GET.ALL.PRD SHP.BR,PN,QSIGN
                IF PRD(3) = 9 THEN LOT.FLAG = YES ELSE LOT.FLAG = NO
                IF NOT(LOT.FLAG) THEN
                   *** Use LD.GEN to get the correct pricing when the
                   *** Print All Gens flag is active
                   HTML.GET.PSTYLE OID,LD.GEN,ORD.STAT,PRC.RESP,PRC.HEADER,ALT.DESC,PSTYLE.COL.CT,SHOW.TOTS,COL.SUB.TOT,PSTYLE.OVRD,PRT.ALL.GENS
                END ELSE
                   OE.LOT.GET.XCURR ,,,,GEN,,LXRT
                   *** Use LD.GEN to get the correct pricing when the
                   *** Print All Gens flag is active
                   FORMS.GET.LOT.PRC FORM.TYPE,LDID,LD.GEN,PRT.ALL.GENS,LOT.PRC
                   PRC.RESP  = '<td colspan=2 align="right" valign="top">':LOT.PRC "R2#11":'</td>'
                   PRC.HEADER    = '<td colspan=2 align="center" bgcolor="':HDRCLR:'"><small>Net Price</small></td>'
                   PSTYLE.COL.CT = 2
                   ALT.DESC      = NO
                   SHOW.TOTS     = YES
                   COL.SUB.TOT   = LOT.PRC
                END

                * Need this hack here to fix a bug which caused this
                * program to halt execution if the COL.SUB.TOT was null
                * It was tracked to the ICONV (HHN202)
                COL.SUB.TOT += 0

                RUN.SUBTOT += ICONV(COL.SUB.TOT,'MR9')
                RUN.TOT += ICONV(COL.SUB.TOT,'MR9')

                IF PSTYLE.COL.CT < 2 THEN PSTYLE.COL.CT = 2
                NOTES.COLSPAN = (PSTYLE.COL.CT - 2) + 3
                IF NO.PRICING<LDN> THEN
                  *** Dont show price above subtotal.
                  PRC.RESP = '<td colspan="':PSTYLE.COL.CT:'" align="right">&nbsp;</td>'
                END

                IF NOT(LOT.FLAG) THEN
                   *** Regular product description.
                   OE.DESC.GET DESC,ALT.DESC,'SOE Printing'
                END ELSE
                   *** Lot billing product description.
                   DESC = LD(3)
                END

                *** Check whether the product is flagged for Serial Number
                *** Tracking at the Shipping Branch...
                PRD.BR.GET.VAL SHP.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>
                      END
                   NEXT SN
                END

                *** Get the decription
                BEGIN CASE
                CASE LOT.FLAG
                   GOSUB GET.LOT.ITEM.DESC
                CASE LD(31) AND LD(38)<1,2> = '1' AND CUS(74) # 'No'
                   *** This product is a kit and is set to print each comp.
                   DESC := '<br>'
                   KCMPS = LD(31)
                   KQTYS = LD(30)
                   KCMTS = LD(37)
                   GET.KIT.COMPS.LOC KCMPS,KQTYS,KCMTS,45,DESC,PRC.BR,GEN
                   DESC.CT = DCOUNT(DESC,VM)
                   FOR DESC.LN = 1 TO DESC.CT
                      DESC<1,DESC.LN> = TRIM(DESC<1,DESC.LN>,' ','B')
                   NEXT DESC.LN
                   UT.REP.STR DESC,VM,'<br>'
                   UT.REP.STR DESC,' ','&nbsp;'
                CASE OTHERWISE
                   UT.REP.STR DESC,VM,'<br>'
                END CASE

                UOM = LD(23)
                IQ.TO.ALPHA PLNE(3),PRD(7),UOM,ORD.QTY,,,,,ORD.ALPHA
                IQ.TO.ALPHA PLNE(3),PRD(7),UOM,SHP.QTY,,,,,SHP.ALPHA
                DFLT.PER.GET 'S',SQTY,SUOM

                *** Temp gen value, used to define the gen when printing
                *** all gens in the first Print
                PRT.GEN = GEN

                *** If this is the First Print, gen the correct gen that
                *** the LDID corresponds to in order to get the correct
                *** BO.DATE and AVAIL.QTY
                IF PRT.ALL.GENS THEN
                   FIND LDID IN LED(48) SETTING FMC,VMC THEN
                      PRT.GEN = VMC
                   END
                END

                *** Check for Available qty
                OE.CHECK.AVAIL.NOW OID,PRT.GEN,LDID,AVAIL.QTY

                *** Check to see when the back order qty will be available
                *** and set BO.DATE
                *** If BO.STATUS = 'X' then show **** for bo date
                BO.DATE   = ''
                OE.CHECK.AVAIL OID,PRT.GEN,LDID,BO.DATE
                BO.DATE   = OCONV(BO.DATE,'D2/')
                BO.STATUS = CUSS(43)
                IF BO.STATUS = '' THEN BO.STATUS = CUS(43)
                IF BO.STATUS = 'X' THEN BO.DATE = STR('*',8)
                IF AVAIL.QTY > ORD.QTY THEN
                   AVAIL.QTY = ORD.QTY
                   BO.DATE   = STR('*',8)
                END
                CMT = '' ;* Comment taken care of by OE.DESC.GET
             END ELSE
                *** PN is not a number, usually a comment.
                OE.DESC.GET CMT,YES,'SOE Printing'
                IF CMT = '' THEN CONTINUE
                UT.REP.STR CMT,VM,'<br>'
                DESC      = ''
                ORD.ALPHA = ''
                SHP.ALPHA = ''
                AVAIL.QTY = ''
                BO.DATE   = ''
                PRC.RESP  = ''
                *** We need to get PSTYLE set if this is the first line
                IF LDN = 1 THEN
                   TLDN = LDN
                   *** Loop until we find a line with a real product on it
                   *** We may not find one, in which case the PSTYLE is
                   *** unnecessary; this email only contains line comments
                   LOOP WHILE NOT(NUM(PN)) AND NOT(LOT.JOB) UNTIL LDN = LDID.CT
                      TLDN += 1
                      LDID = LDIDS<TLDN>
                      LD.GET LDID
                      PN  = LD(1)
                   REPEAT
                   GET.ALL.PRD SHP.BR,PN,QSIGN
                   *** Use LD.GEN to get the correct pricing when the
                   *** Print All Gens flag is active
                   HTML.GET.PSTYLE OID,LD.GEN,ORD.STAT,,PRC.HEADER,ALT.DESC,PSTYLE.COL.CT,SHOW.TOTS,COL.SUB.TOT,PSTYLE.OVRD,PRT.ALL.GENS
                   IF PSTYLE.COL.CT < 2 THEN PSTYLE.COL.CT = 2
                   NOTES.COLSPAN = (PSTYLE.COL.CT - 2) + 3
                END
             END

             IF STATUS = "I" OR STATUS = "B" THEN
                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> = "<br>":LBL.DATA<LBL.NO>
                   NEXT LBL.NO
                END
             END
LD.CMNT:     *** Configure line item comment.
             UT.REP.STR CMT,SVM,'<br>'
             *** Prepend a line break if this line isn't comment-only line
             IF DESC THEN CMT = '<br>':CMT
             *** Replace space with nonbreak spaces so that indents and
             *** other funny formatting will be replicated correctly
             UT.REP.STR CMT,' ','&nbsp;'
             * If this is a direct, then their is no BO possible. so
             * don't show a bo.date
             IF LED(33)<1,GEN> THEN BO.DATE = STR('*',8)

             *** Fix empty entries so HTML is valid; no empty table cells
             IF NOT(ORD.ALPHA) THEN ORD.ALPHA = '&nbsp;'
             IF NOT(SHP.ALPHA) THEN SHP.ALPHA = '&nbsp;'
             IF NOT(AVAIL.QTY) THEN AVAIL.QTY = '&nbsp;'
             IF NOT(BO.DATE)   THEN BO.DATE   = '&nbsp;'
             IF NOT(PRC.RESP)  THEN
                IF PN = 'S' THEN ;*** Check to see if this is a subtotal.
                   IF LD(43) = 'Top of Order' THEN
                      *** Show subtotal since first line item.
                      PRINT.SUBTOT = OCONV(RUN.TOT,'MR9') "R2#12"
                   END ELSE
                      *** Show subtotal since last subtotal.
                      PRINT.SUBTOT = OCONV(RUN.SUBTOT,'MR9') "R2#12"
                   END
                   PRC.RESP = '<td colspan="':PSTYLE.COL.CT:'" align="right">-----------<br>':PRINT.SUBTOT:'</td>'
                   RUN.SUBTOT = 0.00 ;* Reset the running subtotal.
                END ELSE
                   PRC.RESP = '<td colspan="':PSTYLE.COL.CT:'" align="right">&nbsp;</td>'
                END
             END

             ** If showing qts over all gens don't show BO or avail
             IF PRT.ALL.GENS THEN
                AVAIL.QTY = '&nbsp;'
                BO.DATE   = '&nbsp;'
             END

             NEW.RESP = LOOP.RESP
             IF SHP.QTY = '' THEN SHP.QTY = '&nbsp;'
             UT.REP.STR NEW.RESP,'&ORD.QTY&' ,ORD.ALPHA  ;* Order Qty/UOM
             UT.REP.STR NEW.RESP,'&SHP.QTY&' ,SHP.ALPHA  ;* Ship Qty/UOM
             UT.REP.STR NEW.RESP,'&AVL&'     ,AVAIL.QTY  ;* Avail
             UT.REP.STR NEW.RESP,'&BO.DATE&' ,BO.DATE    ;* Back Order Date
             UT.REP.STR NEW.RESP,'&DESC&'    ,DESC       ;* Product Desc
             UT.REP.STR NEW.RESP,'&PRC.RESP&',PRC.RESP   ;* Formt'd Extnded
             UT.REP.STR NEW.RESP,'&CMT&'     ,CMT        ;* Line Item Cmnt
             UT.REP.STR RESP,'&PRC.HEADER&'  ,PRC.HEADER ;* Pricing header

             RESP     = INSERT(RESP,INS.POS;NEW.RESP)
             INS.POS += DCOUNT(NEW.RESP,AM)
          NEXT LDN

          UT.REP.STR RESP,'&HDRCLR&',HDRCLR             ;* header color.

          RETURN
*-------------------------------------------------------------------------*
GET.TRACKING.INFO: *** Gets the response for shipment tracking.

          TRK.MSG       = ''
          SVIA          = '' ;* Shipvia (UPS,RPS,USPS...)
          SVIAS.RTND    = '' ;* Shipvia codes returned.
          WEB.TRK.INFO  = '' ;* Tracking info URL.
          NOTE.TRK.INFO = '' ;* Tracking info if URL can't be used.

          *** Get the order tracking information.
          GET.SVIA.TRACKING OID,GEN,SVIA,SVIAS.RTND,WEB.TRK.INFO,NOTE.TRK.INFO

          IF SVIAS.RTND THEN
             TRK.MSG := 'Order #':OID:' has been shipped via ':SVIAS.RTND<1>:'.<br>'
          END

          TRK.CT = DCOUNT(SVIAS.RTND,VM)
          IF TRK.CT <= 0 THEN RETURN

          IF NOTE.TRK.INFO THEN
             IF TRK.CT > 1 THEN
                TRK.MSG := 'Your shipment tracking numbers are: '
             END ELSE
                TRK.MSG := 'Your shipment tracking number is: '
             END
             FOR X = 1 TO TRK.CT
                TRK.MSG := '<b>':NOTE.TRK.INFO<1,X>:'</b><br>'
             NEXT X
          END

          IF WEB.TRK.INFO THEN
             TRK.MSG := '<br><a href="':WEB.TRK.INFO<1,1>:'">':'Click here to track your packages.</a><br>'
          END

          RETURN
*-------------------------------------------------------------------------*
GET.LOT.ITEM.DESC: *** Get the description for lot billing item.

          *** Use LD.GEN instead of GEN because the lot description
          *** depends on the order status, which must be taken from the
          *** gen that the lot item is on (not the main gen if the Print
          *** All Gens option is in effect)
          LOT.DESC = ''
          OBE.GET.HTML.LOT.DESC OID,LD.GEN,LDID,MODE,STATUS,PRT.ALL.GENS,LOT.DESC
          DESC := LOT.DESC

          RETURN
*-------------------------------------------------------------------------*
SET.TOTALS: *** Set up order totals to display in document

          MATREAD AR FROM ARFILE,ORDNO ELSE MAT AR = ''
          DISC.DT  = AR(11)<1,1,1>
          DUE.DT   = AR(12)

          ** If first print flag is set, get totals for all gens
          IF PRT.ALL.GENS THEN
             SUB.TOL  = OCONV(RUN.TOT,'MR7')
             TOTAL    = OCONV(RUN.TOT,'MR7')
             FGHT     = 0
             HNDL     = 0
             TAX.TOL  = 0
             FET.AMT  = 0

             GEN.CT = DCOUNT(LED(1)<1>,VM)
             FOR GX = 1 TO GEN.CT
                *** Don't add if gen is invoiced, PO, or cancelled
                IF LED(8)<1,GX>+0 # 0 OR LED(6)<1,GX> = 'Y' OR LED(6)<1,GX> = 'X' OR LED(6)<1,GX> = 'B' THEN CONTINUE
                OE.ORDER.TOTAL OID,GX,QSIGN,TOTALX,SUB.TOLX,FGHTX,HNDLX,TAX.TOLX,FETX
*               TOTAL    += TOTALX
*               SUB.TOL  += SUB.TOLX
                FGHT     += FGHTX
                HNDL     += HNDLX
                TAX.TOL  += TAX.TOLX
                FET.AMT  += FETX
             NEXT GX
          END ELSE
             OE.ORDER.TOTAL OID,GEN,QSIGN,,,FGHT,HNDL,TAX.TOL,FET.AMT
             SUB.TOL  = OCONV(RUN.TOT,'MR7')
             TOTAL    = OCONV(RUN.TOT,'MR7')
          END

          * Any freight or handling an FET amount, show it in the totals.
          TOTAL    += FGHT + HNDL + TAX.TOL + FET.AMT

          IF PRT.ALL.GENS THEN
             AMT.PAID = 0
             DISC     = 0
             FOR GX = 1 TO GEN.CT
                GSTAT  = LED(6)<1,GX>
                IF GSTAT # 'X' AND GSTAT # 'Y' AND GSTAT # 'B' THEN
                   SOE.CALC.CASH OID,GX,,AMT.PAIDX,DISCX
                   AMT.PAID += AMT.PAIDX
                   DISC     += DISCX
                END
             NEXT GX
          END ELSE
             SOE.CALC.CASH OID,GEN,,AMT.PAID,DISC
          END

          *** If there is a negative total then show credit title desc.
          ORIG.DISC.TAKEN = 0
          IF STATUS = 'I' AND TOTAL < 0 THEN
             TYPE.DESC = 'Credit Memo'

             EMAIL.GET.ORIG.DISC OID,GEN,ORIG.DISC.TAKEN

             IF ORIG.DISC.TAKEN AND NOT(AMT.PAID)THEN
                SOE.CALC.DISC OID,GEN,RETURN.DISC
                TOTAL   += RETURN.DISC
                SUB.TOL += RETURN.DISC
                *** Show discount taken.
                DISC.AMT = OCONV(RETURN.DISC,"MR2")
                PRC.RESP = '<td colspan="':PSTYLE.COL.CT:'" align="right">'
                PRC.RESP := DISC.AMT
                PRC.RESP := '</td>'
                TOTAL.COMMENT = '<i>Original Discount Taken</i>'
                NEW.RESP = LOOP.RESP
                UT.REP.STR NEW.RESP,'&ORD.QTY&' ,'&nbsp;'
                UT.REP.STR NEW.RESP,'&SHP.QTY&' ,'&nbsp;'
                UT.REP.STR NEW.RESP,'&AVL&'     ,'&nbsp;'
                UT.REP.STR NEW.RESP,'&BO.DATE&' ,'&nbsp;'
                UT.REP.STR NEW.RESP,'&DESC&'    ,TOTAL.COMMENT
                UT.REP.STR NEW.RESP,'&CMT&'     ,'&nbsp;'
                UT.REP.STR NEW.RESP,'&PRC.RESP&',PRC.RESP
                RESP     = INSERT(RESP,INS.POS;NEW.RESP)
                INS.POS += DCOUNT(NEW.RESP,AM)
             END
          END

          *** If any amount of our Order was paid
          IF AMT.PAID THEN
             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 = AMT.PAID
                TOTAL    += TOTAL.AMT
                SUB.TOL  += TOTAL.AMT
                DISC.TAKEN = 0
                PRC.RESP = '<td colspan="':PSTYLE.COL.CT:'" align="right">'
                PRC.RESP := OCONV(TOTAL.AMT,'MR2')
                PRC.RESP := '</td>'
                NEW.RESP = LOOP.RESP
                UT.REP.STR NEW.RESP,'&ORD.QTY&' ,'&nbsp;'
                UT.REP.STR NEW.RESP,'&SHP.QTY&' ,'&nbsp;'
                UT.REP.STR NEW.RESP,'&AVL&'     ,'&nbsp;'
                UT.REP.STR NEW.RESP,'&BO.DATE&' ,'&nbsp;'
                UT.REP.STR NEW.RESP,'&DESC&'    ,TOTAL.COMMENT
                UT.REP.STR NEW.RESP,'&CMT&'     ,'&nbsp;'
                UT.REP.STR NEW.RESP,'&PRC.RESP&',PRC.RESP

                RESP     = INSERT(RESP,INS.POS;NEW.RESP)
                INS.POS += DCOUNT(NEW.RESP,AM)
             END ELSE
                SOE.PAYMENTS.DISC AR.ID,PAY.IDS,PAY.DTS,PAY.AMTS,DISC.TAKEN
                IF STATUS = 'I' AND TOTAL < 0 AND NOT(ORIG.DISC.TAKEN) THEN
                   DISC.TAKEN = 0
                END
                PCT = DCOUNT(PAY.IDS,VM)
                FOR PYN = 1 TO PCT
                   PAY.ID  = PAY.IDS<1,PYN>
                   PAY.DT  = PAY.DTS<1,PYN>
                   PAY.AMT = PAY.AMTS<1,PYN>

                   IF PAY.DT = DATE() THEN
                      TOTAL.COMMENT  = 'Amount paid today # ':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

                   IF PAY.AMT THEN
                      TOTAL   += PAY.AMT
                      SUB.TOL += PAY.AMT
                   END

                   *** Convert our Payment Amount before we add it to the
                   *** document
                   PAY.AMT = OCONV(PAY.AMT,"MR2")
                   PRC.RESP = '<td colspan="':PSTYLE.COL.CT:'" align="right">'
                   PRC.RESP := PAY.AMT
                   PRC.RESP := '</td>'

                   NEW.RESP = LOOP.RESP
                   UT.REP.STR NEW.RESP,'&ORD.QTY&' ,'&nbsp;'
                   UT.REP.STR NEW.RESP,'&SHP.QTY&' ,'&nbsp;'
                   UT.REP.STR NEW.RESP,'&AVL&'     ,'&nbsp;'
                   UT.REP.STR NEW.RESP,'&BO.DATE&' ,'&nbsp;'
                   UT.REP.STR NEW.RESP,'&DESC&'    ,TOTAL.COMMENT
                   UT.REP.STR NEW.RESP,'&CMT&'     ,'&nbsp;'
                   UT.REP.STR NEW.RESP,'&PRC.RESP&',PRC.RESP

                   RESP     = INSERT(RESP,INS.POS;NEW.RESP)
                   INS.POS += DCOUNT(NEW.RESP,AM)
                NEXT PYN
             END

             *** If there was actually a discount already taken
             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   += DISC.TAKEN ;* Take discount from total.
                SUB.TOL += DISC.TAKEN ;* Take discount from subtotal.
                DISC    -= DISC.TAKEN ;* Take discount from avail discount.

                *** Convert our Discount Taken Amount before we add it to
                *** the document
                DISC.TAKEN = OCONV(DISC.TAKEN,"MR2")
                PRC.RESP = '<td colspan="':PSTYLE.COL.CT:'" align="right">'
                PRC.RESP := DISC.TAKEN
                PRC.RESP := '</td>'

                NEW.RESP = LOOP.RESP
                UT.REP.STR NEW.RESP,'&ORD.QTY&' ,'&nbsp;'
                UT.REP.STR NEW.RESP,'&SHP.QTY&' ,'&nbsp;'
                UT.REP.STR NEW.RESP,'&AVL&'     ,'&nbsp;'
                UT.REP.STR NEW.RESP,'&BO.DATE&' ,'&nbsp;'
                UT.REP.STR NEW.RESP,'&DESC&'    ,TOTAL.COMMENT
                UT.REP.STR NEW.RESP,'&CMT&'     ,'&nbsp;'
                UT.REP.STR NEW.RESP,'&PRC.RESP&',PRC.RESP

                RESP     = INSERT(RESP,INS.POS;NEW.RESP)
                INS.POS += DCOUNT(NEW.RESP,AM)
             END
          END

          *** Get any Remote Order Entry discount.
          SOE.CALC.DISC OID,GEN,,,WOE.DISC
          TOTAL   += WOE.DISC
          SUB.TOL += WOE.DISC

          IF BASEC = "CAN$" THEN
             OE.TAX.CALC.AMTS OID,GEN,QSIGN,,,,,,GST.AMT,PST.AMT
             GST.AMT = OCONV(GST.AMT,'MR2')
             PST.AMT = OCONV(PST.AMT,'MR2')
          END

          ** Don't display tax on bids
          IF STATUS = 'B' THEN
             IF BASEC = "CAN$" THEN
                TOTAL  -= OCONV((GST.AMT*100),"MR2")
                TOTAL  -= (PST.AMT*100)
                TOTAL  -= FET.AMT
                GST.AMT = '*****'
                PST.AMT = '*****'
             END ELSE
                TOTAL  -= TAX.TOL
                TOTAL  -= FET.AMT
                TAX.TOL = '*****'
             END
             FET.AMT = 0 ;* Set to 0 so it doesn't show up.
          END

          *** Format all totals to be printed.
          O.FET.AMT = ''
          IF SHOW.TOTS THEN
             O.SUB.TOL = OCONV(SUB.TOL ,'MR2')
             IF BASEC = "CAN$" THEN
                GST.TAX.TOL = OCONV(GST.AMT*100,'MR2')
                PST.TAX.TOL = OCONV(PST.AMT*100,'MR2')
             END ELSE
                O.TAX.TOL   = OCONV(TAX.TOL ,'MR2')
             END
             O.FGHT     = OCONV(FGHT    ,'MR2')
             O.HNDL     = OCONV(HNDL    ,'MR2')
             O.DISC     = OCONV(DISC    ,'MR2')
             O.WOE.DISC = OCONV(WOE.DISC,'MR2')
             IF FET.AMT # 0 THEN
                O.FET.AMT  = OCONV(FET.AMT ,'MR2')
             END
             O.TOTAL    = OCONV(TOTAL   ,'MR2')
          END ELSE
             O.SUB.TOL  = '*****'
             IF BASEC = "CAN$" THEN
                GST.TAX.TOL  = '*****'
                PST.TAX.TOL  = '*****'
             END ELSE
                O.TAX.TOL    = '*****'
             END
             O.FGHT     = '*****'
             O.HNDL     = '*****'
             O.DISC     = '*****'
             O.WOE.DISC = '*****'
             O.TOTAL    = '*****'
             IF O.FET.AMT THEN
                O.FET.AMT  = '*****'
             END
          END
          IF O.FET.AMT AND STATUS # 'B' THEN
             *** If there is FET tax, show it in the totals.
             TAX.DESC := '<tr><td><b>F.E.T.</b></td>'
             TAX.DESC := '<td align="RIGHT"><b>':O.FET.AMT:'</b></td></tr>'
          END

          *** Set up the message for discounts other than WOE that can be
          *** taken if paid by DISC.DT.
          IF STATUS = 'I' AND NOT(O.TOTAL < 0) THEN
             IF DISC < 0 THEN
                *** If a discount is available print it.
                DISC = DISC * -1
                DISC = OCONV(DISC,'MR2')

                IF US.FUNDS THEN
                   DISC = DISC/OCONV(US.FUNDS,'MR4') "MR2"
                END

                PRT.DATE  = OCONV(DISC.DT,'D2/')
                DISC.MSG  ='<br><b>If paid by ':PRT.DATE:' you may deduct $':DISC
                DISC.MSG := '<br>Invoice is due by ':OCONV(DUE.DT,"D2/")
                DISC.MSG := ' net of any cash discount.</b><br>'
             END ELSE
                DISC.MSG = '<br><b>Invoice is due by ':OCONV(DUE.DT,"D2/"):'.</b><br>'
             END
          END ELSE
             DISC.MSG = ''
          END

          UT.REP.STR RESP,'&SUBTOL&'   ,O.SUB.TOL  ;* Subtotal
          UT.REP.STR RESP,'&TAX.DESC&' ,TAX.DESC
          IF BASEC = "CAN$" THEN
             UT.REP.STR RESP,'&GST.TAX&'  ,GST.TAX.TOL  ;* Gst Tax
             UT.REP.STR RESP,'&PST.TAX&'  ,PST.TAX.TOL  ;* Pst Tax
          END ELSE
             UT.REP.STR RESP,'&TAX&'      ,O.TAX.TOL  ;* Tax
          END
          UT.REP.STR RESP,'&FGHT&'     ,O.FGHT     ;* Freight
          UT.REP.STR RESP,'&HNDL&'     ,O.HNDL     ;* Handling
          UT.REP.STR RESP,'&WOE.DISC&' ,O.WOE.DISC ;* WOE Discounts
          UT.REP.STR RESP,'&TOTAL&'    ,O.TOTAL    ;* Total Amount
          UT.REP.STR RESP,'&DISC.MSG&' ,DISC.MSG   ;* Discount Message
          UT.REP.STR RESP,'&TYPE.DESC&',TYPE.DESC  ;* Doc type Desc
          *** Colspan for the box to the left of totals.
          UT.REP.STR RESP,'&NOTES.COLSPAN&',NOTES.COLSPAN

          OE.LOG.PRINT OID,GEN,DOC.TP:VM:1,TYPE.DESC:' E-mail',REPRINT

          *** Convert all AM to line feeds in resp
          CONVERT AM TO CHAR(10) IN RESP

          RETURN
!TSMITH~08/03/12~00:58
