247: p_receipt_number IN ar_cash_receipts.receipt_number%type,
248: p_receivable_trx_id IN VARCHAR2,
249: p_apply_date IN VARCHAR2,
250: p_gl_date IN VARCHAR2,
251: p_comments IN ar_receivable_applications.comments%type
252: ) IS
253:
254: --Declare Local Variables
255: l_msg_count NUMBER;
255: l_msg_count NUMBER;
256: l_msg_data VARCHAR2(240);
257: l_return_status VARCHAR2(1);
258:
259: l_unapp_amount ar_receivable_applications.amount_applied%type;
260: l_unapp_amount_percent NUMBER;
261: l_receipt_date_from ar_cash_receipts.receipt_date%type;
262: l_receipt_date_to ar_cash_receipts.receipt_date%type;
263: l_receipt_gl_date_from ar_receivable_applications.gl_date%type;
259: l_unapp_amount ar_receivable_applications.amount_applied%type;
260: l_unapp_amount_percent NUMBER;
261: l_receipt_date_from ar_cash_receipts.receipt_date%type;
262: l_receipt_date_to ar_cash_receipts.receipt_date%type;
263: l_receipt_gl_date_from ar_receivable_applications.gl_date%type;
264: l_receipt_gl_date_to ar_receivable_applications.gl_date%type;
265: l_receipt_method_id ar_cash_receipts.receipt_method_id%type;
266:
267: -- Bug 1981698 Changed the definition for l_customer_number.
260: l_unapp_amount_percent NUMBER;
261: l_receipt_date_from ar_cash_receipts.receipt_date%type;
262: l_receipt_date_to ar_cash_receipts.receipt_date%type;
263: l_receipt_gl_date_from ar_receivable_applications.gl_date%type;
264: l_receipt_gl_date_to ar_receivable_applications.gl_date%type;
265: l_receipt_method_id ar_cash_receipts.receipt_method_id%type;
266:
267: -- Bug 1981698 Changed the definition for l_customer_number.
268:
267: -- Bug 1981698 Changed the definition for l_customer_number.
268:
269: l_customer_number hz_cust_accounts.account_number%type;
270: l_customer_id hz_cust_accounts.cust_account_id%type;
271: l_receivable_trx_id ar_receivable_applications.receivables_trx_id%type;
272: l_apply_date ar_cash_receipts.receipt_date%type;
273: l_gl_date ar_cash_receipts.receipt_date%type;
274: l_receipt_currency_code ar_cash_receipts.currency_code%type;
275: l_receipt_number ar_cash_receipts.receipt_number%type;
272: l_apply_date ar_cash_receipts.receipt_date%type;
273: l_gl_date ar_cash_receipts.receipt_date%type;
274: l_receipt_currency_code ar_cash_receipts.currency_code%type;
275: l_receipt_number ar_cash_receipts.receipt_number%type;
276: l_comments ar_receivable_applications.comments%type;
277: l_user_id NUMBER;
278: l_application_ref_type ar_receivable_applications.application_ref_type%TYPE;
279: l_application_ref_id ar_receivable_applications.application_ref_id%TYPE;
280: l_application_ref_num ar_receivable_applications.application_ref_num%TYPE;
274: l_receipt_currency_code ar_cash_receipts.currency_code%type;
275: l_receipt_number ar_cash_receipts.receipt_number%type;
276: l_comments ar_receivable_applications.comments%type;
277: l_user_id NUMBER;
278: l_application_ref_type ar_receivable_applications.application_ref_type%TYPE;
279: l_application_ref_id ar_receivable_applications.application_ref_id%TYPE;
280: l_application_ref_num ar_receivable_applications.application_ref_num%TYPE;
281: l_secondary_application_ref_id ar_receivable_applications.secondary_application_ref_id%TYPE;
282: l_receivable_application_id NUMBER;
275: l_receipt_number ar_cash_receipts.receipt_number%type;
276: l_comments ar_receivable_applications.comments%type;
277: l_user_id NUMBER;
278: l_application_ref_type ar_receivable_applications.application_ref_type%TYPE;
279: l_application_ref_id ar_receivable_applications.application_ref_id%TYPE;
280: l_application_ref_num ar_receivable_applications.application_ref_num%TYPE;
281: l_secondary_application_ref_id ar_receivable_applications.secondary_application_ref_id%TYPE;
282: l_receivable_application_id NUMBER;
283:
276: l_comments ar_receivable_applications.comments%type;
277: l_user_id NUMBER;
278: l_application_ref_type ar_receivable_applications.application_ref_type%TYPE;
279: l_application_ref_id ar_receivable_applications.application_ref_id%TYPE;
280: l_application_ref_num ar_receivable_applications.application_ref_num%TYPE;
281: l_secondary_application_ref_id ar_receivable_applications.secondary_application_ref_id%TYPE;
282: l_receivable_application_id NUMBER;
283:
284: l_unapp_amount_balance NUMBER := 0;
277: l_user_id NUMBER;
278: l_application_ref_type ar_receivable_applications.application_ref_type%TYPE;
279: l_application_ref_id ar_receivable_applications.application_ref_id%TYPE;
280: l_application_ref_num ar_receivable_applications.application_ref_num%TYPE;
281: l_secondary_application_ref_id ar_receivable_applications.secondary_application_ref_id%TYPE;
282: l_receivable_application_id NUMBER;
283:
284: l_unapp_amount_balance NUMBER := 0;
285: l_written_off_amount ar_receivable_applications.amount_applied%TYPE;
281: l_secondary_application_ref_id ar_receivable_applications.secondary_application_ref_id%TYPE;
282: l_receivable_application_id NUMBER;
283:
284: l_unapp_amount_balance NUMBER := 0;
285: l_written_off_amount ar_receivable_applications.amount_applied%TYPE;
286: l_tot_write_off_amount ar_receivable_applications.amount_applied%TYPE;
287: l_min_wrt_off_amount ar_receivable_applications.amount_applied%TYPE;
288: l_max_wrt_off_amount ar_receivable_applications.amount_applied%TYPE;
289: l_tot_writeoff_amt_func ar_receivable_applications.amount_applied%TYPE;
282: l_receivable_application_id NUMBER;
283:
284: l_unapp_amount_balance NUMBER := 0;
285: l_written_off_amount ar_receivable_applications.amount_applied%TYPE;
286: l_tot_write_off_amount ar_receivable_applications.amount_applied%TYPE;
287: l_min_wrt_off_amount ar_receivable_applications.amount_applied%TYPE;
288: l_max_wrt_off_amount ar_receivable_applications.amount_applied%TYPE;
289: l_tot_writeoff_amt_func ar_receivable_applications.amount_applied%TYPE;
290: l_exchange_rate ar_cash_receipts.exchange_rate%TYPE;
283:
284: l_unapp_amount_balance NUMBER := 0;
285: l_written_off_amount ar_receivable_applications.amount_applied%TYPE;
286: l_tot_write_off_amount ar_receivable_applications.amount_applied%TYPE;
287: l_min_wrt_off_amount ar_receivable_applications.amount_applied%TYPE;
288: l_max_wrt_off_amount ar_receivable_applications.amount_applied%TYPE;
289: l_tot_writeoff_amt_func ar_receivable_applications.amount_applied%TYPE;
290: l_exchange_rate ar_cash_receipts.exchange_rate%TYPE;
291: l_actual_writeoff_amount NUMBER := 0;
284: l_unapp_amount_balance NUMBER := 0;
285: l_written_off_amount ar_receivable_applications.amount_applied%TYPE;
286: l_tot_write_off_amount ar_receivable_applications.amount_applied%TYPE;
287: l_min_wrt_off_amount ar_receivable_applications.amount_applied%TYPE;
288: l_max_wrt_off_amount ar_receivable_applications.amount_applied%TYPE;
289: l_tot_writeoff_amt_func ar_receivable_applications.amount_applied%TYPE;
290: l_exchange_rate ar_cash_receipts.exchange_rate%TYPE;
291: l_actual_writeoff_amount NUMBER := 0;
292: l_rcpt_percent_amount NUMBER;
285: l_written_off_amount ar_receivable_applications.amount_applied%TYPE;
286: l_tot_write_off_amount ar_receivable_applications.amount_applied%TYPE;
287: l_min_wrt_off_amount ar_receivable_applications.amount_applied%TYPE;
288: l_max_wrt_off_amount ar_receivable_applications.amount_applied%TYPE;
289: l_tot_writeoff_amt_func ar_receivable_applications.amount_applied%TYPE;
290: l_exchange_rate ar_cash_receipts.exchange_rate%TYPE;
291: l_actual_writeoff_amount NUMBER := 0;
292: l_rcpt_percent_amount NUMBER;
293:
305: --Declare Cursor
306: CURSOR writeoff_cur(c_receipt_currency_code ar_cash_receipts.currency_code%type,
307: c_receipt_date_from ar_cash_receipts.receipt_date%type,
308: c_receipt_date_to ar_cash_receipts.receipt_date%type,
309: c_receipt_gl_date_from ar_receivable_applications.gl_date%type,
310: c_receipt_gl_date_to ar_receivable_applications.gl_date%type,
311: c_receipt_method_id ar_cash_receipts.receipt_method_id%type,
312: --Bug 1981698 Changed c_customer_number to c_customer_id.
313: c_customer_id ar_cash_receipts.pay_from_customer%type,
306: CURSOR writeoff_cur(c_receipt_currency_code ar_cash_receipts.currency_code%type,
307: c_receipt_date_from ar_cash_receipts.receipt_date%type,
308: c_receipt_date_to ar_cash_receipts.receipt_date%type,
309: c_receipt_gl_date_from ar_receivable_applications.gl_date%type,
310: c_receipt_gl_date_to ar_receivable_applications.gl_date%type,
311: c_receipt_method_id ar_cash_receipts.receipt_method_id%type,
312: --Bug 1981698 Changed c_customer_number to c_customer_id.
313: c_customer_id ar_cash_receipts.pay_from_customer%type,
314: c_receipt_number ar_cash_receipts.receipt_number%type,
313: c_customer_id ar_cash_receipts.pay_from_customer%type,
314: c_receipt_number ar_cash_receipts.receipt_number%type,
315: c_apply_date ar_cash_receipts.receipt_date%type,
316: c_gl_date ar_cash_receipts.receipt_date%type,
317: c_user_id ar_receivable_applications.created_by%Type
318: ) IS
319:
320: /*5444407*/
321: SELECT acr.cash_receipt_id cash_receipt_id,
329: crh.batch_id batch_id,acr.org_id
330: FROM ar_payment_schedules ps,
331: ar_cash_receipts acr,
332: ar_cash_receipt_history crh,
333: ar_receivable_applications app
334: WHERE ps.invoice_currency_code = c_receipt_currency_code
335: AND acr.cash_receipt_id = ps.cash_receipt_id
336: AND acr.cash_receipt_id = crh.cash_receipt_id
337: AND crh.current_record_flag = 'Y'
688: p_amount_to IN NUMBER default null)
689: RETURN number IS
690:
691: l_unapp_amount_balance NUMBER := 0;
692: l_written_off_amount ar_receivable_applications.amount_applied%TYPE;
693: l_tot_write_off_amount ar_receivable_applications.amount_applied%TYPE;
694: l_max_wrt_off_amount ar_receivable_applications.amount_applied%TYPE;
695: l_tot_writeoff_amt_func ar_receivable_applications.amount_applied%TYPE;
696: l_exchange_rate ar_cash_receipts.exchange_rate%TYPE;
689: RETURN number IS
690:
691: l_unapp_amount_balance NUMBER := 0;
692: l_written_off_amount ar_receivable_applications.amount_applied%TYPE;
693: l_tot_write_off_amount ar_receivable_applications.amount_applied%TYPE;
694: l_max_wrt_off_amount ar_receivable_applications.amount_applied%TYPE;
695: l_tot_writeoff_amt_func ar_receivable_applications.amount_applied%TYPE;
696: l_exchange_rate ar_cash_receipts.exchange_rate%TYPE;
697:
690:
691: l_unapp_amount_balance NUMBER := 0;
692: l_written_off_amount ar_receivable_applications.amount_applied%TYPE;
693: l_tot_write_off_amount ar_receivable_applications.amount_applied%TYPE;
694: l_max_wrt_off_amount ar_receivable_applications.amount_applied%TYPE;
695: l_tot_writeoff_amt_func ar_receivable_applications.amount_applied%TYPE;
696: l_exchange_rate ar_cash_receipts.exchange_rate%TYPE;
697:
698: l_amount_to NUMBER;
691: l_unapp_amount_balance NUMBER := 0;
692: l_written_off_amount ar_receivable_applications.amount_applied%TYPE;
693: l_tot_write_off_amount ar_receivable_applications.amount_applied%TYPE;
694: l_max_wrt_off_amount ar_receivable_applications.amount_applied%TYPE;
695: l_tot_writeoff_amt_func ar_receivable_applications.amount_applied%TYPE;
696: l_exchange_rate ar_cash_receipts.exchange_rate%TYPE;
697:
698: l_amount_to NUMBER;
699: l_amount_from NUMBER;
708: SELECT SUM(DECODE(ra.status,'UNAPP',NVL(ra.amount_applied, 0),0)) unapplied_amount,
709: SUM(decode(ra.status,'ACTIVITY',decode(ra.applied_payment_schedule_id,-3,
710: decode(ra.created_by,p_user_id,NVL(ra.amount_applied,0),0),0),0)) written_off_amount
711: INTO l_unapp_amount_balance,l_written_off_amount
712: FROM ar_receivable_applications ra
713: WHERE ra.cash_receipt_id = p_cash_receipt_id
714: AND ra.status in ('UNAPP','ACTIVITY');
715:
716: --Check how much amount has been written-off by this user for this receipt
717: /* Bug 2479793 : The index on applied_payment_schedule_id is supressed as
718: CBO sometimes find this better than index on cash_receipt_id */
719: /*SELECT NVL(SUM(NVL(ra.amount_applied, 0)),0) written_off_amount
720: INTO l_written_off_amount
721: FROM ar_receivable_applications ra
722: WHERE ra.cash_receipt_id = p_cash_receipt_id
723: AND ra.status = 'ACTIVITY'
724: AND ra.applied_payment_schedule_id + 0 = -3
725: AND ra.created_by = p_user_id;*/
794:
795: ELSE
796: SELECT NVL(SUM(NVL(ra.amount_applied,0)),10) l_unapplied_amount
797: INTO l_unapp_amount_balance
798: FROM ar_receivable_applications ra
799: WHERE ra.cash_receipt_id = p_cash_receipt_id
800: AND status = 'ACTIVITY'
801: AND ra.request_id = p_request_id;
802:
865: ,0)) applied_amount
866:
867: INTO l_applied_amount
868: FROM
869: ar_receivable_applications ra
870: WHERE ra.cash_receipt_id = p_cash_receipt_id
871: AND ra.request_id <> p_request_id;
872: ELSE
873: --Sum of the all the applied amounts for a receipt
884: ,0)) applied_amount
885:
886: INTO l_applied_amount
887: FROM
888: ar_receivable_applications ra
889: WHERE ra.cash_receipt_id = p_cash_receipt_id;
890: END IF;
891:
892: arp_util.debug('arp_process_writeoff.applied_amount()-');
936: SUM(DECODE(ra.status,'ACC', NVL(ra.amount_applied, 0),
937: 0)) on_account_amount
938: INTO l_on_account_amount
939: FROM
940: ar_receivable_applications ra
941: WHERE ra.cash_receipt_id = p_cash_receipt_id;
942:
943: arp_util.debug('arp_process_writeoff.on_account_amount()-');
944: