Tuesday, 13 January 2015

Query to find price discounts and surcharges on order lines :

SELECT   h.order_number,
           l.line_number,
           pa.list_line_type_code,
           pa.arithmetic_operator,
           pa.operand,
           DECODE (
              PA.MODIFIER_LEVEL_CODE,
              'ORDER',
                L.UNIT_LIST_PRICE
              * L.ORDERED_QUANTITY
              * PA.OPERAND
              * SIGN (PA.ADJUSTED_AMOUNT)
              / 100,
              (PA.ADJUSTED_AMOUNT * NVL (L.ORDERED_QUANTITY, 0))
           )
              DISCOUNT_AMT
    FROM   qp_list_headers_vl lh,
           oe_price_adjustments pa,
           oe_order_lines_all l,
           oe_order_headers_all h
   WHERE       h.order_number = 14463
           AND h.header_id = l.header_id
           AND h.org_id = l.org_id
           AND h.header_id = pa.header_id
           AND l.line_id = pa.line_id(+)
           AND pa.list_header_id = lh.list_header_id
           AND (   PA.LIST_LINE_TYPE_CODE = 'DIS'
                OR PA.LIST_LINE_TYPE_CODE = 'SUR'
                OR PA.LIST_LINE_TYPE_CODE = 'PBH')
           AND PA.APPLIED_FLAG = 'Y'
           AND NOT EXISTS
                 (SELECT   'X'
                    FROM   OE_PRICE_ADJ_ASSOCS PAS, OE_PRICE_ADJUSTMENTS PA1
                   WHERE   PAS.RLTD_PRICE_ADJ_ID = PA.PRICE_ADJUSTMENT_ID
                           AND PA1.PRICE_ADJUSTMENT_ID =
                                 PAS.PRICE_ADJUSTMENT_ID
                           AND PA1.LIST_LINE_TYPE_CODE = 'PBH')
ORDER BY   l.line_id
/

a: Qp_list_headers_vl is view based on qp_list_headers_b and qp_list_headers_tl tables.

No comments:

Post a Comment