0% found this document useful (0 votes)
2 views

Oracle Fusion PO sql

The document contains SQL queries that retrieve distinct organization information and invoice statuses from various tables in a database. It includes logic to determine invoice statuses based on conditions such as approval status and payment status. The queries are structured to filter data based on effective dates and specific organizational contexts.

Uploaded by

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

Oracle Fusion PO sql

The document contains SQL queries that retrieve distinct organization information and invoice statuses from various tables in a database. It includes logic to determine invoice statuses based on conditions such as approval status and payment status. The queries are structured to filter data based on effective dates and specific organizational contexts.

Uploaded by

msmani0611
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

SELECT DISTINCT houft.name, hoif.

ORG_INFORMATION2 "Value
Set Id"

,hoif.ORG_INFORMATION3 "Cost Center 1"

,hoif.ORG_INFORMATION7 "Record Identifier"

FROM HR_ORGANIZATION_INFORMATION_F hoif,

HR_ORGANIZATION_UNITS_F_TL houft

WHERE trunc(sysdate) BETWEEN hoif.EFFECTIVE_START_DATE


AND hoif.EFFECTIVE_END_DATE

AND houft.organization_id = hoif.organization_id

AND hoif.ORG_INFORMATION_CONTEXT =
'PER_GL_COST_CENTER_INFO'

AND houft.language = 'US'

AND TRUNC(sysdate) BETWEEN houft.EFFECTIVE_START_DATE


AND houft.EFFECTIVE_END_DATE

ORDER by 1

------------------------------------------------------------------------------------------
--

Select I.*,

DECODE(APPS.Ap_Invoices_Pkg.GET_APPROVAL_STATUS(I.INVOICE
_ID,

I.INVOICE_AMOUNT,I.PAYMENT_STATUS_FLAG,I.INVOICE_TYPE_LOO
KUP_CODE),‘NEVER

APPROVED’ , ‘Never Validated’,‘NEEDS REAPPROVAL’, ‘Needs

Revalidation’,‘Other’) INVOICE_STATUS

FROM AP_INVOICES_ALL I

------------------------------------------------------------------------------------------
--
SELECT r.vendor_name, r.vendor_number, r.invoice_num,
prepay_remaining_amt, invoice_type_lookup_code,
payment_status_flag, distribution_line_number, cancelled_date

, CASE WHEN invoice_type_lookup_code = ‘PREPAYMENT’ AND


invoice_approval_flag = ‘APPROVED’ AND payment_status_flag IN
(‘P’,‘N’) THEN ‘Unpaid’

WHEN prepay_remaining_amt = 0 THEN ‘Fully Applied’

WHEN
DECODE(earliest_settlement_date,NULL,‘PERMANENT’,‘TEMPORAR
Y’) = ‘PERMANENT’ THEN ‘Permanent’

WHEN invoice_approval_status = ‘NEVER APPROVED’ THEN


‘Unapproved’

WHEN cancelled_date IS NOT NULL THEN ‘Cancelled’

WHEN payment_status_flag = ‘N’ AND cancelled_date IS NULL AND


prepay_remaining_amt != 0 THEN ‘Unpaid’

ELSE ‘Available’

END invoice_status

FROM (

SELECT q.*

, CASE WHEN encumbrance_flag = ‘N’ AND


NVL(invoice_approval_flag,‘X’) IN (‘A’,‘T’) AND invoice_holds = 0
THEN ‘APPROVED’

WHEN encumbrance_flag = ‘N’ AND NVL(invoice_approval_flag,‘X’)


IN (‘A’,‘T’) AND invoice_holds > 0 OR
NVL(invoice_approval_flag,‘X’) = ‘N’ THEN ‘NEEDS REAPPROVAL’

WHEN encumbrance_flag = ‘N’ AND dist_var_hold > 0 THEN


‘NEEDS REAPPROVAL’

WHEN encumbrance_flag = ‘N’ AND NVL(invoice_approval_flag,‘X’)


= ‘X’ THEN ‘NEVER APPROVED’

ELSE NULL END invoice_approval_status

FROM (

SELECT idstr.invoice_id

, inv.invoice_num

, vend.segment1 vendor_number
, vend.vendor_name

, inv.creation_date

, inv.invoice_type_lookup_code

, inv.payment_status_flag

, CASE WHEN match.match_flag_count > 0 AND


idstr.match_status_flag IS NULL THEN NULL

WHEN match.match_flag_count > 0 AND


NVL(idstr.match_status_flag,‘N’) = ‘N’ THEN ‘N’

WHEN match.match_flag_count > 0 AND


NVL(idstr.match_status_flag,‘N’) = ‘T’ THEN ‘T’

WHEN match.match_flag_count > 0 AND


NVL(idstr.match_status_flag,‘N’) = ‘A’ THEN ‘A’

ELSE NULL END invoice_approval_flag

, NVL(holds.hold_count,0) invoice_holds

, NVL(dis_var_holds.dist_var_hold_count,0) dist_var_hold

, inv.cancelled_date

, match.match_flag_count

, idstr.line_type_lookup_code

, idstr.distribution_line_number

, idstr.match_status_flag

, inv.earliest_settlement_date

, ROUND(SUM(nvl(idstr.prepay_amount_remaining,amount)),2)
prepay_remaining_amt

, ‘N’ encumbrance_flag

FROM ap_invoices_all inv JOIN ap_invoice_distributions_all idstr


ON (inv.invoice_id = idstr.invoice_id)

JOIN po_vendors vend ON (inv.vendor_id = vend.vendor_id)

LEFT OUTER JOIN (SELECT hold.invoice_id, COUNT(hold.invoice_id)


hold_count

FROM ap_holds_all hold

WHERE hold.release_lookup_code IS NULL


GROUP BY invoice_id

) holds ON (inv.invoice_id = holds.invoice_id)

LEFT OUTER JOIN (SELECT hold_dis.invoice_id,


COUNT(hold_dis.invoice_id) dist_var_hold_count

FROM ap_holds_all hold_dis

WHERE hold_dis.release_lookup_code IS NULL

AND hold_dis.hold_lookup_code = ‘DIST VARIANCE’

GROUP BY hold_dis.invoice_id

) dis_var_holds ON (inv.invoice_id = dis_var_holds.invoice_id)

LEFT OUTER JOIN (SELECT idstr1.invoice_id,


COUNT(idstr1.invoice_id) match_flag_count FROM
ap_invoice_distributions_all idstr1 WHERE
idstr1.match_status_flag IS NOT NULL GROUP BY idstr1.invoice_id)
match ON (inv.invoice_id = match.invoice_id)

WHERE inv.invoice_type_lookup_code = ‘PREPAYMENT’

GROUP BY idstr.invoice_id, inv.invoice_num, vend.segment1,


inv.creation_date, inv.invoice_type_lookup_code,
inv.approval_status, inv.payment_status_flag,
idstr.line_type_lookup_code, idstr.distribution_line_number,
idstr.match_status_flag, inv.earliest_settlement_date,
NVL(holds.hold_count,0),
NVL(dis_var_holds.dist_var_hold_count,0), inv.cancelled_date,
match.match_flag_count, vend.vendor_name, ‘N’,
inv.earliest_settlement_date

ORDER BY inv.creation_date DESC, inv.invoice_num,


idstr.distribution_line_number

)q

)r

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy