          SUBROUTINE (OID,GEN,LDID,LBL.NO,TOL.QTY,UDATA)
** Version# 9.0105[148] - 06/15/2011 - 03:23pm - SMITJR - eclipse
*** V9.0105 Change - Custom Coding .. - 06/15/2011 - SMITJR - eclipse
** Copied from CBP EXCEL.STANDARD.CPN.KEY Version# 9.0107[7] - 06/10/2011 - 10:05am - SMITJR - eclipse
** Copied from BP LABEL.MSEXCEL.EXPORT Version# 9.01 - 05/16/2007 - 06:31pm - BABS - r8.0base
*** V9.01 Change - No Develop Ver Yet HHM635 - 05/16/2007 - BABS - r8.0base
*** Subroutine - LABEL.MSEXCEL.EXPORT
*-------------------------------------------------------------------------*
*** This routine creates an excel spreadsheet from the current generation
*** of an order
*-------------------------------------------------------------------------*
*** OID      - Order ID                                            [IN]
*** GEN      - Generation                                          [IN]
*** LDID     - Not Used
*** LBL.NO   - Not Used
*** TOL.QTY  - Total quantity shipped of last item (not useful)    (OUT)
*** UDATA    - Not Used
*-------------------------------------------------------------------------*
*** LED, LD, and PRD are self-contained in this routine. They do not need
*** to be current
*-------------------------------------------------------------------------*

          MODE = OID[1,1]
          IF MODE # 'S' THEN RETURN
          MATREAD LED FROM LEDFILE,OID ELSE MAT LED = ''
          OE.GET.QSIGN QSIGN,OID,GEN

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

          TB = CHAR(9)
          DATA = ''

          DATA<-1> = 'Order #':TB:OID
          DATA<-1> = 'ShipDate':TB:OCONV(LED(9)<1,GEN>,'D4/')
          DATA<-1> = ' '
          DATA<-1> = 'Ship-To':TB:CUSS(1) "L#35"
          DATA<-1> = TB:LED(78)<1,1,1> "L#35"
          DATA<-1> = TB:LED(78)<1,1,2> "L#35"
          DATA<-1> = TB:LED(78)<1,1,3> "L#27":'  ':LED(75)<1,1>
          DATA<-1> = ' '

          ALT.CN = CUSS(66)

          DATA<-1> = 'Description':TB:'Qty Ordered':TB:'Per U/M':TB:'Sell Price':TB:'Ext Sell'

          MATBUILD SV.LD FROM LD

             OE.GET.LDID.LIST LDID.LIST,OID,GEN
          LDID.CT = DCOUNT(LDID.LIST,VM)
          FOR LDID.CTR = 1 TO LDID.CT
             LDID = LDID.LIST<1,LDID.CTR>
             LD.GET LDID

             GET.ALL.PRD BR,LD(1),QSIGN,GROUP
             PN      = LD(1)

             *IF SUM(LD(5)<1,GEN>)+SUM(LD(6)<1,GEN>) = 0 THEN GOTO SKIP.LD

             * Use the Customer Part Number entered in OE.
             * If one was not entered in OE, check for one defined in
             * Customer Maint.
             CPN = LD(43)<1,1>          ;* Cust PN entered in OE
             IF CPN = '' THEN
                OE.CUS.PN.CMT.GET.ALL BT.CN,ST.CN,ALT.CN,PN,CPNS,LOCS,CMTS
                CPN = CPNS<1>
             END

             PRC.LINE = PRD(9)                      ;* Price Line
             PRD.SEL = PRD(19)                  ;* Product Sell Group

