SELECT *
FROM ( SELECT DISTINCT
APS.VENDOR_NAME,
TO_CHAR (inv.invoice_date, 'rrrr/mm/dd')
inv_date,
-- INV.INVOICE_ID ,
-- TO_CHAR (SYSDATE, 'dd/mm/rrrr hh24:mi:ss'),
------------------
TO_CHAR (
TO_DATE ( :P_FROM_DATE, 'RRRR/MM/DD HH24:MI:SS'),
'rrrr/mm/dd')
FROM_DATEX,
TO_CHAR (TO_DATE ( :P_TO_DATE, 'RRRR/MM/DD HH24:MI:SS'),
'rrrr/mm/dd')
TO_DATEX,
----------------------
inv.DESCRIPTION,
( SELECT SUM (amount) * -1
FROM AP_INVOICE_lines_ALL LL
WHERE 1 > LL.amount
AND LL.amount <> 0
AND LL.INVOICE_ID = INV.INVOICE_ID
GROUP BY INV.INVOICE_ID)
ded,
--------- ______
--INVL.INVOICE_LINE_ID,
aps.SEGMENT1,
INV.PO_HEADER_ID,
POH.COMMENTS
PROJECT,
INV.DISPUTE_REASON
INV_NUMBER,
(SELECT SUM (AMOUNT)
FROM AP_INVOICE_LINES_aLL
WHERE INVOICE_ID = INV.INVOICE_ID AND AMOUNT > 0)
INVOICE_AMOUNT,
-- CK.CHECK_NUMBER,
INV.ORG_ID,
-- LISTAGG (CK.CHECK_NUMBER, ', ')
-- WITHIN GROUP (ORDER BY INV.DISPUTE_REASON)
-- CHECKS,
-- SUM (INV.AMOUNT_PAID) AMOUNT_PAID,
CASE
WHEN INVOICE_TYPE_LOOKUP_CODE <> 'MIXED'
THEN
LISTAGG (CK.CHECK_NUMBER, ', ')
WITHIN GROUP (ORDER BY INV.DISPUTE_REASON)
ELSE
apps.xx_fin_pkg.xx_get_check_num_prep_inv (
inv.invoice_id,
INV.ORG_ID)
END
CHECKS,
CASE
WHEN INVOICE_TYPE_LOOKUP_CODE <> 'MIXED'
THEN
(INV.AMOUNT_PAID)
ELSE
0
END
AMOUNT_PAID,
aps.vendor_id,
INV.INVOICE_ID
FROM AP_INVOICES_ALL INV,
-- AP_INVOICE_LINES_ALL INVL,
AP_CHECKS_ALL CK,
AP_INVOICE_PAYMENTS_ALL PAY,
AP_SUPPLIERS APS,
PO_HEADERS_ALL POH
WHERE 1 = 1
AND INV.CANCELLED_DATE IS NULL
AND PAY.INVOICE_ID(+) = INV.INVOICE_ID
AND CK.CHECK_ID(+) = PAY.CHECK_ID
AND INV.VENDOR_ID = APS.VENDOR_ID
AND INV.PO_HEADER_ID = POH.PO_HEADER_ID(+)
AND CK.VOID_DATE IS NULL
AND (INV.ORG_ID = :P_ORG_ID OR :P_ORG_ID IS NULL)
&p_VENDOR_ID_XX
-- AND (aps.SEGMENT1 = :P_VENDOR_ID OR :p_VENDOR_ID IS NULL)
AND TRUNC (TO_DATE (inv.invoice_Date)) BETWEEN TO_DATE (
:P_FROM_DATE,
'RRRR/MM/DD HH24:MI:SS')
AND TO_DATE (
:P_TO_DATE,
'RRRR/MM/DD HH24:MI:SS')
GROUP BY INV.DISPUTE_REASON,
INV.INVOICE_ID,
APS.VENDOR_NAME,
INV.PO_HEADER_ID,
POH.COMMENTS,
aps.SEGMENT1,
INV.ORG_ID,
aps.vendor_id,
inv.invoice_date,
INVOICE_TYPE_LOOKUP_CODE,
INV.AMOUNT_PAID,
inv.DESCRIPTION)
WHERE 1 = 1
AND ( CASE WHEN CHECKS IS NULL THEN 'NO' ELSE 'YES' END =
:P_IS_INV_PAID
OR :P_IS_INV_PAID IS NULL)
ORDER BY 1, 2
No comments:
Post a Comment