检查订单是否有退货

使用下面SQL检查:
注:A区代表现在要退的订单信息,
     B区是最原始的订单信息,
     C区是可能针对B的已退的订单信息,,  如果C存在,且数据与B中的数据相当,,,那就是说退货已完成,,

就没有办法再针对B做退货啦!
============================

SELECT ooh1.order_number     A1,
       ool1.ordered_item     A2,
       ool1.line_number      A3,
       ool1.ordered_quantity A4,
       ooh1.flow_status_code A5,
       ooh2.order_number     B1,
       ool2.line_number      B1,
       ool2.ordered_quantity B3,
       ooh2.flow_status_code B4,
       ooh3.order_number     C1,
       ool3.line_number      C2,
       ool3.ordered_quantity C3,
       ooh3.flow_status_code C4
  FROM ont.oe_order_headers_all ooh1,
       ont.oe_order_lines_all   ool1,
       ont.oe_order_lines_all   ool2,
       ont.oe_order_headers_all ooh2,
       ont.oe_order_lines_all   ool3,
       ont.oe_order_headers_all ooh3
 WHERE ooh1.header_id = ool1.header_id
   AND ool1.line_category_code = 'RETURN'
   AND ooh1.order_number = '&return_order_number'
   AND ool1.reference_line_id = ool2.line_id
   AND ooh2.header_id = ool2.header_id
   AND ool1.reference_line_id = ool3.reference_line_id(+)
   AND ooh3.header_id(+) = ool3.header_id
   AND ooh1.order_number <> ooh3.order_number
参考:
Solution
ANSWER:
========
It is likely this indicates the original order line was referenced for the item and quantity on an earlier RMA order line.

The following SQL select statements can be used to determine if this Order Item has already been "Returned"
by a previous RMA order line.

1. To get information on order lines which have referenced the original sales order line previously, run the following:

SQL > select line_id, ordered_quantity, reference_line_id
                 from oe_order_lines_all
            where line_category_code = 'RETURN' and reference_line_id = &line_id ;

Please Note: The '&line_id' is replaced by the actual reference_line_id, which would be the line_id for the original sales order line.


2. Using the line_id's returned from sql #1, ('X' and 'Y'), you can find the other return type lines and header_id's they belong to;

SQL > select LINE_NUMBER, LINE_ID, LINE_TYPE_ID, HEADER_ID, REFERENCE_HEADER_ID,
            LINE_CATEGORY_CODE, OPEN_FLAG, BOOKED_FLAG,
           CANCELLED_FLAG, FLOW_STATUS_CODE
                  from OE_ORDER_LINES_ALL
           where line_id in ('XXXXX','YYYYY');


3. The returned values for the header_id's ('N' and 'M') for the lines in sql #2, show status and type, so using the header_ids in the last select,

SQL > select ORDER_NUMBER, HEADER_ID, ORDER_TYPE_ID, CANCELLED_FLAG, OPEN_FLAG,
BOOKED_FLAG, ORDER_CATEGORY_CODE, FLOW_STATUS_CODE
from OE_ORDER_HEADERS_ALL
where header_id in ('NNNNN','MMMMM');

One can find the other separate orders. If one has a return line which is either 'Booked' (Awaiting Return), or 'Closed', then there is already a valid return for the original order item and qty, and no additional returns can reference the same sales order and line item qty. Be sure the ordered item qty and the returned item qty are the same, or there can be additional return lines created for the remaining quantity.

References
Note 133464.1 - OMSE11i.SQL release 11i script
Note 156860.1 - OMCHECK.SQL Oracle Order Management Diagnostic Tool
原文地址:https://www.cnblogs.com/benio/p/2287809.html