*** Calculate Availability
             OE.CHECK.AVAIL.ALL OID,LDID,EDATE
             IF EDATE <= DATE() AND EDATE#'' THEN
                OE.AVAIL.GET OID,GEN,PN,AVAIL,,,LD(31),LD(30),LD(39)
             END ELSE
                AVAIL = OCONV(EDATE,'D4/')
             END

             PER.UM = OCONV(LD(23)<1,1>,'MCL')
             UOM.PER.GET PER.UM,PER                 ;* Per Unit of Measure

             ** Set up the weight and format allowing up to 9 digits of
             ** precision based on control record PROD.WGHT.PREC
             IF PER=1 THEN PERLEN=0 ELSE
                PERLEN=LEN(PER); IF PERLEN>9 THEN PERLEN=9
             END

             WCONV  = 'R':PRD.WGHT$ - PERLEN
             WFORM  =  WCONV:'#15'

             IF PERLEN>4 THEN PERLEN = 4
             LCONV = 'R':4 - PERLEN
             LFORM = LCONV:'#9'

             CONV.FMT = 'MR':PRD.WGHT$
             WGHT = OCONV(PRD(10),CONV.FMT)*PER
             WGHT = TRIM(WGHT) WFORM:' LBS/':PER.UM

             IF LED(92)<1,GEN,2> THEN
                XRATE = OCONV(LED(92)<1,GEN,2>,'MR4')
             END ELSE
                XRATE = 1
             END

             IF PN = 'C' THEN
             DESC=RAISE(LD(3))
             END ELSE
             DESC=PRD(1)
             END
             CONVERT VM TO ' ' IN DESC
             TOL.QTY = LD(4)<1,GEN>/PER * QSIGN
*             TOL.QTY = (SUM(LD(5)<1,GEN>)+SUM(LD(6)<1,GEN>))/PER * QSIGN
             COGS    = OCONV((LD(10)<1,GEN>+0)*PER / XRATE,'MR9') "R9#15"
             SEL.PRC = OCONV((LD(8)<1,GEN>+0)*PER / XRATE,'MR9')  "R9#15"

    ** Calculate GP%
             IF (LD(8)<1,GEN>+0) = 0 THEN GP = 0 ELSE
                GP=ICONV(((LD(8)<1,GEN>-LD(10)<1,GEN>)/LD(8)<1,GEN>)*100,'MR1')
                GP=OCONV(GP,'MR1')
             END
             PRD.BR.GET.VAL BR,PN,20,PACK.QTY

    ** Calculate Date Last Purchased
             PN.FOUND = NO
             LAST.DT = ''
             TOID  = ''
             TMODE = ''
             INVN  = ''
             TGEN  = ''
             ROOT = PN:'~':BR:'~z'
             MATBUILD SV.LED FROM LED
             GOSUB LAST.PUR
             MATPARSE LED FROM SV.LED

             IF LAST.DT # '' THEN
                LAST.DATE = OCONV(LAST.DT,'D4/')
             END ELSE
                LAST.DATE = '** N/A **'
             END

             EXT = TOL.QTY*SEL.PRC
             *EXT = '$':EXT
             SEL.PRC = SEL.PRC
             COGS = '$':COGS
             KEY1 = FIELD(TRANS('PRODUCT',PN,4,'X'),' ',1)

             IF EXT = 0 THEN EXT = ''
             IF SEL.PRC = 0 THEN SEL.PRC = ''
             IF TOL.QTY = 0 THEN TOL.QTY = ''

             TDATA  = DESC:TB:TOL.QTY:TB:PER.UM:TB:SEL.PRC:TB:EXT
             DATA<-1> = TDATA

SKIP.LD:  NEXT LDID

          MATPARSE LD FROM SV.LD

          DCT = DCOUNT(DATA,AM)
          FOR J = 1 TO DCT
          PRINT DATA<J>
          NEXT J

   ***    DDE.MSEXCEL.EXPORT DATA

FINISH:   RETURN
*-------------------------------------------------------------------------*
LAST.PUR: ** Get Last Purchase Date
          LOOP
          BSCAN ID FROM PSUBFILE,ROOT USING '&INDEX&' BY 'D' ELSE EXIT
          ROOT = ''
          IF FIELD(ID,'~',1)#PN OR FIELD(ID,'~',2)#BR THEN EXIT
          TPN   = ''
          TPN   = FIELD(ID,'~',1)
          IF TPN = PN THEN
             PN.FOUND = YES
             TOID  = FIELD(ID,'~',4)
             TMODE = TOID[1,1]
             IF TMODE = 'P' THEN
                MATREAD LED FROM LEDFILE,TOID ELSE MAT LED = ''
                INVN = FIELD(ID,'~',5)
                LOCATE INVN IN LED(8)<1> SETTING TGEN ELSE TGEN = 1
                LAST.DT = LED(9)<1,TGEN>
             END

             IF LAST.DT # '' THEN EXIT
          END ELSE
             IF PN.FOUND THEN EXIT
          END
          REPEAT

          RETURN
*-------------------------------------------------------------------------*
!SMITJR~06/15/11~15:23
