DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_TXR_INS

Source


1 Package Body pay_txr_ins as
2 /* $Header: pytxrrhi.pkb 120.2 2012/01/19 11:27:49 rpahune ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  pay_txr_ins.';  -- Global package name
9 --
10 -- The following global variables are only to be used by
11 -- the set_base_key_value and pre_insert procedures.
12 --
13 g_jurisdiction_code_i  number   default null;
14 g_tax_type_i  number   default null;
15 g_tax_category_i  number   default null;
16 g_classification_id_i  number   default null;
17 g_taxability_rules_date_id_i  number   default null;
18 g_secondary_class_id_i  number   default null;
19 --
20 -- ----------------------------------------------------------------------------
21 -- |------------------------< set_base_key_value >----------------------------|
22 -- ----------------------------------------------------------------------------
23 procedure set_base_key_value
24   (p_jurisdiction_code  in  number
25   ,p_tax_type  in  number
26   ,p_tax_category  in  number
27   ,p_classification_id  in  number
28   ,p_taxability_rules_date_id  in  number
29   ,p_secondary_classification_id  in  number) is
30 --
31   l_proc       varchar2(72) := g_package||'set_base_key_value';
32 --
33 Begin
34   hr_utility.set_location('Entering:'||l_proc, 10);
35   --
36   pay_txr_ins.g_jurisdiction_code_i := p_jurisdiction_code;
37   pay_txr_ins.g_tax_type_i := p_tax_type;
38   pay_txr_ins.g_tax_category_i := p_tax_category;
39   pay_txr_ins.g_classification_id_i := p_classification_id;
40   pay_txr_ins.g_taxability_rules_date_id_i := p_taxability_rules_date_id;
41   pay_txr_ins.g_secondary_class_id_i := p_secondary_classification_id;
42   --
43   hr_utility.set_location(' Leaving:'||l_proc, 20);
44 End set_base_key_value;
45 --
46 --
47 -- ----------------------------------------------------------------------------
48 -- |------------------------------< insert_dml >------------------------------|
49 -- ----------------------------------------------------------------------------
50 -- {Start Of Comments}
51 --
52 -- Description:
53 --   This procedure controls the actual dml insert logic. The processing of
54 --   this procedure are as follows:
55 --   1) Initialise the object_version_number to 1 if the object_version_number
56 --      is defined as an attribute for this entity.
57 --   2) To set and unset the g_api_dml status as required (as we are about to
58 --      perform dml).
59 --   3) To insert the row into the schema.
60 --   4) To trap any constraint violations that may have occurred.
61 --   5) To raise any other errors.
62 --
63 -- Prerequisites:
64 --   This is an internal private procedure which must be called from the ins
65 --   procedure and must have all mandatory attributes set (except the
66 --   object_version_number which is initialised within this procedure).
67 --
68 -- In Parameters:
69 --   A Pl/Sql record structre.
70 --
71 -- Post Success:
72 --   The specified row will be inserted into the schema.
73 --
74 -- Post Failure:
75 --   On the insert dml failure it is important to note that we always reset the
76 --   g_api_dml status to false.
77 --   If a check, unique or parent integrity constraint violation is raised the
78 --   constraint_error procedure will be called.
79 --   If any other error is reported, the error will be raised after the
80 --   g_api_dml status is reset.
81 --
82 -- Developer Implementation Notes:
83 --   None.
84 --
85 -- Access Status:
86 --   Internal Row Handler Use Only.
87 --
88 -- {End Of Comments}
89 -- ----------------------------------------------------------------------------
90 Procedure insert_dml
91   (p_rec in out nocopy pay_txr_shd.g_rec_type
92   ) is
93 --
94   l_proc  varchar2(72) := g_package||'insert_dml';
95 num number;
96 --
97 Begin
98   hr_utility.set_location('Entering:'||l_proc, 5);
99   --
100   --
101   --
102   --
103   -- Insert the row into: pay_taxability_rules
104   --
105   hr_utility.trace('p_rec.jurisdiction_code '||p_rec.jurisdiction_code);
106   hr_utility.trace('p_rec.tax_type '||p_rec.tax_type);
107   hr_utility.trace('p_rec.tax_category '||p_rec.tax_category);
108   hr_utility.trace('p_rec.classification_id '||to_char(p_rec.classification_id));
109   hr_utility.trace('p_rec.legislation_code '||p_rec.legislation_code);
110   hr_utility.trace('p_rec.status '||p_rec.status);
111   hr_utility.trace('p_rec.secondary_classification_id '||
112                     to_char(p_rec.secondary_classification_id));
113   insert into pay_taxability_rules
114       (jurisdiction_code
115       ,tax_type
116       ,tax_category
117       ,classification_id
118       ,taxability_rules_date_id
119       ,legislation_code
120       ,status
121       ,secondary_classification_id
122       )
123   Values
124     (p_rec.jurisdiction_code
125     ,p_rec.tax_type
126     ,p_rec.tax_category
127     ,p_rec.classification_id
128     ,p_rec.taxability_rules_date_id
129     ,p_rec.legislation_code
130     ,p_rec.status
131     ,p_rec.secondary_classification_id
132     );
133   --
134 select count(*)
135 into num
136 from pay_taxability_rules
137 where jurisdiction_code = p_rec.jurisdiction_code;
138   --
139   --
140   hr_utility.set_location(' Leaving:'||l_proc, 10);
141   hr_utility.set_location(' Num:'|| to_char(num), 20);
142 Exception
143   When hr_api.check_integrity_violated Then
144     -- A check constraint has been violated
145     --
146     pay_txr_shd.constraint_error
147       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
148   When hr_api.parent_integrity_violated Then
149     -- Parent integrity has been violated
150     --
151     pay_txr_shd.constraint_error
152       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
153   When hr_api.unique_integrity_violated Then
154     -- Unique integrity has been violated
155     --
156     pay_txr_shd.constraint_error
157       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
158   When Others Then
159     --
160    hr_utility.trace('Exception  in '||SQLERRM);
161     Raise;
162 End insert_dml;
163 --
164 -- ----------------------------------------------------------------------------
165 -- |------------------------------< pre_insert >------------------------------|
166 -- ----------------------------------------------------------------------------
167 -- {Start Of Comments}
168 --
169 -- Description:
170 --   This private procedure contains any processing which is required before
171 --   the insert dml. Presently, if the entity has a corresponding primary
172 --   key which is maintained by an associating sequence, the primary key for
173 --   the entity will be populated with the next sequence value in
174 --   preparation for the insert dml.
175 --
176 -- Prerequisites:
177 --   This is an internal procedure which is called from the ins procedure.
178 --
179 -- In Parameters:
180 --   A Pl/Sql record structure.
181 --
182 -- Post Success:
183 --   Processing continues.
184 --
185 -- Post Failure:
186 --   If an error has occurred, an error message and exception will be raised
187 --   but not handled.
188 --
189 -- Developer Implementation Notes:
190 --   Any pre-processing required before the insert dml is issued should be
191 --   coded within this procedure. As stated above, a good example is the
192 --   generation of a primary key number via a corresponding sequence.
193 --   It is important to note that any 3rd party maintenance should be reviewed
194 --   before placing in this procedure.
195 --
196 -- Access Status:
197 --   Internal Row Handler Use Only.
198 --
199 -- {End Of Comments}
200 -- ----------------------------------------------------------------------------
201 Procedure pre_insert
202   (p_rec  in out nocopy pay_txr_shd.g_rec_type
203   ) is
204 --
205   Cursor C_Sel1 is
206    select taxability_rules_date_id
207    from pay_taxability_rules_dates
208    where legislation_code = p_rec.legislation_code
209    and sysdate between valid_date_from and
210                        valid_date_to;
211 
212 --
213   Cursor C_Sel2 is
214     Select null
215       from pay_taxability_rules
216      where jurisdiction_code =
217              pay_txr_ins.g_jurisdiction_code_i
218         or tax_type =
219              pay_txr_ins.g_tax_type_i
220         or tax_category =
221              pay_txr_ins.g_tax_category_i
222         or classification_id =
223              pay_txr_ins.g_classification_id_i
224         or secondary_classification_id =
225              pay_txr_ins.g_secondary_class_id_i
226         or taxability_rules_date_id =
227              pay_txr_ins.g_taxability_rules_date_id_i;
228 -- Bug 11894789
229   Cursor c_ele_class_validation is
230      Select null
231        from pay_element_classifications
232       where classification_id = p_rec.classification_id;
233 -- Bug 11894789
234    Cursor c_sec_ele_class_validation is
235      Select null
236        from pay_element_classifications
237       where classification_id = p_rec.secondary_classification_id;
238 --
239   l_proc   varchar2(72) := g_package||'pre_insert';
240   l_exists varchar2(1);
241   l_ele_class_exists varchar2(1);
242   l_sec_ele_class_exists varchar2(1);
243   ln_rules_nextval pay_taxability_rules_dates.taxability_rules_date_id%TYPE;
244 --
245 Begin
246   hr_utility.set_location('Entering:'||l_proc, 5);
247   --
248   -- Bug 11894789
249   --
250   IF substr(fnd_release.release_name,1,2) = '12' and substr(fnd_release.release_name,4,1) >= '2' THEN
251 
252 hr_utility.trace('Before Ele Class Validation ');
253 
254     Open c_ele_class_validation;
255     Fetch c_ele_class_validation into l_ele_class_exists;
256     If c_ele_class_validation%notfound Then
257        Close c_ele_class_validation;
258        --
259        -- The element classification was not found.
260        --
261        if p_rec.legislation_code = 'US' THEN
262        fnd_message.set_name('PER','HR_75272_INV_ELE_CLASS');
263        fnd_message.raise_error;
264        elsif p_rec.legislation_code = 'CA' THEN
265        fnd_message.set_name('PER','HR_74028_INV_ELE_CLASS');
266        fnd_message.raise_error;
267        end if;
268     End If;
269     Close c_ele_class_validation;
270 
271 IF p_rec.secondary_classification_id IS NOT NULL THEN
272 
273 	hr_utility.trace('Before Sec Ele Class Validation ');
274 
275     Open c_sec_ele_class_validation;
276     Fetch c_sec_ele_class_validation into l_sec_ele_class_exists;
277     If c_sec_ele_class_validation%notfound Then
278        Close c_sec_ele_class_validation;
279        --
280        -- The secondary element classification was not found.
281        --
282        if p_rec.legislation_code = 'US' THEN
283        fnd_message.set_name('PER','HR_75272_INV_ELE_CLASS');
284        fnd_message.raise_error;
285        elsif p_rec.legislation_code = 'CA' THEN
286        fnd_message.set_name('PER','HR_74028_INV_ELE_CLASS');
287        fnd_message.raise_error;
288        end if;
289     End If;
290     Close c_sec_ele_class_validation;
291 END IF;
292 END IF; -- End of Bug 11894789
293   If (pay_txr_ins.g_jurisdiction_code_i is not null or
294       pay_txr_ins.g_tax_type_i is not null or
295       pay_txr_ins.g_tax_category_i is not null or
296       pay_txr_ins.g_classification_id_i is not null or
297       pay_txr_ins.g_taxability_rules_date_id_i is not null or
298       pay_txr_ins.g_secondary_class_id_i is not null) Then
299     --
300     -- Verify registered primary key values not already in use
301     --
302     Open C_Sel2;
303     Fetch C_Sel2 into l_exists;
304     If C_Sel2%found Then
305        Close C_Sel2;
306        --
307        -- The primary key values are already in use.
308        --
309        fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
310        fnd_message.set_token('TABLE_NAME','pay_taxability_rules');
311        fnd_message.raise_error;
312     End If;
313     Close C_Sel2;
314     --
315     -- Use registered key values and clear globals
316     --
317     p_rec.jurisdiction_code :=
318       pay_txr_ins.g_jurisdiction_code_i;
319     pay_txr_ins.g_jurisdiction_code_i := null;
320 
321     p_rec.tax_type :=
322       pay_txr_ins.g_tax_type_i;
323     pay_txr_ins.g_tax_type_i := null;
324 
325     p_rec.tax_category :=
326       pay_txr_ins.g_tax_category_i;
327     pay_txr_ins.g_tax_category_i := null;
328 
329     p_rec.classification_id :=
330       pay_txr_ins.g_classification_id_i;
331     pay_txr_ins.g_classification_id_i := null;
332 
333     p_rec.taxability_rules_date_id :=
334       pay_txr_ins.g_taxability_rules_date_id_i;
335     pay_txr_ins.g_taxability_rules_date_id_i := null;
336 
337     p_rec.secondary_classification_id :=
338       pay_txr_ins.g_secondary_class_id_i;
339     pay_txr_ins.g_secondary_class_id_i := null;
340 
341   Else
342     --
343     -- No registerd key values, so select the next sequence number
344     --
345     --
346     -- Select the next sequence number
347     --
348     Open C_Sel1;
349     Fetch C_Sel1 Into p_rec.taxability_rules_date_id;
350 
351     IF C_Sel1%NOTFOUND THEN
352 
353        --There is no record available for this legislation code in the PAY_TAXABILITY_RULES_DATES.
354        --So create a record there.
355 
356        select PAY_TAXABILITY_RULES_DATES_S.nextval
357        into ln_rules_nextval
358        from sys.dual;
359 
360        insert into pay_taxability_rules_dates
361        (taxability_rules_date_id, valid_date_from, valid_date_to,
362        legislation_code
363        --last_update_date, last_updated_by, last_update_login, created_by, creation_date, object_version_number
364        ) values
365       (ln_rules_nextval,
366        to_date('0001/01/01', 'YYYY/MM/DD HH24:MI:SS'),
367        to_date('4712/12/31', 'YYYY/MM/DD HH24:MI:SS'),
368        p_rec.legislation_code
369     --   to_date(:last_update_date, 'YYYY/MM/DD HH24:MI:SS'),
370    --    ln_last_updated_by, ln_last_updated_by, ln_last_updated_by,
371    --    to_date(:last_update_date, 'YYYY/MM/DD HH24:MI:SS'), ln_object_version_number
372        );
373        p_rec.taxability_rules_date_id := ln_rules_nextval;
374 
375     END IF;
376 
377     Close C_Sel1;
378   End If;
379   --
380   hr_utility.set_location(' Leaving:'||l_proc, 10);
381 End pre_insert;
382 --
383 -- ----------------------------------------------------------------------------
384 -- |-----------------------------< post_insert >------------------------------|
385 -- ----------------------------------------------------------------------------
386 -- {Start Of Comments}
387 --
388 -- Description:
389 --   This private procedure contains any processing which is required after
390 --   the insert dml.
391 --
392 -- Prerequisites:
393 --   This is an internal procedure which is called from the ins procedure.
394 --
395 -- In Parameters:
396 --   A Pl/Sql record structre.
397 --
398 -- Post Success:
399 --   Processing continues.
400 --
401 -- Post Failure:
402 --   If an error has occurred, an error message and exception will be raised
403 --   but not handled.
404 --
405 -- Developer Implementation Notes:
406 --   Any post-processing required after the insert dml is issued should be
407 --   coded within this procedure. It is important to note that any 3rd party
408 --   maintenance should be reviewed before placing in this procedure.
409 --
410 -- Access Status:
411 --   Internal Row Handler Use Only.
412 --
413 -- {End Of Comments}
414 -- ----------------------------------------------------------------------------
415 Procedure post_insert
416   (p_effective_date               in date
417   ,p_rec                          in pay_txr_shd.g_rec_type
418   ) is
419 --
420   l_proc  varchar2(72) := g_package||'post_insert';
421 --
422 Begin
423   hr_utility.set_location('Entering:'||l_proc, 5);
424   begin
425     --
426     pay_txr_rki.after_insert
427       (p_effective_date              => p_effective_date
428       ,p_jurisdiction_code
429       => p_rec.jurisdiction_code
430       ,p_tax_type
431       => p_rec.tax_type
432       ,p_tax_category
433       => p_rec.tax_category
434       ,p_classification_id
435       => p_rec.classification_id
436       ,p_taxability_rules_date_id
437       => p_rec.taxability_rules_date_id
438       ,p_legislation_code
439       => p_rec.legislation_code
440       ,p_status
441       => p_rec.status
442       ,p_secondary_classification_id
443       => p_rec.secondary_classification_id
444       );
445     --
446   exception
447     --
448     when hr_api.cannot_find_prog_unit then
449       --
450       hr_api.cannot_find_prog_unit_error
451         (p_module_name => 'PAY_TAXABILITY_RULES'
452         ,p_hook_type   => 'AI');
453       --
454   end;
455   --
456   hr_utility.set_location(' Leaving:'||l_proc, 10);
457 End post_insert;
458 --
459 -- ----------------------------------------------------------------------------
460 -- |---------------------------------< ins >----------------------------------|
461 -- ----------------------------------------------------------------------------
462 Procedure ins
463   (p_effective_date               in date
464   ,p_rec                          in out nocopy pay_txr_shd.g_rec_type
465   ) is
466 --
467   l_proc  varchar2(72) := g_package||'ins';
468 --
469 Begin
470   hr_utility.set_location('Entering:'||l_proc, 5);
471   --
472   -- Call the supporting insert validate operations
473   --
474   pay_txr_bus.insert_validate
475      (p_effective_date
476      ,p_rec
477      );
478   --
479   -- Call to raise any errors on multi-message list
480   hr_multi_message.end_validation_set;
481   --
482   -- Call the supporting pre-insert operation
483   --
484   pay_txr_ins.pre_insert(p_rec);
485   --
486   -- Insert the row
487   --
488   pay_txr_ins.insert_dml(p_rec);
489   --
490   -- Call the supporting post-insert operation
491   --
492   pay_txr_ins.post_insert
493      (p_effective_date
494      ,p_rec
495      );
496   --
497   -- Call to raise any errors on multi-message list
498   hr_multi_message.end_validation_set;
499   --
500   hr_utility.set_location('Leaving:'||l_proc, 20);
501 end ins;
502 --
503 -- ----------------------------------------------------------------------------
504 -- |---------------------------------< ins >----------------------------------|
505 -- ----------------------------------------------------------------------------
506 Procedure ins
507   (p_effective_date               in     date
508   ,p_legislation_code             in     varchar2
509   ,p_status                       in     varchar2 default null
510   ,p_jurisdiction_code            in     varchar2
511   ,p_tax_type                     in     varchar2 default null
512   ,p_tax_category                 in     varchar2 default null
513   ,p_classification_id            in     number   default null
514   ,p_taxability_rules_date_id     in     number
515   ,p_secondary_classification_id  in     number   default null
516   ) is
517 --
518   l_rec   pay_txr_shd.g_rec_type;
519   l_proc  varchar2(72) := g_package||'ins';
520 --
521 Begin
522   hr_utility.set_location('Entering:'||l_proc, 5);
523    hr_utility.trace('In Procedure ins');
524   --
525   -- Call conversion function to turn arguments into the
526   -- p_rec structure.
527   --
528    hr_utility.trace('Before calling pay_txr_shd.convert_args ');
529   l_rec :=
530   pay_txr_shd.convert_args
531     (p_jurisdiction_code
532     ,p_tax_type
533     ,p_tax_category
534     ,p_classification_id
535     ,p_taxability_rules_date_id
536     ,p_legislation_code
537     ,p_status
538     ,p_secondary_classification_id
539     );
540   --
541    hr_utility.trace('After calling pay_txr_shd.convert_args ');
542   -- Having converted the arguments into the pay_txr_rec
543   -- plsql record structure we call the corresponding record business process.
544   --
545    hr_utility.trace('Before calling pay_txr_ins.ins ');
546   pay_txr_ins.ins
547      (p_effective_date
548      ,l_rec
549      );
550   --
551   --
552   hr_utility.set_location(' Leaving:'||l_proc, 10);
553 End ins;
554 --
555 end pay_txr_ins;