SELECT POS.SEGMENT1
, HP.PARTY_NAME
,cur_period.PAYMENT_AMOUNT cur_pay_amt
,prev_period.PAYMENT_AMOUNT prev_pay_amt
,ROUND((((cur_period.PAYMENT_AMOUNT-prev_period.PAYMENT_AMOUNT)/prev_period.PAYMENT_AMOUNT)*100),1)||'%' increase_decrease
FROM
(SELECT AIA.VENDOR_ID VENDOR_ID
,SUM(NVL(aipa.AMOUNT,0)) PAYMENT_AMOUNT
FROM AP_INVOICES_ALL AIA,
ap_invoice_payments_all aipa,
gl_periods gl
WHERE 1=1
AND AIA.INVOICE_ID = AIPA.INVOICE_ID
AND aipa.period_name = gl.period_name
AND gl.period_set_name ='XX Period Name'
AND gl.PERIOD_YEAR = :P_Fiscal_Year
AND gl.PERIOD_NAME = :P_Period
--AND SYSDATE BETWEEN gl.start_date and gl.end_date
GROUP BY AIA.VENDOR_ID
) cur_period,
(SELECT AIA.VENDOR_ID VENDOR_ID
,SUM(NVL(aipa.AMOUNT,0)) PAYMENT_AMOUNT
FROM AP_INVOICES_ALL AIA,
ap_invoice_payments_all aipa,
gl_periods gl
WHERE 1=1
AND AIA.INVOICE_ID = AIPA.INVOICE_ID
AND aipa.period_name = gl.period_name
AND gl.period_set_name ='XX Period Name'
AND gl.period_name = (
SELECT gl.period_name
FROM
gl_periods gl,
gl_periods gl2
WHERE 1=1
AND gl.period_set_name ='XX Period Name'
AND (
(
gl2.period_name = :P_Comp_Period
AND gl2.PERIOD_YEAR = :P_Comp_Fis_Year
AND trunc(gl2.start_date) between gl.start_date and gl.end_date
)
OR
(
( trunc(gl2.start_date-1) between gl.start_date and gl.end_date )
AND gl2.period_name = :P_Period
AND gl2.PERIOD_YEAR = :P_Fiscal_Year
AND :P_Comp_Period IS NULL
AND :P_Comp_Fis_Year IS NULL
)
)
AND gl2.period_set_name ='XX Period Name'
)
GROUP BY AIA.VENDOR_ID
) prev_period
,POZ_SUPPLIERS POS
,HZ_PARTIES HP
WHERE POS.VENDOR_ID = cur_period.vendor_id(+)
AND POS.VENDOR_ID = Prev_period.vendor_id(+)
AND POS.party_id = hp.party_id
AND ((COALESCE(NULL, :P_Supplier) IS NULL)
OR (HP.PARTY_NAME IN (:P_Supplier)))
and (NVL(cur_period.PAYMENT_AMOUNT ,0)<>0 OR NVl(prev_period.PAYMENT_AMOUNT ,0)<>0)
AND abs((((cur_period.PAYMENT_AMOUNT-prev_period.PAYMENT_AMOUNT)/prev_period.PAYMENT_AMOUNT)*100)) > = NVL(:P_Change,abs((((cur_period.PAYMENT_AMOUNT-prev_period.PAYMENT_AMOUNT)/prev_period.PAYMENT_AMOUNT)*100)))
No comments:
Post a Comment