DBA Data[Home] [Help]

PACKAGE BODY: APPS.PA_AR_ADV_RECEIPT

Source


1 PACKAGE BODY PA_AR_ADV_RECEIPT AS
2 --$Header: PAGARADB.pls 120.4 2006/12/20 09:15:06 rkchoudh noship $
3 
4 
5 PROCEDURE 	Apply_receipt(
6 			   p_receipt_id         IN     NUMBER,
7                            p_gl_date            IN     DATE,
8                            p_agreement_id       IN     NUMBER,
9                            p_agreement_number   IN     VARCHAR2,
10                            x_payment_set_id     IN OUT NOCOPY   NUMBER,
11                            x_return_status      IN OUT NOCOPY   VARCHAR2,
12                            x_msg_count          IN OUT NOCOPY   NUMBER,
13                            x_msg_data           IN OUT NOCOPY   VARCHAR2 ) is
14 CURSOR APPLY_cur IS
15  select app.amount_applied,
16         app.receivable_application_id
17    from ar_receivable_applications app
18   where app.cash_receipt_id = p_receipt_id
19     and app.STATUS ='ACC'
20     and app.display='Y';
21 l_api_version     		NUMBER := 1.0;
22 l_applied_payment_schedule_id   NUMBER := -7;
23 l_payment_set_id 		NUMBER;
24 l_receivable_application_id     NUMBER(15);
25 l_amount_applied                NUMBER;
26 l_receivable_trx_id 	  	NUMBER(15);
27 l_application_ref_type          VARCHAR2(30):= 'PROJECTS AGREEMENT';
28 l_application_ref_id    	NUMBER(15)  := p_agreement_id;
29 l_application_ref_num  		VARCHAR2(30):= p_agreement_number;
30 l_secondary_application_ref_id	NUMBER(15);
31 l_rec_apps_id     		NUMBER(15) ;
32 l_return_status   		VARCHAR2(30);
33 l_msg_count       		NUMBER;
34 l_msg_data        		VARCHAR2(30);
35 l_position                      VARCHAR2(2);
36 AP_ERROR 			exception;
37 
38 BEGIN
39 
40 l_return_status := 'S';
41 l_msg_count     := NULL;
42 l_msg_data      := NULL;
43 
44 l_position := '1';
45 ar_receipt_lib_pvt.default_prepay_cc_activity(p_appl_type         => 'PREPAYMENT',
46                                               p_receivable_trx_id => l_receivable_trx_id,
47                                               p_return_status     => l_return_status);
48 IF l_return_status <> 'S' then
49        l_msg_data := 'PA_RECV_ACTY_CHECK';
50        l_msg_count:= 1;
51        RAISE AP_ERROR;
52 END IF;
53 
54 l_position := '2';
55 IF x_payment_set_id is null then
56     select ar_receivable_applications_s1.nextval into l_payment_set_id  from dual;
57 ELSE
58     l_payment_set_id := x_payment_set_id;
59 END IF;
60 
61 l_position := '3';
62 FOR i in APPLY_cur
63     loop
64       l_receivable_application_id := i.receivable_application_id;
65       l_amount_applied  := i.amount_applied;
66 
67 l_position := '4';
68      -- Calling the AR package to Unapply the on account ammount
69       	ar_receipt_api_pub.unapply_on_account(P_API_VERSION     	  => l_api_version,
70     	                                      p_cash_receipt_id 	  => p_receipt_id,
71 					      p_receivable_application_id => l_receivable_application_id,
72 					      p_reversal_gl_date	  => p_gl_date,
73 					      X_return_status 		  => l_return_status,
74 					      X_msg_count       	  => l_msg_count,
75 					      X_msg_data        	  => l_msg_data
76 					      );
77 	IF l_return_status <> 'S' then
78 	   RAISE AP_ERROR;
79         END IF;
80 
81 l_position := '5';
82      -- Calling AR package to apply the Amount to prepayment
83 	ar_receipt_api_pub.apply_other_account(P_API_VERSION  		      => l_api_version,
84         	                               p_cash_receipt_id 	      => p_receipt_id,
85 					       p_receivable_application_id    => l_receivable_application_id,
86 					       X_return_status   	      => l_return_status,
87 				               X_msg_count       	      => l_msg_count,
88 					       X_msg_data   		      => l_msg_data,
89 					       P_APPLIED_PAYMENT_SCHEDULE_ID  => l_applied_payment_schedule_id,
90 --                                               P_APPLICATION_REF_TYPE         => l_application_ref_type,
91 					       P_APPLICATION_REF_ID 	      => l_application_ref_id,
92 					       P_application_ref_num          => l_application_ref_num,
93 					       P_secondary_application_ref_id => l_secondary_application_ref_id,
94 			                       P_payment_set_id 	      => l_payment_set_id,
95 					       P_RECEIVABLES_TRX_ID 	      => l_receivable_trx_id,
96 					       P_AMOUNT_APPLIED               => l_amount_applied
97 					      );
98 	IF l_return_status <> 'S' then
99                 RAISE AP_ERROR;
100 	END IF;
101 
102        exit when APPLY_cur%notfound;
103    end loop;
104 
105 l_position := '6';
106  x_payment_set_id := l_payment_set_id;
107 
108 -- HANDLE EXCEPTIONS
109    EXCEPTION
110         WHEN AP_ERROR THEN
111              x_return_status   := l_return_status;
112              x_msg_count       := l_msg_count;
113              x_msg_data        := l_msg_data;
114         WHEN OTHERS THEN
115              RAISE;
116 
117 END Apply_receipt;
118 
119 PROCEDURE    Unapply_receipt(
120                            p_receipt_id         IN     NUMBER,
121 			   p_payment_set_id     IN     NUMBER,
122                            x_return_status      IN OUT NOCOPY   VARCHAR2,
123                            x_msg_count          IN OUT NOCOPY   NUMBER,
124                            x_msg_data           IN OUT NOCOPY   VARCHAR2) is
125 
126 CURSOR UNAPPLY_recpt_cur IS
127  select app.amount_applied,
128         app.receivable_application_id,
129         app.cash_receipt_id
130    from ar_receivable_applications app
131   where app.cash_receipt_id = p_receipt_id
132     and app.STATUS ='OTHER ACC'
133     and app.display='Y';
134 
135 
136 CURSOR UNAPPLY_pay_cur IS
137  select app.amount_applied,
138         app.receivable_application_id,
139 	app.cash_receipt_id
140    from ar_receivable_applications app
141   where app.STATUS ='OTHER ACC'
142     and app.display='Y'
143     and app.payment_set_id = p_payment_set_id;
144 
145 l_api_version                   NUMBER := 1.0;
146 l_rec_app_id                    NUMBER(15);
147 l_amount_applied                NUMBER;
148 l_cash_receipt_id               NUMBER;
149 l_return_status                 VARCHAR2(30);
150 l_msg_count                     NUMBER;
151 l_msg_data                      VARCHAR2(30);
152 l_position                      VARCHAR2(2);
153 AP_ERROR                        exception;
154 
155 BEGIN
156 
157 l_return_status := 'S';
158 l_msg_count     := NULL;
159 l_msg_data      := NULL;
160 l_position      := '0';
161 
162  IF p_receipt_id IS NOT NULL THEN
163   OPEN UNAPPLY_recpt_cur;
164  ELSE
165   OPEN UNAPPLY_pay_cur;
166  END IF;
167 
168  l_position := '1';
169 
170  LOOP
171    IF p_receipt_id IS NOT NULL THEN
172 
173        FETCH UNAPPLY_recpt_cur INTO l_amount_applied,
174                                     l_rec_app_id,
175 				    l_cash_receipt_id;
176 
177        EXIT WHEN UNAPPLY_recpt_cur%NOTFOUND;
178 
179    ELSE
180 
181        FETCH UNAPPLY_pay_cur INTO   l_amount_applied,
182                                     l_rec_app_id,
183 				    l_cash_receipt_id;
184 
185        EXIT WHEN UNAPPLY_pay_cur%NOTFOUND;
186 
187    END IF;
188 
189 
190    l_position := '2';
191 
192    -- Calling the AR package to Unapply the prepayment Amount
193    ar_receipt_api_pub.unapply_other_account(
194                                 P_API_VERSION               => l_api_version,
195         	                p_cash_receipt_id           => l_cash_receipt_id,
196                         	p_receivable_application_id => l_rec_app_id,
197     		                X_return_status             => l_return_status,
198 				X_msg_count                 => l_msg_count,
199 			        X_msg_data                  => l_msg_data);
200 
201         IF l_return_status <> 'S' then
202                 RAISE AP_ERROR;
203         END IF;
204 
205    l_position := '3';
206 
207    -- Calling the AR package to Apply the On Account Amount
208    ar_receipt_api_pub.apply_on_account(P_API_VERSION      => l_api_version,
209       	                               p_cash_receipt_id  => l_cash_receipt_id,
210   		        	       X_return_status    => l_return_status,
211 			               X_msg_count        => l_msg_count,
212 				       X_msg_data         => l_msg_data,
213 				       P_AMOUNT_APPLIED   => l_amount_applied);
214 
215 	IF l_return_status <> 'S' then
216                 RAISE AP_ERROR;
217         END IF;
218 
219    l_position := '4';
220 
221  END LOOP;
222 
223  l_position := '5';
224 
225  IF p_receipt_id IS NOT NULL THEN
226   CLOSE UNAPPLY_recpt_cur;
227  ELSE
228   CLOSE UNAPPLY_pay_cur;
229  END IF;
230 
231  l_position := '6';
232 
233 
234 -- HANDLE EXCEPTIONS
235    EXCEPTION
236         WHEN AP_ERROR THEN
237              x_return_status   := l_return_status;
238              x_msg_count       := l_msg_count;
239              x_msg_data        := l_msg_data;
240         WHEN OTHERS THEN
241              RAISE;
242 
243 END Unapply_receipt;
244 
245 END PA_AR_ADV_RECEIPT;