0% found this document useful (0 votes)
56 views2 pages

Requisition Distributions Overview

Uploaded by

ishaqalikhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views2 pages

Requisition Distributions Overview

Uploaded by

ishaqalikhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

SELECT DISTINCT

1 key,
pha1.po_header_id,
TO_CHAR (pha1.START_DATE, 'DD/MM/YYYY') START_DATE,
TO_CHAR (pha1.END_DATE, 'DD/MM/YYYY') END_DATE,
pha1.segment1,
psv.segment1 vendor_number,
psv.vendor_name,
pha1.vendor_id,
pha1.vendor_contact_id,
[Link],

-- Buyer Name
(SELECT ppnf.full_name
FROM per_person_names_f ppnf
JOIN per_all_people_f papf
ON papf.person_id = ppnf.person_id
WHERE papf.person_id = pha1.agent_id
AND ppnf.name_type = 'GLOBAL'
AND SYSDATE BETWEEN ppnf.effective_start_date AND ppnf.effective_end_date
AND SYSDATE BETWEEN papf.effective_start_date AND papf.effective_end_date
) AS Buyer,

-- Buyer Email
(SELECT email.email_address
FROM per_email_addresses email
WHERE email.person_id = pha1.agent_id
AND UPPER(TRIM(email.email_type)) = 'W1'
AND TRUNC(SYSDATE) BETWEEN TRUNC(NVL(email.date_from, SYSDATE))
AND TRUNC(NVL(email.date_to, SYSDATE))
) AS Buyer_Email,

-- from sql2
pla.contract_id,

ppnf.full_name AS requisition_line_requestor,
email.email_address AS requisition_line_requestor_email,

-- Organisation ID from per_all_assignments_f


(SELECT asg_act.organization_id
FROM per_all_assignments_f asg_act
WHERE asg_act.person_id(+) = pha1.agent_id
AND UPPER(asg_act.assignment_type(+)) IN ('E','P','C')
AND UPPER(asg_act.primary_flag) =
CASE asg_act.assignment_type
WHEN 'E' THEN 'Y'
WHEN 'P' THEN 'N'
WHEN 'C' THEN 'Y'
ELSE NULL
END
AND TRUNC(SYSDATE) BETWEEN TRUNC(NVL(asg_act.effective_start_date(+),
SYSDATE))
AND TRUNC(NVL(asg_act.effective_end_date(+),
SYSDATE))
AND UPPER(TRIM(asg_act.effective_latest_change)) = 'Y'
AND UPPER(TRIM(asg_act.assignment_status_type)) = 'ACTIVE'
) AS organisation_id

FROM po_headers_all pha1


LEFT JOIN poz_suppliers_v psv
ON pha1.vendor_id = psv.vendor_id
JOIN po_lines_all pla
ON pha1.po_header_id = pla.contract_id -- join condition
JOIN po_headers_all pha2
ON pha2.po_header_id = pla.po_header_id -- original sql2 join
JOIN po_distributions_all pda
ON pha2.po_header_id = pda.po_header_id
JOIN por_req_distributions_all prda
ON prda.distribution_id = pda.req_distribution_id
JOIN por_requisition_lines_all prla
ON prla.requisition_line_id = prda.requisition_line_id
AND prla.line_number = 1
JOIN por_requisition_headers_all prha
ON prha.requisition_header_id = prla.requisition_header_id
LEFT JOIN per_person_names_f ppnf
ON ppnf.person_id = prla.requester_id
AND ppnf.name_type = 'GLOBAL'
AND SYSDATE BETWEEN ppnf.effective_start_date
AND ppnf.effective_end_date
LEFT JOIN per_email_addresses email
ON email.person_id = prla.requester_id
AND UPPER(TRIM(email.email_type)) = 'W1'
AND TRUNC(SYSDATE) BETWEEN TRUNC(NVL(email.date_from, SYSDATE))
AND TRUNC(NVL(email.date_to, SYSDATE))
WHERE pla.contract_id = 300000414739549

You might also like