---------------------------------------------------
--- AR_RECEIPT_API_PUB.Create_and_apply
--- By Oracle-ebspro
--- Sample code to Create and Apply
Receipts
---------------------------------------------------
DECLARE
p_api_version NUMBER;
p_init_msg_list VARCHAR2 (240);
p_commit VARCHAR2 (240);
p_validation_level NUMBER;
p_usr_currency_code VARCHAR2 (240);
p_usr_exchange_rate_type VARCHAR2 (240);
p_exchange_rate_type VARCHAR2 (240);
p_exchange_rate NUMBER;
p_exchange_rate_date DATE;
p_factor_discount_amount NUMBER;
p_receipt_date DATE;
p_postmark_date DATE;
p_customer_number VARCHAR2 (240);
p_customer_bank_account_id NUMBER;
p_customer_bank_account_num VARCHAR2 (240);
p_customer_bank_account_name VARCHAR2 (240);
p_location VARCHAR2 (240);
p_customer_receipt_reference VARCHAR2 (240);
p_remittance_bank_account_num VARCHAR2 (240);
p_remittance_bank_account_name VARCHAR2 (240);
p_receipt_method_name VARCHAR2 (240);
p_doc_sequence_value NUMBER;
app_ussgl_transaction_code VARCHAR2 (240);
p_anticipated_clearing_date DATE;
p_called_from VARCHAR2 (240);
p_comments VARCHAR2 (240);
p_issuer_name VARCHAR2 (240);
p_issue_date DATE;
p_issuer_bank_branch_id NUMBER;
p_amount NUMBER;
p_receipt_number VARCHAR2 (240);
p_receipt_method_id NUMBER;
p_customer_name VARCHAR2 (240);
p_customer_id NUMBER;
p_currency_code VARCHAR2 (10);
p_gl_date DATE;
p_deposit_date DATE;
p_customer_site_use_id NUMBER;
p_override_remit_account_flag VARCHAR2 (1);
p_remittance_bank_account_id NUMBER;
p_maturity_date DATE;
x_return_status VARCHAR2 (1);
x_msg_count NUMBER;
x_msg_data VARCHAR2 (240);
p_cr_id NUMBER;
p_global_attribute_rec
AR_RECEIPT_API_PUB.global_attribute_rec_type;
p_attribute_rec
AR_RECEIPT_API_PUB.attribute_rec_type;
p_call_payment_processor VARCHAR2
(100);
p_trx_number VARCHAR2 (100);
p_receipt_comments VARCHAR2 (1000);
p_customer_trx_id
ra_customer_trx.customer_trx_id%TYPE;
p_installment
ar_payment_schedules.terms_sequence_number%TYPE;
p_applied_payment_schedule_id
ar_payment_schedules.payment_schedule_id%TYPE;
p_amount_applied
ar_receivable_applications.amount_applied%TYPE;
p_amount_applied_from ar_receivable_applications.amount_applied_from%TYPE;
p_trans_to_receipt_rate
ar_receivable_applications.trans_to_receipt_rate%TYPE;
p_discount
ar_receivable_applications.earned_discount_taken%TYPE;
p_apply_date ar_receivable_applications.apply_date%TYPE;
p_apply_gl_date
ar_receivable_applications.gl_date%TYPE;
p_customer_trx_line_id
ar_receivable_applications.applied_customer_trx_line_id%TYPE;
p_line_number
ra_customer_trx_lines.line_number%TYPE;
p_show_closed_invoices VARCHAR2 (240);
p_move_deferred_tax VARCHAR2 (240);
p_link_to_trx_hist_id
ar_receivable_applications.link_to_trx_hist_id%TYPE;
app_attribute_rec
AR_RECEIPT_API_PUB.attribute_rec_type;
p_ussgl_transaction_code
ar_cash_receipts.ussgl_transaction_code%TYPE;
app_comments ar_receivable_applications.comments%TYPE;
app_global_attribute_rec
AR_RECEIPT_API_PUB.global_attribute_rec_type;
l_user_id NUMBER := fnd_global.user_id;
l_resp_id NUMBER := fnd_profile.VALUE ('RESP_ID');
l_resp_appl_id NUMBER
:= fnd_profile.VALUE
('RESP_APPL_ID');
l_receipt_num VARCHAR2 (30) := '&P_Receipt_Num';
l_customer VARCHAR2 (240) := '&P_Customer';
l_currency VARCHAR2 (10) := '&P_Currency';
l_trx_num VARCHAR2 (30) := '&P_Trx_Num';
l_receipt_method VARCHAR2 (30) := '&P_Receipt_Method';
l_receipt_method_id NUMBER;
BEGIN
fnd_global.apps_initialize (l_user_id, l_resp_id, l_resp_appl_id);
SELECT receipt_method_id
INTO l_receipt_method_id
FROM ar_receipt_methods
WHERE name = l_receipt_method;
p_receipt_number := l_receipt_num;
p_receipt_method_id
:= l_receipt_method_id;
p_amount := 1000;
p_customer_name := l_customer;
p_currency_code := l_currency;
p_receipt_date := SYSDATE;
p_gl_date := SYSDATE;
p_deposit_date := SYSDATE;
p_trx_number := l_trx_num;
p_amount_applied := 400;
p_apply_date := SYSDATE;
AR_RECEIPT_API_PUB.Create_and_apply (
p_api_version => 1.0,
p_init_msg_list => FND_API.G_TRUE,
p_commit => FND_API.G_TRUE,
p_validation_level => FND_API.G_VALID_LEVEL_FULL,
p_usr_currency_code => p_usr_currency_code,
p_currency_code => p_currency_code,
p_usr_exchange_rate_type => p_usr_exchange_rate_type,
p_exchange_rate_type => p_exchange_rate_type,
p_exchange_rate => p_exchange_rate,
p_exchange_rate_date => p_exchange_rate_date,
p_amount => p_amount,
p_factor_discount_amount =>
p_factor_discount_amount,
p_receipt_number => p_receipt_number,
p_receipt_date => p_receipt_date,
p_gl_date => p_gl_date,
p_maturity_date => p_maturity_date,
p_postmark_date => p_postmark_date,
p_customer_id => p_customer_id,
p_customer_name => p_customer_name,
p_customer_number => p_customer_number,
p_customer_bank_account_id => p_customer_bank_account_id,
p_customer_bank_account_num => p_customer_bank_account_num,
p_customer_bank_account_name => p_customer_bank_account_name,
p_location => p_location,
p_customer_site_use_id => p_customer_site_use_id,
p_customer_receipt_reference => p_customer_receipt_reference,
p_override_remit_account_flag => p_override_remit_account_flag,
p_remittance_bank_account_id => p_remittance_bank_account_id,
p_remittance_bank_account_num => p_remittance_bank_account_num,
p_remittance_bank_account_name => p_remittance_bank_account_name,
p_deposit_date => p_deposit_date,
p_receipt_method_id => p_receipt_method_id,
p_receipt_method_name => p_receipt_method_name,
p_doc_sequence_value => p_doc_sequence_value,
p_ussgl_transaction_code => p_ussgl_transaction_code,
p_anticipated_clearing_date => p_anticipated_clearing_date,
p_called_from => p_called_from,
p_attribute_rec => p_attribute_rec,
p_global_attribute_rec =>
p_global_attribute_rec,
p_receipt_comments => p_receipt_comments,
app_comments => app_comments,
p_issuer_name => p_issuer_name,
p_issue_date => p_issue_date,
p_issuer_bank_branch_id => p_issuer_bank_branch_id,
p_customer_trx_id => p_customer_trx_id,
p_trx_number => p_trx_number,
p_installment =>
p_installment,
p_applied_payment_schedule_id => p_applied_payment_schedule_id,
p_amount_applied => p_amount_applied,
p_amount_applied_from => p_amount_applied_from,
p_trans_to_receipt_rate =>
p_trans_to_receipt_rate,
p_discount => p_discount,
p_apply_date => p_apply_date,
p_apply_gl_date => p_apply_gl_date,
app_ussgl_transaction_code => app_ussgl_transaction_code,
p_customer_trx_line_id => p_customer_trx_line_id,
p_line_number => p_line_number,
p_show_closed_invoices => p_show_closed_invoices,
p_move_deferred_tax => p_move_deferred_tax,
p_link_to_trx_hist_id => p_link_to_trx_hist_id,
app_attribute_rec => app_attribute_rec,
x_return_status => x_return_status,
x_msg_count => x_msg_count,
x_msg_data => x_msg_data,
p_cr_id => p_cr_id,
p_call_payment_processor => FND_API.G_FALSE,
app_global_attribute_rec => app_global_attribute_rec);
IF (x_return_status = 'S')
THEN
COMMIT;
DBMS_OUTPUT.put_line
('SUCCESS');
DBMS_OUTPUT.put_line
(
'Return Status = ' || SUBSTR (x_return_status, 1, 255));
DBMS_OUTPUT.put_line
('Message Count = ' || x_msg_count);
DBMS_OUTPUT.put_line
('Message Data = ' || x_msg_data);
DBMS_OUTPUT.put_line
('p_cr_id = ' || p_cr_id);
ELSE
ROLLBACK;
DBMS_OUTPUT.put_line
(
'Return Status = ' || SUBSTR (x_return_status, 1, 255));
DBMS_OUTPUT.put_line
('Message Count = ' || TO_CHAR (x_msg_count));
DBMS_OUTPUT.put_line
(
'Message Data = ' || SUBSTR (x_msg_data, 1, 255));
DBMS_OUTPUT.put_line
(
APPS.FND_MSG_PUB.Get (p_msg_index => APPS.FND_MSG_PUB.G_LAST,
p_encoded =>
APPS.FND_API.G_FALSE));
IF x_msg_count >=
0
THEN
FOR I IN 1 .. 10
LOOP
DBMS_OUTPUT.put_line
(
I || '. '
|| SUBSTR (FND_MSG_PUB.Get (p_encoded => FND_API.G_FALSE),
1,
255));
END LOOP;
END IF;
END IF;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line
('Exception :' || SQLERRM);
END;