1 Package Body pay_txr_ins as
2 /* $Header: pytxrrhi.pkb 120.0 2005/05/29 09:09 appldev noship $ */
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 --
229 l_proc varchar2(72) := g_package||'pre_insert';
230 l_exists varchar2(1);
231 ln_rules_nextval pay_taxability_rules_dates.taxability_rules_date_id%TYPE;
232 --
233 Begin
234 hr_utility.set_location('Entering:'||l_proc, 5);
235 --
236 If (pay_txr_ins.g_jurisdiction_code_i is not null or
237 pay_txr_ins.g_tax_type_i is not null or
238 pay_txr_ins.g_tax_category_i is not null or
239 pay_txr_ins.g_classification_id_i is not null or
240 pay_txr_ins.g_taxability_rules_date_id_i is not null or
241 pay_txr_ins.g_secondary_class_id_i is not null) Then
242 --
243 -- Verify registered primary key values not already in use
244 --
245 Open C_Sel2;
246 Fetch C_Sel2 into l_exists;
247 If C_Sel2%found Then
248 Close C_Sel2;
249 --
250 -- The primary key values are already in use.
251 --
252 fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
253 fnd_message.set_token('TABLE_NAME','pay_taxability_rules');
254 fnd_message.raise_error;
255 End If;
256 Close C_Sel2;
257 --
258 -- Use registered key values and clear globals
259 --
260 p_rec.jurisdiction_code :=
261 pay_txr_ins.g_jurisdiction_code_i;
262 pay_txr_ins.g_jurisdiction_code_i := null;
263
264 p_rec.tax_type :=
265 pay_txr_ins.g_tax_type_i;
266 pay_txr_ins.g_tax_type_i := null;
267
268 p_rec.tax_category :=
269 pay_txr_ins.g_tax_category_i;
270 pay_txr_ins.g_tax_category_i := null;
271
272 p_rec.classification_id :=
273 pay_txr_ins.g_classification_id_i;
274 pay_txr_ins.g_classification_id_i := null;
275
276 p_rec.taxability_rules_date_id :=
277 pay_txr_ins.g_taxability_rules_date_id_i;
278 pay_txr_ins.g_taxability_rules_date_id_i := null;
279
280 p_rec.secondary_classification_id :=
281 pay_txr_ins.g_secondary_class_id_i;
282 pay_txr_ins.g_secondary_class_id_i := null;
283
284 Else
285 --
286 -- No registerd key values, so select the next sequence number
287 --
288 --
289 -- Select the next sequence number
290 --
291 Open C_Sel1;
292 Fetch C_Sel1 Into p_rec.taxability_rules_date_id;
293
294 IF C_Sel1%NOTFOUND THEN
295
296 --There is no record available for this legislation code in the PAY_TAXABILITY_RULES_DATES.
297 --So create a record there.
298
299 select PAY_TAXABILITY_RULES_DATES_S.nextval
300 into ln_rules_nextval
301 from sys.dual;
302
303 insert into pay_taxability_rules_dates
304 (taxability_rules_date_id, valid_date_from, valid_date_to,
305 legislation_code
306 --last_update_date, last_updated_by, last_update_login, created_by, creation_date, object_version_number
307 ) values
308 (ln_rules_nextval,
309 to_date('0001/01/01', 'YYYY/MM/DD HH24:MI:SS'),
310 to_date('4712/12/31', 'YYYY/MM/DD HH24:MI:SS'),
311 p_rec.legislation_code
312 -- to_date(:last_update_date, 'YYYY/MM/DD HH24:MI:SS'),
313 -- ln_last_updated_by, ln_last_updated_by, ln_last_updated_by,
314 -- to_date(:last_update_date, 'YYYY/MM/DD HH24:MI:SS'), ln_object_version_number
315 );
316 p_rec.taxability_rules_date_id := ln_rules_nextval;
317
318 END IF;
319
320 Close C_Sel1;
321 End If;
322 --
323 hr_utility.set_location(' Leaving:'||l_proc, 10);
324 End pre_insert;
325 --
326 -- ----------------------------------------------------------------------------
327 -- |-----------------------------< post_insert >------------------------------|
328 -- ----------------------------------------------------------------------------
329 -- {Start Of Comments}
330 --
331 -- Description:
332 -- This private procedure contains any processing which is required after
333 -- the insert dml.
334 --
335 -- Prerequisites:
336 -- This is an internal procedure which is called from the ins procedure.
337 --
338 -- In Parameters:
339 -- A Pl/Sql record structre.
340 --
341 -- Post Success:
342 -- Processing continues.
343 --
344 -- Post Failure:
345 -- If an error has occurred, an error message and exception will be raised
346 -- but not handled.
347 --
348 -- Developer Implementation Notes:
349 -- Any post-processing required after the insert dml is issued should be
350 -- coded within this procedure. It is important to note that any 3rd party
351 -- maintenance should be reviewed before placing in this procedure.
352 --
353 -- Access Status:
354 -- Internal Row Handler Use Only.
355 --
356 -- {End Of Comments}
357 -- ----------------------------------------------------------------------------
358 Procedure post_insert
359 (p_effective_date in date
360 ,p_rec in pay_txr_shd.g_rec_type
361 ) is
362 --
363 l_proc varchar2(72) := g_package||'post_insert';
364 --
365 Begin
366 hr_utility.set_location('Entering:'||l_proc, 5);
367 begin
368 --
369 pay_txr_rki.after_insert
370 (p_effective_date => p_effective_date
371 ,p_jurisdiction_code
372 => p_rec.jurisdiction_code
373 ,p_tax_type
374 => p_rec.tax_type
375 ,p_tax_category
376 => p_rec.tax_category
377 ,p_classification_id
378 => p_rec.classification_id
379 ,p_taxability_rules_date_id
380 => p_rec.taxability_rules_date_id
381 ,p_legislation_code
382 => p_rec.legislation_code
383 ,p_status
384 => p_rec.status
385 ,p_secondary_classification_id
386 => p_rec.secondary_classification_id
387 );
388 --
389 exception
390 --
391 when hr_api.cannot_find_prog_unit then
392 --
393 hr_api.cannot_find_prog_unit_error
394 (p_module_name => 'PAY_TAXABILITY_RULES'
395 ,p_hook_type => 'AI');
396 --
397 end;
398 --
399 hr_utility.set_location(' Leaving:'||l_proc, 10);
400 End post_insert;
401 --
402 -- ----------------------------------------------------------------------------
403 -- |---------------------------------< ins >----------------------------------|
404 -- ----------------------------------------------------------------------------
405 Procedure ins
406 (p_effective_date in date
407 ,p_rec in out nocopy pay_txr_shd.g_rec_type
408 ) is
409 --
410 l_proc varchar2(72) := g_package||'ins';
411 --
412 Begin
413 hr_utility.set_location('Entering:'||l_proc, 5);
414 --
415 -- Call the supporting insert validate operations
416 --
417 pay_txr_bus.insert_validate
418 (p_effective_date
419 ,p_rec
420 );
421 --
422 -- Call to raise any errors on multi-message list
423 hr_multi_message.end_validation_set;
424 --
425 -- Call the supporting pre-insert operation
426 --
427 pay_txr_ins.pre_insert(p_rec);
428 --
429 -- Insert the row
430 --
431 pay_txr_ins.insert_dml(p_rec);
432 --
433 -- Call the supporting post-insert operation
434 --
435 pay_txr_ins.post_insert
436 (p_effective_date
437 ,p_rec
438 );
439 --
440 -- Call to raise any errors on multi-message list
441 hr_multi_message.end_validation_set;
442 --
443 hr_utility.set_location('Leaving:'||l_proc, 20);
444 end ins;
445 --
446 -- ----------------------------------------------------------------------------
447 -- |---------------------------------< ins >----------------------------------|
448 -- ----------------------------------------------------------------------------
449 Procedure ins
450 (p_effective_date in date
451 ,p_legislation_code in varchar2
452 ,p_status in varchar2 default null
453 ,p_jurisdiction_code in varchar2
454 ,p_tax_type in varchar2 default null
455 ,p_tax_category in varchar2 default null
456 ,p_classification_id in number default null
457 ,p_taxability_rules_date_id in number
458 ,p_secondary_classification_id in number default null
459 ) is
460 --
461 l_rec pay_txr_shd.g_rec_type;
462 l_proc varchar2(72) := g_package||'ins';
463 --
464 Begin
465 hr_utility.set_location('Entering:'||l_proc, 5);
466 hr_utility.trace('In Procedure ins');
467 --
468 -- Call conversion function to turn arguments into the
469 -- p_rec structure.
470 --
471 hr_utility.trace('Before calling pay_txr_shd.convert_args ');
472 l_rec :=
473 pay_txr_shd.convert_args
474 (p_jurisdiction_code
475 ,p_tax_type
476 ,p_tax_category
477 ,p_classification_id
478 ,p_taxability_rules_date_id
479 ,p_legislation_code
480 ,p_status
481 ,p_secondary_classification_id
482 );
483 --
484 hr_utility.trace('After calling pay_txr_shd.convert_args ');
485 -- Having converted the arguments into the pay_txr_rec
486 -- plsql record structure we call the corresponding record business process.
487 --
488 hr_utility.trace('Before calling pay_txr_ins.ins ');
489 pay_txr_ins.ins
490 (p_effective_date
491 ,l_rec
492 );
493 --
494 --
495 hr_utility.set_location(' Leaving:'||l_proc, 10);
496 End ins;
497 --
498 end pay_txr_ins;