AR Refund Upload

Description
Categories: Enginatics, Upload
Repository: Github
Bulk-refund customer credit balances in AR. Each row refunds either an open credit memo or the unapplied/on-account portion of a customer cash receipt by applying it against the operating unit's Credit Memo Refund Receivables Activity, via AR_CM_APPLICATION_PUB.Activity_application or AR_RECEIPT_API_PUB.Activity_application.

WHEN TO USE EACH REFUND SOURCE
- Credit Memo - the customer has ... 
Bulk-refund customer credit balances in AR. Each row refunds either an open credit memo or the unapplied/on-account portion of a customer cash receipt by applying it against the operating unit's Credit Memo Refund Receivables Activity, via AR_CM_APPLICATION_PUB.Activity_application or AR_RECEIPT_API_PUB.Activity_application.

WHEN TO USE EACH REFUND SOURCE
- Credit Memo - the customer has an open credit memo (e.g. overpayment recorded as a CM) and wants the money back.
- Unapplied Receipt - the customer paid more than they owed, or paid against the account with no specific invoice. The receipt has an unapplied/on-account balance to return.

PER-ROW WORKFLOW
1. Pick Refund Source. The Credit Memo Number / Receipt Number LOV adapts - only the matching one has values.
2. Pick the Credit Memo Number or Receipt Number.
3. Refund Amount auto-populates with the source's open balance (CM remaining balance, or receipt unapplied amount). Override with a smaller positive amount for a partial refund. Excel validates > 0 and <= source balance; PL/SQL re-validates at upload time.
4. Apply Date and Apply GL Date default to today. The GL Date must be in an open AR accounting period.
5. Optionally fill Payment Method, Pay Group, Payment Reason Comments, and Comments - these flow through to the downstream AP Payment Request invoice / AR application record.

APPROVAL LIMITS
The AR API runs with p_chk_approval_limit_flag='Y' - the user's AR approval limit applies. Rows over the limit error with the API's own message. Limits are never bypassed.

END-TO-END FLOW
1. AR (this upload): a new ar_receivable_applications_all row is created (application_type='CM' or 'CASH', status='ACTIVITY').
2. AR -> AP business event (automatic): AP creates a Payment Request invoice (source='Receivables', invoice_type_lookup_code='PAYMENT REQUEST') payable to the customer's TCA party.
3. AP Invoice Validation (standard AP concurrent).
4. AP Payment Process Request issues the disbursement.

This upload performs step 1 only. Steps 2-4 are standard Oracle AP processing - a second human control point before any money leaves.

PER-OU SETUP
Each OU that processes refunds needs a Credit Memo Refund-type Receivables Activity (AR Setup -> Receipts -> Receivable Activities). The same activity is used for both CM and receipt refunds. If none, the upload errors: "No Credit Memo Refund activity is defined for this operating unit."

CANDIDATE IDENTIFICATION
- Credit Memo Number LOV: open credit memos in the OU whose customer account has no open invoices (standard refund-candidate rule). Set "Include accounts with open invoices" = Yes to override the safety filter (e.g. when open invoices are disputed).
- Receipt Number LOV: unapplied/on-account customer receipts in the OU with positive unapplied amount.
- Download in Create, Update mode to see existing candidates as rows.

FILTER PARAMETERS
- Operating Unit - filters both branches.
- GL Date From / To, Credit Memo Number (multi-value), Customer Account, Batch Name (multi-value LOV on AR transaction batches) - Credit Memo branch only. The Receipt branch always shows all unapplied/on-account receipts in the chosen OU.
- Include accounts with open invoices - default blank (= safety filter on for CMs). Does not apply to receipts.

MODE
Create only. Each row gets a Status and Message in the result XLSM for audit.
   more
select
null action_,
null status_,
null message_,
null modified_columns_,
haouv.name operating_unit,
'Credit Memo' refund_source,
rcta.trx_number credit_memo_number,
cast(null as varchar2(30)) receipt_number,
abs(apsa.amount_due_remaining) open_balance,
abs(apsa.amount_due_remaining) refund_amount,
cast(null as date) apply_date,
cast(null as date) apply_gl_date,
cast(null as varchar2(100)) payment_method,
cast(null as varchar2(80)) pay_group,
cast(null as varchar2(240)) payment_reason_comments,
cast(null as varchar2(240)) comments,
rownum upload_row
from
ar_payment_schedules_all apsa,
ra_customer_trx_all rcta,
hr_all_organization_units_vl haouv,
hz_cust_accounts hca
where
1=1 and
apsa.class='CM' and
apsa.status='OP' and
apsa.amount_due_remaining<>0 and
apsa.customer_trx_id=rcta.customer_trx_id and
apsa.org_id=haouv.organization_id and
apsa.customer_id=hca.cust_account_id and
apsa.org_id in (select mgoat.organization_id from mo_glob_org_access_tmp mgoat union select fnd_global.org_id from dual where fnd_release.major_version=11) and
(nvl(:include_with_open_invoices,'N')='Y' or not exists (
select
null
from
ar_payment_schedules_all inv
where
inv.customer_id=apsa.customer_id and
inv.org_id=apsa.org_id and
inv.class='INV' and
inv.status='OP' and
inv.amount_due_remaining<>0
))
union all
select
null action_,
null status_,
null message_,
null modified_columns_,
haouv.name operating_unit,
'Unapplied Receipt' refund_source,
cast(null as varchar2(20)) credit_memo_number,
acra.receipt_number,
(select sum(ara.amount_applied) from ar_receivable_applications_all ara where ara.cash_receipt_id=acra.cash_receipt_id and ara.status in ('UNAPP','ACC') and ara.amount_applied>0) open_balance,
(select sum(ara.amount_applied) from ar_receivable_applications_all ara where ara.cash_receipt_id=acra.cash_receipt_id and ara.status in ('UNAPP','ACC') and ara.amount_applied>0) refund_amount,
cast(null as date) apply_date,
cast(null as date) apply_gl_date,
cast(null as varchar2(100)) payment_method,
cast(null as varchar2(80)) pay_group,
cast(null as varchar2(240)) payment_reason_comments,
cast(null as varchar2(240)) comments,
rownum upload_row
from
ar_cash_receipts_all acra,
hr_all_organization_units_vl haouv,
hz_cust_accounts hca
where
1=1 and
acra.status='UNAPP' and
acra.org_id=haouv.organization_id and
acra.pay_from_customer=hca.cust_account_id and
acra.org_id in (select mgoat.organization_id from mo_glob_org_access_tmp mgoat union select fnd_global.org_id from dual where fnd_release.major_version=11) and
exists (
select
null
from
ar_receivable_applications_all ara
where
ara.cash_receipt_id=acra.cash_receipt_id and
ara.status in ('UNAPP','ACC') and
ara.amount_applied>0
)
Parameter NameSQL textValidation
Upload Mode
:p_upload_mode like '%' || xxen_upload.action_update
LOV
Operating Unit
haouv.name=:operating_unit
LOV
GL Date From
apsa.gl_date>=:gl_date_from
Date
GL Date To
apsa.gl_date<:gl_date_to+1
Date
Credit Memo Number
rcta.trx_number=:credit_memo_number
Customer Account
hca.account_number=:customer_account
Batch Name
rcta.batch_id=:batch_id
LOV
Include accounts with open invoices
 
LOV