          SUBROUTINE (VALUE,OID,GEN,LDID,QSIGN,ADDL,USE.COMM)
** Version# 10.0002 - 01/06/2016 - 04:53pm - TSMITH - eclipse
*** V10.0002 Change - Custom Coding 6 - 01/06/2016 - TSMITH - eclipse
** Copied from BP OE.VE.DISP.MARGIN Version# 10 - 04/01/2009 - 09:57am - EILEENM - main

*** SUBROUNINE - OE.VE.DISP.MARGIN
*-------------------------------------------------------------------------*
*** This is a OE View Element display subroutine.  It's entire purpose is
*** to return the margin.
*-------------------------------------------------------------------------*
*** VALUE    - The margin                                            [OUT]
*** OID      - The order id                                           [IN]
*** GEN      - The gen to display                                     [IN]
*** LDID     - The line item detail id                                [IN]
*** QSIGN    - The qsign for this order and gen                       [IN]
*** ADDL     - This is an array of values additional values that      [IN]
***          - can be used to display line items.
***          - To find the structure of this parameter,
***          - see CC OE.VE.DISP.EQUATES.
*** USE.COMM - Boolean, if this is true then the margin will be       [IN]
***          - calulated using the commision rather than the cost.
*-------------------------------------------------------------------------*
*** Common Variables - LED, LD, and the product variables if LD(1) is
***                    a product number.
*-------------------------------------------------------------------------*
          $INCLUDE CC OE.VE.DISP.EQUATES

          PN       = LD(1)
          MODE     = OID[1,1]
          XRATE    = ADDL<XRATE%>
          PER      = ADDL<PRICE.PER%>
          PRC.GEN  = ADDL<PRICE.GEN%>
          PRC.KEY  = ADDL<PRICE.KEY%>
          VALUE    = ''

          * check to see if there is an exchange rate set up for this
          * gen... if there is then we need to use that exchange rate
          * when setting up the unit price.
          IF LED(92)<1,PRC.GEN,2> THEN
             XRATE = OCONV(LED(92)<1,PRC.GEN,2>,'MR4')
          END ELSE
             XRATE = 1
          END

          OE.CHECK.PRC.RESTRICT OID,GEN,LDID,CHG.PRC.OK
          IF NOT(PRC.KEY) OR NOT(CHG.PRC.OK) THEN
             VALUE<4> = '%76'
          END
          IF PRD(3) = 3 THEN
             VALUE<4> = '%81'
          END

          OE.VE.GET.LOT.INFO LDID,LOT.ITEM,LOT.XRATE,TBILL,TPAID

          IS.PNS = (NOT(NUM(PN)) AND PN # 'S')
          NEW.LOT.PN = PN[1,2] = 'L#'
          IF IS.PNS AND NOT(NEW.LOT.PN) THEN
             * If this isn't a product or a sub-total, there is no margin
             VALUE<4> = '%82'
             RETURN
          END

          BEGIN CASE

          * Old Lot Item Logic
          CASE LOT.ITEM AND LED(8)<1,GEN> = ""
             UNT.CST = OCONV(LD(67)<1,2>/LOT.XRATE,'MR9') - TPAID
             UNT.PRC = OCONV(LD(67)<1,1>/LOT.XRATE,'MR9') - TBILL

          * New Job Managment Logic
          CASE NEW.LOT.PN
             UNT.PRC = OCONV(LD(8)<1,PRC.GEN>*PER / XRATE,'MR9')
             IF USE.COMM THEN
                UNT.CST = OCONV(LD(27)<1,PRC.GEN>*PER / XRATE,'MR9')
             END ELSE
                UNT.CST = OCONV(LD(10)<1,PRC.GEN>*PER / XRATE,'MR9')
             END



          * All others
          CASE OTHERWISE
             UNT.PRC = OCONV(LD(8)<1,PRC.GEN>*PER / XRATE,'MR9')
             BEGIN CASE
             CASE USE.COMM
                UNT.CST = OCONV(LD(27)<1,PRC.GEN>*PER / XRATE,'MR9')
             CASE PRD(3) = 3
                UNT.CST = ''
             CASE OTHERWISE
                UNT.CST = OCONV(LD(10)<1,PRC.GEN>*PER / XRATE,'MR9')
             END CASE

             IF PN = 'S' THEN
                UNT.CST = UNT.CST * QSIGN
                UNT.PRC = UNT.PRC * QSIGN
             END

          END CASE


          IF TRIM(UNT.PRC)+0#0 THEN
             VALUE<1> = ((UNT.PRC - UNT.CST) / UNT.PRC * 100)
          END ELSE
             VALUE<1> = 0
          END

          * Disallow editing any cost/price info for Chg Ord tag items.
          BEGIN CASE
          CASE LED(129)<1,2> AND LD(108)<1,1>
             VALUE<4> = '%278'
          CASE LD(67)<1,3>
             VALUE<4> = '%139'
          CASE LOT.ITEM AND LED(8)<1,GEN> = ''
             VALUE<4> = '%138'
          END CASE

          * On Transfers check users price branch authorization.
          IF MODE = 'T' THEN
             LOCATE LED(2)<1,PRC.GEN,1> IN SECURITY<9> SETTING XX ELSE
                UT.GET.PROMPT '%96':AM:LED(2)<1,PRC.GEN,1>,AUTH.MSG
                VALUE<4> = AUTH.MSG
             END
          END

          RETURN
*-------------------------------------------------------------------------*
!TSMITH~01/06/16~16:53
