[Home] [Help]
Skip to content
PACKAGE BODY: APPS.AR_ADJUST_PUB
Source
1 PACKAGE BODY AR_ADJUST_PUB AS
2 /* $Header: ARXPADJB.pls 120.20.12010000.3 2008/11/17 12:00:31 pbapna ship $*/
3
4 G_PKG_NAME CONSTANT VARCHAR2(30) :='AR_ADJUST_PUB';
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 |
34 | ar_adjvalidate_pvt.Validate_Rcvtrxccid |
35 | ar_adjvalidate_pvt.Validate_dates |
36 | ar_adjvalidate_pvt.Validate_Reason_code |
37 | ar_adjvalidate_pvt.Validate_doc_seq |
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
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 ');
148 END IF;
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 +-----------------------------------------------*/
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;
250 ELSIF (l_error_num = 3) THEN
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 ');
289 /*-------------------------------------------------+
286 END IF;
287 END IF;
288
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;
419
416
417
418 EXCEPTION
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 +-----------------------------------------------*/
477 p_return_status := FND_API.G_RET_STS_SUCCESS ;
478
479 /*-----------------------------------------------+
480 | Set Adjustment Type and Postable attributes |
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 |
526 | SCOPE - PRIVATE |
523 | This is the validation routine for Modification of Approvals |
524 | |
525 | |
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 |
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 |
552 | passed, then update the adjustment with that |
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');
624 IF PG_DEBUG in ('Y', 'C') THEN
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;
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 +-----------------------------------------------*/
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 ;
671
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 /*------------------------------------------------------+
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 |
682 | 'T'. |
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
747 --Bug 2487925 Validate the cash receipt id, if passed
744
745 p_adj_rec.gl_date := trunc(p_adj_rec.gl_date);
746
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 ;
810 l_temp_adj_rec.status := p_adj_rec.status ;
811 l_temp_adj_rec.gl_date := p_adj_rec.gl_date ;
812
813 --Bug 2487925, if only application id is passed, take the cash receipt id of the
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 |
875 | |
872 | |
873 | DESCRIPTION |
874 | This is the validation routine for Reversal of Approvals |
876 | |
877 | SCOPE - PRIVATE |
878 | |
879 | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED |
880 | |
881 | |
882 | |
883 | ARGUMENTS : IN: |
884 | p_old_adj_rec |
885 | |
886 | OUT: |
887 | p_Validation_status |
888 | |
889 | IN/ OUT: |
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
975 arp_util.debug('Validate_Adj_Reverse: ' || 'invalid payment schedule id');
976 END IF;
977 END ;
978
979 ar_adjvalidate_pvt.Validate_dates (
980 p_reversal_date,
981 p_reversal_gl_date,
982 l_ps_rec,
983 l_return_status
984 ) ;
988 IF PG_DEBUG in ('Y', 'C') THEN
985 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
986 THEN
987 p_validation_status := l_return_status;
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 /*-----------------------------------------------+
1065 | Validate Old Adjustment status. Cannot approve|
1066 | if status is 'A' or 'R' |
1067 +----------------------------------------------*/
1068
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')) )
1099 FND_MESSAGE.SET_TOKEN ( 'STATUS', p_adj_rec.status ) ;
1096 THEN
1097
1098 FND_MESSAGE.SET_NAME ('AR', 'AR_AAPI_INVALID_CHANGE_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
1231 END IF ;
1228 IF ( l_temp_adj_rec.status IS NOT NULL )
1229 THEN
1230 p_adj_rec.status := l_temp_adj_rec.status ;
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 | |
1259 | DESCRIPTION |
1260 | This is the populate routine for Line level adjustment |
1261 | |
1262 | |
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: |
1274 | p_return_status |
1275 | |
1276 | IN/ OUT: |
1277 | |
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));
1346 arp_util.debug('=======================================================');
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));
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
1355 EXCEPTION
1356 WHEN others THEN
1357 IF PG_DEBUG in ('Y', 'C') THEN
1358 arp_util.debug('EXCEPTION: (populate_adj_llca_gt)');
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
1408 ll_leg_app varchar2(1);
1409 ll_mfar_app varchar2(1);
1410 ll_leg_adj varchar2(1);
1411 ll_mfar_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
1462
1459 arp_util.debug('create_linelevel_adjustment : ' || 'Warning(s) occurred. Ignoring header level receivables trx id');
1460
1461 END IF;
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 |
1567 | p_api_version |
1568 | p_init_msg_list |
1569 | p_commit |
1570 | p_validation_level |
1571 | p_adj_rec |
1575 | p_return_status |
1572 | p_chk_approval_limits |
1573 | p_check_amount |
1574 | OUT: |
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
1677 l_api_name,
1674 IF NOT FND_API.Compatible_API_Call(
1675 l_api_version,
1676 p_api_version,
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
1802 | Call Prorate calculation routine |
1799 arp_ps_pkg.fetch_p(l_inp_adj_rec.payment_schedule_id,l_app_ps_rec);
1800
1801 /*------------------------------------------+
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
1930 arp_balance_check.Check_Adj_Balance(o_adjustment_id,p_adj_rec.request_id,'Y');
1927 ) ;
1928 /* Bug 4910860
1929 Validate if the accounting entries balance */
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 /*-------------------------------------------------------+
2036 | Handle application errors that result from trapable |
2037 | error conditions. The error messages have already |
2038 | been put on the error stack. |
2039 +-------------------------------------------------------*/
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');
2052 p_count => p_msg_count,
2049 END IF;
2050
2051 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
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,
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,
2126 p_return_status 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;
2148 o_adjustment_id ar_adjustments.adjustment_id%type;
2145 l_app_ps_rec ar_payment_schedules%rowtype;
2146
2147 o_adjustment_number ar_adjustments.adjustment_number%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
2229 /*---------------------------------------------+
2230 | ========== Start of API Body ========== |
2231 +---------------------------------------------*/
2232
2233 /*--------------------------------------------+
2234 | Copy the input adjustment record to local |
2235 | variable to allow changes to it |
2236 +--------------------------------------------*/
2237 l_inp_adj_rec := p_adj_rec ;
2238
2239
2240 /*------------------------------------------------+
2241 | Initialize the profile options and cache data |
2242 +------------------------------------------------*/
2243
2244 ar_adjvalidate_pvt.Init_Context_Rec (
2245 p_validation_level,
2246 l_return_status
2247 );
2248
2249 /*---------------------------------------------------+
2250 | Check the return status |
2251 /*---------------------------------------------------+
2252
2253
2254 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
2255 THEN
2256 p_return_status := l_return_status ;
2257 IF PG_DEBUG in ('Y', 'C') THEN
2258 arp_util.debug('create_linelevel_adjustment: ' || ' Init_context_rec has errors ' );
2259 END IF;
2260 END IF;
2261
2262
2263 /*------------------------------------------------+
2264 | Cache details |
2265 +------------------------------------------------*/
2266
2267 ar_adjvalidate_pvt.Cache_Details (
2268 l_return_status
2269 );
2270
2271 /*---------------------------------------------------+
2272 | Check the return status |
2273 /*---------------------------------------------------+
2274
2275 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
2276 THEN
2277 p_return_status := l_return_status ;
2278 IF PG_DEBUG in ('Y', 'C') THEN
2282
2279 arp_util.debug('create_linelevel_adjustment: ' || ' Cache_details has errors ' );
2280 END IF;
2281 END IF;
2283 /*------------------------------------------+
2284 | Validate the input details |
2285 | Do not continue if there are errors. |
2286 +------------------------------------------*/
2287
2288 /*--------------------------------------------+
2289 | Change for the BOE/BR project has been made |
2290 | parameters p_chk_approval_limits and |
2291 | p_check_amount are being passed. |
2292 | |
2293 | p_check_amount will only be 'F' in case of |
2294 | reversal of adjustments |
2295 +---------------------------------------------*/
2296
2297 /*--------------------------------------------------+
2298 | Bug 1290698- If Partial partial amount is passed |
2299 | Calculate prorated amounts remaining.Need not |
2300 | prorate while reversing |
2301 +--------------------------------------------------*/
2302
2303 l_chk_approval_limits := p_chk_approval_limits;
2304 l_check_amount := p_check_amount;
2305
2306 IF (l_chk_approval_limits IS NULL) THEN
2307 l_chk_approval_limits := FND_API.G_TRUE;
2308 END IF;
2309
2310 IF (l_check_amount IS NULL) THEN
2311 l_check_amount := FND_API.G_TRUE;
2312 END IF;
2313
2314
2315 populate_adj_llca_gt (
2316 p_customer_trx_id => p_adj_rec.customer_trx_id,
2317 p_llca_adj_trx_lines_tbl => p_llca_adj_trx_lines_tbl,
2318 p_return_status => l_gt_return_status);
2319
2320
2321 IF l_gt_return_status <> FND_API.G_RET_STS_SUCCESS
2322 THEN
2323
2324 p_return_status := FND_API.G_RET_STS_ERROR ;
2325
2326 IF PG_DEBUG in ('Y', 'C') THEN
2327 arp_util.debug('create_linelevel_adjustment : ' || 'Error(s) occurred. Rolling back and setting status to ERROR');
2328 arp_util.debug('create_linelevel_adjustment : ' || 'Error while populating GT table');
2329 END IF;
2330
2331 END IF;
2332
2333 IF (p_return_status = FND_API.G_RET_STS_ERROR)
2334 THEN
2335 RAISE FND_API.G_EXC_ERROR;
2336
2337 ELSIF (p_return_status = FND_API.G_RET_STS_UNEXP_ERROR)
2338 THEN
2339 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2340 END IF;
2341
2342 /*--------------------------------------------------+
2343 | Header level Validation Call |
2344 +--------------------------------------------------*/
2345
2346
2347 validate_hdr_level (
2348 p_adj_rec,
2349 l_hdr_return_status);
2350
2351
2352 IF l_hdr_return_status <> FND_API.G_RET_STS_SUCCESS
2353 THEN
2354 p_return_status := FND_API.G_RET_STS_ERROR ;
2355
2356 IF PG_DEBUG in ('Y', 'C') THEN
2357 arp_util.debug('create_linelevel_adjustment : ' || 'Error(s) occurred. Rolling back and setting status to ERROR');
2358 arp_util.debug('create_linelevel_adjustment : ' || 'Error while populating GT table');
2359 END IF;
2360
2361 END IF;
2362
2363
2364 IF (p_return_status = FND_API.G_RET_STS_ERROR)
2365 THEN
2366 RAISE FND_API.G_EXC_ERROR;
2367
2368 ELSIF (p_return_status = FND_API.G_RET_STS_UNEXP_ERROR)
2369 THEN
2370 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2371 END IF;
2372
2373
2374 IF ( p_return_status = FND_API.G_RET_STS_SUCCESS ) -- Start of for loop processing
2375 THEN
2376
2377
2378 --For i in p_llca_adj_trx_lines_tbl.FIRST..p_llca_adj_trx_lines_tbl.LAST
2379 FOR gt_adj_lines_row IN gt_adj_lines_cur(p_adj_rec.customer_trx_id)
2380 Loop
2381
2382 /* l_inp_adj_rec.customer_trx_line_id := p_llca_adj_trx_lines_tbl(i).customer_trx_line_id;
2383 l_inp_adj_rec.receivables_trx_id := p_llca_adj_trx_lines_tbl(i).receivables_trx_id;
2384 l_inp_adj_rec.amount := p_llca_adj_trx_lines_tbl(i).line_amount;*/
2385
2386 l_line_return_status := FND_API.G_RET_STS_SUCCESS;
2387
2388
2389 l_inp_adj_rec.customer_trx_line_id := gt_adj_lines_row.customer_trx_line_id;
2390 l_inp_adj_rec.receivables_trx_id := gt_adj_lines_row.receivables_trx_id;
2391 l_inp_adj_rec.amount := gt_adj_lines_row.line_amount;
2392
2393 l_adj_int_count := l_adj_int_count + 1;
2394 p_llca_adj_create_tbl_type(l_adj_int_count).adjustment_number := 0;
2395 p_llca_adj_create_tbl_type(l_adj_int_count).adjustment_id := 0;
2396 p_llca_adj_create_tbl_type(l_adj_int_count).customer_trx_line_id := gt_adj_lines_row.customer_trx_line_id;
2397
2398 -- Check for null customer trx line id
2399 IF gt_adj_lines_row.customer_trx_line_id IS NULL -- Check for null Customer Trx Line Id
2400 THEN
2401 insert into ar_llca_adj_trx_errors_gt
2402 (
2403 customer_trx_id,
2404 customer_trx_line_id,
2405 receivables_trx_id,
2406 error_message,
2407 invalid_value
2408 )
2409 values
2410 (
2411 l_inp_adj_rec.customer_trx_id,
2412 0,
2413 l_inp_adj_rec.receivables_trx_id,
2414 'AR_RAPI_TRX_LINE_ID_INVALID ',
2415 'customer_trx_line_id'
2416 );
2417
2418 l_line_return_status := FND_API.G_RET_STS_ERROR;
2419
2423 insert into ar_llca_adj_trx_errors_gt
2420 ELSIF gt_adj_lines_row.receivables_trx_id IS NULL
2421 THEN
2422
2424 (
2425 customer_trx_id,
2426 customer_trx_line_id,
2427 receivables_trx_id,
2428 error_message,
2429 invalid_value
2430 )
2431 values
2432 (
2433 l_inp_adj_rec.customer_trx_id,
2434 l_inp_adj_rec.customer_trx_line_id,
2435 0,
2436 'AR_RAPI_RECEIVABLES_TRX_ID_INVALID ',
2437 'receivables_trx_id'
2438 );
2439
2440 l_line_return_status := FND_API.G_RET_STS_ERROR;
2441
2442 ELSE
2443
2444 ar_adjust_pub.Validate_Adj_Insert(
2445 l_inp_adj_rec,
2446 l_chk_approval_limits,
2447 l_check_amount,
2448 l_return_status,
2449 'Y'
2450 );
2451
2452 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
2453 THEN
2454 l_line_return_status := l_return_status ;
2455 IF PG_DEBUG in ('Y', 'C') THEN
2456 arp_util.debug('create_linelevel_adjustment: ' || 'Validation error(s) occurred.');
2457 END IF;
2458 END IF;
2459
2460
2461
2462 /*-----------------------------------------------+
2463 | Build up remaining data for the entity handler |
2464 | Reset attributes which should not be populated |
2465 +-----------------------------------------------*/
2466
2467
2468 IF ( l_line_return_status = FND_API.G_RET_STS_SUCCESS ) THEN
2469 ar_adjust_pub.Set_Remaining_Attributes (
2470 l_inp_adj_rec,
2471 l_return_status
2472 ) ;
2473
2474 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
2475 THEN
2476
2477 l_line_return_status := l_return_status ;
2478 IF PG_DEBUG in ('Y', 'C') THEN
2479 arp_util.debug('create_linelevel_adjustment: ' ||
2480 'Validation error(s) occurred.');
2481 END IF;
2482
2483 END IF;
2484 END IF;
2485
2486 END IF; -- Check for null Customer Trx Line Id
2487
2488 /*-----------------------------------------------+
2489 | Call the entity Handler for insert |
2490 +-----------------------------------------------*/
2491
2492 IF ( l_line_return_status = FND_API.G_RET_STS_SUCCESS ) THEN -- Processing the adjustment
2493
2494 IF (l_inp_adj_rec.code_combination_id is NOT NULL) THEN
2495 l_override_flag := 'Y';
2496 END IF;
2497
2498 IF PG_DEBUG in ('Y', 'C') THEN
2499 arp_util.debug('create_linelevel_adjustment: ' || 'l_inp_adj_rec.line_adjusted = ' || to_char(l_inp_adj_rec.line_adjusted));
2500 arp_util.debug('create_linelevel_adjustment: ' || 'l_inp_adj_rec.tax_adjusted = ' || to_char(l_inp_adj_rec.tax_adjusted));
2501 END IF;
2502
2503 BEGIN
2504 arp_process_adjustment.insert_adjustment (
2505 'DUMMY',
2506 '1',
2507 l_inp_adj_rec,
2508 o_adjustment_number,
2509 o_adjustment_id,
2510 l_check_amount,
2511 p_move_deferred_tax,
2512 p_called_from,
2513 p_old_adjust_id,
2514 l_override_flag,
2515 'LINE'
2516 ) ;
2517 /* Bug 4910860
2518 Validate if the accounting entries balance */
2519 arp_balance_check.Check_Adj_Balance(o_adjustment_id,p_adj_rec.request_id,'Y');
2520
2521
2522 EXCEPTION
2523 WHEN OTHERS THEN
2524 /*---------------------------------------------------+
2525 | Rollback to the defined Savepoint |
2526 +---------------------------------------------------*/
2527
2528 ROLLBACK TO ar_adjust_line_PUB;
2529 p_return_status := FND_API.G_RET_STS_ERROR ;
2530
2531 FND_MESSAGE.set_name( 'AR', 'GENERIC_MESSAGE' );
2532 FND_MESSAGE.set_token( 'GENERIC_TEXT', 'arp_process_adjustment.insert_adjustment exception: '||SQLERRM );
2533 --2920926
2534 FND_MSG_PUB.ADD;
2535 /*--------------------------------------------------+
2536 | Get message count and if 1, return message data |
2537 +---------------------------------------------------*/
2538
2539 FND_MSG_PUB.Count_And_Get(
2540 p_encoded => FND_API.G_FALSE,
2541 p_count => p_msg_count,
2542 p_data => p_msg_data
2543 );
2544 IF PG_DEBUG in ('Y', 'C') THEN
2545 arp_util.debug('create_linelevel_adjustment: ' ||
2546 'Error in Insert Entity handler. Rolling back ' ||
2547 'and setting status to ERROR');
2548 END IF;
2549 RETURN;
2550
2551 END ;
2552
2553
2554
2555 p_llca_adj_create_tbl_type(l_adj_int_count).adjustment_number := o_adjustment_number ;
2556 p_llca_adj_create_tbl_type(l_adj_int_count).adjustment_id := o_adjustment_id ;
2557
2558
2559
2560
2561
2562 /*-------------------------------------------+
2566 END LOOP; -- END of table loop
2563 | ========== End of API Body ========== |
2564 +-------------------------------------------*/
2565 END IF; -- END of Processing the adjustment
2567 END IF; -- END of for loop processing
2568 END IF;
2569
2570 /*---------------------------------------------------+
2571 | Get message count and if 1, return message data |
2572 +---------------------------------------------------*/
2573
2574 FND_MSG_PUB.Count_And_Get(
2575 p_encoded => FND_API.G_FALSE,
2576 p_count => p_msg_count,
2577 p_data => p_msg_data
2578 );
2579
2580 /*--------------------------------+
2581 | Standard check of p_commit |
2582 +--------------------------------*/
2583
2584 IF FND_API.To_Boolean( p_commit_flag )
2585 THEN
2586 IF PG_DEBUG in ('Y', 'C') THEN
2587 arp_util.debug('create_linelevel_adjustment: ' || 'committing');
2588 END IF;
2589 Commit;
2590 END IF;
2591
2592 IF PG_DEBUG in ('Y', 'C') THEN
2593 arp_util.debug('create_linelevel_adjustment()- ');
2594 END IF;
2595
2596 IF (FND_MSG_PUB.Check_Msg_Level (G_MSG_LOW)) THEN
2597 select TO_CHAR( (hsecs - G_START_TIME) / 100)
2598 into l_hsec
2599 from v$timer;
2600 IF PG_DEBUG in ('Y', 'C') THEN
2601 arp_util.debug('create_linelevel_adjustment: ' || 'Elapsed Time : '||l_hsec||' seconds');
2602 END IF;
2603 END IF;
2604
2605 EXCEPTION
2606 WHEN FND_API.G_EXC_ERROR THEN
2607
2608 IF PG_DEBUG in ('Y', 'C') THEN
2609 arp_util.debug('create_linelevel_adjustment: ' || SQLCODE);
2610 arp_util.debug('create_linelevel_adjustment: ' || SQLERRM);
2611 END IF;
2612
2613 ROLLBACK TO ar_adjust_line_PUB;
2614 p_return_status := FND_API.G_RET_STS_ERROR ;
2615 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
2616 p_count => p_msg_count,
2617 p_data => p_msg_data
2618 );
2619
2620 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2621
2622 IF PG_DEBUG in ('Y', 'C') THEN
2623 arp_util.debug('create_linelevel_adjustment: ' || SQLERRM);
2624 END IF;
2625 ROLLBACK TO ar_adjust_line_PUB ;
2626 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2627 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
2628 p_count => p_msg_count,
2629 p_data => p_msg_data
2630 );
2631
2632 WHEN OTHERS THEN
2633
2634 /*-------------------------------------------------------+
2635 | Handle application errors that result from trapable |
2636 | error conditions. The error messages have already |
2637 | been put on the error stack. |
2638 +-------------------------------------------------------*/
2639
2640 IF (SQLCODE = -20001)
2641 THEN
2642 p_return_status := FND_API.G_RET_STS_ERROR ;
2643 ROLLBACK TO ar_adjust_line_PUB;
2644 IF PG_DEBUG in ('Y', 'C') THEN
2645 arp_util.debug('create_linelevel_adjustment: ' ||
2646 'Completion validation error(s) occurred. ' ||
2647 'Rolling back and setting status to ERROR');
2648 END IF;
2649
2650 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
2651 p_count => p_msg_count,
2652 p_data => p_msg_data
2653 );
2654 RETURN;
2655 ELSE
2656 NULL;
2657 END IF;
2658
2659 arp_util.disable_debug;
2660
2661 END create_linelevel_adjustment;
2662
2663
2664 /*===========================================================================+
2665 | PROCEDURE |
2666 | Modify_Adjustment |
2667 | |
2668 | DESCRIPTION |
2669 | This is the main routine that modifies an adjustment |
2670 | |
2671 | SCOPE - PUBLIC |
2672 | |
2673 | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED |
2674 | fnd_api.compatible_api_call |
2675 | fnd_api.g_exc_unexpected_error |
2676 | fnd_api.g_ret_sts_error |
2677 | fnd_api.g_ret_sts_error |
2681 | fnd_msg_pub.count_and_get |
2678 | fnd_api.g_ret_sts_success |
2679 | fnd_api.to_boolean |
2680 | fnd_msg_pub.check_msg_level |
2682 | fnd_msg_pub.initialize |
2683 | ar_adjustments_pkg.fetch_p |
2684 | ar_process_adjustment.update_adjustment |
2685 | ar_adjvalidate_pvt.within_approval_limit |
2686 | |
2687 | ARGUMENTS : IN: |
2688 | p_api_name |
2689 | p_api_version |
2690 | p_init_msg_list |
2691 | p_commit_flag |
2692 | p_validation_level |
2693 | p_adj_rec |
2694 | p_chk_approval_limits |
2695 | p_old_adjust_id |
2696 | OUT: |
2697 | p_return_status |
2698 | p_msg_count |
2699 | p_msg_data |
2700 | |
2701 | IN/ OUT: |
2702 | |
2703 | |
2704 | RETURNS : NONE |
2705 | |
2706 | NOTES |
2707 | |
2708 | MODIFICATION HISTORY |
2709 | Vivek Halder 30-JAN-97 Created |
2710 | Saloni Shah 03-FEB-00 Changes have been made for the BR/BOE project|
2711 | One new parameter has been added: |
2712 | - p_chk_approval_limits. |
2713 | This parameter will be passed to |
2714 | Validate_Adj_Modify procedure. |
2715 | If the value of the flag p_chk_approval_limit|
2716 | is set to 'F' then the adjusted amount will |
2717 | not be validated against the users approval |
2718 | limits. |
2719 | Satheesh Nambiar 17-May-00 Added one more parameter p_move_deferred_tax|
2720 | for BOE/BR
2721 +===========================================================================*/
2722
2723 PROCEDURE Modify_Adjustment (
2724 p_api_name IN varchar2,
2725 p_api_version IN number,
2726 p_init_msg_list IN varchar2 := FND_API.G_FALSE,
2727 p_commit_flag IN varchar2 := FND_API.G_FALSE,
2728 p_validation_level IN number := FND_API.G_VALID_LEVEL_FULL,
2729 p_msg_count OUT NOCOPY number,
2730 p_msg_data OUT NOCOPY varchar2,
2731 p_return_status OUT NOCOPY varchar2 ,
2732 p_adj_rec IN ar_adjustments%rowtype,
2733 p_chk_approval_limits IN varchar2 := FND_API.G_TRUE,
2734 p_move_deferred_tax IN varchar2,
2735 p_old_adjust_id IN ar_adjustments.adjustment_id%type,
2736 p_org_id IN NUMBER DEFAULT NULL
2737 ) IS
2738
2739 l_api_name CONSTANT VARCHAR2(20) := 'AR_ADJUST_PUB';
2740 l_api_version CONSTANT NUMBER := 1.0;
2741 l_old_adj_rec ar_adjustments%rowtype;
2742 l_hsec VARCHAR2(10);
2743 l_status number;
2744 l_inp_adj_rec ar_adjustments%rowtype;
2745 l_return_status varchar2(1) := FND_API.G_RET_STS_SUCCESS;
2746 l_chk_approval_limits varchar2(1);
2747 l_org_return_status VARCHAR2(1);
2748 l_org_id NUMBER;
2749 l_count_chk NUMBER;
2750
2751
2752 BEGIN
2753 IF (FND_MSG_PUB.Check_Msg_Level (G_MSG_LOW)) THEN
2754 select hsecs
2755 into G_START_TIME
2756 from v$timer;
2757 END IF;
2758
2759 /*------------------------------------+
2760 | Standard start of API savepoint |
2761 +------------------------------------*/
2762
2763 SAVEPOINT ar_adjust_PUB;
2764
2765 /*--------------------------------------------------+
2766 | Standard call to check for call compatibility |
2767 +--------------------------------------------------*/
2768
2769 IF NOT FND_API.Compatible_API_Call(
2770 l_api_version,
2771 p_api_version,
2772 l_api_name,
2773 G_PKG_NAME
2774 )
2775 THEN
2776 IF PG_DEBUG in ('Y', 'C') THEN
2780 END IF;
2777 arp_util.debug('Modify_Adjustment: ' || 'Compatility error occurred.');
2778 END IF;
2779 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2781
2782 /*-------------------------------------------------------------+
2783 | Initialize message list if p_init_msg_list is set to TRUE |
2784 +-------------------------------------------------------------*/
2785
2786 IF FND_API.to_Boolean( p_init_msg_list )
2787 THEN
2788 FND_MSG_PUB.initialize;
2789 END IF;
2790
2791 -- arp_util.enable_debug(100000);
2792
2793
2794 IF PG_DEBUG in ('Y', 'C') THEN
2795 arp_util.debug('Modify_Adjustment()+ ');
2796 END IF;
2797
2798 /*-----------------------------------------+
2799 | Initialize return status to SUCCESS |
2800 +-----------------------------------------*/
2801
2802 p_return_status := FND_API.G_RET_STS_SUCCESS;
2803
2804
2805
2806 /* SSA change */
2807 l_org_id := p_org_id;
2808 l_org_return_status := FND_API.G_RET_STS_SUCCESS;
2809 ar_mo_cache_utils.set_org_context_in_api(p_org_id =>l_org_id,
2810 p_return_status =>l_org_return_status);
2811 IF l_org_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2812 p_return_status := FND_API.G_RET_STS_ERROR;
2813 ELSE
2814 /*---------------------------------------------+
2815 | ========== Start of API Body ========== |
2816 +---------------------------------------------*/
2817
2818 /*---------------------------------------------+
2819 | Copy the input record to local variable to |
2820 | allow changes to it |
2821 +---------------------------------------------*/
2822 l_inp_adj_rec := p_adj_rec ;
2823
2824
2825 /*------------------------------------------------+
2826 | Initialize the profile options and cache data |
2827 +------------------------------------------------*/
2828
2829 ar_adjvalidate_pvt.Init_Context_Rec (
2830 p_validation_level,
2831 l_return_status
2832 );
2833 /*------------------------------------------------+
2834 | Check status and return if error |
2835 +------------------------------------------------*/
2836
2837 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
2838 THEN
2839 p_return_status := l_return_status ;
2840 IF PG_DEBUG in ('Y', 'C') THEN
2841 arp_util.debug('Modify_Adjustment: ' || 'failed to initialize the profile options ');
2842 END IF;
2843 END IF;
2844
2845 /*------------------------------------------------+
2846 | Cache details |
2847 +------------------------------------------------*/
2848
2849 ar_adjvalidate_pvt.Cache_Details (
2850 l_return_status
2851 );
2852 /*------------------------------------------------+
2853 | Check status and return if error |
2854 +------------------------------------------------*/
2855
2856 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
2857 THEN
2858 p_return_status := l_return_status ;
2859 IF PG_DEBUG in ('Y', 'C') THEN
2860 arp_util.debug('Modify_Adjustment: ' || 'failed to cache details ');
2861 END IF;
2862 END IF;
2863
2864 /*------------------------------------------------+
2865 | Fetch details of the old adjustment record |
2866 +------------------------------------------------*/
2867 BEGIN
2868 arp_adjustments_pkg.fetch_p (
2869 l_old_adj_rec,
2870 p_old_adjust_id
2871 );
2872 EXCEPTION
2873 WHEN OTHERS THEN
2874 /*---------------------------------------------------+
2875 | Rollback to the defined Savepoint |
2876 +---------------------------------------------------*/
2877 ROLLBACK TO ar_adjust_PUB;
2878 p_return_status := FND_API.G_RET_STS_ERROR ;
2879 FND_MESSAGE.SET_NAME ('AR', 'AR_AAPI_INVALID_ADJ_ID');
2880 FND_MESSAGE.SET_TOKEN ( 'ADJUSTMENT_ID', to_char(p_old_adjust_id) ) ;
2881 FND_MSG_PUB.ADD ;
2882 RETURN;
2883 END ;
2884
2885 /*------------------------------------------+
2886 | Validate for Line level |
2887 | Do not continue if exist AR_ACTIVITY_DETAILS. |
2888 +------------------------------------------*/
2889
2890 BEGIN
2891 Select count(*)
2892 into l_count_chk
2893 from AR_ACTIVITY_DETAILS
2894 where source_id = p_old_adjust_id
2895 and source_table = 'ADJ'
2896 and nvl(CURRENT_ACTIVITY_FLAG,'Y') = 'Y' -- Bug 7241111
2897 and customer_trx_line_id = l_old_adj_rec.customer_trx_line_id;
2898 EXCEPTION
2899 When others then
2900 l_count_chk := 0;
2901 END;
2902
2903 IF l_count_chk <> 0 THEN
2904 p_return_status := FND_API.G_RET_STS_ERROR ;
2908 'and setting status to ERROR');
2905 IF PG_DEBUG in ('Y', 'C') THEN
2906 arp_util.debug('Modify_Adjustment: ' ||
2907 'Validation error(s) occurred. Rolling back ' ||
2909 END IF;
2910
2911 FND_MESSAGE.SET_NAME ('AR', 'AR_LL_ADJ_MODIFY_NOT_ALLOWED');
2912 FND_MESSAGE.SET_TOKEN ( 'ADJUST_ID', p_old_adjust_id ) ;
2913 FND_MSG_PUB.ADD ;
2914
2915 END IF;
2916
2917
2918 /*-----------------------------------------------+
2919 | Handling Line level the validation exceptions |
2920 +-----------------------------------------------*/
2921 IF (p_return_status = FND_API.G_RET_STS_ERROR)
2922 THEN
2923 RAISE FND_API.G_EXC_ERROR;
2924 ELSIF (p_return_status = FND_API.G_RET_STS_UNEXP_ERROR)
2925 THEN
2926 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2927 END IF;
2928
2929
2930
2931 /*------------------------------------------+
2932 | Validate the input details |
2933 | Do not continue if there are errors. |
2934 +------------------------------------------*/
2935
2936 /*--------------------------------------------------+
2937 | Change for the BOE/BR project has been made |
2938 | parameter p_chk_approval_limits is being passed. |
2939 +--------------------------------------------------*/
2940 l_chk_approval_limits := p_chk_approval_limits;
2941 IF (l_chk_approval_limits IS NULL) THEN
2942 l_chk_approval_limits := FND_API.G_TRUE;
2943 END IF;
2944
2945 ar_adjust_pub.Validate_Adj_Modify (
2946 l_inp_adj_rec,
2947 l_old_adj_rec,
2948 l_chk_approval_limits,
2949 l_return_status
2950 );
2951
2952
2953 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
2954 THEN
2955 p_return_status := l_return_status ;
2956 IF PG_DEBUG in ('Y', 'C') THEN
2957 arp_util.debug('Modify_Adjustment: ' ||
2958 'Validation error(s) occurred. Rolling back ' ||
2959 'and setting status to ERROR');
2960 END IF;
2961 END IF;
2962
2963
2964 /*-----------------------------------------------+
2965 | Handling all the validation exceptions |
2966 +-----------------------------------------------*/
2967 IF (p_return_status = FND_API.G_RET_STS_ERROR)
2968 THEN
2969 RAISE FND_API.G_EXC_ERROR;
2970 ELSIF (p_return_status = FND_API.G_RET_STS_UNEXP_ERROR)
2971 THEN
2972 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2973 END IF;
2974
2975
2976 /*-----------------------------------------------+
2977 | Call the entity Handler for Modify |
2978 +-----------------------------------------------*/
2979 BEGIN
2980 arp_process_adjustment.update_adjustment (
2981 'DUMMY',
2982 '1',
2983 l_inp_adj_rec,
2984 p_move_deferred_tax,
2985 p_old_adjust_id
2986 ) ;
2987
2988 EXCEPTION
2989 WHEN OTHERS THEN
2990 /*---------------------------------------------------+
2991 | Rollback to the defined Savepoint |
2992 +---------------------------------------------------*/
2993
2994 ROLLBACK TO ar_adjust_PUB;
2995
2996 p_return_status := FND_API.G_RET_STS_ERROR ;
2997
2998 FND_MESSAGE.set_name( 'AR', 'GENERIC_MESSAGE' );
2999 FND_MESSAGE.set_token( 'GENERIC_TEXT', 'arp_process_adjustment.update_adjustment exception: '||SQLERRM );
3000 --2920926
3001 FND_MSG_PUB.ADD;
3002
3003 /*--------------------------------------------------+
3004 | Get message count and if 1, return message data |
3005 +---------------------------------------------------*/
3006
3007 FND_MSG_PUB.Count_And_Get(
3008 p_encoded => FND_API.G_FALSE,
3009 p_count => p_msg_count,
3010 p_data => p_msg_data
3011 );
3012 IF PG_DEBUG in ('Y', 'C') THEN
3013 arp_util.debug('Modify_Adjustment: ' ||
3014 'Error in Insert Entity handler. Rolling back '||
3015 'and setting status to ERROR');
3016 END IF;
3017
3018 RETURN;
3019
3020 END ;
3021
3022 /*-------------------------------------------+
3023 | ========== End of API Body ========== |
3024 +-------------------------------------------*/
3025 END IF;
3026
3027 /*---------------------------------------------------+
3028 | Get message count and if 1, return message data |
3029 +---------------------------------------------------*/
3030
3031 FND_MSG_PUB.Count_And_Get(
3032 p_encoded => FND_API.G_FALSE,
3033 p_count => p_msg_count,
3034 p_data => p_msg_data
3035 );
3036
3040
3037 /*--------------------------------+
3038 | Standard check of p_commit |
3039 +--------------------------------*/
3041 IF FND_API.To_Boolean( p_commit_flag )
3042 THEN
3043 IF PG_DEBUG in ('Y', 'C') THEN
3044 arp_util.debug('Modify_Adjustment: ' || 'committing');
3045 END IF;
3046 Commit;
3047 END IF;
3048
3049 IF PG_DEBUG in ('Y', 'C') THEN
3050 arp_util.debug('Modify_Adjustment()- ');
3051 END IF;
3052
3053 IF (FND_MSG_PUB.Check_Msg_Level (G_MSG_LOW)) THEN
3054 select TO_CHAR( (hsecs - G_START_TIME) / 100)
3055 into l_hsec
3056 from v$timer;
3057 IF PG_DEBUG in ('Y', 'C') THEN
3058 arp_util.debug('Modify_Adjustment: ' || 'Elapsed Time : '||l_hsec||' seconds');
3059 END IF;
3060 END IF;
3061
3062
3063
3064 EXCEPTION
3065 WHEN FND_API.G_EXC_ERROR THEN
3066
3067 IF PG_DEBUG in ('Y', 'C') THEN
3068 arp_util.debug('Modify_Adjustment: ' || SQLCODE);
3069 arp_util.debug('Modify_Adjustment: ' || SQLERRM);
3070 END IF;
3071
3072 ROLLBACK TO ar_adjust_PUB;
3073 p_return_status := FND_API.G_RET_STS_ERROR ;
3074 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
3075 p_count => p_msg_count,
3076 p_data => p_msg_data
3077 );
3078
3079 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3080
3081 IF PG_DEBUG in ('Y', 'C') THEN
3082 arp_util.debug('Modify_Adjustment: ' || SQLERRM);
3083 END IF;
3084 ROLLBACK TO ar_adjust_PUB ;
3085 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
3086 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
3087 p_count => p_msg_count,
3088 p_data => p_msg_data
3089 );
3090
3091 WHEN OTHERS THEN
3092
3093 /*-------------------------------------------------------+
3094 | Handle application errors that result from trapable |
3095 | error conditions. The error messages have already |
3096 | been put on the error stack. |
3097 +-------------------------------------------------------*/
3098
3099 IF (SQLCODE = -20001)
3100 THEN
3101 p_return_status := FND_API.G_RET_STS_ERROR ;
3102 ROLLBACK TO ar_adjust_PUB;
3103 IF PG_DEBUG in ('Y', 'C') THEN
3104 arp_util.debug('Modify_Adjustment: ' ||
3105 'Completion validation error(s) occurred. ' ||
3106 'Rolling back and setting status to ERROR');
3107 END IF;
3108 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
3109 p_count => p_msg_count,
3110 p_data => p_msg_data
3111 );
3112 RETURN;
3113 ELSE
3114 NULL;
3115 END IF;
3116
3117 arp_util.disable_debug;
3118
3119 END Modify_Adjustment;
3120
3121
3122 /*===========================================================================+
3123 | PROCEDURE |
3124 | Reverse_Adjustment |
3125 | |
3126 | DESCRIPTION |
3127 | This is the main routine that reverses an adjustment |
3128 | |
3129 | SCOPE - PUBLIC |
3130 | |
3131 | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED |
3132 | fnd_api.compatible_api_call |
3133 | fnd_api.g_exc_unexpected_error |
3134 | fnd_api.g_ret_sts_error |
3135 | fnd_api.g_ret_sts_error |
3136 | fnd_api.g_ret_sts_success |
3137 | fnd_api.to_boolean |
3138 | fnd_msg_pub.check_msg_level |
3139 | fnd_msg_pub.count_and_get |
3140 | fnd_msg_pub.initialize |
3141 | ar_adjustments_pkg.fetch_p |
3142 | ar_process_adjustment.reverse_adjustment |
3143 | |
3144 | ARGUMENTS : IN: |
3145 | p_api_name |
3146 | p_api_version |
3150 | p_chk_approval_limits |
3147 | p_init_msg_list |
3148 | p_commit_flag |
3149 | p_validation_level |
3151 | p_old_adjust_id |
3152 | OUT: |
3153 | p_return_status |
3154 | p_msg_count |
3155 | p_msg_data |
3156 | p_new_adj_id |
3157 | |
3158 | IN/ OUT: |
3159 | |
3160 | |
3161 | RETURNS : NONE |
3162 | |
3163 | NOTES |
3164 | |
3165 | MODIFICATION HISTORY |
3166 | Vivek Halder 30-JAN-97 Created |
3167 | Saloni Shah 03-FEB-00 Made changes for BR/BOE project. |
3168 | Added 1 new parameter: |
3169 | - p_chk_approval_limits |
3170 | Made changes the way a reverse adjustment is |
3171 | created. It used to used to call |
3172 | arp_process_adjustment.reverse_adjustment |
3173 | which used to create a reverse adjustment but|
3174 | not update the payment schedules. This has |
3175 | been changed to call Create Adjustment. |
3176 | S.Nambiar 27-Sep-00 Added a new parameter p_called_from for BR |
3177 | S.Nambiar 28-Nov-00 Bug 1449758 - Modified Reverse routine to |
3178 | initialize gl_posted_date and posting_control_id
3179 +===========================================================================*/
3180
3181 PROCEDURE Reverse_Adjustment (
3182 p_api_name IN varchar2,
3183 p_api_version IN number,
3184 p_init_msg_list IN varchar2 := FND_API.G_FALSE,
3185 p_commit_flag IN varchar2 := FND_API.G_FALSE,
3186 p_validation_level IN number := FND_API.G_VALID_LEVEL_FULL,
3187 p_msg_count OUT NOCOPY number,
3188 p_msg_data OUT NOCOPY varchar2,
3189 p_return_status OUT NOCOPY varchar2,
3190 p_old_adjust_id IN ar_adjustments.adjustment_id%type,
3191 p_reversal_gl_date IN date,
3192 p_reversal_date IN date,
3193 p_comments IN ar_adjustments.comments%type,
3194 p_chk_approval_limits IN varchar2 := FND_API.G_TRUE,
3195 p_move_deferred_tax IN varchar2,
3196 p_new_adj_id OUT NOCOPY ar_adjustments.adjustment_id%type,
3197 p_called_from IN varchar2,
3198 p_org_id IN NUMBER DEFAULT NULL
3199 ) IS
3200
3201 l_api_name CONSTANT VARCHAR2(20) := 'AR_ADJUST_PUB';
3202 l_api_version CONSTANT NUMBER := 1.0;
3203
3204 l_reversal_date ar_adjustments.apply_date%type;
3205 l_reversal_gl_date ar_adjustments.gl_date%type;
3206 l_hsec VARCHAR2(10);
3207 l_status number;
3208 l_adj_rec ar_adjustments%rowtype;
3209 l_msg_count number;
3210 l_msg_data varchar2(250);
3211 l_new_adj_num ar_adjustments.adjustment_number%type;
3212 l_check_amount varchar2(1);
3213
3214 l_return_status varchar2(1) := FND_API.G_RET_STS_SUCCESS;
3215 l_chk_approval_limits varchar2(1);
3216 l_org_return_status VARCHAR2(1);
3217 l_org_id NUMBER;
3218
3219 -- Line Leve Reversal
3220 l_llca_adj_trx_lines_tbl ar_adjust_pub.llca_adj_trx_line_tbl_type;
3221 l_llca_adj_create_tbl_type ar_adjust_pub.llca_adj_create_tbl_type;
3222 l_count_chk NUMBER;
3223
3224
3225
3226 BEGIN
3227 IF (FND_MSG_PUB.Check_Msg_Level (G_MSG_LOW)) THEN
3228 select hsecs
3229 into G_START_TIME
3230 from v$timer;
3231 END IF;
3232
3233 /*------------------------------------+
3234 | Standard start of API savepoint |
3235 +------------------------------------*/
3236
3237 SAVEPOINT ar_adjust_PUB;
3238
3239 /*--------------------------------------------------+
3240 | Standard call to check for call compatibility |
3241 +--------------------------------------------------*/
3242
3243 IF NOT FND_API.Compatible_API_Call(
3244 l_api_version,
3245 p_api_version,
3246 l_api_name,
3247 G_PKG_NAME
3248 )
3249 THEN
3250 IF PG_DEBUG in ('Y', 'C') THEN
3251 arp_util.debug('Reverse_Adjustment: ' || 'Compatility error occurred.');
3252 END IF;
3253 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3254 END IF;
3255
3256 /*-------------------------------------------------------------+
3257 | Initialize message list if p_init_msg_list is set to TRUE |
3258 +-------------------------------------------------------------*/
3259
3260 IF FND_API.to_Boolean( p_init_msg_list )
3261 THEN
3265 -- arp_util.enable_debug(100000);
3262 FND_MSG_PUB.initialize;
3263 END IF;
3264
3266
3267
3268 IF PG_DEBUG in ('Y', 'C') THEN
3269 arp_util.debug('Reverse_Adjustment()+ ');
3270 END IF;
3271
3272 /*-----------------------------------------+
3273 | Initialize return status to SUCCESS |
3274 +-----------------------------------------*/
3275
3276 p_return_status := FND_API.G_RET_STS_SUCCESS;
3277
3278
3279
3280 /* SSA change */
3281 l_org_id := p_org_id;
3282 l_org_return_status := FND_API.G_RET_STS_SUCCESS;
3283 ar_mo_cache_utils.set_org_context_in_api(p_org_id =>l_org_id,
3284 p_return_status =>l_org_return_status);
3285 IF l_org_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3286 p_return_status := FND_API.G_RET_STS_ERROR;
3287 ELSE
3288 /*---------------------------------------------+
3289 | ========== Start of API Body ========== |
3290 +---------------------------------------------*/
3291
3292
3293 /*------------------------------------------------+
3294 | Initialize the profile options and cache data |
3295 +------------------------------------------------*/
3296
3297 ar_adjvalidate_pvt.Init_Context_Rec (
3298 p_validation_level,
3299 l_return_status
3300 );
3301 /*------------------------------------------------+
3302 | Check status and return if error |
3303 +------------------------------------------------*/
3304
3305 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
3306 THEN
3307 p_return_status := l_return_status ;
3308 IF PG_DEBUG in ('Y', 'C') THEN
3309 arp_util.debug('Reverse_Adjustment: ' || ' failed to Initialize the profile options ');
3310 END IF;
3311 END IF;
3312
3313 /*------------------------------------------------+
3314 | Fetch details of the old adjustment record |
3315 +------------------------------------------------*/
3316 BEGIN
3317
3318 arp_adjustments_pkg.fetch_p (
3319 l_adj_rec,
3320 p_old_adjust_id
3321 );
3322 EXCEPTION
3323 WHEN OTHERS THEN
3324 /*---------------------------------------------------+
3325 | Rollback to the defined Savepoint |
3326 +---------------------------------------------------*/
3327
3328 ROLLBACK TO ar_adjust_PUB;
3329
3330 p_return_status := FND_API.G_RET_STS_ERROR ;
3331
3332 FND_MESSAGE.SET_NAME ('AR', 'AR_AAPI_INVALID_ADJ_ID');
3333 FND_MESSAGE.SET_TOKEN ( 'ADJUSTMENT_ID', to_char(p_old_adjust_id) ) ;
3334 FND_MSG_PUB.ADD ;
3335 RETURN;
3336 END ;
3337
3338 /*------------------------------------------------+
3339 | Cache details |
3340 +------------------------------------------------*/
3341
3342 ar_adjvalidate_pvt.Cache_Details (
3343 l_return_status
3344 );
3345 /*------------------------------------------------+
3346 | Check status and return if error |
3347 +------------------------------------------------*/
3348
3349 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
3350 THEN
3351 p_return_status := l_return_status ;
3352 IF PG_DEBUG in ('Y', 'C') THEN
3353 arp_util.debug('Reverse_Adjustment: ' || ' failed to Cache_Details ');
3354 END IF;
3355 END IF;
3356
3357 /*--------------------------------------------+
3358 | Validate the input details. Copy the dates |
3359 | into local variables |
3360 +--------------------------------------------*/
3361
3362 l_reversal_gl_date := p_reversal_gl_date ;
3363 l_reversal_date := p_reversal_date ;
3364
3365 /*------------------------------------------------+
3366 | Validate if the adjustment can be reversed |
3367 +------------------------------------------------*/
3368
3369
3370 ar_adjust_pub.Validate_Adj_Reverse (
3371 l_adj_rec,
3372 l_reversal_gl_date,
3373 l_reversal_date,
3374 l_return_status
3375 );
3376
3377
3378 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
3379 THEN
3380 p_return_status := l_return_status ;
3381 IF PG_DEBUG in ('Y', 'C') THEN
3382 arp_util.debug('Reverse_Adjustment: ' ||
3383 'Validation error(s) occurred. Rolling back '||
3384 'and setting status to ERROR');
3385 END IF;
3386 END IF;
3387
3388 /*-----------------------------------------------+
3389 | Handling all the validation exceptions |
3390 +-----------------------------------------------*/
3391 IF (p_return_status = FND_API.G_RET_STS_ERROR)
3392 THEN
3393 RAISE FND_API.G_EXC_ERROR;
3394 ELSIF (p_return_status = FND_API.G_RET_STS_UNEXP_ERROR)
3395 THEN
3396 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3397 END IF;
3398
3399 /*------------------------------------------------------------+
3403 +------------------------------------------------------------*/
3400 | Reverse the amounts and create a new adj adjustment record.|
3401 | The new adjustment record should have the date and gl_date |
3402 | same as the reversal date and gl_date. |
3404 IF PG_DEBUG in ('Y', 'C') THEN
3405 arp_util.debug('Reverse_Adjustment: ' || 'Preparing the values for the new adjustment');
3406 END IF;
3407
3408 -- setting all the new values for the new adjustment
3409
3410 -- setting all the new values for the new adjustment
3411
3412 BEGIN
3413 Select count(*)
3414 into l_count_chk
3415 from AR_ACTIVITY_DETAILS
3416 where source_id = p_old_adjust_id
3417 and source_table = 'ADJ'
3418 and nvl(CURRENT_ACTIVITY_FLAG,'Y') = 'Y' -- Bug 7241111
3419 and customer_trx_line_id = l_adj_rec.customer_trx_line_id;
3420 EXCEPTION
3421 When others then
3422 l_count_chk := 0;
3423 END;
3424
3425
3426 IF NVL(l_count_chk,0) <> 0
3427 THEN
3428 l_adj_rec.status := NULL;
3429 l_adj_rec.adjustment_id := NULL;
3430 l_adj_rec.apply_date := p_reversal_date ;
3431 l_adj_rec.gl_date := p_reversal_gl_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
3442 l_llca_adj_trx_lines_tbl(1).customer_trx_line_id := l_adj_rec.customer_trx_line_id;
3443 l_llca_adj_trx_lines_tbl(1).line_amount := l_adj_rec.amount;
3444 l_llca_adj_trx_lines_tbl(1).receivables_trx_id := l_adj_rec.receivables_trx_id;
3445 l_adj_rec.customer_trx_line_id := NULL; -- Line level Adjustment does not allow line id at header.
3446 l_adj_rec.receivables_trx_id := NULL; -- Line level Adjustment does not allow line id at header.
3447
3448 ELSE
3449 l_adj_rec.status := NULL;
3450 l_adj_rec.adjustment_id := NULL;
3451 l_adj_rec.apply_date := p_reversal_date ;
3452 l_adj_rec.gl_date := p_reversal_gl_date;
3453 l_adj_rec.amount := -l_adj_rec.amount;
3454 l_adj_rec.acctd_amount := -l_adj_rec.acctd_amount;
3455 l_adj_rec.line_adjusted := -l_adj_rec.line_adjusted;
3456 l_adj_rec.freight_adjusted := -l_adj_rec.freight_adjusted;
3457 l_adj_rec.tax_adjusted := -l_adj_rec.tax_adjusted;
3458 l_adj_rec.receivables_charges_adjusted :=
3459 -l_adj_rec.receivables_charges_adjusted ;
3460 l_adj_rec.created_from := 'REVERSE_ADJUSTMENT';
3461 l_adj_rec.comments := p_comments;
3462 END IF;
3463
3464 --Bug 1449758 - While reversing, null out NOCOPY the gl posting fiedls
3465
3466 l_adj_rec.gl_posted_date := NULL;
3467 l_adj_rec.posting_control_id := -3;
3468
3469 /* Bugfix 2734179. Null out doc_seq columns so that they get
3470 fresh values for the reversed row. */
3471 l_adj_rec.doc_sequence_id := NULL;
3472 l_adj_rec.doc_sequence_value := NULL;
3473
3474 IF PG_DEBUG in ('Y', 'C') THEN
3475 arp_util.debug('Reverse_Adjustment: ' || '--------------------------------------------------');
3476 arp_util.debug('Reverse_Adjustment: ' || 'New values for the new adjustment');
3477 arp_util.debug('Reverse_Adjustment: ' || 'status = ' || l_adj_rec.status );
3478 arp_util.debug('Reverse_Adjustment: ' || 'adjustment_id = ' || l_adj_rec.adjustment_id );
3479 arp_util.debug('Reverse_Adjustment: ' || 'apply_date = ' || l_adj_rec.apply_date );
3480 arp_util.debug('Reverse_Adjustment: ' || 'gl_date = ' || l_adj_rec.gl_date );
3481 arp_util.debug('Reverse_Adjustment: ' || 'amount = ' || l_adj_rec.amount );
3482 arp_util.debug('Reverse_Adjustment: ' || 'acctd_amount = ' || l_adj_rec.acctd_amount );
3483 arp_util.debug('Reverse_Adjustment: ' || 'line_adjusted = ' || l_adj_rec.line_adjusted);
3484 arp_util.debug('Reverse_Adjustment: ' || 'freight_adjusted = ' || l_adj_rec.freight_adjusted );
3485 arp_util.debug('Reverse_Adjustment: ' || 'tax_adjusted = ' || l_adj_rec.tax_adjusted);
3486 arp_util.debug('Reverse_Adjustment: ' || 'receivables_charges_adjusted = ' || l_adj_rec.receivables_charges_adjusted );
3487 arp_util.debug('Reverse_Adjustment: ' || 'created_from = ' || l_adj_rec.created_from );
3488 arp_util.debug('Reverse_Adjustment: ' || 'comments = ' || l_adj_rec.comments);
3489 arp_util.debug('Reverse_Adjustment: ' || '--------------------------------------------------');
3490 END IF;
3491
3492
3493 l_check_amount := FND_API.G_FALSE;
3494
3495 l_chk_approval_limits := p_chk_approval_limits;
3496 IF (l_chk_approval_limits IS NULL) THEN
3497 l_chk_approval_limits := FND_API.G_TRUE;
3498 END IF;
3499
3500 /*--------------------------------------------------------------+
3501 | Call the create adjustment api to insert the new adjustment. |
3502 +--------------------------------------------------------------*/
3503
3504 BEGIN
3505
3506 IF NVL(l_count_chk,0) <> 0
3507 THEN
3508
3509
3510 ar_adjust_pub.create_linelevel_adjustment(
3511 p_api_name => 'AR_ADJUST_PUB',
3512 p_api_version => 1.0,
3513 p_msg_count => l_msg_count ,
3514 p_msg_data => l_msg_data,
3515 p_return_status => l_return_status,
3516 p_adj_rec => l_adj_rec,
3517 p_chk_approval_limits => l_chk_approval_limits,
3518 p_llca_adj_trx_lines_tbl => l_llca_adj_trx_lines_tbl,
3519 p_check_amount => l_check_amount,
3520 p_move_deferred_tax => p_move_deferred_tax,
3521 p_llca_adj_create_tbl_type => l_llca_adj_create_tbl_type,
3522 p_called_from => p_called_from,
3523 p_old_adjust_id => p_old_adjust_id);
3524
3525 IF l_llca_adj_create_tbl_type(1).adjustment_id IS NULL THEN
3526 p_return_status := FND_API.G_RET_STS_ERROR;
3527 ELSE
3528 IF PG_DEBUG in ('Y', 'C') THEN
3529 p_new_adj_id := l_llca_adj_create_tbl_type(1).adjustment_id;
3530 arp_util.debug('Reverse_Adjustment: ' ||
3531 'After Create_Adjustment , new_adjustment_id = ' ||
3532 p_new_adj_id || ' new_adjustment_num = ' || l_llca_adj_create_tbl_type(1).adjustment_number);
3533 END IF;
3534 END IF;
3535
3536 ELSE
3537 ar_adjust_pub.Create_Adjustment(
3538 p_api_name => 'AR_ADJUST_PUB',
3539 p_api_version => 1.0,
3540 p_msg_count => l_msg_count ,
3541 p_msg_data => l_msg_data,
3542 p_return_status => l_return_status,
3543 p_adj_rec => l_adj_rec,
3544 p_chk_approval_limits => l_chk_approval_limits,
3545 p_new_adjust_number => l_new_adj_num,
3546 p_new_adjust_id => p_new_adj_id,
3547 p_check_amount => l_check_amount,
3548 p_move_deferred_tax => p_move_deferred_tax,
3549 p_called_from => p_called_from,
3550 p_old_adjust_id => p_old_adjust_id);
3551
3552
3553
3554 /* Bugfix 2734179. Check if the new adjustment record was created. */
3555 IF p_new_adj_id IS NULL THEN
3556 p_return_status := FND_API.G_RET_STS_ERROR;
3557 ELSE
3558 IF PG_DEBUG in ('Y', 'C') THEN
3559 arp_util.debug('Reverse_Adjustment: ' ||
3560 'After Create_Adjustment , new_adjustment_id = ' ||
3561 p_new_adj_id || ' new_adjustment_num = ' || l_new_adj_num);
3562 END IF;
3563 END IF;
3564 END IF;
3565
3566 EXCEPTION
3567 WHEN OTHERS THEN
3568 /*---------------------------------------------------+
3569 | Rollback to the defined Savepoint |
3570 +---------------------------------------------------*/
3571
3572 ROLLBACK TO ar_adjust_PUB;
3573 p_return_status := FND_API.G_RET_STS_ERROR ;
3574
3575 /*--------------------------------------------------+
3576 | Get message count and if 1, return message data |
3577 +---------------------------------------------------*/
3578
3579 FND_MSG_PUB.Count_And_Get(
3580 p_encoded => FND_API.G_FALSE,
3581 p_count => p_msg_count,
3582 p_data => p_msg_data
3583 );
3584 IF PG_DEBUG in ('Y', 'C') THEN
3585 arp_util.debug('Reverse_Adjustment: ' ||
3586 'Error in Insert Entity handler. Rolling back ' ||
3587 'and setting status to ERROR');
3588 END IF;
3589 if (l_msg_count > 0) then
3590 IF PG_DEBUG in ('Y', 'C') THEN
3591 arp_util.debug('Reverse_Adjustment: ' || l_msg_data);
3592 END IF;
3593 end if;
3594
3595 RETURN;
3596
3597 END ;
3598
3599
3600 /*-------------------------------------------+
3601 | ========== End of API Body ========== |
3602 +-------------------------------------------*/
3603 END IF;
3604
3605 /*---------------------------------------------------+
3606 | Get message count and if 1, return message data |
3607 +---------------------------------------------------*/
3608
3609 FND_MSG_PUB.Count_And_Get(
3610 p_encoded =>FND_API.G_FALSE,
3611 p_count => p_msg_count,
3612 p_data => p_msg_data
3613 );
3614
3615 /*--------------------------------+
3616 | Standard check of p_commit |
3617 +--------------------------------*/
3618
3619 IF FND_API.To_Boolean( p_commit_flag )
3620 THEN
3621 IF PG_DEBUG in ('Y', 'C') THEN
3622 arp_util.debug('Reverse_Adjustment: ' || 'committing');
3623 END IF;
3624 Commit;
3625 END IF;
3626
3630
3627 IF PG_DEBUG in ('Y', 'C') THEN
3628 arp_util.debug('Reverse_Adjustment()- ');
3629 END IF;
3631 IF (FND_MSG_PUB.Check_Msg_Level (G_MSG_LOW)) THEN
3632 select TO_CHAR( (hsecs - G_START_TIME) / 100)
3633 into l_hsec
3634 from v$timer;
3635 IF PG_DEBUG in ('Y', 'C') THEN
3636 arp_util.debug('Reverse_Adjustment: ' || 'Elapsed Time : '||l_hsec||' seconds');
3637 END IF;
3638 END IF;
3639
3640
3641 EXCEPTION
3642 WHEN FND_API.G_EXC_ERROR THEN
3643
3644 IF PG_DEBUG in ('Y', 'C') THEN
3645 arp_util.debug('Reverse_Adjustment: ' || SQLCODE);
3646 arp_util.debug('Reverse_Adjustment: ' || SQLERRM);
3647 END IF;
3648
3649 ROLLBACK TO ar_adjust_PUB;
3650 p_return_status := FND_API.G_RET_STS_ERROR ;
3651 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
3652 p_count => p_msg_count,
3653 p_data => p_msg_data
3654 );
3655
3656 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3657
3658 IF PG_DEBUG in ('Y', 'C') THEN
3659 arp_util.debug('Reverse_Adjustment: ' || SQLERRM);
3660 END IF;
3661 ROLLBACK TO ar_adjust_PUB ;
3662 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
3663 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
3664 p_count => p_msg_count,
3665 p_data => p_msg_data
3666 );
3667
3668 WHEN OTHERS THEN
3669
3670 /*-------------------------------------------------------+
3671 | Handle application errors that result from trapable |
3672 | error conditions. The error messages have already |
3673 | been put on the error stack. |
3674 +-------------------------------------------------------*/
3675
3676 IF (SQLCODE = -20001)
3677 THEN
3678 p_return_status := FND_API.G_RET_STS_ERROR ;
3679 ROLLBACK TO ar_adjust_PUB;
3680 IF PG_DEBUG in ('Y', 'C') THEN
3681 arp_util.debug('Reverse_Adjustment: ' ||
3682 'Completion validation error(s) occurred. ' ||
3683 'Rolling back and setting status to ERROR');
3684 END IF;
3685
3686 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
3687 p_count => p_msg_count,
3688 p_data => p_msg_data
3689 );
3690 RETURN;
3691 ELSE
3692 NULL;
3693 END IF;
3694
3695 arp_util.disable_debug;
3696
3697 END Reverse_Adjustment;
3698
3699
3700 /*===========================================================================+
3701 | PROCEDURE |
3702 | Approve_Adjustment |
3703 | |
3704 | DESCRIPTION |
3705 | This is the main routine that approves an adjustment |
3706 | |
3707 | SCOPE - PUBLIC |
3708 | |
3709 | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED |
3710 | fnd_api.compatible_api_call |
3711 | fnd_api.g_exc_unexpected_error |
3712 | fnd_api.g_ret_sts_error |
3713 | fnd_api.g_ret_sts_error |
3714 | fnd_api.g_ret_sts_success |
3715 | fnd_api.to_boolean |
3716 | fnd_msg_pub.check_msg_level |
3717 | fnd_msg_pub.count_and_get |
3718 | fnd_msg_pub.initialize |
3719 | ar_adjustments_pkg.fetch_p |
3720 | ar_process_adjustment.update_approve_adjustment |
3721 | |
3722 | ARGUMENTS : IN: |
3723 | p_api_name |
3724 | p_api_version |
3725 | p_init_msg_list |
3726 | p_commit_flag |
3727 | p_validation_level |
3728 | p_adj_rec |
3729 | p_chk_approval_limits |
3730 | p_old_adjust_id |
3731 | OUT: |
3732 | p_return_status |
3733 | p_msg_count |
3734 | p_msg_data |
3735 | |
3736 | IN/ OUT: |
3740 | |
3737 | |
3738 | |
3739 | RETURNS : NONE |
3741 | NOTES |
3742 | |
3743 | MODIFICATION HISTORY |
3744 | Vivek Halder 30-JAN-97 Created |
3745 | |
3746 | Saloni Shah 03-FEB-00 Changes have been made for the BR/BOE project|
3747 | One new parameter has been added: |
3748 | - p_chk_approval_limits. |
3749 | This parameter will be passed to |
3750 | Validate_Adj_Approve procedure. |
3751 | If the value of the flag p_chk_approval_limit|
3752 | is set to 'F' then the adjusted amount will |
3753 | not be validated against the users approval |
3754 | limits. |
3755 | Satheesh Nambiar 17-May-00 Added one more parameter p_move_deferred_tax|
3756 | for BOE/BR
3757 | |
3758 +===========================================================================*/
3759
3760 PROCEDURE Approve_Adjustment (
3761 p_api_name IN varchar2,
3762 p_api_version IN number,
3763 p_init_msg_list IN varchar2 := FND_API.G_FALSE,
3764 p_commit_flag IN varchar2 := FND_API.G_FALSE,
3765 p_validation_level IN number := FND_API.G_VALID_LEVEL_FULL,
3766 p_msg_count OUT NOCOPY number,
3767 p_msg_data OUT NOCOPY varchar2,
3768 p_return_status OUT NOCOPY varchar2 ,
3769 p_adj_rec IN ar_adjustments%rowtype,
3770 p_chk_approval_limits IN varchar2 := FND_API.G_TRUE,
3771 p_move_deferred_tax IN varchar2,
3772 p_old_adjust_id IN ar_adjustments.adjustment_id%type,
3773 p_org_id IN NUMBER DEFAULT NULL
3774 ) IS
3775
3776 l_api_name CONSTANT VARCHAR2(20) := 'AR_ADJUST_PUB';
3777 l_api_version CONSTANT NUMBER := 1.0;
3778 l_old_adj_rec ar_adjustments%rowtype;
3779
3780 l_inp_adj_rec ar_adjustments%rowtype;
3781 l_hsec VARCHAR2(10);
3782 l_status number;
3783
3784 l_return_status varchar2(1) := FND_API.G_RET_STS_SUCCESS;
3785 l_chk_approval_limits varchar2(1);
3786 l_org_return_status VARCHAR2(1);
3787 l_org_id NUMBER;
3788
3789
3790 BEGIN
3791 IF (FND_MSG_PUB.Check_Msg_Level (G_MSG_LOW)) THEN
3792 select hsecs
3793 into G_START_TIME
3794 from v$timer;
3795 END IF;
3796
3797 /*------------------------------------+
3798 | Standard start of API savepoint |
3799 +------------------------------------*/
3800
3801 SAVEPOINT ar_adjust_PUB;
3802
3803 /*--------------------------------------------------+
3804 | Standard call to check for call compatibility |
3805 +--------------------------------------------------*/
3806
3807 IF NOT FND_API.Compatible_API_Call(
3808 l_api_version,
3809 p_api_version,
3810 l_api_name,
3811 G_PKG_NAME
3812 )
3813 THEN
3814 IF PG_DEBUG in ('Y', 'C') THEN
3815 arp_util.debug('Approve_Adjustment: ' || 'Compatility error occurred.');
3816 END IF;
3817 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3818 END IF;
3819
3820 /*-------------------------------------------------------------+
3821 | Initialize message list if p_init_msg_list is set to TRUE |
3822 +-------------------------------------------------------------*/
3823
3824 IF FND_API.to_Boolean( p_init_msg_list )
3825 THEN
3826 FND_MSG_PUB.initialize;
3827 END IF;
3828
3829 -- arp_util.enable_debug(100000);
3830
3831
3832 IF PG_DEBUG in ('Y', 'C') THEN
3833 arp_util.debug('Approve_Adjustment()+ ');
3834 END IF;
3835
3836 /*-----------------------------------------+
3837 | Initialize return status to SUCCESS |
3838 +-----------------------------------------*/
3839
3840 p_return_status := FND_API.G_RET_STS_SUCCESS;
3841
3842
3843
3844
3845
3846 /* SSA change */
3847 l_org_id := p_org_id;
3848 l_org_return_status := FND_API.G_RET_STS_SUCCESS;
3849 ar_mo_cache_utils.set_org_context_in_api(p_org_id =>l_org_id,
3850 p_return_status =>l_org_return_status);
3851 IF l_org_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3852 p_return_status := FND_API.G_RET_STS_ERROR;
3853 ELSE
3854
3855
3856 /*---------------------------------------------+
3857 | ========== Start of API Body ========== |
3858 +---------------------------------------------*/
3859
3860
3861 /*---------------------------------------------+
3862 | Copy the input record to local variable to |
3863 | allow changes to it |
3864 +---------------------------------------------*/
3865 l_inp_adj_rec := p_adj_rec ;
3866
3867
3871
3868 /*------------------------------------------------+
3869 | Initialize the profile options and cache data |
3870 +------------------------------------------------*/
3872 ar_adjvalidate_pvt.Init_Context_Rec (
3873 p_validation_level,
3874 l_return_status
3875 );
3876 /*------------------------------------------------+
3877 | Check status and return if error |
3878 +------------------------------------------------*/
3879
3880 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
3881 THEN
3882 p_return_status := l_return_status ;
3883 IF PG_DEBUG in ('Y', 'C') THEN
3884 arp_util.debug('Approve_Adjustment: ' || 'failed to Initialize the profile options ');
3885 END IF;
3886 END IF;
3887
3888 /*------------------------------------------------+
3889 | Cache details |
3890 +------------------------------------------------*/
3891
3892 ar_adjvalidate_pvt.Cache_Details (
3893 l_return_status
3894 );
3895 /*------------------------------------------------+
3896 | Check status and return if error |
3897 +------------------------------------------------*/
3898
3899 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
3900 THEN
3901 p_return_status := l_return_status ;
3902 IF PG_DEBUG in ('Y', 'C') THEN
3903 arp_util.debug('Approve_Adjustment: ' || 'failed to Initialize the profile options ');
3904 END IF;
3905 END IF;
3906
3907 /*------------------------------------------------+
3908 | Fetch details of the old adjustment record |
3909 +------------------------------------------------*/
3910 BEGIN
3911
3912 arp_adjustments_pkg.fetch_p (
3913 l_old_adj_rec,
3914 p_old_adjust_id
3915 );
3916
3917 EXCEPTION
3918 WHEN OTHERS THEN
3919 /*---------------------------------------------------+
3920 | Rollback to the defined Savepoint |
3921 +---------------------------------------------------*/
3922
3923 ROLLBACK TO ar_adjust_PUB;
3924
3925 p_return_status := FND_API.G_RET_STS_ERROR ;
3926
3927 FND_MESSAGE.SET_NAME ('AR', 'AR_AAPI_INVALID_ADJ_ID');
3928 FND_MESSAGE.SET_TOKEN ( 'ADJUSTMENT_ID', to_char(p_old_adjust_id) ) ;
3929 FND_MSG_PUB.ADD ;
3930 RETURN;
3931 END ;
3932
3933 /*------------------------------------------+
3934 | Validate the input details |
3935 | Do not continue if there are errors. |
3936 +------------------------------------------*/
3937
3938 /*--------------------------------------------------+
3939 | Change for the BOE/BR project has been made |
3940 | parameter p_chk_approval_limits is being passed. |
3941 +--------------------------------------------------*/
3942
3943 l_chk_approval_limits := p_chk_approval_limits;
3944 IF (l_chk_approval_limits IS NULL) THEN
3945 l_chk_approval_limits := FND_API.G_TRUE;
3946 END IF;
3947
3948 ar_adjust_pub.Validate_Adj_Approve (
3949 l_inp_adj_rec,
3950 l_old_adj_rec,
3951 l_chk_approval_limits,
3952 l_return_status
3953 );
3954
3955
3956 IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS )
3957 THEN
3958
3959 p_return_status := l_return_status ;
3960 IF PG_DEBUG in ('Y', 'C') THEN
3961 arp_util.debug('Approve_Adjustment: ' ||
3962 'Validation error(s) occurred. Rolling back ' ||
3963 'and setting status to ERROR');
3964 END IF;
3965 END IF;
3966
3967 /*-----------------------------------------------+
3968 | Handling all the validation exceptions |
3969 +-----------------------------------------------*/
3970 IF (p_return_status = FND_API.G_RET_STS_ERROR)
3971 THEN
3972 RAISE FND_API.G_EXC_ERROR;
3973 ELSIF (p_return_status = FND_API.G_RET_STS_UNEXP_ERROR)
3974 THEN
3975 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3976 END IF;
3977
3978 /*-----------------------------------------------+
3979 | Call the entity Handler for Approve |
3980 +-----------------------------------------------*/
3981 BEGIN
3982 /*-------------------------------------------------------+
3983 | Change for the BOE/BR project has been made parameter |
3984 | p_chk_approval_limits is being passed to the entity |
3985 | handler to indicate that check the amount_adjusted |
3986 | with the user approval limits only if |
3987 | p_chk_approval_limit flag is set to 'T'. |
3988 +-------------------------------------------------------*/
3989 arp_process_adjustment.update_approve_adj (
3990 'DUMMY',
3991 '1',
3992 l_inp_adj_rec,
3993 l_inp_adj_rec.status,
3994 p_old_adjust_id ,
3995 p_chk_approval_limits,
3996 p_move_deferred_tax
3997 ) ;
3998
3999 EXCEPTION
4003 +---------------------------------------------------*/
4000 WHEN OTHERS THEN
4001 /*---------------------------------------------------+
4002 | Rollback to the defined Savepoint |
4004
4005 ROLLBACK TO ar_adjust_PUB;
4006
4007 p_return_status := FND_API.G_RET_STS_ERROR ;
4008
4009 FND_MESSAGE.set_name( 'AR', 'GENERIC_MESSAGE' );
4010 FND_MESSAGE.set_token( 'GENERIC_TEXT', 'arp_process_adjustment.update_approve_adj exception: '||SQLERRM );
4011 --2920926
4012 FND_MSG_PUB.ADD;
4013 /*--------------------------------------------------+
4014 | Get message count and if 1, return message data |
4015 +---------------------------------------------------*/
4016
4017 FND_MSG_PUB.Count_And_Get(
4018 p_encoded => FND_API.G_FALSE,
4019 p_count => p_msg_count,
4020 p_data => p_msg_data
4021 );
4022
4023 IF PG_DEBUG in ('Y', 'C') THEN
4024 arp_util.debug('Approve_Adjustment: ' ||
4025 'Error in Insert Entity handler. Rolling back ' ||
4026 'and setting status to ERROR');
4027 END IF;
4028
4029 RETURN;
4030
4031 END ;
4032
4033
4034 /*-------------------------------------------+
4035 | ========== End of API Body ========== |
4036 +-------------------------------------------*/
4037 END IF;
4038
4039 /*---------------------------------------------------+
4040 | Get message count and if 1, return message data |
4041 +---------------------------------------------------*/
4042
4043 FND_MSG_PUB.Count_And_Get(
4044 p_encoded => FND_API.G_FALSE,
4045 p_count => p_msg_count,
4046 p_data => p_msg_data
4047 );
4048
4049 /*--------------------------------+
4050 | Standard check of p_commit |
4051 +--------------------------------*/
4052
4053 IF FND_API.To_Boolean( p_commit_flag )
4054 THEN
4055 IF PG_DEBUG in ('Y', 'C') THEN
4056 arp_util.debug('Approve_Adjustment: ' || 'committing');
4057 END IF;
4058 Commit;
4059 END IF;
4060
4061 IF PG_DEBUG in ('Y', 'C') THEN
4062 arp_util.debug('Approve_Adjustment()- ');
4063 END IF;
4064
4065 IF (FND_MSG_PUB.Check_Msg_Level (G_MSG_LOW)) THEN
4066 select TO_CHAR( (hsecs - G_START_TIME) / 100)
4067 into l_hsec
4068 from v$timer;
4069 IF PG_DEBUG in ('Y', 'C') THEN
4070 arp_util.debug('Approve_Adjustment: ' || 'Elapsed Time : '||l_hsec||' seconds');
4071 END IF;
4072 END IF;
4073
4074
4075 EXCEPTION
4076 WHEN FND_API.G_EXC_ERROR THEN
4077
4078 IF PG_DEBUG in ('Y', 'C') THEN
4079 arp_util.debug('Approve_Adjustment: ' || SQLCODE);
4080 arp_util.debug('Approve_Adjustment: ' || SQLERRM);
4081 END IF;
4082
4083 ROLLBACK TO ar_adjust_PUB;
4084 p_return_status := FND_API.G_RET_STS_ERROR ;
4085 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
4086 p_count => p_msg_count,
4087 p_data => p_msg_data
4088 );
4089
4090 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4091
4092 IF PG_DEBUG in ('Y', 'C') THEN
4093 arp_util.debug('Approve_Adjustment: ' || SQLERRM);
4094 END IF;
4095 ROLLBACK TO ar_adjust_PUB ;
4096 p_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4097 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
4098 p_count => p_msg_count,
4099 p_data => p_msg_data
4100 );
4101
4102 WHEN OTHERS THEN
4103
4104 /*-------------------------------------------------------+
4105 | Handle application errors that result from trapable |
4106 | error conditions. The error messages have already |
4107 | been put on the error stack. |
4108 +-------------------------------------------------------*/
4109
4110 IF (SQLCODE = -20001)
4111 THEN
4112 p_return_status := FND_API.G_RET_STS_ERROR ;
4113 ROLLBACK TO ar_adjust_PUB;
4114 IF PG_DEBUG in ('Y', 'C') THEN
4115 arp_util.debug('Approve_Adjustment: ' ||
4116 'Completion validation error(s) occurred. ' ||
4117 'Rolling back and setting status to ERROR');
4118 END IF;
4119
4120 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
4121 p_count => p_msg_count,
4122 p_data => p_msg_data
4123 );
4124 RETURN;
4125 ELSE
4126 NULL;
4127 END IF;
4128
4129 arp_util.disable_debug;
4130
4131 END Approve_Adjustment;
4132
4133
4134 END ar_adjust_PUB;