[Home] [Help]
PACKAGE BODY: APPS.OTA_TFH_API_BUSINESS_RULES
Source
1 Package Body ota_tfh_api_business_rules as
2 /* $Header: ottfh02t.pkb 120.2 2006/02/13 01:51:18 sbhullar noship $ */
3 --
4 --
5 -- Global package name
6 --
7 g_package varchar2(33) := ' ota_tfh_api_business_rules.';
8 --
9 -- Global api dml status
10 --
11 -- ----------------------------------------------------------------------------
12 -- |-------------------------------< check_type >-----------------------------|
13 -- ----------------------------------------------------------------------------
14 --
15 -- Description:
16 -- The attributee 'TYPE' must be in the domain of 'Finance Header Type'.
17 --
18 Procedure check_type
19 (
20 p_type in varchar2
21 ) Is
22 --
23 v_proc varchar2(72) := g_package||'check_type';
24 --
25 Begin
26 --
27 hr_utility.set_location('Entering:'||v_proc, 5);
28 --
29 If p_type is not null Then
30 --
31 ota_general.check_domain_value( 'FINANCE_HEADER_TYPE', p_type);
32 --
33 Else
34 -- column is a not null field **** change message later
35 --
36 ota_tfh_api_shd.constraint_error( 'OTA_TFH_TYPE_CHK');
37 --
38 End If;
39 --
40 hr_utility.set_location(' Leaving:'||v_proc, 10);
41 --
42 End check_type;
43 --
44 -- ----------------------------------------------------------------------------
45 -- |-----------------------< check_transfer_status >--------------------------|
46 -- ----------------------------------------------------------------------------
47 --
48 -- PUBLIC
49 -- Description:
50 -- The attribute 'Transfer Status' must be in the domain of
51 -- 'GL Transfer Status'.
52 --
53 Procedure check_transfer_status
54 (
55 p_transfer_status in varchar2
56 ) is
57 --
58 v_proc varchar2(72) := g_package||'check_transfer_status';
59 --
60 Begin
61 --
62 hr_utility.set_location('Entering:'|| v_proc, 5);
63 --
64 If p_transfer_status is not null Then
65 --
66 ota_general.check_domain_value( 'GL_TRANSFER_STATUS', p_transfer_status);
67 --
68 Else
69 --
70 ota_tfh_api_shd.constraint_error( 'OTA_TFH_TRANSFER_STATUS_CHK');
71 --
72 End If;
73 --
74 --
75 hr_utility.set_location(' Leaving:'|| v_proc, 10);
76 --
77 End check_transfer_status;
78 --
79 -- ----------------------------------------------------------------------------
80 -- |------------------------< check_transfer_rules >-------------------------|
81 -- ----------------------------------------------------------------------------
82 --
83 -- PUBLIC
84 -- Description:
85 -- The following changes to Transfer Status are allowed
86 -- NT -> AT
87 -- AT -> NT
88 -- UT -> NT
89 -- UT -> AT
90 -- When such a change takes place all the lines for the header that
91 -- have the same Transfer Status should also be changed.
92 --
93 -- In addition the following changes are allowed on headers
94 -- AT -> UT
95 -- AT -> ST
96 -- ST -> UT
97 --
98 Procedure check_transfer_rules
99 (
100 p_new_transfer_status in varchar2
101 ,p_old_transfer_status in varchar2
102 ) is
103 --
104 v_proc varchar2(72) := g_package||'check_transfer_rules';
105 --
106 Begin
107 --
108 hr_utility.set_location('Entering:'|| v_proc, 5);
109 --
110 if p_new_transfer_status <> p_old_transfer_status and
111 ((p_old_transfer_status = 'NT' and p_new_transfer_status = 'AT')
112 or (p_old_transfer_status = 'AT' and p_new_transfer_status = 'NT')
113 or (p_old_transfer_status = 'UT' and p_new_transfer_status = 'NT')
114 or (p_old_transfer_status = 'UT' and p_new_transfer_status = 'AT')
115 or (p_old_transfer_status = 'AT' and p_new_transfer_status = 'UT')
116 or (p_old_transfer_status = 'ST' and p_new_transfer_status = 'UT')
117 or (p_old_transfer_status = 'AT' and p_new_transfer_status = 'ST'))
118 then null;
119 else
120 fnd_message.set_name('OTA','OTA_13414_TFH_TRANS_RULES');
121 fnd_message.raise_error;
122 end if;
123 --
124 hr_utility.set_location(' Leaving:'|| v_proc, 10);
125 --
126 End check_transfer_rules;
127 --
128 -- ----------------------------------------------------------------------------
129 -- |--------------------< check_status_unauthorized >-------------------------|
130 -- ----------------------------------------------------------------------------
131 --
132 -- PUBLIC
133 -- Description:
134 -- The transfer status must be 'NT' if the header is not authorised,
135 -- ie: the authorised_by_person_id is null.
136 --
137 Procedure check_status_unauthorized
138 (
139 p_status in varchar2
140 ,p_authorized_person_id in number
141 ) is
142 --
143 v_proc varchar2(72) := g_package||'check_status_unauthorized';
144 --
145 Begin
146 hr_utility.set_location('Entering:'|| v_proc, 5);
147 --
148 If p_authorized_person_id is null Then
149 If p_status <> 'NT' Then
150 fnd_message.set_name('OTA','OTA_13280_TFH_UNAUTHORIZED');
151 fnd_message.raise_error;
152 End if;
153 End If;
154 --
155 hr_utility.set_location(' Leaving:'|| v_proc, 10);
156 End check_status_unauthorized;
157 --
158 -- ----------------------------------------------------------------------------
159 -- |-------------------------< check_authorized_by >--------------------------|
160 -- ----------------------------------------------------------------------------
161 --
162 -- PUBLIC
163 -- Description:
164 -- The authorised_by attribute must be a valid FND_USER
165 --
166 Procedure check_authorized_by
167 (
168 p_person_id in number
169 ) is
170 --
171 v_proc varchar2(72) := g_package||'check_authorized_by';
172 --
173 Begin
174 hr_utility.set_location('Entering:'|| v_proc, 5);
175 --
176 If p_person_id is not null Then
177 If NOT ota_general.check_fnd_user( p_person_id) Then
178 fnd_message.set_name('OTA','OTA_13281_TFH_AUTHORIZER');
179 fnd_message.raise_error;
180 End if;
181 End if;
182 --
183 hr_utility.set_location(' Leaving:'|| v_proc, 10);
184 End check_authorized_by;
185 --
186 -- ----------------------------------------------------------------------------
187 -- |-------------------------< set_date_raised >------------------------------|
188 -- ----------------------------------------------------------------------------
189 --
190 -- PUBLIC
191 -- Description:
192 -- The date_raised attribute must be set to the session date upon
193 -- creation. This attribute may not be updated.
194 --
195 Procedure set_date_raised
196 (
197 p_date_raised out nocopy date
198 ,p_session_date in date
199 ) is
200 --
201 v_proc varchar2(72) := g_package||'set_date_raised';
202 --
203 Begin
204 hr_utility.set_location('Entering:'|| v_proc, 5);
205 --
206 If p_session_date is null Then
207 fnd_message.set_name('OTA','OTA_13313_TFH_DATE_RAISED');
208 fnd_message.raise_error;
209 Else
210 p_date_raised := p_session_date;
211 End If;
212 --
213 hr_utility.set_location(' Leaving:'|| v_proc, 10);
214 End set_date_raised;
215 --
216 -- ----------------------------------------------------------------------------
217 -- |--------------------< check_receivable_attributes >-----------------------|
218 -- ----------------------------------------------------------------------------
219 --
220 -- PUBLIC
221 -- Description:
222 -- If the header is of type 'Receivable' then the following
223 -- attributes must be NOT NULL:
224 -- CUSTOMER_CONTACT_ID
225 -- CUSTOMER_ADDRESS_ID
226 -- CUSTOMER_ID
227 -- INVOICE_ADDRESS
228 -- INVOICE_CONTACT
229 -- RECEIVABLE_TYPE
230 -- The following attributes must be NULL:
231 -- VENDOR_ID
232 -- VENDOR_CONTACT_ID
233 -- VENDOR_ADDRESS_ID
234 --
235 --
236 Procedure check_receivable_attributes
237 (
238 p_type in varchar2
239 ,p_customer_id in number
240 ,p_customer_contact_id in number
241 ,p_customer_address_id in number
242 ,p_invoice_address in varchar2
243 ,p_invoice_contact in varchar2
244 ,p_vendor_id in number
245 ,p_vendor_contact_id in number
246 ,p_vendor_address_id in number
247 ,p_receivable_type in varchar2
248 ) is
249 --
250 v_proc varchar2(72) := g_package||'check_receivable_attributes';
251 --
252 Begin
253 --
254 hr_utility.set_location('Entering:'|| v_proc, 5);
255 --
256 If p_type = 'R' Then
257 --
258 If p_customer_id is null OR
259 p_customer_contact_id is null OR
260 p_customer_address_id is null OR
261 p_invoice_address is null OR
262 p_invoice_contact is null OR
263 p_receivable_type is null OR
264 p_vendor_id is NOT null OR
265 p_vendor_contact_id is NOT null OR
266 p_vendor_address_id is NOT null Then
267 --
268 ota_tfh_api_shd.constraint_error( 'OTA_TFH_RECEIVABLE_ATTRIBUTES');
269 --
270 End if;
271 --
272 End If;
273 --
274 hr_utility.set_location(' Leaving:'|| v_proc, 10);
275 --
276 End check_receivable_attributes;
277 --
278 -- ----------------------------------------------------------------------------
279 -- |----------------------< check_customer_contact >--------------------------|
280 -- ----------------------------------------------------------------------------
281 --
282 -- PUBLIC
283 -- Description:
284 -- The customer_contact_id must be for the same customer as defined on the
285 -- header in the attribute customer_id, if the header is receivable .
286 --
287 Procedure check_customer_contact
288 (
289 p_customer_id in number
290 ,p_contact_id in number
291 ) is
292 --
293 v_exists varchar2(1);
294 v_proc varchar2(72) := g_package||'check_customer_contact';
295 --
296 cursor sel_customer_contact is
297 select 'Y'
298 from ota_customer_contacts_v con
299 where con.customer_id = p_customer_id
300 and con.contact_id = p_contact_id;
301 --
302 Begin
303 hr_utility.set_location('Entering:'|| v_proc, 5);
304 --
305 If p_contact_id is NOT null AND p_customer_id is NOT null Then
306 Open sel_customer_contact;
307 fetch sel_customer_contact into v_exists;
308 --
309 if sel_customer_contact%notfound then
310 close sel_customer_contact;
311 fnd_message.set_name('OTA','OTA_13283_TFH_CUSTOMER_CONTACT');
312 fnd_message.raise_error;
313 end if;
314 --
315 close sel_customer_contact;
316 End if;
317 --
318 hr_utility.set_location(' Leaving:'|| v_proc, 10);
319 End check_customer_contact;
320 --
321 -- ----------------------------------------------------------------------------
322 -- |-----------------------< check_customer_address >-------------------------|
323 -- ----------------------------------------------------------------------------
324 --
325 -- PUBLIC
326 -- Description:
327 -- The customer_address_id must be for the same customer as defined
328 -- on the header in the attribute customer_id, if the header is receivable.
329 --
330 Procedure check_customer_address
331 (
332 p_customer_id in number
333 ,p_address_id in number
334 ) is
335 --
336 v_exists varchar2(1);
337 v_proc varchar2(72) := g_package||'check_customer_address';
338 --
339 cursor sel_customer_address is
340 select 'Y'
341 from ota_customer_addresses_v adr
342 where adr.customer_id = p_customer_id
343 and adr.address_id = p_address_id;
344 --
345 Begin
346 hr_utility.set_location('Entering:'|| v_proc, 5);
347 --
348 If p_address_id is NOT null AND p_customer_id is NOT null Then
349 Open sel_customer_address;
350 fetch sel_customer_address into v_exists;
351 --
352 if sel_customer_address%notfound then
353 close sel_customer_address;
354 fnd_message.set_name('OTA','OTA_13284_TFH_CUSTOMER_ADDRESS');
355 fnd_message.raise_error;
356 end if;
357 --
358 close sel_customer_address;
359 End if;
360 --
361 hr_utility.set_location(' Leaving:'|| v_proc, 10);
362 End check_customer_address;
363 --
364 -- ----------------------------------------------------------------------------
365 -- |------------------------< set_invoice_address >---------------------------|
366 -- ----------------------------------------------------------------------------
367 --
368 -- PUBLIC
369 -- Description:
370 -- Upon insert of a receivable header the address attributes must be
371 -- concatenated together in the invoice_address attribute. This must
372 -- be reset if the customer_address_id is changed. This changed must
373 -- then obey the change rules defined in the business rules. If the
374 -- header has been transfered, then a cancel and recreate would have
375 -- to be performed.
376 --
377 Procedure set_invoice_address
378 (
379 p_customer_id in number
380 ,p_address_id in number
381 ,p_invoice_address out nocopy varchar2
382 ) is
383 --
384 v_address varchar2(2000);
385 v_proc varchar2(72) := g_package||'set_invoice_address';
386 --
387 cursor sel_invoice_address is
388 select adr.address
389 from ota_customer_addresses_v adr
390 where adr.customer_id = p_customer_id
391 and adr.address_id = p_address_id;
392 --
393 Begin
394 hr_utility.set_location('Entering:'|| v_proc, 5);
395 --
396 If p_address_id is NOT null AND p_customer_id is NOT null Then
397 Open sel_invoice_address;
398 fetch sel_invoice_address into v_address;
399 --
400 if sel_invoice_address%notfound then
401 close sel_invoice_address;
402 fnd_message.set_name('OTA','OTA_13284_TFH_CUSTOMER_ADDRESS');
403 fnd_message.raise_error;
404 end if;
405 --
406 p_invoice_address := v_address;
407 --
408 close sel_invoice_address;
409 End if;
410 --
411 hr_utility.set_location(' Leaving:'|| v_proc, 10);
412 End set_invoice_address;
413 --
414 -- ----------------------------------------------------------------------------
415 -- |------------------------< set_invoice_contact >---------------------------|
416 -- ----------------------------------------------------------------------------
417 --
418 -- PUBLIC
419 -- Description:
420 --
421 Procedure set_invoice_contact
422 (
423 p_customer_id in number
424 ,p_contact_id in number
425 ,p_invoice_contact out nocopy varchar2
426 ) is
427 --
428 v_contact varchar2(2000);
429 v_proc varchar2(72) := g_package||'set_invoice_contact';
430 --
431 cursor sel_invoice_contact is
432 select con.full_name
433 from ota_customer_contacts_v con
434 where con.customer_id = p_customer_id
435 and con.contact_id = p_contact_id;
436 --
437 Begin
438 hr_utility.set_location('Entering:'|| v_proc, 5);
439 --
440 If p_contact_id is NOT null AND p_customer_id is NOT null Then
441 Open sel_invoice_contact;
442 fetch sel_invoice_contact into v_contact;
443 --
444 if sel_invoice_contact%notfound then
445 close sel_invoice_contact;
446 fnd_message.set_name('OTA','OTA_13283_TFH_CUSTOMER_CONTACT');
447 fnd_message.raise_error;
448 end if;
449 --
450 p_invoice_contact := v_contact;
451 --
452 close sel_invoice_contact;
453 End if;
454 --
455 hr_utility.set_location(' Leaving:'|| v_proc, 10);
456 End set_invoice_contact;
457 --
458 -- ----------------------------------------------------------------------------
459 -- |-----------------------< check_vendor_contact >---------------------------|
460 -- ----------------------------------------------------------------------------
461 --
462 -- PUBLIC
463 -- Description:
464 -- The vendor_contact must be a valid contact for the vendor defined in
465 -- vendor_id on the header, if the header is 'Payable'.
466 --
467 Procedure check_vendor_contact
468 (
469 p_vendor_id in number
470 ,p_contact_id in number
471 ) is
472 --
473 v_exists varchar2(1);
474 v_proc varchar2(72) := g_package||'check_vendor_contact';
475 --
476 --Bug 4924448
477 cursor sel_vendor_contact is
478 select 'Y'
479 from AP_SUPPLIERS PAV,
480 HZ_PARTIES HP,
481 AP_SUPPLIER_CONTACTS PVC
482 where PAV.vendor_id = p_vendor_id
483 and PVC.VENDOR_CONTACT_ID = p_contact_id
484 and PAV.PARTY_ID = HP.PARTY_ID;
485
486 --
487 Begin
488 hr_utility.set_location('Entering:'|| v_proc, 5);
489 --
490 If p_contact_id is NOT null AND p_vendor_id is NOT null Then
491 Open sel_vendor_contact;
492 fetch sel_vendor_contact into v_exists;
493 --
494 if sel_vendor_contact%notfound then
495 close sel_vendor_contact;
496 fnd_message.set_name('OTA','OTA_13285_TFH_VENDOR_CONTACT');
497 fnd_message.raise_error;
498 end if;
499 --
500 close sel_vendor_contact;
501 End if;
502 --
503 hr_utility.set_location(' Leaving:'|| v_proc, 10);
504 End check_vendor_contact;
505 --
506 -- ----------------------------------------------------------------------------
507 -- |-------------------------< check_vendor_address >-------------------------|
508 -- ----------------------------------------------------------------------------
509 --
510 -- PUBLIC
511 -- Description:
512 -- The vendor_address must be a valid address for the vendor defined
513 -- in VENDOR_ID on the header.
514 --
515 Procedure check_vendor_address
516 (
517 p_vendor_id in number
518 ,p_address_id in number
519 ) is
520 --
521 v_exists varchar2(1);
522 v_proc varchar2(72) := g_package||'check_vendor_address';
523 --
524 cursor sel_vendor_address is
525 select 'Y'
526 from ota_vendor_addresses_v adr
527 where adr.vendor_id = p_vendor_id
528 and adr.vendor_site_id = p_address_id;
529 --
530 Begin
531 hr_utility.set_location('Entering:'|| v_proc, 5);
532 --
533 If p_address_id is NOT null AND p_vendor_id is NOT null Then
534 Open sel_vendor_address;
535 fetch sel_vendor_address into v_exists;
536 --
537 if sel_vendor_address%notfound then
538 close sel_vendor_address;
539 fnd_message.set_name('OTA','OTA_13286_TFH_VENDOR_ADDRESS');
540 fnd_message.raise_error;
541 end if;
542 --
543 close sel_vendor_address;
544 End if;
545 --
546 hr_utility.set_location(' Leaving:'|| v_proc, 10);
547 End check_vendor_address;
548 --
549 -- ----------------------------------------------------------------------------
550 -- |-----------------------< check_payable_attributes >-----------------------|
551 -- ----------------------------------------------------------------------------
552 --
553 -- PUBLIC
554 -- Description:
555 -- If the header is of type 'Payable' then the following
556 -- attributes must be NOT NULL:
557 -- VENDOR_CONTACT_ID
558 -- VENDOR_ADDRESS_ID
559 -- VENDOR_ID
560 -- The following attributes must be NULL:
561 -- CUSTOMER_CONTACT_ID
562 -- CUSTOMER_ADDRESS_ID
563 -- CUSTOMER_ID
564 -- RECEIVABLE_TYPE
565 --
566 --
567 Procedure check_payable_attributes
568 (
569 p_type in varchar2
570 ,p_vendor_id in number
571 ,p_vendor_contact_id in number
572 ,p_vendor_address_id in number
573 ,p_invoice_contact in varchar2
574 ,p_invoice_address in varchar2
575 ,p_customer_id in number
576 ,p_customer_contact_id in number
577 ,p_customer_address_id in number
578 ,p_receivable_type in varchar2
579 ) is
580 --
581 v_proc varchar2(72) := g_package||'check_payable_attributes';
582 --
583 Begin
584 --
585 hr_utility.set_location('Entering:'|| v_proc, 5);
586 --
587 If p_type like 'P' Then
588 --
589 If p_vendor_id is null OR
590 p_vendor_contact_id is null OR
591 p_vendor_address_id is null OR
592 p_receivable_type is NOT null OR
593 p_customer_id is NOT null OR
594 p_customer_contact_id is NOT null OR
595 p_customer_address_id is NOT null Then
596 --
597 ota_tfh_api_shd.constraint_error( 'OTA_TFH_PAYABLE_ATTRIBUTES');
598 --
599 End if;
600 --
601 End If;
602 --
603 hr_utility.set_location(' Leaving:'|| v_proc, 10);
604 --
605 End check_payable_attributes;
606 --
607 -- ----------------------------------------------------------------------------
608 -- |-----------------------< check_cancelled_flag >---------------------------|
609 -- ----------------------------------------------------------------------------
610 --
611 -- PUBLIC
612 -- Description:
613 -- The cancelled_flag attribute must be in the domain 'Yes No'.
614 --
615 Procedure check_cancelled_flag
616 (
617 p_flag in varchar2
618 ) is
619 --
620 v_proc varchar2(72) := g_package||'check_cancelled_flag';
621 --
622 Begin
623 --
624 hr_utility.set_location('Entering:'|| v_proc, 5);
625 --
626 If NOT (p_flag in ('N', 'Y')) then
627 --
628 ota_tfh_api_shd.constraint_error( 'OTA_TFH_CANCELLED_FLAG_CHK');
629 --
630 End If;
631 --
632 hr_utility.set_location(' Leaving:'|| v_proc, 10);
633 --
634 End check_cancelled_flag;
635 --
636 -- ----------------------------------------------------------------------------
637 -- |------------------------< finance_lines_exist >---------------------------|
638 -- ----------------------------------------------------------------------------
639 -- PRIVATE
640 -- A private function to return true or false to indicate whether
641 -- finance lines exist for this header_id
642 --
643 Function finance_lines_exist
644 (
645 p_finance_header_id in number
646 )
647 return boolean
648 is
649 --
650 cursor get_finance_line is
651 select 'Exists'
652 from ota_finance_lines
653 where finance_header_id = p_finance_header_id;
654 --
655 v_finance_line_exists varchar2(30);
656 v_proc varchar2(72) := g_package||'finance_lines_exist';
657 --
658 Begin
659 hr_utility.set_location(' Leaving:'|| v_proc, 5);
660 --
661 open get_finance_line;
662 fetch get_finance_line into v_finance_line_exists;
663 if get_finance_line%found then
664 close get_finance_line;
665 hr_utility.trace('Finance Lines Found');
666 return TRUE;
667 else
668 close get_finance_line;
669 hr_utility.trace('Finance Lines not Found');
670 return FALSE;
671 end if;
672 --
673 hr_utility.set_location(' Leaving:'|| v_proc, 10);
674 End finance_lines_exist;
675 --
676 -- ----------------------------------------------------------------------------
677 -- |---------------------------< cancel_header >------------------------------|
678 -- ----------------------------------------------------------------------------
679 --
680 -- PUBLIC
681 --
682 -- OVERLOADING PROCEDURE
683 --
684 -- Description:
685 -- The update of cancelled_flag is not permitted by any other means
686 -- than to call this procedure to cancel. This sets the cancelled_flag
687 -- to 'Y' and creates a cancellation header with the old header_id on
688 -- the new cancellation header in the supersedes_header_id attribute.
689 -- The procedure 'CANCEL_LINES_FOR_HEADER', found in the lines API,
690 -- will then be called.
691 --
692 Procedure cancel_header
693 (
694 p_rec_finance in out nocopy ota_tfh_api_shd.g_rec_type
695 ,p_cancel_header_id out nocopy number
696 ,p_date_raised in date
697 ,p_validate in boolean
698 ) is
699 --
700 l_rec_cancel ota_tfh_api_shd.g_rec_type;
701 v_proc varchar2(72) := g_package||'cancel_header';
702 --
703 Begin
704 --
705 hr_utility.set_location('Entering:'|| v_proc, 5);
706 --
707 -- * Finance Header has already been cancelled
708 --
709 If p_rec_finance.cancelled_flag = 'Y' Then
710 --
711 fnd_message.set_name('OTA','OTA_13486_TFH_CANCEL_HEADER2');
712 fnd_message.set_token('STEP','1');
713 fnd_message.raise_error;
714 --
715 -- * Finance Header is type CANCELLATION
716 --
717 ElsIf p_rec_finance.type = 'C' Then
718 --
719 fnd_message.set_name('OTA','OTA_13486_TFH_CANCEL_HEADER2');
720 fnd_message.set_token('STEP','2');
721 fnd_message.raise_error;
722 --
723 Else
724 --
725 -- * The Finance Line for cancelling has been transfered
726 --
727 If p_rec_finance.transfer_status = 'ST' Then
728 --
729 l_rec_cancel.type := 'C';
730 l_rec_cancel.finance_header_id := null;
731 l_rec_cancel.superceding_header_id := p_rec_finance.finance_header_id;
732 l_rec_cancel.organization_id := p_rec_finance.organization_id;
733 l_rec_cancel.administrator := p_rec_finance.administrator;
734 l_rec_cancel.cancelled_flag := 'N';
735 l_rec_cancel.currency_code := p_rec_finance.currency_code;
736 l_rec_cancel.payment_status_flag := 'N';
737 l_rec_cancel.transfer_status := 'NT';
738 l_rec_cancel.date_raised := p_date_raised;
739 l_rec_cancel.payment_method := p_rec_finance.payment_method;
740 l_rec_cancel.pym_attribute1 := p_rec_finance.pym_attribute1;
741 l_rec_cancel.pym_attribute2 := p_rec_finance.pym_attribute2;
742 l_rec_cancel.pym_attribute3 := p_rec_finance.pym_attribute3;
743 l_rec_cancel.pym_attribute4 := p_rec_finance.pym_attribute4;
744 l_rec_cancel.pym_attribute5 := p_rec_finance.pym_attribute5;
745 l_rec_cancel.pym_attribute6 := p_rec_finance.pym_attribute6;
746 l_rec_cancel.pym_attribute7 := p_rec_finance.pym_attribute7;
747 l_rec_cancel.pym_attribute8 := p_rec_finance.pym_attribute8;
748 l_rec_cancel.pym_attribute9 := p_rec_finance.pym_attribute9;
749 l_rec_cancel.pym_attribute10 := p_rec_finance.pym_attribute10;
750 l_rec_cancel.pym_attribute11 := p_rec_finance.pym_attribute11;
751 l_rec_cancel.pym_attribute12 := p_rec_finance.pym_attribute12;
752 l_rec_cancel.pym_attribute13 := p_rec_finance.pym_attribute13;
753 l_rec_cancel.pym_attribute14 := p_rec_finance.pym_attribute14;
754 l_rec_cancel.pym_attribute15 := p_rec_finance.pym_attribute15;
755 l_rec_cancel.pym_attribute16 := p_rec_finance.pym_attribute16;
756 l_rec_cancel.pym_attribute17 := p_rec_finance.pym_attribute17;
757 l_rec_cancel.pym_attribute18 := p_rec_finance.pym_attribute18;
758 l_rec_cancel.pym_attribute19 := p_rec_finance.pym_attribute19;
759 l_rec_cancel.pym_attribute20 := p_rec_finance.pym_attribute20;
760 l_rec_cancel.pym_information_category :=
761 p_rec_finance.pym_information_category;
762 --
763 -- * Create a new Finance Header of type Cancellation
764 --
765 ota_tfh_api_ins.ins
766 ( P_rec => l_rec_cancel
767 , P_validate => false
768 , P_transaction_type => 'CREATE_CANCELLATION');
769 --
770 p_cancel_header_id := l_rec_cancel.finance_header_id;
771 --
772 Else
773 --
774 p_cancel_header_id := null;
775 --
776 End if;
777 --
778 -- * Set the cancel flag and update the original Finance Header
779 --
780 p_rec_finance.cancelled_flag := 'Y';
781 --
782 If p_validate = false Then
783 --
784 ota_tfh_api_upd.upd
785 ( P_rec => p_rec_finance
786 , P_validate => false
787 , P_transaction_type => 'CANCEL_HEADER');
788 --
789 End if;
790 --
791 -- * Cancellation of the Header Lines should only be called if
792 -- finance lines exist for this header.
793 --
794 if finance_lines_exist(p_rec_finance.finance_header_id) then
795 ota_tfl_api_business_rules2.set_cancel_flag_for_header
796 ( p_finance_header_id => p_rec_finance.finance_header_id
797 , p_new_cancelled_flag => 'Y');
798 end if;
799 --
800 p_cancel_header_id := l_rec_cancel.finance_header_id;
801 --
802 End if;
803 --
804 hr_utility.set_location(' Leaving:'|| v_proc, 10);
805 --
806 End cancel_header;
807 --
808 -- ----------------------------------------------------------------------------
809 -- |---------------------------< cancel_header >------------------------------|
810 -- ----------------------------------------------------------------------------
811 --
812 -- PUBLIC
813 --
814 -- OVERLOADING PROCEDURE
815 --
816 -- Description:
817 -- The update of cancelled_flag is not permitted by any other means
818 -- than to call this procedure to cancel. This sets the cancelled_flag
819 -- to 'Y' and creates a cancellation header with the old header_id on
820 -- the new cancellation header in the supersedes_header_id attribute.
821 -- The procedure 'CANCEL_LINES_FOR_HEADER', found in the lines API,
822 -- will then be called.
823 --
824 Procedure cancel_header
825 (
826 p_finance_header_id in number
827 ,p_cancel_header_id out nocopy number
828 ,p_date_raised in date
829 ,p_validate in boolean
830 ,p_commit in boolean default FALSE
831 ) is
832 --
833 l_rec_cancel ota_tfh_api_shd.g_rec_type;
834 v_proc varchar2(72) := g_package||'cancel_header';
835 --
836 cursor sel_finance_header is
837 select finance_header_id,
838 superceding_header_id,
839 authorizer_person_id,
840 organization_id,
841 administrator,
842 cancelled_flag,
843 currency_code,
844 date_raised,
845 object_version_number,
846 payment_status_flag,
847 transfer_status,
848 type,
849 receivable_type,
850 comments,
851 external_reference,
852 invoice_address,
853 invoice_contact,
854 payment_method,
855 pym_attribute1,
856 pym_attribute10,
857 pym_attribute11,
858 pym_attribute12,
859 pym_attribute13,
860 pym_attribute14,
861 pym_attribute15,
862 pym_attribute16,
863 pym_attribute17,
864 pym_attribute18,
865 pym_attribute19,
866 pym_attribute2,
867 pym_attribute20,
868 pym_attribute3,
869 pym_attribute4,
870 pym_attribute5,
871 pym_attribute6,
872 pym_attribute7,
873 pym_attribute8,
874 pym_attribute9,
875 pym_information_category,
876 transfer_date,
877 transfer_message,
878 vendor_id,
879 contact_id,
880 address_id,
881 customer_id,
882 tfh_information_category,
883 tfh_information1,
884 tfh_information2,
885 tfh_information3,
886 tfh_information4,
887 tfh_information5,
888 tfh_information6,
889 tfh_information7,
890 tfh_information8,
891 tfh_information9,
892 tfh_information10,
893 tfh_information11,
894 tfh_information12,
895 tfh_information13,
896 tfh_information14,
897 tfh_information15,
898 tfh_information16,
899 tfh_information17,
900 tfh_information18,
901 tfh_information19,
902 tfh_information20,
903 paying_cost_center,
904 receiving_cost_center,
905 transfer_from_set_of_books_id,
906 transfer_to_set_of_books_id,
907 from_segment1,
908 from_segment2,
909 from_segment3,
910 from_segment4,
911 from_segment5,
912 from_segment6,
913 from_segment7,
914 from_segment8,
915 from_segment9,
916 from_segment10,
917 from_segment11,
918 from_segment12,
919 from_segment13,
920 from_segment14,
921 from_segment15,
922 from_segment16,
923 from_segment17,
924 from_segment18,
925 from_segment19,
926 from_segment20,
927 from_segment21,
928 from_segment22,
929 from_segment23,
930 from_segment24,
931 from_segment25,
932 from_segment26,
933 from_segment27,
934 from_segment28,
935 from_segment29,
936 from_segment30,
937 to_segment1,
938 to_segment2,
939 to_segment3,
940 to_segment4,
941 to_segment5,
942 to_segment6,
943 to_segment7,
944 to_segment8,
945 to_segment9,
946 to_segment10,
947 to_segment11,
948 to_segment12,
949 to_segment13,
950 to_segment14,
951 to_segment15,
952 to_segment16,
953 to_segment17,
954 to_segment18,
955 to_segment19,
956 to_segment20,
957 to_segment21,
958 to_segment22,
959 to_segment23,
960 to_segment24,
961 to_segment25,
962 to_segment26,
963 to_segment27,
964 to_segment28,
965 to_segment29,
966 to_segment30,
967 transfer_from_cc_id,
968 transfer_to_cc_id
969 from ota_finance_headers
970 where finance_header_id = p_finance_header_id ;
971 --
972 Begin
973 --
974 hr_utility.set_location('Entering:'|| v_proc, 5);
975 --
976 If p_finance_header_id is NOT null Then
977 --
978 Open sel_finance_header;
979 Fetch sel_finance_header into l_rec_cancel;
980 --
981 If sel_finance_header%notfound then
982 Close sel_finance_header;
983 fnd_message.set_name('OTA','OTA_13486_TFH_CANCEL_HEADER2');
984 fnd_message.set_token('STEP','3');
985 fnd_message.raise_error;
986 --
987 End if;
988 --
989 Close sel_finance_header;
990 End if;
991 --
992 -- Call the overloaded procedure passing the Record Group
993 --
994 cancel_header(l_rec_cancel
995 ,p_cancel_header_id
996 ,p_date_raised
997 ,p_validate);
998 --
999 if p_commit then
1000 commit;
1001 end if;
1002 --
1003 hr_utility.set_location(' Leaving:'|| v_proc, 10);
1004 --
1005 End cancel_header;
1006 --
1007 -- ----------------------------------------------------------------------------
1008 -- |-----------------------------< check_superceding >------------------------|
1009 -- ----------------------------------------------------------------------------
1010 --
1011 -- PRIVATE
1012 -- Description:
1013 -- Checks whether a finance_header is used as a superceding header.
1014 --
1015 Procedure check_superceding
1016 (
1017 p_finance_header_id in number
1018 ) is
1019 --
1020 v_exists varchar2(1);
1021 v_proc varchar2(72) := g_package||'check_superceding';
1022 --
1023 cursor sel_for_deletion is
1024 select 'Y'
1025 from ota_finance_headers tfh
1026 where tfh.superceding_header_id = p_finance_header_id;
1027 --
1028 Begin
1029 hr_utility.set_location('Entering:'|| v_proc, 5);
1030 --
1031 Open sel_for_deletion;
1032 Fetch sel_for_deletion into v_exists;
1033 --
1034 If sel_for_deletion%found then
1035 close sel_for_deletion;
1036 fnd_message.set_name('OTA','OTA_13323_TFH_DELETION');
1037 fnd_message.raise_error;
1038 End if;
1039 --
1040 close sel_for_deletion;
1041 hr_utility.set_location(' Leaving:'|| v_proc, 10);
1042 End check_superceding;
1043 --
1044 -- ----------------------------------------------------------------------------
1045 -- |--------------------------< recancel_header >-----------------------------|
1046 -- ----------------------------------------------------------------------------
1047 --
1048 -- PUBLIC
1049 --
1050 --
1051 -- Description:
1052 -- The update of cancelled_flag is not permitted by any other means
1053 -- than to call this procedure to cancel. This sets the cancelled_flag
1054 -- to 'N' and creates a cancellation header with the old header_id on
1055 -- the new cancellation header in the supersedes_header_id attribute.
1056 -- The procedure 'RECANCEL_LINES_FOR_HEADER', found in the lines API,
1057 -- will then be called.
1058 --
1059 Procedure recancel_header
1060 (
1061 p_finance_header_id in number
1062 ,p_validate in boolean
1063 ,p_commit in boolean default FALSE
1064 ) is
1065 --
1066 v_rec_header ota_finance_headers%rowtype;
1067 l_rec_cancel ota_tfh_api_shd.g_rec_type;
1068 v_proc varchar2(72) := g_package||'recancel_header';
1069 --
1070 cursor sel_finance_header is
1071 select *
1072 from ota_finance_headers tfh
1073 where tfh.finance_header_id = p_finance_header_id;
1074 --
1075 Begin
1076 hr_utility.set_location('Entering:'|| v_proc, 5);
1077 --
1078 If p_finance_header_id is NOT null Then
1079 Open sel_finance_header;
1080 Fetch sel_finance_header into v_rec_header;
1081 --
1082 If sel_finance_header%notfound then
1083 Close sel_finance_header;
1084 fnd_message.set_name('OTA','OTA_13487_TFH_REINST_HEADER');
1085 fnd_message.set_token('STEP','3');
1086 fnd_message.raise_error;
1087 End if;
1088 --
1089 Close sel_finance_header;
1090 --
1091 -- * Finance Header has already been cancelled
1092 --
1093 If v_rec_header.cancelled_flag = 'N' Then
1094 fnd_message.set_name('OTA','OTA_13487_TFH_REINST_HEADER');
1095 fnd_message.set_token('STEP','1');
1096 fnd_message.raise_error;
1097 --
1098 -- * Finance Header of type CANCELLATION
1099 --
1100 ElsIf v_rec_header.type = 'C' Then
1101 fnd_message.set_name('OTA','OTA_13487_TFH_REINST_HEADER');
1102 fnd_message.set_token('STEP','2');
1103 fnd_message.raise_error;
1104 Else
1105 --
1106 -- * Checks whether the Finance Header is superceded by another one
1107 -- or not
1108 --
1109 check_superceding( p_finance_header_id);
1110 --
1111 -- * Re-Set the cancel flag and update the original Finance Header
1112 --
1113 v_rec_header.cancelled_flag := 'N';
1114 --
1115 If p_validate = false Then
1116 --
1117 ota_tfh_api_upd.upd
1118 ( p_finance_header_id => v_rec_header.finance_header_id
1119 , p_cancelled_flag => v_rec_header.cancelled_flag
1120 , p_object_version_number => v_rec_header.object_version_number
1121 , P_validate => false
1122 , P_transaction_type => 'REINSTATE_HEADER');
1123 --
1124 End if;
1125 --
1126 -- * Re-Cancellation of the Header Lines should only be attempted
1127 -- if finance lines exist
1128 --
1129 if finance_lines_exist(v_rec_header.finance_header_id) then
1130 ota_tfl_api_business_rules2.set_cancel_flag_for_header
1131 ( p_finance_header_id => v_rec_header.finance_header_id
1132 , p_new_cancelled_flag => 'N' );
1133 end if;
1134 --
1135 End if;
1136 --
1137 End if;
1138 --
1139 if p_commit then
1140 commit;
1141 end if;
1142 --
1143 hr_utility.set_location(' Leaving:'|| v_proc, 10);
1144 --
1145 End recancel_header;
1146 --
1147 --
1148 -- ----------------------------------------------------------------------------
1149 -- |-------------------< check_cancellation_attributes >----------------------|
1150 -- ----------------------------------------------------------------------------
1151 --
1152 -- PUBLIC
1153 -- Description:
1154 -- If the header is of type 'Cancellation' then the following
1155 -- attributes must be NOT NULL:
1156 -- SUPERSEDES_HEADER_ID
1157 -- The following attributes must be NULL:
1158 -- CUSTOMER_CONTACT_ID
1159 -- CUSTOMER_ADDRESS_ID
1160 -- CUSTOMER_ID
1161 -- INVOICE_ADDRESS
1162 -- INVOICE_CONTACT
1163 -- VENDOR_ID
1164 -- VENDOR_CONTACT_ID
1165 -- VENDOR_ADDRESS_ID
1166 -- PAYMENT_METHOD
1167 -- RECEIVABLE_TYPE
1168 --
1169 --
1170 Procedure check_cancellation_attributes
1171 (
1172 p_type in varchar2
1173 ,p_supersedes_header_id in number
1174 ,p_customer_id in number
1175 ,p_customer_contact_id in number
1176 ,p_customer_address_id in number
1177 ,p_invoice_address in varchar2
1178 ,p_invoice_contact in varchar2
1179 ,p_vendor_id in number
1180 ,p_vendor_contact_id in number
1181 ,p_vendor_address_id in number
1182 ,p_payment_method in varchar2
1183 ,p_receivable_type in varchar2
1184 ) is
1185 --
1186 v_proc varchar2(72) := g_package||'check_cancellation_attributes';
1187 --
1188 Begin
1189 --
1190 hr_utility.set_location('Entering:'|| v_proc, 5);
1191 --
1192 If p_type = 'C' Then
1193 --
1194 If p_supersedes_header_id is null OR
1195 p_vendor_id is NOT null OR
1196 p_receivable_type is NOT null OR
1197 p_vendor_contact_id is NOT null OR
1198 p_vendor_address_id is NOT null OR
1199 p_customer_id is NOT null OR
1200 p_customer_contact_id is NOT null OR
1201 p_customer_address_id is NOT null OR
1202 p_invoice_address is NOT null OR
1203 p_invoice_contact is NOT null Then
1204 --
1205 ota_tfh_api_shd.constraint_error( 'OTA_TFH_CANCELLED_ATTRIBUTES');
1206 --
1207 End if;
1208 --
1209 End If;
1210 --
1211 hr_utility.set_location(' Leaving:'|| v_proc, 10);
1212 --
1213 End check_cancellation_attributes;
1214 --
1215 -- ----------------------------------------------------------------------------
1216 -- |----------------------< check_superseded_header >-------------------------|
1217 -- ----------------------------------------------------------------------------
1218 --
1219 -- PUBLIC
1220 -- Description:
1221 -- For a cancellation header the superseded_header_id must be a valid
1222 -- finance header.
1223 --
1224 Procedure check_superseded_header
1225 (
1226 p_finance_type in varchar2
1227 ,p_superseding_header_id in number
1228 ) is
1229 --
1230 v_exists varchar2(1);
1231 v_proc varchar2(72) := g_package||'check_superseded_header';
1232 --
1233 cursor sel_superseding_header is
1234 select 'Y'
1235 from ota_finance_headers tfh
1236 where tfh.finance_header_id = p_superseding_header_id;
1237 --
1238 --
1239 Begin
1240 hr_utility.set_location('Entering:'|| v_proc, 5);
1241 --
1242 If p_finance_type = 'C' Then
1243 --
1244 If p_superseding_header_id is NOT null Then
1245 Open sel_superseding_header;
1246 fetch sel_superseding_header into v_exists;
1247 --
1248 if sel_superseding_header%notfound then
1249 close sel_superseding_header;
1250 fnd_message.set_name('OTA','OTA_13287_TFH_SUPERSEDED_HEAD');
1251 fnd_message.raise_error;
1252 end if;
1253 --
1254 close sel_superseding_header;
1255 --
1256 Else
1257 fnd_message.set_name('OTA','OTA_13287_TFH_SUPERSEDED_HEAD');
1258 fnd_message.raise_error;
1259 End if;
1260 End if;
1261 --
1262 hr_utility.set_location(' Leaving:'|| v_proc, 10);
1263 End check_superseded_header;
1264 --
1265 -- ----------------------------------------------------------------------------
1266 -- |---------------------< check_update_customer_id >-------------------------|
1267 -- ----------------------------------------------------------------------------
1268 --
1269 -- PUBLIC
1270 -- Description:
1271 -- Reference information check, if the customer_id is changed
1272 --
1273 Procedure check_update_customer_id
1274 (
1275 p_customer_id in number
1276 ,p_address_id in number
1277 ,p_contact_id in number
1278 ,p_vendor_id in number
1279 ) is
1280 --
1281 v_proc varchar2(72) := g_package||'check_update_customer_id';
1282 --
1283 Begin
1284 hr_utility.set_location('Entering:'|| v_proc, 5);
1285 --
1286 If p_customer_id is NOT null AND p_vendor_id is NOT null Then
1287 fnd_message.set_name('OTA','OTA_13324_TFH_CUSTOMER_VENDOR');
1288 fnd_message.raise_error;
1289 --
1290 ElsIf p_customer_id is NOT null Then
1291 --
1292 -- Reference check Customer and Address
1293 --
1294 check_customer_address( p_customer_id
1295 , p_address_id );
1296 --
1297 -- Reference check Customer and Contact
1298 --
1299 check_customer_contact( p_customer_id
1300 , p_contact_id );
1301 --
1302 ElsIf p_vendor_id is null AND
1303 (p_address_id is NOT null OR p_contact_id is NOT null) Then
1304 --
1305 fnd_message.set_name('OTA','OTA_13321_TFH_CUSTOMER_NAME');
1306 fnd_message.raise_error;
1307 End if;
1308 --
1309 hr_utility.set_location(' Leaving:'|| v_proc, 10);
1310 --
1311 End check_update_customer_id;
1312 --
1313 -- ----------------------------------------------------------------------------
1314 -- |-----------------------< check_update_vendor_id >-------------------------|
1315 -- ----------------------------------------------------------------------------
1316 --
1317 -- PUBLIC
1318 -- Description:
1319 -- Reference information check, if the customer_id is changed
1320 --
1321 Procedure check_update_vendor_id
1322 (
1323 p_vendor_id in number
1324 ,p_address_id in number
1325 ,p_contact_id in number
1326 ,p_customer_id in number
1327 ) is
1328 --
1329 v_proc varchar2(72) := g_package||'check_update_vendor_id';
1330 --
1331 Begin
1332 hr_utility.set_location('Entering:'|| v_proc, 5);
1333 --
1334 If p_vendor_id is NOT null AND p_customer_id is NOT null Then
1335 fnd_message.set_name('OTA','OTA_13324_TFH_CUSTOMER_VENDOR');
1336 fnd_message.raise_error;
1337 ElsIf p_vendor_id is NOT null Then
1338 --
1339 -- Reference check Vendor and Address
1340 --
1341 check_vendor_address( p_vendor_id
1342 , p_address_id );
1343 --
1344 -- Reference check Vendor and Contact
1345 --
1346 check_vendor_contact( p_vendor_id
1347 , p_contact_id );
1348 --
1349 ElsIf p_customer_id is null AND
1350 (p_address_id is NOT null OR p_contact_id is NOT null) Then
1351 --
1352 fnd_message.set_name('OTA','OTA_13322_TFH_VENDOR_NAME');
1353 fnd_message.raise_error;
1354 End if;
1355 --
1356 --
1357 hr_utility.set_location(' Leaving:'|| v_proc, 10);
1358 --
1359 End check_update_vendor_id;
1360 --
1361 -- ----------------------------------------------------------------------------
1362 -- |------------------------< cancel_and_recreate >---------------------------|
1363 -- ----------------------------------------------------------------------------
1364 --
1365 -- PUBLIC
1366 -- Description:
1367 -- An API procedure is required to cancel a header and create a new
1368 -- header in its place. This procedure will create a new header, which
1369 -- supersedes the one which is to be cancelled. The procedure
1370 -- 'COPY_LINES_TO_NEW_HEADER', found in the lines API, will then be called.
1371 -- The old finance header will then be cancelled by using the 'CANCEL_HEADER'
1372 -- procedure. The TRANSFER_STATUS on the newly created header must be set to
1373 -- 'N' by default.
1374 --
1375 Procedure cancel_and_recreate
1376 (
1377 p_rec_finance in out nocopy ota_tfh_api_shd.g_rec_type
1378 ,p_date_raised in date
1379 ,p_validate in boolean
1380 ) is
1381 --
1382 l_rec_new ota_tfh_api_shd.g_rec_type;
1383 l_cancel_header_id number;
1384 v_proc varchar2(72) := g_package||'cancel_and_recreate';
1385 --
1386 Begin
1387 --
1388 hr_utility.set_location('Entering:'|| v_proc, 5);
1389 --
1390 -- * Finance Header has already been cancelled
1391 --
1392 If p_rec_finance.cancelled_flag = 'Y' Then
1393 --
1394 fnd_message.set_name('OTA','OTA_13315_TFH_CANCEL_HEADER');
1395 fnd_message.set_token('STEP','1');
1396 fnd_message.raise_error;
1397 --
1398 -- * Finance Header is type CANCELLATION
1399 --
1400 ElsIf p_rec_finance.type = 'C' Then
1401 --
1402 fnd_message.set_name('OTA','OTA_13315_TFH_CANCEL_HEADER');
1403 fnd_message.set_token('STEP','2');
1404 fnd_message.raise_error;
1405 --
1406 -- * The Finance Header for cancelling and recreating must be transfered
1407 --
1408 ElsIf p_rec_finance.transfer_status <> 'ST' Then
1409 --
1410 fnd_message.set_name('OTA','OTA_13315_TFH_CANCEL_HEADER');
1411 fnd_message.set_token('STEP','3');
1412 fnd_message.raise_error;
1413 --
1414 Else
1415 --
1416 l_rec_new := p_rec_finance;
1417 --
1418 l_rec_new.finance_header_id := null;
1419 l_rec_new.transfer_status := 'NT';
1420 l_rec_new.transfer_date := null;
1421 l_rec_new.transfer_message := null;
1422 l_rec_new.external_reference := null;
1423 l_rec_new.comments := null;
1424 l_rec_new.date_raised := p_date_raised;
1425 --
1426 l_cancel_header_id := null;
1427 --
1428 -- * Create a new Finance Header for the original Finance Header
1429 -- which is a direct copy of the old. This new header, with
1430 -- copied lines too, will supersede the cancelled header.
1431 --
1432 l_rec_new.superceding_header_id := p_rec_finance.finance_header_id;
1433 --
1434 ota_tfh_api_ins.ins
1435 ( P_rec => l_rec_new
1436 , P_validate => false
1437 , P_transaction_type => 'RECREATE_HEADER');
1438 --
1439 -- * Now copy all non-cancelled lines and link them to the new
1440 -- header
1441 --
1442 ota_tfl_api_business_rules2.copy_lines_to_new_header
1443 ( p_rec_finance.finance_header_id
1444 , l_rec_new.finance_header_id );
1445 --
1446 -- Cancel the original Finance Header and create a new Finance Header of
1447 -- type Cancellation with it's Finance Header Lines. Set the cancelled
1448 -- flag of the original Finance Header.
1449 --
1450 cancel_header( P_rec_finance => p_rec_finance
1451 , P_cancel_header_id => l_cancel_header_id
1452 , P_date_raised => p_date_raised
1453 , P_validate => p_validate );
1454 End if;
1455 --
1456 hr_utility.set_location(' Leaving:'|| v_proc, 10);
1457 --
1458 End cancel_and_recreate;
1459 --
1460 -- ----------------------------------------------------------------------------
1461 -- |------------------------< cancel_and_recreate >---------------------------|
1462 -- ----------------------------------------------------------------------------
1463 --
1464 -- PUBLIC
1465 -- Description:
1466 -- An API procedure is required to cancel a header and create a new
1467 -- header in its place. This procedure will create a new header, which
1468 -- supersedes the one which is to be cancelled. The procedure
1469 -- 'COPY_LINES_TO_NEW_HEADER', found in the lines API, will then be called.
1470 -- The old finance header will then be cancelled by using the 'CANCEL_HEADER'
1471 -- procedure. The TRANSFER_STATUS on the newly created header must be set to
1472 -- 'N' by default.
1473 --
1474 Procedure cancel_and_recreate
1475 (
1476 p_finance_header_id in number
1477 ,p_recreation_header_id out nocopy number
1478 ,p_cancel_header_id out nocopy number
1479 ,p_date_raised in date
1480 ,p_validate in boolean
1481 ,p_commit in boolean default FALSE
1482 ) is
1483 --
1484 v_rec_header ota_tfh_api_shd.g_rec_type;
1485 v_cursor_boolean boolean;
1486 v_validate boolean;
1487 v_date_raised date;
1488 v_proc varchar2(72) := g_package||'cancel_and_recreate';
1489 --
1490 cursor sel_finance_header is
1491 select finance_header_id
1492 , superceding_header_id
1493 , authorizer_person_id
1494 , organization_id
1495 , administrator
1496 , cancelled_flag
1497 , currency_code
1498 , date_raised
1499 , object_version_number
1500 , payment_status_flag
1501 , transfer_status
1502 , type
1503 , receivable_type
1504 , comments
1505 , external_reference
1506 , invoice_address
1507 , invoice_contact
1508 , payment_method
1509 , pym_attribute1
1510 , pym_attribute10
1511 , pym_attribute11
1512 , pym_attribute12
1513 , pym_attribute13
1514 , pym_attribute14
1515 , pym_attribute15
1516 , pym_attribute16
1517 , pym_attribute17
1518 , pym_attribute18
1519 , pym_attribute19
1520 , pym_attribute2
1521 , pym_attribute20
1522 , pym_attribute3
1523 , pym_attribute4
1524 , pym_attribute5
1525 , pym_attribute6
1526 , pym_attribute7
1527 , pym_attribute8
1528 , pym_attribute9
1529 , pym_information_category
1530 , transfer_date
1531 , transfer_message
1532 , vendor_id
1533 , contact_id
1534 , address_id
1535 , customer_id
1536 , tfh_information_category
1537 , tfh_information1
1538 , tfh_information2
1539 , tfh_information3
1540 , tfh_information4
1541 , tfh_information5
1542 , tfh_information6
1543 , tfh_information7
1544 , tfh_information8
1545 , tfh_information9
1546 , tfh_information10
1547 , tfh_information11
1548 , tfh_information12
1549 , tfh_information13
1550 , tfh_information14
1551 , tfh_information15
1552 , tfh_information16
1553 , tfh_information17
1554 , tfh_information18
1555 , tfh_information19
1556 , tfh_information20
1557 , paying_cost_center
1558 , receiving_cost_center
1559 , transfer_from_set_of_books_id
1560 , transfer_to_set_of_books_id
1561 , from_segment1
1562 , from_segment2
1563 , from_segment3
1564 , from_segment4
1565 , from_segment5
1566 , from_segment6
1567 , from_segment7
1568 , from_segment8
1569 , from_segment9
1570 , from_segment10
1571 , from_segment11
1572 , from_segment12
1573 , from_segment13
1574 , from_segment14
1575 , from_segment15
1576 , from_segment16
1577 , from_segment17
1578 , from_segment18
1579 , from_segment19
1580 , from_segment20
1581 , from_segment21
1582 , from_segment22
1583 , from_segment23
1584 , from_segment24
1585 , from_segment25
1586 , from_segment26
1587 , from_segment27
1588 , from_segment28
1589 , from_segment29
1590 , from_segment30
1591 , to_segment1
1592 , to_segment2
1593 , to_segment3
1594 , to_segment4
1595 , to_segment5
1596 , to_segment6
1597 , to_segment7
1598 , to_segment8
1599 , to_segment9
1600 , to_segment10
1601 , to_segment11
1602 , to_segment12
1603 , to_segment13
1604 , to_segment14
1605 , to_segment15
1606 , to_segment16
1607 , to_segment17
1608 , to_segment18
1609 , to_segment19
1610 , to_segment20
1611 , to_segment21
1612 , to_segment22
1613 , to_segment23
1614 , to_segment24
1615 , to_segment25
1616 , to_segment26
1617 , to_segment27
1618 , to_segment28
1619 , to_segment29
1620 , to_segment30
1621 , transfer_from_cc_id
1622 , transfer_to_cc_id
1623 from ota_finance_headers tfh
1624 where tfh.finance_header_id = p_finance_header_id;
1625 --
1626 Begin
1627 --
1628 hr_utility.set_location('Entering:'|| v_proc, 5);
1629 --
1630 If p_finance_header_id is NOT null then
1631 --
1632 --Concert the HEADER_ID into a record by selecting the full
1633 --row into a record structure.
1634 --
1635 Open sel_finance_header;
1636 Fetch sel_finance_header into v_rec_header;
1637 --
1638 v_validate := p_validate;
1639 v_date_raised := p_date_raised;
1640 --
1641 v_cursor_boolean := sel_finance_header%notfound;
1642 --
1643 close sel_finance_header;
1644 --
1645 If v_cursor_boolean then --the header_id was invalid and no rows returned
1646 --
1647 fnd_message.set_name('OTA','OTA_13315_TFH_CANCEL_HEADER');
1648 fnd_message.set_token('STEP','4');
1649 fnd_message.raise_error;
1650 --
1651 End if; --end check for cursor returning no rows.
1652 --
1653 ota_tfh_api_business_rules.cancel_and_recreate
1654 (p_rec_finance => v_rec_header
1655 ,p_date_raised => v_date_raised
1656 ,p_validate => v_validate
1657 );
1658 --
1659 End if; --end check of null header_id
1660 --
1661 if p_commit then
1662 commit;
1663 end if;
1664 hr_utility.set_location(' Leaving:'|| v_proc, 10);
1665 --
1666 End cancel_and_recreate;
1667 --
1668 -- ----------------------------------------------------------------------------
1669 -- |-----------------------< check_payment_method >---------------------------|
1670 -- ----------------------------------------------------------------------------
1671 --
1672 -- PUBLIC
1673 -- Description:
1674 -- The PAYMENT_METHOD attribute must be in the domain 'Payment Method'.
1675 --
1676 Procedure check_payment_method
1677 (
1678 p_payment_method in varchar2
1679 ) is
1680 --
1681 v_proc varchar2(72) := g_package||'check_payment_method';
1682 --
1683 Begin
1684 --
1685 hr_utility.set_location('Entering:'|| v_proc, 5);
1686 --
1687 If p_payment_method is not null Then
1688 --
1689 ota_general.check_domain_value( 'PAYMENT_METHOD', p_payment_method);
1690 --
1691 End If;
1692 --
1693 hr_utility.set_location(' Leaving:'|| v_proc, 10);
1694 --
1695 End check_payment_method;
1696 --
1697 -- ----------------------------------------------------------------------------
1698 -- |-----------------------< check_allow_transfer >---------------------------|
1699 -- ----------------------------------------------------------------------------
1700 --
1701 -- PUBLIC
1702 -- Description:
1703 -- If the TRANSFER_STATUS attribute is any other value than 'NT' the
1704 -- PAYMENT_METHOD attribute must be NOT NULL.
1705 --
1706 Procedure check_allow_transfer
1707 (
1708 p_transfer_status in varchar2
1709 ,p_payment_method in varchar2
1710 ) is
1711 --
1712 v_proc varchar2(72) := g_package||'check_allow_transfer';
1713 --
1714 Begin
1715 --
1716 hr_utility.set_location('Entering:'|| v_proc, 5);
1717 --
1718 If p_transfer_status <> 'NT' Then
1719 --
1720 If p_payment_method is null Then
1721 --
1722 ota_tfh_api_shd.constraint_error( 'OTA_TFH_CHECK_TRANSFER_ATTRIBUTES');
1723 --
1724 End if;
1725 --
1726 End If;
1727 --
1728 hr_utility.set_location(' Leaving:'|| v_proc, 10);
1729 --
1730 End check_allow_transfer;
1731 --
1732 -- ----------------------------------------------------------------------------
1733 -- |------------------------< check_update01_header >-------------------------|
1734 -- ----------------------------------------------------------------------------
1735 --
1736 -- PUBLIC
1737 -- Description:
1738 --
1739 Function check_update01_header
1740 (
1741 p_rec_old in ota_tfh_api_shd.g_rec_type
1742 ,p_rec_new in ota_tfh_api_shd.g_rec_type
1743 ) Return Boolean is
1744 --
1745 v_proc varchar2(72) := g_package||'check_update01_header';
1746 --
1747 l_super_header_id_changed boolean
1748 := ota_general.value_changed( p_rec_old.superceding_header_id
1749 , p_rec_new.superceding_header_id );
1750 --
1751 l_authorizer_person_id_changed boolean
1752 := ota_general.value_changed( p_rec_old.authorizer_person_id
1753 , p_rec_new.authorizer_person_id );
1754 --
1755 l_organization_id_changed boolean
1756 := ota_general.value_changed( p_rec_old.organization_id
1757 , p_rec_new.organization_id );
1758 --
1759 l_administrator_changed boolean
1760 := ota_general.value_changed( p_rec_old.administrator
1761 , p_rec_new.administrator );
1762 --
1763 l_cancelled_flag_changed boolean
1764 := ota_general.value_changed( p_rec_old.cancelled_flag
1765 , p_rec_new.cancelled_flag );
1766 --
1767 l_currency_code_changed boolean
1768 := ota_general.value_changed( p_rec_old.currency_code
1769 , p_rec_new.currency_code );
1770 --
1771 l_date_raised_changed boolean
1772 := ota_general.value_changed( p_rec_old.date_raised
1773 , p_rec_new.date_raised );
1774 --
1775 l_transfer_status_changed boolean
1776 := ota_general.value_changed( p_rec_old.transfer_status
1777 , p_rec_new.transfer_status );
1778 --
1779 l_type_changed boolean
1780 := ota_general.value_changed( p_rec_old.type
1781 , p_rec_new.type );
1782 --
1783 l_comments_changed boolean
1784 := ota_general.value_changed( p_rec_old.comments
1785 , p_rec_new.comments );
1786 --
1787 l_external_reference_changed boolean
1788 := ota_general.value_changed( p_rec_old.external_reference
1789 , p_rec_new.external_reference );
1790 --
1791 l_invoice_address_changed boolean
1792 := ota_general.value_changed( p_rec_old.invoice_address
1793 , p_rec_new.invoice_address );
1794 --
1795 l_invoice_contact_changed boolean
1796 := ota_general.value_changed( p_rec_old.invoice_contact
1797 , p_rec_new.invoice_contact );
1798 --
1799 l_payment_method_changed boolean
1800 := ota_general.value_changed( p_rec_old.payment_method
1801 , p_rec_new.payment_method );
1802 --
1803 l_transfer_date_changed boolean
1804 := ota_general.value_changed( p_rec_old.transfer_date
1805 , p_rec_new.transfer_date );
1806 --
1807 l_transfer_message_changed boolean
1808 := ota_general.value_changed( p_rec_old.transfer_message
1809 , p_rec_new.transfer_message );
1810 --
1811 l_vendor_id_changed boolean
1812 := ota_general.value_changed( p_rec_old.vendor_id
1813 , p_rec_new.vendor_id );
1814 --
1815 l_contact_id_changed boolean
1816 := ota_general.value_changed( p_rec_old.contact_id
1817 , p_rec_new.contact_id );
1818 --
1819 l_address_id_changed boolean
1820 := ota_general.value_changed( p_rec_old.address_id
1821 , p_rec_new.address_id );
1822 --
1823 l_customer_id_changed boolean
1824 := ota_general.value_changed( p_rec_old.customer_id
1825 , p_rec_new.customer_id );
1826 --
1827 l_payment_status_changed boolean
1828 := ota_general.value_changed( p_rec_old.payment_status_flag
1829 , p_rec_new.payment_status_flag );
1830 --
1831 Begin
1832 --
1833 hr_utility.set_location('Entering:'|| v_proc, 5);
1834 --
1835 If l_super_header_id_changed OR
1836 l_authorizer_person_id_changed OR
1837 l_organization_id_changed OR
1838 l_administrator_changed OR
1839 l_currency_code_changed OR
1840 l_date_raised_changed OR
1841 l_transfer_status_changed OR
1842 l_type_changed OR
1843 l_comments_changed OR
1844 l_external_reference_changed OR
1845 l_invoice_address_changed OR
1846 l_invoice_contact_changed OR
1847 l_transfer_date_changed OR
1848 l_transfer_message_changed OR
1849 l_vendor_id_changed OR
1850 l_contact_id_changed OR
1851 l_address_id_changed OR
1852 l_customer_id_changed OR
1853 l_payment_method_changed THEN
1854 --
1855 -- l_payment_status OR
1856 --
1857 return true;
1858 Else
1859 return false;
1860 --
1861 End if;
1862 --
1863 hr_utility.set_location(' Leaving:'|| v_proc, 10);
1864 --
1865 End check_update01_header;
1866 --
1867 -- ----------------------------------------------------------------------------
1868 -- |------------------------< check_update02_header >-------------------------|
1869 -- ----------------------------------------------------------------------------
1870 --
1871 -- PUBLIC
1872 -- Description:
1873 --
1874 Function check_update02_header
1875 (
1876 p_rec_old in ota_tfh_api_shd.g_rec_type
1877 ,p_rec_new in ota_tfh_api_shd.g_rec_type
1878 ) Return Boolean is
1879 --
1880 v_proc varchar2(72) := g_package||'check_update02_header';
1881 --
1882 l_pym_info_category_changed boolean
1883 := ota_general.value_changed( p_rec_old.pym_information_category
1884 , p_rec_new.pym_information_category );
1885 --
1886 l_pym_attribute1_changed boolean
1887 := ota_general.value_changed( p_rec_old.pym_attribute1
1888 , p_rec_new.pym_attribute1 );
1889 --
1890 l_pym_attribute2_changed boolean
1891 := ota_general.value_changed( p_rec_old.pym_attribute2
1892 , p_rec_new.pym_attribute2 );
1893 --
1894 l_pym_attribute3_changed boolean
1895 := ota_general.value_changed( p_rec_old.pym_attribute3
1896 , p_rec_new.pym_attribute3 );
1897 --
1898 l_pym_attribute4_changed boolean
1899 := ota_general.value_changed( p_rec_old.pym_attribute4
1900 , p_rec_new.pym_attribute4 );
1901 --
1902 l_pym_attribute5_changed boolean
1903 := ota_general.value_changed( p_rec_old.pym_attribute5
1904 , p_rec_new.pym_attribute5 );
1905 --
1906 l_pym_attribute6_changed boolean
1907 := ota_general.value_changed( p_rec_old.pym_attribute6
1908 , p_rec_new.pym_attribute6 );
1909 --
1910 l_pym_attribute7_changed boolean
1911 := ota_general.value_changed( p_rec_old.pym_attribute7
1912 , p_rec_new.pym_attribute7 );
1913 --
1914 l_pym_attribute8_changed boolean
1915 := ota_general.value_changed( p_rec_old.pym_attribute8
1916 , p_rec_new.pym_attribute8 );
1917 --
1918 l_pym_attribute9_changed boolean
1919 := ota_general.value_changed( p_rec_old.pym_attribute9
1920 , p_rec_new.pym_attribute9 );
1921 --
1922 l_pym_attribute10_changed boolean
1923 := ota_general.value_changed( p_rec_old.pym_attribute10
1924 , p_rec_new.pym_attribute10 );
1925 --
1926 l_pym_attribute11_changed boolean
1927 := ota_general.value_changed( p_rec_old.pym_attribute11
1928 , p_rec_new.pym_attribute11 );
1929 --
1930 l_pym_attribute12_changed boolean
1931 := ota_general.value_changed( p_rec_old.pym_attribute12
1932 , p_rec_new.pym_attribute12 );
1933 --
1934 l_pym_attribute13_changed boolean
1935 := ota_general.value_changed( p_rec_old.pym_attribute13
1936 , p_rec_new.pym_attribute13 );
1937 --
1938 l_pym_attribute14_changed boolean
1939 := ota_general.value_changed( p_rec_old.pym_attribute14
1940 , p_rec_new.pym_attribute14 );
1941 --
1942 l_pym_attribute15_changed boolean
1943 := ota_general.value_changed( p_rec_old.pym_attribute15
1944 , p_rec_new.pym_attribute15 );
1945 --
1946 l_pym_attribute16_changed boolean
1947 := ota_general.value_changed( p_rec_old.pym_attribute16
1948 , p_rec_new.pym_attribute16 );
1949 --
1950 l_pym_attribute17_changed boolean
1951 := ota_general.value_changed( p_rec_old.pym_attribute17
1952 , p_rec_new.pym_attribute17 );
1953 --
1954 l_pym_attribute18_changed boolean
1955 := ota_general.value_changed( p_rec_old.pym_attribute18
1956 , p_rec_new.pym_attribute18 );
1957 --
1958 l_pym_attribute19_changed boolean
1959 := ota_general.value_changed( p_rec_old.pym_attribute19
1960 , p_rec_new.pym_attribute19 );
1961 --
1962 l_pym_attribute20_changed boolean
1963 := ota_general.value_changed( p_rec_old.pym_attribute20
1964 , p_rec_new.pym_attribute20 );
1965 --
1966 l_tfh_info_category_changed boolean
1967 := ota_general.value_changed( p_rec_old.tfh_information_category
1968 , p_rec_new.tfh_information_category );
1969 --
1970 l_tfh_info1_changed boolean
1971 := ota_general.value_changed( p_rec_old.tfh_information1
1972 , p_rec_new.tfh_information1 );
1973 --
1974 l_tfh_info2_changed boolean
1975 := ota_general.value_changed( p_rec_old.tfh_information2
1976 , p_rec_new.tfh_information2 );
1977 --
1978 l_tfh_info3_changed boolean
1979 := ota_general.value_changed( p_rec_old.tfh_information3
1980 , p_rec_new.tfh_information3 );
1981 --
1982 l_tfh_info4_changed boolean
1983 := ota_general.value_changed( p_rec_old.tfh_information4
1984 , p_rec_new.tfh_information4 );
1985 --
1986 l_tfh_info5_changed boolean
1987 := ota_general.value_changed( p_rec_old.tfh_information5
1988 , p_rec_new.tfh_information5 );
1989 --
1990 l_tfh_info6_changed boolean
1991 := ota_general.value_changed( p_rec_old.tfh_information6
1992 , p_rec_new.tfh_information6 );
1993 --
1994 l_tfh_info7_changed boolean
1995 := ota_general.value_changed( p_rec_old.tfh_information7
1996 , p_rec_new.tfh_information7 );
1997 --
1998 l_tfh_info8_changed boolean
1999 := ota_general.value_changed( p_rec_old.tfh_information8
2000 , p_rec_new.tfh_information8 );
2001 --
2002 l_tfh_info9_changed boolean
2003 := ota_general.value_changed( p_rec_old.tfh_information9
2004 , p_rec_new.tfh_information9 );
2005 --
2006 l_tfh_info10_changed boolean
2007 := ota_general.value_changed( p_rec_old.tfh_information10
2008 , p_rec_new.tfh_information10 );
2009 --
2010 l_tfh_info11_changed boolean
2011 := ota_general.value_changed( p_rec_old.tfh_information11
2012 , p_rec_new.tfh_information11 );
2013 --
2014 l_tfh_info12_changed boolean
2015 := ota_general.value_changed( p_rec_old.tfh_information12
2016 , p_rec_new.tfh_information12 );
2017 --
2018 l_tfh_info13_changed boolean
2019 := ota_general.value_changed( p_rec_old.tfh_information13
2020 , p_rec_new.tfh_information13 );
2021 --
2022 l_tfh_info14_changed boolean
2023 := ota_general.value_changed( p_rec_old.tfh_information14
2024 , p_rec_new.tfh_information14 );
2025 --
2026 l_tfh_info15_changed boolean
2027 := ota_general.value_changed( p_rec_old.tfh_information15
2028 , p_rec_new.tfh_information15 );
2029 --
2030 l_tfh_info16_changed boolean
2031 := ota_general.value_changed( p_rec_old.tfh_information16
2032 , p_rec_new.tfh_information16 );
2033 --
2034 l_tfh_info17_changed boolean
2035 := ota_general.value_changed( p_rec_old.tfh_information17
2036 , p_rec_new.tfh_information17 );
2037 --
2038 l_tfh_info18_changed boolean
2039 := ota_general.value_changed( p_rec_old.tfh_information18
2040 , p_rec_new.tfh_information18 );
2041 --
2042 l_tfh_info19_changed boolean
2043 := ota_general.value_changed( p_rec_old.tfh_information19
2044 , p_rec_new.tfh_information19 );
2045 --
2046 l_tfh_info20_changed boolean
2047 := ota_general.value_changed( p_rec_old.tfh_information20
2048 , p_rec_new.tfh_information20 );
2049 --
2050 Begin
2051 --
2052 hr_utility.set_location('Entering:'|| v_proc, 5);
2053 --
2054 If l_pym_info_category_changed OR
2055 l_pym_attribute1_changed OR
2056 l_pym_attribute2_changed OR
2057 l_pym_attribute3_changed OR
2058 l_pym_attribute4_changed OR
2059 l_pym_attribute5_changed OR
2060 l_pym_attribute6_changed OR
2061 l_pym_attribute7_changed OR
2062 l_pym_attribute8_changed OR
2063 l_pym_attribute9_changed OR
2064 l_pym_attribute10_changed OR
2065 l_pym_attribute11_changed OR
2066 l_pym_attribute12_changed OR
2067 l_pym_attribute13_changed OR
2068 l_pym_attribute14_changed OR
2069 l_pym_attribute15_changed OR
2070 l_pym_attribute16_changed OR
2071 l_pym_attribute17_changed OR
2072 l_pym_attribute18_changed OR
2073 l_pym_attribute19_changed OR
2074 l_pym_attribute20_changed OR
2075 l_tfh_info_category_changed OR
2076 l_tfh_info1_changed OR
2077 l_tfh_info2_changed OR
2078 l_tfh_info3_changed OR
2079 l_tfh_info4_changed OR
2080 l_tfh_info5_changed OR
2081 l_tfh_info6_changed OR
2082 l_tfh_info7_changed OR
2083 l_tfh_info8_changed OR
2084 l_tfh_info9_changed OR
2085 l_tfh_info10_changed OR
2086 l_tfh_info11_changed OR
2087 l_tfh_info12_changed OR
2088 l_tfh_info13_changed OR
2089 l_tfh_info14_changed OR
2090 l_tfh_info15_changed OR
2091 l_tfh_info16_changed OR
2092 l_tfh_info17_changed OR
2093 l_tfh_info18_changed OR
2094 l_tfh_info19_changed OR
2095 l_tfh_info20_changed THEN
2096 --
2097 --
2098 return true;
2099 else
2100 return false;
2101 --
2102 End if;
2103 --
2104 hr_utility.set_location(' Leaving:'|| v_proc, 10);
2105 --
2106 End check_update02_header;
2107 --
2108 -- ----------------------------------------------------------------------------
2109 -- |------------------------< check_update_header >---------------------------|
2110 -- ----------------------------------------------------------------------------
2111 --
2112 -- PUBLIC
2113 -- Description:
2114 -- The details of a header may not be updated if the header has been
2115 -- transferred other than to set the 'PAYMENT_FLAG'.
2116 -- Enforced by the constraint 'OTA_TFH_CHECK_UPDATE'
2117 --
2118 Procedure check_update_header
2119 (
2120 p_rec_old in ota_tfh_api_shd.g_rec_type
2121 ,p_rec_new in ota_tfh_api_shd.g_rec_type
2122 ,p_transaction_type in varchar2
2123 ) is
2124 --
2125 v_proc varchar2(72) := g_package||'check_update_header';
2126 --
2127 Begin
2128 --
2129 hr_utility.set_location('Entering:'|| v_proc, 5);
2130 --
2131 if p_transaction_type = 'CANCEL_HEADER' or
2132 p_transaction_type = 'REINSTATE_HEADER' then
2133 --
2134 if check_update01_header( p_rec_old, p_rec_new ) or
2135 check_update02_header( p_rec_old, p_rec_new ) or
2136 ota_general.value_changed( p_rec_old.payment_status_flag
2137 , p_rec_new.payment_status_flag) then
2138 --
2139 fnd_message.set_name('OTA','OTA_13290_TFH_UPDATE');
2140 fnd_message.set_token('STEP','1');
2141 fnd_message.raise_error;
2142 end if;
2143
2144 else
2145 if p_rec_old.transfer_status = 'ST' then
2146 if check_update01_header( p_rec_old, p_rec_new ) or
2147 check_update02_header( p_rec_old, p_rec_new ) or
2148 ota_general.value_changed(p_rec_old.cancelled_flag
2149 ,p_rec_new.cancelled_flag) then
2150 --
2151 fnd_message.set_name('OTA','OTA_13290_TFH_UPDATE');
2152 fnd_message.set_token('STEP','2');
2153 fnd_message.raise_error;
2154 end if;
2155 end if;
2156 if p_rec_old.cancelled_flag = 'Y' then
2157 if check_update01_header( p_rec_old, p_rec_new ) or
2158 check_update02_header( p_rec_old, p_rec_new ) or
2159 ota_general.value_changed( p_rec_old.payment_status_flag
2160 , p_rec_new.payment_status_flag) or
2161 ota_general.value_changed(p_rec_old.cancelled_flag
2162 ,p_rec_new.cancelled_flag) then
2163 --
2164 fnd_message.set_name('OTA','OTA_13290_TFH_UPDATE');
2165 fnd_message.set_token('STEP','3');
2166 fnd_message.raise_error;
2167 --
2168 end if;
2169 end if;
2170 end if;
2171 --
2172 hr_utility.set_location(' Leaving:'|| v_proc, 10);
2173 --
2174 End check_update_header;
2175 --
2176 -- ----------------------------------------------------------------------------
2177 -- |--------------------< check_payment_status_flag >-------------------------|
2178 -- ----------------------------------------------------------------------------
2179 --
2180 -- PUBLIC
2181 -- Description:
2182 -- The attribute 'PAYMENT_STATUS_FLAG' must be in the domain 'Yes No'.
2183 --
2184 Procedure check_payment_status_flag
2185 (
2186 p_flag in varchar2
2187 ) is
2188 --
2189 v_proc varchar2(72) := g_package||'check_payment_status_flag';
2190 --
2191 Begin
2192 --
2193 hr_utility.set_location('Entering:'|| v_proc, 5);
2194 --
2195 If NOT (p_flag in ('N', 'Y')) then
2196 --
2197 ota_tfh_api_shd.constraint_error( 'OTA_TFH_PAYMENT_STATUS_FLA_CHK');
2198 --
2199 End If;
2200 --
2201 hr_utility.set_location(' Leaving:'|| v_proc, 10);
2202 --
2203 End check_payment_status_flag;
2204 --
2205 -- ----------------------------------------------------------------------------
2206 -- |------------------------< check_administrator >---------------------------|
2207 -- ----------------------------------------------------------------------------
2208 --
2209 -- PUBLIC
2210 -- Description:
2211 -- The ADMINISTRATOR attribute must be a valid AOL user.
2212 --
2213 Procedure check_administrator
2214 (
2215 p_administrator in number
2216 ) is
2217 --
2218 v_proc varchar2(72) := g_package||'check_administrator';
2219 --
2220 Begin
2221 --
2222 hr_utility.set_location('Entering:'|| v_proc, 5);
2223 --
2224 If p_administrator is NOT null Then
2225 --
2226 if not ota_general.check_fnd_user(p_administrator) then
2227 fnd_message.set_name('OTA','OTA_13291_TFH_ADMINISTRATOR');
2228 fnd_message.raise_error;
2229 end if;
2230 End if;
2231 --
2232 hr_utility.set_location(' Leaving:'|| v_proc, 10);
2233 --
2234 End check_administrator;
2235 --
2236 -- ----------------------------------------------------------------------------
2237 -- |------------------< check_deletion_allowed_status >-----------------------|
2238 -- ----------------------------------------------------------------------------
2239 --
2240 -- PRIVATE
2241 -- Description:
2242 -- Checks whether a finance_header can be deleted.
2243 --
2244 Procedure check_deletion_allowed_status
2245 (
2246 p_finance_header_id in number
2247 ,p_superceding_header_id out nocopy number
2248 ,p_type out nocopy varchar2
2249 ) is
2250 --
2251 p_transfer_status varchar2(30);
2252 v_proc varchar2(72) := g_package||'check_deletion_allowed_status';
2253 --
2254 cursor sel_for_deletion is
2255 select tfh.transfer_status
2256 , tfh.superceding_header_id
2257 , tfh.type
2258 from ota_finance_headers tfh
2259 where tfh.finance_header_id = p_finance_header_id;
2260 --
2261 Begin
2262 --
2263 hr_utility.set_location('Entering:'|| v_proc, 5);
2264 --
2265 If p_finance_header_id is NOT null Then
2266 --
2267 Open sel_for_deletion;
2268 Fetch sel_for_deletion into p_transfer_status
2269 , p_superceding_header_id
2270 , p_type;
2271 --
2272 If sel_for_deletion%notfound then
2273 --
2274 close sel_for_deletion;
2275 --
2276 fnd_message.set_name('OTA','OTA_13323_TFH_DELETION');
2277 fnd_message.raise_error;
2278 End if;
2279 --
2280 close sel_for_deletion;
2281 --
2282 -- Only NOT TRANSFERED Finance Headers can be deleted
2283 --
2284 If p_transfer_status = 'ST' then
2285 --
2286 fnd_message.set_name('OTA','OTA_13323_TFH_DELETION');
2287 fnd_message.raise_error;
2288 End if;
2289 --
2290 End if;
2291 --
2292 hr_utility.set_location(' Leaving:'|| v_proc, 10);
2293 --
2294 End check_deletion_allowed_status;
2295 --
2296 -- ----------------------------------------------------------------------------
2297 -- |------------------------< check_deletion_childs >-------------------------|
2298 -- ----------------------------------------------------------------------------
2299 --
2300 -- PRIVATE
2301 -- Description:
2302 -- Checks whether a finance_header has finance_lines
2303 --
2304 Procedure check_deletion_childs
2305 (
2306 p_finance_header_id in number
2307 ) is
2308 --
2309 v_exists varchar2(1);
2310 v_proc varchar2(72) := g_package||'check_deletion_childs';
2311 --
2312 cursor sel_for_deletion is
2313 select 'Y'
2314 from ota_finance_lines tfl
2315 where tfl.finance_header_id = p_finance_header_id;
2316 --
2317 Begin
2318 --
2319 hr_utility.set_location('Entering:'|| v_proc, 5);
2320 --
2321 Open sel_for_deletion;
2322 Fetch sel_for_deletion into v_exists;
2323 --
2324 If sel_for_deletion%found then
2325 --
2326 close sel_for_deletion;
2327 --
2328 fnd_message.set_name('OTA','OTA_443876_TFH_DELETE_CHK');
2329 fnd_message.raise_error;
2330 --
2331 End if;
2332 --
2333 close sel_for_deletion;
2334 --
2335 hr_utility.set_location(' Leaving:'|| v_proc, 10);
2336 --
2337 End check_deletion_childs;
2338 --
2339 -- ----------------------------------------------------------------------------
2340 -- |----------------------------< check_deletion >----------------------------|
2341 -- ----------------------------------------------------------------------------
2342 --
2343 -- PUBLIC
2344 -- Description:
2345 -- Checks whether a finance_header can be deleted.
2346 --
2347 Procedure check_deletion
2348 (
2349 p_finance_header_id in number
2350 ) is
2351 --
2352 v_type varchar2(30);
2353 v_superceding_header_id number( 9);
2354 v_proc varchar2(72) := g_package||'check_deletion';
2355 --
2356 Begin
2357 --
2358 hr_utility.set_location('Entering:'|| v_proc, 5);
2359 --
2360 If p_finance_header_id is NOT null Then
2361 --
2362 -- * Checks whether the Finance Header has Finance Lines
2363 --
2364 check_deletion_childs( p_finance_header_id);
2365 --
2366 -- * Checks whether the Finance Header is transfered or not
2367 --
2368 check_deletion_allowed_status( p_finance_header_id
2369 , v_superceding_header_id
2370 , v_type );
2371 --
2372 -- * Checks whether the Finance Header is superceded by another one
2373 -- or not
2374 --
2375 check_superceding( p_finance_header_id);
2376 --
2377 -- If a Cancellation Header should be deleted, then the superceding
2378 -- finance header Cancelled Flag is set to 'N'
2379 --
2380 If v_type = 'C' Then
2381 --
2382 recancel_header( p_finance_header_id => v_superceding_header_id
2383 ,p_validate => FALSE);
2384 --
2385 End if;
2386 --
2387 End if;
2388 --
2389 hr_utility.set_location(' Leaving:'|| v_proc, 10);
2390 --
2391 End check_deletion;
2392 -- ----------------------------------------------------------------------------
2393 -- |------------------------------< organization_name> -----------------------|
2394 -- ----------------------------------------------------------------------------
2395 --
2396 -- PRIVATE
2397 -- Description:
2398 -- Returns the organization name for the given id
2399 --
2400 function organization_name (p_organization_id in number) return varchar2 is
2401 --
2402 cursor c_organization is
2403 select name
2404 from hr_organization_units
2405 where organization_id = p_organization_id;
2406 --
2407 l_result hr_all_organization_units.name%TYPE; -- Bug 2256328
2408 --
2409 begin
2410 --
2411 open c_organization;
2412 fetch c_organization into l_result;
2413 close c_organization;
2414 --
2415 return l_result;
2416 --
2417 end;
2418 --
2419 -- ----------------------------------------------------------------------------
2420 -- |----------------------------< initialize_finance_header ------------------|
2421 -- ----------------------------------------------------------------------------
2422 --
2423 -- PUBLIC
2424 -- Description:
2425 -- Get some default values for the Finance Header Form
2426 --
2427 procedure initialize_finance_header
2428 (
2429 p_business_group_id in number
2430 ,p_fnd_user_id in number
2431 ,p_deflt_currency_code out nocopy varchar2
2432 ,p_deflt_trans_status_meaning out nocopy varchar2
2433 ,p_deflt_administrator out nocopy varchar2
2434 ,p_deflt_organization out nocopy varchar2
2435 ) is
2436 cursor get_fnd_user is
2437 select user_name
2438 from fnd_user
2439 where user_id = p_fnd_user_id;
2440 --
2441 begin
2442 -- get default currency code for the Business group
2443 --
2444 p_deflt_currency_code := hr_general.default_currency_code
2445 (p_business_group_id);
2446
2447 --
2448 -- Get default Transfer Status
2449 --
2450 p_deflt_trans_status_meaning :=
2451 hr_general.decode_lookup('GL_TRANSFER_STATUS' ,'NT');
2452 --
2453 -- Get default Administrator
2454 --
2455 open get_fnd_user;
2456 fetch get_fnd_user into p_deflt_administrator;
2457 close get_fnd_user;
2458 --
2459 --
2460 -- Get default organization
2461 --
2462 p_deflt_organization := organization_name (p_business_group_id);
2463
2464 end;
2465 --
2466 --
2467 -- ----------------------------------------------------------------------------
2468 -- |----------------------------< check_superseded >---------------------------
2469 -- ----------------------------------------------------------------------------
2470 --
2471 -- PUBLIC
2472 -- Description:
2473 -- Check whether the Finance Header has been superceded and prevent update
2474 -- if it has
2475 --
2476 procedure check_superseded (p_finance_header_id in number) is
2477 v_proc varchar2(72) := g_package||'check_superseded';
2478 l_dummy varchar2(1);
2479 --
2480 cursor get_superseding_header is
2481 select null
2482 from ota_finance_headers
2483 where superceding_header_id = p_finance_header_id;
2484 --
2485 begin
2486 hr_utility.set_location('Entering:'|| v_proc, 5);
2487 hr_utility.trace('Header ID is '||to_char(p_finance_header_id));
2488 --
2489 open get_superseding_header;
2490 fetch get_superseding_header into l_dummy;
2491 if get_superseding_header%notfound then
2492 close get_superseding_header;
2493 return;
2494 else
2495 close get_superseding_header;
2496 fnd_message.set_name('OTA','OTA_13320_TFH_SUPERSEDED');
2497 fnd_message.raise_error;
2498 --
2499 end if;
2500 --
2501 hr_utility.set_location('Entering:'|| v_proc, 5);
2502 end check_superseded;
2503 --
2504 end ota_tfh_api_business_rules;