[Home] [Help]
PACKAGE BODY: APPS.OTA_TFH_API_BUS
Source
1 Package Body ota_tfh_api_bus as
2 /* $Header: ottfh01t.pkb 120.0 2005/05/29 07:40:15 appldev noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' ota_tfh_api_bus.'; -- Global package name
9 --
10 -- ----------------------------------------------------------------------------
11 -- |---------------------------< insert_validate >----------------------------|
12 -- ----------------------------------------------------------------------------
13 Procedure insert_validate
14 (
15 p_rec in out nocopy ota_tfh_api_shd.g_rec_type
16 ,p_transaction_type in varchar2
17 ) is
18 --
19 l_proc varchar2(72) := g_package||'insert_validate';
20 --
21 Begin
22 hr_utility.set_location('Entering:'||l_proc, 5);
23 --
24 -- Call all supporting business operations
25 --
26 if p_rec.cancelled_flag = 'N' then
27 null;
28 else
29 fnd_message.set_name('OTA','OTA_13489_TFH_CANCEL_FLAG');
30 fnd_message.raise_error;
31 end if;
32 --
33 ota_tfh_api_business_rules.check_receivable_attributes
34 ( p_rec.type
35 , p_rec.customer_id
36 , p_rec.contact_id
37 , p_rec.address_id
38 , p_rec.invoice_address
39 , p_rec.invoice_contact
40 , p_rec.vendor_id
41 , null
42 , null
43 , p_rec.receivable_type);
44 --
45 ota_tfh_api_business_rules.check_payable_attributes
46 ( p_rec.type
47 , p_rec.vendor_id
48 , p_rec.contact_id
49 , p_rec.address_id
50 , p_rec.invoice_contact
51 , p_rec.invoice_address
52 , p_rec.customer_id
53 , null
54 , null
55 , p_rec.receivable_type);
56 --
57 ota_tfh_api_business_rules.check_cancellation_attributes
58 ( p_rec.type
59 , p_rec.superceding_header_id
60 , p_rec.customer_id
61 , p_rec.contact_id
62 , p_rec.address_id
63 , p_rec.invoice_address
64 , p_rec.invoice_contact
65 , p_rec.vendor_id
66 , null
67 , null
68 , p_rec.payment_method
69 , p_rec.receivable_type);
70 --
71 ota_tfh_api_business_rules.check_status_unauthorized
72 ( p_rec.transfer_status
73 , p_rec.authorizer_person_id );
74 --
75 If p_rec.date_raised is null Then
76 --
77 ota_tfh_api_business_rules.set_date_raised( p_rec.date_raised
78 , sysdate );
79 --
80 End if;
81 --
82 ota_tfh_api_business_rules.check_authorized_by
83 ( p_rec.authorizer_person_id);
84
85 --
86 ota_tfh_api_business_rules.check_customer_address
87 ( p_rec.customer_id
88 , p_rec.address_id );
89 --
90 if p_rec.invoice_address is null and
91 p_rec.address_id is not null then
92 ota_tfh_api_business_rules.set_invoice_address
93 ( p_rec.customer_id
94 , p_rec.address_id
95 , p_rec.invoice_address );
96 end if;
97 --
98 ota_tfh_api_business_rules.check_customer_contact
99 ( p_rec.customer_id
100 , p_rec.contact_id );
101 --
102 if p_rec.invoice_address is null and
103 p_rec.address_id is not null then
104 ota_tfh_api_business_rules.set_invoice_contact
105 ( p_rec.customer_id
106 , p_rec.contact_id
107 , p_rec.invoice_contact );
108 end if;
109 --
110 ota_tfh_api_business_rules.check_vendor_contact
111 ( p_rec.vendor_id
112 , p_rec.contact_id );
113 --
114 ota_tfh_api_business_rules.check_vendor_address
115 ( p_rec.vendor_id
116 , p_rec.address_id );
117 --
118 ota_tfh_api_business_rules.check_superseded_header
119 ( p_rec.type
120 , p_rec.superceding_header_id );
121 --
122 ota_tfh_api_business_rules.check_payment_method( p_rec.payment_method );
123 --
124 if p_rec.type <> 'CT' then
125 ota_tfh_api_business_rules.check_allow_transfer
126 ( p_rec.transfer_status
127 , p_rec.payment_method );
128 end if;
129 --
130 ota_tfh_api_business_rules.check_administrator( p_rec.administrator );
131
132 --
133 --
134 -- check_transfer_status( p_rec.transfer_status);
135 --
136 -- check_cancelled_flag( p_rec.cancelled_flag );
137 --
138 -- check_payment_flag( p_rec.payment_flag );
139 --
140 hr_utility.set_location(' Leaving:'||l_proc, 10);
141 End insert_validate;
142 --
143 -- ----------------------------------------------------------------------------
144 -- |---------------------------< update_validate >----------------------------|
145 -- ----------------------------------------------------------------------------
146 -- {Start Of Comments}
147 --
148 -- Description:
149 -- This procedure controls the execution of all update business rules
150 -- validation.
151 --
152 -- Pre Conditions:
153 -- This private procedure is called from upd procedure.
154 --
155 -- In Arguments:
156 -- A Pl/Sql record structre.
157 --
158 -- Post Success:
159 -- Processing continues.
160 --
161 -- Post Failure:
162 -- If a business rules fails the error will not be handled by this procedure
163 -- unless explicity coded.
164 --
165 -- Developer Implementation Notes:
166 -- For update, your business rules should be coded within this procedure and
167 -- should ideally (unless really necessary) just be straight procedure or
168 -- function calls. Try and avoid using conditional branching logic.
169 --
170 -- {End Of Comments}
171 -- ----------------------------------------------------------------------------
172 Procedure update_validate(p_rec in out nocopy ota_tfh_api_shd.g_rec_type
173 ,p_transaction_type in varchar2) is
174 --
175 l_proc varchar2(72) := g_package||'update_validate';
176 --
177 l_type_changed boolean
178 := ota_general.value_changed( ota_tfh_api_shd.g_old_rec.type
179 , p_rec.type );
180 --
181 l_transfer_status_changed boolean
182 := ota_general.value_changed( ota_tfh_api_shd.g_old_rec.transfer_status
183 , p_rec.transfer_status );
184 --
185 l_authorizer_person_id_changed boolean
186 := ota_general.value_changed( ota_tfh_api_shd.g_old_rec.authorizer_person_id
187 , p_rec.authorizer_person_id );
188 --
189 l_address_id_changed boolean
190 := ota_general.value_changed( ota_tfh_api_shd.g_old_rec.address_id
191 , p_rec.address_id );
192 --
193 l_contact_id_changed boolean
194 := ota_general.value_changed( ota_tfh_api_shd.g_old_rec.contact_id
195 , p_rec.contact_id );
196 --
197 l_customer_id_changed boolean
198 := ota_general.value_changed( ota_tfh_api_shd.g_old_rec.customer_id
199 , p_rec.customer_id );
200 --
201 l_vendor_id_changed boolean
202 := ota_general.value_changed( ota_tfh_api_shd.g_old_rec.vendor_id
203 , p_rec.vendor_id );
204 --
205 l_cancelled_flag_changed boolean
206 := ota_general.value_changed( ota_tfh_api_shd.g_old_rec.cancelled_flag
207 , p_rec.cancelled_flag );
208 --
209 l_supercedes_header_id_changed boolean
210 := ota_general.value_changed( ota_tfh_api_shd.g_old_rec.superceding_header_id
211 , p_rec.superceding_header_id );
212 --
213 l_payment_method_changed boolean
214 := ota_general.value_changed( ota_tfh_api_shd.g_old_rec.payment_method
215 , p_rec.payment_method );
216 --
217 l_administrator_changed boolean
218 := ota_general.value_changed( ota_tfh_api_shd.g_old_rec.administrator
219 , p_rec.administrator );
220 --
221 Begin
222 hr_utility.set_location('Entering:'||l_proc, 5);
223 --
224 -- Call all supporting business operations
225 --
226 --
227 ota_tfh_api_business_rules.check_update_header
228 ( ota_tfh_api_shd.g_old_rec
229 , p_rec
230 , p_transaction_type);
231 --
232 -- If cancelling the Header no further checks are required
233 --
234 if p_transaction_type = 'CANCEL_HEADER' then
235 return;
236 end if;
237 --
238 -- If finance header has been superseded then no changes allowed
239 --
240 ota_tfh_api_business_rules.check_superseded (p_rec.finance_header_id);
241 --
242 If l_type_changed OR
243 l_customer_id_changed OR
244 l_address_id_changed OR
245 l_contact_id_changed OR
246 l_vendor_id_changed OR
247 l_cancelled_flag_changed Then
248 --
249 ota_tfh_api_business_rules.check_receivable_attributes
250 ( p_rec.type
251 , p_rec.customer_id
252 , p_rec.contact_id
253 , p_rec.address_id
254 , p_rec.invoice_address
255 , p_rec.invoice_contact
256 , p_rec.vendor_id
257 , null
258 , null
259 , p_rec.receivable_type);
260 --
261 ota_tfh_api_business_rules.check_payable_attributes
262 ( p_rec.type
263 , p_rec.vendor_id
264 , p_rec.contact_id
265 , p_rec.address_id
266 , p_rec.invoice_contact
267 , p_rec.invoice_address
268 , p_rec.customer_id
269 , null
270 , null
271 , p_rec.receivable_type);
272 --
273 End if;
274 --
275 If l_type_changed OR
276 l_supercedes_header_id_changed OR
277 l_customer_id_changed OR
278 l_address_id_changed OR
279 l_contact_id_changed OR
280 l_vendor_id_changed Then
281 --
282 ota_tfh_api_business_rules.check_cancellation_attributes
283 ( p_rec.type
284 , p_rec.superceding_header_id
285 , p_rec.customer_id
286 , p_rec.contact_id
287 , p_rec.address_id
288 , p_rec.invoice_address
289 , p_rec.invoice_contact
290 , p_rec.vendor_id
291 , null
292 , null
293 , p_rec.payment_method
294 , p_rec.receivable_type);
295 --
296 End if;
297 --
298 If l_authorizer_person_id_changed or l_transfer_status_changed Then
299 --
300 ota_tfh_api_business_rules.check_status_unauthorized
301 ( p_rec.transfer_status
302 , p_rec.authorizer_person_id );
303 --
304 ota_tfh_api_business_rules.check_authorized_by
305 ( p_rec.authorizer_person_id);
306 --
307 End if;
308 --
309 If l_customer_id_changed Then
310 --
311 ota_tfh_api_business_rules.check_update_customer_id
312 ( p_rec.customer_id
313 , p_rec.address_id
314 , p_rec.contact_id
315 , p_rec.vendor_id );
316 --
317 End if;
318 --
319 If l_address_id_changed Then
320 --
321 if p_rec.invoice_address is null and
322 p_rec.address_id is not null then
323 ota_tfh_api_business_rules.set_invoice_address
324 ( p_rec.customer_id
325 , p_rec.address_id
326 , p_rec.invoice_address );
327 end if;
328 --
329 End if;
330 --
331 If l_contact_id_changed Then
332 --
333 if p_rec.invoice_address is null and
334 p_rec.address_id is not null then
335 ota_tfh_api_business_rules.set_invoice_contact
336 ( p_rec.customer_id
337 , p_rec.contact_id
338 , p_rec.invoice_contact );
339 end if;
340 --
341 End if;
342 --
343 If l_vendor_id_changed Then
344 --
345 ota_tfh_api_business_rules.check_vendor_contact
346 ( p_rec.vendor_id
347 , p_rec.contact_id );
348 --
349 ota_tfh_api_business_rules.check_vendor_address
350 ( p_rec.vendor_id
351 , p_rec.address_id );
352 --
353 Else
354 --
355 If l_address_id_changed Then
356 --
357 ota_tfh_api_business_rules.check_vendor_address
358 ( p_rec.vendor_id
359 , p_rec.address_id );
360 --
361 End if;
362 --
363 If l_contact_id_changed Then
364 --
365 ota_tfh_api_business_rules.check_vendor_contact
366 ( p_rec.vendor_id
367 , p_rec.contact_id );
368 --
369 End if;
370 --
371 End if;
372 --
373 If l_type_changed OR
374 l_supercedes_header_id_changed Then
375 --
376 ota_tfh_api_business_rules.check_superseded_header
377 ( p_rec.type
378 , p_rec.superceding_header_id );
379 --
380 End if;
381 --
382 If l_payment_method_changed Then
383 --
384 ota_tfh_api_business_rules.check_payment_method
385 ( p_rec.payment_method );
386 --
387 End if;
388 --
389 If p_rec.type <> 'CT' Then
390 If l_transfer_status_changed OR
391 l_payment_method_changed Then
392 --
393 ota_tfh_api_business_rules.check_allow_transfer
394 ( p_rec.transfer_status
395 , p_rec.payment_method );
396 End if;
397 --
398 End if;
399 --
400 If l_transfer_status_changed then
401 ota_tfh_api_business_rules.check_transfer_rules
402 (p_rec.transfer_status
403 ,ota_tfh_api_shd.g_old_rec.transfer_status);
404 End if;
405 --
406 If l_administrator_changed Then
407 --
408 ota_tfh_api_business_rules.check_administrator( p_rec.administrator );
409 --
410 End if;
411
412 --
413 --
414 --
415 hr_utility.set_location(' Leaving:'||l_proc, 10);
416 End update_validate;
417 --
418 -- ----------------------------------------------------------------------------
419 -- |---------------------------< delete_validate >----------------------------|
420 -- ----------------------------------------------------------------------------
421 Procedure delete_validate(p_rec in ota_tfh_api_shd.g_rec_type) is
422 --
423 l_proc varchar2(72) := g_package||'delete_validate';
424 --
425 Begin
426 hr_utility.set_location('Entering:'||l_proc, 5);
427 --
428 -- Call all supporting business operations
429 --
430 ota_tfh_api_business_rules.check_deletion( p_rec.finance_header_id);
431 --
432 hr_utility.set_location(' Leaving:'||l_proc, 10);
433 End delete_validate;
434 --
435 -- ---------------------------------------------------------------------------
436 -- |----------------------< set_security_group_id >--------------------------|
437 -- ---------------------------------------------------------------------------
438 --
439 Procedure set_security_group_id
440 (p_finance_header_id in number
441 ,p_associated_column1 in varchar2 default null
442 ) is
443 --
444 -- Declare cursor
445 --
446 cursor csr_sec_grp is
447 select pbg.security_group_id,
448 pbg.legislation_code
449 from per_business_groups_perf pbg,
450 ota_finance_headers tfh,
451 hr_all_organization_units org
452 where pbg.business_group_id = org.business_group_id
453 and org.organization_id = tfh.organization_id
454 and tfh.finance_header_id = p_finance_header_id;
455
456 --
457 -- Declare local variables
458 --
459 l_security_group_id number;
460 l_proc varchar2(72) := g_package||'set_security_group_id';
461 l_legislation_code varchar2(150);
462 --
463 begin
464 --
465 hr_utility.set_location('Entering:'|| l_proc, 10);
466 --
467 -- Ensure that all the mandatory parameter are not null
468 --
469 hr_api.mandatory_arg_error
470 (p_api_name => l_proc
471 ,p_argument => 'finance_header_id'
472 ,p_argument_value => p_finance_header_id
473 );
474 --
475 open csr_sec_grp;
476 fetch csr_sec_grp into l_security_group_id
477 , l_legislation_code;
478 --
479 if csr_sec_grp%notfound then
480 --
481 close csr_sec_grp;
482 --
483 -- The primary key is invalid therefore we must error
484 --
485 fnd_message.set_name('PAY','HR_7220_INVALID_PRIMARY_KEY');
486 hr_multi_message.add
487 (p_associated_column1
488 => nvl(p_associated_column1,'FINANCE_HEADER_ID')
489 );
490 --
491 else
492 close csr_sec_grp;
493 --
494 -- Set the security_group_id in CLIENT_INFO
495 --
496 hr_api.set_security_group_id
497 (p_security_group_id => l_security_group_id
498 );
499 --
500 -- Set the sessions legislation context in HR_SESSION_DATA
501 --
502 hr_api.set_legislation_context(l_legislation_code);
503 end if;
504 --
505 hr_utility.set_location(' Leaving:'|| l_proc, 20);
506 --
507 end set_security_group_id;
508
509 -- ----------------------------------------------------------------------------
510 -- |-----------------------< return_legislation_code >-------------------------|
511 -- ----------------------------------------------------------------------------
512 --
513 -- {Start Of Comments}
514 --
515 -- Description:
516 -- This function will be used by the user hooks. This will be used
517 -- of by the user hooks of ota_finance_header and
518 -- ota_finance_lines row handler user hook business process.
519 --
520 -- Pre Conditions:
521 -- This function will be called by the user hook packages.
522 --
523 -- In Arguments:
524 -- p_finance_header_id
525 --
526 -- Post Success:
527 -- Processing continues.
528 --
529 -- Post Failure:
530 -- Errors out
531 --
532 -- Developer Implementation Notes:
533 --
534 -- Access Status:
535 -- Internal Development Use Only.
536 --
537 -- {End Of Comments}
538 --------------------------------------------------------------------------------
539 --
540 Function return_legislation_code
541 ( p_finance_header_id in number
542 ) return varchar2 is
543 --
544 -- Declare cursor
545 --
546 cursor csr_leg_code is
547 select legislation_code
548 from per_business_groups_perf pbg,
549 ota_finance_headers tfh,
550 hr_all_organization_units org
551 where pbg.business_group_id = org.business_group_id
552 and org.organization_id = tfh.organization_id
553 and tfh.finance_header_id = p_finance_header_id;
554
555
556 l_proc varchar2(72) := g_package||'return_legislation_code';
557 l_legislation_code varchar2(150);
558 --
559 Begin
560 hr_utility.set_location('Entering:'||l_proc, 5);
561 --
562 -- Ensure that all the mandatory parameters are not null
563 --
564 hr_api.mandatory_arg_error (p_api_name => l_proc,
565 p_argument => 'finance_header_id',
566 p_argument_value => p_finance_header_id);
567 open csr_leg_code;
568 fetch csr_leg_code into l_legislation_code;
569 if csr_leg_code%notfound then
570 close csr_leg_code;
571 --
572 -- The primary key is invalid therefore we must error out
573 --
574 hr_utility.set_message(801, 'HR_7220_INVALID_PRIMARY_KEY');
575 hr_utility.raise_error;
576 end if;
577 --
578 close csr_leg_code;
579 return l_legislation_code;
580 --
581 hr_utility.set_location(' Leaving:'||l_proc, 10);
582 --
583 End return_legislation_code;
584
585
586
587 end ota_tfh_api_bus;