You are on page 1of 3

select api.

doc_sequence_value vouch_no,
api.invoice_num,
pov.vendor_name,
p_open_period open_period,
to_char (api.invoice_date, 'DD-MON-YYYY') invrcvddt,
api.invoice_currency_code curr,
api.invoice_amount invamt,
fnd.description dept,
nvl (api.base_amount, api.invoice_amount) funct_amount,
to_char ( (to_date (api.attribute1, 'RRRR/MM/DD hh24:mi:ss')),
'DD-MON-RRRR')
user_sent,
po_distributions_all pda,
pa_projects_all ppa
where pha.po_header_id = pda.po_header_id
and ppa.project_id = pda.project_id
and pda.project_id is not null
and pda.po_release_id =(select po_release_id
from po_releases_all pra
where pra.release_num =
(select max (release_num)
from po_releases_all
pra1,po_distributions_all pd
where pra1.po_header_id
=pha.po_header_id
and
pd.po_release_id=pra1.po_release_id
and pd.project_id is
not null)
and pra.po_header_id =
pha.po_header_id)
and pha.po_header_id = nvl
(api.quick_po_header_id,poh.po_header_id)
and rownum=1
),
(select pa.segment1
from po_requisition_headers_all por,
po_requisition_lines_all pol,
po_req_distributions_all pod,
po_notification_controls po,
pa_projects_all pa
where por.requisition_header_id =
pol.requisition_header_id
and pod.project_id is not null
and pod.requisition_line_id =
pol.requisition_line_id
and po.po_header_id = poh.po_header_id
and pa.project_id = pod.project_id
and po.attribute2 = por.segment1)))
rproject, decode (
poh.type_lookup_code,'BLANKET',
nvl ( (select pt.task_number
from po_headers_all pha,
po_distributions_all pda,
pa_projects_all ppa,pa_tasks pt
where pha.po_header_id = pda.po_header_id
and ppa.project_id = pda.project_id
and pt.project_id=ppa.project_id
and pda.project_id is not null
and pt.task_id=pda.task_id
and pda.po_release_id =
(select po_release_id
from po_releases_all pra
where pra.release_num = (select max
(release_num)
from po_releases_all
pra1,po_distributions_all pd
where pra1.po_header_id
=pha.po_header_id
and
pd.po_release_id=pra1.po_release_id
and pd.project_id is
not null)
and pra.po_header_id =
pha.po_header_id)
and pha.po_header_id = nvl
(api.quick_po_header_id,poh.po_header_id)
and rownum=1
),
(select pt.task_number
from po_requisition_headers_all por,
po_requisition_lines_all pol,
po_req_distributions_all pod,
po_notification_controls po,
pa_projects_all pa,pa_tasks pt
where por.requisition_header_id =
pol.requisition_header_id
and pod.project_id is not null
and pt.project_id=pa.project_id
and pt.task_id=pod.task_id
and pod.requisition_line_id =
pol.requisition_line_id
and po.po_header_id = poh.po_header_id
and pa.project_id = pod.project_id
and po.attribute2 = por.segment1)))
rtask
from ap_invoices_all api,
po_vendors pov,
fnd_lookup_values fnd,
po_headers_all poh
where api.vendor_id = pov.vendor_id
and api.attribute7 is not null
and fnd.description = 'ENGG'
and poh.type_lookup_code = 'BLANKET'
AND api.doc_sequence_value NOT IN (SELECT ATTRIBUTE3 FROM
RCV_SHIPMENT_HEADERS WHERE ATTRIBUTE3=api.doc_sequence_value AND ATTRIBUTE3 IS NOT
NULL)
and fnd.lookup_code = api.attribute7
-- and poh.segment1 in
('4004992','4004993','4004994','4004995','4004996','4004997','4004998','4004999')
and poh.po_header_id = api.quick_po_header_id
and fnd.lookup_type = 'XXDPC_USER_SENT_DPT'
and decode (ap_invoices_pkg.
get_approval_status (api.invoice_id,
api.invoice_amount,
api.payment_status_flag,
api.invoice_type_lookup_code),
'NEVER APPROVED', 'Never Validated',
'NEEDS REAPPROVAL', 'Needs Revalidation',
'CANCELLED', 'Cancelled',
'Validated') not in ('Validated', 'Needs Revalidation')
and decode (ap_invoices_pkg.
get_approval_status (api.invoice_id,
api.invoice_amount,
api.payment_status_flag,
api.invoice_type_lookup_code),
'NEVER APPROVED', 'Never Validated',
'NEEDS REAPPROVAL', 'Needs Revalidation',
'CANCELLED', 'Cancelled',
'Validated') not like
('Cancelled')) where rproject <> 'E0000';

You might also like