[Home] [Help]
PACKAGE BODY: APPS.PAY_BALANCE_ADJUSTMENT_API
Source
1 package body pay_balance_adjustment_api as
2 /* $Header: pybadapi.pkb 120.0 2005/05/29 03:13:50 appldev noship $ */
3 /*
4 NOTES
5 */
6
7 /*---------------------------------------------------------------------------*/
8 /*-------------------------- constant definitions ---------------------------*/
9 /*---------------------------------------------------------------------------*/
10
11 /*---------------------------------------------------------------------------*/
12 /*------------------------ balance adjustment types -------------------------*/
13 /*---------------------------------------------------------------------------*/
14
15 /*---------------------------------------------------------------------------*/
16 /*----------------------- balance adjustment globals ------------------------*/
17 /*---------------------------------------------------------------------------*/
18 g_package varchar2(33) := ' pay_balance_adjustment_api.';
19
20 /*---------------------------------------------------------------------------*/
21 /*--------------------- local functions and procedures ----------------------*/
22 /*---------------------------------------------------------------------------*/
23
24 /*---------------------------------------------------------------------------*/
25 /*------------------ global functions and procedures ------------------------*/
26 /*---------------------------------------------------------------------------*/
27
28 ------------------------------ create_adjustment ------------------------------
29 /*
30 NAME
31 create_adjustment
32 DESCRIPTION
33 Performs a single balance adjustment.
34 NOTES
35 <none>
36 */
37
38 procedure create_adjustment
39 (
40 p_validate in boolean default false,
41 p_effective_date in date,
42 p_assignment_id in number,
43 p_consolidation_set_id in number,
44 p_element_link_id in number,
45 p_input_value_id1 in number default null,
46 p_input_value_id2 in number default null,
47 p_input_value_id3 in number default null,
48 p_input_value_id4 in number default null,
49 p_input_value_id5 in number default null,
50 p_input_value_id6 in number default null,
51 p_input_value_id7 in number default null,
52 p_input_value_id8 in number default null,
53 p_input_value_id9 in number default null,
54 p_input_value_id10 in number default null,
55 p_input_value_id11 in number default null,
56 p_input_value_id12 in number default null,
57 p_input_value_id13 in number default null,
58 p_input_value_id14 in number default null,
59 p_input_value_id15 in number default null,
60 p_entry_value1 in varchar2 default null,
61 p_entry_value2 in varchar2 default null,
62 p_entry_value3 in varchar2 default null,
63 p_entry_value4 in varchar2 default null,
64 p_entry_value5 in varchar2 default null,
65 p_entry_value6 in varchar2 default null,
66 p_entry_value7 in varchar2 default null,
67 p_entry_value8 in varchar2 default null,
68 p_entry_value9 in varchar2 default null,
69 p_entry_value10 in varchar2 default null,
70 p_entry_value11 in varchar2 default null,
71 p_entry_value12 in varchar2 default null,
72 p_entry_value13 in varchar2 default null,
73 p_entry_value14 in varchar2 default null,
74 p_entry_value15 in varchar2 default null,
75 p_prepay_flag in varchar2 default null,
76
77 -- Costing information.
78 p_balance_adj_cost_flag in varchar2 default null,
79 p_cost_allocation_keyflex_id in number default null,
80 p_attribute_category in varchar2 default null,
81 p_attribute1 in varchar2 default null,
82 p_attribute2 in varchar2 default null,
83 p_attribute3 in varchar2 default null,
84 p_attribute4 in varchar2 default null,
85 p_attribute5 in varchar2 default null,
86 p_attribute6 in varchar2 default null,
87 p_attribute7 in varchar2 default null,
88 p_attribute8 in varchar2 default null,
89 p_attribute9 in varchar2 default null,
90 p_attribute10 in varchar2 default null,
91 p_attribute11 in varchar2 default null,
92 p_attribute12 in varchar2 default null,
93 p_attribute13 in varchar2 default null,
94 p_attribute14 in varchar2 default null,
95 p_attribute15 in varchar2 default null,
96 p_attribute16 in varchar2 default null,
97 p_attribute17 in varchar2 default null,
98 p_attribute18 in varchar2 default null,
99 p_attribute19 in varchar2 default null,
100 p_attribute20 in varchar2 default null,
101
102 p_run_type_id in number default null,
103 p_original_entry_id in number default null,
104
105 -- Element entry information.
106 p_element_entry_id out nocopy number,
107 p_effective_start_date out nocopy date,
108 p_effective_end_date out nocopy date,
109 p_object_version_number out nocopy number,
110 p_create_warning out nocopy boolean
111 ) is
112 l_payroll_id number;
113 l_time_period_id number;
114 l_payroll_action_id number;
115 l_assignment_action_id number;
116 l_business_group_id number;
117 l_element_entry_id number;
118 l_effective_start_date date;
119 l_effective_end_date date;
120 l_object_version_number number;
121 l_create_warning boolean;
122 l_proc varchar2(72) := g_package ||'create_adjustment';
123 begin
124 hr_utility.set_location('Entering:'|| l_proc, 5);
125
126 savepoint create_adjustment;
127
128 -- Obtain information based on the assignment.
129 -- Also get the new payroll_action_id and
130 -- time period information.
131 hr_utility.set_location(l_proc, 20);
132 select asg.business_group_id,
133 asg.payroll_id,
134 ptp.time_period_id,
135 pay_payroll_actions_s.nextval
136 into l_business_group_id,
137 l_payroll_id,
138 l_time_period_id,
139 l_payroll_action_id
140 from per_assignments_f asg,
141 per_time_periods ptp
142 where asg.assignment_id = p_assignment_id
143 and p_effective_date between
144 asg.effective_start_date and asg.effective_end_date
145 and ptp.payroll_id = asg.payroll_id
146 and p_effective_date between
147 ptp.start_date and ptp.end_date;
148
149 -- The balance adjustment element entry.
150 py_element_entry_api.create_element_entry (
151 p_effective_date => p_effective_date,
152 p_business_group_id => l_business_group_id,
153 p_original_entry_id => p_original_entry_id,
154 p_assignment_id => p_assignment_id,
155 p_element_link_id => p_element_link_id,
156 p_entry_type => 'B', -- Balance Adjustment entry.
157 p_creator_type => 'B',
158 p_input_value_id1 => p_input_value_id1,
159 p_input_value_id2 => p_input_value_id2,
160 p_input_value_id3 => p_input_value_id3,
161 p_input_value_id4 => p_input_value_id4,
162 p_input_value_id5 => p_input_value_id5,
163 p_input_value_id6 => p_input_value_id6,
164 p_input_value_id7 => p_input_value_id7,
165 p_input_value_id8 => p_input_value_id8,
166 p_input_value_id9 => p_input_value_id9,
167 p_input_value_id10 => p_input_value_id10,
168 p_input_value_id11 => p_input_value_id11,
169 p_input_value_id12 => p_input_value_id12,
170 p_input_value_id13 => p_input_value_id13,
171 p_input_value_id14 => p_input_value_id14,
172 p_input_value_id15 => p_input_value_id15,
173 p_entry_value1 => p_entry_value1,
174 p_entry_value2 => p_entry_value2,
175 p_entry_value3 => p_entry_value3,
176 p_entry_value4 => p_entry_value4,
177 p_entry_value5 => p_entry_value5,
178 p_entry_value6 => p_entry_value6,
179 p_entry_value7 => p_entry_value7,
180 p_entry_value8 => p_entry_value8,
181 p_entry_value9 => p_entry_value9,
182 p_entry_value10 => p_entry_value10,
183 p_entry_value11 => p_entry_value11,
184 p_entry_value12 => p_entry_value12,
185 p_entry_value13 => p_entry_value13,
186 p_entry_value14 => p_entry_value14,
187 p_entry_value15 => p_entry_value15,
188
189 -- Costing information.
190 p_cost_allocation_keyflex_id => p_cost_allocation_keyflex_id,
191 p_attribute_category => p_attribute_category,
192 p_attribute1 => p_attribute1,
193 p_attribute2 => p_attribute2,
194 p_attribute3 => p_attribute3,
195 p_attribute4 => p_attribute4,
196 p_attribute5 => p_attribute5,
197 p_attribute6 => p_attribute6,
198 p_attribute7 => p_attribute7,
199 p_attribute8 => p_attribute8,
200 p_attribute9 => p_attribute9,
201 p_attribute10 => p_attribute10,
202 p_attribute11 => p_attribute11,
203 p_attribute12 => p_attribute12,
204 p_attribute13 => p_attribute13,
205 p_attribute14 => p_attribute14,
206 p_attribute15 => p_attribute15,
207 p_attribute16 => p_attribute16,
208 p_attribute17 => p_attribute17,
209 p_attribute18 => p_attribute18,
210 p_attribute19 => p_attribute19,
211 p_attribute20 => p_attribute20,
212 p_effective_start_date => l_effective_start_date,
213 p_effective_end_date => l_effective_end_date,
214 p_element_entry_id => l_element_entry_id,
215 p_object_version_number => l_object_version_number,
216 p_create_warning => l_create_warning
217 );
218
219 -- Deal with the creation of Payroll and Assignment
220 -- Action for the adjustment. We call the existing
221 -- routine to ensure that we get support for altering
222 -- latest balances and creation of Action Contexts.
223 hrassact.bal_adjust (consetid => p_consolidation_set_id,
224 eentryid => l_element_entry_id,
225 effdate => p_effective_date,
226 prepay_flag => p_prepay_flag,
227 run_type_id => p_run_type_id);
228
229 -- Perform an update to the entry.
230 -- Entry API doesn't support the bal_adjust_cost_flag.
231 -- and ensure that the creator_type is correct.
232 hr_utility.set_location(l_proc, 30);
233 update pay_element_entries_f pee
234 set pee.creator_type = 'B',
235 pee.balance_adj_cost_flag = p_balance_adj_cost_flag
236 where pee.element_entry_id = l_element_entry_id
237 and p_effective_date between
238 pee.effective_start_date and pee.effective_end_date;
239
240 --
241 -- Set remaining output arguments
242 --
243 p_element_entry_id := l_element_entry_id;
244 p_effective_start_date := l_effective_start_date;
245 p_effective_end_date := l_effective_end_date;
246 p_object_version_number := l_object_version_number;
247 p_create_warning := l_create_warning;
248
249 if(p_validate) then
250 raise hr_api.validate_enabled;
251 end if;
252
253 hr_utility.set_location(' Leaving:'||l_proc, 40);
254 exception
255 when hr_api.validate_enabled then
256 --
257 -- As the Validate_Enabled exception has been raised
258 -- we must rollback to the savepoint
259 --
260 ROLLBACK TO create_adjustment;
261 --
262 -- Only set output warning arguments
263 -- (Any key or derived arguments must be set to null
264 -- when validation only mode is being used.)
265 --
266 p_element_entry_id := null;
267 p_effective_start_date := null;
268 p_effective_end_date := null;
269 p_object_version_number := null;
270 p_create_warning := l_create_warning;
271
272 when others then
273 -- Unexpected error detected.
274 ROLLBACK TO create_adjustment;
275 raise;
276
277 end create_adjustment;
278
279 ------------------------------ delete_adjustment ------------------------------
280 /*
281 NAME
282 delete_adjustment
283 DESCRIPTION
284 Deletes an existing balance adjustment.
285 NOTES
286 <none>
287 */
288
289 procedure delete_adjustment
290 (
291 p_validate in boolean default false,
292 p_effective_date in date,
293 p_element_entry_id in number
294 ) is
295 l_payroll_action_id number;
296 l_assignment_action_id number;
297 l_dummy number;
298 l_proc varchar2(72) := g_package ||'delete_adjustment';
299 begin
300 hr_utility.set_location('Entering:'|| l_proc, 5);
301
302 savepoint delete_adjustment;
303
304 -- We know the element entry, but we need to know the payroll
305 -- action that we have to remove.
306 hr_utility.set_location(l_proc, 20);
307 select act.payroll_action_id
308 ,act.assignment_action_id
309 into l_payroll_action_id
310 ,l_assignment_action_id
311 from pay_payroll_actions ppa,
312 pay_assignment_actions act,
313 pay_element_entries_f pee
314 where pee.element_entry_id = p_element_entry_id
315 and pee.entry_type = 'B'
316 and p_effective_date between
317 pee.effective_start_date and pee.effective_end_date
318 and act.assignment_action_id = pee.creator_id
319 and ppa.payroll_action_id = act.payroll_action_id
320 and ppa.action_type = 'B'
321 ;
322
323 --
324 -- Ensure there are no other assignment actions nor run
325 -- results in this payroll action.
326 --
327 hr_utility.set_location(l_proc, 30);
328 begin
329
330 select 1 into l_dummy from dual
331 where
332 not exists
333 (select 1 from pay_assignment_actions paa
334 where paa.payroll_action_id = l_payroll_action_id
335 and paa.assignment_action_id <> l_assignment_action_id)
336 and not exists
337 (select 1 from pay_run_results prr
338 where prr.assignment_action_id = l_assignment_action_id
339 and not (nvl(prr.element_entry_id, prr.source_id) = p_element_entry_id
340 and prr.source_type = 'E'));
341
342 exception
343 when no_data_found then
344 fnd_message.set_name('PAY', 'HR_7296_API_ARG_NOT_SUP');
345 fnd_message.set_token('ARG_NAME', 'p_element_entry_id');
346 fnd_message.set_token('ARG_VALUE',to_char(p_element_entry_id));
347 fnd_message.raise_error;
348 end;
349
350 -- Make use of existing routine to remove this
351 -- balance adjustment.
352 py_rollback_pkg.rollback_payroll_action(l_payroll_action_id);
353
354 if(p_validate) then
355 raise hr_api.validate_enabled;
356 end if;
357
358 hr_utility.set_location(' Leaving:'||l_proc, 100);
359 exception
360 when hr_api.validate_enabled then
361 --
362 -- As the Validate_Enabled exception has been raised
363 -- we must rollback to the savepoint
364 --
365 ROLLBACK TO delete_adjustment;
366
367 when others then
368 -- Unexpected error detected.
369 ROLLBACK TO delete_adjustment;
370 raise;
371
372 end delete_adjustment;
373
374 end pay_balance_adjustment_api;