Sie sind auf Seite 1von 3

SELECT DISTINCT pr.

pr#
, pr.pr_description
, (SELECT mcb.segment1||'.'||mcb.segment2
FROM mtl_categories_b mcb
, po_requisition_lines_all prl
where 1=1
and prl.category_id = mcb.category_id
and prl.requisition_line_id in (select min(requisition_line_id)
from po_requisition_lines_all
where requisition_header_id =
pr.requisition_header_id)) pr_category
, pr.pr_creator
, pr.pr_creation_date
, pr.pr_approver
, pr.pr_approved_date
, pr.pr_amount
, pr.sequence_num pr_approv_seq
, (select segment3
from gl_code_combinations
where code_combination_id = pda.code_combination_id) po_dept
, (select segment3
from gl_code_combinations
where code_combination_id = pr.code_combination_id) pr_dept
, (select DECODE(catalog_type,'EXTERNAL','Catalog PR','NONCATALOG','Non
Catalog PR',NULL,'')
from po_requisition_lines_all
where catalog_type is not null
AND requisition_line_id = pr.requisition_line_id) pr_request
, pha.segment1 po#
, pha.comments po_description
, (SELECT mcb.segment1||'.'||mcb.segment2
FROM MTL_CATEGORIES_b mcb
, po_lines_all pol
where 1=1
and pol.category_id = mcb.category_id
and po_line_id in (select min(po_line_id)
from po_lines_all
where po_header_id = pha.po_header_id)) po_category
, (SELECT full_name
FROM PER_ALL_PEOPLE_F
WHERE person_id IN ( SELECT employee_id
FROM FND_USER
WHERE user_id = pha.created_by
)
AND ROWNUM <2 )po_created_by
, pah.employee_name po_approver
, pah.sequence_num po_approv_seq
, pha.creation_date po_creation_date
, pha.approved_date po_approval_date
, (SELECT sum(quantity*unit_price)
FROM PO_LINES_ALL
WHERE po_header_id = pha.po_header_id
AND Nvl(cancel_flag,'N') <> 'Y' ) po_amount
, pha.currency_code currency
, (select min(creation_date) from rcv_shipment_lines where po_header_id =
pha.po_header_id) receipt_creation_date
, (select max(creation_date) from rcv_shipment_lines where po_header_id =
pha.po_header_id) receipt_creation_date
, aps.vendor_id
, aps.vendor_name
, apss.country country_code
, (select territory_short_name
from fnd_territories_vl
where territory_code = apss.country) country
, aps.one_time_flag
, (select tolerance_name
from ap_tolerance_templates
where tolerance_type = 'GOODS'
and tolerance_id = apss.tolerance_id) Invoice_Tolerance
, aia.invoice_num
, aia.description invoice_description
, apt.name payment_term
, aia.invoice_date
, (SELECT Max(aca.check_date)
FROM AP_INVOICE_PAYMENTS_ALL aipa,
AP_CHECKS_ALL aca
WHERE aipa.check_id = aca.check_id
AND aipa.invoice_id = aia.invoice_id
AND aca.status_lookup_code <> 'VOIDED'
)payment_date
, (SELECT full_name
FROM PER_ALL_PEOPLE_F
WHERE person_id IN (SELECT MAX(fu.employee_id)
FROM AP_INVOICE_PAYMENTS_ALL aipa
, AP_CHECKS_ALL aca
, fnd_user fu
WHERE aipa.check_id = aca.check_id
AND aipa.invoice_id = aia.invoice_id
AND aca.created_by = fu.user_id
AND aca.status_lookup_code <> 'VOIDED')
and trunc(sysdate) between NVL(effective_start_date,TRUNC(SYSDATE-1))
and NVL(effective_end_date, TRUNC(SYSDATE+1)))Payment_created
, aia.amount_paid
, (aia.invoice_amount - aia.total_tax_amount) Item_Amt
FROM po_headers_all pha
, ap_suppliers aps
, ap_supplier_sites_all apss
, ap_terms apt
, po_distributions_all pda
, ap_invoices_all aia
, ap_invoice_distributions_all aid
, po_action_history_v pah
, (SELECT prha.segment1 pr#,
prha.description pr_description,
prha.creation_date pr_creation_date,
cr.full_name pr_creator,
sum(prla.unit_price*prla.quantity) pr_amount,
prha.approved_date pr_approved_date,
appr.full_name pr_approver,
prda.distribution_id,
prla.requisition_line_id,
prla.requisition_header_id,
pah.sequence_num,
prda.code_combination_id
FROM po_req_distributions_all prda,
po_requisition_lines_all prla,
po_requisition_headers_all prha,
per_all_people_f cr,
po_action_history pah,
per_all_people_f appr
WHERE 1 = 1
AND prda.requisition_line_id = prla.requisition_line_id
AND prla.requisition_header_id = prha.requisition_header_id
AND prha.preparer_id = cr.person_id
AND pah.employee_id = appr.person_id
AND pah.object_id = prha.requisition_header_id
AND object_type_code = 'REQUISITION'
and action_code='APPROVE'
GROUP BY prha.segment1,
prha.description,
prha.creation_date,
cr.full_name,
prha.approved_date,
appr.full_name,
prda.distribution_id,
prla.requisition_line_id,
prla.requisition_header_id,
pah.sequence_num,
prda.code_combination_id
) pr
WHERE 1 = 1
AND Trunc(pha.creation_date) between '01-AUG-2016' and '23-MAY-2017'
AND pha.vendor_id = aps.vendor_id
AND aps.vendor_id = apss.vendor_id
AND pha.vendor_site_id = apss.vendor_site_id
AND pah.object_id = pha.po_header_id
AND pah.object_type_code = 'PO'
AND pha.terms_id = apt.term_id
AND pha.po_header_id = pda.po_header_id
AND pda.po_distribution_id = aid.po_distribution_id
AND aid.invoice_id = aia.invoice_id
AND pda.req_distribution_id = pr.distribution_id(+)
--and pr.pr# = '11225524'
ORDER BY pha.segment1
, aia.invoice_num
, pr.sequence_num ASC

Das könnte Ihnen auch gefallen