Unable to Void Payment

Check these 2 queries.

Query #1:

SELECT SUM(NVL(aid.amount,0))
FROM ap_invoice_payments_all aip,
ap_invoices_all ai,
ap_invoice_distributions_all aid,
ap_invoice_distributions_all aid2
WHERE aip.check_id = &CHECK_ID
AND ai.invoice_id = aip.invoice_id
AND ai.invoice_type_lookup_code = 'PREPAYMENT'
AND ai.invoice_id = aid2.invoice_id
AND aid2.line_type_lookup_code = 'ITEM'
AND aid.prepay_distribution_id = aid2.invoice_distribution_id;

-> If amount returned <> 0 then it means that prepayment has not been unapplied completely.Solution would be to unapply the prepayment and account that event.

Query #2:

SELECT aid.* FROM ap_invoice_distributions_all aid_prepay,
ap_invoice_payments_all aip,
ap_invoices_all ai_prepay,
ap_invoice_distributions_all aid,
ap_invoice_distributions_all aidp
WHERE aip.check_id = &CHECK_ID
AND aip.invoice_id = ai_prepay.invoice_id
AND ai_prepay.invoice_type_lookup_code = 'PREPAYMENT'
AND aid_prepay.invoice_id = ai_prepay.invoice_id
AND aid_prepay.invoice_distribution_id = aid.prepay_distribution_id
AND aid.prepay_distribution_id IS NOT NULL
AND aid.parent_reversal_id IS NOT NULL
AND aid.amount > 0AND nvl(aid.posted_flag, 'N') = 'N'
AND aid.invoice_id = aidp.invoice_id
AND aid.invoice_line_number = aidp.invoice_line_number
AND aid.parent_reversal_id = aidp.invoice_distribution_id
AND aid.prepay_distribution_id = aidp.prepay_distribution_id
AND nvl(aidp.posted_flag, 'N') = 'Y';

-> If this query returns data that means Prepayment unapplication event on the invoice has not been accounted.Solution is to make sure the standard invoice, on which the Prepayment is applied, has been validated and create new accounting.