DBA Data[Home] [Help]

PACKAGE BODY: APPS.IGS_SV_NI_BATCH_PROCESS_PKG

Source


1 PACKAGE BODY igs_sv_ni_batch_process_pkg AS
2 /* $Header: IGSSV03B.pls 120.1 2006/05/31 10:01:26 vskumar noship $ */
3 
4 /******************************************************************
5 
6     Copyright (c) 2002 Oracle Corporation, Redwood Shores, CA, USA
7                          All rights reserved.
8 
9  Created By         : Don Shellito
10 
11  Date Created By    : Oct-01-2002
12 
13  Purpose            : This package is to be used for the processing and
14                       gathering of the SEVIS related information that is
15                       to be sent for transmital.
16 
17                       The concurrent programs that are to be executed are
18                       defined globally.  All other procedures are to be
19                       defined internally.
20 
21  remarks            : None
22 
23  Change History
24 
25 Who                   When           What
26 -----------------------------------------------------------
27 Arkadi Tereshenkov    Oct-14-2002    New Package created.
28 pkpatel               23-APR-2003    Bug 2908378(Solved Multiple Issues)
29 gmaheswa              12-Nov-2003    Bug 3227107 address related changes
30 pkpatel               4-Dec-2003     Bug 3227107 (Used the status column for address in Validate_Site_Info)
31 ssaleem               13-Apr-2005    Bug 4293911 Fnd User customer Id  replaced with person
32 		                     party id
33 ******************************************************************/
34 
35 /*************** Values from addresses    bug #2630743***********************************
36 SEVIS_PRIMARY_US - SEVIS Primary US Address/SEVIS Primary Address in  United States
37 SEVIS_PRIMARY_FOREIGN - SEVIS Primary Foreign Address/SEVIS Primary  Address outside of United States
38 SEVIS_SITE_OF_ACTIVITY - SEVIS Site of Activity/SEVIS Site of Activity
39 ***********************************************************************************/
40 
41 G_PKG_NAME         CONSTANT VARCHAR2(30) := 'IGS_SV_NI_BATCH_PROCESS_PKG';
42 g_us_addr_usage    CONSTANT VARCHAR2(30) := 'SEVIS_PRIMARY_US';
43 g_f_addr_usage     CONSTANT VARCHAR2(30) := 'SEVIS_PRIMARY_FOREIGN';
44 g_site_addr_usage  CONSTANT VARCHAR2(30) := 'SEVIS_SITE_OF_ACTIVITY';
45 g_school_sevis_id  CONSTANT VARCHAR2(30) := 'SV_SCH_CD';
46 g_person_sevis_id  CONSTANT VARCHAR2(30) := 'SEVIS_ID';
47 g_sch_p_sevis_id   CONSTANT VARCHAR2(30) := 'SV_PRG_CD';
48 g_block_mode       CONSTANT NUMBER(1)    := 1; --Insert mode 0:1. If 1 - inserts only changed optional info in the block. , if 0 - all parts of the block
49 g_prod             VARCHAR2(3)           := 'IGS';
50 g_debug_level      NUMBER(1) := 0;
51 g_update_login     NUMBER(15);
52 g_update_by        NUMBER(15);
53 g_delimeter        CONSTANT VARCHAR2(1) := '|';
54 g_create_count    NUMBER(15) := 0;     -- prbhardw CP enhancement
55 g_update_count    NUMBER(15) := 0;     -- prbhardw CP enhancement
56 g_running_create_batch NUMBER(15);     -- prbhardw CP enhancement
57 g_running_update_batch NUMBER(15);     -- prbhardw CP enhancement
58 l_prog_label CONSTANT VARCHAR2(500) :='igs.plsql.igs_sv_ni_batch_process_pkg';
59 l_label VARCHAR2(4000);
60 l_debug_str VARCHAR2(32000);
61 g_person_status    VARCHAR2(6)      := 'NEW';
62 g_nonimg_form_id NUMBER(15);
63 TYPE g_address_rec_type IS TABLE OF IGS_SV_ADDRESSES%ROWTYPE INDEX BY BINARY_INTEGER;
64 TYPE g_edu_rec_type IS TABLE OF IGS_SV_PRGMS_INFO%ROWTYPE INDEX BY BINARY_INTEGER;
65 TYPE g_dependent_rec_type IS TABLE OF IGS_SV_DEPDNT_INFO%ROWTYPE INDEX BY BINARY_INTEGER;
66 TYPE g_convictions_rec_type IS TABLE OF IGS_SV_CONVICTIONS%ROWTYPE INDEX BY BINARY_INTEGER;
67 TYPE g_empl_rec_type IS TABLE OF IGS_SV_EMPL_INFO%ROWTYPE INDEX BY BINARY_INTEGER;
68 TYPE g_parallel_batches_tbl IS TABLE OF IGS_SV_BATCHES.BATCH_ID%TYPE INDEX BY BINARY_INTEGER;
69 TYPE g_running_batches_tbl IS TABLE OF IGS_SV_BATCHES.BATCH_ID%TYPE INDEX BY BINARY_INTEGER;
70 
71 g_parallel_batches g_parallel_batches_tbl;
72 g_running_batches  g_running_batches_tbl;
73 
74 TYPE c_stdnt_list IS RECORD
75 (
76     person_id        igs_pe_nonimg_form.person_id%TYPE,
77     form_id	     igs_pe_ev_form.ev_form_id%TYPE	,
78     person_number    hz_parties.party_number%TYPE,
79     no_show_flag     igs_pe_ev_form.no_show_flag%TYPE	,
80     reprint_reason   igs_pe_ev_form.reprint_reason%TYPE
81 );
82 
83 TYPE t_student_rec IS RECORD
84 (   person_id        igs_sv_persons.person_id%TYPE,
85     batch_id         igs_sv_persons.batch_id%TYPE,
86     record_number    igs_sv_persons.record_number%TYPE,
87     record_status    igs_sv_persons.record_status%TYPE, --(N)ew  (C)hanged
88     person_number    igs_sv_persons.person_number%TYPE,
89     sevis_user_id    igs_sv_batches.sevis_user_id%TYPE,
90     batch_type       igs_sv_batches.batch_type%TYPE,
91     form_id          igs_sv_persons.form_id%TYPE,
92     print_form       igs_sv_persons.print_form%TYPE,
93     dep_flag         VARCHAR2(1),
94     person_status    VARCHAR2(1),
95     changes_found    VARCHAR2(1),
96     issue_status     VARCHAR2(1),
97     bio_status       VARCHAR2(1),
98     empl_status      VARCHAR2(1),
99     other_status     VARCHAR2(1),
100     f_addr_status    VARCHAR2(1),
101     us_addr_status   VARCHAR2(1),
102     edu_status       VARCHAR2(1),
103     dep_status       VARCHAR2(1),
104     fin_status       VARCHAR2(1),
105     conv_status      VARCHAR2(1),
106     site_addr_status VARCHAR2(1),
107     legal_status     VARCHAR2(1),
108     dep_count        NUMBER(3),
109     edu_count        NUMBER(3),
110     no_show_flag     igs_sv_persons.no_show_flag%TYPE,
111     reprint_reason   igs_sv_persons.reprint_rsn_code%TYPE		-- prbhardw
112 );
113 
114 
115 
116 PROCEDURE Put_Log_Msg (
117    p_message IN VARCHAR2,
118    p_level   IN NUMBER
119 );
120 
121 PROCEDURE Generate_Message;
122 
123 PROCEDURE Create_Batch(
124    errbuf             OUT NOCOPY VARCHAR2,  -- Request standard error string
125    retcode            OUT NOCOPY NUMBER  ,  -- Request standard return status
126    p_batch_type       IN  VARCHAR2,  -- Batch type E(ev),  I(international)
127    p_validate_only    IN  VARCHAR2,  -- Validate only flag  'Y'  'N'
128    p_org_id           IN  VARCHAR2,
129    p_dso_id	      IN  VARCHAR2,
130    p_dso_party_id     IN  NUMBER,
131    p_org_party_id     IN  NUMBER
132 ) ;
133 
134 PROCEDURE Purge_Batch(
135    errbuf             OUT NOCOPY VARCHAR2,  -- Request standard error string
136    retcode            OUT NOCOPY NUMBER  ,  -- Request standard return status
137    p_batch_type       IN  VARCHAR2  -- Batch type E(ev),  I(international)
138 ) ;
139 
140 PROCEDURE Insert_Summary_Info(
141    p_batch_id  IN  igs_sv_btch_summary.batch_id%TYPE,
142    p_person_id  IN  igs_sv_btch_summary.person_id%TYPE,
143    p_action_code  IN  igs_sv_btch_summary.action_code%TYPE,
144    p_tag_code  IN  igs_sv_btch_summary.tag_code%TYPE,
145    p_adm_action IN  igs_sv_btch_summary.adm_action_code%TYPE,
146    p_owner_table_name IN igs_sv_btch_summary.owner_table_name%TYPE,
147    p_owner_table_id  IN  igs_sv_btch_summary.OWNER_TABLE_IDENTIFIER%TYPE
148 );
149 
150 PROCEDURE compose_log_file;
151 /*****************************************************************/
152 PROCEDURE Submit_Event (
153   p_batch_type IN VARCHAR2,
154   p_batch_id   IN IGS_SV_BATCHES.BATCH_ID%TYPE
155 )
156 IS
157 
158   l_parameter_list wf_parameter_list_t := wf_parameter_list_t();
159   l_event_name    VARCHAR2(255);
160   l_event_key     VARCHAR2(255);
161   l_party_id      HZ_PARTY_SITES.PARTY_ID%TYPE;
162   l_party_site_id HZ_PARTY_SITES.PARTY_SITE_ID%TYPE;
163   l_trans_type    VARCHAR2(30) :='IGS_SV';
164   l_trans_subtype VARCHAR2(30) ;
165   l_debug_level   NUMBER := 0;
166   l_user_id       VARCHAR2(100);
167   l_party_type    VARCHAR2(30) :='C';
168 
169   CURSOR c_party_data IS
170    SELECT party_id,
171           party_site_id
172      FROM ecx_tp_headers
173     WHERE tp_header_id IN
174           ( SELECT tp_header_id
175               FROM ecx_tp_details
176              WHERE ext_process_id IN
177              ( SELECT ext_process_id
178                  FROM ecx_ext_processes
179                 WHERE direction = 'OUT'
180                       AND transaction_id IN
181                 ( SELECT transaction_id
182                     FROM ecx_transactions
183                    WHERE transaction_type=l_trans_type
184                      AND transaction_subtype =l_trans_subtype
185                 )
186               )
187            );
188 
189    CURSOR c_get_user_id IS
190      SELECT sevis_user_id
191      FROM igs_sv_batches
192      WHERE batch_id = p_batch_id;
193 
194      l_con_req_id NUMBER;
195 BEGIN
196   /* Debug */
197 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
198   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Submit_Event';
199   l_debug_str := 'Entering Submit_Event. p_batch_type is ' || p_batch_type || 'and p_batch_id is ' || p_batch_id;
200   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
201 END IF;
202 
203   IF p_batch_type = 'E' THEN
204 
205     l_event_name := 'oracle.apps.igs.sv.ev.submit';
206     l_trans_subtype :='SEVISEVO';
207 
208   ELSE
209 
210     l_event_name := 'oracle.apps.igs.sv.ni.submit';
211     l_trans_subtype :='SEVISO';
212   END IF;
213 
214   SELECT FND_GLOBAL.CONC_REQUEST_ID INTO l_con_req_id FROM DUAL;
215 
216   OPEN c_party_data;
217   FETCH c_party_data INTO l_party_id, l_party_site_id;
218   CLOSE c_party_data;
219 
220   IF l_party_id IS NULL THEN
221       /* Debug */
222 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
223 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Submit_Event';
224 	  l_debug_str := 'IGS_SV_PRTNR_STP_ERR error in Submit_Event.';
225 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
226 	END IF;
227 
228       FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_PRTNR_STP_ERR'); -- No trading partner setup found
229       FND_MSG_PUB.Add;
230       RAISE FND_API.G_EXC_ERROR;
231 
232   END IF;
233 
234   OPEN c_get_user_id;
235   FETCH c_get_user_id INTO l_user_id;
236   CLOSE c_get_user_id;
237 
238   l_event_key := p_batch_id  || l_con_req_id;
239 
240 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
241 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.event_parameters';
242 	  l_debug_str := 'batch_id= '|| p_batch_id || 'l_party_id= '|| l_party_id || ' l_party_site_id='||l_party_site_id || 'l_trans_type= ' || l_trans_type || ' l_trans_subtype= ' || l_trans_subtype || ' l_debug_level = ' || l_debug_level ;
243 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
244 	END IF;
245   /* Manoj
246   wf_event.AddParameterToList(p_name=>'DOC_ID',p_value=>p_batch_id,p_parameterlist=>l_parameter_list);
247   wf_event.AddParameterToList(p_name=>'PARTY_ID',p_value=>l_party_id,p_parameterlist=>l_parameter_list);
248   wf_event.AddParameterToList(p_name=>'PARTY_SITE_ID',p_value=>l_party_site_id,p_parameterlist=>l_parameter_list);
249   wf_event.AddParameterToList(p_name=>'TRANS_TYPE',p_value=>l_trans_type,p_parameterlist=>l_parameter_list);
250   wf_event.AddParameterToList(p_name=>'TRANS_SUB_TYPE',p_value=>l_trans_subtype,p_parameterlist=>l_parameter_list);
251 Manoj*/
252   --l_user_id := '999-999-777';
253   wf_event.AddParameterToList(p_name=>'ECX_DOCUMENT_ID',p_value=>p_batch_id,p_parameterlist=>l_parameter_list);
254   wf_event.AddParameterToList(p_name=>'ECX_PARTY_ID',p_value=>l_party_id,p_parameterlist=>l_parameter_list);
255   wf_event.AddParameterToList(p_name=>'ECX_PARTY_SITE_ID',p_value=>l_party_site_id,p_parameterlist=>l_parameter_list);
256   wf_event.AddParameterToList(p_name=>'ECX_TRANSACTION_TYPE',p_value=>l_trans_type,p_parameterlist=>l_parameter_list);
257   wf_event.AddParameterToList(p_name=>'ECX_TRANSACTION_SUBTYPE',p_value=>l_trans_subtype,p_parameterlist=>l_parameter_list);
258   wf_event.AddParameterToList(p_name=>'ECX_PARTY_TYPE',p_value=>l_party_type,p_parameterlist=>l_parameter_list);
259   wf_event.AddParameterToList(p_name=>'ECX_DEBUG_LEVEL',p_value=>l_debug_level,p_parameterlist=>l_parameter_list);
260   wf_event.AddParameterToList(p_name=>'PARAMETER1',p_value=>p_batch_id,p_parameterlist=>l_parameter_list);
261   wf_event.AddParameterToList(p_name=>'PARAMETER2',p_value=>l_user_id,p_parameterlist=>l_parameter_list);
262 
263 
264   -- Raise the Event without the message
265   -- The Generate Function Callback will create the XML Document
266   -- Also possible that an API might be called from here to
267   -- to generate the XML document
268   wf_event.raise( p_event_name => l_event_name,
269                   p_event_key  => l_event_key,
270                   p_parameters => l_parameter_list);
271 
272 
273   l_parameter_list.DELETE;
274 
275  /* Debug */
276 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
277   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Submit_Event';
278   l_debug_str := 'Exiting Submit_Event. l_event_key: '||l_event_key;
279   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
280 END IF;
281 
282 END;
283 
284 
285 /******************************************************************
286    Created By         : Arkadi Tereshenkov
287    Date Created By    : Oct 14, 2002
288    Purpose            :
289    remarks            :
290 
291    Change History
292    Who                  When            What
293 ------------------------------------------------------------------------
294 
295 ******************************************************************/
296 PROCEDURE Dump_Current_Person(
297    p_student_rec IN t_student_rec
298 ) IS
299 
300    l_str VARCHAR2(2000);
301 
302 BEGIN
303 	/* Debug */
304 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
305 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Dump_Current_Person';
306 	  l_debug_str := 'Entering Dump_Current_Person. p_student_rec.person_id is '|| p_student_rec.person_id;
307 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
308 	END IF;
309 
310   -- This is a debug procedure used to output a current person info if an error occurs
311   Put_Log_Msg('****** Execution error - dumping current person *********',0);
312 
313   Put_Log_Msg(' person_id '||        p_student_rec.person_id ,0);
314   Put_Log_Msg(' form_id   '||        p_student_rec.form_id ,0);
315   Put_Log_Msg(' print_form   '||        p_student_rec.print_form ,0);
316   Put_Log_Msg(' record_number '||    p_student_rec.record_number ,0);
317   Put_Log_Msg(' record_status '||    p_student_rec.record_status ,0);
318   Put_Log_Msg(' person_number '||    p_student_rec.person_number ,0);
319   Put_Log_Msg(' sevis_user_id '||    p_student_rec.sevis_user_id ,0);
320   Put_Log_Msg(' form_id '||          p_student_rec.form_id ,0);
321   Put_Log_Msg(' person_status '||    p_student_rec.person_status ,0);
322   Put_Log_Msg(' issue_status  '||    p_student_rec.issue_status ,0);
323   Put_Log_Msg(' bio_status '||       p_student_rec.bio_status ,0);
324   Put_Log_Msg(' other_status '||     p_student_rec.other_status ,0);
325   Put_Log_Msg(' f_addr_status '||    p_student_rec.f_addr_status ,0);
326   Put_Log_Msg(' us_addr_status '||   p_student_rec.us_addr_status ,0);
327   Put_Log_Msg(' edu_status '||       p_student_rec.edu_status ,0);
328   Put_Log_Msg(' dep_status '||       p_student_rec.dep_status ,0);
329   Put_Log_Msg(' fin_status '||       p_student_rec.fin_status ,0);
330   Put_Log_Msg(' dep_count '||        p_student_rec.dep_count ,0);
331   Put_Log_Msg(' edu_count '||        p_student_rec.edu_count ,0);
332 
333   Put_Log_Msg('********************************************************',0);
334   /* Debug */
335 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
336 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Dump_Current_Person';
337 	  l_debug_str := 'Exiting Dump_Current_Person.';
338 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
339 	END IF;
340 END Dump_Current_Person;
341 
342 /******************************************************************
343    Created By         : Arkadi Tereshenkov
344    Date Created By    : Oct 14, 2002
345    Purpose            :
346    remarks            :
347 
348    Change History
349    Who                  When            What
350    pkpatel              22-APR-2003     Bug No: 2908378
351                                         Modified the query to select the Active local institution. Added closed_ind = 'N'
352                                         while selecting the ORG_ALTERNATE_ID_TYPE
353                         9-DEC-2003      Bug No: 2908378 (Used the profile for local Institution)
354 ------------------------------------------------------------------------
355 
356 
357 FUNCTION Get_School_Sevis_Id (
358   p_batch_type IN VARCHAR2
359 ) RETURN VARCHAR2
360 IS
361 
362    CURSOR c_alt_id (cp_local_inst hz_parties.party_number%TYPE)
363    IS
364      SELECT org_alternate_id
365        FROM igs_or_org_alt_ids
366        WHERE org_structure_id = cp_local_inst
367        AND sysdate BETWEEN NVL(start_date,sysdate-1) and NVL(end_date,sysdate+1)
368        AND ( ( org_alternate_id_type =
369                      ( SELECT org_alternate_id_type
370                        FROM igs_or_org_alt_idtyp
371                        WHERE system_id_type = g_school_sevis_id AND
372                              close_ind = 'N' AND
373                              inst_flag = 'Y'
374                       ) AND p_batch_type ='I')
375                     OR  ( org_alternate_id_type =
376                          ( SELECT org_alternate_id_type
377                            FROM igs_or_org_alt_idtyp
378                            WHERE system_id_type = g_sch_p_sevis_id AND
379                                  close_ind = 'N' AND
380                                  inst_flag = 'Y'
381                         )
382                         AND p_batch_type ='E')
383                   );
384 
385 l_alt_id   VARCHAR2(255);
386 l_local_inst hz_parties.party_number%TYPE;
387 
388 BEGIN
389 /* Debug
390 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
391   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_School_Sevis_Id';
392   l_debug_str := 'Entering Get_School_Sevis_Id. p_batch_type is '|| p_batch_type;
393   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
394 END IF;
395 
396  l_local_inst := FND_PROFILE.VALUE('IGS_OR_LOCAL_INST');
397 
398      OPEN c_alt_id(l_local_inst);
399      FETCH c_alt_id INTO l_alt_id;
400      CLOSE c_alt_id;
401 
402 /* Debug
403 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
404   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_School_Sevis_Id';
405   l_debug_str := 'Exiting Get_School_Sevis_Id with return value '|| l_alt_id;
406   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
407 END IF;
408 
409    RETURN l_alt_id;
410 
411 
412 END Get_School_Sevis_Id;
413 ******************************************************************/
414 /******************************************************************
415    Created By         : prbhardw
416 
417    Date Created By    : Jan 03, 2006
418 
419    Purpose            : Function to check mutually exclusive tags.
420 
421    Change History
422    Who                  When            What
423 ------------------------------------------------------------------------
424 
425 ******************************************************************/
426 FUNCTION chk_mut_exclusive(p_batch_id igs_sv_btch_summary.batch_id%TYPE,
427 			    p_person_id igs_sv_btch_summary.person_id%TYPE,
428 			    p_action igs_sv_btch_summary.action_code%TYPE,
429 			    p_tag_code igs_sv_btch_summary.tag_code%TYPE
430 			   )
431  RETURN NUMBER
432 IS
433      l_is_mut_excl BOOLEAN := TRUE;
434      l_return_batch_id NUMBER(14) := -1;
435      l_num_parallel_rec NUMBER(4) := 0;
436      l_rec_count NUMBER(5) := 0;
437 BEGIN
438      l_is_mut_excl := igs_sv_util.ismutuallyexclusive(p_person_id,
439 						      p_batch_id,
440 						      p_action,
441 		                                      p_tag_code);
442      IF l_is_mut_excl = TRUE THEN
443 	 IF(g_parallel_batches.COUNT >0) THEN
444  	   FOR i IN g_parallel_batches.FIRST..g_parallel_batches.LAST LOOP
445 	       l_rec_count := l_rec_count +1;
446 	       l_is_mut_excl := igs_sv_util.ismutuallyexclusive(p_person_id,
447 						      g_parallel_batches(l_rec_count),
448 						      p_action,
449 		                                      p_tag_code);
450 	       IF l_is_mut_excl = FALSE THEN
451 	            l_return_batch_id := g_parallel_batches(l_rec_count);
452 	            igs_sv_util.create_Person_Rec(p_person_id,p_batch_id,l_return_batch_id);
453 		    EXIT;
454 	       END IF;
455  	   END LOOP;
456 	 END IF;
457      ELSE
458 	  l_return_batch_id := p_batch_id;
459      END IF;
460 
461      IF l_is_mut_excl = TRUE THEN
462           l_num_parallel_rec := g_parallel_batches.count + 1;
463 	  l_return_batch_id :=  igs_sv_util.open_new_batch(p_person_id,p_batch_id, 'CONN_JOB');
464 	  g_parallel_batches(l_num_parallel_rec) := l_return_batch_id;
465      END IF;
466      RETURN l_return_batch_id;
467 
468 END chk_mut_exclusive;
469 
470 
471 /******************************************************************
472    Created By         : Arkadi Tereshenkov
473    Date Created By    : Oct 14, 2002
474    Purpose            :
475    remarks            :
476 
477    Change History
478    Who                  When            What
479 ------------------------------------------------------------------------
480 
481 ******************************************************************/
482 FUNCTION Is_Number (
483   p_num     VARCHAR2
484 ) RETURN VARCHAR2
485 IS
486 
487 BEGIN
488 /* Debug */
489 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
490   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Is_Number';
491   l_debug_str := 'Entering Is_Number. p_num is '|| p_num;
492   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
493 END IF;
494 
495   RETURN to_char(to_number(p_num));
496 
497 EXCEPTION
498 
499   WHEN VALUE_ERROR THEN
500     /* Debug */
501 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
502   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Is_Number';
503   l_debug_str := 'Exception in Is_Number'||SQLERRM;
504   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
505 END IF;
506 
507     RETURN '';
508 
509 END Is_Number;
510 
511 /******************************************************************
512    Created By         : Arkadi Tereshenkov
513    Date Created By    : Oct 14, 2002
514    Purpose            :
515    remarks            :
516 
517    Change History
518    Who                  When            What
519 ------------------------------------------------------------------------
520 
521 ******************************************************************/
522 FUNCTION Get_Lookup_Name (
523  p_type VARCHAR2 ,
524  p_code VARCHAR2
525 
526  ) RETURN VARCHAR2
527 IS
528 
529   CURSOR c_blk_name IS
530      SELECT meaning
531       FROM fnd_lookup_values
532       WHERE lookup_code = p_code
533         AND view_application_id = 8405
534         AND enabled_flag='Y'
535         AND language = USERENV('LANG')
536         AND lookup_type = p_type
537         AND SYSDATE BETWEEN NVL(start_date_active,SYSDATE-1) AND NVL(end_date_active, SYSDATE + 1);
538 
539   l_block_name  VARCHAR2(255);
540 
541 BEGIN
542  /* Debug */
543 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
544   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Lookup_Name';
545   l_debug_str := 'Entering Get_Lookup_Name. p_type is '||p_type ||' and p_code is '|| p_code;
546   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
547 END IF;
548 
549   OPEN c_blk_name;
550   FETCH c_blk_name INTO l_block_name;
551   CLOSE c_blk_name;
552 
553 /* Debug */
554 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
555   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Lookup_Name';
556   l_debug_str := 'Returning from Get_Lookup_Name with value '||l_block_name;
557   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
558 END IF;
559 
560   RETURN l_block_name;
561 
562 END Get_Lookup_Name;
563 
564 
565 
566 /******************************************************************
567    Created By         : Arkadi Tereshenkov
568    Date Created By    : Oct 14, 2002
569    Purpose            :
570    remarks            :
571 
572    Change History
573    Who                  When            What
574 ------------------------------------------------------------------------
575 
576 ******************************************************************/
577 FUNCTION Convert_Country_Code (
578 
579   p_code VARCHAR2
580 
581  ) RETURN VARCHAR2
582 IS
583 
584  CURSOR c_blk_name IS
585      SELECT SUBSTR(meaning,5,2)
586       FROM fnd_lookup_values
587      WHERE lookup_type = 'PQP_US_COUNTRY_TRANSLATE'
588        AND view_application_id = 3
589        AND lookup_code=p_code
590        AND SYSDATE BETWEEN  NVL(start_date_active,SYSDATE-1)  AND NVL(end_date_active, SYSDATE + 1);
591 
592   l_block_name  VARCHAR2(255);
593 
594 BEGIN
595 /* Debug */
596 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
597   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Convert_Country_Code';
598   l_debug_str := 'Entering Convert_Country_Code. p_code is '||p_code;
599   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
600 END IF;
601 
602   OPEN c_blk_name;
603   FETCH c_blk_name INTO l_block_name;
604   CLOSE c_blk_name;
605 
606 /* Debug */
607 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
608   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Convert_Country_Code';
609   l_debug_str := 'Returning from Convert_Country_Code with value '|| l_block_name;
610   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
611 END IF;
612 
613   RETURN NVL(l_block_name,p_code);
614 
615 
616 END Convert_Country_Code;
617 
618 
619 
620 /******************************************************************
621    Created By         : Arkadi Tereshenkov
622 
623    Date Created By    : Oct 14, 2002
624 
625    Purpose            : Validate information pertaining to the
626                         Legal information block of student.
627                         (IGS_SV_LEGAL_INFO)
628 
629    Remarks            : Return result:
630                            'S' - record found and validated
631                            'E' - validation error
632                            'U' - Unexpected error
633                            'N' - data not found
634 
635    Change History
636    Who                  When            What
637 ------------------------------------------------------------------------
638 
639 ******************************************************************/
640 FUNCTION Convert_Visa_Type (
641   p_visa_meaning VARCHAR2
642  ) RETURN VARCHAR2 IS
643 
644   CURSOR c_visa_type IS
645      SELECT lv.lookup_code
646        FROM fnd_lookup_values   lv
647       WHERE lv.lookup_type = 'SV_MAP_HR_VISA_TYPES'
648         AND lv.meaning     = p_visa_meaning
649         AND SYSDATE BETWEEN  NVL(start_date_active,SYSDATE-1)  AND NVL(end_date_active, SYSDATE + 1);
650 
651   l_sv_visa_code  VARCHAR2(30);
652 
653 BEGIN
654 /* Debug */
655 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
656   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Convert_Visa_Type';
657   l_debug_str := 'Entering Convert_Visa_Type. p_visa_meaning is '||p_visa_meaning;
658   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
659 END IF;
660 
661   OPEN c_visa_type;
662 
663   FETCH c_visa_type
664    INTO l_sv_visa_code;
665 
666   CLOSE c_visa_type;
667 /* Debug */
668 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
669   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Convert_Visa_Type';
670   l_debug_str := 'Returning from Convert_Visa_Type with value '|| l_sv_visa_code;
671   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
672 END IF;
673 
674   RETURN l_sv_visa_code;
675 
676 END Convert_Visa_Type;
677 
678 
679 
680 /******************************************************************
681    Created By         : Arkadi Tereshenkov
682    Date Created By    : Oct 14, 2002
683    Purpose            :
684    remarks            :
685 
686    Change History
687    Who                  When            What
688 ------------------------------------------------------------------------
689 
690 ******************************************************************/
691 FUNCTION Convert_Suffix(
692    p_person_num   IN  VARCHAR2,
693    p_code         IN  VARCHAR2,
694    p_type         IN  VARCHAR2
695 ) RETURN VARCHAR2
696 IS
697 
698    CURSOR c_name_suffix IS
699       SELECT tag
700         FROM fnd_lookup_values
701        WHERE lookup_code         = p_code
702          AND view_application_id = 8405
703          AND enabled_flag        = 'Y'
704          AND language            = USERENV('LANG')
705          AND lookup_type         = p_type
706          AND SYSDATE BETWEEN  NVL(start_date_active,SYSDATE-1)  AND NVL(end_date_active, SYSDATE + 1);
707 
708    l_name_suffix        VARCHAR2(30);
709 
710 BEGIN
711   /* Debug */
712 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
713   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Convert_Suffix';
714   l_debug_str := 'Entering Convert_Suffix. p_person_num is '||p_person_num || ', p_code is '||p_code||' and p_type is '||p_type;
715   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
716 END IF;
717 
718    OPEN c_name_suffix;
719    FETCH c_name_suffix
720     INTO l_name_suffix;
721 
722    IF (c_name_suffix%NOTFOUND) AND p_code IS NOT NULL THEN
723 
724       FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_WARN_FLD_ERR'); -- Warning message for optional field
725       FND_MESSAGE.SET_TOKEN('FIELD_NAME', 'Suffix');
726       FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_num);
727       Put_Log_Msg(FND_MESSAGE.Get,1);
728 
729       l_name_suffix := NULL;
730 
731    END IF;
732    CLOSE c_name_suffix;
733 
734 /* Debug */
735 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
736   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Convert_Suffix';
737   l_debug_str := 'Returning from Convert_Suffix with value '|| l_name_suffix;
738   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
739 END IF;
740 
741    RETURN l_name_suffix;
742 
743 END Convert_Suffix;
744 
745 
746 
747 /******************************************************************
748    Created By         : Arkadi Tereshenkov
749    Date Created By    : Oct 14, 2002
750    Purpose            :
751    remarks            :
752 
753    Change History
754    Who                  When            What
755 ------------------------------------------------------------------------
756 
757 ******************************************************************/
758 FUNCTION Get_Block_Name (
759  p_block VARCHAR2
760  ) RETURN VARCHAR2
761 IS
762 
763 BEGIN
764  /* Debug */
765 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
766   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Block_Name';
767   l_debug_str := 'Inside Get_Block_Name. p_block is '||p_block;
768   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
769 END IF;
770 
771   RETURN get_lookup_name ('SV_VALIDATIONS',p_block);
772 
773 END Get_Block_Name;
774 
775 
776 
777 /******************************************************************
778    Created By         : Arkadi Tereshenkov
779    Date Created By    : Oct 14, 2002
780    Purpose            :
781    remarks            :
782 
783    Change History
784    Who                  When            What
785 ------------------------------------------------------------------------
786 
787 ******************************************************************/
788 FUNCTION Get_Person_Sevis_Id (
789    p_person_id IN NUMBER
790 ) RETURN VARCHAR2
791 IS
792 
793    CURSOR c_alt_id IS
794     SELECT api_person_id
795       FROM igs_pe_alt_pers_id
796      WHERE pe_person_id = p_person_id
797            AND person_id_type
798                IN (SELECT person_id_type
799                      FROM igs_pe_person_id_typ
800                     WHERE s_person_id_type = g_person_sevis_id)
801            AND start_dt <= trunc(sysdate)
802            AND NVL(end_dt,sysdate+1) >= trunc(sysdate);
803 
804 l_alt_id   VARCHAR2(255);
805 
806 BEGIN
807 /* Debug */
808 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
809   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Person_Sevis_Id';
810   l_debug_str := 'Entering Get_Person_Sevis_Id. p_person_id is '||p_person_id;
811   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
812 END IF;
813 
814  OPEN c_alt_id;
815  FETCH c_alt_id INTO l_alt_id;
816  CLOSE c_alt_id;
817 
818 
819  IF l_alt_id IS NOT NULL AND LENGTH(l_alt_id)<=11 THEN
820 
821 /* Debug */
822 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
823   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Person_Sevis_Id';
824   l_debug_str := 'Returning from Get_Person_Sevis_Id with value '||l_alt_id;
825   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
826 END IF;
827 
828    RETURN l_alt_id;
829 
830  END IF;
831 /* Debug */
832 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
833   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Person_Sevis_Id';
834   l_debug_str := 'Returning from Get_Person_Sevis_Id ';
835   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
836 END IF;
837 
838  RETURN '';
839 
840 END Get_Person_Sevis_Id;
841 
842 
843 FUNCTION Check_US_Terr(
844    p_person_num   IN  VARCHAR2,
845    p_code         IN  VARCHAR2
846 ) RETURN VARCHAR2
847 IS
848 
849    CURSOR c_name IS
850       SELECT tag
851         FROM fnd_lookup_values
852        WHERE lookup_code         = p_code
853          AND view_application_id = 8405
854          AND enabled_flag        = 'Y'
855          AND language            = USERENV('LANG')
856          AND lookup_type         = 'SV_US_TERRITORY_CODES'
857          AND SYSDATE BETWEEN  NVL(start_date_active,SYSDATE-1)  AND NVL(end_date_active, SYSDATE + 1);
858 
859    l_name_suffix        VARCHAR2(30);
860 
861 BEGIN
862 /* Debug */
863 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
864   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Check_US_Terr';
865   l_debug_str := 'Entering Check_US_Terr. p_person_num is '||p_person_num ||' and p_code is '||p_code;
866   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
867 END IF;
868 
869    OPEN c_name;
870    FETCH c_name
871     INTO l_name_suffix;
872 
873    IF p_code IS NOT NULL AND c_name%FOUND THEN
874 
875       FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_US_TERR_CD_ERR'); -- Error
876       FND_MESSAGE.SET_TOKEN('CNTRY_CODE', p_code);
877       FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_num);
878       Put_Log_Msg(FND_MESSAGE.Get,1);
879 
880       CLOSE c_name;
881 /* Debug */
882 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
883   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Check_US_Terr';
884   l_debug_str := 'Returning E from Check_US_Terr ';
885   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
886 END IF;
887 
888       RETURN 'E';
889 
890    END IF;
891 
892    CLOSE c_name;
893 
894 /* Debug */
895 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
896   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Check_US_Terr';
897   l_debug_str := 'Returning S from Check_US_Terr ';
898   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
899 END IF;
900 
901    RETURN 'S';
902 
903 END Check_US_Terr;
904 
905 /*****************  Validation procedures  *************************************
906 
907 OIB Other Information
908 FAB Foreign Address Information
909 UAB US Address Information
910 AAB Site of Activity Address Information
911 EIB Education Information
912 FIB Financial Information
913 DIB Dependent Information
914 CIB Conviction Information
915 LIB Legal Information
916 EMB Employment Information
917 PIB Program Information
918 
919 *******************************************************************************/
920 
921 /******************************************************************
922    Created By         : Arkadi Tereshenkov
923 
924    Date Created By    : Oct 14, 2002
925 
926    Purpose            : Validate the information for the block that
927                         is to be used for the Person Info Block
928                         (IGS_SV_PERSONS)
929 
930    Remarks            : Return result:
931                            'S' - record found and validated
932                            'E' - validation error
933                            'U' - Unexpected error
934                            'N' - data not found
935 
936    Change History
937    Who                  When            What
938 ------------------------------------------------------------------------
939 
940 ******************************************************************/
941 FUNCTION Validate_Issue_Info (
942    p_person_rec IN t_student_rec,
943    p_data_rec  IN OUT NOCOPY  IGS_SV_PERSONS%ROWTYPE   -- Data record
944 ) RETURN VARCHAR2
945 IS
946 
947    l_api_name CONSTANT VARCHAR(30) := 'Validate_Issue_Info';
948 
949    CURSOR c_data IS
950      SELECT issue_reason   ,
951             curr_session_end_date ,
952             next_session_start_date ,
953             other_reason,
954             transfer_from_school,
955             prgm_start_date,
956 	    last_session_flag,
957 	    adjudicated_flag
958        FROM igs_pe_nonimg_form
959       WHERE nonimg_form_id = p_person_rec.form_id ;
960 
961    CURSOR c_ev_data IS
962      SELECT create_reason   ,
963             prgm_start_date ,
964             prgm_end_date  ,
965             ev_form_number ,
966             init_prgm_start_date ,
967 	    no_show_flag
968        FROM igs_pe_ev_form
969       WHERE ev_form_id = p_person_rec.form_id ;
970 
971 
972   l_not_valid  boolean  := FALSE;
973   l_prog_start_date     igs_pe_nonimg_form.prgm_start_date%TYPE;
974 
975 BEGIN
976 
977 /* Debug */
978 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
979   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Issue_Info';
980   l_debug_str := 'Entering Validate_Issue_Info. p_person_rec.batch_id is '||p_person_rec.batch_id ||' and person_id is '||p_person_rec.person_id;
981   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
982 END IF;
983 
984    Put_Log_Msg(l_api_name||' starts ',0);
985 
986    p_data_rec.batch_id := NULL;  -- This will tell us if there's been any records found
987 
988    IF p_person_rec.batch_type = 'I' THEN
989 
990      FOR c_data_rec IN c_data LOOP
991 
992        p_data_rec.batch_id        := p_person_rec.batch_id;
993        p_data_rec.person_id       := p_person_rec.person_id;
994        p_data_rec.print_form      := p_person_rec.print_form;
995        p_data_rec.record_number   := p_person_rec.record_number ;
996        p_data_rec.form_id         := p_person_rec.form_id ;
997        p_data_rec.record_status   := p_person_rec.record_status ;
998        p_data_rec.person_number   := p_person_rec.person_number ;
999        p_data_rec.sevis_user_id   := p_person_rec.sevis_user_id ;
1000        l_prog_start_date          := c_data_rec.prgm_start_date ;
1001 
1002        p_data_rec.creation_date := sysdate;
1003        p_data_rec.created_by := g_update_by;
1004        p_data_rec.last_updated_by := g_update_by;
1005        p_data_rec.last_update_date  := sysdate;
1006        p_data_rec.last_update_login := g_update_login;
1007 
1008        p_data_rec.issuing_reason  := c_data_rec.issue_reason;
1009        p_data_rec.curr_session_end_date:= to_char(c_data_rec.curr_session_end_date,'YYYY-MM-DD');
1010        p_data_rec.next_session_start_date:= to_char(c_data_rec.next_session_start_date,'YYYY-MM-DD');
1011        p_data_rec.other_reason:= c_data_rec.other_reason;
1012        p_data_rec.Transfer_from_school:= c_data_rec.Transfer_from_school;
1013        p_data_rec.last_session_flag	:= c_data_rec.last_session_flag;
1014        p_data_rec.adjudicated_flag   := c_data_rec.adjudicated_flag;
1015 
1016 /* Debug */
1017 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1018   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Issue_Info';
1019   l_debug_str := 'Exiting from for loop of Validate_Issue_Info';
1020   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1021 END IF;
1022 
1023        EXIT;  -- one  record is enough
1024 
1025      END LOOP;
1026 
1027    ELSE
1028 
1029      FOR c_data_rec IN c_ev_data LOOP
1030 
1031        p_data_rec.batch_id        := p_person_rec.batch_id;
1032        p_data_rec.person_id       := p_person_rec.person_id;
1033        p_data_rec.print_form      := p_person_rec.print_form;
1034        p_data_rec.record_number   := p_person_rec.record_number ;
1035        p_data_rec.form_id         := p_person_rec.form_id ;
1036        p_data_rec.record_status   := p_person_rec.record_status ;
1037        p_data_rec.person_number   := p_person_rec.person_number ;
1038        p_data_rec.sevis_user_id   := p_person_rec.sevis_user_id ;
1039 
1040        p_data_rec.creation_date := sysdate;
1041        p_data_rec.created_by := g_update_by;
1042        p_data_rec.last_updated_by := g_update_by;
1043        p_data_rec.last_update_date  := sysdate;
1044        p_data_rec.last_update_login := g_update_login;
1045 
1046        p_data_rec.ev_create_reason  := c_data_rec.create_reason;
1047        p_data_rec.ev_form_number:= c_data_rec.ev_form_number;
1048 
1049        --These fields are used for EV program start date
1050 
1051        p_data_rec.curr_session_end_date:= to_char(c_data_rec.prgm_end_date,'YYYY-MM-DD');
1052        p_data_rec.next_session_start_date:= to_char(c_data_rec.prgm_start_date,'YYYY-MM-DD');
1053        p_data_rec.init_prgm_start_date:= to_char(c_data_rec.init_prgm_start_date,'YYYY-MM-DD');
1054        p_data_rec.no_show_flag	:= c_data_rec.no_show_flag;
1055 
1056 /* Debug */
1057 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1058   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Issue_Info';
1059   l_debug_str := 'Exiting from for loop of Validate_Issue_Info';
1060   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1061 END IF;
1062        EXIT;  -- one  record is enough
1063 
1064      END LOOP;
1065 
1066 
1067    END IF;
1068 
1069 
1070    IF p_data_rec.batch_id IS NULL THEN
1071 
1072       Put_Log_Msg(l_api_name||' Successfully completed, no rows found returns N ',0);
1073 /* Debug */
1074 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1075   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Issue_Info';
1076   l_debug_str := 'Returning N from Validate_Issue_Info';
1077   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1078 END IF;
1079 
1080       RETURN 'N';
1081 
1082    ELSE
1083 
1084      IF p_data_rec.issuing_reason = 'C' THEN
1085 
1086         IF p_data_rec.curr_session_end_date IS NULL OR p_data_rec.next_session_start_date IS NULL THEN
1087 
1088            FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_ISSUE_C_REQ_ERR'); -- SEVIS common error
1089            FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
1090 
1091            Put_Log_Msg(FND_MESSAGE.Get,1);
1092            l_not_valid := TRUE;
1093 
1094         END IF;
1095 
1096      ELSIF p_data_rec.issuing_reason = 'T' THEN
1097 
1098         IF p_data_rec.Transfer_from_school IS NULL  THEN
1099 
1100            FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_ISSUE_T_REQ_ERR'); -- SEVIS common error
1101            FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
1102 
1103            Put_Log_Msg(FND_MESSAGE.Get,1);
1104            l_not_valid := TRUE;
1105 
1106         END IF;
1107 
1108      ELSIF p_data_rec.issuing_reason = 'I'  THEN
1109 
1110         IF l_prog_start_date  IS NULL OR  l_prog_start_date < trunc(sysdate) THEN
1111 
1112            FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_INV_PRG_START_DT_ERR'); -- SEVIS common error
1113            FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
1114            FND_MESSAGE.SET_TOKEN('PRGM_DATE', l_prog_start_date );
1115 
1116            Put_Log_Msg(FND_MESSAGE.Get,1);
1117            l_not_valid := TRUE;
1118 
1119         END IF;
1120 
1121 
1122      ELSIF p_data_rec.issuing_reason = 'O' THEN
1123 
1124         IF p_data_rec.other_reason IS NULL  THEN
1125 
1126            FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_ISSUE_O_REQ_ERR'); -- SEVIS common error
1127            FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
1128 
1129            Put_Log_Msg(FND_MESSAGE.Get,1);
1130            l_not_valid := TRUE;
1131 
1132         END IF;
1133 
1134      ELSIF p_person_rec.batch_type = 'E' AND p_data_rec.issuing_reason = 'CONT' AND  p_data_rec.init_prgm_start_date IS NULL THEN
1135 
1136            FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_EV_PRG_RQD_FLD_ERR'); -- error - no initial date specified
1137            FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
1138 
1139            Put_Log_Msg(FND_MESSAGE.Get,1);
1140            l_not_valid := TRUE;
1141 
1142      ELSIF p_person_rec.batch_type = 'E'
1143            AND ( p_data_rec.curr_session_end_date IS NULL
1144                  OR p_data_rec.next_session_start_date IS NULL ) THEN
1145 
1146            FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_EV_PRG_RQD_FLD_ERR'); -- error
1147            FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
1148 
1149            Put_Log_Msg(FND_MESSAGE.Get,1);
1150            l_not_valid := TRUE;
1151 
1152      END IF;
1153 
1154      IF p_person_rec.batch_type = 'I' THEN
1155            IF ( p_data_rec.last_session_flag = 'Y'
1156                  AND p_data_rec.next_session_start_date IS NOT NULL ) THEN
1157 
1158 		   --FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_EV_LAST_SESN'); -- error
1159 		   --FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
1160 		   p_data_rec.next_session_start_date := NULL;
1161 
1162 	   END IF;
1163      END IF;
1164 
1165      IF l_not_valid THEN
1166 
1167         Put_Log_Msg(l_api_name||' Validation error, return E ',0);
1168 	/* Debug */
1169 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1170 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Issue_Info';
1171 	  l_debug_str := 'Returning E from Validate_Issue_Info';
1172 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1173 	END IF;
1174 
1175         RETURN 'E';
1176 
1177      END IF;
1178 
1179    END IF;
1180 
1181    Put_Log_Msg(l_api_name||' Successfully completed, returns S',0);
1182  /* Debug */
1183 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1184   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Issue_Info';
1185   l_debug_str := 'Returning S from Validate_Issue_Info';
1186   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1187 END IF;
1188 
1189    RETURN 'S'; -- Successfull validation
1190 
1191 EXCEPTION
1192 
1193    WHEN OTHERS THEN
1194 	/* Debug */
1195 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1196 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Issue_Info';
1197 	  l_debug_str := 'Exception in Validate_Issue_Info'||SQLERRM;
1198 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1199 	END IF;
1200 
1201       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
1202          FND_MSg_PUB.Add_Exc_Msg (G_PKG_NAME, l_api_name);
1203       END IF;
1204 
1205       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
1206 
1207       RETURN 'U';
1208 
1209 END Validate_Issue_Info;
1210 
1211 
1212 /******************************************************************
1213    Created By         : Arkadi Tereshenkov
1214 
1215    Date Created By    : Oct 14, 2002
1216 
1217    Purpose            : Validation procedure on data that is to be
1218                         resident in the BIO Info block.
1219                         (IGS_SV_BIO_INFO)
1220 
1221    Remarks            : Return result:
1222                            'S' - record found and validated
1223                            'E' - validation error
1224                            'U' - Unexpected error
1225                            'N' - data not found
1226 
1227    Change History
1228    Who                  When            What
1229    pkpatel              22-APR-2003     Bug No: 2908378
1230                                         Modified to prevent mandatory check of position_code and category_code, for dependents
1231                                         Added the new cursor c_perm_res_data for retriving Legal residency country
1232 ------------------------------------------------------------------------
1233 
1234 ******************************************************************/
1235 
1236 FUNCTION Validate_Name(p_Name IN varchar2) RETURN boolean IS
1237         returnVal boolean := false;
1238     BEGIN
1239     /* Debug */
1240 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1241 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Name';
1242 	  l_debug_str := 'Inside Validate_Name. p_Name is '|| p_Name;
1243 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1244 	END IF;
1245 
1246 	FOR counter in 0..9 LOOP
1247 	   if instr(p_Name,counter) > 0 then
1248 		returnVal :=true;
1249 		EXIT WHEN returnVal;
1250 	   END IF;
1251 	END LOOP;
1252 	/* Debug */
1253 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1254 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Name';
1255 	  l_debug_str := 'Returning from Validate_Name';
1256 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1257 	END IF;
1258 
1259         RETURN returnVal;
1260 
1261 END Validate_Name;
1262 
1263 Function Validate_Bio_Info(
1264    p_person_rec IN t_student_rec,
1265    p_data_rec  IN OUT NOCOPY  IGS_SV_BIO_INFO%ROWTYPE    -- Data record
1266 ) RETURN VARCHAR2
1267 IS
1268 
1269    l_api_name CONSTANT VARCHAR(30) := 'Validate_Bio_Info';
1270 
1271 
1272    CURSOR c_hz_data IS
1273       SELECT hzpp.person_last_name,
1274              hzpp.person_middle_name,
1275              hzpp.person_first_name,
1276              hzpp.person_name_suffix,
1277              hzpp.date_of_birth,
1278              hzpp.gender,
1279              prt.birth_country,
1280              hzc.country_code,
1281              prt.birth_city
1282         FROM hz_person_profiles    hzpp,
1283              hz_citizenship        hzc,
1284              igs_pe_hz_parties     prt
1285        WHERE hzpp.party_id = p_person_rec.person_id
1286          AND prt.party_id = hzpp.party_id
1287          AND hzc.party_id (+)  = hzpp.party_id
1288          AND sysdate between hzpp.effective_start_date AND NVL(hzpp.effective_end_date,sysdate+1);
1289 
1290    CURSOR c_nonimg_data IS
1291       SELECT peva.visa_type
1292         FROM igs_pe_visa   peva
1293        WHERE peva.person_id = p_person_rec.person_id
1294          AND SYSDATE BETWEEN peva.visa_issue_date AND peva.visa_expiry_date;
1295 
1296    CURSOR c_com_data IS
1297       SELECT decode(commuter_ind,'Y','1','0') commuter
1298         FROM igs_pe_nonimg_form
1299        WHERE nonimg_form_id  = p_person_rec.form_id;
1300 
1301    CURSOR c_perm_res_data IS
1302    SELECT perm_res_cntry
1303    FROM igs_pe_eit_perm_res_v
1304    WHERE person_id  = p_person_rec.person_id;
1305 
1306    CURSOR c_ev_data IS
1307       SELECT pevf.position_code,
1308              pevf.category_code,
1309              pevf.position_remarks
1310         FROM igs_pe_ev_form        pevf
1311        WHERE pevf.person_id = p_person_rec.person_id
1312          AND ev_form_id     = p_person_rec.form_id;
1313 
1314    CURSOR c_country_reason(cp_person_id number) IS
1315 	SELECT psd.birth_cntry_resn_code
1316         FROM igs_pe_stat_details  psd
1317         WHERE psd.person_id = cp_person_id;
1318 
1319 
1320    l_last_name             hz_person_profiles.person_last_name%TYPE;
1321    l_middle_name           hz_person_profiles.person_middle_name%TYPE;
1322    l_first_name            hz_person_profiles.person_first_name%TYPE;
1323    l_suffix                hz_person_profiles.person_name_suffix%TYPE;
1324    l_birth_date            hz_person_profiles.date_of_birth%TYPE;
1325    l_birth_city            igs_pe_hz_parties.birth_city%TYPE;
1326    l_gender                hz_person_profiles.gender%TYPE;
1327    l_birth_cntry_code      VARCHAR2(30); -- ASAP need new column and table to get type
1328    l_citizen_cntry_code    hz_citizenship.country_code%TYPE;
1329    l_visa_type             IGS_PE_VISA.visa_type%TYPE;
1330    l_commuter              VARCHAR2(1);  -- ASAP need new column and table to get type
1331    l_legal_res_cntry_code  VARCHAR2(30); -- ASAP need new column and table to get type
1332    l_position_code         IGS_PE_EV_FORM.position_code%TYPE;
1333    l_category_code         IGS_PE_EV_FORM.category_code%TYPE;
1334    l_position_remarks      IGS_PE_EV_FORM.position_remarks%TYPE;
1335    l_birth_cntry_resn_code  igs_pe_stat_details.birth_cntry_resn_code%TYPE;
1336 
1337    l_not_valid             BOOLEAN :=FALSE;
1338 BEGIN
1339   -- Visa type valies
1340   -- 01 F-1
1341   -- 02 M-1
1342   -- 03 J-1
1343   -- 04 F-2
1344   -- 05 M-2
1345   -- 06 J-2
1346 	/* Debug */
1347 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1348 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Bio_Info';
1349 	  l_debug_str := 'Inside Validate_Bio_Info. p_person_rec.batch_type is '|| p_person_rec.batch_type ||' and person_id is '|| p_person_rec.person_id;
1350 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1351 	END IF;
1352 
1353    Put_Log_Msg(l_api_name||' starts ',0);
1354    p_data_rec.batch_id := NULL;  -- This will tell us if there's been any records found
1355 
1356    OPEN c_hz_data;
1357    FETCH c_hz_data
1358     INTO l_last_name,
1359          l_middle_name,
1360          l_first_name,
1361          l_suffix,
1362          l_birth_date,
1363          l_gender,
1364          l_birth_cntry_code,
1365          l_citizen_cntry_code,
1366          l_birth_city;
1367 
1368    IF (c_hz_data%FOUND) THEN
1369 
1370       l_suffix := convert_suffix (p_person_rec.person_number, l_suffix, 'PE_US_NAME_SUFFIX');
1371       p_data_rec.last_name             := SUBSTR(l_last_name, 1, 40);
1372       p_data_rec.middle_name           := SUBSTR(l_middle_name, 1, 40);
1373       p_data_rec.first_name            := SUBSTR(l_first_name, 1, 40);
1374       p_data_rec.suffix                := SUBSTR(l_suffix, 1, 3);
1375       p_data_rec.birth_date            := to_char(l_birth_date,'YYYY-MM-DD');
1376       p_data_rec.birth_city            := SUBSTR(l_birth_city,1,60);
1377       p_data_rec.gender                := SUBSTR(l_gender, 1, 1);
1378       p_data_rec.birth_cntry_code      := SUBSTR(l_birth_cntry_code, 1, 2);
1379       p_data_rec.citizen_cntry_code    := convert_country_code (l_citizen_cntry_code);
1380 
1381       p_data_rec.birth_cntry_resn_code := NULL;
1382 
1383       OPEN c_country_reason(p_person_rec.person_id);
1384       FETCH c_country_reason
1385       INTO l_birth_cntry_resn_code;
1386       CLOSE c_country_reason;
1387 
1388       p_data_rec.birth_cntry_resn_code := l_birth_cntry_resn_code;
1389 
1390       OPEN c_nonimg_data;
1391       FETCH c_nonimg_data
1392       INTO l_visa_type;
1393 
1394       l_visa_type := Convert_Visa_Type (l_visa_type);
1395 
1396       CLOSE c_nonimg_data;
1397 
1398       IF (p_person_rec.batch_type = 'I') THEN
1399 
1400         OPEN c_com_data;
1401         FETCH c_com_data
1402         INTO  l_commuter;
1403 
1404         CLOSE c_com_data;
1405 
1406         p_data_rec.commuter              := SUBSTR(l_commuter, 1,1);
1407 
1408       END IF;
1409 
1410       p_data_rec.visa_type             := SUBSTR(l_visa_type, 1, 2);
1411 
1412      IF (p_person_rec.batch_type = 'E') THEN
1413          OPEN c_ev_data;
1414          FETCH c_ev_data
1415           INTO l_position_code,
1416                l_category_code,
1417                l_position_remarks;
1418 
1419          IF (c_ev_data%FOUND) THEN
1420 
1421             p_data_rec.position_code        := SUBSTR(l_position_code, 1, 3);
1422             p_data_rec.category_code        := l_category_code;
1423             p_data_rec.remarks              := l_position_remarks;
1424 
1425          END IF;
1426 
1427          CLOSE c_ev_data;
1428 
1429          -- 2908378 added to get the legal residency code
1430          OPEN c_perm_res_data;
1431          FETCH c_perm_res_data INTO l_legal_res_cntry_code;
1432          CLOSE c_perm_res_data;
1433 
1434       END IF;
1435       p_data_rec.legal_res_cntry_code := l_legal_res_cntry_code;
1436       p_data_rec.batch_id := p_person_rec.batch_id;
1437       p_data_rec.person_id := p_person_rec.person_id;
1438       p_data_rec.print_form := p_person_rec.print_form;
1439       p_data_rec.creation_date := sysdate;
1440       p_data_rec.created_by := g_update_by;
1441       p_data_rec.last_updated_by := g_update_by;
1442       p_data_rec.last_update_date  := sysdate;
1443       p_data_rec.last_update_login := g_update_login;
1444 
1445    END IF;
1446 
1447    CLOSE c_hz_data;
1448 
1449    IF Validate_Name(p_data_rec.last_name) THEN
1450 	 l_not_valid := TRUE;
1451 	 FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_INV_CHAR');
1452 	 FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
1453 	 Put_Log_Msg(FND_MESSAGE.Get,1);
1454    END IF;
1455 
1456    IF p_data_rec.birth_cntry_code = 'US' AND p_data_rec.birth_cntry_resn_code IS NULL
1457         THEN
1458 	 l_not_valid := TRUE;
1459 	 FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_CNTRY_RSN');
1460 	 FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
1461 	 Put_Log_Msg(FND_MESSAGE.Get,1);
1462    END IF;
1463 
1464    IF (p_data_rec.batch_id IS NULL) THEN
1465 
1466       Put_Log_Msg(l_api_name||' Successfully completed, no rows found returns N ',0);
1467 	/* Debug */
1468 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1469 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Bio_Info';
1470 	  l_debug_str := 'Returning N from Validate_Bio_Info.';
1471 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1472 	END IF;
1473 
1474       RETURN 'N';
1475 
1476    ELSE
1477 
1478       --
1479       -- Validate all the data for required fields for both types of students
1480       --
1481       IF (p_data_rec.last_name IS NULL        OR
1482           p_data_rec.birth_date IS NULL       OR
1483           p_data_rec.birth_cntry_code IS NULL) THEN
1484          l_not_valid := TRUE;
1485          FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_BIO_REQ_FLD_ERR'); -- Required fields for both Exchange Visitor or Foreign students
1486          FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
1487          Put_Log_Msg(FND_MESSAGE.Get,1);
1488       END IF;
1489       --
1490       -- Validate all the data for required fields for Foreign students
1491       --
1492 
1493       IF ( NVL(p_data_rec.visa_type,'X') NOT IN ('01','02') AND p_person_rec.dep_flag ='N' AND p_person_rec.batch_type = 'I')
1494          OR ( NVL(p_data_rec.visa_type,'X') NOT IN ('04','05') AND p_person_rec.dep_flag ='Y' AND p_person_rec.batch_type = 'I')
1495          OR ( NVL(p_data_rec.visa_type,'X') <> '03' AND p_person_rec.dep_flag ='N' AND p_person_rec.batch_type = 'E')
1496          OR ( NVL(p_data_rec.visa_type,'X') <> '06' AND p_person_rec.dep_flag ='Y' AND p_person_rec.batch_type = 'E')    THEN
1497          l_not_valid := TRUE;
1498          FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_BIO_NIMG_REQ_FLD_ERR'); -- Required Fields for Foreign students
1499          FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
1500          Put_Log_Msg(FND_MESSAGE.Get,1);
1501       END IF;
1502 
1503       -- 2908378 validation of legal residency code, birth city should fire for all persons
1504       --
1505       -- Validate all the data for required fields for Exchange Visitor students (even for dependants)
1506       --
1507 
1508       IF (NVL(p_person_rec.dep_flag,'N') <> 'Y' AND p_person_rec.batch_type = 'E' AND(p_data_rec.legal_res_cntry_code IS NULL OR
1509            p_data_rec.birth_city IS NULL
1510            ) ) THEN
1511          l_not_valid := TRUE;
1512          FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_BIO_EV_REQ_FLD_ERR'); -- Required Fields for Exchange Visitor students
1513          FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
1514          Put_Log_Msg(FND_MESSAGE.Get,1);
1515       END IF;
1516 
1517       -- 2908378 validation of position_code, category_code should not fire for dependants, since they need not have EV form
1518       --
1519       -- Validate all the data for required fields for Exchange Visitor students (not for dependants)
1520       --
1521       IF (p_person_rec.batch_type = 'E' AND NVL(p_person_rec.dep_flag,'N') <> 'Y' AND(
1522            p_data_rec.position_code IS NULL OR
1523            p_data_rec.category_code IS NULL
1524            ) ) THEN
1525          l_not_valid := TRUE;
1526          FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_BIO_EV_REQ_FLD_ERR'); -- Required Fields for Exchange Visitor students
1527          FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
1528          Put_Log_Msg(FND_MESSAGE.Get,1);
1529       END IF;
1530 
1531 
1532       IF (p_person_rec.batch_type = 'I' AND p_data_rec.citizen_cntry_code IS NULL) THEN
1533 	  l_not_valid := TRUE;
1534           FND_MESSAGE.SET_NAME('IGS', 'PERSON_NUMBER'); -- Required Fields for Exchange Visitor students
1535           FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
1536           Put_Log_Msg(FND_MESSAGE.Get,1);
1537       END IF;
1538 
1539 
1540       IF Check_US_Terr(p_person_rec.person_number,p_data_rec.citizen_cntry_code) ='E' THEN
1541 
1542         --Error in the citizenship countries
1543 
1544          Put_Log_Msg('Error validation citizenship country code',0);
1545          l_not_valid := TRUE;
1546       END IF;
1547 
1548       IF NVL(p_person_rec.dep_flag,'N') <> 'Y' AND Check_US_Terr(p_person_rec.person_number,p_data_rec.legal_res_cntry_code) ='E' THEN
1549 
1550         --Error in the citizenship countries
1551 
1552          Put_Log_Msg('Error validation citizenship country code',0);
1553          l_not_valid := TRUE;
1554       END IF;
1555 
1556 
1557       IF (l_not_valid) THEN
1558 
1559          Put_Log_Msg(l_api_name||' Validation error, return E ',0);
1560 	 /* Debug */
1561 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1562 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Bio_Info';
1563 	  l_debug_str := 'Returning E from Validate_Bio_Info.';
1564 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1565 	END IF;
1566          RETURN 'E';
1567 
1568       END IF;
1569 
1570    END IF;
1571 
1572    Put_Log_Msg(l_api_name||' Successfully completed, returns S',0);
1573 	/* Debug */
1574 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1575 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Bio_Info';
1576 	  l_debug_str := 'Returning S from Validate_Bio_Info.';
1577 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1578 	END IF;
1579 
1580    RETURN 'S'; -- Successfull validation
1581 
1582 EXCEPTION
1583 
1584    WHEN OTHERS THEN
1585 	/* Debug */
1586 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1587 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Bio_Info';
1588 	  l_debug_str := 'Exception in Validate_Bio_Info.'||SQLERRM;
1589 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1590 	END IF;
1591 
1592       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
1593          FND_MSg_PUB.Add_Exc_Msg (G_PKG_NAME, l_api_name);
1594       END IF;
1595       IF c_country_reason%ISOPEN THEN
1596 	CLOSE c_country_reason;
1597       END IF;
1598       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
1599 
1600       RETURN 'U';
1601 
1602 END Validate_Bio_Info;
1603 
1604 
1605 /******************************************************************
1606    Created By         : Arkadi Tereshenkov
1607 
1608    Date Created By    : Oct 14, 2002
1609 
1610    Purpose            : Validation on the data block pertaining to
1611                         Other information.  (IGS_SV_OTH_INFO)
1612 
1613    Remarks            : Return result:
1614                           'S' - record found and validated
1615                           'E' - validation error
1616                           'U' - Unexpected error
1617                           'N' - data not found
1618 
1619    Change History
1620    Who                  When            What
1621    pkpatel              23-APR-2003     Bug 2908378
1622                                         In all the 3 cursors replaced igs_pe_person_id_typ_v with igs_pe_person_id_typ
1623                                         Added to find the active record.
1624                                         In c_get_drivers the region code is to be retrieved from region_cd instead of attribute11
1625 ------------------------------------------------------------------------
1626 
1627 ******************************************************************/
1628 FUNCTION Validate_Other_Info (
1629    p_person_rec IN      t_student_rec,
1630    p_data_rec   IN OUT NOCOPY  IGS_SV_OTH_INFO%ROWTYPE    -- Data record
1631 ) RETURN VARCHAR2
1632 IS
1633 
1634    l_api_name CONSTANT VARCHAR(30) := 'Validate_Other_Info';
1635 
1636    CURSOR c_alternate_id(cp_system_person_id_type igs_pe_person_id_typ.s_person_id_type%TYPE) IS
1637      SELECT palt.api_person_id_uf,
1638             palt.region_cd
1639        FROM igs_pe_alt_pers_id       palt,
1640             igs_pe_person_id_typ     typv
1641       WHERE typv.s_person_id_type        = cp_system_person_id_type
1642         AND palt.person_id_type          = typv.person_id_type
1643         AND palt.pe_person_id            = p_person_rec.person_id
1644         AND SYSDATE BETWEEN palt.start_dt AND NVL(palt.end_dt,SYSDATE);
1645 
1646    l_drivers_license          IGS_PE_ALT_PERS_ID.api_person_id%TYPE;
1647    l_drivers_license_state    IGS_PE_ALT_PERS_ID.region_cd%TYPE;
1648    l_ssn                      IGS_PE_ALT_PERS_ID.api_person_id%TYPE;
1649    l_new_ssn                  IGS_PE_ALT_PERS_ID.api_person_id%TYPE;
1650    l_taxid                    IGS_PE_ALT_PERS_ID.api_person_id%TYPE;
1651    l_not_valid                BOOLEAN := FALSE;
1652    l_region_cd                IGS_PE_ALT_PERS_ID.region_cd%TYPE;
1653    lv_region_cd                IGS_PE_ALT_PERS_ID.region_cd%TYPE;
1654 
1655 BEGIN
1656 	/* Debug */
1657 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1658 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Other_Info';
1659 	  l_debug_str := 'Entering Validate_Other_Info. Batch_id is '||p_person_rec.batch_id||' and person_id is '||p_person_rec.person_id;
1660 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1661 	END IF;
1662    Put_Log_Msg(l_api_name||' starts ',0);
1663 
1664    p_data_rec.batch_id              := NULL;  -- This will tell us if there's been any records found
1665    p_data_rec.drivers_license       := NULL;
1666    p_data_rec.drivers_license_state := NULL;
1667    p_data_rec.ssn                   := NULL;
1668    p_data_rec.tax_id                := NULL;
1669 
1670    --
1671    -- Obtain the drivers license information
1672    --
1673    OPEN c_alternate_id('DRIVER-LIC');
1674    FETCH c_alternate_id
1675     INTO l_drivers_license,
1676          l_drivers_license_state;
1677 
1678    IF (c_alternate_id%FOUND) THEN
1679       p_data_rec.drivers_license       := SUBSTR(l_drivers_license, 1, 30);
1680       p_data_rec.drivers_license_state := SUBSTR(l_drivers_license_state,2);
1681    END IF;
1682    CLOSE c_alternate_id;
1683 
1684    -- Obtain the SSN number information
1685    --
1686    OPEN c_alternate_id('SSN');
1687    FETCH c_alternate_id
1688     INTO l_ssn,l_region_cd;
1689 
1690    IF (c_alternate_id%FOUND) THEN
1691       p_data_rec.ssn := SUBSTR(l_ssn, 1, 9);
1692    END IF;
1693    CLOSE c_alternate_id;
1694 
1695    --
1696    -- Obtain TAX ID information
1697    --
1698    OPEN c_alternate_id('TAXID');
1699    FETCH c_alternate_id
1700     INTO l_taxid,lv_region_cd;
1701 
1702    IF (c_alternate_id%FOUND) THEN
1703       p_data_rec.tax_id := SUBSTR(l_taxid, 1, 9);
1704       IF Is_Number(p_data_rec.tax_id) = '' THEN
1705 	FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_INV_TAXID');
1706         FND_MESSAGE.SET_TOKEN('PERSON_NUM', p_person_rec.person_number);
1707         Put_Log_Msg(FND_MESSAGE.Get,1);
1708         l_not_valid := true;
1709       END IF;
1710    END IF;
1711    CLOSE c_alternate_id;
1712 
1713    --
1714    -- Need to validate that the SSN is in correct format 999999999
1715    --
1716    IF p_data_rec.ssn IS NOT NULL THEN
1717      FOR i IN 1 .. LENGTH (l_ssn) LOOP
1718         l_new_ssn := l_new_ssn || Is_Number(SUBSTR(l_ssn, i, 1));  -- Returns NULL if not numberic value
1719      END LOOP;
1720    ELSE
1721      l_new_ssn := NULL;
1722    END IF;
1723 
1724    IF (l_new_ssn IS NOT NULL) THEN
1725 
1726       IF (LENGTH(l_new_ssn) <> 9) THEN
1727 
1728          FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_WARN_FLD_ERR'); -- Warning message for optional field
1729          FND_MESSAGE.SET_TOKEN('FIELD_NAME', 'SSN');
1730          FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
1731          Put_Log_Msg(FND_MESSAGE.Get,1);
1732          p_data_rec.ssn := NULL;   -- Only warning for bad SSN.  Just NULL out value to be sent.
1733 
1734       ELSE
1735 
1736          p_data_rec.ssn := l_new_ssn;
1737 
1738       END IF;
1739 
1740    END IF;
1741 
1742 --
1743 -- Check to see if there is a state associated to the license
1744 --
1745    IF (p_data_rec.drivers_license IS NOT NULL AND
1746        p_data_rec.drivers_license_state IS NULL) THEN
1747       FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_WARN_FLD_ERR'); -- Warning message for optional field
1748       FND_MESSAGE.SET_TOKEN('FIELD_NAME', 'Drivers License State');
1749       FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
1750       Put_Log_Msg(FND_MESSAGE.Get,1);
1751    END IF;
1752 
1753    IF (p_data_rec.tax_id           IS NOT NULL OR
1754        p_data_rec.ssn              IS NOT NULL OR
1755        p_data_rec.drivers_license IS NOT NULL) THEN
1756 
1757       p_data_rec.batch_id          := p_person_rec.batch_id;
1758       p_data_rec.person_id         := p_person_rec.person_id;
1759       p_data_rec.print_form        := p_person_rec.print_form;
1760       p_data_rec.creation_date     := sysdate;
1761       p_data_rec.created_by        := g_update_by;
1762       p_data_rec.last_updated_by   := g_update_by;
1763       p_data_rec.last_update_date  := sysdate;
1764       p_data_rec.last_update_login := g_update_login;
1765 
1766    END IF;
1767 
1768    IF p_data_rec.batch_id IS NULL THEN
1769 
1770       Put_Log_Msg(l_api_name||' Successfully completed, no rows found returns N ',0);
1771 	/* Debug */
1772 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1773 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Other_Info';
1774 	  l_debug_str := 'Returning N from Validate_Other_Info.';
1775 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1776 	END IF;
1777       RETURN 'N';
1778 
1779    ELSE
1780 
1781       IF (l_not_valid) THEN
1782 
1783          Put_Log_Msg(l_api_name||' Validation error, return E ',0);
1784 	 /* Debug */
1785 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1786 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Other_Info';
1787 	  l_debug_str := 'Returning E from Validate_Other_Info.';
1788 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1789 	END IF;
1790 
1791          RETURN 'E';
1792 
1793       END IF;
1794 
1795    END IF;
1796 
1797    Put_Log_Msg(l_api_name||' Successfully completed, returns S',0);
1798  /* Debug */
1799 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1800 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Other_Info';
1801 	  l_debug_str := 'Returning S from Validate_Other_Info.';
1802 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1803 	END IF;
1804 
1805    RETURN 'S'; -- Successfull validation
1806 
1807 EXCEPTION
1808 
1809    WHEN OTHERS THEN
1810       /* Debug */
1811 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1812 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Other_Info';
1813 	  l_debug_str := 'Exception in Validate_Other_Info.'||SQLERRM;
1814 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1815 	END IF;
1816 
1817       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
1818          FND_MSg_PUB.Add_Exc_Msg (G_PKG_NAME, l_api_name);
1819       END IF;
1820 
1821       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
1822 
1823       RETURN 'U';
1824 
1825 END Validate_Other_Info;
1826 
1827 
1828 
1829 /******************************************************************
1830    Created By         : Arkadi Tereshenkov
1831 
1832    Date Created By    : Oct 14, 2002
1833 
1834    Purpose            : Validate data pertaining to the Foreign
1835                         address information on the student.
1836                         (IGS_SV_ADDRESSES).
1837 
1838    Remarks            : Return result:
1839                            'S' - record found and validated
1840                            'E' - validation error
1841                            'U' - Unexpected error
1842                            'N' - data not found
1843 
1844    Change History
1845    Who                  When            What
1846 ------------------------------------------------------------------------
1847 
1848 ******************************************************************/
1849 FUNCTION Validate_F_Addr_Info (
1850    p_person_rec IN t_student_rec,
1851    p_data_rec   IN OUT NOCOPY  g_address_rec_type ,  -- Data record
1852    p_records    OUT NOCOPY  NUMBER   -- number of addressees found
1853 ) RETURN VARCHAR2
1854 IS
1855 
1856    l_api_name CONSTANT VARCHAR(30) := 'Validate_F_Addr_Info';
1857 
1858    CURSOR c_addr IS
1859      SELECT adr.party_site_id,
1860             addr_line_1,
1861             addr_line_2,
1862             addr_line_3,
1863             addr_line_4,
1864             city,
1865             state,
1866             province,
1867             country_cd,
1868             postal_code
1869        FROM igs_pe_addr_v adr,
1870             igs_pe_partysiteuse_v usg
1871       WHERE person_id = p_person_rec.person_id
1872         AND ( adr.status = 'A' AND SYSDATE BETWEEN NVL(start_dt,SYSDATE) AND NVL(end_dt, SYSDATE + 1) )
1873         AND usg.party_site_id  = adr.party_site_id
1874         AND usg.site_use_type  = g_f_addr_usage
1875         AND usg.active         = 'A';
1876 
1877    l_counter NUMBER(10):= 0;
1878    l_not_valid boolean  := FALSE;
1879 
1880 BEGIN
1881 
1882    Put_Log_Msg(l_api_name||' Starts ',0);
1883    /* Debug */
1884 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1885 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_F_Addr_Info';
1886 	  l_debug_str := 'Entering Validate_F_Addr_Info. batch_id is '|| p_person_rec.batch_id||' and person_id is '|| p_person_rec.person_id;
1887 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1888 	END IF;
1889 
1890 
1891    FOR c_addr_rec IN c_addr LOOP
1892 
1893        l_counter := l_counter +1;
1894 
1895        p_data_rec(l_counter).batch_id := p_person_rec.batch_id;
1896        p_data_rec(l_counter).person_id := p_person_rec.person_id;
1897        p_data_rec(l_counter).print_form := p_person_rec.print_form;
1898        p_data_rec(l_counter).party_site_id := c_addr_rec.party_site_id;
1899        p_data_rec(l_counter).address_type  := 'F';
1900        p_data_rec(l_counter).city   :=SUBSTR( c_addr_rec.city,1,60);
1901        p_data_rec(l_counter).state  := SUBSTR(c_addr_rec.state,1,2);
1902        p_data_rec(l_counter).postal_code := SUBSTR(c_addr_rec.postal_code,1,20);
1903        p_data_rec(l_counter).country_code := SUBSTR(c_addr_rec.country_cd,1,2);
1904        p_data_rec(l_counter).province  := SUBSTR(c_addr_rec.province,1,30);
1905        p_data_rec(l_counter).stdnt_valid_flag := '';
1906        p_data_rec(l_counter).creation_date := sysdate;
1907        p_data_rec(l_counter).created_by := g_update_by;
1908        p_data_rec(l_counter).last_updated_by := g_update_by;
1909        p_data_rec(l_counter).last_update_date  := sysdate;
1910        p_data_rec(l_counter).last_update_login := g_update_login;
1911 
1912        -- assignind adress lines
1913        p_data_rec(l_counter).address_line1 := SUBSTR(c_addr_rec.addr_line_1||c_addr_rec.addr_line_2||c_addr_rec.addr_line_3||c_addr_rec.addr_line_4,1,60);
1914        p_data_rec(l_counter).address_line2 := SUBSTR(c_addr_rec.addr_line_1||c_addr_rec.addr_line_2||c_addr_rec.addr_line_3||c_addr_rec.addr_line_4,61,120);
1915 
1916 	/* Debug */
1917 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1918 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_F_Addr_Info';
1919 	  l_debug_str := 'Exiting from for loop in Validate_F_Addr_Info.';
1920 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1921 	END IF;
1922 
1923        exit;  -- one address is enough
1924 
1925    END LOOP;
1926 
1927    p_records := l_counter;
1928 
1929    IF (l_counter = 0) THEN
1930 
1931       Put_Log_Msg(l_api_name||' Successfully completed, no rows found returns N ',0);
1932 	/* Debug */
1933 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1934 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_F_Addr_Info';
1935 	  l_debug_str := 'Returning N from Validate_F_Addr_Info.';
1936 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1937 	END IF;
1938       RETURN 'N';
1939 
1940    ELSE
1941 
1942      p_data_rec(l_counter).country_code := convert_country_code (p_data_rec(l_counter).country_code);
1943 
1944      IF (p_data_rec(l_counter).country_code IS NULL OR
1945          p_data_rec(l_counter).address_line1 IS NULL) THEN
1946 
1947          FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_F_ADDR_RQD_FLD_ERR'); -- Foreign address block error
1948          FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
1949 
1950          Put_Log_Msg(FND_MESSAGE.Get,1);
1951          l_not_valid := TRUE;
1952 
1953      END IF;
1954 
1955    END IF;
1956 
1957    IF l_not_valid THEN
1958 
1959      Put_Log_Msg(l_api_name||' Validation error, return E ',0);
1960      /* Debug */
1961 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1962 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_F_Addr_Info';
1963 	  l_debug_str := 'Returning E from Validate_F_Addr_Info.';
1964 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1965 	END IF;
1966 
1967      RETURN 'E';
1968 
1969    END IF;
1970 
1971    Put_Log_Msg(l_api_name||' Successfully completed, returns S',0);
1972    /* Debug */
1973 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1974 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_F_Addr_Info';
1975 	  l_debug_str := 'Returning S from Validate_F_Addr_Info.';
1976 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1977 	END IF;
1978 
1979    RETURN 'S'; -- Successfull validation
1980 
1981 EXCEPTION
1982 
1983    WHEN OTHERS THEN
1984    /* Debug */
1985 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
1986 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_F_Addr_Info';
1987 	  l_debug_str := 'Exception in Validate_F_Addr_Info.'||SQLERRM;
1988 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
1989 	END IF;
1990 
1991       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
1992          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
1993       END IF;
1994 
1995       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
1996 
1997       RETURN 'U';
1998 
1999 END Validate_F_Addr_Info;
2000 
2001 
2002 /******************************************************************
2003    Created By         : Arkadi Tereshenkov
2004 
2005    Date Created By    : Oct 14, 2002
2006 
2007    Purpose            : Validate the US Address block information
2008                         on the student.  (IGS_SV_ADDRESSES)
2009 
2010    Remarks            : Return result:
2011                            'S' - record found and validated
2012                            'E' - validation error
2013                            'U' - Unexpected error
2014                            'N' - data not found
2015 
2016    Change History
2017    Who                  When            What
2018    gmaheswa            12-Nov-2003    Modified c_addr cursor to select active address records,
2019                                       as part of address related changes .
2020 ------------------------------------------------------------------------
2021 
2022 ******************************************************************/
2023 FUNCTION Validate_Us_Addr_Info (
2024    p_person_rec IN t_student_rec,
2025    p_data_rec  IN OUT NOCOPY  g_address_rec_type ,  -- Data record
2026    p_records  IN  NUMBER   -- number of addressees found
2027 ) RETURN VARCHAR2
2028 IS
2029 
2030    l_api_name CONSTANT VARCHAR(30) := 'Validate_Us_Addr_Info';
2031 
2032    CURSOR c_addr IS
2033      SELECT adr.party_site_id,
2034             addr_line_1,
2035             addr_line_2,
2036             addr_line_3,
2037             addr_line_4,
2038             city,
2039             state,
2040             province,
2041             country_cd,
2042             postal_code,
2043 	    adr.identifying_address_flag
2044        FROM igs_pe_addr_v adr,
2045             igs_pe_partysiteuse_v usg
2046       WHERE person_id = p_person_rec.person_id
2047         AND ( adr.status = 'A' AND SYSDATE BETWEEN NVL(start_dt,SYSDATE) AND NVL(end_dt, SYSDATE + 1) )
2048         AND usg.party_site_id  = adr.party_site_id
2049         AND usg.site_use_type  = g_us_addr_usage
2050         AND usg.active         = 'A';
2051 
2052    l_counter NUMBER(10):= 0;
2053    l_not_valid BOOLEAN  := FALSE;
2054 
2055 BEGIN
2056 	/* Debug */
2057 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
2058 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_US_Addr_Info';
2059 	  l_debug_str := 'Entering Validate_US_Addr_Info. p_person_rec.batch_id is '||p_person_rec.batch_id ||' and person_id is '||p_person_rec.person_id;
2060 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
2061 	END IF;
2062    Put_Log_Msg(l_api_name||' Starts ',0);
2063 
2064    FOR c_addr_rec IN c_addr LOOP
2065 
2066        l_counter := l_counter +1;
2067 
2068        p_data_rec(l_counter).batch_id := p_person_rec.batch_id;
2069        p_data_rec(l_counter).person_id := p_person_rec.person_id;
2070        p_data_rec(l_counter).print_form := p_person_rec.print_form;
2071        p_data_rec(l_counter).party_site_id := c_addr_rec.party_site_id;
2072        p_data_rec(l_counter).address_type  := 'U';
2073        p_data_rec(l_counter).address_line1 := SUBSTR(c_addr_rec.addr_line_1||c_addr_rec.addr_line_2||c_addr_rec.addr_line_3||c_addr_rec.addr_line_4,1,60);
2074        p_data_rec(l_counter).address_line2 := SUBSTR(c_addr_rec.addr_line_1||c_addr_rec.addr_line_2||c_addr_rec.addr_line_3||c_addr_rec.addr_line_4,61,120);
2075        p_data_rec(l_counter).city   :=SUBSTR( c_addr_rec.city,1,60);
2076        p_data_rec(l_counter).state  := SUBSTR(c_addr_rec.state,1,2);
2077        p_data_rec(l_counter).postal_code := substr(c_addr_rec.postal_code,1,5);
2078        p_data_rec(l_counter).postal_routing_code := substr(c_addr_rec.postal_code,7,4);
2079        p_data_rec(l_counter).country_code := 'US';
2080        p_data_rec(l_counter).primary_flag := c_addr_rec.identifying_address_flag;
2081        p_data_rec(l_counter).province  := '';
2082        p_data_rec(l_counter).stdnt_valid_flag := '';
2083        p_data_rec(l_counter).creation_date := sysdate;
2084        p_data_rec(l_counter).created_by := g_update_by;
2085        p_data_rec(l_counter).last_updated_by := g_update_by;
2086        p_data_rec(l_counter).last_update_date  := sysdate;
2087        p_data_rec(l_counter).last_update_login := g_update_login;
2088 
2089 	/* Debug */
2090 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
2091 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_US_Addr_Info';
2092 	  l_debug_str := 'exiting from for loop in Validate_US_Addr_Info.';
2093 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
2094 	END IF;
2095 
2096        EXIT;  -- one address is enough
2097 
2098    END LOOP;
2099 
2100    IF (l_counter = 0) THEN
2101 
2102       Put_Log_Msg(l_api_name||' Successfully completed, no rows found returns N ',0);
2103 	/* Debug */
2104 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
2105 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_US_Addr_Info';
2106 	  l_debug_str := 'Returning N from Validate_US_Addr_Info. ';
2107 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
2108 	END IF;
2109 
2110       RETURN 'N';
2111    ELSE
2112 
2113     IF p_data_rec(l_counter).city IS NULL
2114        OR p_data_rec(l_counter).state IS NULL
2115        OR p_data_rec(l_counter).postal_code IS NULL
2116        OR p_data_rec(l_counter).address_line1 IS NULL THEN
2117 
2118          FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_US_ADDR_RQD_FLD_ERR'); -- US address block error
2119          FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
2120 
2121          Put_Log_Msg(FND_MESSAGE.Get,1);
2122          l_not_valid := TRUE;
2123 
2124      END IF;
2125 
2126      IF l_not_valid THEN
2127 
2128        Put_Log_Msg(l_api_name||' Validation error, return E ',0);
2129        /* Debug */
2130 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
2131 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_US_Addr_Info';
2132 	  l_debug_str := 'Returning E from Validate_US_Addr_Info. ';
2133 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
2134 	END IF;
2135 
2136        RETURN 'E';
2137 
2138      END IF;
2139 
2140 
2141    END IF;
2142 
2143    Put_Log_Msg(l_api_name||' Successfully completed, returns S',0);
2144    /* Debug */
2145 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
2146 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_US_Addr_Info';
2147 	  l_debug_str := 'Returning S from Validate_US_Addr_Info. ';
2148 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
2149 	END IF;
2150 
2151    RETURN 'S'; -- Successfull validation
2152 
2153 EXCEPTION
2154 
2155    WHEN OTHERS THEN
2156    /* Debug */
2157 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
2158 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_US_Addr_Info';
2159 	  l_debug_str := 'Exception in Validate_US_Addr_Info. '||SQLERRM;
2160 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
2161 	END IF;
2162 
2163       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
2164          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
2165       END IF;
2166 
2167       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
2168 
2169       RETURN 'U';
2170 
2171 END Validate_Us_Addr_Info;
2172 
2173 
2174 /******************************************************************
2175    Created By         : Arkadi Tereshenkov
2176 
2177    Date Created By    : Oct 14, 2002
2178 
2179    Purpose            : Validate the information pertaining to the
2180                         Activity Site Address for the student.
2181                         (IGS_SV_ADDRESSES).
2182 
2183    Remarks            : Return result:
2184                            'S' - record found and validated
2185                            'E' - validation error
2186                            'U' - Unexpected error
2187                            'N' - data not found
2188 
2189    Change History
2190    Who                  When            What
2191    pkpatel              23-APR-2003     Bug No 2908378
2192                                         Replaced IGS_PE_ADDR_V with IGS_AD_LOCVENUE_ADDR_V while joining with IGS_PE_ACT_SITE
2193                                         Selected LOCATION_ID instead of PARTY_SITE_ID for these cases.
2194                                         Added p_data_rec(l_counter).party_site_id := c_addr_rec.party_site_id
2195    gmaheswa             12-Nov-2003     Modified c_addr cursor to select active address records,
2196                                         as part of address related changes .
2197    pkpatel              4-Dec-2003      Bug 3227107 (Used the status column for address)
2198    vskumar		26-May-06	xbuild3 performance fix. deleted the body of the function as no longer used any where.
2199 ------------------------------------------------------------------------
2200 
2201 ******************************************************************/
2202 FUNCTION Validate_Site_Info (
2203    p_person_rec IN      t_student_rec,
2204    p_data_rec   IN OUT NOCOPY  g_address_rec_type ,  -- Data record
2205    p_records    OUT NOCOPY     NUMBER                -- number of addressees found
2206 ) RETURN VARCHAR2
2207 IS
2208 BEGIN
2209 	RETURN NULL;
2210 END Validate_Site_Info;
2211 
2212 
2213 /******************************************************************
2214    Created By         : Arkadi Tereshenkov
2215 
2216    Date Created By    : Oct 14, 2002
2217 
2218    Purpose            : Validate the information that is pertaining
2219                         to the Education Block information.
2220                         (IGS_SV_PRGMS_INFO).
2221 
2222    Remarks            : Return result:
2223                            'S' - record found and validated
2224                            'E' - validation error
2225                            'U' - Unexpected error
2226                            'N' - data not found
2227 
2228    Change History
2229    Who                  When            What
2230 ------------------------------------------------------------------------
2231 
2232 ******************************************************************/
2233 FUNCTION Validate_Edu_Info (
2234    p_person_rec IN t_student_rec,
2235    p_data_rec  IN OUT NOCOPY  IGS_SV_PRGMS_INFO%ROWTYPE
2236 ) RETURN VARCHAR2
2237 IS
2238 
2239    l_api_name CONSTANT VARCHAR(30) := 'Validate_Edu_Info';
2240 
2241    CURSOR c_nonimg_data IS
2242      SELECT penf.education_level,
2243             penf.primary_major,
2244             penf.secondary_major,
2245             penf.minor,
2246             penf.length_of_study,
2247             penf.prgm_start_date,
2248             penf.prgm_end_date,
2249             decode(penf.english_reqd,'Y','1','0')  english_reqd,
2250             decode(penf.english_reqd_met,'Y','1','0')  english_reqd_met,
2251             penf.not_reqd_reason,
2252             penf.educ_lvl_remarks
2253        FROM igs_pe_nonimg_form     penf
2254       WHERE penf.person_id = p_person_rec.person_id
2255         AND penf.nonimg_form_id = p_person_rec.form_id;
2256 
2257    CURSOR c_ev_data IS
2258      SELECT peev.position_code,
2259             peev.subject_field_code,
2260             peev.subject_field_remarks,
2261 	    prgm_start_date,
2262 	    prgm_end_date
2263        FROM igs_pe_ev_form   peev
2264       WHERE peev.person_id  = p_person_rec.person_id
2265         AND peev.ev_form_id = p_person_rec.form_id;
2266 
2267 
2268    l_not_valid                  BOOLEAN := FALSE;
2269    l_education_level            igs_pe_nonimg_form.education_level%TYPE;
2270    l_primary_major              igs_pe_nonimg_form.primary_major%TYPE;
2271    l_secondary_major            igs_pe_nonimg_form.secondary_major%TYPE;
2272    l_minor                      igs_pe_nonimg_form.minor%TYPE;
2273    l_length_of_study            igs_pe_nonimg_form.length_of_study%TYPE;
2274    l_prgm_start_date            igs_pe_nonimg_form.prgm_start_date%TYPE;
2275    l_prgm_end_date              igs_pe_nonimg_form.prgm_end_date%TYPE;
2276    l_english_reqd               igs_pe_nonimg_form.english_reqd%TYPE;
2277    l_english_reqd_met           igs_pe_nonimg_form.english_reqd_met%TYPE;
2278    l_not_reqd_reason            igs_pe_nonimg_form.not_reqd_reason%TYPE;
2279    l_educ_lvl_remarks           igs_pe_nonimg_form.educ_lvl_remarks%TYPE;
2280    l_position_code              igs_pe_ev_form.position_code%TYPE;
2281    l_subject_field_code         igs_pe_ev_form.subject_field_code%TYPE;
2282    l_subject_field_remarks      igs_pe_ev_form.subject_field_remarks%TYPE;
2283    l_ev_prgm_start_date            igs_pe_ev_form.prgm_start_date%TYPE;
2284    l_ev_prgm_end_date              igs_pe_ev_form.prgm_end_date%TYPE;
2285 
2286 
2287 BEGIN
2288 /* Debug */
2289 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
2290 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Edu_Info
2291 	  ';
2292 	  l_debug_str := 'Entering Validate_Edu_Info. p_person_rec.batch_id is '||p_person_rec.batch_id ||' and person_id is '||p_person_rec.person_id;
2293 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
2294 	END IF;
2295 
2296    Put_Log_Msg(l_api_name||' starts ',0);
2297 
2298    p_data_rec.batch_id := NULL;  -- This will tell us if there's been any records found
2299 
2300 --
2301 -- Process Non Immigrant Foreign Student data
2302 --
2303    IF (p_person_rec.batch_type = 'I') THEN
2304 
2305       OPEN c_nonimg_data;
2306       FETCH c_nonimg_data
2307        INTO l_education_level,
2308             l_primary_major,
2309             l_secondary_major,
2310             l_minor,
2311             l_length_of_study,
2312             l_prgm_start_date,
2313             l_prgm_end_date,
2314             l_english_reqd,
2315             l_english_reqd_met,
2316             l_not_reqd_reason,
2317             l_educ_lvl_remarks;
2318 
2319       IF (c_nonimg_data%FOUND) THEN
2320          p_data_rec.batch_id          := p_person_rec.batch_id;
2321          p_data_rec.person_id         := p_person_rec.person_id;
2322          p_data_rec.print_form        := p_person_rec.print_form;
2323          p_data_rec.creation_date     := sysdate;
2324          p_data_rec.created_by        := g_update_by;
2325          p_data_rec.last_updated_by   := g_update_by;
2326          p_data_rec.last_update_date  := sysdate;
2327          p_data_rec.last_update_login := g_update_login;
2328          p_data_rec.prgm_action_type := 'EP';
2329 
2330          p_data_rec.education_level   := l_education_level;
2331          p_data_rec.primary_major     := l_primary_major;
2332          p_data_rec.secondary_major   := l_secondary_major;
2333          p_data_rec.educ_lvl_remarks  := l_educ_lvl_remarks;
2334          p_data_rec.minor             := l_minor;
2335          p_data_rec.length_of_study   := ltrim(to_char(to_number(l_length_of_study),'00'));
2336          p_data_rec.prgm_start_date   := to_char(l_prgm_start_date, 'YYYY-MM-DD');
2337          p_data_rec.prgm_end_date     := to_char(l_prgm_end_date, 'YYYY-MM-DD');
2338          p_data_rec.english_reqd      := l_english_reqd;
2339          p_data_rec.english_reqd_met  := l_english_reqd_met;
2340          p_data_rec.not_reqd_reason   := l_not_reqd_reason;
2341 
2342       END IF;
2343 
2344       CLOSE c_nonimg_data;
2345 
2346    ELSE
2347 --
2348 -- Process Exchange Visitor Student data
2349 --
2350        OPEN c_ev_data;
2351       FETCH c_ev_data
2352        INTO l_position_code,
2353             l_subject_field_code,
2354             l_subject_field_remarks,
2355 	    l_ev_prgm_start_date,
2356 	    l_ev_prgm_end_date;
2357 
2358       IF (c_ev_data%FOUND) THEN
2359 
2360          p_data_rec.batch_id             := p_person_rec.batch_id;
2361          p_data_rec.person_id            := p_person_rec.person_id;
2362          p_data_rec.print_form           := p_person_rec.print_form;
2363          p_data_rec.creation_date        := sysdate;
2364          p_data_rec.created_by           := g_update_by;
2365          p_data_rec.last_updated_by      := g_update_by;
2366          p_data_rec.last_update_date     := sysdate;
2367          p_data_rec.last_update_login    := g_update_login;
2368          p_data_rec.prgm_action_type     := 'EP';
2369          p_data_rec.position_code        := l_position_code;
2370          p_data_rec.subject_field_code   := l_subject_field_code;
2371          p_data_rec.remarks              := l_subject_field_remarks;
2372 	 p_data_rec.prgm_start_date   := to_char(l_ev_prgm_start_date, 'YYYY-MM-DD');
2373          p_data_rec.prgm_end_date     := to_char(l_ev_prgm_end_date, 'YYYY-MM-DD');
2374 
2375       END IF;
2376 
2377       CLOSE c_ev_data;
2378 
2379    END IF;
2380 
2381    IF p_data_rec.batch_id IS NULL THEN
2382 
2383       Put_Log_Msg(l_api_name||' Successfully completed, no rows found returns N ',0);
2384 /* Debug */
2385 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
2386 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Edu_Info';
2387 	  l_debug_str := 'Returning N from Validate_Edu_Info.';
2388 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
2389 	END IF;
2390 
2391       RETURN 'N';
2392 
2393    ELSE
2394 
2395      -- Validate all the data
2396 
2397      IF (p_person_rec.batch_type = 'I') THEN
2398 
2399 --
2400 -- Validate that the required fields for Foreign Student are available.
2401 --
2402         IF (p_data_rec.education_level IS NULL     OR
2403             p_data_rec.primary_major IS NULL       OR
2404             p_data_rec.length_of_study IS NULL     OR
2405             p_data_rec.prgm_start_date IS NULL     OR
2406             p_data_rec.prgm_end_date IS NULL       OR
2407             p_data_rec.english_reqd IS NULL) THEN
2408            l_not_valid := TRUE;
2409            FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_EDU_NIMG_REQ_FLD_ERR'); -- Required fields for Foreign Students
2410            FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
2411            Put_Log_Msg(FND_MESSAGE.Get,1);
2412         END IF;
2413 
2414 --
2415 -- Make sure that there is a value for the English requirement being met or not
2416 --
2417         IF ( p_data_rec.english_reqd = 'Y'  AND p_data_rec.english_reqd_met IS NULL) THEN
2418             l_not_valid := TRUE;
2419             FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_EDU_NIMG_MET_ERR'); -- Required field for Foreign students if english required
2420             FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
2421             Put_Log_Msg(FND_MESSAGE.Get,1);
2422         END IF;
2423 
2424         IF ( p_data_rec.education_level = '11'  AND p_data_rec.educ_lvl_remarks IS NULL) THEN
2425             l_not_valid := TRUE;
2426             FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_EDU_NIMG_REQ_FLD_ERR'); -- Required field for Foreign students if english required
2427             FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
2428             Put_Log_Msg(FND_MESSAGE.Get,1);
2429         END IF;
2430 
2431 --
2432 -- Make sure that there is a reason for the requirement not being met.
2433 --
2434         IF (p_data_rec.english_reqd = 'N'    AND
2435             p_data_rec.not_reqd_reason IS NULL) THEN
2436             l_not_valid := TRUE;
2437             FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_EDU_NIMG_NOT_MET_ERR'); -- Required field for Foreign students english not met
2438             FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
2439             Put_Log_Msg(FND_MESSAGE.Get,1);
2440          END IF;
2441 
2442      ELSE
2443 
2444 --
2445 -- Validate that the required fields are present for the Exchange Visitor.
2446 --
2447         IF (p_data_rec.position_code IS NULL
2448             OR  p_data_rec.subject_field_code IS NULL
2449             OR p_data_rec.remarks IS NULL)  THEN
2450            l_not_valid := TRUE;
2451            FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_EDU_EV_REQ_FLD_ERR'); -- Required field for Exchange Visitor not available.
2452            FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
2453            Put_Log_Msg(FND_MESSAGE.Get,1);
2454         END IF;
2455 
2456      END IF;
2457 
2458      IF (l_not_valid) THEN
2459 
2460         Put_Log_Msg(l_api_name||' Validation error, return E ',0);
2461 	/* Debug */
2462 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
2463 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Edu_Info';
2464 	  l_debug_str := 'Returning E from Validate_Edu_Info.';
2465 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
2466 	END IF;
2467         RETURN 'E';
2468 
2469      END IF;
2470 
2471    END IF;
2472 
2473    Put_Log_Msg(l_api_name||' Successfully completed, returns S',0);
2474    /* Debug */
2475 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
2476 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Edu_Info';
2477 	  l_debug_str := 'Returning S from Validate_Edu_Info.';
2478 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
2479 	END IF;
2480 
2481    RETURN 'S'; -- Successfull validation
2482 
2483 EXCEPTION
2484 
2485    WHEN OTHERS THEN
2486 	/* Debug */
2487 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
2488 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Edu_Info';
2489 	  l_debug_str := 'Exception in Validate_Edu_Info.'||SQLERRM;
2490 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
2491 	END IF;
2492 
2493       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
2494          FND_MSg_PUB.Add_Exc_Msg (G_PKG_NAME, l_api_name);
2495       END IF;
2496 
2497       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
2498 
2499       RETURN 'U';
2500 
2501 END Validate_Edu_Info;
2502 
2503 
2504 /******************************************************************
2505    Created By         : Arkadi Tereshenkov
2506 
2507    Date Created By    : Oct 14, 2002
2508 
2509    Purpose            : Validate information pertaining to the Program
2510                         information block for the student.
2511                         (IGS_SV_PRGMS_INFO).
2512 
2513    Remarks            : Return result:
2514                            'S' - record found and validated
2515                            'E' - validation error
2516                            'U' - Unexpected error
2517                            'N' - data not found
2518 
2519    Change History
2520    Who                  When            What
2521 ------------------------------------------------------------------------
2522 
2523 ******************************************************************/
2524 FUNCTION Get_Othr_Prgm_Info(
2525  p_data_rec  IN OUT NOCOPY  IGS_SV_PRGMS_INFO%ROWTYPE
2526 ) RETURN VARCHAR2
2527 IS
2528      l_api_name CONSTANT VARCHAR(30) := 'Get_Othr_Prgm_Info';
2529 
2530    CURSOR c_nonimg_data IS
2531      SELECT penf.education_level,
2532             penf.primary_major,
2533             penf.secondary_major,
2534             penf.minor,
2535             penf.length_of_study,
2536             penf.prgm_start_date,
2537             penf.prgm_end_date,
2538             decode(penf.english_reqd,'Y','1','0')  english_reqd,
2539             decode(penf.english_reqd_met,'Y','1','0')  english_reqd_met,
2540             penf.not_reqd_reason,
2541             penf.educ_lvl_remarks
2542        FROM igs_pe_nonimg_form     penf
2543       WHERE penf.person_id = p_data_rec.person_id
2544         AND penf.nonimg_form_id = g_nonimg_form_id;
2545 
2546    CURSOR c_ev_data IS
2547      SELECT peev.position_code,
2548             peev.subject_field_code,
2549             peev.subject_field_remarks,
2550 	    prgm_start_date,
2551 	    prgm_end_date
2552        FROM igs_pe_ev_form   peev
2553       WHERE peev.person_id  = p_data_rec.person_id
2554         AND peev.ev_form_id = g_nonimg_form_id;
2555 
2556 
2557    l_education_level            igs_pe_nonimg_form.education_level%TYPE;
2558    l_primary_major              igs_pe_nonimg_form.primary_major%TYPE;
2559    l_secondary_major            igs_pe_nonimg_form.secondary_major%TYPE;
2560    l_minor                      igs_pe_nonimg_form.minor%TYPE;
2561    l_length_of_study            igs_pe_nonimg_form.length_of_study%TYPE;
2562    l_prgm_start_date            igs_pe_nonimg_form.prgm_start_date%TYPE;
2563    l_prgm_end_date              igs_pe_nonimg_form.prgm_end_date%TYPE;
2564    l_english_reqd               igs_pe_nonimg_form.english_reqd%TYPE;
2565    l_english_reqd_met           igs_pe_nonimg_form.english_reqd_met%TYPE;
2566    l_not_reqd_reason            igs_pe_nonimg_form.not_reqd_reason%TYPE;
2567    l_educ_lvl_remarks           igs_pe_nonimg_form.educ_lvl_remarks%TYPE;
2568    l_position_code              igs_pe_ev_form.position_code%TYPE;
2569    l_subject_field_code         igs_pe_ev_form.subject_field_code%TYPE;
2570    l_subject_field_remarks      igs_pe_ev_form.subject_field_remarks%TYPE;
2571    l_ev_prgm_start_date            igs_pe_ev_form.prgm_start_date%TYPE;
2572    l_ev_prgm_end_date              igs_pe_ev_form.prgm_end_date%TYPE;
2573    l_not_valid BOOLEAN := TRUE;
2574 BEGIN
2575 
2576 	/* Debug */
2577 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
2578 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Othr_Prgm_Info';
2579 	  l_debug_str := 'Entering Get_Othr_Prgm_Info. form_id is '||g_nonimg_form_id ||' and person_id is '||p_data_rec.person_id;
2580 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
2581 	END IF;
2582 
2583         Put_Log_Msg(l_api_name||' starts ',0);
2584 
2585       OPEN c_nonimg_data;
2586       FETCH c_nonimg_data
2587        INTO l_education_level,
2588             l_primary_major,
2589             l_secondary_major,
2590             l_minor,
2591             l_length_of_study,
2592             l_prgm_start_date,
2593             l_prgm_end_date,
2594             l_english_reqd,
2595             l_english_reqd_met,
2596             l_not_reqd_reason,
2597             l_educ_lvl_remarks;
2598 
2599       IF (c_nonimg_data%FOUND) THEN
2600          p_data_rec.education_level   := l_education_level;
2601          p_data_rec.primary_major     := l_primary_major;
2602          p_data_rec.secondary_major   := l_secondary_major;
2603          p_data_rec.educ_lvl_remarks  := l_educ_lvl_remarks;
2604          p_data_rec.minor             := l_minor;
2605          p_data_rec.length_of_study   := ltrim(to_char(to_number(l_length_of_study),'00'));
2606          p_data_rec.prgm_start_date   := to_char(l_prgm_start_date, 'YYYY-MM-DD');
2607          p_data_rec.prgm_end_date     := to_char(l_prgm_end_date, 'YYYY-MM-DD');
2608          p_data_rec.english_reqd      := l_english_reqd;
2609          p_data_rec.english_reqd_met  := l_english_reqd_met;
2610          p_data_rec.not_reqd_reason   := l_not_reqd_reason;
2611 	 l_not_valid := FALSE;
2612       ELSE
2613           OPEN c_ev_data;
2614           FETCH c_ev_data
2615 	  INTO l_position_code,
2616 	       l_subject_field_code,
2617 	       l_subject_field_remarks,
2618 	       l_ev_prgm_start_date,
2619 	       l_ev_prgm_end_date;
2620 
2621 	      IF (c_ev_data%FOUND) THEN
2622 		 p_data_rec.position_code        := l_position_code;
2623 		 p_data_rec.subject_field_code   := l_subject_field_code;
2624 		 p_data_rec.remarks              := l_subject_field_remarks;
2625 		 p_data_rec.prgm_start_date   := to_char(l_ev_prgm_start_date, 'YYYY-MM-DD');
2626 		 p_data_rec.prgm_end_date     := to_char(l_ev_prgm_end_date, 'YYYY-MM-DD');
2627 		 l_not_valid := FALSE;
2628 	      END IF;
2629 
2630 	      CLOSE c_ev_data;
2631       END IF;
2632 
2633       CLOSE c_nonimg_data;
2634       IF l_not_valid THEN
2635 	  RETURN 'E';
2636        ELSE
2637           RETURN 'S'; -- Successfull validation
2638        END IF;
2639 
2640 EXCEPTION
2641 
2642    WHEN OTHERS THEN
2643 	/* Debug */
2644 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
2645 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Othr_Prgm_Info';
2646 	  l_debug_str := 'Exception in Get_Othr_Prgm_Info.'||SQLERRM;
2647 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
2648 	END IF;
2649 
2650       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
2651          FND_MSg_PUB.Add_Exc_Msg (G_PKG_NAME, l_api_name);
2652       END IF;
2653       CLOSE c_ev_data;
2654       CLOSE c_nonimg_data;
2655       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
2656 
2657       RETURN 'U';
2658 
2659 END Get_Othr_Prgm_Info;
2660 
2661 FUNCTION Validate_Prgm_Info (
2662    p_person_rec IN t_student_rec,
2663    p_data_rec  IN OUT NOCOPY  g_edu_rec_type,
2664    p_records    OUT NOCOPY     NUMBER ,      -- Number of program records found
2665    p_auth_drp_data_rec IN OUT NOCOPY IGS_SV_PRGMS_INFO%ROWTYPE
2666 ) RETURN VARCHAR2
2667 IS
2668 
2669    l_api_name CONSTANT VARCHAR(30) := 'Validate_Prgm_Info';
2670 
2671    CURSOR c_data IS
2672      SELECT nonimg_stat_id,
2673             nonimg_form_id,
2674             to_char(action_date,'YYYY-MM-DD') action_date,
2675             action_type,
2676             to_char(prgm_start_date,'YYYY-MM-DD') prgm_start_date,
2677             to_char(prgm_end_date,'YYYY-MM-DD') prgm_end_date,
2678             remarks,
2679             termination_reason,
2680 	    print_flag, --prbhardw
2681 	    cancel_flag
2682        FROM igs_pe_nonimg_stat
2683       WHERE nonimg_form_id = p_person_rec.form_id
2684             AND nonimg_stat_id NOT IN
2685             ( SELECT NVL(form_status_id,0)
2686                 FROM igs_sv_prgms_info prg,
2687                      igs_sv_persons pr
2688                WHERE prg.person_id = pr.person_id
2689                      AND prg.batch_id = pr.batch_id
2690                      AND pr.record_status <> 'E'
2691                      AND prg.person_id = p_person_rec.person_id
2692                )
2693    ORDER BY action_date;
2694 
2695    CURSOR c_ev_data IS
2696      SELECT ev_form_stat_id    ,
2697             ev_form_id         ,
2698             to_char(action_date,'YYYY-MM-DD') action_date,
2699             action_type        ,
2700             to_char(prgm_start_date,'YYYY-MM-DD') prgm_start_date,
2701             to_char(prgm_end_date,'YYYY-MM-DD') prgm_end_date,
2702             remarks            ,
2703             termination_reason ,
2704             end_program_reason
2705        FROM igs_pe_ev_form_stat
2706       WHERE ev_form_id = p_person_rec.form_id
2707             AND ev_form_stat_id NOT IN
2708             ( SELECT NVL(form_status_id,0)
2709                 FROM igs_sv_prgms_info prg,
2710                      igs_sv_persons pr
2711                WHERE prg.person_id = pr.person_id
2712                      AND pr.record_status <> 'E'
2713                      AND prg.batch_id = pr.batch_id
2714                      AND prg.person_id = p_person_rec.person_id)
2715    ORDER BY action_date;
2716 
2717   CURSOR c_ev_category_data IS
2718      SELECT category_code,
2719             prgm_start_date,
2720             prgm_end_date
2721        FROM igs_pe_ev_form
2722       WHERE ev_form_id = p_person_rec.form_id;
2723 
2724   CURSOR c_drp IS
2725    SELECT prgms.authorization_reason,
2726           prgms.prgm_start_date,
2727           prgms.prgm_end_date,
2728           prgms.remarks,
2729 	  prgms.auth_action_code
2730      FROM igs_sv_prgms_info  prgms,
2731           igs_sv_persons pr
2732     WHERE prgms.person_id = pr.person_id
2733           AND pr.record_status <> 'E'
2734           AND prgms.person_id  = p_person_rec.person_id
2735           AND prgms.prgm_action_type  = 'DB'
2736 	  AND prgms.batch_id IN
2737 	      ( SELECT max(prs.batch_id)
2738 		 FROM igs_sv_prgms_info prs,
2739 		      igs_sv_persons pr
2740 	       WHERE prs.person_id = pr.person_id
2741 		     AND prs.batch_id = pr.batch_id
2742 		     AND pr.record_status <> 'E'
2743 		     AND prs.person_id = p_person_rec.person_id
2744 		     AND prs.prgm_action_type = 'DB'
2745 	      );
2746 
2747   CURSOR c_res IS
2748    SELECT prgms.prgm_start_date,
2749           prgms.prgm_end_date,
2750           prgms.remarks
2751      FROM igs_sv_prgms_info   prgms,
2752           igs_sv_persons pr
2753     WHERE prgms.person_id = pr.person_id
2754           AND prgms.batch_id = pr.batch_id
2755           AND pr.record_status <> 'E'
2756           AND prgms.person_id         = p_person_rec.person_id
2757           AND prgms.prgm_action_type  = 'RF';
2758 
2759 
2760    CURSOR c_visa_type IS
2761     SELECT visa_type
2762     FROM IGS_PE_NONIMG_FORM
2763     WHERE nonimg_form_id = p_person_rec.form_id;
2764 
2765    CURSOR c_termination_reason(p_visa varchar2, p_term_reason igs_pe_nonimg_stat.termination_reason%TYPE) IS
2766       SELECT COUNT(1)
2767       FROM igs_pe_nonimg_stat
2768       WHERE nonimg_form_id = p_person_rec.form_id
2769             AND p_term_reason NOT IN
2770             ( SELECT lookup_code FROM igs_lookup_values
2771 	      WHERE lookup_type ='PE_SV_TERMINATE_REASON' AND
2772 		    enabled_flag ='Y' AND
2773 		    (tag= p_visa OR tag= 'FM')
2774 	     );
2775 
2776    --prbhardw
2777    CURSOR c_prev_end_date IS
2778      SELECT
2779           PRGM_END_DATE
2780      FROM
2781           IGS_PE_NONIMG_FORM_V
2782      WHERE
2783           nonimg_form_id = p_person_rec.form_id;
2784 
2785    l_not_valid     BOOLEAN := FALSE;
2786    l_AUTH_CODE     VARCHAR2(2);
2787    l_AUTH_START_DT DATE;
2788    l_AUTH_END_DT   DATE;
2789    l_COMMENTS      VARCHAR2(500);
2790    l_visa_type VARCHAR(5);
2791    l_termination_count NUMBER := 0;
2792    l_category_code  VARCHAR2(30);
2793    l_prgm_start_dt DATE;
2794    l_prgm_end_dt   DATE;
2795    lv_prgm_end_dt DATE;
2796    l_cancel_flag  VARCHAR2(1);    -- will go as fifth OUT parameter in ENRF_GET_SEVIS_AUTH_DETAILS
2797    l_auth_rec_count NUMBER(2) := 0;
2798    l_counter NUMBER(10):= 0;
2799 BEGIN
2800 
2801 	/* Debug */
2802 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
2803 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Prgm_Info';
2804 	  l_debug_str := 'Entering Validate_Prgm_Info. p_person_rec.batch_id is '||p_person_rec.batch_id ||' and person_id is '||p_person_rec.person_id;
2805 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
2806 	END IF;
2807 
2808    Put_Log_Msg(l_api_name||' starts ',0);
2809 
2810 --   p_data_rec.batch_id := NULL;  -- This will tell us if there's been any records found
2811    IF p_person_rec.batch_type = 'I' THEN
2812 
2813      -- RF Resume Full Course  STUB - doesn't exist
2814      -- DB Dropped Below Full Course
2815      --  Check for drop below FC
2816       --mmkumar, auth_drop_below
2817      /*
2818      p_auth_drp_data_rec.prgm_action_type := '';
2819 
2820      IF IGS_EN_SEVIS.ENRF_GET_SEVIS_AUTH_DETAILS(
2821            p_person_id     => p_person_rec.person_id,
2822            p_auth_code     => l_auth_code,
2823            p_auth_start_dt => l_auth_start_dt,
2824            p_auth_end_dt   => l_auth_end_dt,
2825            p_comments      => l_comments )
2826 
2827       THEN
2828 
2829         p_auth_drp_data_rec.prgm_action_type :='DB';
2830 	p_auth_drp_data_rec.authorization_reason := l_auth_code;
2831 	p_auth_drp_data_rec.prgm_start_date := to_char(l_auth_start_dt,'YYYY-MM-DD');
2832         p_auth_drp_data_rec.prgm_end_date := to_char(l_auth_end_dt,'YYYY-MM-DD');
2833         p_auth_drp_data_rec.remarks := l_comments;
2834 
2835 
2836 
2837         FOR c_drp_rec IN c_drp LOOP
2838 
2839 	  l_auth_rec_count := l_auth_rec_count +1;	-- prbhardw CP enhancement
2840 	  IF l_cancel_flag <> 'Y' THEN
2841 		  IF c_drp_rec.authorization_reason
2842 		     ||g_delimeter||c_drp_rec.prgm_start_date
2843 		     ||g_delimeter||c_drp_rec.prgm_end_date
2844 		     ||g_delimeter||c_drp_rec.remarks <>
2845 		     l_auth_code
2846 		     ||g_delimeter||to_char(l_auth_start_dt,'YYYY-MM-DD')
2847 		     ||g_delimeter||to_char(l_auth_end_dt,'YYYY-MM-DD')
2848 		     ||g_delimeter||l_comments THEN
2849 
2850 		     p_auth_drp_data_rec.auth_action_code := 'EDIT';
2851 		     -- already reported.
2852 		    -- p_data_rec.prgm_action_type :='';
2853 		    -- p_data_rec.authorization_reason := '';
2854 		   --  p_data_rec.prgm_start_date := '';
2855 		    -- p_data_rec.prgm_end_date := '';
2856 		    -- p_data_rec.remarks := '';
2857 		    -- p_data_rec.auth_action_code := '';
2858 
2859 		   ELSE
2860 		      p_auth_drp_data_rec.auth_action_code := c_drp_rec.auth_action_code;
2861 		   END IF;
2862 	  ELSE
2863 	       p_auth_drp_data_rec.auth_action_code := 'CANCEL';
2864 	  END IF;
2865 
2866         END LOOP;
2867 	IF l_auth_rec_count = 0 THEN
2868 	      p_auth_drp_data_rec.auth_action_code := 'ADD';
2869 	END IF;
2870 
2871     ELSE
2872           p_auth_drp_data_rec.prgm_action_type :='';
2873     END IF;
2874     IF p_data_rec(1).prgm_action_type = '' AND IGS_EN_SEVIS.ENRF_GET_RET_FT_NOTE_DETAILS(
2875            p_person_id     => p_person_rec.person_id,
2876            P_NOTE_TYPE     => l_auth_code,
2877            P_NOTE_START_DT => l_auth_start_dt,
2878            P_NOTE_END_DT   => l_auth_end_dt,
2879            P_NOTE_TEXT     => l_comments )
2880 
2881       THEN
2882 
2883         p_data_rec(1).prgm_action_type :='RF';
2884         p_data_rec(1).prgm_start_date := to_char(l_auth_start_dt,'YYYY-MM-DD');
2885         p_data_rec(1).prgm_end_date := to_char(l_auth_end_dt,'YYYY-MM-DD');
2886         p_data_rec(1).remarks := l_comments;
2887 
2888 
2889         FOR c_drp_rec IN c_res LOOP
2890 
2891 
2892           IF c_drp_rec.prgm_start_date
2893              ||g_delimeter||c_drp_rec.prgm_end_date
2894              ||g_delimeter||c_drp_rec.remarks =
2895              to_char(l_auth_start_dt,'YYYY-MM-DD')
2896              ||g_delimeter||to_char(l_auth_end_dt,'YYYY-MM-DD')
2897              ||g_delimeter||l_comments THEN
2898 
2899              -- already reported.
2900              p_data_rec(1).prgm_action_type :='';
2901              p_data_rec(1).authorization_reason := '';
2902              p_data_rec(1).prgm_start_date := '';
2903              p_data_rec(1).prgm_end_date := '';
2904              p_data_rec(1).remarks := '';
2905              p_data_rec(1).auth_action_code := '';
2906 
2907            END IF;
2908 
2909 
2910         END LOOP;
2911 
2912      END IF;
2913       */
2914 
2915        FOR c_data_rec IN c_data LOOP
2916 	 l_counter := l_counter +1;
2917          p_data_rec(l_counter).batch_id := p_person_rec.batch_id;
2918          p_data_rec(l_counter).person_id := p_person_rec.person_id;
2919          --p_data_rec.print_form := p_person_rec.print_form; prbhardw
2920          p_data_rec(l_counter).creation_date := sysdate;
2921          p_data_rec(l_counter).created_by := g_update_by;
2922          p_data_rec(l_counter).last_updated_by := g_update_by;
2923          p_data_rec(l_counter).last_update_date  := sysdate;
2924          p_data_rec(l_counter).last_update_login := g_update_login;
2925 
2926          p_data_rec(l_counter).prgm_action_type        := c_data_rec.action_type;
2927          p_data_rec(l_counter).print_form              := c_data_rec.print_flag; -- prbhardw
2928          p_data_rec(l_counter).form_status_id          := c_data_rec.nonimg_stat_id;
2929          p_data_rec(l_counter).prgm_start_date         := c_data_rec.prgm_start_date;
2930          p_data_rec(l_counter).prgm_end_date           := c_data_rec.prgm_end_date;
2931          p_data_rec(l_counter).effective_date          := c_data_rec.action_date  ;
2932          p_data_rec(l_counter).termination_reason      := c_data_rec.termination_reason  ;
2933          p_data_rec(l_counter).remarks                 := c_data_rec.remarks  ;
2934 	 IF c_data_rec.cancel_flag = 'Y' THEN    -- prbhardw
2935 	       p_data_rec(l_counter).prgm_action_type   := 'CE';
2936 	 END IF;
2937 
2938 
2939 	/* Debug */
2940 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
2941 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Prgm_Info';
2942 	  l_debug_str := 'Exiting from for loop in Validate_Prgm_Info.';
2943 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
2944 	END IF;
2945 
2946       --   EXIT;  -- one  record is enough
2947 	-- Validate all the data
2948 	     -- Nonimg action types:
2949 	     -- C  Complete Program
2950 	     -- T  Terminate Program
2951 	     -- D  Defer program
2952 	     -- E  Extend program
2953 
2954 	     OPEN c_visa_type;
2955 	     FETCH c_visa_type INTO l_visa_type;
2956 	     CLOSE c_visa_type;
2957 
2958 	     IF p_data_rec(l_counter).prgm_action_type  = 'C' THEN
2959 	       -- No validation at this time
2960 
2961 	       NULL;
2962 
2963 	     ELSIF p_data_rec(l_counter).prgm_action_type  = 'D' AND
2964 		   (  p_data_rec(l_counter).prgm_start_date IS NULL
2965 		      OR p_data_rec(l_counter).prgm_end_date IS NULL)  THEN
2966 
2967 		FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_CMP_PRG_RQD_FLD_ERR'); --  Completion block error
2968 		FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
2969 
2970 		Put_Log_Msg(FND_MESSAGE.Get,1);
2971 		l_not_valid := TRUE;
2972 
2973 	     ELSIF p_data_rec(l_counter).prgm_action_type  = 'T'  AND  p_data_rec(l_counter).termination_reason IS NULL  THEN
2974 
2975 		FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_TRM_PRG_RQD_FLD_ERR'); -- Termination block error
2976 		FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
2977 
2978 		Put_Log_Msg(FND_MESSAGE.Get,1);
2979 		l_not_valid := TRUE;
2980 	     ELSIF p_data_rec(l_counter).prgm_action_type  = 'T'  AND l_visa_type= 'M-1' THEN
2981 	       OPEN c_termination_reason('M', p_data_rec(l_counter).termination_reason);
2982 	       FETCH c_termination_reason INTO l_termination_count;
2983 	       CLOSE c_termination_reason;
2984 	       IF l_termination_count > 0 THEN
2985 		 FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_INV_TERM_REASON');
2986 		 FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
2987 		 Put_Log_Msg(FND_MESSAGE.Get,1);
2988 		 l_not_valid := TRUE;
2989 	       END IF;
2990 	     ELSIF p_data_rec(l_counter).prgm_action_type  = 'T'  AND l_visa_type= 'F-1' THEN
2991 		OPEN c_termination_reason('F', p_data_rec(l_counter).termination_reason);
2992 	       FETCH c_termination_reason INTO l_termination_count;
2993 	       CLOSE c_termination_reason;
2994 	       IF l_termination_count > 0 THEN
2995 		 FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_INV_TERM_REASON');
2996 		 FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
2997 		 Put_Log_Msg(FND_MESSAGE.Get,1);
2998 		 l_not_valid := TRUE;
2999 	       END IF;
3000 
3001 	     ELSIF p_data_rec(l_counter).prgm_action_type  = 'E'  AND
3002 		   (  p_data_rec(l_counter).remarks IS NULL
3003 		      OR p_data_rec(l_counter).prgm_end_date IS NULL)  THEN
3004 
3005 		FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_EXT_PRG_RQD_FLD_ERR'); -- Extention block error
3006 		FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
3007 
3008 		Put_Log_Msg(FND_MESSAGE.Get,1);
3009 		l_not_valid := TRUE;
3010 
3011 	     END IF;
3012 
3013 	     --prbhardw
3014 	     IF p_data_rec(l_counter).prgm_action_type  = 'E'  THEN
3015 		  OPEN c_prev_end_date;
3016 		  FETCH c_prev_end_date INTO lv_prgm_end_dt;
3017 		  CLOSE c_prev_end_date;
3018 		  IF to_date(p_data_rec(l_counter).prgm_end_date,'YYYY-MM-DD') > ADD_MONTHS(lv_prgm_end_dt,12)  THEN
3019 			FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_INV_EXT_PRG_DRN'); -- Extention block error
3020 			Put_Log_Msg(FND_MESSAGE.Get,1);
3021 			l_not_valid := TRUE;
3022 		  END IF;
3023 
3024 	     END IF;
3025 	     IF l_not_valid THEN
3026 	        Put_Log_Msg(l_api_name||' Validation error, return E ',0);
3027 	      /* Debug */
3028 		IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3029 		  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Prgm_Info';
3030 		  l_debug_str := 'Returning E from Validate_Prgm_Info.';
3031 		  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3032 		END IF;
3033 
3034 	        RETURN 'E';
3035 
3036 	     END IF;
3037        END LOOP;
3038 
3039 
3040 
3041    ELSE  -- BATCH TYPE IS 'E'
3042 
3043      FOR c_data_rec IN c_ev_data LOOP
3044        l_counter := l_counter +1;
3045        p_data_rec(l_counter).batch_id := p_person_rec.batch_id;
3046        p_data_rec(l_counter).person_id := p_person_rec.person_id;
3047        p_data_rec(l_counter).print_form := p_person_rec.print_form;
3048        p_data_rec(l_counter).creation_date := sysdate;
3049        p_data_rec(l_counter).created_by := g_update_by;
3050        p_data_rec(l_counter).last_updated_by := g_update_by;
3051        p_data_rec(l_counter).last_update_date  := sysdate;
3052        p_data_rec(l_counter).last_update_login := g_update_login;
3053 
3054        p_data_rec(l_counter).prgm_action_type        := c_data_rec.action_type;
3055        p_data_rec(l_counter).form_status_id          := c_data_rec.ev_form_stat_id;
3056        p_data_rec(l_counter).prgm_start_date         := c_data_rec.prgm_start_date  ;
3057        p_data_rec(l_counter).prgm_end_date           := c_data_rec.prgm_end_date  ;
3058        p_data_rec(l_counter).effective_date          := c_data_rec.action_date  ;
3059        p_data_rec(l_counter).termination_reason      := c_data_rec.termination_reason  ;
3060        p_data_rec(l_counter).end_prgm_reason         := c_data_rec.end_program_reason  ;
3061        p_data_rec(l_counter).remarks                 := c_data_rec.remarks  ;
3062 	/* Debug */
3063 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3064 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Prgm_Info';
3065 	  l_debug_str := 'Exiting from for loop in Validate_Prgm_Info.';
3066 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3067 	END IF;
3068 
3069    --    EXIT;  -- one  record is enough
3070 	 -- Validate EV date
3071      -- AP Amend Program
3072      -- EE Exchange Visitor Extension
3073      -- EF Extend Failure
3074      -- CF Conclude Failure
3075      -- AF Approve Failure
3076      -- OI Other Infraction
3077      -- TR Terminate Exchange Visitor
3078      -- ED End Program
3079 
3080      -- EM Exchange Visitor Matriculation ???
3081      -- US Update Subject Field
3082      -- RF Reprint Form
3083        OPEN c_ev_category_data;
3084        FETCH c_ev_category_data INTO
3085        l_category_code,
3086        l_prgm_start_dt,
3087        l_prgm_end_dt;
3088        CLOSE c_ev_category_data;
3089 
3090        IF l_category_code = '2A' AND l_prgm_end_dt > ADD_MONTHS(l_prgm_start_dt,24)  THEN
3091 	       FND_MESSAGE.SET_NAME('IGS','IGS_SV_INV_PROG_DURN');
3092 	       FND_MESSAGE.SET_TOKEN('PROGDURATION','not exceed 24 months');
3093 	       Put_Log_Msg(FND_MESSAGE.Get,1);
3094 	       l_not_valid := TRUE;
3095        END IF;
3096 
3097        IF p_data_rec(l_counter).prgm_action_type = 'EM' AND p_data_rec(l_counter).prgm_end_date < trunc(SYSDATE) THEN
3098           FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_INV_PRGM_END_DT');
3099           FND_MESSAGE.SET_TOKEN('PERSON_NUM', p_person_rec.person_number );
3100           Put_Log_Msg(FND_MESSAGE.Get,1);
3101           l_not_valid := TRUE;
3102        END IF;
3103 
3104        IF p_data_rec(l_counter).prgm_action_type  = 'AP' AND -- AP Amend Program
3105            (  p_data_rec(l_counter).prgm_start_date IS NULL
3106               OR p_data_rec(l_counter).prgm_end_date IS NULL)  THEN
3107 
3108           FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_EV_PRG_RQD_FLD_ERR');
3109           FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
3110 
3111           Put_Log_Msg(FND_MESSAGE.Get,1);
3112           l_not_valid := TRUE;
3113 
3114         ELSIF p_data_rec(l_counter).prgm_action_type  IN ('EE','EF')  AND -- EE Exchange Visitor Extension,  EF Extend Failure
3115            (  p_data_rec(l_counter).prgm_end_date IS NULL)  THEN
3116 
3117           FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_EV_PRG_RQD_FLD_ERR');
3118           FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
3119 
3120           Put_Log_Msg(FND_MESSAGE.Get,1);
3121           l_not_valid := TRUE;
3122 
3123        ELSIF p_data_rec(l_counter).prgm_action_type  IN ('SP')  AND
3124              p_data_rec(l_counter).remarks IS NULL THEN
3125        -- AF Approve Failure
3126        -- OI Other Infraction
3127 
3128           FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_EV_PRG_RQD_FLD_ERR'); --  Amend program block error
3129           FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
3130 
3131           Put_Log_Msg(FND_MESSAGE.Get,1);
3132           l_not_valid := TRUE;
3133 
3134 
3135         ELSIF p_data_rec(l_counter).prgm_action_type  = 'TR'  AND       -- TR Terminate Exchange Visitor
3136              ( p_data_rec(l_counter).termination_reason IS NULL
3137                OR p_data_rec(l_counter).effective_date IS NULL ) THEN
3138 
3139           FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_TRM_PRG_RQD_FLD_ERR'); -- Termination block error
3140           FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
3141 
3142           Put_Log_Msg(FND_MESSAGE.Get,1);
3143           l_not_valid := TRUE;
3144 
3145         ELSIF p_data_rec(l_counter).prgm_action_type  = 'ED'  AND       -- ED End Program
3146              ( p_data_rec(l_counter).end_prgm_reason IS NULL
3147                OR p_data_rec(l_counter).effective_date IS NULL ) THEN
3148 
3149           FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_TRM_PRG_RQD_FLD_ERR'); -- Termination block error
3150           FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
3151 
3152           Put_Log_Msg(FND_MESSAGE.Get,1);
3153           l_not_valid := TRUE;
3154 
3155 
3156         END IF;
3157 
3158 	IF p_data_rec(l_counter).prgm_action_type  = 'TR'  AND p_data_rec(l_counter).termination_reason = 'OTHER'
3159 	    AND p_data_rec(l_counter).remarks IS NULL  THEN
3160 		FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_TRM_REM_RQD');
3161 		FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
3162 		Put_Log_Msg(FND_MESSAGE.Get,1);
3163 		l_not_valid := TRUE;
3164 	END IF;
3165 
3166 	IF l_not_valid THEN
3167 	      Put_Log_Msg(l_api_name||' Validation error, return E ',0);
3168 	      /* Debug */
3169 		IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3170 		  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Prgm_Info';
3171 		  l_debug_str := 'Returning E from Validate_Prgm_Info.';
3172 		  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3173 		END IF;
3174 
3175 	      RETURN 'E';
3176 
3177 	END IF;
3178 
3179      END LOOP;
3180 
3181    END IF;
3182    p_records := l_counter;
3183    IF l_counter = 0 THEN
3184       Put_Log_Msg(l_api_name||' Successfully completed, no rows found returns N ',0);
3185       /* Debug */
3186 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3187 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Prgm_Info';
3188 	  l_debug_str := 'Returning N from validate_empl_Info.';
3189 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3190 	END IF;
3191       RETURN 'N';
3192    END IF;
3193 
3194 
3195    Put_Log_Msg(l_api_name||' Successfully completed, returns S',0);
3196    /* Debug */
3197 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3198 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Prgm_Info';
3199 	  l_debug_str := 'Returning S from Validate_Prgm_Info.';
3200 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3201 	END IF;
3202 
3203    RETURN 'S'; -- Successfull validation
3204 
3205 EXCEPTION
3206 
3207    WHEN OTHERS THEN
3208    /* Debug */
3209 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3210 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Prgm_Info';
3211 	  l_debug_str := 'Exception in Validate_Prgm_Info.'||SQLERRM;
3212 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3213 	END IF;
3214 
3215       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
3216          FND_MSg_PUB.Add_Exc_Msg (G_PKG_NAME, l_api_name);
3217       END IF;
3218 
3219       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
3220 
3221       RETURN 'U';
3222 
3223 END Validate_Prgm_Info;
3224 
3225 /******************************************************************
3226    Created By         : Arkadi Tereshenkov
3227 
3228    Date Created By    : Oct 14, 2002
3229 
3230    Purpose            : Validate information pertaining to the Finance
3231                         information of the student.
3232                         (IGS_SV_FINANCE_INFO).
3233 
3234    Remarks            : Return result:
3235                            'S' - record found and validated
3236                            'E' - validation error
3237                            'U' - Unexpected error
3238                            'N' - data not found
3239 
3240    Change History
3241    Who                  When            What
3242 ------------------------------------------------------------------------
3243 
3244 ******************************************************************/
3245 FUNCTION Validate_Finance_Info (
3246    p_person_rec IN t_student_rec,
3247    p_data_rec  IN OUT NOCOPY  IGS_SV_FINANCE_INFO%ROWTYPE    -- Data record
3248 ) RETURN VARCHAR2
3249 IS
3250 
3251    l_api_name CONSTANT VARCHAR(30) := 'Validate_Finance_Info';
3252 
3253    CURSOR c_nimg_data IS
3254      SELECT acad_term_length,
3255             tuition_amt,
3256             living_exp_amt,
3257             depdnt_exp_amt  dependent_exp_amt,
3258             other_exp_amt,
3259             other_exp_desc,
3260             personal_funds_amt,
3261             school_funds_amt,
3262             school_funds_desc,
3263             other_funds_amt,
3264             other_funds_desc,
3265             empl_funds_amt,
3266             remarks
3267        FROM igs_pe_nonimg_form     penf
3268       WHERE penf.person_id      = p_person_rec.person_id
3269         AND penf.nonimg_form_id = p_person_rec.form_id;
3270 
3271    CURSOR c_ev_data IS
3272      SELECT prgm_sponsor_amt program_sponsor,
3273             govt_org1_amt,
3274             govt_org2_amt,
3275             govt_org1_code,
3276             govt_org2_code,
3277             intl_org1_amt,
3278             intl_org2_amt,
3279             intl_org1_code,
3280             intl_org2_code,
3281             ev_govt_amt,
3282             bi_natnl_com_amt,
3283             other_govt_amt,
3284             personal_funds_amt,
3285             remarks,
3286             NVL(NVL(govt_org2_amt,govt_org1_amt),'0') recvd_us_gvt_funds_ind,
3287 	    govt_org1_othr_name    ,
3288 	    govt_org2_othr_name    ,
3289             intl_org1_othr_name    ,
3290             intl_org2_othr_name    ,
3291 	    other_govt_name
3292        FROM igs_pe_ev_form     evf
3293       WHERE evf.person_id  = p_person_rec.person_id
3294         AND evf.ev_form_id = p_person_rec.form_id;
3295 
3296    l_not_valid               BOOLEAN := FALSE;
3297    l_acad_term_length        igs_pe_nonimg_form.acad_term_length%TYPE;
3298    l_tuition                 igs_pe_nonimg_form.tuition_amt%TYPE;
3299    l_living_exp              igs_pe_nonimg_form.living_exp_amt%TYPE;
3300    l_dependent_exp           igs_pe_nonimg_form.depdnt_exp_amt%TYPE;
3301    l_other_exp               igs_pe_nonimg_form.other_exp_amt%TYPE;
3302    l_other_exp_desc          igs_pe_nonimg_form.other_exp_desc%TYPE;
3303    l_personal_funds          igs_pe_nonimg_form.personal_funds_amt%TYPE;
3304    l_school_funds            igs_pe_nonimg_form.school_funds_amt%TYPE;
3305    l_school_funds_desc       igs_pe_nonimg_form.school_funds_desc%TYPE;
3306    l_other_funds             igs_pe_nonimg_form.other_funds_amt%TYPE;
3307    l_other_funds_desc        igs_pe_nonimg_form.other_funds_desc%TYPE;
3308    l_empl_funds              igs_pe_nonimg_form.empl_funds_amt%TYPE;
3309    l_remarks                 igs_pe_nonimg_form.remarks%TYPE;
3310    l_program_sponsor         igs_pe_ev_form.prgm_sponsor_amt%TYPE;
3311    l_govt_org1               igs_pe_ev_form.govt_org1_amt%TYPE;
3312    l_govt_org2               igs_pe_ev_form.govt_org2_amt%TYPE;
3313    l_govt_org1_code          igs_pe_ev_form.govt_org1_code%TYPE;
3314    l_govt_org2_code          igs_pe_ev_form.govt_org2_code%TYPE;
3315    l_intl_org1               igs_pe_ev_form.intl_org1_amt%TYPE;
3316    l_intl_org2               igs_pe_ev_form.intl_org2_amt%TYPE;
3317    l_intl_org1_code          igs_pe_ev_form.intl_org1_code%TYPE;
3318    l_intl_org2_code          igs_pe_ev_form.intl_org2_code%TYPE;
3319    l_ev_govt                 igs_pe_ev_form.ev_govt_amt%TYPE;
3320    l_bi_natnl_com            igs_pe_ev_form.bi_natnl_com_amt%TYPE;
3321    l_other_org               igs_pe_ev_form.other_govt_amt%TYPE;
3322    l_recvd_us_gvt_fund_amt   VARCHAR2(30);
3323    l_govt_org1_othr_name     igs_pe_ev_form.govt_org1_othr_name%TYPE;
3324    l_govt_org2_othr_name     igs_pe_ev_form.govt_org2_othr_name%TYPE;
3325    l_intl_org1_othr_name     igs_pe_ev_form.intl_org1_othr_name%TYPE;
3326    l_intl_org2_othr_name     igs_pe_ev_form.intl_org2_othr_name%TYPE;
3327    l_other_govt_name	     igs_pe_ev_form.other_govt_name%TYPE;
3328 
3329 
3330 BEGIN
3331 
3332    Put_Log_Msg(l_api_name||' starts ',0);
3333    /* Debug */
3334 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3335 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Finance_Info';
3336 	  l_debug_str := 'Entering Validate_Finance_Info. p_person_rec.batch_id is '||p_person_rec.batch_id ||' and person_id is '||p_person_rec.person_id;
3337 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3338 	END IF;
3339 
3340    p_data_rec.batch_id := NULL;  -- This will tell us if there's been any records found
3341 
3342 --
3343 -- Process the Foreign Student information
3344 --
3345    IF (p_person_rec.batch_type = 'I') THEN
3346 
3347       OPEN c_nimg_data;
3348       FETCH c_nimg_data
3349        INTO l_acad_term_length,
3350             l_tuition,
3351             l_living_exp,
3352             l_dependent_exp,
3353             l_other_exp,
3354             l_other_exp_desc,
3355             l_personal_funds,
3356             l_school_funds,
3357             l_school_funds_desc,
3358             l_other_funds,
3359             l_other_funds_desc,
3360             l_empl_funds,
3361             l_remarks;
3362 
3363       IF (c_nimg_data%FOUND) THEN
3364 
3365          p_data_rec.batch_id          := p_person_rec.batch_id;
3366          p_data_rec.person_id         := p_person_rec.person_id;
3367          p_data_rec.print_form        := p_person_rec.print_form;
3368          p_data_rec.creation_date     := sysdate;
3369          p_data_rec.created_by        := g_update_by;
3370          p_data_rec.last_updated_by   := g_update_by;
3371          p_data_rec.last_update_date  := sysdate;
3372          p_data_rec.last_update_login := g_update_login;
3373          p_data_rec.acad_term_length  := ltrim(to_char(to_number(l_acad_term_length),'00'));
3374          p_data_rec.tuition           := l_tuition;
3375          p_data_rec.living_exp        := l_living_exp;
3376          p_data_rec.dependent_exp     := l_dependent_exp;
3377          p_data_rec.other_exp         := l_other_exp;
3378          p_data_rec.other_exp_desc    := l_other_exp_desc;
3379          p_data_rec.personal_funds    := l_personal_funds;
3380          p_data_rec.school_funds      := l_school_funds;
3381          p_data_rec.school_funds_desc := l_school_funds_desc;
3382          p_data_rec.other_funds       := l_other_funds;
3383          p_data_rec.other_funds_desc  := l_other_funds_desc;
3384          p_data_rec.empl_funds        := l_empl_funds;
3385          p_data_rec.remarks           := l_remarks;
3386 
3387       END IF;
3388 
3389       CLOSE c_nimg_data;
3390 
3391    ELSE
3392 
3393 --
3394 -- Process the Exchange Visitor Data
3395 --
3396       OPEN c_ev_data;
3397       FETCH c_ev_data
3398        INTO l_program_sponsor,
3399             l_govt_org1,
3400             l_govt_org2,
3401             l_govt_org1_code,
3402             l_govt_org2_code,
3403             l_intl_org1,
3404             l_intl_org2,
3405             l_intl_org1_code,
3406             l_intl_org2_code,
3407             l_ev_govt,
3408             l_bi_natnl_com,
3409             l_other_org,
3410             l_personal_funds,
3411             l_remarks,
3412             l_recvd_us_gvt_fund_amt,
3413 	    l_govt_org1_othr_name,
3414 	    l_govt_org2_othr_name,
3415 	    l_intl_org1_othr_name,
3416 	    l_intl_org2_othr_name,
3417 	    l_other_govt_name;
3418 
3419       IF (c_ev_data%FOUND) THEN
3420 
3421          IF l_recvd_us_gvt_fund_amt <> '0' THEN
3422            l_recvd_us_gvt_fund_amt := '1';
3423          END IF;
3424 
3425          p_data_rec.batch_id          := p_person_rec.batch_id;
3426          p_data_rec.person_id         := p_person_rec.person_id;
3427          p_data_rec.print_form        := p_person_rec.print_form;
3428          p_data_rec.creation_date     := sysdate;
3429          p_data_rec.created_by        := g_update_by;
3430          p_data_rec.last_updated_by   := g_update_by;
3431          p_data_rec.last_update_login := g_update_login;
3432          p_data_rec.last_update_date  := sysdate;
3433          p_data_rec.program_sponsor   := l_program_sponsor;
3434          p_data_rec.govt_org1         := l_govt_org1;
3435          p_data_rec.govt_org2         := l_govt_org2;
3436          p_data_rec.govt_org1_code    := l_govt_org1_code;
3437          p_data_rec.govt_org2_code    := l_govt_org2_code;
3438          p_data_rec.intl_org1         := l_intl_org1;
3439          p_data_rec.intl_org2         := l_intl_org2;
3440          p_data_rec.intl_org1_code    := l_intl_org1_code;
3441          p_data_rec.intl_org2_code    := l_intl_org2_code;
3442          p_data_rec.ev_govt           := l_ev_govt;
3443          p_data_rec.bi_natnl_com      := l_bi_natnl_com;
3444          p_data_rec.other_org         := l_other_org;
3445          p_data_rec.personal_funds    := l_personal_funds;
3446          p_data_rec.remarks           := l_remarks;
3447          p_data_rec.recvd_us_gvt_funds:= l_recvd_us_gvt_fund_amt;
3448 	 p_data_rec.govt_org1_othr_name	:= l_govt_org1_othr_name;
3449 	 p_data_rec.govt_org2_othr_name	:= l_govt_org2_othr_name;
3450 	 p_data_rec.intl_org1_othr_name	:= l_intl_org1_othr_name;
3451 	 p_data_rec.intl_org2_othr_name	:= l_intl_org2_othr_name;
3452 	 p_data_rec.other_govt_name	:= l_other_govt_name	;
3453 
3454       END IF;
3455 
3456       CLOSE c_ev_data;
3457 
3458    END IF;
3459 
3460    IF p_data_rec.batch_id IS NULL THEN
3461 
3462       Put_Log_Msg(l_api_name||' Successfully completed, no rows found returns N ',0);
3463       /* Debug */
3464 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3465 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Finance_Info';
3466 	  l_debug_str := 'Returning N from Validate_Finance_Info.';
3467 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3468 	END IF;
3469 
3470       RETURN 'N';
3471 
3472    ELSE
3473 
3474      -- Validate all the data required for either type of request.
3475      IF (p_data_rec.print_form IS NULL AND p_person_rec.batch_type = 'E') THEN
3476         l_not_valid := TRUE;
3477         FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_FIN_REQ_FLD_ERR'); -- Required Fields for Exchange Visitor students
3478         FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
3479         Put_Log_Msg(FND_MESSAGE.Get,1);
3480      END IF;
3481 
3482 --
3483 -- Validate data specific for Foreign Students
3484 --
3485      IF (p_person_rec.batch_type = 'I') THEN
3486 
3487         IF (p_data_rec.acad_term_length IS NULL     OR
3488             p_data_rec.tuition          IS NULL     OR
3489             p_data_rec.living_exp       IS NULL     OR
3490             p_data_rec.personal_funds   IS NULL) THEN
3491            l_not_valid := TRUE;
3492            FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_FIN_REQ_NIMG_ERR'); -- Required Fields for Exchange Visitor students
3493            FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
3494            Put_Log_Msg(FND_MESSAGE.Get,1);
3495         END IF;
3496 
3497         IF ((p_data_rec.other_exp         IS NOT NULL   AND
3498              p_data_rec.other_exp_desc    IS NULL)      OR
3499             (p_data_rec.school_funds      IS NOT NULL   AND
3500              p_data_rec.school_funds_desc IS NULL)      OR
3501             (p_data_rec.other_funds       IS NOT NULL   AND
3502              p_data_rec.other_funds_desc  IS NULL)) THEN
3503            l_not_valid := TRUE;
3504            FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_FIN_REQ_NIMG_DESC_ERR'); -- Required Fields for Exchange Visitor students
3505            FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
3506            Put_Log_Msg(FND_MESSAGE.Get,1);
3507         END IF;
3508 
3509      ELSE
3510 
3511 --
3512 -- Validate data specific for Exchange Visitor Students
3513 --
3514         IF ((p_data_rec.govt_org1         IS NOT NULL   AND
3515              p_data_rec.govt_org1_code    IS NULL)      OR
3516             (p_data_rec.govt_org2         IS NOT NULL   AND
3517              p_data_rec.govt_org2_code    IS NULL)      OR
3518             (p_data_rec.intl_org1         IS NOT NULL   AND
3519              p_data_rec.intl_org1_code    IS NULL)      OR
3520             (p_data_rec.intl_org2         IS NOT NULL   AND
3521              p_data_rec.intl_org2_code    IS NULL))     THEN
3522            l_not_valid := TRUE;
3523            FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_FIN_REQ_EV_ERR'); -- Required Fields for Exchange Visitor students
3524            FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
3525            Put_Log_Msg(FND_MESSAGE.Get,1);
3526         END IF;
3527 
3528 
3529 	IF ((p_data_rec.govt_org1_code     = 'OTHER' AND
3530              p_data_rec.govt_org1_othr_name  IS NULL)      OR
3531             (p_data_rec.govt_org2_code     = 'OTHER' AND
3532              p_data_rec.govt_org2_othr_name  IS NULL)      OR
3533             (p_data_rec.intl_org1_code     = 'OTHER' AND
3534              p_data_rec.intl_org1_othr_name  IS NULL)      OR
3535             (p_data_rec.intl_org2_code     = 'OTHER' AND
3536              p_data_rec.intl_org2_othr_name IS NULL)      OR
3537 	     p_data_rec.other_govt_name IS NULL AND
3538 	     p_data_rec.other_org IS NOT NULL)     THEN
3539            l_not_valid := TRUE;
3540            FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_OTHR_ORG');
3541            FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
3542            Put_Log_Msg(FND_MESSAGE.Get,1);
3543         END IF;
3544 
3545      END IF;
3546 
3547      IF (l_not_valid) THEN
3548 
3549         Put_Log_Msg(l_api_name||' Validation error, return E ',0);
3550 	/* Debug */
3551 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3552 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Finance_Info';
3553 	  l_debug_str := 'Returning E from Validate_Finance_Info.';
3554 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3555 	END IF;
3556 
3557 
3558         RETURN 'E';
3559 
3560      END IF;
3561 
3562    END IF;
3563 
3564    Put_Log_Msg(l_api_name||' Successfully completed, returns S',0);
3565    /* Debug */
3566 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3567 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Finance_Info';
3568 	  l_debug_str := 'Returning S from Validate_Finance_Info.';
3569 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3570 	END IF;
3571 
3572 
3573    RETURN 'S'; -- Successfull validation
3574 
3575 EXCEPTION
3576 
3577    WHEN OTHERS THEN
3578    /* Debug */
3579 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3580 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Finance_Info';
3581 	  l_debug_str := 'Exception in Validate_Finance_Info. '||SQLERRM;
3582 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3583 	END IF;
3584 
3585 
3586       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
3587          FND_MSg_PUB.Add_Exc_Msg (G_PKG_NAME, l_api_name);
3588       END IF;
3589 
3590       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
3591 
3592       RETURN 'U';
3593 
3594 END Validate_Finance_Info;
3595 
3596 
3597 
3598 /******************************************************************
3599    Created By         : Arkadi Tereshenkov
3600 
3601    Date Created By    : Oct 14, 2002
3602 
3603    Purpose            : Validate information pertaining to the
3604                         dependent information of the student.
3605                         (IGS_SV_DEPDNT_INFO)
3606 
3607    Remarks            : Return result:
3608                            'S' - record found and validated
3609                            'E' - validation error
3610                            'U' - Unexpected error
3611                            'N' - data not found
3612 
3613    Change History
3614    Who                  When            What
3615    vskumar		26-May-06	xbuild3 performance fix. replace sql query used igs_person_base_v view rather igs_pe_person.
3616 ------------------------------------------------------------------------
3617 
3618 ******************************************************************/
3619 FUNCTION Validate_Dependent_Info (
3620    p_person_rec IN      t_student_rec,
3621    p_data_rec   IN OUT NOCOPY  g_dependent_rec_type,    -- Data record
3622    p_records    OUT NOCOPY     NUMBER                   -- Number of dependents found
3623 ) RETURN VARCHAR2
3624 IS
3625 
3626 
3627    l_api_name CONSTANT VARCHAR(30) := 'Validate_Dependent_Info';
3628 
3629    l_dep_person_rec   t_student_rec;
3630    l_dep_data_rec     IGS_SV_BIO_INFO%ROWTYPE ;
3631    l_counter          NUMBER(10) := 0;
3632    l_rel_count	      NUMBER(10) := 0;
3633    l_dep_sevis_id VARCHAR2(30);	--PRBHARDW
3634    -- Dependent codes
3635    -- 01 Spouse
3636    -- 02 Child
3637 
3638    -- Select all dependents
3639    CURSOR c_data IS
3640      SELECT dep.relationship_id,
3641             rel.object_id depdnt_id,
3642             action_code,
3643             to_char(effective_date,'YYYY-MM-DD') effective_date ,
3644             reason_code,
3645             dep.REMARKS comments,
3646             rel.COMMENTS rel_remarks,
3647             decode (RELATIONSHIP_CODE,'PARENT_OF','02','SPOUSE_OF','01','XX' ) relationship
3648        FROM igs_pe_depd_active dep,
3649             HZ_RELATIONSHIPS rel
3650       WHERE subject_id = p_person_rec.person_id
3651             AND rel.relationship_id =  dep.relationship_id
3652             AND (p_person_rec.record_status = 'C' OR dep.action_code ='A')  --In the new mode report only about active dependents
3653             AND RELATIONSHIP_CODE IN ('PARENT_OF','SPOUSE_OF' )
3654             AND (dep.relationship_id, effective_date) IN
3655             ( SELECT dep1.relationship_id,
3656                      MAX(dep1.effective_date)
3657                 FROM igs_pe_depd_active dep1
3658 		WHERE dep1.relationship_id = rel.relationship_id
3659 		GROUP BY  dep1.relationship_id)
3660             AND rel.status = 'A';
3661 
3662    CURSOR c_person_number(p_id NUMBER) IS
3663     SELECT person_number
3664     FROM igs_pe_person_base_v
3665     WHERE person_id = p_id;
3666 
3667 CURSOR c_get_sevis_user_id(c_dep_id NUMBER)
3668      IS
3669           SELECT alt.api_person_id
3670 	  FROM  igs_pe_alt_pers_id alt
3671 	  WHERE
3672 	       alt.pe_person_id = c_dep_id AND
3673 	       alt.person_id_type IN (SELECT person_id_type FROM igs_pe_person_id_typ
3674 				    WHERE s_person_id_type = 'SEVIS_ID') AND
3675                sysdate between alt.start_dt and nvl(alt.end_dt, sysdate+1);
3676 BEGIN
3677 
3678    Put_Log_Msg(l_api_name||' starts ',0);
3679    /* Debug */
3680 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3681 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Dependent_Info';
3682 	  l_debug_str := 'Entering Validate_Dependent_Info. p_person_rec.batch_id is '||p_person_rec.batch_id ||' and person_id is '||p_person_rec.person_id;
3683 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3684 	END IF;
3685 
3686 
3687 
3688    FOR c_data_rec IN c_data LOOP
3689 
3690        l_counter := l_counter +1;
3691        IF l_counter > 25 AND p_person_rec.batch_id = g_running_create_batch THEN
3692           IF g_parallel_batches.count > 0 THEN
3693 	       p_data_rec(l_counter).batch_id := g_parallel_batches(1);
3694 	  ELSE
3695 	      p_data_rec(l_counter).batch_id := igs_sv_util.open_new_batch(p_person_rec.person_id, p_person_rec.batch_id,'CONN_JOB');
3696 	      g_parallel_batches(1) := p_data_rec(l_counter).batch_id;
3697 	  END IF;
3698        ELSE
3699           p_data_rec(l_counter).batch_id := p_person_rec.batch_id;
3700        END IF;
3701        OPEN c_get_sevis_user_id(c_data_rec.depdnt_id);
3702        FETCH c_get_sevis_user_id  INTO l_dep_sevis_id;
3703        CLOSE c_get_sevis_user_id;
3704 
3705        p_data_rec(l_counter).person_id := p_person_rec.person_id;
3706        p_data_rec(l_counter).print_form := p_person_rec.print_form;
3707        p_data_rec(l_counter).creation_date := sysdate;
3708        p_data_rec(l_counter).created_by := g_update_by;
3709        p_data_rec(l_counter).last_updated_by := g_update_by;
3710        p_data_rec(l_counter).last_update_date  := sysdate;
3711        p_data_rec(l_counter).last_update_login := g_update_login;
3712        p_data_rec(l_counter).depdnt_id          := c_data_rec.depdnt_id;
3713        p_data_rec(l_counter).depdnt_action_type   := c_data_rec.action_code;
3714        p_data_rec(l_counter).depdnt_sevis_id    := l_dep_sevis_id; --get_person_sevis_id(c_data_rec.depdnt_id);  prbhardw
3715        p_data_rec(l_counter).termination_effect_date := c_data_rec.effective_date;
3716 
3717        p_data_rec(l_counter).relationship        := c_data_rec.relationship;
3718        p_data_rec(l_counter).relationship_remarks := c_data_rec.rel_remarks;
3719        p_data_rec(l_counter).termination_reason :=  c_data_rec.reason_code ;
3720 
3721        l_dep_person_rec.batch_id   := p_person_rec.batch_id;
3722        l_dep_person_rec.person_id  := c_data_rec.depdnt_id;
3723        l_dep_person_rec.print_form := p_person_rec.print_form;
3724        l_dep_person_rec.batch_type := p_person_rec.batch_type;
3725 
3726        OPEN c_person_number (c_data_rec.depdnt_id);
3727        FETCH c_person_number INTO l_dep_person_rec.person_number ;
3728        CLOSE c_person_number;
3729 
3730        l_dep_person_rec.dep_flag   := 'Y';
3731 
3732 
3733        -- Call Validate_Dep_Info
3734        l_dep_person_rec.dep_status  := Validate_Bio_Info (p_person_rec => l_dep_person_rec,
3735                                                           p_data_rec   => l_dep_data_rec);
3736        IF l_dep_person_rec.dep_status = 'E' THEN -- Validation error - mark person as invalid
3737 
3738           Put_Log_Msg('Validation error occurs ',0);
3739 		/* Debug */
3740 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3741 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Dependent_Info';
3742 	  l_debug_str := 'Returning E from Validate_Dependent_Info.';
3743 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3744 	END IF;
3745 
3746           RETURN 'E';
3747 
3748        ELSIF l_dep_person_rec.dep_status = 'N' THEN
3749 
3750          Put_Log_Msg('Dependent not found by Validate procedure ',0);
3751 	 	/* Debug */
3752 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3753 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Dependent_Info';
3754 	  l_debug_str := 'IGS_SV_UNEXP_EXCPT_ERR Error in Validate_Dependent_Info.';
3755 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3756 	END IF;
3757 
3758          -- probably a bug
3759          FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_UNEXP_EXCPT_ERR'); -- I-20 is missing! Unexpected error
3760          FND_MESSAGE.SET_TOKEN('BLOCK_ID',1);
3761          FND_MSG_PUB.Add;
3762         RAISE FND_API.G_EXC_ERROR;
3763 
3764        END IF;
3765 
3766        p_data_rec(l_counter).person_id   :=  p_person_rec.person_id;
3767 
3768        p_data_rec(l_counter).visa_type   := l_dep_data_rec.visa_type ;
3769        p_data_rec(l_counter).last_name   := l_dep_data_rec.last_name;
3770        p_data_rec(l_counter).first_name  := l_dep_data_rec.first_name;
3771        p_data_rec(l_counter).middle_name := l_dep_data_rec.middle_name;
3772        p_data_rec(l_counter).suffix      := l_dep_data_rec.suffix;
3773        p_data_rec(l_counter).birth_date  := l_dep_data_rec.birth_date ;
3774        p_data_rec(l_counter).person_number  := l_dep_person_rec.person_number ;
3775        p_data_rec(l_counter).gender      := l_dep_data_rec.gender ;
3776        p_data_rec(l_counter).birth_cntry_code := l_dep_data_rec.birth_cntry_code ;
3777        p_data_rec(l_counter).citizen_cntry_code := l_dep_data_rec.citizen_cntry_code ;
3778 
3779        p_data_rec(l_counter).birth_city        := l_dep_data_rec.birth_city ;
3780        p_data_rec(l_counter).legal_res_cntry_code := l_dep_data_rec.legal_res_cntry_code ;
3781        p_data_rec(l_counter).remarks           := l_dep_data_rec.remarks ;
3782        p_data_rec(l_counter).birth_cntry_resn_code := l_dep_data_rec.birth_cntry_resn_code;
3783 
3784        IF p_person_rec.record_status = 'C' THEN
3785 
3786        	/* Debug */
3787 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3788 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Dependent_Info';
3789 	  l_debug_str := 'Exiting from for loop in Validate_Dependent_Info.';
3790 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3791 	END IF;
3792 
3793        --  EXIT; -- Just one dependent in the update mode per batch	prbhardw CP enhancement
3794 
3795        END IF;
3796 
3797 
3798    END LOOP;
3799 
3800    IF l_counter = 0 THEN
3801 
3802       Put_Log_Msg(l_api_name||' Successfully completed, no rows found returns N ',0);
3803       /* Debug */
3804 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3805 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Dependent_Info';
3806 	  l_debug_str := 'Returning N from Validate_Dependent_Info.';
3807 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3808 	END IF;
3809 
3810       RETURN 'N';
3811 
3812    END IF;
3813 
3814    p_records := l_counter;
3815 
3816    Put_Log_Msg(l_api_name||' Successfully completed, returns S',0);
3817    /* Debug */
3818 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3819 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Dependent_Info';
3820 	  l_debug_str := 'Returning S from Validate_Dependent_Info.';
3821 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3822 	END IF;
3823 
3824    RETURN 'S'; -- Successfull validation
3825 
3826 EXCEPTION
3827 
3828    WHEN OTHERS THEN
3829    /* Debug */
3830 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3831 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Dependent_Info';
3832 	  l_debug_str := 'Exception in Validate_Dependent_Info. '||SQLERRM;
3833 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3834 	END IF;
3835 
3836       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
3837          FND_MSg_PUB.Add_Exc_Msg (G_PKG_NAME, l_api_name);
3838       END IF;
3839 
3840       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
3841 
3842       RETURN 'U';
3843 
3844 
3845 END Validate_Dependent_Info;
3846 
3847 
3848 
3849 /******************************************************************
3850    Created By         : Arkadi Tereshenkov
3851 
3852    Date Created By    : Oct 14, 2002
3853 
3854    Purpose            : Validate information pertaining to the
3855                         convictions associated to student.
3856                         (IGS_SV_CONVICTIONS)
3857 
3858    Remarks            : Return result:
3859                            'S' - record found and validated
3860                            'E' - validation error
3861                            'U' - Unexpected error
3862                            'N' - data not found
3863 
3864    Change History
3865    Who                  When            What
3866 ------------------------------------------------------------------------
3867 
3868 ******************************************************************/
3869 FUNCTION Validate_Convictions_Info (
3870    p_person_rec IN      t_student_rec,
3871    p_data_rec   IN OUT NOCOPY  IGS_SV_CONVICTIONS%ROWTYPE    -- Data record
3872 ) RETURN VARCHAR2
3873 IS
3874 
3875    l_api_name CONSTANT VARCHAR(30) := 'Validate_Convictions_Info';
3876 
3877    -- Select only! unreported records since no data change is possbile.
3878 
3879    CURSOR c_data IS
3880      SELECT felony_details_id conviction_id,
3881             disp_action_info criminal_remarks
3882        FROM igs_pe_felony_dtls
3883       WHERE person_id = p_person_rec.person_id
3884             AND convict_ind ='Y'
3885             AND felony_details_id NOT IN
3886             ( SELECT conviction_id
3887                 FROM igs_sv_convictions  prg,
3888                      igs_sv_persons pr
3889                WHERE prg.person_id = pr.person_id
3890                      AND prg.batch_id = pr.batch_id
3891                      AND pr.record_status <> 'E'
3892                      AND prg.person_id = p_person_rec.person_id )
3893     ORDER BY crime_date;
3894 
3895   l_not_valid BOOLEAN := FALSE;
3896 BEGIN
3897 /* Debug */
3898 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3899 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Convictions_Info';
3900 	  l_debug_str := 'Entering Validate_Convictions_Info. p_person_rec.batch_id is '||p_person_rec.batch_id ||' and person_id is '||p_person_rec.person_id;
3901 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3902 	END IF;
3903 
3904    Put_Log_Msg(l_api_name||' starts ',0);
3905 
3906    p_data_rec.batch_id := NULL;  -- This will tell us if there's been any records found
3907 
3908    FOR c_data_rec IN c_data LOOP
3909 
3910        p_data_rec.batch_id := p_person_rec.batch_id;
3911        p_data_rec.person_id := p_person_rec.person_id;
3912        p_data_rec.print_form := p_person_rec.print_form;
3913        p_data_rec.creation_date := sysdate;
3914        p_data_rec.created_by := g_update_by;
3915        p_data_rec.last_updated_by := g_update_by;
3916        p_data_rec.last_update_date  := sysdate;
3917        p_data_rec.last_update_login := g_update_login;
3918 
3919        p_data_rec.conviction_id := c_data_rec.conviction_id;
3920        p_data_rec.remarks       :=SUBSTR(c_data_rec.criminal_remarks,1,500);
3921        p_data_rec.criminal_conviction :='Y' ;
3922 
3923        IF p_data_rec.remarks IS NULL  THEN
3924           l_not_valid := TRUE;
3925        END IF;
3926        EXIT;  -- one  record is enough
3927 
3928    END LOOP;
3929 
3930    IF p_data_rec.batch_id IS NULL THEN
3931 
3932       Put_Log_Msg(l_api_name||' Successfully completed, no rows found returns N ',0);
3933       /* Debug */
3934 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3935 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Convictions_Info';
3936 	  l_debug_str := 'Returning N from Validate_Convictions_Info';
3937 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3938 	END IF;
3939 
3940       RETURN 'N';
3941 
3942    ELSIF l_not_valid THEN
3943 
3944        FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_CONV_RQD_FLD_ERR'); -- Convictions block error
3945        FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
3946 
3947        Put_Log_Msg(FND_MESSAGE.Get,1);
3948 
3949        Put_Log_Msg(l_api_name||' Validation error, return E ',0);
3950        /* Debug */
3951 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3952 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Convictions_Info';
3953 	  l_debug_str := 'Returning E from Validate_Convictions_Info';
3954 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3955 	END IF;
3956 
3957        RETURN 'E';
3958 
3959    END IF;
3960 
3961    Put_Log_Msg(l_api_name||' Successfully completed, returns S',0);
3962    /* Debug */
3963 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3964 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Convictions_Info';
3965 	  l_debug_str := 'Returning S from Validate_Convictions_Info';
3966 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3967 	END IF;
3968 
3969    RETURN 'S'; -- Successfull validation
3970 
3971 EXCEPTION
3972 
3973    WHEN OTHERS THEN
3974    /* Debug */
3975 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
3976 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Convictions_Info';
3977 	  l_debug_str := 'Exception in Validate_Convictions_Info '||SQLERRM;
3978 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
3979 	END IF;
3980 
3981       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
3982          FND_MSg_PUB.Add_Exc_Msg (G_PKG_NAME, l_api_name);
3983       END IF;
3984 
3985       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
3986 
3987       RETURN 'U';
3988 
3989 END Validate_Convictions_Info;
3990 
3991 
3992 
3993 /******************************************************************
3994    Created By         : Arkadi Tereshenkov
3995 
3996    Date Created By    : Oct 14, 2002
3997 
3998    Purpose            : Validate information pertaining to the
3999                         Legal information block of student.
4000                         (IGS_SV_LEGAL_INFO)
4001 
4002    Remarks            : Return result:
4003                            'S' - record found and validated
4004                            'E' - validation error
4005                            'U' - Unexpected error
4006                            'N' - data not found
4007 
4008    Change History
4009    Who                  When            What
4010 ------------------------------------------------------------------------
4011 
4012 ******************************************************************/
4013 FUNCTION Validate_Legal_Info (
4014    p_person_rec IN      t_student_rec,
4015    p_data_rec   IN OUT NOCOPY  IGS_SV_LEGAL_INFO%ROWTYPE    -- Data record
4016 ) RETURN VARCHAR2
4017 IS
4018 
4019    l_api_name                 CONSTANT VARCHAR(30) := 'Validate_Legal_Info';
4020    l_visa_number              IGS_PE_VISA.visa_number%TYPE;
4021    l_visa_issuing_post        IGS_PE_VISA.visa_issuing_post%TYPE;
4022    l_visa_expiration_date     IGS_PE_VISA.visa_expiry_date%TYPE;
4023    l_visa_issuing_country     IGS_PE_VISA.visa_issuing_country%TYPE;
4024    l_I94_number               IGS_PE_VISIT_HISTRY.cntry_entry_form_num%TYPE;
4025    l_visa_issue_date	      IGS_PE_VISA.visa_issue_date%TYPE;
4026    l_port_of_entry            IGS_PE_VISIT_HISTRY.port_of_entry%TYPE;
4027    l_date_of_entry            IGS_PE_VISIT_HISTRY.visit_start_date%TYPE;
4028    l_remarks                  IGS_PE_VISIT_HISTRY.remarks%TYPE;
4029    l_psprt_number             IGS_PE_PASSPORT.passport_number%TYPE;
4030    l_psprt_issuing_cntry_code IGS_PE_PASSPORT.passport_cntry_code%TYPE;
4031    l_psprt_exp_date           IGS_PE_PASSPORT.passport_expiry_date%TYPE;
4032    l_not_valid                BOOLEAN := FALSE;
4033 
4034    CURSOR c_get_visa_data IS
4035      SELECT peva.visa_number,
4036             peva.visa_issuing_post,
4037             peva.visa_expiry_date,
4038             pevv.cntry_entry_form_num,
4039             pevv.port_of_entry,
4040             pevv.visit_start_date,
4041             pevv.remarks,
4042             pspt.passport_number,
4043             pspt.passport_cntry_code,
4044             pspt.passport_expiry_date,
4045             peva.visa_issuing_country,
4046 	    peva.visa_issue_date
4047        FROM igs_pe_visa           peva,
4048             igs_pe_visit_histry   pevv,
4049             igs_pe_passport       pspt
4050       WHERE peva.person_id         = p_person_rec.person_id
4051         AND peva.visa_type         IN ('F-1', 'F-2','M-1','M-2')
4052         AND peva.visa_id           = pevv.visa_id (+)
4053         AND pspt.passport_id (+)   = peva.passport_id
4054         AND peva.visa_expiry_date  >= trunc(sysdate);
4055 
4056 BEGIN
4057 /* Debug */
4058 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4059 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Legal_Info';
4060 	  l_debug_str := 'Entering Validate_Legal_Info. p_person_rec.batch_id is '||p_person_rec.batch_id ||' and person_id is '||p_person_rec.person_id;
4061 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4062 	END IF;
4063 
4064    Put_Log_Msg(l_api_name||' starts ',0);
4065    p_data_rec.batch_id := NULL;           -- This will tell us if there's been any records found
4066 
4067 --
4068 -- Obtain all information on the visa that has been made available
4069 --
4070    OPEN c_get_visa_data;
4071    FETCH c_get_visa_data
4072     INTO l_visa_number,
4073          l_visa_issuing_post,
4074          l_visa_expiration_date,
4075          l_I94_number,
4076          l_port_of_entry,
4077          l_date_of_entry,
4078          l_remarks,
4079          l_psprt_number,
4080          l_psprt_issuing_cntry_code,
4081          l_psprt_exp_date,
4082          l_visa_issuing_country,
4083 	 l_visa_issue_date;
4084 
4085 --
4086 -- Make sure that there was visa information found for the person
4087 --
4088    IF (c_get_visa_data%FOUND) THEN
4089 
4090       p_data_rec.psprt_number               := SUBSTR(l_psprt_number,1,25);
4091       p_data_rec.psprt_issuing_cntry_code   := SUBSTR(l_psprt_issuing_cntry_code,1,3);
4092       p_data_rec.psprt_exp_date             := to_char(l_psprt_exp_date,'YYYY-MM-DD');
4093       p_data_rec.visa_number                := SUBSTR(l_visa_number,1,25);
4094       p_data_rec.visa_issuing_post          := SUBSTR(l_visa_issuing_post,3);
4095       p_data_rec.visa_expiration_date       := to_char(l_visa_expiration_date,'YYYY-MM-DD');
4096       p_data_rec.i94_number                 := SUBSTR(l_I94_number,1,11);
4097       p_data_rec.port_of_entry              := SUBSTR(l_port_of_entry,3);
4098       p_data_rec.visa_issuing_cntry_code    := l_visa_issuing_country;
4099       p_data_rec.date_of_entry              := to_char(l_date_of_entry,'YYYY-MM-DD');
4100       p_data_rec.visa_issue_date	    := l_visa_issue_date;
4101       p_data_rec.remarks                    := l_remarks;
4102       p_data_rec.batch_id                   := p_person_rec.batch_id;
4103       p_data_rec.person_id                  := p_person_rec.person_id;
4104       p_data_rec.print_form                 := p_person_rec.print_form;
4105       p_data_rec.creation_date              := sysdate;
4106       p_data_rec.created_by                 := g_update_by;
4107       p_data_rec.last_updated_by            := g_update_by;
4108       p_data_rec.last_update_date           := sysdate;
4109       p_data_rec.last_update_login          := g_update_login;
4110 
4111    END IF;
4112 
4113    CLOSE c_get_visa_data;
4114 
4115    IF (p_data_rec.batch_id IS NULL) THEN
4116 
4117       Put_Log_Msg(l_api_name||' Successfully completed, no rows found returns N ',0);
4118       /* Debug */
4119 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4120 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Legal_Info';
4121 	  l_debug_str := 'Returning N from Validate_Legal_Info.';
4122 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4123 	END IF;
4124       RETURN 'N';
4125 
4126    END IF;
4127 
4128    Put_Log_Msg(l_api_name||' Successfully completed, returns S',0);
4129    /* Debug */
4130 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4131 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Legal_Info';
4132 	  l_debug_str := 'Returning S from Validate_Legal_Info.';
4133 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4134 	END IF;
4135    RETURN 'S'; -- Successfull validation
4136 
4137 EXCEPTION
4138 
4139    WHEN OTHERS THEN
4140    /* Debug */
4141 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4142 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Legal_Info';
4143 	  l_debug_str := 'Exception in Validate_Legal_Info. '||SQLERRM;
4144 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4145 	END IF;
4146 
4147       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
4148          FND_MSg_PUB.Add_Exc_Msg (G_PKG_NAME, l_api_name);
4149       END IF;
4150 
4151       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
4152 
4153       RETURN 'U';
4154 
4155 END Validate_Legal_Info;
4156 
4157 FUNCTION Validate_ev_Legal_Info (
4158    p_person_rec IN      t_student_rec,
4159    p_data_rec   IN OUT NOCOPY  IGS_SV_LEGAL_INFO%ROWTYPE    -- Data record
4160 ) RETURN VARCHAR2
4161 IS
4162 
4163    l_api_name                 CONSTANT VARCHAR(30) := 'Validate_ev_Legal_Info';
4164    l_visa_number              IGS_PE_VISA.visa_number%TYPE;
4165    l_visa_issuing_post        IGS_PE_VISA.visa_issuing_post%TYPE;
4166    l_visa_expiration_date     IGS_PE_VISA.visa_expiry_date%TYPE;
4167    l_visa_issue_date          IGS_PE_VISA.visa_issue_date%TYPE;
4168    l_visa_issuing_country     IGS_PE_VISA.visa_issuing_country%TYPE;
4169    l_I94_number               IGS_PE_VISIT_HISTRY.cntry_entry_form_num%TYPE;
4170    l_port_of_entry            IGS_PE_VISIT_HISTRY.port_of_entry%TYPE;
4171    l_date_of_entry            IGS_PE_VISIT_HISTRY.visit_start_date%TYPE;
4172    l_remarks                  IGS_PE_VISIT_HISTRY.remarks%TYPE;
4173    l_psprt_number             IGS_PE_PASSPORT.passport_number%TYPE;
4174    l_psprt_issuing_cntry_code IGS_PE_PASSPORT.passport_cntry_code%TYPE;
4175    l_psprt_exp_date           IGS_PE_PASSPORT.passport_expiry_date%TYPE;
4176    l_not_valid                BOOLEAN := FALSE;
4177 
4178 --to_char(peva.visa_issue_date,'YYYY-MM-DD') visa_issue_date
4179 
4180    CURSOR c_get_visa_data IS
4181      SELECT peva.visa_number,
4182             peva.visa_issuing_post,
4183             peva.visa_expiry_date,
4184             pevv.cntry_entry_form_num,
4185             pevv.port_of_entry,
4186             pevv.visit_start_date,
4187             pevv.remarks,
4188             pspt.passport_number,
4189             pspt.passport_cntry_code,
4190             pspt.passport_expiry_date,
4191             peva.visa_issuing_country,
4192 	    peva.visa_issue_date
4193        FROM igs_pe_visa           peva,
4194             igs_pe_visit_histry   pevv,
4195             igs_pe_passport       pspt
4196       WHERE peva.person_id         = p_person_rec.person_id
4197         AND peva.visa_type         IN ('J-1', 'J-2')
4198         AND peva.visa_id           = pevv.visa_id (+)
4199         AND pspt.passport_id (+)   = peva.passport_id
4200         AND peva.visa_expiry_date  >= trunc(sysdate);
4201 
4202 BEGIN
4203 /* Debug */
4204 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4205 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_ev_Legal_Info';
4206 	  l_debug_str := 'Entering Validate_ev_Legal_Info. p_person_rec.batch_id is '||p_person_rec.batch_id ||' and person_id is '||p_person_rec.person_id;
4207 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4208 	END IF;
4209 
4210    Put_Log_Msg(l_api_name||' starts ',0);
4211    p_data_rec.batch_id := NULL;           -- This will tell us if there's been any records found
4212 
4213 --
4214 -- Obtain all information on the visa that has been made available
4215 --
4216    OPEN c_get_visa_data;
4217    FETCH c_get_visa_data
4218     INTO l_visa_number,
4219          l_visa_issuing_post,
4220          l_visa_expiration_date,
4221          l_I94_number,
4222          l_port_of_entry,
4223          l_date_of_entry,
4224          l_remarks,
4225          l_psprt_number,
4226          l_psprt_issuing_cntry_code,
4227          l_psprt_exp_date,
4228          l_visa_issuing_country,
4229 	 l_visa_issue_date;
4230 
4231 --
4232 -- Make sure that there was visa information found for the person
4233 --
4234    IF (c_get_visa_data%FOUND) THEN
4235 
4236       p_data_rec.psprt_number               := SUBSTR(l_psprt_number,1,25);
4237       p_data_rec.psprt_issuing_cntry_code   := SUBSTR(l_psprt_issuing_cntry_code,1,3);
4238       p_data_rec.psprt_exp_date             := to_char(l_psprt_exp_date,'YYYY-MM-DD');
4239       p_data_rec.visa_number                := SUBSTR(l_visa_number,1,25);
4240       p_data_rec.visa_issuing_post          := SUBSTR(l_visa_issuing_post,3);
4241       p_data_rec.visa_expiration_date       := to_char(l_visa_expiration_date,'YYYY-MM-DD');
4242       p_data_rec.i94_number                 := SUBSTR(l_I94_number,1,11);
4243       p_data_rec.port_of_entry              := SUBSTR(l_port_of_entry,3);
4244       p_data_rec.visa_issuing_cntry_code    := l_visa_issuing_country;
4245       p_data_rec.date_of_entry              := to_char(l_date_of_entry,'YYYY-MM-DD');
4246       p_data_rec.visa_issue_date            := l_visa_issue_date;
4247       p_data_rec.remarks                    := l_remarks;
4248       p_data_rec.batch_id                   := p_person_rec.batch_id;
4249       p_data_rec.person_id                  := p_person_rec.person_id;
4250       p_data_rec.print_form                 := p_person_rec.print_form;
4251       p_data_rec.creation_date              := sysdate;
4252       p_data_rec.created_by                 := g_update_by;
4253       p_data_rec.last_updated_by            := g_update_by;
4254       p_data_rec.last_update_date           := sysdate;
4255       p_data_rec.last_update_login          := g_update_login;
4256 
4257    END IF;
4258 
4259    CLOSE c_get_visa_data;
4260 
4261    IF (p_data_rec.batch_id IS NULL) THEN
4262 
4263       Put_Log_Msg(l_api_name||' Successfully completed, no rows found returns N ',0);
4264       /* Debug */
4265 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4266 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_ev_Legal_Info';
4267 	  l_debug_str := 'Returning N from Validate_ev_Legal_Info.';
4268 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4269 	END IF;
4270       RETURN 'N';
4271 
4272    END IF;
4273 
4274    Put_Log_Msg(l_api_name||' Successfully completed, returns S',0);
4275    /* Debug */
4276 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4277 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_ev_Legal_Info';
4278 	  l_debug_str := 'Returning S from Validate_ev_Legal_Info.';
4279 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4280 	END IF;
4281    RETURN 'S'; -- Successfull validation
4282 
4283 EXCEPTION
4284 
4285    WHEN OTHERS THEN
4286    /* Debug */
4287 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4288 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_ev_Legal_Info';
4289 	  l_debug_str := 'Exception in Validate_ev_Legal_Info. '||SQLERRM;
4290 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4291 	END IF;
4292 
4293       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
4294          FND_MSg_PUB.Add_Exc_Msg (G_PKG_NAME, l_api_name);
4295       END IF;
4296 
4297       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
4298 
4299       RETURN 'U';
4300 
4301 END Validate_ev_Legal_Info;
4302 
4303 FUNCTION Get_Empl_Info (
4304    p_data_rec  IN OUT NOCOPY  IGS_SV_EMPL_INFO%ROWTYPE     -- Data record
4305 )   RETURN VARCHAR2  -- 'S' Record found, 'N' - not found. 'U' - Unexpected error
4306 IS
4307 
4308    l_api_name CONSTANT VARCHAR2(25) := 'Get_Empl_Info';
4309 
4310    CURSOR c_data_rec IS
4311      SELECT nonimg_empl_id,
4312             empl_rec_type,
4313             empl_type,
4314             recommend_empl,
4315             rescind_empl,
4316             remarks,
4317             empl_start_date ,
4318             empl_end_date,
4319             course_relevance,
4320             empl_time,
4321             empl_name,
4322 	    action_code
4323       FROM igs_sv_empl_info
4324       WHERE
4325             person_id = p_data_rec.person_id and
4326             nonimg_empl_id = p_data_rec.nonimg_empl_id and
4327 	    batch_id IN
4328             (  SELECT max(emp.batch_id)
4329                  FROM igs_sv_empl_info emp,
4330                       igs_sv_persons pr
4331                 WHERE emp.person_id = pr.person_id
4332                       AND emp.batch_id = pr.batch_id
4333                       AND pr.record_status <> 'E'
4334                       AND emp.person_id = p_data_rec.person_id
4335 		      AND emp.nonimg_empl_id = p_data_rec.nonimg_empl_id
4336             )
4337     ORDER BY nonimg_empl_id;
4338 
4339 BEGIN
4340 	/* Debug */
4341 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4342 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Empl_Info';
4343 	  l_debug_str := 'Entering Get_Empl_Info. p_data_rec.person_id is '||p_data_rec.person_id;
4344 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4345 	END IF;
4346 
4347    Put_Log_Msg(l_api_name||' begins ',0);
4348 
4349    OPEN c_data_rec;
4350    FETCH c_data_rec
4351     INTO p_data_rec.nonimg_empl_id  ,
4352          p_data_rec.empl_rec_type   ,
4353          p_data_rec.empl_type       ,
4354          p_data_rec.recommend_empl  ,
4355          p_data_rec.rescind_empl    ,
4356          p_data_rec.remarks         ,
4357          p_data_rec.empl_start_date ,
4358          p_data_rec.empl_end_date   ,
4359          p_data_rec.course_relevance,
4360          p_data_rec.empl_time     ,
4361          p_data_rec.empl_name     ,
4362          p_data_rec.action_code   ;
4363 
4364    IF c_data_rec%NOTFOUND THEN
4365 
4366       Put_Log_Msg('Record not found ',0);
4367       CLOSE c_data_rec;
4368       /* Debug */
4369 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4370 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Empl_Info';
4371 	  l_debug_str := 'Returning N from Get_Empl_Info';
4372 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4373 	END IF;
4374       RETURN 'N';
4375 
4376    END IF;
4377 
4378    CLOSE c_data_rec;
4379 
4380    Put_Log_Msg(l_api_name||' ends S ',0);
4381 	/* Debug */
4382 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4383 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Empl_Info';
4384 	  l_debug_str := 'Returning S from Get_Empl_Info';
4385 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4386 	END IF;
4387    RETURN 'S';
4388 
4389 EXCEPTION
4390 
4391    WHEN FND_API.G_EXC_ERROR THEN
4392 	 /* Debug */
4393 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4394 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Empl_Info';
4395 	  l_debug_str := 'Exception in Get_Empl_Info '||SQLERRM;
4396 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4397 	END IF;
4398 
4399       Put_Log_Msg(l_api_name||' EXEC ERROR ',0);
4400       RETURN 'U';
4401 
4402    WHEN OTHERS THEN
4403       /* Debug */
4404 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4405 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Empl_Info';
4406 	  l_debug_str := 'Exception in Get_Empl_Info '||SQLERRM;
4407 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4408 	END IF;
4409       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
4410          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
4411       END IF;
4412 
4413       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
4414       RETURN  'U';
4415 
4416 END Get_Empl_Info;
4417 
4418 FUNCTION Check_emp_duration(stDate IN VARCHAR2 , endDt IN VARCHAR2 , p_visa_type IN VARCHAR2) RETURN BOOLEAN IS
4419         returnVal boolean := false;
4420 	startDate Date;
4421 	endDate Date;
4422 	daysBetween number := 0;
4423 
4424     BEGIN
4425 	startDate := TO_DATE(stDate,'YYYY-MM-DD');
4426 	endDate := TO_DATE(endDt,'YYYY-MM-DD');
4427 	daysBetween := endDate-startDate;
4428 
4429 	IF p_visa_type= 'F-1' AND  daysBetween > 365 THEN
4430 	    	returnVal := true;
4431 	ELSIF p_visa_type= 'M-1' AND daysBetween > 183 THEN
4432                   returnVal := true;
4433         END IF;
4434 	RETURN returnVal;
4435 END Check_emp_duration;
4436 
4437 -- only for validation of the input record
4438 FUNCTION validate_employment_Info(
4439   p_person_rec    IN      t_student_rec,
4440   p_data_rec      IN OUT NOCOPY  IGS_SV_EMPL_INFO%ROWTYPE     --Data record
4441 ) RETURN BOOLEAN
4442 IS
4443    l_not_valid    BOOLEAN := FALSE;
4444    l_visa_type VARCHAR2(5);
4445    l_api_name CONSTANT VARCHAR2(25) := 'validate_employment_Info';
4446    l_months NUMBER(2);
4447    CURSOR c_get_visa_type
4448    IS
4449      SELECT visa_type
4450      FROM igs_pe_nonimg_form
4451      WHERE person_id =  p_person_rec.person_id
4452            AND nonimg_form_id =  p_person_rec.form_id;
4453 
4454  BEGIN
4455 	/* Debug */
4456 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4457 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.validate_employment_Info';
4458 	  l_debug_str := 'Entering validate_employment_Info. p_person_rec.batch_id is '||p_person_rec.batch_id ||' and person_id is '||p_person_rec.person_id;
4459 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4460 	END IF;
4461 
4462 	OPEN c_get_visa_type;
4463 	FETCH c_get_visa_type INTO l_visa_type;
4464 	CLOSE c_get_visa_type;
4465 
4466 	IF l_visa_type ='F-1' THEN
4467 	    l_months := 12;
4468 	ELSE
4469 	    l_months := 6;
4470 	END IF;
4471 
4472 
4473       -- Validate all the data
4474    IF p_data_rec.empl_rec_type = 'F'
4475       AND ( ( p_data_rec.recommend_empl   IS NULL
4476                  AND p_data_rec.rescind_empl IS NULL
4477                )
4478             OR p_data_rec.remarks IS NULL) THEN
4479 
4480          FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_EMPL_F_RQD_FLD_ERR'); -- Employment block error
4481          FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
4482 
4483          Put_Log_Msg(FND_MESSAGE.Get,1);
4484          l_not_valid := TRUE;
4485 
4486    ELSIF p_data_rec.empl_rec_type = 'O'
4487       AND ( p_data_rec.empl_time           IS NULL
4488             OR p_data_rec.empl_start_date  IS NULL
4489             OR p_data_rec.empl_end_date    IS NULL
4490             OR p_data_rec.course_relevance IS NULL) THEN
4491 
4492          FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_EMPL_O_RQD_FLD_ERR'); -- Employment block error
4493          FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
4494 
4495          Put_Log_Msg(FND_MESSAGE.Get,1);
4496          l_not_valid := TRUE;
4497 
4498    ELSIF p_data_rec.empl_rec_type = 'C'
4499       AND ( p_data_rec.empl_time           IS NULL
4500             OR p_data_rec.empl_start_date  IS NULL
4501             OR p_data_rec.empl_end_date    IS NULL
4502             OR p_data_rec.course_relevance IS NULL
4503             OR p_data_rec.empl_name        IS NULL
4504             OR p_data_rec.empl_addr_line1  IS NULL
4505             OR p_data_rec.city             IS NULL
4506             OR p_data_rec.state            IS NULL
4507             OR p_data_rec.postal_code      IS NULL
4508             ) THEN
4509 
4510          FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_EMPL_C_RQD_FLD_ERR'); -- Employment block error
4511          FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number );
4512 
4513          Put_Log_Msg(FND_MESSAGE.Get,1);
4514          l_not_valid := TRUE;
4515      ELSIF p_data_rec.empl_rec_type = 'O' THEN
4516           IF Check_emp_duration(p_data_rec.empl_start_date, p_data_rec.empl_end_date, l_visa_type) THEN
4517 	       FND_MESSAGE.SET_NAME('IGS','IGS_SV_EMP_INV_PRD');
4518 	       FND_MESSAGE.SET_TOKEN('MONTHS',l_months);
4519 	       FND_MESSAGE.SET_TOKEN('VISA_TYPE',l_visa_type);
4520 	       Put_Log_Msg(FND_MESSAGE.Get,1);
4521                l_not_valid := TRUE;
4522           END IF;
4523    END IF;
4524 
4525    IF l_not_valid THEN
4526 
4527      Put_Log_Msg(l_api_name||' Validation error, return E ',0);
4528 
4529   --   RETURN 'E';
4530   ELSE
4531      Put_Log_Msg(l_api_name||' Successfully completed, returns S',0);
4532 
4533    --  RETURN 'S'; -- Successfull validation
4534 
4535    END IF;
4536    /* Debug */
4537 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4538 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.validate_employment_Info';
4539 	  l_debug_str := 'Returning from validate_employment_Info';
4540 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4541 	END IF;
4542 
4543    RETURN l_not_valid;
4544 
4545 
4546 END validate_employment_Info;
4547 
4548 
4549 --Overload validate_empl_info method to accept table type argument
4550 
4551 FUNCTION Validate_Empl_Info (
4552    p_person_rec    IN      t_student_rec,
4553    p_data_rec   IN OUT NOCOPY  g_empl_rec_type,    -- Data record
4554    p_records    OUT NOCOPY     NUMBER                   -- Number of dependents found
4555 ) RETURN VARCHAR2
4556 IS
4557 
4558  -- Select the oldest employment record haven't been reported to INS yet.
4559 
4560 
4561    -- Select only! unreported records since no data change is possbile.
4562 
4563    CURSOR c_data(cp_person_id hz_parties.party_id%TYPE) IS
4564      SELECT nonimg_empl_id,
4565             frm.nonimg_form_id,
4566             decode ( empl_type,'01','O','02','C','F')  empl_rec_type,
4567             empl_type,
4568             recommend_empl,
4569             rescind_empl,
4570             em.remarks,
4571             to_char(empl_start_date, 'YYYY-MM-DD') empl_start_date,
4572             to_char(empl_end_date, 'YYYY-MM-DD') empl_end_date,
4573             course_relevance,
4574             empl_time,
4575             empl_party_id,
4576 	    action_code,
4577 	    NVL(em.print_flag, 'N') print_flag
4578        FROM igs_pe_nonimg_empl em,
4579             igs_pe_nonimg_form frm
4580       WHERE frm.person_id = cp_person_id
4581             AND frm.nonimg_form_id = em.nonimg_form_id
4582     ORDER BY nonimg_empl_id;
4583 
4584 
4585     CURSOR c_empl_name (l_party_id NUMBER) IS
4586      SELECT party_name
4587        FROM hz_parties
4588       WHERE party_id = l_party_id;
4589 
4590     CURSOR c_empl_addr (l_party_id NUMBER) IS
4591      SELECT SUBSTR(address1||address2||address3||address4,1,60) addr_line1,
4592             SUBSTR(address1||address2||address3||address4,1,60) addr_line2,
4593             SUBSTR(city,1,60) city    ,
4594             SUBSTR(state,1,2) state   ,
4595             postal_code
4596        FROM hz_locations lc, hz_party_sites st
4597       WHERE party_id = l_party_id
4598             AND lc.location_id = st.location_id
4599             AND identifying_address_flag  ='Y';
4600 
4601   l_postal_code  hz_locations.postal_code%TYPE;
4602   l_not_valid    BOOLEAN := FALSE;
4603   l_api_name CONSTANT VARCHAR(30) := 'Validate_Empl_Info';
4604   l_counter NUMBER(10):= 0;
4605 
4606 BEGIN
4607 
4608 	/* Debug */
4609 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4610 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Empl_Info';
4611 	  l_debug_str := 'Entering validate_empl_Info p_person_rec.batch_id is '||p_person_rec.batch_id ||' and person_id is '||p_person_rec.person_id;
4612 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4613 	END IF;
4614 
4615    Put_Log_Msg(l_api_name||' starts ',0);
4616 
4617    FOR c_data_rec IN c_data(p_person_rec.person_id) LOOP
4618 
4619        l_counter := l_counter +1;
4620 
4621        p_data_rec(l_counter).batch_id := p_person_rec.batch_id;
4622        p_data_rec(l_counter).person_id := p_person_rec.person_id;
4623        p_data_rec(l_counter).print_form := c_data_rec.print_flag; -- p_person_rec.print_form; PRBHARDW
4624        p_data_rec(l_counter).creation_date := sysdate;
4625        p_data_rec(l_counter).created_by := g_update_by;
4626        p_data_rec(l_counter).last_updated_by := g_update_by;
4627        p_data_rec(l_counter).last_update_date  := sysdate;
4628        p_data_rec(l_counter).last_update_login := g_update_login;
4629 
4630        p_data_rec(l_counter).empl_rec_type := c_data_rec.empl_rec_type; -- C(PT) O(PT) F(Off campus)
4631        p_data_rec(l_counter).empl_type  := c_data_rec.empl_type;
4632        p_data_rec(l_counter).nonimg_empl_id:= c_data_rec.nonimg_empl_id;
4633        p_data_rec(l_counter).recommend_empl  := c_data_rec.recommend_empl ;
4634        p_data_rec(l_counter).rescind_empl  := c_data_rec.rescind_empl;
4635        p_data_rec(l_counter).remarks   := c_data_rec.remarks;
4636        p_data_rec(l_counter).empl_start_date  := c_data_rec.empl_start_date;
4637        p_data_rec(l_counter).empl_end_date  := c_data_rec.empl_end_date;
4638        p_data_rec(l_counter).empl_time  := c_data_rec.empl_time;
4639        p_data_rec(l_counter).course_relevance  := c_data_rec.course_relevance;
4640        p_data_rec(l_counter).action_code := c_data_rec.action_code;
4641 
4642        /* Debug */
4643 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4644 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Empl_Info';
4645 	  l_debug_str := 'Remarks: '||p_data_rec(l_counter).remarks||' Empl Type: '||p_data_rec(l_counter).empl_rec_type;
4646 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4647 	END IF;
4648 
4649        IF p_data_rec(l_counter).empl_rec_type  <> 'F' THEN
4650          -- Get party id and address info
4651          OPEN c_empl_name (c_data_rec.empl_party_id);
4652          FETCH c_empl_name INTO p_data_rec(l_counter).empl_name;
4653          CLOSE c_empl_name;
4654 
4655          OPEN c_empl_addr (c_data_rec.empl_party_id);
4656          FETCH c_empl_addr
4657            INTO p_data_rec(l_counter).empl_addr_line1,
4658                 p_data_rec(l_counter).empl_addr_line2,
4659                 p_data_rec(l_counter).city,
4660                 p_data_rec(l_counter).state,
4661                 l_postal_code;
4662 
4663          p_data_rec(l_counter).postal_code := substr(l_postal_code,1,5);
4664          p_data_rec(l_counter).postal_routing_code := substr(l_postal_code,7,4);
4665          CLOSE c_empl_addr;
4666        END IF;
4667 
4668          l_not_valid := validate_employment_Info(p_person_rec => p_person_rec,
4669                                                  p_data_rec  => p_data_rec(l_counter));
4670 
4671         IF l_not_valid THEN
4672            Put_Log_Msg(l_api_name||' Validation error, return E ',0);
4673 	   /* Debug */
4674 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4675 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Empl_Info';
4676 	  l_debug_str := 'Returning E from validate_empl_Info.';
4677 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4678 	END IF;
4679 	   RETURN 'E';
4680 	END IF;
4681    END LOOP;
4682 
4683     p_records := l_counter;
4684    IF l_counter = 0 THEN
4685       Put_Log_Msg(l_api_name||' Successfully completed, no rows found returns N ',0);
4686       /* Debug */
4687 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4688 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Empl_Info';
4689 	  l_debug_str := 'Returning N from validate_empl_Info.';
4690 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4691 	END IF;
4692       RETURN 'N';
4693    END IF;
4694 
4695      -- Validate all the data
4696 
4697    Put_Log_Msg(l_api_name||' Successfully completed, returns S',0);
4698 /* Debug */
4699 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4700 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Empl_Info';
4701 	  l_debug_str := 'Returning S from validate_empl_Info.';
4702 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4703 	END IF;
4704    RETURN 'S'; -- Successfull validation
4705 EXCEPTION
4706 
4707    WHEN OTHERS THEN
4708    /* Debug */
4709 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4710 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Validate_Empl_Info';
4711 	  l_debug_str := 'Exception in validate_empl_Info. '||SQLERRM;
4712 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4713 	END IF;
4714 
4715       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
4716          FND_MSg_PUB.Add_Exc_Msg (G_PKG_NAME, l_api_name);
4717       END IF;
4718 
4719       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
4720       RETURN 'U';
4721 
4722 END Validate_Empl_Info;
4723 /******************************************************************
4724    Created By         : Arkadi Tereshenkov
4725 
4726    Date Created By    : Oct 14, 2002
4727 
4728    Purpose            : Get the person information on the student.
4729                         (IGS_SV_PERSONS).
4730 
4731    Remarks            :
4732 
4733    Change History
4734    Who                  When            What
4735 ------------------------------------------------------------------------
4736 
4737 ******************************************************************/
4738 FUNCTION Get_Issue_Info (
4739    p_data_rec  IN OUT NOCOPY  IGS_SV_PERSONS%ROWTYPE   -- Data record
4740 ) RETURN VARCHAR2  -- 'S' Record found, 'N' - not found. 'U' - Unexpected error
4741 IS
4742 
4743    l_api_name CONSTANT  VARCHAR2(25) := 'Get_Issue_Info';
4744 
4745    CURSOR c_data_rec IS
4746      SELECT cr.batch_id               ,
4747             cr.person_id              ,
4748             cr.record_number          ,
4749             cr.form_id                ,
4750             decode(cr.print_form,'Y','1','0') print_form,
4751             cr.record_status          ,
4752             cr.person_number          ,
4753             cr.sevis_user_id          ,
4754             cr.issuing_reason         ,
4755             cr.curr_session_end_date  ,
4756             cr.next_session_start_date,
4757             cr.other_reason           ,
4758             cr.transfer_from_school   ,
4759             cr.ev_create_reason       ,
4760             cr.ev_form_number	      ,
4761 	    cr.no_show_flag	      ,
4762 	    cr.last_session_flag
4763        FROM igs_sv_persons cr
4764       WHERE cr.person_id = p_data_rec.person_id
4765         AND cr.batch_id IN
4766             (  SELECT max(mx.batch_id)
4767                  FROM igs_sv_persons mx
4768                 WHERE mx.person_id = p_data_rec.person_id
4769                       AND mx.record_status <> 'E'
4770             );
4771 
4772 BEGIN
4773 	/* Debug */
4774 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4775 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Issue_Info';
4776 	  l_debug_str := 'Entering Get_Issue_Info. p_data_rec.person_id is '||p_data_rec.person_id;
4777 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4778 	END IF;
4779 
4780    Put_Log_Msg(l_api_name||' begins ',0);
4781 
4782    OPEN c_data_rec;
4783    FETCH c_data_rec
4784     INTO p_data_rec.batch_id               ,
4785          p_data_rec.person_id              ,
4786          p_data_rec.record_number          ,
4787          p_data_rec.form_id                ,
4788          p_data_rec.print_form             ,
4789          p_data_rec.record_status          ,
4790          p_data_rec.person_number          ,
4791          p_data_rec.sevis_user_id          ,
4792          p_data_rec.issuing_reason         ,
4793          p_data_rec.curr_session_end_date  ,
4794          p_data_rec.next_session_start_date,
4795          p_data_rec.other_reason           ,
4796          p_data_rec.transfer_from_school   ,
4797          p_data_rec.ev_create_reason       ,
4798          p_data_rec.ev_form_number	   ,
4799 	 p_data_rec.no_show_flag	   ,
4800 	 p_data_rec.last_session_flag;
4801 
4802    IF c_data_rec%NOTFOUND THEN
4803 
4804       Put_Log_Msg('Record not found ',0);
4805       CLOSE c_data_rec;
4806       /* Debug */
4807 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4808 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Issue_Info';
4809 	  l_debug_str := 'Returning N from Get_Issue_Info.';
4810 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4811 	END IF;
4812       RETURN 'N';
4813 
4814    END IF;
4815 
4816    CLOSE c_data_rec;
4817 
4818    Put_Log_Msg(l_api_name||' ends S ',0);
4819 /* Debug */
4820 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4821 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Issue_Info';
4822 	  l_debug_str := 'Returning S from Get_Issue_Info.';
4823 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4824 	END IF;
4825    RETURN 'S';
4826 
4827 EXCEPTION
4828 
4829    WHEN FND_API.G_EXC_ERROR THEN
4830 
4831       Put_Log_Msg(l_api_name||' EXEC ERROR ',0);
4832 	/* Debug */
4833 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4834 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Issue_Info';
4835 	  l_debug_str := 'FND_API.G_EXC_ERROR in Get_Issue_Info. '||SQLERRM;
4836 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4837 	END IF;
4838 
4839       RETURN 'U';
4840 
4841    WHEN OTHERS THEN
4842 
4843       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
4844          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
4845       END IF;
4846 	/* Debug */
4847 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4848 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Issue_Info';
4849 	  l_debug_str := 'Exception in Get_Issue_Info. '||SQLERRM;
4850 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4851 	END IF;
4852 
4853       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
4854 
4855       RETURN  'U';
4856 
4857 END Get_Issue_Info;
4858 
4859 
4860 
4861 /******************************************************************
4862    Created By         : Arkadi Tereshenkov
4863 
4864    Date Created By    : Oct 14, 2002
4865 
4866    Purpose            : Get BIO Information for the student.
4867                         (IGS_SV_BIO_INFO).
4868 
4869    Remarks            :
4870 
4871    Change History
4872    Who                  When            What
4873 ------------------------------------------------------------------------
4874 
4875 ******************************************************************/
4876 FUNCTION  Get_Bio_Info (
4877    p_data_rec  IN OUT NOCOPY  IGS_SV_BIO_INFO%ROWTYPE   -- Data record
4878 ) RETURN VARCHAR2  -- 'S' Record found, 'N' - not found. 'U' - Unexpected error
4879 IS
4880 
4881    l_api_name CONSTANT VARCHAR2(25) := 'Get_Bio_Info';
4882 
4883    CURSOR c_data_rec IS
4884      SELECT birth_date             ,
4885             birth_cntry_code       ,
4886             citizen_cntry_code     ,
4887             last_name              ,
4888             middle_name            ,
4889             first_name             ,
4890             suffix                 ,
4891             gender                 ,
4892             legal_res_cntry_code   ,
4893             position_code          ,
4894             commuter               ,
4895             remarks		   ,
4896 	    birth_cntry_resn_code  ,
4897 	    birth_city
4898        FROM igs_sv_bio_info  cr
4899       WHERE cr.person_id = p_data_rec.person_id
4900         AND cr.batch_id IN
4901             (  SELECT max(prs.batch_id)
4902                  FROM igs_sv_bio_info prs,
4903                       igs_sv_persons pr
4904                 WHERE prs.person_id = pr.person_id
4905                       AND prs.batch_id = pr.batch_id
4906                       AND pr.record_status <> 'E'
4907                       AND prs.person_id = p_data_rec.person_id
4908             );
4909 
4910 BEGIN
4911 	/* Debug */
4912 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4913 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Bio_Info';
4914 	  l_debug_str := 'Entering Get_Bio_Info. p_data_rec.person_id is '||p_data_rec.person_id;
4915 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4916 	END IF;
4917 
4918    Put_Log_Msg(l_api_name||' begins ',0);
4919 
4920    OPEN c_data_rec;
4921    FETCH c_data_rec
4922     INTO p_data_rec.birth_date             ,
4923          p_data_rec.birth_cntry_code       ,
4924          p_data_rec.citizen_cntry_code     ,
4925          p_data_rec.last_name              ,
4926          p_data_rec.middle_name            ,
4927          p_data_rec.first_name             ,
4928          p_data_rec.suffix                 ,
4929          p_data_rec.gender                 ,
4930          p_data_rec.legal_res_cntry_code   ,
4931          p_data_rec.position_code          ,
4932          p_data_rec.commuter               ,
4933          p_data_rec.remarks		   ,
4934 	 p_data_rec.birth_cntry_resn_code  ,
4935 	 p_data_rec.birth_city;
4936 
4937    IF c_data_rec%NOTFOUND THEN
4938 
4939       Put_Log_Msg('Record not found ',0);
4940       CLOSE c_data_rec;
4941       /* Debug */
4942 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4943 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Bio_Info';
4944 	  l_debug_str := 'Returning N from Get_Bio_Info.';
4945 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4946 	END IF;
4947       RETURN 'N';
4948 
4949    END IF;
4950 
4951    CLOSE c_data_rec;
4952 
4953    Put_Log_Msg(l_api_name||' ends S ',0);
4954     /* Debug */
4955 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4956 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Bio_Info';
4957 	  l_debug_str := 'Returning S from Get_Bio_Info.';
4958 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4959 	END IF;
4960 
4961    RETURN 'S';
4962 
4963 EXCEPTION
4964 
4965    WHEN FND_API.G_EXC_ERROR THEN
4966     /* Debug */
4967 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4968 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Bio_Info';
4969 	  l_debug_str := 'FND_API.G_EXC_ERROR in Get_Bio_Info. '||SQLERRM;
4970 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4971 	END IF;
4972 
4973       Put_Log_Msg(l_api_name||' EXEC ERROR ',0);
4974 
4975       RETURN 'U';
4976 
4977    WHEN OTHERS THEN
4978 
4979       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
4980          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
4981       END IF;
4982 	/* Debug */
4983 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
4984 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Bio_Info';
4985 	  l_debug_str := 'Exception in Get_Bio_Info. '||SQLERRM;
4986 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
4987 	END IF;
4988       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
4989 
4990       RETURN  'U';
4991 
4992 END Get_Bio_Info;
4993 
4994 
4995 /******************************************************************
4996    Created By         : Arkadi Tereshenkov
4997 
4998    Date Created By    : Oct 14, 2002
4999 
5000    Purpose            : Get other information on the student
5001                         (IGS_SV_OTH_INFO)
5002 
5003    Remarks            :
5004 
5005    Change History
5006    Who                  When            What
5007 ------------------------------------------------------------------------
5008 
5009 ******************************************************************/
5010 FUNCTION Get_Other_Info (
5011    p_data_rec  IN OUT NOCOPY  IGS_SV_OTH_INFO%ROWTYPE   -- Data record
5012 ) RETURN VARCHAR2  -- 'S' Record found, 'N' - not found. 'U' - Unexpected error
5013 IS
5014 
5015    l_api_name CONSTANT VARCHAR2(25) := 'Get_Other_Info';
5016 
5017    CURSOR c_data_rec IS
5018      SELECT drivers_license        ,
5019             drivers_license_state  ,
5020             ssn                    ,
5021             tax_id
5022        FROM igs_sv_oth_info cr
5023       WHERE cr.person_id = p_data_rec.person_id
5024         AND cr.batch_id IN
5025             (  SELECT max(prs.batch_id)
5026                  FROM igs_sv_oth_info prs,
5027                      igs_sv_persons pr
5028                WHERE prs.person_id = pr.person_id
5029                      AND prs.batch_id = pr.batch_id
5030                      AND pr.record_status <> 'E'
5031                      AND prs.person_id = p_data_rec.person_id
5032             );
5033 
5034 BEGIN
5035 /* Debug */
5036 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5037    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Other_Info';
5038    l_debug_str := 'Entering Get_Other_Info. p_data_rec.person_id is '||p_data_rec.person_id;
5039    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5040 END IF;
5041 
5042    Put_Log_Msg(l_api_name||' begins ',0);
5043 
5044    OPEN c_data_rec;
5045    FETCH c_data_rec
5046     INTO p_data_rec.drivers_license        ,
5047          p_data_rec.drivers_license_state  ,
5048          p_data_rec.ssn                    ,
5049          p_data_rec.tax_id                 ;
5050 
5051    IF c_data_rec%NOTFOUND THEN
5052 
5053       Put_Log_Msg('Record not found ',0);
5054       CLOSE c_data_rec;
5055       /* Debug */
5056 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5057 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Other_Info';
5058 	   l_debug_str := 'Returning N from Get_Other_Info.';
5059 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5060 	END IF;
5061 
5062       RETURN 'N';
5063 
5064    END IF;
5065 
5066    CLOSE c_data_rec;
5067 
5068    Put_Log_Msg(l_api_name||' ends S ',0);
5069    /* Debug */
5070 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5071 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Other_Info';
5072 	   l_debug_str := 'Returning S from Get_Other_Info.';
5073 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5074 	END IF;
5075    RETURN 'S';
5076 
5077 EXCEPTION
5078 
5079    WHEN FND_API.G_EXC_ERROR THEN
5080 
5081       Put_Log_Msg(l_api_name||' EXEC ERROR ',0);
5082       /* Debug */
5083 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5084 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Other_Info';
5085 	   l_debug_str := 'FND_API.G_EXC_ERROR in Get_Other_Info-- Returning U. '||SQLERRM;
5086 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5087 	END IF;
5088       RETURN 'U';
5089 
5090    WHEN OTHERS THEN
5091 
5092       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
5093          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
5094       END IF;
5095 
5096       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
5097       /* Debug */
5098 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5099 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Other_Info';
5100 	   l_debug_str := 'Exception in Get_Other_Info-- Returning U. '||SQLERRM;
5101 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5102 	END IF;
5103       RETURN 'U';
5104 
5105       RETURN  'U';
5106 
5107 END Get_Other_Info;
5108 
5109 
5110 
5111 /******************************************************************
5112    Created By         : Arkadi Tereshenkov
5113 
5114    Date Created By    : Oct 14, 2002
5115 
5116    Purpose            : Get Site of activity information on the student
5117                         (IGS_SV_ADDRESSES).
5118 
5119    Remarks            :
5120 
5121    Change History
5122    Who                  When            What
5123 ------------------------------------------------------------------------
5124 
5125 ******************************************************************/
5126 FUNCTION Get_Address_Info (
5127    p_data_rec  IN OUT NOCOPY  IGS_SV_ADDRESSES%ROWTYPE   -- Data record
5128 )  RETURN VARCHAR2  -- 'S' Record found, 'N' - not found. 'U' - Unexpected error
5129 IS
5130 
5131    l_api_name CONSTANT VARCHAR2(25) := 'Get_Address_Info';
5132 
5133    CURSOR c_data_rec IS
5134      SELECT action_type            ,
5135             address_type           ,
5136             address_line1          ,
5137             address_line2          ,
5138             city                   ,
5139             state                  ,
5140             postal_code            ,
5141             postal_routing_code    ,
5142             country_code           ,
5143             province               ,
5144             stdnt_valid_flag	   ,
5145 	    primary_flag           ,
5146 	    activity_site_cd
5147        FROM igs_sv_addresses cr
5148       WHERE cr.person_id = p_data_rec.person_id
5149         AND cr.party_site_id = p_data_rec.party_site_id
5150         AND cr.batch_id IN
5151             (  SELECT max(prs.batch_id)
5152                  FROM igs_sv_addresses prs,
5153                       igs_sv_persons pr
5154                 WHERE prs.person_id = pr.person_id
5155                      AND prs.batch_id = pr.batch_id
5156                      AND pr.record_status <> 'E'
5157                      AND prs.person_id = p_data_rec.person_id
5158                      AND prs.party_site_id = p_data_rec.party_site_id
5159             );
5160 BEGIN
5161 
5162    Put_Log_Msg(l_api_name||' begins ',0);
5163    /* Debug */
5164 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5165    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Address_Info';
5166    l_debug_str := 'Entering Get_Address_Info. p_data_rec.party_site_id is '||p_data_rec.party_site_id;
5167    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5168 END IF;
5169 
5170    OPEN c_data_rec;
5171    FETCH c_data_rec
5172     INTO p_data_rec.action_type            ,
5173          p_data_rec.address_type           ,
5174          p_data_rec.address_line1          ,
5175          p_data_rec.address_line2          ,
5176          p_data_rec.city                   ,
5177          p_data_rec.state                  ,
5178          p_data_rec.postal_code            ,
5179          p_data_rec.postal_routing_code    ,
5180          p_data_rec.country_code           ,
5181          p_data_rec.province               ,
5182          p_data_rec.stdnt_valid_flag       ,
5183 	 p_data_rec.primary_flag	   ,
5184 	 p_data_rec.activity_site_cd	   ;
5185 
5186    IF c_data_rec%NOTFOUND THEN
5187 
5188       Put_Log_Msg('Record not found ',0);
5189       CLOSE c_data_rec;
5190       /* Debug */
5191 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5192 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Address_Info';
5193 	   l_debug_str := 'Returning N from Get_Address_Info.';
5194 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5195 	END IF;
5196 
5197       RETURN 'N';
5198 
5199    END IF;
5200 
5201    CLOSE c_data_rec;
5202 
5203    Put_Log_Msg(l_api_name||' ends S ',0);
5204    /* Debug */
5205 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5206 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Address_Info';
5207 	   l_debug_str := 'Returning S from Get_Address_Info.';
5208 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5209 	END IF;
5210    RETURN 'S';
5211 
5212 EXCEPTION
5213 
5214    WHEN FND_API.G_EXC_ERROR THEN
5215 
5216       Put_Log_Msg(l_api_name||' EXEC ERROR ',0);
5217       /* Debug */
5218 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5219 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Address_Info';
5220 	   l_debug_str := 'FND_API.G_EXC_ERROR in Get_Address_Info. Returning U... '||SQLERRM;
5221 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5222 	END IF;
5223 
5224       RETURN 'U';
5225 
5226    WHEN OTHERS THEN
5227 
5228       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
5229          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
5230       END IF;
5231 
5232       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
5233       /* Debug */
5234 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5235 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Address_Info';
5236 	   l_debug_str := 'EXCEPTION in Get_Address_Info. Returning U... '||SQLERRM;
5237 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5238 	END IF;
5239 
5240       RETURN  'U';
5241 
5242 END Get_Address_Info;
5243 
5244 
5245 
5246 /******************************************************************
5247    Created By         : Arkadi Tereshenkov
5248 
5249    Date Created By    : Oct 14, 2002
5250 
5251    Purpose            : Get Education information on the student
5252                         (IGS_SV_PRGMS_INFO).
5253 
5254    Remarks            :
5255 
5256    Change History
5257    Who                  When            What
5258 ------------------------------------------------------------------------
5259 
5260 ******************************************************************/
5261 FUNCTION Get_Edu_Info (
5262    p_data_rec  IN OUT NOCOPY  IGS_SV_PRGMS_INFO%ROWTYPE    -- Data record
5263 )  RETURN VARCHAR2  -- 'S' Record found, 'N' - not found. 'U' - Unexpected error
5264 IS
5265 
5266    l_api_name CONSTANT VARCHAR2(25) := 'Get_Edu_Info';
5267 
5268    CURSOR c_data_rec IS
5269      SELECT position_code          ,
5270             subject_field_code     ,
5271             education_level        ,
5272             primary_major          ,
5273             secondary_major        ,
5274             minor                  ,
5275             length_of_study        ,
5276             prgm_start_date        ,
5277             prgm_end_date          ,
5278             english_reqd           ,
5279             english_reqd_met       ,
5280             not_reqd_reason        ,
5281             educ_lvl_remarks	   ,
5282 	    remarks
5283        FROM igs_sv_prgms_info cr
5284       WHERE cr.person_id = p_data_rec.person_id
5285         --AND cr.prgm_action_type='EP'
5286         AND cr.batch_id IN
5287             (  SELECT max(prs.batch_id)
5288                  FROM igs_sv_prgms_info prs,
5289                       igs_sv_persons pr
5290                WHERE prs.person_id = pr.person_id
5291                      AND prs.batch_id = pr.batch_id
5292                      AND pr.record_status <> 'E'
5293                      AND prs.person_id        = p_data_rec.person_id
5294                      --AND prs.prgm_action_type = 'EP'
5295             );
5296 
5297 BEGIN
5298 
5299    Put_Log_Msg(l_api_name||' begins ',0);
5300    /* Debug */
5301 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5302    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Edu_Info';
5303    l_debug_str := 'Entering Get_Edu_Info. p_data_rec.person_id is '||p_data_rec.person_id;
5304    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5305 END IF;
5306 
5307    OPEN c_data_rec;
5308    FETCH c_data_rec
5309     INTO p_data_rec.position_code          ,
5310          p_data_rec.subject_field_code     ,
5311          p_data_rec.education_level        ,
5312          p_data_rec.primary_major          ,
5313          p_data_rec.secondary_major        ,
5314          p_data_rec.minor                  ,
5315          p_data_rec.length_of_study        ,
5316          p_data_rec.prgm_start_date        ,
5317          p_data_rec.prgm_end_date          ,
5318          p_data_rec.english_reqd           ,
5319          p_data_rec.english_reqd_met       ,
5320          p_data_rec.not_reqd_reason        ,
5321          p_data_rec.educ_lvl_remarks       ,
5322 	 p_data_rec.remarks;
5323 
5324    IF c_data_rec%NOTFOUND THEN
5325 
5326       Put_Log_Msg('Record not found ',0);
5327       CLOSE c_data_rec;
5328       /* Debug */
5329 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5330 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Edu_Info';
5331 	  l_debug_str := 'Returning N from Get_Edu_Info.';
5332 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5333 	END IF;
5334       RETURN 'N';
5335 
5336    END IF;
5337 
5338    CLOSE c_data_rec;
5339 
5340    Put_Log_Msg(l_api_name||' ends S ',0);
5341 	/* Debug */
5342 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5343 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Edu_Info';
5344 	  l_debug_str := 'Returning S from Get_Edu_Info.';
5345 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5346 	END IF;
5347    RETURN 'S';
5348 
5349 EXCEPTION
5350 
5351    WHEN FND_API.G_EXC_ERROR THEN
5352 
5353       Put_Log_Msg(l_api_name||' EXEC ERROR ',0);
5354 	/* Debug */
5355 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5356 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Edu_Info';
5357 	  l_debug_str := 'FND_API.G_EXC_ERROR: Returning U from Get_Edu_Info. '||SQLERRM;
5358 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5359 	END IF;
5360 
5361       RETURN 'U';
5362 
5363    WHEN OTHERS THEN
5364 
5365       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
5366          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
5367       END IF;
5368 
5369       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
5370       /* Debug */
5371 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5372 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Edu_Info';
5373 	  l_debug_str := 'EXCEPTION: Returning U from Get_Edu_Info. '||SQLERRM;
5374 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5375 	END IF;
5376       RETURN  'U';
5377 
5378 END Get_Edu_Info;
5379 
5380 
5381 
5382 
5383 /******************************************************************
5384    Created By         : Arkadi Tereshenkov
5385 
5386    Date Created By    : Oct 14, 2002
5387 
5388    Purpose            : Get Finance information on the student
5389                         (IGS_SV_FINANCE_INFO)
5390 
5391    Remarks            :
5392 
5393    Change History
5394    Who                  When            What
5395 ------------------------------------------------------------------------
5396 
5397 ******************************************************************/
5398 FUNCTION Get_Finance_Info (
5399    p_data_rec  IN OUT NOCOPY  IGS_SV_FINANCE_INFO%ROWTYPE    -- Data record
5400 )  RETURN VARCHAR2  -- 'S' Record found, 'N' - not found. 'U' - Unexpected error
5401 IS
5402 
5403    l_api_name CONSTANT VARCHAR2(25) := 'Get_Finance_Info';
5404 
5405    CURSOR c_data_rec IS
5406      SELECT acad_term_length       ,
5407             tuition                ,
5408             living_exp             ,
5409             personal_funds         ,
5410             dependent_exp          ,
5411             other_exp              ,
5412             other_exp_desc         ,
5413             school_funds           ,
5414             school_funds_desc      ,
5415             other_funds            ,
5416             other_funds_desc       ,
5417             program_sponsor        ,
5418             govt_org1              ,
5419             govt_org2              ,
5420             govt_org1_code         ,
5421             govt_org2_code         ,
5422             intl_org1              ,
5423             intl_org2              ,
5424             intl_org1_code         ,
5425             intl_org2_code         ,
5426             ev_govt                ,
5427             bi_natnl_com           ,
5428             other_org              ,
5429             remarks		   ,
5430 	    govt_org1_othr_name    ,
5431 	    govt_org2_othr_name    ,
5432             intl_org1_othr_name    ,
5433             intl_org2_othr_name    ,
5434 	    other_govt_name	   ,
5435 	    empl_funds
5436        FROM igs_sv_finance_info cr
5437       WHERE cr.person_id = p_data_rec.person_id
5438         AND cr.batch_id IN
5439             (  SELECT max(prs.batch_id)
5440                  FROM igs_sv_finance_info prs,
5441                      igs_sv_persons pr
5442                WHERE prs.person_id = pr.person_id
5443                      AND prs.batch_id = pr.batch_id
5444                      AND pr.record_status <> 'E'
5445                      AND prs.person_id = p_data_rec.person_id
5446             );
5447 BEGIN
5448 
5449    Put_Log_Msg(l_api_name||' begins ',0);
5450 	/* Debug */
5451 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5452 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Finance_Info';
5453 	   l_debug_str := 'Entering Get_Finance_Info. p_data_rec.person_id is '||p_data_rec.person_id;
5454 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5455 	END IF;
5456 
5457    OPEN c_data_rec;
5458    FETCH c_data_rec
5459     INTO p_data_rec.acad_term_length       ,
5460          p_data_rec.tuition                ,
5461          p_data_rec.living_exp             ,
5462          p_data_rec.personal_funds         ,
5463          p_data_rec.dependent_exp          ,
5464          p_data_rec.other_exp              ,
5465          p_data_rec.other_exp_desc         ,
5466          p_data_rec.school_funds           ,
5467          p_data_rec.school_funds_desc      ,
5468          p_data_rec.other_funds            ,
5469          p_data_rec.other_funds_desc       ,
5470          p_data_rec.program_sponsor        ,
5471          p_data_rec.govt_org1              ,
5472          p_data_rec.govt_org2              ,
5473          p_data_rec.govt_org1_code         ,
5474          p_data_rec.govt_org2_code         ,
5475          p_data_rec.intl_org1              ,
5476          p_data_rec.intl_org2              ,
5477          p_data_rec.intl_org1_code         ,
5478          p_data_rec.intl_org2_code         ,
5479          p_data_rec.ev_govt                ,
5480          p_data_rec.bi_natnl_com           ,
5481          p_data_rec.other_org              ,
5482          p_data_rec.remarks                ,
5483 	 p_data_rec.govt_org1_othr_name    ,
5484 	 p_data_rec.govt_org2_othr_name    ,
5485          p_data_rec.intl_org1_othr_name    ,
5486          p_data_rec.intl_org2_othr_name    ,
5487 	 p_data_rec.other_govt_name	   ,
5488 	 p_data_rec.empl_funds	;
5489 
5490    IF c_data_rec%NOTFOUND THEN
5491 
5492       Put_Log_Msg('Record not found ',0);
5493       CLOSE c_data_rec;
5494       /* Debug */
5495 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5496 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Finance_Info';
5497 	  l_debug_str := 'Returning N from Get_Finance_Info.';
5498 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5499 	END IF;
5500       RETURN 'N';
5501 
5502    END IF;
5503 
5504    CLOSE c_data_rec;
5505 
5506    Put_Log_Msg(l_api_name||' ends S ',0);
5507 	/* Debug */
5508 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5509 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Finance_Info';
5510 	  l_debug_str := 'Returning S from Get_Finance_Info.';
5511 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5512 	END IF;
5513    RETURN 'S';
5514 
5515 EXCEPTION
5516 
5517    WHEN FND_API.G_EXC_ERROR THEN
5518 
5519       Put_Log_Msg(l_api_name||' EXEC ERROR ',0);
5520       /* Debug */
5521 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5522 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Finance_Info';
5523 	  l_debug_str := 'FND_API.G_EXC_ERROR: Returning U from Get_Finance_Info. '||SQLERRM;
5524 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5525 	END IF;
5526       RETURN 'U';
5527 
5528    WHEN OTHERS THEN
5529 
5530       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
5531          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
5532       END IF;
5533 
5534       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
5535       /* Debug */
5536 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5537 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Finance_Info';
5538 	  l_debug_str := 'EXCEPTION: Returning U from Get_Finance_Info. '||SQLERRM;
5539 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5540 	END IF;
5541       RETURN  'U';
5542 
5543 END Get_Finance_Info;
5544 
5545 
5546 
5547 /******************************************************************
5548    Created By         : Arkadi Tereshenkov
5549 
5550    Date Created By    : Oct 14, 2002
5551 
5552    Purpose            : Get the student dependent information.
5553                         (IGS_SV_DEPDNT_INFO)
5554 
5555    Remarks            :
5556 
5557    Change History
5558    Who                  When            What
5559 ------------------------------------------------------------------------
5560 
5561 ******************************************************************/
5562 FUNCTION Get_Dependent_Info (
5563    p_data_rec  IN OUT NOCOPY  IGS_SV_DEPDNT_INFO%ROWTYPE     -- Data record
5564 )   RETURN VARCHAR2  -- 'S' Record found, 'N' - not found. 'U' - Unexpected error
5565 IS
5566 
5567    l_api_name CONSTANT VARCHAR2(25) := 'Get_Dependent_Info';
5568 
5569    CURSOR c_data_rec IS
5570      SELECT depdnt_action_type       ,
5571             depdnt_sevis_id        ,
5572             last_name              ,
5573             first_name             ,
5574             middle_name            ,
5575             suffix                 ,
5576             birth_date             ,
5577             gender                 ,
5578             birth_cntry_code       ,
5579             citizen_cntry_code     ,
5580             relationship           ,
5581             termination_reason     ,
5582             relationship_remarks   ,
5583             perm_res_cntry_code    ,
5584             termination_effect_date,
5585             remarks		   ,
5586 	    birth_cntry_resn_code  ,
5587 	    VISA_TYPE
5588        FROM igs_sv_depdnt_info cr
5589       WHERE cr.person_id = p_data_rec.person_id
5590         AND cr.depdnt_id = p_data_rec.depdnt_id
5591         AND cr.batch_id IN
5592             (  SELECT max(prs.batch_id)
5593                  FROM igs_sv_depdnt_info prs,
5594                      igs_sv_persons pr
5595                WHERE prs.person_id = pr.person_id
5596                      AND prs.batch_id = pr.batch_id
5597                      AND pr.record_status <> 'E'
5598                      AND prs.person_id = p_data_rec.person_id
5599                      AND prs.depdnt_id = p_data_rec.depdnt_id
5600             );
5601 
5602 BEGIN
5603    /* Debug */
5604 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5605 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Dependent_Info';
5606 	   l_debug_str := 'Entering Get_Dependent_Info. p_data_rec.person_id is '||p_data_rec.person_id||' and p_data_rec.depdnt_id is '||p_data_rec.depdnt_id;
5607 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5608 	END IF;
5609    Put_Log_Msg(l_api_name||' begins ',0);
5610 
5611    OPEN c_data_rec;
5612    FETCH c_data_rec
5613     INTO p_data_rec.depdnt_action_type       ,
5614          p_data_rec.depdnt_sevis_id        ,
5615          p_data_rec.last_name              ,
5616          p_data_rec.first_name             ,
5617          p_data_rec.middle_name            ,
5618          p_data_rec.suffix                 ,
5619          p_data_rec.birth_date             ,
5620          p_data_rec.gender                 ,
5621          p_data_rec.birth_cntry_code       ,
5622          p_data_rec.citizen_cntry_code     ,
5623          p_data_rec.relationship           ,
5624          p_data_rec.termination_reason     ,
5625          p_data_rec.relationship_remarks   ,
5626          p_data_rec.perm_res_cntry_code    ,
5627          p_data_rec.termination_effect_date,
5628          p_data_rec.remarks		   ,
5629 	 p_data_rec.birth_cntry_resn_code  ,
5630 	 p_data_rec.VISA_TYPE              ;
5631 
5632    IF c_data_rec%NOTFOUND THEN
5633 
5634       Put_Log_Msg('Record not found ',0);
5635       CLOSE c_data_rec;
5636       /* Debug */
5637 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5638 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Dependent_Info';
5639 	  l_debug_str := 'Returning N from Get_Dependent_Info.';
5640 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5641 	END IF;
5642       RETURN 'N';
5643 
5644    END IF;
5645 
5646    CLOSE c_data_rec;
5647 
5648    Put_Log_Msg(l_api_name||' ends S ',0);
5649    /* Debug */
5650 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5651 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Dependent_Info';
5652 	  l_debug_str := 'Returning S from Get_Dependent_Info.';
5653 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5654 	END IF;
5655    RETURN 'S';
5656 
5657 EXCEPTION
5658 
5659    WHEN FND_API.G_EXC_ERROR THEN
5660       Put_Log_Msg(l_api_name||' EXEC ERROR ',0);
5661       /* Debug */
5662 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5663 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Dependent_Info';
5664 	  l_debug_str := 'FND_API.G_EXC_ERROR: Returning U from Get_Dependent_Info. '||SQLERRM;
5665 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5666 	END IF;
5667       RETURN 'U';
5668 
5669    WHEN OTHERS THEN
5670       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
5671          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
5672       END IF;
5673 
5674       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
5675       /* Debug */
5676 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5677 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Dependent_Info';
5678 	  l_debug_str := 'EXCEPTION: Returning U from Get_Dependent_Info. '||SQLERRM;
5679 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5680 	END IF;
5681       RETURN  'U';
5682 
5683 END Get_Dependent_Info;
5684 
5685 
5686 
5687 /******************************************************************
5688    Created By         : Arkadi Tereshenkov
5689 
5690    Date Created By    : Oct 14, 2002
5691 
5692    Purpose            : Get the legal information for the student.
5693                         (IGS_SV_LEGAL_INFO).
5694 
5695    Remarks            :
5696 
5697    Change History
5698    Who                  When            What
5699 ------------------------------------------------------------------------
5700 
5701 ******************************************************************/
5702 FUNCTION Get_Legal_Info (
5703    p_data_rec   IN OUT NOCOPY  IGS_SV_LEGAL_INFO%ROWTYPE    -- Data record
5704 )   RETURN VARCHAR2  -- 'S' Record found, 'N' - not found. 'U' - Unexpected error
5705 IS
5706    l_api_name CONSTANT VARCHAR2(25) := 'Get_Legal_Info';
5707 
5708    CURSOR c_data_rec IS
5709      SELECT psprt_number           ,
5710             psprt_issuing_cntry_code,
5711             psprt_exp_date         ,
5712             visa_number            ,
5713             visa_issuing_post      ,
5714             visa_issuing_cntry_code,
5715             visa_expiration_date   ,
5716             i94_number             ,
5717             port_of_entry          ,
5718             date_of_entry          ,
5719             remarks		   ,
5720 	    visa_issue_date
5721        FROM igs_sv_legal_info cr
5722       WHERE cr.person_id = p_data_rec.person_id
5723         AND cr.batch_id IN
5724             (  SELECT max(prs.batch_id)
5725                  FROM igs_sv_legal_info prs,
5726                      igs_sv_persons pr
5727                WHERE prs.person_id = pr.person_id
5728                      AND prs.batch_id = pr.batch_id
5729                      AND pr.record_status <> 'E'
5730                      AND prs.person_id = p_data_rec.person_id
5731             );
5732 
5733 BEGIN
5734 
5735    Put_Log_Msg(l_api_name||' begins ',0);
5736 	/* Debug */
5737 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5738 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Legal_Info';
5739 	   l_debug_str := 'Entering Get_Legal_Info. p_data_rec.person_id is '||p_data_rec.person_id;
5740 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5741 	END IF;
5742 
5743    OPEN c_data_rec;
5744    FETCH c_data_rec
5745     INTO p_data_rec.psprt_number           ,
5746          p_data_rec.psprt_issuing_cntry_code,
5747          p_data_rec.psprt_exp_date         ,
5748          p_data_rec.visa_number            ,
5749          p_data_rec.visa_issuing_post      ,
5750          p_data_rec.visa_issuing_cntry_code,
5751          p_data_rec.visa_expiration_date   ,
5752          p_data_rec.i94_number             ,
5753          p_data_rec.port_of_entry          ,
5754          p_data_rec.date_of_entry          ,
5755          p_data_rec.remarks                ,
5756 	 p_data_rec.visa_issue_date;
5757 
5758    IF c_data_rec%NOTFOUND THEN
5759 
5760       Put_Log_Msg('Record not found ',0);
5761       CLOSE c_data_rec;
5762       /* Debug */
5763 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5764 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Legal_Info';
5765 	   l_debug_str := 'Returning N from Get_Legal_Info.';
5766 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5767 	END IF;
5768       RETURN 'N';
5769 
5770    END IF;
5771 
5772    CLOSE c_data_rec;
5773 
5774    Put_Log_Msg(l_api_name||' ends S ',0);
5775 	/* Debug */
5776 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5777 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Legal_Info';
5778 	   l_debug_str := 'Returning S from Get_Legal_Info.';
5779 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5780 	END IF;
5781 
5782    RETURN 'S';
5783 
5784 EXCEPTION
5785 
5786    WHEN FND_API.G_EXC_ERROR THEN
5787 
5788       Put_Log_Msg(l_api_name||' EXEC ERROR ',0);
5789       /* Debug */
5790 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5791 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Legal_Info';
5792 	   l_debug_str := 'FND_API.G_EXC_ERROR: Returning U from Get_Legal_Info. '||SQLERRM;
5793 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5794 	END IF;
5795       RETURN 'U';
5796 
5797    WHEN OTHERS THEN
5798 
5799       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
5800          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
5801       END IF;
5802 
5803       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
5804       /* Debug */
5805 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5806 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_Legal_Info';
5807 	   l_debug_str := 'EXCEPTION: Returning U from Get_Legal_Info. '||SQLERRM;
5808 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5809 	END IF;
5810       RETURN  'U';
5811 
5812 END Get_Legal_Info;
5813 
5814 
5815 /******************************************************************
5816    Created By         : Arkadi Tereshenkov
5817 
5818    Date Created By    : Oct 14, 2002
5819 
5820    Purpose            : Updating of person issue information block
5821                         (IGS_SV_PERSONS).
5822 
5823    Remarks            :
5824 
5825    Change History
5826    Who                  When            What
5827 ------------------------------------------------------------------------
5828 
5829 ******************************************************************/
5830 PROCEDURE Update_Issue_Info (
5831    p_data_rec  IN IGS_SV_PERSONS%ROWTYPE   -- Data record
5832 )
5833 IS
5834 
5835    l_api_name CONSTANT VARCHAR(30) := 'Update_Issue_Info';
5836 
5837 BEGIN
5838 /* Debug */
5839 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5840    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Issue_Info';
5841    l_debug_str := 'Entering Update_Issue_Info. p_data_rec.person_id is '||p_data_rec.person_id|| ' and p_data_rec.batch_id is '||p_data_rec.batch_id;
5842    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5843 END IF;
5844 
5845    UPDATE IGS_SV_PERSONS
5846       SET issuing_reason         = p_data_rec.issuing_reason,
5847           curr_session_end_date  = p_data_rec.curr_session_end_date ,
5848           next_session_start_date= p_data_rec.next_session_start_date ,
5849           other_reason           = p_data_rec.other_reason ,
5850           transfer_from_school   = p_data_rec.transfer_from_school ,
5851           ev_create_reason       = p_data_rec.ev_create_reason ,
5852           ev_form_number         = p_data_rec.ev_form_number,
5853           init_prgm_start_date   = p_data_rec.init_prgm_start_date,
5854 	  no_show_flag		 = p_data_rec.no_show_flag,
5855 	  last_session_flag	 = p_data_rec.last_session_flag,
5856 	  adjudicated_flag       = p_data_rec.adjudicated_flag
5857     WHERE batch_id = p_data_rec.batch_id
5858       AND person_id = p_data_rec.person_id
5859       AND record_number = p_data_rec.record_number;
5860 
5861 EXCEPTION
5862 
5863   WHEN OTHERS THEN
5864 
5865       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
5866          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
5867       END IF;
5868 	/* Debug */
5869 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5870 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Issue_Info';
5871 	   l_debug_str := 'EXCEPTION in Update_Issue_Info. '||SQLERRM;
5872 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5873 	END IF;
5874       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
5875 
5876       RAISE;
5877 
5878 END Update_Issue_Info;
5879 
5880 
5881 
5882 /******************************************************************
5883    Created By         : Arkadi Tereshenkov
5884 
5885    Date Created By    : Oct 14, 2002
5886 
5887    Purpose            : Insert Bio information block.
5888                         (IGS_SV_BIO_INFO).
5889 
5890    Remarks            :
5891 
5892    Change History
5893    Who                  When            What
5894 ------------------------------------------------------------------------
5895 
5896 ******************************************************************/
5897 PROCEDURE Insert_Bio_Info(
5898    p_data_rec  IN  IGS_SV_BIO_INFO%ROWTYPE    -- Data record
5899 )
5900 IS
5901    l_api_name CONSTANT VARCHAR(30) := 'Insert_Bio_Info';
5902 
5903 BEGIN
5904 /* Debug */
5905 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5906    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Bio_Info';
5907    l_debug_str := 'Entering Insert_Bio_Info. p_data_rec.person_id is '||p_data_rec.person_id|| ' and p_data_rec.batch_id is '||p_data_rec.batch_id;
5908    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5909 END IF;
5910     Insert_Summary_Info(p_data_rec.batch_id,
5911 		       p_data_rec.person_id,
5912 		       g_person_status,
5913 		       'SV_BIO',
5914 		       'SEND',
5915 		       'IGS_SV_BIO_INFO',
5916 		       '');
5917    INSERT INTO IGS_SV_BIO_INFO (
5918        batch_id               ,
5919        person_id              ,
5920        print_form             ,
5921        birth_date             ,
5922        birth_cntry_code       ,
5923        birth_city             ,
5924        citizen_cntry_code     ,
5925        last_name              ,
5926        middle_name            ,
5927        first_name             ,
5928        suffix                 ,
5929        gender                 ,
5930        legal_res_cntry_code   ,
5931        position_code          ,
5932        category_code          ,
5933        remarks                ,
5934        commuter               ,
5935        visa_type              ,
5936        creation_date          ,
5937        created_by             ,
5938        last_updated_by        ,
5939        last_update_date       ,
5940        last_update_login      ,
5941        birth_cntry_resn_code
5942      ) VALUES
5943      (
5944        p_data_rec.batch_id               ,
5945        p_data_rec.person_id              ,
5946        p_data_rec.print_form             ,
5947        p_data_rec.birth_date             ,
5948        p_data_rec.birth_cntry_code       ,
5949        p_data_rec.birth_city             ,
5950        p_data_rec.citizen_cntry_code     ,
5951        p_data_rec.last_name              ,
5952        p_data_rec.middle_name            ,
5953        p_data_rec.first_name             ,
5954        p_data_rec.suffix                 ,
5955        p_data_rec.gender                 ,
5956        p_data_rec.legal_res_cntry_code   ,
5957        p_data_rec.position_code          ,
5958        p_data_rec.category_code          ,
5959        p_data_rec.remarks                ,
5960        p_data_rec.commuter               ,
5961        p_data_rec.visa_type              ,
5962        p_data_rec.creation_date          ,
5963        p_data_rec.created_by             ,
5964        p_data_rec.last_updated_by        ,
5965        p_data_rec.last_update_date       ,
5966        p_data_rec.last_update_login      ,
5967        p_data_rec.birth_cntry_resn_code
5968      );
5969 
5970 EXCEPTION
5971 
5972   WHEN OTHERS THEN
5973       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
5974          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
5975       END IF;
5976       /* Debug */
5977 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
5978 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Bio_Info';
5979 	   l_debug_str := 'EXCEPTION in Insert_Bio_Info. '||SQLERRM;
5980 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
5981 	END IF;
5982       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
5983       RAISE;
5984 
5985 END Insert_Bio_Info;
5986 
5987 
5988 
5989 /******************************************************************
5990    Created By         : Arkadi Tereshenkov
5991 
5992    Date Created By    : Oct 14, 2002
5993 
5994    Purpose            : Insert Other information block
5995                         (IGS_SV_OTH_INFO)
5996 
5997    remarks            :
5998 
5999    Change History
6000    Who                  When            What
6001 ------------------------------------------------------------------------
6002 
6003 ******************************************************************/
6004 PROCEDURE Insert_Other_Info (
6005    p_data_rec  IN IGS_SV_OTH_INFO%ROWTYPE    -- Data record
6006 )
6007 IS
6008 
6009    l_api_name CONSTANT VARCHAR(30) := 'Insert_Other_Info';
6010 
6011 BEGIN
6012    /* Debug */
6013 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
6014    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Other_Info';
6015    l_debug_str := 'Entering Insert_Other_Info. p_data_rec.person_id is '||p_data_rec.person_id|| ' and p_data_rec.batch_id is '||p_data_rec.batch_id;
6016    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
6017 END IF;
6018    Insert_Summary_Info(p_data_rec.batch_id,
6019 		       p_data_rec.person_id,
6020 		       g_person_status,
6021 		       'SV_OTHER',
6022 		       'SEND',
6023 		       'IGS_SV_OTH_INFO',
6024 		       '');
6025 
6026    INSERT INTO IGS_SV_OTH_INFO (
6027        batch_id               ,
6028        person_id              ,
6029        print_form             ,
6030        drivers_license        ,
6031        drivers_license_state  ,
6032        ssn                    ,
6033        tax_id                 ,
6034        creation_date          ,
6035        created_by             ,
6036        last_updated_by        ,
6037        last_update_date       ,
6038        last_update_login
6039       ) VALUES
6040       (p_data_rec.batch_id               ,
6041        p_data_rec.person_id              ,
6042        p_data_rec.print_form             ,
6043        p_data_rec.drivers_license        ,
6044        p_data_rec.drivers_license_state  ,
6045        p_data_rec.ssn                    ,
6046        p_data_rec.tax_id                 ,
6047        p_data_rec.creation_date          ,
6048        p_data_rec.created_by             ,
6049        p_data_rec.last_updated_by        ,
6050        p_data_rec.last_update_date       ,
6051        p_data_rec.last_update_login
6052       );
6053 
6054 EXCEPTION
6055 
6056   WHEN OTHERS THEN
6057       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
6058          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
6059       END IF;
6060 
6061 /* Debug */
6062 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
6063    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Other_Info';
6064    l_debug_str := 'EXCEPTION in Insert_Other_Info. '||SQLERRM;
6065    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
6066 END IF;
6067       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
6068 
6069       RAISE;
6070 
6071 END Insert_Other_Info;
6072 
6073 
6074 
6075 /******************************************************************
6076    Created By         : Arkadi Tereshenkov
6077 
6078    Date Created By    : Oct 14, 2002
6079 
6080    Purpose            : Insert site of activity information.
6081                         (IGS_SV_ADDRESSES).
6082 
6083    Remarks            :
6084 
6085    Change History
6086    Who                  When            What
6087 ------------------------------------------------------------------------
6088 
6089 ******************************************************************/
6090 PROCEDURE Insert_Address_Info (
6091    p_addr_type IN VARCHAR,  -- Address type bein inserted- US, Foreign, Site of Activity
6092    p_data_rec  IN  g_address_rec_type ,  -- Data record
6093    p_records  IN  NUMBER   -- number of addressees found
6094 )
6095 IS
6096    l_api_name CONSTANT VARCHAR(30) := 'Insert_Address_Info';
6097    l_count  NUMBER(10);
6098    l_action VARCHAR2(10);
6099    l_btch_id NUMBER(14);
6100    l_remarks  VARCHAR2(500);
6101 BEGIN
6102 /* Debug */
6103 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
6104    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Address_Info';
6105    l_debug_str := 'Entering Insert_Address_Info. Number of records: '||p_records;
6106    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
6107 END IF;
6108 
6109    FOR l_count IN 1..p_records LOOP
6110      IF p_data_rec(l_count).batch_id IS NOT NULL THEN
6111 
6112        IF p_addr_type = 'SOA' THEN
6113 	   IF g_person_status = 'NEW' THEN
6114                  l_action := g_person_status;
6115 	   ELSIF p_data_rec(l_count).action_type = 'A' THEN
6116 	         l_action := 'ADD';
6117 	   ELSIF p_data_rec(l_count).action_type = 'D' THEN
6118 	         l_action := 'DELETE';
6119 	   ELSE
6120 	         l_action := 'EDIT';
6121 	   END IF;
6122 	   l_remarks := p_data_rec(l_count).remarks;
6123 	   l_btch_id := chk_mut_exclusive(p_data_rec(l_count).batch_id,
6124 				       p_data_rec(l_count).person_id,
6125 				       l_action,
6126 				       'SV_SOA');
6127 
6128 	   Insert_Summary_Info(l_btch_id,
6129 				       p_data_rec(l_count).person_id,
6130 				       l_action,
6131 				       'SV_SOA',
6132 				       'SEND',
6133 				       'IGS_SV_ADDRESSES',
6134 				       p_data_rec(l_count).party_site_id);
6135        ELSE
6136           l_remarks := null;
6137           l_btch_id := p_data_rec(l_count).batch_id;
6138 	  IF p_addr_type = 'US' THEN
6139 		Insert_Summary_Info(l_btch_id,
6140 		       p_data_rec(l_count).person_id,
6141 		       g_person_status,
6142 		       'SV_US_ADDR',
6143 		       'SEND',
6144 		       'IGS_SV_ADDRESSES',
6145 		       p_data_rec(l_count).party_site_id);
6146           ELSE
6147 	         Insert_Summary_Info(l_btch_id,
6148 		       p_data_rec(l_count).person_id,
6149 		       g_person_status,
6150 		       'SV_F_ADDR',
6151 		       'SEND',
6152 		       'IGS_SV_ADDRESSES',
6153 		       p_data_rec(l_count).party_site_id);
6154           END IF;
6155        END IF;
6156 
6157        INSERT INTO igs_sv_addresses (
6158        batch_id               ,
6159        person_id              ,
6160        party_site_id          ,
6161        print_form             ,
6162        address_type           ,
6163        address_line1          ,
6164        address_line2          ,
6165        city                   ,
6166        state                  ,
6167        postal_code            ,
6168        postal_routing_code    ,
6169        country_code           ,
6170        province               ,
6171        stdnt_valid_flag       ,
6172        creation_date          ,
6173        created_by             ,
6174        last_updated_by        ,
6175        last_update_date       ,
6176        last_update_login      ,
6177        action_type	      ,
6178        primary_flag           ,
6179        activity_site_cd       ,
6180        remarks
6181      ) VALUES (
6182        l_btch_id              ,
6183        p_data_rec(l_count).person_id              ,
6184        p_data_rec(l_count).party_site_id          ,
6185        p_data_rec(l_count).print_form             ,
6186        p_data_rec(l_count).address_type           ,
6187        p_data_rec(l_count).address_line1          ,
6188        p_data_rec(l_count).address_line2          ,
6189        p_data_rec(l_count).city                   ,
6190        p_data_rec(l_count).state                  ,
6191        p_data_rec(l_count).postal_code            ,
6192        p_data_rec(l_count).postal_routing_code    ,
6193        p_data_rec(l_count).country_code           ,
6194        p_data_rec(l_count).province               ,
6195        p_data_rec(l_count).stdnt_valid_flag       ,
6196        p_data_rec(l_count).creation_date          ,
6197        p_data_rec(l_count).created_by             ,
6198        p_data_rec(l_count).last_updated_by        ,
6199        p_data_rec(l_count).last_update_date       ,
6200        p_data_rec(l_count).last_update_login	  ,
6201        p_data_rec(l_count).action_type		  ,
6202        p_data_rec(l_count).primary_flag           ,
6203        p_data_rec(l_count).activity_site_cd       ,
6204        l_remarks
6205      );
6206      END IF;
6207 
6208    END LOOP;
6209 
6210 EXCEPTION
6211 
6212   WHEN OTHERS THEN
6213       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
6214          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
6215       END IF;
6216 
6217 	/* Debug */
6218 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
6219 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Address_Info';
6220 	   l_debug_str := 'EXCEPTION in Insert_Address_Info. '||SQLERRM;
6221 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
6222 	END IF;
6223       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
6224       RAISE;
6225 
6226 END Insert_Address_Info;
6227 
6228 
6229 
6230 /******************************************************************
6231    Created By         : Arkadi Tereshenkov
6232 
6233    Date Created By    : Oct 14, 2002
6234 
6235    Purpose            : Insert education information on the student
6236                         (IGS_SV_PRGMS_INFO).
6237 
6238    Remarks            :
6239 
6240    Change History
6241    Who                  When            What
6242 ------------------------------------------------------------------------
6243 
6244 ******************************************************************/
6245 PROCEDURE Insert_Edu_Info (
6246    p_edu_type  IN VARCHAR2,
6247    p_data_rec  IN IGS_SV_PRGMS_INFO%ROWTYPE,
6248    p_auth_drp_data_rec IN IGS_SV_PRGMS_INFO%ROWTYPE
6249 )
6250 IS
6251 
6252    l_api_name CONSTANT VARCHAR(30) := 'Insert_Edu_Info';
6253    l_count  NUMBER(10);
6254    l_action VARCHAR2(30);
6255    l_btch_id NUMBER(14);
6256    l_tag_code VARCHAR2(30);
6257    l_edu_status  VARCHAR2(10);
6258    l_cur_rec  IGS_SV_PRGMS_INFO%ROWTYPE;
6259 
6260    l_education_level            igs_pe_nonimg_form.education_level%TYPE;
6261    l_primary_major              igs_pe_nonimg_form.primary_major%TYPE;
6262    l_secondary_major            igs_pe_nonimg_form.secondary_major%TYPE;
6263    l_minor                      igs_pe_nonimg_form.minor%TYPE;
6264    l_length_of_study            igs_pe_nonimg_form.length_of_study%TYPE;
6265    l_prgm_start_date            igs_Sv_prgms_info.prgm_start_date%TYPE;
6266    l_prgm_end_date              igs_Sv_prgms_info.prgm_end_date%TYPE;
6267    l_english_reqd               igs_pe_nonimg_form.english_reqd%TYPE;
6268    l_english_reqd_met           igs_pe_nonimg_form.english_reqd_met%TYPE;
6269    l_not_reqd_reason            igs_pe_nonimg_form.not_reqd_reason%TYPE;
6270    l_educ_lvl_remarks           igs_pe_nonimg_form.educ_lvl_remarks%TYPE;
6271    l_position_code              igs_pe_ev_form.position_code%TYPE;
6272    l_subject_field_code         igs_pe_ev_form.subject_field_code%TYPE;
6273    l_remarks			igs_pe_ev_form.subject_field_remarks%TYPE;
6274 
6275 BEGIN
6276      /* Debug */
6277     IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
6278 	l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Edu_Info';
6279 	l_debug_str := 'Entering Insert_Edu_Info. p_data_rec.person_id is '||p_data_rec.person_id|| ' and p_data_rec.batch_id is '||p_data_rec.batch_id;
6280 	fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
6281     END IF;
6282        l_position_code         := p_data_rec.position_code;
6283        l_subject_field_code    := p_data_rec.subject_field_code;
6284        l_remarks               := p_data_rec.remarks;
6285        l_education_level       := p_data_rec.education_level;
6286        l_primary_major         := p_data_rec.primary_major;
6287        l_secondary_major       := p_data_rec.secondary_major;
6288        l_educ_lvl_remarks      := p_data_rec.educ_lvl_remarks;
6289        l_minor		       := p_data_rec.minor;
6290        l_length_of_study       := p_data_rec.length_of_study;
6291        l_english_reqd	       := p_data_rec.english_reqd;
6292        l_english_reqd_met      := p_data_rec.english_reqd_met;
6293        l_not_reqd_reason       := p_data_rec.not_reqd_reason;
6294        l_prgm_start_date       := p_data_rec.prgm_start_date;
6295        l_prgm_end_date         := p_data_rec.prgm_end_date;
6296 
6297        /* Debug */
6298     IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
6299 	l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Edu_Info';
6300 	l_debug_str := 'After assigning values to local variables';
6301 	fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
6302     END IF;
6303     -- Nonimg action types:
6304      -- C  Complete Program
6305      -- T  Terminate Program
6306      -- D  Defer program
6307      -- E  Extend program
6308     -- EV action types:
6309      -- AP  Amend Program
6310      -- AF  Approve Failure
6311      -- CF  Conclude Failure
6312      -- EE Exchange Visitor Extension
6313      -- ED End Program
6314      -- EM Matriculation
6315      -- EF Extend Failure
6316      -- OI Other Infraction
6317      -- TR Terminate Exchange Visitor
6318      IF p_edu_type = 'PRGM' THEN
6319 	  IF p_data_rec.prgm_action_type = 'C' THEN
6320 	      l_action := 'COMPLETE';
6321 	      l_tag_code := 'SV_STATUS';
6322 	   ELSIF p_data_rec.prgm_action_type = 'CE' THEN
6323 	      l_action := 'CANCEL_EXTENSION';
6324 	      l_tag_code := 'SV_PRGMS';
6325 	   ELSIF p_data_rec.prgm_action_type = 'T' OR p_data_rec.prgm_action_type = 'TR' THEN
6326 	      l_action := 'TERMINATE';
6327 	      l_tag_code := 'SV_STATUS';
6328 	   ELSIF p_data_rec.prgm_action_type = 'D' THEN
6329 	      l_action := 'DEFER';
6330 	      l_tag_code := 'SV_PRGMS';
6331 	   ELSIF p_data_rec.prgm_action_type = 'E' OR p_data_rec.prgm_action_type = 'EE' THEN
6332 	      l_action := 'EXTENSION';
6333 	      l_tag_code := 'SV_PRGMS';
6334 	   ELSIF p_data_rec.prgm_action_type = 'S' OR p_data_rec.prgm_action_type = 'SP' THEN
6335 	      l_action := 'SHORTEN';
6336 	      l_tag_code := 'SV_PRGMS';
6337 	   ELSIF p_data_rec.prgm_action_type = 'EP' THEN
6338 	      l_action := 'EDIT';
6339 	      l_tag_code := 'SV_PRGMS';
6340            ELSIF p_data_rec.prgm_action_type = 'CP' THEN
6341 	      l_action := 'CANCEL';
6342 	      l_tag_code := 'SV_STATUS';
6343 	   ELSIF p_data_rec.prgm_action_type = 'AP' THEN
6344 	      l_action := 'AMEND';
6345 	      l_tag_code := 'SV_PRGMS';
6346 	   ELSIF p_data_rec.prgm_action_type = 'US' THEN
6347 	      l_action := 'EDIT_SUBJECT';
6348 	      l_tag_code := 'SV_PRGMS';
6349 	   ELSIF p_data_rec.prgm_action_type = 'EM' THEN
6350 	      l_action := 'MATRICULATE';
6351 	      l_tag_code := 'SV_PRGMS';
6352 	   ELSIF p_data_rec.prgm_action_type = 'ED' THEN
6353 	      l_action := 'END';
6354 	      l_tag_code := 'SV_STATUS';
6355 	   ELSIF p_data_rec.prgm_action_type = 'DB' THEN
6356 	      l_action := p_data_rec.auth_action_code;
6357 	      l_tag_code := 'SV_AUTH_DROP';
6358 	  /* ELSIF p_data_rec.prgm_action_type = 'AF' THEN
6359 	      l_action := 'APPROVE_FAILURE';
6360 	      l_tag_code := 'SV_PRGMS';
6361 	   ELSIF p_data_rec.prgm_action_type = 'CF' THEN
6362 	      l_action := 'CONCLUDE_FAILURE';
6363 	      l_tag_code := 'SV_PRGMS';
6364 	   ELSIF p_data_rec.prgm_action_type = 'EF' THEN
6365 	      l_action := 'EXTEND_FAILURE';
6366 	      l_tag_code := 'SV_PRGMS';*/
6367 	   ELSE
6368 	      l_action := 'CORRECT_INFRACTION';
6369 	      l_tag_code := 'SV_STATUS';
6370 	   END IF;
6371 
6372 	   IF g_person_status = 'NEW' THEN
6373 	       l_action := g_person_status;
6374 	   END IF;
6375 	   l_btch_id := chk_mut_exclusive(p_data_rec.batch_id,
6376 				       p_data_rec.person_id,
6377 				       l_action,
6378 				       l_tag_code);
6379 	   Insert_Summary_Info(l_btch_id,
6380 				       p_data_rec.person_id,
6381 				       l_action,
6382 				       l_tag_code,
6383 				       'SEND',
6384 				       'IGS_SV_PRGMS_INFO',
6385 				       p_data_rec.prgm_action_type);
6386 
6387           l_cur_rec.person_id := p_data_rec.person_id;
6388 	  l_edu_status  := Get_Othr_Prgm_Info (p_data_rec   => l_cur_rec);
6389 	  IF l_edu_status = 'S' THEN
6390 	       l_position_code       := l_cur_rec.position_code;
6391 	       l_subject_field_code  := l_cur_rec.subject_field_code ;
6392 	       l_education_level     := l_cur_rec.education_level;
6393 	       l_primary_major       := l_cur_rec.primary_major;
6394 	       l_secondary_major     := l_cur_rec.secondary_major;
6395 	       l_educ_lvl_remarks    := l_cur_rec.educ_lvl_remarks ;
6396 	       l_minor               := l_cur_rec.minor ;
6397 	       l_length_of_study     := l_cur_rec.length_of_study ;
6398 	       l_english_reqd        := l_cur_rec.english_reqd;
6399 	       l_english_reqd_met    := l_cur_rec.english_reqd_met ;
6400 	       l_not_reqd_reason     := l_cur_rec.not_reqd_reason;
6401 	       IF p_data_rec.remarks IS NULL THEN
6402 	            l_remarks := l_cur_rec.remarks;
6403 	       END IF;
6404 	       IF p_data_rec.prgm_start_date IS NULL THEN
6405 	            l_prgm_start_date  := l_cur_rec.prgm_start_date;
6406 	       END IF;
6407                IF p_data_rec.prgm_end_date IS NULL THEN
6408 	            l_prgm_end_date  := l_cur_rec.prgm_end_date;
6409 	       END IF;
6410 		  /* Debug */
6411 	    IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
6412 		l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Edu_Info';
6413 		l_debug_str := 'After assigning values received from get_othr_prgm_info to local variables';
6414 		fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
6415 	    END IF;
6416 	  END IF;
6417 
6418      ELSE
6419           l_btch_id := p_data_rec.batch_id;
6420      END IF;
6421      IF p_edu_type = 'EDU' THEN
6422 	  IF g_person_status = 'NEW' THEN
6423 		l_action := g_person_status;
6424 	   ELSE
6425 	        l_action := 'EDIT';
6426            END IF;
6427 	  Insert_Summary_Info(l_btch_id,
6428 			       p_data_rec.person_id,
6429 			       l_action,
6430 			       'SV_PRGMS',
6431 			       'SEND',
6432 			       'IGS_SV_PRGMS_INFO',
6433 			       p_data_rec.prgm_action_type);
6434      END IF;
6435 
6436    INSERT INTO igs_sv_prgms_info (
6437         batch_id               ,
6438         person_id              ,
6439         prgm_action_type       ,
6440         print_form             ,
6441         form_status_id         ,
6442         position_code          ,
6443         subject_field_code     ,
6444         education_level        ,
6445         primary_major          ,
6446         secondary_major        ,
6447         educ_lvl_remarks       ,
6448         minor                  ,
6449         length_of_study        ,
6450         prgm_start_date        ,
6451         prgm_end_date          ,
6452         english_reqd           ,
6453         english_reqd_met       ,
6454         not_reqd_reason        ,
6455         matriculation          ,
6456         effective_date         ,
6457         authorization_reason   ,
6458         termination_reason     ,
6459         end_prgm_reason        ,
6460         reprint_reason         ,
6461         submit_update          ,
6462         remarks                ,
6463         creation_date          ,
6464         created_by             ,
6465         last_updated_by        ,
6466         last_update_date       ,
6467         last_update_login      ,
6468 	auth_action_code
6469       ) VALUES
6470       ( l_btch_id                        ,
6471        p_data_rec.person_id              ,
6472        p_data_rec.prgm_action_type       ,
6473        p_data_rec.print_form             ,
6474        p_data_rec.form_status_id         ,
6475        l_position_code          ,
6476        l_subject_field_code     ,
6477        l_education_level        ,
6478        l_primary_major          ,
6479        l_secondary_major        ,
6480        l_educ_lvl_remarks       ,
6481        l_minor                  ,
6482        l_length_of_study        ,
6483        l_prgm_start_date        ,
6484        l_prgm_end_date          ,
6485        l_english_reqd           ,
6486        l_english_reqd_met       ,
6487        l_not_reqd_reason        ,
6488        p_data_rec.matriculation          ,
6489        p_data_rec.effective_date         ,
6490        p_data_rec.authorization_reason   ,
6491        p_data_rec.termination_reason     ,
6492        p_data_rec.end_prgm_reason        ,
6493        p_data_rec.reprint_reason         ,
6494        p_data_rec.submit_update          ,
6495        l_remarks                ,
6496        p_data_rec.creation_date          ,
6497        p_data_rec.created_by             ,
6498        p_data_rec.last_updated_by        ,
6499        p_data_rec.last_update_date       ,
6500        p_data_rec.last_update_login      ,
6501        p_data_rec.auth_action_code
6502       );
6503       /* Debug */
6504     IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
6505 	l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Edu_Info';
6506 	l_debug_str := 'Record inserted';
6507 	fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
6508     END IF;
6509       IF p_edu_type = 'PRGM' THEN
6510           IF p_auth_drp_data_rec.prgm_action_type = 'DB' THEN
6511 	       UPDATE igs_sv_prgms_info
6512 		SET authorization_reason =p_auth_drp_data_rec.authorization_reason,
6513 		    auth_action_code = p_auth_drp_data_rec.auth_action_code,
6514 		    prgm_start_date = p_auth_drp_data_rec.prgm_start_date,
6515 		    prgm_end_date = p_auth_drp_data_rec.prgm_end_date,
6516 		    remarks = p_auth_drp_data_rec.remarks,
6517 		    prgm_action_type = 'DB'
6518 		WHERE batch_id = l_btch_id
6519 		      AND person_id = p_data_rec.person_id;
6520           END IF;
6521       END IF;
6522 
6523 EXCEPTION
6524 
6525   WHEN OTHERS THEN
6526       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
6527          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
6528       END IF;
6529 
6530 /* Debug */
6531 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
6532    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Edu_Info';
6533    l_debug_str := 'EXCEPTION in Insert_Edu_Info. '||SQLERRM;
6534    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
6535 END IF;
6536       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
6537 
6538       RAISE;
6539 
6540 END Insert_Edu_Info;
6541 
6542 
6543 
6544 /******************************************************************
6545    Created By         : Arkadi Tereshenkov
6546 
6547    Date Created By    : Oct 14, 2002
6548 
6549    Purpose            : Insert Finance information on the student
6550                         (IGS_SV_FINANCE_INFO)
6551 
6552    Remarks            :
6553 
6554    Change History
6555    Who                  When            What
6556 ------------------------------------------------------------------------
6557 
6558 ******************************************************************/
6559 PROCEDURE Insert_Finance_Info (
6560    p_data_rec  IN IGS_SV_FINANCE_INFO %ROWTYPE    -- Data record
6561 )
6562 IS
6563 
6564    l_api_name CONSTANT VARCHAR(30) := 'Insert_Finance_Info';
6565 
6566 BEGIN
6567 /* Debug */
6568 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
6569    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Finance_Info';
6570    l_debug_str := 'Entering Insert_Finance_Info. p_data_rec.person_id is '||p_data_rec.person_id|| ' and p_data_rec.batch_id is '||p_data_rec.batch_id;
6571    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
6572 END IF;
6573    Insert_Summary_Info(p_data_rec.batch_id,
6574 		       p_data_rec.person_id,
6575 		       g_person_status,
6576 		       'SV_FINANCIAL',
6577 		       'SEND',
6578 		       'IGS_SV_FINANCE_INFO',
6579 		       '');
6580    INSERT INTO igs_sv_finance_info (
6581        batch_id               ,
6582        person_id              ,
6583        print_form             ,
6584        acad_term_length       ,
6585        tuition                ,
6586        living_exp             ,
6587        personal_funds         ,
6588        dependent_exp          ,
6589        other_exp              ,
6590        other_exp_desc         ,
6591        school_funds           ,
6592        school_funds_desc      ,
6593        other_funds            ,
6594        other_funds_desc       ,
6595        program_sponsor        ,
6596        govt_org1              ,
6597        govt_org2              ,
6598        govt_org1_code         ,
6599        govt_org2_code         ,
6600        intl_org1              ,
6601        intl_org2              ,
6602        intl_org1_code         ,
6603        intl_org2_code         ,
6604        ev_govt                ,
6605        bi_natnl_com           ,
6606        other_org              ,
6607        recvd_us_gvt_funds     ,
6608        remarks                ,
6609        creation_date          ,
6610        created_by             ,
6611        last_updated_by        ,
6612        last_update_date       ,
6613        last_update_login      ,
6614        govt_org1_othr_name    ,
6615        govt_org2_othr_name    ,
6616        intl_org1_othr_name    ,
6617        intl_org2_othr_name    ,
6618        other_govt_name	      ,
6619        empl_funds
6620       ) VALUES
6621       (p_data_rec.batch_id               ,
6622        p_data_rec.person_id              ,
6623        p_data_rec.print_form             ,
6624        p_data_rec.acad_term_length       ,
6625        p_data_rec.tuition                ,
6626        p_data_rec.living_exp             ,
6627        p_data_rec.personal_funds         ,
6628        p_data_rec.dependent_exp          ,
6629        p_data_rec.other_exp              ,
6630        p_data_rec.other_exp_desc         ,
6631        p_data_rec.school_funds           ,
6632        p_data_rec.school_funds_desc      ,
6633        p_data_rec.other_funds            ,
6634        p_data_rec.other_funds_desc       ,
6635        p_data_rec.program_sponsor        ,
6636        p_data_rec.govt_org1              ,
6637        p_data_rec.govt_org2              ,
6638        p_data_rec.govt_org1_code         ,
6639        p_data_rec.govt_org2_code         ,
6640        p_data_rec.intl_org1              ,
6641        p_data_rec.intl_org2              ,
6642        p_data_rec.intl_org1_code         ,
6643        p_data_rec.intl_org2_code         ,
6644        p_data_rec.ev_govt                ,
6645        p_data_rec.bi_natnl_com           ,
6646        p_data_rec.other_org              ,
6647        p_data_rec.recvd_us_gvt_funds     ,
6648        p_data_rec.remarks                ,
6649        p_data_rec.creation_date          ,
6650        p_data_rec.created_by             ,
6651        p_data_rec.last_updated_by        ,
6652        p_data_rec.last_update_date       ,
6653        p_data_rec.last_update_login	 ,
6654        p_data_rec.govt_org1_othr_name    ,
6655        p_data_rec.govt_org2_othr_name    ,
6656        p_data_rec.intl_org1_othr_name    ,
6657        p_data_rec.intl_org2_othr_name    ,
6658        p_data_rec.other_govt_name	 ,
6659        p_data_rec.empl_funds
6660       );
6661 
6662 EXCEPTION
6663 
6664   WHEN OTHERS THEN
6665       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
6666          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
6667       END IF;
6668 
6669 /* Debug */
6670 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
6671    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Finance_Info';
6672    l_debug_str := 'EXCEPTION in Insert_Finance_Info. '||SQLERRM;
6673    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
6674 END IF;
6675       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
6676 
6677       RAISE;
6678 
6679 END Insert_Finance_Info;
6680 
6681 
6682 
6683 /******************************************************************
6684    Created By         : Arkadi Tereshenkov
6685 
6686    Date Created By    : Oct 14, 2002
6687 
6688    Purpose            : Insert dependent information on the student
6689                         (IGS_SV_DEPDNT_INFO).
6690 
6691    Remarks            :
6692 
6693    Change History
6694    Who                  When            What
6695 ------------------------------------------------------------------------
6696 
6697 ******************************************************************/
6698 PROCEDURE Insert_Dependent_Info (
6699    p_data_rec  IN g_dependent_rec_type,    -- Data record
6700    p_records   IN NUMBER    --Number  of dependents found
6701 )
6702 IS
6703 
6704    l_api_name CONSTANT VARCHAR(30) := 'Insert_Dependent_Info';
6705    l_count  NUMBER(10);
6706    l_action VARCHAR2(10);
6707    l_btch_id NUMBER(14);
6708 BEGIN
6709 /* Debug */
6710 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
6711    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Dependent_Info';
6712    l_debug_str := 'Entering Insert_Dependent_Info.Number of records being inserted: '||p_records;
6713    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
6714 END IF;
6715    FOR l_count IN 1..p_records LOOP
6716      IF p_data_rec(l_count).depdnt_id  IS NOT NULL  THEN
6717 	   IF g_person_status = 'NEW' THEN
6718 	       l_action := g_person_status;
6719 	   ELSIF p_data_rec(l_count).depdnt_action_type = 'A' THEN
6720 	      l_action := 'ADD';
6721 	   ELSIF p_data_rec(l_count).depdnt_action_type = 'U' THEN
6722 	      l_action := 'EDIT';
6723 	   ELSIF p_data_rec(l_count).depdnt_action_type = 'T' THEN
6724 	      l_action := 'TERMINATE';
6725 	   ELSIF p_data_rec(l_count).depdnt_action_type = 'C' THEN
6726 	      l_action := 'CANCEL';
6727 	   ELSIF p_data_rec(l_count).depdnt_action_type = 'R' THEN
6728 	      l_action := 'REACTIVATE';
6729 	   ELSIF p_data_rec(l_count).depdnt_action_type = 'E' THEN
6730 	      l_action := 'END';
6731 	  -- ELSIF p_data_rec(l_count).print_form = 'Y' THEN
6732 	     -- l_action := 'REPRINT';
6733 	   ELSE
6734 	      l_action := 'DELETE';
6735 	   END IF;
6736 
6737 	   l_btch_id := chk_mut_exclusive(p_data_rec(l_count).batch_id,
6738 				       p_data_rec(l_count).person_id,
6739 				       l_action,
6740 				       'SV_DEPDNT');
6741 	   Insert_Summary_Info(l_btch_id,
6742 				       p_data_rec(l_count).person_id,
6743 				       l_action,
6744 				       'SV_DEPDNT',
6745 				       'SEND',
6746 				       'IGS_SV_DEPDNT_INFO',
6747 				       p_data_rec(l_count).depdnt_id);
6748 
6749        INSERT INTO igs_sv_depdnt_info (
6750           batch_id               ,
6751           person_id              ,
6752           depdnt_id              ,
6753           print_form             ,
6754           person_number          ,
6755           depdnt_action_type     ,
6756           depdnt_sevis_id        ,
6757           visa_type              ,
6758           last_name              ,
6759           first_name             ,
6760           middle_name            ,
6761           suffix                 ,
6762           birth_date             ,
6763           gender                 ,
6764           birth_cntry_code       ,
6765           citizen_cntry_code     ,
6766           relationship           ,
6767           termination_reason     ,
6768           relationship_remarks   ,
6769           perm_res_cntry_code    ,
6770           termination_effect_date,
6771           remarks                ,
6772           creation_date          ,
6773           created_by             ,
6774           last_updated_by        ,
6775           last_update_date       ,
6776           last_update_login	 ,
6777 	  birth_cntry_resn_code
6778          ) VALUES
6779          (l_btch_id              ,  -- prbhardw CP enhancement
6780           p_data_rec(l_count).person_id              ,
6781           p_data_rec(l_count).depdnt_id              ,
6782           p_data_rec(l_count).print_form             ,
6783           p_data_rec(l_count).person_number          ,
6784           p_data_rec(l_count).depdnt_action_type     ,
6785           p_data_rec(l_count).depdnt_sevis_id        ,
6786           p_data_rec(l_count).visa_type              ,
6787           p_data_rec(l_count).last_name              ,
6788           p_data_rec(l_count).first_name             ,
6789           p_data_rec(l_count).middle_name            ,
6790           p_data_rec(l_count).suffix                 ,
6791           p_data_rec(l_count).birth_date             ,
6792           p_data_rec(l_count).gender                 ,
6793           p_data_rec(l_count).birth_cntry_code       ,
6794           p_data_rec(l_count).citizen_cntry_code     ,
6795           p_data_rec(l_count).relationship           ,
6796           p_data_rec(l_count).termination_reason     ,
6797           p_data_rec(l_count).relationship_remarks   ,
6798           p_data_rec(l_count).perm_res_cntry_code    ,
6799           p_data_rec(l_count).termination_effect_date,
6800           p_data_rec(l_count).remarks                ,
6801           p_data_rec(l_count).creation_date          ,
6802           p_data_rec(l_count).created_by             ,
6803           p_data_rec(l_count).last_updated_by        ,
6804           p_data_rec(l_count).last_update_date       ,
6805           p_data_rec(l_count).last_update_login	     ,
6806 	  p_data_rec(l_count).birth_cntry_resn_code
6807          );
6808      END IF;
6809    END LOOP;
6810 
6811 EXCEPTION
6812 
6813   WHEN OTHERS THEN
6814       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
6815          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
6816       END IF;
6817 	/* Debug */
6818 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
6819 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Dependent_Info';
6820 	   l_debug_str := 'EXCEPTION in Insert_Dependent_Info. '||SQLERRM;
6821 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
6822 	END IF;
6823       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
6824 
6825       RAISE;
6826 
6827 END Insert_Dependent_Info;
6828 
6829 /******************************************************************
6830    Created By         : Arkadi Tereshenkov
6831 
6832    Date Created By    : Oct 14, 2002
6833 
6834    Purpose            : Insert Conviction information on the student.
6835                         (IGS_SV_CONVICTIONS).
6836 
6837    Remarks            :
6838 
6839    Change History
6840    Who                  When            What
6841 ------------------------------------------------------------------------
6842 
6843 ******************************************************************/
6844 PROCEDURE Insert_Convictions_Info (
6845    p_data_rec  IN IGS_SV_CONVICTIONS%ROWTYPE
6846 ) IS
6847 
6848    l_api_name CONSTANT VARCHAR(30) := 'Insert_Convictions_Info';
6849    l_count  NUMBER(10);
6850 
6851 BEGIN
6852 	/* Debug */
6853 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
6854 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Convictions_Info';
6855 	   l_debug_str := 'Entering Insert_Convictions_Info. p_data_rec.person_id is '||p_data_rec.person_id|| ' and p_data_rec.batch_id is '||p_data_rec.batch_id;
6856 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
6857 	END IF;
6858        Insert_Summary_Info(p_data_rec.batch_id,
6859 		       p_data_rec.person_id,
6860 		       g_person_status,
6861 		       'SV_CONVICTION',
6862 		       'SEND',
6863 		       'IGS_SV_CONVICTIONS',
6864 		       '');
6865        INSERT INTO igs_sv_convictions (
6866         batch_id               ,
6867         person_id              ,
6868         conviction_id          ,
6869         print_form             ,
6870         criminal_conviction    ,
6871         remarks                ,
6872         creation_date          ,
6873         created_by             ,
6874         last_updated_by        ,
6875         last_update_date       ,
6876         last_update_login
6877        ) VALUES
6878        (p_data_rec.batch_id               ,
6879         p_data_rec.person_id              ,
6880         p_data_rec.conviction_id          ,
6881         p_data_rec.print_form             ,
6882         p_data_rec.criminal_conviction    ,
6883         p_data_rec.remarks                ,
6884         p_data_rec.creation_date          ,
6885         p_data_rec.created_by             ,
6886         p_data_rec.last_updated_by        ,
6887         p_data_rec.last_update_date       ,
6888         p_data_rec.last_update_login
6889        );
6890 
6891 EXCEPTION
6892 
6893   WHEN OTHERS THEN
6894       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
6895          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
6896       END IF;
6897 
6898 	/* Debug */
6899 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
6900 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Convictions_Info';
6901 	   l_debug_str := 'EXCEPTION in Insert_Convictions_Info. '||SQLERRM;
6902 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
6903 	END IF;
6904       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
6905 
6906       RAISE;
6907 
6908 END Insert_Convictions_Info;
6909 
6910 /******************************************************************
6911    Created By         : Arkadi Tereshenkov
6912 
6913    Date Created By    : Oct 14, 2002
6914 
6915    Purpose            : Insert Legal information on the student.
6916                         (IGS_SV_LEGAL_INFO).
6917 
6918    Remarks            :
6919 
6920    Change History
6921    Who                  When            What
6922 ------------------------------------------------------------------------
6923 
6924 ******************************************************************/
6925 PROCEDURE Insert_Legal_Info (
6926    p_data_rec   IN IGS_SV_LEGAL_INFO%ROWTYPE    -- Data record
6927 )
6928 IS
6929    l_api_name CONSTANT VARCHAR(30) := 'Insert_Legal_Info';
6930 
6931 BEGIN
6932 	/* Debug */
6933 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
6934 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Legal_Info';
6935 	   l_debug_str := 'Entering Insert_Legal_Info. p_data_rec.person_id is '||p_data_rec.person_id|| ' and p_data_rec.batch_id is '||p_data_rec.batch_id;
6936 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
6937 	END IF;
6938    Insert_Summary_Info(p_data_rec.batch_id,
6939 		       p_data_rec.person_id,
6940 		       g_person_status,
6941 		       'SV_LEGAL',
6942 		       'SEND',
6943 		       'IGS_SV_LEGAL_INFO',
6944 		       '');
6945    INSERT INTO igs_sv_legal_info (
6946        batch_id               ,
6947        person_id              ,
6948        print_form             ,
6949        psprt_number           ,
6950        psprt_issuing_cntry_code,
6951        psprt_exp_date         ,
6952        visa_number            ,
6953        visa_issuing_post      ,
6954        visa_issuing_cntry_code,
6955        visa_expiration_date   ,
6956        i94_number             ,
6957        port_of_entry          ,
6958        date_of_entry          ,
6959        remarks                ,
6960        creation_date          ,
6961        created_by             ,
6962        last_updated_by        ,
6963        last_update_date       ,
6964        last_update_login      ,
6965        VISA_ISSUE_DATE
6966       ) VALUES
6967       (p_data_rec.batch_id               ,
6968        p_data_rec.person_id              ,
6969        p_data_rec.print_form             ,
6970        p_data_rec.psprt_number           ,
6971        p_data_rec.psprt_issuing_cntry_code,
6972        p_data_rec.psprt_exp_date         ,
6973        p_data_rec.visa_number            ,
6974        p_data_rec.visa_issuing_post      ,
6975        p_data_rec.visa_issuing_cntry_code,
6976        p_data_rec.visa_expiration_date   ,
6977        p_data_rec.i94_number             ,
6978        p_data_rec.port_of_entry          ,
6979        p_data_rec.date_of_entry          ,
6980        p_data_rec.remarks                ,
6981        p_data_rec.creation_date          ,
6982        p_data_rec.created_by             ,
6983        p_data_rec.last_updated_by        ,
6984        p_data_rec.last_update_date       ,
6985        p_data_rec.last_update_login      ,
6986        p_data_rec.VISA_ISSUE_DATE
6987       );
6988 
6989 EXCEPTION
6990 
6991   WHEN OTHERS THEN
6992       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
6993          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
6994       END IF;
6995 
6996 /* Debug */
6997 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
6998    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Legal_Info';
6999    l_debug_str := 'EXCEPTION in Insert_Legal_Info. '||SQLERRM;
7000    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7001 END IF;
7002       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
7003 
7004       RAISE;
7005 
7006 END Insert_Legal_Info;
7007 
7008 /******************************************************************
7009    Created By         : Arkadi Tereshenkov
7010 
7011    Date Created By    : Oct 14, 2002
7012 
7013    Purpose            : Insert employment information on the student
7014                         (IGS_SV_EMPL_INFO).
7015 
7016    Remarks            :
7017 
7018    Change History
7019    Who                  When            What
7020 ------------------------------------------------------------------------
7021 
7022 ******************************************************************/
7023 PROCEDURE Insert_Empl_Info (
7024    p_data_rec      IN IGS_SV_EMPL_INFO%ROWTYPE     --Data record
7025 )
7026 IS
7027    l_api_name CONSTANT VARCHAR(30) := 'Insert_Empl_Info';
7028    l_action VARCHAR2(6);
7029    l_tag_code VARCHAR2(30);
7030    l_btch_id NUMBER(14);
7031 BEGIN
7032 /* Debug */
7033 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7034    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Empl_Info';
7035    l_debug_str := 'Entering Insert_Empl_Info. p_data_rec.person_id is '||p_data_rec.person_id|| ' and p_data_rec.batch_id is '||p_data_rec.batch_id;
7036    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7037 END IF;
7038    IF g_person_status = 'NEW' THEN
7039       l_action := g_person_status;
7040    ELSIF p_data_rec.action_code = 'C' THEN
7041       l_action := 'CANCEL';
7042    ELSIF p_data_rec.action_code = 'A' OR p_data_rec.empl_rec_type = 'C' OR p_data_rec.empl_rec_type = 'O' THEN
7043       l_action := 'ADD';
7044    ELSE
7045       l_action := 'EDIT';
7046    END IF;
7047    IF p_data_rec.empl_rec_type = 'C' THEN
7048       l_tag_code := 'SV_CPT_EMPL';
7049    ELSIF p_data_rec.empl_rec_type = 'O' THEN
7050       l_tag_code := 'SV_OPT_EMPL';
7051    ELSE
7052       l_tag_code := 'SV_OFF_EMPL';
7053    END IF;
7054 
7055    l_btch_id := chk_mut_exclusive(p_data_rec.batch_id,
7056 			       p_data_rec.person_id,
7057 			       l_action,
7058 			       l_tag_code);
7059    Insert_Summary_Info(l_btch_id,
7060 			       p_data_rec.person_id,
7061 			       l_action,
7062 			       l_tag_code,
7063 			       'SEND',
7064 			       'IGS_SV_EMPL_INFO',
7065 			       p_data_rec.nonimg_empl_id);
7066    /* Debug */
7067         IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7068           l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Employment_Info';
7069           l_debug_str := 'mut_exclusive chk returns '||l_btch_id||' for batch: '||p_data_rec.batch_id||'person: '||p_data_rec.person_id||' action: '||l_action||' tag: '||l_tag_code;
7070           fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7071         END IF;
7072 
7073    INSERT INTO igs_sv_empl_info (
7074        batch_id               ,
7075        person_id              ,
7076        nonimg_empl_id         ,
7077        empl_rec_type          ,
7078        print_form             ,
7079        empl_type              ,
7080        recommend_empl         ,
7081        rescind_empl           ,
7082        remarks                ,
7083        empl_start_date        ,
7084        empl_end_date          ,
7085        empl_name              ,
7086        empl_time              ,
7087        course_relevance       ,
7088        empl_addr_line1        ,
7089        empl_addr_line2        ,
7090        city                   ,
7091        state                  ,
7092        postal_code            ,
7093        creation_date          ,
7094        created_by             ,
7095        last_updated_by        ,
7096        last_update_date       ,
7097        last_update_login      ,
7098        action_code
7099       ) VALUES
7100       (l_btch_id               ,    --- prbhardw CP enhancement
7101        p_data_rec.person_id              ,
7102        p_data_rec.nonimg_empl_id         ,
7103        p_data_rec.empl_rec_type          ,
7104        p_data_rec.print_form             ,
7105        p_data_rec.empl_type              ,
7106        p_data_rec.recommend_empl         ,
7107        p_data_rec.rescind_empl           ,
7108        p_data_rec.remarks                ,
7109        p_data_rec.empl_start_date        ,
7110        p_data_rec.empl_end_date          ,
7111        p_data_rec.empl_name              ,
7112        p_data_rec.empl_time              ,
7113        p_data_rec.course_relevance       ,
7114        p_data_rec.empl_addr_line1        ,
7115        p_data_rec.empl_addr_line2        ,
7116        p_data_rec.city                   ,
7117        p_data_rec.state                  ,
7118        p_data_rec.postal_code            ,
7119        p_data_rec.creation_date          ,
7120        p_data_rec.created_by             ,
7121        p_data_rec.last_updated_by        ,
7122        p_data_rec.last_update_date       ,
7123        p_data_rec.last_update_login	 ,
7124        p_data_rec.action_code
7125       );
7126 
7127 EXCEPTION
7128 
7129   WHEN OTHERS THEN
7130       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
7131          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
7132       END IF;
7133 	/* Debug */
7134 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7135    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Empl_Info';
7136    l_debug_str := 'EXCEPTION in Insert_Empl_Info. '||SQLERRM;
7137    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7138 END IF;
7139       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
7140 
7141       RAISE;
7142 
7143 END Insert_Empl_Info;
7144 
7145 
7146 
7147 /******************************************************************
7148    Created By         : Arkadi Tereshenkov
7149 
7150    Date Created By    : Oct 14, 2002
7151 
7152    Purpose            : Update registration block information.
7153 
7154    remarks            :
7155 
7156    Change History
7157    Who                  When            What
7158 ------------------------------------------------------------------------
7159 
7160 ******************************************************************/
7161 FUNCTION Update_Registration_Info (
7162    p_person_rec      IN OUT NOCOPY t_student_rec    --Person record
7163 ) RETURN VARCHAR2
7164 IS
7165 
7166    l_api_name    CONSTANT VARCHAR2(30)   := 'Update_Registration_Info';
7167 
7168    l_cur_rec     IGS_SV_LEGAL_INFO%ROWTYPE;
7169    l_status      VARCHAR2(1);
7170 
7171    l_prev_rec     IGS_SV_LEGAL_INFO%ROWTYPE;
7172 
7173 
7174   -- Old dates
7175    CURSOR c_old_ses_dates IS
7176      SELECT pr.curr_session_end_date,
7177             pr.next_session_start_date,
7178 	    pr.last_session_flag
7179        FROM igs_sv_persons pr
7180       WHERE pr.person_id = p_person_rec.person_id
7181         AND pr.batch_id IN
7182             ( SELECT max(btch.batch_id)
7183                 FROM igs_sv_persons prs,
7184                      igs_sv_batches btch,
7185                      igs_sv_persons pr
7186                WHERE prs.person_id = pr.person_id
7187                      AND prs.batch_id = pr.batch_id
7188                      AND pr.record_status <> 'E'
7189                      AND prs.batch_id = btch.batch_id
7190                      AND btch.batch_type = p_person_rec.batch_type
7191                      AND prs.person_id = p_person_rec.person_id
7192                      AND pr.curr_session_end_date  IS NOT NULL
7193             );
7194 
7195   -- Select current session dates.
7196    CURSOR c_ses_dates IS
7197      SELECT to_char(curr_session_end_date,'YYYY-MM-DD') ,
7198             to_char(next_session_start_date ,'YYYY-MM-DD'),
7199 	    last_session_flag
7200        FROM igs_pe_nonimg_form
7201       WHERE nonimg_form_id = p_person_rec.form_id;
7202 
7203    l_start_date      igs_sv_persons.curr_session_end_date%TYPE;
7204    l_end_date        igs_sv_persons.next_session_start_date%TYPE;
7205    l_old_start_date  igs_sv_persons.curr_session_end_date%TYPE;
7206    l_old_end_date    igs_sv_persons.next_session_start_date%TYPE;
7207    l_old_session_flag  igs_pe_nonimg_form.last_session_flag%TYPE;
7208    l_last_session_flag  igs_pe_nonimg_form.last_session_flag%TYPE;
7209    l_f_addr_rec      g_address_rec_type;
7210    l_count           NUMBER(10);
7211    l_changes_found   VARCHAR2(1) := 'N'; --No changes by default
7212 
7213 
7214 BEGIN
7215 /* Debug */
7216 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7217    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Registration_Info';
7218    l_debug_str := 'Entering Update_Registration_Info. p_person_rec.person_id is '||p_person_rec.person_id|| ' and p_person_rec.batch_type is '||p_person_rec.batch_type;
7219    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7220 END IF;
7221 
7222    Put_Log_Msg(l_api_name||' begins ',0);
7223 
7224 
7225    --Get current dates
7226    OPEN c_ses_dates;
7227    FETCH c_ses_dates
7228     INTO l_start_date,
7229          l_end_date,
7230 	 l_last_session_flag;
7231    CLOSE c_ses_dates;
7232 
7233    -- Get old dates
7234    OPEN c_old_ses_dates;
7235    FETCH c_old_ses_dates
7236     INTO l_old_start_date,
7237          l_old_end_date,
7238 	 l_old_session_flag;
7239    CLOSE c_old_ses_dates;
7240 
7241 
7242    -- Call Validate_Legal_Info
7243 
7244    p_person_rec.legal_status  := Validate_Legal_Info (p_person_rec => p_person_rec,
7245                                                        p_data_rec   => l_cur_rec);
7246 
7247 
7248    IF p_person_rec.legal_status = 'E'  THEN -- Validation error - mark person as invalid
7249 
7250       p_person_rec.person_status := 'I';
7251 
7252       Put_Log_Msg('Validation error occurs ',0);
7253 	/* Debug */
7254 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7255 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Registration_Info';
7256 	   l_debug_str := 'Returning S from Update_Registration_Info.';
7257 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7258 	END IF;
7259 
7260       RETURN 'S';
7261 
7262    ELSIF p_person_rec.legal_status = 'U' THEN --Unexpected error - terminate execution
7263 
7264       Put_Log_Msg('Unexpected error returned by validation ',0);
7265       /* Debug */
7266 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7267 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Registration_Info';
7268 	   l_debug_str := 'Unexpected error in Update_Registration_Info.';
7269 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7270 	END IF;
7271 
7272       RAISE FND_API.G_EXC_ERROR;
7273 
7274    ELSIF p_person_rec.legal_status = 'S' THEN
7275 
7276 
7277      -- Compare ancial Info
7278      l_prev_rec.person_id := p_person_rec.person_id;
7279 
7280      l_status := Get_Legal_Info ( p_data_rec  => l_prev_rec);
7281 
7282      IF l_status = 'U' THEN
7283 	/* Debug */
7284 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7285 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Registration_Info';
7286 	   l_debug_str := 'RAISE FND_API.G_EXC_ERROR in Update_Registration_Info.';
7287 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7288 	END IF;
7289 
7290         RAISE FND_API.G_EXC_ERROR;
7291 
7292      END IF;
7293 
7294      IF l_status = 'N' OR
7295       ( l_prev_rec.psprt_number
7296         ||g_delimeter||l_prev_rec.psprt_issuing_cntry_code
7297         ||g_delimeter||l_prev_rec.psprt_exp_date
7298         ||g_delimeter||l_prev_rec.visa_number
7299         ||g_delimeter||l_prev_rec.visa_issuing_post
7300         ||g_delimeter||l_prev_rec.visa_issuing_cntry_code
7301         ||g_delimeter||l_prev_rec.visa_expiration_date
7302         ||g_delimeter||l_prev_rec.i94_number
7303         ||g_delimeter||l_prev_rec.port_of_entry
7304         ||g_delimeter||l_prev_rec.date_of_entry
7305         ||g_delimeter||l_prev_rec.remarks
7306 	||g_delimeter||l_prev_rec.visa_issue_date  <>
7307         l_cur_rec.psprt_number
7308         ||g_delimeter||l_cur_rec.psprt_issuing_cntry_code
7309         ||g_delimeter||l_cur_rec.psprt_exp_date
7310         ||g_delimeter||l_cur_rec.visa_number
7311         ||g_delimeter||l_cur_rec.visa_issuing_post
7312         ||g_delimeter||l_cur_rec.visa_issuing_cntry_code
7313         ||g_delimeter||l_cur_rec.visa_expiration_date
7314         ||g_delimeter||l_cur_rec.i94_number
7315         ||g_delimeter||l_cur_rec.port_of_entry
7316         ||g_delimeter||l_cur_rec.date_of_entry
7317         ||g_delimeter||l_cur_rec.remarks
7318 	||g_delimeter||l_cur_rec.visa_issue_date ) THEN
7319 
7320         p_person_rec.legal_status := 'C';  -- Changed
7321         p_person_rec.changes_found := 'Y';
7322 
7323         Put_Log_Msg('Legal info is changed  ',0);
7324 
7325         IF p_person_rec.person_status <> 'I' THEN
7326 
7327           Insert_Legal_Info ( p_data_rec  => l_cur_rec);
7328 
7329         END IF;
7330    -- Call Validate_F_Addr_Info
7331 
7332 
7333     END IF;
7334 
7335    END IF;
7336    IF p_person_rec.legal_status = 'C' OR
7337       (  l_old_start_date <> l_start_date
7338        OR l_old_end_date <> l_end_date
7339        OR ( l_old_start_date IS NULL AND l_start_date IS NOT NULL)
7340        OR ( l_old_end_date IS NULL AND l_end_date IS NOT NULL)
7341        OR (l_old_session_flag <> l_last_session_flag)) THEN		--- prbhardw
7342 
7343     /* IF l_start_date IS NULL OR l_end_date IS NULL THEN
7344 
7345        --Error dates must be not null
7346         Put_Log_Msg('Dates are null  return S',0);
7347 
7348         FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_REG_REQD_FLD_ERR'); --Dates not found
7349         FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
7350         Put_Log_Msg(FND_MESSAGE.Get,1);
7351 
7352         p_person_rec.person_status := 'I';
7353 	/* Debug
7354 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7355 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Registration_Info';
7356 	   l_debug_str := 'Returning S from Update_Registration_Info.';
7357 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7358 	END IF;
7359 
7360         RETURN 'S';
7361 
7362      END IF;*/
7363      -- Update session dates for the main record required.
7364 
7365       UPDATE igs_sv_persons
7366          SET curr_session_end_date = l_start_date,
7367              next_session_start_date = l_end_date,
7368 	     last_session_flag = l_last_session_flag		---prbhardw
7369        WHERE person_id = p_person_rec.person_id and
7370              batch_id  = p_person_rec.batch_id;
7371 
7372        -- Check if legal info is present, not changed and hasn't beet inserted yet.
7373 
7374       p_person_rec.changes_found := 'Y';
7375 
7376       Put_Log_Msg('Legal info is changed  ',0);
7377 
7378 
7379       -- Foreign address is required
7380 
7381       p_person_rec.f_addr_status  := Validate_F_Addr_Info (p_person_rec => p_person_rec,
7382                                                            p_data_rec   => l_f_addr_rec,
7383                                                            p_records    => l_count);
7384 
7385       IF p_person_rec.f_addr_status  = 'E' THEN -- Validation error - mark person as invalid
7386 
7387         p_person_rec.person_status := 'I';
7388 
7389         Put_Log_Msg('Validation error occurs - return S ',0);
7390 	/* Debug */
7391 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7392 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Registration_Info';
7393 	   l_debug_str := 'Returning S from Update_Registration_Info.';
7394 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7395 	END IF;
7396 
7397         RETURN 'S';
7398 
7399       ELSIF p_person_rec.f_addr_status  = 'U' THEN --Unexpected error - terminate execution
7400 
7401         Put_Log_Msg('Unexpected error returned by validation ',0);
7402 
7403         RAISE FND_API.G_EXC_ERROR;
7404 
7405       ELSIF p_person_rec.f_addr_status = 'N' THEN -- Not found
7406 
7407         Put_Log_Msg('F Address block is not found return S',0);
7408 
7409         FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_REG_REQD_FLD_ERR'); --f address is not found
7410         FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', p_person_rec.person_number);
7411         Put_Log_Msg(FND_MESSAGE.Get,1);
7412 
7413         p_person_rec.person_status := 'I';
7414 	/* Debug */
7415 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7416 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Registration_Info';
7417 	   l_debug_str := 'Returning S from Update_Registration_Info.';
7418 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7419 	END IF;
7420 
7421         RETURN 'S';
7422 
7423      END IF;
7424 
7425    END IF;
7426 
7427    Put_Log_Msg(l_api_name||' ends ',0);
7428 
7429    RETURN 'S';
7430 
7431 EXCEPTION
7432 
7433    WHEN FND_API.G_EXC_ERROR THEN
7434 
7435       Put_Log_Msg(l_api_name||' EXEC_ERROR returns U',0);
7436       /* Debug */
7437 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7438 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Registration_Info';
7439 	   l_debug_str := 'FND_API.G_EXC_ERROR: Returning U from Update_Registration_Info. '||SQLERRM;
7440 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7441 	END IF;
7442       RETURN 'U';
7443 
7444    WHEN OTHERS THEN
7445 
7446       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
7447          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
7448       END IF;
7449 
7450       Put_Log_Msg(l_api_name||' OTHERS return U',0);
7451       /* Debug */
7452 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7453 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Registration_Info';
7454 	   l_debug_str := 'EXCEPTION: Returning U from Update_Registration_Info. '||SQLERRM;
7455 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7456 	END IF;
7457       RETURN  'U';
7458 
7459 END Update_Registration_Info;
7460 
7461 
7462 FUNCTION Update_ev_Legal_Info (
7463    p_person_rec      IN OUT NOCOPY t_student_rec    --Person record
7464 ) RETURN VARCHAR2
7465 IS
7466 
7467    l_api_name    CONSTANT VARCHAR2(30)   := 'Update_ev_Legal_Info';
7468 
7469    l_cur_rec     IGS_SV_LEGAL_INFO%ROWTYPE;
7470    l_status      VARCHAR2(1);
7471 
7472    l_prev_rec     IGS_SV_LEGAL_INFO%ROWTYPE;
7473 
7474    l_count           NUMBER(10);
7475    l_changes_found   VARCHAR2(1) := 'N'; --No changes by default
7476 
7477 
7478 BEGIN
7479 /* Debug */
7480 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7481    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_ev_Legal_Info';
7482    l_debug_str := 'Entering Update_ev_Legal_Info. p_person_rec.person_id is '||p_person_rec.person_id|| ' and p_person_rec.batch_type is '||p_person_rec.batch_type;
7483    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7484 END IF;
7485 
7486    Put_Log_Msg(l_api_name||' begins ',0);
7487 
7488    -- Call Validate_Legal_Info
7489 
7490    p_person_rec.legal_status  := Validate_ev_Legal_Info (p_person_rec => p_person_rec,
7491                                                        p_data_rec   => l_cur_rec);
7492 
7493    IF p_person_rec.legal_status = 'E'  THEN -- Validation error - mark person as invalid
7494 
7495       p_person_rec.person_status := 'I';
7496 
7497       Put_Log_Msg('Validation error occurs ',0);
7498 	/* Debug */
7499 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7500 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_ev_Legal_Info';
7501 	   l_debug_str := 'Returning S from Update_ev_Legal_Info.';
7502 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7503 	END IF;
7504 
7505       RETURN 'S';
7506 
7507    ELSIF p_person_rec.legal_status = 'U' THEN --Unexpected error - terminate execution
7508 
7509       Put_Log_Msg('Unexpected error returned by validation ',0);
7510       /* Debug */
7511 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7512 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_ev_Legal_Info';
7513 	   l_debug_str := 'Unexpected error in Update_ev_Legal_Info.';
7514 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7515 	END IF;
7516 
7517       RAISE FND_API.G_EXC_ERROR;
7518 
7519    ELSIF p_person_rec.legal_status = 'S' THEN
7520 
7521 
7522      -- Compare ancial Info
7523      l_prev_rec.person_id := p_person_rec.person_id;
7524 
7525      l_status := Get_Legal_Info ( p_data_rec  => l_prev_rec);
7526      IF l_status = 'U' THEN
7527 	/* Debug */
7528 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7529 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_ev_Legal_Info';
7530 	   l_debug_str := 'RAISE FND_API.G_EXC_ERROR in Update_ev_Legal_Info.';
7531 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7532 	END IF;
7533 
7534         RAISE FND_API.G_EXC_ERROR;
7535 
7536      END IF;
7537 
7538 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7539 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Previous_Legal_Info';
7540           l_debug_str :=  'psprt_issuing_cntry_code=' || l_prev_rec.psprt_issuing_cntry_code;
7541           l_debug_str := l_debug_str || 'psprt_exp_date=' || l_prev_rec.psprt_exp_date;
7542           l_debug_str := l_debug_str || 'visa_number=' || l_prev_rec.visa_number ;
7543           l_debug_str := l_debug_str || 'visa_issuing_post=' || l_prev_rec.visa_issuing_post;
7544           l_debug_str := l_debug_str || 'visa_issuing_cntry_code=' || l_prev_rec.visa_issuing_cntry_code;
7545           l_debug_str := l_debug_str || 'visa_expiration_date=' || l_prev_rec.visa_expiration_date;
7546           l_debug_str := l_debug_str || 'i94_number=' || l_prev_rec.i94_number;
7547           l_debug_str := l_debug_str || 'port_of_entry=' || l_prev_rec.port_of_entry;
7548           l_debug_str := l_debug_str || 'date_of_entry=' || l_prev_rec.date_of_entry;
7549           l_debug_str := l_debug_str || 'remarks=' || l_prev_rec.remarks;
7550           l_debug_str := l_debug_str || 'visa_issue_date=' || l_prev_rec.visa_issue_date ;
7551 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7552 	END IF;
7553 
7554 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7555 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Current_Legal_Info';
7556           l_debug_str :=  'psprt_issuing_cntry_code=' || l_cur_rec.psprt_issuing_cntry_code;
7557           l_debug_str := l_debug_str || 'psprt_exp_date=' || l_cur_rec.psprt_exp_date;
7558           l_debug_str := l_debug_str || 'visa_number=' || l_cur_rec.visa_number ;
7559           l_debug_str := l_debug_str || 'visa_issuing_post=' || l_cur_rec.visa_issuing_post;
7560           l_debug_str := l_debug_str || 'visa_issuing_cntry_code=' || l_cur_rec.visa_issuing_cntry_code;
7561           l_debug_str := l_debug_str || 'visa_expiration_date=' || l_cur_rec.visa_expiration_date;
7562           l_debug_str := l_debug_str || 'i94_number=' || l_cur_rec.i94_number;
7563           l_debug_str := l_debug_str || 'port_of_entry=' || l_cur_rec.port_of_entry;
7564           l_debug_str := l_debug_str || 'date_of_entry=' || l_cur_rec.date_of_entry;
7565           l_debug_str := l_debug_str || 'remarks=' || l_cur_rec.remarks;
7566           l_debug_str := l_debug_str || 'visa_issue_date=' || l_cur_rec.visa_issue_date ;
7567 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7568 	END IF;
7569 
7570      IF l_status = 'N' OR
7571       ( l_prev_rec.psprt_number
7572         ||g_delimeter||l_prev_rec.psprt_issuing_cntry_code
7573         ||g_delimeter||l_prev_rec.psprt_exp_date
7574         ||g_delimeter||l_prev_rec.visa_number
7575         ||g_delimeter||l_prev_rec.visa_issuing_post
7576         ||g_delimeter||l_prev_rec.visa_issuing_cntry_code
7577         ||g_delimeter||l_prev_rec.visa_expiration_date
7578         ||g_delimeter||l_prev_rec.i94_number
7579         ||g_delimeter||l_prev_rec.port_of_entry
7580         ||g_delimeter||l_prev_rec.date_of_entry
7581         ||g_delimeter||l_prev_rec.remarks
7582 	||g_delimeter||l_prev_rec.visa_issue_date <>
7583         l_cur_rec.psprt_number
7584         ||g_delimeter||l_cur_rec.psprt_issuing_cntry_code
7585         ||g_delimeter||l_cur_rec.psprt_exp_date
7586         ||g_delimeter||l_cur_rec.visa_number
7587         ||g_delimeter||l_cur_rec.visa_issuing_post
7588         ||g_delimeter||l_cur_rec.visa_issuing_cntry_code
7589         ||g_delimeter||l_cur_rec.visa_expiration_date
7590         ||g_delimeter||l_cur_rec.i94_number
7591         ||g_delimeter||l_cur_rec.port_of_entry
7592         ||g_delimeter||l_cur_rec.date_of_entry
7593         ||g_delimeter||l_cur_rec.remarks
7594 	||g_delimeter||l_cur_rec.visa_issue_date) THEN
7595 
7596         p_person_rec.legal_status := 'C';  -- Changed
7597         p_person_rec.changes_found := 'Y';
7598 
7599         Put_Log_Msg('Legal info is changed  ',0);
7600 
7601         IF p_person_rec.person_status <> 'I' THEN
7602 
7603           Insert_Legal_Info ( p_data_rec  => l_cur_rec);
7604 
7605         END IF;
7606 
7607 
7608     END IF;
7609 
7610    END IF;
7611 
7612    Put_Log_Msg(l_api_name||' ends ',0);
7613 
7614    RETURN 'S';
7615 
7616 EXCEPTION
7617 
7618    WHEN FND_API.G_EXC_ERROR THEN
7619 
7620       Put_Log_Msg(l_api_name||' EXEC_ERROR returns U',0);
7621       /* Debug */
7622 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7623 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_ev_Legal_Info';
7624 	   l_debug_str := 'FND_API.G_EXC_ERROR: Returning U from Update_ev_Legal_Info. '||SQLERRM;
7625 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7626 	END IF;
7627       RETURN 'U';
7628 
7629    WHEN OTHERS THEN
7630 
7631       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
7632          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
7633       END IF;
7634 
7635       Put_Log_Msg(l_api_name||' OTHERS return U',0);
7636       /* Debug */
7637 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7638 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_ev_Legal_Info';
7639 	   l_debug_str := 'EXCEPTION: Returning U from Update_ev_Legal_Info. '||SQLERRM;
7640 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7641 	END IF;
7642       RETURN  'U';
7643 
7644 END Update_ev_Legal_Info;
7645 
7646 /******************************************************************
7647    Created By         : Arkadi Tereshenkov
7648 
7649    Date Created By    : Oct 14, 2002
7650 
7651    Purpose            : Update registration block information.
7652 
7653    remarks            :
7654 
7655    Change History
7656    Who                  When            What
7657    pkpatel              30-JUN-2003     Bug 2908378
7658                                         Checked the status of Get_Address_Info properly.
7659 ------------------------------------------------------------------------
7660 
7661 ******************************************************************/
7662 FUNCTION Update_EV_Address_Info (
7663    p_person_rec      IN OUT NOCOPY t_student_rec    --Person record
7664 ) RETURN VARCHAR2
7665 IS
7666 
7667    l_api_name    CONSTANT VARCHAR2(30)   := 'Update_EV_Address_Info';
7668    l_status      VARCHAR2(1);
7669 
7670 
7671   -- Old dates
7672    CURSOR c_valid IS
7673      SELECT is_valid
7674        FROM igs_pe_ev_form
7675       WHERE ev_form_id = p_person_rec.form_id;
7676 
7677   -- Select current session dates.
7678 
7679    l_valid           VARCHAR2(1);
7680    l_statsite        VARCHAR2(1);
7681    l_us_addr_rec     g_address_rec_type;
7682    l_count           NUMBER(10);
7683    l_cur             NUMBER(10);
7684    l_changes_found   VARCHAR2(1) := 'N'; --No changes by default
7685    l_prev_us_addr_rec IGS_SV_ADDRESSES%ROWTYPE;
7686 
7687    l_site_addr_rec     g_address_rec_type;
7688    l_prev_site_addr_rec IGS_SV_ADDRESSES%ROWTYPE;
7689 
7690 
7691 
7692 BEGIN
7693 
7694    Put_Log_Msg(l_api_name||' begins ',0);
7695    /* Debug */
7696 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7697    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Address_Info';
7698    l_debug_str := 'Entering Update_EV_Address_Info. p_person_rec.form_id is '||p_person_rec.form_id;
7699    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7700 END IF;
7701 
7702 
7703    --Get valid flag
7704 
7705    OPEN c_valid;
7706    FETCH c_valid INTO l_valid;
7707    CLOSE c_valid;
7708 
7709    -- Foreign address is required
7710 
7711    p_person_rec.us_addr_status  := Validate_US_Addr_Info (p_person_rec => p_person_rec,
7712                                                           p_data_rec   => l_us_addr_rec,
7713                                                           p_records    => l_count);
7714 
7715 
7716    IF p_person_rec.us_addr_status  = 'E' THEN -- Validation error - mark person as invalid
7717 
7718      p_person_rec.person_status := 'I';
7719 
7720      Put_Log_Msg('Validation error occurs - return S ',0);
7721       /* Debug */
7722 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7723 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Address_Info';
7724 	   l_debug_str := 'Returning S from Update_EV_Address_Info.';
7725 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7726 	END IF;
7727 
7728      RETURN 'S';
7729 
7730    ELSIF p_person_rec.us_addr_status  = 'U' THEN --Unexpected error - terminate execution
7731 
7732      Put_Log_Msg('Unexpected error returned by validation ',0);
7733      /* Debug */
7734 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7735 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Address_Info';
7736 	   l_debug_str := 'Unexpected error in Update_EV_Address_Info.';
7737 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7738 	END IF;
7739 
7740      RAISE FND_API.G_EXC_ERROR;
7741 
7742    ELSIF p_person_rec.us_addr_status = 'N' THEN -- Not found
7743 
7744      Put_Log_Msg('US Address block is not found return S',0);
7745 
7746      FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_NO_US_ADDR_FLD_ERR'); --US address is not found
7747      Put_Log_Msg(FND_MESSAGE.Get,1);
7748 
7749      p_person_rec.person_status := 'I';
7750      /* Debug */
7751 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7752 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Address_Info';
7753 	   l_debug_str := 'Returning S from Update_EV_Address_Info.';
7754 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7755 	END IF;
7756 
7757      RETURN 'S';
7758 
7759    END IF;
7760 
7761    -- Get old record and compare
7762 
7763    l_us_addr_rec(1).STDNT_VALID_FLAG := l_valid;
7764    l_prev_us_addr_rec.party_site_id := l_us_addr_rec(1).party_site_id ;
7765    l_prev_us_addr_rec.person_id := l_us_addr_rec(1).person_id ;
7766 
7767    l_status := Get_Address_Info ( p_data_rec  => l_prev_us_addr_rec);
7768 
7769    IF l_status = 'S' THEN
7770 
7771      IF l_prev_us_addr_rec.address_line1
7772         ||g_delimeter||l_prev_us_addr_rec.address_line2
7773         ||g_delimeter||l_prev_us_addr_rec.city
7774         ||g_delimeter||l_prev_us_addr_rec.state
7775         ||g_delimeter||l_prev_us_addr_rec.postal_code
7776         ||g_delimeter||l_prev_us_addr_rec.postal_routing_code
7777         ||g_delimeter||l_prev_us_addr_rec.country_code
7778         ||g_delimeter||l_prev_us_addr_rec.province
7779       --||g_delimeter||l_prev_us_addr_rec.stdnt_valid_flag
7780         ||g_delimeter||l_prev_us_addr_rec.primary_flag <>
7781         l_us_addr_rec(1).address_line1
7782         ||g_delimeter||l_us_addr_rec(1).address_line2
7783         ||g_delimeter||l_us_addr_rec(1).city
7784         ||g_delimeter||l_us_addr_rec(1).state
7785         ||g_delimeter||l_us_addr_rec(1).postal_code
7786         ||g_delimeter||l_us_addr_rec(1).postal_routing_code
7787         ||g_delimeter||l_us_addr_rec(1).country_code
7788         ||g_delimeter||l_us_addr_rec(1).province
7789       --||g_delimeter||l_us_addr_rec(1).stdnt_valid_flag
7790         ||g_delimeter||l_us_addr_rec(1).primary_flag THEN
7791         p_person_rec.us_addr_status := 'C';  -- Changed
7792         p_person_rec.changes_found := 'Y';
7793 
7794         Put_Log_Msg('US address is changed ',0);
7795 
7796      -- 2908378 this end if was placed at the end, hence the job was errored out when there is no change in address
7797      END IF;
7798 
7799    ELSIF l_status = 'N' THEN
7800 
7801          --Not found
7802 
7803          Put_Log_Msg('US info is changed - no prev record ',0);
7804          p_person_rec.us_addr_status := 'C';
7805          p_person_rec.changes_found := 'Y';
7806 
7807    ELSE
7808          --Error found l_status = 'U'
7809 	 /* Debug */
7810 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7811 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Address_Info';
7812 	   l_debug_str := 'RAISE FND_API.G_EXC_ERROR in Update_EV_Address_Info.';
7813 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7814 	END IF;
7815          RAISE FND_API.G_EXC_ERROR;
7816 
7817    END IF;
7818 
7819    IF p_person_rec.us_addr_status  = 'C' AND p_person_rec.person_status <> 'I' THEN
7820       Insert_Address_Info ('US', p_data_rec  => l_us_addr_rec,p_records => 1);
7821    END IF;
7822    IF p_person_rec.person_status <> 'I' THEN --Check if site of activity is changed
7823 
7824 
7825      --Check site of activity
7826      p_person_rec.us_addr_status  := Validate_Site_Info (p_person_rec => p_person_rec,
7827                                                          p_data_rec   => l_site_addr_rec,
7828                                                          p_records    => l_count);
7829      IF p_person_rec.us_addr_status  = 'E' THEN -- Validation error - mark person as invalid
7830 
7831        p_person_rec.person_status := 'I';
7832 
7833        Put_Log_Msg('Validation error occurs - return S ',0);
7834        /* Debug */
7835 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7836 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Address_Info';
7837 	   l_debug_str := 'Returning S from Update_EV_Address_Info. us_addr_status is E';
7838 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7839 	END IF;
7840 
7841        RETURN 'S';
7842 
7843      ELSIF p_person_rec.us_addr_status  = 'U' THEN --Unexpected error - terminate execution
7844 
7845        Put_Log_Msg('Unexpected error returned by validation ',0);
7846        /* Debug */
7847 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7848 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Address_Info';
7849 	   l_debug_str := 'ERROR in Update_EV_Address_Info. us_addr_status is U';
7850 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7851 	END IF;
7852 
7853        RAISE FND_API.G_EXC_ERROR;
7854 
7855      ELSIF p_person_rec.us_addr_status = 'N' THEN -- Not found
7856 
7857        Put_Log_Msg('Site of activity Address block is not found return S',0);
7858        /* Debug */
7859 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7860 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Address_Info';
7861 	   l_debug_str := 'Returning S from Update_EV_Address_Info. us_addr_status is N';
7862 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7863 	END IF;
7864 
7865        RETURN 'S';
7866 
7867      END IF;
7868 
7869      -- Get old record and compare
7870      p_person_rec.site_addr_status := 'N';
7871 
7872      FOR l_cur IN 1..l_count LOOP
7873 
7874           l_prev_site_addr_rec.party_site_id := l_site_addr_rec(l_cur).party_site_id ;
7875           l_prev_site_addr_rec.person_id := l_site_addr_rec(l_cur).person_id ;
7876 
7877           l_statsite := Get_Address_Info ( p_data_rec  => l_prev_site_addr_rec);
7878 
7879           IF l_statsite = 'N' THEN
7880 
7881 		--Not found
7882 
7883                Put_Log_Msg('site info is changed - no prev record ',0);
7884                p_person_rec.site_addr_status := 'C';
7885                p_person_rec.changes_found := 'Y';
7886 
7887           ELSIF l_statsite = 'S' THEN
7888 
7889 	       IF l_prev_site_addr_rec.action_type = 'U' THEN
7890 
7891 		    l_prev_site_addr_rec.action_type := 'C';
7892 		    p_person_rec.changes_found := 'Y';
7893 	       END IF;
7894 
7895 	       IF l_site_addr_rec(l_cur).action_type ='D' AND l_prev_site_addr_rec.action_type <> 'D' THEN
7896 		    p_person_rec.site_addr_status := 'C';
7897                     p_person_rec.changes_found := 'Y';
7898 	       ELSIF l_site_addr_rec(l_cur).action_type <> 'D' AND l_prev_site_addr_rec.action_type = 'D' THEN
7899 		    p_person_rec.site_addr_status := 'C';
7900                     p_person_rec.changes_found := 'Y';
7901                ELSIF l_prev_site_addr_rec.address_line1
7902 		    ||g_delimeter||l_prev_site_addr_rec.address_line2
7903 		    ||g_delimeter||l_prev_site_addr_rec.city
7904 		    ||g_delimeter||l_prev_site_addr_rec.state
7905 		    ||g_delimeter||l_prev_site_addr_rec.postal_code
7906 		    ||g_delimeter||l_prev_site_addr_rec.postal_routing_code
7907 		    ||g_delimeter||l_prev_site_addr_rec.country_code
7908 		    ||g_delimeter||l_prev_site_addr_rec.province
7909 		    --||g_delimeter||l_prev_site_addr_rec.stdnt_valid_flag
7910 		    ||g_delimeter||l_prev_site_addr_rec.primary_flag
7911 		    ||g_delimeter||l_prev_site_addr_rec.activity_site_cd
7912 		    ||g_delimeter||l_prev_site_addr_rec.remarks  <>
7913 		    l_site_addr_rec(l_cur).address_line1
7914 		    ||g_delimeter||l_site_addr_rec(l_cur).address_line2
7915 		    ||g_delimeter||l_site_addr_rec(l_cur).city
7916 		    ||g_delimeter||l_site_addr_rec(l_cur).state
7917 		    ||g_delimeter||l_site_addr_rec(l_cur).postal_code
7918 		    ||g_delimeter||l_site_addr_rec(l_cur).postal_routing_code
7919 		    ||g_delimeter||l_site_addr_rec(l_cur).country_code
7920 		    ||g_delimeter||l_site_addr_rec(l_cur).province
7921 		    --||g_delimeter||l_site_addr_rec(l_cur).stdnt_valid_flag
7922 		    ||g_delimeter||l_site_addr_rec(l_cur).primary_flag
7923 		    ||g_delimeter||l_site_addr_rec(l_cur).activity_site_cd
7924 		    ||g_delimeter||l_site_addr_rec(l_cur).remarks THEN
7925 
7926                          p_person_rec.site_addr_status := 'C';  -- Changed
7927 			 p_person_rec.changes_found := 'Y';
7928 
7929 			 l_site_addr_rec(l_cur).action_type := 'U';
7930 
7931 			 Put_Log_Msg('site address is changed ',0);
7932 	       ELSE
7933 
7934 		    l_site_addr_rec(l_cur).batch_id :=NULL;  -- delete from insert
7935 
7936                END IF;
7937 
7938           ELSE
7939            --Error found l_statsite = 'U'
7940 		/* Debug */
7941 		IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7942 		   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Address_Info';
7943 		   l_debug_str := 'RAISE FND_API.G_EXC_ERROR in Update_EV_Address_Info.';
7944 		   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7945 		END IF;
7946 
7947            RAISE FND_API.G_EXC_ERROR;
7948 
7949           END IF;
7950 
7951          /* IF p_person_rec.changes_found = 'Y' THEN
7952           -- one address only
7953 		/* Debug
7954 		IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7955 		   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Address_Info';
7956 		   l_debug_str := 'changes_found is Y. Exiting Update_EV_Address_Info.';
7957 		   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7958 		END IF;
7959                EXIT;
7960 
7961           END IF;*/
7962 
7963      END LOOP;
7964 
7965      IF p_person_rec.site_addr_status  = 'C' AND p_person_rec.person_status <> 'I'  THEN
7966 
7967         Insert_Address_Info ('SOA', p_data_rec  => l_site_addr_rec,p_records => l_count);
7968 
7969      END IF;
7970    END IF;
7971 
7972 
7973    Put_Log_Msg(l_api_name||' ends ',0);
7974    /* Debug */
7975 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7976    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Address_Info';
7977    l_debug_str := 'Returning S from Update_EV_Address_Info.';
7978    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7979 END IF;
7980 
7981    RETURN 'S';
7982 
7983 EXCEPTION
7984 
7985    WHEN FND_API.G_EXC_ERROR THEN
7986 
7987       Put_Log_Msg(l_api_name||' EXEC_ERROR returns U',0);
7988       /* Debug */
7989 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
7990 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Address_Info';
7991 	   l_debug_str := 'FND_API.G_EXC_ERROR: Returning U from Update_EV_Address_Info. '||SQLERRM;
7992 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
7993 	END IF;
7994       RETURN 'U';
7995 
7996    WHEN OTHERS THEN
7997 
7998       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
7999          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
8000       END IF;
8001 
8002       Put_Log_Msg(l_api_name||' OTHERS return U',0);
8003       /* Debug */
8004 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8005 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Address_Info';
8006 	   l_debug_str := 'EXCEPTION: Returning U from Update_EV_Address_Info. '||SQLERRM;
8007 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8008 	END IF;
8009 
8010       RETURN  'U';
8011 
8012 END Update_EV_Address_Info;
8013 
8014 
8015 
8016 /******************************************************************
8017    Created By         : Arkadi Tereshenkov
8018 
8019    Date Created By    : Oct 14, 2002
8020 
8021    Purpose            : Update Personal information block.
8022 
8023    Remarks            : 'S' - success
8024                         'U' - Unexpected error
8025 
8026    Change History
8027    Who                  When            What
8028 ------------------------------------------------------------------------
8029 
8030 ******************************************************************/
8031 FUNCTION Update_Personal_Info (
8032    p_person_rec      IN OUT NOCOPY  t_student_rec    --Person record
8033 ) RETURN VARCHAR2
8034 IS
8035 
8036    l_api_name    CONSTANT VARCHAR2(30)   := 'Update_Personal_Info';
8037    l_bio_rec     IGS_SV_BIO_INFO%ROWTYPE;
8038    l_oth_rec     IGS_SV_OTH_INFO%ROWTYPE;
8039    l_f_addr_rec  g_address_rec_type;
8040    l_us_addr_rec g_address_rec_type;
8041    l_count          NUMBER(10);
8042    l_changes_found  VARCHAR2(1) := 'N'; --No changes by default
8043    l_status      VARCHAR2(1);
8044 
8045    l_prev_bio_rec     IGS_SV_BIO_INFO%ROWTYPE;
8046    l_prev_oth_rec     IGS_SV_OTH_INFO%ROWTYPE;
8047    l_prev_f_addr_rec  IGS_SV_ADDRESSES%ROWTYPE;
8048    l_prev_us_addr_rec IGS_SV_ADDRESSES%ROWTYPE;
8049 
8050 
8051 BEGIN
8052    /* Debug */
8053 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8054    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Personal_Info';
8055    l_debug_str := 'Entering Update_Personal_Info. p_person_rec.person_id is '||p_person_rec.person_id;
8056    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8057 END IF;
8058 
8059    Put_Log_Msg(l_api_name||' begins ',0);
8060 
8061 
8062    -- Call Validate_Bio_Info
8063 
8064    p_person_rec.bio_status  := Validate_Bio_Info (p_person_rec =>p_person_rec,
8065                                                    p_data_rec  => l_bio_rec);
8066 
8067    IF p_person_rec.batch_type = 'I' THEN
8068      -- Call Validate_Other_Info
8069 
8070      p_person_rec.other_status  := Validate_Other_Info (p_person_rec => p_person_rec,
8071                                                         p_data_rec   => l_oth_rec);
8072 
8073      -- Call Validate_F_Addr_Info
8074 
8075      p_person_rec.f_addr_status  := Validate_F_Addr_Info (p_person_rec => p_person_rec,
8076                                                           p_data_rec   => l_f_addr_rec,
8077                                                           p_records    => l_count);
8078 
8079 
8080      -- Call Validate_US_address_Info
8081 
8082      p_person_rec.us_addr_status  := Validate_Us_Addr_Info (p_person_rec => p_person_rec,
8083                                                             p_data_rec   => l_us_addr_rec,
8084                                                             p_records   => l_count);
8085 
8086    ELSE
8087 
8088      p_person_rec.other_status  := 'N';
8089      p_person_rec.f_addr_status := 'N';
8090      p_person_rec.us_addr_status  := 'N';
8091 
8092    END IF;
8093 
8094    IF p_person_rec.bio_status = 'E'
8095       OR p_person_rec.other_status = 'E'
8096       OR p_person_rec.f_addr_status  = 'E'
8097       OR p_person_rec.us_addr_status = 'E' THEN -- Validation error - mark person as invalid
8098 
8099       p_person_rec.person_status := 'I';
8100 
8101       Put_Log_Msg('UPI - Validation error occurs ',0);
8102       /* Debug */
8103 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8104 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Personal_Info';
8105 	   l_debug_str := 'Returning S from Update_Personal_Info.';
8106 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8107 	END IF;
8108 
8109       RETURN 'S';
8110 
8111    END IF;
8112 
8113    IF ( p_person_rec.bio_status = 'U'
8114       OR p_person_rec.other_status = 'U'
8115       OR p_person_rec.f_addr_status  = 'U'
8116       OR p_person_rec.us_addr_status = 'U')  THEN --Unexpected error - terminate execution
8117 
8118       Put_Log_Msg('UPI - unexpected error returned by validation ',0);
8119       /* Debug */
8120 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8121 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Personal_Info';
8122 	   l_debug_str := 'RAISE FND_API.G_EXC_ERROR in Update_Personal_Info.';
8123 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8124 	END IF;
8125 
8126       RAISE FND_API.G_EXC_ERROR;
8127 
8128    ELSIF p_person_rec.bio_status = 'N' THEN -- Not found
8129 
8130       -- These are I-20 blocks and should be found. If this happens - its a bug
8131 
8132       Put_Log_Msg('UPI BIO block is not found ',0);
8133       /* Debug */
8134 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8135 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Personal_Info';
8136 	   l_debug_str := 'IGS_SV_UNEXP_EXCPT_ERR in Update_Personal_Info. bio_status is N';
8137 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8138 	END IF;
8139 
8140 
8141 
8142       FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_UNEXP_EXCPT_ERR'); -- I-20 is missing! Unexpected error
8143       FND_MESSAGE.SET_TOKEN('BLOCK_ID',2);
8144       FND_MSG_PUB.Add;
8145 
8146       RAISE FND_API.G_EXC_ERROR;
8147 
8148    END IF;
8149 
8150    -- Compare BIO
8151    l_prev_bio_rec.person_id := l_bio_rec.person_id;
8152 
8153    l_status := Get_Bio_Info ( p_data_rec  => l_prev_bio_rec);
8154 
8155    IF l_status = 'U' THEN
8156 	/* Debug */
8157 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8158 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Personal_Info';
8159 	   l_debug_str := 'FND_API.G_EXC_ERROR in Update_Personal_Info. l_status is U';
8160 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8161 	END IF;
8162       RAISE FND_API.G_EXC_ERROR;
8163 
8164    END IF;
8165 
8166    IF l_prev_bio_rec.birth_date
8167       ||g_delimeter||l_prev_bio_rec.birth_cntry_code
8168       ||g_delimeter||l_prev_bio_rec.citizen_cntry_code
8169       ||g_delimeter||l_prev_bio_rec.last_name
8170       ||g_delimeter||l_prev_bio_rec.middle_name
8171       ||g_delimeter||l_prev_bio_rec.first_name
8172       ||g_delimeter||l_prev_bio_rec.suffix
8173       ||g_delimeter||l_prev_bio_rec.gender
8174       ||g_delimeter||l_prev_bio_rec.legal_res_cntry_code
8175       ||g_delimeter||l_prev_bio_rec.position_code
8176       ||g_delimeter||l_prev_bio_rec.remarks
8177       ||g_delimeter||l_prev_bio_rec.commuter
8178       ||g_delimeter||l_prev_bio_rec.birth_cntry_resn_code
8179       ||g_delimeter||l_prev_bio_rec.birth_city	    <>
8180       l_bio_rec.birth_date
8181       ||g_delimeter||l_bio_rec.birth_cntry_code
8182       ||g_delimeter||l_bio_rec.citizen_cntry_code
8183       ||g_delimeter||l_bio_rec.last_name
8184       ||g_delimeter||l_bio_rec.middle_name
8185       ||g_delimeter||l_bio_rec.first_name
8186       ||g_delimeter||l_bio_rec.suffix
8187       ||g_delimeter||l_bio_rec.gender
8188       ||g_delimeter||l_bio_rec.legal_res_cntry_code
8189       ||g_delimeter||l_bio_rec.position_code
8190       ||g_delimeter||l_bio_rec.remarks
8191       ||g_delimeter||l_bio_rec.commuter
8192       ||g_delimeter||l_bio_rec.birth_cntry_resn_code
8193       ||g_delimeter||l_bio_rec.birth_city      THEN
8194 
8195       p_person_rec.bio_status := 'C';  -- Changed
8196       p_person_rec.changes_found := 'Y';
8197       Put_Log_Msg('Bio info is changed  ',0);
8198       /* Debug */
8199 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8200 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Personal_Info';
8201 	   l_debug_str := 'Bio Info changed. l_prev_bio_rec.citizen_cntry_code '||l_prev_bio_rec.citizen_cntry_code||' and l_bio_rec.citizen_cntry_code:'||l_bio_rec.citizen_cntry_code;
8202 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8203 	END IF;
8204 
8205    END IF;
8206 
8207    -- Get other
8208    IF p_person_rec.other_status = 'S' THEN --Found new info
8209 
8210       l_prev_oth_rec.person_id := l_oth_rec.person_id;
8211 
8212       l_status := Get_Other_Info ( p_data_rec  => l_prev_oth_rec);
8213 
8214       IF l_status = 'S' THEN
8215 
8216          IF l_prev_oth_rec.drivers_license
8217             ||g_delimeter||l_prev_oth_rec.drivers_license_state
8218             ||g_delimeter||l_prev_oth_rec.ssn
8219             ||g_delimeter||l_prev_oth_rec.tax_id  <>
8220             l_oth_rec.drivers_license
8221             ||g_delimeter||l_oth_rec.drivers_license_state
8222             ||g_delimeter||l_oth_rec.ssn
8223             ||g_delimeter||l_oth_rec.tax_id  THEN
8224 
8225             p_person_rec.other_status := 'C';  -- Changed
8226             Put_Log_Msg('Other info is changed ',0);
8227             p_person_rec.changes_found := 'Y';
8228 
8229          END IF;
8230 
8231       ELSIF l_status = 'N' THEN
8232 
8233          --Not found
8234          Put_Log_Msg('Other info is changed  ',0);
8235          p_person_rec.other_status := 'C';
8236          p_person_rec.changes_found := 'Y';
8237 
8238 
8239       ELSE
8240 
8241          --Error found l_status = 'U'
8242 	/* Debug */
8243 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8244 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Personal_Info';
8245 	   l_debug_str := 'FND_API.G_EXC_ERROR in Update_Personal_Info.';
8246 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8247 	END IF;
8248 
8249          RAISE FND_API.G_EXC_ERROR;
8250 
8251       END IF;
8252 
8253    END IF; --End of read and compare
8254 
8255    -- Compare Address
8256 
8257    IF p_person_rec.f_addr_status = 'S' THEN --Found new info
8258 
8259       l_prev_f_addr_rec.person_id := l_f_addr_rec(1).person_id ;
8260       l_prev_f_addr_rec.party_site_id := l_f_addr_rec(1).party_site_id ;
8261 
8262       l_status := Get_Address_Info ( p_data_rec  => l_prev_f_addr_rec);
8263 
8264       IF l_status = 'S' THEN
8265 
8266          IF l_prev_f_addr_rec.address_line1
8267             ||g_delimeter||l_prev_f_addr_rec.address_line2
8268             ||g_delimeter||l_prev_f_addr_rec.city
8269             ||g_delimeter||l_prev_f_addr_rec.state
8270             ||g_delimeter||l_prev_f_addr_rec.postal_code
8271             ||g_delimeter||l_prev_f_addr_rec.postal_routing_code
8272             ||g_delimeter||l_prev_f_addr_rec.country_code
8273             ||g_delimeter||l_prev_f_addr_rec.province
8274           --  ||g_delimeter||l_prev_f_addr_rec.stdnt_valid_flag
8275             ||g_delimeter||l_prev_f_addr_rec.primary_flag <>
8276             l_f_addr_rec(1).address_line1
8277             ||g_delimeter||l_f_addr_rec(1).address_line2
8278             ||g_delimeter||l_f_addr_rec(1).city
8279             ||g_delimeter||l_f_addr_rec(1).state
8280             ||g_delimeter||l_f_addr_rec(1).postal_code
8281             ||g_delimeter||l_f_addr_rec(1).postal_routing_code
8282             ||g_delimeter||l_f_addr_rec(1).country_code
8283             ||g_delimeter||l_f_addr_rec(1).province
8284            -- ||g_delimeter||l_f_addr_rec(1).stdnt_valid_flag
8285             ||g_delimeter||l_f_addr_rec(1).primary_flag THEN
8286 
8287             p_person_rec.f_addr_status := 'C';  -- Changed
8288 
8289             p_person_rec.changes_found := 'Y';
8290             Put_Log_Msg('F Address is changed',0);
8291 
8292          END IF;
8293 
8294       ELSIF l_status = 'N' THEN
8295 
8296          --Not found
8297 
8298          Put_Log_Msg('F address info is changed  ',0);
8299          p_person_rec.f_addr_status := 'C';
8300          p_person_rec.changes_found := 'Y';
8301 
8302       ELSE
8303 
8304          --Error found l_status = 'U'
8305 	 /* Debug */
8306 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8307 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Personal_Info';
8308 	   l_debug_str := 'FND_API.G_EXC_ERROR in Update_Personal_Info. f_addr_status is S';
8309 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8310 	END IF;
8311 
8312          RAISE FND_API.G_EXC_ERROR;
8313 
8314       END IF;
8315 
8316    END IF; --End of read and compare
8317 
8318 
8319    IF p_person_rec.us_addr_status = 'S' THEN --Found new info
8320 
8321       l_prev_us_addr_rec.party_site_id := l_us_addr_rec(1).party_site_id ;
8322       l_prev_us_addr_rec.person_id := l_us_addr_rec(1).person_id ;
8323 
8324       l_status := Get_Address_Info ( p_data_rec  => l_prev_us_addr_rec);
8325 
8326       IF l_status = 'S' THEN
8327 
8328          IF l_prev_us_addr_rec.address_line1
8329             ||g_delimeter||l_prev_us_addr_rec.address_line2
8330             ||g_delimeter||l_prev_us_addr_rec.city
8331             ||g_delimeter||l_prev_us_addr_rec.state
8332             ||g_delimeter||l_prev_us_addr_rec.postal_code
8333             ||g_delimeter||l_prev_us_addr_rec.postal_routing_code
8334             ||g_delimeter||l_prev_us_addr_rec.country_code
8335             ||g_delimeter||l_prev_us_addr_rec.province
8336           --||g_delimeter||l_prev_us_addr_rec.stdnt_valid_flag
8337             ||g_delimeter||l_prev_us_addr_rec.primary_flag <>
8338             l_us_addr_rec(1).address_line1
8339             ||g_delimeter||l_us_addr_rec(1).address_line2
8340             ||g_delimeter||l_us_addr_rec(1).city
8341             ||g_delimeter||l_us_addr_rec(1).state
8342             ||g_delimeter||l_us_addr_rec(1).postal_code
8343             ||g_delimeter||l_us_addr_rec(1).postal_routing_code
8344             ||g_delimeter||l_us_addr_rec(1).country_code
8345             ||g_delimeter||l_us_addr_rec(1).province
8346          -- ||g_delimeter||l_us_addr_rec(1).stdnt_valid_flag
8347             ||g_delimeter||l_us_addr_rec(1).primary_flag THEN
8348 
8349             p_person_rec.us_addr_status := 'C';  -- Changed
8350             p_person_rec.changes_found := 'Y';
8351 
8352             Put_Log_Msg('US address is changed ',0);
8353 
8354          END IF;
8355 
8356       ELSIF l_status = 'N' THEN
8357 
8358          --Not found
8359 
8360          Put_Log_Msg('US info is changed - no prev record ',0);
8361          p_person_rec.us_addr_status := 'C';
8362          p_person_rec.changes_found := 'Y';
8363 
8364       ELSE
8365          --Error found l_status = 'U'
8366 	 /* Debug */
8367 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8368 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Personal_Info';
8369 	   l_debug_str := 'FND_API.G_EXC_ERROR in Update_Personal_Info. us_addr_status is S';
8370 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8371 	END IF;
8372 
8373          RAISE FND_API.G_EXC_ERROR;
8374 
8375       END IF;
8376 
8377    END IF; --End of read and compare
8378 
8379    -- Insert
8380    IF p_person_rec.person_status <> 'I'
8381       AND (p_person_rec.bio_status = 'C'
8382         OR p_person_rec.other_status = 'C'
8383         OR p_person_rec.f_addr_status  = 'C'
8384         OR p_person_rec.us_addr_status = 'C') THEN
8385 
8386       p_person_rec.changes_found := 'Y';
8387       Put_Log_Msg('Info is chnaged for the block - do insert',0);
8388 
8389       -- There are changes need to insert data
8390       IF  p_person_rec.bio_status  = 'C'  THEN
8391           Insert_Bio_Info ( p_data_rec  => l_bio_rec);
8392       END IF;
8393 
8394       IF p_person_rec.batch_type = 'I' AND p_person_rec.other_status  = 'C' THEN
8395 
8396          Insert_Other_Info ( p_data_rec  => l_oth_rec);
8397 
8398       END IF;
8399 
8400       IF  p_person_rec.batch_type = 'I' AND   p_person_rec.f_addr_status  = 'C'  THEN
8401 
8402          Insert_Address_Info ('F', p_data_rec  => l_f_addr_rec,p_records => 1);   --- prbhardw CP enhancement
8403 
8404       END IF;
8405 
8406       IF  p_person_rec.batch_type = 'I' AND p_person_rec.us_addr_status  = 'C'  THEN
8407 
8408          Insert_Address_Info ( 'US',p_data_rec  => l_us_addr_rec,p_records => 1);   --- prbhardw CP enhancement
8409 
8410       END IF;
8411 
8412    END IF;
8413 
8414    Put_Log_Msg(l_api_name||' ends ',0);
8415    /* Debug */
8416 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8417    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Personal_Info';
8418    l_debug_str := 'Returning S from Update_Personal_Info.';
8419    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8420 END IF;
8421 
8422    RETURN 'S';
8423 
8424 EXCEPTION
8425 
8426    WHEN FND_API.G_EXC_ERROR THEN
8427 
8428       Put_Log_Msg(l_api_name||' EXEC_ERROR returns U',0);
8429       /* Debug */
8430 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8431 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Personal_Info';
8432 	   l_debug_str := 'FND_API.G_EXC_ERROR: Returning U from Update_Personal_Info. '||SQLERRM;
8433 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8434 	END IF;
8435       RETURN 'U';
8436 
8437    WHEN OTHERS THEN
8438 
8439       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
8440          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
8441       END IF;
8442 
8443       Put_Log_Msg(l_api_name||' OTHERS return U',0);
8444       /* Debug */
8445 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8446 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Personal_Info';
8447 	   l_debug_str := 'EXCEPTION: Returning U from Update_Personal_Info. '||SQLERRM;
8448 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8449 	END IF;
8450       RETURN  'U';
8451 
8452 END Update_Personal_Info;
8453 
8454 FUNCTION Get_EV_Prgm_Info (
8455    p_data_rec  IN OUT NOCOPY  IGS_SV_PRGMS_INFO%ROWTYPE     -- Data record
8456 )   RETURN VARCHAR2  -- 'S' Record found, 'N' - not found. 'U' - Unexpected error
8457 IS
8458 
8459    l_api_name CONSTANT VARCHAR2(25) := 'Get_EV_Prgm_Info';
8460 
8461    CURSOR c_data_rec IS
8462      SELECT  prgm_action_type,
8463 	   prgm_start_date,
8464 	   prgm_end_date ,
8465 	   effective_date,
8466 	   termination_reason,
8467 	   end_prgm_reason,
8468 	   remarks
8469      FROM igs_sv_prgms_info
8470      WHERE person_id = p_data_rec.person_id AND
8471             batch_id IN
8472             (  SELECT max(prg.batch_id)
8473                  FROM igs_sv_prgms_info prg,
8474                       igs_sv_persons pr
8475                 WHERE prg.person_id = pr.person_id
8476                       AND prg.batch_id = pr.batch_id
8477                       AND pr.record_status <> 'E'
8478                       AND prg.person_id = p_data_rec.person_id
8479             )
8480      ORDER BY effective_date;
8481    BEGIN
8482 	/* Debug */
8483 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8484 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_EV_Prgm_Info';
8485 	  l_debug_str := 'Entering Get_EV_Prgm_Info. p_data_rec.person_id is '||p_data_rec.person_id;
8486 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8487 	END IF;
8488 
8489    Put_Log_Msg(l_api_name||' begins ',0);
8490 
8491    OPEN c_data_rec;
8492    FETCH c_data_rec
8493     INTO p_data_rec.prgm_action_type,
8494          p_data_rec.prgm_start_date,
8495          p_data_rec.prgm_end_date ,
8496          p_data_rec.effective_date,
8497          p_data_rec.termination_reason,
8498          p_data_rec.end_prgm_reason,
8499          p_data_rec.remarks ;
8500 
8501    IF c_data_rec%NOTFOUND THEN
8502 
8503       Put_Log_Msg('Record not found ',0);
8504       CLOSE c_data_rec;
8505       /* Debug */
8506 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8507 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_EV_Prgm_Info';
8508 	  l_debug_str := 'Returning N from Get_EV_Prgm_Info';
8509 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8510 	END IF;
8511       RETURN 'N';
8512 
8513    END IF;
8514 
8515    CLOSE c_data_rec;
8516 
8517    Put_Log_Msg(l_api_name||' ends S ',0);
8518 	/* Debug */
8519 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8520 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_EV_Prgm_Info';
8521 	  l_debug_str := 'Returning S from Get_EV_Prgm_Info';
8522 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8523 	END IF;
8524    RETURN 'S';
8525 
8526 EXCEPTION
8527 
8528    WHEN FND_API.G_EXC_ERROR THEN
8529 	 /* Debug */
8530 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8531 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_EV_Prgm_Info';
8532 	  l_debug_str := 'Exception in Get_EV_Prgm_Info '||SQLERRM;
8533 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8534 	END IF;
8535 
8536       Put_Log_Msg(l_api_name||' EXEC ERROR ',0);
8537       RETURN 'U';
8538 
8539    WHEN OTHERS THEN
8540       /* Debug */
8541 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8542 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_EV_Prgm_Info';
8543 	  l_debug_str := 'Exception in Get_EV_Prgm_Info '||SQLERRM;
8544 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8545 	END IF;
8546       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
8547          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
8548       END IF;
8549 
8550       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
8551       RETURN  'U';
8552 
8553 END Get_EV_Prgm_Info;
8554 
8555 FUNCTION Get_nonimg_Prgm_Info (
8556    p_data_rec  IN OUT NOCOPY  IGS_SV_PRGMS_INFO%ROWTYPE     -- Data record
8557 )   RETURN VARCHAR2  -- 'S' Record found, 'N' - not found. 'U' - Unexpected error
8558 IS
8559 
8560    l_api_name CONSTANT VARCHAR2(25) := 'Get_nonimg_Prgm_Info';
8561 
8562    CURSOR c_data_rec IS
8563      SELECT effective_date,
8564 	   prgm_action_type,
8565 	   prgm_start_date,
8566 	   prgm_end_date,
8567 	   remarks,
8568 	   termination_reason,
8569 	   print_form
8570      FROM igs_sv_prgms_info
8571      WHERE person_id = p_data_rec.person_id AND
8572             batch_id IN
8573             (  SELECT max(prg.batch_id)
8574                  FROM igs_sv_prgms_info prg,
8575                       igs_sv_persons pr
8576                 WHERE prg.person_id = pr.person_id
8577                       AND prg.batch_id = pr.batch_id
8578                       AND pr.record_status <> 'E'
8579                       AND prg.person_id = p_data_rec.person_id
8580             )
8581      ORDER BY effective_date;
8582    BEGIN
8583 	/* Debug */
8584 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8585 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_nonimg_Prgm_Info';
8586 	  l_debug_str := 'Entering Get_nonimg_Prgm_Info. p_data_rec.person_id is '||p_data_rec.person_id;
8587 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8588 	END IF;
8589 
8590    Put_Log_Msg(l_api_name||' begins ',0);
8591 
8592    OPEN c_data_rec;
8593    FETCH c_data_rec
8594     INTO p_data_rec.effective_date,
8595          p_data_rec.prgm_action_type,
8596          p_data_rec.prgm_start_date,
8597          p_data_rec.prgm_end_date,
8598          p_data_rec.remarks,
8599          p_data_rec.termination_reason,
8600          p_data_rec.print_form  ;
8601    IF c_data_rec%NOTFOUND THEN
8602 
8603       Put_Log_Msg('Record not found ',0);
8604       CLOSE c_data_rec;
8605       /* Debug */
8606 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8607 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_nonimg_Prgm_Info';
8608 	  l_debug_str := 'Returning N from Get_nonimg_Prgm_Info';
8609 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8610 	END IF;
8611       RETURN 'N';
8612 
8613    END IF;
8614 
8615    CLOSE c_data_rec;
8616 
8617    Put_Log_Msg(l_api_name||' ends S ',0);
8618 	/* Debug */
8619 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8620 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_nonimg_Prgm_Info';
8621 	  l_debug_str := 'Returning S from Get_nonimg_Prgm_Info';
8622 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8623 	END IF;
8624    RETURN 'S';
8625 
8626 EXCEPTION
8627 
8628    WHEN FND_API.G_EXC_ERROR THEN
8629 	 /* Debug */
8630 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8631 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_nonimg_Prgm_Info';
8632 	  l_debug_str := 'Exception in Get_nonimg_Prgm_Info '||SQLERRM;
8633 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8634 	END IF;
8635 
8636       Put_Log_Msg(l_api_name||' EXEC ERROR ',0);
8637       RETURN 'U';
8638 
8639    WHEN OTHERS THEN
8640       /* Debug */
8641 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8642 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Get_nonimg_Prgm_Info';
8643 	  l_debug_str := 'Exception in Get_nonimg_Prgm_Info '||SQLERRM;
8644 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8645 	END IF;
8646       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
8647          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
8648       END IF;
8649 
8650       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
8651       RETURN  'U';
8652 
8653 END Get_nonimg_Prgm_Info;
8654 
8655 /******************************************************************
8656    Created By         : Arkadi Tereshenkov
8657 
8658    Date Created By    : Oct 14, 2002
8659 
8660    Purpose            : Update program information block
8661 
8662    Remarks            :
8663 
8664    Change History
8665    Who                  When            What
8666 ------------------------------------------------------------------------
8667 
8668 ******************************************************************/
8669 FUNCTION Update_Program_Info (
8670    p_person_rec      IN OUT NOCOPY  t_student_rec    --Person record
8671 ) RETURN VARCHAR2
8672 IS
8673 
8674    l_api_name   CONSTANT VARCHAR2(30)   := 'Update_Program_Info';
8675    l_cur_rec    IGS_SV_PRGMS_INFO%ROWTYPE;
8676    l_status     VARCHAR2(1);
8677    l_prev_rec   IGS_SV_PRGMS_INFO%ROWTYPE;
8678    l_count      NUMBER(10);
8679    l_cur_prgm_rec  g_edu_rec_type;
8680    l_cur_authdrp_rec  IGS_SV_PRGMS_INFO%ROWTYPE;
8681 BEGIN
8682 
8683    Put_Log_Msg(l_api_name||' begins ',0);
8684    /* Debug */
8685 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8686    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Program_Info';
8687    l_debug_str := 'Entering Update_Program_Info. p_person_rec.person_id is '||p_person_rec.person_id;
8688    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8689 END IF;
8690 
8691    -- First part - check program Info block
8692 
8693    p_person_rec.edu_status  := Validate_Edu_Info (p_person_rec => p_person_rec,
8694                                                   p_data_rec   => l_cur_rec);
8695 
8696    IF p_person_rec.edu_status = 'E'  THEN -- Validation error - mark person as invalid
8697 
8698       p_person_rec.person_status := 'I';
8699 
8700       Put_Log_Msg('Validation error occurs ',0);
8701        /* Debug */
8702 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8703 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Program_Info';
8704 	   l_debug_str := 'Returning S from Update_Program_Info. p_person_rec.edu_status is E';
8705 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8706 	END IF;
8707 
8708       RETURN 'S';
8709 
8710    END IF;
8711 
8712    IF p_person_rec.edu_status = 'U' THEN --Unexpected error - terminate execution
8713 
8714       Put_Log_Msg('Unexpected error returned by validation ',0);
8715       /* Debug */
8716 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8717 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Program_Info';
8718 	   l_debug_str := 'RAISE FND_API.G_EXC_ERROR in Update_Program_Info. p_person_rec.edu_status is U';
8719 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8720 	END IF;
8721 
8722       RAISE FND_API.G_EXC_ERROR;
8723 
8724    ELSIF p_person_rec.edu_status = 'N' THEN -- Not found
8725 
8726       -- These are I-20 blocks and should be found. If this happens - its a bug
8727 
8728       Put_Log_Msg('EDU block is not found ',0);
8729       /* Debug */
8730 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8731 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Program_Info';
8732 	   l_debug_str := 'RAISE FND_API.G_EXC_ERROR in Update_Program_Info. p_person_rec.edu_status is N.';
8733 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8734 	END IF;
8735 
8736       FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_UNEXP_EXCPT_ERR'); -- I-20 is missing! Unexpected error
8737       FND_MESSAGE.SET_TOKEN('BLOCK_ID',3);
8738       FND_MSG_PUB.Add;
8739 
8740       RAISE FND_API.G_EXC_ERROR;
8741 
8742    END IF;
8743 
8744 
8745    -- Compare EDU Info
8746    l_prev_rec.person_id := p_person_rec.person_id;
8747 
8748    l_status := Get_Edu_Info ( p_data_rec  => l_prev_rec);
8749 
8750    IF l_status = 'U' OR l_status = 'N' THEN
8751 	/* Debug */
8752 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8753 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Program_Info';
8754 	   l_debug_str := 'RAISE FND_API.G_EXC_ERROR in Update_Program_Info. l_status is U or N.';
8755 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8756 	END IF;
8757       RAISE FND_API.G_EXC_ERROR;
8758 
8759    END IF;
8760 
8761    IF l_prev_rec.position_code
8762       ||g_delimeter||l_prev_rec.subject_field_code
8763       ||g_delimeter||l_prev_rec.education_level
8764       ||g_delimeter||l_prev_rec.primary_major
8765       ||g_delimeter||l_prev_rec.secondary_major
8766       ||g_delimeter||l_prev_rec.educ_lvl_remarks
8767       ||g_delimeter||l_prev_rec.minor
8768       ||g_delimeter||l_prev_rec.length_of_study
8769       ||g_delimeter||l_prev_rec.prgm_start_date
8770       ||g_delimeter||l_prev_rec.prgm_end_date
8771       ||g_delimeter||l_prev_rec.english_reqd
8772       ||g_delimeter||l_prev_rec.english_reqd_met
8773       ||g_delimeter||l_prev_rec.not_reqd_reason
8774         <>
8775       l_cur_rec.position_code
8776       ||g_delimeter||l_cur_rec.subject_field_code
8777       ||g_delimeter||l_cur_rec.education_level
8778       ||g_delimeter||l_cur_rec.primary_major
8779       ||g_delimeter||l_cur_rec.secondary_major
8780       ||g_delimeter||l_cur_rec.educ_lvl_remarks
8781       ||g_delimeter||l_cur_rec.minor
8782       ||g_delimeter||l_cur_rec.length_of_study
8783       ||g_delimeter||l_cur_rec.prgm_start_date
8784       ||g_delimeter||l_cur_rec.prgm_end_date
8785       ||g_delimeter||l_cur_rec.english_reqd
8786       ||g_delimeter||l_cur_rec.english_reqd_met
8787       ||g_delimeter||l_cur_rec.not_reqd_reason
8788       THEN
8789 
8790       p_person_rec.edu_status := 'C';  -- Changed
8791 
8792       p_person_rec.changes_found := 'Y';
8793 
8794       Put_Log_Msg('EDU info is changed  ',0);
8795 
8796       IF p_person_rec.person_status <> 'I'  THEN
8797 
8798         Insert_Edu_Info ( 'EDU', p_data_rec  => l_cur_rec, p_auth_drp_data_rec => l_cur_authdrp_rec);
8799 
8800       END IF;
8801 
8802    END IF;
8803 
8804    -- Validate program block
8805 
8806    p_person_rec.edu_status  := Validate_Prgm_Info (p_person_rec =>p_person_rec, p_data_rec  => l_cur_prgm_rec, p_records => l_count, p_auth_drp_data_rec => l_cur_authdrp_rec);
8807    IF p_person_rec.edu_status = 'E'  THEN -- Validation error - mark person as invalid
8808 
8809       p_person_rec.person_status := 'I';
8810 
8811       Put_Log_Msg('Validation error occurs ',0);
8812 	/* Debug */
8813 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8814 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Program_Info';
8815 	   l_debug_str := 'Returning S from Update_Program_Info.';
8816 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8817 	END IF;
8818 
8819       RETURN 'S';
8820 
8821    ELSIF p_person_rec.edu_status = 'U' THEN --Unexpected error - terminate execution
8822 
8823       Put_Log_Msg('Unexpected error returned by validation ',0);
8824       /* Debug */
8825 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8826 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Program_Info';
8827 	   l_debug_str := 'RAISE FND_API.G_EXC_ERROR in Update_Program_Info.';
8828 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8829 	END IF;
8830 
8831       RAISE FND_API.G_EXC_ERROR;
8832 
8833    END IF;
8834 
8835    FOR l_current IN 1.. l_count LOOP
8836 
8837       Put_Log_Msg('Checking NI programs  '||l_cur_prgm_rec(l_current).person_id,0);
8838       l_prev_rec.person_id := p_person_rec.person_id;
8839 
8840       p_person_rec.edu_status := 'S';  -- Changed
8841 
8842       l_status := Get_nonimg_Prgm_Info ( p_data_rec => l_prev_rec);
8843 
8844       IF l_status = 'U' THEN
8845        /* Debug */
8846         IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8847           l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Employment_Info';
8848           l_debug_str := 'Unexpected error in Update_Employment_Info. l_status is U.';
8849           fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8850         END IF;
8851          RAISE FND_API.G_EXC_ERROR;
8852       END IF;
8853 
8854       IF  l_status = 'S' THEN
8855           IF
8856 	  (
8857 	   l_prev_rec.prgm_action_type
8858 	   ||g_delimeter||l_prev_rec.effective_date
8859 	   ||g_delimeter||l_prev_rec.print_form
8860 	   ||g_delimeter||l_prev_rec.prgm_start_date
8861 	   ||g_delimeter||l_prev_rec.prgm_end_date
8862 	   ||g_delimeter||l_prev_rec.remarks
8863 	   ||g_delimeter||l_prev_rec.termination_reason
8864 	   <>
8865 	   l_cur_prgm_rec(l_current).prgm_action_type
8866 	   ||g_delimeter||l_cur_prgm_rec(l_current).effective_date
8867 	   ||g_delimeter||l_cur_prgm_rec(l_current).print_form
8868 	   ||g_delimeter||l_cur_prgm_rec(l_current).prgm_start_date
8869 	   ||g_delimeter||l_cur_prgm_rec(l_current).prgm_end_date
8870 	   ||g_delimeter||l_cur_prgm_rec(l_current).remarks
8871 	   ||g_delimeter||l_cur_prgm_rec(l_current).termination_reason
8872 	  ) THEN
8873 		 Put_Log_Msg('Info is changed for  '||l_cur_prgm_rec(l_current).person_id,0);
8874 		 p_person_rec.edu_status := 'C';  -- Changed
8875 		 p_person_rec.changes_found := 'Y';
8876              END IF;
8877 
8878       ELSE   --Remove current person from the insert list
8879         l_cur_prgm_rec(l_current).person_id := NULL;
8880       END IF;
8881 
8882       IF p_person_rec.edu_status = 'C' AND p_person_rec.person_status <> 'I' THEN
8883 	Insert_Edu_Info ('PRGM', p_data_rec  => l_cur_prgm_rec(l_current), p_auth_drp_data_rec => l_cur_authdrp_rec);
8884       END IF;
8885    END LOOP;
8886 
8887   Put_Log_Msg(l_api_name||' ends ',0);
8888     /* Debug */
8889 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8890 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Program_Info';
8891 	   l_debug_str := 'Final Return S from Update_Program_Info.';
8892 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8893 	END IF;
8894 
8895     RETURN 'S';
8896 
8897 EXCEPTION
8898 
8899    WHEN FND_API.G_EXC_ERROR THEN
8900 
8901       Put_Log_Msg(l_api_name||' EXEC_ERROR returns U',0);
8902       /* Debug */
8903 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8904 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Program_Info';
8905 	   l_debug_str := 'FND_API.G_EXC_ERROR: Returning U from Update_Program_Info. '||SQLERRM;
8906 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8907 	END IF;
8908       RETURN 'U';
8909 
8910    WHEN OTHERS THEN
8911 
8912       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
8913          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
8914       END IF;
8915 
8916       Put_Log_Msg(l_api_name||' OTHERS return U',0);
8917       /* Debug */
8918 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8919 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Program_Info';
8920 	   l_debug_str := 'EXCEPTION: Returning U from Update_Program_Info. '||SQLERRM;
8921 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8922 	END IF;
8923 
8924       RETURN  'U';
8925 
8926 END Update_Program_Info;
8927 
8928 
8929 
8930 /******************************************************************
8931    Created By         : Arkadi Tereshenkov
8932 
8933    Date Created By    : Oct 14, 2002
8934 
8935    Purpose            : Update EV program information block
8936 
8937    Remarks            :
8938 
8939    Change History
8940    Who                  When            What
8941 ------------------------------------------------------------------------
8942 
8943 ******************************************************************/
8944 FUNCTION Update_EV_Program_Info (
8945    p_person_rec      IN OUT NOCOPY  t_student_rec    --Person record
8946 ) RETURN VARCHAR2
8947 IS
8948 
8949    l_api_name   CONSTANT VARCHAR2(30)   := 'Update_EV_Program_Info';
8950    l_cur_rec    IGS_SV_PRGMS_INFO%ROWTYPE;
8951    l_cur_authdrp_rec  IGS_SV_PRGMS_INFO%ROWTYPE;
8952    l_status     VARCHAR2(1);
8953    l_prev_rec   IGS_SV_PRGMS_INFO%ROWTYPE;
8954    l_count      NUMBER(10);
8955    l_cur_prgm_rec  g_edu_rec_type;
8956 
8957 BEGIN
8958 
8959    Put_Log_Msg(l_api_name||' begins ',0);
8960    /* Debug */
8961 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8962    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Program_Info';
8963    l_debug_str := 'Entering Update_EV_Program_Info. p_person_rec.person_id is '||p_person_rec.person_id;
8964    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8965 END IF;
8966 
8967 
8968 	p_person_rec.edu_status  := Validate_Edu_Info (p_person_rec => p_person_rec,
8969                                                   p_data_rec   => l_cur_rec);
8970 
8971    IF p_person_rec.edu_status = 'E'  THEN -- Validation error - mark person as invalid
8972 
8973       p_person_rec.person_status := 'I';
8974 
8975       Put_Log_Msg('Validation error occurs ',0);
8976        /* Debug */
8977 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8978 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Program_Info';
8979 	   l_debug_str := 'Returning S from Update_Program_Info. p_person_rec.edu_status is E';
8980 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8981 	END IF;
8982 
8983       RETURN 'S';
8984 
8985    END IF;
8986 
8987    IF p_person_rec.edu_status = 'U' THEN --Unexpected error - terminate execution
8988 
8989       Put_Log_Msg('Unexpected error returned by validation ',0);
8990       /* Debug */
8991 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
8992 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Program_Info';
8993 	   l_debug_str := 'RAISE FND_API.G_EXC_ERROR in Update_Program_Info. p_person_rec.edu_status is U';
8994 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
8995 	END IF;
8996 
8997       RAISE FND_API.G_EXC_ERROR;
8998 
8999    ELSIF p_person_rec.edu_status = 'N' THEN -- Not found
9000 
9001       -- These are I-20 blocks and should be found. If this happens - its a bug
9002 
9003       Put_Log_Msg('EDU block is not found ',0);
9004       /* Debug */
9005 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9006 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Program_Info';
9007 	   l_debug_str := 'RAISE FND_API.G_EXC_ERROR in Update_Program_Info. p_person_rec.edu_status is N.';
9008 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9009 	END IF;
9010 
9011       FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_UNEXP_EXCPT_ERR'); -- I-20 is missing! Unexpected error
9012       FND_MESSAGE.SET_TOKEN('BLOCK_ID',3);
9013       FND_MSG_PUB.Add;
9014 
9015       RAISE FND_API.G_EXC_ERROR;
9016 
9017    END IF;
9018 
9019 
9020    -- Compare EDU Info
9021    l_prev_rec.person_id := p_person_rec.person_id;
9022 
9023    l_status := Get_Edu_Info ( p_data_rec  => l_prev_rec);
9024 
9025    IF l_status = 'U' OR l_status = 'N' THEN
9026 	/* Debug */
9027 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9028 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Program_Info';
9029 	   l_debug_str := 'RAISE FND_API.G_EXC_ERROR in Update_Program_Info. l_status is U or N.';
9030 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9031 	END IF;
9032       RAISE FND_API.G_EXC_ERROR;
9033 
9034    END IF;
9035 /*
9036    IF l_prev_rec.position_code
9037       ||g_delimeter||l_prev_rec.remarks
9038       <>
9039       l_cur_rec.position_code
9040       ||g_delimeter||l_cur_rec.remarks
9041       THEN
9042 
9043       p_person_rec.edu_status := 'C';  -- Changed
9044 
9045       p_person_rec.changes_found := 'Y';
9046 
9047       Put_Log_Msg('EDU info is changed  ',0);
9048 
9049       IF p_person_rec.person_status <> 'I'  THEN
9050 
9051         Insert_Edu_Info ( 'EDU', p_data_rec  => l_cur_rec, p_auth_drp_data_rec => l_cur_authdrp_rec);
9052 
9053       END IF;
9054 
9055    END IF;
9056 */
9057    IF l_prev_rec.subject_field_code  <>  l_cur_rec.subject_field_code  THEN
9058 
9059       p_person_rec.edu_status := 'C';  -- Changed
9060 
9061       p_person_rec.changes_found := 'Y';
9062 
9063       Put_Log_Msg('EDU info is changed  ',0);
9064 
9065       IF p_person_rec.person_status <> 'I'  THEN
9066 	l_cur_rec.prgm_action_type := 'US';
9067         Insert_Edu_Info ( 'PRGM', p_data_rec  => l_cur_rec, p_auth_drp_data_rec => l_cur_authdrp_rec);
9068 
9069       END IF;
9070 
9071    END IF;
9072 
9073 
9074 
9075 
9076    -- Validate program block
9077 
9078    p_person_rec.edu_status  := Validate_Prgm_Info (p_person_rec =>p_person_rec, p_data_rec  => l_cur_prgm_rec, p_records => l_count,
9079 						   p_auth_drp_data_rec => l_cur_authdrp_rec);
9080    IF p_person_rec.edu_status = 'E'  THEN -- Validation error - mark person as invalid
9081 
9082       p_person_rec.person_status := 'I';
9083 
9084       Put_Log_Msg('Validation error occurs ',0);
9085        /* Debug */
9086 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9087 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Program_Info';
9088 	   l_debug_str := 'Returning S from Update_EV_Program_Info. p_person_rec.edu_status is E.';
9089 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9090 	END IF;
9091 
9092       RETURN 'S';
9093 
9094    ELSIF p_person_rec.edu_status = 'U' THEN --Unexpected error - terminate execution
9095 
9096       Put_Log_Msg('Unexpected error returned by validation ',0);
9097       /* Debug */
9098 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9099 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Program_Info';
9100 	   l_debug_str := 'RAISE FND_API.G_EXC_ERROR in Update_EV_Program_Info. p_person_rec.edu_status is U.';
9101 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9102 	END IF;
9103 
9104       RAISE FND_API.G_EXC_ERROR;
9105 
9106    END IF;
9107 
9108 
9109 FOR l_current IN 1.. l_count LOOP
9110 
9111       Put_Log_Msg('Checking ev programs  '||l_cur_prgm_rec(l_current).person_id,0);
9112       l_prev_rec.person_id := p_person_rec.person_id;
9113 
9114       p_person_rec.edu_status := 'S';  -- Changed
9115 
9116       l_status := Get_EV_Prgm_Info ( p_data_rec  => l_prev_rec);
9117 
9118       IF l_status = 'U' THEN
9119        /* Debug */
9120         IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9121           l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Employment_Info';
9122           l_debug_str := 'Unexpected error in Update_Employment_Info. l_status is U.';
9123           fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9124         END IF;
9125          RAISE FND_API.G_EXC_ERROR;
9126       END IF;
9127 
9128       IF  l_status = 'S' THEN
9129           IF
9130 	  (
9131 	   l_prev_rec.prgm_action_type
9132 	   ||g_delimeter||l_prev_rec.prgm_start_date
9133 	   ||g_delimeter||l_prev_rec.prgm_end_date
9134 	   ||g_delimeter||l_prev_rec.effective_date
9135 	   ||g_delimeter||l_prev_rec.termination_reason
9136 	   ||g_delimeter||l_prev_rec.end_prgm_reason
9137 	   ||g_delimeter||l_prev_rec.remarks
9138 	   <>
9139 	   l_cur_prgm_rec(l_current).prgm_action_type
9140 	   ||g_delimeter||l_cur_prgm_rec(l_current).prgm_start_date
9141 	   ||g_delimeter||l_cur_prgm_rec(l_current).prgm_end_date
9142 	   ||g_delimeter||l_cur_prgm_rec(l_current).effective_date
9143 	   ||g_delimeter||l_cur_prgm_rec(l_current).termination_reason
9144 	   ||g_delimeter||l_cur_prgm_rec(l_current).end_prgm_reason
9145 	   ||g_delimeter||l_cur_prgm_rec(l_current).remarks
9146 	  ) THEN
9147 		 Put_Log_Msg('Info is changed for  '||l_cur_prgm_rec(l_current).person_id,0);
9148 		 p_person_rec.edu_status := 'C';  -- Changed
9149 		 p_person_rec.changes_found := 'Y';
9150 	     END IF;
9151 
9152       ELSE   --Remove current person from the insert list
9153         l_cur_prgm_rec(l_current).person_id := NULL;
9154       END IF;
9155 
9156       IF p_person_rec.edu_status = 'C' AND p_person_rec.person_status <> 'I' THEN
9157 		 /* Debug */
9158 		IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9159 		   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Program_Info';
9160 		   l_debug_str := 'inserting prgm info.';
9161 		   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9162 		END IF;
9163 	Insert_Edu_Info ('PRGM', p_data_rec  => l_cur_prgm_rec(l_current), p_auth_drp_data_rec => l_cur_authdrp_rec);
9164       END IF;
9165    END LOOP;
9166 
9167    Put_Log_Msg(l_api_name||' ends ',0);
9168     /* Debug */
9169 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9170 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Program_Info';
9171 	   l_debug_str := 'Returning S from Update_EV_Program_Info.';
9172 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9173 	END IF;
9174 
9175    RETURN 'S';
9176 
9177 EXCEPTION
9178 
9179    WHEN FND_API.G_EXC_ERROR THEN
9180 
9181       Put_Log_Msg(l_api_name||' EXEC_ERROR returns U',0);
9182        /* Debug */
9183 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9184 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Program_Info';
9185 	   l_debug_str := 'FND_API.G_EXC_ERROR: Returning U from Update_EV_Program_Info. '||SQLERRM;
9186 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9187 	END IF;
9188 
9189       RETURN 'U';
9190 
9191    WHEN OTHERS THEN
9192 
9193       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
9194          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
9195       END IF;
9196 
9197       Put_Log_Msg(l_api_name||' OTHERS return U',0);
9198        /* Debug */
9199 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9200 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_EV_Program_Info';
9201 	   l_debug_str := 'EXCEPTION: Returning U from Update_EV_Program_Info. '||SQLERRM;
9202 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9203 	END IF;
9204 
9205 
9206       RETURN  'U';
9207 
9208 END Update_EV_Program_Info;
9209 
9210 
9211 /******************************************************************
9212    Created By         : Arkadi Tereshenkov
9213 
9214    Date Created By    : Oct 14, 2002
9215 
9216    Purpose            : Update Finance Information block on student
9217 
9218    Remarks            :
9219 
9220    Change History
9221    Who                  When            What
9222 ------------------------------------------------------------------------
9223 
9224 ******************************************************************/
9225 FUNCTION Update_Finance_Info (
9226    p_person_rec      IN OUT NOCOPY  t_student_rec    --Person record
9227 ) RETURN VARCHAR2
9228 IS
9229 
9230    l_api_name    CONSTANT VARCHAR2(30)   := 'Update_Finance_Info';
9231    l_cur_rec     IGS_SV_FINANCE_INFO%ROWTYPE;
9232    l_prev_rec    IGS_SV_FINANCE_INFO%ROWTYPE;
9233    l_status      VARCHAR2(1);
9234 
9235 
9236 BEGIN
9237 
9238    Put_Log_Msg(l_api_name||' begins ',0);
9239 	/* Debug */
9240 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9241 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Finance_Info';
9242 	   l_debug_str := 'Entering Update_Finance_Info. p_person_rec.person_id is '||p_person_rec.person_id;
9243 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9244 	END IF;
9245 
9246    -- Call Validate_Finance_Info
9247    p_person_rec.fin_status  := Validate_Finance_Info (p_person_rec => p_person_rec,
9248                                                       p_data_rec   => l_cur_rec);
9249    IF p_person_rec.fin_status = 'E'  THEN -- Validation error - mark person as invalid
9250 
9251       p_person_rec.person_status := 'I';
9252 
9253       Put_Log_Msg('Validation error occurs ',0);
9254       /* Debug */
9255 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9256 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Finance_Info';
9257 	   l_debug_str := 'Returning S from Update_Finance_Info. p_person_rec.fin_status is E';
9258 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9259 	END IF;
9260 
9261       RETURN 'S';
9262 
9263    ELSIF p_person_rec.fin_status = 'U' THEN --Unexpected error - terminate execution
9264 
9265       Put_Log_Msg('Unexpected error returned by validation ',0);
9266       /* Debug */
9267 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9268 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Finance_Info';
9269 	   l_debug_str := 'Raise FND_API.G_EXC_ERROR in Update_Finance_Info. fin_status is U';
9270 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9271 	END IF;
9272 
9273       RAISE FND_API.G_EXC_ERROR;
9274 
9275    ELSIF p_person_rec.fin_status = 'N' THEN -- Not found
9276 
9277       -- These are I-20 blocks and should be found. If this happens - its a bug
9278 
9279       Put_Log_Msg('Finance block is not found ',0);
9280       /* Debug */
9281 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9282 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Finance_Info';
9283 	   l_debug_str := 'Raise FND_API.G_EXC_ERROR in Update_Finance_Info. fin_status is N';
9284 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9285 	END IF;
9286 
9287 
9288       FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_UNEXP_EXCPT_ERR'); -- I-20 is missing! Unexpected error
9289       FND_MESSAGE.SET_TOKEN('BLOCK_ID',4);
9290       FND_MSG_PUB.Add;
9291 
9292       RAISE FND_API.G_EXC_ERROR;
9293 
9294    END IF;
9295 
9296 
9297    -- Compare Finance Info
9298    l_prev_rec.person_id := p_person_rec.person_id;
9299 
9300    l_status := Get_Finance_Info ( p_data_rec  => l_prev_rec);
9301 
9302    IF l_status = 'U' OR l_status = 'N' THEN
9303       /* Debug */
9304 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9305 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Finance_Info';
9306 	   l_debug_str := 'Raise FND_API.G_EXC_ERROR in Update_Finance_Info. l_status is U or N';
9307 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9308 	END IF;
9309 
9310       RAISE FND_API.G_EXC_ERROR;
9311 
9312    END IF;
9313 
9314    IF l_prev_rec.acad_term_length
9315       ||g_delimeter||l_prev_rec.tuition
9316       ||g_delimeter||l_prev_rec.living_exp
9317       ||g_delimeter||l_prev_rec.personal_funds
9318       ||g_delimeter||l_prev_rec.dependent_exp
9319       ||g_delimeter||l_prev_rec.other_exp
9320       ||g_delimeter||l_prev_rec.other_exp_desc
9321       ||g_delimeter||l_prev_rec.school_funds
9322       ||g_delimeter||l_prev_rec.school_funds_desc
9323       ||g_delimeter||l_prev_rec.other_funds
9324       ||g_delimeter||l_prev_rec.other_funds_desc
9325       ||g_delimeter||l_prev_rec.empl_funds
9326       ||g_delimeter||l_prev_rec.program_sponsor
9327       ||g_delimeter||l_prev_rec.govt_org1
9328       ||g_delimeter||l_prev_rec.govt_org2
9329       ||g_delimeter||l_prev_rec.govt_org1_code
9330       ||g_delimeter||l_prev_rec.govt_org2_code
9331       ||g_delimeter||l_prev_rec.intl_org1
9332       ||g_delimeter||l_prev_rec.intl_org2
9333       ||g_delimeter||l_prev_rec.intl_org1_code
9334       ||g_delimeter||l_prev_rec.intl_org2_code
9335       ||g_delimeter||l_prev_rec.ev_govt
9336       ||g_delimeter||l_prev_rec.bi_natnl_com
9337       ||g_delimeter||l_prev_rec.other_org
9338       ||g_delimeter||l_prev_rec.remarks
9339       ||g_delimeter||l_prev_rec.govt_org1_othr_name
9340       ||g_delimeter||l_prev_rec.govt_org2_othr_name
9341       ||g_delimeter||l_prev_rec.intl_org1_othr_name
9342       ||g_delimeter||l_prev_rec.intl_org2_othr_name
9343       ||g_delimeter||l_prev_rec.other_govt_name
9344       <>
9345       l_cur_rec.acad_term_length
9346       ||g_delimeter||l_cur_rec.tuition
9347       ||g_delimeter||l_cur_rec.living_exp
9348       ||g_delimeter||l_cur_rec.personal_funds
9349       ||g_delimeter||l_cur_rec.dependent_exp
9350       ||g_delimeter||l_cur_rec.other_exp
9351       ||g_delimeter||l_cur_rec.other_exp_desc
9352       ||g_delimeter||l_cur_rec.school_funds
9353       ||g_delimeter||l_cur_rec.school_funds_desc
9354       ||g_delimeter||l_cur_rec.other_funds
9355       ||g_delimeter||l_cur_rec.other_funds_desc
9356       ||g_delimeter||l_cur_rec.empl_funds
9357       ||g_delimeter||l_cur_rec.program_sponsor
9358       ||g_delimeter||l_cur_rec.govt_org1
9359       ||g_delimeter||l_cur_rec.govt_org2
9360       ||g_delimeter||l_cur_rec.govt_org1_code
9361       ||g_delimeter||l_cur_rec.govt_org2_code
9362       ||g_delimeter||l_cur_rec.intl_org1
9363       ||g_delimeter||l_cur_rec.intl_org2
9364       ||g_delimeter||l_cur_rec.intl_org1_code
9365       ||g_delimeter||l_cur_rec.intl_org2_code
9366       ||g_delimeter||l_cur_rec.ev_govt
9367       ||g_delimeter||l_cur_rec.bi_natnl_com
9368       ||g_delimeter||l_cur_rec.other_org
9369       ||g_delimeter||l_cur_rec.remarks
9370       ||g_delimeter||l_cur_rec.govt_org1_othr_name
9371       ||g_delimeter||l_cur_rec.govt_org2_othr_name
9372       ||g_delimeter||l_cur_rec.intl_org1_othr_name
9373       ||g_delimeter||l_cur_rec.intl_org2_othr_name
9374       ||g_delimeter||l_cur_rec.other_govt_name
9375       THEN
9376 
9377       p_person_rec.fin_status := 'C';  -- Changed
9378 
9379       Put_Log_Msg('Finance info is changed  ',0);
9380 
9381       p_person_rec.changes_found := 'Y';
9382 
9383       IF p_person_rec.person_status <> 'I'  THEN
9384         Insert_Finance_Info ( p_data_rec  => l_cur_rec);
9385       END IF;
9386 
9387    END IF;
9388    Put_Log_Msg(l_api_name||' ends ',0);
9389    /* Debug */
9390    IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9391       l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Finance_Info';
9392       l_debug_str := 'Returning S from Update_Finance_Info.';
9393       fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9394    END IF;
9395 
9396    RETURN 'S';
9397 
9398 EXCEPTION
9399 
9400    WHEN FND_API.G_EXC_ERROR THEN
9401 
9402       Put_Log_Msg(l_api_name||' EXEC_ERROR returns U',0);
9403       /* Debug */
9404    IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9405       l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Finance_Info';
9406       l_debug_str := 'FND_API.G_EXC_ERROR: Returning U from Update_Finance_Info. '||SQLERRM;
9407       fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9408    END IF;
9409       RETURN 'U';
9410 
9411    WHEN OTHERS THEN
9412 
9413       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
9414          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
9415       END IF;
9416 
9417       Put_Log_Msg(l_api_name||' OTHERS return U',0);
9418       /* Debug */
9419    IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9420       l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Finance_Info';
9421       l_debug_str := 'EXCEPTION: Returning U from Update_Finance_Info. '||SQLERRM;
9422       fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9423    END IF;
9424 
9425       RETURN  'U';
9426 
9427 END Update_Finance_Info;
9428 
9429 
9430 
9431 /******************************************************************
9432    Created By         : Arkadi Tereshenkov
9433 
9434    Date Created By    : Oct 14, 2002
9435 
9436    Purpose            : Update Dependent block information on the student
9437 
9438    Remarks            :
9439 
9440    Change History
9441    Who                  When            What
9442 ------------------------------------------------------------------------
9443 
9444 ******************************************************************/
9445 FUNCTION Update_Dependent_Info (
9446    p_person_rec      IN OUT NOCOPY  t_student_rec    --Person record
9447 ) RETURN VARCHAR2
9448 IS
9449 
9450    l_api_name   CONSTANT VARCHAR2(30)   := 'Update_Dependent_Info';
9451    l_cur_rec    g_dependent_rec_type;
9452    l_prev_rec   IGS_SV_DEPDNT_INFO%ROWTYPE;
9453    l_status     VARCHAR2(1);
9454    l_count      NUMBER(10);
9455    l_current    NUMBER(10);
9456    l_rel_type_count NUMBER := 0;
9457 
9458    CURSOR c_spouse_of_rel IS
9459           SELECT COUNT(1)
9460           FROM igs_sv_depdnt_info cr,
9461 	       igs_sv_persons pr
9462 	  WHERE cr.person_id = p_person_rec.person_id
9463 		AND pr.record_status <> 'E'
9464 		AND cr.person_id = pr.person_id
9465 		AND cr.relationship = 'SPOUSE_OF';
9466 
9467 BEGIN
9468 
9469    Put_Log_Msg(l_api_name||' begins ',0);
9470    /* Debug */
9471    IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9472       l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Dependent_Info';
9473       l_debug_str := 'Entering Update_Dependent_Info. p_person_rec.person_id is '||p_person_rec.person_id;
9474       fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9475    END IF;
9476 
9477 
9478    -- Call Validate_Empl_Info
9479 
9480    p_person_rec.dep_status  := Validate_Dependent_Info (p_person_rec => p_person_rec,
9481                                                          p_data_rec   => l_cur_rec,
9482                                                          p_records    => l_count);
9483    IF p_person_rec.dep_status = 'E'  THEN -- Validation error - mark person as invalid
9484 
9485       p_person_rec.person_status := 'I';
9486 
9487       Put_Log_Msg('Validation error occurs ',0);
9488       /* Debug */
9489      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9490         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Dependent_Info';
9491         l_debug_str := 'Returning S from Update_Dependent_Info. dep_status is E.';
9492         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9493      END IF;
9494       RETURN 'S';
9495 
9496    ELSIF p_person_rec.dep_status = 'U' THEN --Unexpected error - terminate execution
9497 
9498       Put_Log_Msg('Unexpected error returned by validation ',0);
9499       /* Debug */
9500      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9501         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Dependent_Info';
9502         l_debug_str := 'Raise FND_API.G_EXC_ERROR in Update_Dependent_Info. dep_status is U.';
9503         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9504      END IF;
9505 
9506       RAISE FND_API.G_EXC_ERROR;
9507 
9508    ELSIF p_person_rec.dep_status = 'N' THEN -- Not found
9509 
9510       Put_Log_Msg('Dependent block is not found ',0);
9511       /* Debug */
9512      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9513         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Dependent_Info';
9514         l_debug_str := 'Returning S from Update_Dependent_Info. dep_status is N.';
9515         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9516      END IF;
9517       RETURN 'S';
9518 
9519    END IF;
9520    FOR l_current IN 1.. l_count LOOP
9521 
9522       -- Compare Dependent Info
9523       Put_Log_Msg('Checking dependent '||l_cur_rec(l_current).depdnt_id,0);
9524 
9525       l_prev_rec.person_id := p_person_rec.person_id;
9526       l_prev_rec.depdnt_id := l_cur_rec(l_current).depdnt_id;
9527       p_person_rec.dep_status := 'S';  -- Changed
9528 
9529       l_status := Get_Dependent_Info ( p_data_rec  => l_prev_rec);
9530 
9531 
9532 --manoj stars
9533 
9534 
9535 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9536 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Previous_Dependent_Info';
9537 	  l_debug_str := 'l_prev_rec action_type='||l_prev_rec.depdnt_action_type;
9538           l_debug_str := l_debug_str || 'visa_type=' || l_prev_rec.visa_type;
9539           l_debug_str := l_debug_str || 'last_name=' || l_prev_rec.last_name;
9540           l_debug_str := l_debug_str || 'first_name=' || l_prev_rec.first_name ;
9541           l_debug_str := l_debug_str || 'middle_name=' || l_prev_rec.middle_name;
9542           l_debug_str := l_debug_str || 'suffix=' || l_prev_rec.suffix;
9543           l_debug_str := l_debug_str || 'birth_date=' || l_prev_rec.birth_date;
9544           l_debug_str := l_debug_str || 'gender=' || l_prev_rec.gender;
9545           l_debug_str := l_debug_str || 'birth_cntry_code=' || l_prev_rec.birth_cntry_code;
9546           l_debug_str := l_debug_str || 'citizen_cntry_code=' || l_prev_rec.citizen_cntry_code;
9547           l_debug_str := l_debug_str || 'relationship=' || l_prev_rec.relationship;
9548           l_debug_str := l_debug_str || 'termination_reason=' || l_prev_rec.termination_reason ;
9549           l_debug_str := l_debug_str || 'relationship_remarks=' || l_prev_rec.relationship_remarks;
9550           l_debug_str := l_debug_str || 'perm_res_cntry_code=' || l_prev_rec.perm_res_cntry_code;
9551           l_debug_str := l_debug_str || 'termination_effect_date=' || l_prev_rec.termination_effect_date;
9552           l_debug_str := l_debug_str || 'remarks=' || l_prev_rec.remarks;
9553           l_debug_str := l_debug_str || 'birth_cntry_resn_code=' || l_prev_rec.birth_cntry_resn_code;
9554 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9555 	END IF;
9556 
9557 
9558 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9559 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Current_Dependent_Info';
9560 	  l_debug_str := 'cur dep action type: '||l_cur_rec(l_current).depdnt_action_type;
9561 	  l_debug_str := l_debug_str || 'visa_type=' ||  l_cur_rec(l_current).visa_type;
9562           l_debug_str := l_debug_str || 'last_name=' || l_cur_rec(l_current).last_name;
9563           l_debug_str := l_debug_str || 'first_name=' || l_cur_rec(l_current).first_name;
9564           l_debug_str := l_debug_str || 'middle_name=' || l_cur_rec(l_current).middle_name;
9565           l_debug_str := l_debug_str || 'suffix=' || l_cur_rec(l_current).suffix;
9566           l_debug_str := l_debug_str || 'birth_date=' || l_cur_rec(l_current).birth_date;
9567           l_debug_str := l_debug_str || 'gender=' || l_cur_rec(l_current).gender;
9568           l_debug_str := l_debug_str || 'birth_cntry_code=' || l_cur_rec(l_current).birth_cntry_code;
9569           l_debug_str := l_debug_str || 'citizen_cntry_code=' || l_cur_rec(l_current).citizen_cntry_code;
9570           l_debug_str := l_debug_str || 'relationship=' || l_cur_rec(l_current).relationship;
9571           l_debug_str := l_debug_str || 'termination_reason=' || l_cur_rec(l_current).termination_reason;
9572           l_debug_str := l_debug_str || 'relationship_remarks=' || l_cur_rec(l_current).relationship_remarks;
9573           l_debug_str := l_debug_str || 'perm_res_cntry_code=' || l_cur_rec(l_current).perm_res_cntry_code;
9574           l_debug_str := l_debug_str || 'termination_effect_date=' || l_cur_rec(l_current).termination_effect_date;
9575           l_debug_str := l_debug_str || 'remarks=' || l_cur_rec(l_current).remarks ;
9576 	  l_debug_str := l_debug_str || 'birth_cntry_resn_code=' || l_cur_rec(l_current).birth_cntry_resn_code;
9577 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9578 	END IF;
9579 --manoj ends
9580 
9581       IF l_status = 'U' THEN
9582          /* Debug */
9583 	 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9584 		l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Dependent_Info';
9585 		l_debug_str := 'Raise FND_API.G_EXC_ERROR in Update_Dependent_Info. l_status is U.';
9586 		fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9587          END IF;
9588          RAISE FND_API.G_EXC_ERROR;
9589 
9590       END IF;
9591 
9592       -- check if dependent sevis id is present
9593 
9594       IF l_status = 'S' AND l_cur_rec(l_current).depdnt_sevis_id IS NULL THEN
9595 
9596          FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_STUDENT_ID_ERR'); -- SEVIS STUDENT id not found
9597          FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', l_cur_rec(l_current).person_number);
9598          Put_Log_Msg(FND_MESSAGE.Get,1);
9599 
9600          p_person_rec.person_status := 'I';
9601 
9602          Put_Log_Msg('Validation error occurs ',0);
9603 	 /* Debug */
9604         IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9605           l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Dependent_Info';
9606           l_debug_str := 'Returning S from Update_Dependent_Info. l_status is S.';
9607           fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9608         END IF;
9609          RETURN 'S';
9610 
9611       ELSIF l_status = 'N'  THEN
9612         -- New dependent status A;
9613         IF l_cur_rec(l_current).depdnt_action_type = 'A' THEN
9614           l_cur_rec(l_current).depdnt_action_type := 'A';
9615           p_person_rec.dep_status := 'C';  -- Changed
9616           p_person_rec.changes_found := 'Y';
9617 
9618           Put_Log_Msg('Info is changed for  '||l_cur_rec(l_current).depdnt_id,0);
9619 
9620         END IF;
9621 
9622  -------prbhardw
9623           IF l_cur_rec(l_current).relationship = 'SPOUSE_OF' THEN
9624 	       OPEN c_spouse_of_rel;
9625 	       FETCH c_spouse_of_rel INTO l_rel_type_count;
9626 	       CLOSE c_spouse_of_rel;
9627 	       IF l_rel_type_count > 0 THEN
9628 		    FND_MESSAGE.SET_NAME('IGS','IGS_SV_SPOUSE_REL');
9629 		    FND_MESSAGE.SET_TOKEN('PERSON_NUM',p_person_rec.person_number);
9630 		    Put_Log_Msg(FND_MESSAGE.Get,1);
9631 	       END IF;
9632 
9633 	  END IF;
9634  -------prbhardw
9635 
9636      ELSIF l_prev_rec.depdnt_action_type IN ('A','R','U') AND
9637            l_cur_rec(l_current).depdnt_action_type ='T' THEN
9638 
9639         -- Person terminated.
9640         l_cur_rec(l_current).depdnt_action_type := 'T';
9641         p_person_rec.dep_status := 'C';  -- Changed
9642         p_person_rec.changes_found := 'Y';
9643 
9644         Put_Log_Msg('Info is changed for  '||l_cur_rec(l_current).depdnt_id,0);
9645 
9646 
9647      ELSIF  l_prev_rec.depdnt_action_type IN ('T') AND
9648             l_cur_rec(l_current).depdnt_action_type ='A' THEN
9649           -- Person reactivated
9650         l_cur_rec(l_current).depdnt_action_type := 'R';
9651         p_person_rec.dep_status := 'C';  -- Changed
9652         p_person_rec.changes_found := 'Y';
9653 
9654         Put_Log_Msg('Info is changed for  '||l_cur_rec(l_current).depdnt_id,0);
9655 
9656 
9657      ELSIF (l_prev_rec.visa_type		--l_cur_rec(l_current).depdnt_action_type ='A'  AND
9658           ||g_delimeter||l_prev_rec.last_name
9659           ||g_delimeter||l_prev_rec.first_name
9660           ||g_delimeter||l_prev_rec.middle_name
9661           ||g_delimeter||l_prev_rec.suffix
9662           ||g_delimeter||l_prev_rec.birth_date
9663           ||g_delimeter||l_prev_rec.gender
9664           ||g_delimeter||l_prev_rec.birth_cntry_code
9665           ||g_delimeter||l_prev_rec.citizen_cntry_code
9666           ||g_delimeter||l_prev_rec.relationship
9667           ||g_delimeter||l_prev_rec.termination_reason
9668           ||g_delimeter||l_prev_rec.relationship_remarks
9669           ||g_delimeter||l_prev_rec.perm_res_cntry_code
9670           ||g_delimeter||l_prev_rec.termination_effect_date
9671           ||g_delimeter||l_prev_rec.remarks
9672 	  ||g_delimeter||l_prev_rec.birth_cntry_resn_code
9673 	 <> l_cur_rec(l_current).visa_type
9674          ||g_delimeter||l_cur_rec(l_current).last_name
9675          ||g_delimeter||l_cur_rec(l_current).first_name
9676          ||g_delimeter||l_cur_rec(l_current).middle_name
9677          ||g_delimeter||l_cur_rec(l_current).suffix
9678          ||g_delimeter||l_cur_rec(l_current).birth_date
9679          ||g_delimeter||l_cur_rec(l_current).gender
9680          ||g_delimeter||l_cur_rec(l_current).birth_cntry_code
9681          ||g_delimeter||l_cur_rec(l_current).citizen_cntry_code
9682          ||g_delimeter||l_cur_rec(l_current).relationship
9683          ||g_delimeter||l_cur_rec(l_current).termination_reason
9684          ||g_delimeter||l_cur_rec(l_current).relationship_remarks
9685          ||g_delimeter||l_cur_rec(l_current).perm_res_cntry_code
9686          ||g_delimeter||l_cur_rec(l_current).termination_effect_date
9687          ||g_delimeter||l_cur_rec(l_current).remarks
9688 	 ||g_delimeter||l_cur_rec(l_current).birth_cntry_resn_code
9689 	 ) THEN
9690 
9691 
9692 
9693 
9694          Put_Log_Msg('Info is changed for  '||l_cur_rec(l_current).depdnt_id,0);
9695 	 /* Debug */
9696 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9697 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Dependent_Info';
9698 	  l_debug_str := 'Update_Dependent_Info. l_prev_rec.depdnt_action_type: '||l_prev_rec.depdnt_action_type||'cur dep action type: '||l_cur_rec(l_current).depdnt_action_type;
9699 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9700 	END IF;
9701            --IF l_prev_rec.depdnt_action_type = l_cur_rec(l_current).depdnt_action_type THEN
9702 	        l_cur_rec(l_current).depdnt_action_type := 'U';  --update mode for the person
9703 	   --END IF;
9704         p_person_rec.dep_status := 'C';  -- Changed
9705         p_person_rec.changes_found := 'Y';
9706 
9707 
9708       ELSE   --Remove current dependent from the insert list
9709         l_cur_rec(l_current).depdnt_id := NULL;
9710       END IF;
9711 
9712      /* IF p_person_rec.dep_status = 'C' AND p_person_rec.record_status ='C' THEN         prbhardw CP enhancement
9713         -- Only one dependent in the update section.
9714 	/* Debug
9715         IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9716           l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Dependent_Info';
9717           l_debug_str := 'Exiting Update_Dependent_Info. dep_status and record_status is C.';
9718           fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9719         END IF;
9720 
9721        -- EXIT;
9722 
9723       END IF;*/
9724 
9725    END LOOP;
9726        IF  p_person_rec.dep_status = 'C' AND p_person_rec.person_status <> 'I'  THEN
9727 
9728       Insert_Dependent_Info ( p_data_rec  => l_cur_rec,p_records => l_count );
9729 
9730        END IF;
9731 
9732    Put_Log_Msg(l_api_name||' ends ',0);
9733    /* Debug */
9734    IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9735        l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Dependent_Info';
9736        l_debug_str := 'Returning S from Update_Dependent_Info.';
9737        fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9738    END IF;
9739 
9740    RETURN 'S';
9741 
9742 EXCEPTION
9743 
9744    WHEN FND_API.G_EXC_ERROR THEN
9745       Put_Log_Msg(l_api_name||' EXEC_ERROR returns U',0);
9746       /* Debug */
9747         IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9748           l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Dependent_Info';
9749           l_debug_str := 'FND_API.G_EXC_ERROR: Returning U from Update_Dependent_Info. '||SQLERRM;
9750           fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9751         END IF;
9752       RETURN 'U';
9753 
9754    WHEN OTHERS THEN
9755 
9756       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
9757          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
9758       END IF;
9759       Put_Log_Msg(l_api_name||' OTHERS return U',0);
9760       /* Debug */
9761         IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9762           l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Dependent_Info';
9763           l_debug_str := 'EXCEPTION: Returning U from Update_Dependent_Info. '||SQLERRM;
9764           fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9765         END IF;
9766 
9767       RETURN  'U';
9768 
9769 END Update_Dependent_Info;
9770 
9771 
9772 
9773 /******************************************************************
9774    Created By         : Arkadi Tereshenkov
9775 
9776    Date Created By    : Oct 14, 2002
9777 
9778    Purpose            : Update Employment information block
9779 
9780    Remarks            :
9781 
9782    Change History
9783    Who                  When            What
9784 ------------------------------------------------------------------------
9785 
9786 ******************************************************************/
9787 FUNCTION Update_Employment_Info (
9788    p_person_rec      IN OUT NOCOPY  t_student_rec    -- Person record
9789 ) RETURN VARCHAR2
9790 IS
9791 
9792    l_api_name    CONSTANT VARCHAR2(30)   := 'Update_Employment_Info';
9793    l_cur_rec    g_empl_rec_type;  ---IGS_SV_EMPL_INFO%ROWTYPE;  prbhardw
9794    l_prev_rec   IGS_SV_EMPL_INFO%ROWTYPE;
9795    l_status     VARCHAR2(1);
9796 
9797    l_count      NUMBER(10);
9798    l_current    NUMBER(10);
9799 
9800 BEGIN
9801 
9802    Put_Log_Msg(l_api_name||' begins ',0);
9803    /* Debug */
9804   IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9805      l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Employment_Info';
9806      l_debug_str := 'Entering Update_Employment_Info. p_person_rec.person_id is '||p_person_rec.person_id;
9807      fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9808   END IF;
9809 
9810    -- Call Validate_Empl_Info
9811 
9812     p_person_rec.empl_status  := Validate_Empl_Info (p_person_rec => p_person_rec,
9813                                                     p_data_rec   => l_cur_rec,
9814                                                     p_records    => l_count);
9815 
9816    IF p_person_rec.empl_status = 'E'  THEN -- Validation error - mark person as invalid
9817       p_person_rec.person_status := 'I';
9818       Put_Log_Msg('Validation error occurs ',0);
9819       /* Debug */
9820      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9821         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Employment_Info';
9822         l_debug_str := 'Returning S from Update_Employment_Info. empl_status is E.';
9823         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9824      END IF;
9825       RETURN 'S';
9826    ELSIF p_person_rec.empl_status = 'U' THEN --Unexpected error - terminate execution
9827       Put_Log_Msg('Unexpected error returned by validation ',0);
9828       /* Debug */
9829      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9830         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Employment_Info';
9831         l_debug_str := 'Unexpected error in Update_Employment_Info. empl_status is U.';
9832         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9833      END IF;
9834       RAISE FND_API.G_EXC_ERROR;
9835    ELSIF p_person_rec.empl_status = 'N' THEN -- Not found
9836       Put_Log_Msg('Employment block is not found ',0);
9837       /* Debug */
9838      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9839         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Employment_Info';
9840         l_debug_str := 'Returning S from Update_Employment_Info. empl_status is N.';
9841         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9842      END IF;
9843       RETURN 'S';
9844    END IF;
9845 
9846 FOR l_current IN 1.. l_count LOOP
9847 
9848       Put_Log_Msg('Checking employment  '||l_cur_rec(l_current).person_id,0);
9849       l_prev_rec.person_id := p_person_rec.person_id;
9850       l_prev_rec.nonimg_empl_id := l_cur_rec(l_current).nonimg_empl_id;
9851 
9852       p_person_rec.empl_status := 'S';  -- Changed
9853 
9854       l_status := Get_Empl_Info ( p_data_rec  => l_prev_rec);
9855 	/* Debug */
9856         IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9857           l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Employment_Info';
9858           l_debug_str := 'l_status from Get_Empl_Info: '||l_status;
9859           fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9860         END IF;
9861       IF l_status = 'U' THEN
9862        /* Debug */
9863         IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9864           l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Employment_Info';
9865           l_debug_str := 'Unexpected error in Update_Employment_Info. l_status is U.';
9866           fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9867         END IF;
9868          RAISE FND_API.G_EXC_ERROR;
9869       END IF;
9870 
9871       IF l_status = 'N'  THEN
9872         -- New employment record status A;
9873           l_cur_rec(l_current).action_code := 'A';
9874           p_person_rec.empl_status := 'C';  -- Changed
9875           p_person_rec.changes_found := 'Y';
9876           Put_Log_Msg('Info is changed for  '||l_cur_rec(l_current).person_id,0);
9877 
9878       ELSIF  l_status = 'S' THEN
9879 
9880 	    IF l_cur_rec(l_current).action_code IN ('N','A') THEN
9881 	        l_cur_rec(l_current).action_code := 'A';  -- add
9882 	    ELSE
9883 	        l_cur_rec(l_current).action_code := 'C';  -- cancel
9884 	    END IF;
9885 
9886             IF l_cur_rec(l_current).action_code <> l_prev_rec.action_code THEN
9887 		  p_person_rec.empl_status := 'C';  -- Changed
9888                   p_person_rec.changes_found := 'Y';
9889 	    ELSE
9890 		IF (l_cur_rec(l_current).empl_rec_type = 'F'  AND
9891 		(
9892 		   l_prev_rec.empl_rec_type
9893 		 ||g_delimeter||l_prev_rec.empl_type
9894 		 ||g_delimeter||l_prev_rec.recommend_empl
9895 		 ||g_delimeter||l_prev_rec.rescind_empl
9896 		 ||g_delimeter||l_prev_rec.remarks
9897 		 ||g_delimeter||l_prev_rec.empl_start_date
9898 		 ||g_delimeter||l_prev_rec.empl_end_date
9899 		 ||g_delimeter||l_prev_rec.course_relevance
9900 		 ||g_delimeter||l_prev_rec.empl_time
9901 		 ||g_delimeter||l_prev_rec.empl_name
9902 		 <>
9903 		   l_cur_rec(l_current).empl_rec_type
9904 		 ||g_delimeter||l_cur_rec(l_current).empl_type
9905 		 ||g_delimeter||l_cur_rec(l_current).recommend_empl
9906 		 ||g_delimeter||l_cur_rec(l_current).rescind_empl
9907 		 ||g_delimeter||l_cur_rec(l_current).remarks
9908 		 ||g_delimeter||l_cur_rec(l_current).empl_start_date
9909 		 ||g_delimeter||l_cur_rec(l_current).empl_end_date
9910 		 ||g_delimeter||l_cur_rec(l_current).course_relevance
9911 		 ||g_delimeter||l_cur_rec(l_current).empl_time
9912 		 ||g_delimeter||l_cur_rec(l_current).empl_name
9913 		 )) THEN
9914 		 Put_Log_Msg('Info is changed for  '||l_cur_rec(l_current).person_id,0);
9915 		  l_cur_rec(l_current).action_code := 'E';
9916 		  p_person_rec.empl_status := 'C';  -- Changed
9917 		  p_person_rec.changes_found := 'Y';
9918              END IF;
9919            END IF;
9920       ELSE   --Remove current person from the insert list
9921         l_cur_rec(l_current).person_id := NULL;
9922       END IF;
9923 
9924       IF p_person_rec.empl_status = 'C' AND p_person_rec.person_status <> 'I' THEN
9925 	Insert_Empl_Info ( p_data_rec  => l_cur_rec(l_current));
9926       END IF;
9927    END LOOP;
9928 
9929    Put_Log_Msg('Employment info is changed  ',0);
9930 
9931    Put_Log_Msg(l_api_name||' ends ',0);
9932    /* Debug */
9933         IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9934           l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Employment_Info';
9935           l_debug_str := 'Returning S from Update_Employment_Info.';
9936           fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9937         END IF;
9938    RETURN 'S';
9939 
9940 EXCEPTION
9941 
9942    WHEN FND_API.G_EXC_ERROR THEN
9943 
9944       Put_Log_Msg(l_api_name||' EXEC_ERROR returns U',0);
9945       /* Debug */
9946         IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9947           l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Employment_Info';
9948           l_debug_str := 'ND_API.G_EXC_ERROR: Returning U from Update_Employment_Info. '||SQLERRM;
9949           fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9950         END IF;
9951       RETURN 'U';
9952 
9953    WHEN OTHERS THEN
9954 
9955       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
9956          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
9957       END IF;
9958 
9959       Put_Log_Msg(l_api_name||' OTHERS return U',0);
9960       /* Debug */
9961         IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
9962           l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Employment_Info';
9963           l_debug_str := 'EXCEPTION: Returning U from Update_Employment_Info. '||SQLERRM;
9964           fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
9965         END IF;
9966 
9967       RETURN  'U';
9968 END Update_Employment_Info;
9969 
9970 
9971 
9972 /******************************************************************
9973    Created By         : Arkadi Tereshenkov
9974 
9975    Date Created By    : Oct 14, 2002
9976 
9977    Purpose            : Update Conviction block information.
9978 
9979    Remarks            :
9980 
9981    Change History
9982    Who                  When            What
9983 ------------------------------------------------------------------------
9984 
9985 ******************************************************************/
9986 FUNCTION Update_Conviction_Info (
9987    p_person_rec      IN OUT NOCOPY  t_student_rec    --Person record
9988 ) RETURN VARCHAR2
9989 
9990 IS
9991 
9992    l_api_name    CONSTANT VARCHAR2(30)   := 'Update_Conviction_Info';
9993    l_cur_rec    IGS_SV_CONVICTIONS%ROWTYPE;
9994    l_status     VARCHAR2(1);
9995    l_prev_rec   IGS_SV_CONVICTIONS%ROWTYPE;
9996 
9997 BEGIN
9998 
9999    Put_Log_Msg(l_api_name||' begins ',0);
10000    /* Debug */
10001   IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10002      l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Conviction_Info';
10003      l_debug_str := 'Entering Update_Conviction_Info. p_person_rec.person_id is '||p_person_rec.person_id;
10004      fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10005   END IF;
10006 
10007 
10008    -- Call Validate_Convictions_Info
10009 
10010    p_person_rec.conv_status  := Validate_Convictions_Info (p_person_rec => p_person_rec,
10011                                                             p_data_rec   => l_cur_rec);
10012 
10013    IF p_person_rec.conv_status = 'E'  THEN -- Validation error - mark person as invalid
10014 
10015       p_person_rec.person_status := 'I';
10016 
10017       Put_Log_Msg('Validation error occurs ',0);
10018       /* Debug */
10019      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10020         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Conviction_Info';
10021         l_debug_str := 'Returning S from Update_Conviction_Info. conv_status is E.';
10022         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10023      END IF;
10024 
10025       RETURN 'S';
10026 
10027    ELSIF p_person_rec.conv_status = 'U' THEN --Unexpected error - terminate execution
10028 
10029       Put_Log_Msg('Unexpected error returned by validation ',0);
10030       /* Debug */
10031      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10032         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Conviction_Info';
10033         l_debug_str := 'Unexpected error in Update_Conviction_Info. conv_status is U.';
10034         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10035      END IF;
10036 
10037       RAISE FND_API.G_EXC_ERROR;
10038 
10039    ELSIF p_person_rec.conv_status = 'N' THEN -- Not found
10040 
10041       Put_Log_Msg('Convictions block is not found ',0);
10042       /* Debug */
10043      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10044         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Conviction_Info';
10045         l_debug_str := 'Returning S from Update_Conviction_Info. conv_status is N.';
10046         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10047      END IF;
10048 
10049       RETURN 'S';
10050 
10051    END IF;
10052 
10053    -- If something is returned by the procedure - Insert it right away.
10054 
10055    Put_Log_Msg('Convictions info is changed  ',0);
10056 
10057    p_person_rec.changes_found := 'Y';
10058 
10059    IF p_person_rec.person_status <> 'I'  THEN
10060 
10061      Insert_Convictions_Info ( p_data_rec  => l_cur_rec);
10062 
10063    END IF;
10064 
10065    Put_Log_Msg(l_api_name||' ends ',0);
10066    /* Debug */
10067      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10068         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Conviction_Info';
10069         l_debug_str := 'Returning S from Update_Conviction_Info.';
10070         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10071      END IF;
10072 
10073    RETURN 'S';
10074 
10075 EXCEPTION
10076 
10077    WHEN FND_API.G_EXC_ERROR THEN
10078 
10079       Put_Log_Msg(l_api_name||' EXEC_ERROR returns U',0);
10080       /* Debug */
10081      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10082         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Conviction_Info';
10083         l_debug_str := 'FND_API.G_EXC_ERROR: Returning U from Update_Conviction_Info. '||SQLERRM;
10084         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10085      END IF;
10086       RETURN 'U';
10087 
10088    WHEN OTHERS THEN
10089 
10090       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
10091          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
10092       END IF;
10093 
10094       Put_Log_Msg(l_api_name||' OTHERS return U',0);
10095       /* Debug */
10096      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10097         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Update_Conviction_Info';
10098         l_debug_str := 'EXCEPTION: Returning U from Update_Conviction_Info. '||SQLERRM;
10099         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10100      END IF;
10101 
10102       RETURN  'U';
10103 
10104 END Update_Conviction_Info;
10105 
10106 
10107 
10108 /******************************************************************
10109    Created By         : Arkadi Tereshenkov
10110 
10111    Date Created By    : Oct 14, 2002
10112 
10113    Purpose            : This procedure cleans up tables for a person
10114                         if part of the information is not valid.
10115 
10116    Remarks            :
10117 
10118    Change History
10119    Who                  When            What
10120 ------------------------------------------------------------------------
10121 
10122 ******************************************************************/
10123 PROCEDURE Remove_Person_Data (
10124    p_person_id IN NUMBER,
10125    p_batch_id  IN NUMBER
10126 ) IS
10127 
10128 BEGIN
10129     /* Debug */
10130     IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10131        l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Remove_Person_Data';
10132        l_debug_str := 'Entering Remove_Person_Data. p_person_id is '||p_person_id||' and p_batch_id is '||p_batch_id;
10133        fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10134     END IF;
10135    -- Delete from all related tables
10136 
10137    DELETE FROM igs_sv_addresses WHERE batch_id = p_batch_id AND ( person_id = p_person_id OR p_person_id IS NULL );
10138 
10139    DELETE FROM igs_sv_addresses WHERE batch_id > p_batch_id AND ( person_id = p_person_id OR p_person_id IS NULL );
10140 
10141    DELETE FROM igs_sv_bio_info WHERE batch_id = p_batch_id AND ( person_id = p_person_id OR p_person_id IS NULL ) ;
10142 
10143    DELETE FROM igs_sv_convictions WHERE batch_id = p_batch_id AND ( person_id = p_person_id OR p_person_id IS NULL ) ;
10144 
10145    DELETE FROM igs_sv_depdnt_info WHERE batch_id = p_batch_id AND ( person_id = p_person_id OR p_person_id IS NULL ) ;
10146 
10147    DELETE FROM igs_sv_depdnt_info WHERE batch_id > p_batch_id AND ( person_id = p_person_id OR p_person_id IS NULL ) ;
10148 
10149    DELETE FROM igs_sv_empl_info WHERE batch_id = p_batch_id AND ( person_id = p_person_id OR p_person_id IS NULL ) ;
10150 
10151    DELETE FROM igs_sv_empl_info WHERE batch_id > p_batch_id AND ( person_id = p_person_id OR p_person_id IS NULL ) ;
10152 
10153    DELETE FROM igs_sv_finance_info WHERE batch_id = p_batch_id AND ( person_id = p_person_id OR p_person_id IS NULL ) ;
10154 
10155    DELETE FROM igs_sv_legal_info WHERE batch_id = p_batch_id AND ( person_id = p_person_id OR p_person_id IS NULL ) ;
10156 
10157    DELETE FROM igs_sv_oth_info WHERE batch_id = p_batch_id AND ( person_id = p_person_id OR p_person_id IS NULL ) ;
10158 
10159    DELETE FROM igs_sv_prgms_info WHERE batch_id = p_batch_id AND ( person_id = p_person_id OR p_person_id IS NULL ) ;
10160 
10161    DELETE FROM igs_sv_prgms_info WHERE batch_id > p_batch_id AND ( person_id = p_person_id OR p_person_id IS NULL ) ;
10162 
10163    DELETE FROM igs_sv_persons WHERE batch_id = p_batch_id AND ( person_id = p_person_id OR p_person_id IS NULL );
10164 
10165    DELETE FROM igs_sv_persons WHERE batch_id > p_batch_id AND ( person_id = p_person_id OR p_person_id IS NULL );
10166 
10167    DELETE FROM igs_sv_btch_summary WHERE batch_id = p_batch_id AND ( person_id = p_person_id OR p_person_id IS NULL );  -- prbhardw
10168 
10169    DELETE FROM igs_sv_btch_summary WHERE batch_id > p_batch_id AND ( person_id = p_person_id OR p_person_id IS NULL );  -- prbhardw
10170     /* Debug */
10171     IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10172        l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Remove_Person_Data';
10173        l_debug_str := 'Exiting Remove_Person_Data.';
10174        fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10175     END IF;
10176 
10177 END Remove_Person_Data;
10178 
10179 
10180 
10181 /******************************************************************
10182    Created By         : Arkadi Tereshenkov
10183 
10184    Date Created By    : Oct 14, 2002
10185 
10186    Purpose            : This is the main Concurrent program that is
10187                         called when submitting a request for the
10188                         Exchange Visitors.
10189 
10190    Remarks            :
10191 
10192    Change History
10193    Who                  When            What
10194 ------------------------------------------------------------------------
10195 mmkumar              12-Sep-2005      Added one more parameter for p_org_id
10196 ******************************************************************/
10197 PROCEDURE EV_Batch_Process(
10198    errbuf             OUT NOCOPY VARCHAR2,  -- Request standard error string
10199    retcode            OUT NOCOPY NUMBER  ,  -- Request standard return status
10200    p_validate_only    IN  VARCHAR2,  -- Validate only flag  'Y'  'N'
10201    p_org_id           IN VARCHAR2,
10202    p_dso_id           IN VARCHAR2
10203 )
10204 IS
10205 
10206    l_api_name    CONSTANT VARCHAR2(30)   := 'EV_Batch_Process';
10207 
10208    l_dso_id VARCHAR2(20) := substr(p_dso_id,1,instr(p_dso_id,'-',-1)-1) ;
10209    l_dso_party_id NUMBER := to_number(substr(p_dso_id,instr(p_dso_id,'-',-1)+1));
10210 
10211    l_org_id VARCHAR2(20) := substr(p_org_id,1,instr(p_org_id,'-',-1)-1) ;
10212    l_org_party_id NUMBER := to_number(substr(p_org_id,instr(p_org_id,'-',-1)+1));
10213 
10214 BEGIN
10215    -- Just call the procedure
10216    /* Debug */
10217    IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10218       l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.EV_Batch_Process';
10219       l_debug_str := 'Entering EV_Batch_Process. p_validate_only is '||p_validate_only;
10220       l_debug_str := l_debug_str || 'l_org_id=' || l_org_id;
10221       l_debug_str := l_debug_str || 'l_dso_id=' || l_dso_id;
10222       l_debug_str := l_debug_str || 'l_dso_party_id=' || l_dso_party_id;
10223       l_debug_str := l_debug_str || 'l_org_party_id=' || l_org_party_id;
10224       l_debug_str := l_debug_str || 'p_org_id=' || p_org_id;
10225       l_debug_str := l_debug_str || 'p_dso_id=' || p_dso_id;
10226       fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10227    END IF;
10228    SAVEPOINT EV_Batch_Process;
10229 
10230    Create_Batch(
10231      errbuf           => errbuf ,
10232      retcode          => retcode,
10233      p_batch_type     => 'E',
10234      p_validate_only  => p_validate_only,
10235      p_org_id         => l_org_id,
10236      p_dso_id	      => l_dso_id,
10237      p_dso_party_id   =>  l_dso_party_id,
10238      p_org_party_id   =>  l_org_party_id
10239    );
10240 EXCEPTION
10241 
10242    WHEN OTHERS THEN
10243      /* Debug */
10244    IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10245       l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.EV_Batch_Process';
10246       l_debug_str := 'Exception in EV_Batch_Process. '||SQLERRM;
10247       fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10248    END IF;
10249 
10250      ROLLBACK TO EV_Batch_Process;
10251 
10252       retcode := 2;
10253       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
10254          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
10255       END IF;
10256 
10257       Generate_Message;
10258 
10259 END EV_Batch_Process;
10260 
10261 
10262 FUNCTION Get_pre_noshow_status(p_person_id igs_sv_persons.person_id%TYPE, p_batch_id igs_sv_persons.person_id%TYPE)
10263 RETURN VARCHAR2
10264 IS
10265 l_no_show_status  VARCHAR2(1);
10266 CURSOR no_show_change(c_person_id igs_sv_persons.person_id%TYPE, c_batch_id igs_sv_persons.person_id%TYPE)
10267 IS
10268 SELECT old_per.no_show_flag
10269 FROM igs_sv_persons new_per, igs_sv_persons old_per
10270 WHERE new_per.person_id = c_person_id AND
10271       new_per.batch_id = c_batch_id AND
10272       old_per.batch_id = (SELECT max(batch_id) FROM igs_sv_persons WHERE batch_id < c_batch_id) AND
10273       old_per.person_id = new_per.person_id;
10274 BEGIN
10275 
10276   OPEN no_show_change(p_person_id,p_batch_id);
10277   FETCH no_show_change INTO l_no_show_status;
10278   CLOSE no_show_change;
10279 
10280   RETURN NVL(l_no_show_status,'N');
10281 
10282 END Get_pre_noshow_status;
10283 
10284 
10285 FUNCTION new_batch(
10286      p_batch_id igs_sv_batches.batch_id%TYPE,
10287      p_dso_id           VARCHAR2,
10288      p_org_id	        VARCHAR2,
10289      p_batch_type       VARCHAR2,
10290      p_org_party_id     NUMBER,
10291      p_user_party_id     NUMBER
10292      )
10293 RETURN NUMBER
10294 IS
10295    l_batch_id   igs_sv_batches.batch_id%TYPE;
10296 BEGIN
10297      DELETE FROM igs_sv_batches WHERE batch_id = p_batch_id;
10298      INSERT INTO igs_sv_batches
10299      ( batch_id,
10300        schema_version,
10301        sevis_user_id,
10302        sevis_school_id,
10303        batch_status,
10304        batch_type,
10305        creation_date ,
10306        created_by ,
10307        last_updated_by ,
10308        last_update_date ,
10309        last_update_login,
10310        SEVIS_SCHOOL_ORG_ID   ,
10311        SEVIS_USER_PERSON_ID
10312      )
10313      VALUES
10314      ( igs_sv_batches_id_s.nextval,
10315        1,
10316        p_dso_id,
10317        p_org_id,
10318        'S',
10319        p_batch_type,
10320        sysdate,
10321        g_update_by,
10322        g_update_by,
10323        sysdate,
10324        g_update_login,
10325        p_org_party_id,
10326        p_user_party_id
10327      )
10328      RETURNING batch_id INTO l_batch_id;
10329 
10330      RETURN l_batch_id;
10331 END new_batch;
10332 
10333 /******************************************************************
10334    Created By         : Arkadi Tereshenkov
10335 
10336    Date Created By    : Oct 14, 2002
10337 
10338    Purpose            : This is the main procedure to be called when
10339                         the request has been submitted for either the
10340                         Exchange Visitors or Non Immigrant students.
10341                         This procedure is called from the concurrent
10342                         requests.
10343 
10344    remarks            :
10345 
10346    Change History
10347    Who                  When            What
10348    pkpatel              22-APR-2003     Bug No 2908378
10349                                         Modified the action type to ('TR','ED') for EV records
10350                                         Added the code for inserting Site of Activity Address
10351 ------------------------------------------------------------------------
10352 mmkumar              12-Sep-2005     SEVIS 5 uptake, Added new parameter for Org ID
10353 ******************************************************************/
10354 PROCEDURE Create_Batch(
10355    errbuf             OUT NOCOPY VARCHAR2,  -- Request standard error string
10356    retcode            OUT NOCOPY NUMBER  ,  -- Request standard return status
10357    p_batch_type       IN  VARCHAR2,  -- Batch type E(ev),  I(international),   B (both)
10358    p_validate_only    IN  VARCHAR2,  -- Validate only flag  'Y'  'N'
10359    p_org_id           IN  VARCHAR2,
10360    p_dso_id	      IN  VARCHAR2,
10361    p_dso_party_id     IN  NUMBER,
10362    p_org_party_id     IN  NUMBER
10363 ) IS
10364 
10365    l_api_name  CONSTANT VARCHAR2(25) := 'Create_Batch';
10366    TYPE student_list_cur IS REF CURSOR;
10367    c_student_list   student_list_cur;
10368    c_student_list_rec  c_stdnt_list;
10369 -- select all persons from I-20 where form status is not Terminated or Completed and reported to SEVIS already
10370 
10371 
10372 
10373    l_batch_id         igs_sv_batches.batch_id%TYPE;
10374    l_person_sevis_id  IGS_SV_PERSONS.SEVIS_USER_ID%TYPE;
10375    l_issue_rec        IGS_SV_PERSONS%ROWTYPE;
10376    l_bio_rec          IGS_SV_BIO_INFO%ROWTYPE;
10377    l_oth_rec          IGS_SV_OTH_INFO%ROWTYPE;
10378    l_edu_rec          IGS_SV_PRGMS_INFO%ROWTYPE;
10379    l_fin_rec          IGS_SV_FINANCE_INFO %ROWTYPE;
10380    l_dep_rec          g_dependent_rec_type;
10381    l_f_addr_rec       g_address_rec_type;
10382    l_us_addr_rec      g_address_rec_type;
10383    l_site_addr_rec    g_address_rec_type;
10384    l_exist            NUMBER(25);
10385    l_submiter_id      NUMBER(25);
10386    l_submiter_number  hz_parties.party_number%TYPE;
10387    no_show_status     VARCHAR2(1);
10388    l_cur_authdrp_rec  IGS_SV_PRGMS_INFO%ROWTYPE;
10389    l_btch_id	      igs_sv_batches.batch_id%TYPE;
10390 
10391    CURSOR C_EV_CUR IS
10392    SELECT fr.person_id, min(ev_form_id) form_id, pr.party_number person_number, fr.no_show_flag, fr.reprint_reason reprint_reason
10393     FROM igs_pe_ev_form fr, hz_parties pr,  igs_pe_alt_pers_id alt
10394     WHERE pr.party_id = fr.person_id  AND fr.form_effective_date <= trunc(sysdate)
10395     AND fr.ev_form_id NOT IN
10396        (SELECT st.ev_form_id  FROM igs_pe_ev_form_stat st
10397         WHERE st.action_type IN ('TR','ED')
10398               AND st.ev_form_id = fr.ev_form_id
10399                AND st.ev_form_stat_id IN
10400                    ( SELECT NVL(prs.form_status_id,0) FROM igs_sv_prgms_info prs, igs_sv_persons pr
10401                      WHERE prs.person_id = pr.person_id AND prs.batch_id = pr.batch_id
10402                            AND pr.record_status <> 'E' AND prs.person_id = fr.person_id)
10403        ) AND fr.sevis_school_identifier = p_org_party_id AND
10404           (
10405 	    p_dso_id IS NULL OR
10406 	    fr.person_id IN (SELECT rel.object_id FROM hz_relationships rel, igs_pe_alt_pers_id alt
10407 	                          WHERE rel.subject_id = alt.pe_person_id and
10408 	                          alt.api_person_id = p_dso_id and
10409 	                          alt.person_id_type IN (SELECT person_id_type  FROM igs_pe_person_id_typ  WHERE s_person_id_type = 'SEVIS_ID')
10410 	    AND rel.DIRECTIONAL_FLAG = 'F' AND sysdate between rel.start_date AND nvl(end_date, sysdate)
10411 	    AND rel.RELATIONSHIP_CODE = 'NEXT_OF_KIN_OF')
10412 	   )
10413   GROUP BY  pr.party_number,fr.person_id,  fr.no_show_flag, fr.reprint_reason;
10414 
10415   CURSOR C_NI_CUR IS
10416    SELECT fr.person_id, min(nonimg_form_id) form_id, pr.party_number person_number, null no_show_flag, fr.reprint_reason reprint_reason
10417    FROM igs_pe_nonimg_form fr, hz_parties pr
10418    WHERE pr.party_id = fr.person_id
10419    AND fr.form_effective_date <= trunc(sysdate)
10420    AND fr.nonimg_form_id NOT IN
10421         ( SELECT st.nonimg_form_id FROM IGS_PE_NONIMG_STAT st
10422          WHERE st.action_type IN ('T','C')
10423          AND st.nonimg_form_id = fr.nonimg_form_id
10424          AND st.nonimg_stat_id IN
10425               ( SELECT NVL(prs.form_status_id,0)
10426                 FROM igs_sv_prgms_info prs, igs_sv_persons pr
10427                 WHERE prs.person_id = pr.person_id AND prs.batch_id = pr.batch_id
10428                 AND pr.record_status <> 'E' AND prs.person_id = fr.person_id
10429                 ) )
10430    AND fr.sevis_school_identifier = p_org_party_id AND
10431    ( p_dso_id IS NULL OR
10432      fr.person_id IN (SELECT rel.object_id
10433 	                    FROM hz_relationships rel, igs_pe_alt_pers_id alt
10434 	                    WHERE rel.subject_id = alt.pe_person_id and
10435 	                    alt.api_person_id = p_dso_id  and
10436 	                    alt.person_id_type IN (SELECT person_id_type FROM igs_pe_person_id_typ
10437 	   			    WHERE s_person_id_type = 'SEVIS_ID') AND
10438 	                    rel.DIRECTIONAL_FLAG = 'F' AND
10439 	                    sysdate between rel.start_date AND nvl(end_date, sysdate) AND
10440 	                    rel.RELATIONSHIP_CODE = 'NEXT_OF_KIN_OF')
10441  )
10442  GROUP BY  pr.party_number,fr.person_id, fr.reprint_reason;
10443 
10444 
10445    CURSOR c_submiter_id IS
10446      SELECT person_party_id
10447        FROM fnd_user
10448       WHERE user_id = g_update_by;
10449 
10450    CURSOR submiter_number_cur(cp_party_id hz_parties.party_id%TYPE) IS
10451    SELECT party_number
10452    FROM   hz_parties
10453    WHERE  party_id = cp_party_id;
10454 
10455    CURSOR c_prev_info( p_id NUMBER, f_id NUMBER) IS
10456      SELECT 1
10457       FROM igs_sv_persons a,
10458            igs_sv_batches b
10459      WHERE person_id = p_id
10460            AND a.batch_id = b.batch_id
10461            AND b.batch_type = p_batch_type
10462            AND a.record_status <> 'E'
10463            AND form_id = f_id;
10464 
10465    CURSOR c_active_batch IS
10466      SELECT batch_id
10467       FROM igs_sv_batches
10468      WHERE batch_status IN ('N')       -- prbhardw
10469            AND batch_type = p_batch_type;
10470 
10471    CURSOR c_print_form (p_form_id NUMBER) IS
10472      SELECT decode(print_form,'Y','1','0') print_form
10473        FROM igs_pe_nonimg_form
10474       WHERE nonimg_form_id = p_form_id
10475             AND p_batch_type = 'I'
10476       UNION
10477      SELECT decode(print_form,'Y','1','0') print_form
10478        FROM igs_pe_ev_form
10479       WHERE ev_form_id = p_form_id
10480             AND p_batch_type = 'E';
10481 
10482 
10483      ---prbhardw
10484      CURSOR c_prgm_print_flag (p_form_id NUMBER) IS
10485      SELECT decode(print_flag,'Y','1','0') print_form
10486        FROM igs_pe_nonimg_stat
10487       WHERE nonimg_form_id = p_form_id
10488             AND p_batch_type = 'I'
10489 	    AND action_type = 'E';
10490 
10491 
10492      CURSOR c_get_dso_id(c_person_id igs_pe_ev_form.person_id%TYPE)
10493      IS
10494           SELECT alt.api_person_id
10495 	  FROM hz_relationships rel, igs_pe_alt_pers_id alt
10496 	  WHERE rel.subject_id = c_person_id and
10497 	       rel.object_id = alt.pe_person_id AND
10498 	       sysdate between rel.start_date AND nvl(end_date, sysdate) AND
10499 	       rel.RELATIONSHIP_CODE = 'NEXT_OF_KIN_FOR' AND
10500 	       alt.person_id_type
10501 			       IN (SELECT person_id_type
10502 				     FROM igs_pe_person_id_typ
10503 				    WHERE s_person_id_type = 'SEVIS_ID');
10504 
10505 
10506 
10507 
10508    l_batch_status VARCHAR(1) := 'N';  -- batch status  (S)uccess, (E)rror,'N'o new students
10509    l_record_number igs_sv_persons.record_number%TYPE;
10510    l_student_rec   t_student_rec;
10511    l_status        VARCHAR2(1);
10512    l_count         NUMBER(10);
10513    l_soa_count	   NUMBER(5);   -- prbhardw CP enhancement
10514 
10515    l_sevis_user_person_id NUMBER;
10516 
10517    dso_id VARCHAR2(20) := p_dso_id;
10518    -- prbhardw
10519 
10520 BEGIN
10521 	/* Debug */
10522 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10523 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
10524 	   l_debug_str := 'Entering Create_Batch. p_batch_type is '||p_batch_type;
10525 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10526 	END IF;
10527 
10528    FND_MSG_PUB.initialize;
10529 
10530    SAVEPOINT Create_Batch;
10531    IF fnd_profile.value('IGS_SV_ENABLED') <> 'Y' THEN
10532 	/* Debug */
10533 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10534 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
10535 	   l_debug_str := 'Raise ERROR: Sevis Disabled';
10536 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10537 	END IF;
10538 
10539       FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_DISABLED'); -- SEVIS disabled
10540       FND_MSG_PUB.Add;
10541       RAISE FND_API.G_EXC_ERROR;
10542 
10543    END IF;
10544 
10545 
10546    IF fnd_profile.value('IGS_SV_DEBUG') <> 'Y' THEN
10547 
10548       g_debug_level := 1;
10549 
10550    END IF;
10551 
10552    g_update_login            := FND_GLOBAL.LOGIN_ID;
10553    g_update_by               := FND_GLOBAL.USER_ID;
10554 
10555    OPEN c_submiter_id;
10556    FETCH c_submiter_id
10557     INTO l_submiter_id;
10558    CLOSE c_submiter_id;
10559 
10560 
10561    l_record_number := 1;
10562    IF p_dso_id IS NULL THEN
10563 	   l_person_sevis_id  := get_person_sevis_id(l_submiter_id);
10564 	   IF l_person_sevis_id IS NULL THEN
10565 
10566 	      OPEN submiter_number_cur(l_submiter_id);
10567 	      FETCH submiter_number_cur INTO l_submiter_number;
10568 	      CLOSE submiter_number_cur;
10569 
10570 	      /* Debug */
10571 	      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10572 		 l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
10573 		 l_debug_str := 'Raise FND_API.G_EXC_ERROR: l_person_sevis_id is null';
10574 		 fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10575 	      END IF;
10576 
10577 	      FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_SUBMITTER_ID_ERR'); -- SEVIS submitter id not found
10578 	      FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', l_submiter_number);
10579 	      FND_MSG_PUB.Add;
10580 	      RAISE FND_API.G_EXC_ERROR;
10581 
10582 	   END IF;
10583 	   l_sevis_user_person_id := l_submiter_id;
10584    ELSE
10585 	l_person_sevis_id := p_dso_id;
10586 	l_sevis_user_person_id := p_dso_party_id;
10587    END IF;
10588    -- Check for active batch
10589    OPEN c_active_batch;
10590    FETCH c_active_batch INTO l_batch_id;
10591    CLOSE c_active_batch;
10592 
10593    IF l_batch_id IS NOT NULL AND p_validate_only = 'N' THEN
10594       /*Debug*/
10595       IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10596 	 l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
10597 	 l_debug_str := 'Raise ERROR: message name IGS_SV_BATCH_FOUND';
10598 	 fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10599       END IF;
10600 
10601      -- Active batch is found and mode not validate only - terminate current process
10602       FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_BATCH_FOUND');
10603       FND_MESSAGE.SET_TOKEN('BATCH_ID', l_batch_id);
10604       FND_MSG_PUB.Add;
10605       RAISE FND_API.G_EXC_ERROR;
10606 
10607    END IF;
10608    -- Create batch record
10609    Put_Log_Msg('Inserting batch record',0);
10610 
10611    INSERT INTO igs_sv_batches
10612      ( batch_id,
10613        schema_version,
10614        sevis_user_id,
10615        sevis_school_id,
10616        batch_status,
10617        batch_type,
10618        creation_date ,
10619        created_by ,
10620        last_updated_by ,
10621        last_update_date ,
10622        last_update_login,
10623        SEVIS_SCHOOL_ORG_ID,
10624        SEVIS_USER_PERSON_ID
10625      )
10626      VALUES
10627      ( igs_sv_batches_id_s.nextval,
10628        1,
10629        l_person_sevis_id,
10630        p_org_id,
10631        'S',
10632        p_batch_type,
10633        sysdate,
10634        g_update_by,
10635        g_update_by,
10636        sysdate,
10637        g_update_login,
10638        p_org_party_id,
10639        l_sevis_user_person_id
10640      )
10641      RETURNING batch_id INTO l_batch_id;
10642      g_running_create_batch := l_batch_id;        -- prbhardw CP enhancement
10643      g_running_update_batch  := l_batch_id;       -- prbhardw CP enhancement
10644      g_running_batches(1) := l_batch_id;
10645    -- Loop for each student
10646      IF p_batch_type ='I' THEN
10647          OPEN C_NI_CUR;
10648          FETCH C_NI_CUR INTO c_student_list_rec;
10649      ELSE
10650         OPEN C_EV_CUR;
10651         FETCH C_EV_CUR INTO c_student_list_rec;
10652      END IF;
10653 
10654    --FOR c_student_list_rec IN c_student_list LOOP
10655    LOOP			-- prbhardw
10656         IF p_batch_type ='I' THEN
10657 	      EXIT WHEN C_NI_CUR%NOTFOUND;
10658 	ELSE
10659 	   EXIT WHEN C_EV_CUR%NOTFOUND;
10660 	END IF;
10661      /*FETCH c_student_list INTO
10662           c_student_list_rec.person_id,
10663 	  c_student_list_rec.form_id,
10664 	  c_student_list_rec.person_number,
10665 	  c_student_list_rec.no_show_flag,
10666 	  c_student_list_rec.reprint_reason;
10667 
10668 	  EXIT WHEN c_student_list%NOTFOUND;*/
10669 
10670 	  -- check for total students
10671 	  IF g_create_count = 250 OR g_update_count = 250 THEN
10672 	       l_batch_id :=  new_batch(l_batch_id, l_person_sevis_id, p_org_id, p_batch_type,p_org_party_id,l_sevis_user_person_id);
10673 	       IF g_create_count = 250 THEN	-- prbhardw CP enhancement
10674 		    g_running_create_batch := l_batch_id;
10675 		    g_running_batches(g_running_batches.COUNT + 1) := g_running_create_batch;
10676 	       ELSE
10677 		    g_running_update_batch := l_batch_id;
10678 		    g_running_batches(g_running_batches.COUNT + 1) := g_running_update_batch;
10679 	       END IF;
10680           END IF;
10681 
10682 
10683 
10684       Put_Log_Msg('Initializing student record',0);
10685       /* Debug */
10686 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10687 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
10688 	   l_debug_str := 'Setting person values in Create_Batch Person ID '||c_student_list_rec.person_id||' Person No: '||c_student_list_rec.person_number;
10689 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10690 	END IF;
10691       --  Initialize record group for the student
10692       l_student_rec.person_id     := c_student_list_rec.person_id;
10693       l_student_rec.record_number := l_record_number;
10694       l_student_rec.record_status := 'N'; -- so far new
10695       l_student_rec.person_number := c_student_list_rec.person_number;
10696       l_student_rec.form_id       := c_student_list_rec.form_id;
10697       l_student_rec.sevis_user_id := get_person_sevis_id(l_student_rec.person_id);
10698       l_student_rec.person_status := 'V';
10699       l_student_rec.batch_type    := p_batch_type;
10700       l_student_rec.batch_id      := l_batch_id;
10701       l_student_rec.changes_found := 'N';
10702       l_student_rec.dep_flag      := 'N';
10703       l_student_rec.no_show_flag := c_student_list_rec.no_show_flag;
10704       l_student_rec.reprint_reason := c_student_list_rec.reprint_reason; --prbhardw
10705 
10706       -- Check if the student has been submitted to sevis
10707 
10708       OPEN c_prev_info ( l_student_rec.person_id , c_student_list_rec.form_id);
10709       FETCH c_prev_info
10710        INTO l_exist;
10711 
10712       -- Assign mode to the record
10713 
10714       Put_Log_Msg('',1);
10715       Put_Log_Msg('*******************Next person '||l_student_rec.person_number||'**************************',0);
10716 
10717       IF c_prev_info%FOUND THEN
10718          l_student_rec.record_status := 'C';  --change mode
10719          -- If mode update - check SEVIS person Id
10720 
10721          FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_STUDENT_UPD'); -- Student is found in Update mode
10722          FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', l_student_rec.person_number);
10723          Put_Log_Msg(FND_MESSAGE.Get,1);
10724 
10725          IF l_student_rec.sevis_user_id IS NULL THEN
10726 
10727             FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_STUDENT_ID_ERR'); -- SEVIS STUDENT id not found
10728             FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', l_student_rec.person_number);
10729             Put_Log_Msg(FND_MESSAGE.Get,1);
10730             Put_Log_Msg('Sevis id not found',0);
10731 
10732             l_student_rec.person_status := 'I';
10733 
10734          END IF;
10735 
10736       ELSE
10737 
10738         FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_STUDENT_CRT'); -- Student is found in Create mode
10739         FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', l_student_rec.person_number);
10740         Put_Log_Msg(FND_MESSAGE.Get,1);
10741 
10742       END IF;
10743 
10744       CLOSE c_prev_info;
10745 
10746       Put_Log_Msg('Person status is: '||l_student_rec.person_status,0);
10747 
10748       IF l_student_rec.person_status = 'V' THEN
10749 
10750         OPEN c_print_form(l_student_rec.form_id);
10751         FETCH c_print_form INTO l_student_rec.print_form;
10752         CLOSE c_print_form;
10753 
10754          -- Create main student record
10755 	 IF dso_id IS NULL THEN
10756 	       OPEN c_get_dso_id(l_student_rec.person_id);
10757 	       FETCH c_get_dso_id INTO dso_id;
10758 	       CLOSE c_get_dso_id;
10759 	 END IF;
10760 	 /* Debug */
10761 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10762 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
10763 	   l_debug_str := 'Inserting in igs_sv_persons batch id: '||l_batch_id;
10764 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10765 	END IF;
10766          INSERT INTO igs_sv_persons (
10767              batch_id     ,
10768              person_id    ,
10769              record_number,
10770              form_id      ,
10771              print_form   ,
10772 	     pdso_sevis_id,
10773              record_status,
10774              person_number,
10775              sevis_user_id,
10776              creation_date,
10777              created_by             ,
10778              last_updated_by        ,
10779              last_update_date       ,
10780              last_update_login,
10781 	     no_show_flag,
10782 	     reprint_rsn_code,
10783 	     PDSO_SEVIS_PERSON_ID
10784             ) VALUES (
10785              l_batch_id,
10786              l_student_rec.person_id,
10787              l_student_rec.record_number,
10788              l_student_rec.form_id,
10789              l_student_rec.print_form,
10790 	     dso_id,
10791              l_student_rec.record_status,
10792              l_student_rec.person_number,
10793              l_student_rec.sevis_user_id,
10794              sysdate,
10795              g_update_by,
10796              g_update_by,
10797              sysdate,
10798              g_update_login,
10799 	     l_student_rec.no_show_flag,
10800 	     l_student_rec.reprint_reason,
10801              p_dso_party_id
10802             );
10803       END IF;
10804 
10805            g_nonimg_form_id := l_student_rec.form_id;
10806 
10807      IF l_student_rec.record_status = 'N' THEN
10808       g_person_status := 'NEW';
10809              -- If mode new
10810 
10811          -- Call Validate_Issue_Info  and Insert_Issue_Info
10812 
10813          -- 'S' - record found and validated 'E' - validation error 'U' - Unexpected error  'N' - data not found
10814 
10815 
10816          l_student_rec.issue_status := Validate_Issue_Info (p_person_rec => l_student_rec,
10817                                                             p_data_rec  => l_issue_rec);
10818          -- Call Validate_Bio_Info  and Insert_Bio_Info
10819          l_student_rec.bio_status  := Validate_Bio_Info (p_person_rec => l_student_rec,
10820                                                          p_data_rec  => l_bio_rec);
10821          -- Call Validate_US_address_Info Insert_Address_Info
10822          l_student_rec.us_addr_status  := Validate_Us_Addr_Info (p_person_rec => l_student_rec,
10823                                                                  p_data_rec   => l_us_addr_rec,
10824                                                                  p_records    => l_count);
10825          -- Call Validate_Finance_Info Insert_Finance_Info
10826          l_student_rec.fin_status  := Validate_Finance_Info (p_person_rec => l_student_rec,
10827                                                              p_data_rec  => l_fin_rec);
10828 
10829          -- Call Validate_EDU_Info Insert_EDU_Info
10830 
10831           l_student_rec.edu_status  := Validate_Edu_Info (p_person_rec => l_student_rec,
10832                                                            p_data_rec   => l_edu_rec);
10833           IF p_batch_type = 'I' THEN
10834 
10835            -- 2908378 added, since site of activity is only specific to EV
10836            l_student_rec.site_addr_status := 'S'; -- For EV only
10837 
10838            -- Call Validate_Other_Info Insert_Other_Info
10839 
10840            l_student_rec.other_status  := Validate_Other_Info (p_person_rec => l_student_rec,
10841                                                                p_data_rec  => l_oth_rec);
10842            -- Call Validate_F_Addr_Info  Insert_Address_Info
10843            l_student_rec.f_addr_status  := Validate_F_Addr_Info (p_person_rec => l_student_rec,
10844                                                                 p_data_rec   => l_f_addr_rec,
10845                                                                 p_records    => l_count);
10846 	  ELSE
10847 
10848             l_student_rec.f_addr_status := 'S'; --for Non-Img only
10849             l_student_rec.other_status := 'S'; --for Non-Img only
10850 
10851            -- 2908378 passed l_site_addr_rec for capturing the Site of Activity Address
10852            l_student_rec.site_addr_status  := Validate_Site_Info (p_person_rec => l_student_rec,
10853                                                                  p_data_rec   => l_site_addr_rec,
10854                                                                  p_records    => l_count);
10855            l_soa_count := l_count;
10856            IF l_student_rec.site_addr_status      = 'U'  THEN --Unexpected error - terminate execution
10857 	      /* Debug */
10858 		IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10859 		  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
10860 		  l_debug_str := 'Returning U from Create_Batch. site_addr_status is U.';
10861 		  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10862 		END IF;
10863 
10864               RAISE FND_API.G_EXC_ERROR;
10865 
10866            END IF;
10867 
10868           END IF;
10869 
10870          -- Call Validate_Dependent_Info Insert_Dependent_Info
10871 
10872          l_student_rec.dep_status  := Validate_Dependent_Info (p_person_rec => l_student_rec,
10873                                                                p_data_rec   => l_dep_rec,
10874                                                                p_records    => l_count );
10875 
10876          l_student_rec.dep_count   := l_count;
10877          -- check all statuses
10878          -- 2908378 added validation with l_student_rec.site_addr_status
10879          IF l_student_rec.issue_status = 'E'
10880             OR l_student_rec.bio_status = 'E'
10881             OR l_student_rec.other_status = 'E'
10882             OR l_student_rec.f_addr_status  = 'E'
10883             OR l_student_rec.us_addr_status = 'E'
10884             OR l_student_rec.site_addr_status = 'E'
10885             OR l_student_rec.edu_status  = 'E'
10886             OR l_student_rec.fin_status  = 'E'
10887             OR l_student_rec.dep_status = 'E' THEN -- Validation error - mark person as invalid
10888 
10889             l_student_rec.person_status := 'I';
10890 
10891          END IF;
10892          IF l_student_rec.issue_status      = 'U'
10893             OR l_student_rec.bio_status     = 'U'
10894             OR l_student_rec.other_status   = 'U'
10895             OR l_student_rec.f_addr_status  = 'U'
10896             OR l_student_rec.us_addr_status = 'U'
10897             OR l_student_rec.site_addr_status = 'U'
10898             OR l_student_rec.edu_status     = 'U'
10899             OR l_student_rec.fin_status     = 'U'
10900             OR l_student_rec.dep_status     = 'U'  THEN --Unexpected error - terminate execution
10901 
10902             RAISE FND_API.G_EXC_ERROR;
10903 
10904          ELSIF l_student_rec.issue_status = 'N'
10905             OR l_student_rec.bio_status   = 'N'
10906             OR l_student_rec.edu_status   = 'N'
10907             OR l_student_rec.fin_status   = 'N' THEN -- Not found
10908 
10909             -- These are I-20 blocks and should be found. If this happens - its a bug
10910 
10911             FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_UNEXP_EXCPT_ERR'); -- I-20 is missing! Unexpected error
10912             FND_MESSAGE.SET_TOKEN('BLOCK_ID',5);
10913             FND_MSG_PUB.Add;
10914                /* Debug */
10915 		IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
10916 		  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
10917 		  l_debug_str := 'IGS_SV_UNEXP_EXCPT_ERR in Create_Batch.';
10918 		  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
10919 		END IF;
10920 
10921             RAISE FND_API.G_EXC_ERROR;
10922 
10923          END IF;
10924 
10925          -- Check for required blocks
10926 
10927          IF l_student_rec.f_addr_status = 'N' AND p_batch_type = 'I' THEN
10928 
10929             FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_NO_F_ADDR_FLD_ERR'); -- Foreign address not found
10930             FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', l_student_rec.person_number);
10931             Put_Log_Msg(FND_MESSAGE.Get,1);
10932 
10933             l_student_rec.person_status := 'I';
10934 
10935          END IF;
10936          IF l_student_rec.us_addr_status = 'N' AND p_batch_type = 'E' THEN
10937 
10938             FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_NO_US_ADDR_FLD_ERR'); -- US address not found
10939             FND_MESSAGE.SET_TOKEN('PERSON_NUMBER', l_student_rec.person_number);
10940             Put_Log_Msg(FND_MESSAGE.Get,1);
10941 
10942             l_student_rec.person_status := 'I';
10943 
10944          END IF;
10945          IF l_student_rec.person_status = 'V' THEN
10946            l_record_number := l_record_number +1;
10947 	   g_create_count := g_create_count +1; -- prbhardw CP enhancement
10948 
10949 	   l_student_rec.record_number := g_create_count;  -- prbhardw CP enhancement
10950 
10951            Put_Log_Msg(' Inserting data ',0);
10952 
10953            l_student_rec.changes_found := 'Y' ;
10954 
10955             -- Insertion of everything.
10956 
10957             Update_Issue_Info ( p_data_rec  => l_issue_rec);
10958 
10959             Insert_Bio_Info ( p_data_rec  => l_bio_rec);
10960 
10961             IF l_student_rec.other_status = 'S' and p_batch_type ='I' THEN
10962 
10963                Insert_Other_Info ( p_data_rec  => l_oth_rec);
10964 
10965             END IF;
10966 
10967             Insert_Edu_Info ('EDU', p_data_rec  => l_edu_rec, p_auth_drp_data_rec => l_cur_authdrp_rec);
10968 
10969             IF p_batch_type ='I' THEN
10970 
10971               Insert_Address_Info ('F', p_data_rec  => l_f_addr_rec,p_records => 1);   --- prbhardw CP enhancement
10972 
10973             END IF;
10974 
10975             IF l_student_rec.us_addr_status = 'S' THEN
10976 
10977                Insert_Address_Info ( 'US',p_data_rec  => l_us_addr_rec,p_records => 1);   --- prbhardw CP enhancement
10978 
10979             END IF;
10980             -- 2908378 added to insert site of activity
10981             IF  l_student_rec.site_addr_status = 'S' AND p_batch_type ='E' THEN
10982                Insert_Address_Info ('SOA', p_data_rec  => l_site_addr_rec,p_records => l_soa_count);   --- prbhardw CP enhancement
10983             END IF;
10984 
10985             Insert_Finance_Info ( p_data_rec  => l_fin_rec);
10986 
10987             IF l_student_rec.dep_status = 'S' THEN
10988 
10989               Insert_Dependent_Info ( p_data_rec  => l_dep_rec,p_records   => l_student_rec.dep_count  );
10990 
10991             END IF;
10992 
10993          ELSE
10994 
10995            Put_Log_Msg(' No insertion, person_status is:'||l_student_rec.person_status ,0);
10996 
10997          END IF;  -- Insertion ends here
10998      ELSE
10999           g_person_status := 'EDIT';
11000           l_record_number := l_record_number +1;
11001 	  g_update_count := g_update_count +1; -- prbhardw CP enhancement
11002 	  l_student_rec.record_number := g_update_count; -- prbhardw CP enhancement
11003 
11004           IF p_batch_type = 'I' THEN -- If mode update for Non immigrants
11005 
11006                -- IF l_student_rec.changes_found <> 'Y' THEN   --- commented by prbhardw
11007 
11008 		     -- Call Update_Employment_Info
11009                     l_status := Update_Employment_Info ( p_person_rec  => l_student_rec  );
11010 
11011 		    IF l_status <> 'S' THEN
11012 				/* Debug */
11013 			 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11014 				l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
11015 				l_debug_str := 'ERROR in Create_Batch. l_status from Update_Employment_Info is not S';
11016 				fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11017 			 END IF;
11018 			 RAISE FND_API.G_EXC_ERROR;
11019 		    END IF;
11020 
11021              --  END IF;
11022 
11023 	   -- Call Update_Registration_Info
11024 	       l_status := Update_Registration_Info ( p_person_rec  => l_student_rec  );
11025                IF l_status <> 'S' THEN
11026 	      /* Debug */
11027 		    IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11028 		         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
11029 		         l_debug_str := 'ERROR in Create_Batch. l_status is not S';
11030 		         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11031 		    END IF;
11032 
11033                     RAISE FND_API.G_EXC_ERROR;
11034                END IF;
11035               -- IF l_student_rec.changes_found <> 'Y' THEN    --- commented by prbhardw
11036 
11037                       -- Call Update_Personal_Info
11038                     l_status := Update_Personal_Info ( p_person_rec  => l_student_rec  );
11039 
11040                     IF l_status <> 'S' THEN
11041 				/* Debug */
11042 		         IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11043 		               l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
11044 		               l_debug_str := 'ERROR in Create_Batch. changes_found <> Y and l_status is not S';
11045 		               fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11046 		         END IF;
11047                          RAISE FND_API.G_EXC_ERROR;
11048                     END IF;
11049              --  END IF;
11050               -- IF l_student_rec.changes_found <> 'Y' THEN   --- commented by prbhardw
11051 
11052 			-- Call Update_Program_Info
11053                     l_status := Update_Program_Info ( p_person_rec  => l_student_rec  );
11054 
11055                     IF l_status <> 'S' THEN
11056 				/* Debug */
11057 		         IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11058 		               l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
11059 		               l_debug_str := 'ERROR in Create_Batch. l_status from Update_Program_Info is not S';
11060 		               fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11061 		         END IF;
11062 
11063                          RAISE FND_API.G_EXC_ERROR;
11064                     END IF;
11065             --   END IF;
11066 
11067              --  IF l_student_rec.changes_found <> 'Y' THEN   --- commented by prbhardw
11068 
11069 			-- Call Update_Finance_Info
11070                     l_status := Update_Finance_Info ( p_person_rec  => l_student_rec  );
11071 
11072                     IF l_status <> 'S' THEN
11073 				/* Debug */
11074 		         IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11075 				l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
11076 				l_debug_str := 'ERROR in Create_Batch. l_status from Update_Finance_Info is not S';
11077 				fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11078 		         END IF;
11079                          RAISE FND_API.G_EXC_ERROR;
11080                     END IF;
11081               -- END IF;
11082 
11083              --  IF l_student_rec.changes_found <> 'Y' THEN   --- commented by prbhardw
11084 
11085 			-- Call Update_Dependent_Info
11086                     l_status := Update_Dependent_Info ( p_person_rec  => l_student_rec  );
11087 
11088 		    IF l_status <> 'S' THEN
11089 				/* Debug */
11090 			 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11091 				l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
11092 				l_debug_str := 'ERROR in Create_Batch. l_status from Update_Dependent_Info is not S';
11093 				fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11094 			 END IF;
11095 			 RAISE FND_API.G_EXC_ERROR;
11096 		    END IF;
11097 
11098 	      -- END IF;
11099 
11100              --  IF l_student_rec.changes_found <> 'Y' THEN   --- commented by prbhardw
11101 
11102 			-- Call Update_Conviction_Info
11103                     l_status := Update_Conviction_Info ( p_person_rec  => l_student_rec  );
11104 
11105 		    IF l_status <> 'S' THEN
11106 				/* Debug */
11107 			 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11108 				l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
11109 				l_debug_str := 'ERROR in Create_Batch. l_status from Update_Conviction_Info is not S';
11110 				fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11111 			 END IF;
11112 			 RAISE FND_API.G_EXC_ERROR;
11113                     END IF;
11114 
11115              --  END IF;
11116 
11117           ELSE  -- Update for EV student
11118          -------
11119 	  IF l_student_rec.no_show_flag =  'Y' THEN
11120                IF Get_pre_noshow_status(l_student_rec.person_id,l_student_rec.batch_id) = 'Y' THEN
11121                     l_student_rec.changes_found := 'N';
11122                ELSE
11123 	            l_student_rec.changes_found := 'Y';
11124 		   l_btch_id := chk_mut_exclusive(l_student_rec.batch_id,
11125 				       l_student_rec.person_id,
11126 				       'NOSHOW',
11127 				       'SV_STATUS');
11128 		    Insert_Summary_Info(l_btch_id,
11129 				       l_student_rec.person_id,
11130 				       'NOSHOW',
11131 				       'SV_STATUS',
11132 				       'SEND',
11133 				       'IGS_SV_PERSONS',
11134 				       '');
11135 	       END IF;
11136 	  ELSE
11137 
11138 
11139 
11140 	   --IF no_show_status <> l_student_rec.no_show_flag AND l_student_rec.no_show_flag <> 'Y' THEN
11141 
11142 		   l_status := Update_Personal_Info ( p_person_rec  => l_student_rec  );
11143 
11144 		   IF l_status <> 'S' THEN
11145 			/* Debug */
11146 			IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11147 			  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
11148 			  l_debug_str := 'ERROR in Create_Batch. l_status from Update_Personal_Info is not S';
11149 			  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11150 			END IF;
11151 
11152 		      RAISE FND_API.G_EXC_ERROR;
11153 		   END IF;
11154 		    l_status := Update_ev_legal_Info ( p_person_rec  => l_student_rec  );
11155                    IF l_status <> 'S' THEN
11156 	               /* Debug */
11157 		       IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11158 		            l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
11159 		            l_debug_str := 'ERROR in Create_Batch. Update_ev_legal_Info status is not S';
11160 		            fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11161 		       END IF;
11162 
11163                        RAISE FND_API.G_EXC_ERROR;
11164                    END IF;
11165 
11166 		 --  IF l_student_rec.changes_found <> 'Y' THEN   --- commented by prbhardw
11167 		     -- Call Update_Finance_Info
11168 		     l_status := Update_Finance_Info ( p_person_rec  => l_student_rec  );
11169 
11170 
11171 		     IF l_status <> 'S' THEN
11172 		       /* Debug */
11173 			IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11174 			  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
11175 			  l_debug_str := 'ERROR in Create_Batch. l_status from Update_Finance_Info is not S';
11176 			  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11177 			END IF;
11178 		       RAISE FND_API.G_EXC_ERROR;
11179 		     END IF;
11180 		 --  END IF;
11181 
11182 		 --  IF l_student_rec.changes_found <> 'Y' THEN   --- commented by prbhardw
11183 
11184 		     -- Call Update_EV_Program_Info
11185 		     l_status := Update_EV_Program_Info ( p_person_rec  => l_student_rec  );
11186 
11187 
11188 		     IF l_status <> 'S' THEN
11189 		       /* Debug */
11190 			IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11191 			  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
11192 			  l_debug_str := 'ERROR in Create_Batch. l_status from Update_EV_Program_Info is not S';
11193 			  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11194 			END IF;
11195 		       RAISE FND_API.G_EXC_ERROR;
11196 		     END IF;
11197 		 --  END IF;
11198 
11199 		 --  IF l_student_rec.changes_found <> 'Y' THEN   --- commented by prbhardw
11200 
11201 		     -- Call Update_EV_Address_Info
11202 		     l_status := Update_EV_Address_Info ( p_person_rec  => l_student_rec  );
11203 
11204 
11205 		     IF l_status <> 'S' THEN
11206 		       /* Debug */
11207 			IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11208 			  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
11209 			  l_debug_str := 'ERROR in Create_Batch. l_status from Update_EV_Address_Info is not S';
11210 			  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11211 			END IF;
11212 		       RAISE FND_API.G_EXC_ERROR;
11213 		     END IF;
11214 
11215 		   --END IF;
11216 		 --  IF l_student_rec.changes_found <> 'Y' THEN   --- commented by prbhardw
11217 
11218 		     -- Call Update_Dependent_Info
11219 		     l_status := Update_Dependent_Info ( p_person_rec  => l_student_rec  );
11220 
11221 
11222 		     IF l_status <> 'S' THEN
11223 		       /* Debug */
11224 			IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11225 			  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
11226 			  l_debug_str := 'ERROR in Create_Batch. l_status from Update_Dependent_Info is not S';
11227 			  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11228 			END IF;
11229 		       RAISE FND_API.G_EXC_ERROR;
11230 		     END IF;
11231 
11232 		 --  END IF;
11233 		    --PRBHARDW
11234 		    IF Get_pre_noshow_status(l_student_rec.person_id,l_student_rec.batch_id) = 'Y' THEN
11235 			    l_student_rec.changes_found := 'Y';
11236 		    END IF;
11237 		    IF l_student_rec.reprint_reason = '06' THEN
11238 			l_student_rec.changes_found := 'Y';
11239 		    END IF;
11240 		    --PRBHARDW
11241 
11242 		 END IF;
11243 
11244 	      END IF;
11245 	  END IF;
11246       IF l_student_rec.person_status = 'I' THEN
11247 
11248          --Remove all person data from tables
11249 
11250         Remove_Person_Data(p_person_id => l_student_rec.person_id, p_batch_id => l_batch_id);
11251 
11252         FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_STUDENT_INVALID'); -- Student has validation error - not processed
11253         Put_Log_Msg(FND_MESSAGE.Get,1);
11254 
11255       ELSIF l_student_rec.changes_found = 'Y' THEN
11256 
11257         IF  p_validate_only ='N' THEN
11258 
11259           FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_STUDENT_SUCCESS'); -- Student successfully processed
11260           Put_Log_Msg(FND_MESSAGE.Get,1);
11261 
11262         ELSE
11263 
11264           FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_STDNT_VALID_SUCC'); -- Student successfully processed
11265           Put_Log_Msg(FND_MESSAGE.Get,1);
11266 
11267         END IF;
11268 
11269         l_batch_status :='S';
11270 
11271       ELSIF l_student_rec.changes_found = 'N' THEN
11272 
11273          --Remove all person data from tables
11274         Remove_Person_Data(p_person_id => l_student_rec.person_id, p_batch_id => l_batch_id);
11275 
11276         FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_STUDENT_NO_CHANGE'); -- No changes found for the student
11277         Put_Log_Msg(FND_MESSAGE.Get,1);
11278 
11279       END IF;
11280         IF p_batch_type ='I' THEN
11281 	      FETCH C_NI_CUR INTO c_student_list_rec;
11282 	ELSE
11283 	   FETCH C_EV_CUR INTO c_student_list_rec;
11284 	END IF;
11285    END LOOP;
11286 
11287         IF p_batch_type ='I' THEN
11288 	      CLOSE C_NI_CUR;
11289 	ELSE
11290 	   CLOSE C_EV_CUR ;
11291 	END IF;
11292 
11293 
11294 
11295    IF l_batch_status = 'N' THEN
11296      -- no students for the batch - change
11297 
11298       FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_NO_STUDENTS'); -- No students found to submit
11299       Put_Log_Msg(FND_MESSAGE.Get,1);
11300 
11301       DELETE FROM igs_sv_batches WHERE batch_id = l_batch_id;
11302 
11303    END IF;
11304 
11305    /*
11306    IF l_record_number >=250 THEN
11307 
11308       FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_MAX_RECORDS'); -- Too many students.
11309       Put_Log_Msg(FND_MESSAGE.Get,1);
11310 
11311    END IF;
11312    */
11313 
11314 
11315 
11316    -- Check batch validate and invalid flag
11317 
11318    -- Rollback since batch shouldn't be saved
11319 
11320    --Raise an event for WF and commit
11321    IF l_batch_status = 'S' AND p_validate_only ='N' THEN
11322 
11323     -- Submit_Event ( p_batch_type, l_batch_id);
11324        null;
11325    ELSE
11326      Remove_Person_Data (p_person_id => NULL, p_batch_id => l_batch_id );
11327       DELETE FROM igs_sv_batches WHERE batch_id = l_batch_id;
11328       DELETE FROM igs_sv_batches WHERE batch_id > l_batch_id;
11329    END IF;
11330 /* Debug */
11331 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11332   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
11333   l_debug_str := 'Commiting in Create_Batch. l_batch_status: '||l_batch_status;
11334   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11335 END IF;
11336    compose_log_file;
11337 
11338    COMMIT;
11339 
11340    retcode := 0;
11341 
11342 EXCEPTION
11343 
11344    WHEN FND_API.G_EXC_ERROR THEN
11345       /* Debug */
11346 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11347 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
11348 	  l_debug_str := 'FND_API.G_EXC_ERROR exception in Create_Batch. '||SQLERRM;
11349 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11350 	END IF;
11351       ROLLBACK TO Create_Batch;
11352       retcode := 2;
11353       dump_current_person(l_student_rec);
11354         IF C_NI_CUR%ISOPEN THEN
11355 	      CLOSE C_NI_CUR;
11356 	ELSIF C_EV_CUR%ISOPEN THEN
11357 	   CLOSE C_EV_CUR ;
11358 	END IF;
11359       Generate_Message;
11360 
11361    WHEN OTHERS THEN
11362 
11363       /* Debug */
11364 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11365 	  l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Create_Batch';
11366 	  l_debug_str := 'Other exception in Create_Batch. '||SQLERRM;
11367 	  fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11368 	END IF;
11369       ROLLBACK TO Create_Batch;
11370       retcode := 2;
11371       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
11372          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
11373       END IF;
11374 
11375       dump_current_person(l_student_rec);
11376         IF C_NI_CUR%ISOPEN THEN
11377 	      CLOSE C_NI_CUR;
11378 	ELSIF C_EV_CUR%ISOPEN THEN
11379 	   CLOSE C_EV_CUR ;
11380 	END IF;
11381       Generate_Message;
11382 
11383 END Create_Batch;
11384 
11385 
11386 
11387 
11388 /******************************************************************
11389    Created By         : Arkadi Tereshenkov
11390 
11391    Date Created By    : Oct 14, 2002
11392 
11393    Purpose            : This is the main concurrent program called when
11394                         submitting request for the non immigrant students
11395 
11396    Remarks            :
11397 
11398    Change History
11399    Who                  When            What
11400 ------------------------------------------------------------------------
11401 
11402 ******************************************************************/
11403 PROCEDURE NIMG_Batch_Process(
11404    errbuf             OUT NOCOPY VARCHAR2,  -- Request standard error string
11405    retcode            OUT NOCOPY NUMBER  ,  -- Request standard return status
11406    p_validate_only    IN  VARCHAR2,  -- Validate only flag  'Y'  'N'
11407    p_org_id           IN  VARCHAR2,
11408    p_dso_id           IN  VARCHAR2
11409 ) IS
11410 
11411    l_api_name    CONSTANT VARCHAR2(30)   := 'NIMG_Batch_Process';
11412 
11413    l_dso_id VARCHAR2(20) := substr(p_dso_id,1,instr(p_dso_id,'-',-1)-1) ;
11414    l_dso_party_id NUMBER := to_number(substr(p_dso_id,instr(p_dso_id,'-',-1)+1));
11415 
11416    l_org_id VARCHAR2(20) := substr(p_org_id,1,instr(p_org_id,'-',-1)-1) ;
11417    l_org_party_id NUMBER := to_number(substr(p_org_id,instr(p_org_id,'-',-1)+1));
11418 
11419 
11420 BEGIN
11421    /* Debug */
11422   IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11423      l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.NIMG_Batch_Process';
11424      l_debug_str := 'Entering NIMG_Batch_Process.';
11425       l_debug_str := l_debug_str || 'l_org_id=' || l_org_id;
11426       l_debug_str := l_debug_str || 'l_dso_id=' || l_dso_id;
11427       l_debug_str := l_debug_str || 'l_dso_party_id=' || l_dso_party_id;
11428       l_debug_str := l_debug_str || 'l_org_party_id=' || l_org_party_id;
11429       l_debug_str := l_debug_str || 'p_org_id=' || p_org_id;
11430       l_debug_str := l_debug_str || 'p_dso_id=' || p_dso_id;
11431 
11432      fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11433   END IF;
11434 
11435    -- Just call the procedure
11436    SAVEPOINT NIMG_Batch_Process;
11437 
11438    Create_Batch(
11439      errbuf           => errbuf ,
11440      retcode          => retcode,
11441      p_batch_type     => 'I',
11442      p_validate_only  => p_validate_only ,
11443      p_org_id         => l_org_id,
11444      p_dso_id         => l_dso_id,
11445      p_dso_party_id   => l_dso_party_id,
11446      p_org_party_id   => l_org_party_id
11447      ) ;
11448 
11449 EXCEPTION
11450 
11451    WHEN OTHERS THEN
11452 
11453       /* Debug */
11454      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11455        l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.NIMG_Batch_Process';
11456        l_debug_str := 'Exception in NIMG_Batch_Process. '||SQLERRM;
11457        fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11458      END IF;
11459 
11460       ROLLBACK TO NIMG_Batch_Process;
11461 
11462       retcode := 2;
11463       errbuf := SQLERRM;
11464       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
11465          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
11466       END IF;
11467 
11468       Generate_Message;
11469 
11470 END NIMG_Batch_Process;
11471 
11472 
11473 
11474 /******************************************************************
11475    Created By         : Arkadi Tereshenkov
11476 
11477    Date Created By    : Oct 14, 2002
11478 
11479    Purpose            : This is the main procedure to be called when
11480                         the request has to be purged for
11481                         Exchange Visitors or Non Immigrant students.
11482                         This procedure is called from the concurrent
11483                         requests.
11484 
11485    remarks            :
11486 
11487    Change History
11488    Who                  When            What
11489 ------------------------------------------------------------------------
11490 
11491 ******************************************************************/
11492 PROCEDURE Purge_Batch(
11493    errbuf             OUT NOCOPY VARCHAR2,  -- Request standard error string
11494    retcode            OUT NOCOPY NUMBER  ,  -- Request standard return status
11495    p_batch_type       IN  VARCHAR2   -- Batch type E(ev),  I(international)
11496 ) IS
11497 
11498    l_api_name  CONSTANT VARCHAR2(25) := 'Purge_Batch';
11499    l_batch_id         igs_sv_batches.batch_id%TYPE;
11500 
11501    CURSOR c_active_batch IS
11502      SELECT batch_id
11503       FROM igs_sv_batches
11504      WHERE batch_status IN ('S','N')
11505            AND batch_type = p_batch_type;
11506 
11507 BEGIN
11508 
11509    /* Debug */
11510      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11511        l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Purge_Batch';
11512        l_debug_str := 'Entering Purge_Batch. p_batch_type is '||p_batch_type;
11513        fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11514      END IF;
11515    FND_MSG_PUB.initialize;
11516 
11517    SAVEPOINT Purge_Batch;
11518 
11519    -- Check for active batch
11520 
11521    OPEN c_active_batch;
11522    FETCH c_active_batch INTO l_batch_id;
11523    CLOSE c_active_batch;
11524 
11525    IF l_batch_id IS NULL THEN
11526      -- Active batch is not found and mode not validate only - terminate current process
11527       FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_NO_BATCH_FOUND');
11528       Put_Log_Msg(FND_MESSAGE.Get,1);
11529 
11530    ELSE
11531 
11532      --Remove batch
11533      Remove_Person_Data (p_person_id => NULL, p_batch_id => l_batch_id );
11534 
11535      DELETE FROM igs_sv_batches WHERE batch_id = l_batch_id;
11536      DELETE FROM igs_sv_batches WHERE batch_id > l_batch_id;
11537 
11538    END IF;
11539 
11540    retcode := 0;
11541    /* Debug */
11542      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11543        l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.NIMG_Batch_Process';
11544        l_debug_str := 'retcode in NIMG_Batch_Process: '||retcode;
11545        fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11546      END IF;
11547 EXCEPTION
11548 
11549    WHEN FND_API.G_EXC_ERROR THEN
11550 
11551       /* Debug */
11552      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11553        l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.NIMG_Batch_Process';
11554        l_debug_str := 'FND_API.G_EXC_ERROR Exception in NIMG_Batch_Process. '||SQLERRM;
11555        fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11556      END IF;
11557       ROLLBACK TO Purge_Batch;
11558 
11559       retcode := 2;
11560 
11561       Generate_Message;
11562 
11563    WHEN OTHERS THEN
11564 
11565       /* Debug */
11566      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11567        l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.NIMG_Batch_Process';
11568        l_debug_str := 'Exception in NIMG_Batch_Process. '||SQLERRM;
11569        fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11570      END IF;
11571       ROLLBACK TO Purge_Batch;
11572 
11573       retcode := 2;
11574 
11575       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
11576          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
11577       END IF;
11578 
11579       Generate_Message;
11580 
11581 END Purge_Batch;
11582 
11583 
11584 
11585 
11586 /******************************************************************
11587    Created By         : Arkadi Tereshenkov
11588 
11589    Date Created By    : Oct 14, 2002
11590 
11591    Purpose            : This is the main procedure to be called when
11592                         there is a need to purge EV data.
11593 
11594    Remarks            :
11595 
11596    Change History
11597    Who                  When            What
11598 ------------------------------------------------------------------------
11599 
11600 ******************************************************************/
11601 PROCEDURE EV_Purge_Batch (
11602   errbuf         OUT NOCOPY VARCHAR2,  -- Request standard error string
11603   retcode        OUT NOCOPY NUMBER    -- Request standard return status
11604 ) IS
11605    l_api_name       CONSTANT VARCHAR2(30)   := 'EV_Purge_Batch';
11606    l_return_status  VARCHAR2(1);
11607    l_msg_count      NUMBER;
11608    l_msg_data       VARCHAR2(2000);
11609 
11610 BEGIN
11611    /* Debug */
11612   IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11613      l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.EV_Purge_Batch';
11614      l_debug_str := 'Entering EV_Purge_Batch.';
11615      fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11616   END IF;
11617    -- Just call the procedure
11618 
11619    Purge_Batch(
11620      errbuf           => errbuf ,
11621      retcode          => retcode,
11622      p_batch_type     => 'E') ;
11623 
11624 EXCEPTION
11625 
11626    WHEN OTHERS THEN
11627       /* Debug */
11628      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11629         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.EV_Purge_Batch';
11630         l_debug_str := 'EXCEPTION in EV_Purge_Batch. '||SQLERRM;
11631         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11632      END IF;
11633       retcode := 2;
11634 
11635       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
11636          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
11637       END IF;
11638 
11639       Generate_Message;
11640 
11641 END EV_Purge_Batch;
11642 
11643 
11644 
11645 
11646 /******************************************************************
11647    Created By         : Arkadi Tereshenkov
11648 
11649    Date Created By    : Oct 14, 2002
11650 
11651    Purpose            : This is the main procedure to be called when
11652                         there is a need to purge Non immigrant data.
11653 
11654    Remarks            :
11655 
11656    Change History
11657    Who                  When            What
11658 ------------------------------------------------------------------------
11659 
11660 ******************************************************************/
11661 PROCEDURE NIMG_Purge_Batch (
11662   errbuf         OUT NOCOPY VARCHAR2,  -- Request standard error string
11663   retcode        OUT NOCOPY NUMBER    -- Request standard return status
11664 ) IS
11665    l_api_name       CONSTANT VARCHAR2(30)   := 'NIMG_Purge_Batch';
11666    l_return_status  VARCHAR2(1);
11667    l_msg_count      NUMBER;
11668    l_msg_data       VARCHAR2(2000);
11669 
11670 BEGIN
11671 
11672    /* Debug */
11673      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11674         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.NIMG_Purge_Batch';
11675         l_debug_str := 'Entering NIMG_Purge_Batch.';
11676         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11677      END IF;
11678    -- Just call the procedure
11679 
11680    SAVEPOINT NIMG_Purge_Batch;
11681 
11682    Purge_Batch(
11683      errbuf           => errbuf ,
11684      retcode          => retcode,
11685      p_batch_type     => 'I') ;
11686 
11687 EXCEPTION
11688 
11689    WHEN OTHERS THEN
11690        /* Debug */
11691      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11692         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.NIMG_Purge_Batch';
11693         l_debug_str := 'EXCEPTION in NIMG_Purge_Batch. '||SQLERRM;
11694         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11695      END IF;
11696       ROLLBACK TO NIMG_Purge_Batch;
11697 
11698       retcode := 2;
11699 
11700       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
11701          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
11702       END IF;
11703 
11704       Generate_Message;
11705 
11706 END NIMG_Purge_Batch;
11707 
11708 
11709 /******************************************************************
11710    Created By         : Arkadi Tereshenkov
11711 
11712    Date Created By    : Oct 14, 2002
11713 
11714    Purpose            : Used to generate messages that are to be output
11715                         into the concurrent request log.
11716 
11717    Remarks            :
11718 
11719    Change History
11720    Who                  When            What
11721 ------------------------------------------------------------------------
11722 
11723 ******************************************************************/
11724 PROCEDURE Generate_Message
11725 IS
11726 
11727    l_msg_count      NUMBER;
11728    l_msg_data       VARCHAR2(2000);
11729 
11730 BEGIN
11731    /* Debug */
11732      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11733         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Generate_Message';
11734         l_debug_str := 'Entering Generate_Message.';
11735         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11736      END IF;
11737    FND_MSg_PUB.Count_And_Get ( p_count => l_msg_count,
11738                                p_data  => l_msg_data );
11739 
11740    IF (l_msg_count > 0) THEN
11741 
11742       l_msg_data := '';
11743 
11744       FOR l_cur IN 1..l_msg_count LOOP
11745 
11746          l_msg_data := FND_MSg_PUB.GET(l_cur, FND_API.g_FALSE);
11747          Put_Log_Msg(l_msg_data,1);
11748       END LOOP;
11749 
11750    ELSE
11751 
11752          l_msg_data  := 'Error Returned but Error stack has no data';
11753          Put_Log_Msg(l_msg_data,1);
11754 
11755    END IF;
11756     /* Debug */
11757      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11758         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Generate_Message';
11759         l_debug_str := 'Exiting Generate_Message. l_msg_data is: '||l_msg_data;
11760         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11761      END IF;
11762 END Generate_Message;
11763 
11764 
11765 
11766 /******************************************************************
11767    Created By         : Arkadi Tereshenkov
11768 
11769    Date Created By    : Oct 14, 2002
11770 
11771    Purpose            : Place the messages that have been generated into
11772                         the appropriate log file for viewing.
11773 
11774    Remarks            :
11775 
11776    Change History
11777    Who                  When            What
11778 ------------------------------------------------------------------------
11779 
11780 ******************************************************************/
11781 PROCEDURE Put_Log_Msg (
11782    p_message IN VARCHAR2,
11783    p_level         IN NUMBER
11784 ) IS
11785 
11786    l_api_name             CONSTANT VARCHAR2(30)   := 'Put_Log_Msg';
11787 
11788 BEGIN
11789 
11790     -- This procedure outputs messages into the log file  Level 0 - System messages. 1 - user messages
11791     IF p_level >= g_debug_level THEN
11792 
11793       fnd_file.put_line (FND_FILE.LOG,p_message);
11794 
11795     END IF;
11796 
11797 END Put_Log_Msg;
11798 
11799 
11800 PROCEDURE process_person_record (
11801   p_BatchID        IN NUMBER,
11802   p_sevisID        IN VARCHAR2,
11803   p_person_id      IN NUMBER,
11804   p_Status         IN VARCHAR2,
11805   p_SEVIS_ErrorCode    IN VARCHAR2,
11806   p_SEVIS_ErrorElement IN VARCHAR2
11807 )
11808 IS
11809   l_rowid  VARCHAR2(255);
11810   l_alt_id igs_pe_person_id_typ.person_id_type%TYPE;
11811 
11812 
11813   CURSOR c_alt IS
11814    SELECT person_id_type
11815      FROM igs_pe_person_id_typ
11816     WHERE s_person_id_type = g_person_sevis_id AND
11817           closed_ind = 'N';
11818 
11819 
11820 BEGIN
11821     /* Debug */
11822      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11823         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.process_person_record';
11824         l_debug_str := 'Entering process_person_record. p_sevisID is: '||p_sevisID||' and p_person_id is: '||p_person_id;
11825         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11826      END IF;
11827 
11828  IF lower(p_Status) <> 'true' THEN
11829 
11830     UPDATE igs_sv_persons
11831        SET record_status = 'E',
11832            sevis_error_code = p_SEVIS_ErrorCode,
11833            sevis_error_element = p_SEVIS_ErrorElement
11834      WHERE batch_id = p_BatchID
11835            AND person_id = p_person_id;
11836 
11837   -- purge the person data completely.
11838 
11839 --    Remove_Person_Data (p_person_id => p_person_id, p_batch_id => p_BatchID );
11840 
11841   ELSIF  NVL(Get_Person_Sevis_Id (p_person_id),'X') <> p_sevisID THEN
11842 
11843    -- Update sevis id
11844    -- end date current one (if any)
11845 
11846    UPDATE igs_pe_alt_pers_id
11847       SET end_dt = trunc(sysdate)
11848     WHERE pe_person_id = p_person_id
11849           AND person_id_type
11850               IN (SELECT person_id_type
11851                     FROM igs_pe_person_id_typ
11852                    WHERE s_person_id_type = g_person_sevis_id)
11853            AND start_dt <= trunc(sysdate)
11854            AND NVL(end_dt,sysdate+1) >= trunc(sysdate) ;
11855 
11856       OPEN c_alt;
11857       FETCH c_alt INTO l_alt_id;
11858       CLOSE c_alt;
11859 
11860      -- Insert new
11861      IGS_PE_ALT_PERS_ID_PKG.INSERT_ROW (
11862          X_ROWID         => l_rowid,
11863          X_PE_PERSON_ID  => p_person_id,
11864          X_API_PERSON_ID => p_sevisID,
11865          X_API_PERSON_ID_UF => p_sevisID,
11866          X_PERSON_ID_TYPE => l_alt_id,
11867          X_START_DT       => trunc(sysdate),
11868          X_END_DT         => NULL,
11869          X_attribute_category => '',
11870          X_attribute1          => '',
11871          X_attribute2          => '',
11872          X_attribute3          => '',
11873          X_attribute4          => '',
11874          X_attribute5          => '',
11875          X_attribute6          => '',
11876          X_attribute7          => '',
11877          X_attribute8          => '',
11878          X_attribute9          => '',
11879          X_attribute10         => '',
11880          X_attribute11         => '',
11881          X_attribute12         => '',
11882          X_attribute13         => '',
11883          X_attribute14         => '',
11884          X_attribute15         => '',
11885          X_attribute16         => '',
11886          X_attribute17         => '',
11887          X_attribute18         => '',
11888          X_attribute19         => '',
11889          X_attribute20         => '',
11890          X_MODE                => 'I'
11891       );
11892 
11893 
11894   END IF;
11895    /* Debug */
11896      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11897         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.process_person_record';
11898         l_debug_str := 'Exiting process_person_record';
11899         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11900      END IF;
11901 
11902 END process_person_record;
11903 
11904 PROCEDURE process_trans_header (
11905   p_BatchID        IN NUMBER,
11906   p_FileErrorCode  IN VARCHAR2,
11907   p_FileValidation IN VARCHAR2)
11908 IS
11909 /*----------------------------------------------------------
11910 p_FileErrorCode => The resultCode attribute is set to success if all submitted records process successfully.
11911                                 Otherwise, the resultCode indicates either indicates that:
11912 
11913 				1) file has not yet been processed or
11914 
11915 				2) the file has been processed with at least one record failing business rules validation
11916 				(although all other records are successfully loaded into SEVIS)
11917 
11918 p_FileValidation => The status attribute is set to true if there are no errors associated with this batch submittal.
11919 
11920 ----------------------------------------------------------*/
11921    l_api_name       CONSTANT VARCHAR2(30)   := 'process_trans_header';
11922 
11923   CURSOR c_batch IS
11924     SELECT batch_status
11925       FROM igs_sv_batches
11926      WHERE batch_id = p_BatchID;
11927 
11928   l_status igs_sv_batches.batch_status%TYPE;
11929 
11930 
11931 BEGIN
11932 
11933      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11934         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.process_trans_header';
11935         l_debug_str := 'Came in with p_BatchID = '||p_BatchID||'  p_FileErrorCode = '||p_FileErrorCode ||' p_FileValidation = '||p_FileValidation||' '||SQLERRM;
11936         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11937      END IF;
11938 
11939   SAVEPOINT process_trans_header;
11940 
11941   -- S0001 - successfull download.
11942   -- p_FileValidation - true
11943 
11944   OPEN c_batch;
11945   FETCH c_batch INTO l_status;
11946 
11947   IF c_batch%NOTFOUND THEN
11948 
11949      CLOSE c_batch;
11950      FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_BATCH_NOT_FOUND'); -- Batch not found
11951      FND_MESSAGE.SET_TOKEN('BATCH_ID',p_BatchID);
11952      FND_MSG_PUB.Add;
11953 
11954      RAISE FND_API.G_EXC_ERROR;
11955 
11956   END IF;
11957 
11958   CLOSE c_batch;
11959 
11960   IF lower(p_FileValidation) = 'true' OR p_FileValidation='1' THEN
11961     -- successfull batch transmition.
11962 
11963     IF l_status <>'S' THEN
11964        FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_INVALID_STATUS'); -- Batch is not in process
11965        FND_MESSAGE.SET_TOKEN('BATCH_ID',p_BatchID);
11966        FND_MSG_PUB.Add;
11967 
11968        RAISE FND_API.G_EXC_ERROR;
11969 
11970     END IF;
11971 
11972     -- Update batch  and set success status
11973     UPDATE igs_sv_batches SET batch_status = 'P' WHERE batch_id = p_BatchID;
11974 
11975   ELSE
11976     -- purge the batch completely.
11977 
11978     Remove_Person_Data (p_person_id => NULL, p_batch_id => p_BatchID );
11979 
11980     UPDATE igs_sv_batches SET batch_status = 'E', SEVIS_ERROR_CODE = NVL(p_FileErrorCode,NVL(p_FileValidation,'X')) WHERE batch_id = p_BatchID;
11981 
11982   END IF;
11983 EXCEPTION
11984    WHEN FND_API.G_EXC_ERROR THEN
11985       /* Debug */
11986      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11987         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.process_trans_header';
11988         l_debug_str := 'FND_API.G_EXC_ERROR in process_trans_header '||SQLERRM;
11989         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11990      END IF;
11991       ROLLBACK TO process_trans_header;
11992    WHEN OTHERS THEN
11993        /* Debug */
11994        IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
11995           l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.process_trans_header';
11996           l_debug_str := 'Exiting process_trans_header '||SQLERRM;
11997           fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
11998        END IF;
11999       ROLLBACK TO process_trans_header;
12000 
12001       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
12002          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
12003       END IF;
12004 END process_trans_header;
12005 
12006 PROCEDURE process_trans_errors (
12007   p_BatchID        IN NUMBER,
12008   p_ErrorCode      IN VARCHAR2,
12009   p_ErrorMessage   IN VARCHAR2,
12010   x_return_status  OUT NOCOPY VARCHAR2
12011 )
12012 IS
12013 BEGIN
12014   NULL;
12015 END process_trans_errors;
12016 
12017 
12018 PROCEDURE process_student_record (
12019   p_BatchID        IN NUMBER,
12020   p_sevisID        IN VARCHAR2,
12021   p_PersonID   IN VARCHAR2,
12022   p_Status         IN VARCHAR2,
12023   p_SEVIS_ErrorCode    IN VARCHAR2,
12024   p_SEVIS_ErrorElement IN VARCHAR2)
12025 
12026 
12027 IS
12028 /*----------------------------------------------------------
12029 p_SEVIS_ErrorCode => SEVIS defined error code
12030 
12031 p_SEVIS_ErrorElement => Error message
12032 
12033 p_PersonID => User defined field B for principal record
12034 
12035 p_Status => The status attribute is set to true if this record is successfully loaded into SEVIS.  If the attempt failed, then the list of errors appear below this element
12036 
12037 ----------------------------------------------------------*/
12038   l_api_name   CONSTANT VARCHAR2(30)   := 'process_student_record';
12039   l_person_id  NUMBER(15);
12040 
12041 
12042 BEGIN
12043 
12044      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
12045         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.process_student_record';
12046         l_debug_str := 'Came in with p_BatchID = '||p_BatchID||'  p_sevisID = '||p_sevisID
12047 		||'  p_PersonID = '||p_PersonID|| ' p_Status = '||p_Status
12048 		||'  p_SEVIS_ErrorCode = '||p_SEVIS_ErrorCode||'  p_SEVIS_ErrorElement = '||p_SEVIS_ErrorElement||' '||SQLERRM;
12049         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
12050      END IF;
12051 
12052 
12053     SAVEPOINT process_student_record;
12054 
12055 
12056   l_person_id := to_number(p_PersonID);
12057 
12058   process_person_record (
12059     p_BatchID        => p_BatchID,
12060     p_sevisID        => p_sevisID,
12061     p_person_id      => l_person_id,
12062     p_Status         => p_Status,
12063     p_SEVIS_ErrorCode    => p_SEVIS_ErrorCode,
12064     p_SEVIS_ErrorElement => p_SEVIS_ErrorElement
12065   );
12066 
12067 update igs_sv_persons set SEVIS_USER_ID = p_sevisID ,
12068         SEVIS_ERROR_CODE = p_SEVIS_ErrorCode, SEVIS_ERROR_ELEMENT  = p_SEVIS_ErrorElement
12069         where person_id = p_PersonID;
12070 
12071 EXCEPTION
12072 
12073    WHEN FND_API.G_EXC_ERROR THEN
12074 
12075       ROLLBACK TO process_student_record;
12076 
12077       RAISE FND_API.G_EXC_ERROR;
12078 
12079    WHEN OTHERS THEN
12080 
12081       ROLLBACK TO process_student_record;
12082 
12083       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
12084          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
12085       END IF;
12086 
12087       RAISE FND_API.G_EXC_ERROR;
12088 
12089 
12090 END process_student_record;
12091 
12092 PROCEDURE process_dep_record (
12093   p_BatchID        IN NUMBER,
12094   p_DepPersonID        IN NUMBER,
12095   p_DepSevisID        IN VARCHAR2,
12096   p_PersonID   IN VARCHAR2,
12097   p_Status         IN VARCHAR2,
12098   p_SEVIS_ErrorCode    IN VARCHAR2,
12099   p_SEVIS_ErrorElement IN VARCHAR2
12100 
12101   )
12102 IS
12103 /*----------------------------------------------------------
12104 p_SEVIS_ErrorCode => SEVIS defined error code
12105 
12106 p_SEVIS_ErrorElement => Error message
12107 
12108 p_DepPersonID => User defined field B for principal record
12109 
12110 p_Status => The status attribute is set to true if this record is successfully loaded into SEVIS.  If the attempt failed, then the list of errors appear below this element
12111 
12112 ----------------------------------------------------------*/
12113 
12114   l_api_name   CONSTANT VARCHAR2(30)   := 'process_dep_record';
12115   l_person_id  NUMBER(15);
12116   l_temp VARCHAR2(1);
12117 
12118 CURSOR c_dep IS
12119     SELECT  '1'
12120       FROM IGS_SV_DEPDNT_INFO
12121      WHERE PERSON_ID = p_PersonID and DEPDNT_ID  = p_DepPersonID;
12122 
12123 
12124 BEGIN
12125      IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
12126         l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.process_dep_record';
12127         l_debug_str := 'Came in with p_BatchID = '||p_BatchID||'  p_DepPersonID = '||p_DepPersonID
12128 		||'  p_DepSevisID = '||p_DepSevisID||'  p_PersonID = '||p_PersonID
12129 		|| ' p_Status = '||p_Status||'  p_SEVIS_ErrorCode = '
12130 		||p_SEVIS_ErrorCode||'  p_SEVIS_ErrorElement = '||p_SEVIS_ErrorElement||' '||SQLERRM;
12131         fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
12132      END IF;
12133 
12134   OPEN c_dep;
12135   FETCH c_dep INTO l_temp;
12136 
12137   IF c_dep%NOTFOUND THEN
12138 
12139      CLOSE c_dep;
12140 
12141      FND_MESSAGE.SET_NAME('IGS', 'IGS_SV_DEP_NOT_FOUND'); -- Dependent not found
12142      FND_MESSAGE.SET_TOKEN('PERSON_ID',p_PersonID);
12143      FND_MSG_PUB.Add;
12144 
12145      RAISE FND_API.G_EXC_ERROR;
12146 
12147   END IF;
12148 
12149   CLOSE c_dep;
12150 
12151   l_person_id := to_number(p_DepPersonID);
12152   process_person_record (
12153     p_BatchID        => p_BatchID,
12154     p_sevisID        => p_DepSevisID,
12155     p_person_id      => l_person_id,
12156     p_Status         => p_Status,
12157     p_SEVIS_ErrorCode    => p_SEVIS_ErrorCode,
12158     p_SEVIS_ErrorElement => p_SEVIS_ErrorElement
12159   );
12160 
12161     UPDATE IGS_SV_DEPDNT_INFO SET DEPDNT_SEVIS_ID = p_DepSevisID WHERE PERSON_ID = p_PersonID and DEPDNT_ID  = p_DepPersonID;
12162 
12163 EXCEPTION
12164 
12165    WHEN FND_API.G_EXC_ERROR THEN
12166       ROLLBACK TO process_dep_record;
12167    WHEN OTHERS THEN
12168       ROLLBACK TO process_dep_record;
12169       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
12170          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
12171       END IF;
12172 END process_dep_record;
12173 
12174 /******************************************************************
12175    Created By         : prbhardw
12176 
12177    Date Created By    : Dec 30, 2005
12178 
12179    Purpose            : Insert batch summary into igs_sv_btch_summary before inserting in interface tables.
12180 
12181    Change History
12182    Who                  When            What
12183 ------------------------------------------------------------------------
12184 
12185 ******************************************************************/
12186 PROCEDURE Insert_Summary_Info(
12187    p_batch_id  IN  igs_sv_btch_summary.batch_id%TYPE,
12188    p_person_id  IN  igs_sv_btch_summary.person_id%TYPE,
12189    p_action_code  IN  igs_sv_btch_summary.action_code%TYPE,
12190    p_tag_code  IN  igs_sv_btch_summary.tag_code%TYPE,
12191    p_adm_action IN  igs_sv_btch_summary.adm_action_code%TYPE,
12192    p_owner_table_name IN igs_sv_btch_summary.owner_table_name%TYPE,
12193    p_owner_table_id  IN  igs_sv_btch_summary.OWNER_TABLE_IDENTIFIER%TYPE
12194 )
12195 IS
12196    l_api_name CONSTANT VARCHAR(30) := 'Insert_Summary_Info';
12197 l_count NUMBER;
12198 CURSOR c_test IS
12199 SELECT max(batch_id) FROM IGS_SV_BTCH_SUMMARY;
12200 l_batch NUMBER(20) := 0;
12201 BEGIN
12202 /* Debug */
12203 IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
12204    l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Summary_Info';
12205    l_debug_str := 'Entering Insert_Summary_Info. p_data_rec.person_id is '||p_person_id|| ' and batch_id is '||p_batch_id;
12206    fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
12207 END IF;
12208 
12209    INSERT INTO IGS_SV_BTCH_SUMMARY (
12210         summary_id	       ,
12211         batch_id               ,
12212         person_id              ,
12213         action_code            ,
12214 	tag_code               ,
12215 	adm_action_code        ,
12216 	creation_date          ,
12217 	created_by             ,
12218 	last_updated_by        ,
12219 	last_update_date       ,
12220 	last_update_login      ,
12221 	owner_table_name,
12222 	OWNER_TABLE_IDENTIFIER         --mmkumar, owner_table_id
12223      ) VALUES
12224      (
12225       IGS_SV_BTCH_SUMM_ID_S.nextval    ,
12226        p_batch_id  ,
12227        p_person_id  ,
12228        p_action_code ,
12229        p_tag_code  ,
12230        p_adm_action ,
12231        sysdate,
12232        g_update_by,
12233        g_update_by,
12234        sysdate,
12235        g_update_login,
12236        p_owner_table_name,
12237        p_owner_table_id
12238      );
12239 
12240   OPEN c_test;
12241   FETCH c_test INTO l_batch;
12242   CLOSE c_test;
12243      /* Debug */
12244 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
12245 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Summary_Info';
12246 	   l_debug_str := 'record in Insert_Summary_Info max batch_id: '||l_batch;
12247 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
12248 	END IF;
12249 EXCEPTION
12250 
12251   WHEN OTHERS THEN
12252       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
12253          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
12254       END IF;
12255       /* Debug */
12256 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
12257 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Insert_Summary_Info';
12258 	   l_debug_str := 'EXCEPTION in Insert_Summary_Info. '||SQLERRM;
12259 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
12260 	END IF;
12261       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
12262       RAISE;
12263 
12264 END Insert_Summary_Info;
12265 
12266 
12267 /******************************************************************
12268    Created By         : prbhardw
12269 
12270    Date Created By    : Jan 03, 2006
12271 
12272    Purpose            : Code to submit event and generate XML has been seperated
12273                         from create_batch as part of SEVIS enhancements.
12274 
12275    Change History
12276    Who                  When            What
12277 ------------------------------------------------------------------------
12278 
12279 ******************************************************************/
12280 PROCEDURE Generate_Batch_XML(
12281           errbuf   OUT NOCOPY VARCHAR2,  -- Request standard error string
12282 	  retcode  OUT NOCOPY NUMBER  ,  -- Request standard return status
12283 	  batch_id IN NUMBER
12284 )
12285 IS
12286   CURSOR c_get_batch_type(cp_batch_id igs_sv_batches.batch_id%TYPE)
12287   IS
12288      SELECT batch_type
12289      FROM igs_sv_batches
12290      WHERE batch_id = cp_batch_id;
12291   l_batch_type VARCHAR2(1);
12292  BEGIN
12293        /* Debug */
12294 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
12295 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.Generate_Batch_XML';
12296 	   l_debug_str := 'Batch_id for Generate_Batch_XML: '||batch_id;
12297 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
12298 	END IF;
12299       Put_Log_Msg('Batch_id for Generate_Batch_XML: '||batch_id, 0);
12300 
12301      OPEN c_get_batch_type(batch_id);
12302      FETCH c_get_batch_type INTO l_batch_type;
12303      CLOSE c_get_batch_type;
12304      Submit_Event ( l_batch_type, batch_id);
12305 END Generate_Batch_XML;
12306 
12307 
12308 /******************************************************************
12309    Created By         : prbhardw
12310 
12311    Date Created By    : Jan 03, 2006
12312 
12313    Purpose            : Create log file.
12314 
12315    Change History
12316    Who                  When            What
12317 ------------------------------------------------------------------------
12318 
12319 ******************************************************************/
12320 PROCEDURE compose_log_file
12321 IS
12322 
12323    l_api_name CONSTANT VARCHAR(30) := 'compose_log_file';
12324    l_batch_count NUMBER(5) := 1;
12325    l_per_count NUMBER(5) := 0;
12326 
12327    CURSOR c_persons_per_batch(cp_batch_id igs_sv_btch_summary.batch_id%TYPE)
12328    IS
12329      SELECT COUNT(DISTINCT person_id)
12330      FROM igs_sv_btch_summary
12331      WHERE batch_id = cp_batch_id;
12332 
12333    CURSOR c_get_new_persons(cp_batch_id igs_sv_btch_summary.batch_id%TYPE)
12334    IS
12335      SELECT hz.party_number prsn_num, lkp.meaning info
12336      FROM igs_sv_btch_summary svbs, hz_parties hz, IGS_LOOKUP_VALUES lkp
12337      WHERE svbs.batch_id = cp_batch_id
12338            AND svbs.action_code = 'NEW'
12339            AND svbs.person_id = hz.party_id
12340            AND svbs.TAG_CODE = lkp.lookup_code
12341            AND lkp.lookup_type ='IGS_SV_COMP_TREE';
12342 
12343    CURSOR c_get_updated_persons(cp_batch_id igs_sv_btch_summary.batch_id%TYPE)
12344    IS
12345      SELECT hz.party_number prsn_num, lkp.meaning info
12346      FROM igs_sv_btch_summary svbs, hz_parties hz, IGS_LOOKUP_VALUES lkp
12347      WHERE svbs.batch_id = cp_batch_id
12348            AND svbs.action_code <> 'NEW'
12349            AND svbs.person_id = hz.party_id
12350            AND svbs.TAG_CODE = lkp.lookup_code
12351            AND lkp.lookup_type ='IGS_SV_COMP_TREE'
12352 	   AND lkp.enabled_flag = 'Y';
12353 
12354 BEGIN
12355         fnd_message.set_name('IGS','IGS_SV_BTCH');
12356         fnd_file.put_line(fnd_file.log,fnd_message.get());
12357         fnd_file.put_line(FND_FILE.LOG,' ');
12358 	--Put_Log_Msg(' Following Batch IDs are generated: ',0);
12359         fnd_message.set_name('IGS','IGS_SV_BTCH_ID');
12360         fnd_file.put(fnd_file.log,'  ' || fnd_message.get());
12361 	fnd_message.set_name('IGS','IGS_SV_PERS_COUNT');
12362         fnd_file.put_line(fnd_file.log,'     ' || fnd_message.get());
12363 	--Put_Log_Msg('  Batch ID     No. of Persons',0);
12364 	--Put_Log_Msg('  --------     --------------',0);
12365   --   g_running_batches(1) := 2020205;
12366 
12367    --  g_parallel_batches(1) := 1010101;
12368 
12369   FOR i IN 1..g_parallel_batches.COUNT LOOP
12370      OPEN c_persons_per_batch(g_parallel_batches(i));
12371      FETCH c_persons_per_batch INTO l_per_count;
12372      CLOSE c_persons_per_batch;
12373      Put_Log_Msg('  ' || g_parallel_batches(i) || '   :  ' || l_per_count,0);
12374      l_batch_count := l_batch_count+1;
12375   END LOOP;
12376 
12377   FOR i IN 1..g_running_batches.COUNT LOOP
12378      OPEN c_persons_per_batch(g_running_batches(i));
12379      FETCH c_persons_per_batch INTO l_per_count;
12380      CLOSE c_persons_per_batch;
12381      Put_Log_Msg('  ' || g_running_batches(i) || '   :  ' || l_per_count,0);
12382      l_batch_count := l_batch_count+1;
12383   END LOOP;
12384 
12385      fnd_file.put_line(FND_FILE.LOG,' ');
12386      fnd_message.set_name('IGS','IGS_SV_BTCH_PERS');
12387      fnd_file.put_line(fnd_file.log,fnd_message.get());
12388      fnd_file.put_line(FND_FILE.LOG,' ');
12389    --  Put_Log_Msg(' ',0);
12390    --  Put_Log_Msg(' Following are the person records included in each batch: ',0);
12391     -- Put_Log_Msg(' ',0);
12392 
12393   FOR i IN 1..g_parallel_batches.COUNT LOOP
12394      fnd_message.set_name('IGS','IGS_SV_BTCH_ID');
12395      fnd_file.put_line(fnd_file.log,'  ' || fnd_message.get() || ': ' || g_parallel_batches(i));
12396   --   Put_Log_Msg('  Batch ID: '||g_parallel_batches(i),0);
12397   --   Put_Log_Msg('  ------------------------',0);
12398      fnd_message.set_name('IGS','IGS_SV_NEW_PERS');
12399      fnd_file.put_line(fnd_file.log,'     ' || fnd_message.get());
12400     --- Put_Log_Msg('     New Persons: ',0);
12401     -- Put_Log_Msg('     ------------',0);
12402      fnd_message.set_name('IGS','IGS_SV_PER_NUM');
12403      fnd_file.put(fnd_file.log,'        ' || fnd_message.get());
12404      fnd_message.set_name('IGS','IGS_SV_INFMN');
12405      fnd_file.put_line(fnd_file.log,'		' || fnd_message.get());
12406    --  Put_Log_Msg('        Person Number			Information ',0);
12407      Put_Log_Msg('        --------------		------------ ',0);
12408 
12409      FOR new_persons IN c_get_new_persons(g_parallel_batches(i)) LOOP
12410           Put_Log_Msg('        ' || rpad(new_persons.prsn_num,30,' ') || '             ' || new_persons.info,0);
12411      END LOOP;
12412 
12413      fnd_message.set_name('IGS','IGS_SV_UPD_PERS');
12414      fnd_file.put_line(fnd_file.log,'     ' || fnd_message.get());
12415      --Put_Log_Msg('     Updated Persons: ',0);
12416      Put_Log_Msg('     ----------------',0);
12417      fnd_message.set_name('IGS','IGS_SV_PER_NUM');
12418      fnd_file.put(fnd_file.log,'        ' || fnd_message.get());
12419      fnd_message.set_name('IGS','IGS_SV_INFMN');
12420      fnd_file.put_line(fnd_file.log,'		' || fnd_message.get());
12421      --Put_Log_Msg('        Person Number			Information ',0);
12422      Put_Log_Msg('        --------------		------------ ',0);
12423 
12424      FOR updated_persons IN c_get_updated_persons(g_parallel_batches(i)) LOOP
12425           Put_Log_Msg('        ' || rpad(updated_persons.prsn_num,30,' ') || '             ' || updated_persons.info,0);
12426      END LOOP;
12427 
12428   END LOOP;
12429 
12430   FOR i IN 1..g_running_batches.COUNT LOOP
12431      Put_Log_Msg('  Batch ID: ' || g_running_batches(i),0);
12432      Put_Log_Msg('  ------------------------',0);
12433      fnd_message.set_name('IGS','IGS_SV_NEW_PERS');
12434      fnd_file.put_line(fnd_file.log,'     ' || fnd_message.get());
12435    --  Put_Log_Msg('     New Persons: ',0);
12436      Put_Log_Msg('     ------------',0);
12437      fnd_message.set_name('IGS','IGS_SV_PER_NUM');
12438      fnd_file.put(fnd_file.log,'        ' || fnd_message.get());
12439      fnd_message.set_name('IGS','IGS_SV_INFMN');
12440      fnd_file.put_line(fnd_file.log,'		' || fnd_message.get());
12441     -- Put_Log_Msg('        Person Number			Information ',0);
12442      Put_Log_Msg('        --------------		------------ ',0);
12443 
12444      FOR new_persons IN c_get_new_persons(g_running_batches(i)) LOOP
12445           Put_Log_Msg('        ' || rpad(new_persons.prsn_num,30,' ') || '             ' || new_persons.info,0);
12446      END LOOP;
12447 
12448      fnd_message.set_name('IGS','IGS_SV_UPD_PERS');
12449      fnd_file.put_line(fnd_file.log,'     ' || fnd_message.get());
12450     -- Put_Log_Msg('     Updated Persons: ',0);
12451      Put_Log_Msg('     ----------------',0);
12452      fnd_message.set_name('IGS','IGS_SV_PER_NUM');
12453      fnd_file.put(fnd_file.log,'        ' || fnd_message.get());
12454      fnd_message.set_name('IGS','IGS_SV_INFMN');
12455      fnd_file.put_line(fnd_file.log,'		' || fnd_message.get());
12456      --Put_Log_Msg('        Person Number			Information ',0);
12457      Put_Log_Msg('        --------------		------------ ',0);
12458 
12459      FOR updated_persons IN c_get_updated_persons(g_running_batches(i)) LOOP
12460           Put_Log_Msg('        ' || rpad(updated_persons.prsn_num,30,' ') || '             ' || updated_persons.info,0);
12461      END LOOP;
12462   END LOOP;
12463 
12464 
12465 EXCEPTION
12466 
12467   WHEN OTHERS THEN
12468       IF (FND_MSg_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
12469          FND_MSg_PUB.Add_Exc_Msg (g_PKg_NAME, l_api_name);
12470       END IF;
12471       /* Debug */
12472 	IF fnd_log.test(fnd_log.level_statement,l_prog_label) THEN
12473 	   l_label := 'igs.plsql.igs_sv_ni_batch_process_pkg.compose_log_file';
12474 	   l_debug_str := 'EXCEPTION in compose_log_file.'||SQLERRM;
12475 	   fnd_log.string_with_context( fnd_log.level_statement,l_label,l_debug_str, NULL,NULL,NULL,NULL,NULL,NULL);
12476 	END IF;
12477       Put_Log_Msg(l_api_name||' OTHERS ERROR ',0);
12478 
12479       RAISE;
12480 
12481 END compose_log_file;
12482 
12483 END igs_sv_ni_batch_process_pkg;