Pages

Saturday, January 22, 2011

Invoice number for sales order number

SELECT ooh.order_number
              ,ool.line_number
              ,ool.ordered_item
              ,ool.ordered_quantity * ool.unit_selling_price
              ,rct.trx_number invoice_number
              ,rct.trx_date
              ,rcta.line_number
              ,rcta.unit_selling_price
              ,ooh.org_id
   FROM  oe_order_headers_all ooh
               ,oe_order_lines_all ool
               ,ra_customer_trx_all rct
               ,ra_customer_trx_lines_all rcta
   WHERE ooh.header_id=ool.header_Id
        AND  rcta.interface_line_attribute1=to_char(ooh.order_number)
        AND  rcta.interface_line_attribute6=to_char(ool.line_id)
        AND  rcta.customer_trx_id=rct.customer_trx_id
        AND  ooh.order_number=nvl(:p_order_number,ooh.order_number)
        AND  ooh.org_id=nvl(:p_org_id,ooh.org_id)

Join between OM,WSH,AR Tables

SELECT ooh.order_number
              ,ool.line_id
              ,ool.ordered_quantity
              ,ool.shipped_quantity
              ,ool.invoiced_quantity
              ,wdd.delivery_detail_id
              ,wnd.delivery_id
              ,rctl.interface_line_attribute1
              ,rctl.interface_line_attribute3
              ,rctl.interface_line_attribute6
              ,rct.org_id
              ,rct.creation_date
              ,trx_number
              ,rctl.quantity_ordered
              ,rct.interface_header_context
  FROM oe_order_headers_all ooh
             ,oe_order_lines_all ool
             ,wsh_delivery_details wdd
             ,wsh_new_deliveries wnd
             ,wsh_delivery_assignments wda
             ,ra_customer_trx_all rct
             ,ra_customer_trx_lines_all rctl
 WHERE ooh.header_Id=ool.header_id
      AND wdd.source_header_id=ooh.header_id
      AND wdd.delivery_detail_Id=wda.delivery_detail_id
      AND wda.delivery_id=wnd.delivery_id
      AND rctl.interface_line_attribute1=to_char(ooh.order_number)
      AND rctl.interface_line_attribute6=to_char(ool.line_id)
      AND rctl.interface_line_attribute3=to_char(wnd.delivery_id)
      AND rctl.customer_trx_id=rct.customer_trx_id
      AND rct.interface_header_context='ORDER ENTRY'