[Home] [Help]
PACKAGE BODY: APPS.AR_ADJUST_PUB
Source
4 G_PKG_NAME CONSTANT VARCHAR2(30) :='AR_ADJUST_PUB';
1 PACKAGE BODY AR_ADJUST_PUB AS
2 /* $Header: ARXPADJB.pls 120.30.12020000.2 2012/07/03 22:38:00 dgaurab ship $*/
3
5 G_MSG_UERROR CONSTANT NUMBER := FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR;
6 G_MSG_ERROR CONSTANT NUMBER := FND_MSG_PUB.G_MSG_LVL_ERROR;
7 G_MSG_HIGH CONSTANT NUMBER := FND_MSG_PUB.G_MSG_LVL_DEBUG_HIGH;
8 G_MSG_MEDIUM CONSTANT NUMBER := FND_MSG_PUB.G_MSG_LVL_DEBUG_MEDIUM;
9 G_MSG_LOW CONSTANT NUMBER := FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW;
10
11 /*===========================================================================+
12 | PROCEDURE |
13 | Validate_Adj_Insert |
14 | |
15 | DESCRIPTION |
16 | This is the routine that validates the inputs during creation|
17 | of adjustments |
18 | |
19 | SCOPE - PRIVATE |
20 | |
21 | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED |
22 | fnd_api.compatible_api_call |
23 | fnd_api.g_exc_unexpected_error |
24 | fnd_api.g_ret_sts_error |
25 | fnd_api.g_ret_sts_error |
26 | fnd_api.g_ret_sts_success |
27 | fnd_api.to_boolean |
28 | fnd_msg_pub.check_msg_level |
29 | fnd_msg_pub.count_and_get |
30 | fnd_msg_pub.initialize |
31 | ar_adjvalidate_pvt.Validate_Type |
32 | ar_adjvalidate_pvt.Validate_Payschd |
33 | ar_adjvalidate_pvt.Validate_amount |
37 | ar_adjvalidate_pvt.Validate_doc_seq |
34 | ar_adjvalidate_pvt.Validate_Rcvtrxccid |
35 | ar_adjvalidate_pvt.Validate_dates |
36 | ar_adjvalidate_pvt.Validate_Reason_code |
38 | ar_adjvalidate_pvt.Validate_Associated_Receipt |
39 | ar_adjvalidate_pvt.Validate_Ussgl_code |
40 | ar_adjvalidate_pvt.Validate_Desc_Flexfield |
41 | ar_adjvalidate_pvt.Validate_Created_From |
42 | |
43 | ARGUMENTS : IN: p_chk_approval_limits |
44 | p_check_amount |
45 | OUT: |
46 | IN/ OUT: p_Validation_status |
47 | p_adj_rec |
48 | |
49 | RETURNS : NONE |
50 | |
51 | NOTES |
52 | |
53 | MODIFICATION HISTORY |
54 | Vivek Halder 30-JUN-97 Created |
55 | Saloni Shah 03-FEB-00 Changes have been made for BR/BOE project. |
56 | Two new IN parameters have been added |
57 | - p_chk_approval_limits and p_check_amount|
58 | These parameters are passed to the |
59 | Validate_amount procedure. |
60 | Vat changes have also been made to calculate |
61 | the amounts if the adjustment type is 'LINE' |
62 | or 'CHARGES'. |
63 | |
64 | Satheesh Nambiar 25-Aug-00 Bug 1395396. Modified the code to process $0 |
65 | adjustment for LINE |
66 | V Crisostomo 09-OCT-02 Bug 2443950 : skip validate_doc_seq when |
67 | adjustment is against receivable_trx_id = -15|
68 +===========================================================================*/
69
70 PG_DEBUG varchar2(1) := NVL(FND_PROFILE.value('AFLOG_ENABLED'), 'N');
71
72 -- Added parameter p_llca_from_call for Line level Adjustment
73 PROCEDURE Validate_Adj_Insert (
74 p_adj_rec IN OUT NOCOPY ar_adjustments%rowtype,
75 p_chk_approval_limits IN varchar2,
76 p_check_amount IN varchar2,
77 p_validation_status IN OUT NOCOPY varchar2,
78 p_llca_from_call IN varchar2 DEFAULT 'N'
79 ) IS
80
81 l_return_status varchar2(1);
82 l_ps_rec ar_payment_schedules%rowtype;
83 l_prorated_tax NUMBER;
84 l_prorated_amt NUMBER;
85 l_error_num NUMBER;
86
87 BEGIN
88
89 IF PG_DEBUG in ('Y', 'C') THEN
90 arp_util.debug('Validate_Adj_Insert()+');
91 arp_util.debug('p_llca_from_call :'|| p_llca_from_call);
92 END IF;
93
94
95 /*-------------------------------------------------+
96 | Initialize return status to SUCCESS |
97 +-------------------------------------------------*/
98 p_validation_status := FND_API.G_RET_STS_SUCCESS;
99
100 /*-------------------------------------------------+
101 | 1. Validate type |
102 +-------------------------------------------------*/
103 ar_adjvalidate_pvt.Validate_Type (
104 p_adj_rec,
105 l_return_status
106 ) ;
107 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
108 THEN
109 p_validation_status := l_return_status ;
110 IF PG_DEBUG in ('Y', 'C') THEN
111 arp_util.debug ('Validate_Adj_Insert: ' || ' failed to validate type ');
112 END IF;
113 END IF;
114
115 /*-------------------------------------------------+
116 | 2. Validate payment_schedule_id and |
117 | customer_trx_line_id |
118 +-------------------------------------------------*/
119 ar_adjvalidate_pvt.Validate_Payschd (
120 p_adj_rec,
121 l_ps_rec,
122 l_return_status,
123 p_llca_from_call
124 );
125 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
126 THEN
127 p_validation_status := l_return_status ;
128 IF PG_DEBUG in ('Y', 'C') THEN
129 arp_util.debug ('Validate_Adj_Insert: ' || ' failed to validate payment_schedule id ');
130 END IF;
131 END IF;
132
133 /*-------------------------------------------------+
134 | 3. Validate adjustment apply_date and GL date |
135 +-------------------------------------------------*/
136
137 ar_adjvalidate_pvt.Validate_dates (
138 p_adj_rec.apply_date,
139 p_adj_rec.gl_date,
140 l_ps_rec,
141 l_return_status
142 );
143 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
144 THEN
148 END IF;
145 p_validation_status := l_return_status ;
146 IF PG_DEBUG in ('Y', 'C') THEN
147 arp_util.debug ('Validate_Adj_Insert: ' || ' failed to validate dates ');
149 ELSE
150 p_adj_rec.apply_date := trunc(p_adj_rec.apply_date);
151 p_adj_rec.gl_date := trunc(p_adj_rec.gl_date);
152 END IF;
153
154 /*-------------------------------------------------+
155 | 4. Validate amount and status |
156 | |
157 | Change for the BOE/BR project has been made |
158 | parameters p_chk_approval_limits and |
159 | p_check_amount are being passed to validate |
160 | amount. |
161 | p_check_amount will only be 'F' in of |
162 | reversal of adjustments |
163 +-------------------------------------------------*/
164
165 ar_adjvalidate_pvt.Validate_amount (
166 p_adj_rec,
167 l_ps_rec,
168 p_chk_approval_limits,
169 p_check_amount,
170 l_return_status
171 );
172
173 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
174 THEN
175 p_validation_status := l_return_status ;
176 IF PG_DEBUG in ('Y', 'C') THEN
177 arp_util.debug ('Validate_Adj_Insert: ' || ' failed to validate amount '|| p_validation_status);
178 END IF;
179 END IF;
180
181 /*-------------------------------------------------+
182 | 5. Validate receivables_trx_id and code |
183 | combination. |
184 +-------------------------------------------------*/
185
186 /*-------------------------------------------------+
187 | Bug 1290698. Modified to pass PS record for |
188 | Validating PS class and receivable trx type |
189 +-------------------------------------------------*/
190 ar_adjvalidate_pvt.Validate_Rcvtrxccid (
191 p_adj_rec,
192 l_ps_rec,
193 l_return_status,
194 p_llca_from_call
195 );
196 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
197 THEN
198 p_validation_status := l_return_status ;
199 IF PG_DEBUG in ('Y', 'C') THEN
200 arp_util.debug ('Validate_Adj_Insert: ' || ' failed to validate receivables trx ccid');
201 END IF;
202 END IF;
203
204
205 /*-------------------------------------------------+
206 | 6. VAT CHANGES |
207 | Calculate the amount if the adjust type is |
208 | 'LINE' or 'CHARGES' |
209 | |
210 | This need not be done if the insert of |
211 | adjustment is for reverse_adjustment, which |
212 | is indicated by the flag p_check_amount |
213 +--------------------------------------------------*/
214 --Bug 1395396 Calculate prorate only if adjustment amount <> 0
215 -- Added call to customer_trx_line_id for Line level Adjustment
216 IF (p_adj_rec.type in ('LINE', 'CHARGES') AND
217 p_check_amount = FND_API.G_TRUE AND
218 p_adj_rec.amount <> 0) THEN
219
220 ARP_PROCESS_ADJUSTMENT.cal_prorated_amounts(p_adj_rec.amount,
221 p_adj_rec.payment_schedule_id,
222 p_adj_rec.type,
223 p_adj_rec.receivables_trx_id,
224 p_adj_rec.apply_date,
225 l_prorated_amt,
226 l_prorated_tax,
227 l_error_num,
228 p_adj_rec.customer_trx_line_id);
229
230 IF (l_error_num = 1) THEN
231 IF PG_DEBUG in ('Y', 'C') THEN
232 arp_util.debug('Validate_Adj_Insert: ' || 'cal_prorated_amount failed - error num 1');
233 END IF;
234 /*-----------------------------------------------+
235 | Set the message |
236 +-----------------------------------------------*/
237 FND_MESSAGE.SET_NAME('AR','AR_TW_PRORATE_ADJ_NO_TAX_RATE');
238 FND_MSG_PUB.ADD ;
239 p_validation_status := FND_API.G_RET_STS_ERROR;
240 ELSIF (l_error_num = 2) THEN
241 IF PG_DEBUG in ('Y', 'C') THEN
242 arp_util.debug('Validate_Adj_Insert: ' || 'cal_prorated_amount failed - error num 2');
243 END IF;
244 /*-----------------------------------------------+
245 | Set the message |
246 +-----------------------------------------------*/
250 ELSIF (l_error_num = 3) THEN
247 FND_MESSAGE.SET_NAME('AR','AR_TW_PRORATE_ADJ_OVERAPPLY');
248 FND_MSG_PUB.ADD ;
249 p_validation_status := FND_API.G_RET_STS_ERROR;
251 IF PG_DEBUG in ('Y', 'C') THEN
252 arp_util.debug('Validate_Adj_Insert: ' || 'cal_prorated_amount failed - error num 3');
253 END IF;
254 /*-----------------------------------------------+
255 | Set the message |
256 +-----------------------------------------------*/
257 p_validation_status := FND_API.G_RET_STS_ERROR;
258 ELSE
259 IF (p_adj_rec.type = 'LINE') THEN
260 p_adj_rec.line_adjusted := l_prorated_amt;
261 ELSE
262 p_adj_rec.receivables_charges_adjusted := l_prorated_amt;
263 END IF;
264 p_adj_rec.tax_adjusted := l_prorated_tax;
265 END IF;
266 END IF;
267
268 /*-------------------------------------------------+
269 | Check for over-application (Bug 3766262) |
270 +-------------------------------------------------*/
271 /*We need to check for over-application only when it's not an adjustment
272 reversal*/
273 IF (p_check_amount = FND_API.G_TRUE)
274 THEN
275 ar_adjvalidate_pvt.Validate_Over_Application(
276 p_adj_rec,
277 l_ps_rec,
278 l_return_status);
279 END IF;
280
281 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
282 THEN
283 p_validation_status := l_return_status ;
284 IF PG_DEBUG in ('Y', 'C') THEN
285 arp_util.debug ('Validate_Adj_Insert: ' || ' failed over-application check ');
286 END IF;
287 END IF;
288
289 /*-------------------------------------------------+
290 | Check for over-application Line level Adjustment |
291 +-------------------------------------------------*/
292 IF p_llca_from_call = 'Y' AND p_adj_rec.type = 'LINE'
293 THEN
294
295 IF (p_check_amount = FND_API.G_TRUE)
296 THEN
297 ar_adjvalidate_pvt.Validate_Over_Application_llca(
298 p_adj_rec,
299 l_ps_rec,
300 l_return_status);
301 END IF;
302
303 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
304 THEN
305 p_validation_status := l_return_status ;
306 IF PG_DEBUG in ('Y', 'C') THEN
307 arp_util.debug ('Validate_Adj_Insert: ' || ' failed over_application_llca check ');
308 END IF;
309 END IF;
310 END IF;
311
312
313 /*-------------------------------------------------+
314 | 7. Validate doc_sequence_value |
315 +-------------------------------------------------*/
316 -- Bug 2443950 - skip checking for doc sequence when adjustment is due to BR assignment
317 -- since this type of adjustment is not a document
318
319 if p_adj_rec.receivables_trx_id <> -15 then
320
321 ar_adjvalidate_pvt.Validate_doc_seq (
322 p_adj_rec,
323 l_return_status
324 ) ;
325 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
326 THEN
327 p_validation_status := l_return_status ;
328 IF PG_DEBUG in ('Y', 'C') THEN
329 arp_util.debug ('Validate_Adj_Insert: ' || ' failed to validate doc seq ');
330 END IF;
331 END IF;
332 end if;
333
334
335 /*-------------------------------------------------+
336 | 8. Validate reason_code |
337 +-------------------------------------------------*/
338 ar_adjvalidate_pvt.Validate_Reason_code (
339 p_adj_rec,
340 l_return_status
341 );
342 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
343 THEN
344 p_validation_status := l_return_status ;
345 IF PG_DEBUG in ('Y', 'C') THEN
346 arp_util.debug ('Validate_Adj_Insert: ' || ' failed to validate reason code ');
347 END IF;
348 END IF;
349
350 /*-------------------------------------------------+
351 | 9. Validate associated cash_receipt_id |
352 +-------------------------------------------------*/
353 ar_adjvalidate_pvt.Validate_Associated_Receipt (
354 p_adj_rec,
355 l_return_status
356 );
357 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
358 THEN
359 p_validation_status := l_return_status ;
360 IF PG_DEBUG in ('Y', 'C') THEN
361 arp_util.debug ('Validate_Adj_Insert: ' || ' failed to validate associated receipt id ');
362 END IF;
363 END IF;
364
365 /*-------------------------------------------------+
366 | 10. Validate ussgl transaction code |
367 +-------------------------------------------------*/
368 ar_adjvalidate_pvt.Validate_Ussgl_code (
369 p_adj_rec,
370 l_return_status
371 );
372 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
373 THEN
374 p_validation_status := l_return_status ;
375 IF PG_DEBUG in ('Y', 'C') THEN
376 arp_util.debug ('Validate_Adj_Insert: ' || ' failed to validate ussgl_code');
377 END IF;
378 END IF;
379
380 /*-------------------------------------------------+
381 | 11. Validate descriptive flex |
382 +-------------------------------------------------*/
383 ar_adjvalidate_pvt.Validate_Desc_Flexfield(
384 p_adj_rec,
385 l_return_status
386 );
387 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
388 THEN
389 p_validation_status := l_return_status ;
390 IF PG_DEBUG in ('Y', 'C') THEN
391 arp_util.debug ('Validate_Adj_Insert: ' || ' failed to validate ussgl_code');
392 END IF;
393 END IF;
394
395 /*-------------------------------------------------+
396 | 12. Validate created form |
397 +-------------------------------------------------*/
398 ar_adjvalidate_pvt.Validate_Created_From (
399 p_adj_rec,
400 l_return_status
401 );
402
403 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
404 THEN
405 p_validation_status := l_return_status ;
406 IF PG_DEBUG in ('Y', 'C') THEN
407 arp_util.debug ('Validate_Adj_Insert: ' || ' failed to validate created from ');
408 END IF;
409 END IF;
410
411 IF PG_DEBUG in ('Y', 'C') THEN
412 arp_util.debug('Validate_Adj_Insert()-');
413 arp_util.debug('Validate_Adj_Insert: ' || 'value of the status flag ' || p_validation_status);
414 END IF;
415 RETURN;
416
417
418 EXCEPTION
419
420 WHEN OTHERS THEN
421 IF PG_DEBUG in ('Y', 'C') THEN
422 arp_util.debug('EXCEPTION: Validate_Adj_Insert() ');
423 END IF;
424 FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,'Validate_Adj_Insert');
425 p_validation_status := FND_API.G_RET_STS_UNEXP_ERROR ;
426 RETURN;
427
428
429 END Validate_Adj_Insert;
430
431 /*===========================================================================+
432 | PROCEDURE |
433 | Set_Remaining_Attributes |
434 | |
435 | DESCRIPTION |
436 | This routine sets data of remaining attributes which are not |
437 | not populated by the validation process. It also resets the |
438 | the columns in the adjustment record that should not be |
439 | populated during creation of adjustments |
440 | |
441 | SCOPE - PRIVATE |
442 | |
443 | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED |
444 | |
445 | |
446 | |
447 | ARGUMENTS : IN: |
448 | OUT: |
449 | p_Validation_status |
450 | IN/ OUT: |
451 | p_adj_rec |
452 | |
453 | |
454 | RETURNS : NONE |
455 | |
456 | NOTES |
457 | |
458 | MODIFICATION HISTORY |
459 | Vivek Halder 30-JUN-97 Created |
460 | |
461 +===========================================================================*/
462
463 PROCEDURE Set_Remaining_Attributes (
464 p_adj_rec IN OUT NOCOPY ar_adjustments%rowtype,
465 p_return_status IN OUT NOCOPY varchar2
466 ) IS
467
468 BEGIN
469
470 IF PG_DEBUG in ('Y', 'C') THEN
471 arp_util.debug('Set_Remaining_Attributes()+');
472 END IF;
473
474 /*-----------------------------------------------+
475 | Set the status to success |
476 +-----------------------------------------------*/
480 | Set Adjustment Type and Postable attributes |
477 p_return_status := FND_API.G_RET_STS_SUCCESS ;
478
479 /*-----------------------------------------------+
481 +-----------------------------------------------*/
482 /*-----------------------------------------------+
483 | Bug 1290698- Set the Adjustment Type to manual|
484 | only if it is null. For BOE/BR adjustment_type|
485 | can be 'E'-ENDORSEMNT or 'X'-EXCHANGE |
486 +-----------------------------------------------*/
487 IF p_adj_rec.adjustment_type is null
488 THEN
489 p_adj_rec.adjustment_type := 'M' ;
490 END IF;
491 p_adj_rec.postable := 'Y' ;
492
493 /*--------------------------------------------------------+
494 | Reset the distribution_set_id, chargeback_customer_id |
495 | and subsequent customer trx id |
496 +--------------------------------------------------------*/
497 p_adj_rec.distribution_set_id := NULL;
498 p_adj_rec.chargeback_customer_trx_id := NULL ;
499 p_adj_rec.subsequent_trx_id := NULL ;
500
501
502 IF PG_DEBUG in ('Y', 'C') THEN
503 arp_util.debug('Set_Remaining_Attributes()-' );
504 END IF;
505
506 EXCEPTION
507
508 WHEN OTHERS THEN
509 IF PG_DEBUG in ('Y', 'C') THEN
510 arp_util.debug('EXCEPTION: Set_Remaining_Attributes() ');
511 END IF;
512 FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,'Set_Remaining_Attributes');
513 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
514 RETURN;
515
516 END Set_Remaining_Attributes;
517
518 /*===========================================================================+
519 | PROCEDURE |
520 | Validate_Adj_Modify |
521 | |
522 | DESCRIPTION |
523 | This is the validation routine for Modification of Approvals |
524 | |
525 | |
526 | SCOPE - PRIVATE |
527 | |
528 | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED |
529 | |
530 | |
531 | |
532 | ARGUMENTS : IN: |
533 | p_old_adj_rec |
534 | |
535 | OUT: |
536 | p_Validation_status |
537 | IN/ OUT: |
538 | p_adj_rec |
539 | |
540 | RETURNS : NONE |
541 | |
542 | NOTES |
543 | |
544 | MODIFICATION HISTORY |
545 | Vivek Halder 30-JAN-97 Created |
546 | Saloni Shah 03-FEB-00 Changes have been made for the BOE/BR project|
547 | A new parameter p_chk_approval_limits is |
548 | passed. The value of this flag will indicate |
552 | passed, then update the adjustment with that |
549 | if the amount_adjusted should be validated |
550 | against the user approval limits or not |
551 | S.Nambiar 31-Aug-02 Bug 2487925, if associated_application_id is |
553 | id.
554 +===========================================================================*/
555
556 PROCEDURE Validate_Adj_modify (
557 p_adj_rec IN OUT NOCOPY ar_adjustments%rowtype,
558 p_old_adj_rec IN ar_adjustments%rowtype,
559 p_chk_approval_limits IN varchar2,
560 p_validation_status IN OUT NOCOPY varchar2
561 ) IS
562
563 l_ps_rec ar_payment_schedules%rowtype;
564 l_approved_flag varchar2(1);
565 l_temp_adj_rec ar_adjustments%rowtype;
566 l_return_status varchar2(1);
567 l_cash_receipt_id ar_receivable_applications.cash_receipt_id%TYPE;
568
569 BEGIN
570
571 IF PG_DEBUG in ('Y', 'C') THEN
572 arp_util.debug('Validate_Adj_modify()+' );
573 END IF;
574
575 /*----------------------------------------------+
576 | Validate Old Adjustment status. Cannot modify |
577 | if status is 'A' |
578 +----------------------------------------------*/
579 --Bug 2655679 .ASSOCIATE_RECEIPT is passed when the user want to associate
580 --a receipt to an existing adjustment.As per the previous design, user can't
581 --modify an adjustment which is approved. This is the only exception.
582
583 IF ((( p_old_adj_rec.status = 'A' ) AND (p_adj_rec.created_from <> 'ASSOCIATE_RECEIPT'))
584 OR (p_old_adj_rec.status = 'R')) /*Bug 4303601*/
585 THEN
586 FND_MESSAGE.SET_NAME ('AR', 'AR_AAPI_NO_CHANGE_OR_REVERSE');
587 FND_MESSAGE.SET_TOKEN ( 'STATUS', p_old_adj_rec.status ) ;
588 FND_MSG_PUB.ADD ;
589 p_validation_status := FND_API.G_RET_STS_ERROR;
590 IF PG_DEBUG in ('Y', 'C') THEN
591 arp_util.debug('Validate_Adj_modify: ' || 'The old adjustment status is A, cannot modify');
592 END IF;
593 END IF;
594
595 --If approved adjustment is being modified for associating receipt,
596 --then associated cash_receipt_id or application id should be passed.
597
598 IF (( p_old_adj_rec.status = 'A' ) AND
599 (p_adj_rec.created_from = 'ASSOCIATE_RECEIPT') AND
600 (p_adj_rec.associated_application_id IS NULL ) AND
601 (p_adj_rec.associated_cash_receipt_id IS NULL)
602 ) THEN
603 FND_MESSAGE.SET_NAME ('AR', 'AR_RAPI_RCPT_RA_ID_X_INVALID');
604 FND_MSG_PUB.ADD ;
605 p_validation_status := FND_API.G_RET_STS_ERROR;
606 IF PG_DEBUG in ('Y', 'C') THEN
607 arp_util.debug('Validate_Adj_modify: ' || 'Invalid associated cash_receipt_id or application id -should not be null');
608 END IF;
609 END IF;
610
611 --If approved adjustment is being modified for associating receipt,
612 --no other attribute should be allowed to modify.
613
614 IF (( p_old_adj_rec.status = 'A' ) AND
615 (p_adj_rec.created_from = 'ASSOCIATE_RECEIPT') AND
616 ((p_adj_rec.comments IS NOT NULL ) OR
617 (p_adj_rec.status IS NOT NULL ) OR
618 (p_adj_rec.gl_date IS NOT NULL )))
619 THEN
620 FND_MESSAGE.SET_NAME ('AR', 'AR_AAPI_NO_CHANGE_OR_REVERSE');
621 FND_MESSAGE.SET_TOKEN ( 'STATUS', p_old_adj_rec.status ) ;
622 FND_MSG_PUB.ADD ;
623 p_validation_status := FND_API.G_RET_STS_ERROR;
624 IF PG_DEBUG in ('Y', 'C') THEN
625 arp_util.debug('Validate_Adj_modify: ' || 'Cannot modify comments,status or gl date of an approved adjustment');
626 END IF;
627 END IF;
628
629
630 /*----------------------------------------------------+
631 | Check new status. It could be NULL, 'A','R','W','M'|
632 +-----------------------------------------------------*/
633
634 IF ( (p_adj_rec.status IS NOT NULL) AND
635 (p_adj_rec.status NOT IN ('A', 'R', 'W', 'M')) )
636 THEN
637 FND_MESSAGE.SET_NAME ('AR', 'AR_AAPI_INVALID_CHANGE_STATUS');
638 FND_MESSAGE.SET_TOKEN ( 'STATUS', p_adj_rec.status ) ;
639 FND_MSG_PUB.ADD ;
640 p_validation_status := FND_API.G_RET_STS_ERROR;
641 IF PG_DEBUG in ('Y', 'C') THEN
642 arp_util.debug('Validate_Adj_modify: ' || 'The new adjustment status is not valid, cannot modify');
643 END IF;
644 END IF;
645
646 /*---------------------------------------------------+
647 | 2. Validate approval limits if new status is 'A' |
648 +---------------------------------------------------*/
649
650 /*----------------------------------+
651 | a) Get the invoice currency code |
652 +----------------------------------*/
653
654 BEGIN
655
656 SELECT *
657 INTO l_ps_rec
658 FROM ar_payment_schedules
659 WHERE payment_schedule_id = p_old_adj_rec.payment_schedule_id;
660
661 EXCEPTION
662 WHEN NO_DATA_FOUND THEN
663
664 /*-----------------------------------------------+
665 | Payment schedule Id does not exist |
666 | Set the message and status accordingly |
667 +-----------------------------------------------*/
671
668 FND_MESSAGE.SET_NAME ( 'AR', 'AR_AAPI_INVALID_PAYMENT_SCHEDULE');
669 FND_MESSAGE.SET_TOKEN('PAYMENT_SCHEDULE_ID',to_char(p_old_adj_rec.payment_schedule_id));
670 FND_MSG_PUB.ADD ;
672 p_validation_status := FND_API.G_RET_STS_ERROR;
673 IF PG_DEBUG in ('Y', 'C') THEN
674 arp_util.debug('Validate_Adj_modify: ' || 'Invalid Payment Schedule Id');
675 END IF;
676 END ;
677
678 /*------------------------------------------------------+
682 | 'T'. |
679 | Changes made for BR/BOE project. The check for the |
680 | adjusted_amount against the users approval limits |
681 | will be done only if p_chk_approval_limits is set to |
683 +------------------------------------------------------*/
684 IF ( p_adj_rec.status = 'A' and
685 p_chk_approval_limits = FND_API.G_TRUE )
686 THEN
687
688 /*-----------------------------------+
689 | Get the approval limits and check |
690 +-----------------------------------*/
691
692 ar_adjvalidate_pvt.Within_approval_limits(
693 p_old_adj_rec.amount,
694 l_ps_rec.invoice_currency_code,
695 l_approved_flag,
696 l_return_status
697 ) ;
698
699 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
700 THEN
701 p_validation_status := l_return_status;
702 IF PG_DEBUG in ('Y', 'C') THEN
703 arp_util.debug('Validate_Adj_modify: ' || 'failure in get approval limits and check');
704 END IF;
705 END IF;
706
707 IF ( l_approved_flag <> FND_API.G_TRUE )
708 THEN
709 FND_MESSAGE.SET_NAME ( 'AR', 'AR_VAL_AMT_APPROVAL_LIMIT');
710 FND_MSG_PUB.ADD ;
711 p_validation_status := FND_API.G_RET_STS_ERROR;
712 IF PG_DEBUG in ('Y', 'C') THEN
713 arp_util.debug('Validate_Adj_modify: ' || 'amount not in approval limits ');
714 END IF;
715 END IF;
716
717 /*-------------------------------------------------+
718 | Check over application |
719 +-------------------------------------------------*/
720
721 -- This is done by the entity handler
722
723 END IF;
724
725 /*-------------------------------------------------+
726 | 3. Validate GL date |
727 +-------------------------------------------------*/
728
729 /*Bug4303601*/
730 ar_adjvalidate_pvt.Validate_dates (
731 p_old_adj_rec.apply_date,
732 NVL(p_adj_rec.gl_date,p_old_adj_rec.gl_date),
733 l_ps_rec,
734 l_return_status
735 ) ;
736 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
737 THEN
738 p_validation_status := l_return_status;
739 IF PG_DEBUG in ('Y', 'C') THEN
740 arp_util.debug('Validate_Adj_modify: ' || 'failure in validating dates');
741 END IF;
742 END IF;
743
744
745 p_adj_rec.gl_date := trunc(p_adj_rec.gl_date);
746
747 --Bug 2487925 Validate the cash receipt id, if passed
748
749 IF (p_adj_rec.associated_cash_receipt_id IS NOT NULL) THEN
750
751 ar_adjvalidate_pvt.Validate_Associated_Receipt (
752 p_adj_rec,
753 l_return_status
754 );
755 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
756 THEN
757 p_validation_status := l_return_status ;
758 IF PG_DEBUG in ('Y', 'C') THEN
759 arp_util.debug ('Validate_Adj_modify: ' || ' failed to validate associated receipt id ');
760 END IF;
761 END IF;
762 END IF;
763
764 --Bug 2487925 if the associated_application_id is passed, then validate
765 --it. It should belong to a valid cash receipt and application. And the
766 -- adjustment and the application should be done to the same invoice.
767
768 IF ( p_adj_rec.associated_application_id IS NOT NULL )
769 THEN
770 BEGIN
771 SELECT cash_receipt_id
772 INTO l_cash_receipt_id
773 FROM ar_receivable_applications
774 WHERE status= 'APP'
775 AND display='Y'
776 AND receivable_application_id = p_adj_rec.associated_application_id
777 AND applied_payment_schedule_id= p_old_adj_rec.payment_schedule_id;
778 EXCEPTION
779 WHEN no_data_found THEN
780 FND_MESSAGE.SET_NAME ( 'AR', 'AR_RAPI_REC_APP_ID_INVALID');
781 FND_MSG_PUB.ADD ;
782 p_validation_status := FND_API.G_RET_STS_ERROR;
783 IF PG_DEBUG in ('Y', 'C') THEN
784 arp_util.debug('Validate_Adj_modify: ' || 'Associated Application ID passed is invalid');
785 END IF;
786 END;
787
788 END IF;
789
790 --Show error is cash receipt is id not found
791
792 IF (( p_adj_rec.associated_application_id IS NOT NULL ) AND
793 ( p_old_adj_rec.associated_cash_receipt_id IS NULL ) AND
794 ( p_adj_rec.associated_cash_receipt_id IS NULL ) AND
795 ( l_cash_receipt_id IS NULL )) THEN
796
797 FND_MESSAGE.SET_NAME ( 'AR', 'AR_RAPI_REC_APP_ID_INVALID');
798 FND_MSG_PUB.ADD ;
799 p_validation_status := FND_API.G_RET_STS_ERROR;
800 IF PG_DEBUG in ('Y', 'C') THEN
801 arp_util.debug('Validate_Adj_modify: ' || 'Associated Application ID should belongs to valid Receipt,pass cash receipt id');
802 END IF;
803 END IF;
804
805 /*---------------------------------------------------+
806 | 5. Copy all other attributes into p_adj_rec |
807 +---------------------------------------------------*/
808
809 l_temp_adj_rec.comments := p_adj_rec.comments ;
813 --Bug 2487925, if only application id is passed, take the cash receipt id of the
810 l_temp_adj_rec.status := p_adj_rec.status ;
811 l_temp_adj_rec.gl_date := p_adj_rec.gl_date ;
812
814 --application, if only cash receipt id is passed, just update associated cash receipt id only
815
816 IF l_cash_receipt_id IS NOT NULL THEN
817 l_temp_adj_rec.associated_cash_receipt_id := l_cash_receipt_id;
818 ELSIF p_adj_rec.associated_cash_receipt_id IS NOT NULL THEN
819 l_temp_adj_rec.associated_cash_receipt_id := p_adj_rec.associated_cash_receipt_id;
820 END IF;
821
822 l_temp_adj_rec.associated_application_id := p_adj_rec.associated_application_id;
823
824 p_adj_rec := p_old_adj_rec ;
825
826 IF ( l_temp_adj_rec.comments IS NOT NULL )
827 THEN
828 p_adj_rec.comments := l_temp_adj_rec.comments;
829 END IF;
830
831 IF ( l_temp_adj_rec.status IS NOT NULL )
832 THEN
833 p_adj_rec.status := l_temp_adj_rec.status ;
834 END IF ;
835
836 IF ( l_temp_adj_rec.gl_date IS NOT NULL )
837 THEN
838 p_adj_rec.gl_date := l_temp_adj_rec.gl_date ;
839 END IF ;
840
841 --Bug 2487925
842 IF ( l_temp_adj_rec.associated_cash_receipt_id IS NOT NULL )
843 THEN
844 p_adj_rec.associated_cash_receipt_id := l_temp_adj_rec.associated_cash_receipt_id ;
845 END IF ;
846
847 IF ( l_temp_adj_rec.associated_application_id IS NOT NULL )
848 THEN
849 p_adj_rec.associated_application_id := l_temp_adj_rec.associated_application_id ;
850 END IF ;
851
852 IF PG_DEBUG in ('Y', 'C') THEN
853 arp_util.debug('Validate_Adj_modify()-' );
854 END IF;
855
856 EXCEPTION
857
858 WHEN OTHERS THEN
859 IF PG_DEBUG in ('Y', 'C') THEN
860 arp_util.debug('EXCEPTION: Validate_Adj_Modify() ');
861 END IF;
862 FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,'Validate_Adj_Modify');
863 p_validation_status := FND_API.G_RET_STS_UNEXP_ERROR ;
864 RETURN;
865
866
867 END Validate_Adj_Modify;
868
869 /*===========================================================================+
870 | PROCEDURE |
871 | Validate_Adj_Reverse |
872 | |
873 | DESCRIPTION |
874 | This is the validation routine for Reversal of Approvals |
875 | |
876 | |
877 | SCOPE - PRIVATE |
878 | |
879 | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED |
880 | |
881 | |
882 | |
883 | ARGUMENTS : IN: |
884 | p_old_adj_rec |
885 | |
889 | IN/ OUT: |
886 | OUT: |
887 | p_Validation_status |
888 | |
890 | p_reversal_gl_date |
891 | p_reversal_date |
892 | |
893 | RETURNS : NONE |
894 | |
895 | NOTES |
896 | |
897 | MODIFICATION HISTORY |
898 | Vivek Halder 30-JAN-97 Created |
899 | |
900 +===========================================================================*/
901
902 PROCEDURE Validate_Adj_Reverse (
903 p_old_adj_rec IN ar_adjustments%rowtype,
904 p_reversal_gl_date IN OUT NOCOPY date,
905 p_reversal_date IN OUT NOCOPY date,
906 p_validation_status IN OUT NOCOPY varchar2
907 ) IS
908
909 l_ps_rec ar_payment_schedules%rowtype;
910 l_return_status varchar2(1);
911
912 BEGIN
913
914 IF PG_DEBUG in ('Y', 'C') THEN
915 arp_util.debug('Validate_Adj_Reverse()+');
916 END IF;
917
918 /*----------------------------------------------+
919 | Validate Old Adjustment status. Cannot reverse|
920 | if status is 'A' |
921 +----------------------------------------------*/
922
923 IF ( p_old_adj_rec.status <> 'A' )
924 THEN
925 FND_MESSAGE.SET_NAME ( 'AR', 'AR_AAPI_NO_CHANGE_OR_REVERSE');
926 FND_MESSAGE.SET_TOKEN ( 'STATUS', p_old_adj_rec.status);
927 FND_MSG_PUB.ADD ;
928 p_validation_status := FND_API.G_RET_STS_ERROR;
929 IF PG_DEBUG in ('Y', 'C') THEN
930 arp_util.debug('Validate_Adj_Reverse: ' || 'the status of the old adj is not A ');
931 END IF;
932 END IF;
933
934
935 /*-------------------------------------------------+
936 | Validate reversal dates |
937 +-------------------------------------------------*/
938
939
940 IF ( p_reversal_gl_date IS NULL )
941 THEN
942 p_reversal_gl_date := p_old_adj_rec.gl_date;
943 END IF;
944
945 IF ( p_reversal_date IS NULL )
946 THEN
947 p_reversal_date := p_old_adj_rec.apply_date;
948 END IF;
949
950 /*-----------------------------------+
951 | Get the Payment schedule details |
952 +-----------------------------------*/
953
954 BEGIN
955
956 SELECT *
957 INTO l_ps_rec
958 FROM ar_payment_schedules
959 WHERE payment_schedule_id = p_old_adj_rec.payment_schedule_id;
960
961 EXCEPTION
962 WHEN NO_DATA_FOUND THEN
963
964 /*-----------------------------------------------+
965 | Payment schedule Id does not exist |
966 | Set the message and status accordingly |
967 +-----------------------------------------------*/
968
969 FND_MESSAGE.SET_NAME ('AR', 'AR_AAPI_INVALID_PAYMENT_SCHEDULE');
970 FND_MESSAGE.SET_TOKEN ( 'PAYMENT_SCHEDULE_ID', to_char(p_old_adj_rec.payment_schedule_id) ) ;
971 FND_MSG_PUB.ADD ;
972
973 p_validation_status := FND_API.G_RET_STS_ERROR;
974 IF PG_DEBUG in ('Y', 'C') THEN
978
975 arp_util.debug('Validate_Adj_Reverse: ' || 'invalid payment schedule id');
976 END IF;
977 END ;
979 ar_adjvalidate_pvt.Validate_dates (
980 p_reversal_date,
981 p_reversal_gl_date,
982 l_ps_rec,
983 l_return_status
984 ) ;
985 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
986 THEN
987 p_validation_status := l_return_status;
988 IF PG_DEBUG in ('Y', 'C') THEN
989 arp_util.debug('Validate_Adj_Reverse: ' || 'invalid dates');
990 END IF;
991 END IF;
992
993 p_reversal_gl_date := trunc(p_reversal_gl_date);
994 p_reversal_date := trunc(p_reversal_date);
995
996 IF PG_DEBUG in ('Y', 'C') THEN
997 arp_util.debug('Validate_Adj_Reverse()-' );
998 END IF;
999
1000 EXCEPTION
1001
1002 WHEN OTHERS THEN
1003 IF PG_DEBUG in ('Y', 'C') THEN
1004 arp_util.debug('EXCEPTION: Validate_Adj_Reverse() ');
1005 END IF;
1006 FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,'Validate_Adj_Reverse');
1007 p_validation_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1008 RETURN;
1009
1010
1011 END Validate_Adj_Reverse;
1012
1013 /*===========================================================================+
1014 | PROCEDURE |
1015 | Validate_Adj_Approve |
1016 | |
1017 | DESCRIPTION |
1018 | This is the validation routine for Approval |
1019 | |
1020 | |
1021 | SCOPE - PRIVATE |
1022 | |
1023 | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED |
1024 | |
1025 | |
1026 | |
1027 | ARGUMENTS : IN: |
1028 | p_old_adj_rec |
1029 | |
1030 | OUT: |
1031 | p_Validation_status |
1032 | |
1033 | IN/ OUT: |
1034 | p_adj_rec |
1035 | |
1036 | |
1037 | RETURNS : NONE |
1038 | |
1039 | NOTES |
1040 | |
1041 | MODIFICATION HISTORY |
1042 | Vivek Halder 30-JAN-97 Created |
1043 | |
1044 +===========================================================================*/
1045
1046 PROCEDURE Validate_Adj_Approve (
1047 p_adj_rec IN OUT NOCOPY ar_adjustments%rowtype,
1048 p_old_adj_rec IN ar_adjustments%rowtype,
1049 p_chk_approval_limits IN varchar2,
1050 p_validation_status IN OUT NOCOPY varchar2
1051 ) IS
1052
1053 l_ps_rec ar_payment_schedules%rowtype;
1054 l_approved_flag varchar2(1);
1055 l_temp_adj_rec ar_adjustments%rowtype;
1056 l_return_status varchar2(1);
1057
1058 BEGIN
1059
1060 IF PG_DEBUG in ('Y', 'C') THEN
1061 arp_util.debug('Validate_Adj_Approve()+');
1062 END IF;
1063
1064 /*-----------------------------------------------+
1068
1065 | Validate Old Adjustment status. Cannot approve|
1066 | if status is 'A' or 'R' |
1067 +----------------------------------------------*/
1069 IF ( p_old_adj_rec.status IN ('A','R') ) /*Bug 4290494*/
1070 THEN
1071
1072 FND_MESSAGE.SET_NAME ('AR', 'AR_AAPI_NO_CHANGE_OR_REVERSE');
1073 FND_MESSAGE.SET_TOKEN ( 'STATUS', p_old_adj_rec.status ) ;
1074 FND_MSG_PUB.ADD ;
1075 p_validation_status := FND_API.G_RET_STS_ERROR;
1076 IF PG_DEBUG in ('Y', 'C') THEN
1077 arp_util.debug('Validate_Adj_Approve: ' || 'the adjustment is already approved or rejected');
1078 END IF;
1079 END IF;
1080
1081 /*----------------------------------------------------+
1082 | If new status is NULL set it to 'A' |
1083 +----------------------------------------------------*/
1084
1085 IF (p_adj_rec.status IS NULL )
1086 THEN
1087 p_adj_rec.status := 'A' ;
1088 END IF;
1089
1090 /*----------------------------------------------------+
1091 | Check new status. It could be NULL, 'A','R','W','M'|
1092 +----------------------------------------------------*/
1093
1094 IF ( (p_adj_rec.status IS NOT NULL) AND
1095 (p_adj_rec.status NOT IN ('A', 'R', 'W', 'M')) )
1096 THEN
1097
1098 FND_MESSAGE.SET_NAME ('AR', 'AR_AAPI_INVALID_CHANGE_STATUS');
1099 FND_MESSAGE.SET_TOKEN ( 'STATUS', p_adj_rec.status ) ;
1100 FND_MSG_PUB.ADD ;
1101 p_validation_status := FND_API.G_RET_STS_ERROR;
1102 IF PG_DEBUG in ('Y', 'C') THEN
1103 arp_util.debug('Validate_Adj_Approve: ' || 'the value of the new status is not in A, R, W, M');
1104 END IF;
1105
1106 END IF;
1107
1108
1109
1110 /*---------------------------------------------------+
1111 | 2. Validate approval limits if new status is 'A' |
1112 +---------------------------------------------------*/
1113
1114 /*----------------------------------+
1115 | a) Get the invoice currency code |
1116 +----------------------------------*/
1117
1118 BEGIN
1119
1120 SELECT *
1121 INTO l_ps_rec
1122 FROM ar_payment_schedules
1123 WHERE payment_schedule_id = p_old_adj_rec.payment_schedule_id;
1124
1125 EXCEPTION
1126 WHEN NO_DATA_FOUND THEN
1127
1128 /*-----------------------------------------------+
1129 | Payment schedule Id does not exist |
1130 | Set the message and status accordingly |
1131 +-----------------------------------------------*/
1132
1133 FND_MESSAGE.SET_NAME ('AR', 'AR_AAPI_INVALID_PAYMENT_SCHEDULE');
1134 FND_MESSAGE.SET_TOKEN('PAYMENT_SCHEDULE_ID',to_char(p_old_adj_rec.payment_schedule_id));
1135 FND_MSG_PUB.ADD ;
1136 p_validation_status := FND_API.G_RET_STS_ERROR;
1137 IF PG_DEBUG in ('Y', 'C') THEN
1138 arp_util.debug('Validate_Adj_Approve: ' || 'Invalid payment schedule id');
1139 END IF;
1140
1141 END ;
1142
1143 /*----------------------------------------------------+
1144 | Change introduced for the BR/BOE project. |
1145 | Special processing for bypassing limit check if |
1146 | p_chk_approval_limits is set to 'F' |
1147 +--------------------------------------------------- */
1148 IF ( p_adj_rec.status = 'A' and
1149 p_chk_approval_limits = FND_API.G_TRUE)
1150 THEN
1151
1152 /*-----------------------------------+
1153 | Get the approval limits and check |
1154 +-----------------------------------*/
1155
1156 ar_adjvalidate_pvt.Within_approval_limits(
1157 p_old_adj_rec.amount,
1158 l_ps_rec.invoice_currency_code,
1159 l_approved_flag,
1160 l_return_status
1161 ) ;
1162
1163 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
1164 THEN
1165 p_validation_status := l_return_status;
1166 IF PG_DEBUG in ('Y', 'C') THEN
1167 arp_util.debug('Validate_Adj_Approve: ' || ' Error in Get the approval limits and check ');
1168 END IF;
1169 END IF;
1170
1171 IF ( l_approved_flag <> FND_API.G_TRUE )
1172 THEN
1173 FND_MESSAGE.SET_NAME ('AR', 'AR_VAL_AMT_APPROVAL_LIMIT');
1174 FND_MSG_PUB.ADD ;
1175
1176 p_validation_status := FND_API.G_RET_STS_ERROR;
1177 IF PG_DEBUG in ('Y', 'C') THEN
1178 arp_util.debug('Validate_Adj_Approve: ' || 'not within approval limits');
1179 END IF;
1180 END IF;
1181
1182 /*-------------------------------------------------+
1183 | Check over application |
1184 +-------------------------------------------------*/
1185
1186 -- This is done by the entity handler
1187
1188 END IF;
1189
1190 /*-------------------------------------------------+
1191 | 3. Validate GL date |
1192 +-------------------------------------------------*/
1193
1194 /*Bug4303601*/
1195 ar_adjvalidate_pvt.Validate_dates (
1196 p_old_adj_rec.apply_date,
1197 NVL(p_adj_rec.gl_date,p_old_adj_rec.gl_date),
1198 l_ps_rec,
1199 l_return_status
1200 ) ;
1201 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
1202 THEN
1203 p_validation_status := l_return_status ;
1204 IF PG_DEBUG in ('Y', 'C') THEN
1205 arp_util.debug('Validate_Adj_Approve: ' || 'invalid gl_date');
1206 END IF;
1207 END IF;
1208
1209 p_adj_rec.gl_date := trunc(p_adj_rec.gl_date);
1210
1211 /*---------------------------------------------------+
1212 | 4. Copy all other attributes into p_adj_rec |
1213 +---------------------------------------------------*/
1214
1215 l_temp_adj_rec := NULL ;
1216
1217 l_temp_adj_rec.comments := p_adj_rec.comments ;
1218 l_temp_adj_rec.status := p_adj_rec.status ;
1219 l_temp_adj_rec.gl_date := p_adj_rec.gl_date ;
1220
1221 p_adj_rec := p_old_adj_rec ;
1222
1223 IF ( l_temp_adj_rec.comments IS NOT NULL )
1224 THEN
1225 p_adj_rec.comments := l_temp_adj_rec.comments;
1226 END IF;
1227
1228 IF ( l_temp_adj_rec.status IS NOT NULL )
1229 THEN
1230 p_adj_rec.status := l_temp_adj_rec.status ;
1231 END IF ;
1232
1233 IF ( l_temp_adj_rec.gl_date IS NOT NULL )
1234 THEN
1235 p_adj_rec.gl_date := l_temp_adj_rec.gl_date ;
1236 END IF ;
1237
1238 IF PG_DEBUG in ('Y', 'C') THEN
1239 arp_util.debug('Validate_Adj_Approve ()-' );
1240 END IF;
1241
1242 EXCEPTION
1243
1244 WHEN OTHERS THEN
1245 IF PG_DEBUG in ('Y', 'C') THEN
1246 arp_util.debug('EXCEPTION: Validate_Adj_Approve() ');
1247 END IF;
1248 FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,'Validate_Adj_Approve');
1249 p_validation_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1250 RETURN;
1251
1252
1253 END Validate_Adj_Approve;
1254
1255 /*===========================================================================+
1256 | PROCEDURE |
1257 | populate_adj_llca_gt |
1258 | |
1262 | |
1259 | DESCRIPTION |
1260 | This is the populate routine for Line level adjustment |
1261 | |
1263 | SCOPE - PRIVATE |
1264 | |
1265 | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED |
1266 | |
1267 | |
1268 | |
1269 | ARGUMENTS : IN: |
1270 | p_customer_trx_id |
1271 | p_llca_adj_trx_lines_tbl |
1272 | |
1273 | OUT: |
1277 | |
1274 | p_return_status |
1275 | |
1276 | IN/ OUT: |
1278 | |
1279 | |
1280 | RETURNS : NONE |
1281 | |
1282 | NOTES |
1283 | |
1284 | MODIFICATION HISTORY |
1285 | mpsingh 04-feb-2008 Created |
1286 | |
1287 +===========================================================================*/
1288
1289 PROCEDURE populate_adj_llca_gt (
1290 p_customer_trx_id IN NUMBER,
1291 p_llca_adj_trx_lines_tbl IN llca_adj_trx_line_tbl_type,
1292 p_return_status OUT NOCOPY VARCHAR2)
1293 IS
1294 BEGIN
1295 IF PG_DEBUG in ('Y', 'C') THEN
1296 arp_util.debug('Populate_adj_llca_gt ()+ ');
1297 END IF;
1298
1299 p_return_status := FND_API.G_RET_STS_SUCCESS;
1300
1301 -- Clean the GT Table first.
1302 delete from ar_llca_adj_trx_lines_gt
1303 where customer_trx_id = p_customer_trx_id;
1304
1305 delete from ar_llca_adj_trx_errors_gt
1306 where customer_trx_id = p_customer_trx_id;
1307
1308
1309
1310 If p_llca_adj_trx_lines_tbl.count = 0 Then
1311 IF PG_DEBUG in ('Y', 'C') THEN
1312 arp_util.debug('=======================================================');
1313 arp_util.debug(' PL SQL TABLE ( INPUT PARAMETERS ........)+ ');
1314 arp_util.debug('=======================================================');
1315 arp_util.debug('create_linelevel_adjustment: ' || 'Pl Sql Table is empty ..
1316 All Lines ');
1317 END IF;
1318 Else
1319 IF PG_DEBUG in ('Y', 'C') THEN
1320 arp_util.debug('No of records in PLSQL Table
1321 =>'||to_char(p_llca_adj_trx_lines_tbl.count));
1322 END IF;
1323 For i in p_llca_adj_trx_lines_tbl.FIRST..p_llca_adj_trx_lines_tbl.LAST
1324 Loop
1325 Insert into ar_llca_adj_trx_lines_gt
1326 ( customer_trx_id,
1327 customer_trx_line_id,
1328 receivables_trx_id,
1329 line_amount
1330 )
1331 values
1332 (
1333 p_customer_trx_id,
1334 p_llca_adj_trx_lines_tbl(i).customer_trx_line_id,
1335 p_llca_adj_trx_lines_tbl(i).receivables_trx_id,
1336 p_llca_adj_trx_lines_tbl(i).line_amount
1337 );
1338
1339 IF PG_DEBUG in ('Y', 'C') THEN
1340 arp_util.debug('=======================================================');
1341 arp_util.debug(' Line .............=> '||to_char(i));
1342 arp_util.debug('customer_trx_id => '||to_char(p_customer_trx_id));
1343 arp_util.debug('customer_trx_line_id => '||to_char(p_llca_adj_trx_lines_tbl(i).customer_trx_line_id));
1344 arp_util.debug('line_amount => '||to_char(p_llca_adj_trx_lines_tbl(i).line_amount));
1345 arp_util.debug('receivables_trx_id => '||to_char(p_llca_adj_trx_lines_tbl(i).receivables_trx_id));
1346 arp_util.debug('=======================================================');
1347 END IF;
1348 End Loop;
1349 End If;
1350
1351 IF PG_DEBUG in ('Y', 'C') THEN
1352 arp_util.debug('populate_adj_llca_gt ()- ');
1353 END IF;
1354
1358 arp_util.debug('EXCEPTION: (populate_adj_llca_gt)');
1355 EXCEPTION
1356 WHEN others THEN
1357 IF PG_DEBUG in ('Y', 'C') THEN
1359 END IF;
1360 p_return_status := FND_API.G_RET_STS_ERROR;
1361 raise;
1362 End populate_adj_llca_gt;
1363
1364
1365 /*===========================================================================+
1366 | PROCEDURE |
1367 | validate_hdr_level |
1368 | |
1369 | DESCRIPTION |
1370 | This is the validate hdr routine for Line level adjustment |
1371 | |
1372 | |
1373 | SCOPE - PRIVATE |
1374 | |
1375 | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED |
1376 | |
1377 | |
1378 | |
1379 | ARGUMENTS : IN: |
1380 | p_adj_rec |
1381 | |
1382 | OUT: |
1383 | p_return_status |
1384 | |
1385 | IN/ OUT: |
1386 | |
1387 | |
1388 | |
1389 | RETURNS : NONE |
1390 | |
1391 | NOTES |
1392 | |
1393 | MODIFICATION HISTORY |
1394 | mpsingh 12-feb-2008 Created |
1395 | |
1396 +===========================================================================*/
1397
1398 PROCEDURE validate_hdr_level (
1399 p_adj_rec IN ar_adjustments%rowtype,
1400 p_return_status OUT NOCOPY VARCHAR2)
1401 IS
1402
1403
1404 l_return_status varchar2(1);
1405 ll_installment number := 0;
1406
1407 -- Legacy status
1411 ll_mfar_adj varchar2(1);
1408 ll_leg_app varchar2(1);
1409 ll_mfar_app varchar2(1);
1410 ll_leg_adj varchar2(1);
1412
1413 BEGIN
1414 IF PG_DEBUG in ('Y', 'C') THEN
1415 arp_util.debug('validate_hdr_level ()+ ');
1416 END IF;
1417
1418 p_return_status := FND_API.G_RET_STS_SUCCESS;
1419
1420
1421 IF p_adj_rec.type NOT IN ('LINE')
1422 THEN
1423
1424 l_return_status := FND_API.G_RET_STS_ERROR ;
1425 FND_MESSAGE.SET_NAME ('AR', 'AR_ADJ_API_TYPE_DISALLOW');
1426 FND_MESSAGE.SET_TOKEN ( 'TYPE', p_adj_rec.TYPE ) ;
1427 FND_MSG_PUB.ADD ;
1428
1429 IF PG_DEBUG in ('Y', 'C') THEN
1430 arp_util.debug('create_linelevel_adjustment : ' || 'Error(s) occurred. Rolling back and setting status to ERROR');
1431 arp_util.debug('create_linelevel_adjustment : ' || 'line level adjustment can only allowed for type LINE');
1432 END IF;
1433
1434 END IF;
1435
1436 IF p_adj_rec.customer_trx_line_id IS NOT NULL
1437 THEN
1438
1439 FND_MESSAGE.SET_NAME ('AR', 'AR_ADJ_API_CUST_LINE_ID_IG');
1440 FND_MESSAGE.SET_TOKEN ( 'CUSTOMER_TRX_LINE_ID', p_adj_rec.customer_trx_line_id ) ;
1441 FND_MSG_PUB.ADD ;
1442
1443 IF PG_DEBUG in ('Y', 'C') THEN
1444 arp_util.debug('create_linelevel_adjustment : ' || 'Warning(s) occurred. Ignoring header level customer trx line id');
1445
1446 END IF;
1447
1448 END IF;
1449
1450
1451 IF p_adj_rec.receivables_trx_id IS NOT NULL
1452 THEN
1453
1454 FND_MESSAGE.SET_NAME ('AR', 'AR_ADJ_API_RECV_TRX_ID_IG');
1455 FND_MESSAGE.SET_TOKEN ( 'RECEIVABLES_TRX_ID', p_adj_rec.receivables_trx_id ) ;
1456 FND_MSG_PUB.ADD ;
1457
1458 IF PG_DEBUG in ('Y', 'C') THEN
1459 arp_util.debug('create_linelevel_adjustment : ' || 'Warning(s) occurred. Ignoring header level receivables trx id');
1460
1461 END IF;
1462
1463 END IF;
1464
1465 IF p_adj_rec.amount IS NOT NULL
1466 THEN
1467 FND_MESSAGE.SET_NAME ('AR', 'AR_ADJ_API_AMOUNT_IG');
1468 FND_MESSAGE.SET_TOKEN ( 'AMOUNT', p_adj_rec.amount ) ;
1469 FND_MSG_PUB.ADD ;
1470
1471 IF PG_DEBUG in ('Y', 'C') THEN
1472 arp_util.debug('create_linelevel_adjustment : ' || 'Warning(s) occurred. Ignoring header level Amount');
1473
1474 END IF;
1475
1476 END IF;
1477
1478
1479 /* Multiple Installment transaction not allowed at line-level */
1480 select count(*) into ll_installment
1481 from ar_payment_schedules
1482 where class in ('INV','DM')
1483 and customer_trx_id = p_adj_rec.customer_trx_id;
1484
1485 IF nvl(ll_installment,0) > 1
1486 THEN
1487 l_return_status := FND_API.G_RET_STS_ERROR ;
1488 FND_MESSAGE.SET_NAME ('AR', 'AR_LL_ADJ_INSTALL_NOT_ALLOWED');
1489 FND_MESSAGE.SET_TOKEN ( 'CUST_TRX_ID', p_adj_rec.customer_trx_id ) ;
1490 FND_MSG_PUB.ADD ;
1491 IF PG_DEBUG in ('Y', 'C') THEN
1492 arp_util.debug('create_linelevel_adjustment : ' || 'Error(s) occurred. Rolling back and setting status to ERROR');
1493 arp_util.debug('create_linelevel_adjustment : ' || 'Multiple Installment transaction not allowed at line-level');
1494 END IF;
1495
1496 END IF;
1497
1498 /* Legacy data with activity not allowed at line-level */
1499 Begin
1500 arp_det_dist_pkg.check_legacy_status
1501 (p_trx_id => p_adj_rec.customer_trx_id,
1502 x_11i_adj => ll_leg_adj,
1503 x_mfar_adj => ll_mfar_adj,
1504 x_11i_app => ll_leg_app,
1505 x_mfar_app => ll_mfar_app );
1506 IF (ll_leg_adj = 'Y') OR (ll_leg_app = 'Y')
1507 THEN
1508 l_return_status := FND_API.G_RET_STS_ERROR ;
1509 FND_MESSAGE.SET_NAME ('AR', 'AR_LL_ADJ_LEGACY_NOT_ALLOWED');
1510 FND_MESSAGE.SET_TOKEN ( 'CUST_TRX_ID', p_adj_rec.customer_trx_id ) ;
1511 FND_MSG_PUB.ADD ;
1512 IF PG_DEBUG in ('Y', 'C') THEN
1513 arp_util.debug('create_linelevel_adjustment : ' || 'Error(s) occurred. Rolling back and setting status to ERROR');
1514 arp_util.debug('create_linelevel_adjustment : ' || 'Legacy data with activity not allowed at line-level');
1515 END IF;
1516
1517 END IF;
1518
1519 Exception
1520 when others then
1521 p_return_status := FND_API.G_RET_STS_ERROR;
1522 raise;
1523 End;
1524
1525 p_return_status := l_return_status;
1526
1527 IF PG_DEBUG in ('Y', 'C') THEN
1528 arp_util.debug('validate_hdr_level ()- ');
1529 END IF;
1530
1531 EXCEPTION
1532 when others then
1533 IF PG_DEBUG in ('Y', 'C') THEN
1534 arp_util.debug('EXCEPTION: (validate_hdr_level)');
1535 END IF;
1536 p_return_status := FND_API.G_RET_STS_ERROR;
1537 raise;
1538
1539 END validate_hdr_level;
1540
1541
1542
1543 /*===========================================================================+
1544 | PROCEDURE |
1545 | Create_Adjustment |
1546 | |
1547 | DESCRIPTION |
1548 | This is the main routine that creates adjustment |
1549 | |
1550 | SCOPE - PUBLIC |
1551 | |
1552 | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED |
1553 | fnd_api.compatible_api_call |
1554 | fnd_api.g_exc_unexpected_error |
1555 | fnd_api.g_ret_sts_error |
1556 | fnd_api.g_ret_sts_error |
1557 | fnd_api.g_ret_sts_success |
1558 | fnd_api.to_boolean |
1559 | fnd_msg_pub.check_msg_level |
1560 | fnd_msg_pub.count_and_get |
1561 | fnd_msg_pub.initialize |
1562 | ar_adjvalidate_pvt.Init_Context_Rec |
1563 | ar_adjvalidate_pvt.Cache_Details |
1564 | |
1565 | ARGUMENTS : IN: |
1566 | p_api_name |
1570 | p_validation_level |
1567 | p_api_version |
1568 | p_init_msg_list |
1569 | p_commit |
1571 | p_adj_rec |
1572 | p_chk_approval_limits |
1573 | p_check_amount |
1574 | OUT: |
1575 | p_return_status |
1576 | p_msg_count |
1577 | p_msg_data |
1578 | p_new_adjust_number |
1579 | p_new_adjust_id |
1580 | |
1581 | IN/ OUT: |
1582 | |
1583 | |
1584 | |
1585 | RETURNS : NONE |
1586 | |
1587 | NOTES |
1588 | |
1589 | MODIFICATION HISTORY |
1590 | Vivek Halder 30-JUN-97 Created |
1591 | Saloni Shah 03-FEB-00 Changes for the BR/BOE project has been made.|
1592 | Two new IN parameters have been added: |
1593 | - p_chk_approval_limits and p_check_amount|
1594 | These parameters are passed to |
1595 | Validate_Adj_Insert procedure. |
1596 | p_chk_approval_limits flag indicates whether |
1597 | the adjustment amount should be validated |
1598 | against the users approval limits or not. |
1599 | p_check_amount is set to 'F' in case of |
1600 | adjustment reversal only, this flag |
1601 | when set to 'F' indicates that even if the |
1602 | adjustment type is 'INVOICE'the |
1603 | amount_due_remaining will not be zero. |
1604 | SNAMBIAR 04-May-00 Bug 1290698 |
1605 | Added Proration logic for partial payments |
1606 | SNAMBIAR 05-Sep-00 Bug 1392055 - Call prorate routine only when
1607 | PS.amount_due_remaining > 0
1608 | SNAMBIAR 27-Sep-00 Added new parameters p_called_from and
1609 | p_old_adj_id for reverse
1610 | AMMISHRA 13-Feb-02 Set l_override_flag to Y if CCID is
1611 | overridden through ADjustment API.Then the
1612 | l_override_flag is passed to insert_adjustment
1613 | procedure.
1614 +===========================================================================*/
1615
1616 PROCEDURE Create_Adjustment (
1617 p_api_name IN varchar2,
1618 p_api_version IN number,
1619 p_init_msg_list IN varchar2 := FND_API.G_FALSE,
1620 p_commit_flag IN varchar2 := FND_API.G_FALSE,
1621 p_validation_level IN number := FND_API.G_VALID_LEVEL_FULL,
1622 p_msg_count OUT NOCOPY number,
1623 p_msg_data OUT NOCOPY varchar2,
1624 p_return_status OUT NOCOPY varchar2 ,
1625 p_adj_rec IN ar_adjustments%rowtype,
1626 p_chk_approval_limits IN varchar2 := FND_API.G_TRUE,
1627 p_check_amount IN varchar2 := FND_API.G_TRUE,
1628 p_move_deferred_tax IN varchar2,
1629 p_new_adjust_number OUT NOCOPY ar_adjustments.adjustment_number%type,
1630 p_new_adjust_id OUT NOCOPY ar_adjustments.adjustment_id%type,
1631 p_called_from IN varchar2,
1632 p_old_adjust_id IN ar_adjustments.adjustment_id%type,
1633 p_org_id IN NUMBER DEFAULT NULL
1634 ) IS
1635
1636 l_api_name CONSTANT VARCHAR2(20) := 'AR_ADJUST_PUB';
1637 l_api_version CONSTANT NUMBER := 1.0;
1638
1639 l_hsec VARCHAR2(10);
1640 l_status number;
1641
1642 l_inp_adj_rec ar_adjustments%rowtype;
1643 l_app_ps_rec ar_payment_schedules%rowtype;
1644
1645 o_adjustment_number ar_adjustments.adjustment_number%type;
1646 o_adjustment_id ar_adjustments.adjustment_id%type;
1647 l_return_status varchar2(1);
1648 l_chk_approval_limits varchar2(1);
1649 l_check_amount varchar2(1);
1650
1651 l_override_flag varchar2(1); --Bug 2183969
1652 l_org_return_status VARCHAR2(1);
1653 l_org_id NUMBER;
1654
1655 BEGIN
1656
1657
1658 IF (FND_MSG_PUB.Check_Msg_Level (G_MSG_LOW)) THEN
1659 select hsecs
1660 into G_START_TIME
1661 from v$timer;
1662 END IF;
1663
1664 /*------------------------------------+
1665 | Standard start of API savepoint |
1666 +------------------------------------*/
1667
1668 SAVEPOINT ar_adjust_PUB;
1669
1670 /*--------------------------------------------------+
1671 | Standard call to check for call compatibility |
1672 +--------------------------------------------------*/
1673
1674 IF NOT FND_API.Compatible_API_Call(
1675 l_api_version,
1676 p_api_version,
1677 l_api_name,
1678 G_PKG_NAME
1679 )
1680 THEN
1681 IF PG_DEBUG in ('Y', 'C') THEN
1682 arp_util.debug('Create_Adjustment: ' || 'Compatility error occurred.');
1683 END IF;
1684 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1685 END IF;
1686
1687 /*-------------------------------------------------------------+
1688 | Initialize message list if p_init_msg_list is set to TRUE |
1689 +-------------------------------------------------------------*/
1690
1691 IF FND_API.to_Boolean( p_init_msg_list )
1692 THEN
1693 FND_MSG_PUB.initialize;
1694 END IF;
1695
1696 -- arp_util.enable_debug(100000);
1697
1698 IF PG_DEBUG in ('Y', 'C') THEN
1699 arp_util.debug('Create_Adjustment()+ ');
1700 END IF;
1701
1702 /*-----------------------------------------+
1703 | Initialize return status to SUCCESS |
1704 +-----------------------------------------*/
1705
1706 p_return_status := FND_API.G_RET_STS_SUCCESS;
1707
1708 /* SSA change */
1709 l_org_id := p_org_id;
1710 l_org_return_status := FND_API.G_RET_STS_SUCCESS;
1711 ar_mo_cache_utils.set_org_context_in_api(p_org_id =>l_org_id,
1712 p_return_status =>l_org_return_status);
1713 IF l_org_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1714 p_return_status := FND_API.G_RET_STS_ERROR;
1715 ELSE
1716
1717 /*---------------------------------------------+
1718 | ========== Start of API Body ========== |
1719 +---------------------------------------------*/
1720
1721 /*--------------------------------------------+
1722 | Copy the input adjustment record to local |
1723 | variable to allow changes to it |
1724 +--------------------------------------------*/
1725 l_inp_adj_rec := p_adj_rec ;
1726
1727
1728 /*------------------------------------------------+
1729 | Initialize the profile options and cache data |
1730 +------------------------------------------------*/
1731
1732 ar_adjvalidate_pvt.Init_Context_Rec (
1733 p_validation_level,
1734 l_return_status
1735 );
1736
1737 /*---------------------------------------------------+
1738 | Check the return status |
1739 /*---------------------------------------------------+
1740
1741
1742 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
1743 THEN
1744 p_return_status := l_return_status ;
1745 IF PG_DEBUG in ('Y', 'C') THEN
1746 arp_util.debug('Create_Adjustment: ' || ' Init_context_rec has errors ' );
1747 END IF;
1748 END IF;
1749
1750
1751 /*------------------------------------------------+
1752 | Cache details |
1753 +------------------------------------------------*/
1754
1755 ar_adjvalidate_pvt.Cache_Details (
1756 l_return_status
1757 );
1758
1759 /*---------------------------------------------------+
1760 | Check the return status |
1761 /*---------------------------------------------------+
1762
1763 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
1764 THEN
1765 p_return_status := l_return_status ;
1766 IF PG_DEBUG in ('Y', 'C') THEN
1767 arp_util.debug('Create_Adjustment: ' || ' Cache_details has errors ' );
1768 END IF;
1769 END IF;
1770
1771 /*------------------------------------------+
1772 | Validate the input details |
1773 | Do not continue if there are errors. |
1774 +------------------------------------------*/
1775
1776 /*--------------------------------------------+
1777 | Change for the BOE/BR project has been made |
1778 | parameters p_chk_approval_limits and |
1779 | p_check_amount are being passed. |
1780 | |
1781 | p_check_amount will only be 'F' in case of |
1782 | reversal of adjustments |
1783 +---------------------------------------------*/
1784
1785 /*--------------------------------------------------+
1786 | Bug 1290698- If Partial partial amount is passed |
1787 | Calculate prorated amounts remaining.Need not |
1788 | prorate while reversing |
1789 +--------------------------------------------------*/
1790
1791 IF p_adj_rec.amount is NOT NULL and p_adj_rec.type = 'INVOICE'
1792 and p_adj_rec.created_from <> 'REVERSE_ADJUSTMENT'
1793 and p_check_amount = 'F' THEN
1794
1795 /*--------------------------------------------+
1796 |Fetch Payment schedule record for prorating|
1797 +--------------------------------------------*/
1798
1799 arp_ps_pkg.fetch_p(l_inp_adj_rec.payment_schedule_id,l_app_ps_rec);
1800
1801 /*------------------------------------------+
1802 | Call Prorate calculation routine |
1803 +------------------------------------------*/
1804 --Bug 1392055 - Prorate only if amount_due_remaining > 0
1805 -- Bug 3461288 - change condition for prorating to <> 0, fix provided
1806 -- in 1392055 prevented prorating for Credit memos
1807
1808 IF NVL(l_app_ps_rec.amount_due_remaining,0) <> 0 THEN
1809
1810 ARP_APP_CALC_PKG.calc_applied_and_remaining(
1811 l_inp_adj_rec.amount,
1812 3, -- Prorate all
1813 l_app_ps_rec.invoice_currency_code,
1814 l_app_ps_rec.amount_line_items_remaining,
1815 l_app_ps_rec.tax_remaining,
1816 l_app_ps_rec.freight_remaining,
1817 l_app_ps_rec.receivables_charges_remaining,
1818 l_inp_adj_rec.line_adjusted,
1819 l_inp_adj_rec.tax_adjusted,
1820 l_inp_adj_rec.freight_adjusted,
1821 l_inp_adj_rec.receivables_charges_adjusted,
1822 l_inp_adj_rec.created_from);
1823 END IF;
1824 END IF;
1825
1826 l_chk_approval_limits := p_chk_approval_limits;
1827 l_check_amount := p_check_amount;
1828
1829 IF (l_chk_approval_limits IS NULL) THEN
1830 l_chk_approval_limits := FND_API.G_TRUE;
1831 END IF;
1832
1833 IF (l_check_amount IS NULL) THEN
1834 l_check_amount := FND_API.G_TRUE;
1835 END IF;
1836
1837 ar_adjust_pub.Validate_Adj_Insert(
1838 l_inp_adj_rec,
1839 l_chk_approval_limits,
1840 l_check_amount,
1841 l_return_status
1842 );
1843
1844 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
1845 THEN
1846 p_return_status := l_return_status ;
1847 IF PG_DEBUG in ('Y', 'C') THEN
1848 arp_util.debug('Create_Adjustment: ' || 'Validation error(s) occurred. '||
1849 'and setting status to ERROR');
1850 END IF;
1851 END IF;
1852
1853
1854 /*-----------------------------------------------+
1855 | Handling all the validation exceptions |
1856 +-----------------------------------------------*/
1857 IF (p_return_status = FND_API.G_RET_STS_ERROR)
1858 THEN
1859 RAISE FND_API.G_EXC_ERROR;
1860
1861 ELSIF (p_return_status = FND_API.G_RET_STS_UNEXP_ERROR)
1862 THEN
1863 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1864 END IF;
1865
1866
1867 /*-----------------------------------------------+
1868 | Build up remaining data for the entity handler |
1869 | Reset attributes which should not be populated |
1870 +-----------------------------------------------*/
1871
1872 ar_adjust_pub.Set_Remaining_Attributes (
1873 l_inp_adj_rec,
1874 l_return_status
1875 ) ;
1876
1877 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
1878 THEN
1879
1880 p_return_status := l_return_status ;
1881 IF PG_DEBUG in ('Y', 'C') THEN
1882 arp_util.debug('Create_Adjustment: ' ||
1883 'Validation error(s) occurred. Rolling back '||
1884 'and setting status to ERROR');
1885 END IF;
1886
1887 IF (p_return_status = FND_API.G_RET_STS_ERROR)
1888 THEN
1889 RAISE FND_API.G_EXC_ERROR;
1890 ELSIF (p_return_status = FND_API.G_RET_STS_UNEXP_ERROR)
1891 THEN
1892 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1893 END IF;
1894 END IF;
1895
1896 /*-----------------------------------------------+
1897 | Call the entity Handler for insert |
1898 +-----------------------------------------------*/
1899
1900 /*Bug 2183969 set l_override_flag to Y and passed to
1901 insert_adjustment function if code_combination_id is
1902 overridden through Adjustment API.
1903 */
1904
1905
1906 IF (l_inp_adj_rec.code_combination_id is NOT NULL) THEN
1907 l_override_flag := 'Y';
1908 END IF;
1909
1910 IF PG_DEBUG in ('Y', 'C') THEN
1911 arp_util.debug('Create_Adjustment: ' || 'l_inp_adj_rec.line_adjusted = ' || to_char(l_inp_adj_rec.line_adjusted));
1912 arp_util.debug('Create_Adjustment: ' || 'l_inp_adj_rec.tax_adjusted = ' || to_char(l_inp_adj_rec.tax_adjusted));
1913 END IF;
1914
1915 BEGIN
1916 arp_process_adjustment.insert_adjustment (
1917 'DUMMY',
1918 '1',
1919 l_inp_adj_rec,
1920 o_adjustment_number,
1921 o_adjustment_id,
1922 l_check_amount,
1923 p_move_deferred_tax,
1924 p_called_from,
1925 p_old_adjust_id,
1926 l_override_flag
1927 ) ;
1928 /* Bug 4910860
1929 Validate if the accounting entries balance */
1930 arp_balance_check.Check_Adj_Balance(o_adjustment_id,p_adj_rec.request_id,'Y');
1931
1932 EXCEPTION
1933 WHEN OTHERS THEN
1934 /*---------------------------------------------------+
1935 | Rollback to the defined Savepoint |
1936 +---------------------------------------------------*/
1937
1938 ROLLBACK TO ar_adjust_PUB;
1939 p_return_status := FND_API.G_RET_STS_ERROR ;
1940
1941 FND_MESSAGE.set_name( 'AR', 'GENERIC_MESSAGE' );
1942 FND_MESSAGE.set_token( 'GENERIC_TEXT', 'arp_process_adjustment.insert_adjustment exception: '||SQLERRM );
1943 --2920926
1944 FND_MSG_PUB.ADD;
1945 /*--------------------------------------------------+
1946 | Get message count and if 1, return message data |
1947 +---------------------------------------------------*/
1948
1949 FND_MSG_PUB.Count_And_Get(
1950 p_encoded => FND_API.G_FALSE,
1951 p_count => p_msg_count,
1952 p_data => p_msg_data
1953 );
1954 IF PG_DEBUG in ('Y', 'C') THEN
1955 arp_util.debug('Create_Adjustment: ' ||
1956 'Error in Insert Entity handler. Rolling back ' ||
1957 'and setting status to ERROR');
1958 END IF;
1959 RETURN;
1960
1961 END ;
1962
1963 p_new_adjust_id := o_adjustment_id ;
1964 p_new_adjust_number := o_adjustment_number ;
1965
1966 /*-------------------------------------------+
1967 | ========== End of API Body ========== |
1968 +-------------------------------------------*/
1969 END IF;
1970
1971 /*---------------------------------------------------+
1972 | Get message count and if 1, return message data |
1973 +---------------------------------------------------*/
1974
1975 FND_MSG_PUB.Count_And_Get(
1976 p_encoded => FND_API.G_FALSE,
1977 p_count => p_msg_count,
1978 p_data => p_msg_data
1979 );
1980
1981 /*--------------------------------+
1982 | Standard check of p_commit |
1983 +--------------------------------*/
1984
1985 IF FND_API.To_Boolean( p_commit_flag )
1986 THEN
1987 IF PG_DEBUG in ('Y', 'C') THEN
1988 arp_util.debug('Create_Adjustment: ' || 'committing');
1989 END IF;
1990 Commit;
1991 END IF;
1992
1993 IF PG_DEBUG in ('Y', 'C') THEN
1994 arp_util.debug('Create_Adjustment()- ');
1995 END IF;
1996
1997 IF (FND_MSG_PUB.Check_Msg_Level (G_MSG_LOW)) THEN
1998 select TO_CHAR( (hsecs - G_START_TIME) / 100)
1999 into l_hsec
2000 from v$timer;
2001 IF PG_DEBUG in ('Y', 'C') THEN
2002 arp_util.debug('Create_Adjustment: ' || 'Elapsed Time : '||l_hsec||' seconds');
2003 END IF;
2004 END IF;
2005
2006 EXCEPTION
2007 WHEN FND_API.G_EXC_ERROR THEN
2008
2009 IF PG_DEBUG in ('Y', 'C') THEN
2010 arp_util.debug('Create_Adjustment: ' || SQLCODE);
2011 arp_util.debug('Create_Adjustment: ' || SQLERRM);
2012 END IF;
2013
2014 ROLLBACK TO ar_adjust_PUB;
2015 p_return_status := FND_API.G_RET_STS_ERROR ;
2016 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
2017 p_count => p_msg_count,
2018 p_data => p_msg_data
2019 );
2020
2021 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2022
2023 IF PG_DEBUG in ('Y', 'C') THEN
2024 arp_util.debug('Create_Adjustment: ' || SQLERRM);
2025 END IF;
2026 ROLLBACK TO ar_adjust_PUB ;
2027 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2028 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
2029 p_count => p_msg_count,
2030 p_data => p_msg_data
2031 );
2032
2033 WHEN OTHERS THEN
2034
2035 /*-------------------------------------------------------+
2039 +-------------------------------------------------------*/
2036 | Handle application errors that result from trapable |
2037 | error conditions. The error messages have already |
2038 | been put on the error stack. |
2040
2041 IF (SQLCODE = -20001)
2042 THEN
2043 p_return_status := FND_API.G_RET_STS_ERROR ;
2044 ROLLBACK TO ar_adjust_PUB;
2045 IF PG_DEBUG in ('Y', 'C') THEN
2046 arp_util.debug('Create_Adjustment: ' ||
2047 'Completion validation error(s) occurred. ' ||
2048 'Rolling back and setting status to ERROR');
2049 END IF;
2050
2051 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
2052 p_count => p_msg_count,
2053 p_data => p_msg_data
2054 );
2055 RETURN;
2056 ELSE
2057 NULL;
2058 END IF;
2059
2060 arp_util.disable_debug;
2061
2062 END Create_Adjustment;
2063
2064
2065
2066 /*===========================================================================+
2067 | PROCEDURE |
2068 | create_linelevel_adjustment |
2069 | |
2070 | DESCRIPTION |
2071 | This is the main routine that creates adjustment |
2072 | |
2073 | SCOPE - PUBLIC |
2074 | |
2075 | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED |
2076 | fnd_api.compatible_api_call |
2077 | fnd_api.g_exc_unexpected_error |
2078 | fnd_api.g_ret_sts_error |
2079 | fnd_api.g_ret_sts_error |
2080 | fnd_api.g_ret_sts_success |
2081 | fnd_api.to_boolean |
2082 | fnd_msg_pub.check_msg_level |
2083 | fnd_msg_pub.count_and_get |
2084 | fnd_msg_pub.initialize |
2085 | ar_adjvalidate_pvt.Init_Context_Rec |
2086 | ar_adjvalidate_pvt.Cache_Details |
2087 | |
2088 | ARGUMENTS : IN: |
2089 | p_api_name |
2090 | p_api_version |
2091 | p_init_msg_list |
2092 | p_commit |
2093 | p_validation_level |
2094 | p_adj_rec |
2095 | p_chk_approval_limits |
2096 | p_llca_adj_trx_lines_tbl |
2097 | p_check_amount |
2098 | OUT: |
2099 | p_return_status |
2100 | p_msg_count |
2101 | p_msg_data |
2102 | p_new_adjust_number |
2103 | p_new_adjust_id |
2104 | |
2105 | IN/ OUT: |
2106 | |
2107 | |
2108 | |
2109 | RETURNS : NONE |
2110 | |
2111 | NOTES |
2112 | |
2113 | MODIFICATION HISTORY |
2114 | mpsingh 04-FEB-2008 Created |
2115 | |
2116 +===========================================================================*/
2117
2118 PROCEDURE create_linelevel_adjustment (
2119 p_api_name IN varchar2,
2120 p_api_version IN number,
2121 p_init_msg_list IN varchar2 := FND_API.G_FALSE,
2122 p_commit_flag IN varchar2 := FND_API.G_FALSE,
2126 p_return_status OUT NOCOPY varchar2 ,
2123 p_validation_level IN number := FND_API.G_VALID_LEVEL_FULL,
2124 p_msg_count OUT NOCOPY number,
2125 p_msg_data OUT NOCOPY varchar2,
2127 p_adj_rec IN ar_adjustments%rowtype,
2128 p_chk_approval_limits IN varchar2 := FND_API.G_TRUE,
2129 p_llca_adj_trx_lines_tbl IN llca_adj_trx_line_tbl_type,
2130 p_check_amount IN varchar2 := FND_API.G_TRUE,
2131 p_move_deferred_tax IN varchar2,
2132 p_llca_adj_create_tbl_type OUT NOCOPY llca_adj_create_tbl_type,
2133 p_called_from IN varchar2,
2134 p_old_adjust_id IN ar_adjustments.adjustment_id%type,
2135 p_org_id IN NUMBER DEFAULT NULL
2136 ) IS
2137
2138 l_api_name CONSTANT VARCHAR2(20) := 'AR_ADJUST_PUB';
2139 l_api_version CONSTANT NUMBER := 1.0;
2140
2141 l_hsec VARCHAR2(10);
2142 l_status number;
2143
2144 l_inp_adj_rec ar_adjustments%rowtype;
2145 l_app_ps_rec ar_payment_schedules%rowtype;
2146
2147 o_adjustment_number ar_adjustments.adjustment_number%type;
2148 o_adjustment_id ar_adjustments.adjustment_id%type;
2149 l_return_status varchar2(1);
2150 l_gt_return_status varchar2(1);
2151 l_hdr_return_status varchar2(1);
2152 l_line_return_status varchar2(1);
2153 l_chk_approval_limits varchar2(1);
2154 l_check_amount varchar2(1);
2155
2156 l_override_flag varchar2(1);
2157 l_org_return_status VARCHAR2(1);
2158 l_org_id NUMBER;
2159 l_adj_int_count number := 0;
2160 l_chk_count number := 0;
2161
2162 cursor gt_adj_lines_cur (p_cust_trx_id in number) is
2163 select * from ar_llca_adj_trx_lines_gt
2164 where customer_trx_id = p_cust_trx_id;
2165
2166
2167 BEGIN
2168
2169
2170 IF (FND_MSG_PUB.Check_Msg_Level (G_MSG_LOW)) THEN
2171 select hsecs
2172 into G_START_TIME
2173 from v$timer;
2174 END IF;
2175
2176 /*------------------------------------+
2177 | Standard start of API savepoint |
2178 +------------------------------------*/
2179
2180 SAVEPOINT ar_adjust_line_PUB;
2181
2182 /*--------------------------------------------------+
2183 | Standard call to check for call compatibility |
2184 +--------------------------------------------------*/
2185
2186 IF NOT FND_API.Compatible_API_Call(
2187 l_api_version,
2188 p_api_version,
2189 l_api_name,
2190 G_PKG_NAME
2191 )
2192 THEN
2193 IF PG_DEBUG in ('Y', 'C') THEN
2194 arp_util.debug('create_linelevel_adjustment : ' || 'Compatility error occurred.');
2195 END IF;
2196 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2197 END IF;
2198
2199 /*-------------------------------------------------------------+
2200 | Initialize message list if p_init_msg_list is set to TRUE |
2201 +-------------------------------------------------------------*/
2202
2203 IF FND_API.to_Boolean( p_init_msg_list )
2204 THEN
2205 FND_MSG_PUB.initialize;
2206 END IF;
2207
2208 -- arp_util.enable_debug(100000);
2209
2210 IF PG_DEBUG in ('Y', 'C') THEN
2211 arp_util.debug('create_linelevel_adjustment()+ ');
2212 END IF;
2213
2214 /*-----------------------------------------+
2215 | Initialize return status to SUCCESS |
2216 +-----------------------------------------*/
2217
2218 p_return_status := FND_API.G_RET_STS_SUCCESS;
2219
2220 /* SSA change */
2221 l_org_id := p_org_id;
2222 l_org_return_status := FND_API.G_RET_STS_SUCCESS;
2223 ar_mo_cache_utils.set_org_context_in_api(p_org_id =>l_org_id,
2224 p_return_status =>l_org_return_status);
2225 IF l_org_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2226 p_return_status := FND_API.G_RET_STS_ERROR;
2227 ELSE
2228 --Verify whether line level adjustment is allowed for given org/invoice
2229 IF NOT arp_standard.is_llca_allowed(l_org_id,p_adj_rec.customer_trx_id) THEN
2230 FND_MESSAGE.set_name('AR', 'AR_SUMMARIZED_DIST_NO_LLCA_ADJ');
2231 FND_MSG_PUB.Add;
2232 l_return_status := FND_API.G_RET_STS_ERROR;
2233 RAISE FND_API.G_EXC_ERROR;
2234 END IF;
2235
2236 /*---------------------------------------------+
2237 | ========== Start of API Body ========== |
2238 +---------------------------------------------*/
2239
2240 /*--------------------------------------------+
2241 | Copy the input adjustment record to local |
2242 | variable to allow changes to it |
2243 +--------------------------------------------*/
2244 l_inp_adj_rec := p_adj_rec ;
2245
2246
2247 /*------------------------------------------------+
2248 | Initialize the profile options and cache data |
2249 +------------------------------------------------*/
2250
2251 ar_adjvalidate_pvt.Init_Context_Rec (
2252 p_validation_level,
2253 l_return_status
2254 );
2255
2256 /*---------------------------------------------------+
2257 | Check the return status |
2258 /*---------------------------------------------------+
2259
2260
2261 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
2262 THEN
2263 p_return_status := l_return_status ;
2267 END IF;
2264 IF PG_DEBUG in ('Y', 'C') THEN
2265 arp_util.debug('create_linelevel_adjustment: ' || ' Init_context_rec has errors ' );
2266 END IF;
2268
2269
2270 /*------------------------------------------------+
2271 | Cache details |
2272 +------------------------------------------------*/
2273
2274 ar_adjvalidate_pvt.Cache_Details (
2275 l_return_status
2276 );
2277
2278 /*---------------------------------------------------+
2279 | Check the return status |
2280 /*---------------------------------------------------+
2281
2282 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
2283 THEN
2284 p_return_status := l_return_status ;
2285 IF PG_DEBUG in ('Y', 'C') THEN
2286 arp_util.debug('create_linelevel_adjustment: ' || ' Cache_details has errors ' );
2287 END IF;
2288 END IF;
2289
2290 /*------------------------------------------+
2291 | Validate the input details |
2292 | Do not continue if there are errors. |
2293 +------------------------------------------*/
2294
2295 /*--------------------------------------------+
2296 | Change for the BOE/BR project has been made |
2297 | parameters p_chk_approval_limits and |
2298 | p_check_amount are being passed. |
2299 | |
2300 | p_check_amount will only be 'F' in case of |
2301 | reversal of adjustments |
2302 +---------------------------------------------*/
2303
2304 /*--------------------------------------------------+
2305 | Bug 1290698- If Partial partial amount is passed |
2306 | Calculate prorated amounts remaining.Need not |
2307 | prorate while reversing |
2308 +--------------------------------------------------*/
2309
2310 l_chk_approval_limits := p_chk_approval_limits;
2311 l_check_amount := p_check_amount;
2312
2313 IF (l_chk_approval_limits IS NULL) THEN
2314 l_chk_approval_limits := FND_API.G_TRUE;
2315 END IF;
2316
2317 IF (l_check_amount IS NULL) THEN
2318 l_check_amount := FND_API.G_TRUE;
2319 END IF;
2320
2321
2322 populate_adj_llca_gt (
2323 p_customer_trx_id => p_adj_rec.customer_trx_id,
2324 p_llca_adj_trx_lines_tbl => p_llca_adj_trx_lines_tbl,
2325 p_return_status => l_gt_return_status);
2326
2327
2328 IF l_gt_return_status <> FND_API.G_RET_STS_SUCCESS
2329 THEN
2330
2331 p_return_status := FND_API.G_RET_STS_ERROR ;
2332
2333 IF PG_DEBUG in ('Y', 'C') THEN
2334 arp_util.debug('create_linelevel_adjustment : ' || 'Error(s) occurred. Rolling back and setting status to ERROR');
2335 arp_util.debug('create_linelevel_adjustment : ' || 'Error while populating GT table');
2336 END IF;
2337
2338 END IF;
2339
2340 IF (p_return_status = FND_API.G_RET_STS_ERROR)
2341 THEN
2342 RAISE FND_API.G_EXC_ERROR;
2343
2344 ELSIF (p_return_status = FND_API.G_RET_STS_UNEXP_ERROR)
2345 THEN
2346 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2347 END IF;
2348
2349 /*--------------------------------------------------+
2350 | Header level Validation Call |
2351 +--------------------------------------------------*/
2352
2353
2354 validate_hdr_level (
2355 p_adj_rec,
2356 l_hdr_return_status);
2357
2358
2359 IF l_hdr_return_status <> FND_API.G_RET_STS_SUCCESS
2360 THEN
2361 p_return_status := FND_API.G_RET_STS_ERROR ;
2362
2363 IF PG_DEBUG in ('Y', 'C') THEN
2364 arp_util.debug('create_linelevel_adjustment : ' || 'Error(s) occurred. Rolling back and setting status to ERROR');
2365 arp_util.debug('create_linelevel_adjustment : ' || 'Error while populating GT table');
2366 END IF;
2367
2368 END IF;
2369
2370
2371 IF (p_return_status = FND_API.G_RET_STS_ERROR)
2372 THEN
2373 RAISE FND_API.G_EXC_ERROR;
2374
2375 ELSIF (p_return_status = FND_API.G_RET_STS_UNEXP_ERROR)
2376 THEN
2377 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2378 END IF;
2379
2380
2381 IF ( p_return_status = FND_API.G_RET_STS_SUCCESS ) -- Start of for loop processing
2382 THEN
2383
2384
2385 --For i in p_llca_adj_trx_lines_tbl.FIRST..p_llca_adj_trx_lines_tbl.LAST
2386 FOR gt_adj_lines_row IN gt_adj_lines_cur(p_adj_rec.customer_trx_id)
2387 Loop
2388
2389 /* l_inp_adj_rec.customer_trx_line_id := p_llca_adj_trx_lines_tbl(i).customer_trx_line_id;
2390 l_inp_adj_rec.receivables_trx_id := p_llca_adj_trx_lines_tbl(i).receivables_trx_id;
2391 l_inp_adj_rec.amount := p_llca_adj_trx_lines_tbl(i).line_amount;*/
2392
2393 l_line_return_status := FND_API.G_RET_STS_SUCCESS;
2394
2395
2396 l_inp_adj_rec.customer_trx_line_id := gt_adj_lines_row.customer_trx_line_id;
2397 l_inp_adj_rec.receivables_trx_id := gt_adj_lines_row.receivables_trx_id;
2398 l_inp_adj_rec.amount := gt_adj_lines_row.line_amount;
2399
2400 l_adj_int_count := l_adj_int_count + 1;
2401 p_llca_adj_create_tbl_type(l_adj_int_count).adjustment_number := 0;
2402 p_llca_adj_create_tbl_type(l_adj_int_count).adjustment_id := 0;
2403 p_llca_adj_create_tbl_type(l_adj_int_count).customer_trx_line_id := gt_adj_lines_row.customer_trx_line_id;
2404
2405 -- Check for null customer trx line id
2406 IF gt_adj_lines_row.customer_trx_line_id IS NULL -- Check for null Customer Trx Line Id
2407 THEN
2411 customer_trx_line_id,
2408 insert into ar_llca_adj_trx_errors_gt
2409 (
2410 customer_trx_id,
2412 receivables_trx_id,
2413 error_message,
2414 invalid_value
2415 )
2416 values
2417 (
2418 l_inp_adj_rec.customer_trx_id,
2419 0,
2420 l_inp_adj_rec.receivables_trx_id,
2421 'AR_RAPI_TRX_LINE_ID_INVALID ',
2422 'customer_trx_line_id'
2423 );
2424
2425 l_line_return_status := FND_API.G_RET_STS_ERROR;
2426
2427 ELSIF gt_adj_lines_row.receivables_trx_id IS NULL
2428 THEN
2429
2430 insert into ar_llca_adj_trx_errors_gt
2431 (
2432 customer_trx_id,
2433 customer_trx_line_id,
2434 receivables_trx_id,
2435 error_message,
2436 invalid_value
2437 )
2438 values
2439 (
2440 l_inp_adj_rec.customer_trx_id,
2441 l_inp_adj_rec.customer_trx_line_id,
2442 0,
2443 'AR_RAPI_RECEIVABLES_TRX_ID_INVALID ',
2444 'receivables_trx_id'
2445 );
2446
2447 l_line_return_status := FND_API.G_RET_STS_ERROR;
2448
2449 ELSE
2450
2451 ar_adjust_pub.Validate_Adj_Insert(
2452 l_inp_adj_rec,
2453 l_chk_approval_limits,
2454 l_check_amount,
2455 l_return_status,
2456 'Y'
2457 );
2458
2459 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
2460 THEN
2461 l_line_return_status := l_return_status ;
2462 IF PG_DEBUG in ('Y', 'C') THEN
2463 arp_util.debug('create_linelevel_adjustment: ' || 'Validation error(s) occurred.');
2464 END IF;
2465 END IF;
2466
2467
2468
2469 /*-----------------------------------------------+
2470 | Build up remaining data for the entity handler |
2471 | Reset attributes which should not be populated |
2472 +-----------------------------------------------*/
2473
2474
2475 IF ( l_line_return_status = FND_API.G_RET_STS_SUCCESS ) THEN
2476 ar_adjust_pub.Set_Remaining_Attributes (
2477 l_inp_adj_rec,
2478 l_return_status
2479 ) ;
2480
2481 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
2482 THEN
2483
2484 l_line_return_status := l_return_status ;
2485 IF PG_DEBUG in ('Y', 'C') THEN
2486 arp_util.debug('create_linelevel_adjustment: ' ||
2487 'Validation error(s) occurred.');
2488 END IF;
2489
2490 END IF;
2491 ELSE
2492 p_return_status := FND_API.G_RET_STS_ERROR ; -- Bug 12635650
2493
2494 END IF;
2495
2496 END IF; -- Check for null Customer Trx Line Id
2497
2498 /*-----------------------------------------------+
2499 | Call the entity Handler for insert |
2500 +-----------------------------------------------*/
2501
2502 IF ( l_line_return_status = FND_API.G_RET_STS_SUCCESS ) THEN -- Processing the adjustment
2503
2504 IF (l_inp_adj_rec.code_combination_id is NOT NULL) THEN
2505 l_override_flag := 'Y';
2506 END IF;
2507
2508 IF PG_DEBUG in ('Y', 'C') THEN
2509 arp_util.debug('create_linelevel_adjustment: ' || 'l_inp_adj_rec.line_adjusted = ' || to_char(l_inp_adj_rec.line_adjusted));
2510 arp_util.debug('create_linelevel_adjustment: ' || 'l_inp_adj_rec.tax_adjusted = ' || to_char(l_inp_adj_rec.tax_adjusted));
2511 END IF;
2512
2513 BEGIN
2514 arp_process_adjustment.insert_adjustment (
2515 'DUMMY',
2516 '1',
2517 l_inp_adj_rec,
2518 o_adjustment_number,
2519 o_adjustment_id,
2520 l_check_amount,
2521 p_move_deferred_tax,
2522 p_called_from,
2523 p_old_adjust_id,
2524 l_override_flag,
2525 'LINE'
2526 ) ;
2527 /* Bug 4910860
2528 Validate if the accounting entries balance */
2529 arp_balance_check.Check_Adj_Balance(o_adjustment_id,p_adj_rec.request_id,'Y');
2530
2531
2532 EXCEPTION
2533 WHEN OTHERS THEN
2534 /*---------------------------------------------------+
2535 | Rollback to the defined Savepoint |
2536 +---------------------------------------------------*/
2537
2538 ROLLBACK TO ar_adjust_line_PUB;
2539 p_return_status := FND_API.G_RET_STS_ERROR ;
2540
2541 FND_MESSAGE.set_name( 'AR', 'GENERIC_MESSAGE' );
2542 FND_MESSAGE.set_token( 'GENERIC_TEXT', 'arp_process_adjustment.insert_adjustment exception: '||SQLERRM );
2543 --2920926
2544 FND_MSG_PUB.ADD;
2545 /*--------------------------------------------------+
2546 | Get message count and if 1, return message data |
2547 +---------------------------------------------------*/
2548
2549 FND_MSG_PUB.Count_And_Get(
2550 p_encoded => FND_API.G_FALSE,
2551 p_count => p_msg_count,
2552 p_data => p_msg_data
2553 );
2554 IF PG_DEBUG in ('Y', 'C') THEN
2555 arp_util.debug('create_linelevel_adjustment: ' ||
2556 'Error in Insert Entity handler. Rolling back ' ||
2557 'and setting status to ERROR');
2558 END IF;
2559 RETURN;
2560
2561 END ;
2562
2563
2564
2568
2565 p_llca_adj_create_tbl_type(l_adj_int_count).adjustment_number := o_adjustment_number ;
2566 p_llca_adj_create_tbl_type(l_adj_int_count).adjustment_id := o_adjustment_id ;
2567
2569
2570
2571
2572 /*-------------------------------------------+
2573 | ========== End of API Body ========== |
2574 +-------------------------------------------*/
2575 END IF; -- END of Processing the adjustment
2576 END LOOP; -- END of table loop
2577 END IF; -- END of for loop processing
2578 END IF;
2579
2580 /*---------------------------------------------------+
2581 | Get message count and if 1, return message data |
2582 +---------------------------------------------------*/
2583
2584 FND_MSG_PUB.Count_And_Get(
2585 p_encoded => FND_API.G_FALSE,
2586 p_count => p_msg_count,
2587 p_data => p_msg_data
2588 );
2589
2590 /*--------------------------------+
2591 | Standard check of p_commit |
2592 +--------------------------------*/
2593
2594 IF FND_API.To_Boolean( p_commit_flag )
2595 THEN
2596 IF PG_DEBUG in ('Y', 'C') THEN
2597 arp_util.debug('create_linelevel_adjustment: ' || 'committing');
2598 END IF;
2599 Commit;
2600 END IF;
2601
2602 IF PG_DEBUG in ('Y', 'C') THEN
2603 arp_util.debug('create_linelevel_adjustment()- ');
2604 END IF;
2605
2606 IF (FND_MSG_PUB.Check_Msg_Level (G_MSG_LOW)) THEN
2607 select TO_CHAR( (hsecs - G_START_TIME) / 100)
2608 into l_hsec
2609 from v$timer;
2610 IF PG_DEBUG in ('Y', 'C') THEN
2611 arp_util.debug('create_linelevel_adjustment: ' || 'Elapsed Time : '||l_hsec||' seconds');
2612 END IF;
2613 END IF;
2614
2615 EXCEPTION
2616 WHEN FND_API.G_EXC_ERROR THEN
2617
2618 IF PG_DEBUG in ('Y', 'C') THEN
2619 arp_util.debug('create_linelevel_adjustment: ' || SQLCODE);
2620 arp_util.debug('create_linelevel_adjustment: ' || SQLERRM);
2621 END IF;
2622
2623 ROLLBACK TO ar_adjust_line_PUB;
2624 p_return_status := FND_API.G_RET_STS_ERROR ;
2625 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
2626 p_count => p_msg_count,
2627 p_data => p_msg_data
2628 );
2629
2630 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2631
2632 IF PG_DEBUG in ('Y', 'C') THEN
2633 arp_util.debug('create_linelevel_adjustment: ' || SQLERRM);
2634 END IF;
2635 ROLLBACK TO ar_adjust_line_PUB ;
2636 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2637 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
2638 p_count => p_msg_count,
2639 p_data => p_msg_data
2640 );
2641
2642 WHEN OTHERS THEN
2643
2644 /*-------------------------------------------------------+
2645 | Handle application errors that result from trapable |
2646 | error conditions. The error messages have already |
2647 | been put on the error stack. |
2648 +-------------------------------------------------------*/
2649
2650 IF (SQLCODE = -20001)
2651 THEN
2652 p_return_status := FND_API.G_RET_STS_ERROR ;
2653 ROLLBACK TO ar_adjust_line_PUB;
2654 IF PG_DEBUG in ('Y', 'C') THEN
2655 arp_util.debug('create_linelevel_adjustment: ' ||
2656 'Completion validation error(s) occurred. ' ||
2657 'Rolling back and setting status to ERROR');
2658 END IF;
2659
2660 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
2661 p_count => p_msg_count,
2662 p_data => p_msg_data
2663 );
2664 RETURN;
2665 ELSE
2666 NULL;
2667 END IF;
2668
2669 arp_util.disable_debug;
2670
2671 END create_linelevel_adjustment;
2672
2673
2674 /*===========================================================================+
2675 | PROCEDURE |
2676 | Modify_Adjustment |
2677 | |
2678 | DESCRIPTION |
2679 | This is the main routine that modifies an adjustment |
2680 | |
2681 | SCOPE - PUBLIC |
2682 | |
2683 | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED |
2684 | fnd_api.compatible_api_call |
2685 | fnd_api.g_exc_unexpected_error |
2686 | fnd_api.g_ret_sts_error |
2687 | fnd_api.g_ret_sts_error |
2688 | fnd_api.g_ret_sts_success |
2692 | fnd_msg_pub.initialize |
2689 | fnd_api.to_boolean |
2690 | fnd_msg_pub.check_msg_level |
2691 | fnd_msg_pub.count_and_get |
2693 | ar_adjustments_pkg.fetch_p |
2694 | ar_process_adjustment.update_adjustment |
2695 | ar_adjvalidate_pvt.within_approval_limit |
2696 | |
2697 | ARGUMENTS : IN: |
2698 | p_api_name |
2699 | p_api_version |
2700 | p_init_msg_list |
2701 | p_commit_flag |
2702 | p_validation_level |
2703 | p_adj_rec |
2704 | p_chk_approval_limits |
2705 | p_old_adjust_id |
2706 | OUT: |
2707 | p_return_status |
2708 | p_msg_count |
2709 | p_msg_data |
2710 | |
2711 | IN/ OUT: |
2712 | |
2713 | |
2714 | RETURNS : NONE |
2715 | |
2716 | NOTES |
2717 | |
2718 | MODIFICATION HISTORY |
2719 | Vivek Halder 30-JAN-97 Created |
2720 | Saloni Shah 03-FEB-00 Changes have been made for the BR/BOE project|
2721 | One new parameter has been added: |
2722 | - p_chk_approval_limits. |
2723 | This parameter will be passed to |
2724 | Validate_Adj_Modify procedure. |
2725 | If the value of the flag p_chk_approval_limit|
2726 | is set to 'F' then the adjusted amount will |
2727 | not be validated against the users approval |
2728 | limits. |
2729 | Satheesh Nambiar 17-May-00 Added one more parameter p_move_deferred_tax|
2730 | for BOE/BR
2731 +===========================================================================*/
2732
2733 PROCEDURE Modify_Adjustment (
2734 p_api_name IN varchar2,
2735 p_api_version IN number,
2736 p_init_msg_list IN varchar2 := FND_API.G_FALSE,
2737 p_commit_flag IN varchar2 := FND_API.G_FALSE,
2738 p_validation_level IN number := FND_API.G_VALID_LEVEL_FULL,
2739 p_msg_count OUT NOCOPY number,
2740 p_msg_data OUT NOCOPY varchar2,
2741 p_return_status OUT NOCOPY varchar2 ,
2742 p_adj_rec IN ar_adjustments%rowtype,
2743 p_chk_approval_limits IN varchar2 := FND_API.G_TRUE,
2744 p_move_deferred_tax IN varchar2,
2745 p_old_adjust_id IN ar_adjustments.adjustment_id%type,
2746 p_org_id IN NUMBER DEFAULT NULL
2747 ) IS
2748
2749 l_api_name CONSTANT VARCHAR2(20) := 'AR_ADJUST_PUB';
2750 l_api_version CONSTANT NUMBER := 1.0;
2751 l_old_adj_rec ar_adjustments%rowtype;
2752 l_hsec VARCHAR2(10);
2753 l_status number;
2754 l_inp_adj_rec ar_adjustments%rowtype;
2755 l_return_status varchar2(1) := FND_API.G_RET_STS_SUCCESS;
2756 l_chk_approval_limits varchar2(1);
2757 l_org_return_status VARCHAR2(1);
2758 l_org_id NUMBER;
2759
2760
2761 BEGIN
2762 IF (FND_MSG_PUB.Check_Msg_Level (G_MSG_LOW)) THEN
2763 select hsecs
2764 into G_START_TIME
2765 from v$timer;
2766 END IF;
2767
2768 /*------------------------------------+
2769 | Standard start of API savepoint |
2770 +------------------------------------*/
2771
2772 SAVEPOINT ar_adjust_PUB;
2773
2774 /*--------------------------------------------------+
2775 | Standard call to check for call compatibility |
2776 +--------------------------------------------------*/
2777
2778 IF NOT FND_API.Compatible_API_Call(
2779 l_api_version,
2780 p_api_version,
2781 l_api_name,
2782 G_PKG_NAME
2783 )
2784 THEN
2785 IF PG_DEBUG in ('Y', 'C') THEN
2786 arp_util.debug('Modify_Adjustment: ' || 'Compatility error occurred.');
2787 END IF;
2788 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2789 END IF;
2790
2791 /*-------------------------------------------------------------+
2792 | Initialize message list if p_init_msg_list is set to TRUE |
2793 +-------------------------------------------------------------*/
2794
2795 IF FND_API.to_Boolean( p_init_msg_list )
2796 THEN
2800 -- arp_util.enable_debug(100000);
2797 FND_MSG_PUB.initialize;
2798 END IF;
2799
2801
2802
2803 IF PG_DEBUG in ('Y', 'C') THEN
2804 arp_util.debug('Modify_Adjustment()+ ');
2805 END IF;
2806
2807 /*-----------------------------------------+
2808 | Initialize return status to SUCCESS |
2809 +-----------------------------------------*/
2810
2811 p_return_status := FND_API.G_RET_STS_SUCCESS;
2812
2813
2814
2815 /* SSA change */
2816 l_org_id := p_org_id;
2817 l_org_return_status := FND_API.G_RET_STS_SUCCESS;
2818 ar_mo_cache_utils.set_org_context_in_api(p_org_id =>l_org_id,
2819 p_return_status =>l_org_return_status);
2820 IF l_org_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2821 p_return_status := FND_API.G_RET_STS_ERROR;
2822 ELSE
2823 /*---------------------------------------------+
2824 | ========== Start of API Body ========== |
2825 +---------------------------------------------*/
2826
2827 /*---------------------------------------------+
2828 | Copy the input record to local variable to |
2829 | allow changes to it |
2830 +---------------------------------------------*/
2831 l_inp_adj_rec := p_adj_rec ;
2832
2833
2834 /*------------------------------------------------+
2835 | Initialize the profile options and cache data |
2836 +------------------------------------------------*/
2837
2838 ar_adjvalidate_pvt.Init_Context_Rec (
2839 p_validation_level,
2840 l_return_status
2841 );
2842 /*------------------------------------------------+
2843 | Check status and return if error |
2844 +------------------------------------------------*/
2845
2846 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
2847 THEN
2848 p_return_status := l_return_status ;
2849 IF PG_DEBUG in ('Y', 'C') THEN
2850 arp_util.debug('Modify_Adjustment: ' || 'failed to initialize the profile options ');
2851 END IF;
2852 END IF;
2853
2854 /*------------------------------------------------+
2855 | Cache details |
2856 +------------------------------------------------*/
2857
2858 ar_adjvalidate_pvt.Cache_Details (
2859 l_return_status
2860 );
2861 /*------------------------------------------------+
2862 | Check status and return if error |
2863 +------------------------------------------------*/
2864
2865 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
2866 THEN
2867 p_return_status := l_return_status ;
2868 IF PG_DEBUG in ('Y', 'C') THEN
2869 arp_util.debug('Modify_Adjustment: ' || 'failed to cache details ');
2870 END IF;
2871 END IF;
2872
2873 /*------------------------------------------------+
2874 | Fetch details of the old adjustment record |
2875 +------------------------------------------------*/
2876 BEGIN
2877 arp_adjustments_pkg.fetch_p (
2878 l_old_adj_rec,
2879 p_old_adjust_id
2880 );
2881 EXCEPTION
2882 WHEN OTHERS THEN
2883 /*---------------------------------------------------+
2884 | Rollback to the defined Savepoint |
2885 +---------------------------------------------------*/
2886 ROLLBACK TO ar_adjust_PUB;
2887 p_return_status := FND_API.G_RET_STS_ERROR ;
2888 FND_MESSAGE.SET_NAME ('AR', 'AR_AAPI_INVALID_ADJ_ID');
2889 FND_MESSAGE.SET_TOKEN ( 'ADJUSTMENT_ID', to_char(p_old_adjust_id) ) ;
2890 FND_MSG_PUB.ADD ;
2891 RETURN;
2892 END ;
2893
2894 /* Removed the validation for Line Level adjustment as part of Bug 13036360. */
2895
2896
2897 /*-----------------------------------------------+
2898 | Handling Line level the validation exceptions |
2899 +-----------------------------------------------*/
2900 IF (p_return_status = FND_API.G_RET_STS_ERROR)
2901 THEN
2902 RAISE FND_API.G_EXC_ERROR;
2903 ELSIF (p_return_status = FND_API.G_RET_STS_UNEXP_ERROR)
2904 THEN
2905 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2906 END IF;
2907
2908
2909
2910 /*------------------------------------------+
2911 | Validate the input details |
2912 | Do not continue if there are errors. |
2913 +------------------------------------------*/
2914
2915 /*--------------------------------------------------+
2916 | Change for the BOE/BR project has been made |
2917 | parameter p_chk_approval_limits is being passed. |
2918 +--------------------------------------------------*/
2919 l_chk_approval_limits := p_chk_approval_limits;
2920 IF (l_chk_approval_limits IS NULL) THEN
2924 ar_adjust_pub.Validate_Adj_Modify (
2921 l_chk_approval_limits := FND_API.G_TRUE;
2922 END IF;
2923
2925 l_inp_adj_rec,
2926 l_old_adj_rec,
2927 l_chk_approval_limits,
2928 l_return_status
2929 );
2930
2931
2932 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
2933 THEN
2934 p_return_status := l_return_status ;
2935 IF PG_DEBUG in ('Y', 'C') THEN
2936 arp_util.debug('Modify_Adjustment: ' ||
2937 'Validation error(s) occurred. Rolling back ' ||
2938 'and setting status to ERROR');
2939 END IF;
2940 END IF;
2941
2942
2943 /*-----------------------------------------------+
2944 | Handling all the validation exceptions |
2945 +-----------------------------------------------*/
2946 IF (p_return_status = FND_API.G_RET_STS_ERROR)
2947 THEN
2948 RAISE FND_API.G_EXC_ERROR;
2949 ELSIF (p_return_status = FND_API.G_RET_STS_UNEXP_ERROR)
2950 THEN
2951 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2952 END IF;
2953
2954
2955 /*-----------------------------------------------+
2956 | Call the entity Handler for Modify |
2957 +-----------------------------------------------*/
2958 BEGIN
2959 arp_process_adjustment.update_adjustment (
2960 'DUMMY',
2961 '1',
2962 l_inp_adj_rec,
2963 p_move_deferred_tax,
2964 p_old_adjust_id
2965 ) ;
2966
2967 EXCEPTION
2968 WHEN OTHERS THEN
2969 /*---------------------------------------------------+
2970 | Rollback to the defined Savepoint |
2971 +---------------------------------------------------*/
2972
2973 ROLLBACK TO ar_adjust_PUB;
2974
2975 p_return_status := FND_API.G_RET_STS_ERROR ;
2976
2977 FND_MESSAGE.set_name( 'AR', 'GENERIC_MESSAGE' );
2978 FND_MESSAGE.set_token( 'GENERIC_TEXT', 'arp_process_adjustment.update_adjustment exception: '||SQLERRM );
2979 --2920926
2980 FND_MSG_PUB.ADD;
2981
2982 /*--------------------------------------------------+
2983 | Get message count and if 1, return message data |
2984 +---------------------------------------------------*/
2985
2986 FND_MSG_PUB.Count_And_Get(
2987 p_encoded => FND_API.G_FALSE,
2988 p_count => p_msg_count,
2989 p_data => p_msg_data
2990 );
2991 IF PG_DEBUG in ('Y', 'C') THEN
2992 arp_util.debug('Modify_Adjustment: ' ||
2993 'Error in Insert Entity handler. Rolling back '||
2994 'and setting status to ERROR');
2995 END IF;
2996
2997 RETURN;
2998
2999 END ;
3000
3001 /*-------------------------------------------+
3002 | ========== End of API Body ========== |
3003 +-------------------------------------------*/
3004 END IF;
3005
3006 /*---------------------------------------------------+
3007 | Get message count and if 1, return message data |
3008 +---------------------------------------------------*/
3009
3010 FND_MSG_PUB.Count_And_Get(
3011 p_encoded => FND_API.G_FALSE,
3012 p_count => p_msg_count,
3013 p_data => p_msg_data
3014 );
3015
3016 /*--------------------------------+
3017 | Standard check of p_commit |
3018 +--------------------------------*/
3019
3020 IF FND_API.To_Boolean( p_commit_flag )
3021 THEN
3022 IF PG_DEBUG in ('Y', 'C') THEN
3023 arp_util.debug('Modify_Adjustment: ' || 'committing');
3024 END IF;
3025 Commit;
3026 END IF;
3027
3028 IF PG_DEBUG in ('Y', 'C') THEN
3029 arp_util.debug('Modify_Adjustment()- ');
3030 END IF;
3031
3032 IF (FND_MSG_PUB.Check_Msg_Level (G_MSG_LOW)) THEN
3033 select TO_CHAR( (hsecs - G_START_TIME) / 100)
3034 into l_hsec
3035 from v$timer;
3036 IF PG_DEBUG in ('Y', 'C') THEN
3037 arp_util.debug('Modify_Adjustment: ' || 'Elapsed Time : '||l_hsec||' seconds');
3038 END IF;
3039 END IF;
3040
3041
3042
3043 EXCEPTION
3044 WHEN FND_API.G_EXC_ERROR THEN
3045
3046 IF PG_DEBUG in ('Y', 'C') THEN
3047 arp_util.debug('Modify_Adjustment: ' || SQLCODE);
3048 arp_util.debug('Modify_Adjustment: ' || SQLERRM);
3049 END IF;
3050
3051 ROLLBACK TO ar_adjust_PUB;
3052 p_return_status := FND_API.G_RET_STS_ERROR ;
3053 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
3054 p_count => p_msg_count,
3055 p_data => p_msg_data
3056 );
3057
3058 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3059
3060 IF PG_DEBUG in ('Y', 'C') THEN
3061 arp_util.debug('Modify_Adjustment: ' || SQLERRM);
3062 END IF;
3066 p_count => p_msg_count,
3063 ROLLBACK TO ar_adjust_PUB ;
3064 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
3065 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
3067 p_data => p_msg_data
3068 );
3069
3070 WHEN OTHERS THEN
3071
3072 /*-------------------------------------------------------+
3073 | Handle application errors that result from trapable |
3074 | error conditions. The error messages have already |
3075 | been put on the error stack. |
3076 +-------------------------------------------------------*/
3077
3078 IF (SQLCODE = -20001)
3079 THEN
3080 p_return_status := FND_API.G_RET_STS_ERROR ;
3081 ROLLBACK TO ar_adjust_PUB;
3082 IF PG_DEBUG in ('Y', 'C') THEN
3083 arp_util.debug('Modify_Adjustment: ' ||
3084 'Completion validation error(s) occurred. ' ||
3085 'Rolling back and setting status to ERROR');
3086 END IF;
3087 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
3088 p_count => p_msg_count,
3089 p_data => p_msg_data
3090 );
3091 RETURN;
3092 ELSE
3093 NULL;
3094 END IF;
3095
3096 arp_util.disable_debug;
3097
3098 END Modify_Adjustment;
3099
3100
3101 /*===========================================================================+
3102 | PROCEDURE |
3103 | Reverse_Adjustment |
3104 | |
3105 | DESCRIPTION |
3106 | This is the main routine that reverses an adjustment |
3107 | |
3108 | SCOPE - PUBLIC |
3109 | |
3110 | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED |
3111 | fnd_api.compatible_api_call |
3112 | fnd_api.g_exc_unexpected_error |
3113 | fnd_api.g_ret_sts_error |
3114 | fnd_api.g_ret_sts_error |
3115 | fnd_api.g_ret_sts_success |
3116 | fnd_api.to_boolean |
3117 | fnd_msg_pub.check_msg_level |
3118 | fnd_msg_pub.count_and_get |
3119 | fnd_msg_pub.initialize |
3120 | ar_adjustments_pkg.fetch_p |
3121 | ar_process_adjustment.reverse_adjustment |
3122 | |
3123 | ARGUMENTS : IN: |
3124 | p_api_name |
3125 | p_api_version |
3126 | p_init_msg_list |
3127 | p_commit_flag |
3128 | p_validation_level |
3129 | p_chk_approval_limits |
3130 | p_old_adjust_id |
3131 | OUT: |
3132 | p_return_status |
3133 | p_msg_count |
3134 | p_msg_data |
3135 | p_new_adj_id |
3136 | |
3137 | IN/ OUT: |
3138 | |
3139 | |
3140 | RETURNS : NONE |
3141 | |
3142 | NOTES |
3143 | |
3144 | MODIFICATION HISTORY |
3145 | Vivek Halder 30-JAN-97 Created |
3146 | Saloni Shah 03-FEB-00 Made changes for BR/BOE project. |
3147 | Added 1 new parameter: |
3148 | - p_chk_approval_limits |
3149 | Made changes the way a reverse adjustment is |
3150 | created. It used to used to call |
3151 | arp_process_adjustment.reverse_adjustment |
3152 | which used to create a reverse adjustment but|
3153 | not update the payment schedules. This has |
3154 | been changed to call Create Adjustment. |
3158 +===========================================================================*/
3155 | S.Nambiar 27-Sep-00 Added a new parameter p_called_from for BR |
3156 | S.Nambiar 28-Nov-00 Bug 1449758 - Modified Reverse routine to |
3157 | initialize gl_posted_date and posting_control_id
3159
3160 PROCEDURE Reverse_Adjustment (
3161 p_api_name IN varchar2,
3162 p_api_version IN number,
3163 p_init_msg_list IN varchar2 := FND_API.G_FALSE,
3164 p_commit_flag IN varchar2 := FND_API.G_FALSE,
3165 p_validation_level IN number := FND_API.G_VALID_LEVEL_FULL,
3166 p_msg_count OUT NOCOPY number,
3167 p_msg_data OUT NOCOPY varchar2,
3168 p_return_status OUT NOCOPY varchar2,
3169 p_old_adjust_id IN ar_adjustments.adjustment_id%type,
3170 p_reversal_gl_date IN date,
3171 p_reversal_date IN date,
3172 p_comments IN ar_adjustments.comments%type,
3173 p_chk_approval_limits IN varchar2 := FND_API.G_TRUE,
3174 p_move_deferred_tax IN varchar2,
3175 p_new_adj_id OUT NOCOPY ar_adjustments.adjustment_id%type,
3176 p_called_from IN varchar2,
3177 p_org_id IN NUMBER DEFAULT NULL
3178 ) IS
3179
3180 l_api_name CONSTANT VARCHAR2(20) := 'AR_ADJUST_PUB';
3181 l_api_version CONSTANT NUMBER := 1.0;
3182
3183 l_reversal_date ar_adjustments.apply_date%type;
3184 l_reversal_gl_date ar_adjustments.gl_date%type;
3185 l_hsec VARCHAR2(10);
3186 l_status number;
3187 l_adj_rec ar_adjustments%rowtype;
3188 l_msg_count number;
3189 l_msg_data varchar2(250);
3190 l_new_adj_num ar_adjustments.adjustment_number%type;
3191 l_check_amount varchar2(1);
3192
3193 l_return_status varchar2(1) := FND_API.G_RET_STS_SUCCESS;
3194 l_chk_approval_limits varchar2(1);
3195 l_org_return_status VARCHAR2(1);
3196 l_org_id NUMBER;
3197
3198 -- Line Leve Reversal
3199 l_llca_adj_trx_lines_tbl ar_adjust_pub.llca_adj_trx_line_tbl_type;
3200 l_llca_adj_create_tbl_type ar_adjust_pub.llca_adj_create_tbl_type;
3201 l_count_chk NUMBER;
3202
3203
3204
3205 BEGIN
3206 IF (FND_MSG_PUB.Check_Msg_Level (G_MSG_LOW)) THEN
3207 select hsecs
3208 into G_START_TIME
3209 from v$timer;
3210 END IF;
3211
3212 /*------------------------------------+
3213 | Standard start of API savepoint |
3214 +------------------------------------*/
3215
3216 SAVEPOINT ar_adjust_PUB;
3217
3218 /*--------------------------------------------------+
3219 | Standard call to check for call compatibility |
3220 +--------------------------------------------------*/
3221
3222 IF NOT FND_API.Compatible_API_Call(
3223 l_api_version,
3224 p_api_version,
3225 l_api_name,
3226 G_PKG_NAME
3227 )
3228 THEN
3229 IF PG_DEBUG in ('Y', 'C') THEN
3230 arp_util.debug('Reverse_Adjustment: ' || 'Compatility error occurred.');
3231 END IF;
3232 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3233 END IF;
3234
3235 /*-------------------------------------------------------------+
3236 | Initialize message list if p_init_msg_list is set to TRUE |
3237 +-------------------------------------------------------------*/
3238
3239 IF FND_API.to_Boolean( p_init_msg_list )
3240 THEN
3241 FND_MSG_PUB.initialize;
3242 END IF;
3243
3244 -- arp_util.enable_debug(100000);
3245
3246
3247 IF PG_DEBUG in ('Y', 'C') THEN
3248 arp_util.debug('Reverse_Adjustment()+ ');
3249 END IF;
3250
3251 /*-----------------------------------------+
3252 | Initialize return status to SUCCESS |
3253 +-----------------------------------------*/
3254
3255 p_return_status := FND_API.G_RET_STS_SUCCESS;
3256
3257
3258
3259 /* SSA change */
3260 l_org_id := p_org_id;
3261 l_org_return_status := FND_API.G_RET_STS_SUCCESS;
3262 ar_mo_cache_utils.set_org_context_in_api(p_org_id =>l_org_id,
3263 p_return_status =>l_org_return_status);
3264 IF l_org_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3265 p_return_status := FND_API.G_RET_STS_ERROR;
3266 ELSE
3267 /*---------------------------------------------+
3268 | ========== Start of API Body ========== |
3269 +---------------------------------------------*/
3270
3271
3272 /*------------------------------------------------+
3273 | Initialize the profile options and cache data |
3274 +------------------------------------------------*/
3275
3276 ar_adjvalidate_pvt.Init_Context_Rec (
3277 p_validation_level,
3278 l_return_status
3279 );
3280 /*------------------------------------------------+
3281 | Check status and return if error |
3282 +------------------------------------------------*/
3283
3284 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
3285 THEN
3286 p_return_status := l_return_status ;
3287 IF PG_DEBUG in ('Y', 'C') THEN
3288 arp_util.debug('Reverse_Adjustment: ' || ' failed to Initialize the profile options ');
3289 END IF;
3290 END IF;
3291
3292 /*------------------------------------------------+
3296
3293 | Fetch details of the old adjustment record |
3294 +------------------------------------------------*/
3295 BEGIN
3297 arp_adjustments_pkg.fetch_p (
3298 l_adj_rec,
3299 p_old_adjust_id
3300 );
3301 EXCEPTION
3302 WHEN OTHERS THEN
3303 /*---------------------------------------------------+
3304 | Rollback to the defined Savepoint |
3305 +---------------------------------------------------*/
3306
3307 ROLLBACK TO ar_adjust_PUB;
3308
3309 p_return_status := FND_API.G_RET_STS_ERROR ;
3310
3311 FND_MESSAGE.SET_NAME ('AR', 'AR_AAPI_INVALID_ADJ_ID');
3312 FND_MESSAGE.SET_TOKEN ( 'ADJUSTMENT_ID', to_char(p_old_adjust_id) ) ;
3313 FND_MSG_PUB.ADD ;
3314 RETURN;
3315 END ;
3316
3317 /*------------------------------------------------+
3318 | Cache details |
3319 +------------------------------------------------*/
3320
3321 ar_adjvalidate_pvt.Cache_Details (
3322 l_return_status
3323 );
3324 /*------------------------------------------------+
3325 | Check status and return if error |
3326 +------------------------------------------------*/
3327
3328 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
3329 THEN
3330 p_return_status := l_return_status ;
3331 IF PG_DEBUG in ('Y', 'C') THEN
3332 arp_util.debug('Reverse_Adjustment: ' || ' failed to Cache_Details ');
3333 END IF;
3334 END IF;
3335
3336 /*--------------------------------------------+
3337 | Validate the input details. Copy the dates |
3338 | into local variables |
3339 +--------------------------------------------*/
3340
3341 l_reversal_gl_date := p_reversal_gl_date ;
3342 l_reversal_date := p_reversal_date ;
3343
3344 /*------------------------------------------------+
3345 | Validate if the adjustment can be reversed |
3346 +------------------------------------------------*/
3347
3348
3349 ar_adjust_pub.Validate_Adj_Reverse (
3350 l_adj_rec,
3351 l_reversal_gl_date,
3352 l_reversal_date,
3353 l_return_status
3354 );
3355
3356
3357 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
3358 THEN
3359 p_return_status := l_return_status ;
3360 IF PG_DEBUG in ('Y', 'C') THEN
3361 arp_util.debug('Reverse_Adjustment: ' ||
3362 'Validation error(s) occurred. Rolling back '||
3363 'and setting status to ERROR');
3364 END IF;
3365 END IF;
3366
3367 /*-----------------------------------------------+
3368 | Handling all the validation exceptions |
3369 +-----------------------------------------------*/
3370 IF (p_return_status = FND_API.G_RET_STS_ERROR)
3371 THEN
3372 RAISE FND_API.G_EXC_ERROR;
3373 ELSIF (p_return_status = FND_API.G_RET_STS_UNEXP_ERROR)
3374 THEN
3375 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3376 END IF;
3377
3378 /*------------------------------------------------------------+
3379 | Reverse the amounts and create a new adj adjustment record.|
3380 | The new adjustment record should have the date and gl_date |
3381 | same as the reversal date and gl_date. |
3382 +------------------------------------------------------------*/
3383 IF PG_DEBUG in ('Y', 'C') THEN
3384 arp_util.debug('Reverse_Adjustment: ' || 'Preparing the values for the new adjustment');
3385 END IF;
3386
3387 -- setting all the new values for the new adjustment
3388
3389 -- setting all the new values for the new adjustment
3390
3391 BEGIN
3392 Select count(*)
3393 into l_count_chk
3394 from AR_ACTIVITY_DETAILS
3395 where source_id = p_old_adjust_id
3396 and source_table = 'ADJ'
3397 and nvl(CURRENT_ACTIVITY_FLAG,'Y') = 'Y' -- Bug 7241111
3398 and customer_trx_line_id = l_adj_rec.customer_trx_line_id;
3399 EXCEPTION
3400 When others then
3401 l_count_chk := 0;
3402 END;
3403
3404
3405 IF NVL(l_count_chk,0) <> 0
3406 THEN
3407 l_adj_rec.status := NULL;
3408 l_adj_rec.adjustment_id := NULL;
3409 l_adj_rec.apply_date := p_reversal_date ;
3410 l_adj_rec.gl_date := p_reversal_gl_date;
3411 l_adj_rec.amount := -l_adj_rec.amount;
3412 l_adj_rec.acctd_amount := -l_adj_rec.acctd_amount;
3413 l_adj_rec.line_adjusted := -l_adj_rec.line_adjusted;
3414 l_adj_rec.freight_adjusted := -l_adj_rec.freight_adjusted;
3415 l_adj_rec.tax_adjusted := -l_adj_rec.tax_adjusted;
3416 l_adj_rec.receivables_charges_adjusted :=
3417 -l_adj_rec.receivables_charges_adjusted ;
3418 l_adj_rec.created_from := 'REVERSE_ADJUSTMENT';
3419 l_adj_rec.comments := p_comments;
3420
3421 l_llca_adj_trx_lines_tbl(1).customer_trx_line_id := l_adj_rec.customer_trx_line_id;
3422 l_llca_adj_trx_lines_tbl(1).line_amount := l_adj_rec.amount;
3423 l_llca_adj_trx_lines_tbl(1).receivables_trx_id := l_adj_rec.receivables_trx_id;
3424 l_adj_rec.customer_trx_line_id := NULL; -- Line level Adjustment does not allow line id at header.
3425 l_adj_rec.receivables_trx_id := NULL; -- Line level Adjustment does not allow line id at header.
3426
3427 ELSE
3431 l_adj_rec.gl_date := p_reversal_gl_date;
3428 l_adj_rec.status := NULL;
3429 l_adj_rec.adjustment_id := NULL;
3430 l_adj_rec.apply_date := p_reversal_date ;
3432 l_adj_rec.amount := -l_adj_rec.amount;
3433 l_adj_rec.acctd_amount := -l_adj_rec.acctd_amount;
3434 l_adj_rec.line_adjusted := -l_adj_rec.line_adjusted;
3435 l_adj_rec.freight_adjusted := -l_adj_rec.freight_adjusted;
3436 l_adj_rec.tax_adjusted := -l_adj_rec.tax_adjusted;
3437 l_adj_rec.receivables_charges_adjusted :=
3438 -l_adj_rec.receivables_charges_adjusted ;
3439 l_adj_rec.created_from := 'REVERSE_ADJUSTMENT';
3440 l_adj_rec.comments := p_comments;
3441 END IF;
3442
3443 --Bug 1449758 - While reversing, null out NOCOPY the gl posting fiedls
3444
3445 l_adj_rec.gl_posted_date := NULL;
3446 l_adj_rec.posting_control_id := -3;
3447
3448 /* Bugfix 2734179. Null out doc_seq columns so that they get
3449 fresh values for the reversed row. */
3450 l_adj_rec.doc_sequence_id := NULL;
3451 l_adj_rec.doc_sequence_value := NULL;
3452
3453 IF PG_DEBUG in ('Y', 'C') THEN
3454 arp_util.debug('Reverse_Adjustment: ' || '--------------------------------------------------');
3455 arp_util.debug('Reverse_Adjustment: ' || 'New values for the new adjustment');
3456 arp_util.debug('Reverse_Adjustment: ' || 'status = ' || l_adj_rec.status );
3457 arp_util.debug('Reverse_Adjustment: ' || 'adjustment_id = ' || l_adj_rec.adjustment_id );
3458 arp_util.debug('Reverse_Adjustment: ' || 'apply_date = ' || l_adj_rec.apply_date );
3459 arp_util.debug('Reverse_Adjustment: ' || 'gl_date = ' || l_adj_rec.gl_date );
3460 arp_util.debug('Reverse_Adjustment: ' || 'amount = ' || l_adj_rec.amount );
3461 arp_util.debug('Reverse_Adjustment: ' || 'acctd_amount = ' || l_adj_rec.acctd_amount );
3462 arp_util.debug('Reverse_Adjustment: ' || 'line_adjusted = ' || l_adj_rec.line_adjusted);
3463 arp_util.debug('Reverse_Adjustment: ' || 'freight_adjusted = ' || l_adj_rec.freight_adjusted );
3464 arp_util.debug('Reverse_Adjustment: ' || 'tax_adjusted = ' || l_adj_rec.tax_adjusted);
3465 arp_util.debug('Reverse_Adjustment: ' || 'receivables_charges_adjusted = ' || l_adj_rec.receivables_charges_adjusted );
3466 arp_util.debug('Reverse_Adjustment: ' || 'created_from = ' || l_adj_rec.created_from );
3467 arp_util.debug('Reverse_Adjustment: ' || 'comments = ' || l_adj_rec.comments);
3468 arp_util.debug('Reverse_Adjustment: ' || '--------------------------------------------------');
3469 END IF;
3470
3471
3472 l_check_amount := FND_API.G_FALSE;
3473
3474 l_chk_approval_limits := p_chk_approval_limits;
3475 IF (l_chk_approval_limits IS NULL) THEN
3476 l_chk_approval_limits := FND_API.G_TRUE;
3477 END IF;
3478
3479 /*--------------------------------------------------------------+
3480 | Call the create adjustment api to insert the new adjustment. |
3481 +--------------------------------------------------------------*/
3482
3483 BEGIN
3484
3485 IF NVL(l_count_chk,0) <> 0
3486 THEN
3487
3488
3489 ar_adjust_pub.create_linelevel_adjustment(
3490 p_api_name => 'AR_ADJUST_PUB',
3491 p_api_version => 1.0,
3492 p_msg_count => l_msg_count ,
3493 p_msg_data => l_msg_data,
3494 p_return_status => l_return_status,
3495 p_adj_rec => l_adj_rec,
3496 p_chk_approval_limits => l_chk_approval_limits,
3497 p_llca_adj_trx_lines_tbl => l_llca_adj_trx_lines_tbl,
3498 p_check_amount => l_check_amount,
3499 p_move_deferred_tax => p_move_deferred_tax,
3500 p_llca_adj_create_tbl_type => l_llca_adj_create_tbl_type,
3501 p_called_from => p_called_from,
3502 p_old_adjust_id => p_old_adjust_id);
3503
3504 IF l_llca_adj_create_tbl_type(1).adjustment_id IS NULL THEN
3505 p_return_status := FND_API.G_RET_STS_ERROR;
3506 ELSE
3507 IF PG_DEBUG in ('Y', 'C') THEN
3508 p_new_adj_id := l_llca_adj_create_tbl_type(1).adjustment_id;
3509 arp_util.debug('Reverse_Adjustment: ' ||
3510 'After Create_Adjustment , new_adjustment_id = ' ||
3511 p_new_adj_id || ' new_adjustment_num = ' || l_llca_adj_create_tbl_type(1).adjustment_number);
3512 END IF;
3513 END IF;
3514
3515 ELSE
3516 ar_adjust_pub.Create_Adjustment(
3517 p_api_name => 'AR_ADJUST_PUB',
3518 p_api_version => 1.0,
3519 p_msg_count => l_msg_count ,
3520 p_msg_data => l_msg_data,
3521 p_return_status => l_return_status,
3522 p_adj_rec => l_adj_rec,
3523 p_chk_approval_limits => l_chk_approval_limits,
3524 p_new_adjust_number => l_new_adj_num,
3525 p_new_adjust_id => p_new_adj_id,
3526 p_check_amount => l_check_amount,
3527 p_move_deferred_tax => p_move_deferred_tax,
3528 p_called_from => p_called_from,
3529 p_old_adjust_id => p_old_adjust_id);
3530
3531
3532
3533 /* Bugfix 2734179. Check if the new adjustment record was created. */
3534 IF p_new_adj_id IS NULL THEN
3535 p_return_status := FND_API.G_RET_STS_ERROR;
3536 ELSE
3537 IF PG_DEBUG in ('Y', 'C') THEN
3538 arp_util.debug('Reverse_Adjustment: ' ||
3539 'After Create_Adjustment , new_adjustment_id = ' ||
3540 p_new_adj_id || ' new_adjustment_num = ' || l_new_adj_num);
3541 END IF;
3542 END IF;
3546 WHEN OTHERS THEN
3543 END IF;
3544
3545 EXCEPTION
3547 /*---------------------------------------------------+
3548 | Rollback to the defined Savepoint |
3549 +---------------------------------------------------*/
3550
3551 ROLLBACK TO ar_adjust_PUB;
3552 p_return_status := FND_API.G_RET_STS_ERROR ;
3553
3554 /*--------------------------------------------------+
3555 | Get message count and if 1, return message data |
3556 +---------------------------------------------------*/
3557
3558 FND_MSG_PUB.Count_And_Get(
3559 p_encoded => FND_API.G_FALSE,
3560 p_count => p_msg_count,
3561 p_data => p_msg_data
3562 );
3563 IF PG_DEBUG in ('Y', 'C') THEN
3564 arp_util.debug('Reverse_Adjustment: ' ||
3565 'Error in Insert Entity handler. Rolling back ' ||
3566 'and setting status to ERROR');
3567 END IF;
3568 if (l_msg_count > 0) then
3569 IF PG_DEBUG in ('Y', 'C') THEN
3570 arp_util.debug('Reverse_Adjustment: ' || l_msg_data);
3571 END IF;
3572 end if;
3573
3574 RETURN;
3575
3576 END ;
3577
3578
3579 /*-------------------------------------------+
3580 | ========== End of API Body ========== |
3581 +-------------------------------------------*/
3582 END IF;
3583
3584 /*---------------------------------------------------+
3585 | Get message count and if 1, return message data |
3586 +---------------------------------------------------*/
3587
3588 FND_MSG_PUB.Count_And_Get(
3589 p_encoded =>FND_API.G_FALSE,
3590 p_count => p_msg_count,
3591 p_data => p_msg_data
3592 );
3593
3594 /*--------------------------------+
3595 | Standard check of p_commit |
3596 +--------------------------------*/
3597
3598 IF FND_API.To_Boolean( p_commit_flag )
3599 THEN
3600 IF PG_DEBUG in ('Y', 'C') THEN
3601 arp_util.debug('Reverse_Adjustment: ' || 'committing');
3602 END IF;
3603 Commit;
3604 END IF;
3605
3606 IF PG_DEBUG in ('Y', 'C') THEN
3607 arp_util.debug('Reverse_Adjustment()- ');
3608 END IF;
3609
3610 IF (FND_MSG_PUB.Check_Msg_Level (G_MSG_LOW)) THEN
3611 select TO_CHAR( (hsecs - G_START_TIME) / 100)
3612 into l_hsec
3613 from v$timer;
3614 IF PG_DEBUG in ('Y', 'C') THEN
3615 arp_util.debug('Reverse_Adjustment: ' || 'Elapsed Time : '||l_hsec||' seconds');
3616 END IF;
3617 END IF;
3618
3619
3620 EXCEPTION
3621 WHEN FND_API.G_EXC_ERROR THEN
3622
3623 IF PG_DEBUG in ('Y', 'C') THEN
3624 arp_util.debug('Reverse_Adjustment: ' || SQLCODE);
3625 arp_util.debug('Reverse_Adjustment: ' || SQLERRM);
3626 END IF;
3627
3628 ROLLBACK TO ar_adjust_PUB;
3629 p_return_status := FND_API.G_RET_STS_ERROR ;
3630 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
3631 p_count => p_msg_count,
3632 p_data => p_msg_data
3633 );
3634
3635 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3636
3637 IF PG_DEBUG in ('Y', 'C') THEN
3638 arp_util.debug('Reverse_Adjustment: ' || SQLERRM);
3639 END IF;
3640 ROLLBACK TO ar_adjust_PUB ;
3641 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
3642 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
3643 p_count => p_msg_count,
3644 p_data => p_msg_data
3645 );
3646
3647 WHEN OTHERS THEN
3648
3649 /*-------------------------------------------------------+
3650 | Handle application errors that result from trapable |
3651 | error conditions. The error messages have already |
3652 | been put on the error stack. |
3653 +-------------------------------------------------------*/
3654
3655 IF (SQLCODE = -20001)
3656 THEN
3657 p_return_status := FND_API.G_RET_STS_ERROR ;
3658 ROLLBACK TO ar_adjust_PUB;
3659 IF PG_DEBUG in ('Y', 'C') THEN
3660 arp_util.debug('Reverse_Adjustment: ' ||
3661 'Completion validation error(s) occurred. ' ||
3662 'Rolling back and setting status to ERROR');
3663 END IF;
3664
3665 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
3666 p_count => p_msg_count,
3667 p_data => p_msg_data
3668 );
3669 RETURN;
3670 ELSE
3671 NULL;
3672 END IF;
3673
3674 arp_util.disable_debug;
3675
3676 END Reverse_Adjustment;
3677
3678
3679 /*===========================================================================+
3683 | DESCRIPTION |
3680 | PROCEDURE |
3681 | Approve_Adjustment |
3682 | |
3684 | This is the main routine that approves an adjustment |
3685 | |
3686 | SCOPE - PUBLIC |
3687 | |
3688 | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED |
3689 | fnd_api.compatible_api_call |
3690 | fnd_api.g_exc_unexpected_error |
3691 | fnd_api.g_ret_sts_error |
3692 | fnd_api.g_ret_sts_error |
3693 | fnd_api.g_ret_sts_success |
3694 | fnd_api.to_boolean |
3695 | fnd_msg_pub.check_msg_level |
3696 | fnd_msg_pub.count_and_get |
3697 | fnd_msg_pub.initialize |
3698 | ar_adjustments_pkg.fetch_p |
3699 | ar_process_adjustment.update_approve_adjustment |
3700 | |
3701 | ARGUMENTS : IN: |
3702 | p_api_name |
3703 | p_api_version |
3704 | p_init_msg_list |
3705 | p_commit_flag |
3706 | p_validation_level |
3707 | p_adj_rec |
3708 | p_chk_approval_limits |
3709 | p_old_adjust_id |
3710 | OUT: |
3711 | p_return_status |
3712 | p_msg_count |
3713 | p_msg_data |
3714 | |
3715 | IN/ OUT: |
3716 | |
3717 | |
3718 | RETURNS : NONE |
3719 | |
3720 | NOTES |
3721 | |
3722 | MODIFICATION HISTORY |
3723 | Vivek Halder 30-JAN-97 Created |
3727 | - p_chk_approval_limits. |
3724 | |
3725 | Saloni Shah 03-FEB-00 Changes have been made for the BR/BOE project|
3726 | One new parameter has been added: |
3728 | This parameter will be passed to |
3729 | Validate_Adj_Approve procedure. |
3730 | If the value of the flag p_chk_approval_limit|
3731 | is set to 'F' then the adjusted amount will |
3732 | not be validated against the users approval |
3733 | limits. |
3734 | Satheesh Nambiar 17-May-00 Added one more parameter p_move_deferred_tax|
3735 | for BOE/BR
3736 | |
3737 +===========================================================================*/
3738
3739 PROCEDURE Approve_Adjustment (
3740 p_api_name IN varchar2,
3741 p_api_version IN number,
3742 p_init_msg_list IN varchar2 := FND_API.G_FALSE,
3743 p_commit_flag IN varchar2 := FND_API.G_FALSE,
3744 p_validation_level IN number := FND_API.G_VALID_LEVEL_FULL,
3745 p_msg_count OUT NOCOPY number,
3746 p_msg_data OUT NOCOPY varchar2,
3747 p_return_status OUT NOCOPY varchar2 ,
3748 p_adj_rec IN ar_adjustments%rowtype,
3749 p_chk_approval_limits IN varchar2 := FND_API.G_TRUE,
3750 p_move_deferred_tax IN varchar2,
3751 p_old_adjust_id IN ar_adjustments.adjustment_id%type,
3752 p_org_id IN NUMBER DEFAULT NULL
3753 ) IS
3754
3755 l_api_name CONSTANT VARCHAR2(20) := 'AR_ADJUST_PUB';
3756 l_api_version CONSTANT NUMBER := 1.0;
3757 l_old_adj_rec ar_adjustments%rowtype;
3758
3759 l_inp_adj_rec ar_adjustments%rowtype;
3760 l_hsec VARCHAR2(10);
3761 l_status number;
3762
3763 l_return_status varchar2(1) := FND_API.G_RET_STS_SUCCESS;
3764 l_chk_approval_limits varchar2(1);
3765 l_org_return_status VARCHAR2(1);
3766 l_org_id NUMBER;
3767
3768
3769 BEGIN
3770 IF (FND_MSG_PUB.Check_Msg_Level (G_MSG_LOW)) THEN
3771 select hsecs
3772 into G_START_TIME
3773 from v$timer;
3774 END IF;
3775
3776 /*------------------------------------+
3777 | Standard start of API savepoint |
3778 +------------------------------------*/
3779
3780 SAVEPOINT ar_adjust_PUB;
3781
3782 /*--------------------------------------------------+
3783 | Standard call to check for call compatibility |
3784 +--------------------------------------------------*/
3785
3786 IF NOT FND_API.Compatible_API_Call(
3787 l_api_version,
3788 p_api_version,
3789 l_api_name,
3790 G_PKG_NAME
3791 )
3792 THEN
3793 IF PG_DEBUG in ('Y', 'C') THEN
3794 arp_util.debug('Approve_Adjustment: ' || 'Compatility error occurred.');
3795 END IF;
3796 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3797 END IF;
3798
3799 /*-------------------------------------------------------------+
3800 | Initialize message list if p_init_msg_list is set to TRUE |
3801 +-------------------------------------------------------------*/
3802
3803 IF FND_API.to_Boolean( p_init_msg_list )
3804 THEN
3805 FND_MSG_PUB.initialize;
3806 END IF;
3807
3808 -- arp_util.enable_debug(100000);
3809
3810
3811 IF PG_DEBUG in ('Y', 'C') THEN
3812 arp_util.debug('Approve_Adjustment()+ ');
3813 END IF;
3814
3815 /*-----------------------------------------+
3816 | Initialize return status to SUCCESS |
3817 +-----------------------------------------*/
3818
3819 p_return_status := FND_API.G_RET_STS_SUCCESS;
3820
3821
3822
3823
3824
3825 /* SSA change */
3826 l_org_id := p_org_id;
3827 l_org_return_status := FND_API.G_RET_STS_SUCCESS;
3828 ar_mo_cache_utils.set_org_context_in_api(p_org_id =>l_org_id,
3829 p_return_status =>l_org_return_status);
3830 IF l_org_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3831 p_return_status := FND_API.G_RET_STS_ERROR;
3832 ELSE
3833
3834
3835 /*---------------------------------------------+
3836 | ========== Start of API Body ========== |
3837 +---------------------------------------------*/
3838
3839
3840 /*---------------------------------------------+
3841 | Copy the input record to local variable to |
3842 | allow changes to it |
3843 +---------------------------------------------*/
3844 l_inp_adj_rec := p_adj_rec ;
3845
3846
3847 /*------------------------------------------------+
3848 | Initialize the profile options and cache data |
3849 +------------------------------------------------*/
3850
3851 ar_adjvalidate_pvt.Init_Context_Rec (
3852 p_validation_level,
3853 l_return_status
3854 );
3855 /*------------------------------------------------+
3856 | Check status and return if error |
3857 +------------------------------------------------*/
3858
3862 IF PG_DEBUG in ('Y', 'C') THEN
3859 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
3860 THEN
3861 p_return_status := l_return_status ;
3863 arp_util.debug('Approve_Adjustment: ' || 'failed to Initialize the profile options ');
3864 END IF;
3865 END IF;
3866
3867 /*------------------------------------------------+
3868 | Cache details |
3869 +------------------------------------------------*/
3870
3871 ar_adjvalidate_pvt.Cache_Details (
3872 l_return_status
3873 );
3874 /*------------------------------------------------+
3875 | Check status and return if error |
3876 +------------------------------------------------*/
3877
3878 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
3879 THEN
3880 p_return_status := l_return_status ;
3881 IF PG_DEBUG in ('Y', 'C') THEN
3882 arp_util.debug('Approve_Adjustment: ' || 'failed to Initialize the profile options ');
3883 END IF;
3884 END IF;
3885
3886 /*------------------------------------------------+
3887 | Fetch details of the old adjustment record |
3888 +------------------------------------------------*/
3889 BEGIN
3890
3891 arp_adjustments_pkg.fetch_p (
3892 l_old_adj_rec,
3893 p_old_adjust_id
3894 );
3895
3896 EXCEPTION
3897 WHEN OTHERS THEN
3898 /*---------------------------------------------------+
3899 | Rollback to the defined Savepoint |
3900 +---------------------------------------------------*/
3901
3902 ROLLBACK TO ar_adjust_PUB;
3903
3904 p_return_status := FND_API.G_RET_STS_ERROR ;
3905
3906 FND_MESSAGE.SET_NAME ('AR', 'AR_AAPI_INVALID_ADJ_ID');
3907 FND_MESSAGE.SET_TOKEN ( 'ADJUSTMENT_ID', to_char(p_old_adjust_id) ) ;
3908 FND_MSG_PUB.ADD ;
3909 RETURN;
3910 END ;
3911
3912 /*------------------------------------------+
3913 | Validate the input details |
3914 | Do not continue if there are errors. |
3915 +------------------------------------------*/
3916
3917 /*--------------------------------------------------+
3918 | Change for the BOE/BR project has been made |
3919 | parameter p_chk_approval_limits is being passed. |
3920 +--------------------------------------------------*/
3921
3922 l_chk_approval_limits := p_chk_approval_limits;
3923 IF (l_chk_approval_limits IS NULL) THEN
3924 l_chk_approval_limits := FND_API.G_TRUE;
3925 END IF;
3926
3927 ar_adjust_pub.Validate_Adj_Approve (
3928 l_inp_adj_rec,
3929 l_old_adj_rec,
3930 l_chk_approval_limits,
3931 l_return_status
3932 );
3933
3934
3935 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
3936 THEN
3937
3938 p_return_status := l_return_status ;
3939 IF PG_DEBUG in ('Y', 'C') THEN
3940 arp_util.debug('Approve_Adjustment: ' ||
3941 'Validation error(s) occurred. Rolling back ' ||
3942 'and setting status to ERROR');
3943 END IF;
3944 END IF;
3945
3946 /*-----------------------------------------------+
3947 | Handling all the validation exceptions |
3948 +-----------------------------------------------*/
3949 IF (p_return_status = FND_API.G_RET_STS_ERROR)
3950 THEN
3951 RAISE FND_API.G_EXC_ERROR;
3952 ELSIF (p_return_status = FND_API.G_RET_STS_UNEXP_ERROR)
3953 THEN
3954 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3955 END IF;
3956
3957 /*-----------------------------------------------+
3958 | Call the entity Handler for Approve |
3959 +-----------------------------------------------*/
3960 BEGIN
3961 /*-------------------------------------------------------+
3962 | Change for the BOE/BR project has been made parameter |
3963 | p_chk_approval_limits is being passed to the entity |
3964 | handler to indicate that check the amount_adjusted |
3965 | with the user approval limits only if |
3966 | p_chk_approval_limit flag is set to 'T'. |
3967 +-------------------------------------------------------*/
3968 arp_process_adjustment.update_approve_adj (
3969 'DUMMY',
3970 '1',
3971 l_inp_adj_rec,
3972 l_inp_adj_rec.status,
3973 p_old_adjust_id ,
3974 p_chk_approval_limits,
3975 p_move_deferred_tax
3976 ) ;
3977
3978 EXCEPTION
3979 WHEN OTHERS THEN
3980 /*---------------------------------------------------+
3981 | Rollback to the defined Savepoint |
3982 +---------------------------------------------------*/
3983
3984 ROLLBACK TO ar_adjust_PUB;
3985
3986 p_return_status := FND_API.G_RET_STS_ERROR ;
3987
3988 FND_MESSAGE.set_name( 'AR', 'GENERIC_MESSAGE' );
3989 FND_MESSAGE.set_token( 'GENERIC_TEXT', 'arp_process_adjustment.update_approve_adj exception: '||SQLERRM );
3990 --2920926
3994 +---------------------------------------------------*/
3991 FND_MSG_PUB.ADD;
3992 /*--------------------------------------------------+
3993 | Get message count and if 1, return message data |
3995
3996 FND_MSG_PUB.Count_And_Get(
3997 p_encoded => FND_API.G_FALSE,
3998 p_count => p_msg_count,
3999 p_data => p_msg_data
4000 );
4001
4002 IF PG_DEBUG in ('Y', 'C') THEN
4003 arp_util.debug('Approve_Adjustment: ' ||
4004 'Error in Insert Entity handler. Rolling back ' ||
4005 'and setting status to ERROR');
4006 END IF;
4007
4008 RETURN;
4009
4010 END ;
4011
4012
4013 /*-------------------------------------------+
4014 | ========== End of API Body ========== |
4015 +-------------------------------------------*/
4016 END IF;
4017
4018 /*---------------------------------------------------+
4019 | Get message count and if 1, return message data |
4020 +---------------------------------------------------*/
4021
4022 FND_MSG_PUB.Count_And_Get(
4023 p_encoded => FND_API.G_FALSE,
4024 p_count => p_msg_count,
4025 p_data => p_msg_data
4026 );
4027
4028 /*--------------------------------+
4029 | Standard check of p_commit |
4030 +--------------------------------*/
4031
4032 IF FND_API.To_Boolean( p_commit_flag )
4033 THEN
4034 IF PG_DEBUG in ('Y', 'C') THEN
4035 arp_util.debug('Approve_Adjustment: ' || 'committing');
4036 END IF;
4037 Commit;
4038 END IF;
4039
4040 IF PG_DEBUG in ('Y', 'C') THEN
4041 arp_util.debug('Approve_Adjustment()- ');
4042 END IF;
4043
4044 IF (FND_MSG_PUB.Check_Msg_Level (G_MSG_LOW)) THEN
4045 select TO_CHAR( (hsecs - G_START_TIME) / 100)
4046 into l_hsec
4047 from v$timer;
4048 IF PG_DEBUG in ('Y', 'C') THEN
4049 arp_util.debug('Approve_Adjustment: ' || 'Elapsed Time : '||l_hsec||' seconds');
4050 END IF;
4051 END IF;
4052
4053
4054 EXCEPTION
4055 WHEN FND_API.G_EXC_ERROR THEN
4056
4057 IF PG_DEBUG in ('Y', 'C') THEN
4058 arp_util.debug('Approve_Adjustment: ' || SQLCODE);
4059 arp_util.debug('Approve_Adjustment: ' || SQLERRM);
4060 END IF;
4061
4062 ROLLBACK TO ar_adjust_PUB;
4063 p_return_status := FND_API.G_RET_STS_ERROR ;
4064 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
4065 p_count => p_msg_count,
4066 p_data => p_msg_data
4067 );
4068
4069 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4070
4071 IF PG_DEBUG in ('Y', 'C') THEN
4072 arp_util.debug('Approve_Adjustment: ' || SQLERRM);
4073 END IF;
4074 ROLLBACK TO ar_adjust_PUB ;
4075 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4076 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
4077 p_count => p_msg_count,
4081 WHEN OTHERS THEN
4078 p_data => p_msg_data
4079 );
4080
4082
4083 /*-------------------------------------------------------+
4084 | Handle application errors that result from trapable |
4085 | error conditions. The error messages have already |
4086 | been put on the error stack. |
4087 +-------------------------------------------------------*/
4088
4089 IF (SQLCODE = -20001)
4090 THEN
4091 p_return_status := FND_API.G_RET_STS_ERROR ;
4092 ROLLBACK TO ar_adjust_PUB;
4093 IF PG_DEBUG in ('Y', 'C') THEN
4094 arp_util.debug('Approve_Adjustment: ' ||
4095 'Completion validation error(s) occurred. ' ||
4096 'Rolling back and setting status to ERROR');
4097 END IF;
4098
4099 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
4100 p_count => p_msg_count,
4101 p_data => p_msg_data
4102 );
4103 RETURN;
4104 ELSE
4105 NULL;
4106 END IF;
4107
4108 arp_util.disable_debug;
4109
4110 END Approve_Adjustment;
4111
4112
4113 END ar_adjust_PUB;