Professional Documents
Culture Documents
-------------------------------------*/--
/*-----------------------------------------------------
-- Cursor for UnApplied Receipts --
-----------------------------------------------------*/
CURSOR c_receipt(p_period_end_date date) IS
SELECT acra.cash_receipt_id cash_receipt_id,
acra.pay_from_customer customer_id,
acra.org_id org_id,
acra.receipt_date receipt_date,
acra.receipt_number receipt_number,
araa.gl_date gl_date,
acra.amount amount
FROM ar_cash_receipts_all acra,ar_cash_receipt_history_all acrha,
(SELECT DISTINCT saraa.cash_receipt_id, saraa.gl_date
FROM ar_receivable_applications_all saraa
WHERE saraa.creation_date =
(SELECT MIN(ssaraa.creation_date)
FROM ar_receivable_applications_all ssaraa
WHERE ssaraa.cash_receipt_id = saraa.cash_receipt_id)) araa
WHERE
-- Table Joins :
acra.cash_receipt_id = araa.cash_receipt_id
AND acra.CASH_RECEIPT_ID = acrha.CASH_RECEIPT_ID
AND araa.CASH_RECEIPT_ID = acrha.CASH_RECEIPT_ID
-- Parameters :
AND acra.org_id = NVL(p_org_id, acra.org_id) --* ORG
AND TO_CHAR(acra.pay_from_customer) =
NVL(p_cust_id, acra.pay_from_customer)
--* Customer
--AND TO_CHAR(araa.gl_date, 'yyyy/mm/dd') || ' 00:00:00' <=v_period_end_date
AND Trunc(araa.gl_date) <=p_period_end_date
--* GL Date
-- Conditions :
-- AND acra.AMOUNT <> 0 --* Should have some amount
AND acra.status = 'UNAPP' --* Should be unapplied
AND acrha.STATUS = 'CLEARED'
and acra.PAY_FROM_CUSTOMER in
(select hca.CUST_ACCOUNT_ID
from hz_parties hp, Hz_Cust_Accounts hca
where hca.PARTY_ID = hp.PARTY_ID
and hp.attribute6 = nvl(p_cust_type, hp.ATTRIBUTE6))
ORDER BY araa.gl_date;
-- order by apsa.gl_date ;
-- Record of C_TRX cursor row type to hold c_trx fetches
r_trx c_trx%ROWTYPE;
---------------------------------------------------- C-TRX ----*/
/****************************************
* *
* STARTING *
* *
****************************************/
BEGIN
fnd_global.apps_initialize(1010, p_resp_id, 222);
arp_standard.enable_debug;
--* writing output headings :
fnd_file.put_line(fnd_file.output, ' ');
fnd_file.put_line(fnd_file.output,
' Customized - Invoice - Receipts Knocking Off Program ');
fnd_file.put_line(fnd_file.output,
'-------------------------------------------------------------------- ');
fnd_file.put_line(fnd_file.output, ' ');
fnd_file.put_line(fnd_file.output, ' p_org_id : ' || p_org_id);
fnd_file.put_line(fnd_file.output, ' p_cust_id : ' || p_cust_id);
fnd_file.put_line(fnd_file.output, ' p_period : ' || p_period);
fnd_file.put_line(fnd_file.output, ' p_resp_id : ' || p_resp_id);
fnd_file.put_line(fnd_file.output, ' ');
fnd_file.put_line(fnd_file.output,
' ================ ========== ========== ============
============ =============== ========== ============ ============ ==========
============ ==========');
fnd_file.put_line(fnd_file.output,
' Customer # Receipt # Rec GLDate Receipt Amt Avl Rec
Amt Transaction # Trx GLDate TRX Line Amt Avl.Line Amt Appl.Date Applied Amt
Status ');
fnd_file.put_line(fnd_file.output,
' ================ ========== ========== ============
============ =============== ========== ============ ============ ==========
============ ==========');
-----------------------------------------------------------------------------------
-
-- Receipt Loop
--
-----------------------------------------------------------------------------------
-
FOR r_receipt IN c_receipt(v_period_end_date) LOOP
--* If receipt date lies in next period or later, write error in log, and dont
apply this receipt
IF r_receipt.receipt_date >
-- TO_DATE(v_period_end_date, 'yyyy/mm/dd hh24:mi:ss')
v_period_end_date
THEN
fnd_file.put_line(fnd_file.LOG, ' ');
fnd_file.put_line(fnd_file.LOG,
'Receipt No.:' || r_receipt.receipt_number);
fnd_file.put_line(fnd_file.LOG,
' Error : Receipt Date does not lie in ' ||
p_period);
ELSE
--* other wise proceed with applying the receipt
--* getting customer number from customer id
SELECT ac.customer_number
INTO v_customer_no
FROM ar_customers ac
WHERE ac.customer_id = r_receipt.customer_id;
-------------------------------------------------------------------------------
-- TRX Loop
--
-------------------------------------------------------------------------------
FOR r_trx IN c_trx(r_receipt.org_id,
r_receipt.customer_id,
v_period_end_date) LOOP
-- * application date = later of REC_GL_date, TRX_GL_Date
-----**commented on 03-APRIL-2017**----
IF r_receipt.gl_date > r_trx.gl_date THEN
v_apply_date := trunc(sysdate);--r_receipt.gl_date;
ELSE
v_apply_date := trunc(sysdate);--r_trx.gl_date;
END IF;
-----**commented on 03-APRIL-2017**----
-----------------------------------------------
-- Applied amt calculation --
-----------------------------------------------
v_amt_applied := r_trx.line_due_amount;
--* due amount is applied amount
--* move to next receipt if receipt should have run out of unapplied amout
IF 0 = v_rec_avl_amt THEN
EXIT;
END IF;
--/*----------------------------------------------------------------------------
-- API Call to APPLY
--
--------------------------------------------------------------------------------
IF v_currency_code = 'PKR' THEN
------------------------------------------------------------------------------
------- FOR PKR
------------------------------------------------------------------------------
ar_receipt_api_pub.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,
-----------------User computed variables
p_org_id => r_trx.org_id,
p_cash_receipt_id => r_receipt.cash_receipt_id,
p_customer_trx_id => r_trx.customer_trx_id,
p_amount_applied => v_amt_applied,
----p_trans_to_receipt_rate => v_exhange_rate,
commented on 03 Oct 13
p_apply_date =>v_period_end_date,--
v_apply_date,
p_apply_gl_date =>v_period_end_date,--
v_apply_date,
------------------ message variables
x_return_status => l_return_status,
x_msg_count => l_msg_count,
x_msg_data => l_msg_data);
ELSE
-----------------------------------------------------------------------
--------------- For Other than PKR
-----------------------------------------------------------------------
ar_receipt_api_pub.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,
-----------------User computed variables
--p_org_id => r_trx.org_id,
p_cash_receipt_id =>
r_receipt.cash_receipt_id,
p_customer_trx_id =>
r_trx.customer_trx_id,
p_amount_applied => v_amt_applied,
p_trans_to_receipt_rate => v_exhange_rate,
p_apply_date => v_period_end_date,--
v_apply_date,
p_apply_gl_date => v_period_end_date,--
v_apply_date,
------------------ message variables
x_return_status => l_return_status,
x_msg_count => l_msg_count,
x_msg_data => l_msg_data);
END IF;
--------------------------------------------------------------
-- API Error Logging --
--------------------------------------------------------------
IF l_return_status != 'S' THEN
fnd_file.put_line(fnd_file.LOG, ' ');
fnd_file.put_line(fnd_file.LOG,
'Receipt No.: ' || r_receipt.receipt_number ||
' TRX No.: ' || r_trx.trx_number || ' Status: ' ||
l_return_status);
fnd_file.put_line(fnd_file.LOG,
' ' || ' r_trx.org_id: ' || r_trx.org_id ||
' r_receipt.cash_receipt_id: ' ||
r_receipt.cash_receipt_id ||
' r_trx.customer_trx_id: ' ||
r_trx.customer_trx_id || ' v_amt_applied: ' ||
v_amt_applied || ' v_apply_date: ' ||
v_period_end_date);
IF l_msg_count = 1 THEN
fnd_file.put_line(fnd_file.LOG,
' Message : ' || l_msg_data);
ELSIF l_msg_count > 1 THEN
LOOP
p_count := p_count + 1;
l_msg_data := fnd_msg_pub.get(fnd_msg_pub.g_next,
fnd_api.g_false);
fnd_file.put_line(fnd_file.LOG,
' Message ' || p_count || ' : ' ||
l_msg_data);
END LOOP;
END IF;
END IF;
---------------------------------------------------------------------------/*---
--* writing application to output file --
fnd_file.put_line(fnd_file.output,
' ' ||
-- values
RPAD(NVL(v_customer_no, ' '), 17) ||
RPAD(NVL(r_receipt.receipt_number, ' '), 11) ||
RPAD(r_receipt.gl_date, 11) ||
RPAD(NVL(r_receipt.amount, -1), 13) ||
RPAD(NVL(v_rec_avl_amt, -1), 13) ||
RPAD(NVL(r_trx.trx_number, ' '), 16) ||
RPAD(r_trx.gl_date, 11) ||
RPAD(NVL(r_trx.line_amount, -1), 13) ||
RPAD(NVL(r_trx.line_due_amount, -1), 13) ||
RPAD(v_period_end_date, 11) ||
RPAD(NVL(v_amt_applied, -1), 13) ||
RPAD(NVL(l_return_status, ' '), 11));
-- output written ------------------*/--
END LOOP; -- trx loop
END IF; -- skipping receipt later than period end date IF
END LOOP; -- receipt loop
arp_standard.disable_debug;
END;
/