DBA Data[Home] [Help]

PACKAGE BODY: APPS.PA_ASGMT_WFSTD

Source


1 PACKAGE BODY PA_ASGMT_WFSTD AS
2 --  $Header: PAWFAAPB.pls 120.13.12010000.9 2008/12/12 09:16:02 kjai ship $
3 -- forward declarations
4 --------------------------------------------------------------------------------------------------------------
5 -- This procedure prints the text which is being passed as the input
6 -- Input parameters
7 -- Parameters                   Type           Required  Description
8 --  p_log_msg                   VARCHAR2        YES      It stores text which you want to print on screen
9 -- Out parameters
10 ----------------------------------------------------------------------------------------------------------------
11 PROCEDURE log_message (p_log_msg IN VARCHAR2)
12 IS
13 BEGIN
14     --dbms_output.put_line('Log : ' || p_log_msg);
15         NULL;
16 END log_message;
17 
18 PROCEDURE Capture_approver_response (p_item_type IN VARCHAR2,
19                                      p_item_key  IN VARCHAR2) ;
20 
21 PROCEDURE Set_Nf_Error_Msg_Attr (p_item_type IN VARCHAR2,
22                      p_item_key  IN VARCHAR2,
23                  p_msg_count IN NUMBER,
24                  p_msg_data IN VARCHAR2 ) ;
25 PROCEDURE get_primary_contact_info
26                            (p_resource_id  IN NUMBER
27                           , p_assignment_id IN NUMBER
28                           , p_approver1_person_id IN NUMBER
29                           , p_approver1_type IN      VARCHAR2
30                           , p_approver2_person_id IN NUMBER
31                           , p_approver2_type IN      VARCHAR2
32                           , x_PrimaryContactId     OUT NOCOPY NUMBER ); --File.Sql.39 bug 4440895
33 
34 PROCEDURE populate_wf_performers
35     ( p_wf_type_code IN VARCHAR2
36      ,p_item_type    IN VARCHAR2
37      ,p_item_key     IN VARCHAR2
38      ,p_object_id1  IN VARCHAR2
39      ,p_object_id2  IN VARCHAR2
40      ,p_in_performers_tbl PA_CLIENT_EXTN_ASGMT_WF.Users_List_Tbltyp
41      ,p_current_approver_flag  IN VARCHAR2
42      ,x_number_of_performers OUT NOCOPY NUMBER ); --File.Sql.39 bug 4440895
43 
44 PROCEDURE get_wf_performer (p_wf_type_code IN VARCHAR2,
45                 p_item_type    IN VARCHAR2,
46                 p_item_key     IN VARCHAR2,
47                 p_routing_order IN NUMBER,
48                     p_object_id1  IN VARCHAR2 ,
49                 x_performer_name OUT NOCOPY VARCHAR2, --File.Sql.39 bug 4440895
50                 x_performer_type OUT NOCOPY VARCHAR2 ); --File.Sql.39 bug 4440895
51 
52 PROCEDURE Set_approver_comments (p_apprvl_item_type VARCHAR2,
53                  p_apprvl_item_key  VARCHAR2,
54                  p_item_type  VARCHAR2,
55                  p_item_key  VARCHAR2,
56                  p_assignment_id NUMBER ) ;
57 
58 PROCEDURE Set_Comment_Attributes (p_item_type IN VARCHAR2,
59                           p_item_key  IN VARCHAR2,
60                   p_rect_type IN VARCHAR2 );
61 
62 /*PROCEDURE Check_And_Get_Proj_Customer ( p_project_id IN NUMBER
63                        ,x_customer_id OUT NUMBER
64                        ,x_customer_name OUT VARCHAR2 );*/
65 
66 PROCEDURE   Set_NF_Subject_and_Desc  (p_item_type       IN VARCHAR2,
67                       p_item_key        IN VARCHAR2,
68                       p_assignment_type IN VARCHAR2,
69                       p_reapproval_flag IN VARCHAR2,
70                       p_msg_type        IN VARCHAR2 );
71 
72 -- end forward declarations
73 
74 PROCEDURE Start_Workflow (  p_project_id           IN NUMBER DEFAULT NULL
75                           , p_assignment_id        IN NUMBER
76               , p_status_code          IN VARCHAR2 DEFAULT NULL
77                           , p_person_id            IN NUMBER DEFAULT NULL
78                           , p_wf_item_type         IN VARCHAR2
79                           , p_wf_process           IN VARCHAR2
80               , p_approver1_person_id  IN NUMBER DEFAULT NULL
81               , p_approver1_type       IN VARCHAR2 DEFAULT NULL
82               , p_approver2_person_id  IN NUMBER DEFAULT NULL
83               , p_approver2_type       IN VARCHAR2  DEFAULT NULL
84               , p_apprvl_item_type     IN VARCHAR2 DEFAULT NULL
85               , p_apprvl_item_key      IN VARCHAR2 DEFAULT NULL
86                           , p_conflict_group_id    IN NUMBER DEFAULT NULL
87               , x_msg_count            OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
88               , x_msg_data             OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
89               , x_return_status        OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
90               , x_error_message_code   OUT NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
91 IS
92 
93 CURSOR l_assignments_csr IS
94 SELECT ppa.assignment_id,
95        ppa.assignment_name,
96        ppa.assignment_effort,
97        ppa.additional_information,
98        ppa.description,
99        ppa.note_to_approver,
100        ppa.project_id,
101        ppa.resource_id,
102        ppa.start_date,
103        ppa.end_date,
104        ppa.status_code,
105        ppa.apprvl_status_code,
106        ppa.pending_approval_flag,
107        ppa.assignment_type,
108        ppa.revenue_bill_rate,
109        ppa.revenue_currency_code,
110        ppa.bill_rate_override,
111        ppa.bill_rate_curr_override,
112        ppa.markup_percent_override,
113        ppa.fcst_tp_amount_type_name,
114        ppa.tp_rate_override,
115        ppa.tp_currency_override,
116        ppa.tp_calc_base_code_override,
117        ppa.tp_percent_applied_override,
118        ppa.work_type_name,
119        ppa.transfer_price_rate,   --  Added for bug 3051110
120        ppa.transfer_pr_rate_curr
121 FROM pa_project_assignments_v ppa
122 WHERE assignment_id = p_assignment_id;
123 
124 CURSOR csr_get_override_basis_name (p_override_basis_code IN VARCHAR2) IS
125 SELECT plks.meaning
126 FROM   pa_lookups plks
127 WHERE  plks.lookup_type = 'CC_MARKUP_BASE_CODE'
128 AND    plks.lookup_code = p_override_basis_code;
129 
130 CURSOR l_stus_csr (c_status_code IN VARCHAR2) IS
131 SELECT ps.wf_success_status_code,
132        ps.wf_failure_status_code,
133        ps.project_status_name
134 FROM   pa_project_statuses ps
135 WHERE  project_status_code = c_status_code;
136 
137 CURSOR l_resource_csr(l_resource_id IN NUMBER, p_start_date IN DATE) IS
138 SELECT per.full_name resource_name,
139        rta.person_id resource_person_id,
140        rta.resource_id resource_id,
141        hou.name resource_organization_name,
142        assign.supervisor_id manager_id
143 FROM   per_people_f per,
144        per_assignments_f assign,
145        hr_all_organization_units hou,
146        pa_resource_txn_attributes rta
147 WHERE  rta.resource_id = l_resource_id
148 AND    rta.person_id = per.person_id
149 AND    rta.person_id = assign.person_id
150 AND    assign.primary_flag = 'Y'
151 AND    assign.assignment_type in ('E','C')
152 AND    hou.organization_id = assign.organization_id
153 AND    p_start_date BETWEEN assign.effective_start_date AND assign.effective_end_date
154 AND    p_start_date BETWEEN per.effective_start_date AND per.effective_end_date  /* 2983985 - Added this condition */
155 ;
156 
157 
158 CURSOR l_projects_csr(l_project_id IN NUMBER) IS
159 SELECT pap.project_id project_id,
160        pap.name name,
161        pap.segment1 segment1,
162        pap.carrying_out_organization_id carrying_out_organization_id,
163        pap.location_id,
164        hr.name organization_name,
165        NVL(pt.administrative_flag,'N') admin_flag
166 FROM pa_projects_all pap,
167      hr_all_organization_units hr,
168      pa_project_types_all pt
169 WHERE pap.project_id = l_project_id
170 AND   pap.carrying_out_organization_id =
171       hr.organization_id
172 AND   pap.org_id = pt.org_id    -- Added for Bug 5389093
173 AND   pt.project_type = pap.project_type;
174 
175 /* Commenting Below and changing cursor query for bug 7640483
176 CURSOR l_prev_asgmt_info_csr (l_assignment_id IN NUMBER)
177 IS
178 SELECT assignment_effort prev_effort,
179       (trunc(end_date) -
180       (trunc(start_date)+1)) prev_duration
181 FROM pa_assignments_history
182 WHERE assignment_id = l_assignment_id
183 AND   nvl(last_approved_flag,'N') = 'Y';
184 */
185 
186 CURSOR l_prev_asgmt_info_csr (l_assignment_id IN NUMBER)
187 IS
188 SELECT assignment_effort prev_effort,
189       (trunc(end_date) - trunc(start_date) + 1) prev_duration
190 FROM pa_assignments_history
191 WHERE assignment_id = l_assignment_id
192 AND   nvl(last_approved_flag,'N') = 'Y';
193 
194 l_assignments_rec l_assignments_csr%ROWTYPE;
195 l_resource_rec l_resource_csr%ROWTYPE;
196 l_projects_rec l_projects_csr%ROWTYPE;
197 l_prev_asgmt_info_rec l_prev_asgmt_info_csr%ROWTYPE;
198 l_asgmt_details_url      VARCHAR2(600);
199 l_resource_details_url   VARCHAR2(600);
200 l_resource_schedules_url VARCHAR2(600);
201 l_itemkey  VARCHAR2(30);
202 l_responsibility_id       NUMBER;
203 l_resp_appl_id            NUMBER;
204 l_wf_started_date         DATE;
205 l_wf_started_by_id        NUMBER;
206 l_wf_started_by_full_name     per_people_f.full_name%TYPE;
207 l_wf_started_by_email_address per_people_f.email_address%TYPE;
208 l_wf_started_by_username      fnd_user.user_name%TYPE;
209 l_display_name        wf_users.display_name%TYPE; ---- VARCHAR2(200); Changed for bug 3267790
210 l_project_manager_person_id  NUMBER ;
211 l_project_manager_name    per_all_people_f.full_name%TYPE;  ---- VARCHAR2(200);  Changed for bug 3267790
212 l_project_manager_uname   wf_users.name%TYPE;        ---- VARCHAR2(200); Changed for bug 3267790
213 l_project_party_id        NUMBER ;
214 l_project_role_id         NUMBER ;
215 l_project_role_name       pa_project_role_types.meaning%TYPE; ---- VARCHAR2(80);  Changed for bug 3267790
216 l_approver1_user_name     wf_users.name%TYPE;        ---- VARCHAR2(200); Changed for bug 3267790
217 l_approver2_user_name     wf_users.name%TYPE;        ---- VARCHAR2(200); Changed for bug 3267790
218 l_approver1_type          VARCHAR2(200);
219 l_approver2_type          VARCHAR2(200);
220 l_apprvl_nf_rec1_uname    wf_users.name%TYPE;        ---- VARCHAR2(200); Changed for bug 3267790
221 l_apprvl_nf_rec2_uname    wf_users.name%TYPE;        ---- VARCHAR2(200); Changed for bug 3267790
222 l_apprvl_nf_rec3_uname    wf_users.name%TYPE;        ---- VARCHAR2(200); Changed for bug 3267790
223 l_apprvl_nf_rec4_uname    wf_users.name%TYPE;        ---- VARCHAR2(200); Changed for bug 3267790
224 l_apprvl_nf_rec1_utype    VARCHAR2(30);
225 l_apprvl_nf_rec2_utype    VARCHAR2(30);
226 l_apprvl_nf_rec3_utype    VARCHAR2(30);
227 l_apprvl_nf_rec4_utype    VARCHAR2(30);
228 l_apprvl_nf_rec1_person_id NUMBER := 0;
229 l_apprvl_nf_rec2_person_id NUMBER := 0;
230 l_apprvl_nf_rec3_person_id NUMBER := 0;
231 l_apprvl_nf_rec4_person_id NUMBER := 0;
232 
233 l_reject_nf_rec1_uname    wf_users.name%TYPE;        ---- VARCHAR2(200); Changed for bug 3267790
234 l_reject_nf_rec2_uname    wf_users.name%TYPE;        ---- VARCHAR2(200); Changed for bug 3267790
235 l_reject_nf_rec3_uname    wf_users.name%TYPE;        ---- VARCHAR2(200); Changed for bug 3267790
236 l_reject_nf_rec4_uname    wf_users.name%TYPE;        ---- VARCHAR2(200); Changed for bug 3267790
237 l_reject_nf_rec1_utype    VARCHAR2(30);
238 l_reject_nf_rec2_utype    VARCHAR2(30);
239 l_reject_nf_rec3_utype    VARCHAR2(30);
240 l_reject_nf_rec4_utype    VARCHAR2(30);
241 l_reject_nf_rec1_person_id NUMBER := 0;
242 l_reject_nf_rec2_person_id NUMBER := 0;
243 l_reject_nf_rec3_person_id NUMBER := 0;
244 l_reject_nf_rec4_person_id NUMBER := 0;
245 
246 l_cancel_nf_rec1_uname     wf_users.name%TYPE;       ---- VARCHAR2(200); Changed for bug 3267790
247 l_cancel_nf_rec2_uname     wf_users.name%TYPE;       ---- VARCHAR2(200); Changed for bug 3267790
248 l_cancel_nf_rec3_uname     wf_users.name%TYPE;       ---- VARCHAR2(200); Changed for bug 3267790
249 l_cancel_nf_rec4_uname     wf_users.name%TYPE;       ---- VARCHAR2(200); Changed for bug 3267790
250 l_cancel_nf_rec1_utype    VARCHAR2(30);
251 l_cancel_nf_rec2_utype    VARCHAR2(30);
252 l_cancel_nf_rec3_utype    VARCHAR2(30);
253 l_cancel_nf_rec4_utype    VARCHAR2(30);
254 l_cancel_nf_rec1_person_id NUMBER := 0;
255 l_cancel_nf_rec2_person_id NUMBER := 0;
256 l_cancel_nf_rec3_person_id NUMBER := 0;
257 l_cancel_nf_rec4_person_id NUMBER := 0;
258 l_number_of_approvers     NUMBER := 0;
259 l_number_of_apprvl_nf_rects  NUMBER := 0;
260 l_number_of_reject_nf_rects  NUMBER := 0;
261 l_number_of_cancel_nf_rects  NUMBER := 0;
262 
263 l_return_status           VARCHAR2(1);
264 l_error_message_code      VARCHAR2(30);
265 l_wf_success_status_code      pa_project_statuses.project_status_code%TYPE;
266 l_wf_failure_status_code      pa_project_statuses.project_status_code%TYPE;
267 l_project_status_name         pa_project_statuses.project_status_name%TYPE;
268 l_resource_person_id NUMBER;
269 l_reapproval_flag  VARCHAR2(1);
270 l_country_name            VARCHAR2(200);
271 l_city                    VARCHAR2(200);
272 l_region                  VARCHAR2(200);
273 l_country_code            VARCHAR2(30);
274 l_err_code            NUMBER := 0;
275 l_err_stage           VARCHAR2(2000);
276 l_err_stack           VARCHAR2(2000);
277 l_msg_count    NUMBER ;
278 l_msg_index_out    NUMBER ;
279 l_msg_data     VARCHAR2(2000);
280 l_data             VARCHAR2(2000);
281 l_primarycontactid NUMBER := 0;
282 l_primarycontactname  wf_users.name%TYPE;        ---- VARCHAR2(240); Changed for bug 3267790
283 l_resource_start_date  DATE;
284 
285 -- 4363092 TCA changes, replaced RA views with HZ tables
286 /*
287 l_customer_id      ra_customers.customer_id%TYPE;
288 l_customer_name    ra_customers.customer_name%TYPE;
289 */
290 
291 l_customer_id                hz_cust_accounts.cust_account_id%TYPE;
292 l_customer_name              hz_parties.party_name%TYPE;
293 
294 -- 4363092 end
295 
296 l_workflow_started_by_uname fnd_user.user_name%TYPE; ----VARCHAR2(100); Changed for bug 3267790 /* Increased length from 30 to 100 for bug 3148857 */
297 l_waiting_time     NUMBER := 0;
298 l_number_of_reminders NUMBER := 0;
299 l_save_threshold      NUMBER;
300 l_override_basis_name VARCHAR2(80) := NULL;
301 
302 l_last_approver_uname fnd_user.USER_NAME%TYPE; --- VARCHAR2(240); -- Added for the bug 3817940
303 l_res_manager_id PER_PEOPLE_F.PERSON_ID%TYPE;  -- Added for bug 4334741
304 BEGIN
305         -- dbms_output.put_line ('inside start workflow');
306     x_return_status := FND_API.G_RET_STS_SUCCESS;
307         /*
308     IF fnd_msg_pub.count_msg > 0 THEN
309        insert_into_temp ('msgs in stack inside start_workflow is',
310                   fnd_msg_pub.count_msg);
311         END IF;
312         */
313     fnd_msg_pub.initialize;
314         pa_debug.init_err_stack ('pa_asgmt_wfstd.start_workflow');
315     x_msg_count := 0;
316  -- Create the unique item key to launch WF with
317         SELECT pa_prm_wf_item_key_s.nextval
318         INTO l_itemkey
319         FROM dual;
320 
321     l_wf_started_by_id  := FND_GLOBAL.user_id;
322     l_responsibility_id := FND_GLOBAL.resp_id;
323     l_resp_appl_id      := FND_GLOBAL.resp_appl_id;
324 
325     FND_GLOBAL.Apps_Initialize ( user_id => l_wf_started_by_id
326                                , resp_id => l_responsibility_id
327                                , resp_appl_id => l_resp_appl_id );
328 
329     -- Setting thresold value to run the process in background
330     l_save_threshold      := wf_engine.threshold;
331     wf_engine.threshold := -1;
332 
333 
334     -- Now start fetching the details
335         OPEN l_assignments_csr;
336     FETCH l_assignments_csr INTO l_assignments_rec;
337     IF l_assignments_csr%NOTFOUND THEN
338        x_return_status := FND_API.G_RET_STS_ERROR;
339        pa_utils.add_message (p_app_short_name  => 'PA',
340                                  p_msg_name        => 'PA_INVALID_ASMGT_ID');
341        x_error_message_code := 'PA_INVALID_ASMGT_ID'; -- msg already avail
342        CLOSE l_assignments_csr;
343        x_msg_count := x_msg_count + 1;
344         ELSE
345        CLOSE l_assignments_csr;
346         END IF;
347        -- := l_assignments_rec.apprvl_status_code;
348 /*
349      -- Do not launch a workflow if an approval is already pending
350         IF NVL(l_assignments_rec.pending_approval_flag, 'N') = 'Y' THEN
351        x_return_status := FND_API.G_RET_STS_ERROR;
352        pa_utils.add_message (p_app_short_name => 'PA',
353                                  p_msg_name       =>
354                 'PA_ASG_APPROVAL_PENDING' );
355        x_error_message_code := 'PA_ASG_APPROVAL_PENDING';
356        x_msg_count := x_msg_count + 1;
357     END IF;
358 */
359     OPEN l_stus_csr(l_assignments_rec.apprvl_status_code);
360     FETCH l_stus_csr INTO
361         l_wf_success_status_code,
362         l_wf_failure_status_code,
363         l_project_status_name ;
364     IF l_stus_csr%NOTFOUND THEN
365        x_return_status := FND_API.G_RET_STS_ERROR;
366        pa_utils.add_message (p_app_short_name => 'PA',
367                                  p_msg_name       => 'PA_INVALID_STATUS_CODE');
368        x_error_message_code := 'PA_INVALID_STATUS_CODE';-- msg already avail
369        CLOSE l_stus_csr;
370        x_msg_count := x_msg_count + 1;
371         ELSE
372        CLOSE l_stus_csr;
373     END IF;
374 
375         OPEN l_projects_csr(l_assignments_rec.project_id);
376     FETCH l_projects_csr INTO l_projects_rec;
377     IF l_projects_csr%NOTFOUND THEN
378        x_return_status := FND_API.G_RET_STS_ERROR;
379        x_error_message_code := 'PA_INVALID_PROJECT_ID'; -- msg already avail
380        pa_utils.add_message (p_app_short_name  => 'PA',
381                                  p_msg_name        => 'PA_INVALID_PROJECT_ID');
382        CLOSE l_projects_csr;
383        x_msg_count := x_msg_count + 1;
384         ELSE
385        CLOSE l_projects_csr;
386         END IF;
387 
388         Check_And_Get_Proj_Customer
389                    (p_project_id   => l_assignments_rec.project_id
390            ,x_customer_id  => l_customer_id
391                ,x_customer_name => l_customer_name );
392         -- Get the previously approved effort and duration
393     -- in case of re-approvals
394         OPEN l_prev_asgmt_info_csr (l_assignments_rec.assignment_id) ;
395     FETCH l_prev_asgmt_info_csr INTO
396           l_prev_asgmt_info_rec;
397     IF    l_prev_asgmt_info_csr%NOTFOUND THEN
398           l_reapproval_flag := 'N';
399         ELSE
400           l_reapproval_flag := 'Y';
401         END IF;
402     CLOSE l_prev_asgmt_info_csr;
403 
404         -- Get the Location details of the project location
405         IF l_projects_rec.location_id IS NOT NULL THEN
406            pa_location_utils.Get_PA_Location_Details
407               ( p_location_id   => l_projects_rec.location_id
408                ,x_country_name  => l_country_name
409                ,x_city          => l_city
410                ,x_region        => l_region
411                ,x_country_code  => l_country_code
412                ,x_return_status => l_return_status
413                ,x_error_message_code  => l_error_message_code );
414        -- dbms_output.put_line ('after pa_location_utils');
415 
416            IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
417           x_return_status := l_return_status;
418           x_error_message_code := l_error_message_code ;
419           pa_utils.add_message (p_app_short_name  => 'PA',
420                                     p_msg_name        => l_error_message_code);
421            END IF;
422          END IF;
423 
424     -- Bug 5362698 - use sysdate to get the name so that the latest name
425     -- is obtained.
426     -- OPEN l_resource_csr(l_assignments_rec.resource_id, l_assignments_rec.start_date);
427     -- Need to get the Max of StartDate or the Sysdate for future hire. Fix
428     -- for Bug# 7585927.
429     if(l_assignments_rec.start_date > sysdate) then
430       l_resource_start_date := l_assignments_rec.start_date;
431     else
432       l_resource_start_date := sysdate;
433     end if;
434 
435     OPEN l_resource_csr(l_assignments_rec.resource_id,  l_resource_start_date );
436        FETCH l_resource_csr INTO l_resource_rec;
437        IF l_resource_csr%NOTFOUND THEN
438           x_return_status := FND_API.G_RET_STS_ERROR;
439           x_error_message_code := 'PA_INVALID_PERSON_ID'; --msg already avail
440           pa_utils.add_message (p_app_short_name => 'PA',
441                                  p_msg_name       => 'PA_INVALID_PERSON_ID');
442            CLOSE l_resource_csr;
443            x_msg_count := x_msg_count + 1;
444     ELSE
445            CLOSE l_resource_csr;
446     END IF;
447 
448       -- Get the project manager details
449          pa_project_parties_utils.get_curr_proj_mgr_details
450         (p_project_id => l_projects_rec.project_id
451         ,x_manager_person_id => l_project_manager_person_id
452         ,x_manager_name      => l_project_manager_name
453         ,x_project_party_id  => l_project_party_id
454                 ,x_project_role_id   => l_project_role_id
455                 ,x_project_role_name => l_project_role_name
456                 ,x_return_status     => l_return_status
457                 ,x_error_message_code => l_error_message_code );
458 
459        -- dbms_output.put_line ('after pa_project_parties_utils');
460         -- Only non-admin projects require a manager
461       IF l_projects_rec.admin_flag = 'N' THEN
462      IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
463         x_return_status := l_return_status;
464         x_error_message_code := l_error_message_code;
465         pa_utils.add_message (p_app_short_name  => 'PA',
466                                   p_msg_name        => l_error_message_code);
467          END IF;
468       END IF;
469     -- If there are any busines rules violations , then do
470     -- not proceed. Return
471          l_msg_count := fnd_msg_pub.count_msg;
472          IF l_msg_count > 0 THEN
473            IF l_msg_count = 1 THEN
474              pa_interface_utils_pub.get_messages
475                  (p_encoded        => FND_API.G_TRUE,
476                   p_msg_index      => 1,
477                   p_msg_count      => l_msg_count,
478                   p_msg_data       => l_msg_data ,
479                   p_data           => l_data,
480                   p_msg_index_out  => l_msg_index_out );
481              x_msg_data := l_data;
482              x_msg_count := l_msg_count;
483        ELSE
484              x_msg_count := l_msg_count;
485            END IF;
486            pa_debug.reset_err_stack;
487        RETURN;
488          END IF;
489     -- Get the approvers user name
490        IF p_approver1_person_id IS NOT NULL THEN
491           wf_directory.getusername
492             (p_orig_system => 'PER',
493                  p_orig_system_id => p_approver1_person_id,
494                  p_name         => l_approver1_user_name,
495                  p_display_name => l_display_name);
496            l_number_of_approvers := l_number_of_approvers + 1;
497            l_approver1_type := p_approver1_type;
498        END IF;
499 
500        IF p_approver2_person_id IS NOT NULL THEN
501           wf_directory.getusername
502             (p_orig_system => 'PER',
503                  p_orig_system_id => p_approver2_person_id,
504                  p_name         => l_approver2_user_name,
505                  p_display_name => l_display_name);
506            l_number_of_approvers := l_number_of_approvers + 1;
507            l_approver2_type := p_approver2_type;
508        END IF;
509 
510     -- get the recipients user name (resource , project manager ,
511         -- If person_id is passed use that value to get the user name
512         -- of the resource, otherwise, use the person id fetched from resources
513          IF p_person_id IS NULL THEN
514             l_resource_person_id := l_resource_rec.resource_person_id;
515              ELSE
516             l_resource_person_id := p_person_id;
517              END IF;
518          wf_directory.getusername
519             (p_orig_system => 'PER',
520                      p_orig_system_id => l_resource_person_id,
521                  p_name         => l_apprvl_nf_rec1_uname,
522                  p_display_name => l_display_name);
523         l_reject_nf_rec1_uname := l_apprvl_nf_rec1_uname;
524             l_cancel_nf_rec1_uname := l_apprvl_nf_rec1_uname;
525         l_apprvl_nf_rec1_utype := 'RESOURCE';
526         l_apprvl_nf_rec1_person_id := l_resource_person_id;
527         l_reject_nf_rec1_utype := 'RESOURCE';
528         l_reject_nf_rec1_person_id := l_resource_person_id;
529         l_cancel_nf_rec1_utype := 'RESOURCE';
530         l_cancel_nf_rec1_person_id := l_resource_person_id;
531         l_number_of_apprvl_nf_rects := l_number_of_apprvl_nf_rects +1;
532         l_number_of_reject_nf_rects := l_number_of_reject_nf_rects +1;
533         l_number_of_cancel_nf_rects := l_number_of_cancel_nf_rects +1;
534 
535     -- Now get the resource's manager name , since the approvers may or
536     -- may not be the resource's manager
537     -- Begin changes for Bug 4334741 Changed resource manager from l_resource_rec.manager_id to l_res_manager_id
538 -- Bug 4473484
539 --    l_res_manager_id := pa_resource_utils.get_hr_manager_id(l_resource_rec.resource_id,l_assignments_rec.assignment_id);
540       l_res_manager_id := pa_resource_utils.get_hr_manager_id(p_resource_id => l_resource_rec.resource_id,
541                                                               p_start_date  => l_assignments_rec.start_date);
542 	  IF l_res_manager_id IS NOT NULL THEN
543              wf_directory.getusername
544             (p_orig_system => 'PER',
545                  p_orig_system_id => l_res_manager_id,
546                  p_name         =>   l_apprvl_nf_rec2_uname,
547                  p_display_name => l_display_name);
548              l_reject_nf_rec2_uname := l_apprvl_nf_rec2_uname;
549              l_cancel_nf_rec2_uname := l_apprvl_nf_rec2_uname;
550              l_apprvl_nf_rec2_utype := 'RESOURCE_MANAGER';
551              l_apprvl_nf_rec2_person_id := l_res_manager_id;
552              l_reject_nf_rec2_utype := 'RESOURCE_MANAGER';
553              l_reject_nf_rec2_person_id := l_res_manager_id;
554              l_cancel_nf_rec2_utype := 'RESOURCE_MANAGER';
555              l_cancel_nf_rec2_person_id := l_res_manager_id;
556              l_number_of_apprvl_nf_rects := l_number_of_apprvl_nf_rects +1;
557              l_number_of_reject_nf_rects := l_number_of_reject_nf_rects +1;
558              l_number_of_cancel_nf_rects := l_number_of_cancel_nf_rects +1;
559 
560               END IF;
561     -- End changes for Bug 4334741 Changed resource manager from l_resource_rec.manager_id to l_res_manager_id
562     -- Now get the project manager's user name
563            IF l_project_manager_person_id IS NOT NULL THEN
564              wf_directory.getusername
565             (p_orig_system => 'PER',
566                  p_orig_system_id => l_project_manager_person_id,
567                  p_name         =>   l_project_manager_uname,
568                  p_display_name => l_display_name);
569          l_apprvl_nf_rec3_uname := l_project_manager_uname;
570              l_reject_nf_rec3_uname := l_project_manager_uname;
571              l_cancel_nf_rec3_uname := l_project_manager_uname;
572              l_apprvl_nf_rec3_utype := 'PROJECT_MANAGER';
573              l_apprvl_nf_rec3_person_id := l_project_manager_person_id;
574              l_reject_nf_rec3_utype := 'PROJECT_MANAGER';
575              l_reject_nf_rec3_person_id := l_project_manager_person_id;
576              l_cancel_nf_rec3_utype := 'PROJECT_MANAGER';
577              l_cancel_nf_rec3_person_id := l_project_manager_person_id;
578              l_number_of_apprvl_nf_rects := l_number_of_apprvl_nf_rects +1;
579              l_number_of_reject_nf_rects := l_number_of_reject_nf_rects +1;
580              l_number_of_cancel_nf_rects := l_number_of_cancel_nf_rects +1;
581            END IF;
582 
583              -- Ramesh 07/11/00
584         -- Primary contact would be one of the two approvers
585         -- Call the procedure to get the primary contact id
586                 get_primary_contact_info
587                    (p_resource_id         => l_resource_rec.resource_id
588                    ,p_assignment_id       => l_assignments_rec.assignment_id
589                    ,p_approver1_person_id => p_approver1_person_id
590                    ,p_approver1_type      => p_approver1_type
591                    ,p_approver2_person_id => p_approver2_person_id
592                    ,p_approver2_type      => p_approver2_type
593                    ,x_PrimaryContactId    => l_primarycontactid );
594     -- dbms_output.put_line ('after resource utils - primary contact');
595         -- Now get the primary contact's user name
596                IF l_primarycontactid IS NOT NULL THEN
597                  wf_directory.getusername
598                     (p_orig_system => 'PER',
599                      p_orig_system_id => l_primarycontactid,
600                      p_name         =>   l_primarycontactname,
601                      p_display_name =>   l_display_name);
602                  l_apprvl_nf_rec4_uname := l_primarycontactname;
603                  l_reject_nf_rec4_uname := l_primarycontactname;
604                  l_cancel_nf_rec4_uname := l_primarycontactname;
605              l_apprvl_nf_rec4_utype := 'ORG_PRIMARY_CONTACT';
606              l_apprvl_nf_rec4_person_id := l_primarycontactid;
607              l_reject_nf_rec4_utype := 'ORG_PRIMARY_CONTACT';
608              l_reject_nf_rec4_person_id :=  l_primarycontactid;
609              l_cancel_nf_rec4_utype := 'ORG_PRIMARY_CONTACT';
610              l_cancel_nf_rec4_person_id :=  l_primarycontactid;
611                  l_number_of_apprvl_nf_rects := l_number_of_apprvl_nf_rects +1;
612                  l_number_of_reject_nf_rects := l_number_of_reject_nf_rects +1;
613              l_number_of_cancel_nf_rects := l_number_of_cancel_nf_rects +1;
614                END IF;
615         -- End 07/11/00 changes
616     -- We now have all the values in local variables
617     -- Create the WF process
618         wf_engine.CreateProcess ( ItemType => p_wf_item_type
619                                 , ItemKey  => l_itemkey
620                                 , process  => p_wf_process
621                                 );
622 
623     --Set approval type
624     wf_engine.SetItemAttrText
625         ( itemtype => p_wf_item_type
626         , itemkey  => l_itemkey
627         , aname    => 'APPROVAL_TYPE'
628         , avalue   => PA_ASGMT_WFSTD.G_SINGLE_APPROVAL  );
629 
630     -- Now set the values as appropriate  in the WF attributes
631         -- Set Project details attributes
632          wf_engine.SetItemAttrNumber
633                                 ( itemtype => p_wf_item_type
634                                 , itemkey => l_itemkey
635                                 , aname => 'PROJECT_ID'
636                                 , avalue => l_projects_rec.project_id
637                                 );
638 
639           wf_engine.SetItemAttrText
640                                ( itemtype => p_wf_item_type
641                                , itemkey => l_itemkey
642                                , aname => 'PROJECT_NUMBER'
643                                , avalue => l_projects_rec.segment1
644                                );
645 
646            wf_engine.SetItemAttrText
647                                ( itemtype => p_wf_item_type
648                                , itemkey => l_itemkey
649                                , aname => 'PROJECT_NAME'
650                                , avalue => l_projects_rec.name
651                                );
652 
653            wf_engine.SetItemAttrText
654                                ( itemtype => p_wf_item_type
655                                , itemkey => l_itemkey
656                                , aname => 'PROJECT_ORGANIZATION'
657                                , avalue => l_projects_rec.organization_name
658                                );
659 /*Commented the code for the bug 3595857
660             Bug 3595857 - Adding the FROM_ROLE_VALUE Attribute
661            wf_engine.SetItemAttrText
662                                ( itemtype => p_wf_item_type
663                                , itemkey => l_itemkey
664                                , aname => 'FROM_ROLE_VALUE'
665                                , avalue => fnd_global.user_name
666                                );*/
667 
668            wf_engine.SetItemAttrText
669                                ( itemtype => p_wf_item_type
670                                , itemkey => l_itemkey
671                                , aname => 'PROJECT_LOCATION'
672                                , avalue => l_city||' , ' ||l_region||
673                            ' , ' ||l_country_name
674                                );
675     -- Set the customer name if it is not null
676      IF l_customer_name IS NOT NULL THEN
677            wf_engine.SetItemAttrText
678                                ( itemtype => p_wf_item_type
679                                , itemkey => l_itemkey
680                                , aname => 'PROJECT_CUSTOMER'
681                                , avalue => l_customer_name
682                                );
683      END IF;
684 
685 
686     -- Set Assignment related attributes
687 
688            wf_engine.SetItemAttrNumber
689                 ( itemtype => p_wf_item_type
690                                 , itemkey => l_itemkey
691                                 , aname => 'ASSIGNMENT_ID'
692                                 , avalue => l_assignments_rec.assignment_id
693                                 );
694 
695            wf_engine.SetItemAttrText
696                    ( itemtype => p_wf_item_type
697                                , itemkey => l_itemkey
698                                , aname => 'ASSIGNMENT_NAME'
699                                , avalue => l_assignments_rec.assignment_name
700                                );
701 
702            wf_engine.SetItemAttrText
703                    ( itemtype => p_wf_item_type
704                                , itemkey => l_itemkey
705                                , aname => 'ASSIGNMENT_TYPE'
706                                , avalue => l_assignments_rec.assignment_type
707                                );
708 
709            wf_engine.SetItemAttrText
710                    ( itemtype => p_wf_item_type
711                                , itemkey => l_itemkey
712                                , aname => 'DESCRIPTION'
713                                , avalue => l_assignments_rec.description
714                                );
715 
716 /* Added for bug 3051110 */
717 
718            wf_engine.SetItemAttrNumber(itemtype => p_wf_item_type
719                 , Itemkey => l_itemkey
720                 , aname => 'TRANSFER_PRICE_RATE'
721                     , avalue => l_assignments_rec.transfer_price_rate);
722 
723            wf_engine.SetItemAttrtext(itemtype => p_wf_item_type
724                 , Itemkey => l_itemkey
725                 , aname => 'TRANSFER_PR_RATE_CURR'
726                     , avalue => l_assignments_rec.transfer_pr_rate_curr);
727 
728            wf_engine.SetItemAttrText
729                    ( itemtype => p_wf_item_type
730                                , itemkey => l_itemkey
731                                , aname => 'ADDITIONAL_INFORMATION'
732                                , avalue =>
733                     l_assignments_rec.additional_information
734                                );
735 
736            wf_engine.SetItemAttrDate
737                   (itemtype => p_wf_item_type
738                               , itemkey => l_itemkey
739                               , aname => 'START_DATE'
740                               , avalue => l_assignments_rec.start_date
741                               );
742 
743            wf_engine.SetItemAttrDate
744                  (itemtype => p_wf_item_type
745                               , itemkey => l_itemkey
746                               , aname => 'END_DATE'
747                               , avalue => l_assignments_rec.end_date
748                              );
749 
750            wf_engine.SetItemAttrNumber
751                    ( itemtype => p_wf_item_type
752                                , itemkey => l_itemkey
753                                , aname => 'ASSIGNMENT_DURATION'
754                                , avalue =>
755                  (trunc(l_assignments_rec.end_date) -
756                      trunc(l_assignments_rec.start_date)+1)
757                                );
758 
759            wf_engine.SetItemAttrNumber
760                    ( itemtype => p_wf_item_type
761                                , itemkey => l_itemkey
762                                , aname => 'ASSIGNMENT_EFFORT'
763                                , avalue => l_assignments_rec.assignment_effort
764                                );
765 
766            -- Start Additions by RM for bug 2274426
767            wf_engine.SetItemAttrNumber
768                                ( itemtype => p_wf_item_type
769                                , itemkey => l_itemkey
770                                , aname => 'REVENUE_BILL_RATE'
771                                , avalue => l_assignments_rec.revenue_bill_rate
772                                );
773            wf_engine.SetItemAttrText
774                             ( itemtype => p_wf_item_type
775                             , itemkey => l_itemkey
776                             , aname => 'REVENUE_BILL_RATE_CURR'
777                             , avalue => l_assignments_rec.revenue_currency_code
778                             );
779            wf_engine.SetItemAttrNumber
780                                ( itemtype => p_wf_item_type
781                                , itemkey => l_itemkey
782                                , aname => 'BILL_RATE_OVERRIDE'
783                                , avalue => l_assignments_rec.bill_rate_override
784                                );
785            wf_engine.SetItemAttrText
786                           ( itemtype => p_wf_item_type
787                           , itemkey => l_itemkey
788                           , aname => 'BILL_RATE_OVERRIDE_CURR'
789                           , avalue => l_assignments_rec.bill_rate_curr_override
790                           );
791            IF l_assignments_rec.markup_percent_override IS NOT NULL THEN
792               wf_engine.SetItemAttrText
793                           ( itemtype => p_wf_item_type
794                           , itemkey => l_itemkey
795                           , aname => 'MARKUP_PCT_OVERRIDE'
796                           , avalue => to_char(l_assignments_rec.markup_percent_override)||'%'
797                           );
798            ELSE
799                wf_engine.SetItemAttrText
800                           ( itemtype => p_wf_item_type
801                           , itemkey => l_itemkey
802                           , aname => 'MARKUP_PCT_OVERRIDE'
803                           , avalue => to_char(l_assignments_rec.markup_percent_override)
804                           );
805            END IF;
806            wf_engine.SetItemAttrText
807                           ( itemtype => p_wf_item_type
808                           , itemkey => l_itemkey
809                           , aname => 'TP_AMT_TYPE_NAME'
810                           , avalue => l_assignments_rec.fcst_tp_amount_type_name
811                           );
812            wf_engine.SetItemAttrNumber
813                           ( itemtype => p_wf_item_type
814                           , itemkey => l_itemkey
815                           , aname => 'TP_RATE_OVERRIDE'
816                           , avalue => l_assignments_rec.tp_rate_override
817                           );
818            wf_engine.SetItemAttrText
819                           ( itemtype => p_wf_item_type
820                           , itemkey => l_itemkey
821                           , aname => 'TP_RATE_OVERRIDE_CURR'
822                           , avalue => l_assignments_rec.tp_currency_override
823                           );
824            IF l_assignments_rec.tp_calc_base_code_override IS NOT NULL THEN
825               open csr_get_override_basis_name(l_assignments_rec.tp_calc_base_code_override);
826               fetch csr_get_override_basis_name into l_override_basis_name;
827               close csr_get_override_basis_name;
828            END IF;
829            wf_engine.SetItemAttrText
830                           ( itemtype => p_wf_item_type
831                           , itemkey => l_itemkey
832                           , aname => 'OVERRIDE_BASIS_NAME'
833                           , avalue => l_override_basis_name
834                           );
835            IF l_assignments_rec.tp_percent_applied_override IS NOT NULL THEN
836               IF l_override_basis_name IS NOT NULL THEN
837                  wf_engine.SetItemAttrText
838                      ( itemtype => p_wf_item_type
839                      , itemkey => l_itemkey
840                      , aname => 'TP_PCT_APPLIED_OVERRIDE'
841                      , avalue => ', '||to_char(l_assignments_rec.tp_percent_applied_override)||'%'
842                      );
843               ELSE
844                  wf_engine.SetItemAttrText
845                      ( itemtype => p_wf_item_type
846                      , itemkey => l_itemkey
847                      , aname => 'TP_PCT_APPLIED_OVERRIDE'
848                      , avalue => to_char(l_assignments_rec.tp_percent_applied_override)||'%'
849                      );
850               END IF;
851            ELSE
852               wf_engine.SetItemAttrText
853                      ( itemtype => p_wf_item_type
854                      , itemkey => l_itemkey
855                      , aname => 'TP_PCT_APPLIED_OVERRIDE'
856                      , avalue => to_char(l_assignments_rec.tp_percent_applied_override)
857                      );
858            END IF;
859            wf_engine.SetItemAttrText
860                           ( itemtype => p_wf_item_type
861                           , itemkey => l_itemkey
862                           , aname => 'WORK_TYPE_NAME'
863                           , avalue => l_assignments_rec.work_type_name
864                           );
865            -- End of Additions by RM
866 
867            wf_engine.SetItemAttrText
868                    ( itemtype => p_wf_item_type
869                                , itemkey => l_itemkey
870                                , aname => 'CURRENT_ASGMT_STATUS_CODE'
871                                , avalue => l_assignments_rec.apprvl_status_code
872                                );
873 
874            wf_engine.SetItemAttrText
875                    ( itemtype => p_wf_item_type
876                                , itemkey => l_itemkey
877                                , aname => 'NOTE_TO_APPROVER'
878                                , avalue => l_assignments_rec.note_to_approver
879                                );
880            wf_engine.SetItemAttrText
881                    ( itemtype => p_wf_item_type
882                                , itemkey => l_itemkey
883                                , aname => 'ASGMT_FAILURE_STATUS_CODE'
884                                , avalue => l_wf_failure_status_code
885                                );
886 
887            wf_engine.SetItemAttrText
888                    ( itemtype => p_wf_item_type
889                                , itemkey => l_itemkey
890                                , aname => 'ASGMT_SUCCESS_STATUS_CODE'
891                                , avalue => l_wf_success_status_code
892                                );
893            wf_engine.SetItemAttrText
894                    ( itemtype => p_wf_item_type
895                                , itemkey => l_itemkey
896                                , aname => 'PROJECT_STATUS_NAME'
897                                , avalue => l_project_status_name
898                                );
899 
900            wf_engine.SetItemAttrText
901                    ( itemtype => p_wf_item_type
902                                , itemkey => l_itemkey
903                                , aname => 'REAPPROVAL_FLAG'
904                                , avalue => l_reapproval_flag
905                                );
906      -- Set the previously approved values , if it is a re-approval
907      IF l_reapproval_flag = 'Y' THEN
908            wf_engine.SetItemAttrNumber
909                    ( itemtype => p_wf_item_type
910                                , itemkey => l_itemkey
911                                , aname => 'PREV_DURATION'
912                                , avalue => l_prev_asgmt_info_rec.prev_duration );
913            wf_engine.SetItemAttrNumber
914                    ( itemtype => p_wf_item_type
915                     , itemkey => l_itemkey
916                     , aname   => 'PREV_EFFORT'
917                     , avalue  => l_prev_asgmt_info_rec.prev_effort );
918     END IF;
919 
920     -- Set resource related attributes
921 
922            wf_engine.SetItemAttrNumber
923                    ( itemtype => p_wf_item_type
924                                 , itemkey => l_itemkey
925                                 , aname => 'RESOURCE_ID'
926                                 , avalue => l_resource_rec.resource_id
927                                );
928 
929            wf_engine.SetItemAttrNumber
930                    ( itemtype => p_wf_item_type
931                                 , itemkey => l_itemkey
932                                 , aname => 'RESOURCE_PERSON_ID'
933                                 , avalue => l_resource_person_id
934                                );
935 
936            wf_engine.SetItemAttrText
937                    ( itemtype => p_wf_item_type
938                                , itemkey => l_itemkey
939                                , aname => 'RESOURCE_NAME'
940                                , avalue => l_resource_rec.resource_name
941                                );
942 
943            wf_engine.SetItemAttrText
944                    ( itemtype => p_wf_item_type
945                                , itemkey => l_itemkey
946                                , aname => 'RESOURCE_ORGANIZATION'
947                                , avalue =>
948                  l_resource_rec.resource_organization_name
949                                );
950 
951     -- Set project manager attributes
952 
953            wf_engine.SetItemAttrNumber
954                    ( itemtype => p_wf_item_type
955                                 , itemkey => l_itemkey
956                                 , aname => 'PROJECT_MANAGER_PERSON_ID'
957                                 , avalue => l_project_manager_person_id
958                                );
959 
960            wf_engine.SetItemAttrText
961                    ( itemtype => p_wf_item_type
962                                , itemkey => l_itemkey
963                                , aname => 'PROJECT_MANAGER_NAME'
964                                , avalue => l_project_manager_name
965                                );
966 
967            wf_engine.SetItemAttrText
968                    ( itemtype => p_wf_item_type
969                                , itemkey => l_itemkey
970                                , aname => 'PROJECT_MANAGER_UNAME'
971                                , avalue =>
972                  l_project_manager_uname
973                                );
974     -- Set the other attributes
975 
976            wf_engine.SetItemAttrNumber
977                    (  itemtype => p_wf_item_type
978                                 , itemkey => l_itemkey
979                                 , aname => 'NUMBER_OF_APPROVERS'
980                                 , avalue => l_number_of_approvers
981                                );
982 
983            wf_engine.SetItemAttrNumber
984                    (  itemtype => p_wf_item_type
985                                 , itemkey => l_itemkey
986                                 , aname => 'NUMBER_OF_APPRVL_NF_RECIPIENTS'
987                                 , avalue => l_number_of_apprvl_nf_rects
988                 );
989 
990            wf_engine.SetItemAttrNumber
991                    (  itemtype => p_wf_item_type
992                                 , itemkey => l_itemkey
993                                 , aname => 'NUMBER_OF_REJECT_NF_RECIPIENTS'
994                                 , avalue => l_number_of_reject_nf_rects
995                                );
996 
997            wf_engine.SetItemAttrNumber
998                    (  itemtype => p_wf_item_type
999                                 , itemkey => l_itemkey
1000                                 , aname => 'NUMBER_OF_CANCEL_NF_RECIPIENTS'
1001                                 , avalue => l_number_of_reject_nf_rects
1002                                );
1003 
1004 
1005            wf_engine.SetItemAttrNumber
1006                    (  itemtype => p_wf_item_type
1007                                 , itemkey => l_itemkey
1008                                 , aname => 'APPROVER_LOOP_COUNTER'
1009                                 , avalue => 0
1010                                );
1011            wf_engine.SetItemAttrNumber
1012                    (  itemtype => p_wf_item_type
1013                                 , itemkey => l_itemkey
1014                                 , aname => 'APPROVAL_NF_LOOP_COUNTER'
1015                                 , avalue => 0
1016                                );
1017            wf_engine.SetItemAttrNumber
1018                    (  itemtype => p_wf_item_type
1019                                 , itemkey => l_itemkey
1020                                 , aname => 'REJECTION_NF_LOOP_COUNTER'
1021                                 , avalue => 0
1022                                );
1023 
1024            wf_engine.SetItemAttrNumber
1025                    (  itemtype => p_wf_item_type
1026                                 , itemkey => l_itemkey
1027                                 , aname => 'CANCELLATION_NF_LOOP_COUNTER'
1028                                 , avalue => 0
1029                                );
1030 
1031            wf_engine.SetItemAttrNumber
1032                    (  itemtype => p_wf_item_type
1033                                 , itemkey => l_itemkey
1034                                 , aname => 'APPROVER_1_PERSON_ID'
1035                                 , avalue => p_approver1_person_id
1036                                );
1037 
1038            wf_engine.SetItemAttrNumber
1039                    (  itemtype => p_wf_item_type
1040                                 , itemkey => l_itemkey
1041                                 , aname => 'APPROVER_2_PERSON_ID'
1042                                 , avalue => p_approver2_person_id
1043                                );
1044 
1045            wf_engine.SetItemAttrText
1046                    ( itemtype => p_wf_item_type
1047                                , itemkey => l_itemkey
1048                                , aname => 'APPROVER1_USER_NAME'
1049                                , avalue => l_approver1_user_name
1050                                );
1051 
1052            wf_engine.SetItemAttrText
1053                    ( itemtype => p_wf_item_type
1054                                , itemkey => l_itemkey
1055                                , aname => 'APPROVER2_USER_NAME'
1056                                , avalue => l_approver2_user_name
1057                                );
1058            wf_engine.SetItemAttrText
1059                    ( itemtype => p_wf_item_type
1060                                , itemkey => l_itemkey
1061                                , aname => 'APPROVER_1_TYPE'
1062                                , avalue => l_approver1_type
1063                                );
1064            wf_engine.SetItemAttrText
1065                    ( itemtype => p_wf_item_type
1066                                , itemkey => l_itemkey
1067                                , aname => 'APPROVER_2_TYPE'
1068                                , avalue => l_approver2_type
1069                                );
1070            wf_engine.SetItemAttrText
1071                    ( itemtype => p_wf_item_type
1072                                , itemkey => l_itemkey
1073                                , aname => 'APPROVAL_NF_REC1_USER_NAME'
1074                                , avalue => l_apprvl_nf_rec1_uname
1075                                );
1076 
1077            wf_engine.SetItemAttrText
1078                    ( itemtype => p_wf_item_type
1079                                , itemkey => l_itemkey
1080                                , aname => 'APPROVAL_NF_REC1_USER_TYPE'
1081                                , avalue => l_apprvl_nf_rec1_utype
1082                                );
1083            wf_engine.SetItemAttrNumber
1084                    ( itemtype => p_wf_item_type
1085                                , itemkey => l_itemkey
1086                                , aname => 'APPROVAL_NF_REC1_PERSON_ID'
1087                                , avalue => l_apprvl_nf_rec1_person_id
1088                                );
1089            wf_engine.SetItemAttrText
1090                    ( itemtype => p_wf_item_type
1091                                , itemkey => l_itemkey
1092                                , aname => 'APPROVAL_NF_REC2_USER_NAME'
1093                                , avalue => l_apprvl_nf_rec2_uname
1094                                );
1095            wf_engine.SetItemAttrText
1096                    ( itemtype => p_wf_item_type
1097                                , itemkey => l_itemkey
1098                                , aname => 'APPROVAL_NF_REC2_USER_TYPE'
1099                                , avalue => l_apprvl_nf_rec2_utype
1100                                );
1101            wf_engine.SetItemAttrNumber
1102                    ( itemtype => p_wf_item_type
1103                                , itemkey => l_itemkey
1104                                , aname => 'APPROVAL_NF_REC2_PERSON_ID'
1105                                , avalue => l_apprvl_nf_rec2_person_id
1106                                );
1107            wf_engine.SetItemAttrText
1108                    ( itemtype => p_wf_item_type
1109                                , itemkey => l_itemkey
1110                                , aname => 'APPROVAL_NF_REC3_USER_NAME'
1111                                , avalue => l_apprvl_nf_rec3_uname
1112                                );
1113            wf_engine.SetItemAttrText
1114                    ( itemtype => p_wf_item_type
1115                                , itemkey => l_itemkey
1116                                , aname => 'APPROVAL_NF_REC3_USER_TYPE'
1117                                , avalue => l_apprvl_nf_rec3_utype
1118                                );
1119            wf_engine.SetItemAttrNumber
1120                    ( itemtype => p_wf_item_type
1121                                , itemkey => l_itemkey
1122                                , aname => 'APPROVAL_NF_REC3_PERSON_ID'
1123                                , avalue => l_apprvl_nf_rec3_person_id
1124                                );
1125         -- Ramesh 07/11/00
1126          IF l_apprvl_nf_rec4_uname IS NOT NULL THEN
1127            wf_engine.SetItemAttrText
1128                                ( itemtype => p_wf_item_type
1129                                , itemkey => l_itemkey
1130                                , aname => 'APPROVAL_NF_REC4_USER_NAME'
1131                                , avalue => l_apprvl_nf_rec4_uname
1132                                );
1133            wf_engine.SetItemAttrText
1134                    ( itemtype => p_wf_item_type
1135                                , itemkey => l_itemkey
1136                                , aname => 'APPROVAL_NF_REC4_USER_TYPE'
1137                                , avalue => l_apprvl_nf_rec4_utype
1138                                );
1139            wf_engine.SetItemAttrNumber
1140                    ( itemtype => p_wf_item_type
1141                                , itemkey => l_itemkey
1142                                , aname => 'APPROVAL_NF_REC4_PERSON_ID'
1143                                , avalue => l_apprvl_nf_rec4_person_id
1144                                );
1145          END IF;
1146         -- End 07/11/00 changes
1147 
1148            wf_engine.SetItemAttrText
1149                    ( itemtype => p_wf_item_type
1150                                , itemkey => l_itemkey
1151                                , aname => 'REJECT_NF_REC1_USER_NAME'
1152                                , avalue => l_reject_nf_rec1_uname
1153                                );
1154            wf_engine.SetItemAttrText
1155                    ( itemtype => p_wf_item_type
1156                                , itemkey => l_itemkey
1157                                , aname => 'REJECT_NF_REC1_USER_TYPE'
1158                                , avalue => l_reject_nf_rec1_utype
1159                                );
1160            wf_engine.SetItemAttrNumber
1161                    ( itemtype => p_wf_item_type
1162                                , itemkey => l_itemkey
1163                                , aname => 'REJECT_NF_REC1_PERSON_ID'
1164                                , avalue => l_reject_nf_rec1_person_id
1165                                );
1166            wf_engine.SetItemAttrText
1167                    ( itemtype => p_wf_item_type
1168                                , itemkey => l_itemkey
1169                                , aname => 'REJECT_NF_REC2_USER_NAME'
1170                                , avalue => l_reject_nf_rec2_uname
1171                                );
1172            wf_engine.SetItemAttrText
1173                    ( itemtype => p_wf_item_type
1174                                , itemkey => l_itemkey
1175                                , aname => 'REJECT_NF_REC2_USER_TYPE'
1176                                , avalue => l_reject_nf_rec2_utype
1177                                );
1178            wf_engine.SetItemAttrNumber
1179                    ( itemtype => p_wf_item_type
1180                                , itemkey => l_itemkey
1181                                , aname => 'REJECT_NF_REC2_PERSON_ID'
1182                                , avalue => l_reject_nf_rec2_person_id
1183                                );
1184            wf_engine.SetItemAttrText
1185                    ( itemtype => p_wf_item_type
1186                                , itemkey => l_itemkey
1187                                , aname => 'REJECT_NF_REC3_USER_NAME'
1188                                , avalue => l_reject_nf_rec3_uname
1189                                );
1190            wf_engine.SetItemAttrText
1191                    ( itemtype => p_wf_item_type
1192                                , itemkey => l_itemkey
1193                                , aname => 'REJECT_NF_REC3_USER_TYPE'
1194                                , avalue => l_reject_nf_rec3_utype
1195                                );
1196            wf_engine.SetItemAttrNumber
1197                    ( itemtype => p_wf_item_type
1198                                , itemkey => l_itemkey
1199                                , aname => 'REJECT_NF_REC3_PERSON_ID'
1200                                , avalue => l_reject_nf_rec3_person_id
1201                                );
1202             -- Ramesh 07/11/00 changes
1203         IF l_reject_nf_rec4_uname IS NOT NULL THEN
1204            wf_engine.SetItemAttrText
1205                                ( itemtype => p_wf_item_type
1206                                , itemkey => l_itemkey
1207                                , aname => 'REJECT_NF_REC4_USER_NAME'
1208                                , avalue => l_reject_nf_rec4_uname
1209                                );
1210            wf_engine.SetItemAttrText
1211                    ( itemtype => p_wf_item_type
1212                                , itemkey => l_itemkey
1213                                , aname => 'REJECT_NF_REC4_USER_TYPE'
1214                                , avalue => l_reject_nf_rec4_utype
1215                                );
1216            wf_engine.SetItemAttrNumber
1217                    ( itemtype => p_wf_item_type
1218                                , itemkey => l_itemkey
1219                                , aname => 'REJECT_NF_REC4_PERSON_ID'
1220                                , avalue => l_reject_nf_rec4_person_id
1221                                );
1222         END IF;
1223         -- End 07/11/00 changes
1224 
1225            wf_engine.SetItemAttrText
1226                    ( itemtype => p_wf_item_type
1227                                , itemkey => l_itemkey
1228                                , aname => 'CANCEL_NF_REC1_USER_NAME'
1229                                , avalue => l_cancel_nf_rec1_uname
1230                                );
1231            wf_engine.SetItemAttrText
1232                    ( itemtype => p_wf_item_type
1233                                , itemkey => l_itemkey
1234                                , aname => 'CANCEL_NF_REC1_USER_TYPE'
1235                                , avalue => l_cancel_nf_rec1_utype
1236                                );
1237            wf_engine.SetItemAttrNumber
1238                    ( itemtype => p_wf_item_type
1239                                , itemkey => l_itemkey
1240                                , aname => 'CANCEL_NF_REC1_PERSON_ID'
1241                                , avalue => l_cancel_nf_rec1_person_id
1242                                );
1243            wf_engine.SetItemAttrText
1244                    ( itemtype => p_wf_item_type
1245                                , itemkey => l_itemkey
1246                                , aname => 'CANCEL_NF_REC2_USER_NAME'
1247                                , avalue => l_cancel_nf_rec2_uname
1248                                );
1249            wf_engine.SetItemAttrText
1250                    ( itemtype => p_wf_item_type
1251                                , itemkey => l_itemkey
1252                                , aname => 'CANCEL_NF_REC2_USER_TYPE'
1253                                , avalue => l_cancel_nf_rec2_utype
1254                                );
1255            wf_engine.SetItemAttrNumber
1256                    ( itemtype => p_wf_item_type
1257                                , itemkey => l_itemkey
1258                                , aname => 'CANCEL_NF_REC2_PERSON_ID'
1259                                , avalue => l_cancel_nf_rec2_person_id
1260                                );
1261            wf_engine.SetItemAttrText
1262                    ( itemtype => p_wf_item_type
1263                                , itemkey => l_itemkey
1264                                , aname => 'CANCEL_NF_REC3_USER_NAME'
1265                                , avalue => l_cancel_nf_rec3_uname
1266                                );
1267            wf_engine.SetItemAttrText
1268                    ( itemtype => p_wf_item_type
1269                                , itemkey => l_itemkey
1270                                , aname => 'CANCEL_NF_REC3_USER_TYPE'
1271                                , avalue => l_cancel_nf_rec3_utype
1272                                );
1273            wf_engine.SetItemAttrNumber
1274                    ( itemtype => p_wf_item_type
1275                                , itemkey => l_itemkey
1276                                , aname => 'CANCEL_NF_REC3_PERSON_ID'
1277                                , avalue => l_cancel_nf_rec3_person_id
1278                                );
1279             -- Ramesh 07/11/00 changes
1280         IF l_cancel_nf_rec4_uname IS NOT NULL THEN
1281            wf_engine.SetItemAttrText
1282                                ( itemtype => p_wf_item_type
1283                                , itemkey => l_itemkey
1284                                , aname => 'CANCEL_NF_REC4_USER_NAME'
1285                                , avalue => l_cancel_nf_rec4_uname
1286                                );
1287            wf_engine.SetItemAttrText
1288                    ( itemtype => p_wf_item_type
1289                                , itemkey => l_itemkey
1290                                , aname => 'CANCEL_NF_REC4_USER_TYPE'
1291                                , avalue => l_cancel_nf_rec4_utype
1292                                );
1293            wf_engine.SetItemAttrNumber
1294                    ( itemtype => p_wf_item_type
1295                                , itemkey => l_itemkey
1296                                , aname => 'CANCEL_NF_REC4_PERSON_ID'
1297                                , avalue => l_cancel_nf_rec4_person_id
1298                                );
1299         END IF;
1300         -- End 07/11/00 changes
1301 
1302             -- Set the item attributes for apprvl item type
1303         -- and apprvl item key . This would be the item type
1304         -- and item key of the approval process
1305         IF (p_apprvl_item_type IS NOT NULL AND p_apprvl_item_key
1306             IS NOT NULL ) THEN
1307             wf_engine.SetItemAttrText
1308                          ( itemtype => p_wf_item_type
1309                          , itemkey =>  l_itemkey
1310                          , aname => 'APPRVL_ITEM_TYPE'
1311                          , avalue => p_apprvl_item_type
1312                          );
1313             wf_engine.SetItemAttrText
1314                          ( itemtype => p_wf_item_type
1315                          , itemkey =>  l_itemkey
1316                          , aname => 'APPRVL_ITEM_KEY'
1317                          , avalue => p_apprvl_item_key
1318                          );
1319           /*Bug 3817940 : Code addition Starts*/
1320       if p_wf_process = 'PA_APRVL_NF_SP' or p_wf_process = 'PA_CANCEL_NF_SP' or p_wf_process = 'PA_REJ_NF_SP'
1321       Then
1322         l_last_approver_uname :=     wf_engine.GetItemAttrText
1323                    ( itemtype => p_apprvl_item_type
1324                                , itemkey =>  p_apprvl_item_key
1325                                , aname => 'APPROVER_UNAME');
1326 
1327             wf_engine.SetItemAttrText
1328                    ( itemtype => p_wf_item_type
1329                                , itemkey =>  l_itemkey
1330                                , aname => 'FROM_ROLE_VALUE1'
1331                                , avalue => l_last_approver_uname
1332                                );
1333            END IF;
1334             /*Bug 3817940 : Code addition ends*/
1335         END IF;
1336 
1337         --
1338         --Bug 1733307: set URL
1339         --
1340 /*Code modified for bug 6408552*/
1341 /*For Admin Assignment, we should call with paCalledPage as 'AdminAsmt'*/
1342 IF (l_assignments_rec.assignment_type = 'STAFFED_ADMIN_ASSIGNMENT') THEN
1343 
1344 	   l_asgmt_details_url :=
1345            'JSP:/OA_HTML/OA.jsp?akRegionApplicationId=275&akRegionCode=PA_ASMT_LAYOUT&paCalledPage=AdminAsmt&paAssignmentId='||p_assignment_id||'&addBreadCrumb=RP';
1346 
1347 ELSE -- Old code that was being called generically
1348 
1349 	   l_asgmt_details_url :=
1350            'JSP:/OA_HTML/OA.jsp?akRegionApplicationId=275&akRegionCode=PA_ASMT_LAYOUT&paCalledPage=ProjStaffedAsmt&paAssignmentId='||p_assignment_id||'&addBreadCrumb=RP';
1351 
1352 END IF ;
1353 /*Code modification ends for bug 6408552*/
1354            l_resource_schedules_url := 'JSP:/OA_HTML/OA.jsp?akRegionApplicationId=275&akRegionCode=PA_VIEW_RESOURCE_LAYOUT&paResourceId='||l_resource_rec.resource_id||'&addBreadCrumb=RP';
1355 
1356            wf_engine.SetItemAttrText
1357                    ( itemtype => p_wf_item_type
1358                                , itemkey  => l_itemkey
1359                                , aname => 'ASSIGNMENT_DETAILS_URL_INFO'
1360                                , avalue => l_asgmt_details_url
1361                                );
1362            wf_engine.SetItemAttrText
1363                    ( itemtype => p_wf_item_type
1364                                , itemkey =>  l_itemkey
1365                                , aname => 'RESOURCE_DETAILS_URL_INFO'
1366                                , avalue => l_resource_details_url
1367                                );
1368            wf_engine.SetItemAttrText
1369                    ( itemtype => p_wf_item_type
1370                                , itemkey =>  l_itemkey
1371                                , aname => 'RESOURCE_SCHEDULES_URL_INFO'
1372                                , avalue => l_resource_schedules_url
1373                                );
1374 
1375            wf_engine.SetItemAttrNumber
1376                    ( itemtype => p_wf_item_type
1377                                , itemkey =>  l_itemkey
1378                                , aname => 'CONFLICT_GROUP_ID'
1379                                , avalue => p_conflict_group_id
1380                                );
1381 
1382     -- Set workflow started by attributes
1383     -- Get the current user_id using FND_GLOBAL.USER_ID
1384     -- Get the user name from the user id
1385     -- Set the workflow started by user name
1386     l_workflow_started_by_uname := FND_GLOBAL.USER_NAME;
1387             wf_engine.SetItemAttrText
1388                          ( itemtype => p_wf_item_type
1389                          , itemkey =>  l_itemkey
1390                          , aname => 'WORKFLOW_STARTED_BY_UNAME'
1391                          , avalue => l_workflow_started_by_uname
1392                          );
1393 
1394     -- Call the client extensions to set the waiting period
1395     -- for reminders as well as the number of times to remind
1396     PA_CLIENT_EXTN_ASGMT_WF.Set_Timeout_And_Reminders
1397         ( p_assignment_id          => l_assignments_rec.assignment_id
1398           ,p_project_id            => l_projects_rec.project_id
1399           ,x_waiting_time          => l_waiting_time
1400           ,x_number_of_reminders   => l_number_of_reminders );
1401 
1402     IF l_waiting_time IS NULL THEN
1403        -- If the client extension did not return a valid
1404        -- waiting time , then set it to the default defined
1405        -- by the product , which is 3 days (expressed in minutes)
1406        -- (3 * 24 * 60) = 4320
1407        l_waiting_time := 4320;
1408     END IF;
1409     IF l_number_of_reminders IS NULL THEN
1410        -- If the client extension did not return a valid
1411        -- waiting time , then set it to the default defined
1412        -- by the product , which is 3
1413        l_number_of_reminders := 3;
1414         END IF;
1415        -- Now set the appropriate attributes in the workflow process
1416            wf_engine.SetItemAttrNumber
1417                    ( itemtype => p_wf_item_type
1418                                , itemkey => l_itemkey
1419                                , aname => 'TIMEOUT_WAITING_PERIOD'
1420                                , avalue => l_waiting_time
1421                                );
1422 
1423            wf_engine.SetItemAttrNumber
1424                    ( itemtype => p_wf_item_type
1425                                , itemkey => l_itemkey
1426                                , aname => 'NUMBER_OF_REMINDERS'
1427                                , avalue => l_number_of_reminders
1428                                );
1429     -- Now start the WF process
1430            wf_engine.StartProcess ( itemtype => p_wf_item_type
1431                                   , itemkey => l_itemkey );
1432             PA_WORKFLOW_UTILS.Insert_WF_Processes
1436                 ,p_entity_key1         => to_char(l_projects_rec.project_id)
1433             (p_wf_type_code        => 'ASSIGNMENT_APPROVAL'
1434             ,p_item_type           => p_wf_item_type
1435             ,p_item_key            => l_itemkey
1437             ,p_entity_key2         => to_char(p_assignment_id)
1438             ,p_description         => NULL
1439             ,p_err_code            => l_err_code
1440             ,p_err_stage           => l_err_stage
1441             ,p_err_stack           => l_err_stack
1442             );
1443         --Setting the original value
1444         wf_engine.threshold := l_save_threshold;
1445 
1446     -- dbms_output.put_line ('after pa_workflow_utils ');
1447 EXCEPTION
1448  WHEN OTHERS THEN
1449      --Setting the original value
1450      wf_engine.threshold := l_save_threshold;
1451 
1452      -- dbms_output.put_line ('others exception raised ');
1453      -- dbms_output.put_line ('error is '||SQLERRM);
1454 
1455      -- 4537865 : RESET other OUT params also
1456      x_msg_data := SUBSTRB(SQLERRM,1,240);
1457      x_error_message_code := SQLCODE ;
1458      -- 4537865 : End
1459      fnd_msg_pub.add_exc_msg
1460       (p_pkg_name => 'PA_ASGMT_WFSTD',
1461        p_procedure_name => pa_debug.g_err_stack );
1462        x_msg_count := fnd_msg_pub.count_msg;
1463        x_return_status:= FND_API.G_RET_STS_UNEXP_ERROR;
1464 END Start_Workflow ;
1465 
1466 
1467 
1468 PROCEDURE  get_workflow_process_info
1469               (p_status_code IN VARCHAR2
1470                ,x_wf_item_type OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
1471                ,x_wf_process   OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
1472                ,x_wf_type      OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
1473                ,x_msg_count    OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
1474                ,x_msg_data     OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
1475                ,x_return_status  OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
1476                ,x_error_message_code OUT NOCOPY VARCHAR2 ) IS --File.Sql.39 bug 4440895
1477 CURSOR l_stus_csr IS
1478 SELECT ps.wf_success_status_code,
1479        ps.wf_failure_status_code,
1480        ps.workflow_item_type,
1481        ps.workflow_process,
1482        ps.project_system_status_code ,
1483        ps.enable_wf_flag
1484 FROM   pa_project_statuses ps
1485 WHERE  project_status_code = p_status_code;
1486 
1487 l_stus_rec  l_stus_csr%ROWTYPE;
1488 l_msg_count    NUMBER :=0;
1489 l_msg_index_out    NUMBER ;
1490 l_msg_data     VARCHAR2(2000);
1491 l_data             VARCHAR2(2000);
1492 BEGIN
1493     -- This procedure returns whether wf is enabled for the given
1494     -- assignment approval status and if so, the item type and process
1495     -- It also returns whether the WF is an approval WF or an FYI WF
1496     -- The logic is
1497     -- If the approval status is a SUBMITTED status , then the
1498     -- workflow is an APPROVAL WORKFLOW. else if the status
1499     -- is an APPROVED or REJECTED status, the workflow is a FYI only
1500     x_return_status := FND_API.G_RET_STS_SUCCESS;
1501         x_msg_count := 0;
1502         pa_debug.init_err_stack ('pa_asgmt_wfstd.get_workflow_process_info');
1503     OPEN l_stus_csr;
1504     FETCH l_stus_csr INTO l_stus_rec;
1505     IF l_stus_csr%NOTFOUND THEN
1506        x_return_status := FND_API.G_RET_STS_ERROR;
1507        x_error_message_code := 'PA_INVALID_STATUS_CODE';-- msg already avail
1508        pa_utils.add_message (p_app_short_name => 'PA',
1509                                  p_msg_name       => 'PA_INVALID_STATUS_CODE');
1510        l_msg_count := l_msg_count + 1;
1511        CLOSE l_stus_csr;
1512            -- RETURN;
1513         ELSE
1514        CLOSE l_stus_csr;
1515     END IF;
1516 
1517          IF l_msg_count > 0 THEN
1518            IF l_msg_count = 1 THEN
1519              pa_interface_utils_pub.get_messages
1520                  (p_encoded        => FND_API.G_TRUE,
1521                   p_msg_index      => 1,
1522                   p_msg_count      => l_msg_count,
1523                   p_msg_data       => l_msg_data ,
1524                   p_data           => l_data,
1525                   p_msg_index_out  => l_msg_index_out );
1526              x_msg_data  := l_data;
1527              x_msg_count := l_msg_count;
1528        ELSE
1529              x_msg_count := l_msg_count;
1530            END IF;
1531            pa_debug.reset_err_stack;
1532        x_return_status := FND_API.G_RET_STS_ERROR;
1533        RETURN;
1534          END IF;
1535 
1536      IF NVL(l_stus_rec.enable_wf_flag,'N') = 'N' THEN
1537         x_wf_type := 'NOT_ENABLED';
1538      END IF ;
1539      IF NVL(l_stus_rec.enable_wf_flag,'N') = 'Y' THEN
1540             x_wf_item_type := l_stus_rec.workflow_item_type;
1541         x_wf_process   := l_stus_rec.workflow_process;
1542             IF l_stus_rec.project_system_status_code =
1543         'ASGMT_APPRVL_SUBMITTED' THEN
1544          x_wf_type := 'APPROVAL_PROCESS';
1545         ELSIF l_stus_rec.project_system_status_code IN
1546              ('ASGMT_APPRVL_APPROVED','ASGMT_APPRVL_REJECTED','ASGMT_APPRVL_CANCELED') THEN
1547          x_wf_type := 'FYI_NF';
1548         END IF;
1549      END IF;
1550 EXCEPTION
1551  WHEN OTHERS THEN
1552      -- 4537865 : RESET other OUT params also
1553      x_msg_data := SUBSTRB(SQLERRM,1,240);
1554      x_error_message_code := SQLCODE ;
1555      x_wf_item_type := NULL ;
1556      x_wf_process   := NULL ;
1557      x_wf_type      := NULL ;
1558 
1559      -- 4537865 : End
1560      fnd_msg_pub.add_exc_msg
1561       (p_pkg_name => 'PA_ASGMT_WFSTD',
1562        p_procedure_name => pa_debug.g_err_stack );
1563        x_msg_count := fnd_msg_pub.count_msg;
1564        x_return_status:= FND_API.G_RET_STS_UNEXP_ERROR;
1565        RAISE ;
1566 END Get_workflow_process_info ;
1567 
1568 FUNCTION Is_approval_pending (p_assignment_id IN NUMBER) RETURN VARCHAR2
1569 IS
1570 CURSOR l_asgmt_csr IS
1571 SELECT NVL(pending_approval_flag,'N')
1572 FROM pa_project_assignments
1573 WHERE assignment_id = p_assignment_id;
1574 l_pending_approval_flag pa_project_assignments.pending_approval_flag%TYPE;
1575 BEGIN
1576     OPEN l_asgmt_csr;
1577     FETCH l_asgmt_csr INTO l_pending_approval_flag;
1578     IF l_asgmt_csr%NOTFOUND THEN
1579        l_pending_approval_flag := 'N';
1580     END IF;
1581     CLOSE l_asgmt_csr;
1582     RETURN l_pending_approval_flag;
1583 EXCEPTION
1584  WHEN OTHERS THEN
1585     RAISE ;
1586 END Is_Approval_Pending ;
1587 
1588 
1589 
1590 PROCEDURE Generate_URL ( itemtype  IN VARCHAR2
1591                          , itemkey   IN VARCHAR2
1592                          , actid     IN NUMBER
1593                          , funcmode  IN VARCHAR2
1594                          , resultout OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
1595                          ) IS
1596 
1597 l_asgmt_details_url          VARCHAR2(600);
1598 l_resource_details_url       VARCHAR2(600);
1599 l_resource_schedules_url     VARCHAR2(600);
1600 l_view_conflict_url          VARCHAR2(600);
1601 l_overcom_description        VARCHAR2(600);
1602 l_resolve_conflicts_by_rmvl  VARCHAR2(1);
1603 l_assignment_id              NUMBER;
1604 l_resource_person_id         NUMBER;
1605 l_resource_id                NUMBER;
1606 l_conflict_group_id          NUMBER;
1607 l_asgmt_start_date           DATE;
1608 l_asgmt_end_date             DATE;
1609 l_return_status              VARCHAR2(1);
1610 l_msg_count                  NUMBER;
1611 l_msg_data                   VARCHAR2(2000);
1612 
1613 l_asgmt_type                 pa_project_assignments.assignment_type%TYPE; /*Added for bug 6408552*/
1614 BEGIN
1615 
1616         pa_debug.init_err_stack ('pa_asgmt_wfstd.Generate_URL');
1617         -- Return if WF Not Running
1618     IF (funcmode <> wf_engine.eng_run) THEN
1619             resultout := wf_engine.eng_null;
1620             RETURN;
1621     END IF;
1622         l_assignment_id := wf_engine.GetItemAttrNumber
1623                    (itemtype => itemtype,
1624                     itemkey  => itemkey,
1625                     aname    => 'ASSIGNMENT_ID');
1626 
1627         l_resource_person_id := wf_engine.GetItemAttrNumber
1628                    (itemtype => itemtype,
1629                     itemkey  => itemkey,
1630                     aname    => 'RESOURCE_PERSON_ID');
1631 
1632         l_resource_id  := wf_engine.GetItemAttrNumber
1633                    (itemtype => itemtype,
1634                     itemkey  => itemkey,
1635                     aname    => 'RESOURCE_ID');
1636 
1637         l_asgmt_start_date  := wf_engine.GetItemAttrDate
1638                    (itemtype => itemtype,
1639                     itemkey  => itemkey,
1640                     aname    => 'START_DATE');
1641 
1642         l_asgmt_end_date  := wf_engine.GetItemAttrDate
1643                    (itemtype => itemtype,
1644                     itemkey  => itemkey,
1645                     aname    => 'END_DATE');
1646 
1647         l_conflict_group_id  := wf_engine.GetItemAttrNumber
1648                        (itemtype => itemtype,
1649                         itemkey  => itemkey,
1650                         aname    => 'CONFLICT_GROUP_ID');
1651 
1652         /*Added for bug 6408552*/
1653 	l_asgmt_type := wf_engine.GetItemAttrText
1654     			       (itemtype => itemtype,
1655      			        itemkey  => itemkey,
1656      			        aname    => 'ASSIGNMENT_TYPE');
1657         resultout := wf_engine.eng_completed||':'||'S';
1658     -- call to the generate url api goes here
1659     -- If unable to generate url return
1660     -- resultout := wf_engine.eng_completed||':'||'F';
1661     -- If such URL generation succeded then set the appropriate attributes
1662     -- so that it gets displayed in the NF
1663 /*Code modified for bug 6408552*/
1664 /*make url with paCalledPage as 'AdminAsmt' for an Admin Assignment*/
1665 IF (l_asgmt_type = 'STAFFED_ADMIN_ASSIGNMENT') THEN
1666 
1667 	   l_asgmt_details_url := 'JSP:/OA_HTML/OA.jsp?akRegionApplicationId=275&akRegionCode=PA_ASMT_LAYOUT'
1668                                || '&paCalledPage=AdminAsmt&paAssignmentId=' || l_assignment_id
1669                                ||'&addBreadCrumb=RP';
1670 
1671 ELSE -- old code that was being called generically
1672 
1673 	   l_asgmt_details_url := 'JSP:/OA_HTML/OA.jsp?akRegionApplicationId=275&akRegionCode=PA_ASMT_LAYOUT'
1674                                || '&paCalledPage=ProjStaffedAsmt&paAssignmentId=' || l_assignment_id
1675                                ||'&addBreadCrumb=RP';
1676 
1677 END IF ;
1678 /*Code modifications end for bug 6408552*/
1679            l_resource_schedules_url := 'JSP:/OA_HTML/OA.jsp?akRegionApplicationId=275&akRegionCode='
1680                                     || 'PA_VIEW_RESOURCE_LAYOUT&paResourceId=' || l_resource_id
1681                                     || '&addBreadCrumb=RP';
1682 
1683            wf_engine.SetItemAttrText
1684                    ( itemtype => itemtype
1685                                , itemkey => itemkey
1686                                , aname => 'ASSIGNMENT_DETAILS_URL_INFO'
1687                                , avalue => l_asgmt_details_url
1688                                );
1689            wf_engine.SetItemAttrText
1690                    ( itemtype => itemtype
1691                                , itemkey =>  itemkey
1692                                , aname => 'RESOURCE_DETAILS_URL_INFO'
1693                                , avalue => l_resource_details_url
1694                                );
1695            wf_engine.SetItemAttrText
1696                    ( itemtype => itemtype
1697                                , itemkey =>  itemkey
1698                                , aname => 'RESOURCE_SCHEDULES_URL_INFO'
1699                                , avalue => l_resource_schedules_url
1700                                );
1701 
1702            -- Display the overcommitment description and URL only when there is any conflict.
1703            IF (l_conflict_group_id IS NOT NULL) THEN
1704               PA_SCHEDULE_PVT.will_resolve_conflicts_by_rmvl
1705                                            ( p_conflict_group_id         => l_conflict_group_id
1706                                            , x_resolve_conflicts_by_rmvl => l_resolve_conflicts_by_rmvl
1707                        , x_msg_count             => l_msg_count
1708                        , x_msg_data                  => l_msg_data
1709                        , x_return_status             => l_return_status);
1710 
1711               -- set overcommitment description
1712               IF (l_resolve_conflicts_by_rmvl = 'Y') THEN
1713                  l_overcom_description := 'If approved, this assignment will result in the removal of conflicting '
1714                                        || 'hours from an existing assignment of the resource.';
1715               ELSE
1716                  l_overcom_description := 'If approved, this assignment will result in an overcommitment of the resource.';
1717               END IF;
1718 
1719               wf_engine.SetItemAttrText
1720                       ( itemtype => itemtype
1721                                   , itemkey  => itemkey
1722                                   , aname    => 'OVERCOM_DESCRIPTION'
1723                                   , avalue   => l_overcom_description );
1724 
1725               -- set 'Number of Assignments Resulting in Resource Overcommitment -1/0' for single approval
1726               -- required notification.
1727               wf_engine.SetItemAttrNumber
1728                    ( itemtype => itemtype
1729                                , itemkey => itemkey
1730                                , aname => 'NUMBER_OF_OVERCOM_ASGMT'
1731                                , avalue => 1 );
1732            ELSE
1733               wf_engine.SetItemAttrNumber
1734                    ( itemtype => itemtype
1735                                , itemkey => itemkey
1736                                , aname => 'NUMBER_OF_OVERCOM_ASGMT'
1737                                , avalue => 0 );
1738            END IF; -- IF (l_conflict_group_id IS NULL)
1739 
1740            -- set overcommitment url
1741            l_view_conflict_url := 'JSP:/OA_HTML/OA.jsp?akRegionApplicationId=275&akRegionCode=PA_RES_OVERCOMMITMENT_LAYOUT'
1742                                || '&paAssignmentId=' || l_assignment_id || '&paConflictGroupId=' || l_conflict_group_id
1743                                || '&paCallingPage=Default&addBreadCrumb=RP';
1744 
1745            wf_engine.SetItemAttrText
1746                       ( itemtype => itemtype
1747                                   , itemkey  => itemkey
1748                                   , aname    => 'VIEW_CONFLICT_URL_INFO'
1749                                   , avalue   => l_view_conflict_url );
1750 
1751           pa_debug.reset_err_stack;
1752 
1753 EXCEPTION
1754    WHEN OTHERS THEN
1755     WF_CORE.CONTEXT
1756         ('PA_ASGMT_WFSTD',
1757          'Generate_URL',
1758           itemtype,
1759           itemkey,
1760           to_char(actid),
1761           funcmode);
1762     resultout := wf_engine.eng_completed||':'||'F';
1763     RAISE;
1764 
1765 END Generate_URL ;
1766 
1767 PROCEDURE Generate_URL_failure
1768             ( itemtype  IN VARCHAR2
1769                          , itemkey   IN VARCHAR2
1770                          , actid     IN NUMBER
1771                          , funcmode  IN VARCHAR2
1772                          , resultout OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
1773                          ) IS
1774 l_mesg    VARCHAR2(240);
1775 BEGIN
1776         -- Return if WF Not Running
1777     IF (funcmode <> wf_engine.eng_run) THEN
1778             resultout := wf_engine.eng_null;
1779             RETURN;
1780     END IF;
1781       FND_MESSAGE.SET_NAME ('PA','PA_ASGMT_URL_GEN_FAILURE');
1782       l_mesg := FND_MESSAGE.GET;
1783           wf_engine.SetItemAttrText
1784                    (itemtype => itemtype
1785                                ,itemkey =>  itemkey
1786                                ,aname => 'URL_FAILURE_INFO'
1787                                ,avalue => l_mesg
1788                                );
1789 EXCEPTION
1790    WHEN OTHERS THEN
1791     WF_CORE.CONTEXT
1792         ('PA_ASGMT_WFSTD',
1793          'Generate_URL_Failure',
1794           itemtype,
1795           itemkey,
1796           to_char(actid),
1797           funcmode);
1798        RAISE;
1799 END Generate_URL_failure;
1800 
1801 PROCEDURE Start_New_WF   (itemtype IN VARCHAR2
1802                          , itemkey IN VARCHAR2
1803                          , actid IN NUMBER
1804                          , funcmode IN VARCHAR2
1805                          , resultout OUT NOCOPY VARCHAR2 )  IS --File.Sql.39 bug 4440895
1806 
1807 l_new_item_type         VARCHAR2(30);
1808 l_new_process           VARCHAR2(30);
1809 l_new_item_key          VARCHAR2(30);
1810 l_project_id            NUMBER;
1811 l_assignment_id         NUMBER;
1812 l_resource_person_id    NUMBER;
1813 l_new_asgmt_status_code VARCHAR2(30);
1814 l_conflict_group_id     NUMBER;
1815 l_msg_count             NUMBER;
1816 l_msg_data          VARCHAR2(200);
1817 l_error_message_code    VARCHAR2(200);
1818 l_return_status         VARCHAR2(30);
1819 BEGIN
1820         pa_debug.init_err_stack ('pa_asgmt_wfstd.start_new_wf');
1821         -- Return if WF Not Running
1822     IF (funcmode <> wf_engine.eng_run) THEN
1823             resultout := wf_engine.eng_null;
1824             RETURN;
1825     END IF;
1826         l_new_item_type      := wf_engine.GetItemAttrText
1827                    (itemtype => itemtype,
1828                     itemkey  => itemkey,
1829                     aname    => 'NEW_WF_ITEM_TYPE');
1830 
1831         l_new_process        := wf_engine.GetItemAttrText
1832                    (itemtype => itemtype,
1833                     itemkey  => itemkey,
1834                     aname    => 'NEW_WF_PROCESS_NAME');
1835     IF (l_new_item_type IS NOT NULL AND
1836         l_new_process IS NOT NULL ) THEN
1837         -- Get the necessary details from the item attributes
1838              l_new_asgmt_status_code      :=
1839              wf_engine.GetItemAttrText
1840                    (itemtype => itemtype,
1841                     itemkey  => itemkey,
1842                     aname    => 'NEW_ASGMT_STATUS_CODE' );
1843              l_project_id     := wf_engine.GetItemAttrNumber
1844                    (itemtype => itemtype,
1845                     itemkey  => itemkey,
1846                     aname    => 'PROJECT_ID' );
1847              l_assignment_id    := wf_engine.GetItemAttrNumber
1848                    (itemtype => itemtype,
1849                     itemkey  => itemkey,
1850                     aname    => 'ASSIGNMENT_ID');
1851              l_resource_person_id    := wf_engine.GetItemAttrNumber
1852                    (itemtype => itemtype,
1853                     itemkey  => itemkey,
1854                     aname    => 'RESOURCE_PERSON_ID');
1855              l_conflict_group_id     := wf_engine.GetItemAttrNumber
1856                    (itemtype => itemtype,
1857                     itemkey  => itemkey,
1858                     aname    => 'CONFLICT_GROUP_ID');
1859 
1860          Start_Workflow
1861                 ( p_project_id          =>  l_project_id
1862                         , p_assignment_id       => l_assignment_id
1863                         , p_status_code         => l_new_asgmt_status_code
1864                         , p_person_id           => l_resource_person_id
1865                         , p_wf_item_type        => l_new_item_type
1866                         , p_wf_process          => l_new_process
1867                         , p_approver1_person_id => NULL
1868                         , p_approver1_type      => NULL
1869                         , p_approver2_person_id => NULL
1870                         , p_approver2_type      => NULL
1871             , p_apprvl_item_type    => itemtype
1872             , p_apprvl_item_key     => itemkey
1873                         , p_conflict_group_id   => l_conflict_group_id
1874                         , x_msg_count           => l_msg_count
1875                         , x_msg_data            => l_msg_data
1876                         , x_return_status       => l_return_status
1877                         , x_error_message_code  => l_error_message_code);
1878         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1879                    raise_application_error(-20001, l_error_message_code);
1880             END IF;
1881            END IF;
1882            resultout := wf_engine.eng_completed||':'||'S';
1883            pa_debug.reset_err_stack;
1884 EXCEPTION
1885  WHEN OTHERS THEN
1886     WF_CORE.CONTEXT
1887         ('PA_ASGMT_WFSTD',
1888          'Start_New_WF',
1889           itemtype,
1890           itemkey,
1891           to_char(actid),
1892           funcmode);
1893       resultout := wf_engine.eng_completed||':'||'F';
1894       RAISE ;
1895 END Start_New_WF ;
1896 
1897   PROCEDURE Set_Success_Status  (itemtype IN VARCHAR2
1898                                , itemkey IN VARCHAR2
1899                                , actid IN NUMBER
1900                                , funcmode IN VARCHAR2
1901                                , resultout OUT NOCOPY VARCHAR2 )  IS --File.Sql.39 bug 4440895
1902 
1903 ---l_asgmt_success_status_code  pa_project_statuses.project_status_code%TYPE;
1904 l_asgmt_success_status_code  VARCHAR2(30);
1905 -- l_assignment_id  pa_project_assignments.assignment_id%TYPE;
1906 l_assignment_id  NUMBER;
1907 l_msg_count     NUMBER;
1908 l_msg_data  VARCHAR2(200);
1909 l_error_message_code VARCHAR2(200);
1910 l_return_status VARCHAR2(30);
1911 l_schedule_exception_id NUMBER;
1912 l_is_new_assignment_flag VARCHAR2(1);
1913 BEGIN
1914         pa_debug.init_err_stack ('pa_asgmt_wfstd.Set_Success_Status');
1915         -- Return if WF Not Running
1916     IF (funcmode <> wf_engine.eng_run) THEN
1917             resultout := wf_engine.eng_null;
1918             RETURN;
1919     END IF;
1920         l_asgmt_success_status_code      :=
1921             wf_engine.GetItemAttrText
1922                    (itemtype => itemtype,
1923                     itemkey  => itemkey,
1924                     aname    => 'ASGMT_SUCCESS_STATUS_CODE');
1925         l_assignment_id        :=
1926             wf_engine.GetItemAttrText
1927                    (itemtype => itemtype,
1928                     itemkey  => itemkey,
1929                     aname    => 'ASSIGNMENT_ID');
1930     -- Now store the approvers' response in the global variable
1931     Capture_approver_response (p_item_type => itemtype,
1932                    p_item_key  => itemkey );
1933     Set_Asgmt_wf_result_Status
1934         (p_assignment_id => l_assignment_id,
1935          p_status_code   => l_asgmt_success_status_code,
1936                  p_result_type   => 'APPROVE',
1937          p_item_type     => itemtype,
1938          p_item_key      => itemkey ,
1939          x_return_status => l_return_status );
1940 
1941     -- Any additional API for schedules goes here
1942     -- IF l_schedule_exception_id IS NOT NULL THEN
1943 /*
1944           SAVEPOINT asgmt_success;
1945       pa_schedule_pvt.update_asgn_wf_success  (
1946           P_ASSIGNMENT_ID           =>  l_assignment_id
1947                  ,P_IS_NEW_ASSIGNMENT_FLAG  =>  l_is_new_assignment_flag
1948          ,P_SCH_EXCEPTION_ID        =>  l_schedule_exception_id
1949          ,P_SUCCESS_STATUS_CODE    =>   l_asgmt_success_status_code
1950          ,X_RETURN_STATUS            => l_return_status
1951          ,X_MSG_COUNT                => l_msg_count
1952          ,X_MSG_DATA                 => l_msg_data );
1953          */
1954            IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1955                resultout := wf_engine.eng_completed||':'||'F';
1956            RETURN;
1957            END IF;
1958         resultout := wf_engine.eng_completed||':'||'S';
1959         pa_debug.reset_err_stack;
1960 
1961 EXCEPTION
1962 WHEN OTHERS THEN
1963     WF_CORE.CONTEXT
1964     ('PA_ASGMT_WFSTD',
1965      'Set_Success_Status',
1966       itemtype,
1967       itemkey,
1968       to_char(actid),
1969       funcmode);
1970     resultout := wf_engine.eng_completed||':'||'F';
1971         RAISE;
1972 
1973 END Set_Success_Status ;
1974 
1975 
1976 PROCEDURE Set_Failure_Status  (itemtype IN VARCHAR2
1977                                , itemkey IN VARCHAR2
1978                                , actid IN NUMBER
1979                                , funcmode IN VARCHAR2
1980                                , resultout OUT NOCOPY VARCHAR2 )  IS --File.Sql.39 bug 4440895
1981 
1982 l_asgmt_failure_status_code  pa_project_statuses.project_status_code%TYPE;
1983 l_assignment_id  pa_project_assignments.assignment_id%TYPE;
1984 l_msg_count     NUMBER;
1985 l_msg_data  VARCHAR2(200);
1986 l_error_message_code VARCHAR2(200);
1987 l_return_status VARCHAR2(30);
1988 l_schedule_exception_id pa_schedule_exceptions.schedule_exception_id%TYPE;
1989 l_is_new_assignment_flag VARCHAR2(1);
1990 BEGIN
1991         pa_debug.init_err_stack ('pa_asgmt_wfstd.Set_Failure_Status');
1992         -- Return if WF Not Running
1993     IF (funcmode <> wf_engine.eng_run) THEN
1994             resultout := wf_engine.eng_null;
1995             RETURN;
1996     END IF;
1997         l_asgmt_failure_status_code      :=
1998             wf_engine.GetItemAttrText
1999                    (itemtype => itemtype,
2000                     itemkey  => itemkey,
2001                     aname    => 'ASGMT_FAILURE_STATUS_CODE');
2002         l_assignment_id        :=
2003             wf_engine.GetItemAttrText
2004                    (itemtype => itemtype,
2005                     itemkey  => itemkey,
2006                     aname    => 'ASSIGNMENT_ID');
2007     -- Now store the approvers' response in the global variable
2008     Capture_approver_response (p_item_type => itemtype,
2009                    p_item_key  => itemkey );
2010     Set_Asgmt_wf_result_Status
2011         (p_assignment_id => l_assignment_id,
2012          p_status_code   => l_asgmt_failure_status_code,
2013                  p_result_type   => 'REJECT',
2014          p_item_type     => itemtype,
2015          p_item_key      => itemkey,
2016              x_return_status => l_return_status );
2017 
2018     -- Any additional API for schedules goes here
2019      -- IF l_schedule_exception_id IS NOT NULL THEN
2020        /*
2021     SAVEPOINT asgmt_failure;
2022     pa_schedule_pvt.update_asgn_wf_failure
2023         (p_assignment_id     => l_assignment_id
2024         ,p_is_new_assignment_flag => l_is_new_assignment_flag
2025         ,p_sch_exception_id  => l_schedule_exception_id
2026         ,p_failure_status_code   => l_asgmt_failure_status_code
2027         ,x_return_status     => l_return_status
2028         ,x_msg_count         => l_msg_count
2029         ,x_msg_data          => l_msg_data );
2030          */
2031           IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2032                resultout := wf_engine.eng_completed||':'||'F';
2033            RETURN;
2034           END IF;
2035      resultout := wf_engine.eng_completed||':'||'S';
2036      pa_debug.reset_err_stack;
2037 
2038 EXCEPTION
2039 WHEN OTHERS THEN
2040     WF_CORE.CONTEXT
2041        ('PA_ASGMT_WFSTD',
2042     'Set_Failure_Status',
2043     itemtype,
2044     itemkey,
2045     to_char(actid),
2046     funcmode);
2047      resultout := wf_engine.eng_completed||':'||'F';
2048      RAISE;
2049 END Set_Failure_Status ;
2050 
2051   PROCEDURE Check_Wf_Enabled    (itemtype IN VARCHAR2
2052                                , itemkey IN VARCHAR2
2053                                , actid IN NUMBER
2054                                , funcmode IN VARCHAR2
2055                                , resultout OUT NOCOPY VARCHAR2 )  IS --File.Sql.39 bug 4440895
2056 
2057 l_assignment_id pa_project_statuses.project_status_code%TYPE;
2058 l_new_item_type  VARCHAR2(30);
2059 l_new_process    VARCHAR2(30);
2060 l_new_asgmt_status_code   pa_project_statuses.project_status_code%TYPE;
2061 l_return_status           VARCHAR2(1);
2062 l_error_message_code      VARCHAR2(30);
2063 l_wf_type   VARCHAR2(30);
2064 l_msg_count     NUMBER;
2065 l_msg_data  VARCHAR2(200);
2066 
2067 BEGIN
2068     /*
2069     Get the foll item attr
2070      'NEW_ASGMT_STATUS_CODE'
2071     Get the WF enabled flag, item type and process name
2072     of the new asgmt status code
2073     If wf enabled flag = 'N' then resultout = 'F'
2074     else
2075       set the new wf item type and new wf process attr
2076       resultout = 'T'
2077     */
2078         pa_debug.init_err_stack ('pa_asgmt_wfstd.Check_Wf_Enabled');
2079         -- Return if WF Not Running
2080     IF (funcmode <> wf_engine.eng_run) THEN
2081             resultout := wf_engine.eng_null;
2082             RETURN;
2083     END IF;
2084         l_new_asgmt_status_code      :=
2085             wf_engine.GetItemAttrText
2086                    (itemtype => itemtype,
2087                     itemkey  => itemkey,
2088                     aname    => 'NEW_ASGMT_STATUS_CODE' );
2089         get_workflow_process_info
2090                  (p_status_code => l_new_asgmt_status_code
2091                  ,x_wf_item_type => l_new_item_type
2092                  ,x_wf_process   => l_new_process
2093                  ,x_wf_type      => l_wf_type
2094                  ,x_msg_count    => l_msg_count
2095          ,x_msg_data     => l_msg_data
2096                  ,x_return_status  => l_return_status
2097                  ,x_error_message_code => l_error_message_code );
2098 
2099     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2100            resultout := wf_engine.eng_completed||':'||'N';
2101        RETURN;
2102     END IF;
2103     IF l_wf_type = 'NOT_ENABLED' THEN
2104            resultout := wf_engine.eng_completed||':'||'N';
2105     ELSE
2106         IF (l_new_item_type IS NOT NULL AND
2107         l_new_process IS NOT NULL ) THEN
2108                wf_engine.SetItemAttrText
2109                    (itemtype => itemtype
2110                                ,itemkey =>  itemkey
2111                                ,aname => 'NEW_WF_ITEM_TYPE'
2112                                ,avalue => l_new_item_type
2113                                );
2114                wf_engine.SetItemAttrText
2115                    (itemtype => itemtype
2116                                ,itemkey =>  itemkey
2117                                ,aname => 'NEW_WF_PROCESS_NAME'
2118                                ,avalue => l_new_process
2119                                );
2120                resultout := wf_engine.eng_completed||':'||'Y';
2121          ELSE
2122                resultout := wf_engine.eng_completed||':'||'N';
2123              END IF;
2124           END IF;
2125            pa_debug.reset_err_stack;
2126 EXCEPTION
2127   WHEN OTHERS THEN
2128       WF_CORE.CONTEXT
2129     ('PA_ASGMT_WFSTD',
2130      'Check_Wf_Enabled',
2131       itemtype,
2132       itemkey,
2133       to_char(actid),
2134       funcmode);
2135      RAISE;
2136 END Check_Wf_Enabled ;
2137 
2138 
2139   PROCEDURE Generate_Approvers (itemtype IN VARCHAR2
2140                                , itemkey IN VARCHAR2
2141                                , actid IN NUMBER
2142                                , funcmode IN VARCHAR2
2143                                , resultout OUT NOCOPY VARCHAR2 )  IS --File.Sql.39 bug 4440895
2144 
2145 l_approvers_list_tbl  PA_CLIENT_EXTN_ASGMT_WF.Users_List_Tbltyp ;
2146 l_out_approvers_list_tbl  PA_CLIENT_EXTN_ASGMT_WF.Users_List_Tbltyp ;
2147 l_number_of_approvers  NUMBER := 0;
2148 l_approvers_list_rec  PA_CLIENT_EXTN_ASGMT_WF.Users_List_Rectyp ;
2149 l_assignment_id   pa_project_assignments.assignment_id%TYPE;
2150 l_project_id      pa_projects_all.project_id%TYPE;
2151 l_approver_user_name   wf_users.name%type; ----- VARCHAR2(30); Commented for bug 3267790 VARCHAR2(100);
2152 /* Modified length from 30 to 100 for bug 3148857 */
2153 l_approver_person_id  NUMBER := 0;
2154 l_approver_type   VARCHAR2(30);
2155 l_item_attr_name  VARCHAR2(30);
2156 l_approvers_list_tbl_idx NUMBER := 1;
2157 BEGIN
2158         pa_debug.init_err_stack ('pa_asgmt_wfstd.Generate_Approvers');
2159         -- Return if WF Not Running
2160     IF (funcmode <> wf_engine.eng_run) THEN
2161             resultout := wf_engine.eng_null;
2162             RETURN;
2163     END IF;
2164      NULL;
2165         l_assignment_id := wf_engine.GetItemAttrNumber
2166                    (itemtype => itemtype,
2167                     itemkey  => itemkey,
2168                     aname    => 'ASSIGNMENT_ID');
2169         l_project_id     := wf_engine.GetItemAttrNumber
2170                    (itemtype => itemtype,
2171                     itemkey  => itemkey,
2172                     aname    => 'PROJECT_ID' );
2173 --  Now populate the PL/SQL table with the 2 approvers
2174 --  which are done by the product by default
2175     FOR i IN 1..2
2176       LOOP
2177     l_item_attr_name := 'APPROVER_'||i||'_PERSON_ID';
2178         l_approver_person_id :=
2179                              wf_engine.GetItemAttrNumber
2180                    (  itemtype => itemtype
2181                                 , itemkey =>  itemkey
2182                                 , aname => l_item_attr_name
2183                                );
2184 
2185     l_item_attr_name := 'APPROVER'||i||'_USER_NAME';
2186         l_approver_user_name := wf_engine.GetItemAttrText
2187                    ( itemtype => itemtype
2188                                , itemkey =>  itemkey
2189                                , aname =>  l_item_attr_name
2190                                );
2191     l_item_attr_name := 'APPROVER_'||i||'_TYPE';
2192         l_approver_type :=    wf_engine.GetItemAttrText
2193                    ( itemtype => itemtype
2194                                , itemkey =>  itemkey
2195                                , aname =>  l_item_attr_name
2196                                );
2197     IF l_approver_user_name IS NOT NULL THEN
2198          l_approvers_list_rec.User_Name := l_approver_user_name;
2199          l_approvers_list_rec.Person_id := l_approver_person_id;
2200          l_approvers_list_rec.Type :=  l_approver_type;
2201          l_approvers_list_rec.Routing_Order :=  i;
2202          l_approvers_list_tbl(l_approvers_list_tbl_idx) := l_approvers_list_rec;
2203          l_approvers_list_tbl_idx := l_approvers_list_tbl_idx + 1;
2204        END IF;
2205      END LOOP;
2206     -- Pass the pl/sql table to the client extension so
2207     -- users can customize the approvers
2208    PA_CLIENT_EXTN_ASGMT_WF.Generate_Assignment_Approvers
2209     (p_assignment_id                => l_assignment_id
2210     ,p_project_id               => l_project_id
2211     ,p_in_list_of_approvers     => l_approvers_list_tbl
2212     ,x_out_list_of_approvers        => l_out_approvers_list_tbl
2213     ,x_number_of_approvers      => l_number_of_approvers );
2214 
2215     -- Call the populate_wf_performers procedure
2216     populate_wf_performers
2217         ( p_wf_type_code => 'ASSIGNMENT_APPROVAL'
2218          ,p_item_type    => itemtype
2219          ,p_item_key     => itemkey
2220          ,p_object_id1  => l_assignment_id
2221          ,p_object_id2  => l_project_id
2222          ,p_in_performers_tbl => l_out_approvers_list_tbl
2223          ,p_current_approver_flag  => 'N'
2224      ,x_number_of_performers => l_number_of_approvers );
2225 
2226     -- Now set the number of approvers
2227            wf_engine.SetItemAttrNumber
2228                    (  itemtype => itemtype
2229                                 , itemkey =>  itemkey
2230                                 , aname => 'NUMBER_OF_APPROVERS'
2231                                 , avalue => l_number_of_approvers
2232                                );
2233            pa_debug.reset_err_stack;
2234 
2235 EXCEPTION
2236   WHEN OTHERS THEN
2237     WF_CORE.CONTEXT
2238         ('PA_ASGMT_WFSTD',
2239          'Generate_Approvers',
2240           itemtype,
2241           itemkey,
2242           to_char(actid),
2243           funcmode);
2244      RAISE;
2245 END Generate_Approvers ;
2246 
2247 PROCEDURE get_Approver         (itemtype IN VARCHAR2
2248                                ,itemkey IN VARCHAR2
2249                                ,actid IN NUMBER
2250                                ,funcmode IN VARCHAR2
2251                                ,resultout OUT NOCOPY VARCHAR2 ) IS --File.Sql.39 bug 4440895
2252 l_number_of_approvers  NUMBER := 0;
2253 l_approver_loop_counter NUMBER := 0;
2254 l_approver_item_attr_name VARCHAR2(30);
2255 l_approver_user_name pa_wf_ntf_performers.user_name%TYPE; ----VARCHAR2(240); Commented for bug 3267790
2256 l_prev_approver_user_name wf_users.name%TYPE;             ----VARCHAR2(240); Commented for bug 3267790 as this takes the value from wf_users
2257 l_approver_type      VARCHAR2(30);
2258 l_assignment_id   NUMBER;
2259 l_wf_startedby_uname fnd_user.user_name%type;
2260 
2261 BEGIN
2262     /*
2263      Get item attr approvals loop counter and number of approvers
2264      Approvals loop counter := approvals loop counter + 1;
2265      If approvals loop counter > number of approvers , resultout = 'F'
2266           and return
2267      Else if approval loop counter = 1, set performer to approver1
2268      and so on.
2269      Set performer item attr concat with approvals loop counter
2270      Set approvals loop counter
2271      Resultout = 'S'
2272     */
2273         -- Return if WF Not Running
2274         pa_debug.init_err_stack ('pa_asgmt_wfstd.get_approver');
2275     IF (funcmode <> wf_engine.eng_run) THEN
2276             resultout := wf_engine.eng_null;
2277             RETURN;
2278     END IF;
2279            l_number_of_approvers := wf_engine.GetItemAttrNumber
2280                    (  itemtype => itemtype
2281                                 , itemkey =>  itemkey
2282                                 , aname => 'NUMBER_OF_APPROVERS'
2283                                );
2284            l_approver_loop_counter := wf_engine.getItemAttrNumber
2285                    (  itemtype => itemtype
2286                                 , itemkey =>  itemkey
2287                                 , aname => 'APPROVER_LOOP_COUNTER'
2288                                );
2289            l_assignment_id := wf_engine.GetItemAttrNumber
2290                    (itemtype => itemtype,
2291                     itemkey  => itemkey,
2292                     aname    => 'ASSIGNMENT_ID');
2293 
2294        l_approver_loop_counter := l_approver_loop_counter + 1;
2295     IF l_approver_loop_counter > l_number_of_approvers THEN
2296              resultout := wf_engine.eng_completed||':'||'F';
2297          RETURN ;
2298     END IF;
2299         get_wf_performer (p_wf_type_code => 'ASSIGNMENT_APPROVAL'
2300               ,p_item_type   => itemtype
2301               ,p_item_key    => itemkey
2302               ,p_routing_order => l_approver_loop_counter
2303                   ,p_object_id1  => l_assignment_id
2304               ,x_performer_name => l_approver_user_name
2305               ,x_performer_type => l_approver_type );
2306 
2307     IF l_approver_user_name IS NULL THEN
2308              resultout := wf_engine.eng_completed||':'||'F';
2309          RETURN ;
2310     END IF;
2311     -- In order to set the forwarded from, capture the current
2312     -- approver before modifying the same
2313     -- Set the current approver as the previous approver
2314     -- Handling a NULL previous approver (which is likely when
2315     -- the current approver is the first approver) is done
2316     -- in the Set forwarded from procedure
2317     l_prev_approver_user_name := wf_engine.GetItemAttrText
2318                    ( itemtype => itemtype
2319                                , itemkey =>  itemkey
2320                                , aname => 'APPROVER_UNAME'
2321                                );
2322         wf_engine.SetItemAttrText
2323                    ( itemtype => itemtype
2324                                , itemkey =>  itemkey
2325                                , aname => 'PREV_APPROVER_UNAME'
2326                                , avalue => l_prev_approver_user_name
2327                                );
2328         wf_engine.SetItemAttrText
2329                    ( itemtype => itemtype
2330                                , itemkey =>  itemkey
2331                                , aname => 'APPROVER_UNAME'
2332                                , avalue => l_approver_user_name
2333                                );
2334            wf_engine.SetItemAttrNumber
2335                    ( itemtype => itemtype
2336                                , itemkey =>  itemkey
2337                                , aname => 'APPROVER_LOOP_COUNTER'
2338                                , avalue => l_approver_loop_counter
2339                                );
2340 
2341 /*Added the code for the bug 3595857*/
2342     IF l_approver_loop_counter = 1 THEN
2343         l_wf_startedby_uname := wf_engine.GetItemAttrText
2344                    ( itemtype => itemtype
2345                                , itemkey =>  itemkey
2346                                , aname => 'WORKFLOW_STARTED_BY_UNAME'
2347                                );
2348 
2349            wf_engine.SetItemAttrText
2350                                ( itemtype => itemtype
2351                                , itemkey => itemkey
2352                                , aname => 'FROM_ROLE_VALUE'
2353                                , avalue =>  l_wf_startedby_uname
2354                                );
2355    ELSE
2356                wf_engine.SetItemAttrText
2357                                ( itemtype => itemtype
2358                                , itemkey => itemkey
2359                                , aname => 'FROM_ROLE_VALUE'
2360                                , avalue => l_prev_approver_user_name
2361                                );
2362     END IF;
2363     /*End of the code addition for the bug 3595857*/
2364 
2365         -- Need to set the current user as the current approver
2366         -- and set the flag to 'N' for the rest
2367         --
2368         UPDATE pa_wf_ntf_performers
2369         SET current_approver_flag =
2370         (DECODE(user_name,l_approver_user_name,'Y','N'))
2371         WHERE item_type = itemtype
2372         AND   item_key  = itemkey
2373         AND   object_id1 = l_assignment_id;
2374             resultout := wf_engine.eng_completed||':'||'S';
2375            pa_debug.reset_err_stack;
2376 EXCEPTION
2377   WHEN OTHERS THEN
2378     WF_CORE.CONTEXT
2379         ('PA_ASGMT_WFSTD',
2380          'Get_Approver',
2381           itemtype,
2382           itemkey,
2383           to_char(actid),
2384           funcmode);
2385      RAISE;
2386 END Get_Approver ;
2387 
2388 PROCEDURE Generate_apprvl_nf_recipients
2389                     (itemtype IN VARCHAR2
2390                                , itemkey IN VARCHAR2
2391                                , actid IN NUMBER
2392                                , funcmode IN VARCHAR2
2393                                , resultout OUT NOCOPY VARCHAR2 ) IS --File.Sql.39 bug 4440895
2394 
2395 l_approval_nf_rects_tbl  PA_CLIENT_EXTN_ASGMT_WF.Users_List_Tbltyp ;
2396 l_out_approval_nf_rects_tbl  PA_CLIENT_EXTN_ASGMT_WF.Users_List_Tbltyp ;
2397 l_number_of_recipients  NUMBER := 0;
2398 l_approval_nf_rects_rec  PA_CLIENT_EXTN_ASGMT_WF.Users_List_Rectyp ;
2399 l_assignment_id   pa_project_assignments.assignment_id%TYPE;
2400 l_project_id      pa_projects_all.project_id%TYPE;
2401 l_approval_nf_rect_username   VARCHAR2(100);  /* Modified length from 30 to 100 for bug 3148857 */
2402 l_rect_person_id  NUMBER := 0;
2403 l_recipient_type   VARCHAR2(30);
2404 l_item_attr_name  VARCHAR2(30);
2405 l_number_of_apprvl_nf_rects  NUMBER := 0;
2406 l_approval_nf_loop_counter  NUMBER := 0;
2407 l_ntfy_rect_item_attr_name VARCHAR2(30);
2408 l_ntfy_apprvl_recipient_name wf_users.name%TYPE;  ---VARCHAR2(240); Changed for bug 3267790
2409 l_ntfy_apprvl_rect_person_id NUMBER := 0;
2410 l_ntfy_apprvl_rect_type VARCHAR2(30);
2411 l_apprvl_item_type  VARCHAR2(30);
2412 l_apprvl_item_key  VARCHAR2(30);
2413 l_number_of_apprvl_recipients NUMBER := 0;
2414 
2415 BEGIN
2416     -- This will not do anything in milestone 1. In version 1
2417     -- appropriate client extensions will be called
2418 
2419        pa_debug.init_err_stack ('pa_asgmt_wfstd.Generate_apprvl_nf_recipients');
2420         -- Return if WF Not Running
2421     IF (funcmode <> wf_engine.eng_run) THEN
2422             resultout := wf_engine.eng_null;
2423             RETURN;
2424     END IF;
2425         l_assignment_id := wf_engine.GetItemAttrNumber
2426                    (itemtype => itemtype,
2427                     itemkey  => itemkey,
2428                     aname    => 'ASSIGNMENT_ID');
2429         l_project_id     := wf_engine.GetItemAttrNumber
2430                    (itemtype => itemtype,
2431                     itemkey  => itemkey,
2432                     aname    => 'PROJECT_ID' );
2433 --  Now populate the PL/SQL table with the 4 recipients
2434 --  which are done by the product by default
2435         l_number_of_apprvl_nf_rects := wf_engine.GetItemAttrNumber
2436                    (  itemtype => itemtype
2437                                 , itemkey =>  itemkey
2438                                 , aname => 'NUMBER_OF_APPRVL_NF_RECIPIENTS'
2439                                );
2440 
2441     l_apprvl_item_type  := wf_engine.getItemAttrText
2442                    ( itemtype => itemtype
2443                                , itemkey =>  itemkey
2444                                , aname => 'APPRVL_ITEM_TYPE' );
2445 
2446     l_apprvl_item_key   := wf_engine.getItemAttrText
2447                    ( itemtype => itemtype
2448                                , itemkey =>  itemkey
2449                                , aname => 'APPRVL_ITEM_KEY');
2450 
2451      FOR i IN 1..l_number_of_apprvl_nf_rects  LOOP
2452        l_ntfy_rect_item_attr_name :=
2453         'APPROVAL_NF_REC'||i||'_USER_NAME';
2454            l_ntfy_apprvl_recipient_name := wf_engine.getItemAttrText
2455                    ( itemtype => itemtype
2456                                , itemkey =>  itemkey
2457                                , aname => l_ntfy_rect_item_attr_name
2458                                );
2459        l_ntfy_rect_item_attr_name :=
2460         'APPROVAL_NF_REC'||i||'_USER_TYPE';
2461            l_ntfy_apprvl_rect_type := wf_engine.getItemAttrText
2462                    ( itemtype => itemtype
2463                                , itemkey =>  itemkey
2464                                , aname => l_ntfy_rect_item_attr_name
2465                                );
2466        l_ntfy_rect_item_attr_name :=
2467         'APPROVAL_NF_REC'||i||'_PERSON_ID';
2468            l_ntfy_apprvl_rect_person_id := wf_engine.getItemAttrNumber
2469                    ( itemtype => itemtype
2470                                , itemkey =>  itemkey
2471                                , aname => l_ntfy_rect_item_attr_name
2472                                );
2473        IF l_ntfy_apprvl_recipient_name IS NOT NULL THEN
2474               l_number_of_apprvl_recipients := l_number_of_apprvl_recipients + 1;
2475               l_approval_nf_rects_rec.User_Name := l_ntfy_apprvl_recipient_name;
2476               l_approval_nf_rects_rec.Person_id := l_ntfy_apprvl_rect_person_id;
2477               l_approval_nf_rects_rec.Type      := l_ntfy_apprvl_rect_type;
2478               l_approval_nf_rects_rec.Routing_Order :=  l_number_of_apprvl_recipients;
2479               l_approval_nf_rects_tbl(l_number_of_apprvl_recipients) := l_approval_nf_rects_rec;
2480            END IF;
2481      END LOOP;
2482     -- Pass the pl/sql table to the client extension so
2483     -- users can customize the approvers
2484 
2485      PA_CLIENT_EXTN_ASGMT_WF.Generate_NF_Recipients
2486     (p_assignment_id                => l_assignment_id
2487     ,p_project_id               => l_project_id
2488     ,p_notification_type            => 'APPROVAL_FYI'
2489     ,p_in_list_of_recipients        => l_approval_nf_rects_tbl
2490     ,x_out_list_of_recipients       => l_out_approval_nf_rects_tbl
2491     ,x_number_of_recipients     => l_number_of_recipients );
2492 
2493     populate_wf_performers
2494         ( p_wf_type_code => 'APPROVAL_FYI'
2495          ,p_item_type    => itemtype
2496          ,p_item_key     => itemkey
2497          ,p_object_id1  => l_assignment_id
2498          ,p_object_id2  => l_project_id
2499          ,p_in_performers_tbl => l_out_approval_nf_rects_tbl
2500          ,p_current_approver_flag  => 'N'
2501      ,x_number_of_performers => l_number_of_recipients );
2502 
2503     -- Now set the number of approvl nf recipients based
2504     -- on how many records were inserted
2505 
2506          wf_engine.SetItemAttrNumber
2507             (itemtype => itemtype
2508                         ,itemkey =>  itemkey
2509                         ,aname => 'NUMBER_OF_APPRVL_NF_RECIPIENTS'
2510                         ,avalue => l_number_of_recipients
2511             );
2512     -- Now populate the Comments fields, which would have
2513     -- been stored in the pa_wf_ntf_performers table
2514        IF (l_apprvl_item_type IS NOT NULL AND l_apprvl_item_key
2515            IS NOT NULL ) THEN
2516          Set_approver_comments  (p_apprvl_item_type => l_apprvl_item_type
2517                 ,p_apprvl_item_key  => l_apprvl_item_key
2518                 ,p_item_type        => itemtype
2519                 ,p_item_key         => itemkey
2520                 ,p_assignment_id    => l_assignment_id);
2521       END IF;
2522 
2523 EXCEPTION
2524   WHEN OTHERS THEN
2525     WF_CORE.CONTEXT
2526         ('PA_ASGMT_WFSTD',
2527          'Generate_apprvl_nf_recipients',
2528           itemtype,
2529           itemkey,
2530           to_char(actid),
2531           funcmode);
2532      RAISE;
2533 END Generate_apprvl_nf_recipients ;
2534 
2535 PROCEDURE Get_Approval_NF_Recipient
2536                                 (itemtype IN VARCHAR2
2537                                , itemkey IN VARCHAR2
2538                                , actid IN NUMBER
2539                                , funcmode IN VARCHAR2
2540                                , resultout OUT NOCOPY VARCHAR2 )  IS --File.Sql.39 bug 4440895
2541 
2542 l_number_of_apprvl_nf_rects  NUMBER := 0;
2543 l_approval_nf_loop_counter  NUMBER := 0;
2544 l_ntfy_rect_item_attr_name VARCHAR2(30);
2545 l_ntfy_apprvl_recipient_name pa_wf_ntf_performers.user_name%TYPE; ---VARCHAR2(240); Changed for bug 3267790
2546 l_ntfy_apprvl_rect_type VARCHAR2(30);
2547 l_assignment_id NUMBER := 0;
2548 
2549 BEGIN
2550     /*
2551      Get item attr approval nf rect loop counter and number of rects
2552      Approvals nf rect loop counter := approvals nf rect loop counter + 1;
2553      If loop counter > number of rcts , resultout = 'F'
2554           and return
2555      Read the wf performers table and get the
2556      recipient record based on the loop counter.
2557      Set performer to the retrieved record
2558      If performer = resource , remove all comments
2559      else restore the comments
2560      Set loop counter
2561      Resultout = 'T'
2562     */
2563         -- Return if WF Not Running
2564     IF (funcmode <> wf_engine.eng_run) THEN
2565             resultout := wf_engine.eng_null;
2566             RETURN;
2567     END IF;
2568            l_number_of_apprvl_nf_rects := wf_engine.GetItemAttrNumber
2569                    (  itemtype => itemtype
2570                                 , itemkey =>  itemkey
2571                                 , aname => 'NUMBER_OF_APPRVL_NF_RECIPIENTS'
2572                                );
2573            l_approval_nf_loop_counter := wf_engine.getItemAttrNumber
2574                    (  itemtype => itemtype
2575                                 , itemkey =>  itemkey
2576                                 , aname => 'APPROVAL_NF_LOOP_COUNTER'
2577                                );
2578            l_assignment_id := wf_engine.getItemAttrNumber
2579                    (  itemtype => itemtype
2580                                 , itemkey =>  itemkey
2581                                 , aname => 'ASSIGNMENT_ID'
2582                                );
2583      l_approval_nf_loop_counter := l_approval_nf_loop_counter + 1;
2584      IF l_approval_nf_loop_counter > l_number_of_apprvl_nf_rects THEN
2585              resultout := wf_engine.eng_completed||':'||'F';
2586          RETURN;
2587          END IF;
2588         get_wf_performer (p_wf_type_code => 'APPROVAL_FYI'
2589               ,p_item_type   => itemtype
2590               ,p_item_key    => itemkey
2591               ,p_routing_order => l_approval_nf_loop_counter
2592                   ,p_object_id1  =>  l_assignment_id
2593               ,x_performer_name =>l_ntfy_apprvl_recipient_name
2594               ,x_performer_type =>l_ntfy_apprvl_rect_type );
2595            wf_engine.SetItemAttrText
2596                    ( itemtype => itemtype
2597                                , itemkey =>  itemkey
2598                                , aname => 'NTFY_APPRVL_RECIPIENT_NAME'
2599                                , avalue => l_ntfy_apprvl_recipient_name
2600                                );
2601            wf_engine.SetItemAttrNumber
2602                    ( itemtype => itemtype
2603                                , itemkey =>  itemkey
2604                                , aname => 'APPROVAL_NF_LOOP_COUNTER'
2605                                , avalue => l_approval_nf_loop_counter
2606                                );
2607         -- Do not show comments if the recipient is the resource
2608         -- otherwise show the comments. To achieve this, set the
2609         -- displayed comments field appropriately
2610         -- This is done in the set_comments procedure
2611            Set_Comment_Attributes (p_item_type => itemtype,
2612                        p_item_key  => itemkey ,
2613                        p_rect_type =>
2614                        l_ntfy_apprvl_rect_type );
2615 
2616             resultout := wf_engine.eng_completed||':'||'S';
2617 EXCEPTION
2618 WHEN OTHERS THEN
2619     WF_CORE.CONTEXT
2620         ('PA_ASGMT_WFSTD',
2621          'Get_Approval_NF_Recipient',
2622           itemtype,
2623           itemkey,
2624           to_char(actid),
2625           funcmode);
2626      RAISE;
2627 END Get_Approval_NF_Recipient ;
2628 
2629   PROCEDURE Generate_reject_nf_recipients
2630                                 (itemtype IN VARCHAR2
2631                                , itemkey IN VARCHAR2
2632                                , actid IN NUMBER
2633                                , funcmode IN VARCHAR2
2634                                , resultout OUT NOCOPY VARCHAR2 )  IS --File.Sql.39 bug 4440895
2635 l_reject_nf_rects_tbl  PA_CLIENT_EXTN_ASGMT_WF.Users_List_Tbltyp ;
2636 l_out_reject_nf_rects_tbl  PA_CLIENT_EXTN_ASGMT_WF.Users_List_Tbltyp ;
2637 l_number_of_recipients  NUMBER := 0;
2638 l_reject_nf_rects_rec  PA_CLIENT_EXTN_ASGMT_WF.Users_List_Rectyp ;
2639 l_assignment_id   pa_project_assignments.assignment_id%TYPE;
2640 l_project_id      pa_projects_all.project_id%TYPE;
2641 l_reject_nf_rect_username   wf_users.name%type; ---VARCHAR2(100); /* Modified length from 30 to 100 for bug 3148857 */ -- Changed for bug 3267790
2642 l_rect_person_id  NUMBER := 0;
2643 l_recipient_type   VARCHAR2(30);
2644 l_item_attr_name  VARCHAR2(30);
2645 l_number_of_reject_nf_rects  NUMBER := 0;
2646 l_reject_nf_loop_counter  NUMBER := 0;
2647 l_ntfy_rect_item_attr_name VARCHAR2(30);
2648 l_ntfy_reject_recipient_name wf_users.name%type; ----- VARCHAR2(240);Changed for bug 3267790
2649 l_ntfy_reject_rect_person_id NUMBER := 0;
2650 l_ntfy_reject_rect_type VARCHAR2(30);
2651 l_apprvl_item_type  VARCHAR2(30);
2652 l_apprvl_item_key  VARCHAR2(30);
2653 
2654 BEGIN
2655         -- Return if WF Not Running
2656     IF (funcmode <> wf_engine.eng_run) THEN
2657             resultout := wf_engine.eng_null;
2658             RETURN;
2659     END IF;
2660         l_assignment_id := wf_engine.GetItemAttrNumber
2661                    (itemtype => itemtype,
2662                     itemkey  => itemkey,
2663                     aname    => 'ASSIGNMENT_ID');
2664         l_project_id     := wf_engine.GetItemAttrNumber
2665                    (itemtype => itemtype,
2666                     itemkey  => itemkey,
2667                     aname    => 'PROJECT_ID' );
2668 --  Now populate the PL/SQL table with the 4 recipients
2669 --  which are done by the product by default
2670         l_number_of_reject_nf_rects := wf_engine.GetItemAttrNumber
2671                    (  itemtype => itemtype
2672                                 , itemkey =>  itemkey
2673                                 , aname => 'NUMBER_OF_REJECT_NF_RECIPIENTS'
2674                                );
2675 
2676     l_apprvl_item_type  := wf_engine.getItemAttrText
2677                    ( itemtype => itemtype
2678                                , itemkey =>  itemkey
2679                                , aname => 'APPRVL_ITEM_TYPE' );
2680 
2681     l_apprvl_item_key   := wf_engine.getItemAttrText
2682                    ( itemtype => itemtype
2683                                , itemkey =>  itemkey
2684                                , aname => 'APPRVL_ITEM_KEY');
2685 
2686     FOR i IN 1..l_number_of_reject_nf_rects
2687      LOOP
2688        l_ntfy_rect_item_attr_name :=
2689         'REJECT_NF_REC'||i||'_USER_NAME';
2690            l_ntfy_reject_recipient_name := wf_engine.getItemAttrText
2691                    ( itemtype => itemtype
2692                                , itemkey =>  itemkey
2693                                , aname => l_ntfy_rect_item_attr_name
2694                                );
2695        l_ntfy_rect_item_attr_name :=
2696         'REJECT_NF_REC'||i||'_USER_TYPE';
2697            l_ntfy_reject_rect_type := wf_engine.getItemAttrText
2698                    ( itemtype => itemtype
2699                                , itemkey =>  itemkey
2700                                , aname => l_ntfy_rect_item_attr_name
2701                                );
2702        l_ntfy_rect_item_attr_name :=
2703         'REJECT_NF_REC'||i||'_PERSON_ID';
2704            l_ntfy_reject_rect_person_id := wf_engine.getItemAttrNumber
2705                    ( itemtype => itemtype
2706                                , itemkey =>  itemkey
2707                                , aname => l_ntfy_rect_item_attr_name
2708                                );
2709        IF l_ntfy_reject_recipient_name IS NOT NULL THEN
2710               l_reject_nf_rects_rec.User_Name := l_ntfy_reject_recipient_name;
2711               l_reject_nf_rects_rec.Person_id :=
2712              l_ntfy_reject_rect_person_id;
2713               l_reject_nf_rects_rec.Type      :=
2714              l_ntfy_reject_rect_type;
2715               l_reject_nf_rects_rec.Routing_Order :=  i;
2716               l_reject_nf_rects_tbl(i)        := l_reject_nf_rects_rec;
2717            END IF;
2718      END LOOP;
2719     -- Pass the pl/sql table to the client extension so
2720     -- users can customize the approvers
2721 
2722      PA_CLIENT_EXTN_ASGMT_WF.Generate_NF_Recipients
2723     (p_assignment_id                => l_assignment_id
2724     ,p_project_id               => l_project_id
2725     ,p_notification_type            => 'REJECTION_FYI'
2726     ,p_in_list_of_recipients        => l_reject_nf_rects_tbl
2727     ,x_out_list_of_recipients       => l_out_reject_nf_rects_tbl
2728     ,x_number_of_recipients     => l_number_of_recipients );
2729 
2730     populate_wf_performers
2731         ( p_wf_type_code => 'REJECTION_FYI'
2732          ,p_item_type    => itemtype
2733          ,p_item_key     => itemkey
2734          ,p_object_id1  => l_assignment_id
2735          ,p_object_id2  => l_project_id
2736          ,p_in_performers_tbl => l_out_reject_nf_rects_tbl
2737          ,p_current_approver_flag  => 'N'
2738      ,x_number_of_performers => l_number_of_recipients );
2739 
2740     -- Now set the number of reject nf recipients based
2741     -- on how many records were inserted
2742 
2743          wf_engine.SetItemAttrNumber
2744             (itemtype => itemtype
2745                         ,itemkey =>  itemkey
2746                         ,aname => 'NUMBER_OF_REJECT_NF_RECIPIENTS'
2747                         ,avalue => l_number_of_recipients
2748             );
2749     -- Now populate the Comments fields, which would have
2750     -- been stored in the pa_wf_ntf_performers table
2751        IF (l_apprvl_item_type IS NOT NULL AND l_apprvl_item_key
2752            IS NOT NULL ) THEN
2753          Set_approver_comments  (p_apprvl_item_type => l_apprvl_item_type
2754                 ,p_apprvl_item_key  => l_apprvl_item_key
2755                 ,p_item_type        => itemtype
2756                 ,p_item_key         => itemkey
2757                 ,p_assignment_id    => l_assignment_id);
2758       END IF;
2759 EXCEPTION
2760   WHEN OTHERS THEN
2761     WF_CORE.CONTEXT
2762         ('PA_ASGMT_WFSTD',
2763          'Generate_reject_nf_recipients',
2764           itemtype,
2765           itemkey,
2766           to_char(actid),
2767           funcmode);
2768      RAISE;
2769 END Generate_reject_nf_recipients ;
2770 
2771 PROCEDURE Get_Reject_NF_Recipient
2772                     (itemtype IN VARCHAR2
2773                                , itemkey IN VARCHAR2
2774                                , actid IN NUMBER
2775                                , funcmode IN VARCHAR2
2776                                , resultout OUT NOCOPY VARCHAR2 ) IS --File.Sql.39 bug 4440895
2777 
2778 l_number_of_reject_nf_rects  NUMBER := 0;
2779 l_rejection_nf_loop_counter  NUMBER := 0;
2780 l_ntfy_rect_item_attr_name VARCHAR2(30);
2781 l_ntfy_reject_recipient_name pa_wf_ntf_performers.user_name%type; ----- VARCHAR2(240);Changed for bug 3267790
2782 l_ntfy_reject_rect_type VARCHAR2(30);
2783 l_assignment_id NUMBER := 0;
2784 
2785 BEGIN
2786     /*
2787      Get item attr reject nf rect loop counter and number of rects
2788      reject nf rect loop counter := reject nf rect loop counter + 1;
2789      If loop counter > number of rcts , resultout = 'F'
2790           and return
2791      Read the wf performers table and get the
2792      recipient record based on the loop counter.
2793      Set performer to the retrieved record
2794      If performer = resource , remove all comments
2795      else restore the comments
2796      Set loop counter
2797      Resultout = 'T'
2798     */
2799            -- Return if WF Not Running
2800        IF (funcmode <> wf_engine.eng_run) THEN
2801                resultout := wf_engine.eng_null;
2802                RETURN;
2803        END IF;
2804            l_number_of_reject_nf_rects := wf_engine.GetItemAttrNumber
2805                    (  itemtype => itemtype
2806                                 , itemkey =>  itemkey
2807                                 , aname => 'NUMBER_OF_REJECT_NF_RECIPIENTS'
2808                                );
2809            l_rejection_nf_loop_counter := wf_engine.getItemAttrNumber
2810                    (  itemtype => itemtype
2811                                 , itemkey =>  itemkey
2812                                 , aname => 'REJECTION_NF_LOOP_COUNTER'
2813                                );
2814 
2815            l_assignment_id := wf_engine.getItemAttrNumber
2816                    (  itemtype => itemtype
2817                                 , itemkey =>  itemkey
2818                                 , aname => 'ASSIGNMENT_ID'
2819                                );
2820      l_rejection_nf_loop_counter := l_rejection_nf_loop_counter + 1;
2821      IF l_rejection_nf_loop_counter > l_number_of_reject_nf_rects THEN
2822              resultout := wf_engine.eng_completed||':'||'F';
2823          RETURN;
2824          END IF;
2825         get_wf_performer (p_wf_type_code => 'REJECTION_FYI'
2826               ,p_item_type   => itemtype
2827               ,p_item_key    => itemkey
2828               ,p_routing_order => l_rejection_nf_loop_counter
2829                   ,p_object_id1  =>  l_assignment_id
2830               ,x_performer_name =>l_ntfy_reject_recipient_name
2831               ,x_performer_type =>l_ntfy_reject_rect_type );
2832            wf_engine.SetItemAttrText
2833                    ( itemtype => itemtype
2834                                , itemkey =>  itemkey
2835                                , aname => 'NTFY_REJECT_RECIPIENT_NAME'
2836                                , avalue => l_ntfy_reject_recipient_name
2837                                );
2838            wf_engine.SetItemAttrNumber
2839                    ( itemtype => itemtype
2840                                , itemkey =>  itemkey
2841                                , aname => 'REJECTION_NF_LOOP_COUNTER'
2842                                , avalue => l_rejection_nf_loop_counter
2843                                );
2844         -- Do not show comments if the recipient is the resource
2845         -- otherwise show the comments. To achieve this, set the
2846         -- displayed comments field appropriately
2847         -- This is done in the set_comments procedure
2848            Set_Comment_Attributes (p_item_type => itemtype,
2849                        p_item_key  => itemkey ,
2850                        p_rect_type =>
2851                        l_ntfy_reject_rect_type );
2852             resultout := wf_engine.eng_completed||':'||'S';
2853 EXCEPTION
2854   WHEN OTHERS THEN
2855     WF_CORE.CONTEXT
2856         ('PA_ASGMT_WFSTD',
2857          'Get_Reject_NF_Recipient',
2858           itemtype,
2859           itemkey,
2860           to_char(actid),
2861           funcmode);
2862      RAISE;
2863 END Get_Reject_NF_Recipient ;
2864 
2865 
2866 
2867   PROCEDURE Generate_cancel_nf_recipients
2868                                 (itemtype IN VARCHAR2
2869                                , itemkey IN VARCHAR2
2870                                , actid IN NUMBER
2871                                , funcmode IN VARCHAR2
2872                                , resultout OUT NOCOPY VARCHAR2 )  IS --File.Sql.39 bug 4440895
2873 l_cancel_nf_rects_tbl  PA_CLIENT_EXTN_ASGMT_WF.Users_List_Tbltyp ;
2874 l_out_cancel_nf_rects_tbl  PA_CLIENT_EXTN_ASGMT_WF.Users_List_Tbltyp ;
2875 l_number_of_recipients  NUMBER := 0;
2876 l_cancel_nf_rects_rec  PA_CLIENT_EXTN_ASGMT_WF.Users_List_Rectyp ;
2877 l_assignment_id   pa_project_assignments.assignment_id%TYPE;
2878 l_project_id      pa_projects_all.project_id%TYPE;
2879 l_cancel_nf_rect_username  wf_users.name%type; ----- VARCHAR2(30);Changed for bug 3267790
2880 --VARCHAR2(100); /* Modified length from 30 to 100 for bug 3148857 */
2881 l_rect_person_id  NUMBER := 0;
2882 l_recipient_type   VARCHAR2(30);
2883 l_item_attr_name  VARCHAR2(30);
2884 l_number_of_cancel_nf_rects  NUMBER := 0;
2885 l_cancel_nf_loop_counter  NUMBER := 0;
2886 l_ntfy_rect_item_attr_name VARCHAR2(30);
2887 l_ntfy_cancel_recipient_name wf_users.name%type; --- VARCHAR2(240);Changed for bug 3267790
2888 l_ntfy_cancel_rect_person_id NUMBER := 0;
2889 l_ntfy_cancel_rect_type VARCHAR2(30);
2890 l_apprvl_item_type  VARCHAR2(30);
2891 l_apprvl_item_key  VARCHAR2(30);
2892 
2893 l_counter NUMBER := 0; -- local variable for bug 7511389
2894 
2895 BEGIN
2896         -- Return if WF Not Running
2897     IF (funcmode <> wf_engine.eng_run) THEN
2898             resultout := wf_engine.eng_null;
2899             RETURN;
2900     END IF;
2901         l_assignment_id := wf_engine.GetItemAttrNumber
2902                    (itemtype => itemtype,
2903                     itemkey  => itemkey,
2904                     aname    => 'ASSIGNMENT_ID');
2905         l_project_id     := wf_engine.GetItemAttrNumber
2906                    (itemtype => itemtype,
2907                     itemkey  => itemkey,
2908                     aname    => 'PROJECT_ID' );
2909 --  Now populate the PL/SQL table with the 4 recipients
2910 --  which are done by the product by default
2911         l_number_of_cancel_nf_rects := wf_engine.GetItemAttrNumber
2912                    (  itemtype => itemtype
2913                                 , itemkey =>  itemkey
2914                                 , aname => 'NUMBER_OF_CANCEL_NF_RECIPIENTS'
2915                                );
2916 
2917     l_apprvl_item_type  := wf_engine.getItemAttrText
2918                    ( itemtype => itemtype
2919                                , itemkey =>  itemkey
2920                                , aname => 'APPRVL_ITEM_TYPE' );
2921 
2922     l_apprvl_item_key   := wf_engine.getItemAttrText
2923                    ( itemtype => itemtype
2924                                , itemkey =>  itemkey
2925                                , aname => 'APPRVL_ITEM_KEY');
2926 
2927     FOR i IN 1..l_number_of_cancel_nf_rects
2928      LOOP
2929        l_ntfy_rect_item_attr_name :=
2930         'CANCEL_NF_REC'||i||'_USER_NAME';
2931            l_ntfy_cancel_recipient_name := wf_engine.getItemAttrText
2932                    ( itemtype => itemtype
2933                                , itemkey =>  itemkey
2934                                , aname => l_ntfy_rect_item_attr_name
2935                                );
2936        l_ntfy_rect_item_attr_name :=
2937         'CANCEL_NF_REC'||i||'_USER_TYPE';
2938            l_ntfy_cancel_rect_type := wf_engine.getItemAttrText
2939                    ( itemtype => itemtype
2940                                , itemkey =>  itemkey
2941                                , aname => l_ntfy_rect_item_attr_name
2942                                );
2943        l_ntfy_rect_item_attr_name :=
2944         'CANCEL_NF_REC'||i||'_PERSON_ID';
2945            l_ntfy_cancel_rect_person_id := wf_engine.getItemAttrNumber
2946                    ( itemtype => itemtype
2947                                , itemkey =>  itemkey
2948                                , aname => l_ntfy_rect_item_attr_name
2949                                );
2950        IF l_ntfy_cancel_recipient_name IS NOT NULL THEN
2951 
2952        /*Bug 7511389 : increasing the counter */
2953        l_counter := l_counter + 1;
2954 
2955               l_cancel_nf_rects_rec.User_Name := l_ntfy_cancel_recipient_name;
2956               l_cancel_nf_rects_rec.Person_id :=
2957              l_ntfy_cancel_rect_person_id;
2958               l_cancel_nf_rects_rec.Type      :=
2959              l_ntfy_cancel_rect_type;
2960 
2961              /*For bug 7511389 : removing 'i' and using 'l_counter' instead */
2962 --              l_cancel_nf_rects_rec.Routing_Order :=  i;
2963 --              l_cancel_nf_rects_tbl(i)        := l_cancel_nf_rects_rec;
2964                 l_cancel_nf_rects_rec.Routing_Order :=  l_counter;
2965                 l_cancel_nf_rects_tbl(l_counter)        := l_cancel_nf_rects_rec;
2966            END IF;
2967      END LOOP;
2968     -- Pass the pl/sql table to the client extension so
2969     -- users can customize the approvers
2970 
2971      PA_CLIENT_EXTN_ASGMT_WF.Generate_NF_Recipients
2972     (p_assignment_id                => l_assignment_id
2973     ,p_project_id               => l_project_id
2974     ,p_notification_type            => 'CANCELLATION_FYI'
2975     ,p_in_list_of_recipients        => l_cancel_nf_rects_tbl
2976     ,x_out_list_of_recipients       => l_out_cancel_nf_rects_tbl
2977     ,x_number_of_recipients     => l_number_of_recipients );
2978 
2979     populate_wf_performers
2980         ( p_wf_type_code => 'CANCELLATION_FYI'
2981          ,p_item_type    => itemtype
2982          ,p_item_key     => itemkey
2983          ,p_object_id1  => l_assignment_id
2984          ,p_object_id2  => l_project_id
2985          ,p_in_performers_tbl => l_out_cancel_nf_rects_tbl
2986          ,p_current_approver_flag  => 'N'
2987      ,x_number_of_performers => l_number_of_recipients );
2988 
2989     -- Now set the number of cancel nf recipients based
2990     -- on how many records were inserted
2991 
2992          wf_engine.SetItemAttrNumber
2993             (itemtype => itemtype
2994                         ,itemkey =>  itemkey
2995                         ,aname => 'NUMBER_OF_CANCEL_NF_RECIPIENTS'
2996                         ,avalue => l_number_of_recipients
2997             );
2998     -- Now populate the Comments fields, which would have
2999     -- been stored in the pa_wf_ntf_performers table
3000        IF (l_apprvl_item_type IS NOT NULL AND l_apprvl_item_key
3001            IS NOT NULL ) THEN
3002          Set_approver_comments  (p_apprvl_item_type => l_apprvl_item_type
3003                 ,p_apprvl_item_key  => l_apprvl_item_key
3004                 ,p_item_type        => itemtype
3005                 ,p_item_key         => itemkey
3006                 ,p_assignment_id    => l_assignment_id);
3007       END IF;
3008 EXCEPTION
3009   WHEN OTHERS THEN
3010     WF_CORE.CONTEXT
3011         ('PA_ASGMT_WFSTD',
3012          'Generate_cancel_nf_recipients',
3013           itemtype,
3014           itemkey,
3015           to_char(actid),
3016           funcmode);
3017      RAISE;
3018 END Generate_cancel_nf_recipients ;
3019 
3020 
3021 PROCEDURE Get_Cancel_NF_Recipient
3022                     (itemtype IN VARCHAR2
3023                                , itemkey IN VARCHAR2
3024                                , actid IN NUMBER
3025                                , funcmode IN VARCHAR2
3026                                , resultout OUT NOCOPY VARCHAR2 ) IS --File.Sql.39 bug 4440895
3027 
3028 l_number_of_cancel_nf_rects  NUMBER := 0;
3029 l_cancellation_nf_loop_counter  NUMBER := 0;
3030 l_ntfy_rect_item_attr_name VARCHAR2(30);
3031 l_ntfy_cancel_recipient_name pa_wf_ntf_performers.user_name%TYPE; ----- VARCHAR2(240);Changed for bug 3267790
3032 l_ntfy_cancel_rect_type VARCHAR2(30);
3033 l_assignment_id NUMBER := 0;
3034 
3035 BEGIN
3036     /*
3037      Get item attr cancel nf rect loop counter and number of rects
3038      cancel nf rect loop counter := cancel nf rect loop counter + 1;
3039      If loop counter > number of rcts , resultout = 'F'
3040           and return
3041      Read the wf performers table and get the
3042      recipient record based on the loop counter.
3043      Set performer to the retrieved record
3044      If performer = resource , remove all comments
3045      else restore the comments
3046      Set loop counter
3047      Resultout = 'T'
3048     */
3049            -- Return if WF Not Running
3050        IF (funcmode <> wf_engine.eng_run) THEN
3051                resultout := wf_engine.eng_null;
3052                RETURN;
3053        END IF;
3054            l_number_of_cancel_nf_rects := wf_engine.GetItemAttrNumber
3055                    (  itemtype => itemtype
3056                                 , itemkey =>  itemkey
3057                                 , aname => 'NUMBER_OF_CANCEL_NF_RECIPIENTS'
3058                                );
3059            l_cancellation_nf_loop_counter := wf_engine.getItemAttrNumber
3060                    (  itemtype => itemtype
3061                                 , itemkey =>  itemkey
3062                                 , aname => 'CANCELLATION_NF_LOOP_COUNTER'
3063                                );
3064 
3065            l_assignment_id := wf_engine.getItemAttrNumber
3066                    (  itemtype => itemtype
3067                                 , itemkey =>  itemkey
3068                                 , aname => 'ASSIGNMENT_ID'
3069                                );
3070      l_cancellation_nf_loop_counter := l_cancellation_nf_loop_counter + 1;
3071      IF l_cancellation_nf_loop_counter > l_number_of_cancel_nf_rects THEN
3072              resultout := wf_engine.eng_completed||':'||'F';
3073          RETURN;
3074          END IF;
3075         get_wf_performer (p_wf_type_code => 'CANCELLATION_FYI'
3076               ,p_item_type   => itemtype
3077               ,p_item_key    => itemkey
3078               ,p_routing_order => l_cancellation_nf_loop_counter
3079                   ,p_object_id1  =>  l_assignment_id
3080               ,x_performer_name =>l_ntfy_cancel_recipient_name
3081               ,x_performer_type =>l_ntfy_cancel_rect_type );
3082            wf_engine.SetItemAttrText
3083                    ( itemtype => itemtype
3084                                , itemkey =>  itemkey
3085                                , aname => 'NTFY_CANCEL_RECIPIENT_NAME'
3086                                , avalue => l_ntfy_cancel_recipient_name
3087                                );
3088            wf_engine.SetItemAttrNumber
3089                    ( itemtype => itemtype
3090                                , itemkey =>  itemkey
3091                                , aname => 'CANCELLATION_NF_LOOP_COUNTER'
3092                                , avalue => l_cancellation_nf_loop_counter
3093                                );
3094         -- Do not show comments if the recipient is the resource
3095         -- otherwise show the comments. To achieve this, set the
3096         -- displayed comments field appropriately
3097         -- This is done in the set_comments procedure
3098            Set_Comment_Attributes (p_item_type => itemtype,
3099                        p_item_key  => itemkey ,
3100                        p_rect_type =>
3101                        l_ntfy_cancel_rect_type );
3102             resultout := wf_engine.eng_completed||':'||'S';
3103 EXCEPTION
3104   WHEN OTHERS THEN
3105     WF_CORE.CONTEXT
3106         ('PA_ASGMT_WFSTD',
3107          'Get_Cancel_NF_Recipient',
3108           itemtype,
3109           itemkey,
3110           to_char(actid),
3111           funcmode);
3112      RAISE;
3113 END Get_Cancel_NF_Recipient ;
3114 
3115 
3116 
3117 PROCEDURE Set_Forwarded_From  (itemtype IN VARCHAR2
3118                                , itemkey IN VARCHAR2
3119                                , actid IN NUMBER
3120                                , funcmode IN VARCHAR2
3121                                , resultout OUT NOCOPY VARCHAR2 ) IS --File.Sql.39 bug 4440895
3122 l_forwarded_from  wf_users.name%type; ----- VARCHAR2(240); Changed for bug 3267790
3123 BEGIN
3124 
3125         -- Return if WF Not Running
3126     IF (funcmode <> wf_engine.eng_run) THEN
3127             resultout := wf_engine.eng_null;
3128             RETURN;
3129     END IF;
3130     -- The approval notification would have been forwarded
3131     -- from either the initial submittor or the last approver
3132     -- Prev Approver uname is set only in get approver node
3133     -- Hence, if that value is not set, get the value
3134     -- from workflow started by uname attribute, which
3135     -- is always set at the time of starting the workflow
3136      l_forwarded_from := wf_engine.GetItemAttrText
3137                    ( itemtype => itemtype
3138                                , itemkey =>  itemkey
3139                                , aname => 'PREV_APPROVER_UNAME'
3140                                );
3141      IF l_forwarded_from IS NULL THEN
3142         l_forwarded_from := wf_engine.GetItemAttrText
3143                    ( itemtype => itemtype
3144                                , itemkey =>  itemkey
3145                                , aname => 'WORKFLOW_STARTED_BY_UNAME'
3146                                );
3147      END IF;
3148       -- Now set the forwarded from field
3149          wf_engine.SetItemAttrText
3150                    ( itemtype => itemtype
3151                                , itemkey =>  itemkey
3152                                , aname => 'FORWARDED_FROM'
3153                                , avalue => l_forwarded_from
3154                                );
3155 EXCEPTION
3156   WHEN OTHERS THEN
3157     WF_CORE.CONTEXT
3158         ('PA_ASGMT_WFSTD',
3159          'Set_Forwarded_From',
3160           itemtype,
3161           itemkey,
3162           to_char(actid),
3163           funcmode);
3164      RAISE;
3165 END Set_Forwarded_From;
3166 
3167 PROCEDURE Set_Approval_Reqd_Msg (itemtype IN VARCHAR2
3168                                , itemkey IN VARCHAR2
3169                                , actid IN NUMBER
3170                                , funcmode IN VARCHAR2
3171                                , resultout OUT NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
3172 IS
3173 l_assignment_type   pa_project_assignments.assignment_type%TYPE;
3174 l_reapproval_flag   VARCHAR2(1);
3175 BEGIN
3176     IF (funcmode <> wf_engine.eng_run) THEN
3177             resultout := wf_engine.eng_null;
3178             RETURN;
3179     END IF;
3180         -- Check whether the assignment is work or admin assignment
3181     -- If work assignment check whether this is a reapproval
3182     -- Accordingly set the attributes for MSG_SUBJECT and MSG_DESCRIPTION
3183     -- All this is done in the Set_NF_Subject_and_Desc procedure
3184 
3185     l_assignment_type := wf_engine.GetItemAttrText
3186                    (itemtype => itemtype,
3187                     itemkey  => itemkey,
3188                     aname    => 'ASSIGNMENT_TYPE');
3189 
3190     l_reapproval_flag := wf_engine.GetItemAttrText
3191                  (itemtype => itemtype,
3192                               itemkey  => itemkey,
3193                               aname    => 'REAPPROVAL_FLAG');
3194 
3195     -- Set the appropriate notification subject and description
3196     -- item attributes
3197 
3198         Set_NF_Subject_and_Desc  (p_item_type   => itemtype,
3199                   p_item_key    => itemkey,
3200                   p_assignment_type => l_assignment_type,
3201                   p_reapproval_flag => l_reapproval_flag,
3202                   p_msg_type        => 'ASSIGNMENT_APPROVAL');
3203 
3204 EXCEPTION
3205   WHEN OTHERS THEN
3206     WF_CORE.CONTEXT
3207         ('PA_ASGMT_WFSTD',
3208          'Set_Approval_Reqd_Msg',
3209           itemtype,
3210           itemkey,
3211           to_char(actid),
3212           funcmode);
3213      RAISE;
3214 END Set_Approval_Reqd_Msg ;
3215 
3216 PROCEDURE Set_Approved_Msg   (itemtype IN VARCHAR2
3217                                , itemkey IN VARCHAR2
3218                                , actid IN NUMBER
3219                                , funcmode IN VARCHAR2
3220                                , resultout OUT NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
3221 IS
3222 BEGIN
3223     IF (funcmode <> wf_engine.eng_run) THEN
3224             resultout := wf_engine.eng_null;
3225             RETURN;
3226     END IF;
3227 
3228     -- Set the appropriate notification subject and description
3229     -- item attributes
3230     -- assignment type and re-approval flags are not needed for
3231     -- the approved FYI messages
3232 
3233         Set_NF_Subject_and_Desc  (p_item_type   => itemtype,
3234                   p_item_key    => itemkey,
3235                   p_assignment_type => NULL,
3236                   p_reapproval_flag => NULL,
3237                   p_msg_type        => 'APPROVAL_FYI');
3238 
3239 EXCEPTION
3240   WHEN OTHERS THEN
3241     WF_CORE.CONTEXT
3242         ('PA_ASGMT_WFSTD',
3243          'Set_Approved_Msg',
3244           itemtype,
3245           itemkey,
3246           to_char(actid),
3247           funcmode);
3248      RAISE;
3249 END Set_Approved_Msg;
3250 
3251 PROCEDURE Set_Rejected_Msg     (itemtype IN VARCHAR2
3252                                ,itemkey IN VARCHAR2
3253                                ,actid IN NUMBER
3254                                ,funcmode IN VARCHAR2
3255                                ,resultout OUT NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
3256 
3257 IS
3258 BEGIN
3259     IF (funcmode <> wf_engine.eng_run) THEN
3260             resultout := wf_engine.eng_null;
3261             RETURN;
3262     END IF;
3263 
3264     -- Set the appropriate notification subject and description
3265     -- item attributes
3266     -- assignment type and re-approval flags are not needed for
3267     -- the rejected FYI messages
3268 
3269         Set_NF_Subject_and_Desc  (p_item_type   => itemtype,
3270                   p_item_key    => itemkey,
3271                   p_assignment_type => NULL,
3272                   p_reapproval_flag => NULL,
3273                   p_msg_type        => 'REJECTION_FYI');
3274 EXCEPTION
3275   WHEN OTHERS THEN
3276     WF_CORE.CONTEXT
3277         ('PA_ASGMT_WFSTD',
3278          'Set_Rejected_Msg',
3279           itemtype,
3280           itemkey,
3281           to_char(actid),
3282           funcmode);
3283      RAISE;
3284 END Set_Rejected_Msg;
3285 
3286 
3287 PROCEDURE Set_Canceled_Msg     (itemtype IN VARCHAR2
3288                                ,itemkey IN VARCHAR2
3289                                ,actid IN NUMBER
3290                                ,funcmode IN VARCHAR2
3291                                ,resultout OUT NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
3292 
3293 IS
3294 BEGIN
3295     IF (funcmode <> wf_engine.eng_run) THEN
3296             resultout := wf_engine.eng_null;
3297             RETURN;
3298     END IF;
3299 
3300     -- Set the appropriate notification subject and description
3301     -- item attributes
3302     -- assignment type and re-approval flags are not needed for
3303     -- the rejected FYI messages
3304 
3305         Set_NF_Subject_and_Desc  (p_item_type   => itemtype,
3306                   p_item_key    => itemkey,
3307                   p_assignment_type => NULL,
3308                   p_reapproval_flag => NULL,
3309                   p_msg_type        => 'CANCELLATION_FYI');
3310 EXCEPTION
3311   WHEN OTHERS THEN
3312     WF_CORE.CONTEXT
3313         ('PA_ASGMT_WFSTD',
3314          'Set_Canceled_Msg',
3315           itemtype,
3316           itemkey,
3317           to_char(actid),
3318           funcmode);
3319      RAISE;
3320 END Set_Canceled_Msg;
3321 
3322 
3323 PROCEDURE Validate_Forwarded_User
3324                     ( itemtype IN VARCHAR2
3325                                 , itemkey IN VARCHAR2
3326                                 , actid IN NUMBER
3327                                 , funcmode IN VARCHAR2
3328                                 , resultout OUT NOCOPY VARCHAR2 ) IS --File.Sql.39 bug 4440895
3329 l_msg_text   VARCHAR2(240);
3330 invalid_user_exception EXCEPTION;
3331 BEGIN
3332 /*
3333     IF funcmode = 'FORWARD' THEN
3334       Notification assignee validations go here
3335       get the assigned user which is available in wf_engine.context_text
3336       validate this user
3337       If not valid user fnd_message.set_name ('PA','PA_NO_RESOURCE_AUTHORITY');
3338       l_msg_text := fnd_message.get;
3339       RAISE invalid_user_exception;
3340           END IF;
3341 */
3342     NULL;
3343 EXCEPTION
3344   WHEN invalid_user_exception THEN
3345     WF_CORE.CONTEXT
3346         ('PA_ASGMT_WFSTD',
3347          'Validate_Forwarded_User',
3348           l_msg_text,
3349           NULL,
3350           NULL,
3351           NULL);
3352      RAISE;
3353 
3354   WHEN OTHERS THEN
3355     WF_CORE.CONTEXT
3356         ('PA_ASGMT_WFSTD',
3357          'Validate_Forwarded_User',
3358           itemtype,
3359           itemkey,
3360           to_char(actid),
3361           funcmode);
3362      RAISE;
3363 
3364 END Validate_Forwarded_User ;
3365 
3366 PROCEDURE Set_Approval_Pending  (itemtype IN VARCHAR2
3367                                , itemkey IN VARCHAR2
3368                                , actid IN NUMBER
3369                                , funcmode IN VARCHAR2
3370                                , resultout OUT NOCOPY VARCHAR2 ) IS --File.Sql.39 bug 4440895
3371 
3372 l_assignment_id pa_project_assignments.assignment_id%TYPE;
3373 BEGIN
3374         l_assignment_id := wf_engine.GetItemAttrNumber
3375                    (itemtype => itemtype,
3376                     itemkey  => itemkey,
3377                     aname    => 'ASSIGNMENT_ID');
3378     Maintain_wf_pending_flag
3379             (p_assignment_id => l_assignment_id,
3380              p_mode      => 'PENDING_APPROVAL'
3381             ) ;
3382 
3383 EXCEPTION
3384   WHEN OTHERS THEN
3385     WF_CORE.CONTEXT
3386         ('PA_ASGMT_WFSTD',
3387          'Set_Approval_Pending',
3388           itemtype,
3389           itemkey,
3390           to_char(actid),
3391           funcmode);
3392      RAISE;
3393 END Set_Approval_Pending;
3394 
3395 PROCEDURE Maintain_wf_pending_flag (p_assignment_id  IN NUMBER,
3396                     p_mode  IN VARCHAR2 ) IS
3397 l_pending_approval_flag  VARCHAR2(1);
3398 BEGIN
3399     -- if mode = 'PENDING_APPROVAL' set pending_approval_flag = 'Y'
3400     -- elseif mode = 'APPROVAL_PROCESS_COMPLETED' set
3401     --- pending_approval_flag = 'N'
3402     -- This is de-coupled from update status (though updating
3403     -- the same entity, since status may be maintained in multiple
3404     -- places and the pending flag has to be maintained both at the
3405     --start and completeion of the approval WF.
3406       IF p_mode = 'PENDING_APPROVAL' THEN
3407          l_pending_approval_flag := 'Y';
3408       ELSIF
3409          p_mode = 'APPROVAL_PROCESS_COMPLETED' THEN
3410          l_pending_approval_flag := 'N';
3411       ELSE
3412          -- placeholder for any possible future values
3413          l_pending_approval_flag := 'N';
3414           END IF;
3415       UPDATE pa_project_assignments
3416       SET    pending_approval_flag = l_pending_approval_flag,
3417          record_version_number = record_version_number + 1
3418       WHERE  assignment_id = p_assignment_id;
3419 EXCEPTION
3420    WHEN OTHERS THEN
3421     RAISE;
3422 END Maintain_wf_pending_flag ;
3423 
3424 
3425 PROCEDURE Set_Asgmt_wf_result_Status
3426      (p_assignment_id IN pa_project_assignments.assignment_id%TYPE,
3427       p_status_code IN pa_project_statuses.project_status_code%TYPE,
3428       p_result_type  IN VARCHAR2,
3429       p_item_type IN VARCHAR2,
3430       p_item_key  IN VARCHAR2,
3431       x_return_status OUT NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
3432 IS
3433 l_apprvl_status_code pa_project_statuses.project_status_code%TYPE;
3434 l_change_id pa_assignments_history.change_id%TYPE;
3435 l_return_status VARCHAR2(30);
3436 l_msg_count   NUMBER := 0;
3437 l_msg_data    VARCHAR2(500);
3438 l_record_version_number NUMBER := 0;
3439 l_out_record_version_number NUMBER := 0;
3440 l_conflict_group_id         NUMBER;
3441 l_submitter_uname          wf_users.name%type; --- VARCHAR2(100); Changed for bug 3267790
3442 /* Modified length from 30 to 100 for bug 3148857 */
3443 NO_ASSIGNMENT_ID            EXCEPTION;
3444 
3445 CURSOR l_get_record_version_csr IS
3446 SELECT record_version_number FROM
3447 pa_project_assignments
3448 WHERE assignment_id = p_assignment_id;
3449 
3450 BEGIN
3451   OPEN l_get_record_version_csr;
3452   FETCH l_get_record_version_csr
3453   INTO l_record_version_number;
3454 
3455   IF l_get_record_version_csr%NOTFOUND THEN
3456      CLOSE l_get_record_version_csr;
3457      RAISE NO_ASSIGNMENT_ID;
3458   END IF;
3459   CLOSE l_get_record_version_csr;
3460 
3461   -- call the pa_asgmt_approval_pvt to update the
3462   -- assignment approval status and the schedules
3463   x_return_status := FND_API.G_RET_STS_SUCCESS ;
3464   SAVEPOINT asgmt_apprvl;
3465 
3466   pa_assignment_approval_pvt.update_approval_status
3467            (p_assignment_id         => p_assignment_id,
3468         p_action_code           => p_result_type,
3469         p_record_version_number => l_record_version_number,
3470         x_apprvl_status_code    => l_apprvl_status_code,
3471         x_change_id             => l_change_id,
3472             x_record_version_number => l_out_record_version_number,
3473         x_return_status         => l_return_status ,
3474         x_msg_count         => l_msg_count,
3475         x_msg_data          => l_msg_data );
3476 
3477   -- if return status <> SUCCESS, populate the error messages rollback to asgmt_apprvl
3478   -- and return error
3479   IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3480      set_nf_error_msg_attr (p_item_type => p_item_type,
3481                             p_item_key  => p_item_key,
3482                     p_msg_count => l_msg_count,
3483                         p_msg_data  => l_msg_data);
3484      ROLLBACK TO asgmt_apprvl;
3485      x_return_status := l_return_status;
3486   ELSE
3487      -------------------------------------------------------------------
3488      --  Resolve Overcommitment conflict for Approve
3489      -------------------------------------------------------------------
3490      l_conflict_group_id  := wf_engine.GetItemAttrNumber
3491                              (itemtype => p_item_type,
3492                               itemkey  => p_item_key,
3493                               aname    => 'CONFLICT_GROUP_ID');
3494 
3495      l_submitter_uname := wf_engine.GetItemAttrText
3496                    ( itemtype => p_item_type
3497                                , itemkey  => p_item_key
3498                                , aname    => 'WORKFLOW_STARTED_BY_UNAME');
3499 
3500      IF (l_conflict_group_id IS NOT NULL AND p_result_type=PA_ASSIGNMENT_APPROVAL_PUB.g_approve_action) THEN
3501         -- resolve remaining conflicts by taking action chosen by user
3502         PA_SCHEDULE_PVT.RESOLVE_CONFLICTS (p_conflict_group_id   => l_conflict_group_id
3503                                           ,p_assignment_id       => p_assignment_id
3504                                       ,x_return_status       => l_return_status
3505                                           ,x_msg_count           => l_msg_count
3506                                           ,x_msg_data            => l_msg_data);
3507         /*IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3508            RAISE FND_API.G_EXC_ERROR;
3509         END IF;*/
3510 
3511         -- complete post overcommitment processing
3512         PA_SCHEDULE_PVT.OVERCOM_POST_APRVL_PROCESSING
3513                                               (p_conflict_group_id   => l_conflict_group_id
3514                                               ,p_fnd_user_name       => l_submitter_uname
3515                                       ,x_return_status       => l_return_status
3516                                               ,x_msg_count           => l_msg_count
3517                                               ,x_msg_data            => l_msg_data);
3518         /*IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3519            RAISE FND_API.G_EXC_ERROR;
3520         END IF;*/
3521      END IF; -- IF (l_conflict_group_id IS NOT NULL...
3522   END IF;
3523 
3524   Maintain_wf_pending_flag
3525         (p_assignment_id => p_assignment_id,
3526                  p_mode  => 'APPROVAL_PROCESS_COMPLETED');
3527 
3528   -- Set the attribute NEW_ASGMT_STATUS_CODE
3529   wf_engine.SetItemAttrText
3530                    ( itemtype => p_item_type
3531                                , itemkey =>  p_item_key
3532                                , aname => 'NEW_ASGMT_STATUS_CODE'
3533                                , avalue => l_apprvl_status_code);
3534 EXCEPTION
3535   WHEN NO_ASSIGNMENT_ID THEN
3536     WF_CORE.CONTEXT
3537         ('PA_ASGMT_WFSTD',
3538          'Set_Asgmt_wf_result_status',
3539           p_item_type,
3540           p_item_key,
3541           'INVALID_ASSIGNMENT_ID',
3542           NULL );
3543      RAISE;
3544  WHEN OTHERS THEN RAISE;
3545 END Set_Asgmt_wf_result_status;
3546 
3547 
3548 
3549 PROCEDURE Capture_approver_comment  (itemtype IN VARCHAR2
3550                                , itemkey IN VARCHAR2
3551                                , actid IN NUMBER
3552                                , funcmode IN VARCHAR2
3553                                , resultout OUT NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
3554 IS
3555 l_comment               VARCHAR2(4000); --VARCHAR2(2000); Bug 7459451 : Changed the length to accomodate max length returned by wf_engine.getItemAttrText
3556 l_approver_user_name    wf_users.name%type; ----- VARCHAR2(240);Changed for bug 3267790
3557 /* Modified length from 30 to 100 for bug 3148857 */
3558 l_assignment_id     NUMBER;
3559 l_wf_context_user       pa_wf_ntf_performers.user_name%TYPE;
3560 l_reassignee_user_name  pa_wf_ntf_performers.user_name%TYPE;
3561 l_object_id1            pa_wf_ntf_performers.object_id1%TYPE;
3562 l_object_id2            pa_wf_ntf_performers.object_id2%TYPE;
3563 l_prev_approver_user_name pa_wf_ntf_performers.user_name%TYPE;
3564 
3565 CURSOR get_reassignee IS
3566 SELECT USER_NAME
3567 FROM   pa_wf_ntf_performers
3568 WHERE  user_name = l_wf_context_user
3569 AND    wf_type_code = 'ASSIGNMENT_APPROVAL'
3570 AND    item_type = itemtype
3571 AND    item_key  = itemkey;
3572 
3573 CURSOR get_objectids IS
3574 SELECT object_id1, object_id2
3575 FROM   pa_wf_ntf_performers
3576 WHERE  wf_type_code = 'ASSIGNMENT_APPROVAL'
3577 AND    item_type = itemtype
3578 AND    item_key  = itemkey
3579 AND    current_approver_flag = 'Y';
3580 
3581 BEGIN
3582        l_comment := wf_engine.GetItemAttrText
3583                    ( itemtype => itemtype
3584                                , itemkey =>  itemkey
3585                                , aname => 'APPROVER_RESPONSE'
3586                                );
3587        IF l_comment IS NOT NULL THEN
3588            l_approver_user_name := wf_engine.GetItemAttrText
3589                    ( itemtype => itemtype
3590                                , itemkey =>  itemkey
3591                                , aname => 'APPROVER_UNAME'
3592                                );
3593            l_assignment_id := wf_engine.GetItemAttrNumber
3594                    ( itemtype => itemtype
3595                                , itemkey =>  itemkey
3596                                , aname => 'ASSIGNMENT_ID'
3597                                );
3598        UPDATE pa_wf_ntf_performers
3599        SET  approver_comments = substr(l_comment,1,255)
3600        WHERE item_type  = itemtype
3601        AND   item_key   = itemkey
3602        AND   object_id1 = l_assignment_id
3603        AND   user_name  = l_approver_user_Name;
3604        -- Now reset the approver response attribute
3605        -- so that the next approver can add his/her comments
3606             wf_engine.SetItemAttrText
3607                          ( itemtype => itemtype
3608                          , itemkey =>  itemkey
3609                          , aname => 'APPROVER_RESPONSE'
3610                          , avalue => NULL
3611                          );
3612        END IF;
3613 
3614        --IF the user reassigns the notification to another person, two things need to be done
3615        --1) If the reassignee is not already in the notification table, insert into notification and
3616        --   set current_approver_flag to 'Y'.  If reassignee is already in the table, then just set flag to 'Y'
3617        --2) Set the Forwarded_From attribute for display
3618        IF funcmode IN ('TRANSFER', 'FORWARD') THEN
3619 
3620           l_wf_context_user := WF_ENGINE.context_text;
3621 
3622           --Check to see if the reassignee already in the table
3623            OPEN get_reassignee;
3624           FETCH get_reassignee INTO l_reassignee_user_name;
3628           IF l_reassignee_user_name IS NULL THEN
3625           CLOSE get_reassignee;
3626 
3627           --IF not in the table, then insert and set current_approver_flag to 'Y'
3629 
3630 
3631             --Get object_ids for inserting into the new record
3632             OPEN get_objectids;
3633             FETCH get_objectids INTO l_object_id1, l_object_id2;
3634             CLOSE get_objectids;
3635 
3636             INSERT INTO pa_wf_ntf_performers (WF_TYPE_CODE, ITEM_TYPE, ITEM_KEY,
3637                                               OBJECT_ID1, OBJECT_ID2, USER_NAME,
3638                                               USER_TYPE, CURRENT_APPROVER_FLAG)
3639               VALUES ('ASSIGNMENT_APPROVAL', itemtype, itemkey,
3640                        l_object_id1, l_object_id2, l_wf_context_user,
3641                        'REASSIGNEE', 'Y');
3642 
3643           END IF;
3644 
3645 
3646           --Set current_approver_flag to 'N' for the previous current_approver
3647           UPDATE pa_wf_ntf_performers
3648             SET current_approver_flag = (DECODE(user_name,l_wf_context_user,'Y','N'))
3649             WHERE wf_type_code = 'ASSIGNMENT_APPROVAL'
3650             AND   item_type = itemtype
3651             AND   item_key  = itemkey
3652             AND   current_approver_flag = 'Y';
3653 
3654 
3655           --
3656           --Correctly set the forwarded_from attribute
3657           --
3658 
3659           --set the previous_approver attribute correctly
3660           l_prev_approver_user_name :=
3661                     wf_engine.GetItemAttrText
3662                    ( itemtype => itemtype
3663                                , itemkey =>  itemkey
3664                                , aname => 'APPROVER_UNAME');
3665           wf_engine.SetItemAttrText
3666                    ( itemtype => itemtype
3667                                , itemkey =>  itemkey
3668                                , aname => 'PREV_APPROVER_UNAME'
3669                                , avalue => l_prev_approver_user_name
3670                                );
3671 
3672           --set current_approver to be the reassignee
3673           wf_engine.SetItemAttrText
3674                    ( itemtype => itemtype
3675                                , itemkey =>  itemkey
3676                                , aname => 'APPROVER_UNAME'
3677                                , avalue => l_wf_context_user
3678                                );
3679 
3680 
3681           --call set_forwarded_from procedure
3682           Set_Forwarded_From  (itemtype    => itemtype
3683                                , itemkey   => itemkey
3684                                , actid     => actid
3685                                , funcmode  => funcmode
3686                                , resultout => resultout);
3687 
3688           --set notification attribute forwarded_from to let the change show up
3689           WF_NOTIFICATION.SetAttrText (nid    => WF_ENGINE.context_nid
3690                                       ,aname  => 'FORWARDED_FROM'
3691                                       ,avalue => l_prev_approver_user_name);
3692 
3693 /*
3694 
3695             INSERT INTO pa_wf_ntf_performers (WF_TYPE_CODE, ITEM_TYPE, ITEM_KEY,
3696                                               OBJECT_ID1, OBJECT_ID2, USER_NAME,
3697                                               USER_TYPE, CURRENT_APPROVER_FLAG)
3698               VALUES ('ASSIGNMENT_APPROVAL', itemtype, itemkey,
3699                        1, 2, l_wf_context_user,
3700                        'REASSIGNEE', 'Y');
3701 */
3702        END IF;  --end of checking in 'TRANSFER'/'FORWARD' mode
3703 exception
3704 WHEN OTHERS THEN
3705    wf_core.context
3706     ('PA_ASGMT_WFSTD',
3707     'Capture_approver_comment',
3708      itemtype,
3709      itemkey);
3710         RAISE;
3711 END Capture_approver_comment;
3712 
3713 PROCEDURE Capture_approver_response (p_item_type IN VARCHAR2,
3714                      p_item_key  IN VARCHAR2)
3715 IS
3716 BEGIN
3717     g_approver_response :=
3718                             wf_engine.GetItemAttrText
3719                    ( itemtype => p_item_type
3720                                , itemkey =>  p_item_key
3721                                , aname => 'APPROVER_RESPONSE'
3722                                );
3723 EXCEPTION
3724  WHEN OTHERS THEN RAISE;
3725 END Capture_approver_response;
3726 
3727 PROCEDURE Populate_approval_NF_comments  (itemtype IN VARCHAR2
3728                                , itemkey IN VARCHAR2
3729                                , actid IN NUMBER
3730                                , funcmode IN VARCHAR2
3731                                , resultout OUT NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
3732 IS
3733 l_assignment_id pa_project_assignments.assignment_id%TYPE;
3734 
3735 BEGIN
3736    -- Call the set_approver_comments procedure.
3737    -- Since populate_approval_NF_comments is being called from the
3738    -- approval process, pass the same item type and item key values
3739    -- for both p_apprvl and p_item parameters
3740 
3741         l_assignment_id := wf_engine.GetItemAttrNumber
3742                    (itemtype => itemtype,
3743                     itemkey  => itemkey,
3744                     aname    => 'ASSIGNMENT_ID');
3745 
3746         Set_approver_comments   (p_apprvl_item_type => itemtype
3747                 ,p_apprvl_item_key  => itemkey
3748                 ,p_item_type        => itemtype
3749                 ,p_item_key         => itemkey
3750                 ,p_assignment_id    => l_assignment_id);
3751 
3752    -- Now call the set comment attributes procedure
3753    -- This will copy the comments from the internal comments
3754    -- attribute to the displayed comments attributes
3755    -- Since the comments are to be displayed only to
3756    -- an approver, there is no need to send a value for
3757    -- p_rect_type parameter. A value for this parameter
3758    -- is needed only if the recipient is the RESOURCE
3759    -- since all comments have to be suppressed in a notification
3760    -- a Resource recieves. A Resource would never recieve an
3761    -- 'Approval required ' notification
3762 
3763        Set_Comment_Attributes (p_item_type => itemtype,
3764                    p_item_key  => itemkey ,
3765                    p_rect_type => NULL );
3766 EXCEPTION
3767 WHEN OTHERS THEN
3768    wf_core.context
3769     ('PA_ASGMT_WFSTD',
3770     'Populate_approval_NF_comments' ,
3771      itemtype,
3772      itemkey);
3773 RAISE;
3774 
3775 END Populate_approval_NF_comments;
3776 
3777 PROCEDURE generate_sch_err_msg
3778                 (document_id     IN      VARCHAR2,
3779                  display_type    IN      VARCHAR2,
3780                  document        IN OUT  NOCOPY VARCHAR2, --File.Sql.39 bug 4440895
3781                  document_type   IN OUT  NOCOPY VARCHAR2)  IS --File.Sql.39 bug 4440895
3782 l_msg_count    NUMBER ;
3783 l_msg_index_out    NUMBER ;
3784 l_msg_data     VARCHAR2(2000);
3785 l_data             VARCHAR2(2000);
3786 l_newline      VARCHAR2(10);
3787 l_item_type    VARCHAR2(200);
3788 l_item_key     VARCHAR2(200);
3789 l_msg_text VARCHAR2(300);
3790 CURSOR l_nf_csr IS
3791 SELECT item_type, item_key
3792 FROM   wf_item_activity_statuses
3793 WHERE  notification_id = document_id;
3794 
3795 BEGIN
3796      l_newline := FND_GLOBAL.newline;
3797      l_msg_count := FND_MSG_PUB.Count_Msg;
3798      OPEN l_nf_csr;
3799      FETCH l_nf_csr INTO l_item_type, l_item_key;
3800      IF l_nf_csr%NOTFOUND THEN
3801     document := 'Item Key not found';
3802         CLOSE l_nf_csr;
3803         RETURN;
3804      ELSE
3805         CLOSE l_nf_csr;
3806      END IF;
3807      -- document := '<html>';
3808        document_type := 'text/html';
3809      l_msg_data := wf_engine.GetItemAttrText
3810                    ( itemtype => l_item_type
3811                                , itemkey =>  l_item_key
3812                                , aname => 'L_MSG_DATA'
3813                                );
3814      IF l_msg_count = 0 THEN
3815     document := 'No errors in the stack';
3816     RETURN;
3817      END IF;
3818 
3819      IF l_msg_count > 1 THEN
3820         FOR i in 1..l_msg_count LOOP
3821         pa_interface_utils_pub.get_messages
3822         (p_encoded        => FND_API.G_FALSE,
3823          p_msg_index      => i,
3824                  p_msg_count      => l_msg_count ,
3825                  p_msg_data       => l_msg_data ,
3826                  p_data           => l_data,
3827                  p_msg_index_out  => l_msg_index_out );
3828           document := document ||  ' <p>' || l_data ||' </p>';
3829        END LOOP;
3830      ELSIF l_msg_count = 1 THEN
3831             FND_MESSAGE.SET_ENCODED (l_msg_data);
3832             l_data := FND_MESSAGE.GET;
3833             document := document ||  ' <p>' || l_data ||' </p>';
3834      END IF;
3835 
3836 exception
3837 WHEN OTHERS THEN
3838    wf_core.context('PA_ASGMT_WFSTD','Generate_sch_err_msg',Document_id,NULL);
3839         RAISE;
3840 END generate_sch_err_msg;
3841 
3842 PROCEDURE set_nf_error_msg_attr (p_item_type IN VARCHAR2,
3843                      p_item_key  IN VARCHAR2,
3844                  p_msg_count IN NUMBER,
3845                  p_msg_data IN VARCHAR2 ) IS
3846 
3847 l_msg_index_out    NUMBER ;
3848 l_msg_data     VARCHAR2(2000);
3849 l_data             VARCHAR2(2000);
3850 l_item_attr_name   VARCHAR2(30);
3851 BEGIN
3852           IF p_msg_count = 0 THEN
3853            RETURN;
3854           END IF;
3855 
3856       IF p_msg_count = 1 THEN
3857          IF p_msg_data IS NOT NULL THEN
3858                 FND_MESSAGE.SET_ENCODED (p_msg_data);
3859                 l_data := FND_MESSAGE.GET;
3860                 wf_engine.SetItemAttrText
3861                    ( itemtype => p_item_type
3862                                , itemkey =>  p_item_key
3863                                , aname => 'ERROR_MSG1'
3864                                , avalue => l_data
3865                                );
3866          END IF;
3867              RETURN ;
3868           END IF;
3869 
3870           IF p_msg_count > 1 THEN
3871               FOR i in 1..p_msg_count
3872         LOOP
3873           IF i > 5 THEN
3874          EXIT;
3875           END IF;
3876           pa_interface_utils_pub.get_messages
3877         (p_encoded        => FND_API.G_FALSE,
3878          p_msg_index      => i,
3879                  p_msg_count      => p_msg_count ,
3880                  p_msg_data       => p_msg_data ,
3881                  p_data           => l_data,
3882                  p_msg_index_out  => l_msg_index_out );
3883                  l_item_attr_name := 'ERROR_MSG'||i;
3884                    wf_engine.SetItemAttrText
3885                    ( itemtype => p_item_type
3886                                , itemkey =>  p_item_key
3887                                , aname => l_item_attr_name
3888                                , avalue => l_data
3889                                );
3890             END LOOP;
3891       END IF;
3892 EXCEPTION
3893     WHEN OTHERS THEN RAISE;
3894 END set_nf_error_msg_attr;
3895 
3896 PROCEDURE get_primary_contact_info
3897                (p_resource_id  IN NUMBER
3898               , p_assignment_id IN NUMBER
3899               , p_approver1_person_id IN NUMBER
3900               , p_approver1_type IN      VARCHAR2
3901               , p_approver2_person_id IN NUMBER
3902               , p_approver2_type IN      VARCHAR2
3903               , x_PrimaryContactId     OUT NOCOPY NUMBER ) --File.Sql.39 bug 4440895
3904 IS
3905 l_primarycontactname per_all_people_f.full_name%type; ----- VARCHAR2(240);Changed for bug 3267790
3906 l_managerid      NUMBER := 0;
3907 l_managername        per_all_people_f.full_name%type;----- VARCHAR2(240);Changed for bug 3267790
3908 l_return_status      VARCHAR2(1);
3909 l_msg_count      NUMBER ;
3910 l_msg_data       VARCHAR2(2000);
3911 BEGIN
3912     -- If the primary contact was either the 1st or 2nd approver
3913     -- then return the appropriate person id
3914     IF p_approver1_type = 'ORG_PRIMARY_CONTACT' THEN
3915            x_PrimaryContactId := p_approver1_person_id;
3916        RETURN;
3917         ELSIF p_approver2_type = 'ORG_PRIMARY_CONTACT' THEN
3918        x_PrimaryContactId := p_approver2_person_id;
3919        RETURN;
3920     END IF;
3921         -- If the primary contact is neither of the two approvers,
3922     -- then get that info from the DB
3923          pa_resource_utils.get_org_primary_contact
3924                           (P_ResourceId          => p_resource_id
3925                            ,p_assignment_id      => p_assignment_id
3926                            ,x_PrimaryContactId   => x_primarycontactid
3927                            ,x_PrimaryContactName => l_primarycontactname
3928                            ,x_ManagerId          => l_managerid
3929                            ,x_ManagerName        => l_managername
3930                            ,x_return_Status      => l_return_status
3931                            ,x_msg_count          => l_msg_count
3932                            ,x_msg_data           => l_msg_data
3933                            ) ;
3934 EXCEPTION
3935  WHEN OTHERS THEN RAISE;
3936 
3937 END get_primary_contact_info;
3938 
3939 PROCEDURE populate_wf_performers
3940     ( p_wf_type_code IN VARCHAR2
3941      ,p_item_type    IN VARCHAR2
3942      ,p_item_key     IN VARCHAR2
3943      ,p_object_id1  IN VARCHAR2
3944      ,p_object_id2  IN VARCHAR2
3945      ,p_in_performers_tbl PA_CLIENT_EXTN_ASGMT_WF.Users_List_Tbltyp
3946      ,p_current_approver_flag  IN VARCHAR2
3947      ,x_number_of_performers OUT NOCOPY NUMBER ) --File.Sql.39 bug 4440895
3948 IS
3949 l_number_of_performers NUMBER := 0;
3950 BEGIN
3951     -- Need to insert the user names into
3952     -- the members table. To validate the users first
3953     -- to ensure that notifications can be appropriately sent
3954     -- Insert only active users
3955     x_number_of_performers := 0;
3956       IF p_in_performers_tbl.EXISTS(1) THEN
3957      FOR i IN 1..p_in_performers_tbl.COUNT LOOP
3958          IF wf_directory.UserActive
3959         (p_in_performers_tbl(i).User_Name) THEN
3960              INSERT INTO pa_wf_ntf_performers (
3961                   Wf_Type_Code,Item_Type,
3962                   Item_Key,object_id1,
3963                   object_id2,User_Name,User_Type,
3964                   Routing_Order,Current_Approver_flag
3965           )
3966               VALUES
3967           ( p_wf_type_code,
3968             p_item_type,
3969             p_item_key,
3970             p_object_id1,
3971             p_object_id2,
3972             p_in_performers_tbl(i).User_Name,
3973             p_in_performers_tbl(i).Type,
3974             p_in_performers_tbl(i).Routing_Order,
3975                 p_current_approver_flag );
3976              l_number_of_performers := l_number_of_performers + 1;
3977       END IF;
3978     END LOOP;
3979       END IF;
3980      x_number_of_performers := l_number_of_performers;
3981 EXCEPTION
3982  WHEN OTHERS THEN RAISE;
3983 END populate_wf_performers;
3984 
3985 PROCEDURE get_wf_performer (p_wf_type_code IN VARCHAR2,
3986                 p_item_type    IN VARCHAR2,
3987                 p_item_key     IN VARCHAR2,
3988                 p_routing_order IN NUMBER,
3989                     p_object_id1  IN VARCHAR2 ,
3990                 x_performer_name OUT NOCOPY VARCHAR2, --File.Sql.39 bug 4440895
3991                 x_performer_type OUT NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
3992 IS
3993 CURSOR l_get_next_performer_csr
3994 IS
3995 SELECT User_Name , User_Type FROM pa_wf_ntf_performers
3996 WHERE  wf_type_code = p_wf_type_code
3997 AND    item_type    = p_item_type
3998 AND    item_key     = p_item_key
3999 AND   routing_order = p_routing_order
4000 AND   object_id1   = p_object_id1;
4001 
4002 l_user_name        pa_wf_ntf_performers.user_name%TYPE;
4003 
4004 BEGIN
4005 
4006     OPEN l_get_next_performer_csr ;
4007     FETCH l_get_next_performer_csr INTO
4008           x_performer_name, x_performer_type ;
4009     IF l_get_next_performer_csr%NOTFOUND THEN
4010        x_performer_name := NULL;
4011        x_performer_type := NULL;
4012     END IF;
4013 
4014     CLOSE l_get_next_performer_csr;
4015 
4016 
4017         --Bug 1770103: do not send FYI notification to the user logged in.
4018 
4019         IF p_wf_type_code like '%FYI' THEN
4020 
4021           --Get the Name of the User logged In.
4022       l_user_name := wf_engine.GetItemAttrText
4023                          ( itemtype => p_item_type
4024                          , itemkey =>  p_item_key
4025                          , aname => 'WORKFLOW_STARTED_BY_UNAME');
4026     /*  IF x_performer_name = l_user_name THEN
4027              x_performer_name := NULL;
4028              x_performer_type := NULL;
4029           END IF;*/
4030         END IF;
4031         --end of bug 1770103
4032 
4033 EXCEPTION
4034  WHEN OTHERS THEN RAISE;
4035 END get_wf_performer ;
4036 
4037 PROCEDURE Set_approver_comments (p_apprvl_item_type VARCHAR2,
4038                  p_apprvl_item_key  VARCHAR2,
4039                  p_item_type  VARCHAR2,
4040                  p_item_key  VARCHAR2,
4041                  p_assignment_id NUMBER )
4042 IS
4043 CURSOR l_get_approver_comments_csr IS
4044 SELECT user_Name,approver_comments
4045 FROM pa_wf_ntf_performers
4046 WHERE item_type = p_apprvl_item_type
4047 AND   item_key  = p_apprvl_item_key
4048 AND   object_id1 = p_assignment_id
4049 AND   approver_comments IS NOT NULL;
4050 l_get_approver_comments_rec l_get_approver_comments_csr%ROWTYPE;
4051 l_counter NUMBER := 0;
4052 l_item_attr_name   VARCHAR2(30);
4053 BEGIN
4054     -- Using the approval item type , get the
4055     -- comments of the approvers.
4056         -- p_apprvl_item_type and p_item_type
4057     -- would be different if the FYI notification wf is triggered
4058     -- by the approval workflow.
4059         -- When this procedure is invoked by the approval workflow
4060     -- p_apprvl_item_type and p_item_type would be the same
4061 
4062     IF (p_apprvl_item_type IS NOT NULL AND p_apprvl_item_key
4063         IS NOT NULL ) THEN
4064     OPEN l_get_approver_comments_csr;
4065     LOOP
4066         FETCH l_get_approver_comments_csr INTO
4067         l_get_approver_comments_rec;
4068         IF l_get_approver_comments_csr%NOTFOUND THEN
4069            EXIT;
4070         END IF;
4071         l_counter := l_counter + 1;
4072         IF l_counter > 5 THEN
4073            EXIT;
4074         END IF;
4075       -- Now set the appropriate comments attributes for this WF
4076       -- Populate the internal comments only . displayed comments
4077       -- will be done by the get_recipients nodes
4078         l_item_attr_name := 'INTERNAL_APPROVER_COMMENTS_'||l_counter ;
4079             wf_engine.SetItemAttrText
4080                    ( itemtype => p_item_type
4081                                , itemkey =>  p_item_key
4082                                , aname => l_item_attr_name
4083                                , avalue =>
4084                  l_get_approver_comments_rec.user_name ||
4085                  ' : ' ||
4086                 l_get_approver_comments_rec.approver_comments
4087                                );
4088     END LOOP;
4089     CLOSE l_get_approver_comments_csr;
4090       END IF;
4091 
4092 EXCEPTION
4093    WHEN OTHERS THEN RAISE;
4094 END Set_Approver_Comments;
4095 
4096 PROCEDURE Set_Comment_Attributes (p_item_type IN VARCHAR2,
4097                           p_item_key  IN VARCHAR2,
4098                   p_rect_type IN VARCHAR2 ) IS
4099 l_comments_item_attr_name  VARCHAR2(30);
4100 l_comments VARCHAR2(4000); -- VARCHAR2(255); Bug 7459451 : Changed the length to accomodate max length returned by wf_engine.getItemAttrText
4101 BEGIN
4102     -- Set displayed comments to NULL if the recipient is resource
4103     -- otherwise set the displayed comments to the internal comments
4104         FOR i IN 1..5 LOOP
4105         l_comments_item_attr_name := 'INTERNAL_APPROVER_COMMENTS_'||i;
4106         l_comments := wf_engine.getItemAttrText
4107                    ( itemtype => p_item_type
4108                                , itemkey =>  p_item_key
4109                                , aname => l_comments_item_attr_name
4110                                );
4111              IF p_rect_type = 'RESOURCE' THEN
4112                 l_comments := NULL;
4113              END IF;
4114                  wf_engine.SetItemAttrText
4115                    ( itemtype => p_item_type
4116                                , itemkey =>  p_item_key
4117                                , aname => 'APPROVER_COMMENTS_'||i
4118                                , avalue => l_comments
4119                                );
4120         END LOOP;
4121 
4122 EXCEPTION
4123    WHEN OTHERS THEN RAISE;
4124 END Set_Comment_Attributes;
4125 
4126 PROCEDURE Check_And_Get_Proj_Customer ( p_project_id IN NUMBER
4127                        ,x_customer_id OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
4128                        ,x_customer_name OUT NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
4129 IS
4130 
4131 l_customer_id    pa_project_customers.customer_id%TYPE;
4132 l_num_ids        NUMBER;
4133 
4134 CURSOR l_check_one_cust_only_csr IS
4135 SELECT customer_id FROM pa_project_customers
4136 WHERE project_id = p_project_id;
4137 
4138 /*
4139 CURSOR l_get_cust_csr IS
4140 SELECT ppc.customer_id,rac.customer_name
4141 FROM pa_project_customers ppc,
4142      ra_customers rac
4143 WHERE ppc.project_id = p_project_id
4144 AND   rac.customer_id = ppc.customer_id ;
4145 */
4146 
4150 SELECT customer_name
4147 -- 4363092 TCA changes, replaced RA views with HZ tables
4148 /*
4149 CURSOR l_get_cust_csr IS
4151 FROM ra_customers
4152 WHERE customer_id = l_customer_id;
4153 */
4154 CURSOR l_get_cust_csr IS
4155 SELECT substrb(party.party_name,1,50) customer_name
4156 FROM hz_parties party, hz_cust_accounts cust_acct
4157 WHERE cust_acct.cust_account_id = l_customer_id
4158       and cust_acct.party_id = party.party_id ;
4159 -- 4363092 end
4160 
4161 BEGIN
4162    OPEN l_check_one_cust_only_csr;
4163 
4164    LOOP
4165      FETCH l_check_one_cust_only_csr INTO l_customer_id;
4166      EXIT WHEN (l_check_one_cust_only_csr%ROWCOUNT > 1 OR l_check_one_cust_only_csr%NOTFOUND);
4167    END LOOP;
4168    l_num_ids := l_check_one_cust_only_csr%ROWCOUNT;
4169 
4170    CLOSE l_check_one_cust_only_csr;
4171 
4172    IF (l_num_ids = 1) THEN
4173      x_customer_id := l_customer_id;
4174 
4175      OPEN l_get_cust_csr;
4176      FETCH l_get_cust_csr INTO
4177         x_customer_name;
4178      CLOSE l_get_cust_csr;
4179    END IF;
4180 
4181 EXCEPTION
4182    WHEN OTHERS THEN RAISE;
4183 
4184 END Check_And_Get_proj_customer;
4185 
4186 PROCEDURE   Set_NF_Subject_and_Desc  (p_item_type       IN VARCHAR2,
4187                       p_item_key        IN VARCHAR2,
4188                       p_assignment_type IN VARCHAR2,
4189                       p_reapproval_flag IN VARCHAR2,
4190                       p_msg_type        IN VARCHAR2) IS
4191 l_msg_subj_code              VARCHAR2(30);
4192 l_msg_desc_code              VARCHAR2(30);
4193 l_msg_subj_text              VARCHAR2(2000);
4194 l_msg_desc_text              VARCHAR2(2000);
4195 l_msg_subj_itemattr_name     VARCHAR2(30);
4196 l_msg_desc_itemattr_name     VARCHAR2(30);
4197 l_assignment_id              NUMBER ;
4198 l_conflict_group_id          NUMBER ;
4199 l_resolve_conflicts_by_rmvl  VARCHAR2(1);
4200 l_view_conflict_url          VARCHAR2(2000);
4201 l_return_status              VARCHAR2(1);
4202 l_msg_count              NUMBER ;
4203 l_msg_data               VARCHAR2(2000);
4204 
4205 BEGIN
4206 
4207     /*
4208     Pass the following . assignment_type,reapproval_flag
4209                     ,msg_type - ASSIGNMENT_APPROVAL
4210                 ,       APPROVAL_FYI , REJECTION_FYI
4211         If assignment approval ,
4212        If admin assignment
4213         Set msg subj and header as Admin approval
4214        Else
4215          If reapproval set msg subj and header as reapproval
4216        End if
4217     Elsif
4218        approval FYI set msg subj and header FYI depends on ovecommitment result.
4219     Elsif
4220        rejection FYI set msg subj and header FYI as rejected
4221         Elsif
4222            cancellation FYI set msg subj and header FYI as canceled
4223     End if
4224     */
4225     IF p_msg_type = 'ASSIGNMENT_APPROVAL' THEN
4226            l_msg_subj_itemattr_name := 'MSG_SUBJECT';
4227            l_msg_desc_itemattr_name := 'MSG_DESCRIPTION';
4228 
4229        IF p_assignment_type = 'STAFFED_ADMIN_ASSIGNMENT' THEN
4230           l_msg_subj_code := 'PA_NFSUBJ_ADM_ASG_APRVL_REQD';
4231           l_msg_desc_code := 'PA_NFDESC_ADM_ASG_APRVL_REQD';
4232        ELSIF p_assignment_type = 'STAFFED_ASSIGNMENT' THEN
4233         IF p_reapproval_flag = 'Y' THEN
4234                l_msg_subj_code := 'PA_NFSUBJ_ASG_REAPRVL_REQD';
4235                l_msg_desc_code := 'PA_NFDESC_ASG_REAPRVL_REQD';
4236             ELSE
4237                l_msg_subj_code := 'PA_NFSUBJ_ASG_APRVL_REQD';
4238                l_msg_desc_code := 'PA_NFDESC_ASG_APRVL_REQD';
4239             END IF;
4240            END IF;
4241 
4242          ELSIF p_msg_type = 'APPROVAL_FYI' THEN
4243                l_assignment_id := wf_engine.GetItemAttrNumber
4244                            (itemtype => p_item_type,
4245                             itemkey  => p_item_key,
4246                             aname    => 'ASSIGNMENT_ID');
4247                l_conflict_group_id := wf_engine.GetItemAttrNumber
4248                                (itemtype => p_item_type,
4249                                 itemkey  => p_item_key,
4250                                 aname    => 'CONFLICT_GROUP_ID');
4251 
4252                -- If there is no overcommitment conflict
4253                IF (l_conflict_group_id IS NULL) THEN
4254               l_msg_subj_code := 'PA_NFSUBJ_ASGMT_APPROVED';
4255               l_msg_desc_code := 'PA_NFDESC_ASGMT_APPROVED';
4256 
4257                   -- set 'Number of Assignments Resulting in Resource Overcommitment -1/0' for single
4258                   -- approval FYI notification.
4259                   wf_engine.SetItemAttrNumber
4260                    ( itemtype => p_item_type
4261                                , itemkey  => p_item_key
4262                                , aname    => 'NUMBER_OF_OVERCOM_ASGMT'
4263                                , avalue   => 0 );
4264                -- If there is any overcommitment conflict
4265                ELSE
4266                   PA_SCHEDULE_PVT.has_resolved_conflicts_by_rmvl
4267                                   ( p_conflict_group_id         => l_conflict_group_id
4268                                   , p_assignment_id             => l_assignment_id
4269                                   , x_resolve_conflicts_by_rmvl => l_resolve_conflicts_by_rmvl
4270                                   , x_return_status             => l_return_status
4271                                   , x_msg_count                 => l_msg_count
4272                                   , x_msg_data                  => l_msg_data);
4273                   IF (l_resolve_conflicts_by_rmvl = 'Y') THEN
4274                  l_msg_subj_code := 'PA_NFSUBJ_ASGMT_APPR_CONF_REM';
4275                  l_msg_desc_code := 'PA_NFDESC_ASGMT_APPR_CONF_REM';
4276                   ELSE
4277                  l_msg_subj_code := 'PA_NFSUBJ_ASGMT_APPR_KP_CONF';
4278                  l_msg_desc_code := 'PA_NFDESC_ASGMT_APPR_KP_CONF';
4279                   END IF;
4280 
4281                   -- set 'Number of Assignments Resulting in Resource Overcommitment -1/0' for single
4282                   -- approval FYI notification.
4283                   wf_engine.SetItemAttrNumber
4284                    ( itemtype => p_item_type
4285                                , itemkey  => p_item_key
4286                                , aname    => 'NUMBER_OF_OVERCOM_ASGMT'
4287                                , avalue   => 1 );
4288                END IF; -- If (l_conflict_group_id IS NULL)
4289 
4290                -- set resource overcommitment url
4291                l_view_conflict_url := 'JSP:/OA_HTML/OA.jsp?akRegionApplicationId=275&akRegionCode='
4292                                    || 'PA_RES_OVERCOMMITMENT_LAYOUT&paAssignmentId=' || l_assignment_id
4293                                    || '&paConflictGroupId=' || l_conflict_group_id
4294                                    || '&paCallingPage=Default&addBreadCrumb=RP';
4295 
4296                wf_engine.SetItemAttrText
4297                       ( itemtype => p_item_type
4298                                   , itemkey  => p_item_key
4299                                   , aname    => 'VIEW_CONFLICT_URL_INFO'
4300                                   , avalue   => l_view_conflict_url );
4301      ELSIF p_msg_type = 'REJECTION_FYI' OR p_msg_type = 'CANCELLATION_FYI' THEN
4302                -- set 'Number of Assignments Resulting in Resource Overcommitment -0' for single
4303                -- reject/cancel FYI notification.
4304                wf_engine.SetItemAttrNumber
4305                    ( itemtype => p_item_type
4306                                , itemkey  => p_item_key
4307                                , aname    => 'NUMBER_OF_OVERCOM_ASGMT'
4308                                , avalue   => 0 );
4309 
4310                l_assignment_id := wf_engine.GetItemAttrNumber
4311                            (itemtype => p_item_type,
4312                             itemkey  => p_item_key,
4313                             aname    => 'ASSIGNMENT_ID');
4314                -- set resource overcommitment url
4315                l_view_conflict_url := 'JSP:/OA_HTML/OA.jsp?akRegionApplicationId=275&akRegionCode='
4316                                    || 'PA_RES_OVERCOMMITMENT_LAYOUT&paAssignmentId=' || l_assignment_id
4317                                    || '&paConflictGroupId=&paCallingPage=Default&addBreadCrumb=RP';
4318 
4319                wf_engine.SetItemAttrText
4320                       ( itemtype => p_item_type
4321                                   , itemkey  => p_item_key
4322                                   , aname    => 'VIEW_CONFLICT_URL_INFO'
4323                                   , avalue   => l_view_conflict_url );
4324 
4325            IF p_msg_type = 'REJECTION_FYI' THEN
4326               l_msg_subj_code := 'PA_NFSUBJ_ASGMT_REJECTED';
4327               l_msg_desc_code := 'PA_NFDESC_ASGMT_REJECTED';
4328                ELSIF p_msg_type = 'CANCELLATION_FYI' THEN
4329               l_msg_subj_code := 'PA_NFSUBJ_ASGMT_CANCELED';
4330               l_msg_desc_code := 'PA_NFDESC_ASGMT_CANCELED';
4331                END IF;
4332      END IF;
4333 
4334      IF p_msg_type IN ('APPROVAL_FYI','REJECTION_FYI','CANCELLATION_FYI') THEN
4335            l_msg_subj_itemattr_name := 'MSG_SUBJECT_FYI';
4336            l_msg_desc_itemattr_name := 'MSG_DESCRIPTION_FYI';
4337      END IF;
4338 
4339          -- Now that the message codes have been set,
4340      -- get the message from fnd messages
4341      FND_MESSAGE.SET_NAME ('PA',l_msg_subj_code);
4342      l_msg_subj_text := FND_MESSAGE.GET;
4343      FND_MESSAGE.SET_NAME ('PA',l_msg_desc_code);
4344      l_msg_desc_text := FND_MESSAGE.GET;
4345 
4346          wf_engine.SetItemAttrText
4347                    ( itemtype => p_item_type
4348                                , itemkey =>  p_item_key
4349                                , aname =>    l_msg_subj_itemattr_name
4350                                , avalue =>   l_msg_subj_text
4351                                );
4352          wf_engine.SetItemAttrText
4353                    ( itemtype => p_item_type
4354                                , itemkey =>  p_item_key
4355                                , aname =>    l_msg_desc_itemattr_name
4356                                , avalue =>   l_msg_desc_text
4357                                );
4358 EXCEPTION
4359   WHEN OTHERS THEN RAISE;
4360 
4361 END Set_NF_Subject_and_Desc ;
4362 
4363 
4364 
4365 PROCEDURE Delete_Assignment_WF_Records (p_assignment_id  IN   pa_project_assignments.assignment_id%TYPE,
4366                                         p_project_id     IN   pa_project_assignments.project_id%TYPE)
4367 IS
4368 
4369 /*CURSOR get_project_id IS
4370   SELECT project_id
4371   FROM pa_project_assignments
4372   WHERE assignment_id = p_assignment_id;
4373 
4374 l_project_id   pa_project_assignments.project_id%TYPE;*/
4375 
4376 BEGIN
4377 
4378   /*OPEN get_project_id;
4379   FETCH get_project_id INTO l_project_id;
4380   CLOSE get_project_id;*/
4381 
4382   DELETE FROM pa_wf_processes
4383   WHERE  entity_key1 = to_char(p_project_id)
4384   AND    entity_key2 = to_char(p_assignment_id)
4385   AND    wf_type_code = 'ASSIGNMENT_APPROVAL';
4386 
4387 
4388   DELETE FROM pa_wf_ntf_performers
4389   WHERE wf_type_code in ('ASSIGNMENT_APPROVAL','REJECTION_FYI','APPROVAL_FYI','CANCELLATION_FYI')
4390   AND   object_id1 = p_assignment_id;
4391 
4392 END Delete_Assignment_WF_Records;
4393 
4394 ---------------------------------------------------------------------------------------------------
4395 --                               Workflow apis for mass assignment approval
4396 ---------------------------------------------------------------------------------------------------
4397 --Begin Forward declaration
4398 PROCEDURE process_approval_result
4399     ( p_project_id                  IN NUMBER
4400      ,p_mode                        IN    VARCHAR2
4401      ,p_assignment_id_tbl           IN    SYSTEM.pa_num_tbl_type
4402      ,p_approval_status_tbl         IN    SYSTEM.pa_varchar2_30_tbl_type
4403      ,p_group_id                    IN    NUMBER
4404      ,p_approver_group_id           IN    NUMBER
4405      ,p_routing_order               IN    NUMBER
4406      ,p_num_of_assignments          IN    NUMBER
4407      ,p_submitter_user_name         IN    VARCHAR2
4408      ,p_conflict_group_id           IN    NUMBER
4409      ,p_update_info_doc             IN    VARCHAR2
4410      ,p_forwarded_from              IN    VARCHAR2
4411      ,p_note_to_approvers           IN    VARCHAR2);
4412 
4413 
4414 
4415 --END Forward declarations
4416 
4417 --------------------------------------------
4418 --This API starts the mass approval workflow
4419 --It is called when a notification needs to
4420 --be sent to approver for assignment approval
4421 --This API is called in mass_assignment_approval
4422 --and in process_approval_result_wf
4423 --------------------------------------------
4424 PROCEDURE start_mass_approval_flow
4425    ( p_project_id          IN   NUMBER              := FND_API.G_MISS_NUM
4426     ,p_mode                IN   VARCHAR2            := FND_API.G_MISS_CHAR
4427     ,p_note_to_approvers   IN   VARCHAR2            := FND_API.G_MISS_CHAR
4428     ,p_forwarded_from      IN   VARCHAR2
4429     ,p_performer_user_name IN   VARCHAR2            := FND_API.G_MISS_CHAR
4430     ,p_routing_order       IN   NUMBER              := FND_API.G_MISS_NUM
4431     ,p_group_id            IN   NUMBER              := FND_API.G_MISS_NUM
4432     ,p_approver_group_id   IN   NUMBER              := FND_API.G_MISS_NUM
4433     ,p_submitter_user_name IN   VARCHAR2            := FND_API.G_MISS_CHAR
4434     ,p_update_info_doc     IN   VARCHAR2            := FND_API.G_MISS_CHAR
4435     ,p_project_name        IN   VARCHAR2
4436     ,p_project_number      IN   VARCHAR2
4437     ,p_project_manager     IN   VARCHAR2
4438     ,p_project_org         IN   VARCHAR2
4439     ,p_project_cus         IN   VARCHAR2
4440     ,p_conflict_group_id   IN   NUMBER              := FND_API.G_MISS_NUM
4441     ,x_return_status       OUT  NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
4442     ,x_msg_count           OUT  NOCOPY NUMBER --File.Sql.39 bug 4440895
4443     ,x_msg_data            OUT  NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
4444 IS
4445 
4446     l_itemkey             VARCHAR2(30);
4447     l_responsibility_id   NUMBER;
4448     l_resp_appl_id        NUMBER;
4449     l_wf_started_date     DATE;
4450     l_wf_started_by_id    NUMBER;
4451     l_return_status       VARCHAR2(1);
4452     l_error_message_code  VARCHAR2(30);
4453     l_save_threshold      NUMBER;
4454     l_msg_count           NUMBER ;
4455     l_msg_index_out   NUMBER ;
4456     l_msg_data            VARCHAR2(2000);
4457     l_wf_item_type        VARCHAR2(2000):= 'PAWFAAP'; --Assignment Approval Item type
4458     l_wf_process          VARCHAR2(2000):= 'PA_ASGMT_APPRVL_MP'; --Assignment Approval process
4459     l_err_code        NUMBER := 0;
4460     l_err_stage           VARCHAR2(2000);
4461     l_err_stack           VARCHAR2(2000);
4462 
4463     l_ntfy_apprvl_recipient_name  pa_wf_ntf_performers.user_name%TYPE;  --- Commented for 3267790 fnd_user.user_name%TYPE; --used to set NTFY_APPRVL_RECIPIENT_NAME attribute
4464     l_prev_user                   fnd_user.user_name%TYPE; --used to set FORWARDED_FROM attribute
4465     l_number_of_assignments NUMBER;
4466     l_mass_approve_url    VARCHAR2(2000); --Mass Approve page URL
4467     l_debug_mode VARCHAR2(1) := NVL(FND_PROFILE.value('PA_DEBUG_MODE'), 'N'); -- 5345171
4468 
4469 BEGIN
4470 
4471     -- Initialize the Error Stack
4472     PA_DEBUG.init_err_stack('PA_ASGMT_WFSTD.start_mass_approval_flow');
4473 
4474     --Log Message
4475     IF l_debug_mode = 'Y' THEN -- 5345171
4476         PA_DEBUG.write_log
4477         ( x_module      => 'pa.plsql.PA_ASGMT_WFSTD.start_mass_approval_flow.begin'
4478          ,x_msg         => 'Beginning of mass approval workflow api'
4479          ,x_log_level   => 1);
4480     END IF;
4481 
4482     -- Initialize the return status to success
4483     x_return_status := FND_API.G_RET_STS_SUCCESS;
4484 
4485     --Clear the global PL/SQL message table
4486     FND_MSG_PUB.initialize;
4487 
4488     log_message('Inside Start mass approval flow: 0');
4489     log_message('Value of updated info doc:' || p_update_info_doc);
4490 
4491     -- Create the unique item key to launch WF with
4492     SELECT pa_prm_wf_item_key_s.nextval
4493     INTO   l_itemkey
4494     FROM   dual;
4495 
4496     l_wf_started_by_id  := FND_GLOBAL.user_id;
4497     l_responsibility_id := FND_GLOBAL.resp_id;
4501                                , resp_id      => l_responsibility_id
4498     l_resp_appl_id      := FND_GLOBAL.resp_appl_id;
4499 
4500     FND_GLOBAL.Apps_Initialize ( user_id      => l_wf_started_by_id
4502                                , resp_appl_id => l_resp_appl_id );
4503 
4504     -- Setting thresold value to run the process in background
4505     l_save_threshold    := wf_engine.threshold;
4506     wf_engine.threshold := -1;
4507 
4508     -----------------------------------
4509     --Getting the current approver name
4510     -----------------------------------
4511     BEGIN
4512         SELECT user_name
4513         INTO   l_ntfy_apprvl_recipient_name
4514         FROM   pa_wf_ntf_performers
4515         WHERE  group_id          = p_group_id
4516         AND    approver_group_id = p_approver_group_id
4517         AND    routing_order     = p_routing_order
4518         AND    rownum            = 1;
4519     EXCEPTION
4520         WHEN NO_DATA_FOUND THEN
4521             null;
4522     END;
4523 
4524     log_message('l_ntfy_apprvl_recipient_name:' || l_ntfy_apprvl_recipient_name);
4525     log_message('Inside Start mass approval flow: 1');
4526 
4527     ----------------------------------------------------------
4528     --Getting the Forwared From (Submitter/previous approver)
4529     ----------------------------------------------------------
4530     IF p_forwarded_from IS NULL THEN
4531        l_prev_user := p_submitter_user_name;
4532     ELSE
4533        l_prev_user := p_forwarded_from;
4534     END IF;
4535 
4536     log_message('Inside Start mass approval flow: 2');
4537 
4538     --------------------------------------------
4539     --Getting number of assignments for approval
4540     --------------------------------------------
4541     BEGIN
4542         SELECT count(object_id1)
4543         INTO   l_number_of_assignments
4544         FROM   pa_wf_ntf_performers pf,
4545                pa_project_assignments asmt
4546         WHERE  pf.group_id          = p_group_id
4547         AND    pf.approver_group_id = p_approver_group_id
4548         AND    pf.routing_order     = p_routing_order
4549         AND    pf.object_id1 = asmt.assignment_id
4550         AND    asmt.apprvl_status_code <> PA_ASSIGNMENT_APPROVAL_PUB.g_rejected;
4551     EXCEPTION
4552         WHEN NO_DATA_FOUND THEN
4553             l_number_of_assignments := 0;
4554     END;
4555 
4556     log_message('Inside Start mass approval flow: 3');
4557     log_message('Conflict group_id:' || p_conflict_group_id);
4558 
4559     IF l_number_of_assignments > 0 THEN
4560     ----------------------------------
4561     --Constructing mass approve URL
4562     ---------------------------------
4563     l_mass_approve_url := 'JSP:/OA_HTML/OA.jsp?akRegionCode=PA_MASS_APPR_LAYOUT' ||
4564 '&akRegionApplicationId=275' ||
4565 '&paProjectId='||
4566 p_project_id || '&paGroupId=' ||
4567 p_group_id || '&paApproverGroupId=' ||
4568 p_approver_group_id ||
4569 '&paRoutingOrder=' || p_routing_order ||
4570 '&paMode=' || p_mode || '&paNotificationId=' ||
4571 '&#NID' || '&paItemKey=' || l_itemkey ||
4572 '&paSubmitterUserName=' || p_submitter_user_name ||
4573 '&paConflictGroupId=' || p_conflict_group_id || '&addBreadCrumb=RP';
4574 
4575     log_message('l_mass_approve_url:' || l_mass_approve_url);
4576 
4577     -- Create the WF process
4578     wf_engine.CreateProcess
4579         ( ItemType => l_wf_item_type
4580         , ItemKey  => l_itemkey
4581         , process  => l_wf_process );
4582 
4583     log_message('Inside Start mass approval flow : 4');
4584 
4585     ----------------------------------------------------------------
4586     --Set all the required workflow attributes and start the workflow
4587     -----------------------------------------------------------------
4588     --set group_id
4589     wf_engine.SetItemAttrNumber
4590         ( itemtype => l_wf_item_type
4591         , itemkey  => l_itemkey
4592         , aname    => 'GROUP_ID'
4593         , avalue   => p_group_id);
4594 
4595     wf_engine.SetItemAttrNumber
4596         ( itemtype => l_wf_item_type
4597         , itemkey  => l_itemkey
4598         , aname    => 'APPROVER_GROUP_ID'
4599         , avalue   => p_approver_group_id);
4600 
4601     wf_engine.SetItemAttrNumber
4602         ( itemtype => l_wf_item_type
4603         , itemkey  => l_itemkey
4604         , aname    => 'ROUTING_ORDER'
4605         , avalue   => p_routing_order);
4606 
4607     --This is required for check_notiifcation_completed API logic
4608     wf_engine.SetItemAttrText
4609         ( itemtype => l_wf_item_type
4610         , itemkey  => l_itemkey
4611         , aname    => 'MODE'
4612         , avalue   => p_mode);
4613 
4614     wf_engine.SetItemAttrText
4615         ( itemtype => l_wf_item_type
4616         , itemkey  => l_itemkey
4617         , aname    => 'SUBMITTER_UNAME'
4618         , avalue   => p_submitter_user_name);
4619 
4620     wf_engine.SetItemAttrDocument
4621         ( itemtype => l_wf_item_type
4622         , itemkey  => l_itemkey
4623         , aname    => 'UPDATED_INFO_DOC'
4624         , documentid   => p_update_info_doc  );
4625 
4626     --Set approval type
4627     wf_engine.SetItemAttrText
4628         ( itemtype => l_wf_item_type
4629         , itemkey  => l_itemkey
4630         , aname    => 'APPROVAL_TYPE'
4631         , avalue   => PA_ASGMT_WFSTD.G_MASS_APPROVAL  );
4632 
4633     --Setting Mass Assignments details
4634     wf_engine.SetItemAttrText
4635         ( itemtype => l_wf_item_type
4636         , itemkey  => l_itemkey
4637         , aname    => 'NTFY_APPRVL_RECIPIENT_NAME'
4638         , avalue   => l_ntfy_apprvl_recipient_name  );
4639 
4640     wf_engine.SetItemAttrText
4641         ( itemtype => l_wf_item_type
4642         , itemkey  => l_itemkey
4643         , aname    => 'FORWARDED_FROM'
4644         , avalue   => l_prev_user  );
4645 
4646     wf_engine.SetItemAttrText
4647         ( itemtype => l_wf_item_type
4648         , itemkey  => l_itemkey
4649         , aname    => 'NOTE_TO_APPROVER'
4650         , avalue   => p_note_to_approvers  );
4651 
4652     wf_engine.SetItemAttrText
4653         ( itemtype => l_wf_item_type
4654         , itemkey  => l_itemkey
4655         , aname    => 'NUMBER_OF_ASSIGNMENTS'
4656         , avalue   => l_number_of_assignments  );
4657 
4658     wf_engine.SetItemAttrText
4659         ( itemtype => l_wf_item_type
4660         , itemkey  => l_itemkey
4661         , aname    => 'MASS_APPROVE_URL_INFO'
4662         , avalue   => l_mass_approve_url );
4663 
4664     --Setting the Upadate info document
4665      wf_engine.SetItemAttrDocument
4666         ( itemtype => l_wf_item_type
4667         , itemkey  => l_itemkey
4668         , aname    => 'UPDATED_INFO_DOC'
4669         , documentid   => p_update_info_doc );
4670 
4671     --Setting Project Details
4672     IF p_project_manager IS NOT NULL THEN
4673         wf_engine.SetItemAttrText
4674             ( itemtype => l_wf_item_type
4675             , itemkey  => l_itemkey
4676             , aname    => 'PROJECT_MANAGER_NAME'
4677             , avalue   => p_project_manager );
4678     END IF;
4679 
4680     wf_engine.SetItemAttrNumber
4681         ( itemtype => l_wf_item_type
4682          , itemkey => l_itemkey
4683          , aname   => 'PROJECT_ID'
4684          , avalue  => p_project_id);
4685 
4686     wf_engine.SetItemAttrText
4687         ( itemtype => l_wf_item_type
4688         , itemkey  => l_itemkey
4689         , aname    => 'PROJECT_NUMBER'
4690         , avalue   => p_project_number);
4691 
4692     wf_engine.SetItemAttrText
4693         ( itemtype => l_wf_item_type
4694          , itemkey => l_itemkey
4695          , aname   => 'PROJECT_NAME'
4696          , avalue  => p_project_name);
4697 
4698     wf_engine.SetItemAttrText
4699         ( itemtype => l_wf_item_type
4700         , itemkey  => l_itemkey
4701         , aname    => 'PROJECT_ORGANIZATION'
4702         , avalue   => p_project_org);
4703 
4704    wf_engine.SetItemAttrText
4705         ( itemtype => l_wf_item_type
4706         , itemkey  => l_itemkey
4707         , aname    => 'FROM_ROLE_VALUE'
4708         , avalue   => p_submitter_user_name); --Added for bug 4535838
4709 
4710     -- Set the customer name if it is not null
4711     IF p_project_cus IS NOT NULL THEN
4712         wf_engine.SetItemAttrText
4713             ( itemtype => l_wf_item_type
4714             , itemkey  => l_itemkey
4715             , aname    => 'PROJECT_CUSTOMER'
4716             , avalue   => p_project_cus);
4717     END IF;
4718 
4719     log_message('Starting process');
4720     -----------------------------
4721     --Start the workflow process
4722     -----------------------------
4723     wf_engine.StartProcess ( itemtype => l_wf_item_type
4724                             ,itemkey  => l_itemkey );
4725 
4726     PA_WORKFLOW_UTILS.Insert_WF_Processes
4727         (p_wf_type_code        => 'MASS_ASSIGNMENT_APPROVAL'
4728         ,p_item_type           => l_wf_item_type
4729         ,p_item_key            => l_itemkey
4730         ,p_entity_key1         => to_char(p_project_id)
4731         ,p_entity_key2         => to_char(p_group_id)
4732         ,p_description         => NULL
4733         ,p_err_code            => l_err_code
4734         ,p_err_stage           => l_err_stage
4735         ,p_err_stack           => l_err_stack );
4736 
4737     END IF; --l_num_of_assignments > 0
4738 
4739     --Setting the original value
4740     wf_engine.threshold := l_save_threshold;
4741 
4742 EXCEPTION
4743     WHEN OTHERS THEN
4744 
4745          --Setting the original value
4746          wf_engine.threshold := l_save_threshold;
4747 
4748          -- Set the excetption Message and the stack
4749          FND_MSG_PUB.add_exc_msg
4750              ( p_pkg_name       => 'PA_ASGMT_WFSTD.start_mass_Approval_flow'
4751               ,p_procedure_name => PA_DEBUG.G_Err_Stack );
4752 
4753          x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4754          RAISE;
4755 END start_mass_approval_flow;
4756 
4757 
4758 /** This API starts the FYI notifications to indicate if
4759   * asignments have been approved or rejected. It sends the following notification.
4760   *     1. Resource FYI for every assignment approved/rejected
4761   */
4762 PROCEDURE process_res_fyi_notification
4763     ( p_project_id           IN   NUMBER    := FND_API.G_MISS_NUM
4764      ,p_assignment_id        IN   NUMBER    := FND_API.G_MISS_NUM
4765      ,p_mode                 IN   VARCHAR2
4766      ,p_project_name         IN   VARCHAR2
4767      ,p_project_number       IN   VARCHAR2
4768      ,p_project_manager      IN   VARCHAR2
4769      ,p_project_org          IN   VARCHAR2
4770      ,p_project_cus          IN   VARCHAR2
4771      ,p_conflict_group_id    IN   NUMBER    := NULL
4772      ,x_return_status        OUT  NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
4773      ,x_msg_count            OUT  NOCOPY NUMBER --File.Sql.39 bug 4440895
4774      ,x_msg_data             OUT  NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
4775 IS
4776 
4777     l_itemkey             VARCHAR2(30);
4778     l_responsibility_id   NUMBER;
4779     l_resp_appl_id        NUMBER;
4780     l_wf_started_date     DATE;
4781     l_wf_started_by_id    NUMBER;
4782     l_return_status       VARCHAR2(1);
4783     l_error_message_code  VARCHAR2(30);
4784     x_error_message_code  VARCHAR2(30);
4785     l_save_threshold      NUMBER;
4786     l_msg_count           NUMBER ;
4787     l_msg_index_out   NUMBER ;
4788     l_msg_data            VARCHAR2(2000);
4789     l_wf_item_type        VARCHAR2(2000):= 'PARMAAP'; --Assignment Approval Item type
4790     l_wf_process          VARCHAR2(2000):= 'PA_MASS_APRVL_RES_FP';
4791     l_err_code        NUMBER := 0;
4792     l_err_stage       VARCHAR2(2000);
4793     l_err_stack           VARCHAR2(2000);
4794     l_display_name        wf_users.display_name%TYPE;  ---VARCHAR2(200); Changed for bug 3267790
4795     l_approver_name       VARCHAR2(200);
4796     l_resource_id         NUMBER;
4797     --l_res_user_name       VARCHAR2(200);
4798     l_msg_subj_code       VARCHAR2(30);
4799     l_msg_desc_code       VARCHAR2(30);
4800     l_msg_subj_text       VARCHAR2(2000);
4801     l_msg_desc_text       VARCHAR2(2000);
4802     l_resolve_conflicts_by_rmvl  VARCHAR2(1);
4803     l_view_conflict_url   VARCHAR2(2000);
4804 
4805     l_approval_nf_rects_tbl  PA_CLIENT_EXTN_ASGMT_WF.Users_List_Tbltyp ;
4806     l_out_approval_nf_rects_tbl  PA_CLIENT_EXTN_ASGMT_WF.Users_List_Tbltyp ;
4807     l_number_of_recipients  NUMBER := 0;
4808     l_approval_nf_rects_rec  PA_CLIENT_EXTN_ASGMT_WF.Users_List_Rectyp ;
4809     l_ntfy_apprvl_recipient_name wf_users.name%TYPE; ---VARCHAR2(240); Changed for bug 3267790
4810     l_ntfy_apprvl_rect_person_id NUMBER := 0;
4811     l_ntfy_apprvl_rect_type VARCHAR2(30);
4812     l_notification_type VARCHAR2(30);
4813 
4814     l_asgmt_details_url      VARCHAR2(600);
4815     l_resource_schedules_url VARCHAR2(600);
4816     l_reapproval_flag  VARCHAR2(1);
4817     l_aprvl_status pa_project_assignments.apprvl_status_code%TYPE;
4818     l_override_basis_name VARCHAR2(80) := NULL;
4819     l_resource_start_date  DATE;
4820 
4821     CURSOR l_prev_asgmt_info_csr (l_assignment_id IN NUMBER)
4822     IS
4823     SELECT assignment_effort prev_effort,
4824           (trunc(end_date) -
4825           (trunc(start_date)+1)) prev_duration
4826     FROM  pa_assignments_history
4827     WHERE assignment_id               = l_assignment_id
4828     AND   nvl(last_approved_flag,'N') = 'Y';
4829 
4830     CURSOR l_assignments_csr IS
4831     SELECT
4832        ppa.assignment_name,
4833        ppa.assignment_effort,
4834        ppa.additional_information,
4835        ppa.description,
4836        ppa.start_date,
4837        ppa.end_date,
4838        ppa.apprvl_status_code,
4839        ppa.revenue_bill_rate,
4840        ppa.revenue_currency_code,
4841        ppa.bill_rate_override,
4842        ppa.bill_rate_curr_override,
4843        ppa.markup_percent_override,
4844        ppa.fcst_tp_amount_type_name,
4845        ppa.tp_rate_override,
4846        ppa.tp_currency_override,
4847        ppa.tp_calc_base_code_override,
4848        ppa.tp_percent_applied_override,
4849        ppa.work_type_name,
4850        ppa.transfer_price_rate,   -- Added for bug 3051110
4851        ppa.transfer_pr_rate_curr
4852     FROM pa_project_assignments_v ppa
4853     WHERE assignment_id = p_assignment_id;
4854 
4855     CURSOR csr_get_override_basis_name (p_override_basis_code IN VARCHAR2) IS
4856     SELECT plks.meaning
4857     FROM   pa_lookups plks
4858     WHERE  plks.lookup_type = 'CC_MARKUP_BASE_CODE'
4859     AND    plks.lookup_code = p_override_basis_code;
4860 
4861     -- Bug 5362698 - Get the name from HR instead of pa_resources_denorm so
4862     -- that the latest name is obtained.
4863     /*
4864     CURSOR l_resource_csr (l_resource_id IN NUMBER, l_start_date IN DATE) IS
4865     SELECT res.resource_name,
4866            hr.name
4867     FROM   pa_resources_denorm res,
4868            hr_all_organization_units hr
4869     WHERE  res.resource_id = l_resource_id
4870     AND    hr.organization_id = res.resource_organization_id
4871     AND    l_start_date between resource_effective_start_date and resource_effective_end_date;
4872     */
4873 
4874     CURSOR l_resource_csr(l_resource_id IN NUMBER, p_start_date IN DATE) IS
4875     SELECT per.full_name resource_name,
4876            hou.name
4877     FROM   per_people_f per,
4878            per_assignments_f assign,
4879            hr_all_organization_units hou,
4880            pa_resource_txn_attributes rta
4881     WHERE  rta.resource_id = l_resource_id
4882     AND    rta.person_id = per.person_id
4883     AND    rta.person_id = assign.person_id
4884     AND    assign.primary_flag = 'Y'
4885     AND    assign.assignment_type in ('E','C')
4886     AND    hou.organization_id = assign.organization_id
4887     AND    p_start_date BETWEEN assign.effective_start_date
4888                             AND assign.effective_end_date
4889     AND    p_start_date BETWEEN per.effective_start_date
4890                             AND per.effective_end_date;
4891 
4892     l_prev_asgmt_info_rec l_prev_asgmt_info_csr%ROWTYPE;
4893     l_assignments_rec l_assignments_csr%ROWTYPE;
4894     l_resource_rec l_resource_csr%ROWTYPE;
4895     l_debug_mode VARCHAR2(1) := NVL(FND_PROFILE.value('PA_DEBUG_MODE'), 'N'); -- 5345171
4896 
4897 BEGIN
4898 
4899     -- Initialize the Error Stack
4900     PA_DEBUG.init_err_stack('PA_ASGMT_WFSTD.process_res_fyi_notification');
4901 
4902     --Log Message
4903     IF l_debug_mode = 'Y' THEN -- 5345171
4904         PA_DEBUG.write_log
4905         ( x_module      => 'pa.plsql.PA_ASGMT_WFSTD.process_res_fyi_notification.begin'
4906          ,x_msg         => 'Beginning of mass fyi workflow api'
4907          ,x_log_level   => 1);
4908     END IF;
4909     log_message('Inside process res mgr');
4910 
4911     -- Initialize the return status to success
4912     x_return_status := FND_API.G_RET_STS_SUCCESS;
4913 
4914     --Clear the global PL/SQL message table
4915     FND_MSG_PUB.initialize;
4916     x_msg_count := 0;
4917 
4918     ---------------------------------
4919     --Set the pending approval flag
4920     ---------------------------------
4921     Maintain_wf_pending_flag
4922         (p_assignment_id => p_assignment_id,
4923          p_mode          => 'APPROVAL_PROCESS_COMPLETED') ;
4924 
4925     log_message('After Maintain pending flag for assignment id:' || p_assignment_id);
4926 
4927     ---------------------------
4928     --Set the mass wf flag
4929     ---------------------------
4930     UPDATE pa_project_assignments
4931     SET    mass_wf_in_progress_flag = 'N'
4932     WHERE  assignment_id = p_assignment_id;
4933 
4934     log_message('After setting mass wf flag');
4935 
4936     SELECT resource_id
4937     INTO   l_resource_id
4938     FROM   pa_project_assignments
4939     WHERE  assignment_id = p_assignment_id;
4940 
4941     log_message('After getting resource_id:'|| l_resource_id);
4942 
4943    --------------------------------------------------------------
4944    --Call Client extension to get the resource recepient(s)
4945    --------------------------------------------------------------
4946    --Getting recepients approval type
4947     SELECT apprvl_status_code
4948     INTO   l_aprvl_status
4949     FROM   pa_project_assignments
4950     WHERE  assignment_id = p_assignment_id;
4951 
4952     log_message('After getting recepients approval type:' || l_aprvl_status);
4953 
4954     IF l_aprvl_status = PA_ASSIGNMENT_APPROVAL_PUB.g_approved THEN
4955         l_notification_type := 'APPROVAL_FYI';
4956     ELSE l_notification_type := 'REJECTION_FYI';
4957     END IF;
4958 
4959     --Getting recepients person_id
4960     SELECT res.person_id
4961     INTO   l_ntfy_apprvl_rect_person_id
4962     FROM   pa_resources_denorm res
4963     WHERE  res.resource_id    = l_resource_id
4964     AND    rownum             = 1;
4965 
4966     log_message('After getting person_id:' || l_ntfy_apprvl_rect_person_id);
4967 
4968     --Getting recepients fnd user name
4969     wf_directory.getusername
4970         (p_orig_system    => 'PER'
4971         ,p_orig_system_id => l_ntfy_apprvl_rect_person_id
4972         ,p_name           => l_ntfy_apprvl_recipient_name
4973         ,p_display_name   => l_display_name);
4974 
4975    l_ntfy_apprvl_rect_type := 'RESOURCE';
4976 
4977    log_message('After getting l_ntfy_apprvl_recipient_name:' || l_ntfy_apprvl_recipient_name);
4978 
4979    --ceating the recipient in table
4980    IF l_ntfy_apprvl_recipient_name IS NOT NULL THEN
4981               l_approval_nf_rects_rec.User_Name := l_ntfy_apprvl_recipient_name;
4982               l_approval_nf_rects_rec.Person_id := l_ntfy_apprvl_rect_person_id;
4983               l_approval_nf_rects_rec.Type      := l_ntfy_apprvl_rect_type;
4984               --l_approval_nf_rects_rec.Routing_Order :=  ?;
4985               l_approval_nf_rects_tbl(1)        := l_approval_nf_rects_rec;
4986 
4987 
4988    log_message('Before Calling client extension to get all recipients');
4989    log_message('Recipient count:' || l_approval_nf_rects_tbl.COUNT);
4990 
4991    --Calling client extension to get all recipients
4992    PA_CLIENT_EXTN_ASGMT_WF.Generate_NF_Recipients
4993        (p_assignment_id             => p_assignment_id
4994        ,p_project_id                => p_project_id
4995        ,p_notification_type         => l_notification_type
4996        ,p_in_list_of_recipients     => l_approval_nf_rects_tbl
4997        ,x_out_list_of_recipients    => l_out_approval_nf_rects_tbl
4998        ,x_number_of_recipients      => l_number_of_recipients );
4999 
5000    log_message('After Calling client extension');
5001    log_message('Recipient count:' || l_out_approval_nf_rects_tbl.COUNT);
5002 
5003    IF (l_out_approval_nf_rects_tbl.COUNT > 0 ) THEN --GSI Bug 7430471
5004 
5005     --Getting the out recipient record
5006     l_approval_nf_rects_rec := l_out_approval_nf_rects_tbl(1);
5007 
5008     l_ntfy_apprvl_recipient_name := l_approval_nf_rects_rec.User_Name;
5009     l_ntfy_apprvl_rect_person_id := l_approval_nf_rects_rec.Person_id;
5010     l_ntfy_apprvl_rect_type      := l_approval_nf_rects_rec.Type;
5011 
5012     log_message('After getting out recipient recoed');
5013 
5014     --------------------------------------
5015     --Start Resource Notification workflow
5016     --------------------------------------
5017     l_wf_started_by_id  := FND_GLOBAL.user_id;
5018     l_responsibility_id := FND_GLOBAL.resp_id;
5019     l_resp_appl_id      := FND_GLOBAL.resp_appl_id;
5020 
5021     FND_GLOBAL.Apps_Initialize ( user_id      => l_wf_started_by_id
5022                                , resp_id      => l_responsibility_id
5023                                , resp_appl_id => l_resp_appl_id );
5024 
5025     -- Setting thresold value to run the process in background
5026     l_save_threshold    := wf_engine.threshold;
5027     wf_engine.threshold := -1;
5028 
5029     log_message('RESOURCE PERSON ID:' || l_ntfy_apprvl_rect_person_id);
5030     log_message('RESOURCE UNAME:' || l_ntfy_apprvl_recipient_name);
5031 
5032     ----------------------------------------------------------------
5033     --Getting all local variables required for workflow attributes
5034     ---------------------------------------------------------------
5035     OPEN l_assignments_csr;
5036     FETCH l_assignments_csr INTO l_assignments_rec;
5037 
5038     IF l_assignments_csr%NOTFOUND THEN
5039        x_return_status := FND_API.G_RET_STS_ERROR;
5040            pa_utils.add_message (p_app_short_name  => 'PA',
5041                                  p_msg_name        => 'PA_INVALID_ASMGT_ID');
5042        x_msg_count := x_msg_count + 1;
5043 
5044         END IF;
5045     CLOSE l_assignments_csr;
5046 
5047     l_asgmt_details_url := 'JSP:/OA_HTML/OA.jsp?akRegionApplicationId=275&akRegionCode=PA_ASMT_LAYOUT' ||
5048                            '&paCalledPage=ProjStaffedAsmt&paAssignmentId='||p_assignment_id||'&addBreadCrumb=RP';
5049 
5050     l_resource_schedules_url := 'JSP:/OA_HTML/OA.jsp?akRegionApplicationId=275&akRegionCode=PA_VIEW_RESOURCE_LAYOUT' ||
5051                                 '&paResourceId='||l_resource_id||'&addBreadCrumb=RP';
5052 
5053     OPEN l_prev_asgmt_info_csr (p_assignment_id) ;
5054     FETCH l_prev_asgmt_info_csr INTO
5055           l_prev_asgmt_info_rec;
5056     IF    l_prev_asgmt_info_csr%NOTFOUND THEN
5057           l_reapproval_flag := 'N';
5058     ELSE
5059           l_reapproval_flag := 'Y';
5060     END IF;
5061     CLOSE l_prev_asgmt_info_csr;
5062 
5063     -- Bug 5362698 - use sysdate to get the name so that the latest name
5064     -- is obtained.
5065     -- Need to get the Max of StartDate or the Sysdate for future hire. Fix
5066     -- for Bug# 7585927.
5067     if(l_assignments_rec.start_date > sysdate) then
5068       l_resource_start_date := l_assignments_rec.start_date;
5069     else
5070       l_resource_start_date := sysdate;
5071     end if;
5072     OPEN l_resource_csr(l_resource_id, l_resource_start_date);
5073     FETCH l_resource_csr INTO l_resource_rec;
5074 
5075     IF l_resource_csr%NOTFOUND THEN
5076         x_return_status := FND_API.G_RET_STS_ERROR;
5077         pa_utils.add_message (p_app_short_name => 'PA',
5078                               p_msg_name       => 'PA_INVALID_PERSON_ID');
5079         x_msg_count := x_msg_count + 1;
5080     END IF;
5081     CLOSE l_resource_csr;
5082 
5083      -- Create the unique item key to launch WF with
5084     SELECT pa_prm_wf_item_key_s.nextval
5085     INTO   l_itemkey
5086     FROM   dual;
5087 
5088      -- Create the WF process
5089     wf_engine.CreateProcess
5090         ( ItemType => l_wf_item_type
5091         , ItemKey  => l_itemkey
5092         , process  => l_wf_process );
5093 
5094     ----------------------------------------------------------------
5095     -- Set subject, description and overcommiment conflict detail URL
5096     ---------------------------------------------------------------
5097     IF (l_assignments_rec.apprvl_status_code = PA_ASSIGNMENT_APPROVAL_PUB.g_approved) THEN
5098 
5099        -- If there is no overcommitment conflict
5100        IF (p_conflict_group_id IS NULL) THEN
5101           l_msg_subj_code := 'PA_NFSUBJ_ASGMT_APPROVED';
5102           l_msg_desc_code := 'PA_NFDESC_ASGMT_APPROVED';
5103 
5104        -- If there is any overcommitment conflict
5105        ELSE
5106           PA_SCHEDULE_PVT.has_resolved_conflicts_by_rmvl
5107                                   ( p_conflict_group_id         => p_conflict_group_id
5108                                   , p_assignment_id             => p_assignment_id
5109                                   , x_resolve_conflicts_by_rmvl => l_resolve_conflicts_by_rmvl
5110                                   , x_return_status             => l_return_status
5111                                   , x_msg_count                 => l_msg_count
5112                                   , x_msg_data                  => l_msg_data);
5113           IF (l_resolve_conflicts_by_rmvl = 'Y') THEN
5114          l_msg_subj_code := 'PA_NFSUBJ_ASGMT_APPR_CONF_REM';
5115              l_msg_desc_code := 'PA_NFDESC_ASGMT_APPR_CONF_REM';
5116           ELSE
5117              l_msg_subj_code := 'PA_NFSUBJ_ASGMT_APPR_KP_CONF';
5118              l_msg_desc_code := 'PA_NFDESC_ASGMT_APPR_KP_CONF';
5119           END IF;
5120        END IF; -- If (p_conflict_group_id IS NULL)
5121     ELSE
5122        l_msg_subj_code := 'PA_NFSUBJ_ASGMT_REJECTED';
5123        l_msg_desc_code := 'PA_NFDESC_ASGMT_REJECTED';
5124     END IF; -- IF (l_assignments_rec.apprvl_status_code = PA_ASSIGNMENT_APPROVAL_PUB.g_approved)
5125 
5126     -- get the message from fnd messages for subject and description
5127     FND_MESSAGE.SET_NAME ('PA',l_msg_subj_code);
5128     l_msg_subj_text := FND_MESSAGE.GET;
5129     FND_MESSAGE.SET_NAME ('PA',l_msg_desc_code);
5130     l_msg_desc_text := FND_MESSAGE.GET;
5131 
5132     -- set resource overcommitment url
5133     l_view_conflict_url := 'JSP:/OA_HTML/OA.jsp?akRegionApplicationId=275&akRegionCode='
5134                         || 'PA_RES_OVERCOMMITMENT_LAYOUT&paAssignmentId=' || p_assignment_id
5135                         || '&paConflictGroupId=' || p_conflict_group_id
5136                         || '&paCallingPage=Default&addBreadCrumb=RP';
5137 
5138     log_message('Setting item attributes Inside process res mgr');
5139 
5140     ------------------------------------------------------------
5141     --Set the item attributes required for resource notification
5142     ------------------------------------------------------------
5143     -- setting subject, description, conflict URL for overcommitment
5144     wf_engine.SetItemAttrText
5145         ( itemtype => l_wf_item_type
5146         , itemkey  => l_itemkey
5147         , aname    => 'MSG_SUBJECT'
5148         , avalue   => l_msg_subj_text);
5149 
5150      wf_engine.SetItemAttrText
5151         ( itemtype => l_wf_item_type
5152         , itemkey  => l_itemkey
5153         , aname    => 'MSG_DESCRIPTION'
5154         , avalue   => l_msg_desc_text );
5155 
5156 --    IF (l_assignments_rec.apprvl_status_code = PA_ASSIGNMENT_APPROVAL_PUB.g_approved AND
5157 --        p_conflict_group_id IS NOT NULL) THEN
5158           wf_engine.SetItemAttrText
5159               ( itemtype => l_wf_item_type
5160               , itemkey  => l_itemkey
5161               , aname    => 'CONFLICT_URL'
5162               , avalue   => l_view_conflict_url );
5163 --    END IF;
5164 
5165     --Setting Resource attributes
5166     wf_engine.SetItemAttrText
5167         ( itemtype => l_wf_item_type
5168         , itemkey  => l_itemkey
5169         , aname    => 'NTFY_FYI_USER_NAME'
5170         , avalue   => l_ntfy_apprvl_recipient_name);
5171 
5172      wf_engine.SetItemAttrText
5173         ( itemtype => l_wf_item_type
5174         , itemkey  => l_itemkey
5175         , aname    => 'RESOURCE_NAME'
5176         , avalue   => l_resource_rec.resource_name );
5177 
5178     wf_engine.SetItemAttrText
5179         ( itemtype => l_wf_item_type
5180         , itemkey  => l_itemkey
5181         , aname    => 'RESOURCE_ORGANIZATION'
5182         , avalue   => l_resource_rec.name );
5183 
5184 
5185     --Setting URL information
5186     wf_engine.SetItemAttrText
5187         ( itemtype => l_wf_item_type
5188         , itemkey  => l_itemkey
5189         , aname    => 'ASSIGNMENT_DETAILS_URL'
5190         , avalue   => l_asgmt_details_url );
5191 
5192     wf_engine.SetItemAttrText
5193     ( itemtype => l_wf_item_type
5194         , itemkey  => l_itemkey
5195         , aname    => 'RESOURCE_SCHEDULES_URL'
5196         , avalue   => l_resource_schedules_url );
5197 
5198     --Setting assignment attributes
5199     IF l_reapproval_flag = 'Y' THEN
5200            wf_engine.SetItemAttrNumber
5201                     ( itemtype => l_wf_item_type
5202                     , itemkey => l_itemkey
5203                     , aname   => 'PREV_DURATION'
5204                     , avalue  => l_prev_asgmt_info_rec.prev_duration );
5205 
5206            wf_engine.SetItemAttrNumber
5207                    ( itemtype => l_wf_item_type
5208                     ,itemkey  => l_itemkey
5209                     , aname   => 'PREV_EFFORT'
5210                     , avalue  => l_prev_asgmt_info_rec.prev_effort );
5211     END IF;
5212 
5213            -- Start Additions by RM for bug 2274426
5214            wf_engine.SetItemAttrNumber
5215                                ( itemtype => l_wf_item_type
5216                                , itemkey => l_itemkey
5217                                , aname => 'REVENUE_BILL_RATE'
5218                                , avalue => l_assignments_rec.revenue_bill_rate
5219                                );
5220            wf_engine.SetItemAttrText
5221                             ( itemtype => l_wf_item_type
5222                             , itemkey => l_itemkey
5223                             , aname => 'REVENUE_BILL_RATE_CURR'
5224                             , avalue => l_assignments_rec.revenue_currency_code
5225                             );
5226            wf_engine.SetItemAttrNumber
5227                                ( itemtype => l_wf_item_type
5228                                , itemkey => l_itemkey
5229                                , aname => 'BILL_RATE_OVERRIDE'
5230                                , avalue => l_assignments_rec.bill_rate_override
5231                                );
5232            wf_engine.SetItemAttrText
5233                           ( itemtype => l_wf_item_type
5234                           , itemkey => l_itemkey
5235                           , aname => 'BILL_RATE_OVERRIDE_CURR'
5236                           , avalue => l_assignments_rec.bill_rate_curr_override
5237                           );
5238            IF l_assignments_rec.markup_percent_override IS NOT NULL THEN
5239               wf_engine.SetItemAttrText
5240                           ( itemtype => l_wf_item_type
5241                           , itemkey => l_itemkey
5242                           , aname => 'MARKUP_PCT_OVERRIDE'
5243                           , avalue => to_char(l_assignments_rec.markup_percent_override)||'%'
5244                           );
5245            ELSE
5246                wf_engine.SetItemAttrText
5247                           ( itemtype => l_wf_item_type
5248                           , itemkey => l_itemkey
5249                           , aname => 'MARKUP_PCT_OVERRIDE'
5250                           , avalue => to_char(l_assignments_rec.markup_percent_override)
5251                           );
5252            END IF;
5253            wf_engine.SetItemAttrText
5254                           ( itemtype => l_wf_item_type
5255                           , itemkey => l_itemkey
5256                           , aname => 'TP_AMT_TYPE_NAME'
5257                           , avalue => l_assignments_rec.fcst_tp_amount_type_name
5258                           );
5259            wf_engine.SetItemAttrNumber
5260                           ( itemtype => l_wf_item_type
5261                           , itemkey => l_itemkey
5262                           , aname => 'TP_RATE_OVERRIDE'
5263                           , avalue => l_assignments_rec.tp_rate_override
5264                           );
5265            wf_engine.SetItemAttrText
5266                           ( itemtype => l_wf_item_type
5267                           , itemkey => l_itemkey
5268                           , aname => 'TP_RATE_OVERRIDE_CURR'
5269                           , avalue => l_assignments_rec.tp_currency_override
5270                           );
5271            IF l_assignments_rec.tp_calc_base_code_override IS NOT NULL THEN
5272               open csr_get_override_basis_name(l_assignments_rec.tp_calc_base_code_override);
5273               fetch csr_get_override_basis_name into l_override_basis_name;
5274               close csr_get_override_basis_name;
5275            END IF;
5276            wf_engine.SetItemAttrText
5277                           ( itemtype => l_wf_item_type
5278                           , itemkey => l_itemkey
5279                           , aname => 'OVERRIDE_BASIS_NAME'
5280                           , avalue => l_override_basis_name
5281                           );
5282            IF l_assignments_rec.tp_percent_applied_override IS NOT NULL THEN
5283               IF l_override_basis_name IS NOT NULL THEN
5284                  wf_engine.SetItemAttrText
5285                      ( itemtype => l_wf_item_type
5286                      , itemkey => l_itemkey
5287                      , aname => 'TP_PCT_APPLIED_OVERRIDE'
5288                      , avalue => ', '||to_char(l_assignments_rec.tp_percent_applied_override)||'%'
5289                      );
5290               ELSE
5291                  wf_engine.SetItemAttrText
5292                      ( itemtype => l_wf_item_type
5293                      , itemkey => l_itemkey
5294                      , aname => 'TP_PCT_APPLIED_OVERRIDE'
5295                      , avalue => to_char(l_assignments_rec.tp_percent_applied_override)||'%'
5296                      );
5297               END IF;
5298            ELSE
5299               wf_engine.SetItemAttrText
5300                      ( itemtype => l_wf_item_type
5301                      , itemkey => l_itemkey
5302                      , aname => 'TP_PCT_APPLIED_OVERRIDE'
5303                      , avalue => to_char(l_assignments_rec.tp_percent_applied_override)
5304                      );
5305            END IF;
5306            wf_engine.SetItemAttrText
5307                           ( itemtype => l_wf_item_type
5308                           , itemkey => l_itemkey
5309                           , aname => 'WORK_TYPE_NAME'
5310                           , avalue => l_assignments_rec.work_type_name
5311                           );
5312            -- End of Additions by RM
5313 
5314     wf_engine.SetItemAttrText
5315     ( itemtype => l_wf_item_type
5316         , itemkey  => l_itemkey
5317         , aname    => 'ASSIGNMENT_NAME'
5318         , avalue   => l_assignments_rec.assignment_name );
5319 
5320     wf_engine.SetItemAttrNumber
5321         ( itemtype => l_wf_item_type
5322         , itemkey  => l_itemkey
5323         , aname    => 'ASSIGNMENT_DURATION'
5324         , avalue   => (trunc(l_assignments_rec.end_date) -
5325                      trunc(l_assignments_rec.start_date)+1) );
5326 
5327     wf_engine.SetItemAttrNumber
5328     ( itemtype => l_wf_item_type
5329         , itemkey  => l_itemkey
5330         , aname    => 'ASSIGNMENT_EFFORT'
5331         , avalue   => l_assignments_rec.assignment_effort );
5332 
5333     wf_engine.SetItemAttrText
5334     ( itemtype => l_wf_item_type
5335         , itemkey  => l_itemkey
5336         , aname    => 'DESCRIPTION'
5337         , avalue   => l_assignments_rec.description );
5338 
5339     wf_engine.SetItemAttrText
5340     ( itemtype => l_wf_item_type
5341         , itemkey  => l_itemkey
5342         , aname    => 'ADDITIONAL_INFORMATION'
5343         , avalue   => l_assignments_rec.additional_information );
5344 
5345     --Setting Project attributes
5346     wf_engine.SetItemAttrText
5347     ( itemtype => l_wf_item_type
5348         , itemkey  => l_itemkey
5349         , aname    => 'PROJECT_NAME'
5350         , avalue   => p_project_name );
5351 
5352     wf_engine.SetItemAttrText
5353     ( itemtype => l_wf_item_type
5354         , itemkey  => l_itemkey
5355         , aname    => 'PROJECT_NUMBER'
5356         , avalue   => p_project_number );
5357 
5358     wf_engine.SetItemAttrText
5359     ( itemtype => l_wf_item_type
5360         , itemkey  => l_itemkey
5361         , aname    => 'PROJECT_MANAGER_NAME'
5362         , avalue   => p_project_manager );
5363 
5364     wf_engine.SetItemAttrText
5365     ( itemtype => l_wf_item_type
5366         , itemkey  => l_itemkey
5367         , aname    => 'PROJECT_ORGANIZATION'
5368         , avalue   => p_project_org );
5369 
5370     wf_engine.SetItemAttrText
5371     ( itemtype => l_wf_item_type
5372         , itemkey  => l_itemkey
5373         , aname    => 'PROJECT_CUSTOMER'
5374         , avalue   => p_project_cus );
5375 
5376     wf_engine.SetItemAttrDate
5377     ( itemtype => l_wf_item_type
5378         , itemkey  => l_itemkey
5379         , aname    => 'START_DATE'
5380         , avalue   => l_assignments_rec.start_date);
5381 
5382     wf_engine.SetItemAttrDate
5383     ( itemtype => l_wf_item_type
5384         , itemkey  => l_itemkey
5385         , aname    => 'END_DATE'
5386         , avalue   => l_assignments_rec.end_date);
5387 
5388 /*  Added for bug 3051110   */
5389 
5390     wf_engine.SetItemAttrNumber
5391         (  itemtype => l_wf_item_type
5392          , Itemkey => l_itemkey
5393          , aname => 'TRANSFER_PRICE_RATE'
5394          , avalue => l_assignments_rec.transfer_price_rate);
5395 
5396     wf_Engine.SetItemAttrText
5397        (itemtype => l_wf_item_type
5398         , itemkey => l_itemkey
5399     , aname => 'TRANSFER_PR_RATE_CURR'
5400     , avalue => l_assignments_rec.transfer_pr_rate_curr);
5401 
5402     --Start the workflow process
5403     wf_engine.StartProcess ( itemtype => l_wf_item_type
5404                             ,itemkey  => l_itemkey );
5405 
5406     PA_WORKFLOW_UTILS.Insert_WF_Processes
5407         (p_wf_type_code        => 'MASS_ASSIGNMENT_APPROVAL'
5408         ,p_item_type           => l_wf_item_type
5409         ,p_item_key            => l_itemkey
5410         ,p_entity_key1         => to_char(p_project_id)
5411         ,p_entity_key2         => to_char(p_assignment_id)
5412         ,p_description         => NULL
5413         ,p_err_code            => l_err_code
5414         ,p_err_stage           => l_err_stage
5415         ,p_err_stack           => l_err_stack );
5416 
5417      END IF ; -- GSI Bug 7430471
5418     END IF;--end recipient name is null (no fnd_user for this resource)
5419 
5420 
5421     --Setting the original value
5422     wf_engine.threshold := l_save_threshold;
5423 
5424     -- IF the number of messages is 1 then fetch the message code from
5425     -- the stack and return its text
5426     x_msg_count :=  FND_MSG_PUB.Count_Msg;
5427 
5428     IF x_msg_count = 1 THEN
5429         pa_interface_utils_pub.get_messages
5430             ( p_encoded       => FND_API.G_TRUE
5431              ,p_msg_index     => 1
5432              ,p_data          => x_msg_data
5433              ,p_msg_index_out => l_msg_index_out );
5434     END IF;
5435 
5436     -- Reset the error stack when returning to the calling program
5437     PA_DEBUG.Reset_Err_Stack;
5438 
5439     -- If g_error_exists is TRUE then set the x_return_status to 'E'
5440     IF FND_MSG_PUB.Count_Msg >0  THEN
5441         x_return_status := FND_API.G_RET_STS_ERROR;
5442     END IF;
5443 
5444 EXCEPTION
5445     WHEN OTHERS THEN
5446 
5447          --Setting the original value
5448          wf_engine.threshold := l_save_threshold;
5449 
5450          -- Set the excetption Message and the stack
5451          FND_MSG_PUB.add_exc_msg
5452              ( p_pkg_name       => 'PA_ASGMT_WFSTD.process_res_fyi_notification'
5453               ,p_procedure_name => PA_DEBUG.G_Err_Stack );
5454 
5455          x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
5456          RAISE;
5457 END process_res_fyi_notification;
5458 
5459 --------------------------------------------------------
5460 --This API sets the workflow attributes for Manager FYIs
5461 --Manager FYIs include notifications to Resource Manager
5462 --Staffing Manager and Project Managers
5463 ---------------------------------------------------------
5464 PROCEDURE set_manager_attributes
5465     ( itemtype               IN   VARCHAR2
5466      ,itemkey                IN   VARCHAR2
5467      ,p_group_id             IN   NUMBER
5468      ,p_mode                 IN   VARCHAR2
5469      ,p_update_info_doc      IN   VARCHAR2  := FND_API.G_MISS_CHAR
5470      ,p_num_apr_asgns        IN   NUMBER
5471      ,p_num_rej_asgns        IN   NUMBER
5472      ,p_project_name         IN   VARCHAR2
5473      ,p_project_number       IN   VARCHAR2
5474      ,p_project_manager      IN   VARCHAR2
5475      ,p_project_org          IN   VARCHAR2
5476      ,p_project_cus          IN   VARCHAR2
5477      ,p_conflict_group_id    IN   NUMBER    := FND_API.G_MISS_NUM
5478      ,p_notified_id          IN   NUMBER
5479      ,x_return_status        OUT  NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
5480      ,x_msg_count            OUT  NOCOPY NUMBER ) --File.Sql.39 bug 4440895
5481 IS
5482 
5483     l_assignment_id         NUMBER;
5484     l_msg_count             NUMBER := 0;
5485     l_error_message_code    VARCHAR2(30);
5486     l_return_status         VARCHAR2(1);
5487     l_wf_item_type          VARCHAR2(30);
5488     l_itemkey               NUMBER;
5489     l_conflict_url          VARCHAR2(600);
5490     l_selected_roles_url   VARCHAR2(600);
5491     l_selected_roles2_url   VARCHAR2(600);
5492     l_selected_resources_url   VARCHAR2(600);
5493     l_selected_resources2_url   VARCHAR2(600);
5494     l_conflict_group_id     NUMBER;
5495 
5496     CURSOR l_assignments_csr (l_assignment_id IN NUMBER ) IS
5497     SELECT
5498        ppa.project_id,
5499        ppa.assignment_name,
5500        ppa.assignment_effort,
5501        ppa.additional_information,
5502        ppa.description,
5503        ppa.start_date,
5504        ppa.end_date,
5505        ppa.revenue_bill_rate,
5506        ppa.revenue_currency_code,
5507        ppa.bill_rate_override,
5508        ppa.bill_rate_curr_override,
5509        ppa.markup_percent_override,
5510        ppa.fcst_tp_amount_type_name,
5511        ppa.tp_rate_override,
5512        ppa.tp_currency_override,
5513        ppa.tp_calc_base_code_override,
5514        ppa.tp_percent_applied_override,
5515        ppa.work_type_name,
5516        hr.name
5517     FROM pa_project_assignments_v ppa,
5518          pa_resources_denorm res,
5519          hr_all_organization_units hr
5520     WHERE ppa.assignment_id    = l_assignment_id
5521     AND   res.resource_id      = ppa.resource_id
5522     AND   ppa.start_date BETWEEN res.resource_effective_start_date
5523                              AND res.resource_effective_end_date
5524     AND   hr.organization_id   = res.resource_organization_id;
5525 
5526 CURSOR csr_get_override_basis_name (p_override_basis_code IN VARCHAR2) IS
5527 SELECT plks.meaning
5528 FROM   pa_lookups plks
5529 WHERE  plks.lookup_type = 'CC_MARKUP_BASE_CODE'
5530 AND    plks.lookup_code = p_override_basis_code;
5531 
5532     l_assignments_rec l_assignments_csr%ROWTYPE;
5533     l_override_basis_name  VARCHAR2(80) := NULL;
5534 
5535 BEGIN
5536 
5537         log_message('Inside set manager attributes');
5538 
5539         l_wf_item_type := itemtype;
5540         l_itemkey      := itemkey;
5541 
5542         BEGIN
5543                 SELECT object_id1
5544                 INTO   l_assignment_id
5545                 FROM   pa_wf_ntf_performers
5546                 WHERE  group_id = p_group_id
5547                 AND    rownum   = 1;
5548             EXCEPTION
5549                 WHEN OTHERS THEN
5550                    null;
5551             END;
5552 
5553             OPEN l_assignments_csr (l_assignment_id);
5554             FETCH l_assignments_csr INTO l_assignments_rec;
5555 
5556             IF l_assignments_csr%NOTFOUND THEN
5557                x_return_status := FND_API.G_RET_STS_ERROR;
5558                    pa_utils.add_message (p_app_short_name  => 'PA',
5559                                          p_msg_name        => 'PA_INVALID_ASMGT_ID');
5560                l_msg_count := l_msg_count + 1;
5561 
5562             END IF;
5563             CLOSE l_assignments_csr;
5564 
5565           l_selected_roles_url := 'JSP:/OA_HTML/OA.jsp?akRegionApplicationId=275' ||
5566                 '&akRegionCode=PA_SELECTED_ROLES_LAYOUT&paCallingPage=WF_Notifications' ||
5567                 '&paProjectId=' || l_assignments_rec.project_id || '&paNotifiedId=' ||
5568                 p_notified_id || '&paGroupId=' || p_group_id || '&paApprovalStatus=Approved&addBreadCrumb=RP';
5569 
5570           l_selected_roles2_url := 'JSP:/OA_HTML/OA.jsp?akRegionApplicationId=275' ||
5571                 '&akRegionCode=PA_SELECTED_ROLES_LAYOUT&paCallingPage=WF_Notifications' ||
5572                 '&paProjectId=' || l_assignments_rec.project_id || '&paNotifiedId=' ||
5573                 p_notified_id || '&paGroupId=' || p_group_id || '&paApprovalStatus=Rejected&addBreadCrumb=RP';
5574 
5575         ------------------------------------------------------------
5576         --If this is assignment creation mode set assignment info
5577         --else set Updated Info attributes
5578         -----------------------------------------------------------
5579 
5580         IF p_mode = PA_MASS_ASGMT_TRX.G_MASS_ASGMT THEN
5581 
5582             l_selected_resources_url := 'JSP:/OA_HTML/OA.jsp?akRegionApplicationId=275' ||
5583                 '&akRegionCode=PA_SELECTED_RESOURCES_LAYOUT&paCallingPage=WF_Notifications' ||
5584                 '&paProjectId=' || l_assignments_rec.project_id || '&paNotifiedId=' ||
5585                 p_notified_id || '&paGroupId=' || p_group_id || '&paApprovalStatus=Approved&addBreadCrumb=RP';
5586 
5587             l_selected_resources2_url := 'JSP:/OA_HTML/OA.jsp?akRegionApplicationId=275' ||
5588                 '&akRegionCode=PA_SELECTED_RESOURCES_LAYOUT&paCallingPage=WF_Notifications' ||
5589                 '&paProjectId=' || l_assignments_rec.project_id || '&paNotifiedId=' ||
5590                 p_notified_id || '&paGroupId=' || p_group_id || '&paApprovalStatus=Rejected&addBreadCrumb=RP';
5591 
5592             wf_engine.SetItemAttrText
5593                 ( itemtype => l_wf_item_type
5594                 , itemkey  => l_itemkey
5595                 , aname    => 'SELECTED_RESOURCES_URL'
5596                 , avalue   => l_selected_resources_url);
5597 
5598             wf_engine.SetItemAttrText
5599                 ( itemtype => l_wf_item_type
5600                 , itemkey  => l_itemkey
5601                 , aname    => 'SELECTED_RESOURCES2_URL'
5602                 , avalue   => l_selected_resources2_url);
5603 
5604              wf_engine.SetItemAttrText
5605                  ( itemtype => l_wf_item_type
5606                  , itemkey  => l_itemkey
5607                  , aname    => 'ASSIGNMENT_NAME'
5608                  , avalue   => l_assignments_rec.assignment_name );
5609 
5610             wf_engine.SetItemAttrText
5611                 ( itemtype => l_wf_item_type
5612                 , itemkey  => l_itemkey
5613                 , aname    => 'RESOURCE_ORGANIZATION'
5614                 , avalue   => l_assignments_rec.name );
5615 
5616             wf_engine.SetItemAttrNumber
5617                 ( itemtype => l_wf_item_type
5618                 , itemkey  => l_itemkey
5619                 , aname    => 'ASSIGNMENT_DURATION'
5620                 , avalue   => (trunc(l_assignments_rec.end_date) -
5621                                trunc(l_assignments_rec.start_date)+1) );
5622 
5623             wf_engine.SetItemAttrNumber
5624                 ( itemtype => l_wf_item_type
5625                 , itemkey  => l_itemkey
5626                 , aname    => 'ASSIGNMENT_EFFORT'
5627                 , avalue   => l_assignments_rec.assignment_effort );
5628 
5629             wf_engine.SetItemAttrText
5630                 ( itemtype => l_wf_item_type
5631                 , itemkey  => l_itemkey
5632                 , aname    => 'DESCRIPTION'
5633                 , avalue   => l_assignments_rec.description );
5634 
5635             wf_engine.SetItemAttrText
5636                 ( itemtype => l_wf_item_type
5637                 , itemkey  => l_itemkey
5638                 , aname    => 'ADDITIONAL_INFORMATION'
5639                 , avalue   => l_assignments_rec.additional_information );
5640 
5641            wf_engine.SetItemAttrDate
5642                   (itemtype => l_wf_item_type
5643                               , itemkey => l_itemkey
5644                               , aname => 'START_DATE'
5645                               , avalue => l_assignments_rec.start_date
5646                               );
5647 
5648            wf_engine.SetItemAttrDate
5649                   (itemtype => l_wf_item_type
5650                               , itemkey => l_itemkey
5651                               , aname => 'END_DATE'
5652                               , avalue => l_assignments_rec.end_date
5653                               );
5654            -- Start Additions by RM for bug 2274426
5655            wf_engine.SetItemAttrNumber
5656                                ( itemtype => l_wf_item_type
5657                                , itemkey => l_itemkey
5658                                , aname => 'REVENUE_BILL_RATE'
5659                                , avalue => l_assignments_rec.revenue_bill_rate
5660                                );
5661            wf_engine.SetItemAttrText
5662                             ( itemtype => l_wf_item_type
5663                             , itemkey => l_itemkey
5664                             , aname => 'REVENUE_BILL_RATE_CURR'
5665                             , avalue => l_assignments_rec.revenue_currency_code
5666                             );
5667            wf_engine.SetItemAttrNumber
5668                                ( itemtype => l_wf_item_type
5669                                , itemkey => l_itemkey
5670                                , aname => 'BILL_RATE_OVERRIDE'
5671                                , avalue => l_assignments_rec.bill_rate_override
5672                                );
5673            wf_engine.SetItemAttrText
5674                           ( itemtype => l_wf_item_type
5675                           , itemkey => l_itemkey
5676                           , aname => 'BILL_RATE_OVERRIDE_CURR'
5677                           , avalue => l_assignments_rec.bill_rate_curr_override
5678                           );
5679            IF l_assignments_rec.markup_percent_override IS NOT NULL THEN
5680               wf_engine.SetItemAttrText
5681                           ( itemtype => l_wf_item_type
5682                           , itemkey => l_itemkey
5683                           , aname => 'MARKUP_PCT_OVERRIDE'
5684                           , avalue => to_char(l_assignments_rec.markup_percent_override)||'%'
5685                           );
5686            ELSE
5687                wf_engine.SetItemAttrText
5688                           ( itemtype => l_wf_item_type
5689                           , itemkey => l_itemkey
5690                           , aname => 'MARKUP_PCT_OVERRIDE'
5691                           , avalue => to_char(l_assignments_rec.markup_percent_override)
5692                           );
5693            END IF;
5694            wf_engine.SetItemAttrText
5695                           ( itemtype => l_wf_item_type
5696                           , itemkey => l_itemkey
5697                           , aname => 'TP_AMT_TYPE_NAME'
5698                           , avalue => l_assignments_rec.fcst_tp_amount_type_name
5699                           );
5700            wf_engine.SetItemAttrNumber
5701                           ( itemtype => l_wf_item_type
5702                           , itemkey => l_itemkey
5703                           , aname => 'TP_RATE_OVERRIDE'
5704                           , avalue => l_assignments_rec.tp_rate_override
5705                           );
5706            wf_engine.SetItemAttrText
5707                           ( itemtype => l_wf_item_type
5708                           , itemkey => l_itemkey
5709                           , aname => 'TP_RATE_OVERRIDE_CURR'
5710                           , avalue => l_assignments_rec.tp_currency_override
5711                           );
5712            IF l_assignments_rec.tp_calc_base_code_override IS NOT NULL THEN
5713               open csr_get_override_basis_name(l_assignments_rec.tp_calc_base_code_override);
5714               fetch csr_get_override_basis_name into l_override_basis_name;
5715               close csr_get_override_basis_name;
5716            END IF;
5717            wf_engine.SetItemAttrText
5718                           ( itemtype => l_wf_item_type
5719                           , itemkey => l_itemkey
5720                           , aname => 'OVERRIDE_BASIS_NAME'
5721                           , avalue => l_override_basis_name
5722                           );
5723            IF l_assignments_rec.tp_percent_applied_override IS NOT NULL THEN
5724               IF l_override_basis_name IS NOT NULL THEN
5725                  wf_engine.SetItemAttrText
5726                      ( itemtype => l_wf_item_type
5727                      , itemkey => l_itemkey
5728                      , aname => 'TP_PCT_APPLIED_OVERRIDE'
5729                      , avalue => ', '||to_char(l_assignments_rec.tp_percent_applied_override)||'%'
5730                      );
5731               ELSE
5732                  wf_engine.SetItemAttrText
5733                      ( itemtype => l_wf_item_type
5734                      , itemkey => l_itemkey
5735                      , aname => 'TP_PCT_APPLIED_OVERRIDE'
5736                      , avalue => to_char(l_assignments_rec.tp_percent_applied_override)||'%'
5737                      );
5738               END IF;
5739            ELSE
5740               wf_engine.SetItemAttrText
5741                      ( itemtype => l_wf_item_type
5742                      , itemkey => l_itemkey
5743                      , aname => 'TP_PCT_APPLIED_OVERRIDE'
5744                      , avalue => to_char(l_assignments_rec.tp_percent_applied_override)
5745                      );
5746            END IF;
5747            wf_engine.SetItemAttrText
5748                           ( itemtype => l_wf_item_type
5749                           , itemkey => l_itemkey
5750                           , aname => 'WORK_TYPE_NAME'
5751                           , avalue => l_assignments_rec.work_type_name
5752                           );
5753            -- End of Additions by RM
5754 
5755         ELSIF (p_mode = PA_MASS_ASGMT_TRX.G_MASS_UPDATE_ASGMT_BASIC_INFO OR
5756                p_mode = PA_MASS_ASGMT_TRX.G_MASS_UPDATE_COMPETENCIES     OR
5757                p_mode = PA_MASS_ASGMT_TRX.G_MASS_UPDATE_FORECAST_ITEMS   OR
5758                p_mode = PA_MASS_ASGMT_TRX.G_MASS_UPDATE_SCHEDULE )
5759 
5760         THEN
5761 
5762             wf_engine.SetItemAttrDocument
5763                 ( itemtype => l_wf_item_type
5764                 , itemkey  => l_itemkey
5765                 , aname    => 'UPDATED_INFO_DOC'
5766                 , documentid   => p_update_info_doc );
5767 
5768         END IF;
5769 
5770         ---------------------------------------------------------------------
5771         --Setting Common attributes for CRN / UPD / APS
5772         --------------------------------------------------------------------
5773 
5774         --Setting Assignment Attributes
5775         wf_engine.SetItemAttrNumber
5776             ( itemtype => l_wf_item_type
5777             , itemkey  => l_itemkey
5778             , aname    => 'APPROVED_ASSIGNMENTS'
5779             , avalue   => p_num_apr_asgns );
5780 
5781         wf_engine.SetItemAttrText
5782             ( itemtype => l_wf_item_type
5783             , itemkey  => l_itemkey
5784             , aname    => 'SELECTED_ROLES_URL'
5785             , avalue   => l_selected_roles_url);
5786 
5787         wf_engine.SetItemAttrText
5788             ( itemtype => l_wf_item_type
5789             , itemkey  => l_itemkey
5790             , aname    => 'SELECTED_ROLES2_URL'
5791             , avalue   => l_selected_roles2_url);
5792 
5793          wf_engine.SetItemAttrNumber
5794             ( itemtype => l_wf_item_type
5795             , itemkey  => l_itemkey
5796             , aname    => 'REJECTED_ASSIGNMENTS'
5797             , avalue   => p_num_rej_asgns );
5798 
5799         --Setting Project attributes
5800         wf_engine.SetItemAttrText
5801             ( itemtype => l_wf_item_type
5802             , itemkey  => l_itemkey
5803             , aname    => 'PROJECT_NAME'
5804             , avalue   => p_project_name );
5805 
5806         wf_engine.SetItemAttrText
5807            ( itemtype => l_wf_item_type
5808             , itemkey  => l_itemkey
5809             , aname    => 'PROJECT_NUMBER'
5810             , avalue   => p_project_number );
5811 
5812         wf_engine.SetItemAttrText
5813             ( itemtype => l_wf_item_type
5814             , itemkey  => l_itemkey
5815             , aname    => 'PROJECT_MANAGER_NAME'
5816             , avalue   => p_project_manager );
5817 
5818         wf_engine.SetItemAttrText
5819             ( itemtype => l_wf_item_type
5820             , itemkey  => l_itemkey
5821             , aname    => 'PROJECT_ORGANIZATION'
5822             , avalue   => p_project_org );
5823 
5824         wf_engine.SetItemAttrText
5825             ( itemtype => l_wf_item_type
5826             , itemkey  => l_itemkey
5827             , aname    => 'PROJECT_CUSTOMER'
5828             , avalue   => p_project_cus );
5829 
5830         -- Always display View Conflict link
5831         IF (p_conflict_group_id IS NUll OR p_conflict_group_id = FND_API.G_MISS_NUM) THEN
5832            l_conflict_group_id := '';
5833         ELSE
5834            l_conflict_group_id := p_conflict_group_id;
5835         END IF;
5836 
5837         l_conflict_url := 'JSP:/OA_HTML/OA.jsp?akRegionApplicationId=275&akRegionCode=PA_VIEW_CONFLICTS_LAYOUT&paProjectId=' ||
5838                           l_assignments_rec.project_id || '&paCallingPage=MassAsmtFYINotif&paConflictGroupId=' ||
5839                           l_conflict_group_id || '&addBreadCrumb=RP';
5840 
5841          wf_engine.SetItemAttrText
5842                ( itemtype => l_wf_item_type
5843                , itemkey  => l_itemkey
5844                , aname    => 'CONFLICT_URL'
5845                , avalue   => l_conflict_url );
5846 
5847         x_msg_count := l_msg_count;
5848 
5849 END set_manager_attributes;
5850 
5851 /** This API starts the FYI notifications to indicate if
5852   * asignments have been approved or rejected. It sends the following notification.
5853   *     1. Staffing Manager FYI for the mass txn
5854   *     2. Resource Manager FYI for the mass txn
5855   *     3. Project Manager FYI for the mass txn
5856   * The logic involves calling the client extension for every
5857   * assignment and populating pa_wf_ntf_performers table
5858   * Notifications are then sent to recipients from the pa_wf_ntf_performers table
5859   */
5860 PROCEDURE process_mgr_fyi_notification
5861     ( p_assignment_id_tbl    IN   SYSTEM.pa_num_tbl_type
5862      ,p_project_id           IN   NUMBER    := FND_API.G_MISS_NUM
5863      ,p_group_id             IN   NUMBER    := FND_API.G_MISS_NUM
5864      ,p_mode                 IN   VARCHAR2
5865      ,p_update_info_doc      IN   VARCHAR2  := FND_API.G_MISS_CHAR
5866      ,p_num_apr_asgns        IN   NUMBER
5867      ,p_num_rej_asgns        IN   NUMBER
5868      ,p_project_name         IN   VARCHAR2
5869      ,p_project_number       IN   VARCHAR2
5870      ,p_project_manager      IN   VARCHAR2
5871      ,p_project_org          IN   VARCHAR2
5872      ,p_project_cus          IN   VARCHAR2
5873      ,p_submitter_user_name  IN   VARCHAR2
5874      ,p_conflict_group_id    IN   NUMBER    := FND_API.G_MISS_NUM
5875      ,x_return_status        OUT  NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
5876      ,x_msg_count            OUT  NOCOPY NUMBER --File.Sql.39 bug 4440895
5877      ,x_msg_data             OUT  NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
5878 IS
5879 
5880     l_itemkey             VARCHAR2(30);
5881     l_responsibility_id   NUMBER;
5882     l_resp_appl_id        NUMBER;
5883     l_wf_started_date     DATE;
5884     l_wf_started_by_id    NUMBER;
5885     l_return_status       VARCHAR2(1);
5886     l_error_message_code  VARCHAR2(30);
5887     l_save_threshold      NUMBER;
5888     l_msg_count           NUMBER ;
5889     l_msg_index_out   NUMBER ;
5890     l_msg_data            VARCHAR2(2000);
5891     l_wf_item_type        VARCHAR2(2000):= 'PARMAAP'; --Assignment Approval Item type
5892     l_wf_process          VARCHAR2(2000);
5893     l_err_code        NUMBER := 0;
5894     l_err_stage       VARCHAR2(2000);
5895     l_err_stack           VARCHAR2(2000);
5896     l_assignment_id       NUMBER;
5897     l_recipients_tbl      SYSTEM.pa_varchar2_240_tbl_type;  /*Commented SYSTEM.pa_varchar2_30_tbl_type for the bug 3311991*/
5898     l_recipients_type_tbl SYSTEM.pa_varchar2_30_tbl_type;
5899 
5900     l_approval_nf_rects_tbl                  PA_CLIENT_EXTN_ASGMT_WF.Users_List_Tbltyp ;
5901     l_out_approval_nf_rects_tbl              PA_CLIENT_EXTN_ASGMT_WF.Users_List_Tbltyp ;
5902     l_number_of_recipients                   NUMBER := 0;
5903     l_approval_nf_rects_rec                  PA_CLIENT_EXTN_ASGMT_WF.Users_List_Rectyp ;
5904     l_ntfy_apprvl_recipient_name             wf_users.name%TYPE; ---VARCHAR2(240); Changer for 3267790
5905     l_ntfy_apprvl_rect_person_id             NUMBER := 0;
5906     l_ntfy_apprvl_rect_type                  VARCHAR2(30);
5907     l_notification_type                      VARCHAR2(30);
5908 
5909     l_res_mgr_person_id           NUMBER;
5910     l_staff_mgr_person_id         NUMBER;
5911     l_project_manager_person_id   NUMBER ;
5912     l_project_manager_name        per_all_people_f.full_name%TYPE; --VARCHAR2(200);  Changed for bug 3267790
5913     l_project_party_id            NUMBER ;
5914     l_project_role_id             NUMBER ;
5915     l_project_role_name           VARCHAR2(80);
5916     l_admin_project               VARCHAR2(1); --Variable which denotes if a project is an admin project or not
5917     l_num_apr_asgns               NUMBER ;
5918     l_num_rej_asgns               NUMBER ;
5919     l_display_name        wf_users.display_name%TYPE; --VARCHAR2(360); Commented VARCHAR2(360) for bug 3267790 --Commented VARCHAR2(200) for bug 3311991
5920     l_approver_name       wf_users.display_name%TYPE; --VARCHAR2(320); Commented VARCHAR2(320) for bug 3267790 --Commented VARCHAR2(200) for bug 3311991
5921     l_aprvl_status_code   pa_project_assignments.apprvl_status_code%TYPE;
5922     l_assignment_id_tbl   SYSTEM.pa_num_tbl_type;
5923 
5924     CURSOR Resource_Manager IS
5925     SELECT distinct res.manager_id
5926     FROM   pa_resources_denorm res,
5927            pa_project_assignments asgn,
5928            pa_wf_ntf_performers ntf,
5929            fnd_user fnd
5930     WHERE  ntf.group_id       = p_group_id
5931     AND    asgn.assignment_id = l_assignment_id
5932     AND    asgn.assignment_id = ntf.object_id1
5933     AND    res.resource_id    = asgn.resource_id
5934     AND    asgn.start_date BETWEEN res.resource_effective_start_date
5935                AND     res.resource_effective_end_date
5936     AND    res.manager_id     = fnd.employee_id
5937     AND    fnd.user_name     <> ntf.user_name;
5938 
5939     CURSOR Staffing_Manager IS
5940     SELECT distinct per.person_id as staffing_mgr_id
5941     FROM   fnd_grants fg,
5942            fnd_objects fob,
5943            fnd_user fnd,
5944            pa_resources_denorm res,
5945            /* Commenting this for performance tuning Bug#2499051
5946            (select pa_security_pvt.get_menu_id('PA_PRM_RES_PRMRY_CONTACT') menu_id
5947               from   dual) temp, */
5948            pa_project_assignments asgn,
5949            pa_wf_ntf_performers ntf,
5950            wf_roles wf,
5951            per_all_people_f per
5952     WHERE  ntf.group_id       = p_group_id
5953     AND    asgn.assignment_id = l_assignment_id
5954     AND    asgn.assignment_id = ntf.object_id1
5955     AND    res.resource_id    = asgn.resource_id
5956     AND    asgn.start_date BETWEEN res.resource_effective_start_date
5957                AND     res.resource_effective_end_date
5958     --AND    fnd.employee_id    = to_number(substr(fg.grantee_key,instr(fg.grantee_key,':')+1))
5959     AND    fnd.employee_id    = per.person_id
5960     AND    per.party_id = wf.orig_system_id
5961     AND    sysdate between per.effective_start_date and per.effective_end_date
5962     AND    wf.orig_system = 'HZ_PARTY'
5963     AND    fg.grantee_key = wf.name
5964     AND    fnd.user_name     <> ntf.user_name
5965     AND    fg.instance_pk1_value = TO_CHAR(res.resource_organization_id)
5966     AND    fg.instance_type   = 'INSTANCE'
5967     AND    fg.object_id       = fob.object_id
5968     AND    fob.obj_name       = 'ORGANIZATION'
5969     AND    fg.menu_id         = pa_security_pvt.get_menu_id('PA_PRM_RES_PRMRY_CONTACT') /* temp.menu_id commented for bug#2499051 */
5970     AND    fg.grantee_type    = 'USER'
5971     AND    trunc(SYSDATE) BETWEEN trunc(fg.start_date)
5972                           AND     trunc(NVL(fg.END_DATE, SYSDATE+1));
5973 
5974     l_index NUMBER;
5975 
5976     CURSOR get_managers IS
5977         SELECT distinct user_name,
5978                user_type
5979         FROM pa_wf_ntf_performers
5980         WHERE wf_type_code  = 'MASS_APPROVAL_FYI'
5981         AND group_id        = p_group_id;
5982     l_notified_id NUMBER;
5983     l_debug_mode VARCHAR2(1) := NVL(FND_PROFILE.value('PA_DEBUG_MODE'), 'N'); -- 5345171
5984 
5985 BEGIN
5986 
5987     -- Initialize the Error Stack
5988     PA_DEBUG.init_err_stack('PA_ASGMT_WFSTD.process_mgr_fyi_notification');
5989 
5990     --Log Message
5991     IF l_debug_mode = 'Y' THEN -- 5345171
5992         PA_DEBUG.write_log
5993         ( x_module      => 'pa.plsql.PA_ASGMT_WFSTD.process_mgr_fyi_notification.begin'
5994          ,x_msg         => 'Beginning of mass fyi workflow api'
5995          ,x_log_level   => 1);
5996     END IF;
5997 
5998     -- Initialize the return status to success
5999     x_return_status := FND_API.G_RET_STS_SUCCESS;
6000 
6001     --Clear the global PL/SQL message table
6002     FND_MSG_PUB.initialize;
6003 
6004     --------------------------------------------
6005     --Get Project Manager for these assignments
6006     --------------------------------------------
6007     --Get the project type
6008     --MOAC Changes: Bug 4363092 : removed nvl usage with org_id
6009     SELECT NVL(pt.administrative_flag,'N') admin_flag
6010     INTO   l_admin_project
6011     FROM   pa_projects_all pap,
6012            pa_project_types_all pt
6013     WHERE  pap.project_id = p_project_id
6014     AND    pt.project_type = pap.project_type
6015     AND    pap.org_id = pt.org_id;
6016 
6017     --Only Non-admin Projects have managers
6018     IF l_admin_project = 'N' THEN
6019 
6020         --Log Message
6021         IF l_debug_mode = 'Y' THEN -- 5345171
6022                 PA_DEBUG.write_log
6023                     (x_module    => 'pa.plsql.PA_ASGMT_WFSTD.process_mgr_fyi_notification.check_prj_manager.'
6024                     ,x_msg       => 'Check if project manger exists.'
6025                     ,x_log_level => 1);
6026         END IF;
6027 
6028         pa_project_parties_utils.get_curr_proj_mgr_details
6029             ( p_project_id         => p_project_id
6030              ,x_manager_person_id  => l_project_manager_person_id
6031              ,x_manager_name       => l_project_manager_name
6032              ,x_project_party_id   => l_project_party_id
6033              ,x_project_role_id    => l_project_role_id
6034              ,x_project_role_name  => l_project_role_name
6035              ,x_return_status      => l_return_status
6036              ,x_error_message_code => l_error_message_code );
6037 
6038         IF l_return_status = FND_API.G_RET_STS_ERROR THEN
6039             PA_UTILS.Add_Message( p_app_short_name => 'PA'
6040                                      ,p_msg_name       => l_error_message_code);
6041         END IF;
6042 
6043         l_return_status := FND_API.G_MISS_CHAR;
6044         l_error_message_code := FND_API.G_MISS_CHAR;
6045 
6046     END IF; --end l_admin_project = 'N'
6047 
6048     log_message('After Getting manager');
6049 
6050     l_assignment_id_tbl := p_assignment_id_tbl;
6051 
6052     ---------------------------------------------------------
6053     --For every assignment in this mass transaction populate
6054     --pa_wf_ntf_performers with recipients
6055     --Assumptions: The project manager remains the same for
6056     --all assignments in the client extension
6057     --------------------------------------------------------
6058     FOR i in 1..l_assignment_id_tbl.COUNT LOOP
6059 
6060         --Getting recepients approval type
6061         SELECT apprvl_status_code
6062         INTO   l_aprvl_status_code
6063         FROM   pa_project_assignments
6064         WHERE  assignment_id = l_assignment_id_tbl(i);
6065 
6066         IF l_aprvl_status_code = PA_ASSIGNMENT_APPROVAL_PUB.g_approved THEN
6067             l_notification_type := 'APPROVAL_FYI';
6068         ELSE l_notification_type := 'REJECTION_FYI';
6069         END IF;
6070 
6071         --Get Resource Manager and Staffing Manager for this
6072         --assignment and pass to client extension along with
6073         --Project Manager
6074         l_assignment_id := l_assignment_id_tbl(i);
6075 
6076         --Getting Resource manager
6077         OPEN Resource_Manager;
6078         FETCH Resource_manager INTO l_res_mgr_person_id;
6079         CLOSE Resource_Manager;
6080 
6081         --Getting Staffing Manager
6082         OPEN Staffing_Manager;
6083         FETCH Staffing_manager INTO l_staff_mgr_person_id;
6084         CLOSE Staffing_Manager;
6085 
6086         ----------------------------------------------
6087         --Build recipient IN table for client extensions
6088         ----------------------------------------------
6089 
6090         l_index := 0;
6091 
6092         --Populating Resource manager in recipient table
6093         ------------------------------------------------
6094         IF l_res_mgr_person_id IS NOT NULL THEN
6095 
6096             --Getting recepients fnd user name
6097             wf_directory.getusername
6098             (p_orig_system    => 'PER'
6099             ,p_orig_system_id => l_res_mgr_person_id
6100             ,p_name           => l_ntfy_apprvl_recipient_name
6101             ,p_display_name   => l_display_name);
6102 
6103             l_ntfy_apprvl_rect_type := 'RESOURCE_MANAGER';
6104 
6105             --ceating the recipient in table
6106             IF l_ntfy_apprvl_recipient_name IS NOT NULL THEN
6107                 l_approval_nf_rects_rec.User_Name := l_ntfy_apprvl_recipient_name;
6108                 l_approval_nf_rects_rec.Person_id := l_res_mgr_person_id;
6109                 l_approval_nf_rects_rec.Type      := l_ntfy_apprvl_rect_type;
6110                 --l_approval_nf_rects_rec.Routing_Order :=  ?;
6111                 l_approval_nf_rects_tbl(l_index + 1)        := l_approval_nf_rects_rec;
6112                 l_index := l_index + 1;
6113             END IF;
6114 
6115         END IF;
6116 
6117         log_message('Resource Mgr name:' || l_ntfy_apprvl_recipient_name);
6118 
6119 
6120         --Populating Staffing manager in recipient table
6121         ------------------------------------------------
6122         IF l_staff_mgr_person_id IS NOT NULL THEN
6123 
6124             --Getting recepients fnd user name
6125             wf_directory.getusername
6126             (p_orig_system    => 'PER'
6127             ,p_orig_system_id => l_staff_mgr_person_id
6128             ,p_name           => l_ntfy_apprvl_recipient_name
6129             ,p_display_name   => l_display_name);
6130 
6131             l_ntfy_apprvl_rect_type := 'STAFFING_MANAGER';
6132 
6133             IF l_ntfy_apprvl_recipient_name IS NOT NULL THEN
6134                 l_approval_nf_rects_rec.User_Name := l_ntfy_apprvl_recipient_name;
6135                 l_approval_nf_rects_rec.Person_id := l_staff_mgr_person_id;
6136                 l_approval_nf_rects_rec.Type      := l_ntfy_apprvl_rect_type;
6137                 --l_approval_nf_rects_rec.Routing_Order :=  ?;
6138                 l_approval_nf_rects_tbl(l_index + 1)        := l_approval_nf_rects_rec;
6139                 l_index := l_index + 1;
6140             END IF;
6141 
6142         END IF;
6143 
6144         log_message('Staff Mgr name:' || l_ntfy_apprvl_recipient_name);
6145 
6146 
6147         --Populating Project manager in recipient table
6148         -----------------------------------------------
6149         IF l_project_manager_person_id IS NOT NULL THEN
6150 
6151             --Getting recepients fnd user name
6152             wf_directory.getusername
6153             (p_orig_system    => 'PER'
6154             ,p_orig_system_id => l_project_manager_person_id
6155             ,p_name           => l_ntfy_apprvl_recipient_name
6156             ,p_display_name   => l_display_name);
6157 
6158             l_ntfy_apprvl_rect_type := 'PROJECT_MANAGER';
6159 
6160             IF l_ntfy_apprvl_recipient_name IS NOT NULL THEN
6161                 l_approval_nf_rects_rec.User_Name := l_ntfy_apprvl_recipient_name;
6162                 l_approval_nf_rects_rec.Person_id := l_project_manager_person_id;
6163                 l_approval_nf_rects_rec.Type      := l_ntfy_apprvl_rect_type;
6164                 --l_approval_nf_rects_rec.Routing_Order :=  ?;
6165                 l_approval_nf_rects_tbl(l_index + 1)        := l_approval_nf_rects_rec;
6166                 l_index := l_index + 1;
6167             END IF;
6168 
6169         END IF;
6170 
6171         log_message('Before calling mgr client extensions');
6172         log_message('Project Mgr name:' || l_ntfy_apprvl_recipient_name);
6173         log_message('assignment_id:' || l_assignment_id);
6174         log_message('Before COUNT:' || l_approval_nf_rects_tbl.COUNT);
6175 
6176         -------------------------------------------------
6177         --Calling client extension to get all recipients
6178         -------------------------------------------------
6179         PA_CLIENT_EXTN_ASGMT_WF.Generate_NF_Recipients
6180            (p_assignment_id             => l_assignment_id
6181            ,p_project_id                => p_project_id
6182            ,p_notification_type         => l_notification_type
6183            ,p_in_list_of_recipients     => l_approval_nf_rects_tbl
6184            ,x_out_list_of_recipients    => l_out_approval_nf_rects_tbl
6185            ,x_number_of_recipients      => l_number_of_recipients );
6186 
6187         log_message('After calling mgr client extensions');
6188         log_message('After COUNT:' || l_out_approval_nf_rects_tbl.COUNT);
6189         log_message('Total number of managers is:' || l_number_of_recipients );
6190 
6191         IF l_out_approval_nf_rects_tbl.COUNT > 0 THEN
6192 
6193         ---------------------------------------------------------
6194         --Get Recipients and populate pa_wf_ntf_performers table
6195         --Use WF_TYPE_CODE as MASS_APPROVAL_FYI
6196         ---------------------------------------------------------
6197         FOR j IN 1..l_out_approval_nf_rects_tbl.COUNT LOOP
6198             l_approval_nf_rects_rec := l_out_approval_nf_rects_tbl(j);
6199 
6200             log_message('User Name ' || j || ':' || l_approval_nf_rects_rec.user_name);
6201 
6202             IF l_approval_nf_rects_rec.user_name IS NOT NULL THEN
6203 
6204                 log_message('Insert in loop:' || j);
6205 
6206                 INSERT INTO pa_wf_ntf_performers(
6207                         WF_TYPE_CODE
6208                        ,ITEM_TYPE
6209                        ,ITEM_KEY
6210                        ,OBJECT_ID1
6211                        ,GROUP_ID
6212                        ,USER_NAME
6213                        ,USER_TYPE
6214                        ,ROUTING_ORDER )
6215                 VALUES ('MASS_APPROVAL_FYI'
6216                       ,'-1'
6217                       ,'-1'
6218                       ,l_assignment_id
6219                       ,p_group_id
6220                       ,l_approval_nf_rects_rec.user_name
6221                       ,l_approval_nf_rects_rec.type
6222                       ,l_approval_nf_rects_rec.routing_order
6223                       );
6224             END IF;--end l_approval_nf_rects_rec.user_name
6225 
6226         END LOOP;--end j loop
6227 
6228         END IF;
6229 
6230     END LOOP;--end i loop
6231 
6232     log_message('After inserting manager records');
6233 
6234     --------------------------------------------------------
6235     --Select distinct recipients for this mass transaction
6236     --from pa_wf_ntf_performers table and send notifications
6237     --------------------------------------------------------
6238     OPEN get_managers;
6239     FETCH get_managers BULK COLLECT INTO l_recipients_tbl, l_recipients_type_tbl;
6240     CLOSE get_managers;
6241 
6242     log_message('Number of manangers :' || l_recipients_tbl.COUNT);
6243 
6244     --Delete recipients from pa_wf_ntf_performers table
6245     --for this mass transaction
6246     DELETE
6247     FROM pa_wf_ntf_performers
6248     WHERE wf_type_code  = 'MASS_APPROVAL_FYI'
6249     AND group_id        = p_group_id;
6250 
6251     --------------------------------------------------------
6252     --Start Notification Workflow for all manager recipients
6253     --------------------------------------------------------
6254     l_wf_started_by_id  := FND_GLOBAL.user_id;
6255     l_responsibility_id := FND_GLOBAL.resp_id;
6256     l_resp_appl_id      := FND_GLOBAL.resp_appl_id;
6257 
6258     FND_GLOBAL.Apps_Initialize ( user_id      => l_wf_started_by_id
6259                                , resp_id      => l_responsibility_id
6260                                , resp_appl_id => l_resp_appl_id );
6261 
6262     -- Setting thresold value to run the process in background
6263     l_save_threshold    := wf_engine.threshold;
6264     wf_engine.threshold := -1;
6265 
6266     -----------------------------------------------------------------------------
6267     --Setting Process Creation / Update / Aproval submission  mode for assignments
6268     -----------------------------------------------------------------------------
6269     IF p_mode = PA_MASS_ASGMT_TRX.G_MASS_ASGMT THEN
6270 
6271         l_wf_process := 'PA_MASS_APRVL_CRN_FP';
6272 
6273     ELSIF (p_mode = PA_MASS_ASGMT_TRX.G_MASS_UPDATE_ASGMT_BASIC_INFO OR
6274            p_mode = PA_MASS_ASGMT_TRX.G_MASS_UPDATE_COMPETENCIES     OR
6275            p_mode = PA_MASS_ASGMT_TRX.G_MASS_UPDATE_FORECAST_ITEMS   OR
6276            p_mode = PA_MASS_ASGMT_TRX.G_MASS_UPDATE_SCHEDULE )
6277     THEN
6278 
6279         l_wf_process := 'PA_MASS_APRVL_UPD_FP';
6280 
6281     ELSIF  p_mode = PA_MASS_ASGMT_TRX.G_MASS_SUBMIT_FOR_APPROVAL THEN
6282 
6283         l_wf_process := 'PA_MASS_APRVL_APS_FP';
6284 
6285     END IF;
6286 
6287 
6288     For k IN 1..l_recipients_tbl.COUNT LOOP
6289 
6290         -- Create the unique item key to launch WF with
6291         SELECT pa_prm_wf_item_key_s.nextval
6292         INTO   l_itemkey
6293         FROM   dual;
6294 
6295         -- Create the WF process
6296         wf_engine.CreateProcess
6297             ( ItemType => l_wf_item_type
6298             , ItemKey  => l_itemkey
6299             , process  => l_wf_process );
6300 
6301         ------------------------------------------------------------
6302         --Set the item attributes required for manager notifications
6303         ------------------------------------------------------------
6304         wf_engine.SetItemAttrText
6305             ( itemtype => l_wf_item_type
6306             , itemkey  => l_itemkey
6307             , aname    => 'NTFY_FYI_USER_NAME'
6308             , avalue   => l_recipients_tbl(k));
6309 
6310         ------------------------------------------------------------------
6311         --Getting manager person_id
6312         --The logic below gets the manager person id only for
6313         --Staffing and Resource managers. For Project managers
6314         --notified_id will be null and selected roles and selected resources
6315         --pages should display all resources/roles in the mass transaction
6316         -------------------------------------------------------------------
6317         l_notified_id := null;
6318         BEGIN
6319 
6320             IF l_recipients_type_tbl(k) <> 'PROJECT_MANAGER' THEN
6321                 SELECT employee_id
6322                 INTO   l_notified_id
6323                 FROM   fnd_user
6324                 WHERE  user_name = l_recipients_tbl(k)
6325                 AND    rownum = 1;
6326 
6327                 -- bug 2475300 : added following two select stmt to set # of approved/rejected
6328                 -- asmt according to the resource/staffing manager. Resource/staffing mgr should
6329                 -- see the # of asmt which is related to only their resources.
6330                 SELECT count(*)
6331                 INTO   l_num_apr_asgns
6332                 FROM   pa_res_aprvl_roles_v ar
6333                 WHERE  ar.notified_id = l_notified_id
6334                 AND    ar.group_id = p_group_id
6335                 AND    ar.approval_status = 'ASGMT_APPRVL_APPROVED';
6336 
6337                 SELECT count(*)
6338                 INTO   l_num_rej_asgns
6339                 FROM   pa_res_aprvl_roles_v ar
6340                 WHERE  ar.notified_id = l_notified_id
6341                 AND    ar.group_id = p_group_id
6342                 AND    ar.approval_status = 'ASGMT_APPRVL_REJECTED';
6343             ELSE
6344                l_num_apr_asgns := p_num_apr_asgns;
6345                l_num_rej_asgns := p_num_rej_asgns;
6346             END IF;
6347 
6348         EXCEPTION
6349             WHEN OTHERS THEN
6350                 null;
6351         END;
6352 
6353        log_message('Before Calling set manager attributes');
6354 
6355         set_manager_attributes
6356             ( itemtype               => l_wf_item_type
6357              ,itemkey                => l_itemkey
6358              ,p_group_id             => p_group_id
6359              ,p_mode                 => p_mode
6360              ,p_update_info_doc      => p_update_info_doc
6361              ,p_num_apr_asgns        => p_num_apr_asgns
6362              ,p_num_rej_asgns        => p_num_rej_asgns
6363              ,p_project_name         => p_project_name
6364              ,p_project_number       => p_project_number
6365              ,p_project_manager      => p_project_manager
6366              ,p_project_org          => p_project_org
6367              ,p_project_cus          => p_project_cus
6368              ,p_conflict_group_id    => p_conflict_group_id
6369              ,p_notified_id          => l_notified_id
6370              ,x_return_status        => l_return_status
6371              ,x_msg_count            => l_msg_count );
6372 
6373         log_message('After Calling set manager attributes');
6374 
6375         --Start the workflow process
6376         wf_engine.StartProcess ( itemtype => l_wf_item_type
6377                                 ,itemkey  => l_itemkey );
6378 
6379         PA_WORKFLOW_UTILS.Insert_WF_Processes
6380             (p_wf_type_code        => 'MASS_ASSIGNMENT_APPROVAL'
6381         ,p_item_type           => l_wf_item_type
6382         ,p_item_key            => l_itemkey
6383         ,p_entity_key1         => to_char(p_project_id)
6384         ,p_entity_key2         => to_char(p_group_id)
6385         ,p_description         => NULL
6386         ,p_err_code            => l_err_code
6387         ,p_err_stage           => l_err_stage
6388         ,p_err_stack           => l_err_stack );
6389 
6390     END LOOP;--end k loop
6391 
6392 
6393     --Setting the original value
6394     wf_engine.threshold := l_save_threshold;
6395 
6396     -- IF the number of messages is 1 then fetch the message code from
6397     -- the stack and return its text
6398     x_msg_count :=  FND_MSG_PUB.Count_Msg;
6399 
6400     IF x_msg_count = 1 THEN
6401         pa_interface_utils_pub.get_messages
6402             ( p_encoded       => FND_API.G_TRUE
6403              ,p_msg_index     => 1
6404              ,p_data          => x_msg_data
6405              ,p_msg_index_out => l_msg_index_out );
6406     END IF;
6407 
6408     -- Reset the error stack when returning to the calling program
6409     PA_DEBUG.Reset_Err_Stack;
6410 
6411     -- If g_error_exists is TRUE then set the x_return_status to 'E'
6412     IF FND_MSG_PUB.Count_Msg >0  THEN
6413         x_return_status := FND_API.G_RET_STS_ERROR;
6414     END IF;
6415 
6416 EXCEPTION
6417     WHEN OTHERS THEN
6418 
6419          -- Set the excetption Message and the stack
6420          FND_MSG_PUB.add_exc_msg
6421              ( p_pkg_name       => 'PA_ASGMT_WFSTD.process_mgr_fyi_notification'
6422               ,p_procedure_name => PA_DEBUG.G_Err_Stack );
6423 
6424          x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6425          RAISE;
6426 END process_mgr_fyi_notification;
6427 
6428 
6429 
6430 ----------------------------------------------------------------
6431 --This API is called inside the workflow to make the processing
6432 --of approval result a background process
6433 --It doest the processing of approval result by calling API
6434 --process_approval_result
6435 ----------------------------------------------------------------
6436 PROCEDURE process_approval_result_wf
6437     ( itemtype    IN      VARCHAR2
6438      ,itemkey     IN      VARCHAR2
6439      ,actid       IN      NUMBER
6440      ,funcmode    IN      VARCHAR2
6441      ,resultout   OUT     NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
6442      )
6443 IS
6444     l_msg_index_out         NUMBER;
6445     l_msg_count             NUMBER;
6446     l_msg_data              VARCHAR2(2000);
6447     l_return_status         VARCHAR2(1);
6448     x_return_status         VARCHAR2(1);
6452     l_project_id            pa_project_assignments.project_id%TYPE;
6449     x_msg_count             NUMBER;
6450     x_msg_data              VARCHAR2(2000);
6451 
6453     l_mode                  VARCHAR2(30);
6454     l_assignment_id_tbl     SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type();
6455     l_approval_status_tbl   SYSTEM.pa_varchar2_30_tbl_type:= SYSTEM.pa_varchar2_30_tbl_type();
6456     l_group_id              NUMBER;
6457     l_approver_group_id     NUMBER;
6458     l_routing_order         NUMBER;
6459     l_num_assignments       NUMBER;
6460     l_conflict_group_id     NUMBER;
6461     l_update_info_doc VARCHAR2(2000);
6462     l_submitter_user_name fnd_user.user_name%type; /* Commeted for bug 3261755 VARCHAR2(30); */
6463     l_note_to_approvers   VARCHAR2(2000);
6464     l_forwarded_from      fnd_user.user_name%type; /* Commeted for bug 3261755 VARCHAR2(30); */
6465     l_debug_mode VARCHAR2(1) := NVL(FND_PROFILE.value('PA_DEBUG_MODE'), 'N'); -- 5345171
6466 
6467 BEGIN
6468     log_message('Inside mass_process_approval_result_wf');
6469 
6470     -- Initialize the Error Stack
6471     PA_DEBUG.init_err_stack('PA_ASGMT_WFSTD.mass_process_approval_result_wf');
6472 
6473     --Log Message
6474     IF l_debug_mode = 'Y' THEN -- 5345171
6475         PA_DEBUG.write_log
6476         ( x_module      => 'pa.plsql.PA_ASGMT_WFSTD.mass_process_approval_result_wf.begin'
6477          ,x_msg         => 'Beginning of mass_assignment_approval'
6478          ,x_log_level   => 1);
6479     END IF;
6480 
6481     -- Initialize the return status to success
6482     x_return_status := FND_API.G_RET_STS_SUCCESS;
6483 
6484     --Clear the global PL/SQL message table
6485     FND_MSG_PUB.initialize;
6486 
6487     log_message('Inside mass_process_approval_result_wf 2');
6488 
6489     ---------------------------------------------------
6490     --Get the values required from the item attributes
6491     ---------------------------------------------------
6492     l_project_id := wf_engine.getItemAttrNumber
6493                         ( itemtype => itemtype
6494                         , itemkey  => itemkey
6495                         , aname    => 'PROJECT_ID' );
6496 
6497     l_mode := wf_engine.getItemAttrText
6498                   ( itemtype => itemtype
6499                   , itemkey  => itemkey
6500                   , aname    => 'MODE' );
6501 
6502     l_group_id := wf_engine.getItemAttrNumber
6503                         ( itemtype => itemtype
6504                         , itemkey  => itemkey
6505                         , aname    => 'GROUP_ID' );
6506 
6507     l_approver_group_id := wf_engine.getItemAttrNumber
6508                                ( itemtype => itemtype
6509                                , itemkey  => itemkey
6510                                , aname    => 'APPROVER_GROUP_ID' );
6511 
6512     l_routing_order := wf_engine.getItemAttrNumber
6513                            ( itemtype => itemtype
6514                            , itemkey  => itemkey
6515                            , aname    => 'ROUTING_ORDER' );
6516 
6517     l_num_assignments := wf_engine.getItemAttrNumber
6518                              ( itemtype => itemtype
6519                              , itemkey  => itemkey
6520                              , aname    => 'NUMBER_OF_ASSIGNMENTS' );
6521 
6522     --Get the Update Info document
6523     l_update_info_doc := wf_engine.getItemAttrDocument
6524                              ( itemtype => itemtype
6525                              , itemkey  => itemkey
6526                              , aname    => 'UPDATED_INFO_DOC' );
6527 
6528     l_submitter_user_name := wf_engine.getItemAttrText
6529                                   ( itemtype => itemtype
6530                                   , itemkey  => itemkey
6531                                   , aname    => 'SUBMITTER_UNAME');
6532 
6533     l_conflict_group_id := wf_engine.getItemAttrNumber
6534                            ( itemtype => itemtype
6535                            , itemkey  => itemkey
6536                            , aname    => 'CONFLICT_GROUP_ID' );
6537 
6538     l_forwarded_from := wf_engine.getItemAttrText
6539                                   ( itemtype => itemtype
6540                                   , itemkey  => itemkey
6541                                   , aname    => 'NTFY_APPRVL_RECIPIENT_NAME');
6542 
6543     l_note_to_approvers := wf_engine.getItemAttrText
6544                                   ( itemtype => itemtype
6545                                   , itemkey  => itemkey
6546                                   , aname    => 'NOTE_TO_APPROVER');
6547 
6548     -----------------------------------------------------------
6549     --Loop through all assignments and populate the assignment
6550     --and status tables
6551     --Also get number of approved and rejected assignments
6552     -----------------------------------------------------------
6553     FOR i IN 1..l_num_assignments LOOP
6554         l_assignment_id_tbl.extend;
6555         l_assignment_id_tbl(i) := wf_engine.getItemAttrNumber
6556                                       ( itemtype => itemtype
6557                                        ,itemkey  => itemkey
6558                                        ,aname    => 'ASSIGNMENT_'|| i );
6559 
6560         l_approval_status_tbl.extend;
6561         l_approval_status_tbl(i) := wf_engine.getItemAttrText
6562                                         ( itemtype => itemtype
6563                                          ,itemkey  => itemkey
6564                                          ,aname    => 'STATUS_'|| i );
6565     END LOOP;
6566 
6567     log_message('Before Calling process approval_result');
6568 
6569     process_approval_result
6570         ( p_project_id            => l_project_id
6571          ,p_mode                  => l_mode
6572          ,p_assignment_id_tbl     => l_assignment_id_tbl
6573          ,p_approval_status_tbl   => l_approval_status_tbl
6574          ,p_group_id              => l_group_id
6575          ,p_approver_group_id     => l_approver_group_id
6576          ,p_routing_order         => l_routing_order
6577          ,p_num_of_assignments    => l_num_assignments
6578          ,p_submitter_user_name   => l_submitter_user_name
6579          ,p_conflict_group_id     => l_conflict_group_id
6580          ,p_update_info_doc       => l_update_info_doc
6581          ,p_forwarded_from        => l_forwarded_from
6582          ,p_note_to_approvers     => l_note_to_approvers);
6583 
6584     log_message('After Calling process approval_result');
6585 
6586     ------------------------------------------------------------------
6587     -- IF the number of messages is 1 then fetch the message code from
6588     -- the stack and return its text
6589     ------------------------------------------------------------------
6590     x_msg_count :=  FND_MSG_PUB.Count_Msg;
6591 
6592     IF x_msg_count = 1 THEN
6593         pa_interface_utils_pub.get_messages
6594             ( p_encoded       => FND_API.G_TRUE
6595              ,p_msg_index     => 1
6596              ,p_data          => x_msg_data
6597              ,p_msg_index_out => l_msg_index_out );
6598     END IF;
6599 
6600     -- Reset the error stack when returning to the calling program
6601     PA_DEBUG.Reset_Err_Stack;
6602 
6603     -- If g_error_exists is TRUE then set the x_return_status to 'E'
6604     IF FND_MSG_PUB.Count_Msg >0  THEN
6605         x_return_status := FND_API.G_RET_STS_ERROR;
6606     END IF;
6607 
6608 EXCEPTION
6609     WHEN OTHERS THEN
6610 
6611          -- Set the excetption Message and the stack
6612          FND_MSG_PUB.add_exc_msg
6613              ( p_pkg_name       => 'PA_ASGMT_WFSTD.process_approval_result_wf'
6614               ,p_procedure_name => PA_DEBUG.G_Err_Stack );
6615 
6616          x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6617          RAISE;
6618 END process_approval_result_wf;
6619 
6620 -----------------------------------------------------------
6621 --This Procedure reverts the assignment status to
6622 --Working or Requires Re-submission from
6623 --submitted in case of errors
6624 -----------------------------------------------------------
6625 PROCEDURE Revert_assignment_status(
6626                    p_assignment_id IN  NUMBER
6627                   ,p_group_id      IN  NUMBER
6628                   ,x_return_status OUT NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
6629 IS
6630 
6631     CURSOR get_status_and_rec_num IS
6632     SELECT record_version_number
6633     FROM   pa_project_assignments
6634     WHERE  assignment_id = p_assignment_id;
6635 
6636     CURSOR get_assignment_status IS
6637     SELECT approval_status
6638     FROM   pa_wf_ntf_performers
6639     WHERE  group_id   = p_group_id
6640     AND    object_id1 = p_assignment_id
6641     AND    rownum     = 1;
6642 
6643     l_record_version_number      NUMBER;
6644     l_apprvl_status_code         pa_project_statuses.project_status_code%TYPE;
6645     l_return_status              VARCHAR2(1);
6646 
6647 BEGIN
6648 
6649     OPEN get_status_and_rec_num;
6650     FETCH get_status_and_rec_num INTO l_record_version_number;
6651     CLOSE get_status_and_rec_num;
6652 
6653     OPEN get_assignment_status;
6654     FETCH get_assignment_status INTO l_apprvl_status_code ;
6655     CLOSE get_assignment_status;
6656 
6657     PA_PROJECT_ASSIGNMENTS_PKG.Update_Row (
6658         p_assignment_id         => p_assignment_id
6659        ,p_record_version_number => l_record_version_number
6660        ,p_apprvl_status_code    => l_apprvl_status_code
6661        ,x_return_status         => l_return_status );
6662 
6663     x_return_status := l_return_status;
6664 
6665      ---------------------------------
6666     --Set the pending approval flag
6667     ---------------------------------
6668     Maintain_wf_pending_flag
6669         (p_assignment_id => p_assignment_id,
6670          p_mode          => 'APPROVAL_PROCESS_COMPLETED') ;
6671 
6672     log_message('After Maintain pending flag for assignment id:' || p_assignment_id);
6673 
6674     ---------------------------
6675     --Set the mass wf flag
6676     ---------------------------
6677     UPDATE pa_project_assignments
6678     SET    mass_wf_in_progress_flag = 'N'
6679     WHERE  assignment_id = p_assignment_id;
6680 
6681 EXCEPTION
6682      WHEN OTHERS THEN
6683 
6684          x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6685          RAISE;
6686 END Revert_assignment_status;
6687 
6688 ----------------------------------------------------------
6689 --This procedure does the per assignment approval processing
6690 --tasks
6691 -----------------------------------------------------------
6692 PROCEDURE process_assignment_tasks (
6693             p_assignment_id       IN NUMBER
6694            ,p_approval_status     IN pa_project_assignments.apprvl_status_code%TYPE
6695            ,p_action_code         IN VARCHAR2
6696            ,p_conflict_group_id   IN NUMBER
6697            ,p_project_id          IN NUMBER
6698            ,p_mode                IN VARCHAR2
6699            ,p_project_name        IN VARCHAR2
6700            ,p_project_number      IN VARCHAR2
6701            ,p_project_manager     IN VARCHAR2
6702            ,p_project_org         IN VARCHAR2
6703            ,p_project_cus         IN VARCHAR2
6704            ,p_submitter_user_name IN VARCHAR2
6705            ,p_group_id            IN NUMBER
6706            ,p_routing_order       IN NUMBER)
6707 
6708 IS
6709     PRAGMA AUTONOMOUS_TRANSACTION;
6710 
6711     l_change_id              NUMBER;
6712     l_aprvl_status_code      pa_project_assignments.apprvl_status_code%TYPE;
6713     l_resource_id            NUMBER;
6714     l_submitter_user_id      NUMBER;
6715     l_record_version_number1 NUMBER;
6716     l_record_version_number2 NUMBER;
6717     l_return_status          VARCHAR2(1);
6718     l_msg_count             NUMBER;
6719     l_msg_data              VARCHAR2(2000);
6720 
6721     CURSOR pending_approvals (c_assignment_id IN NUMBER) IS
6722     SELECT user_name
6723     FROM   pa_wf_ntf_performers ntf
6724     WHERE  ntf.group_id          = p_group_id
6725     AND    ntf.routing_order     = p_routing_order + 1
6726     AND    ntf.object_id1        = c_assignment_id;
6727 
6728     l_pending_approvals pending_approvals%ROWTYPE;
6729 
6730     CURSOR get_rec_num ( p_assignment_id IN NUMBER )IS
6731     SELECT record_version_number
6732     FROM pa_project_assignments
6733     WHERE assignment_id = p_assignment_id;
6734 
6735 BEGIN
6736 
6737         SAVEPOINT UPDATE_APPROVAL_STATUS;
6738 
6739         OPEN pending_approvals (p_assignment_id);
6740         FETCH pending_approvals INTO l_pending_approvals;
6741 
6742         IF (pending_approvals%NOTFOUND) OR (p_approval_status = PA_ASSIGNMENT_APPROVAL_PUB.g_reject_action) THEN
6743 
6744             log_message('No pending approvals for assignment:' || p_assignment_id);
6745 
6746             OPEN get_rec_num ( p_assignment_id );
6747             FETCH get_rec_num INTO l_record_version_number1;
6748             CLOSE get_rec_num;
6749 
6750             log_message('Record version number:' || l_record_version_number1);
6751             log_message('Before calling Update approval status');
6752 
6753             PA_ASSIGNMENT_APPROVAL_PVT.Update_Approval_Status
6754                 ( p_assignment_id         => p_assignment_id
6755                  ,p_action_code           => p_action_code
6756                  ,p_note_to_approver      => null
6757                  ,p_record_version_number => l_record_version_number1
6758                  ,x_apprvl_status_code    => l_aprvl_status_code
6759                  ,x_change_id             => l_change_id
6760                  ,x_record_version_number => l_record_version_number2
6761                  ,x_return_status         => l_return_status
6762                  ,x_msg_count             => l_msg_count
6763                  ,x_msg_data              => l_msg_data);
6764 
6765             log_message('After calling Update approval status');
6766             log_message('Before  Calling resolve conflicts:' || p_conflict_group_id);
6767 
6768             If (p_conflict_group_id IS NOT NULL) THEN
6769                PA_SCHEDULE_PVT.resolve_conflicts
6770                         ( p_conflict_group_id   => p_conflict_group_id
6771                          ,p_assignment_id       => p_assignment_id
6772                          ,x_return_status       => l_return_status
6773                          ,x_msg_count           => l_msg_count
6774                          ,x_msg_data            => l_msg_data);
6775             END IF;
6776 
6777             log_message('After Calling resolve conflicts');
6778 
6779             --------------------------------
6780             --Call resource fyi notification
6781             --------------------------------
6782             log_message('Before Calling process res fyi');
6783 
6784             process_res_fyi_notification
6785                 ( p_project_id        => p_project_id
6786                  ,p_mode              => p_mode
6787                  ,p_assignment_id     => p_assignment_id
6788                  ,p_project_name      => p_project_name
6789                  ,p_project_number    => p_project_number
6790                  ,p_project_manager   => p_project_manager
6791                  ,p_project_org       => p_project_org
6792                  ,p_project_cus       => p_project_cus
6793                  ,p_conflict_group_id => p_conflict_group_id
6794                  ,x_return_status     => l_return_status
6795                  ,x_msg_count         => l_msg_count
6796                  ,x_msg_data          => l_msg_data);
6797 
6798             log_message('After Calling process res fyi');
6799 
6800             IF FND_MSG_PUB.Count_Msg > 0 THEN
6801 
6802                log_message('Error in res_fyi');
6803 
6804                ROLLBACK TO  UPDATE_APPROVAL_STATUS;
6805 
6806                SELECT user_id
6807                INTO   l_submitter_user_id
6808                FROM   fnd_user
6809                WHERE  user_name = p_submitter_user_name;
6810 
6811                SELECT resource_id
6812                INTO   l_resource_id
6813                FROM   pa_project_assignments
6814                WHERE  assignment_id = p_assignment_id;
6815 
6816                --Revert assignment status back to Working or Requires Re-submission
6817                Revert_assignment_status(
6818                    p_assignment_id => p_assignment_id
6819                   ,p_group_id      => p_group_id
6820                   ,x_return_status => l_return_status);
6821 
6822                PA_MESSAGE_UTILS.save_messages
6823                    (p_user_id            =>  l_submitter_user_id,
6824                     p_source_type1       =>  PA_MASS_ASGMT_TRX.G_SOURCE_TYPE1,
6825                     p_source_type2       =>  'MASS_APPROVAL',
6826                     p_source_identifier1 =>  'PAWFAAP',
6827                     p_source_identifier2 =>  p_group_id,
6828                     p_context1           =>  p_project_id,
6829                     p_context2           =>  p_assignment_id,
6830                     p_context3           =>  l_resource_id,
6831                     p_commit             =>  FND_API.G_TRUE,
6832                     x_return_status      =>  l_return_status);
6833 
6834                log_message('After Error in res_fyi');
6835 
6836             ELSE
6837                 ----------------------------
6838                 --Commit per assignment
6839                 ----------------------------
6840                 COMMIT;
6841             END IF; --end l_return_status <> success
6842 
6843         ELSE
6844 
6845             COMMIT; --When pending_approvals not found
6846 
6847         END IF;--end pending_approvals%NOTFOUND
6848         CLOSE pending_approvals;
6849 
6850 EXCEPTION
6851     WHEN OTHERS THEN
6852 
6853          ROLLBACK TO UPDATE_APPROVAL_STATUS;
6854 
6855          RAISE;
6856 END process_assignment_tasks;
6857 
6858 ------------------------------------------------------------------
6859 --This API is called by the workflow API process_approval_result_wf
6860 --This API does the processing of approval result including sending
6861 --notifications to managers and resource
6862 -------------------------------------------------------------------
6863 PROCEDURE process_approval_result
6864     ( p_project_id                  IN NUMBER
6865      ,p_mode                        IN    VARCHAR2
6866      ,p_assignment_id_tbl           IN    SYSTEM.pa_num_tbl_type
6867      ,p_approval_status_tbl         IN    SYSTEM.pa_varchar2_30_tbl_type
6868      ,p_group_id                    IN    NUMBER
6869      ,p_approver_group_id           IN    NUMBER
6870      ,p_routing_order               IN    NUMBER
6871      ,p_num_of_assignments          IN    NUMBER
6872      ,p_submitter_user_name         IN    VARCHAR2
6873      ,p_conflict_group_id           IN    NUMBER
6874      ,p_update_info_doc             IN    VARCHAR2
6875      ,p_forwarded_from              IN    VARCHAR2
6876      ,p_note_to_approvers           IN    VARCHAR2)
6877 IS
6878     l_approval_status       pa_project_assignments.apprvl_status_code%TYPE;
6879     l_aprvl_status_code     pa_project_assignments.apprvl_status_code%TYPE;
6880     l_change_id             NUMBER;
6881     l_action_code           VARCHAR2(30);
6882     l_approver_group_id     NUMBER;
6883     l_assignment_id_tbl     SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type();
6884     l_msg_index_out         NUMBER;
6885     l_msg_count             NUMBER;
6886     l_msg_data              VARCHAR2(2000);
6887     l_return_status         VARCHAR2(1);
6888     x_return_status         VARCHAR2(1);
6889     x_msg_count             NUMBER;
6890     x_msg_data              VARCHAR2(2000);
6891     l_error_message_code    VARCHAR(30);
6892     x_error_message_code  VARCHAR2(30);
6893 
6894 /*  Commented and altered as below for bug 5595003
6895     CURSOR distinct_approvers IS
6896     SELECT distinct user_name
6897     FROM   pa_wf_ntf_performers ntf,
6898            pa_project_assignments asgn
6899     WHERE  ntf.group_id            = p_group_id
6900     AND    ntf.object_id1          = asgn.assignment_id
6901     AND    asgn.apprvl_status_code = PA_ASSIGNMENT_APPROVAL_PUB.g_submitted
6902     AND    ntf.routing_order       = p_routing_order + 1; */
6903 
6904     CURSOR distinct_approvers IS
6905     SELECT distinct ntf.user_name
6906     FROM   pa_wf_ntf_performers ntf,
6907            pa_project_assignments asgn,
6908 	   pa_wf_ntf_performers ntf1
6909     WHERE  ntf.group_id            = p_group_id
6910     AND    ntf.object_id1          = asgn.assignment_id
6911     AND    asgn.apprvl_status_code = PA_ASSIGNMENT_APPROVAL_PUB.g_submitted
6912     AND    ntf.routing_order       = p_routing_order + 1
6913     AND    ntf1.group_id            = p_group_id
6914     AND    ntf1.object_id1          = asgn.assignment_id
6915     AND    ntf1.routing_order       = p_routing_order
6916     AND    ntf1.approver_group_id   = p_approver_group_id;
6917 
6918     CURSOR pending_txn_approvals IS
6919     SELECT 'Y'
6920     FROM   pa_wf_ntf_performers ntf,
6921            pa_project_assignments asgn
6922     WHERE  ntf.group_id            = p_group_id
6923     AND    ntf.object_id1          = asgn.assignment_id
6924     AND    asgn.apprvl_status_code = PA_ASSIGNMENT_APPROVAL_PUB.g_submitted;
6925 
6926     l_pending_txn_approvals pending_txn_approvals%ROWTYPE;
6927 
6928     l_num_apr_asgns NUMBER;
6929     l_num_rej_asgns NUMBER;
6930 
6931     l_customer_id         NUMBER;
6932     l_customer_name       VARCHAR2(2000);
6933     l_project_manager_person_id   NUMBER ;
6934     l_project_manager_name        per_all_people_f.full_name%TYPE;--VARCHAR2(200);  Commented For 3267790
6935     l_project_party_id            NUMBER ;
6936     l_project_role_id             NUMBER ;
6937     l_project_role_name           VARCHAR2(80);
6938 
6939     CURSOR l_projects_csr(l_project_id IN NUMBER) IS
6940     SELECT pap.project_id project_id,
6941            pap.name name,
6945            hr.name organization_name,
6942            pap.segment1 segment1,
6943            pap.carrying_out_organization_id carrying_out_organization_id,
6944            pap.location_id,
6946            NVL(pt.administrative_flag,'N') admin_flag
6947     FROM   pa_projects_all pap,
6948            hr_all_organization_units hr,
6949            pa_project_types_all pt
6950     WHERE  pap.project_id = l_project_id
6951     AND    pap.carrying_out_organization_id = hr.organization_id
6952     AND    pap.org_id = pt.org_id    -- Added for Bug 5389093
6953     AND    pt.project_type = pap.project_type;
6954 
6955     l_projects_rec l_projects_csr%ROWTYPE;
6956     l_update_info_doc VARCHAR2(2000);
6957 
6958     l_submitter_user_id NUMBER;
6959 
6960     CURSOR sub_not_required_csr IS
6961     SELECT 'Y'
6962     FROM    PA_REPORTING_EXCEPTIONS
6963     WHERE  user_id            = l_submitter_user_id
6964     AND    context            = PA_MASS_ASGMT_TRX.G_SOURCE_TYPE1
6965     AND    sub_context        =  'MASS_APPROVAL'
6966     AND    source_identifier1 = 'PAWFAAP'
6967     AND    source_identifier2 =  p_group_id;
6968 
6969     l_sub_not_required_rec sub_not_required_csr%ROWTYPE;
6970 
6971 
6972 BEGIN
6973 
6974     log_message('Inside process approval result');
6975     -----------------------------------------------------------
6976     --Get the Project information for FYI notifications
6977     -------------------------------------------------------
6978     OPEN l_projects_csr( p_project_id);
6979     FETCH l_projects_csr INTO l_projects_rec;
6980     IF l_projects_csr%NOTFOUND THEN
6981         pa_utils.add_message (p_app_short_name  => 'PA',
6982                               p_msg_name        => 'PA_INVALID_PROJECT_ID');
6983     END IF;
6984     CLOSE l_projects_csr;
6985 
6986     Check_And_Get_Proj_Customer
6987         (p_project_id    => p_project_id
6988         ,x_customer_id   => l_customer_id
6989         ,x_customer_name => l_customer_name );
6990 
6991     -- Get the project manager details
6992     pa_project_parties_utils.get_curr_proj_mgr_details
6993         (p_project_id         => l_projects_rec.project_id
6994         ,x_manager_person_id  => l_project_manager_person_id
6995         ,x_manager_name       => l_project_manager_name
6996         ,x_project_party_id   => l_project_party_id
6997         ,x_project_role_id    => l_project_role_id
6998         ,x_project_role_name  => l_project_role_name
6999         ,x_return_status      => l_return_status
7000         ,x_error_message_code => l_error_message_code );
7001 
7002     -- Only non-admin projects require a manager
7003     IF l_projects_rec.admin_flag = 'N' THEN
7004         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7005             x_return_status := l_return_status;
7006             x_error_message_code := l_error_message_code;
7007             pa_utils.add_message (p_app_short_name  => 'PA',
7008                                   p_msg_name        => l_error_message_code);
7009         END IF;
7010     END IF;
7011 
7012     ----------------------------------------
7013     --Start processing the approval result
7014     ----------------------------------------
7015 
7016     FOR i IN 1..p_assignment_id_tbl.COUNT LOOP
7017 
7018         l_approval_status  := p_approval_status_tbl(i);
7019 
7020         IF l_approval_status = PA_ASSIGNMENT_APPROVAL_PUB.g_approve_action THEN
7021 
7022             l_action_code := PA_ASSIGNMENT_APPROVAL_PUB.g_approve_action;
7023             --l_num_apr_asgns := l_num_apr_asgns + 1;
7024 
7025         ELSIF l_approval_status = PA_ASSIGNMENT_APPROVAL_PUB.g_reject_action THEN
7026 
7027             l_action_code := PA_ASSIGNMENT_APPROVAL_PUB.g_reject_action;
7028             --l_num_rej_asgns := l_num_rej_asgns + 1;
7029 
7030         END IF;
7031 
7032         ----------------------------------------------------------------------
7033         --The API below does the per assignment approval result processing tasks
7034         ----------------------------------------------------------------------
7035         log_message('Check if there are any pending approvals for assignment:' ||p_assignment_id_tbl(i) );
7036         log_message('Routing order:' || p_routing_order);
7037 
7038         process_assignment_tasks (
7039             p_assignment_id       => p_assignment_id_tbl(i)
7040            ,p_approval_status     => l_approval_status
7041            ,p_action_code         => l_action_code
7042            ,p_conflict_group_id   => p_conflict_group_id
7043            ,p_project_id          => p_project_id
7044            ,p_mode                => p_mode
7045            ,p_project_name        => l_projects_rec.name
7046            ,p_project_number      => l_projects_rec.segment1
7047            ,p_project_manager     => l_project_manager_name
7048            ,p_project_org         => l_projects_rec.organization_name
7049            ,p_project_cus         => l_customer_name
7050            ,p_submitter_user_name => p_submitter_user_name
7051            ,p_group_id            => p_group_id
7052            ,p_routing_order       => p_routing_order
7053         );
7054 
7055     END LOOP; --end i loop
7056 
7057     ---------------------------------------------------
7058     --For each distinct approvers in next routing order
7059     --start approval required notification
7060     ---------------------------------------------------
7061     FOR rec IN distinct_approvers LOOP
7062 
7063         SELECT PA_WF_NTF_PERFORMERS_S.nextval
7064         INTO   l_approver_group_id
7065         FROM   dual;
7066 
7067         /* Commented and altered as below for bug 5595003
7068 	UPDATE pa_wf_ntf_performers
7069         SET    approver_group_id = l_approver_group_id
7070         WHERE  group_id          = p_group_id
7071         AND    user_name         = rec.user_name
7072         AND    routing_order     = p_routing_order + 1;  */
7073 
7074 	FORALL  k in p_assignment_id_tbl.first..p_assignment_id_tbl.last
7075 		UPDATE pa_wf_ntf_performers
7076 		SET    approver_group_id = l_approver_group_id
7077 		WHERE  group_id          = p_group_id
7078 		AND    user_name         = rec.user_name
7079 		AND    routing_order     = p_routing_order + 1
7080 		AND    object_id1        = p_assignment_id_tbl(k)
7081 		AND    p_approval_status_tbl(k) = PA_ASSIGNMENT_APPROVAL_PUB.g_approve_action;
7082 
7083         log_message('New approver group id:' || l_approver_group_id);
7084 
7085         ----------------------------------------------------------
7086         --Call API to start one workflow for each grouped approver
7087         ----------------------------------------------------------
7088         log_message('Before Calling start_mass_approval_flow for approver :' || rec.user_name);
7089 
7090         start_mass_approval_flow
7091                    (p_project_id           => p_project_id
7092                    ,p_mode                 => p_mode
7093                    ,p_note_to_approvers    => p_note_to_approvers
7094                    ,p_forwarded_from       => p_forwarded_from
7095                    ,p_performer_user_name  => rec.user_name
7096                    ,p_routing_order        => p_routing_order + 1
7097                    ,p_group_id             => p_group_id
7098                    ,p_approver_group_id    => l_approver_group_id
7099                    ,p_project_name         => l_projects_rec.name
7100                    ,p_project_number       => l_projects_rec.segment1
7101                    ,p_project_manager      => l_project_manager_name
7102                    ,p_project_org          => l_projects_rec.organization_name
7103                    ,p_project_cus          => l_customer_name
7104                    ,p_conflict_group_id    => p_conflict_group_id
7105                    ,p_submitter_user_name  => p_submitter_user_name
7106                    ,x_return_status        => l_return_status
7107                    ,x_msg_count            => l_msg_count
7108                    ,x_msg_data             => l_msg_data);
7109 
7110         log_message('After Calling start_mass_approval_flow for approver :' || rec.user_name);
7111 
7112     END LOOP;--end distinct approvers loop
7113 
7114     ---------------------------------------------------------------------
7115     -- Call FYI Notifications for Managers if all status have been changed
7116     -- for this mass transaction
7117     -- And call schedule APIs to resolve overcommitment conflict.
7118     ---------------------------------------------------------------------
7119     log_message('Checking pending txn approvals');
7120 
7121     OPEN pending_txn_approvals;
7122     FETCH pending_txn_approvals INTO l_pending_txn_approvals;
7123 
7124     IF pending_txn_approvals%NOTFOUND THEN
7125 
7126         BEGIN
7127 
7128             --Get all assignments in this mass transaction
7129             SELECT ntf.object_id1
7130             BULK COLLECT INTO l_assignment_id_tbl
7131             FROM   pa_wf_ntf_performers ntf
7132             WHERE  ntf.group_id            = p_group_id
7133             AND    ntf.routing_order       = 1;
7134         EXCEPTION
7135             WHEN NO_DATA_FOUND THEN
7136                 null;
7137         END;
7138 
7139         --Reset the number of approved and rejected assignments
7140         l_num_apr_asgns := 0;
7141         l_num_rej_asgns := 0;
7142 
7143         FOR i IN 1..l_assignment_id_tbl.COUNT LOOP
7144 
7145             l_approval_status := null;
7146 
7147             BEGIN
7148                 SELECT apprvl_status_code
7149                 INTO   l_approval_status
7150                 FROM   pa_project_assignments
7151                 WHERE  assignment_id = l_assignment_id_tbl(i);
7152             EXCEPTION
7153                 WHEN NO_DATA_FOUND THEN
7154                 null;
7155             END;
7156 
7157            IF l_approval_status = PA_ASSIGNMENT_APPROVAL_PUB.g_approved THEN
7158 
7159                l_num_apr_asgns := l_num_apr_asgns + 1;
7160 
7161            ELSIF l_approval_status = PA_ASSIGNMENT_APPROVAL_PUB.g_rejected THEN
7162 
7163                l_num_rej_asgns := l_num_rej_asgns + 1;
7164 
7165            END IF;
7166         END LOOP;
7167 
7168         log_message('Calling mgr fyi notification');
7169 
7170         process_mgr_fyi_notification
7171             ( p_assignment_id_tbl   => l_assignment_id_tbl
7172              ,p_project_id          => p_project_id
7173              ,p_mode                => p_mode
7174              ,p_group_id            => p_group_id
7175              ,p_update_info_doc     => l_update_info_doc
7176              ,p_num_apr_asgns       => l_num_apr_asgns
7177              ,p_num_rej_asgns       => l_num_rej_asgns
7178              ,p_project_name        => l_projects_rec.name
7179              ,p_project_number      => l_projects_rec.segment1
7180              ,p_project_manager     => l_project_manager_name
7181              ,p_project_org         => l_projects_rec.organization_name
7182              ,p_project_cus         => l_customer_name
7183              ,p_submitter_user_name => p_submitter_user_name
7184              ,p_conflict_group_id   => p_conflict_group_id
7185              ,x_return_status       => l_return_status
7186              ,x_msg_count           => l_msg_count
7187              ,x_msg_data            => l_msg_data);
7188 
7189          log_message('Calling overcom_post_aprvl_processing');
7190 
7191         ------------------------------------------------------------------
7192         --This API is called to send notifications to conflicting managers
7193         ------------------------------------------------------------------
7194         PA_SCHEDULE_PVT.overcom_post_aprvl_processing
7195                         ( p_conflict_group_id   => p_conflict_group_id
7196                          ,p_fnd_user_name       => p_submitter_user_name
7197                          ,x_return_status       => l_return_status
7198                          ,x_msg_count           => l_msg_count
7199                          ,x_msg_data            => l_msg_data);
7200 
7201         BEGIN
7202                SELECT user_id
7203                INTO   l_submitter_user_id
7204                FROM   fnd_user
7205                WHERE  user_name = p_submitter_user_name;
7206         EXCEPTION
7207             WHEN NO_DATA_FOUND THEN
7208             null;
7209         END;
7210         ------------------------------------------------
7211         --This API processes the submitter notifcations
7212         ------------------------------------------------
7213 
7214         OPEN sub_not_required_csr;
7215         FETCH sub_not_required_csr INTO l_sub_not_required_rec;
7216 
7217         IF sub_not_required_csr%FOUND THEN
7218 
7219         log_message('Calling submitter notification');
7220 
7221         process_submitter_notification
7222                 (p_project_id          => p_project_id
7223                 ,p_mode                => p_mode
7224                 ,p_group_id            => p_group_id
7225                 ,p_update_info_doc     => l_update_info_doc
7226                 ,p_num_apr_asgns       => l_num_apr_asgns
7227                 ,p_num_rej_asgns       => l_num_rej_asgns
7228                 ,p_project_name        => l_projects_rec.name
7229                 ,p_project_number      => l_projects_rec.segment1
7230                 ,p_project_manager     => l_project_manager_name
7231                 ,p_project_org         => l_projects_rec.organization_name
7232                 ,p_project_cus         => l_customer_name
7233                 ,p_submitter_user_name => p_submitter_user_name
7234                 ,x_return_status       => l_return_status
7235                 ,x_msg_count           => l_msg_count
7236                 ,x_msg_data            => l_msg_data);
7237 
7238         END IF;
7239         CLOSE sub_not_required_csr;
7240 
7241     END IF; --end call to fyi notifications
7242     CLOSE pending_txn_approvals;
7243 
7244     log_message('After call to mgr fyi');
7245 
7246 EXCEPTION
7247     WHEN OTHERS THEN
7248          x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
7249          RAISE;
7250 END process_approval_result;
7251 
7252 -----------------------------------------------------------
7253 --This API processes the notification sent to the submitter
7254 --if there are errors in the end of the mass transaction
7255 --approval process
7256 --This API raises a NO_ASSIGNMENT_ERRORS EXCEPTION
7257 --when there are no errors and in that case notification
7258 --is not sent to the submitter
7259 -----------------------------------------------------------
7260 PROCEDURE process_submitter_notification
7261     ( p_project_id           IN   NUMBER    := FND_API.G_MISS_NUM
7262      ,p_mode                 IN  VARCHAR2
7263      ,p_group_id             IN   NUMBER    := FND_API.G_MISS_NUM
7264      ,p_update_info_doc      IN   VARCHAR2  := FND_API.G_MISS_CHAR
7265      ,p_num_apr_asgns        IN   NUMBER
7266      ,p_num_rej_asgns        IN   NUMBER
7267      ,p_project_name         IN   VARCHAR2
7268      ,p_project_number       IN   VARCHAR2
7269      ,p_project_manager      IN   VARCHAR2
7270      ,p_project_org          IN   VARCHAR2
7271      ,p_project_cus          IN   VARCHAR2
7272      ,p_submitter_user_name  IN   VARCHAR2
7273      ,p_assignment_id        IN   NUMBER := FND_API.G_MISS_NUM
7274      ,x_return_status        OUT  NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
7275      ,x_msg_count            OUT  NOCOPY NUMBER --File.Sql.39 bug 4440895
7276      ,x_msg_data             OUT  NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
7277 IS
7278 
7279     l_itemkey             VARCHAR2(30);
7280     l_responsibility_id   NUMBER;
7281     l_resp_appl_id        NUMBER;
7282     l_wf_started_date     DATE;
7283     l_wf_started_by_id    NUMBER;
7284     l_return_status       VARCHAR2(1);
7285     l_error_message_code  VARCHAR2(30);
7286     x_error_message_code  VARCHAR2(30);
7287     l_save_threshold      NUMBER;
7288     l_msg_count           NUMBER ;
7289     l_msg_index_out       NUMBER ;
7290     l_msg_data            VARCHAR2(2000);
7291     l_wf_item_type        VARCHAR2(2000):= 'PARMAAP'; --Assignment Approval Item type
7292     l_wf_process          VARCHAR2(2000);
7293     l_err_code            NUMBER := 0;
7294     l_err_stage           VARCHAR2(2000);
7295     l_err_stack           VARCHAR2(2000);
7296     l_assignment_id       NUMBER;
7297     l_error_asgns_count   NUMBER := 0;
7298     l_view_errors_url     VARCHAR2(2000);
7299 
7300     CURSOR l_assignments_csr (l_assignment_id IN NUMBER ) IS
7301     SELECT
7305        ppa.additional_information,
7302        ppa.project_id,
7303        ppa.assignment_name,
7304        ppa.assignment_effort,
7306        ppa.description,
7307        ppa.start_date,
7308        ppa.end_date,
7309        ppa.revenue_bill_rate,
7310        ppa.revenue_currency_code,
7311        ppa.bill_rate_override,
7312        ppa.bill_rate_curr_override,
7313        ppa.markup_percent_override,
7314        ppa.fcst_tp_amount_type_name,
7315        ppa.tp_rate_override,
7316        ppa.tp_currency_override,
7317        ppa.tp_calc_base_code_override,
7318        ppa.tp_percent_applied_override,
7319        ppa.work_type_name,
7320        hr.name
7321     FROM pa_project_assignments_v ppa,
7322          pa_resources_denorm res,
7323          hr_all_organization_units hr
7324     WHERE assignment_id        = l_assignment_id
7325     AND   res.resource_id      = ppa.resource_id
7326     AND   ppa.start_date BETWEEN res.resource_effective_start_date
7327                              AND res.resource_effective_end_date
7328     AND   hr.organization_id   = res.resource_organization_id;
7329 
7330     l_assignments_rec l_assignments_csr%ROWTYPE;
7331 
7332 CURSOR csr_get_override_basis_name (p_override_basis_code IN VARCHAR2) IS
7333 SELECT plks.meaning
7334 FROM   pa_lookups plks
7335 WHERE  plks.lookup_type = 'CC_MARKUP_BASE_CODE'
7336 AND    plks.lookup_code = p_override_basis_code;
7337 
7338     CURSOR count_error_asgns IS
7339     SELECT count( distinct ( attribute2))
7340     FROM   PA_REPORTING_EXCEPTIONS
7341     WHERE  context            = PA_MASS_ASGMT_TRX.G_SOURCE_TYPE1
7342       AND  sub_context        = 'MASS_APPROVAL'
7343       AND  source_identifier1 = 'PAWFAAP'
7344       AND  source_identifier2 = p_group_id;
7345 
7346       NO_ASSIGNMENT_ERRORS EXCEPTION;
7347 
7348 l_override_basis_name VARCHAR2(80) := NULL;
7349 l_debug_mode VARCHAR2(1) := NVL(FND_PROFILE.value('PA_DEBUG_MODE'), 'N'); -- 5345171
7350 
7351 
7352 BEGIN
7353 
7354     -- Initialize the Error Stack
7355     PA_DEBUG.init_err_stack('PA_ASGMT_WFSTD.process_submitter_notification');
7356 
7357     --Log Message
7358     IF l_debug_mode = 'Y' THEN -- 5345171
7359         PA_DEBUG.write_log
7360         ( x_module      => 'pa.plsql.PA_ASGMT_WFSTD.process_submitter_notification.begin'
7361          ,x_msg         => 'Beginning of mass fyi workflow api'
7362          ,x_log_level   => 1);
7363     END IF;
7364 
7365     -- Initialize the return status to success
7366     x_return_status := FND_API.G_RET_STS_SUCCESS;
7367 
7368     --Clear the global PL/SQL message table
7369     FND_MSG_PUB.initialize;
7370     x_msg_count := 0;
7371 
7372     log_message('Inside submitter notification');
7373 
7374     --Setting local variables
7375     OPEN count_error_asgns;
7376     FETCH count_error_asgns INTO l_error_asgns_count;
7377     CLOSE count_error_asgns;
7378 
7379     log_message('Error messages:' || l_error_asgns_count);
7380 
7381     -----------------------------------------------------------
7382     --If there are no errors this notiifcation must not be sent
7383     -----------------------------------------------------------
7384     IF l_error_asgns_count = 0 THEN
7385         RAISE NO_ASSIGNMENT_ERRORS;
7386     END IF;
7387     --------------------------------------
7388     --Start Submitter Notification workflow
7389     --------------------------------------
7390     l_wf_started_by_id  := FND_GLOBAL.user_id;
7391     l_responsibility_id := FND_GLOBAL.resp_id;
7392     l_resp_appl_id      := FND_GLOBAL.resp_appl_id;
7393 
7394     FND_GLOBAL.Apps_Initialize ( user_id      => l_wf_started_by_id
7395                                , resp_id      => l_responsibility_id
7396                                , resp_appl_id => l_resp_appl_id );
7397 
7398     -- Setting thresold value to run the process in background
7399     l_save_threshold    := wf_engine.threshold;
7400     wf_engine.threshold := -1;
7401 
7402     ----------------------------------------------------------------
7403     --Getting all local variables required for workflow attributes
7404     ---------------------------------------------------------------
7405 
7406     -- Create the unique item key to launch WF with
7407     SELECT pa_prm_wf_item_key_s.nextval
7408     INTO   l_itemkey
7409     FROM   dual;
7410 
7411     log_message('The value of p_mode is:' || p_mode );
7412      log_message('The value of item_key is :' || l_itemkey );
7413     -----------------------------------------------------------------------------
7414     --Setting Process Creation / Update / Aproval submission  mode
7415     -----------------------------------------------------------------------------
7416     IF p_mode = PA_MASS_ASGMT_TRX.G_MASS_ASGMT THEN
7417 
7418         l_wf_process := 'PA_MASS_APRVL_SUB_CRN';
7419 
7420     ELSIF (p_mode = PA_MASS_ASGMT_TRX.G_MASS_UPDATE_ASGMT_BASIC_INFO OR
7421            p_mode = PA_MASS_ASGMT_TRX.G_MASS_UPDATE_COMPETENCIES     OR
7422            p_mode = PA_MASS_ASGMT_TRX.G_MASS_UPDATE_FORECAST_ITEMS   OR
7423            p_mode = PA_MASS_ASGMT_TRX.G_MASS_UPDATE_SCHEDULE )
7424     THEN
7425 
7426         l_wf_process := 'PA_MASS_APRVL_SUB_UPD';
7427 
7428     ELSIF  p_mode = PA_MASS_ASGMT_TRX.G_MASS_SUBMIT_FOR_APPROVAL THEN
7429 
7430         l_wf_process := 'PA_MASS_APRVL_SUB_APS';
7431 
7432     END IF;
7433 
7434      -- Create the WF process
7435     wf_engine.CreateProcess
7436         ( ItemType => l_wf_item_type
7437         , ItemKey  => l_itemkey
7438         , process  => l_wf_process );
7439 
7440     log_message('After creating process');
7441 
7442     ------------------------------------------------------------
7443     --Set the item attributes required for submitter notification
7444     --based on the mode
7445     ------------------------------------------------------------
7446     IF p_mode = PA_MASS_ASGMT_TRX.G_MASS_ASGMT THEN
7447 
7448             BEGIN
7449                 SELECT object_id1
7450                 INTO   l_assignment_id
7451                 FROM   pa_wf_ntf_performers
7452                 WHERE  group_id = p_group_id
7453                 AND    rownum   = 1;
7454             EXCEPTION
7455                 WHEN NO_DATA_FOUND THEN
7456                     l_assignment_id := p_assignment_id;
7457                 WHEN OTHERS THEN
7458                    null;
7459             END;
7460 
7461             OPEN l_assignments_csr (l_assignment_id);
7462             FETCH l_assignments_csr INTO l_assignments_rec;
7463 
7464             IF l_assignments_csr%NOTFOUND THEN
7465                x_return_status := FND_API.G_RET_STS_ERROR;
7466                    pa_utils.add_message (p_app_short_name  => 'PA',
7467                                          p_msg_name        => 'PA_INVALID_ASMGT_ID');
7468             END IF;
7469 
7470             CLOSE l_assignments_csr;
7471 
7472             wf_engine.SetItemAttrText
7473                  ( itemtype => l_wf_item_type
7474                  , itemkey  => l_itemkey
7475                  , aname    => 'ASSIGNMENT_NAME'
7476                  , avalue   => l_assignments_rec.assignment_name );
7477 
7478             wf_engine.SetItemAttrText
7479                 ( itemtype => l_wf_item_type
7480                 , itemkey  => l_itemkey
7481                 , aname    => 'RESOURCE_ORGANIZATION'
7482                 , avalue   => l_assignments_rec.name );
7483 
7484             wf_engine.SetItemAttrNumber
7485                 ( itemtype => l_wf_item_type
7486                 , itemkey  => l_itemkey
7487                 , aname    => 'ASSIGNMENT_DURATION'
7488                 , avalue   => (trunc(l_assignments_rec.end_date) -
7489                                trunc(l_assignments_rec.start_date)+1) );
7490 
7491             wf_engine.SetItemAttrNumber
7492                 ( itemtype => l_wf_item_type
7493                 , itemkey  => l_itemkey
7494                 , aname    => 'ASSIGNMENT_EFFORT'
7495                 , avalue   => l_assignments_rec.assignment_effort );
7496 
7497             wf_engine.SetItemAttrText
7498                 ( itemtype => l_wf_item_type
7499                 , itemkey  => l_itemkey
7500                 , aname    => 'DESCRIPTION'
7501                 , avalue   => l_assignments_rec.description );
7502 
7503             wf_engine.SetItemAttrText
7504                 ( itemtype => l_wf_item_type
7505                 , itemkey  => l_itemkey
7506                 , aname    => 'ADDITIONAL_INFORMATION'
7507                 , avalue   => l_assignments_rec.additional_information );
7508 
7509            -- Start Additions by RM for bug 2274426
7510            wf_engine.SetItemAttrNumber
7511                                ( itemtype => l_wf_item_type
7512                                , itemkey => l_itemkey
7513                                , aname => 'REVENUE_BILL_RATE'
7514                                , avalue => l_assignments_rec.revenue_bill_rate
7515                                );
7516            wf_engine.SetItemAttrText
7517                             ( itemtype => l_wf_item_type
7518                             , itemkey => l_itemkey
7519                             , aname => 'REVENUE_BILL_RATE_CURR'
7520                             , avalue => l_assignments_rec.revenue_currency_code
7521                             );
7522            wf_engine.SetItemAttrNumber
7523                                ( itemtype => l_wf_item_type
7524                                , itemkey => l_itemkey
7525                                , aname => 'BILL_RATE_OVERRIDE'
7526                                , avalue => l_assignments_rec.bill_rate_override
7527                                );
7528            wf_engine.SetItemAttrText
7529                           ( itemtype => l_wf_item_type
7530                           , itemkey => l_itemkey
7531                           , aname => 'BILL_RATE_OVERRIDE_CURR'
7532                           , avalue => l_assignments_rec.bill_rate_curr_override
7533                           );
7534            IF l_assignments_rec.markup_percent_override IS NOT NULL THEN
7535               wf_engine.SetItemAttrText
7536                           ( itemtype => l_wf_item_type
7537                           , itemkey => l_itemkey
7538                           , aname => 'MARKUP_PCT_OVERRIDE'
7539                           , avalue => to_char(l_assignments_rec.markup_percent_override)||'%'
7540                           );
7541            ELSE
7542                wf_engine.SetItemAttrText
7543                           ( itemtype => l_wf_item_type
7544                           , itemkey => l_itemkey
7545                           , aname => 'MARKUP_PCT_OVERRIDE'
7546                           , avalue => to_char(l_assignments_rec.markup_percent_override)
7547                           );
7548            END IF;
7549            wf_engine.SetItemAttrText
7550                           ( itemtype => l_wf_item_type
7551                           , itemkey => l_itemkey
7552                           , aname => 'TP_AMT_TYPE_NAME'
7553                           , avalue => l_assignments_rec.fcst_tp_amount_type_name
7554                           );
7555            wf_engine.SetItemAttrNumber
7556                           ( itemtype => l_wf_item_type
7557                           , itemkey => l_itemkey
7558                           , aname => 'TP_RATE_OVERRIDE'
7559                           , avalue => l_assignments_rec.tp_rate_override
7560                           );
7561            wf_engine.SetItemAttrText
7562                           ( itemtype => l_wf_item_type
7563                           , itemkey => l_itemkey
7564                           , aname => 'TP_RATE_OVERRIDE_CURR'
7565                           , avalue => l_assignments_rec.tp_currency_override
7566                           );
7567            IF l_assignments_rec.tp_calc_base_code_override IS NOT NULL THEN
7568               open csr_get_override_basis_name(l_assignments_rec.tp_calc_base_code_override);
7569               fetch csr_get_override_basis_name into l_override_basis_name;
7570               close csr_get_override_basis_name;
7571            END IF;
7572            wf_engine.SetItemAttrText
7573                           ( itemtype => l_wf_item_type
7574                           , itemkey => l_itemkey
7575                           , aname => 'OVERRIDE_BASIS_NAME'
7576                           , avalue => l_override_basis_name
7577                           );
7578            IF l_assignments_rec.tp_percent_applied_override IS NOT NULL THEN
7579               IF l_override_basis_name IS NOT NULL THEN
7580                  wf_engine.SetItemAttrText
7581                      ( itemtype => l_wf_item_type
7582                      , itemkey => l_itemkey
7583                      , aname => 'TP_PCT_APPLIED_OVERRIDE'
7584                      , avalue => ', '||to_char(l_assignments_rec.tp_percent_applied_override)||'%'
7585                      );
7586               ELSE
7587                  wf_engine.SetItemAttrText
7588                      ( itemtype => l_wf_item_type
7589                      , itemkey => l_itemkey
7590                      , aname => 'TP_PCT_APPLIED_OVERRIDE'
7591                      , avalue => to_char(l_assignments_rec.tp_percent_applied_override)||'%'
7592                      );
7593               END IF;
7594            ELSE
7595               wf_engine.SetItemAttrText
7596                      ( itemtype => l_wf_item_type
7597                      , itemkey => l_itemkey
7598                      , aname => 'TP_PCT_APPLIED_OVERRIDE'
7599                      , avalue => to_char(l_assignments_rec.tp_percent_applied_override)
7600                      );
7601            END IF;
7602            wf_engine.SetItemAttrText
7603                           ( itemtype => l_wf_item_type
7604                           , itemkey => l_itemkey
7605                           , aname => 'WORK_TYPE_NAME'
7606                           , avalue => l_assignments_rec.work_type_name
7607                           );
7608            -- End of Additions by RM
7609 
7610             --Setting Successful assignments count
7611             wf_engine.SetItemAttrNumber
7612                 ( itemtype => l_wf_item_type
7613                 , itemkey  => l_itemkey
7614                 , aname    => 'APPROVED_ASSIGNMENTS'
7615                 , avalue   => p_num_apr_asgns + p_num_rej_asgns);
7616 
7617         ELSIF (p_mode = PA_MASS_ASGMT_TRX.G_MASS_UPDATE_ASGMT_BASIC_INFO OR
7618                p_mode = PA_MASS_ASGMT_TRX.G_MASS_UPDATE_COMPETENCIES     OR
7619                p_mode = PA_MASS_ASGMT_TRX.G_MASS_UPDATE_FORECAST_ITEMS   OR
7620                p_mode = PA_MASS_ASGMT_TRX.G_MASS_UPDATE_SCHEDULE )
7621 
7622         THEN
7623             wf_engine.SetItemAttrDocument
7624                 ( itemtype => l_wf_item_type
7625                 , itemkey  => l_itemkey
7626                 , aname    => 'UPDATED_INFO_DOC'
7627                 , documentid  => p_update_info_doc );
7628 
7629             --Setting Successful assignments count
7630             wf_engine.SetItemAttrNumber
7631                 ( itemtype => l_wf_item_type
7632                 , itemkey  => l_itemkey
7633                 , aname    => 'APPROVED_ASSIGNMENTS'
7634                 , avalue   => p_num_apr_asgns + p_num_rej_asgns);
7635 
7636         END IF;
7637 
7638         ---------------------------------------------------------------------
7639         --Setting Common Assignment attributes for CRN / UPD / APS
7640         --------------------------------------------------------------------
7641 
7642         log_message('Setting common attributes');
7643 
7644         --Setting total assignments count
7645         wf_engine.SetItemAttrNumber
7646             ( itemtype => l_wf_item_type
7647             , itemkey  => l_itemkey
7648             , aname    => 'NUMBER_OF_ASSIGNMENTS'
7649             , avalue   => p_num_apr_asgns + p_num_rej_asgns + l_error_asgns_count);
7650 
7651         --Setting failed assignments count
7652          wf_engine.SetItemAttrNumber
7653             ( itemtype => l_wf_item_type
7654             , itemkey  => l_itemkey
7655             , aname    => 'REJECTED_ASSIGNMENTS'
7656             , avalue   =>  l_error_asgns_count);
7657 
7658         --Setting Project attributes
7659         wf_engine.SetItemAttrText
7660             ( itemtype => l_wf_item_type
7661             , itemkey  => l_itemkey
7662             , aname    => 'PROJECT_NAME'
7663             , avalue   => p_project_name );
7664 
7665         wf_engine.SetItemAttrText
7666             ( itemtype => l_wf_item_type
7667             , itemkey  => l_itemkey
7668             , aname    => 'PROJECT_NUMBER'
7669             , avalue   => p_project_number );
7670 
7671         wf_engine.SetItemAttrText
7672             ( itemtype => l_wf_item_type
7673             , itemkey  => l_itemkey
7674             , aname    => 'PROJECT_MANAGER_NAME'
7675             , avalue   => p_project_manager );
7676 
7677         wf_engine.SetItemAttrText
7678             ( itemtype => l_wf_item_type
7679             , itemkey  => l_itemkey
7680             , aname    => 'PROJECT_ORGANIZATION'
7681             , avalue   => p_project_org );
7682 
7683         wf_engine.SetItemAttrText
7684             ( itemtype => l_wf_item_type
7685             , itemkey  => l_itemkey
7686             , aname    => 'PROJECT_CUSTOMER'
7687             , avalue   => p_project_cus );
7688 
7689      wf_engine.SetItemAttrText
7690         ( itemtype => l_wf_item_type
7691         , itemkey  => l_itemkey
7692         , aname    => 'SUBMITTER_UNAME'
7693         , avalue   => p_submitter_user_name);
7694 
7695      l_view_errors_url := 'JSP:/OA_HTML/OA.jsp?akRegionCode=PA_ERROR_LAYOUT&akRegionApplicationId=275&paProjectId='
7696      || p_project_id ||'&paSrcType1=MASS_ASSIGNMENT_TRANSACTION&paSrcType2=MASS_APPROVAL&paSrcId1=PAWFAAP&paSrcId2='
7697      || p_group_id || '&addBreadCrumb=RP' ;
7698 
7699       wf_engine.SetItemAttrText
7700                ( itemtype => l_wf_item_type
7701                , itemkey  => l_itemkey
7702                , aname    => 'VIEW_ERRORS_URL'
7703                , avalue   => l_view_errors_url );
7704 
7705      log_message('Staring process for :' || l_wf_item_type || ':' || l_itemkey);
7706 
7707     --Start the workflow process
7708     wf_engine.StartProcess ( itemtype => l_wf_item_type
7709                             ,itemkey  => l_itemkey );
7710 
7711     PA_WORKFLOW_UTILS.Insert_WF_Processes
7712         (p_wf_type_code        => 'MASS_ASSIGNMENT_APPROVAL'
7713         ,p_item_type           => l_wf_item_type
7714         ,p_item_key            => l_itemkey
7715         ,p_entity_key1         => to_char(p_project_id)
7716         ,p_entity_key2         => to_char(p_group_id)
7717         ,p_description         => NULL
7718         ,p_err_code            => l_err_code
7719         ,p_err_stage           => l_err_stage
7720         ,p_err_stack           => l_err_stack );
7721 
7722    log_message('Out of  submitter notification');
7723 
7724 
7725     --Setting the original value
7726     wf_engine.threshold := l_save_threshold;
7727 
7728     -- IF the number of messages is 1 then fetch the message code from
7729     -- the stack and return its text
7730     x_msg_count :=  FND_MSG_PUB.Count_Msg;
7731 
7732     IF x_msg_count = 1 THEN
7733         pa_interface_utils_pub.get_messages
7734             ( p_encoded       => FND_API.G_TRUE
7735              ,p_msg_index     => 1
7736              ,p_data          => x_msg_data
7737              ,p_msg_index_out => l_msg_index_out );
7738     END IF;
7739 
7740     -- Reset the error stack when returning to the calling program
7741     PA_DEBUG.Reset_Err_Stack;
7742 
7743     -- If g_error_exists is TRUE then set the x_return_status to 'E'
7744     IF FND_MSG_PUB.Count_Msg >0  THEN
7745         x_return_status := FND_API.G_RET_STS_ERROR;
7746     END IF;
7747 
7748 EXCEPTION
7749     WHEN NO_ASSIGNMENT_ERRORS THEN
7750         x_return_status := FND_API.G_RET_STS_SUCCESS;
7751     WHEN OTHERS THEN
7752 
7753          --Setting the original value
7754          wf_engine.threshold := l_save_threshold;
7755 
7756          -- Set the excetption Message and the stack
7757          FND_MSG_PUB.add_exc_msg
7758              ( p_pkg_name       => 'PA_ASGMT_WFSTD.process_submitter_notification'
7759               ,p_procedure_name => PA_DEBUG.G_Err_Stack );
7760 
7761          x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
7762          RAISE;
7763 END process_submitter_notification;
7764 
7765 ---------------------------------------------------------
7766 --This API is called from Assignment Approval workflow
7767 --This determines if approval is for a single
7768 --transaction or a mass transaction
7769 ---------------------------------------------------------
7770 PROCEDURE Check_Approval_Type
7771               ( itemtype  IN VARCHAR2
7772                ,itemkey   IN VARCHAR2
7773                ,actid     IN NUMBER
7774                ,funcmode  IN VARCHAR2
7775                ,resultout OUT NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
7776 IS
7777 
7778 l_approval_type              VARCHAR2(10);
7779 
7780 BEGIN
7781 
7782     pa_debug.init_err_stack ('pa_asgmt_wfstd.Check_approval_type');
7783 
7784     -- Return if WF Not Running
7785     IF (funcmode <> wf_engine.eng_run) THEN
7786         resultout := wf_engine.eng_null;
7787         RETURN;
7788     END IF;
7789 
7790     l_approval_type := wf_engine.GetItemAttrText
7791                    (itemtype => itemtype,
7792                     itemkey  => itemkey,
7793                     aname    => 'APPROVAL_TYPE');
7794 
7795     IF l_approval_type = PA_ASGMT_WFSTD.G_MASS_APPROVAL THEN
7796 
7797         resultout := wf_engine.eng_completed||':'||'M';
7798 
7799     ELSIF l_approval_type = PA_ASGMT_WFSTD.G_SINGLE_APPROVAL THEN
7800 
7801         resultout := wf_engine.eng_completed||':'||'S';
7802 
7803     END IF;
7804 
7805     pa_debug.reset_err_stack;
7806 
7807 EXCEPTION
7808    WHEN OTHERS THEN
7809     WF_CORE.CONTEXT
7810         ('PA_ASGMT_WFSTD',
7811          'Check_approval_type',
7812           itemtype,
7813           itemkey,
7814           to_char(actid),
7815           funcmode);
7816     resultout := wf_engine.eng_completed||':'||'S';
7817     RAISE;
7818 
7819 END Check_Approval_Type ;
7820 
7821 -------------------------------------------------------------
7822 --This is a post notification function being called when user
7823 --either responds to notification by closing the notification
7824 --or when notification times out
7825 --This is called from approval required mass notification
7826 -------------------------------------------------------------
7827 PROCEDURE Check_Notification_Completed
7828               ( itemtype  IN VARCHAR2
7829                ,itemkey   IN VARCHAR2
7830                ,actid     IN NUMBER
7831                ,funcmode  IN VARCHAR2
7832                ,resultout OUT NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
7833 IS
7834 
7835     l_project_id            pa_project_assignments.project_id%TYPE;
7836     l_mode                  VARCHAR2(30);
7837     l_assignment_id_tbl     SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type();
7838     l_approval_status_tbl   SYSTEM.pa_varchar2_30_tbl_type:= SYSTEM.pa_varchar2_30_tbl_type();
7839     l_group_id              NUMBER;
7840     l_approver_group_id     NUMBER;
7841     l_routing_order         NUMBER;
7842     l_num_assignments       NUMBER;
7843     l_conflict_group_id     NUMBER;
7844     l_update_info_doc VARCHAR2(2000);
7845     l_submitter_user_name fnd_user.user_name%type; ----- VARCHAR2(30); Commented for bug 3267790
7846     l_note_to_approvers   VARCHAR2(2000);
7847     l_forwarded_from      fnd_user.user_name%type;--VARCHAR2(30); 5345171
7848     l_ntfy_apprvl_recip_name fnd_user.user_name%TYPE; --skkoppul commented for bug 6744129  VARCHAR2(30); -- added for bug 5488496
7849 
7850     CURSOR pending_txn_approvals IS
7851     SELECT 'Y'
7852     FROM   pa_wf_ntf_performers ntf,
7853            pa_project_assignments asgn
7854     WHERE  ntf.group_id          = l_group_id
7855     AND    ntf.approver_group_id = l_approver_group_id	--uncommented this line for Bug#5662785
7856     AND    ntf.routing_order     = l_routing_order
7857     AND    ntf.user_name         = l_ntfy_apprvl_recip_name  -- added for bug 5488496
7858     AND    ntf.object_id1        = asgn.assignment_id
7859     AND    ntf.object_id2        <> 100
7860     AND   ( asgn.apprvl_status_code <> PA_ASSIGNMENT_APPROVAL_PUB.g_rejected OR
7861             asgn.apprvl_status_code <> PA_ASSIGNMENT_APPROVAL_PUB.g_approved );
7862 
7863     l_pending_txn_approvals pending_txn_approvals%ROWTYPE;
7864 
7865 BEGIN
7866 
7867     l_group_id := wf_engine.GetItemAttrNumber
7868                    (itemtype => itemtype,
7869                     itemkey  => itemkey,
7870                     aname    => 'GROUP_ID');
7871 
7872     l_approver_group_id := wf_engine.GetItemAttrNumber
7873                    (itemtype => itemtype,
7874                     itemkey  => itemkey,
7875                     aname    => 'APPROVER_GROUP_ID');
7876 
7877     l_routing_order := wf_engine.GetItemAttrNumber
7878                    (itemtype => itemtype,
7879                     itemkey  => itemkey,
7880                     aname    => 'ROUTING_ORDER');
7881 
7882 -- added for bug 5488496
7883     l_ntfy_apprvl_recip_name := wf_engine.getItemAttrText
7884  	                     (itemtype => itemtype,
7885  	                     itemkey  => itemkey,
7886  	                     aname    => 'NTFY_APPRVL_RECIPIENT_NAME');
7887 
7888     IF funcmode = 'RESPOND' THEN
7889 
7890         ------------------------------------------------
7891         --Check if approver has handled the notification
7892         --Approver should have either approved/rejected
7893         --the assignments
7894         --In this case we check if assignment status is
7895         --approved/rejected
7896         -----------------------------------------------
7897         OPEN pending_txn_approvals;
7898         FETCH pending_txn_approvals INTO l_pending_txn_approvals;
7899 
7900         IF pending_txn_approvals%FOUND THEN
7901 
7902 		--	resultout := 'ERROR:PA_NO_ACTION_ON_NOTIFCATIONS';  commented for Bug#5650363
7903 		--	Added for the below line for Bug#5650363
7904 		resultout := 'ERROR:' || substrb(fnd_message.get_string('PA','PA_NO_ACTION_ON_NOTIFCATIONS'),1,114);
7905 
7906 		CLOSE pending_txn_approvals;		 -- Added Close statement for BUG#6328067
7907 		ELSE
7908 		CLOSE pending_txn_approvals;         -- Added Close statement for BUG#6328067
7909         END IF;
7910 
7911     END IF;--end respond
7912 
7913     ---------------------------------------------------------------
7914     --In the case of timeout all the assignments in the notifcation
7915     --have to be rejected. Get all relevant attributes from workflow
7916     --and call process_approval_result API
7917     ----------------------------------------------------------------
7918     IF funcmode = 'TIMEOUT' THEN
7919 
7920         SELECT ntf.object_id1
7921         BULK COLLECT INTO l_assignment_id_tbl
7922         FROM   pa_wf_ntf_performers ntf,
7923                pa_project_assignments asgn
7924         WHERE  ntf.group_id            = l_group_id
7925         AND    ntf.approver_group_id   = l_approver_group_id
7926         AND    ntf.routing_order       = l_routing_order
7927         AND    ntf.object_id1          = asgn.assignment_id
7928         AND    asgn.apprvl_status_code = PA_ASSIGNMENT_APPROVAL_PUB.g_submitted;
7929 
7930         l_project_id := wf_engine.getItemAttrNumber
7931                         ( itemtype => itemtype
7932                         , itemkey  => itemkey
7933                         , aname    => 'PROJECT_ID' );
7934 
7935         l_mode := wf_engine.getItemAttrText
7936                   ( itemtype => itemtype
7937                   , itemkey  => itemkey
7938                   , aname    => 'MODE' );
7939 
7940         l_num_assignments := l_assignment_id_tbl.COUNT;
7941 
7942         --Get the Update Info document
7943         l_update_info_doc := wf_engine.getItemAttrDocument
7944                              ( itemtype => itemtype
7945                              , itemkey  => itemkey
7946                              , aname    => 'UPDATED_INFO_DOC' );
7947 
7948         l_submitter_user_name := wf_engine.getItemAttrText
7949                                   ( itemtype => itemtype
7950                                   , itemkey  => itemkey
7951                                   , aname    => 'SUBMITTER_UNAME');
7952 
7953         l_conflict_group_id := wf_engine.getItemAttrNumber
7954                            ( itemtype => itemtype
7955                            , itemkey  => itemkey
7956                            , aname    => 'CONFLICT_GROUP_ID' );
7957 
7958         l_forwarded_from := wf_engine.getItemAttrText
7959                                   ( itemtype => itemtype
7960                                   , itemkey  => itemkey
7961                                   , aname    => 'NTFY_APPRVL_RECIPIENT_NAME');
7962 
7963         l_note_to_approvers := wf_engine.getItemAttrText
7964                                   ( itemtype => itemtype
7965                                   , itemkey  => itemkey
7966                                   , aname    => 'NOTE_TO_APPROVER');
7967 
7968         FOR i IN 1..l_assignment_id_tbl.COUNT LOOP
7969             l_approval_status_tbl.extend;
7970             l_approval_status_tbl(i) := PA_ASSIGNMENT_APPROVAL_PUB.g_reject_action;
7971         END LOOP;
7972 
7973         process_approval_result
7974             ( p_project_id            => l_project_id
7975              ,p_mode                  => l_mode
7976              ,p_assignment_id_tbl     => l_assignment_id_tbl
7977              ,p_approval_status_tbl   => l_approval_status_tbl
7978              ,p_group_id              => l_group_id
7979              ,p_approver_group_id     => l_approver_group_id
7980              ,p_routing_order         => l_routing_order
7981              ,p_num_of_assignments    => l_num_assignments
7982              ,p_submitter_user_name   => l_submitter_user_name
7983              ,p_conflict_group_id     => l_conflict_group_id
7984              ,p_update_info_doc       => l_update_info_doc
7985              ,p_forwarded_from        => l_forwarded_from
7986              ,p_note_to_approvers     => l_note_to_approvers);
7987 
7988     END IF; --end timeout case
7989 -- 4537865 : Included Exception Block
7990 EXCEPTION
7991         WHEN OTHERS THEN
7992         Wf_Core.Context('PA_ASGMT_WFSTD','Check_Notification_Completed',itemtype,itemkey,to_char(actid),funcmode);
7993         RAISE;
7994 END Check_Notification_Completed ;
7995 
7996 PROCEDURE Set_Submitter_User_Name
7997             (p_item_type     IN        VARCHAR2,
7998              p_item_key      IN        VARCHAR2,
7999              p_actid         IN        NUMBER,
8000              p_funcmode      IN        VARCHAR2,
8001              p_result        OUT       NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
8002  IS
8003 
8004  l_error_item_type      VARCHAR2(30);
8005  l_error_item_key       NUMBER;
8006  l_submitter_user_name  VARCHAR2(240);
8007 
8008  BEGIN
8009 
8010    log_message('Inside Set_Submitter_User_Name');
8011 
8012 
8013    --get the following wf attributes for the process that errored out.
8014    l_error_item_type :=            WF_ENGINE.GetItemAttrText(itemtype =>  p_item_type,
8015                                                               itemkey  => p_item_key,
8016                                                               aname    => 'ERROR_ITEM_TYPE');
8017 
8018    l_error_item_key  :=            WF_ENGINE.GetItemAttrText(itemtype =>  p_item_type,
8019                                                               itemkey  => p_item_key,
8020                                                               aname    => 'ERROR_ITEM_KEY');
8021 
8022    l_submitter_user_name :=        WF_ENGINE.GetItemAttrText(itemtype => l_error_item_type,
8023                                                              itemkey  => l_error_item_key,
8024                                                              aname    => 'SUBMITTER_UNAME');
8025 
8026    --SET the Text item attributes (these attributes were created at design time)
8027     WF_ENGINE.SetItemAttrText(itemtype => p_item_type,
8028                               itemkey  => p_item_key,
8029                               aname    => 'SUBMITTER_UNAME',
8030                               avalue   => l_submitter_user_name);
8031 
8032    log_message('After Set_Submitter_User_Name');
8033 -- 4537865 : Included Exception Block
8034 EXCEPTION
8035 	WHEN OTHERS THEN
8036 	Wf_Core.Context('PA_ASGMT_WFSTD','Set_Submitter_User_Name',p_item_type,p_item_key,to_char(p_actid),p_funcmode);
8037 	RAISE;
8038  END Set_Submitter_User_Name;
8039 
8040 --if there is an unexpected error then the sysadmin can choose to abort or retry
8041 --the unprocessed items.  If he chooses to abort then this API is called in
8042 --order to revert the errored assignments to previous status
8043 
8044 PROCEDURE Abort_Remaining_Trx
8045             (p_item_type     IN        VARCHAR2,
8046              p_item_key      IN        VARCHAR2,
8047              p_actid         IN        NUMBER,
8048              p_funcmode      IN        VARCHAR2,
8049              p_result        OUT       NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
8050 
8051  IS
8052 
8053  l_error_item_type   VARCHAR2(30);
8054  l_submitter_uname   fnd_user.user_name%type; ----- VARCHAR2(30); Commented for bug 3267790
8055  l_error_item_key    NUMBER;
8056  l_submitter_user_id NUMBER;
8057  l_resource_id       pa_resources_denorm.resource_id%TYPE;
8058  l_return_status     VARCHAR2(1);
8059  l_group_id          NUMBER;
8060  l_project_id        NUMBER;
8061  l_assignment_id_tbl SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type();
8062 
8063  BEGIN
8064 
8065    log_message('Inside Abort_Remaining_Trx');
8066 
8067    --aborting a wf happens when there is an unexpected error and
8068    --the sysadmin chooses to abort the workflow.
8069    --but we commit 1 at a time, so some of the transactions
8070    --may be complete - so we are only aborting the ones that are not yet processed.
8071 
8072    --get the following wf attributes for the process that errored out.
8073    l_error_item_type :=            WF_ENGINE.GetItemAttrText(itemtype => p_item_type,
8074                                                               itemkey  => p_item_key,
8075                                                               aname    => 'ERROR_ITEM_TYPE');
8076 
8077    l_error_item_key  :=            WF_ENGINE.GetItemAttrText(itemtype => p_item_type,
8078                                                               itemkey  => p_item_key,
8079                                                               aname    => 'ERROR_ITEM_KEY');
8080 
8081    l_project_id :=                       WF_ENGINE.GetItemAttrText(itemtype => l_error_item_type,
8082                                                                    itemkey  => l_error_item_key,
8083                                                                    aname    => 'PROJECT_ID');
8084 
8085    l_submitter_uname :=          WF_ENGINE.GetItemAttrText(itemtype => l_error_item_type,
8086                                                              itemkey  => l_error_item_key,
8087                                                              aname    => 'SUBMITTER_UNAME');
8088 
8089    l_group_id :=                 WF_ENGINE.GetItemAttrText(itemtype => l_error_item_type,
8090                                                              itemkey  => l_error_item_key,
8091                                                              aname    => 'GROUP_ID');
8092 
8093    SELECT ntf.object_id1
8094    BULK COLLECT INTO l_assignment_id_tbl
8095    FROM   pa_wf_ntf_performers ntf,
8096           pa_project_assignments asgn
8097    WHERE  ntf.group_id            = l_group_id
8098    AND    ntf.routing_order       = 1
8099    AND    ntf.object_id1          = asgn.assignment_id
8100    AND    asgn.apprvl_status_code = PA_ASSIGNMENT_APPROVAL_PUB.g_submitted;
8101 
8102 
8103          --if there are any aborted items then add a message to the stack
8104          --saying that those items were aborted by the sysadmin.
8105          IF l_assignment_id_tbl.COUNT > 0 THEN
8106 
8107             FOR i IN l_assignment_id_tbl.FIRST .. l_assignment_id_tbl.LAST LOOP
8108 
8109                FND_MSG_PUB.initialize;
8110 
8111                PA_UTILS.Add_Message( p_app_short_name => 'PA'
8112                                     ,p_msg_name       => 'PA_PROCESS_ABORTED_SYSADMIN');
8113 
8114                SELECT user_id
8115                INTO   l_submitter_user_id
8116                FROM   fnd_user
8117                WHERE  user_name = l_submitter_uname;
8118 
8119                SELECT resource_id
8120                INTO   l_resource_id
8121                FROM   pa_project_assignments
8122                WHERE  assignment_id = l_assignment_id_tbl(i);
8123 
8124                --Revert assignment status back to previous status before approval
8125                Revert_assignment_status(
8126                    p_assignment_id => l_assignment_id_tbl(i)
8127                   ,p_group_id      => l_group_id
8128                   ,x_return_status => l_return_status);
8129 
8130                PA_MESSAGE_UTILS.save_messages(p_user_id            =>  l_submitter_user_id,
8131                                               p_source_type1       =>  PA_MASS_ASGMT_TRX.G_SOURCE_TYPE1,
8132                                               p_source_type2       =>  'MASS_APPROVAL',
8133                                               p_source_identifier1 =>  'PAWFAAP',
8134                                               p_source_identifier2 =>  l_group_id,
8135                                               p_context1           =>  l_project_id,
8136                                               p_context2           =>  l_assignment_id_tbl(i),
8137                                               p_context3           =>  l_resource_id,
8138                                               p_commit             =>  FND_API.G_FALSE,
8139                                               x_return_status      =>  l_return_status);
8140 
8141             END LOOP;
8142 
8143          END IF;
8144     log_message('Abort_Remaining_Trx');
8145 
8146  EXCEPTION
8147    WHEN OTHERS THEN
8148       RAISE;
8149 
8150  END Abort_Remaining_Trx;
8151 
8152 END PA_ASGMT_WFSTD;