1 PACKAGE BODY ARP_BR_REMIT_FUNCTION AS
2 /* $Header: ARBRRMFB.pls 115.8 2003/10/10 14:23:01 mraymond ship $*/
3
4 PG_DEBUG varchar2(1) := NVL(FND_PROFILE.value('AFLOG_ENABLED'), 'N');
5
6 FUNCTION GET_AMOUNT (p_trh_id IN ar_transaction_history.transaction_history_id%TYPE,
7 p_status IN ar_transaction_history.status%TYPE,
8 p_customer_trx_id IN ra_customer_trx.customer_trx_id%TYPE) RETURN NUMBER IS
9
10 l_field varchar2(30);
11 l_amount NUMBER;
12
13 CURSOR dist_amount(p2_status IN ar_distributions.source_type%TYPE) is
14 select amount_dr
15 from ar_distributions
16 where source_id=p_trh_id
17 and source_table='TH'
18 and source_type=p2_status;
19
20 CURSOR app_amount is
21 select amount_applied
22 from ar_receivable_applications
23 where applied_customer_trx_id=p_customer_trx_id
24 and status='APP'
25 and link_to_trx_hist_id=p_trh_id;
26
27 BEGIN
28
29 IF (p_status='REMITTED') THEN
30 OPEN dist_amount('REMITTANCE');
31 FETCH dist_amount INTO l_amount;
32 CLOSE dist_amount;
33 ELSIF (p_status='FACTORED') THEN
34 OPEN dist_amount('FACTOR');
35 FETCH dist_amount INTO l_amount;
36 CLOSE dist_amount;
37 ELSIF (p_status='CLOSED') THEN
38 OPEN app_amount;
39 FETCH app_amount INTO l_amount;
40 CLOSE app_amount;
41 ELSE
42 l_field := 'P_STATUS';
43 FND_MESSAGE.set_name('AR','AR_PROCEDURE_VALID_ARGS_FAIL');
44 FND_MESSAGE.set_token('PROCEDURE','GET_AMOUNT');
45 FND_MESSAGE.set_token('PARAMETER', l_field);
46 APP_EXCEPTION.raise_exception;
47 END IF;
48
49 RETURN l_amount;
50
51 EXCEPTION
52 WHEN OTHERS then
53 IF PG_DEBUG in ('Y', 'C') THEN
54 arp_util.debug('EXCEPTION OTHERS: ARP_BR_REMIT_FUNCTION.GET_AMOUNT');
55 END IF;
56
57 IF dist_amount%ISOPEN THEN
58 CLOSE dist_amount;
59 END IF;
60
61 IF app_amount%ISOPEN THEN
62 CLOSE app_amount;
63 END IF;
64
65 RAISE;
66
67 END GET_AMOUNT;
68
69
70
71 FUNCTION GET_ACCTD_AMOUNT (p_trh_id IN ar_transaction_history.transaction_history_id%TYPE,
72 p_status IN ar_transaction_history.status%TYPE,
73 p_customer_trx_id IN ra_customer_trx.customer_trx_id%TYPE) RETURN NUMBER IS
74
75 l_field varchar2(30);
76 l_amount NUMBER;
77
78 CURSOR dist_amount(p2_status IN ar_distributions.source_type%TYPE) is
79 select acctd_amount_dr
80 from ar_distributions
81 where source_id=p_trh_id
82 and source_table='TH'
83 and source_type=p2_status;
84
85 CURSOR app_amount is
86 select amount_applied_from
87 from ar_receivable_applications
88 where applied_customer_trx_id=p_customer_trx_id
89 and status='APP'
90 and link_to_trx_hist_id=p_trh_id;
91
92 BEGIN
93
94 IF (p_status='REMITTED') THEN
95 OPEN dist_amount('REMITTANCE');
96 FETCH dist_amount INTO l_amount;
97 CLOSE dist_amount;
98 ELSIF (p_status='FACTORED') THEN
99 OPEN dist_amount('FACTOR');
100 FETCH dist_amount INTO l_amount;
101 CLOSE dist_amount;
102 ELSIF (p_status='CLOSED') THEN
103 OPEN app_amount;
104 FETCH app_amount INTO l_amount;
105 CLOSE app_amount;
106 ELSE
107 l_field := 'P_STATUS';
108 FND_MESSAGE.set_name('AR','AR_PROCEDURE_VALID_ARGS_FAIL');
109 FND_MESSAGE.set_token('PROCEDURE','GET_ACCTD_AMOUNT');
110 FND_MESSAGE.set_token('PARAMETER', l_field);
111 APP_EXCEPTION.raise_exception;
112 END IF;
113
114 RETURN l_amount;
115
116 EXCEPTION
117 WHEN OTHERS then
118 IF PG_DEBUG in ('Y', 'C') THEN
119 arp_util.debug('EXCEPTION OTHERS: ARP_BR_REMIT_FUNCTION.GET_ACCTD_AMOUNT');
120 END IF;
121
122 IF dist_amount%ISOPEN THEN
123 CLOSE dist_amount;
124 END IF;
125
126 IF app_amount%ISOPEN THEN
127 CLOSE app_amount;
128 END IF;
129
130 RAISE;
131
132 END GET_ACCTD_AMOUNT;
133
134 /*===========================================================================+
135 | FUNCTION |
136 | revision |
137 | |
138 | DESCRIPTION |
139 | This function returns the revision number of this package. |
140 | |
141 | SCOPE - PUBLIC |
142 | |
143 | RETURNS : Revision number of this package |
144 | |
145 | MODIFICATION HISTORY |
146 | 10 JAN 2001 John HALL Created |
147 +===========================================================================*/
148 FUNCTION revision RETURN VARCHAR2 IS
149 BEGIN
150 RETURN '$Revision: 115.8 $';
151 END revision;
152 --
153
154
155
156 END ARP_BR_REMIT_FUNCTION;
157 --