1 package body hrassact as
2 /* $Header: pyassact.pkb 120.43.12020000.12 2012/11/09 11:35:24 asnell ship $ */
3 /*
4 Copyright (c) Oracle Corporation 1991,1992,1993. All rights reserved
5 --
6 /*
7 --
8 Name : hrassact
9 Author : $Author: asnell $
10 Synopsis : Payroll and Assignment action processing.
11 Contents : applied_interlocks
12 bal_adjust
13 bal_adjust_actions
14 del_latest_balances
15 do_assact_rollback
16 do_pact_rollback
17 ensure_assact_rolled_back
18 ensure_pact_rolled_back
19 ext_man_payment
20 inassact
21 inassact_main
22 irbaact
23 reversal
24 rollback_ass_action
25 rollback_payroll_action
26 trash_latest_balances
27 trash_latest_balances
28 trash_quickpay
29 undo_stop_update
30 val_assact_rollback
31 val_pact_rollback
32 validate_rollback_mode
33 --
34 Change List
35 -----------
36 Date Name Vers Bug No Description
37 -----------+-------------+-------+----------+-------------------------------+
38 09-NOV-2012 asnell 115.164 14695457 Backed out changes in .163 by re-instating .162
39 19-JUL-2012 kskoduri 115.162 13369815 Modified code to allow insertion of dummy quickpay via
40 ins_dummy_quickpay_action api the code for normal quickpay
41 is unchanged
42 12-Jun-2012 vmaripal 115.160 13340377 Modified hint in seqper cursor in
43 irbaact. Removed ORDERED
44 08-Jun-2012 ranarra 115.159 14118551 Modified function get_retry_reversal_aciton_id,
45 fixed a regression in version 115.154 and
46 reverted the change made in 115.155.
47 29-May-2012 asnell 115.156 13541539 seqper coded for POG
48 19-Apr-2012 pparate 115.155 13963282 temporarily fixed masking for 25digit result.
49 this change would be reverted in next version.
50 22-Mar-2012 asnell 115.154 13870488 re-instate hints on seqper
51 10-Nov-2011 pparate 115.153 13359813 For reversal changed masking from 21digits 38decimals to
52 23digits 36decimals as result value for customer exceeded
53 21digits before decimal.
54 16-Jun-2011 vpallapo 115.152 12356133 Performance fix, added hints to force indexes and avoid full table scans
55 while inserting into pay_assignment_actions.
56 22-Nov-2010 priupadh 115.151 10212578 Modified maintain_lat_bal now calling pay_core_utils.get_legislation_rule
57 for leg rule 'BAL_ADJ_LAT_BAL'
58 22-Apr-2010 phattarg 115.150 9089219 Removed ORDERED hint from cursor albc_selective
59 in hrassact.del_latest_balances.
60 21-Apr-2010 phattarg 115.149 8994425 Corrected the behavior of trash_latest_balances procedure
61 when pap 'LAT_BAL_CHECK_MODE' is set to B..
62 19-Apr-2010 phattarg 115.148 9558506 Performance fix to 'seqper' cursor in
63 hrassact.resequence_actions.
64 03-Jun-2009 priupadh 115.147 8570075 Modified trash_latest_balances,removed "close ivchk"
65 inside if condition as it was closing twice ivchk.
66 14-Apr-2009 priupadh 115.146 7652030 Removed checkfile in dbdrv.
67 14-Apr-2009 priupadh 115.145 7652030 Modified multi_assignment_reversal
68 now calling create_all_group_balances
69 after last assignment reversal.
70 21-Nov-2008 ubhat 115.144 7584883 Divided locking code for
71 per_all_assignment_f and
72 per_periods_of_service.
73 10-Oct-2008 salogana 115.143 7371362 Added bulk delete in
74 trash_latest_balances FOR
75 pay_assignment_latest_balances
76 05-Aug-2008 salogana 115.142 6595092 Added bulk delete code in
77 trash_latest_balances for
78 performance improvement.
79 26-Feb-2008 Ckesanap 115.141 6820127 Added another definition of
80 ext_man_payment to be called as
81 a concurrent request for Void and
82 Reversal enhancement.
83 19-DEC-2007 AYegappa 115.140 6676706 Performance fix to Balance
84 Adjustments (added some hints)
85 05-NOV-2007 alogue 115.139 Performance fix to
86 trash_latest_balances.
87 11-JUN-2007 KKawol 115.138 Set the entry path on reversal
88 run results.
89 12-FEB-2007 SuSivasu 115.137 Set the time period to be based
90 on the period earned for the
91 Balance Adjustment when the
92 TIME_PERIOD_ID leg rule is set.
93 16-JAN-2007 nbristow 115.136 Changes for
94 maintain_balances_for_action
95 30-NOV-2006 divicker 115.135 Retain old reversal sig order
96 23-NOV-2006 divicker 115.134 Multi reversal parameter update
97 10-NOV-2006 alogue 115.133 5410515 Stop balance adjustments or
98 reversals on assignments with
99 allready incomplete actions.
100 09-NOV-2006 divicker 115.132 Further batch reversal changes
101 03-NOV-2006 nbristow 115.131 Now performing
102 a distinct for pog joins
103 03-NOV-2006 divicker 115.130 Revert to 115.128 pending
104 further check on 115.129
105 02-NOV-2006 divicker 115.129 Add loop for processing multi
106 reverse run balances
107 31-OCT-2006 divicker 115.128 Need correct refactoring of
108 reversal proc.
109 30-OCT-2006 divicker 115.126 5616882 Reversal by assignment set func
110 Bug fix 5410515
111 19-OCT-2006 alogue 115.125 5612247 Performance fix to POG
112 resequence statements.
113 07-AUG-2006 alogue 115.124 5441737 Resequence G object group actions
114 - Retropay matser assignment actions
115 have null assignment_id.
116 02-AUG-2006 alogue 115.123 5416668 Performance fix to albc_selective
117 in del_latest_balances.
118 30-JUN-2006 nbristow 115.122 Context length limited to 30
119 chars
120 19-JUN-2006 SuSivasu 115.121 Enabled the Balance Date and Time
121 Definition ID contexts to be stored
122 in pay_action_contexts.
123 14-MAR-2006 alogue 115.120 5094068 Fix lb_context_match_check
124 to correctly spot if context
125 wasn't in the udca.
126 07-MAR-2006 alogue 115.119 5082050 Further fix to POG retro
127 resequencing for assignments
128 started in the future.
129 17-FEB-2006 alogue 115.118 Further fix to previous change.
130 17-FEB-2006 nbristow 115.117 Using the interlock rule G, the
131 Retro actions were not
132 correctly resequencing for
133 terminated employees.
134 14-FEB-2006 alogue 115.116 5034395 Radix issue in maintain_lat_bal.
135 04-OCT-2005 alogue 115.115 4644738 Load cxt_id in udca for Reversals
136 as used by context_match_check.
137 05-SEP-2005 alogue 115.114 Performance CBO hints in
138 trash_latest_balances.
139 27-JUL-2005 nbristow 115.113 Resequence_actions was not
140 joining to the assignment table
141 correctly under certain date
142 track conditions.
143 08-JUN-2005 alogue 115.112 4372751 Performance fix: hint in seqasg
144 in resequence_actions.
145 06-MAY-2005 NBristow 115.111 Added new contexts
146 LOCAL_UNIT_ID, ORGANIZATION_ID
147 and SOURCE_NUMBER2.
148 29-APR-2005 SuSivasu 115.110 Added p_reason parameter for
149 ext_man_payment.
150 29-APR-2005 alogue 115.109 4337565 Support of ENABLE_RR_SPARSE
151 upgrade.
152 14-APR-2005 alogue 115.108 3465844 Use PAY_ASSIGNMENT_ACTIONS_N51
153 instead of PAY_ASSIGNMENT_ACTIONS_N1
154 in index hints.
155 04-APR-2005 alogue 115.107 Latest Balance Maintenance by
156 Reversals.
157 23-FEB-2005 nbristow 115.106 Changes for Period Allocation.
158 10-DEC-2004 alogue 115.105 g_ba_lat_bal_maintenance global
159 for BAL_ADJ_LAT_BAL legislation
160 rule.
161 25-NOV-2004 nbristow 115.104 Retropay multi assignments
162 25-OCT-2004 thabara 115.103 3966979 Added p_element_type_id to
163 del_latest_balances().
164 Modified maintain_lat_bal().
165 24-SEP-2004 nbristow 115.102 Changes for process group
166 actions.
167 20-SEP-2004 thabara 115.101 3482270 Original Entry ID support for
168 balance adjustments.
169 Modified set_action_context(),
170 bal_adjust_actions() and
171 maintain_lat_bal().
172 16-SEP-2004 alogue 115.100 3863038 More Performance fixes in
173 del_latest_balances.
174 09-AUG-2004 tbattoo 115.99 3724695 Support for reversals and retropay
175 08-JUL-2004 nbristow 115.98 Changes for Sparse Matrix JC.
176 30-APR-2004 alogue 115.97 More Performance fixes in
177 del_latest_balances.
178 28-APR-2004 thabara 115.96 Modified irbaact not to call
179 get_tax_unit when taxunt is set
180 for action type B and I.
181 27-APR-2004 alogue 115.95 Performance fix to albc_selective
182 in del_latest_balances.
183 09-Mar-2004 swinton 115.94 Enhancement 3368211 -
184 Amended Trash_Quickpay() to
185 support new QuickPay Exclusions
186 model.
187 02-FEB-2004 nbristow 115.93 Reversal was not correctly
188 setting the run balances, when
189 the run is prior to the
190 balance validation date.
191 06-JAN-2004 alogue 115.92 3354185 Avoid execution of
192 del_latest_balances() for balance
193 initialisations.
194 16-DEC-2003 tbattoo 115.91 Fix to mantain latest balances
195 11-DEC-2003 tbattoo 115.90 Fix to mantain latest balances
196 09-DEC-2003 nbristow 115.89 Changes to maintain
197 pay_latest_balances.
198 24-NOV-2003 alogue 115.88 3262314 Performance enhancement to
199 previous change.
200 24-NOV-2003 alogue 115.87 3262314 Performance enhancement to
201 previous change.
202 21-NOV-2003 alogue 115.86 3262314 Avoid corruption of latest
203 balance value by balance
204 adjustments.
205 13-NOV-2003 nbristow 115.85 Reversal was not correctly
206 setting the jurisdiction code
207 in sparse mode.
208 04-NOV-2003 alogue 115.84 3176709 Use of per_business_groups_perf,
209 per_all_people_f and
210 pay_all_payrolls_f. Performance
211 fix to seqper cursors.
212 03-NOV-2003 tbattoo 115.83 support for sparse matrix and
213 pay_latest_balances table
214 17-OCT-2003 alogue 115.82 Tuned get_rr_values cursor
215 in set_action_context.
216 14-OCT-2003 alogue 115.81 3166638 Performance fix to quickpay
217 assignment action creation.
218 05-SEP-2003 alogue 115.80 3130030 Performance fix to plbc_selective
219 in del_latest_balances.
220 05-SEP-2003 alogue 115.79 3130030 Performance fix to trash_quickpay.
221 03-SEP-2003 thabara 115.78 Correction of 115.77.
222 03-SEP-2003 thabara 115.77 3105028 Modified set_action_context not
223 to set defaults to dynamic
224 contexts for Balance Upload.
225 Modified the process order of
226 create_all_asg/group_balances
227 in bal_adjust_actions to call
228 them after setting contexts.
229 03-SEP-2003 nbristow 115.76 RETRO_DELETE is now a
230 legislation rule.
231 29-AUG-2003 nbristow 115.75 Action sequence on
232 pay_run_balances was not being
233 updated correctly.
234 53-JUN-2003 alogue 115.74 2960902 New trash_latest_balances
235 only passed balance_type_id
236 and trash_date. Overloads
237 original version.
238 12-MAY-2003 alogue 115.73 2911448 Avoid locking issues in Batch
239 Balance Adjustments by only
240 updating action_population_status
241 in inassact_main if need to.
242 11-MAR-2004 rthirlby 115.72 2822429 Altered reversal, so that run
243 result values for SOURCE_IV
244 and SOURCE_NUMBER input values
245 are not negated. These rrvs will
246 be ids/numbers that should not be
247 reversed.
248 05-MAR-2003 sdhole 115.71 2805195 Added parameter tax_unit_id
249 with default value null to
250 bal_adjust procedure.
251 07-FEB-2003 nbristow 115.70 Reversal was not correctly
252 working for the new contexts.
253 05-FEB-2003 nbristow 115.69 Further new context changes.
254 05-FEB-2003 nbristow 115.68 Added contexts for
255 source_number and source_text2
256 24-JAN-2003 alogue 115.67 Reverse bug 2453546 changes.
257 20-JAN-2003 alogue 115.66 2758499 Fixed trash_latest_balances
258 to handle latest balances
259 earlier than trash_date.
260 14-JAN-2003 nbristow 115.65 Now Jurisdiction input value
261 can have any name.
262 10-JAN-2003 alogue 115.64 2266326 Use of CHECK_LATEST_BALANCES,
263 CHECK_RRVS_FIRST and
264 CHECK_LAT_BALS_FIRST package
265 globals to tune behaviour of
266 trash_latest_balances.
267 09-JAN-2003 alogue 115.63 2692195 Use of hr_utility.debug_enabled
268 for performance of trace
269 statements.
270 06-DEC-2002 alogue 115.62 Subtle-paranoid fix to
271 bal_adjust_actions to avoid
272 possible issue with NOCOPY
273 changes.
274 03-DEC-2002 scchakra 115.61 2613838 Added overloaded procedure
275 get_default_leg_value to return
276 the default run type for a
277 legislation. Included
278 NOCOPY Performance Changes.
279 15-NOV-2002 alogue 115.60 2667222 Re-implement 2492007 cartesian
280 join (in a different way!).
281 07-NOV-2002 alogue 115.59 2453546 Optimise performance of seqper
282 cursor in inassact be breaking
283 into 2.
284 24-OCT-2002 alogue 115.57 2641336 Optimise performance for
285 statements in del_latest_balances.
286 16-OCT-2002 alogue 115.56 2581887 Optimise performance for
287 Balance Initialisation.
288 24-SEP-2002 alogue 115.55 2587443 Further enhanced Reversals so
289 handle result values with up
290 to 38 decimal places.
291 19-SEP-2002 nbristow 115.54 Changes in 115.50 introduced
292 a bug in Retropay, reversed
293 the change to run_results
294 cursor.
295 09-SEP-2002 alogue 115.53 2529691 Performance fix to
296 resequence_actions.
297 09-AUG-2002 alogue 115.52 Performance fix to element
298 entries statement in
299 do_assact_rollback that was
300 using FTS.
301 09-AUG-2002 alogue 115.51 2362454 Enhance Reversals so handle
302 result values with up to 35
303 decimal places. Previously
304 there was a restriction of up
305 to 20 dcs within the fnd_number
306 code.
307 01-AUG-2002 dsaxby 115.50 2492007 Prevent ora-01403
308 no data found from within
309 bal_adjust_actions.
310 Also, fix select of run results
311 to reverse to remove apparent
312 cartesian join.
313 21-JUN-2002 alogue 115.49 Fix CA TAX_GROUP value fetch
314 in udca.
315 30-APR-2002 RThirlby 115.48 Support for pay_run_balances -
316 balance reporting architecture,
317 for reversals and balance
318 adjustments.
319 26-APR-2002 alogue 115.47 2346351 Support of payroll_id in udca
320 for balances that use payroll_id
321 context.
322 09-APR-2002 nbristow 115.46 Added get_default_leg_rule to
323 allow the defaulting of run
324 type.
325 03-APR-2002 tbattoo 115.45 added p_run_type_id parameter
326 18-DEC-2001 dsaxby 115.44 GSCC standards fix.
327 26-NOV-2001 dsaxby 115.43 1682940 Changes for Purge.
328 Do not shuffle assignment
329 actions in purge mode and allow
330 insert of upload action before
331 a Purge.
332 Added commit at end of file.
333 Added purge_mode parameter to
334 bal_adjust_actions.
335 Added dbdrv line.
336 13-NOV-2001 jtomkins 115.42 Added prepay_flag parameter to
337 bal_adjust and bal_adjust_actions
338 01-NOV-2001 nbristow 115.41 Set Action Context exist
339 statement now in the correct
340 format.
341 29-OCT-2001 nbristow 115.40 Set Action Context changed to
342 check that a row does not
343 already exist in the action
344 context table.
345 11-OCT-2001 nbristow 115.39 Added hints to statements
346 in rev_pre_inserted_rr.
347 04-SEP-2001 nbristow 115.38 Added the resequence_chunk
348 procedure.
349 12-JUL-2001 kkawol 115.37 Change to inassact_main. If
350 rule_type 'I' does not exist for
351 the legislation, we default rule
352 mode to N. Bug 1337853.
353 25-JUN-2001 alogue 115.36 Performance fix to balance
354 adjustment latest balance
355 maintenance.
356 25-JUN-2001 alogue 115.35 Added CBO hints
357 22-JUN-2001 alogue 115.34 Added CBO hints
358 12-JUN-2001 nbristow 115.33 Initialising retro_purge.
359 04-JUN-2001 kkawol 115.32 Added changes required for
360 Quickpay Prepay to work with
361 master and sub actions (iter eng).
362 Changed qpppassact and inassact.
363 29-MAY-2001 nbristow 115.31 Changes to Retropay so that
364 the RRs are not deleted.
365 08-MAY-2001 alogue 115.30 1763446 Added CBO hints
366 24-APR-2001 mreid 115.29 1518951 Added CBO hints
367 06-APR-2001 alogue 115.28 Changes for source text iv
368 context.
369 26-JAN-2001 alogue 115.26 1614003 Balance Adjustment lat bal
370 maintenance handle multiple
371 feeds by same adjustment.
372 16-JAN-2001 alogue 115.26 Handle null result values in
373 balance adjustment latest
374 balance maintenance.
375 10-JAN-2001 alogue 115.25 1571313 Handle -9999 balance values in
376 balance adjustment latest
377 balance maintenance.
378 26-NOV-2000 nbristow 115.24 Changes for source text context
379 21-NOV-2000 alogue 115.23 887061 Skipped terminated assignments
380 support.
381 02-OCT-2000 alogue 115.22 1421447 Avoid a PLS-00365 in latest
382 balance maintenance inm balance
383 adjustments.
384 29-SEP-2000 nbristow 115.21 Now passing tax unit id to
385 balance adjustments.
386 18-SEP-2000 nbristow 115.20 Maintenance of latest balances
387 was not taking into account
388 null rrv.
389 14-SEP-2000 NBRISTOW 115.19 Changes to trash_latest_balances
390 to remove full pl/sql feed
391 checking balances.
392 30-AUG-2000 ALOGUE 115.17 Deletion of latest balances
393 by balance adjustment if
394 leg rule for lat bal maintenance
395 is not defined.
396 04-AUG-2000 ALOGUE 115.16 Maintenance of latest balances
397 within balance adjustments.
398 19-MAY-2000 nbristow 115.15 Added procedures to resequence
399 sequenced actions.
400 22-FEB-2000 dsaxby 115.14 #1168142 Remove the need for a period of
401 service row to exist when
402 processing a balance adjustment
403 action. This is for OAB.
404 13-JAN-2000 alogue 115.13 Ensure that error_messages
405 inserted into pay_message_lines
406 are at max 240 in length.
407 16-NOV-1999 nbristow 115.12 Now reversals and balance
408 adjustments populate
409 pay_action_contexts.
410 26-JUL-1999 ALOGUE 115.11 Enhancement in Reversal to
411 get reversals results in same
412 order as run being reversed.
413 Optimises behaviour of the
414 retrocosting of a reversal.
415 02-JUN-1999 ALOGUE 115.10 Fix in bal_adjust_actions to
416 ensure only update this balance
417 adjustments run results.
418 22-APR-1999 ALOGUE 115.8 Changed rollback_payroll_action
419 12-APR-1999 ALOGUE 115.7 Fix to reversals to support
420 canonical numbers.
421 07-APR-1999 SDOSHI 115.6 Flexible Dates Conversion
422 04-JAN-1999 NBRISTOW 110.8 Changed rollback_payroll_action
423 to use the rollback package.
424 04-SEP-1998 KKAWOL 40.62 #721925 Reversals run results: select
425 actual status instead of
426 forcing it to be 'P'.
427 27-NOV-1997 MFENDER 110.3 #589767 Modified inassact to populate
428 tax_unit_id for quickpay
429 prepayments.
430 05-SEP-1997 KKAWOL 40.61 #547578 Period dates fix. Set the
431 date_earned column as
432 appropriate on the
433 pay_payroll_actions table.
434 19-JUN-1997 ALOGUE 40.60 #507602 Reversals run results: source_id
435 = run_result_id of the run
436 result being reversed.
437 04-APR-1997 NBRISTOW 40.59 #473685 Segment1 was not being decoded
438 for US legislation to convert
439 it to a number.
440 01-APR-1997 ALOGUE 40.58 Fixed previous change.
441 27-MAR-1997 ALOGUE 40.57 US reversal GRE Fix #459662
442 15-JAN-1996 NBRISTOW 40.56 EOY performance fix for W2.
443 13-JAN-1996 NBRISTOW 40.55 Reverse Backport.
444 13-JAN-1996 NBRISTOW 40.54 Backport EOY performance fix.
445 23-DEC-1996 NBRISTOW 40.53 Uncommented exit.
446 09-DEC-1996 SSINHA 40.52 Fixed previous change
447 05-DEC-1996 NBRISTOW 40.51 Fixed previous change.
448 29-NOV-1996 DSAXBY 40.50 #366215 New Reversal functionality.
449
450 20-NOV-1996 NBRISTOW 40.49 Now passing a flag to inassact
451 to indicate that the assignment
452 needs to be locked.
453 18-JUN-1996 NBRISTOW 40.48 #374931 Now when a balance adjustment
454 is performed only the latest
455 balances feed by the adjustment
456 are deleted.
457 14-JUN-1996 DSAXBY 40.47 #374389 When reversing an indirect
458 result, set source_type of new
459 result to 'V' (required for
460 Costing).
461 08-MAY-1996 NBRISTOW 40.46 #359005 Performance problem in
462 del_latest_balances, now using
463 a cursor to delete context
464 values.
465 22-APR-1996 DSAXBY 40.45 #360386 Change joins to the
466 per_business_groups view.
467 13-APR-1996 DKERR 40.44 Modified inassact for external
468 manual payments to allow
469 the insert of an assignment
470 action where a payment action
471 have been voided.
472 14-MAR-1996 DSAXBY 40.43 Make 'X' actions alter action
473 sequence where necessary.
474 27-FEB-1996 DSAXBY 40.42 Added support for 'X' actions.
475 17-JAN-1996 NBRISTOW 40.41 #335099 Altered sql statements in
476 inassact to improve performance
477 of US Check report. US Check
478 Report is using balance
479 user exit thus calling inassact.
480 10-JAN-1996 DSAXBY 40.40 #333428 Changed trash_latest_balances
481 procedure to avoid trashing
482 balances un-necessarily. This
483 required the addition of a new
484 parameter.
485 11-DEC-1995 NBRISTOW 40.39 Changed inassact to insert the
486 Tax Unit Id for quick pay
487 actions.
488 10-NOV-1995 NBRISTOW 40.38 Changed name of bal_adjust to
489 bal_adjust_actions, added extra
490 out arguments. Created new
491 procedure bal_adjust for
492 existing bal_adjust calls.
493 06-NOV-1995 NBRISTOW 40.37 Tax Unit Id now placed on the
494 assignment_action for balance
495 adjustments and resversals.
496 Also the jurisdiction is placed
497 on the run result.
498 13-SEP-1995 DSAXBY 40.35 #307123 New parameter to reversal
499 procedure, indicating that we do
500 not need to insert assact and
501 interlock. Introduced for
502 backpay.
503 16-AUG-1995 DSAXBY 40.34 #301528 Removed unnecessary check from
504 ensure_assact_rolled_back
505 procedure.
506 25-JUL-1995 AMILLS 40.33 Amended selection statement
507 substituting clause :-
508 'HR_6075_ELE_ENTRY_REC_EXIST'
509 with the following 2 hard
510 coded error messages:
511 'HR_7699_ELE_ENTRY_REC_EXISTS'
512 'HR_7700_ELE_ENTRY_REC_EXISTS'
513 10-JUL-1995 DSAXBY 40.32 #292828 Set date_earned for bal adjust.
514 05-JUL-1995 NBRISTOW 40.31 Added intial balance load
515 payroll action type.
516 19-APR-1995 DSAXBY 40.30 #277088 : trash_latest_balances
517 now deletes latest balances
518 correctly again!
519 18-APR-1995 DSAXBY 40.29 Removed 'nowait' statement to
520 avoid immediate failure on lock
521 when called as part of w2
522 report work.
523 04-APR-1995 DSAXBY 40.28 Reverse 'H_HHMM' uom.
524 31-MAR-1995 DSAXBY 40.27 Now insert assignment action
525 with status = 'U' for a non
526 tracked action type ('N').
527 24-MAR-1995 DSAXBY 40.26 Now call undo_stop_update
528 procedure instead of hr_ent_api
529 delete_element_entry.
530 13-FEB-1995 DSAXBY 40.25 Fix problem causing 7010 error
531 when inserting quickpay assact.
532 31-JAN-1995 DSAXBY 40.24 Must not trash latest balances
533 for an action type of 'N'.
534 16-DEC-1994 DSAXBY 40.23 Added qpppassact.
535 Delete pre_payment rows for
536 QuickPay Pre-Payment process.
537 25-NOV-1994 DSAXBY 40.22 Change in params to qpassact.
538 26-OCT-1994 DSAXBY 40.21 Delete from the
539 pay_balance_context_values
540 table where necessary.
541 Set time_period_id for
542 balance adjustments.
543 Created public versions of
544 validate_pact_rollback and
545 validate_assact_rollback
546 procedures. (To be called from
547 forms).
548 Prevent mark for retry for
549 Balance Adjustment. Note this
550 check has been moved
551 val_pact_rollback procedure.
552 Insert value for the
553 time_period_id column when
554 processing balance adjustment.
555 Alter rules and strategy for
556 checking rules for rolling back
557 and marking for retry assignment
558 and payroll actions.
559 Disabled all uses of the
560 business_group_id index.
561 05-OCT-1994 DKERR 40.20 Set the OBJECT_VERSION_NUMBER
562 to 1 for inserts into
563 PAY_PAYROLL_ACTIONS and
564 PAY_ASSIGNMENT_ACTIONS for
565 all action types.
566 28-JUN-1994 DSAXBY 40.19 Added line to decode statement
567 in reversal routine, to
568 prevent invalid number errors.
569 Delete from pay_costs and
570 pay_quickpay_inclusions when
571 we roll back.
572 Do not attempt to delete from
573 pay_pre_payments, unless we are
574 rolling back a Pre-Payment!
575 21-JUN-1994 CSWAN 40.18 For reversal RRVs, flip the
576 sign of the RRVs being reversed,
577 rather than prepending a '-'
578 character, which leads to
579 balance errors.
580 28-MAR-1994 DSAXBY 40.17 G622 Set updating_action_id to null
581 when rolling back update rec
582 entries which were corrections.
583 18-MAR-1994 DSAXBY 40.16 G172 Improved messaging for rollback
584 assignment action. Added message
585 for rollback payroll action.
586 28-FEB-1994 DSAXBY 40.15 G585 Allow nested mark for retry.
587 Prevent marking payment action
588 types for retry.
589 05-JAN-1994 DSAXBY 40.14 G481 Only process NEE when reversing
590 effective of stop and update
591 rules.
592 20-DEC-1993 DSAXBY 40.13 G454 Delete pre-payment rows.
593 G283/ Ensure interlock rows are
594 G272 deleted if rollback assact is
595 called from form.
596 ---- Altered DELETE_NEXT_CHANGE to
597 FUTURE_CHANGE for rollback of
598 REE update feature.
599 17-DEC-1993 DSAXBY 40.12 G277 Updated incorrect comments.
600 14-DEC-1993 DSAXBY 40.11 G277 Rolling back of Update and
601 stop REE rules.
602 pay_element_entry_values table).
603 13-DEC-1993 CSWAN 40.10 G410 Removed reference to removed
604 PLANNED_PAYMENT_DATE column.
605 13-DEC-1993 AFRITH 40.9 G396 Unsequenced assignment actions
606 not interlocked by sequenced
607 actions .
608 09-DEC-1993 DSAXBY 40.8 G320 Handle ND unit of measure.
609 06-DEC-1993 DSAXBY 40.7 G296 Prevent looping on rollback or
610 mark for retry when assignment
611 actions are not to be
612 (correctly) rolled back or
613 marked for retry.
614 12-NOV-1993 DSAXBY 40.6 G36 Handled non tracked action
615 properly again.
616 29-OCT-1993 RPATEL 40.5 Added functionality for
617 Manual/External Payments,
618 error handling invalid action.
619 26-OCT-1993 DSAXBY 40.4 Added some missing error mesg.
620 Prevent Reversal of something
621 that is already reversed.
622 Trash latest balances for Rev
623 and Balance Adjustment. (Needed
624 to add del_latest_balances).
625 20-OCT-1993 AFRITH 40.3 Added BACKPAY mode.
626 19-OCT-1993 DSAXBY 40.2 Altered bal_adjust. No longer
627 a function, now procedure and
628 updates creator_id.
629 Fixed payroll action roll back.
630 13-AUG-1993 DSAXBY 40.1 Fix interlock delete.
631 28-JUL-1993 DSAXBY 30.8 Work on reversal and bal_adjust
632 20-JUL-1993 DSAXBY 30.7 Added bal_adjust.
633 24-FEB-1999 J. Moyano 115.5 MLS Changes. Reference to
634 pay_payment_types_tl included in
635 procedure do_pact_rollback.
636 11-SEP-2000 divicker 115.18 Performance changes
637 -----------+-------------+-------+----------+-------------------------------+
638 */
639 --
640 --
641 /*-------------------------- RECORD types ---------------------------*/
642 --
643 type context_cache_type is record
644 (
645 cxt_id number_tbl,
646 cxt_name varchar_60_tbl,
647 sz number
648 );
649 --
650 type assact_details is record
651 (assact_id pay_assignment_actions.assignment_action_id%type,
652 assignment_id pay_assignment_actions.assignment_id%type,
653 full_name per_all_people_f.full_name%type,
654 assignment_number per_all_assignments_f.assignment_number%type,
655 payroll_id per_all_assignments_f.payroll_id%type);
656 --
657 type pact_details is record
658 (pact_id pay_payroll_actions.payroll_action_id%type,
659 action_name hr_lookups.meaning%type,
660 action_type pay_payroll_actions.action_type%type,
661 sequenced_flag boolean,
662 action_date date,
663 current_date date, -- this is sysdate.
664 payroll_name pay_all_payrolls_f.payroll_name%type,
665 bg_name hr_organization_units.name%type,
666 independent_periods_flag boolean);
667 --
668 c_eot constant date := to_date('31/12/4712','DD/MM/YYYY');
669 g_context_cache context_cache_type;
670 contexts_cached boolean := FALSE;
671 g_lat_bal_check_mode pay_action_parameters.parameter_value%TYPE := null;
672 g_debug boolean := hr_utility.debug_enabled;
673 g_dynamic_contexts pay_core_utils.t_contexts_tab;
674 --
675 --
676 --
677 /*------------------------ val_pact_rr_rules ---------------------------*/
678 --
679 procedure val_pact_rr_rules (p_pact_rec in pact_details,
680 p_rollback_mode in varchar2) is
681 begin
682 if p_rollback_mode = 'RETRY' then
683 if p_pact_rec.action_type in ('V', 'B', 'Z', 'E', 'H') then
684 hr_utility.set_message(801, 'HR_7093_ACTION_CANT_RETPAY');
685 hr_utility.set_message_token('ACTION_NAME',p_pact_rec.action_name);
686 hr_utility.raise_error;
687 end if;
688 else
689 if p_pact_rec.action_type = 'Z' then
690 hr_utility.set_message(801, 'HR_7212_ACTION_RBACK_RULE');
691 hr_utility.set_message_token('ACTION_NAME',p_pact_rec.action_name);
692 hr_utility.raise_error;
693 end if;
694 end if;
695 end val_pact_rr_rules;
696 --
697 --
698 /*------------------------ val_assact_rr_rules -------------------------*/
699 --
700 function val_assact_rr_rules (p_pact_rec in pact_details,
701 p_rollback_mode in varchar2)
702 return boolean is
703 begin
704 --
705 -- Validate the rollback and mark for retry rules for
706 -- assignment actions.
707 if g_debug then
708 hr_utility.set_location('hrassact.val_assact_rr_rules', 10);
709 end if;
710 if p_rollback_mode = 'RETRY' then
711 if p_pact_rec.action_type in ('V', 'B', 'Z', 'E', 'M', 'H', 'T') then
712 return false;
713 end if;
714 else
715 if p_pact_rec.action_type in ('Q', 'V', 'B', 'Z', 'U', 'E', 'M', 'T')
716 then
717 return false;
718 end if;
719 end if;
720 --
721 return true;
722 end val_assact_rr_rules;
723 --
724 --
725 /*----------------------- validate_rollback_mode ----------------------*/
726 --
727 procedure validate_rollback_mode(p_rollback_mode in varchar2) is
728 begin
729 if p_rollback_mode not in ('RETRY', 'ROLLBACK', 'BACKPAY') then
730 hr_utility.set_message(801, 'HR_7000_ACTION_BAD_ROLL_MODE');
731 hr_utility.raise_error;
732 end if;
733 end validate_rollback_mode;
734 --
735 --
736 /*----------------------- ensure_assact_rolled_back ----------------------*/
737 /*
738 * This routine checks that the target assignment action appears to
739 * have been rolled back prior to it's deletion (i.e, must have no
740 * attached run results, latest balances, quickpay inclusions, etc).
741 *
742 * There are two levels of checking, since this routine is also
743 * used to check whether a RETRY can be performed (in which case any
744 * EEs created by a QuickPay are allowed to remain).
745 */
746 procedure ensure_assact_rolled_back (p_assact_id in number,
747 p_rollback_mode in varchar2) is
748 --
749 cursor c1 is
750 select null from dual
751 where exists
752 (select null -- check for any RRs
753 from pay_run_results
754 where assignment_action_id = p_assact_id)
755 or exists
756 (select null -- check for any MESSAGEs
757 from pay_message_lines
758 where source_type = 'A'
759 and source_id = p_assact_id)
760 -- or exists -- check for any latest balances
761 -- (select null
762 -- from pay_assignment_latest_balances
763 -- where assignment_action_id = p_assact_id)
764 -- or exists -- check for any latest balances
765 -- (select null
766 -- from pay_person_latest_balances
767 -- where assignment_action_id = p_assact_id)
768 -- or exists -- check for any latest balances
769 -- (select null
770 -- from pay_latest_balances
771 -- where assignment_action_id = p_assact_id)
772 or exists -- check for updates to REEs
773 (select null
774 from pay_element_entries_f
775 where updating_action_id = p_assact_id);
776 --
777 cursor c2 is
778 select null from dual
779 where exists
780 (select null -- check for any RRs
781 from pay_run_results
782 where assignment_action_id = p_assact_id
783 and status <> 'B')
784 or exists
785 (select null -- check for any MESSAGEs
786 from pay_message_lines
787 where source_type = 'A'
788 and source_id = p_assact_id)
789 -- or exists -- check for any latest balances
790 -- (select null
791 -- from pay_assignment_latest_balances
792 -- where assignment_action_id = p_assact_id)
793 -- or exists -- check for any latest balances
794 -- (select null
795 -- from pay_person_latest_balances
796 -- where assignment_action_id = p_assact_id)
797 -- or exists -- check for any latest balances
798 -- (select null
799 -- from pay_latest_balances
800 -- where assignment_action_id = p_assact_id)
801 or exists -- check for updates to REEs
802 (select null
803 from pay_element_entries_f
804 where updating_action_id = p_assact_id);
805 --
806 begin
807 g_debug := hr_utility.debug_enabled;
808 --
809 if g_debug then
810 hr_utility.set_location('hrassact.ensure_assact_rolled_back',10);
811 end if;
812 validate_rollback_mode(p_rollback_mode);
813 --
814 if (p_rollback_mode = 'BACKPAY') then
815 --
816 if g_debug then
817 hr_utility.set_location('hrassact.ensure_assact_rolled_back',20);
818 end if;
819 for c2rec in c2 loop
820 -- any record fetched is an error
821 hr_utility.set_message(801, 'HR_7001_ACTION_MUST_ROLL_FIRST');
822 hr_utility.set_message_token('ASSACTID',p_assact_id);
823 hr_utility.raise_error;
824 end loop;
825 --
826 else
827 --
828 if g_debug then
829 hr_utility.set_location('hrassact.ensure_assact_rolled_back',30);
830 end if;
831 for c1rec in c1 loop
832 -- any record fetched is an error
833 hr_utility.set_message(801, 'HR_7001_ACTION_MUST_ROLL_FIRST');
834 hr_utility.set_message_token('ASSACTID',p_assact_id);
835 hr_utility.raise_error;
836 end loop;
837 --
838 end if;
839 --
840 return;
841 end ensure_assact_rolled_back;
842 --
843 --
844 /*----------------------- ensure_pact_rolled_back ----------------------*/
845 /*
846 * This routine checks that the payroll action about to be rolled
847 * back has no assignment actions attached to it which would indicate that
848 * the rollback_payroll_action procedure has not been called.
849 */
850 procedure ensure_pact_rolled_back (p_pact_id in number) is
851 cursor c1 is
852 select null
853 from dual
854 where exists
855 (select null -- check for any ASSACTs
856 from pay_assignment_actions
857 where payroll_action_id = p_pact_id)
858 or exists
859 (select null -- check for any MESSAGEs
860 from pay_message_lines
861 where source_type = 'P'
862 and source_id = p_pact_id);
863 begin
864 g_debug := hr_utility.debug_enabled;
865 --
866 if g_debug then
867 hr_utility.set_location('hrassact.ensure_pact_rolled_back',10);
868 end if;
869 for c1rec in c1 loop
870 -- any record fetched is an error
871 hr_utility.set_message(801, 'HR_7007_ACTION_ROLL_ASSACTS');
872 hr_utility.raise_error;
873 end loop;
874 return;
875 end ensure_pact_rolled_back;
876 --
877 --
878 /*----------------------- val_assact_rollback ----------------------*/
879 /*
880 * This routine checks whether the specified assignment action can be
881 * rolled back, but relies on parameters for all information at a
882 * higher level than the ass action (e.g, for action type). This is
883 * more efficient when testing a lot of actions on the same payroll
884 * action.
885 *
886 * This means that any rollback checks at a higher level (e.g, can't
887 * rollback a purge) must also have been performed.
888 *
889 * This routine is not needed to validate a mark for BACKPAY operation.
890 */
891 function val_assact_rollback (p_pact_rec in pact_details,
892 p_assact_rec in out nocopy assact_details,
893 p_rollback_mode in varchar2)
894 return boolean is
895 --
896 l_action_sequence pay_assignment_actions.action_sequence%type;
897 l_action_status pay_assignment_actions.action_status%type;
898 l_person_id per_all_people_f.person_id%type;
899 begin
900 --
901 g_debug := hr_utility.debug_enabled;
902 -- Obtain information about this assignment action which we will
903 -- need later on.
904 -- Some of this is required for messages.
905 if g_debug then
906 hr_utility.set_location('hrassact.val_assact_rollback',10);
907 end if;
908 select ACT.assignment_id,
909 ACT.action_sequence,
910 ACT.action_status,
911 ASS.payroll_id,
912 POS.person_id,
913 substr(PEO.full_name,1,80),
914 ASS.assignment_number
915 into p_assact_rec.assignment_id,
916 l_action_sequence,
917 l_action_status,
918 p_assact_rec.payroll_id,
919 l_person_id,
920 p_assact_rec.full_name,
921 p_assact_rec.assignment_number
922 from per_periods_of_service POS,
923 per_all_assignments_f ASS,
924 per_all_people_f PEO,
925 pay_assignment_actions ACT
926 where ACT.assignment_action_id = p_assact_rec.assact_id
927 and ASS.assignment_id = ACT.assignment_id
928 and p_pact_rec.action_date between
929 ASS.effective_start_date and ASS.effective_end_date
930 and PEO.person_id = ASS.person_id
931 and p_pact_rec.action_date between
932 PEO.effective_start_date and PEO.effective_end_date
933 and POS.period_of_service_id = ASS.period_of_service_id;
934 --
935 -- can only retry if already complete
936 if p_rollback_mode = 'RETRY' and l_action_status not in ('C', 'S') then
937 return FALSE;
938 end if;
939 --
940 --
941 --
942 -- If rolling back or retrying, we need to know if assignments
943 -- can be considered in isolation (as prescribed by the
944 -- independent time periods flag for this legislation). Assignments
945 -- with no Payroll are independent.
946 --
947 -- Operation is disallowed if this is a sequenced action AND there
948 -- exists any sequenced actions in the future. Also disallowed
949 -- if any child action exists (e.g can't rollback a run if already
950 -- costed).
951 -- Note - exception is if are attempting to roll back Reversal or
952 -- Balance Adjustment actions, where we do not bother to perform
953 -- the future actions check.
954 --
955 declare
956 dummy number;
957 begin
958 -- For either legislation, examine the assignment action
959 -- to see if it is locked by another action. Peform
960 -- slightly different checks for RETRY and ROLLBACK
961 -- modes. See comments below.
962 if g_debug then
963 hr_utility.set_location('hrassact.val_assact_rollback',20);
964 end if;
965 if(p_rollback_mode = 'RETRY') then
966 -- Case for RETRY mode.
967 -- Check that the assignment action we are attempting to
968 -- mark for retry is not locked by an assignment action
969 -- that has an action_status that is not mark for retry.
970 select null
971 into dummy
972 from dual
973 where not exists (
974 select null
975 from pay_action_interlocks int,
976 pay_assignment_actions act
977 where int.locked_action_id = p_assact_rec.assact_id
978 and act.assignment_action_id = int.locking_action_id
979 and act.action_status <> 'M');
980 else
981 -- Case for ROLLBACK mode.
982 -- Check that the assignment action we are attempting to
983 -- roll back is not locked by an assignment action.
984 select null
985 into dummy
986 from dual
987 where not exists (
988 select null
989 from pay_action_interlocks int
990 where int.locked_action_id = p_assact_rec.assact_id);
991 end if;
992 --
993 -- Now, if we have a balance adjustment or Reversal,
994 -- we do not bother to check for actions in the future,
995 -- because these are special cases.
996 --
997 -- Referring to above comments, the reversal has been
998 -- extended to incorporate new functionality to now
999 -- check for future payroll run actions that now interlock
1000 if (p_pact_rec.action_type <> 'B'
1001 and p_pact_rec.action_type <> 'I'
1002 and p_pact_rec.action_type <> 'V')
1003 then
1004 -- Check the legislation case.
1005 if p_pact_rec.independent_periods_flag then
1006 --
1007 -- check for other actions on this ASSIGNMENT
1008 -- Perform different checks for RETRY or ROLLBACK.
1009 if g_debug then
1010 hr_utility.set_location('hrassact.val_assact_rollback',30);
1011 end if;
1012 if(p_rollback_mode = 'RETRY') then
1013 -- Case for RETRY mode.
1014 -- Disallow mark for retry assignment action
1015 -- if there are future SEQUENCED assignment actions
1016 -- for the assignment and these actions are not
1017 -- marked for retry.
1018 select null into dummy
1019 from dual
1020 where not exists
1021 (select null
1022 from pay_assignment_actions ACT,
1023 pay_payroll_actions PACT,
1024 pay_action_classifications CLASS,
1025 pay_action_classifications CLAS2
1026 where ACT.assignment_id = p_assact_rec.assignment_id
1027 and ACT.action_sequence > l_action_sequence
1028 and ACT.action_status <> 'M'
1029 and ACT.payroll_action_id = PACT.payroll_action_id
1030 and PACT.action_type = CLASS.action_type
1031 and CLASS.classification_name = 'SEQUENCED'
1032 and CLAS2.action_type = p_pact_rec.action_type
1033 and CLAS2.classification_name = 'SEQUENCED' );
1034 else
1035 -- Case for ROLLBACK mode.
1036 -- Disallow rollback assignment action
1037 -- if there are future SEQUENCED assignment actions
1038 -- for the assignment.
1039 select null into dummy
1040 from dual
1041 where not exists
1042 (select null
1043 from pay_assignment_actions ACT,
1044 pay_payroll_actions PACT,
1045 pay_action_classifications CLASS,
1046 pay_action_classifications CLAS2
1047 where ACT.assignment_id = p_assact_rec.assignment_id
1048 and ACT.action_sequence > l_action_sequence
1049 and ACT.payroll_action_id = PACT.payroll_action_id
1050 and PACT.action_type = CLASS.action_type
1051 and CLASS.classification_name = 'SEQUENCED'
1052 and CLAS2.action_type = p_pact_rec.action_type
1053 and CLAS2.classification_name = 'SEQUENCED' );
1054 end if;
1055 else
1056 -- check for other actions on this PERSON
1057 -- As above, perform different checks for
1058 -- RETRY and ROLLBACK modes.
1059 if g_debug then
1060 hr_utility.set_location('hrassact.val_assact_rollback',40);
1061 end if;
1062 if(p_rollback_mode = 'RETRY') then
1063 -- Case for RETRY mode.
1064 select null into dummy
1065 from dual
1066 where not exists
1067 (select null
1068 from pay_action_classifications CLASS,
1069 pay_action_classifications CLAS2,
1070 pay_payroll_actions PACT,
1071 pay_assignment_actions ACT,
1072 per_all_assignments_f ASS,
1073 per_periods_of_service POS
1074 where POS.person_id = l_person_id
1075 and ASS.period_of_service_id = POS.period_of_service_id
1076 and ACT.assignment_id = ASS.assignment_id
1077 and ACT.action_sequence > l_action_sequence
1078 and ACT.action_status <> 'M'
1079 and ACT.payroll_action_id = PACT.payroll_action_id
1080 and PACT.action_type = CLASS.action_type
1081 and CLASS.classification_name = 'SEQUENCED'
1082 and CLAS2.action_type = p_pact_rec.action_type
1083 and CLAS2.classification_name = 'SEQUENCED' );
1084 else
1085 -- Case for ROLLBACK mode.
1086 select null into dummy
1087 from dual
1088 where not exists
1089 (select null
1090 from pay_action_classifications CLASS,
1091 pay_action_classifications CLAS2,
1092 pay_payroll_actions PACT,
1093 pay_assignment_actions ACT,
1094 per_all_assignments_f ASS,
1095 per_periods_of_service POS
1096 where POS.person_id = l_person_id
1097 and ASS.period_of_service_id = POS.period_of_service_id
1098 and ACT.assignment_id = ASS.assignment_id
1099 and ACT.action_sequence > l_action_sequence
1100 and ACT.payroll_action_id = PACT.payroll_action_id
1101 and PACT.action_type = CLASS.action_type
1102 and CLASS.classification_name = 'SEQUENCED'
1103 and CLAS2.action_type = p_pact_rec.action_type
1104 and CLAS2.classification_name = 'SEQUENCED' );
1105 end if;
1106 end if;
1107 end if;
1108 --
1109 exception
1110 when no_data_found then
1111 if g_debug then
1112 hr_utility.set_location('hrassact.val_assact_rollback',50);
1113 end if;
1114 return FALSE;
1115 --
1116 end;
1117 --
1118 if g_debug then
1119 hr_utility.set_location('hrassact.val_assact_rollback',60);
1120 end if;
1121 return TRUE;
1122 --
1123 end val_assact_rollback;
1124 --
1125 --
1126 /*----------------------- val_pact_rollback -------------------------*/
1127 /*
1128 * This routine is called before a rollback to get any payroll action level
1129 * information (e.g, action type) whch will be needed. This routine also
1130 * performs some validation as to whether the action can be rolled back,
1131 * and so may fail.
1132 */
1133 procedure val_pact_rollback (p_pact_rec in out nocopy pact_details,
1134 p_rollback_mode in varchar2 ) is
1135 --
1136 l_business_group_id hr_organization_units.business_group_id%type;
1137 begin
1138 --
1139 validate_rollback_mode(p_rollback_mode);
1140 --
1141 -- get payroll action level information
1142 if g_debug then
1143 hr_utility.set_location('hrassact.val_pact_rollback', 10);
1144 end if;
1145 select pac.business_group_id,
1146 pac.effective_date,
1147 hrl.meaning,
1148 pac.action_type,
1149 trunc(sysdate),
1150 pay.payroll_name,
1151 grp.name
1152 into l_business_group_id,
1153 p_pact_rec.action_date,
1154 p_pact_rec.action_name,
1155 p_pact_rec.action_type,
1156 p_pact_rec.current_date,
1157 p_pact_rec.payroll_name,
1158 p_pact_rec.bg_name
1159 from pay_payroll_actions pac,
1160 pay_all_payrolls_f pay,
1161 per_business_groups_perf grp,
1162 hr_lookups hrl
1163 where pac.payroll_action_id = p_pact_rec.pact_id
1164 and hrl.lookup_code = pac.action_type
1165 and hrl.lookup_type = 'ACTION_TYPE'
1166 and grp.business_group_id = pac.business_group_id
1167 and pay.payroll_id (+) = pac.payroll_id
1168 and pac.effective_date between
1169 pay.effective_start_date (+) and pay.effective_end_date (+);
1170 if g_debug then
1171 hr_utility.trace('action type is ' || p_pact_rec.action_type );
1172 end if;
1173 --
1174 --
1175 -- some types (e.g, purge) of action can't be rolled back full stop.
1176 declare
1177 dummy number;
1178 begin
1179 if g_debug then
1180 hr_utility.set_location('hrassact.val_pact_rollback', 20);
1181 end if;
1182 select null
1183 into dummy
1184 from dual
1185 where not exists
1186 (select null
1187 from pay_action_classifications
1188 where action_type = p_pact_rec.action_type
1189 and classification_name = 'NONREMOVEABLE');
1190 exception
1191 when no_data_found then
1192 hr_utility.set_message(801, 'HR_6216_ACTION_CANT_PURGE');
1193 hr_utility.set_message_token('PACT_ID',
1194 to_char(p_pact_rec.pact_id));
1195 hr_utility.raise_error;
1196 end;
1197 --
1198 --
1199 -- get some more info needed to roll back actions
1200 if g_debug then
1201 hr_utility.set_location('hrassact.val_pact_rollback', 30);
1202 end if;
1203 if upper( hr_leg_rule.get_independent_periods(l_business_group_id))
1204 like 'Y%' then
1205 p_pact_rec.independent_periods_flag := TRUE;
1206 else
1207 p_pact_rec.independent_periods_flag := FALSE;
1208 end if;
1209 --
1210 --
1211 -- see if this type of action is sequenced or not
1212 declare
1213 dummy number;
1214 begin
1215 p_pact_rec.sequenced_flag := TRUE;
1216 --
1217 if g_debug then
1218 hr_utility.set_location('hrassact.val_pact_rollback', 40);
1219 end if;
1220 select null
1221 into dummy
1222 from pay_action_classifications CLASS
1223 where CLASS.action_type = p_pact_rec.action_type
1224 and CLASS.classification_name = 'SEQUENCED';
1225 if g_debug then
1226 hr_utility.trace('this action type IS sequenced');
1227 end if;
1228 exception
1229 when no_data_found then
1230 p_pact_rec.sequenced_flag := FALSE;
1231 if g_debug then
1232 hr_utility.trace('this action type NOT sequenced');
1233 end if;
1234 end;
1235 end val_pact_rollback;
1236 --
1237 --
1238 procedure validate_pact_rollback
1239 (
1240 p_payroll_action_id in number,
1241 p_rollback_mode in varchar2
1242 ) is
1243 l_pact_rec pact_details;
1244 begin
1245 g_debug := hr_utility.debug_enabled;
1246 --
1247 -- We simply call the internal validate rollback procedure
1248 -- to give us the information we need.
1249 if g_debug then
1250 hr_utility.set_location('hrassact.validate_pact_rollback', 10);
1251 end if;
1252 l_pact_rec.pact_id := p_payroll_action_id;
1253 --
1254 val_pact_rollback(p_pact_rec => l_pact_rec,
1255 p_rollback_mode => p_rollback_mode);
1256 --
1257 -- Rollback and Mark for retry rules
1258 val_pact_rr_rules(l_pact_rec, p_rollback_mode);
1259 --
1260 end validate_pact_rollback;
1261 --
1262 /*----------------------- validate_assact_rollback -------------------------*/
1263 /*
1264 * This procedure is an overloaded public procedure to validate a
1265 * particular assignment action.
1266 */
1267 function validate_assact_rollback
1268 (
1269 p_payroll_action_id in number,
1270 p_assignment_action_id in number,
1271 p_rollback_mode in varchar2
1272 ) return boolean is
1273 l_pact_rec pact_details;
1274 l_assact_rec assact_details;
1275 result boolean;
1276 begin
1277 g_debug := hr_utility.debug_enabled;
1278 --
1279 -- Call the validate payroll action routine to get pact details.
1280 if g_debug then
1281 hr_utility.set_location('hrassact.validate_assact_rollback',10);
1282 end if;
1283 l_pact_rec.pact_id := p_payroll_action_id;
1284 val_pact_rollback(p_pact_rec => l_pact_rec,
1285 p_rollback_mode => p_rollback_mode);
1286 --
1287 -- Call the validate assignment action routine to validate assact.
1288 if g_debug then
1289 hr_utility.set_location('hrassact.validate_assact_rollback',20);
1290 end if;
1291 l_assact_rec.assact_id := p_assignment_action_id;
1292 --
1293 if val_assact_rollback(l_pact_rec, l_assact_rec, p_rollback_mode) and
1294 val_assact_rr_rules(l_pact_rec, p_rollback_mode)
1295 then
1296 return true;
1297 else
1298 return false;
1299 end if;
1300 end validate_assact_rollback;
1301 --
1302 --
1303 --
1304 /*----------------------- trash_quickpay ----------------------------*/
1305 /*
1306 * This procedure removes any entries inserted for a Quickpay action
1307 */
1308 procedure trash_quickpay (p_action_id number) is
1309 cursor c1 is
1310 select pee.element_entry_id
1311 from pay_element_entries_f pee,
1312 pay_assignment_actions paa
1313 where pee.creator_type = 'Q'
1314 and pee.creator_id = paa.assignment_action_id
1315 and pee.assignment_id = paa.assignment_id
1316 and paa.assignment_action_id = p_action_id
1317 for update of pee.element_entry_id;
1318 --
1319 begin
1320 -- For QuickPay actions, we delete the entries which were
1321 -- inserted as part of the Quickpay transaction. Any processed run
1322 -- results were trashed in a previous step.
1323 begin
1324 -- We wish to remove the QuickPay inclusions.
1325 if g_debug then
1326 hr_utility.set_location('hrassact.trash_quickpay',10);
1327 end if;
1328 --
1329 -- Enhancement 3368211
1330 -- Delete from both PAY_QUICKPAY_INCLUSIONS and
1331 -- PAY_QUICKPAY_EXCLUSIONS.
1332 --
1333 -- There is a chance the assignment action id exists in both tables if
1334 -- the assignment action was created before the QuickPay Exclusions
1335 -- data model was in use.
1336 delete from pay_quickpay_exclusions
1337 where assignment_action_id = p_action_id;
1338 --
1339 delete from pay_quickpay_inclusions
1340 where assignment_action_id = p_action_id;
1341 --
1342 if g_debug then
1343 hr_utility.set_location('hrassact.trash_quickpay',20);
1344 end if;
1345 for c1rec in c1 loop
1346 --
1347 -- delete any unprocessed run result attached to the entry.
1348 if g_debug then
1349 hr_utility.set_location('hrassact.trash_quickpay',30);
1350 end if;
1351 delete from pay_run_result_values RRV
1352 where RRV.run_result_id in
1353 (select RR.run_result_id
1354 from pay_run_results RR
1355 where RR.source_type = 'E'
1356 and RR.source_id = c1rec.element_entry_id);
1357 --
1358 if g_debug then
1359 hr_utility.set_location('hrassact.trash_quickpay',40);
1360 end if;
1361 delete from pay_run_results RR
1362 where RR.source_type = 'E'
1363 and RR.source_id = c1rec.element_entry_id;
1364 --
1365 -- delete any element entry values
1366 if g_debug then
1367 hr_utility.set_location('hrassact.trash_quickpay',50);
1368 end if;
1369 delete from pay_element_entry_values_f EEV
1370 where EEV.element_entry_id = c1rec.element_entry_id;
1371 --
1372 -- delete the entry itself
1373 if g_debug then
1374 hr_utility.set_location('hrassact.trash_quickpay',60);
1375 end if;
1376 delete from pay_element_entries_f
1377 where current of c1;
1378 --
1379 end loop;
1380 end;
1381 --
1382 if g_debug then
1383 hr_utility.set_location('hrassact.trash_quickpay',60);
1384 end if;
1385 return;
1386 --
1387 end trash_quickpay;
1388 --
1389 --
1390 --
1391
1392 /*------------------------ undo_stop_update -----------------------------*/
1393 /*
1394 * This procedure is called when we have detected the need to undo the
1395 * effect of a stop or update recurring entry formula result rule.
1396 * Note that, due to the complexity of calculating entry end dates, we
1397 * call the existing routine, but trap error messages that are
1398 * inappropriate for our application.
1399 */
1400 procedure undo_stop_update(
1401 p_ee_id in number,
1402 p_mult in varchar,
1403 p_date in date,
1404 p_mode in varchar2) is
1405 --
1406 -- Local variables.
1407 effstart date;
1408 effend date;
1409 val_start date;
1410 val_end date;
1411 next_end date;
1412 orig_ee_id number;
1413 asg_id number;
1414 el_id number;
1415 c_indent constant varchar2(30) := 'pyassact.undo_stop_update';
1416 begin
1417 -- Select some information about the entry we are operating on.
1418 if g_debug then
1419 hr_utility.set_location(c_indent, 10);
1420 end if;
1421 select pee.effective_start_date,
1422 pee.effective_end_date,
1423 pee.original_entry_id,
1424 pee.assignment_id,
1425 pee.element_link_id
1426 into effstart, effend, orig_ee_id, asg_id, el_id
1427 from pay_element_entries_f pee
1428 where pee.element_entry_id = p_ee_id
1429 and p_date between
1430 pee.effective_start_date and pee.effective_end_date;
1431 --
1432 -- Do nothing if the entry end date is end of time.
1433 if(effend = c_eot) then
1434 return;
1435 end if;
1436 --
1437 -- For undo update, we have to get next effective start date.
1438 if(p_mode = 'DELETE_NEXT_CHANGE') then
1439 begin
1440 if g_debug then
1441 hr_utility.set_location(c_indent, 20);
1442 end if;
1443 select min(ee.effective_end_date)
1444 into next_end
1445 from pay_element_entries_f ee
1446 where ee.element_entry_id = p_ee_id
1447 and ee.effective_start_date > effend;
1448 exception
1449 when no_data_found then null;
1450 end;
1451 --
1452 val_start := effend + 1;
1453 --
1454 if next_end is null then
1455 val_end := c_eot;
1456 else
1457 val_end := next_end;
1458 end if;
1459 elsif(p_mode = 'FUTURE_CHANGE') then
1460 val_start := effend + 1;
1461 val_end := c_eot;
1462 end if;
1463 --
1464 -- For either mode, we need to obtain the date to which
1465 -- we may legally extend the entry.
1466 declare
1467 message varchar2(200);
1468 applid varchar2(200);
1469 begin
1470 val_end := hr_entry.recurring_entry_end_date (
1471 asg_id, el_id, p_date, 'Y', p_mult, p_ee_id, orig_ee_id);
1472 exception
1473 -- Several error messages can be raised from this procedure.
1474 -- We wish to trap a number of them, as they should be ignored
1475 -- for our purposes.
1476 when hr_utility.hr_error then
1477 hr_utility.get_message_details(message,applid);
1478 --
1479 if(message in ('HR_7699_ELE_ENTRY_REC_EXISTS',
1480 'HR_7700_ELE_ENTRY_REC_EXISTS',
1481 'HR_6281_ELE_ENTRY_DT_DEL_LINK',
1482 'HR_6283_ELE_ENTRY_DT_ELE_DEL',
1483 'HR_6284_ELE_ENTRY_DT_ASG_DEL')
1484 ) then
1485 -- We cannot extend the entry.
1486 if g_debug then
1487 hr_utility.set_location(c_indent, 25);
1488 end if;
1489 return;
1490 else
1491 -- Should fail if it is anything else.
1492 raise;
1493 end if;
1494 end;
1495 --
1496 -- May need to check for entry overlap.
1497 if(p_mult = 'N') then
1498 --
1499 declare dummy number;
1500 begin
1501 if g_debug then
1502 hr_utility.set_location(c_indent, 30);
1503 end if;
1504 select null
1505 into dummy
1506 from pay_element_entries_f ee
1507 where ee.entry_type = 'E'
1508 and ee.element_entry_id <> p_ee_id
1509 and ee.assignment_id = asg_id
1510 and ee.element_link_id = el_id
1511 and (ee.effective_start_date <= val_end and
1512 ee.effective_end_date >= val_start);
1513 --
1514 -- If row returned, we are in trouble.
1515 hr_utility.set_message(801, 'HR_6956_ELE_ENTRY_OVERLAP');
1516 hr_utility.raise_error;
1517 --
1518 exception
1519 when no_data_found then null;
1520 end;
1521 end if;
1522 --
1523 -- May need to set validation end date to the end of time.
1524 if((p_mode = 'FUTURE_CHANGE') or
1525 (p_mode = 'DELETE_NEXT_CHANGE' and
1526 val_end = c_eot)
1527 ) then
1528 effend := val_end;
1529 end if;
1530 --
1531 -- Process the delete of element entries.
1532 if(p_mode = 'DELETE_NEXT_CHANGE') then
1533 if g_debug then
1534 hr_utility.set_location(c_indent, 40);
1535 end if;
1536 delete from pay_element_entries_f ee
1537 where ee.element_entry_id = p_ee_id
1538 and ee.effective_start_date = val_start;
1539 --
1540 if g_debug then
1541 hr_utility.set_location(c_indent, 50);
1542 end if;
1543 update pay_element_entries_f ee
1544 set ee.effective_end_date = decode(val_end, c_eot, effend, val_end)
1545 where ee.element_entry_id = p_ee_id
1546 and ee.effective_start_date = effstart;
1547 --
1548 elsif(p_mode = 'FUTURE_CHANGE') then
1549 --
1550 if g_debug then
1551 hr_utility.set_location(c_indent, 60);
1552 end if;
1553 delete from pay_element_entries_f ee
1554 where ee.element_entry_id = p_ee_id
1555 and ee.effective_start_date > effstart;
1556 --
1557 if g_debug then
1558 hr_utility.set_location(c_indent, 70);
1559 end if;
1560 update pay_element_entries_f ee
1561 set ee.effective_end_date = effend
1562 where ee.element_entry_id = p_ee_id
1563 and ee.effective_start_date = effstart;
1564 end if;
1565 --
1566 -- Now, delete the entry values between validation start/end dates..
1567 --
1568 if g_debug then
1569 hr_utility.set_location(c_indent, 80);
1570 end if;
1571 delete from pay_element_entry_values_f eev
1572 where eev.element_entry_id = p_ee_id
1573 and ((eev.effective_end_date between val_start and val_end)
1574 or (eev.effective_start_date between val_start and val_end));
1575 --
1576 -- Update the effective end date as appropriate.
1577 if g_debug then
1578 hr_utility.set_location(c_indent, 90);
1579 end if;
1580 update pay_element_entry_values_f eev
1581 set eev.effective_end_date = val_end
1582 where eev.element_entry_id = p_ee_id
1583 and p_date between
1584 eev.effective_start_date and eev.effective_end_date;
1585 --
1586 end undo_stop_update;
1587 --
1588 /*----------------------- do_assact_rollback ---------------------------*/
1589 /*
1590 *
1591 * This procedure performs all third party DML and validation
1592 * needed to support the rollback, mark for retry or mark
1593 * for backpay of an assignment action.
1594 *
1595 * For the definitive list of action types, see the ACTION TYPE
1596 * domain in CASE.
1597 *
1598 * Any deletes of child records which should only be performed for
1599 * rollback, rather than for both retry and rollback, are performed
1600 * either via cascading constraints or via the delete trigger on
1601 * assignment actions.
1602 *
1603 */
1604 procedure do_assact_rollback (p_pact_rec in pact_details,
1605 p_assact_rec in assact_details,
1606 p_rollback_mode in varchar2,
1607 p_leave_base_table_row in boolean) is
1608 begin
1609 --
1610 if p_pact_rec.sequenced_flag then
1611 --
1612 -- Delete any Run Results which were created by this action. This
1613 -- will have no effect for unsequenced actions such as
1614 -- Pre-Payments. For efficiency there should be no cascade
1615 -- trigger on Run Results so we need to trash the values as well.
1616 if g_debug then
1617 hr_utility.set_location('hrassact.do_assact_rollback',10);
1618 end if;
1619 delete from pay_run_result_values RRV
1620 where RRV.run_result_id in
1621 (select RR.run_result_id
1622 from pay_run_results RR
1623 where RR.assignment_action_id = p_assact_rec.assact_id);
1624 --
1625 if g_debug then
1626 hr_utility.set_location('hrassact.do_assact_rollback',20);
1627 end if;
1628 delete from pay_run_results RR
1629 where RR.assignment_action_id = p_assact_rec.assact_id;
1630 --
1631 -- Delete latest balances. Not deleted via constraint due to
1632 -- performance requirements on Insert and Update, and also because
1633 -- they need to go for retry as well as rollback.
1634 -- Start with any balance context values.
1635 if g_debug then
1636 hr_utility.set_location('hrassact.do_assact_rollback',25);
1637 end if;
1638 delete from pay_balance_context_values VAL
1639 where exists (
1640 select null
1641 from pay_person_latest_balances PLB
1642 where PLB.assignment_action_id = p_assact_rec.assact_id
1643 and VAL.latest_balance_id = PLB.latest_balance_id);
1644 --
1645 if g_debug then
1646 hr_utility.set_location('hrassact.do_assact_rollback',30);
1647 end if;
1648 delete from pay_person_latest_balances PLB
1649 where PLB.assignment_action_id = p_assact_rec.assact_id;
1650 --
1651 if g_debug then
1652 hr_utility.set_location('hrassact.do_assact_rollback',35);
1653 end if;
1654 delete from pay_balance_context_values VAL
1655 where exists (
1656 select null
1657 from pay_assignment_latest_balances ALB
1658 where ALB.assignment_action_id = p_assact_rec.assact_id
1659 and VAL.latest_balance_id = ALB.latest_balance_id);
1660 --
1661 if g_debug then
1662 hr_utility.set_location('hrassact.do_assact_rollback',40);
1663 end if;
1664 delete from pay_assignment_latest_balances ALB
1665 where ALB.assignment_action_id = p_assact_rec.assact_id;
1666 --
1667 -- If the payroll action that is being deleted is
1668 -- a Balance Adjustment (type = 'B'), then we attempt to
1669 -- delete the element entry row and element entry rows
1670 -- that are associated with it.
1671 if p_pact_rec.action_type = 'B' then
1672 -- Do the business for Balance Adjustment.
1673 declare
1674 v_eeid number; -- the element entry id.
1675 begin
1676 -- Start by selecting the element_entry_id
1677 -- that we need to delete.
1678 -- We are joining effective dates only to hit the whole
1679 -- index, because there should only be the one row anyway.
1680 -- hr_utility.set_location('hrassact.do_assact_rollback',50);
1681 select pee.element_entry_id
1682 into v_eeid
1683 from pay_element_entries_f pee
1684 where pee.creator_id = p_assact_rec.assact_id
1685 and pee.assignment_id = p_assact_rec.assignment_id
1686 and p_pact_rec.action_date between
1687 pee.effective_start_date and pee.effective_end_date;
1688 --
1689 -- Now, we attempt to delete the entry values.
1690 -- hr_utility.set_location('hrassact.do_assact_rollback',60);
1691 delete from pay_element_entry_values_f pev
1692 where pev.element_entry_id = v_eeid
1693 and p_pact_rec.action_date between
1694 pev.effective_start_date and pev.effective_end_date;
1695 --
1696 -- Now we attempt to delete the element entry row.
1697 -- Note, if this procedure is called from the balance
1698 -- adjustment row, the form may be attempting to delete
1699 -- this row. However, this could be called from the
1700 -- actions form, in which case we do need to do the delete.
1701 -- hr_utility.set_location('hrassact.do_assact_rollback',70);
1702 delete from pay_element_entries_f pee
1703 where pee.element_entry_id = v_eeid
1704 and p_pact_rec.action_date between
1705 pee.effective_start_date and pee.effective_end_date;
1706 end;
1707 else
1708 -- Now process for Non balance adjustment case.
1709 --
1710 -- The following section is designed to undo any changes
1711 -- to Recurring element entries that have been made by
1712 -- the Payroll Run, via Update and Stop REE rules.
1713 -- Note, we have to perform some extra joins to check
1714 -- that we are only picking up recurring element entries.
1715 declare
1716 cursor c1 is
1717 select pet.multiple_entries_allowed_flag,
1718 pee.element_entry_id,
1719 pee.updating_action_id,
1720 pee.effective_start_date,
1721 pee.effective_end_date
1722 from pay_element_types_f pet,
1723 pay_element_links_f pel,
1724 pay_element_entries_f pee
1725 where pee.assignment_id = p_assact_rec.assignment_id
1726 and pee.entry_type = 'E'
1727 and p_pact_rec.action_date between
1728 pee.effective_start_date and pee.effective_end_date
1729 and pel.element_link_id = pee.element_link_id
1730 and p_pact_rec.action_date between
1731 pel.effective_start_date and pel.effective_end_date
1732 and pet.element_type_id = pel.element_type_id
1733 and p_pact_rec.action_date between
1734 pel.effective_start_date and pel.effective_end_date
1735 and pet.processing_type = 'R';
1736 --
1737 v_max_date date; -- max effective date of element entry.
1738 begin
1739 -- Loop through all the standard entries for the assignment
1740 -- and attempt to undo changes that have been made by
1741 -- stop and update REE rules. We cannot be guaranteed
1742 -- to undo changes in their entirety, since we do not
1743 -- have all the information we need to hand, but we
1744 -- perform delete next change.
1745 if g_debug then
1746 hr_utility.set_location('hrassact.do_assact_rollback',80);
1747 end if;
1748 for c1rec in c1 loop
1749 -- First, look for possible stop rule case.
1750 if(c1rec.effective_end_date = p_pact_rec.action_date) then
1751 -- We may have a stopped entry, but we need to
1752 -- see if this really is the case.
1753 if g_debug then
1754 hr_utility.set_location('hrassact.do_assact_rollback',90);
1755 end if;
1756 select max(pee.effective_end_date)
1757 into v_max_date
1758 from pay_element_entries_f pee
1759 where pee.element_entry_id = c1rec.element_entry_id;
1760 --
1761 if(v_max_date = p_pact_rec.action_date) then
1762 -- This entry has been chopped off. We assume
1763 -- it has been performed by the Payroll Run.
1764 -- Call the ee api to delete next change.
1765 undo_stop_update (c1rec.element_entry_id,
1766 c1rec.multiple_entries_allowed_flag,
1767 p_pact_rec.action_date,
1768 'FUTURE_CHANGE');
1769 end if;
1770 end if; -- stop rule.
1771 --
1772 -- Now, we look for an Update Rule Case.
1773 -- Here we need to see if there is a record
1774 -- whoes effective start date is the same as
1775 -- that of the run, and the updating_action_id of
1776 -- the entry is the same as the assignment_action_id
1777 -- and there exists a previous record with effective
1778 -- end date of the previous day (i.e. a date effective
1779 -- update has occurred).
1780 if(c1rec.effective_start_date = p_pact_rec.action_date
1781 and c1rec.updating_action_id = p_assact_rec.assact_id)
1782 then
1783 -- Note, in following select, use max to avoid
1784 -- having to deal with no data found error.
1785 if g_debug then
1786 hr_utility.set_location('hrassact.do_assact_rollback',110);
1787 end if;
1788 select max(pee.effective_end_date)
1789 into v_max_date
1790 from pay_element_entries_f pee
1791 where pee.element_entry_id = c1rec.element_entry_id
1792 and pee.effective_end_date = (p_pact_rec.action_date - 1);
1793 --
1794 if(v_max_date is not null) then
1795 -- Ok, there is a previous record. We now wish
1796 -- to delete future changes on that record.
1797 undo_stop_update (c1rec.element_entry_id,
1798 c1rec.multiple_entries_allowed_flag,
1799 (p_pact_rec.action_date - 1),
1800 'DELETE_NEXT_CHANGE');
1801 else
1802 -- In the case where there is no previous record,
1803 -- the update was previously a correction. This
1804 -- means we need to set the updating_action_id
1805 -- to null.
1806 if g_debug then
1807 hr_utility.set_location('hrassact.do_assact_rollback',130);
1808 end if;
1809 update pay_element_entries_f pee
1810 set pee.updating_action_id = null
1811 where pee.element_entry_id = c1rec.element_entry_id
1812 and p_pact_rec.action_date between
1813 pee.effective_start_date and pee.effective_end_date;
1814 end if;
1815 end if;
1816 end loop;
1817 end;
1818 end if; -- end of Balance Adjustment specific stuff.
1819 --
1820 end if; -- end of actions specific to SEQUENCED actions
1821 --
1822 --
1823 -- delete any messages associated with the assignment action.
1824 if g_debug then
1825 hr_utility.set_location('hrassact.do_assact_rollback',140);
1826 end if;
1827 delete from pay_message_lines ML
1828 where ML.source_type = 'A'
1829 and ML.source_id = p_assact_rec.assact_id;
1830 --
1831 if(p_pact_rec.action_type in ('P','U')) then
1832 -- Need to delete pre-payment rows.
1833 -- Originally left it to the data base, but
1834 -- that meant that rows were not deleted
1835 -- in retry mode.
1836 -- Note, the delete of a pre-payment row causes
1837 -- a cascade delete from pay_coin_anal_elements.
1838 if g_debug then
1839 hr_utility.set_location('hrassact.do_assact_rollback',150);
1840 end if;
1841 delete from pay_pre_payments ppp
1842 where ppp.assignment_action_id = p_assact_rec.assact_id;
1843 end if;
1844 --
1845 if(p_pact_rec.action_type = 'C') then
1846 -- Delete from the costing table.
1847 delete from pay_costs
1848 where assignment_action_id = p_assact_rec.assact_id;
1849 end if;
1850 --
1851 /*
1852 * ROLLBACK specific code
1853 */
1854 if p_rollback_mode = 'ROLLBACK' then
1855 --
1856 -- Write a message to payroll action level to indicate
1857 -- that the action has been rolled back.
1858 --
1859 declare
1860 mesg_text pay_message_lines.line_text%type;
1861 begin
1862 hr_utility.set_message (801, 'HR_ACTION_ASACT_ROLLOK');
1863 hr_utility.set_message_token
1864 ('ASG_NUMBER',p_assact_rec.assignment_number);
1865 hr_utility.set_message_token
1866 ('FULL_NAME',p_assact_rec.full_name);
1867 hr_utility.set_message_token
1868 ('SYSDATE',fnd_date.date_to_canonical(p_pact_rec.current_date));
1869 mesg_text := substrb(hr_utility.get_message,1,240);
1870 --
1871 -- now write our message to the payroll_action level. We
1872 -- want to spit out the asssignment's current Payroll ID as well.
1873 if g_debug then
1874 hr_utility.set_location('hrassact.do_assact_rollback',160);
1875 end if;
1876 insert into pay_message_lines
1877 (line_sequence,
1878 payroll_id,
1879 message_level,
1880 source_id,
1881 source_type,
1882 line_text
1883 )
1884 values
1885 (pay_message_lines_s.nextval,
1886 p_assact_rec.payroll_id,
1887 'I', -- Information level
1888 p_pact_rec.pact_id,
1889 'P',
1890 mesg_text
1891 );
1892 end;
1893 --
1894 if p_pact_rec.action_type = 'Q' then
1895 trash_quickpay (p_action_id => p_assact_rec.assact_id);
1896 end if;
1897 --
1898 end if;
1899 --
1900 -- see if we want to alter the assignment action itself (we wouldn't
1901 -- if we were being called from a form)
1902 if not p_leave_base_table_row then
1903 if p_rollback_mode = 'RETRY' then
1904 if g_debug then
1905 hr_utility.set_location('hrassact.do_assact_rollback',170);
1906 end if;
1907 update pay_assignment_actions
1908 set action_status = 'M'
1909 where assignment_action_id = p_assact_rec.assact_id;
1910 --
1911 elsif p_rollback_mode = 'BACKPAY' then
1912 if g_debug then
1913 hr_utility.set_location('hrassact.do_assact_rollback',180);
1914 end if;
1915 update pay_assignment_actions
1916 set action_status = 'B'
1917 where assignment_action_id = p_assact_rec.assact_id;
1918 --
1919 elsif p_rollback_mode = 'ROLLBACK' then
1920 -- there may be pay_action_interlock rows.
1921 -- which are locking other assignment actions.
1922 if g_debug then
1923 hr_utility.set_location('hrassact.do_assact_rollback',190);
1924 end if;
1925 delete from pay_action_interlocks lck
1926 where lck.locking_action_id = p_assact_rec.assact_id;
1927 --
1928 if g_debug then
1929 hr_utility.set_location('hrassact.do_assact_rollback',200);
1930 end if;
1931 delete from pay_assignment_actions
1932 where assignment_action_id = p_assact_rec.assact_id;
1933 end if;
1934 else
1935 -- In the case of rolling back (from the form), we
1936 -- still need to delete interlock rows. Of course,
1937 -- in this case we do not delete the action.
1938 if(p_rollback_mode = 'ROLLBACK') then
1939 if g_debug then
1940 hr_utility.set_location('hrassact.do_assact_rollback',210);
1941 end if;
1942 delete from pay_action_interlocks lck
1943 where lck.locking_action_id = p_assact_rec.assact_id;
1944 end if;
1945 end if;
1946 --
1947 if g_debug then
1948 hr_utility.set_location('hrassact.do_assact_rollback',220);
1949 end if;
1950 return;
1951 --
1952 end do_assact_rollback;
1953 --
1954 --
1955 --
1956 /*----------------------- do_pact_rollback ----------------------*/
1957 /*
1958 * This routine performs the actual work of rolling back a
1959 * payroll action. See the description of the three overloaded
1960 * calls which use this internal function for details.
1961 *
1962 */
1963 procedure do_pact_rollback
1964 (p_payroll_action_id in number,
1965 p_chunk_size in number default 200,
1966 p_all_or_nothing in boolean default TRUE,
1967 p_failed_assact in out nocopy number,
1968 p_rollback_mode in varchar2,
1969 p_leave_base_table_row in boolean) is
1970 --
1971 l_pact_rec pact_details; -- payroll action details
1972 l_assact_rec assact_details; -- assignment action details
1973 l_cur_aseq number; -- Current action_sequence.
1974 l_counter number; -- counts number of actions processed
1975 -- within one chunk.
1976 c_indent constant varchar2(30) := 'pyassact.do_pact_rollback';
1977 --
1978 begin
1979
1980 -- populate payroll action details and perform high level validation
1981 l_pact_rec.pact_id := p_payroll_action_id;
1982 if g_debug then
1983 hr_utility.set_location(c_indent, 10);
1984 end if;
1985 val_pact_rollback(p_pact_rec => l_pact_rec,
1986 p_rollback_mode => p_rollback_mode);
1987 --
1988 -- Rollback and Mark for retry rules
1989 val_pact_rr_rules(l_pact_rec, p_rollback_mode);
1990 --
1991 -- assume things will go well for us
1992 p_failed_assact := null;
1993 --
1994 -- If a process has failed disasterously, there could
1995 -- be range rows still hanging around. Need to trash these.
1996 delete from pay_population_ranges ppr
1997 where ppr.payroll_action_id = p_payroll_action_id;
1998 --
1999 -- We need to roll back assignment actions in reverse order
2000 -- from high action_sequence down (for multiple assignments).
2001 -- Therefore, start by selecting the max action_sequence.
2002 if g_debug then
2003 hr_utility.set_location(c_indent, 20);
2004 end if;
2005 select max(act.action_sequence) + 1
2006 into l_cur_aseq
2007 from pay_assignment_actions act
2008 where act.payroll_action_id = p_payroll_action_id;
2009 --
2010 -- now roll back each assignment action in turn (lock as we go)
2011 declare
2012 more_actions boolean;
2013 --
2014 -- This cursor retrieves all target assignment actions which
2015 -- have not already been considered for rolling back.
2016 -- It used to use rownum to restrict the fetch to a chunk of
2017 -- assignment actions. However, rownum and the ordering worked
2018 -- in opposite directions, leading to the code only processing
2019 -- the first chunk.
2020 cursor c1 is
2021 select act.assignment_action_id,
2022 act.action_sequence
2023 from pay_assignment_actions act
2024 where act.payroll_action_id = p_payroll_action_id
2025 and act.action_sequence < l_cur_aseq
2026 order by act.action_sequence desc
2027 for update of act.action_status;
2028 begin
2029 --
2030 --
2031 -- The outer loop handles chunks of assignment actions,
2032 -- We delete a chunk of assignment actions at a time,
2033 -- using supplied parameter value, we do not use the
2034 -- existing chunks.
2035 -- To keep commit unit size down, a local counter is incremented
2036 -- each time an assignment action is rolled back or marked for
2037 -- retry (as opposed to when the action is considered for
2038 -- processing, but rejected, and hence, no db change ensues).
2039 --
2040 more_actions := TRUE; -- Set this to satisfy the while condition.
2041 while(more_actions) loop
2042 more_actions := FALSE;
2043 l_counter := 0;
2044 --
2045 if g_debug then
2046 hr_utility.set_location(c_indent,30);
2047 end if;
2048 for c1rec in c1 loop
2049 exit when l_counter = p_chunk_size;
2050 more_actions := TRUE;
2051 --
2052 -- Set this variable so that when we re-open cursor c1, for
2053 -- the next chunk, we don't reprocess the actions we've
2054 -- dealt with already.
2055 l_cur_aseq := c1rec.action_sequence;
2056 --
2057 -- see if OK to roll back or retry this assignment action
2058 l_assact_rec.assact_id := c1rec.assignment_action_id;
2059 if g_debug then
2060 hr_utility.set_location(c_indent,40);
2061 end if;
2062 if val_assact_rollback
2063 (p_pact_rec => l_pact_rec,
2064 p_assact_rec => l_assact_rec,
2065 p_rollback_mode => p_rollback_mode) then
2066 --
2067 -- OK, clean up all child records for the action
2068 if g_debug then
2069 hr_utility.set_location(c_indent,50);
2070 end if;
2071 do_assact_rollback
2072 (p_pact_rec => l_pact_rec,
2073 p_assact_rec => l_assact_rec,
2074 p_rollback_mode => p_rollback_mode,
2075 p_leave_base_table_row => FALSE);
2076 -- We've just processed another assignment action, so
2077 -- increment the counter.
2078 l_counter := l_counter + 1;
2079 --
2080 else
2081 -- We have detected that an assignment action
2082 -- should not be rolled back. We set a parameter
2083 -- value to tell the outside world.
2084 -- Only set if null, because several assignment
2085 -- actions could fail, and we wish to report on
2086 -- the first of these
2087 if p_failed_assact is null then
2088 p_failed_assact := c1rec.assignment_action_id;
2089 end if;
2090 --
2091 -- decide whether to leap out entirely
2092 if p_all_or_nothing then
2093 hr_utility.set_message(801, 'HR_7008_ACTION_CANT_ROLLBACK');
2094 hr_utility.set_message_token
2095 ('FAILING_ASSACT', to_char(c1rec.assignment_action_id));
2096 hr_utility.raise_error;
2097 end if;
2098 end if;
2099 --
2100 end loop; -- cursor loop.
2101 --
2102 if not p_all_or_nothing then
2103 commit;
2104 end if;
2105 --
2106 end loop; -- loop round for next chunk.
2107 --
2108 end;
2109 --
2110 -- trash messages
2111 if g_debug then
2112 hr_utility.set_location(c_indent,60);
2113 end if;
2114 delete from pay_message_lines ML
2115 where ML.source_type = 'P'
2116 and ML.source_id = p_payroll_action_id;
2117 --
2118 -- now trash the payroll action itself if the user so desires (and if
2119 -- all assignment actions where successfully rolled back).
2120 if g_debug then
2121 hr_utility.set_location(c_indent,70);
2122 end if;
2123 if not p_leave_base_table_row and p_failed_assact is null then
2124 --
2125 --
2126 -- Now we need to have a message to indicate
2127 -- that the payroll action was rolled back.
2128 -- We start by checking the payroll action type.
2129 -- If that is Magnetic Transfer, we wish to
2130 -- select the actual payment type (thus giving
2131 -- us BACS or NACHA or whatever, before generating
2132 -- the message.
2133 if(l_pact_rec.action_type = 'M') then
2134 if g_debug then
2135 hr_utility.set_location(c_indent,90);
2136 end if;
2137 select ppt_tl.payment_type_name
2138 into l_pact_rec.action_name
2139 from pay_payroll_actions pac,
2140 pay_payment_types_tl ppt_tl,
2141 pay_payment_types ppt
2142 where pac.payroll_action_id = l_pact_rec.pact_id
2143 and ppt.payment_type_id = pac.payment_type_id
2144 and ppt_tl.payment_type_id = ppt.payment_type_id
2145 and userenv('LANG') = ppt_tl.language;
2146 end if;
2147 --
2148 -- We now need to set up the message, depending on whether
2149 -- the payroll_id is null or not.
2150 declare
2151 mesg_text pay_message_lines.line_text%type;
2152 begin
2153 if(l_pact_rec.payroll_name is null) then
2154 -- Set up message for no payroll case.
2155 hr_utility.set_message(801,'HR_ACTION_PACT_ROLLNOPAY');
2156 hr_utility.set_message_token('ACTION_TYPE',l_pact_rec.action_name);
2157 hr_utility.set_message_token('BG_NAME',l_pact_rec.bg_name);
2158 hr_utility.set_message_token('SYSDATE',
2159 fnd_date.date_to_canonical(l_pact_rec.current_date));
2160 else
2161 -- Set up message for payroll case.
2162 hr_utility.set_message(801,'HR_ACTION_PACT_ROLLPAY');
2163 hr_utility.set_message_token('ACTION_TYPE',l_pact_rec.action_name);
2164 hr_utility.set_message_token('PAYROLL_NAME',
2165 l_pact_rec.payroll_name);
2166 hr_utility.set_message_token('BG_NAME',l_pact_rec.bg_name);
2167 hr_utility.set_message_token('SYSDATE',
2168 fnd_date.date_to_canonical(l_pact_rec.current_date));
2169 end if;
2170 mesg_text := substrb(hr_utility.get_message,1,240);
2171 --
2172 if g_debug then
2173 hr_utility.set_location(c_indent,100);
2174 end if;
2175 insert into pay_message_lines (
2176 line_sequence,
2177 payroll_id,
2178 message_level,
2179 source_id,
2180 source_type,
2181 line_text)
2182 select pay_message_lines_s.nextval,
2183 pac.payroll_id,
2184 'I', -- information.
2185 pac.business_group_id,
2186 'B',
2187 mesg_text
2188 from pay_payroll_actions pac
2189 where pac.payroll_action_id = l_pact_rec.pact_id;
2190
2191 end;
2192 --
2193 if g_debug then
2194 hr_utility.set_location(c_indent,80);
2195 end if;
2196 delete from pay_payroll_actions
2197 where payroll_action_id = p_payroll_action_id;
2198 --
2199 if not p_all_or_nothing then
2200 if g_debug then
2201 hr_utility.set_location(c_indent,110);
2202 end if;
2203 commit;
2204 end if;
2205 --
2206 end if;
2207 --
2208 if g_debug then
2209 hr_utility.set_location(c_indent,120);
2210 end if;
2211 return;
2212 --
2213 end do_pact_rollback;
2214 --
2215 --
2216 --
2217 /*----------------------- rollback_payroll_action ----------------------*/
2218 /*
2219 * This routine rolls back an entire payroll action.
2220 *
2221 * Three forms are available:
2222 *
2223 * 1) Rollback entire action without committing, fail if any individual
2224 * assignment action couldn't be rolled back.
2225 *
2226 * 2) Rollback entire action without committing, continue if any
2227 * assignment action couldn't be rolled back, setting
2228 * p_failed_assact to indicate the problematic action.
2229 *
2230 * 3) Same as previous form, but commit in chunks as processing
2231 * continues to avoid huge rollback segments.
2232 *
2233 * p_rollback_mode must be either ROLLBACK or RETRY
2234 */
2235 --
2236 procedure rollback_payroll_action
2237 (p_payroll_action_id in number,
2238 p_rollback_mode in varchar2,
2239 p_leave_base_table_row in boolean) is
2240 begin
2241 g_debug := hr_utility.debug_enabled;
2242 --
2243 if g_debug then
2244 hr_utility.set_location('hrassact.rollback_payroll_action',10);
2245 end if;
2246 py_rollback_pkg.rollback_payroll_action
2247 (p_payroll_action_id => p_payroll_action_id,
2248 p_rollback_mode => p_rollback_mode,
2249 p_leave_base_table_row => p_leave_base_table_row);
2250 end rollback_payroll_action;
2251 --
2252 --
2253 procedure rollback_payroll_action
2254 (p_payroll_action_id in number,
2255 p_failed_assact in out nocopy number,
2256 p_rollback_mode in varchar2,
2257 p_leave_base_table_row in boolean) is
2258 begin
2259 g_debug := hr_utility.debug_enabled;
2260 --
2261 if g_debug then
2262 hr_utility.set_location('hrassact.rollback_payroll_action',20);
2263 end if;
2264 py_rollback_pkg.rollback_payroll_action
2265 (p_payroll_action_id => p_payroll_action_id,
2266 p_rollback_mode => p_rollback_mode,
2267 p_leave_base_table_row => p_leave_base_table_row);
2268 end rollback_payroll_action;
2269 --
2270 --
2271 procedure rollback_payroll_action
2272 (p_payroll_action_id in number,
2273 p_chunk_size in number,
2274 p_failed_assact in out nocopy number,
2275 p_rollback_mode in varchar2,
2276 p_leave_base_table_row in boolean) is
2277 begin
2278 g_debug := hr_utility.debug_enabled;
2279 --
2280 if g_debug then
2281 hr_utility.set_location('hrassact.rollback_payroll_action',30);
2282 end if;
2283 py_rollback_pkg.rollback_payroll_action
2284 (p_payroll_action_id => p_payroll_action_id,
2285 p_all_or_nothing => FALSE,
2286 p_rollback_mode => p_rollback_mode,
2287 p_leave_base_table_row => p_leave_base_table_row);
2288 end rollback_payroll_action;
2289 --
2290 --
2291 --
2292 --
2293 /*--------------------------- rollback_ass_action -----------------------*/
2294 /*
2295 * This routine performs the actual work of rolling back a
2296 * assignment action.
2297 */
2298 procedure rollback_ass_action
2299 (p_assignment_action_id in number,
2300 p_rollback_mode in varchar2,
2301 p_leave_base_table_row in boolean) is
2302 --
2303 l_pact_rec pact_details; -- payroll action details
2304 l_assact_rec assact_details; -- assignment action details
2305 cursor c1 is
2306 select payroll_action_id
2307 from pay_assignment_actions
2308 where assignment_action_id = p_assignment_action_id
2309 for update of action_status;
2310 --
2311 --
2312 begin
2313 g_debug := hr_utility.debug_enabled;
2314 --
2315 if g_debug then
2316 hr_utility.set_location('hrassact.rollback_ass_action',20);
2317 end if;
2318 for c1rec in c1 loop
2319 --
2320 -- populate payroll action details and perform high level validation
2321 l_pact_rec.pact_id := c1rec.payroll_action_id;
2322 if g_debug then
2323 hr_utility.set_location('hrassact.rollback_ass_action',30);
2324 end if;
2325 val_pact_rollback(p_pact_rec => l_pact_rec,
2326 p_rollback_mode => p_rollback_mode);
2327 --
2328 -- see if OK to roll back or retry this assignment action
2329 l_assact_rec.assact_id := p_assignment_action_id;
2330 --
2331 if g_debug then
2332 hr_utility.set_location('hrassact.rollback_ass_action',40);
2333 end if;
2334 if p_rollback_mode = 'BACKPAY' or
2335 (val_assact_rollback (l_pact_rec, l_assact_rec, p_rollback_mode) and
2336 val_assact_rr_rules (l_pact_rec, p_rollback_mode))
2337 then
2338 --
2339 -- OK, clean up all child records for the action
2340 if g_debug then
2341 hr_utility.set_location('hrassact.rollback_ass_action',50);
2342 end if;
2343 do_assact_rollback
2344 (p_pact_rec => l_pact_rec,
2345 p_assact_rec => l_assact_rec,
2346 p_rollback_mode => p_rollback_mode,
2347 p_leave_base_table_row => p_leave_base_table_row);
2348 else
2349 hr_utility.set_message(801, 'HR_7008_ACTION_CANT_ROLLBACK');
2350 hr_utility.set_message_token('FAILING_ASSACT',l_assact_rec.assact_id);
2351 hr_utility.raise_error;
2352 end if;
2353 --
2354 end loop;
2355 --
2356 if g_debug then
2357 hr_utility.set_location('hrassact.rollback_ass_action',60);
2358 end if;
2359 return;
2360 --
2361 end rollback_ass_action;
2362 --
2363 --
2364 /*------------------------- trash_latest_balances -----------------------*/
2365 /*
2366 * This procedure trashes any latest balances
2367 * invalidated for the given balance type and input value
2368 * on or after the given date where there exists at least
2369 * one processed, non zero result value. This is done to
2370 * avoid trashing latest balances that could not have
2371 * been affected by the change in the balance feed.
2372 */
2373 procedure trash_latest_balances(l_balance_type_id number,
2374 l_input_value_id number,
2375 l_trash_date date) is
2376 --
2377 -- Select all person latest balances to delete.
2378 cursor plbc is
2379 select /*+ ORDERED INDEX (PLB PAY_PERSON_LATEST_BALANCES_FK1)
2380 USE_NL (PLB) */
2381 plb.latest_balance_id
2382 from pay_defined_balances pdb,
2383 pay_person_latest_balances plb
2384 where pdb.balance_type_id = l_balance_type_id
2385 and plb.defined_balance_id = pdb.defined_balance_id
2386 and exists (
2387 select null
2388 from pay_run_results prr,
2389 pay_run_result_values rrv
2390 where rrv.input_value_id = l_input_value_id
2391 and prr.run_result_id = rrv.run_result_id
2392 and prr.status in ('P', 'PA')
2393 and nvl(rrv.result_value, '0') <> '0');
2394 --
2395 cursor lbc is
2396 select
2397 lb.latest_balance_id
2398 from pay_defined_balances pdb,
2399 pay_latest_balances lb
2400 where pdb.balance_type_id = l_balance_type_id
2401 and lb.defined_balance_id = pdb.defined_balance_id
2402 and exists (
2403 select null
2404 from pay_run_results prr,
2405 pay_run_result_values rrv
2406 where rrv.input_value_id = l_input_value_id
2407 and prr.run_result_id = rrv.run_result_id
2408 and prr.status in ('P', 'PA')
2409 and nvl(rrv.result_value, '0') <> '0');
2410 --
2411 -- Select all assignment latest balances to delete.
2412 cursor albc is
2413 select /*+ ORDERED INDEX (PLB PAY_ASSIGNMENT_LATEST_BALA_FK2)
2414 USE_NL (PLB) */
2415 plb.latest_balance_id
2416 from pay_defined_balances pdb,
2417 pay_assignment_latest_balances plb
2418 where pdb.balance_type_id = l_balance_type_id
2419 and plb.defined_balance_id = pdb.defined_balance_id
2420 and exists (
2421 select null
2422 from pay_run_results prr,
2423 pay_run_result_values rrv
2424 where rrv.input_value_id = l_input_value_id
2425 and prr.run_result_id = rrv.run_result_id
2426 and prr.status in ('P', 'PA')
2427 and nvl(rrv.result_value, '0') <> '0');
2428 --
2429 cursor platbalc is
2430 select /*+ ORDERED INDEX (PLB PAY_PERSON_LATEST_BALANCES_FK1)
2431 USE_NL (PLB) */
2432 plb.latest_balance_id
2433 from pay_defined_balances pdb,
2434 pay_person_latest_balances plb
2435 where pdb.balance_type_id = l_balance_type_id
2436 and plb.defined_balance_id = pdb.defined_balance_id;
2437 --
2438 -- Select all assignment latest balances to delete.
2439 cursor alatbalc is
2440 select /*+ ORDERED INDEX (PLB PAY_ASSIGNMENT_LATEST_BALA_FK2)
2441 USE_NL (PLB) */
2442 plb.latest_balance_id
2443 from pay_defined_balances pdb,
2444 pay_assignment_latest_balances plb
2445 where pdb.balance_type_id = l_balance_type_id
2446 and plb.defined_balance_id = pdb.defined_balance_id;
2447 --
2448 -- Select all latest balances to delete.
2449 cursor latbalc is
2450 select /*+ ORDERED INDEX (PLB PAY_LATEST_BALANCES_FK1)
2451 USE_NL (PLB) */
2452 plb.latest_balance_id
2453 from pay_defined_balances pdb,
2454 pay_latest_balances plb
2455 where pdb.balance_type_id = l_balance_type_id
2456 and plb.defined_balance_id = pdb.defined_balance_id;
2457 --
2458 -- Select if run result value exists for input value
2459 cursor ivchk is
2460 select '1' from dual
2461 where exists (select 1
2462 from pay_run_results prr,
2463 pay_run_result_values rrv
2464 where rrv.input_value_id = l_input_value_id
2465 and prr.run_result_id = rrv.run_result_id
2466 and prr.status in ('P', 'PA')
2467 and nvl(rrv.result_value, '0') <> '0');
2468 --
2469 -- Select the balances that are PL/SQL fed.
2470 cursor pl_feed_chk_a is
2471 select alb.latest_balance_id
2472 from pay_assignment_latest_balances alb,
2473 pay_defined_balances pdb,
2474 pay_balance_dimensions pbd
2475 where pdb.balance_type_id = l_balance_type_id
2476 and pdb.defined_balance_id = alb.defined_balance_id
2477 and pdb.balance_dimension_id = pbd.balance_dimension_id
2478 and pbd.feed_checking_type = 'F';
2479
2480 cursor pl_feed_chk is
2481 select plb.latest_balance_id,
2482 'P' balance_type
2483 from pay_person_latest_balances plb,
2484 pay_defined_balances pdb,
2485 pay_balance_dimensions pbd
2486 where pdb.balance_type_id = l_balance_type_id
2487 and pdb.defined_balance_id = plb.defined_balance_id
2488 and pdb.balance_dimension_id = pbd.balance_dimension_id
2489 and pbd.feed_checking_type = 'F'
2490 union
2491 select plb.latest_balance_id,
2492 'B' balance_type
2493 from pay_latest_balances plb,
2494 pay_defined_balances pdb,
2495 pay_balance_dimensions pbd
2496 where pdb.balance_type_id = l_balance_type_id
2497 and pdb.defined_balance_id = plb.defined_balance_id
2498 and pdb.balance_dimension_id = pbd.balance_dimension_id
2499 and pbd.feed_checking_type = 'F';
2500
2501 l_ivchk varchar2(2);
2502 l_rrv_found number := -1;
2503 --Added following type for Bug:6595092 bulk delete
2504 Type t_latbal is table of pay_assignment_latest_balances.latest_balance_id%type;
2505 lat_bal_list t_latbal;
2506 --
2507 begin
2508 g_debug := hr_utility.debug_enabled;
2509 --
2510 if g_debug then
2511 hr_utility.set_location('hrassact.trash_latest_balances',10);
2512 end if;
2513 if (g_lat_bal_check_mode is null) then
2514 begin
2515 if g_debug then
2516 hr_utility.set_location('hrassact.trash_latest_balances',15);
2517 end if;
2518 select parameter_value
2519 into g_lat_bal_check_mode
2520 from pay_action_parameters
2521 where parameter_name = 'LAT_BAL_CHECK_MODE';
2522
2523 exception
2524 when others then
2525 g_lat_bal_check_mode := 'N';
2526 end;
2527
2528 if (g_lat_bal_check_mode = 'B') then
2529 HRASSACT.CHECK_LAT_BALS_FIRST := TRUE;
2530 elsif (g_lat_bal_check_mode = 'R') then
2531 HRASSACT.CHECK_RRVS_FIRST := TRUE;
2532 end if;
2533 end if;
2534 --
2535 if HRASSACT.CHECK_LATEST_BALANCES = TRUE then
2536 if HRASSACT.CHECK_RRVS_FIRST = TRUE then
2537 if g_debug then
2538 hr_utility.set_location('hrassact.trash_latest_balances',20);
2539 end if;
2540 --
2541 -- Check for existance of run result value for input value
2542 --
2543 open ivchk;
2544 fetch ivchk
2545 into l_ivchk;
2546 if ivchk%FOUND then
2547 --
2548 if g_debug then
2549 hr_utility.set_location('hrassact.trash_latest_balances',30);
2550 end if;
2551 -- Delete all balance context values and
2552 -- person latest balances.
2553 for plbcrec in platbalc loop
2554 delete from pay_balance_context_values BCV
2555 where BCV.latest_balance_id = plbcrec.latest_balance_id;
2556 --
2557 delete from pay_person_latest_balances PLB
2558 where PLB.latest_balance_id = plbcrec.latest_balance_id;
2559 end loop;
2560
2561 if g_debug then
2562 hr_utility.set_location('hrassact.trash_latest_balances',40);
2563 end if;
2564 -- Delete all balance context values and
2565 -- assignment latest balances.
2566
2567 --Commented the following and added a block with cusrsor and bulk delete
2568 --for Bug:6595092
2569 /* for albcrec in alatbalc loop
2570 delete from pay_balance_context_values BCV
2571 where BCV.latest_balance_id = albcrec.latest_balance_id;
2572 --
2573 delete from pay_assignment_latest_balances ALB
2574 where ALB.latest_balance_id = albcrec.latest_balance_id;
2575 end loop; */
2576
2577 open alatbalc;
2578 loop
2579 fetch alatbalc bulk collect into lat_bal_list limit 100000;
2580
2581 forall i in 1..lat_bal_list.count
2582 delete from pay_balance_context_values BCV
2583 where BCV.latest_balance_id = lat_bal_list(i);
2584
2585 forall i in 1..lat_bal_list.count
2586 delete from pay_assignment_latest_balances ALB
2587 where ALB.latest_balance_id =lat_bal_list(i);
2588
2589 exit when alatbalc%notfound;
2590 end loop;
2591
2592 IF alatbalc%ISOPEN
2593 THEN
2594 CLOSE alatbalc;
2595 END IF;
2596
2597 --
2598 -- Delete all latest Balanaces.
2599 for lbcrec in latbalc loop
2600 --
2601 delete from pay_latest_balances LB
2602 where LB.latest_balance_id = lbcrec.latest_balance_id;
2603 end loop;
2604 --
2605 end if;
2606 close ivchk;
2607
2608 elsif HRASSACT.CHECK_LAT_BALS_FIRST = TRUE then
2609
2610 if g_debug then
2611 hr_utility.set_location('hrassact.trash_latest_balances',50);
2612 end if;
2613 --
2614 -- Check for any latest balances before relevant run result value
2615 --
2616 for plbcrec in platbalc loop
2617 if l_rrv_found = -1 then
2618 open ivchk;
2619
2620 fetch ivchk
2621 into l_ivchk;
2622
2623 if ivchk%FOUND then
2624 l_rrv_found := 1;
2625 else
2626 l_rrv_found := 0;
2627 close ivchk;
2628 exit;
2629 end if;
2630 close ivchk;
2631 end if;
2632 if l_rrv_found = 1 then
2633 delete from pay_balance_context_values BCV
2634 where BCV.latest_balance_id = plbcrec.latest_balance_id;
2635 --
2636 delete from pay_person_latest_balances PLB
2637 where PLB.latest_balance_id = plbcrec.latest_balance_id;
2638 end if;
2639 end loop;
2640 --
2641 if g_debug then
2642 hr_utility.set_location('hrassact.trash_latest_balances',60);
2643 end if;
2644 -- Delete all balance context values and
2645 -- assignment latest balances.
2646 if l_rrv_found <> 0 then
2647 for albcrec in alatbalc loop
2648 if l_rrv_found = -1 then
2649 open ivchk;
2650
2651 fetch ivchk
2652 into l_ivchk;
2653
2654 if ivchk%FOUND then
2655 l_rrv_found := 1;
2656 else
2657 l_rrv_found := 0;
2658 close ivchk;
2659 exit;
2660 end if;
2661 close ivchk;
2662 end if;
2663 if l_rrv_found = 1 then
2664 delete from pay_balance_context_values BCV
2665 where BCV.latest_balance_id = albcrec.latest_balance_id;
2666 --
2667 delete from pay_assignment_latest_balances ALB
2668 where ALB.latest_balance_id = albcrec.latest_balance_id;
2669 end if;
2670 end loop;
2671 end if;
2672 --
2673 if l_rrv_found <> 0 then
2674 for lbcrec in latbalc loop
2675 if l_rrv_found = -1 then
2676 open ivchk;
2677
2678 fetch ivchk
2679 into l_ivchk;
2680
2681 if ivchk%FOUND then
2682 l_rrv_found := 1;
2683 else
2684 l_rrv_found := 0;
2685 close ivchk;
2686 exit;
2687 end if;
2688 close ivchk;
2689 end if;
2690 if l_rrv_found = 1 then
2691 delete from pay_latest_balances ALB
2692 where ALB.latest_balance_id = lbcrec.latest_balance_id;
2693 end if;
2694 end loop;
2695 end if;
2696 else
2697 --
2698 -- Original Code
2699 --
2700 if g_debug then
2701 hr_utility.set_location('hrassact.trash_latest_balances',70);
2702 end if;
2703 -- Delete all balance context values and
2704 -- person latest balances.
2705 for plbcrec in plbc loop
2706 delete from pay_balance_context_values BCV
2707 where BCV.latest_balance_id = plbcrec.latest_balance_id;
2708 --
2709 delete from pay_person_latest_balances PLB
2710 where PLB.latest_balance_id = plbcrec.latest_balance_id;
2711 end loop;
2712 --
2713 if g_debug then
2714 hr_utility.set_location('hrassact.trash_latest_balances',80);
2715 end if;
2716 -- Delete all balance context values and
2717 -- assignment latest balances.
2718 open albc;
2719 loop
2720 fetch albc bulk collect into lat_bal_list limit 100000;
2721
2722 forall i in 1..lat_bal_list.count
2723 delete from pay_balance_context_values BCV
2724 where BCV.latest_balance_id = lat_bal_list(i);
2725
2726 forall i in 1..lat_bal_list.count
2727 delete from pay_assignment_latest_balances ALB
2728 where ALB.latest_balance_id =lat_bal_list(i);
2729
2730 exit when albc%notfound;
2731 end loop;
2732
2733 IF albc%ISOPEN
2734 THEN
2735 CLOSE albc;
2736 END IF;
2737 --
2738 if g_debug then
2739 hr_utility.set_location('hrassact.trash_latest_balances',70);
2740 end if;
2741 --
2742 for lbcrec in lbc loop
2743 delete from pay_latest_balances ALB
2744 where ALB.latest_balance_id = lbcrec.latest_balance_id;
2745 end loop;
2746 --
2747 end if;
2748 --
2749 if g_debug then
2750 hr_utility.set_location('hrassact.trash_latest_balances',90);
2751 end if;
2752 --
2753 for plrec in pl_feed_chk loop
2754 --
2755 if g_debug then
2756 hr_utility.set_location('hrassact.trash_latest_balances',100);
2757 end if;
2758
2759 delete from pay_balance_context_values BCV
2760 where BCV.latest_balance_id = plrec.latest_balance_id;
2761 --
2762 if (plrec.balance_type = 'P') then
2763 delete from pay_person_latest_balances PLB
2764 where PLB.latest_balance_id = plrec.latest_balance_id;
2765 else
2766 delete from pay_latest_balances PLB
2767 where PLB.latest_balance_id = plrec.latest_balance_id;
2768 end if;
2769 --
2770 end loop;
2771
2772
2773 open pl_feed_chk_a;
2774 loop
2775 fetch pl_feed_chk_a bulk collect into lat_bal_list limit 100000;
2776
2777 forall i in 1..lat_bal_list.count
2778 delete from pay_balance_context_values BCV
2779 where BCV.latest_balance_id = lat_bal_list(i);
2780
2781 forall i in 1..lat_bal_list.count
2782 delete from pay_assignment_latest_balances ALB
2783 where ALB.latest_balance_id =lat_bal_list(i);
2784
2785 exit when pl_feed_chk_a%notfound;
2786 end loop;
2787
2788 IF pl_feed_chk_a%ISOPEN
2789 THEN
2790 CLOSE pl_feed_chk_a;
2791 END IF;
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802 --
2803 end if;
2804 --
2805 if g_debug then
2806 hr_utility.set_location('hrassact.trash_latest_balances',110);
2807 end if;
2808 --
2809 return;
2810 --
2811 end trash_latest_balances;
2812 --
2813 --
2814 /*------------------------- trash_latest_balances -----------------------*/
2815 /*
2816 * This procedure trashes any latest balances
2817 * invalidated for the given balance type
2818 */
2819 procedure trash_latest_balances(l_balance_type_id number,
2820 l_trash_date date) is
2821 -- Select all person latest balances to delete.
2822 cursor plbc is
2823 select /*+ ORDERED INDEX (PLB PAY_PERSON_LATEST_BALANCES_FK1)
2824 USE_NL (PLB) */
2825 plb.latest_balance_id
2826 from pay_defined_balances pdb,
2827 pay_person_latest_balances plb
2828 where pdb.balance_type_id = l_balance_type_id
2829 and plb.defined_balance_id = pdb.defined_balance_id;
2830 --
2831 -- Select all assignment latest balances to delete.
2832 cursor albc is
2833 select /*+ ORDERED INDEX (PLB PAY_ASSIGNMENT_LATEST_BALA_FK2)
2834 USE_NL (PLB) */
2835 plb.latest_balance_id
2836 from pay_defined_balances pdb,
2837 pay_assignment_latest_balances plb
2838 where pdb.balance_type_id = l_balance_type_id
2839 and plb.defined_balance_id = pdb.defined_balance_id;
2840 -- Select all latest balances to delete.
2841 cursor lbc is
2842 select /*+ ORDERED INDEX (LB PAY_LATEST_BALANCES_FK1)
2843 USE_NL (LB) */
2844 lb.latest_balance_id
2845 from pay_defined_balances pdb,
2846 pay_latest_balances lb
2847 where pdb.balance_type_id = l_balance_type_id
2848 and lb.defined_balance_id = pdb.defined_balance_id;
2849
2850 Type t_latbal is table of pay_assignment_latest_balances.latest_balance_id%type;
2851 lat_bal_list t_latbal;
2852
2853 begin
2854 hr_utility.set_location('hrassact.trash_latest_balances',10);
2855 --
2856 -- Delete all balance context values and
2857 -- person latest balances.
2858 for plbcrec in plbc loop
2859 delete from pay_balance_context_values BCV
2860 where BCV.latest_balance_id = plbcrec.latest_balance_id;
2861 --
2862 delete from pay_person_latest_balances PLB
2863 where PLB.latest_balance_id = plbcrec.latest_balance_id;
2864 end loop;
2865 --
2866 hr_utility.set_location('hrassact.trash_latest_balances',20);
2867 -- Delete all balance context values and
2868 -- assignment latest balances.
2869 open albc;
2870 loop
2871 fetch albc bulk collect into lat_bal_list limit 100000;
2872
2873 forall i in 1..lat_bal_list.count
2874 delete from pay_balance_context_values BCV
2875 where BCV.latest_balance_id = lat_bal_list(i);
2876
2877 forall i in 1..lat_bal_list.count
2878 delete from pay_assignment_latest_balances ALB
2879 where ALB.latest_balance_id =lat_bal_list(i);
2880
2881 exit when albc%notfound;
2882 end loop;
2883
2884 IF albc%ISOPEN
2885 THEN
2886 CLOSE albc;
2887 END IF;
2888
2889 --
2890 hr_utility.set_location('hrassact.trash_latest_balances',30);
2891 for lbcrec in lbc loop
2892 delete from pay_latest_balances ALB
2893 where ALB.latest_balance_id = lbcrec.latest_balance_id;
2894 end loop;
2895 hr_utility.set_location('hrassact.trash_latest_balances',40);
2896 --
2897 return;
2898 --
2899 end trash_latest_balances;
2900 --
2901 /*------------------------- del_latest_balances -----------------------*/
2902 /*
2903 * This procedure trashes any latest balances for the person.
2904 */
2905 procedure del_latest_balances
2906 (
2907 p_assignment_id in number,
2908 p_effective_date in date, -- allow date effective join.
2909 p_element_entry in number default null,
2910 p_element_type_id in number default null
2911 ) is
2912 --
2913 -- Cursors to delete all the latest balances for an assignment.
2914 --
2915 cursor plbc (p_person_id number) is
2916 select plb.latest_balance_id
2917 from pay_person_latest_balances plb
2918 where plb.person_id = p_person_id;
2919 --
2920 cursor lbc (p_person_id number) is
2921 select lb.latest_balance_id
2922 from pay_latest_balances lb
2923 where lb.person_id = p_person_id;
2924 --
2925 cursor albc (p_person_id number) is
2926 select /*+ ORDERED */ alb.latest_balance_id
2927 from per_periods_of_service pos,
2928 per_all_assignments_f asg,
2929 pay_assignment_actions act,
2930 pay_payroll_actions pac,
2931 pay_assignment_latest_balances alb
2932 where pos.person_id = p_person_id
2933 and asg.period_of_service_id = pos.period_of_service_id
2934 and asg.person_id = p_person_id
2935 and act.assignment_id = asg.assignment_id
2936 and alb.assignment_action_id = act.assignment_action_id
2937 and pac.payroll_action_id = act.payroll_action_id
2938 and pac.effective_date between
2939 asg.effective_start_date and asg.effective_end_date;
2940
2941
2942 --
2943 -- Cursors to selectively delete the latest balances for an assignment.
2944 --
2945 cursor plbc_selective (p_person_id number,
2946 p_eletyp_id number
2947 ) is
2948 select
2949 plb.latest_balance_id
2950 from
2951 pay_input_values_f piv,
2952 pay_balance_feeds_f pbf,
2953 pay_defined_balances pdb,
2954 pay_person_latest_balances plb,
2955 pay_assignment_actions paa,
2956 pay_payroll_actions ppa
2957 where plb.person_id = p_person_id
2958 and piv.element_type_id = p_eletyp_id
2959 and piv.input_value_id = pbf.input_value_id
2960 and plb.defined_balance_id = pdb.defined_balance_id
2961 and pdb.balance_type_id = pbf.balance_type_id
2962 and paa.assignment_action_id = plb.assignment_action_id
2963 and paa.payroll_action_id = ppa.payroll_action_id
2964 and ppa.effective_date between pbf.effective_start_date
2965 and pbf.effective_end_date
2966 and ppa.effective_date between piv.effective_start_date
2967 and piv.effective_end_date;
2968 --
2969 cursor albc_selective (p_person_id number,
2970 p_eletyp_id number) is
2971 select
2972 alb.latest_balance_id
2973 from pay_assignment_latest_balances alb,
2974 pay_assignment_actions act,
2975 pay_payroll_actions pac,
2976 pay_defined_balances pdb,
2977 pay_balance_feeds_f pbf,
2978 pay_input_values_f piv
2979 where act.assignment_id = alb.assignment_id
2980 and alb.assignment_id in
2981 (select distinct asg.assignment_id
2982 from per_all_assignments_f asg
2983 where asg.person_id = p_person_id)
2984 and alb.assignment_action_id = act.assignment_action_id
2985 and piv.element_type_id = p_eletyp_id
2986 and piv.input_value_id = pbf.input_value_id
2987 and alb.defined_balance_id = pdb.defined_balance_id
2988 and pdb.balance_type_id = pbf.balance_type_id
2989 and pac.payroll_action_id = act.payroll_action_id
2990 and pac.effective_date between pbf.effective_start_date
2991 and pbf.effective_end_date
2992 and pac.effective_date between piv.effective_start_date
2993 and piv.effective_end_date;
2994 --
2995 cursor lbc_selective (p_person_id number,
2996 p_eletyp_id number
2997 ) is
2998 select
2999 plb.latest_balance_id
3000 from
3001 pay_input_values_f piv,
3002 pay_balance_feeds_f pbf,
3003 pay_defined_balances pdb,
3004 pay_latest_balances plb,
3005 pay_assignment_actions paa,
3006 pay_payroll_actions ppa
3007 where plb.person_id = p_person_id
3008 and piv.element_type_id = p_eletyp_id
3009 and piv.input_value_id = pbf.input_value_id
3010 and plb.defined_balance_id = pdb.defined_balance_id
3011 and pdb.balance_type_id = pbf.balance_type_id
3012 and paa.assignment_action_id = plb.assignment_action_id
3013 and paa.payroll_action_id = ppa.payroll_action_id
3014 and ppa.effective_date between pbf.effective_start_date
3015 and pbf.effective_end_date
3016 and ppa.effective_date between piv.effective_start_date
3017 and piv.effective_end_date;
3018 --
3019 l_person_id number;
3020 l_element_type_id number;
3021 begin
3022 g_debug := hr_utility.debug_enabled;
3023 --
3024 -- Simply return the person_id for the assignment.
3025 if g_debug then
3026 hr_utility.set_location('hrassact.del_latest_balances',10);
3027 end if;
3028 select asg.person_id
3029 into l_person_id
3030 from per_all_assignments_f asg
3031 where asg.assignment_id = p_assignment_id
3032 and p_effective_date between
3033 asg.effective_start_date and asg.effective_end_date;
3034 --
3035 if (p_element_entry is null) and (p_element_type_id is null) then
3036 -- Delete (person) balance context values.
3037 if g_debug then
3038 hr_utility.set_location('hrassact.del_latest_balances',20);
3039 end if;
3040 for plbcrec in plbc(l_person_id) loop
3041 delete from pay_balance_context_values BCV
3042 where BCV.latest_balance_id = plbcrec.latest_balance_id;
3043 --
3044 delete from pay_person_latest_balances PLB
3045 where PLB.latest_balance_id = plbcrec.latest_balance_id;
3046 end loop;
3047 --
3048 -- We need to delete all latest balances for the
3049 -- person's period of service.
3050 if g_debug then
3051 hr_utility.set_location('hrassact.del_latest_balances',40);
3052 end if;
3053 for albcrec in albc(l_person_id) loop
3054 delete from pay_balance_context_values BCV
3055 where BCV.latest_balance_id = albcrec.latest_balance_id;
3056 --
3057 delete from pay_assignment_latest_balances ALB
3058 where ALB.latest_balance_id = albcrec.latest_balance_id;
3059 end loop;
3060 --
3061 if g_debug then
3062 hr_utility.set_location('hrassact.del_latest_balances',45);
3063 end if;
3064 for lbcrec in lbc(l_person_id) loop
3065 delete from pay_latest_balances ALB
3066 where ALB.latest_balance_id = lbcrec.latest_balance_id;
3067 end loop;
3068 else
3069 --
3070 l_element_type_id := p_element_type_id;
3071 --
3072 -- Check if the element type id is specified.
3073 --
3074 if l_element_type_id is null then
3075 --
3076 -- Derive the element type id from the entry id.
3077 --
3078 if g_debug then
3079 hr_utility.set_location('hrassact.del_latest_balances',60);
3080 end if;
3081 select pel.element_type_id into l_element_type_id
3082 from pay_element_entries_f pee
3083 ,pay_element_links_f pel
3084 where
3085 pee.element_entry_id = p_element_entry
3086 and p_effective_date between pee.effective_start_date
3087 and pee.effective_end_date
3088 and pel.element_link_id = pee.element_link_id
3089 and p_effective_date between pel.effective_start_date
3090 and pel.effective_end_date
3091 ;
3092 end if;
3093 -- Delete (person) balance context values.
3094 if g_debug then
3095 hr_utility.set_location('hrassact.del_latest_balances',70);
3096 end if;
3097 for plbcrec in plbc_selective(l_person_id, l_element_type_id) loop
3098 delete from pay_balance_context_values BCV
3099 where BCV.latest_balance_id = plbcrec.latest_balance_id;
3100 --
3101 delete from pay_person_latest_balances PLB
3102 where PLB.latest_balance_id = plbcrec.latest_balance_id;
3103 end loop;
3104 --
3105 -- Delete contexts and latest balances for assignment.
3106 -- We need to delete all latest balances for the
3107 -- person's period of service.
3108 if g_debug then
3109 hr_utility.set_location('hrassact.del_latest_balances',80);
3110 end if;
3111 for albcrec in albc_selective(l_person_id, l_element_type_id) loop
3112 delete from pay_balance_context_values BCV
3113 where BCV.latest_balance_id = albcrec.latest_balance_id;
3114 --
3115 delete from pay_assignment_latest_balances ALB
3116 where ALB.latest_balance_id = albcrec.latest_balance_id;
3117 end loop;
3118 --
3119 if g_debug then
3120 hr_utility.set_location('hrassact.del_latest_balances',85);
3121 end if;
3122 for lbcrec in lbc_selective(l_person_id, l_element_type_id) loop
3123 delete from pay_latest_balances ALB
3124 where ALB.latest_balance_id = lbcrec.latest_balance_id;
3125 end loop;
3126 end if;
3127 --
3128 end del_latest_balances;
3129 --
3130 --------------------------- update_action_sequence ------------------------------
3131 /*
3132 NAME
3133 update_action_sequence
3134 DESCRIPTION
3135 Update the action sequence of a particular action.
3136 NOTES
3137 */
3138 procedure update_action_sequence (p_assact in number,
3139 rmode in varchar2)
3140 is
3141 pact number;
3142 actseq number;
3143 asgid number;
3144 newseq number;
3145 begin
3146 select payroll_action_id,
3147 action_sequence,
3148 assignment_id,
3149 pay_assignment_actions_s.nextval
3150 into pact,
3151 actseq,
3152 asgid,
3153 newseq
3154 from pay_assignment_actions
3155 where assignment_action_id = p_assact;
3156 --
3157 resequence_actions(pact, asgid, actseq, rmode);
3158 --
3159 update pay_assignment_actions
3160 set action_sequence = newseq
3161 where assignment_action_id = p_assact;
3162 --
3163 update pay_run_balances
3164 set action_sequence = newseq
3165 where assignment_action_id = p_assact;
3166 --
3167 end update_action_sequence;
3168 --
3169 --------------------------- resequence_chunk ----------------------
3170 /*
3171 NAME
3172 resequence_chunk
3173 DESCRIPTION
3174 Resequence sequenced actions for a whole chunk of assignments.
3175 NOTES
3176 */
3177 procedure resequence_chunk
3178 (
3179 pactid in number,
3180 cnkno in number,
3181 rmode in varchar2, -- rule_mode (time period independent Y or N)
3182 chldact in varchar2 default 'N' -- update child actions (Y or N)
3183 ) is
3184 --
3185 cursor cnkasg is
3186 select ppa.effective_date,
3187 paa.assignment_action_id,
3188 ppa.action_type
3189 from pay_payroll_actions ppa,
3190 pay_assignment_actions paa
3191 where ppa.payroll_action_id = pactid
3192 and paa.payroll_action_id = ppa.payroll_action_id
3193 and paa.source_action_id is null
3194 and paa.chunk_number = cnkno;
3195 --
3196 begin
3197 --
3198 for asgrec in cnkasg loop
3199 resequence_actions(
3200 asgrec.assignment_action_id,
3201 rmode,
3202 chldact,
3203 asgrec.action_type);
3204 end loop;
3205 --
3206 end resequence_chunk;
3207 --
3208 --------------------------- resequence_actions ---------------------------
3209 ---
3210 /*
3211 NAME
3212 resequence_actions
3213 DESCRIPTION
3214 Resequence sequenced actions.
3215 NOTES
3216 */
3217 procedure resequence_actions
3218 (
3219 aaid in number,
3220 rmode in varchar2, -- rule_mode (time period independent Y or N)
3221 chldact in varchar2 default 'N', -- update child actions (Y or N)
3222 actype in varchar2 -- action_type
3223 ) is
3224 --
3225 --
3226 cursor seqasg (
3227 aaid number,
3228 chldact varchar2
3229 ) is
3230 select ac2.rowid,
3231 ac2.assignment_action_id
3232 from pay_action_classifications acl,
3233 pay_assignment_actions ac2,
3234 pay_assignment_actions paa,
3235 pay_payroll_actions ppa,
3236 pay_payroll_actions pa2
3237 where paa.assignment_action_id = aaid
3238 and ppa.payroll_action_id = paa.payroll_action_id
3239 and ac2.assignment_id = paa.assignment_id
3240 and pa2.payroll_action_id = ac2.payroll_action_id
3241 and acl.classification_name = 'SEQUENCED'
3242 and pa2.effective_date > ppa.effective_date
3243 and pa2.action_type = acl.action_type
3244 and (( chldact = 'N'
3245 and ac2.source_action_id is null)
3246 or
3247 ( chldact = 'Y')
3248 )
3249 order by pa2.effective_date, ac2.action_sequence
3250 for update of ac2.assignment_action_id;
3251 --
3252 cursor seqper (
3253 aaid number,
3254 chldact varchar2
3255 ) is
3256 select /*+ ORDERED USE_NL(ac2, pa2)
3257 INDEX(ac2 PAY_ASSIGNMENT_ACTIONS_N1)
3258 INDEX(pa2 PAY_PAYROLL_ACTIONS_PK) */
3259 ac2.rowid,
3260 ac2.assignment_action_id
3261 from pay_assignment_actions act,
3262 pay_payroll_actions pac,
3263 per_all_assignments_f asg,
3264 per_all_assignments_f as2,
3265 pay_assignment_actions ac2,
3266 pay_payroll_actions pa2,
3267 pay_action_classifications acl
3268 where act.assignment_action_id = aaid
3269 and pac.payroll_action_id = act.payroll_action_id
3270 and asg.assignment_id = act.assignment_id
3271 and pac.effective_date between
3272 asg.effective_start_date and asg.effective_end_date
3273 and as2.person_id = asg.person_id
3274 and as2.effective_end_date > pac.effective_date
3275 and ac2.assignment_id = as2.assignment_id
3276 and pa2.payroll_action_id = ac2.payroll_action_id
3277 and as2.effective_start_date = (select max(paf3.effective_start_date)
3278 from per_all_assignments_f paf3
3279 where paf3.assignment_id = ac2.assignment_id
3280 and paf3.effective_start_date <= pa2.effective_date
3281 )
3282 and acl.classification_name = 'SEQUENCED'
3283 and pa2.action_type = acl.action_type
3284 and pa2.effective_date > pac.effective_date
3285 and (( chldact = 'N'
3286 and ac2.source_action_id is null)
3287 or
3288 ( chldact = 'Y')
3289 )
3290 order by pa2.effective_date, ac2.action_sequence
3291 for update of ac2.assignment_action_id;
3292 --
3293 -- G when aaid is not a retropay (ie act.assignment is not null)
3294 --
3295 cursor seqgrp (
3296 aaid number,
3297 chldact varchar2
3298 ) is
3299 select ac2.rowid,
3300 ac2.assignment_action_id
3301 from
3302 (
3303 select distinct ac3.assignment_action_id
3304 from pay_assignment_actions act,
3305 pay_object_groups pog,
3306 pay_object_groups pog2,
3307 pay_object_groups pog3,
3308 pay_payroll_actions pac,
3309 pay_object_groups pog4,
3310 pay_assignment_actions ac3,
3311 pay_payroll_actions pa3,
3312 pay_action_classifications acl
3313 where act.assignment_action_id = aaid
3314 and pac.payroll_action_id = act.payroll_action_id
3315 and pog.source_id = act.assignment_id
3316 and pog.source_type = 'PAF'
3317 and pog2.object_group_id = pog.parent_object_group_id
3318 and pog2.source_type = 'PPF'
3319 and pog3.source_id = pog2.source_id
3320 and pog3.source_type = 'PPF'
3321 and pog4.parent_object_group_id = pog3.object_group_id
3322 and ac3.assignment_id = pog4.source_id
3323 and pa3.payroll_action_id = ac3.payroll_action_id
3324 and pa3.effective_date > pac.effective_date
3325 and pa3.action_type <> 'L'
3326 and pa3.action_type = acl.action_type
3327 and acl.classification_name = 'SEQUENCED'
3328 union all
3329 select distinct ac3.assignment_action_id
3330 from pay_assignment_actions act,
3331 pay_object_groups pog,
3332 pay_object_groups pog2,
3333 pay_object_groups pog3,
3334 pay_payroll_actions pac,
3335 pay_assignment_actions ac3,
3336 pay_payroll_actions pa3
3337 where act.assignment_action_id = aaid
3338 and pac.payroll_action_id = act.payroll_action_id
3339 and pog.source_id = act.assignment_id
3340 and pog.source_type = 'PAF'
3341 and pog2.object_group_id = pog.parent_object_group_id
3342 and pog2.source_type = 'PPF'
3343 and pog3.source_id = pog2.source_id
3344 and pog3.source_type = 'PPF'
3345 and ac3.object_id = pog3.object_group_id
3346 and ac3.object_type = 'POG'
3347 and pa3.payroll_action_id = ac3.payroll_action_id
3348 and pa3.effective_date > pac.effective_date
3349 and pa3.action_type = 'L') V,
3350 pay_assignment_actions ac2,
3351 pay_payroll_actions pa2
3352 where ac2.assignment_action_id = V.assignment_action_id
3353 and pa2.payroll_action_id = ac2.payroll_action_id
3354 and (( chldact = 'N'
3355 and ac2.source_action_id is null)
3356 or
3357 ( chldact = 'Y')
3358 )
3359 order by pa2.effective_date, ac2.action_sequence
3360 for update of ac2.assignment_action_id;
3361 --
3362 -- G when aaid is a retropay (ie act.assignment is null)
3363 --
3364 cursor seqgrpret (
3365 aaid number,
3366 chldact varchar2
3367 ) is
3368 select ac2.rowid,
3369 ac2.assignment_action_id
3370 from
3371 (
3372 select distinct ac3.assignment_action_id
3373 from pay_assignment_actions act,
3374 pay_object_groups pog,
3375 pay_object_groups pog2,
3376 pay_payroll_actions pac,
3377 pay_object_groups pog3,
3378 pay_assignment_actions ac3,
3379 pay_payroll_actions pa3,
3380 pay_action_classifications acl
3381 where act.assignment_action_id = aaid
3382 and pac.payroll_action_id = act.payroll_action_id
3383 and pog.object_group_id = act.object_id
3384 and pog.source_type = 'PPF'
3385 and pog2.source_id = pog.source_id
3386 and pog2.source_type = 'PPF'
3387 and pog3.parent_object_group_id = pog2.object_group_id
3388 and ac3.assignment_id = pog3.source_id
3389 and pa3.payroll_action_id = ac3.payroll_action_id
3390 and pa3.effective_date > pac.effective_date
3391 and pa3.action_type <> 'L'
3392 and pa3.action_type = acl.action_type
3393 and acl.classification_name = 'SEQUENCED'
3394 union all
3395 select distinct ac3.assignment_action_id
3396 from pay_assignment_actions act,
3397 pay_object_groups pog,
3398 pay_object_groups pog2,
3399 pay_payroll_actions pac,
3400 pay_assignment_actions ac3,
3401 pay_payroll_actions pa3
3402 where act.assignment_action_id = aaid
3403 and pac.payroll_action_id = act.payroll_action_id
3404 and pog.object_group_id = act.object_id
3405 and pog.source_type = 'PPF'
3406 and pog2.source_id = pog.source_id
3407 and pog2.source_type = 'PPF'
3408 and ac3.object_id = pog2.object_group_id
3409 and ac3.object_type = 'POG'
3410 and pa3.payroll_action_id = ac3.payroll_action_id
3411 and pa3.effective_date > pac.effective_date
3412 and pa3.action_type = 'L') V,
3413 pay_assignment_actions ac2,
3414 pay_payroll_actions pa2
3415 where ac2.assignment_action_id = V.assignment_action_id
3416 and pa2.payroll_action_id = ac2.payroll_action_id
3417 and (( chldact = 'N'
3418 and ac2.source_action_id is null)
3419 or
3420 ( chldact = 'Y')
3421 )
3422 order by pa2.effective_date, ac2.action_sequence
3423 for update of ac2.assignment_action_id;
3424 --
3425 my_rowid rowid;
3426 upd_aa_id pay_assignment_actions.assignment_action_id%type;
3427 --
3428 begin
3429 --
3430 g_debug := hr_utility.debug_enabled;
3431 --
3432 if g_debug then
3433 hr_utility.set_location('hrassact.resequence_actions', 10);
3434 end if;
3435 if(rmode = 'Y') then
3436 open seqasg(aaid, chldact);
3437 elsif (rmode = 'N') then
3438 open seqper(aaid, chldact);
3439 else
3440 -- G mode
3441 if (actype = 'L') then
3442 open seqgrpret(aaid, chldact);
3443 else
3444 open seqgrp(aaid, chldact);
3445 end if;
3446 end if;
3447 --
3448 loop
3449 -- fetch the rowid and then update.
3450 if(rmode = 'Y') then
3451 fetch seqasg into my_rowid, upd_aa_id;
3452 exit when seqasg%notfound;
3453 elsif (rmode = 'N') then
3454 fetch seqper into my_rowid, upd_aa_id;
3455 exit when seqper%notfound;
3456 else
3457 -- G mode
3458 if (actype = 'L') then
3459 fetch seqgrpret into my_rowid, upd_aa_id;
3460 exit when seqgrpret%notfound;
3461 else
3462 fetch seqgrp into my_rowid, upd_aa_id;
3463 exit when seqgrp%notfound;
3464 end if;
3465 end if;
3466 --
3467 --
3468 -- Now, update with new action_sequence.
3469 update pay_assignment_actions act
3470 set act.action_sequence = pay_assignment_actions_s.nextval
3471 where act.rowid = my_rowid;
3472 --
3473 update pay_run_balances
3474 set action_sequence = pay_assignment_actions_s.currval
3475 where assignment_action_id = upd_aa_id;
3476 --
3477 end loop;
3478 --
3479 --
3480 -- we are finished with the cursor, so we close it here.
3481 if(rmode = 'Y') then
3482 close seqasg;
3483 elsif(rmode = 'N') then
3484 close seqper;
3485 else
3486 -- G mode
3487 if (actype = 'L') then
3488 close seqgrpret;
3489 else
3490 close seqgrp;
3491 end if;
3492 end if;
3493 --
3494 if g_debug then
3495 hr_utility.set_location('hrassact.resequence_actions', 20);
3496 end if;
3497 end resequence_actions;
3498 --
3499 procedure resequence_children(p_asg_action in number)
3500 is
3501 --
3502 cursor get_chld (p_aa_id number)
3503 is
3504 select assignment_action_id
3505 from pay_assignment_actions
3506 where source_action_id = p_aa_id
3507 order by action_sequence;
3508 --
3509 begin
3510 --
3511 for chdrec in get_chld(p_asg_action) loop
3512 --
3513 resequence_children(chdrec.assignment_action_id);
3514 --
3515 update pay_assignment_actions
3516 set action_sequence = pay_assignment_actions_s.nextval
3517 where assignment_action_id = chdrec.assignment_action_id;
3518 --
3519 end loop;
3520 --
3521 end resequence_children;
3522 --
3523 procedure resequence_actions
3524 (
3525 pactid in number,
3526 asgid in number,
3527 actseq in number,
3528 rmode in varchar2 -- rule_mode (time period independent Y or N)
3529 ) is
3530 --
3531 --
3532 cursor seqasg (
3533 asgid number,
3534 actseq number) is
3535 select /*+ INDEX (pa2 PAY_PAYROLL_ACTIONS_PK) */
3536 ac2.rowid,
3537 ac2.assignment_action_id,
3538 ac2.source_action_id,
3539 ac2.object_type
3540 from pay_action_classifications acl,
3541 pay_assignment_actions ac2,
3542 pay_payroll_actions pa2
3543 where ac2.assignment_id = asgid
3544 and pa2.payroll_action_id = ac2.payroll_action_id
3545 and acl.classification_name = 'SEQUENCED'
3546 and pa2.action_type = acl.action_type
3547 and ac2.action_sequence > actseq
3548 and (ac2.source_action_id is null
3549 or
3550 (ac2.object_id is not null
3551 and ac2.object_type = 'POG')
3552 )
3553 order by pa2.effective_date, ac2.action_sequence
3554 for update of ac2.assignment_action_id;
3555 --
3556 cursor seqper (pactid number,
3557 asgid number,
3558 actseq number,
3559 rmode varchar2) is
3560 select /*+ ORDERED
3561 INDEX (ac2 PAY_ASSIGNMENT_ACTIONS_N51)
3562 (pa2 PAY_PAYROLL_ACTIONS_PK) */
3563 ac2.rowid,
3564 ac2.assignment_action_id,
3565 ac2.source_action_id,
3566 ac2.object_type
3567 from pay_payroll_actions pac,
3568 per_all_assignments_f asg,
3569 per_all_assignments_f as2,
3570 pay_assignment_actions act,
3571 pay_assignment_actions ac2,
3572 pay_payroll_actions pa2,
3573 pay_action_classifications acl
3574 where pac.payroll_action_id = pactid
3575 and act.payroll_action_id = pac.payroll_action_id
3576 and act.assignment_id = asgid
3577 and act.source_action_id is null
3578 and asg.assignment_id = act.assignment_id
3579 and pac.effective_date between
3580 asg.effective_start_date and asg.effective_end_date
3581 and as2.person_id = asg.person_id
3582 and decode(rmode, 'G', pac.effective_date,
3583 as2.effective_end_date) >= pac.effective_date
3584 and ac2.assignment_id = as2.assignment_id
3585 and pa2.payroll_action_id = ac2.payroll_action_id
3586 and as2.effective_start_date = (select max(paf3.effective_start_date)
3587 from per_all_assignments_f paf3
3588 where paf3.assignment_id = ac2.assignment_id
3589 )
3590 and acl.classification_name = 'SEQUENCED'
3591 and pa2.action_type = acl.action_type
3592 and ac2.action_sequence > actseq
3593 and (ac2.source_action_id is null
3594 or
3595 (ac2.object_id is not null
3596 and ac2.object_type = 'POG')
3597 )
3598 order by pa2.effective_date, ac2.action_sequence
3599 for update of ac2.assignment_action_id;
3600 --
3601 -- G nb pactid is never a retropay
3602 --
3603 cursor seqgrp (pactid number,
3604 asgid number,
3605 actseq number,
3606 rmode varchar2) is
3607 select /*+ ORDERED
3608 INDEX (ac2 PAY_ASSIGNMENT_ACTIONS_PK)
3609 (pa2 PAY_PAYROLL_ACTIONS_PK) */
3610 ac2.rowid,
3611 ac2.assignment_action_id,
3612 ac2.source_action_id,
3613 ac2.object_type
3614 from
3615 (
3616 select /*+ ORDERED */
3617 distinct ac3.assignment_action_id
3618 from pay_payroll_actions pac,
3619 pay_assignment_actions act,
3620 pay_object_groups pog,
3621 pay_object_groups pog2,
3622 pay_object_groups pog3,
3623 pay_object_groups pog4,
3624 pay_assignment_actions ac3,
3625 pay_payroll_actions pa3,
3626 pay_action_classifications acl
3627 where pac.payroll_action_id = pactid
3628 and act.payroll_action_id = pac.payroll_action_id
3629 and act.assignment_id = asgid
3630 and act.source_action_id is null
3631 and pog.source_id = act.assignment_id
3632 and pog.source_type = 'PAF'
3633 and pac.effective_date between
3634 pog.start_date and pog.end_date
3635 and pog2.object_group_id = pog.parent_object_group_id
3636 and pog2.source_type = 'PPF'
3637 and pog3.source_id = pog2.source_id
3638 and pog3.source_type = 'PPF'
3639 and pog4.parent_object_group_id = pog3.object_group_id
3640 and ac3.assignment_id = pog4.source_id
3641 and ac3.action_sequence > actseq
3642 and pa3.payroll_action_id = ac3.payroll_action_id
3643 and pa3.action_type <> 'L'
3644 and pa3.action_type = acl.action_type
3645 and acl.classification_name = 'SEQUENCED'
3646 union all
3647 select /*+ ORDERED */
3648 distinct ac3.assignment_action_id
3649 from pay_payroll_actions pac,
3650 pay_assignment_actions act,
3651 pay_object_groups pog,
3652 pay_object_groups pog2,
3653 pay_object_groups pog3,
3654 pay_assignment_actions ac3,
3655 pay_payroll_actions pa3
3656 where pac.payroll_action_id = pactid
3657 and act.payroll_action_id = pac.payroll_action_id
3658 and act.assignment_id = asgid
3659 and act.source_action_id is null
3660 and pog.source_id = act.assignment_id
3661 and pog.source_type = 'PAF'
3662 and pac.effective_date between
3663 pog.start_date and pog.end_date
3664 and pog2.object_group_id = pog.parent_object_group_id
3665 and pog2.source_type = 'PPF'
3666 and pog3.source_id = pog2.source_id
3667 and pog3.source_type = 'PPF'
3668 and ac3.object_id = pog3.object_group_id
3669 and ac3.object_type = 'POG'
3670 and ac3.action_sequence > actseq
3671 and pa3.payroll_action_id = ac3.payroll_action_id
3672 and pa3.action_type = 'L') V,
3673 pay_assignment_actions ac2,
3674 pay_payroll_actions pa2
3675 where ac2.assignment_action_id = V.assignment_action_id
3676 and pa2.payroll_action_id = ac2.payroll_action_id
3677 and (ac2.source_action_id is null
3678 or
3679 (ac2.object_id is not null
3680 and ac2.object_type = 'POG')
3681 )
3682 order by pa2.effective_date, ac2.action_sequence
3683 for update of ac2.assignment_action_id;
3684
3685 --
3686 my_rowid rowid;
3687 upd_aa_id pay_assignment_actions.assignment_action_id%type;
3688 src_aa_id pay_assignment_actions.source_action_id%type;
3689 obj_type pay_assignment_actions.object_type%type;
3690 --
3691 begin
3692 --
3693 g_debug := hr_utility.debug_enabled;
3694 --
3695 hr_utility.trace('passing pact = '||pactid);
3696 hr_utility.trace('passing asgid = '||asgid);
3697 hr_utility.trace('passing actseq = '||actseq);
3698 --
3699 if g_debug then
3700 hr_utility.set_location('hrassact.resequence_actions', 10);
3701 end if;
3702 if(rmode = 'Y') then
3703 open seqasg(asgid,actseq);
3704 elsif(rmode = 'N') then
3705 open seqper(pactid, asgid,actseq,rmode);
3706 else
3707 open seqgrp(pactid, asgid,actseq,rmode);
3708 end if;
3709 --
3710 loop
3711 -- fetch the rowid and then update.
3712 if(rmode = 'Y') then
3713 fetch seqasg into my_rowid, upd_aa_id, src_aa_id, obj_type;
3714 exit when seqasg%notfound;
3715 elsif(rmode = 'N') then
3716 fetch seqper into my_rowid, upd_aa_id, src_aa_id, obj_type;
3717 exit when seqper%notfound;
3718 else
3719 fetch seqgrp into my_rowid, upd_aa_id, src_aa_id, obj_type;
3720 exit when seqgrp%notfound;
3721 end if;
3722 --
3723 hr_utility.trace('Resequenceing '||upd_aa_id);
3724 resequence_children(upd_aa_id);
3725 --
3726 --
3727 -- Now, update with new action_sequence.
3728 update pay_assignment_actions act
3729 set act.action_sequence = pay_assignment_actions_s.nextval
3730 where act.rowid = my_rowid;
3731 --
3732 update pay_run_balances
3733 set action_sequence = pay_assignment_actions_s.currval
3734 where assignment_action_id = upd_aa_id;
3735 --
3736 /* If it's an assignment action thats created due to a
3737 POG then we need to up the POGs action sequence
3738 */
3739 if (obj_type is not null
3740 and obj_type = 'POG'
3741 and src_aa_id is not null) then
3742 --
3743 update pay_assignment_actions act
3744 set act.action_sequence = pay_assignment_actions_s.nextval
3745 where act.assignment_action_id = src_aa_id;
3746 --
3747 end if;
3748 --
3749 end loop;
3750 --
3751 --
3752 -- we are finished with the cursor, so we close it here.
3753 if(rmode = 'Y') then
3754 close seqasg;
3755 elsif(rmode = 'N') then
3756 close seqper;
3757 else
3758 close seqgrp;
3759 end if;
3760 if g_debug then
3761 hr_utility.set_location('hrassact.resequence_actions', 20);
3762 end if;
3763 end resequence_actions;
3764 --
3765 --
3766 /*--------------------------- applied_interlocks -------------------------*/
3767 /*
3768 * Returns a string of the assignment actions ids which are locked by
3769 * the assignment action p_locking_action_id.
3770 */
3771 --
3772 function applied_interlocks(p_locking_action_id number) return varchar2 is
3773 --
3774 -- Cursor definitions
3775 cursor interlocks(p_locking_action_id number) is
3776 select int.locked_action_id locked_action_id
3777 from pay_action_interlocks int
3778 where int.locking_action_id = p_locking_action_id
3779 order by int.locked_action_id;
3780 --
3781 -- Local variables
3782 v_string_max_length constant number := 240;
3783 v_string varchar2(240) := NULL;
3784 v_max_length_reached boolean := false;
3785 --
3786 begin
3787 g_debug := hr_utility.debug_enabled;
3788 --
3789 -- Find interlocks for this assignment action
3790 if g_debug then
3791 hr_utility.set_location('hrassact.applied_interlocks',10);
3792 end if;
3793 <<interlocks_loop>>
3794 for locked IN interlocks(p_locking_action_id) loop
3795 --
3796 if length(rtrim(v_string)) is null then
3797 -- If this is the first locked action id set the string to the id
3798 v_string := locked.locked_action_id;
3799 else
3800 --
3801 if length(rtrim(v_string)) + 1 +
3802 length(rtrim(locked.locked_action_id)) <= v_string_max_length then
3803 -- For the second and subsequent locked action ids, append them to
3804 -- the current string, if there is enough space left for the dash
3805 -- and the whole of the id.
3806 if g_debug then
3807 hr_utility.set_location('hrassact.applied_interlocks',20);
3808 end if;
3809 v_string := v_string || '-' || locked.locked_action_id;
3810 else
3811 --
3812 if length(rtrim(v_string))+2 <= v_string_max_length then
3813 -- If there is no space left at the end of the string for the
3814 -- current locked action id, add the arrow symbol to the end
3815 -- of the string
3816 if g_debug then
3817 hr_utility.set_location('hrassact.applied_interlocks',30);
3818 end if;
3819 v_string := v_string || '->';
3820 else
3821 -- If the end of the string has already been reached,
3822 -- replace the last id with the arrow symbol
3823 if g_debug then
3824 hr_utility.set_location('hrassact.applied_interlocks',40);
3825 end if;
3826 v_string := substr(v_string, 1, instr(v_string, '-', -1, 1)-1)
3827 || '->';
3828 end if;
3829 --
3830 v_max_length_reached := true;
3831 --
3832 end if; -- end if length(v_string) + 1 ...
3833 --
3834 end if; -- end if v_string = ''
3835 --
3836 -- If the end of the string has been reached then end the loop,
3837 -- as there is no space in v_string to list any more ids
3838 exit interlocks_loop when v_max_length_reached;
3839 --
3840 end loop interlocks_loop; -- end for locked IN interlocks
3841 --
3842 if g_debug then
3843 hr_utility.set_location('hrassact.applied_interlocks',40);
3844 end if;
3845 return v_string;
3846 --
3847 end applied_interlocks;
3848 --
3849 ------------------- get_default_leg_value -------------------
3850 /*
3851 NAME
3852 get_default_leg_value
3853 DESCRIPTION
3854 Given a legislative procedure name, identifier
3855 and an element entry id. This procedure calculates
3856 the default value.
3857 */
3858 procedure get_default_leg_value (p_plsql_proc in varchar2,
3859 p_identifier in number,
3860 p_entry in number,
3861 p_effdate in date,
3862 p_value out nocopy varchar2)
3863 is
3864 l_def_rt_str varchar2(2000); -- used with dynamic pl/sql
3865 sql_cursor integer;
3866 l_rows integer;
3867 l_value varchar2(2000);
3868 begin
3869 l_def_rt_str := 'begin '||p_plsql_proc||' (';
3870 l_def_rt_str := l_def_rt_str || ':p_identifier, ';
3871 l_def_rt_str := l_def_rt_str || ':p_entry, ';
3872 l_def_rt_str := l_def_rt_str || ':p_effdate, ';
3873 l_def_rt_str := l_def_rt_str || ':l_value); end; ';
3874 --
3875 sql_cursor := dbms_sql.open_cursor;
3876 --
3877 dbms_sql.parse(sql_cursor, l_def_rt_str, dbms_sql.v7);
3878 --
3879 --
3880 dbms_sql.bind_variable(sql_cursor, 'p_identifier', p_identifier);
3881 --
3882 dbms_sql.bind_variable(sql_cursor, 'p_entry', p_entry);
3883 --
3884 dbms_sql.bind_variable(sql_cursor, 'p_effdate', p_effdate);
3885 --
3886 dbms_sql.bind_variable(sql_cursor, 'l_value', l_value, 30);
3887 --
3888 l_rows := dbms_sql.execute (sql_cursor);
3889 --
3890 if (l_rows = 1) then
3891 dbms_sql.variable_value(sql_cursor, 'l_value',
3892 l_value);
3893 dbms_sql.close_cursor(sql_cursor);
3894 --
3895 else
3896 l_value := null;
3897 dbms_sql.close_cursor(sql_cursor);
3898 end if;
3899 --
3900 p_value := l_value;
3901 --
3902 end get_default_leg_value;
3903 --
3904 ------------------- get_default_leg_value -------------------
3905 /*
3906 NAME
3907 get_default_leg_value
3908 DESCRIPTION
3909 Given a legislative procedure name this procedure
3910 gets the default run type id.
3911 */
3912 procedure get_default_leg_value
3913 (p_plsql_proc in varchar2
3914 ,p_effective_date in varchar2
3915 ,p_run_type_id out nocopy number
3916 ) is
3917 --
3918 begin
3919 --
3920 get_default_leg_value
3921 (p_plsql_proc => p_plsql_proc
3922 ,p_identifier => null
3923 ,p_entry => null
3924 ,p_effdate => p_effective_date
3925 ,p_value => p_run_type_id
3926 );
3927
3928 p_run_type_id := to_number(p_run_type_id);
3929 --
3930 end;
3931 --
3932 --------------------------- cache_contexts------------------------
3933 /*
3934 NAME
3935 cache_contexts - This simply sets up a cache of the context
3936 names
3937 DESCRIPTION
3938 NOTES
3939 */
3940 procedure cache_contexts
3941 is
3942 --
3943 cursor get_cxt is
3944 select context_name,
3945 context_id
3946 from ff_contexts;
3947 --
3948 begin
3949 --
3950 g_context_cache.sz := 0;
3951 --
3952 for cxtrec in get_cxt loop
3953 --
3954 g_context_cache.sz := g_context_cache.sz + 1;
3955 g_context_cache.cxt_id(g_context_cache.sz) := cxtrec.context_id;
3956 g_context_cache.cxt_name(g_context_cache.sz) := cxtrec.context_name;
3957 --
3958 end loop;
3959 --
3960 contexts_cached := TRUE;
3961 --
3962 end cache_contexts;
3963 --
3964 --------------------------- get_cache_context------------------------
3965 /*
3966 NAME
3967 get_cache_context - This retrieves the context id given the
3968 context name from the cache.
3969 DESCRIPTION
3970 NOTES
3971 */
3972 procedure get_cache_context(p_cxt_name in varchar2,
3973 p_cxt_id out nocopy number)
3974 is
3975 --
3976 cxt_num number;
3977 cxt_id number;
3978 found boolean;
3979 begin
3980 --
3981 if (contexts_cached = FALSE) then
3982 cache_contexts;
3983 end if;
3984 --
3985 found := FALSE;
3986 for cxt_num in 1..g_context_cache.sz loop
3987 --
3988 if (g_context_cache.cxt_name(cxt_num) = p_cxt_name) then
3989 found := TRUE;
3990 cxt_id := g_context_cache.cxt_id(cxt_num);
3991 end if;
3992 end loop;
3993 --
3994 if (found = TRUE) then
3995 p_cxt_id := cxt_id;
3996 else
3997 hr_general.assert_condition(FALSE);
3998 end if;
3999 --
4000 end get_cache_context;
4001
4002
4003 --------------------------- inassact ------------------------------
4004 /*
4005 NAME
4006 inassact - INsert ASSignment Action
4007 DESCRIPTION
4008 Inserts and validates the insert of an assignment
4009 action. This is called
4010 a) from the QuickPay processing procedure (qpassact).
4011 b) from the Reversal procedure (reversal).
4012 c) from external/manual payment procedure (ext_man_payment).
4013 d) from the Balance Adjustment procedure (bal_adjust).
4014 e) from the hrbaldtm package (connected to balance user exit).
4015 NOTES
4016 This procedure handles the interlock rules
4017 required in the case of QuickPay, and the
4018 re-sequencing of action_sequence for
4019 Reversal and Balance Adjustment and External/Manual
4020 Payments.
4021 inassact is a cover for inassact_main, to ensure a
4022 taxunt is passed to inassact_main.
4023 */
4024 procedure inassact
4025 (
4026 pactid in number, -- payroll_action_id.
4027 asgid in number, -- assignment_id to create action for.
4028 p_ass_action_seq in number default null, --action sequence
4029 p_serial_number in varchar2 default null, --cheque number
4030 p_pre_payment_id in number default null, --pre payment id
4031 p_element_entry in number default null,
4032 p_asg_lock in boolean default TRUE, --lock assignment
4033 p_purge_mode in boolean default FALSE, --purge mode
4034 run_type_id in number default null
4035 ) is
4036 --
4037 begin
4038 hrassact.inassact_main(pactid, asgid, p_ass_action_seq,
4039 p_serial_number, p_pre_payment_id,
4040 p_element_entry, p_asg_lock, null,
4041 p_purge_mode,run_type_id);
4042 end inassact;
4043 --
4044 procedure inassact_main
4045 (
4046 pactid in number, -- payroll_action_id.
4047 asgid in number, -- assignment_id to create action for.
4048 p_ass_action_seq in number default null, --action sequence
4049 p_serial_number in varchar2 default null, --cheque number
4050 p_pre_payment_id in number default null, --pre payment id
4051 p_element_entry in number default null,
4052 p_asg_lock in boolean default TRUE, --lock assignment
4053 taxunt in number default null, -- tax unit id
4054 p_purge_mode in boolean default FALSE --purge mode
4055 ) is
4056 --
4057 begin
4058 hrassact.inassact_main(pactid, asgid, p_ass_action_seq,
4059 p_serial_number, p_pre_payment_id,
4060 p_element_entry, p_asg_lock, taxunt,
4061 p_purge_mode,null);
4062 end inassact_main;
4063
4064 procedure inassact_main
4065 (
4066 pactid in number, -- payroll_action_id.
4067 asgid in number, -- assignment_id to create action for.
4068 p_ass_action_seq in number default null, --action sequence
4069 p_serial_number in varchar2 default null, --cheque number
4070 p_pre_payment_id in number default null, --pre payment id
4071 p_element_entry in number default null,
4072 p_asg_lock in boolean default TRUE, --lock assignment
4073 taxunt in number default null, -- tax unit id
4074 p_purge_mode in boolean default FALSE, --purge mode
4075 p_run_type_id in number default null
4076 ) is
4077 aa_id number;
4078 begin
4079 aa_id := inassact_main
4080 (
4081 pactid => pactid,
4082 asgid => asgid,
4083 p_ass_action_seq => p_ass_action_seq,
4084 p_serial_number => p_serial_number,
4085 p_pre_payment_id => p_pre_payment_id,
4086 p_element_entry => p_element_entry,
4087 p_asg_lock => p_asg_lock,
4088 taxunt => taxunt,
4089 p_purge_mode => p_purge_mode,
4090 p_run_type_id => p_run_type_id
4091 );
4092 end inassact_main;
4093 --
4094 function inassact_main
4095 (
4096 pactid in number, -- payroll_action_id.
4097 asgid in number, -- assignment_id to create action for.
4098 p_ass_action_seq in number default null, --action sequence
4099 p_serial_number in varchar2 default null, --cheque number
4100 p_pre_payment_id in number default null, --pre payment id
4101 p_element_entry in number default null,
4102 p_asg_lock in boolean default TRUE, --lock assignment
4103 taxunt in number default null, -- tax unit id
4104 p_purge_mode in boolean default FALSE, --purge mode
4105 p_run_type_id in number default null ,
4106 p_mode in varchar2 default 'STANDARD'
4107 ) return number
4108 is
4109 rmode pay_legislation_rules.rule_mode%type;
4110 posid per_periods_of_service.period_of_service_id%type;
4111 actyp pay_payroll_actions.action_type%type;
4112 bgid pay_payroll_actions.business_group_id%type;
4113 l_action_population_status pay_payroll_actions.action_population_status%type;
4114 aa_id number;
4115 --
4116 --------------------------- irbaact ------------------------------
4117 /*
4118 NAME
4119 irbaact - Insert Reversal or Balance Adjustment ACTion.
4120 DESCRIPTION
4121 Insert an assignment action for a Reversal,
4122 Balance Adjustment or non tracked action.
4123 NOTES
4124 This procedure copes with the re-sequencing
4125 that may be required.
4126 Note the call from the balance user exit code
4127 via the hrbaldtm.get_bal_ass_action procedure.
4128 */
4129 procedure irbaact
4130 (
4131 pactid in number, -- payroll_action_id.
4132 asgid in number, -- assignment_id of action to create.
4133 rmode in varchar2, -- rule_mode (time period independent Y or N)
4134 actyp in varchar2, -- action type.
4135 ee_id in number, -- element entry id.
4136 taxunt in number, -- tax unit id
4137 pmode in boolean, -- purge mode
4138 p_run_type_id in number, -- tax unit id
4139 aa_id in number,
4140 p_mode in varchar2
4141 ) is
4142 --
4143 --
4144 -- This cursor selects the rowid values of all
4145 -- the sequenced assignment actions for the
4146 -- specified assignment only, that are later
4147 -- than the effective_date of the specified
4148 -- payroll action.
4149 cursor seqasg (pactid number,
4150 asgid number) is
4151 select ac2.rowid,
4152 ac2.assignment_action_id
4153 from pay_action_classifications acl,
4154 pay_assignment_actions ac2,
4155 pay_assignment_actions act,
4156 pay_payroll_actions pa2,
4157 pay_payroll_actions pac
4158 where pac.payroll_action_id = pactid
4159 and act.payroll_action_id = pac.payroll_action_id
4160 and act.assignment_id = asgid
4161 and ac2.assignment_id = act.assignment_id
4162 and pa2.payroll_action_id = ac2.payroll_action_id
4163 and acl.classification_name = 'SEQUENCED'
4164 and pa2.action_type = acl.action_type
4165 and pa2.effective_date > pac.effective_date
4166 order by pa2.effective_date, ac2.action_sequence
4167 for update of ac2.assignment_action_id;
4168 --
4169 --
4170 -- This cursor selects the rowid values of all
4171 -- the sequenced assignment actions for the
4172 -- specified assignment and any other assignments
4173 -- for that person, that are later than the
4174 -- effective_date of the specified payroll action.
4175 -- Grabs all assignments for person, regardless of
4176 -- period of service.
4177 --
4178 cursor seqper (pactid number,
4179 asgid number) is
4180 select /*+
4181 INDEX(ac2 PAY_ASSIGNMENT_ACTIONS_N51) */
4182 ac2.rowid,
4183 ac2.assignment_action_id
4184 from pay_payroll_actions pac,
4185 pay_assignment_actions act,
4186 per_all_assignments_f asg,
4187 per_all_assignments_f as2,
4188 pay_assignment_actions ac2,
4189 pay_payroll_actions pa2,
4190 pay_action_classifications acl
4191 where pac.payroll_action_id = pactid
4192 and act.payroll_action_id = pac.payroll_action_id
4193 and act.assignment_id = asgid
4194 and asg.assignment_id = act.assignment_id
4195 and pac.effective_date between
4196 asg.effective_start_date and asg.effective_end_date
4197 and as2.person_id = asg.person_id
4198 and as2.effective_end_date > pac.effective_date
4199 and ac2.assignment_id = as2.assignment_id
4200 and pa2.payroll_action_id = ac2.payroll_action_id
4201 and pa2.effective_date between
4202 as2.effective_start_date and as2.effective_end_date
4203 and acl.classification_name = 'SEQUENCED'
4204 and pa2.action_type = acl.action_type
4205 and pa2.effective_date > pac.effective_date
4206 order by pa2.effective_date, ac2.action_sequence
4207 for update of ac2.assignment_action_id;
4208 --
4209 --
4210 -- Pay Object Group (G itpflag):
4211 -- This cursor selects the rowid values of all
4212 -- the sequenced assignment actions for the
4213 -- specified assignment and any other assignments
4214 -- for that person, that are later than the
4215 -- effective_date of the specified payroll action.
4216 -- Grabs all assignments for person, regardless of
4217 -- period of service.
4218 --
4219 cursor seqgrp (pactid number,
4220 asgid number) is
4221 select /*+ ORDERED
4222 INDEX(ac2 PAY_ASSIGNMENT_ACTIONS_PK) */
4223 ac2.rowid,
4224 ac2.assignment_action_id
4225 from
4226 (
4227 select /*+ ORDERED */
4228 distinct ac3.assignment_action_id
4229 from pay_payroll_actions pac,
4230 pay_assignment_actions act,
4231 pay_object_groups pog,
4232 pay_object_groups pog2,
4233 pay_object_groups pog3,
4234 pay_object_groups pog4,
4235 pay_assignment_actions ac3,
4236 pay_payroll_actions pa3,
4237 pay_action_classifications acl
4238 where pac.payroll_action_id = pactid
4239 and act.payroll_action_id = pac.payroll_action_id
4240 and act.assignment_id = asgid
4241 and pog.source_id = act.assignment_id
4242 and pog.source_type = 'PAF'
4243 and pog2.object_group_id = pog.parent_object_group_id
4244 and pog2.source_type = 'PPF'
4245 and pog3.source_id = pog2.source_id
4246 and pog3.source_type = 'PPF'
4247 and pog4.parent_object_group_id = pog3.object_group_id
4248 and ac3.assignment_id = pog4.source_id
4249 and pa3.payroll_action_id = ac3.payroll_action_id
4250 and pa3.effective_date > pac.effective_date
4251 and pa3.action_type <> 'L'
4252 and pa3.action_type = acl.action_type
4253 and acl.classification_name = 'SEQUENCED'
4254 union all
4255 select /*+ ORDERED */
4256 distinct ac3.assignment_action_id
4257 from pay_payroll_actions pac,
4258 pay_assignment_actions act,
4259 pay_object_groups pog,
4260 pay_object_groups pog2,
4261 pay_object_groups pog3,
4262 pay_assignment_actions ac3,
4263 pay_payroll_actions pa3
4264 where pac.payroll_action_id = pactid
4265 and act.payroll_action_id = pac.payroll_action_id
4266 and act.assignment_id = asgid
4267 and pog.source_id = act.assignment_id
4268 and pog.source_type = 'PAF'
4269 and pog2.object_group_id = pog.parent_object_group_id
4270 and pog2.source_type = 'PPF'
4271 and pog3.source_id = pog2.source_id
4272 and pog3.source_type = 'PPF'
4273 and ac3.object_id = pog3.object_group_id
4274 and ac3.object_type = 'POG'
4275 and pa3.payroll_action_id = ac3.payroll_action_id
4276 and pa3.effective_date > pac.effective_date
4277 and pa3.action_type = 'L') V,
4278 pay_assignment_actions ac2,
4279 pay_payroll_actions pa2
4280 where ac2.assignment_action_id = V.assignment_action_id
4281 and pa2.payroll_action_id = ac2.payroll_action_id
4282 order by pa2.effective_date, ac2.action_sequence
4283 for update of ac2.assignment_action_id;
4284 --
4285 cursor perasg (persid number) is
4286 select distinct paf.assignment_id
4287 from per_all_assignments_f paf
4288 where paf.person_id = persid;
4289 --
4290 cursor perobj (asgid number) is
4291 select distinct pog_grp.source_id assignment_id
4292 from pay_object_groups pog_act,
4293 pay_object_groups pog_grp
4294 where pog_act.source_id = asgid
4295 and pog_act.source_type = 'PAF'
4296 and pog_act.parent_object_group_id = pog_grp.parent_object_group_id
4297 and pog_grp.source_type = 'PAF';
4298 --
4299 my_rowid rowid;
4300 upd_aa_id pay_assignment_actions.assignment_action_id%type;
4301 actype pay_payroll_actions.action_type%type;
4302 effdate date; -- the effective date of the payroll action.
4303 lgcode varchar2(30); -- Used to check if the US legislation.
4304 persid number; -- assignments person_id
4305 taxunt2 number; -- The tax unit id if legislation is US
4306 l_run_type_id number;
4307 aa_exists number;
4308 --
4309 begin
4310 g_debug := hr_utility.debug_enabled;
4311 --
4312 taxunt2 := null;
4313 l_run_type_id := p_run_type_id;
4314 --
4315 -- Need the effective date of the payroll action.
4316 -- Also want to see the action_type.
4317 if(actyp <> 'X') then
4318 -- Do not need either effective date or leg code for 'X'.
4319 -- Need the effective date of the payroll action.
4320 -- Also want to see the action_type.
4321 -- The legislation and the tax unit is also needed for the US.
4322 if g_debug then
4323 hr_utility.set_location('hrassact.irbaact',10);
4324 --
4325 hr_utility.trace('pactid = '||pactid);
4326 hr_utility.trace('assignment_id = '||asgid);
4327 end if;
4328 --
4329 select pac.effective_date,
4330 pac.action_type,
4331 pbg.legislation_code,
4332 asg.person_id
4333 into effdate, actype, lgcode, persid
4334 from
4335 per_business_groups_perf pbg,
4336 per_all_assignments_f asg,
4337 pay_payroll_actions pac
4338 where pac.payroll_action_id = pactid
4339 and pbg.business_group_id = asg.business_group_id
4340 and asg.assignment_id = asgid
4341 and pac.effective_date between
4342 asg.effective_start_date and asg.effective_end_date;
4343 --
4344 if (actyp not in ('V','B','I'))
4345 or ((actyp in ('B','I')) and (taxunt is null)) then
4346 --
4347 taxunt2 := hr_dynsql.get_tax_unit(asgid, effdate);
4348 end if;
4349 --
4350 if g_debug then
4351 hr_utility.set_location('hrassact.irbaact',11);
4352 end if;
4353 end if;
4354 --
4355 if (actyp = 'V') then
4356 taxunt2 := taxunt;
4357 end if;
4358 --
4359 -- Need to set the run type for Bal Adj.
4360 -- Note, this is not done for Initialisation. These
4361 -- Have to be set explicitly on initialisation.
4362 if (actyp = 'B') then
4363 --
4364 declare
4365 l_rt_id varchar2(10);
4366 default_run_type pay_legislation_rules.rule_mode%type;
4367 begin
4368 if (p_run_type_id is null) then
4369 begin
4370 select rule_mode
4371 into default_run_type
4372 from pay_legislation_rules
4373 where legislation_code = lgcode
4374 and rule_type = 'DEFAULT_RUN_TYPE';
4375 exception
4376 when no_data_found then
4377 default_run_type := 'N';
4378 end;
4379 --
4380 if (default_run_type = 'Y') then
4381 get_default_leg_value('pay_' || lgcode || '_rules.get_default_run_type',
4382 asgid,
4383 ee_id,
4384 effdate,
4385 l_rt_id);
4386 l_run_type_id := to_number(l_rt_id);
4387 end if;
4388 end if;
4389 end;
4390 end if;
4391 --
4392 if (actyp in ('B', 'I')) then
4393 if (taxunt is not null) then
4394 taxunt2 := taxunt;
4395 end if;
4396 end if;
4397 --
4398 -- Before we go further, trash latest balances.
4399 -- Don't trash for non tracked action.
4400 -- Note that this is used for the balance function.
4401
4402 if(actype <> 'N' and actype <> 'X' and actype <> 'B' and
4403 actype <> 'I' and actype <> 'V') then
4404 del_latest_balances(asgid, effdate, p_element_entry);
4405 end if;
4406 --
4407 -- insert an assigment action.
4408 if g_debug then
4409 hr_utility.set_location('hrassact.irbaact',20);
4410 end if;
4411 if((actype = 'V' or actype = 'I' or actype = 'B')
4412 and p_mode <> 'BACKPAY') then
4413 -- we need to check that there isn't a failed action for this
4414 -- assignment/person/group
4415 if (rmode = 'Y') then
4416 begin
4417 select 1
4418 into aa_exists
4419 from dual
4420 where exists (
4421 select /*+ INDEX (pay_pa2 pay_payroll_actions_pk) */ null
4422 from pay_action_classifications pay_acl,
4423 pay_payroll_actions pay_pa2,
4424 pay_assignment_actions pay_ac2
4425 where pay_ac2.assignment_id = asgid
4426 and pay_pa2.payroll_action_id = pay_ac2.payroll_action_id
4427 and pay_acl.classification_name = 'SEQUENCED'
4428 and pay_pa2.action_type = pay_acl.action_type
4429 and pay_ac2.action_status not in ('C', 'S', 'B'));
4430 exception
4431 when no_data_found then
4432 aa_exists := 0;
4433 end;
4434 elsif (rmode = 'N') then
4435 aa_exists := 0;
4436 for dprec in perasg(persid) loop
4437 begin
4438 select 1
4439 into aa_exists
4440 from sys.dual
4441 where exists (
4442 select /*+ INDEX (pay_pa2 pay_payroll_actions_pk) */ null
4443 from pay_action_classifications pay_acl,
4444 pay_payroll_actions pay_pa2,
4445 pay_assignment_actions pay_ac2
4446 where pay_ac2.assignment_id = dprec.assignment_id
4447 and pay_pa2.payroll_action_id = pay_ac2.payroll_action_id
4448 and pay_acl.classification_name = 'SEQUENCED'
4449 and pay_pa2.action_type = pay_acl.action_type
4450 and pay_ac2.action_status not in ('C', 'S', 'B'));
4451
4452 exit;
4453 exception
4454 when no_data_found then
4455 null;
4456 end;
4457 end loop;
4458 else
4459 -- rmode = G
4460 aa_exists := 0;
4461 for dprec in perobj(asgid) loop
4462 begin
4463 select 1
4464 into aa_exists
4465 from sys.dual
4466 where exists (
4467 select /*+ INDEX (pay_pa2 pay_payroll_actions_pk) */ null
4468 from pay_action_classifications pay_acl,
4469 pay_payroll_actions pay_pa2,
4470 pay_assignment_actions pay_ac2
4471 where pay_ac2.assignment_id = dprec.assignment_id
4472 and pay_pa2.payroll_action_id = pay_ac2.payroll_action_id
4473 and pay_acl.classification_name = 'SEQUENCED'
4474 and pay_pa2.action_type = pay_acl.action_type
4475 and pay_ac2.action_status not in ('C', 'S', 'B'));
4476
4477 exit;
4478 exception
4479 when no_data_found then
4480 null;
4481 end;
4482 end loop;
4483 end if;
4484 if(aa_exists <> 0) then
4485 hr_utility.set_message(801,'HR_7010_ACTION_INTLOCK_FAIL');
4486 hr_utility.raise_error;
4487 end if;
4488 end if;
4489 -- we need to check that there is not a purge action
4490 -- with an effective date later than the effective
4491 -- date of the assignment action we are about to
4492 -- insert. If so, raise an error.
4493 -- An exception is the 'I' action. It can be inserted
4494 -- before a purge, because a Purge uses balance
4495 -- initialisation to perform balance rollup.
4496 if g_debug then
4497 hr_utility.set_location('hrassact.irbaact',25);
4498 end if;
4499 insert into pay_assignment_actions (
4500 assignment_action_id,
4501 assignment_id,
4502 payroll_action_id,
4503 action_status,
4504 chunk_number,
4505 action_sequence,
4506 object_version_number,
4507 tax_unit_id,
4508 run_type_id)
4509 select aa_id,
4510 asgid,
4511 pactid,
4512 decode(actyp, 'N', 'U', 'X', 'U', 'C'),
4513 1,
4514 aa_id,
4515 1,
4516 taxunt2,
4517 l_run_type_id
4518 from sys.dual
4519 where not exists (
4520 select null
4521 from pay_payroll_actions pac,
4522 pay_payroll_actions pa2,
4523 pay_assignment_actions act,
4524 pay_assignment_actions ac2
4525 where pac.payroll_action_id = pactid
4526 and pac.action_type <> 'I'
4527 and act.payroll_action_id = pac.payroll_action_id
4528 and act.assignment_id = asgid
4529 and ac2.assignment_id = act.assignment_id
4530 and pa2.payroll_action_id = ac2.payroll_action_id
4531 and pa2.action_type = 'Z'
4532 and pa2.effective_date > pac.effective_date);
4533 --
4534 if(sql%rowcount = 0) then
4535 hr_utility.set_message(801,'HR_7009_ACTION_FUTURE_PURGE');
4536 hr_utility.raise_error;
4537 end if;
4538 --
4539 -- If we are really getting called from purge, we do not
4540 -- want to perform any re-sequencing. Purge mode is actually
4541 -- only set when we are creating balance initialzation actions
4542 -- but we DO want to contine re-sequencing when performing
4543 -- a "normal" initialization.
4544 -- When purge mode is operating, the purge process itself
4545 -- takes responsibility for any re-sequencing required.
4546 if(not pmode) then
4547 -- method is to loop round the selected assignment
4548 -- action rows, updating the action sequence.
4549 -- We do not attempt a correlated update, since we
4550 -- need to aquire and hold locks on all the rows.
4551 -- NOTE - the update of sequences for 'X' actions will
4552 -- work correctly because the seqasg cursor does not
4553 -- join to per_all_assignments_f.
4554 if g_debug then
4555 hr_utility.set_location('hrassact.irbaact',30);
4556 end if;
4557 if(rmode = 'Y') then
4558 open seqasg(pactid, asgid);
4559 elsif(rmode = 'N') then
4560 open seqper(pactid, asgid);
4561 else
4562 open seqgrp(pactid, asgid);
4563 end if;
4564 --
4565 loop
4566 -- fetch the rowid and then update.
4567 if(rmode = 'Y') then
4568 fetch seqasg into my_rowid, upd_aa_id;
4569 exit when seqasg%notfound;
4570 elsif(rmode = 'N') then
4571 fetch seqper into my_rowid, upd_aa_id;
4572 exit when seqper%notfound;
4573 else
4574 fetch seqgrp into my_rowid, upd_aa_id;
4575 exit when seqgrp%notfound;
4576 end if;
4577 --
4578 --
4579 -- Now, update with new action_sequence.
4580 update pay_assignment_actions act
4581 set act.action_sequence = pay_assignment_actions_s.nextval
4582 where act.rowid = my_rowid;
4583 --
4584 update pay_run_balances
4585 set action_sequence = pay_assignment_actions_s.currval
4586 where assignment_action_id = upd_aa_id;
4587 end loop;
4588 --
4589 --
4590 -- we are finished with the cursor, so we close it here.
4591 if(rmode = 'Y') then
4592 close seqasg;
4593 elsif(rmode = 'N') then
4594 close seqper;
4595 else
4596 close seqgrp;
4597 end if;
4598 end if;
4599 end irbaact;
4600 --
4601 begin
4602 g_debug := hr_utility.debug_enabled;
4603 --
4604 -- Start by grabbing the type of the action we are dealing with.
4605 select pac.action_type,
4606 pac.business_group_id,
4607 pay_assignment_actions_s.nextval
4608 into actyp,
4609 bgid,
4610 aa_id
4611 from pay_payroll_actions pac
4612 where pac.payroll_action_id = pactid;
4613 --
4614 -- Most of the action types require that we look for the legislation
4615 -- rule, i.e. time period dependent (i.e. UK) or time period
4616 -- independent (i.e. US) time periods. However, we ignore this for
4617 -- E(X)tract actions, which are a special case.
4618 begin
4619 if(actyp <> 'X') then
4620 -- take the opportunity here to lock the assignment
4621 -- and period of service of the person.
4622 if g_debug then
4623 hr_utility.set_location('hrassact.inassact_main',10);
4624 end if;
4625 if (p_asg_lock) then
4626 -- We wish to lock the assignment and period of service.
4627 declare
4628 posid number;
4629 begin
4630 select /*+ ORDERED
4631 INDEX (asg PER_ASSIGNMENTS_F_PK)
4632 USE_NL(asg) */
4633 asg.business_group_id,
4634 asg.period_of_service_id
4635 into bgid, posid
4636 from pay_payroll_actions pac,
4637 per_all_assignments_f asg
4638 where pac.payroll_action_id = pactid
4639 and asg.assignment_id = asgid
4640 and pac.effective_date between
4641 asg.effective_start_date and asg.effective_end_date
4642 for update of asg.assignment_id;
4643
4644 if posid is not null then
4645 begin
4646 select 1
4647 into posid
4648 from per_periods_of_service pos
4649 where pos.period_of_service_id = posid
4650 for update of pos.period_of_service_id;
4651 exception
4652 when no_data_found then
4653 null;
4654 end;
4655 end if;
4656 end;
4657 end if;
4658 --
4659 if g_debug then
4660 hr_utility.set_location('hrassact.inassact_main',15);
4661 end if;
4662 --
4663 -- get the rule_mode
4664 select /*+ ORDERED*/ plr.rule_mode
4665 into rmode
4666 from per_business_groups_perf grp,
4667 pay_legislation_rules plr
4668 where grp.business_group_id = bgid
4669 and plr.legislation_code = grp.legislation_code
4670 and plr.rule_type = 'I'
4671 and plr.rule_mode in ('Y','N','G');
4672 --
4673 end if;
4674 --
4675 exception
4676 when no_data_found then
4677 rmode := 'N';
4678 end;
4679 --
4680 --
4681 -- Different processing, depending on the type of action.
4682 if(actyp = 'Q') then
4683 -- process QuickPay.
4684 -- Defferent processing depending on the rule mode.
4685 -- the statements below both check that the assignment
4686 -- is date effective for date_earned and date_paid
4687 -- (i.e. effective_date). This is is exactly the same
4688 -- as for the run.
4689 if(rmode = 'Y') then
4690 -- time period independent legislation.
4691 if g_debug then
4692 hr_utility.set_location('hrassact.inassact_main',20);
4693 end if;
4694 if (gv_dum_qpay) then
4695 hr_utility.set_location('hrassact.inassact_main Dummy quickpay ',20);
4696 insert into pay_assignment_actions (
4697 assignment_action_id,
4698 assignment_id,
4699 payroll_action_id,
4700 action_status,
4701 chunk_number,
4702 action_sequence,
4703 object_version_number,
4704 tax_unit_id)
4705 select aa_id,
4706 asgid,
4707 pac.payroll_action_id,
4708 'U',
4709 1,
4710 aa_id,
4711 1,
4712 hr_dynsql.get_tax_unit(asg.assignment_id,
4713 pac.effective_date)
4714 from
4715 per_business_groups_perf pbg,
4716 per_all_assignments_f asg,
4717 per_all_assignments_f as2,
4718 pay_payroll_actions pac
4719 where pac.payroll_action_id = pactid
4720 and asg.payroll_id = pac.payroll_id
4721 and asg.assignment_id = asgid
4722 and pac.effective_date between
4723 asg.effective_start_date and asg.effective_end_date
4724 and as2.assignment_id = asg.assignment_id
4725 and pac.date_earned between
4726 as2.effective_start_date and as2.effective_end_date
4727 and pbg.business_group_id = pac.business_group_id
4728 and not exists (
4729 select null
4730 from pay_payroll_actions pa2,
4731 pay_assignment_actions ac2,
4732 per_time_periods ptp
4733 where ac2.assignment_id = asg.assignment_id
4734 and pa2.payroll_action_id = ac2.payroll_action_id
4735 and ptp.payroll_id = pac.payroll_id
4736 and pac.effective_date between ptp.start_date and ptp.end_date
4737 and pa2.effective_date <= ptp.end_date);
4738 else
4739 hr_utility.set_location('hrassact.inassact_main Normal quickpay ',20);
4740 insert into pay_assignment_actions (
4741 assignment_action_id,
4742 assignment_id,
4743 payroll_action_id,
4744 action_status,
4745 chunk_number,
4746 action_sequence,
4747 object_version_number,
4748 tax_unit_id)
4749 select aa_id,
4750 asgid,
4751 pac.payroll_action_id,
4752 'U',
4753 1,
4754 aa_id,
4755 1,
4756 hr_dynsql.get_tax_unit(asg.assignment_id,
4757 pac.effective_date)
4758 from
4759 per_business_groups_perf pbg,
4760 per_all_assignments_f asg,
4761 per_all_assignments_f as2,
4762 pay_payroll_actions pac
4763 where pac.payroll_action_id = pactid
4764 and asg.payroll_id = pac.payroll_id
4765 and asg.assignment_id = asgid
4766 and pac.effective_date between
4767 asg.effective_start_date and asg.effective_end_date
4768 and as2.assignment_id = asg.assignment_id
4769 and pac.date_earned between
4770 as2.effective_start_date and as2.effective_end_date
4771 and pbg.business_group_id = pac.business_group_id
4772 and not exists (
4773 select null
4774 from pay_action_classifications acl,
4775 pay_payroll_actions pa2,
4776 pay_assignment_actions ac2
4777 where ac2.assignment_id = asg.assignment_id
4778 and pa2.payroll_action_id = ac2.payroll_action_id
4779 and acl.classification_name = 'SEQUENCED'
4780 and pa2.action_type = acl.action_type
4781 and (pa2.effective_date > pac.effective_date
4782 or (ac2.action_status not in ('C', 'S')
4783 and pa2.effective_date <= pac.effective_date)));
4784 end if;
4785 elsif rmode = 'G' then -- bug 13541539
4786 -- POG dependent legislation
4787 if g_debug then
4788 hr_utility.set_location('hrassact.inassact_main',22);
4789 end if;
4790 if (gv_dum_qpay) then
4791 hr_utility.set_location('hrassact.inassact_main Dummy quickpay ',22);
4792 insert into pay_assignment_actions (
4793 assignment_action_id,
4794 assignment_id,
4795 payroll_action_id,
4796 action_status,
4797 chunk_number,
4798 action_sequence,
4799 object_version_number,
4800 tax_unit_id)
4801 select aa_id,
4802 asgid,
4803 pac.payroll_action_id,
4804 'U',
4805 1,
4806 aa_id,
4807 1,
4808 hr_dynsql.get_tax_unit(asg.assignment_id,
4809 pac.effective_date)
4810 from per_business_groups_perf pbg,
4811 per_all_assignments_f asg,
4812 per_all_assignments_f as2,
4813 pay_object_groups pog,
4814 pay_payroll_actions pac
4815 where pac.payroll_action_id = pactid
4816 and asg.payroll_id = pac.payroll_id
4817 and asg.assignment_id = asgid
4818 and pac.effective_date between
4819 asg.effective_start_date and asg.effective_end_date
4820 and as2.assignment_id = asg.assignment_id
4821 and pac.date_earned between
4822 as2.effective_start_date and as2.effective_end_date
4823 and pog.source_id = asgid
4824 and pac.effective_date between
4825 pog.start_date and pog.end_date
4826 and pog.source_type = 'PAF'
4827 and pbg.business_group_id = pac.business_group_id
4828 and not exists (
4829 select /*+ INDEX (pa2 PAY_PAYROLL_ACTIONS_PK)
4830 INDEX (ac2 PAY_ASSIGNMENT_ACTIONS_N1) */ null
4831 from pay_assignment_actions ac2,
4832 pay_payroll_actions pa2,
4833 pay_object_groups pog2,
4834 per_time_periods ptp
4835 where pog2.parent_object_group_id = pog.parent_object_group_id
4836 and ac2.assignment_id = pog2.source_id
4837 and pa2.payroll_action_id = ac2.payroll_action_id
4838 and ptp.payroll_id = pac.payroll_id
4839 and pac.effective_date between ptp.start_date and ptp.end_date
4840 and pa2.effective_date <= ptp.end_date);
4841 else
4842 hr_utility.set_location('hrassact.inassact_main Normal quickpay ',22);
4843 insert into pay_assignment_actions (
4844 assignment_action_id,
4845 assignment_id,
4846 payroll_action_id,
4847 action_status,
4848 chunk_number,
4849 action_sequence,
4850 object_version_number,
4851 tax_unit_id)
4852 select aa_id,
4853 asgid,
4854 pac.payroll_action_id,
4855 'U',
4856 1,
4857 aa_id,
4858 1,
4859 hr_dynsql.get_tax_unit(asg.assignment_id,
4860 pac.effective_date)
4861 from per_business_groups_perf pbg,
4862 per_all_assignments_f asg,
4863 per_all_assignments_f as2,
4864 pay_object_groups pog,
4865 pay_payroll_actions pac
4866 where pac.payroll_action_id = pactid
4867 and asg.payroll_id = pac.payroll_id
4868 and asg.assignment_id = asgid
4869 and pac.effective_date between
4870 asg.effective_start_date and asg.effective_end_date
4871 and as2.assignment_id = asg.assignment_id
4872 and pac.date_earned between
4873 as2.effective_start_date and as2.effective_end_date
4874 and pog.source_id = asgid
4875 and pac.effective_date between
4876 pog.start_date and pog.end_date
4877 and pog.source_type = 'PAF'
4878 and pbg.business_group_id = pac.business_group_id
4879 and not exists (
4880 select /*+ INDEX (pa2 PAY_PAYROLL_ACTIONS_PK)
4881 INDEX (ac2 PAY_ASSIGNMENT_ACTIONS_N1) */ null
4882 from pay_action_classifications acl,
4883 pay_assignment_actions ac2,
4884 pay_payroll_actions pa2,
4885 pay_object_groups pog2
4886 where pog2.parent_object_group_id = pog.parent_object_group_id
4887 and ac2.assignment_id = pog2.source_id
4888 and pa2.payroll_action_id = ac2.payroll_action_id
4889 and acl.classification_name = 'SEQUENCED'
4890 and pa2.action_type = acl.action_type
4891 and (pa2.effective_date > pac.effective_date
4892 or (ac2.action_status not in ('C', 'S')
4893 and pa2.effective_date <= pac.effective_date)));
4894 end if;
4895 --
4896 else
4897 -- time period dependent legislation.
4898 if g_debug then
4899 hr_utility.set_location('hrassact.inassact_main',30);
4900 end if;
4901 if (gv_dum_qpay) then
4902 hr_utility.set_location('hrassact.inassact_main Dummy quickpay ',30);
4903 insert into pay_assignment_actions (
4904 assignment_action_id,
4905 assignment_id,
4906 payroll_action_id,
4907 action_status,
4908 chunk_number,
4909 action_sequence,
4910 object_version_number,
4911 tax_unit_id)
4912 select aa_id,
4913 asgid,
4914 pac.payroll_action_id,
4915 'U',
4916 1,
4917 aa_id,
4918 1,
4919 hr_dynsql.get_tax_unit(asg.assignment_id,
4920 pac.effective_date)
4921 from per_business_groups_perf pbg,
4922 per_all_assignments_f asg,
4923 per_all_assignments_f as2,
4924 per_periods_of_service pos,
4925 pay_payroll_actions pac
4926 where pac.payroll_action_id = pactid
4927 and asg.payroll_id = pac.payroll_id
4928 and asg.assignment_id = asgid
4929 and pos.period_of_service_id = asg.period_of_service_id
4930 and pac.effective_date between
4931 asg.effective_start_date and asg.effective_end_date
4932 and as2.assignment_id = asg.assignment_id
4933 and pac.date_earned between
4934 as2.effective_start_date and as2.effective_end_date
4935 and pbg.business_group_id = pac.business_group_id
4936 and not exists (
4937 select /*+ INDEX (pa2 PAY_PAYROLL_ACTIONS_PK)
4938 INDEX (ac2 PAY_ASSIGNMENT_ACTIONS_N1) */ null
4939 from pay_assignment_actions ac2,
4940 pay_payroll_actions pa2,
4941 per_all_assignments_f as2,
4942 per_time_periods ptp
4943 where as2.period_of_service_id = pos.period_of_service_id
4944 and ac2.assignment_id = as2.assignment_id
4945 and pa2.payroll_action_id = ac2.payroll_action_id
4946 and ptp.payroll_id = pac.payroll_id
4947 and pac.effective_date between ptp.start_date and ptp.end_date
4948 and pa2.effective_date <= ptp.end_date);
4949 else
4950 hr_utility.set_location('hrassact.inassact_main Normal quickpay ',30);
4951 -- Changes for bug 12356133, forced indexes PAY_PAYROLL_ACTIONS_PK and
4952 -- PAY_ASSIGNMENT_ACTIONS_N1 through hints.
4953 insert into pay_assignment_actions (
4954 assignment_action_id,
4955 assignment_id,
4956 payroll_action_id,
4957 action_status,
4958 chunk_number,
4959 action_sequence,
4960 object_version_number,
4961 tax_unit_id)
4962 select aa_id,
4963 asgid,
4964 pac.payroll_action_id,
4965 'U',
4966 1,
4967 aa_id,
4968 1,
4969 hr_dynsql.get_tax_unit(asg.assignment_id,
4970 pac.effective_date)
4971 from per_business_groups_perf pbg,
4972 per_all_assignments_f asg,
4973 per_all_assignments_f as2,
4974 per_periods_of_service pos,
4975 pay_payroll_actions pac
4976 where pac.payroll_action_id = pactid
4977 and asg.payroll_id = pac.payroll_id
4978 and asg.assignment_id = asgid
4979 and pos.period_of_service_id = asg.period_of_service_id
4980 and pac.effective_date between
4981 asg.effective_start_date and asg.effective_end_date
4982 and as2.assignment_id = asg.assignment_id
4983 and pac.date_earned between
4984 as2.effective_start_date and as2.effective_end_date
4985 and pbg.business_group_id = pac.business_group_id
4986 and not exists (
4987 select /*+ INDEX (pa2 PAY_PAYROLL_ACTIONS_PK)
4988 INDEX (ac2 PAY_ASSIGNMENT_ACTIONS_N1) */ null
4989 from pay_action_classifications acl,
4990 pay_assignment_actions ac2,
4991 pay_payroll_actions pa2,
4992 per_all_assignments_f as2
4993 where as2.period_of_service_id = pos.period_of_service_id
4994 and ac2.assignment_id = as2.assignment_id
4995 and pa2.payroll_action_id = ac2.payroll_action_id
4996 and acl.classification_name = 'SEQUENCED'
4997 and pa2.action_type = acl.action_type
4998 and (pa2.effective_date > pac.effective_date
4999 or (ac2.action_status not in ('C', 'S')
5000 and pa2.effective_date <= pac.effective_date)));
5001 end if;
5002 end if;
5003 --
5004 -- Check if a row was inserted.
5005 -- If a row was not inserted, it must mean interlock
5006 -- rule failure for that particular assignment.
5007 -- This condition is reported via an error message.
5008 if(sql%rowcount = 0) then
5009 hr_utility.set_message(801,'HR_7010_ACTION_INTLOCK_FAIL');
5010 hr_utility.raise_error;
5011 end if;
5012 elsif (actyp in ('V','B','N','X','I')) then
5013 --
5014 -- The following called to create assignment action for
5015 -- Reversal, Balance Adjustment Non Tracked, Archive and
5016 -- Balance Upload actions.
5017 -- The non tracked case is for the balance user exit.
5018 irbaact(pactid,asgid,rmode,actyp, p_element_entry, taxunt,
5019 p_purge_mode,p_run_type_id,aa_id, p_mode);
5020 elsif (actyp = 'E') then
5021 --
5022 -- Insert a pay_assignment_actions record for Pre-payment
5023 -- External/Manual payments.
5024 -- Only do this if the pre-payment has not already
5025 -- been paid.
5026 -- This is detected if there is any assignment action
5027 -- with a pre_payment_id the same as that we are attempting
5028 -- to process which is not locked by a void action.
5029 insert into PAY_ASSIGNMENT_ACTIONS (
5030 ASSIGNMENT_ACTION_ID,
5031 ASSIGNMENT_ID,
5032 PAYROLL_ACTION_ID,
5033 ACTION_STATUS,
5034 CHUNK_NUMBER,
5035 ACTION_SEQUENCE,
5036 PRE_PAYMENT_ID,
5037 SERIAL_NUMBER,
5038 OBJECT_VERSION_NUMBER)
5039 select p_ass_action_seq,
5040 asgid,
5041 pactid,
5042 'C',
5043 1,
5044 PAY_ASSIGNMENT_ACTIONS_S.nextval,
5045 p_pre_payment_id,
5046 p_serial_number,
5047 1
5048 from sys.dual
5049 where not exists (
5050 select null
5051 from pay_assignment_actions act
5052 where act.pre_payment_id = p_pre_payment_id
5053 and not exists
5054 ( select null
5055 from pay_action_interlocks loc1,
5056 pay_assignment_actions actv,
5057 pay_payroll_actions pactv
5058 where loc1.locked_action_id = act.assignment_action_id
5059 and loc1.locking_action_id = actv.assignment_action_id
5060 and pactv.payroll_action_id = actv.payroll_action_id
5061 and pactv.action_type = 'D'
5062 )
5063 ) ;
5064
5065 --
5066 -- Check that a row has been inserted.
5067 if g_debug then
5068 hr_utility.set_location('hrassact.inassact_main',40);
5069 end if;
5070 if(sql%rowcount = 0) then
5071 hr_utility.set_message(801,'HR_7010_ACTION_INTLOCK_FAIL');
5072 hr_utility.raise_error;
5073 end if;
5074 --
5075 elsif (actyp = 'U') then
5076 -- Insert an assignment action for a QuickPay Pre-Payment.
5077 -- We perform validation of the interlock rules here.
5078 -- kkawol: Only return rows for master assignment action.
5079 --
5080 if g_debug then
5081 hr_utility.set_location('hrassact.inassact_main',45);
5082 end if;
5083 insert into PAY_ASSIGNMENT_ACTIONS (
5084 ASSIGNMENT_ACTION_ID,
5085 ASSIGNMENT_ID,
5086 PAYROLL_ACTION_ID,
5087 ACTION_STATUS,
5088 CHUNK_NUMBER,
5089 ACTION_SEQUENCE,
5090 OBJECT_VERSION_NUMBER,
5091 TAX_UNIT_ID)
5092 select aa_id,
5093 act.assignment_id,
5094 pac.payroll_action_id, -- qpprepay pact.
5095 'U',
5096 1,
5097 aa_id,
5098 1,
5099 hr_dynsql.get_tax_unit(asg.assignment_id,
5100 pac.effective_date)
5101 from per_business_groups_perf pbg,
5102 pay_assignment_actions act,
5103 pay_payroll_actions pac, -- prepay action.
5104 pay_payroll_actions pa2, -- the QuickPay action.
5105 per_periods_of_service pos,
5106 per_all_assignments_f asg
5107 where pac.payroll_action_id = pactid
5108 and pa2.payroll_action_id = pac.target_payroll_action_id
5109 and act.payroll_action_id = pa2.payroll_action_id
5110 and act.source_action_id is null /* master assignment action */
5111 and asg.assignment_id = act.assignment_id
5112 and pa2.effective_date between
5113 asg.effective_start_date and asg.effective_end_date
5114 and pos.period_of_service_id = asg.period_of_service_id
5115 and pbg.business_group_id = pac.business_group_id
5116 and not exists (
5117 select null
5118 from pay_assignment_actions ac2,
5119 pay_payroll_actions pa3,
5120 pay_action_interlocks int
5121 where int.locked_action_id = act.assignment_action_id
5122 and ac2.assignment_action_id = int.locking_action_id
5123 and pa3.payroll_action_id = ac2.payroll_action_id
5124 and pa3.action_type in ('P', 'U'))
5125 and not exists (
5126 select null
5127 from per_all_assignments_f as3,
5128 pay_assignment_actions ac3
5129 where rmode <> 'Y'
5130 and ac3.payroll_action_id = pa2.payroll_action_id
5131 and ac3.action_status not in ('C', 'S')
5132 and as3.assignment_id = ac3.assignment_id
5133 and pa2.effective_date between
5134 as3.effective_start_date and as3.effective_end_date
5135 and as3.person_id = pos.person_id);
5136 else
5137 -- If we get here, we are attempting to process
5138 -- an illegal action type.
5139 hr_utility.set_message(801,'HR_7034_ACTION_TYP_INV_VBN');
5140 hr_utility.raise_error;
5141 end if;
5142 --
5143 --
5144 -- update the action_population_status to indicate
5145 -- an action has been successfully inserted.
5146 if g_debug then
5147 hr_utility.set_location('hrassact.inassact_main',50);
5148 end if;
5149
5150 begin
5151 select pac.action_population_status
5152 into l_action_population_status
5153 from pay_payroll_actions pac
5154 where pac.payroll_action_id = pactid;
5155 exception
5156 when others then
5157 l_action_population_status := 'U';
5158 end;
5159
5160 if l_action_population_status <> 'C' then
5161 update pay_payroll_actions pac
5162 set pac.action_population_status = 'C'
5163 where pac.payroll_action_id = pactid;
5164 end if;
5165 --
5166 return aa_id;
5167 --
5168 end inassact_main;
5169 --
5170 ----------------------------- qpassact ------------------------------
5171 /*
5172 NAME
5173 qpassact - insert QuickPay ASSignment Action
5174 DESCRIPTION
5175 Inserts and validates the insert of an assignment
5176 action for the QuickPay user exit.
5177 NOTES
5178 This procedure directly calls inassact.
5179 */
5180 procedure qpassact
5181 (
5182 p_payroll_action_id in number, -- payroll_action_id.
5183 p_assignment_id in number, -- assignment_id to create action for.
5184 p_assignment_action_id out nocopy number,
5185 p_object_version_number out nocopy number
5186 ) is
5187 assactid number;
5188 c_indent constant varchar2(30) := 'hrassact.qpassact';
5189 begin
5190 g_debug := hr_utility.debug_enabled;
5191 --
5192 -- Simply call the inassact procedure.
5193 if g_debug then
5194 hr_utility.set_location(c_indent,5);
5195 end if;
5196 inassact(p_payroll_action_id, p_assignment_id, null, null, null);
5197 --
5198 -- Get the assignment_action_id
5199 -- that has just been inserted
5200 select pay_assignment_actions_s.currval
5201 into assactid
5202 from sys.dual;
5203 --
5204 -- Return information.
5205 p_assignment_action_id := assactid;
5206 p_object_version_number := 1;
5207 end qpassact;
5208 --
5209 --------------------------- qpppassact ------------------------------
5210 /*
5211 NAME
5212 qpppassact - Insert a QuickPay Pre-Payment action.
5213 DESCRIPTION
5214 Process a QuickPay Pre-Payment action.
5215 NOTES
5216 This procedure is meant to be called via the QuickPay form.
5217 */
5218 procedure qpppassact
5219 (
5220 p_payroll_action_id in number, -- of QuickPay pre-payment.
5221 p_assignment_action_id out nocopy number,
5222 p_object_version_number out nocopy number
5223 ) is
5224 l_assignment_id number;
5225 l_locking_action_id number;
5226 l_locked_action_id number;
5227 begin
5228 g_debug := hr_utility.debug_enabled;
5229 --
5230 -- We have to get the assignment_id
5231 -- of the assignment that is going
5232 -- to be prepaid, so it may be passed on.
5233 -- kkawol: query restricted to only return the assignment id
5234 -- of the master action.
5235 --
5236 if g_debug then
5237 hr_utility.set_location('hrassact.qpppassact',10);
5238 end if;
5239 select act.assignment_id
5240 into l_assignment_id
5241 from pay_assignment_actions act,
5242 pay_payroll_actions pac
5243 where pac.payroll_action_id = p_payroll_action_id
5244 and act.payroll_action_id = pac.target_payroll_action_id
5245 and act.source_action_id is null;
5246 --
5247 -- Start by simply inserting an assignment action.
5248 if g_debug then
5249 hr_utility.set_location('hrassact.qpppassact',20);
5250 end if;
5251 hrassact.inassact(p_payroll_action_id,l_assignment_id,null,null,null);
5252 --
5253 -- Get some information for insert to interlocks.
5254 -- kkawol: Only returning details for the master action.
5255 --
5256 if g_debug then
5257 hr_utility.set_location('hrassact.qpppassact',30);
5258 end if;
5259 select pay_assignment_actions_s.currval,
5260 act.assignment_action_id
5261 into l_locking_action_id,
5262 l_locked_action_id
5263 from pay_payroll_actions pac,
5264 pay_assignment_actions act
5265 where pac.payroll_action_id = p_payroll_action_id
5266 and act.payroll_action_id = pac.target_payroll_action_id
5267 and act.source_action_id is null;
5268 --
5269 -- We can now insert interlock row.
5270 if g_debug then
5271 hr_utility.set_location('hrassact.qpppassact',40);
5272 end if;
5273 insert into pay_action_interlocks (
5274 locking_action_id,
5275 locked_action_id)
5276 values (l_locking_action_id,
5277 l_locked_action_id);
5278 --
5279 -- Update the payroll actions table with the
5280 -- appropriate date_earned value.
5281 if g_debug then
5282 hr_utility.set_location('hrassact.qpppassact',50);
5283 end if;
5284 update pay_payroll_actions pac
5285 set pac.date_earned = (
5286 select pa2.date_earned
5287 from pay_payroll_actions pa2,
5288 pay_assignment_actions act
5289 where act.assignment_action_id = l_locked_action_id
5290 and pa2.payroll_action_id = act.payroll_action_id)
5291
5292 where pac.payroll_action_id =p_payroll_action_id;
5293 --
5294
5295 p_assignment_action_id := l_locking_action_id;
5296 p_object_version_number := 1;
5297 --
5298 end qpppassact;
5299 --
5300 --------------------------- reversal ------------------------------
5301 /*
5302 NAME
5303 reversal - Process a reversal.
5304 DESCRIPTION
5305 Process a reversal for an assignment action.
5306 NOTES
5307 - This is called directly from the Reversal form.
5308 This fucntion reverses all appropriate run results.
5309 By 'appropriate', we mean all numeric unit of measure.
5310 This currently leads us to negate input values such as
5311 'rate' and so on, as there is currently no way of telling
5312 the reversal not to do so. This may be altered in a
5313 subsequent version.
5314 - The redo parameter indicates whether or not we need to
5315 insert an assignment action and interlock. If redo is
5316 set true, we do not need to. This was introduced to
5317 cope with the requirements for BackPay.
5318 - The multi flag indicates if we are calling this as part of
5319 the assignment set reversal procedure in which case we want to
5320 skip the initial setup part of this procedure
5321 */
5322 procedure reversal
5323 (
5324 pactid in number, -- payroll_action_id.
5325 assactid in number, -- assignment_action_id to be reversed.
5326 redo in boolean default false, -- ins assact and interlock if false
5327 rev_aaid in number default 0, -- reversal aa id of parent assactid
5328 multi in boolean default false
5329 ) is
5330 --
5331 -- Cursors used for latest balance maintenance
5332 --
5333 cursor rev_rrs (revassactid number, p_si_needed varchar2, p_st_needed varchar2,
5334 p_sn_needed varchar2, p_st2_needed varchar2,
5335 p_sn2_needed varchar2, p_org_needed varchar2) is
5336 select prr.run_result_id,
5337 paa.tax_unit_id,
5338 prr.local_unit_id,
5339 prr.jurisdiction_code,
5340 prr.source_id original_entry_id,
5341 ppa.payroll_id,
5342 decode(p_si_needed,
5343 'Y', pay_balance_pkg.find_context('SOURCE_ID', prr.run_result_id),
5344 null) source_id,
5345 decode(p_st_needed,
5346 'Y', pay_balance_pkg.find_context('SOURCE_TEXT', prr.run_result_id),
5347 null) source_text,
5348 decode(p_sn_needed,
5349 'Y', pay_balance_pkg.find_context('SOURCE_NUMBER', prr.run_result_id),
5350 null) source_number,
5351 decode(p_st2_needed,
5352 'Y', pay_balance_pkg.find_context('SOURCE_TEXT2', prr.run_result_id),
5353 null) source_text2,
5354 decode(p_sn2_needed,
5355 'Y', pay_balance_pkg.find_context('SOURCE_NUMBER2', prr.run_result_id),
5356 null) source_number2,
5357 decode(p_org_needed,
5358 'Y', pay_balance_pkg.find_context('ORGANIZATION_ID', prr.run_result_id),
5359 null) organization_id,
5360 ppa.effective_date
5361 from pay_assignment_actions paa,
5362 pay_run_results prr,
5363 pay_payroll_actions ppa
5364 where paa.assignment_action_id = revassactid
5365 and ppa.payroll_action_id = paa.payroll_action_id
5366 and paa.assignment_action_id = prr.assignment_action_id;
5367 --
5368 -- cursor and variables used in reversal of pay_run_balances
5369 --
5370 rev_asgact_id pay_assignment_actions.assignment_action_id%type;
5371 rev_act_seq pay_assignment_actions.action_sequence%type;
5372 rev_eff_date pay_payroll_actions.effective_date%type;
5373 --
5374 asgid number; -- assignment_id.
5375 taxunt number; -- tax unit id if legislation is US
5376 run_type_id number;
5377 udca context_details;
5378 cxt_id number;
5379
5380 found number;
5381 rev_assact number; -- reversal assignment_action_id.
5382 leg_code per_business_groups_perf.legislation_code%type;
5383 l_process_path pay_assignment_actions.process_path%type;
5384 l_found boolean;
5385 l_inp_val_name pay_input_values_f.name%type;
5386 l_rev_lat_bal_maintenance boolean;
5387 l_rule_mode pay_legislation_rules.rule_mode%type;
5388 l_si_needed pay_legislation_rules.rule_mode%type;
5389 l_st_needed pay_legislation_rules.rule_mode%type;
5390 l_sn_needed pay_legislation_rules.rule_mode%type;
5391 l_sn2_needed pay_legislation_rules.rule_mode%type;
5392 l_org_needed pay_legislation_rules.rule_mode%type;
5393 l_st2_needed pay_legislation_rules.rule_mode%type;
5394 l_value pay_action_parameters.parameter_value%type;
5395 l_tax_group hr_organization_information.org_information5%type;
5396 begin
5397 g_debug := hr_utility.debug_enabled;
5398 --
5399 -- To process the reversal, we need to
5400 -- obtain information about the assignment.
5401 -- Note : in addition, the following select
5402 -- will only return a row if the reversal
5403 -- effective date is equal to or later than
5404 -- the effective date of the assignment action
5405 -- being reversed, and that action is a legal
5406 -- action to be reversed.
5407 -- We also get the tax unit id (US only) which is
5408 -- required for the reversal assigment action.
5409 -- not part of assignment set reversal so perform normal logic
5410 begin
5411 if g_debug then
5412 hr_utility.trace('pactid: '||to_char(pactid));
5413 hr_utility.trace('assactid: '||to_char(assactid));
5414 hr_utility.set_location('hrassact.reversal',10);
5415 end if;
5416 select ac2.assignment_id,
5417 ac2.tax_unit_id,
5418 ac2.run_type_id,
5419 pbg.legislation_code
5420 into asgid, taxunt,run_type_id, leg_code
5421 from pay_action_classifications acl,
5422 pay_assignment_actions ac2,
5423 pay_payroll_actions pa2,
5424 per_business_groups_perf pbg,
5425 pay_payroll_actions pac
5426 where pac.payroll_action_id = pactid
5427 and pbg.business_group_id = pac.business_group_id
5428 and ac2.assignment_action_id = assactid
5429 and pa2.payroll_action_id = ac2.payroll_action_id
5430 and acl.classification_name = 'REVERSED'
5431 and acl.action_type = pa2.action_type
5432 and pa2.effective_date <= pac.effective_date;
5433 exception
5434 when no_data_found then
5435 hr_utility.set_message(801,'HR_7011_ACTION_ILLEGAL_REV');
5436 hr_utility.raise_error;
5437 end;
5438 --
5439 if not multi then
5440 -- If redo is true, we do not not need to insert
5441 -- either an assignment action or an interlock.
5442 -- the BackPay process needs this.
5443 if(not redo) then
5444 --
5445 -- start by inserting an assignment action row.
5446 hrassact.inassact_main(pactid,asgid,null,null,null,null,TRUE,taxunt,FALSE,run_type_id);
5447 --
5448 hr_utility.set_location('hrassact.reversal',10);
5449 -- Return the Reversal's assignment_action_id
5450 select act.assignment_action_id
5451 into rev_assact
5452 from pay_assignment_actions act
5453 where act.payroll_action_id = pactid
5454 and act.assignment_id = asgid;
5455 --
5456 select pay_core_utils.get_process_path(assactid)
5457 into l_process_path
5458 from dual;
5459 -- need to set process path for reversals
5460 update pay_assignment_actions
5461 set process_path =l_process_path
5462 where assignment_action_id=rev_assact;
5463
5464 -- insert an interlock row.
5465 -- Take this opportunity to do a specific check that we
5466 -- have not already reversed the assignment action.
5467 -- Do this by checking a reversal does not already lock
5468 -- this row.
5469 if g_debug then
5470 hr_utility.set_location('hrassact.reversal',20);
5471 end if;
5472 insert into pay_action_interlocks (
5473 locking_action_id,
5474 locked_action_id)
5475 select rev_assact,
5476 assactid
5477 from dual
5478 where not exists (
5479 select null
5480 from pay_assignment_actions ac2,
5481 pay_payroll_actions pa2,
5482 pay_action_interlocks pai
5483 where pai.locked_action_id = assactid
5484 and ac2.assignment_action_id = pai.locking_action_id
5485 and pa2.payroll_action_id = ac2.payroll_action_id
5486 and pa2.action_type = 'V');
5487 --
5488 if(sql%rowcount = 0) then
5489 hr_utility.set_message(801,'HR_7013_ACTION_IS_REVERSED');
5490 hr_utility.raise_error;
5491 end if;
5492 hr_utility.set_location('hrassact.reversal',10);
5493 --
5494 -- insert lock to master action if this is a sub action
5495
5496 insert into pay_action_interlocks (
5497 locking_action_id,
5498 locked_action_id)
5499 select rev_assact, paa1.assignment_action_id
5500 from pay_assignment_actions paa,pay_assignment_actions paa1
5501 where paa.assignment_action_id=assactid
5502 and paa1.payroll_action_id=paa.payroll_action_id
5503 and paa1.source_action_id is null
5504 and paa1.assignment_id=paa.assignment_id
5505 and paa1.assignment_action_id<>paa.assignment_action_id;
5506
5507
5508 else
5509 -- Return the Reversal's assignment_action_id
5510 select act.assignment_action_id
5511 into rev_assact
5512 from pay_assignment_actions act
5513 where act.payroll_action_id = pactid
5514 and act.assignment_id = asgid;
5515
5516 --create new interlock if needed
5517 insert into pay_action_interlocks
5518 (locking_action_id,locked_action_id)
5519 select rev_assact,assactid
5520 from dual where not exists (select 1
5521 from pay_action_interlocks
5522 where locking_action_id=rev_assact
5523 and locked_action_id=assactid);
5524
5525
5526 end if;
5527 else -- multi flag
5528 rev_assact := rev_aaid;
5529 end if;
5530 --
5531 --
5532 -- Now we need to process the reversal itself.
5533 -- We insert 'copies' of the run results and values
5534 -- from the run to be reversed, except we negate the
5535 -- values of result values that have numeric unit of
5536 -- measure. Note that there is no intelligence involved
5537 -- here, the routine does not know anything about
5538 -- what the values are being used for.
5539 -- Approach : select all the relevant run result
5540 -- rows and then insert the run result values
5541 -- for each one at a time.
5542 --
5543 -- Note the order by run run_result_id was introduced to
5544 -- ensure that the reversals results are in the same order
5545 -- as the reversed runs results.
5546 -- This slight change in behaviour will result in optimising
5547 -- the results of a retrocosting of a reversal.
5548 --
5549 -- Note - when the run result that is being reversed is
5550 -- an indirect we change the source_type of the new
5551 -- result to 'V' (#374389)
5552 declare
5553 cursor run_results(pactid number,assactid number) is
5554 select prr.run_result_id, -- original run_result_id.
5555 prr.element_type_id,
5556 prr.entry_type,
5557 prr.source_id,
5558 decode(prr.source_type, 'I', 'V', 'R'), -- source_type
5559 prr.status, ---'P' -- status
5560 prr.jurisdiction_code,
5561 prr.start_date,
5562 prr.end_date,
5563 prr.time_definition_id,
5564 prr.entry_process_path
5565 from pay_run_results prr
5566 where prr.assignment_action_id = assactid
5567 order by prr.run_result_id;
5568 --
5569 -- hold a run result record row.
5570 oldrrid pay_run_results.run_result_id%type;
5571 etypid pay_run_results.element_type_id%type;
5572 enttype pay_run_results.entry_type%type;
5573 srcid pay_run_results.source_id%type;
5574 stype pay_run_results.source_type%type;
5575 stat pay_run_results.status%type;
5576 v_jcode pay_run_results.jurisdiction_code%type;
5577 start_date pay_run_results.start_date%type;
5578 end_date pay_run_results.end_date%type;
5579 time_def_id pay_run_results.time_definition_id%type;
5580 entrypath pay_run_results.entry_process_path%type;
5581 --
5582 -- format mask for result value
5583 mask_36_dec_places varchar2(100);
5584 l_src_iv varchar2(30);
5585 l_src_num varchar2(30);
5586 l_src_num2 varchar2(30);
5587 l_org_id_iv varchar2(30);
5588 l_iv_found boolean;
5589 l_num_found boolean;
5590 begin
5591
5592 -- intialise mask for a number with 35 decimal places
5593 -- fnd_number.number_to_canonical uses a mask with only 20 decimal places
5594 -- bug 2362454
5595 -- increased to 38 decimal places and redelieverd under bug 2587443
5596 -- Bug 13359813 - Customer had result value with 22 numbers before decimal
5597 -- this is a valid result generated from payroll run. Needed to increase allowed
5598 -- number limit. Raised numbers to 23 and reduced decimal to 36. Initially it was
5599 -- set to 35 and then increased to 38 considering max decimals supported is 38.
5600 mask_36_dec_places := 'FM9999999999999999999999999.9999999999999999999999999999999999';
5601 --12345678901234567890123 123456789012345678901234567890123456
5602
5603 --
5604 -- open the cursor.
5605 open run_results(pactid,assactid);
5606 --
5607 loop
5608 fetch run_results
5609 into oldrrid,etypid,enttype,srcid,stype,stat,v_jcode, start_date, end_date, time_def_id, entrypath;
5610 --
5611 exit when run_results%notfound;
5612 --
5613 -- we want to know if element type is
5614 -- date effective for Reversal Date.
5615 declare
5616 dummy number; -- need this for syntax.
5617 begin
5618 if g_debug then
5619 hr_utility.set_location('hrassact.reversal',25);
5620 end if;
5621 select 1
5622 into dummy
5623 from pay_payroll_actions pac,
5624 pay_element_types_f pet
5625 where pac.payroll_action_id = pactid
5626 and pet.element_type_id = etypid
5627 and pac.effective_date between
5628 pet.effective_start_date and pet.effective_end_date;
5629 exception
5630 when no_data_found then
5631 hr_utility.set_message(801,'HR_7012_ACTION_ELE_NOT_EFF');
5632 hr_utility.raise_error;
5633 end;
5634 --
5635 if g_debug then
5636 hr_utility.set_location('hrassact.reversal',30);
5637 end if;
5638
5639 insert into pay_run_results (
5640 run_result_id,
5641 element_type_id,
5642 assignment_action_id,
5643 entry_type,
5644 source_id,
5645 source_type,
5646 status,
5647 jurisdiction_code,
5648 start_date,
5649 end_date,
5650 time_definition_id,
5651 entry_process_path)
5652 values (pay_run_results_s.nextval,
5653 etypid,
5654 rev_assact, -- the reversal assignment action.
5655 enttype,
5656 oldrrid,
5657 stype,
5658 stat,
5659 v_jcode,
5660 start_date,
5661 end_date,
5662 time_def_id,
5663 entrypath);
5664 --
5665 -- now we need to insert the result values
5666 -- for the result just inserted.
5667 -- NOTE - the first line in the decode is a
5668 -- dummy statement that prevents invalid
5669 -- number errors, caused by attempted
5670 -- implicit conversions from characters to
5671 -- numbers.
5672 --
5673 -- Bug 2822429 - Input values that represent the context SOURCE_ID
5674 -- or SOURCE_NUMBER must not have their run_result_value negated,
5675 -- as they are ids, not number values. Hence, where uom is I or N
5676 -- an extra decode is performed. If the piv.name is the SOURCE_ID
5677 -- or SOURCE_NUMBER input value, then multiply by 1, otherwise by
5678 -- -1 as before.
5679 -- Need to get input_value name for SOURCE_ID and SOURCE_NUMBER
5680 --
5681 hr_utility.trace('leg_code: '||leg_code);
5682 pay_core_utils.get_leg_context_iv_name('SOURCE_ID'
5683 ,leg_code
5684 ,l_src_iv
5685 ,l_iv_found);
5686 if (not l_iv_found) then
5687 l_src_iv := null;
5688 else
5689 l_si_needed := 'Y';
5690 hr_utility.trace('l_src_iv: '||l_src_iv);
5691 end if;
5692 --
5693 pay_core_utils.get_leg_context_iv_name('SOURCE_NUMBER'
5694 ,leg_code
5695 ,l_src_num
5696 ,l_num_found);
5697 if (not l_num_found) then
5698 l_src_num := null;
5699 else
5700 l_sn_needed := 'Y';
5701 hr_utility.trace('l_src_num: '||l_src_num);
5702 end if;
5703 --
5704 pay_core_utils.get_leg_context_iv_name('SOURCE_NUMBER2'
5705 ,leg_code
5706 ,l_src_num2
5707 ,l_num_found);
5708 if (not l_num_found) then
5709 l_src_num2 := null;
5710 else
5711 l_sn2_needed := 'Y';
5712 hr_utility.trace('l_src_num2: '||l_src_num2);
5713 end if;
5714 --
5715 pay_core_utils.get_leg_context_iv_name('ORGANIZATION_ID'
5716 ,leg_code
5717 ,l_org_id_iv
5718 ,l_num_found);
5719 if (not l_num_found) then
5720 l_org_id_iv := null;
5721 else
5722 l_org_needed := 'Y';
5723 hr_utility.trace('l_org_id_iv: '||l_org_id_iv);
5724 end if;
5725 --
5726 if g_debug then
5727 hr_utility.set_location('hrassact.reversal',35);
5728 end if;
5729 insert into pay_run_result_values (
5730 input_value_id,
5731 run_result_id,
5732 result_value)
5733 select piv.input_value_id,
5734 pay_run_results_s.currval,
5735 decode(piv.uom,
5736 'XXXXXXXXXX', '***********************',
5737 'H_DECIMAL1', rtrim(to_char((-1) * to_number(rrv.result_value, mask_36_dec_places), mask_36_dec_places), '.'),
5738 'H_DECIMAL2', rtrim(to_char((-1) * to_number(rrv.result_value, mask_36_dec_places), mask_36_dec_places), '.'),
5739 'H_DECIMAL3', rtrim(to_char((-1) * to_number(rrv.result_value, mask_36_dec_places), mask_36_dec_places), '.'),
5740 'H_HH' , rtrim(to_char((-1) * to_number(rrv.result_value, mask_36_dec_places), mask_36_dec_places), '.'),
5741 'H_HHMM' , rtrim(to_char((-1) * to_number(rrv.result_value, mask_36_dec_places), mask_36_dec_places), '.'),
5742 'H_HHMMSS' , rtrim(to_char((-1) * to_number(rrv.result_value, mask_36_dec_places), mask_36_dec_places), '.'),
5743 'I' , rtrim(to_char(decode(piv.name, l_src_iv , (1)
5744 , l_src_num, (1)
5745 , l_src_num2, (1)
5746 , l_org_id_iv, (1)
5747 , (-1))
5748 * to_number(rrv.result_value, mask_36_dec_places)
5749 , mask_36_dec_places), '.'),
5750 'M' , rtrim(to_char((-1) * to_number(rrv.result_value, mask_36_dec_places), mask_36_dec_places), '.'),
5751 'N' , rtrim(to_char(decode(piv.name, l_src_iv , (1)
5752 , l_src_num, (1)
5753 , l_src_num2, (1)
5754 , l_org_id_iv, (1)
5755 , (-1))
5756 * to_number(rrv.result_value, mask_36_dec_places)
5757 , mask_36_dec_places), '.'),
5758 'ND' , rtrim(to_char((-1) * to_number(rrv.result_value, mask_36_dec_places), mask_36_dec_places), '.'),
5759 rrv.result_value)
5760 from pay_payroll_actions pac,
5761 pay_run_result_values rrv,
5762 pay_input_values_f piv
5763 where pac.payroll_action_id = pactid
5764 and rrv.run_result_id = oldrrid
5765 and piv.input_value_id = rrv.input_value_id
5766 and pac.effective_date between
5767 piv.effective_start_date and piv.effective_end_date;
5768 end loop;
5769 --
5770 close run_results;
5771 --
5772 -- Now setup the action contexts, if there are any
5773 -- if not multi then
5774 insert into pay_action_contexts
5775 (ASSIGNMENT_ACTION_ID,
5776 ASSIGNMENT_ID,
5777 CONTEXT_ID,
5778 CONTEXT_VALUE)
5779 select distinct rev_assact,
5780 pac.assignment_id,
5781 pac.context_id,
5782 pac.context_value
5783 from pay_action_contexts pac
5784 where pac.assignment_action_id = assactid;
5785 -- end if;
5786 --
5787 -- Added for fix 366215.
5788 -- Now we have inserted the negative run results for
5789 -- the Reversal itself, we call a procedure to create
5790 -- "pre-inserted" run results and values to allow the
5791 -- correct re-processing of element entries in a
5792 -- subsequent run.
5793 --hrassact.rev_pre_inserted_rr(pactid);
5794 --
5795 -- To signal that processing has been successfully
5796 -- completed, update the action_status to (C)omplete.
5797 hr_utility.set_location('hrassact.reversal',40);
5798 update pay_payroll_actions pac
5799 set pac.action_status = 'C'
5800 where pac.payroll_action_id = pactid;
5801 end;
5802 --
5803 --
5804 -- Now do the reversal for pay_run_balances. 1st the asg level balances
5805 --
5806 if g_debug then
5807 hr_utility.set_location('hrassact.reversal',45);
5808 end if;
5809 --
5810 /* currently for multi reversal we are using pactid as the reversal
5811 pactid. If multi then the ass_act_id is the rev_act_id we want to
5812 use and is already set */
5813 if not multi then
5814
5815 select paa.assignment_action_id
5816 , paa.action_sequence
5817 , ppa.effective_date
5818 into rev_asgact_id
5819 , rev_act_seq
5820 , rev_eff_date
5821 from pay_assignment_actions paa
5822 , pay_payroll_actions ppa
5823 where paa.payroll_action_id = pactid
5824 and paa.payroll_action_id = ppa.payroll_action_id;
5825
5826 else
5827
5828 select paa.assignment_action_id
5829 , paa.action_sequence
5830 , ppa.effective_date
5831 into rev_asgact_id
5832 , rev_act_seq
5833 , rev_eff_date
5834 from pay_assignment_actions paa,
5835 pay_payroll_actions ppa
5836 where paa.assignment_action_id = assactid
5837 and ppa.payroll_action_id = paa.payroll_action_id;
5838
5839 end if;
5840 --
5841 pay_balance_pkg.maintain_balances_for_action(rev_assact);
5842 --
5843 if g_debug then
5844 hr_utility.set_location('Leaving: hrassact.reversal', 100);
5845 end if;
5846 end reversal;
5847 --
5848 ----------------- multi_assignment_reversal ------------------------------
5849 /*
5850 NAME
5851 multi_assignment_reversal - Process a reversal by assignment set.
5852 DESCRIPTION
5853 Process a reversal for an assignment action, version called via PYUGEN
5854 as opposed to that called via Reversal Form version.
5855 This version omits the assignment action creation that has been already
5856 prepared via the c code routines called as part of PYUGEN prior.
5857 NOTES
5858 - This is called directly from PYUGEN REVERSAL
5859
5860 BUG 7652030 - pay_balance_pkg.create_all_group_balances was getting called
5861 during reversal of all assignments causing errors
5862 Now calling create_all_group_balances after the last reversal .
5863 */
5864 procedure multi_assignment_reversal
5865 (
5866 pactid in number, -- payroll_action_id.
5867 assactid in number, -- assignment_action_id to be reversed.
5868 rev_aaid in number -- locking action
5869 ) is
5870 begin
5871
5872 hrassact.gv_multi_reversal := TRUE;
5873
5874 If hrassact.gv_cnt_reversal_act_id is null then
5875
5876 SELECT count(*)
5877 INTO hrassact.gv_cnt_reversal_act_id
5878 FROM pay_action_interlocks pai,
5879 pay_assignment_actions paa
5880 WHERE paa.payroll_action_id = pactid
5881 AND paa.assignment_action_id = pai.locking_action_id;
5882 end if;
5883
5884 reversal(pactid, -- call reversal with PYUGEN payroll_action_id
5885 assactid, -- call reversal with PYUGEN assignment action id
5886 false, -- redo flag set to false for reversal thru PYUGEN
5887 rev_aaid, -- locking action id
5888 true -- multi flag to indicate assignment set reversal
5889 );
5890
5891 hrassact.gv_cnt_reversal_act_id := hrassact.gv_cnt_reversal_act_id - 1 ;
5892
5893 If hrassact.gv_cnt_reversal_act_id = 0 then
5894 pay_balance_pkg.create_all_group_balances(pactid,
5895 'ALL',
5896 'NORMAL',
5897 NULL,
5898 NULL);
5899 End if;
5900
5901 end multi_assignment_reversal;
5902 --
5903 ----------------------- rev_pre_inserted_rr --------------------------
5904 /* COMMENETED OUT AS THIS PROC IS NO LONGER USED
5905 NAME
5906 rev_pre_inserted_rr - Reversal create pre-inserted run results.
5907 DESCRIPTION
5908 Creates pre-inserted run results when a Reversal is processed
5909 These are created for any non-recurring or additional entry
5910 type for the assignment, where there is not already an
5911 unprocessed entry.
5912 NOTES
5913 <none>
5914 */
5915 /* procedure rev_pre_inserted_rr
5916 (
5917 p_payroll_action_id in number -- payroll_action_id of reversal.
5918 ) is
5919 cursor c1 is
5920 select + ORDERED
5921 INDEX(PEE PAY_ELEMENT_ENTRIES_F_PK,
5922 PEL PAY_ELEMENT_LINKS_F_PK,
5923 PET PAY_ELEMENT_TYPES_F_PK,
5924 ACT2 PAY_ASSIGNMENT_ACTIONS_PK)
5925 USE_NL(PAC ACT PAI ACT2 RR2 PEE)
5926 pet.element_type_id,
5927 act.assignment_action_id,
5928 pee.entry_type,
5929 pee.element_entry_id
5930 from pay_payroll_actions pac,
5931 pay_assignment_actions act,
5932 pay_action_interlocks pai,
5933 pay_assignment_actions act2,
5934 pay_run_results rr2,
5935 pay_element_entries_f pee,
5936 pay_element_links_f pel,
5937 pay_element_types_f pet
5938 where pac.payroll_action_id = p_payroll_action_id
5939 and act.payroll_action_id = pac.payroll_action_id
5940 and pee.assignment_id = act.assignment_id
5941 and pai.locking_action_id = act.assignment_action_id
5942 and pai.locked_action_id = act2.assignment_action_id
5943 and pac.date_earned between
5944 pee.effective_start_date and pee.effective_end_date
5945 and pel.element_link_id = pee.element_link_id
5946 and pac.date_earned between
5947 pel.effective_start_date and pel.effective_end_date
5948 and pet.element_type_id = pel.element_type_id
5949 and pac.date_earned between
5950 pet.effective_start_date and pet.effective_end_date
5951 and ((pet.processing_type = 'N' and pee.entry_type <> 'B')
5952 or pee.entry_type = 'D')
5953 and rr2.source_id = pee.element_entry_id
5954 and rr2.source_type <> 'I'-- exclude indirects
5955 and rr2.assignment_action_id = act2.assignment_action_id
5956 and rr2.status <> 'U'
5957 and not exists (
5958 select null
5959 from pay_run_results rr3
5960 where rr3.source_id = pee.element_entry_id
5961 and rr3.status = 'U')
5962 order by pee.element_entry_id;
5963 --
5964 c_indent constant varchar2(30) := 'hrassact.rev_pre_inserted_rr';
5965 begin
5966 g_debug := hr_utility.debug_enabled;
5967 -- Insert un-processed run results and values as appropriate
5968 if g_debug then
5969 hr_utility.set_location(c_indent, 10);
5970 end if;
5971 for c1rec in c1 loop
5972 -- Start with insertion of run result.
5973 insert into pay_run_results (
5974 run_result_id,
5975 element_type_id,
5976 assignment_action_id,
5977 entry_type,
5978 source_id,
5979 source_type,
5980 status,
5981 jurisdiction_code)
5982 values (pay_run_results_s.nextval,
5983 c1rec.element_type_id,
5984 c1rec.assignment_action_id,
5985 c1rec.entry_type,
5986 c1rec.element_entry_id,
5987 'E',
5988 'U',
5989 null);
5990 --
5991 -- Now, insert the appropriate run result values.
5992 -- All the values should be null, the Payroll Run
5993 -- will fill these in later.
5994 insert into pay_run_result_values (
5995 input_value_id,
5996 run_result_id,
5997 result_value)
5998 select pev.input_value_id,
5999 pay_run_results_s.currval,
6000 null
6001 from pay_payroll_actions pac,
6002 pay_assignment_actions act, -- reversal
6003 pay_element_entry_values_f pev
6004 where act.assignment_action_id = c1rec.assignment_action_id --rev
6005 and act.payroll_action_id = pac.payroll_action_id
6006 and pev.element_entry_id = c1rec.element_entry_id
6007 and pac.date_earned between
6008 pev.effective_start_date and pev.effective_end_date;
6009 end loop;
6010 end rev_pre_inserted_rr;
6011 */
6012 -------------------------- ext_man_payment --------------------------
6013 /*
6014 NAME
6015 ext_man_payment - Performs External/Manual Payments
6016 DESCRIPTION
6017 Process a External/Manual Payment.
6018 NOTES
6019 This is called directly from the Pre-Payment External/Manual
6020 Payment form.
6021 */
6022 procedure ext_man_payment
6023 (
6024 p_payroll_id in number,
6025 p_eff_date in date,
6026 p_assignment_action_id in number,
6027 p_assignment_id in number,
6028 p_comments in varchar2,
6029 p_serial_number in varchar2,
6030 p_pre_payment_id in number,
6031 p_reason in varchar2 default null
6032 ) is
6033 c_indent constant varchar2(30) := 'hrassact.ext_man_payment';
6034 l_payroll_action_id number;
6035 l_assignment_action_id number;
6036 l_business_group_id number;
6037 l_consolidation_set_id number;
6038 --
6039 cursor C_CON1 is
6040 select pay_payroll_actions_s.nextval,
6041 pay_assignment_actions_s.nextval,
6042 pa.CONSOLIDATION_SET_ID,
6043 pa.BUSINESS_GROUP_ID
6044 from PAY_ASSIGNMENT_ACTIONS paa,
6045 PAY_PAYROLL_ACTIONS pa
6046 where paa.ASSIGNMENT_ACTION_ID = p_assignment_action_id
6047 and paa.PAYROLL_ACTION_ID = pa.PAYROLL_ACTION_ID;
6048 --
6049 begin
6050 g_debug := hr_utility.debug_enabled;
6051 --
6052 -- Open the cursor and retrieve the payroll action details
6053 if g_debug then
6054 hr_utility.set_location(c_indent,5);
6055 end if;
6056 open C_CON1;
6057 fetch C_CON1 into l_payroll_action_id,
6058 l_assignment_action_id,
6059 l_consolidation_set_id,
6060 l_business_group_id;
6061 close C_CON1;
6062 --
6063 -- insert the payroll action row
6064 if g_debug then
6065 hr_utility.set_location(c_indent,10);
6066 end if;
6067 insert into PAY_PAYROLL_ACTIONS
6068 (PAYROLL_ACTION_ID,
6069 ACTION_TYPE,
6070 BUSINESS_GROUP_ID,
6071 CONSOLIDATION_SET_ID,
6072 PAYROLL_ID,
6073 ACTION_POPULATION_STATUS,
6074 ACTION_STATUS,
6075 EFFECTIVE_DATE,
6076 COMMENTS,
6077 OBJECT_VERSION_NUMBER,
6078 PAY_ADVICE_MESSAGE)
6079 values
6080 (l_payroll_action_id,
6081 'E',
6082 l_business_group_id,
6083 l_consolidation_set_id,
6084 p_payroll_id,
6085 'C',
6086 'C',
6087 p_eff_date,
6088 p_comments,
6089 1,
6090 p_reason);
6091 --
6092 -- call procedure to insert assignment action record
6093 if g_debug then
6094 hr_utility.set_location(c_indent,20);
6095 end if;
6096 inassact(pactid => l_payroll_action_id,
6097 asgid => p_assignment_id,
6098 p_ass_action_seq => l_assignment_action_id,
6099 p_pre_payment_id => p_pre_payment_id,
6100 p_serial_number => p_serial_number);
6101 --
6102 -- insert a pay action interlock record.
6103 if g_debug then
6104 hr_utility.set_location(c_indent,30);
6105 end if;
6106 insert into PAY_ACTION_INTERLOCKS
6107 (LOCKING_ACTION_ID,
6108 LOCKED_ACTION_ID)
6109 values
6110 (l_assignment_action_id,
6111 p_assignment_action_id);
6112 --
6113 -- Update the payroll action table with
6114 -- the appropriate date earned value.
6115 if g_debug then
6116 hr_utility.set_location(c_indent,40);
6117 end if;
6118 update pay_payroll_actions pac
6119 set pac.date_earned = (
6120 select pa2.date_earned
6121 from pay_payroll_actions pa2,
6122 pay_assignment_actions act
6123 where act.assignment_action_id = p_assignment_action_id
6124 and pa2.payroll_action_id = act.payroll_action_id
6125 )
6126 where pac.payroll_action_id = l_payroll_action_id;
6127 --
6128 end ext_man_payment;
6129 --
6130 -- Added for bug 6820127
6131 -------------------------- ext_man_payment --------------------------
6132 /*
6133 NAME
6134 ext_man_payment - Performs External/Manual Payments
6135 DESCRIPTION
6136 Process a External/Manual Payment.
6137 NOTES
6138 This procedure is called from the executable PYEXMNPT within the 'Cancel Check' flow.
6139 */
6140 procedure ext_man_payment
6141 (
6142 p_errmsg OUT NOCOPY VARCHAR2,
6143 p_errcode OUT NOCOPY NUMBER,
6144 p_payroll_id in number, -- payroll id of assign
6145 p_eff_date in varchar2, -- session date
6146 p_assignment_action_id in number, -- pre-payment assign action
6147 p_assignment_id in number, -- assign id
6148 p_comments in varchar2,-- comments
6149 p_serial_number in varchar2,-- serial number
6150 p_pre_payment_id in number, -- pre-payment id
6151 p_reason in varchar2 default null -- Reason
6152 )
6153 IS
6154 c_indent constant varchar2(30) := 'hrassact.ext_man_payment2';
6155
6156 BEGIN
6157
6158 g_debug := hr_utility.debug_enabled;
6159
6160 if g_debug then
6161 hr_utility.set_location('Entering '||c_indent,10);
6162 end if;
6163
6164 ext_man_payment(p_payroll_id,
6165 TRUNC(FND_DATE.canonical_to_date(P_EFF_DATE)),
6166 p_assignment_action_id,
6167 p_assignment_id,
6168 p_comments,
6169 p_serial_number,
6170 p_pre_payment_id,
6171 p_reason);
6172
6173 if g_debug then
6174 hr_utility.set_location('Leaving '||c_indent,20);
6175 end if;
6176
6177 END ext_man_payment;
6178 --------------------------- set_action_contexts------------------------
6179 /*
6180 NAME
6181 set_action_contexts - This sets up the action contexts for a
6182 given element entry.
6183 DESCRIPTION
6184 NOTES
6185 */
6186 procedure set_action_context (p_assact in number,
6187 p_rrid in number, -- run_result_id
6188 p_entry in number,
6189 p_tax_unit in number,
6190 p_asgid in number,
6191 p_busgrp in number,
6192 p_legcode in varchar2,
6193 p_oentry in number, -- original entry id
6194 udca out nocopy context_details
6195 )
6196 is
6197 --
6198 cursor get_rr_values (p_run_result_id number,
6199 p_effective_date date
6200 )
6201 is
6202 select piv.name,
6203 prrv.result_value,
6204 prrv.input_value_id,
6205 prrv.run_result_id
6206 from pay_run_results prr,
6207 pay_run_result_values prrv,
6208 pay_input_values_f piv
6209 where prr.run_result_id = p_run_result_id
6210 and prrv.run_result_id = prr.run_result_id
6211 and piv.input_value_id = prrv.input_value_id
6212 and p_effective_date between piv.effective_start_date
6213 and piv.effective_end_date;
6214 --
6215 cxt_id number;
6216 cnt number;
6217 pay_id number;
6218 source_iv pay_legislation_rules.rule_type%type;
6219 source_text_iv pay_legislation_rules.rule_type%type;
6220 jurisdiction_iv pay_legislation_rules.rule_type%type;
6221 action_contexts boolean;
6222 l_def_jur_str varchar2(2000); -- used with dynamic pl/sql
6223 l_ctx_balance_date date;
6224 l_ctx_time_def_id number;
6225 sql_cursor integer;
6226 l_rows integer;
6227 dummy number;
6228 l_found boolean;
6229 l_action_type varchar2(30);
6230 l_effective_date date;
6231 c_indent constant varchar2(32) := 'hrassact.set_action_context';
6232 --
6233 begin
6234 g_debug := hr_utility.debug_enabled;
6235 --
6236 if g_debug then
6237 hr_utility.set_location(c_indent,10);
6238 end if;
6239 udca.sz := 0;
6240 pay_core_utils.get_dynamic_contexts(p_busgrp,
6241 g_dynamic_contexts);
6242 --
6243 --
6244 -- Get Payroll ID and Action Type
6245 --
6246 select
6247 pac.payroll_id
6248 ,pac.action_type
6249 ,pac.effective_date
6250 into
6251 pay_id
6252 ,l_action_type
6253 ,l_effective_date
6254 from
6255 pay_payroll_actions pac
6256 ,pay_assignment_actions aa
6257 where
6258 aa.assignment_action_id = p_assact
6259 and pac.payroll_action_id = aa.payroll_action_id;
6260
6261 --
6262 -- Do we need to perform the ACTION_CONTEXT code
6263 --
6264 begin
6265 --
6266 if g_debug then
6267 hr_utility.set_location(c_indent,20);
6268 end if;
6269 select 1
6270 into dummy
6271 from pay_legislation_rules plr
6272 where p_legcode = plr.legislation_code
6273 and plr.rule_type = 'ACTION_CONTEXTS'
6274 and plr.rule_mode = 'Y';
6275 --
6276 if g_debug then
6277 hr_utility.set_location(c_indent,30);
6278 end if;
6279 action_contexts := TRUE;
6280 --
6281 exception
6282 when no_data_found then
6283 hr_utility.set_location(c_indent,40);
6284 action_contexts := FALSE;
6285 end;
6286 --
6287 if g_debug then
6288 hr_utility.set_location(c_indent,50);
6289 end if;
6290 --
6291 -- OK get the contexts cached
6292 --
6293 if not contexts_cached then
6294 cache_contexts;
6295 end if;
6296 --
6297 -- Start setting up the contexts.
6298 --
6299 if (p_tax_unit is not null) then
6300 get_cache_context('TAX_UNIT_ID', cxt_id);
6301 udca.sz := udca.sz + 1;
6302 udca.assact_id(udca.sz) := p_assact;
6303 udca.asg_id(udca.sz) := p_asgid;
6304 udca.cxt_id(udca.sz) := cxt_id;
6305 udca.cxt_name(udca.sz) := 'TAX_UNIT_ID';
6306 udca.cxt_value(udca.sz) := p_tax_unit;
6307 udca.valid(udca.sz) := TRUE;
6308 end if;
6309 --
6310 -- Setting up the Balance Date and Time Definition ID contexts.
6311 --
6312 if p_rrid is not null then
6313 select end_date,
6314 time_definition_id
6315 into l_ctx_balance_date,
6316 l_ctx_time_def_id
6317 from pay_run_results
6318 where run_result_id = p_rrid;
6319 --
6320 if l_ctx_balance_date is not null then
6321 get_cache_context('BALANCE_DATE', cxt_id);
6322 udca.sz := udca.sz + 1;
6323 udca.assact_id(udca.sz) := p_assact;
6324 udca.asg_id(udca.sz) := p_asgid;
6325 udca.cxt_id(udca.sz) := cxt_id;
6326 udca.cxt_name(udca.sz) := 'BALANCE_DATE';
6327 udca.cxt_value(udca.sz) := fnd_date.date_to_canonical(l_ctx_balance_date);
6328 udca.valid(udca.sz) := TRUE;
6329 end if;
6330 --
6331 if l_ctx_time_def_id is not null then
6332 get_cache_context('TIME_DEFINITION_ID', cxt_id);
6333 udca.sz := udca.sz + 1;
6334 udca.assact_id(udca.sz) := p_assact;
6335 udca.asg_id(udca.sz) := p_asgid;
6336 udca.cxt_id(udca.sz) := cxt_id;
6337 udca.cxt_name(udca.sz) := 'TIME_DEFINITION_ID';
6338 udca.cxt_value(udca.sz) := l_ctx_time_def_id;
6339 udca.valid(udca.sz) := TRUE;
6340 end if;
6341 --
6342 end if;
6343 --
6344 for rrvrec in get_rr_values (p_rrid, l_effective_date) loop
6345 for l_cnt in 1..g_dynamic_contexts.count loop
6346 --
6347 hr_utility.set_location(c_indent,90);
6348 --
6349 --Run Result Contexts
6350 if (rrvrec.name = g_dynamic_contexts(l_cnt).input_value_name) then
6351 --
6352 hr_utility.set_location(c_indent,95);
6353 declare
6354 l_ctx_value pay_run_result_values.result_value%type;
6355 begin
6356 l_ctx_value := null;
6357 --
6358 if (rrvrec.result_value is not null) then
6359 --
6360 l_ctx_value := rrvrec.result_value;
6361
6362 elsif l_action_type <> 'I' then
6363 --
6364 --
6365 -- setup defaults of contexts if not Balance Initialization
6366 --
6367 if g_dynamic_contexts(l_cnt).is_context_def = TRUE then
6368
6369 l_def_jur_str := 'begin ' || g_dynamic_contexts(l_cnt).default_plsql || ' (';
6370 l_def_jur_str := l_def_jur_str || ':p_assact, ';
6371 l_def_jur_str := l_def_jur_str || ':p_entry, ';
6372 l_def_jur_str := l_def_jur_str || ':l_ctx_value); end; ';
6373 --
6374 sql_cursor := dbms_sql.open_cursor;
6375 --
6376 dbms_sql.parse(sql_cursor, l_def_jur_str, dbms_sql.v7);
6377 --
6378 --
6379 dbms_sql.bind_variable(sql_cursor, 'p_assact', p_assact);
6380 --
6381 dbms_sql.bind_variable(sql_cursor, 'p_entry', p_entry);
6382 --
6383 dbms_sql.bind_variable(sql_cursor, 'l_ctx_value', l_ctx_value, 30);
6384 --
6385 l_rows := dbms_sql.execute (sql_cursor);
6386 --
6387 if (l_rows = 1) then
6388 dbms_sql.variable_value(sql_cursor, 'l_ctx_value',
6389 l_ctx_value);
6390 dbms_sql.close_cursor(sql_cursor);
6391 --
6392 -- OK we got the default, we need to set it
6393 update pay_run_result_values
6394 set result_value = l_ctx_value
6395 where run_result_id = rrvrec.run_result_id
6396 and input_value_id = rrvrec.input_value_id;
6397 --
6398 else
6399 l_ctx_value := null;
6400 dbms_sql.close_cursor(sql_cursor);
6401 end if;
6402 end if;
6403 --
6404 end if;
6405
6406 hr_utility.set_location(c_indent,96);
6407 --
6408 if l_ctx_value is not null then
6409 --
6410 -- Set the jurisdiction on the run_result.
6411 if (g_dynamic_contexts(l_cnt).context_name = 'JURISDICTION_CODE') then
6412 update pay_run_results
6413 set jurisdiction_code = l_ctx_value
6414 where run_result_id = p_rrid;
6415 --
6416 elsif (g_dynamic_contexts(l_cnt).context_name = 'ORGANIZATION_ID') then
6417 --
6418 -- Need to ensure that its a Third Party Organization
6419 --
6420 declare
6421 l_org_id number;
6422 begin
6423 select organization_id
6424 into l_org_id
6425 from hr_organization_information hoi
6426 where hoi.organization_id = l_ctx_value
6427 and hoi.org_information_context = 'CLASS'
6428 and hoi.org_information1 = 'HR_PAYEE';
6429
6430 exception
6431 when no_data_found then
6432 pay_core_utils.assert_condition('set_action_context:1',
6433 1 = 2);
6434 end;
6435 end if;
6436 --
6437 if g_debug then
6438 hr_utility.set_location(c_indent,100);
6439 end if;
6440 get_cache_context(g_dynamic_contexts(l_cnt).context_name, cxt_id);
6441 udca.sz := udca.sz + 1;
6442 udca.assact_id(udca.sz) := p_assact;
6443 udca.asg_id(udca.sz) := p_asgid;
6444 udca.cxt_name(udca.sz) := g_dynamic_contexts(l_cnt).context_name;
6445 udca.cxt_id(udca.sz) := cxt_id;
6446 udca.cxt_value(udca.sz) := l_ctx_value;
6447 udca.valid(udca.sz) := TRUE;
6448 end if;
6449 end;
6450 if g_debug then
6451 hr_utility.set_location(c_indent,105);
6452 end if;
6453 --
6454 end if;
6455 if g_debug then
6456 hr_utility.set_location(c_indent,106);
6457 end if;
6458 end loop;
6459 end loop;
6460
6461 --
6462 -- Payroll ID
6463 --
6464 if g_debug then
6465 hr_utility.set_location(c_indent,130);
6466 end if;
6467 get_cache_context('PAYROLL_ID', cxt_id);
6468 udca.sz := udca.sz + 1;
6469 udca.assact_id(udca.sz) := p_assact;
6470 udca.asg_id(udca.sz) := p_asgid;
6471 udca.cxt_name(udca.sz) := 'PAYROLL_ID';
6472 udca.cxt_id(udca.sz) := cxt_id;
6473 udca.cxt_value(udca.sz) := pay_id;
6474 udca.valid(udca.sz) := TRUE;
6475
6476 --
6477 -- Original Entry ID
6478 --
6479 if p_oentry is not null then
6480 if g_debug then
6481 hr_utility.set_location(c_indent,135);
6482 end if;
6483
6484 get_cache_context('ORIGINAL_ENTRY_ID', cxt_id);
6485 udca.sz := udca.sz + 1;
6486 udca.assact_id(udca.sz) := p_assact;
6487 udca.asg_id(udca.sz) := p_asgid;
6488 udca.cxt_name(udca.sz) := 'ORIGINAL_ENTRY_ID';
6489 udca.cxt_id(udca.sz) := cxt_id;
6490 udca.cxt_value(udca.sz) := p_oentry;
6491 udca.valid(udca.sz) := TRUE;
6492
6493 end if;
6494 --
6495 -- Local Unit ID
6496 --
6497 declare
6498 l_local_unit_id number;
6499 begin
6500 select local_unit_id
6501 into l_local_unit_id
6502 from pay_run_results
6503 where run_result_id = p_rrid;
6504 --
6505 if l_local_unit_id is not null then
6506 if g_debug then
6507 hr_utility.set_location(c_indent,136);
6508 end if;
6509
6510 get_cache_context('LOCAL_UNIT_ID', cxt_id);
6511 udca.sz := udca.sz + 1;
6512 udca.assact_id(udca.sz) := p_assact;
6513 udca.asg_id(udca.sz) := p_asgid;
6514 udca.cxt_name(udca.sz) := 'LOCAL_UNIT_ID';
6515 udca.cxt_id(udca.sz) := cxt_id;
6516 udca.cxt_value(udca.sz) := l_local_unit_id;
6517 udca.valid(udca.sz) := TRUE;
6518
6519 end if;
6520 end;
6521 --
6522 if (p_legcode = 'US' or p_legcode = 'CA') then
6523 --
6524 if g_debug then
6525 hr_utility.set_location(c_indent,140);
6526 end if;
6527 declare
6528 tax_group hr_organization_information.org_information5%type;
6529 asg_id number;
6530 pay_id number;
6531 begin
6532 --
6533 if (p_legcode = 'US') then
6534 if g_debug then
6535 hr_utility.set_location(c_indent,150);
6536 end if;
6537 select hoi.org_information5,
6538 paa.assignment_id
6539 into tax_group,
6540 asg_id
6541 from hr_organization_information hoi,
6542 pay_assignment_actions paa
6543 where UPPER(hoi.org_information_context) = 'FEDERAL TAX RULES'
6544 and hoi.organization_id = paa.tax_unit_id
6545 and paa.assignment_action_id = p_assact
6546 and hoi.org_information5 is not null;
6547 else
6548 if g_debug then
6549 hr_utility.set_location(c_indent,153);
6550 end if;
6551 select hoi.org_information4,
6552 paa.assignment_id
6553 into tax_group,
6554 asg_id
6555 from hr_organization_information hoi,
6556 pay_assignment_actions paa
6557 where UPPER(hoi.org_information_context) = 'CANADA EMPLOYER IDENTIFICATION'
6558 and hoi.organization_id = paa.tax_unit_id
6559 and paa.assignment_action_id = p_assact
6560 and hoi.org_information4 is not null;
6561 end if;
6562 --
6563 if g_debug then
6564 hr_utility.set_location(c_indent,155);
6565 end if;
6566 get_cache_context('TAX_GROUP', cxt_id);
6567 udca.sz := udca.sz + 1;
6568 udca.assact_id(udca.sz) := p_assact;
6569 udca.asg_id(udca.sz) := asg_id;
6570 udca.cxt_name(udca.sz) := 'TAX_GROUP';
6571 udca.cxt_id(udca.sz) := cxt_id;
6572 udca.cxt_value(udca.sz) := tax_group;
6573 udca.valid(udca.sz) := TRUE;
6574 --
6575 exception
6576 when no_data_found then
6577 if g_debug then
6578 hr_utility.set_location(c_indent,160);
6579 end if;
6580 null;
6581 end;
6582 --
6583 end if;
6584 --
6585 if g_debug then
6586 hr_utility.set_location(c_indent,170);
6587 end if;
6588 -- Now do all the inserts.
6589 if action_contexts = TRUE then
6590 for cnt in 1..udca.sz loop
6591 --
6592 if (udca.cxt_name(cnt) in ('SOURCE_ID'
6593 ,'JURISDICTION_CODE'
6594 ,'SOURCE_TEXT'
6595 ,'SOURCE_NUMBER'
6596 ,'SOURCE_TEXT2'
6597 ,'BALANCE_DATE'
6598 ,'TIME_DEFINITION_ID'
6599 ,'TAX_GROUP'
6600 ,'ORIGINAL_ENTRY_ID')) then
6601 if g_debug then
6602 hr_utility.set_location(c_indent,180);
6603 end if;
6604 --
6605 -- The row could already be in the table due
6606 -- to batch balance adjustments
6607 --
6608 insert into pay_action_contexts
6609 (assignment_action_id,
6610 assignment_id,
6611 context_id,
6612 context_value)
6613 select udca.assact_id(cnt),
6614 udca.asg_id(cnt),
6615 udca.cxt_id(cnt),
6616 udca.cxt_value(cnt)
6617 from sys.dual
6618 where not exists (select ''
6619 from pay_action_contexts
6620 where assignment_action_id = udca.assact_id(cnt)
6621 and assignment_id = udca.asg_id(cnt)
6622 and context_id = udca.cxt_id(cnt)
6623 and context_value = udca.cxt_value(cnt));
6624 end if;
6625 --
6626 end loop;
6627 end if;
6628 if g_debug then
6629 hr_utility.set_location(c_indent,190);
6630 end if;
6631 exception
6632 when others then
6633 hr_utility.trace(sqlerrm);
6634 raise;
6635 --
6636 end set_action_context;
6637 --
6638 --------------------------- bal_adjust_actions ----------------------
6639 /*
6640 NAME
6641 bal_adjust_actions - perform balance adjustment.
6642 DESCRIPTION
6643 Process a balance adjustment.
6644 NOTES
6645 */
6646 procedure bal_adjust_actions
6647 (
6648 consetid in number, -- consolidation_set_id.
6649 eentryid in number, -- element_entry_id.
6650 effdate in date, -- effective_date of bal adjust.
6651 pyactid out nocopy number, -- payroll action id.
6652 asactid out nocopy number, -- assignment action id.
6653 act_type in varchar2 default 'B',-- payroll_action_type.
6654 prepay_flag in varchar2 default null, -- include in prepay process?
6655 taxunit in number default null, -- tax unit id.
6656 purge_mode in boolean default false, -- are we calling in purge mode?
6657 run_type_id in number default null
6658 ) is
6659 c_indent constant varchar2(32) := 'hrassact.bal_adjust_actions';
6660 pactid number; -- payroll_action_id.
6661 busgrp number; -- business_group_id.
6662 legcode pay_legislation_rules.legislation_code%TYPE; -- leg code
6663 asgid number; -- assignment_id.
6664 payid number; -- payroll_id.
6665 tperiod number; -- time_period_id.
6666 dtearned date; -- date_earned.
6667 creatby number; -- created_by.
6668 creatdate date; -- creation_date.
6669 assactid number; -- assignment_action_id of inserted action.
6670 tax_unit number; -- tax_unit_id
6671 udca context_details;
6672 l_run_result_id number;
6673 l_jc_name varchar2(30);
6674 l_rr_sparse boolean;
6675 l_rr_sparse_jc boolean;
6676 l_found boolean;
6677 l_rule_mode varchar2(30);
6678 l_status varchar2(30);
6679 l_original_entry_id number;
6680 l_dummy varchar2(1);
6681 --
6682 cursor csr_time_period_leg (p_leg_code in varchar2) is
6683 select 'Y'
6684 from pay_legislation_rules
6685 where rule_type = 'TIME_PERIOD_ID'
6686 and legislation_code = p_leg_code
6687 and rule_mode = 'Y';
6688 --
6689 begin
6690 g_debug := hr_utility.debug_enabled;
6691 --
6692 --
6693 -- Select a number of values, including assignment
6694 -- and payroll action details.
6695 -- take this opportunity to check that the assignment
6696 -- and element type is date effective. In the case of
6697 -- the assignment, this should be confirming what has
6698 -- already been checked by the form.
6699 -- In addition, select a sequence value for
6700 -- pay_run_results.
6701 --
6702 -- Bug #3482270 - original entry id support.
6703 -- Original_entry_id will be also derived from the entry
6704 -- record here, which must have already been validated and
6705 -- attached to the record by the form or entry API before
6706 -- calling this process.
6707 --
6708 if g_debug then
6709 hr_utility.trace('effdate='||to_char(effdate, 'DD-MON-YYYY'));
6710 hr_utility.set_location(c_indent,5);
6711 end if;
6712 select /*+ ordered use_nl(pee asg ptp pbg)
6713 index(pee PAY_ELEMENT_ENTRIES_F_PK)
6714 index(asg PER_ASSIGNMENTS_F_PK)
6715 index(ptp PER_TIME_PERIODS_N50) */
6716 pay_payroll_actions_s.nextval,
6717 asg.business_group_id,
6718 pbg.legislation_code,
6719 asg.assignment_id,
6720 asg.payroll_id,
6721 ptp.time_period_id,
6722 pee.created_by,
6723 pee.creation_date,
6724 pee.original_entry_id
6725 into pactid,
6726 busgrp,
6727 legcode,
6728 asgid,
6729 payid,
6730 tperiod,
6731 creatby,
6732 creatdate,
6733 l_original_entry_id
6734 from pay_element_entries_f pee,
6735 per_all_assignments_f asg,
6736 per_time_periods ptp,
6737 per_business_groups_perf pbg
6738 where pee.element_entry_id = eentryid
6739 and effdate between
6740 pee.effective_start_date and pee.effective_end_date
6741 and asg.assignment_id = pee.assignment_id
6742 and effdate between
6743 asg.effective_start_date and asg.effective_end_date
6744 and pbg.business_group_id = asg.business_group_id
6745 and ptp.payroll_id = asg.payroll_id
6746 and effdate between
6747 ptp.start_date and ptp.end_date;
6748 --
6749 open csr_time_period_leg(legcode);
6750 fetch csr_time_period_leg into l_dummy;
6751 --
6752 if (csr_time_period_leg%found) then
6753 close csr_time_period_leg;
6754 select pt2.time_period_id, pt2.end_date
6755 into tperiod, dtearned
6756 from per_time_periods pt2
6757 where pt2.time_period_id in
6758 (select min(time_period_id)
6759 from per_time_periods ptp
6760 where ptp.payroll_id = payid
6761 and effdate between ptp.start_date
6762 and greatest(ptp.end_date, ptp.regular_payment_date));
6763 else
6764 close csr_time_period_leg;
6765 dtearned := effdate;
6766 end if;
6767 --
6768 -- insert payroll action row.
6769 if g_debug then
6770 hr_utility.set_location(c_indent,10);
6771 end if;
6772 insert into pay_payroll_actions (
6773 payroll_action_id,
6774 action_type,
6775 business_group_id,
6776 consolidation_set_id,
6777 payroll_id,
6778 action_population_status,
6779 action_status,
6780 effective_date,
6781 date_earned,
6782 action_sequence,
6783 time_period_id,
6784 future_process_mode,
6785 created_by,
6786 creation_date,
6787 object_version_number)
6788 values (pactid,
6789 act_type,
6790 busgrp,
6791 consetid,
6792 payid,
6793 'C',
6794 'C',
6795 effdate,
6796 dtearned,
6797 pay_payroll_actions_s.nextval,
6798 tperiod,
6799 prepay_flag,
6800 creatby,
6801 creatdate,
6802 1);
6803 --
6804 -- now, we need to insert the assignment action.
6805 inassact_main(pactid,asgid,null,null,null,eentryid,
6806 TRUE, taxunit,purge_mode,run_type_id);
6807 --
6808 --
6809 -- We now need to get the id of the inserted action,
6810 -- so that it can be used for update purposes.
6811 if g_debug then
6812 hr_utility.set_location(c_indent,15);
6813 end if;
6814 select act.assignment_action_id, act.tax_unit_id
6815 into assactid, tax_unit
6816 from pay_assignment_actions act
6817 where act.payroll_action_id = pactid;
6818 --
6819 --
6820 -- we need to insert the run result row
6821 if g_debug then
6822 hr_utility.set_location(c_indent,20);
6823 end if;
6824
6825
6826 -- calc jur code name
6827 pay_core_utils.get_leg_context_iv_name
6828 ('JURISDICTION_CODE',
6829 legcode,
6830 l_jc_name,
6831 l_found);
6832
6833 if (l_found = FALSE) then
6834 l_jc_name := 'Jurisdiction';
6835 end if;
6836
6837
6838 -- set rr sparse leg_rule
6839 pay_core_utils.get_legislation_rule('RR_SPARSE',
6840 legcode,
6841 l_rule_mode,
6842 l_found
6843 );
6844 if (l_found = FALSE) then
6845 l_rule_mode := 'N';
6846 end if;
6847
6848 if upper(l_rule_mode)='Y'
6849 then
6850 -- Confirm Enabling Upgrade has been made by customer
6851 pay_core_utils.get_upgrade_status(busgrp,
6852 'ENABLE_RR_SPARSE',
6853 l_status);
6854
6855 if upper(l_status)='N'
6856 then
6857 l_rule_mode := 'N';
6858 end if;
6859 end if;
6860
6861 if upper(l_rule_mode)='Y'
6862 then
6863 l_rr_sparse:=TRUE;
6864 else
6865 l_rr_sparse :=FALSE;
6866 end if;
6867 --
6868 pay_core_utils.get_upgrade_status(busgrp,
6869 'RR_SPARSE_JC',
6870 l_status);
6871 --
6872 if upper(l_status)='Y'
6873 then
6874 l_rr_sparse_jc :=TRUE;
6875 else
6876 l_rr_sparse_jc :=FALSE;
6877 end if;
6878
6879 -- create run result
6880 pay_run_result_pkg.create_run_result(
6881 p_element_entry_id => eentryid,
6882 p_session_date => effdate,
6883 p_business_group_id => busgrp,
6884 p_jc_name => l_jc_name,
6885 p_rr_sparse => l_rr_sparse,
6886 p_rr_sparse_jc => l_rr_sparse_jc,
6887 p_asg_action_id => assactid,
6888 p_run_result_id => l_run_result_id);
6889
6890
6891 --
6892 if(sql%notfound) then
6893 if g_debug then
6894 hr_utility.trace('Update of pay_run_results has failed');
6895 end if;
6896 raise no_data_found;
6897 end if;
6898 --
6899 -- Update the element entry creator_id column
6900 -- with the assignment_action_id of balance
6901 -- adjustment action.
6902 if g_debug then
6903 hr_utility.set_location(c_indent,25);
6904 end if;
6905 update pay_element_entries_f pee
6906 set pee.creator_id = assactid
6907 where pee.element_entry_id = eentryid;
6908 --
6909 if(sql%notfound) then
6910 if g_debug then
6911 hr_utility.trace('Update of pay_element_entries_f has failed');
6912 end if;
6913 raise no_data_found;
6914 end if;
6915 --
6916 --
6917 if (act_type = 'B') then
6918
6919 -- Setup the action contexts
6920 set_action_context (assactid,
6921 l_run_result_id,
6922 eentryid,
6923 tax_unit,
6924 asgid,
6925 busgrp,
6926 legcode,
6927 l_original_entry_id,
6928 udca
6929 );
6930 --
6931 -- Call to start of latest balance maintenance code
6932 --
6933 maintain_lat_bal(assactid => assactid,
6934 rrid => l_run_result_id,
6935 eentryid => eentryid,
6936 effdate => effdate,
6937 udca => udca,
6938 act_type => act_type);
6939
6940 end if;
6941
6942 --
6943 -- Perform balance adjustment for pay_run_balances, 1st for asg level
6944 -- run balances, then group run balances.
6945 --
6946 pay_balance_pkg.create_all_asg_balances(p_asgact_id => assactid);
6947 --
6948 pay_balance_pkg.create_all_group_balances(p_pact_id => pactid);
6949 --
6950
6951 --
6952 -- Set out variables
6953 pyactid := pactid;
6954 asactid := assactid;
6955 --
6956 end bal_adjust_actions;
6957 --------------------------- bal_adjust ------------------------------
6958 /*
6959 NAME
6960 bal_adjust - perform balance adjustment.
6961 DESCRIPTION
6962 Process a balance adjustment.
6963 NOTES
6964 This is called directly from the Balance Adjustment form.
6965 This is used as a cover for bal_adjust_actions.
6966 */
6967 procedure bal_adjust
6968 (
6969 consetid in number, -- consolidation_set_id.
6970 eentryid in number, -- element_entry_id.
6971 effdate in date, -- effective_date of bal adjust.
6972 act_type in varchar2 default 'B', -- payroll_action_type.
6973 prepay_flag in varchar2 default null, -- include in prepay process?
6974 run_type_id in number default null,
6975 tax_unit_id in number default null
6976 ) is
6977 --
6978 l_pay_act_id number;
6979 l_asg_act_id number;
6980 c_indent constant varchar2(22) := 'hrassact.bal_adjust';
6981 begin
6982 g_debug := hr_utility.debug_enabled;
6983 --
6984 if g_debug then
6985 hr_utility.set_location(c_indent,10);
6986 end if;
6987 bal_adjust_actions(consetid, eentryid, effdate, l_pay_act_id,
6988 l_asg_act_id, act_type, prepay_flag,tax_unit_id,false,run_type_id);
6989 if g_debug then
6990 hr_utility.set_location(c_indent,20);
6991 end if;
6992 end;
6993 --
6994 --------------------------- maintain_lat_bal ------------------------
6995 /*
6996 NAME
6997 maintain_lat_bal - maintenace of latest balances.
6998 DESCRIPTION
6999 Perform maintenace of latest balances within balance adjustment.
7000 NOTES
7001 This is called from the balance adjustment code above and from the
7002 batch balance adjustment code.
7003 */
7004
7005 procedure maintain_lat_bal
7006 (
7007 assactid in number, -- assignment_action_id of inserted action.
7008 rrid in number, -- run_result_id
7009 eentryid in number, -- element_entry_id.
7010 effdate in date, -- effective_date of bal adjust.
7011 udca in context_details, -- The UDCA
7012 act_type in varchar2 default 'B' -- payroll_action_type.
7013 ) is
7014 --
7015 --
7016 -- balance dimensions cache
7017 --
7018 type bal_dims_cache is record
7019 (dim_id number_tbl,
7020 dim_name varchar_80_tbl,
7021 feed_chk_type varchar_tbl,
7022 feed_chk_code varchar_80_tbl,
7023 exp_chk_lvl varchar_tbl,
7024 exp_chk_code varchar_80_tbl,
7025 sz number
7026 );
7027 --
7028 l_element_type_id number;
7029 --
7030 -- cursor to get the run result values of the balance adjustment
7031 --
7032 -- Modified to retrieve result values with run_result_id.
7033 -- Bug 3482270.
7034 --
7035 cursor run_result_values is
7036 select rrv.input_value_id,
7037 rrv.result_value,
7038 rrv.run_result_id
7039 from pay_run_result_values rrv
7040 where rrv.run_result_id = rrid
7041 and rrv.result_value is not null;
7042
7043 cursor fed_latest_balances(p_inp_val_id number,
7044 p_person_id number,
7045 p_asg_id number) is
7046 select plb.latest_balance_id,
7047 plb.assignment_action_id,
7048 plb.value,
7049 nvl(plb.expired_assignment_action_id, -9999) expired_assignment_action_id,
7050 nvl(plb.expired_value, -9999) expired_value,
7051 nvl(plb.prev_balance_value, -9999) prev_balance_value,
7052 nvl(plb.prev_assignment_action_id, -9999) prev_assignment_action_id,
7053 plb.expiry_date,
7054 plb.expired_date,
7055 plb.prev_expiry_date,
7056 pdb.balance_dimension_id,
7057 pdb.balance_type_id,
7058 pbf.scale
7059 from pay_latest_balances plb,
7060 pay_defined_balances pdb,
7061 pay_balance_feeds_f pbf
7062 where pbf.input_value_id = p_inp_val_id
7063 and effdate between pbf.effective_start_date
7064 and pbf.effective_end_date
7065 and pdb.balance_type_id = pbf.balance_type_id
7066 and plb.defined_balance_id = pdb.defined_balance_id
7067 and plb.person_id = p_person_id
7068 and ( plb.assignment_id = p_asg_id
7069 or plb.assignment_id is null)
7070 and ( plb.process_group_id = (select distinct parent_object_group_id
7071 from pay_object_groups pog
7072 where pog.source_id = p_asg_id
7073 and pog.source_type = 'PAF')
7074 or plb.process_group_id is null);
7075
7076 --
7077 -- cursor to get the assignment latest balances that may be fed
7078 -- ie pay_balance feeds_f (subject to feed checking)
7079 --
7080 cursor fed_assignment_balances(p_inp_val_id number,
7081 p_asgid number) is
7082 select palb.latest_balance_id,
7083 palb.assignment_action_id,
7084 palb.value,
7085 nvl(palb.expired_assignment_action_id, -9999) expired_assignment_action_id,
7086 nvl(palb.expired_value, -9999) expired_value,
7087 nvl(palb.prev_balance_value, -9999) prev_balance_value,
7088 nvl(palb.prev_assignment_action_id, -9999) prev_assignment_action_id,
7089 pdb.balance_dimension_id,
7090 pdb.balance_type_id,
7091 pbf.scale
7092 from pay_assignment_latest_balances palb,
7093 pay_defined_balances pdb,
7094 pay_balance_feeds_f pbf
7095 where pbf.input_value_id = p_inp_val_id
7096 and effdate between pbf.effective_start_date
7097 and pbf.effective_end_date
7098 and pdb.balance_type_id = pbf.balance_type_id
7099 and palb.defined_balance_id = pdb.defined_balance_id
7100 and palb.assignment_id = p_asgid;
7101 --
7102 -- cursor to get the person latest balances that may be fed
7103 -- ie pay_balance feeds_f (subject to feed checking)
7104 --
7105 cursor fed_person_balances(p_inp_val_id number,
7106 p_person_id number) is
7107 select pplb.latest_balance_id,
7108 pplb.assignment_action_id,
7109 pplb.value,
7110 nvl(pplb.expired_assignment_action_id, -9999) expired_assignment_action_id,
7111 nvl(pplb.expired_value, -9999) expired_value,
7112 nvl(pplb.prev_balance_value, -9999) prev_balance_value,
7113 nvl(pplb.prev_assignment_action_id, -9999) prev_assignment_action_id,
7114 pdb.balance_dimension_id,
7115 pdb.balance_type_id,
7116 pbf.scale
7117 from pay_person_latest_balances pplb,
7118 pay_defined_balances pdb,
7119 pay_balance_feeds_f pbf
7120 where pbf.input_value_id = p_inp_val_id
7121 and effdate between pbf.effective_start_date
7122 and pbf.effective_end_date
7123 and pdb.balance_type_id = pbf.balance_type_id
7124 and pplb.defined_balance_id = pdb.defined_balance_id
7125 and pplb.person_id = p_person_id;
7126
7127 bal_dims bal_dims_cache;
7128
7129 c_indent constant varchar2(30) := 'hrassact.maintain_lat_bal';
7130 pactid pay_payroll_actions.payroll_action_id%TYPE;
7131 asgid per_all_assignments_f.assignment_id%TYPE;
7132 bus_grp_id per_all_assignments_f.business_group_id%TYPE;
7133 l_person_id per_all_assignments_f.person_id%TYPE;
7134 cxt_id number;
7135 tax_unit_id number;
7136 bal_dim_name pay_balance_dimensions.dimension_name%TYPE;
7137 balance_expiry_code pay_balance_dimensions.expiry_checking_code%TYPE;
7138 balance_expiry_level pay_balance_dimensions.expiry_checking_level%TYPE;
7139 bal_context_string varchar2(2000);
7140 bal_fed boolean;
7141 l_change_flag boolean;
7142 l_rule_mode pay_legislation_rules.rule_mode%TYPE;
7143 not_supported boolean;
7144 l_status varchar2(30);
7145 dummy_date date;
7146
7147 leg_rule_found boolean := FALSE;
7148 --
7149 -- Name : create_context_string
7150 --
7151 -- Get context values and also returns context string that is passed
7152 -- to feed and expiry checking if the expiry level is A (Assignment Action
7153 -- Level) or D (Date Level).
7154 --
7155 function get_contexts(udca in context_details
7156 ) return varchar2 is
7157 --
7158 l_context_string varchar2(2000);
7159 --
7160 c_indent constant varchar2(35) := 'hrassact.create_context_string';
7161 begin
7162 --
7163 if g_debug then
7164 hr_utility.set_location(c_indent,10);
7165 end if;
7166 --
7167 l_context_string := '';
7168 for cnt in 1..udca.sz loop
7169 --
7170 l_context_string := l_context_string||udca.cxt_name(cnt)||
7171 '='||udca.cxt_value(cnt)||' ';
7172 --
7173 end loop;
7174 return(l_context_string);
7175
7176 end get_contexts;
7177 --
7178 -- Name : proc_feed_check - Execute balance feeding procedure
7179 --
7180 -- Returns TRUE if balance is to be fed
7181 --
7182 -- The pl/sql function name that checks whether the balance is fed is
7183 -- passed to this routine as 'p_feed_checking_code'. The call to the
7184 -- function is done using dynamic pl/sql.
7185 --
7186 function proc_feed_check
7187 (
7188 p_feed_checking_code in varchar2, -- feed checking procedure name
7189 p_dimension_name in varchar2, -- dimension name
7190 p_bal_context_str in varchar2 -- list of context values.
7191 ) return boolean is
7192 l_feed_balance boolean := FALSE;
7193 --
7194 c_indent constant varchar2(35) := 'hrassact.proc_feed_check';
7195 l_feed_chk_str varchar2(2000); -- used with dynamic pl/sql
7196 sql_cursor integer;
7197 l_rows integer;
7198 l_feed_flag integer;
7199 --
7200 begin
7201 --
7202 if g_debug then
7203 hr_utility.set_location (c_indent, 1);
7204 hr_utility.trace ('Feed checking code = ' || p_feed_checking_code);
7205 hr_utility.trace ('context string = ' || p_bal_context_str);
7206 end if;
7207 --
7208 -- we build up the sql string to call the balance
7209 -- feed checking pl/sql procedure:
7210 --
7211 l_feed_chk_str := 'begin ' || p_feed_checking_code || ' (';
7212 l_feed_chk_str := l_feed_chk_str || ':pactid, ';
7213 l_feed_chk_str := l_feed_chk_str || ':assactid, ';
7214 l_feed_chk_str := l_feed_chk_str || ':asgid, ';
7215 l_feed_chk_str := l_feed_chk_str || ':effdate, ';
7216 l_feed_chk_str := l_feed_chk_str || ':p_dimension_name, ';
7217 l_feed_chk_str := l_feed_chk_str || ':p_bal_context_str, ';
7218 l_feed_chk_str := l_feed_chk_str || ':l_feed_flag); end;';
7219 --
7220 -- now execute the SQL statement using dynamic pl/sql:
7221 --
7222 -- Dynamic sql steps:
7223 -- ==================
7224 -- 1. Open dynamic sql cursor
7225 -- 2. Parse dynamic sql
7226 -- 3. bind variables
7227 -- 4. Execute dynamic sql
7228 -- 5. Get the variable value (providing there are rows returned)
7229 -- 6. Close the dynamic sql cursor
7230 --
7231 if g_debug then
7232 hr_utility.set_location (c_indent, 20);
7233 end if;
7234 sql_cursor := dbms_sql.open_cursor; -- step 1
7235 --
7236 if g_debug then
7237 hr_utility.set_location (c_indent, 25);
7238 end if;
7239 dbms_sql.parse(sql_cursor, l_feed_chk_str, dbms_sql.v7); -- step 2
7240 --
7241 if g_debug then
7242 hr_utility.set_location (c_indent, 30);
7243 end if;
7244 dbms_sql.bind_variable(sql_cursor, 'pactid', pactid); -- step 3:
7245 --
7246 dbms_sql.bind_variable(sql_cursor, 'assactid', assactid);
7247 --
7248 dbms_sql.bind_variable(sql_cursor, 'asgid', asgid);
7249 --
7250 dbms_sql.bind_variable(sql_cursor, 'effdate', effdate);
7251 --
7252 dbms_sql.bind_variable(sql_cursor, 'p_dimension_name', p_dimension_name);
7253 --
7254 dbms_sql.bind_variable(sql_cursor, 'p_bal_context_str', p_bal_context_str);
7255 --
7256 dbms_sql.bind_variable(sql_cursor, 'l_feed_flag', l_feed_flag);
7257 --
7258 if g_debug then
7259 hr_utility.set_location (c_indent, 35);
7260 end if;
7261 l_rows := dbms_sql.execute (sql_cursor); -- step 4
7262 --
7263 if (l_rows = 1) then
7264 if g_debug then
7265 hr_utility.set_location (c_indent, 40);
7266 end if;
7267 dbms_sql.variable_value(sql_cursor, 'l_feed_flag', -- step 5
7268 l_feed_flag);
7269 --
7270 if l_feed_flag = 1 then
7271 l_feed_balance := TRUE;
7272 end if;
7273 --
7274 if g_debug then
7275 hr_utility.set_location (c_indent, 45);
7276 end if;
7277 dbms_sql.close_cursor(sql_cursor); -- step 6
7278 else
7279 --
7280 -- None or more than 1 row has been returned. We must error as package
7281 -- call can only return 1 row, so this condition should never occur !
7282 --
7283 if g_debug then
7284 hr_utility.set_location (c_indent, 111);
7285 end if;
7286 dbms_sql.close_cursor(sql_cursor);
7287 hr_utility.raise_error;
7288 end if;
7289 --
7290 return(l_feed_balance);
7291 --
7292 end proc_feed_check;
7293 --
7294 -- Name : context_match_check - Perform context match feed checking
7295 --
7296 -- Returns TRUE if balance is to be fed
7297 --
7298 -- Performs matching check between latest balance context values
7299 -- and context values held inthe udca. Type of checking on
7300 -- jurisdiction_code context is dependant upon p_feed_checking_type.
7301 --
7302 function lb_context_match_check
7303 (
7304 p_lat_bal_id in number, -- latest balance_id
7305 p_feed_checking_type in varchar2, -- feed checking type ie 'E' or 'J'
7306 p_bal_type_id in number, -- balance type id
7307 udca in context_details
7308 ) return boolean is
7309 l_feed_flag boolean;
7310 l_match boolean;
7311
7312 c_indent constant varchar2(35) := 'hrassact.lb_context_match_check';
7313 l_jurisdiction_level pay_balance_types.jurisdiction_level%TYPE;
7314 cnt number;
7315 l_tax_unit_id number;
7316 l_jurisdiction_code pay_run_result_values.result_value%type;
7317 l_original_entry_id number;
7318 l_source_id number;
7319 l_source_text pay_run_result_values.result_value%type;
7320 l_source_text2 pay_run_result_values.result_value%type;
7321 l_source_number number;
7322 l_source_number2 number;
7323 l_tax_group pay_run_result_values.result_value%type;
7324 l_local_unit_id number;
7325 l_organization_id number;
7326 l_payroll_id number;
7327 --
7328 begin
7329 --
7330 select tax_unit_id,
7331 jurisdiction_code,
7332 original_entry_id,
7333 source_id,
7334 source_text,
7335 source_text2,
7336 source_number,
7337 source_number2,
7338 tax_group,
7339 payroll_id,
7340 local_unit_id,
7341 organization_id
7342 into l_tax_unit_id,
7343 l_jurisdiction_code,
7344 l_original_entry_id,
7345 l_source_id,
7346 l_source_text,
7347 l_source_text2,
7348 l_source_number,
7349 l_source_number2,
7350 l_tax_group,
7351 l_payroll_id,
7352 l_local_unit_id,
7353 l_organization_id
7354 from pay_latest_balances
7355 where p_lat_bal_id = latest_balance_id;
7356
7357 if g_debug then
7358 hr_utility.set_location (c_indent, 1);
7359 end if;
7360
7361 l_feed_flag := TRUE;
7362 if udca.sz = 0 then
7363 l_feed_flag := FALSE;
7364 else
7365
7366 if (l_jurisdiction_code is not null) then
7367 l_match := FALSE;
7368 for cnt in 1..udca.sz loop
7369 if (udca.cxt_name(cnt) = 'JURISDICTION_CODE') then
7370 l_match := TRUE;
7371 select nvl(jurisdiction_level, 0)
7372 into l_jurisdiction_level
7373 from pay_balance_types
7374 where balance_type_id = p_bal_type_id;
7375 if substr(udca.cxt_value(cnt), 1, l_jurisdiction_level) <>
7376 l_jurisdiction_code then
7377 -- jurisdiction_code to required level does not match
7378 l_feed_flag := FALSE;
7379 exit;
7380 end if;
7381 end if;
7382 end loop;
7383
7384 if (l_feed_flag=FALSE or
7385 l_match=FALSE) then
7386 return FALSE;
7387 end if;
7388 end if;
7389
7390 if (l_tax_unit_id is not null) then
7391 l_match := FALSE;
7392 for cnt in 1..udca.sz loop
7393 if udca.cxt_name(cnt) = 'TAX_UNIT_ID' then
7394 l_match := TRUE;
7395 if udca.cxt_value(cnt)<>to_char(l_tax_unit_id) then
7396 l_feed_flag := FALSE;
7397 exit;
7398 end if;
7399 end if;
7400 end loop;
7401
7402 if (l_feed_flag=FALSE or
7403 l_match=FALSE) then
7404 return FALSE;
7405 end if;
7406 end if;
7407
7408 if (l_original_entry_id is not null) then
7409 l_match := FALSE;
7410 for cnt in 1..udca.sz loop
7411 if udca.cxt_name(cnt) = 'ORIGINAL_ENTRY_ID' then
7412 l_match := TRUE;
7413 if udca.cxt_value(cnt)<>to_char(l_original_entry_id) then
7414 l_feed_flag := FALSE;
7415 exit;
7416 end if;
7417 end if;
7418 end loop;
7419
7420 if (l_feed_flag=FALSE or
7421 l_match=FALSE) then
7422 return FALSE;
7423 end if;
7424 end if;
7425
7426 if (l_source_id is not null) then
7427 l_match := FALSE;
7428 for cnt in 1..udca.sz loop
7429 if udca.cxt_name(cnt) = 'SOURCE_ID' then
7430 l_match := TRUE;
7431 if udca.cxt_value(cnt)<>to_char(l_source_id) then
7432 l_feed_flag := FALSE;
7433 exit;
7434 end if;
7435 end if;
7436 end loop;
7437
7438 if (l_feed_flag=FALSE or
7439 l_match=FALSE) then
7440 return FALSE;
7441 end if;
7442 end if;
7443
7444 if (l_source_text is not null) then
7445 l_match := FALSE;
7446 for cnt in 1..udca.sz loop
7447 if udca.cxt_name(cnt) = 'SOURCE_TEXT' then
7448 l_match := TRUE;
7449 if udca.cxt_value(cnt)<>l_source_text then
7450 l_feed_flag := FALSE;
7451 exit;
7452 end if;
7453 end if;
7454 end loop;
7455
7456 if (l_feed_flag=FALSE or
7457 l_match=FALSE) then
7458 return FALSE;
7459 end if;
7460 end if;
7461
7462 if (l_source_text2 is not null) then
7463 l_match := FALSE;
7464 for cnt in 1..udca.sz loop
7465 if udca.cxt_name(cnt) = 'SOURCE_TEXT2' then
7466 l_match := TRUE;
7467 if udca.cxt_value(cnt)<>l_source_text2 then
7468 l_feed_flag := FALSE;
7469 exit;
7470 end if;
7471 end if;
7472 end loop;
7473
7474 if (l_feed_flag=FALSE or
7475 l_match=FALSE) then
7476 return FALSE;
7477 end if;
7478 end if;
7479
7480 if (l_source_number is not null) then
7481 l_match := FALSE;
7482 for cnt in 1..udca.sz loop
7483 if udca.cxt_name(cnt) = 'SOURCE_NUMBER' then
7484 l_match := TRUE;
7485 if udca.cxt_value(cnt)<>to_char(l_source_number) then
7486 l_feed_flag := FALSE;
7487 exit;
7488 end if;
7489 end if;
7490 end loop;
7491
7492 if (l_feed_flag=FALSE or
7493 l_match=FALSE) then
7494 return FALSE;
7495 end if;
7496 end if;
7497
7498 if (l_source_number2 is not null) then
7499 l_match := FALSE;
7500 for cnt in 1..udca.sz loop
7501 if udca.cxt_name(cnt) = 'SOURCE_NUMBER2' then
7502 l_match := TRUE;
7503 if udca.cxt_value(cnt)<>to_char(l_source_number2) then
7504 l_feed_flag := FALSE;
7505 exit;
7506 end if;
7507 end if;
7508 end loop;
7509
7510 if (l_feed_flag=FALSE or
7511 l_match=FALSE) then
7512 return FALSE;
7513 end if;
7514 end if;
7515
7516 if (l_local_unit_id is not null) then
7517 l_match := FALSE;
7518 for cnt in 1..udca.sz loop
7519 if udca.cxt_name(cnt) = 'LOCAL_UNIT_ID' then
7520 l_match := TRUE;
7521 if udca.cxt_value(cnt)<>to_char(l_local_unit_id) then
7522 l_feed_flag := FALSE;
7523 exit;
7524 end if;
7525 end if;
7526 end loop;
7527
7528 if (l_feed_flag=FALSE or
7529 l_match=FALSE) then
7530 return FALSE;
7531 end if;
7532 end if;
7533
7534 if (l_organization_id is not null) then
7535 l_match := FALSE;
7536 for cnt in 1..udca.sz loop
7537 if udca.cxt_name(cnt) = 'ORGANIZATION_ID' then
7538 l_match := TRUE;
7539 if udca.cxt_value(cnt)<>to_char(l_organization_id) then
7540 l_feed_flag := FALSE;
7541 exit;
7542 end if;
7543 end if;
7544 end loop;
7545
7546 if (l_feed_flag=FALSE or
7547 l_match=FALSE) then
7548 return FALSE;
7549 end if;
7550 end if;
7551
7552 if (l_tax_group is not null) then
7553 l_match := FALSE;
7554 for cnt in 1..udca.sz loop
7555 if udca.cxt_name(cnt) = 'TAX_GROUP' then
7556 l_match := TRUE;
7557 if udca.cxt_value(cnt)<>l_tax_group then
7558 l_feed_flag := FALSE;
7559 exit;
7560 end if;
7561 end if;
7562 end loop;
7563
7564 if (l_feed_flag=FALSE or
7565 l_match=FALSE) then
7566 return FALSE;
7567 end if;
7568 end if;
7569
7570 if (l_payroll_id is not null) then
7571 l_match := FALSE;
7572 for cnt in 1..udca.sz loop
7573 if udca.cxt_name(cnt) = 'PAYROLL_ID' then
7574 l_match := TRUE;
7575 if udca.cxt_value(cnt)<>to_char(l_payroll_id) then
7576 l_feed_flag := FALSE;
7577 exit;
7578 end if;
7579 end if;
7580 end loop;
7581
7582 if (l_feed_flag=FALSE or
7583 l_match=FALSE) then
7584 return FALSE;
7585 end if;
7586 end if;
7587
7588 end if;
7589
7590 if p_feed_checking_type = 'J' then
7591
7592 for cnt in 1..udca.sz loop
7593 if udca.cxt_name(cnt) = 'JURISDICTION_CODE' then
7594 l_feed_flag := FALSE;
7595 exit;
7596 end if;
7597 end loop;
7598
7599 end if;
7600 return(l_feed_flag);
7601 --
7602 end lb_context_match_check;
7603
7604 function context_match_check
7605 (
7606 p_lat_bal_id in number, -- latest balance_id
7607 p_feed_checking_type in varchar2, -- feed checking type ie 'E' or 'J'
7608 p_bal_type_id in number, -- balance type id
7609 udca in context_details
7610 ) return boolean is
7611 l_feed_flag boolean;
7612 --
7613 cursor balance_context_values is
7614 select context_id,
7615 value
7616 from pay_balance_context_values
7617 where latest_balance_id = p_lat_bal_id;
7618
7619 c_indent constant varchar2(35) := 'hrassact.context_match_check';
7620 l_jurisdiction_level pay_balance_types.jurisdiction_level%TYPE;
7621 cnt number;
7622 --
7623 begin
7624 --
7625 if g_debug then
7626 hr_utility.set_location (c_indent, 1);
7627 end if;
7628 --
7629 l_feed_flag := TRUE;
7630
7631 for bcv in balance_context_values loop
7632
7633 if udca.sz = 0 then
7634 l_feed_flag := FALSE;
7635 else
7636 for cnt in 1..udca.sz loop
7637
7638 if udca.cxt_id(cnt) = bcv.context_id then
7639
7640 -- have to deal with jurisdiction code context
7641 -- as a special case
7642 if udca.cxt_name(cnt) = 'JURISDICTION_CODE' then
7643
7644 select nvl(jurisdiction_level, 0)
7645 into l_jurisdiction_level
7646 from pay_balance_types
7647 where balance_type_id = p_bal_type_id;
7648
7649 if substr(udca.cxt_value(cnt), 1, l_jurisdiction_level) <>
7650 bcv.value then
7651 -- jurisdiction_code to required level does not match
7652 l_feed_flag := FALSE;
7653 end if;
7654
7655 elsif udca.cxt_value(cnt) <> bcv.value then
7656 -- balance context value doesn't match udca value
7657 l_feed_flag := FALSE;
7658 end if;
7659
7660 exit;
7661
7662 elsif cnt = udca.sz then
7663
7664 -- balance context not in udca
7665 l_feed_flag := FALSE;
7666
7667 end if;
7668
7669 end loop;
7670 end if;
7671
7672 end loop;
7673
7674 --
7675 if g_debug then
7676 hr_utility.set_location (c_indent, 20);
7677 end if;
7678 --
7679 -- jurisdiction_code check for 'J' feed checking type whereby
7680 -- jurisdiction_code must be undefined in the udca
7681 if p_feed_checking_type = 'J' then
7682
7683 for cnt in 1..udca.sz loop
7684 if udca.cxt_name(cnt) = 'JURISDICTION_CODE' then
7685 l_feed_flag := FALSE;
7686 exit;
7687 end if;
7688 end loop;
7689
7690 end if;
7691
7692 return(l_feed_flag);
7693 --
7694 end context_match_check;
7695 --
7696 -- Name : feed_check - Function to control feed checking
7697 -- on a particular latest balance
7698 --
7699 -- Returns TRUE if balance is to be fed
7700 --
7701 function feed_check
7702 (
7703 lat_bal_id in number, -- latest balance_id
7704 lat_bal_type in varchar2, -- latest balance type (ie A or P or L)
7705 bal_dim_id in number, -- balance dimension id
7706 bal_type_id in number, -- balance type id
7707 bal_dim_name in out nocopy varchar2, -- balance dimension name
7708 bal_exp_code in out nocopy varchar2, -- balance dimension expiry code
7709 bal_exp_level in out nocopy varchar2, -- balance dimension expiry level
7710 bal_context_str in varchar2, -- balance dimension contexts string
7711 udca in context_details
7712 ) return boolean is
7713 feed_balance boolean;
7714 --
7715 c_indent constant varchar2(30) := 'hrassact.feed_check';
7716 feed_checking_type pay_balance_dimensions.feed_checking_type%TYPE;
7717 feed_checking_code pay_balance_dimensions.feed_checking_code%TYPE;
7718 dim_num number;
7719 found boolean := FALSE;
7720 --
7721 begin
7722 --
7723 if g_debug then
7724 hr_utility.set_location (c_indent, 10);
7725 end if;
7726 --
7727 -- get balance dimension info for the latest balance
7728 --
7729 -- check cache first
7730 --
7731 for dim_num in 1..bal_dims.sz loop
7732 if bal_dims.dim_id(dim_num) = bal_dim_id then
7733 bal_dim_name := bal_dims.dim_name(dim_num);
7734 feed_checking_type := bal_dims.feed_chk_type(dim_num);
7735 feed_checking_code := bal_dims.feed_chk_code(dim_num);
7736 bal_exp_code := bal_dims.exp_chk_code(dim_num);
7737 bal_exp_level := bal_dims.exp_chk_lvl(dim_num);
7738 found := TRUE;
7739 end if;
7740 end loop;
7741
7742 if found = FALSE then
7743
7744 select pbd.dimension_name,
7745 pbd.feed_checking_type,
7746 pbd.feed_checking_code,
7747 pbd.expiry_checking_code,
7748 pbd.expiry_checking_level
7749 into bal_dim_name,
7750 feed_checking_type,
7751 feed_checking_code,
7752 bal_exp_code,
7753 bal_exp_level
7754 from pay_balance_dimensions pbd
7755 where pbd.balance_dimension_id = bal_dim_id;
7756
7757 -- put into cache
7758 bal_dims.sz := bal_dims.sz + 1;
7759 bal_dims.dim_id(bal_dims.sz) := bal_dim_id;
7760 bal_dims.dim_name(bal_dims.sz) := bal_dim_name;
7761 bal_dims.feed_chk_type(bal_dims.sz) := feed_checking_type;
7762 bal_dims.feed_chk_code(bal_dims.sz) := feed_checking_code;
7763 bal_dims.exp_chk_code(bal_dims.sz) := bal_exp_code;
7764 bal_dims.exp_chk_lvl(bal_dims.sz) := bal_exp_level;
7765
7766 end if;
7767
7768
7769 --
7770 if feed_checking_type is null then
7771 -- default checking type whereby always feed balance
7772 if g_debug then
7773 hr_utility.set_location (c_indent, 20);
7774 end if;
7775 feed_balance := TRUE;
7776
7777 elsif feed_checking_type not in ('P', 'E', 'J') then
7778 -- unhandled checking type is S-ubject
7779 -- we either just delete latest balance, or
7780 -- recalculate it
7781 -- YET TO BE DECIDED
7782
7783 if g_debug then
7784 hr_utility.set_location (c_indent, 30);
7785 end if;
7786
7787 if lat_bal_type = 'A' then
7788 delete from pay_balance_context_values
7789 where latest_balance_id = lat_bal_id;
7790
7791 delete from pay_assignment_latest_balances
7792 where latest_balance_id = lat_bal_id;
7793 elsif lat_bal_type = 'P' then
7794 delete from pay_balance_context_values
7795 where latest_balance_id = lat_bal_id;
7796
7797 delete from pay_person_latest_balances
7798 where latest_balance_id = lat_bal_id;
7799 else
7800 delete from pay_latest_balances
7801 where latest_balance_id = lat_bal_id;
7802
7803 end if;
7804 -- or recalculate latest balance
7805 feed_balance := FALSE;
7806
7807 elsif feed_checking_type = 'P' then
7808 -- legislative defined procedure feed_checking_code is
7809 -- used to perform feed checking
7810
7811 feed_balance := proc_feed_check(feed_checking_code, bal_dim_name,
7812 bal_context_str);
7813
7814 elsif feed_checking_type in ('E', 'J') then
7815
7816 if (lat_bal_type='L') then
7817 feed_balance:= lb_context_match_check(lat_bal_id,feed_checking_type,
7818 bal_type_id, udca);
7819 else
7820 feed_balance := context_match_check(lat_bal_id, feed_checking_type,
7821 bal_type_id, udca);
7822 end if;
7823
7824 end if;
7825
7826 return(feed_balance);
7827
7828 end feed_check;
7829 --
7830 -- Name : get_expiry_date - Execute balance expiry date procedure
7831 --
7832 -- Returns last date in period for dimension containing the
7833 -- effective_date of p_bal_owner_asg_actid
7834 --
7835 -- returns 01/01/1900 if p_bal_owner_asg_actid is the empty value
7836 -- ie -9999. The calling code will then treats this as special balance
7837 -- value - and should leave it unchanged.
7838 --
7839 -- returns 01/01/1990 if is a never expired type of balance
7840 --
7841 -- The pl/sql function name that checks whether the balance is fed is
7842 -- passed to this routine as 'p_expiry_date_code'. The call to the
7843 -- function is done using dynamic pl/sql.
7844 --
7845 -- Also returns effective date of latest balance in p_bal_owner_eff_date
7846 -- (to save refetching later on).
7847 --
7848 function get_expiry_date
7849 (
7850 p_expiry_date_code in varchar2, -- expiry date procedure name
7851 p_ass_action_id in number, -- balance adjustment asg action id
7852 p_bal_owner_asg_actid in number, -- latest balance asg action id
7853 p_dimension_name in varchar2, -- dimension name
7854 p_expiry_check_level in varchar2, -- expiry checking level
7855 p_bal_context_str in varchar2, -- list of context values.
7856 p_bal_owner_eff_date in out nocopy date -- latest balance date
7857 ) return date is
7858 l_expiry_date date;
7859 --
7860 c_indent constant varchar2(35) := 'hrassact.get_expiry_date';
7861 l_payroll_action pay_payroll_actions.payroll_action_id%type;
7862 l_effective_date pay_payroll_actions.effective_date%type;
7863 l_bal_owner_pay_action pay_payroll_actions.payroll_action_id%type;
7864 l_expiry_chk_str varchar2(2000); -- used with dynamic pl/sql
7865 sql_cursor integer;
7866 l_rows integer;
7867 --
7868 begin
7869 --
7870 if g_debug then
7871 hr_utility.set_location (c_indent, 5);
7872 end if;
7873 if p_bal_owner_asg_actid = -9999 then
7874 l_expiry_date := to_date('01/01/1900', 'DD/MM/YYYY');
7875 p_bal_owner_eff_date := l_expiry_date;
7876
7877 return(l_expiry_date);
7878 end if;
7879 --
7880 if g_debug then
7881 hr_utility.trace ('Expiry date fetching code = ' || p_expiry_date_code);
7882 hr_utility.set_location (c_indent||p_bal_owner_asg_actid, 7);
7883 end if;
7884 --
7885 -- Get the payroll_action_id and eff date for the latest balance
7886 -- The expiry date returned is the last date in the period for
7887 -- the balance dimension that contains this date
7888 --
7889 select pay.payroll_action_id,
7890 pay.effective_date
7891 into l_bal_owner_pay_action,
7892 p_bal_owner_eff_date
7893 from pay_assignment_actions asg
7894 , pay_payroll_actions pay
7895 where asg.assignment_action_id = p_bal_owner_asg_actid
7896 and pay.payroll_action_id = asg.payroll_action_id;
7897 --
7898 -- Get the payroll_action_id and eff date for the adjustment if
7899 -- it is different
7900 --
7901 if g_debug then
7902 hr_utility.set_location (c_indent||p_ass_action_id, 10);
7903 end if;
7904 if p_ass_action_id <> p_bal_owner_asg_actid then
7905 select pay.payroll_action_id,
7906 pay.effective_date
7907 into l_payroll_action,
7908 l_effective_date
7909 from pay_assignment_actions asg
7910 , pay_payroll_actions pay
7911 where asg.assignment_action_id = p_ass_action_id
7912 and pay.payroll_action_id = asg.payroll_action_id;
7913 else
7914 l_payroll_action := l_bal_owner_pay_action;
7915 l_effective_date := p_bal_owner_eff_date;
7916 end if;
7917 --
7918 -- if Never expired balance we simply return an expiry date
7919 -- of beginning of time
7920 --
7921 if p_expiry_check_level = 'N' then
7922 if g_debug then
7923 hr_utility.set_location (c_indent, 12);
7924 end if;
7925 l_expiry_date := to_date('01/01/1900', 'DD/MM/YYYY');
7926
7927 return(l_expiry_date);
7928 elsif p_expiry_date_code is null then
7929 --
7930 -- expiry date procedure doesn't exist
7931 --
7932 if g_debug then
7933 hr_utility.set_location (c_indent, 14);
7934 end if;
7935 dbms_sql.close_cursor(sql_cursor);
7936 hr_utility.set_message(801, 'HR_7274_PAY_NO_EXPIRY_CODE');
7937 hr_utility.set_message_token ('EXPIRY_CODE', p_expiry_date_code);
7938 hr_utility.raise_error;
7939 end if;
7940 --
7941 -- we build up the sql string to call the balance
7942 -- feed checking pl/sql procedure:
7943 --
7944 l_expiry_chk_str := 'begin ' || p_expiry_date_code || ' (';
7945 l_expiry_chk_str := l_expiry_chk_str || ':l_bal_owner_pay_action, ';
7946 l_expiry_chk_str := l_expiry_chk_str || ':l_payroll_action, ';
7947 l_expiry_chk_str := l_expiry_chk_str || ':p_bal_owner_asg_actid, ';
7948 l_expiry_chk_str := l_expiry_chk_str || ':p_ass_action_id, ';
7949 l_expiry_chk_str := l_expiry_chk_str || ':p_bal_owner_eff_date, ';
7950 l_expiry_chk_str := l_expiry_chk_str || ':l_effective_date, ';
7951 l_expiry_chk_str := l_expiry_chk_str || ':p_dimension_name, ';
7952 --
7953 if (p_expiry_check_level in ('A', 'D')) then
7954 l_expiry_chk_str := l_expiry_chk_str || ':p_bal_context_str, ';
7955 end if;
7956 --
7957 l_expiry_chk_str := l_expiry_chk_str || ':l_expiry_date); end;';
7958 --
7959 -- now execute the SQL statement using dynamic pl/sql:
7960 --
7961 -- Dynamic sql steps:
7962 -- ==================
7963 -- 1. Open dynamic sql cursor
7964 -- 2. Parse dynamic sql
7965 -- 3. bind variables
7966 -- 4. Execute dynamic sql
7967 -- 5. Get the variable value (providing there are rows returned)
7968 -- 6. Close the dynamic sql cursor
7969 --
7970 if g_debug then
7971 hr_utility.set_location (c_indent, 20);
7972 end if;
7973 sql_cursor := dbms_sql.open_cursor; -- step 1
7974 --
7975 if g_debug then
7976 hr_utility.set_location (c_indent, 25);
7977 end if;
7978 dbms_sql.parse(sql_cursor, l_expiry_chk_str, dbms_sql.v7); -- step 2
7979 --
7980 if g_debug then
7981 hr_utility.set_location (c_indent||to_char(p_bal_owner_eff_date, 'DD/MM/YYYY'), 30);
7982 end if;
7983 dbms_sql.bind_variable(sql_cursor, 'l_bal_owner_pay_action', l_bal_owner_pay_action); -- step 3:
7984 --
7985 dbms_sql.bind_variable(sql_cursor, 'l_payroll_action', l_payroll_action);
7986 --
7987 dbms_sql.bind_variable(sql_cursor, 'p_bal_owner_asg_actid', p_bal_owner_asg_actid);
7988 --
7989 dbms_sql.bind_variable(sql_cursor, 'p_ass_action_id', p_ass_action_id);
7990 --
7991 dbms_sql.bind_variable(sql_cursor, 'p_bal_owner_eff_date', p_bal_owner_eff_date);
7992 --
7993 dbms_sql.bind_variable(sql_cursor, 'l_effective_date', l_effective_date);
7994 --
7995 dbms_sql.bind_variable(sql_cursor, 'p_dimension_name', p_dimension_name);
7996 --
7997 if (p_expiry_check_level in ('A', 'D')) then
7998 dbms_sql.bind_variable(sql_cursor, 'p_bal_context_str', p_bal_context_str);
7999 end if;
8000 --
8001 dbms_sql.bind_variable(sql_cursor, 'l_expiry_date', l_expiry_date);
8002 --
8003 if g_debug then
8004 hr_utility.set_location (c_indent, 35);
8005 end if;
8006 l_rows := dbms_sql.execute (sql_cursor); -- step 4
8007 --
8008 if (l_rows = 1) then
8009 if g_debug then
8010 hr_utility.set_location (c_indent, 40);
8011 end if;
8012 dbms_sql.variable_value(sql_cursor, 'l_expiry_date', -- step 5
8013 l_expiry_date);
8014 --
8015 if g_debug then
8016 hr_utility.set_location (c_indent||to_char(l_expiry_date, 'DD/MM/YYYY'), 45);
8017 end if;
8018 dbms_sql.close_cursor(sql_cursor); -- step 6
8019 elsif (l_rows = 0) then
8020 --
8021 -- expiry date procedure didn't exist
8022 --
8023 if g_debug then
8024 hr_utility.set_location (c_indent, 50);
8025 end if;
8026 dbms_sql.close_cursor(sql_cursor);
8027 hr_utility.set_message(801, 'HR_7274_PAY_NO_EXPIRY_CODE');
8028 hr_utility.set_message_token ('EXPIRY_CODE', p_expiry_date_code);
8029 hr_utility.raise_error;
8030 else
8031 --
8032 -- None or more than 1 row has been returned. We must error as package
8033 -- call can only return 1 row, so this condition should never occur !
8034 --
8035 if g_debug then
8036 hr_utility.set_location (c_indent, 60);
8037 end if;
8038 dbms_sql.close_cursor(sql_cursor);
8039 hr_utility.raise_error;
8040 end if;
8041 --
8042 return(l_expiry_date);
8043 --
8044 end get_expiry_date;
8045 --
8046 -- Name : feed_balance - Adjust latest/previous/expired balances
8047 --
8048 -- Called if balance adjustment does feed this latest balance.
8049 -- Have to adjust none of more of latest, previous or expired balance
8050 -- values and possibly their asg action ids depending upon their
8051 -- and the balance adjustments period
8052 --
8053 function feed_balance
8054 (
8055 p_expiry_date_code in varchar2, -- expiry date procedure name
8056 p_dimension_name in varchar2, -- dimension name
8057 p_expiry_check_level in varchar2, -- expiry checking level
8058 p_bal_context_str in varchar2, -- list of context values.
8059 assignment_action_id in out nocopy number, -- lb lat asg action id
8060 value in out nocopy number, -- lb lat value
8061 expired_asg_action_id in out nocopy number, -- lb exp asg action id
8062 expired_value in out nocopy number, -- lb exp value
8063 prev_asg_action_id in out nocopy number, -- lb prev al asg action id
8064 prev_balance_value in out nocopy number, -- lb prev value
8065 result_value in number, -- balance adjustment rrv
8066 feed_scale in number, -- balance dimension feed scale
8067 expiry_date in out nocopy date , -- lb expiry date
8068 expired_date in out nocopy date , -- lb expired date
8069 prev_expiry_date in out nocopy date -- lb prev expiry date
8070 ) return boolean is
8071 l_change_flag boolean;
8072 --
8073 c_indent constant varchar2(35) := 'hrassact.feed_balance';
8074 lat_bal_exp_date date;
8075 l_bal_owner_eff_date pay_payroll_actions.effective_date%type;
8076 bal_adj_exp_date date;
8077 bal_adj_eff_date pay_payroll_actions.effective_date%type;
8078 prev_bal_exp_date date;
8079 p_bal_owner_eff_date pay_payroll_actions.effective_date%type;
8080 exp_bal_exp_date date;
8081 e_bal_owner_eff_date pay_payroll_actions.effective_date%type;
8082 --
8083 begin
8084 --
8085 if g_debug then
8086 hr_utility.set_location (c_indent, 10);
8087 end if;
8088 --
8089 l_change_flag := TRUE;
8090 --
8091 -- Check if latest balance already owned by balance
8092 -- adjustment. If so simply increment the value
8093 --
8094 if assignment_action_id = assactid or
8095 expired_asg_action_id = assactid then
8096
8097 if g_debug then
8098 hr_utility.set_location (c_indent, 15);
8099 end if;
8100
8101 if assignment_action_id = assactid then
8102 value := value + (result_value * feed_scale);
8103 end if;
8104
8105 if expired_asg_action_id = assactid then
8106 expired_value := expired_value + (result_value * feed_scale);
8107
8108 if prev_asg_action_id = assactid then
8109 prev_balance_value := prev_balance_value + (result_value * feed_scale);
8110 end if;
8111 end if;
8112
8113 return(l_change_flag);
8114 end if;
8115
8116 --
8117 -- Get expiry date for balance adjustment
8118 --
8119 bal_adj_exp_date := get_expiry_date(p_expiry_date_code, assactid,
8120 assactid, p_dimension_name,
8121 p_expiry_check_level, p_bal_context_str,
8122 bal_adj_eff_date);
8123 --
8124 if g_debug then
8125 hr_utility.set_location (c_indent, 20);
8126 end if;
8127 --
8128 -- Get expiry date for latest balance
8129 --
8130 lat_bal_exp_date := get_expiry_date(p_expiry_date_code, assignment_action_id,
8131 assignment_action_id, p_dimension_name,
8132 p_expiry_check_level, p_bal_context_str,
8133 l_bal_owner_eff_date);
8134 --
8135 if g_debug then
8136 hr_utility.set_location (c_indent||p_dimension_name, 30);
8137 end if;
8138
8139 if bal_adj_exp_date > lat_bal_exp_date then
8140 -- balance adjustment expiry date is later than the latest balance
8141 -- expiry date, and hence in a later period so we copy the latest balance
8142 -- to the previous latest balance and expired latest balance, and set
8143 -- the latest balance to be the balance adjustment
8144
8145 if g_debug then
8146 hr_utility.set_location (c_indent, 40);
8147 end if;
8148
8149 prev_balance_value := value;
8150 prev_asg_action_id := assignment_action_id;
8151 expired_value := value;
8152 expired_asg_action_id := assignment_action_id;
8153
8154 value := result_value * feed_scale;
8155 assignment_action_id := assactid;
8156 expired_date := lat_bal_exp_date;
8157 prev_expiry_date := lat_bal_exp_date;
8158 expiry_date := bal_adj_exp_date;
8159
8160 elsif bal_adj_exp_date = lat_bal_exp_date then
8161 -- balance adjustment expiry date = latest balance expiry date
8162 -- so feed latest balance and possibly previous latest balance
8163
8164 if g_debug then
8165 hr_utility.set_location (c_indent, 50);
8166 end if;
8167
8168 if bal_adj_eff_date >= l_bal_owner_eff_date then
8169 -- balance adjustment effective date is later than the latest balance
8170 -- effective date so we copy the latest balance to the previous latest
8171 -- balance and adjust the latest balance value and its asg action id by
8172 -- the adjustment
8173
8174 if g_debug then
8175 hr_utility.set_location (c_indent, 60);
8176 end if;
8177
8178 prev_balance_value := value;
8179 prev_asg_action_id := assignment_action_id;
8180
8181 value := value + (result_value * feed_scale);
8182 assignment_action_id := assactid;
8183 prev_expiry_date := lat_bal_exp_date;
8184 expiry_date := bal_adj_exp_date;
8185
8186 else
8187 -- the balance adjustment effective date is earlier than the latest balance
8188 -- effective date so we adjust the latest balance value (but nots its asg
8189 -- action id), and then see if we need to adjust the previous latest
8190 -- balance
8191
8192 if g_debug then
8193 hr_utility.set_location (c_indent, 70);
8194 end if;
8195
8196 value := value + (result_value * feed_scale);
8197 expiry_date := bal_adj_exp_date;
8198
8199 -- Get expiry date for previous latest balance
8200 prev_bal_exp_date := get_expiry_date(p_expiry_date_code, prev_asg_action_id,
8201 prev_asg_action_id, p_dimension_name,
8202 p_expiry_check_level, p_bal_context_str,
8203 p_bal_owner_eff_date);
8204
8205 if bal_adj_exp_date = prev_bal_exp_date then
8206 -- need to adjust previous balance as in same period as balance adjustment
8207
8208 if g_debug then
8209 hr_utility.set_location (c_indent, 80);
8210 end if;
8211
8212 if bal_adj_eff_date >= p_bal_owner_eff_date then
8213 -- as balance adjustment effective date is later than previous latest
8214 -- balance effective date we also need to amend previous latest
8215 -- balance asg action id
8216
8217 if g_debug then
8218 hr_utility.set_location (c_indent, 90);
8219 end if;
8220
8221 prev_balance_value := prev_balance_value + (result_value * feed_scale);
8222 prev_asg_action_id := assactid;
8223 prev_expiry_date := bal_adj_exp_date;
8224 else
8225 if g_debug then
8226 hr_utility.set_location (c_indent, 100);
8227 end if;
8228
8229 prev_balance_value := prev_balance_value + (result_value * feed_scale);
8230 prev_expiry_date := prev_bal_exp_date;
8231 end if;
8232
8233 elsif prev_asg_action_id <> -9999 then
8234 -- balance adjustment is in later period than previous latest balance
8235 -- so replace previous latest balance value and its asg action id by
8236 -- the balance adjustment
8237
8238 if g_debug then
8239 hr_utility.set_location (c_indent, 110);
8240 end if;
8241 prev_balance_value := result_value * feed_scale;
8242 prev_asg_action_id := assactid;
8243 prev_expiry_date := bal_adj_exp_date;
8244
8245 else
8246 -- previous balance value is undefined (ie null or -9999)
8247
8248 if g_debug then
8249 hr_utility.set_location (c_indent, 115);
8250 end if;
8251
8252 end if;
8253 end if;
8254
8255 else
8256 -- balance adjusmtent expiry date <> latest balance expiry date
8257 -- so may need to adjust expired and previous latest balances
8258 if g_debug then
8259 hr_utility.set_location (c_indent, 120);
8260 end if;
8261
8262 -- Get expiry date for expired latest balance
8263 exp_bal_exp_date := get_expiry_date(p_expiry_date_code, expired_asg_action_id,
8264 expired_asg_action_id, p_dimension_name,
8265 p_expiry_check_level, p_bal_context_str,
8266 e_bal_owner_eff_date);
8267
8268 -- if balance adjusmtent expiry date = expired balance expiry date
8269 -- then adjust expired balance and possibly previous latest balance
8270 if bal_adj_exp_date = exp_bal_exp_date then
8271
8272 if g_debug then
8273 hr_utility.set_location (c_indent, 130);
8274 end if;
8275
8276 if bal_adj_eff_date >= e_bal_owner_eff_date then
8277 -- balance adjustment effective date is later than the expired balance
8278 -- effective date so the expired value and asg action id needs to be
8279 -- adjusted by the balance adjustment
8280 --
8281 -- before doing so we see if the previous latest balance is from the
8282 -- same assignment action id and hence also needs adjusting
8283
8284 if g_debug then
8285 hr_utility.set_location (c_indent, 140);
8286 end if;
8287
8288 if expired_asg_action_id = prev_asg_action_id then
8289 -- adjust the previous latest balance
8290 if g_debug then
8291 hr_utility.set_location (c_indent, 150);
8292 end if;
8293
8294 prev_balance_value := prev_balance_value + (result_value * feed_scale);
8295 prev_asg_action_id := assactid;
8296 prev_expiry_date := bal_adj_exp_date;
8297 end if;
8298
8299 expired_value := expired_value + (result_value * feed_scale);
8300 expired_asg_action_id := assactid;
8301 expired_date := bal_adj_exp_date;
8302
8303 else
8304 -- balance adjustment effective date is earlier than the expired balance
8305 -- effective date so the expired value (not the asg action id) needs
8306 -- to be adjusted by the balance adjustment
8307 --
8308 -- before doing so we see if the previous latest balance is from the
8309 -- same assignment action id and hence also needs adjusting
8310
8311 if g_debug then
8312 hr_utility.set_location (c_indent, 160);
8313 end if;
8314
8315 if expired_asg_action_id = prev_asg_action_id then
8316 -- adjust the previous latest balance
8317 if g_debug then
8318 hr_utility.set_location (c_indent||prev_balance_value, 170);
8319 end if;
8320
8321 prev_balance_value := prev_balance_value + (result_value * feed_scale);
8322 prev_expiry_date := exp_bal_exp_date;
8323 if g_debug then
8324 hr_utility.set_location (c_indent||prev_balance_value, 170);
8325 end if;
8326 end if;
8327
8328 if g_debug then
8329 hr_utility.set_location (c_indent||expired_value, 170);
8330 end if;
8331 expired_value := expired_value + (result_value * feed_scale);
8332 expired_date := exp_bal_exp_date;
8333 if g_debug then
8334 hr_utility.set_location (c_indent||expired_value, 170);
8335 end if;
8336
8337 end if;
8338
8339 else
8340 -- the balance adjustment expiry date is not the same as either the
8341 -- latest balance expiry date or the expired balance expiry date,
8342 -- and is not later than the latest balance expiry date.
8343 -- it may be between the latest and expired balance periods - in
8344 -- which case we would want to adjust the expired, or it may be
8345 -- ealier than the expired.
8346 --
8347 if g_debug then
8348 hr_utility.set_location (c_indent, 180);
8349 end if;
8350
8351 if expired_asg_action_id <> -9999 and
8352 bal_adj_exp_date > exp_bal_exp_date then
8353 -- it is newer so we need to replace the expired (and possibly previous)
8354
8355 if g_debug then
8356 hr_utility.set_location (c_indent, 190);
8357 end if;
8358
8359 if expired_asg_action_id = prev_asg_action_id then
8360 -- adjust the previous latest balance
8361 if g_debug then
8362 hr_utility.set_location (c_indent, 200);
8363 end if;
8364
8365 prev_balance_value := result_value * feed_scale;
8366 prev_asg_action_id := assactid;
8367 prev_expiry_date := bal_adj_exp_date;
8368 end if;
8369
8370 expired_value := result_value * feed_scale;
8371 expired_asg_action_id := assactid;
8372 expired_date := bal_adj_exp_date;
8373
8374 else
8375 -- the balance adjustment is in an older period than the expired
8376 -- latest balance and therefore does not feed it
8377
8378 if g_debug then
8379 hr_utility.set_location (c_indent, 210);
8380 end if;
8381
8382 l_change_flag := FALSE;
8383
8384 end if;
8385
8386 end if;
8387 end if;
8388
8389 return(l_change_flag);
8390 --
8391 end feed_balance;
8392 --
8393 begin
8394 g_debug := hr_utility.debug_enabled;
8395 --
8396 if g_debug then
8397 hr_utility.set_location(c_indent,10);
8398 end if;
8399 --
8400 -- initialise balance dimensions cache
8401 --
8402 bal_dims.sz := 0;
8403 --
8404 -- get info about assignment and action
8405 -- including tax_unit_id context value
8406 --
8407 select pera.assignment_id,
8408 pera.person_id,
8409 paa.payroll_action_id,
8410 paa.tax_unit_id,
8411 pera.business_group_id
8412 into asgid,
8413 l_person_id,
8414 pactid,
8415 tax_unit_id,
8416 bus_grp_id
8417 from pay_assignment_actions paa,
8418 per_all_assignments_f pera
8419 where paa.assignment_action_id = assactid
8420 and pera.assignment_id = paa.assignment_id
8421 and effdate between pera.effective_start_date
8422 and pera.effective_end_date;
8423 --
8424 if g_debug then
8425 hr_utility.set_location(c_indent,20);
8426 end if;
8427 --
8428 if act_type = 'B' then
8429 --
8430 -- check for BAL_ADJ_LAT_BAL legislation rule to see if
8431 -- this functionality is supported for this balance adjustment
8432 --
8433 if g_ba_lat_bal_maintenance is null then
8434
8435 /*Bug 10212578 12.2 Begin */
8436 leg_rule_found := FALSE;
8437 pay_core_utils.get_legislation_rule('BAL_ADJ_LAT_BAL',pay_core_utils.get_legislation_code(bus_grp_id),l_rule_mode,leg_rule_found);
8438
8439 if leg_rule_found = FALSE then
8440 l_rule_mode := 'N';
8441 end if;
8442 /*Bug 10212578 12.2 End */
8443 if upper(l_rule_mode) = 'Y' then
8444 g_ba_lat_bal_maintenance := FALSE;
8445 else
8446 g_ba_lat_bal_maintenance := TRUE;
8447 end if;
8448
8449 end if;
8450 not_supported := g_ba_lat_bal_maintenance;
8451 else
8452 --
8453 -- Reversal - as entered maintain_lat_bal REV_LAT_BAL
8454 -- is set
8455 --
8456 not_supported := FALSE;
8457 end if;
8458 --
8459 --
8460 if not_supported = TRUE then
8461 --
8462 -- delete latest balances
8463 if g_debug then
8464 hr_utility.set_location(c_indent,25);
8465 end if;
8466 --
8467 -- Derive element type id from the run result.
8468 --
8469 select rr.element_type_id into l_element_type_id
8470 from pay_run_results rr
8471 where rr.run_result_id = rrid;
8472
8473 del_latest_balances(asgid, effdate, eentryid, l_element_type_id);
8474 return;
8475 end if;
8476 --
8477 -- get the contexts cached
8478 if contexts_cached = FALSE then
8479 cache_contexts;
8480 end if;
8481 --
8482 if g_debug then
8483 hr_utility.set_location(c_indent,30);
8484 end if;
8485 --
8486 for rrv in run_result_values loop
8487
8488 bal_fed := FALSE;
8489 l_change_flag := FALSE;
8490 -- return contents of udca
8491 bal_context_string := get_contexts(udca);
8492
8493
8494 pay_core_utils.get_upgrade_status(p_bus_grp_id=> bus_grp_id,
8495 p_short_name=> 'SINGLE_BAL_TABLE',
8496 p_status=>l_status);
8497
8498 if (l_status='N')
8499 then
8500 -- feed check assignment latest balances
8501 for alb in fed_assignment_balances(rrv.input_value_id, asgid) loop
8502 bal_fed := feed_check(alb.latest_balance_id, 'A', alb.balance_dimension_id,
8503 alb.balance_type_id, bal_dim_name,
8504 balance_expiry_code, balance_expiry_level,
8505 bal_context_string, udca);
8506
8507
8508 if bal_fed = TRUE then
8509 l_change_flag := feed_balance(balance_expiry_code, bal_dim_name,
8510 balance_expiry_level, bal_context_string,
8511 alb.assignment_action_id, alb.value,
8512 alb.expired_assignment_action_id, alb.expired_value,
8513 alb.prev_assignment_action_id, alb.prev_balance_value,
8514 fnd_number.canonical_to_number(rrv.result_value),
8515 alb.scale, dummy_date,dummy_date,dummy_date);
8516
8517 if l_change_flag = TRUE then
8518 update pay_assignment_latest_balances
8519 set assignment_action_id = alb.assignment_action_id,
8520 value = alb.value,
8521 expired_assignment_action_id = alb.expired_assignment_action_id,
8522 expired_value = alb.expired_value,
8523 prev_assignment_action_id = alb.prev_assignment_action_id,
8524 prev_balance_value = alb.prev_balance_value
8525 where latest_balance_id = alb.latest_balance_id;
8526 end if;
8527 end if;
8528 end loop;
8529 --
8530 -- feed check person latest balances
8531 for plb in fed_person_balances(rrv.input_value_id, l_person_id) loop
8532 bal_fed := feed_check(plb.latest_balance_id, 'P', plb.balance_dimension_id,
8533 plb.balance_type_id, bal_dim_name,
8534 balance_expiry_code, balance_expiry_level,
8535 bal_context_string, udca);
8536
8537 if bal_fed = TRUE then
8538 l_change_flag := feed_balance(balance_expiry_code, bal_dim_name,
8539 balance_expiry_level, bal_context_string,
8540 plb.assignment_action_id, plb.value,
8541 plb.expired_assignment_action_id, plb.expired_value,
8542 plb.prev_assignment_action_id, plb.prev_balance_value,
8543 fnd_number.canonical_to_number(rrv.result_value),
8544 plb.scale,dummy_date,dummy_date,dummy_date);
8545
8546 if l_change_flag = TRUE then
8547 update pay_person_latest_balances
8548 set assignment_action_id = plb.assignment_action_id,
8549 value = plb.value,
8550 expired_assignment_action_id = plb.expired_assignment_action_id,
8551 expired_value = plb.expired_value,
8552 prev_assignment_action_id = plb.prev_assignment_action_id,
8553 prev_balance_value = plb.prev_balance_value
8554 where latest_balance_id = plb.latest_balance_id;
8555 end if;
8556 end if;
8557 end loop;
8558 --
8559 else
8560 -- feed check person latest balances
8561 for lb in fed_latest_balances(rrv.input_value_id, l_person_id, asgid) loop
8562 hr_utility.set_location(c_indent,100);
8563 bal_fed := feed_check(lb.latest_balance_id, 'L', lb.balance_dimension_id,
8564 lb.balance_type_id, bal_dim_name,
8565 balance_expiry_code, balance_expiry_level,
8566 bal_context_string, udca);
8567
8568 if bal_fed = TRUE then
8569 l_change_flag := feed_balance(balance_expiry_code, bal_dim_name,
8570 balance_expiry_level, bal_context_string,
8571 lb.assignment_action_id, lb.value,
8572 lb.expired_assignment_action_id, lb.expired_value,
8573 lb.prev_assignment_action_id, lb.prev_balance_value,
8574 fnd_number.canonical_to_number(rrv.result_value),
8575 lb.scale,lb.expiry_date, lb.expired_date,lb.prev_expiry_date);
8576
8577 if l_change_flag = TRUE then
8578 update pay_latest_balances
8579 set assignment_action_id = lb.assignment_action_id,
8580 value = lb.value,
8581 expiry_date = lb.expiry_date,
8582 expired_assignment_action_id = lb.expired_assignment_action_id,
8583 expired_value = lb.expired_value,
8584 expired_date = lb.expired_date,
8585 prev_assignment_action_id = lb.prev_assignment_action_id,
8586 prev_expiry_date = lb.prev_expiry_date,
8587 prev_balance_value = lb.prev_balance_value
8588 where latest_balance_id = lb.latest_balance_id;
8589 end if;
8590 end if;
8591 end loop;
8592 end if;
8593 end loop;
8594 --
8595 end maintain_lat_bal;
8596 --
8597 -- this function retruns the assignment_action id of the
8598 -- reversal that is being retried
8599 -- the action passed is is the assignment action of the reversal
8600
8601 function get_retry_revesal_action_id(p_act_id number)
8602 return number is
8603
8604 l_mst_id number;
8605 new_assactid number;
8606 found number;
8607 begin
8608
8609 -- determine the master action
8610 SELECT pai.locked_action_id
8611 INTO l_mst_id
8612 FROM pay_action_interlocks pai,pay_assignment_actions paa
8613 WHERE pai.locking_action_id = p_act_id
8614 AND paa.assignment_action_id = pai.locked_action_id
8615 AND paa.source_action_id is null;
8616
8617 select 1
8618 into found
8619 from dual
8620 where exists (select 1 from pay_assignment_actions paa
8621 where paa.source_action_id=l_mst_id);
8622
8623 begin
8624 -- if there is no run for that interlocok cacluate
8625
8626 -- what the new assignment action should be
8627 select child_asg.assignment_action_id
8628 into new_assactid
8629 from pay_assignment_actions mast_asg,
8630 pay_assignment_actions child_asg,
8631 pay_assignment_actions rev_asg,
8632 pay_action_interlocks pai
8633 where l_mst_id=mast_asg.assignment_action_id
8634 and child_asg.source_action_id is not null
8635 and child_asg.assignment_id=mast_asg.assignment_id
8636 and child_asg.payroll_action_id=mast_asg.payroll_action_id
8637 and child_asg.action_status<>'B'
8638 and pay_core_utils.get_process_path(child_asg.assignment_action_id)
8639 =rev_asg.process_path
8640 and rev_asg.assignment_action_id=p_act_id
8641 and pai.locking_action_id=p_act_id
8642 and pai.locked_action_id=child_asg.assignment_action_id;
8643
8644 return new_assactid;
8645
8646 exception
8647 when no_data_found then
8648 return -9999;
8649
8650 when too_many_rows then
8651 hr_utility.set_message(801,'HR_34864_INTERLOCK_ERR_REV');
8652 hr_utility.raise_error;
8653
8654 end;
8655
8656 exception
8657 when no_data_found then
8658 return l_mst_id;
8659
8660 end;
8661 --
8662
8663 procedure ins_dummy_quickpay_action(p_assignment_id in number,
8664 p_consolidation_set_id in number,
8665 p_run_type_id in number,
8666 p_effective_date in date )
8667 is
8668 v_payroll_action_id number;
8669 v_business_group_id number;
8670 v_p_object_version_number number;
8671 v_assignment_action_id number;
8672 v_a_object_version_number number;
8673 v_r_mode varchar2(5);
8674 begin
8675 hr_utility.set_location ('Entered ins_dummy_quickpay_action', 10);
8676 hr_utility.trace ('Assignment id is :'||p_assignment_id);
8677 hr_utility.trace ('p_consolidation_set_id is :'||p_consolidation_set_id);
8678 hr_utility.trace ('p_run_type_id is :'||p_run_type_id);
8679
8680 begin
8681 SELECT business_group_id
8682 into v_business_group_id
8683 FROM per_all_assignments_f
8684 WHERE assignment_id = p_assignment_id
8685 AND p_effective_date BETWEEN effective_start_date AND effective_end_date ;
8686 exception
8687 when no_data_found then
8688 hr_utility.set_message(801, 'HR_7244_QPAY_NO_PAY_D_EFF');
8689 hr_utility.raise_error;
8690 end;
8691
8692 hr_utility.trace ('v_business_group_id is :'||v_business_group_id);
8693
8694
8695 /*setting this variable to avoid the interlock failure error in quickpay action creation */
8696 hrassact.gv_dum_qpay := TRUE ;
8697
8698 hr_utility.set_location ('hrassact.ins_dummy_quickpay_action', 20);
8699
8700 /*Call the following function to insert a quickpay payroll action*/
8701 pay_qpq_api.ins
8702 (
8703 p_business_group_id => v_business_group_id
8704 ,p_assignment_id => p_assignment_id
8705 ,p_consolidation_set_id => p_consolidation_set_id
8706 ,p_effective_date => p_effective_date
8707 ,p_run_type_id => p_run_type_id
8708 ,p_date_earned => p_effective_date
8709 ,p_payroll_action_id => v_payroll_action_id
8710 ,p_p_object_version_number => v_p_object_version_number
8711 ,p_assignment_action_id => v_assignment_action_id
8712 ,p_a_object_version_number => v_a_object_version_number
8713 );
8714
8715 hr_utility.trace ('v_payroll_action_id:'||v_payroll_action_id);
8716 hr_utility.trace ('v_assignment_action_id'||v_assignment_action_id);
8717
8718 hrassact.gv_dum_qpay := FALSE ;
8719 hr_utility.set_location ('hrassact.ins_dummy_quickpay_action', 30);
8720
8721 if v_payroll_action_id is not null and v_assignment_action_id is not null then
8722 /*Inserting the action sequence in pay_payroll_actions since
8723 it is not inserted by the previous called api
8724 also inserting the batch_process_mode as DUM_QPAY to indicate
8725 the payrollaction is inserted using this code*/
8726
8727 update pay_payroll_actions
8728 set action_sequence = pay_payroll_actions_s.nextval,
8729 batch_process_mode = 'DUM_QPAY'
8730 where payroll_action_id = v_payroll_action_id
8731 and action_sequence is null;
8732
8733 hr_utility.set_location ('hrassact.ins_dummy_quickpay_action', 40);
8734
8735 -- get the rule_mode
8736 begin
8737 select /*+ ORDERED*/ plr.rule_mode
8738 into v_r_mode
8739 from per_business_groups_perf grp,
8740 pay_legislation_rules plr
8741 where grp.business_group_id = v_business_group_id
8742 and plr.legislation_code = grp.legislation_code
8743 and plr.rule_type = 'I'
8744 and plr.rule_mode in ('Y','N','G');
8745 exception
8746 when no_data_found then
8747 v_r_mode := 'N';
8748 end;
8749
8750 hr_utility.set_location ('hrassact.ins_dummy_quickpay_action', 50);
8751 /*Resequencing the assignment actions*/
8752 hrassact.resequence_actions
8753 (
8754 aaid => v_assignment_action_id,
8755 rmode => v_r_mode ,
8756 chldact => 'Y', -- need to verify whether resequencing of child actions is required or not
8757 actype => 'Q'
8758 );
8759
8760 hr_utility.set_location ('hrassact.ins_dummy_quickpay_action', 60);
8761 /*Updating the action status of assignment action to complete*/
8762
8763 update pay_assignment_actions
8764 set ACTION_STATUS = 'C'
8765 where assignment_action_id = v_assignment_action_id;
8766
8767 hr_utility.set_location ('hrassact.ins_dummy_quickpay_action', 70);
8768 /*Updating the payroll action status as complete*/
8769
8770 update pay_payroll_actions
8771 set action_status = 'C'
8772 where payroll_action_id = v_payroll_action_id;
8773
8774 hr_utility.set_location ('hrassact.ins_dummy_quickpay_action', 80);
8775 end if;
8776
8777 end;
8778 --
8779 end hrassact;