DBA Data[Home] [Help]

PACKAGE BODY: APPS.HR_PERF_MGMT_PLAN_INTERNAL

Source


1 PACKAGE BODY hr_perf_mgmt_plan_internal AS
2 	/* $Header: pepmpbsi.pkb 120.94.12020000.6 2013/03/18 10:44:20 schowdhu ship $ */
3 	  -- Package Variables
4 	  -- Package Variables
5 	  --
6 	   g_package                     VARCHAR2 (33)                               := 'hr_perf_mgmt_plan_internal.';
7 	   g_debug                       BOOLEAN                                     := hr_utility.debug_enabled;
8 	   g_num_errors                  NUMBER                                      := 0;
9 	   g_max_errors                  NUMBER;
10 	   --
11 	   -- Proprietory debugging. Allows for concurrent request output, etc.
12 	   -- (see procedures "op").
13 	   --
14 	   g_dbg                         BOOLEAN                                     := g_debug;
15 	   g_dbg_type                    NUMBER                                      := g_no_debug;
16 	   g_log_level                   VARCHAR2 (1)                                := g_regular_log;
17 	   --
18 	   --
19 	   -- Package (private) constants.
20 	   --
21 	   LOGGING              CONSTANT pay_action_parameters.parameter_name%TYPE   := 'LOGGING';
22 	   max_errors           CONSTANT pay_action_parameters.parameter_name%TYPE   := 'MAX_ERRORS_ALLOWED';
23 	   NEWLINE              CONSTANT VARCHAR2 (10)                               := fnd_global.NEWLINE;
24 	   tab                  CONSTANT VARCHAR2 (30)                               := fnd_global.tab;
25 	   --
26 	   g_error_txt                   VARCHAR2 (32000);
27 	   g_cp_error_txt                VARCHAR2 (32000);
28 
29 	   --
30 
31 	   --
32 	   -- Private user-defined types.
33 	   --
34 
35 	   -- Used for populating Plan Population
36 	   TYPE g_qual_pop_r IS RECORD (
37 		  assignment_id              per_all_assignments_f.assignment_id%TYPE,
38 		  person_id                  per_all_assignments_f.person_id%TYPE,
39 		  business_group_id          per_all_assignments_f.business_group_id%TYPE,
40 		  supervisor_id              per_all_assignments_f.supervisor_id%TYPE,
41 		  supervisor_assignment_id   per_all_assignments_f.supervisor_assignment_id%TYPE,
42 		  organization_id            per_all_assignments_f.organization_id%TYPE,
43 		  position_id                per_all_assignments_f.position_id%TYPE
44 	   );
45 
46 	   TYPE g_qual_pop_t IS TABLE OF g_qual_pop_r
47 		  INDEX BY BINARY_INTEGER;
48 
49 	   g_qual_pop_tbl                g_qual_pop_t;
50 
51 	   -- Used for populating existing scorecard population
52 	   TYPE g_curr_sc_pop_r IS RECORD (
53 		  assignment_id           per_personal_scorecards.assignment_id%TYPE,
54 		  scorecard_id            per_personal_scorecards.scorecard_id%TYPE,
55 		  object_version_number   per_personal_scorecards.object_version_number%TYPE,
56 		  status_code             per_personal_scorecards.status_code%TYPE
57 	   );
58 
59 	   TYPE g_curr_sc_pop_t IS TABLE OF g_curr_sc_pop_r
60 		  INDEX BY BINARY_INTEGER;
61 
62 	   g_curr_sc_pop_tbl             g_curr_sc_pop_t;
63 
64 	   -- Used for populating qualifying objectives
65 	   TYPE g_qual_obj_r IS RECORD (
66 		  objective_id             per_objectives_library.objective_id%TYPE,
67 		  objective_name           per_objectives_library.objective_name%TYPE,
68 		  valid_from               per_objectives_library.valid_from%TYPE,
69 		  valid_to                 per_objectives_library.valid_to%TYPE,
70 		  target_date              per_objectives_library.target_date%TYPE,
71 		  next_review_date         per_objectives_library.next_review_date%TYPE,
72 		  group_code               per_objectives_library.group_code%TYPE,
73 		  priority_code            per_objectives_library.priority_code%TYPE,
74 		  appraise_flag            per_objectives_library.appraise_flag%TYPE,
75 		  weighting_percent        per_objectives_library.weighting_percent%TYPE,
76 		  target_value             per_objectives_library.target_value%TYPE,
77 		  uom_code                 per_objectives_library.uom_code%TYPE,
78 		  measurement_style_code   per_objectives_library.measurement_style_code%TYPE,
79 		  measure_name             per_objectives_library.measure_name%TYPE,
80 		  measure_type_code        per_objectives_library.measure_type_code%TYPE,
81 		  measure_comments         per_objectives_library.measure_comments%TYPE,
82 		  details                  per_objectives_library.details%TYPE,
83 		  success_criteria         per_objectives_library.success_criteria%TYPE,
84 		  comments                 per_objectives_library.comments%TYPE,
85 		  elig_obj_id              ben_elig_obj_f.elig_obj_id%TYPE
86 	   );
87 
88 	   TYPE g_qual_obj_t IS TABLE OF g_qual_obj_r
89 		  INDEX BY BINARY_INTEGER;
90 
91 	   g_qual_obj_tbl                g_qual_obj_t;
92 
93 	   -- User for populating existing scorecard objectives
94 	   TYPE g_curr_sc_obj_r IS RECORD (
95 		  copied_from_library_id   per_objectives.copied_from_library_id%TYPE,
96 		  objective_id             per_objectives.objective_id%TYPE,
97 		  object_version_number    per_objectives.object_version_number%TYPE
98 	   );
99 
100 	   TYPE g_curr_sc_obj_t IS TABLE OF g_curr_sc_obj_r
101 		  INDEX BY BINARY_INTEGER;
102 
103 	   g_curr_sc_obj_tbl             g_curr_sc_obj_t;
104 
105 	   -- User for populating plan appraisal periods
106 	   TYPE g_plan_aprsl_pds_r IS RECORD (
107 		  appraisal_period_id      per_appraisal_periods.appraisal_period_id%TYPE,
108 		  appraisal_template_id    per_appraisal_periods.appraisal_template_id%TYPE,
109 		  start_date               per_appraisal_periods.start_date%TYPE,
110 		  end_date                 per_appraisal_periods.end_date%TYPE,
111 		  task_start_date          per_appraisal_periods.task_start_date%TYPE,
112 		  task_end_date            per_appraisal_periods.task_end_date%TYPE,
113 		  initiator_code           per_appraisal_periods.initiator_code%TYPE,
114 		  appraisal_system_type    per_appraisal_periods.appraisal_system_type%TYPE,
115 		  auto_conc_process        per_appraisal_periods.auto_conc_process%TYPE,
116 		  days_before_task_st_dt   per_appraisal_periods.days_before_task_st_dt%TYPE,
117 		  appraisal_assmt_status   per_appraisal_periods.appraisal_assmt_status%TYPE,
118 		  appraisal_type           per_appraisal_periods.appraisal_type%TYPE
119 	   );
120 
121 	   TYPE g_plan_aprsl_pds_t IS TABLE OF g_plan_aprsl_pds_r
122 		  INDEX BY BINARY_INTEGER;
123 
124 	   g_plan_aprsl_pds_tbl          g_plan_aprsl_pds_t;
125 
126 	   --
127 	   TYPE g_boolean_t IS TABLE OF BOOLEAN
128 		  INDEX BY BINARY_INTEGER;
129 
130 	   g_plan_pop_known_t            g_boolean_t;
131 	   g_fetched_plan_member_index   NUMBER;
132 
133 	   --
134 	   TYPE scorecard_info IS RECORD (
135 		  scorecard_id     per_personal_scorecards.scorecard_id%TYPE,
136 		  assignment_id    per_personal_scorecards.assignment_id%TYPE,
137 		  person_id        per_personal_scorecards.person_id%TYPE,
138 		  scorecard_name   per_personal_scorecards.scorecard_name%TYPE
139 	   );
140 
141 	   TYPE assignment_info IS RECORD (
142 		  assignment_id          per_all_assignments_f.assignment_id%TYPE,
143 		  business_group_id      per_all_assignments_f.business_group_id%TYPE,
144 		  grade_id               per_all_assignments_f.grade_id%TYPE,
145 		  position_id            per_all_assignments_f.position_id%TYPE,
146 		  job_id                 per_all_assignments_f.job_id%TYPE,
147 		  org_id                 per_all_assignments_f.organization_id%TYPE,
148 		  supervisor_id          per_all_assignments_f.supervisor_id%TYPE,
149 		  effective_state_date   per_all_assignments_f.effective_start_date%TYPE
150 	   );
151 
152 	   TYPE appraisal_templ_info IS RECORD (
153 		  appraisal_template_id     per_appraisal_templates.appraisal_template_id%TYPE,
154 		  assessment_type_id        per_appraisal_templates.assessment_type_id%TYPE,
155 		  objective_asmnt_type_id   per_appraisal_templates.objective_asmnt_type_id%TYPE,
156 		  business_group_id         per_appraisal_templates.business_group_id%TYPE
157 	   );
158 
159 	   TYPE assess_comps_info IS RECORD (
160 		  competence_id                  per_competence_elements.competence_id%TYPE,
161 		  competence_element_id          per_competence_elements.competence_element_id%TYPE,
162 		  TYPE                           per_competence_elements.TYPE%TYPE,
163 		  parent_competence_element_id   per_competence_elements.parent_competence_element_id%TYPE,
164 		  NAME                           per_competences_vl.NAME%TYPE,
165 		  RANK                           NUMBER
166 	   );
167 
168 	   TYPE bus_rules_comps IS RECORD (
169 		  NAME                        per_competences_vl.NAME%TYPE,
170 		  competence_id               per_competences.competence_id%TYPE,
171 		  competence_element_id       per_competence_elements.competence_element_id%TYPE,
172 		  mandatory                   per_competence_elements.mandatory%TYPE,
173 		  proficiency_level_id        per_competence_elements.proficiency_level_id%TYPE,
174 		  high_proficiency_level_id   per_competence_elements.high_proficiency_level_id%TYPE,
175 		  organization_id             per_competence_elements.organization_id%TYPE,
176 		  job_id                      per_competence_elements.job_id%TYPE,
177 		  position_id                 per_competence_elements.position_id%TYPE,
178 		  valid_grade_id              per_competence_elements.valid_grade_id%TYPE,
179 		  business_group_id           per_competence_elements.business_group_id%TYPE,
180 		  enterprise_id               per_competence_elements.enterprise_id%TYPE,
181 		  structure_type              hr_lookups.meaning%TYPE,
182 		  read_only_attr              NUMBER,
183 		  detail_attr                 NUMBER,
184 		  competence_alias            per_competences.competence_alias%TYPE,
185 		  GLOBAL                      VARCHAR2 (1),
186 		  description                 per_competences.description%TYPE,
187 		  date_from                   per_competences.date_from%TYPE,
188 		  certification_required      per_competences.certification_required%TYPE,
189 		  behavioural_indicator       per_competences.behavioural_indicator%TYPE,
190 		  low_step_value              per_rating_levels_vl.step_value%TYPE,
191 		  low_step_name               per_rating_levels_vl.NAME%TYPE,
192 		  high_step_value             per_rating_levels_vl.step_value%TYPE,
193 		  high_step_name              per_rating_levels_vl.NAME%TYPE,
194 		  lookup_code                 hr_lookups.lookup_code%TYPE,
195 		  minimum_proficiency         VARCHAR2 (100),
196 		  maximum_proficiency         VARCHAR2 (100),
197 		  TYPE                        per_competence_elements.TYPE%TYPE
198 	   );
199 
200 	   TYPE sel_comp_tab IS TABLE OF bus_rules_comps
201 		  INDEX BY BINARY_INTEGER;
202 
203 	   TYPE competences_rc IS RECORD (
204 		  competence_id   per_competences.competence_id%TYPE
205 	   );
206 
207 	   TYPE competences_tbl IS TABLE OF competences_rc
208 		  INDEX BY BINARY_INTEGER;
209 
210 	   TYPE appr_prds_rc IS RECORD (
211 		  appraisal_period_id     per_appraisal_periods.appraisal_period_id%TYPE,
212 		  appraisal_template_id   per_appraisal_periods.appraisal_template_id%TYPE,
213 		  business_group_id       per_appraisal_templates.business_group_id%TYPE
214 	   );
215 
216 	   TYPE appr_prds_tbl IS TABLE OF appr_prds_rc
217 		  INDEX BY BINARY_INTEGER;
218 
219 	   -- added for PERF ADMIN ACTIONS
220 	   TYPE t_selected_entities IS TABLE OF NUMBER
221 		  INDEX BY BINARY_INTEGER;
222 
223 	   g_selected_entities           t_selected_entities;
224 
225 	   TYPE t_plan_rec IS TABLE OF per_perf_mgmt_plans%ROWTYPE
226 		  INDEX BY BINARY_INTEGER;
227 
228 	   g_plan_rec                    t_plan_rec;
229 	   g_plan_dtls                   t_plan_rec;
230 	   g_appraisals_exist            VARCHAR2 (1)                                := 'N';
231 	   g_target_sc_id                NUMBER (15);
232 	   g_target_appr_id              NUMBER (15);
233 
234 	   -- END Changes for PERF ADMIN ACTIONS
235 	--
236 	   PROCEDURE log_message (p_message_text IN VARCHAR2)
237 	   IS
238 	   BEGIN
239 		  IF fnd_global.conc_request_id = -1
240 		  THEN
241 			 hr_utility.trace (SUBSTR (p_message_text, 1, 200));
242 			 hr_utility.trace (SUBSTR (p_message_text, 201, 200));
243 		  ELSE
244 			 fnd_file.put_line (fnd_file.LOG, p_message_text);
245 		  END IF;
246 	   END log_message;
247 
248 	--
249 	   -- This procedure is added as part of fix for bug#7392154. this will raise an
250 	-- for all the Supervisor hierarchy based plans when the topmost supervisor
251 	-- is terminated.
252 	--
253 	-- ----------------------------------------------------------------------------
254 	-- |----------------------< chk_top_supervisor >------------------------------|
255 	-- ----------------------------------------------------------------------------
256 	--
257 	--
258 	   PROCEDURE chk_top_supervisor (p_plan_id IN NUMBER)
259 	   IS
260 		  l_proc        VARCHAR2 (80)                 := g_package || 'chk_top_supervisor';
261 
262 		  CURSOR csr_plan_supervisor (p_plan_id IN NUMBER)
263 		  IS
264 			 SELECT hierarchy_type_code, supervisor_id, supervisor_assignment_id, assignment_types_code
265 			   FROM per_perf_mgmt_plans
266 			  WHERE plan_id = p_plan_id;
267 
268 		  l_plan_dtls   csr_plan_supervisor%ROWTYPE;
269 
270 	--
271 		  CURSOR csr_chk_emp_sup (p_supervisor_id IN NUMBER)
272 		  IS
273 			 SELECT 'Y'
274 			   FROM DUAL
275 			  WHERE EXISTS (
276 					   SELECT 'x'
277 						 FROM per_all_people_f ppf, per_periods_of_service pps
278 						WHERE ppf.person_id = p_supervisor_id
279 						  AND TRUNC (SYSDATE) BETWEEN ppf.effective_start_date AND ppf.effective_end_date
280 						  AND ppf.person_id = pps.person_id
281 						  AND TRUNC (SYSDATE) BETWEEN pps.date_start AND NVL (pps.actual_termination_date, TRUNC (SYSDATE)));
282 
283 	--
284 		  CURSOR csr_chk_emp_sup_asg (p_supervisor_asg_id IN NUMBER)
285 		  IS
286 			 SELECT 'Y'
287 			   FROM DUAL
288 			  WHERE EXISTS (
289 					   SELECT 'x'
290 						 FROM per_all_assignments_f paaf, per_periods_of_service pps
291 						WHERE paaf.assignment_id = p_supervisor_asg_id
292 						  AND TRUNC (SYSDATE) BETWEEN paaf.effective_start_date AND paaf.effective_end_date
293 						  AND paaf.period_of_service_id = pps.period_of_service_id
294 						  AND TRUNC (SYSDATE) BETWEEN pps.date_start AND NVL (pps.actual_termination_date, TRUNC (SYSDATE)));
295 
296 	--
297 		  CURSOR csr_chk_cwk_sup (p_supervisor_id IN NUMBER)
298 		  IS
299 			 SELECT 'Y'
300 			   FROM DUAL
301 			  WHERE EXISTS (
302 					   SELECT 'x'
303 						 FROM per_all_people_f ppf, per_periods_of_placement ppp
304 						WHERE ppf.person_id = p_supervisor_id
305 						  AND TRUNC (SYSDATE) BETWEEN ppf.effective_start_date AND ppf.effective_end_date
306 						  AND ppf.person_id = ppp.person_id
307 						  AND TRUNC (SYSDATE) BETWEEN ppp.date_start AND NVL (ppp.actual_termination_date, TRUNC (SYSDATE)));
308 
309 	--
310 		  CURSOR csr_chk_cwk_sup_asg (p_supervisor_asg_id IN NUMBER)
311 		  IS
312 			 SELECT 'Y'
313 			   FROM DUAL
314 			  WHERE EXISTS (
315 					   SELECT 'x'
316 						 FROM per_all_assignments_f paaf, per_periods_of_placement ppp
317 						WHERE paaf.assignment_id = p_supervisor_asg_id
318 						  AND TRUNC (SYSDATE) BETWEEN paaf.effective_start_date AND paaf.effective_end_date
319 						  AND paaf.person_id = ppp.person_id
320 						  AND paaf.period_of_placement_date_start = ppp.date_start
321 						  AND TRUNC (SYSDATE) BETWEEN ppp.date_start AND NVL (ppp.actual_termination_date, TRUNC (SYSDATE)));
322 
323 		  l_valid_sup   VARCHAR2 (1);
324 	   BEGIN
325 		  hr_utility.set_location ('Entering:' || l_proc, 10);
326 		  l_valid_sup := 'N';
327 
328 		  IF p_plan_id IS NULL
329 		  THEN
330 			 log_message ('Plan ID is passed as null, leaving.' || l_proc);
331 			 hr_api.mandatory_arg_error (p_api_name => l_proc, p_argument => 'P_PLAN_ID', p_argument_value => p_plan_id);
332 		  END IF;
333 
334 		  OPEN csr_plan_supervisor (p_plan_id);
335 
336 		  FETCH csr_plan_supervisor
337 		   INTO l_plan_dtls;
338 
339 		  IF csr_plan_supervisor%NOTFOUND
340 		  THEN
341 			 CLOSE csr_plan_supervisor;
342 
343 			 hr_utility.set_location ('Not a valid plan_id value passed. Exiting.' || l_proc, 20);
344 			 hr_utility.raise_error;
345 		  END IF;
346 
347 		  CLOSE csr_plan_supervisor;
348 
349 		  IF l_plan_dtls.hierarchy_type_code = 'SUP' OR l_plan_dtls.hierarchy_type_code = 'SUP_ASG'
350 		  THEN
351 			 IF l_plan_dtls.hierarchy_type_code = 'SUP'
352 			 THEN
353 				IF l_plan_dtls.assignment_types_code IN ('E', 'EC')
354 				THEN
355 				   OPEN csr_chk_emp_sup (l_plan_dtls.supervisor_id);
356 
357 				   FETCH csr_chk_emp_sup
358 					INTO l_valid_sup;
359 
360 				   IF csr_chk_emp_sup%FOUND
361 				   THEN
362 					  log_message ('Valid Supervisor, so existing' || l_proc);
363 
364 					  CLOSE csr_chk_emp_sup;
365 
366 					  RETURN;
367 				   END IF;
368 
369 				   CLOSE csr_chk_emp_sup;
370 				END IF;                                                                                         -- assignment_type='E'
371 
372 				IF l_plan_dtls.assignment_types_code IN ('C', 'EC')
373 				THEN
374 				   OPEN csr_chk_cwk_sup (l_plan_dtls.supervisor_id);
375 
376 				   FETCH csr_chk_cwk_sup
377 					INTO l_valid_sup;
378 
379 				   IF csr_chk_cwk_sup%FOUND
380 				   THEN
381 					  log_message ('Valid Supervisor, so existing' || l_proc);
382 
383 					  CLOSE csr_chk_cwk_sup;
384 
385 					  RETURN;
386 				   END IF;
387 
388 				   CLOSE csr_chk_cwk_sup;
389 				END IF;
390 
391 				log_message ('l_valid_sup' || l_valid_sup || '-' || l_proc);
392 
393 				IF NVL (l_valid_sup, 'N') <> 'Y'
394 				THEN
395 				   hr_utility.set_message (800, 'HR_50436_WPM_TERM_SUPERVISOR');                                     ---  new message
396 				   hr_utility.set_location ('Top supervisor for the plan terminated. Exiting.' || l_proc, 30);
397 				   hr_utility.raise_error;
398 				END IF;
399 			 ELSE                                                                                                          -- SUP_ASG.
400 				IF l_plan_dtls.assignment_types_code IN ('E', 'EC')
401 				THEN
402 				   OPEN csr_chk_emp_sup_asg (l_plan_dtls.supervisor_assignment_id);
403 
404 				   FETCH csr_chk_emp_sup_asg
405 					INTO l_valid_sup;
406 
407 				   IF csr_chk_emp_sup_asg%FOUND
408 				   THEN
409 					  log_message ('Valid Supervisor, so existing' || l_proc);
410 
411 					  CLOSE csr_chk_emp_sup_asg;
412 
413 					  RETURN;
414 				   END IF;
415 
416 				   CLOSE csr_chk_emp_sup_asg;
417 				END IF;                                                                                         -- assignment_type='E'
418 
419 				IF l_plan_dtls.assignment_types_code IN ('C', 'EC')
420 				THEN
421 				   OPEN csr_chk_cwk_sup_asg (l_plan_dtls.supervisor_assignment_id);
422 
423 				   FETCH csr_chk_cwk_sup_asg
424 					INTO l_valid_sup;
425 
426 				   IF csr_chk_cwk_sup_asg%FOUND
427 				   THEN
428 					  log_message ('Valid Supervisor, so existing' || l_proc);
429 
430 					  CLOSE csr_chk_cwk_sup_asg;
431 
432 					  RETURN;
433 				   END IF;
434 
435 				   CLOSE csr_chk_cwk_sup_asg;
436 				END IF;
437 
438 				log_message ('l_valid_sup' || l_valid_sup || '-' || l_proc);
439 
440 				IF NVL (l_valid_sup, 'N') <> 'Y'
441 				THEN
442 				   hr_utility.set_message (800, 'HR_50436_WPM_TERM_SUPERVISOR');                                     ---  new message
443 				   hr_utility.set_location ('Top supervisor for the plan terminated. Exiting.' || l_proc, 30);
444 				   hr_utility.raise_error;
445 				END IF;
446 			 END IF;
447 		  ELSE
448 			 hr_utility.set_location ('Not a supervisor hierarchy type plan. So no validation performed.' || l_proc, 80);
449 		  END IF;
450 
451 		  hr_utility.set_location ('Leaving:' || l_proc, 100);
452 	   END chk_top_supervisor;
453 
454 	--
455 	-- ----------------------------------------------------------------------------
456 	-- |----------------------< initialize_logging >------------------------------|
457 	-- ----------------------------------------------------------------------------
458 	--
459 	   PROCEDURE initialize_logging (p_action_parameter_group_id IN NUMBER, p_log_output IN VARCHAR2)
460 	   IS
461 		  --
462 		  -- Gets an action parameter value.
463 		  --
464 		  CURSOR csr_get_action_param (p_parameter_name IN VARCHAR2)
465 		  IS
466 			 SELECT pap.parameter_value
467 			   FROM pay_action_parameters pap
468 			  WHERE pap.parameter_name = p_parameter_name;
469 
470 		  l_logging      pay_action_parameters.parameter_value%TYPE;
471 		  l_max_errors   pay_action_parameters.parameter_value%TYPE;
472 		  l_string       VARCHAR2 (500);
473 	   BEGIN
474 		  --
475 		  -- Reset the package globals.
476 		  --
477 		  g_errbuf := NULL;
478 		  g_retcode := success;
479 		  g_max_errors := 0;
480 		  g_error_txt := '';
481 
482 		  --
483 		  -- If the action parameter ID is passed in, the action param group
484 		  -- is set.  Native dynamic PL/SQL is used to eliminate the
485 		  -- the dependency on the pay package procedure.
486 
487 		  -- This option we disabled because thriough application we pass explicit null
488 		   -- but when run through concurrent program this validation can fail
489 		   -- so keeping at par with application submit of cp we bypass this validation.
490 		  /* IF p_action_parameter_group_id IS NOT NULL THEN
491 
492 			   l_string :=
493 				   'BEGIN
494 						pay_core_utils.set_pap_group_id(p_pap_group_id => ' ||
495 							to_char(p_action_parameter_group_id) || ');
496 					END;';
497 
498 			   EXECUTE IMMEDIATE l_string;
499 
500 		   END IF;*/
501 
502 		  --
503 		  IF (p_log_output = 'Y' AND fnd_global.conc_request_id > 0)
504 		  THEN
505 			 -- Call from concurrent program
506 			 g_dbg := TRUE;
507 			 g_dbg_type := g_fnd_log;
508 
509 			 --
510 			 -- Get the Payroll Action logging parameter
511 			 --
512 			 OPEN csr_get_action_param (LOGGING);
513 
514 			 FETCH csr_get_action_param
515 			  INTO l_logging;
516 
517 			 CLOSE csr_get_action_param;
518 
519 			 --
520 			 -- If logging is set to General in Payroll Action parameters, enable debugging.
521 			 --
522 			 IF (INSTR (NVL (l_logging, 'N'), 'G') <> 0)
523 			 THEN
524 				g_log_level := g_debug_log;
525 			 ELSE
526 				g_log_level := g_regular_log;
527 			 END IF;
528 		  ELSIF (p_log_output <> 'Y')
529 		  THEN
530 			 -- Call from API
531 			 IF (g_debug)
532 			 THEN
533 				g_dbg := TRUE;
534 				g_dbg_type := g_pipe;
535 				g_log_level := g_debug_log;
536 			 END IF;
537 		  END IF;
538 
539 		  --
540 		  -- Set the max number of errors allowed.
541 		  --
542 		  OPEN csr_get_action_param (max_errors);
543 
544 		  FETCH csr_get_action_param
545 		   INTO l_max_errors;
546 
547 		  CLOSE csr_get_action_param;
548 
549 		  g_max_errors := NVL (TO_NUMBER (l_max_errors), 0);
550 	   END initialize_logging;
551 
552 	--
553 	-- ----------------------------------------------------------------------------
554 	-- |----------------------< op >----------------------------------------------|
555 	-- ----------------------------------------------------------------------------
556 	--
557 	   PROCEDURE op (p_msg IN VARCHAR2, p_log_level IN NUMBER, p_location IN NUMBER DEFAULT NULL)
558 	   IS
559 		  l_msg   VARCHAR2 (32000) := p_msg;
560 	   BEGIN
561 		  IF (g_dbg_type IS NOT NULL AND p_msg IS NOT NULL AND p_log_level <= g_log_level)
562 		  THEN
563 			 --
564 			 -- Break the output into chunks of 70 characters.
565 			 --
566 			 WHILE LENGTH (l_msg) > 0
567 			 LOOP
568 				IF g_dbg_type = g_pipe OR g_debug
569 				THEN
570 				   IF p_location IS NOT NULL
571 				   THEN
572 					  hr_utility.set_location (SUBSTR (l_msg, 1, 70), p_location);
573 				   ELSE
574 					  log_message (SUBSTR (l_msg, 1, 70));
575 				   END IF;
576 				ELSIF g_dbg_type = g_fnd_log
577 				THEN
578 				   IF p_location IS NOT NULL
579 				   THEN
580 					  fnd_file.put_line (fnd_file.LOG, SUBSTR (l_msg, 1, 70) || ', ' || TO_CHAR (p_location));
581 				   ELSE
582 					  fnd_file.put_line (fnd_file.LOG, SUBSTR (l_msg, 1, 70));
583 				   END IF;
584 				ELSIF fnd_global.conc_request_id = -1 THEN
585 					log_message(l_msg);
586 				END IF;
587 
588 				l_msg := SUBSTR (l_msg, 71);
589 			 END LOOP;
590 		  END IF;
591 	   END op;
592 
593 	--
594 	-- ----------------------------------------------------------------------------
595 	-- |-------------------------< chk_publishing_status >------------------------|
596 	-- ----------------------------------------------------------------------------
597 	-- {Start Of Comments}
598 	--
599 	-- Description:
600 	--   Checks that the status code is a valid for Publish o Reverse Publish plan
601 	--   action.
602 	--
603 	-- Prerequisites:
604 	--   None.
605 	--
606 	-- In Arguments:
607 	--
608 	--
609 	-- Post Success:
610 	--  Processing continues if the status is valid.
611 	--
612 	-- Post Failure:
613 	--  An application error is raised if the status code is not valid.
614 	--
615 	-- Access Status:
616 	--   Internal Only.
617 	--
618 	-- {End Of Comments}
619 	-- ----------------------------------------------------------------------------
620 	   PROCEDURE chk_publishing_status (p_reverse_mode IN VARCHAR2, p_status_code IN VARCHAR2)
621 	   IS
622 		  -- Declare local variables
623 		  l_proc                  VARCHAR2 (72) := g_package || 'chk_publishing_status';
624 		  e_status_check_failed   EXCEPTION;
625 	   BEGIN
626 		  --
627 		  IF g_dbg
628 		  THEN
629 			 op ('Entering:' || l_proc, g_regular_log, 10);
630 		  END IF;
631 
632 		  --
633 		  IF (p_reverse_mode = 'N' AND p_status_code NOT IN ('DRAFT', 'UPDATED', 'SUBMITTED', 'RESUBMITTED'))
634 		  THEN
635 			 -- Set the message name, so that exception handler can get translated text
636 			 IF g_dbg
637 			 THEN
638 				op (l_proc, g_debug_log, 20);
639 			 END IF;
640 
641 			 fnd_message.set_name ('PER', 'HR_50294_WPM_INV_PLAN_STS_PUB');
642 			 g_error_txt := NVL (fnd_message.get, 'HR_50294_WPM_INV_PLAN_STS_PUB');
643 			 RAISE e_status_check_failed;
644 		  ELSIF (p_reverse_mode <> 'N' AND p_status_code NOT IN ('PUBLISHED'))
645 		  THEN
646 			 -- Set the message name, so that exception handler can get translated text
647 			 IF g_dbg
648 			 THEN
649 				op (l_proc, g_debug_log, 30);
650 			 END IF;
651 
652 			 fnd_message.set_name ('PER', 'HR_50295_WPM_INV_PLAN_STS_RPUB');
653 			 g_error_txt := NVL (fnd_message.get, 'HR_50295_WPM_INV_PLAN_STS_RPUB');
654 			 RAISE e_status_check_failed;
655 		  END IF;
656 
657 		  --
658 		  IF g_dbg
659 		  THEN
660 			 op ('Leaving:' || l_proc, g_regular_log, 80);
661 		  END IF;
662 	   --
663 	   EXCEPTION
664 		  WHEN OTHERS
665 		  THEN
666 			 IF g_dbg
667 			 THEN
668 				op ('Leaving:' || l_proc, g_regular_log, 90);
669 			 END IF;
670 
671 			 --
672 			 g_retcode := warning;
673 			 g_errbuf := g_error_txt;
674 
675 			 IF g_dbg
676 			 THEN
677 				op (g_error_txt, g_regular_log);
678 			 END IF;
679 
680 			 IF g_dbg
681 			 THEN
682 				op (SQLERRM, g_regular_log);
683 			 END IF;
684 
685 			 RAISE;
686 	   END chk_publishing_status;
687 
688 	--
689 	-- ----------------------------------------------------------------------------
690 	-- |---------------------< populate_qual_plan_population >---------------------|
691 	-- ----------------------------------------------------------------------------
692 	-- {Start Of Comments}
693 	--
694 	-- Description:
695 	--   Populate the qualifying plan population and loads in cache(i.e. PLSQL table
696 	--    with index as assignment id and other values.
697 	--
698 	-- Prerequisites:
699 	--   None.
700 	--
701 	-- In Arguments:
702 	--
703 	--
704 	-- Post Success:
705 	--  Processing continues on successful population.
706 	--
707 	-- Post Failure:
708 	--  An application error is raised if population fails.
709 
710 	   --
711 	-- Access Status:
712 	--   Internal Use Only.
713 	--
714 	-- {End Of Comments}
715 	-- ----------------------------------------------------------------------------
716 	   PROCEDURE populate_qual_plan_population (p_plan_rec IN per_perf_mgmt_plans%ROWTYPE, p_effective_date IN DATE)
717 	   IS
718 		  -- Declare local variables
719 		  l_proc                   VARCHAR2 (72)                                    := g_package || 'populate_qual_plan_population';
720 		  l_temp_pop_tbl           g_qual_pop_t;
721 
722 		  -- Supervisor Hierarchy population
723 		  -- Includes supervisor assignment and person assignments that are in not more than N level
724 		  -- below in hierarchy, where N is the value specified in hierarchy level attribute of the plan
725 		  --
726 		  CURSOR csr_sup_hier_pop
727 		  IS
728 			 SELECT     *
729 				   FROM (SELECT asg.assignment_id, asg.person_id, asg.business_group_id, asg.supervisor_id,
730 								asg.supervisor_assignment_id, asg.organization_id, asg.position_id
731 						   FROM per_all_assignments_f asg
732 						  WHERE (   (    p_plan_rec.assignment_types_code IN ('E', 'C')
733 									 AND asg.assignment_type = p_plan_rec.assignment_types_code
734 									)
735 								 OR (p_plan_rec.assignment_types_code = 'EC' AND asg.assignment_type IN ('E', 'C'))
736 								)
737 							AND p_effective_date BETWEEN asg.effective_start_date AND asg.effective_end_date
738 							AND (   (p_plan_rec.primary_asg_only_flag = 'N')
739 								 OR p_plan_rec.primary_asg_only_flag = 'Y' AND asg.primary_flag = 'Y'
740 								)
741 							AND 'x' =
742 								   (SELECT 'x'
743 									  FROM per_all_people_f ppf
744 									 WHERE asg.person_id = ppf.person_id
745 									   AND p_effective_date BETWEEN ppf.effective_start_date AND ppf.effective_end_date
746 									   AND ('Y' =
747 											   DECODE (p_plan_rec.assignment_types_code,
748 													   'E', ppf.current_employee_flag,
749 													   'C', ppf.current_npw_flag,
750 													   'EC', (SELECT 'Y'
751 																FROM DUAL
752 															   WHERE ppf.current_employee_flag = 'Y' OR ppf.current_npw_flag = 'Y')
753 													  )
754 										   ))) o
755 			 CONNECT BY o.supervisor_id = PRIOR o.person_id AND LEVEL <= NVL (p_plan_rec.hierarchy_levels, LEVEL) + 1
756 			 START WITH o.person_id = p_plan_rec.supervisor_id;
757 
758 		  --  Supervisor Assignment Hierarchy  population
759 		  -- Includes supervisor assignment and person assignments that are in not more than N level
760 		  -- below in hierarchy, where N is the value specified in hierarchy level attribute of the plan
761 		  --
762 		  CURSOR csr_sup_asg_hier_pop
763 		  IS
764 			 SELECT     *
765 				   FROM (SELECT asg.assignment_id, asg.person_id, asg.business_group_id, asg.supervisor_id,
766 								asg.supervisor_assignment_id, asg.organization_id, asg.position_id
767 						   FROM per_all_assignments_f asg
768 						  WHERE (   (    p_plan_rec.assignment_types_code IN ('E', 'C')
769 									 AND asg.assignment_type = p_plan_rec.assignment_types_code
770 									)
771 								 OR (p_plan_rec.assignment_types_code = 'EC' AND asg.assignment_type IN ('E', 'C'))
772 								)
773 							AND p_effective_date BETWEEN asg.effective_start_date AND asg.effective_end_date
774 							AND 'x' =
775 								   (SELECT 'x'
776 									  FROM per_all_people_f ppf
777 									 WHERE asg.person_id = ppf.person_id
778 									   AND p_effective_date BETWEEN ppf.effective_start_date AND ppf.effective_end_date
779 									   AND ('Y' =
780 											   DECODE (p_plan_rec.assignment_types_code,
781 													   'E', ppf.current_employee_flag,
782 													   'C', ppf.current_npw_flag,
783 													   'EC', (SELECT 'Y'
784 																FROM DUAL
785 															   WHERE ppf.current_employee_flag = 'Y' OR ppf.current_npw_flag = 'Y')
786 													  )
787 										   ))) o
788 			 CONNECT BY o.supervisor_assignment_id = PRIOR o.assignment_id AND LEVEL <= NVL (p_plan_rec.hierarchy_levels, LEVEL) + 1
789 			 START WITH o.assignment_id = p_plan_rec.supervisor_assignment_id;
790 
791 		  --  Organization hierarchy population
792 		  -- Includes assignment where assignment organization is top organization or in next N levels of the plan
793 		  -- organization hierarchy, where N is the value specified in hierarchy level attribute of the plan
794 		  --
795 		  CURSOR csr_org_hier_pop
796 		  IS
797 			 SELECT asg.assignment_id, asg.person_id, asg.business_group_id, asg.supervisor_id, asg.supervisor_assignment_id,
798 					asg.organization_id, asg.position_id
799 			   FROM per_all_assignments_f asg
800 			  WHERE (   (p_plan_rec.assignment_types_code IN ('E', 'C') AND asg.assignment_type = 'E')
801 					 OR (p_plan_rec.assignment_types_code = 'EC' AND asg.assignment_type IN ('E', 'C'))
802 					)
803 				AND p_effective_date BETWEEN asg.effective_start_date AND asg.effective_end_date
804 				AND ((p_plan_rec.primary_asg_only_flag = 'N') OR p_plan_rec.primary_asg_only_flag = 'Y' AND asg.primary_flag = 'Y')
805 				AND 'x' =
806 					   (SELECT 'x'
807 						  FROM per_all_people_f ppf
808 						 WHERE asg.person_id = ppf.person_id
809 						   AND p_effective_date BETWEEN ppf.effective_start_date AND ppf.effective_end_date
810 						   AND ('Y' =
811 								   DECODE (p_plan_rec.assignment_types_code,
812 										   'E', ppf.current_employee_flag,
813 										   'C', ppf.current_npw_flag,
814 										   'EC', (SELECT 'Y'
815 													FROM DUAL
816 												   WHERE ppf.current_employee_flag = 'Y' OR ppf.current_npw_flag = 'Y')
817 										  )
818 							   ))
819 				AND asg.organization_id IN (
820 					   SELECT o.organization_id_child
821 						 FROM (SELECT     o.organization_id_child
822 									 FROM per_org_structure_elements o
823 							   CONNECT BY o.organization_id_parent = PRIOR o.organization_id_child
824 									  AND o.org_structure_version_id = PRIOR o.org_structure_version_id
825 									  AND LEVEL <= NVL (p_plan_rec.hierarchy_levels, LEVEL)
826 							   START WITH o.organization_id_parent = p_plan_rec.top_organization_id
827 									  AND o.org_structure_version_id = p_plan_rec.org_structure_version_id
828 							   UNION
829 							   SELECT p_plan_rec.top_organization_id organization_id_child
830 								 FROM DUAL) o,
831 							  hr_organization_units org
832 						WHERE o.organization_id_child = org.organization_id
833 						  AND p_effective_date BETWEEN org.date_from AND NVL (org.date_to, p_effective_date));
834 
835 		  -- Position Hierarchy population
836 		  -- Includes assignments whose assignment position is top position or in next N levels of
837 		  -- plan position hierarchy, where N is the value specified in hierarchy level attribute of the plan
838 		  --
839 		  CURSOR csr_pos_hier_pop
840 		  IS
841 			 SELECT asg.assignment_id, asg.person_id, asg.business_group_id, asg.supervisor_id, asg.supervisor_assignment_id,
842 					asg.organization_id, asg.position_id
843 			   FROM per_all_assignments_f asg
844 			  WHERE (   (p_plan_rec.assignment_types_code IN ('E', 'C') AND asg.assignment_type = p_plan_rec.assignment_types_code)
845 					 OR (p_plan_rec.assignment_types_code = 'EC' AND asg.assignment_type IN ('E', 'C'))
846 					)
847 				AND p_effective_date BETWEEN asg.effective_start_date AND asg.effective_end_date
848 				AND ((p_plan_rec.primary_asg_only_flag = 'N') OR p_plan_rec.primary_asg_only_flag = 'Y' AND asg.primary_flag = 'Y')
849 				AND 'x' =
850 					   (SELECT 'x'
851 						  FROM per_all_people_f ppf
852 						 WHERE asg.person_id = ppf.person_id
853 						   AND p_effective_date BETWEEN ppf.effective_start_date AND ppf.effective_end_date
854 						   AND ('Y' =
855 								   DECODE (p_plan_rec.assignment_types_code,
856 										   'E', ppf.current_employee_flag,
857 										   'C', ppf.current_npw_flag,
858 										   'EC', (SELECT 'Y'
859 													FROM DUAL
860 												   WHERE ppf.current_employee_flag = 'Y' OR ppf.current_npw_flag = 'Y')
861 										  )
862 							   ))
863 				AND (asg.position_id IN (
864 						SELECT o.subordinate_position_id
865 						  FROM (SELECT     p.subordinate_position_id
866 									  FROM per_pos_structure_elements p
867 								CONNECT BY p.parent_position_id = PRIOR p.subordinate_position_id
868 									   AND p.pos_structure_version_id = PRIOR p.pos_structure_version_id
869 									   AND LEVEL <= NVL (p_plan_rec.hierarchy_levels, LEVEL)
870 								START WITH p.parent_position_id = p_plan_rec.top_position_id
871 									   AND p.pos_structure_version_id = p_plan_rec.pos_structure_version_id) o,
872 							   per_positions pos
873 						 WHERE o.subordinate_position_id = pos.position_id
874 						   AND p_effective_date BETWEEN pos.date_effective AND NVL (pos.date_end, p_effective_date)
875 						UNION
876 						SELECT p_plan_rec.top_position_id subordinate_position_id
877 						  FROM DUAL)
878 					);
879 
880 		  CURSOR csr_apprl_periods (p_pln_id per_perf_mgmt_plans.plan_id%TYPE)
881 		  IS
882 			 SELECT prds.appraisal_period_id, prds.appraisal_template_id, templ.business_group_id
883 			   FROM per_appraisal_periods prds, per_appraisal_templates templ
884 			  WHERE prds.plan_id = p_pln_id AND templ.appraisal_template_id = prds.appraisal_template_id;
885 
886 		  l_last_bg_id             per_appraisal_templates.business_group_id%TYPE;
887 		  l_bg_change              BOOLEAN                                          DEFAULT FALSE;
888 		  l_check_cross_bg_templ   BOOLEAN                                          DEFAULT FALSE;
889 		  l_appr_prds_tbl          appr_prds_tbl;
890 		  e_invl_templ_popl        EXCEPTION;
891 	   BEGIN
892 		  --
893 		  IF g_dbg
894 		  THEN
895 			 op ('Entering:' || l_proc, g_regular_log, 10);
896 		  END IF;
897 
898 		  --
899 		  g_plan_pop_known_t.DELETE;
900 
901 		  --
902 		  -- Check the hierarchy_type and populate the assignment table
903 		  --
904 		  IF (p_plan_rec.hierarchy_type_code = 'SUP')
905 		  THEN
906 			 --
907 			 IF g_dbg
908 			 THEN
909 				op (l_proc, g_debug_log, 20);
910 			 END IF;
911 
912 			 --
913 			 OPEN csr_sup_hier_pop;
914 
915 			 FETCH csr_sup_hier_pop
916 			 BULK COLLECT INTO l_temp_pop_tbl;
917 
918 			 CLOSE csr_sup_hier_pop;
919 		  --
920 		  ELSIF (p_plan_rec.hierarchy_type_code = 'SUP_ASG')
921 		  THEN
922 			 --
923 			 IF g_dbg
924 			 THEN
925 				op (l_proc, g_debug_log, 30);
926 			 END IF;
927 
928 			 --
929 			 OPEN csr_sup_asg_hier_pop;
930 
931 			 FETCH csr_sup_asg_hier_pop
932 			 BULK COLLECT INTO l_temp_pop_tbl;
933 
934 			 CLOSE csr_sup_asg_hier_pop;
935 		  --
936 		  ELSIF (p_plan_rec.hierarchy_type_code = 'ORG')
937 		  THEN
938 			 --
939 			 IF g_dbg
940 			 THEN
941 				op (l_proc, g_debug_log, 40);
942 			 END IF;
943 
944 			 --
945 			 OPEN csr_org_hier_pop;
946 
947 			 FETCH csr_org_hier_pop
948 			 BULK COLLECT INTO l_temp_pop_tbl;
949 
950 			 CLOSE csr_org_hier_pop;
951 		  --
952 		  ELSIF (p_plan_rec.hierarchy_type_code = 'POS')
953 		  THEN
954 			 --
955 			 IF g_dbg
956 			 THEN
957 				op (l_proc, g_debug_log, 50);
958 			 END IF;
959 
960 			 --
961 			 OPEN csr_pos_hier_pop;
962 
963 			 FETCH csr_pos_hier_pop
964 			 BULK COLLECT INTO l_temp_pop_tbl;
965 
966 			 CLOSE csr_pos_hier_pop;
967 		  --
968 		  END IF;
969 
970 		  --
971 		  IF g_dbg
972 		  THEN
973 			 op (l_proc, g_debug_log, 60);
974 		  END IF;
975 
976 		  --
977 		  OPEN csr_apprl_periods (p_plan_rec.plan_id);
978 
979 		  FETCH csr_apprl_periods
980 		  BULK COLLECT INTO l_appr_prds_tbl;
981 
982 		  CLOSE csr_apprl_periods;
983 
984 		  --
985 		  IF g_dbg
986 		  THEN
987 			 op (l_proc, g_debug_log, 60);
988 		  END IF;
989 
990 		  --
991 		  IF l_appr_prds_tbl.COUNT > 0
992 		  THEN
993 			 FOR i IN l_appr_prds_tbl.FIRST .. l_appr_prds_tbl.LAST
994 			 LOOP
995 				IF g_dbg
996 				THEN
997 				   op (' Entered Appraisal Template Local Check ' || l_appr_prds_tbl (i).appraisal_period_id, g_debug_log, 60);
998 				END IF;
999 
1000 				IF (l_appr_prds_tbl (i).business_group_id IS NOT NULL)
1001 				THEN
1002 				   l_check_cross_bg_templ := TRUE;
1003 				   EXIT WHEN l_check_cross_bg_templ;
1004 				END IF;
1005 			 END LOOP;
1006 		  END IF;
1007 
1008 		  IF l_check_cross_bg_templ
1009 		  THEN
1010 			 IF g_dbg
1011 			 THEN
1012 				op (' Entered l_check_cross_bg_templ ', g_debug_log, 60);
1013 			 END IF;
1014 
1015 			 FOR i IN l_temp_pop_tbl.FIRST .. l_temp_pop_tbl.LAST
1016 			 LOOP
1017 				FOR j IN l_appr_prds_tbl.FIRST .. l_appr_prds_tbl.LAST
1018 				LOOP
1019 				   IF (l_appr_prds_tbl (j).business_group_id <> l_temp_pop_tbl (i).business_group_id)
1020 				   THEN
1021 					  l_bg_change := TRUE;
1022 
1023 					  IF g_dbg
1024 					  THEN
1025 						 op (' Selected Population is not in Appraisal Template BG ', g_regular_log, 90);
1026 					  END IF;
1027 
1028 					  IF g_dbg
1029 					  THEN
1030 						 op (   ' Appraisal Template BG='
1031 							 || l_appr_prds_tbl (j).business_group_id
1032 							 || ' Person Id='
1033 							 || l_temp_pop_tbl (i).assignment_id
1034 							 || ' BG='
1035 							 || l_temp_pop_tbl (i).business_group_id,
1036 							 g_regular_log,
1037 							 90
1038 							);
1039 					  END IF;
1040 
1041 					  EXIT WHEN l_bg_change;
1042 				   END IF;
1043 				END LOOP;
1044 
1045 				IF (NOT l_bg_change)
1046 				THEN
1047 				   IF (i = 1)
1048 				   THEN
1049 					  l_last_bg_id := l_temp_pop_tbl (i).business_group_id;
1050 				   ELSE
1051 					  IF (l_last_bg_id <> l_temp_pop_tbl (i).business_group_id)
1052 					  THEN
1053 						 l_bg_change := TRUE;
1054 
1055 						 IF g_dbg
1056 						 THEN
1057 							op (' Population is spanned across Business Groups  ', g_regular_log, 90);
1058 						 END IF;
1059 
1060 						 EXIT WHEN l_bg_change;
1061 					  ELSE
1062 						 l_last_bg_id := l_temp_pop_tbl (i).business_group_id;
1063 					  END IF;
1064 				   END IF;
1065 				ELSE
1066 				   EXIT WHEN l_bg_change;
1067 				END IF;
1068 			 END LOOP;
1069 		  END IF;
1070 
1071 		  IF (l_bg_change)
1072 		  THEN
1073 			 RAISE e_invl_templ_popl;
1074 		  END IF;
1075 
1076 		  --
1077 		  -- Populate the plan population global cache
1078 		  -- with index as assignment id and  other values in respective columns
1079 		  --
1080 		  IF l_temp_pop_tbl.COUNT > 0
1081 		  THEN
1082 			 FOR i IN l_temp_pop_tbl.FIRST .. l_temp_pop_tbl.LAST
1083 			 LOOP
1084 				--
1085 				IF g_dbg
1086 				THEN
1087 				   op ('Assignment Id = ' || l_temp_pop_tbl (i).assignment_id, g_debug_log);
1088 				END IF;
1089 
1090 				--
1091 				IF NOT g_qual_pop_tbl.EXISTS (l_temp_pop_tbl (i).assignment_id)
1092 				THEN
1093 				   g_qual_pop_tbl (l_temp_pop_tbl (i).assignment_id).assignment_id := l_temp_pop_tbl (i).assignment_id;
1094 				   g_qual_pop_tbl (l_temp_pop_tbl (i).assignment_id).person_id := l_temp_pop_tbl (i).person_id;
1095 				   g_qual_pop_tbl (l_temp_pop_tbl (i).assignment_id).business_group_id := l_temp_pop_tbl (i).business_group_id;
1096 				   g_qual_pop_tbl (l_temp_pop_tbl (i).assignment_id).supervisor_id := l_temp_pop_tbl (i).supervisor_id;
1097 				   g_qual_pop_tbl (l_temp_pop_tbl (i).assignment_id).supervisor_assignment_id :=
1098 																						  l_temp_pop_tbl (i).supervisor_assignment_id;
1099 				   g_qual_pop_tbl (l_temp_pop_tbl (i).assignment_id).organization_id := l_temp_pop_tbl (i).organization_id;
1100 				   g_qual_pop_tbl (l_temp_pop_tbl (i).assignment_id).position_id := l_temp_pop_tbl (i).position_id;
1101 				END IF;
1102 			 END LOOP;
1103 		  --
1104 		  END IF;
1105 
1106 		  --
1107 		  g_plan_pop_known_t (p_plan_rec.plan_id) := TRUE;
1108 
1109 		  --
1110 		  IF g_dbg
1111 		  THEN
1112 			 op ('Leaving:' || l_proc, g_regular_log, 80);
1113 		  END IF;
1114 	   --
1115 	   EXCEPTION
1116 		  WHEN e_invl_templ_popl
1117 		  THEN
1118 			 IF g_dbg
1119 			 THEN
1120 				op (g_error_txt, g_regular_log);
1121 			 END IF;
1122 
1123 			 fnd_message.set_name ('PER', 'HR_WPM_INVL_TMPL_POPL');
1124 			 g_error_txt := NVL (fnd_message.get, 'HR_WPM_INVL_TMPL_POPL');
1125 			 g_retcode := error;
1126 			 g_errbuf := g_error_txt;
1127 			 RAISE;
1128 		  WHEN OTHERS
1129 		  THEN
1130 			 IF g_dbg
1131 			 THEN
1132 				op ('Leaving:' || l_proc, g_regular_log, 90);
1133 			 END IF;
1134 
1135 			 --
1136 			 fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
1137 			 g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
1138 			 g_retcode := warning;
1139 			 g_errbuf := g_cp_error_txt;
1140 			 g_num_errors := g_num_errors + 1;
1141 
1142 			 IF g_dbg
1143 			 THEN
1144 				op (g_error_txt, g_regular_log);
1145 			 END IF;
1146 
1147 			 IF g_dbg
1148 			 THEN
1149 				op (SQLERRM, g_regular_log);
1150 			 END IF;
1151 
1152 			 --
1153 			 -- If the max number of errors has been exceeded, raise the error and
1154 			 -- terminate processing of this plan.
1155 			 --
1156 			 IF g_num_errors > g_max_errors
1157 			 THEN
1158 				fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
1159 				g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
1160 				g_retcode := error;
1161 				g_errbuf := g_error_txt;
1162 				RAISE;
1163 			 END IF;
1164 	   END populate_qual_plan_population;
1165 
1166 	--
1167 	-- ----------------------------------------------------------------------------
1168 	-- |---------------------< populate_curr_plan_population >---------------------|
1169 	-- ----------------------------------------------------------------------------
1170 	-- {Start Of Comments}
1171 	--
1172 	-- Description:
1173 	--   Populate the current plan population and loads in cache(i.e. PLSQL table
1174 	--    with index as assignment id and other values.
1175 	--
1176 	-- Prerequisites:
1177 	--   None.
1178 	--
1179 	-- In Arguments:
1180 	--
1181 	--
1182 	-- Post Success:
1183 	--  Processing continues on successful population.
1184 	--
1185 	-- Post Failure:
1186 	--  An application error is raised if population fails.
1187 
1188 	   --
1189 	-- Access Status:
1190 	--   Internal Use Only.
1191 	--
1192 	-- {End Of Comments}
1193 	-- ----------------------------------------------------------------------------
1194 	   PROCEDURE populate_curr_plan_population (p_plan_id IN NUMBER)
1195 	   IS
1196 		  -- Declare local variables
1197 		  l_proc           VARCHAR2 (72)   := g_package || 'populate_curr_plan_population';
1198 		  l_temp_pop_tbl   g_curr_sc_pop_t;
1199 
1200 		  -- Current Plan population
1201 		  CURSOR csr_curr_plan_pop
1202 		  IS
1203 			 SELECT assignment_id, scorecard_id, object_version_number, status_code
1204 			   FROM per_personal_scorecards
1205 			  WHERE creator_type = 'AUTO' AND plan_id = p_plan_id AND status_code <> 'TRANSFER_OUT';
1206 	   --
1207 	   BEGIN
1208 		  --
1209 		  IF g_dbg
1210 		  THEN
1211 			 op ('Entering:' || l_proc, g_regular_log, 10);
1212 		  END IF;
1213 
1214 		  --
1215 
1216 		  --
1217 		  -- Get the plan population and populate the current population table
1218 		  --
1219 		  OPEN csr_curr_plan_pop;
1220 
1221 		  FETCH csr_curr_plan_pop
1222 		  BULK COLLECT INTO l_temp_pop_tbl;
1223 
1224 		  CLOSE csr_curr_plan_pop;
1225 
1226 		  --
1227 		  IF g_dbg
1228 		  THEN
1229 			 op (l_proc, g_debug_log, 60);
1230 		  END IF;
1231 
1232 		  --
1233 
1234 		  --
1235 		  -- Populate the plan population global cache
1236 		  -- with index as assignment id and other values in respective columns
1237 		  --
1238 		  IF l_temp_pop_tbl.COUNT > 0
1239 		  THEN
1240 			 FOR i IN l_temp_pop_tbl.FIRST .. l_temp_pop_tbl.LAST
1241 			 LOOP
1242 				--
1243 				IF g_dbg
1244 				THEN
1245 				   op ('Assignment Id = ' || l_temp_pop_tbl (i).assignment_id, g_debug_log);
1246 				END IF;
1247 
1248 				--
1249 				IF NOT g_curr_sc_pop_tbl.EXISTS (l_temp_pop_tbl (i).assignment_id)
1250 				THEN
1251 				   g_curr_sc_pop_tbl (l_temp_pop_tbl (i).assignment_id).assignment_id := l_temp_pop_tbl (i).assignment_id;
1252 				   g_curr_sc_pop_tbl (l_temp_pop_tbl (i).assignment_id).scorecard_id := l_temp_pop_tbl (i).scorecard_id;
1253 				   g_curr_sc_pop_tbl (l_temp_pop_tbl (i).assignment_id).object_version_number :=
1254 																							 l_temp_pop_tbl (i).object_version_number;
1255 				   g_curr_sc_pop_tbl (l_temp_pop_tbl (i).assignment_id).status_code := l_temp_pop_tbl (i).status_code;
1256 				END IF;
1257 			 END LOOP;
1258 		  --
1259 		  END IF;
1260 
1261 		  --
1262 		  IF g_dbg
1263 		  THEN
1264 			 op ('Leaving:' || l_proc, g_regular_log, 80);
1265 		  END IF;
1266 	   --
1267 	   EXCEPTION
1268 		  WHEN OTHERS
1269 		  THEN
1270 			 IF g_dbg
1271 			 THEN
1272 				op ('Leaving:' || l_proc, g_regular_log, 90);
1273 			 END IF;
1274 
1275 			 --
1276 			 fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
1277 			 g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
1278 			 g_retcode := warning;
1279 			 g_errbuf := g_cp_error_txt;
1280 			 g_num_errors := g_num_errors + 1;
1281 
1282 			 IF g_dbg
1283 			 THEN
1284 				op (g_error_txt, g_regular_log);
1285 			 END IF;
1286 
1287 			 IF g_dbg
1288 			 THEN
1289 				op (SQLERRM, g_regular_log);
1290 			 END IF;
1291 
1292 			 --
1293 			 -- If the max number of errors has been exceeded, raise the error and
1294 			 -- terminate processing of this plan.
1295 			 --
1296 			 IF g_num_errors > g_max_errors
1297 			 THEN
1298 				fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
1299 				g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
1300 				g_retcode := error;
1301 				g_errbuf := g_error_txt;
1302 			 END IF;
1303 	   END populate_curr_plan_population;
1304 
1305 	--
1306 	-- ----------------------------------------------------------------------------
1307 	-- |-----------------------< populate_qual_objectives >-----------------------|
1308 	-- ----------------------------------------------------------------------------
1309 	-- {Start Of Comments}
1310 	--
1311 	-- Description:
1312 	--   Populate the qualifying objectives for a given plan period (i.e. PLSQL table
1313 	--    with index as assignment id and boolean value.
1314 	--
1315 	-- Prerequisites:
1316 	--   None.
1317 	--
1318 	-- In Arguments:
1319 	--
1320 	--
1321 	-- Post Success:
1322 	--  Processing continues on successful population.
1323 	--
1324 	-- Post Failure:
1325 	--  An application error is raised if population fails.
1326 
1327 	   --
1328 	-- Access Status:
1329 	--   Internal Use Only.
1330 	--
1331 	-- {End Of Comments}
1332 	-- ----------------------------------------------------------------------------
1333 	   PROCEDURE populate_qual_objectives (p_start_date IN DATE, p_end_date IN DATE)
1334 	   IS
1335 		  -- Declare local variables
1336 		  l_proc           VARCHAR2 (72) := g_package || 'populate_qual_objectives';
1337 		  l_temp_obj_tbl   g_qual_obj_t;
1338 
1339 		  -- Current Plan population
1340 		  CURSOR csr_qual_objectives
1341 		  IS
1342 			 SELECT objective_id, objective_name, valid_from, valid_to, target_date, next_review_date, group_code, priority_code,
1343 					appraise_flag, weighting_percent, target_value, uom_code, measurement_style_code, measure_name,
1344 					measure_type_code, measure_comments, details, success_criteria, comments, elig.elig_obj_id
1345 			   FROM per_objectives_library pol, ben_elig_obj_f elig
1346 			  WHERE (   pol.valid_from BETWEEN p_start_date AND p_end_date
1347 					 OR p_start_date BETWEEN pol.valid_from AND NVL (pol.valid_to, TO_DATE ('31-12-4712', 'DD-MM-YYYY'))
1348 					)
1349 				AND pol.eligibility_type_code <> 'N_P'
1350 				AND elig.table_name = 'PER_OBJECTIVES_LIBRARY'
1351 				AND column_name = 'OBJECTIVE_ID'
1352 				AND elig.COLUMN_VALUE = pol.objective_id
1353 				-- added 23-Jun-2009 schowdhu
1354 				AND TRUNC (SYSDATE) BETWEEN elig.effective_start_date AND elig.effective_end_date;
1355 	   BEGIN
1356 		  --
1357 		  IF g_dbg
1358 		  THEN
1359 			 op ('Entering:' || l_proc, g_regular_log, 10);
1360 		  END IF;
1361 
1362 		  --
1363 
1364 		  --
1365 		  -- Get the plan population and populate the qualifying objectives for plan
1366 		  --
1367 		  OPEN csr_qual_objectives;
1368 
1369 		  FETCH csr_qual_objectives
1370 		  BULK COLLECT INTO l_temp_obj_tbl;
1371 
1372 		  CLOSE csr_qual_objectives;
1373 
1374 		  --
1375 		  IF g_dbg
1376 		  THEN
1377 			 op (l_proc, g_debug_log, 20);
1378 		  END IF;
1379 
1380 		  --
1381 
1382 		  --
1383 		  -- Populate the plan population global cache
1384 		  -- with index as library objective id and other values in respective columns
1385 		  --
1386 		  IF l_temp_obj_tbl.COUNT > 0
1387 		  THEN
1388 			 FOR i IN l_temp_obj_tbl.FIRST .. l_temp_obj_tbl.LAST
1389 			 LOOP
1390 				--
1391 				IF g_dbg
1392 				THEN
1393 				   op ('Objective Id = ' || l_temp_obj_tbl (i).objective_id, g_debug_log);
1394 				END IF;
1395 
1396 				--
1397 				--   Condition removed for bug no 6875448
1398 				--IF NOT g_curr_sc_pop_tbl.EXISTS(l_temp_obj_tbl(i).objective_id) THEN
1399 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).objective_id := l_temp_obj_tbl (i).objective_id;
1400 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).objective_name := l_temp_obj_tbl (i).objective_name;
1401 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).valid_from := l_temp_obj_tbl (i).valid_from;
1402 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).valid_to := l_temp_obj_tbl (i).valid_to;
1403 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).target_date := l_temp_obj_tbl (i).target_date;
1404 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).next_review_date := l_temp_obj_tbl (i).next_review_date;
1405 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).group_code := l_temp_obj_tbl (i).group_code;
1406 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).priority_code := l_temp_obj_tbl (i).priority_code;
1407 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).appraise_flag := l_temp_obj_tbl (i).appraise_flag;
1408 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).weighting_percent := l_temp_obj_tbl (i).weighting_percent;
1409 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).target_value := l_temp_obj_tbl (i).target_value;
1410 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).uom_code := l_temp_obj_tbl (i).uom_code;
1411 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).measurement_style_code := l_temp_obj_tbl (i).measurement_style_code;
1412 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).measure_name := l_temp_obj_tbl (i).measure_name;
1413 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).measure_type_code := l_temp_obj_tbl (i).measure_type_code;
1414 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).measure_comments := l_temp_obj_tbl (i).measure_comments;
1415 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).details := l_temp_obj_tbl (i).details;
1416 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).success_criteria := l_temp_obj_tbl (i).success_criteria;
1417 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).comments := l_temp_obj_tbl (i).comments;
1418 				g_qual_obj_tbl (l_temp_obj_tbl (i).objective_id).elig_obj_id := l_temp_obj_tbl (i).elig_obj_id;
1419 			 -- END IF;
1420 			 END LOOP;
1421 		  --
1422 		  END IF;
1423 
1424 		  --
1425 		  IF g_dbg
1426 		  THEN
1427 			 op ('Leaving:' || l_proc, g_regular_log, 80);
1428 		  END IF;
1429 	   --
1430 	   EXCEPTION
1431 		  WHEN OTHERS
1432 		  THEN
1433 			 IF g_dbg
1434 			 THEN
1435 				op ('Leaving:' || l_proc, g_regular_log, 90);
1436 			 END IF;
1437 
1438 			 --
1439 			 fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
1440 			 g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
1441 			 g_retcode := warning;
1442 			 g_errbuf := g_cp_error_txt;
1443 			 g_num_errors := g_num_errors + 1;
1444 
1445 			 IF g_dbg
1446 			 THEN
1447 				op (g_error_txt, g_regular_log);
1448 			 END IF;
1449 
1450 			 IF g_dbg
1451 			 THEN
1452 				op (SQLERRM, g_regular_log);
1453 			 END IF;
1454 
1455 			 --
1456 			 -- If the max number of errors has been exceeded, raise the error and
1457 			 -- terminate processing of this plan.
1458 			 --
1459 			 IF g_num_errors > g_max_errors
1460 			 THEN
1461 				fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
1462 				g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
1463 				g_retcode := error;
1464 				g_errbuf := g_error_txt;
1465 				RAISE;
1466 			 END IF;
1467 	   END populate_qual_objectives;
1468 
1469 	--
1470 	-- ----------------------------------------------------------------------------
1471 	-- |---------------------< populate_curr_sc_objectives >----------------------|
1472 	-- ----------------------------------------------------------------------------
1473 	-- {Start Of Comments}
1474 	--
1475 	-- Description:
1476 	--   Populate the current objectivesfor a gives scorecard (i.e. PLSQL table
1477 	--    with index as library objective id and other values.
1478 	--
1479 	-- Prerequisites:
1480 	--   None.
1481 	--
1482 	-- In Arguments:
1483 	--
1484 	--
1485 	-- Post Success:
1486 	--  Processing continues on successful population.
1487 	--
1488 	-- Post Failure:
1489 	--  An application error is raised if population fails.
1490 
1491 	   --
1492 	-- Access Status:
1493 	--   Internal Use Only.
1494 	--
1495 	-- {End Of Comments}
1496 	-- ----------------------------------------------------------------------------
1497 	   PROCEDURE populate_curr_sc_objectives (p_scorecard_id IN NUMBER)
1498 	   IS
1499 		  -- Declare local variables
1500 		  l_proc           VARCHAR2 (72)   := g_package || 'populate_curr_sc_objectives';
1501 		  l_temp_obj_tbl   g_curr_sc_obj_t;
1502 
1503 		  -- Current scorecard objectives
1504 		  CURSOR csr_curr_sc_objs
1505 		  IS
1506 			 SELECT copied_from_library_id, objective_id, object_version_number
1507 			   FROM per_objectives pob
1508 			  WHERE pob.copied_from_library_id IS NOT NULL AND pob.scorecard_id = p_scorecard_id;
1509 	   --
1510 	   BEGIN
1511 		  --
1512 		  IF g_dbg
1513 		  THEN
1514 			 op ('Entering:' || l_proc, g_regular_log, 10);
1515 		  END IF;
1516 
1517 		  --
1518 
1519 		  --
1520 		  -- Initialize the objectivestables that is used for different scorecards in loop
1521 		  --
1522 		  -- g_curr_sc_obj_tbl := l_temp_obj_tbl;
1523 		  g_curr_sc_obj_tbl.DELETE;
1524 
1525 		  --
1526 		  -- Get the plan population and populate the current scorecard objectives
1527 		  --
1528 		  OPEN csr_curr_sc_objs;
1529 
1530 		  FETCH csr_curr_sc_objs
1531 		  BULK COLLECT INTO l_temp_obj_tbl;
1532 
1533 		  CLOSE csr_curr_sc_objs;
1534 
1535 		  --
1536 		  IF g_dbg
1537 		  THEN
1538 			 op (l_proc, g_debug_log, 60);
1539 		  END IF;
1540 
1541 		  --
1542 
1543 		  --
1544 		  -- Populate the plan population global cache
1545 		  -- with index as library objective id and other values in respective columns
1546 		  --
1547 		  IF l_temp_obj_tbl.COUNT > 0
1548 		  THEN
1549 			 FOR i IN l_temp_obj_tbl.FIRST .. l_temp_obj_tbl.LAST
1550 			 LOOP
1551 				--
1552 				IF g_dbg
1553 				THEN
1554 				   op ('Objective Id = ' || l_temp_obj_tbl (i).objective_id, g_debug_log);
1555 				END IF;
1556 
1557 				--
1558 				--      Condition removed for bug no 6875448
1559 				--IF NOT g_curr_sc_pop_tbl.EXISTS(l_temp_obj_tbl(i).copied_from_library_id) THEN
1560 				g_curr_sc_obj_tbl (l_temp_obj_tbl (i).copied_from_library_id).copied_from_library_id :=
1561 																							 l_temp_obj_tbl (i).copied_from_library_id;
1562 				g_curr_sc_obj_tbl (l_temp_obj_tbl (i).copied_from_library_id).objective_id := l_temp_obj_tbl (i).objective_id;
1563 				g_curr_sc_obj_tbl (l_temp_obj_tbl (i).copied_from_library_id).object_version_number :=
1564 																							  l_temp_obj_tbl (i).object_version_number;
1565 			 --END IF;
1566 			 END LOOP;
1567 		  --
1568 		  END IF;
1569 
1570 		  --
1571 		  IF g_dbg
1572 		  THEN
1573 			 op ('Leaving:' || l_proc, g_regular_log, 80);
1574 		  END IF;
1575 	   --
1576 	   EXCEPTION
1577 		  WHEN OTHERS
1578 		  THEN
1579 			 IF g_dbg
1580 			 THEN
1581 				op ('Leaving:' || l_proc, g_regular_log, 90);
1582 			 END IF;
1583 
1584 			 --
1585 			 fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
1586 			 g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
1587 			 g_retcode := warning;
1588 			 g_errbuf := g_cp_error_txt;
1589 			 g_num_errors := g_num_errors + 1;
1590 
1591 			 IF g_dbg
1592 			 THEN
1593 				op (g_error_txt, g_regular_log);
1594 			 END IF;
1595 
1596 			 IF g_dbg
1597 			 THEN
1598 				op (SQLERRM, g_regular_log);
1599 			 END IF;
1600 
1601 			 --
1602 			 -- If the max number of errors has been exceeded, raise the error and
1603 			 -- terminate processing of this plan.
1604 			 --
1605 			 IF g_num_errors > g_max_errors
1606 			 THEN
1607 				fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
1608 				g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
1609 				g_retcode := error;
1610 				g_errbuf := g_error_txt;
1611 				RAISE;
1612 			 END IF;
1613 	   END populate_curr_sc_objectives;
1614 
1615 	--
1616 	-- ----------------------------------------------------------------------------
1617 	-- |---------------------< populate_plan_apprsl_periods >---------------------|
1618 	-- ----------------------------------------------------------------------------
1619 	-- {Start Of Comments}
1620 	--
1621 	-- Description:
1622 	--   Populates the appraisal periods for a given plan.
1623 	--
1624 	-- Prerequisites:
1625 	--   None.
1626 	--
1627 	-- In Arguments:
1628 	--
1629 	--
1630 	-- Post Success:
1631 	--  Processing continues on successful population.
1632 	--
1633 	-- Post Failure:
1634 	--  An application error is raised if population fails.
1635 
1636 	   --
1637 	-- Access Status:
1638 	--   Internal Use Only.
1639 	--
1640 	-- {End Of Comments}
1641 	-- ----------------------------------------------------------------------------
1642 	   PROCEDURE populate_plan_apprsl_periods (p_plan_id IN NUMBER)
1643 	   IS
1644 		  -- Declare local variables
1645 		  l_proc   VARCHAR2 (72) := g_package || 'populate_plan_apprsl_periods';
1646 
1647 		  -- Current scorecard objectives
1648 		  CURSOR csr_plan_apprsl_pds
1649 		  IS
1650 			 SELECT appraisal_period_id, appraisal_template_id, start_date, end_date, task_start_date, task_end_date, initiator_code,
1651 					appraisal_system_type, auto_conc_process, days_before_task_st_dt, appraisal_assmt_status, appraisal_type
1652 			   FROM per_appraisal_periods pap
1653 			  WHERE pap.plan_id = p_plan_id;
1654 	   --
1655 	   BEGIN
1656 		  --
1657 		  IF g_dbg
1658 		  THEN
1659 			 op ('Entering:' || l_proc, g_regular_log, 10);
1660 		  END IF;
1661 
1662 		  --
1663 
1664 		  --
1665 		  -- Get the plan appraisal periods
1666 		  --
1667 		  OPEN csr_plan_apprsl_pds;
1668 
1669 		  FETCH csr_plan_apprsl_pds
1670 		  BULK COLLECT INTO g_plan_aprsl_pds_tbl;
1671 
1672 		  CLOSE csr_plan_apprsl_pds;
1673 
1674 		  --
1675 		  IF g_dbg
1676 		  THEN
1677 			 op (l_proc, g_debug_log, 60);
1678 		  END IF;
1679 
1680 		  --
1681 
1682 		  --
1683 		  IF g_dbg
1684 		  THEN
1685 			 op ('Leaving:' || l_proc, g_regular_log, 80);
1686 		  END IF;
1687 	   --
1688 	   EXCEPTION
1689 		  WHEN OTHERS
1690 		  THEN
1691 			 IF g_dbg
1692 			 THEN
1693 				op ('Leaving:' || l_proc, g_regular_log, 90);
1694 			 END IF;
1695 
1696 			 --
1697 			 fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
1698 			 g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
1699 			 g_retcode := warning;
1700 			 g_errbuf := g_cp_error_txt;
1701 			 g_num_errors := g_num_errors + 1;
1702 
1703 			 IF g_dbg
1704 			 THEN
1705 				op (g_error_txt, g_regular_log);
1706 			 END IF;
1707 
1708 			 IF g_dbg
1709 			 THEN
1710 				op (SQLERRM, g_regular_log);
1711 			 END IF;
1712 
1713 			 --
1714 			 -- If the max number of errors has been exceeded, raise the error and
1715 			 -- terminate processing of this plan.
1716 			 --
1717 			 IF g_num_errors > g_max_errors
1718 			 THEN
1719 				fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
1720 				g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
1721 				g_retcode := error;
1722 				g_errbuf := g_error_txt;
1723 				RAISE;
1724 			 END IF;
1725 	   END populate_plan_apprsl_periods;
1726 
1727 	--
1728 	-- ----------------------------------------------------------------------------
1729 	-- |----------------------< create_scorecard_for_person >---------------------|
1730 	-- ----------------------------------------------------------------------------
1731 	-- {Start Of Comments}
1732 	--
1733 	-- Description:
1734 	--   Creates scorecard for a given person when plan is published.
1735 	--
1736 	-- Prerequisites:
1737 	--   None.
1738 	--
1739 	-- In Arguments:
1740 	--
1741 	--
1742 	-- Post Success:
1743 	--  Processing continues if scorecard is created.
1744 	--
1745 	-- Post Failure:
1746 	--  An application error is raised if scorecard is not created.
1747 	--
1748 	-- Access Status:
1749 	--   Internal Only.
1750 	--
1751 	-- {End Of Comments}
1752 	-- ----------------------------------------------------------------------------
1753 	   PROCEDURE create_scorecard_for_person (
1754 		  p_effective_date   IN              DATE,
1755 		  p_scorecard_name   IN              VARCHAR2,
1756 		  p_assignment_id    IN              NUMBER,
1757 		  p_start_date       IN              DATE,
1758 		  p_end_date         IN              DATE,
1759 		  p_plan_id          IN              NUMBER,
1760 		  p_creator_type     IN              VARCHAR2,
1761 		  p_status_code      IN              VARCHAR2,
1762 		  p_scorecard_id               OUT NOCOPY      NUMBER,
1763 		  p_supervisor_id              IN              NUMBER DEFAULT NULL,
1764 		  p_supervisor_assignment_id   IN              NUMBER DEFAULT NULL
1765 	   )
1766 	   IS
1767 		  -- Declare local variables
1768 		  l_proc                     VARCHAR2 (72) := g_package || 'create_scorecard_for_person';
1769 		  --
1770 		  l_scorecard_id             NUMBER;
1771 		  l_object_version_number    NUMBER;
1772 		  --l_status_code                 varchar2(30);
1773 		  l_duplicate_name_warning   BOOLEAN;
1774 	   --
1775 	   BEGIN
1776 		  --
1777 		  IF g_dbg
1778 		  THEN
1779 			 op ('Entering:' || l_proc, g_regular_log, 10);
1780 		  END IF;
1781 
1782 		  --
1783 
1784 		  --
1785 		  -- Call create_scorecard
1786 		  --
1787 		  hr_personal_scorecard_api.create_scorecard (p_effective_date              => p_effective_date,
1788 													  p_scorecard_name              => p_scorecard_name,
1789 													  p_assignment_id               => p_assignment_id,
1790 													  p_start_date                  => p_start_date,
1791 													  p_end_date                    => p_end_date,
1792 													  p_plan_id                     => p_plan_id,
1793 													  p_creator_type                => p_creator_type,
1794 													  p_scorecard_id                => l_scorecard_id,
1795 													  p_object_version_number       => l_object_version_number,
1796 													  p_status_code                 => p_status_code,
1797 													  p_duplicate_name_warning        => l_duplicate_name_warning,
1798 													  p_supervisor_id                 => p_supervisor_id,
1799 													  p_supervisor_assignment_id      => p_supervisor_assignment_id
1800 													 );
1801 		  -- Out parameter
1802 		  p_scorecard_id := l_scorecard_id;
1803 
1804 		  IF g_dbg
1805 		  THEN
1806 			 op ('Scorecard Id = ' || l_scorecard_id, g_debug_log);
1807 		  END IF;
1808 
1809 		  --
1810 		  IF g_dbg
1811 		  THEN
1812 			 op ('Leaving:' || l_proc, g_regular_log, 80);
1813 		  END IF;
1814 	   --
1815 	   EXCEPTION
1816 		  WHEN OTHERS
1817 		  THEN
1818 			 -- WPM  Logging changes
1819 			 hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).MESSAGE_TYPE := 'E';
1820 			 hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).message_number := 'OTHER';
1821 			 hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).MESSAGE_TEXT := SQLERRM;
1822 			 hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).processing_status := 'ERROR';
1823 																															 -- Error
1824 
1825 			 IF g_dbg
1826 			 THEN
1827 				op ('Leaving:' || l_proc, g_regular_log, 90);
1828 			 END IF;
1829 
1830 			 --
1831 			 fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
1832 			 g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
1833 			 g_retcode := warning;
1834 			 g_errbuf := g_cp_error_txt;
1835 			 g_num_errors := g_num_errors + 1;
1836 
1837 			 IF g_dbg
1838 			 THEN
1839 				op (g_error_txt, g_regular_log);
1840 			 END IF;
1841 
1842 			 IF g_dbg
1843 			 THEN
1844 				op (SQLERRM, g_regular_log);
1845 			 END IF;
1846 
1847 			 --
1848 			 -- If the max number of errors has been exceeded, raise the error and
1849 			 -- terminate processing of this plan.
1850 			 --
1851 			 IF g_num_errors > g_max_errors
1852 			 THEN
1853 				fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
1854 				g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
1855 				g_retcode := error;
1856 				g_errbuf := g_error_txt;
1857 				RAISE;
1858 			 END IF;
1859 	   END create_scorecard_for_person;
1860 
1861 	--
1862 	-- ----------------------------------------------------------------------------
1863 	-- |----------------------< update_scorecard_for_person >---------------------|
1864 	-- ----------------------------------------------------------------------------
1865 	-- {Start Of Comments}
1866 	--
1867 	-- Description:
1868 	--   Updates the given scorecard  when plan is republished.
1869 	--
1870 	-- Prerequisites:
1871 	--   None.
1872 	--
1873 	-- In Arguments:
1874 	--
1875 	--
1876 	-- Post Success:
1877 	--  Processing continues if scorecard is updated.
1878 	--
1879 	-- Post Failure:
1880 	--  An application error is raised if scorecard is not updated.
1881 	--
1882 	-- Access Status:
1883 	--   Internal Only.
1884 	--
1885 	-- {End Of Comments}
1886 	-- ----------------------------------------------------------------------------
1887 	   PROCEDURE update_scorecard_for_person (
1888 		  p_effective_date          IN   DATE,
1889 		  p_scorecard_id            IN   NUMBER,
1890 		  p_object_version_number   IN   NUMBER,
1891 		  p_scorecard_name          IN   VARCHAR2 DEFAULT hr_api.g_varchar2,
1892 		  p_start_date              IN   DATE DEFAULT hr_api.g_date,
1893 		  p_end_date                IN   DATE DEFAULT hr_api.g_date,
1894 		  p_status_code                IN   VARCHAR2 DEFAULT hr_api.g_varchar2,
1895 		  p_supervisor_id              IN   NUMBER DEFAULT NULL,
1896 		  p_supervisor_assignment_id   IN   NUMBER DEFAULT NULL
1897 	   )
1898 	   IS
1899 		  -- Declare local variables
1900 		  l_proc                     VARCHAR2 (72) := g_package || 'update_scorecard_for_person';
1901 		  --
1902 		  l_duplicate_name_warning   BOOLEAN;
1903 		  l_object_version_number    NUMBER        := p_object_version_number;
1904 	   --
1905 	   BEGIN
1906 		  --
1907 		  IF g_dbg
1908 		  THEN
1909 			 op ('Entering:' || l_proc, g_regular_log, 10);
1910 		  END IF;
1911 
1912 		  --
1913 
1914 		  --
1915 		  -- Call update_scorecard
1916 		  --
1917 		  hr_personal_scorecard_api.update_scorecard (p_effective_date              => p_effective_date,
1918 													  p_scorecard_id                => p_scorecard_id,
1919 													  p_object_version_number       => l_object_version_number,
1920 													  p_scorecard_name              => p_scorecard_name,
1921 													  p_start_date                  => p_start_date,
1922 													  p_end_date                    => p_end_date,
1923 													  p_status_code                 => p_status_code,
1924 													  p_duplicate_name_warning        => l_duplicate_name_warning,
1925 													  p_supervisor_id                 => p_supervisor_id,
1926 													  p_supervisor_assignment_id      => p_supervisor_assignment_id
1927 													 );
1928 
1929 		  --
1930 		  IF g_dbg
1931 		  THEN
1932 			 op ('Leaving:' || l_proc, g_regular_log, 80);
1933 		  END IF;
1934 	   --
1935 	   EXCEPTION
1936 		  WHEN OTHERS
1937 		  THEN
1938 			 -- WPM  Logging changes
1939 			 hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).MESSAGE_TYPE := 'E';
1940 			 hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).message_number := 'OTHER';
1941 			 hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).MESSAGE_TEXT := SQLERRM;
1942 			 hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).processing_status := 'ERROR';
1943 																															 -- Error
1944 
1945 			 IF g_dbg
1946 			 THEN
1947 				op ('Leaving:' || l_proc, g_regular_log, 90);
1948 			 END IF;
1949 
1950 			 --
1951 			 fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
1952 			 g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
1953 			 g_retcode := warning;
1954 			 g_errbuf := g_cp_error_txt;
1955 			 g_num_errors := g_num_errors + 1;
1956 
1957 			 IF g_dbg
1958 			 THEN
1959 				op (g_error_txt, g_regular_log);
1960 			 END IF;
1961 
1962 			 IF g_dbg
1963 			 THEN
1964 				op (SQLERRM, g_regular_log);
1965 			 END IF;
1966 
1967 			 --
1968 			 -- If the max number of errors has been exceeded, raise the error and
1969 			 -- terminate processing of this plan.
1970 			 --
1971 			 IF g_num_errors > g_max_errors
1972 			 THEN
1973 				fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
1974 				g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
1975 				g_retcode := error;
1976 				g_errbuf := g_error_txt;
1977 				RAISE;
1978 			 END IF;
1979 	   END update_scorecard_for_person;
1980 
1981 	--
1982 	-- ----------------------------------------------------------------------------
1983 	-- |----------------------< delete_scorecard_for_person >---------------------|
1984 	-- ----------------------------------------------------------------------------
1985 	-- {Start Of Comments}
1986 	--
1987 	-- Description:
1988 	--   Delete the given scorecard.
1989 	--
1990 	-- Prerequisites:
1991 	--   None.
1992 	--
1993 	-- In Arguments:
1994 	--
1995 	--
1996 	-- Post Success:
1997 	--  Processing continues if scorecard is deleted.
1998 	--
1999 	-- Post Failure:
2000 	--  An application error is raised if scorecard is not deleted.
2001 	--
2002 	-- Access Status:
2003 	--   Internal Only.
2004 	--
2005 	-- {End Of Comments}
2006 	-- ----------------------------------------------------------------------------
2007 	   PROCEDURE delete_scorecard_for_person (p_scorecard_id IN NUMBER, p_object_version_number IN NUMBER)
2008 	   IS
2009 		  -- Declare local variables
2010 		  l_proc                      VARCHAR2 (72) := g_package || 'delete_scorecard_for_person';
2011 		  --
2012 		  l_created_by_plan_warning   BOOLEAN;
2013 	   BEGIN
2014 		  --
2015 		  IF g_dbg
2016 		  THEN
2017 			 op ('Entering:' || l_proc, g_regular_log, 10);
2018 		  END IF;
2019 
2020 		  --
2021 
2022 		  --
2023 		  -- Call update_scorecard
2024 		  --
2025 		  hr_personal_scorecard_api.delete_scorecard (p_scorecard_id                 => p_scorecard_id,
2026 													  p_object_version_number        => p_object_version_number,
2027 													  p_created_by_plan_warning      => l_created_by_plan_warning
2028 													 );
2029 
2030 		  --
2031 		  IF g_dbg
2032 		  THEN
2033 			 op ('Leaving:' || l_proc, g_regular_log, 80);
2034 		  END IF;
2035 	   --
2036 	   EXCEPTION
2037 		  WHEN OTHERS
2038 		  THEN
2039 			 IF g_dbg
2040 			 THEN
2041 				op ('Leaving:' || l_proc, g_regular_log, 90);
2042 			 END IF;
2043 
2044 			 --
2045 			 fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
2046 			 g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
2047 			 g_retcode := warning;
2048 			 g_errbuf := g_cp_error_txt;
2049 			 g_num_errors := g_num_errors + 1;
2050 
2051 			 IF g_dbg
2052 			 THEN
2053 				op (g_error_txt, g_regular_log);
2054 			 END IF;
2055 
2056 			 IF g_dbg
2057 			 THEN
2058 				op (SQLERRM, g_regular_log);
2059 			 END IF;
2060 
2061 			 --
2062 			 -- If the max number of errors has been exceeded, raise the error and
2063 			 -- terminate processing of this plan.
2064 			 --
2065 			 IF g_num_errors > g_max_errors
2066 			 THEN
2067 				fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
2068 				g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
2069 				g_retcode := error;
2070 				g_errbuf := g_error_txt;
2071 				RAISE;
2072 			 END IF;
2073 	   END delete_scorecard_for_person;
2074 
2075 	--
2076 	-- ----------------------------------------------------------------------------
2077 	-- |-------------------------< create_scorecard_objective >------------------|
2078 	-- ----------------------------------------------------------------------------
2079 	-- {Start Of Comments}
2080 	--
2081 	-- Description:
2082 	--   Creates objective for a given scorecard when plan is published.
2083 	--
2084 	-- Prerequisites:
2085 	--   None.
2086 	--
2087 	-- In Arguments:
2088 	--
2089 	--
2090 	-- Post Success:
2091 	--  Processing continues if objective is created.
2092 	--
2093 	-- Post Failure:
2094 	--  An application error is raised if objective is not created.
2095 	--
2096 	-- Access Status:
2097 	--   Internal Only.
2098 	--
2099 	-- {End Of Comments}
2100 	-- ----------------------------------------------------------------------------
2101 	   PROCEDURE create_scorecard_objective (
2102 		  p_effective_date           IN   DATE,
2103 		  p_business_group_id        IN   NUMBER,
2104 		  p_person_id                IN   NUMBER,
2105 		  p_scorecard_id             IN   NUMBER,
2106 		  p_start_date               IN   DATE,
2107 		  p_end_date                 IN   DATE,
2108 		  p_objective_name           IN   VARCHAR2,
2109 		  p_valid_from               IN   DATE,
2110 		  p_valid_to                 IN   DATE,
2111 		  p_target_date              IN   DATE,
2112 		  p_copied_from_library_id   IN   NUMBER,
2113 		  p_next_review_date         IN   DATE,
2114 		  p_group_code               IN   VARCHAR2,
2115 		  p_priority_code            IN   VARCHAR2,
2116 		  p_appraise_flag            IN   VARCHAR2,
2117 		  p_weighting_percent        IN   NUMBER,
2118 		  p_target_value             IN   NUMBER,
2119 		  p_uom_code                 IN   VARCHAR2,
2120 		  p_measurement_style_code   IN   VARCHAR2,
2121 		  p_measure_name             IN   VARCHAR2,
2122 		  p_measure_type_code        IN   VARCHAR2,
2123 		  p_measure_comments         IN   VARCHAR2,
2124 		  p_details                  IN   VARCHAR2,
2125 		  p_success_criteria         IN   VARCHAR2,
2126 		  p_comments                 IN   VARCHAR2
2127 	   )
2128 	   IS
2129 		  -- Declare local variables
2130 		  l_proc                           VARCHAR2 (72) := g_package || 'create_scorecard_objective';
2131 		  --
2132 		  l_objective_id                   NUMBER;
2133 		  l_object_version_number          NUMBER;
2134 		  l_duplicate_name_warning         BOOLEAN       := FALSE;
2135 		  l_comb_weight_over_100_warning   BOOLEAN       := FALSE;
2136 		  l_weighting_appraisal_warning    BOOLEAN       := FALSE;
2137 		  l_pc_v_act_mismatch_warning      BOOLEAN       := FALSE;
2138 		  l_quant_met_not_pc_warning       BOOLEAN       := FALSE;
2139 		  l_qual_met_not_pc_warning        BOOLEAN       := FALSE;
2140 		  --
2141 		  l_start_date                     DATE;
2142 		  l_target_date                    DATE;
2143 		  l_next_review_date               DATE;
2144 	   --
2145 	   BEGIN
2146 		  --
2147 		  IF g_dbg
2148 		  THEN
2149 			 op ('Entering:' || l_proc, g_regular_log, 10);
2150 		  END IF;
2151 
2152 		  --
2153 
2154 		  --
2155 		  -- Derive objective target date p_target_date < p_start date is added to fix 5233771
2156 		  --
2157 		  IF (p_target_date IS NULL OR p_target_date > p_end_date OR p_target_date < p_start_date)
2158 		  THEN
2159 			 l_target_date := p_end_date;
2160 		  ELSE
2161 			 l_target_date := p_target_date;
2162 		  END IF;
2163 
2164 		  -- while fixing 5233771, following is added to be in synch with Duncans mail
2165 		  -- and the same is incorporated in copy functionality from ui
2166 		  -- Derive Next review date
2167 		  --
2168 		  IF (p_next_review_date IS NULL OR p_next_review_date > p_end_date OR p_next_review_date < p_start_date)
2169 		  THEN
2170 			 l_next_review_date := NULL;
2171 		  ELSE
2172 			 l_next_review_date := p_next_review_date;
2173 		  END IF;
2174 
2175 		  --
2176 		  IF g_dbg
2177 		  THEN
2178 			 op ('Entering:' || l_proc, g_regular_log, 20);
2179 		  END IF;
2180 
2181 		  --
2182 
2183 		  --
2184 		  -- Call create_objective
2185 		  --
2186 		  hr_objectives_api.create_objective (p_effective_date                   => p_effective_date,
2187 											  p_business_group_id                => p_business_group_id
2188 	-- below param value is changed to -3 as per requirement.
2189 		  ,
2190 											  p_owning_person_id                 => -3                                   --p_person_id
2191 																					  ,
2192 											  p_scorecard_id                     => p_scorecard_id,
2193 											  p_start_date                       => p_start_date,
2194 											  p_name                             => p_objective_name,
2195 											  p_target_date                      => l_target_date,
2196 											  p_copied_from_library_id           => p_copied_from_library_id,
2197 											  p_next_review_date                 => l_next_review_date,
2198 											  p_group_code                       => p_group_code,
2199 											  p_priority_code                    => p_priority_code,
2200 											  p_appraise_flag                    => p_appraise_flag,
2201 											  p_weighting_percent                => p_weighting_percent,
2202 											  p_target_value                     => p_target_value,
2203 											  p_uom_code                         => p_uom_code,
2204 											  p_measurement_style_code           => p_measurement_style_code,
2205 											  p_measure_name                     => p_measure_name,
2206 											  p_measure_type_code                => p_measure_type_code,
2207 											  p_measure_comments                 => p_measure_comments,
2208 											  p_detail                           => p_details,
2209 											  p_comments                         => p_comments,
2210 											  p_success_criteria                 => p_success_criteria,
2211 											  p_objective_id                     => l_objective_id,
2212 											  p_object_version_number            => l_object_version_number
2213 	--    ,p_duplicate_name_warning         =>  l_duplicate_name_warning
2214 		  ,
2215 											  p_weighting_over_100_warning       => l_comb_weight_over_100_warning
2216 	--    ,p_comb_weight_over_100_warning   =>  l_comb_weight_over_100_warning
2217 		  ,
2218 											  p_weighting_appraisal_warning      => l_weighting_appraisal_warning
2219 	--    ,p_pc_v_act_mismatch_warning      =>  l_pc_v_act_mismatch_warning
2220 	--    ,p_quant_met_not_pc_warning       =>  l_quant_met_not_pc_warning
2221 	--    ,p_qual_met_not_pc_warning        =>  l_qual_met_not_pc_warning
2222 											 );
2223 
2224 		  --
2225 		  IF g_dbg
2226 		  THEN
2227 			 op ('Leaving:' || l_proc, g_regular_log, 80);
2228 		  END IF;
2229 	   --
2230 	   EXCEPTION
2231 		  WHEN OTHERS
2232 		  THEN
2233 			 IF g_dbg
2234 			 THEN
2235 				op ('Leaving:' || l_proc, g_regular_log, 90);
2236 			 END IF;
2237 
2238 			 --
2239 			 fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
2240 			 g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
2241 			 g_retcode := warning;
2242 			 g_errbuf := g_cp_error_txt;
2243 			 g_num_errors := g_num_errors + 1;
2244 
2245 			 IF g_dbg
2246 			 THEN
2247 				op (g_error_txt, g_regular_log);
2248 			 END IF;
2249 
2250 			 IF g_dbg
2251 			 THEN
2252 				op (SQLERRM, g_regular_log);
2253 			 END IF;
2254 
2255 			 --
2256 			 -- If the max number of errors has been exceeded, raise the error and
2257 			 -- terminate processing of this plan.
2258 			 --
2259 			 IF g_num_errors > g_max_errors
2260 			 THEN
2261 				fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
2262 				g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
2263 				g_retcode := error;
2264 				g_errbuf := g_error_txt;
2265 				RAISE;
2266 			 END IF;
2267 	   END create_scorecard_objective;
2268 
2269 	--
2270 	-- ----------------------------------------------------------------------------
2271 	-- |----------------------< update_scorecard_objective >----------------------|
2272 	-- ----------------------------------------------------------------------------
2273 	-- {Start Of Comments}
2274 	--
2275 	-- Description:
2276 	--   Updates objective for a given scorecard when plan is republished.
2277 	--
2278 	-- Prerequisites:
2279 	--   None.
2280 	--
2281 	-- In Arguments:
2282 	--
2283 	--
2284 	-- Post Success:
2285 	--  Processing continues if objective is updated.
2286 	--
2287 	-- Post Failure:
2288 	--  An application error is raised if objective is not updated.
2289 	--
2290 	-- Access Status:
2291 	--   Internal Only.
2292 	--
2293 	-- {End Of Comments}
2294 	-- ----------------------------------------------------------------------------
2295 	   PROCEDURE update_scorecard_objective (
2296 		  p_effective_date           IN   DATE,
2297 		  p_objective_id             IN   NUMBER,
2298 		  p_object_version_number    IN   NUMBER,
2299 		  p_scorecard_id             IN   NUMBER DEFAULT hr_api.g_number,
2300 		  p_start_date               IN   DATE DEFAULT hr_api.g_date,
2301 		  p_end_date                 IN   DATE DEFAULT hr_api.g_date,
2302 		  p_objective_name           IN   VARCHAR2 DEFAULT hr_api.g_varchar2,
2303 		  p_valid_from               IN   DATE DEFAULT hr_api.g_date,
2304 		  p_valid_to                 IN   DATE DEFAULT hr_api.g_date,
2305 		  p_target_date              IN   DATE DEFAULT hr_api.g_date,
2306 		  p_copied_from_library_id   IN   NUMBER DEFAULT hr_api.g_number,
2307 		  p_next_review_date         IN   DATE DEFAULT hr_api.g_date,
2308 		  p_group_code               IN   VARCHAR2 DEFAULT hr_api.g_varchar2,
2309 		  p_priority_code            IN   VARCHAR2 DEFAULT hr_api.g_varchar2,
2310 		  p_appraise_flag            IN   VARCHAR2 DEFAULT hr_api.g_varchar2,
2311 		  p_weighting_percent        IN   NUMBER DEFAULT hr_api.g_number,
2312 		  p_target_value             IN   NUMBER DEFAULT hr_api.g_number,
2313 		  p_uom_code                 IN   VARCHAR2 DEFAULT hr_api.g_varchar2,
2314 		  p_measurement_style_code   IN   VARCHAR2 DEFAULT hr_api.g_varchar2,
2315 		  p_measure_name             IN   VARCHAR2 DEFAULT hr_api.g_varchar2,
2316 		  p_measure_type_code        IN   VARCHAR2 DEFAULT hr_api.g_varchar2,
2317 		  p_measure_comments         IN   VARCHAR2 DEFAULT hr_api.g_varchar2,
2318 		  p_details                  IN   VARCHAR2 DEFAULT hr_api.g_varchar2,
2319 		  p_success_criteria         IN   VARCHAR2 DEFAULT hr_api.g_varchar2,
2320 		  p_comments                 IN   VARCHAR2 DEFAULT hr_api.g_varchar2
2321 	   )
2322 	   IS
2323 		  -- Declare local variables
2324 		  l_proc                           VARCHAR2 (72) := g_package || 'update_scorecard_objective';
2325 		  --
2326 		  l_object_version_number          NUMBER        := p_object_version_number;
2327 		  l_duplicate_name_warning         BOOLEAN       := FALSE;
2328 		  l_comb_weight_over_100_warning   BOOLEAN       := FALSE;
2329 		  l_weighting_appraisal_warning    BOOLEAN       := FALSE;
2330 		  l_pc_v_act_mismatch_warning      BOOLEAN       := FALSE;
2331 		  l_quant_met_not_pc_warning       BOOLEAN       := FALSE;
2332 		  l_qual_met_not_pc_warning        BOOLEAN       := FALSE;
2333 		  --
2334 		  l_start_date                     DATE;
2335 		  l_target_date                    DATE;
2336 		  l_next_review_date               DATE;
2337 	   --
2338 	   BEGIN
2339 		  --
2340 		  IF g_dbg
2341 		  THEN
2342 			 op ('Entering:' || l_proc, g_regular_log, 10);
2343 		  END IF;
2344 
2345 		  -- Call to lck for initiating per_obj_shd api to populate global variable.   Bug#14383575
2346 		  IF (p_objective_id IS NOT NULL AND p_object_version_number IS NOT NULL)
2347 		  THEN
2348 				per_obj_shd.lck(p_objective_id, p_object_version_number);
2349 		  ELSE
2350 				op('Lock on per_objectives not acquired:' || l_proc, g_regular_log, 30);
2351 		  END IF;
2352 
2353 	--
2354 		  --
2355 		  --
2356 		  -- Derive objective target date p_target_date < p_start date is added to fix 5233771
2357 		  --
2358 		  IF (p_target_date IS NULL OR p_target_date > p_end_date OR p_target_date < p_start_date)
2359 		  THEN
2360 			 l_target_date := p_end_date;
2361 		  ELSE
2362 			 l_target_date := p_target_date;
2363 		  END IF;
2364 
2365 		  -- while fixing 5233771, following is added to be in synch with Duncans mail
2366 		  -- and the same is incorporated in copy functionality from ui
2367 		  -- Derive Next review date
2368 		  --
2369 		  IF (p_next_review_date IS NULL OR p_next_review_date > p_end_date OR p_next_review_date < p_start_date)
2370 		  THEN
2371 			 l_next_review_date := NULL;
2372 		  ELSE
2373 			 l_next_review_date := p_next_review_date;
2374 		  END IF;
2375 
2376 		  --
2377 		  IF g_dbg
2378 		  THEN
2379 			 op ('Entering:' || l_proc, g_regular_log, 20);
2380 		  END IF;
2381 
2382 		  --
2383 
2384 		  --
2385 		  -- Call update_objective
2386 		  --
2387 		  /* KGOWRIPE: removing the update API call for bug#10289224. This is to take care of the OVN getting
2388 			 incremented when the plan is republished for Library objectives.
2389 		   */
2390 		  /*
2391 		  hr_objectives_api.update_objective
2392 										(p_effective_date                   => p_effective_date,
2393 										 p_objective_id                     => p_objective_id,
2394 										 p_object_version_number            => l_object_version_number,
2395 										 p_scorecard_id                     => p_scorecard_id,
2396 										 p_start_date                       => p_start_date,
2397 										 p_name                             => p_objective_name,
2398 										 p_target_date                      => l_target_date,
2399 										 p_copied_from_library_id           => p_copied_from_library_id,
2400 										 p_next_review_date                 => l_next_review_date,
2401 										 p_group_code                       => p_group_code,
2402 										 p_priority_code                    => p_priority_code,
2403 										 p_appraise_flag                    => p_appraise_flag,
2404 										 p_weighting_percent                => p_weighting_percent,
2405 										 p_target_value                     => p_target_value,
2406 										 p_uom_code                         => p_uom_code,
2407 										 p_measurement_style_code           => p_measurement_style_code,
2408 										 p_measure_name                     => p_measure_name,
2409 										 p_measure_type_code                => p_measure_type_code,
2410 										 p_measure_comments                 => p_measure_comments,
2411 										 p_detail                           => p_details,
2412 										 p_comments                         => p_comments,
2413 										 p_success_criteria                 => p_success_criteria
2414 																								 --    ,p_duplicate_name_warning         =>  l_duplicate_name_warning
2415 		  ,
2416 										 p_weighting_over_100_warning       => l_comb_weight_over_100_warning
2417 																											 --    ,p_comb_weight_over_100_warning   =>  l_comb_weight_over_100_warning
2418 		  ,
2419 										 p_weighting_appraisal_warning      => l_weighting_appraisal_warning
2420 										--    ,p_pc_v_act_mismatch_warning      =>  l_pc_v_act_mismatch_warning
2421 										--    ,p_quant_met_not_pc_warning       =>  l_quant_met_not_pc_warning
2422 										--    ,p_qual_met_not_pc_warning        =>  l_qual_met_not_pc_warning
2423 										);
2424 		   */
2425 	  -- We must now examine each argument value in the
2426 	  -- procedure to see if a system default is being used. If a system default
2427 	  -- is being used then we must set to the 'current' argument value.
2428 
2429 		   UPDATE     per_objectives
2430 		   SET        scorecard_id = decode(p_scorecard_id,hr_api.g_number,per_obj_shd.g_old_rec.scorecard_id,p_scorecard_id)
2431 					 ,start_date   = decode(p_start_date,hr_api.g_date,per_obj_shd.g_old_rec.start_date,p_start_date)
2432 					 ,name         = decode(p_objective_name,hr_api.g_varchar2,per_obj_shd.g_old_rec.name,p_objective_name)
2433 					 ,target_date  = l_target_date
2434 					 ,copied_from_library_id = decode(p_copied_from_library_id,hr_api.g_number,per_obj_shd.g_old_rec.copied_from_library_id,p_copied_from_library_id)
2435 					 ,next_review_date = l_next_review_date
2436 					 ,group_code = decode(p_group_code,hr_api.g_varchar2,per_obj_shd.g_old_rec.group_code,p_group_code)
2437 					 ,priority_code = decode(p_priority_code,hr_api.g_varchar2,per_obj_shd.g_old_rec.priority_code,p_priority_code)
2438 					 ,appraise_flag = decode(p_appraise_flag,hr_api.g_varchar2,per_obj_shd.g_old_rec.appraise_flag,p_appraise_flag)
2439 					 ,weighting_percent = decode(p_weighting_percent,hr_api.g_number,per_obj_shd.g_old_rec.weighting_percent,p_weighting_percent)
2440 					 ,target_value  = decode(p_target_value,hr_api.g_number,per_obj_shd.g_old_rec.target_value,p_target_value)
2441 					 ,uom_code      = decode(p_uom_code,hr_api.g_varchar2,per_obj_shd.g_old_rec.uom_code,p_uom_code)
2442 					 ,measurement_style_code = decode(p_measurement_style_code,hr_api.g_varchar2,per_obj_shd.g_old_rec.measurement_style_code,p_measurement_style_code)
2443 					 ,measure_name  = decode(p_measure_name,hr_api.g_varchar2,per_obj_shd.g_old_rec.measure_name,p_measure_name)
2444 					 ,measure_type_code = decode(p_measure_type_code,hr_api.g_varchar2,per_obj_shd.g_old_rec.measure_type_code,p_measure_type_code)
2445 					 ,measure_comments = decode(p_measure_comments,hr_api.g_varchar2,per_obj_shd.g_old_rec.measure_comments,p_measure_comments)
2446 					 ,detail = decode(p_details,hr_api.g_varchar2,per_obj_shd.g_old_rec.detail,p_details)
2447 					 ,comments = decode(p_comments,hr_api.g_varchar2,per_obj_shd.g_old_rec.comments,p_comments)
2448 					 ,success_criteria = decode(p_success_criteria,hr_api.g_varchar2,per_obj_shd.g_old_rec.success_criteria,p_success_criteria)
2449 		   WHERE     objective_id = p_objective_id;
2450 
2451 		  --
2452 		  IF g_dbg
2453 		  THEN
2454 			 op ('Leaving:' || l_proc, g_regular_log, 80);
2455 		  END IF;
2456 	   --
2457 	   EXCEPTION
2458 		  WHEN OTHERS
2459 		  THEN
2460 			 IF g_dbg
2461 			 THEN
2462 				op ('Leaving:' || l_proc, g_regular_log, 90);
2463 			 END IF;
2464 
2465 			 --
2466 			 fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
2467 			 g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
2468 			 g_retcode := warning;
2469 			 g_errbuf := g_cp_error_txt;
2470 			 g_num_errors := g_num_errors + 1;
2471 
2472 			 IF g_dbg
2473 			 THEN
2474 				op (g_error_txt, g_regular_log);
2475 			 END IF;
2476 
2477 			 IF g_dbg
2478 			 THEN
2479 				op (SQLERRM, g_regular_log);
2480 			 END IF;
2481 
2482 			 --
2483 			 -- If the max number of errors has been exceeded, raise the error and
2484 			 -- terminate processing of this plan.
2485 			 --
2486 			 IF g_num_errors > g_max_errors
2487 			 THEN
2488 				fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
2489 				g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
2490 				g_retcode := error;
2491 				g_errbuf := g_error_txt;
2492 				RAISE;
2493 			 END IF;
2494 	   END update_scorecard_objective;
2495 
2496 	--
2497 	-- ----------------------------------------------------------------------------
2498 	-- |----------------------< delete_scorecard_objective >---------------------|
2499 	-- ----------------------------------------------------------------------------
2500 	-- {Start Of Comments}
2501 	--
2502 	-- Description:
2503 	--   Deletes a given objective.
2504 	--
2505 	-- Prerequisites:
2506 	--   None.
2507 	--
2508 	-- In Arguments:
2509 	--
2510 	--
2511 	-- Post Success:
2512 	--  Processing continues if objective is deleted.
2513 	--
2514 	-- Post Failure:
2515 	--  An application error is raised if objective is not deleted.
2516 	--
2517 	-- Access Status:
2518 	--   Internal Only.
2519 	--
2520 	-- {End Of Comments}
2521 	-- ----------------------------------------------------------------------------
2522 	   PROCEDURE delete_scorecard_objective (p_objective_id IN NUMBER, p_object_version_number IN NUMBER)
2523 	   IS
2524 		  -- Declare local variables
2525 		  l_proc   VARCHAR2 (72) := g_package || 'delete_scorecard_objective';
2526 	   --
2527 	   BEGIN
2528 		  --
2529 		  IF g_dbg
2530 		  THEN
2531 			 op ('Entering:' || l_proc, g_regular_log, 10);
2532 		  END IF;
2533 
2534 		  --
2535 
2536 		  --
2537 		  -- Call delete_objective
2538 		  --
2539 		  hr_objectives_api.delete_objective (p_objective_id => p_objective_id, p_object_version_number => p_object_version_number);
2540 
2541 		  --
2542 		  IF g_dbg
2543 		  THEN
2544 			 op ('Leaving:' || l_proc, g_regular_log, 80);
2545 		  END IF;
2546 	   --
2547 	   EXCEPTION
2548 		  WHEN OTHERS
2549 		  THEN
2550 			 IF g_dbg
2551 			 THEN
2552 				op ('Leaving:' || l_proc, g_regular_log, 90);
2553 			 END IF;
2554 
2555 			 --
2556 			 fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
2557 			 g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
2558 			 g_retcode := warning;
2559 			 g_errbuf := g_cp_error_txt;
2560 			 g_num_errors := g_num_errors + 1;
2561 
2562 			 IF g_dbg
2563 			 THEN
2564 				op (g_error_txt, g_regular_log);
2565 			 END IF;
2566 
2567 			 IF g_dbg
2568 			 THEN
2569 				op (SQLERRM, g_regular_log);
2570 			 END IF;
2571 
2572 			 --
2573 			 -- If the max number of errors has been exceeded, raise the error and
2574 			 -- terminate processing of this plan.
2575 			 --
2576 			 IF g_num_errors > g_max_errors
2577 			 THEN
2578 				fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
2579 				g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
2580 				g_retcode := error;
2581 				g_errbuf := g_error_txt;
2582 				RAISE;
2583 			 END IF;
2584 	   END delete_scorecard_objective;
2585 
2586 	   FUNCTION get_appraisal_config_params (
2587 		  p_appr_initiator_code   IN              per_appraisal_periods.initiator_code%TYPE,
2588 		  p_function_id           IN OUT NOCOPY   fnd_form_functions.function_id%TYPE,
2589 		  p_function_name         IN OUT NOCOPY   fnd_form_functions.function_name%TYPE,
2590 		  p_func_parameters       IN OUT NOCOPY   fnd_form_functions.PARAMETERS%TYPE,
2591 		  p_appraisal_sys_type    IN OUT NOCOPY   per_appraisals.appraisal_system_status%TYPE
2592 	   )
2593 		  RETURN BOOLEAN
2594 	   IS
2595 		  l_resp_id               NUMBER;
2596 		  l_appraisal_mgr_menu    fnd_menus.menu_name%TYPE                DEFAULT NULL;
2597 		  l_appraisal_empl_menu   fnd_menus.menu_name%TYPE                DEFAULT NULL;
2598 		  l_selected_menu         fnd_menus.menu_name%TYPE                DEFAULT NULL;
2599 		  l_function_id           fnd_form_functions.function_id%TYPE;
2600 		  l_function_name         fnd_form_functions.function_name%TYPE;
2601 		  l_initiation_type       VARCHAR2 (10)                           DEFAULT NULL;
2602 		  l_func_params           fnd_form_functions.PARAMETERS%TYPE;
2603 		  l_system_type           VARCHAR2 (50);
2604 		  l_menu_id               fnd_menus.menu_id%TYPE;
2605 
2606 		  CURSOR get_appraisal_function (p_menu_name fnd_menus.menu_name%TYPE, p_search_func VARCHAR2)
2607 		  IS
2608 			 SELECT menu_functions.function_id, ff.function_name, ff.PARAMETERS, menu_id
2609 			   FROM fnd_compiled_menu_functions menu_functions, fnd_form_functions ff
2610 			  WHERE menu_id = (SELECT menu_id
2611 								 FROM fnd_menus
2612 								WHERE menu_name = p_menu_name)
2613 				AND ff.function_id = menu_functions.function_id
2614 				AND ff.PARAMETERS LIKE p_search_func;
2615 	   BEGIN
2616 		  -- to be derived from plan id
2617 
2618 		  /*
2619 			  fnd_global.apps_initialize(user_id =>1922,
2620 											resp_id =>21540,
2621 											resp_appl_id=> 800);
2622 		  */
2623 		  IF g_dbg
2624 		  THEN
2625 			 op ('p_appr_initiator_code = ' || p_appr_initiator_code, g_debug_log);
2626 		  END IF;
2627 
2628 		  IF g_dbg
2629 		  THEN
2630 			 op ('login person = ' || fnd_global.user_id, g_debug_log);
2631 		  END IF;
2632 
2633 		  IF g_dbg
2634 		  THEN
2635 			 op ('login name = ' || fnd_global.user_name, g_debug_log);
2636 		  END IF;
2637 
2638 		  IF g_dbg
2639 		  THEN
2640 			 op ('resp id = ' || fnd_global.resp_id, g_debug_log);
2641 		  END IF;
2642 
2643 		  l_initiation_type := 'MGR';
2644 		  l_resp_id := fnd_global.resp_id;
2645 		  l_appraisal_mgr_menu := fnd_profile.value_specific (NAME => 'HR_MANAGER_APPRAISALS_MENU', responsibility_id => l_resp_id);
2646 
2647 		  IF g_dbg
2648 		  THEN
2649 			 op ('MGR MENU = ' || fnd_profile.VALUE ('HR_MANAGER_APPRAISALS_MENU'), g_debug_log);
2650 		  END IF;
2651 
2652 		  IF g_dbg
2653 		  THEN
2654 			 op ('EMP MENU = ' || fnd_profile.VALUE ('HR_WORKER_APPRAISALS_MENU'), g_debug_log);
2655 		  END IF;
2656 
2657 		  IF g_dbg
2658 		  THEN
2659 			 op ('l_appraisal_mgr_menu = ' || l_appraisal_mgr_menu, g_debug_log);
2660 		  END IF;
2661 
2662 		  l_appraisal_empl_menu := fnd_profile.value_specific (NAME => 'HR_WORKER_APPRAISALS_MENU', responsibility_id => l_resp_id);
2663 
2664 		  IF g_dbg
2665 		  THEN
2666 			 op ('l_appraisal_empl_menu = ' || l_appraisal_empl_menu, g_debug_log);
2667 		  END IF;
2668 
2669 		  IF (p_appr_initiator_code = 'MGR' AND l_appraisal_mgr_menu IS NOT NULL)
2670 		  THEN
2671 			 l_selected_menu := l_appraisal_mgr_menu;
2672 			 p_appraisal_sys_type := p_appr_initiator_code || p_appraisal_sys_type;
2673 			 l_system_type := '%' || p_appr_initiator_code || p_appraisal_sys_type || '%';
2674 		  ELSIF (p_appr_initiator_code = 'EMP' AND l_appraisal_empl_menu IS NOT NULL)
2675 		  THEN
2676 			 l_selected_menu := l_appraisal_empl_menu;
2677 			 p_appraisal_sys_type := p_appr_initiator_code || p_appraisal_sys_type;
2678 			 l_system_type := '%' || p_appr_initiator_code || p_appraisal_sys_type || '%';
2679 		  END IF;
2680 
2681 		  IF g_dbg
2682 		  THEN
2683 			 op ('l_selected_menu = ' || l_selected_menu, g_debug_log);
2684 		  END IF;
2685 
2686 		  OPEN get_appraisal_function (l_selected_menu, l_system_type);
2687 
2688 		  FETCH get_appraisal_function
2689 		   INTO l_function_id, l_function_name, l_func_params, l_menu_id;
2690 
2691 		  IF get_appraisal_function%NOTFOUND
2692 		  THEN
2693 			 RETURN FALSE;
2694 		  ELSE
2695 			 p_function_id := l_function_id;
2696 			 p_function_name := l_function_name;
2697 			 p_func_parameters :=
2698 				   l_func_params
2699 				|| '&'
2700 				|| 'pFunctionId='
2701 				|| l_function_id
2702 				|| '&'
2703 				|| 'pMenuId='
2704 				|| l_menu_id
2705 				|| '&'
2706 				|| 'OAFunc='
2707 				|| l_function_name;
2708 		  END IF;
2709 
2710 		  IF g_dbg
2711 		  THEN
2712 			 op ('l_function_id = ' || l_function_id, g_debug_log);
2713 		  END IF;
2714 
2715 		  IF g_dbg
2716 		  THEN
2717 			 op ('l_function_name = ' || l_function_name, g_debug_log);
2718 		  END IF;
2719 
2720 		  RETURN TRUE;
2721 	   EXCEPTION
2722 		  WHEN OTHERS
2723 		  THEN
2724 			 IF g_dbg
2725 			 THEN
2726 				op (SQLERRM, g_regular_log);
2727 			 END IF;
2728 
2729 			 RAISE;
2730 	   END;
2731 
2732 	   PROCEDURE apply_overridding_rules (
2733 		  p_enterprise_id     IN              NUMBER,
2734 		  p_organization_id   IN              NUMBER,
2735 		  p_job_id            IN              NUMBER,
2736 		  p_position_id       IN              NUMBER,
2737 		  p_skip_duplicate                    BOOLEAN,
2738 		  l_sel_comp_table    IN OUT NOCOPY   sel_comp_tab
2739 	   )
2740 	   IS
2741 		  CURSOR get_asgn_req_comps (enterprise_id NUMBER, org_id NUMBER, job_id NUMBER, pos_id NUMBER)
2742 		  IS
2743 			 SELECT pc.NAME competence_name, pce.competence_id, pce.competence_element_id, pce.mandatory, pce.proficiency_level_id,
2744 					pce.high_proficiency_level_id, pce.organization_id, NVL (pce.job_id, -1) job_id,
2745 					NVL (pce.position_id, -1) position_id, pce.valid_grade_id, NVL (pce.business_group_id, -1) business_group_id,
2746 					pce.enterprise_id, hrl.meaning structure_type,
2747 					DECODE (job_id, NULL, DECODE (position_id, NULL, 1, 0), 0) read_only_attr, 0 detail_attr, pc.competence_alias,
2748 					DECODE (pc.business_group_id, NULL, 'Y', 'N') GLOBAL, pc.description, pc.date_from, pc.certification_required,
2749 					pc.behavioural_indicator, r1.step_value low_step_value, r1.NAME low_step_name, r2.step_value high_step_value,
2750 					r2.NAME high_step_name, hrl.lookup_code,
2751 					DECODE (r1.step_value, NULL, NULL, r1.step_value || ' - ' || r1.NAME) minimum_proficiency,
2752 					DECODE (r2.step_value, NULL, NULL, r2.step_value || ' - ' || r2.NAME) maximum_proficiency, pce.TYPE
2753 			   FROM per_competence_elements pce,
2754 					per_competences_vl pc,
2755 					hr_lookups hrl,
2756 					per_rating_levels_vl r1,
2757 					per_rating_levels_vl r2
2758 			  WHERE pce.TYPE = 'REQUIREMENT'
2759 				AND pce.competence_id = pc.competence_id
2760 				AND TRUNC (SYSDATE) BETWEEN NVL (pce.effective_date_from, TRUNC (SYSDATE))
2761 										AND NVL (pce.effective_date_to, TRUNC (SYSDATE))
2762 				AND hrl.lookup_type(+) = 'STRUCTURE_TYPE'
2763 				AND hrl.lookup_code(+) =
2764 					   DECODE (pce.organization_id,
2765 							   NULL, (DECODE (pce.job_id, NULL, (DECODE (pce.position_id, NULL, 'BUS', 'POS')), 'JOB')),
2766 							   'ORG'
2767 							  )
2768 				AND pce.proficiency_level_id = r1.rating_level_id(+)
2769 				AND pce.high_proficiency_level_id = r2.rating_level_id(+)
2770 				AND pce.business_group_id = enterprise_id
2771 				AND (   pce.enterprise_id = NVL (enterprise_id, -1)
2772 					 OR pce.organization_id = NVL (org_id, -1)
2773 					 OR pce.job_id = NVL (job_id, -1)
2774 					 OR pce.position_id = NVL (pos_id, -1)
2775 					);
2776 
2777 		  l_mat_comp_table        sel_comp_tab;
2778 		  i                       INTEGER      DEFAULT 0;
2779 		  issamecompetence        BOOLEAN      DEFAULT FALSE;
2780 		  issamestructuretype     BOOLEAN      DEFAULT FALSE;
2781 		  isignore                BOOLEAN      DEFAULT FALSE;
2782 		  isbessential            BOOLEAN      DEFAULT FALSE;
2783 		  isbdesired              BOOLEAN      DEFAULT FALSE;
2784 		  markouterrowforignore   BOOLEAN;
2785 		  isessentialdesired      BOOLEAN;
2786 	   BEGIN
2787 		  IF g_dbg
2788 		  THEN
2789 			 op ('p_enterprise_id = ' || p_enterprise_id, g_debug_log);
2790 		  END IF;
2791 
2792 		  IF g_dbg
2793 		  THEN
2794 			 op ('p_organization_id = ' || p_organization_id, g_debug_log);
2795 		  END IF;
2796 
2797 		  IF g_dbg
2798 		  THEN
2799 			 op ('p_job_id = ' || p_job_id, g_debug_log);
2800 		  END IF;
2801 
2802 		  IF g_dbg
2803 		  THEN
2804 			 op ('p_position_id = ' || p_position_id, g_debug_log);
2805 		  END IF;
2806 
2807 		  OPEN get_asgn_req_comps (p_enterprise_id, p_organization_id, p_job_id, p_position_id);
2808 
2809 		  FETCH get_asgn_req_comps
2810 		  BULK COLLECT INTO l_sel_comp_table;
2811 
2812 		  CLOSE get_asgn_req_comps;
2813 
2814 		  l_mat_comp_table := l_sel_comp_table;
2815 
2816 	-- execute the cursor and apply the overriding rules
2817 		  FOR j IN 1 .. l_sel_comp_table.COUNT
2818 		  LOOP
2819 			 markouterrowforignore := FALSE;
2820 
2821 			 FOR k IN 1 .. l_mat_comp_table.COUNT
2822 			 LOOP
2823 				BEGIN
2824 				   issamecompetence := (l_sel_comp_table (j).competence_id = l_mat_comp_table (k).competence_id);
2825 				   issamestructuretype := (l_sel_comp_table (j).lookup_code = l_mat_comp_table (k).lookup_code);
2826 				   isignore := ('I' = l_mat_comp_table (k).mandatory);
2827 
2828 				   IF (NOT isignore AND issamecompetence AND NOT issamestructuretype)
2829 				   THEN
2830 					  IF ('POS' = l_mat_comp_table (k).lookup_code)
2831 					  THEN
2832 						 markouterrowforignore := TRUE;
2833 						 GOTO end_block;
2834 					  END IF;
2835 
2836 					  IF (('POS' = l_sel_comp_table (j).lookup_code) AND (NOT 'POS' = l_mat_comp_table (k).lookup_code))
2837 					  THEN
2838 						 l_mat_comp_table (k).mandatory := 'I';
2839 						 GOTO end_block;
2840 					  END IF;
2841 
2842 					  isbessential := ('Y' = l_mat_comp_table (k).mandatory AND 'Y' = l_sel_comp_table (j).mandatory);
2843 					  isbdesired := ('N' = l_mat_comp_table (k).mandatory AND 'N' = l_sel_comp_table (j).mandatory);
2844 
2845 					  IF (isbessential AND 'ORG' = l_sel_comp_table (j).lookup_code AND 'JOB' = l_mat_comp_table (k).lookup_code)
2846 					  THEN
2847 						 l_mat_comp_table (k).mandatory := 'I';
2848 						 GOTO end_block;
2849 					  END IF;
2850 
2851 					  IF (isbessential AND 'JOB' = l_sel_comp_table (j).lookup_code AND 'ORG' = l_mat_comp_table (k).lookup_code)
2852 					  THEN
2853 						 markouterrowforignore := TRUE;
2854 						 GOTO end_block;
2855 					  END IF;
2856 
2857 					  IF (    isbdesired
2858 						  AND (   ('ORG' = l_sel_comp_table (j).lookup_code AND 'JOB' = l_mat_comp_table (k).lookup_code)
2859 							   OR ('JOB' = l_sel_comp_table (j).lookup_code AND 'ORG' = l_mat_comp_table (k).lookup_code)
2860 							  )
2861 						 )
2862 					  THEN
2863 						 IF ((l_mat_comp_table (k).low_step_value IS NOT NULL) AND (l_sel_comp_table (j).low_step_value IS NOT NULL)
2864 							)
2865 						 THEN
2866 							--fix for bug 3063145.
2867 							IF (l_mat_comp_table (k).low_step_value >= l_sel_comp_table (j).low_step_value)
2868 							THEN
2869 							   l_sel_comp_table (j).low_step_value := l_mat_comp_table (k).low_step_value;
2870 							   l_mat_comp_table (k).mandatory := 'I';
2871 							END IF;
2872 						 ELSIF (l_mat_comp_table (k).low_step_value IS NOT NULL AND l_sel_comp_table (j).low_step_value IS NULL)
2873 						 THEN
2874 							l_sel_comp_table (j).low_step_value := l_mat_comp_table (k).low_step_value;
2875 							l_mat_comp_table (k).mandatory := 'I';
2876 						 ELSE
2877 							l_mat_comp_table (k).mandatory := 'I';
2878 						 END IF;
2879 
2880 						 IF (    (l_mat_comp_table (k).high_step_value IS NOT NULL)
2881 							 AND (l_sel_comp_table (j).high_step_value IS NOT NULL)
2882 							)
2883 						 THEN
2884 							--fix for bug 3063145.
2885 							IF (l_mat_comp_table (k).high_step_value <= l_sel_comp_table (j).high_step_value)
2886 							THEN
2887 							   l_sel_comp_table (j).high_step_value := l_mat_comp_table (k).high_step_value;
2888 							   l_mat_comp_table (k).mandatory := 'I';
2889 							END IF;
2890 						 ELSIF ((l_mat_comp_table (k).high_step_value IS NOT NULL) AND (l_sel_comp_table (j).high_step_value IS NULL)
2891 							   )
2892 						 THEN
2893 							l_sel_comp_table (j).high_step_value := l_mat_comp_table (k).high_step_value;
2894 							l_mat_comp_table (k).mandatory := 'I';
2895 						 ELSE
2896 							l_mat_comp_table (k).mandatory := 'I';
2897 						 END IF;
2898 					  END IF;
2899 
2900 					  IF (p_skip_duplicate)
2901 					  THEN
2902 						 isessentialdesired :=
2903 							(   ('Y' = l_sel_comp_table (j).mandatory AND 'N' = l_mat_comp_table (k).mandatory)
2904 							 OR ('N' = l_sel_comp_table (j).mandatory AND 'Y' = l_mat_comp_table (k).mandatory)
2905 							);
2906 
2907 						 IF (       isessentialdesired
2908 								AND (('ORG' = l_sel_comp_table (j).lookup_code AND 'JOB' = l_mat_comp_table (k).lookup_code))
2909 							 OR (('ORG' = l_mat_comp_table (k).lookup_code AND 'JOB' = l_sel_comp_table (j).lookup_code))
2910 							)
2911 						 THEN
2912 							l_mat_comp_table (k).mandatory := 'I';
2913 						 END IF;
2914 					  END IF;
2915 
2916 					  IF ('BUS' = l_sel_comp_table (j).lookup_code AND 'BUS' = l_mat_comp_table (k).lookup_code)
2917 					  THEN
2918 						 l_mat_comp_table (k).mandatory := 'I';
2919 					  END IF;
2920 				   END IF;
2921 
2922 				   <<end_block>>
2923 				   NULL;
2924 				END;
2925 			 END LOOP;
2926 
2927 			 IF (markouterrowforignore)
2928 			 THEN
2929 				l_sel_comp_table (j).mandatory := 'I';
2930 			 END IF;
2931 
2932 			 FOR i IN 1 .. l_sel_comp_table.COUNT
2933 			 LOOP
2934 				IF (l_sel_comp_table (i).mandatory = 'I')
2935 				THEN
2936 				   l_sel_comp_table (i) := NULL;
2937 				END IF;
2938 			 END LOOP;
2939 		  END LOOP;
2940 
2941 		  FOR j IN 1 .. l_sel_comp_table.COUNT
2942 		  LOOP
2943 			 IF g_dbg
2944 			 THEN
2945 				op (' from overriding comp = ' || l_sel_comp_table (j).competence_id || '   ' || l_sel_comp_table (j).NAME,
2946 					g_debug_log
2947 				   );
2948 			 END IF;
2949 		  END LOOP;
2950 	   END apply_overridding_rules;
2951 
2952 	-- ----------------------------------------------------------------------------
2953 	-- |----------------------< create_appraisal_for_person >---------------------|
2954 	-- ----------------------------------------------------------------------------
2955 	-- {Start Of Comments}
2956 	--
2957 	-- Description:
2958 	--   Creates Appraisal for a given person when plan is published.
2959 	--
2960 	-- Prerequisites:
2961 	--   None.
2962 	--
2963 	-- In Arguments:
2964 	--
2965 	--
2966 	-- Post Success:
2967 	--  Processing continues if Appraisal is created.
2968 	--
2969 	-- Post Failure:
2970 	--  An application error is raised if scorecard is not created.
2971 	--
2972 	-- Access Status:
2973 	--   Internal Only.
2974 	--
2975 	-- {End Of Comments}
2976 	-- ----------------------------------------------------------------------------
2977 	   PROCEDURE create_appraisal_for_person (
2978 		  p_score_card_id                       per_personal_scorecards.scorecard_id%TYPE,
2979 		  p_appraisal_templ_id                  per_appraisal_templates.appraisal_template_id%TYPE,
2980 		  p_effective_date                      DATE,
2981 		  p_appraisal_start_date                DATE,
2982 		  p_appraisal_end_date                  DATE,
2983 		  p_appraisal_status                    per_appraisals.status%TYPE DEFAULT 'PLANNED',
2984 		  p_type                                per_appraisals.TYPE%TYPE DEFAULT NULL,
2985 		  p_appraisal_date                      per_appraisals.appraisal_date%TYPE,
2986 	--       p_appraisal_system_status per_appraisals.appraisal_system_status%TYPE,
2987 		  p_plan_id                             NUMBER,
2988 		  p_next_appraisal_date                 per_appraisals.next_appraisal_date%TYPE DEFAULT NULL,
2989 		  p_status                              per_appraisals.status%TYPE DEFAULT NULL,
2990 		  p_comments                            per_appraisals.comments%TYPE DEFAULT NULL,
2991 		  p_appraisee_access                    per_appraisals.appraisee_access%TYPE DEFAULT NULL,
2992 		  p_appraisal_initiator                 per_appraisal_periods.initiator_code%TYPE,
2993 		  p_return_status          OUT NOCOPY   VARCHAR2
2994 	   )
2995 	   IS
2996 		  CURSOR get_scorecard_info (p_scorecard_id per_personal_scorecards.scorecard_id%TYPE)
2997 		  IS
2998 			 SELECT scorecard_id, assignment_id, person_id, scorecard_name
2999 			   FROM per_personal_scorecards
3000 			  WHERE scorecard_id = p_scorecard_id;
3001 
3002 		  CURSOR get_assignment_info (p_assignment_id per_all_assignments_f.assignment_id%TYPE)
3003 		  IS
3004 			 SELECT assignment_id, business_group_id, grade_id, position_id, job_id, organization_id, supervisor_id,
3005 					effective_start_date
3006 			   FROM per_all_assignments_f
3007 			  WHERE assignment_id = p_assignment_id AND TRUNC (SYSDATE) BETWEEN effective_start_date AND effective_end_date;
3008 
3009 		  CURSOR get_appraisal_templ_info (p_appraisal_templ_id per_appraisals.appraisal_template_id%TYPE)
3010 		  IS
3011 			 SELECT appraisal_template_id, assessment_type_id, objective_asmnt_type_id, business_group_id
3012 			   FROM per_appraisal_templates
3013 			  WHERE appraisal_template_id = p_appraisal_templ_id;
3014 
3015 		  CURSOR get_assess_templ_comps (p_assess_type_id per_competence_elements.assessment_type_id%TYPE)
3016 		  IS
3017 			 SELECT ce.competence_id, ce.competence_element_id, ce.TYPE, ce.parent_competence_element_id, c.NAME,
3018 					RANK () OVER (PARTITION BY ce.competence_id ORDER BY ce.competence_element_id) RANK
3019 			   FROM per_competence_elements a, per_competence_elements ce, per_competences_vl c
3020 			  WHERE a.assessment_type_id = p_assess_type_id
3021 				AND a.TYPE = 'ASSESSMENT_GROUP'
3022 				AND (NVL (c.date_from, TRUNC (SYSDATE)) <= TRUNC (SYSDATE))
3023 				AND NVL (c.date_to, TRUNC (SYSDATE)) >= TRUNC (SYSDATE)
3024 				AND a.competence_element_id = ce.parent_competence_element_id
3025 				AND ce.competence_id = c.competence_id;
3026 
3027 		  CURSOR check_default_job_competency (p_assessment_type_id per_assessment_types.assessment_type_id%TYPE)
3028 		  IS
3029 			 SELECT default_job_competencies
3030 			   FROM per_assessment_types
3031 			  WHERE assessment_type_id = p_assessment_type_id;
3032 
3033 		  CURSOR get_scorecard_objectives (p_scorecard_id per_objectives.scorecard_id%TYPE)
3034 		  IS
3035 			 SELECT objective_id, scorecard_id, object_version_number, NAME
3036 			   FROM per_objectives
3037 			  WHERE scorecard_id = p_scorecard_id AND appraise_flag = 'Y';
3038 
3039 		  CURSOR get_assess_templ_info (p_assess_templ per_appraisal_templates.assessment_type_id%TYPE)
3040 		  IS
3041 			 SELECT default_job_competencies, assessment_type_id
3042 			   FROM per_assessment_types
3043 			  WHERE assessment_type_id = p_assess_templ;
3044 
3045 		  l_scorecard_info                scorecard_info;
3046 		  no_score_card_with_this_id      EXCEPTION;
3047 		  l_assignment_info               assignment_info;
3048 		  no_assignment_with_this_id      EXCEPTION;
3049 		  l_appraisal_ovn                 per_appraisals.object_version_number%TYPE;
3050 		  l_apprl_return_status           VARCHAR2 (10)                                        DEFAULT NULL;
3051 		  l_assess_comp_return_status     VARCHAR2 (10)                                        DEFAULT NULL;
3052 		  l_assess_obj_return_status      VARCHAR2 (10)                                        DEFAULT NULL;
3053 		  l_apprl_id                      per_appraisals.appraisal_id%TYPE                     DEFAULT NULL;
3054 		  l_apprl_templ_info              appraisal_templ_info;
3055 		  no_apprl_templ_with_this_id     EXCEPTION;
3056 		  l_assessment_comp_id            per_assessments.assessment_id%TYPE;
3057 		  l_assessment_obj_id             per_assessments.assessment_id%TYPE;
3058 		  l_assessment_comp_ovn           per_assessments.object_version_number%TYPE;
3059 		  l_assessment_obj_ovn            per_assessments.object_version_number%TYPE;
3060 		  l_assess_comps                  assess_comps_info;
3061 		  l_check_default_job_comps       VARCHAR2 (2)                                         DEFAULT '';
3062 		  l_comp_ele_id                   per_competence_elements.competence_element_id%TYPE;
3063 		  l_comp_ovn                      per_competence_elements.object_version_number%TYPE;
3064 		  l_return_status                 VARCHAR2 (10)                                        DEFAULT '';
3065 		  l_competence_error              VARCHAR2 (1000)                                      DEFAULT NULL;
3066 		  module_name                     VARCHAR2 (100)                                       DEFAULT 'MASS APPRAISAL CREATION';
3067 		  l_error_message                 VARCHAR2 (1000)                                      DEFAULT NULL;
3068 		  appraisal_creation_error        EXCEPTION;
3069 		  assess_comp_error               EXCEPTION;
3070 		  assess_obj_error                EXCEPTION;
3071 		  l_appraisal_sys_type            VARCHAR2 (10);
3072 		  function_360_exists             BOOLEAN                                              DEFAULT FALSE;
3073 		  appraisal_system_type_error     EXCEPTION;
3074 		  l_weighting_over_100_warning    BOOLEAN;
3075 		  l_weighting_appraisal_warning   BOOLEAN;
3076 		  no_apprl_function_defined       EXCEPTION;
3077 		  l_function_id                   fnd_form_functions.function_id%TYPE;
3078 		  l_function_name                 fnd_form_functions.function_name%TYPE;
3079 		  l_func_params                   fnd_form_functions.PARAMETERS%TYPE;
3080 		  l_object_id                     NUMBER;
3081 		  l_assess_comps_processed        competences_tbl;
3082 		  z                               PLS_INTEGER;
3083 		  l_def_job_comps                 sel_comp_tab;
3084 		  appraisal_setup_issue           EXCEPTION;
3085 		  -- Declare local variables
3086 		  l_proc                          VARCHAR2 (72)                                  := g_package || 'create_appraisal_for_person';
3087 		  --
3088 		  l_scorecard_id                  NUMBER;
3089 		  l_object_version_number         NUMBER;
3090 		  --l_status_code                 varchar2(30);
3091 		  l_duplicate_name_warning        BOOLEAN;
3092 		  l_found_comp                    BOOLEAN;
3093 		  --
3094 		  l_templ_def_job_comps           per_assessment_types.default_job_competencies%TYPE;
3095 		  l_assess_type_id                per_assessment_types.assessment_type_id%TYPE;
3096 	   BEGIN
3097 		  --
3098 		  IF g_dbg
3099 		  THEN
3100 			 op ('Entering:' || l_proc, g_debug_log, 10);
3101 		  END IF;
3102 
3103 		  --
3104 
3105 		  --
3106 		  -- Call create_scorecard
3107 		  --
3108 		  l_scorecard_info.scorecard_id := NULL;
3109 		  l_scorecard_info.assignment_id := NULL;
3110 
3111 		  OPEN get_scorecard_info (p_score_card_id);
3112 
3113 		  FETCH get_scorecard_info
3114 		   INTO l_scorecard_info;
3115 
3116 		  CLOSE get_scorecard_info;
3117 
3118 		  IF (l_scorecard_info.scorecard_id IS NULL OR l_scorecard_info.assignment_id IS NULL)
3119 		  THEN
3120 			 RAISE no_score_card_with_this_id;
3121 		  END IF;
3122 
3123 		  IF g_dbg
3124 		  THEN
3125 			 op (' get_scorecard_info ' || l_proc, g_debug_log, 20);
3126 		  END IF;
3127 
3128 		  l_assignment_info.assignment_id := NULL;
3129 
3130 		  OPEN get_assignment_info (l_scorecard_info.assignment_id);
3131 
3132 		  FETCH get_assignment_info
3133 		   INTO l_assignment_info;
3134 
3135 		  CLOSE get_assignment_info;
3136 
3137 		  IF (l_assignment_info.assignment_id IS NULL)
3138 		  THEN
3139 			 RAISE no_assignment_with_this_id;
3140 		  END IF;
3141 
3142 		  IF g_dbg
3143 		  THEN
3144 			 op (' get_assignment_info ' || l_proc, g_debug_log, 20);
3145 		  END IF;
3146 
3147 		  OPEN get_appraisal_templ_info (p_appraisal_templ_id);
3148 
3149 		  FETCH get_appraisal_templ_info
3150 		   INTO l_apprl_templ_info;
3151 
3152 		  CLOSE get_appraisal_templ_info;
3153 
3154 		  IF (l_apprl_templ_info.appraisal_template_id IS NULL)
3155 		  THEN
3156 			 RAISE no_apprl_templ_with_this_id;
3157 		  END IF;
3158 
3159 		  IF g_dbg
3160 		  THEN
3161 			 op (' get_appraisal_templ_info ' || l_proc, g_debug_log, 20);
3162 		  END IF;
3163 
3164 		  l_appraisal_sys_type := p_type;
3165 		  function_360_exists :=
3166 			 get_appraisal_config_params (p_appr_initiator_code      => p_appraisal_initiator,
3167 										  p_function_id              => l_function_id,
3168 										  p_function_name            => l_function_name,
3169 										  p_func_parameters          => l_func_params,
3170 										  p_appraisal_sys_type       => l_appraisal_sys_type
3171 										 );
3172 
3173 		  IF g_dbg
3174 		  THEN
3175 			 op ('l_function_id = ' || l_function_id, g_debug_log);
3176 		  END IF;
3177 
3178 		  IF g_dbg
3179 		  THEN
3180 			 op ('l_function_name = ' || l_function_name, g_debug_log);
3181 		  END IF;
3182 
3183 		  IF g_dbg
3184 		  THEN
3185 			 op ('l_func_params = ' || l_func_params, g_debug_log);
3186 		  END IF;
3187 
3188 		  IF (l_function_id IS NULL OR l_appraisal_sys_type IS NULL)
3189 		  THEN
3190 			 IF g_dbg
3191 			 THEN
3192 				op ('Could not derive Appraisal Function or Appraisal System Type', g_debug_log);
3193 			 END IF;
3194 
3195 			 RAISE appraisal_setup_issue;
3196 		  END IF;
3197 
3198 	/*
3199 		IF (function_360_exists = true) then
3200 		  IF g_dbg THEN op(' Appraisal System Function ' || l_appraisal_sys_status, g_DEBUG_LOG); END IF;
3201 		end if;
3202 
3203 		-- throw exception as there is no Function
3204 		if(function_360_exists = false) then
3205 			raise NO_APPRL_FUNCTION_DEFINED;
3206 			IF g_dbg THEN op(' Appraisal System Function ' || l_appraisal_sys_status, g_DEBUG_LOG); END IF;
3207 
3208 		end if;
3209 	*/
3210 
3211 		  --function_360_exists := true;  -- to be changed
3212 
3213 		  /*
3214 
3215 		  if(function_360_exists = false) then
3216 			  raise APPRAISAL_SYSTEM_TYPE_ERROR;
3217 		  end if;
3218 
3219 		  */
3220 
3221 		  --fnd_log.string(fnd_log.level_error,module_name,' Appraisal Creation for Score Card ' || l_scorecard_info.scorecard_name);
3222 
3223 		  -- to be, in case of Position Hierarchy we need get the supervisor id using the Plan and
3224 		  --  position hierarchy cursor.
3225 		  hr_appraisals_api.create_appraisal (p_validate                         => FALSE,
3226 											  p_effective_date                   => p_effective_date,
3227 											  p_business_group_id                => l_assignment_info.business_group_id,
3228 											  p_appraisal_template_id            => p_appraisal_templ_id,
3229 											  p_appraisee_person_id              => l_scorecard_info.person_id,
3230 											  p_appraiser_person_id              => l_assignment_info.supervisor_id,
3231 											  --to be changed for position
3232 											  p_appraisal_date                   => p_appraisal_date,
3233 											  p_appraisal_period_start_date      => p_appraisal_start_date,
3234 											  p_appraisal_period_end_date        => p_appraisal_end_date,
3235 											  p_type                             => p_type,                                    -- ANN,
3236 											  p_next_appraisal_date              => p_next_appraisal_date,
3237 											  p_status                           => p_status,
3238 											  -- PLANNED,TRANSFER,RFC,
3239 											  p_comments                         => p_comments,
3240 											  p_system_type                      => l_appraisal_sys_type,
3241 											  --MGR360 EMP360
3242 											  p_system_params                    => l_func_params,
3243 											  --p_appraisee_access,
3244 											  p_main_appraiser_id                => l_assignment_info.supervisor_id,
3245 											  --to be changed for position
3246 											  p_assignment_id                    => l_assignment_info.assignment_id,
3247 											  p_assignment_start_date            => l_assignment_info.effective_state_date,
3248 											  p_asg_business_group_id            => l_assignment_info.business_group_id,
3249 											  p_assignment_organization_id       => l_assignment_info.org_id,
3250 											  p_assignment_job_id                => l_assignment_info.job_id,
3251 											  --p_assignment_position_id = l_assignment_info.position_id  ,
3252 											  p_assignment_grade_id              => l_assignment_info.grade_id,
3253 											  p_appraisal_id                     => l_apprl_id,
3254 											  p_object_version_number            => l_appraisal_ovn,
3255 											  p_appraisal_system_status          => p_appraisal_status,
3256 											  p_plan_id                          => p_plan_id
3257 											 );
3258 
3259 		  IF g_dbg
3260 		  THEN
3261 			 op ('Appraisal Id = ' || l_apprl_id, g_debug_log);
3262 		  END IF;
3263 
3264 		  IF (l_apprl_id IS NOT NULL AND l_apprl_templ_info.assessment_type_id IS NOT NULL)
3265 		  THEN
3266 			 hr_assessments_api.create_assessment (p_assessment_id                     => l_assessment_comp_id,
3267 												   p_assessment_type_id                => l_apprl_templ_info.assessment_type_id,
3268 												   p_business_group_id                 => l_assignment_info.business_group_id,
3269 												   p_person_id                         => l_scorecard_info.person_id,
3270 												   --p_assessment_group_id,
3271 												   p_assessment_period_start_date      => p_appraisal_start_date,
3272 												   p_assessment_period_end_date        => p_appraisal_end_date,
3273 												   p_assessment_date                   => p_appraisal_date,
3274 												   p_assessor_person_id                => l_assignment_info.supervisor_id,
3275 												   --to be changed for position
3276 												   p_appraisal_id                      => l_apprl_id,
3277 												   --p_comments,
3278 												   p_object_version_number             => l_assessment_comp_ovn,
3279 												   p_validate                          => FALSE,
3280 												   p_effective_date                    => p_effective_date
3281 												  );
3282 		  END IF;
3283 
3284 		  IF g_dbg
3285 		  THEN
3286 			 op ('Competence Assesment Id = ' || l_assessment_comp_id, g_debug_log);
3287 		  END IF;
3288 
3289 		  -- this record is created for final ratings on Objectives.
3290 		  IF (l_apprl_id IS NOT NULL AND l_apprl_templ_info.objective_asmnt_type_id IS NOT NULL)
3291 		  THEN
3292 			 hr_assessments_api.create_assessment (p_assessment_id                     => l_assessment_obj_id,
3293 												   p_assessment_type_id                => l_apprl_templ_info.assessment_type_id,
3294 												   p_business_group_id                 => l_assignment_info.business_group_id,
3295 												   p_person_id                         => l_scorecard_info.person_id,
3296 												   --p_assessment_group_id,
3297 												   p_assessment_period_start_date      => p_appraisal_start_date,
3298 												   p_assessment_period_end_date        => p_appraisal_end_date,
3299 												   p_assessment_date                   => p_appraisal_date,
3300 												   p_assessor_person_id                => l_assignment_info.supervisor_id,
3301 												   --to be changed for position
3302 												   p_appraisal_id                      => l_apprl_id,
3303 												   --p_comments,
3304 												   p_object_version_number             => l_assessment_obj_ovn,
3305 												   p_validate                          => FALSE,
3306 												   p_effective_date                    => p_effective_date
3307 												  );
3308 		  END IF;
3309 
3310 		  IF g_dbg
3311 		  THEN
3312 			 op ('Objective Assessment Id = ' || l_assessment_obj_id, g_debug_log);
3313 		  END IF;
3314 
3315 		  -- to be
3316 		  IF (p_appraisal_initiator = 'MA')
3317 		  THEN
3318 			 l_object_id := l_assignment_info.supervisor_id;
3319 		  ELSIF (p_appraisal_initiator = 'A')
3320 		  THEN
3321 			 l_object_id := l_scorecard_info.person_id;
3322 		  END IF;
3323 
3324 		  z := 1;
3325 
3326 		  IF (l_assessment_comp_id IS NOT NULL)
3327 		  THEN
3328 			 FOR competences IN get_assess_templ_comps (l_apprl_templ_info.assessment_type_id)
3329 			 LOOP
3330 				BEGIN
3331 				   l_return_status := '';
3332 				   l_competence_error := NULL;
3333 				   l_assess_comps_processed (z).competence_id := competences.competence_id;
3334 				   hr_competence_element_api.create_competence_element (p_validate                   => FALSE,
3335 																		p_competence_element_id      => l_comp_ele_id,
3336 																		p_object_version_number      => l_comp_ovn,
3337 																		p_type                       => 'ASSESSMENT',
3338 																		p_business_group_id          => l_assignment_info.business_group_id,
3339 																		p_competence_id              => competences.competence_id,
3340 																		p_assessment_id              => l_assessment_comp_id,
3341 																		p_effective_date_from        => p_appraisal_start_date,
3342 																		p_effective_date             => p_effective_date,
3343 																		p_object_name                => 'ASSESSOR_ID',
3344 																		p_object_id                  => l_object_id
3345 																	   );
3346 				   z := z + 1;
3347 
3348 				   IF g_dbg
3349 				   THEN
3350 					  op ('Competence Element Id = ' || l_comp_ele_id, g_debug_log);
3351 				   END IF;
3352 				EXCEPTION
3353 				   WHEN OTHERS
3354 				   THEN
3355 					  -- to be added a message to identify competence element error
3356 					  IF g_dbg
3357 					  THEN
3358 						 op (SQLERRM, g_regular_log);
3359 					  END IF;
3360 				END;
3361 			 END LOOP;
3362 		  END IF;
3363 
3364 		  OPEN get_assess_templ_info (l_apprl_templ_info.assessment_type_id);
3365 
3366 		  FETCH get_assess_templ_info
3367 		   INTO l_templ_def_job_comps, l_assess_type_id;
3368 
3369 		  CLOSE get_assess_templ_info;
3370 
3371 		  IF (l_templ_def_job_comps = 'Y')
3372 		  THEN
3373 			 apply_overridding_rules (p_enterprise_id        => l_assignment_info.business_group_id,
3374 									  p_organization_id      => l_assignment_info.org_id,
3375 									  p_job_id               => l_assignment_info.job_id,
3376 									  p_position_id          => l_assignment_info.position_id,
3377 									  p_skip_duplicate       => TRUE,
3378 									  l_sel_comp_table       => l_def_job_comps
3379 									 );
3380 
3381 			 -- create the Job Comps eliminating duplicates
3382 			 IF (l_assessment_comp_id IS NOT NULL)
3383 			 THEN
3384 				FOR j IN 1 .. l_def_job_comps.COUNT
3385 				LOOP
3386 				   BEGIN
3387 					  l_found_comp := FALSE;
3388 
3389 					  FOR k IN 1 .. l_assess_comps_processed.COUNT
3390 					  LOOP
3391 						 IF (    l_def_job_comps (j).competence_id IS NOT NULL
3392 							 AND l_def_job_comps (j).competence_id = l_assess_comps_processed (k).competence_id
3393 							)
3394 						 THEN
3395 							l_found_comp := TRUE;
3396 						 END IF;
3397 					  END LOOP;
3398 
3399 					  IF (l_def_job_comps (j).competence_id IS NOT NULL AND NOT l_found_comp)
3400 					  THEN
3401 						 hr_competence_element_api.create_competence_element
3402 																		 (p_validate                   => FALSE,
3403 																		  p_competence_element_id      => l_comp_ele_id,
3404 																		  p_object_version_number      => l_comp_ovn,
3405 																		  p_type                       => 'ASSESSMENT',
3406 																		  p_business_group_id          => l_assignment_info.business_group_id,
3407 																		  p_competence_id              => l_def_job_comps (j).competence_id,
3408 																		  p_assessment_id              => l_assessment_comp_id,
3409 																		  p_effective_date_from        => p_appraisal_start_date,
3410 																		  p_effective_date             => p_effective_date,
3411 																		  p_object_name                => 'ASSESSOR_ID',
3412 																		  p_object_id                  => l_object_id
3413 																		 );
3414 
3415 						 IF g_dbg
3416 						 THEN
3417 							op (' Def Job Competence Id and Element Id = ' || l_comp_ele_id || l_def_job_comps (j).competence_id,
3418 								g_debug_log
3419 							   );
3420 						 END IF;
3421 					  END IF;
3422 				   EXCEPTION
3423 					  WHEN OTHERS
3424 					  THEN
3425 						 -- to be added a message to identify competence element error
3426 						 IF g_dbg
3427 						 THEN
3428 							op (SQLERRM, g_regular_log);
3429 						 END IF;
3430 				   END;
3431 				END LOOP;
3432 			 END IF;
3433 		  END IF;
3434 
3435 		  IF (l_apprl_id IS NOT NULL)
3436 		  THEN
3437 			 FOR objectives IN get_scorecard_objectives (p_score_card_id)
3438 			 LOOP
3439 				BEGIN
3440 				   hr_objectives_api.update_objective (p_validate                         => FALSE,
3441 													   p_objective_id                     => objectives.objective_id,
3442 													   p_object_version_number            => objectives.object_version_number,
3443 													   p_effective_date                   => p_effective_date,
3444 													   p_appraisal_id                     => l_apprl_id,
3445 													   -- to be changed in SWI,API,RHI
3446 													   p_weighting_over_100_warning       => l_weighting_over_100_warning,
3447 													   p_weighting_appraisal_warning      => l_weighting_appraisal_warning
3448 													  );
3449 
3450 				   IF g_dbg
3451 				   THEN
3452 					  op ('Linked objective Id to Appraisal = ' || objectives.objective_id, g_debug_log);
3453 				   END IF;
3454 				EXCEPTION
3455 				   WHEN OTHERS
3456 				   THEN
3457 					  -- to be added a message to identify update objective error
3458 					  IF g_dbg
3459 					  THEN
3460 						 op (SQLERRM, g_regular_log);
3461 					  END IF;
3462 				END;
3463 			 END LOOP;
3464 		  END IF;
3465 
3466 		  -- Out parameter
3467 
3468 		  --
3469 		  IF g_dbg
3470 		  THEN
3471 			 op ('Leaving:' || l_proc, g_regular_log, 80);
3472 		  END IF;
3473 	   --
3474 	   EXCEPTION
3475 		  WHEN OTHERS
3476 		  THEN
3477 			 IF g_dbg
3478 			 THEN
3479 				op ('Leaving:' || l_proc, g_regular_log, 90);
3480 			 END IF;
3481 
3482 			 --
3483 			 fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
3484 			 g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
3485 			 g_retcode := warning;
3486 			 g_errbuf := g_cp_error_txt;
3487 			 g_num_errors := g_num_errors + 1;
3488 
3489 			 IF g_dbg
3490 			 THEN
3491 				op (g_error_txt, g_regular_log);
3492 			 END IF;
3493 
3494 			 IF g_dbg
3495 			 THEN
3496 				op (SQLERRM, g_regular_log);
3497 			 END IF;
3498 
3499 			 --
3500 			 -- If the max number of errors has been exceeded, raise the error and
3501 			 -- terminate processing of this plan.
3502 			 --
3503 			 IF g_num_errors > g_max_errors
3504 			 THEN
3505 				fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
3506 				g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
3507 				g_retcode := error;
3508 				g_errbuf := g_error_txt;
3509 				RAISE;
3510 			 END IF;
3511 	   END create_appraisal_for_person;
3512 
3513 	--
3514 	-- ----------------------------------------------------------------------------
3515 	-- |----------------------< create_appraisal_for_person >---------------------|
3516 	-- ----------------------------------------------------------------------------
3517 	-- {Start Of Comments}
3518 	--
3519 	-- Description:
3520 	--   Creates appraisal for a given person when plan is published.
3521 	--
3522 	-- Prerequisites:
3523 	--   None.
3524 	--
3525 	-- In Arguments:
3526 	--
3527 	--
3528 	-- Post Success:
3529 	--  Processing continues if appraisal is created.
3530 	--
3531 	-- Post Failure:
3532 	--  An application error is raised if appraisal is not created.
3533 	--
3534 	-- Access Status:
3535 	--   Internal Only.
3536 	--
3537 	-- {End Of Comments}
3538 	-- ----------------------------------------------------------------------------
3539 	   PROCEDURE create_appraisal_for_person (
3540 		  p_effective_date                IN   DATE,
3541 		  p_business_group_id             IN   NUMBER,
3542 		  p_appraisal_template_id         IN   NUMBER,
3543 		  p_appraisee_person_id           IN   NUMBER,
3544 		  p_appraiser_person_id           IN   NUMBER,
3545 		  p_appraisal_period_start_date   IN   DATE,
3546 		  p_appraisal_period_end_date     IN   DATE
3547 	   )
3548 	   IS
3549 		  -- Declare local variables
3550 		  l_proc                    VARCHAR2 (72) := g_package || 'create_appraisal_for_person ';
3551 		  --
3552 		  l_appraisal_id            NUMBER;
3553 		  l_object_version_number   NUMBER;
3554 	   --
3555 	   BEGIN
3556 		  --
3557 		  IF g_dbg
3558 		  THEN
3559 			 op ('Entering:' || l_proc, g_regular_log, 10);
3560 		  END IF;
3561 
3562 		  --
3563 
3564 		  --
3565 		  -- Call create_appraisal
3566 		  --
3567 		  hr_appraisals_api.create_appraisal (p_effective_date                   => p_effective_date,
3568 											  p_business_group_id                => p_business_group_id,
3569 											  p_appraisal_template_id            => p_appraisal_template_id,
3570 											  p_appraisee_person_id              => p_appraisee_person_id,
3571 											  p_appraiser_person_id              => p_appraiser_person_id,
3572 											  p_appraisal_period_start_date      => p_appraisal_period_start_date,
3573 											  p_appraisal_period_end_date        => p_appraisal_period_end_date,
3574 											  p_appraisal_id                     => l_appraisal_id,
3575 											  p_object_version_number            => l_object_version_number
3576 											 );
3577 
3578 		  --
3579 		  IF g_dbg
3580 		  THEN
3581 			 op ('Leaving:' || l_proc, g_regular_log, 80);
3582 		  END IF;
3583 	   --
3584 	   EXCEPTION
3585 		  WHEN OTHERS
3586 		  THEN
3587 			 IF g_dbg
3588 			 THEN
3589 				op ('Leaving:' || l_proc, g_regular_log, 90);
3590 			 END IF;
3591 
3592 			 --
3593 			 fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
3594 			 g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
3595 			 g_retcode := warning;
3596 			 g_errbuf := g_cp_error_txt;
3597 			 g_num_errors := g_num_errors + 1;
3598 
3599 			 IF g_dbg
3600 			 THEN
3601 				op (g_error_txt, g_regular_log);
3602 			 END IF;
3603 
3604 			 IF g_dbg
3605 			 THEN
3606 				op (SQLERRM, g_regular_log);
3607 			 END IF;
3608 
3609 			 --
3610 			 -- If the max number of errors has been exceeded, raise the error and
3611 			 -- terminate processing of this plan.
3612 			 --
3613 			 IF g_num_errors > g_max_errors
3614 			 THEN
3615 				fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
3616 				g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
3617 				g_retcode := error;
3618 				g_errbuf := g_error_txt;
3619 				RAISE;
3620 			 END IF;
3621 	   END create_appraisal_for_person;
3622 
3623 	--
3624 	-- ----------------------------------------------------------------------------
3625 	-- |----------------------< update_appraisal_for_person >---------------------|
3626 	-- ----------------------------------------------------------------------------
3627 	-- {Start Of Comments}
3628 	--
3629 	-- Description:
3630 	--   Updates appraisal for a given person when plan is published.
3631 	--
3632 	-- Prerequisites:
3633 	--   None.
3634 	--
3635 	-- In Arguments:
3636 	--
3637 	--
3638 	-- Post Success:
3639 	--  Processing continues if appraisal is updated.
3640 	--
3641 	-- Post Failure:
3642 	--  An application error is raised if appraisal is not updated.
3643 	--
3644 	-- Access Status:
3645 	--   Internal Only.
3646 	--
3647 	-- {End Of Comments}
3648 	-- ----------------------------------------------------------------------------
3649 	   PROCEDURE update_appraisal_for_person (
3650 		  p_effective_date                IN   DATE,
3651 		  p_appraisal_id                  IN   NUMBER,
3652 		  p_object_version_number         IN   NUMBER,
3653 		  p_appraiser_person_id           IN   NUMBER,
3654 		  p_appraisal_period_start_date   IN   DATE,
3655 		  p_appraisal_period_end_date     IN   DATE
3656 	   )
3657 	   IS
3658 		  -- Declare local variables
3659 		  l_proc                    VARCHAR2 (72) := g_package || 'update_appraisal_for_person ';
3660 		  --
3661 		  l_object_version_number   NUMBER        := p_object_version_number;
3662 	   --
3663 	   BEGIN
3664 		  --
3665 		  IF g_dbg
3666 		  THEN
3667 			 op ('Entering:' || l_proc, g_regular_log, 10);
3668 		  END IF;
3669 
3670 		  --
3671 
3672 		  --
3673 		  -- Call update_appraisal
3674 		  --
3675 		  hr_appraisals_api.update_appraisal (p_effective_date                   => p_effective_date,
3676 											  p_appraisal_id                     => p_appraisal_id,
3677 											  p_object_version_number            => l_object_version_number,
3678 											  p_appraiser_person_id              => p_appraiser_person_id,
3679 											  p_appraisal_period_start_date      => p_appraisal_period_start_date,
3680 											  p_appraisal_period_end_date        => p_appraisal_period_end_date
3681 											 );
3682 
3683 		  --
3684 		  IF g_dbg
3685 		  THEN
3686 			 op ('Leaving:' || l_proc, g_regular_log, 80);
3687 		  END IF;
3688 	   --
3689 	   EXCEPTION
3690 		  WHEN OTHERS
3691 		  THEN
3692 			 IF g_dbg
3693 			 THEN
3694 				op ('Leaving:' || l_proc, g_regular_log, 90);
3695 			 END IF;
3696 
3697 			 --
3698 			 fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
3699 			 g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
3700 			 g_retcode := warning;
3701 			 g_errbuf := g_cp_error_txt;
3702 			 g_num_errors := g_num_errors + 1;
3703 
3704 			 IF g_dbg
3705 			 THEN
3706 				op (g_error_txt, g_regular_log);
3707 			 END IF;
3708 
3709 			 IF g_dbg
3710 			 THEN
3711 				op (SQLERRM, g_regular_log);
3712 			 END IF;
3713 
3714 			 --
3715 			 -- If the max number of errors has been exceeded, raise the error and
3716 			 -- terminate processing of this plan.
3717 			 --
3718 			 IF g_num_errors > g_max_errors
3719 			 THEN
3720 				fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
3721 				g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
3722 				g_retcode := error;
3723 				g_errbuf := g_error_txt;
3724 				RAISE;
3725 			 END IF;
3726 	   END update_appraisal_for_person;
3727 
3728 	--
3729 	-- ----------------------------------------------------------------------------
3730 	-- |----------------------< delete_appraisal_for_person >---------------------|
3731 	-- ----------------------------------------------------------------------------
3732 	-- {Start Of Comments}
3733 	--
3734 	-- Description:
3735 	--   Deletes appraisal for a given person when plan is published.
3736 	--
3737 	-- Prerequisites:
3738 	--   None.
3739 	--
3740 	-- In Arguments:
3741 	--
3742 	--
3743 	-- Post Success:
3744 	--  Processing continues if appraisal is deleted.
3745 	--
3746 	-- Post Failure:
3747 	--  An application error is raised if appraisal is not deleted.
3748 	--
3749 	-- Access Status:
3750 	--   Internal Only.
3751 	--
3752 	-- {End Of Comments}
3753 	-- ----------------------------------------------------------------------------
3754 	   PROCEDURE delete_appraisal_for_person (p_appraisal_id IN NUMBER, p_object_version_number IN NUMBER)
3755 	   IS
3756 		  -- Declare local variables
3757 		  l_proc   VARCHAR2 (72) := g_package || 'delete_appraisal_for_person ';
3758 
3759 		  CURSOR get_assessm_for_apprl (apprl_id per_appraisals.appraisal_id%TYPE)
3760 		  IS
3761 			 SELECT assessment_id, object_version_number
3762 			   FROM per_assessments
3763 			  WHERE appraisal_id = apprl_id;
3764 
3765 		  CURSOR get_competences (assess_id per_assessments.assessment_id%TYPE)
3766 		  IS
3767 			 SELECT   competence_element_id, object_version_number
3768 				 FROM per_competence_elements
3769 				WHERE assessment_id = assess_id
3770 			 ORDER BY competence_element_id DESC;
3771 	   --
3772 	   BEGIN
3773 		  --
3774 		  IF g_dbg
3775 		  THEN
3776 			 op ('Entering:' || l_proc, g_regular_log, 10);
3777 		  END IF;
3778 
3779 		  --
3780 
3781 		  --
3782 		  -- Call delete_appraisal
3783 		  --
3784 		  FOR assess_records IN get_assessm_for_apprl (p_appraisal_id)
3785 		  LOOP
3786 			 FOR assess_comps IN get_competences (assess_records.assessment_id)
3787 			 LOOP
3788 				hr_competence_element_api.delete_competence_element (p_validate                   => FALSE,
3789 																	 p_competence_element_id      => assess_comps.competence_element_id,
3790 																	 p_object_version_number      => assess_comps.object_version_number
3791 																	);
3792 			 END LOOP;
3793 
3794 			 hr_assessments_api.delete_assessment (p_validate                   => FALSE,
3795 												   p_assessment_id              => assess_records.assessment_id,
3796 												   p_object_version_number      => assess_records.object_version_number
3797 												  );
3798 		  END LOOP;
3799 
3800 		  hr_appraisals_api.delete_appraisal (p_validate                   => FALSE,
3801 											  p_appraisal_id               => p_appraisal_id,
3802 											  p_object_version_number      => p_object_version_number
3803 											 );
3804 
3805 		  --
3806 		  IF g_dbg
3807 		  THEN
3808 			 op ('Leaving:' || l_proc, g_regular_log, 80);
3809 		  END IF;
3810 	   --
3811 	   EXCEPTION
3812 		  WHEN OTHERS
3813 		  THEN
3814 			 IF g_dbg
3815 			 THEN
3816 				op ('Leaving:' || l_proc, g_regular_log, 90);
3817 			 END IF;
3818 
3819 			 --
3820 			 fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
3821 			 g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
3822 			 g_retcode := warning;
3823 			 g_errbuf := g_cp_error_txt;
3824 			 g_num_errors := g_num_errors + 1;
3825 
3826 			 IF g_dbg
3827 			 THEN
3828 				op (g_error_txt, g_regular_log);
3829 			 END IF;
3830 
3831 			 IF g_dbg
3832 			 THEN
3833 				op (SQLERRM, g_regular_log);
3834 			 END IF;
3835 
3836 			 --
3837 			 -- If the max number of errors has been exceeded, raise the error and
3838 			 -- terminate processing of this plan.
3839 			 --
3840 			 IF g_num_errors > g_max_errors
3841 			 THEN
3842 				fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
3843 				g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
3844 				g_retcode := error;
3845 				g_errbuf := g_error_txt;
3846 				RAISE;
3847 			 END IF;
3848 	   END delete_appraisal_for_person;
3849 
3850 	--
3851 	--
3852 	-- ----------------------------------------------------------------------------
3853 	-- |---------------------------< get_plan_action >----------------------------|
3854 	-- ----------------------------------------------------------------------------
3855 	--
3856 	   PROCEDURE get_plan_action (
3857 		  itemtype    IN              VARCHAR2,
3858 		  itemkey     IN              VARCHAR2,
3859 		  actid       IN              NUMBER,
3860 		  funcmode    IN              VARCHAR2,
3861 		  resultout   OUT NOCOPY      VARCHAR2
3862 	   )
3863 	   IS
3864 	--
3865 		  l_action   VARCHAR2 (30);
3866 	--
3867 	   BEGIN
3868 	--
3869 		  IF (funcmode = 'RUN')
3870 		  THEN
3871 			 --
3872 			 l_action := wf_engine.getitemattrtext (itemtype => itemtype, itemkey => itemkey, aname => 'WPM_PLAN_ACTION');
3873 
3874 			 --
3875 			 IF (l_action IN ('PUBLISH', 'REVERSE_PUBLISH'))
3876 			 THEN
3877 				resultout := 'COMPLETE:' || l_action;
3878 			 ELSE
3879 				resultout := 'ERROR' || 'Y';
3880 			 END IF;
3881 		  ELSE
3882 			 resultout := 'ERROR' || 'Y';
3883 		  END IF;
3884 	   --
3885 	   EXCEPTION
3886 		  WHEN OTHERS
3887 		  THEN
3888 			 wf_core.CONTEXT ('HR_PERF_MGMT_PLANS_INTERNAL', 'GET_PLAN_ACTION', itemtype, itemkey, TO_CHAR (actid), funcmode);
3889 			 RAISE;
3890 	   END get_plan_action;
3891 
3892 	--
3893 	-- ----------------------------------------------------------------------------
3894 	-- |---------------------------< get_plan_method >----------------------------|
3895 	-- ----------------------------------------------------------------------------
3896 	--
3897 	   PROCEDURE get_plan_method (
3898 		  itemtype    IN              VARCHAR2,
3899 		  itemkey     IN              VARCHAR2,
3900 		  actid       IN              NUMBER,
3901 		  funcmode    IN              VARCHAR2,
3902 		  resultout   OUT NOCOPY      VARCHAR2
3903 	   )
3904 	   IS
3905 	--
3906 		  l_method   VARCHAR2 (30);
3907 	--
3908 	   BEGIN
3909 	--
3910 		  IF (funcmode = 'RUN')
3911 		  THEN
3912 			 --
3913 			 l_method := wf_engine.getitemattrtext (itemtype => itemtype, itemkey => itemkey, aname => 'WPM_PLAN_METHOD');
3914 
3915 			 --
3916 			 IF (l_method IN ('CAS', 'PAR'))
3917 			 THEN
3918 				resultout := 'COMPLETE:' || l_method;
3919 			 ELSE
3920 				resultout := 'ERROR' || 'Y';
3921 			 END IF;
3922 		  ELSE
3923 			 resultout := 'ERROR' || 'Y';
3924 		  END IF;
3925 	   --
3926 	   EXCEPTION
3927 		  WHEN OTHERS
3928 		  THEN
3929 			 wf_core.CONTEXT ('HR_PERF_MGMT_PLANS_INTERNAL', 'GET_PLAN_METHOD', itemtype, itemkey, TO_CHAR (actid), funcmode);
3930 			 RAISE;
3931 	   END get_plan_method;
3932 
3933 	--
3934 	-- ----------------------------------------------------------------------------
3935 	-- |-----------------------------< start_process >----------------------------|
3936 	-- ----------------------------------------------------------------------------
3937 	--
3938 	   PROCEDURE start_process (
3939 		  p_plan_rec         IN   per_perf_mgmt_plans%ROWTYPE,
3940 		  p_effective_date   IN   DATE,
3941 		  p_reverse_mode     IN   VARCHAR2,
3942 		  p_item_type        IN   VARCHAR2,
3943 		  p_wf_process       IN   VARCHAR2
3944 	   )
3945 	   IS
3946 		  -- Declare local variables
3947 		  l_proc                     VARCHAR2 (72)                := g_package || 'start_process';
3948 		  --
3949 		  l_item_key                 VARCHAR2 (30);
3950 		  l_item_user_key            VARCHAR2 (80)                := p_plan_rec.plan_id;
3951 		  l_plan_action              VARCHAR2 (80);
3952 		  l_top_msg_hdr              VARCHAR2 (2000);
3953 		  l_top_msg_txt              VARCHAR2 (2000);
3954 		  l_mbr_msg_hdr              VARCHAR2 (2000);
3955 		  l_mbr_msg_txt              VARCHAR2 (2000);
3956 		  l_role_name                wf_roles.NAME%TYPE;
3957 		  l_role_displayname         wf_roles.display_name%TYPE;
3958 		  l_admin_role_name          wf_roles.NAME%TYPE;
3959 		  l_admin_role_displayname   wf_roles.display_name%TYPE;
3960 		  l_wfthreshold              NUMBER;
3961 	   --
3962 	   BEGIN
3963 		  --
3964 		  IF g_dbg
3965 		  THEN
3966 			 op ('Entering:' || l_proc, g_regular_log, 10);
3967 		  END IF;
3968 
3969 		  --
3970 		  --
3971 		  -- Derive the item key
3972 		  --
3973 		  SELECT hr_workflow_item_key_s.NEXTVAL
3974 			INTO l_item_key
3975 			FROM DUAL;
3976 
3977 		  --
3978 		  -- Derive the other values based on plan action
3979 		  --
3980 		  IF (p_reverse_mode = 'N')
3981 		  THEN
3982 			 l_plan_action := 'PUBLISH';
3983 		  ELSIF (p_reverse_mode = 'Y')
3984 		  THEN
3985 			 l_plan_action := 'REVERSE_PUBLISH';
3986 		  END IF;
3987 
3988 		  -- WF Process
3989 		  wf_engine.createprocess (itemtype => p_item_type, itemkey => l_item_key, process => p_wf_process);
3990 		  -- Item User Key
3991 		  wf_engine.setitemuserkey (itemtype => p_item_type, itemkey => l_item_key, userkey => l_item_user_key);
3992 		  -- Effective Date
3993 		  wf_engine.setitemattrtext (itemtype      => p_item_type,
3994 									 itemkey       => l_item_key,
3995 									 aname         => 'EFFECTIVE_DATE',
3996 									 avalue        => p_effective_date
3997 									);
3998 		  -- Plan Id
3999 		  wf_engine.setitemattrtext (itemtype      => p_item_type,
4000 									 itemkey       => l_item_key,
4001 									 aname         => 'WPM_PLAN_ID',
4002 									 avalue        => p_plan_rec.plan_id
4003 									);
4004 		  -- Plan Name
4005 		  wf_engine.setitemattrtext (itemtype      => p_item_type,
4006 									 itemkey       => l_item_key,
4007 									 aname         => 'WPM_PLAN',
4008 									 avalue        => p_plan_rec.plan_name
4009 									);
4010 		  -- Plan Action
4011 		  wf_engine.setitemattrtext (itemtype      => p_item_type,
4012 									 itemkey       => l_item_key,
4013 									 aname         => 'WPM_PLAN_ACTION',
4014 									 avalue        => l_plan_action
4015 									);
4016 		  -- Plan Method
4017 		  wf_engine.setitemattrtext (itemtype      => p_item_type,
4018 									 itemkey       => l_item_key,
4019 									 aname         => 'WPM_PLAN_METHOD',
4020 									 avalue        => p_plan_rec.method_code
4021 									);
4022 		  -- Plan Hierarchy
4023 		  wf_engine.setitemattrtext (itemtype      => p_item_type,
4024 									 itemkey       => l_item_key,
4025 									 aname         => 'WPM_PLAN_HIERARCHY',
4026 									 avalue        => p_plan_rec.hierarchy_type_code
4027 									);
4028 		  -- Plan Supervisor Id
4029 		  wf_engine.setitemattrtext (itemtype      => p_item_type,
4030 									 itemkey       => l_item_key,
4031 									 aname         => 'WPM_PLAN_SUPERVISOR_ID',
4032 									 avalue        => p_plan_rec.supervisor_id
4033 									);
4034 		  -- Plan Supervisor Assignment Id
4035 		  wf_engine.setitemattrtext (itemtype      => p_item_type,
4036 									 itemkey       => l_item_key,
4037 									 aname         => 'WPM_PLAN_SUPERVISOR_ASG_ID',
4038 									 avalue        => p_plan_rec.supervisor_assignment_id
4039 									);
4040 		  -- Plan Top Organization Id
4041 		  wf_engine.setitemattrtext (itemtype      => p_item_type,
4042 									 itemkey       => l_item_key,
4043 									 aname         => 'WPM_PLAN_TOP_ORG_ID',
4044 									 avalue        => p_plan_rec.top_organization_id
4045 									);
4046 		  -- Plan Top Position Id
4047 		  wf_engine.setitemattrtext (itemtype      => p_item_type,
4048 									 itemkey       => l_item_key,
4049 									 aname         => 'WPM_PLAN_TOP_POS_ID',
4050 									 avalue        => p_plan_rec.top_position_id
4051 									);
4052 		  -- Objective Setting Start Date
4053 		  wf_engine.setitemattrtext (itemtype      => p_item_type,
4054 									 itemkey       => l_item_key,
4055 									 aname         => 'OBJ_SET_START',
4056 									 avalue        => p_plan_rec.obj_setting_start_date
4057 									);
4058 		  -- Objective Setting End Date
4059 		  wf_engine.setitemattrtext (itemtype      => p_item_type,
4060 									 itemkey       => l_item_key,
4061 									 aname         => 'OBJ_SET_FINISH',
4062 									 avalue        => p_plan_rec.obj_setting_deadline
4063 									);
4064 		  -- start changes for Bug#5903006
4065 		  wf_engine.setitemattrtext (itemtype      => p_item_type,
4066 									 itemkey       => l_item_key,
4067 									 aname         => 'HR_WPM_OBJ_SETTING_FLAG',
4068 									 avalue        => p_plan_rec.include_obj_setting_flag
4069 									);
4070 		  -- End Changes for bug#5903006
4071 
4072 		  --
4073 	-- ------------------------------------
4074 	-- Get the Role for plan Administrator
4075 	-- ------------------------------------
4076 	--
4077 		  wf_directory.getrolename (p_orig_system         => 'PER',
4078 									p_orig_system_id      => p_plan_rec.administrator_person_id,
4079 									p_name                => l_admin_role_name,
4080 									p_display_name        => l_admin_role_displayname
4081 								   );
4082 		  --
4083 		  -- Plan Administrator
4084 		  --
4085 		  wf_engine.setitemattrtext (itemtype      => p_item_type,
4086 									 itemkey       => l_item_key,
4087 									 aname         => 'HR_WPM_PLAN_ADMINISTRATOR',
4088 									 avalue        => l_admin_role_name
4089 									);
4090 	--
4091 	-- ---------------------------------
4092 	-- Get the Role for the Owner
4093 	-- ---------------------------------
4094 	--
4095 		  wf_directory.getrolename (p_orig_system         => 'FND_USR',
4096 									p_orig_system_id      => fnd_global.user_id,
4097 									p_name                => l_role_name,
4098 									p_display_name        => l_role_displayname
4099 								   );
4100 		  --
4101 		  wf_engine.setitemowner (itemtype => p_item_type, itemkey => l_item_key, owner => l_role_name);
4102 		  --
4103 		  -- Changes by KMG for fixing BUG#7710591
4104 		  l_wfthreshold := NVL (wf_engine.threshold, 50);
4105 		  wf_engine.threshold := -1;                                                                     -- Ensures a deferred process
4106 		  wf_engine.startprocess (itemtype => p_item_type, itemkey => l_item_key);
4107 		  wf_engine.threshold := l_wfthreshold;
4108 
4109 		  --
4110 		  --
4111 		  IF g_dbg
4112 		  THEN
4113 			 op ('Leaving:' || l_proc, g_regular_log, 80);
4114 		  END IF;
4115 	   --
4116 	   EXCEPTION
4117 		  WHEN OTHERS
4118 		  THEN
4119 			 IF g_dbg
4120 			 THEN
4121 				op ('Leaving:' || l_proc, g_regular_log, 90);
4122 			 END IF;
4123 
4124 			 --
4125 			 fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
4126 			 g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
4127 			 g_retcode := error;
4128 			 g_errbuf := g_cp_error_txt;
4129 			 g_num_errors := g_num_errors + 1;
4130 
4131 			 IF g_dbg
4132 			 THEN
4133 				op (g_error_txt, g_regular_log);
4134 			 END IF;
4135 
4136 			 IF g_dbg
4137 			 THEN
4138 				op (SQLERRM, g_regular_log);
4139 			 END IF;
4140 
4141 			 RAISE;
4142 	   END start_process;
4143 
4144 	--
4145 	-- ----------------------------------------------------------------------------
4146 	-- |----------------------< populate_plan_members_cache >---------------------|
4147 	-- ----------------------------------------------------------------------------
4148 	--
4149 	   PROCEDURE populate_plan_members_cache (
4150 		  itemtype    IN              VARCHAR2,
4151 		  itemkey     IN              VARCHAR2,
4152 		  actid       IN              NUMBER,
4153 		  funcmode    IN              VARCHAR2,
4154 		  resultout   OUT NOCOPY      VARCHAR2
4155 	   )
4156 	   IS
4157 		  --
4158 		  l_plan_id          NUMBER;
4159 		  l_effective_date   DATE;
4160 
4161 		  -- Plan record
4162 		  CURSOR csr_get_plan_rec (p_plan_id NUMBER)
4163 		  IS
4164 			 SELECT *
4165 			   FROM per_perf_mgmt_plans
4166 			  WHERE plan_id = p_plan_id;
4167 
4168 		  --
4169 		  l_plan_rec         per_perf_mgmt_plans%ROWTYPE;
4170 	   BEGIN
4171 		  --
4172 		  IF (funcmode = 'RUN')
4173 		  THEN
4174 			 -- Get the workwlow attribute values
4175 			 l_plan_id := wf_engine.getitemattrtext (itemtype => itemtype, itemkey => itemkey, aname => 'WPM_PLAN_ID');
4176 			 l_effective_date := wf_engine.getitemattrtext (itemtype => itemtype, itemkey => itemkey, aname => 'EFFECTIVE_DATE');
4177 
4178 			 --
4179 			 -- Get plan record
4180 			 --
4181 			 OPEN csr_get_plan_rec (l_plan_id);
4182 
4183 			 FETCH csr_get_plan_rec
4184 			  INTO l_plan_rec;
4185 
4186 			 CLOSE csr_get_plan_rec;
4187 
4188 			 -- populate plan cache table
4189 			 populate_qual_plan_population (l_plan_rec, l_effective_date);
4190 
4191 			 --
4192 			 IF (g_plan_pop_known_t (l_plan_id) AND g_qual_pop_tbl.COUNT > 0)
4193 			 THEN
4194 				resultout := 'COMPLETE:' || 'Y';
4195 			 ELSE
4196 				resultout := 'COMPLETE:' || 'N';
4197 			 END IF;
4198 		  ELSE
4199 			 -- function mode is not Run
4200 			 resultout := 'ERROR' || 'Y';
4201 		  END IF;
4202 	   --
4203 	   EXCEPTION
4204 		  WHEN OTHERS
4205 		  THEN
4206 			 wf_core.CONTEXT ('HR_PERF_MGMT_PLANS_INTERNAL',
4207 							  'POPULATE_PLAN_MEMBERS_CACHE',
4208 							  itemtype,
4209 							  itemkey,
4210 							  TO_CHAR (actid),
4211 							  funcmode
4212 							 );
4213 			 RAISE;
4214 	   END populate_plan_members_cache;
4215 
4216 	--
4217 	-- ----------------------------------------------------------------------------
4218 	-- |---------------------------< get_plan_member >----------------------------|
4219 	-- ----------------------------------------------------------------------------
4220 	--
4221 	   PROCEDURE get_plan_member (
4222 		  itemtype    IN              VARCHAR2,
4223 		  itemkey     IN              VARCHAR2,
4224 		  actid       IN              NUMBER,
4225 		  funcmode    IN              VARCHAR2,
4226 		  resultout   OUT NOCOPY      VARCHAR2
4227 	   )
4228 	   IS
4229 		  --
4230 		  l_plan_id            NUMBER;
4231 		  l_role_name          wf_roles.NAME%TYPE;
4232 		  l_role_displayname   wf_roles.display_name%TYPE;
4233 	   --
4234 	   BEGIN
4235 		  --
4236 		  IF (funcmode = 'RUN')
4237 		  THEN
4238 			 -- Get the workwlow attribute values
4239 			 l_plan_id := wf_engine.getitemattrtext (itemtype => itemtype, itemkey => itemkey, aname => 'WPM_PLAN_ID');
4240 
4241 			 -- If plan population is known
4242 			 IF (g_plan_pop_known_t (l_plan_id))
4243 			 THEN
4244 				--  Get the current plan member index
4245 				IF (g_fetched_plan_member_index IS NULL)
4246 				THEN
4247 				   g_fetched_plan_member_index := g_qual_pop_tbl.FIRST;
4248 				ELSE
4249 				   g_fetched_plan_member_index := g_qual_pop_tbl.NEXT (g_fetched_plan_member_index);
4250 				END IF;
4251 
4252 				-- Loop till member is found with wf role
4253 				WHILE (g_fetched_plan_member_index IS NOT NULL)
4254 				LOOP
4255 				   -- Get the Role for the Owner
4256 				   wf_directory.getrolename (p_orig_system         => 'PER',
4257 											 p_orig_system_id      => g_qual_pop_tbl (g_fetched_plan_member_index).person_id,
4258 											 p_name                => l_role_name,
4259 											 p_display_name        => l_role_displayname
4260 											);
4261 
4262 				   --
4263 				   IF (l_role_name IS NOT NULL)
4264 				   THEN
4265 					  wf_engine.setitemattrtext (itemtype, itemkey, 'WPM_PLAN_MEMBER', l_role_name);
4266 					  resultout := 'COMPLETE:' || 'Y';
4267 					  RETURN;
4268 				   END IF;
4269 
4270 				   --
4271 				   g_fetched_plan_member_index := g_qual_pop_tbl.NEXT (g_fetched_plan_member_index);
4272 				--
4273 				END LOOP;
4274 
4275 				-- Loop complete wf role is not found for any plan member
4276 				resultout := 'COMPLETE:' || 'N';
4277 			 --
4278 			 ELSE
4279 				-- Plan population is not known
4280 				resultout := 'ERROR' || 'Y';
4281 			 END IF;
4282 		  ELSE
4283 			 -- function mode is not Run
4284 			 resultout := 'ERROR' || 'Y';
4285 		  END IF;
4286 	   --
4287 	   EXCEPTION
4288 		  WHEN OTHERS
4289 		  THEN
4290 			 wf_core.CONTEXT ('HR_PERF_MGMT_PLANS_INTERNAL', 'GET_PLAN_MEMBER', itemtype, itemkey, TO_CHAR (actid), funcmode);
4291 			 RAISE;
4292 	   END get_plan_member;
4293 
4294 	--
4295 	-- ----------------------------------------------------------------------------
4296 	-- |------------------------< get_top_plan_member >--------------------------|
4297 	-- ----------------------------------------------------------------------------
4298 	--
4299 	   PROCEDURE get_top_plan_member (
4300 		  itemtype    IN              VARCHAR2,
4301 		  itemkey     IN              VARCHAR2,
4302 		  actid       IN              NUMBER,
4303 		  funcmode    IN              VARCHAR2,
4304 		  resultout   OUT NOCOPY      VARCHAR2
4305 	   )
4306 	   IS
4307 		  --
4308 		  l_plan_id            NUMBER;
4309 		  l_plan_hierarchy     VARCHAR2 (30);
4310 		  l_top_id             NUMBER;
4311 		  l_role_name          wf_roles.NAME%TYPE;
4312 		  l_role_displayname   wf_roles.display_name%TYPE;
4313 	   --
4314 	   BEGIN
4315 		  --
4316 		  IF (funcmode = 'RUN')
4317 		  THEN
4318 			 -- Get the workwlow attribute values
4319 			 l_plan_id := wf_engine.getitemattrtext (itemtype => itemtype, itemkey => itemkey, aname => 'WPM_PLAN_ID');
4320 			 --
4321 			 l_plan_hierarchy := wf_engine.getitemattrtext (itemtype => itemtype, itemkey => itemkey, aname => 'WPM_PLAN_HIERARCHY');
4322 
4323 			 IF (l_plan_hierarchy = 'SUP')
4324 			 THEN
4325 				--
4326 				l_top_id := wf_engine.getitemattrtext (itemtype => itemtype, itemkey => itemkey, aname => 'WPM_PLAN_SUPERVISOR_ID');
4327 			 ELSIF (l_plan_hierarchy = 'SUP_ASG')
4328 			 THEN
4329 				--
4330 				l_top_id :=
4331 						  wf_engine.getitemattrtext (itemtype      => itemtype, itemkey => itemkey,
4332 													 aname         => 'WPM_PLAN_SUPERVISOR_ASG_ID');
4333 			 ELSIF (l_plan_hierarchy = 'ORG')
4334 			 THEN
4335 				--
4336 				l_top_id := wf_engine.getitemattrtext (itemtype => itemtype, itemkey => itemkey, aname => 'WPM_PLAN_TOP_ORG_ID');
4337 			 ELSIF (l_plan_hierarchy = 'POS')
4338 			 THEN
4339 				--
4340 				l_top_id := wf_engine.getitemattrtext (itemtype => itemtype, itemkey => itemkey, aname => 'WPM_PLAN_TOP_POS_ID');
4341 			 END IF;
4342 
4343 			 -- If plan population is known
4344 			 IF (g_plan_pop_known_t (l_plan_id))
4345 			 THEN
4346 				--  Get the current plan member index
4347 				IF (g_fetched_plan_member_index IS NULL)
4348 				THEN
4349 				   g_fetched_plan_member_index := g_qual_pop_tbl.FIRST;
4350 				ELSE
4351 				   g_fetched_plan_member_index := g_qual_pop_tbl.NEXT (g_fetched_plan_member_index);
4352 				END IF;
4353 
4354 				-- Loop till member is found with wf role
4355 				WHILE (g_fetched_plan_member_index IS NOT NULL)
4356 				LOOP
4357 				   IF    (l_plan_hierarchy = 'SUP' AND g_qual_pop_tbl (g_fetched_plan_member_index).person_id = l_top_id)
4358 					  OR (l_plan_hierarchy = 'SUP_ASG' AND g_qual_pop_tbl (g_fetched_plan_member_index).assignment_id = l_top_id)
4359 					  OR (l_plan_hierarchy = 'ORG' AND g_qual_pop_tbl (g_fetched_plan_member_index).organization_id = l_top_id)
4360 					  OR (l_plan_hierarchy = 'POS' AND g_qual_pop_tbl (g_fetched_plan_member_index).position_id = l_top_id)
4361 				   THEN
4362 					  -- Get the Role for the Owner
4363 					  wf_directory.getrolename (p_orig_system         => 'PER',
4364 												p_orig_system_id      => g_qual_pop_tbl (g_fetched_plan_member_index).person_id,
4365 												p_name                => l_role_name,
4366 												p_display_name        => l_role_displayname
4367 											   );
4368 
4369 					  --
4370 					  IF (l_role_name IS NOT NULL)
4371 					  THEN
4372 						 wf_engine.setitemattrtext (itemtype, itemkey, 'WPM_PLAN_MEMBER', l_role_name);
4373 						 resultout := 'COMPLETE:' || 'Y';
4374 						 RETURN;
4375 					  END IF;
4376 				   --
4377 				   END IF;
4378 
4379 				   --
4380 				   g_fetched_plan_member_index := g_qual_pop_tbl.NEXT (g_fetched_plan_member_index);
4381 				--
4382 				END LOOP;
4383 
4384 				-- Loop complete wf role is not found for any plan member
4385 				resultout := 'COMPLETE:' || 'N';
4386 			 --
4387 			 ELSE
4388 				-- Plan population is not known
4389 				resultout := 'ERROR' || 'Y';
4390 			 END IF;
4391 		  ELSE
4392 			 -- function mode is not Run
4393 			 resultout := 'ERROR' || 'Y';
4394 		  END IF;
4395 	   --
4396 	   EXCEPTION
4397 		  WHEN OTHERS
4398 		  THEN
4399 			 wf_core.CONTEXT ('HR_PERF_MGMT_PLANS_INTERNAL', 'GET_TOP_PLAN_MEMBER', itemtype, itemkey, TO_CHAR (actid), funcmode);
4400 			 RAISE;
4401 	   END get_top_plan_member;
4402 
4403 	--
4404 	-- ----------------------------------------------------------------------------
4405 	-- |----------------------< get_non_top_plan_member >-------------------------|
4406 	-- ----------------------------------------------------------------------------
4407 	--
4408 	   PROCEDURE get_non_top_plan_member (
4409 		  itemtype    IN              VARCHAR2,
4410 		  itemkey     IN              VARCHAR2,
4411 		  actid       IN              NUMBER,
4412 		  funcmode    IN              VARCHAR2,
4413 		  resultout   OUT NOCOPY      VARCHAR2
4414 	   )
4415 	   IS
4416 		  --
4417 		  l_plan_id            NUMBER;
4418 		  l_plan_hierarchy     VARCHAR2 (30);
4419 		  l_top_id             NUMBER;
4420 		  l_role_name          wf_roles.NAME%TYPE;
4421 		  l_role_displayname   wf_roles.display_name%TYPE;
4422 		  l_sc_exists          VARCHAR2 (20);
4423 
4424 		  CURSOR csr_chk_sc_exists (p_assignment_id NUMBER, p_plan_id NUMBER)
4425 		  IS
4426 			 SELECT 'Y'
4427 			   FROM DUAL
4428 			  WHERE EXISTS (SELECT 'X'
4429 							  FROM per_personal_scorecards
4430 							 WHERE plan_id = p_plan_id AND assignment_id = p_assignment_id);
4431 	   --
4432 	   BEGIN
4433 		  --
4434 		  IF (funcmode = 'RUN')
4435 		  THEN
4436 			 -- Get the workwlow attribute values
4437 			 l_plan_id := wf_engine.getitemattrtext (itemtype => itemtype, itemkey => itemkey, aname => 'WPM_PLAN_ID');
4438 			 --
4439 			 l_plan_hierarchy := wf_engine.getitemattrtext (itemtype => itemtype, itemkey => itemkey, aname => 'WPM_PLAN_HIERARCHY');
4440 
4441 			 IF (l_plan_hierarchy = 'SUP')
4442 			 THEN
4443 				--
4444 				l_top_id := wf_engine.getitemattrtext (itemtype => itemtype, itemkey => itemkey, aname => 'WPM_PLAN_SUPERVISOR_ID');
4445 			 ELSIF (l_plan_hierarchy = 'SUP_ASG')
4446 			 THEN
4447 				--
4448 				l_top_id :=
4449 						  wf_engine.getitemattrtext (itemtype      => itemtype, itemkey => itemkey,
4450 													 aname         => 'WPM_PLAN_SUPERVISOR_ASG_ID');
4451 			 ELSIF (l_plan_hierarchy = 'ORG')
4452 			 THEN
4453 				--
4454 				l_top_id := wf_engine.getitemattrtext (itemtype => itemtype, itemkey => itemkey, aname => 'WPM_PLAN_TOP_ORG_ID');
4455 			 ELSIF (l_plan_hierarchy = 'POS')
4456 			 THEN
4457 				--
4458 				l_top_id := wf_engine.getitemattrtext (itemtype => itemtype, itemkey => itemkey, aname => 'WPM_PLAN_TOP_POS_ID');
4459 			 END IF;
4460 
4461 			 -- If plan population is known
4462 			 IF (g_plan_pop_known_t (l_plan_id))
4463 			 THEN
4464 				--  Get the current plan member index
4465 				IF (g_fetched_plan_member_index IS NULL)
4466 				THEN
4467 				   g_fetched_plan_member_index := g_qual_pop_tbl.FIRST;
4468 				ELSE
4469 				   g_fetched_plan_member_index := g_qual_pop_tbl.NEXT (g_fetched_plan_member_index);
4470 				END IF;
4471 
4472 				-- Loop till member is found with wf role
4473 				WHILE (g_fetched_plan_member_index IS NOT NULL)
4474 				LOOP
4475 				   l_sc_exists := 'N';
4476 
4477 	--changed by schowdhu 8865480 08-Sep-09
4478 				   OPEN csr_chk_sc_exists (g_fetched_plan_member_index, l_plan_id);
4479 
4480 				   FETCH csr_chk_sc_exists
4481 					INTO l_sc_exists;
4482 
4483 				   CLOSE csr_chk_sc_exists;
4484 
4485 				   IF NVL (l_sc_exists, 'N') = 'Y'
4486 				   THEN
4487 					  IF    (l_plan_hierarchy = 'SUP' AND g_qual_pop_tbl (g_fetched_plan_member_index).person_id <> l_top_id)
4488 						 OR (l_plan_hierarchy = 'SUP_ASG' AND g_qual_pop_tbl (g_fetched_plan_member_index).assignment_id <> l_top_id
4489 							)
4490 						 OR (l_plan_hierarchy = 'ORG' AND g_qual_pop_tbl (g_fetched_plan_member_index).organization_id <> l_top_id)
4491 						 OR (l_plan_hierarchy = 'POS' AND g_qual_pop_tbl (g_fetched_plan_member_index).position_id <> l_top_id)
4492 					  THEN
4493 						 -- Get the Role for the Owner
4494 						 wf_directory.getrolename (p_orig_system         => 'PER',
4495 												   p_orig_system_id      => g_qual_pop_tbl (g_fetched_plan_member_index).person_id,
4496 												   p_name                => l_role_name,
4497 												   p_display_name        => l_role_displayname
4498 												  );
4499 
4500 						 --
4501 						 IF (l_role_name IS NOT NULL)
4502 						 THEN
4503 							wf_engine.setitemattrtext (itemtype, itemkey, 'WPM_PLAN_MEMBER', l_role_name);
4504 							resultout := 'COMPLETE:' || 'Y';
4505 							RETURN;
4506 						 END IF;
4507 					  --
4508 					  END IF;
4509 				   END IF;                                                                                              -- l_sc_exists
4510 
4511 				   --
4512 				   g_fetched_plan_member_index := g_qual_pop_tbl.NEXT (g_fetched_plan_member_index);
4513 				--
4514 				END LOOP;
4515 
4516 				-- Loop complete wf role is not found for any plan member
4517 				resultout := 'COMPLETE:' || 'N';
4518 			 --
4519 			 ELSE
4520 				-- Plan population is not known
4521 				resultout := 'ERROR' || 'Y';
4522 			 END IF;
4523 		  ELSE
4524 			 -- function mode is not Run
4525 			 resultout := 'ERROR' || 'Y';
4526 		  END IF;
4527 	   --
4528 	   EXCEPTION
4529 		  WHEN OTHERS
4530 		  THEN
4531 			 wf_core.CONTEXT ('HR_PERF_MGMT_PLANS_INTERNAL', 'GET_NON_TOP_PLAN_MEMBER', itemtype, itemkey, TO_CHAR (actid), funcmode);
4532 			 RAISE;
4533 	   END get_non_top_plan_member;
4534 
4535 	--
4536 	-- ----------------------------------------------------------------------------
4537 	-- |---------------------< submit_publish_plan_cp >---------------------------|
4538 	-- ----------------------------------------------------------------------------
4539 	--
4540 	   PROCEDURE submit_publish_plan_cp (
4541 		  p_effective_date          IN              VARCHAR2,
4542 		  p_plan_id                 IN              NUMBER,
4543 		  p_reverse_mode            IN              VARCHAR2,
4544 		  p_item_type               IN              VARCHAR2,
4545 		  p_wf_process              IN              VARCHAR2,
4546 		  p_object_version_number   IN OUT NOCOPY   NUMBER,
4547 		  p_status_code             IN OUT NOCOPY   VARCHAR2
4548 	   )
4549 	   IS
4550 		  --
4551 		  l_object_version_number   NUMBER                                 := p_object_version_number;
4552 		  l_status_code             per_perf_mgmt_plans.status_code%TYPE;
4553 		  l_dummy                   BOOLEAN;
4554 		  l_request_id              NUMBER;
4555 		  l_effective_date          DATE                                   := NVL (p_effective_date, TRUNC (SYSDATE));
4556 
4557 		  -- Plan record
4558 		  CURSOR csr_get_plan_rec
4559 		  IS
4560 			 SELECT *
4561 			   FROM per_perf_mgmt_plans
4562 			  WHERE plan_id = p_plan_id;
4563 
4564 		  l_plan_rec                per_perf_mgmt_plans%ROWTYPE;
4565 	   --
4566 	   BEGIN
4567 		  -- Submit the request
4568 		  l_request_id :=
4569 			 fnd_request.submit_request (application      => 'PER',
4570 										 program          => 'PERPLNPUB',
4571 										 sub_request      => FALSE,
4572 										 argument1        => fnd_date.date_to_canonical (l_effective_date),
4573 										 argument2        => p_plan_id,
4574 										 argument3        => p_reverse_mode,
4575 										 argument4        => 'N',
4576 										 argument5        => 'Y',
4577 										 argument6        => NULL,
4578 										 argument7        => 'HRWPM',
4579 										 argument8        => 'HR_NOTIFY_WPM_PLAN_POP_PRC'
4580 										);
4581 
4582 		  --
4583 		  IF l_request_id > 0
4584 		  THEN
4585 			 -- Update the status of plan
4586 			 IF (p_status_code = 'DRAFT')
4587 			 THEN
4588 				l_status_code := 'SUBMITTED';
4589 			 ELSIF (p_status_code = 'UPDATED' OR p_status_code = 'FAILED')
4590 			 THEN
4591 				l_status_code := 'RESUBMITTED';
4592 			 END IF;
4593 
4594 			 --
4595 			 per_pmp_upd.upd (p_plan_id                     => p_plan_id,
4596 							  p_effective_date              => l_effective_date,
4597 							  p_object_version_number       => l_object_version_number,
4598 							  p_status_code                 => l_status_code,
4599 							  p_duplicate_name_warning      => l_dummy,
4600 							  p_no_life_events_warning      => l_dummy
4601 							 );
4602 			 --
4603 			 p_object_version_number := l_object_version_number;
4604 			 p_status_code := l_status_code;
4605 
4606 			 --
4607 			 -- Get Plan record
4608 			 --
4609 			 OPEN csr_get_plan_rec;
4610 
4611 			 FETCH csr_get_plan_rec
4612 			  INTO l_plan_rec;
4613 
4614 			 CLOSE csr_get_plan_rec;
4615 
4616 			 --
4617 			 -- Send notification to administrator that plan publish errored
4618 			 --
4619 			 send_fyi_admin (p_plan_rec => l_plan_rec, p_status => 'SUBMITTED', p_request_id => l_request_id);
4620 		  ELSE
4621 			 p_status_code := 'E';
4622 		  END IF;
4623 	   --
4624 	   END submit_publish_plan_cp;
4625 
4626 	--
4627 	-- ----------------------------------------------------------------------------
4628 	-- |---------------------------< publish_plan_cp >----------------------------|
4629 	-- ----------------------------------------------------------------------------
4630 	--
4631 	   PROCEDURE publish_plan_cp (
4632 		  errbuf                        OUT NOCOPY      VARCHAR2,
4633 		  retcode                       OUT NOCOPY      NUMBER,
4634 		  p_effective_date              IN              VARCHAR2,
4635 		  p_plan_id                     IN              NUMBER,
4636 		  p_reverse_mode                IN              VARCHAR2 DEFAULT 'N',
4637 		  p_what_if                     IN              VARCHAR2 DEFAULT 'N',
4638 		  p_log_output                  IN              VARCHAR2 DEFAULT 'N',
4639 		  p_action_parameter_group_id   IN              NUMBER DEFAULT NULL,
4640 		  p_item_type                   IN              VARCHAR2 DEFAULT 'HRWPM',
4641 		  p_wf_process                  IN              VARCHAR2 DEFAULT 'HR_NOTIFY_WPM_PLAN_POP_PRC'
4642 	   )
4643 	   IS
4644 	--
4645 		  CURSOR csr_plan_ovn
4646 		  IS
4647 			 SELECT object_version_number
4648 			   FROM per_perf_mgmt_plans
4649 			  WHERE plan_id = p_plan_id;
4650 
4651 		  CURSOR csr_plan_status_code
4652 		  IS
4653 			 SELECT status_code
4654 			   FROM per_perf_mgmt_plans
4655 			  WHERE plan_id = p_plan_id;
4656 
4657 		  l_object_version_number   NUMBER;
4658 		  l_status_code             per_perf_mgmt_plans.status_code%TYPE;
4659 		  l_dummy                   BOOLEAN;
4660 		  l_wpm_batch_action_id     VARCHAR2 (30);
4661 	--
4662 	   BEGIN
4663 		  BEGIN
4664 			 -- Check if the top supervisor is TERMINATED OR NOT.
4665 			 chk_top_supervisor (p_plan_id);
4666 		  EXCEPTION
4667 			 WHEN OTHERS
4668 			 THEN
4669 				g_errbuf := SQLERRM;
4670 				g_retcode := error;
4671 				RAISE;
4672 		  END;
4673 
4674 		 -- WPM Logging Changes
4675 	--     HR_WPM_MASS_APR_PUSH.l_current_wpm_batch_action_id := per_wpm_batch_actions_s.NEXTVAL;
4676 		  SELECT per_wpm_batch_actions_s.NEXTVAL
4677 			INTO l_wpm_batch_action_id
4678 			FROM DUAL;
4679 
4680 		  hr_wpm_mass_apr_push.l_current_wpm_batch_action_id := l_wpm_batch_action_id;
4681 
4682 		  INSERT INTO per_wpm_batch_actions
4683 					  (wpm_batch_action_id, conc_request_id, conc_program_name, plan_id, appraisal_period_id, status, start_date,
4684 					   end_date
4685 					  )
4686 			   VALUES (l_wpm_batch_action_id, fnd_global.conc_request_id, 'PERPLNPUB', p_plan_id, NULL, 'PENDING', SYSDATE,
4687 																								 --p_effective_date, -- trunc(sysdate)
4688 					   NULL
4689 					  );
4690 
4691 		  COMMIT;
4692 
4693 		  --
4694 		  -- Derive the object version number of plan record
4695 		  --
4696 		  OPEN csr_plan_ovn;
4697 
4698 		  FETCH csr_plan_ovn
4699 		   INTO l_object_version_number;
4700 
4701 		  CLOSE csr_plan_ovn;
4702 
4703 	-- get the status of plan, if it is called from scheduled concureent program status should be chsnged to resubmitted.
4704 		  OPEN csr_plan_status_code;
4705 
4706 		  FETCH csr_plan_status_code
4707 		   INTO l_status_code;
4708 
4709 		  CLOSE csr_plan_status_code;
4710 
4711 		  -- Initialize return status
4712 		  retcode := warning;
4713 
4714 	-- (bug 6460457) changes to allow published plan to be rerun through scheduled concurrent prgms.
4715 		  IF l_status_code IN ('PUBLISHED', 'FAILED')
4716 		  THEN
4717 			 l_status_code := 'RESUBMITTED';
4718 			 per_pmp_upd.upd (p_plan_id                     => p_plan_id,
4719 							  p_effective_date              => fnd_date.canonical_to_date (p_effective_date),
4720 							  p_object_version_number       => l_object_version_number,
4721 							  p_status_code                 => l_status_code,
4722 							  p_duplicate_name_warning      => l_dummy,
4723 							  p_no_life_events_warning      => l_dummy
4724 							 );
4725 
4726 			 -- get the new ovn number to pass it to publish_plan function as update is called before this once
4727 			 OPEN csr_plan_ovn;
4728 
4729 			 FETCH csr_plan_ovn
4730 			  INTO l_object_version_number;
4731 
4732 			 CLOSE csr_plan_ovn;
4733 		  END IF;
4734 
4735 		  -- WPM Logging Changes  Post Review
4736 		  -- to avoid caching issues
4737 		  hr_wpm_mass_apr_push.g_wpm_person_actions.DELETE;
4738 		  hr_wpm_mass_apr_push.log_records_index := NULL;
4739 		  --
4740 		  --  Call the publish plan
4741 		  --
4742 		  publish_plan (p_effective_date                 => fnd_date.canonical_to_date (p_effective_date),
4743 						p_plan_id                        => p_plan_id,
4744 						p_object_version_number          => l_object_version_number,
4745 						p_reverse_mode                   => p_reverse_mode,
4746 						p_what_if                        => p_what_if,
4747 						p_log_output                     => p_log_output,
4748 						p_action_parameter_group_id      => p_action_parameter_group_id,
4749 						p_item_type                      => p_item_type,
4750 						p_wf_process                     => p_wf_process
4751 					   );
4752 		  --
4753 		  errbuf := g_errbuf;
4754 		  retcode := g_retcode;
4755 		  --
4756 			 -- WPM Logging Changes
4757 		  hr_wpm_mass_apr_push.print_cache ();
4758 
4759 		  UPDATE per_wpm_batch_actions
4760 			 SET end_date = SYSDATE,
4761 				 status = DECODE (g_retcode, 0, 'SUCCESS', 'WARNING')
4762 		   WHERE wpm_batch_action_id = hr_wpm_mass_apr_push.l_current_wpm_batch_action_id;
4763 
4764 		  COMMIT;
4765 	   --
4766 	   EXCEPTION
4767 		  WHEN OTHERS
4768 		  THEN
4769 			 ROLLBACK;
4770 			 -- WPM Logging Changes
4771 			 hr_wpm_mass_apr_push.print_cache ();
4772 
4773 			 UPDATE per_wpm_batch_actions
4774 				SET status = 'ERROR',
4775 					end_date = SYSDATE
4776 			  WHERE wpm_batch_action_id = hr_wpm_mass_apr_push.l_current_wpm_batch_action_id;
4777 
4778 			 COMMIT;
4779 
4780 			 --
4781 			 -- update status of the plan to 'Failed'
4782 			 --
4783 			 UPDATE per_perf_mgmt_plans
4784 				SET status_code = 'FAILED'
4785 			  WHERE plan_id = p_plan_id;
4786 
4787 			 COMMIT;
4788 			 --
4789 			 errbuf := g_errbuf;
4790 			 retcode := g_retcode;
4791 	   --
4792 	   END publish_plan_cp;
4793 
4794 	--
4795 	-- ----------------------------------------------------------------------------
4796 	-- |-----------------------------< publish_plan >-----------------------------|
4797 	-- ----------------------------------------------------------------------------
4798 	--
4799 	   PROCEDURE publish_plan (
4800 		  p_effective_date              IN              DATE,
4801 		  p_plan_id                     IN              NUMBER,
4802 		  p_object_version_number       IN OUT NOCOPY   NUMBER,
4803 		  p_reverse_mode                IN              VARCHAR2 DEFAULT 'N',
4804 		  p_what_if                     IN              VARCHAR2 DEFAULT 'N',
4805 		  p_log_output                  IN              VARCHAR2 DEFAULT 'N',
4806 		  p_action_parameter_group_id   IN              NUMBER DEFAULT NULL,
4807 		  p_item_type                   IN              VARCHAR2 DEFAULT 'HRWPM',
4808 		  p_wf_process                  IN              VARCHAR2 DEFAULT 'HR_NOTIFY_WPM_PLAN_POP_PRC'
4809 	   )
4810 	   IS
4811 		  --
4812 		  -- Declare cursors and local variables
4813 		  --
4814 		  l_proc                    VARCHAR2 (72)                                 := g_package || 'publish_plan';
4815 		  l_logging                 pay_action_parameters.parameter_value%TYPE;
4816 		  l_debug                   BOOLEAN                                       := FALSE;
4817 		  l_effective_date          DATE                                          := TRUNC (NVL (p_effective_date, SYSDATE));
4818 		  l_object_version_number   NUMBER;
4819 		  l_status_code             per_perf_mgmt_plans.status_code%TYPE;
4820 		  l_dummy                   BOOLEAN;
4821 		  --
4822 		  l_scorecard_id            per_personal_scorecards.scorecard_id%TYPE;
4823 		  --
4824 		  l_message_count           NUMBER                                        := 0;
4825 		  l_message                 VARCHAR2 (256);
4826 		  l_qual_pop_index          BINARY_INTEGER;
4827 		  l_curr_sc_pop_index       BINARY_INTEGER;
4828 		  l_qual_obj_index          BINARY_INTEGER;
4829 		  l_plan_aprsl_pds_index    BINARY_INTEGER;
4830 		  l_curr_sc_obj_index       BINARY_INTEGER;
4831 		  l_appr_ret_status         VARCHAR2 (1);
4832 		  l_check_elig              VARCHAR2 (1);
4833 		  l_check_elig_person       VARCHAR2 (1);
4834 		  --
4835 		  l_submit_new_req          BOOLEAN                                       := TRUE;
4836 		  l_conc_request_id         NUMBER                                        := 0;
4837 		  e                         EXCEPTION;
4838 		  l_ret                     BOOLEAN;
4839 		  l_message_req             VARCHAR (2000);
4840 
4841 			--
4842 		  -- Cursor to get the  Participants of an appraisal other than MA
4843 		  CURSOR csr_get_appr_part (p_appraisal_id per_appraisals.appraisal_id%TYPE)
4844 		  IS
4845 			 SELECT participant_id, object_version_number, participation_type
4846 			   FROM per_participants
4847 			  WHERE participation_in_id = p_appraisal_id
4848 				AND participation_in_table = 'PER_APPRAISALS'
4849 				AND participation_in_column = 'APPRAISAL_ID'
4850 				AND participation_type <> 'MAINAP'
4851 				AND participation_status = 'OPEN';
4852 
4853 	--Cursor to get pending Requests
4854 		  CURSOR previous_concurrent_requests (
4855 			 plan_id               per_appraisals.plan_id%TYPE,
4856 			 appraisal_period_id   per_appraisal_periods.appraisal_period_id%TYPE
4857 		  )
4858 		  IS
4859 			 SELECT cr.request_id, cr.phase_code
4860 			   FROM fnd_concurrent_programs cp, fnd_concurrent_requests cr
4861 			  WHERE cp.concurrent_program_name = 'WPMAPRPUSH'
4862 				AND cp.application_id = 800
4863 				AND cp.concurrent_program_id = cr.concurrent_program_id
4864 				AND cr.argument2 = TO_CHAR (plan_id)
4865 				AND cr.argument3 = TO_CHAR (appraisal_period_id)
4866 				AND cr.actual_start_date IS NULL
4867 				AND cr.actual_completion_date IS NULL
4868 				AND cr.phase_code = 'P';
4869 
4870 		  -- Plan record
4871 		  CURSOR csr_get_plan_rec
4872 		  IS
4873 			 SELECT *
4874 			   FROM per_perf_mgmt_plans
4875 			  WHERE plan_id = p_plan_id;
4876 
4877 		  -- Scorecard Objectives
4878 		  CURSOR csr_sc_objectives (p_scorecard_id NUMBER)
4879 		  IS
4880 			 SELECT objective_id, object_version_number
4881 			   FROM per_objectives
4882 			  WHERE scorecard_id = p_scorecard_id;
4883 
4884 		  CURSOR csr_plan_appraisals (plan_id per_appraisals.plan_id%TYPE)
4885 		  IS
4886 			 SELECT appraisal_id, object_version_number
4887 			   FROM per_appraisals
4888 			  WHERE plan_id = plan_id;
4889 
4890 		  CURSOR csr_find_appr_for_scorecard (
4891 			 p_plan_id        per_appraisals.plan_id%TYPE,
4892 			 p_scorecard_id   per_personal_scorecards.scorecard_id%TYPE
4893 		  )
4894 		  IS
4895 			 SELECT pa.appraisal_id, pa.object_version_number, pa.appraisal_system_status
4896 			   FROM per_appraisals pa, per_personal_scorecards pps
4897 			  WHERE pa.plan_id = p_plan_id AND appraisee_person_id = pps.person_id AND pps.scorecard_id = p_scorecard_id;
4898 
4899 		  -- cursor added
4900 		  -- 23-Jun-2009 schowdhu Eligibility Profile Enhc.
4901 		  CURSOR get_elig_obj_id_for_person (p_plan_id IN per_perf_mgmt_plans.plan_id%TYPE)
4902 		  IS
4903 			 SELECT elig.elig_obj_id
4904 			   FROM ben_elig_obj_f elig
4905 			  WHERE elig.table_name = 'PER_PERF_MGMT_PLANS'
4906 				AND elig.column_name = 'PLAN_ID'
4907 				AND elig.COLUMN_VALUE = p_plan_id
4908 				AND TRUNC (SYSDATE) BETWEEN elig.effective_start_date AND elig.effective_end_date;
4909 
4910 		  CURSOR get_person_name (p_person_id IN per_all_people_f.person_id%TYPE)
4911 		  IS
4912 			 SELECT full_name
4913 			   FROM per_all_people_f ppf
4914 			  WHERE ppf.person_id = p_person_id AND l_effective_date BETWEEN ppf.effective_start_date AND ppf.effective_end_date;
4915 
4916 		  l_plan_rec                per_perf_mgmt_plans%ROWTYPE;
4917 		  l_obj_date                DATE                                          := TRUNC (SYSDATE);
4918 		  l_scorecard_status_code   VARCHAR2 (30);
4919 		  l_process_date            DATE;
4920 		  l_process_date_char       VARCHAR2 (50);
4921 		  l_request_id              NUMBER;
4922 		  l_appr_ovn                per_appraisals.object_version_number%TYPE;
4923 		  l_appr_id                 per_appraisals.appraisal_id%TYPE;
4924 		  l_appr_sys_status         per_appraisals.appraisal_system_status%TYPE;
4925 		  l_appraiser_person_id     per_appraisals.appraiser_person_id%TYPE;
4926 		  l_elig_obj_id             ben_elig_obj_f.elig_obj_id%TYPE;
4927 		  l_person_name             per_all_people_f.full_name%TYPE;
4928 	   BEGIN
4929 		  --
4930 		  -- Initialize logging
4931 		  --
4932 		  initialize_logging (p_action_parameter_group_id => p_action_parameter_group_id, p_log_output => p_log_output);
4933 
4934 		  --
4935 		  IF g_dbg
4936 		  THEN
4937 			 op ('Entering:' || l_proc, g_regular_log, 10);
4938 		  END IF;
4939 
4940 		  --
4941 		  -- Get Plan record
4942 		  --
4943 		  OPEN csr_get_plan_rec;
4944 
4945 		  FETCH csr_get_plan_rec
4946 		   INTO l_plan_rec;
4947 
4948 		  CLOSE csr_get_plan_rec;
4949 
4950 		  --
4951 		  IF g_dbg
4952 		  THEN
4953 			 op (l_proc, g_debug_log, 20);
4954 		  END IF;
4955 
4956 		  l_request_id := fnd_global.conc_request_id;
4957 
4958 		  IF g_dbg
4959 		  THEN
4960 			 op ('Plan Name: ' || SUBSTR (l_plan_rec.plan_name, 1, 40), g_debug_log, 21);
4961 		  END IF;
4962 
4963 		  IF g_dbg
4964 		  THEN
4965 			 op ('Concurrent Request ID: ' || TO_CHAR (l_request_id), g_debug_log, 22);
4966 		  END IF;
4967 
4968 		  --
4969 		  -- Checks that the status is valid for PLAN PUBLISH OR REVERSE PUBLISH
4970 		  --
4971 		  chk_publishing_status (p_reverse_mode, l_plan_rec.status_code);
4972 
4973 		  --
4974 		  IF g_dbg
4975 		  THEN
4976 			 op (l_proc, g_debug_log, 30);
4977 		  END IF;
4978 
4979 		  -- If objective setting flag or appraisals flag is set then
4980 		  -- populate qualifying population table
4981 		  IF ((l_plan_rec.include_obj_setting_flag = 'Y') OR (l_plan_rec.include_appraisals_flag = 'Y'))
4982 		  THEN
4983 			 --
4984 			 -- Get the qualifying plan population
4985 			 -- g_qual_pop_tbl is populated with index as 'assignment_id'
4986 			 --
4987 			 populate_qual_plan_population (l_plan_rec, l_effective_date);
4988 
4989 			 IF g_dbg
4990 			 THEN
4991 				op (l_proc, g_debug_log, 40);
4992 			 END IF;
4993 		  END IF;
4994 
4995 		  -- If objective setting flag is set then
4996 		  -- populate current population and qualifying objectives tables
4997 		  IF ((l_plan_rec.include_obj_setting_flag = 'Y') OR (l_plan_rec.include_appraisals_flag = 'Y'))
4998 		  THEN
4999 			 --
5000 			 -- Get existing plan population if plan is republished or reverse published
5001 			 -- g_curr_sc_pop_tbl is populated with index as 'assignment_id'
5002 			 --
5003 			 IF (l_plan_rec.status_code IN ('UPDATED', 'RESUBMITTED', 'PUBLISHED'))
5004 			 THEN
5005 				--
5006 				IF g_dbg
5007 				THEN
5008 				   op (l_proc, g_debug_log, 50);
5009 				END IF;
5010 
5011 				populate_curr_plan_population (p_plan_id);
5012 			 END IF;
5013 
5014 			 --
5015 			 -- Get the qualifying objectives
5016 			 -- g_qual_obj_tbl is populated with index as 'objective_id'
5017 			 --
5018 			 IF g_dbg
5019 			 THEN
5020 				op (l_proc, g_debug_log, 60);
5021 			 END IF;
5022 
5023 			 --
5024 			 IF (l_plan_rec.automatic_allocation_flag = 'Y')
5025 			 THEN
5026 				populate_qual_objectives (l_plan_rec.start_date, l_plan_rec.end_date);
5027 			 END IF;
5028 		  END IF;
5029 
5030 		  -- If appraisals flag is set then
5031 		  -- populate appraisala period table
5032 		  IF (l_plan_rec.include_appraisals_flag = 'Y')
5033 		  THEN
5034 			 --
5035 			 -- Get the qualifying plan periods
5036 			 -- g_plan_aprsl_pds_tbl is populated with details
5037 			 --
5038 			 IF g_dbg
5039 			 THEN
5040 				op (l_proc, g_debug_log, 70);
5041 			 END IF;
5042 
5043 			 --
5044 			 populate_plan_apprsl_periods (l_plan_rec.plan_id);
5045 		  END IF;
5046 
5047 		  --
5048 		  -- Loop through plan population to create/update/delete scorecards, objectives and appraisal
5049 		  --
5050 		  l_qual_pop_index := g_qual_pop_tbl.FIRST;
5051 
5052 		  WHILE (l_qual_pop_index IS NOT NULL)
5053 		  LOOP
5054 			 -- WPM Logging Changes
5055 			 hr_wpm_mass_apr_push.log_records_index := g_qual_pop_tbl (l_qual_pop_index).assignment_id;
5056 
5057 			 IF NOT hr_wpm_mass_apr_push.g_wpm_person_actions.EXISTS (hr_wpm_mass_apr_push.log_records_index)
5058 			 THEN
5059 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).wpm_person_action_id := -1;
5060 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).wpm_batch_action_id :=
5061 																				   hr_wpm_mass_apr_push.l_current_wpm_batch_action_id;
5062 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).person_id :=
5063 																						  g_qual_pop_tbl (l_qual_pop_index).person_id;
5064 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).assignment_id :=
5065 																					  g_qual_pop_tbl (l_qual_pop_index).assignment_id;
5066 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).business_group_id :=
5067 																				  g_qual_pop_tbl (l_qual_pop_index).business_group_id;
5068 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).processing_status := 'P';
5069 																														-- Processing
5070 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).transaction_ref_table :=
5071 																											'PER_PERSONAL_SCORECARDS';
5072 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).eligibility_status := 'Y';
5073 																						  -- Default handling cases of plan republish
5074 			 END IF;
5075 
5076 			 --
5077 			 l_qual_obj_index := g_qual_obj_tbl.FIRST;
5078 
5079 			 IF (   l_plan_rec.status_code IN ('DRAFT', 'SUBMITTED')
5080 				 OR (l_plan_rec.status_code IN ('UPDATED', 'RESUBMITTED') AND NOT g_curr_sc_pop_tbl.EXISTS (l_qual_pop_index))
5081 				)
5082 			 THEN
5083 				-- If objective setting flag is set
5084 				IF ((l_plan_rec.include_obj_setting_flag = 'Y') OR (l_plan_rec.include_appraisals_flag = 'Y'))
5085 				THEN
5086 				   --Check for the elibility of the employee/assignment
5087 				   --23-Jun-2009 schowdhu Eligibility Profile Enhc.- start
5088 				   OPEN get_elig_obj_id_for_person (l_plan_rec.plan_id);
5089 
5090 				   FETCH get_elig_obj_id_for_person
5091 					INTO l_elig_obj_id;
5092 
5093 				   CLOSE get_elig_obj_id_for_person;
5094 
5095 				   OPEN get_person_name (g_qual_pop_tbl (l_qual_pop_index).person_id);
5096 
5097 				   FETCH get_person_name
5098 					INTO l_person_name;
5099 
5100 				   CLOSE get_person_name;
5101 
5102 				   IF (l_elig_obj_id IS NULL)
5103 				   THEN
5104 					  -- WPM Logging Changes
5105 					  hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).eligibility_status := 'Y';
5106 				   END IF;
5107 
5108 				   IF (l_elig_obj_id IS NOT NULL)                                                      -- Eligiblity profile is chosen
5109 				   THEN
5110 					  BEGIN
5111 						 --
5112 						 ben_env_object.init (p_business_group_id      => g_qual_pop_tbl (l_qual_pop_index).business_group_id,
5113 											  p_thread_id              => NULL,
5114 											  p_chunk_size             => NULL,
5115 											  p_threads                => NULL,
5116 											  p_max_errors             => NULL,
5117 											  p_benefit_action_id      => NULL,
5118 											  p_effective_date         => l_obj_date
5119 											 );
5120 						 --
5121 						 l_check_elig_person :=
5122 							ben_per_asg_elig.eligible (g_qual_pop_tbl (l_qual_pop_index).person_id,
5123 													   g_qual_pop_tbl (l_qual_pop_index).assignment_id,
5124 													   l_elig_obj_id,
5125 													   l_obj_date,
5126 													   g_qual_pop_tbl (l_qual_pop_index).business_group_id,
5127 													   'Y'                                              ---KMG -- Added to Allow CWK's
5128 													  );
5129 						 -- WPM Logging Changes
5130 						 hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).eligibility_status :=
5131 																												   l_check_elig_person;
5132 					  EXCEPTION
5133 						 WHEN OTHERS
5134 						 THEN
5135 							l_check_elig_person := 'N';
5136 							-- WPM Logging Changes
5137 							hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).eligibility_status :=
5138 																												  l_check_elig_person;
5139 							-- WPM Logging Changes Post Review
5140 							hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).MESSAGE_TYPE := 'E';
5141 							hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).message_number :=
5142 																															  'OTHER';
5143 							hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).MESSAGE_TEXT :=
5144 																															  SQLERRM;
5145 							hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).processing_status :=
5146 																															  'ERROR';
5147 																															 -- Error
5148 							op (   'Eligibility Check errored for: '
5149 								|| l_person_name
5150 								|| ' ('
5151 								|| g_qual_pop_tbl (l_qual_pop_index).person_id
5152 								|| '). No Scorecard created.',
5153 								g_regular_log
5154 							   );
5155 							op (SQLERRM, g_regular_log, 331);
5156 
5157 							--logged if the topmost person is excluded from the plan population     schowdhu 8744109
5158 							IF    (    l_plan_rec.hierarchy_type_code = 'SUP'
5159 								   AND l_plan_rec.supervisor_id = g_qual_pop_tbl (l_qual_pop_index).person_id
5160 								  )
5161 							   OR (    l_plan_rec.hierarchy_type_code = 'SUP_ASG'
5162 								   AND l_plan_rec.supervisor_assignment_id = g_qual_pop_tbl (l_qual_pop_index).assignment_id
5163 								  )
5164 							   OR (    l_plan_rec.hierarchy_type_code IN ('POS')
5165 								   AND l_plan_rec.top_position_id = g_qual_pop_tbl (l_qual_pop_index).position_id
5166 								  )
5167 							   OR (    l_plan_rec.hierarchy_type_code = 'ORG'
5168 								   AND is_supervisor_in_org (l_plan_rec.top_organization_id,
5169 															 g_qual_pop_tbl (l_qual_pop_index).person_id
5170 															) = 1
5171 								  )
5172 							THEN
5173 							   op ('+-------------------------------------------------------------------+', g_regular_log);
5174 							   op (   'Warning: Eligibility Check errored for the topmost person '
5175 								   || l_person_name
5176 								   || ' ('
5177 								   || g_qual_pop_tbl (l_qual_pop_index).person_id
5178 								   || ').',
5179 								   g_regular_log
5180 								  );
5181 							   op ('+-------------------------------------------------------------------+', g_regular_log);
5182 							   g_retcode := warning;
5183 							END IF;
5184 					  END;
5185 				   END IF;
5186 
5187 	--     l_elig_obj_id null check                                      -- Eligiblity profile is chosen END
5188 				   IF (l_check_elig_person = 'N')
5189 				   THEN
5190 					  op (   ' Not Eligible. Publish plan SKIPPED for '
5191 						  || l_person_name
5192 						  || ' ('
5193 						  || g_qual_pop_tbl (l_qual_pop_index).person_id
5194 						  || ').',
5195 						  g_regular_log
5196 						 );
5197 
5198 					  --logged if the topmost person is excluded from the plan population     schowdhu 8744109
5199 					  IF    (    l_plan_rec.hierarchy_type_code = 'SUP'
5200 							 AND l_plan_rec.supervisor_id = g_qual_pop_tbl (l_qual_pop_index).person_id
5201 							)
5202 						 OR (    l_plan_rec.hierarchy_type_code = 'SUP_ASG'
5203 							 AND l_plan_rec.supervisor_assignment_id = g_qual_pop_tbl (l_qual_pop_index).assignment_id
5204 							)
5205 						 OR (    l_plan_rec.hierarchy_type_code IN ('POS')
5206 							 AND l_plan_rec.top_position_id = g_qual_pop_tbl (l_qual_pop_index).position_id
5207 							)
5208 						 OR (    l_plan_rec.hierarchy_type_code = 'ORG'
5209 							 AND is_supervisor_in_org (l_plan_rec.top_organization_id, g_qual_pop_tbl (l_qual_pop_index).person_id) =
5210 																																	 1
5211 							)
5212 					  THEN
5213 						 op ('+-------------------------------------------------------------------+', g_regular_log);
5214 						 op (   'Warning: Topmost person '
5215 							 || l_person_name
5216 							 || ' ('
5217 							 || g_qual_pop_tbl (l_qual_pop_index).person_id
5218 							 || ') '
5219 							 || 'is excluded from   the plan as he is ineligble as per the eligibility profile attached. ',
5220 							 g_regular_log
5221 							);
5222 						 op ('+-------------------------------------------------------------------+', g_regular_log);
5223 						 g_retcode := warning;
5224 					  END IF;
5225 				   END IF;
5226 
5227 	-- end 23-Jun-2009 schowdhu Eligibility Profile Enhc.
5228 				   IF (l_check_elig_person = 'Y' OR (l_check_elig_person IS NULL AND l_elig_obj_id IS NULL))
5229 				   THEN
5230 					  -- Create the scorecard for this assignment
5231 					  IF g_dbg
5232 					  THEN
5233 						 op (l_proc, g_debug_log, 80);
5234 					  END IF;
5235 
5236 					  IF l_plan_rec.method_code = 'CAS'
5237 					  THEN
5238 						 IF    (    l_plan_rec.hierarchy_type_code = 'SUP'
5239 								AND l_plan_rec.supervisor_id = g_qual_pop_tbl (l_qual_pop_index).person_id
5240 							   )
5241 							OR (    l_plan_rec.hierarchy_type_code = 'SUP_ASG'
5242 								AND l_plan_rec.supervisor_assignment_id = g_qual_pop_tbl (l_qual_pop_index).assignment_id
5243 							   )
5244 							OR (    l_plan_rec.hierarchy_type_code IN ('POS')
5245 								AND l_plan_rec.top_position_id = g_qual_pop_tbl (l_qual_pop_index).position_id
5246 							   )
5247 							OR (    l_plan_rec.hierarchy_type_code = 'ORG'
5248 								AND is_supervisor_in_org (l_plan_rec.top_organization_id, g_qual_pop_tbl (l_qual_pop_index).person_id) =
5249 																																	 1
5250 							   )
5251 						 THEN
5252 							l_scorecard_status_code := 'NOT_STARTED_WITH_WKR';
5253 						 ELSE
5254 							l_scorecard_status_code := 'NOT_STARTED_WITH_MGR';
5255 						 END IF;
5256 					  ELSE
5257 						 l_scorecard_status_code := 'NOT_STARTED_WITH_WKR';
5258 					  END IF;
5259 
5260 					  --
5261 					  create_scorecard_for_person
5262 											  (p_effective_date                => l_effective_date,
5263 												   p_scorecard_name      => l_plan_rec.plan_name,
5264 												   p_assignment_id       => g_qual_pop_tbl (l_qual_pop_index).assignment_id,
5265 												   p_start_date          => l_plan_rec.start_date,
5266 												   p_end_date            => l_plan_rec.end_date,
5267 												   p_plan_id             => l_plan_rec.plan_id,
5268 												   p_creator_type        => 'AUTO',
5269 												   p_status_code         => l_scorecard_status_code,
5270 											   p_scorecard_id                  => l_scorecard_id,
5271 											   p_supervisor_id                 => g_qual_pop_tbl (l_qual_pop_index).supervisor_id,
5272 											   p_supervisor_assignment_id      => g_qual_pop_tbl (l_qual_pop_index).supervisor_assignment_id
5273 												  );
5274 
5275 					  -- Loop through objectives and create the qualifying objectives for scorecard
5276 					  -- make sure objectives are not created if scorecard is not created
5277 					  IF (l_plan_rec.automatic_allocation_flag = 'Y' AND l_scorecard_id IS NOT NULL)
5278 					  THEN
5279 						 l_qual_obj_index := g_qual_obj_tbl.FIRST;
5280 
5281 						 WHILE (l_qual_obj_index IS NOT NULL)
5282 						 LOOP
5283 							-- Following is commented, and l_obj_date is being set to sysdate bug# 5211538
5284 							-- l_obj_date is being seto to sysdate in the declare block itself
5285 							/*
5286 							-- objective date should be later of plan start date on obgective valif_from date
5287 							l_obj_date := l_plan_rec.start_date;
5288 							IF (l_plan_rec.start_date < g_qual_obj_tbl(l_qual_obj_index).valid_from) THEN
5289 							  l_obj_date := g_qual_obj_tbl(l_qual_obj_index).valid_from;
5290 							END IF;
5291 							*/
5292 							  --
5293 							  -- Enclose the call to eligibility within a block, so that if for any
5294 							  -- reason the eligibility engine errors, then process can still
5295 							  -- continue by skipping the current person/assignemnt as not eligible
5296 							  --
5297 							BEGIN
5298 							   --
5299 							   ben_env_object.init (p_business_group_id      => g_qual_pop_tbl (l_qual_pop_index).business_group_id,
5300 													p_thread_id              => NULL,
5301 													p_chunk_size             => NULL,
5302 													p_threads                => NULL,
5303 													p_max_errors             => NULL,
5304 													p_benefit_action_id      => NULL,
5305 													p_effective_date         => l_obj_date
5306 												   );
5307 
5308 							   --
5309 							   IF g_dbg
5310 							   THEN
5311 								  op (l_proc, g_debug_log, 222);
5312 								  op (l_proc || g_qual_obj_tbl (l_qual_obj_index).elig_obj_id, g_debug_log, 222);
5313 								  op (l_proc, g_debug_log, 222);
5314 							   END IF;
5315 
5316 							   --
5317 							   l_check_elig :=
5318 								  ben_per_asg_elig.eligible (g_qual_pop_tbl (l_qual_pop_index).person_id,
5319 															 g_qual_pop_tbl (l_qual_pop_index).assignment_id,
5320 															 g_qual_obj_tbl (l_qual_obj_index).elig_obj_id,
5321 															 l_obj_date,
5322 															 g_qual_pop_tbl (l_qual_pop_index).business_group_id,
5323 															 'Y'                                        ---KMG -- Added to Allow CWK's
5324 															);
5325 							EXCEPTION
5326 							   WHEN OTHERS
5327 							   THEN
5328 								  l_check_elig := 'N';
5329 
5330 								  IF g_dbg
5331 								  THEN
5332 									 op (l_proc, g_debug_log, 333);
5333 								  END IF;
5334 
5335 								  IF g_dbg
5336 								  THEN
5337 									 op (l_proc || ' SKIPPED ' || g_qual_obj_tbl (l_qual_obj_index).elig_obj_id, g_debug_log, 333);
5338 								  END IF;
5339 							END;
5340 
5341 							IF (l_check_elig = 'Y')
5342 							THEN
5343 							   -- Create the objective
5344 							   create_scorecard_objective
5345 												(p_effective_date              => l_effective_date,
5346 												 p_scorecard_id                => l_scorecard_id,
5347 												 p_business_group_id           => g_qual_pop_tbl (l_qual_pop_index).business_group_id,
5348 												 p_person_id                   => g_qual_pop_tbl (l_qual_pop_index).person_id,
5349 												 p_start_date                  => l_plan_rec.start_date,
5350 												 p_end_date                    => l_plan_rec.end_date,
5351 												 p_objective_name              => g_qual_obj_tbl (l_qual_obj_index).objective_name,
5352 												 p_valid_from                  => g_qual_obj_tbl (l_qual_obj_index).valid_from,
5353 												 p_valid_to                    => g_qual_obj_tbl (l_qual_obj_index).valid_to,
5354 												 p_target_date                 => g_qual_obj_tbl (l_qual_obj_index).target_date,
5355 												 p_copied_from_library_id      => g_qual_obj_tbl (l_qual_obj_index).objective_id,
5356 												 p_next_review_date            => g_qual_obj_tbl (l_qual_obj_index).next_review_date,
5357 												 p_group_code                  => g_qual_obj_tbl (l_qual_obj_index).group_code,
5358 												 p_priority_code               => g_qual_obj_tbl (l_qual_obj_index).priority_code,
5359 												 p_appraise_flag               => g_qual_obj_tbl (l_qual_obj_index).appraise_flag,
5360 												 p_weighting_percent           => g_qual_obj_tbl (l_qual_obj_index).weighting_percent,
5361 												 p_target_value                => g_qual_obj_tbl (l_qual_obj_index).target_value,
5362 												 p_uom_code                    => g_qual_obj_tbl (l_qual_obj_index).uom_code,
5363 												 p_measurement_style_code      => g_qual_obj_tbl (l_qual_obj_index).measurement_style_code,
5364 												 p_measure_name                => g_qual_obj_tbl (l_qual_obj_index).measure_name,
5365 												 p_measure_type_code           => g_qual_obj_tbl (l_qual_obj_index).measure_type_code,
5366 												 p_measure_comments            => g_qual_obj_tbl (l_qual_obj_index).measure_comments,
5367 												 p_details                     => g_qual_obj_tbl (l_qual_obj_index).details,
5368 												 p_success_criteria            => g_qual_obj_tbl (l_qual_obj_index).success_criteria,
5369 												 p_comments                    => g_qual_obj_tbl (l_qual_obj_index).comments
5370 												);
5371 							END IF;
5372 
5373 							--
5374 							l_qual_obj_index := g_qual_obj_tbl.NEXT (l_qual_obj_index);
5375 						 --
5376 						 END LOOP;                                                                     -- l_qual_obj_index IS NOT NULL
5377 					  END IF;                                                                  -- l_plan_rec.automatic_allocation_flag
5378 
5379 					  --
5380 					  -- Copy past objectives if the flag is set and previous plan id is available
5381 					  --
5382 					  IF (l_plan_rec.copy_past_objectives_flag = 'Y' AND l_plan_rec.previous_plan_id IS NOT NULL)
5383 					  THEN
5384 						 --
5385 						 copy_past_objectives (p_effective_date         => l_effective_date,
5386 											   p_business_group_id      => g_qual_pop_tbl (l_qual_pop_index).business_group_id,
5387 											   p_person_id              => g_qual_pop_tbl (l_qual_pop_index).person_id,
5388 											   p_scorecard_id           => l_scorecard_id,
5389 											   p_start_date             => l_plan_rec.start_date,
5390 											   p_end_date               => l_plan_rec.end_date,
5391 											   p_target_date            => NULL,
5392 											   p_assignemnt_id          => g_qual_pop_tbl (l_qual_pop_index).assignment_id,
5393 											   p_prev_plan_id           => l_plan_rec.previous_plan_id,
5394 											   p_curr_plan_id           => l_plan_rec.plan_id
5395 											  );
5396 					  --
5397 					  END IF;                                                                               -- Copying past Objectives
5398 				   --
5399 
5400 				   --
5401 				   END IF;
5402 				END IF;                                                                                          -- Elig Profile Check
5403 			 ELSIF (l_plan_rec.status_code IN ('UPDATED', 'RESUBMITTED') AND g_curr_sc_pop_tbl.EXISTS (l_qual_pop_index))
5404 			 THEN
5405 				-- If objective setting flag is set
5406 				IF ((l_plan_rec.include_obj_setting_flag = 'Y') OR (l_plan_rec.include_appraisals_flag = 'Y'))
5407 				THEN
5408 				   -- Update the scorecard for this assignment
5409 				   IF g_dbg
5410 				   THEN
5411 					  op (l_proc, g_debug_log, 90);
5412 				   END IF;
5413 
5414 				   l_scorecard_id := g_curr_sc_pop_tbl (l_qual_pop_index).scorecard_id;
5415 
5416 				   -- additional AND clause added to the IF condition, as we do not want to change the
5417 				   -- scorecard status unless status is PUBLISHED
5418 				   IF (    NVL (l_plan_rec.change_sc_status_flag, 'N') = 'Y'
5419 					   AND g_curr_sc_pop_tbl (l_qual_pop_index).status_code = 'PUBLISHED'
5420 					  )
5421 				   THEN
5422 					  IF l_plan_rec.method_code = 'CAS'
5423 					  THEN
5424 						 --
5425 						 IF    (    l_plan_rec.hierarchy_type_code = 'SUP'
5426 								AND l_plan_rec.supervisor_id = g_qual_pop_tbl (l_qual_pop_index).person_id
5427 							   )
5428 							OR (    l_plan_rec.hierarchy_type_code = 'SUP_ASG'
5429 								AND l_plan_rec.supervisor_assignment_id = g_qual_pop_tbl (l_qual_pop_index).assignment_id
5430 							   )
5431 							OR (    l_plan_rec.hierarchy_type_code IN ('POS')
5432 								AND l_plan_rec.top_position_id = g_qual_pop_tbl (l_qual_pop_index).position_id
5433 							   )
5434 							OR (    l_plan_rec.hierarchy_type_code = 'ORG'
5435 								AND is_supervisor_in_org (l_plan_rec.top_organization_id, g_qual_pop_tbl (l_qual_pop_index).person_id) =
5436 																																	 1
5437 							   )
5438 						 THEN
5439 							l_scorecard_status_code := 'NOT_STARTED_WITH_WKR';
5440 						 ELSE
5441 							l_scorecard_status_code := 'NOT_STARTED_WITH_MGR';
5442 						 END IF;
5443 					  ELSE
5444 						 l_scorecard_status_code := 'NOT_STARTED_WITH_WKR';
5445 					  END IF;
5446 
5447 					  --
5448 					  update_scorecard_for_person
5449 												(p_effective_date             => l_effective_date,
5450 												 p_scorecard_id               => l_scorecard_id,
5451 												 p_object_version_number      => g_curr_sc_pop_tbl (l_qual_pop_index).object_version_number,
5452 												 p_scorecard_name             => l_plan_rec.plan_name,
5453 												 p_start_date                 => l_plan_rec.start_date,
5454 												 p_end_date                   => l_plan_rec.end_date,
5455 												 p_status_code                => l_scorecard_status_code
5456 												);
5457 				   ELSE
5458 					  update_scorecard_for_person
5459 											   (p_effective_date             => l_effective_date,
5460 												p_scorecard_id               => l_scorecard_id,
5461 												p_object_version_number      => g_curr_sc_pop_tbl (l_qual_pop_index).object_version_number,
5462 												p_scorecard_name             => l_plan_rec.plan_name,
5463 												p_start_date                 => l_plan_rec.start_date,
5464 												p_end_date                   => l_plan_rec.end_date
5465 											   );
5466 				   END IF;
5467 
5468 				   --
5469 				   IF g_dbg
5470 				   THEN
5471 					  op (l_proc, g_debug_log, 100);
5472 				   END IF;
5473 
5474 						--
5475 						-- Populate existing objectives for this scorecard
5476 				   -- g_curr_sc_obj_tbl is populated with index as 'copied_from_library_id'
5477 				   --
5478 				   populate_curr_sc_objectives (l_scorecard_id);
5479 
5480 				   -- Loop through objectives and create the qualifying objectives for scorecard
5481 				   -- make sure objectives are not created if scorecard is not created
5482 				   IF (l_plan_rec.automatic_allocation_flag = 'Y' AND l_scorecard_id IS NOT NULL)
5483 				   THEN
5484 					  l_qual_obj_index := g_qual_obj_tbl.FIRST;
5485 
5486 					  WHILE (l_qual_obj_index IS NOT NULL)
5487 					  LOOP
5488 						 -- Following is commented, and l_obj_date is being set to sysdate bug# 5211538
5489 						 -- l_obj_date is being seto to sysdate in the declare block itself
5490 						 /*
5491 						 -- objective date should be later of plan start date on obgective valif_from date
5492 						 l_obj_date := l_plan_rec.start_date;
5493 						 IF (l_plan_rec.start_date < g_qual_obj_tbl(l_qual_obj_index).valid_from) THEN
5494 						   l_obj_date := g_qual_obj_tbl(l_qual_obj_index).valid_from;
5495 						 END IF;
5496 						 */
5497 						 --
5498 						 -- Enclose the call to eligibility within a block, so that if for any
5499 						 -- reason the eligibility engine errors, then process can still
5500 						 -- continue by skipping the current person/assignemnt as not eligible
5501 						 --
5502 						 BEGIN
5503 							--
5504 							ben_env_object.init (p_business_group_id      => g_qual_pop_tbl (l_qual_pop_index).business_group_id,
5505 												 p_thread_id              => NULL,
5506 												 p_chunk_size             => NULL,
5507 												 p_threads                => NULL,
5508 												 p_max_errors             => NULL,
5509 												 p_benefit_action_id      => NULL,
5510 												 p_effective_date         => l_obj_date
5511 												);
5512 
5513 							--
5514 							IF g_dbg
5515 							THEN
5516 							   op (l_proc, g_debug_log, 222);
5517 							   op (l_proc || g_qual_obj_tbl (l_qual_obj_index).elig_obj_id, g_debug_log, 222);
5518 							   op (l_proc, g_debug_log, 222);
5519 							END IF;
5520 
5521 							--
5522 							l_check_elig :=
5523 							   ben_per_asg_elig.eligible (g_qual_pop_tbl (l_qual_pop_index).person_id,
5524 														  g_qual_pop_tbl (l_qual_pop_index).assignment_id,
5525 														  g_qual_obj_tbl (l_qual_obj_index).elig_obj_id,
5526 														  l_obj_date,
5527 														  g_qual_pop_tbl (l_qual_pop_index).business_group_id,
5528 														  'Y'                                           ---KMG -- Added to Allow CWK's
5529 														 );
5530 						 EXCEPTION
5531 							WHEN OTHERS
5532 							THEN
5533 							   l_check_elig := 'N';
5534 
5535 							   IF g_dbg
5536 							   THEN
5537 								  op (l_proc, g_debug_log, 333);
5538 							   END IF;
5539 
5540 							   IF g_dbg
5541 							   THEN
5542 								  op (l_proc || '-- SKIPPED --' || g_qual_obj_tbl (l_qual_obj_index).elig_obj_id, g_debug_log, 333);
5543 							   END IF;
5544 						 END;
5545 
5546 						 --
5547 						 IF (l_check_elig = 'Y')
5548 						 THEN
5549 							--
5550 							-- if it's newly qualified objective then create else update
5551 							--
5552 							IF (NOT g_curr_sc_obj_tbl.EXISTS (g_qual_obj_tbl (l_qual_obj_index).objective_id))
5553 							THEN
5554 							   -- Create the objective
5555 							   create_scorecard_objective
5556 												(p_effective_date              => l_effective_date,
5557 												 p_scorecard_id                => l_scorecard_id,
5558 												 p_business_group_id           => g_qual_pop_tbl (l_qual_pop_index).business_group_id,
5559 												 p_person_id                   => g_qual_pop_tbl (l_qual_pop_index).person_id,
5560 												 p_start_date                  => l_plan_rec.start_date,
5561 												 p_end_date                    => l_plan_rec.end_date,
5562 												 p_objective_name              => g_qual_obj_tbl (l_qual_obj_index).objective_name,
5563 												 p_valid_from                  => g_qual_obj_tbl (l_qual_obj_index).valid_from,
5564 												 p_valid_to                    => g_qual_obj_tbl (l_qual_obj_index).valid_to,
5565 												 p_target_date                 => g_qual_obj_tbl (l_qual_obj_index).target_date,
5566 												 p_copied_from_library_id      => g_qual_obj_tbl (l_qual_obj_index).objective_id,
5567 												 p_next_review_date            => g_qual_obj_tbl (l_qual_obj_index).next_review_date,
5568 												 p_group_code                  => g_qual_obj_tbl (l_qual_obj_index).group_code,
5569 												 p_priority_code               => g_qual_obj_tbl (l_qual_obj_index).priority_code,
5570 												 p_appraise_flag               => g_qual_obj_tbl (l_qual_obj_index).appraise_flag,
5571 												 p_weighting_percent           => g_qual_obj_tbl (l_qual_obj_index).weighting_percent,
5572 												 p_target_value                => g_qual_obj_tbl (l_qual_obj_index).target_value,
5573 												 p_uom_code                    => g_qual_obj_tbl (l_qual_obj_index).uom_code,
5574 												 p_measurement_style_code      => g_qual_obj_tbl (l_qual_obj_index).measurement_style_code,
5575 												 p_measure_name                => g_qual_obj_tbl (l_qual_obj_index).measure_name,
5576 												 p_measure_type_code           => g_qual_obj_tbl (l_qual_obj_index).measure_type_code,
5577 												 p_measure_comments            => g_qual_obj_tbl (l_qual_obj_index).measure_comments,
5578 												 p_details                     => g_qual_obj_tbl (l_qual_obj_index).details,
5579 												 p_success_criteria            => g_qual_obj_tbl (l_qual_obj_index).success_criteria,
5580 												 p_comments                    => g_qual_obj_tbl (l_qual_obj_index).comments
5581 												);
5582 							--
5583 							ELSE
5584 							   IF (NVL (l_plan_rec.update_library_objectives, 'N') = 'Y')
5585 							   THEN                                                                                -- 8740021 bug fix
5586 								  -- Update the objective
5587 								  update_scorecard_objective
5588 											   (p_effective_date              => l_effective_date,
5589 												p_objective_id                => g_curr_sc_obj_tbl (l_qual_obj_index).objective_id,
5590 												p_object_version_number       => g_curr_sc_obj_tbl (l_qual_obj_index).object_version_number,
5591 												p_scorecard_id                => l_scorecard_id,
5592 												p_start_date                  => l_plan_rec.start_date,
5593 												p_end_date                    => l_plan_rec.end_date,
5594 												p_objective_name              => g_qual_obj_tbl (l_qual_obj_index).objective_name,
5595 												p_valid_from                  => g_qual_obj_tbl (l_qual_obj_index).valid_from,
5596 												p_valid_to                    => g_qual_obj_tbl (l_qual_obj_index).valid_to,
5597 												p_target_date                 => g_qual_obj_tbl (l_qual_obj_index).target_date,
5598 												p_copied_from_library_id      => g_qual_obj_tbl (l_qual_obj_index).objective_id,
5599 												p_next_review_date            => g_qual_obj_tbl (l_qual_obj_index).next_review_date,
5600 												p_group_code                  => g_qual_obj_tbl (l_qual_obj_index).group_code,
5601 												p_priority_code               => g_qual_obj_tbl (l_qual_obj_index).priority_code,
5602 												p_appraise_flag               => g_qual_obj_tbl (l_qual_obj_index).appraise_flag,
5603 												p_weighting_percent           => g_qual_obj_tbl (l_qual_obj_index).weighting_percent,
5604 												p_target_value                => g_qual_obj_tbl (l_qual_obj_index).target_value,
5605 												p_uom_code                    => g_qual_obj_tbl (l_qual_obj_index).uom_code,
5606 												p_measurement_style_code      => g_qual_obj_tbl (l_qual_obj_index).measurement_style_code,
5607 												p_measure_name                => g_qual_obj_tbl (l_qual_obj_index).measure_name,
5608 												p_measure_type_code           => g_qual_obj_tbl (l_qual_obj_index).measure_type_code,
5609 												p_measure_comments            => g_qual_obj_tbl (l_qual_obj_index).measure_comments,
5610 												p_details                     => g_qual_obj_tbl (l_qual_obj_index).details,
5611 												p_success_criteria            => g_qual_obj_tbl (l_qual_obj_index).success_criteria,
5612 												p_comments                    => g_qual_obj_tbl (l_qual_obj_index).comments
5613 											   );
5614 							   END IF;                                                                              -- 8740021 bug fix
5615 							END IF;
5616 						 --
5617 						 ELSE
5618 							--
5619 								 --  End date objectives that qulify but are not eligible anymore and exists in current objectives
5620 								 --
5621 							IF g_dbg
5622 							THEN
5623 							   op (l_proc, g_debug_log, 110);
5624 							END IF;
5625 
5626 							--
5627 							IF (g_curr_sc_obj_tbl.EXISTS (g_qual_obj_tbl (l_qual_obj_index).objective_id))
5628 							THEN
5629 							   update_scorecard_objective
5630 											   (p_effective_date             => l_effective_date,
5631 												p_start_date                 => l_plan_rec.start_date,
5632 												p_objective_id               => g_curr_sc_obj_tbl (l_qual_obj_index).objective_id,
5633 												p_object_version_number      => g_curr_sc_obj_tbl (l_qual_obj_index).object_version_number,
5634 												p_end_date                   => l_effective_date
5635 											   );
5636 							END IF;
5637 						 --
5638 						 END IF;                                                                                      --Eligible check
5639 
5640 						 --
5641 						 l_qual_obj_index := g_qual_obj_tbl.NEXT (l_qual_obj_index);
5642 					  --
5643 					  END LOOP;
5644 				   --
5645 				   END IF;                                                                                 --automatic_allocation_flag
5646 					 --
5647 					 -- Copy past objectives if the flag is set and previous plan id is available
5648 					 --
5649 					--  7707697 Bug fix, Copy Past Objectives method need not be called during
5650 					 --  scorecard update, hence commenting it
5651 				  /*   IF (l_plan_rec.copy_past_objectives_flag = 'Y' AND l_plan_rec.previous_plan_id is not NULL)
5652 					 THEN
5653 					 --
5654 					   copy_past_objectives
5655 						 (p_effective_date            => l_effective_date
5656 						 ,p_business_group_id         => g_qual_pop_tbl(l_qual_pop_index).business_group_id
5657 						 ,p_person_id                 => g_qual_pop_tbl(l_qual_pop_index).person_id
5658 						 ,p_scorecard_id              => l_scorecard_id
5659 						 ,p_start_date                => l_plan_rec.start_date
5660 						 ,p_end_date                  => l_plan_rec.end_date
5661 						 ,p_target_date               => null
5662 						 ,p_assignemnt_id             => g_qual_pop_tbl(l_qual_pop_index).assignment_id
5663 						 ,p_prev_plan_id              => l_plan_rec.previous_plan_id
5664 						 ,p_curr_plan_id              => l_plan_rec.plan_id);
5665 					   --
5666 					 END IF;  */
5667 					 --
5668 				-- End date objectives that exists in current scorecard objectives but does not qualify anymore
5669 				--
5670 				   /* Commenting as this code is rdundant.. for fixing bug#7560950
5671 				l_curr_sc_obj_index := g_curr_sc_obj_tbl.FIRST;
5672 					 WHILE(l_curr_sc_obj_index IS NOT NULL)
5673 					 LOOP
5674 				  IF (NOT g_qual_obj_tbl.EXISTS(l_curr_sc_obj_index)) THEN
5675 						 --
5676 						 IF g_dbg THEN op(l_proc, g_DEBUG_LOG, 120); END IF;
5677 						 --
5678 						 update_scorecard_objective(
5679 							  p_effective_date        =>  l_effective_date
5680 							 ,p_start_date             => l_plan_rec.start_date
5681 							 ,p_objective_id          =>  g_curr_sc_obj_tbl(l_curr_sc_obj_index).objective_id
5682 							 ,p_object_version_number =>  g_curr_sc_obj_tbl(l_curr_sc_obj_index).object_version_number
5683 							 ,p_end_date              =>  l_effective_date);
5684 				  END IF;
5685 					   --
5686 				  l_curr_sc_obj_index := g_curr_sc_obj_tbl.NEXT(l_curr_sc_obj_index);
5687 				  --
5688 					 END LOOP;
5689 				  --commented upto here for bug#7560950*/
5690 				END IF;
5691 				--
5692 			   /* ELSIF (l_plan_rec.status_code = 'PUBLISHED') THEN
5693 			 -- If objective setting flag is set
5694 			 IF (l_plan_rec.include_obj_setting_flag = 'Y') THEN
5695 
5696 			   IF g_dbg THEN op(l_proc, g_DEBUG_LOG, 130); END IF;
5697 			   -- Loop though and delete the objectives for scorecard
5698 					FOR obj_rec IN csr_sc_objectives(g_curr_sc_pop_tbl(l_qual_pop_index).scorecard_id)
5699 					LOOP
5700 					  delete_scorecard_objective(p_objective_id          =>  obj_rec.objective_id
5701 												,p_object_version_number =>  obj_rec.object_version_number);
5702 					END LOOP;
5703 
5704 			   -- Delete the scorecard
5705 					delete_scorecard_for_person(g_curr_sc_pop_tbl(l_qual_pop_index).scorecard_id
5706 											   ,g_curr_sc_pop_tbl(l_qual_pop_index).object_version_number);
5707 				  END IF;
5708 				  --
5709 				  IF (l_plan_rec.include_appraisals_flag = 'Y') THEN
5710 					FOR plan_appraisals IN csr_plan_appraisals(p_plan_id)
5711 					LOOP
5712 					  delete_appraisal_for_person(plan_appraisals.appraisal_id,plan_appraisals.object_version_number);
5713 					END LOOP;
5714 				  END IF;*/
5715 				--
5716 			 END IF;
5717 
5718 			 --
5719 			 --  Get the next index value
5720 			 --
5721 			 l_qual_pop_index := g_qual_pop_tbl.NEXT (l_qual_pop_index);
5722 
5723 			 -- WPM  Logging changes
5724 			 IF hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).processing_status = 'P'
5725 			 THEN
5726 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).processing_status := 'SUCCESS';
5727 																														   -- Success
5728 			 END IF;
5729 		  --
5730 		  END LOOP;
5731 
5732 	--
5733 	--    ===========================================================================================
5734 	--- DELETE the non qualifying scorecards and the appraisals( for terminated employees) changes for 6460457
5735 		  l_curr_sc_pop_index := g_curr_sc_pop_tbl.FIRST;
5736 
5737 		  WHILE (l_curr_sc_pop_index IS NOT NULL)
5738 		  LOOP
5739 			 BEGIN
5740 				IF (l_plan_rec.status_code IN ('UPDATED', 'RESUBMITTED') AND NOT g_qual_pop_tbl.EXISTS (l_curr_sc_pop_index))
5741 				THEN
5742 				   -- If objective setting flag is set
5743 
5744 				   --IF (l_plan_rec.include_obj_setting_flag = 'Y') THEN
5745 				   IF g_dbg
5746 				   THEN
5747 					  op (l_proc, g_debug_log, 130);
5748 				   END IF;
5749 
5750 		 -- Loop though and delete the objectives for scorecard
5751 	-- 7321947 will not delete any record for non-qualifying scorecards.
5752 			/*  FOR obj_rec IN csr_sc_objectives(g_curr_sc_pop_tbl(l_curr_sc_pop_index).scorecard_id)
5753 			  LOOP
5754 
5755 				delete_scorecard_objective(p_objective_id          =>  obj_rec.objective_id
5756 										  ,p_object_version_number =>  obj_rec.object_version_number);
5757 			  END LOOP;*/
5758 		   -- END IF;
5759 				  --- delete the appraisals for the person
5760 				   IF (l_plan_rec.include_appraisals_flag = 'Y')
5761 				   THEN
5762 					  --  FOR plan_appraisals IN csr_plan_appraisals(p_plan_id)
5763 					  OPEN csr_find_appr_for_scorecard (p_plan_id, g_curr_sc_pop_tbl (l_curr_sc_pop_index).scorecard_id);
5764 
5765 					  LOOP
5766 						 hr_utility.set_location ('Before transfer out _for_person', 107);
5767 
5768 						 FETCH csr_find_appr_for_scorecard
5769 						  INTO l_appr_id, l_appr_ovn, l_appr_sys_status;
5770 
5771 						 EXIT WHEN csr_find_appr_for_scorecard%NOTFOUND;
5772 
5773 						 IF l_appr_sys_status NOT IN ('COMPLETED','APPRFEEDBACK')
5774 						 THEN
5775 							UPDATE per_appraisals
5776 							   SET appraisal_system_status = 'TRANSFER_OUT'
5777 							 WHERE appraisal_id = l_appr_id;
5778 
5779 	-- revoke the participant statuses and close them.NOt deleting them if feedback is already provided.
5780 							FOR i IN csr_get_appr_part (l_appr_id)
5781 							LOOP
5782 							   UPDATE per_participants
5783 								  SET participation_status = 'CLOSED'
5784 								WHERE participant_id = i.participant_id;
5785 							END LOOP;
5786 	-- we are doing a direct update as update API will not work for terminated and traansfer employees
5787 	-- update it to transfer out so as to not show the details anywhere
5788 						 END IF;
5789 
5790 						 hr_utility.set_location ('After transfer out appraisal_for_person appraisal_id: ' || l_appr_id, 107);
5791 					  END LOOP;
5792 
5793 					  CLOSE csr_find_appr_for_scorecard;
5794 				   END IF;
5795 
5796 				   -- Delete the scorecard
5797 
5798 				   /*  delete_scorecard_for_person(g_curr_sc_pop_tbl(l_curr_sc_pop_index).scorecard_id
5799 												,g_curr_sc_pop_tbl(l_curr_sc_pop_index).object_version_number);    */
5800 				   hr_personal_scorecard_api.update_scorecard
5801 											 (p_effective_date              => TRUNC (SYSDATE),
5802 											  p_scorecard_id                => g_curr_sc_pop_tbl (l_curr_sc_pop_index).scorecard_id,
5803 											  p_object_version_number       => g_curr_sc_pop_tbl (l_curr_sc_pop_index).object_version_number,
5804 											  p_duplicate_name_warning      => l_dummy,
5805 											  p_status_code                 => 'TRANSFER_OUT'
5806 											 );
5807 				--
5808 
5809 				--
5810 				END IF;
5811 			 EXCEPTION
5812 				WHEN OTHERS
5813 				THEN
5814 					  -- WPM  Logging changes
5815 					  /*
5816 					  hr_wpm_mass_apr_push.g_wpm_person_actions(hr_wpm_mass_apr_push.log_records_index).MESSAGE_TYPE := 'E';
5817 					  hr_wpm_mass_apr_push.g_wpm_person_actions(hr_wpm_mass_apr_push.log_records_index).MESSAGE_NUMBER := 'OTHER';
5818 					  hr_wpm_mass_apr_push.g_wpm_person_actions(hr_wpm_mass_apr_push.log_records_index).MESSAGE_TEXT := SQLERRM;
5819 				   */
5820 				   IF g_dbg
5821 				   THEN
5822 					  op ('Leaving:' || l_proc, g_regular_log, 90);
5823 				   END IF;
5824 
5825 				   --
5826 				   fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
5827 				   g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
5828 				   g_retcode := warning;
5829 				   g_errbuf := g_cp_error_txt;
5830 				   g_num_errors := g_num_errors + 1;
5831 
5832 				   IF g_dbg
5833 				   THEN
5834 					  op (g_error_txt, g_regular_log);
5835 				   END IF;
5836 
5837 				   IF g_dbg
5838 				   THEN
5839 					  op (SQLERRM, g_regular_log);
5840 				   END IF;
5841 
5842 				   --
5843 				   -- If the max number of errors has been exceeded, raise the error and
5844 				   -- terminate processing of this plan.
5845 				   --
5846 				   IF g_num_errors > g_max_errors
5847 				   THEN
5848 					  fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
5849 					  g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
5850 					  g_retcode := error;
5851 					  g_errbuf := g_error_txt;
5852 					  RAISE;
5853 				   END IF;
5854 			 END;
5855 
5856 			 --------- iterate the loop
5857 			 l_curr_sc_pop_index := g_curr_sc_pop_tbl.NEXT (l_curr_sc_pop_index);
5858 		  END LOOP;
5859 
5860 	---  DELETE logic ends( replaced by 7321947 changes)
5861 	--============================================================================================
5862 		  IF g_dbg
5863 		  THEN
5864 			 op (l_proc, g_debug_log, 140);
5865 		  END IF;
5866 
5867 			  --
5868 			  -- If the plan is republished, End date scorecards, objectives and
5869 			  -- appraisals for existing population that does not qualify anymore
5870 			  --
5871 		   /* Bug# 6648036 changes Begin Commenting the if Condition
5872 		   IF (l_plan_rec.status_code in ('UPDATED','RESUBMITTED') AND l_plan_rec.include_obj_setting_flag = 'Y') THEN
5873 				--
5874 				l_curr_sc_pop_index := g_curr_sc_pop_tbl.FIRST;
5875 				WHILE (l_curr_sc_pop_index IS NOT NULL)
5876 				LOOP
5877 				  IF (NOT g_qual_pop_tbl.EXISTS(l_curr_sc_pop_index)) THEN
5878 					--
5879 			   IF g_dbg THEN op(l_proc, g_DEBUG_LOG, 150); END IF;
5880 					--
5881 			   -- Loop though objectives for scorecards
5882 					FOR obj_rec IN csr_sc_objectives(g_curr_sc_pop_tbl(l_curr_sc_pop_index).scorecard_id)
5883 			   LOOP
5884 					  update_scorecard_objective(
5885 						   p_effective_date        =>  l_effective_date
5886 						  ,p_start_date             => l_plan_rec.start_date
5887 						  ,p_objective_id          =>  obj_rec.objective_id
5888 						  ,p_object_version_number =>  obj_rec.object_version_number
5889 						  ,p_end_date              =>  l_effective_date);
5890 					END LOOP;
5891 
5892 					--
5893 			   IF g_dbg THEN op(l_proc, g_DEBUG_LOG, 160); END IF;
5894 			   --
5895 					  update_scorecard_for_person(
5896 						   p_effective_date        =>  l_effective_date
5897 						  ,p_start_date            =>  l_plan_rec.start_date --Added for 5725110
5898 						  ,p_scorecard_id          =>  g_curr_sc_pop_tbl(l_curr_sc_pop_index).scorecard_id
5899 						  ,p_object_version_number =>  g_curr_sc_pop_tbl(l_curr_sc_pop_index).object_version_number
5900 						  ,p_end_date              =>  l_effective_date);
5901 				  END IF;
5902 				--
5903 				l_curr_sc_pop_index := g_curr_sc_pop_tbl.NEXT(l_curr_sc_pop_index);
5904 				--
5905 				END LOOP;
5906 			  END IF;
5907 
5908 		  Bug# 6648036 Changes End */
5909 
5910 		  --
5911 		  IF g_dbg
5912 		  THEN
5913 			 op (l_proc, g_debug_log, 170);
5914 		  END IF;
5915 
5916 		  --
5917 		  -- Update the plan status
5918 		  --
5919 		  l_object_version_number := l_plan_rec.object_version_number;
5920 
5921 		  IF (p_reverse_mode = 'Y')
5922 		  THEN
5923 			 IF g_dbg
5924 			 THEN
5925 				op (l_proc, g_debug_log, 180);
5926 			 END IF;
5927 
5928 			 l_status_code := 'DRAFT';
5929 		  ELSE
5930 			 IF g_dbg
5931 			 THEN
5932 				op (l_proc, g_debug_log, 190);
5933 			 END IF;
5934 
5935 			 l_status_code := 'PUBLISHED';
5936 		  END IF;
5937 
5938 		  --
5939 		  per_pmp_upd.upd (p_plan_id                     => l_plan_rec.plan_id,
5940 						   p_effective_date              => l_effective_date,
5941 						   p_object_version_number       => l_object_version_number,
5942 						   p_status_code                 => l_status_code,
5943 						   p_change_sc_status_flag       => NULL,
5944 						   p_duplicate_name_warning      => l_dummy,
5945 						   p_no_life_events_warning      => l_dummy
5946 						  );
5947 		  -- Return the new object version number
5948 		  p_object_version_number := l_object_version_number;
5949 
5950 		  --
5951 		  IF g_dbg
5952 		  THEN
5953 			 op (l_proc, g_debug_log, 200);
5954 		  END IF;
5955 
5956 		  --
5957 		  -- Submit the workflow process for notifying plan population
5958 		  -- Commented out the following line. No matter what this flag,
5959 		  -- notifications to be sent. Bug# 5225196
5960 		  --IF (l_plan_rec.include_obj_setting_flag = 'Y' AND
5961 		  IF (l_plan_rec.notify_population_flag = 'Y')
5962 		  THEN
5963 			 --
5964 			 IF g_dbg
5965 			 THEN
5966 				op (l_proc, g_debug_log, 210);
5967 			 END IF;
5968 
5969 			 --
5970 			 start_process (p_plan_rec            => l_plan_rec,
5971 							p_effective_date      => l_effective_date,
5972 							p_reverse_mode        => p_reverse_mode,
5973 							p_item_type           => p_item_type,
5974 							p_wf_process          => p_wf_process
5975 						   );
5976 		  END IF;
5977 
5978 		  --
5979 		  IF g_dbg
5980 		  THEN
5981 			 op (l_proc, g_debug_log, 220);
5982 		  END IF;
5983 
5984 		  --
5985 		  -- Always Send notification to administrator that plan has been published.
5986 		  --
5987 		  send_fyi_admin (p_plan_rec => l_plan_rec, p_status => 'PUBLISHED', p_request_id => fnd_global.conc_request_id);
5988 
5989 		  IF g_dbg
5990 		  THEN
5991 			 op (l_proc, g_debug_log, 210);
5992 		  END IF;
5993 
5994 		  --
5995 		  COMMIT;
5996 
5997 		  IF (   l_plan_rec.status_code IN ('DRAFT', 'SUBMITTED')
5998 			  OR (l_plan_rec.status_code IN ('UPDATED', 'RESUBMITTED') AND NOT g_curr_sc_pop_tbl.EXISTS (l_qual_pop_index))
5999 			 )
6000 		  THEN
6001 			 --
6002 			 -- Create Appraisals if flag is set
6003 			 --
6004 			 IF (l_plan_rec.include_appraisals_flag = 'Y')
6005 			 THEN
6006 				--
6007 				l_plan_aprsl_pds_index := g_plan_aprsl_pds_tbl.FIRST;
6008 
6009 				WHILE (l_plan_aprsl_pds_index IS NOT NULL)
6010 				LOOP
6011 				   --
6012 				   IF (g_plan_aprsl_pds_tbl (l_plan_aprsl_pds_index).auto_conc_process = 'Y')
6013 				   THEN
6014 					  l_process_date :=
6015 						   g_plan_aprsl_pds_tbl (l_plan_aprsl_pds_index).task_start_date
6016 						 - NVL (g_plan_aprsl_pds_tbl (l_plan_aprsl_pds_index).days_before_task_st_dt, 0);
6017 					  l_process_date_char := TO_CHAR (l_process_date, fnd_conc_date.get_date_format (TRUNC (SYSDATE)));
6018 
6019 					  --
6020 					  IF g_dbg
6021 					  THEN
6022 						 op ('Eff_date is ' || p_effective_date, g_debug_log, 90);
6023 						 op ('l_process_date is ' || l_process_date, g_debug_log, 90);
6024 						 op ('l_process_date_CHAR is ' || l_process_date_char, g_debug_log, 90);
6025 					  END IF;
6026 
6027 								 --
6028 								 -- Do not call appraisal_push, if process_date < sysdate.
6029 								 --
6030 					  -- changes for cancelling pending requests
6031 					  BEGIN
6032 						 FOR conc IN previous_concurrent_requests (p_plan_id,
6033 																   g_plan_aprsl_pds_tbl (l_plan_aprsl_pds_index).appraisal_period_id
6034 																  )
6035 						 LOOP
6036 							l_conc_request_id := conc.request_id;
6037 							l_ret := fnd_concurrent.cancel_request (conc.request_id, l_message_req);
6038 
6039 							IF l_ret
6040 							THEN
6041 							   l_submit_new_req := TRUE;
6042 							ELSE
6043 							   RAISE e;
6044 							END IF;
6045 						 END LOOP;
6046 					  EXCEPTION
6047 						 WHEN e
6048 						 THEN
6049 							l_submit_new_req := FALSE;
6050 					  END;
6051 
6052 					  IF NOT l_submit_new_req
6053 					  THEN
6054 						 IF g_dbg
6055 						 THEN
6056 							op ('Unable to cancel request ' || l_conc_request_id, g_regular_log, 10);
6057 						 END IF;
6058 					  ELSE
6059 						 IF g_dbg
6060 						 THEN
6061 							op ('Able to  cancel all pending requests ', g_regular_log, 10);
6062 						 END IF;
6063 					  END IF;
6064 
6065 					  IF l_process_date >= TRUNC (SYSDATE) AND l_submit_new_req
6066 					  THEN
6067 						 hr_wpm_mass_apr_push.submit_appraisal_cp
6068 										  (p_effective_date           => l_process_date,
6069 										   p_start_date               => l_process_date_char,
6070 										   p_plan_id                  => p_plan_id,
6071 										   p_appraisal_period_id      => g_plan_aprsl_pds_tbl (l_plan_aprsl_pds_index).appraisal_period_id,
6072 										   p_log_output               => p_log_output
6073 										  );
6074 					  END IF;                                                                   -- run only if process date >= sysdate
6075 				   END IF;
6076 
6077 				   --
6078 				   l_plan_aprsl_pds_index := g_plan_aprsl_pds_tbl.NEXT (l_plan_aprsl_pds_index);
6079 				--
6080 				END LOOP;
6081 
6082 				-- populate the hierarchy for appraisal summary
6083 				per_wpm_summary_pkg.populate_plan_hierarchy (p_plan_id => p_plan_id, p_effective_date => TRUNC (SYSDATE));
6084 			 --
6085 			 END IF;                                                                                          --include appraisal flag
6086 		  --
6087 		  END IF;
6088 
6089 		  --
6090 		  -- Error logging
6091 		  --
6092 		  l_message_count := per_accrual_message_pkg.count_messages;
6093 
6094 		  FOR j IN 1 .. l_message_count
6095 		  LOOP
6096 			 l_message := per_accrual_message_pkg.GET_MESSAGE (j);
6097 
6098 			 IF g_dbg
6099 			 THEN
6100 				op (l_message, g_regular_log);
6101 			 END IF;
6102 		  END LOOP;
6103 
6104 		  --
6105 		  IF g_dbg
6106 		  THEN
6107 			 op ('Max Errors Allowed is: ' || TO_CHAR (g_max_errors), g_regular_log, 988);
6108 			 op ('Errors encountered is: ' || TO_CHAR (g_num_errors), g_regular_log, 989);
6109 			 op ('Leaving: ' || l_proc, g_regular_log, 990);
6110 		  END IF;
6111 	   --
6112 	   EXCEPTION
6113 		  WHEN OTHERS
6114 		  THEN
6115 			 IF g_dbg
6116 			 THEN
6117 				op ('Leaving:' || l_proc, g_regular_log, 90);
6118 			 END IF;
6119 
6120 			 --
6121 			 fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
6122 			 g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
6123 			 g_retcode := error;
6124 			 g_errbuf := g_cp_error_txt;
6125 			 g_num_errors := g_num_errors + 1;
6126 
6127 			 IF g_dbg
6128 			 THEN
6129 				op ('Max Errors Allowed is: ' || TO_CHAR (g_max_errors), g_regular_log);
6130 				op ('Errors encountered is: ' || TO_CHAR (g_num_errors), g_regular_log);
6131 				op (g_error_txt, g_regular_log);
6132 				op (SQLERRM, g_regular_log);
6133 			 END IF;
6134 
6135 			 --
6136 			 -- Send notification to administrator that plan publish errored
6137 			 --
6138 			 send_fyi_admin (p_plan_rec => l_plan_rec, p_status => 'ERROR', p_request_id => fnd_global.conc_request_id);
6139 
6140 			 IF g_dbg
6141 			 THEN
6142 				op ('Leaving:' || l_proc, g_regular_log, 91);
6143 			 END IF;
6144 
6145 			 --
6146 			 RAISE;
6147 	   END publish_plan;
6148 
6149 	--
6150 	-- ----------------------------------------------------------------------------
6151 	-- |----------------------------< send_fyi_ntf >------------------------------|
6152 	-- ----------------------------------------------------------------------------
6153 	--
6154 	   PROCEDURE send_fyi_ntf (
6155 		  itemtype    IN              VARCHAR2,
6156 		  itemkey     IN              VARCHAR2,
6157 		  actid       IN              NUMBER,
6158 		  funcmode    IN              VARCHAR2,
6159 		  resultout   OUT NOCOPY      VARCHAR2
6160 	   )
6161 	   IS
6162 		  prole                wf_users.NAME%TYPE;                                                                    -- Fix 3210283.
6163 		  l_role_name          wf_roles.NAME%TYPE;
6164 		  expand_role          VARCHAR2 (1);
6165 		  l_msg                VARCHAR2 (30);
6166 		  -- Start changes for bug#5903006
6167 		  l_obj_setting_flag   VARCHAR2 (30);
6168 	  --end changes for bug#5903006
6169 	--
6170 	   BEGIN
6171 		  IF (funcmode <> wf_engine.eng_run)
6172 		  THEN
6173 			 resultout := wf_engine.eng_null;
6174 			 RETURN;
6175 		  END IF;
6176 
6177 		  l_role_name := wf_engine.getitemattrtext (itemtype => itemtype, itemkey => itemkey, aname => 'WPM_PLAN_MEMBER');
6178 		  l_msg := UPPER (wf_engine.getactivityattrtext (itemtype, itemkey, actid, 'MESSAGE_NAME'));
6179 		  -- Start Changes for bug#5903006
6180 		  l_obj_setting_flag :=
6181 							  wf_engine.getitemattrtext (itemtype      => itemtype, itemkey => itemkey,
6182 														 aname         => 'HR_WPM_OBJ_SETTING_FLAG');
6183 
6184 		  IF NVL (l_obj_setting_flag, 'N') = 'N'
6185 		  THEN
6186 			 IF l_msg = 'WPM_PLAN_PUB_ALL_POP_MSG'
6187 			 THEN
6188 				l_msg := 'WPM_PLAN_PUB_ALL_NO_OBJ_MSG';
6189 			 ELSIF l_msg = 'WPM_PLAN_PUB_NON_TOP_POP_MSG'
6190 			 THEN
6191 				l_msg := 'WPM_PLAN_PUB_NON_TOP_NOOBJ_MSG';
6192 			 ELSIF l_msg = 'WPM_PLAN_PUB_TOP_POP_MSG'
6193 			 THEN
6194 				l_msg := 'WPM_PLAN_PUB_TOP_NO_OBJ_MSG';
6195 			 END IF;
6196 		  END IF;
6197 
6198 		  -- End Changes for bug#5903006
6199 		  expand_role := 'N';
6200 
6201 		  IF l_role_name IS NULL
6202 		  THEN
6203 			 wf_core.token ('TYPE', itemtype);
6204 			 wf_core.token ('ACTID', TO_CHAR (actid));
6205 			 wf_core.RAISE ('WFENG_NOTIFICATION_PERFORMER');
6206 		  END IF;
6207 
6208 		  --
6209 		  wf_engine_util.notification_send (itemtype, itemkey, actid, l_msg, 'HRWPM', l_role_name, expand_role, resultout);
6210 	   EXCEPTION
6211 		  WHEN OTHERS
6212 		  THEN
6213 			 RAISE;
6214 	   END send_fyi_ntf;
6215 
6216 	--
6217 	-- ----------------------------------------------------------------------------
6218 	-- |----------------------------< send_fyi_ntf_admin >------------------------|
6219 	-- ----------------------------------------------------------------------------
6220 	--
6221 	   PROCEDURE send_fyi_ntf_admin (
6222 		  itemtype    IN              VARCHAR2,
6223 		  itemkey     IN              VARCHAR2,
6224 		  actid       IN              NUMBER,
6225 		  funcmode    IN              VARCHAR2,
6226 		  resultout   OUT NOCOPY      VARCHAR2
6227 	   )
6228 	   IS
6229 		  prole                wf_users.NAME%TYPE;
6230 		  l_role_name          wf_roles.NAME%TYPE;
6231 		  l_role_displayname   wf_roles.display_name%TYPE;
6232 		  expand_role          VARCHAR2 (1);
6233 		  l_msg                VARCHAR2 (30);
6234 		  l_plan_id            NUMBER;
6235 
6236 		  CURSOR csr_get_admin
6237 		  IS
6238 			 SELECT administrator_person_id, supervisor_id
6239 			   FROM per_perf_mgmt_plans
6240 			  WHERE plan_id = l_plan_id;
6241 
6242 		  l_admin_person_id    NUMBER;
6243 		  l_supervisor_id      NUMBER;
6244 	--
6245 	   BEGIN
6246 		  IF (funcmode <> wf_engine.eng_run)
6247 		  THEN
6248 			 resultout := wf_engine.eng_null;
6249 			 RETURN;
6250 		  END IF;
6251 
6252 		  --
6253 		  -- get plan id
6254 		  --
6255 		  l_plan_id := wf_engine.getitemattrnumber (itemtype => itemtype, itemkey => itemkey, aname => 'WPM_PLAN_ID');
6256 
6257 		  --
6258 		  -- get administrator person id from plan
6259 		  --
6260 		  OPEN csr_get_admin;
6261 
6262 		  FETCH csr_get_admin
6263 		   INTO l_admin_person_id, l_supervisor_id;
6264 
6265 		  CLOSE csr_get_admin;
6266 
6267 		  --
6268 		  -- Continue only if supervisor id is different from admin person id
6269 		  --
6270 		  IF l_admin_person_id <> NVL (l_supervisor_id, -1)
6271 		  THEN
6272 			 -- Get the Role for the Owner
6273 			 wf_directory.getrolename (p_orig_system         => 'PER',
6274 									   p_orig_system_id      => l_admin_person_id,
6275 									   p_name                => l_role_name,
6276 									   p_display_name        => l_role_displayname
6277 									  );
6278 	/*
6279 	  l_role_name :=wf_engine.GetItemAttrText(
6280 						itemtype => itemtype,
6281 						itemkey  => itemkey,
6282 						aname    => 'WPM_PLAN_MEMBER');
6283 	  */
6284 			 l_msg := UPPER (wf_engine.getactivityattrtext (itemtype, itemkey, actid, 'MESSAGE_NAME'));
6285 			 expand_role := 'N';
6286 
6287 			 IF l_role_name IS NULL
6288 			 THEN
6289 				wf_core.token ('TYPE', itemtype);
6290 				wf_core.token ('ACTID', TO_CHAR (actid));
6291 				wf_core.RAISE ('WFENG_NOTIFICATION_PERFORMER');
6292 			 END IF;
6293 
6294 			 --
6295 			 wf_engine_util.notification_send (itemtype, itemkey, actid, l_msg, 'HRWPM', l_role_name, expand_role, resultout);
6296 		  END IF;                                                                                         --l_admin <> l_supervisor_id
6297 	   EXCEPTION
6298 		  WHEN OTHERS
6299 		  THEN
6300 			 RAISE;
6301 	   END send_fyi_ntf_admin;
6302 
6303 	--
6304 	-- ----------------------------------------------------------------------------
6305 	-- |------------------------------< send_fyi_admin >--------------------------|
6306 	-- ----------------------------------------------------------------------------
6307 	--
6308 	   PROCEDURE send_fyi_admin (p_plan_rec IN per_perf_mgmt_plans%ROWTYPE, p_status IN VARCHAR2, p_request_id IN NUMBER)
6309 	   IS
6310 		  l_to_role_name            wf_roles.NAME%TYPE;
6311 		  l_to_role_displayname     wf_roles.display_name%TYPE;
6312 		  l_from_role_name          wf_roles.NAME%TYPE;
6313 		  l_from_role_displayname   wf_roles.display_name%TYPE;
6314 		  expand_role               VARCHAR2 (1);
6315 		  l_msg                     VARCHAR2 (30);
6316 		  l_notification_id         NUMBER;
6317 		  from_role_not_exists      EXCEPTION;
6318 		  to_role_not_exists        EXCEPTION;
6319 		  l_subject                 VARCHAR2 (200)               DEFAULT NULL;
6320 		  l_proc                    VARCHAR2 (72)                := g_package || 'send_fyi_admin';
6321 	--
6322 	   BEGIN
6323 		  IF g_dbg
6324 		  THEN
6325 			 op (l_proc, g_regular_log, 10);
6326 		  END IF;
6327 
6328 		  --
6329 
6330 		  -- Get the Role for the Owner
6331 		  wf_directory.getrolename (p_orig_system         => 'PER',
6332 									p_orig_system_id      => p_plan_rec.administrator_person_id,
6333 									p_name                => l_to_role_name,
6334 									p_display_name        => l_to_role_displayname
6335 								   );
6336 
6337 		  IF g_dbg
6338 		  THEN
6339 			 op (l_proc, g_debug_log, 20);
6340 		  END IF;
6341 
6342 		  --
6343 		  IF l_to_role_name IS NULL
6344 		  THEN
6345 			 IF g_dbg
6346 			 THEN
6347 				op (l_proc, g_debug_log, 25);
6348 			 END IF;
6349 
6350 			 RAISE to_role_not_exists;
6351 		  END IF;
6352 
6353 		  /* Owner is always administrator, we don;t need to check for the from role
6354 			-- ---------------------------------
6355 			-- Get the Role for the Owner
6356 			-- ---------------------------------
6357 			--
6358 			wf_directory.getRoleName
6359 			  (p_orig_system    => 'FND_USR'
6360 			  ,p_orig_system_id => fnd_global.user_id
6361 			  ,p_name           => l_from_role_name
6362 			  ,p_display_name   => l_from_role_displayname);
6363 			  --
6364 			IF g_dbg THEN op(l_proc, g_DEBUG_LOG, 30); END IF;
6365 			if l_from_role_name is null then
6366 			  IF g_dbg THEN op(l_proc, g_DEBUG_LOG, 45); END IF;
6367 			  raise from_role_not_exists;
6368 			end if;
6369 		  */
6370 		  expand_role := 'N';
6371 
6372 		  --
6373 		  IF g_dbg
6374 		  THEN
6375 			 op (l_proc, g_debug_log, 50);
6376 		  END IF;
6377 
6378 		  IF p_status = 'PUBLISHED'
6379 		  THEN
6380 			 l_notification_id :=
6381 				wf_notification.send (ROLE              => l_to_role_name,
6382 									  msg_type          => 'HRWPM',
6383 									  msg_name          => 'WPM_PLAN_PUB_ADMIN_MSG',
6384 									  callback          => NULL,
6385 									  CONTEXT           => NULL,
6386 									  send_comment      => NULL,
6387 									  priority          => 50
6388 									 );
6389 			 wf_notification.setattrtext (l_notification_id, 'PUB_PLAN_NAME', p_plan_rec.plan_name);
6390 			 wf_notification.setattrnumber (l_notification_id, 'PUB_REQ_ID', p_request_id);
6391 		  ELSIF p_status = 'ERROR'
6392 		  THEN
6393 			 IF g_dbg
6394 			 THEN
6395 				op (l_proc, g_debug_log, 51);
6396 			 END IF;
6397 
6398 			 l_notification_id :=
6399 				wf_notification.send (ROLE              => l_to_role_name,
6400 									  msg_type          => 'HRWPM',
6401 									  msg_name          => 'WPM_PLANPUB_ERROR_ADMIN_MSG',
6402 									  callback          => NULL,
6403 									  CONTEXT           => NULL,
6404 									  send_comment      => NULL,
6405 									  priority          => 50
6406 									 );
6407 			 wf_notification.setattrtext (l_notification_id, 'FAILED_PLAN_NAME', p_plan_rec.plan_name);
6408 			 wf_notification.setattrnumber (l_notification_id, 'FAILED_REQ_ID', p_request_id);
6409 
6410 			 IF g_dbg
6411 			 THEN
6412 				op (l_proc, g_debug_log, 52);
6413 			 END IF;
6414 		  ELSIF p_status = 'SUBMITTED'
6415 		  THEN
6416 			 IF g_dbg
6417 			 THEN
6418 				op (l_proc, g_debug_log, 52);
6419 			 END IF;
6420 
6421 			 l_notification_id :=
6422 				wf_notification.send (ROLE              => l_to_role_name,
6423 									  msg_type          => 'HRWPM',
6424 									  msg_name          => 'WPM_PLAN_SUBMIT_ADMIN_MSG',
6425 									  callback          => NULL,
6426 									  CONTEXT           => NULL,
6427 									  send_comment      => NULL,
6428 									  priority          => 50
6429 									 );
6430 			 wf_notification.setattrtext (l_notification_id, 'SUBMIT_PLAN_NAME', p_plan_rec.plan_name);
6431 			 wf_notification.setattrnumber (l_notification_id, 'SUBMIT_REQ_ID', p_request_id);
6432 		  ELSIF p_status = 'ROLLBACK'
6433 		  THEN
6434 			 IF g_dbg
6435 			 THEN
6436 				op (l_proc, g_debug_log, 54);
6437 			 END IF;
6438 
6439 			 hr_utility.set_location (' wf_notification.send:', 51);
6440 			 l_notification_id :=
6441 				wf_notification.send (ROLE              => l_to_role_name,
6442 									  msg_type          => 'HRWPM',
6443 									  msg_name          => 'WPM_PLAN_ROLLB_ADMIN_MSG',
6444 									  callback          => NULL,
6445 									  CONTEXT           => NULL,
6446 									  send_comment      => NULL,
6447 									  priority          => 50
6448 									 );
6449 			 wf_notification.setattrtext (l_notification_id, 'ROLLB_PLAN_NAME', p_plan_rec.plan_name);
6450 			 wf_notification.setattrnumber (l_notification_id, 'ROLLB_REQ_ID', p_request_id);
6451 		  ELSE
6452 			 IF g_dbg
6453 			 THEN
6454 				op (l_proc, g_debug_log, 53);
6455 			 END IF;
6456 
6457 			 NULL;
6458 		  END IF;
6459 
6460 		  IF g_dbg
6461 		  THEN
6462 			 op (l_proc, g_debug_log, 60);
6463 		  END IF;
6464 
6465 		  wf_notification.setattrtext (l_notification_id, '#FROM_ROLE', l_to_role_name);
6466 		  wf_notification.setattrtext (l_notification_id, 'WPM_PLAN', p_plan_rec.plan_name);
6467 		  wf_notification.setattrtext (l_notification_id, 'PLAN_START_DATE', p_plan_rec.start_date);
6468 		  wf_notification.setattrtext (l_notification_id, 'PLAN_END_DATE', p_plan_rec.end_date);
6469 		  wf_notification.setattrnumber (l_notification_id, 'CONCREQID', p_request_id);
6470 
6471 		  IF g_dbg
6472 		  THEN
6473 			 op (l_proc, g_debug_log, 70);
6474 		  END IF;
6475 	   EXCEPTION
6476 		  WHEN OTHERS
6477 		  THEN
6478 			 IF g_dbg
6479 			 THEN
6480 				op (l_proc, g_regular_log, 100);
6481 			 END IF;
6482 
6483 			 RAISE;
6484 	   END send_fyi_admin;
6485 
6486 	--
6487 	-- ----------------------------------------------------------------------------
6488 	-- |-----------------------< copy_past_objectives >---------------------------|
6489 	-- ----------------------------------------------------------------------------
6490 	--
6491 	   PROCEDURE copy_past_objectives (
6492 		  p_effective_date      IN   DATE,
6493 		  p_business_group_id   IN   NUMBER,
6494 		  p_person_id           IN   NUMBER,
6495 		  p_scorecard_id        IN   NUMBER,
6496 		  p_start_date          IN   DATE,
6497 		  p_end_date            IN   DATE,
6498 		  p_target_date         IN   DATE DEFAULT NULL,
6499 		  p_assignemnt_id       IN   NUMBER,
6500 		  p_prev_plan_id        IN   NUMBER,
6501 		  p_curr_plan_id        IN   NUMBER
6502 	   )
6503 	   IS
6504 		  --
6505 		  -- Declare local variables
6506 		  --
6507 		  l_proc                           VARCHAR2 (72) := g_package || 'copy_past_objectives';
6508 		  l_objective_id                   NUMBER;
6509 		  l_object_version_number          NUMBER;
6510 		  l_duplicate_name_warning         BOOLEAN       := FALSE;
6511 		  l_comb_weight_over_100_warning   BOOLEAN       := FALSE;
6512 		  l_weighting_appraisal_warning    BOOLEAN       := FALSE;
6513 		  l_pc_v_act_mismatch_warning      BOOLEAN       := FALSE;
6514 		  l_quant_met_not_pc_warning       BOOLEAN       := FALSE;
6515 		  l_qual_met_not_pc_warning        BOOLEAN       := FALSE;
6516 		  --
6517 		  l_start_date                     DATE;
6518 		  l_target_date                    DATE;
6519 		  l_next_review_date               DATE;
6520 
6521 		  --
6522 		  CURSOR past_obj
6523 		  IS
6524 			 SELECT obj.*
6525 			   FROM per_objectives obj, per_personal_scorecards psc
6526 			  WHERE psc.plan_id = p_prev_plan_id
6527 				AND psc.assignment_id = p_assignemnt_id
6528 				AND psc.scorecard_id = obj.scorecard_id
6529 				AND obj.achievement_date IS NULL
6530 				AND obj.appraisal_id IS NULL
6531 				AND NOT EXISTS (
6532 					   SELECT 'X'
6533 						 FROM per_personal_scorecards psc1, per_objectives pobj1
6534 						WHERE psc1.plan_id = p_curr_plan_id
6535 						  AND psc1.assignment_id = psc.assignment_id
6536 						  AND psc1.scorecard_id = pobj1.scorecard_id
6537 						  AND pobj1.copied_from_objective_id = obj.objective_id);
6538 	   --
6539 	   BEGIN
6540 		  --
6541 		  IF g_dbg
6542 		  THEN
6543 			 op ('Entering:' || l_proc, g_regular_log, 10);
6544 		  END IF;
6545 
6546 		  --
6547 		  FOR pobj IN past_obj
6548 		  LOOP
6549 			 --
6550 			 IF g_dbg
6551 			 THEN
6552 				op (l_proc, g_debug_log, 20);
6553 			 END IF;
6554 
6555 			 --
6556 			 BEGIN
6557 				l_objective_id := NULL;
6558 				l_object_version_number := NULL;
6559 				l_duplicate_name_warning := FALSE;
6560 				l_comb_weight_over_100_warning := FALSE;
6561 				l_weighting_appraisal_warning := FALSE;
6562 				l_pc_v_act_mismatch_warning := FALSE;
6563 				l_quant_met_not_pc_warning := FALSE;
6564 				l_qual_met_not_pc_warning := FALSE;
6565 
6566 				 --
6567 				 -- Derive objective target date
6568 				 --
6569 				 --    8670717  bug fix changes
6570 				/* IF (p_target_date IS NULL OR p_target_date > p_end_date OR p_target_date < p_start_date
6571 					)
6572 				 THEN
6573 					l_target_date              := p_end_date;
6574 				 ELSE
6575 					l_target_date              := p_target_date;
6576 				 END IF;    */
6577 				IF p_target_date IS NULL
6578 				THEN
6579 				   l_target_date := pobj.target_date;
6580 				ELSE
6581 				   l_target_date := p_target_date;
6582 				END IF;
6583 
6584 				IF (l_target_date IS NULL OR l_target_date > p_end_date OR l_target_date < p_start_date)
6585 				THEN
6586 				   l_target_date := p_end_date;
6587 				-- ELSE -- l_target_date := p_target_date;
6588 				END IF;
6589 
6590 				--
6591 				--
6592 				IF (pobj.next_review_date IS NULL OR pobj.next_review_date < p_start_date OR pobj.next_review_date > p_end_date)
6593 				THEN
6594 				   l_next_review_date := NULL;
6595 				ELSE
6596 				   l_next_review_date := pobj.next_review_date;
6597 				END IF;
6598 
6599 				--
6600 				IF g_dbg
6601 				THEN
6602 				   op (l_proc, g_debug_log, 40);
6603 				END IF;
6604 
6605 				--
6606 				-- Call create_objective
6607 				--
6608 				hr_objectives_api.create_objective (p_effective_date                   => p_effective_date,
6609 													p_business_group_id                => p_business_group_id,
6610 													p_owning_person_id                 => pobj.owning_person_id,
6611 													p_scorecard_id                     => p_scorecard_id,
6612 													p_start_date                       => p_start_date,
6613 													p_appraise_flag                    => pobj.appraise_flag,
6614 													p_name                             => pobj.NAME,
6615 													p_target_date                      => l_target_date,
6616 													p_copied_from_objective_id         => pobj.objective_id,
6617 													p_complete_percent                 => pobj.complete_percent,
6618 													p_next_review_date                 => l_next_review_date,
6619 													p_group_code                       => pobj.group_code,
6620 													p_priority_code                    => pobj.priority_code,
6621 													p_weighting_percent                => pobj.weighting_percent,
6622 													p_target_value                     => pobj.target_value,
6623 													p_uom_code                         => pobj.uom_code,
6624 													p_measurement_style_code           => pobj.measurement_style_code,
6625 													p_measure_name                     => pobj.measure_name,
6626 													p_measure_type_code                => pobj.measure_type_code,
6627 													p_measure_comments                 => pobj.measure_comments,
6628 													p_detail                           => pobj.detail,
6629 													p_comments                         => pobj.comments,
6630 													p_success_criteria                 => pobj.success_criteria,
6631 													p_objective_id                     => l_objective_id,
6632 													p_object_version_number            => l_object_version_number,
6633 													p_weighting_appraisal_warning      => l_weighting_appraisal_warning,
6634 													p_weighting_over_100_warning       => l_comb_weight_over_100_warning,
6635 													--,p_duplicate_name_warning         =>  l_duplicate_name_warning
6636 													--,p_comb_weight_over_100_warning   =>  l_comb_weight_over_100_warning
6637 													--,p_pc_v_act_mismatch_warning      =>  l_pc_v_act_mismatch_warning
6638 													--,p_quant_met_not_pc_warning       =>  l_quant_met_not_pc_warning
6639 													--,p_qual_met_not_pc_warning        =>  l_qual_met_not_pc_warning
6640 
6641 													--9450977
6642 													p_attribute1                       => pobj.attribute1,
6643 													p_attribute2                       => pobj.attribute2,
6644 													p_attribute3                       => pobj.attribute3,
6645 													p_attribute4                       => pobj.attribute4,
6646 													p_attribute5                       => pobj.attribute5,
6647 													p_attribute6                       => pobj.attribute6,
6648 													p_attribute7                       => pobj.attribute7,
6649 													p_attribute8                       => pobj.attribute8,
6650 													p_attribute9                       => pobj.attribute9,
6651 													p_attribute10                      => pobj.attribute10,
6652 													p_attribute11                      => pobj.attribute11,
6653 													p_attribute12                      => pobj.attribute12,
6654 													p_attribute13                      => pobj.attribute13,
6655 													p_attribute14                      => pobj.attribute14,
6656 													p_attribute15                      => pobj.attribute15,
6657 													p_attribute16                      => pobj.attribute16,
6658 													p_attribute17                      => pobj.attribute17,
6659 													p_attribute18                      => pobj.attribute18,
6660 													p_attribute19                      => pobj.attribute19,
6661 													p_attribute20                      => pobj.attribute20,
6662 													p_attribute21                      => pobj.attribute21,
6663 													p_attribute22                      => pobj.attribute22,
6664 													p_attribute23                      => pobj.attribute23,
6665 													p_attribute24                      => pobj.attribute24,
6666 													p_attribute25                      => pobj.attribute25,
6667 													p_attribute26                      => pobj.attribute26,
6668 													p_attribute27                      => pobj.attribute27,
6669 													p_attribute28                      => pobj.attribute28,
6670 													p_attribute29                      => pobj.attribute29,
6671 													p_attribute30                      => pobj.attribute30
6672 												   );
6673 
6674 				--
6675 				IF g_dbg
6676 				THEN
6677 				   op (l_proc, g_regular_log, 50);
6678 				END IF;
6679 			   --
6680 			 --
6681 			 EXCEPTION
6682 				WHEN OTHERS
6683 				THEN
6684 				   IF g_dbg
6685 				   THEN
6686 					  op ('Leaving Inner:' || l_proc, g_regular_log, 90);
6687 				   END IF;
6688 
6689 				   --
6690 				   fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
6691 				   g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
6692 				   g_retcode := warning;
6693 				   g_errbuf := g_cp_error_txt;
6694 				   g_num_errors := g_num_errors + 1;
6695 
6696 				   IF g_dbg
6697 				   THEN
6698 					  op (g_error_txt, g_regular_log);
6699 				   END IF;
6700 
6701 				   IF g_dbg
6702 				   THEN
6703 					  op (SQLERRM, g_regular_log);
6704 				   END IF;
6705 
6706 				   --
6707 				   -- If the max number of errors has been exceeded, raise the error and
6708 				   -- terminate processing of this plan.
6709 				   --
6710 				   IF g_num_errors > g_max_errors
6711 				   THEN
6712 					  fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
6713 					  g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
6714 					  g_retcode := error;
6715 					  g_errbuf := g_error_txt;
6716 					  RAISE;
6717 				   END IF;
6718 			 END;
6719 		  END LOOP;
6720 
6721 		  --
6722 		  IF g_dbg
6723 		  THEN
6724 			 op ('Leaving:' || l_proc, g_debug_log, 190);
6725 		  END IF;
6726 	   --
6727 	   EXCEPTION
6728 		  WHEN OTHERS
6729 		  THEN
6730 			 IF g_dbg
6731 			 THEN
6732 				op ('Leaving Outer:' || l_proc, g_regular_log, 200);
6733 			 END IF;
6734 
6735 			 --
6736 			 fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
6737 			 g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
6738 			 g_retcode := warning;
6739 			 g_errbuf := g_cp_error_txt;
6740 			 g_num_errors := g_num_errors + 1;
6741 
6742 			 IF g_dbg
6743 			 THEN
6744 				op (g_error_txt, g_regular_log);
6745 			 END IF;
6746 
6747 			 IF g_dbg
6748 			 THEN
6749 				op (SQLERRM, g_regular_log);
6750 			 END IF;
6751 
6752 			 --
6753 			 -- If the max number of errors has been exceeded, raise the error and
6754 			 -- terminate processing of this plan.
6755 			 --
6756 			 IF g_num_errors > g_max_errors
6757 			 THEN
6758 				fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
6759 				g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
6760 				g_retcode := error;
6761 				g_errbuf := g_error_txt;
6762 				RAISE;
6763 			 END IF;
6764 	   --
6765 	   END copy_past_objectives;
6766 
6767 	----------------------------------------------------------------------------------
6768 	-----------------< is_supervisor_in_org >-----------------------------------------
6769 	----------------------------------------------------------------------------------
6770 	-- changed by schowdhu for bug 8740114 30-JUL-09
6771 	   FUNCTION is_supervisor_in_org (p_top_organization_id IN NUMBER, p_person_id IN NUMBER)
6772 		  RETURN NUMBER
6773 	   IS
6774 		  --- Declare cursors and local variables
6775 		  ---- cursor to get the organisation of the person.
6776 		  CURSOR csr_get_org (p_person_id IN NUMBER)
6777 		  IS
6778 			 SELECT paa.organization_id
6779 			   FROM per_all_assignments_f paa
6780 			  WHERE (TRUNC (SYSDATE) BETWEEN paa.effective_start_date AND paa.effective_end_date)
6781 				AND paa.person_id = p_person_id
6782 				AND paa.primary_flag = 'Y';
6783 
6784 		  --- cursor variable
6785 		  get_per_org   csr_get_org%ROWTYPE;
6786 	   BEGIN
6787 		  ------- get the supervisor id of the person
6788 		  OPEN csr_get_org (p_person_id);
6789 
6790 		  FETCH csr_get_org
6791 		   INTO get_per_org;
6792 
6793 		  CLOSE csr_get_org;
6794 
6795 		  IF (get_per_org.organization_id <> p_top_organization_id)
6796 		  THEN
6797 			 RETURN 0;
6798 		  ELSE
6799 			 RETURN 1;
6800 		  END IF;
6801 	   END;
6802 
6803 	---------------------------------------------------------------------------------------
6804 	-----------------< change_plan_active_status >-----------------------------------------
6805 	---------------------------------------------------------------------------------------
6806 	   PROCEDURE change_plan_active_status (p_plan_id IN NUMBER)
6807 	   IS
6808 		  l_status_code   per_perf_mgmt_plans.status_code%TYPE;
6809 	   BEGIN
6810 		  SELECT status_code
6811 			INTO l_status_code
6812 			FROM per_perf_mgmt_plans
6813 		   WHERE plan_id = p_plan_id;
6814 
6815 	--- this is the logic for dectivating a published plan .
6816 		  IF (l_status_code = 'PUBLISHED')
6817 		  THEN
6818 			 UPDATE per_perf_mgmt_plans
6819 				SET status_code = 'INACTIVE'
6820 			  WHERE plan_id = p_plan_id;
6821 
6822 			 COMMIT;
6823 	--- logic for status code updated to published if already inactive
6824 		  ELSIF (l_status_code = 'INACTIVE')
6825 		  THEN
6826 			 UPDATE per_perf_mgmt_plans
6827 				SET status_code = 'PUBLISHED'
6828 			  WHERE plan_id = p_plan_id;
6829 
6830 			 COMMIT;
6831 	-- UI allows only published plan and Inactivate plan to access this function through the functional button.
6832 	-- if any other call is made it will not do anything.
6833 		  END IF;
6834 	   END;
6835 
6836 	--
6837 	--
6838 	--
6839 	   PROCEDURE report_plan_summary (p_plan_id IN NUMBER, p_sc_summary IN VARCHAR2, p_appraisal_summary IN VARCHAR2)
6840 	   IS
6841 		  CURSOR csr_sc_summary (p_plan_id IN NUMBER)
6842 		  IS
6843 			 SELECT   hr_general.decode_lookup ('HR_WPM_SCORECARD_STATUS', status_code) status, COUNT (*) COUNT
6844 				 FROM per_personal_scorecards
6845 				WHERE plan_id = p_plan_id
6846 			 GROUP BY hr_general.decode_lookup ('HR_WPM_SCORECARD_STATUS', status_code)
6847 			 ORDER BY hr_general.decode_lookup ('HR_WPM_SCORECARD_STATUS', status_code);
6848 
6849 	--
6850 		  CURSOR csr_appraisal_summary (p_plan_id IN NUMBER)
6851 		  IS
6852 			 SELECT   hr_general.decode_lookup ('APPRAISAL_SYSTEM_STATUS', appraisal_system_status) status,
6853 					  pat.NAME appraisal_template_name, pa.appraisal_period_start_date, pa.appraisal_period_end_date, COUNT (*)
6854 																															   COUNT
6855 				 FROM per_appraisals pa, per_appraisal_templates pat
6856 				WHERE pa.plan_id = p_plan_id AND pa.appraisal_template_id = pat.appraisal_template_id
6857 			 GROUP BY hr_general.decode_lookup ('APPRAISAL_SYSTEM_STATUS', appraisal_system_status),
6858 					  pat.NAME,
6859 					  pa.appraisal_period_start_date,
6860 					  pa.appraisal_period_end_date
6861 			 ORDER BY hr_general.decode_lookup ('APPRAISAL_SYSTEM_STATUS', appraisal_system_status),
6862 					  pat.NAME,
6863 					  pa.appraisal_period_start_date,
6864 					  pa.appraisal_period_end_date;
6865 	   BEGIN
6866 		  IF p_sc_summary = 'Y'
6867 		  THEN
6868 			 log_message ('Score card summary by status:');
6869 			 log_message ('------------------------------------------------------------');
6870 			 log_message ('Status                                               Count
6871 	'        );
6872 			 log_message ('------------------------------------------------------------');
6873 
6874 			 FOR i IN csr_sc_summary (p_plan_id)
6875 			 LOOP
6876 				log_message (i.status || '                     ' || i.COUNT);
6877 			 END LOOP;
6878 
6879 			 log_message ('------------------------------------------------------------');
6880 		  END IF;
6881 
6882 		  IF p_appraisal_summary = 'Y'
6883 		  THEN
6884 			 log_message ('Appraisal summary by status:');
6885 			 log_message ('------------------------------------------------------------------------');
6886 			 log_message ('Template Name           Start Date   End Date   Status
6887 	Count  ' );
6888 			 log_message ('------------------------------------------------------------------------');
6889 
6890 			 FOR i IN csr_appraisal_summary (p_plan_id)
6891 			 LOOP
6892 				log_message (   i.appraisal_template_name
6893 							 || '   '
6894 							 || TO_CHAR (i.appraisal_period_start_date, 'DD/MM/YYYY')
6895 							 || '   '
6896 							 || TO_CHAR (i.appraisal_period_end_date, 'DD/MM/YYYY')
6897 							 || i.status
6898 							 || i.COUNT
6899 							);
6900 			 END LOOP;
6901 
6902 			 log_message ('------------------------------------------------------------------------');
6903 		  END IF;
6904 	   ---
6905 	   END report_plan_summary;
6906 
6907 	--
6908 	--
6909 	   PROCEDURE delete_scorecards (p_plan_id IN NUMBER)
6910 	   IS
6911 		  CURSOR csr_sc_ids (p_plan_id IN NUMBER)
6912 		  IS
6913 			 SELECT scorecard_id
6914 			   FROM per_personal_scorecards
6915 			  WHERE plan_id = p_plan_id;
6916 
6917 		  TYPE t_sc_ids IS TABLE OF NUMBER
6918 			 INDEX BY BINARY_INTEGER;
6919 
6920 		  l_sc_ids   t_sc_ids;
6921 	   BEGIN
6922 	--
6923 		  log_message ('Deleting Score cards for the plan');
6924 
6925 		  OPEN csr_sc_ids (p_plan_id);
6926 
6927 		  LOOP
6928 			 FETCH csr_sc_ids
6929 			 BULK COLLECT INTO l_sc_ids LIMIT 1000;
6930 
6931 			 --Delete any transactions from HR_API_Transactions and transaction steps
6932 			 FORALL i IN l_sc_ids.FIRST .. l_sc_ids.LAST
6933 				DELETE FROM hr_api_transaction_steps step
6934 					  WHERE step.transaction_id IN (
6935 								 SELECT trn.transaction_id
6936 								   FROM hr_api_transactions trn
6937 								  WHERE trn.transaction_ref_id = l_sc_ids (i)
6938 									AND trn.transaction_ref_table = 'PER_PERSONAL_SCORECARDS');
6939 			 FORALL i IN l_sc_ids.FIRST .. l_sc_ids.LAST
6940 				DELETE FROM hr_api_transactions
6941 					  WHERE transaction_ref_id = l_sc_ids (i) AND transaction_ref_table = 'PER_PERSONAL_SCORECARDS';
6942 			 -- Delete all score card objectives
6943 			 FORALL i IN l_sc_ids.FIRST .. l_sc_ids.LAST
6944 				DELETE FROM per_objectives
6945 					  WHERE scorecard_id = l_sc_ids (i);
6946 			 -- Delete all score cards now
6947 			 FORALL i IN l_sc_ids.FIRST .. l_sc_ids.LAST
6948 				DELETE FROM per_personal_scorecards
6949 					  WHERE scorecard_id = l_sc_ids (i);
6950 			 EXIT WHEN csr_sc_ids%NOTFOUND;
6951 		  END LOOP;
6952 
6953 		  CLOSE csr_sc_ids;
6954 
6955 		  log_message ('Score cards deleted successfully for the plan');
6956 	--
6957 	   EXCEPTION
6958 		  WHEN OTHERS
6959 		  THEN
6960 			 log_message ('Error while deleting score cards');
6961 			 log_message (SQLERRM);
6962 			 RAISE;
6963 	   END delete_scorecards;
6964 
6965 	--
6966 	--
6967 	--
6968 	   PROCEDURE delete_appraisals (p_plan_id IN NUMBER)
6969 	   IS
6970 		  CURSOR csr_appr (p_plan_id IN NUMBER)
6971 		  IS
6972 			 SELECT appraisal_id, object_version_number
6973 			   FROM per_appraisals
6974 			  WHERE plan_id = p_plan_id;
6975 	   BEGIN
6976 		  log_message ('Deleting Appraisals for the plan');
6977 
6978 		  FOR i IN csr_appr (p_plan_id)
6979 		  LOOP
6980 			 -- hr_appraisals_api.delete_appraisal
6981 			 delete_appraisal_for_person (p_appraisal_id => i.appraisal_id, p_object_version_number => i.object_version_number);
6982 		  END LOOP;
6983 
6984 		  log_message ('Appraisals deleted successfully for the plan');
6985 	   EXCEPTION
6986 		  WHEN OTHERS
6987 		  THEN
6988 			 log_message ('Error while deleting appraisals');
6989 			 log_message (SQLERRM);
6990 			 RAISE;
6991 	   END delete_appraisals;
6992 
6993 	--
6994 	--
6995 	   FUNCTION backout_perf_mgmt_plan_cp (p_effective_date IN DATE, p_plan_id IN NUMBER, p_report_only IN VARCHAR2 DEFAULT 'Y')
6996 		  RETURN NUMBER
6997 	   IS
6998 		  l_request_id   NUMBER;
6999 		  l_proc         VARCHAR2 (72) := g_package || 'backout_perf_mgmt_plan_cp';
7000 	   BEGIN
7001 		  hr_utility.set_location ('Entering ' || l_proc, 10);
7002 
7003 		  IF p_plan_id IS NULL
7004 		  THEN
7005 			 hr_api.mandatory_arg_error (p_api_name            => 'BACKOUT_PERF_MGMT_PLAN_CP',
7006 										 p_argument            => 'P_PLAN_ID',
7007 										 p_argument_value      => p_plan_id
7008 										);
7009 		  END IF;
7010 
7011 		  IF p_effective_date IS NULL
7012 		  THEN
7013 			 hr_api.mandatory_arg_error (p_api_name            => 'BACKOUT_PERF_MGMT_PLAN_CP',
7014 										 p_argument            => 'P_EFFECTIVE_DATE',
7015 										 p_argument_value      => p_effective_date
7016 										);
7017 		  END IF;
7018 
7019 		  l_request_id :=
7020 			 fnd_request.submit_request (application      => 'PER',
7021 										 program          => 'PERWPMBKOUT',
7022 										 sub_request      => FALSE,
7023 										 argument1        => fnd_date.date_to_canonical (p_effective_date),
7024 										 argument2        => p_plan_id,
7025 										 argument3        => p_report_only
7026 										);
7027 		  COMMIT;
7028 		  log_message ('Request id: ' || l_request_id);
7029 		  hr_utility.set_location ('Leaving ' || l_proc, 20);
7030 		  RETURN l_request_id;
7031 	   EXCEPTION
7032 		  WHEN OTHERS
7033 		  THEN
7034 			 hr_utility.set_location ('Error submitting the request.' || l_proc, 30);
7035 			 RETURN -1;
7036 			 RAISE;
7037 	   END backout_perf_mgmt_plan_cp;
7038 
7039 	-- ----------------------------------------------------------------------------
7040 	-- |----------------------------< backout_perf_mgmt_plan>----------------------|
7041 	-- ----------------------------------------------------------------------------
7042 	   PROCEDURE backout_perf_mgmt_plan (
7043 		  errbuf             OUT NOCOPY      VARCHAR2,
7044 		  retcode            OUT NOCOPY      NUMBER,
7045 		  p_effective_date   IN              VARCHAR2,
7046 		  p_plan_id          IN              NUMBER,
7047 		  p_report_only      IN              VARCHAR2 DEFAULT 'Y'
7048 	   )
7049 	   IS
7050 		  l_proc                    VARCHAR2 (72)                          := g_package || 'backout_perf_mgmt_plan';
7051 
7052 		  CURSOR csr_valid_plan (p_plan_id IN NUMBER)
7053 		  IS
7054 			 SELECT *
7055 			   FROM per_perf_mgmt_plans
7056 			  WHERE plan_id = p_plan_id;
7057 
7058 		  l_plan_rec                csr_valid_plan%ROWTYPE;
7059 
7060 	--sussuman 13657400
7061 		  CURSOR csr_sc_exists (p_plan_id IN NUMBER)
7062 		  IS
7063 			 SELECT 'Y'
7064 			   FROM DUAL
7065 			  WHERE EXISTS (SELECT NULL
7066 							  FROM per_personal_scorecards
7067 							 WHERE plan_id = p_plan_id);
7068 
7069 		  l_sc_rec                  VARCHAR2 (1);
7070 
7071 	--cursor created for bug 13657400
7072 
7073 		  --psugumar 7294077
7074 		  CURSOR csr_person_ids (p_plan_id IN NUMBER)
7075 		  IS
7076 			 SELECT person_id
7077 			   FROM per_personal_scorecards
7078 			  WHERE plan_id = p_plan_id;
7079 
7080 		  l_plan_name               per_perf_mgmt_plans.plan_name%TYPE;
7081 
7082 		  TYPE tab_person_id IS TABLE OF per_appraisals.appraisee_person_id%TYPE
7083 			 INDEX BY BINARY_INTEGER;
7084 
7085 		  person_ids                tab_person_id;
7086 		  l_effective_date          DATE;
7087 		  l_object_version_number   NUMBER;
7088 		  l_status_code             per_perf_mgmt_plans.status_code%TYPE;
7089 		  l_dummy                   BOOLEAN;
7090 		  -- added for 13650421
7091 		  l_request_id              NUMBER;
7092 	   BEGIN
7093 		  hr_utility.set_location ('Entering:' || l_proc, 10);
7094 
7095 	--Bug7294077
7096 		  OPEN csr_person_ids (p_plan_id);
7097 
7098 		  FETCH csr_person_ids
7099 		  BULK COLLECT INTO person_ids LIMIT 1000;
7100 
7101 		  CLOSE csr_person_ids;
7102 
7103 		  IF p_plan_id IS NULL
7104 		  THEN
7105 			 hr_api.mandatory_arg_error (p_api_name            => 'BACKOUT_PERF_MGMT_PLAN',
7106 										 p_argument            => 'P_PLAN_ID',
7107 										 p_argument_value      => p_plan_id
7108 										);
7109 		  END IF;
7110 
7111 		  IF p_effective_date IS NULL
7112 		  THEN
7113 			 hr_api.mandatory_arg_error (p_api_name            => 'BACKOUT_PERF_MGMT_PLAN',
7114 										 p_argument            => 'P_EFFECTIVE_DATE',
7115 										 p_argument_value      => p_effective_date
7116 										);
7117 		  END IF;
7118 
7119 		  l_effective_date := fnd_date.canonical_to_date (p_effective_date);
7120 
7121 		  OPEN csr_valid_plan (p_plan_id);
7122 
7123 		  FETCH csr_valid_plan
7124 		   INTO l_plan_rec;
7125 
7126 		  IF csr_valid_plan%NOTFOUND
7127 		  THEN
7128 			 hr_utility.set_message (800, 'HR_50264_PMS_INVALID_PLAN');
7129 			 log_message ('Perf. Management Plan doesn''t exist.');
7130 			 hr_utility.raise_error;
7131 		  END IF;
7132 
7133 		  CLOSE csr_valid_plan;
7134 
7135 		  IF l_plan_rec.status_code IN ('DRAFT', 'INACTIVE')
7136 		  THEN
7137 			 fnd_message.set_name ('PER', 'HR_50780_WPM_INVALID_STATUS_BACKOUT');
7138 			 log_message ('This plan cannot be backed out as this is currently in
7139 	' ||                  l_plan_rec.status_code);
7140 			 fnd_message.set_token ('STATUS', l_plan_rec.status_code);
7141 			 hr_utility.raise_error;
7142 		  END IF;
7143 
7144 		  IF TRUNC (SYSDATE) > TRUNC (l_plan_rec.end_date)
7145 		  THEN
7146 			 log_message ('This plan cannot be backed out as this plan is Completed');
7147 			 hr_utility.raise_error;
7148 		  END IF;
7149 
7150 		  log_message ('Details of the Plan: ' || l_plan_rec.plan_name);
7151 		  log_message ('--------------------------------------------------------------');
7152 		  log_message ('Administrator                    :
7153 	' ||               hr_general.decode_person_name (l_plan_rec.administrator_person_id));
7154 		  log_message ('Start Date                       :
7155 	' ||               TO_CHAR (l_plan_rec.start_date, 'DD/MM/YYYY'));
7156 		  log_message ('End Date                         :
7157 	' ||               TO_CHAR (l_plan_rec.start_date, 'DD/MM/YYYY'));
7158 		  log_message (   'Status                           :
7159 	'
7160 					   || hr_general.decode_lookup ('HR_WPM_PLAN_STATUS', l_plan_rec.status_code)
7161 					  );
7162 		  log_message (   'Objective Setting Included?      :
7163 	'
7164 					   || hr_general.decode_lookup ('YES_NO', l_plan_rec.include_obj_setting_flag)
7165 					  );
7166 		  log_message (   'Appraisals Included?             :
7167 	'
7168 					   || hr_general.decode_lookup ('YES_NO', l_plan_rec.include_appraisals_flag)
7169 					  );
7170 		  log_message (   'Sharing/Align Objectives Enabled?:
7171 	'
7172 					   || hr_general.decode_lookup ('YES_NO', l_plan_rec.sharing_alignment_task_flag)
7173 					  );
7174 		  log_message (   'Appraisals Included?             :
7175 	'
7176 					   || hr_general.decode_lookup ('YES_NO', l_plan_rec.include_appraisals_flag)
7177 					  );
7178 		  log_message ('--------------------------------------------------------------');
7179 		  report_plan_summary (p_plan_id                => p_plan_id,
7180 							   p_sc_summary             => NVL (l_plan_rec.include_obj_setting_flag, 'N'),
7181 							   p_appraisal_summary      => NVL (l_plan_rec.include_appraisals_flag, 'N')
7182 							  );
7183 
7184 		  IF p_report_only = 'Y'
7185 		  THEN
7186 			 RETURN;
7187 		  END IF;
7188 
7189 	--Update the  plan status to SUBMITTED so that no further updates can happen to the plan
7190 		  l_object_version_number := l_plan_rec.object_version_number;
7191 		  l_status_code := 'SUBMITTED';
7192 		  -- added for 13650421
7193 		  l_request_id := fnd_global.conc_request_id;
7194 		  per_pmp_upd.upd (p_plan_id                     => p_plan_id,
7195 						   p_effective_date              => l_effective_date,
7196 						   p_object_version_number       => l_object_version_number,
7197 						   p_status_code                 => l_status_code,
7198 						   p_duplicate_name_warning      => l_dummy,
7199 						   p_no_life_events_warning      => l_dummy
7200 						  );
7201 		  COMMIT;
7202 
7203 	--sussuman 13657400
7204 		  OPEN csr_sc_exists (p_plan_id);
7205 
7206 		  FETCH csr_sc_exists
7207 		   INTO l_sc_rec;
7208 
7209 		  CLOSE csr_sc_exists;
7210 
7211 		  IF (l_sc_rec = 'Y')
7212 		  THEN
7213 			 delete_scorecards (p_plan_id);
7214 		  END IF;
7215 
7216 	--changes for bug 13657400
7217 		  IF NVL (l_plan_rec.include_appraisals_flag, 'N') = 'Y'
7218 		  THEN
7219 			 delete_appraisals (p_plan_id);
7220 		  END IF;
7221 
7222 		  --
7223 		  -- reset the plan status to DRAFT now
7224 		  l_status_code := 'DRAFT';
7225 		  per_pmp_upd.upd (p_plan_id                     => p_plan_id,
7226 						   p_effective_date              => l_effective_date,
7227 						   p_object_version_number       => l_object_version_number,
7228 						   p_status_code                 => l_status_code,
7229 						   p_duplicate_name_warning      => l_dummy,
7230 						   p_no_life_events_warning      => l_dummy
7231 						  );
7232 
7233 		  --remove the plan details from hierarchy table as plan is rolled back.
7234 		  DELETE      per_wpm_plan_hierarchy
7235 				WHERE plan_id = p_plan_id;
7236 
7237 		  --remove the plan details from Appraisal Summary table as plan is rolled back.
7238 		  DELETE      per_wpm_appraisal_summary
7239 				WHERE plan_id = p_plan_id;
7240 
7241 	--7294077
7242 		  IF (l_plan_rec.notify_population_flag = 'Y')
7243 		  THEN
7244 			 FOR j IN 1 .. person_ids.COUNT
7245 			 LOOP
7246 				send_message_notification (person_ids (j), 'WPM_PLAN_ROLLBACK_MSG', p_plan_id, NULL);
7247 			 END LOOP;
7248 		  END IF;
7249 
7250 		  -- Send notification to administrator that plan rolled back
7251 				  ---- added for 13650421
7252 		  send_fyi_admin (p_plan_rec => l_plan_rec, p_status => 'ROLLBACK', p_request_id => l_request_id);
7253 		  COMMIT;
7254 		  hr_utility.set_location ('Leaving:' || l_proc, 50);
7255 	   EXCEPTION
7256 		  WHEN OTHERS
7257 		  THEN
7258 			 retcode := error;
7259 			 errbuf := SQLERRM;
7260 			 ROLLBACK;
7261 			 l_status_code := 'PUBLISHED';
7262 			 per_pmp_upd.upd (p_plan_id                     => p_plan_id,
7263 							  p_effective_date              => l_effective_date,
7264 							  p_object_version_number       => l_object_version_number,
7265 							  p_status_code                 => l_status_code,
7266 							  p_duplicate_name_warning      => l_dummy,
7267 							  p_no_life_events_warning      => l_dummy
7268 							 );
7269 			 COMMIT;
7270 			 RAISE;
7271 	   END backout_perf_mgmt_plan;
7272 
7273 	--
7274 	--
7275 	   FUNCTION plan_admin_actions_cp (
7276 		  p_effective_date           IN   DATE,
7277 		  p_plan_id                  IN   NUMBER,
7278 		  p_selected_entities_list   IN   VARCHAR2,
7279 		  p_task_code                IN   VARCHAR2
7280 	   )
7281 		  RETURN NUMBER
7282 	   IS
7283 		  l_request_id   NUMBER;
7284 		  l_proc         VARCHAR2 (72) := g_package || 'plan_admin_actions_cp';
7285 	   BEGIN
7286 		  --
7287 		  hr_utility.set_location ('Entering ' || l_proc, 10);
7288 
7289 		  IF p_plan_id IS NULL
7290 		  THEN
7291 			 hr_api.mandatory_arg_error (p_api_name            => 'PLAN_ADMIN_ACTIONS_CP',
7292 										 p_argument            => 'P_PLAN_ID',
7293 										 p_argument_value      => p_plan_id
7294 										);
7295 		  END IF;
7296 
7297 		  IF p_effective_date IS NULL
7298 		  THEN
7299 			 hr_api.mandatory_arg_error (p_api_name            => 'PLAN_ADMIN_ACTIONS_CP',
7300 										 p_argument            => 'P_EFFECTIVE_DATE',
7301 										 p_argument_value      => p_effective_date
7302 										);
7303 		  END IF;
7304 
7305 		  IF p_selected_entities_list IS NULL
7306 		  THEN
7307 			 hr_api.mandatory_arg_error (p_api_name            => 'PLAN_ADMIN_ACTIONS_CP',
7308 										 p_argument            => 'P_SELECTED_ENTITIES_LIST',
7309 										 p_argument_value      => p_selected_entities_list
7310 										);
7311 		  END IF;
7312 
7313 		  IF p_task_code IS NULL
7314 		  THEN
7315 			 hr_api.mandatory_arg_error (p_api_name            => 'PLAN_ADMIN_ACTIONS_CP',
7316 										 p_argument            => 'P_TASK_CODE',
7317 										 p_argument_value      => p_task_code
7318 										);
7319 		  END IF;
7320 
7321 		  --
7322 		  l_request_id :=
7323 			 fnd_request.submit_request (application      => 'PER',
7324 										 program          => 'PERWPMADMINCP',
7325 										 sub_request      => FALSE,
7326 										 argument1        => fnd_date.date_to_canonical (p_effective_date),
7327 										 argument2        => p_plan_id,
7328 										 argument3        => p_selected_entities_list,
7329 										 argument4        => p_task_code
7330 										);
7331 		  COMMIT;
7332 		  log_message ('Request id: ' || l_request_id);
7333 		  hr_utility.set_location ('Leaving ' || l_proc, 20);
7334 		  --
7335 		  RETURN l_request_id;
7336 	   EXCEPTION
7337 		  WHEN OTHERS
7338 		  THEN
7339 			 hr_utility.set_location ('Error submitting the request.' || l_proc, 30);
7340 			 RAISE;
7341 	   END plan_admin_actions_cp;
7342 
7343 	--
7344 	--
7345 	   FUNCTION string_to_array (p_selected_entities_list IN VARCHAR2)
7346 		  RETURN NUMBER
7347 	   IS
7348 		  i            NUMBER;
7349 		  l_pos        NUMBER;
7350 		  l_sel_list   VARCHAR2 (32767);
7351 	   BEGIN
7352 		  -- Delete existing pl/sql table, if any.
7353 		  g_selected_entities.DELETE;
7354 		  l_sel_list := p_selected_entities_list;
7355 		  i := 0;
7356 		  l_pos := INSTR (l_sel_list, ',');
7357 
7358 		  LOOP
7359 			 IF l_pos <> 0
7360 			 THEN
7361 				g_selected_entities (i) := SUBSTR (l_sel_list, 1, l_pos - 1);
7362 			 ELSE
7363 				g_selected_entities (i) := l_sel_list;
7364 			 END IF;
7365 
7366 			 EXIT WHEN l_sel_list IS NULL OR l_pos = 0;
7367 			 l_sel_list := SUBSTR (l_sel_list, l_pos + 1);
7368 			 i := i + 1;
7369 			 l_pos := INSTR (l_sel_list, ',');
7370 		  END LOOP;
7371 
7372 		  RETURN g_selected_entities.COUNT;
7373 	   EXCEPTION
7374 		  WHEN OTHERS
7375 		  THEN
7376 			 RAISE;
7377 	   END string_to_array;
7378 
7379 	--
7380 	   FUNCTION chk_assignment_in_population (p_assignment_id IN NUMBER)
7381 		  RETURN VARCHAR2
7382 	   IS
7383 		  l_chk   VARCHAR2 (1)   := 'N';
7384 		  i       BINARY_INTEGER;
7385 	   BEGIN
7386 		  IF g_qual_pop_tbl.COUNT > 0
7387 		  THEN
7388 			 IF g_qual_pop_tbl.EXISTS (p_assignment_id)
7389 			 THEN
7390 				l_chk := 'Y';
7391 			 END IF;
7392 		  END IF;
7393 
7394 		  RETURN l_chk;
7395 	   EXCEPTION
7396 		  WHEN OTHERS
7397 		  THEN
7398 			 RETURN 'N';
7399 	   END chk_assignment_in_population;
7400 
7401 	--
7402 	--
7403 	   PROCEDURE enroll_a_person (
7404 		  p_plan_id          IN   NUMBER,
7405 		  p_assignment_id    IN   NUMBER,
7406 		  p_person_id        IN   NUMBER,
7407 		  p_effective_date   IN   DATE,
7408 		  p_pop_qual_objs    IN   VARCHAR2 DEFAULT 'Y',
7409 		  p_pop_apprl_prds   IN   VARCHAR2 DEFAULT 'Y',
7410 		  p_sc_status_code   IN   VARCHAR2 DEFAULT NULL,
7411 		  p_enroll_appr      IN   VARCHAR2 DEFAULT 'Y'
7412 	   )
7413 	   IS
7414 		  l_effective_date          DATE                              := p_effective_date;
7415 		  l_qual_pop_index          BINARY_INTEGER;
7416 		  l_scorecard_status_code   VARCHAR2 (40);
7417 		  l_scorecard_id            NUMBER;
7418 		  l_qual_obj_index          BINARY_INTEGER;
7419 		  l_obj_date                DATE                              := TRUNC (SYSDATE);
7420 		  l_check_elig              VARCHAR2 (1);
7421 		  l_check_period_elig       VARCHAR2 (1);
7422 		  l_plan_aprsl_pds_index    BINARY_INTEGER;
7423 		  l_appr_ret_status         VARCHAR2 (30);
7424 		  l_elig_obj_id             ben_elig_obj_f.elig_obj_id%TYPE;
7425 		  l_proc                    VARCHAR2 (72)                     := g_package || 'enroll_a_person';
7426 
7427 		  -- cursor added
7428 		  -- 23-Jun-2009 schowdhu Eligibility Profile Enhc.
7429 		  CURSOR get_elig_obj_id_for_period (p_appraisal_period_id IN per_appraisal_periods.appraisal_period_id%TYPE)
7430 		  IS
7431 			 SELECT elig.elig_obj_id
7432 			   FROM ben_elig_obj_f elig
7433 			  WHERE elig.table_name = 'PER_APPRAISAL_PERIODS'
7434 				AND elig.column_name = 'APPRAISAL_PERIOD_ID'
7435 				AND elig.COLUMN_VALUE = p_appraisal_period_id
7436 				AND TRUNC (SYSDATE) BETWEEN elig.effective_start_date AND elig.effective_end_date;
7437 	   BEGIN
7438 		  hr_utility.set_location ('Entering: ' || l_proc, 10);
7439 
7440 		  IF (g_plan_dtls (1).automatic_allocation_flag = 'Y') AND p_pop_qual_objs = 'Y'
7441 		  THEN
7442 			 populate_qual_objectives (g_plan_dtls (1).start_date, g_plan_dtls (1).end_date);
7443 		  END IF;
7444 
7445 		  IF (g_plan_dtls (1).include_appraisals_flag = 'Y') AND p_pop_apprl_prds = 'Y'
7446 		  THEN
7447 			 populate_plan_apprsl_periods (g_plan_dtls (1).plan_id);
7448 		  END IF;
7449 
7450 		  --
7451 		  -- Loop through plan population to create/update/delete scorecards, objectives and appraisal
7452 		  --
7453 		  l_qual_pop_index := p_assignment_id;
7454 		  IF g_plan_dtls (1).status_code = 'PUBLISHED'
7455 		  THEN
7456 			 ----
7457 					-- If objective setting flag is set
7458 			 IF ((g_plan_dtls (1).include_obj_setting_flag = 'Y') OR (g_plan_dtls (1).include_appraisals_flag = 'Y'))
7459 			 THEN
7460 				-- Create the scorecard for this assignment
7461 				IF g_plan_dtls (1).method_code = 'CAS'
7462 				THEN
7463 				   IF    (    g_plan_dtls (1).hierarchy_type_code = 'SUP'
7464 						  AND g_plan_dtls (1).supervisor_id = g_qual_pop_tbl (l_qual_pop_index).person_id
7465 						 )
7466 					  OR (    g_plan_dtls (1).hierarchy_type_code = 'SUP_ASG'
7467 						  AND g_plan_dtls (1).supervisor_assignment_id = g_qual_pop_tbl (l_qual_pop_index).assignment_id
7468 						 )
7469 					  OR (    g_plan_dtls (1).hierarchy_type_code IN ('POS')
7470 						  AND g_plan_dtls (1).top_position_id = g_qual_pop_tbl (l_qual_pop_index).position_id
7471 						 )
7472 					  OR (    g_plan_dtls (1).hierarchy_type_code = 'ORG'
7473 						  AND is_supervisor_in_org (g_plan_dtls (1).top_organization_id, g_qual_pop_tbl (l_qual_pop_index).person_id) =
7474 																																	 1
7475 						 )
7476 				   THEN
7477 					  l_scorecard_status_code := 'NOT_STARTED_WITH_WKR';
7478 				   ELSE
7479 					  l_scorecard_status_code := 'NOT_STARTED_WITH_MGR';
7480 				   END IF;
7481 				ELSE
7482 				   l_scorecard_status_code := 'NOT_STARTED_WITH_WKR';
7483 				END IF;
7484 
7485 				IF p_sc_status_code IS NOT NULL
7486 				THEN                                                                   --- override for status code passed.. so use it
7487 				   l_scorecard_status_code := p_sc_status_code;
7488 				END IF;
7489 
7490 				--
7491 				create_scorecard_for_person (p_effective_date      => l_effective_date,
7492 											 p_scorecard_name      => g_plan_dtls (1).plan_name,
7493 											 p_assignment_id       => g_qual_pop_tbl (l_qual_pop_index).assignment_id,
7494 											 p_start_date          => g_plan_dtls (1).start_date,
7495 											 p_end_date            => g_plan_dtls (1).end_date,
7496 											 p_plan_id             => g_plan_dtls (1).plan_id,
7497 											 p_creator_type        => 'AUTO',
7498 											 p_status_code         => l_scorecard_status_code,
7499 											 p_scorecard_id                  => l_scorecard_id,
7500 											 p_supervisor_id                 => g_qual_pop_tbl (l_qual_pop_index).supervisor_id,
7501 											 p_supervisor_assignment_id      => g_qual_pop_tbl (l_qual_pop_index).supervisor_assignment_id
7502 											);
7503 
7504 				--changes done for bug#10062408
7505 				IF l_scorecard_id IS NOT NULL
7506 				THEN
7507 				   -- Now update the plan hierarchy for this person
7508 				   g_target_sc_id := l_scorecard_id;                                        --- set the sc id for the calling routine
7509 				   per_wpm_summary_pkg.build_hierarchy_for_sc (p_plan_id => g_plan_dtls (1).plan_id, p_sc_id => l_scorecard_id);
7510 				-- added the above line to update hierarchy for this sc.
7511 				END IF;
7512 
7513 				IF (g_plan_dtls (1).automatic_allocation_flag = 'Y' AND l_scorecard_id IS NOT NULL)
7514 				THEN
7515 				   l_qual_obj_index := g_qual_obj_tbl.FIRST;
7516 
7517 				   WHILE (l_qual_obj_index IS NOT NULL)
7518 				   LOOP
7519 					  --
7520 					  -- Enclose the call to eligibility within a block, so that if for any
7521 					  -- reason the eligibility engine errors, then process can still
7522 					  -- continue by skipping the current person/assignemnt as not eligible
7523 					  --
7524 					  BEGIN
7525 						 --
7526 						 ben_env_object.init (p_business_group_id      => g_qual_pop_tbl (l_qual_pop_index).business_group_id,
7527 											  p_thread_id              => NULL,
7528 											  p_chunk_size             => NULL,
7529 											  p_threads                => NULL,
7530 											  p_max_errors             => NULL,
7531 											  p_benefit_action_id      => NULL,
7532 											  p_effective_date         => l_obj_date
7533 											 );
7534 						 --
7535 						 --
7536 						 l_check_elig :=
7537 							ben_per_asg_elig.eligible (g_qual_pop_tbl (l_qual_pop_index).person_id,
7538 													   g_qual_pop_tbl (l_qual_pop_index).assignment_id,
7539 													   g_qual_obj_tbl (l_qual_obj_index).elig_obj_id,
7540 													   l_obj_date,
7541 													   g_qual_pop_tbl (l_qual_pop_index).business_group_id,
7542 													   'Y'                                              ---KMG -- Added to Allow CWK's
7543 													  );
7544 					  EXCEPTION
7545 						 WHEN OTHERS
7546 						 THEN
7547 							NULL;
7548 					  END;
7549 
7550 					  IF (l_check_elig = 'Y')
7551 					  THEN
7552 						 -- Create the objective
7553 						 create_scorecard_objective
7554 												(p_effective_date              => l_effective_date,
7555 												 p_scorecard_id                => l_scorecard_id,
7556 												 p_business_group_id           => g_qual_pop_tbl (l_qual_pop_index).business_group_id,
7557 												 p_person_id                   => g_qual_pop_tbl (l_qual_pop_index).person_id,
7558 												 p_start_date                  => g_plan_dtls (1).start_date,
7559 												 p_end_date                    => g_plan_dtls (1).end_date,
7560 												 p_objective_name              => g_qual_obj_tbl (l_qual_obj_index).objective_name,
7561 												 p_valid_from                  => g_qual_obj_tbl (l_qual_obj_index).valid_from,
7562 												 p_valid_to                    => g_qual_obj_tbl (l_qual_obj_index).valid_to,
7563 												 p_target_date                 => g_qual_obj_tbl (l_qual_obj_index).target_date,
7564 												 p_copied_from_library_id      => g_qual_obj_tbl (l_qual_obj_index).objective_id,
7565 												 p_next_review_date            => g_qual_obj_tbl (l_qual_obj_index).next_review_date,
7566 												 p_group_code                  => g_qual_obj_tbl (l_qual_obj_index).group_code,
7567 												 p_priority_code               => g_qual_obj_tbl (l_qual_obj_index).priority_code,
7568 												 p_appraise_flag               => g_qual_obj_tbl (l_qual_obj_index).appraise_flag,
7569 												 p_weighting_percent           => g_qual_obj_tbl (l_qual_obj_index).weighting_percent,
7570 												 p_target_value                => g_qual_obj_tbl (l_qual_obj_index).target_value,
7571 												 p_uom_code                    => g_qual_obj_tbl (l_qual_obj_index).uom_code,
7572 												 p_measurement_style_code      => g_qual_obj_tbl (l_qual_obj_index).measurement_style_code,
7573 												 p_measure_name                => g_qual_obj_tbl (l_qual_obj_index).measure_name,
7574 												 p_measure_type_code           => g_qual_obj_tbl (l_qual_obj_index).measure_type_code,
7575 												 p_measure_comments            => g_qual_obj_tbl (l_qual_obj_index).measure_comments,
7576 												 p_details                     => g_qual_obj_tbl (l_qual_obj_index).details,
7577 												 p_success_criteria            => g_qual_obj_tbl (l_qual_obj_index).success_criteria,
7578 												 p_comments                    => g_qual_obj_tbl (l_qual_obj_index).comments
7579 												);
7580 					  END IF;
7581 
7582 					  --
7583 					  l_qual_obj_index := g_qual_obj_tbl.NEXT (l_qual_obj_index);
7584 				   --
7585 				   END LOOP;
7586 
7587 				   hr_utility.set_location (l_proc, 20);
7588 				END IF;                                                                                   --auto allocation flag = 'y'
7589 
7590 				log_message ('Done with qual objectives');
7591 
7592 				IF (g_plan_dtls (1).copy_past_objectives_flag = 'Y' AND g_plan_dtls (1).previous_plan_id IS NOT NULL)
7593 				THEN
7594 				   --
7595 				   hr_utility.set_location (l_proc, 30);
7596 				   copy_past_objectives (p_effective_date         => l_effective_date,
7597 										 p_business_group_id      => g_qual_pop_tbl (l_qual_pop_index).business_group_id,
7598 										 p_person_id              => g_qual_pop_tbl (l_qual_pop_index).person_id,
7599 										 p_scorecard_id           => l_scorecard_id,
7600 										 p_start_date             => g_plan_dtls (1).start_date,
7601 										 p_end_date               => g_plan_dtls (1).end_date,
7602 										 p_target_date            => NULL,
7603 										 p_assignemnt_id          => g_qual_pop_tbl (l_qual_pop_index).assignment_id,
7604 										 p_prev_plan_id           => g_plan_dtls (1).previous_plan_id,
7605 										 p_curr_plan_id           => g_plan_dtls (1).plan_id
7606 										);
7607 				   hr_utility.set_location (l_proc, 40);
7608 				--
7609 				END IF;                                                                                                              --
7610 
7611 				hr_utility.set_location (l_proc || ':' || g_appraisals_exist||':'||g_plan_aprsl_pds_tbl.COUNT ||':'||g_plan_dtls (1).include_appraisals_flag, 45);
7612 
7613 				-- Create appraisals for this person only if there exists any appraisals for this plan.
7614 				IF     p_enroll_appr = 'Y'
7615 				   AND g_plan_dtls (1).include_appraisals_flag = 'Y'
7616 				   AND g_appraisals_exist = 'Y'
7617 				   AND g_plan_aprsl_pds_tbl.COUNT > 0
7618 				THEN
7619 				   l_plan_aprsl_pds_index := g_plan_aprsl_pds_tbl.FIRST;
7620 				   hr_utility.set_location (l_proc, 50);
7621 
7622 				   WHILE (l_plan_aprsl_pds_index IS NOT NULL)
7623 				   LOOP
7624 					  --23-Jun-2009 schowdhu Eligibility Profile Enhc.-start
7625 					   --
7626 					   -- Enclose the call to eligibility within a block, so that if for any
7627 					   -- reason the eligibility engine errors, then process can still
7628 					   -- continue by skipping the current person/assignemnt as not eligible
7629 					   --
7630 					  OPEN get_elig_obj_id_for_period (g_plan_aprsl_pds_tbl (l_plan_aprsl_pds_index).appraisal_period_id);
7631 
7632 					  FETCH get_elig_obj_id_for_period
7633 					   INTO l_elig_obj_id;
7634 
7635 					  CLOSE get_elig_obj_id_for_period;
7636 
7637 					  IF (l_elig_obj_id IS NOT NULL)
7638 					  THEN
7639 						 BEGIN
7640 							--
7641 							ben_env_object.init (p_business_group_id      => g_qual_pop_tbl (l_qual_pop_index).business_group_id,
7642 												 p_thread_id              => NULL,
7643 												 p_chunk_size             => NULL,
7644 												 p_threads                => NULL,
7645 												 p_max_errors             => NULL,
7646 												 p_benefit_action_id      => NULL,
7647 												 p_effective_date         => l_obj_date
7648 												);
7649 							--
7650 							--
7651 							l_check_period_elig :=
7652 							   ben_per_asg_elig.eligible (p_person_id,
7653 														  p_assignment_id,
7654 														  l_elig_obj_id,
7655 														  l_obj_date,
7656 														  g_qual_pop_tbl (l_qual_pop_index).business_group_id,
7657 														  'Y'                                           ---KMG -- Added to Allow CWK's
7658 														 );
7659 						 EXCEPTION
7660 							WHEN OTHERS
7661 							THEN
7662 							   l_check_period_elig := 'N';
7663 
7664 							   IF g_dbg
7665 							   THEN
7666 								  op (l_proc, g_debug_log, 330);
7667 							   END IF;
7668 
7669 							   IF g_dbg
7670 							   THEN
7671 								  op (   l_proc
7672 									  || ' enroll_a_person skipped for appraisal period: '
7673 									  || g_plan_aprsl_pds_tbl (l_plan_aprsl_pds_index).appraisal_period_id
7674 									  || ' assignment_id: '
7675 									  || g_qual_pop_tbl (l_qual_pop_index).assignment_id,
7676 									  g_debug_log,
7677 									  330
7678 									 );
7679 							   END IF;
7680 						 END;
7681 					  END IF;                                                                              -- l_elig_obj_id null check
7682 
7683 	--23-Jun-2009 schowdhu Eligibility Profile Enhc.-start
7684 					  IF (l_check_period_elig = 'Y' OR (l_check_period_elig IS NULL AND l_elig_obj_id IS NULL))
7685 					  THEN
7686 						 hr_wpm_mass_apr_push.create_appraisal_for_person
7687 									  (p_score_card_id              => l_scorecard_id,
7688 									   p_appraisal_templ_id         => g_plan_aprsl_pds_tbl (l_plan_aprsl_pds_index).appraisal_template_id,
7689 									   p_effective_date             => p_effective_date,                             --to be validated
7690 									   p_appraisal_start_date       => g_plan_aprsl_pds_tbl (l_plan_aprsl_pds_index).start_date,
7691 									   p_appraisal_end_date         => g_plan_aprsl_pds_tbl (l_plan_aprsl_pds_index).end_date,
7692 									   p_appraisal_date             => g_plan_aprsl_pds_tbl (l_plan_aprsl_pds_index).task_start_date,
7693 									   p_appraisal_status           => 'PLANNED',                            -- decided in the meeting
7694 									   p_plan_id                    => p_plan_id,
7695 									   p_next_appraisal_date        => NULL,                                                  -- to be
7696 									   p_appraisal_initiator        => g_plan_aprsl_pds_tbl (l_plan_aprsl_pds_index).initiator_code,
7697 									   p_type                       => g_plan_aprsl_pds_tbl (l_plan_aprsl_pds_index).appraisal_type,
7698 									   -- A column to be added to UI and table in per_appraisal_periods
7699 									   p_appraisal_system_type      => g_plan_aprsl_pds_tbl (l_plan_aprsl_pds_index).appraisal_system_type,
7700 									   p_return_status              => l_appr_ret_status
7701 									  );
7702 					  END IF;                                                                                     -- eligibility check
7703 
7704 					  hr_utility.set_location (l_proc, 60);
7705 					  --
7706 					  l_plan_aprsl_pds_index := g_plan_aprsl_pds_tbl.NEXT (l_plan_aprsl_pds_index);
7707 				   --
7708 				   END LOOP;
7709 
7710 				   hr_utility.set_location (l_proc, 70);
7711 				END IF;
7712 			 END IF;                                                                         -- appraisal = y or objective setting 'y'
7713 		  END IF;                                                                                                     -- plan PUBLISHD
7714 
7715 		  hr_utility.set_location ('Leaving:' || l_proc, 100);
7716 	   END enroll_a_person;
7717 
7718 	--
7719 	--
7720 	   PROCEDURE admin_enroll_into_plan (p_plan_id IN NUMBER, p_effective_date IN DATE)
7721 	   IS
7722 		  l_proc                   VARCHAR2 (72)                        := g_package || 'admin_enroll_into_plan';
7723 		  l_plan_name              per_perf_mgmt_plans.plan_name%TYPE;
7724 
7725 		  --
7726 		  CURSOR csr_person_dtls (p_assignment_id IN NUMBER, p_effective_date IN DATE)
7727 		  IS
7728 			 SELECT papf.person_id, papf.full_name full_name, paaf.assignment_id, paaf.assignment_number, paaf.position_id,
7729 					paaf.organization_id, paaf.supervisor_id, paaf.supervisor_assignment_id, suppapf.full_name supervisor_name
7730 			   FROM per_people_f papf, per_assignments_f paaf, per_all_people_f suppapf
7731 			  WHERE paaf.assignment_id = p_assignment_id
7732 				AND papf.person_id = paaf.person_id
7733 				AND p_effective_date BETWEEN papf.effective_start_date AND papf.effective_end_date
7734 				AND p_effective_date BETWEEN paaf.effective_start_date AND paaf.effective_end_date
7735 				AND paaf.supervisor_id = suppapf.person_id(+)
7736 				--8632500 Modified
7737 				AND p_effective_date BETWEEN suppapf.effective_start_date(+) AND suppapf.effective_end_date(+);
7738 
7739 		  --
7740 		  l_person_rec             csr_person_dtls%ROWTYPE;
7741 
7742 		  --
7743 		  --
7744 		  CURSOR csr_apprs_exist (p_plan_id IN NUMBER)
7745 		  IS
7746 			 SELECT 'Y'
7747 			   FROM DUAL
7748 			  WHERE EXISTS (SELECT 'x'
7749 							  FROM per_appraisals
7750 							 WHERE plan_id = p_plan_id);
7751 
7752 		  l_chk_exists             VARCHAR2 (1);
7753 
7754 		  --
7755 		  --
7756 		  CURSOR csr_asg_enrolled (p_assignment_id IN NUMBER, p_plan_id IN NUMBER)
7757 		  IS
7758 			 SELECT 'Y'
7759 			   FROM per_personal_scorecards
7760 			  WHERE plan_id = p_plan_id AND assignment_id = p_assignment_id AND status_code <> 'TRANSFER_OUT';
7761 
7762 		  l_asg_already_enrolled   VARCHAR2 (1);
7763 		  l_person_id              NUMBER;
7764 	   BEGIN
7765 		  hr_utility.set_location ('Entering:' || l_proc, 10);
7766 		  g_qual_pop_tbl.DELETE;
7767 		  populate_qual_plan_population (g_plan_dtls (1), p_effective_date);
7768 		  hr_utility.set_location (l_proc, 11);
7769 
7770 		  IF (g_plan_dtls (1).automatic_allocation_flag = 'Y')
7771 		  THEN
7772 			 populate_qual_objectives (g_plan_dtls (1).start_date, g_plan_dtls (1).end_date);
7773 		  END IF;
7774 
7775 		  hr_utility.set_location (l_proc, 12);
7776 
7777 		  IF (g_plan_dtls (1).include_appraisals_flag = 'Y')
7778 		  THEN
7779 			 populate_plan_apprsl_periods (g_plan_dtls (1).plan_id);
7780 
7781 			 OPEN csr_apprs_exist (p_plan_id);
7782 
7783 			 FETCH csr_apprs_exist
7784 			  INTO g_appraisals_exist;
7785 
7786 			 CLOSE csr_apprs_exist;
7787 		  END IF;
7788 
7789 		  hr_utility.set_location (l_proc, 13);
7790 	--
7791 		  l_asg_already_enrolled := 'N';
7792 
7793 		  FOR i IN g_selected_entities.FIRST .. g_selected_entities.LAST
7794 		  LOOP
7795 			 hr_utility.set_location (l_proc, 14);
7796 
7797 			 OPEN csr_asg_enrolled (g_selected_entities (i), p_plan_id);
7798 
7799 			 FETCH csr_asg_enrolled
7800 			  INTO l_asg_already_enrolled;
7801 
7802 			 CLOSE csr_asg_enrolled;
7803 
7804 			 -- Bug 7277335  Fix
7805 			 -- IF NVL(l_asg_already_enrolled,'N') = 'N' THEN
7806 			 FOR j IN csr_person_dtls (g_selected_entities (i), p_effective_date)
7807 			 LOOP
7808 				l_chk_exists := chk_assignment_in_population (j.assignment_id);
7809 				hr_utility.set_location (l_proc, 15);
7810 				l_person_id := j.person_id;
7811 
7812 				IF l_chk_exists = 'N'
7813 				THEN
7814 				   log_message (   j.full_name
7815 								|| '-'
7816 								|| j.assignment_id
7817 								|| '-'
7818 								|| j.assignment_number
7819 								|| ' is not in the plan population. Cannot enroll.'
7820 							   );
7821 				   g_num_errors := NVL (g_num_errors, 0) + 1;
7822 				--EDIT -- write a message to the conc.log
7823 				ELSE
7824 				   BEGIN
7825 					  IF NVL (l_asg_already_enrolled, 'N') = 'N'
7826 					  THEN
7827 						 log_message (j.full_name || '-' || j.assignment_number || ' is in the plan population. Trying to enroll.');
7828 						 enroll_a_person (p_plan_id             => p_plan_id,
7829 										  p_assignment_id       => j.assignment_id,
7830 										  p_person_id           => j.person_id,
7831 										  p_effective_date      => p_effective_date
7832 										 );
7833 						 log_message ('Successfully enrolled ' || j.full_name || '-' || j.assignment_number || '.');
7834 						 -- Ntf should be sent if person is successfully enrolled
7835 						 send_message_notification (l_person_id, 'WPM_AP_ENROLL_MSG', p_plan_id, NULL);             -- 9014013 Bug Fix
7836 					  ELSE
7837 						 log_message (j.full_name || '-' || j.assignment_id || '-' || j.assignment_number || ' is already Enrolled ');
7838 						 g_num_errors := NVL (g_num_errors, 0) + 1;
7839 					  END IF;
7840 				   -- Commenting this as Ntf should not be sent if person is already enrolled .
7841 				   -- send_message_notification (l_person_id, 'WPM_AP_ENROLL_MSG', p_plan_id, NULL);  -- 9014013 Bug Fix
7842 				   EXCEPTION
7843 					  WHEN OTHERS
7844 					  THEN
7845 						 log_message ('Error
7846 	enrolling:' ||                    j.full_name || '-' || j.assignment_number || '.');
7847 						 log_message (SQLERRM);
7848 	--changes done for bug#10062408
7849 		   --              g_num_errors               := NVL (g_num_errors, 0) + 1;
7850 				   END;
7851 				END IF;
7852 			 END LOOP;
7853 			-- send_message_notification (l_person_id, 'WPM_AP_ENROLL_MSG', p_plan_id, NULL);  -- 9014013 Bug Fix
7854 		  --  END IF; -- asg not enrolled
7855 		  END LOOP;
7856 
7857 		  hr_utility.set_location ('Leaving:' || l_proc, 100);
7858 	   END admin_enroll_into_plan;
7859 
7860 	--
7861 	--
7862 	   PROCEDURE revert_appraisal_details (p_appraisal_id IN NUMBER, p_plan_id IN NUMBER, p_effective_date IN DATE)
7863 	   IS
7864 		  CURSOR csr_event_dtls (p_appraisal_id NUMBER)
7865 		  IS
7866 			 SELECT pa.appraisee_person_id, pe.event_id, pe.object_version_number event_ovn, ppr.performance_review_id,
7867 					ppr.object_version_number review_ovn
7868 			   FROM per_appraisals pa, per_events pe, per_performance_reviews ppr
7869 			  WHERE pa.appraisal_id = p_appraisal_id AND pa.event_id = pe.event_id AND pe.event_id = ppr.event_id;
7870 
7871 		  l_appraisee_person_id           NUMBER;
7872 
7873 		  --
7874 		  CURSOR csr_appr_objs (p_appraisal_id NUMBER)
7875 		  IS
7876 			 SELECT po.objective_id, po.object_version_number
7877 			   FROM per_objectives po
7878 			  WHERE appraisal_id = p_appraisal_id;
7879 
7880 		  --
7881 		  CURSOR csr_sc_obj (p_sc_id NUMBER, p_objective_id NUMBER)
7882 		  IS
7883 			 SELECT po.objective_id, po.object_version_number
7884 			   FROM per_objectives po
7885 			  WHERE scorecard_id = p_sc_id AND copied_from_objective_id = p_objective_id;
7886 
7887 		  --
7888 		  CURSOR csr_sc_id (p_appraisee_person_id NUMBER, p_plan_id NUMBER)
7889 		  IS
7890 			 SELECT scorecard_id
7891 			   FROM per_personal_scorecards sc
7892 			  WHERE person_id = p_appraisee_person_id AND plan_id = p_plan_id;
7893 
7894 		  l_sc_id                         NUMBER;
7895 	-- Variables for IN/OUT parameters
7896 		  l_weighting_over_100_warning    BOOLEAN;
7897 		  l_weighting_appraisal_warning   BOOLEAN;
7898 		  l_object_version_number         NUMBER;
7899 	   BEGIN
7900 		  -- Delete the event that is created and the performance review row as well
7901 		  FOR i IN csr_event_dtls (p_appraisal_id)
7902 		  LOOP
7903 			 l_appraisee_person_id := i.appraisee_person_id;
7904 			 hr_perf_review_api.delete_perf_review (p_performance_review_id      => i.performance_review_id,
7905 													p_object_version_number      => i.review_ovn
7906 												   );
7907 			 --
7908 			 per_events_api.delete_event (p_event_id => i.event_id, p_object_version_number => i.event_ovn);
7909 		  END LOOP;
7910 
7911 		  OPEN csr_sc_id (l_appraisee_person_id, p_plan_id);
7912 
7913 		  FETCH csr_sc_id
7914 		   INTO l_sc_id;
7915 
7916 		  CLOSE csr_sc_id;
7917 
7918 		  --
7919 		  -- Update the scorecard_id back in all the appraisal objectives
7920 		  -- and delete the duplicated objectives from the sc
7921 		  IF l_sc_id IS NOT NULL
7922 		  THEN
7923 			 FOR j IN csr_appr_objs (p_appraisal_id)
7924 			 LOOP
7925 				l_object_version_number := j.object_version_number;
7926 				hr_objectives_api.update_objective (p_validate                         => FALSE,
7927 													p_effective_date                   => p_effective_date,
7928 													p_objective_id                     => j.objective_id,
7929 													p_object_version_number            => l_object_version_number,
7930 													p_scorecard_id                     => l_sc_id,
7931 													p_weighting_over_100_warning       => l_weighting_over_100_warning,
7932 													p_weighting_appraisal_warning      => l_weighting_appraisal_warning,
7933 													p_appraise_flag                    => 'Y'
7934 												   );
7935 
7936 				--now delete the duplicated objective from the SC
7937 				FOR i IN csr_sc_obj (l_sc_id, j.objective_id)
7938 				LOOP
7939 				   hr_objectives_api.delete_objective (p_validate                   => FALSE,
7940 													   p_objective_id               => i.objective_id,
7941 													   p_object_version_number      => i.object_version_number
7942 													  );
7943 				END LOOP;
7944 			 END LOOP;
7945 		  END IF;
7946 	   --
7947 	   END revert_appraisal_details;
7948 
7949 	--
7950 	--
7951 	   PROCEDURE admin_reopen_plan_appraisals (p_plan_id IN NUMBER, p_effective_date IN DATE)
7952 	   IS
7953 		  CURSOR csr_appraisal_dtls (p_appraisal_id IN NUMBER, p_plan_id IN NUMBER, p_effective_date IN DATE)
7954 		  IS
7955 			 SELECT pa.appraisal_id, pa.main_appraiser_id, pa.appraisee_person_id, papf.full_name "MAIN_APPRAISER_NAME",
7956 					papf1.full_name "APPRAISEE_NAME",
7957 					TO_CHAR (appraisal_period_start_date, 'DD-MON-YYYY') appraisal_period_start_date,
7958 					TO_CHAR (appraisal_period_end_date, 'DD-MON-YYYY') appraisal_period_end_date,
7959 					TO_CHAR (appraisal_date, 'DD-MON-YYYY') appraisal_date, pa.status, pa.assignment_id
7960 			   FROM per_appraisals pa, per_people_f papf, per_people_f papf1
7961 			  WHERE pa.appraisal_id = p_appraisal_id
7962 				AND pa.plan_id = p_plan_id
7963 				AND pa.main_appraiser_id = papf.person_id
7964 				AND p_effective_date BETWEEN papf.effective_start_date AND papf.effective_end_date
7965 				AND pa.appraisee_person_id = papf1.person_id
7966 				AND p_effective_date BETWEEN papf1.effective_start_date AND papf1.effective_end_date;
7967 
7968 		  l_appraisal_dtls   VARCHAR2 (4000);
7969 		  l_person_id        per_appraisals.appraisee_person_id%TYPE;
7970 		  l_assignment_id    per_appraisals.assignment_id%TYPE;
7971 		  l_full_name        per_people_f.full_name%TYPE;
7972 	   BEGIN
7973 		  FOR i IN g_selected_entities.FIRST .. g_selected_entities.LAST
7974 		  LOOP
7975 			 BEGIN
7976 				FOR j IN csr_appraisal_dtls (g_selected_entities (i), p_plan_id, p_effective_date)
7977 				LOOP
7978 				   log_message ('Opening appraisal for: ' || j.appraisee_name);
7979 				   log_message (   'This appraisal will be assigned to the main appraiser,'
7980 								|| j.main_appraiser_name
7981 								|| ' in Ongoing Status.'
7982 							   );
7983 				   l_appraisal_dtls :=
7984 									  j.appraisee_name || '-' || j.appraisal_period_start_date || ' - ' || j.appraisal_period_end_date;
7985 				   l_person_id := j.appraisee_person_id;
7986 				   l_assignment_id := j.assignment_id;
7987 				   l_full_name := j.appraisee_name;
7988 				END LOOP;
7989 
7990 				--
7991 				revert_appraisal_details (p_appraisal_id        => g_selected_entities (i),
7992 										  p_plan_id             => p_plan_id,
7993 										  p_effective_date      => p_effective_date
7994 										 );
7995 
7996 				--
7997 				UPDATE per_appraisals pa
7998 				   SET system_params = SUBSTR (system_params, 1, INSTR (pa.system_params, 'pItemKey=') - 2),
7999 					   appraisal_system_status = 'ONGOING',
8000 					   event_id = NULL
8001 				 WHERE pa.appraisal_id = g_selected_entities (i);
8002 
8003 				--
8004 				--
8005 				send_message_notification (get_manager_id (l_person_id, l_assignment_id),
8006 										   'WPM_APPRAISAL_REOPEN_MGR_MSG',
8007 										   p_plan_id,
8008 										   l_full_name
8009 										  );
8010 				send_message_notification (l_person_id, 'WPM_APPRAISAL_REOPEN_WKR_MSG', p_plan_id, NULL);
8011 			 --
8012 			 EXCEPTION
8013 				WHEN OTHERS
8014 				THEN
8015 				   log_message ('Error reopening appraisal:' || l_appraisal_dtls || '.');
8016 				   log_message (SQLERRM);
8017 				   g_num_errors := NVL (g_num_errors, 0) + 1;
8018 			 END;
8019 		  END LOOP;
8020 	   END admin_reopen_plan_appraisals;
8021 
8022 	--
8023 	--
8024 	   PROCEDURE remove_scorecard_details (p_scorecard_id IN NUMBER)
8025 	   IS
8026 	   BEGIN
8027 		  DELETE FROM hr_api_transaction_steps step
8028 				WHERE step.transaction_id IN (
8029 							  SELECT trn.transaction_id
8030 								FROM hr_api_transactions trn
8031 							   WHERE trn.transaction_ref_id = p_scorecard_id
8032 									 AND trn.transaction_ref_table = 'PER_PERSONAL_SCORECARDS');
8033 
8034 		  DELETE FROM hr_api_transactions
8035 				WHERE transaction_ref_id = p_scorecard_id AND transaction_ref_table = 'PER_PERSONAL_SCORECARDS';
8036 
8037 		  --
8038 		  DELETE FROM per_objectives
8039 				WHERE scorecard_id = p_scorecard_id;
8040 	   END remove_scorecard_details;
8041 
8042 	   PROCEDURE admin_remove_scorecard (p_plan_id IN NUMBER, p_effective_date IN DATE)
8043 	   IS
8044 		  CURSOR csr_sc_dtls (p_sc_id IN NUMBER, p_plan_id IN NUMBER, p_effective_date IN DATE)
8045 		  IS
8046 			 SELECT pc.scorecard_id, pc.person_id, papf.full_name scorecard_owner, pc.status_code
8047 			   FROM per_personal_scorecards pc, per_people_f papf
8048 			  WHERE pc.scorecard_id = p_sc_id
8049 				AND pc.plan_id = p_plan_id
8050 				AND pc.person_id = papf.person_id
8051 				AND p_effective_date BETWEEN papf.effective_start_date AND papf.effective_end_date;
8052 
8053 		  --
8054 		  CURSOR csr_appr_dtls (p_person_id NUMBER, p_plan_id NUMBER)
8055 		  IS
8056 			 SELECT appraisal_id, object_version_number
8057 			   FROM per_appraisals
8058 			  WHERE plan_id = p_plan_id AND appraisee_person_id = p_person_id;
8059 		--15902260
8060 		CURSOR csr_valid_plan (p_plan_id IN NUMBER)
8061 		  IS
8062 			 SELECT *
8063 			   FROM per_perf_mgmt_plans
8064 			  WHERE plan_id = p_plan_id;
8065 
8066 		  l_plan_rec                csr_valid_plan%ROWTYPE;
8067 
8068 		  --
8069 		  l_sc_dtls     VARCHAR2 (500);
8070 		  l_person_id   per_personal_scorecards.person_id%TYPE;
8071 	   BEGIN
8072 		  FOR i IN g_selected_entities.FIRST .. g_selected_entities.LAST
8073 		  LOOP
8074 			 BEGIN
8075 				FOR j IN csr_sc_dtls (g_selected_entities (i), p_plan_id, p_effective_date)
8076 				LOOP
8077 				   log_message ('Removing scorecard for: ' || j.scorecard_owner);
8078 				   l_sc_dtls := j.scorecard_owner || '- ' || j.status_code;
8079 				   -- no  need to remove score card details
8080 				   remove_scorecard_details (g_selected_entities (i));
8081 
8082 				   -- UPdate the status of score card to DELETED
8083 				   DELETE      per_personal_scorecards
8084 						 WHERE scorecard_id = g_selected_entities (i);
8085 
8086 				   --
8087 				   FOR k IN csr_appr_dtls (j.person_id, p_plan_id)
8088 				   LOOP
8089 					  delete_appraisal_for_person (k.appraisal_id, k.object_version_number);
8090 				   END LOOP;
8091 
8092 				   -- remove the node from the hierarchy
8093 				   DELETE FROM per_wpm_plan_hierarchy
8094 						 WHERE employee_person_id = j.person_id;
8095 
8096 				   --
8097 				   l_person_id := j.person_id;
8098 				END LOOP;
8099 			OPEN csr_valid_plan (p_plan_id);
8100 			  FETCH csr_valid_plan
8101 			   INTO l_plan_rec;
8102 
8103 			IF (l_plan_rec.notify_population_flag = 'Y')
8104 				THEN
8105 						send_message_notification (l_person_id, 'WPM_SC_REMOVE_MSG', p_plan_id, NULL);
8106 			END IF;
8107 			 --
8108 			 EXCEPTION
8109 				WHEN OTHERS
8110 				THEN
8111 				   log_message ('Error removing scorecard:' || l_sc_dtls || '.');
8112 				   log_message (SQLERRM);
8113 				   g_num_errors := NVL (g_num_errors, 0) + 1;
8114 			 END;
8115 		  END LOOP;
8116 	--
8117 	   END admin_remove_scorecard;
8118 
8119 	--
8120 	--
8121 	   PROCEDURE admin_reopen_scorecard (p_plan_id IN NUMBER, p_effective_date IN DATE)
8122 	   IS
8123 		  CURSOR csr_sc_dtls (p_sc_id IN NUMBER, p_plan_id IN NUMBER, p_effective_date IN DATE)
8124 		  IS
8125 			 SELECT pc.scorecard_id, pc.person_id, papf.full_name scorecard_owner, pc.status_code, papf.business_group_id,
8126 					paaf.organization_id, paaf.position_id, paaf.job_id, pc.assignment_id, paaf.supervisor_id          --  Bug7567079
8127 			   FROM per_personal_scorecards pc, per_people_f papf, per_assignments_f paaf
8128 			  WHERE pc.scorecard_id = p_sc_id
8129 				AND pc.plan_id = p_plan_id
8130 				AND pc.assignment_id = paaf.assignment_id
8131 				AND pc.person_id = papf.person_id
8132 				AND p_effective_date BETWEEN paaf.effective_start_date AND paaf.effective_end_date
8133 				AND p_effective_date BETWEEN papf.effective_start_date AND papf.effective_end_date;
8134 
8135 		  CURSOR csr_appr_in_progress (p_plan_id IN NUMBER, p_effective_date IN DATE)
8136 		  IS
8137 			 SELECT 'Y'
8138 			   FROM per_appraisal_periods
8139 			  WHERE plan_id = p_plan_id AND p_effective_date BETWEEN task_start_date AND task_end_date;
8140 
8141 		  l_appraisals_in_progress   VARCHAR2 (1)   := 'N';
8142 		  l_sc_dtls                  VARCHAR2 (500);
8143 		  l_scorecard_status_code    VARCHAR2 (30);
8144 	   --Bug7567079 l_sup_id per_all_assignments_f.supervisor_id%type default null;
8145 	   BEGIN
8146 		  OPEN csr_appr_in_progress (p_plan_id, p_effective_date);
8147 
8148 		  FETCH csr_appr_in_progress
8149 		   INTO l_appraisals_in_progress;
8150 
8151 		  CLOSE csr_appr_in_progress;
8152 
8153 		  FOR i IN g_selected_entities.FIRST .. g_selected_entities.LAST
8154 		  LOOP
8155 			 FOR j IN csr_sc_dtls (g_selected_entities (i), p_plan_id, p_effective_date)
8156 			 LOOP
8157 				BEGIN
8158 				   log_message ('Reopening scorecard for: ' || j.scorecard_owner);
8159 				   l_sc_dtls := j.scorecard_owner || '- ' || j.status_code;
8160 
8161 				   IF (   TRUNC (SYSDATE) BETWEEN g_plan_dtls (1).obj_setting_start_date AND g_plan_dtls (1).obj_setting_deadline
8162 					   OR (g_plan_dtls (1).obj_set_outside_period_flag = 'Y' AND NVL (l_appraisals_in_progress, 'N') = 'N')
8163 					  )
8164 				   THEN
8165 					  log_message ('Within Objective setting deadline, so reopening the score
8166 	card.'            );
8167 
8168 					   --included for fixing bug#6918115
8169 					  -- IF g_plan_dtls(1).method_code = 'CAS' THEN
8170 					  IF    (g_plan_dtls (1).hierarchy_type_code = 'SUP' AND g_plan_dtls (1).supervisor_id = j.person_id)
8171 						 OR (    g_plan_dtls (1).hierarchy_type_code = 'SUP_ASG'
8172 							 AND g_plan_dtls (1).supervisor_assignment_id = j.assignment_id
8173 							)
8174 						 OR (g_plan_dtls (1).hierarchy_type_code IN ('POS') AND g_plan_dtls (1).top_position_id = j.position_id)
8175 						 OR (    g_plan_dtls (1).hierarchy_type_code = 'ORG'
8176 							 AND is_supervisor_in_org (g_plan_dtls (1).top_organization_id, j.person_id) = 1
8177 							)
8178 					  THEN
8179 						 l_scorecard_status_code := 'NOT_STARTED_WITH_WKR';
8180 					  ELSE
8181 						 l_scorecard_status_code := 'MGR';
8182 					  END IF;
8183 
8184 					  --ELSE
8185 					   --    l_scorecard_status_code := 'MGR';
8186 					  --END IF;
8187 					  UPDATE per_personal_scorecards
8188 						 SET status_code = l_scorecard_status_code
8189 					   WHERE scorecard_id = g_selected_entities (i);
8190 
8191 					  --l_sup_id := get_manager_id(j.person_id);
8192 					  send_message_notification (j.person_id, 'WPM_SC_REOPEN_WKR_MSG', p_plan_id, NULL);
8193 					  send_message_notification (j.supervisor_id, 'WPM_SC_REOPEN_MGR_MSG', p_plan_id, j.scorecard_owner);
8194 				   ELSE
8195 					  log_message ('Score card is outside the Objective setting deadline, so
8196 	cannot be reopened.');
8197 				   END IF;
8198 				EXCEPTION
8199 				   WHEN OTHERS
8200 				   THEN
8201 					  log_message ('Error reopening scorecard:' || l_sc_dtls || '.');
8202 					  log_message (SQLERRM);
8203 					  g_num_errors := NVL (g_num_errors, 0) + 1;
8204 				END;
8205 			 END LOOP;
8206 		  END LOOP;
8207 	   --
8208 	   END admin_reopen_scorecard;
8209 
8210 	--
8211 	   PROCEDURE admin_refresh_scorecard (p_plan_id IN NUMBER, p_effective_date IN DATE)
8212 	   IS
8213 		  CURSOR csr_sc_dtls (p_sc_id IN NUMBER, p_plan_id IN NUMBER, p_effective_date IN DATE)
8214 		  IS
8215 			 SELECT pc.scorecard_id, pc.person_id, papf.full_name scorecard_owner, pc.status_code, papf.business_group_id,
8216 					paaf.organization_id, paaf.position_id, paaf.job_id, pc.assignment_id, paaf.supervisor_id          --  Bug7567079
8217 			   FROM per_personal_scorecards pc, per_people_f papf, per_assignments_f paaf
8218 			  WHERE pc.scorecard_id = p_sc_id
8219 				AND pc.plan_id = p_plan_id
8220 				AND pc.assignment_id = paaf.assignment_id
8221 				AND pc.person_id = papf.person_id
8222 				AND p_effective_date BETWEEN paaf.effective_start_date AND paaf.effective_end_date
8223 				AND p_effective_date BETWEEN papf.effective_start_date AND papf.effective_end_date;
8224 
8225 		  l_sc_rec                  csr_sc_dtls%ROWTYPE;
8226 		  l_qual_obj_index          BINARY_INTEGER;
8227 		  l_scorecard_id            NUMBER;
8228 		  l_obj_date                DATE                                       := TRUNC (SYSDATE);
8229 		  l_scorecard_status_code   VARCHAR2 (30);
8230 		  l_check_elig              VARCHAR2 (10);
8231 
8232 		  CURSOR csr_sc_dup_obj (p_scorecard_id IN NUMBER, p_library_id IN NUMBER)
8233 		  IS
8234 			 SELECT 'Y'
8235 			   FROM per_objectives
8236 			  WHERE scorecard_id = p_scorecard_id AND copied_from_library_id = p_library_id;
8237 
8238 		  l_sc_dup_obj              VARCHAR2 (1);
8239 		  l_sup_id                  per_all_assignments_f.supervisor_id%TYPE   DEFAULT NULL;
8240 	   BEGIN
8241 		  IF (g_plan_dtls (1).automatic_allocation_flag = 'Y')
8242 		  THEN
8243 			 populate_qual_objectives (g_plan_dtls (1).start_date, g_plan_dtls (1).end_date);
8244 		  END IF;
8245 
8246 		  FOR i IN g_selected_entities.FIRST .. g_selected_entities.LAST
8247 		  LOOP
8248 			 l_scorecard_id := g_selected_entities (i);
8249 			 log_message ('Processing Scorecard:' || l_scorecard_id);
8250 
8251 			 BEGIN
8252 				OPEN csr_sc_dtls (l_scorecard_id, p_plan_id, p_effective_date);
8253 
8254 				FETCH csr_sc_dtls
8255 				 INTO l_sc_rec;
8256 
8257 				CLOSE csr_sc_dtls;
8258 
8259 	-- No need remove details. reevaluate objectives eligibility and insert any not existing ones
8260 	--       remove_scorecard_details(l_scorecard_id);
8261 		   --
8262 				log_message ('select scorecard_id rec:' || l_sc_rec.scorecard_owner);
8263 
8264 				IF (g_plan_dtls (1).automatic_allocation_flag = 'Y')
8265 				THEN
8266 				   l_qual_obj_index := g_qual_obj_tbl.FIRST;
8267 
8268 				   WHILE (l_qual_obj_index IS NOT NULL)
8269 				   LOOP
8270 					  --
8271 					  -- Enclose the call to eligibility within a block, so that if for any
8272 					  -- reason the eligibility engine errors, then process can still
8273 					  -- continue by skipping the current person/assignemnt as not eligible
8274 					  --
8275 					  log_message ('Evaluating: ' || g_qual_obj_tbl (l_qual_obj_index).objective_name);
8276 
8277 					  BEGIN
8278 						 --
8279 						 ben_env_object.init (p_business_group_id      => l_sc_rec.business_group_id,
8280 											  p_thread_id              => NULL,
8281 											  p_chunk_size             => NULL,
8282 											  p_threads                => NULL,
8283 											  p_max_errors             => NULL,
8284 											  p_benefit_action_id      => NULL,
8285 											  p_effective_date         => l_obj_date
8286 											 );
8287 						 --
8288 						 --
8289 						 l_check_elig :=
8290 							ben_per_asg_elig.eligible (l_sc_rec.person_id,
8291 													   l_sc_rec.assignment_id,
8292 													   g_qual_obj_tbl (l_qual_obj_index).elig_obj_id,
8293 													   l_obj_date,
8294 													   l_sc_rec.business_group_id,
8295 													   'Y'                                              ---KMG -- Added to Allow CWK's
8296 													  );
8297 						 log_message ('eLIGI CHECK:' || l_check_elig);
8298 					  EXCEPTION
8299 						 WHEN OTHERS
8300 						 THEN
8301 							log_message ('Error while evaluating eligibility for' || g_qual_obj_tbl (l_qual_obj_index).objective_name);
8302 							log_message (SQLERRM);
8303 							NULL;
8304 					  END;
8305 
8306 					  IF (l_check_elig = 'Y')
8307 					  THEN
8308 						 -- Create the objective
8309 						 OPEN csr_sc_dup_obj (l_scorecard_id, g_qual_obj_tbl (l_qual_obj_index).objective_id);
8310 
8311 						 FETCH csr_sc_dup_obj
8312 						  INTO l_sc_dup_obj;
8313 
8314 						 IF csr_sc_dup_obj%NOTFOUND
8315 						 THEN
8316 							create_scorecard_objective
8317 												(p_effective_date              => p_effective_date,
8318 												 p_scorecard_id                => l_scorecard_id,
8319 												 p_business_group_id           => l_sc_rec.business_group_id,
8320 												 p_person_id                   => l_sc_rec.person_id,
8321 												 p_start_date                  => g_plan_dtls (1).start_date,
8322 												 p_end_date                    => g_plan_dtls (1).end_date,
8323 												 p_objective_name              => g_qual_obj_tbl (l_qual_obj_index).objective_name,
8324 												 p_valid_from                  => g_qual_obj_tbl (l_qual_obj_index).valid_from,
8325 												 p_valid_to                    => g_qual_obj_tbl (l_qual_obj_index).valid_to,
8326 												 p_target_date                 => g_qual_obj_tbl (l_qual_obj_index).target_date,
8327 												 p_copied_from_library_id      => g_qual_obj_tbl (l_qual_obj_index).objective_id,
8328 												 p_next_review_date            => g_qual_obj_tbl (l_qual_obj_index).next_review_date,
8329 												 p_group_code                  => g_qual_obj_tbl (l_qual_obj_index).group_code,
8330 												 p_priority_code               => g_qual_obj_tbl (l_qual_obj_index).priority_code,
8331 												 p_appraise_flag               => g_qual_obj_tbl (l_qual_obj_index).appraise_flag,
8332 												 p_weighting_percent           => g_qual_obj_tbl (l_qual_obj_index).weighting_percent,
8333 												 p_target_value                => g_qual_obj_tbl (l_qual_obj_index).target_value,
8334 												 p_uom_code                    => g_qual_obj_tbl (l_qual_obj_index).uom_code,
8335 												 p_measurement_style_code      => g_qual_obj_tbl (l_qual_obj_index).measurement_style_code,
8336 												 p_measure_name                => g_qual_obj_tbl (l_qual_obj_index).measure_name,
8337 												 p_measure_type_code           => g_qual_obj_tbl (l_qual_obj_index).measure_type_code,
8338 												 p_measure_comments            => g_qual_obj_tbl (l_qual_obj_index).measure_comments,
8339 												 p_details                     => g_qual_obj_tbl (l_qual_obj_index).details,
8340 												 p_success_criteria            => g_qual_obj_tbl (l_qual_obj_index).success_criteria,
8341 												 p_comments                    => g_qual_obj_tbl (l_qual_obj_index).comments
8342 												);
8343 						 END IF;                                                -- create only if the objective is not already copied.
8344 
8345 						 CLOSE csr_sc_dup_obj;
8346 					  END IF;
8347 
8348 					  --
8349 					  l_qual_obj_index := g_qual_obj_tbl.NEXT (l_qual_obj_index);
8350 				   --
8351 				   END LOOP;
8352 				END IF;                                                                                   --auto allocation flag = 'y'
8353 
8354 				--
8355 				IF g_plan_dtls (1).method_code = 'CAS'
8356 				THEN
8357 				   IF    (g_plan_dtls (1).hierarchy_type_code = 'SUP' AND g_plan_dtls (1).supervisor_id = l_sc_rec.person_id)
8358 					  OR (    g_plan_dtls (1).hierarchy_type_code = 'SUP_ASG'
8359 						  AND g_plan_dtls (1).supervisor_assignment_id = l_sc_rec.assignment_id
8360 						 )
8361 					  OR (g_plan_dtls (1).hierarchy_type_code IN ('POS') AND g_plan_dtls (1).top_position_id = l_sc_rec.position_id)
8362 					  OR (    g_plan_dtls (1).hierarchy_type_code = 'ORG'
8363 						  AND is_supervisor_in_org (g_plan_dtls (1).top_organization_id, l_sc_rec.person_id) = 1
8364 						 )
8365 				   THEN
8366 					  l_scorecard_status_code := 'NOT_STARTED_WITH_WKR';
8367 				   ELSE
8368 					  l_scorecard_status_code := 'NOT_STARTED_WITH_MGR';
8369 				   END IF;
8370 				ELSE
8371 				   l_scorecard_status_code := 'NOT_STARTED_WITH_WKR';
8372 				END IF;
8373 
8374 				UPDATE per_personal_scorecards
8375 				   SET status_code = l_scorecard_status_code
8376 				 WHERE scorecard_id = l_scorecard_id;
8377 
8378 				--Bug7567079         l_sup_id := get_manager_id(l_sc_rec.person_id);
8379 				send_message_notification (l_sc_rec.person_id, 'WPM_SC_REFRESH_WKR', p_plan_id, NULL);
8380 				send_message_notification (l_sc_rec.supervisor_id, 'WPM_SC_REFRESH_MGR', p_plan_id, l_sc_rec.scorecard_owner);
8381 			 EXCEPTION
8382 				WHEN OTHERS
8383 				THEN
8384 				   log_message ('Error refreshing
8385 	scorecard:' ||              l_sc_rec.scorecard_owner || '.');
8386 				   log_message (SQLERRM);
8387 				   g_num_errors := NVL (g_num_errors, 0) + 1;
8388 			 END;
8389 		  END LOOP;
8390 	   END admin_refresh_scorecard;
8391 
8392 	---
8393 	--
8394 	   PROCEDURE admin_change_top_sup (
8395 		  p_plan_id                    IN   NUMBER,
8396 		  p_effective_date             IN   DATE,
8397 		  p_supervisor_id              IN   NUMBER,
8398 		  p_supervisor_assignment_id   IN   NUMBER DEFAULT NULL,
8399 		  p_commit_mode                IN   VARCHAR DEFAULT 'Y',
8400 		  p_sup_rollback_req_id        IN   NUMBER DEFAULT NULL
8401 	   )
8402 	   IS
8403 		  l_proc                VARCHAR2 (72) := g_package || 'admin_change_top_sup';
8404 
8405 		  CURSOR csr_current_population (p_plan_id IN NUMBER, p_effective_date IN DATE)
8406 		  IS
8407 			 SELECT pps.scorecard_id, pps.person_id, pps.assignment_id, NVL (pps.supervisor_id, paf.supervisor_id) supervisor_id,
8408 					NVL (pps.supervisor_assignment_id, paf.supervisor_assignment_id) supervisor_assignment_id,
8409 					pps.object_version_number, hr_general.decode_person_name (pps.person_id) worker_name
8410 			   FROM per_personal_scorecards pps, per_assignments_f paf
8411 			  WHERE pps.plan_id = p_plan_id
8412 				AND pps.assignment_id = paf.assignment_id
8413 				AND p_effective_date BETWEEN paf.effective_start_date AND paf.effective_end_date;
8414 
8415 	--   TYPE  t_curr_rec IS RECORD OF csr_current_population%ROWTYPE;
8416 		  TYPE t_curr_pop IS TABLE OF csr_current_population%ROWTYPE
8417 			 INDEX BY BINARY_INTEGER;
8418 
8419 		  l_curr_pop            t_curr_pop;
8420 
8421 		  --
8422 		  CURSOR csr_sup_hier_pop (p_effective_date IN DATE, p_supervisor_id IN NUMBER)
8423 		  IS
8424 			 SELECT     *
8425 				   FROM (SELECT asg.assignment_id, asg.person_id, asg.business_group_id, asg.supervisor_id,
8426 								asg.supervisor_assignment_id, asg.organization_id, asg.position_id
8427 						   FROM per_all_assignments_f asg
8428 						  WHERE (   (    g_plan_dtls (1).assignment_types_code IN ('E', 'C')
8429 									 AND asg.assignment_type = g_plan_dtls (1).assignment_types_code
8430 									)
8431 								 OR (g_plan_dtls (1).assignment_types_code = 'EC' AND asg.assignment_type IN ('E', 'C'))
8432 								)
8433 							AND p_effective_date BETWEEN asg.effective_start_date AND asg.effective_end_date
8434 							AND (   (g_plan_dtls (1).primary_asg_only_flag = 'N')
8435 								 OR g_plan_dtls (1).primary_asg_only_flag = 'Y' AND asg.primary_flag = 'Y'
8436 								)
8437 							AND 'x' =
8438 								   (SELECT 'x'
8439 									  FROM per_all_people_f ppf
8440 									 WHERE asg.person_id = ppf.person_id
8441 									   AND p_effective_date BETWEEN ppf.effective_start_date AND ppf.effective_end_date
8442 									   AND ('Y' =
8443 											   DECODE (g_plan_dtls (1).assignment_types_code,
8444 													   'E', ppf.current_employee_flag,
8445 													   'C', ppf.current_npw_flag,
8446 													   'EC', (SELECT 'Y'
8447 																FROM DUAL
8448 															   WHERE ppf.current_employee_flag = 'Y' OR ppf.current_npw_flag = 'Y')
8449 													  )
8450 										   ))) o
8451 			 CONNECT BY o.supervisor_id = PRIOR o.person_id AND LEVEL <= NVL (g_plan_dtls (1).hierarchy_levels, LEVEL) + 1
8452 			 START WITH o.person_id = p_supervisor_id;
8453 
8454 		  --  Supervisor Assignment Hierarchy  population
8455 		  -- Includes supervisor assignment and person assignments that are in not more than N level
8456 		  -- below in hierarchy, where N is the value specified in hierarchy level attribute of the plan
8457 		  --
8458 		  CURSOR csr_sup_asg_hier_pop (p_effective_date IN DATE, p_supervisor_assignment_id IN NUMBER)
8459 		  IS
8460 			 SELECT     *
8461 				   FROM (SELECT asg.assignment_id, asg.person_id, asg.business_group_id, asg.supervisor_id,
8462 								asg.supervisor_assignment_id, asg.organization_id, asg.position_id
8463 						   FROM per_all_assignments_f asg
8464 						  WHERE (   (    g_plan_dtls (1).assignment_types_code IN ('E', 'C')
8465 									 AND asg.assignment_type = g_plan_dtls (1).assignment_types_code
8466 									)
8467 								 OR (g_plan_dtls (1).assignment_types_code = 'EC' AND asg.assignment_type IN ('E', 'C'))
8468 								)
8469 							AND p_effective_date BETWEEN asg.effective_start_date AND asg.effective_end_date
8470 							AND 'x' =
8471 								   (SELECT 'x'
8472 									  FROM per_all_people_f ppf
8473 									 WHERE asg.person_id = ppf.person_id
8474 									   AND p_effective_date BETWEEN ppf.effective_start_date AND ppf.effective_end_date
8475 									   AND ('Y' =
8476 											   DECODE (g_plan_dtls (1).assignment_types_code,
8477 													   'E', ppf.current_employee_flag,
8478 													   'C', ppf.current_npw_flag,
8479 													   'EC', (SELECT 'Y'
8480 																FROM DUAL
8481 															   WHERE ppf.current_employee_flag = 'Y' OR ppf.current_npw_flag = 'Y')
8482 													  )
8483 										   ))) o
8484 			 CONNECT BY o.supervisor_assignment_id = PRIOR o.assignment_id
8485 						AND LEVEL <= NVL (g_plan_dtls (1).hierarchy_levels, LEVEL) + 1
8486 			 START WITH o.assignment_id = p_supervisor_assignment_id;
8487 
8488 		  l_temp_pop_tbl        t_curr_pop;
8489 		  l_temp_prop_pop_tbl   g_qual_pop_t;
8490 		  l_prop_pop_tbl        g_qual_pop_t;
8491 		  l_asg_index           NUMBER;
8492 	   BEGIN
8493 		  SAVEPOINT admin_change_top_sup;
8494 		  hr_utility.set_location ('Entering: ' || l_proc, 10);
8495 
8496 		  OPEN csr_current_population (p_plan_id, p_effective_date);
8497 
8498 		  FETCH csr_current_population
8499 		  BULK COLLECT INTO l_temp_pop_tbl;
8500 
8501 		  CLOSE csr_current_population;
8502 
8503 		  log_message ('current population:' || l_temp_pop_tbl.COUNT);
8504 
8505 		  IF l_temp_pop_tbl.COUNT > 0
8506 		  THEN
8507 			 FOR i IN l_temp_pop_tbl.FIRST .. l_temp_pop_tbl.LAST
8508 			 LOOP
8509 				--
8510 				l_curr_pop (l_temp_pop_tbl (i).assignment_id).scorecard_id := l_temp_pop_tbl (i).scorecard_id;
8511 				l_curr_pop (l_temp_pop_tbl (i).assignment_id).assignment_id := l_temp_pop_tbl (i).assignment_id;
8512 				l_curr_pop (l_temp_pop_tbl (i).assignment_id).person_id := l_temp_pop_tbl (i).person_id;
8513 				l_curr_pop (l_temp_pop_tbl (i).assignment_id).supervisor_id := l_temp_pop_tbl (i).supervisor_id;
8514 				l_curr_pop (l_temp_pop_tbl (i).assignment_id).supervisor_assignment_id := l_temp_pop_tbl (i).supervisor_assignment_id;
8515 			 --
8516 			 END LOOP;
8517 
8518 			 --
8519 			 l_temp_pop_tbl.DELETE;
8520 		  END IF;
8521 
8522 		  log_message ('g_plan_dtls(1).hierarchy_type_code:' || g_plan_dtls (1).hierarchy_type_code);
8523 
8524 		  IF g_plan_dtls (1).hierarchy_type_code = 'SUP'
8525 		  THEN
8526 			 OPEN csr_sup_hier_pop (p_effective_date, p_supervisor_id);
8527 
8528 			 FETCH csr_sup_hier_pop
8529 			 BULK COLLECT INTO l_temp_prop_pop_tbl;
8530 
8531 			 log_message ('Row count:' || csr_sup_hier_pop%ROWCOUNT);
8532 
8533 			 CLOSE csr_sup_hier_pop;
8534 		  ELSIF g_plan_dtls (1).hierarchy_type_code = 'SUP_ASG'
8535 		  THEN
8536 			 OPEN csr_sup_asg_hier_pop (p_effective_date, p_supervisor_id);
8537 
8538 			 FETCH csr_sup_asg_hier_pop
8539 			 BULK COLLECT INTO l_temp_prop_pop_tbl;
8540 
8541 			 log_message ('ASG Row count:' || csr_sup_hier_pop%ROWCOUNT);
8542 
8543 			 CLOSE csr_sup_asg_hier_pop;
8544 		  END IF;
8545 
8546 		  log_message ('current population post sup change: ' || l_temp_prop_pop_tbl.COUNT);
8547 		  log_message ('proposed population post sup change: ' || l_temp_prop_pop_tbl.COUNT);
8548 
8549 		  --
8550 		  IF l_temp_prop_pop_tbl.COUNT > 0
8551 		  THEN
8552 			 FOR i IN l_temp_prop_pop_tbl.FIRST .. l_temp_prop_pop_tbl.LAST
8553 			 LOOP
8554 				--
8555 				l_prop_pop_tbl (l_temp_prop_pop_tbl (i).assignment_id).assignment_id := l_temp_prop_pop_tbl (i).assignment_id;
8556 				l_prop_pop_tbl (l_temp_prop_pop_tbl (i).assignment_id).person_id := l_temp_prop_pop_tbl (i).person_id;
8557 				l_prop_pop_tbl (l_temp_prop_pop_tbl (i).assignment_id).business_group_id := l_temp_prop_pop_tbl (i).business_group_id;
8558 				l_prop_pop_tbl (l_temp_prop_pop_tbl (i).assignment_id).supervisor_id := l_temp_prop_pop_tbl (i).supervisor_id;
8559 				l_prop_pop_tbl (l_temp_prop_pop_tbl (i).assignment_id).supervisor_assignment_id :=
8560 																					 l_temp_prop_pop_tbl (i).supervisor_assignment_id;
8561 				l_prop_pop_tbl (l_temp_prop_pop_tbl (i).assignment_id).organization_id := l_temp_prop_pop_tbl (i).organization_id;
8562 				l_prop_pop_tbl (l_temp_prop_pop_tbl (i).assignment_id).position_id := l_temp_prop_pop_tbl (i).position_id;
8563 			 END LOOP;
8564 
8565 			 --
8566 			 l_temp_prop_pop_tbl.DELETE;
8567 		  END IF;
8568 
8569 		  l_asg_index := l_curr_pop.FIRST;
8570 
8571 	-- Now update the plan with new supervisor id
8572 		  IF g_plan_dtls (1).hierarchy_type_code = 'SUP'
8573 		  THEN
8574 			 UPDATE per_perf_mgmt_plans
8575 				SET supervisor_id = p_supervisor_id
8576 			  WHERE plan_id = p_plan_id;
8577 
8578 			 log_message ('Update plan sup to:' || p_supervisor_id);
8579 		  ELSIF g_plan_dtls (1).hierarchy_type_code = 'SUP_ASG'
8580 		  THEN
8581 			 UPDATE per_perf_mgmt_plans
8582 				SET supervisor_assignment_id = p_supervisor_assignment_id
8583 			  WHERE plan_id = p_plan_id;
8584 
8585 			 log_message ('Update plan supasg to:' || p_supervisor_assignment_id);
8586 		  END IF;
8587 
8588 		  g_plan_dtls (1).supervisor_id := p_supervisor_id;
8589 		  g_plan_dtls (1).supervisor_assignment_id := p_supervisor_assignment_id;
8590 
8591 		  IF g_qual_pop_tbl.COUNT = 0
8592 		  THEN
8593 			 populate_qual_plan_population (g_plan_dtls (1), p_effective_date);
8594 		  END IF;
8595 
8596 		  IF (g_plan_dtls (1).automatic_allocation_flag = 'Y')
8597 		  THEN
8598 			 populate_qual_objectives (g_plan_dtls (1).start_date, g_plan_dtls (1).end_date);
8599 		  END IF;
8600 
8601 		  IF (g_plan_dtls (1).include_appraisals_flag = 'Y')
8602 		  THEN
8603 			 populate_plan_apprsl_periods (g_plan_dtls (1).plan_id);
8604 		  END IF;
8605 
8606 		  hr_utility.set_location (l_proc || 'count:' || g_qual_pop_tbl.COUNT, 20);
8607 		  log_message ('COUNT OF PROP TABLE:' || l_prop_pop_tbl.COUNT);
8608 
8609 		  WHILE (l_asg_index IS NOT NULL)
8610 		  LOOP
8611 			 IF l_prop_pop_tbl.EXISTS (l_asg_index)
8612 			 THEN
8613 				log_message ('Assignment :' || l_asg_index || ' exists in the current and proposed hierarchy.');
8614 			 ELSE
8615 				log_message ('Assignment :' || l_asg_index || ' does not exists in the proposed hierarchy. Transferring out.');
8616 
8617 				UPDATE per_personal_scorecards
8618 				   SET status_code = 'TRANSFER_OUT'
8619 				 WHERE scorecard_id = l_curr_pop (l_asg_index).scorecard_id;
8620 
8621 				send_message_notification (p_person_id      => l_curr_pop (l_asg_index).person_id,
8622 										   p_message        => 'WPM_SC_REMOVE_MSG',
8623 										   p_plan_id        => p_plan_id,
8624 										   p_full_name      => l_curr_pop (l_asg_index).worker_name
8625 										  );
8626 			 END IF;
8627 
8628 			 l_asg_index := l_curr_pop.NEXT (l_asg_index);
8629 		  END LOOP;
8630 
8631 		  --
8632 		  l_asg_index := l_prop_pop_tbl.FIRST;
8633 
8634 		  WHILE (l_asg_index IS NOT NULL)
8635 		  LOOP
8636 			 IF l_curr_pop.EXISTS (l_asg_index)
8637 			 THEN
8638 				log_message ('Assignment 2 :' || l_asg_index || ' exists in the current and proposed hierarchy.');
8639 			 ELSE
8640 				log_message (   'Assignment 2 :'
8641 								  || l_asg_index
8642 								  || ' does not exists in the current hierarchy and exists in proposed. Enrolling.'
8643 								 );
8644 				enroll_a_person (p_plan_id             => p_plan_id,
8645 								 p_assignment_id       => l_prop_pop_tbl (l_asg_index).assignment_id,
8646 								 p_person_id           => l_prop_pop_tbl (l_asg_index).person_id,
8647 								 p_effective_date      => p_effective_date,
8648 								 p_pop_qual_objs       => 'N',
8649 								 p_pop_apprl_prds      => 'N'
8650 								);
8651 				send_message_notification (p_person_id      => l_prop_pop_tbl (l_asg_index).person_id,
8652 										   p_message        => 'WPM_AP_ENROLL_MSG',
8653 										   p_plan_id        => p_plan_id,
8654 										   p_full_name      => NULL
8655 										  );
8656 			 END IF;
8657 
8658 			 l_asg_index := l_prop_pop_tbl.NEXT (l_asg_index);
8659 		  END LOOP;
8660 
8661 		  --
8662 		  IF NVL (p_commit_mode, 'Y') = 'Y'
8663 		  THEN
8664 			 ROLLBACK TO admin_change_top_sup;
8665 		  ELSE
8666 			 COMMIT;
8667 		  END IF;
8668 
8669 		  hr_utility.set_location ('Entering: ' || l_proc, 90);
8670 	   END admin_change_top_sup;
8671 
8672 	   PROCEDURE copy_curr_objs (p_curr_sc_id IN NUMBER, p_target_sc_id IN NUMBER, p_target_appr_id IN NUMBER)
8673 	   IS
8674 		  l_proc                          VARCHAR2 (80) := g_package || 'copy_curr_objs';
8675 
8676 		  CURSOR csr_curr_objs (p_sc_id IN NUMBER)
8677 		  IS
8678 			 SELECT *
8679 			   FROM per_objectives
8680 			  WHERE scorecard_id = p_sc_id;
8681 
8682 
8683 		  l_objective_id                  NUMBER;
8684 		  l_target_appr_id                NUMBER;
8685 		  l_exists                        VARCHAR2(1);
8686 	--
8687 	-- Variables for IN/OUT parameters
8688 		  l_weighting_over_100_warning    BOOLEAN;
8689 		  l_weighting_appraisal_warning   BOOLEAN;
8690 		  l_object_version_number         NUMBER;
8691 	   BEGIN
8692 		  hr_utility.set_location ('Entering: ' || l_proc, 10);
8693 
8694 		  FOR i IN csr_curr_objs (p_curr_sc_id)
8695 		  LOOP
8696 			 BEGIN
8697 			   l_exists := 'N';
8698 			   SELECT 'Y'
8699 			   INTO   l_exists
8700 			   FROM DUAL
8701 			   WHERE EXISTS (Select 'x'
8702 							 FROM   per_objectives
8703 							 WHERE  scorecard_id = p_target_sc_id
8704 							 AND    (copied_from_library_id = i.copied_from_library_id
8705 							 OR copied_from_objective_id = i.objective_id));
8706 			 EXCEPTION
8707 			   WHEN NO_DATA_FOUND THEN
8708 				  log_message('Objective '||i.objective_id||' not present in target scorecard:'||p_target_sc_id);
8709 				  l_exists := 'N';
8710 			   WHEN OTHERS THEN
8711 				  l_exists := NULL;
8712 			 END;
8713 			 --
8714 			 -- Call API to create objective in target SC/Appraisal.
8715 			 --
8716 			 IF i.appraise_flag = 'Y'
8717 			 THEN
8718 				l_target_appr_id := p_target_appr_id;
8719 			 ELSE
8720 				l_target_appr_id := NULL;
8721 			 END IF;
8722 			 IF NVL(l_exists,'N') = 'N' THEN
8723 			   hr_objectives_api.create_objective (p_validate                         => FALSE,
8724 												 p_effective_date                   => TRUNC (SYSDATE),
8725 												 p_business_group_id                => i.business_group_id,
8726 												 p_name                             => i.NAME,
8727 												 p_start_date                       => i.start_date,
8728 												 p_target_date                      => i.target_date,
8729 												 p_owning_person_id                 => i.owning_person_id,
8730 												 p_achievement_date                 => i.achievement_date,
8731 												 p_detail                           => i.detail,
8732 												 p_comments                         => i.comments,
8733 												 p_success_criteria                 => i.success_criteria,
8734 												 p_attribute_category               => i.attribute_category,
8735 												 p_attribute1                       => i.attribute1,
8736 												 p_attribute2                       => i.attribute2,
8737 												 p_attribute3                       => i.attribute3,
8738 												 p_attribute4                       => i.attribute4,
8739 												 p_attribute5                       => i.attribute5,
8740 												 p_attribute6                       => i.attribute6,
8741 												 p_attribute7                       => i.attribute7,
8742 												 p_attribute8                       => i.attribute8,
8743 												 p_attribute9                       => i.attribute9,
8744 												 p_attribute10                      => i.attribute10,
8745 												 p_attribute11                      => i.attribute11,
8746 												 p_attribute12                      => i.attribute12,
8747 												 p_attribute13                      => i.attribute13,
8748 												 p_attribute14                      => i.attribute14,
8749 												 p_attribute15                      => i.attribute15,
8750 												 p_attribute16                      => i.attribute16,
8751 												 p_attribute17                      => i.attribute17,
8752 												 p_attribute18                      => i.attribute18,
8753 												 p_attribute19                      => i.attribute19,
8754 												 p_attribute20                      => i.attribute20,
8755 												 p_attribute21                      => i.attribute21,
8756 												 p_attribute22                      => i.attribute22,
8757 												 p_attribute23                      => i.attribute23,
8758 												 p_attribute24                      => i.attribute24,
8759 												 p_attribute25                      => i.attribute25,
8760 												 p_attribute26                      => i.attribute26,
8761 												 p_attribute27                      => i.attribute27,
8762 												 p_attribute28                      => i.attribute28,
8763 												 p_attribute29                      => i.attribute29,
8764 												 p_attribute30                      => i.attribute30,
8765 												 p_scorecard_id                     => p_target_sc_id,
8766 												 p_appraisal_id                     => l_target_appr_id,
8767 												 p_copied_from_library_id           => i.copied_from_library_id,
8768 												 p_copied_from_objective_id         => i.objective_id,
8769 												 --point to the current objective
8770 												 p_aligned_with_objective_id        => i.aligned_with_objective_id,
8771 												 p_next_review_date                 => i.next_review_date,
8772 												 p_group_code                       => i.group_code,
8773 												 p_priority_code                    => i.priority_code,
8774 												 p_appraise_flag                    => i.appraise_flag,
8775 												 p_verified_flag                    => i.verified_flag,
8776 												 p_target_value                     => i.target_value,
8777 												 p_weighting_percent                => i.weighting_percent,
8778 												 p_complete_percent                 => i.complete_percent,
8779 												 p_uom_code                         => i.uom_code,
8780 												 p_measurement_style_code           => i.measurement_style_code,
8781 												 p_measure_name                     => i.measure_name,
8782 												 p_measure_type_code                => i.measure_type_code,
8783 												 p_measure_comments                 => i.measure_comments,
8784 												 p_sharing_access_code              => i.sharing_access_code,
8785 												 p_weighting_over_100_warning       => l_weighting_over_100_warning,
8786 												 p_weighting_appraisal_warning      => l_weighting_appraisal_warning,
8787 												 p_objective_id                     => l_objective_id,
8788 												 p_object_version_number            => l_object_version_number
8789 												);
8790 			  END IF;
8791 
8792 			 --
8793 			 -- Convert API warning boolean parameter values to specific
8794 			 -- messages and add them to Multiple Message List
8795 			 --
8796 			 IF l_weighting_over_100_warning
8797 			 THEN
8798 				fnd_message.set_name ('PER', 'HR_50198_WPM_WEIGHT_WARN');
8799 				hr_multi_message.ADD (p_message_type => hr_multi_message.g_warning_msg);
8800 			 END IF;
8801 
8802 			 IF l_weighting_appraisal_warning
8803 			 THEN
8804 				fnd_message.set_name ('PER', 'HR_50223_WPM_APPRAISE_WARN');
8805 				hr_multi_message.ADD (p_message_type => hr_multi_message.g_warning_msg);
8806 			 END IF;
8807 		  END LOOP;
8808 
8809 		  hr_utility.set_location ('Leaving: ' || l_proc, 100);
8810 	   END copy_curr_objs;
8811 
8812 	   PROCEDURE transfer_sc (p_plan_id IN NUMBER, p_effective_date IN DATE, p_enroll_appr IN VARCHAR2, p_copy_curr_obj IN VARCHAR2)
8813 	   IS
8814 		  l_proc               VARCHAR2 (80)         := g_package || 'transfer_sc';
8815 
8816 		  CURSOR csr_chk_appr_in_progress (p_scorecard_id IN NUMBER, p_eff_date IN DATE)
8817 		  IS
8818 			 SELECT 'Y'
8819 			   FROM DUAL
8820 			  WHERE EXISTS (
8821 					   SELECT 'x'
8822 						 FROM per_personal_scorecards sc, per_perf_mgmt_plans pl, per_appraisal_periods ap
8823 						WHERE sc.scorecard_id = p_scorecard_id
8824 						  AND sc.plan_id = pl.plan_id
8825 						  AND pl.plan_id = ap.plan_id
8826 						  AND p_eff_date BETWEEN ap.task_start_date AND ap.task_end_date);
8827 
8828 		  l_appr_in_progress   VARCHAR2 (1);
8829 		  l_sc_status_code     VARCHAR2 (30);
8830 
8831 		  CURSOR csr_sc_dtls (p_sc_id IN NUMBER)
8832 		  IS
8833 			 SELECT *
8834 			   FROM per_personal_scorecards
8835 			  WHERE scorecard_id = p_sc_id;
8836 
8837 		  l_sc_rec             csr_sc_dtls%ROWTYPE;
8838 
8839 	  --bug14046867  ... cursor for target supervisor_id and person full name.
8840 		  CURSOR csr_target_sup ( l_target_sc_id IN NUMBER)
8841 		  IS
8842 			 SELECT supervisor_id
8843 			   FROM per_personal_scorecards
8844 			  WHERE scorecard_id =  l_target_sc_id;
8845 
8846 		   l_target_sup_id NUMBER;
8847 
8848 		   CURSOR csr_person_full_name (p_sc_id IN NUMBER)
8849 		   IS
8850 		   SELECT hr_person_name.get_list_name(ppf.global_name, ppf.local_name) full_name
8851 			 FROM  per_all_people_f ppf, per_personal_scorecards pps
8852 			 WHERE ppf.person_id = pps.person_id
8853 		 AND   pps.scorecard_id = p_sc_id
8854 		 AND TRUNC(SYSDATE) between ppf.effective_start_date and ppf.effective_end_date;
8855 
8856 			person_full_name VARCHAR(200);
8857 		  --bug14046867
8858 		  CURSOR csr_target_sc (p_assignment_id IN NUMBER, p_plan_id IN NUMBER)
8859 		  IS
8860 			 SELECT scorecard_id
8861 			   FROM per_personal_scorecards
8862 			  WHERE plan_id = p_plan_id AND assignment_id = p_assignment_id;
8863 
8864 		  l_target_sc_id       NUMBER;
8865 
8866 		  CURSOR csr_target_appr (p_plan_id IN NUMBER, p_person_id IN NUMBER)
8867 		  IS
8868 			 SELECT appraisal_id
8869 			   FROM per_appraisals
8870 			  WHERE plan_id = p_plan_id AND appraisee_person_id = p_person_id;
8871 
8872 		  l_target_appr_id     NUMBER (15);
8873 		  CURSOR csr_find_appr_for_scorecard (
8874 			 p_plan_id        per_appraisals.plan_id%TYPE,
8875 			 p_scorecard_id   per_personal_scorecards.scorecard_id%TYPE
8876 		  )
8877 		  IS
8878 			 SELECT pa.appraisal_id, pa.object_version_number, pa.appraisal_system_status
8879 			   FROM per_appraisals pa, per_personal_scorecards pps
8880 			  WHERE pa.plan_id = p_plan_id AND appraisee_person_id = pps.person_id AND pps.scorecard_id = p_scorecard_id;
8881 	  -- Cursor to get the  Participants of an appraisal other than MA
8882 		  CURSOR csr_get_appr_part (p_appraisal_id per_appraisals.appraisal_id%TYPE)
8883 		  IS
8884 			 SELECT participant_id, object_version_number, participation_type
8885 			   FROM per_participants
8886 			  WHERE participation_in_id = p_appraisal_id
8887 				AND participation_in_table = 'PER_APPRAISALS'
8888 				AND participation_in_column = 'APPRAISAL_ID'
8889 				AND participation_type <> 'MAINAP'
8890 				AND participation_status = 'OPEN';
8891 			CURSOR csr_chek_appr_exist (p_plan_id IN NUMBER) IS
8892 			 SELECT 'Y'
8893 			 FROM  dual
8894 			 WHERE EXISTS (SELECT 'X'
8895 						   FROM    per_appraisals
8896 						   WHERE   plan_id = p_plan_id
8897 						   AND     appraisal_system_status <> 'DELETED');
8898 
8899 		  l_dummy                   BOOLEAN;
8900 		  l_appr_ovn                per_appraisals.object_version_number%TYPE;
8901 		  l_appr_id                 per_appraisals.appraisal_id%TYPE;
8902 		  l_appr_sys_status         per_appraisals.appraisal_system_status%TYPE;
8903 		  l_appraiser_person_id     per_appraisals.appraiser_person_id%TYPE;
8904 		 --bug14046867
8905 		  l_person_id   per_personal_scorecards.person_id%TYPE;
8906 		  l_src_supervisor_id per_personal_scorecards.supervisor_id%TYPE;
8907 		l_tgt_supervisor_id per_personal_scorecards.supervisor_id%TYPE;
8908 		 --bug14046867
8909 
8910 	   BEGIN
8911 		  hr_utility.set_location ('Entering:' || l_proc, 10);
8912 
8913 
8914 		  --hr_utility.set_location ('Entering:' || l_proc, 11);
8915 
8916 		  IF g_qual_pop_tbl.COUNT = 0
8917 		  THEN
8918 			 populate_qual_plan_population (g_plan_dtls (1), p_effective_date);
8919 		  END IF;
8920 
8921 		  IF (g_plan_dtls (1).automatic_allocation_flag = 'Y')
8922 		  THEN
8923 			 populate_qual_objectives (g_plan_dtls (1).start_date, g_plan_dtls (1).end_date);
8924 		  END IF;
8925 
8926 		  FOR i IN g_selected_entities.FIRST .. g_selected_entities.LAST
8927 		  LOOP
8928 			 BEGIN
8929 				g_target_sc_id := -1;
8930 				l_target_sc_id := NULL;
8931 				l_target_appr_id := NULL;
8932 
8933 				IF i = 1
8934 				THEN
8935 				   OPEN csr_chk_appr_in_progress (g_selected_entities (i), p_effective_date);
8936 
8937 				   FETCH csr_chk_appr_in_progress
8938 					INTO l_appr_in_progress;
8939 
8940 				   CLOSE csr_chk_appr_in_progress;
8941 
8942 				   IF l_appr_in_progress = 'Y'
8943 				   THEN
8944 					  l_sc_status_code := 'PUBLISHED';
8945 				   ELSE
8946 					  IF g_plan_dtls (1).method_code = 'CAS'
8947 					  THEN
8948 						 l_sc_status_code := 'NOT_STARTED_WITH_MGR';
8949 					  ELSE
8950 						 l_sc_status_code := 'NOT_STARTED_WITH_WKR';
8951 					  END IF;
8952 				   END IF;                                                                                         -- appr in progress
8953 				END IF;                                                                                                         -- i=1
8954 				IF p_enroll_appr = 'Y'
8955 				THEN
8956 				   OPEN csr_chek_appr_exist(p_plan_id);
8957 				   FETCH csr_chek_appr_exist INTO g_appraisals_exist;
8958 				   CLOSE csr_chek_appr_exist;
8959 				END IF;
8960 				OPEN csr_sc_dtls (g_selected_entities (i));
8961 
8962 				FETCH csr_sc_dtls
8963 				 INTO l_sc_rec;
8964 
8965 			--bug14046867
8966 
8967 			 g_src_plan_id := l_sc_rec.plan_id;   --assigning source plan id into the global variable.
8968 					OPEN csr_person_full_name (g_selected_entities (i));
8969 
8970 				FETCH csr_person_full_name
8971 				 INTO person_full_name;
8972 
8973 						CLOSE csr_person_full_name;
8974 				 --bug14046867
8975 
8976 				IF csr_sc_dtls%NOTFOUND
8977 				THEN
8978 				   log_message ('Invalid Scorecard: ' || g_selected_entities (i) || '.Cannot Transfer.');
8979 				   RETURN;
8980 				ELSE
8981 				   OPEN csr_target_sc (l_sc_rec.assignment_id, p_plan_id);
8982 
8983 				   FETCH csr_target_sc
8984 					INTO l_target_sc_id;
8985 
8986 				   CLOSE csr_target_sc;
8987 
8988 				   IF l_target_sc_id IS NULL
8989 				   THEN
8990 					IF NOT g_qual_pop_tbl.EXISTS(l_sc_rec.assignment_id) THEN
8991 						 log_message('Selected Assignment:'||l_sc_rec.assignment_id||' doesn''t qualify for the target plan. Cannot Transfer.' );
8992 					 ELSE
8993 					 -- not already enrolled in the target plan
8994 					  enroll_a_person (p_plan_id             => p_plan_id,
8995 									   p_assignment_id       => l_sc_rec.assignment_id,
8996 									   p_person_id           => l_sc_rec.person_id,
8997 									   p_effective_date      => p_effective_date,
8998 									   p_pop_qual_objs       => 'N',
8999 									   p_pop_apprl_prds      => 'Y',
9000 									   p_sc_status_code      => l_sc_status_code,
9001 									   p_enroll_appr         => p_enroll_appr
9002 									  );
9003 						  log_message ('New Scorecard :' || g_target_sc_id || ' created for target plan: '
9004 										|| g_plan_dtls (1).plan_name
9005 									   );
9006 					  l_target_sc_id := g_target_sc_id;
9007 					 END IF;
9008 				   END IF;
9009 					--bug14046867 taking target supervisor_id
9010 
9011 						   OPEN csr_target_sup (l_target_sc_id);
9012 
9013 							   FETCH csr_target_sup
9014 					 INTO l_target_sup_id;
9015 
9016 						   CLOSE csr_target_sup;
9017 					 --bug14046867
9018 				   IF p_enroll_appr = 'Y'
9019 				   THEN
9020 					  OPEN csr_target_appr (p_plan_id, l_sc_rec.person_id);
9021 
9022 					  FETCH csr_target_appr
9023 					   INTO l_target_appr_id;
9024 
9025 						  log_message ('New Appr ID: ' || l_target_appr_id);
9026 
9027 					  CLOSE csr_target_appr;
9028 				   END IF;
9029 
9030 				   IF NVL (p_copy_curr_obj, 'Y') = 'Y'
9031 				   THEN
9032 					  copy_curr_objs (p_curr_sc_id          => l_sc_rec.scorecard_id,
9033 									  p_target_sc_id        => l_target_sc_id,
9034 									  p_target_appr_id      => l_target_appr_id
9035 									 );
9036 				   END IF;
9037 				END IF;
9038 
9039 				CLOSE csr_sc_dtls;
9040 				IF l_target_sc_id IS NOT NULL THEN -- transfer out only if the scorecard is correctly transferred to TARGET PLAN
9041 				-- Now update the current scorecard and appraisals (if any) to TRANSFER_OUT
9042 				--
9043 				  --- delete the appraisals for the person
9044 				   IF (g_plan_dtls (1).include_appraisals_flag = 'Y')
9045 				   THEN
9046 					  --  FOR plan_appraisals IN csr_plan_appraisals(p_plan_id)
9047 					  OPEN csr_find_appr_for_scorecard (l_sc_rec.plan_id, l_sc_rec.scorecard_id);
9048 
9049 					  LOOP
9050 						 hr_utility.set_location ('Before transfer out _for_person', 107);
9051 
9052 						 FETCH csr_find_appr_for_scorecard
9053 						  INTO l_appr_id, l_appr_ovn, l_appr_sys_status;
9054 
9055 						 EXIT WHEN csr_find_appr_for_scorecard%NOTFOUND;
9056 
9057 						 IF l_appr_sys_status NOT IN ('COMPLETED','APPRFEEDBACK')
9058 						 THEN
9059 							UPDATE per_appraisals
9060 							   SET appraisal_system_status = 'TRANSFER_OUT'
9061 							 WHERE appraisal_id = l_appr_id;
9062 
9063 	-- revoke the participant statuses and close them.NOt deleting them if feedback is already provided.
9064 							FOR i IN csr_get_appr_part (l_appr_id)
9065 							LOOP
9066 							   UPDATE per_participants
9067 								  SET participation_status = 'CLOSED'
9068 								WHERE participant_id = i.participant_id;
9069 							END LOOP;
9070 	-- we are doing a direct update as update API will not work for terminated and traansfer employees
9071 	-- update it to transfer out so as to not show the details anywhere
9072 						 END IF;
9073 
9074 						 hr_utility.set_location ('After transfer out appraisal_for_person appraisal_id: ' || l_appr_id, 107);
9075 					  END LOOP;
9076 
9077 					  CLOSE csr_find_appr_for_scorecard;
9078 				   END IF;-- end include appr
9079 				   hr_personal_scorecard_api.update_scorecard
9080 											 (p_effective_date              => TRUNC (SYSDATE),
9081 											  p_scorecard_id                =>l_sc_rec.scorecard_id,
9082 											  p_object_version_number       => l_sc_rec.object_version_number,
9083 											  p_duplicate_name_warning      => l_dummy,
9084 											  p_status_code                 => 'TRANSFER_OUT'
9085 											 );
9086 				 END IF; --- check l_target_sc_id IS NOT NULL
9087 
9088 			--bug14046867
9089 
9090 		  l_person_id := l_sc_rec.person_id;
9091 		  l_src_supervisor_id := l_sc_rec.supervisor_id;
9092 		  l_tgt_supervisor_id := l_target_sup_id ;
9093 
9094 
9095 
9096 
9097 				IF ( p_enroll_appr = 'N' AND p_copy_curr_obj = 'Y')   --only transfering score card
9098 				THEN
9099 				 send_message_notification (l_person_id, 'WPM_SC_TRNF_WITH_OBJ_WKR', p_plan_id, NULL);
9100 				 send_message_notification (l_src_supervisor_id, 'WPM_SC_TRNF_WITH_OBJ_MGR', p_plan_id, person_full_name);
9101 				   send_message_notification (l_tgt_supervisor_id, 'WPM_SC_TRNF_WITH_OBJ_MGR', p_plan_id, person_full_name);
9102 
9103 			  ELSIF ( p_enroll_appr = 'Y' AND p_copy_curr_obj = 'Y')   --transfering score card and appraisal
9104 				THEN
9105 				 send_message_notification (l_person_id, 'WPM_SC_TRNF_WITH_APPR_WKR', p_plan_id, NULL);
9106 				 send_message_notification (l_src_supervisor_id, 'WPM_SC_TRNF_WITH_APPR_MGR', p_plan_id, person_full_name);
9107 				 send_message_notification (l_tgt_supervisor_id, 'WPM_SC_TRNF_WITH_OBJ_MGR', p_plan_id, person_full_name);
9108 
9109 			  ELSIF ( p_enroll_appr = 'N' AND p_copy_curr_obj = 'N')   --transfering only worker
9110 				THEN
9111 				 send_message_notification (l_person_id, 'WPM_SC_TRNF_ONLY_WKR', p_plan_id, NULL);
9112 				 send_message_notification (l_src_supervisor_id, 'WPM_SC_TRNF_ONLY_MGR', p_plan_id, person_full_name);
9113 				   send_message_notification (l_tgt_supervisor_id, 'WPM_SC_TRNF_WITH_OBJ_MGR', p_plan_id, person_full_name);
9114 				 --bug14046867
9115 			  END IF;
9116 
9117 
9118 			 EXCEPTION
9119 				WHEN OTHERS
9120 				THEN
9121 				   log_message ('Error while transferring scorecard: ' || g_selected_entities (i));
9122 				   log_message (SQLERRM);
9123 			 END;
9124 		  END LOOP;
9125 
9126 
9127 		  hr_utility.set_location ('Leaving:' || l_proc, 100);
9128 	   END transfer_sc;
9129 
9130 	   PROCEDURE admin_transfer_scorecard (p_plan_id NUMBER, p_effective_date DATE, p_sub_taskcode VARCHAR2)
9131 	   IS
9132 		  l_proc   VARCHAR2 (80) := g_package || 'admin_transfer_scorecard';
9133 	   BEGIN
9134 		  hr_utility.set_location ('Entering:' || l_proc, 10);
9135 		  log_message ('Dest Plan: ' || g_plan_dtls (1).plan_name);
9136 		  log_message (   'Dest Plan: Obj Setting:'
9137 							|| TO_CHAR (g_plan_dtls (1).obj_setting_start_date, 'dd-mm-yyyy')
9138 							|| '<->'
9139 							|| TO_CHAR (g_plan_dtls (1).obj_setting_deadline, 'dd-mm-yyyy')
9140 						   );
9141 
9142 		  IF p_sub_taskcode IS NULL
9143 		  THEN
9144 			 hr_api.mandatory_arg_error (p_api_name            => 'ADMIN_TRANSFER_SCORECARD',
9145 										 p_argument            => 'P_SUB_TASKCODE',
9146 										 p_argument_value      => p_sub_taskcode
9147 										);
9148 		  END IF;
9149 
9150 		  IF hr_api.not_exists_in_hr_lookups (p_effective_date      => p_effective_date,
9151 											  p_lookup_type         => 'PER_PMP_TRNF_ACTIONS',
9152 											  p_lookup_code         => p_sub_taskcode
9153 											 )
9154 		  THEN
9155 			 log_message ('Invalid Sub task code selected for transfer action:' || p_sub_taskcode);
9156 			 hr_utility.set_message (800, 'HR_WPM_TASK_CODE_NOT_EXISTS');
9157 			 hr_utility.raise_error;
9158 		  END IF;
9159 
9160 		  IF g_plan_dtls (1).status_code <> 'PUBLISHED'
9161 		  THEN
9162 			 log_message ('Destination Plan is not Published. Cannot transfer scorecards to that plan. RETURNING..');
9163 			 RETURN;
9164 		  END IF;
9165 
9166 		  IF p_sub_taskcode = 'TRNF_SC'
9167 		  THEN
9168 			 transfer_sc (p_plan_id             => p_plan_id, p_effective_date => p_effective_date, p_enroll_appr => 'N',
9169 						  p_copy_curr_obj       => 'Y');
9170 		  ELSIF p_sub_taskcode = 'TRNF_SC_APPR'
9171 		  THEN
9172 			 transfer_sc (p_plan_id             => p_plan_id, p_effective_date => p_effective_date, p_enroll_appr => 'Y',
9173 						  p_copy_curr_obj       => 'Y');
9174 		  ELSIF p_sub_taskcode = 'TRNF_WKR'
9175 		  THEN
9176 			 transfer_sc (p_plan_id             => p_plan_id, p_effective_date => p_effective_date, p_enroll_appr => 'N',
9177 						  p_copy_curr_obj       => 'N');
9178 		  END IF;
9179 
9180 		  hr_utility.set_location ('Leaving:' || l_proc, 100);
9181 	   END;
9182 
9183 	--
9184 	--
9185 	   PROCEDURE plan_admin_actions (
9186 		  errbuf                     OUT NOCOPY      VARCHAR2,
9187 		  retcode                    OUT NOCOPY      NUMBER,
9188 		  p_effective_date           IN              VARCHAR2,
9189 		  p_plan_id                  IN              NUMBER,
9190 		  p_selected_entities_list   IN              VARCHAR2,
9191 		  p_task_code                IN              VARCHAR2
9192 	   )
9193 	   IS
9194 		  l_proc             VARCHAR2 (72) := g_package || 'plan_admin_actions';
9195 		  l_person_count     NUMBER;
9196 
9197 		  CURSOR csr_plan_dtls (p_plan_id IN NUMBER)
9198 		  IS
9199 			 SELECT *
9200 			   FROM per_perf_mgmt_plans
9201 			  WHERE plan_id = p_plan_id;
9202 
9203 		  l_effective_date   DATE;
9204 		  l_sup_rollback_req_id        NUMBER;
9205 		  l_supervisor_id              NUMBER;
9206 		  l_supervisor_assignment_id   NUMBER;
9207 		  l_commit_mode                VARCHAR2 (2)  := 'N';
9208 		  l_task_code                  VARCHAR2 (30);
9209 		  l_sub_taskcode               VARCHAR2 (30);
9210 	   BEGIN
9211 		  --
9212 		  hr_utility.set_location ('Entering ' || l_proc, 10);
9213 		  g_plan_dtls.DELETE;
9214 
9215 		  OPEN csr_plan_dtls (p_plan_id);
9216 
9217 		  FETCH csr_plan_dtls
9218 		   INTO g_plan_dtls (1);
9219 
9220 		  CLOSE csr_plan_dtls;
9221 
9222 		  g_num_errors := 0;
9223 
9224 		  --
9225 		  IF p_plan_id IS NULL
9226 		  THEN
9227 			 hr_api.mandatory_arg_error (p_api_name            => 'PLAN_ADMIN_ACTIONS_CP',
9228 										 p_argument            => 'P_PLAN_ID',
9229 										 p_argument_value      => p_plan_id
9230 										);
9231 		  END IF;
9232 
9233 		  IF p_effective_date IS NULL
9234 		  THEN
9235 			 hr_api.mandatory_arg_error (p_api_name            => 'PLAN_ADMIN_ACTIONS_CP',
9236 										 p_argument            => 'P_EFFECTIVE_DATE',
9237 										 p_argument_value      => p_effective_date
9238 										);
9239 		  END IF;
9240 
9241 		  IF p_selected_entities_list IS NULL
9242 		  THEN
9243 			 hr_api.mandatory_arg_error (p_api_name            => 'PLAN_ADMIN_ACTIONS_CP',
9244 										 p_argument            => 'P_SELECTED_ENTITIES_LIST',
9245 										 p_argument_value      => p_selected_entities_list
9246 										);
9247 		  END IF;
9248 
9249 		  IF p_task_code IS NULL
9250 		  THEN
9251 			 hr_api.mandatory_arg_error (p_api_name            => 'PLAN_ADMIN_ACTIONS_CP',
9252 										 p_argument            => 'P_TASK_CODE',
9253 										 p_argument_value      => p_task_code
9254 										);
9255 		  END IF;
9256 
9257 		  l_effective_date := fnd_date.canonical_to_date (p_effective_date);
9258 		  log_message ('after effective date');
9259 		  IF INSTR(p_task_code,'-') > 0 THEN
9260 			l_task_code := SUBSTR (p_task_code, 1, INSTR (p_task_code, '-') - 1);
9261 			l_sub_taskcode := SUBSTR (p_task_code, INSTR (p_task_code, '-') + 1);
9262 		  ELSE
9263 			l_task_code := p_task_code;
9264 		  END IF;
9265 		  log_message('l_task_code:'||l_task_code);
9266 		  log_message('l_sub_taskcode:'||l_sub_taskcode);
9267 
9268 		  IF hr_api.not_exists_in_hr_lookups (p_effective_date      => l_effective_date,
9269 											  p_lookup_type         => 'HR_WPM_ADMIN_ACTIONS',
9270 											  p_lookup_code         => l_task_code
9271 											 )
9272 		  THEN
9273 			 log_message ('Invalid task code selected.' || l_task_code);
9274 			 hr_utility.set_message (800, 'HR_WPM_TASK_CODE_NOT_EXISTS');
9275 			 hr_utility.raise_error;
9276 		  END IF;
9277 
9278 		  IF p_task_code = 'CHANGE_TOP_SUPERVISOR'
9279 		  THEN
9280 			 IF g_plan_dtls (1).hierarchy_type_code = 'SUP'
9281 			 THEN
9282 				l_supervisor_id := SUBSTR (p_selected_entities_list, 1, INSTR (p_selected_entities_list, ',') - 1);
9283 				log_message ('New supervisor id: ' || l_supervisor_id);
9284 				log_message ('new supervsior_id is: ' || l_supervisor_id);
9285 			 ELSIF g_plan_dtls (1).hierarchy_type_code = 'SUP_ASG'
9286 			 THEN
9287 				l_supervisor_assignment_id := SUBSTR (p_selected_entities_list, 1, INSTR (p_selected_entities_list, ',') - 1);
9288 				log_message ('new supervsior_assignment_id is: ' || l_supervisor_assignment_id);
9289 			 END IF;
9290 
9291 			 l_commit_mode := SUBSTR (p_selected_entities_list, INSTR (p_selected_entities_list, ',') + 1, 1);
9292 			 log_message ('Commit:' || l_commit_mode);
9293 
9294 			 IF l_commit_mode = 'N'
9295 			 THEN
9296 				l_sup_rollback_req_id := SUBSTR (p_selected_entities_list, INSTR (p_selected_entities_list, ',', 1, 2) + 1);
9297 			 END IF;
9298 		  ELSE
9299 		  l_person_count := string_to_array (p_selected_entities_list => p_selected_entities_list);
9300 		  log_message ('Number of selected persons: ' || l_person_count);
9301 		  END IF;
9302 
9303 		  IF l_task_code = 'ENROLL_PLAN'
9304 		  THEN
9305 			 admin_enroll_into_plan (p_plan_id => p_plan_id, p_effective_date => l_effective_date);
9306 		  ELSIF l_task_code = 'REOPEN_APPRAISALS'
9307 		  THEN
9308 			 admin_reopen_plan_appraisals (p_plan_id => p_plan_id, p_effective_date => l_effective_date);
9309 		  ELSIF l_task_code = 'REMOVE_SC'
9310 		  THEN
9311 			 admin_remove_scorecard (p_plan_id => p_plan_id, p_effective_date => l_effective_date);
9312 		  ELSIF l_task_code = 'REOPEN_SC'
9313 		  THEN
9314 			 admin_reopen_scorecard (p_plan_id => p_plan_id, p_effective_date => l_effective_date);
9315 		  ELSIF l_task_code = 'REFRESH_SC'
9316 		  THEN
9317 			 admin_refresh_scorecard (p_plan_id => p_plan_id, p_effective_date => l_effective_date);
9318 		  ELSIF l_task_code = 'CHANGE_TOP_SUPERVISOR'
9319 		  THEN
9320 			 admin_change_top_sup (p_plan_id                       => p_plan_id,
9321 								   p_effective_date                => l_effective_date,
9322 								   p_supervisor_id                 => l_supervisor_id,
9323 								   p_supervisor_assignment_id      => l_supervisor_assignment_id,
9324 								   p_commit_mode                   => l_commit_mode,
9325 								   p_sup_rollback_req_id           => l_sup_rollback_req_id
9326 								  );
9327 		  ELSIF l_task_code = 'TRANSFER_OBJ'
9328 		  THEN
9329 			 admin_transfer_scorecard (p_plan_id             => p_plan_id, p_effective_date => l_effective_date,
9330 									   p_sub_taskcode        => l_sub_taskcode);
9331 		  ELSE
9332 			 log_message ('Invalid task code selected.' || l_task_code);
9333 			 hr_utility.set_message (800, 'HR_WPM_TASK_CODE_NOT_VALID');
9334 			 hr_utility.raise_error;
9335 		  END IF;
9336 
9337 		  --
9338 		  --
9339 		  COMMIT;
9340 
9341 		  IF g_num_errors > 0
9342 		  THEN
9343 			 log_message ('No. of persons errored: ' || g_num_errors);
9344 			 retcode := warning;
9345 			 errbuf := 'Errors occured processing the selected persons. Pl. check the
9346 	concurrent log for details.';
9347 		  END IF;
9348 
9349 		  hr_utility.set_location ('Leaving ' || l_proc, 100);
9350 	   EXCEPTION
9351 		  WHEN OTHERS
9352 		  THEN
9353 			 log_message ('Error Completing the process.');
9354 			 errbuf := SQLERRM;
9355 			 retcode := error;
9356 			 ROLLBACK;
9357 			 RAISE;
9358 	   END plan_admin_actions;
9359 
9360 	--
9361 	   PROCEDURE send_message_notification (
9362 		  p_person_id   IN   NUMBER,
9363 		  p_message          VARCHAR2,
9364 		  p_plan_id          per_perf_mgmt_plans.plan_id%TYPE DEFAULT NULL,
9365 		  p_full_name        per_all_people_f.full_name%TYPE
9366 	   )
9367 	   IS
9368 		  CURSOR get_role (person_id per_all_people_f.person_id%TYPE)
9369 		  IS
9370 			 SELECT wf.NAME role_name
9371 			   FROM wf_roles wf
9372 			  WHERE wf.orig_system = 'PER' AND wf.orig_system_id = person_id;
9373 
9374 		  CURSOR csr_plan_det (p_plan_id per_perf_mgmt_plans.plan_id%TYPE)
9375 		  IS
9376 			 SELECT plan_name, administrator_person_id
9377 			   FROM per_perf_mgmt_plans
9378 			  WHERE plan_id = p_plan_id;
9379 
9380 		  CURSOR csr_full_name
9381 		  IS
9382 			 SELECT full_name
9383 			   FROM per_all_people_f
9384 			  WHERE person_id = p_person_id AND TRUNC (SYSDATE) BETWEEN effective_start_date AND effective_end_date;
9385 
9386 		  l_full_name            per_all_people_f.full_name%TYPE;
9387 		  l_plan_rec             csr_plan_det%ROWTYPE;
9388 				--bug14046867 declaring a variable to hold the source plan details
9389 			l_src_plan_rec     	 csr_plan_det%ROWTYPE;
9390 			--bug14046867
9391 		  to_role_not_exists     EXCEPTION;
9392 		  from_role_not_exists   EXCEPTION;
9393 		  err_msg                VARCHAR2 (2000);
9394 		  l_to_role              wf_local_roles.NAME%TYPE   DEFAULT NULL;
9395 		  l_from_role            wf_local_roles.NAME%TYPE   DEFAULT NULL;
9396 		  ln_notification_id     NUMBER;
9397 	   BEGIN
9398 		  OPEN get_role (p_person_id);
9399 
9400 		  FETCH get_role
9401 		   INTO l_to_role;
9402 
9403 		  CLOSE get_role;
9404 
9405 		  IF l_to_role IS NULL
9406 		  THEN
9407 			 RAISE to_role_not_exists;
9408 		  END IF;
9409 
9410 		  IF p_plan_id IS NOT NULL
9411 		  THEN
9412 			 OPEN csr_plan_det (p_plan_id);
9413 
9414 			 FETCH csr_plan_det
9415 			  INTO l_plan_rec;
9416 
9417 			 CLOSE csr_plan_det;
9418 		  END IF;
9419 
9420 		--bug14046867  getting source plan details
9421 			IF g_src_plan_id IS NOT NULL
9422 		   THEN
9423 			 OPEN csr_plan_det (g_src_plan_id);
9424 
9425 			 FETCH csr_plan_det
9426 			  INTO l_src_plan_rec;
9427 
9428 			 CLOSE csr_plan_det;
9429 		  END IF;
9430 		   --bug14046867
9431 
9432 		  OPEN get_role (l_plan_rec.administrator_person_id);
9433 
9434 		  FETCH get_role
9435 		   INTO l_from_role;
9436 
9437 		  CLOSE get_role;
9438 
9439 		  IF l_from_role IS NULL
9440 		  THEN
9441 			 RAISE from_role_not_exists;
9442 		  END IF;
9443 
9444 		  OPEN get_role (p_person_id);
9445 
9446 		  FETCH get_role
9447 		   INTO l_to_role;
9448 
9449 		  CLOSE get_role;
9450 
9451 		  IF p_full_name IS NULL
9452 		  THEN
9453 			 OPEN csr_full_name;
9454 
9455 			 FETCH csr_full_name
9456 			  INTO l_full_name;
9457 
9458 			 CLOSE csr_full_name;
9459 		  END IF;
9460 
9461 		  ln_notification_id :=
9462 			 wf_notification.send (ROLE              => l_to_role,
9463 								   msg_type          => 'HRWPM',
9464 								   --  msg_name => 'HR_WPM_SC_REMOVE',
9465 								   msg_name          => p_message,
9466 								   callback          => NULL,
9467 								   CONTEXT           => NULL,
9468 								   send_comment      => NULL,
9469 								   priority          => 50
9470 								  );
9471 		  wf_notification.setattrtext (ln_notification_id, '#FROM_ROLE', l_from_role);
9472 			 --Bug14046389 included  WPM_SC_RESET_MGR AND  WPM_SC_RESET_WKR
9473 		  IF (p_message = 'WPM_AP_ENROLL_MSG' OR p_message = 'WPM_SC_REMOVE_MSG' OR p_message = 'WPM_PLAN_ROLLBACK_MSG' OR p_message = 'WPM_SC_REALLOCATE_OBJ_WKR' OR p_message = 'WPM_SC_RESET_WKR' OR p_message = 'WPM_SC_RESET_MGR')
9474 		  THEN
9475 			 wf_notification.setattrtext (ln_notification_id, 'HR_WPM_PLAN_NAME', l_plan_rec.plan_name);
9476 		  ELSIF p_message = 'WPM_SC_REOPEN_MGR_MSG' OR p_message = 'WPM_SC_REFRESH_MGR'
9477 		  THEN
9478 			 wf_notification.setattrtext (ln_notification_id, 'SCORE_CARD_EMP_NAME', NVL (p_full_name, l_full_name));
9479 		  ELSIF p_message = 'WPM_APPRAISAL_REOPEN_MGR_MSG'
9480 		  THEN
9481 			 wf_notification.setattrtext (ln_notification_id, 'APPRAISAL_EMP_NAME', NVL (p_full_name, l_full_name));
9482 		 --bug14046867 setting attributes
9483 		  ELSIF ( p_message IN ('WPM_SC_TRNF_WITH_APPR_MGR','WPM_SC_TRNF_WITH_OBJ_MGR','WPM_SC_TRNF_ONLY_MGR'))
9484 			 THEN
9485 			   wf_notification.setattrtext (ln_notification_id, 'EMP_NAME', NVL (p_full_name, l_full_name));
9486 			   wf_notification.setattrtext (ln_notification_id, 'SOURCE_WPM_PLAN', l_src_plan_rec.plan_name);
9487 			   wf_notification.setattrtext (ln_notification_id, 'TARGET_WPM_PLAN', l_plan_rec.plan_name);
9488 
9489 
9490 			ELSIF ( p_message IN ('WPM_SC_TRNF_WITH_APPR_WKR','WPM_SC_TRNF_WITH_OBJ_WKR','WPM_SC_TRNF_ONLY_WKR'))
9491 			 THEN
9492 
9493 			   wf_notification.setattrtext (ln_notification_id, 'SOURCE_WPM_PLAN', l_src_plan_rec.plan_name);
9494 			   wf_notification.setattrtext (ln_notification_id, 'TARGET_WPM_PLAN', l_plan_rec.plan_name);
9495 		  END IF;
9496 			--bug14046867
9497 		  wf_notification.denormalize_notification (ln_notification_id, NULL, NULL);
9498 	   EXCEPTION
9499 		  WHEN OTHERS
9500 		  THEN
9501 			 err_msg := SUBSTR ('Error ' || TO_CHAR (SQLCODE) || ': ' || SQLERRM, 1, 255);
9502 	   END send_message_notification;
9503 
9504 	   FUNCTION get_manager_id (
9505 		  p_person_id       IN   per_all_assignments_f.person_id%TYPE,
9506 		  p_assignment_id        per_all_assignments_f.assignment_id%TYPE
9507 	   )
9508 		  RETURN NUMBER
9509 	   IS
9510 		  CURSOR get_supervisor_id (person_id per_all_people_f.person_id%TYPE)
9511 		  IS
9512 			 --8262552 Changes to get the correct supervisor Id based on assignment Id
9513 			 SELECT supervisor_id
9514 			   FROM per_all_assignments_f
9515 			  WHERE person_id = p_person_id
9516 				AND TRUNC (SYSDATE) BETWEEN effective_start_date AND effective_end_date
9517 				AND assignment_id = p_assignment_id;
9518 
9519 		  l_super_visor_id   per_all_assignments_f.supervisor_id%TYPE;
9520 		  l_role             wf_local_roles.NAME%TYPE                   DEFAULT NULL;
9521 	   BEGIN
9522 		  OPEN get_supervisor_id (p_person_id);
9523 
9524 		  FETCH get_supervisor_id
9525 		   INTO l_super_visor_id;
9526 
9527 		  CLOSE get_supervisor_id;
9528 
9529 		  RETURN l_super_visor_id;
9530 	   EXCEPTION
9531 		  WHEN OTHERS
9532 		  THEN
9533 			 NULL;
9534 	   END get_manager_id;
9535 
9536 	   --
9537 	   PROCEDURE send_fyi_ntf (
9538 		  itemtype    IN              VARCHAR2,
9539 		  itemkey     IN              VARCHAR2,
9540 		  actid       IN              NUMBER,
9541 		  funcmode    IN              VARCHAR2,
9542 		  resultout   OUT NOCOPY      VARCHAR2,
9543 		  rolename    IN              VARCHAR2
9544 	   )
9545 	   IS
9546 		  prole                wf_users.NAME%TYPE;                                                                    -- Fix 3210283.
9547 		  l_role_name          wf_roles.NAME%TYPE;
9548 		  expand_role          VARCHAR2 (1);
9549 		  l_msg                VARCHAR2 (30);
9550 		  -- Start changes for bug#5903006
9551 		  l_obj_setting_flag   VARCHAR2 (30);
9552 	  --end changes for bug#5903006
9553 	--
9554 	   BEGIN
9555 		  IF (funcmode <> wf_engine.eng_run)
9556 		  THEN
9557 			 resultout := wf_engine.eng_null;
9558 			 RETURN;
9559 		  END IF;
9560 
9561 		  l_role_name := rolename;
9562 		  l_msg := UPPER (wf_engine.getactivityattrtext (itemtype, itemkey, actid, 'MESSAGE_NAME'));
9563 		  -- Start Changes for bug#5903006
9564 		  l_obj_setting_flag :=
9565 							  wf_engine.getitemattrtext (itemtype      => itemtype, itemkey => itemkey,
9566 														 aname         => 'HR_WPM_OBJ_SETTING_FLAG');
9567 
9568 		  IF NVL (l_obj_setting_flag, 'N') = 'N'
9569 		  THEN
9570 			 IF l_msg = 'WPM_PLAN_PUB_ALL_POP_MSG'
9571 			 THEN
9572 				l_msg := 'WPM_PLAN_PUB_ALL_NO_OBJ_MSG';
9573 			 ELSIF l_msg = 'WPM_PLAN_PUB_NON_TOP_POP_MSG'
9574 			 THEN
9575 				l_msg := 'WPM_PLAN_PUB_NON_TOP_NOOBJ_MSG';
9576 			 ELSIF l_msg = 'WPM_PLAN_PUB_TOP_POP_MSG'
9577 			 THEN
9578 				l_msg := 'WPM_PLAN_PUB_TOP_NO_OBJ_MSG';
9579 			 END IF;
9580 		  END IF;
9581 
9582 		  -- End Changes for bug#5903006
9583 		  expand_role := 'N';
9584 
9585 		  IF l_role_name IS NULL
9586 		  THEN
9587 			 wf_core.token ('TYPE', itemtype);
9588 			 wf_core.token ('ACTID', TO_CHAR (actid));
9589 			 wf_core.RAISE ('WFENG_NOTIFICATION_PERFORMER');
9590 		  END IF;
9591 
9592 		  --
9593 		  wf_engine_util.notification_send (itemtype, itemkey, actid, l_msg, 'HRWPM', l_role_name, expand_role, resultout);
9594 	   EXCEPTION
9595 		  WHEN OTHERS
9596 		  THEN
9597 			 RAISE;
9598 	   END send_fyi_ntf;
9599 
9600 	--
9601 	   PROCEDURE notify_plan_population (
9602 		  itemtype    IN              VARCHAR2,
9603 		  itemkey     IN              VARCHAR2,
9604 		  actid       IN              NUMBER,
9605 		  funcmode    IN              VARCHAR2,
9606 		  resultout   OUT NOCOPY      VARCHAR2
9607 	   )
9608 	   IS
9609 		  l_plan_id            NUMBER;
9610 		  l_role_name          wf_roles.NAME%TYPE;
9611 		  l_role_displayname   wf_roles.display_name%TYPE;
9612 		  --
9613 		  l_member_index       NUMBER;
9614 		  l_result             VARCHAR2 (100);
9615 		  l_count              NUMBER                       := 0;
9616 		  l_sc_exists          VARCHAR2 (20);
9617 
9618 		  CURSOR csr_chk_sc_exists (p_assignment_id NUMBER, p_plan_id NUMBER)
9619 		  IS
9620 			 SELECT 'Y'
9621 			   FROM DUAL
9622 			  WHERE EXISTS (SELECT 'X'
9623 							  FROM per_personal_scorecards
9624 							 WHERE plan_id = p_plan_id AND assignment_id = p_assignment_id);
9625 	   BEGIN
9626 		  --
9627 		  IF (funcmode = 'RUN')
9628 		  THEN
9629 			 -- Get the workwlow attribute values
9630 			 l_plan_id := wf_engine.getitemattrtext (itemtype => itemtype, itemkey => itemkey, aname => 'WPM_PLAN_ID');
9631 
9632 			 -- If plan population is known
9633 			 IF (g_plan_pop_known_t (l_plan_id))
9634 			 THEN
9635 				l_member_index := g_qual_pop_tbl.FIRST;
9636 
9637 				WHILE (l_member_index IS NOT NULL)
9638 				LOOP
9639 				   l_sc_exists := 'N';
9640 
9641 	--changed by schowdhu 8865480 08-Sep-09
9642 				   OPEN csr_chk_sc_exists (l_member_index, l_plan_id);
9643 
9644 				   FETCH csr_chk_sc_exists
9645 					INTO l_sc_exists;
9646 
9647 				   CLOSE csr_chk_sc_exists;
9648 
9649 				   IF NVL (l_sc_exists, 'N') = 'Y'
9650 				   THEN
9651 					  -- Get the Role for the Owner
9652 					  wf_directory.getrolename (p_orig_system         => 'PER',
9653 												p_orig_system_id      => g_qual_pop_tbl (l_member_index).person_id,
9654 												p_name                => l_role_name,
9655 												p_display_name        => l_role_displayname
9656 											   );
9657 
9658 					  --
9659 					  IF (l_role_name IS NOT NULL)
9660 					  THEN
9661 						 --
9662 						 send_fyi_ntf (itemtype, itemkey, actid, funcmode, l_result, l_role_name);
9663 						 l_count := l_count + 1;
9664 					  END IF;
9665 				   END IF;                                                                                            --  IF sc exists
9666 
9667 				   --
9668 				   l_member_index := g_qual_pop_tbl.NEXT (l_member_index);
9669 				--
9670 				END LOOP;
9671 			 END IF;
9672 		  END IF;
9673 	   EXCEPTION
9674 		  WHEN OTHERS
9675 		  THEN
9676 			 wf_core.CONTEXT ('HR_PERF_MGMT_PLANS_INTERNAL',
9677 							  'POPULATE_PLAN_MEMBERS_CACHE',
9678 							  itemtype,
9679 							  itemkey,
9680 							  TO_CHAR (actid),
9681 							  funcmode
9682 							 );
9683 			 RAISE;
9684 	   END notify_plan_population;
9685 
9686 	   PROCEDURE submit_publish_plan_rep_cp (
9687 		  p_effective_date              IN              DATE,
9688 		  p_plan_id                     IN              NUMBER,
9689 		  p_object_version_number       IN OUT NOCOPY   NUMBER,
9690 		  p_reverse_mode                IN              VARCHAR2 DEFAULT 'N',
9691 		  p_what_if                     IN              VARCHAR2 DEFAULT 'N',
9692 		  p_log_output                  IN              VARCHAR2 DEFAULT 'N',
9693 		  p_action_parameter_group_id   IN              NUMBER DEFAULT NULL,
9694 		  p_item_type                   IN              VARCHAR2 DEFAULT 'HRWPM',
9695 		  p_wf_process                  IN              VARCHAR2 DEFAULT 'HR_NOTIFY_WPM_PLAN_POP_PRC',
9696 		  p_status_code                 IN OUT NOCOPY   VARCHAR2,
9697 		  p_republish_values            IN              VARCHAR2
9698 	   )
9699 	   IS
9700 		  l_proc                    VARCHAR2 (72)                 := g_package || 'submit_publish_plan_rep_cp';
9701 		  l_request_id              NUMBER;
9702 		  l_effective_date          DATE                          := NVL (p_effective_date, TRUNC (SYSDATE));
9703 		  l_pl_rec                  per_perf_mgmt_plans%ROWTYPE;
9704 		  l_dummy                   BOOLEAN;
9705 		  l_dummy1                  VARCHAR2 (10);
9706 		  l_status_code             VARCHAR2 (30);
9707 		  l_object_version_number   NUMBER;
9708 
9709 		  CURSOR csr_plan (p_plan_id IN NUMBER)
9710 		  IS
9711 			 SELECT *
9712 			   FROM per_perf_mgmt_plans
9713 			  WHERE plan_id = p_plan_id;
9714 
9715 		  CURSOR csr_sc_exist (p_plan_id IN NUMBER)
9716 		  IS
9717 			 SELECT 'Y'
9718 			   FROM DUAL
9719 			  WHERE EXISTS (SELECT 'x'
9720 							  FROM per_personal_scorecards
9721 							 WHERE plan_id = p_plan_id);
9722 
9723 		  CURSOR csr_get_plan_rec
9724 		  IS
9725 			 SELECT *
9726 			   FROM per_perf_mgmt_plans
9727 			  WHERE plan_id = p_plan_id;
9728 
9729 		  l_plan_rec                csr_get_plan_rec%ROWTYPE;
9730 	   BEGIN
9731 		  hr_utility.set_location ('Entering:' || l_proc, 10);
9732 		  hr_api.mandatory_arg_error (p_api_name            => 'submit_publish_plan_rep_cp',
9733 									  p_argument            => 'p_effective_date',
9734 									  p_argument_value      => p_effective_date
9735 									 );
9736 		  hr_api.mandatory_arg_error (p_api_name            => 'submit_publish_plan_rep_cp',
9737 									  p_argument            => 'p_plan_id',
9738 									  p_argument_value      => p_plan_id
9739 									 );
9740 		  hr_api.mandatory_arg_error (p_api_name            => 'submit_publish_plan_rep_cp',
9741 									  p_argument            => 'p_object_version_number',
9742 									  p_argument_value      => p_object_version_number
9743 									 );
9744 		  hr_api.mandatory_arg_error (p_api_name            => 'submit_publish_plan_rep_cp',
9745 									  p_argument            => 'p_republish_values',
9746 									  p_argument_value      => p_republish_values
9747 									 );
9748 
9749 		  OPEN csr_plan (p_plan_id);
9750 
9751 		  FETCH csr_plan
9752 		   INTO l_pl_rec;
9753 
9754 		  IF csr_plan%NOTFOUND
9755 		  THEN
9756 			 CLOSE csr_plan;
9757 
9758 			 log_message ('Invalid Plan ID entered: ' || p_plan_id || ' Exiting.');
9759 			 p_status_code := 'E';
9760 			 RETURN;
9761 		  END IF;
9762 
9763 		  CLOSE csr_plan;
9764 
9765 		  IF l_pl_rec.status_code = 'DRAFT'
9766 		  THEN
9767 			 log_message ('Plan being published for the first time. Cannot republish. Exiting.');
9768 			 p_status_code := 'E';
9769 			 RETURN;
9770 		  END IF;
9771 
9772 		  OPEN csr_sc_exist (p_plan_id);
9773 
9774 		  FETCH csr_sc_exist
9775 		   INTO l_dummy1;
9776 
9777 		  CLOSE csr_sc_exist;
9778 
9779 		  IF NVL (l_dummy1, 'N') = 'N'
9780 		  THEN
9781 			 log_message ('Plan being published for the first time. Cannot republish. Exiting.');
9782 			 p_status_code := 'E';
9783 			 RETURN;
9784 		  END IF;
9785 
9786 		  -- initialize the OVN
9787 		  l_object_version_number := l_pl_rec.object_version_number;
9788 			--
9789 		  -- Submit the request
9790 		  l_request_id :=
9791 			 fnd_request.submit_request (application      => 'PER',
9792 										 program          => 'PERPLNREPUB',
9793 										 sub_request      => FALSE,
9794 										 argument1        => fnd_date.date_to_canonical (l_effective_date),
9795 										 argument2        => p_plan_id,
9796 										 argument3        => l_object_version_number,
9797 										 argument4        => p_reverse_mode,
9798 										 argument5       => 'N',
9799 										 argument6        => 'Y',
9800 										 argument7        => NULL,
9801 										 argument8        => 'HRWPM',
9802 										 argument9       => 'HR_NOTIFY_WPM_PLAN_POP_PRC',
9803 										 argument10      => null,
9804 										 argument11        => p_republish_values
9805 										);
9806 
9807 		  --
9808 		  IF l_request_id > 0
9809 		  THEN
9810 			 -- Update the status of plan
9811 			 IF (p_status_code = 'DRAFT')
9812 			 THEN
9813 				l_status_code := 'SUBMITTED';
9814 			 ELSIF (p_status_code = 'UPDATED' OR p_status_code = 'FAILED')
9815 			 THEN
9816 				l_status_code := 'RESUBMITTED';
9817 			 END IF;
9818 
9819 			 --
9820 			 per_pmp_upd.upd (p_plan_id                     => p_plan_id,
9821 							  p_effective_date              => l_effective_date,
9822 							  p_object_version_number       => l_object_version_number,
9823 							  p_status_code                 => l_status_code,
9824 							  p_duplicate_name_warning      => l_dummy,
9825 							  p_no_life_events_warning      => l_dummy
9826 							 );
9827 			 --
9828 			 p_object_version_number := l_object_version_number;
9829 			 p_status_code := l_status_code;
9830 
9831 			 --
9832 			 -- Get Plan record
9833 			 --
9834 			 OPEN csr_get_plan_rec;
9835 
9836 			 FETCH csr_get_plan_rec
9837 			  INTO l_plan_rec;
9838 
9839 			 CLOSE csr_get_plan_rec;
9840 
9841 			 --
9842 			 -- Send notification to administrator that plan publish errored
9843 			 --
9844 			 send_fyi_admin (p_plan_rec => l_plan_rec, p_status => 'SUBMITTED', p_request_id => l_request_id);
9845 		  ELSE
9846 			 p_status_code := 'E';
9847 		  END IF;
9848 
9849 		  hr_utility.set_location ('Leaving:' || l_proc, 80);
9850 	   END submit_publish_plan_rep_cp;
9851 
9852 	--
9853 	   PROCEDURE sc_allocate_objs (p_plan_id IN NUMBER, p_scorecard_id IN NUMBER, p_reallocate IN VARCHAR2)
9854 	   IS
9855 		  CURSOR csr_sc_dtls (p_sc_id IN NUMBER, p_plan_id IN NUMBER, p_effective_date IN DATE)
9856 		  IS
9857 			 SELECT pc.scorecard_id, pc.person_id, pc.object_version_number, papf.full_name scorecard_owner, pc.status_code,
9858 					papf.business_group_id, paaf.organization_id, paaf.position_id, paaf.job_id, pc.assignment_id,
9859 					paaf.supervisor_id                                                                                 --  Bug7567079
9860 			   FROM per_personal_scorecards pc, per_people_f papf, per_assignments_f paaf
9861 			  WHERE pc.scorecard_id = p_sc_id
9862 				AND pc.plan_id = p_plan_id
9863 				AND pc.assignment_id = paaf.assignment_id
9864 				AND pc.person_id = papf.person_id
9865 				AND p_effective_date BETWEEN paaf.effective_start_date AND paaf.effective_end_date
9866 				AND p_effective_date BETWEEN papf.effective_start_date AND papf.effective_end_date;
9867 
9868 		  l_sc_rec                  csr_sc_dtls%ROWTYPE;
9869 		  l_qual_obj_index          BINARY_INTEGER;
9870 		  l_scorecard_id            NUMBER;
9871 		  l_obj_date                DATE                                       := TRUNC (SYSDATE);
9872 		  l_scorecard_status_code   VARCHAR2 (30);
9873 		  l_check_elig              VARCHAR2 (10);
9874 
9875 		  CURSOR csr_sc_dup_obj (p_scorecard_id IN NUMBER, p_library_id IN NUMBER)
9876 		  IS
9877 			 SELECT 'Y'
9878 			   FROM per_objectives
9879 			  WHERE scorecard_id = p_scorecard_id AND copied_from_library_id = p_library_id;
9880 
9881 	--
9882 		  CURSOR csr_sc_obj (p_scorecard_id IN NUMBER, p_objective_id IN NUMBER)
9883 		  IS
9884 			 SELECT objective_id, object_version_number
9885 			   FROM per_objectives po
9886 			  WHERE po.scorecard_id = p_scorecard_id AND po.copied_from_library_id = p_objective_id;
9887 
9888 		  l_obj_ovn                 NUMBER;
9889 		  l_objective_id            NUMBER;
9890 		  l_sc_dup_obj              VARCHAR2 (1);
9891 		  l_sup_id                  per_all_assignments_f.supervisor_id%TYPE   DEFAULT NULL;
9892 	   BEGIN
9893 		  l_scorecard_id := p_scorecard_id;
9894 		  OPEN csr_sc_dtls (p_scorecard_id, p_plan_id, l_obj_date);
9895 
9896 		  FETCH csr_sc_dtls
9897 		   INTO l_sc_rec;
9898 
9899 		  CLOSE csr_sc_dtls;
9900 
9901 		  log_message ('select scorecard_id rec:' || l_sc_rec.scorecard_owner);
9902 		  log_message ('Inside reallocate obj for sc' || g_plan_dtls (1).automatic_allocation_flag);
9903 
9904 		  IF (g_plan_dtls (1).automatic_allocation_flag = 'Y')
9905 		  THEN
9906 			 l_qual_obj_index := g_qual_obj_tbl.FIRST;
9907 			 log_message ('l_qual_obj_index' || l_qual_obj_index);
9908 
9909 			 WHILE (l_qual_obj_index IS NOT NULL)
9910 			 LOOP
9911 				--
9912 				-- Enclose the call to eligibility within a block, so that if for any
9913 				-- reason the eligibility engine errors, then process can still
9914 				-- continue by skipping the current person/assignemnt as not eligible
9915 				--
9916 				log_message ('Evaluating: ' || g_qual_obj_tbl (l_qual_obj_index).objective_name);
9917 				log_message (   'Evaluating: '
9918 								  || g_qual_obj_tbl (l_qual_obj_index).objective_id
9919 								  || '-'
9920 								  || g_qual_obj_tbl (l_qual_obj_index).objective_name
9921 								 );
9922 
9923 				BEGIN
9924 				   --
9925 				   ben_env_object.init (p_business_group_id      => l_sc_rec.business_group_id,
9926 										p_thread_id              => NULL,
9927 										p_chunk_size             => NULL,
9928 										p_threads                => NULL,
9929 										p_max_errors             => NULL,
9930 										p_benefit_action_id      => NULL,
9931 										p_effective_date         => l_obj_date
9932 									   );
9933 				   --
9934 				   --
9935 				   l_check_elig :=
9936 					  ben_per_asg_elig.eligible (l_sc_rec.person_id,
9937 												 l_sc_rec.assignment_id,
9938 												 g_qual_obj_tbl (l_qual_obj_index).elig_obj_id,
9939 												 l_obj_date,
9940 												 l_sc_rec.business_group_id,
9941 												 'Y'                                                    ---KMG -- Added to Allow CWK's
9942 												);
9943 				   log_message ('eLIGI CHECK:' || l_check_elig|| l_sc_rec.scorecard_id);
9944 				EXCEPTION
9945 				   WHEN OTHERS
9946 				   THEN
9947 					  log_message ('Error while evaluating eligibility for' || g_qual_obj_tbl (l_qual_obj_index).objective_name);
9948 					  log_message (SQLERRM);
9949 					  NULL;
9950 				END;
9951 
9952 				IF (l_check_elig = 'Y')
9953 				THEN
9954 				   IF p_reallocate = 'N'
9955 				   THEN                                                     -- this is refresh scorecard with new eligible objectives
9956 					  -- Create the objective
9957 					  OPEN csr_sc_dup_obj (l_scorecard_id, g_qual_obj_tbl (l_qual_obj_index).objective_id);
9958 
9959 					  FETCH csr_sc_dup_obj
9960 					   INTO l_sc_dup_obj;
9961 
9962 					  IF csr_sc_dup_obj%NOTFOUND
9963 					  THEN
9964 						 log_message('adding objective:'|| g_qual_obj_tbl (l_qual_obj_index).objective_name||' to ' || l_sc_rec.scorecard_id);
9965 						 create_scorecard_objective
9966 												(p_effective_date              => l_obj_date,
9967 												 p_scorecard_id                => l_scorecard_id,
9968 												 p_business_group_id           => l_sc_rec.business_group_id,
9969 												 p_person_id                   => l_sc_rec.person_id,
9970 												 p_start_date                  => g_plan_dtls (1).start_date,
9971 												 p_end_date                    => g_plan_dtls (1).end_date,
9972 												 p_objective_name              => g_qual_obj_tbl (l_qual_obj_index).objective_name,
9973 												 p_valid_from                  => g_qual_obj_tbl (l_qual_obj_index).valid_from,
9974 												 p_valid_to                    => g_qual_obj_tbl (l_qual_obj_index).valid_to,
9975 												 p_target_date                 => g_qual_obj_tbl (l_qual_obj_index).target_date,
9976 												 p_copied_from_library_id      => g_qual_obj_tbl (l_qual_obj_index).objective_id,
9977 												 p_next_review_date            => g_qual_obj_tbl (l_qual_obj_index).next_review_date,
9978 												 p_group_code                  => g_qual_obj_tbl (l_qual_obj_index).group_code,
9979 												 p_priority_code               => g_qual_obj_tbl (l_qual_obj_index).priority_code,
9980 												 p_appraise_flag               => g_qual_obj_tbl (l_qual_obj_index).appraise_flag,
9981 												 p_weighting_percent           => g_qual_obj_tbl (l_qual_obj_index).weighting_percent,
9982 												 p_target_value                => g_qual_obj_tbl (l_qual_obj_index).target_value,
9983 												 p_uom_code                    => g_qual_obj_tbl (l_qual_obj_index).uom_code,
9984 												 p_measurement_style_code      => g_qual_obj_tbl (l_qual_obj_index).measurement_style_code,
9985 												 p_measure_name                => g_qual_obj_tbl (l_qual_obj_index).measure_name,
9986 												 p_measure_type_code           => g_qual_obj_tbl (l_qual_obj_index).measure_type_code,
9987 												 p_measure_comments            => g_qual_obj_tbl (l_qual_obj_index).measure_comments,
9988 												 p_details                     => g_qual_obj_tbl (l_qual_obj_index).details,
9989 												 p_success_criteria            => g_qual_obj_tbl (l_qual_obj_index).success_criteria,
9990 												 p_comments                    => g_qual_obj_tbl (l_qual_obj_index).comments
9991 												);
9992 					   log_message('Added Objective: '|| g_qual_obj_tbl (l_qual_obj_index).objective_name||' to ' || l_sc_rec.scorecard_id);
9993 					  END IF;                                                                                       -- END csr_dup_obj
9994 
9995 					  CLOSE csr_sc_dup_obj;
9996 				   ELSE
9997 					  log_message('Inside the log:');                                                                                     -- p_reallocate Y
9998 					  log_message ('Refresh mode:');
9999 					  l_objective_id := NULL;
10000 					  l_obj_ovn := NULL;
10001 					  OPEN csr_sc_obj (l_scorecard_id, g_qual_obj_tbl (l_qual_obj_index).objective_id);
10002 
10003 					  FETCH csr_sc_obj
10004 					   INTO l_objective_id, l_obj_ovn;
10005 
10006 					  IF csr_sc_obj%FOUND
10007 					  THEN
10008 						 log_message('Updating Objective: '||g_qual_obj_tbl (l_qual_obj_index).objective_name||' for ' || l_sc_rec.scorecard_id);
10009 						 update_scorecard_objective
10010 												(p_effective_date              => l_obj_date,
10011 												 p_objective_id                => l_objective_id,
10012 												 p_scorecard_id                => l_scorecard_id,
10013 												 p_object_version_number       =>  l_obj_ovn,
10014 												 p_start_date                  => g_plan_dtls (1).start_date,
10015 												 p_end_date                    => g_plan_dtls (1).end_date,
10016 												 p_objective_name              => g_qual_obj_tbl (l_qual_obj_index).objective_name,
10017 												 p_valid_from                  => g_qual_obj_tbl (l_qual_obj_index).valid_from,
10018 												 p_valid_to                    => g_qual_obj_tbl (l_qual_obj_index).valid_to,
10019 												 p_target_date                 => g_qual_obj_tbl (l_qual_obj_index).target_date,
10020 												 p_copied_from_library_id      => g_qual_obj_tbl (l_qual_obj_index).objective_id,
10021 												 p_next_review_date            => g_qual_obj_tbl (l_qual_obj_index).next_review_date,
10022 												 p_group_code                  => g_qual_obj_tbl (l_qual_obj_index).group_code,
10023 												 p_priority_code               => g_qual_obj_tbl (l_qual_obj_index).priority_code,
10024 												 p_appraise_flag               => g_qual_obj_tbl (l_qual_obj_index).appraise_flag,
10025 												 p_weighting_percent           => g_qual_obj_tbl (l_qual_obj_index).weighting_percent,
10026 												 p_target_value                => g_qual_obj_tbl (l_qual_obj_index).target_value,
10027 												 p_uom_code                    => g_qual_obj_tbl (l_qual_obj_index).uom_code,
10028 												 p_measurement_style_code      => g_qual_obj_tbl (l_qual_obj_index).measurement_style_code,
10029 												 p_measure_name                => g_qual_obj_tbl (l_qual_obj_index).measure_name,
10030 												 p_measure_type_code           => g_qual_obj_tbl (l_qual_obj_index).measure_type_code,
10031 												 p_measure_comments            => g_qual_obj_tbl (l_qual_obj_index).measure_comments,
10032 												 p_details                     => g_qual_obj_tbl (l_qual_obj_index).details,
10033 												 p_success_criteria            => g_qual_obj_tbl (l_qual_obj_index).success_criteria,
10034 												 p_comments                    => g_qual_obj_tbl (l_qual_obj_index).comments
10035 												);
10036 					  END IF;                                                                                                 -- found
10037 
10038 					  CLOSE csr_sc_obj;
10039 				   END IF;                                                                                         -- reallocate check
10040 				END IF;
10041 
10042 				--
10043 				l_qual_obj_index := g_qual_obj_tbl.NEXT (l_qual_obj_index);
10044 			 --
10045 			 END LOOP;
10046 			 IF NVL(g_plan_dtls(1).notify_population_flag,'N') = 'Y' THEN
10047 			   --IF p_reallocate = 'N' THEN
10048 			   --Bug7567079         l_sup_id := get_manager_id(l_sc_rec.person_id);
10049 				 --send_message_notification (l_sc_rec.person_id, 'WPM_SC_REFRESH_WKR', p_plan_id, NULL);
10050 				 --send_message_notification (l_sc_rec.supervisor_id, 'WPM_SC_REFRESH_MGR', p_plan_id, l_sc_rec.scorecard_owner);
10051 			   IF p_reallocate = 'Y' THEN
10052 			   send_message_notification (l_sc_rec.person_id, 'WPM_SC_REALLOCATE_OBJ_WKR', p_plan_id, NULL);
10053 			   END IF;
10054 			 END IF; --end notify
10055 		  END IF;                                                                                         --auto allocation flag = 'y'
10056 
10057 
10058 	   EXCEPTION
10059 		  WHEN OTHERS
10060 		  THEN
10061 			 log_message ('Error refreshing scorecard:' || l_sc_rec.scorecard_owner);
10062 			 log_message (SQLERRM);
10063 			 g_num_errors := NVL (g_num_errors, 0) + 1;
10064 	   END sc_allocate_objs;
10065 
10066 	--
10067 	   PROCEDURE reallocate_objectives (p_plan_id IN NUMBER)
10068 	   IS
10069 		  l_curr_sc_pop_index       NUMBER;
10070 
10071 	--
10072 		  CURSOR csr_sc (p_sc_id IN NUMBER)
10073 		  IS
10074 			 SELECT pc.scorecard_id, pc.plan_id, pc.person_id, papf.full_name scorecard_owner, pc.status_code,
10075 					papf.business_group_id, paaf.organization_id, paaf.position_id, paaf.job_id, pc.assignment_id,
10076 					paaf.supervisor_id                                                                                 --  Bug7567079
10077 			   FROM per_personal_scorecards pc, per_people_f papf, per_assignments_f paaf
10078 			  WHERE pc.scorecard_id = p_sc_id
10079 				AND pc.assignment_id = paaf.assignment_id
10080 				AND pc.person_id = papf.person_id
10081 				AND TRUNC (SYSDATE) BETWEEN paaf.effective_start_date AND paaf.effective_end_date
10082 				AND TRUNC (SYSDATE) BETWEEN papf.effective_start_date AND papf.effective_end_date;
10083 
10084 		  l_sc_rec                  csr_sc%ROWTYPE;
10085 		  l_scorecard_status_code   VARCHAR2 (30);
10086 	   BEGIN
10087 		  l_curr_sc_pop_index := g_curr_sc_pop_tbl.FIRST;
10088 
10089 		  WHILE (l_curr_sc_pop_index IS NOT NULL)
10090 		  LOOP
10091 			 OPEN csr_sc (g_curr_sc_pop_tbl (l_curr_sc_pop_index).scorecard_id);
10092 
10093 			 FETCH csr_sc
10094 			  INTO l_sc_rec;
10095 
10096 			 CLOSE csr_sc;
10097 
10098 			 BEGIN
10099 				hr_wpm_mass_apr_push.log_records_index := l_sc_rec.assignment_id;
10100 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).wpm_person_action_id := -1;
10101 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).wpm_batch_action_id :=
10102 																				   hr_wpm_mass_apr_push.l_current_wpm_batch_action_id;
10103 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).person_id := l_sc_rec.person_id;
10104 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).assignment_id :=
10105 																				g_curr_sc_pop_tbl (l_curr_sc_pop_index).assignment_id;
10106 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).business_group_id :=
10107 																										   l_sc_rec.business_group_id;
10108 				log_message ('Reallocating for : ' || l_sc_rec.scorecard_id);
10109 				sc_allocate_objs (p_plan_id           => p_plan_id,
10110 								  p_scorecard_id      => g_curr_sc_pop_tbl (l_curr_sc_pop_index).scorecard_id,
10111 								  p_reallocate        => 'Y'
10112 								 );
10113 				l_curr_sc_pop_index := g_curr_sc_pop_tbl.NEXT (l_curr_sc_pop_index);
10114 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).processing_status := 'SUCCESS';
10115 			 EXCEPTION
10116 				WHEN OTHERS
10117 				THEN
10118 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).MESSAGE_TYPE := 'E';
10119 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).message_number := 'OTHER';
10120 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).MESSAGE_TEXT := SQLERRM;
10121 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).processing_status := 'ERROR';
10122 	               l_curr_sc_pop_index := g_curr_sc_pop_tbl.NEXT (l_curr_sc_pop_index);
10123 																															 -- Error
10124 			 END;
10125 		  END LOOP;
10126 		  COMMIT;
10127 	   END reallocate_objectives;
10128 
10129 	--
10130 	   PROCEDURE reset_scorecards (p_plan_id IN NUMBER)
10131 	   IS
10132 		  l_curr_sc_pop_index       NUMBER;
10133 
10134 		  CURSOR csr_sc (p_sc_id IN NUMBER)
10135 		  IS
10136 			 SELECT pc.scorecard_id, pc.plan_id, pc.person_id, papf.full_name scorecard_owner, pc.status_code,
10137 					papf.business_group_id, paaf.organization_id, paaf.position_id, paaf.job_id, pc.assignment_id,
10138 					paaf.supervisor_id                                                                                 --  Bug7567079
10139 			   FROM per_personal_scorecards pc, per_people_f papf, per_assignments_f paaf
10140 			  WHERE pc.scorecard_id = p_sc_id
10141 				AND pc.assignment_id = paaf.assignment_id
10142 				AND pc.person_id = papf.person_id
10143 				AND TRUNC (SYSDATE) BETWEEN paaf.effective_start_date AND paaf.effective_end_date
10144 				AND TRUNC (SYSDATE) BETWEEN papf.effective_start_date AND papf.effective_end_date;
10145 
10146 		  l_sc_rec                  csr_sc%ROWTYPE;
10147 		  l_scorecard_status_code   VARCHAR2 (30);
10148 	   BEGIN
10149 		  l_curr_sc_pop_index := g_curr_sc_pop_tbl.FIRST;
10150 
10151 		  WHILE (l_curr_sc_pop_index IS NOT NULL)
10152 		  LOOP
10153 			 OPEN csr_sc (g_curr_sc_pop_tbl (l_curr_sc_pop_index).scorecard_id);
10154 
10155 			 FETCH csr_sc
10156 			  INTO l_sc_rec;
10157 
10158 			 CLOSE csr_sc;
10159 
10160 			 log_message ('sc status:' || l_sc_rec.status_code);
10161 
10162 			 BEGIN
10163 				hr_wpm_mass_apr_push.log_records_index := l_sc_rec.assignment_id;
10164 
10165 				IF NOT hr_wpm_mass_apr_push.g_wpm_person_actions.EXISTS (hr_wpm_mass_apr_push.log_records_index)
10166 				THEN
10167 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).wpm_person_action_id := -1;
10168 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).wpm_batch_action_id :=
10169 																				   hr_wpm_mass_apr_push.l_current_wpm_batch_action_id;
10170 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).person_id := l_sc_rec.person_id;
10171 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).assignment_id :=
10172 																				g_curr_sc_pop_tbl (l_curr_sc_pop_index).assignment_id;
10173 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).business_group_id :=
10174 																										   l_sc_rec.business_group_id;
10175 				END IF;
10176 
10177 				IF (l_sc_rec.status_code = 'PUBLISHED')
10178 				THEN
10179 				   IF g_plan_dtls (1).method_code = 'CAS'
10180 				   THEN
10181 					  IF    (g_plan_dtls (1).hierarchy_type_code = 'SUP' AND g_plan_dtls (1).supervisor_id = l_sc_rec.person_id)
10182 						 OR (    g_plan_dtls (1).hierarchy_type_code = 'SUP_ASG'
10183 							 AND g_plan_dtls (1).supervisor_assignment_id = l_sc_rec.assignment_id
10184 							)
10185 						 OR (g_plan_dtls (1).hierarchy_type_code IN ('POS') AND g_plan_dtls (1).top_position_id = l_sc_rec.position_id
10186 							)
10187 						 OR (    g_plan_dtls (1).hierarchy_type_code = 'ORG'
10188 							 AND is_supervisor_in_org (g_plan_dtls (1).top_organization_id, l_sc_rec.person_id) = 1
10189 							)
10190 					  THEN
10191 						 l_scorecard_status_code := 'NOT_STARTED_WITH_WKR';
10192 					  ELSE
10193 						 l_scorecard_status_code := 'NOT_STARTED_WITH_MGR';
10194 					  END IF;
10195 				   ELSE
10196 					  l_scorecard_status_code := 'NOT_STARTED_WITH_WKR';
10197 				   END IF;
10198 
10199 				   log_message ('Updating sc to NOT_STARTED:' || g_curr_sc_pop_tbl (l_curr_sc_pop_index).scorecard_id);
10200 
10201 				   UPDATE per_personal_scorecards
10202 					  SET status_code = l_scorecard_status_code
10203 					WHERE scorecard_id = g_curr_sc_pop_tbl (l_curr_sc_pop_index).scorecard_id;
10204 				END IF;                                                                                     --- reset scorecard status
10205 
10206 				--Bug7567079         l_sup_id := get_manager_id(l_sc_rec.person_id);
10207 				log_message ('sending fyi:' || l_sc_rec.person_id);
10208 				IF NVL(g_plan_dtls(1).notify_population_flag,'N') = 'Y' THEN
10209 					--Bug14046389  changed the message.
10210 				  send_message_notification (l_sc_rec.person_id, 'WPM_SC_RESET_WKR', l_sc_rec.plan_id, NULL);
10211 				  send_message_notification (l_sc_rec.supervisor_id, 'WPM_SC_RESET_MGR', l_sc_rec.plan_id, l_sc_rec.scorecard_owner);
10212 				END IF;
10213 				l_curr_sc_pop_index := g_curr_sc_pop_tbl.NEXT (l_curr_sc_pop_index);
10214 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).processing_status := 'SUCCESS';
10215 			 EXCEPTION
10216 				WHEN OTHERS
10217 				THEN
10218 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).MESSAGE_TYPE := 'E';
10219 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).message_number := 'OTHER';
10220 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).MESSAGE_TEXT := SQLERRM;
10221 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).processing_status := 'ERROR';
10222 	               l_curr_sc_pop_index := g_curr_sc_pop_tbl.NEXT (l_curr_sc_pop_index);
10223 																															 -- Error
10224 			 END;
10225 		   END LOOP;
10226 		   COMMIT;
10227 	   END reset_scorecards;
10228 
10229 	--
10230 	   PROCEDURE refresh_scorecards (p_plan_id IN NUMBER)
10231 	   IS
10232 		  l_curr_sc_pop_index       NUMBER;
10233 
10234 		  CURSOR csr_sc (p_sc_id IN NUMBER)
10235 		  IS
10236 			 SELECT pc.scorecard_id, pc.plan_id, pc.person_id, papf.full_name scorecard_owner, pc.status_code,
10237 					papf.business_group_id, paaf.organization_id, paaf.position_id, paaf.job_id, pc.assignment_id,
10238 					paaf.supervisor_id                                                                                 --  Bug7567079
10239 			   FROM per_personal_scorecards pc, per_people_f papf, per_assignments_f paaf
10240 			  WHERE pc.scorecard_id = p_sc_id
10241 				AND pc.assignment_id = paaf.assignment_id
10242 				AND pc.person_id = papf.person_id
10243 				AND TRUNC (SYSDATE) BETWEEN paaf.effective_start_date AND paaf.effective_end_date
10244 				AND TRUNC (SYSDATE) BETWEEN papf.effective_start_date AND papf.effective_end_date;
10245 
10246 		  l_sc_rec                  csr_sc%ROWTYPE;
10247 		  l_scorecard_status_code   VARCHAR2 (30);
10248 	   BEGIN
10249 		  l_curr_sc_pop_index := g_curr_sc_pop_tbl.FIRST;
10250 
10251 		  WHILE (l_curr_sc_pop_index IS NOT NULL)
10252 		  LOOP
10253           op ('Scorecard Id: ' || TO_CHAR (g_curr_sc_pop_tbl (l_curr_sc_pop_index).scorecard_id), g_debug_log, 777);
10254 		  hr_utility.set_location('Scorecard Id: ' || TO_CHAR (g_curr_sc_pop_tbl (l_curr_sc_pop_index).scorecard_id), 777);
10255 
10256 			 OPEN csr_sc (g_curr_sc_pop_tbl (l_curr_sc_pop_index).scorecard_id);
10257 
10258 			 FETCH csr_sc
10259 			  INTO l_sc_rec;
10260 
10261 			 CLOSE csr_sc;
10262 
10263 			 BEGIN
10264 				hr_wpm_mass_apr_push.log_records_index := l_sc_rec.assignment_id;
10265 
10266 				IF NOT hr_wpm_mass_apr_push.g_wpm_person_actions.EXISTS (hr_wpm_mass_apr_push.log_records_index)
10267 				THEN
10268 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).wpm_person_action_id := -1;
10269 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).wpm_batch_action_id :=
10270 																				   hr_wpm_mass_apr_push.l_current_wpm_batch_action_id;
10271 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).person_id := l_sc_rec.person_id;
10272 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).assignment_id :=
10273 																				g_curr_sc_pop_tbl (l_curr_sc_pop_index).assignment_id;
10274 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).business_group_id :=
10275 																										   l_sc_rec.business_group_id;
10276 				END IF;
10277 
10278 				sc_allocate_objs (p_plan_id           => p_plan_id,
10279 								  p_scorecard_id      => g_curr_sc_pop_tbl (l_curr_sc_pop_index).scorecard_id,
10280 								  p_reallocate        => 'N'
10281 								 );
10282 				IF NVL(g_plan_dtls(1).notify_population_flag,'N') = 'Y' THEN
10283 				   send_message_notification (l_sc_rec.person_id, 'WPM_SC_REFRESH_WKR', l_sc_rec.plan_id, NULL);
10284 				   send_message_notification (l_sc_rec.supervisor_id, 'WPM_SC_REFRESH_MGR', l_sc_rec.plan_id, l_sc_rec.scorecard_owner);
10285 				END IF;
10286 				l_curr_sc_pop_index := g_curr_sc_pop_tbl.NEXT (l_curr_sc_pop_index);
10287 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).processing_status := 'SUCCESS';
10288 			 EXCEPTION
10289 				WHEN OTHERS
10290 				THEN
10291 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).MESSAGE_TYPE := 'E';
10292 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).message_number := 'OTHER';
10293 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).MESSAGE_TEXT := SQLERRM;
10294 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).processing_status := 'ERROR';
10295                    l_curr_sc_pop_index := g_curr_sc_pop_tbl.NEXT (l_curr_sc_pop_index);
10296 																															 -- Error
10297 			 END;
10298 		  END LOOP;
10299 		  COMMIT;
10300 	   END refresh_scorecards;
10301 
10302 	   PROCEDURE rebuild_sup_hierarchy (p_plan_id IN NUMBER)
10303 	   IS
10304 		  l_curr_sc_pop_index       NUMBER;
10305 
10306 		  CURSOR csr_sc (p_sc_id IN NUMBER)
10307 		  IS
10308 			 SELECT pc.scorecard_id, pc.plan_id, pc.person_id, papf.full_name scorecard_owner, pc.status_code,
10309 					papf.business_group_id, paaf.organization_id, paaf.position_id, paaf.job_id, pc.assignment_id,
10310 					paaf.supervisor_id                                                                                 --  Bug7567079
10311 			   FROM per_personal_scorecards pc, per_people_f papf, per_assignments_f paaf
10312 			  WHERE pc.scorecard_id = p_sc_id
10313 				AND pc.assignment_id = paaf.assignment_id
10314 				AND pc.person_id = papf.person_id
10315 				AND TRUNC (SYSDATE) BETWEEN paaf.effective_start_date AND paaf.effective_end_date
10316 				AND TRUNC (SYSDATE) BETWEEN papf.effective_start_date AND papf.effective_end_date;
10317 
10318 		  l_sc_rec                  csr_sc%ROWTYPE;
10319 		  l_scorecard_status_code   VARCHAR2 (30);
10320 
10321 		  PROCEDURE sc_refresh_sup (p_scorecard_id IN NUMBER)
10322 		  IS
10323 			 CURSOR csr_curr_sup (p_sc_id IN NUMBER)
10324 			 IS
10325 				SELECT paf.supervisor_id, paf.supervisor_assignment_id, sc.object_version_number
10326 				  FROM per_personal_scorecards sc, per_assignments_f paf
10327 				 WHERE sc.scorecard_id = p_sc_id
10328 				   AND sc.assignment_id = paf.assignment_id
10329 				   AND TRUNC (SYSDATE) BETWEEN paf.effective_start_date AND paf.effective_end_date;
10330 
10331 			 l_sc_sup     csr_curr_sup%ROWTYPE;
10332 			 l_dup_warn   BOOLEAN;
10333 		  BEGIN
10334 			 OPEN csr_curr_sup (p_scorecard_id);
10335 
10336 			 FETCH csr_curr_sup
10337 			  INTO l_sc_sup;
10338 
10339 			 CLOSE csr_curr_sup;
10340 
10341           op ('In sc_refresh_sup Scorecard Id: ' || TO_CHAR (p_scorecard_id), g_debug_log, 7777);
10342           op ('In sc_refresh_sup Supervisor Id: ' || TO_CHAR (l_sc_sup.supervisor_id), g_debug_log, 7777);
10343           op ('In sc_refresh_sup Supervisor Assignment Id: ' || TO_CHAR (l_sc_sup.supervisor_assignment_id), g_debug_log, 7777);
10344 
10345 	      hr_utility.set_location('In sc_refresh_sup Scorecard Id: ' || TO_CHAR (p_scorecard_id), 7777);
10346 		  hr_utility.set_location('In sc_refresh_sup Supervisor Id: ' || TO_CHAR (l_sc_sup.supervisor_id), 7777);
10347 		  hr_utility.set_location('In sc_refresh_sup Supervisor Assignment Id: ' || TO_CHAR (l_sc_sup.supervisor_assignment_id), 7777);
10348 
10349 			 hr_personal_scorecard_api.update_scorecard (p_effective_date                => TRUNC (SYSDATE),
10350 														 p_scorecard_id                  => p_scorecard_id,
10351 														 p_object_version_number         => l_sc_sup.object_version_number,
10352 														 p_supervisor_id                 => l_sc_sup.supervisor_id,
10353 														 p_supervisor_assignment_id      => l_sc_sup.supervisor_assignment_id,
10354 														 p_duplicate_name_warning        => l_dup_warn
10355 														);
10356 		  END sc_refresh_sup;
10357 	   BEGIN
10358 		  l_curr_sc_pop_index := g_curr_sc_pop_tbl.FIRST;
10359 
10360 		  WHILE (l_curr_sc_pop_index IS NOT NULL)
10361 		  LOOP
10362 			 OPEN csr_sc (g_curr_sc_pop_tbl (l_curr_sc_pop_index).scorecard_id);
10363 
10364 			 FETCH csr_sc
10365 			  INTO l_sc_rec;
10366 
10367 			 CLOSE csr_sc;
10368 
10369 			 BEGIN
10370 				hr_wpm_mass_apr_push.log_records_index := l_sc_rec.assignment_id;
10371 
10372 				IF NOT hr_wpm_mass_apr_push.g_wpm_person_actions.EXISTS (hr_wpm_mass_apr_push.log_records_index)
10373 				THEN
10374 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).wpm_person_action_id := -1;
10375 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).wpm_batch_action_id :=
10376 																				   hr_wpm_mass_apr_push.l_current_wpm_batch_action_id;
10377 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).person_id := l_sc_rec.person_id;
10378 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).assignment_id :=
10379 																				g_curr_sc_pop_tbl (l_curr_sc_pop_index).assignment_id;
10380 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).business_group_id :=
10381 																										   l_sc_rec.business_group_id;
10382 				END IF;
10383 
10384 				sc_refresh_sup (g_curr_sc_pop_tbl (l_curr_sc_pop_index).scorecard_id);
10385 				IF NVL(g_plan_dtls(1).notify_population_flag,'N') = 'Y' THEN
10386 				  send_message_notification (l_sc_rec.person_id, 'WPM_SC_REFRESH_WKR', l_sc_rec.plan_id, NULL);
10387 				  send_message_notification (l_sc_rec.supervisor_id, 'WPM_SC_REFRESH_MGR', l_sc_rec.plan_id, l_sc_rec.scorecard_owner);
10388 				END IF;
10389 				l_curr_sc_pop_index := g_curr_sc_pop_tbl.NEXT (l_curr_sc_pop_index);
10390 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).processing_status := 'SUCCESS';
10391 			 EXCEPTION
10392 				WHEN OTHERS
10393 				THEN
10394 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).MESSAGE_TYPE := 'E';
10395 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).message_number := 'OTHER';
10396 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).MESSAGE_TEXT := SQLERRM;
10397 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).processing_status := 'ERROR';
10398                    l_curr_sc_pop_index := g_curr_sc_pop_tbl.NEXT (l_curr_sc_pop_index);                                                                                                          -- Error
10399 			 END;
10400 		  END LOOP;
10401 
10402 		  -- populate the hierarchy for appraisal summary
10403 		  per_wpm_summary_pkg.populate_plan_hierarchy (p_plan_id => p_plan_id, p_effective_date => TRUNC (SYSDATE));
10404 		  COMMIT;
10405 	   END rebuild_sup_hierarchy;
10406 
10407 	   PROCEDURE reevaluate_plan_pop (p_plan_id IN NUMBER)
10408 	   IS
10409 		  CURSOR get_elig_obj_id_for_person (p_plan_id IN per_perf_mgmt_plans.plan_id%TYPE)
10410 		  IS
10411 			 SELECT elig.elig_obj_id
10412 			   FROM ben_elig_obj_f elig
10413 			  WHERE elig.table_name = 'PER_PERF_MGMT_PLANS'
10414 				AND elig.column_name = 'PLAN_ID'
10415 				AND elig.COLUMN_VALUE = p_plan_id
10416 				AND TRUNC (SYSDATE) BETWEEN elig.effective_start_date AND elig.effective_end_date;
10417 
10418 		  CURSOR get_person_name (p_person_id IN per_all_people_f.person_id%TYPE)
10419 		  IS
10420 			 SELECT full_name
10421 			   FROM per_all_people_f ppf
10422 			  WHERE ppf.person_id = p_person_id AND TRUNC (SYSDATE) BETWEEN ppf.effective_start_date AND ppf.effective_end_date;
10423 		  CURSOR csr_find_appr_for_scorecard (
10424 			 p_plan_id        per_appraisals.plan_id%TYPE,
10425 			 p_scorecard_id   per_personal_scorecards.scorecard_id%TYPE
10426 		  )
10427 		  IS
10428 			 SELECT pa.appraisal_id, pa.object_version_number, pa.appraisal_system_status
10429 			   FROM per_appraisals pa, per_personal_scorecards pps
10430 			  WHERE pa.plan_id = p_plan_id AND appraisee_person_id = pps.person_id AND pps.scorecard_id = p_scorecard_id;
10431 	  -- Cursor to get the  Participants of an appraisal other than MA
10432 		  CURSOR csr_get_appr_part (p_appraisal_id per_appraisals.appraisal_id%TYPE)
10433 		  IS
10434 			 SELECT participant_id, object_version_number, participation_type
10435 			   FROM per_participants
10436 			  WHERE participation_in_id = p_appraisal_id
10437 				AND participation_in_table = 'PER_APPRAISALS'
10438 				AND participation_in_column = 'APPRAISAL_ID'
10439 				AND participation_type <> 'MAINAP'
10440 				AND participation_status = 'OPEN';
10441 
10442 		  l_dummy                   BOOLEAN;
10443 		  l_appr_ovn                per_appraisals.object_version_number%TYPE;
10444 		  l_appr_id                 per_appraisals.appraisal_id%TYPE;
10445 		  l_appr_sys_status         per_appraisals.appraisal_system_status%TYPE;
10446 		  l_appraiser_person_id     per_appraisals.appraiser_person_id%TYPE;
10447 		  l_elig_obj_id             ben_elig_obj_f.elig_obj_id%TYPE;
10448 		  l_person_name             per_all_people_f.full_name%TYPE;
10449 		  l_qual_pop_index          BINARY_INTEGER;
10450 		  l_curr_sc_pop_index       BINARY_INTEGER;
10451 		  l_qual_obj_index          BINARY_INTEGER;
10452 		  l_check_elig              VARCHAR2 (1);
10453 		  l_check_elig_person       VARCHAR2 (1);
10454 		  l_obj_date                DATE                              := TRUNC (SYSDATE);
10455 		  l_scorecard_status_code   VARCHAR2 (30);
10456 		  l_scorecard_id            NUMBER;
10457 	   BEGIN
10458 	-- If objective setting flag is set
10459 		  IF ((g_plan_dtls (1).include_obj_setting_flag = 'Y') OR (g_plan_dtls (1).include_appraisals_flag = 'Y'))
10460 		  THEN                                                                                                 -- include obj setting
10461 			 --Check for the elibility of the employee/assignment
10462 				--23-Jun-2009 schowdhu Eligibility Profile Enhc.- start
10463 			 OPEN get_elig_obj_id_for_person (g_plan_dtls (1).plan_id);
10464 
10465 			 FETCH get_elig_obj_id_for_person
10466 			  INTO l_elig_obj_id;
10467 
10468 			 CLOSE get_elig_obj_id_for_person;
10469 
10470 			 l_qual_pop_index := g_qual_pop_tbl.FIRST;
10471 
10472 			 WHILE (l_qual_pop_index IS NOT NULL)
10473 			 LOOP                                                                                                   -- Qual pop looop
10474 				hr_wpm_mass_apr_push.log_records_index := g_qual_pop_tbl (l_qual_pop_index).assignment_id;
10475 
10476 				IF NOT hr_wpm_mass_apr_push.g_wpm_person_actions.EXISTS (hr_wpm_mass_apr_push.log_records_index)
10477 				THEN
10478 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).wpm_person_action_id := -1;
10479 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).wpm_batch_action_id :=
10480 																				   hr_wpm_mass_apr_push.l_current_wpm_batch_action_id;
10481 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).person_id :=
10482 																						  g_qual_pop_tbl (l_qual_pop_index).person_id;
10483 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).assignment_id :=
10484 																					  g_qual_pop_tbl (l_qual_pop_index).assignment_id;
10485 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).business_group_id :=
10486 																				  g_qual_pop_tbl (l_qual_pop_index).business_group_id;
10487 				END IF;
10488 
10489 			 OPEN get_person_name (g_qual_pop_tbl (l_qual_pop_index).person_id);
10490 
10491 			 FETCH get_person_name
10492 			  INTO l_person_name;
10493 
10494 			 CLOSE get_person_name;
10495 
10496 			 IF (l_elig_obj_id IS NULL)
10497 			 THEN
10498 				-- WPM Logging Changes
10499 				hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).eligibility_status := 'Y';
10500 			 END IF;
10501 
10502 			 IF (l_elig_obj_id IS NOT NULL)                                                            -- Eligiblity profile is chosen
10503 			 THEN
10504 				BEGIN
10505 				   --
10506 				   ben_env_object.init (p_business_group_id      => g_qual_pop_tbl (l_qual_pop_index).business_group_id,
10507 										p_thread_id              => NULL,
10508 										p_chunk_size             => NULL,
10509 										p_threads                => NULL,
10510 										p_max_errors             => NULL,
10511 										p_benefit_action_id      => NULL,
10512 										p_effective_date         => l_obj_date
10513 									   );
10514 				   --
10515 				   l_check_elig_person :=
10516 					  ben_per_asg_elig.eligible (g_qual_pop_tbl (l_qual_pop_index).person_id,
10517 												 g_qual_pop_tbl (l_qual_pop_index).assignment_id,
10518 												 l_elig_obj_id,
10519 												 l_obj_date,
10520 												 g_qual_pop_tbl (l_qual_pop_index).business_group_id,
10521 												 'Y'                                                    ---KMG -- Added to Allow CWK's
10522 												);
10523 				   -- WPM Logging Changes
10524 				   hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).eligibility_status :=
10525 																												   l_check_elig_person;
10526 				EXCEPTION
10527 				   WHEN OTHERS
10528 				   THEN
10529 					  l_check_elig_person := 'N';
10530 					  -- WPM Logging Changes
10531 					  hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).eligibility_status :=
10532 																												  l_check_elig_person;
10533 					  -- WPM Logging Changes Post Review
10534 					  hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).MESSAGE_TYPE := 'E';
10535 					  hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).message_number := 'OTHER';
10536 					  hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).MESSAGE_TEXT := SQLERRM;
10537 					  hr_wpm_mass_apr_push.g_wpm_person_actions (hr_wpm_mass_apr_push.log_records_index).processing_status := 'ERROR';
10538 																															 -- Error
10539 					  op (   'Eligibility Check errored for: '
10540 						  || l_person_name
10541 						  || ' ('
10542 						  || g_qual_pop_tbl (l_qual_pop_index).person_id
10543 						  || '). No Scorecard created.',
10544 						  g_regular_log
10545 						 );
10546 					  op (SQLERRM, g_regular_log, 331);
10547 
10548 					  --logged if the topmost person is excluded from the plan population     schowdhu 8744109
10549 					  IF    (    g_plan_dtls (1).hierarchy_type_code = 'SUP'
10550 							 AND g_plan_dtls (1).supervisor_id = g_qual_pop_tbl (l_qual_pop_index).person_id
10551 							)
10552 						 OR (    g_plan_dtls (1).hierarchy_type_code = 'SUP_ASG'
10553 							 AND g_plan_dtls (1).supervisor_assignment_id = g_qual_pop_tbl (l_qual_pop_index).assignment_id
10554 							)
10555 						 OR (    g_plan_dtls (1).hierarchy_type_code IN ('POS')
10556 							 AND g_plan_dtls (1).top_position_id = g_qual_pop_tbl (l_qual_pop_index).position_id
10557 							)
10558 						 OR (    g_plan_dtls (1).hierarchy_type_code = 'ORG'
10559 							 AND is_supervisor_in_org (g_plan_dtls (1).top_organization_id,
10560 													   g_qual_pop_tbl (l_qual_pop_index).person_id
10561 													  ) = 1
10562 							)
10563 					  THEN
10564 						 op ('+-------------------------------------------------------------------+', g_regular_log);
10565 						 op (   'Warning: Eligibility Check errored for the topmost person '
10566 							 || l_person_name
10567 							 || ' ('
10568 							 || g_qual_pop_tbl (l_qual_pop_index).person_id
10569 							 || ').',
10570 							 g_regular_log
10571 							);
10572 						 op ('+-------------------------------------------------------------------+', g_regular_log);
10573 						 g_retcode := warning;
10574 					  END IF;
10575 				END;
10576 			 END IF;                                                                                           -- elig obj id not null
10577 
10578 	--     l_elig_obj_id null check                                      -- Eligiblity profile is chosen END
10579 			 IF (l_check_elig_person = 'N')
10580 			 THEN
10581 				op (   ' Not Eligible. Publish plan SKIPPED for '
10582 					|| l_person_name
10583 					|| ' ('
10584 					|| g_qual_pop_tbl (l_qual_pop_index).person_id
10585 					|| ').',
10586 					g_regular_log
10587 				   );
10588 
10589 				--logged if the topmost person is excluded from the plan population     schowdhu 8744109
10590 				IF    (    g_plan_dtls (1).hierarchy_type_code = 'SUP'
10591 					   AND g_plan_dtls (1).supervisor_id = g_qual_pop_tbl (l_qual_pop_index).person_id
10592 					  )
10593 				   OR (    g_plan_dtls (1).hierarchy_type_code = 'SUP_ASG'
10594 					   AND g_plan_dtls (1).supervisor_assignment_id = g_qual_pop_tbl (l_qual_pop_index).assignment_id
10595 					  )
10596 				   OR (    g_plan_dtls (1).hierarchy_type_code IN ('POS')
10597 					   AND g_plan_dtls (1).top_position_id = g_qual_pop_tbl (l_qual_pop_index).position_id
10598 					  )
10599 				   OR (    g_plan_dtls (1).hierarchy_type_code = 'ORG'
10600 					   AND is_supervisor_in_org (g_plan_dtls (1).top_organization_id, g_qual_pop_tbl (l_qual_pop_index).person_id) = 1
10601 					  )
10602 				THEN
10603 				   op ('+-------------------------------------------------------------------+', g_regular_log);
10604 				   op (   'Warning: Topmost person '
10605 					   || l_person_name
10606 					   || ' ('
10607 					   || g_qual_pop_tbl (l_qual_pop_index).person_id
10608 					   || ') '
10609 					   || 'is excluded from   the plan as he is ineligble as per the eligibility profile attached. ',
10610 					   g_regular_log
10611 					  );
10612 				   op ('+-------------------------------------------------------------------+', g_regular_log);
10613 				   g_retcode := warning;
10614 				END IF;
10615 			 END IF;
10616 
10617 	-- end 23-Jun-2009 schowdhu Eligibility Profile Enhc.
10618 			 IF (l_check_elig_person = 'Y' OR (l_check_elig_person IS NULL AND l_elig_obj_id IS NULL))
10619 			 THEN
10620 				-- Create the scorecard for this assignment
10621 				IF g_plan_dtls (1).method_code = 'CAS'
10622 				THEN
10623 				   IF    (    g_plan_dtls (1).hierarchy_type_code = 'SUP'
10624 						  AND g_plan_dtls (1).supervisor_id = g_qual_pop_tbl (l_qual_pop_index).person_id
10625 						 )
10626 					  OR (    g_plan_dtls (1).hierarchy_type_code = 'SUP_ASG'
10627 						  AND g_plan_dtls (1).supervisor_assignment_id = g_qual_pop_tbl (l_qual_pop_index).assignment_id
10628 						 )
10629 					  OR (    g_plan_dtls (1).hierarchy_type_code IN ('POS')
10630 						  AND g_plan_dtls (1).top_position_id = g_qual_pop_tbl (l_qual_pop_index).position_id
10631 						 )
10632 					  OR (    g_plan_dtls (1).hierarchy_type_code = 'ORG'
10633 						  AND is_supervisor_in_org (g_plan_dtls (1).top_organization_id, g_qual_pop_tbl (l_qual_pop_index).person_id) =
10634 																																	 1
10635 						 )
10636 				   THEN
10637 					  l_scorecard_status_code := 'NOT_STARTED_WITH_WKR';
10638 				   ELSE
10639 					  l_scorecard_status_code := 'NOT_STARTED_WITH_MGR';
10640 				   END IF;
10641 				ELSE
10642 				   l_scorecard_status_code := 'NOT_STARTED_WITH_WKR';
10643 				END IF;
10644 
10645 				--
10646 				   --- HERE Add only if it is not part of current plan population
10647 				   IF NOT g_curr_sc_pop_tbl.EXISTS (l_qual_pop_index)
10648 				   THEN
10649 					  create_scorecard_for_person
10650 											 (p_effective_date                => TRUNC (SYSDATE),
10651 											 p_scorecard_name      => g_plan_dtls (1).plan_name,
10652 											 p_assignment_id       => g_qual_pop_tbl (l_qual_pop_index).assignment_id,
10653 											 p_start_date          => g_plan_dtls (1).start_date,
10654 											 p_end_date            => g_plan_dtls (1).end_date,
10655 											 p_plan_id             => g_plan_dtls (1).plan_id,
10656 											 p_creator_type        => 'AUTO',
10657 											 p_status_code         => l_scorecard_status_code,
10658 											  p_scorecard_id                  => l_scorecard_id,
10659 											  p_supervisor_id                 => g_qual_pop_tbl (l_qual_pop_index).supervisor_id,
10660 											  p_supervisor_assignment_id      => g_qual_pop_tbl (l_qual_pop_index).supervisor_assignment_id
10661 											);
10662 
10663 				IF (g_plan_dtls (1).automatic_allocation_flag = 'Y' AND l_scorecard_id IS NOT NULL)
10664 				THEN
10665 				   l_qual_obj_index := g_qual_obj_tbl.FIRST;
10666 
10667 				   WHILE (l_qual_obj_index IS NOT NULL)
10668 				   LOOP
10669 					  --
10670 					  -- Enclose the call to eligibility within a block, so that if for any
10671 					  -- reason the eligibility engine errors, then process can still
10672 					  -- continue by skipping the current person/assignemnt as not eligible
10673 					  --
10674 					  BEGIN
10675 						 --
10676 						 ben_env_object.init (p_business_group_id      => g_qual_pop_tbl (l_qual_pop_index).business_group_id,
10677 											  p_thread_id              => NULL,
10678 											  p_chunk_size             => NULL,
10679 											  p_threads                => NULL,
10680 											  p_max_errors             => NULL,
10681 											  p_benefit_action_id      => NULL,
10682 											  p_effective_date         => l_obj_date
10683 											 );
10684 						 --
10685 						 --
10686 						 l_check_elig :=
10687 							ben_per_asg_elig.eligible (g_qual_pop_tbl (l_qual_pop_index).person_id,
10688 													   g_qual_pop_tbl (l_qual_pop_index).assignment_id,
10689 													   g_qual_obj_tbl (l_qual_obj_index).elig_obj_id,
10690 													   l_obj_date,
10691 													   g_qual_pop_tbl (l_qual_pop_index).business_group_id,
10692 													   'Y'                                              ---KMG -- Added to Allow CWK's
10693 													  );
10694 					  EXCEPTION
10695 						 WHEN OTHERS
10696 						 THEN
10697 							NULL;
10698 					  END;
10699 
10700 					  IF (l_check_elig = 'Y')
10701 					  THEN
10702 						 -- Create the objective
10703 						 create_scorecard_objective
10704 												(p_effective_date              => TRUNC (SYSDATE),
10705 												 p_scorecard_id                => l_scorecard_id,
10706 												 p_business_group_id           => g_qual_pop_tbl (l_qual_pop_index).business_group_id,
10707 												 p_person_id                   => g_qual_pop_tbl (l_qual_pop_index).person_id,
10708 												 p_start_date                  => g_plan_dtls (1).start_date,
10709 												 p_end_date                    => g_plan_dtls (1).end_date,
10710 												 p_objective_name              => g_qual_obj_tbl (l_qual_obj_index).objective_name,
10711 												 p_valid_from                  => g_qual_obj_tbl (l_qual_obj_index).valid_from,
10712 												 p_valid_to                    => g_qual_obj_tbl (l_qual_obj_index).valid_to,
10713 												 p_target_date                 => g_qual_obj_tbl (l_qual_obj_index).target_date,
10714 												 p_copied_from_library_id      => g_qual_obj_tbl (l_qual_obj_index).objective_id,
10715 												 p_next_review_date            => g_qual_obj_tbl (l_qual_obj_index).next_review_date,
10716 												 p_group_code                  => g_qual_obj_tbl (l_qual_obj_index).group_code,
10717 												 p_priority_code               => g_qual_obj_tbl (l_qual_obj_index).priority_code,
10718 												 p_appraise_flag               => g_qual_obj_tbl (l_qual_obj_index).appraise_flag,
10719 												 p_weighting_percent           => g_qual_obj_tbl (l_qual_obj_index).weighting_percent,
10720 												 p_target_value                => g_qual_obj_tbl (l_qual_obj_index).target_value,
10721 												 p_uom_code                    => g_qual_obj_tbl (l_qual_obj_index).uom_code,
10722 												 p_measurement_style_code      => g_qual_obj_tbl (l_qual_obj_index).measurement_style_code,
10723 												 p_measure_name                => g_qual_obj_tbl (l_qual_obj_index).measure_name,
10724 												 p_measure_type_code           => g_qual_obj_tbl (l_qual_obj_index).measure_type_code,
10725 												 p_measure_comments            => g_qual_obj_tbl (l_qual_obj_index).measure_comments,
10726 												 p_details                     => g_qual_obj_tbl (l_qual_obj_index).details,
10727 												 p_success_criteria            => g_qual_obj_tbl (l_qual_obj_index).success_criteria,
10728 												 p_comments                    => g_qual_obj_tbl (l_qual_obj_index).comments
10729 												);
10730 					  END IF;
10731 
10732 					  --
10733 					  l_qual_obj_index := g_qual_obj_tbl.NEXT (l_qual_obj_index);
10734 				   --
10735 				   END LOOP;
10736 				END IF;
10737 				-- Bug 16436529 :: Message moved outside of eligible objectives block to avoid multiple notification
10738 				-- Bug 14046389 added the message WPM_AP_ENROLL_MSG.
10739                 send_message_notification(g_qual_pop_tbl (l_qual_pop_index).person_id,'WPM_AP_ENROLL_MSG',p_plan_id,NULL);                                                                                  --auto allocation flag = 'y'
10740 				   END IF;                                                                         -- if not existing in curr plan pop
10741 			 END IF;                                                                                             -- if person eligible
10742 
10743 				l_qual_pop_index := g_qual_pop_tbl.NEXT (l_qual_pop_index);
10744 
10745 			 END LOOP;                                                                                               --- qual pop loop
10746 	--
10747 	--    ===========================================================================================
10748 	--- TTRANSFEROUT the non qualifying scorecards and the appraisals
10749 		  l_curr_sc_pop_index := g_curr_sc_pop_tbl.FIRST;
10750 		  WHILE (l_curr_sc_pop_index IS NOT NULL)
10751 		  LOOP
10752 			 BEGIN
10753 				IF (g_plan_dtls (1).status_code IN ('UPDATED', 'RESUBMITTED') AND NOT g_qual_pop_tbl.EXISTS (l_curr_sc_pop_index))
10754 				THEN
10755 				  --- delete the appraisals for the person
10756 				   IF (g_plan_dtls (1).include_appraisals_flag = 'Y')
10757 				   THEN
10758 					  --  FOR plan_appraisals IN csr_plan_appraisals(p_plan_id)
10759 					  OPEN csr_find_appr_for_scorecard (p_plan_id, g_curr_sc_pop_tbl (l_curr_sc_pop_index).scorecard_id);
10760 
10761 					  LOOP
10762 						 hr_utility.set_location ('Before transfer out _for_person', 107);
10763 
10764 						 FETCH csr_find_appr_for_scorecard
10765 						  INTO l_appr_id, l_appr_ovn, l_appr_sys_status;
10766 
10767 						 EXIT WHEN csr_find_appr_for_scorecard%NOTFOUND;
10768 
10769 						 IF l_appr_sys_status NOT IN ('COMPLETED','APPRFEEDBACK')
10770 						 THEN
10771 							UPDATE per_appraisals
10772 							   SET appraisal_system_status = 'TRANSFER_OUT'
10773 							 WHERE appraisal_id = l_appr_id;
10774 
10775 	-- revoke the participant statuses and close them.NOt deleting them if feedback is already provided.
10776 							FOR i IN csr_get_appr_part (l_appr_id)
10777 							LOOP
10778 							   UPDATE per_participants
10779 								  SET participation_status = 'CLOSED'
10780 								WHERE participant_id = i.participant_id;
10781 							END LOOP;
10782 	-- we are doing a direct update as update API will not work for terminated and traansfer employees
10783 	-- update it to transfer out so as to not show the details anywhere
10784 						 END IF;
10785 
10786 						 hr_utility.set_location ('After transfer out appraisal_for_person appraisal_id: ' || l_appr_id, 107);
10787 					  END LOOP;
10788 
10789 					  CLOSE csr_find_appr_for_scorecard;
10790 				   END IF;
10791 				   hr_personal_scorecard_api.update_scorecard
10792 											 (p_effective_date              => TRUNC (SYSDATE),
10793 											  p_scorecard_id                => g_curr_sc_pop_tbl (l_curr_sc_pop_index).scorecard_id,
10794 											  p_object_version_number       => g_curr_sc_pop_tbl (l_curr_sc_pop_index).object_version_number,
10795 											  p_duplicate_name_warning      => l_dummy,
10796 											  p_status_code                 => 'TRANSFER_OUT'
10797 											 );
10798 				--
10799 
10800 				--
10801 				END IF;
10802 			 EXCEPTION
10803 				WHEN OTHERS
10804 				THEN
10805 				   fnd_message.set_name ('PER', 'HR_50297_WPM_CP_ERROR');
10806 				   g_cp_error_txt := NVL (fnd_message.get, 'HR_50297_WPM_CP_ERROR');
10807 				   g_retcode := warning;
10808 				   g_errbuf := g_cp_error_txt;
10809 				   g_num_errors := g_num_errors + 1;
10810 
10811 				   IF g_dbg
10812 				   THEN
10813 					  op (g_error_txt, g_regular_log);
10814 				   END IF;
10815 
10816 				   IF g_dbg
10817 				   THEN
10818 					  op (SQLERRM, g_regular_log);
10819 				   END IF;
10820 
10821 				   --
10822 				   -- If the max number of errors has been exceeded, raise the error and
10823 				   -- terminate processing of this plan.
10824 				   --
10825 				   IF g_num_errors > g_max_errors
10826 				   THEN
10827 					  fnd_message.set_name ('PER', 'HR_50298_WPM_MAX_ERRORS');
10828 					  g_error_txt := NVL (fnd_message.get, 'HR_50298_WPM_MAX_ERRORS');
10829 					  g_retcode := error;
10830 					  g_errbuf := g_error_txt;
10831 					  RAISE;
10832 				   END IF;
10833 			 END;
10834 			 --------- iterate the loop
10835 			 l_curr_sc_pop_index := g_curr_sc_pop_tbl.NEXT (l_curr_sc_pop_index);
10836 		  END LOOP;
10837 	---  deenrolling logic ends
10838 	--============================================================================================
10839 			 -- populate the hierarchy for appraisal summary
10840 			 per_wpm_summary_pkg.populate_plan_hierarchy (p_plan_id => p_plan_id, p_effective_date => TRUNC (SYSDATE));
10841 		  END IF;                                                                                                  -- obj setting
10842 		  COMMIT ;
10843 	   END reevaluate_plan_pop;
10844 
10845 	--
10846 	   PROCEDURE republish_plan (
10847 		  p_effective_date              IN              DATE,
10848 		  p_plan_id                     IN              NUMBER,
10849 		  p_object_version_number       IN OUT NOCOPY   NUMBER,
10850 		  p_reverse_mode                IN              VARCHAR2 DEFAULT 'N',
10851 		  p_what_if                     IN              VARCHAR2 DEFAULT 'N',
10852 		  p_log_output                  IN              VARCHAR2 DEFAULT 'N',
10853 		  p_action_parameter_group_id   IN              NUMBER DEFAULT NULL,
10854 		  p_item_type                   IN              VARCHAR2 DEFAULT 'HRWPM',
10855 		  p_wf_process                  IN              VARCHAR2 DEFAULT 'HR_NOTIFY_WPM_PLAN_POP_PRC',
10856 		  p_status_code                 IN              VARCHAR2,
10857 		  p_republish_values            IN              VARCHAR2
10858 	   )
10859 	   IS
10860           l_proc                    VARCHAR2 (72)                                 := g_package || 'republish_plan';
10861 		  l_logging                 pay_action_parameters.parameter_value%TYPE;
10862 		  l_debug                   BOOLEAN                                       := FALSE;
10863 		  l_effective_date          DATE                                          := TRUNC (NVL (p_effective_date, SYSDATE));
10864 		  l_object_version_number   NUMBER;
10865 		  l_status_code             per_perf_mgmt_plans.status_code%TYPE;
10866 		  l_dummy                   BOOLEAN;
10867 		  --
10868 		  l_scorecard_id            per_personal_scorecards.scorecard_id%TYPE;
10869 		  --
10870 		  l_message_count           NUMBER                                        := 0;
10871 		  l_message                 VARCHAR2 (256);
10872 		  l_qual_pop_index          BINARY_INTEGER;
10873 		  l_curr_sc_pop_index       BINARY_INTEGER;
10874 		  l_qual_obj_index          BINARY_INTEGER;
10875 		  l_plan_aprsl_pds_index    BINARY_INTEGER;
10876 		  l_curr_sc_obj_index       BINARY_INTEGER;
10877 		  l_appr_ret_status         VARCHAR2 (1);
10878 		  l_check_elig              VARCHAR2 (1);
10879 		  l_check_elig_person       VARCHAR2 (1);
10880 		  --
10881 		  l_submit_new_req          BOOLEAN                                       := TRUE;
10882 		  l_conc_request_id         NUMBER                                        := 0;
10883 		  e                         EXCEPTION;
10884 		  l_ret                     BOOLEAN;
10885 		  l_message_req             VARCHAR (2000);
10886 
10887 			--
10888 		  -- Cursor to get the  Participants of an appraisal other than MA
10889 		  CURSOR csr_get_appr_part (p_appraisal_id per_appraisals.appraisal_id%TYPE)
10890 		  IS
10891 			 SELECT participant_id, object_version_number, participation_type
10892 			   FROM per_participants
10893 			  WHERE participation_in_id = p_appraisal_id
10894 				AND participation_in_table = 'PER_APPRAISALS'
10895 				AND participation_in_column = 'APPRAISAL_ID'
10896 				AND participation_type <> 'MAINAP'
10897 				AND participation_status = 'OPEN';
10898 
10899 		  -- Plan record
10900 		  CURSOR csr_get_plan_rec
10901 		  IS
10902 			 SELECT *
10903 			   FROM per_perf_mgmt_plans
10904 			  WHERE plan_id = p_plan_id;
10905 
10906 		  -- Scorecard Objectives
10907 		  CURSOR csr_sc_objectives (p_scorecard_id NUMBER)
10908 		  IS
10909 			 SELECT objective_id, object_version_number
10910 			   FROM per_objectives
10911 			  WHERE scorecard_id = p_scorecard_id;
10912 
10913 		  CURSOR csr_plan_appraisals (plan_id per_appraisals.plan_id%TYPE)
10914 		  IS
10915 			 SELECT appraisal_id, object_version_number
10916 			   FROM per_appraisals
10917 			  WHERE plan_id = plan_id;
10918 
10919 		  CURSOR csr_find_appr_for_scorecard (
10920 			 p_plan_id        per_appraisals.plan_id%TYPE,
10921 			 p_scorecard_id   per_personal_scorecards.scorecard_id%TYPE
10922 		  )
10923 		  IS
10924 			 SELECT pa.appraisal_id, pa.object_version_number, pa.appraisal_system_status
10925 			   FROM per_appraisals pa, per_personal_scorecards pps
10926 			  WHERE pa.plan_id = p_plan_id AND appraisee_person_id = pps.person_id AND pps.scorecard_id = p_scorecard_id;
10927 
10928 		  -- cursor added
10929 		  -- 23-Jun-2009 schowdhu Eligibility Profile Enhc.
10930 		  CURSOR get_elig_obj_id_for_person (p_plan_id IN per_perf_mgmt_plans.plan_id%TYPE)
10931 		  IS
10932 			 SELECT elig.elig_obj_id
10933 			   FROM ben_elig_obj_f elig
10934 			  WHERE elig.table_name = 'PER_PERF_MGMT_PLANS'
10935 				AND elig.column_name = 'PLAN_ID'
10936 				AND elig.COLUMN_VALUE = p_plan_id
10937 				AND TRUNC (SYSDATE) BETWEEN elig.effective_start_date AND elig.effective_end_date;
10938 
10939 		  CURSOR get_person_name (p_person_id IN per_all_people_f.person_id%TYPE)
10940 		  IS
10941 			 SELECT full_name
10942 			   FROM per_all_people_f ppf
10943 			  WHERE ppf.person_id = p_person_id AND l_effective_date BETWEEN ppf.effective_start_date AND ppf.effective_end_date;
10944 
10945 		  l_plan_rec                per_perf_mgmt_plans%ROWTYPE;
10946 		  l_obj_date                DATE                                          := TRUNC (SYSDATE);
10947 		  l_scorecard_status_code   VARCHAR2 (30);
10948 		  l_process_date            DATE;
10949 		  l_process_date_char       VARCHAR2 (50);
10950 		  l_request_id              NUMBER;
10951 		  l_appr_ovn                per_appraisals.object_version_number%TYPE;
10952 		  l_appr_id                 per_appraisals.appraisal_id%TYPE;
10953 		  l_appr_sys_status         per_appraisals.appraisal_system_status%TYPE;
10954 		  l_appraiser_person_id     per_appraisals.appraiser_person_id%TYPE;
10955 		  l_elig_obj_id             ben_elig_obj_f.elig_obj_id%TYPE;
10956 		  l_person_name             per_all_people_f.full_name%TYPE;
10957 		  l_task_codes              VARCHAR2 (200);
10958 		  t_task_codes              DBMS_UTILITY.lname_array;
10959 		  l_task_cnt                BINARY_INTEGER;
10960 	   BEGIN
10961 		  --
10962 		  -- Initialize logging
10963 		  --
10964 		  initialize_logging (p_action_parameter_group_id => p_action_parameter_group_id, p_log_output => p_log_output);
10965 
10966 		  --
10967 		  IF g_dbg
10968 		  THEN
10969 			 op ('Entering:' || l_proc, g_regular_log, 10);
10970 		  END IF;
10971 
10972 		  --
10973 		  -- Get Plan record
10974 		  --
10975 		  OPEN csr_get_plan_rec;
10976 
10977 		  FETCH csr_get_plan_rec
10978 		   INTO g_plan_dtls (1);
10979 
10980 		  CLOSE csr_get_plan_rec;
10981 
10982 		  l_plan_rec := g_plan_dtls (1);
10983 
10984 		  --
10985 		  IF g_dbg
10986 		  THEN
10987 			 op (l_proc, g_debug_log, 20);
10988 		  END IF;
10989 
10990 		  l_request_id := fnd_global.conc_request_id;
10991 
10992 		  IF g_dbg
10993 		  THEN
10994 			 op ('Plan Name: ' || SUBSTR (l_plan_rec.plan_name, 1, 40), g_debug_log, 21);
10995 		  END IF;
10996 
10997 		  IF g_dbg
10998 		  THEN
10999 			 op ('Concurrent Request ID: ' || TO_CHAR (l_request_id), g_debug_log, 22);
11000 		  END IF;
11001 
11002 		  --
11003 		  --
11004 		  l_task_codes := RTRIM (LTRIM (p_republish_values, ','), ',');
11005 		  DBMS_UTILITY.comma_to_table (l_task_codes, l_task_cnt, t_task_codes);
11006 
11007 		  IF NVL (l_task_cnt, 0) = 0
11008 		  THEN
11009 			 op ('Task codes not passed. Exiting..' || l_task_cnt, g_debug_log, 23);
11010 			 RETURN;
11011 		  END IF;
11012 
11013 		  --
11014 		  --
11015 		  FOR i IN 1 .. l_task_cnt
11016 		  LOOP                                                                                                                       --
11017 			 IF hr_api.not_exists_in_hr_lookups (p_effective_date      => l_effective_date,
11018 												 p_lookup_type         => 'HR_WPM_PUBLISH_TASKS',
11019 												 p_lookup_code         => t_task_codes (i)
11020 												)
11021 			 THEN
11022 				op ('Invalid Task Code. Exiting..' || t_task_codes (i), g_debug_log, 23);
11023 				RETURN;
11024 			 END IF;
11025 			 IF i = 1 THEN
11026 				populate_qual_plan_population (l_plan_rec, l_effective_date);
11027 				populate_curr_plan_population (p_plan_id);
11028 				populate_qual_objectives (g_plan_dtls (1).start_date, g_plan_dtls (1).end_date);
11029 			 END IF;
11030 
11031 			 IF t_task_codes (i) = 'REALLOCATE_OBJ'
11032 			 THEN
11033                 op ('Entering Reallocate Objective for Plan Id: ' || TO_CHAR (p_plan_id), g_debug_log, 7);
11034 				hr_utility.set_location('Entering Reallocate Objective for Plan Id: ' || TO_CHAR (p_plan_id), 7);
11035 				reallocate_objectives (p_plan_id);
11036 			 ELSIF t_task_codes (i) = 'RESET_SC'
11037 			 THEN
11038                 op ('Entering Reset Scorecard for Plan Id: ' || TO_CHAR (p_plan_id), g_debug_log, 7);
11039 				hr_utility.set_location('Entering Reset Scorecard for Plan Id: ' || TO_CHAR (p_plan_id), 7);
11040 				log_message ('Calling reset_sc');
11041 				reset_scorecards (p_plan_id);
11042 			 ELSIF t_task_codes (i) = 'REFRESH_SC'
11043 			 THEN
11044                 op ('Entering Refresh Scoreacard for Plan Id: ' || TO_CHAR (p_plan_id), g_debug_log, 7);
11045 				hr_utility.set_location('Entering Refresh Scoreacard for Plan Id: ' || TO_CHAR (p_plan_id), 7);
11046 				refresh_scorecards (p_plan_id);
11047 			 ELSIF t_task_codes (i) = 'REBUILD_SUP_HIER'
11048 			 THEN
11049                 op ('Entering Rebuild Supervisor Heirarchy for Plan Id: ' || TO_CHAR (p_plan_id), g_debug_log, 7);
11050 				hr_utility.set_location('Entering Rebuild Supervisor Heirarchy for Plan Id: ' || TO_CHAR (p_plan_id), 7);
11051 				rebuild_sup_hierarchy (p_plan_id);
11052 			 ELSIF t_task_codes (i) = 'REEVAL_PLAN_POP'
11053 			 THEN
11054                 op ('Entering Re-evaluate Plan Population for Plan Id: ' || TO_CHAR (p_plan_id), g_debug_log, 7);
11055 				hr_utility.set_location('Entering Re-evaluate Plan Population for Plan Id: ' || TO_CHAR (p_plan_id), 7);
11056 				reevaluate_plan_pop (p_plan_id);
11057                 hr_utility.set_location('Delete Existing qualified plan Population.', 777);
11058                 g_qual_pop_tbl.DELETE;
11059                 hr_utility.set_location('Repopulate the Qualified Plan Population.', 777);
11060                 populate_qual_plan_population (l_plan_rec, l_effective_date);
11061 				hr_utility.set_location('Reevaluate plan population finished. Calling Rebuild Supervisor Hierarchy with Plan id : ' || TO_CHAR (p_plan_id), 7);
11062 				rebuild_sup_hierarchy (p_plan_id);
11063 			 ELSE
11064 				op ('Invalid Task Code. Exiting..' || t_task_codes (i), g_debug_log, 23);
11065 				RETURN;
11066 			 END IF;
11067 		  END LOOP;                                                                                                --- task codes LOOP
11068 	   END republish_plan;
11069 
11070 	--
11071 	   PROCEDURE plan_republish (
11072 		  errbuf                        OUT NOCOPY      VARCHAR2,
11073 		  retcode                       OUT NOCOPY      NUMBER,
11074 		  p_effective_date              IN              VARCHAR2,
11075 		  p_plan_id                     IN              NUMBER,
11076 		  p_object_version_number       IN              NUMBER DEFAULT NULL,
11077 		  p_reverse_mode                IN              VARCHAR2 DEFAULT 'N',
11078 		  p_what_if                     IN              VARCHAR2 DEFAULT 'N',
11079 		  p_log_output                  IN              VARCHAR2 DEFAULT 'N',
11080 		  p_action_parameter_group_id   IN              NUMBER DEFAULT NULL,
11081 		  p_item_type                   IN              VARCHAR2 DEFAULT 'HRWPM',
11082 		  p_wf_process                  IN              VARCHAR2 DEFAULT 'HR_NOTIFY_WPM_PLAN_POP_PRC',
11083 		  p_status_code                 IN              VARCHAR2 DEFAULT NULL,
11084 		  p_republish_values            IN              VARCHAR2
11085 	   )
11086 	   IS
11087 		  l_object_version_number   NUMBER;
11088 		  l_proc                    VARCHAR2 (72)                 := g_package || 'plan_republish';
11089 		  l_pl_rec                  per_perf_mgmt_plans%ROWTYPE;
11090 		  l_dummy                   VARCHAR2 (10);
11091 
11092 		  CURSOR csr_plan (p_plan_id IN NUMBER)
11093 		  IS
11094 			 SELECT *
11095 			   FROM per_perf_mgmt_plans
11096 			  WHERE plan_id = p_plan_id;
11097 
11098 		  CURSOR csr_sc_exist (p_plan_id IN NUMBER)
11099 		  IS
11100 			 SELECT 'Y'
11101 			   FROM DUAL
11102 			  WHERE EXISTS (SELECT 'x'
11103 							  FROM per_personal_scorecards
11104 							 WHERE plan_id = p_plan_id);
11105 
11106 		  l_wpm_batch_action_id     VARCHAR2 (30);
11107 		  l_effective_date          DATE;
11108 	   BEGIN
11109 		  hr_utility.set_location ('Entering:' || l_proc, 10);
11110 		  g_errbuf := NULL;
11111 		  g_retcode := NULL;
11112 		  --
11113 		  hr_api.mandatory_arg_error (p_api_name            => 'plan_republish',
11114 									  p_argument            => 'p_effective_date',
11115 									  p_argument_value      => p_effective_date
11116 									 );
11117 		  hr_api.mandatory_arg_error (p_api_name => 'plan_republish', p_argument => 'p_plan_id', p_argument_value => p_plan_id);
11118 		  hr_api.mandatory_arg_error (p_api_name            => 'plan_republish',
11119 									  p_argument            => 'p_republish_values',
11120 									  p_argument_value      => p_republish_values
11121 									 );
11122 		  --
11123 		  l_effective_date := fnd_date.canonical_to_date (p_effective_date);
11124 
11125 		  --
11126 		  -- WPM Logging Changes
11127 		  SELECT per_wpm_batch_actions_s.NEXTVAL
11128 			INTO l_wpm_batch_action_id
11129 			FROM DUAL;
11130 
11131 		  hr_wpm_mass_apr_push.l_current_wpm_batch_action_id := l_wpm_batch_action_id;
11132 
11133 		  INSERT INTO per_wpm_batch_actions
11134 					  (wpm_batch_action_id, conc_request_id, conc_program_name, plan_id, appraisal_period_id, status, start_date,
11135 					   end_date
11136 					  )
11137 			   VALUES (l_wpm_batch_action_id, fnd_global.conc_request_id, 'PERPLNREPUB', p_plan_id, NULL, 'PENDING', SYSDATE,
11138 					   NULL
11139 					  );
11140 
11141 		  --
11142 		  COMMIT;
11143 
11144 		  --
11145 		  OPEN csr_plan (p_plan_id);
11146 
11147 		  FETCH csr_plan
11148 		   INTO l_pl_rec;
11149 
11150 		  IF csr_plan%NOTFOUND
11151 		  THEN
11152 			 CLOSE csr_plan;
11153 
11154 			 log_message ('Invalid Plan ID entered: ' || p_plan_id || ' Exiting.');
11155 			 errbuf := 'Invalid Plan ID entered: ' || p_plan_id || ' Exiting.';
11156 			 retcode := 2;
11157 			 RETURN;
11158 		  END IF;
11159 
11160 		  CLOSE csr_plan;
11161 
11162 		  IF l_pl_rec.status_code = 'DRAFT'
11163 		  THEN
11164 			 log_message ('Plan being published for the first time. Cannot republish. Exiting.');
11165 			 errbuf := 'Plan being published for the first time. Cannot republish. Exiting.';
11166 			 retcode := 2;
11167 			 RETURN;
11168 		  END IF;
11169 
11170 		  OPEN csr_sc_exist (p_plan_id);
11171 
11172 		  FETCH csr_sc_exist
11173 		   INTO l_dummy;
11174 
11175 		  CLOSE csr_sc_exist;
11176 
11177 		  IF NVL (l_dummy, 'N') = 'N'
11178 		  THEN
11179 			 log_message ('Plan being published for the first time. Cannot republish. Exiting.');
11180 			 errbuf := 'Plan being published for the first time. Cannot republish. Exiting.';
11181 			 retcode := 2;
11182 			 RETURN;
11183 		  END IF;
11184 
11185 		  -- WPM Logging Changes  Post Review
11186 		  -- to avoid caching issues
11187 		  hr_wpm_mass_apr_push.g_wpm_person_actions.DELETE;
11188 		  hr_wpm_mass_apr_push.log_records_index := NULL;
11189 		  l_object_version_number := l_pl_rec.object_version_number;
11190 		  --
11191 		  --  Call the publish plan
11192 		  --
11193 		  republish_plan (p_effective_date                 => l_effective_date,
11194 						  p_plan_id                        => p_plan_id,
11195 						  p_object_version_number          => l_object_version_number,
11196 						  p_reverse_mode                   => p_reverse_mode,
11197 						  p_what_if                        => p_what_if,
11198 						  p_log_output                     => p_log_output,
11199 						  p_action_parameter_group_id      => p_action_parameter_group_id,
11200 						  p_item_type                      => p_item_type,
11201 						  p_wf_process                     => p_wf_process,
11202 						  p_status_code                    => p_status_code,
11203 						  p_republish_values               => p_republish_values
11204 						 );
11205 		  --
11206 		  errbuf := g_errbuf;
11207 		  retcode := g_retcode;
11208 		  --
11209 		  -- WPM Logging Changes
11210 		  hr_wpm_mass_apr_push.print_cache ();
11211 
11212 		  UPDATE per_wpm_batch_actions
11213 			 SET end_date = SYSDATE,
11214 				 status = DECODE (g_retcode, 0, 'SUCCESS', 'WARNING')
11215 		   WHERE wpm_batch_action_id = hr_wpm_mass_apr_push.l_current_wpm_batch_action_id;
11216 
11217 		  UPDATE per_perf_mgmt_plans
11218 			 SET status_code = 'PUBLISHED'
11219 		  WHERE plan_id = p_plan_id;
11220 		  COMMIT;
11221 		  hr_utility.set_location ('Leaving:' || l_proc, 80);
11222 	   EXCEPTION
11223 		  WHEN OTHERS
11224 		  THEN
11225 			 ROLLBACK;
11226 			 -- WPM Logging Changes
11227 			 hr_wpm_mass_apr_push.print_cache ();
11228 			 log_message('Inside Exception in Plan_republish');
11229 			 log_message(SQLERRM);
11230 
11231 			 UPDATE per_wpm_batch_actions
11232 				SET status = 'ERROR',
11233 					end_date = SYSDATE
11234 			  WHERE wpm_batch_action_id = hr_wpm_mass_apr_push.l_current_wpm_batch_action_id;
11235 
11236 			 COMMIT;
11237 
11238 			 --
11239 			 -- update status of the plan to 'Failed'
11240 			 --
11241 			 UPDATE per_perf_mgmt_plans
11242 				SET status_code = 'FAILED'
11243 			  WHERE plan_id = p_plan_id;
11244 
11245 			 COMMIT;
11246 			 --
11247 			 errbuf := g_errbuf;
11248 			 retcode := g_retcode;
11249 	   --
11250 	   END plan_republish;
11251 	END hr_perf_mgmt_plan_internal;