DBA Data[Home] [Help]

PACKAGE BODY: APPS.IGS_FI_PRC_FEE_ASS

Source


1 PACKAGE BODY igs_fi_prc_fee_ass AS
2 /* $Header: IGSFI09B.pls 120.45 2006/06/29 12:00:04 abshriva ship $ */
3 
4 /*************************************************************
5  Created By :
6  Date Created By :
7  Purpose :
8  Know limitations, enhancements or remarks
9  Change History
10  Who            When         What
11  abshriva       19-Jun-2006   Bug 5104329 -Introduced new function finpl_get_derived_am_at and involed in finpl_prc_fee_cat_fee_liab
12  akandreg       31-May-2006  Bug 5134636 - Modified finpl_lock_records and finpl_insert_record
13  abshriva       24-May-2006  Bug:5204728 - Added Order by clause in both cursor of finpl_find_far.Introduced p_trace_on in create_retention_charge
14  abshriva       17-May-2006  Bug 5113295 - Modifies finpl_chk_debt_ret_sched - Added call to igs_fi_gen_008.chk_unit_prg_transfer
15  abshriva       12-May-2006  Bug 5217319: Amount Precision change in create_retention_charge,finpl_ins_fee_ass
16  gurprsin       06-Dec-2005  Bug 4735807, Modified function 'finp_ins_enr_fee_ass', Modified the logic to return and log the message
17                              if No Fee category is attached to the SPA.
18  abshriva       05-Dec-2005  Bug 4701695  Modified function 'finp_ins_enr_fee_ass'
19  pathipat       23-Nov-2005  Bug 4718712 - Modified finpl_ins_fee_as, finpl_chk_debt_ret_sched, finp_clc_ass_amnt
20                              and finpl_prc_fee_cat_fee_liab. Added course_cd and career to tbl_wav_fcfl.
21  ayedubat       03-NOV-2005  Bug 4634950 - Changed the procedure, finp_ins_enr_fee_ass to set the Global
22                              Parameter, g_v_wav_calc_flag to N after the call to create_waivers procedure
23  ayedubat       17-OCT-2005  Bug 4639869 - Incase the Fee Assessment is invoked from Tutiton Waivers logic,
24                              Rollback should not be used as this would cause to rollback the Waivers records
25                              prior to invocation of Fee Assessment
26  ayedubat       17-OCT-2005  Bug 4639869 - Changed the logic to Roll Back upto Save Point, fee_calc_sp only
27                              if the global parameter g_v_wav_calc_flag is set to N. Also changed the logic to
28                              assess the SPA records even if the profile, Auto Calculation of Waivers is set to N
29  pathipat       14-Oct-2005  Bug 4644004 - Retention amount is not calculated for increment charge method
30                              Modified finpl_ins_fee_as
31  pathipat       14-Oct-2005  Bug 4634543 - Waiver amt not getting computed from fee assessment process
32                              Modified finp_ins_enr_fee_ass
33  pathipat       10-Oct-2005  Bug 4375258 - Change party_number FK to TCA parties impact -
34                              Added new local function finpl_get_org_unit_cd to fetch the org_unit_cd\
35                              Replaced usage of igs_fi_gen_008.get_party_number with finpl_get_org_unit_cd for Org derivation
36  pathipat       04-Oct-2005  Bug 3781716 - Improper output message when fee category missing
37                              Modified finp_ins_enr_fee_ass - added code to log message and error out if Fee Cat is
38                              not specified for the SPA.
39  pathipat       21-Sep-2005  Bug 4383148 - Fees not assessed if attendance type cannot be derived
40                              Modified finpl_get_derived_values
41  pathipat       21-Sep-2005  Enh 3513252 - Modified finp_clc_ass_amnt - Removed appending IGS_FI_PRE_SET_CHARGE
42                              to the fee type description
43  uudayapr       16-Sep-2005  Bug 4609164 - Modified the code logic in finpl_ins_fee_ass procedure
44  pathipat       06-Sep-2005  Bug 4540295 - Fee assessment produce double fees after program version change
45  bannamal       26-Aug-2005  Enh#3392095 Tuition Waiver Build.
46  bannamal       08-Jul-2005  Enh#3392088 Campus Privilege Fee Build.
47  bannamal       03-JUN-2005  Bug#3442712 Unit Level Fee Assessment Build. Changes done as per TD.
48  bannamal       27-May-2005  Bug#4077763 Fee Calculation Performance Enhancement. Changes done as per TD.
49  bannamal       14-Apr-2005  Bug#4297359 ER Registration Fee issue
50                              Modified finpl_clc_chg_mthd_elements. Added code to check whether the credit points for the unit
51                              attempt is non zero in case the non zero billable cp flag is set to 'Y'.
52                              Also modified finpl_chk_debt_ret_sched. modified the call to igs_fi_gen_008.get_complete_withdr_ret_amt
53                              to add one more parameter.
54  bannamal       31-MAR-2005  Bug 4224364 STUDENT FINANCE UPTAKE OF PROGRAM TRANSFER FUTURE DATED FLAG VALUE CHANGES
55                              Modified the cursors c_get_term_recs, c_get_scas_recs to ignore the program attempts
56                              with Future-Dated Transfer flag set to 'C'
57  svuppala       21-MAR-2005  Bug 4240402 Timezone impact; Truncating the time part in calling place of the table handlers
58                              of the tables IGS_FI_FEE_AS_ALL, IGS_FI_FEE_AS_ITEMS.
59                              Modified the sysdate entries as Trunc(Sysdate) and
60                              p_effective_dt also modified as trunc(p_effective_dt) where ever required .
61  pathipat       18-Nov-2004 Bug 4017841 - Modified get_stdnt_res_status_cd() and finp_ins_enr_fee_ass()
62                             Removed reference to res_dt_alias of table igs_fi_control_all and associated code
63  rmaddipa       05-NOV-2004 Enh 3988455, Modified get_stdnt_unit_set_dtls
64  rmaddipa       03-Nov-2004 Enh 3988455, Modified the procedure finpl_prc_predictive_scas
65  rnirwani       13-Sep-2004 changed cursor c_latest_intermit_date  to not consider logically deleted records and
66                             also to avoid un-approved intermission records. Bug# 3885804
67  pathipat       07-Sep-2004 Enh 3880438 - Retention Enhancements
68                             Modified finpl_chk_debt_ret_sched, finpl_ins_fee_ass, finp_ins_enr_fee_ass
69                             Added proc create_retention_charge.
70                             Removed duplicate function finpl_chk_debt_ret_sched
71  shtatiko       27-JUL-2004 Enh# 3787816, Removed function finpl_charge_is_declined. This call has been replaced with igs_fi_gen_008.chk_chg_adj
72  shtatiko       23-JUL-2004 Enh# 3741400, Added finpl_clc_sua_cp and modified c_sua_load, finpl_clc_chg_mthd_elements.
73  pathipat       01-Jul-2004 Bug 3734842 - Modified finpl_prc_fee_cat_fee_liab() to lock records before processing.
74                             Modified finpl_ins_fee_ass() to check if header and line records were created correctly
75                             Added functions finpl_lock_records(), finpl_insert_record() and finpl_check_header_lines()
76  shtatiko       24-DEC-2003 Enh# 3167098, Removed references to g_d_prg_chg_da_alias_val and g_b_prg_chg_da_use
77                             as fee assessment calculations based on program change enforcement date alias is removed.
78                             Impacted procedures are finp_ins_enr_fee_ass, finpl_prc_fee_cat_fee_liab, finpl_clc_chg_mthd_elements and finpl_get_derived_values
79                             Removed references to igs_fi_f_cat_cal_rel.
80  uudayapr       17-dec-2003 Bug#3080983 ,Modified the cursor c_fadv to fetch data from the table IGS_FI_FEE_AS instead of the view
81                             IGS_FI_FEE_ASS_DEBT_V. and also the declartions of IGS_FI_FEE_ASS_DEBT_V.assessment_amount%TYPE to NUMBER
82  shtatiko       08-DEC-2003 Bug# 3175779, Modified finp_clc_ass_amnt. Separated the processing of element ranges and element range rates.
83  shtatiko       13-NOV-2003 Bug# 3255069, p_charge_elements is made to 1 only when Charge Method is overridden.
84                             And this is done only after processing all records in PL/SQL Table.
85  pathipat       05-Nov-2003 Enh 3117341 - Audit and Special Fees TD - Modifications according to TD, s1a
86  pathipat       29-Oct-2003 Bug 3166331 - Modified finp_clc_ass_amnt
87                             Derived location_cd from SUA level if charge method <> Flatrate added cursor c_sua_location_cd for the same.
88  pathipat       13-Oct-2003 Bug 3166331 - Modified finp_clc_ass_amnt
89                             Modified code to derive org_unit_cd from Unit Attempt/Unit Section level
90                             if the charge method is not Flatrate. Also for Predictive Mode.
91  pathipat       01-Oct-2003 Bug 3164141 - Modified finpl_ins_fee_ass - Added check for Declined Charges
92                             Modified code to log messages just before the insert into igs_fi_fee_as happens
93  pathipat       12-Sep-2003 Enh 3108052 - Unit Sets in Rate Table build
94                             Modifications according to TD - s1a
95  pathipat       03-Sep-2003 Bug 3123669 - Modified finp_clc_ass_amnt - If charge method is overridden, then re-set charge method
96                             to Flat Rate and Status = 'O'. Removed commented out code.
97  vchappid       22-Jul-2003 Bug#3048175, Element Ranges mapping bug. In function finp_clc_ass_amnt, parameter p_charge_elements
98                             should be set only when the element rate range is found and not when the Element Range Applies.
99  vchappid       11-Jul-2003 Bug#2916881 procedure finpl_get_derived_values, flags v_on_att_mode,v_off_att_mode,
100                             v_composite_att_mod are initialized to FALSE. When, attendance mode/type is not derived
101                             then the assessment should be stopped.
102  vvutukur       26-May-2003 Enh#2831572.Financial Accounting Build.Modified procedure finpl_ins_fee_ass.
103  knaraset       02-May-03   Modified cursors c_suah_load_scahfv and c_sua_hist_load in function finpl_clc_chg_mthd_elements
104                             and c_org_unit_cd and c_unit_class_att in function finpl_prc_sua_load to consider uoo_id
105                             as part of MUS build bug 2829262.
106  vchappid       12-Feb-03   Bug#2788346, function finpl_clc_chg_mthd_elements invokes function finpl_prc_sua_load. This
107                             invoking logic is changed for 'Flat Rate' charge method.
108  vchappid       27-Jan-03   Bug#2656411, in the function finpl_ins_match_chg_rate, modified the logic for identifying
109                             matching fee assessment rate
110  pradhakr       15-Jan-03   Added one more paramter no_assessment_ind to
111                             the call enrp_get_load_apply as an impact, following
112                             the modification of the package Igs_En_Prc_Load.
113                             Changes wrt ENCR026. Bug# 2743459
114  vchappid        09-Jan-03  Bug# 2660155, As a review comment, in the log messages Person id is replaced with the person number
115  vchappid        11-Nov-02  Bug# 2584986, GL- Interface Build, New Date parameter p_d_gl_date
116                             is added to the finp_ins_enr_fee_ass procedure specification,
117                             the same parameter is passed to the charges API
118                             Reference to the igs_fi_curr is removed, Exchange_Rate is always passed as 1 only.
119  npalanis        23-OCT-02  Bug : 2608360
120                             references to residency_class_id and residency_status_id is changed to residency_status_cd
121                             and residency_class_cd due to transtion of residency_class and residency_status code class
122                             to igs lookups
123  vchappid        21-Oct-02  Bug# 2580672, Modifications to the code as suggested by Enrolment Unit Attempt TD
124  vchappid        17-Oct-02  Bug# 2595962, Removed the procedure finpl_create_todo_rec,
125                             changes as per the Predictive Fee Assessment TD
126  sarakshi        13-Sep-02  Enh#2564643,removed the reference of subaccount also default for gscc fix
127  vchappid        25-jul-02  Bug#2237227, added 'add_flag' with Default value 'N' into the Pl/SQL table t_fee_as_items
128                             In the Function finpl_sum_fee_ass_item, if the record in the pl/sql table matches with values
129                             that are passed to the function and the Fee Calculation Method is Primary Career then the Charge
130                             Elements, EFTSU, Credit Points and the assessment amount are added to the existing PL/SQL table
131                             otherwise the values are replaced with the values that are passed to the Function
132  vchappid        18-Jul-02  Bug# 2326166, values of Credit Points, Eftsu are also recorded when a charge is created incase when the
133                             charge method is Per Unit, Per Credit Points and EFTSU incase of Institution/Non-Institution Fee Triggers
134  vchappid        15-Jul-02  Bug# 2433955, logging of message -IGS_FI_DER_RES_STAT is incorrectly done.
135                             Same Message Name is logged using procedure r_s_log_entry and the same message name is used to set
136                             the name of the message name when the details have to be shown to the user
137                             Message Name IGS_FI_DER_RES_STAT is changed to IGS_FI_RES_STAT, the new message is already
138                             registered in the system but is not being used in the process.
139  rnirwani        11-Jun-02  Bug# 2396536
140                             Modified procedure finp_ins_enr_fee_ass so that after the check for key program in case it is found that the key program does
141                             not exist then the message is logged. The log entry is saved and a return true is done. This will enable the process to continue
142                             processing for other students - if applicable.
143  rnirwani        28-May-02  Bug# 2378804
144                             Removed the generic invocation of get-lci-fci-rel and moved the same to procedures: get_derived_elemens
145                             and clc_chg_method_elems where actually the load calendar values would be used. removed the usage of global variable since
146                             it is not required any longer.
147  rnirwani        27-May-02  Bug# 2378804
148                             Moved the code related to setting the global variable gv_Current_Data at the beginning of the procedure.
149                             Altered the invocation of get-lci-fci-rel so that in case teh prior fee cal instance is passed then
150                             the load calendar for prior fee calendar should be returned by the this function. This load calendar is
151                             then used for all further calculations.
152  rnirwani        13-May-02  Bug# 2261649 - Removed the variable lv_usec_amount since it was not being used
153                             and referrd to table IGS_PS_USEC_CHARGE which has been obsolete.
154  rnirwani        02-May-02  Bug# 2344901 - modification in procedure finp_clc_ass_amnt.
155                             fee assessment does not happen in case a charge rate record is not located
156                             for any one line item records (where multiple exists).
157  smadathi        02-May-2002   Bug 2261649. The function finp_get_additional_charge removed.
158  rnirwani        02-May-02  Bug# 2345191  modified procedure finp_clc_ass_amnt
159                             the contract fee rate identification code was using the parameter passed attributes
160                             for attendance type, mode and location.
161                             It is supposed to use the derived values.
162  rnirwani        17-apr-02  bug# 2317155  modified finpl_ins_fee_ass .
163                             passed org unit code to the charges API
164  vchappid        17-Jan-02  Enh Bug#2162747, Key Program Implementation, Fin Cal Inst parameters
165                             removed, new parameter p_c_career is added
166  masehgal        17-Jan-2002   ENH # 2170429
167                                Obsoletion of SPONSOR_CD
168  vchappid        29-Nov-01  Enh Bug#2122257, Changed some of the cursor definitions
169                             obsolecence of function finpl_get_fee_cat is done
170  (reverse chronological order - newest change first)
171 ***************************************************************/
172   --
173   X_ROWID               VARCHAR2(25);
174   v_fa_sequence_number  igs_fi_fee_as_all.transaction_id%TYPE;
175   g_v_person_number     hz_parties.party_number%TYPE;
176   l_v_lkp_all           CONSTANT VARCHAR2(60) := igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'ALL');
177 
178   TYPE inst_prog_details_rec_type IS RECORD (
179          program_cd       igs_ps_ver_all.course_cd%TYPE,
180          program_version  igs_ps_ver_all.version_number%TYPE,
181          career           igs_ps_ver_all.course_type%TYPE );
182 
183   -- This table type will hold the program details which are liable for an Institution system fee trigger category.
184   TYPE inst_prog_det_tbl_typ IS TABLE OF inst_prog_details_rec_type  INDEX BY BINARY_INTEGER;
185 
186   g_inst_liable_progs_tbl inst_prog_det_tbl_typ;
187   g_n_inst_progs_cntr     NUMBER;
188 
189   g_v_fee_alt_code   igs_ca_inst_all.alternate_code%TYPE;
190 
191   -- This is set to TRUE if Institution Fee is to be assessed in Predictive Mode.
192   g_b_prc_inst_fee  BOOLEAN;
193 
194   g_v_career         CONSTANT igs_fi_control_all.fee_calc_mthd_code%TYPE := 'CAREER';
195   g_v_program        CONSTANT igs_fi_control_all.fee_calc_mthd_code%TYPE := 'PROGRAM';
196   g_v_primary_career CONSTANT igs_fi_control_all.fee_calc_mthd_code%TYPE := 'PRIMARY_CAREER';
197   g_v_retention      CONSTANT igs_fi_inv_int_all.transaction_type%TYPE   := 'RETENTION';
198 
199   g_v_chgmthd_flatrate  CONSTANT igs_fi_invln_int_all.s_chg_method_type%TYPE := 'FLATRATE';
200 
201 
202   -- This indicates whether any records exists in PL/SQL table maintained.
203   g_b_fee_chgs_exists BOOLEAN;
204 
205   g_v_fcfl_source VARCHAR2(10) := NULL;
206   g_v_wav_calc_flag VARCHAR2(1) := NULL;
207 
208   -- Profile for determining whether Nominated or Derived values are used
209   g_v_att_profile         CONSTANT fnd_lookup_values.lookup_code%TYPE := FND_PROFILE.VALUE('IGS_FI_NOM_DER_VALUES');
210   g_v_auto_calc_wav_prof  CONSTANT VARCHAR2(30) := fnd_profile.VALUE('IGS_FI_AUTO_CALC_WAIVERS');
211 
212   g_n_org_id      CONSTANT igs_fi_fee_as_all.org_id%TYPE := igs_ge_gen_003.get_org_id;
213 
214   -- Global variable to hold Currency Code - assigned a value in finp_ins_enr_fee_ass, cursor c_fi_control
215   g_v_currency_cd igs_fi_control_all.currency_cd%TYPE := NULL;
216 
217   -- Global Cursor to get the Alternate Code for a Calendar Instance passed.
218   CURSOR g_c_alternate_code ( cp_v_cal_type igs_ca_inst_all.cal_type%TYPE,
219                               cp_n_seq_num  igs_ca_inst_all.sequence_number%TYPE ) IS
220     SELECT alternate_code
221     FROM igs_ca_inst_all
222     WHERE cal_type = cp_v_cal_type
223     AND sequence_number = cp_n_seq_num;
224 
225   g_v_res_profile    CONSTANT VARCHAR2(100) := fnd_profile.VALUE('IGS_FI_RES_CLASS_ID');
226 
227   tbl_fee_as_items t_fee_as_items_typ;  -- Holds the records of previous assessment while processing for retention
228   tbl_fee_as_items_diff t_fee_as_items_typ;  -- Holds the records which are the diff between previous assessment and current assessment while processing retention
229   tbl_fee_as_items_dummy t_fee_as_items_typ;  -- This is the dummy table used in retention calculation
230 
231   TYPE t_unit_status IS TABLE OF VARCHAR2(1) INDEX BY BINARY_INTEGER;
232   TYPE t_date IS TABLE OF igs_en_su_attempt_all.enrolled_dt%TYPE INDEX BY BINARY_INTEGER;
233 
234   TYPE wav_fcfl_rec_type IS RECORD (
235                     p_fee_category   igs_fi_f_cat_fee_lbl_all.fee_cat%TYPE,
236                     p_fee_type       igs_fi_f_cat_fee_lbl_all.fee_type%TYPE,
237                     p_course_cd      igs_en_stdnt_ps_att_all.course_cd%TYPE,
238                     p_career         igs_ps_ver_all.course_type%TYPE);
239 
240   TYPE wav_fcfl_tbl_type IS TABLE OF wav_fcfl_rec_type INDEX BY BINARY_INTEGER;
241   tbl_wav_fcfl  wav_fcfl_tbl_type;
242   t_dummy_wav_fcfl wav_fcfl_tbl_type;
243 
244   -- Procedure to log given String to fnd_log_messages. Message Level will be STATEMENT.
245   PROCEDURE log_to_fnd ( p_v_module IN VARCHAR2,
246                          p_v_string IN VARCHAR2 ) IS
247   BEGIN
248     IF (fnd_log.level_statement >= fnd_log.g_current_runtime_level) THEN
249 
250       fnd_log.string( fnd_log.level_statement, 'Fee Assessment:' || p_v_module, p_v_string);
251 
252     END IF;
253   END log_to_fnd;
254 
255 PROCEDURE check_census_dt_setup(
256               p_v_predictive_mode     IN VARCHAR2,
257               p_v_load_cal_type       IN igs_fi_f_cat_ca_inst.fee_cal_type%TYPE,
258               p_n_load_ci_seq_number  IN igs_fi_f_cat_ca_inst.fee_ci_sequence_number%TYPE,
259               p_d_cns_dt_als_val      OUT NOCOPY DATE,
260               p_b_return_status       OUT NOCOPY BOOLEAN,
261               p_v_message_name        OUT NOCOPY VARCHAR2 ) IS
262 /*----------------------------------------------------------------------------
263 ||  Created By : UMESH UDAYAPRAKASH
264 ||  Created On : 06-JAN-2004
265 ||  Purpose :
266 ||  Known limitations, enhancements or remarks :
267 ||  Change History :
268 ||  Who             When            What
269 ||  bannamal        27-May-2005     Bug#4077763 Fee Calculation Performance Enhancement.
270 ||                                  Replaced the literal used in the cursor c_census_dt_alias by cursor parameter.
271 ||  (reverse chronological order - newest change first)
272 ----------------------------------------------------------------------------*/
273   CURSOR c_census_dt_alias (cp_n_s_control_num igs_ge_s_gen_cal_con.s_control_num%TYPE) IS
274     SELECT census_dt_alias
275     FROM igs_ge_s_gen_cal_con
276     WHERE s_control_num = cp_n_s_control_num;
277 
278   CURSOR c_check_dt_alias (cp_dt_alias igs_ca_da_inst.dt_alias%TYPE,
279                            cp_cal_type igs_ca_da_inst.cal_type%TYPE,
280                            cp_ci_sequence_number igs_ca_da_inst.ci_sequence_number%TYPE) IS
281     SELECT MAX(alias_val)
282     FROM igs_ca_da_inst_v
283     WHERE dt_alias = cp_dt_alias
284     AND cal_type = cp_cal_type
285     AND ci_sequence_number = cp_ci_sequence_number;
286 
287   l_v_census_dt_alias     igs_ge_s_gen_cal_con.census_dt_alias%TYPE;
288   l_d_check_dt_alias      igs_ca_da_inst_v.alias_val%TYPE;
289 BEGIN
290 
291   p_d_cns_dt_als_val := NULL;
292   IF p_v_load_cal_type IS NULL OR
293      p_n_load_ci_seq_number IS NULL OR
294      p_v_predictive_mode IS NULL
295   THEN
296     p_b_return_status := FALSE;
297     RETURN ;
298   END IF;
299 
300   log_to_fnd( p_v_module => 'check_census_dt_setup',
301               p_v_string => 'Entered check_census_dt_setup. ');
302 
303   IF (p_v_predictive_mode = 'Y') OR (p_v_predictive_mode = 'N' AND g_c_fee_calc_mthd = g_v_program) THEN
304     OPEN c_census_dt_alias ( cp_n_s_control_num => 1 );
305     FETCH c_census_dt_alias INTO l_v_census_dt_alias;
306     CLOSE c_census_dt_alias;
307 
308     IF l_v_census_dt_alias IS NULL THEN
309       p_b_return_status := FALSE;
310       p_v_message_name :='IGS_FI_NO_CENSUS_DT_SETUP';
311       log_to_fnd( p_v_module => 'check_census_dt_setup',
312                   p_v_string => 'Returning with message IGS_FI_NO_CENSUS_DT_SETUP.');
313       RETURN;
314     END IF;
315 
316     OPEN c_check_dt_alias(cp_dt_alias           => l_v_census_dt_alias,
317                           cp_cal_type           => p_v_load_cal_type,
318                           cp_ci_sequence_number => p_n_load_ci_seq_number);
319     FETCH c_check_dt_alias INTO l_d_check_dt_alias;
320     CLOSE c_check_dt_alias;
321 
322     IF l_d_check_dt_alias IS NOT NULL THEN
323        p_d_cns_dt_als_val := l_d_check_dt_alias;
324        p_b_return_status := TRUE;
325     ELSE
326       p_v_message_name := 'IGS_FI_NO_CENSUS_DT_SETUP';
327       p_b_return_status := FALSE;
328     END IF;
329 
330     log_to_fnd( p_v_module => 'check_census_dt_setup',
331                 p_v_string => 'Returning Out: Alias Val:' || TO_CHAR(p_d_cns_dt_als_val, 'DD-MON-YYYY') || ', Message: ' || p_v_message_name);
332     RETURN;
333 
334   ELSE
335     log_to_fnd( p_v_module => 'check_census_dt_setup',
336                 p_v_string => 'Returning in case of Non-Predictive and Non-Program.');
337     p_b_return_status := TRUE;
338     RETURN ;
339   END IF;
340 
341 END check_census_dt_setup;
342 
343 FUNCTION  finpl_lock_records(p_n_person_id                 IN igs_fi_fee_as_all.person_id%TYPE,
344                              p_v_course_cd                 IN igs_ps_ver_all.course_cd%TYPE,
345                              p_v_fee_cal_type              IN igs_fi_fee_as_all.fee_cal_type%TYPE,
346                              p_n_fee_ci_sequence_number    IN igs_fi_fee_as_all.fee_ci_sequence_number%TYPE)  RETURN BOOLEAN;
347 
348 FUNCTION finpl_get_derived_am_at (p_person_id                 IN     hz_parties.party_id%TYPE,
349                                   p_course_cd                 IN     igs_ps_course.course_cd%TYPE,
350                                   p_effective_dt              IN     DATE,
351                                   p_fee_cal_type              IN     igs_fi_f_cat_fee_lbl_all.fee_cal_type%TYPE,
352                                   p_fee_ci_sequence_number    IN     igs_fi_f_cat_fee_lbl_all.fee_ci_sequence_number%TYPE,
353                                   p_fee_type                  IN     igs_fi_f_cat_fee_lbl_all.fee_type%TYPE,
354                                   p_s_fee_trigger_cat         IN     igs_fi_fee_type_all.s_fee_trigger_cat%TYPE,
355                                   p_trace_on                  IN     VARCHAR2,
356                                   p_c_career                  IN     igs_ps_ver_all.course_type%TYPE,
357                                   p_derived_attendance_type   OUT    NOCOPY igs_fi_fee_as_rate.attendance_type%TYPE,
358                                   p_derived_att_mode          OUT    NOCOPY igs_en_atd_mode_all.govt_attendance_mode%TYPE) RETURN BOOLEAN;
359 
360 
361 FUNCTION  finpl_check_header_lines(p_n_person_id       igs_fi_fee_as_all.person_id%TYPE,
362                                    p_n_transaction_id  igs_fi_fee_as_all.transaction_id%TYPE) RETURN BOOLEAN;
363 
364 PROCEDURE create_retention_charge( p_n_person_id               IN igs_fi_inv_int_all.person_id%TYPE,
365                                    p_v_course_cd               IN igs_fi_inv_int_all.course_cd%TYPE,
366                                    p_v_fee_cal_type            IN igs_fi_inv_int_all.fee_cal_type%TYPE,
367                                    p_n_fee_ci_sequence_number  IN igs_fi_inv_int_all.fee_ci_sequence_number%TYPE,
368                                    p_v_fee_type                IN igs_fi_inv_int_all.fee_type%TYPE,
369                                    p_v_fee_cat                 IN igs_fi_inv_int_all.fee_cat%TYPE,
370                                    p_d_gl_date                 IN igs_fi_invln_int_all.gl_date%TYPE,
371                                    p_n_uoo_id                  IN igs_fi_invln_int_all.uoo_id%TYPE,
372                                    p_n_amount                  IN igs_fi_inv_int_all.invoice_amount%TYPE,
373                                    p_v_fee_type_desc           IN igs_fi_fee_type_all.description%TYPE,
374                                    p_v_fee_trig_cat            IN igs_fi_fee_type_all.s_fee_trigger_cat%TYPE,
375                                    p_trace_on                  IN VARCHAR2);
376 
377   FUNCTION finp_clc_ass_amnt(
378   p_effective_dt                   IN DATE ,
379   p_person_id                      IN hz_parties.party_id%TYPE ,
380   p_course_cd                      IN igs_en_stdnt_ps_att_all.course_cd%TYPE ,
381   p_course_version_number          IN igs_en_stdnt_ps_att_all.version_number%TYPE ,
382   p_course_attempt_status          IN VARCHAR2 ,
383   p_fee_type                       IN igs_fi_f_cat_fee_lbl_all.fee_type%TYPE ,
384   p_fee_cal_type                   IN igs_fi_f_cat_fee_lbl_all.fee_cal_type%TYPE ,
385   p_fee_ci_sequence_number         IN igs_fi_f_cat_fee_lbl_all.fee_ci_sequence_number%TYPE ,
386   p_fee_cat                        IN IGS_FI_F_CAT_CA_INST.FEE_CAT%TYPE ,
387   p_s_fee_type                     IN igs_fi_fee_type_all.s_fee_type%TYPE ,
388   p_s_fee_trigger_cat              IN VARCHAR2 ,
389   p_rul_sequence_number            IN igs_fi_f_cat_fee_lbl_all.rul_sequence_number%TYPE ,
390   p_charge_method                  IN igs_fi_f_typ_ca_inst_all.s_chg_method_type%TYPE ,
391   p_location_cd                    IN VARCHAR2 ,
392   p_attendance_type                IN VARCHAR2 ,
393   p_attendance_mode                IN VARCHAR2 ,
394   p_trace_on                       IN VARCHAR2 ,
395   p_creation_dt                    IN OUT NOCOPY DATE ,
396   p_charge_elements                IN OUT NOCOPY igs_fi_fee_as_all.chg_elements%TYPE ,
397   p_fee_assessment                 IN OUT NOCOPY NUMBER ,
398   p_charge_rate                    OUT NOCOPY IGS_FI_FEE_AS_RATE.chg_rate%TYPE,
399   p_c_career                       IN igs_ps_ver_all.course_type%TYPE,
400   p_elm_rng_order_name             IN igs_fi_f_typ_ca_inst_all.elm_rng_order_name%TYPE,
401   p_n_max_chg_elements             IN igs_fi_fee_as_items.max_chg_elements%TYPE,
402   p_n_called                       IN NUMBER) RETURN BOOLEAN;
403 
404 
405   FUNCTION finpl_get_org_unit_cd(p_n_party_id   IN hz_parties.party_id%TYPE) RETURN VARCHAR2;
406 
407   FUNCTION get_stdnt_res_status_cd ( p_n_person_id IN igs_en_stdnt_ps_att_all.person_id%TYPE) RETURN VARCHAR2 AS
408   /*************************************************************
409    Created By :      Shirish Tatikonda
410    Date Created By : 30-DEC-2003
411    Purpose :         To derive Residency Status Code.
412                      Called from finpl_get_derived_values in ACTUAL mode.
413                             from finp_clc_ass_amnt in PREDICTIVE mode.
414    Know limitations, enhancements or remarks
415    Change History
416    Who             When          What
417    shtatiko        30-DEC-2003   Enh# 3167098, Created this function.
418    pathipat        17-Nov-2004   Bug 4017841 - Revamped code to invoke PE function to obtain
419                                  Residency Status instead of cursor c_res_status
420    bannamal        01-Jul-2005   Bug#4077763 Fee Calculation Performance Enhancement.
421                                  replaced the usage of local variable l_v_res_profile
422                                  by global variable g_v_res_profile
423   ***************************************************************/
424 
425     l_v_res_status     igs_pe_res_dtls_all.residency_class_cd%TYPE;
426 
427   BEGIN
428 
429     log_to_fnd( p_v_module => 'get_stdnt_res_status_cd',
430                 p_v_string => 'Entered get_stdnt_res_status_cd. Params: ' ||p_n_person_id ||
431                               ',Profile Value: ' || g_v_res_profile ||
432                               ', Load Calendar: '|| g_v_load_cal_type ||' - '||g_n_load_seq_num);
433 
434     IF p_n_person_id IS NULL OR g_v_load_cal_type IS NULL OR g_n_load_seq_num IS NULL THEN
435       RETURN NULL;
436     END IF;
437 
438     -- Check if profile 'IGS: Residency Class' is set or not.
439     IF g_v_res_profile IS NULL THEN
440       l_v_res_status := NULL;
441     ELSE
442       l_v_res_status := igs_pe_gen_001.get_res_status(p_person_id        => p_n_person_id,
443                                                       p_residency_class  => g_v_res_profile,
444                                                       p_cal_type         => g_v_load_cal_type,
445                                                       p_sequence_number  => g_n_load_seq_num);
446     END IF;
447 
448     log_to_fnd( p_v_module => 'get_stdnt_res_status_cd',
449                 p_v_string => 'Returning Derived Res Status Cd: ' ||  l_v_res_status);
450 
451     RETURN l_v_res_status;
452 
453   END get_stdnt_res_status_cd;
454 
455   FUNCTION get_stdnt_class_standing ( p_n_person_id          IN igs_en_stdnt_ps_att_all.person_id%TYPE,
456                                       p_v_course_cd          IN igs_ps_ver_all.course_cd%TYPE,
457                                       p_v_s_fee_trigger_cat  IN igs_fi_fee_type_all.s_fee_trigger_cat%TYPE ) RETURN VARCHAR2 AS
458   /*************************************************************
459    Created By :      Shirish Tatikonda
460    Date Created By : 30-DEC-2003
461    Purpose :         To derive Student Class Standing
462                      Called from finpl_get_derived_values in ACTUAL mode.
463                             Class Standing is not derived in PREDICTIVE mode.
464    Know limitations, enhancements or remarks
465    Change History
466    Who             When          What
467    shtatiko        30-DEC-2003   Enh# 3167098, Created this function.
468   ***************************************************************/
469 
470    l_v_derived_class_standing  igs_fi_fee_as_rate.class_standing%TYPE;
471 
472   BEGIN
473 
474     IF p_n_person_id IS NULL
475        OR p_v_course_cd IS NULL
476        OR p_v_s_fee_trigger_cat IS NULL THEN
477       RETURN NULL;
478     END IF;
479 
480     log_to_fnd( p_v_module => 'get_stdnt_class_standing',
481                 p_v_string => 'Entered get_stdnt_class_standing. Params: ' ||p_n_person_id || ', ' || p_v_course_cd );
482 
483     -- Assessment Mode: ACTUAL
484     --   Fee Calc Method: PROGRAM
485     --                       -- For Institution Fee, Class Standing needn't be derived.
486     --                    CAREER
487     --                       -- Derive irrespective System Fee Trigger Category.
488     --                    PRIMARY_CAREER
489     --                       -- Determine Class Standing based on Key Program.
490     -- Assessment Mode: PREDICTIVE
491     --                       -- Class Standing Cannnot be derived in Predictive Mode.
492 
493     IF (g_c_fee_calc_mthd IN (g_v_program, g_v_career)) THEN
494       IF (p_v_s_fee_trigger_cat <> gcst_institutn) THEN
495         l_v_derived_class_standing := igs_pr_get_class_std.get_class_standing(p_person_id => p_n_person_id,
496                                                                               p_course_cd => p_v_course_cd,
497                                                                               p_predictive_ind => g_c_predictive_ind,
498                                                                               p_effective_dt => NULL,
499                                                                               p_load_cal_type => g_v_load_cal_type,
500                                                                               p_load_ci_sequence_number => g_n_load_seq_num
501                                                                              );
502       ELSE
503         IF (g_c_fee_calc_mthd=g_v_career) THEN
504           l_v_derived_class_standing := igs_pr_get_class_std.get_class_standing( p_person_id => p_n_person_id,
505                                                                                  p_course_cd => g_c_key_program,
506                                                                                  p_predictive_ind => g_c_predictive_ind,
507                                                                                  p_effective_dt => NULL,
508                                                                                  p_load_cal_type => g_v_load_cal_type,
509                                                                                  p_load_ci_sequence_number => g_n_load_seq_num
510                                                                                );
511         END IF;
512       END IF;
513     ELSE -- g_c_fee_calc_mthd = g_v_primary_career
514       l_v_derived_class_standing := igs_pr_get_class_std.get_class_standing(p_person_id => p_n_person_id,
515                                                                             p_course_cd => g_c_key_program,
516                                                                             p_predictive_ind => g_c_predictive_ind,
517                                                                             p_effective_dt => NULL,
518                                                                             p_load_cal_type => g_v_load_cal_type,
519                                                                             p_load_ci_sequence_number => g_n_load_seq_num
520                                                                            );
521     END IF;
522 
523     log_to_fnd( p_v_module => 'get_stdnt_class_standing',
524                 p_v_string => 'Derived Class Standing: ' || l_v_derived_class_standing);
525     RETURN l_v_derived_class_standing;
526 
527   END get_stdnt_class_standing;
528 
529   PROCEDURE get_stdnt_unit_set_dtls ( p_n_person_id          IN igs_en_stdnt_ps_att_all.person_id%TYPE,
530                                       p_v_course_cd          IN igs_ps_ver_all.course_cd%TYPE,
531                                       p_v_s_fee_trigger_cat  IN igs_fi_fee_type_all.s_fee_trigger_cat%TYPE,
532                                       p_v_unit_set_cd        OUT NOCOPY igs_as_su_setatmpt.unit_set_cd%TYPE,
533                                       p_n_unit_set_ver_num   OUT NOCOPY igs_as_su_setatmpt.us_version_number%TYPE ) AS
534   /*************************************************************
535    Created By :      Shirish Tatikonda
536    Date Created By : 30-DEC-2003
537    Purpose :         To derive Unit Set Details.
538                      Called from finpl_get_derived_values in ACTUAL mode.
539                             from finp_clc_ass_amnt in PREDICTIVE mode.
540    Know limitations, enhancements or remarks
541    Change History
542    Who             When          What
543    rmaddipa        05-NOV-2004   Enh# 3988455 Added statement to close the
544                                               cursor cur_unit_set
545    shtatiko        30-DEC-2003   Enh# 3167098, Created this function.
546   ***************************************************************/
547 
548     -- Derive the Unit Set Code and Version Number, but only of category Pre Enrollment.
549     CURSOR cur_unit_set (cp_person_id     hz_parties.party_id%TYPE,
550                          cp_course_cd     igs_ps_ver_all.course_cd%TYPE,
551                          cp_effective_dt  DATE,
552                          cp_v_student_confirmed_ind  igs_as_su_setatmpt.student_confirmed_ind%TYPE,
553                          cp_v_s_unit_set_cat  igs_en_unit_set_cat.s_unit_set_cat%TYPE) IS
554       SELECT asu.unit_set_cd,
555              asu.us_version_number
556       FROM igs_as_su_setatmpt asu,
557            igs_en_unit_set_all us,
558            igs_en_unit_set_cat usc
559       WHERE asu.person_id = cp_person_id
560       AND asu.course_cd = cp_course_cd
561       AND asu.student_confirmed_ind = cp_v_student_confirmed_ind
562       AND TRUNC(cp_effective_dt) BETWEEN TRUNC(asu.selection_dt) AND NVL(TRUNC(asu.rqrmnts_complete_dt), NVL(TRUNC(asu.end_dt), TRUNC(cp_effective_dt)))
563       AND asu.unit_set_cd = us.unit_set_cd
564       AND asu.us_version_number = us.version_number
565       AND us.unit_set_cat = usc.unit_set_cat
566       AND usc.s_unit_set_cat = cp_v_s_unit_set_cat;
567 
568     l_v_unit_set_cd  igs_en_unit_set_all.unit_set_cd%TYPE;
569     l_n_us_version_number igs_en_unit_set_all.version_number%TYPE;
570 
571   BEGIN
572 
573     p_v_unit_set_cd := NULL;
574     p_n_unit_set_ver_num := NULL;
575 
576     IF p_n_person_id IS NULL
577        OR p_v_course_cd IS NULL THEN
578       RETURN;
579     END IF;
580 
581     log_to_fnd( p_v_module => 'get_stdnt_unit_set_dtls',
582                 p_v_string => 'Entered get_stdnt_unit_set_dtls. Params: ' ||p_n_person_id || ', ' || p_v_course_cd ||', ' || p_v_s_fee_trigger_cat );
583 
584     IF (g_c_fee_calc_mthd <> g_v_program OR p_v_s_fee_trigger_cat = 'INSTITUTN') THEN
585       log_to_fnd( p_v_module => 'get_stdnt_unit_set_dtls',
586                   p_v_string => 'Returning NULL in case of Non-Program or Institution case.' );
587       RETURN;
588     ELSE
589       OPEN cur_unit_set( p_n_person_id, p_v_course_cd, g_d_ld_census_val, 'Y', 'PRENRL_YR' );
590       FETCH cur_unit_set INTO l_v_unit_set_cd,
591                               l_n_us_version_number;
592       IF cur_unit_set%NOTFOUND THEN
593         p_v_unit_set_cd := NULL;
594         p_n_unit_set_ver_num := NULL;
595       ELSE
596         p_v_unit_set_cd := l_v_unit_set_cd;
597         p_n_unit_set_ver_num := l_n_us_version_number;
598       END IF;
599       CLOSE cur_unit_set;
600       log_to_fnd( p_v_module => 'get_stdnt_unit_set_dtls',
601                   p_v_string => 'Derived Unit Set Cd: ' || p_v_unit_set_cd || ', ' || p_n_unit_set_ver_num );
602     END IF;
603 
604   END get_stdnt_unit_set_dtls;
605 
606   PROCEDURE finpl_get_unit_type_level(p_n_uoo_id              IN  igs_ps_unit_ofr_opt_all.uoo_id%TYPE,
607                                       p_n_unit_prg_type_level OUT NOCOPY igs_ps_unit_ver_all.unit_type_id%TYPE,
608                                       p_v_unit_level          OUT NOCOPY igs_ps_unit_ver_all.unit_level%TYPE ) AS
609 
610   /*************************************************************
611    Created By :      Bhaskar Annamalai
612    Date Created By : 03-JUN-2005
613    Purpose :         To derive Unit Program Type Level, Unit Level.
614 
615    Know limitations, enhancements or remarks
616 
617    Change History
618    Who             When          What
619      ***************************************************************/
620 
621     CURSOR cur_unit_type_level (cp_n_uoo_id  igs_ps_unit_ofr_opt_all.uoo_id%TYPE) IS
622     SELECT uv.unit_type_id, uv.unit_level
623     FROM igs_ps_unit_ver_all uv,
624              igs_ps_unit_ofr_opt_all uoo
625     WHERE uv.unit_cd = uoo.unit_cd
626     AND   uv.version_number = uoo.version_number
627     AND   uoo.uoo_id = cp_n_uoo_id;
628 
629     l_n_unit_prg_type_level  igs_ps_unit_ver_all.unit_type_id%TYPE;
630     l_v_unit_level           igs_ps_unit_ver_all.unit_level%TYPE;
631 
632   BEGIN
633    p_n_unit_prg_type_level := NULL;
634    p_v_unit_level := NULL;
635 
636    log_to_fnd( p_v_module => 'finpl_get_unit_type_level',
637                p_v_string => 'Entered finpl_get_unit_type_level. Params: ' ||p_n_uoo_id || ', ' || p_n_unit_prg_type_level ||', ' || p_v_unit_level );
638 
639    IF p_n_uoo_id IS NOT NULL THEN
640 
641      OPEN cur_unit_type_level( p_n_uoo_id );
642      FETCH cur_unit_type_level INTO l_n_unit_prg_type_level, l_v_unit_level;
643      IF cur_unit_type_level%FOUND  THEN
644        p_n_unit_prg_type_level := l_n_unit_prg_type_level;
645        p_v_unit_level := l_v_unit_level;
646      END IF;
647      CLOSE cur_unit_type_level;
648      log_to_fnd( p_v_module => 'finpl_get_unit_type_level',
649                  p_v_string => 'Derived  Unit Program Type Level ID: ' || p_n_unit_prg_type_level ||', Unit Level: ' || p_v_unit_level );
650 
651    END IF;
652 
653   END finpl_get_unit_type_level;
654 
655   FUNCTION finpl_get_uptl(p_n_unit_type_id IN igs_ps_unit_type_lvl.unit_type_id%TYPE) RETURN VARCHAR2 AS
656 
657   /*************************************************************
658    Created By :      Priya Athipatla
659    Date Created By : 02-Sep-2005
660    Purpose :         To derive Unit Program Type Level (Level Code)
661 
662    Know limitations, enhancements or remarks
663 
664    Change History
665    Who             When          What
666    ***************************************************************/
667 
668     -- Cursor to fetch the Level Code for the Unit Program Type Level Id.
669     CURSOR cur_uptl(cp_n_unit_type_id    igs_ps_unit_type_lvl.unit_type_id%TYPE) IS
670       SELECT level_code
671       FROM igs_ps_unit_type_lvl
672       WHERE unit_type_id = cp_n_unit_type_id;
673 
674     l_v_level_code  igs_ps_unit_type_lvl.level_code%TYPE;
675 
676   BEGIN
677 
678      OPEN cur_uptl(p_n_unit_type_id);
679      FETCH cur_uptl INTO l_v_level_code;
680      CLOSE cur_uptl;
681 
682      RETURN l_v_level_code;
683 
684   END finpl_get_uptl;
685 
686 
687   PROCEDURE finpl_get_unit_class_mode( p_n_uoo_id     IN  igs_ps_unit_ofr_opt_all.uoo_id%TYPE,
688                                        p_v_unit_class OUT NOCOPY igs_as_unit_class_all.unit_class%TYPE,
689                                        p_v_unit_mode  OUT NOCOPY igs_as_unit_class_all.unit_mode%TYPE ) AS
690 
691     /*************************************************************
692    Created By :      Bhaskar Annamalai
693    Date Created By : 03-JUN-2005
694    Purpose :         To derive Unit Class, Unit Mode.
695 
696    Know limitations, enhancements or remarks
697 
698    Change History
699    Who             When          What
700      ***************************************************************/
701   CURSOR cur_unit_class_mode (cp_n_uoo_id igs_ps_unit_ofr_opt_all.uoo_id%TYPE) IS
702   SELECT uc.unit_class, uc.unit_mode
703   FROM   igs_as_unit_class_all uc,
704              igs_ps_unit_ofr_opt_all uoo
705   WHERE uc.unit_class =  uoo.unit_class
706   AND   uoo.uoo_id = p_n_uoo_id;
707 
708   l_v_unit_class  igs_as_unit_class_all.unit_class%TYPE;
709   l_v_unit_mode   igs_as_unit_class_all.unit_mode%TYPE;
710 
711   BEGIN
712     p_v_unit_class := NULL;
713     p_v_unit_mode := NULL;
714 
715    log_to_fnd( p_v_module => 'finpl_get_unit_class_mode',
716                p_v_string => 'Entered finpl_get_unit_class_mode. Params: ' ||p_n_uoo_id || ', ' || p_v_unit_class ||', ' || p_v_unit_mode );
717 
718     IF p_n_uoo_id  IS NOT NULL THEN
719 
720       OPEN cur_unit_class_mode( p_n_uoo_id );
721       FETCH cur_unit_class_mode INTO l_v_unit_class, l_v_unit_mode;
722       IF cur_unit_class_mode%FOUND THEN
723         p_v_unit_class  := l_v_unit_class;
724         p_v_unit_mode   := l_v_unit_mode;
725       END IF;
726       CLOSE cur_unit_class_mode;
727      log_to_fnd( p_v_module => 'finpl_get_unit_class_mode',
728                  p_v_string => 'Derived  Unit Class: ' || p_v_unit_class ||', Unit Mode: ' || p_v_unit_mode );
729 
730     END IF;
731 
732   END finpl_get_unit_class_mode;
733 
734 
735   PROCEDURE finpl_sort_table ( p_input_tbl  IN OUT NOCOPY t_fee_as_items_typ,
736                             p_v_elm_rng_order_name IN igs_fi_elm_rng_ords.elm_rng_order_name%TYPE ) AS
737    /*************************************************************
738    Created By :      Bhaskar Annamalai
739    Date Created By : 20-JUN-2005
740    Purpose :         To Sort the Pl/sql table.
741 
742    Know limitations, enhancements or remarks
743 
744    Change History
745    Who             When          What
746   ***************************************************************/
747 
748    j NUMBER;
749    l_rec_index_row r_s_fee_as_items_typ;
750    l_n_order_num  igs_fi_er_ord_dtls.order_num%TYPE;
751    l_v_order_attr_val  igs_fi_er_ord_dtls.order_attr_value%TYPE;
752 
753    CURSOR cur_order_num (cp_n_unit_type_id   igs_fi_fee_as_items.unit_type_id%TYPE) IS
754      SELECT order_num, order_attr_value
755      FROM igs_fi_er_ord_dtls
756      WHERE elm_rng_order_name = p_v_elm_rng_order_name
757      AND order_attr_value = TO_CHAR(cp_n_unit_type_id);
758 
759   BEGIN
760     -- Populate the value of UNIT_TYPE_ID in the PL/SQL table
761     FOR i IN 1..p_input_tbl.COUNT LOOP
762       l_n_order_num := NULL;
763       l_v_order_attr_val := NULL;
764       IF (p_input_tbl(i).unit_type_id  IS NOT NULL) THEN
765         OPEN cur_order_num (p_input_tbl(i).unit_type_id);
766         FETCH cur_order_num INTO l_n_order_num, l_v_order_attr_val;
767         CLOSE cur_order_num;
768         p_input_tbl(i).element_order := l_n_order_num;
769       ELSE
770         p_input_tbl(i).element_order := NULL;
771       END IF;
772     END LOOP;
773 
774     -- Sort the table
775     FOR i IN 1..p_input_tbl.COUNT LOOP
776        l_rec_index_row := p_input_tbl(i);
777        j := i;
778        WHILE ((j > 1) AND (p_input_tbl(j-1).element_order > l_rec_index_row.element_order) )
779        LOOP
780            p_input_tbl(j) := p_input_tbl(j-1);
781            j := j-1;
782        END LOOP;
783        p_input_tbl(j) := l_rec_index_row;
784     END LOOP;
785   EXCEPTION
786       WHEN OTHERS THEN
787         log_to_fnd( p_v_module => 'finpl_sort_table',
788                     p_v_string => 'From WHEN OTHERS. ' || SUBSTR(sqlerrm,1,500));
789         Fnd_Message.Set_Name ('IGS', 'IGS_GE_UNHANDLED_EXP');
790         Fnd_Message.Set_Token('NAME','finpl_sort_table -'||SUBSTR(sqlerrm,1,500));
791         IGS_GE_MSG_STACK.ADD;
792         App_Exception.Raise_Exception;
793   END finpl_sort_table;
794 
795 
796   PROCEDURE finpl_retn_sort_table ( p_input_tbl1  IN OUT NOCOPY t_fee_as_items_typ,
797                                     p_input_tbl2  IN OUT NOCOPY t_unit_status,
798                                     p_input_tbl3  IN OUT NOCOPY t_date ) AS
799 
800    /*************************************************************
801    Created By :      Bhaskar Annamalai
802    Date Created By : 23-Aug-2005
803    Purpose :         To Sort the Pl/sql table used in Retention.
804 
805    Know limitations, enhancements or remarks
806 
807    Change History
808    Who             When          What
809   ***************************************************************/
810    j NUMBER;
811    l_rec_index_row r_s_fee_as_items_typ;
812    l_d_temp  DATE;
813    l_d_status VARCHAR2(1);
814 
815   BEGIN
816 
817     FOR i IN 1..p_input_tbl3.COUNT LOOP
818        l_rec_index_row := p_input_tbl1(i);
819        l_d_temp := p_input_tbl3(i);
820        l_d_status := p_input_tbl2(i);
821 
822        j := i;
823        WHILE ((j > 1) AND (p_input_tbl3(j-1) > l_d_temp) )
824        LOOP
825          p_input_tbl3(j) := p_input_tbl3(j-1);
826          p_input_tbl2(j) := p_input_tbl2(j-1);
827          p_input_tbl1(j) := p_input_tbl1(j-1);
828          j := j-1;
829        END LOOP;
830        p_input_tbl1(j) := l_rec_index_row;
831        p_input_tbl2(j) := l_d_status;
832        p_input_tbl3(j) := l_d_temp;
833     END LOOP;
834 
835   EXCEPTION
836       WHEN OTHERS THEN
837         log_to_fnd( p_v_module => 'finpl_retn_sort_table',
838                     p_v_string => 'From WHEN OTHERS. ' || SUBSTR(sqlerrm,1,500));
839         Fnd_Message.Set_Name ('IGS', 'IGS_GE_UNHANDLED_EXP');
840         Fnd_Message.Set_Token('NAME','finpl_retn_sort_table -'||SUBSTR(sqlerrm,1,500));
841         IGS_GE_MSG_STACK.ADD;
842         App_Exception.Raise_Exception;
843   END finpl_retn_sort_table;
844 
845 
846   PROCEDURE finpl_prc_teach_prd_retn_levl(p_person_id                 igs_fi_fee_as_all.person_id%TYPE,
847                                            p_fee_cat                   igs_fi_fee_as_all.fee_cat%TYPE,
848                                            p_fee_type                  igs_fi_fee_as_all.fee_type%TYPE,
849                                            p_fee_cal_type              igs_fi_fee_as_all.fee_cal_type%TYPE,
850                                            p_fee_ci_sequence_number    igs_fi_fee_as_all.fee_ci_sequence_number%TYPE,
851                                            p_course_cd                 igs_fi_fee_as_all.course_cd%TYPE,
852                                            p_n_uoo_id                  igs_fi_fai_dtls.uoo_id%TYPE,
853                                            p_trace_on                  VARCHAR2,
854                                            p_d_gl_date                 igs_fi_invln_int_all.gl_date%TYPE,
855                                            p_n_diff_amount             NUMBER,
856                                            p_v_retention_level         igs_fi_f_typ_ca_inst_all.retention_level_code%TYPE,
857                                            p_v_cmp_withdr_ret          igs_fi_f_typ_ca_inst_all.complete_ret_flag%TYPE,
858                                            p_v_fee_type_desc           igs_fi_fee_type_all.description%TYPE,
859                                            p_v_fee_trig_cat            igs_fi_fee_type_all.s_fee_trigger_cat%TYPE
860                                           ) AS
861  /*************************************************************
862  Created By :      Bhaskar Annamalai
863  Date Created By : 20-JUN-2005
864  Purpose :  For processing teaching period level retention.
865 
866  Know limitations, enhancements or remarks
867 
868  Change History
869  Who             When          What
870  ***************************************************************/
871   -- Cursor to obtain the Unit Section details
872   -- Retention not applicable for Unit Sections with status Invalid or Duplicate
873   CURSOR cur_usec_dtls(cp_n_person_id     igs_en_su_attempt_all.person_id%TYPE,
874                        cp_v_course_cd     igs_en_su_attempt_all.course_cd%TYPE,
875                        cp_n_uoo_id        igs_en_su_attempt_all.uoo_id%TYPE) IS
876     SELECT *
877     FROM igs_en_su_attempt_all
878     WHERE person_id = cp_n_person_id
879     AND course_cd = cp_v_course_cd
880     AND uoo_id = cp_n_uoo_id
881     ORDER BY  discontinued_dt;
882 
883   -- Cursor to determine if a given Unit Section is Non-Standard
884   CURSOR cur_non_std_usec(cp_n_uoo_id   igs_ps_unit_ofr_opt_all.uoo_id%TYPE) IS
885     SELECT non_std_usec_ind
886     FROM igs_ps_unit_ofr_opt_all
887     WHERE uoo_id = cp_n_uoo_id;
888 
889   l_v_load_incurred       VARCHAR2(1) := NULL;
890   l_v_non_std_usec        VARCHAR2(1) := NULL;
891   l_n_retention_amount    NUMBER := 0.0;
892 
893   BEGIN
894 
895     -- If a downward adjustment has happened, then Retention could be applicable.
896     -- Determine if load is incurred
897     FOR rec_usec_dtls IN cur_usec_dtls(p_person_id,
898                                        p_course_cd,
899                                        p_n_uoo_id)
900     LOOP
901        IF (rec_usec_dtls.unit_attempt_status IN ('INVALID','DUPLICATE')) THEN
902            log_to_fnd( p_v_module => 'finpl_prc_teach_prd_retn_levl',
903                        p_v_string => 'Teach Period level retention : Unit Status in Invalid or Duplicate, No retention'||
904                                      '  Uoo Id: '|| p_n_uoo_id);
905            RETURN;
906        END IF;
907 
908        log_to_fnd( p_v_module => 'finpl_prc_teach_prd_retn_levl',
909                    p_v_string => 'Teach Period level retention : Checking if load is incurred');
910        -- Determine if the Unit Section incurs load
911        l_v_load_incurred := igs_en_prc_load.enrp_get_load_apply(p_teach_cal_type              => rec_usec_dtls.cal_type,
912                                                                    p_teach_sequence_number       => rec_usec_dtls.ci_sequence_number,
913                                                                    p_discontinued_dt             => rec_usec_dtls.discontinued_dt,
914                                                                    p_administrative_unit_status  => rec_usec_dtls.administrative_unit_status,
915                                                                    p_unit_attempt_status         => rec_usec_dtls.unit_attempt_status,
916                                                                    p_no_assessment_ind           => rec_usec_dtls.no_assessment_ind,
917                                                                    p_load_cal_type               => g_v_load_cal_type,
918                                                                    p_load_sequence_number        => g_n_load_seq_num,
919                                                                    p_include_audit               => rec_usec_dtls.no_assessment_ind);
920        -- If the Unit Section incurs load, then retention is not applicable.
921        IF (l_v_load_incurred = 'Y') THEN
922            log_to_fnd( p_v_module => 'finpl_prc_teach_prd_retn_levl',
923                        p_v_string => 'Teach Period level retention : Load incurred for Usec, so skip Unit Section'||
924                                      '  Uoo Id: '|| p_n_uoo_id);
925            RETURN;
926        END IF;
927 
928        log_to_fnd( p_v_module => 'finpl_prc_teach_prd_retn_levl',
929                    p_v_string => 'Teach Period level retention : Load not incurred for Usec, continue for'||
930                                  ' Uoo Id: '|| p_n_uoo_id);
931 
932        -- Determine if Unit Section is Non-Standard or not.
933        OPEN cur_non_std_usec(p_n_uoo_id);
934        FETCH cur_non_std_usec INTO l_v_non_std_usec;
935        CLOSE cur_non_std_usec;
936 
937        IF (l_v_non_std_usec = 'Y') THEN
938            -- If the Unit Section is Non-Standard, invoked function to determine Retention Amount
939            log_to_fnd( p_v_module => 'finpl_prc_teach_prd_retn_levl',
940                        p_v_string => 'Non Standard USEC - Invoking igs_fi_gen_008.get_ns_usec_retention');
941            l_n_retention_amount := igs_fi_gen_008.get_ns_usec_retention(p_n_uoo_id  => p_n_uoo_id,
942                                                                            p_v_fee_type       => p_fee_type,
943                                                                            p_d_effective_date => rec_usec_dtls.discontinued_dt,
944                                                                            p_n_diff_amount    => p_n_diff_amount);
945            log_to_fnd( p_v_module => 'finpl_prc_teach_prd_retn_levl',
946                        p_v_string => 'Teach Period Retention - Retention Amount Derived: ' || l_n_retention_amount);
947 
948            IF NVL(l_n_retention_amount, 0.0) > 0.0 THEN
949                    log_to_fnd( p_v_module => 'finpl_prc_teach_prd_retn_levl',
950                                p_v_string => 'Teach Period Retention - Retention Amount > 0, invoking create_retention_charge.');
951                    IF (p_trace_on = 'Y') THEN
952                       fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'RET_LEVEL') || ': ' || igs_fi_gen_gl.get_lkp_meaning('IGS_FI_RET_LEVEL', p_v_retention_level));
953                       fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'WITHDWR_RET') || ': ' || igs_fi_gen_gl.get_lkp_meaning('YES_NO', p_v_cmp_withdr_ret));
954                    END IF;
955 
956                    create_retention_charge( p_n_person_id               => p_person_id,
957                                             p_v_course_cd               => p_course_cd,
958                                             p_v_fee_cal_type            => p_fee_cal_type,
959                                             p_n_fee_ci_sequence_number  => p_fee_ci_sequence_number,
960                                             p_v_fee_type                => p_fee_type,
961                                             p_v_fee_cat                 => p_fee_cat,
962                                             p_d_gl_date                 => TRUNC(p_d_gl_date),
963                                             p_n_uoo_id                  => p_n_uoo_id,
964                                             p_n_amount                  => l_n_retention_amount,
965                                             p_v_fee_type_desc           => p_v_fee_type_desc,
966                                             p_v_fee_trig_cat            => p_v_fee_trig_cat ,
967                                             p_trace_on                  => p_trace_on);
968             END IF;  -- End if for l_n_retention_amount > 0.0
969        ELSE
970             -- If Unit Section is NOT Non-Standard, then invoke Teaching Period level retention
971             log_to_fnd( p_v_module => 'finpl_prc_teach_prd_retn_levl',
972                         p_v_string => 'Not NS - Apply Teaching Period Retention - Invoking igs_fi_gen_008.get_teach_retention');
973             l_n_retention_amount := igs_fi_gen_008.get_teach_retention(p_v_fee_cal_type             => p_fee_cal_type,
974                                                                          p_n_fee_ci_sequence_number   => p_fee_ci_sequence_number,
975                                                                          p_v_fee_type                 => p_fee_type,
976                                                                          p_v_teach_cal_type           => rec_usec_dtls.cal_type,
977                                                                          p_n_teach_ci_sequence_number => rec_usec_dtls.ci_sequence_number,
978                                                                          p_d_effective_date           => rec_usec_dtls.discontinued_dt,
979                                                                          p_n_diff_amount              => p_n_diff_amount);
980             log_to_fnd( p_v_module => 'finpl_prc_teach_prd_retn_levl',
981                         p_v_string => 'Teach Period Retention - Retention Amount Derived: ' || l_n_retention_amount);
982 
983             IF NVL(l_n_retention_amount, 0.0) > 0.0 THEN
984                    log_to_fnd( p_v_module => 'finpl_prc_teach_prd_retn_levl',
985                                p_v_string => 'Teach Period Retention - Retention Amount > 0, invoking create_retention_charge.');
986                    IF (p_trace_on = 'Y') THEN
987                       fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'RET_LEVEL') || ': ' || igs_fi_gen_gl.get_lkp_meaning('IGS_FI_RET_LEVEL', p_v_retention_level));
988                       fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'WITHDWR_RET') || ': ' || igs_fi_gen_gl.get_lkp_meaning('YES_NO', p_v_cmp_withdr_ret));
989                    END IF;
990 
991                    create_retention_charge( p_n_person_id               => p_person_id,
992                                             p_v_course_cd               => p_course_cd,
993                                             p_v_fee_cal_type            => p_fee_cal_type,
994                                             p_n_fee_ci_sequence_number  => p_fee_ci_sequence_number,
995                                             p_v_fee_type                => p_fee_type,
996                                             p_v_fee_cat                 => p_fee_cat,
997                                             p_d_gl_date                 => TRUNC(p_d_gl_date),
998                                             p_n_uoo_id                  => p_n_uoo_id,
999                                             p_n_amount                  => l_n_retention_amount,
1000                                             p_v_fee_type_desc           => p_v_fee_type_desc,
1001                                             p_v_fee_trig_cat            => p_v_fee_trig_cat,
1002                                             p_trace_on                  => p_trace_on);
1003             END IF;  -- End if for l_n_retention_amount > 0.0
1004        END IF;  -- End if for l_v_non_std_usec = 'Y'
1005     END LOOP;
1006 
1007   EXCEPTION
1008       WHEN Others THEN
1009         log_to_fnd( p_v_module => 'finpl_prc_teach_prd_retn_levl',
1010                     p_v_string => 'From Exception Handler of When Others.');
1011         Fnd_Message.Set_Name('IGS','IGS_GE_UNHANDLED_EXP');
1012         Fnd_Message.Set_Token('NAME','IGS_FI_PRC_FEE_ASS.FINPL_PRC_TEACH_PRD_RETN_LEVL-'||SUBSTR(SQLERRM,1,500));
1013         igs_ge_msg_stack.add;
1014         app_exception.raise_exception;
1015   END finpl_prc_teach_prd_retn_levl;
1016 
1017   FUNCTION finpl_clc_sua_cp( p_v_unit_cd                     IN igs_en_su_attempt_all.unit_cd%TYPE,
1018                              p_n_version_number              IN igs_en_su_attempt_all.version_number%TYPE,
1019                              p_v_cal_type                    IN igs_en_su_attempt_all.cal_type%TYPE,
1020                              p_n_ci_sequence_number          IN igs_en_su_attempt_all.ci_sequence_number%TYPE,
1021                              p_v_load_cal_type               IN igs_en_su_attempt_all.cal_type%TYPE,
1022                              p_n_load_ci_sequence_number     IN igs_en_su_attempt_all.ci_sequence_number%TYPE,
1023                              p_n_override_enrolled_cp        IN igs_en_su_attempt_all.override_enrolled_cp%TYPE,
1024                              p_n_override_eftsu              IN igs_en_su_attempt_all.override_eftsu%TYPE,
1025                              p_n_uoo_id                      IN igs_en_su_attempt_all.uoo_id%TYPE,
1026                              p_v_include_audit               IN igs_en_su_attempt_all.no_assessment_ind%TYPE ) RETURN NUMBER AS
1027     /*************************************************************
1028      Created By      : Shirish Tatikonda
1029      Date Created By : 21-JUL-2004
1030      Purpose         : This function returns Enrolled/Audit/Billable Credit points.
1031                        This is invoked in finpl_clc_chg_mthd_elements, in cursor c_sua_load.
1032      Know limitations, enhancements or remarks
1033      Change History
1034      Who             When          What
1035      shtatiko        21-JUL-2004   Enh# 3741400, Created this function.
1036     ***************************************************************/
1037     l_n_eftsu        igs_fi_fee_as_items.eftsu%TYPE;
1038     l_n_enrolled_cp  igs_fi_fee_as_items.credit_points%TYPE;
1039     l_n_billing_cp   igs_fi_fee_as_items.credit_points%TYPE;
1040     l_n_audit_cp     igs_fi_fee_as_items.credit_points%TYPE;
1041     l_n_ret_cp       igs_fi_fee_as_items.credit_points%TYPE;
1042   BEGIN
1043 
1044     -- Invoke EN API to calculate Enrolled/Billable/Audit Credit Points
1045     l_n_ret_cp := igs_en_prc_load.enrp_clc_sua_load (
1046                          p_unit_cd                 => p_v_unit_cd,
1047                          p_version_number          => p_n_version_number,
1048                          p_cal_type                => p_v_cal_type,
1049                          p_ci_sequence_number      => p_n_ci_sequence_number,
1050                          p_load_cal_type           => p_v_load_cal_type,
1051                          p_load_ci_sequence_number => p_n_load_ci_sequence_number,
1052                          p_override_enrolled_cp    => p_n_override_enrolled_cp,
1053                          p_override_eftsu          => p_n_override_eftsu,
1054                          p_return_eftsu            => l_n_eftsu,                -- OUT
1055                          p_uoo_id                  => p_n_uoo_id,
1056                          p_include_as_audit        => p_v_include_audit,
1057                          p_billing_cp              => l_n_billing_cp,           -- OUT
1058                          p_audit_cp                => l_n_audit_cp,             -- OUT
1059                          p_enrolled_cp             => l_n_enrolled_cp);         -- OUT
1060 
1061     IF p_v_include_audit = 'Y' THEN
1062       RETURN NVL(l_n_audit_cp, 0);
1063     ELSE
1064       RETURN NVL(NVL(l_n_billing_cp, l_n_enrolled_cp), 0);
1065     END IF;
1066 
1067   END finpl_clc_sua_cp;
1068 
1069 -----------------------------------------------------------------------------------
1070 FUNCTION finpl_get_derived_am_at (
1071         p_person_id                     hz_parties.party_id%TYPE,
1072         p_course_cd                     IGS_PS_COURSE.course_cd%TYPE,
1073         p_effective_dt                  DATE,
1074         p_fee_cal_type                  igs_fi_f_cat_fee_lbl_all.fee_cal_type%TYPE,
1075         p_fee_ci_sequence_number        igs_fi_f_cat_fee_lbl_all.fee_ci_sequence_number%TYPE,
1076         p_fee_type                      igs_fi_f_cat_fee_lbl_all.fee_type%TYPE,
1077         p_s_fee_trigger_cat             igs_fi_fee_type_all.s_fee_trigger_cat%TYPE,
1078         p_trace_on                      VARCHAR2,
1079         p_c_career                      IN      igs_ps_ver_all.course_type%TYPE,
1080         p_derived_attendance_type       OUT NOCOPY      igs_fi_fee_as_rate.attendance_type%TYPE,
1081         p_derived_att_mode              OUT NOCOPY      igs_en_atd_mode_all.govt_attendance_mode%TYPE) RETURN BOOLEAN  AS
1082 /*************************************************************
1083  Created By : abshriva
1084  Date Created By : 1-Jun-2006
1085  Purpose : Bug 5104329:Getting derived values of attendance mode and type.
1086  Know limitations, enhancements or remarks
1087  Change History
1088  Who             When          What
1089 *************************************************************/
1090 
1091 BEGIN
1092   DECLARE
1093     cst_on          CONSTANT        VARCHAR2(10) := 'ON';
1094     cst_off         CONSTANT        VARCHAR2(10) := 'OFF';
1095     cst_composite   CONSTANT        VARCHAR2(10) := 'COMPOSITE';
1096     v_derived_attendance_type       igs_en_atd_type_all.attendance_type%TYPE;
1097     v_derived_attendance_mode       VARCHAR2(10);  -- Used only in case of Derived Profile. Holds values On, Off, and Composite.
1098     v_derived_govt_att_mode         igs_en_atd_mode_all.govt_attendance_mode%TYPE;
1099     v_derived_prog_att_mode         igs_en_atd_mode_all.attendance_mode%TYPE;  -- Used in Nominated Profile. Holds value of AM associated at Prog Attempt.
1100     v_on_att_mode                   BOOLEAN := FALSE;
1101     v_off_att_mode                  BOOLEAN := FALSE;
1102     v_composite_att_mode            BOOLEAN := FALSE;
1103     TYPE derived_values_rec IS RECORD ( course_cd      igs_ps_ver_all.course_cd%TYPE,
1104                                         course_type    igs_ps_ver_all.course_type%TYPE);
1105     TYPE derived_values_ref IS REF CURSOR RETURN derived_values_rec;
1106     c_scafv    derived_values_ref;
1107     l_c_scafv  c_scafv%ROWTYPE;
1108 
1109     -- record type variable defined for geeting the attendance type and govt attendance mode when the
1110     -- nominated values are used
1111     TYPE l_der_nom_rec IS RECORD ( attendance_type  igs_en_atd_type_all.attendance_type%TYPE,
1112                                    govt_att_mode    igs_en_atd_mode_all.govt_attendance_mode%TYPE,
1113                                    prog_att_mode    igs_en_atd_mode_all.attendance_mode%TYPE);
1114     TYPE l_der_nom_ref IS REF CURSOR RETURN l_der_nom_rec;
1115     l_v_prg_liabale      VARCHAR2(10);
1116     c_att_md_ty    l_der_nom_ref;
1117     l_c_att_md_ty  c_att_md_ty%ROWTYPE;
1118     l_n_cr_points        igs_en_su_attempt_all.override_achievable_cp%TYPE;
1119     l_n_fte              igs_en_su_attempt_all.override_achievable_cp%TYPE;
1120 CURSOR c_sca_psv ( cp_v_lookup_type igs_lookups_view.lookup_type%TYPE,
1121                            cp_v_fee_ass_ind igs_lookups_view.fee_ass_ind%TYPE ) IS
1122           SELECT  spat.person_id,
1123                   spat.program_cd,
1124                   spat.program_version,
1125                   spat.fee_cat,
1126                   sca.commencement_dt,
1127                   sca.discontinued_dt,
1128                   sca.adm_admission_appl_number,
1129                   sca.adm_nominated_course_cd,
1130                   sca.adm_sequence_number,
1131                   sca.cal_type,
1132                   spat.location_cd,
1133                   spat.attendance_mode,
1134                   spat.attendance_type,
1135                   ps.course_type
1136           FROM    igs_en_spa_terms spat,
1137                   igs_en_stdnt_ps_att_all sca,
1138                   igs_ps_ver_all ps,
1139                   igs_lookups_view lkps
1140           WHERE   spat.person_id = p_person_id
1141           AND     spat.person_id = sca.person_id
1142           AND     spat.program_cd = sca.course_cd
1143           AND     spat.program_version = sca.version_number
1144           AND     spat.term_cal_type = g_v_load_cal_type
1145           AND     spat.term_sequence_number = g_n_load_seq_num
1146           AND     spat.program_cd = ps.course_cd
1147           AND     spat.program_version = ps.version_number
1148           AND     lkps.lookup_type = cp_v_lookup_type
1149           AND     sca.course_attempt_status = lkps.lookup_code
1150           AND     lkps.fee_ass_ind = cp_v_fee_ass_ind;
1151 
1152 
1153   BEGIN
1154     log_to_fnd( p_v_module => 'finpl_get_derived_am_at',
1155                 p_v_string => 'Entered finpl_get_derived_am_at. Parameters are: ' ||
1156                               p_person_id || ', ' || p_course_cd || ', ' || TO_CHAR(p_effective_dt, 'DD-MON-YYYY')
1157                               || ', ' || p_fee_cal_type || ', ' || p_fee_ci_sequence_number || ', ' || p_fee_type
1158                                || ', ' || p_s_fee_trigger_cat || ', ' || p_trace_on || ', ' || p_c_career );
1159     IF (p_trace_on = 'Y') THEN
1160       fnd_file.new_line(fnd_file.log);
1161     END IF;
1162     -- Obtain System Fee Type for the fee_type provided
1163 
1164     log_to_fnd( p_v_module => 'finpl_get_derived_am_at',
1165                 p_v_string => 'Profile IGS_FI_NOM_DER_VALUES value: ' || g_v_att_profile );
1166     -- Get the derived attendance type
1167     ----------------------------------
1168 
1169     -- Profile Value is NOMINATED:
1170     --       If Institution Fee OR Primary Career Calculation Method
1171     --          Get AT and AM from Key Program
1172     --       Else
1173     --          Get AT and AM from Program in context
1174     -- Profile Value is DERIVED
1175     --       Call EN APIs to get AT.
1176 
1177     IF (g_v_att_profile = gcst_nominated) THEN --Enh# 2162747, SFCR06
1178 
1179         IF (p_s_fee_trigger_cat = 'INSTITUTN' OR g_c_fee_calc_mthd = g_v_primary_career) THEN  -- For Institutional Level
1180             OPEN c_att_md_ty FOR SELECT a.attendance_type,
1181                                         b.govt_attendance_mode,
1182                                         a.attendance_mode
1183                                  FROM   igs_en_spa_terms a,
1184                                         igs_en_atd_mode_all b
1185                                  WHERE  a.person_id = p_person_id
1186                                  AND    a.term_cal_type = g_v_load_cal_type
1187                                  AND    a.term_sequence_number = g_n_load_seq_num
1188                                  AND    b.attendance_mode = a.attendance_mode
1189                                  AND    a.key_program_flag = 'Y';
1190         ELSE -- For Other than Institutional Level
1191             OPEN c_att_md_ty FOR SELECT a.attendance_type,
1192                                         b.govt_attendance_mode,
1193                                         a.attendance_mode
1194                                  FROM   igs_en_spa_terms a,
1195                                         igs_en_atd_mode_all b
1196                                  WHERE  a.person_id = p_person_id
1197                                  AND    a.program_cd = p_course_cd
1198                                  AND    a.term_cal_type = g_v_load_cal_type
1199                                  AND    a.term_sequence_number = g_n_load_seq_num
1200                                  AND    b.attendance_mode = a.attendance_mode;
1201         END IF;
1202 
1203       FETCH c_att_md_ty INTO l_c_att_md_ty;
1204       -- Same Attendance Mode and Attendance Type variables are used to avoid duplicate declaring of the local variables
1205       v_derived_attendance_type := l_c_att_md_ty.attendance_type;
1206       v_derived_govt_att_mode   := l_c_att_md_ty.govt_att_mode;
1207       v_derived_prog_att_mode   := l_c_att_md_ty.prog_att_mode;
1208       CLOSE c_att_md_ty;
1209 
1210       log_to_fnd( p_v_module => 'finpl_get_derived_am_at',
1211                   p_v_string => 'Nominated Profile. Derived Att Type: ' || v_derived_attendance_type ||
1212                                 ', Govt. Att Mode: ' || v_derived_govt_att_mode ||
1213                                 ', Prog Att Mode: ' || v_derived_prog_att_mode);
1214 
1215     ELSE
1216       log_to_fnd( p_v_module => 'finpl_get_derived_am_at',
1217                   p_v_string => 'Profile value is Derived. Deriving Attendance Type.');
1218       -- Get Attendance Type by calling EN API.
1219       IF p_s_fee_trigger_cat = gcst_institutn OR
1220          g_c_fee_calc_mthd = g_v_primary_career THEN
1221         igs_en_prc_load.enrp_get_inst_latt_fte ( p_person_id        => p_person_id,
1222                                                  p_load_cal_type    => g_v_load_cal_type,
1223                                                  p_load_seq_number  => g_n_load_seq_num,
1224                                                  p_attendance       => v_derived_attendance_type,
1225                                                  p_credit_points    => l_n_cr_points,
1226                                                  p_fte              => l_n_fte );
1227 
1228       ELSE /* p_s_fee_trigger_cat <> gcst_institutn AND g_c_fee_calc_mthd <> g_v_primary_career */
1229         v_derived_attendance_type := igs_en_prc_load.enrp_get_prg_att_type ( p_person_id        => p_person_id,
1230                                                                              p_course_cd        => p_course_cd,
1231                                                                              p_cal_type         => g_v_load_cal_type,
1232                                                                              p_sequence_number  => g_n_load_seq_num );
1233       END IF;
1234     END IF;
1235 
1236     IF (v_derived_attendance_type IS NULL) THEN
1237       IF (p_trace_on = 'Y') THEN
1238         fnd_message.set_name ( 'IGS', 'IGS_FI_UNABLE_DERIVE_ATTTYPE');
1239         fnd_file.put_line (fnd_file.log, fnd_message.get);
1240       END IF;
1241     END IF;
1242 
1243     log_to_fnd( p_v_module => 'finpl_get_derived_am_at',
1244                 p_v_string => 'Deriving Attendance Mode...');
1245     -- Get the derived attendance mode
1246     ----------------------------------
1247     IF (g_v_att_profile = gcst_nominated) THEN
1248       IF v_derived_govt_att_mode IS NULL AND v_derived_prog_att_mode IS NULL THEN
1249         IF (p_trace_on = 'Y') THEN
1250           -- Trace Entry
1251            fnd_message.set_name ( 'IGS', 'IGS_FI_UNABLE_DERIVE_ATTMODE');
1252            fnd_file.put_line (fnd_file.log, fnd_message.get);
1253         END IF;
1254       END IF;
1255     ELSE
1256 
1257       -- Processing for PRIMARY_CAREER is same for Institution and Non-Institution Fees.
1258       IF (p_s_fee_trigger_cat = gcst_institutn AND g_c_fee_calc_mthd <> g_v_primary_career) THEN
1259 
1260         log_to_fnd( p_v_module => 'finpl_get_derived_am_at',
1261                     p_v_string => 'Looping through Liable Programs in Institution case. (table g_inst_liable_progs_tbl) ');
1262         FOR l_sca_psv IN c_sca_psv('CRS_ATTEMPT_STATUS', 'Y') LOOP
1263           l_v_prg_liabale := igs_fi_gen_001.check_stdnt_prg_att_liable (
1264                                        p_n_person_id              => l_sca_psv.person_id,
1265                                        p_v_course_cd              => l_sca_psv.program_cd,
1266                                        p_n_course_version         => l_sca_psv.program_version,
1267                                        p_v_fee_cat                => l_sca_psv.fee_cat,
1268                                        p_v_fee_type               => p_fee_type,
1269                                        p_v_s_fee_trigger_cat      => p_s_fee_trigger_cat,
1270                                        p_v_fee_cal_type           => p_fee_cal_type,
1271                                        p_n_fee_ci_seq_number      => p_fee_ci_sequence_number,
1272                                        p_n_adm_appl_number        => l_sca_psv.adm_admission_appl_number,
1273                                        p_v_adm_nom_course_cd      => l_sca_psv.adm_nominated_course_cd,
1274                                        p_n_adm_seq_number         => l_sca_psv.adm_sequence_number,
1275                                        p_d_commencement_dt        => l_sca_psv.commencement_dt,
1276                                        p_d_disc_dt                => l_sca_psv.discontinued_dt,
1277                                        p_v_cal_type               => l_sca_psv.cal_type,
1278                                        p_v_location_cd            => l_sca_psv.location_cd,
1279                                        p_v_attendance_mode        => l_sca_psv.attendance_mode,
1280                                        p_v_attendance_type        => l_sca_psv.attendance_type ) ;
1281           IF l_v_prg_liabale = 'TRUE' THEN
1282             v_derived_attendance_mode := igs_en_gen_006.enrp_get_sca_am(p_person_id,
1283                                                                         l_sca_psv.program_cd,
1284                                                                         g_v_load_cal_type,
1285                                                                         g_n_load_seq_num);
1286             log_to_fnd( p_v_module => 'finpl_get_derived_am_at',
1287                         p_v_string => 'Attendance Mode derived for course ' || l_sca_psv.program_cd || ' is ' || v_derived_attendance_mode);
1288             IF (v_derived_attendance_mode = cst_on) THEN
1289               v_on_att_mode := TRUE;
1290             ELSIF (v_derived_attendance_mode = cst_off) THEN
1291               v_off_att_mode := TRUE;
1292             ELSIF (v_derived_attendance_mode = cst_composite) THEN
1293               v_composite_att_mode := TRUE;
1294             END IF;
1295           END IF;
1296         END LOOP;
1297         -- Determine the govt attendance mode from the combination
1298         -- of derived values across the student program attempts
1299         v_derived_prog_att_mode := NULL; -- This variable holds value only in case of Nominated Profile
1300         IF (v_on_att_mode = TRUE AND
1301           v_off_att_mode = FALSE AND
1302           v_composite_att_mode = FALSE) THEN
1303           v_derived_govt_att_mode := 1;
1304         ELSIF (v_on_att_mode = FALSE AND
1305           v_off_att_mode = TRUE AND
1306           v_composite_att_mode = FALSE) THEN
1307           v_derived_govt_att_mode := 2;
1308         ELSIF ((v_on_att_mode = TRUE AND
1309           v_off_att_mode = TRUE) OR
1310           v_composite_att_mode = TRUE) THEN
1311           v_derived_govt_att_mode := 3;
1312         ELSE
1313           IF (p_trace_on = 'Y') THEN
1314             -- Trace Entry
1315             fnd_message.set_name ( 'IGS', 'IGS_FI_UNABLE_DERIVE_ATTMODE');
1316             fnd_file.put_line(fnd_file.log, fnd_message.get);
1317           END IF;
1318         END IF;
1319         log_to_fnd( p_v_module => 'finpl_get_derived_am_at',
1320                     p_v_string => 'Institution Case: Attendance Mode: ' || v_derived_govt_att_mode);
1321 
1322 
1323       ELSE /* p_s_fee_trigger_cat <> gcst_institutn OR g_c_fee_calc_mthd = 'PRIMARY_CAREER' */
1324 
1325         IF ( g_c_fee_calc_mthd IN (g_v_program, g_v_career)) THEN
1326 
1327           -- PROGRAM: Derive AM from the course in context
1328           -- CAREER : Derive AM for the Primary Program of career i.e., course in context
1329 
1330             v_derived_attendance_mode := igs_en_gen_006.enrp_get_sca_am(p_person_id,
1331                                                                         p_course_cd,
1332                                                                         g_v_load_cal_type,
1333                                                                         g_n_load_seq_num);
1334 
1335           v_derived_prog_att_mode := NULL; -- This variable holds value only in case of Nominated Profile
1336           IF (v_derived_attendance_mode = cst_on) THEN
1337             v_derived_govt_att_mode := 1;
1338           ELSIF (v_derived_attendance_mode = cst_off) THEN
1339             v_derived_govt_att_mode := 2;
1340           ELSIF (v_derived_attendance_mode = cst_composite) THEN
1341             v_derived_govt_att_mode := 3;
1342           ELSE
1343             IF (p_trace_on = 'Y') THEN
1344               -- Trace Entry
1345               fnd_message.set_name ( 'IGS', 'IGS_FI_UNABLE_DERIVE_ATTMODE');
1346               fnd_file.put_line (fnd_file.log, fnd_message.get);
1347             END IF;
1348           END IF;
1349           log_to_fnd( p_v_module => 'finpl_get_derived_am_at',
1350                       p_v_string => 'Non-Institution Case, PROGRAM/CAREER: Attendance Mode: ' || v_derived_govt_att_mode);
1351 
1352         ELSIF ( g_c_fee_calc_mthd =g_v_primary_career) THEN
1353           -- Derive AM from Key Program of the person for the given term.
1354 
1355           OPEN c_scafv FOR SELECT program_cd course_cd,
1356                                     NULL
1357                              FROM   igs_en_spa_terms
1358                              WHERE  person_id = p_person_id
1359                              AND    term_cal_type = g_v_load_cal_type
1360                              AND    term_sequence_number = g_n_load_seq_num;
1361 
1362           LOOP
1363           FETCH c_scafv INTO l_c_scafv;
1364           EXIT WHEN c_scafv%NOTFOUND;
1365 
1366             v_derived_attendance_mode := igs_en_gen_006.enrp_get_sca_am( p_person_id,
1367                                                                            l_c_scafv.course_cd,
1368                                                                            g_v_load_cal_type,
1369                                                                            g_n_load_seq_num);
1370 
1371             IF (v_derived_attendance_mode = cst_on) THEN
1372                 v_on_att_mode := TRUE;
1373             ELSIF (v_derived_attendance_mode = cst_off) THEN
1374               v_off_att_mode := TRUE;
1375             ELSIF (v_derived_attendance_mode = cst_composite) THEN
1376               v_composite_att_mode := TRUE;
1377             END IF;
1378 
1379           END LOOP;
1380           CLOSE c_scafv;
1381 
1382           -- Determine the govt attendance mode from the combination
1383           -- of derived values across the load periods
1384           v_derived_prog_att_mode := NULL; -- This variable holds value only in case of Nominated Profile
1385           IF (v_on_att_mode = TRUE AND
1386             v_off_att_mode = FALSE AND
1387             v_composite_att_mode = FALSE) THEN
1388             v_derived_govt_att_mode := 1;
1389           ELSIF (v_on_att_mode = FALSE AND
1390             v_off_att_mode = TRUE AND
1391             v_composite_att_mode = FALSE) THEN
1392             v_derived_govt_att_mode := 2;
1393           ELSIF ((v_on_att_mode = TRUE AND
1394             v_off_att_mode = TRUE) OR
1395             v_composite_att_mode = TRUE) THEN
1396             v_derived_govt_att_mode := 3;
1397           ELSE
1398             IF (p_trace_on = 'Y') THEN
1399               -- Trace Entry
1400               fnd_message.set_name ( 'IGS', 'IGS_FI_UNABLE_DERIVE_ATTMODE');
1401               fnd_file.put_line (fnd_file.log, fnd_message.get);
1402             END IF;
1403           END IF;
1404           log_to_fnd( p_v_module => 'finpl_get_derived_am_at',
1405                       p_v_string => 'Non-Institution Case, PRIMARY_CAREER: Attendance Mode: ' || v_derived_govt_att_mode);
1406         END IF; /* g_c_fee_calc_mthd */
1407       END IF;
1408     END IF; /* Nominated or Derived */
1409 
1410     -- Message about derivation of Attendance type and mode needs to be shown only if both
1411     -- have been derived.
1412     IF (v_derived_attendance_type IS NOT NULL) AND (v_derived_govt_att_mode IS NOT NULL) THEN
1413       IF (p_trace_on = 'Y') THEN
1414         fnd_message.set_name ( 'IGS', 'IGS_FI_ATTTYPE_GOVT_ATTMODE');
1415         fnd_message.set_token('ATT_TYPE', v_derived_attendance_type);
1416         fnd_file.put_line(fnd_file.log, fnd_message.get );
1417         fnd_message.set_name('IGS', 'IGS_FI_DER_ATT_TYPE_GOVT_MODE');
1418         fnd_message.set_token('ATT_MODE', v_derived_govt_att_mode);
1419         fnd_file.put_line (fnd_file.log, fnd_message.get);
1420       END IF;
1421     END IF;
1422 
1423     p_derived_attendance_type := v_derived_attendance_type;
1424     IF (g_v_att_profile = gcst_nominated) THEN
1425       p_derived_att_mode := v_derived_prog_att_mode;
1426     ELSE
1427       p_derived_att_mode := v_derived_govt_att_mode;
1428     END IF;
1429     log_to_fnd( p_v_module => 'finpl_get_derived_am_at',
1430                 p_v_string => 'End of finpl_get_derived_am_at. Out: Att Type: '|| p_derived_attendance_type
1431                               || ', Govt Att Mode: ' || p_derived_att_mode );
1432     RETURN TRUE;
1433 
1434   END;
1435 EXCEPTION
1436 WHEN OTHERS THEN
1437   log_to_fnd( p_v_module => 'finpl_get_derived_am_at',
1438               p_v_string => 'From Exception Handler of When Others.');
1439   fnd_message.set_name ('IGS', 'IGS_GE_UNHANDLED_EXP');
1440   fnd_message.set_token('NAME','IGS_FI_PRC_FEE_ASS.FINPL_GET_DERIVED_AM_AT-'||SUBSTR(sqlerrm,1,500));
1441   igs_ge_msg_stack.add;
1442   app_exception.raise_exception;
1443 END finpl_get_derived_am_at;
1444 -----------------------------------------------------------------------------------
1445 
1446 FUNCTION finp_clc_ass_amnt( p_effective_dt             IN DATE ,
1447                         p_person_id                    IN hz_parties.party_id%TYPE ,
1448                         p_course_cd                    IN igs_en_stdnt_ps_att_all.course_cd%TYPE ,
1449                         p_course_version_number        IN igs_en_stdnt_ps_att_all.version_number%TYPE ,
1450                         p_course_attempt_status        IN VARCHAR2 ,
1451                         p_fee_type                     IN igs_fi_f_cat_fee_lbl_all.fee_type%TYPE ,
1452                         p_fee_cal_type                 IN igs_fi_f_cat_fee_lbl_all.fee_cal_type%TYPE ,
1453                         p_fee_ci_sequence_number       IN igs_fi_f_cat_fee_lbl_all.fee_ci_sequence_number%TYPE ,
1454                         p_fee_cat                      IN IGS_FI_F_CAT_CA_INST.FEE_CAT%TYPE ,
1455                         p_s_fee_type                   IN igs_fi_fee_type_all.s_fee_type%TYPE ,
1456                         p_s_fee_trigger_cat            IN VARCHAR2 ,
1457                         p_rul_sequence_number          IN igs_fi_f_cat_fee_lbl_all.rul_sequence_number%TYPE ,
1458                         p_charge_method                IN igs_fi_f_typ_ca_inst_all.s_chg_method_type%TYPE ,
1459                         p_location_cd                  IN VARCHAR2 ,
1460                         p_attendance_type              IN VARCHAR2 ,
1461                         p_attendance_mode              IN VARCHAR2 ,
1462                         p_trace_on                     IN VARCHAR2 ,
1463                         p_creation_dt                  IN OUT NOCOPY DATE ,
1464                         p_charge_elements              IN OUT NOCOPY igs_fi_fee_as_all.chg_elements%TYPE ,
1465                         p_fee_assessment               IN OUT NOCOPY NUMBER,
1466                         p_charge_rate                  OUT NOCOPY IGS_FI_FEE_AS_RATE.chg_rate%TYPE,
1467                         p_c_career                     IN igs_ps_ver_all.course_type%TYPE,
1468                         p_elm_rng_order_name           IN igs_fi_f_typ_ca_inst_all.elm_rng_order_name%TYPE,
1469                         p_n_max_chg_elements           IN igs_fi_fee_as_items.max_chg_elements%TYPE,
1470                         p_n_called                     IN NUMBER) RETURN BOOLEAN AS
1471 /*************************************************************
1472  Created By :
1473  Date Created By :
1474  Purpose :
1475  Know limitations, enhancements or remarks
1476  Change History
1477  Who             When          What
1478  pathipat        23-Nov-2005   Bug 4718712 - Added code to set local variable to p_course_version_number
1479  pathipat        21-Sep-2005   Bug 3513252 - Removed appending IGS_FI_PRE_SET_CHARGE to the fee type description
1480                                Removed local variable v_fee_description as it is not being used anymore
1481  bannamal        08-Jul-2005   Enh#3392088 Campus Privilege Fee. Changes done as per TD.
1482  bannamal        03-JUN-2005   Bug#3442712 Unit Level Fee Assessment Build. Modified c_elm_rng_rates to include
1483                                unit_type_id,  unit_mode, unit_cd, unit_version_number,unit_level. Added code to
1484                                get derived Unit Program Type level, Unit Class, Unit Mode, Version Number, Unit Level.
1485  bannamal        27-May-2005   Bug#4077763 Fee Calculation Performance Enhancement. Changes done as per TD.
1486  shtatiko        27-JUL-2004   Bug# 3795849, Added l_v_derived_prog_att_mode to hold value of AM set at Program Attempt.
1487                                Bug# 3784618, Changed parameters and defnition of c_cfar
1488  UUDAYAPR 17-DEC-2003 --Modified The Parameter Type Of P_fee_assessment To Number
1489                          From Igs_fi_fee_ass_debt_v.Assessment_amount%Type.
1490  shtatiko        08-DEC-2003   Bug# 3175779, Removed the cursor c_fterrv. Added c_elm_rng_rates and c_elm_ranges.
1491                                Modified the remaining code to effect this change.
1492  shtatiko        13-NOV-2003   Bug# 3255069, p_charge_elements is made to 1 only when Charge Method is overridden.
1493                                And this is done only after processing all records in PL/SQL Table.
1494  pathipat        05-Nov-2003   Enh 3117341 - Audit and Special Fees TD
1495                                Added code for Audit Fee Type
1496  pathipat        29-Oct-2003   Bug 3166331 - Derived location_cd from SUA level if charge method <> Flatrate.
1497                                Added cursor c_sua_location_cd for the same.
1498  pathipat        13-Oct-2003   Bug 3166331 - Modified code to derive org_unit_cd from Unit Attempt/Unit Section level
1499                                if the charge method is not Flatrate. Also to derive course_cd irrespective of override
1500                                Also for Predictive Mode, derived the course_cd and org_unit_Cd from SPA level.
1501  pathipat        12-Sep-2003   Enh 3108052 - Unit Sets in Rate Table build
1502                                Modified c_fterrv to include unit_set_cd and us_Version_number
1503                                Added logic w.r.t unit_set_cd and version_number
1504  pathipat       03-Sep-2003    Bug 3123669 - If charge method is overridden, then re-set charge method
1505                                to Flat Rate and Status = 'O'.
1506  rnirwani        02-May-02  Bug# 2344901
1507                             Modification done to local procedure finpl_fin_far
1508                             in the section where the calculation is done for the assessment based upon the
1509                             charge elements and the charge rate code has been modified to take care of null values for
1510                             the charge elements, charge rate and the assessed amount.
1511  rnirwani        02-May-02  Bug# 2345191
1512                             cursor c_cfar has been modified to accept the attendance mode, type and location code
1513                             as parameter when the cursor is invoked.
1514                             the cursor invocation has been changed to accept the derived values of above.
1515                             The parameter values would not be used for identifying the contract charge rate.
1516 
1517  (reverse chronological order - newest change first)
1518 ***************************************************************/
1519 lv_param_values VARCHAR2(1080);
1520 BEGIN
1521 DECLARE
1522 e_one_record_expected           EXCEPTION;
1523 v_message_name                  VARCHAR2(30);
1524 v_charge_rate                   IGS_FI_FEE_AS_RATE.chg_rate%TYPE := 0.0;
1525 v_lower_nrml_rate_ovrd_ind      IGS_FI_FEE_AS_RT.lower_nrml_rate_ovrd_ind%TYPE;
1526 v_residency_status_cd           igs_fi_fee_as_rate.residency_status_cd%TYPE;
1527 v_class_standing                igs_fi_fee_as_rate.class_standing%TYPE;
1528 v_cfar_chg_rate                 IGS_FI_FEE_AS_RT.chg_rate%TYPE;
1529 v_derived_location_cd           igs_fi_fee_as_rate.location_cd%TYPE;
1530 v_derived_attendance_type       igs_fi_fee_as_rate.attendance_type%TYPE;
1531 v_derived_govt_att_mode         igs_en_atd_mode_all.govt_attendance_mode%TYPE;
1532 l_v_derived_prog_att_mode       igs_en_atd_mode_all.attendance_mode%TYPE;
1533 
1534 v_derived_residency_status_cd   igs_fi_fee_as_rate.residency_status_cd%TYPE;
1535 v_derived_org_unit_cd           hz_parties.party_number%TYPE;
1536 v_derived_class_standing        igs_fi_fee_as_rate.class_standing%TYPE;
1537 
1538 v_derived_unit_set_cd           igs_fi_fee_as_rate.unit_set_cd%TYPE := NULL;
1539 v_derived_us_version_num        igs_fi_fee_as_rate.us_version_number%TYPE := NULL;
1540 
1541 lv_cntrct_rt_apply              BOOLEAN;
1542 
1543 /**to check  whether override charge method is actioned**/
1544 lv_charge_override BOOLEAN := FALSE;
1545 lv_fee_assessment IGS_FI_FEE_AS_ITEMS.amount%TYPE;
1546 v_derived_course_cd igs_en_stdnt_ps_att_all.course_cd%TYPE;
1547 l_overide_chg_method igs_fi_f_typ_ca_inst_all.s_chg_method_type%TYPE;
1548 l_fee_category IGS_FI_F_CAT_CA_INST.FEE_CAT%TYPE;
1549 
1550 l_ch_ovr_exist BOOLEAN := FALSE;
1551 
1552 l_b_elm_ranges_defined BOOLEAN := FALSE;
1553 l_b_elm_range_applies BOOLEAN := FALSE;
1554 l_n_crs_version_num   igs_fi_fee_as_items.crs_version_number%TYPE;
1555 
1556 v_derived_unit_type_id             igs_fi_fee_as_rate.unit_type_id%TYPE;
1557 v_derived_unit_class               igs_fi_fee_as_rate.unit_class%TYPE;
1558 v_derived_unit_mode                igs_fi_fee_as_rate.unit_mode%TYPE;
1559 v_derived_unit_cd                  igs_fi_fee_as_rate.unit_cd%TYPE;
1560 v_derived_unit_version_num         igs_fi_fee_as_rate.unit_version_number%TYPE;
1561 v_derived_unit_level               igs_fi_fee_as_rate.unit_level%TYPE;
1562 l_v_level_code                     igs_ps_unit_type_lvl.level_code%TYPE;
1563 
1564 l_v_inst_course_cd                 igs_fi_fai_dtls.course_cd%TYPE;
1565 l_v_inst_unit_att_status           igs_fi_fai_dtls.unit_attempt_status%TYPE;
1566 l_v_inst_location_cd               igs_fi_fai_dtls.location_cd%TYPE;
1567 l_v_inst_org_unit_cd               igs_fi_fai_dtls.org_unit_cd%TYPE;
1568 l_b_derived        BOOLEAN := FALSE;
1569 l_n_called         NUMBER;
1570 l_n_count          NUMBER;
1571 l_v_trace_on       VARCHAR2(5);
1572 l_b_elm_rng        BOOLEAN  := FALSE;
1573 l_b_pred           BOOLEAN  := FALSE;
1574 
1575 /**Cursor to get fee type description**/
1576  CURSOR c_fee_type( cp_fee_type      IGS_FI_FEE_AS_ITEMS.FEE_TYPE%TYPE ) IS
1577         SELECT description
1578         FROM igs_fi_fee_type_all
1579         WHERE fee_type = cp_fee_type;
1580 
1581 v_fee_type_description     igs_fi_fee_type_all.description%TYPE;
1582 
1583 -- Cursor to find all rates defined under element range found in above cursor.
1584 CURSOR c_elm_rng_rates ( cp_v_fee_type       igs_fi_f_typ_ca_inst_all.fee_type%TYPE,
1585                          cp_v_fee_cal_type   igs_fi_f_typ_ca_inst_all.fee_cal_type%TYPE,
1586                          cp_n_ci_seq_number  igs_fi_f_typ_ca_inst_all.fee_ci_sequence_number%TYPE,
1587                          cp_v_fee_cat        igs_fi_fee_cat_all.fee_cat%TYPE,
1588                          cp_n_range_number   igs_fi_elm_range.range_number%TYPE,
1589                          cp_v_relation_type  igs_fi_elm_range.s_relation_type%TYPE) IS
1590   SELECT err.rate_number,
1591          far.order_of_precedence,
1592          far.chg_rate,
1593          far.govt_hecs_payment_option,
1594          far.govt_hecs_cntrbtn_band,
1595          far.location_cd,
1596          far.attendance_type,
1597          far.attendance_mode,
1598          far.unit_class,
1599          far.residency_status_id,
1600          far.residency_status_cd,
1601          far.course_cd,
1602          far.version_number,
1603          far.class_standing ,
1604          far.org_party_id,
1605          far.unit_set_cd,
1606          far.us_version_number,
1607          far.unit_type_id,
1608          far.unit_mode,
1609          far.unit_cd,
1610          far.unit_version_number,
1611          far.unit_level
1612   FROM igs_fi_elm_range_rt err,
1613        igs_fi_fee_as_rate far
1614   WHERE far.fee_type = err.fee_type
1615   AND far.fee_cal_type = err.fee_cal_type
1616   AND far.fee_ci_sequence_number = err.fee_ci_sequence_number
1617   AND far.rate_number = err.rate_number
1618   AND far.s_relation_type = err.s_relation_type
1619   AND (far.fee_cat = err.fee_cat OR (far.fee_cat IS NULL AND err.fee_cat IS NULL))
1620   AND err.fee_type = cp_v_fee_type
1621   AND err.fee_cal_type = cp_v_fee_cal_type
1622   AND err.fee_ci_sequence_number = cp_n_ci_seq_number
1623   AND (err.fee_cat IS NULL OR err.fee_cat = cp_v_fee_cat)
1624   AND err.range_number = cp_n_range_number
1625   AND err.s_relation_type = cp_v_relation_type  -- just to be sure that Elm Ranges and Elm Range Rates are picked up from same level and so redundant.
1626   AND err.logical_delete_dt IS NULL
1627   AND far.logical_delete_dt IS NULL
1628   ORDER BY far.order_of_precedence ASC;
1629 
1630 -- This cursor identifies the contact rate based for the person program attempt for the fee type being processed.
1631 -- If the Profile is Nominated, Rate's AM is compared against Nominated Program AM.
1632 --                   Derived, Derived Govt AM is compared against Govt AM mapped to Rate's AM.
1633 CURSOR c_cfar ( cp_location_cd      igs_fi_fee_as_rate.location_cd%TYPE,
1634                 cp_attendance_type  igs_fi_fee_as_rate.attendance_type%TYPE,
1635                 cp_prog_att_mode    igs_fi_fee_as_rate.attendance_mode%TYPE,
1636                 cp_govt_att_mode    igs_en_atd_mode_all.govt_attendance_mode%TYPE) IS
1637   SELECT cfar.lower_nrml_rate_ovrd_ind,
1638          cfar.chg_rate
1639   FROM igs_fi_fee_as_rt  cfar,
1640        igs_en_atd_mode_all am
1641   WHERE cfar.person_id = p_person_id AND
1642         cfar.course_cd = p_course_cd AND
1643         cfar.FEE_TYPE = p_fee_type AND
1644         NVL(cfar.location_cd, cp_location_cd) = cp_location_cd AND
1645         NVL(cfar.attendance_type, cp_attendance_type) = cp_attendance_type AND
1646         am.attendance_mode (+) = cfar.attendance_mode AND
1647         (
1648          (g_v_att_profile = gcst_nominated AND NVL(cfar.attendance_mode, cp_prog_att_mode) = cp_prog_att_mode)
1649          OR
1650          (g_v_att_profile = gcst_derived AND NVL(am.govt_attendance_Mode, cp_govt_att_mode) = cp_govt_att_mode)
1651         ) AND
1652         TRUNC(p_effective_dt) >= TRUNC(cfar.start_dt) AND
1653         (cfar.end_dt IS NULL OR
1654         TRUNC(p_effective_dt) <= TRUNC(cfar.end_dt));
1655 
1656   CURSOR c_am (cp_attendance_mode  igs_en_atd_mode_all.attendance_mode%TYPE) IS
1657         SELECT  am.GOVT_ATTENDANCE_MODE
1658         FROM    igs_en_atd_mode_all am
1659         WHERE   am.ATTENDANCE_MODE = cp_attendance_mode;
1660 
1661   -- To find the organization unit code from the Student Attempt Table (For Charge Method of
1662   -- FLATRATE)
1663   CURSOR c_resp_org_unit_cd(cp_course_cd IN igs_ps_ver_all.course_cd%TYPE,
1664                             cp_version_number IN igs_ps_ver_all.version_number%TYPE ) IS
1665   SELECT responsible_org_unit_cd
1666   FROM   igs_ps_ver_all v
1667   WHERE  v.course_cd            = cp_course_cd
1668   AND    v.version_number       = cp_version_number;
1669 
1670   -- To find the organization unit code from the Unit Section Level
1671   CURSOR c_org_unit_sec_cd(cp_uoo_id IN igs_ps_unit_ofr_opt_all.uoo_id%TYPE) IS
1672   SELECT owner_org_unit_cd, location_cd
1673   FROM   igs_ps_unit_ofr_opt_all
1674   WHERE  uoo_id = cp_uoo_id;
1675 
1676   CURSOR cur_unit_cd (cp_n_uoo_id  igs_fi_fee_as_items.uoo_id%TYPE) IS
1677   SELECT unit_cd, version_number
1678   FROM   igs_ps_unit_ofr_opt_all
1679   WHERE  uoo_id = cp_n_uoo_id;
1680 
1681 FUNCTION finpl_ins_match_chg_rate(
1682         p_rate_location_cd              igs_fi_fee_as_rate.location_cd%TYPE,
1683         p_rate_attendance_type          igs_fi_fee_as_rate.attendance_type%TYPE,
1684         p_rate_attendance_mode          igs_fi_fee_as_rate.attendance_mode%TYPE,
1685         p_rate_class_standing           IGS_PR_CLASS_STD.CLASS_STANDING%TYPE,
1686         p_rate_course_cd                igs_ps_ver_all.course_cd%TYPE,
1687         p_rate_version_number           igs_ps_ver_all.version_number%TYPE,
1688         p_rate_org_unit_cd              igs_ps_unit_ver_all.owner_org_unit_cd%TYPE,
1689         p_rate_residency_status_cd      igs_pe_res_dtls_all.residency_status_cd%TYPE,
1690         p_derived_location_cd           igs_fi_fee_as_rate.location_cd%TYPE,
1691         p_derived_attendance_type       igs_fi_fee_as_rate.attendance_type%TYPE,
1692         p_derived_govt_att_mode         igs_en_atd_mode_all.govt_attendance_mode%TYPE,
1693         p_derived_prog_att_mode         igs_en_atd_mode_all.attendance_mode%TYPE,
1694         p_derived_class_standing        IGS_PR_CLASS_STD.CLASS_STANDING%TYPE,
1695         p_derived_course_cd             igs_ps_ver_all.course_cd%TYPE,
1696         p_derived_version_number        igs_ps_ver_all.version_number%TYPE,
1697         p_derived_org_unit_cd           igs_ps_unit_ver_all.owner_org_unit_cd%TYPE,
1698         p_derived_residency_status_cd   igs_pe_res_dtls_all.residency_status_cd%TYPE,
1699         p_rate_unit_set_cd              igs_fi_fee_as_rate.unit_set_cd%TYPE,
1700         p_rate_us_version_num           igs_fi_fee_as_rate.us_version_number%TYPE,
1701         p_derived_unit_set_cd           igs_fi_fee_as_rate.unit_set_cd%TYPE,
1702         p_derived_us_version_num        igs_fi_fee_as_rate.us_version_number%TYPE,
1703         p_rate_unit_type_id             igs_fi_fee_as_items.unit_type_id%TYPE,
1704         p_derived_unit_type_id          igs_fi_fee_as_items.unit_type_id%TYPE,
1705         p_rate_unit_class               igs_fi_fee_as_items.unit_class%TYPE,
1706         p_derived_unit_class            igs_fi_fee_as_items.unit_class%TYPE,
1707         p_rate_unit_mode                igs_fi_fee_as_items.unit_mode%TYPE,
1708         p_derived_unit_mode             igs_fi_fee_as_items.unit_mode%TYPE,
1709         p_rate_unit_cd                  igs_fi_fee_as_rate.unit_cd%TYPE,
1710         p_derived_unit_cd               igs_fi_fee_as_rate.unit_cd%TYPE,
1711         p_rate_unit_version_num         igs_fi_fee_as_rate.unit_version_number%TYPE,
1712         p_derived_unit_version_num      igs_fi_fee_as_rate.unit_version_number%TYPE,
1713         p_rate_unit_level               igs_fi_fee_as_items.unit_level%TYPE,
1714         p_derived_unit_level            igs_fi_fee_as_items.unit_level%TYPE
1715         ) RETURN BOOLEAN AS
1716 /*************************************************************
1717  Created By :
1718  Date Created By :
1719  Purpose :
1720  Know limitations, enhancements or remarks
1721  Change History
1722  Who             When          What
1723  bannamal        03-JUN-2005   Bug#3442712 Unit Level Fee Assessment Build.
1724                                Added new parameters and added checks on these parameters.
1725  shtatiko        27-JUL-2004   Enh# 3795849, Added p_derived_prog_att_mode.
1726  pathipat        12-Sep-2003   Enh 3108052 - Unit Sets in Rate Table build
1727                                Added code and params related to unit_set_cd and us_version_number
1728  vchappid       27-Jan-03      Bug#2656411, modified the logic for identifying matching fee assessment rate
1729 *************************************************************/
1730 
1731 BEGIN   -- finpl_ins_match_chg_rate
1732         -- 2.3.1 Match Charge Rate
1733         -- Attempt to match assessment rate attributes with student IGS_PS_COURSE attempt.
1734         -- The order of precedence ensures the first
1735         -- match found is the desired charge rate.
1736   DECLARE
1737     v_rate_govt_att_mode   igs_en_atd_mode_all.govt_attendance_mode%TYPE;
1738     CURSOR c_am IS
1739       SELECT am.govt_attendance_mode
1740       FROM igs_en_atd_mode_all am
1741       WHERE am.attendance_mode = p_rate_attendance_mode;
1742 
1743   BEGIN
1744     log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1745                 p_v_string => 'Entered finpl_ins_match_chg_rate. Rate Parameters are: ' ||
1746                               p_rate_location_cd || ', ' || p_rate_attendance_type || ', ' || p_rate_attendance_mode
1747                               || ', ' || p_rate_class_standing || ', ' || p_rate_course_cd || ', ' || p_rate_version_number
1748                               || ', ' || p_rate_org_unit_cd || ', ' || p_rate_residency_status_cd
1749                               || ', ' || p_rate_unit_set_cd || ', ' || p_rate_us_version_num);
1750     log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1751                 p_v_string => 'Entered finpl_ins_match_chg_rate. Derived Parameters are: ' ||
1752                               p_derived_location_cd || ', ' || p_derived_attendance_type || ', ' || p_derived_govt_att_mode
1753                               || ', ' || p_derived_prog_att_mode || ', ' || p_derived_class_standing || ', ' || p_derived_course_cd
1754                               || ', ' || p_derived_version_number || ', ' || p_derived_org_unit_cd
1755                               || ', ' || p_derived_residency_status_cd || ', ' || p_derived_unit_set_cd || ', ' || p_derived_us_version_num);
1756 
1757     IF (p_rate_location_cd IS NOT NULL) THEN
1758       IF ((p_derived_location_cd <> p_rate_location_cd) OR p_derived_location_cd IS NULL) THEN
1759         log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1760                     p_v_string => 'Location Code Mismatch. Values:'|| p_rate_location_cd || ', ' || p_derived_location_cd || '. Returning false.');
1761         RETURN FALSE;
1762       END IF;
1763     END IF;
1764 
1765     IF (p_rate_attendance_type IS NOT NULL) THEN
1766       IF ((p_derived_attendance_type <> p_rate_attendance_type) OR p_derived_attendance_type IS NULL) THEN
1767         log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1768                     p_v_string => 'Att Type Mismatch. Values:'|| p_rate_attendance_type || ', ' || p_derived_attendance_type || '. Returning false.');
1769        RETURN FALSE;
1770       END IF;
1771     END IF;
1772 
1773     IF (p_rate_attendance_mode IS NOT NULL) THEN
1774       -- Get the govt attendance mode for the fee assessment rate attendance mode
1775       IF g_v_att_profile = gcst_nominated THEN
1776         -- In case of Nominated, compare Rate's AM with Derived Program AM.
1777         IF ((p_derived_prog_att_mode <> p_rate_attendance_mode) OR p_derived_prog_att_mode IS NULL) THEN
1778           log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1779                       p_v_string => 'Nominated: Att Mode Mismatch. Values:'|| p_rate_attendance_mode || ', Prog AM: ' || p_derived_prog_att_mode || ', Govt AM: ' || p_derived_govt_att_mode || '. Returning false.');
1780           RETURN FALSE;
1781         END IF;
1782       ELSE
1783         -- In case of Derived, compare Rate's Govt AM with Derived Govt AM (In case of Derived, only Govt AM is derived)
1784         OPEN c_am;
1785         FETCH c_am INTO v_rate_govt_att_mode;
1786         CLOSE c_am;
1787         IF ((p_derived_govt_att_mode <> v_rate_govt_att_mode) OR p_derived_govt_att_mode IS NULL) THEN
1788           log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1789                       p_v_string => 'Derived: Att Mode Mismatch. Values:'|| p_rate_attendance_mode || ', ' || v_rate_govt_att_mode || ', ' || p_derived_govt_att_mode || '. Returning false.');
1790           RETURN FALSE;
1791         END IF;
1792       END IF;
1793     END IF;
1794 
1795     IF (p_rate_class_standing IS NOT NULL )THEN
1796       IF ((p_derived_class_standing <> p_rate_class_standing) OR p_derived_class_standing IS NULL)  THEN
1797         log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1798                     p_v_string => 'Class Standing Mismatch. Values:'|| p_rate_class_standing || ', ' || p_derived_class_standing || '. Returning false.');
1799         RETURN FALSE;
1800       END IF;
1801     END IF;
1802 
1803     IF (p_rate_course_cd IS NOT NULL) THEN
1804       IF ((p_derived_course_cd <> p_rate_course_cd) OR p_derived_course_cd IS NULL) THEN
1805         log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1806                     p_v_string => 'Course Cd Mismatch. Values:'|| p_rate_course_cd || ', ' || p_derived_course_cd || '. Returning false.');
1807         RETURN FALSE;
1808       ELSIF (p_rate_version_number IS NOT NULL) THEN
1809         IF ((p_derived_version_number <> p_rate_version_number) OR p_derived_version_number IS NULL) THEN
1810            log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1811                     p_v_string => 'Course Ver Mismatch. Values:'|| p_rate_version_number || ', ' || p_derived_version_number || '. Returning false.');
1812            RETURN FALSE;
1813         END IF;
1814       END IF;
1815     END IF;
1816 
1817     IF (p_rate_org_unit_cd IS NOT NULL )THEN
1818       IF ((p_derived_org_unit_cd <> p_rate_org_unit_cd ) OR p_derived_org_unit_cd IS NULL)  THEN
1819         log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1820                     p_v_string => 'Org Unit Mismatch. Values:'|| p_rate_org_unit_cd || ', ' || p_derived_org_unit_cd || '. Returning false.');
1821         RETURN FALSE;
1822       END IF;
1823     END IF;
1824 
1825     IF (p_rate_residency_status_cd IS NOT NULL )THEN
1826       IF ((p_derived_residency_status_cd <> p_rate_residency_status_cd ) OR p_derived_residency_status_cd IS NULL) THEN
1827         log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1828                     p_v_string => 'Res Stat Mismatch. Values:'|| p_rate_residency_status_cd || ', ' || p_derived_residency_status_cd || '. Returning false.');
1829        RETURN FALSE;
1830       END IF;
1831     END IF;
1832 
1833     IF (p_rate_unit_set_cd IS NOT NULL) THEN
1834       IF ((p_derived_unit_set_cd <> p_rate_unit_set_cd) OR  p_derived_unit_set_cd IS NULL) THEN
1835         log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1836                     p_v_string => 'Unit Set Cd Mismatch. Values:'|| p_rate_unit_set_cd || ', ' || p_derived_unit_set_cd || '. Returning false.');
1837        RETURN FALSE;
1838       ELSIF (p_rate_us_version_num IS NOT NULL) THEN
1839         IF ((p_derived_us_version_num <> p_rate_us_version_num) OR p_derived_us_version_num IS NULL) THEN
1840            log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1841                     p_v_string => 'Unit Set Ver Mismatch. Values:'|| p_rate_us_version_num || ', ' || p_derived_us_version_num || '. Returning false.');
1842            RETURN FALSE;
1843         END IF;
1844       END IF;
1845     END IF;
1846 
1847     IF (p_rate_unit_type_id IS NOT NULL) THEN
1848       IF ((p_derived_unit_type_id <> p_rate_unit_type_id) OR p_derived_unit_type_id IS NULL) THEN
1849          log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1850                  p_v_string => 'Unit Program Type Level Mismatch. Values:'|| p_rate_unit_type_id || ', ' || p_derived_unit_type_id || '. Returning false.');
1851          RETURN FALSE;
1852       END IF;
1853     END IF;
1854 
1855     IF (p_rate_unit_class IS NOT NULL) THEN
1856       IF ((p_derived_unit_class <> p_rate_unit_class) OR p_derived_unit_class IS NULL) THEN
1857          log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1858                p_v_string => 'Unit Class Mismatch. Values:'|| p_rate_unit_class || ', ' || p_derived_unit_class || '. Returning false.');
1859         RETURN FALSE;
1860       END IF;
1861     END IF;
1862 
1863     IF (p_rate_unit_mode IS NOT NULL) THEN
1864       IF ((p_derived_unit_mode <> p_rate_unit_mode) OR p_derived_unit_mode IS NULL) THEN
1865          log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1866               p_v_string => 'Unit Mode Mismatch. Values:'|| p_rate_unit_mode || ', ' || p_derived_unit_mode || '. Returning false.');
1867         RETURN FALSE;
1868       END IF;
1869     END IF;
1870 
1871    IF (p_rate_unit_cd IS NOT NULL) THEN
1872       IF ((p_derived_unit_cd <> p_rate_unit_cd) OR p_derived_unit_cd IS NULL) THEN
1873          log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1874               p_v_string => 'Unit Code Mismatch. Values:'|| p_rate_unit_cd || ', ' || p_derived_unit_cd || '. Returning false.');
1875          RETURN FALSE;
1876       ELSIF (p_rate_unit_version_num IS NOT NULL) THEN
1877          IF ((p_derived_unit_version_num <> p_rate_unit_version_num) OR p_derived_unit_version_num IS NULL) THEN
1878             log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1879                  p_v_string => 'Unit Version Mismatch. Values:'|| p_rate_unit_version_num || ', ' || p_derived_unit_version_num || '. Returning false.');
1880             RETURN FALSE;
1881          END IF;
1882       END IF;
1883    END IF;
1884 
1885    IF (p_rate_unit_level IS NOT NULL) THEN
1886      IF ((p_derived_unit_level <> p_rate_unit_level) OR p_derived_unit_level IS NULL) THEN
1887         log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1888                p_v_string => 'Unit Level Mismatch. Values:'|| p_rate_unit_level || ', ' || p_derived_unit_level || '. Returning false.');
1889         RETURN FALSE;
1890      END IF;
1891    END IF;
1892 
1893     log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1894                 p_v_string => 'All rate attributes matched. Returning True.');
1895     RETURN TRUE;
1896   END;
1897   EXCEPTION
1898     WHEN OTHERS THEN
1899         log_to_fnd( p_v_module => 'finpl_ins_match_chg_rate',
1900                     p_v_string => 'From WHEN OTHERS. ' || SUBSTR(sqlerrm,1,500));
1901         Fnd_Message.Set_Name ('IGS', 'IGS_GE_UNHANDLED_EXP');
1902         Fnd_Message.Set_Token('NAME','IGS_FI_PRC_FEE_ASS.FINPL_INS_MATCH_CHG_RATE-'||SUBSTR(sqlerrm,1,500));
1903         IGS_GE_MSG_STACK.ADD;
1904         App_Exception.Raise_Exception;
1905 END finpl_ins_match_chg_rate;
1906 
1907 -------------------------------------------------------------------------------
1908 FUNCTION finpl_get_derived_values (
1909         p_person_id                     hz_parties.party_id%TYPE,
1910         p_course_cd                     IGS_PS_COURSE.course_cd%TYPE,
1911         p_effective_dt                  DATE,
1912         p_fee_cal_type                  igs_fi_f_cat_fee_lbl_all.fee_cal_type%TYPE,
1913         p_fee_ci_sequence_number        igs_fi_f_cat_fee_lbl_all.fee_ci_sequence_number%TYPE,
1914         p_fee_type                      igs_fi_f_cat_fee_lbl_all.fee_type%TYPE,
1915         p_s_fee_trigger_cat             igs_fi_fee_type_all.s_fee_trigger_cat%TYPE,
1916         p_trace_on                      VARCHAR2,
1917         p_derived_attendance_type       OUT NOCOPY      igs_fi_fee_as_rate.attendance_type%TYPE,
1918         p_derived_govt_att_mode         OUT NOCOPY      igs_en_atd_mode_all.govt_attendance_mode%TYPE,
1919         p_derived_prog_att_mode         OUT NOCOPY      igs_en_atd_mode_all.attendance_mode%TYPE, -- Added as part of 3795849
1920         p_derived_residency_status_cd   OUT NOCOPY      igs_pe_res_dtls_all.residency_status_cd%TYPE,
1921         p_derived_class_standing        OUT NOCOPY   IGS_PR_CLASS_STD.CLASS_STANDING%TYPE,
1922         p_c_career                      IN      igs_ps_ver_all.course_type%TYPE,
1923         p_derived_unit_set_cd           OUT NOCOPY igs_en_unit_set_all.unit_set_cd%TYPE,
1924         p_derived_us_version_num        OUT NOCOPY igs_en_unit_set_all.version_number%TYPE
1925         ) RETURN BOOLEAN  AS
1926 /*************************************************************
1927  Created By :
1928  Date Created By :
1929  Purpose :
1930  Know limitations, enhancements or remarks
1931  Change History
1932  Who             When          What
1933  pathipat        21-Sep-2005   Bug 4383148 - Fees not assessed if attendance type cannot be derived
1934                                Removed code that returns FALSE if AT could not be derived.
1935  pathipat        12-Sep-2003   Enh 3108052 - Unit Sets in Rate Table build
1936                                Added params p_derived_unit_set_cd and p_derived_us_version_num
1937  shtatiko        27-Jul-2004   Bug# 3795849, Added p_derived_attendance_mode. This holds value only in case of Nominated Profile.
1938  bannamal        1-Jul-2005    Bug#4077763 Fee Calculation Performance Enhancement.
1939                                Removed the parameters p_prior_fee_cal_type, p_prior_fee_ci_sequence_number
1940 *************************************************************/
1941 
1942 BEGIN
1943   DECLARE
1944     cst_on          CONSTANT        VARCHAR2(10) := 'ON';
1945     cst_off         CONSTANT        VARCHAR2(10) := 'OFF';
1946     cst_composite   CONSTANT        VARCHAR2(10) := 'COMPOSITE';
1947     v_total_period_load             NUMBER;
1948     v_derived_attendance_type       igs_en_atd_type_all.attendance_type%TYPE;
1949     v_derived_attendance_mode       VARCHAR2(10);  -- Used only in case of Derived Profile. Holds values On, Off, and Composite.
1950     v_derived_govt_att_mode         igs_en_atd_mode_all.govt_attendance_mode%TYPE;
1951     v_derived_prog_att_mode         igs_en_atd_mode_all.attendance_mode%TYPE;  -- Used in Nominated Profile. Holds value of AM associated at Prog Attempt.
1952     v_trigger_fired                 fnd_lookup_values.lookup_code%TYPE;
1953     v_count                         NUMBER(5);
1954     v_on_att_mode                   BOOLEAN := FALSE;
1955     v_off_att_mode                  BOOLEAN := FALSE;
1956     v_composite_att_mode            BOOLEAN := FALSE;
1957 
1958     v_derived_residency_status_cd           igs_pe_res_dtls_all.residency_status_cd%TYPE;
1959     v_derived_class_standing                IGS_PR_CLASS_STD.CLASS_STANDING%TYPE;
1960 
1961     -- Bug# 2122257, Modified the cursor select statement to include the audit table (IGS_FI_F_CAT_CAL_REL)
1962     -- for selecting Fee Category when it is changed.
1963     /* Modified by vchappid as a part of SFCR015 Build */
1964     -- cursor modified as per enh# 2162747, implemented as ref cursor
1965     TYPE derived_values_rec IS RECORD ( course_cd      igs_ps_ver_all.course_cd%TYPE,
1966                                         course_type    igs_ps_ver_all.course_type%TYPE);
1967     TYPE derived_values_ref IS REF CURSOR RETURN derived_values_rec;
1968     c_scafv    derived_values_ref;
1969     l_c_scafv  c_scafv%ROWTYPE;
1970 
1971     l_c_course_cd igs_ps_ver_all.course_cd%TYPE;
1972 
1973     -- record type variable defined for geeting the attendance type and govt attendance mode when the
1974     -- nominated values are used
1975     TYPE l_der_nom_rec IS RECORD ( attendance_type  igs_en_atd_type_all.attendance_type%TYPE,
1976                                    govt_att_mode    igs_en_atd_mode_all.govt_attendance_mode%TYPE,
1977                                    prog_att_mode    igs_en_atd_mode_all.attendance_mode%TYPE);
1978     TYPE l_der_nom_ref IS REF CURSOR RETURN l_der_nom_rec;
1979 
1980     c_att_md_ty    l_der_nom_ref;
1981     l_c_att_md_ty  c_att_md_ty%ROWTYPE;
1982 
1983     CURSOR cur_fee_type(cp_v_fee_type   igs_fi_fee_type_all.fee_type%TYPE) IS
1984       SELECT s_fee_type
1985       FROM igs_fi_fee_type_all
1986       WHERE fee_type =  cp_v_fee_type;
1987 
1988     l_v_s_fee_type       igs_fi_fee_type_all.s_fee_type%TYPE := NULL;
1989     l_n_cr_points        igs_en_su_attempt_all.override_achievable_cp%TYPE;
1990     l_n_fte              igs_en_su_attempt_all.override_achievable_cp%TYPE;
1991 
1992   BEGIN
1993     log_to_fnd( p_v_module => 'finpl_get_derived_values',
1994                 p_v_string => 'Entered finpl_get_derived_values. Parameters are: ' ||
1995                               p_person_id || ', ' || p_course_cd || ', ' || TO_CHAR(p_effective_dt, 'DD-MON-YYYY')
1996                               || ', ' || p_fee_cal_type || ', ' || p_fee_ci_sequence_number || ', ' || p_fee_type
1997                                || ', ' || p_s_fee_trigger_cat || ', ' || p_trace_on || ', ' || p_c_career );
1998     IF (p_trace_on = 'Y') THEN
1999       fnd_file.new_line(fnd_file.log);
2000     END IF;
2001     -- Obtain System Fee Type for the fee_type provided
2002     OPEN cur_fee_type(p_fee_type);
2003     FETCH cur_fee_type INTO l_v_s_fee_type;
2004     CLOSE cur_fee_type;
2005 
2006     log_to_fnd( p_v_module => 'finpl_get_derived_values',
2007                 p_v_string => 'Profile IGS_FI_NOM_DER_VALUES value: ' || g_v_att_profile );
2008     -- Get the derived attendance type
2009     ----------------------------------
2010 
2011     -- Profile Value is NOMINATED:
2012     --       If Institution Fee OR Primary Career Calculation Method
2013     --          Get AT and AM from Key Program
2014     --       Else
2015     --          Get AT and AM from Program in context
2016     -- Profile Value is DERIVED
2017     --       Call EN APIs to get AT.
2018 
2019     IF (g_v_att_profile = gcst_nominated) THEN --Enh# 2162747, SFCR06
2020 
2021         IF (p_s_fee_trigger_cat = 'INSTITUTN' OR g_c_fee_calc_mthd = g_v_primary_career) THEN  -- For Institutional Level
2022             OPEN c_att_md_ty FOR SELECT a.attendance_type,
2023                                         b.govt_attendance_mode,
2024                                         a.attendance_mode
2025                                  FROM   igs_en_spa_terms a,
2026                                         igs_en_atd_mode_all b
2027                                  WHERE  a.person_id = p_person_id
2028                                  AND    a.term_cal_type = g_v_load_cal_type
2029                                  AND    a.term_sequence_number = g_n_load_seq_num
2030                                  AND    b.attendance_mode = a.attendance_mode
2031                                  AND    a.key_program_flag = 'Y';
2032         ELSE -- For Other than Institutional Level
2033             OPEN c_att_md_ty FOR SELECT a.attendance_type,
2034                                         b.govt_attendance_mode,
2035                                         a.attendance_mode
2036                                  FROM   igs_en_spa_terms a,
2037                                         igs_en_atd_mode_all b
2038                                  WHERE  a.person_id = p_person_id
2039                                  AND    a.program_cd = p_course_cd
2040                                  AND    a.term_cal_type = g_v_load_cal_type
2041                                  AND    a.term_sequence_number = g_n_load_seq_num
2042                                  AND    b.attendance_mode = a.attendance_mode;
2043         END IF;
2044 
2045       FETCH c_att_md_ty INTO l_c_att_md_ty;
2046       -- Same Attendance Mode and Attendance Type variables are used to avoid duplicate declaring of the local variables
2047       v_derived_attendance_type := l_c_att_md_ty.attendance_type;
2048       v_derived_govt_att_mode   := l_c_att_md_ty.govt_att_mode;
2049       v_derived_prog_att_mode   := l_c_att_md_ty.prog_att_mode;
2050       CLOSE c_att_md_ty;
2051 
2052       log_to_fnd( p_v_module => 'finpl_get_derived_values',
2053                   p_v_string => 'Nominated Profile. Derived Att Type: ' || v_derived_attendance_type ||
2054                                 ', Govt. Att Mode: ' || v_derived_govt_att_mode ||
2055                                 ', Prog Att Mode: ' || v_derived_prog_att_mode);
2056       -- End of Modification Enh# 2162747
2057     ELSE
2058       log_to_fnd( p_v_module => 'finpl_get_derived_values',
2059                   p_v_string => 'Profile value is Derived. Deriving Attendance Type.');
2060       -- Get Attendance Type by calling EN API.
2061       IF p_s_fee_trigger_cat = gcst_institutn OR
2062          g_c_fee_calc_mthd = g_v_primary_career THEN
2063         igs_en_prc_load.enrp_get_inst_latt_fte ( p_person_id        => p_person_id,
2064                                                  p_load_cal_type    => g_v_load_cal_type,
2065                                                  p_load_seq_number  => g_n_load_seq_num,
2066                                                  p_attendance       => v_derived_attendance_type,
2067                                                  p_credit_points    => l_n_cr_points,
2068                                                  p_fte              => l_n_fte );
2069 
2070       ELSE /* p_s_fee_trigger_cat <> gcst_institutn AND g_c_fee_calc_mthd <> g_v_primary_career */
2071         v_derived_attendance_type := igs_en_prc_load.enrp_get_prg_att_type ( p_person_id        => p_person_id,
2072                                                                              p_course_cd        => p_course_cd,
2073                                                                              p_cal_type         => g_v_load_cal_type,
2074                                                                              p_sequence_number  => g_n_load_seq_num );
2075       END IF;
2076     END IF;
2077 
2078     IF (v_derived_attendance_type IS NULL) THEN
2079       IF (p_trace_on = 'Y') THEN
2080         fnd_message.set_name ( 'IGS', 'IGS_FI_UNABLE_DERIVE_ATTTYPE');
2081         fnd_file.put_line (fnd_file.log, fnd_message.get);
2082       END IF;
2083     END IF;
2084 
2085     log_to_fnd( p_v_module => 'finpl_get_derived_values',
2086                 p_v_string => 'Deriving Attendance Mode...');
2087     -- Get the derived attendance mode
2088     ----------------------------------
2089     -- Start of Modification Enh# 2162747
2090     IF (g_v_att_profile = gcst_nominated) THEN
2091       IF v_derived_govt_att_mode IS NULL AND v_derived_prog_att_mode IS NULL THEN
2092         IF (p_trace_on = 'Y') THEN
2093           -- Trace Entry
2094            fnd_message.set_name ( 'IGS', 'IGS_FI_UNABLE_DERIVE_ATTMODE');
2095            fnd_file.put_line (fnd_file.log, fnd_message.get);
2096         END IF;
2097       END IF;
2098       -- End of Modification Enh# 2162747
2099     ELSE
2100 
2101       -- Processing for PRIMARY_CAREER is same for Institution and Non-Institution Fees.
2102       IF (p_s_fee_trigger_cat = gcst_institutn AND g_c_fee_calc_mthd <> g_v_primary_career) THEN
2103 
2104           -- For all the liable program attempts identified in finpl_clc_chg_mthd_elements, find attendance mode.
2105           IF g_inst_liable_progs_tbl.COUNT > 0 THEN
2106             log_to_fnd( p_v_module => 'finpl_get_derived_values',
2107                         p_v_string => 'Looping through Liable Programs in Institution case. (table g_inst_liable_progs_tbl) ');
2108             FOR l_n_cntr IN g_inst_liable_progs_tbl.FIRST..g_inst_liable_progs_tbl.LAST LOOP
2109               IF g_inst_liable_progs_tbl.EXISTS(l_n_cntr) THEN
2110 
2111                 l_c_course_cd := g_inst_liable_progs_tbl(l_n_cntr).program_cd;
2112                 -- get the attendance mode for the current load period for the course in context.
2113                 v_derived_attendance_mode := igs_en_gen_006.enrp_get_sca_am(p_person_id,
2114                                                                             l_c_course_cd,
2115                                                                             g_v_load_cal_type,
2116                                                                             g_n_load_seq_num);
2117                 log_to_fnd( p_v_module => 'finpl_get_derived_values',
2118                             p_v_string => 'Attendance Mode derived for course ' || l_c_course_cd || ' is ' || v_derived_attendance_mode);
2119                 IF (v_derived_attendance_mode = cst_on) THEN
2120                   v_on_att_mode := TRUE;
2121                 ELSIF (v_derived_attendance_mode = cst_off) THEN
2122                   v_off_att_mode := TRUE;
2123                 ELSIF (v_derived_attendance_mode = cst_composite) THEN
2124                   v_composite_att_mode := TRUE;
2125                 END IF;
2126               END IF;
2127             END LOOP;
2128           END IF;
2129 
2130         -- Determine the govt attendance mode from the combination
2131         -- of derived values across the student program attempts
2132         v_derived_prog_att_mode := NULL; -- This variable holds value only in case of Nominated Profile
2133         IF (v_on_att_mode = TRUE AND
2134           v_off_att_mode = FALSE AND
2135           v_composite_att_mode = FALSE) THEN
2136           v_derived_govt_att_mode := 1;
2137         ELSIF (v_on_att_mode = FALSE AND
2138           v_off_att_mode = TRUE AND
2139           v_composite_att_mode = FALSE) THEN
2140           v_derived_govt_att_mode := 2;
2141         ELSIF ((v_on_att_mode = TRUE AND
2142           v_off_att_mode = TRUE) OR
2143           v_composite_att_mode = TRUE) THEN
2144           v_derived_govt_att_mode := 3;
2145         ELSE
2146           IF (p_trace_on = 'Y') THEN
2147             -- Trace Entry
2148             fnd_message.set_name ( 'IGS', 'IGS_FI_UNABLE_DERIVE_ATTMODE');
2149             fnd_file.put_line (fnd_file.log, fnd_message.get);
2150           END IF;
2151         END IF;
2152         log_to_fnd( p_v_module => 'finpl_get_derived_values',
2153                     p_v_string => 'Institution Case: Attendance Mode: ' || v_derived_govt_att_mode);
2154 
2155 
2156       ELSE /* p_s_fee_trigger_cat <> gcst_institutn OR g_c_fee_calc_mthd = 'PRIMARY_CAREER' */
2157 
2158         IF ( g_c_fee_calc_mthd IN (g_v_program, g_v_career)) THEN
2159 
2160           -- PROGRAM: Derive AM from the course in context
2161           -- CAREER : Derive AM for the Primary Program of career i.e., course in context
2162 
2163             v_derived_attendance_mode := igs_en_gen_006.enrp_get_sca_am(p_person_id,
2164                                                                         p_course_cd,
2165                                                                         g_v_load_cal_type,
2166                                                                         g_n_load_seq_num);
2167 
2168           v_derived_prog_att_mode := NULL; -- This variable holds value only in case of Nominated Profile
2169           IF (v_derived_attendance_mode = cst_on) THEN
2170             v_derived_govt_att_mode := 1;
2171           ELSIF (v_derived_attendance_mode = cst_off) THEN
2172             v_derived_govt_att_mode := 2;
2173           ELSIF (v_derived_attendance_mode = cst_composite) THEN
2174             v_derived_govt_att_mode := 3;
2175           ELSE
2176             IF (p_trace_on = 'Y') THEN
2177               -- Trace Entry
2178               fnd_message.set_name ( 'IGS', 'IGS_FI_UNABLE_DERIVE_ATTMODE');
2179               fnd_file.put_line (fnd_file.log, fnd_message.get);
2180             END IF;
2181           END IF;
2182           log_to_fnd( p_v_module => 'finpl_get_derived_values',
2183                       p_v_string => 'Non-Institution Case, PROGRAM/CAREER: Attendance Mode: ' || v_derived_govt_att_mode);
2184 
2185         ELSIF ( g_c_fee_calc_mthd =g_v_primary_career) THEN
2186           -- Derive AM from Key Program of the person for the given term.
2187 
2188           OPEN c_scafv FOR SELECT program_cd course_cd,
2189                                     NULL
2190                              FROM   igs_en_spa_terms
2191                              WHERE  person_id = p_person_id
2192                              AND    term_cal_type = g_v_load_cal_type
2193                              AND    term_sequence_number = g_n_load_seq_num;
2194 
2195           LOOP
2196           FETCH c_scafv INTO l_c_scafv;
2197           EXIT WHEN c_scafv%NOTFOUND;
2198 
2199             v_derived_attendance_mode := igs_en_gen_006.enrp_get_sca_am( p_person_id,
2200                                                                            l_c_scafv.course_cd,
2201                                                                            g_v_load_cal_type,
2202                                                                            g_n_load_seq_num);
2203 
2204             IF (v_derived_attendance_mode = cst_on) THEN
2205                 v_on_att_mode := TRUE;
2206             ELSIF (v_derived_attendance_mode = cst_off) THEN
2207               v_off_att_mode := TRUE;
2208             ELSIF (v_derived_attendance_mode = cst_composite) THEN
2209               v_composite_att_mode := TRUE;
2210             END IF;
2211 
2212           END LOOP;
2213           CLOSE c_scafv;
2214 
2215           -- Determine the govt attendance mode from the combination
2216           -- of derived values across the load periods
2217           v_derived_prog_att_mode := NULL; -- This variable holds value only in case of Nominated Profile
2218           IF (v_on_att_mode = TRUE AND
2219             v_off_att_mode = FALSE AND
2220             v_composite_att_mode = FALSE) THEN
2221             v_derived_govt_att_mode := 1;
2222           ELSIF (v_on_att_mode = FALSE AND
2223             v_off_att_mode = TRUE AND
2224             v_composite_att_mode = FALSE) THEN
2225             v_derived_govt_att_mode := 2;
2226           ELSIF ((v_on_att_mode = TRUE AND
2227             v_off_att_mode = TRUE) OR
2228             v_composite_att_mode = TRUE) THEN
2229             v_derived_govt_att_mode := 3;
2230           ELSE
2231             IF (p_trace_on = 'Y') THEN
2232               -- Trace Entry
2233               fnd_message.set_name ( 'IGS', 'IGS_FI_UNABLE_DERIVE_ATTMODE');
2234               fnd_file.put_line (fnd_file.log, fnd_message.get);
2235             END IF;
2236           END IF;
2237           log_to_fnd( p_v_module => 'finpl_get_derived_values',
2238                       p_v_string => 'Non-Institution Case, PRIMARY_CAREER: Attendance Mode: ' || v_derived_govt_att_mode);
2239         END IF; /* g_c_fee_calc_mthd */
2240       END IF;
2241     END IF; /* Nominated or Derived */
2242 
2243     -- Message about derivation of Attendance type and mode needs to be shown only if both
2244     -- have been derived.
2245     IF (v_derived_attendance_type IS NOT NULL) AND (v_derived_govt_att_mode IS NOT NULL) THEN
2246       IF (p_trace_on = 'Y') THEN
2247         fnd_message.set_name ( 'IGS', 'IGS_FI_ATTTYPE_GOVT_ATTMODE');
2248         fnd_message.set_token('ATT_TYPE', v_derived_attendance_type);
2249         fnd_file.put_line(fnd_file.log, fnd_message.get );
2250         fnd_message.set_name('IGS', 'IGS_FI_DER_ATT_TYPE_GOVT_MODE');
2251         fnd_message.set_token('ATT_MODE', v_derived_govt_att_mode);
2252         fnd_file.put_line (fnd_file.log, fnd_message.get);
2253       END IF;
2254     END IF;
2255 
2256     -- Get the derived Residency Status
2257     ----------------------------------
2258     -- If the Profile is not set, then no Residency Status matching is required
2259 
2260     log_to_fnd( p_v_module => 'finpl_get_derived_values',
2261                 p_v_string => 'Deriving Residency Status..');
2262     v_derived_residency_status_cd := get_stdnt_res_status_cd( p_n_person_id => p_person_id );
2263 
2264     IF v_derived_residency_status_cd IS NOT NULL THEN
2265       IF (p_trace_on = 'Y') THEN
2266         fnd_message.set_name('IGS', 'IGS_FI_RES_STAT');
2267         fnd_message.set_token('RES_STAT',  v_derived_residency_status_cd);
2268         fnd_file.put_line (fnd_file.log, fnd_message.get);
2269       END IF;
2270       log_to_fnd( p_v_module => 'finpl_get_derived_values',
2271                   p_v_string => 'Residency Status Code: ' || v_derived_residency_status_cd);
2272     ELSE
2273       IF (p_trace_on = 'Y') THEN
2274         fnd_message.set_name('IGS', 'IGS_FI_NO_RES_STAT');
2275         fnd_file.put_line (fnd_file.log, fnd_message.get);
2276       END IF;
2277       log_to_fnd( p_v_module => 'finpl_get_derived_values',
2278                   p_v_string => 'Unable to derive Residency Status Code.');
2279     END IF;
2280 
2281     -- Get the derived Class Standing
2282     ----------------------------------
2283     log_to_fnd( p_v_module => 'finpl_get_derived_values',
2284                 p_v_string => 'Deriving Class Standing..');
2285     v_derived_class_standing := get_stdnt_class_standing ( p_n_person_id => p_person_id,
2286                                                            p_v_course_cd => p_course_cd,
2287                                                            p_v_s_fee_trigger_cat => p_s_fee_trigger_cat );
2288     IF (v_derived_class_standing IS NOT NULL) THEN
2289       IF (p_trace_on = 'Y') THEN
2290         fnd_message.set_name('IGS', 'IGS_FI_CLASS_STD');
2291         fnd_message.set_token('CLASS_STD', v_derived_class_standing);
2292         fnd_file.put_line (fnd_file.log, fnd_message.get);
2293       END IF;
2294       log_to_fnd( p_v_module => 'finpl_get_derived_values',
2295                   p_v_string => 'Class Standing: ' || v_derived_class_standing);
2296     ELSE
2297       IF (p_trace_on = 'Y') THEN
2298         fnd_message.set_name ( 'IGS', 'IGS_FI_NO_CLASS_STD' );
2299         fnd_file.put_line (fnd_file.log, fnd_message.get);
2300       END IF;
2301       log_to_fnd( p_v_module => 'finpl_get_derived_values',
2302                   p_v_string => 'Unable to derive Class Standing.');
2303    END IF;
2304 
2305     -- Get the derived Unit Set Details
2306     ----------------------------------
2307 
2308     log_to_fnd( p_v_module => 'finpl_get_derived_values',
2309                 p_v_string => 'Deriving Unit Set Details..');
2310     get_stdnt_unit_set_dtls ( p_n_person_id => p_person_id,
2311                               p_v_course_cd => p_course_cd,
2312                               p_v_s_fee_trigger_cat => p_s_fee_trigger_cat,
2313                               p_v_unit_set_cd => p_derived_unit_set_cd,
2314                               p_n_unit_set_ver_num => p_derived_us_version_num );
2315 
2316     -- Log appropriate messages if the Unit Set could or could not be derived
2317     -- Unit set details are derived only in case of PROGRAM and non-institution case.
2318     IF (g_c_fee_calc_mthd = g_v_program AND p_s_fee_trigger_cat <> 'INSTITUTN') THEN
2319       IF p_derived_unit_set_cd IS NOT NULL AND
2320          p_derived_us_version_num IS NOT NULL THEN
2321         IF (p_trace_on = 'Y') THEN
2322           fnd_message.set_name('IGS','IGS_FI_DER_UNIT_SET');
2323           fnd_message.set_token('UNIT_SET',p_derived_unit_set_cd);
2324           fnd_message.set_token('VER',p_derived_us_version_num);
2325           fnd_file.put_line (fnd_file.log, fnd_message.get);
2326           fnd_file.new_line(fnd_file.log);
2327         END IF;
2328         log_to_fnd( p_v_module => 'finpl_get_derived_values',
2329                     p_v_string => 'Unit Set Details: ' || p_derived_unit_set_cd || ', ' || p_derived_us_version_num);
2330       ELSE
2331         p_derived_unit_set_cd := NULL;
2332         p_derived_us_version_num := NULL;
2333         v_message_name := 'IGS_FI_NO_UNIT_SET';
2334         IF (p_trace_on = 'Y') THEN
2335            fnd_message.set_name ( 'IGS', v_message_name);
2336            fnd_file.put_line (fnd_file.log, fnd_message.get);
2337         END IF;
2338         log_to_fnd( p_v_module => 'finpl_get_derived_values',
2339                     p_v_string => 'Unable to derive Unit Set Details.');
2340       END IF;
2341     END IF;
2342 
2343     p_derived_attendance_type := v_derived_attendance_type;
2344     p_derived_govt_att_mode := v_derived_govt_att_mode;
2345     p_derived_prog_att_mode := v_derived_prog_att_mode;
2346     p_derived_residency_status_cd := v_derived_residency_status_cd;
2347     p_derived_class_standing := v_derived_class_standing;
2348 
2349     log_to_fnd( p_v_module => 'finpl_get_derived_values',
2350                 p_v_string => 'End of finpl_get_derived_values. Out: Att Type: '|| p_derived_attendance_type
2351                               || ', Govt Att Mode: ' || p_derived_govt_att_mode
2352                               || ', Prog Att Mode: ' || p_derived_prog_att_mode
2353                               || ', Residency Status Cd:' || p_derived_residency_status_cd
2354                               || ', Class Standing: ' || p_derived_class_standing
2355                               || ', Unit Set Code: ' || p_derived_unit_set_cd
2356                               || ', Unit Set Version: ' || p_derived_us_version_num );
2357     RETURN TRUE;
2358 
2359   END;
2360 EXCEPTION
2361 WHEN OTHERS THEN
2362   log_to_fnd( p_v_module => 'finpl_get_derived_values',
2363               p_v_string => 'From Exception Handler of When Others.');
2364   fnd_message.set_name ('IGS', 'IGS_GE_UNHANDLED_EXP');
2365   fnd_message.set_token('NAME','IGS_FI_PRC_FEE_ASS.FINPL_GET_DERIVED_VALUES-'||SUBSTR(sqlerrm,1,500));
2366   igs_ge_msg_stack.add;
2367   app_exception.raise_exception;
2368 END finpl_get_derived_values;
2369 
2370 
2371 -------------------------------------------------------------------------------
2372 PROCEDURE finpl_find_far(
2373         p_person_id                             hz_parties.party_id%TYPE,
2374         p_course_cd                             igs_en_stdnt_ps_att_all.course_cd%TYPE,
2375         p_fee_cat                               IGS_FI_F_CAT_CA_INST.FEE_CAT%TYPE,
2376         p_fee_cal_type                          igs_fi_f_cat_fee_lbl_all.fee_cal_type%TYPE,
2377         p_fee_ci_sequence_number                igs_fi_f_cat_fee_lbl_all.fee_ci_sequence_number%TYPE,
2378         p_fee_type                              igs_fi_f_cat_fee_lbl_all.fee_type%TYPE,
2379         p_location_cd                           igs_en_stdnt_ps_att_all.location_cd%TYPE,
2380         p_effective_dt                          DATE,
2381         p_s_fee_trigger_cat                     igs_fi_fee_type_all.s_fee_trigger_cat%TYPE,
2382         p_derived_location_cd                   igs_fi_fee_as_rate.location_cd%TYPE,
2383         p_derived_attendance_type               igs_fi_fee_as_rate.attendance_type%TYPE,
2384         p_derived_govt_att_mode                 igs_en_atd_mode_all.govt_attendance_mode%TYPE,
2385         p_derived_prog_att_mode                 igs_en_atd_mode_all.attendance_mode%TYPE,
2386         p_trace_on                              VARCHAR2,
2387         p_derived_residency_status_cd           igs_pe_res_dtls_all.residency_status_cd%TYPE,
2388         p_derived_org_unit_cd                   igs_ps_unit_ver_all.owner_org_unit_cd%TYPE,
2389         p_derived_course_cd                     igs_ps_ver_all.course_cd%TYPE,
2390         p_derived_version_number                igs_ps_ver_all.version_number%TYPE,
2391         p_derived_class_standing                IGS_PR_CLASS_STD.CLASS_STANDING%TYPE,
2392         p_charge_rate               OUT NOCOPY  IGS_FI_FEE_AS_RATE.chg_rate%TYPE,
2393         p_derived_unit_set_cd       IN          igs_fi_fee_as_rate.unit_set_cd%TYPE,
2394         p_derived_us_version_num    IN          igs_fi_fee_as_rate.us_version_number%TYPE,
2395         p_derived_unit_type_id      IN          igs_fi_fee_as_items.unit_type_id%TYPE,
2396         p_derived_unit_class        IN          igs_fi_fee_as_items.unit_class%TYPE,
2397         p_derived_unit_mode         IN          igs_fi_fee_as_items.unit_mode%TYPE,
2398         p_derived_unit_cd           IN          igs_fi_fee_as_rate.unit_cd%TYPE,
2399         p_derived_unit_version_num  IN          igs_fi_fee_as_rate.unit_version_number%TYPE,
2400         p_derived_unit_level        IN          igs_fi_fee_as_items.unit_level%TYPE
2401         ) AS
2402   /***********************************************************************************************
2403   Change History:
2404   Who         When            What
2405   abshriva    23-May-2006     Bug 5204728: Added ORDER BY order_of_precedence in cursor c_ftfarv1 and c_ftfarv2
2406   pathipat    10-Oct-2005     Bug 4375258 - Change party_number FK to TCA parties impact
2407                               Replaced usage of igs_fi_gen_008.get_party_number with finpl_get_org_unit_cd
2408                               for Org derivation
2409   bannamal    03-JUN-2005     Bug#3442712 Unit Level Fee Assessment Build.
2410                               Added new parameters for this build.
2411   shtatiko    27-JUL-2004     Enh# 3795849, Added p_derived_prog_att_mode.
2412   pathipat    12-Sep-2003     Enh 3108052 - Unit Sets in Rate Table build
2413                               Added params p_derived_unit_set_cd and p_derived_us_version_num
2414                               Modified cursor c_ftfarv to include unit_set_cd and us_Version_number
2415   rnirwani    02-May-02       Bug# 2344901
2416                               in case no matching record is found then no value is assigned to the out NOCOPY parameter
2417                               p_charge_rate. This has been modified to assign a zero to this parameter.
2418   smadathi    02-May-2002     Bug 2261649. The reference to function finp_get_additional_charge removed.
2419   **********************************************************************************************/
2420 BEGIN
2421   DECLARE
2422     v_chg_rate                      igs_fi_fee_as_rate.chg_rate%TYPE;
2423     v_s_relation_type               igs_fi_fee_as_rate.s_relation_type%TYPE;
2424     v_location_cd                   igs_fi_fee_as_rate.location_cd%TYPE;
2425     v_attendance_type               igs_fi_fee_as_rate.attendance_type%TYPE;
2426     v_attendance_mode               igs_fi_fee_as_rate.attendance_mode%TYPE;
2427     v_rate_number                   igs_fi_fee_as_rate.rate_number%TYPE;
2428     v_fee_ass_rate_match            BOOLEAN;
2429     l_b_fee_ass_rate_found          BOOLEAN;
2430     v_residency_status_cd           igs_pe_res_dtls_all.residency_status_cd%TYPE;
2431     v_org_unit_cd                   igs_ps_unit_ver_all.owner_org_unit_cd%TYPE;
2432     v_course_cd                     igs_fi_fee_as_rate.course_cd%TYPE;
2433     v_version_number                igs_fi_fee_as_rate.version_number%TYPE;
2434     v_class_standing                 igs_fi_fee_as_rate.class_standing%TYPE;
2435     v_unit_set_cd                   igs_fi_fee_as_rate.unit_set_cd%TYPE := NULL;
2436     v_us_version_number             igs_fi_fee_as_rate.us_version_number%TYPE := NULL;
2437 
2438     CURSOR c_ftfarv1(cp_v_s_relation_type igs_fi_fee_as_rate.s_relation_type%TYPE) IS
2439     SELECT  far.chg_rate,
2440             far.s_relation_type,
2441             far.location_cd,
2442             far.attendance_type,
2443             far.attendance_mode,
2444             far.rate_number,
2445             far.residency_status_cd,
2446             far.org_party_id,
2447             far.course_cd,
2448             far.version_number,
2449             far.class_standing,
2450             far.unit_set_cd,
2451             far.us_version_number,
2452             far.unit_type_id,
2453             far.unit_class,
2454             far.unit_mode,
2455             far.unit_cd,
2456             far.unit_version_number,
2457             far.unit_level
2458     FROM igs_fi_fee_as_rate far,
2459                  igs_fi_f_cat_fee_lbl_all fcfl
2460     WHERE far.s_relation_type = cp_v_s_relation_type
2461     AND   far.logical_delete_dt is NULL
2462     AND   fcfl.fee_cat = far.fee_cat
2463     AND   fcfl.fee_cal_type = far.fee_cal_type
2464     AND   fcfl.fee_ci_sequence_number = far.fee_ci_sequence_number
2465     AND   fcfl.fee_type = far.fee_type
2466     AND   far.fee_type = p_fee_type
2467     AND   far.fee_cal_type = p_fee_cal_type
2468     AND   far.fee_ci_sequence_number = p_fee_ci_sequence_number
2469     AND   far.fee_cat = p_fee_cat
2470     ORDER BY far.order_of_precedence ASC;
2471 
2472     CURSOR c_ftfarv2(cp_v_s_relation_type igs_fi_fee_as_rate.s_relation_type%TYPE) IS
2473     SELECT  far.chg_rate,
2474             far.s_relation_type,
2475             far.location_cd,
2476             far.attendance_type,
2477             far.attendance_mode,
2478             far.rate_number,
2479             far.residency_status_cd,
2480             far.org_party_id,
2481             far.course_cd,
2482             far.version_number,
2483             far.class_standing,
2484             far.unit_set_cd,
2485             far.us_version_number,
2486             far.unit_type_id,
2487             far.unit_class,
2488             far.unit_mode,
2489             far.unit_cd,
2490             far.unit_version_number,
2491             far.unit_level
2492     FROM   igs_fi_fee_as_rate far,
2493                    igs_fi_f_cat_fee_lbl_all fcfl
2494     WHERE  far.s_relation_type = cp_v_s_relation_type
2495     AND   far.logical_delete_dt is NULL
2496     AND   fcfl.fee_type = far.fee_type
2497     AND   fcfl.fee_cal_type = far.fee_cal_type
2498     AND   fcfl.fee_ci_sequence_number = far.fee_ci_sequence_number
2499     AND   fcfl.fee_cat = p_fee_cat
2500     AND   far.fee_type = p_fee_type
2501     AND   far.fee_cal_type = p_fee_cal_type
2502     AND   far.fee_ci_sequence_number = p_fee_ci_sequence_number
2503     AND   (far.fee_cat = p_fee_cat or far.fee_cat is NULL)
2504     ORDER BY far.order_of_precedence ASC;
2505 
2506     l_c_ftfarv1  c_ftfarv1%ROWTYPE;
2507     l_b_cursor   BOOLEAN;
2508     l_v_party_number hz_parties.party_number%TYPE := NULL;
2509     l_v_level_code   igs_ps_unit_type_lvl.level_code%TYPE;
2510 
2511   BEGIN
2512     log_to_fnd( p_v_module => 'finpl_find_far',
2513                 p_v_string => 'Entered finpl_find_far. Parameters are: ' ||
2514                                p_person_id || ', ' || p_course_cd || ', ' || p_fee_cat
2515                                || ', ' || p_fee_cal_type || ', ' || p_fee_ci_sequence_number
2516                                || ', ' || p_fee_type || ', ' || p_location_cd || ', ' || TO_CHAR(p_effective_dt, 'DD-MON-YYYY')
2517                                || ', ' || p_s_fee_trigger_cat
2518                                || ', ' || p_derived_location_cd || ', ' || p_derived_attendance_type
2519                                || ', ' || p_derived_govt_att_mode || ', ' || p_derived_prog_att_mode || ', ' || p_trace_on
2520                                || ', ' || p_derived_residency_status_cd
2521                                || ', ' || p_derived_org_unit_cd || ', ' || p_derived_course_cd || ', ' || p_derived_version_number
2522                                || ', ' || p_derived_class_standing || ', ' || p_derived_unit_set_cd
2523                                || ', ' || p_derived_us_version_num|| ', ' || p_derived_unit_type_id || ', ' || p_derived_unit_class
2524                                || ', ' || p_derived_unit_mode || ', ' || p_derived_unit_cd || ', ' || p_derived_unit_version_num
2525                                || ', ' || p_derived_unit_level);
2526 
2527     p_charge_rate := 0;
2528     v_fee_ass_rate_match := FALSE;
2529     l_b_fee_ass_rate_found := FALSE;
2530     l_b_cursor := FALSE;
2531 
2532     FOR v_ftfarv_rec IN c_ftfarv1('FCFL') LOOP
2533       l_b_cursor := TRUE;
2534       l_v_party_number := NULL;
2535       IF v_ftfarv_rec.org_party_id IS NOT NULL THEN
2536          l_v_party_number := finpl_get_org_unit_cd(v_ftfarv_rec.org_party_id);
2537       END IF;
2538 
2539       IF v_ftfarv_rec.unit_type_id IS NOT NULL THEN
2540         l_v_level_code := finpl_get_uptl(v_ftfarv_rec.unit_type_id);
2541       ELSE
2542         l_v_level_code := NULL;
2543       END IF;
2544 
2545       l_b_fee_ass_rate_found := TRUE;
2546       IF (v_fee_ass_rate_match = TRUE) THEN
2547         EXIT;
2548       END IF;
2549 
2550       -- Attempt to match the assessment rate
2551         -- Perform 2.3.1 Match Charge Rate
2552         IF (finpl_ins_match_chg_rate(
2553                   v_ftfarv_rec.location_cd,
2554                   v_ftfarv_rec.ATTENDANCE_TYPE,
2555                   v_ftfarv_rec.ATTENDANCE_MODE,
2556                   v_ftfarv_rec.class_standing,
2557                   v_ftfarv_rec.course_cd,
2558                   v_ftfarv_rec.version_number,
2559                   l_v_party_number,
2560                   v_ftfarv_rec.residency_status_cd,
2561                   p_derived_location_cd,
2562                   p_derived_attendance_type,
2563                   p_derived_govt_att_mode,
2564                   p_derived_prog_att_mode,
2565                   p_derived_class_standing,
2566                   p_course_cd,
2567                   p_course_version_number,
2568                   p_derived_org_unit_cd,
2569                   p_derived_residency_status_cd,
2570                   v_ftfarv_rec.unit_set_cd,
2571                   v_ftfarv_rec.us_version_number,
2572                   p_derived_unit_set_cd,
2573                   p_derived_us_version_num,
2574                   v_ftfarv_rec.unit_type_id,
2575                   p_derived_unit_type_id,
2576                   v_ftfarv_rec.unit_class,
2577                   p_derived_unit_class,
2578                   v_ftfarv_rec.unit_mode,
2579                   p_derived_unit_mode,
2580                   v_ftfarv_rec.unit_cd,
2581                   p_derived_unit_cd,
2582                   v_ftfarv_rec.unit_version_number,
2583                   p_derived_unit_version_num,
2584                   v_ftfarv_rec.unit_level,
2585                   p_derived_unit_level
2586                   ) = TRUE) THEN
2587           p_charge_rate := v_ftfarv_rec.chg_rate;
2588           IF (p_trace_on = 'Y') THEN
2589                       fnd_file.new_line(fnd_file.log);
2590                       IF (p_derived_unit_cd IS NOT NULL) THEN
2591                         fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_ACCT_ENTITIES', 'UNIT') || ': ' || p_derived_unit_cd);
2592                       END IF;
2593                       fnd_message.set_name('IGS', 'IGS_FI_LEV_CHG_RATE_NO');
2594                       fnd_message.set_token('LEVEL', v_ftfarv_rec.s_relation_type);
2595                       fnd_message.set_token('CH_RT', TO_CHAR(v_ftfarv_rec.chg_rate));
2596                       fnd_message.set_token('RT_NUM', TO_CHAR(v_ftfarv_rec.rate_number));
2597                       fnd_message.set_token('ATT_TYP', NVL(v_ftfarv_rec.ATTENDANCE_TYPE, l_v_lkp_all));
2598                       fnd_message.set_token('ATT_MOD', NVL(v_ftfarv_rec.ATTENDANCE_MODE, l_v_lkp_all));
2599                       fnd_message.set_token('LOC', NVL(v_ftfarv_rec.location_cd, l_v_lkp_all));
2600                       fnd_message.set_token('RES_STAT', NVL(v_ftfarv_rec.residency_status_cd, l_v_lkp_all));
2601                       fnd_message.set_token('ORG_UNIT_CD', NVL(l_v_party_number, l_v_lkp_all));
2602                       fnd_message.set_token('COURSE_CD', NVL(v_ftfarv_rec.course_cd, l_v_lkp_all));
2603                       fnd_message.set_token('VERSION', NVL(TO_CHAR(v_ftfarv_rec.version_number), l_v_lkp_all));
2604                       fnd_message.set_token('CLAS_STNDNG', NVL(v_ftfarv_rec.class_standing, l_v_lkp_all));
2605                       fnd_message.set_token('UNIT_SET_CD', NVL(v_ftfarv_rec.unit_set_cd, l_v_lkp_all));
2606                       fnd_message.set_token('US_VER', NVL(TO_CHAR(v_ftfarv_rec.us_version_number), l_v_lkp_all));
2607                       fnd_message.set_token('UNIT_TYP_CD', NVL(l_v_level_code, l_v_lkp_all));
2608                       fnd_message.set_token('UNIT_CLASS', NVL(v_ftfarv_rec.unit_class, l_v_lkp_all));
2609                       fnd_message.set_token('UNIT_MODE', NVL(v_ftfarv_rec.unit_mode, l_v_lkp_all));
2610                       fnd_message.set_token('UNIT_CODE', NVL(v_ftfarv_rec.unit_cd, l_v_lkp_all));
2611                       fnd_message.set_token('UNIT_VER_NUM', NVL(TO_CHAR(v_ftfarv_rec.unit_version_number), l_v_lkp_all));
2612                       fnd_message.set_token('UNIT_LEVEL', NVL(v_ftfarv_rec.unit_level, l_v_lkp_all));
2613                       fnd_file.put_line (fnd_file.log, fnd_message.get);
2614                       fnd_message.set_name('IGS', 'IGS_FI_FEEASS_RATE_MATCHES');
2615                       fnd_file.put_line (fnd_file.log, fnd_message.get);
2616                       fnd_file.new_line(fnd_file.log);
2617           END IF;
2618           -- stop processing Rate Records
2619           log_to_fnd( p_v_module => 'finpl_find_far',
2620                       p_v_string => 'Rate Matched: ' || p_charge_rate );
2621           v_fee_ass_rate_match := TRUE;
2622 
2623         ELSE -- Not Matched
2624           -- Process next rate record
2625           NULL;
2626         END IF; -- finpl_ins_match_chg_rate
2627     END LOOP;
2628 
2629     IF l_b_cursor = FALSE THEN
2630             FOR v_ftfarv_rec IN c_ftfarv2('FTCI') LOOP
2631               l_v_party_number := NULL;
2632               IF v_ftfarv_rec.org_party_id IS NOT NULL THEN
2633                   l_v_party_number := finpl_get_org_unit_cd(v_ftfarv_rec.org_party_id);
2634               END IF;
2635               IF v_ftfarv_rec.unit_type_id IS NOT NULL THEN
2636                   l_v_level_code := finpl_get_uptl(v_ftfarv_rec.unit_type_id);
2637               ELSE
2638                   l_v_level_code := NULL;
2639               END IF;
2640               l_b_fee_ass_rate_found := TRUE;
2641               IF (v_fee_ass_rate_match = TRUE) THEN
2642                 EXIT;
2643               END IF;
2644 
2645               -- Attempt to match the assessment rate
2646                 -- Perform 2.3.1 Match Charge Rate
2647                 IF (finpl_ins_match_chg_rate(
2648                           v_ftfarv_rec.location_cd,
2649                           v_ftfarv_rec.ATTENDANCE_TYPE,
2650                           v_ftfarv_rec.ATTENDANCE_MODE,
2651                           v_ftfarv_rec.class_standing,
2652                           v_ftfarv_rec.course_cd,
2653                           v_ftfarv_rec.version_number,
2654                           l_v_party_number,
2655                           v_ftfarv_rec.residency_status_cd,
2656                           p_derived_location_cd,
2657                           p_derived_attendance_type,
2658                           p_derived_govt_att_mode,
2659                           p_derived_prog_att_mode,
2660                           p_derived_class_standing,
2661                           p_course_cd,
2662                           p_course_version_number,
2663                           p_derived_org_unit_cd,
2664                           p_derived_residency_status_cd,
2665                           v_ftfarv_rec.unit_set_cd,
2666                           v_ftfarv_rec.us_version_number,
2667                           p_derived_unit_set_cd,
2668                           p_derived_us_version_num,
2669                           v_ftfarv_rec.unit_type_id,
2670                           p_derived_unit_type_id,
2671                           v_ftfarv_rec.unit_class,
2672                           p_derived_unit_class,
2673                           v_ftfarv_rec.unit_mode,
2674                           p_derived_unit_mode,
2675                           v_ftfarv_rec.unit_cd,
2676                           p_derived_unit_cd,
2677                           v_ftfarv_rec.unit_version_number,
2678                           p_derived_unit_version_num,
2679                           v_ftfarv_rec.unit_level,
2680                           p_derived_unit_level
2681                           ) = TRUE) THEN
2682                   p_charge_rate := v_ftfarv_rec.chg_rate;
2683                   IF (p_trace_on = 'Y') THEN
2684                       fnd_file.new_line(fnd_file.log);
2685                       IF (p_derived_unit_cd IS NOT NULL) THEN
2686                         fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_ACCT_ENTITIES', 'UNIT') || ': ' || p_derived_unit_cd);
2687                       END IF;
2688                       fnd_message.set_name('IGS', 'IGS_FI_LEV_CHG_RATE_NO');
2689                       fnd_message.set_token('LEVEL', v_ftfarv_rec.s_relation_type);
2690                       fnd_message.set_token('CH_RT', TO_CHAR(v_ftfarv_rec.chg_rate));
2691                       fnd_message.set_token('RT_NUM', TO_CHAR(v_ftfarv_rec.rate_number));
2692                       fnd_message.set_token('ATT_TYP', NVL(v_ftfarv_rec.ATTENDANCE_TYPE, l_v_lkp_all));
2693                       fnd_message.set_token('ATT_MOD', NVL(v_ftfarv_rec.ATTENDANCE_MODE, l_v_lkp_all));
2694                       fnd_message.set_token('LOC', NVL(v_ftfarv_rec.location_cd, l_v_lkp_all));
2695                       fnd_message.set_token('RES_STAT', NVL(v_ftfarv_rec.residency_status_cd, l_v_lkp_all));
2696                       fnd_message.set_token('ORG_UNIT_CD', NVL(l_v_party_number, l_v_lkp_all));
2697                       fnd_message.set_token('COURSE_CD', NVL(v_ftfarv_rec.course_cd, l_v_lkp_all));
2698                       fnd_message.set_token('VERSION', NVL(TO_CHAR(v_ftfarv_rec.version_number), l_v_lkp_all));
2699                       fnd_message.set_token('CLAS_STNDNG', NVL(v_ftfarv_rec.class_standing, l_v_lkp_all));
2700                       fnd_message.set_token('UNIT_SET_CD', NVL(v_ftfarv_rec.unit_set_cd, l_v_lkp_all));
2701                       fnd_message.set_token('US_VER', NVL(TO_CHAR(v_ftfarv_rec.us_version_number), l_v_lkp_all));
2702                       fnd_message.set_token('UNIT_TYP_CD', NVL(l_v_level_code, l_v_lkp_all));
2703                       fnd_message.set_token('UNIT_CLASS', NVL(v_ftfarv_rec.unit_class, l_v_lkp_all));
2704                       fnd_message.set_token('UNIT_MODE', NVL(v_ftfarv_rec.unit_mode, l_v_lkp_all));
2705                       fnd_message.set_token('UNIT_CODE', NVL(v_ftfarv_rec.unit_cd, l_v_lkp_all));
2706                       fnd_message.set_token('UNIT_VER_NUM', NVL(TO_CHAR(v_ftfarv_rec.unit_version_number), l_v_lkp_all));
2707                       fnd_message.set_token('UNIT_LEVEL', NVL(v_ftfarv_rec.unit_level, l_v_lkp_all));
2708                       fnd_file.put_line (fnd_file.log, fnd_message.get);
2709                       fnd_message.set_name('IGS', 'IGS_FI_FEEASS_RATE_MATCHES');
2710                       fnd_file.put_line (fnd_file.log, fnd_message.get);
2711                   END IF;
2712                   -- stop processing Rate Records
2713                   log_to_fnd( p_v_module => 'finpl_find_far',
2714                               p_v_string => 'Rate Matched: ' || p_charge_rate );
2715                   v_fee_ass_rate_match := TRUE;
2716 
2717                 ELSE -- Not Matched
2718                   -- Process next rate record
2719                   NULL;
2720                 END IF; -- finpl_ins_match_chg_rate
2721             END LOOP;
2722     END IF;
2723 
2724     -- If there are no rates defined, return with charge rate of 0.
2725     IF l_b_fee_ass_rate_found = FALSE THEN
2726       log_to_fnd( p_v_module => 'finpl_find_far',
2727                   p_v_string => 'No Rate record found. Returning with 0 rate.');
2728       p_charge_rate := 0;
2729       IF (p_trace_on = 'Y') THEN
2730         fnd_file.new_line(fnd_file.log);
2731         IF (p_derived_unit_cd IS NOT NULL) THEN
2732             fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_ACCT_ENTITIES', 'UNIT') || ': ' || p_derived_unit_cd);
2733         END IF;
2734         fnd_message.set_name ( 'IGS', 'IGS_FI_FEEASS_RATE_FOUND');
2735         fnd_file.put_line (fnd_file.log, fnd_message.get);
2736         fnd_message.set_name('IGS', 'IGS_FI_CHG_RATE');
2737         fnd_message.set_token('RATE', '0');
2738         fnd_file.put_line (fnd_file.log, fnd_message.get);
2739         fnd_file.new_line(fnd_file.log);
2740       END IF;
2741     END IF;
2742 
2743     IF (l_b_fee_ass_rate_found = TRUE AND v_fee_ass_rate_match = FALSE) THEN
2744       -- In case no matching record found then charge rate is set as zero.
2745       log_to_fnd( p_v_module => 'finpl_find_far',
2746                   p_v_string => 'No Rate Matched. Returning with 0 rate.');
2747       p_charge_rate := 0;
2748       -- fee ass rate records existed, but none matched
2749       IF (p_trace_on = 'Y') THEN
2750         fnd_file.new_line(fnd_file.log);
2751         IF (p_derived_unit_cd IS NOT NULL) THEN
2752             fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_ACCT_ENTITIES', 'UNIT') || ': ' || p_derived_unit_cd);
2753         END IF;
2754         fnd_message.set_name('IGS', 'IGS_FI_FEEASS_RATE_EXISTS');
2755         fnd_file.put_line (fnd_file.log, fnd_message.get);
2756         fnd_message.set_name('IGS', 'IGS_FI_CHG_RATE');
2757         fnd_message.set_token('RATE', '0');
2758         fnd_file.put_line (fnd_file.log, fnd_message.get);
2759         fnd_file.new_line(fnd_file.log);
2760       END IF;
2761     END IF;
2762 
2763     log_to_fnd( p_v_module => 'finpl_find_far',
2764                 p_v_string => 'End of finpl_find_far. Out: Rate: ' || p_charge_rate );
2765   END;
2766   EXCEPTION
2767      WHEN OTHERS THEN
2768         log_to_fnd( p_v_module => 'finpl_find_far',
2769                     p_v_string => 'From exception handler of When Others.');
2770         Fnd_Message.Set_Name ('IGS', 'IGS_GE_UNHANDLED_EXP');
2771         Fnd_Message.Set_Token('NAME','IGS_FI_PRC_FEE_ASS.FINPL_FIND_FAR-'||SUBSTR(sqlerrm,1,500));
2772         IGS_GE_MSG_STACK.ADD;
2773         App_Exception.Raise_Exception;
2774 END finpl_find_far;
2775 
2776 PROCEDURE finpl_prc_element_ranges (p_n_person_id                IN  NUMBER,
2777                                p_v_fee_cat                  IN  VARCHAR2,
2778                                p_v_fee_type                 IN  VARCHAR2,
2779                                p_v_fee_cal_type             IN  VARCHAR2,
2780                                p_n_fee_ci_sequence_num      IN  NUMBER,
2781                                p_v_fee_trigger_cat          IN  VARCHAR2,
2782                                p_n_rul_sequence_num         IN  NUMBER,
2783                                p_v_der_course_cd            IN  VARCHAR2,
2784                                p_n_der_crs_version_num      IN  NUMBER,
2785                                p_v_der_location_cd          IN  VARCHAR2,
2786                                p_v_der_attendance_type      IN  VARCHAR2,
2787                                p_v_der_govt_att_mode        IN  VARCHAR2,
2788                                p_v_der_prog_att_mode        IN  VARCHAR2,
2789                                p_v_der_class_standing       IN  VARCHAR2,
2790                                p_v_der_org_unit_cd          IN  VARCHAR2,
2791                                p_v_der_residency_status_cd  IN  VARCHAR2,
2792                                p_v_der_unit_set_cd          IN  VARCHAR2,
2793                                p_n_der_us_version_num       IN  NUMBER,
2794                                p_v_fee_description          IN  VARCHAR2,
2795                                p_v_elm_rng_order_name       IN  VARCHAR2,
2796                                p_n_chg_elements             IN  NUMBER,
2797                                p_n_fee_amount               OUT NOCOPY NUMBER,
2798                                p_n_charge_rate              OUT NOCOPY NUMBER,
2799                                p_t_fee_as_items             IN OUT NOCOPY t_fee_as_items_typ,
2800                                p_v_trace_on                 IN VARCHAR2,
2801                                p_n_element_cap              IN NUMBER,
2802                                p_n_called                   IN NUMBER ) AS
2803 
2804  /*************************************************************
2805  Created By :      Bhaskar Annamalai
2806  Date Created By : 20-JUN-2005
2807  Purpose :  For processing element ranges.
2808 
2809  Know limitations, enhancements or remarks
2810 
2811  Change History
2812  Who         When            What
2813  pathipat    10-Oct-2005     Bug 4375258 - Change party_number FK to TCA parties impact
2814                              Replaced usage of igs_fi_gen_008.get_party_number with finpl_get_org_unit_cd
2815                              for Org derivation
2816  ***************************************************************/
2817 
2818 
2819 l_n_record_found  NUMBER;                        /* Used to check whether global element ranges are defined or not*/
2820 l_n_sub_rec_found NUMBER;                        /* Used to check whether sub ranges are defined or not*/
2821 l_n_match_elm_rng NUMBER;                        /* Used to check whether global element range matches*/
2822 l_n_charge_rate igs_fi_fee_as_rate.chg_rate%TYPE;
2823 l_b_rate_matched BOOLEAN;                        /* To check whether rate matches*/
2824 l_v_fee_category igs_fi_f_cat_ca_inst.fee_cat%TYPE;
2825 l_v_derived_location_cd  igs_fi_fee_as_rate.location_cd%TYPE;
2826 l_b_elm_range_rate_match BOOLEAN := FALSE;       /* To check whether global element range rate matches or not*/
2827 
2828 -- Cursor to find all Global Element ranges defined for the input parameter combination.
2829 CURSOR c_elm_ranges ( cp_v_fee_type       igs_fi_f_typ_ca_inst_all.fee_type%TYPE,
2830                       cp_v_fee_cal_type   igs_fi_f_typ_ca_inst_all.fee_cal_type%TYPE,
2831                       cp_n_ci_seq_number  igs_fi_f_typ_ca_inst_all.fee_ci_sequence_number%TYPE,
2832                       cp_v_fee_cat        igs_fi_fee_cat_all.fee_cat%TYPE ) IS
2833   SELECT er_id,
2834          s_relation_type,
2835          range_number,
2836          lower_range,
2837          upper_range,
2838          s_chg_method_type override_chg_method_type -- Override charge method at element range level
2839   FROM igs_fi_elm_range
2840   WHERE fee_type = cp_v_fee_type
2841   AND fee_cal_Type = cp_v_fee_cal_type
2842   AND fee_ci_sequence_number = cp_n_ci_seq_number
2843   AND (fee_cat IS NULL OR fee_cat = cp_v_fee_cat)
2844   AND logical_delete_dt IS NULL
2845   ORDER BY lower_range ASC;
2846 
2847 -- Cursor to find all rates defined under element range found in above cursor.
2848   CURSOR c_elm_rng_rates ( cp_v_fee_type       igs_fi_f_typ_ca_inst_all.fee_type%TYPE,
2849                            cp_v_fee_cal_type   igs_fi_f_typ_ca_inst_all.fee_cal_type%TYPE,
2850                            cp_n_ci_seq_number  igs_fi_f_typ_ca_inst_all.fee_ci_sequence_number%TYPE,
2851                            cp_v_fee_cat        igs_fi_fee_cat_all.fee_cat%TYPE,
2852                            cp_n_range_number   igs_fi_elm_range.range_number%TYPE,
2853                            cp_v_relation_type  igs_fi_elm_range.s_relation_type%TYPE) IS
2854    SELECT far.*
2855    FROM igs_fi_elm_range_rt err,
2856         igs_fi_fee_as_rate far
2857    WHERE far.fee_type = err.fee_type
2858    AND far.fee_cal_type = err.fee_cal_type
2859    AND far.fee_ci_sequence_number = err.fee_ci_sequence_number
2860    AND far.rate_number = err.rate_number
2861    AND far.s_relation_type = err.s_relation_type
2862    AND (far.fee_cat = err.fee_cat OR (far.fee_cat IS NULL AND err.fee_cat IS NULL))
2863    AND err.fee_type = cp_v_fee_type
2864    AND err.fee_cal_type = cp_v_fee_cal_type
2865    AND err.fee_ci_sequence_number = cp_n_ci_seq_number
2866    AND (err.fee_cat IS NULL OR err.fee_cat = cp_v_fee_cat)
2867    AND err.range_number = cp_n_range_number
2868    AND err.s_relation_type = cp_v_relation_type  -- just to be sure that Elm Ranges and Elm Range Rates are picked up from same level and so redundant.
2869    AND err.logical_delete_dt IS NULL
2870    AND far.logical_delete_dt IS NULL
2871    ORDER BY far.order_of_precedence ASC;
2872 
2873 -- Cursor to find all Sub Element ranges defined for the input parameter
2874 CURSOR cur_sub_elm_ranges (cp_n_er_id  igs_fi_elm_range.er_id%TYPE) IS
2875 SELECT *
2876 FROM igs_fi_sub_elm_rng
2877 WHERE er_id = cp_n_er_id
2878 ORDER BY sub_lower_range;
2879 
2880 -- Cursor to find all rates defined under sub element range found in above cursor.
2881 CURSOR cur_sub_elm_rng_rates (cp_n_sub_er_id  igs_fi_sub_er_rt.sub_er_id%TYPE) IS
2882 SELECT far.*
2883 FROM igs_fi_sub_er_rt ser,
2884              igs_fi_fee_as_rate far
2885 WHERE ser.sub_er_id = cp_n_sub_er_id
2886 AND far.far_id = ser.far_id
2887 AND ser.logical_delete_date IS NULL
2888 AND far.logical_delete_dt IS NULL
2889 ORDER BY far.order_of_precedence;
2890 
2891  -- To find the organization unit code from the Prgoram Version Table (For Charge Method of
2892  -- FLATRATE)
2893  CURSOR c_resp_org_unit_cd(cp_course_cd IN igs_ps_ver_all.course_cd%TYPE,
2894                            cp_version_number IN igs_ps_ver_all.version_number%TYPE
2895                           )IS
2896  SELECT responsible_org_unit_cd
2897  FROM   igs_ps_ver_all v
2898  WHERE  v.course_cd            = cp_course_cd
2899  AND    v.version_number       = cp_version_number;
2900 
2901  CURSOR cur_get_ret_level (cp_v_fee_type              igs_fi_f_typ_ca_inst_all.fee_type%TYPE,
2902                             cp_v_fee_cal_type          igs_fi_f_typ_ca_inst_all.fee_cal_type%TYPE,
2903                              cp_n_fee_ci_sequence_num   igs_fi_f_typ_ca_inst_all.fee_ci_sequence_number%TYPE) IS
2904    SELECT retention_level_code
2905    FROM  igs_fi_f_typ_ca_inst_all
2906    WHERE fee_type               = cp_v_fee_type
2907    AND   fee_cal_type           = cp_v_fee_cal_type
2908    AND   fee_ci_sequence_number = cp_n_fee_ci_sequence_num;
2909 
2910 l_v_derived_org_unit_cd        igs_ps_ver_all.responsible_org_unit_cd%TYPE;
2911 l_rec_sub_rates                cur_sub_elm_rng_rates%ROWTYPE;
2912 l_rec_global_rates             c_elm_rng_rates%ROWTYPE;
2913 l_n_count                      NUMBER;   -- Used like an index variable when a new record in added to the plsql table tbl_fai_unit_dtls
2914 l_v_party_number               hz_parties.party_number%TYPE := NULL;
2915 l_n_loop_subelm_rng            NUMBER;
2916 l_n_previous_upper             igs_fi_sub_elm_rng.sub_upper_range%TYPE;
2917 l_v_lower_nrml_rate_ovrd_ind   IGS_FI_FEE_AS_RT.lower_nrml_rate_ovrd_ind%TYPE;
2918 l_n_cfar_chg_rate              IGS_FI_FEE_AS_RT.chg_rate%TYPE;
2919 lv_cntrct_rt_apply             BOOLEAN;
2920 l_n_summed_chg_elm             igs_fi_fee_as_items.chg_elements%TYPE;
2921 l_n_rate_factor                igs_fi_fee_as_items.chg_elements%TYPE;
2922 l_b_flag                       BOOLEAN;
2923 l_b_first_rate_match           BOOLEAN;
2924 l_v_ret_level                  igs_fi_f_typ_ca_inst_all.retention_level_code%TYPE;
2925 l_v_level_code                 igs_ps_unit_type_lvl.level_code%TYPE;
2926 
2927 BEGIN
2928 
2929   l_n_record_found  := 0;
2930   l_n_match_elm_rng := 0;
2931   l_n_sub_rec_found := 0;
2932   p_n_fee_amount   := 0;
2933   l_n_loop_subelm_rng := 0;
2934   l_b_first_rate_match := FALSE;
2935 
2936   log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
2937               p_v_string => 'Entered finpl_prc_element_ranges. ');
2938 
2939   l_n_summed_chg_elm := p_n_chg_elements;
2940 
2941   OPEN cur_get_ret_level(p_v_fee_type, p_v_fee_cal_type, p_n_fee_ci_sequence_num);
2942   FETCH cur_get_ret_level INTO l_v_ret_level;
2943   CLOSE cur_get_ret_level;
2944 
2945   FOR rec_elm_ranges IN c_elm_ranges( p_v_fee_type,
2946                                    p_v_fee_cal_type,
2947                                    p_n_fee_ci_sequence_num,
2948                                    p_v_fee_cat)
2949   LOOP
2950     l_n_record_found := 1;
2951     IF ((rec_elm_ranges.lower_range IS NULL OR l_n_summed_chg_elm >= rec_elm_ranges.lower_range)
2952          AND (rec_elm_ranges.upper_range IS NULL OR l_n_summed_chg_elm <= rec_elm_ranges.upper_range)) THEN
2953     --Global Element range matched
2954       log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
2955                   p_v_string => 'Global Element Range applies. Lower ' || rec_elm_ranges.lower_range || ', Upper: ' || rec_elm_ranges.upper_range);
2956       -- Global Element Range Applies
2957       IF (p_v_trace_on = 'Y') THEN
2958          fnd_file.new_line(fnd_file.log);
2959          fnd_message.set_name ( 'IGS', 'IGS_FI_ELE_RANGE_APPLIES');
2960          fnd_file.put_line (fnd_file.log, fnd_message.get);
2961          fnd_message.set_name('IGS', 'IGS_FI_TESTING_ELEMENT_RANGE');
2962          fnd_message.set_token('ELM_RNG_NUM', TO_CHAR(rec_elm_ranges.range_number));
2963          fnd_file.put_line (fnd_file.log, fnd_message.get);
2964          fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'LOW_RANGE') || ': ' || TO_CHAR(rec_elm_ranges.lower_range));
2965          fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'UPPER_RANGE') || ': ' || TO_CHAR(rec_elm_ranges.upper_range));
2966          IF (rec_elm_ranges.override_chg_method_type IS NOT NULL) THEN
2967             fnd_message.set_name('IGS', 'IGS_FI_OVRRIDE_CHG_METH_TYPE');
2968             fnd_message.set_token('CHG_MTHD', igs_fi_gen_gl.get_lkp_meaning('CHG_METHOD', rec_elm_ranges.override_chg_method_type));
2969             fnd_file.put_line (fnd_file.log, fnd_message.get);
2970          END IF;
2971       END IF;
2972 
2973       IF p_v_elm_rng_order_name IS NOT NULL THEN
2974         log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
2975                     p_v_string => 'Calling finpl_sort_table to sort the record in the plsql table');
2976         finpl_sort_table( p_t_fee_as_items, p_v_elm_rng_order_name);
2977       END IF;
2978 
2979       l_n_match_elm_rng := 1;
2980       IF (rec_elm_ranges.override_chg_method_type = gcst_flatrate) THEN
2981         l_n_rate_factor := 1;
2982         OPEN c_elm_rng_rates ( p_v_fee_type,
2983                                p_v_fee_cal_type,
2984                                p_n_fee_ci_sequence_num,
2985                                p_v_fee_cat,
2986                                rec_elm_ranges.range_number,
2987                                rec_elm_ranges.s_relation_type);
2988         FETCH c_elm_rng_rates INTO l_rec_global_rates;
2989         IF (c_elm_rng_rates%NOTFOUND) THEN
2990 
2991           CLOSE c_elm_rng_rates;
2992           --Rate records not found
2993           IF (p_v_trace_on = 'Y') THEN
2994               fnd_message.set_name('IGS', 'IGS_FI_GLBELM_NO_RATE');
2995               fnd_file.put_line (fnd_file.log, fnd_message.get);
2996           END IF;
2997           p_n_charge_rate := 0;
2998           p_n_fee_amount  := 0;
2999          log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3000                      p_v_string => 'Returning from the procedure since there are no active rates.');
3001           RETURN;
3002         ELSE
3003           CLOSE c_elm_rng_rates;
3004 
3005           IF ((g_c_fee_calc_mthd = g_v_primary_career) OR
3006                   ((g_c_fee_calc_mthd <> g_v_primary_career) AND (p_v_fee_trigger_cat <> 'INSTITUTN'))) THEN
3007 
3008               OPEN c_resp_org_unit_cd(p_v_der_course_cd, p_n_der_crs_version_num);
3009               FETCH c_resp_org_unit_cd INTO l_v_derived_org_unit_cd;
3010               CLOSE c_resp_org_unit_cd;
3011               l_v_derived_location_cd := p_v_der_location_cd;
3012               l_v_fee_category := p_v_fee_cat;
3013 
3014           ELSE --If fee calculation method is not primary career and fee trigger category is Institution
3015               l_v_derived_org_unit_cd := NULL;
3016               l_v_derived_location_cd := NULL;
3017               l_v_fee_category := NULL;
3018           END IF;
3019 
3020           OPEN c_elm_rng_rates ( p_v_fee_type,
3021                             p_v_fee_cal_type,
3022                             p_n_fee_ci_sequence_num,
3023                             p_v_fee_cat,
3024                             rec_elm_ranges.range_number,
3025                             rec_elm_ranges.s_relation_type);
3026           FETCH c_elm_rng_rates INTO l_rec_global_rates;
3027 
3028           l_b_elm_range_rate_match := FALSE;
3029 
3030           WHILE (c_elm_rng_rates%FOUND)
3031           LOOP
3032               IF (l_rec_global_rates.org_party_id IS NOT NULL) THEN
3033                 l_v_party_number := finpl_get_org_unit_cd(l_rec_global_rates.org_party_id);
3034               ELSE
3035                 l_v_party_number := NULL;
3036               END IF;
3037               log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3038                           p_v_string => 'Calling finpl_ins_match_chg_rate');
3039               IF ( finpl_ins_match_chg_rate(
3040                                    l_rec_global_rates.location_cd,
3041                                    l_rec_global_rates.attendance_type,
3042                                    l_rec_global_rates.attendance_mode,
3043                                    l_rec_global_rates.class_standing,
3044                                    l_rec_global_rates.course_cd,
3045                                    l_rec_global_rates.version_number,
3046                                    l_v_party_number,
3047                                    l_rec_global_rates.residency_status_cd,
3048                                    l_v_derived_location_cd,
3049                                    p_v_der_attendance_type,
3050                                    p_v_der_govt_att_mode,
3051                                    p_v_der_prog_att_mode,
3052                                    p_v_der_class_standing,
3053                                    p_v_der_course_cd,
3054                                    p_n_der_crs_version_num,
3055                                    l_v_derived_org_unit_cd,
3056                                    p_v_der_residency_status_cd,
3057                                    l_rec_global_rates.unit_set_cd,
3058                                    l_rec_global_rates.us_version_number,
3059                                    p_v_der_unit_set_cd,
3060                                    p_n_der_us_version_num,
3061                                    NULL,
3062                                    NULL,
3063                                    NULL,
3064                                    NULL,
3065                                    NULL,
3066                                    NULL,
3067                                    NULL,
3068                                    NULL,
3069                                    NULL,
3070                                    NULL,
3071                                    NULL,
3072                                    NULL ) = TRUE ) THEN
3073 
3074                    log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3075                                p_v_string => 'Global Element Range rate matches');
3076                    IF (p_v_trace_on = 'Y') THEN
3077                      fnd_file.new_line(fnd_file.log);
3078                      fnd_message.set_name('IGS', 'IGS_FI_LEV_CHG_RATE_NO');
3079                      fnd_message.set_token('LEVEL', l_rec_global_rates.s_relation_type);
3080                      fnd_message.set_token('CH_RT', TO_CHAR(l_rec_global_rates.chg_rate));
3081                      fnd_message.set_token('RT_NUM', TO_CHAR(l_rec_global_rates.rate_number));
3082                      fnd_message.set_token('ATT_TYP', NVL(l_rec_global_rates.ATTENDANCE_TYPE, l_v_lkp_all));
3083                      fnd_message.set_token('ATT_MOD', NVL(l_rec_global_rates.ATTENDANCE_MODE, l_v_lkp_all));
3084                      fnd_message.set_token('LOC', NVL(l_rec_global_rates.location_cd, l_v_lkp_all));
3085                      fnd_message.set_token('RES_STAT', NVL(l_rec_global_rates.residency_status_cd, l_v_lkp_all));
3086                      fnd_message.set_token('ORG_UNIT_CD', NVL(l_v_party_number, l_v_lkp_all));
3087                      fnd_message.set_token('COURSE_CD', NVL(l_rec_global_rates.course_cd, l_v_lkp_all));
3088                      fnd_message.set_token('VERSION', NVL(TO_CHAR(l_rec_global_rates.version_number), l_v_lkp_all));
3089                      fnd_message.set_token('CLAS_STNDNG', NVL(l_rec_global_rates.class_standing, l_v_lkp_all));
3090                      fnd_message.set_token('UNIT_SET_CD', NVL(l_rec_global_rates.unit_set_cd, l_v_lkp_all));
3091                      fnd_message.set_token('US_VER', NVL(TO_CHAR(l_rec_global_rates.us_version_number), l_v_lkp_all));
3092                      fnd_message.set_token('UNIT_TYP_CD', NVL(TO_CHAR(l_rec_global_rates.unit_type_id), l_v_lkp_all));
3093                      fnd_message.set_token('UNIT_CLASS', NVL(l_rec_global_rates.unit_class, l_v_lkp_all));
3094                      fnd_message.set_token('UNIT_MODE', NVL(l_rec_global_rates.unit_mode, l_v_lkp_all));
3095                      fnd_message.set_token('UNIT_CODE', NVL(l_rec_global_rates.unit_cd, l_v_lkp_all));
3096                      fnd_message.set_token('UNIT_VER_NUM', NVL(TO_CHAR(l_rec_global_rates.unit_version_number), l_v_lkp_all));
3097                      fnd_message.set_token('UNIT_LEVEL', NVL(l_rec_global_rates.unit_level, l_v_lkp_all));
3098                      fnd_file.put_line (fnd_file.log, fnd_message.get);
3099                      fnd_message.set_name('IGS', 'IGS_FI_FEEASS_RATE_MATCHES');
3100                      fnd_file.put_line (fnd_file.log, fnd_message.get);
3101                      fnd_file.new_line(fnd_file.log);
3102                    END IF;
3103 
3104                    l_b_elm_range_rate_match := TRUE;
3105                    p_n_charge_rate := l_rec_global_rates.chg_rate;
3106                    EXIT;
3107               END IF;
3108           FETCH c_elm_rng_rates INTO l_rec_global_rates;
3109           END LOOP;
3110           CLOSE c_elm_rng_rates;
3111 
3112           --If rate is not matched
3113           IF (NOT l_b_elm_range_rate_match) THEN
3114               log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3115                           p_v_string => 'No Rate Matched. Returning with 0 rate.');
3116               p_n_charge_rate := 0;
3117               p_n_fee_amount  := 0;
3118               IF (p_v_trace_on = 'Y') THEN
3119                 fnd_file.new_line(fnd_file.log);
3120                 fnd_message.set_name ( 'IGS', 'IGS_FI_NO_ELM_RNG_RATE_MATCH');
3121                 fnd_file.put_line (fnd_file.log, fnd_message.get);
3122                 fnd_message.set_name('IGS', 'IGS_FI_CHG_RATE');
3123                 fnd_message.set_token('RATE', TO_CHAR(p_n_charge_rate) );
3124                 fnd_file.put_line (fnd_file.log, fnd_message.get);
3125                 fnd_file.new_line(fnd_file.log);
3126               END IF;
3127               RETURN;
3128           END IF;
3129 
3130           OPEN c_cfar (l_v_derived_location_cd, p_v_der_attendance_type, p_v_der_prog_att_mode, p_v_der_govt_att_mode);
3131           FETCH c_cfar INTO       l_v_lower_nrml_rate_ovrd_ind,
3132                                   l_n_cfar_chg_rate;
3133 
3134           IF (c_cfar%FOUND) THEN
3135             log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3136                         p_v_string => 'l_n_cfar_chg_rate: ' || l_n_cfar_chg_rate || ', l_v_lower_nrml_rate_ovrd_ind: ' || l_v_lower_nrml_rate_ovrd_ind);
3137             IF (l_v_lower_nrml_rate_ovrd_ind = 'Y') THEN
3138               -- the normal rate is used when it
3139               -- is lower than the contract rate
3140               IF (p_n_charge_rate > l_n_cfar_chg_rate) THEN
3141                 IF (p_trace_on = 'Y') THEN
3142                   fnd_message.set_name('IGS', 'IGS_FI_CONTRACT_RATE');
3143                   fnd_message.set_token('RATE', TO_CHAR(NVL(l_n_cfar_chg_rate, 0)) );
3144                   fnd_file.put_line (fnd_file.log, fnd_message.get);
3145                   fnd_message.set_name('IGS', 'IGS_FI_CHG_RATE');
3146                   fnd_message.set_token('RATE', TO_CHAR(NVL(l_n_charge_rate, 0)) );
3147                   fnd_file.put_line (fnd_file.log, fnd_message.get);
3148                 END IF;
3149                 lv_cntrct_rt_apply := TRUE;
3150                 p_n_charge_rate := l_n_cfar_chg_rate;
3151                 log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3152                             p_v_string => 'The contract rate is lower than the charge rate, so the contract rate will be used. Chg Rate: ' || l_n_charge_rate);
3153               END IF;
3154             ELSE
3155               -- Use the contract rate
3156               lv_cntrct_rt_apply := TRUE;
3157               p_n_charge_rate := l_n_cfar_chg_rate;
3158               IF (p_trace_on = 'Y') THEN
3159                 fnd_message.set_name('IGS', 'IGS_FI_CONTRACT_RATE');
3160                 fnd_message.set_token('RATE', TO_CHAR(NVL(l_n_charge_rate, 0)) );
3161                 fnd_file.put_line (fnd_file.log, fnd_message.get);
3162               END IF;
3163               log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3164                           p_v_string => 'The contract rate will be used. Chg Rate: ' || l_n_charge_rate);
3165             END IF;
3166 
3167           ELSE
3168             log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3169                         p_v_string => 'No Contract Rate Found ..');
3170           END IF;
3171           -- attempt to find a second contract rate - only one record should be found
3172           FETCH c_cfar INTO l_v_lower_nrml_rate_ovrd_ind,
3173                             l_n_cfar_chg_rate;
3174           IF (c_cfar%FOUND) THEN
3175             CLOSE c_cfar;
3176             IF g_v_wav_calc_flag = 'N' THEN
3177               ROLLBACK TO fee_calc_sp;
3178             END IF;
3179 
3180             IF (p_trace_on = 'Y') THEN
3181                 fnd_message.set_name('IGS', 'IGS_FI_MULTI_CONTRACT_RT');
3182                 fnd_file.put_line (fnd_file.log, fnd_message.get);
3183             END IF;
3184             log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3185                         p_v_string => 'Raising e_one_record_expected.');
3186             RAISE e_one_record_expected;
3187           END IF;
3188           CLOSE c_cfar;
3189 
3190           p_n_fee_amount := igs_ru_gen_003.rulp_clc_student_fee( p_n_rul_sequence_num,
3191                                                                  NVL(l_n_rate_factor,0),
3192                                                                  NVL(p_n_charge_rate,0) );
3193 
3194           l_b_flag := FALSE;
3195 
3196           IF (p_n_called <> 1) THEN
3197              IF (p_v_fee_trigger_cat <> gcst_institutn) THEN
3198                 tbl_fai_unit_dtls.DELETE;
3199              END IF;
3200 
3201              FOR i IN 1..p_t_fee_as_items.COUNT
3202              LOOP
3203                IF (p_v_fee_trigger_cat <> gcst_institutn AND l_v_ret_level = 'TEACH_PERIOD' AND g_c_predictive_ind = 'N') THEN
3204                   IF (p_t_fee_as_items(i).uoo_id IS NOT NULL AND NVL(p_t_fee_as_items(i).chg_elements,0) > 0) THEN
3205                     l_n_count := tbl_fai_unit_dtls.COUNT + 1;
3206                     tbl_fai_unit_dtls(l_n_count).fee_cat             :=  p_v_fee_cat;
3207                     tbl_fai_unit_dtls(l_n_count).course_cd           :=  p_v_der_course_cd;
3208                     tbl_fai_unit_dtls(l_n_count).crs_version_number  :=  p_n_der_crs_version_num;
3209                     tbl_fai_unit_dtls(l_n_count).unit_attempt_status :=  p_t_fee_as_items(i).unit_attempt_status;
3210                     tbl_fai_unit_dtls(l_n_count).org_unit_cd         :=  p_t_fee_as_items(i).org_unit_cd;
3211                     tbl_fai_unit_dtls(l_n_count).class_standing      :=  p_v_der_class_standing;
3212                     tbl_fai_unit_dtls(l_n_count).location_cd         :=  p_t_fee_as_items(i).location_cd;
3213                     tbl_fai_unit_dtls(l_n_count).uoo_id              :=  p_t_fee_as_items(i).uoo_id;
3214                     tbl_fai_unit_dtls(l_n_count).unit_set_cd         :=  p_v_der_unit_set_cd;
3215                     tbl_fai_unit_dtls(l_n_count).us_version_number   :=  p_n_der_us_version_num;
3216                     tbl_fai_unit_dtls(l_n_count).chg_elements        :=  p_t_fee_as_items(i).chg_elements;
3217                     tbl_fai_unit_dtls(l_n_count).unit_type_id        :=  p_t_fee_as_items(i).unit_type_id;
3218                     tbl_fai_unit_dtls(l_n_count).unit_class          :=  p_t_fee_as_items(i).unit_class;
3219                     tbl_fai_unit_dtls(l_n_count).unit_mode           :=  p_t_fee_as_items(i).unit_mode;
3220                     tbl_fai_unit_dtls(l_n_count).unit_cd             :=  p_t_fee_as_items(i).unit_cd;
3221                     tbl_fai_unit_dtls(l_n_count).unit_level          :=  p_t_fee_as_items(i).unit_level;
3222                     tbl_fai_unit_dtls(l_n_count).unit_version_number :=  p_t_fee_as_items(i).unit_version_number;
3223                   END IF;
3224                END IF;
3225                IF t_fee_as_items(i).chg_elements >= 0 AND
3226                      t_fee_as_items(i).uoo_id IS NULL AND
3227                      t_fee_as_items(i).old_amount > 0 THEN
3228                           p_t_fee_as_items(i).chg_elements := 1;
3229                           p_t_fee_as_items(i).amount := p_n_fee_amount;
3230 
3231                  l_b_flag := TRUE;
3232 
3233                ELSE
3234                  p_t_fee_as_items(i).amount := 0;
3235                END IF;
3236 
3237              END LOOP;
3238 
3239              IF (l_b_flag = FALSE) THEN
3240 
3241                 gv_as_item_cntr := nvl(gv_as_item_cntr,0) + 1;
3242                 -- Insert a new record in the IGS_FI_FEE_AS_ITEMS table
3243                 p_t_fee_as_items(gv_as_item_cntr).person_id               := p_n_person_id;
3244                 p_t_fee_as_items(gv_as_item_cntr).status                  := 'O';
3245                 p_t_fee_as_items(gv_as_item_cntr).fee_type                := p_v_fee_type;
3246                 p_t_fee_as_items(gv_as_item_cntr).fee_cat                 := l_v_fee_category;
3247                 p_t_fee_as_items(gv_as_item_cntr).fee_cal_type            := p_v_fee_cal_type;
3248                 p_t_fee_as_items(gv_as_item_cntr).fee_ci_sequence_number  := p_n_fee_ci_sequence_num;
3249                 p_t_fee_as_items(gv_as_item_cntr).course_cd               := p_v_der_course_cd;
3250                 p_t_fee_as_items(gv_as_item_cntr).crs_version_number      := l_n_crs_version_num;
3251                 p_t_fee_as_items(gv_as_item_cntr).description             := p_v_fee_description;
3252                 p_t_fee_as_items(gv_as_item_cntr).chg_method_type         := gcst_flatrate;
3253                 p_t_fee_as_items(gv_as_item_cntr).old_chg_elements        := 0;
3254                 p_t_fee_as_items(gv_as_item_cntr).chg_elements            := NVL(l_n_rate_factor,0);
3255                 p_t_fee_as_items(gv_as_item_cntr).old_amount              := 0;
3256                 p_t_fee_as_items(gv_as_item_cntr).amount                  := NVL(p_n_fee_amount,0);
3257                 p_t_fee_as_items(gv_as_item_cntr).unit_attempt_status     := null;
3258                 p_t_fee_as_items(gv_as_item_cntr).location_cd             := l_v_derived_location_cd;
3259                 p_t_fee_as_items(gv_as_item_cntr).old_eftsu               := NULL;
3260                 p_t_fee_as_items(gv_as_item_cntr).eftsu                   := NULL;
3261                 p_t_fee_as_items(gv_as_item_cntr).old_credit_points       := NULL;
3262                 p_t_fee_as_items(gv_as_item_cntr).credit_points           := NULL;
3263                 p_t_fee_as_items(gv_as_item_cntr).org_unit_cd             := l_v_derived_org_unit_cd;
3264                 p_t_fee_as_items(gv_as_item_cntr).uoo_id                  := NULL;
3265                 p_t_fee_as_items(gv_as_item_cntr).chg_rate                := NVL(p_n_charge_rate,0);
3266                 p_t_fee_as_items(gv_as_item_cntr).rul_sequence_number     := p_n_rul_sequence_num;
3267                 p_t_fee_as_items(gv_as_item_cntr).unit_set_cd             := p_v_der_unit_set_cd;
3268                 p_t_fee_as_items(gv_as_item_cntr).us_version_number       := p_n_der_us_version_num;
3269                 p_t_fee_as_items(gv_as_item_cntr).residency_status_cd     := p_v_der_residency_status_cd;
3270                 p_t_fee_as_items(gv_as_item_cntr).class_standing          := p_v_der_class_standing;
3271                 p_t_fee_as_items(gv_as_item_cntr).unit_type_id            := NULL;
3272                 p_t_fee_as_items(gv_as_item_cntr).unit_class              := NULL;
3273                 p_t_fee_as_items(gv_as_item_cntr).unit_mode               := NULL;
3274                 p_t_fee_as_items(gv_as_item_cntr).unit_cd                 := NULL;
3275                 p_t_fee_as_items(gv_as_item_cntr).unit_version_number     := NULL;
3276                 p_t_fee_as_items(gv_as_item_cntr).unit_level              := NULL;
3277 
3278                 log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3279                             p_v_string => 'Charge Method Overidden. Adding record to PL/SQL table as record number: ' || gv_as_item_cntr );
3280              END IF;
3281           END IF;
3282         END IF;
3283 
3284       ELSIF rec_elm_ranges.override_chg_method_type  IS NULL THEN
3285         IF ((p_n_element_cap IS NOT NULL) AND (p_n_element_cap < l_n_summed_chg_elm)) THEN
3286           l_n_rate_factor := p_n_element_cap;
3287         ELSE
3288           l_n_rate_factor := l_n_summed_chg_elm;
3289         END IF;
3290 
3291         OPEN c_elm_rng_rates ( p_v_fee_type,
3292                                p_v_fee_cal_type,
3293                                p_n_fee_ci_sequence_num,
3294                                p_v_fee_cat,
3295                                rec_elm_ranges.range_number,
3296                                rec_elm_ranges.s_relation_type);
3297         FETCH c_elm_rng_rates INTO l_rec_global_rates;
3298         IF (c_elm_rng_rates%NOTFOUND) THEN
3299 
3300           CLOSE c_elm_rng_rates;
3301           --Rate records not found
3302           IF (p_v_trace_on = 'Y') THEN
3303               fnd_message.set_name('IGS', 'IGS_FI_GLBELM_NO_RATE');
3304               fnd_file.put_line (fnd_file.log, fnd_message.get);
3305           END IF;
3306           p_n_charge_rate := 0;
3307           p_n_fee_amount  := 0;
3308           log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3309                      p_v_string => 'Returning from the procedure since there are no active rates.');
3310           RETURN;
3311 
3312         ELSE
3313 
3314           CLOSE c_elm_rng_rates;
3315 
3316                   log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3317                               p_v_string => 'Looping across the input PLSQL table, p_t_fee_as_items');
3318           FOR i IN 1..p_t_fee_as_items.COUNT
3319           LOOP
3320             log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3321                         p_v_string => 'Record: '||i||' - Status: '||p_t_fee_as_items(i).status||' Chg Elements: '||p_t_fee_as_items(i).chg_elements);
3322             IF (p_t_fee_as_items(i).status = 'E' AND p_t_fee_as_items(i).chg_elements > 0) THEN
3323               l_b_elm_range_rate_match := FALSE;
3324                   log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3325                               p_v_string => 'Looping across the Global Element Range Rates');
3326               OPEN c_elm_rng_rates ( p_v_fee_type,
3327                                 p_v_fee_cal_type,
3328                                 p_n_fee_ci_sequence_num,
3329                                 p_v_fee_cat,
3330                                 rec_elm_ranges.range_number,
3331                                 rec_elm_ranges.s_relation_type);
3332               FETCH c_elm_rng_rates INTO l_rec_global_rates;
3333               WHILE (c_elm_rng_rates%FOUND)
3334               LOOP
3335 
3336                   IF (l_rec_global_rates.org_party_id IS NOT NULL) THEN
3337                     l_v_party_number := finpl_get_org_unit_cd(l_rec_global_rates.org_party_id);
3338                   ELSE
3339                     l_v_party_number := NULL;
3340                   END IF;
3341                   IF l_rec_global_rates.unit_type_id IS NOT NULL THEN
3342                       l_v_level_code := finpl_get_uptl(l_rec_global_rates.unit_type_id);
3343                   ELSE
3344                       l_v_level_code := NULL;
3345                   END IF;
3346                   log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3347                               p_v_string => 'Calling finpl_ins_match_chg_rate');
3348                   IF ( finpl_ins_match_chg_rate(
3349                                        l_rec_global_rates.location_cd,
3350                                        l_rec_global_rates.attendance_type,
3351                                        l_rec_global_rates.attendance_mode,
3352                                        l_rec_global_rates.class_standing,
3353                                        l_rec_global_rates.course_cd,
3354                                        l_rec_global_rates.version_number,
3355                                        l_v_party_number,
3356                                        l_rec_global_rates.residency_status_cd,
3357                                        p_t_fee_as_items(i).location_cd,
3358                                        p_v_der_attendance_type,
3359                                        p_v_der_govt_att_mode,
3360                                        p_v_der_prog_att_mode,
3361                                        p_v_der_class_standing,
3362                                        p_v_der_course_cd,
3363                                        p_n_der_crs_version_num,
3364                                        p_t_fee_as_items(i).org_unit_cd,
3365                                        p_v_der_residency_status_cd,
3366                                        l_rec_global_rates.unit_set_cd,
3367                                        l_rec_global_rates.us_version_number,
3368                                        p_v_der_unit_set_cd,
3369                                        p_n_der_us_version_num,
3370                                        l_rec_global_rates.unit_type_id,
3371                                        p_t_fee_as_items(i).unit_type_id,
3372                                        l_rec_global_rates.unit_class,
3373                                        p_t_fee_as_items(i).unit_class,
3374                                        l_rec_global_rates.unit_mode,
3375                                        p_t_fee_as_items(i).unit_mode,
3376                                        l_rec_global_rates.unit_cd,
3377                                        p_t_fee_as_items(i).unit_cd,
3378                                        l_rec_global_rates.unit_version_number,
3379                                        p_t_fee_as_items(i).unit_version_number,
3380                                        l_rec_global_rates.unit_level,
3381                                        p_t_fee_as_items(i).unit_level) = TRUE ) THEN
3382 
3383                        log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3384                                    p_v_string => 'Global Element Range rate matches');
3385                        IF (p_v_trace_on = 'Y') THEN
3386                          fnd_file.new_line(fnd_file.log);
3387                          IF (p_v_fee_trigger_cat <> gcst_institutn) THEN
3388                            fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_ACCT_ENTITIES', 'UNIT') || ': ' || p_t_fee_as_items(i).unit_cd);
3389                          END IF;
3390                          fnd_message.set_name('IGS', 'IGS_FI_LEV_CHG_RATE_NO');
3391                          fnd_message.set_token('LEVEL', l_rec_global_rates.s_relation_type);
3392                          fnd_message.set_token('CH_RT', TO_CHAR(l_rec_global_rates.chg_rate));
3393                          fnd_message.set_token('RT_NUM', TO_CHAR(l_rec_global_rates.rate_number));
3394                          fnd_message.set_token('ATT_TYP', NVL(l_rec_global_rates.ATTENDANCE_TYPE, l_v_lkp_all));
3395                          fnd_message.set_token('ATT_MOD', NVL(l_rec_global_rates.ATTENDANCE_MODE, l_v_lkp_all));
3396                          fnd_message.set_token('LOC', NVL(l_rec_global_rates.location_cd, l_v_lkp_all));
3397                          fnd_message.set_token('RES_STAT', NVL(l_rec_global_rates.residency_status_cd, l_v_lkp_all));
3398                          fnd_message.set_token('ORG_UNIT_CD', NVL(l_v_party_number, l_v_lkp_all));
3399                          fnd_message.set_token('COURSE_CD', NVL(l_rec_global_rates.course_cd, l_v_lkp_all));
3400                          fnd_message.set_token('VERSION', NVL(TO_CHAR(l_rec_global_rates.version_number), l_v_lkp_all));
3401                          fnd_message.set_token('CLAS_STNDNG', NVL(l_rec_global_rates.class_standing, l_v_lkp_all));
3402                          fnd_message.set_token('UNIT_SET_CD', NVL(l_rec_global_rates.unit_set_cd, l_v_lkp_all));
3403                          fnd_message.set_token('US_VER', NVL(TO_CHAR(l_rec_global_rates.us_version_number), l_v_lkp_all));
3404                          fnd_message.set_token('UNIT_TYP_CD', NVL(l_v_level_code, l_v_lkp_all));
3405                          fnd_message.set_token('UNIT_CLASS', NVL(l_rec_global_rates.unit_class, l_v_lkp_all));
3406                          fnd_message.set_token('UNIT_MODE', NVL(l_rec_global_rates.unit_mode, l_v_lkp_all));
3407                          fnd_message.set_token('UNIT_CODE', NVL(l_rec_global_rates.unit_cd, l_v_lkp_all));
3408                          fnd_message.set_token('UNIT_VER_NUM', NVL(TO_CHAR(l_rec_global_rates.unit_version_number), l_v_lkp_all));
3409                          fnd_message.set_token('UNIT_LEVEL', NVL(l_rec_global_rates.unit_level, l_v_lkp_all));
3410                          fnd_file.put_line (fnd_file.log, fnd_message.get);
3411                          fnd_message.set_name('IGS', 'IGS_FI_FEEASS_RATE_MATCHES');
3412                          fnd_file.put_line (fnd_file.log, fnd_message.get);
3413                          fnd_file.new_line(fnd_file.log);
3414                        END IF;
3415 
3416                        l_b_elm_range_rate_match := TRUE;
3417                        p_n_charge_rate := l_rec_global_rates.chg_rate;
3418                        p_t_fee_as_items(i).chg_rate := l_rec_global_rates.chg_rate;
3419                        EXIT;
3420                   END IF;
3421 
3422               FETCH c_elm_rng_rates INTO l_rec_global_rates;
3423               END LOOP;
3424               CLOSE c_elm_rng_rates;
3425 
3426               --If rate is not matched
3427               IF (NOT l_b_elm_range_rate_match) THEN
3428                   log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3429                               p_v_string => 'No Rate Matched. Returning with 0 rate.');
3430                   p_n_charge_rate := 0;
3431                   p_t_fee_as_items(i).chg_rate := 0;
3432                   IF (p_v_trace_on = 'Y') THEN
3433                     fnd_file.new_line(fnd_file.log);
3434                     fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_ACCT_ENTITIES', 'UNIT') || ': ' || p_t_fee_as_items(i).unit_cd);
3435                     fnd_message.set_name ( 'IGS', 'IGS_FI_NO_ELM_RNG_RATE_MATCH');
3436                     fnd_file.put_line (fnd_file.log, fnd_message.get);
3437                     fnd_message.set_name('IGS', 'IGS_FI_CHG_RATE');
3438                     fnd_message.set_token('RATE', TO_CHAR(p_n_charge_rate) );
3439                     fnd_file.put_line (fnd_file.log, fnd_message.get);
3440                     fnd_file.new_line(fnd_file.log);
3441                   END IF;
3442               END IF;
3443 
3444               lv_cntrct_rt_apply := FALSE;
3445 
3446               OPEN c_cfar (p_t_fee_as_items(i).location_cd, p_v_der_attendance_type, p_v_der_prog_att_mode, p_v_der_govt_att_mode);
3447               FETCH c_cfar INTO       l_v_lower_nrml_rate_ovrd_ind,
3448                                       l_n_cfar_chg_rate;
3449 
3450               IF (c_cfar%FOUND) THEN
3451                 log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3452                             p_v_string => 'l_n_cfar_chg_rate: ' || l_n_cfar_chg_rate || ', l_v_lower_nrml_rate_ovrd_ind: ' || l_v_lower_nrml_rate_ovrd_ind);
3453                 IF (l_v_lower_nrml_rate_ovrd_ind = 'Y') THEN
3454                   -- the normal rate is used when it
3455                   -- is lower than the contract rate
3456                   IF (p_n_charge_rate > l_n_cfar_chg_rate) THEN
3457                     IF (p_trace_on = 'Y') THEN
3458                       fnd_message.set_name('IGS', 'IGS_FI_CONTRACT_RATE');
3459                       fnd_message.set_token('RATE', TO_CHAR(NVL(l_n_cfar_chg_rate, 0)) );
3460                       fnd_file.put_line (fnd_file.log, fnd_message.get);
3461                       fnd_message.set_name('IGS', 'IGS_FI_CHG_RATE');
3462                       fnd_message.set_token('RATE', TO_CHAR(NVL(l_n_charge_rate, 0)) );
3463                       fnd_file.put_line (fnd_file.log, fnd_message.get);
3464                     END IF;
3465                     lv_cntrct_rt_apply := TRUE;
3466                     p_n_charge_rate := l_n_cfar_chg_rate;
3467                     p_t_fee_as_items(i).chg_rate := p_n_charge_rate;
3468                     log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3469                                 p_v_string => 'The contract rate is lower than the charge rate, so the contract rate will be used. Chg Rate: ' || l_n_charge_rate);
3470                   END IF;
3471                 ELSE
3472                   -- Use the contract rate
3473                   lv_cntrct_rt_apply := TRUE;
3474                   p_n_charge_rate := l_n_cfar_chg_rate;
3475                   p_t_fee_as_items(i).chg_rate := p_n_charge_rate;
3476                   IF (p_trace_on = 'Y') THEN
3477                     fnd_message.set_name('IGS', 'IGS_FI_CONTRACT_RATE');
3478                     fnd_message.set_token('RATE', TO_CHAR(NVL(l_n_charge_rate, 0)) );
3479                     fnd_file.put_line (fnd_file.log, fnd_message.get);
3480                   END IF;
3481                   log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3482                               p_v_string => 'The contract rate will be used. Chg Rate: ' || l_n_charge_rate);
3483                 END IF;
3484 
3485               ELSE
3486                 log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3487                             p_v_string => 'No Contract Rate Found ..');
3488               END IF;
3489               -- attempt to find a second contract rate - only one record should be found
3490               FETCH c_cfar INTO l_v_lower_nrml_rate_ovrd_ind,
3491                                 l_n_cfar_chg_rate;
3492               IF (c_cfar%FOUND) THEN
3493                 CLOSE c_cfar;
3494                 IF g_v_wav_calc_flag = 'N' THEN
3495                   ROLLBACK TO fee_calc_sp;
3496                 END IF;
3497 
3498                 IF (p_trace_on = 'Y') THEN
3499                     fnd_message.set_name('IGS', 'IGS_FI_MULTI_CONTRACT_RT');
3500                     fnd_file.put_line (fnd_file.log, fnd_message.get);
3501                 END IF;
3502                 log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3503                             p_v_string => 'Raising e_one_record_expected.');
3504                 RAISE e_one_record_expected;
3505               END IF;
3506               CLOSE c_cfar;
3507 
3508               IF l_n_rate_factor < p_t_fee_as_items(i).chg_elements THEN
3509 
3510                 p_t_fee_as_items(i).amount := igs_ru_gen_003.rulp_clc_student_fee(p_n_rul_sequence_num,
3511                                                                         l_n_rate_factor, p_t_fee_as_items(i).chg_rate);
3512                 p_t_fee_as_items(i).rul_sequence_number := p_n_rul_sequence_num;
3513                 p_t_fee_as_items(i).residency_status_cd := p_v_der_residency_status_cd;
3514                 p_t_fee_as_items(i).class_standing := p_v_der_class_standing;
3515                 p_t_fee_as_items(i).unit_set_cd := p_v_der_unit_set_cd;
3516                 p_t_fee_as_items(i).us_version_number := p_n_der_us_version_num;
3517                 p_n_fee_amount := p_n_fee_amount + p_t_fee_as_items(i).amount;
3518                 l_n_rate_factor := 0;
3519                 EXIT;
3520               ELSE
3521                 p_t_fee_as_items(i).amount := igs_ru_gen_003.rulp_clc_student_fee(p_n_rul_sequence_num,
3522                                                                         p_t_fee_as_items(i).chg_elements, p_t_fee_as_items(i).chg_rate);
3523                 p_t_fee_as_items(i).rul_sequence_number := p_n_rul_sequence_num;
3524                 p_t_fee_as_items(i).residency_status_cd := p_v_der_residency_status_cd;
3525                 p_t_fee_as_items(i).class_standing := p_v_der_class_standing;
3526                 p_t_fee_as_items(i).unit_set_cd := p_v_der_unit_set_cd;
3527                 p_t_fee_as_items(i).us_version_number := p_n_der_us_version_num;
3528                 p_n_fee_amount := p_n_fee_amount + p_t_fee_as_items(i).amount;
3529                 l_n_rate_factor := l_n_rate_factor - p_t_fee_as_items(i).chg_elements;
3530               END IF;
3531             END IF;
3532           END LOOP;
3533         END IF;
3534 
3535        ELSIF (rec_elm_ranges.override_chg_method_type = 'INCREMENTAL') THEN
3536         l_n_previous_upper := 0;
3537         p_n_fee_amount := 0;
3538         l_n_rate_factor := l_n_summed_chg_elm;
3539 
3540         FOR rec_sub_elm_ranges IN cur_sub_elm_ranges(rec_elm_ranges.er_id)
3541         LOOP
3542           IF (l_n_loop_subelm_rng = 0) THEN
3543              IF (p_v_trace_on = 'Y') THEN
3544                fnd_file.new_line(fnd_file.log);
3545                fnd_message.set_name ( 'IGS', 'IGS_FI_SUB_ELM_RNG_MATCH');
3546                fnd_file.put_line (fnd_file.log, fnd_message.get);
3547                fnd_file.new_line(fnd_file.log);
3548              END IF;
3549              l_n_loop_subelm_rng := 1;
3550           END IF;
3551 
3552           IF (rec_sub_elm_ranges.sub_chg_method_code IS NOT NULL) THEN
3553              IF (p_v_trace_on = 'Y') THEN
3554                fnd_message.set_name('IGS', 'IGS_FI_OVRRIDE_CHG_METH_TYPE');
3555                fnd_message.set_token('CHG_MTHD', igs_fi_gen_gl.get_lkp_meaning('CHG_METHOD', rec_sub_elm_ranges.sub_chg_method_code));
3556                fnd_file.put_line (fnd_file.log, fnd_message.get);
3557              END IF;
3558           END IF;
3559 
3560           log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3561                       p_v_string => 'Sub Element Range. Lower ' || rec_sub_elm_ranges.sub_lower_range || ', Upper ' ||  rec_sub_elm_ranges.sub_upper_range);
3562 
3563           l_n_sub_rec_found := 1;
3564 
3565           IF ((g_c_fee_calc_mthd = g_v_primary_career) OR
3566              ((g_c_fee_calc_mthd <> g_v_primary_career) AND (p_v_fee_trigger_cat <> 'INSTITUTN'))) THEN
3567 
3568             OPEN c_resp_org_unit_cd(p_v_der_course_cd, p_n_der_crs_version_num);
3569             FETCH c_resp_org_unit_cd INTO l_v_derived_org_unit_cd;
3570             CLOSE c_resp_org_unit_cd;
3571             l_v_derived_location_cd := p_v_der_location_cd;
3572             l_v_fee_category := p_v_fee_cat;
3573 
3574           ELSE --If fee calculation method is not primary career and fee trigger category is Institution
3575             l_v_derived_org_unit_cd := NULL;
3576             l_v_derived_location_cd := NULL;
3577             l_v_fee_category := NULL;
3578           END IF;
3579 
3580 
3581           OPEN cur_sub_elm_rng_rates(rec_sub_elm_ranges.sub_er_id);
3582           FETCH cur_sub_elm_rng_rates INTO l_rec_sub_rates;
3583           IF (cur_sub_elm_rng_rates%NOTFOUND) THEN
3584           --Rate records not found
3585             CLOSE cur_sub_elm_rng_rates;
3586             IF (p_v_trace_on = 'Y') THEN
3587               fnd_message.set_name('IGS', 'IGS_FI_SUBELM_NO_RATE');
3588               fnd_file.put_line (fnd_file.log, fnd_message.get);
3589               fnd_file.new_line(fnd_file.log);
3590             END IF;
3591             p_n_charge_rate := 0;
3592             l_n_charge_rate := 0;
3593             log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3594                         p_v_string => 'Rates not defined for Sub Element Range');
3595 
3596             IF (l_b_first_rate_match = FALSE) THEN
3597               p_n_fee_amount  := 0;
3598               RETURN;
3599             END IF;
3600           ELSE
3601           --Rate records exist
3602             l_b_rate_matched := FALSE;
3603             --Loop through the sub element range rates
3604             WHILE (cur_sub_elm_rng_rates%FOUND)
3605             LOOP
3606 
3607                 IF (l_rec_sub_rates.org_party_id IS NOT NULL) THEN
3608                   l_v_party_number := finpl_get_org_unit_cd(l_rec_sub_rates.org_party_id);
3609                 ELSE
3610                   l_v_party_number := NULL;
3611                 END IF;
3612                 log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3613                             p_v_string => 'Calling finpl_ins_match_chg_rate');
3614 
3615                 IF ( finpl_ins_match_chg_rate (p_rate_location_cd             => l_rec_sub_rates.location_cd,
3616                                            p_rate_attendance_type         => l_rec_sub_rates.attendance_type,
3617                                            p_rate_attendance_mode         => l_rec_sub_rates.attendance_mode,
3618                                            p_rate_class_standing          => l_rec_sub_rates.class_standing,
3619                                            p_rate_course_cd               => l_rec_sub_rates.course_cd,
3620                                            p_rate_version_number          => l_rec_sub_rates.version_number,
3621                                            p_rate_org_unit_cd             => l_v_party_number,
3622                                            p_rate_residency_status_cd     => l_rec_sub_rates.residency_status_cd,
3623                                            p_derived_location_cd          => l_v_derived_location_cd,
3624                                            p_derived_attendance_type      => p_v_der_attendance_type,
3625                                            p_derived_govt_att_mode        => p_v_der_govt_att_mode,
3626                                            p_derived_prog_att_mode        => p_v_der_prog_att_mode,
3627                                            p_derived_class_standing       => p_v_der_class_standing,
3628                                            p_derived_course_cd            => p_v_der_course_cd,
3629                                            p_derived_version_number       => p_n_der_crs_version_num,
3630                                            p_derived_org_unit_cd          => l_v_derived_org_unit_cd,
3631                                            p_derived_residency_status_cd  => p_v_der_residency_status_cd,
3632                                            p_rate_unit_set_cd             => l_rec_sub_rates.unit_set_cd,
3633                                            p_rate_us_version_num          => l_rec_sub_rates.us_version_number,
3634                                            p_derived_unit_set_cd          => p_v_der_unit_set_cd,
3635                                            p_derived_us_version_num       => p_n_der_us_version_num,
3636                                            p_rate_unit_type_id            => NULL,
3637                                            p_derived_unit_type_id         => NULL,
3638                                            p_rate_unit_class              => NULL,
3639                                            p_derived_unit_class           => NULL,
3640                                            p_rate_unit_mode               => NULL,
3641                                            p_derived_unit_mode            => NULL,
3642                                            p_rate_unit_cd                 => NULL,
3643                                            p_derived_unit_cd              => NULL,
3644                                            p_rate_unit_version_num        => NULL,
3645                                            p_derived_unit_version_num     => NULL,
3646                                            p_rate_unit_level              => NULL,
3647                                            p_derived_unit_level           => NULL ) = TRUE ) THEN
3648                   log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3649                               p_v_string => 'Sub Element Range rate matches');
3650                   IF (p_v_trace_on = 'Y') THEN
3651                      fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'LOW_RANGE') || ': ' || TO_CHAR(rec_sub_elm_ranges.sub_lower_range));
3652                      fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'UPPER_RANGE') || ': ' || TO_CHAR(rec_sub_elm_ranges.sub_upper_range));
3653                      fnd_message.set_name('IGS', 'IGS_FI_LEV_CHG_RATE_NO');
3654                      fnd_message.set_token('LEVEL', l_rec_sub_rates.s_relation_type);
3655                      fnd_message.set_token('CH_RT', TO_CHAR(l_rec_sub_rates.chg_rate));
3656                      fnd_message.set_token('RT_NUM', TO_CHAR(l_rec_sub_rates.rate_number));
3657                      fnd_message.set_token('ATT_TYP', NVL(l_rec_sub_rates.ATTENDANCE_TYPE, l_v_lkp_all));
3658                      fnd_message.set_token('ATT_MOD', NVL(l_rec_sub_rates.ATTENDANCE_MODE, l_v_lkp_all));
3659                      fnd_message.set_token('LOC', NVL(l_rec_sub_rates.location_cd, l_v_lkp_all));
3660                      fnd_message.set_token('RES_STAT', NVL(l_rec_sub_rates.residency_status_cd, l_v_lkp_all));
3661                      fnd_message.set_token('ORG_UNIT_CD', NVL(l_v_party_number, l_v_lkp_all));
3662                      fnd_message.set_token('COURSE_CD', NVL(l_rec_sub_rates.course_cd, l_v_lkp_all));
3663                      fnd_message.set_token('VERSION', NVL(TO_CHAR(l_rec_sub_rates.version_number), l_v_lkp_all));
3664                      fnd_message.set_token('CLAS_STNDNG', NVL(l_rec_sub_rates.class_standing, l_v_lkp_all));
3665                      fnd_message.set_token('UNIT_SET_CD', NVL(l_rec_sub_rates.unit_set_cd, l_v_lkp_all));
3666                      fnd_message.set_token('US_VER', NVL(TO_CHAR(l_rec_sub_rates.us_version_number), l_v_lkp_all));
3667                      fnd_message.set_token('UNIT_TYP_CD', NVL(TO_CHAR(l_rec_sub_rates.unit_type_id), l_v_lkp_all));
3668                      fnd_message.set_token('UNIT_CLASS', NVL(l_rec_sub_rates.unit_class, l_v_lkp_all));
3669                      fnd_message.set_token('UNIT_MODE', NVL(l_rec_sub_rates.unit_mode, l_v_lkp_all));
3670                      fnd_message.set_token('UNIT_CODE', NVL(l_rec_sub_rates.unit_cd, l_v_lkp_all));
3671                      fnd_message.set_token('UNIT_VER_NUM', NVL(TO_CHAR(l_rec_sub_rates.unit_version_number), l_v_lkp_all));
3672                      fnd_message.set_token('UNIT_LEVEL', NVL(l_rec_sub_rates.unit_level, l_v_lkp_all));
3673                      fnd_file.put_line (fnd_file.log, fnd_message.get);
3674                      fnd_message.set_name('IGS', 'IGS_FI_FEEASS_RATE_MATCHES');
3675                      fnd_file.put_line (fnd_file.log, fnd_message.get);
3676                      fnd_file.new_line(fnd_file.log);
3677                   END IF;
3678 
3679                 --If the rate matches
3680                   l_n_charge_rate := l_rec_sub_rates.chg_rate;
3681                   l_b_rate_matched := TRUE;
3682                   l_b_first_rate_match := TRUE;
3683                   EXIT;
3684                 END IF; -- If rate is matched.
3685                 FETCH cur_sub_elm_rng_rates INTO l_rec_sub_rates;
3686             END LOOP; -- Loop across the sub element range rates
3687             CLOSE cur_sub_elm_rng_rates;
3688             --If rate is not matched
3689             IF (NOT l_b_rate_matched) THEN
3690               log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3691               p_v_string => 'No Rate Matched. Returning with 0 rate.');
3692               p_n_charge_rate := 0;
3693               l_n_charge_rate := 0;
3694               IF (l_b_first_rate_match = FALSE) THEN
3695                 p_n_fee_amount  := 0;
3696               END IF;
3697             END IF;
3698 
3699           END IF; --If sub element range rates defined
3700 
3701           lv_cntrct_rt_apply := FALSE;
3702 
3703           OPEN c_cfar (l_v_derived_location_cd, p_v_der_attendance_type, p_v_der_prog_att_mode, p_v_der_govt_att_mode);
3704           FETCH c_cfar INTO       l_v_lower_nrml_rate_ovrd_ind,
3705                                   l_n_cfar_chg_rate;
3706 
3707           IF (c_cfar%FOUND) THEN
3708             log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3709                         p_v_string => 'l_n_cfar_chg_rate: ' || l_n_cfar_chg_rate || ', l_v_lower_nrml_rate_ovrd_ind: ' || l_v_lower_nrml_rate_ovrd_ind);
3710             IF (l_v_lower_nrml_rate_ovrd_ind = 'Y') THEN
3711               -- the normal rate is used when it
3712               -- is lower than the contract rate
3713               IF (l_n_charge_rate > l_n_cfar_chg_rate) THEN
3714                 IF (p_trace_on = 'Y') THEN
3715                   fnd_message.set_name('IGS', 'IGS_FI_CONTRACT_RATE');
3716                   fnd_message.set_token('RATE', TO_CHAR(NVL(l_n_cfar_chg_rate, 0)) );
3717                   fnd_file.put_line (fnd_file.log, fnd_message.get);
3718                   fnd_message.set_name('IGS', 'IGS_FI_CHG_RATE');
3719                   fnd_message.set_token('RATE', TO_CHAR(NVL(l_n_charge_rate, 0)) );
3720                   fnd_file.put_line (fnd_file.log, fnd_message.get);
3721                 END IF;
3722                 lv_cntrct_rt_apply := TRUE;
3723                 l_n_charge_rate := l_n_cfar_chg_rate;
3724                 log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3725                             p_v_string => 'The contract rate is lower than the charge rate, so the contract rate will be used. Chg Rate: ' || l_n_charge_rate);
3726               END IF;
3727             ELSE
3728               -- Use the contract rate
3729               lv_cntrct_rt_apply := TRUE;
3730               l_n_charge_rate := l_n_cfar_chg_rate;
3731               IF (p_trace_on = 'Y') THEN
3732                 fnd_message.set_name('IGS', 'IGS_FI_CONTRACT_RATE');
3733                 fnd_message.set_token('RATE', TO_CHAR(NVL(l_n_charge_rate, 0)) );
3734                 fnd_file.put_line (fnd_file.log, fnd_message.get);
3735               END IF;
3736               log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3737                           p_v_string => 'The contract rate will be used. Chg Rate: ' || l_n_charge_rate);
3738             END IF;
3739 
3740           ELSE
3741             log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3742                         p_v_string => 'No Contract Rate Found ..');
3743           END IF;
3744           -- attempt to find a second contract rate - only one record should be found
3745           FETCH c_cfar INTO l_v_lower_nrml_rate_ovrd_ind,
3746                             l_n_cfar_chg_rate;
3747           IF (c_cfar%FOUND) THEN
3748             CLOSE c_cfar;
3749             IF g_v_wav_calc_flag = 'N' THEN
3750               ROLLBACK TO fee_calc_sp;
3751             END IF;
3752 
3753             IF (p_trace_on = 'Y') THEN
3754                 fnd_message.set_name('IGS', 'IGS_FI_MULTI_CONTRACT_RT');
3755                 fnd_file.put_line (fnd_file.log, fnd_message.get);
3756             END IF;
3757             log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3758                         p_v_string => 'Raising e_one_record_expected.');
3759             RAISE e_one_record_expected;
3760           END IF;
3761           CLOSE c_cfar;
3762 
3763 
3764           IF (l_n_summed_chg_elm > rec_sub_elm_ranges.sub_upper_range) THEN
3765 
3766             l_n_rate_factor := rec_sub_elm_ranges.sub_upper_range - l_n_previous_upper;
3767             IF (rec_sub_elm_ranges.sub_chg_method_code = gcst_flatrate) THEN
3768               p_n_fee_amount := p_n_fee_amount + igs_ru_gen_003.rulp_clc_student_fee(p_n_rul_sequence_num,1, l_n_charge_rate);
3769             ELSIF (rec_sub_elm_ranges.sub_chg_method_code IS NULL) THEN
3770               p_n_fee_amount := p_n_fee_amount + igs_ru_gen_003.rulp_clc_student_fee(p_n_rul_sequence_num, l_n_rate_factor, l_n_charge_rate);
3771             END IF;
3772 
3773           ELSE
3774 
3775             l_n_rate_factor := l_n_summed_chg_elm - l_n_previous_upper;
3776             IF (rec_sub_elm_ranges.sub_chg_method_code = gcst_flatrate) THEN
3777               p_n_fee_amount := p_n_fee_amount + igs_ru_gen_003.rulp_clc_student_fee(p_n_rul_sequence_num,1, l_n_charge_rate);
3778             ELSIF (rec_sub_elm_ranges.sub_chg_method_code IS NULL) THEN
3779               p_n_fee_amount := p_n_fee_amount + igs_ru_gen_003.rulp_clc_student_fee(p_n_rul_sequence_num, l_n_rate_factor, l_n_charge_rate);
3780             END IF;
3781             EXIT;
3782           END IF;
3783 
3784           l_n_previous_upper := rec_sub_elm_ranges.sub_upper_range;
3785 
3786         END LOOP;
3787         --Sub Element Ranges are not found
3788         IF l_n_sub_rec_found = 0 THEN
3789           p_n_charge_rate := 0;
3790           p_n_fee_amount  := 0;
3791 
3792           IF (p_v_trace_on = 'Y') THEN
3793             fnd_message.set_name('IGS', 'IGS_FI_SUBELM_NO_RANGE');
3794             fnd_file.put_line (fnd_file.log, fnd_message.get);
3795           END IF;
3796           RETURN;
3797 
3798         ELSE
3799           l_b_flag := FALSE;
3800           IF (p_n_called <> 1) THEN
3801              IF (p_v_fee_trigger_cat <> gcst_institutn) THEN
3802                 tbl_fai_unit_dtls.DELETE;
3803              END IF;
3804 
3805               FOR  i IN 1..p_t_fee_as_items.COUNT
3806               LOOP
3807                 IF (p_v_fee_trigger_cat <> gcst_institutn ) THEN
3808                     IF (p_t_fee_as_items(i).uoo_id IS NOT NULL AND l_v_ret_level = 'TEACH_PERIOD' AND g_c_predictive_ind = 'N' AND
3809                          NVL(p_t_fee_as_items(i).chg_elements,0) > 0) THEN
3810                       l_n_count := tbl_fai_unit_dtls.COUNT + 1;
3811                       tbl_fai_unit_dtls(l_n_count).fee_cat             :=  p_v_fee_cat;
3812                       tbl_fai_unit_dtls(l_n_count).course_cd           :=  p_v_der_course_cd;
3813                       tbl_fai_unit_dtls(l_n_count).crs_version_number  :=  p_n_der_crs_version_num;
3814                       tbl_fai_unit_dtls(l_n_count).unit_attempt_status :=  p_t_fee_as_items(i).unit_attempt_status;
3815                       tbl_fai_unit_dtls(l_n_count).org_unit_cd         :=  p_t_fee_as_items(i).org_unit_cd;
3816                       tbl_fai_unit_dtls(l_n_count).class_standing      :=  p_v_der_class_standing;
3817                       tbl_fai_unit_dtls(l_n_count).location_cd         :=  p_t_fee_as_items(i).location_cd;
3818                       tbl_fai_unit_dtls(l_n_count).uoo_id              :=  p_t_fee_as_items(i).uoo_id;
3819                       tbl_fai_unit_dtls(l_n_count).unit_set_cd         :=  p_v_der_unit_set_cd;
3820                       tbl_fai_unit_dtls(l_n_count).us_version_number   :=  p_n_der_us_version_num;
3821                       tbl_fai_unit_dtls(l_n_count).chg_elements        :=  p_t_fee_as_items(i).chg_elements;
3822                       tbl_fai_unit_dtls(l_n_count).unit_type_id        :=  p_t_fee_as_items(i).unit_type_id;
3823                       tbl_fai_unit_dtls(l_n_count).unit_class          :=  p_t_fee_as_items(i).unit_class;
3824                       tbl_fai_unit_dtls(l_n_count).unit_mode           :=  p_t_fee_as_items(i).unit_mode;
3825                       tbl_fai_unit_dtls(l_n_count).unit_cd             :=  p_t_fee_as_items(i).unit_cd;
3826                       tbl_fai_unit_dtls(l_n_count).unit_level          :=  p_t_fee_as_items(i).unit_level;
3827                       tbl_fai_unit_dtls(l_n_count).unit_version_number :=  p_t_fee_as_items(i).unit_version_number;
3828                     END IF;
3829                 END IF;
3830 
3831                 IF  p_t_fee_as_items(i).chg_elements >= 0 AND
3832                     p_t_fee_as_items(i).uoo_id IS NULL AND
3833                     p_t_fee_as_items(i).old_amount > 0 THEN
3834 
3835                       p_t_fee_as_items(i).amount := p_n_fee_amount;
3836                       l_b_flag := TRUE;
3837                       EXIT;
3838                 ELSE
3839                   p_t_fee_as_items(i).amount := 0;
3840                 END IF;
3841               END LOOP; --Loop Across the plsql table
3842 
3843               IF (l_b_flag = FALSE) THEN
3844 
3845                   gv_as_item_cntr := gv_as_item_cntr + 1;
3846                   p_t_fee_as_items(gv_as_item_cntr).person_id              := p_n_person_id;
3847                   p_t_fee_as_items(gv_as_item_cntr).status                 := 'I';
3848                   p_t_fee_as_items(gv_as_item_cntr).fee_type               := p_v_fee_type;
3849                   p_t_fee_as_items(gv_as_item_cntr).fee_cat                := p_v_fee_cat;
3850                   p_t_fee_as_items(gv_as_item_cntr).fee_cal_type           := p_v_fee_cal_type;
3851                   p_t_fee_as_items(gv_as_item_cntr).fee_ci_sequence_number := p_n_fee_ci_sequence_num;
3852                   p_t_fee_as_items(gv_as_item_cntr).course_cd              := p_v_der_course_cd;
3853                   p_t_fee_as_items(gv_as_item_cntr).crs_version_number     := l_n_crs_version_num;
3854                   p_t_fee_as_items(gv_as_item_cntr).description            := p_v_fee_description;
3855                   p_t_fee_as_items(gv_as_item_cntr).chg_method_type        := 'INCREMENTAL';
3856                   p_t_fee_as_items(gv_as_item_cntr).old_chg_elements       := 0;
3857                   p_t_fee_as_items(gv_as_item_cntr).chg_elements           := NVL(p_n_chg_elements,0);
3858                   p_t_fee_as_items(gv_as_item_cntr).old_amount             := 0;
3859                   p_t_fee_as_items(gv_as_item_cntr).amount                 := NVL(p_n_fee_amount,0);
3860                   p_t_fee_as_items(gv_as_item_cntr).unit_attempt_status    := NULL;
3861                   p_t_fee_as_items(gv_as_item_cntr).location_cd            := l_v_derived_location_cd;
3862                   p_t_fee_as_items(gv_as_item_cntr).old_eftsu              := NULL;
3863                   p_t_fee_as_items(gv_as_item_cntr).eftsu                  := NULL;
3864                   p_t_fee_as_items(gv_as_item_cntr).old_credit_points      := NULL;
3865                   p_t_fee_as_items(gv_as_item_cntr).credit_points          := NULL;
3866                   p_t_fee_as_items(gv_as_item_cntr).org_unit_cd            := l_v_derived_org_unit_cd;
3867                   p_t_fee_as_items(gv_as_item_cntr).uoo_id                 := NULL;
3868                   p_t_fee_as_items(gv_as_item_cntr).chg_rate               := NULL;
3869                   p_t_fee_as_items(gv_as_item_cntr).rul_sequence_number    := p_n_rul_sequence_num;
3870                   p_t_fee_as_items(gv_as_item_cntr).unit_set_cd            := p_v_der_unit_set_cd;
3871                   p_t_fee_as_items(gv_as_item_cntr).us_version_number      := p_n_der_us_version_num;
3872                   p_t_fee_as_items(gv_as_item_cntr).residency_status_cd    := p_v_der_residency_status_cd;
3873                   p_t_fee_as_items(gv_as_item_cntr).class_standing         := p_v_der_class_standing;
3874 
3875               END IF;
3876           END IF;
3877         END IF;
3878       END IF;
3879     END IF;
3880   END LOOP;
3881 
3882   IF l_n_record_found = 0 THEN
3883     log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3884                 p_v_string => 'Global Element Ranges not defined.' );
3885     p_n_charge_rate  := NULL;
3886     p_n_fee_amount   := NULL;
3887     RETURN;
3888   END IF;
3889 
3890   IF l_n_match_elm_rng = 0 THEN
3891 
3892        log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3893                    p_v_string => 'No Element Range Matches. IGS_FI_NO_ELEMNTRNG_MATCH' );
3894        p_n_charge_rate  := 0;
3895        p_n_fee_amount   := 0;
3896        IF (p_v_trace_on = 'Y') THEN
3897          fnd_message.set_name ( 'IGS', 'IGS_FI_NO_ELEMNTRNG_MATCH');
3898          fnd_file.put_line (fnd_file.log, fnd_message.get);
3899          fnd_message.set_name('IGS', 'IGS_FI_CHG_RATE');
3900          fnd_message.set_token('RATE', TO_CHAR(p_n_charge_rate) );
3901          fnd_file.put_line (fnd_file.log, fnd_message.get);
3902        END IF;
3903        RETURN;
3904   END IF;
3905 
3906 EXCEPTION
3907     WHEN e_one_record_expected THEN
3908         log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3909                     p_v_string => 'From Exception Handler of e_one_record_expected.');
3910         FND_MESSAGE.SET_NAME('IGS','IGS_GE_UNHANDLED_EXP');
3911         FND_MESSAGE.SET_TOKEN('NAME','IGS_FI_PRC_FEE_ASS.FINPL_PRC_ELEMENT_RANGES-'||SUBSTR(sqlerrm,1,500));
3912         IGS_GE_MSG_STACK.ADD;
3913         App_Exception.Raise_Exception;
3914 
3915    WHEN OTHERS THEN
3916         log_to_fnd( p_v_module => 'finpl_prc_element_ranges',
3917                     p_v_string => 'From exception handler of When Others.');
3918         Fnd_Message.Set_Name ('IGS', 'IGS_GE_UNHANDLED_EXP');
3919         Fnd_Message.Set_Token('NAME','igs_fi_prc_fee_ass.finpl_prc_element_ranges-'||SUBSTR(sqlerrm,1,500));
3920         IGS_GE_MSG_STACK.ADD;
3921         App_Exception.Raise_Exception;
3922 END finpl_prc_element_ranges;
3923 
3924 BEGIN
3925 
3926 BEGIN
3927 
3928 log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
3929             p_v_string => 'Entered finp_clc_ass_amnt. Parameters are: ' ||
3930                           TO_CHAR(p_effective_dt, 'DD-MON-YYYY') || ', ' || p_person_id || ', ' || p_course_cd || ', ' || p_course_version_number
3931                            || ', ' || p_course_attempt_status || ', ' || p_fee_type || ', ' || p_fee_cal_type || ', ' || p_fee_ci_sequence_number
3932                            || ', ' || p_fee_cat|| ', ' ||p_s_fee_type|| ', ' ||p_s_fee_trigger_cat|| ', ' ||p_rul_sequence_number|| ', ' ||
3933                            p_charge_method|| ', ' ||p_location_cd|| ', ' ||p_attendance_type|| ', ' ||p_attendance_mode
3934                            || ', ' || TO_CHAR(p_creation_dt, 'DD-MON-YYYY') || ', ' ||
3935                            p_charge_elements|| ', ' ||p_fee_assessment|| ', ' ||p_charge_rate|| ', ' || p_c_career);
3936 
3937 IF (g_c_predictive_ind = 'Y') THEN
3938    v_derived_unit_type_id       :=   NULL;
3939    v_derived_unit_class         :=   NULL;
3940    v_derived_unit_mode          :=   NULL;
3941    v_derived_unit_cd            :=   NULL;
3942    v_derived_unit_version_num   :=   NULL;
3943    v_derived_unit_level         :=   NULL;
3944 END IF;
3945 
3946 -- This function calculates the assessment amount--finp_clc_ass_amnt
3947 lv_charge_override := FALSE;
3948 l_b_elm_ranges_defined :=  FALSE;
3949 l_b_derived        := FALSE;
3950 l_ch_ovr_exist     := FALSE;
3951 l_b_elm_rng := FALSE;
3952 l_b_pred    := FALSE;
3953 
3954 IF ((p_s_fee_type = gcst_tuition OR p_s_fee_type = gcst_other OR p_s_fee_type  = gcst_tuition_other OR p_s_fee_type = g_v_audit)) THEN
3955 
3956   --The value of parameter p_n_called will be 1 if it is called from finpl_chk_debt_ret_sched for retention.
3957   --The value of parameter p_n_called will be 0 if it is called from finpl_prc_fee_cat_fee_liab for calculation of actual amount.
3958    IF (p_n_called = 1) THEN
3959       l_n_called := 1;
3960       l_n_count := tbl_fee_as_items_dummy.COUNT;
3961       l_v_trace_on := 'N';
3962 --When this function is called for retention the plsql table tbl_fee_as_items_dummy is used. No messages are logged.
3963    ELSE
3964       l_n_called := 0;
3965       l_n_count := t_fee_as_items.COUNT;
3966       l_v_trace_on := p_trace_on;
3967 --When this function is called for actual amount calculation the plsql table t_fee_as_items is used.
3968    END IF;
3969 
3970     FOR i IN 1..l_n_count
3971     LOOP
3972       IF ((p_n_called = 1 AND tbl_fee_as_items_dummy(i).chg_elements > 0) OR
3973             (p_n_called = 0 AND NVL(t_fee_as_items(i).chg_elements,0) > 0)) THEN
3974 
3975        IF (g_c_predictive_ind = 'N') THEN
3976 
3977           IF (l_b_derived = FALSE) THEN
3978              l_b_derived := TRUE;
3979              -- Perform 2.3.1 Get Derived Values
3980              -- function call has been modified to pass the prior fee calendar instance
3981              -- as apart of the early/prior assessment changes for fee calc DLD (bug 1851586)
3982              log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
3983                          p_v_string => 'Actual Mode: Deriving Attributes by calling finpl_get_derived_values..');
3984              v_derived_location_cd := p_location_cd;
3985              IF (finpl_get_derived_values(
3986                       p_person_id,
3987                       p_course_cd,
3988                       p_effective_dt,
3989                       p_fee_cal_type,
3990                       p_fee_ci_sequence_number,
3991                       p_fee_type,
3992                       p_s_fee_trigger_cat,
3993                       l_v_trace_on,
3994                       v_derived_attendance_type,
3995                       v_derived_govt_att_mode,
3996                       l_v_derived_prog_att_mode,
3997                       v_derived_residency_status_cd,
3998                       v_derived_class_standing,
3999                       p_c_career,
4000                       v_derived_unit_set_cd,
4001                       v_derived_us_version_num) = FALSE) THEN
4002                RETURN FALSE;
4003              END IF;
4004           END IF;
4005           IF (g_c_fee_calc_mthd <> g_v_primary_career) THEN
4006                 IF p_s_fee_trigger_cat <> 'INSTITUTN' THEN
4007                        -- Course Code is null for Institution type of Fee
4008                        -- Course_Cd is derived irrespective of Charge Override, hence brought out
4009                        -- from the loop 'v_fterrv_rec.override_chg_method_type IS NOT NULL'
4010                        v_derived_course_cd := p_course_cd;
4011                        l_n_crs_version_num := p_course_version_number;
4012 
4013                        IF (p_n_called = 1) THEN
4014                          OPEN c_org_unit_sec_cd(tbl_fee_as_items_dummy(i).uoo_id);
4015                        ELSE
4016                          OPEN c_org_unit_sec_cd(t_fee_as_items(i).uoo_id);
4017                        END IF;
4018                        FETCH c_org_unit_sec_cd INTO v_derived_org_unit_cd, v_derived_location_cd;
4019                        CLOSE c_org_unit_sec_cd;
4020 
4021                 ELSE
4022                        l_v_inst_course_cd := p_course_cd;
4023                        IF (p_n_called = 1) THEN
4024                          OPEN c_org_unit_sec_cd(tbl_fee_as_items_dummy(i).uoo_id);
4025                        ELSE
4026                          OPEN c_org_unit_sec_cd(t_fee_as_items(i).uoo_id);
4027                        END IF;
4028                        FETCH c_org_unit_sec_cd INTO l_v_inst_org_unit_cd, l_v_inst_location_cd;
4029                        CLOSE c_org_unit_sec_cd;
4030 
4031                        -- For Institution type Fee, following attributes are Null
4032                        v_derived_course_cd := NULL;
4033                        l_n_crs_version_num := NULL;
4034                        v_derived_org_unit_cd := NULL;
4035                        v_derived_location_cd := NULL;
4036                 END IF;
4037 
4038           ELSE --g_c_fee_calc_mthd is 'PRIMARY_CAREER'
4039                    v_derived_course_cd := p_course_cd;
4040                    l_n_crs_version_num := p_course_version_number;
4041                    IF (p_n_called = 1) THEN
4042                      OPEN c_org_unit_sec_cd(tbl_fee_as_items_dummy(i).uoo_id);
4043                    ELSE
4044                      OPEN c_org_unit_sec_cd(t_fee_as_items(i).uoo_id);
4045                    END IF;
4046                    FETCH c_org_unit_sec_cd INTO v_derived_org_unit_cd, v_derived_location_cd;
4047                    CLOSE c_org_unit_sec_cd;
4048 
4049           END IF; -- End if for fee calc mthd <> Primary Career
4050           log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
4051                       p_v_string => 'Actual Case: Derived Course Cd: ' || v_derived_course_cd || ', Org Unit:' || v_derived_org_unit_cd
4052                                     || ', Location Cd: ' || v_derived_location_cd );
4053 
4054        ELSIF (g_c_predictive_ind = 'Y') THEN
4055            IF l_b_pred = FALSE THEN
4056               l_b_pred := TRUE;
4057               log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
4058                           p_v_string => 'Predictive Mode: Deriving Attributes..');
4059               v_derived_location_cd := p_location_cd;
4060               l_n_crs_version_num := p_course_version_number;
4061               v_derived_attendance_type := p_attendance_type;
4062               OPEN c_am (p_attendance_mode);
4063               FETCH c_am INTO v_derived_govt_att_mode;
4064               CLOSE c_am;
4065               l_v_derived_prog_att_mode := p_attendance_mode;
4066               v_derived_residency_status_cd:= get_stdnt_res_status_cd(p_person_id);
4067               get_stdnt_unit_set_dtls( p_n_person_id => p_person_id,
4068                                        p_v_course_cd => p_course_cd,
4069                                        p_v_s_fee_trigger_cat => p_s_fee_trigger_cat,
4070                                        p_v_unit_set_cd => v_derived_unit_set_cd,
4071                                        p_n_unit_set_ver_num => v_derived_us_version_num );
4072            END IF;
4073            IF (p_n_called = 1) THEN
4074              v_derived_course_cd := tbl_fee_as_items_dummy(i).course_cd;
4075              v_derived_org_unit_cd := tbl_fee_as_items_dummy(i).org_unit_cd;
4076            ELSE
4077              v_derived_course_cd := t_fee_as_items(i).course_cd;
4078              v_derived_org_unit_cd := t_fee_as_items(i).org_unit_cd;
4079            END IF;
4080            log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
4081                        p_v_string => 'Predictive Mode: Derived Values are: Location: ' || v_derived_location_cd ||
4082                                      ', AT: ' || v_derived_attendance_type || ', AM: ' || p_attendance_mode ||
4083                                      ', Govt AM: ' || v_derived_govt_att_mode || ', Crs Cd: ' || v_derived_course_cd ||
4084                                      ', Org Unit Cd: ' || v_derived_org_unit_cd || ', Res Code: ' || v_derived_residency_status_cd ||
4085                                      ', Unit Set Cd: ' || v_derived_unit_set_cd || ', Unit Set Ver: ' || v_derived_us_version_num );
4086 
4087        END IF;
4088 
4089        v_residency_status_cd := v_derived_residency_status_cd;
4090        v_class_standing := v_derived_class_standing;
4091        IF (p_charge_method = gcst_flatrate) THEN
4092               log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
4093                           p_v_string => 'Calling finpl_find_far directly as FLAT RATE');
4094               IF (p_n_called = 1) THEN
4095 
4096                 finpl_find_far(
4097                       p_person_id,
4098                       p_course_cd,
4099                       p_fee_cat,
4100                       p_fee_cal_type,
4101                       p_fee_ci_sequence_number,
4102                       p_fee_type,
4103                       p_location_cd,
4104                       p_effective_dt,
4105                       p_s_fee_trigger_cat,
4106                       tbl_fee_as_items_dummy(i).location_cd,
4107                       v_derived_attendance_type,
4108                       v_derived_govt_att_mode,
4109                       l_v_derived_prog_att_mode,
4110                       l_v_trace_on,
4111                       v_derived_residency_status_cd,
4112                       tbl_fee_as_items_dummy(i).org_unit_cd,
4113                       tbl_fee_as_items_dummy(i).course_cd,
4114                       p_course_version_number,
4115                       v_derived_class_standing,
4116                       v_charge_rate,
4117                       v_derived_unit_set_cd,
4118                       v_derived_us_version_num,
4119                       tbl_fee_as_items_dummy(i).unit_type_id,
4120                       tbl_fee_as_items_dummy(i).unit_class,
4121                       tbl_fee_as_items_dummy(i).unit_mode,
4122                       tbl_fee_as_items_dummy(i).unit_cd,
4123                       tbl_fee_as_items_dummy(i).unit_version_number,
4124                       tbl_fee_as_items_dummy(i).unit_level
4125                       ); -- out
4126 
4127                   tbl_fee_as_items_dummy(i).chg_rate := v_charge_rate;
4128               ELSE
4129                 finpl_find_far(
4130                       p_person_id,
4131                       p_course_cd,
4132                       p_fee_cat,
4133                       p_fee_cal_type,
4134                       p_fee_ci_sequence_number,
4135                       p_fee_type,
4136                       p_location_cd,
4137                       p_effective_dt,
4138                       p_s_fee_trigger_cat,
4139                       t_fee_as_items(i).location_cd,
4140                       v_derived_attendance_type,
4141                       v_derived_govt_att_mode,
4142                       l_v_derived_prog_att_mode,
4143                       l_v_trace_on,
4144                       v_derived_residency_status_cd,
4145                       t_fee_as_items(i).org_unit_cd,
4146                       t_fee_as_items(i).course_cd,
4147                       p_course_version_number,
4148                       v_derived_class_standing,
4149                       v_charge_rate,
4150                       v_derived_unit_set_cd,
4151                       v_derived_us_version_num,
4152                       t_fee_as_items(i).unit_type_id,
4153                       t_fee_as_items(i).unit_class,
4154                       t_fee_as_items(i).unit_mode,
4155                       t_fee_as_items(i).unit_cd,
4156                       t_fee_as_items(i).unit_version_number,
4157                       t_fee_as_items(i).unit_level
4158                       ); -- out
4159 
4160                   t_fee_as_items(i).chg_rate := v_charge_rate;
4161 
4162               END IF;
4163 
4164          ELSIF (p_charge_method IN (gcst_eftsu, gcst_crpoint, gcst_perunit)) THEN
4165             IF (l_b_elm_rng = FALSE) THEN
4166                l_b_elm_rng := TRUE;
4167                --to get fee type description
4168                OPEN  c_fee_type(p_fee_type);
4169                FETCH c_fee_type INTO v_fee_type_description;
4170                CLOSE c_fee_type;
4171 
4172                IF (p_n_called = 1) THEN
4173                   log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
4174                            p_v_string => 'Calling finpl_prc_element_ranges with tbl_fee_as_item2');
4175                   finpl_prc_element_ranges(
4176                                p_n_person_id               => p_person_id,
4177                                p_v_fee_cat                 => p_fee_cat,
4178                                p_v_fee_type                => p_fee_type,
4179                                p_v_fee_cal_type            => p_fee_cal_type,
4180                                p_n_fee_ci_sequence_num     => p_fee_ci_sequence_number,
4181                                p_v_fee_trigger_cat         => p_s_fee_trigger_cat,
4182                                p_n_rul_sequence_num        => p_rul_sequence_number,
4183                                p_v_der_course_cd           => v_derived_course_cd,
4184                                p_n_der_crs_version_num     => p_course_version_number,
4185                                p_v_der_location_cd         => v_derived_location_cd,
4186                                p_v_der_attendance_type     => v_derived_attendance_type,
4187                                p_v_der_govt_att_mode       => v_derived_govt_att_mode,
4188                                p_v_der_prog_att_mode       => l_v_derived_prog_att_mode,
4189                                p_v_der_class_standing      => v_class_standing,
4190                                p_v_der_org_unit_cd         => v_derived_org_unit_cd,
4191                                p_v_der_residency_status_cd => v_residency_status_cd,
4192                                p_v_der_unit_set_cd         => v_derived_unit_set_cd,
4193                                p_n_der_us_version_num      => v_derived_us_version_num,
4194                                p_v_fee_description         => v_fee_type_description,
4195                                p_v_elm_rng_order_name      => p_elm_rng_order_name,
4196                                p_n_chg_elements            => p_charge_elements,
4197                                p_n_fee_amount              => p_fee_assessment,
4198                                p_n_charge_rate             => v_charge_rate,
4199                                p_t_fee_as_items            => tbl_fee_as_items_dummy,
4200                                p_v_trace_on                => l_v_trace_on,
4201                                p_n_element_cap             => p_n_max_chg_elements,
4202                                p_n_called                  => p_n_called
4203                                );
4204                ELSE
4205                   log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
4206                            p_v_string => 'Calling finpl_prc_element_ranges with t_fee_as_items');
4207                  finpl_prc_element_ranges(
4208                                p_n_person_id               => p_person_id,
4209                                p_v_fee_cat                 => p_fee_cat,
4210                                p_v_fee_type                => p_fee_type,
4211                                p_v_fee_cal_type            => p_fee_cal_type,
4212                                p_n_fee_ci_sequence_num     => p_fee_ci_sequence_number,
4213                                p_v_fee_trigger_cat         => p_s_fee_trigger_cat,
4214                                p_n_rul_sequence_num        => p_rul_sequence_number,
4215                                p_v_der_course_cd           => v_derived_course_cd,
4216                                p_n_der_crs_version_num     => p_course_version_number,
4217                                p_v_der_location_cd         => v_derived_location_cd,
4218                                p_v_der_attendance_type     => v_derived_attendance_type,
4219                                p_v_der_govt_att_mode       => v_derived_govt_att_mode,
4220                                p_v_der_prog_att_mode       => l_v_derived_prog_att_mode,
4221                                p_v_der_class_standing      => v_class_standing,
4222                                p_v_der_org_unit_cd         => v_derived_org_unit_cd,
4223                                p_v_der_residency_status_cd => v_residency_status_cd,
4224                                p_v_der_unit_set_cd         => v_derived_unit_set_cd,
4225                                p_n_der_us_version_num      => v_derived_us_version_num,
4226                                p_v_fee_description         => v_fee_type_description,
4227                                p_v_elm_rng_order_name      => p_elm_rng_order_name,
4228                                p_n_chg_elements            => p_charge_elements,
4229                                p_n_fee_amount              => p_fee_assessment,
4230                                p_n_charge_rate             => v_charge_rate,
4231                                p_t_fee_as_items            => t_fee_as_items,
4232                                p_v_trace_on                => l_v_trace_on,
4233                                p_n_element_cap             => p_n_max_chg_elements,
4234                                p_n_called                  => p_n_called
4235                                );
4236 
4237                END IF;
4238 
4239               IF (v_charge_rate IS NULL AND p_fee_assessment IS NULL) THEN
4240                  l_b_elm_ranges_defined := FALSE;
4241               ELSE
4242                  l_b_elm_ranges_defined := TRUE;
4243                  EXIT;
4244               END IF;
4245             END IF;
4246             IF (l_b_elm_ranges_defined = FALSE) THEN
4247                 -------------------------------
4248                 -- No Element Range is defined
4249                 -------------------------------
4250                 -- match derived attributes from Fee Assessessment Rates table.
4251                 log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
4252                             p_v_string => 'No Element Ranges Defined. Calling finpl_find_far');
4253                 IF (p_n_called = 1) THEN
4254                    finpl_find_far(
4255                         p_person_id,
4256                         p_course_cd,
4257                         p_fee_cat,
4258                         p_fee_cal_type,
4259                         p_fee_ci_sequence_number,
4260                         p_fee_type,
4261                         p_location_cd,
4262                         p_effective_dt,
4263                         p_s_fee_trigger_cat,
4264                         tbl_fee_as_items_dummy(i).location_cd,
4265                         v_derived_attendance_type,
4266                         v_derived_govt_att_mode,
4267                         l_v_derived_prog_att_mode,
4268                         l_v_trace_on,
4269                         v_derived_residency_status_cd,
4270                         tbl_fee_as_items_dummy(i).org_unit_cd,
4271                         tbl_fee_as_items_dummy(i).course_cd,
4272                         p_course_version_number,
4273                         v_derived_class_standing,
4274                         v_charge_rate,
4275                         v_derived_unit_set_cd,
4276                         v_derived_us_version_num,
4277                         tbl_fee_as_items_dummy(i).unit_type_id,
4278                         tbl_fee_as_items_dummy(i).unit_class,
4279                         tbl_fee_as_items_dummy(i).unit_mode,
4280                         tbl_fee_as_items_dummy(i).unit_cd,
4281                         tbl_fee_as_items_dummy(i).unit_version_number,
4282                         tbl_fee_as_items_dummy(i).unit_level
4283                         );
4284                    tbl_fee_as_items_dummy(i).chg_rate := v_charge_rate;
4285                 ELSE
4286                    finpl_find_far(
4287                         p_person_id,
4288                         p_course_cd,
4289                         p_fee_cat,
4290                         p_fee_cal_type,
4291                         p_fee_ci_sequence_number,
4292                         p_fee_type,
4293                         p_location_cd,
4294                         p_effective_dt,
4295                         p_s_fee_trigger_cat,
4296                         t_fee_as_items(i).location_cd,
4297                         v_derived_attendance_type,
4298                         v_derived_govt_att_mode,
4299                         l_v_derived_prog_att_mode,
4300                         l_v_trace_on,
4301                         v_derived_residency_status_cd,
4302                         t_fee_as_items(i).org_unit_cd,
4303                         t_fee_as_items(i).course_cd,
4304                         p_course_version_number,
4305                         v_derived_class_standing,
4306                         v_charge_rate,
4307                         v_derived_unit_set_cd,
4308                         v_derived_us_version_num,
4309                         t_fee_as_items(i).unit_type_id,
4310                         t_fee_as_items(i).unit_class,
4311                         t_fee_as_items(i).unit_mode,
4312                         t_fee_as_items(i).unit_cd,
4313                         t_fee_as_items(i).unit_version_number,
4314                         t_fee_as_items(i).unit_level
4315                         );
4316                    t_fee_as_items(i).chg_rate := v_charge_rate;
4317 
4318                 END IF;
4319             END IF;
4320        END IF;
4321 
4322        lv_cntrct_rt_apply := FALSE;
4323 
4324        -- Check if a contract fee assessment rate is to apply
4325        -- If the Profile is Nominated, Rate's AM is compared against Nominated Program AM.
4326        --                   Derived, Derived Govt AM is compared against Govt AM mapped to Rate's AM. (Bug# 3784618)
4327        IF (p_n_called = 1) THEN
4328          log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
4329                      p_v_string => 'Calling c_cfar. Parameters: ' || tbl_fee_as_items_dummy(i).location_cd
4330                                     || ','||v_derived_attendance_type ||','||l_v_derived_prog_att_mode ||','||v_derived_govt_att_mode);
4331        ELSE
4332          log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
4333                      p_v_string => 'Calling c_cfar. Parameters: ' || t_fee_as_items(i).location_cd
4334                                     || ','||v_derived_attendance_type ||','||l_v_derived_prog_att_mode ||','||v_derived_govt_att_mode);
4335        END IF;
4336 
4337        IF (p_n_called = 1) THEN
4338          OPEN c_cfar (tbl_fee_as_items_dummy(i).location_cd, v_derived_attendance_type, l_v_derived_prog_att_mode, v_derived_govt_att_mode);
4339        ELSE
4340          OPEN c_cfar (t_fee_as_items(i).location_cd, v_derived_attendance_type, l_v_derived_prog_att_mode, v_derived_govt_att_mode);
4341        END IF;
4342 
4343        FETCH c_cfar INTO       v_lower_nrml_rate_ovrd_ind,
4344                                v_cfar_chg_rate;
4345 
4346 
4347        IF (c_cfar%FOUND) THEN
4348          log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
4349                      p_v_string => 'v_cfar_chg_rate: ' || v_cfar_chg_rate || ', v_lower_nrml_rate_ovrd_ind: ' || v_lower_nrml_rate_ovrd_ind);
4350          IF (v_lower_nrml_rate_ovrd_ind = 'Y') THEN
4351            -- the normal rate is used when it
4352            -- is lower than the contract rate
4353            IF (v_charge_rate > v_cfar_chg_rate) THEN
4354              IF (l_v_trace_on = 'Y') THEN
4355                fnd_message.set_name('IGS', 'IGS_FI_CONTRACT_RATE');
4356                fnd_message.set_token('RATE', TO_CHAR(NVL(v_cfar_chg_rate, 0)) );
4357                fnd_file.put_line (fnd_file.log, fnd_message.get);
4358                fnd_message.set_name('IGS', 'IGS_FI_CHG_RATE');
4359                fnd_message.set_token('RATE', TO_CHAR(NVL(v_charge_rate, 0)) );
4360                fnd_file.put_line (fnd_file.log, fnd_message.get);
4361              END IF;
4362              lv_cntrct_rt_apply := TRUE;
4363              v_charge_rate := v_cfar_chg_rate;
4364              IF (p_n_called = 1) THEN
4365                tbl_fee_as_items_dummy(i).chg_rate := v_charge_rate;
4366              ELSE
4367                t_fee_as_items(i).chg_rate := v_charge_rate;
4368              END IF;
4369              log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
4370                          p_v_string => 'The contract rate is lower than the charge rate, so the contract rate will be used. Chg Rate: ' || v_charge_rate);
4371            END IF;
4372          ELSE
4373            -- Use the contract rate
4374            lv_cntrct_rt_apply := TRUE;
4375            v_charge_rate := v_cfar_chg_rate;
4376            IF (p_n_called = 1) THEN
4377              tbl_fee_as_items_dummy(i).chg_rate := v_charge_rate;
4378            ELSE
4379              t_fee_as_items(i).chg_rate := v_charge_rate;
4380            END IF;
4381            IF (l_v_trace_on = 'Y') THEN
4382              fnd_message.set_name('IGS', 'IGS_FI_CONTRACT_RATE');
4383              fnd_message.set_token('RATE', TO_CHAR(NVL(v_charge_rate, 0)) );
4384              fnd_file.put_line (fnd_file.log, fnd_message.get);
4385            END IF;
4386            log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
4387                        p_v_string => 'The contract rate will be used. Chg Rate: ' || v_charge_rate);
4388          END IF;
4389 
4390        ELSE
4391          log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
4392                      p_v_string => 'No Contract Rate Found ..');
4393        END IF;
4394        -- attempt to find a second contract rate - only one record should be found
4395        FETCH c_cfar INTO v_lower_nrml_rate_ovrd_ind,
4396                          v_cfar_chg_rate;
4397        IF (c_cfar%FOUND) THEN
4398          CLOSE c_cfar;
4399          IF g_v_wav_calc_flag = 'N' THEN
4400            ROLLBACK TO fee_calc_sp;
4401          END IF;
4402 
4403          IF (l_v_trace_on = 'Y') THEN
4404              fnd_message.set_name('IGS', 'IGS_FI_MULTI_CONTRACT_RT');
4405              fnd_file.put_line (fnd_file.log, fnd_message.get);
4406          END IF;
4407          log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
4408                      p_v_string => 'Raising e_one_record_expected.');
4409          RAISE e_one_record_expected;
4410        END IF;
4411        CLOSE c_cfar;
4412 
4413        IF (p_n_called = 1) THEN
4414            lv_fee_assessment := igs_ru_gen_003.rulp_clc_student_fee( p_rul_sequence_number,
4415                                                                      tbl_fee_as_items_dummy(i).chg_elements,
4416                                                                      tbl_fee_as_items_dummy(i).chg_rate);
4417 
4418            tbl_fee_as_items_dummy(i).amount                := NVL(lv_fee_assessment,0);
4419            tbl_fee_as_items_dummy(i).rul_sequence_number   := p_rul_sequence_number;
4420            tbl_fee_as_items_dummy(i).residency_status_cd   := v_residency_status_cd ;
4421            tbl_fee_as_items_dummy(i).class_standing        := v_class_standing ;
4422            p_fee_assessment := NVL(p_fee_assessment,0) + NVL(tbl_fee_as_items_dummy(i).amount,0);
4423 
4424            tbl_fee_as_items_dummy(i).unit_set_cd           := v_derived_unit_set_cd;
4425            tbl_fee_as_items_dummy(i).us_version_number     := v_derived_us_version_num;
4426        ELSE
4427            lv_fee_assessment := igs_ru_gen_003.rulp_clc_student_fee( p_rul_sequence_number,
4428                                                                      t_fee_as_items(i).chg_elements,
4429                                                                      t_fee_as_items(i).chg_rate);
4430 
4431            t_fee_as_items(i).amount                := NVL(lv_fee_assessment,0);
4432            t_fee_as_items(i).rul_sequence_number   := p_rul_sequence_number;
4433            t_fee_as_items(i).residency_status_cd   := v_residency_status_cd ;
4434            t_fee_as_items(i).class_standing        := v_class_standing ;
4435            p_fee_assessment := NVL(p_fee_assessment,0) + NVL(t_fee_as_items(i).amount,0);
4436 
4437            t_fee_as_items(i).unit_set_cd           := v_derived_unit_set_cd;
4438            t_fee_as_items(i).us_version_number     := v_derived_us_version_num;
4439        END IF;
4440       END IF;
4441     END LOOP;
4442 END IF;
4443 
4444 p_charge_rate := v_charge_rate;
4445 
4446  log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
4447              p_v_string => 'End of finp_clc_ass_amnt. Out - Creation Dt: ' || TO_CHAR(p_creation_dt, 'DD-MON-YYYY')
4448                             || ', Chg Elements: ' || p_charge_elements || ', Fee As Amount: ' || p_fee_assessment
4449                             || ', Charge Rate: ' || p_charge_rate );
4450  RETURN TRUE;
4451 EXCEPTION
4452 
4453 WHEN e_one_record_expected THEN
4454         log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
4455                     p_v_string => 'From Exception Handler of e_one_record_expected.');
4456         FND_MESSAGE.SET_NAME('IGS','IGS_GE_UNHANDLED_EXP');
4457         FND_MESSAGE.SET_TOKEN('NAME','IGS_FI_PRC_FEE_ASS.FINP_CLC_ASS_AMNT-'||SUBSTR(sqlerrm,1,500));
4458         IGS_GE_MSG_STACK.ADD;
4459          lv_param_values := to_char(p_effective_dt)||','||to_char(p_person_id)||','||
4460           p_course_cd||','||p_course_attempt_status||','||
4461           p_fee_type||','||
4462           to_char(p_fee_ci_sequence_number)||','||
4463           p_fee_cat||','||p_s_fee_type||','||
4464           p_s_fee_trigger_cat||','||
4465           to_char(p_rul_sequence_number)||','||
4466           p_charge_method||','||
4467           p_location_cd||','||
4468           p_attendance_type||','||
4469           p_attendance_mode||','||
4470           p_trace_on||','||
4471           to_char(p_creation_dt)||','||
4472           p_charge_elements||','||
4473           p_fee_assessment;
4474          FND_MESSAGE.SET_NAME('IGS','IGS_GE_PARAMETERS');
4475          FND_MESSAGE.SET_TOKEN('VALUE',lv_param_values);
4476          IGS_GE_MSG_STACK.ADD;
4477         App_Exception.Raise_Exception(Null, Null, fnd_message.get);
4478 
4479 WHEN OTHERS THEN
4480         log_to_fnd( p_v_module => 'finp_clc_ass_amnt',
4481                     p_v_string => 'When Others.' || SUBSTR(sqlerrm,1,500));
4482         FND_MESSAGE.SET_NAME('IGS','IGS_GE_UNHANDLED_EXP');
4483         FND_MESSAGE.SET_TOKEN('NAME','IGS_FI_PRC_FEE_ASS.FINP_CLC_ASS_AMNT');
4484         IGS_GE_MSG_STACK.ADD;
4485          lv_param_values := to_char(p_effective_dt)||','||to_char(p_person_id)||','||
4486           p_course_cd||','||p_course_attempt_status||','||
4487           p_fee_type||','||
4488           to_char(p_fee_ci_sequence_number)||','||
4489           p_fee_cat||','||p_s_fee_type||','||
4490           p_s_fee_trigger_cat||','||
4491           to_char(p_rul_sequence_number)||','||
4492           p_charge_method||','||
4493           p_location_cd||','||
4494           p_attendance_type||','||
4495           p_attendance_mode||','||
4496           p_trace_on||','||
4497           to_char(p_creation_dt)||','||
4498           p_charge_elements||','||
4499           p_fee_assessment;
4500          FND_MESSAGE.SET_NAME('IGS','IGS_GE_PARAMETERS');
4501          FND_MESSAGE.SET_TOKEN('VALUE',lv_param_values);
4502          IGS_GE_MSG_STACK.ADD;
4503         App_Exception.Raise_Exception;
4504 
4505 END;
4506 END;
4507 END finp_clc_ass_amnt;
4508 
4509   --
4510   -- Calculate and insert fee assessments as required
4511    FUNCTION finp_ins_enr_fee_ass(p_effective_dt          IN DATE ,
4512                             p_person_id                  IN IGS_EN_STDNT_PS_ATT_ALL.person_id%TYPE ,
4513                             p_course_cd                  IN IGS_EN_STDNT_PS_ATT_ALL.course_cd%TYPE ,
4514                             p_fee_category               IN IGS_EN_STDNT_PS_ATT_ALL.FEE_CAT%TYPE ,
4515                             p_fee_cal_type               IN IGS_CA_INST_ALL.CAL_TYPE%TYPE ,
4516                             p_fee_ci_sequence_num        IN IGS_CA_INST_ALL.sequence_number%TYPE ,
4517                             p_fee_type                   IN IGS_FI_FEE_TYPE_ALL.FEE_TYPE%TYPE ,
4518                             p_trace_on                   IN VARCHAR2 ,
4519                             p_test_run                   IN VARCHAR2 ,
4520                             p_creation_dt                IN OUT NOCOPY DATE ,
4521                             p_message_name               OUT    NOCOPY VARCHAR2,
4522                             p_process_mode               IN VARCHAR2 ,
4523                             p_c_career                   IN igs_ps_ver_all.course_type%TYPE,
4524                             p_d_gl_date                  IN DATE,
4525                             p_v_wav_calc_flag            IN VARCHAR2,
4526                             p_n_waiver_amount            OUT NOCOPY NUMBER
4527                             ) RETURN BOOLEAN AS
4528 /*************************************************************
4529  Created By :
4530  Date Created By :
4531  Purpose :
4532  Know limitations, enhancements or remarks
4533  Change History
4534  Who            When         What
4535  gurprsin       06-Dec-2005  Bug 4735807, Modified function 'finp_ins_enr_fee_ass', Modified the logic to return and log the message
4536                              if No Fee category is attached to the SPA.
4537  abshriva       5-Dec-2005   Bug 4701695 Removed condition to display 'Fee calculation method' and 'term'message
4538                              in log file  on execution of 'Process Fee Assessment'
4539  pathipat       23-Nov-2005  Bug 4718712 - Modified cur_spa - removed condition on course_type.
4540 *************************************************************/
4541     BEGIN
4542     DECLARE
4543         e_one_record_expected           EXCEPTION;
4544         v_fee_cat                       igs_fi_f_cat_ca_inst.fee_cat%TYPE;
4545         v_record_found                  BOOLEAN := FALSE;
4546         v_message_name                  VARCHAR2(30);
4547 
4548         l_fee_category          igs_fi_fee_cat_all.fee_cat%TYPE;
4549         l_b_fci_lci             BOOLEAN := FALSE;
4550         l_b_ret_status          BOOLEAN;
4551         l_b_recs_found          BOOLEAN;
4552         l_b_return_status       BOOLEAN := FALSE;
4553         l_v_message_name        fnd_new_messages.message_name%TYPE := NULL;
4554         l_n_sum_waiver_amount   NUMBER := 0.0;
4555         l_v_raise_wf_event      VARCHAR2(1);
4556         l_v_err_msg             VARCHAR2(2000);
4557 
4558         CURSOR c_fcci_fss ( cp_effective_dt DATE) IS
4559                 SELECT fcci.fee_cat
4560                 FROM igs_fi_f_cat_ca_inst fcci,
4561                      igs_fi_fee_str_stat  fss
4562                 WHERE fcci.fee_cat = p_fee_category
4563                 AND (
4564                      -- In Predictive, Select only when Effective Date (i.e., SYSDATE) is less than FCCI Start Date Alias Value.
4565                      ( g_c_predictive_ind = 'Y' AND
4566                        (TRUNC(cp_effective_dt) < (SELECT TRUNC(daiv.alias_val)
4567                                                   FROM igs_ca_da_inst_v  daiv
4568                                                   WHERE daiv.DT_ALIAS = fcci.start_dt_alias AND
4569                                                   daiv.sequence_number = fcci.start_dai_sequence_number AND
4570                                                   daiv.CAL_TYPE =fcci.fee_cal_type AND
4571                                                   daiv.ci_sequence_number = fcci.fee_ci_sequence_number)
4572                        )
4573                      )
4574                      OR
4575                      -- In Actual, Select only when FCCI is active as on Effective Date. (i.e., Eff Date <= FCCI Start Date Alias)
4576                      ( g_c_predictive_ind = 'N' AND
4577                        (TRUNC(cp_effective_dt) >= (SELECT TRUNC(daiv.alias_val)
4578                                                    FROM igs_ca_da_inst_v  daiv
4579                                                    WHERE daiv.DT_ALIAS = fcci.start_dt_alias AND
4580                                                    daiv.sequence_number = fcci.start_dai_sequence_number AND
4581                                                    daiv.CAL_TYPE =fcci.fee_cal_type AND
4582                                                    daiv.ci_sequence_number = fcci.fee_ci_sequence_number)
4583                        )
4584                      )
4585                     )
4586                 AND TRUNC(cp_effective_dt) <= ( SELECT  TRUNC(daiv.alias_val)
4587                                                 FROM    IGS_CA_DA_INST_V        daiv
4588                                                 WHERE   daiv.DT_ALIAS = fcci.end_dt_alias
4589                                                 AND     daiv.sequence_number = fcci.end_dai_sequence_number
4590                                                 AND     daiv.CAL_TYPE =fcci.fee_cal_type
4591                                                 AND     daiv.ci_sequence_number = fcci.fee_ci_sequence_number)
4592                 AND     fcci.fee_cat_ci_status = fss.FEE_STRUCTURE_STATUS
4593                 AND     fss.s_fee_structure_status = gcst_active;
4594 
4595 
4596         -- cursor for getting Fee Calculation Method, Program Change Date Alias
4597         CURSOR c_fi_control  IS
4598         SELECT fee_calc_mthd_code,
4599                currency_cd
4600         FROM   igs_fi_control_all;
4601 
4602         l_c_fi_control  c_fi_control%ROWTYPE;
4603 
4604         -- cursor for checking course type
4605         CURSOR c_course_type  IS
4606         SELECT 'X'
4607         FROM   igs_ps_type_all
4608         WHERE course_type = p_c_career;
4609 
4610         l_c_temp VARCHAR2(1);
4611 
4612         CURSOR c_daiv( cp_dt_alias  igs_fi_f_cat_ca_inst.start_dt_alias%TYPE) IS
4613         SELECT  alias_val
4614         FROM    igs_ca_da_inst_v
4615         WHERE   dt_alias = cp_dt_alias
4616         AND     cal_type = p_fee_cal_type
4617         AND     ci_sequence_number = p_fee_ci_sequence_num;
4618 
4619         l_c_daiv  c_daiv%ROWTYPE;
4620 
4621        l_c_control_curr  igs_fi_control_all.currency_cd%TYPE;
4622 
4623        CURSOR cur_fee_cat_curr(cp_fee_cat IN VARCHAR2) IS
4624        SELECT currency_cd
4625        FROM igs_fi_fee_cat_all
4626        WHERE fee_cat = cp_fee_cat;
4627        l_cur_fee_cat_curr cur_fee_cat_curr%ROWTYPE;
4628 
4629     lv_sum_message varchar2(30);
4630 
4631     -- Get the Program Attempt Status for the program that is passed as input to the process
4632     CURSOR cur_sca IS
4633     SELECT  sca.course_attempt_status
4634     FROM    igs_en_stdnt_ps_att_all sca
4635     WHERE   sca.person_id = p_person_id
4636     AND     sca.course_cd = p_course_cd;
4637 
4638     -- Cursor to check if there are any Incomplete Program Transfers.
4639     CURSOR c_sua_for_sec (cp_n_person_id PLS_INTEGER,
4640                           cp_v_secondary VARCHAR2,
4641                           cp_v_enrolled  VARCHAR2) IS
4642     SELECT 'X'
4643     FROM igs_en_stdnt_ps_att_all sca,
4644          igs_en_su_attempt_all sua
4645     WHERE sca.person_id = cp_n_person_id
4646     AND   sca.person_id = sua.person_id
4647     AND   sca.course_cd = sua.course_cd
4648     AND   NVL(sca.primary_program_type, cp_v_secondary) = cp_v_secondary
4649     AND   sua.unit_attempt_status = cp_v_enrolled;
4650     rec_sua_for_sec c_sua_for_sec%ROWTYPE;
4651 
4652     -- Cursor to derive Key Program for a given student and for a given term.
4653     CURSOR c_key_program ( cp_n_person_id PLS_INTEGER,
4654                            cp_v_load_cal_type igs_fi_f_cat_ca_inst.fee_cal_type%TYPE,
4655                            cp_n_load_ci_seq_num igs_fi_f_cat_ca_inst.fee_ci_sequence_number%TYPE,
4656                            cp_v_key_prog_flag   igs_en_spa_terms.key_program_flag%TYPE ) IS
4657     SELECT program_cd, program_version
4658     FROM igs_en_spa_terms
4659     WHERE person_id = cp_n_person_id
4660     AND term_cal_type = cp_v_load_cal_type
4661     AND term_sequence_number = cp_n_load_ci_seq_num
4662     AND key_program_flag = cp_v_key_prog_flag;
4663 
4664     -- Cursor to fetch program details when the processing mode is ACTUAL.
4665     CURSOR c_scas ( cp_n_person_id   PLS_INTEGER,
4666                     cp_v_load_cal_type VARCHAR2,
4667                     cp_n_load_ci_seq_num NUMBER,
4668                     cp_v_program_cd VARCHAR2,
4669                     cp_v_fee_cat VARCHAR2,
4670                     cp_v_course_type VARCHAR2,
4671                     cp_v_key_program_flag igs_en_spa_terms.key_program_flag%TYPE,
4672                     cp_v_lookup_type igs_lookups_view.lookup_type%TYPE,
4673                     cp_v_fee_ass_ind igs_lookups_view.fee_ass_ind%TYPE) IS
4674     SELECT esptv.person_id,
4675            esptv.program_cd,
4676            esptv.program_version,
4677            psv.course_type,
4678            esptv.fee_cat,
4679            esptv.location_cd,
4680            esptv.attendance_mode,
4681            esptv.attendance_type,
4682            sca.course_attempt_status,
4683            sca.cal_type,
4684            sca.commencement_dt,
4685            sca.discontinued_dt,
4686            psv.short_title,
4687            esptv.key_program_flag
4688     FROM igs_en_spa_terms esptv,
4689          igs_ps_ver_all psv,
4690          igs_en_stdnt_ps_att_all sca,
4691          igs_lookups_view scas
4692     WHERE esptv.program_cd = psv.course_cd
4693     AND esptv.program_version = psv.version_number
4694     AND esptv.program_cd = sca.course_cd
4695     AND esptv.program_version = sca.version_number
4696     AND esptv.person_id = sca.person_id
4697     AND esptv.person_id = cp_n_person_id
4698     AND
4699      (esptv.term_cal_type = cp_v_load_cal_type
4700       AND
4701       esptv.term_sequence_number = cp_n_load_ci_seq_num
4702      )
4703     AND (cp_v_program_cd IS NULL OR esptv.program_cd = cp_v_program_cd)
4704     AND (cp_v_fee_cat IS NULL OR esptv.fee_cat = cp_v_fee_cat)
4705     AND (  /* If Fee Calc Mthd is CAREER, Term records are created only for primary programs. So select all records from terms table */
4706          (g_c_fee_calc_mthd IN (g_v_program,g_v_career))
4707          OR
4708          (esptv.key_program_flag = cp_v_key_program_flag AND g_c_fee_calc_mthd = g_v_primary_career)
4709         )
4710     AND (cp_v_course_type IS NULL OR psv.course_type = cp_v_course_type)
4711     AND sca.course_attempt_status = scas.lookup_code
4712     AND scas.lookup_type = cp_v_lookup_type
4713     AND scas.fee_ass_ind = cp_v_fee_ass_ind
4714     ORDER BY esptv.fee_cat, esptv.person_id, esptv.program_cd;
4715 
4716     CURSOR cur_person_name (cp_n_person_id PLS_INTEGER) IS
4717     SELECT party_name
4718     FROM  hz_parties p
4719     WHERE  p.party_id = cp_n_person_id;
4720 
4721     CURSOR cur_spa (cp_n_person_id         hz_parties.party_id%TYPE,
4722                     cp_v_load_cal_type     igs_ca_inst_all.cal_type%TYPE,
4723                     cp_n_load_ci_seq_num   igs_ca_inst_all.sequence_number%TYPE,
4724                     cp_v_key_program_flag  igs_en_spa_terms.key_program_flag%TYPE,
4725                     cp_v_course_type       igs_ps_ver_all.course_type%TYPE,
4726                     cp_v_lookup_type       igs_lookups_view.lookup_type%TYPE,
4727                     cp_v_fee_ass_ind       igs_lookups_view.fee_ass_ind%TYPE,
4728                     cp_v_fee_cat           igs_en_spa_terms.fee_cat%TYPE) IS
4729     SELECT     esptv.person_id,
4730                esptv.program_cd,
4731                esptv.program_version,
4732                psv.course_type,
4733                esptv.fee_cat,
4734                esptv.location_cd,
4735                esptv.attendance_mode,
4736                esptv.attendance_type,
4737                sca.course_attempt_status,
4738                sca.cal_type,
4739                sca.commencement_dt,
4740                sca.discontinued_dt,
4741                psv.short_title,
4742                esptv.key_program_flag
4743        FROM    igs_en_spa_terms esptv,
4744                igs_ps_ver_all psv,
4745                igs_en_stdnt_ps_att_all sca,
4746                igs_lookups_view scas
4747        WHERE   esptv.program_cd = psv.course_cd
4748        AND     esptv.program_version = psv.version_number
4749        AND     esptv.program_cd = sca.course_cd
4750        AND     esptv.program_version = sca.version_number
4751        AND     esptv.person_id = sca.person_id
4752        AND     esptv.person_id = cp_n_person_id
4753        AND    (esptv.term_cal_type = cp_v_load_cal_type
4754        AND     esptv.term_sequence_number = cp_n_load_ci_seq_num)
4755        AND    ((g_c_fee_calc_mthd in (g_v_program, g_v_career)) OR
4756                 (esptv.key_program_flag = cp_v_key_program_flag AND
4757                 g_c_fee_calc_mthd = g_v_primary_career))
4758        AND    sca.course_attempt_status = scas.lookup_code
4759        AND    scas.lookup_type = cp_v_lookup_type
4760        AND    scas.fee_ass_ind = cp_v_fee_ass_ind
4761        AND    esptv.fee_cat = cp_v_fee_cat;
4762 
4763     l_v_person_name hz_parties.party_name%TYPE;
4764     l_v_currency_cd igs_fi_fee_cat_all.currency_cd%TYPE;
4765 
4766     TYPE t_fee_type_typ IS TABLE OF igs_fi_fee_type_all.fee_type%TYPE INDEX BY BINARY_INTEGER;
4767     tbl_fee_type t_fee_type_typ;
4768     l_b_found    BOOLEAN;
4769     l_n_waiver_amount NUMBER;
4770     l_v_return_status VARCHAR2(10);
4771     l_n_msg_count NUMBER;
4772     l_v_msg_data  VARCHAR2(2000);
4773 
4774     CURSOR cur_fee_cat(cp_n_person_id   IN igs_en_stdnt_ps_att.person_id%TYPE,
4775                        cp_v_course_cd   IN igs_en_stdnt_ps_att.course_cd%TYPE) IS
4776       SELECT fee_cat
4777       FROM igs_en_stdnt_ps_att
4778       WHERE person_id = cp_n_person_id
4779       AND course_cd = cp_v_course_cd;
4780 
4781     l_v_fee_cat      igs_en_stdnt_ps_att.fee_cat%TYPE;
4782 
4783     FUNCTION finpl_sum_fee_ass_item (
4784                         p_person_id                             IGS_FI_FEE_AS_ITEMS.person_id%TYPE,
4785                         p_status                                IGS_FI_FEE_AS_ITEMS.status%TYPE,
4786                         p_fee_type                              IGS_FI_FEE_AS_ITEMS.fee_type%TYPE,
4787                         P_fee_cat                               IGS_FI_FEE_AS_ITEMS.fee_cat%TYPE,
4788                         p_fee_cal_type                          IGS_FI_FEE_AS_ITEMS.fee_cal_type%TYPE,
4789                         p_fee_ci_sequence_number                IGS_FI_FEE_AS_ITEMS.fee_ci_sequence_number%TYPE,
4790                         p_course_cd                             IGS_FI_FEE_AS_ITEMS.course_cd%TYPE,
4791                         p_n_crs_version_number                  igs_fi_fee_as_items.crs_version_number%TYPE,
4792                         p_chg_method_type                       IGS_FI_FEE_AS_ITEMS.s_chg_method_type%TYPE,
4793                         p_description                           IGS_FI_FEE_AS_ITEMS.description%TYPE,
4794                         p_chg_elements                          IGS_FI_FEE_AS_ITEMS.chg_elements%TYPE,
4795                         p_unit_attempt_status                   IGS_FI_FEE_AS_ITEMS.unit_attempt_status%TYPE,
4796                         p_location_cd                           IGS_FI_FEE_AS_ITEMS.location_cd%TYPE,
4797                         p_eftsu                                 IGS_FI_FEE_AS_ITEMS.eftsu%TYPE,
4798                         p_credit_points                         IGS_FI_FEE_AS_ITEMS.credit_points%TYPE,
4799                         p_amount                                IGS_FI_FEE_AS_ITEMS.amount%TYPE,
4800                         p_org_unit_cd                           IGS_FI_FEE_AS_ITEMS.org_unit_cd%TYPE,
4801                         p_trace_on                              VARCHAR2,
4802                         p_message_name                  OUT NOCOPY      VARCHAR2,
4803                         p_uoo_id        igs_fi_fee_as_items.uoo_id%TYPE,
4804                         p_n_unit_type_id                        igs_fi_fee_as_items.unit_type_id%TYPE,
4805                         p_v_unit_level                          igs_fi_fee_as_items.unit_level%TYPE,
4806                         p_v_unit_class                          igs_fi_fee_as_items.unit_class%TYPE,
4807                         p_v_unit_mode                           igs_fi_fee_as_items.unit_mode%TYPE,
4808                         p_v_unit_cd                             igs_fi_fee_as_items.unit_cd%TYPE,
4809                         p_n_unit_version                        igs_fi_fee_as_items.unit_version_number%TYPE
4810                         )
4811                 RETURN BOOLEAN  AS
4812                 /*************************************************************
4813                   Created By :syam shankar
4814                   Date Created By :18-sep-2000
4815                   Purpose :
4816                   Know limitations, enhancements or remarks
4817                   Change History
4818                   Who             When            What
4819                   pathipat        06-Sep-2005     Bug 4540295 - Fee assessment produce double fees after program version change
4820                                                   Added parameter p_n_crs_version_number
4821                   bannamal        08-Jul-2005     Enh#3392088 Campus Privilege Fee.
4822                                                   Removed the condition that checks for a change in the Charge Method.
4823                   vchappid        25-jul-2002     bug#2237227, added 'add_flag' with Default value 'N' into the Pl/SQL table t_fee_as_items
4824                                                   if the record in the pl/sql table matches with values that are passed to the function  and
4825                                                   the Fee Calculation Method is Primary Career then the Charge Elements, EFTSU, Credit Points and the
4826                                                   assessment amount are added to the existing PL/SQL table otherwise the values are replaced
4827                                                   with the values that are passed to the Function
4828 
4829                   (reverse chronological order - newest change first)
4830                 ***************************************************************/
4831                         v_message_name                  VARCHAR2(30);
4832                         lv_record_found boolean := FALSE;
4833                         CURSOR c_fee_type( cp_fee_type      IGS_FI_FEE_AS_ITEMS.FEE_TYPE%TYPE ) IS
4834                            SELECT description, s_fee_trigger_cat
4835                            FROM igs_fi_fee_type_all
4836                            WHERE fee_type = cp_fee_type;
4837 
4838                         v_fee_type_description      igs_fi_fee_type_all.description%type;
4839                         l_fee_trigger_cat           igs_fi_fee_type_all.s_fee_trigger_cat%TYPE;
4840                 BEGIN
4841                   log_to_fnd( p_v_module => 'finpl_sum_fee_ass_item',
4842                               p_v_string => 'Entered finpl_sum_fee_ass_item. Parameters are: ' ||
4843                                             p_person_id || ', ' || p_status || ', ' || p_fee_type || ', ' || P_fee_cat || ', ' || p_fee_cal_type
4844                                             || ', ' || p_fee_ci_sequence_number || ', ' || p_course_cd || ', ' || p_chg_method_type || ', ' ||
4845                                             p_description || ', ' || p_chg_elements || ', ' ||p_unit_attempt_status || ', ' || p_location_cd || ', '||
4846                                             p_eftsu || ', '|| p_credit_points || ', ' || p_amount || ', ' || p_org_unit_cd || ', ' || p_uoo_id );
4847 
4848                   -- added the trigger cat to the cursor
4849                   -- bug 1928360
4850                   OPEN  c_fee_type(p_fee_type);
4851                   FETCH c_fee_type INTO v_fee_type_description, l_fee_trigger_cat;
4852                   CLOSE c_fee_type;
4853 
4854                   log_to_fnd( p_v_module => 'finpl_sum_fee_ass_item',
4855                               p_v_string => 'Looping through Records in PL/SQL Table..');
4856                   FOR i in 1..gv_as_item_cntr LOOP
4857                     -- for a flat rate of charge method and fee trigger of institution the course code
4858                     -- fee cat should not be matched as these would be stored as null in the table.
4859                     -- bug # 1928360
4860                     IF (t_fee_as_items(i).person_id       = p_person_id) AND
4861                        (t_fee_as_items(i).fee_type        = p_fee_type)  AND
4862                        ((t_fee_as_items(i).fee_cat = p_fee_cat) or (t_fee_as_items(i).fee_cat IS NULL AND p_fee_cat IS NULL)) AND
4863                        (t_fee_as_items(i).fee_cal_type    = p_fee_cal_type)  AND
4864                        (t_fee_as_items(i).fee_ci_sequence_number = p_fee_ci_sequence_number)   AND
4865                        ((t_fee_as_items(i).course_cd = p_course_cd) OR (t_fee_as_items(i).course_cd IS NULL AND p_course_cd IS NULL)) AND
4866                        ((t_fee_as_items(i).location_cd = p_location_cd) OR
4867                                     ((t_fee_as_items(i).location_cd IS NULL) AND (p_location_cd IS NULL) ) )         AND
4868                                -- Added by schodava as a part of the CCR to the Fee Calc Build (Enh# 1851586)
4869                        ((t_fee_as_items(i).org_unit_cd = p_org_unit_cd) OR
4870                        ((t_fee_as_items(i).org_unit_cd IS NULL) AND (p_org_unit_cd IS NULL) )) AND
4871                          ((t_fee_as_items(i).uoo_id = p_uoo_id) OR (t_fee_as_items(i).uoo_id IS NULL AND p_uoo_id IS NULL ))
4872                     THEN
4873                       -- If the Fee Calculation Method
4874                       -- bug#2237227, added 'add_flag' with Default value 'N' into the Pl/SQL table t_fee_as_items
4875                       -- if the record in the pl/sql table matches with values that are passed to the function  and
4876                       -- the Fee Calculation Method is Primary Career then the Charge Elements, EFTSU, Credit Points and the
4877                       -- assessment amount are added to the existing PL/SQL table otherwise the values are replaced
4878                       -- with the values that are passed to the Function
4879                       IF ((t_fee_as_items(i).add_flag = 'Y') AND g_c_fee_calc_mthd =g_v_primary_career) THEN
4880                         t_fee_as_items(i).eftsu            := t_fee_as_items(i).eftsu + p_eftsu;
4881                         t_fee_as_items(i).credit_points    := t_fee_as_items(i).credit_points + p_credit_points;
4882                         t_fee_as_items(i).chg_elements     := t_fee_as_items(i).chg_elements + p_chg_elements;
4883                         t_fee_as_items(i).amount           := t_fee_as_items(i).amount + p_amount;
4884                         log_to_fnd( p_v_module => 'finpl_sum_fee_ass_item',
4885                                     p_v_string => 'Record Found. Primary Career so adding..');
4886                       ELSE
4887                         t_fee_as_items(i).eftsu            := p_eftsu;
4888                         t_fee_as_items(i).credit_points    := p_credit_points;
4889                         t_fee_as_items(i).chg_elements     := p_chg_elements;
4890                         t_fee_as_items(i).amount           := p_amount;
4891                         IF g_c_fee_calc_mthd =g_v_primary_career THEN
4892                            t_fee_as_items(i).add_flag := 'Y';
4893                         END IF;
4894                         log_to_fnd( p_v_module => 'finpl_sum_fee_ass_item',
4895                                     p_v_string => 'Record Found..');
4896                       END IF;
4897                       t_fee_as_items(i).chg_method_type            := p_chg_method_type;
4898                       t_fee_as_items(i).unit_attempt_status        := p_unit_attempt_status;
4899                       t_fee_as_items(i).unit_type_id               := p_n_unit_type_id;
4900                       t_fee_as_items(i).unit_mode                  := p_v_unit_mode;
4901                       t_fee_as_items(i).unit_class                 := p_v_unit_class;
4902                       t_fee_as_items(i).unit_cd                    := p_v_unit_cd;
4903                       t_fee_as_items(i).unit_version_number        := p_n_unit_version;
4904                       t_fee_as_items(i).unit_level                 := p_v_unit_level;
4905                       lv_record_found := TRUE;
4906                     END IF;
4907                   END LOOP;
4908 
4909                   --new record add if not found
4910                   IF NOT lv_record_found  THEN
4911                     gv_as_item_cntr := nvl(gv_as_item_cntr,0) + 1;
4912                     log_to_fnd( p_v_module => 'finpl_sum_fee_ass_item',
4913                                 p_v_string => 'Record Not Found. Adding it as ' || gv_as_item_cntr || ' record in table.');
4914                     t_fee_as_items(gv_as_item_cntr).person_id               := p_person_id;
4915                     t_fee_as_items(gv_as_item_cntr).status                  := p_status;
4916                     t_fee_as_items(gv_as_item_cntr).fee_type                := p_fee_type;
4917                     t_fee_as_items(gv_as_item_cntr).fee_cat                 := p_fee_cat;
4918                     t_fee_as_items(gv_as_item_cntr).fee_cal_type            := p_fee_cal_type;
4919                     t_fee_as_items(gv_as_item_cntr).fee_ci_sequence_number  := p_fee_ci_sequence_number;
4920                     t_fee_as_items(gv_as_item_cntr).course_cd               := p_course_cd;
4921                     t_fee_as_items(gv_as_item_cntr).crs_version_number      := p_n_crs_version_number;
4922                     t_fee_as_items(gv_as_item_cntr).description             := v_fee_type_description;
4923                     t_fee_as_items(gv_as_item_cntr).chg_method_type         := p_chg_method_type;
4924                     t_fee_as_items(gv_as_item_cntr).old_chg_elements        := 0;
4925                     t_fee_as_items(gv_as_item_cntr).chg_elements            := p_chg_elements;
4926                     t_fee_as_items(gv_as_item_cntr).old_amount              := 0;
4927                     t_fee_as_items(gv_as_item_cntr).amount                  := p_amount;
4928                     t_fee_as_items(gv_as_item_cntr).unit_attempt_status     := p_unit_attempt_status;
4929                     t_fee_as_items(gv_as_item_cntr).location_cd             := p_location_cd;
4930                     t_fee_as_items(gv_as_item_cntr).old_eftsu               := 0;
4931                     t_fee_as_items(gv_as_item_cntr).eftsu                   := p_eftsu;
4932                     t_fee_as_items(gv_as_item_cntr).old_credit_points       := 0;
4933                     t_fee_as_items(gv_as_item_cntr).credit_points           := p_credit_points;
4934                     t_fee_as_items(gv_as_item_cntr).chg_rate                := NULL;
4935                     t_fee_as_items(gv_as_item_cntr).org_unit_cd             := p_org_unit_cd;
4936                     t_fee_as_items(gv_as_item_cntr).uoo_id                  := p_uoo_id;
4937                     t_fee_as_items(gv_as_item_cntr).unit_type_id            := p_n_unit_type_id;
4938                     t_fee_as_items(gv_as_item_cntr).unit_class              := p_v_unit_class;
4939                     t_fee_as_items(gv_as_item_cntr).unit_mode               := p_v_unit_mode;
4940                     t_fee_as_items(gv_as_item_cntr).unit_cd                 := p_v_unit_cd;
4941                     t_fee_as_items(gv_as_item_cntr).unit_level              := p_v_unit_level;
4942                     t_fee_as_items(gv_as_item_cntr).unit_version_number     := p_n_unit_version;
4943                     IF g_c_fee_calc_mthd =g_v_primary_career THEN
4944                         t_fee_as_items(gv_as_item_cntr).add_flag := 'Y';
4945                     END IF;
4946                    END IF;
4947                    RETURN TRUE;
4948         EXCEPTION
4949                   WHEN OTHERS THEN
4950                     log_to_fnd( p_v_module => 'finpl_sum_fee_ass_item',
4951                                 p_v_string => 'From Exception Handler of When Others.');
4952                     v_message_name := 'IGS_GE_UNHANDLED_EXP';
4953                     IF (p_trace_on = 'Y') THEN
4954                         fnd_message.set_name('IGS', v_message_name);
4955                         Fnd_Message.Set_Token('NAME','IGS_FI_PRC_FEE_ASS.FINPL_SUM_FEE_ASS_ITEM-'||SUBSTR(sqlerrm,1,500));
4956                         fnd_file.put_line (fnd_file.log, fnd_message.get);
4957                     END IF;
4958                     p_message_name := v_message_name;
4959                     RETURN FALSE;
4960     END finpl_sum_fee_ass_item;
4961 
4962 
4963    PROCEDURE finpl_chk_debt_ret_sched(p_person_id                 igs_fi_fee_as_all.person_id%TYPE,
4964                                       p_fee_cat                   igs_fi_fee_as_all.fee_cat%TYPE,
4965                                       p_fee_type                  igs_fi_fee_as_all.fee_type%TYPE,
4966                                       p_fee_cal_type              igs_fi_fee_as_all.fee_cal_type%TYPE,
4967                                       p_fee_ci_sequence_number    igs_fi_fee_as_all.fee_ci_sequence_number%TYPE,
4968                                       p_course_cd                 igs_fi_fee_as_all.course_cd%TYPE,
4969                                       p_crs_version_number        igs_fi_fee_as_items.crs_version_number%TYPE,
4970                                       p_course_attempt_status     igs_fi_fee_as_items.course_attempt_status%TYPE,
4971                                       p_old_ass_amount            igs_fi_fee_as_all.transaction_amount%TYPE,
4972                                       p_new_ass_amount            igs_fi_fee_as_all.transaction_amount%TYPE,
4973                                       p_effective_date            DATE,
4974                                       p_trace_on                  VARCHAR2,
4975                                       p_d_gl_date                 igs_fi_invln_int_all.gl_date%TYPE,
4976                                       p_v_s_fee_type              igs_fi_fee_type_all.s_fee_type%TYPE,
4977                                       p_n_rul_sequence_number     igs_fi_fee_as_items.rul_sequence_number%TYPE,
4978                                       p_n_scope_rul_seq_num       igs_fi_fee_as_items.scope_rul_sequence_num%TYPE,
4979                                       p_v_chg_method_type         igs_fi_fee_as_items.s_chg_method_type%TYPE,
4980                                       p_s_fee_trigger_cat         igs_fi_fee_type_all.s_fee_trigger_cat%TYPE,
4981                                       p_v_location_cd             igs_fi_fee_as_items.location_cd%TYPE,
4982                                       p_v_career                  igs_ps_ver_all.course_type%TYPE,
4983                                       p_elm_rng_order_name        igs_fi_f_typ_ca_inst_all.elm_rng_order_name%TYPE,
4984                                       p_attendance_mode           igs_fi_fee_as_items.attendance_mode%TYPE,
4985                                       p_attendance_type           igs_fi_fee_as_items.attendance_type%TYPE,
4986                                       p_n_max_chg_elements        igs_fi_fee_as_items.max_chg_elements%TYPE
4987                                       ) AS
4988 /********************************************************************************************************
4989   CHANGE HISTORY:
4990   WHO            WHEN            WHAT
4991   abshriva       17-May-2006     Bug 5113295 - Added check (igs_fi_gen_008.chk_unit_prg_transfer) for units that were
4992                                  part of Program Transfer.Added cur_disc_dt to select only dcnt_reason_cd.
4993   pathipat       22-Nov-2005     Bug 4718712 - Added code to log Old and New Amts only if atleast one is non-zero
4994   bannamal       08-Jul-2005     Enh#3392088 Campus Privilege Fee. Changes done as per TD.
4995   bannamal       14-Apr-2005     Bug#4297359 ER Registration Fee issue
4996                                  Modified the call to igs_fi_gen_008.get_complete_withdr_ret_amt to add
4997                                  a new parameter p_v_nonzero_billable_cp_flag.
4998   pathipat       07-Sep-2004     Enh 3880438 - Retention Enhancements
4999                                  Completely revamped retention logic to include Teaching Period retention.
5000   pathipat       05-Nov-2003     Enh 3117341 - Audit and Special Fees TD
5001                                  Removed code for retention amount, added call to generic pkg to get amount
5002   pathipat     12-Sep-2003     Enh 3108052 - Unit Sets in Rate table build
5003                                Modified TBH calls of igs_Fi_fee_As_items
5004   sarakshi     13-Sep-2002     Enh#2564643,removed teh reference of subaccount from this procedure
5005   vvutukur     11-02-2002      Removed the cursor l_c_invoice_id and the check if the retention amount is greater than 0,
5006                                within which source invoice id is derived. This is done for bug 2195715 as part of SFCR003,
5007                                as there is no negative adjustment charge crated by Retention.
5008 *********************************************************************************************************/
5009   -- Local variables
5010   l_v_retention_level     igs_fi_f_typ_ca_inst_all.retention_level_code%TYPE := NULL;
5011   l_v_cmp_withdr_ret      igs_fi_f_typ_ca_inst_all.complete_ret_flag%TYPE := NULL;
5012   l_n_diff_amount         NUMBER := 0.0;
5013   l_n_retention_amount    NUMBER := 0.0;
5014   l_v_fee_type_desc       igs_fi_fee_type_all.description%TYPE  := NULL;
5015   l_v_fee_trig_cat        igs_fi_fee_type_all.s_fee_trigger_cat%TYPE  := NULL;
5016   l_n_sum_amount          NUMBER := 0.0;
5017 
5018   tbl_unit_status t_unit_status;  -- Table which says whether the corresponding unit record in tbl_fee_as_items_diff table is enrolled unit or discontinued unit
5019   tbl_enr_disc_dt t_date;         -- Table which has the discontinued dt/enrolled dt for the corresponding unit record in tbl_fee_as_items_diff table
5020 
5021   -- User-defined exceptions
5022   skip          EXCEPTION;
5023 
5024   -- Cursor to determine Optional Indicator of the fee type
5025   CURSOR cur_opt_ind(cp_v_fee_type   igs_fi_fee_type_all.fee_type%TYPE) IS
5026     SELECT optional_payment_ind, description, s_fee_trigger_cat
5027     FROM igs_fi_fee_type_all
5028     WHERE fee_type = cp_v_fee_type;
5029 
5030   --- Cursor for getting nonzero_billable_cp_flag from ftci
5031 
5032    CURSOR cur_nz_bill_cp_flag ( cp_v_fee_type           igs_fi_f_typ_ca_inst_all.fee_type%TYPE,
5033                                 cp_v_fee_cal_type       igs_fi_f_typ_ca_inst_all.fee_cal_type%TYPE,
5034                                 cp_n_fee_ci_seq_number  igs_fi_f_typ_ca_inst_all.fee_ci_sequence_number%TYPE )IS
5035      SELECT nonzero_billable_cp_flag
5036      FROM   igs_fi_f_typ_ca_inst_all
5037      WHERE fee_type = cp_v_fee_type
5038      AND   fee_cal_type = cp_v_fee_cal_type
5039      AND   fee_ci_sequence_number = cp_n_fee_ci_seq_number;
5040 
5041    CURSOR cur_fai_dtls (cp_n_fee_ass_item_id igs_fi_fai_dtls.fee_ass_item_id%TYPE) IS
5042      SELECT fai.*
5043      FROM igs_fi_fai_dtls fai
5044      WHERE fee_ass_item_id = cp_n_fee_ass_item_id;
5045 
5046    CURSOR cur_dropped_unit (cp_person_id  hz_parties.party_id%TYPE,
5047                             cp_course_cd  igs_en_su_attempt_all.course_cd%TYPE,
5048                             cp_v_fee_ass_ind VARCHAR2,
5049                             cp_v_lookup_type       igs_lookups_view.lookup_type%TYPE,
5050                             cp_v_enrp_get_load_apply   VARCHAR2,
5051                             cp_n_uoo_id igs_en_su_attempt_all.uoo_id%TYPE)  IS
5052      SELECT discontinued_dt
5053      FROM   igs_en_su_attempt_all sua,
5054             igs_lookups_view lkp
5055      WHERE lkp.lookup_code = sua.unit_attempt_status
5056      AND   lkp.lookup_type = cp_v_lookup_type
5057      AND   (sua.no_assessment_ind = cp_v_fee_ass_ind OR cp_v_fee_ass_ind IS NULL)
5058      AND   sua.person_id = cp_person_id
5059      AND   sua.course_cd = cp_course_cd
5060      AND   (igs_en_prc_load.enrp_get_load_apply(sua.cal_type,
5061                                                 sua.ci_sequence_number,
5062                                                 sua.discontinued_dt,
5063                                                 sua.administrative_unit_status,
5064                                                 sua.unit_attempt_status,
5065                                                 sua.no_assessment_ind,
5066                                                 g_v_load_cal_type,
5067                                                 g_n_load_seq_num,
5068                                                 sua.no_assessment_ind ) = cp_v_enrp_get_load_apply )
5069      AND  sua.uoo_id = cp_n_uoo_id
5070      AND  (igs_fi_gen_008.chk_unit_prg_transfer(sua.dcnt_reason_cd) = 'N')
5071      ORDER BY sua.discontinued_dt;
5072 
5073    CURSOR cur_enr_date (cp_person_id hz_parties.party_id%TYPE,
5074                         cp_course_cd igs_en_su_attempt_all.course_cd%TYPE,
5075                         cp_n_uoo_id  igs_en_su_attempt_all.uoo_id%TYPE)  IS
5076      SELECT sua.enrolled_dt
5077      FROM   igs_en_su_attempt_all sua
5078      WHERE sua.uoo_id = cp_n_uoo_id
5079      AND   sua.person_id = cp_person_id
5080      AND   sua.course_cd = cp_course_cd;
5081 
5082    CURSOR cur_disc_dt (cp_n_person_id hz_parties.party_id%TYPE,
5083                        cp_v_course_cd igs_en_su_attempt_all.course_cd%TYPE,
5084                        cp_n_uoo_id  igs_en_su_attempt_all.uoo_id%TYPE)  IS
5085      SELECT sua.dcnt_reason_cd
5086      FROM   igs_en_su_attempt_all sua
5087      WHERE sua.uoo_id = cp_n_uoo_id
5088      AND   sua.person_id = cp_n_person_id
5089      AND   sua.course_cd = cp_v_course_cd;
5090 
5091    CURSOR cur_unit_cd (cp_n_uoo_id  igs_fi_fee_as_items.uoo_id%TYPE) IS
5092     SELECT unit_cd, version_number
5093     FROM   igs_ps_unit_ofr_opt_all
5094     WHERE  uoo_id = cp_n_uoo_id;
5095 
5096   l_v_optional_ind      igs_fi_fee_type_all.optional_payment_ind%TYPE := NULL;
5097   l_v_nz_bill_cp_flag   igs_fi_f_typ_ca_inst_all.nonzero_billable_cp_flag%TYPE;
5098   l_v_fee_ass_ind       VARCHAR2(1);
5099   l_n_chg_elements      igs_fi_fee_as_items.chg_elements%TYPE;
5100   l_n_count             NUMBER;
5101   l_n_prg_type_level   igs_ps_unit_ver_all.unit_type_id%TYPE;
5102   l_v_unit_level       igs_ps_unit_ver_all.unit_level%TYPE;
5103   l_v_unit_class       igs_as_unit_class_all.unit_class%TYPE;
5104   l_v_unit_mode        igs_as_unit_class_all.unit_mode%TYPE;
5105   l_v_unit_cd          igs_ps_unit_ofr_opt_all.unit_cd%TYPE;
5106   l_n_version_num      igs_ps_unit_ofr_opt_all.version_number%TYPE;
5107   l_n_amount           igs_fi_fee_as_items.amount%TYPE;
5108   l_v_charge_rate      igs_fi_fee_as_rate.chg_rate%TYPE;
5109   l_n_uoo_id           igs_fi_fee_as_items.uoo_id%TYPE;
5110   l_n_old_amount       igs_fi_fee_as_items.amount%TYPE;
5111   l_d_disc_dt          igs_en_su_attempt_all.enrolled_dt%TYPE;
5112   l_d_enr_dt           igs_en_su_attempt_all.enrolled_dt%TYPE;
5113   l_b_rec_found        BOOLEAN;
5114   l_n_disc_units       NUMBER;
5115   l_b_flag             BOOLEAN;
5116 
5117   l_v_dcnt_reason_cd   igs_en_su_attempt_all.dcnt_reason_cd%TYPE;
5118 
5119   BEGIN
5120 
5121     log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5122                 p_v_string => 'Entered finpl_chk_debt_ret_sched. Parameters are: ' ||
5123                               p_person_id || ', ' || p_fee_cat || ', ' || p_fee_type || ', ' || p_fee_cal_type || ', ' ||
5124                               p_fee_ci_sequence_number || ', ' || ', ' || p_course_cd || ', ' ||
5125                               p_old_ass_amount || ', ' || p_new_ass_amount || ', ' || TO_CHAR(p_effective_date, 'DD-MON-YYYY') ||', '||
5126                               TO_CHAR(p_d_gl_date, 'DD-MON-YYYY'));
5127 
5128     IF (p_trace_on = 'Y') THEN
5129        -- Old and New Amounts need not be logged in the log file if both are zero.
5130        IF (p_old_ass_amount > 0 OR p_new_ass_amount > 0) THEN
5131            fnd_file.new_line(fnd_file.log);
5132            fnd_message.set_name('IGS', 'IGS_FI_ST_DT_ASS_AMT');
5133            fnd_message.set_token('OLD_AMT', TO_CHAR(p_old_ass_amount));
5134            fnd_file.put_line (fnd_file.log, fnd_message.get);
5135            fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'NEW_AMOUNT') || ': ' || TO_CHAR(p_new_ass_amount));
5136            fnd_file.new_line(fnd_file.log);
5137        END IF;
5138     END IF;
5139 
5140     -- If the Fee Type has Optional Indicator set to 'Y', Retention is not applicable. Return 0.0
5141     OPEN cur_opt_ind(p_fee_type);
5142     FETCH cur_opt_ind INTO l_v_optional_ind, l_v_fee_type_desc, l_v_fee_trig_cat;
5143     CLOSE cur_opt_ind;
5144 
5145     IF l_v_optional_ind = 'Y' THEN
5146        log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5147                    p_v_string => 'Fee Type - ' || p_fee_type ||' is Optional. Retention not applicable. Return. ');
5148 
5149        RETURN;
5150     END IF;
5151 
5152     -- Obtain values of Retention Level and Complete Withdrawal Retention checkbox from FTCI
5153     igs_fi_gen_008.get_retention_params(p_v_fee_cal_type            => p_fee_cal_type,
5154                                         p_n_fee_ci_sequence_number  => p_fee_ci_sequence_number,
5155                                         p_v_fee_type                => p_fee_type,
5156                                         p_v_ret_level               => l_v_retention_level,
5157                                         p_v_complete_withdr_ret     => l_v_cmp_withdr_ret);
5158     log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5159                 p_v_string => 'Retention Params - Retention Level: ' || l_v_retention_level ||' Complete Withdrawal Flag: '||l_v_cmp_withdr_ret);
5160 
5161     -- Calculate the Difference Amount
5162     -- This Amount is used in Fee Period Retention or when the Complete Withdrawal Retention Flag is 'Y'
5163     l_n_diff_amount := NVL(p_new_ass_amount,0) - NVL(p_old_ass_amount,0);
5164     log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5165                 p_v_string => 'Diff between summed up New and Old Amounts = ' || l_n_diff_amount);
5166 
5167 
5168     -- Based on Retention Params, different methods of calculating retention are used.
5169     IF (l_v_cmp_withdr_ret = 'Y') THEN
5170 
5171         -- Retention is applicable only for downward adjustments. For upward adj, do not check for retention
5172         IF (l_n_diff_amount >= 0) THEN
5173            log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5174                        p_v_string => 'Complete Withdrawal Retention : Diff Amount >= 0, so return without any retention');
5175            RETURN;
5176         END IF;
5177         -- If downward adjustment has happened, then determine the Retention Amount applicable
5178         log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5179                     p_v_string => 'Complete Withdrawal Retention : Invoking igs_fi_gen_008.get_complete_withdr_ret_amt');
5180         OPEN cur_nz_bill_cp_flag( p_fee_type, p_fee_cal_type, p_fee_ci_sequence_number );
5181         FETCH cur_nz_bill_cp_flag INTO l_v_nz_bill_cp_flag;
5182         CLOSE cur_nz_bill_cp_flag;
5183         -- Included the parameter p_v_nonzero_billable_cp_flag in the call to get_complete_withdr_ret_amt
5184         l_n_retention_amount := igs_fi_gen_008.get_complete_withdr_ret_amt(p_n_person_id               => p_person_id,
5185                                                                            p_v_course_cd               => p_course_cd,
5186                                                                            p_v_load_cal_type           => g_v_load_cal_type,
5187                                                                            p_n_load_ci_sequence_number => g_n_load_seq_num,
5188                                                                            p_n_diff_amount             => l_n_diff_amount,
5189                                                                            p_v_fee_type                => p_fee_type,
5190                                                                            p_v_nonzero_billable_cp_flag  => l_v_nz_bill_cp_flag);
5191         log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5192                     p_v_string => 'Complete Withdrawal Retention - Retention Amount Derived: ' || l_n_retention_amount);
5193 
5194         IF NVL(l_n_retention_amount, 0.0) > 0.0 THEN
5195              log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5196                          p_v_string => 'Complete Withdrawal Retention - Retention Amount > 0, invoking create_retention_charge.');
5197              IF (p_trace_on = 'Y') THEN
5198                fnd_file.new_line(fnd_file.log);
5199                fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'RET_LEVEL') || ': ' || igs_fi_gen_gl.get_lkp_meaning('IGS_FI_RET_LEVEL', l_v_retention_level));
5200                fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'WITHDWR_RET') || ': ' || igs_fi_gen_gl.get_lkp_meaning('YES_NO', l_v_cmp_withdr_ret));
5201              END IF;
5202              create_retention_charge( p_n_person_id               => p_person_id,
5203                                       p_v_course_cd               => p_course_cd,
5204                                       p_v_fee_cal_type            => p_fee_cal_type,
5205                                       p_n_fee_ci_sequence_number  => p_fee_ci_sequence_number,
5206                                       p_v_fee_type                => p_fee_type,
5207                                       p_v_fee_cat                 => p_fee_cat,
5208                                       p_d_gl_date                 => TRUNC(p_d_gl_date),
5209                                       p_n_uoo_id                  => NULL,
5210                                       p_n_amount                  => l_n_retention_amount,
5211                                       p_v_fee_type_desc           => l_v_fee_type_desc,
5212                                       p_v_fee_trig_cat            => l_v_fee_trig_cat,
5213                                       p_trace_on                  => p_trace_on);
5214         END IF;  -- End if for l_n_retention_amount > 0.0
5215 
5216     ELSIF (l_v_cmp_withdr_ret = 'N') THEN
5217        -- If Retention Level is set to Fee Period, obtain Retention Amount from Fee Type level
5218        IF (l_v_retention_level = 'FEE_PERIOD') THEN
5219            -- Retention is applicable only for downward adjustments. For upward adj, do not check for retention
5220            IF (l_n_diff_amount >= 0) THEN
5221               log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5222                           p_v_string => 'Fee Period retention : Diff Amount >= 0, so return without any retention');
5223               RETURN;
5224            END IF;
5225            -- If downward adjustment has happened, then determine the Retention Amount applicable
5226            log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5227                        p_v_string => 'Fee Period retention : Invoking igs_fi_gen_008.get_fee_retention_amount');
5228            l_n_retention_amount := igs_fi_gen_008.get_fee_retention_amount(p_v_fee_cat                 => p_fee_cat,
5229                                                                            p_v_fee_cal_type            => p_fee_cal_type,
5230                                                                            p_n_fee_ci_sequence_number  => p_fee_ci_sequence_number,
5231                                                                            p_v_fee_type                => p_fee_type,
5232                                                                            p_n_diff_amount             => l_n_diff_amount);
5233            log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5234                        p_v_string => 'Fee Period retention - Retention Amount Derived: ' || l_n_retention_amount);
5235 
5236            IF NVL(l_n_retention_amount, 0.0) > 0.0 THEN
5237                 log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5238                             p_v_string => 'Fee Period retention - Retention Amount > 0, invoking create_retention_charge.');
5239                 IF (p_trace_on = 'Y') THEN
5240                   fnd_file.new_line(fnd_file.log);
5241                   fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'RET_LEVEL') || ': ' || igs_fi_gen_gl.get_lkp_meaning('IGS_FI_RET_LEVEL', l_v_retention_level));
5242                   fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'WITHDWR_RET') || ': ' || igs_fi_gen_gl.get_lkp_meaning('YES_NO', l_v_cmp_withdr_ret));
5243                 END IF;
5244 
5245                 create_retention_charge( p_n_person_id            => p_person_id,
5246                                       p_v_course_cd               => p_course_cd,
5247                                       p_v_fee_cal_type            => p_fee_cal_type,
5248                                       p_n_fee_ci_sequence_number  => p_fee_ci_sequence_number,
5249                                       p_v_fee_type                => p_fee_type,
5250                                       p_v_fee_cat                 => p_fee_cat,
5251                                       p_d_gl_date                 => TRUNC(p_d_gl_date),
5252                                       p_n_uoo_id                  => NULL,
5253                                       p_n_amount                  => l_n_retention_amount,
5254                                       p_v_fee_type_desc           => l_v_fee_type_desc,
5255                                       p_v_fee_trig_cat            => l_v_fee_trig_cat,
5256                                       p_trace_on                  => p_trace_on);
5257            END IF;  -- End if for l_n_retention_amount > 0.0
5258 
5259        -- If Retention Level is set to Teach Period, obtain Retention Amount from FTCI + Teach Period level
5260        ELSIF (l_v_retention_level = 'TEACH_PERIOD') THEN
5261 
5262            log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5263                        p_v_string => 'Teach Period level Retention : Looping across pl/sql tbl t_fee_as_items. Count = '||t_fee_as_items.COUNT);
5264 
5265            IF t_fee_as_items.COUNT > 0 THEN
5266                FOR i in t_fee_as_items.FIRST..t_fee_as_items.LAST LOOP
5267                    BEGIN
5268                        IF t_fee_as_items.EXISTS(i) THEN
5269                            log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5270                                        p_v_string => 'Teach Period level Retention : Record '|| i ||
5271                                                      ' - Uoo ID: '||t_fee_as_items(i).uoo_id||
5272                                                      ' Status: '||t_fee_as_items(i).status);
5273 
5274                            -- Only charges that have not been declined/reversed will be processed
5275                            IF (t_fee_as_items(i).status <> 'D') THEN
5276                              IF (t_fee_as_items(i).uoo_id IS NULL) THEN
5277                                IF (NVL(t_fee_as_items(i).old_amount, 0) > 0) THEN
5278                                   log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5279                                               p_v_string => 'Teach Period level Retention: t_fee_as_items('||i||').old_amount < 0');
5280                                   tbl_fee_as_items.DELETE;
5281                                --The table tbl_fee_as_items is loaded with unit records of previous assessment
5282                                   FOR rec_fai_dlts IN cur_fai_dtls(t_fee_as_items(i).fee_ass_item_id)
5283                                   LOOP
5284                                     log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5285                                                 p_v_string => 'Teach Period level Retention: UOO Id: '||rec_fai_dlts.uoo_id);
5286                                     finpl_get_unit_type_level(rec_fai_dlts.uoo_id, l_n_prg_type_level, l_v_unit_level);
5287                                     finpl_get_unit_class_mode(rec_fai_dlts.uoo_id, l_v_unit_class, l_v_unit_mode);
5288                                     OPEN cur_unit_cd (rec_fai_dlts.uoo_id);
5289                                     FETCH cur_unit_cd INTO l_v_unit_cd, l_n_version_num;
5290                                     IF cur_unit_cd%NOTFOUND THEN
5291                                       l_v_unit_cd := NULL;
5292                                       l_n_version_num := NULL;
5293                                     END IF;
5294                                     CLOSE cur_unit_cd;
5295                                     l_n_count := tbl_fee_as_items.COUNT + 1;
5296                                     log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5297                                                 p_v_string => 'Teach Period level Retention: Adding record to tbl_fee_as_items at position - '||l_n_count);
5298                                     tbl_fee_as_items(l_n_count).chg_elements           := rec_fai_dlts.chg_elements;
5299                                     tbl_fee_as_items(l_n_count).person_id              := p_person_id;
5300                                     tbl_fee_as_items(l_n_count).fee_type               := p_fee_type;
5301                                     tbl_fee_as_items(l_n_count).fee_cat                := p_fee_cat;
5302                                     tbl_fee_as_items(l_n_count).fee_cal_type           := p_fee_cal_type;
5303                                     tbl_fee_as_items(l_n_count).fee_ci_sequence_number := p_fee_ci_sequence_number;
5304                                     tbl_fee_as_items(l_n_count).course_cd              := p_course_cd;
5305                                     tbl_fee_as_items(l_n_count).chg_method_type        := p_v_chg_method_type;
5306                                     tbl_fee_as_items(l_n_count).unit_attempt_status    := rec_fai_dlts.unit_attempt_status;
5307                                     tbl_fee_as_items(l_n_count).location_cd            := rec_fai_dlts.location_cd;
5308                                     tbl_fee_as_items(l_n_count).org_unit_cd            := rec_fai_dlts.org_unit_cd;
5309                                     tbl_fee_as_items(l_n_count).class_standing         := rec_fai_dlts.class_standing;
5310                                     tbl_fee_as_items(l_n_count).uoo_id                 := rec_fai_dlts.uoo_id;
5311                                     tbl_fee_as_items(l_n_count).unit_set_cd            := rec_fai_dlts.unit_set_cd;
5312                                     tbl_fee_as_items(l_n_count).us_version_number      := rec_fai_dlts.us_version_number;
5313                                     tbl_fee_as_items(l_n_count).unit_type_id           := l_n_prg_type_level;
5314                                     tbl_fee_as_items(l_n_count).unit_class             := l_v_unit_class;
5315                                     tbl_fee_as_items(l_n_count).unit_mode              := l_v_unit_mode;
5316                                     tbl_fee_as_items(l_n_count).unit_cd                := l_v_unit_cd;
5317                                     tbl_fee_as_items(l_n_count).unit_level             := l_v_unit_level;
5318                                     tbl_fee_as_items(l_n_count).unit_version_number    := l_n_version_num;
5319                                     tbl_fee_as_items(l_n_count).status                 := t_fee_as_items(i).status;
5320                                   END LOOP;
5321 
5322                                   l_v_fee_ass_ind := NULL;
5323 
5324                                   IF (p_v_s_fee_type = gcst_tuition_other OR  p_v_s_fee_type = gcst_other) THEN
5325                                      IF g_v_include_audit = 'Y' THEN
5326                                         l_v_fee_ass_ind := NULL;   -- Consider All units
5327                                      ELSE
5328                                         l_v_fee_ass_ind := 'N';  -- Consider only non-auditable units
5329                                      END IF;
5330                                   -- For Audit Fee Type, ONLY auditable units are considered, irrespective of the profile value
5331                                   ELSIF (p_v_s_fee_type = g_v_audit) THEN
5332                                      l_v_fee_ass_ind := 'Y';   -- Consider only auditable units
5333                                   END IF;
5334 
5335                                   tbl_fee_as_items_diff.DELETE;
5336                                   tbl_unit_status.DELETE;
5337                                   tbl_enr_disc_dt.DELETE;
5338 
5339                             -- The table tbl_fee_as_items_diff is loaded with diff records between previous assessment and current assessment
5340                             -- The table tbl_unit_status says whether the corresponding unit record in tbl_fee_as_items_diff is dropped or enrolled
5341                             -- The table tbl_enr_disc_dt has the discontinued dt/enrolled dt for the corresponding unit record in tbl_fee_as_items_diff
5342 
5343                                --Add record to tbl_fee_as_items_diff only if its not present in the old assessment.
5344                                -- i.e. the unit details of enrolled units after the previous assessment
5345                                   IF p_s_fee_trigger_cat = gcst_institutn THEN
5346                                 -- In case of Institution fee type the unit level details are obtained from the plsql table tbl_fai_unit_dtls.
5347                                      FOR j IN 1..tbl_fai_unit_dtls.COUNT
5348                                      LOOP
5349                                         l_b_rec_found := FALSE;
5350                                         FOR k IN 1..tbl_fee_as_items.COUNT
5351                                         LOOP
5352                                           IF tbl_fai_unit_dtls(j).uoo_id = tbl_fee_as_items(k).uoo_id THEN
5353                                             l_b_rec_found := TRUE;
5354                                             EXIT;
5355                                           END IF;
5356                                         END LOOP;
5357 
5358                                         IF (l_b_rec_found = FALSE) THEN
5359                                            l_n_count := tbl_fee_as_items_diff.COUNT + 1;
5360                                            tbl_fee_as_items_diff(l_n_count).chg_elements           := tbl_fai_unit_dtls(j).chg_elements;
5361                                            tbl_fee_as_items_diff(l_n_count).person_id              := p_person_id;
5362                                            tbl_fee_as_items_diff(l_n_count).fee_type               := p_fee_type;
5363                                            tbl_fee_as_items_diff(l_n_count).fee_cat                := p_fee_cat;
5364                                            tbl_fee_as_items_diff(l_n_count).fee_cal_type           := p_fee_cal_type;
5365                                            tbl_fee_as_items_diff(l_n_count).fee_ci_sequence_number := p_fee_ci_sequence_number;
5366                                            tbl_fee_as_items_diff(l_n_count).course_cd              := p_course_cd;
5367                                            tbl_fee_as_items_diff(l_n_count).chg_method_type        := p_v_chg_method_type;
5368                                            tbl_fee_as_items_diff(l_n_count).unit_attempt_status    := tbl_fai_unit_dtls(j).unit_attempt_status;
5369                                            tbl_fee_as_items_diff(l_n_count).location_cd            := tbl_fai_unit_dtls(j).location_cd;
5370                                            tbl_fee_as_items_diff(l_n_count).org_unit_cd            := tbl_fai_unit_dtls(j).org_unit_cd;
5371                                            tbl_fee_as_items_diff(l_n_count).class_standing         := tbl_fai_unit_dtls(j).class_standing;
5372                                            tbl_fee_as_items_diff(l_n_count).uoo_id                 := tbl_fai_unit_dtls(j).uoo_id;
5373                                            tbl_fee_as_items_diff(l_n_count).unit_set_cd            := tbl_fai_unit_dtls(j).unit_set_cd;
5374                                            tbl_fee_as_items_diff(l_n_count).us_version_number      := tbl_fai_unit_dtls(j).us_version_number;
5375                                            tbl_fee_as_items_diff(l_n_count).unit_type_id           := tbl_fai_unit_dtls(j).unit_type_id;
5376                                            tbl_fee_as_items_diff(l_n_count).unit_class             := tbl_fai_unit_dtls(j).unit_class;
5377                                            tbl_fee_as_items_diff(l_n_count).unit_mode              := tbl_fai_unit_dtls(j).unit_mode;
5378                                            tbl_fee_as_items_diff(l_n_count).unit_cd                := tbl_fai_unit_dtls(j).unit_cd;
5379                                            tbl_fee_as_items_diff(l_n_count).unit_level             := tbl_fai_unit_dtls(j).unit_level;
5380                                            tbl_fee_as_items_diff(l_n_count).unit_version_number    := tbl_fai_unit_dtls(j).unit_version_number;
5381                                            tbl_fee_as_items_diff(l_n_count).status                 := t_fee_as_items(i).status;
5382                                            tbl_unit_status(l_n_count) := 'E';
5383                                            OPEN cur_enr_date(p_person_id, p_course_cd, tbl_fai_unit_dtls(j).uoo_id);
5384                                            FETCH cur_enr_date INTO l_d_enr_dt;
5385                                            CLOSE cur_enr_date ;
5386                                            tbl_enr_disc_dt(l_n_count) := l_d_enr_dt;
5387                                         END IF;
5388                                      END LOOP;
5389 
5390 
5391                                   ELSE
5392                                 -- In case of Non-Institution fee type the unit level details are obtained from the plsql table t_fee_as_items.
5393                                     log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5394                                                 p_v_string => 'Teach Period level Retention: Looping across Main table, t_fee_as_items');
5395                                     FOR j IN 1..t_fee_as_items.COUNT
5396                                     LOOP
5397                                       IF ( t_fee_as_items(j).fee_type = p_fee_type AND t_fee_as_items(i).course_cd = p_course_cd AND
5398                                            t_fee_as_items(j).old_amount = 0 ) THEN
5399                                         l_b_rec_found := FALSE;
5400                                         log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5401                                                     p_v_string => 'Teach Period level Retention: Looping across Prev Assmnt table, tbl_fee_as_items');
5402                                         FOR k IN 1..tbl_fee_as_items.COUNT
5403                                         LOOP
5404                                           IF t_fee_as_items(j).uoo_id = tbl_fee_as_items(k).uoo_id THEN
5405                                             log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5406                                                         p_v_string => 'Teach Period level Retention: Found same record in Prev Assmnt and Main table');
5407                                             l_b_rec_found := TRUE;
5408                                             EXIT;
5409                                           END IF;
5410                                         END LOOP;
5411                                         IF (l_b_rec_found = FALSE) THEN
5412                                           log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5413                                                       p_v_string => 'Teach Period level Retention: Did not find record in main table, so adding '||
5414                                                                     'new record in Diff table, tbl_fee_as_items_diff with status Enrolled');
5415                                           l_n_count := tbl_fee_as_items_diff.COUNT + 1;
5416                                           tbl_fee_as_items_diff(l_n_count) := t_fee_as_items(j);
5417                                           tbl_unit_status(l_n_count) := 'E';
5418                                           OPEN cur_enr_date(p_person_id, p_course_cd, t_fee_as_items(j).uoo_id);
5419                                           FETCH cur_enr_date INTO l_d_enr_dt;
5420                                           CLOSE cur_enr_date ;
5421                                           tbl_enr_disc_dt(l_n_count) := l_d_enr_dt;
5422                                         END IF;
5423                                       END IF;
5424                                     END LOOP;
5425                                   END IF;
5426                                   l_n_disc_units := 0;
5427 
5428                                --Add unit records to tbl_fee_as_items_diff which were assessed in the previous assessment and dropped after tbat.
5429                                   log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5430                                               p_v_string => 'Teach Period level Retention: Looping across tbl_fee_as_items for adding dropped units');
5431                                   FOR j IN 1..tbl_fee_as_items.COUNT
5432                                   LOOP
5433                                     -- Replace p_course_cd being passed as input to this cursor with tbl_fee_as_items(j).course_cd
5434                                     OPEN cur_dropped_unit(p_person_id, tbl_fee_as_items(j).course_cd,l_v_fee_ass_ind,
5435                                                           'UNIT_ATTEMPT_STATUS', 'N', tbl_fee_as_items(j).uoo_id);
5436                                     FETCH cur_dropped_unit INTO l_d_disc_dt;
5437                                     CLOSE cur_dropped_unit;
5438                                     IF l_d_disc_dt IS NOT NULL THEN
5439                                       l_n_disc_units := l_n_disc_units + 1;
5440                                       l_n_count := tbl_fee_as_items_diff.COUNT + 1;
5441                                       log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5442                                                   p_v_string => 'Teach Period level Retention: Adding dropped unit in tbl_fee_as_items_diff at '||l_n_count);
5443                                       tbl_fee_as_items_diff(l_n_count) := tbl_fee_as_items(j);
5444                                       tbl_unit_status(l_n_count) := 'D';
5445                                       tbl_enr_disc_dt(l_n_count) := l_d_disc_dt;
5446                                     END IF;
5447                                   END LOOP;
5448 
5449                                   l_b_flag := TRUE;
5450                                   l_n_old_amount := NVL(t_fee_as_items(i).old_amount, 0);
5451                                   l_n_amount :=  NVL(t_fee_as_items(i).old_amount, 0);
5452                                   IF l_n_disc_units > 0 THEN
5453                                -- sort the records using the discontinued dt/enrolled dt
5454                                      log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5455                                                  p_v_string => 'Calling finpl_retn_sort_table since there are dropped units');
5456                                      finpl_retn_sort_table(tbl_fee_as_items_diff, tbl_unit_status, tbl_enr_disc_dt);
5457 
5458                                      log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5459                                                  p_v_string => 'Teach Period level Retention: Looping across tbl_fee_as_items_diff');
5460                                --For each diff record finp_clc_ass_amnt is called and retention is calculated if the unit in context is dropped.
5461                                      FOR j IN 1..tbl_fee_as_items_diff.COUNT
5462                                      LOOP
5463                                        l_b_flag := FALSE;
5464                                        tbl_fee_as_items_dummy.DELETE;
5465                                        IF (tbl_unit_status(j) = 'D') THEN
5466                               --If the unit in context is dropped load the table tbl_fee_as_items_dummy with the records of previous calculation excluding the dropped unit
5467                                          l_n_disc_units := l_n_disc_units - 1;
5468                                          IF (l_n_disc_units < 0) THEN
5469                                            IF j = tbl_fee_as_items_diff.COUNT THEN
5470                                              log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5471                                                          p_v_string => 'Teach Period level Retention: Only one unit is dropped or the dropped unit'||
5472                                                                        ' is the last record in tbl_fee_as_items_diff');
5473                                              l_b_flag := TRUE;
5474                                              l_n_uoo_id := tbl_fee_as_items_diff(j).uoo_id;
5475                                              EXIT;
5476                                            END IF;
5477                                          END IF;
5478 
5479                                          log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5480                                                      p_v_string => 'Teach Period level Retention: Looping across tbl_fee_as_items');
5481                                          FOR k IN 1..tbl_fee_as_items.COUNT
5482                                          LOOP
5483                                            IF (tbl_fee_as_items(k).uoo_id <> tbl_fee_as_items_diff(j).uoo_id) THEN
5484                                              log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5485                                                          p_v_string => 'Teach Period level Retention: Add to dummy table tbl_fee_as_items_dummy, '||
5486                                                                        'all units exluding the dropped unit from the Prev assmnt table, tbl_fee_as_items');
5487                                              l_n_count := tbl_fee_as_items_dummy.COUNT + 1;
5488                                              tbl_fee_as_items_dummy(l_n_count) := tbl_fee_as_items(k);
5489                                            END IF;
5490                                          END LOOP;
5491                                          tbl_fee_as_items := tbl_fee_as_items_dummy;
5492 
5493                                        ELSIF (tbl_unit_status(j) = 'E') THEN
5494                               --If the unit in context is enrolled load the table tbl_fee_as_items_dummy with the records of previous calculation
5495                               --including the enrolled unit
5496                                          IF j = tbl_fee_as_items_diff.COUNT THEN
5497                                            l_b_flag := FALSE;
5498                                            EXIT;
5499                                          END IF;
5500 
5501                                          FOR k IN 1..tbl_fee_as_items.COUNT
5502                                          LOOP
5503                                            l_n_count := tbl_fee_as_items_dummy.COUNT + 1;
5504                                            tbl_fee_as_items_dummy(l_n_count) := tbl_fee_as_items(k);
5505                                          END LOOP;
5506                                          l_n_count := tbl_fee_as_items_dummy.COUNT + 1;
5507                                          tbl_fee_as_items_dummy(l_n_count) := tbl_fee_as_items_diff(j);
5508                                          tbl_fee_as_items := tbl_fee_as_items_dummy;
5509                                        END IF;
5510                                        l_n_chg_elements := 0;
5511                                        FOR k IN 1..tbl_fee_as_items_dummy.COUNT
5512                                        LOOP
5513                                          l_n_chg_elements := l_n_chg_elements + tbl_fee_as_items_dummy(k).chg_elements;
5514                                        END LOOP;
5515                                        l_n_amount := 0;
5516 
5517                                        log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5518                                                    p_v_string => 'Calling finp_clc_ass_amnt');
5519 
5520                                        IF (finp_clc_ass_amnt(p_effective_dt              =>  p_effective_date,
5521                                                 p_person_id                          =>  p_person_id,
5522                                                 p_course_cd                          =>  p_course_cd,
5523                                                 p_course_version_number              =>  p_crs_version_number,
5524                                                 p_course_attempt_status              =>  p_course_attempt_status,
5525                                                 p_fee_type                           =>  p_fee_type,
5526                                                 p_fee_cal_type                       =>  p_fee_cal_type,
5527                                                 p_fee_ci_sequence_number             =>  p_fee_ci_sequence_number,
5528                                                 p_fee_cat                            =>  p_fee_cat,
5529                                                 p_s_fee_type                         =>  p_v_s_fee_type,
5530                                                 p_s_fee_trigger_cat                  =>  p_s_fee_trigger_cat,
5531                                                 p_rul_sequence_number                =>  p_n_rul_sequence_number,
5532                                                 p_charge_method                      =>  p_v_chg_method_type,
5533                                                 p_location_cd                        =>  p_v_location_cd,
5534                                                 p_attendance_type                    =>  p_attendance_type,
5535                                                 p_attendance_mode                    =>  p_attendance_mode,
5536                                                 p_trace_on                           =>  p_trace_on,
5537                                                 p_creation_dt                        =>  p_creation_dt, -- in out
5538                                                 p_charge_elements                    =>  l_n_chg_elements,      -- in out
5539                                                 p_fee_assessment                     =>  l_n_amount,       -- in out
5540                                                 p_charge_rate                        =>  l_v_charge_rate,
5541                                                 p_c_career                           =>  p_v_career,
5542                                                 p_elm_rng_order_name                 =>  p_elm_rng_order_name,
5543                                                 p_n_max_chg_elements                 =>  p_n_max_chg_elements,
5544                                                 p_n_called                           =>  1 ) = FALSE) THEN
5545 
5546                                               log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5547                                               p_v_string => 'finp_clc_ass_amnt returned FALSE. Out Vars: Chg Elms: '
5548                                                              || l_n_chg_elements || ', Amount: ' || l_n_amount );
5549                                        ELSE
5550                                          IF (tbl_unit_status(j) = 'D') THEN
5551                               --calculate retention only if the unit attempt is dropped
5552                                             l_n_diff_amount := NVL(l_n_amount,0) - NVL(l_n_old_amount,0);
5553                                             IF (l_n_diff_amount < 0) THEN
5554                                                l_n_uoo_id := tbl_fee_as_items_diff(j).uoo_id;
5555                                                log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5556                                                            p_v_string => 'Calling finpl_prc_teach_prd_retn_levl, l_n_diff_amount is '||NVL(l_n_diff_amount,0));
5557                                                finpl_prc_teach_prd_retn_levl( p_person_id                =>  p_person_id,
5558                                                                           p_fee_cat                  =>  p_fee_cat,
5559                                                                           p_fee_type                 =>  p_fee_type,
5560                                                                           p_fee_cal_type             =>  p_fee_cal_type,
5561                                                                           p_fee_ci_sequence_number   =>  p_fee_ci_sequence_number,
5562                                                                           p_course_cd                =>  p_course_cd,
5563                                                                           p_n_uoo_id                 =>  l_n_uoo_id,
5564                                                                           p_trace_on                 =>  p_trace_on,
5565                                                                           p_d_gl_date                =>  p_d_gl_date,
5566                                                                           p_n_diff_amount            =>  l_n_diff_amount,
5567                                                                           p_v_retention_level        =>  l_v_retention_level,
5568                                                                           p_v_cmp_withdr_ret         =>  l_v_cmp_withdr_ret,
5569                                                                           p_v_fee_type_desc          =>  l_v_fee_type_desc,
5570                                                                           p_v_fee_trig_cat           =>  l_v_fee_trig_cat );
5571                                            END IF;
5572                                          END IF;
5573                                          l_n_old_amount := l_n_amount;
5574                                        END IF;
5575                                      END LOOP;
5576                                   END IF;
5577                                END IF;
5578                              ELSE -- uoo_id not null
5579                                  -- Calculate the Difference Amount
5580                                  l_n_diff_amount := NVL(t_fee_as_items(i).amount, 0) - NVL(t_fee_as_items(i).old_amount, 0);
5581 
5582                                  log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5583                                              p_v_string => 'Teach Period level Retention : Difference Amount = ' || l_n_diff_amount ||
5584                                                            ' UOO Id: '||t_fee_as_items(i).uoo_id);
5585 
5586                                  IF (l_n_diff_amount >= 0) THEN
5587                                      log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5588                                                  p_v_string => 'Teach Period level retention : Diff Amount >= 0, so skip Unit Section');
5589                                      RAISE skip;
5590                                  END IF;
5591 
5592                                  -- Check if the unit has been dropped due to a Program Transfer. If yes, then do not invoke retention
5593                                  OPEN cur_disc_dt(p_person_id, t_fee_as_items(i).course_cd, t_fee_as_items(i).uoo_id);
5594                                  FETCH cur_disc_dt INTO l_v_dcnt_reason_cd;
5595                                  CLOSE cur_disc_dt;
5596                                  IF (igs_fi_gen_008.chk_unit_prg_transfer(l_v_dcnt_reason_cd) = 'Y') THEN
5597                                        log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5598                                                    p_v_string => 'Teach Period level Retention: Unit Transferred, UOO_ID: '||t_fee_as_items(i).uoo_id
5599                                                                   ||' Course Cd: '||t_fee_as_items(i).course_cd||' and Disc Reason: '||l_v_dcnt_reason_cd);
5600                                        RAISE SKIP;
5601                                  END IF;
5602 
5603                                  finpl_prc_teach_prd_retn_levl( p_person_id                =>  p_person_id,
5604                                                                  p_fee_cat                  =>  p_fee_cat,
5605                                                                  p_fee_type                 =>  p_fee_type,
5606                                                                  p_fee_cal_type             =>  p_fee_cal_type,
5607                                                                  p_fee_ci_sequence_number   =>  p_fee_ci_sequence_number,
5608                                                                  p_course_cd                =>  p_course_cd,
5609                                                                  p_n_uoo_id                 =>  t_fee_as_items(i).uoo_id,
5610                                                                  p_trace_on                 =>  p_trace_on,
5611                                                                  p_d_gl_date                =>  p_d_gl_date,
5612                                                                  p_n_diff_amount            =>  l_n_diff_amount,
5613                                                                  p_v_retention_level        =>  l_v_retention_level,
5614                                                                  p_v_cmp_withdr_ret         =>  l_v_cmp_withdr_ret,
5615                                                                  p_v_fee_type_desc          =>  l_v_fee_type_desc,
5616                                                                  p_v_fee_trig_cat           =>  l_v_fee_trig_cat );
5617 
5618                              END IF; -- If uoo_id is null
5619                            END IF;  -- End if for t_fee_as_items(i).status <> 'D'
5620                        END IF;  -- End if for t_fee_as_items.EXISTS(i)
5621                    EXCEPTION
5622                       WHEN skip THEN
5623                          -- Do nothing, skip record
5624                          NULL;
5625                    END;
5626                END LOOP;
5627            END IF;  -- End if for t_fee_as_items.COUNT > 0
5628        END IF; -- End if for check on l_v_retention_level
5629     END IF;  -- End if for check on l_v_cmp_withdr_ret
5630 
5631    log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5632                p_v_string => 'Returning from finpl_chk_debt_ret_sched');
5633 
5634   EXCEPTION
5635     WHEN Others THEN
5636       log_to_fnd( p_v_module => 'finpl_chk_debt_ret_sched',
5637                   p_v_string => 'From Exception Handler of When Others.');
5638       Fnd_Message.Set_Name('IGS','IGS_GE_UNHANDLED_EXP');
5639       Fnd_Message.Set_Token('NAME','IGS_FI_PRC_FEE_ASS.FINPL_CHK_DEBT_RET_SCHED-'||SUBSTR(SQLERRM,1,500));
5640       igs_ge_msg_stack.add;
5641       app_exception.raise_exception;
5642   END finpl_chk_debt_ret_sched;
5643 
5644         PROCEDURE finpl_ins_fee_ass(
5645                 p_person_id               hz_parties.party_id%TYPE,
5646                 p_course_cd               igs_en_stdnt_ps_att_all.course_cd%TYPE,
5647                 p_fee_type                igs_fi_f_cat_fee_lbl_all.fee_type%TYPE,
5648                 p_fee_cal_type            igs_fi_f_cat_fee_lbl_all.fee_cal_type%TYPE,
5649                 p_fee_ci_sequence_number  igs_fi_f_cat_fee_lbl_all.fee_ci_sequence_number%TYPE,
5650                 p_s_fee_trigger_cat       igs_fi_fee_type_all.s_fee_trigger_cat%TYPE,
5651                 p_fee_cat                 igs_en_stdnt_ps_att_all.fee_cat%TYPE,
5652                 p_currency                igs_fi_control_all.currency_cd%TYPE,
5653                 p_charge_rate             igs_fi_fee_as_rate.chg_rate%TYPE,
5654                 p_s_fee_type              igs_fi_fee_type_all.s_fee_type%TYPE,
5655                 p_effective_dt            DATE,
5656                 p_trace_on                VARCHAR2,
5657                 p_crs_version_number      igs_fi_fee_as_items.crs_version_number%TYPE,
5658                 p_course_attempt_status   igs_fi_fee_as_items.course_attempt_status%TYPE,
5659                 p_attendance_mode         igs_fi_fee_as_items.attendance_mode%TYPE,
5660                 p_attendance_type         igs_fi_fee_as_items.attendance_type%TYPE,
5661                 p_charge_elements       IN OUT NOCOPY   Igs_fi_fee_as_all.chg_elements%TYPE,
5662                 p_fee_assessment        IN OUT NOCOPY   NUMBER,
5663                 -- Added to initialize the new pl/sql table for Institution related records
5664                 p_fcfl_status           IN igs_fi_f_cat_fee_lbl_all.fee_liability_status%TYPE,
5665                 p_n_rul_sequence_number IN igs_fi_fee_as_items.rul_sequence_number%TYPE,
5666                 p_n_scope_rul_seq_num   IN igs_fi_fee_as_items.scope_rul_sequence_num%TYPE,
5667                 p_v_chg_method_type     IN igs_fi_fee_as_items.s_chg_method_type%TYPE,
5668                 p_v_location_cd         IN igs_fi_fee_as_items.location_cd%TYPE,
5669                 p_v_career              IN igs_ps_ver_all.course_type%TYPE,
5670                 p_elm_rng_order_name    IN igs_fi_f_typ_ca_inst_all.elm_rng_order_name%TYPE,
5671                 p_n_max_chg_elements    IN igs_fi_fee_as_items.max_chg_elements%TYPE) AS
5672 
5673          /*************************************************************************************************
5674          CHANGE HISTORY:
5675          WHO             WHEN            WHAT
5676          abshriva       12-May-2006       Bug 5217319: Amount Precision change, added API call to allow correct precison into DB
5677          pathipat       22-Nov-2005      Bug 4718712 - Removed code setting t_fee_as_items(i).crs_version_number to
5678                                          p_crs_version_number when t_fee_as_items(i).course_cd is not null.
5679          pathipat       14-Oct-2005      Bug 4644004 - Retention amount is not calculated for increment charge method
5680                                          Added code to set t_fee_as_items(i).crs_version_number to p_crs_version_number
5681          uudayapr       14-Sep-2005      Bug 4609164 - passed the value of unit_class and unit_mode to the charges Api.
5682          pathipat       06-Sep-2005      Bug 4540295 - Fee assessment produce double fees after program version change
5683                                          Used t_Fee_as_items.crs_version_number for inserting into igs_fi_fee_as_items
5684                                          instead of the local variable l_crs_version_number.
5685          bannamal       08-Jul-2005      Enh#3392088 Campus Privilege Fee.
5686                                          Modified the tbh call to fee as items table to include two new columns.
5687          bannamal       03-Jun-2005      Bug#3442712 Unit Level Fee Assessment Build. Modified the call to igs_fi_fee_as_items_pkg.insert_row
5688                                          added new parameters unit_type_id, unit_class, unit_mode and unit_level.
5689          pathipat       07-Sep-2004      Enh 3880438 - Retention Enhancements build
5690                                          Removed condition checking if new amount < old amount before invoking finpl_chk_debt_ret_sched
5691          shtatiko       27-JUL-2004      Enh# 3787816, Replaced the call to finpl_charge_is_declined with igs_fi_gen_008.chk_chg_adj.
5692          pathipat       06-Jul-2004      Bug 3734842 - Added logic to check if records have been created correctly
5693                                          in IGS_FI_FEE_AS and IGS_FI_FEE_AS_ITEMS tables - added call to finpl_check_header_lines
5694          UUDAYAPR       17-DEC-2003      BUG#3080983 Modified V_assessment_amount,V_transaction_amount,p_fee_assessment
5695                                              To Number From Igs_fi_fee_ass_debt_v.Assessment_amount%Type,
5696                                                      V_manual_entry_ind To Varchar2(1)
5697                                                     v_last_effective_assessment_dt =  IGS_FI_FEE_ASS_DEBT_V.last_effective_assessment_dt%TYPE TO DATE;
5698                                          and also the Cursor c_fadv
5699          pathipat       01-Oct-2003      Bug 3164141 - Added check for Declined Charges
5700                                          Moved code for logging messages to before the actual insert happens
5701          pathipat       12-Sep-2003      Enh 3108052 - Unit Sets in Rate Table build
5702                                          Modified TBH call of igs_fi_fee_as_items
5703          vvutukur       26-May-2003      Enh#2831572.Financial Accounting Build. Assigned proper value to p_v_residency_cd before calling charges api.
5704          sarakshi       13-Sep-2002      Enh#2564643,removed teh reference of subaccount from this procedure
5705          VVUTUKUR       11-02-2002       Removed cursor l_c_invoice_id and related logic reg. the derivation of the source transaction ID.
5706                                          Since this part of covered  in Charges API. bug 2195715 as part of SFCR003
5707          rnirwani       17-apr-02        Before invocation to the charges api the orgunit code is also assigned to record group
5708                                          relating to lines entry for bug# 2317155
5709          ************************************************************************************************/
5710        -- Exception raised when insertion into IGS_FI_FEE_AS and IGS_FI_FEE_AS_ITEMS had some errors
5711           e_unexpected_error              EXCEPTION;
5712 
5713         BEGIN
5714           DECLARE
5715                 e_one_record_expected           EXCEPTION;
5716 
5717                 cst_assessment  CONSTANT        igs_fi_fee_as_all.s_transaction_type%TYPE := 'ASSESSMENT';
5718                 v_chg_rate                      IGS_FI_FEE_AS_RATE.chg_rate%TYPE;
5719                 v_chg_elements                  NUMBER;
5720                 v_course_cd                     igs_en_stdnt_ps_att_all.course_cd%TYPE;
5721                 v_message_name                  VARCHAR2(30);
5722 
5723                 l_source_invoice_id igs_fi_inv_int_all.invoice_id%TYPE;
5724                 l_invoice_id igs_fi_inv_int_all.invoice_id%TYPE;
5725                 l_header_rec  igs_fi_charges_api_pvt.header_rec_type;
5726                 l_line_rec    igs_fi_charges_api_pvt.line_tbl_type;
5727                 l_line_rec_dummy    igs_fi_charges_api_pvt.line_tbl_type;
5728                 l_line_id_tbl  igs_fi_charges_api_pvt.line_id_tbl_type;
5729                 l_line_id_tbl_dummy  igs_fi_charges_api_pvt.line_id_tbl_type;
5730                 l_status  VARCHAR2(1);
5731                 l_msg_count NUMBER;
5732                 l_msg_data VARCHAR2(2000);
5733 
5734                 l_crs_attempt_status  igs_fi_fee_as_items.course_attempt_status%TYPE;
5735 
5736                 v_rec_found             BOOLEAN;
5737                 l_v_invoice_number      igs_fi_inv_int_all.invoice_number%TYPE;
5738                 l_b_charge_declined     BOOLEAN;
5739                 l_v_elm_rng_ord_name    igs_fi_f_typ_ca_inst_all.elm_rng_order_name%TYPE;
5740                 l_v_chg_mthd_typ        igs_fi_f_cat_fee_lbl_all.s_chg_method_type%TYPE;
5741                 l_v_invoice_num         igs_fi_inv_int_all.invoice_number%TYPE;
5742                 l_n_waiver_amt          NUMBER;
5743 
5744                 CURSOR  c_chg_method ( cp_fee_cat                igs_fi_f_cat_fee_lbl_all.fee_cat%TYPE,
5745                                        cp_fee_type               igs_fi_f_cat_fee_lbl_all.fee_type%TYPE,
5746                                        cp_fee_cal_type           igs_fi_f_cat_fee_lbl_all.fee_cal_type%TYPE,
5747                                        cp_fee_ci_sequence_number igs_fi_f_cat_fee_lbl_all.fee_ci_sequence_number%TYPE) IS
5748                       SELECT s_chg_method_type, elm_rng_order_name
5749                       FROM igs_fi_f_cat_fee_lbl_v
5750                       WHERE fee_cat =  cp_fee_cat
5751                       AND fee_type =   cp_fee_type
5752                       AND fee_cal_type = cp_fee_cal_type
5753                       AND fee_ci_sequence_number = cp_fee_ci_sequence_number;
5754 
5755           BEGIN
5756                 log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
5757                             p_v_string => 'Entered finpl_ins_fee_ass. Parameters are: '
5758                                           || 'Person Id: '      || p_person_id
5759                                           || ', Course Cd: '    || p_course_cd
5760                                           || ', Fee Type: '     || p_fee_type
5761                                           || ', Fee Cal: '      || p_fee_cal_type
5762                                           || ', Fee Cal Seq: '  || p_fee_ci_sequence_number
5763                                           || ', Sys Fee Trig: ' || p_s_fee_trigger_cat
5764                                           || ', Fee Cat: '      || p_fee_cat
5765                                           || ', Curr: '         || p_currency
5766                                           || ', Chg Rate: '     || p_charge_rate
5767                                           || ', Sys Fee Type: ' || p_s_fee_type
5768                                           || ', Eff Date: '     || TO_CHAR(p_effective_dt, 'DD-MON-YYYY HH24:MI:SS')
5769                                           || ', Crs Vers: '     || p_crs_version_number
5770                                           || ', Att Mode: '     || p_attendance_mode
5771                                           || ', Att TYpe: '     || p_attendance_type
5772                                           || ', Chg Elements: ' || p_charge_elements
5773                                           || ', Fee As Amount: '|| p_fee_assessment
5774                                           || ', FCFL Status: '  || p_fcfl_status
5775                                           || ', FCFL Source: '  || g_v_fcfl_source );
5776 
5777                 IF p_fee_assessment <= 0 AND g_b_fee_chgs_exists = FALSE THEN
5778 
5779                   log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
5780                               p_v_string => 'Returning with message - Fee assessment transaction record not created.' );
5781                   RETURN;
5782                 END IF;
5783 
5784                 log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
5785                             p_v_string => 'Try inserting Fee As Transaction.' );
5786                 -- Enh# 3167098, For an Institution Fee, Course Code and Fee Category should be NULL (Only if Fee Calc Mthd is not Primary Career)
5787                 IF (p_s_fee_trigger_cat = gcst_institutn
5788                    AND g_c_fee_calc_mthd <> g_v_primary_career) THEN
5789                   v_fee_cat := NULL;
5790                   v_course_cd := NULL;
5791                 ELSE
5792                   v_fee_cat := p_fee_cat;
5793                   v_course_cd := p_course_cd;
5794                 END IF;
5795 
5796                 v_chg_rate := p_charge_rate;
5797                 v_chg_elements := p_charge_elements;
5798 
5799                 log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
5800                             p_v_string => 'Vars to be used: ' || v_fee_cat||','||v_course_cd||','||v_chg_rate||','||v_chg_elements );
5801                 DECLARE
5802                   lv_diff_amount igs_fi_fee_as_items.amount%type := 0;
5803                   lv_sum_diff    igs_fi_fee_as_items.amount%type := 0;
5804                   lv_as_record_ins boolean := FALSE;
5805                   lv_fee_ass_item_id              IGS_FI_FEE_AS_ITEMS.fee_ass_item_id%TYPE;
5806                   lv_as_items_rowid               VARCHAR2(25);
5807                   lv_as_rowid                     VARCHAR2(25);
5808                   lv_sum_old_amount               igs_fi_fee_as_all.transaction_amount%TYPE := 0;
5809                   lv_sum_new_amount               igs_fi_fee_as_all.transaction_amount%TYPE := 0;
5810                   l_v_fai_rowid                   VARCHAR2(25);
5811                   l_v_fee_as_item_dtl_id          NUMBER;
5812 
5813                 BEGIN
5814                         lv_sum_diff := 0;
5815 
5816                        log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
5817                                    p_v_string => 'Looping through records in PL/SQL Table.');
5818 
5819                         FOR i in 1..gv_as_item_cntr LOOP
5820                             lv_diff_amount := 0;
5821                             IF t_fee_as_items(i).fee_type = p_fee_type THEN
5822 
5823                                 -- A declined charge should not be considered for re-assessment
5824                                 l_b_charge_declined := FALSE;
5825                                 igs_fi_gen_008.chk_chg_adj(
5826                                      p_n_person_id              => p_person_id,
5827                                      p_v_location_cd            => t_fee_as_items(i).location_cd,
5828                                      p_v_course_cd              => t_fee_as_items(i).course_cd,
5829                                      p_v_fee_cal_type           => t_fee_as_items(i).fee_cal_type,
5830                                      p_v_fee_cat                => t_fee_as_items(i).fee_cat,
5831                                      p_n_fee_ci_sequence_number => t_fee_as_items(i).fee_ci_sequence_number,
5832                                      p_v_fee_type               => t_fee_as_items(i).fee_type,
5833                                      p_n_uoo_id                 => t_fee_as_items(i).uoo_id,
5834                                      p_v_transaction_type       => 'ASSESSMENT',
5835                                      p_n_invoice_id             => NULL,
5836                                      p_v_invoice_num            => l_v_invoice_number,
5837                                      p_b_chg_decl_rev           => l_b_charge_declined );
5838 
5839                                 IF l_b_charge_declined = FALSE  THEN
5840                                   /** check diff in amount**/
5841                                   lv_diff_amount :=  NVL(t_fee_as_items(i).amount,0) - NVL(t_fee_as_items(i).old_amount,0);
5842                                   lv_sum_old_amount := NVL(lv_sum_old_amount,0) +  NVL(t_fee_as_items(i).old_amount,0);
5843                                   lv_sum_new_amount := NVL(lv_sum_new_amount,0) +  NVL(t_fee_as_items(i).amount,0);
5844 
5845                                   log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
5846                                               p_v_string => 'Charge not declined. Charge level: Old: '
5847                                                             || NVL(t_fee_as_items(i).old_amount,0) || ', New Amt: '
5848                                                             || NVL(t_fee_as_items(i).amount,0) );
5849                                   log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
5850                                               p_v_string => 'Cumulative: Old: ' || lv_sum_old_amount || ', New: ' || lv_sum_new_amount);
5851 
5852                                   IF (NVL(lv_diff_amount,0) <> 0)  THEN
5853                                   /*** to set flag to true for insert into AS table only one record in AS table **/
5854                                      IF NOT lv_as_record_ins THEN
5855                                           lv_as_record_ins := TRUE;
5856                                      END IF;
5857                                     /** summing up the differential amount for insert into AS Table**/
5858                                     lv_sum_diff := NVL(lv_sum_diff,0) + NVL(lv_diff_amount,0);
5859                                   END IF;
5860                                 ELSE
5861                                   -- If charge is declined, then set status to 'D'.
5862                                   -- This record will not be processed, hence not inserted into the fee assessment tables
5863                                   t_fee_as_items(i).status := 'D';
5864                                   IF (p_trace_on = 'Y') THEN
5865                                     fnd_message.set_name('IGS', 'IGS_FI_SP_FEE_DECLINED');
5866                                     fnd_message.set_token('INVOICE_NUM', l_v_invoice_number);
5867                                     fnd_file.new_line(fnd_file.log);
5868                                     fnd_file.put_line(fnd_file.log, fnd_message.get);
5869                                   END IF;
5870                                   log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
5871                                               p_v_string => 'Charge (Number: ' || l_v_invoice_number || ') is declined.' );
5872                                 END IF;
5873                              END IF;  /** added by syam on 21-NOV-2000 to insert proper sum into amount of as table **/
5874                         END LOOP;
5875 
5876                         log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
5877                                     p_v_string => 'Total: lv_sum_new_amount:' || lv_sum_new_amount || ', lv_sum_old_amount' || lv_sum_old_amount);
5878 
5879                           -- As part of Retention Enhancements build, removed condition  "IF lv_sum_new_amount < lv_sum_old_amount THEN"
5880                           -- from here. Retention is invoked irrespective of old and new amounts.
5881                           -- Also passed p_fee_cat and p_course_cd instead of v_fee_cat and v_course_cd
5882                           log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
5883                                       p_v_string => 'Calling finpl_chk_debt_ret_sched');
5884                           finpl_chk_debt_ret_sched(p_person_id                => p_person_id,
5885                                                    p_fee_cat                  => p_fee_cat,
5886                                                    p_fee_type                 => p_fee_type,
5887                                                    p_fee_cal_type             => p_fee_cal_type,
5888                                                    p_fee_ci_sequence_number   => p_fee_ci_sequence_number,
5889                                                    p_course_cd                => p_course_cd,
5890                                                    p_crs_version_number       => p_crs_version_number,
5891                                                    p_course_attempt_status    => p_course_attempt_status,
5892                                                    p_old_ass_amount           => lv_sum_old_amount,
5893                                                    p_new_ass_amount           => lv_sum_new_amount,
5894                                                    p_trace_on                 => p_trace_on,
5895                                                    p_effective_date           => p_effective_dt,
5896                                                    p_d_gl_date                => TRUNC(p_d_gl_date),
5897                                                    p_v_s_fee_type             => p_s_fee_type,
5898                                                    p_n_rul_sequence_number    => p_n_rul_sequence_number,
5899                                                    p_n_scope_rul_seq_num      => p_n_scope_rul_seq_num,
5900                                                    p_v_chg_method_type        => p_v_chg_method_type,
5901                                                    p_s_fee_trigger_cat        => p_s_fee_trigger_cat,
5902                                                    p_v_location_cd            => p_v_location_cd,
5903                                                    p_v_career                 => p_v_career,
5904                                                    p_elm_rng_order_name       => p_elm_rng_order_name,
5905                                                    p_attendance_mode          => p_attendance_mode,
5906                                                    p_attendance_type          => p_attendance_type,
5907                                                    p_n_max_chg_elements       => p_n_max_chg_elements
5908                                                    );
5909 
5910                       -- modified as a part of fix for Bug # 2021281 (schodava)
5911                       -- adding the record for institution fee to the new pl/sql table
5912                       -- For a system fee trigger category of 'INSTITUTION',
5913                       -- If a record is found in the new pl/sql table for the person and FTCI,
5914                       -- then update the status of the record in the pl/sql table to the current status of the FCFL.
5915                       -- else, insert a record in the pl/sql table
5916                         v_rec_found := FALSE;
5917                         IF p_s_fee_trigger_cat = gcst_institutn THEN
5918                                   FOR l_cntr IN 1..g_inst_fee_rec_cntr LOOP
5919                                        IF p_person_id = l_inst_fee_rec(l_cntr).person_id
5920                                           AND p_fee_type = l_inst_fee_rec(l_cntr).fee_type
5921                                           AND p_fee_cal_type           = l_inst_fee_rec(l_cntr).fee_cal_type
5922                                           AND p_fee_ci_sequence_number = l_inst_fee_rec(l_cntr).fee_ci_sequence_number
5923                                           THEN
5924                                          log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
5925                                                      p_v_string => 'Institution Case: Updating status from '
5926                                                                    || l_inst_fee_rec(l_cntr).fcfl_status || ' to status ' || p_fcfl_status );
5927                                          l_inst_fee_rec(l_cntr).fcfl_status := p_fcfl_status;
5928                                          v_rec_found := TRUE;
5929                                          EXIT WHEN v_rec_found;
5930                                        END IF;
5931                                   END LOOP;
5932                                   IF v_rec_found = FALSE THEN
5933                                        log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
5934                                                    p_v_string => 'Institution Case: Adding record to l_inst_fee_rec.');
5935                                        g_inst_fee_rec_cntr := NVL(g_inst_fee_rec_cntr,0) + 1;
5936                                        l_inst_fee_rec(g_inst_fee_rec_cntr).person_id := p_person_id;
5937                                        l_inst_fee_rec(g_inst_fee_rec_cntr).fee_type := p_fee_type;
5938                                        l_inst_fee_rec(g_inst_fee_rec_cntr).fee_cal_type := p_fee_cal_type;
5939                                        l_inst_fee_rec(g_inst_fee_rec_cntr).fee_ci_sequence_number := p_fee_ci_sequence_number;
5940                                        l_inst_fee_rec(g_inst_fee_rec_cntr).fcfl_status := p_fcfl_status;
5941                                   END IF;
5942                         END IF;
5943 
5944                         IF lv_as_record_ins THEN
5945                                 DECLARE
5946                                    l_n_org_id  igs_fi_fee_As_all.ORG_ID%TYPE := igs_ge_gen_003.get_org_id;
5947 
5948                                 BEGIN
5949                                        log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
5950                                                    p_v_string => 'Trying to insert records..');
5951                                        -- If Fee Assessment Debt record has been found (from cursor c_fadv)
5952                                         -- Message: Inserting Fee Assessment Transaction
5953 
5954                                   log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
5955                                               p_v_string => 'Inserting Fee As Record for Amount: ' || lv_sum_diff );
5956                                 --  Modified transaction_dt entry as Trunc(Sysdate) as part of Bug 4240402: Timezone impact
5957                                   igs_fi_fee_as_pkg.insert_row(
5958                                                 x_rowid                   => lv_as_rowid,
5959                                                 x_person_id               => p_person_id,
5960                                                 x_transaction_id          => v_fa_sequence_number,
5961                                                 x_fee_type                => p_fee_type,
5962                                                 x_fee_cal_type            => p_fee_cal_type,
5963                                                 x_fee_ci_sequence_number  => p_fee_ci_sequence_number,
5964                                                 x_fee_cat                 => v_fee_cat,
5965                                                 x_s_transaction_type      => cst_assessment,
5966                                                 x_transaction_dt          => TRUNC(SYSDATE),
5967                                                 x_transaction_amount      => igs_fi_gen_gl.get_formatted_amount(NVL(lv_sum_diff,0)),
5968                                                 x_currency_cd             => p_currency,
5969                                                 x_exchange_rate           => 1,
5970                                                 x_chg_elements            => v_chg_elements,
5971                                                 x_effective_dt            => TRUNC(p_effective_dt),
5972                                                 x_course_cd               => v_course_cd,
5973                                                 x_notification_dt         => NULL,
5974                                                 x_logical_delete_dt       => NULL,
5975                                                 x_comments                => NULL,
5976                                                 x_mode                    => 'R',
5977                                                 x_org_id                  => l_n_org_id );
5978 
5979                                      IF (p_trace_on = 'Y') THEN
5980                                         fnd_message.set_name('IGS', 'IGS_FI_STUDFEE_ASSESSED_PRG');
5981                                         fnd_file.put_line (fnd_file.log, fnd_message.get);
5982                                         fnd_file.new_line(fnd_file.log);
5983                                      END IF;
5984 
5985                                 END;
5986 
5987                                 FOR i in 1..gv_as_item_cntr LOOP
5988                                     lv_diff_amount := 0;
5989                                     IF t_fee_as_items(i).fee_type = p_fee_type THEN
5990                                           -- The status is set to 'D' if the charge has been declined
5991                                           -- In such a case no further processing happens for that charge
5992                                           IF t_fee_as_items(i).status <> 'D' THEN
5993                                                 /** check diff in amount**/
5994                                                 lv_diff_amount :=  NVL(t_fee_as_items(i).amount,0) - NVL(t_fee_as_items(i).old_amount,0);
5995                                                 IF (nvl(lv_diff_amount,0) <> 0)  THEN
5996                                                     /*** to insert all records  in AS  ITEMs table with difference in amount ***/
5997                                                     OPEN  c_chg_method (t_fee_as_items(i).fee_cat,
5998                                                                         t_fee_as_items(i).fee_type,
5999                                                                         t_fee_as_items(i).fee_cal_type,
6000                                                                         t_fee_as_items(i).fee_ci_sequence_number);
6001                                                     FETCH c_chg_method INTO l_v_chg_mthd_typ, l_v_elm_rng_ord_name;
6002                                                     CLOSE c_chg_method;
6003 
6004                                                     IF t_fee_as_items(i).chg_method_type is NULL THEN
6005                                                         t_fee_as_items(i).chg_method_type := l_v_chg_mthd_typ;
6006                                                     END IF;
6007 
6008                                                     IF t_fee_as_items(i).course_cd IS NULL THEN
6009                                                         t_fee_as_items(i).crs_version_number := NULL;
6010                                                         l_crs_attempt_status     := NULL;
6011                                                     END IF;
6012                                                     -- setting the values for the header record variable to be passed to
6013                                                     -- charges API. bug # 1851586
6014 
6015                                                     l_header_rec.p_person_id                  := t_fee_as_items(i).person_id;
6016                                                     l_header_rec.p_fee_type                   := t_fee_as_items(i).fee_type;
6017                                                     l_header_rec.p_fee_cat                    := t_fee_as_items(i).fee_cat;
6018                                                     l_header_rec.p_fee_cal_type               := t_fee_as_items(i).fee_cal_type;
6019                                                     l_header_rec.p_fee_ci_sequence_number     := t_fee_as_items(i).fee_ci_sequence_number;
6020                                                     l_header_rec.p_course_cd                  := t_fee_as_items(i).course_cd;
6021                                                     l_header_rec.p_attendance_type            := p_attendance_type;
6022                                                     l_header_rec.p_attendance_mode            := p_attendance_mode;
6023                                                     l_header_rec.p_invoice_amount             := nvl(lv_diff_amount,0);
6024                                                     l_header_rec.p_invoice_creation_date      := SYSDATE;
6025                                                     l_header_rec.p_invoice_desc               := t_fee_as_items(i).description;
6026                                                     l_header_rec.p_transaction_type           := cst_assessment;
6027                                                     l_header_rec.p_currency_cd                := p_currency;
6028                                                     l_header_rec.p_exchange_rate              := 1;
6029                                                     l_header_rec.p_effective_date             := p_effective_dt;
6030                                                     l_header_rec.p_waiver_flag                := NULL;
6031                                                     l_header_rec.p_waiver_reason              := NULL;
6032                                                     l_header_rec.p_source_transaction_id      := NULL;
6033 
6034                                                     --initializing the line record variable
6035                                                     l_line_rec := l_line_rec_dummy;
6036 
6037                                                     -- setting the values for the line record variable to bne passed to the
6038                                                     -- charges API bug # 1851586
6039                                                     l_line_rec(1).p_s_chg_method_type     := t_fee_as_items(i).chg_method_type;
6040                                                     l_line_rec(1).p_description           := t_fee_as_items(i).description;
6041                                                     l_line_rec(1).p_chg_elements          := t_fee_as_items(i).chg_elements;
6042                                                     l_line_rec(1).p_amount                := nvl(lv_diff_amount,0);
6043                                                     l_line_rec(1).p_unit_attempt_status   := t_fee_as_items(i).unit_attempt_status;
6044                                                     l_line_rec(1).p_eftsu                 := t_fee_as_items(i).eftsu;
6045                                                     l_line_rec(1).p_credit_points         := t_fee_as_items(i).credit_points;
6046                                                     l_line_rec(1).p_org_unit_cd           := t_fee_as_items(i).org_unit_cd;
6047                                                     l_line_rec(1).p_location_cd           := t_fee_as_items(i).location_cd;
6048                                                     l_line_rec(1).p_uoo_id                := t_fee_as_items(i).uoo_id;
6049                                                     l_line_rec(1).p_d_gl_date             := TRUNC(p_d_gl_date);
6050                                                     l_line_rec(1).p_residency_status_cd   := t_fee_as_items(i).residency_status_cd;
6051                                                     l_line_rec(1).p_unit_type_id          := t_fee_as_items(i).unit_type_id;
6052                                                     l_line_rec(1).p_unit_level            := t_fee_as_items(i).unit_level;
6053                                                     l_line_rec(1).p_unit_class            := t_fee_as_items(i).unit_class;
6054                                                     l_line_rec(1).p_unit_mode             := t_fee_as_items(i).unit_mode;
6055                                                     -- initializing the line id variable which would accept the out NOCOPY values from the chargtes API
6056                                                     l_line_id_tbl := l_line_id_tbl_dummy;
6057 
6058                                                     -- invoking the charges API to create a charge against the assessment done.
6059                                                     log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
6060                                                                 p_v_string => 'Inserting Charge for Amount: ' || lv_diff_amount );
6061                                                     igs_fi_charges_api_pvt.create_charge(
6062                                                                 p_api_version => 2.0,
6063                                                                 p_init_msg_list => 'F',
6064                                                                 p_commit => 'F',
6065                                                                 p_header_rec => l_header_rec,
6066                                                                 p_line_tbl => l_line_rec,
6067                                                                 x_invoice_id => l_invoice_id,
6068                                                                 x_line_id_tbl => l_line_id_tbl,
6069                                                                 x_return_status => l_status,
6070                                                                 x_msg_count => l_msg_count,
6071                                                                 x_msg_data => l_msg_data,
6072                                                                 x_waiver_amount => l_n_waiver_amt);
6073 
6074                                                       -- If status returned by the Charges API is not 'S' then raise exception
6075                                                       IF l_status <> 'S' THEN
6076                                                           log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
6077                                                                       p_v_string => 'Charges API returned with status <> S, stack message and raise exception');
6078 
6079                                                           IF l_msg_count = 1 THEN
6080                                                                fnd_message.set_encoded(l_msg_data);
6081                                                           ELSIF l_msg_count > 1 THEN
6082                                                                FOR l_n_cntr IN 1 .. l_msg_count
6083                                                                LOOP
6084                                                                     fnd_message.set_encoded(fnd_msg_pub.get (p_msg_index => l_n_cntr,
6085                                                                                                              p_encoded => 'T')
6086                                                                                             );
6087                                                                END LOOP;
6088                                                           END IF;
6089                                                           app_exception.raise_exception;
6090                                                       END IF;
6091 
6092                                                       IF (p_trace_on = 'Y') THEN
6093                                                         -- Trace Entry
6094                                                         IF lv_diff_amount > 0 THEN
6095                                                           l_v_invoice_num := igs_fi_gen_008.get_invoice_number(l_invoice_id);
6096                                                           fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'CHARGE_NUMBER') || ': ' || l_v_invoice_num);
6097                                                           fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'CHG_AMOUNT') || ': ' || TO_CHAR(NVL(lv_diff_amount, 0)));
6098                                                           fnd_file.new_line(fnd_file.log);
6099                                                         END IF;
6100                                                       END IF;
6101 
6102                                                       IF (p_s_fee_trigger_cat = gcst_institutn) THEN
6103                                                         t_fee_as_items(i).residency_status_cd := NULL;
6104                                                       END IF;
6105 
6106                                                         -- if the error status returned by tehe charges API is success then the insert
6107                                                         -- to the lines table is made by passing the invoice id.
6108                                                             lv_as_items_rowid := NULL;
6109                                                             log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
6110                                                                         p_v_string => 'Inserting Fee Assessment Items Record.');
6111 
6112                                                             igs_fi_fee_as_items_pkg.insert_row(
6113                                                                   x_rowid               =>   lv_as_items_rowid,
6114                                                                   x_fee_ass_item_id     =>   lv_fee_ass_item_id,
6115                                                                   x_transaction_id      =>   v_fa_sequence_number,
6116                                                                   x_person_id           =>   t_fee_as_items(i).person_id,
6117                                                                   x_status              =>   t_fee_as_items(i).status,
6118                                                                   x_fee_type            =>   t_fee_as_items(i).fee_type,
6119                                                                   x_fee_cat             =>   t_fee_as_items(i).fee_cat ,
6120                                                                   x_fee_cal_type        =>   t_fee_as_items(i).fee_cal_type ,
6121                                                                   x_fee_ci_sequence_number => t_fee_as_items(i).fee_ci_sequence_number,
6122                                                                   x_rul_sequence_number =>    t_fee_as_items(i).rul_sequence_number,
6123                                                                   x_s_chg_method_type   =>   t_fee_as_items(i).chg_method_type,
6124                                                                   x_description         =>   t_fee_as_items(i).description,
6125                                                                   x_chg_elements        =>   t_fee_as_items(i).chg_elements,
6126                                                                   x_amount              =>   igs_fi_gen_gl.get_formatted_amount(NVL(lv_diff_amount,0)),
6127                                                                   x_fee_effective_dt    =>   TRUNC(p_effective_dt),
6128                                                                   x_course_cd           =>   t_fee_as_items(i).course_cd,
6129                                                                   x_crs_version_number =>    t_fee_as_items(i).crs_version_number,
6130                                                                   x_course_attempt_status => l_crs_attempt_status,
6131                                                                   x_attendance_mode     =>   p_attendance_mode,
6132                                                                   x_attendance_type     =>   p_attendance_type,
6133                                                                   x_unit_attempt_status =>   t_fee_as_items(i).unit_attempt_status,
6134                                                                   x_location_cd         =>   t_fee_as_items(i).location_cd,
6135                                                                   x_eftsu               =>   t_fee_as_items(i).eftsu,
6136                                                                   x_credit_points       =>   t_fee_as_items(i).credit_points,
6137                                                                   x_logical_delete_date =>   null,
6138                                                                   X_INVOICE_ID          => l_invoice_id,
6139                                                                   x_org_unit_cd         =>  t_fee_as_items(i).org_unit_cd,
6140                                                                   x_class_standing      =>  t_fee_as_items(i).class_standing,
6141                                                                   x_residency_status_cd =>  t_fee_as_items(i).residency_status_cd,
6142                                                                   x_uoo_id              => t_fee_as_items(i).uoo_id,
6143                                                                   x_chg_rate            => igs_fi_gen_gl.get_formatted_amount(t_fee_as_items(i).chg_rate),
6144                                                                   x_unit_set_cd         => t_fee_as_items(i).unit_set_cd,
6145                                                                   x_us_version_number   => t_fee_as_items(i).us_version_number,
6146                                                                   x_unit_type_id        => t_fee_as_items(i).unit_type_id,
6147                                                                   x_unit_class          => t_fee_as_items(i).unit_class,
6148                                                                   x_unit_mode           => t_fee_as_items(i).unit_mode,
6149                                                                   x_unit_level          => t_fee_as_items(i).unit_level,
6150                                                                   x_scope_rul_sequence_num => p_n_scope_rul_seq_num,
6151                                                                   x_elm_rng_order_name  => l_v_elm_rng_ord_name,
6152                                                                   x_max_chg_elements    => p_n_max_chg_elements
6153                                                                   );
6154 
6155                                                                 -- Code for addition of a record in the new pl/sql table
6156                                                                 -- for 'INSTIUTION' fee trigger category is moved from here
6157                                                                 -- to above, before the call to IGS_FI_FEE_AS_PKG.insert_row
6158                                                                 -- This was to handle the case, where NO adjustment was required for the fee.
6159                                                                 -- In this case, the code present at this point was not accessed,
6160                                                                 -- and no record was being created in the pl/sql table. (Bug # 2021281) schodava
6161                                                 END IF;  -- End if for (nvl(lv_diff_amount,0) <> 0)
6162                                         END IF;  -- End if for t_fee_as_items(i).status <> 'D'
6163                                     END IF; -- End if for t_fee_as_items(i).fee_type = p_fee_type
6164                                 END LOOP;
6165 
6166                                 FOR j IN 1..tbl_fai_unit_dtls.COUNT
6167                                 LOOP
6168                                   l_v_fai_rowid := NULL;
6169                                   l_v_fee_as_item_dtl_id := NULL;
6170                                   log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
6171                                   p_v_string => 'Inserting record in IGS_FI_FAI_DTLS with UOO_ID: '||tbl_fai_unit_dtls(j).uoo_id||
6172                                                 ' for Fee Assessment Item ID: '||lv_fee_ass_item_id);
6173                                   igs_fi_fai_dtls_pkg.insert_row(
6174                                                           x_rowid                 => l_v_fai_rowid,
6175                                                           x_fee_as_item_dtl_id    => l_v_fee_as_item_dtl_id,
6176                                                           x_fee_ass_item_id       => lv_fee_ass_item_id,
6177                                                           x_fee_cat              => tbl_fai_unit_dtls(j).fee_cat,
6178                                                           x_course_cd             => tbl_fai_unit_dtls(j).course_cd,
6179                                                           x_crs_version_number    => tbl_fai_unit_dtls(j).crs_version_number,
6180                                                           x_unit_attempt_status   => tbl_fai_unit_dtls(j).unit_attempt_status,
6181                                                           x_org_unit_cd           => tbl_fai_unit_dtls(j).org_unit_cd,
6182                                                           x_class_standing        => tbl_fai_unit_dtls(j).class_standing,
6183                                                           x_location_cd           => tbl_fai_unit_dtls(j).location_cd,
6184                                                           x_uoo_id                => tbl_fai_unit_dtls(j).uoo_id,
6185                                                           x_unit_set_cd           => tbl_fai_unit_dtls(j).unit_set_cd,
6186                                                           x_us_version_number     => tbl_fai_unit_dtls(j).us_version_number,
6187                                                           x_chg_elements          => tbl_fai_unit_dtls(j).chg_elements
6188                                                           );
6189                                 END LOOP;
6190 
6191                                 log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
6192                                             p_v_string => 'Checking if Header and Lines match, calling finpl_check_header_lines');
6193                                 -- Check if records have been created correctly in IGS_FI_FEE_AS and IGS_FI_FEE_AS_ITEMS
6194                                 IF NOT finpl_check_header_lines(p_person_id,v_fa_sequence_number) THEN
6195                                      -- Any error in Header and Lines records, raise error
6196                                      log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
6197                                                  p_v_string => 'Header and Lines do not match, RAISE e_unexpected_error');
6198                                      RAISE e_unexpected_error;
6199                                 END IF;
6200 
6201                         END IF;  /** end if for lv_as_record_ins **/
6202                 END;
6203           END;
6204           EXCEPTION
6205              WHEN e_unexpected_error THEN
6206 
6207                 IF g_v_wav_calc_flag = 'N' THEN
6208                   ROLLBACK TO fee_calc_sp;
6209                 END IF;
6210                 log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
6211                             p_v_string => 'From Exception Handler of e_unexpected_error.');
6212                 fnd_message.set_name ('IGS', 'IGS_GE_UNEXPECTED_ERR');
6213                 igs_ge_msg_stack.add;
6214                 app_exception.raise_exception(NULL, NULL, fnd_message.get);
6215 
6216              WHEN e_one_record_expected THEN
6217                 IF g_v_wav_calc_flag = 'N' THEN
6218                   ROLLBACK TO fee_calc_sp;
6219                 END IF;
6220                 log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
6221                             p_v_string => 'From Exception Handler of e_one_record_expected.' || SUBSTR(sqlerrm,1,500));
6222                 Fnd_Message.Set_Name ('IGS', 'IGS_GE_UNHANDLED_EXP');
6223                 Fnd_Message.Set_Token('NAME','IGS_FI_PRC_FEE_ASS.FINPL_INS_FEE_ASS-'||SUBSTR(sqlerrm,1,500));
6224                 IGS_GE_MSG_STACK.ADD;
6225                   App_Exception.Raise_Exception(Null, Null, fnd_message.get);
6226              WHEN OTHERS THEN
6227                 IF g_v_wav_calc_flag = 'N' THEN
6228                   ROLLBACK TO fee_calc_sp;
6229                 END IF;
6230                 log_to_fnd( p_v_module => 'finpl_ins_fee_ass',
6231                             p_v_string => 'From Exception Handler of When Others.' || SUBSTR(sqlerrm,1,500));
6232                 Fnd_Message.Set_Name ('IGS', 'IGS_GE_UNHANDLED_EXP');
6233                 Fnd_Message.Set_Token('NAME','IGS_FI_PRC_FEE_ASS.FINPL_INS_FEE_ASS-'||SUBSTR(sqlerrm,1,500));
6234                 IGS_GE_MSG_STACK.ADD;
6235                   App_Exception.Raise_Exception;
6236           END finpl_ins_fee_ass;
6237 
6238     -------------------------------------------------------------------------------
6239         FUNCTION finpl_prc_sua_load (
6240                 p_effective_dt                          DATE,
6241                 p_trace_on                              VARCHAR2,
6242                 p_person_id                             hz_parties.party_id%TYPE,
6243                 p_course_cd                             igs_en_stdnt_ps_att_all.course_cd%TYPE,
6244                 p_course_version_number                 igs_en_stdnt_ps_att_all.version_number%TYPE,
6245                 p_unit_cd                               igs_en_su_attempt_h_all.unit_cd%TYPE,
6246                 p_unit_version_number                   igs_en_su_attempt_h_all.version_number%TYPE,
6247                 p_cal_type                              igs_en_su_attempt_h_all.CAL_TYPE%TYPE,
6248                 p_effective_start_dt                    igs_en_su_attempt_h_all.hist_start_dt%TYPE,
6249                 p_effective_end_dt                      igs_en_su_attempt_h_all.hist_end_dt%TYPE,
6250                 p_eftsu                                 igs_fi_fee_as_items.eftsu%TYPE,
6251                 p_credit_points                         igs_fi_fee_as_items.credit_points%TYPE,
6252                 p_s_fee_type                            igs_fi_fee_type_all.s_fee_type%TYPE,
6253                 p_charge_method                         igs_fi_f_typ_ca_inst_all.s_chg_method_type%TYPE,
6254                 p_fee_type                              IGS_FI_FEE_AS_ITEMS.FEE_TYPE%TYPE ,
6255                 p_fee_cat                               IGS_FI_FEE_AS_ITEMS.FEE_CAT%TYPE,
6256                 p_fee_cal_type                          IGS_FI_FEE_AS_ITEMS.FEE_CAL_TYPE%TYPE,
6257                 p_fee_ci_sequence_number                IGS_FI_FEE_AS_ITEMS.fee_ci_sequence_number%TYPE,
6258                 p_unit_attempt_status                   IGS_FI_FEE_AS_ITEMS.unit_attempt_status%TYPE,
6259                 p_location_cd                   IGS_FI_FEE_AS_ITEMS.location_cd%TYPE,
6260                 p_ci_sequence_number                    IGS_FI_FEE_AS_ITEMS.ci_sequence_number%TYPE,
6261                 p_charge_elements               IN OUT NOCOPY   igs_fi_fee_as_all.chg_elements%TYPE,
6262                 p_ret_true_flag                 OUT NOCOPY      BOOLEAN,
6263                 p_message_name                  OUT NOCOPY      VARCHAR2,
6264                 p_s_fee_trigger_cat                     igs_fi_fee_type_all.s_fee_trigger_cat%TYPE,
6265                 p_uoo_id                                IGS_FI_FEE_AS_ITEMS.UOO_ID%TYPE,
6266                 p_unit_course_cd                        igs_ps_ver_all.course_cd%TYPE,
6267                 p_n_unit_type_id                        igs_fi_fee_as_items.unit_type_id%TYPE,
6268                 p_v_unit_level                          igs_fi_fee_as_items.unit_level%TYPE,
6269                 p_v_unit_mode                           igs_fi_fee_as_items.unit_mode%TYPE
6270                 )         RETURN BOOLEAN  AS
6271                         -- added the parameter p_s_fee_trigger_cat Bug# 1906022
6272                         -- since certain processing here would vary for the fee trigger
6273                         -- generally special handling for INSTITUTN trigger
6274         BEGIN
6275           DECLARE
6276                 v_message_name                  VARCHAR2(30);
6277                 v_derived_org_unit_cd           IGS_FI_FEE_AS_ITEMS.org_unit_cd%TYPE;
6278 
6279                 l_v_no_assessment_ind           igs_en_su_attempt_all.no_assessment_ind%TYPE;
6280                 l_n_eftsu                       igs_fi_fee_as_items.eftsu%TYPE;
6281                 l_n_credit_points  igs_fi_fee_as_items.credit_points%TYPE;
6282 
6283 
6284                 CURSOR c_unit_class_att (cp_person_id           igs_en_su_attempt_all.person_id%TYPE,
6285                                         cp_course_cd            igs_en_su_attempt_all.course_cd%TYPE,
6286                                         cp_uoo_id              igs_en_su_attempt_all.uoo_id%TYPE ) IS
6287                         SELECT  unit_class, no_assessment_ind
6288                         FROM    igs_en_su_attempt_all
6289                         WHERE   person_id = cp_person_id
6290                         AND     course_cd = cp_course_cd
6291                         AND     uoo_id = cp_uoo_id;
6292 
6293                 lv_unit_class_att       igs_en_su_attempt_all.unit_class%TYPE;
6294 
6295   -- Added by schodava as a part of the CCR for the Fee Calc (Enh # 1851586) DLD
6296   -- To find the organization unit code from the Student Attempt Table (For Charge Method of
6297   -- CREDIT_POINT or PERUNIT)
6298   CURSOR  c_org_unit_cd(cp_person_id IN igs_en_su_attempt_all.person_id%TYPE,
6299                         cp_course_cd in igs_en_su_attempt_all.course_cd%TYPE,
6300                         cp_uoo_id IN igs_en_su_attempt_all.uoo_id%TYPE
6301                         ) IS
6302   SELECT  org_unit_cd   -- this column needs to be added as yet to the table as a part of Nov 2001 Build
6303   FROM    igs_en_su_attempt_all su
6304   WHERE   su.person_id = cp_person_id
6305   AND     su.course_cd = cp_course_cd
6306   AND     su.uoo_id   = cp_uoo_id;
6307 
6308   -- To find the organization unit code from the Student Attempt Table (For Charge Method of
6309   -- CREDIT_POINT or PERUNIT)Note : If the above cursor c_org_unit_cd returns no rows,the
6310   -- Organization Unit Code from this cursor is used.
6311   CURSOR c_org_unit_sec_cd(cp_unit_cd IN igs_ps_unit_ofr_opt_all.unit_cd%TYPE,
6312                            cp_version_number IN igs_ps_unit_ofr_opt_all.version_number%TYPE,
6313                            cp_cal_type IN igs_ps_unit_ofr_opt_all.cal_type%TYPE,
6314                            cp_ci_sequence_number IN igs_ps_unit_ofr_opt_all.ci_sequence_number%TYPE,
6315                            cp_location_cd IN igs_ps_unit_ofr_opt_all.location_cd%TYPE,
6316                            cp_unit_class IN igs_ps_unit_ofr_opt_all.unit_class%TYPE
6317                           ) IS
6318   SELECT owner_org_unit_cd -- this column is added as a part of Unit Section Reference information Build
6319   FROM   igs_ps_unit_ofr_opt_all uoo
6320   WHERE  uoo.unit_cd            = cp_unit_cd
6321   AND    uoo.version_number     = cp_version_number
6322   AND    uoo.cal_type           = cp_cal_type
6323   AND    uoo.ci_sequence_number = cp_ci_sequence_number
6324   AND    uoo.location_cd        = cp_location_cd
6325   AND    uoo.unit_class         = cp_unit_class;
6326 
6327   -- To find the organization unit code from the Prgoram Version Table (For Charge Method of
6328   -- FLATRATE)
6329   CURSOR c_resp_org_unit_cd(cp_course_cd IN igs_ps_ver_all.course_cd%TYPE,
6330                             cp_version_number IN igs_ps_ver_all.version_number%TYPE
6331                            )IS
6332   SELECT responsible_org_unit_cd
6333   FROM   igs_ps_ver_all v
6334   WHERE  v.course_cd            = cp_course_cd
6335   AND    v.version_number       = cp_version_number;
6336 
6337   -- End of Additions made by schodava as a part of Fee Calc CCR
6338   BEGIN
6339                 log_to_fnd( p_v_module => 'finpl_prc_sua_load',
6340                             p_v_string => 'Entered finpl_prc_sua_load. Parameters are: '
6341                                           || 'Effective Dt: '   || TO_CHAR(p_effective_dt, 'DD-MON-YYYY HH24:MI:SS')
6342                                           || ', Person Id: '    || p_person_id
6343                                           || ', Course Cd: '    || p_course_cd
6344                                           || ', Course Ver: '   || p_course_version_number
6345                                           || ', Unit Cd: '      || p_unit_cd
6346                                           || ', Unit Ver: '     || p_unit_version_number
6347                                           || ', Cal Type: '     || p_cal_type
6348                                           || ', Eff St Dt: '    || TO_CHAR(p_effective_start_dt, 'DD-MON-YYYY HH24:MI:SS')
6349                                           || ', Eff End Dt: '   || TO_CHAR(p_effective_end_dt, 'DD-MON-YYYY HH24:MI:SS')
6350                                           || ', Eftsu: '        || p_eftsu
6351                                           || ', Cr Points: '    || p_credit_points
6352                                           || ', Sys Fee Type: ' || p_s_fee_type
6353                                           || ', Chg Mthd: '     || p_charge_method
6354                                           || ', Fee Type: '     || p_fee_type
6355                                           || ', Fee Cat: '      || p_fee_cat
6356                                           || ', Fee Cal Type: ' || p_fee_cal_type
6357                                           || ', Fee Cal Seq Num: ' || p_fee_ci_sequence_number
6358                                           || ', Unit Att Stat: '|| p_unit_attempt_status
6359                                           || ', Loc Cd: '       || p_location_cd
6360                                           || ', Ci Seq Num: '   || p_ci_sequence_number
6361                                           || ', Chg Elms: '     || p_charge_elements
6362                                           || ', Sys Fee Trig Cat: ' || p_s_fee_trigger_cat
6363                                           || ', Uoo Id: '       || p_uoo_id
6364                                           || ', Unit Crs Cd: '  || p_unit_course_cd );
6365                 -- Initialize the OUT variable with FALSE
6366                 p_ret_true_flag := FALSE;
6367                 OPEN c_unit_class_att ( p_person_id     ,
6368                                         p_unit_course_cd,
6369                                         p_uoo_id );
6370                 FETCH c_unit_class_att INTO lv_unit_class_att, l_v_no_assessment_ind;
6371                 CLOSE c_unit_class_att;
6372 
6373                 IF (p_trace_on = 'Y') THEN
6374                      -- Trace Entry
6375                      IF (p_charge_method = gcst_flatrate) THEN
6376                              NULL;
6377                      ELSE
6378                           fnd_file.new_line(fnd_file.log);
6379                           fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_TRIGGER_GROUP', 'UNIT') || ': ' || p_unit_cd);
6380                           fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'TEACH_CAL_ALT_CD') || ': ' || p_cal_type ||
6381                                                            '  ' || TO_CHAR(p_effective_start_dt,'DD/MM/YYYY') ||
6382                                                            '  ' || TO_CHAR(p_effective_end_dt,'DD/MM/YYYY'));
6383                           fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_ACCT_ENTITIES', 'LOC') || ': ' || p_location_cd);
6384                           fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'UNIT_CLASS') || ': ' || lv_unit_class_att);
6385                           fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'AUDITED') || ': ' || l_v_no_assessment_ind);
6386                           IF ((p_unit_cd IS NOT NULL) AND (p_unit_version_number IS NOT NULL)) THEN
6387                              fnd_message.set_name('IGS', 'IGS_FI_UNIT_CD_VERSION');
6388                              fnd_message.set_token('UNIT_CD', p_unit_cd);
6389                              fnd_message.set_token('UNIT_VER', TO_CHAR(p_unit_version_number));
6390                              fnd_file.put_line (fnd_file.log, fnd_message.get);
6391                           END IF;
6392                           IF (p_n_unit_type_id IS NULL) THEN
6393                              fnd_message.set_name('IGS', 'IGS_FI_NO_UNIT_TYPE');
6394                              fnd_file.put_line (fnd_file.log, fnd_message.get);
6395                           ELSE
6396                              fnd_file.put_line (fnd_file.log,
6397                                                 igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'UNIT_PROG_TYP') ||
6398                                                 ': ' || finpl_get_uptl(p_n_unit_type_id));
6399                           END IF;
6400                           fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'UNIT_LEVEL') || ': ' || p_v_unit_level);
6401                           IF (p_v_unit_mode IS NULL) THEN
6402                             fnd_message.set_name('IGS', 'IGS_FI_NO_UNIT_MODE');
6403                             fnd_file.put_line (fnd_file.log, fnd_message.get);
6404                           ELSE
6405                             fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'UNIT_MODE') || ': ' || p_v_unit_mode);
6406                           END IF;
6407                      END IF;
6408                 END IF;
6409 
6410               v_derived_org_unit_cd := NULL;
6411               -- For Non Institution Fee, check for Org Unit Cd first at Unit level then at Unit Section
6412               -- Note: Org Unit Code WILL exists at least one level.
6413               -- For Flat Rate, Fetch it from Program Level.
6414               IF (p_charge_method <> gcst_flatrate) THEN  --Enh# 2162747, Derive the Org_Unit_cd at Unit Level or Unit Section Level only when the Charge Method is not Flat Rate
6415                 log_to_fnd( p_v_module => 'finpl_prc_sua_load',
6416                             p_v_string => 'Other Than Flat Rate. Try for Org Unit code from Unit and Unit Section levels.' );
6417                 OPEN c_org_unit_cd(p_person_id,
6418                                    p_unit_course_cd, --Enh#2162747 Changed p_course_cd to p_unit_course_cd
6419                                    p_uoo_id);
6420                 FETCH c_org_unit_cd INTO v_derived_org_unit_cd;
6421                 CLOSE c_org_unit_cd;
6422 
6423                 IF v_derived_org_unit_cd IS NOT NULL THEN
6424                   IF (p_trace_on = 'Y') THEN
6425                     fnd_message.set_name ( 'IGS', 'IGS_FI_ORG_UNIT');
6426                     fnd_message.set_token('ORG_UNIT_CD',v_derived_org_unit_cd );
6427                     fnd_file.put_line (fnd_file.log, fnd_message.get);
6428                   END IF;
6429 
6430                 ELSE
6431                   -- Couldn't derive from Unit level, try at Unit Section
6432                   OPEN c_org_unit_sec_cd(p_unit_cd,
6433                                          p_unit_version_number,
6434                                          p_cal_type,
6435                                          p_ci_sequence_number,
6436                                          p_location_cd,
6437                                          lv_unit_class_att);
6438                   FETCH c_org_unit_sec_cd INTO v_derived_org_unit_cd;
6439                   CLOSE c_org_unit_sec_cd;
6440                   IF v_derived_org_unit_cd IS NOT NULL THEN
6441                     IF (p_trace_on = 'Y') THEN
6442                       fnd_message.set_name ( 'IGS', 'IGS_FI_ORG_UNIT');
6443                       fnd_message.set_token('ORG_UNIT_CD',v_derived_org_unit_cd);
6444                       fnd_file.put_line (fnd_file.log, fnd_message.get);
6445                     END IF;
6446                   ELSE
6447                     v_message_name := 'IGS_FI_NO_ORG_UNIT';
6448                     IF (p_trace_on = 'Y') THEN
6449                       fnd_message.set_name('IGS', v_message_name);
6450                       fnd_message.set_token('UNIT_CD', p_unit_cd);
6451                       fnd_file.put_line (fnd_file.log, fnd_message.get);
6452                     END IF;
6453                     log_to_fnd( p_v_module => 'finpl_prc_sua_load',
6454                                 p_v_string => 'Other than Flat Rate: Could not derive Org Unit Code.' );
6455                   END IF;
6456                 END IF;
6457                 log_to_fnd( p_v_module => 'finpl_prc_sua_load',
6458                             p_v_string => 'Other than Flat Rate: Derived Org Unit cd: ' || v_derived_org_unit_cd );
6459               END IF;
6460 
6461                 IF (p_charge_method = gcst_flatrate) THEN
6462                   p_charge_elements := 1;
6463                   BEGIN
6464                     -- The org unit cd is derived at the Program Level if the Charge method is FLATRATE
6465                     OPEN c_resp_org_unit_cd(p_course_cd,
6466                                             p_course_version_number);
6467                     FETCH c_resp_org_unit_cd INTO v_derived_org_unit_cd;
6468                     CLOSE c_resp_org_unit_cd;
6469 
6470                     log_to_fnd( p_v_module => 'finpl_prc_sua_load',
6471                                 p_v_string => 'Flat Rate: Derived Org Unit Cd from Program level: '
6472                                               || v_derived_org_unit_cd || '.Call finpl_sum_fee_ass_item..' );
6473                     IF finpl_sum_fee_ass_item (
6474                             p_person_id=>p_person_id,
6475                             p_status=>'E',
6476                             p_fee_type=>p_fee_type,
6477                             P_fee_cat=>p_fee_cat,
6478                             p_fee_cal_type=>p_fee_cal_type,
6479                             p_fee_ci_sequence_number=>p_fee_ci_sequence_number,
6480                             p_course_cd=>p_course_cd,
6481                             p_n_crs_version_number => p_course_version_number,
6482                             p_chg_method_type=>p_charge_method,
6483                             p_description=>null,--fee type desc selected inside
6484                             p_chg_elements=>p_charge_elements,--which is 1
6485                             p_unit_attempt_status =>NULL,
6486                             p_location_cd=>p_location_cd,
6487                             p_eftsu =>null,
6488                             p_credit_points=>null,
6489                             p_amount=>0,
6490                             p_org_unit_cd => v_derived_org_unit_cd, -- CCR for Enh# 1851586
6491                             p_trace_on=>p_trace_on,
6492                             p_message_name=>lv_sum_message,
6493                             p_uoo_id => NULL,
6494                             p_n_unit_type_id => NULL,
6495                             p_v_unit_level => NULL,
6496                             p_v_unit_class => NULL,
6497                             p_v_unit_mode => NULL,
6498                             p_v_unit_cd => NULL,
6499                             p_n_unit_version => NULL
6500                             )  = FALSE THEN
6501                       log_to_fnd( p_v_module => 'finpl_prc_sua_load',
6502                                   p_v_string => 'Returning false as finpl_sum_fee_ass_item returned with message:'|| lv_sum_message );
6503                       RETURN FALSE;
6504                     END IF;
6505                   END;
6506                   IF (p_trace_on = 'Y') THEN
6507                     -- Trace Entry
6508                     fnd_file.new_line(fnd_file.log);
6509                     fnd_message.set_name ( 'IGS', 'IGS_FI_LOAD_INCURRED');
6510                     fnd_message.set_token('YES_NO', igs_fi_gen_gl.get_lkp_meaning('YES_NO', 'Y') );
6511                     fnd_file.put_line (fnd_file.log, fnd_message.get);
6512                     fnd_message.set_name('IGS', 'IGS_FI_CHG_METH_TYPE');
6513                     fnd_message.set_token('CHG_MTHD', igs_fi_gen_gl.get_lkp_meaning('CHG_METHOD', p_charge_method));
6514                     fnd_file.put_line (fnd_file.log, fnd_message.get);
6515                     fnd_message.set_name('IGS', 'IGS_FI_CHRG_METHOD_ELEMENTS');
6516                     fnd_message.set_token('CHG_ELM', TO_CHAR(p_charge_elements));
6517                     fnd_file.put_line (fnd_file.log, fnd_message.get);
6518                   END IF;
6519                   p_ret_true_flag := TRUE;
6520                   RETURN TRUE;
6521 
6522                 ELSIF (p_charge_method = gcst_perunit) THEN
6523                   p_charge_elements := p_charge_elements + 1;
6524                   BEGIN
6525                     log_to_fnd( p_v_module => 'finpl_prc_sua_load',
6526                                 p_v_string => 'Per Unit: Calling finpl_sum_fee_ass_item with elements ' || p_charge_elements );
6527                     IF finpl_sum_fee_ass_item (
6528                             p_person_id=>p_person_id,
6529                             p_status=>'E',
6530                             p_fee_type=>p_fee_type,
6531                             P_fee_cat=>p_fee_cat,
6532                             p_fee_cal_type=>p_fee_cal_type,
6533                             p_fee_ci_sequence_number=>p_fee_ci_sequence_number,
6534                             p_course_cd=>p_course_cd,
6535                             p_n_crs_version_number => p_course_version_number,
6536                             p_chg_method_type=>p_charge_method,
6537                             p_description=>null,--fee type desc selected inside
6538                             p_chg_elements=>1,  -- The Charge Method is Per Unit, Charge Elements will be passed as 1 for each assessable Unit
6539                             p_unit_attempt_status =>p_unit_attempt_status,
6540                             p_location_cd=>p_location_cd,
6541                             p_eftsu =>p_eftsu,
6542                             p_credit_points=>p_credit_points,
6543                             p_amount=>0,
6544                             p_org_unit_cd => v_derived_org_unit_cd, -- CCR for Enh# 1851586
6545                             p_trace_on=>p_trace_on,
6546                             p_message_name=>lv_sum_message,
6547                             p_uoo_id => p_uoo_id,
6548                             p_n_unit_type_id => p_n_unit_type_id,
6549                             p_v_unit_level => p_v_unit_level,
6550                             p_v_unit_class => lv_unit_class_att,
6551                             p_v_unit_mode => p_v_unit_mode,
6552                             p_v_unit_cd => p_unit_cd,
6553                             p_n_unit_version => p_unit_version_number )  = FALSE THEN
6554                       log_to_fnd( p_v_module => 'finpl_prc_sua_load',
6555                                   p_v_string => 'Returning false as finpl_sum_fee_ass_item returned with message:'|| lv_sum_message );
6556                       RETURN FALSE;
6557                     END IF;
6558                   END;
6559                   IF (p_trace_on = 'Y') THEN
6560                     -- Trace Entry
6561                     fnd_message.set_name ( 'IGS', 'IGS_FI_LOAD_INCURRED');
6562                     fnd_message.set_token('YES_NO', igs_fi_gen_gl.get_lkp_meaning('YES_NO', 'Y') );
6563                     fnd_file.put_line (fnd_file.log, fnd_message.get);
6564                     fnd_message.set_name('IGS', 'IGS_FI_CHRG_METHOD_ELEMENTS');
6565                     fnd_message.set_token('CHG_ELM', TO_CHAR(p_charge_elements));
6566                     fnd_file.put_line (fnd_file.log, fnd_message.get);
6567                   END IF;
6568 
6569                 ELSIF (p_charge_method = gcst_eftsu) THEN
6570                   p_charge_elements := p_charge_elements + p_eftsu;
6571                   BEGIN
6572                     log_to_fnd( p_v_module => 'finpl_prc_sua_load',
6573                                 p_v_string => 'Per Unit: Calling finpl_sum_fee_ass_item with elements ' || p_charge_elements );
6574                     IF finpl_sum_fee_ass_item (
6575                          p_person_id=>p_person_id,
6576                          p_status=>'E',
6577                          p_fee_type=>p_fee_type,
6578                          P_fee_cat=>p_fee_cat,
6579                          p_fee_cal_type=>p_fee_cal_type,
6580                          p_fee_ci_sequence_number=>p_fee_ci_sequence_number,
6581                          p_course_cd=>p_course_cd,
6582                          p_n_crs_version_number => p_course_version_number,
6583                          p_chg_method_type=>p_charge_method,
6584                          p_description=>null,--fee type desc selected inside
6585                          p_chg_elements=>p_eftsu,
6586                          p_unit_attempt_status =>p_unit_attempt_status,
6587                          p_location_cd=>p_location_cd,
6588                          p_eftsu =>p_eftsu,
6589                          p_credit_points=>p_credit_points,
6590                          p_amount=>0,
6591                          p_org_unit_cd => v_derived_org_unit_cd, -- CCR for Enh# 1851586
6592                          p_trace_on=>p_trace_on,
6593                          p_message_name=>lv_sum_message,
6594                          p_uoo_id => p_uoo_id,
6595                          p_n_unit_type_id => p_n_unit_type_id,
6596                          p_v_unit_level => p_v_unit_level,
6597                          p_v_unit_class => lv_unit_class_att,
6598                          p_v_unit_mode => p_v_unit_mode,
6599                          p_v_unit_cd => p_unit_cd,
6600                          p_n_unit_version => p_unit_version_number )  = FALSE THEN
6601                       log_to_fnd( p_v_module => 'finpl_prc_sua_load',
6602                                   p_v_string => 'Returning false as finpl_sum_fee_ass_item returned with message:'|| lv_sum_message );
6603                       RETURN FALSE;
6604                     END IF;
6605                   END;
6606 
6607                   IF (p_trace_on = 'Y') THEN
6608                     -- Auditable Units contribute to only Charge Elements but not for Load. Load Incurred for such a unit is always ZERO.
6609                     -- But igs_en_gen_014.enrs_clc_sua_eftsu in cursor c_sua_load returns Billing Credit Points for an Auditable Unit.
6610                     l_n_eftsu := 0;
6611                     IF l_v_no_assessment_ind = 'N' THEN
6612                       l_n_eftsu := p_eftsu;
6613                     END IF;
6614                     fnd_message.set_name('IGS', 'IGS_FI_LOAD_INCURRED');
6615                     fnd_message.set_token('YES_NO', igs_fi_gen_gl.get_lkp_meaning('YES_NO', 'Y') );
6616                     fnd_file.put_line (fnd_file.log, fnd_message.get);
6617                     fnd_message.set_name('IGS', 'IGS_FI_CHG_ELE');
6618                     fnd_message.set_token('ELEMENTS', TO_CHAR(NVL(p_eftsu, 0)));
6619                     fnd_file.put_line (fnd_file.log, fnd_message.get);
6620                   END IF;
6621 
6622                 ELSIF (p_charge_method = gcst_crpoint) THEN
6623                   p_charge_elements := p_charge_elements + p_credit_points;
6624                   BEGIN
6625                     log_to_fnd( p_v_module => 'finpl_prc_sua_load',
6626                                 p_v_string => 'Credit Points: Calling finpl_sum_fee_ass_item with elements ' || p_charge_elements );
6627                     IF finpl_sum_fee_ass_item (
6628                          p_person_id=>p_person_id,
6629                          p_status=>'E',
6630                          p_fee_type=>p_fee_type,
6631                          p_fee_cat=>p_fee_cat,
6632                          p_fee_cal_type=>p_fee_cal_type,
6633                          p_fee_ci_sequence_number=>p_fee_ci_sequence_number,
6634                          p_course_cd=>p_course_cd,
6635                          p_n_crs_version_number => p_course_version_number,
6636                          p_chg_method_type=>p_charge_method,
6637                          p_description=>null,--fee type desc selected inside
6638                          p_chg_elements=>p_credit_points,
6639                          p_unit_attempt_status =>p_unit_attempt_status,
6640                          p_location_cd=>p_location_cd,
6641                          p_eftsu =>p_eftsu,
6642                          p_credit_points=>p_credit_points,
6643                          p_amount=>0,
6644                          p_org_unit_cd => v_derived_org_unit_cd, -- CCR for Enh# 1851586
6645                          p_trace_on=>p_trace_on,
6646                          p_message_name=>lv_sum_message,
6647                          p_uoo_id => p_uoo_id,
6648                          p_n_unit_type_id => p_n_unit_type_id,
6649                          p_v_unit_level => p_v_unit_level,
6650                          p_v_unit_class => lv_unit_class_att,
6651                          p_v_unit_mode => p_v_unit_mode,
6652                          p_v_unit_cd => p_unit_cd,
6653                          p_n_unit_version => p_unit_version_number )  = FALSE THEN
6654                       log_to_fnd( p_v_module => 'finpl_prc_sua_load',
6655                                   p_v_string => 'Returning false as finpl_sum_fee_ass_item returned with message:'|| lv_sum_message );
6656                       RETURN FALSE;
6657                     END IF;
6658                   END;
6659 
6660                   IF (p_trace_on = 'Y') THEN
6661                     -- Auditable Units contribute to only Charge Elements but not for Load. Load Incurred for such a unit is always ZERO.
6662                     -- But igs_en_gen_014.enrs_clc_sua_cp in cursor c_sua_load returns Billing Credit Points for an Auditable Unit.
6663                     l_n_credit_points := 0;
6664                     IF l_v_no_assessment_ind = 'N' THEN
6665                       l_n_credit_points := p_credit_points;
6666                     END IF;
6667                     fnd_message.set_name('IGS', 'IGS_FI_LOAD_INCURRED');
6668                     fnd_message.set_token('YES_NO', igs_fi_gen_gl.get_lkp_meaning('YES_NO', 'Y') );
6669                     fnd_file.put_line (fnd_file.log, fnd_message.get);
6670                     fnd_message.set_name('IGS', 'IGS_FI_CHG_ELE');
6671                     fnd_message.set_token('ELEMENTS', TO_CHAR(NVL(p_credit_points, 0)));
6672                     fnd_file.put_line (fnd_file.log, fnd_message.get);
6673                   END IF;
6674                 END IF;
6675 
6676                 log_to_fnd( p_v_module => 'finpl_prc_sua_load',
6677                             p_v_string => 'Returning from finpl_prc_sua_load. Out: Charge elements ' || p_charge_elements );
6678                 RETURN TRUE;
6679         END;
6680    EXCEPTION
6681           WHEN OTHERS THEN
6682             log_to_fnd( p_v_module => 'finpl_prc_sua_load',
6683                         p_v_string => 'From Exception Handler of When Others' );
6684             fnd_message.set_name ('IGS', 'IGS_GE_UNHANDLED_EXP');
6685             fnd_message.set_token('NAME','IGS_FI_PRC_FEE_ASS.FINPL_PRC_SUA_LOAD-'||SUBSTR(sqlerrm,1,500));
6686             igs_ge_msg_stack.ADD;
6687             app_exception.raise_exception;
6688         END finpl_prc_sua_load;
6689 
6690     ------------------------------------------------------------------------------
6691         FUNCTION finpl_clc_chg_mthd_elements(
6692                 p_effective_dt                  DATE,
6693                 p_trace_on                      VARCHAR2,
6694                 p_person_id                     igs_en_stdnt_ps_att_all.person_id%TYPE,
6695                 p_course_cd                     igs_en_stdnt_ps_att_all.course_cd%TYPE,
6696                 p_course_version_number         igs_en_stdnt_ps_att_all.version_number%TYPE,
6697                 p_attendance_type               igs_en_stdnt_ps_att_all.ATTENDANCE_TYPE%TYPE,
6698                 p_course_attempt_status         igs_en_stdnt_ps_att_all.course_attempt_status%TYPE,
6699                 p_charge_method                 igs_fi_f_cat_fee_lbl_all.s_chg_method_type%TYPE,
6700                 p_fee_cat                       IGS_FI_F_CAT_CA_INST.FEE_CAT%TYPE,
6701                 p_fee_cal_type                  igs_fi_f_cat_fee_lbl_all.fee_cal_type%TYPE,
6702                 p_fee_ci_sequence_number        igs_fi_f_cat_fee_lbl_all.fee_ci_sequence_number%TYPE,
6703                 p_fee_type                      igs_fi_f_cat_fee_lbl_all.fee_type%TYPE,
6704                 p_s_fee_type                    igs_fi_fee_type_all.s_fee_type%TYPE,
6705                 p_s_fee_trigger_cat             igs_fi_fee_type_all.s_fee_trigger_cat%TYPE,
6706                 p_charge_elements       IN OUT NOCOPY   igs_fi_fee_as_all.chg_elements%TYPE,
6707                 p_message_name          OUT NOCOPY      VARCHAR2,
6708                 p_location_cd                   IGS_FI_FEE_AS_ITEMS.LOCATION_CD%TYPE,
6709                 p_c_career                      igs_ps_ver_all.course_type%TYPE,
6710                 p_n_selection_rule      IN      igs_ru_rule.sequence_number%TYPE
6711                 )
6712         RETURN BOOLEAN AS
6713 /*************************************************************
6714  Created By :
6715  Date Created By :
6716  Purpose :
6717  Know limitations, enhancements or remarks
6718  Change History
6719  Who             When       What
6720  bannamal       08-Jul-2005 Enh#3392088 Campus Privilege Fee.
6721                             Changes done as per TD.
6722  bannamal       14-Apr-2005 Bug#4297359 ER Registration Fee issue
6723                             Added code to check whether the credit points for the unit
6724                             attempt is non zero in case the non zero billable cp flag is
6725                             set to 'Y'.
6726  pathipat       05-Nov-2003 Enh 3117341 - Audit and Special Fees TD
6727                             Modifications according to TD, s1a
6728  vchappid       12-Feb-03   Bug#2788346, In this function, function finpl_pr8/16/2005
6729                             invoking logic is changed for 'Flat Rate' charge method.
6730 ***************************************************************/
6731    lv_param_values VARCHAR2(1080);
6732    BEGIN
6733         DECLARE
6734                 v_version_number                igs_en_stdnt_ps_att_all.version_number%TYPE;
6735                 v_eftsu                         igs_fi_fee_as_all.chg_elements%TYPE;
6736                 v_credit_points                 igs_fi_fee_as_all.chg_elements%TYPE;
6737                 v_ret_true_flag                 BOOLEAN;
6738                 v_trigger_fired                 fnd_lookup_values.lookup_code%TYPE;
6739                 v_message_name                  VARCHAR2(30);
6740                 v_derived_org_unit_cd           IGS_FI_FEE_AS_ITEMS.org_unit_cd%TYPE;
6741                 v_derived_location_cd           IGS_FI_FEE_AS_ITEMS.LOCATION_CD%TYPE;
6742                 l_eftsu     NUMBER;
6743                 l_crpoint   NUMBER;
6744 
6745                 l_v_fee_ass_ind           VARCHAR2(1) := NULL;
6746 
6747                 l_n_eftsu   igs_fi_fee_as_items.eftsu%TYPE;
6748                 l_n_credit_points  igs_fi_fee_as_items.credit_points%TYPE;
6749 
6750                 l_b_sca_liable_fcfl  BOOLEAN;
6751                 l_v_prg_liabale      VARCHAR2(10);
6752 
6753                 -- cursor to find student IGS_PS_UNIT attempts across multiple
6754                 -- student IGS_PS_COURSE attempts
6755                 -- this cursor has been modified to incorporate the changes for early/prioe assessment
6756                 -- fee clac DLD  (Bug# 1851586)
6757                 -- the records are fetched in the basis of the prior fee calendar instance
6758 
6759                 -- Bug# 2122257, Modified the cursor select statement to include the audit table (IGS_FI_F_CAT_CAL_REL)
6760                 -- for selecting Fee Category when it is changed.
6761                 /* Modified by vchappid as a part of SFCR015 Build */
6762 
6763                 -- Enh#2162747, Modified the cursor, removed the eftsu and credit point calculation, same function is invoked to calculate EFTSU, CREDIT POINTS
6764                 -- when the the charge method is either EFTSU or CREDIT POINTS
6765                 -- Enh# 3167098, modified following cursor
6766                 CURSOR c_sualv_scafv (cp_person_id  hz_parties.party_id%TYPE,
6767                                       cp_course_cd  igs_en_su_attempt_all.course_cd%TYPE,
6768                                       cp_v_fee_ass_ind VARCHAR2,
6769                                       cp_v_lookup_type       igs_lookups_view.lookup_type%TYPE,
6770                                       cp_v_fee_ass_indicator igs_lookups_view.fee_ass_ind%TYPE)  IS
6771                   SELECT  sua.cal_type,
6772                           sua.ci_sequence_number,
6773                           sua.discontinued_dt,
6774                           sua.administrative_unit_status,
6775                           sua.unit_attempt_status,
6776                           sua.unit_cd,
6777                           sua.version_number,
6778                           sua.uoo_id,
6779                           sua.override_enrolled_cp,
6780                           sua.override_eftsu,
6781                           sua.no_assessment_ind,
6782                           sua.location_cd,
6783                           sua.org_unit_cd,
6784                           uoo.owner_org_unit_cd
6785                   FROM    igs_en_su_attempt_all sua,
6786                           igs_lookups_view lkp,
6787                           igs_ps_unit_ofr_opt_all uoo
6788                   WHERE lkp.lookup_code = sua.unit_attempt_status
6789                   AND   lkp.lookup_type = cp_v_lookup_type
6790                   AND   lkp.fee_ass_ind = cp_v_fee_ass_indicator
6791                   AND   (sua.no_assessment_ind = cp_v_fee_ass_ind OR cp_v_fee_ass_ind IS NULL)
6792                   AND   sua.person_id = cp_person_id
6793                   AND   sua.course_cd = cp_course_cd
6794                   AND   uoo.uoo_id    = sua.uoo_id;
6795 
6796                 -- cursor to find student unit attempt for a course in context and in the given term.
6797                 -- Enh# 3741400, igs_en_get_suaeh_dtl.enrp_get_suaeh_eff_st is replaced with SYSDATE
6798                 CURSOR c_sua_load ( cp_person_id               hz_parties.party_id%TYPE,
6799                                     cp_course_cd               igs_ps_ver_all.course_cd%TYPE,
6800                                     cp_course_version          igs_ps_ver_all.version_number%TYPE,
6801                                     cp_load_cal_type           igs_ca_inst_all.cal_type%TYPE,
6802                                     cp_load_ci_sequence_number igs_ca_inst_all.sequence_number%TYPE,
6803                                     cp_v_fee_ass_ind           VARCHAR2,
6804                                     cp_v_lookup_type           igs_lookup_values.lookup_type%TYPE,
6805                                     cp_v_fee_ass_indicator     igs_lookups_view.fee_ass_ind%TYPE,
6806                                     cp_v_enrp_get_load_apply   VARCHAR2
6807                                     ) IS
6808                         SELECT  sua.course_cd,
6809                                 sua.unit_cd,
6810                                 sua.version_number,
6811                                 sua.cal_type,
6812                                 sua.unit_attempt_status,
6813                                 sua.ci_sequence_number,
6814                                 sua.location_cd,
6815                                 SYSDATE effective_start_dt,
6816                                 SYSDATE effective_end_dt,
6817                                 NVL(igs_en_gen_014.enrs_clc_sua_eftsu(
6818                                                 sua.person_id,
6819                                                 p_course_cd, -- Enh#2162747 changed sua.course_cd to p_course_cd
6820                                                 p_course_version_number, -- Enh#2162747
6821                                                 sua.unit_cd,
6822                                                 sua.version_number,
6823                                                 sua.cal_type,
6824                                                 sua.ci_sequence_number,
6825                                                 sua.uoo_id,
6826                                                 cp_load_cal_type,
6827                                                 cp_load_ci_sequence_number,
6828                                                 sua.override_enrolled_cp,
6829                                                 sua.override_eftsu,
6830                                                 'Y',            -- truncate_ind
6831                                                 NULL,
6832                                                 sua.no_assessment_ind
6833                                                 ),0)   eftsu,  -- sca_cp_total
6834                                 finpl_clc_sua_cp( sua.unit_cd,
6835                                                   sua.version_number,
6836                                                   sua.cal_type,
6837                                                   sua.ci_sequence_number,
6838                                                   cp_load_cal_type,
6839                                                   cp_load_ci_sequence_number,
6840                                                   sua.override_enrolled_cp,
6841                                                   sua.override_eftsu,
6842                                                   sua.uoo_id,
6843                                                   sua.no_assessment_ind) credit_points,
6844                                 sua.uoo_id uoo_id,
6845                                 sua.no_assessment_ind,
6846                                 sua.org_unit_cd,
6847                                 uoo.owner_org_unit_cd
6848                         FROM    igs_en_su_attempt_all       sua,
6849                                 igs_lookups_view        suas,
6850                                 igs_en_spa_terms        terms,
6851                                 igs_ps_unit_ofr_opt_all uoo
6852                         WHERE   sua.person_id = p_person_id AND
6853                                 sua.person_id = terms.person_id AND
6854                                 sua.course_cd = terms.program_cd AND
6855                                 uoo.uoo_id    = sua.uoo_id AND
6856                                 terms.term_cal_type = g_v_load_cal_type AND
6857                                 terms.term_sequence_number = g_n_load_seq_num AND
6858                                 (
6859                                  ( sua.course_cd = p_course_cd AND g_c_fee_calc_mthd IN (g_v_program, g_v_career))
6860                                  OR
6861                                  (g_c_fee_calc_mthd= g_v_primary_career)
6862                                 ) AND
6863                                 suas.lookup_code = sua.unit_attempt_status AND
6864                                 suas.lookup_type = cp_v_lookup_type AND
6865                                 suas.fee_ass_ind = cp_v_fee_ass_indicator AND
6866                                 (sua.no_assessment_ind = cp_v_fee_ass_ind OR cp_v_fee_ass_ind IS NULL) AND
6867                                 igs_en_prc_load.enrp_get_load_apply(
6868                                       sua.cal_type,
6869                                       sua.ci_sequence_number,
6870                                       sua.discontinued_dt,
6871                                       sua.administrative_unit_status,
6872                                       sua.unit_attempt_status,
6873                                       sua.no_assessment_ind,
6874                                       cp_load_cal_type,
6875                                       cp_load_ci_sequence_number,
6876                                       sua.no_assessment_ind
6877                                       ) = cp_v_enrp_get_load_apply;
6878 
6879   -- Added by schodava as a part of the CCR for the Fee Calc (Enh # 1851586) DLD
6880   -- To find the organization unit code from the Program Version Table (For Charge Method of 'FLATRATE','EFTSU','PERUNIT','CREDIT POINT')
6881   CURSOR c_resp_org_unit_cd(cp_course_cd IN igs_ps_ver_all.course_cd%TYPE,
6882                             cp_version_number IN igs_ps_ver_all.version_number%TYPE
6883                            )IS
6884   SELECT responsible_org_unit_cd
6885   FROM   igs_ps_ver_all v
6886   WHERE  v.course_cd            = cp_course_cd
6887   AND    v.version_number       = cp_version_number;
6888 
6889         -- Enh# 3167098, Removed references to igs_fi_f_cat_cal_rel and igs_fi_cng_fcat_lbl_sca_pr_v in following cursor.
6890         -- For CAREER, Term records are created only for primary programs. So, select all programs from terms table.
6891         CURSOR c_sca_psv ( cp_v_lookup_type igs_lookups_view.lookup_type%TYPE,
6892                            cp_v_fee_ass_ind igs_lookups_view.fee_ass_ind%TYPE ) IS
6893           SELECT  spat.person_id,
6894                   spat.program_cd,
6895                   spat.program_version,
6896                   spat.fee_cat,
6897                   sca.commencement_dt,
6898                   sca.discontinued_dt,
6899                   sca.adm_admission_appl_number,
6900                   sca.adm_nominated_course_cd,
6901                   sca.adm_sequence_number,
6902                   sca.cal_type,
6903                   spat.location_cd,
6904                   spat.attendance_mode,
6905                   spat.attendance_type,
6906                   ps.course_type
6907           FROM    igs_en_spa_terms spat,
6908                   igs_en_stdnt_ps_att_all sca,
6909                   igs_ps_ver_all ps,
6910                   igs_lookups_view lkps
6911           WHERE   spat.person_id = p_person_id
6912           AND     spat.person_id = sca.person_id
6913           AND     spat.program_cd = sca.course_cd
6914           AND     spat.program_version = sca.version_number
6915           AND     spat.term_cal_type = g_v_load_cal_type
6916           AND     spat.term_sequence_number = g_n_load_seq_num
6917           AND     spat.program_cd = ps.course_cd
6918           AND     spat.program_version = ps.version_number
6919           AND     lkps.lookup_type = cp_v_lookup_type
6920           AND     sca.course_attempt_status = lkps.lookup_code
6921           AND     lkps.fee_ass_ind = cp_v_fee_ass_ind;
6922 
6923 ---  Cursor for getting nonzero_billable_cp_flag from ftci
6924 
6925          CURSOR cur_nz_bill_cp_flag ( cp_v_fee_type           igs_fi_f_typ_ca_inst_all.fee_type%TYPE,
6926                                       cp_v_fee_cal_type       igs_fi_f_typ_ca_inst_all.fee_cal_type%TYPE,
6927                                       cp_n_fee_ci_seq_number  igs_fi_f_typ_ca_inst_all.fee_ci_sequence_number%TYPE ) IS
6928            SELECT nonzero_billable_cp_flag
6929            FROM igs_fi_f_typ_ca_inst_all
6930            WHERE fee_type = cp_v_fee_type
6931            AND   fee_cal_type = cp_v_fee_cal_type
6932            AND   fee_ci_sequence_number = cp_n_fee_ci_seq_number;
6933 
6934          CURSOR cur_unit_cd (cp_n_uoo_id  igs_fi_fee_as_items.uoo_id%TYPE) IS
6935            SELECT unit_cd, version_number
6936            FROM   igs_ps_unit_ofr_opt_all
6937            WHERE  uoo_id = cp_n_uoo_id;
6938 
6939          CURSOR cur_get_ret_level (cp_v_fee_type              igs_fi_f_typ_ca_inst_all.fee_type%TYPE,
6940                                    cp_v_fee_cal_type          igs_fi_f_typ_ca_inst_all.fee_cal_type%TYPE,
6941                                    cp_n_fee_ci_sequence_num   igs_fi_f_typ_ca_inst_all.fee_ci_sequence_number%TYPE) IS
6942            SELECT retention_level_code
6943            FROM  igs_fi_f_typ_ca_inst_all
6944            WHERE fee_type               = cp_v_fee_type
6945            AND   fee_cal_type           = cp_v_fee_cal_type
6946            AND   fee_ci_sequence_number = cp_n_fee_ci_sequence_num;
6947 
6948          CURSOR cur_unit_set (cp_person_id     hz_parties.party_id%TYPE,
6949                               cp_course_cd     igs_ps_ver_all.course_cd%TYPE,
6950                               cp_effective_dt  DATE,
6951                               cp_v_student_confirmed_ind  igs_as_su_setatmpt.student_confirmed_ind%TYPE,
6952                               cp_v_s_unit_set_cat  igs_en_unit_set_cat.s_unit_set_cat%TYPE) IS
6953            SELECT asu.unit_set_cd,
6954                   asu.us_version_number
6955            FROM igs_as_su_setatmpt asu,
6956                 igs_en_unit_set_all us,
6957                 igs_en_unit_set_cat usc
6958            WHERE asu.person_id = cp_person_id
6959            AND asu.course_cd = cp_course_cd
6960            AND asu.student_confirmed_ind = cp_v_student_confirmed_ind
6961            AND TRUNC(cp_effective_dt) BETWEEN TRUNC(asu.selection_dt) AND NVL(TRUNC(asu.rqrmnts_complete_dt), NVL(TRUNC(asu.end_dt), TRUNC(cp_effective_dt)))
6962            AND asu.unit_set_cd = us.unit_set_cd
6963            AND asu.us_version_number = us.version_number
6964            AND us.unit_set_cat = usc.unit_set_cat
6965            AND usc.s_unit_set_cat = cp_v_s_unit_set_cat;
6966 
6967 
6968         l_v_course_cd   VARCHAR2(30);
6969         l_v_fee_cat     VARCHAR2(30);
6970         l_v_location_cd VARCHAR2(30);
6971         l_v_org_unit_cd VARCHAR2(30);
6972         l_v_nz_bill_cp_flag  igs_fi_f_typ_ca_inst_all.nonzero_billable_cp_flag%TYPE;
6973         l_n_crs_version_number  igs_fi_Fee_as_items.crs_version_number%TYPE;
6974 
6975         l_n_prg_type_level   igs_ps_unit_ver_all.unit_type_id%TYPE;
6976         l_v_unit_level       igs_ps_unit_ver_all.unit_level%TYPE;
6977         l_v_unit_class       igs_as_unit_class_all.unit_class%TYPE;
6978         l_v_unit_mode        igs_as_unit_class_all.unit_mode%TYPE;
6979         l_n_count            NUMBER;
6980         l_b_rule             BOOLEAN;
6981         l_v_unit_cd          igs_ps_unit_ofr_opt_all.unit_cd%TYPE;
6982         l_n_version_num      igs_ps_unit_ofr_opt_all.version_number%TYPE;
6983         l_v_ret_level        igs_fi_f_typ_ca_inst_all.retention_level_code%TYPE;
6984         l_v_class_standing   igs_fi_fee_as_rate.class_standing%TYPE;
6985         l_v_unit_set_cd      igs_as_su_setatmpt.unit_set_cd%TYPE;
6986         l_n_us_version_num   igs_as_su_setatmpt.us_version_number%TYPE;
6987 
6988 
6989         BEGIN
6990           -- Begin for finpl_clc_chg_mthd_elements
6991 
6992           log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
6993                       p_v_string => 'Entered finpl_clc_chg_mthd_elements. Parameters are: '
6994                                     || 'Effective Dt: ' || TO_CHAR(p_effective_dt, 'DD-MON-YYYY HH24:MI:SS')
6995                                     || ', Trace On: ' || p_trace_on
6996                                     || ', Person Id: ' || p_person_id
6997                                     || ', Course Cd: ' || p_course_cd
6998                                     || ', Course Ver: ' || p_course_version_number
6999                                     || ', Att Type: ' || p_attendance_type
7000                                     || ', Crs Att Stat: ' || p_course_attempt_status
7001                                     || ', Chg Mthd: ' || p_charge_method
7002                                     || ', Fee Cat: ' || p_fee_cat
7003                                     || ', Fee Cal Type: ' || p_fee_cal_type
7004                                     || ', Fee Cal Seq Num: ' || p_fee_ci_sequence_number
7005                                     || ', Fee Type: ' || p_fee_type
7006                                     || ', Sys Fee Type: ' || p_s_fee_type
7007                                     || ', Sys Fee Trig Cat: ' || p_s_fee_trigger_cat
7008                                     || ', Charge Elms: ' || p_charge_elements
7009                                     || ', Location Cd: ' || p_location_cd
7010                                     || ', Career: ' || p_c_career );
7011 
7012           -- Step 1. Derive Load from the parameters (In case of PREDICTIVE, From Program and
7013           --                                          in case of ACTUAL, from Units attached to Program)
7014           -- Step 2. Derive Number of Charge Elements based on charge method and load derived.
7015 
7016           p_message_name := NULL;
7017           v_eftsu := 0;
7018           v_credit_points := 0;
7019 
7020           -- ====> PREDICTIVE MODE
7021           -------------------------
7022 
7023           -- check if a predictive assessment is being carried out
7024           -- if so use Default Load attached for the program.
7025           IF ( g_c_predictive_ind = 'Y' ) THEN
7026 
7027             log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7028                         p_v_string => 'Following path of Predictive. Deriving Default Load.');
7029             IF (igs_en_gen_002.enrp_get_att_dflt(p_course_cd,
7030                                                  p_course_version_number,
7031                                                  p_attendance_type,
7032                                                  g_v_load_cal_type, --Enh# SFCR021 v_ftcmav_rec.load_cal_type,
7033                                                  v_eftsu,
7034                                                  v_credit_points) = TRUE) THEN
7035               -- Enh# 3167098, In Predictive, org unit cd is derived from the Program Level as attributes are derived from Program level.
7036               OPEN c_resp_org_unit_cd(p_course_cd,p_course_version_number);
7037               FETCH c_resp_org_unit_cd INTO v_derived_org_unit_cd;
7038               CLOSE c_resp_org_unit_cd;
7039 
7040               log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7041                           p_v_string => 'Derived Values. Eftsu: ' || v_eftsu
7042                                         || ', Cr Points: ' || v_credit_points
7043                                         ||', Org Unit Cd: ' || v_derived_org_unit_cd);
7044 
7045 
7046               -- Enh# 3167098, For an Institution Fee, Course Code and Fee Category should be NULL (Only if Fee Calc Mthd is not Primary Career)
7047               IF p_s_fee_trigger_cat = gcst_institutn
7048                  AND g_c_fee_calc_mthd <> g_v_primary_career THEN
7049                 l_v_course_cd := NULL;
7050                 l_n_crs_version_number := NULL;
7051                 l_v_fee_cat := NULL;
7052                 l_v_location_cd := NULL;
7053                 l_v_org_unit_cd := NULL;
7054               ELSE
7055                 l_v_course_cd := p_course_cd;
7056                 l_n_crs_version_number := p_course_version_number;
7057                 l_v_fee_cat := p_fee_cat;
7058                 l_v_location_cd := p_location_cd;
7059                 l_v_org_unit_cd := v_derived_org_unit_cd;
7060               END IF;
7061 
7062               IF (p_charge_method = gcst_flatrate) THEN
7063                 p_charge_elements := 1;
7064                         ---SYAM-KSS----added  by syam as part of DLD chap 9 devlp  call to sum_fee for insert if flat rate
7065                 BEGIN
7066                   log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7067                               p_v_string => 'Calling finpl_sum_fee_ass_item in Flat Rate Case.');
7068                   IF finpl_sum_fee_ass_item (
7069                         p_person_id            => p_person_id,
7070                         p_status               => 'E',
7071                         p_fee_type             => p_fee_type,
7072                         P_fee_cat              => l_v_fee_cat,
7073                         p_fee_cal_type         => p_fee_cal_type,
7074                         p_fee_ci_sequence_number=>p_fee_ci_sequence_number,
7075                         p_course_cd            => l_v_course_cd,
7076                         p_n_crs_version_number => l_n_crs_version_number,
7077                         p_chg_method_type      => p_charge_method,
7078                         p_description          => null,                --fee type desc selected inside
7079                         p_chg_elements         => p_charge_elements,   --which is 1
7080                         p_unit_attempt_status  => null,
7081                         p_location_cd          => l_v_location_cd,
7082                         p_eftsu                => null,
7083                         p_credit_points        => null,
7084                         p_amount               => 0,
7085                         p_org_unit_cd          => l_v_org_unit_cd, -- CCR for Enh# 1851586
7086                         p_trace_on             => p_trace_on,
7087                         p_message_name         => lv_sum_message,
7088                         p_uoo_id               => NULL,
7089                         p_n_unit_type_id       => NULL,
7090                         p_v_unit_level         => NULL,
7091                         p_v_unit_class         => NULL,
7092                         p_v_unit_mode          => NULL,
7093                         p_v_unit_cd            => NULL,
7094                         p_n_unit_version       => NULL
7095                         )  = FALSE THEN
7096                     log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7097                                 p_v_string => 'Returning False as finpl_sum_fee_ass_item returned false with message: ' || lv_sum_message);
7098                     RETURN FALSE;
7099                   END IF;
7100                 END;
7101                 log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7102                             p_v_string => 'Returning with Charge Elements 1 in Flat Rate Case.');
7103                 RETURN TRUE;
7104 
7105               ELSIF (p_charge_method = gcst_eftsu) THEN
7106                 p_charge_elements := NVL(p_charge_elements,0) + NVL(v_eftsu,0);
7107                 log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7108                             p_v_string => 'EFTSU Case: Calling finpl_sum_fee_ass_item with Charge Elemsnts: ' || p_charge_elements);
7109                 BEGIN
7110                   IF finpl_sum_fee_ass_item (
7111                                  p_person_id            => p_person_id,
7112                                  p_status               => 'E',
7113                                  p_fee_type             => p_fee_type,
7114                                  P_fee_cat              => l_v_fee_cat,
7115                                  p_fee_cal_type         => p_fee_cal_type,
7116                                  p_fee_ci_sequence_number=>p_fee_ci_sequence_number,
7117                                  p_course_cd            => l_v_course_cd,
7118                                  p_n_crs_version_number => l_n_crs_version_number,
7119                                  p_chg_method_type      => p_charge_method,
7120                                  p_description          => null,--fee type desc selected inside
7121                                  p_chg_elements         => v_eftsu,
7122                                  p_unit_attempt_status  => null,
7123                                  p_location_cd          => l_v_location_cd,
7124                                  p_eftsu                => v_eftsu,
7125                                  p_credit_points        => null,
7126                                  p_amount               => 0,
7127                                  p_org_unit_cd          => l_v_org_unit_cd, -- CCR for Enh# 1851586
7128                                  p_trace_on             => p_trace_on,
7129                                  p_message_name         => lv_sum_message,
7130                                  p_uoo_id               => NULL,
7131                                  p_n_unit_type_id       => NULL,
7132                                  p_v_unit_level         => NULL,
7133                                  p_v_unit_class         => NULL,
7134                                  p_v_unit_mode          => NULL,
7135                                  p_v_unit_cd            => NULL,
7136                                  p_n_unit_version       => NULL
7137                                  )  = FALSE THEN
7138                               RETURN FALSE;
7139                   END IF;
7140                 END;
7141               ELSIF (p_charge_method = gcst_crpoint) THEN
7142                 p_charge_elements := NVL(p_charge_elements,0) + NVL(v_credit_points,0);
7143                 log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7144                             p_v_string => 'Cr Point Case: Calling finpl_sum_fee_ass_item with Charge Elemsnts: ' || p_charge_elements);
7145                 BEGIN
7146                   IF finpl_sum_fee_ass_item (
7147                                  p_person_id            => p_person_id,
7148                                  p_status               => 'E',
7149                                  p_fee_type             => p_fee_type,
7150                                  P_fee_cat              => l_v_fee_cat,
7151                                  p_fee_cal_type         => p_fee_cal_type,
7152                                  p_fee_ci_sequence_number=>p_fee_ci_sequence_number,
7153                                  p_course_cd            => l_v_course_cd,
7154                                  p_n_crs_version_number => l_n_crs_version_number,
7155                                  p_chg_method_type      => p_charge_method,
7156                                  p_description          => null,--fee type desc selected inside
7157                                  p_chg_elements         => v_credit_points,
7158                                  p_unit_attempt_status  => null,
7159                                  p_location_cd          => l_v_location_cd,
7160                                  p_eftsu                => null,
7161                                  p_credit_points        => v_credit_points,
7162                                  p_amount               => 0,
7163                                  p_org_unit_cd          => l_v_org_unit_cd, -- CCR for Enh# 1851586
7164                                  p_trace_on             => p_trace_on,
7165                                  p_message_name         => lv_sum_message,
7166                                  p_uoo_id               => NULL,
7167                                  p_n_unit_type_id       => NULL,
7168                                  p_v_unit_level         => NULL,
7169                                  p_v_unit_class         => NULL,
7170                                  p_v_unit_mode          => NULL,
7171                                  p_v_unit_cd            => NULL,
7172                                  p_n_unit_version       => NULL )  = FALSE THEN
7173                               RETURN FALSE;
7174                   END IF;
7175                 END;
7176               END IF;
7177             ELSE
7178               IF (p_trace_on = 'Y') THEN
7179                 fnd_message.set_name ( 'IGS', 'IGS_FI_UNABLE_DETM_DFLTLOAD');
7180                 fnd_file.put_line (fnd_file.log, fnd_message.get);
7181               END IF;
7182               log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7183                           p_v_string => 'Unable derive Default load. Returning false with message IGS_FI_UNABLE_DETM_DFLTLOAD.');
7184               RETURN FALSE;
7185             END IF;
7186           END IF;
7187 
7188           -- ====> ACTUAL MODE
7189           -------------------------
7190 
7191           -- For fee types = Tuition and Other, if profile is Y, then All units are considered.
7192           -- For Audit fee type, consider only Auditable Units (Enh# 3167098, Term Based Fee Calc)
7193           IF (p_s_fee_type = gcst_tuition_other OR  p_s_fee_type = gcst_other) THEN
7194              IF g_v_include_audit = 'Y' THEN
7195                 l_v_fee_ass_ind := NULL;   -- Consider All units
7196              ELSE
7197                 l_v_fee_ass_ind := 'N';  -- Consider only non-auditable units
7198              END IF;
7199           -- For Audit Fee Type, ONLY auditable units are considered, irrespective of the profile value
7200           ELSIF (p_s_fee_type = g_v_audit) THEN
7201                 l_v_fee_ass_ind := 'Y';   -- Consider only auditable units
7202           END IF;
7203 
7204           -- Processing incase of PRIMARY_CAREER is same for Institution and Non-Institution Fees. This is handled after the following code.
7205           IF ( p_s_fee_trigger_cat = gcst_institutn  AND
7206                g_c_fee_calc_mthd <> g_v_primary_career AND
7207                g_c_predictive_ind = 'N') THEN
7208 
7209             log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7210                         p_v_string => 'Actual Mode: Following path 1 (Institution case). l_v_fee_ass_ind: ' || l_v_fee_ass_ind);
7211 
7212             -- This is set to TRUE if the charge method id FLAT RATE and load is incurred.
7213             v_ret_true_flag := FALSE;
7214             tbl_fai_unit_dtls.DELETE;
7215 
7216             ----------------
7217             -- 1. Get all the Program Attempts for the given TERM.
7218             -- 2. Check if the program attempt is liable under FCFL in context.
7219             -- 3. If Yes, Get all unit attached to program attempt in context.
7220             -- 4.         For each unit, calculate Load and derive number of charge elements based on calculated load and charge method.
7221             -- 5. After getting the number of charge elements, call finpl_sum_fee_ass_item to sum up all records in PL/SQL table.
7222             ----------------
7223 
7224               log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7225                           p_v_string => 'Looping thru Program Attempts from TERMS table. Cursor c_sca_psv.');
7226               -- Identify programs for calculating charge elements.
7227               FOR l_sca_psv IN c_sca_psv('CRS_ATTEMPT_STATUS', 'Y') LOOP
7228 
7229                 log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7230                             p_v_string => 'Calling check_stdnt_prg_att_liable with Arguments: '
7231                                           || l_sca_psv.person_id        || ', ' || l_sca_psv.program_cd  || ', '
7232                                           || l_sca_psv.program_version  || ', ' || l_sca_psv.fee_cat  || ', '
7233                                           || p_fee_type                 || ', ' || p_s_fee_trigger_cat  || ', '
7234                                           || p_fee_cal_type             || ', ' || p_fee_ci_sequence_number  || ', '
7235                                           || l_sca_psv.adm_admission_appl_number || ', ' || l_sca_psv.adm_nominated_course_cd  || ', '
7236                                           || l_sca_psv.adm_sequence_number || ', ' || TO_CHAR(l_sca_psv.commencement_dt, 'DD-MON-YYYY') || ', '
7237                                           || TO_CHAR(l_sca_psv.discontinued_dt, 'DD-MON-YYYY') || ', ' || l_sca_psv.cal_type  || ', '
7238                                           || l_sca_psv.location_cd      || ', ' || l_sca_psv.attendance_mode  || ', '
7239                                           || l_sca_psv.attendance_type);
7240                 -- Check if Program Attempt is liable under FCFL in context.
7241                 -- If not, skip this term record and proceed with the next.
7242                 l_b_sca_liable_fcfl := TRUE;
7243                 l_v_prg_liabale := igs_fi_gen_001.check_stdnt_prg_att_liable (
7244                                        p_n_person_id              => l_sca_psv.person_id,
7245                                        p_v_course_cd              => l_sca_psv.program_cd,
7246                                        p_n_course_version         => l_sca_psv.program_version,
7247                                        p_v_fee_cat                => l_sca_psv.fee_cat,
7248                                        p_v_fee_type               => p_fee_type,
7249                                        p_v_s_fee_trigger_cat      => p_s_fee_trigger_cat,
7250                                        p_v_fee_cal_type           => p_fee_cal_type,
7251                                        p_n_fee_ci_seq_number      => p_fee_ci_sequence_number,
7252                                        p_n_adm_appl_number        => l_sca_psv.adm_admission_appl_number,
7253                                        p_v_adm_nom_course_cd      => l_sca_psv.adm_nominated_course_cd,
7254                                        p_n_adm_seq_number         => l_sca_psv.adm_sequence_number,
7255                                        p_d_commencement_dt        => l_sca_psv.commencement_dt,
7256                                        p_d_disc_dt                => l_sca_psv.discontinued_dt,
7257                                        p_v_cal_type               => l_sca_psv.cal_type,
7258                                        p_v_location_cd            => l_sca_psv.location_cd,
7259                                        p_v_attendance_mode        => l_sca_psv.attendance_mode,
7260                                        p_v_attendance_type        => l_sca_psv.attendance_type ) ;
7261                 IF l_v_prg_liabale = 'TRUE' THEN
7262                   -- Program Attempt is liable for the FCFL
7263                   l_b_sca_liable_fcfl := TRUE;
7264                 ELSE
7265                   -- Program Attempt is not liable for the FCFL
7266                   log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7267                               p_v_string => 'After check_stdnt_prg_att_liable: Program Attempt is not liable under this FCFL.');
7268                   l_b_sca_liable_fcfl := FALSE;
7269                 END IF;
7270 
7271                 IF l_b_sca_liable_fcfl THEN
7272                   -- Add entry to global table for Programs liable under Institution Fee FCFL.
7273                   -- This is used in deriving Attendance Mode.
7274                   g_n_inst_progs_cntr := g_n_inst_progs_cntr + 1;
7275                   g_inst_liable_progs_tbl(g_n_inst_progs_cntr).program_cd := l_sca_psv.program_cd;
7276                   g_inst_liable_progs_tbl(g_n_inst_progs_cntr).program_version := l_sca_psv.program_version;
7277                   g_inst_liable_progs_tbl(g_n_inst_progs_cntr).career := l_sca_psv.course_type;
7278 
7279                   log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7280                               p_v_string => 'After check_stdnt_prg_att_liable: Program Attempt is liable under this FCFL. ' ||
7281                                             'Added to g_inst_liable_progs_tbl (' || g_n_inst_progs_cntr ||'). Looping thru Units..' );
7282 
7283                   -- For the each liable program in context, get Unit Attempts for calculation of load.
7284                   FOR v_sualv_scafv_rec IN c_sualv_scafv(p_person_id,
7285                                                          l_sca_psv.program_cd,
7286                                                          l_v_fee_ass_ind,
7287                                                          'UNIT_ATTEMPT_STATUS',
7288                                                          'Y')
7289                   LOOP
7290                     -- initializing the local variables before invoking the load incurred
7291                     v_eftsu :=0;
7292                     v_credit_points :=0;
7293                     l_b_rule := FALSE;
7294                     finpl_get_unit_type_level(v_sualv_scafv_rec.uoo_id, l_n_prg_type_level, l_v_unit_level);
7295                     finpl_get_unit_class_mode(v_sualv_scafv_rec.uoo_id, l_v_unit_class, l_v_unit_mode);
7296                     OPEN cur_unit_cd (v_sualv_scafv_rec.uoo_id);
7297                     FETCH cur_unit_cd INTO l_v_unit_cd, l_n_version_num;
7298                     IF cur_unit_cd%NOTFOUND THEN
7299                       l_v_unit_cd := NULL;
7300                       l_n_version_num := NULL;
7301                     END IF;
7302                     CLOSE cur_unit_cd;
7303 
7304                     IF (p_n_selection_rule IS NOT NULL) THEN
7305                             IF (igs_ru_gen_003.rulp_clc_student_scope(p_rule_number           =>  p_n_selection_rule,
7306                                                                       p_unit_loc_cd           =>  v_sualv_scafv_rec.location_cd,
7307                                                                       p_prg_type_level        =>  finpl_get_uptl(l_n_prg_type_level),
7308                                                                       p_org_code              =>  v_sualv_scafv_rec.owner_org_unit_cd,
7309                                                                       p_unit_mode             =>  l_v_unit_mode,
7310                                                                       p_unit_class            =>  l_v_unit_class,
7311                                                                       p_message               =>  l_v_message_name ) = TRUE) THEN
7312 
7313                                l_b_rule := TRUE;
7314                             END IF;
7315                     ELSE
7316                      l_b_rule := TRUE;
7317                     END IF;
7318                     IF (l_b_rule = TRUE) THEN
7319                           IF ( igs_en_prc_load.enrp_get_load_apply( p_teach_cal_type             => v_sualv_scafv_rec.cal_type,
7320                                                                       p_teach_sequence_number      => v_sualv_scafv_rec.ci_sequence_number,
7321                                                                       p_discontinued_dt            => v_sualv_scafv_rec.discontinued_dt,
7322                                                                       p_administrative_unit_status => v_sualv_scafv_rec.administrative_unit_status,
7323                                                                       p_unit_attempt_status        => v_sualv_scafv_rec.unit_attempt_status,
7324                                                                       p_no_assessment_ind          => v_sualv_scafv_rec.no_assessment_ind,
7325                                                                       p_load_cal_type              => g_v_load_cal_type,
7326                                                                       p_load_sequence_number       => g_n_load_seq_num,
7327                                                                       p_include_audit              => v_sualv_scafv_rec.no_assessment_ind
7328                                                                      ) ='Y') THEN
7329 
7330                               OPEN cur_get_ret_level(p_fee_type, p_fee_cal_type, p_fee_ci_sequence_number);
7331                               FETCH cur_get_ret_level INTO l_v_ret_level;
7332                               CLOSE cur_get_ret_level;
7333                               IF l_v_ret_level = 'TEACH_PERIOD' THEN
7334                                   l_v_class_standing := igs_pr_get_class_std.get_class_standing(p_person_id => p_person_id,
7335                                                                                                 p_course_cd => p_course_cd,
7336                                                                                                 p_predictive_ind => g_c_predictive_ind,
7337                                                                                                 p_effective_dt => NULL,
7338                                                                                                 p_load_cal_type => g_v_load_cal_type,
7339                                                                                                 p_load_ci_sequence_number => g_n_load_seq_num
7340                                                                                                );
7341 
7342                                   OPEN cur_unit_set( p_person_id, p_course_cd, g_d_ld_census_val, 'Y', 'PRENRL_YR' );
7343                                   FETCH cur_unit_set INTO l_v_unit_set_cd, l_n_us_version_num;
7344                                   IF cur_unit_set%NOTFOUND THEN
7345                                     l_v_unit_set_cd := NULL;
7346                                     l_n_us_version_num := NULL;
7347                                   END IF;
7348                                   CLOSE cur_unit_set;
7349 
7350                                   l_n_count := tbl_fai_unit_dtls.COUNT + 1;
7351                                   tbl_fai_unit_dtls(l_n_count).fee_cat              := p_fee_cat;
7352                                   tbl_fai_unit_dtls(l_n_count).course_cd            := l_sca_psv.program_cd;
7353                                   tbl_fai_unit_dtls(l_n_count).crs_version_number   := l_sca_psv.program_version;
7354                                   tbl_fai_unit_dtls(l_n_count).unit_attempt_status  := v_sualv_scafv_rec.unit_attempt_status;
7355                                   tbl_fai_unit_dtls(l_n_count).org_unit_cd          := v_sualv_scafv_rec.org_unit_cd;
7356                                   tbl_fai_unit_dtls(l_n_count).class_standing       := l_v_class_standing;
7357                                   tbl_fai_unit_dtls(l_n_count).location_cd          := v_sualv_scafv_rec.location_cd;
7358                                   tbl_fai_unit_dtls(l_n_count).uoo_id               := v_sualv_scafv_rec.uoo_id;
7359                                   tbl_fai_unit_dtls(l_n_count).unit_set_cd          := l_v_unit_set_cd;
7360                                   tbl_fai_unit_dtls(l_n_count).us_version_number    := l_n_us_version_num;
7361                                   tbl_fai_unit_dtls(l_n_count).unit_type_id         := l_n_prg_type_level;
7362                                   tbl_fai_unit_dtls(l_n_count).unit_level           := l_v_unit_level;
7363                                   tbl_fai_unit_dtls(l_n_count).unit_class           := l_v_unit_class;
7364                                   tbl_fai_unit_dtls(l_n_count).unit_mode            := l_v_unit_mode;
7365                                   tbl_fai_unit_dtls(l_n_count).unit_cd              := l_v_unit_cd;
7366                                   tbl_fai_unit_dtls(l_n_count).unit_version_number  := l_n_version_num;
7367                               END IF;
7368 
7369 
7370                               -- In case of FLAT RATE, finpl_sum_fee_ass_item should be called only once for all courses. For doing this, use v_ret_true_flag.
7371                               IF (p_charge_method = gcst_flatrate) AND (NOT v_ret_true_flag) THEN
7372                               -- If the nonzero billable cp flag is 'Y' then check the credit points
7373                                 OPEN cur_nz_bill_cp_flag( p_fee_type, p_fee_cal_type, p_fee_ci_sequence_number );
7374                                 FETCH cur_nz_bill_cp_flag INTO l_v_nz_bill_cp_flag;
7375                                 CLOSE cur_nz_bill_cp_flag;
7376                                 IF l_v_nz_bill_cp_flag = 'Y' THEN
7377                                   -- call finpl_clc_sua_cp to get the credit points
7378                                   v_credit_points := finpl_clc_sua_cp( p_v_unit_cd                => v_sualv_scafv_rec.unit_cd,
7379                                                                      p_n_version_number           => v_sualv_scafv_rec.version_number,
7380                                                                      p_v_cal_type                 => v_sualv_scafv_rec.cal_type,
7381                                                                      p_n_ci_sequence_number       => v_sualv_scafv_rec.ci_sequence_number,
7382                                                                      p_v_load_cal_type            => g_v_load_cal_type,
7383                                                                      p_n_load_ci_sequence_number  => g_n_load_seq_num,
7384                                                                      p_n_override_enrolled_cp     => v_sualv_scafv_rec.override_enrolled_cp,
7385                                                                      p_n_override_eftsu           => v_sualv_scafv_rec.override_eftsu,
7386                                                                      p_n_uoo_id                   => v_sualv_scafv_rec.uoo_id,
7387                                                                      p_v_include_audit            => v_sualv_scafv_rec.no_assessment_ind);
7388                                   v_credit_points := NVL(v_credit_points,0);
7389                                 END IF;
7390 
7391                                   IF (l_v_nz_bill_cp_flag = 'Y' AND v_credit_points > 0) OR l_v_nz_bill_cp_flag = 'N'  THEN
7392                                      p_charge_elements := 1;
7393                                      IF finpl_sum_fee_ass_item ( p_person_id=>p_person_id,
7394                                                                  p_status=>'E',
7395                                                                  p_fee_type=>p_fee_type,
7396                                                                  P_fee_cat=>NULL,
7397                                                                  p_fee_cal_type=>p_fee_cal_type,
7398                                                                  p_fee_ci_sequence_number=>p_fee_ci_sequence_number,
7399                                                                  p_course_cd=>NULL,
7400                                                                  p_n_crs_version_number => NULL,
7401                                                                  p_chg_method_type=>p_charge_method,
7402                                                                  p_description=>null ,--fee type desc selected inside
7403                                                                  p_chg_elements=>p_charge_elements,--which is 1
7404                                                                  p_unit_attempt_status =>NULL,
7405                                                                  p_location_cd=>NULL,
7406                                                                  p_eftsu =>NULL,
7407                                                                  p_credit_points=>NULL,
7408                                                                  p_amount=>0,
7409                                                                  p_org_unit_cd => NULL,
7410                                                                  p_trace_on=>p_trace_on,
7411                                                                  p_message_name=>lv_sum_message,
7412                                                                  p_uoo_id => NULL,
7413                                                                  p_n_unit_type_id => NULL,
7414                                                                  p_v_unit_level   => NULL,
7415                                                                  p_v_unit_class   => NULL,
7416                                                                  p_v_unit_mode    => NULL,
7417                                                                  p_v_unit_cd      => NULL,
7418                                                                  p_n_unit_version => NULL )  = FALSE THEN
7419                                       log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7420                                                  p_v_string => 'Flat Rate Case: Returning False as finpl_sum_fee_ass_item returned message: ' || lv_sum_message);
7421                                       RETURN FALSE;
7422                                      END IF;
7423                                      IF (p_trace_on = 'Y') THEN
7424                                         fnd_file.new_line(fnd_file.log);
7425                                         fnd_message.set_name ( 'IGS', 'IGS_FI_LOAD_INCURRED');
7426                                         fnd_message.set_token('YES_NO', igs_fi_gen_gl.get_lkp_meaning('YES_NO', 'Y') );
7427                                         fnd_file.put_line (fnd_file.log, fnd_message.get);
7428                                         fnd_message.set_name('IGS', 'IGS_FI_CHRG_METHOD_ELEMENTS');
7429                                         fnd_message.set_token('CHG_ELM', TO_CHAR(p_charge_elements));
7430                                         fnd_file.put_line (fnd_file.log, fnd_message.get);
7431                                      END IF;
7432                                     v_ret_true_flag := TRUE;
7433                                   END IF;
7434 
7435 
7436                               ELSIF (p_charge_method = gcst_perunit) THEN
7437                                 -- Consider all Units that are assessable, Cursor c_sualv_scafv will get all assessable units only.
7438                                 p_charge_elements := p_charge_elements + 1;
7439                                 IF l_v_ret_level = 'TEACH_PERIOD' THEN
7440                                   tbl_fai_unit_dtls(l_n_count).chg_elements := 1;
7441                                 END IF;
7442                                 IF (p_trace_on = 'Y') THEN
7443                                   fnd_file.new_line(fnd_file.log);
7444                                   fnd_message.set_name ( 'IGS', 'IGS_FI_LOAD_INCURRED');
7445                                   fnd_message.set_token('YES_NO', igs_fi_gen_gl.get_lkp_meaning('YES_NO', 'Y') );
7446                                   fnd_file.put_line (fnd_file.log, fnd_message.get);
7447                                   fnd_message.set_name('IGS', 'IGS_FI_CHG_ELE');
7448                                   fnd_message.set_token('ELEMENTS', TO_CHAR(p_charge_elements));
7449                                   fnd_file.put_line (fnd_file.log, fnd_message.get);
7450                                 END IF;
7451 
7452                               ELSIF (p_charge_method = gcst_eftsu) THEN
7453                                 -- Consider all Units that are assessable, Cursor c_sualv_scafv will get all assessable units only.
7454                                 v_eftsu := igs_en_prc_load.enrp_clc_sua_eftsu(
7455                                                p_person_id,
7456                                                p_course_cd,
7457                                                p_course_version_number,
7458                                                v_sualv_scafv_rec.unit_cd,
7459                                                v_sualv_scafv_rec.version_number,
7460                                                v_sualv_scafv_rec.cal_type,
7461                                                v_sualv_scafv_rec.ci_sequence_number,
7462                                                v_sualv_scafv_rec.uoo_id,
7463                                                g_v_load_cal_type,
7464                                                g_n_load_seq_num,
7465                                                v_sualv_scafv_rec.override_enrolled_cp,
7466                                                v_sualv_scafv_rec.override_eftsu,
7467                                                'Y',
7468                                                NULL,
7469                                                g_c_key_program,  -- new parameters , key program and version number are newly added, Career Impact DLD
7470                                                g_n_key_version,
7471                                                v_credit_points,
7472                                                v_sualv_scafv_rec.no_assessment_ind );
7473                                 v_eftsu := NVL(v_eftsu,0);
7474                                 IF l_v_ret_level = 'TEACH_PERIOD' THEN
7475                                   tbl_fai_unit_dtls(l_n_count).chg_elements := v_eftsu;
7476                                 END IF;
7477                                 p_charge_elements := p_charge_elements + v_eftsu;
7478 
7479                                 log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7480                                             p_v_string => 'Derived Vals from enrp_clc_sua_eftsu- Uoo: ' || v_sualv_scafv_rec.uoo_id
7481                                                           || ', Eftsu:' || v_eftsu || ', Charge Elements: ' || p_charge_elements );
7482                                 IF (p_trace_on = 'Y') THEN
7483                                  fnd_file.new_line(fnd_file.log);
7484                                  fnd_message.set_name('IGS', 'IGS_FI_LOAD_INCURRED');
7485                                  fnd_message.set_token('YES_NO', igs_fi_gen_gl.get_lkp_meaning('YES_NO', 'Y') );
7486                                  fnd_file.put_line (fnd_file.log, fnd_message.get);
7487                                  fnd_message.set_name('IGS', 'IGS_FI_CHG_ELE');
7488                                  fnd_message.set_token('ELEMENTS', TO_CHAR(NVL(v_eftsu, 0)));
7489                                  fnd_file.put_line (fnd_file.log, fnd_message.get);
7490                                 END IF;
7491 
7492                               ELSIF (p_charge_method = gcst_crpoint) THEN  -- Credit Points
7493                                 -- Consider all Units that are assessable, Cursor c_sualv_scafv will get all assessable units only.
7494                                 -- Added this call as part of Enh# 3741400, Billable Credit Points
7495                                 v_credit_points := finpl_clc_sua_cp( p_v_unit_cd                  => v_sualv_scafv_rec.unit_cd,
7496                                                                      p_n_version_number           => v_sualv_scafv_rec.version_number,
7497                                                                      p_v_cal_type                 => v_sualv_scafv_rec.cal_type,
7498                                                                      p_n_ci_sequence_number       => v_sualv_scafv_rec.ci_sequence_number,
7499                                                                      p_v_load_cal_type            => g_v_load_cal_type,
7500                                                                      p_n_load_ci_sequence_number  => g_n_load_seq_num,
7501                                                                      p_n_override_enrolled_cp     => v_sualv_scafv_rec.override_enrolled_cp,
7502                                                                      p_n_override_eftsu           => v_sualv_scafv_rec.override_eftsu,
7503                                                                      p_n_uoo_id                   => v_sualv_scafv_rec.uoo_id,
7504                                                                      p_v_include_audit            => v_sualv_scafv_rec.no_assessment_ind);
7505                                 v_credit_points := NVL(v_credit_points,0);
7506                                 IF l_v_ret_level = 'TEACH_PERIOD' THEN
7507                                   tbl_fai_unit_dtls(l_n_count).chg_elements := v_credit_points;
7508                                 END IF;
7509                                 p_charge_elements := p_charge_elements + v_credit_points;
7510 
7511                                 log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7512                                             p_v_string => 'Derived Vals from finpl_clc_sua_cp- Uoo: ' || v_sualv_scafv_rec.uoo_id
7513                                                           || ', Credit Points:' || v_credit_points || ', Charge Elements: ' || p_charge_elements );
7514                                 IF (p_trace_on = 'Y') THEN
7515                                  fnd_file.new_line(fnd_file.log);
7516                                  fnd_message.set_name('IGS', 'IGS_FI_LOAD_INCURRED');
7517                                  fnd_message.set_token('YES_NO', igs_fi_gen_gl.get_lkp_meaning('YES_NO', 'Y') );
7518                                  fnd_file.put_line (fnd_file.log, fnd_message.get);
7519                                  fnd_message.set_name('IGS', 'IGS_FI_CHG_ELE');
7520                                  fnd_message.set_token('ELEMENTS', TO_CHAR(NVL(v_credit_points, 0)));
7521                                  fnd_file.put_line (fnd_file.log, fnd_message.get);
7522                                END IF;
7523                               END IF;
7524                             END IF;
7525                     END IF;
7526                   END LOOP; /* For cursor, c_sualv_scafv */
7527                 END IF; /* l_b_sca_liable_fcfl */
7528               END LOOP; /* For Cursor c_sca_psv */
7529 
7530             -- inserting the record in the pl/sql table only once for the case of institution
7531             -- triggered fee. this is change implemented thru CCR SFCR009
7532             IF p_charge_method <> gcst_flatrate THEN
7533               IF p_charge_method = gcst_eftsu THEN
7534                 l_eftsu := p_charge_elements;
7535                 l_crpoint := NULL;
7536               ELSIF p_charge_method = gcst_crpoint THEN
7537                 l_eftsu := NULL;
7538                 l_crpoint := p_charge_elements;
7539               END IF;
7540               log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7541                           p_v_string => 'Other than Flat Rate Case: calling finpl_sum_fee_ass_item.');
7542               IF finpl_sum_fee_ass_item (p_person_id=>p_person_id,
7543                                          p_status=>'E',
7544                                          p_fee_type=>p_fee_type,
7545                                          P_fee_cat=>NULL,
7546                                          p_fee_cal_type=>p_fee_cal_type,
7547                                          p_fee_ci_sequence_number=>p_fee_ci_sequence_number,
7548                                          p_course_cd=>NULL,
7549                                          p_n_crs_version_number => NULL,
7550                                          p_chg_method_type=>p_charge_method,
7551                                          p_description=>null ,--fee type desc selected inside
7552                                          p_chg_elements=>p_charge_elements,
7553                                          p_unit_attempt_status =>NULL,
7554                                          p_location_cd=>NULL,
7555                                          p_eftsu    => l_eftsu,
7556                                          p_credit_points=> l_crpoint,
7557                                          p_amount=>0,
7558                                          p_org_unit_cd => NULL, -- CCR for Enh# 1851586
7559                                          p_trace_on=>p_trace_on,
7560                                          p_message_name=>lv_sum_message,
7561                                          p_uoo_id => NULL,
7562                                          p_n_unit_type_id => NULL,
7563                                          p_v_unit_level   => NULL,
7564                                          p_v_unit_class   => NULL,
7565                                          p_v_unit_mode    => NULL,
7566                                          p_v_unit_cd      => NULL,
7567                                          p_n_unit_version => NULL)  = FALSE THEN
7568                 log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7569                             p_v_string => 'Other than Flat Rate Case: Returning false as finpl_sum_fee_ass_item returned message: '||lv_sum_message);
7570                 RETURN FALSE;
7571               END IF;
7572             END IF;
7573           END IF;
7574 
7575           IF ((p_s_fee_trigger_cat <> gcst_institutn OR g_c_fee_calc_mthd= g_v_primary_career)
7576                AND (g_c_predictive_ind = 'N')) THEN
7577 
7578             log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7579                         p_v_string => 'Actual Mode: Following path 2 (Non-Institution case). l_v_fee_ass_ind: ' || l_v_fee_ass_ind);
7580             -- This captures return value from finpl_prc_sua_load which returns true if the charge method is FLAT RATE.
7581             v_ret_true_flag := FALSE;
7582 
7583             log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7584                           p_v_string => 'Loop Thru Units of course: ' || p_course_cd);
7585                 -- Current date - use current student Unit attempt
7586               FOR v_sua_load_rec IN c_sua_load ( p_person_id,
7587                                                  p_course_cd,
7588                                                  p_course_version_number,
7589                                                  g_v_load_cal_type,
7590                                                  g_n_load_seq_num,
7591                                                  l_v_fee_ass_ind,
7592                                                  'UNIT_ATTEMPT_STATUS',
7593                                                  'Y',
7594                                                  'Y' )
7595               LOOP
7596                 log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7597                             p_v_string => 'Derived Vals from c_sua_load- Uoo: ' || v_sua_load_rec.uoo_id || ', Auditable Ind: ' || v_sua_load_rec.no_assessment_ind
7598                                            || ', Credit Points:' || v_sua_load_rec.credit_points || ', Charge Elements: ' || v_sua_load_rec.eftsu );
7599 
7600                 l_b_rule := FALSE;
7601 
7602                 finpl_get_unit_type_level(v_sua_load_rec.uoo_id, l_n_prg_type_level, l_v_unit_level);
7603                 finpl_get_unit_class_mode(v_sua_load_rec.uoo_id, l_v_unit_class, l_v_unit_mode);
7604 
7605                 IF (p_n_selection_rule IS NOT NULL) THEN
7606                         IF (igs_ru_gen_003.rulp_clc_student_scope (p_rule_number              =>  p_n_selection_rule,
7607                                                                       p_unit_loc_cd           =>  v_sua_load_rec.location_cd,
7608                                                                       p_prg_type_level        =>  finpl_get_uptl(l_n_prg_type_level),
7609                                                                       p_org_code              =>  v_sua_load_rec.owner_org_unit_cd,
7610                                                                       p_unit_mode             =>  l_v_unit_mode,
7611                                                                       p_unit_class            =>  l_v_unit_class,
7612                                                                       p_message               =>  l_v_message_name ) = TRUE) THEN
7613                                l_b_rule := TRUE;
7614                         END IF;
7615                 ELSE
7616                     l_b_rule := TRUE;
7617                 END IF;
7618                 IF (l_b_rule = TRUE) THEN
7619                         --In case of flat rate the program level location code is to be used # 1906022
7620                         OPEN cur_nz_bill_cp_flag( p_fee_type, p_fee_cal_type, p_fee_ci_sequence_number );
7621                         FETCH cur_nz_bill_cp_flag INTO l_v_nz_bill_cp_flag;
7622                         CLOSE cur_nz_bill_cp_flag;
7623                        -- if the nonzero billable cp flag is 'Y' and credit points is 0 then ignore that unit attempt
7624                         IF NOT(p_charge_method = gcst_flatrate AND l_v_nz_bill_cp_flag = 'Y'  AND v_sua_load_rec.credit_points = 0) THEN
7625 
7626                         IF p_charge_method = gcst_flatrate THEN
7627                           v_derived_location_cd := p_location_cd;
7628                         ELSE
7629                           v_derived_location_cd := v_sua_load_rec.location_cd;
7630                         END IF;
7631                         -- Flag v_ret_true_flag will be set to TRUE in the function finpl_prc_sua_load for 'Flat Rate' charge method
7632                         -- For all other charge methods the FALSE will be returned from this function and should continue for each
7633                         -- fee assessable unit
7634                         IF NOT v_ret_true_flag THEN
7635                           log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7636                                       p_v_string => 'Calling finpl_prc_sua_load..');
7637                           IF (finpl_prc_sua_load(p_effective_dt,
7638                                                  p_trace_on,
7639                                                  p_person_id,
7640                                                  p_course_cd,
7641                                                  p_course_version_number,
7642                                                  v_sua_load_rec.unit_cd,
7643                                                  v_sua_load_rec.version_number,
7644                                                  v_sua_load_rec.cal_type,
7645                                                  v_sua_load_rec.effective_start_dt,
7646                                                  v_sua_load_rec.effective_end_dt,
7647                                                  NVL(v_sua_load_rec.eftsu,0),
7648                                                  NVL(v_sua_load_rec.credit_points,0),
7649                                                  p_s_fee_type,
7650                                                  p_charge_method,
7651                                                  p_fee_type ,
7652                                                  p_fee_cat  ,
7653                                                  p_fee_cal_type,
7654                                                  p_fee_ci_sequence_number,
7655                                                  v_sua_load_rec.unit_attempt_status,
7656                                                  v_derived_location_cd,
7657                                                  v_sua_load_rec.ci_sequence_number,
7658                                                  p_charge_elements,      -- IN OUT
7659                                                  v_ret_true_flag,        -- OUT
7660                                                  p_message_name,
7661                                                  p_s_fee_trigger_cat,
7662                                                  v_sua_load_rec.uoo_id,
7663                                                  v_sua_load_rec.course_cd,
7664                                                  l_n_prg_type_level,
7665                                                  l_v_unit_level,
7666                                                  l_v_unit_mode
7667                                                  ) = FALSE) THEN   --Enh# 2162747, added new parameter p_unit_course_cd to finpl_prc_sua_load
7668                             log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7669                                         p_v_string => 'Returning as finpl_prc_sua_load returned false. Out: ' || p_charge_elements );
7670                             RETURN FALSE;
7671                           END IF;
7672                           log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7673                                       p_v_string => 'After call to finpl_prc_sua_load, Charge Elements: ' || p_charge_elements );
7674                         END IF;
7675                         END IF;
7676                 END IF;
7677               END LOOP;
7678 
7679           END IF;         -- not institution and not unconfirm
7680 
7681           log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7682                       p_v_string => 'At the end of processing, Charge Elements: ' || p_charge_elements );
7683           RETURN TRUE;
7684         END;
7685         EXCEPTION
7686         WHEN OTHERS THEN
7687                 log_to_fnd( p_v_module => 'finpl_clc_chg_mthd_elements',
7688                             p_v_string => 'From Exception Handler of When Others.');
7689                 FND_MESSAGE.SET_NAME('IGS','IGS_GE_UNHANDLED_EXP');
7690                 FND_MESSAGE.SET_TOKEN('NAME','IGS_FI_PRC_FEE_ASS.FINPL_CLC_CHG_MTHD_ELEMENTS-'||SUBSTR(sqlerrm,1,500));
7691                 IGS_GE_MSG_STACK.ADD;
7692                  lv_param_values := to_char(p_effective_dt)||','||p_trace_on||','||
7693                  to_char(p_person_id)||','||
7694                   p_course_cd||','||to_char(p_course_version_number)||','||
7695                   p_attendance_type||','||p_course_attempt_status||','||
7696                   p_charge_method||','||
7697                   p_fee_cat||','||
7698                   p_fee_cal_type||','||
7699                   to_char(p_fee_ci_sequence_number)||','||
7700                   p_fee_type||','||
7701                   p_s_fee_type||','||
7702                   p_s_fee_trigger_cat||','||
7703                   p_charge_elements;
7704                  FND_MESSAGE.SET_NAME('IGS','IGS_GE_PARAMETERS');
7705                  FND_MESSAGE.SET_TOKEN('VALUE',lv_param_values);
7706                  IGS_GE_MSG_STACK.ADD;
7707                   App_Exception.Raise_Exception;
7708        END finpl_clc_chg_mthd_elements;
7709 
7710 
7711     -------------------------------------------------------------------------------
7712 
7713     -- Removed finpl_val_sua_census as part of Enh# 3167098, Term Based Fee Calc
7714 
7715     -------------------------------------------------------------------------------
7716         FUNCTION finpl_prc_fee_cat_fee_liab (
7717                 p_effective_dt                  DATE,
7718                 p_trace_on                      VARCHAR2,
7719                 p_fee_cal_type                  igs_ca_inst_all.cal_type%TYPE,
7720                 p_fee_ci_sequence_num           igs_ca_inst_all.sequence_number%TYPE,
7721                 p_local_currency                igs_fi_control_all.currency_cd%TYPE,
7722                 p_fee_cat                       igs_en_stdnt_ps_att_all.fee_cat%tYPE,
7723                 p_person_id                     hz_parties.party_id%TYPE,
7724                 p_course_cd                     igs_en_stdnt_ps_att_all.course_cd%TYPE,
7725                 p_course_version_number         igs_en_stdnt_ps_att_all.version_number%TYPE,
7726                 p_cal_type                      igs_en_stdnt_ps_att_all.cal_type%TYPE,
7727                 p_scahv_location_cd             igs_en_stdnt_ps_att_all.location_cd%TYPE,
7728                 p_scahv_attendance_mode         igs_en_stdnt_ps_att_all.attendance_mode%TYPE,
7729                 p_scahv_attendance_type         igs_en_stdnt_ps_att_all.attendance_type%TYPE,
7730                 p_discontinued_dt               igs_en_stdnt_ps_att_all.discontinued_dt%TYPE,
7731                 p_course_attempt_status         igs_en_stdnt_ps_att_all.course_attempt_status%TYPE,
7732                 p_message_name              OUT NOCOPY  VARCHAR2,
7733                 p_process_mode               IN VARCHAR2 ,
7734                 p_c_career                   IN igs_ps_ver_all.course_type%TYPE,
7735                 p_waiver_call_ind            IN VARCHAR2,
7736                 p_target_fee_type            IN VARCHAR2
7737                 ) RETURN BOOLEAN AS
7738                 /*************************************************************
7739                   Change History
7740                   Who             When            What
7741                   abshriva       19-Jun-2006     Bug 5104329 -Invoked finpl_get_derived_am_at to pass derived values of
7742                                                  attendance mode and type before all callouts to finpl_ins_fee_ass.
7743                   pathipat       23-Nov-2005      Bug 4718712 - Added code to assign values to p_course_cd and p_career
7744                                                   in tbl_wav_fcfl if Waiver Assignment exists.
7745                   bannamal       26-Aug-2005      Enh#3392095 Tuition Waiver Build. Added two new parameters.
7746                   bannamal       08-Jul-2005      Enh#3392088 Campus Privilege Fee.
7747                                                   Modified the cursor c_fcflv and changed the call to finpl_clc_ass_amnt.
7748                   pathipat        06-Jul-2004     Bug 3734842 - Added logic to lock records before processing
7749                   UUDYAPR         17-DEC-2003    --BUG 3080983Modified The Parameter Type Of v_fee_assessment To
7750                                                    Number From Igs_fi_fee_ass_debt_v.Assessment_amount%Type.
7751                   pathipat        05-Nov-2003     Enh 3117341 - Audit and Special Fees TD
7752                                                   Added code for Audit Fee Trigger fired
7753                   (reverse chronological order - newest change first)
7754                 ***************************************************************/
7755                 -- Exception raised when a lock could not be obtained in the Temp table. (pathipat, as part of bug 3734842)
7756                 e_lock_exception                EXCEPTION;
7757                 PRAGMA EXCEPTION_INIT(e_lock_exception, -54);
7758 
7759         BEGIN
7760           DECLARE
7761                 cst_completed   CONSTANT        igs_en_stdnt_ps_att_all.course_attempt_status%TYPE := 'COMPLETED';
7762                 v_next_fcfl_flag                BOOLEAN;
7763                 v_charge_rate                   IGS_FI_FEE_AS_RATE.chg_rate%TYPE;
7764                 v_charge_elements               igs_fi_fee_as_all.chg_elements%TYPE;
7765                 v_fee_assessment                NUMBER;
7766                 v_fee_cat                       IGS_FI_F_CAT_CA_INST.FEE_CAT%TYPE;
7767                 v_fee_cal_type                  IGS_FI_F_CAT_CA_INST.fee_cal_type%TYPE;
7768                 v_fee_ci_sequence_number        IGS_FI_F_CAT_CA_INST.fee_ci_sequence_number%TYPE;
7769                 v_fcci_end_dt                   IGS_CA_DA_INST_V.alias_val%TYPE;
7770                 v_fcflv_start_dt                IGS_CA_DA_INST_V.alias_val%TYPE;
7771                 v_fcflv_end_dt                  IGS_CA_DA_INST_V.alias_val%TYPE;
7772                 v_fcci_found                    BOOLEAN;
7773                 v_fcfl_found                    BOOLEAN;
7774                 v_message_name                  VARCHAR2(30);
7775                 v_trigger_fired                 fnd_lookup_values.lookup_code%TYPE;
7776                 l_n_rec_count                   NUMBER;
7777                 l_v_attendance_type             igs_en_stdnt_ps_att_all.attendance_type%TYPE;
7778                 l_v_attendance_mode             igs_en_stdnt_ps_att_all.attendance_mode%TYPE;
7779 
7780                 inst_liable_prog_dummy_tbl      inst_prog_det_tbl_typ;
7781 
7782                 CURSOR c_fcci_fss (
7783                         cp_effective_dt DATE) IS
7784                         SELECT  fcci.FEE_CAT,
7785                                 fcci.fee_cal_type,
7786                                 fcci.fee_ci_sequence_number,
7787                                 fcci.start_dt_alias,
7788                                 fcci.start_dai_sequence_number,
7789                                 fcci.end_dt_alias,
7790                                 fcci.end_dai_sequence_number,
7791                                 ci.start_dt,
7792                                 ci.end_dt
7793                         FROM    IGS_FI_F_CAT_CA_INST    fcci,
7794                                 IGS_FI_FEE_STR_STAT     fss,
7795                                 igs_ca_inst_all             ci
7796                         WHERE   fcci.FEE_CAT = p_fee_cat AND
7797                                 (p_fee_cal_type IS NULL OR fcci.fee_cal_type = p_fee_cal_type) AND
7798                                 (p_fee_ci_sequence_num IS NULL OR
7799                                 fcci.fee_ci_sequence_number = p_fee_ci_sequence_num) AND
7800                                 (
7801                                  -- In Predictive, Select only when Effective Date (i.e., SYSDATE) is less than FCFL Start Date Alias Value.
7802                                  ( g_c_predictive_ind = 'Y' AND
7803                                    (TRUNC(cp_effective_dt) < (SELECT TRUNC(daiv.alias_val)
7804                                                               FROM igs_ca_da_inst_v  daiv
7805                                                               WHERE daiv.DT_ALIAS = fcci.start_dt_alias AND
7806                                                               daiv.sequence_number = fcci.start_dai_sequence_number AND
7807                                                               daiv.CAL_TYPE =fcci.fee_cal_type AND
7808                                                               daiv.ci_sequence_number = fcci.fee_ci_sequence_number AND
7809                                                               daiv.alias_val IS NOT NULL))
7810                                  )
7811                                  OR
7812                                  -- In Actual, Select only when FCFL is active as on Effective Date. (i.e., Eff Date <= FCFL Start Date Alias)
7813                                  ( g_c_predictive_ind = 'N' AND
7814                                    (TRUNC(cp_effective_dt) >= (SELECT TRUNC(daiv.alias_val)
7815                                                                FROM igs_ca_da_inst_v  daiv
7816                                                                WHERE daiv.DT_ALIAS = fcci.start_dt_alias AND
7817                                                                daiv.sequence_number = fcci.start_dai_sequence_number AND
7818                                                                daiv.CAL_TYPE =fcci.fee_cal_type AND
7819                                                                daiv.ci_sequence_number = fcci.fee_ci_sequence_number AND
7820                                                                daiv.alias_val IS NOT NULL))
7821                                  )
7822                                 ) AND
7823                                 TRUNC(cp_effective_dt) <=
7824                                         (SELECT TRUNC(daiv.alias_val)
7825                                         FROM    IGS_CA_DA_INST_V        daiv
7826                                         WHERE   daiv.DT_ALIAS = fcci.end_dt_alias AND
7827                                                 daiv.sequence_number = fcci.end_dai_sequence_number AND
7828                                                 daiv.CAL_TYPE =fcci.fee_cal_type AND
7829                                                 daiv.ci_sequence_number = fcci.fee_ci_sequence_number AND
7830                                                 daiv.alias_val IS NOT NULL) AND
7831                                 (p_discontinued_dt IS NULL OR
7832                                 (TRUNC(p_discontinued_dt) >=
7833                                         (SELECT TRUNC(daiv.alias_val)
7834                                         FROM    IGS_CA_DA_INST_V        daiv
7835                                         WHERE   daiv.DT_ALIAS = fcci.start_dt_alias AND
7836                                                 daiv.sequence_number = fcci.start_dai_sequence_number AND
7837                                                 daiv.CAL_TYPE =fcci.fee_cal_type AND
7838                                                 daiv.ci_sequence_number = fcci.fee_ci_sequence_number AND
7839                                                 daiv.alias_val IS NOT NULL) AND
7840                                 TRUNC(p_discontinued_dt) <=
7841                                         (SELECT TRUNC(daiv.alias_val)
7842                                         FROM    IGS_CA_DA_INST_V        daiv
7843                                         WHERE   daiv.DT_ALIAS = fcci.end_dt_alias AND
7844                                                 daiv.sequence_number = fcci.end_dai_sequence_number AND
7845                                                 daiv.CAL_TYPE =fcci.fee_cal_type AND
7846                                                 daiv.ci_sequence_number = fcci.fee_ci_sequence_number AND
7847                                                 daiv.alias_val IS NOT NULL))) AND
7848                                 fcci.fee_cat_ci_status = fss.FEE_STRUCTURE_STATUS AND
7849                                 fss.s_fee_structure_status = gcst_active AND
7850                                 ci.CAL_TYPE = fcci.fee_cal_type AND
7851                                 ci.sequence_number = fcci.fee_ci_sequence_number;
7852                 CURSOR c_daiv (
7853                         cp_dt_alias                     IGS_CA_DA_INST.DT_ALIAS%TYPE,
7854                         cp_dai_sequence_number          IGS_CA_DA_INST.sequence_number%TYPE,
7855                         cp_fee_cal_type                 IGS_CA_DA_INST.CAL_TYPE%TYPE,
7856                         cp_fee_ci_sequence_number       IGS_CA_DA_INST.ci_sequence_number%TYPE) IS
7857                         SELECT  daiv.alias_val
7858                         FROM    IGS_CA_DA_INST_V        daiv
7859                         WHERE   daiv.DT_ALIAS = cp_dt_alias AND
7860                                 daiv.sequence_number = cp_dai_sequence_number AND
7861                                 daiv.CAL_TYPE =cp_fee_cal_type AND
7862                                 daiv.ci_sequence_number = cp_fee_ci_sequence_number;
7863                 CURSOR c_fcflv (
7864                         cp_fee_cat              IGS_FI_F_CAT_CA_INST.FEE_CAT%TYPE,
7865                         cp_fee_cal_type         IGS_FI_F_CAT_CA_INST.fee_cal_type%TYPE,
7866                         cp_fee_ci_sequence_number IGS_FI_F_CAT_CA_INST.fee_ci_sequence_number%TYPE,
7867                         cp_v_s_transaction_type igs_fi_fee_as_all.s_transaction_type%TYPE ) IS
7868                   SELECT fcflv.fee_cal_type,
7869                           fcflv.fee_ci_sequence_number,
7870                           fcflv.FEE_TYPE,
7871                           fcflv.fee_liability_status,
7872                           fcflv.start_dt_alias,
7873                           fcflv.start_dai_sequence_number,
7874                           fcflv.end_dt_alias,
7875                           fcflv.end_dai_sequence_number,
7876                           fcflv.s_chg_method_type,
7877                           fcflv.rul_sequence_number,
7878                           fcflv.currency_cd,
7879                           fss.s_fee_structure_status,
7880                           ft.s_fee_trigger_cat,
7881                           ft.s_fee_type,
7882                           fcflv.fee_cat,
7883                           'CURRENT' source,
7884                           fcflv.elm_rng_order_name,
7885                           fcflv.scope_rul_sequence_num,
7886                           fcflv.max_chg_elements
7887                   FROM    igs_fi_f_cat_fee_lbl_v  fcflv,
7888                           igs_fi_fee_str_stat     fss,
7889                           igs_fi_fee_type_all         ft
7890                   WHERE   fcflv.fee_cat = cp_fee_cat AND
7891                           fcflv.fee_cal_type = cp_fee_cal_type AND
7892                           fcflv.fee_ci_sequence_number = cp_fee_ci_sequence_number AND
7893                           (p_fee_type IS NULL OR fcflv.fee_type = p_fee_type) AND
7894                           fcflv.fee_liability_status = fss.fee_structure_status AND
7895                           fcflv.fee_type = ft.fee_type AND
7896                           (p_waiver_call_ind = 'N' OR (p_waiver_call_ind = 'Y' AND fcflv.fee_type = p_target_fee_type)) AND
7897                           ((p_v_wav_calc_flag = 'Y' AND fcflv.waiver_calc_flag = 'Y') OR (p_v_wav_calc_flag = 'N' AND fcflv.waiver_calc_flag = 'N'))
7898                   UNION ALL
7899                   -- This will select FCFLs from Fee As Items table that are not selected in above part of cursor.
7900                   SELECT DISTINCT ast.fee_cal_type,
7901                          ast.fee_ci_sequence_number,
7902                          ast.fee_type,
7903                          NULL,
7904                          NULL,
7905                          TO_NUMBER(NULL),
7906                          NULL,
7907                          TO_NUMBER(NULL),
7908                          NULL,
7909                          TO_NUMBER(NULL),
7910                          NULL,
7911                          'INACTIVE',
7912                          ft.s_fee_trigger_cat,
7913                          ft.s_fee_type,
7914                          ast.fee_cat,
7915                          'OLD' source,
7916                          ast.elm_rng_order_name,
7917                          ast.scope_rul_sequence_num,
7918                          ast.max_chg_elements
7919                   FROM igs_fi_fee_as_items ast,
7920                        igs_fi_fee_as_all fas,
7921                        igs_fi_fee_type_all ft,
7922                        igs_ps_ver_all ps
7923                   WHERE ast.person_id = p_person_id
7924                   AND (p_fee_type IS NULL OR (p_fee_type IS NOT NULL AND ast.fee_type = p_fee_type))-- will reverse existing charges only when user has not provided Fee Type as input
7925                   AND ps.course_cd (+) = ast.course_cd
7926                   AND ps.version_number (+) = ast.crs_version_number
7927                   AND ast.fee_cal_type = cp_fee_cal_type
7928                   AND ast.fee_ci_sequence_number = cp_fee_ci_sequence_number
7929                   AND ast.fee_type = ft.fee_type
7930                   AND ast.person_id = fas.person_id
7931                   AND ast.transaction_id = fas.transaction_id
7932                   AND fas.s_transaction_type = cp_v_s_transaction_type
7933                   AND (
7934                         ((ft.s_fee_trigger_cat = gcst_institutn
7935                           AND (ast.course_cd IS NULL
7936                                OR (g_c_fee_calc_mthd = g_v_program AND ast.course_cd IS NOT NULL)
7937                               ))
7938                         OR
7939                         ( ft.s_fee_trigger_cat <> gcst_institutn AND
7940                          (
7941                           (ast.course_cd = p_course_cd AND g_c_fee_calc_mthd = g_v_program) OR
7942                           (ps.course_type = p_c_career AND g_c_fee_calc_mthd = g_v_career)
7943                          )
7944                         ))
7945                         OR
7946                         (g_c_fee_calc_mthd = g_v_primary_career)
7947                       ) AND (ast.fee_type,NVL(ast.fee_cat,cp_fee_cat)) NOT IN (SELECT fee_type,fee_cat FROM igs_fi_f_cat_fee_lbl_all
7948                                                                                WHERE fee_cat = cp_fee_cat
7949                                                                                AND fee_cal_type = ast.fee_cal_type
7950                                                                                AND fee_ci_sequence_number = ast.fee_ci_sequence_number
7951                                                                                AND fee_type = ast.fee_type);
7952 
7953                 -- Actual Mode of processing, when the fee calculation method is 'Program','Career'.
7954                 -- Get all the program attempts from the student terms table, other than the program/career that is in context
7955                 CURSOR c_std_term_spas( cp_v_lookup_type igs_lookups_view.lookup_type%TYPE,
7956                                         cp_v_fee_ass_ind igs_lookups_view.fee_ass_ind%TYPE ) IS
7957                   SELECT spt.program_cd,
7958                          spt.program_version,
7959                          spt.fee_cat,
7960                          spa.adm_admission_appl_number,
7961                          spa.adm_nominated_course_cd,
7962                          spa.adm_sequence_number,
7963                          spa.commencement_dt,
7964                          spa.discontinued_dt,
7965                          spa.cal_type,
7966                          spt.location_cd,
7967                          spt.attendance_mode,
7968                          spt.attendance_type
7969                   FROM igs_en_spa_terms spt,
7970                        igs_en_stdnt_ps_att_all spa,
7971                        igs_ps_ver_all ps,
7972                        igs_lookups_view lkps
7973                   WHERE spt.person_id = spa.person_id
7974                   AND spt.program_cd = spa.course_cd
7975                   AND spt.program_version = spa.version_number
7976                   AND spt.person_id = p_person_id
7977                   AND spt.term_cal_type = g_v_load_cal_type
7978                   AND spt.term_sequence_number = g_n_load_seq_num
7979                   AND spt.program_cd = ps.course_cd
7980                   AND spt.program_version = ps.version_number
7981                   AND spa.course_attempt_status = lkps.lookup_code
7982                   AND lkps.lookup_type = cp_v_lookup_type
7983                   AND lkps.fee_ass_ind = cp_v_fee_ass_ind
7984                   AND (
7985                        (spt.program_cd <> p_course_cd AND g_c_fee_calc_mthd = g_v_program) OR
7986                        (ps.course_type <> p_c_career AND g_c_fee_calc_mthd = g_v_career)
7987                       );
7988 
7989               CURSOR cur_fcfl (cp_v_fee_cat igs_fi_f_cat_fee_lbl_all.fee_cat%TYPE,
7990                                 cp_v_fee_cal_type igs_fi_f_cat_fee_lbl_all.fee_cal_type%TYPE,
7991                                  cp_n_fee_ci_seq_num igs_fi_f_cat_fee_lbl_all.fee_ci_sequence_number%TYPE,
7992                                    cp_v_fee_type igs_fi_f_cat_fee_lbl_all.fee_type%TYPE) IS
7993                SELECT fee_cat, fee_type
7994                FROM igs_fi_f_cat_fee_lbl_all
7995                WHERE fee_cal_type = cp_v_fee_cal_type
7996                AND fee_ci_sequence_number = cp_n_fee_ci_seq_num
7997                AND fee_type = cp_v_fee_type;
7998 
7999               l_v_liable VARCHAR2(10) := 'FALSE';
8000 
8001           FUNCTION finpl_init_fee_ass_item (
8002                  p_person_id                             IGS_FI_FEE_AS_ITEMS.person_id%TYPE,
8003                  p_fee_type                              IGS_FI_FEE_AS_ITEMS.fee_type%TYPE,
8004                  P_fee_cat                               IGS_FI_FEE_AS_ITEMS.fee_cat%TYPE,
8005                  p_fee_cal_type                          IGS_FI_FEE_AS_ITEMS.fee_cal_type%TYPE,
8006                  p_fee_ci_sequence_number                IGS_FI_FEE_AS_ITEMS.fee_ci_sequence_number%TYPE,
8007                  p_course_cd                             IGS_FI_FEE_AS_ITEMS.course_cd%TYPE,
8008                  p_effective_date                        DATE,
8009                  p_trace_on                              VARCHAR2,
8010                  p_c_career                              igs_ps_ver_all.course_type%TYPE)
8011           RETURN BOOLEAN
8012           AS
8013           /*************************************************************
8014             Created By :syam shankar
8015             Date Created By :18-sep-2000
8016             Purpose :
8017             Know limitations, enhancements or remarks
8018             Change History
8019             Who             When            What
8020             pathipat        06-Sep-2005     Bug 4540295 - Fee assessment produce double fees after program version change
8021             bannamal        08-Jul-2005     Enh#3392088 Campus Privilege Fee. Modified
8022                                             the cursor cur_chg_method.
8023             pathipat        12-Sep-2003     Enh 3108052 - Unit Sets in Rate Table build
8024                                             Added unit_set_cd and us_version_number to plsql table
8025             (reverse chronological order - newest change first)
8026           ***************************************************************/
8027             v_message_name                  VARCHAR2(30);
8028             ln_fee_ass_item_id              igs_fi_fee_as_items.fee_ass_item_id%TYPE;
8029             lv_fee_trg_cat                  igs_fi_fee_type_all.s_fee_trigger_cat%TYPE;
8030             lv_chg_method                   IGS_FI_FEE_AS_ITEMS.S_Chg_Method_Type%TYPE;
8031 
8032 
8033             CURSOR c_fee_type( cp_fee_type      IGS_FI_FEE_AS_ITEMS.FEE_TYPE%TYPE ) IS
8034                     SELECT description,
8035                            s_fee_trigger_cat
8036                     FROM igs_fi_fee_type_all
8037                     WHERE fee_type = cp_fee_type;
8038             v_fee_type_description igs_fi_fee_type_all.description%type;
8039             l_n_scope_rul_seq_num  igs_fi_f_typ_ca_inst_all.scope_rul_sequence_num%TYPE;
8040 
8041             CURSOR cur_chg_method1(cp_fee_type                igs_fi_fee_as_all.fee_type%TYPE,
8042                                    cp_fee_cal_type            igs_fi_fee_as_all.fee_cal_type%TYPE,
8043                                    cp_fee_ci_Sequence_number  igs_fi_fee_as_all.fee_ci_sequence_number%TYPE) IS
8044                    SELECT s_chg_method_type,
8045                           scope_rul_sequence_num
8046                    FROM   igs_fi_f_typ_ca_inst_all
8047                    WHERE  fee_type               = cp_fee_type
8048                    AND    fee_cal_type           = cp_fee_cal_type
8049                    AND    fee_ci_sequence_number = cp_fee_ci_sequence_number;
8050 
8051             -- Enh# 3167098, Removed the context of Fee Category when selecting as Fee Cat can be changed after assessment.
8052             CURSOR c_as_items  (cp_person_id            igs_fi_fee_as_items.person_id%TYPE,
8053                                 cp_fee_type             igs_fi_fee_as_items.fee_type%TYPE ,
8054                                 cp_fee_cal_type         igs_fi_fee_as_items.fee_cal_type%TYPE,
8055                                 cp_fee_ci_sequence_number  igs_fi_fee_as_items.fee_ci_sequence_number%TYPE,
8056                                 cp_course_cd            igs_fi_fee_as_items.course_cd%TYPE,
8057                                 cp_career               igs_ps_ver_all.course_type%TYPE,
8058                                 cp_s_trigger_cat        igs_fi_fee_type_all.s_fee_trigger_cat%TYPE,
8059                                 cp_v_s_transaction_type1 igs_fi_fee_as_all.s_transaction_type%TYPE,
8060                                 cp_v_s_transaction_type2 igs_fi_fee_as_all.s_transaction_type%TYPE
8061                                 ) IS
8062               SELECT   a.course_cd,
8063                        a.crs_version_number,
8064                        a.location_cd,
8065                        SUM(a.chg_elements) sum_elements,
8066                        SUM(a.amount) sum_amount,
8067                        SUM(a.credit_points) sum_credit_points,
8068                        SUM(a.eftsu) sum_eftsu,
8069                        a.org_unit_cd,
8070                        a.uoo_id,
8071                        a.fee_cat
8072               FROM    igs_fi_fee_as_items a,
8073                       igs_ps_ver_all ps
8074               WHERE   a.course_cd = ps.course_cd (+)
8075               AND     a.crs_version_number = ps.version_number (+)
8076               AND     a.person_id = cp_person_id
8077               AND     a.fee_type  = cp_fee_type
8078               AND     a.fee_cal_type = cp_fee_cal_type
8079               AND     a.fee_ci_sequence_number  = cp_fee_ci_sequence_number
8080               AND     ((p_fee_cat IS NOT NULL AND a.fee_cat = p_fee_cat ) OR (a.fee_cat IS NULL OR p_fee_cat IS NULL))
8081               AND     ((cp_s_trigger_cat =  gcst_institutn AND
8082                                   (a.course_cd is NULL
8083                                     OR (g_c_fee_calc_mthd = g_v_program AND a.course_cd IS NOT NULL)
8084                                   ))
8085                        OR (
8086                            (g_c_fee_calc_mthd = g_v_program AND a.course_cd = cp_course_cd)
8087                            OR
8088                            (g_c_fee_calc_mthd = g_v_career AND ps.course_type = cp_career)
8089                            OR
8090                            (g_c_fee_calc_mthd = g_v_primary_career)
8091                           )
8092                       )
8093               AND     a.logical_delete_date IS NULL
8094               AND     TRUNC(a.fee_effective_dt) <= TRUNC(p_effective_date)
8095               AND     NOT EXISTS ( SELECT 'x'
8096                                    FROM   igs_fi_fee_as_all b
8097                                    WHERE  b.person_id  = cp_person_id
8098                                    AND    b.transaction_id = a.transaction_id
8099                                    AND    b.fee_type = cp_fee_type
8100                                    AND    b.fee_cal_type = cp_fee_cal_type
8101                                    AND    b.fee_ci_sequence_number = cp_fee_ci_sequence_number
8102                                    AND    ((p_fee_cat IS NOT NULL AND b.fee_cat = p_fee_cat ) OR (b.fee_cat IS NULL OR p_fee_cat IS NULL))
8103                                    AND    ((cp_s_trigger_cat =  gcst_institutn AND
8104                                                      (a.course_cd is NULL
8105                                                        OR (g_c_fee_calc_mthd = g_v_program AND a.course_cd IS NOT NULL)
8106                                                      ))
8107                                            OR (
8108                                                (g_c_fee_calc_mthd = g_v_program AND a.course_cd = cp_course_cd)
8109                                                 OR
8110                                                (g_c_fee_calc_mthd = g_v_career AND ps.course_type = cp_career)
8111                                                 OR
8112                                                (g_c_fee_calc_mthd = g_v_primary_career)
8113                                               )
8114                                           )
8115                                    AND    b.s_transaction_type in (cp_v_s_transaction_type1, cp_v_s_transaction_type2)
8116                                   )
8117               GROUP BY a.course_cd,
8118                        a.crs_version_number,
8119                        a.fee_cat,
8120                        a.uoo_id,
8121                        a.location_cd,
8122                        a.org_unit_cd;
8123 
8124             -- Cursor to select all charges created if is is 'Institution' Fee and the charge method identified is 'Flat Rate'
8125             CURSOR c_as_inst_items  (cp_person_id              igs_fi_fee_as_items.person_id%TYPE,
8126                                      cp_fee_type               igs_fi_fee_as_items.fee_type%TYPE,
8127                                      cp_fee_cal_type           igs_fi_fee_as_items.fee_cal_type%TYPE,
8128                                      cp_fee_ci_sequence_number igs_fi_fee_as_items.fee_ci_sequence_number%TYPE,
8129                                      cp_course_cd              igs_fi_fee_as_items.course_cd%TYPE,
8130                                      cp_v_s_transaction_type1  igs_fi_fee_as_all.s_transaction_type%TYPE,
8131                                      cp_v_s_transaction_type2  igs_fi_fee_as_all.s_transaction_type%TYPE
8132                                      ) IS
8133 
8134               SELECT   a.course_cd,
8135                        a.crs_version_number,
8136                        a.location_cd,
8137                        SUM(a.chg_elements) sum_elements,
8138                        SUM(a.amount) sum_amount,
8139                        SUM(a.credit_points) sum_credit_points,
8140                        SUM(a.eftsu) sum_eftsu,
8141                        a.org_unit_cd,
8142                        a.uoo_id,
8143                        a.fee_cat
8144                FROM    igs_fi_fee_as_items a
8145                WHERE   a.person_id = cp_person_id AND
8146                        a.fee_type  = cp_fee_type AND
8147                        a.fee_cal_type = cp_fee_cal_type AND
8148                        a.fee_ci_sequence_number  = cp_fee_ci_sequence_number AND
8149                        ((p_fee_cat IS NOT NULL AND a.fee_cat = p_fee_cat ) OR (a.fee_cat IS NULL OR p_fee_cat IS NULL)) AND
8150                        a.logical_delete_date IS NULL AND
8151                        TRUNC(a.fee_effective_dt) <= TRUNC(p_effective_date) AND
8152                        NOT EXISTS ( SELECT 'X'
8153                                     FROM   igs_fi_fee_as_all b
8154                                     WHERE  b.person_id  = cp_person_id
8155                                     AND    b.transaction_id = a.transaction_id
8156                                     AND    b.fee_type   = cp_fee_type
8157                                     AND    b.fee_cal_type = cp_fee_cal_type
8158                                     AND    b.fee_ci_sequence_number = cp_fee_ci_sequence_number
8159                                     AND    ((p_fee_cat IS NOT NULL AND b.fee_cat = p_fee_cat ) OR (b.fee_cat IS NULL OR p_fee_cat IS NULL))
8160                                     AND    b.s_transaction_type in (cp_v_s_transaction_type1, cp_v_s_transaction_type2)
8161                                   )
8162                GROUP BY a.course_cd,
8163                         a.crs_version_number,
8164                         a.fee_cat,
8165                         a.uoo_id,
8166                         a.location_cd,
8167                         a.org_unit_cd;
8168 
8169             CURSOR cur_chg_method(cp_person_id               igs_fi_fee_as_all.person_id%TYPE,
8170                                   cp_fee_type                igs_fi_fee_as_all.fee_type%TYPE,
8171                                   cp_course_cd               igs_fi_fee_as_all.course_cd%TYPE,
8172                                   cp_fee_cal_type            igs_fi_fee_as_all.fee_cal_type%TYPE,
8173                                   cp_fee_ci_Sequence_number  igs_fi_fee_as_all.fee_ci_sequence_number%TYPE,
8174                                   cp_career                  igs_ps_ver_all.course_type%TYPE) IS
8175 
8176               SELECT a.fee_ass_item_id upd,
8177                      a.s_chg_method_type
8178               FROM   igs_fi_fee_as_items a,
8179                      igs_ps_ver_all ps
8180               WHERE  a.course_cd = ps.course_cd (+)
8181               AND    a.crs_version_number = ps.version_number (+)
8182               AND    a.person_id   = cp_person_id
8183               AND    a.fee_type    = cp_fee_type
8184               AND    (a.course_cd  IS NULL
8185                       OR
8186                       (
8187                        (g_c_fee_calc_mthd = g_v_program AND a.course_cd = cp_course_cd)
8188                         OR
8189                         /* Select based on Career but not on the course code passed as Primary Program can be changed after the assessment. */
8190                        (g_c_fee_calc_mthd = g_v_career AND ps.course_type = cp_career)
8191                         OR
8192                        (g_c_fee_calc_mthd = g_v_primary_career)
8193                       )
8194                      )
8195               AND    a.fee_cal_type = cp_fee_cal_type
8196               AND    a.fee_ci_sequence_number = cp_fee_ci_sequence_number
8197               AND    a.chg_elements <> 0
8198               ORDER BY upd DESC;
8199 
8200           BEGIN
8201             log_to_fnd( p_v_module => 'finpl_init_fee_ass_item',
8202                         p_v_string => 'Entered  . Parameters are: '
8203                                       || 'Person Id: '      || p_person_id
8204                                       || ', Fee Type: '     || p_fee_type
8205                                       || ', Fee Cat : '     || P_fee_cat
8206                                       || ', Fee Cal Type: ' || p_fee_cal_type
8207                                       || ', Fee Seq Num: '  || p_fee_ci_sequence_number
8208                                       || ', Cousre Cd: '    || p_course_cd
8209                                       || ', Effective Dt: ' || TO_CHAR(p_effective_dt, 'DD-MON-YYYY HH24:MI:SS')
8210                                       || ', Trace On: '     || p_trace_on
8211                                       || ', Career: '       || p_c_career );
8212             t_fee_as_items := t_dummy_fee_as_items; /**initialise pl/sql structure**/
8213             gv_as_item_cntr := 0;
8214             g_b_fee_chgs_exists := FALSE;
8215 
8216             OPEN  c_fee_type(p_fee_type);
8217             FETCH c_fee_type INTO v_fee_type_description,
8218                                   lv_fee_trg_cat;
8219             CLOSE c_fee_type;
8220 
8221             OPEN cur_chg_method1(p_fee_type,
8222                                  p_fee_cal_type,
8223                                  p_fee_ci_sequence_number);
8224             FETCH cur_chg_method1 INTO lv_chg_method, l_n_scope_rul_seq_num;
8225             CLOSE cur_chg_method1;
8226 
8227             IF lv_fee_trg_cat = gcst_institutn AND lv_chg_method = gcst_flatrate THEN
8228 
8229               log_to_fnd( p_v_module => 'finpl_init_fee_ass_item',
8230                           p_v_string => 'Institution Fee with Flat Rate. Following Path 1 with cursor c_as_inst_items.');
8231               FOR r_inst_items IN c_as_inst_items ( p_person_id,
8232                                                     p_fee_type,
8233                                                     p_fee_cal_type,
8234                                                     p_fee_ci_sequence_number,
8235                                                     p_course_cd,
8236                                                     'RETENTION','EXTERNAL')
8237               LOOP
8238                 gv_as_item_cntr :=  NVL(gv_as_item_cntr, 0) + 1;
8239                 t_fee_as_items(gv_as_item_cntr).person_id               := p_person_id;
8240                 t_fee_as_items(gv_as_item_cntr).status                  := 'E';
8241                 t_fee_as_items(gv_as_item_cntr).fee_type                := p_fee_type;
8242                 t_fee_as_items(gv_as_item_cntr).fee_cat                 := r_inst_items.fee_cat;
8243                 t_fee_as_items(gv_as_item_cntr).fee_cal_type            := p_fee_cal_type;
8244                 t_fee_as_items(gv_as_item_cntr).description             := v_fee_type_description;
8245                 t_fee_as_items(gv_as_item_cntr).fee_ci_sequence_number  := p_fee_ci_sequence_number;
8246                 t_fee_as_items(gv_as_item_cntr).course_cd               := r_inst_items.course_cd;
8247                 t_fee_as_items(gv_as_item_cntr).crs_version_number      := r_inst_items.crs_version_number;
8248                 t_fee_as_items(gv_as_item_cntr).old_chg_elements        := r_inst_items.sum_elements;
8249                 t_fee_as_items(gv_as_item_cntr).old_amount              := r_inst_items.sum_amount;
8250                 t_fee_as_items(gv_as_item_cntr).location_cd             := r_inst_items.location_cd;
8251                 t_fee_as_items(gv_as_item_cntr).old_eftsu               := r_inst_items.sum_eftsu;
8252                 t_fee_as_items(gv_as_item_cntr).old_credit_points       := r_inst_items.sum_credit_points;
8253                 t_fee_as_items(gv_as_item_cntr).org_unit_cd             := r_inst_items.org_unit_cd;
8254                 t_fee_as_items(gv_as_item_cntr).chg_elements            := 0;
8255                 t_fee_as_items(gv_as_item_cntr).uoo_id                  := r_inst_items.uoo_id ;
8256                 t_fee_as_items(gv_as_item_cntr).unit_set_cd             := NULL;
8257                 t_fee_as_items(gv_as_item_cntr).us_version_number       := NULL;
8258                 t_fee_as_items(gv_as_item_cntr).unit_type_id            := NULL;
8259                 t_fee_as_items(gv_as_item_cntr).unit_class              := NULL;
8260                 t_fee_as_items(gv_as_item_cntr).unit_mode               := NULL;
8261                 t_fee_as_items(gv_as_item_cntr).unit_cd                 := NULL;
8262                 t_fee_as_items(gv_as_item_cntr).unit_level              := NULL;
8263                 t_fee_as_items(gv_as_item_cntr).unit_version_number     := NULL;
8264 
8265                 OPEN cur_chg_method(p_person_id,
8266                                     p_fee_type,
8267                                     p_course_cd,
8268                                     p_fee_cal_type,
8269                                     p_fee_ci_sequence_number,
8270                                     p_c_career);
8271                 FETCH cur_chg_method INTO ln_fee_ass_item_id,
8272                                           t_fee_as_items(gv_as_item_cntr).chg_method_type;
8273                 CLOSE cur_chg_method;
8274 
8275                 t_fee_as_items(gv_as_item_cntr).fee_ass_item_id         := ln_fee_ass_item_id;
8276 
8277                 g_b_fee_chgs_exists := TRUE;
8278               END LOOP;
8279 
8280             ELSE
8281               log_to_fnd( p_v_module => 'finpl_init_fee_ass_item',
8282                           p_v_string => 'NOT(Institution Fee with Flat Rate). Following Path 2 with cursor c_as_items.');
8283               FOR r_items IN c_as_items(p_person_id,
8284                                         p_fee_type,
8285                                         p_fee_cal_type,
8286                                         p_fee_ci_sequence_number,
8287                                         p_course_cd,
8288                                         p_c_career,
8289                                         lv_fee_trg_cat,
8290                                         'RETENTION','EXTERNAL')
8291               LOOP
8292                 gv_as_item_cntr :=  nvl(gv_as_item_cntr,0) + 1;
8293                 t_fee_as_items(gv_as_item_cntr).person_id               := p_person_id;
8294                 t_fee_as_items(gv_as_item_cntr).status                  := 'E';
8295                 t_fee_as_items(gv_as_item_cntr).fee_type                := p_fee_type;
8296                 t_fee_as_items(gv_as_item_cntr).fee_cat                 := r_items.fee_cat;
8297                 t_fee_as_items(gv_as_item_cntr).fee_cal_type            := p_fee_cal_type;
8298                 t_fee_as_items(gv_as_item_cntr).description             := v_fee_type_description;
8299                 t_fee_as_items(gv_as_item_cntr).fee_ci_sequence_number  := p_fee_ci_sequence_number;
8300                 t_fee_as_items(gv_as_item_cntr).course_cd               := r_items.course_cd;
8301                 t_fee_as_items(gv_as_item_cntr).crs_version_number      := r_items.crs_version_number;
8302                 t_fee_as_items(gv_as_item_cntr).old_chg_elements        := r_items.sum_elements;
8303                 t_fee_as_items(gv_as_item_cntr).old_amount              := r_items.sum_amount;
8304                 t_fee_as_items(gv_as_item_cntr).location_cd             := r_items.location_cd;
8305                 t_fee_as_items(gv_as_item_cntr).old_eftsu               := r_items.sum_eftsu;
8306                 t_fee_as_items(gv_as_item_cntr).old_credit_points       := r_items.sum_credit_points;
8307                 t_fee_as_items(gv_as_item_cntr).org_unit_cd             := r_items.org_unit_cd;
8308                 t_fee_as_items(gv_as_item_cntr).chg_elements            := 0;
8309                 t_fee_as_items(gv_as_item_cntr).uoo_id                  := r_items.uoo_id ;
8310                 t_fee_as_items(gv_as_item_cntr).unit_set_cd             := NULL;
8311                 t_fee_as_items(gv_as_item_cntr).us_version_number       := NULL;
8312                 t_fee_as_items(gv_as_item_cntr).unit_type_id            := NULL;
8313                 t_fee_as_items(gv_as_item_cntr).unit_class              := NULL;
8314                 t_fee_as_items(gv_as_item_cntr).unit_mode               := NULL;
8315                 t_fee_as_items(gv_as_item_cntr).unit_cd                 := NULL;
8316                 t_fee_as_items(gv_as_item_cntr).unit_level              := NULL;
8317                 t_fee_as_items(gv_as_item_cntr).unit_version_number     := NULL;
8318 
8319                 OPEN cur_chg_method(p_person_id,
8320                                     p_fee_type,
8321                                     p_course_cd,
8322                                     p_fee_cal_type,
8323                                     p_fee_ci_sequence_number,
8324                                     p_c_career);
8325                 FETCH cur_chg_method INTO ln_fee_ass_item_id,
8326                                           t_fee_as_items(gv_as_item_cntr).chg_method_type;
8327                 CLOSE cur_chg_method;
8328 
8329                 t_fee_as_items(gv_as_item_cntr).fee_ass_item_id         := ln_fee_ass_item_id;
8330 
8331                 g_b_fee_chgs_exists := TRUE;
8332               END LOOP;
8333             END IF;
8334 
8335             log_to_fnd( p_v_module => 'finpl_init_fee_ass_item',
8336                         p_v_string => 'Returning from finpl_init_fee_ass_item. Added ' ||t_fee_as_items.COUNT || ' record(s) to PL/SQL Table.');
8337             RETURN TRUE;
8338 
8339           EXCEPTION
8340             WHEN OTHERS THEN
8341               log_to_fnd( p_v_module => 'finpl_init_fee_ass_item',
8342                           p_v_string => 'From Exception Handler of When Others.');
8343               v_message_name := 'IGS_GE_UNHANDLED_EXP';
8344               IF (p_trace_on = 'Y') THEN
8345                 fnd_message.set_name('IGS', v_message_name);
8346                 Fnd_Message.Set_Token('NAME','IGS_FI_PRC_FEE_ASS.FINPL_INIT_FEE_ASS_ITEM');
8347                 fnd_file.put_line (fnd_file.log, fnd_message.get);
8348               END IF;
8349             RETURN FALSE;
8350           END finpl_init_fee_ass_item;
8351 
8352        BEGIN
8353                -- Beginning of Main for finpl_prc_fee_cat_fee_liab
8354                log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8355                            p_v_string => 'Entered finpl_prc_fee_cat_fee_liab. Parameters are: '
8356                                          || 'Effective Date: '    || TO_CHAR(p_effective_dt, 'DD-MON-YYYY HH24:MI:SS')
8357                                          || ', Trace On: '        || p_trace_on
8358                                          || ', Fee Cal Type: '    || p_fee_cal_type
8359                                          || ', Fee Cal Seq Num: ' || p_fee_ci_sequence_num
8360                                          || ', Local Currency: '  || p_local_currency
8361                                          || ', Fee Cat: '         || p_fee_cat
8362                                          || ', Person Id: '       || p_person_id
8363                                          || ', Course Cd: '       || p_course_cd
8364                                          || ', Course Version: '  || p_course_version_number
8365                                          || ', Location Cd: '     || p_scahv_location_cd
8366                                          || ', Att Mode: '        || p_scahv_attendance_mode
8367                                          || ', Att Type: '        || p_scahv_attendance_type
8368                                          || ', Disc Date: '       || p_discontinued_dt
8369                                          || ', Crs Attempt Status: ' || p_course_attempt_status
8370                                          || ', Process Mode: '    || p_process_mode
8371                                          || ', Career: '          || p_c_career );
8372                 p_message_name := NULL;
8373                 log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8374                             p_v_string => 'Calling finpl_lock_records' );
8375 
8376                l_n_rec_count := 0;
8377 
8378               -- Before processing, obtain a lock in table IGS_FI_SPA_FEE_PRDS for the given Person-Course-Fee Period.
8379               IF  NOT finpl_lock_records(p_n_person_id               => p_person_id,
8380                                          p_v_course_cd               => p_course_cd,
8381                                          p_v_fee_cal_type            => p_fee_cal_type,
8382                                          p_n_fee_ci_sequence_number  => p_fee_ci_sequence_num) THEN
8383                       -- If lock could not be obtained, error out.
8384                       log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8385                                   p_v_string => 'finpl_lock_records returned FALSE, locking not successful' );
8386                       RAISE e_lock_exception;
8387               END IF;
8388 
8389                 -- Loop Across Active FCCIs as on Process Effective Date.
8390                 log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8391                             p_v_string => 'Looping across FCCIs...');
8392                 v_fcci_found := FALSE;
8393                 FOR v_fcci_fss_rec IN c_fcci_fss(p_effective_dt) LOOP
8394                   v_fcci_found := TRUE;
8395 
8396                   log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8397                               p_v_string => 'FCCI: ' || v_fcci_fss_rec.fee_cal_type || ' '
8398                                             || TO_CHAR(v_fcci_fss_rec.start_dt, 'DD/MM/YYYY') || ' '
8399                                             || TO_CHAR(v_fcci_fss_rec.end_dt, 'DD/MM/YYYY'));
8400                   IF (p_trace_on = 'Y') THEN
8401                     -- Trace Entry
8402                     fnd_file.new_line(fnd_file.log);
8403                     fnd_message.set_name('IGS', 'IGS_FI_FEE_CAL');
8404                     fnd_message.set_token('CAL_TYPE', v_fcci_fss_rec.fee_cal_type);
8405                     fnd_file.put_line (fnd_file.log, fnd_message.get);
8406                     fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'START_DT') || ': ' || TO_CHAR(v_fcci_fss_rec.start_dt, 'DD/MM/YYYY'));
8407                     fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'END_DT') || ': ' || TO_CHAR(v_fcci_fss_rec.end_dt, 'DD/MM/YYYY'));
8408                   END IF;
8409 
8410                   log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8411                               p_v_string => 'Loop Accross FCFLs..' );
8412 
8413                   -- Process liabilities belonging to the fee category, operating in the assessment period
8414                   v_fcfl_found := FALSE;
8415                   g_v_fcfl_source := NULL;
8416                   FOR v_fcflv_rec IN c_fcflv( v_fcci_fss_rec.FEE_CAT,
8417                                               v_fcci_fss_rec.fee_cal_type,
8418                                               v_fcci_fss_rec.fee_ci_sequence_number,
8419                                               'ASSESSMENT')
8420                   LOOP
8421 
8422                     log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8423                                 p_v_string => '--------------------------' );
8424                     log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8425                                 p_v_string => 'FCFL: Source: ' || v_fcflv_rec.source || ': '
8426                                               || v_fcflv_rec.fee_cat || ', ' || v_fcflv_rec.fee_type || ', '|| v_fcflv_rec.fee_cal_type || ', '
8427                                               || v_fcflv_rec.fee_ci_sequence_number || ', '|| v_fcflv_rec.fee_liability_status || ', '
8428                                               || v_fcflv_rec.s_chg_method_type || ', '|| v_fcflv_rec.rul_sequence_number || ', '
8429                                               || v_fcflv_rec.currency_cd || ', '|| v_fcflv_rec.s_fee_structure_status || ', '
8430                                               || v_fcflv_rec.s_fee_trigger_cat || ', '|| v_fcflv_rec.s_fee_type || ', '|| v_fcflv_rec.start_dt_alias || ', '
8431                                               || v_fcflv_rec.start_dai_sequence_number || ', '|| v_fcflv_rec.end_dt_alias || ', '
8432                                               || v_fcflv_rec.end_dai_sequence_number);
8433 
8434                     g_inst_liable_progs_tbl := inst_liable_prog_dummy_tbl;
8435                     g_n_inst_progs_cntr := 0;
8436                     v_next_fcfl_flag := FALSE;
8437                     tbl_fai_unit_dtls.DELETE;
8438                     g_v_fcfl_source := RTRIM(v_fcflv_rec.source);
8439 
8440                     -- Check if Institution Fees can be assessed in Predictive Mode.
8441                     -- Flag g_b_prc_inst_fee is set in finpl_prc_predictive_scas
8442                     IF g_c_predictive_ind = 'Y' AND
8443                        v_fcflv_rec.s_fee_trigger_cat = gcst_institutn AND
8444                        g_b_prc_inst_fee = FALSE THEN
8445 
8446                       log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8447                                   p_v_string => 'Predictive: Institution Fees can not be assessed. Proceeding with next FCFL.' );
8448                       v_next_fcfl_flag := TRUE;
8449                     END IF;
8450 
8451                     -- If validation of Institution fees fails, and those are the only FCFLs found
8452                     -- then message, IGS_FI_NOACTIVE_FEECAT_FEE_LI needs to be logged at the end.
8453                     IF v_next_fcfl_flag = FALSE THEN
8454                       v_fcfl_found := TRUE;
8455                     END IF;
8456 
8457                     -- added by schodava for Bug # 2021281
8458                     -- in case the fee trigger is institution then check
8459                     -- whether this particular fee cal instance has already been assessed for.
8460                     -- compare the FCFL status of the record in the pl/sql table with the v_fcflv_rec fcfl status
8461                     -- If already assessed, then set the next flag to true,
8462                     -- i.e. stop the processing of the present fcfl record.
8463 
8464                     IF v_next_fcfl_flag = FALSE AND
8465                        (v_fcflv_rec.s_fee_trigger_cat = gcst_institutn) THEN
8466                       FOR l_cntr IN 1..g_inst_fee_rec_cntr LOOP
8467                         IF p_person_id                            = l_inst_fee_rec(l_cntr).person_id              AND
8468                            v_fcflv_rec.fee_type                   = l_inst_fee_rec(l_cntr).fee_type               AND
8469                            v_fcflv_rec.fee_cal_type               = l_inst_fee_rec(l_cntr).fee_cal_type           AND
8470                            v_fcflv_rec.fee_ci_sequence_number     = l_inst_fee_rec(l_cntr).fee_ci_sequence_number AND
8471                            ( (v_fcflv_rec.fee_liability_status    <> l_inst_fee_rec(l_cntr).fcfl_status AND l_inst_fee_rec(l_cntr).fcfl_status = 'ACTIVE')
8472                              OR ( v_fcflv_rec.fee_liability_status = l_inst_fee_rec(l_cntr).fcfl_status ))        THEN
8473 
8474                           log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8475                                       p_v_string => 'Institution Fee is already assessed for someother FCFL that has same FTCI. Proceed with next FCFL.' );
8476                           v_next_fcfl_flag := TRUE;
8477                         END IF;
8478                       END LOOP;
8479                     END IF;
8480 
8481                     -- If the FCFL source is OLD i.e., Fee As Table, and if its Institution Fee,
8482                     --   Then in case of ACTUAL mode, check if the FCFL is liable in any program that is other than program in context
8483                     --   If any other program is liable, then we don't reverse the Institution charge that is already present in DB.
8484                     --   i.e, proceed to next FCFL.
8485                     -- In case of PREDICTIVE mode, Institution Fees is assessed only for Key Program.
8486 
8487                     log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8488                                 p_v_string => 'Checking for other liable programs for Institution Fee in context.' );
8489 
8490                     IF (v_fcflv_rec.source = 'OLD') THEN
8491                       IF (g_c_predictive_ind = 'N') THEN
8492                         IF (v_fcflv_rec.s_fee_trigger_cat = gcst_institutn AND g_c_fee_calc_mthd <> g_v_primary_career) THEN
8493                           -- Check if any other program/career is liable for this Institution Fee
8494                           log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8495                                       p_v_string => 'Checking for other liable programs for Institution Fee in context.' );
8496                           FOR l_std_term_spas IN c_std_term_spas('CRS_ATTEMPT_STATUS','Y') LOOP
8497                             -- check if the program is liable for any other program/ career
8498                             log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8499                                         p_v_string => 'Calling check_stdnt_prg_att_liable for '|| l_std_term_spas.program_cd
8500                                                       || ', ' || l_std_term_spas.program_version || ', ' ||l_std_term_spas.fee_cat );
8501                             l_v_liable := igs_fi_gen_001.check_stdnt_prg_att_liable(
8502                                                            p_person_id,
8503                                                            l_std_term_spas.program_cd,
8504                                                            l_std_term_spas.program_version,
8505                                                            l_std_term_spas.fee_cat,
8506                                                            v_fcflv_rec.fee_type,
8507                                                            v_fcflv_rec.s_fee_trigger_cat,
8508                                                            v_fcflv_rec.fee_cal_type,
8509                                                            v_fcflv_rec.fee_ci_sequence_number,
8510                                                            l_std_term_spas.adm_admission_appl_number,
8511                                                            l_std_term_spas.adm_nominated_course_cd,
8512                                                            l_std_term_spas.adm_sequence_number,
8513                                                            l_std_term_spas.commencement_dt,
8514                                                            l_std_term_spas.discontinued_dt,
8515                                                            l_std_term_spas.cal_type,
8516                                                            l_std_term_spas.location_cd,
8517                                                            l_std_term_spas.attendance_mode,
8518                                                            l_std_term_spas.attendance_type);
8519                             IF l_v_liable = 'TRUE' THEN
8520                               -- If found liable for any other program/career then we should not be reversing the existing institution charges
8521                               log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8522                                           p_v_string => 'Program ' || l_std_term_spas.program_cd || ' is liable. So proceed to next FCFL');
8523                               v_next_fcfl_flag := TRUE;
8524                               EXIT;
8525                             END IF;
8526                           END LOOP;
8527                         END IF;
8528                       END IF;
8529                     END IF;
8530 
8531                     IF v_next_fcfl_flag = FALSE THEN
8532                       BEGIN
8533                         log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8534                                     p_v_string => 'Calling finpl_init_fee_ass_item.' );
8535                         IF finpl_init_fee_ass_item (
8536                                p_person_id,
8537                                v_fcflv_rec.fee_type,
8538                                v_fcflv_rec.fee_cat,
8539                                v_fcflv_rec.fee_cal_type,
8540                                v_fcflv_rec.fee_ci_sequence_number,
8541                                p_course_cd,
8542                                p_effective_dt,
8543                                p_trace_on,
8544                                p_c_career) = FALSE THEN
8545                           log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8546                                       p_v_string => 'finpl_init_fee_ass_item returned FALSE. Returning from finpl_prc_fee_cat_fee_liab.' );
8547                           RETURN FALSE;
8548                          END IF;
8549                       END;
8550                       -- Reset variables
8551                       v_charge_elements := 0;
8552                       v_fee_assessment := 0;
8553 
8554                       -- Log FCFL information.
8555                       IF (p_trace_on = 'Y' AND v_fcflv_rec.source <> 'OLD') THEN
8556 
8557                         IF (v_fcflv_rec.start_dt_alias IS NOT NULL) THEN
8558                                 fnd_file.new_line(fnd_file.log);
8559                                 OPEN c_daiv (
8560                                                 v_fcflv_rec.start_dt_alias,
8561                                                 v_fcflv_rec.start_dai_sequence_number,
8562                                                 v_fcci_fss_rec.fee_cal_type,
8563                                                 v_fcci_fss_rec.fee_ci_sequence_number);
8564                                 FETCH c_daiv INTO v_fcflv_start_dt;
8565                                 CLOSE c_daiv;
8566                                 fnd_message.set_name('IGS', 'IGS_FI_START_DATE_ALIAS');
8567                                 fnd_message.set_token('DT_ALIAS', v_fcflv_rec.start_dt_alias ||'    ');
8568                                 fnd_file.put (fnd_file.log, fnd_message.get);
8569                                 fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'START_DT') || ': ' || TO_CHAR(v_fcflv_start_dt, 'DD/MM/YYYY'));
8570                         END IF;
8571                         IF (v_fcflv_rec.end_dt_alias IS NOT NULL) THEN
8572                                 OPEN c_daiv (
8573                                                 v_fcflv_rec.end_dt_alias,
8574                                                 v_fcflv_rec.end_dai_sequence_number,
8575                                                 v_fcci_fss_rec.fee_cal_type,
8576                                                 v_fcci_fss_rec.fee_ci_sequence_number);
8577                                 FETCH c_daiv INTO v_fcflv_end_dt;
8578                                 CLOSE c_daiv;
8579                                 fnd_message.set_name('IGS', 'IGS_FI_END_DATE_ALIAS');
8580                                 fnd_message.set_token('DT_ALIAS', v_fcflv_rec.end_dt_alias ||'    ');
8581                                 fnd_file.put (fnd_file.log, fnd_message.get);
8582                                 fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'END_DT') || ': ' || TO_CHAR(v_fcflv_end_dt, 'DD/MM/YYYY'));
8583                         END IF;
8584 
8585                         fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'FEE_TYPE') || ': ' || v_fcflv_rec.fee_type);
8586                         fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'SYSTEM_FEE_TYPE') || ': ' || v_fcflv_rec.s_fee_type);
8587                         fnd_message.set_name('IGS', 'IGS_FI_FEE_TYPE_TRG_CAT');
8588                         fnd_message.set_token('S_FEE_TRIG', v_fcflv_rec.s_fee_trigger_cat);
8589                         fnd_file.put_line (fnd_file.log, fnd_message.get);
8590 
8591                         fnd_message.set_name('IGS', 'IGS_FI_CHG_METH_TYPE');
8592                         fnd_message.set_token('CHG_MTHD', igs_fi_gen_gl.get_lkp_meaning('CHG_METHOD', v_fcflv_rec.s_chg_method_type));
8593                         fnd_file.put_line (fnd_file.log, fnd_message.get);
8594                         fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'RULE_SEQ') || ': ' || TO_CHAR(v_fcflv_rec.rul_sequence_number));
8595                         IF (v_fcflv_rec.scope_rul_sequence_num IS NOT NULL) THEN
8596                           fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'SEL_CRI_RULE') || ': ' || TO_CHAR(v_fcflv_rec.scope_rul_sequence_num));
8597                         END IF;
8598                         IF (v_fcflv_rec.elm_rng_order_name IS NOT NULL) THEN
8599                           fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'ELM_RNG_ORDER') || ': ' || v_fcflv_rec.elm_rng_order_name);
8600                         END IF;
8601                         IF (v_fcflv_rec.max_chg_elements IS NOT NULL) THEN
8602                           fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'MAX_CHG_ELM') || ': ' || TO_CHAR(v_fcflv_rec.max_chg_elements));
8603                         END IF;
8604                       END IF;
8605                     END IF; /* v_next_fcfl_flag = FALSE */
8606 
8607                     -- Audit Fees Cannot be assessed in Predictive mode.
8608                     IF v_next_fcfl_flag = FALSE
8609                        AND g_c_predictive_ind = 'Y'
8610                        AND v_fcflv_rec.s_fee_type = g_v_audit THEN
8611                       IF (p_trace_on = 'Y' AND v_fcflv_rec.source <> 'OLD') THEN
8612                         fnd_message.set_name ( 'IGS', 'IGS_FI_PRED_MODE_NO_AUDIT_FEE');
8613                         fnd_file.put_line (fnd_file.log, fnd_message.get);
8614                       END IF;
8615                       log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8616                                   p_v_string => 'Predictive: Audit Fees can not be assessed. Proceeding with next FCFL.' );
8617                       v_next_fcfl_flag := TRUE;
8618                     END IF;
8619 
8620                     -- Charge method 'Per Unit' cannot be processed in Predictive mode.
8621 
8622                     IF (v_next_fcfl_flag = FALSE) THEN
8623                       IF (g_c_predictive_ind = 'Y') THEN
8624 
8625                         log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8626                                     p_v_string => 'Predictive: Checking validation of PER UNIT Chg Mthd.' );
8627 
8628                         IF (v_fcflv_rec.s_chg_method_type = gcst_perunit) THEN
8629                           -- a PER UNIT charge method cannot be carried out in predictive assessment
8630                           IF (p_trace_on = 'Y' AND v_fcflv_rec.source <> 'OLD') THEN
8631                             fnd_message.set_name ( 'IGS', 'IGS_FI_PREDASS_PERUNIT_CHGMTH');
8632                             fnd_file.put_line (fnd_file.log, fnd_message.get);
8633                           END IF;
8634                           log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8635                                       p_v_string => 'PER UNIT Chg Mthd can not be processed in Predictive. Proceed to next FCFL.' );
8636                           v_next_fcfl_flag := TRUE;
8637                         END IF;
8638                       END IF;
8639                     END IF;
8640 
8641                     IF (v_next_fcfl_flag = FALSE) THEN
8642                       IF (finpl_get_derived_am_at(p_person_id,
8643                                                   p_course_cd,
8644                                                   p_effective_dt,
8645                                                   v_fcflv_rec.fee_cal_type,
8646                                                   v_fcflv_rec.fee_ci_sequence_number,
8647                                                   v_fcflv_rec.FEE_TYPE,
8648                                                   v_fcflv_rec.s_fee_trigger_cat,
8649                                                   p_trace_on,
8650                                                   p_c_career,
8651                                                   l_v_attendance_type,
8652                                                   l_v_attendance_mode) = FALSE) THEN
8653                         RETURN FALSE;
8654                       END IF;
8655                       log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8656                                   p_v_string => 'Checking FCFL status...' );
8657                       -- Check the fee liability status
8658                       IF (v_fcflv_rec.s_fee_structure_status = gcst_planned) THEN
8659                         v_message_name := 'IGS_FI_FEELIAB_STATU_PLANNED';
8660                         IF (p_trace_on = 'Y' AND v_fcflv_rec.source <> 'OLD') THEN
8661                           fnd_message.set_name ( 'IGS', v_message_name);
8662                           fnd_file.put_line (fnd_file.log, fnd_message.get);
8663                         END IF;
8664                         log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8665                                     p_v_string => 'FCFL Status is Planned. So Proceed with next FCFL.' );
8666                         v_next_fcfl_flag := TRUE;
8667 
8668                       ELSIF (v_fcflv_rec.s_fee_structure_status = gcst_inactive) THEN
8669                         -- The liability may have been ACTIVE at the time of
8670                         -- the last assessment and an assessment could have
8671                         -- been recorded, therefore we must clear it.
8672                         v_message_name := 'IGS_FI_FEELIAB_STATU_INACTIVE';
8673                         IF (p_trace_on = 'Y' AND v_fcflv_rec.source <> 'OLD') THEN
8674                           -- Trace entry
8675                           fnd_message.set_name ( 'IGS', v_message_name);
8676                           fnd_file.put_line (fnd_file.log, fnd_message.get);
8677                         END IF;
8678 
8679                         v_fee_assessment := 0;
8680                         v_charge_rate := 0;
8681 
8682                         log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8683                                     p_v_string => 'FCFL Status is Inactive. So call finpl_ins_fee_ass with assessment amount 0.' );
8684                         -- Perform 2.4 Record Assessment Amount
8685                         finpl_ins_fee_ass(
8686                                         p_person_id,
8687                                         p_course_cd,
8688                                         v_fcflv_rec.FEE_TYPE,
8689                                         v_fcflv_rec.fee_cal_type,
8690                                         v_fcflv_rec.fee_ci_sequence_number,
8691                                         v_fcflv_rec.s_fee_trigger_cat,
8692                                         v_fcflv_rec.fee_cat,
8693                                         p_local_currency,
8694                                         v_charge_rate,
8695                                         v_fcflv_rec.s_fee_type,
8696                                         p_effective_dt,
8697                                         p_trace_on,
8698                                         p_course_version_number,
8699                                         p_course_attempt_status,
8700                                         l_v_attendance_mode,
8701                                         l_v_attendance_type,
8702                                         v_charge_elements,
8703                                         v_fee_assessment,
8704                                         v_fcflv_rec.fee_liability_status,
8705                                         v_fcflv_rec.rul_sequence_number,
8706                                         v_fcflv_rec.scope_rul_sequence_num,
8707                                         v_fcflv_rec.s_chg_method_type,
8708                                         p_scahv_location_cd,
8709                                         p_c_career,
8710                                         v_fcflv_rec.elm_rng_order_name,
8711                                         v_fcflv_rec.max_chg_elements );
8712                         log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8713                                     p_v_string => 'FCFL Status is Inactive. So proceed with next FCFL.' );
8714                         v_next_fcfl_flag := TRUE;
8715 
8716                       ELSIF (v_fcflv_rec.s_fee_structure_status = gcst_active) THEN
8717                         log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8718                                     p_v_string => 'FCFL Status is Active. So carrying out Date Alias Validations.' );
8719                         -- Check if End Date Alias of FCCI and FCFL are same. If Not, check End Date Alias validation.
8720                         IF v_fcci_fss_rec.end_dt_alias <> v_fcflv_rec.end_dt_alias
8721                            OR v_fcci_fss_rec.end_dai_sequence_number <> v_fcflv_rec.end_dai_sequence_number THEN
8722                           IF (TRUNC(SYSDATE) > TRUNC(v_fcflv_end_dt)) THEN
8723                             IF (p_trace_on = 'Y') THEN
8724                               fnd_file.new_line(fnd_file.log);
8725                               fnd_message.set_name('IGS','IGS_ST_PROC_NEXT_FEE_CAT_CAL');
8726                               fnd_file.put_line (fnd_file.log, fnd_message.get);
8727                             END IF;
8728                             log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8729                                         p_v_string => 'Today is past the fee assessment processing period. Processing next fee category calendar instance.' );
8730                             v_next_fcfl_flag := TRUE;
8731                           END IF;
8732                         END IF;
8733                       END IF; /* FCFL Status */
8734                     END IF; /* v_next_fcfl_flag = FALSE */
8735 
8736                     -- Check if Process Effective Date falls within Start and End Dates of FCFL.
8737                     IF (v_next_fcfl_flag = FALSE) THEN
8738                       IF g_c_predictive_ind = 'N'
8739                          AND (TRUNC(p_effective_dt) NOT BETWEEN TRUNC(v_fcflv_start_dt)
8740                                                                 AND TRUNC(v_fcflv_end_dt)) THEN
8741 
8742                         v_fee_assessment := 0;
8743                         v_charge_rate := 0;
8744                         IF (p_trace_on = 'Y') THEN
8745                           -- Trace Entry
8746                           fnd_file.new_line(fnd_file.log);
8747                           fnd_message.set_name('IGS','IGS_FI_ST_DT_ASS_AMT');
8748                           fnd_message.set_token('OLD_AMT', TO_CHAR(v_fee_assessment) );
8749                           fnd_file.put_line (fnd_file.log, fnd_message.get);
8750                         END IF;
8751 
8752                         log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8753                                     p_v_string => 'Effective Date does not fall within FCFL start date and end date. Calling finpl_ins_fee_ass with Assessment amount as 0.' );
8754 
8755                         -- Perform 2.4 Record Assessment Amount
8756                         finpl_ins_fee_ass(
8757                                         p_person_id,
8758                                         p_course_cd,
8759                                         v_fcflv_rec.FEE_TYPE,
8760                                         v_fcflv_rec.fee_cal_type,
8761                                         v_fcflv_rec.fee_ci_sequence_number,
8762                                         v_fcflv_rec.s_fee_trigger_cat,
8763                                         v_fcflv_rec.fee_cat,
8764                                         p_local_currency,
8765                                         v_charge_rate,
8766                                         v_fcflv_rec.s_fee_type,
8767                                         p_effective_dt,
8768                                         p_trace_on,
8769                                         p_course_version_number,
8770                                         p_course_attempt_status,
8771                                         l_v_attendance_mode,
8772                                         l_v_attendance_type,
8773                                         v_charge_elements,
8774                                         v_fee_assessment,
8775                                         v_fcflv_rec.fee_liability_status,
8776                                         v_fcflv_rec.rul_sequence_number,
8777                                         v_fcflv_rec.scope_rul_sequence_num,
8778                                         v_fcflv_rec.s_chg_method_type,
8779                                         p_scahv_location_cd,
8780                                         p_c_career,
8781                                         v_fcflv_rec.elm_rng_order_name,
8782                                         v_fcflv_rec.max_chg_elements );
8783                         log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8784                                     p_v_string => 'Effective Date does not fall within FCFL start date and end date. Proceed with next FCFL.' );
8785                         v_next_fcfl_flag := TRUE;
8786                       END IF;
8787                     END IF;
8788 
8789                     -- In case of Predictive, FCFL Start Date should be less than or equal to SYSDATE
8790                     IF v_next_fcfl_flag = FALSE THEN
8791                       IF g_c_predictive_ind = 'Y' AND  TRUNC(SYSDATE) >= TRUNC(v_fcflv_start_dt) THEN
8792                         IF (p_trace_on = 'Y') THEN
8793                           fnd_message.set_name('IGS','IGS_FI_PRED_PAST_TERM');
8794                           fnd_message.set_token('DT_ALIAS', v_fcflv_rec.start_dt_alias );
8795                           fnd_message.set_token('ALT_CD', g_v_fee_alt_code );
8796                           fnd_file.put_line (fnd_file.log, fnd_message.get);
8797                         END IF;
8798                         log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8799                                     p_v_string => 'FCFL Start Date is greater than SYSDATE. Proceed to next FCFL.' );
8800                         v_next_fcfl_flag := TRUE;
8801                       END IF;
8802                     END IF;
8803 
8804                     -- Perform 2.1 Check Fee Triggers
8805                     IF (v_next_fcfl_flag = FALSE) THEN
8806 
8807                       log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8808                                   p_v_string => 'Checking Fee Trigger. Arguments passed: '
8809                                                 || 'Fee Cat: ' || v_fcci_fss_rec.fee_cat
8810                                                 || ', Fee Cal Type: ' || p_fee_cal_type
8811                                                 || ', Fee Cal Seq Num: ' || p_fee_ci_sequence_num
8812                                                 || ', Fee Type: ' || v_fcflv_rec.fee_type
8813                                                 || ', Fee Trig Cat: ' || v_fcflv_rec.s_fee_trigger_cat
8814                                                 || ', Effective Dt: ' || TO_CHAR(p_effective_dt, 'DD-MON-YYYY HH24:MI:SS')
8815                                                 || ', Person Id: ' || p_person_id
8816                                                 || ', Course Cd: ' || p_course_cd
8817                                                 || ', Course Ver: ' || p_course_version_number
8818                                                 || ', Cal Type: ' || p_cal_type
8819                                                 || ', Location Cd: ' || p_scahv_location_cd
8820                                                 || ', Att Mode: ' || p_scahv_attendance_mode
8821                                                 || ', Att Type: ' || p_scahv_attendance_type );
8822                       IF (igs_fi_gen_005.finp_val_fee_trigger(
8823                                       v_fcci_fss_rec.fee_cat,
8824                                       p_fee_cal_type,
8825                                       p_fee_ci_sequence_num,
8826                                       v_fcflv_rec.fee_type,
8827                                       v_fcflv_rec.s_fee_trigger_cat,
8828                                       p_effective_dt,
8829                                       p_person_id,
8830                                       p_course_cd,
8831                                       p_course_version_number,
8832                                       p_cal_type,
8833                                       p_scahv_location_cd,
8834                                       p_scahv_attendance_mode,
8835                                       p_scahv_attendance_type,
8836                                       v_trigger_fired) = TRUE) THEN
8837                         -- Trigger was fired.
8838                         log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8839                                     p_v_string => 'Trigger Fired: ' || v_trigger_fired );
8840                         IF (v_trigger_fired = 'INSTITUTN') THEN
8841                                 IF (p_trace_on = 'Y') THEN
8842                                         fnd_file.new_line(fnd_file.log);
8843                                         fnd_message.set_name ( 'IGS', 'IGS_FI_FEETRGCAT_INSTITUTN');
8844                                         fnd_file.put_line (fnd_file.log, fnd_message.get);
8845                                 END IF;
8846                         ELSIF (v_trigger_fired = 'CTFT') THEN
8847                                 IF (p_trace_on = 'Y') THEN
8848                                         fnd_file.new_line(fnd_file.log);
8849                                         fnd_message.set_name ( 'IGS', 'IGS_FI_PRGTYPE_FEETRG_MATCHES');
8850                                         fnd_file.put_line (fnd_file.log, fnd_message.get);
8851                                 END IF;
8852                         ELSIF (v_trigger_fired = 'CGFT') THEN
8853                                 IF (p_trace_on = 'Y') THEN
8854                                         fnd_file.new_line(fnd_file.log);
8855                                         fnd_message.set_name ( 'IGS', 'IGS_FI_PRGGRP_FEETRG_PRGATT');
8856                                         fnd_file.put_line (fnd_file.log, fnd_message.get);
8857                                 END IF;
8858                         ELSIF (v_trigger_fired = 'CFT') THEN
8859                                 IF (p_trace_on = 'Y') THEN
8860                                         fnd_file.new_line(fnd_file.log);
8861                                         fnd_message.set_name ( 'IGS', 'IGS_FI_PRGFEE_TRGATTRIB_MATCH');
8862                                         fnd_file.put_line (fnd_file.log, fnd_message.get);
8863                                 END IF;
8864                         ELSIF (v_trigger_fired = 'UFT') THEN
8865                                 IF (p_trace_on = 'Y') THEN
8866                                         fnd_file.new_line(fnd_file.log);
8867                                         fnd_message.set_name ( 'IGS', 'IGS_FI_UNIT_FEETRG_ATTRIB');
8868                                         fnd_file.put_line (fnd_file.log, fnd_message.get);
8869                                 END IF;
8870                         ELSIF (v_trigger_fired = 'USFT') THEN
8871                                 IF (p_trace_on = 'Y') THEN
8872                                         fnd_file.new_line(fnd_file.log);
8873                                         fnd_message.set_name ( 'IGS', 'IGS_FI_UNIT_SET_FEETRG_ATTRIB');
8874                                         fnd_file.put_line (fnd_file.log, fnd_message.get);
8875                                 END IF;
8876                         ELSIF (v_trigger_fired = 'AUDIT') THEN
8877                                 IF (p_trace_on = 'Y') THEN
8878                                         fnd_file.new_line(fnd_file.log);
8879                                         fnd_message.set_name ( 'IGS', 'IGS_FI_AUD_FEE_TRIG_FIRED');
8880                                         fnd_file.put_line (fnd_file.log, fnd_message.get);
8881                                 END IF;
8882                         ELSIF (v_trigger_fired = 'COMPOSITE') THEN
8883                                 IF (p_trace_on = 'Y') THEN
8884                                         fnd_file.new_line(fnd_file.log);
8885                                         fnd_message.set_name ( 'IGS', 'IGS_FI_FEETRG_GRP_MEMBER');
8886                                         fnd_file.put_line (fnd_file.log, fnd_message.get);
8887                                 END IF;
8888 
8889                         END IF;
8890                       ELSE    -- Trigger did not fire
8891                         v_fee_assessment := 0;
8892                         v_charge_rate := 0;
8893                         v_message_name := 'IGS_FI_TRG_DID_NOT_FIRE';
8894                         IF (p_trace_on = 'Y') THEN
8895                                 -- Trace Entry
8896                                 fnd_message.set_name ( 'IGS', v_message_name);
8897                                 fnd_file.put_line (fnd_file.log, fnd_message.get);
8898                                 fnd_file.new_line(fnd_file.log);
8899                                 fnd_message.set_name('IGS','IGS_FI_ASS_AMT');
8900                                 fnd_message.set_token('AMOUNT',TO_CHAR(v_fee_assessment) );
8901                                 fnd_file.put_line (fnd_file.log, fnd_message.get);
8902                         END IF;
8903 
8904                         log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8905                                     p_v_string => 'Trigger Not fired. Call finpl_ins_fee_ass with assessment amount 0.');
8906                         -- Perform 2.4 Record Assessment Amount
8907                         finpl_ins_fee_ass(
8908                                         p_person_id,
8909                                         p_course_cd,
8910                                         v_fcflv_rec.FEE_TYPE,
8911                                         v_fcflv_rec.fee_cal_type,
8912                                         v_fcflv_rec.fee_ci_sequence_number,
8913                                         v_fcflv_rec.s_fee_trigger_cat,
8914                                         p_fee_cat,
8915                                         p_local_currency,
8916                                         v_charge_rate,
8917                                         v_fcflv_rec.s_fee_type,
8918                                         p_effective_dt,
8919                                         p_trace_on,
8920                                         p_course_version_number,
8921                                         p_course_attempt_status,
8922                                         l_v_attendance_mode,
8923                                         l_v_attendance_type,
8924                                         v_charge_elements,
8925                                         v_fee_assessment,
8926                                         v_fcflv_rec.fee_liability_status,
8927                                         v_fcflv_rec.rul_sequence_number,
8928                                         v_fcflv_rec.scope_rul_sequence_num,
8929                                         v_fcflv_rec.s_chg_method_type,
8930                                         p_scahv_location_cd,
8931                                         p_c_career,
8932                                         v_fcflv_rec.elm_rng_order_name,
8933                                         v_fcflv_rec.max_chg_elements );
8934                         log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8935                                     p_v_string => 'Trigger Not fired. Proceed with next FCFL.');
8936                         v_next_fcfl_flag := TRUE;
8937                       END IF; /* igs_fi_gen_005.finp_val_fee_trigger */
8938                     END IF;
8939 
8940 
8941                     IF p_process_mode IN ('ACTUAL','PREDICTIVE') THEN
8942                       IF (v_next_fcfl_flag = FALSE) THEN
8943                         -- Perform 2.2 Calculate Charge Method Elements
8944                         log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8945                                     p_v_string => 'Calling finpl_clc_chg_mthd_elements...');
8946                         IF (finpl_clc_chg_mthd_elements(
8947                                         p_effective_dt,
8948                                         p_trace_on,
8949                                         p_person_id,
8950                                         p_course_cd,
8951                                         p_course_version_number,
8952                                         p_scahv_attendance_type,
8953                                         p_course_attempt_status,
8954                                         v_fcflv_rec.s_chg_method_type,
8955                                         v_fcci_fss_rec.FEE_CAT,
8956                                         v_fcflv_rec.fee_cal_type,
8957                                         v_fcflv_rec.fee_ci_sequence_number,
8958                                         v_fcflv_rec.FEE_TYPE,
8959                                         v_fcflv_rec.s_fee_type,
8960                                         v_fcflv_rec.s_fee_trigger_cat,
8961                                         v_charge_elements,
8962                                         p_message_name,
8963                                         p_scahv_location_cd,
8964                                         p_c_career,
8965                                         v_fcflv_rec.scope_rul_sequence_num) = FALSE) THEN
8966                           log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8967                                       p_v_string => 'finpl_clc_chg_mthd_elements returned FALSE with message ' || p_message_name || '. Proceed with next FCFL.');
8968                           v_next_fcfl_flag := TRUE;
8969                         END IF;
8970                       END IF;
8971 
8972                       IF (v_next_fcfl_flag = FALSE) THEN
8973                         IF (v_charge_elements > 0) THEN
8974                           -- Perform 2.3 Calculate Assessment Amount
8975                           IF (p_trace_on = 'Y') THEN
8976                               fnd_file.new_line(fnd_file.log);
8977                               fnd_message.set_name('IGS','IGS_FI_CHRG_METHOD_ELEMENTS');
8978                               fnd_message.set_token('CHG_ELM',TO_CHAR(v_charge_elements) );
8979                               fnd_file.put_line (fnd_file.log, fnd_message.get);
8980                           END IF;
8981                           log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
8982                                       p_v_string => 'Calling finp_clc_ass_amnt..');
8983                           IF (finp_clc_ass_amnt(
8984                                       p_effective_dt,
8985                                       p_person_id,
8986                                       p_course_cd,
8987                                       p_course_version_number,
8988                                       p_course_attempt_status,
8989                                       v_fcflv_rec.FEE_TYPE,
8990                                       v_fcflv_rec.fee_cal_type,
8991                                       v_fcflv_rec.fee_ci_sequence_number,
8992                                       v_fcci_fss_rec.FEE_CAT,
8993                                       v_fcflv_rec.s_fee_type,
8994                                       v_fcflv_rec.s_fee_trigger_cat,
8995                                       v_fcflv_rec.rul_sequence_number,
8996                                       v_fcflv_rec.s_chg_method_type,
8997                                       p_scahv_location_cd,
8998                                       p_scahv_attendance_type,
8999                                       p_scahv_attendance_mode,
9000                                       p_trace_on,
9001                                       p_creation_dt, -- in out
9002                                       v_charge_elements,      -- in out
9003                                       v_fee_assessment,       -- in out
9004                                       v_charge_rate,
9005                                       p_c_career,
9006                                       v_fcflv_rec.elm_rng_order_name,
9007                                       v_fcflv_rec.max_chg_elements,
9008                                       0) = FALSE) THEN
9009                             log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
9010                                         p_v_string => 'finp_clc_ass_amnt returned FALSE. Proceed with next FCFL. Out Vars: Chg Elms: '
9011                                                       || v_charge_elements || ', Amount: ' || v_fee_assessment );
9012                             v_next_fcfl_flag := TRUE;
9013                           END IF;
9014                         ELSE
9015                           log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
9016                                       p_v_string => 'No Charge Elements found so make Assessment Amount to 0.');
9017                           v_fee_assessment := 0;
9018                           v_charge_rate := 0;
9019                           IF (p_trace_on = 'Y') THEN
9020                             fnd_message.set_name ( 'IGS', 'IGS_FI_NO_CHARGE_ELEMENTS');
9021                             fnd_file.put_line (fnd_file.log, fnd_message.get);
9022                             fnd_file.new_line(fnd_file.log);
9023                             fnd_message.set_name('IGS', 'IGS_FI_ASS_AMT');
9024                             fnd_message.set_token('AMOUNT', TO_CHAR(v_fee_assessment) );
9025                             fnd_file.put_line (fnd_file.log, fnd_message.get);
9026                           END IF;
9027 
9028                         END IF; /* v_charge_elements > 0 */
9029                       END IF;
9030                     END IF; /* p_process_mode IN ('ACTUAL','PREDICTIVE') */
9031 
9032                     IF (v_next_fcfl_flag = FALSE) THEN
9033 
9034                       --Added as part of Tuition Waivers
9035                       IF (NVL(p_v_wav_calc_flag,'N') = 'Y') THEN
9036                         p_n_waiver_amount := NVL(p_n_waiver_amount,0) + NVL(v_fee_assessment,0);
9037                         log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
9038                                     p_v_string => 'Assigning v_fee_assessment cumulatively to p_n_waiver_amount of '||p_n_waiver_amount);
9039                         RETURN TRUE;
9040                       END IF;
9041 
9042                       -- Perform 2.4 Record Assessment Amount
9043                       log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
9044                                   p_v_string => 'Calling finpl_ins_fee_ass..' );
9045                       finpl_ins_fee_ass(
9046                                p_person_id,
9047                                p_course_cd,
9048                                v_fcflv_rec.fee_type,
9049                                v_fcflv_rec.fee_cal_type,
9050                                v_fcflv_rec.fee_ci_sequence_number,
9051                                v_fcflv_rec.s_fee_trigger_cat,
9052                                p_fee_cat,
9053                                p_local_currency,
9054                                v_charge_rate,
9055                                v_fcflv_rec.s_fee_type,
9056                                p_effective_dt,
9057                                p_trace_on,
9058                                p_course_version_number,
9059                                p_course_attempt_status,
9060                                l_v_attendance_mode,
9061                                l_v_attendance_type,
9062                                v_charge_elements,
9063                                v_fee_assessment,
9064                                v_fcflv_rec.fee_liability_status,
9065                                v_fcflv_rec.rul_sequence_number,
9066                                v_fcflv_rec.scope_rul_sequence_num,
9067                                v_fcflv_rec.s_chg_method_type,
9068                                p_scahv_location_cd,
9069                                p_c_career,
9070                                v_fcflv_rec.elm_rng_order_name,
9071                                v_fcflv_rec.max_chg_elements );
9072                       log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
9073                                   p_v_string => 'After finpl_ins_fee_ass for this FCFL. Proceed with next FCFL.' );
9074                     END IF;
9075                     --Added as part of Tuition Waivers Build
9076                     IF (p_v_wav_calc_flag = 'N' AND p_waiver_call_ind = 'N') THEN
9077                       IF (igs_fi_wav_utils_002.check_stdnt_wav_assignment( p_n_person_id         => p_person_id,
9078                                                                        p_v_fee_type          => v_fcflv_rec.fee_type,
9079                                                                        p_v_fee_cal_type      => p_fee_cal_type,
9080                                                                        p_n_fee_ci_seq_number => p_fee_ci_sequence_num ) = TRUE) THEN
9081                          FOR rec_fcfl IN cur_fcfl(v_fcflv_rec.fee_cat, p_fee_cal_type, p_fee_ci_sequence_num, v_fcflv_rec.fee_type)
9082                          LOOP
9083                            l_n_rec_count := tbl_wav_fcfl.COUNT + 1;
9084                            tbl_wav_fcfl(l_n_rec_count).p_fee_category := rec_fcfl.fee_cat;
9085                            tbl_wav_fcfl(l_n_rec_count).p_fee_type := rec_fcfl.fee_type;
9086                            tbl_wav_fcfl(l_n_rec_count).p_course_cd := p_course_cd;
9087                            tbl_wav_fcfl(l_n_rec_count).p_career := p_c_career;
9088                            log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
9089                                        p_v_string => 'Adding record '||l_n_rec_count||' in tbl_wav_fcfl, Fee Cat: '|| rec_fcfl.fee_cat
9090                                                      ||', Fee Type: '||rec_fcfl.fee_type||', Course Cd: '||p_course_cd
9091                                                      ||', Career: '||p_c_career);
9092                          END LOOP;
9093                       END IF;
9094                     END IF;
9095                   END LOOP; /* End of Loop of FCFL */
9096 
9097                   IF (v_fcfl_found = FALSE) THEN
9098                     v_message_name := 'IGS_FI_NOACTIVE_FEECAT_FEE_LI';
9099                     IF (p_trace_on = 'Y') THEN
9100                       fnd_message.set_name ( 'IGS', v_message_name);
9101                       fnd_file.put_line (fnd_file.log, fnd_message.get);
9102                     END IF;
9103                     log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
9104                                 p_v_string => 'No Active FCFL found. Ending the processing. ' || v_message_name );
9105                   END IF;
9106                 END LOOP; /* End of Loop of FCCI */
9107 
9108                 -- Log a message if no Active FCCI records exist.
9109                 IF (v_fcci_found = FALSE) THEN
9110                   IF (p_trace_on = 'Y') THEN
9111                     fnd_file.new_line(fnd_file.log);
9112                     fnd_message.set_name ( 'IGS', 'IGS_FI_NOACTIVE_FEECATCAL_INS');
9113                     fnd_file.put_line (fnd_file.log, fnd_message.get);
9114                   END IF;
9115                   log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
9116                               p_v_string => 'No Active FCCI found. Ending the processing. IGS_FI_NOACTIVE_FEECATCAL_INS' );
9117                 END IF;
9118 
9119                 log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
9120                             p_v_string => 'Returning from finpl_prc_fee_cat_fee_liab. Out - Message: ' || p_message_name );
9121                 RETURN TRUE;
9122         END;
9123    EXCEPTION
9124         WHEN e_lock_exception THEN
9125                 log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
9126                             p_v_string => 'In Exception Handler of e_lock_exception' );
9127                 fnd_message.set_name('IGS', 'IGS_FI_FEEAS_NO_CONC_RUN');
9128                 fnd_message.set_token('PERSON_NUM',g_v_person_number);
9129                 fnd_message.set_token('FEE_PERIOD',g_v_fee_alt_code);
9130                 igs_ge_msg_stack.add;
9131                 app_exception.raise_exception(NULL, NULL, fnd_message.get);
9132           WHEN OTHERS THEN
9133                   log_to_fnd( p_v_module => 'finpl_prc_fee_cat_fee_liab',
9134                               p_v_string => 'From exception handler of WHEN OTHERS of finpl_prc_fee_cat_fee_liab.' );
9135                   Fnd_Message.Set_Name ('IGS', 'IGS_GE_UNHANDLED_EXP');
9136                   Fnd_Message.Set_Token('NAME','IGS_FI_PRC_FEE_ASS.FINPL_PRC_FEE_CAT_FEE_LIAB-'||SUBSTR(sqlerrm,1,500));
9137                   IGS_GE_MSG_STACK.ADD;
9138                   App_Exception.Raise_Exception;
9139         END finpl_prc_fee_cat_fee_liab;
9140 
9141     PROCEDURE finpl_prc_predictive_scas ( p_n_person_id           IN igs_fi_fee_as_items.person_id%TYPE,
9142                                           p_v_course_cd           IN igs_ps_ver_all.course_cd%TYPE,
9143                                           p_v_career              IN igs_ps_ver_all.course_type%TYPE,
9144                                           p_v_fee_category        IN igs_fi_fee_cat_all.fee_cat%TYPE,
9145                                           p_v_fee_cal_type        IN igs_fi_f_typ_ca_inst_all.fee_cal_type%TYPE,
9146                                           p_n_fee_ci_sequence_num IN igs_fi_f_typ_ca_inst_all.fee_ci_sequence_number%TYPE,
9147                                           p_v_curr_cd             IN igs_fi_control_all.currency_cd%TYPE,
9148                                           p_d_effective_date      IN DATE,
9149                                           p_v_trace_on            IN VARCHAR2,
9150                                           p_b_record_found        OUT NOCOPY BOOLEAN,
9151                                           p_v_message_name        OUT NOCOPY VARCHAR2,
9152                                           p_b_return_status       OUT NOCOPY BOOLEAN,
9153                                           p_waiver_call_ind       IN VARCHAR2,
9154                                           p_target_fee_type       IN VARCHAR2
9155                                           ) IS
9156     /*************************************************************
9157      Created By :      Shirish Tatikonda
9158      Date Created By : 30-DEC-2003
9159      Purpose :         All program attempts that needs to be assessed in PREDICTIVE Mode
9160                        will be identified in this procedure.
9161                        Called from finp_ins_enr_fee_ass.
9162 
9163      Know limitations, enhancements or remarks
9164      Change History
9165      Who             When          What
9166      rmaddipa        03-NOV-2004   Enh 3988455, Modified definitions of cursors c_get_term_recs, c_get_scas_recs
9167      shtatiko        30-DEC-2003   Enh# 3167098, Created this function.
9168     ***************************************************************/
9169 
9170       TYPE prd_prog_details_rec_typ IS RECORD (
9171              person_id          hz_parties.party_id%TYPE,
9172              program_cd         igs_ps_ver_all.course_cd%TYPE,
9173              program_version    igs_ps_ver_all.version_number%TYPE,
9174              career             igs_ps_ver_all.course_type%TYPE,
9175              fee_cat            igs_fi_fee_cat_all.fee_cat%TYPE,
9176              crs_cal_type       igs_en_stdnt_ps_att_all.cal_type%TYPE,
9177              location_cd        igs_en_stdnt_ps_att_all.location_cd%TYPE,
9178              att_mode           igs_en_stdnt_ps_att_all.attendance_mode%TYPE,
9179              att_type           igs_en_stdnt_ps_att_all.attendance_type%TYPE,
9180              key_program        igs_en_stdnt_ps_att_all.key_program%TYPE,
9181              crs_attempt_status igs_en_stdnt_ps_att_all.course_attempt_status%TYPE,
9182              crs_commence_dt    igs_en_stdnt_ps_att_all.commencement_dt%TYPE,
9183              disc_dt            igs_en_stdnt_ps_att_all.discontinued_dt%TYPE,
9184              adm_admission_appl_number igs_en_stdnt_ps_att_all.adm_admission_appl_number%TYPE,
9185              adm_nominated_course_cd   igs_en_stdnt_ps_att_all.adm_nominated_course_cd%TYPE,
9186              adm_sequence_number       igs_en_stdnt_ps_att_all.adm_sequence_number%TYPE,
9187              source             VARCHAR2 (1)
9188            );
9189 
9190       -- This table type will hold the assessable program details Under Predictive Mode of Processing.
9191       TYPE predictive_progs_tbl_typ IS TABLE OF prd_prog_details_rec_typ
9192         INDEX BY BINARY_INTEGER;
9193 
9194       l_predictive_progs_tbl predictive_progs_tbl_typ;
9195       l_n_prd_progs_cntr   NUMBER;
9196 
9197       l_b_term_key_prg_found  BOOLEAN;
9198 
9199       -- Cursor to get Fee Assessable Program Attempts from Terms Table.
9200       --Enh 3988455: Uptake of Program Transfer Enhancements
9201       --Cursor modified to ignore program attempts with Future-Dated Transfer flag set to 'C'
9202       CURSOR c_get_term_recs(cp_n_person_id    igs_fi_fee_as_items.person_id%TYPE,
9203                              cp_v_fee_category igs_fi_fee_cat_all.fee_cat%TYPE,
9204                              cp_v_course_cd    igs_ps_ver_all.course_cd%TYPE,
9205                              cp_v_career       igs_ps_ver_all.course_type%TYPE,
9206                              cp_v_key_program_flag        igs_en_spa_terms.key_program_flag%TYPE,
9207                              cp_v_course_attempt_status1  igs_en_stdnt_ps_att_all.course_attempt_status%TYPE,
9208                              cp_v_course_attempt_status2  igs_en_stdnt_ps_att_all.course_attempt_status%TYPE,
9209                              cp_v_course_attempt_status3  igs_en_stdnt_ps_att_all.course_attempt_status%TYPE,
9210                              cp_v_course_attempt_status4  igs_en_stdnt_ps_att_all.course_attempt_status%TYPE,
9211                              cp_v_future_dated_trans_flag igs_en_stdnt_ps_att_all.future_dated_trans_flag%TYPE
9212                             ) IS
9213         SELECT spat.person_id,
9214                spat.program_cd,
9215                spat.program_version,
9216                psv.course_type,
9217                spat.fee_cat,
9218                sca.cal_type,
9219                spat.location_cd,
9220                spat.attendance_mode,
9221                spat.attendance_type,
9222                spat.key_program_flag,
9223                sca.course_attempt_status,
9224                sca.commencement_dt,
9225                sca.discontinued_dt
9226         FROM igs_en_spa_terms spat,
9227              igs_en_stdnt_ps_att_all sca,
9228              igs_ps_ver_all psv
9229         WHERE spat.program_cd = psv.course_cd
9230         AND spat.program_version = psv.version_number
9231         AND spat.person_id = cp_n_person_id
9232         AND spat.program_cd = sca.course_cd
9233         AND spat.program_version = sca.version_number
9234         AND spat.person_id = sca.person_id
9235         AND
9236          (spat.term_cal_type = g_v_load_cal_type
9237           AND
9238           spat.term_sequence_number = g_n_load_seq_num
9239          )
9240         AND (cp_v_fee_category IS NULL OR spat.fee_cat = cp_v_fee_category)
9241         AND (cp_v_course_cd IS NULL OR spat.program_cd = cp_v_course_cd)
9242         AND (cp_v_career IS NULL OR cp_v_career = psv.course_type)
9243         AND (
9244              (g_c_fee_calc_mthd IN (g_v_program,g_v_career)) -- Get all Term Records
9245              OR
9246              (spat.key_program_flag = cp_v_key_program_flag AND g_c_fee_calc_mthd = g_v_primary_career)  -- Get only record of Key Program
9247             )
9248         AND (
9249              ( g_c_fee_calc_mthd = g_v_program
9250                AND (sca.course_attempt_status IN  (cp_v_course_attempt_status1, cp_v_course_attempt_status2, cp_v_course_attempt_status3, cp_v_course_attempt_status4)
9251                     AND (NVL(sca.future_dated_trans_flag,'N') <> cp_v_future_dated_trans_flag)
9252                     )
9253              )
9254              OR
9255              ( g_c_fee_calc_mthd IN (g_v_career, g_v_primary_career)
9256                AND sca.course_attempt_status in (cp_v_course_attempt_status1, cp_v_course_attempt_status2, cp_v_course_attempt_status3))
9257             )
9258         ORDER BY spat.fee_cat,
9259                  spat.person_id,
9260                  spat.program_cd;
9261 
9262       -- Cursor to fetch Program Attempts from Student Program Attempt table.
9263       --Enh 3988455: Uptake of Program Transfer Enhancements
9264       --Cursor modified to ignore program attempts with Future-Dated Transfer flag set to 'C'
9265       CURSOR c_get_scas_recs(cp_n_person_id igs_fi_fee_as_items.person_id%TYPE,
9266                              cp_v_fee_cat   igs_fi_fee_cat_all.fee_cat%TYPE,
9267                              cp_v_course_cd igs_ps_ver_all.course_cd%TYPE,
9268                              cp_v_career    igs_ps_ver_all.course_type%TYPE,
9269                              cp_v_primary_program_type    igs_en_stdnt_ps_att_all.primary_program_type%TYPE,
9270                              cp_v_key_program             igs_en_stdnt_ps_att_all.key_program%TYPE,
9271                              cp_v_course_attempt_status1  igs_en_stdnt_ps_att_all.course_attempt_status%TYPE,
9272                              cp_v_course_attempt_status2  igs_en_stdnt_ps_att_all.course_attempt_status%TYPE,
9273                              cp_v_course_attempt_status3  igs_en_stdnt_ps_att_all.course_attempt_status%TYPE,
9274                              cp_v_course_attempt_status4  igs_en_stdnt_ps_att_all.course_attempt_status%TYPE,
9275                              cp_v_future_dated_trans_flag igs_en_stdnt_ps_att_all.future_dated_trans_flag%TYPE ) IS
9276         SELECT sca.person_id,
9277                sca.course_cd,
9278                sca.version_number,
9279                psv.course_type,
9280                sca.fee_cat,
9281                sca.cal_type,
9282                sca.location_cd,
9283                sca.attendance_mode,
9284                sca.attendance_type,
9285                sca.key_program,
9286                sca.course_attempt_status,
9287                sca.commencement_dt,
9288                sca.discontinued_dt,
9289                sca.adm_admission_appl_number,
9290                sca.adm_nominated_course_cd,
9291                sca.adm_sequence_number
9292         FROM igs_en_stdnt_ps_att_all sca,
9293              igs_ps_ver_all psv
9294         WHERE sca.course_cd = psv.course_cd
9295         AND sca. version_number = psv.version_number
9296         AND sca.person_id = cp_n_person_id
9297         AND (cp_v_fee_cat IS NULL OR sca.fee_cat = cp_v_fee_cat)
9298         AND (cp_v_course_cd IS NULL OR sca.course_cd = cp_v_course_cd)
9299         AND (cp_v_career IS NULL OR psv.course_type = cp_v_career)
9300         AND (
9301              (g_c_fee_calc_mthd =g_v_program)
9302              OR
9303              (g_c_fee_calc_mthd =g_v_career AND sca.primary_program_type = cp_v_primary_program_type )
9304              OR
9305              (g_c_fee_calc_mthd = g_v_primary_career AND sca.key_program = cp_v_key_program)
9306             )
9307         AND (
9308              (g_c_fee_calc_mthd = g_v_program AND (sca.course_attempt_status IN  (cp_v_course_attempt_status1, cp_v_course_attempt_status2, cp_v_course_attempt_status3, cp_v_course_attempt_status4)
9309                                                    AND (NVL(sca.future_dated_trans_flag,'N') <> cp_v_future_dated_trans_flag)
9310                                                    )
9311              )
9312              OR
9313              (g_c_fee_calc_mthd IN (g_v_career, g_v_primary_career) AND sca.course_attempt_status in (cp_v_course_attempt_status1, cp_v_course_attempt_status2, cp_v_course_attempt_status3))
9314             )
9315         ORDER BY sca.fee_cat,
9316                  sca.person_id,
9317                  sca.course_cd;
9318 
9319       CURSOR c_fee_cat_curr (cp_v_fee_cat IN igs_fi_fee_cat_all.fee_cat%TYPE) IS
9320         SELECT currency_cd
9321         FROM igs_fi_fee_cat_all
9322         WHERE fee_cat = cp_v_fee_cat;
9323       rec_cur_fee_cat_curr c_fee_cat_curr%ROWTYPE;
9324 
9325       l_b_rec_found_at_terms BOOLEAN;
9326       l_b_prog_att_liable    BOOLEAN;
9327       l_n_cntr               NUMBER;
9328 
9329       FUNCTION find_record_exists ( p_v_course_cd  IN igs_ps_ver_all.course_cd%TYPE,
9330                                     p_v_career     IN igs_ps_ver_all.course_type%TYPE ) RETURN BOOLEAN IS
9331       /*************************************************************
9332        Created By :      Shirish Tatikonda
9333        Date Created By : 30-DEC-2003
9334        Purpose :         Function to check whether the given course/career is already existing in the table.
9335 
9336        Know limitations, enhancements or remarks
9337        Change History
9338        Who             When          What
9339        shtatiko        30-DEC-2003   Enh# 3167098, Created this function.
9340       ***************************************************************/
9341         l_n_cntr  NUMBER := 0;
9342       BEGIN
9343 
9344         IF l_predictive_progs_tbl.COUNT > 0 THEN
9345           FOR l_n_cntr IN l_predictive_progs_tbl.FIRST..l_predictive_progs_tbl.LAST LOOP
9346             IF l_predictive_progs_tbl.EXISTS(l_n_cntr) THEN
9347 
9348               IF ( (g_c_fee_calc_mthd = g_v_program AND l_predictive_progs_tbl(l_n_cntr).program_cd = p_v_course_cd)
9349                    OR
9350                    (g_c_fee_calc_mthd = g_v_career AND l_predictive_progs_tbl(l_n_cntr).career = p_v_career)
9351                    -- find_record_exists is not called for PRIMARY_CAREER case.
9352                  ) THEN
9353                 log_to_fnd( p_v_module => 'find_record_exists',
9354                             p_v_string => 'Record found. Returning TRUE.' );
9355                 RETURN TRUE;
9356               END IF;
9357             END IF;
9358           END LOOP;
9359         END IF;
9360 
9361         log_to_fnd( p_v_module => 'find_record_exists',
9362                     p_v_string => 'Record Not found. Returning FALSE.' );
9363         RETURN FALSE;
9364 
9365       END find_record_exists;
9366 
9367       FUNCTION validate_prog_att ( p_n_cntr IN NUMBER ) RETURN BOOLEAN IS
9368       /*************************************************************
9369        Created By :      Shirish Tatikonda
9370        Date Created By : 09-JAN-2003
9371        Purpose :         Function to check whether the current Program Attempt is liable for assessment.
9372 
9373        Know limitations, enhancements or remarks
9374        Change History
9375        Who             When          What
9376        shtatiko        09-JAN-2003   Enh# 3167098, Created this function.
9377       ***************************************************************/
9378 
9379         current_rec  prd_prog_details_rec_typ;
9380         l_d_adm_ld_start_dt igs_ca_inst_all.start_dt%TYPE;
9381         l_d_fee_ld_start_dt igs_ca_inst_all.start_dt%TYPE;
9382         l_d_crs_cmpl_dt     DATE;
9383         l_v_message_name    fnd_new_messages.message_name%TYPE;
9384 
9385         -- Cursor to get latest intermission end date.
9386         CURSOR c_latest_intermit_date ( cp_n_person_id  igs_en_stdnt_ps_intm.person_id%TYPE,
9387                                         cp_v_course_cd  igs_ps_ver_all.course_cd%TYPE,
9388                                         cp_logical_delete_date igs_en_stdnt_ps_intm.logical_delete_date%TYPE) IS
9389           SELECT sci.end_dt
9390           FROM igs_en_stdnt_ps_intm sci,
9391                IGS_EN_INTM_TYPES eit
9392           WHERE sci.person_id = cp_n_person_id
9393           AND sci.course_cd = cp_v_course_cd
9394           AND sci.logical_delete_date = cp_logical_delete_date
9395           AND sci.approved  = eit.appr_reqd_ind AND
9396           eit.intermission_type = sci.intermission_type
9397           ORDER BY end_dt DESC;
9398         l_d_int_end_dt  igs_en_stdnt_ps_intm.end_dt%TYPE;
9399 
9400         -- Cursor to get the admission offer response status and admission calendar instance details
9401         CURSOR c_adm_details ( cp_n_person_id                  igs_en_stdnt_ps_intm.person_id%TYPE,
9402                                cp_n_adm_admission_appl_number  igs_en_stdnt_ps_att_all.adm_admission_appl_number%TYPE,
9403                                cp_v_adm_nominated_course_cd    igs_en_stdnt_ps_att_all.adm_nominated_course_cd%TYPE,
9404                                cp_n_adm_sequence_number        igs_en_stdnt_ps_att_all.adm_sequence_number%TYPE ) IS
9405           SELECT off.s_adm_offer_resp_status,
9406                  app.adm_cal_type,
9407                  app.adm_ci_sequence_number
9408           FROM igs_ad_ps_appl_inst_all apl_in,
9409                igs_ad_ofr_resp_stat off,
9410                igs_ad_appl_all app
9411           WHERE apl_in.adm_offer_resp_status = off.adm_offer_resp_status
9412           AND apl_in.person_id = cp_n_person_id
9413           AND apl_in.nominated_course_cd = cp_v_adm_nominated_course_cd
9414           AND apl_in.sequence_number = cp_n_adm_sequence_number
9415           AND apl_in.admission_appl_number = cp_n_adm_admission_appl_number
9416           AND app.person_id = apl_in.person_id
9417           AND app.admission_appl_number = apl_in.admission_appl_number;
9418         rec_adm_details  c_adm_details%ROWTYPE;
9419 
9420         -- Cursor to Get the subordinate Load Calendar Instance for the derived Admission Calendar Instance
9421         CURSOR c_sub_adm_cal ( cp_v_adm_cal_type   igs_ca_inst_all.cal_type%TYPE,
9422                                cp_n_adm_ci_seq_num igs_ca_inst_all.sequence_number%TYPE,
9423                                cp_v_admission      igs_ca_type.s_cal_cat%TYPE,
9424                                cp_v_load           igs_ca_type.s_cal_cat%TYPE ) IS
9425           SELECT rl.sub_cal_type,
9426                  rl.sub_ci_sequence_number
9427           FROM igs_ca_inst_rel rl,
9428                igs_ca_type ct1,
9429                igs_ca_type ct2
9430           WHERE rl.sup_cal_type = ct1.cal_type
9431           AND ct1.s_cal_cat = cp_v_admission
9432           AND rl.sub_cal_type = ct2.cal_type
9433           AND ct2.s_cal_cat = cp_v_load
9434           AND rl.sup_cal_type = cp_v_adm_cal_type
9435           AND rl.sup_ci_sequence_number = cp_n_adm_ci_seq_num;
9436         rec_sub_adm_cal  c_sub_adm_cal%ROWTYPE;
9437 
9438         -- Cursor to get Start Date of Calendar Instance given
9439         CURSOR c_get_start_dt ( cp_v_cal_type   igs_ca_inst_all.cal_type%TYPE,
9440                                 cp_n_ci_seq_num igs_ca_inst_all.sequence_number%TYPE ) IS
9441           SELECT start_dt
9442           FROM igs_ca_inst_all
9443           WHERE cal_type = cp_v_cal_type
9444           AND sequence_number = cp_n_ci_seq_num;
9445 
9446         l_v_adm_alt_code       igs_ca_inst_all.alternate_code%TYPE;
9447         l_v_adm_load_alt_code  igs_ca_inst_all.alternate_code%TYPE;
9448 
9449 
9450       BEGIN
9451 
9452         current_rec := l_predictive_progs_tbl(p_n_cntr);
9453 
9454         log_to_fnd( p_v_module => 'validate_prog_att',
9455                     p_v_string => 'Entered validate_prog_att. Program Attempt Status: ' || current_rec.crs_attempt_status );
9456 
9457         IF current_rec.crs_attempt_status = 'INTERMIT' THEN
9458           -- check if the intermission type is defined and if the latest intermission end date is less than the census date alias value.
9459           OPEN c_latest_intermit_date ( p_n_person_id,
9460                                         current_rec.program_cd,
9461                                         TO_DATE('31-12-4712','DD-MM-YYYY') );
9462           FETCH c_latest_intermit_date INTO l_d_int_end_dt;
9463           CLOSE c_latest_intermit_date;
9464 
9465           log_to_fnd( p_v_module => 'validate_prog_att',
9466                       p_v_string => 'Intermission End Date: ' || TO_CHAR(l_d_int_end_dt,'DD-MON-YYYY') ||
9467                                     ', Census Date Alias Value: ' || TO_CHAR(g_d_ld_census_val,'DD-MON-YYYY'));
9468           IF l_d_int_end_dt >= g_d_ld_census_val THEN
9469             RETURN FALSE;
9470           ELSE
9471             RETURN TRUE;
9472           END IF;
9473 
9474         ELSIF current_rec.crs_attempt_status IN ('INACTIVE', 'UNCONFIRM') THEN
9475           IF current_rec.source = 'T' THEN
9476             IF current_rec.crs_attempt_status = 'UNCONFIRM' THEN
9477               log_to_fnd( p_v_module => 'validate_prog_att',
9478                           p_v_string => 'Return True at Point 1.' );
9479               RETURN TRUE;
9480             ELSE
9481               NULL;
9482               -- Go to 'Program Completion Date validations' below
9483             END IF;
9484           ELSE
9485             IF current_rec.adm_admission_appl_number IS NULL
9486                OR current_rec.adm_nominated_course_cd IS NULL
9487                OR current_rec.adm_sequence_number IS NULL THEN
9488               IF current_rec.crs_attempt_status = 'UNCONFIRM' THEN
9489                 IF p_v_trace_on = 'Y' THEN
9490                   fnd_message.set_name ( 'IGS', 'IGS_FI_PRED_NO_START_DATE');
9491                   fnd_file.put_line (fnd_file.log, fnd_message.get);
9492                 END IF;
9493                 log_to_fnd( p_v_module => 'validate_prog_att',
9494                             p_v_string => 'Return False with message: IGS_FI_PRED_NO_START_DATE' );
9495                 RETURN FALSE;
9496               ELSE
9497                 -- Note: Course Commencement Date is always avaliable for an INACTIVE program attempt.
9498                 IF current_rec.crs_commence_dt > g_d_ld_census_val THEN
9499                   IF p_v_trace_on = 'Y' THEN
9500                     fnd_message.set_name('IGS', 'IGS_FI_PRED_STRTDT_EARLY_CNSDT');
9501                     fnd_message.set_token('ALT_CD', g_v_load_alt_code);
9502                     fnd_file.put_line (fnd_file.log, fnd_message.get);
9503                   END IF;
9504                   log_to_fnd( p_v_module => 'validate_prog_att',
9505                               p_v_string => 'Return False with message: IGS_FI_PRED_STRTDT_EARLY_CNSDT' );
9506                   RETURN FALSE;
9507                 ELSE
9508                   NULL;
9509                   -- Go to 'Program Completion Date validations' below
9510                 END IF;
9511               END IF;
9512             ELSE
9513               -- get the student admission application offer response status and the admission calendar instance.
9514               OPEN c_adm_details ( current_rec.person_id,
9515                                    current_rec.adm_admission_appl_number,
9516                                    current_rec.adm_nominated_course_cd,
9517                                    current_rec.adm_sequence_number );
9518               FETCH c_adm_details INTO rec_adm_details;
9519               CLOSE c_adm_details;
9520               log_to_fnd( p_v_module => 'validate_prog_att',
9521                           p_v_string => 'Admission Calendar Derived: '
9522                                         || rec_adm_details.adm_cal_type || ', '
9523                                         || rec_adm_details.adm_ci_sequence_number || ', '
9524                                         || rec_adm_details.s_adm_offer_resp_status );
9525 
9526               IF current_rec.crs_attempt_status = 'INACTIVE' THEN
9527                 IF rec_adm_details.s_adm_offer_resp_status = 'ACCEPTED' THEN
9528                   NULL;
9529                   -- Go to 'Admission Calendar Instance Validation' below
9530                 ELSE
9531                   IF p_v_trace_on = 'Y' THEN
9532                     fnd_message.set_name ( 'IGS', 'IGS_FI_PRED_STATUS_NO_ACCEPTED');
9533                     fnd_file.put_line (fnd_file.log, fnd_message.get);
9534                   END IF;
9535                   log_to_fnd( p_v_module => 'validate_prog_att',
9536                               p_v_string => 'Returning False with message: IGS_FI_PRED_STATUS_NO_ACCEPTED' );
9537                   RETURN FALSE;
9538                 END IF; /* rec_adm_details.s_adm_offer_resp_status */
9539               ELSE
9540                 IF rec_adm_details.s_adm_offer_resp_status = 'PENDING' THEN
9541                   NULL;
9542                   -- Go to 'Admission Calendar Instance Validation' below
9543                 ELSE
9544                   IF p_v_trace_on = 'Y' THEN
9545                     fnd_message.set_name ( 'IGS', 'IGS_FI_PRED_STATUS_NOT_PENDING');
9546                     fnd_file.put_line (fnd_file.log, fnd_message.get);
9547                   END IF;
9548                   log_to_fnd( p_v_module => 'validate_prog_att',
9549                               p_v_string => 'Returning False with message: IGS_FI_PRED_STATUS_NOT_PENDING' );
9550                   RETURN FALSE;
9551                 END IF;
9552               END IF;
9553 
9554               -- Admission Calendar Instance Validation
9555               -- Get the subordinate Load Calendar Instance for the derived Admission Calendar Instance
9556               OPEN c_sub_adm_cal ( rec_adm_details.adm_cal_type,
9557                                    rec_adm_details.adm_ci_sequence_number,
9558                                    'ADMISSION',
9559                                    'LOAD' );
9560               FETCH c_sub_adm_cal INTO rec_sub_adm_cal;
9561               CLOSE c_sub_adm_cal;
9562               log_to_fnd( p_v_module => 'validate_prog_att',
9563                           p_v_string => 'Sub Calendar of Admission Calendar Derived: '
9564                                         || rec_sub_adm_cal.sub_cal_type || ', '
9565                                         || rec_sub_adm_cal.sub_ci_sequence_number );
9566 
9567               -- Get the Alternate Code of Admission Calendar
9568               OPEN g_c_alternate_code ( rec_adm_details.adm_cal_type, rec_adm_details.adm_ci_sequence_number );
9569               FETCH g_c_alternate_code INTO l_v_adm_alt_code;
9570               CLOSE g_c_alternate_code;
9571 
9572               IF rec_sub_adm_cal.sub_cal_type IS NULL OR rec_sub_adm_cal.sub_ci_sequence_number IS NULL THEN
9573                 IF p_v_trace_on = 'Y' THEN
9574                   fnd_message.set_name( 'IGS', 'IGS_FI_NO_ADM_LD_RELN_EXISTS' );
9575                   fnd_message.set_token('ADM_ALT_CD', l_v_adm_alt_code);
9576                   fnd_file.put_line (fnd_file.log, fnd_message.get);
9577                 END IF;
9578                 log_to_fnd( p_v_module => 'validate_prog_att',
9579                             p_v_string => 'Returning False with message: IGS_FI_NO_ADM_LD_RELN_EXISTS' );
9580                 RETURN FALSE;
9581               END IF;
9582 
9583               IF current_rec.crs_attempt_status = 'INACTIVE' THEN
9584                 -- Get Start Date of Admission Load Period derived above
9585                 OPEN c_get_start_dt ( rec_sub_adm_cal.sub_cal_type,
9586                                       rec_sub_adm_cal.sub_ci_sequence_number );
9587                 FETCH c_get_start_dt INTO l_d_adm_ld_start_dt;
9588                 CLOSE c_get_start_dt;
9589 
9590                 -- Get Start Date of Load Period of the Fee Calendar passed to process
9591                 OPEN c_get_start_dt ( g_v_load_cal_type,
9592                                       g_n_load_seq_num );
9593                 FETCH c_get_start_dt INTO l_d_fee_ld_start_dt;
9594                 CLOSE c_get_start_dt;
9595 
9596                 log_to_fnd( p_v_module => 'validate_prog_att',
9597                             p_v_string => 'Adm Load Period St Dt: ' || TO_CHAR(l_d_adm_ld_start_dt, 'DD-MON-YYYY')
9598                                           || ', Fee Load Period St Dt: ' || TO_CHAR(l_d_fee_ld_start_dt, 'DD-MON-YYYY'));
9599                 IF l_d_fee_ld_start_dt < l_d_adm_ld_start_dt THEN
9600                   IF p_v_trace_on = 'Y' THEN
9601                     -- Get the Alternate Code of Load Calendar associated to Admission Calendar
9602                     OPEN g_c_alternate_code ( rec_sub_adm_cal.sub_cal_type,
9603                                               rec_sub_adm_cal.sub_ci_sequence_number );
9604                     FETCH g_c_alternate_code INTO l_v_adm_load_alt_code;
9605                     CLOSE g_c_alternate_code;
9606 
9607                     fnd_message.set_name( 'IGS', 'IGS_FI_PRED_FEE_LP_ERLY_ADM_LP' );
9608                     fnd_message.set_token('LC1_ALT_CD', l_v_adm_load_alt_code);
9609                     fnd_message.set_token('ALT_CD', l_v_adm_alt_code);
9610                     fnd_message.set_token('LC2_ALT_CD', g_v_load_alt_code);
9611                     fnd_file.put_line (fnd_file.log, fnd_message.get);
9612                   END IF;
9613                   log_to_fnd( p_v_module => 'validate_prog_att',
9614                               p_v_string => 'Returning False with message: IGS_FI_PRED_FEE_LP_ERLY_ADM_LP' );
9615                   RETURN FALSE;
9616                 ELSE
9617                   NULL;
9618                   -- Go to 'Program Completion Date validations' below
9619                 END IF;
9620               ELSE
9621                 -- Check if Derived Load period of Admission Calendar is same as Load Period of Fee Calendar passed to process.
9622                 IF g_v_load_cal_type <> rec_sub_adm_cal.sub_cal_type
9623                    OR g_n_load_seq_num <> rec_sub_adm_cal.sub_ci_sequence_number THEN
9624                   IF p_v_trace_on = 'Y' THEN
9625                     -- Get the Alternate Code of Load Calendar associated to Admission Calendar
9626                     OPEN g_c_alternate_code ( rec_sub_adm_cal.sub_cal_type,
9627                                               rec_sub_adm_cal.sub_ci_sequence_number );
9628                     FETCH g_c_alternate_code INTO l_v_adm_load_alt_code;
9629                     CLOSE g_c_alternate_code;
9630 
9631                     fnd_message.set_name( 'IGS', 'IGS_FI_PRED_LOAD_PRDS_NOTSAME' );
9632                     fnd_message.set_token('LC1_ALT_CD', l_v_adm_load_alt_code);
9633                     fnd_message.set_token('ALT_CD', l_v_adm_alt_code);
9634                     fnd_message.set_token('LC2_ALT_CD', g_v_load_alt_code);
9635                     fnd_file.put_line (fnd_file.log, fnd_message.get);
9636                   END IF;
9637                   log_to_fnd( p_v_module => 'validate_prog_att',
9638                               p_v_string => 'Returning False with message: IGS_FI_PRED_LOAD_PRDS_NOTSAME' );
9639                   RETURN FALSE;
9640                 ELSE
9641                   log_to_fnd( p_v_module => 'validate_prog_att',
9642                               p_v_string => 'Returning True at Point 2.' );
9643                   RETURN TRUE;
9644                 END IF;
9645               END IF;
9646             END IF; /* Check for nulls */
9647           END IF; /* current_rec.source */
9648         END IF; /* crs_attempt_status */
9649 
9650         -- Program Completion Date validations
9651 
9652         IF current_rec.crs_attempt_status IN ('ENROLLED', 'INACTIVE') THEN
9653           -- Call EN API to get Course Completion Date.
9654           l_d_crs_cmpl_dt := igs_en_gen_015.enrf_drv_cmpl_dt ( p_person_id => current_rec.person_id,
9655                                                                p_course_cd => current_rec.program_cd,
9656                                                                p_achieved_cp => NULL,
9657                                                                p_attendance_type => current_rec.att_type,
9658                                                                p_load_cal_type => NULL,
9659                                                                p_load_ci_seq_num => NULL,
9660                                                                p_load_ci_alt_code => NULL,
9661                                                                p_load_ci_start_dt => NULL,
9662                                                                p_load_ci_end_dt => NULL,
9663                                                                p_message_name => l_v_message_name );
9664           log_to_fnd( p_v_module => 'validate_prog_att',
9665                       p_v_string => 'Completion Date Derived: ' || TO_CHAR(l_d_crs_cmpl_dt,'DD-MON-YYYY') );
9666           IF l_d_crs_cmpl_dt IS NULL THEN
9667             log_to_fnd( p_v_module => 'validate_prog_att',
9668                         p_v_string => 'Returning True at Point 3.' );
9669             RETURN TRUE;
9670           ELSE
9671             -- Check if derived course completion date is less than Census Date Alias
9672             IF l_d_crs_cmpl_dt < g_d_ld_census_val THEN
9673               IF p_v_trace_on = 'Y' THEN
9674                 fnd_message.set_name ( 'IGS', 'IGS_FI_CRS_END_DT_LT_CNS_DT');
9675                 fnd_file.put_line (fnd_file.log, fnd_message.get);
9676               END IF;
9677               log_to_fnd( p_v_module => 'validate_prog_att',
9678                           p_v_string => 'Returning False with message: IGS_FI_CRS_END_DT_LT_CNS_DT' );
9679               RETURN FALSE;
9680             ELSE
9681               log_to_fnd( p_v_module => 'validate_prog_att',
9682                           p_v_string => 'Returning True at Point 4.' );
9683               RETURN TRUE;
9684             END IF;
9685           END IF;
9686         END IF;
9687 
9688       END validate_prog_att;
9689 
9690     BEGIN
9691 
9692       log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9693                   p_v_string => 'Entered finpl_prc_predictive_scas. Parameters are: '
9694                                 || 'Person Id: '        || p_n_person_id
9695                                 || ', Course Cd: '        || p_v_course_cd
9696                                 || ', Career: '           || p_v_career
9697                                 || ', Fee Cat: '          || p_v_fee_category
9698                                 || ', Fee Cal Type: '     || p_v_fee_cal_type
9699                                 || ', Fee Cal Seq Num: '  || p_n_fee_ci_sequence_num
9700                                 || ', Currency Cd: '      || p_v_curr_cd
9701                                 || ', Effective Dt: '     || TO_CHAR(p_d_effective_date, 'DD-MON-YYYY')
9702                                 || ', Trace On: '         || p_v_trace_on );
9703 
9704       -- If there any term records for the given term, then ALWAYS select Key Program from Terms table
9705       -- IRRESPECTIVE of whether this key program is selected in following cursor c_get_term_recs or not.
9706       --   If it finds this key program in c_get_term_recs, then INSTITUTION Fees is assessed for that program.
9707       --   If it doesn't, then no INSTITUTION Fees is assessed for the person.
9708       -- If Key Program is not there in Terms table, then check in SPA Table for Key Program.
9709 
9710       -- Check if Key Program Exists in Terms Table for the given term and for the person in context.
9711       -- g_c_key_program and g_n_key_version  are determined in finp_ins_enr_fee_ass
9712       IF g_c_key_program IS NOT NULL AND g_n_key_version IS NOT NULL THEN
9713         log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9714                     p_v_string => 'Key Program found in TERMS table.' );
9715         l_b_term_key_prg_found := TRUE;
9716       ELSE
9717         log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9718                     p_v_string => 'Key Program NOT found in TERMS table.' );
9719         l_b_term_key_prg_found := FALSE;
9720       END IF;
9721 
9722       ------------------------------------------------
9723       -- Identification of Assessable Program Attempts
9724       ------------------------------------------------
9725 
9726       log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9727                   p_v_string => 'Predictive: Finding Student Program Attempts from TERMS table.' );
9728       -- Get assessable Program Attempts from Terms Table.
9729       l_n_prd_progs_cntr := 0;
9730       FOR rec_term_prog_att IN c_get_term_recs ( p_n_person_id,
9731                                                  p_v_fee_category,
9732                                                  p_v_course_cd,
9733                                                  p_v_career,
9734                                                  'Y',
9735                                                  'INTERMIT','ENROLLED','INACTIVE','UNCONFIRM',
9736                                                  'C' )
9737       LOOP
9738 
9739         -- Add the current record to PL/SQL table, l_predictive_progs_tbl
9740         l_n_prd_progs_cntr := l_n_prd_progs_cntr + 1;
9741         l_predictive_progs_tbl(l_n_prd_progs_cntr).person_id        := rec_term_prog_att.person_id;
9742         l_predictive_progs_tbl(l_n_prd_progs_cntr).program_cd       := rec_term_prog_att.program_cd;
9743         l_predictive_progs_tbl(l_n_prd_progs_cntr).program_version  := rec_term_prog_att.program_version;
9744         l_predictive_progs_tbl(l_n_prd_progs_cntr).career           := rec_term_prog_att.course_type;
9745         l_predictive_progs_tbl(l_n_prd_progs_cntr).fee_cat          := rec_term_prog_att.fee_cat;
9746         l_predictive_progs_tbl(l_n_prd_progs_cntr).crs_cal_type     := rec_term_prog_att.cal_type;
9747         l_predictive_progs_tbl(l_n_prd_progs_cntr).location_cd      := rec_term_prog_att.location_cd;
9748         l_predictive_progs_tbl(l_n_prd_progs_cntr).att_mode         := rec_term_prog_att.attendance_mode;
9749         l_predictive_progs_tbl(l_n_prd_progs_cntr).att_type         := rec_term_prog_att.attendance_type;
9750         l_predictive_progs_tbl(l_n_prd_progs_cntr).key_program      := rec_term_prog_att.key_program_flag;
9751         l_predictive_progs_tbl(l_n_prd_progs_cntr).crs_attempt_status := rec_term_prog_att.course_attempt_status;
9752         l_predictive_progs_tbl(l_n_prd_progs_cntr).crs_commence_dt  := rec_term_prog_att.commencement_dt;
9753         l_predictive_progs_tbl(l_n_prd_progs_cntr).disc_dt          := rec_term_prog_att.discontinued_dt;
9754         l_predictive_progs_tbl(l_n_prd_progs_cntr).adm_admission_appl_number := NULL;
9755         l_predictive_progs_tbl(l_n_prd_progs_cntr).adm_nominated_course_cd := NULL;
9756         l_predictive_progs_tbl(l_n_prd_progs_cntr).adm_sequence_number := NULL;
9757         l_predictive_progs_tbl(l_n_prd_progs_cntr).source           := 'T'; -- From Terms Table.
9758         log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9759                     p_v_string => 'Added Record to PL/SQL table(' || l_n_prd_progs_cntr || '). Parameters are: '
9760                                   || 'Program Cd: '             || rec_term_prog_att.program_cd
9761                                   ||', Program Ver:'            || rec_term_prog_att.program_version
9762                                   ||', Career:'                 || rec_term_prog_att.course_type
9763                                   ||', Fee Cat:'                || rec_term_prog_att.fee_cat
9764                                   ||', Cal Type:'               || rec_term_prog_att.cal_type
9765                                   ||', Location Cd:'            || rec_term_prog_att.location_cd
9766                                   ||', Att Mode:'               || rec_term_prog_att.attendance_mode
9767                                   ||', Att Type:'               || rec_term_prog_att.attendance_type
9768                                   ||', Key Prog Flag:'          || rec_term_prog_att.key_program_flag
9769                                   ||', Crs_attempt_status:'     || rec_term_prog_att.course_attempt_status
9770                                   ||', crs_commence_dt:'        || TO_CHAR(rec_term_prog_att.commencement_dt, 'DD-MON-YYYY')
9771                                   ||', disc_dt:'                || TO_CHAR(rec_term_prog_att.discontinued_dt, 'DD-MON-YYYY'));
9772       END LOOP; /* Loop across Term Records. */
9773 
9774       -- Now determine Program Attempts from Student Program Attempts table.
9775       -- EXCEPT in case of PRIMARY_CAREER and Key program is found in terms table.
9776       IF NOT (g_c_fee_calc_mthd = g_v_primary_career AND
9777               l_b_term_key_prg_found = TRUE) THEN
9778 
9779         log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9780                     p_v_string => 'Predictive: Finding Student Program Attempts from SPA table.' );
9781         FOR rec_scas IN c_get_scas_recs ( p_n_person_id,
9782                                           p_v_fee_category,
9783                                           p_v_course_cd,
9784                                           p_v_career,
9785                                           'PRIMARY',
9786                                           'Y',
9787                                           'INTERMIT','ENROLLED','INACTIVE','UNCONFIRM',
9788                                           'C' )
9789         LOOP
9790           l_b_rec_found_at_terms := FALSE;
9791 
9792           -- Check whether this record exists already. Check it only if its not PRIMARY_CAREER.
9793           -- If its PRIMARY_CAREER, then only record we get is Key Program, which we have to add it.
9794           IF g_c_fee_calc_mthd <> g_v_primary_career THEN
9795             log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9796                         p_v_string => 'Find whether record already exists in PL/SQL table by calling find_record_exists: '
9797                                       || rec_scas.course_cd || ', ' || rec_scas.course_type );
9798             l_b_rec_found_at_terms := find_record_exists ( p_v_course_cd => rec_scas.course_cd,
9799                                                            p_v_career    => rec_scas.course_type );
9800           END IF;
9801 
9802           -- If the record is not already existing in table, then add this record to table.
9803           IF NOT l_b_rec_found_at_terms THEN
9804             l_n_prd_progs_cntr := l_n_prd_progs_cntr + 1;
9805             l_predictive_progs_tbl(l_n_prd_progs_cntr).person_id := rec_scas.person_id;
9806             l_predictive_progs_tbl(l_n_prd_progs_cntr).program_cd := rec_scas.course_cd;
9807             l_predictive_progs_tbl(l_n_prd_progs_cntr).program_version := rec_scas.version_number;
9808             l_predictive_progs_tbl(l_n_prd_progs_cntr).career := rec_scas.course_type;
9809             l_predictive_progs_tbl(l_n_prd_progs_cntr).fee_cat := rec_scas.fee_cat;
9810             l_predictive_progs_tbl(l_n_prd_progs_cntr).crs_cal_type := rec_scas.cal_type;
9811             l_predictive_progs_tbl(l_n_prd_progs_cntr).location_cd := rec_scas.location_cd;
9812             l_predictive_progs_tbl(l_n_prd_progs_cntr).att_mode := rec_scas.attendance_mode;
9813             l_predictive_progs_tbl(l_n_prd_progs_cntr).att_type := rec_scas.attendance_type;
9814             l_predictive_progs_tbl(l_n_prd_progs_cntr).key_program := rec_scas.key_program;
9815             l_predictive_progs_tbl(l_n_prd_progs_cntr).crs_attempt_status := rec_scas.course_attempt_status;
9816             l_predictive_progs_tbl(l_n_prd_progs_cntr).crs_commence_dt := rec_scas.commencement_dt;
9817             l_predictive_progs_tbl(l_n_prd_progs_cntr).disc_dt := rec_scas.discontinued_dt;
9818             l_predictive_progs_tbl(l_n_prd_progs_cntr).adm_admission_appl_number := rec_scas.adm_admission_appl_number;
9819             l_predictive_progs_tbl(l_n_prd_progs_cntr).adm_nominated_course_cd := rec_scas.adm_nominated_course_cd;
9820             l_predictive_progs_tbl(l_n_prd_progs_cntr).adm_sequence_number := rec_scas.adm_sequence_number;
9821             l_predictive_progs_tbl(l_n_prd_progs_cntr).source := 'S'; -- From SPA Table.
9822             log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9823                         p_v_string => 'Added Record to PL/SQL table(' || l_n_prd_progs_cntr || '). Parameters are: '
9824                                   || 'Program Cd: '             || rec_scas.course_cd
9825                                   ||', Program Ver:'            || rec_scas.version_number
9826                                   ||', Career:'                 || rec_scas.course_type
9827                                   ||', Fee Cat:'                || rec_scas.fee_cat
9828                                   ||', Cal Type:'               || rec_scas.cal_type
9829                                   ||', Location Cd:'            || rec_scas.location_cd
9830                                   ||', Att Mode:'               || rec_scas.attendance_mode
9831                                   ||', Att Type:'               || rec_scas.attendance_type
9832                                   ||', Key Prog Flag:'          || rec_scas.key_program
9833                                   ||', Crs_attempt_status:'     || rec_scas.course_attempt_status
9834                                   ||', crs_commence_dt:'        || TO_CHAR(rec_scas.commencement_dt, 'DD-MON-YYYY')
9835                                   ||', disc_dt:'                || TO_CHAR(rec_scas.discontinued_dt, 'DD-MON-YYYY')
9836                                   ||', Adm Appl Num: '          || rec_scas.adm_admission_appl_number
9837                                   ||', Adm Nom Crs Cd: '        || rec_scas.adm_nominated_course_cd
9838                                   ||', Adm Seq Num: '           || rec_scas.adm_sequence_number );
9839 
9840           END IF; /* NOT l_b_rec_found_at_terms */
9841         END LOOP;
9842       END IF; /* NOT (PRIMARY_CAREER and Key Prog Found) */
9843 
9844       -------------------------------------------------
9845       -- Call finpl_prc_fee_cat_fee_liab for assessment
9846       -------------------------------------------------
9847 
9848       IF l_predictive_progs_tbl.COUNT > 0 THEN
9849         log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9850                     p_v_string => 'There are records in PL/SQL Table. Process each Program Att found.');
9851         fnd_file.new_line(fnd_file.log);
9852         FOR l_n_cntr IN l_predictive_progs_tbl.FIRST..l_predictive_progs_tbl.LAST LOOP
9853           IF l_predictive_progs_tbl.EXISTS(l_n_cntr) THEN
9854 
9855             IF (p_trace_on = 'Y') THEN
9856               fnd_message.set_name ( 'IGS', 'IGS_FI_MAJOR_PRGLOC_USED');
9857               fnd_message.set_token('PROG', l_predictive_progs_tbl(l_n_cntr).program_cd);
9858               fnd_message.set_token('VER', TO_CHAR(l_predictive_progs_tbl(l_n_cntr).program_version));
9859               fnd_file.put_line (fnd_file.log, fnd_message.get);
9860               fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'STATUS') || ': ' || l_predictive_progs_tbl(l_n_cntr).crs_attempt_status);
9861               fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'START_DT') || ': ' || TO_CHAR(l_predictive_progs_tbl(l_n_cntr).crs_commence_dt, 'DD/MM/YYYY'));
9862               fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'FEE_CAT') || ': ' || l_predictive_progs_tbl(l_n_cntr).fee_cat);
9863               fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_ACCT_ENTITIES', 'LOC') || ': ' || l_predictive_progs_tbl(l_n_cntr).location_cd);
9864               fnd_message.set_name ( 'IGS', 'IGS_FI_DER_ATT_TYPE_GOVT_MODE');
9865               fnd_message.set_token('ATT_MODE', l_predictive_progs_tbl(l_n_cntr).att_mode);
9866               fnd_file.put_line (fnd_file.log, fnd_message.get);
9867               fnd_message.set_name ( 'IGS', 'IGS_FI_ATTTYPE_GOVT_ATTMODE');
9868               fnd_message.set_token('ATT_TYPE', l_predictive_progs_tbl(l_n_cntr).att_type);
9869               fnd_file.put_line (fnd_file.log, fnd_message.get);
9870               fnd_message.set_name ( 'IGS', 'IGS_FI_NO_KEY_PROGRAM');
9871               fnd_message.set_token('YES_NO', l_predictive_progs_tbl(l_n_cntr).key_program);
9872             END IF;
9873 
9874             log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9875                         p_v_string => 'Calling validate_prog_att for record ' || l_n_cntr);
9876             l_b_prog_att_liable := validate_prog_att ( p_n_cntr => l_n_cntr);
9877 
9878             IF l_b_prog_att_liable = TRUE THEN
9879               log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9880                           p_v_string => 'Check if Institution Fee can be assessed.');
9881               -- Check if Institution Fee is to be assessed or not.
9882               -- Note: In Predictive Mode, Institution Fees is assessed ONLY for a Key Program.
9883               IF l_predictive_progs_tbl(l_n_cntr).source = 'T' THEN
9884                 IF l_predictive_progs_tbl(l_n_cntr).key_program = 'Y' THEN
9885                   g_b_prc_inst_fee := TRUE;
9886                 ELSE
9887                   g_b_prc_inst_fee := FALSE;
9888                 END IF;
9889               ELSE
9890                 IF l_predictive_progs_tbl(l_n_cntr).key_program = 'Y' THEN
9891                   IF l_b_term_key_prg_found THEN
9892                     g_b_prc_inst_fee := FALSE;
9893                   ELSE
9894                     g_b_prc_inst_fee := TRUE;
9895                   END IF;
9896                 ELSE
9897                   g_b_prc_inst_fee := FALSE;
9898                 END IF;
9899               END IF;
9900 
9901               IF g_b_prc_inst_fee THEN
9902                 log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9903                             p_v_string => 'Institution Fee is assessed for this Program Attempt.');
9904               ELSE
9905                 log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9906                             p_v_string => 'Institution Fee is NOT assessed for this Program Attempt.');
9907               END IF;
9908 
9909               -- If Fee Category is not specified for the SPA, error out.
9910               IF l_predictive_progs_tbl(l_n_cntr).fee_cat IS NULL THEN
9911                  log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9912                              p_v_string => 'Predictive: Fee Category at SPA level is Null, so log message and abort.');
9913                  fnd_message.set_name ( 'IGS', 'IGS_FI_NO_SPA_FEE_CAT');
9914                  fnd_message.set_token('PROG_ATT', l_predictive_progs_tbl(l_n_cntr).program_cd);
9915                  fnd_file.new_line(fnd_file.log);
9916                  fnd_file.put_line(fnd_file.log,fnd_message.get);
9917                  p_b_return_status := FALSE;
9918                  p_b_record_found := TRUE;
9919                  RETURN;
9920               END IF;
9921 
9922               -- Check if currency code that is attached at the Fee Category Level is same
9923               -- as the currency code that is set at the System Options Level.
9924               OPEN c_fee_cat_curr(l_predictive_progs_tbl(l_n_cntr).fee_cat);
9925               FETCH c_fee_cat_curr INTO rec_cur_fee_cat_curr;
9926               CLOSE c_fee_cat_curr;
9927 
9928               IF (rec_cur_fee_cat_curr.currency_cd <> p_v_curr_cd
9929                   OR rec_cur_fee_cat_curr.currency_cd IS NULL
9930                  ) THEN
9931                 IF (p_trace_on = 'Y') THEN
9932                   fnd_message.set_name ( 'IGS', 'IGS_FI_INVALID_CURR_CODE');
9933                   fnd_file.put_line (fnd_file.log, fnd_message.get);
9934                   fnd_message.set_name('IGS', 'IGS_FI_INV_FEE_CAT_CURR_CODE');
9935                   fnd_message.set_token('CUR_CODE1', rec_cur_fee_cat_curr.currency_cd );
9936                   fnd_message.set_token('FEE_CAT', RTRIM(l_predictive_progs_tbl(l_n_cntr).fee_cat) );
9937                   fnd_message.set_token('CUR_CODE2', p_v_curr_cd );
9938                   fnd_file.put_line (fnd_file.log, fnd_message.get);
9939                 END IF;
9940                 log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9941                             p_v_string => 'Currency at Sys Opt Level('|| p_v_curr_cd || ') and Fee Cat level('
9942                                           || rec_cur_fee_cat_curr.currency_cd ||') are not same. Proceed with next Program Att.');
9943               ELSE
9944 
9945                 IF (p_trace_on = 'Y') THEN
9946                   fnd_file.new_line(fnd_file.log);
9947                   fnd_message.set_name ( 'IGS', 'IGS_FI_PREDICTIVE_FEEASS_SPA');
9948                   fnd_file.put_line (fnd_file.log, fnd_message.get);
9949                 END IF;
9950 
9951                      log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9952                                  p_v_string => 'Calling finpl_prc_fee_cat_fee_liab for Predictive Assessment.');
9953 
9954                      IF (finpl_prc_fee_cat_fee_liab (
9955                             p_d_effective_date,
9956                             p_v_trace_on,
9957                             p_v_fee_cal_type,
9958                             p_n_fee_ci_sequence_num,
9959                             p_v_curr_cd,
9960                             l_predictive_progs_tbl(l_n_cntr).fee_cat,
9961                             l_predictive_progs_tbl(l_n_cntr).person_id,
9962                             l_predictive_progs_tbl(l_n_cntr).program_cd,
9963                             l_predictive_progs_tbl(l_n_cntr).program_version,
9964                             l_predictive_progs_tbl(l_n_cntr).crs_cal_type,
9965                             l_predictive_progs_tbl(l_n_cntr).location_cd,
9966                             l_predictive_progs_tbl(l_n_cntr).att_mode,
9967                             l_predictive_progs_tbl(l_n_cntr).att_type,
9968                             l_predictive_progs_tbl(l_n_cntr).disc_dt,
9969                             l_predictive_progs_tbl(l_n_cntr).crs_attempt_status,
9970                             p_v_message_name,
9971                             'PREDICTIVE',
9972                             l_predictive_progs_tbl(l_n_cntr).career,
9973                             p_waiver_call_ind,
9974                             p_target_fee_type
9975                             ) = FALSE
9976                         ) THEN
9977                             p_b_return_status := FALSE;
9978                             p_b_record_found := TRUE;
9979                             log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9980                                         p_v_string => 'finpl_prc_fee_cat_fee_liab returned FALSE. Returning from finpl_prc_predictive_scas as Failure.');
9981                             RETURN;
9982                      END IF;
9983               END IF; /* Check for Fee Category */
9984             ELSE
9985               log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9986                           p_v_string => 'Program Attempt is not Liable for Assessing. Proceed with next Program Attempt..');
9987             END IF; /* l_b_prog_att_liable */
9988           END IF;
9989         END LOOP;
9990       END IF;
9991 
9992       IF l_predictive_progs_tbl.COUNT > 0 THEN
9993         log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
9994                     p_v_string => 'There are records and processed successfully. So returning as Success.');
9995         p_b_return_status := TRUE;
9996         p_b_record_found := TRUE;
9997         p_v_message_name := NULL;
9998       ELSE
9999         log_to_fnd( p_v_module => 'finpl_prc_predictive_scas',
10000                     p_v_string => 'There are no records found. So returning as Success.');
10001         p_b_return_status := TRUE;
10002         p_b_record_found := FALSE;
10003         p_v_message_name := NULL;
10004       END IF;
10005 
10006     END finpl_prc_predictive_scas;
10007 
10008 
10009     BEGIN       -- FINP_INS_ENR_FEE_ASS main
10010         -- Set the rollback segment. This is the biggest rollback segment.
10011         -- initialise PL/SQL tables
10012 
10013         -- The savepoint needs to be set only if Fee Calc is not invoked from the Waiver processing logic.
10014         IF p_v_wav_calc_flag = 'N' THEN
10015            SAVEPOINT fee_calc_sp;
10016         END IF;
10017 
10018         -- Set the global variable with the procedure parameter, p_v_wav_calc_flag
10019         g_v_wav_calc_flag := p_v_wav_calc_flag;
10020 
10021         log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10022                     p_v_string => 'Entered finp_ins_enr_fee_ass. Parameters are: '
10023                                   || 'Effective Date: ' || TO_CHAR(p_effective_dt, 'DD-MON-YYYY HH24:MI:SS')
10024                                   || ', Person Id: '    || p_person_id
10025                                   || ', Course Cd: '    || p_course_cd
10026                                   || ', Fee Category: ' || p_fee_category
10027                                   || ', Fee Cal Type: ' || p_fee_cal_type
10028                                   || ', Fee Cal Seq Num: ' || p_fee_ci_sequence_num
10029                                   || ', Fee Type: '     || p_fee_type
10030                                   || ', Trace On: '     || p_trace_on
10031                                   || ', Test Run: '     || p_test_run
10032                                   || ', Process Mode: ' || p_process_mode
10033                                   || ', Career: '       || p_c_career
10034                                   || ', GL Date: '      || TO_CHAR(p_d_gl_date, 'DD-MON-YYYY') );
10035 
10036         l_inst_fee_rec := l_inst_fee_rec_dummy;
10037         g_inst_fee_rec_cntr := 0;
10038 
10039         IF (p_trace_on = 'Y') THEN
10040            fnd_file.new_line(fnd_file.log);
10041         END IF;
10042 
10043         -- Check calling parameters
10044         IF (p_effective_dt IS NULL OR
10045                         p_trace_on IS NULL OR
10046                         p_test_run IS NULL) THEN
10047                 p_message_name := Null;
10048                 RETURN TRUE;
10049         END IF;
10050 
10051         /* Select the fee calculation method and program change date alias,
10052            error out NOCOPY when there is no fee calculation method setup */
10053         OPEN  c_fi_control;
10054         FETCH c_fi_control INTO l_c_fi_control;
10055         IF c_fi_control%FOUND THEN
10056           /* Check if Fee Calculation Method is defined, error out NOCOPY if not defined */
10057           l_c_control_curr := l_c_fi_control.currency_cd;
10058           IF (l_c_fi_control.fee_calc_mthd_code IS NOT NULL) THEN
10059             g_c_fee_calc_mthd := l_c_fi_control.fee_calc_mthd_code;
10060             g_v_currency_cd := l_c_fi_control.currency_cd;
10061             log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10062                         p_v_string => 'Fee Calculation Method: ' || g_c_fee_calc_mthd );
10063 
10064             log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10065                         p_v_string => 'Currency Code: ' || g_v_currency_cd );
10066           ELSE
10067             CLOSE c_fi_control;
10068             IF (p_trace_on = 'Y') THEN
10069               /* Could not determine Fee calculation method */
10070               fnd_message.set_name ( 'IGS', 'IGS_FI_FEE_CALC_MTHD_NOT_SET');
10071               fnd_file.put_line (fnd_file.log, fnd_message.get);
10072             END IF;
10073             p_message_name := 'IGS_FI_FEE_CALC_MTHD_NOT_SET';
10074             log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10075                         p_v_string => 'Returning from finp_ins_enr_fee_ass with message ' || p_message_name );
10076             RETURN FALSE;
10077           END IF;
10078         ELSE
10079           CLOSE c_fi_control;
10080           IF (p_trace_on = 'Y') THEN
10081             fnd_message.set_name ( 'IGS', 'IGS_FI_FEE_CALC_MTHD_NOT_SET');
10082             fnd_file.put_line (fnd_file.log, fnd_message.get);
10083           END IF;
10084           p_message_name := 'IGS_FI_FEE_CALC_MTHD_NOT_SET';
10085           log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10086                       p_v_string => 'Returning from finp_ins_enr_fee_ass with message ' || p_message_name || '.');
10087           -- Could not determine Fee calculation method
10088           RETURN FALSE;
10089         END IF;
10090         CLOSE c_fi_control;
10091 
10092         -- p_c_career should have value only when Fee Calc Method is CAREER.
10093         IF ( g_c_fee_calc_mthd = g_v_career) THEN
10094           IF ( p_c_career IS NOT NULL) THEN
10095             -- Validate whether p_c_career is a valid program type.
10096             OPEN c_course_type;
10097             FETCH c_course_type INTO l_c_temp;
10098             IF (c_course_type%NOTFOUND) THEN
10099               CLOSE c_course_type;
10100               IF (p_trace_on = 'Y') THEN
10101                 fnd_message.set_name ( 'IGS', 'IGS_GE_INVALID_VALUE');
10102                 fnd_file.put_line (fnd_file.log, fnd_message.get);
10103               END IF;
10104               p_message_name := 'IGS_GE_INVALID_VALUE';
10105               log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10106                           p_v_string => 'Returning from finp_ins_enr_fee_ass: Invalid Course Type.' );
10107               RETURN FALSE;
10108             -- Log an error message since it course type is not a valid course type
10109             END IF;
10110           END IF;
10111         ELSE
10112           IF ( p_c_career IS NOT NULL) THEN
10113              IF (p_trace_on = 'Y') THEN
10114                 fnd_message.set_name ( 'IGS', 'IGS_GE_INVALID_VALUE');
10115                 fnd_file.put_line (fnd_file.log, fnd_message.get);
10116               END IF;
10117               p_message_name := 'IGS_GE_INVALID_VALUE';
10118               log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10119                           p_v_string => 'Returning from finp_ins_enr_fee_ass: Course Type passed when not CAREER.' );
10120               RETURN FALSE;
10121           END IF;
10122         END IF;
10123 
10124         g_v_person_number := igs_fi_gen_008.get_party_number(p_person_id);
10125 
10126         -- Check for existence of incomplete Primary Program Transfers. If there are any, Fee Assessment cannot be carried out.
10127         -- This check needs to be done only in ACTUAL mode.
10128         IF g_c_fee_calc_mthd IN (g_v_career, g_v_primary_career)
10129            AND p_process_mode <> 'PREDICTIVE' THEN
10130           log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10131                       p_v_string => 'Checking for Incomplete Primary Program Transfer.' );
10132           OPEN c_sua_for_sec( p_person_id,
10133                               'SECONDARY',
10134                               'ENROLLED' );
10135           FETCH c_sua_for_sec INTO rec_sua_for_sec;
10136           IF c_sua_for_sec%FOUND THEN   /* Incomplete transfers found */
10137             -- If this is called from Concurrent Manager
10138             IF fnd_global.conc_request_id <> -1 THEN
10139               IF (p_trace_on = 'Y') THEN
10140                 fnd_message.set_name('IGS', 'IGS_FI_PERSON_NUM');
10141                 fnd_message.set_token('PERSON_NUM', g_v_person_number);
10142                 fnd_file.put_line (fnd_file.log, fnd_message.get);
10143 
10144                 fnd_message.set_name('IGS', 'IGS_FI_INC_PRG_TRANSFER');
10145                 fnd_message.set_token('PERSON_NUM', g_v_person_number);
10146                 fnd_file.put_line (fnd_file.log, fnd_message.get);
10147               END IF;
10148               p_message_name := 'IGS_FI_INC_PRG_TRANSFER';
10149               fnd_message.set_name('IGS', 'IGS_FI_INC_PRG_TRANSFER');
10150               igs_ge_msg_stack.ADD;
10151               log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10152                           p_v_string => 'Returning from finp_ins_enr_fee_ass with message ' || p_message_name );
10153               -- Return TRUE so that the message is shown in Report and continues with next person, if any.
10154               RETURN TRUE;
10155             ELSE
10156               -- This is called from Self-Service Package. Return FALSE so that this message is shown on page.
10157               p_message_name := 'IGS_FI_SS_SP_NOT_ASSESSED';
10158               log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10159                           p_v_string => 'SS: Returning from finp_ins_enr_fee_ass with message ' || p_message_name );
10160               RETURN FALSE;
10161             END IF;
10162           END IF;
10163         END IF;
10164 
10165         -- Validating Course Code and Fee Calc Method
10166         -- Course Cd (p_course_cd) parameter is allowed only incase the fee calculation method is PROGRAM and the process should be errored out NOCOPY
10167         -- other fee calculation methods.
10168         IF ( p_course_cd IS NOT NULL AND g_c_fee_calc_mthd <> g_v_program) THEN
10169           IF (p_trace_on = 'Y') THEN
10170             fnd_message.set_name ( 'IGS', 'IGS_GE_INVALID_VALUE');
10171             fnd_file.put_line (fnd_file.log, fnd_message.get);
10172           END IF;
10173           p_message_name := 'IGS_GE_INVALID_VALUE';
10174           RETURN FALSE;
10175         END IF;
10176 
10177         -- Set Flag to determine if the current assessment mode is Predictive
10178         IF (p_process_mode = 'PREDICTIVE' ) THEN
10179           g_c_predictive_ind := 'Y';
10180         ELSE
10181           g_c_predictive_ind := 'N';
10182         END IF;
10183 
10184         -- Derive Load Period for the passed Fee Period.
10185         l_b_fci_lci := igs_fi_gen_001.finp_get_lfci_reln( p_fee_cal_type,
10186                                                           p_fee_ci_sequence_num,
10187                                                           'FEE',
10188                                                           g_v_load_cal_type,
10189                                                           g_n_load_seq_num,
10190                                                           v_message_name);
10191         IF NOT l_b_fci_lci THEN
10192           IF (p_trace_on = 'Y') THEN
10193             fnd_message.set_name ( 'IGS', v_message_name);
10194             fnd_file.put_line (fnd_file.log, fnd_message.get);
10195           END IF;
10196           p_message_name := v_message_name;
10197           log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10198                       p_v_string => 'Error in finp_get_lfci_reln. Returning from finp_ins_enr_fee_ass with message ' || p_message_name );
10199           RETURN FALSE;
10200         END IF;
10201         OPEN g_c_alternate_code ( g_v_load_cal_type, g_n_load_seq_num );
10202         FETCH g_c_alternate_code INTO g_v_load_alt_code;
10203         CLOSE g_c_alternate_code;
10204 
10205         OPEN g_c_alternate_code ( p_fee_cal_type, p_fee_ci_sequence_num );
10206         FETCH g_c_alternate_code INTO g_v_fee_alt_code;
10207         CLOSE g_c_alternate_code;
10208 
10209         log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10210                     p_v_string => 'Load Period: ' || g_v_load_cal_type || ', ' || g_n_load_seq_num );
10211 
10212 
10213 
10214         -- Note: There will always be a key program, if there are any records for this term.
10215         g_c_key_program := NULL;
10216         g_n_key_version := NULL;
10217         OPEN c_key_program ( p_person_id,
10218                              g_v_load_cal_type,
10219                              g_n_load_seq_num,
10220                              'Y' );
10221         FETCH c_key_program INTO g_c_key_program, g_n_key_version;
10222         CLOSE c_key_program;
10223         log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10224                     p_v_string => 'Key Program Derived: ' || g_c_key_program || ', ' || g_n_key_version );
10225 
10226         -- If fee category is provided, Check if there exists any Active FCCIs as on Process Effective Date.
10227         IF (p_fee_category IS NOT NULL) THEN
10228           log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10229                       p_v_string => 'Checking if there exists any Active FCCIs as on Process Effective Date.' );
10230           OPEN c_fcci_fss(p_effective_dt);
10231           FETCH c_fcci_fss INTO v_fee_cat;
10232           IF (c_fcci_fss%NOTFOUND) THEN
10233             CLOSE   c_fcci_fss;
10234             v_message_name := 'IGS_FI_FEECAT_NOACTIVE_FEEASS';
10235             IF (p_trace_on = 'Y') THEN
10236               fnd_message.set_name ( 'IGS', v_message_name);
10237               fnd_file.put_line (fnd_file.log, fnd_message.get);
10238             END IF;
10239             -- call proc to save traces
10240             p_message_name := v_message_name;
10241             log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10242                         p_v_string => 'Returning from finp_ins_enr_fee_ass with message ' || p_message_name );
10243             RETURN TRUE;
10244           END IF;
10245           CLOSE   c_fcci_fss;
10246         END IF;
10247 
10248         -- Obtain the value of the profile 'IGS: Charge tuition for Audited Student Attempt'
10249         -- If this is not defined, then log error message
10250         g_v_include_audit := fnd_profile.value('IGS_FI_CHARGE_AUDIT_FEES');
10251         IF g_v_include_audit IS NULL THEN
10252           v_message_name := 'IGS_FI_SP_FEE_NO_PROFILE';
10253           IF (p_trace_on = 'Y') THEN
10254             fnd_message.set_name ( 'IGS', v_message_name);
10255             fnd_file.put_line (fnd_file.log, fnd_message.get);
10256           END IF;
10257           -- call proc to save traces
10258           p_message_name := v_message_name;
10259           log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10260                       p_v_string => 'Returning from finp_ins_enr_fee_ass with message ' || p_message_name );
10261           RETURN FALSE;
10262         ELSE
10263           log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10264                       p_v_string => 'Value of Profile IGS_FI_SP_FEE_NO_PROFILE: ' || g_v_include_audit );
10265         END IF;
10266 
10267         -- Check if Census Date Alias setup is complete. If Yes, derive it into g_d_ld_census_val
10268         log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10269                     p_v_string => 'Checking Census date setup by calling check_census_dt_setup.' );
10270         check_census_dt_setup ( p_v_predictive_mode => g_c_predictive_ind,
10271                                 p_v_load_cal_type   => g_v_load_cal_type,
10272                                 p_n_load_ci_seq_number => g_n_load_seq_num,
10273                                 p_d_cns_dt_als_val  => g_d_ld_census_val,
10274                                 p_b_return_status   => l_b_return_status,
10275                                 p_v_message_name    => l_v_message_name );
10276         log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10277                     p_v_string => 'After check_census_dt_setup, Derived Census Date: ' || TO_CHAR(g_d_ld_census_val, 'DD-MON-YYYY') );
10278         IF l_b_return_status = FALSE THEN
10279           p_message_name := l_v_message_name;
10280           IF (p_trace_on = 'Y' AND l_v_message_name IS NOT NULL ) THEN
10281             fnd_message.set_name( 'IGS', l_v_message_name );
10282             IF l_v_message_name = 'IGS_FI_NO_CENSUS_DT_SETUP' THEN
10283               fnd_message.set_token('ALT_CD', g_v_load_alt_code );
10284             END IF;
10285             fnd_file.put_line (fnd_file.log, fnd_message.get);
10286           END IF;
10287           log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10288                       p_v_string => 'Error in check_census_dt_setup: ' || l_v_message_name );
10289           RETURN FALSE;
10290         END IF;
10291 
10292         -- Fee Calc Method: PROGRAM
10293         --                    -- Identify All Valid Program Attempts from Terms table.
10294         --                  CAREER
10295         --                    -- All Primary Programs. (Note: Terms table will have only Primary Programs when CAREER)
10296         --                  PRIMARY_CAREER
10297         --                    -- Only Key Program is identified for Assessment.
10298 
10299           v_record_found := FALSE;
10300 
10301             IF (p_trace_on = 'Y') THEN
10302                fnd_file.new_line(fnd_file.log);
10303                OPEN cur_person_name(p_person_id);
10304                FETCH cur_person_name INTO l_v_person_name;
10305                CLOSE cur_person_name;
10306                fnd_file.put_line( fnd_file.log, RPAD('-', '79', '-') );
10307                fnd_message.set_name('IGS', 'IGS_FI_PERSON_NUM');
10308                fnd_message.set_token('PERSON_NUM', g_v_person_number);
10309                fnd_file.put_line (fnd_file.log, fnd_message.get);
10310                fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_HOLDS', 'PERSON_NAME') || ': ' || l_v_person_name);
10311             END IF;
10312 
10313             tbl_wav_fcfl.DELETE;
10314 
10315           -- ACTUAL Mode processing.
10316           IF g_c_predictive_ind = 'N' THEN
10317 
10318             log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10319                         p_v_string => 'ACTUAL Mode: Looping Across Student Program Attempts from TERMS Table.' );
10320             -- Loop accross all programs for the student in context and for the given term period.
10321             FOR rec_scas IN c_scas ( p_person_id,
10322                                      g_v_load_cal_type,
10323                                      g_n_load_seq_num,
10324                                      p_course_cd,
10325                                      p_fee_category,
10326                                      p_c_career,
10327                                      'Y',
10328                                      'CRS_ATTEMPT_STATUS',
10329                                      'Y' ) LOOP
10330               v_record_found := TRUE;
10331               l_fee_category := rec_scas.fee_cat;
10332 
10333               -- If Fee Category is not specified for the SPA, error out.
10334               IF l_fee_category IS NULL THEN
10335                  log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10336                              p_v_string => 'Fee Category at SPA level (rec_scas.fee_cat) is Null, so log message and abort.');
10337                  fnd_message.set_name ( 'IGS', 'IGS_FI_NO_SPA_FEE_CAT');
10338                  fnd_message.set_token('PROG_ATT', rec_scas.program_cd);
10339                  --Bug 4735807,If this is called from Concurrent Manager
10340                  IF fnd_global.conc_request_id <> -1 THEN
10341                    fnd_file.new_line(fnd_file.log);
10342                    fnd_file.put_line(fnd_file.log,fnd_message.get);
10343                  ELSE
10344                    -- This is called from Self-Service Package. Return FALSE so that this message is shown on page.
10345                    p_message_name := 'IGS_FI_NO_SPA_FEE_CAT';
10346                    igs_ge_msg_stack.ADD;
10347                  END IF;
10348                  RETURN FALSE;
10349               END IF;
10350 
10351               IF (p_trace_on = 'Y') THEN
10352                 fnd_file.new_line(fnd_file.log);
10353                 fnd_message.set_name ( 'IGS', 'IGS_FI_MAJOR_PRGLOC_USED');
10354                 fnd_message.set_token('PROG', rec_scas.program_cd);
10355                 fnd_message.set_token('VER', TO_CHAR(rec_scas.program_version));
10356                 fnd_file.put_line (fnd_file.log, fnd_message.get);
10357                 fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'TITLE') || ': ' || rec_scas.short_title);
10358                 fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'STATUS') || ': ' || igs_fi_gen_gl.get_lkp_meaning('VS_EN_COURSE_ATMPT_STATUS', rec_scas.course_attempt_status));
10359                 fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'START_DT') || ': ' || TO_CHAR(rec_scas.commencement_dt, 'DD/MM/YYYY'));
10360                 fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'FEE_CAT') || ': ' || l_fee_category);
10361                 fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_ACCT_ENTITIES', 'LOC') || ': ' || rec_scas.location_cd);
10362                 fnd_message.set_name ( 'IGS', 'IGS_FI_DER_ATT_TYPE_GOVT_MODE');
10363                 fnd_message.set_token('ATT_MODE', rec_scas.attendance_mode);
10364                 fnd_file.put_line (fnd_file.log, fnd_message.get);
10365                 fnd_message.set_name ( 'IGS', 'IGS_FI_ATTTYPE_GOVT_ATTMODE');
10366                 fnd_message.set_token('ATT_TYPE', rec_scas.attendance_type);
10367                 fnd_file.put_line (fnd_file.log, fnd_message.get);
10368                 fnd_message.set_name ( 'IGS', 'IGS_FI_NO_KEY_PROGRAM');
10369                 fnd_message.set_token('YES_NO', rec_scas.key_program_flag);
10370                 fnd_file.put_line (fnd_file.log, fnd_message.get);
10371               END IF;
10372 
10373               -- Process Fee Category Fee Liabilities
10374 
10375               -- GL Interface Build, check if currency code that is attached at the Fee Category Level is same
10376               -- as the currency code that is set at the System Options Level. If not, proceed with next Program Attempt.
10377               OPEN cur_fee_cat_curr(l_fee_category);
10378               FETCH cur_fee_cat_curr INTO l_cur_fee_cat_curr;
10379               CLOSE cur_fee_cat_curr;
10380 
10381               IF (l_cur_fee_cat_curr.currency_cd <> l_c_control_curr OR l_cur_fee_cat_curr.currency_cd IS NULL)  THEN
10382                 IF (p_trace_on = 'Y') THEN
10383                   fnd_file.new_line(fnd_file.log);
10384                   fnd_message.set_name ( 'IGS', 'IGS_FI_INVALID_CURR_CODE');
10385                   fnd_file.put_line (fnd_file.log, fnd_message.get);
10386                   fnd_message.set_name('IGS', 'IGS_FI_INV_FEE_CAT_CURR_CODE');
10387                   fnd_message.set_token('CUR_CODE1', l_cur_fee_cat_curr.currency_cd );
10388                   fnd_message.set_token('FEE_CAT', RTRIM(l_fee_category) );
10389                   fnd_message.set_token('CUR_CODE2', l_c_control_curr );
10390                   fnd_file.put_line (fnd_file.log, fnd_message.get);
10391                   log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10392                               p_v_string => 'Currency at Fee Cat is Invalid. Sys Opt Level: ' || l_c_control_curr || ', Fee Cat Level: ' || l_cur_fee_cat_curr.currency_cd );
10393                 END IF;
10394               ELSE
10395                        log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10396                                    p_v_string => 'Calling finpl_prc_fee_cat_fee_liab' );
10397 
10398                        IF (finpl_prc_fee_cat_fee_liab(p_effective_dt          => p_effective_dt,
10399                                                       p_trace_on              => p_trace_on,
10400                                                       p_fee_cal_type          => p_fee_cal_type,
10401                                                       p_fee_ci_sequence_num   => p_fee_ci_sequence_num,
10402                                                       p_local_currency        => l_c_control_curr,
10403                                                       p_fee_cat               => l_fee_category,
10404                                                       p_person_id             => rec_scas.person_id,
10405                                                       p_course_cd             => rec_scas.program_cd,
10406                                                       p_course_version_number => rec_scas.program_version,
10407                                                       p_cal_type              => rec_scas.cal_type,
10408                                                       p_scahv_location_cd     => rec_scas.location_cd,
10409                                                       p_scahv_attendance_mode => rec_scas.attendance_mode,
10410                                                       p_scahv_attendance_type => rec_scas.attendance_type,
10411                                                       p_discontinued_dt       => rec_scas.discontinued_dt,
10412                                                       p_course_attempt_status => rec_scas.course_attempt_status,
10413                                                       p_message_name          => p_message_name,
10414                                                       p_process_mode          => p_process_mode,
10415                                                       p_c_career              => rec_scas.course_type,
10416                                                       p_waiver_call_ind       => 'N',
10417                                                       p_target_fee_type       => NULL) = FALSE ) THEN
10418                              log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10419                                          p_v_string => 'finpl_prc_fee_cat_fee_liab returned FALSE. Returning from finp_ins_enr_fee_ass.' );
10420                              RETURN FALSE;
10421                        END IF;
10422 
10423               END IF; /* Check for Fee Category */
10424             END LOOP; /* c_scas, Loop across programs */
10425 
10426             IF p_v_wav_calc_flag = 'N' THEN
10427                IF (p_fee_category IS NOT NULL OR  p_course_cd IS NOT NULL OR p_c_career IS NOT NULL) THEN
10428                  FOR i IN 1..tbl_wav_fcfl.COUNT
10429                  LOOP
10430                    IF tbl_wav_fcfl.EXISTS(i) THEN
10431                        FOR rec_spa IN cur_spa ( p_person_id,
10432                                             g_v_load_cal_type,
10433                                             g_n_load_seq_num,
10434                                             'Y',
10435                                             p_c_career,
10436                                             'CRS_ATTEMPT_STATUS',
10437                                             'Y',
10438                                             tbl_wav_fcfl(i).p_fee_category )
10439                        LOOP
10440                           -- If Fee Category is not specified for the SPA, error out.
10441                           IF rec_spa.fee_cat IS NULL THEN
10442                               log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10443                                           p_v_string => 'Waiver Processing: Fee Category at SPA level is Null, so log message and abort.');
10444                               fnd_message.set_name ( 'IGS', 'IGS_FI_NO_SPA_FEE_CAT');
10445                               fnd_message.set_token('PROG_ATT', rec_spa.program_cd);
10446                               fnd_file.new_line(fnd_file.log);
10447                               fnd_file.put_line(fnd_file.log,fnd_message.get);
10448                               RETURN FALSE;
10449                           END IF;
10450 
10451                          IF NOT((p_fee_category IS NOT NULL AND p_fee_category = rec_spa.fee_cat)
10452                              OR (p_course_cd IS NOT NULL AND p_course_cd = rec_spa.program_cd)
10453                              OR (p_c_career IS NOT NULL AND p_c_career = rec_spa.course_type)) THEN
10454                              -- Log the Program Details
10455                              IF (p_trace_on = 'Y') THEN
10456                                fnd_file.new_line(fnd_file.log);
10457                                fnd_message.set_name ( 'IGS', 'IGS_FI_MAJOR_PRGLOC_USED');
10458                                fnd_message.set_token('PROG', rec_spa.program_cd);
10459                                fnd_message.set_token('VER', TO_CHAR(rec_spa.program_version));
10460                                fnd_file.put_line (fnd_file.log, fnd_message.get);
10461                                fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'TITLE') || ': ' || rec_spa.short_title);
10462                                fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'STATUS') || ': ' || igs_fi_gen_gl.get_lkp_meaning('VS_EN_COURSE_ATMPT_STATUS', rec_spa.course_attempt_status));
10463                                fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'START_DT') || ': ' || TO_CHAR(rec_spa.commencement_dt, 'DD/MM/YYYY'));
10464                                fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'FEE_CAT') || ': ' || rec_spa.fee_cat);
10465                                fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_ACCT_ENTITIES', 'LOC') || ': ' || rec_spa.location_cd);
10466                                fnd_message.set_name ( 'IGS', 'IGS_FI_DER_ATT_TYPE_GOVT_MODE');
10467                                fnd_message.set_token('ATT_MODE', rec_spa.attendance_mode);
10468                                fnd_file.put_line (fnd_file.log, fnd_message.get);
10469                                fnd_message.set_name ( 'IGS', 'IGS_FI_ATTTYPE_GOVT_ATTMODE');
10470                                fnd_message.set_token('ATT_TYPE', rec_spa.attendance_type);
10471                                fnd_file.put_line (fnd_file.log, fnd_message.get);
10472                                fnd_message.set_name ( 'IGS', 'IGS_FI_NO_KEY_PROGRAM');
10473                                fnd_message.set_token('YES_NO', rec_spa.key_program_flag);
10474                                fnd_file.put_line (fnd_file.log, fnd_message.get);
10475                              END IF;
10476 
10477                             -- Validate Currency against the currency setup in System Options
10478                             OPEN cur_fee_cat_curr(rec_spa.fee_cat);
10479                             FETCH cur_fee_cat_curr INTO l_v_currency_cd;
10480                             CLOSE cur_fee_cat_curr;
10481                             IF (l_v_currency_cd <> l_c_control_curr OR l_v_currency_cd IS NULL)  THEN
10482                               IF (p_trace_on = 'Y') THEN
10483                                 fnd_file.new_line(fnd_file.log);
10484                                 fnd_message.set_name ( 'IGS', 'IGS_FI_INVALID_CURR_CODE');
10485                                 fnd_file.put_line (fnd_file.log, fnd_message.get);
10486                                 fnd_message.set_name('IGS', 'IGS_FI_INV_FEE_CAT_CURR_CODE');
10487                                 fnd_message.set_token('CUR_CODE1', l_v_currency_cd );
10488                                 fnd_message.set_token('FEE_CAT', RTRIM(rec_spa.fee_cat) );
10489                                 fnd_message.set_token('CUR_CODE2', l_c_control_curr );
10490                                 fnd_file.put_line (fnd_file.log, fnd_message.get);
10491                                 log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10492                                             p_v_string => 'Waiver Procesing: Currency at Fee Cat is Invalid. Sys Opt Level: ' || l_c_control_curr
10493                                                           || ', Fee Cat Level: ' || l_v_currency_cd );
10494                               END IF;
10495                             ELSE
10496                                log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10497                                            p_v_string => 'Waiver Processing: Calling finpl_prc_fee_cat_fee_liab' );
10498 
10499                                 IF (finpl_prc_fee_cat_fee_liab ( p_effective_dt          => p_effective_dt,
10500                                                       p_trace_on              => p_trace_on,
10501                                                       p_fee_cal_type          => p_fee_cal_type,
10502                                                       p_fee_ci_sequence_num   => p_fee_ci_sequence_num,
10503                                                       p_local_currency        => l_v_currency_cd,
10504                                                       p_fee_cat               => rec_spa.fee_cat,
10505                                                       p_person_id             => rec_spa.person_id,
10506                                                       p_course_cd             => rec_spa.program_cd,
10507                                                       p_course_version_number => rec_spa.program_version,
10508                                                       p_cal_type              => rec_spa.cal_type,
10509                                                       p_scahv_location_cd     => rec_spa.location_cd,
10510                                                       p_scahv_attendance_mode => rec_spa.attendance_mode,
10511                                                       p_scahv_attendance_type => rec_spa.attendance_type,
10512                                                       p_discontinued_dt       => rec_spa.discontinued_dt,
10513                                                       p_course_attempt_status => rec_spa.course_attempt_status,
10514                                                       p_message_name          => l_v_message_name,
10515                                                       p_process_mode          => p_process_mode,
10516                                                       p_c_career              => rec_spa.course_type,
10517                                                       p_waiver_call_ind       => 'Y',
10518                                                       p_target_fee_type       => tbl_wav_fcfl(i).p_fee_type ) = TRUE ) THEN
10519                                   log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10520                                               p_v_string => 'Waiver Processing: finpl_prc_fee_cat_fee_liab returned true' );
10521                                ELSE
10522                                  log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10523                                              p_v_string => 'Waiver Processing: finpl_prc_fee_cat_fee_liab returned false' );
10524                                END IF;
10525                             END IF;
10526                             END IF;  -- End if for check on p_fee_category and p_course_cd
10527                        END LOOP; -- End loop for cur_spa
10528                    END IF;
10529                  END LOOP;  -- End loop for tbl_wav_fcfl
10530                END IF;  -- End if for (p_fee_category IS NOT NULL OR  p_course_cd IS NOT NULL)
10531             END IF;
10532 
10533           ELSE  -- Predictive Mode of processing.
10534 
10535             l_b_recs_found := FALSE;
10536             l_b_ret_status := FALSE;
10537             log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10538                         p_v_string => 'PREDICTIVE Mode: Calling finpl_prc_predictive_scas.' );
10539             finpl_prc_predictive_scas ( p_n_person_id           => p_person_id,
10540                                             p_v_course_cd           => p_course_cd,
10541                                             p_v_career              => p_c_career,
10542                                             p_v_fee_category        => p_fee_category,
10543                                             p_v_fee_cal_type        => p_fee_cal_type,
10544                                             p_n_fee_ci_sequence_num => p_fee_ci_sequence_num,
10545                                             p_v_curr_cd             => l_c_control_curr,
10546                                             p_d_effective_date      => p_effective_dt,
10547                                             p_v_trace_on            => p_trace_on,
10548                                             p_b_record_found        => l_b_recs_found,
10549                                             p_v_message_name        => p_message_name,
10550                                             p_b_return_status       => l_b_ret_status,
10551                                             p_waiver_call_ind       => 'N',
10552                                             p_target_fee_type       => NULL );
10553             -- Assign l_b_recs_found to v_record_found so that proper message (IGS_FI_NO_STUDPRG_ATTEMPT) is logged if no records found.
10554             v_record_found := l_b_recs_found;
10555 
10556             IF l_b_ret_status = FALSE THEN
10557                 log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10558                             p_v_string => 'finpl_prc_predictive_scas returned FALSE. Returning from finp_ins_enr_fee_ass.' );
10559                 RETURN FALSE;
10560             ELSE
10561               IF p_v_wav_calc_flag = 'N' THEN
10562                  IF (p_fee_category IS NOT NULL OR  p_course_cd IS NOT NULL OR p_c_career IS NOT NULL) THEN
10563                     --- Loop across the PLSQL table to assess fees in entirety
10564                     FOR i IN 1..tbl_wav_fcfl.COUNT
10565                     LOOP
10566                       IF tbl_wav_fcfl.EXISTS(i) THEN
10567                           log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10568                                       p_v_string => 'PREDICTIVE Mode: Waiver Processing - Calling finpl_prc_predictive_scas.' );
10569                            -- If the SPA has already been assessed, then skip it. Else invoke Predictive processing again.
10570                            IF ((p_fee_category IS NOT NULL AND p_fee_category = tbl_wav_fcfl(i).p_fee_category)
10571                                 OR (p_course_cd IS NOT NULL AND p_course_cd = tbl_wav_fcfl(i).p_course_cd)
10572                                 OR (p_c_career IS NOT NULL AND p_c_career = tbl_wav_fcfl(i).p_career)) THEN
10573                                 NULL;
10574                            ELSE
10575                                 finpl_prc_predictive_scas ( p_n_person_id           => p_person_id,
10576                                               p_v_course_cd           => NULL,
10577                                               p_v_career              => NULL,
10578                                               p_v_fee_category        => tbl_wav_fcfl(i).p_fee_category,
10579                                               p_v_fee_cal_type        => p_fee_cal_type,
10580                                               p_n_fee_ci_sequence_num => p_fee_ci_sequence_num,
10581                                               p_v_curr_cd             => l_c_control_curr,
10582                                               p_d_effective_date      => p_effective_dt,
10583                                               p_v_trace_on            => p_trace_on,
10584                                               p_b_record_found        => l_b_recs_found,
10585                                               p_v_message_name        => p_message_name,
10586                                               p_b_return_status       => l_b_ret_status,
10587                                               p_waiver_call_ind       => 'Y',
10588                                               p_target_fee_type       => tbl_wav_fcfl(i).p_fee_type );
10589                                 IF (l_b_ret_status = FALSE) THEN
10590                                       log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10591                                                   p_v_string => 'Waiver Processing: finpl_prc_predictive_scas returned FALSE. Returning from finp_ins_enr_fee_ass.' );
10592                                       RETURN FALSE;
10593                                 END IF;
10594                            END IF;  -- End if for NOT condition
10595                       END IF;  -- End if for tbl_wav_fcfl.EXISTS(i)
10596                     END LOOP;
10597                  END IF;  -- End if for (p_fee_category IS NOT NULL OR  p_course_cd IS NOT NULL)
10598               END IF;  -- End if for ( p_v_wav_calc_flag = 'N' )
10599             END IF;  -- End if for l_b_ret_status = FALSE
10600           END IF; /* Predictive Mode = 'N' */
10601 
10602         IF v_record_found = FALSE THEN
10603           v_message_name := 'IGS_FI_NO_STUDPRG_ATTEMPT';
10604           IF (p_trace_on = 'Y') THEN
10605             fnd_message.set_name ( 'IGS', v_message_name);
10606             fnd_file.put_line (fnd_file.log, fnd_message.get);
10607           END IF;
10608           log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10609                       p_v_string => 'No Program Attempt Found. Returning from finp_ins_enr_fee_ass with message ' || v_message_name );
10610         ELSE
10611 
10612           -- If invoked for Waiver Amount calculation only, then it need not process the remaining part
10613           -- The OUT param, p_n_waiver_amount, has been assigned the appropriate value in finp_clc_ass_amnt
10614           -- So, return TRUE from here.
10615           IF  p_v_wav_calc_flag = 'Y' THEN
10616               log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10617                           p_v_string => 'Invoked from Waiver Logic, so return TRUE without doing COMMIT or ROLLBACK');
10618               RETURN TRUE;
10619           END IF;
10620 
10621           -- If the Auto Calculation of Waivers profile is set to Yes and this is invoked by the normal
10622           -- run of Fee Calc, then proceed.
10623           IF (g_v_auto_calc_wav_prof = 'Y' AND p_v_wav_calc_flag = 'N' ) THEN
10624 
10625             -- For Waivers, raise Workflow event only if the process is run with Test Run = No.
10626             -- For Test Run mode, do not raise Workflow event.
10627             IF p_test_run = 'N' THEN
10628                l_v_raise_wf_event := 'Y';
10629             ELSE
10630                l_v_raise_wf_event := 'N';
10631             END IF;
10632 
10633             log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10634                         p_v_string => 'Before looping across tbl_wav_fcfl');
10635             FOR i IN 1..tbl_wav_fcfl.COUNT
10636             LOOP
10637               l_b_found := FALSE;
10638               FOR j IN 1..tbl_fee_type.COUNT
10639               LOOP
10640                 IF (tbl_wav_fcfl(i).p_fee_type = tbl_fee_type(j)) THEN
10641                   l_b_found := TRUE;
10642                   EXIT;
10643                 END IF;
10644               END LOOP;
10645               IF (l_b_found = FALSE) THEN
10646                 tbl_fee_type(tbl_fee_type.COUNT + 1) := tbl_wav_fcfl(i).p_fee_type;
10647               END IF;
10648             END LOOP;
10649 
10650             l_v_err_msg := NULL;
10651             log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10652                         p_v_string => 'Waiver Processing: calling igs_fi_prc_waivers.create_waivers for '||tbl_fee_type.COUNT||' record(s)');
10653             FOR i IN 1..tbl_fee_type.COUNT
10654             LOOP
10655               -- Invoke  Waiver API to calculate waiver, always in ACTUAL mode irrespective of the mode Fee Calc is run in
10656               igs_fi_prc_waivers.create_waivers( p_n_person_id          => p_person_id,
10657                                                  p_v_fee_type           => tbl_fee_type(i),
10658                                                  p_v_fee_cal_type       => p_fee_cal_type,
10659                                                  p_n_fee_ci_seq_number  => p_fee_ci_sequence_num,
10660                                                  p_v_waiver_name        => NULL,
10661                                                  p_v_currency_cd        => l_c_control_curr,
10662                                                  p_d_gl_date            => p_d_gl_date,
10663                                                  p_v_real_time_flag     => g_v_auto_calc_wav_prof,
10664                                                  p_v_process_mode       => 'ACTUAL',
10665                                                  p_v_career             => p_c_career,
10666                                                  p_b_init_msg_list      => TRUE,
10667                                                  p_validation_level     => 0,
10668                                                  p_v_raise_wf_event     => l_v_raise_wf_event,
10669                                                  x_waiver_amount        => l_n_waiver_amount,
10670                                                  x_return_status        => l_v_return_status,
10671                                                  x_msg_count            => l_n_msg_count,
10672                                                  x_msg_data             => l_v_msg_data );
10673               IF l_v_return_status = 'S' THEN
10674                   l_n_sum_waiver_amount := NVL(l_n_sum_waiver_amount,0) + NVL(l_n_waiver_amount,0);
10675                   log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10676                               p_v_string => 'Waiver Processing: Waiver Amount '||i||': '||NVL(l_n_waiver_amount,0));
10677               ELSE
10678                   l_n_sum_waiver_amount := 0;
10679                   log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10680                               p_v_string => 'Waiver Processing: Error: Message Count - '||NVL(l_n_msg_count,0)||' Message Data: '||l_v_msg_data);
10681                   IF (p_trace_on = 'Y') THEN
10682                      IF l_n_msg_count = 1 THEN
10683                         fnd_message.set_encoded(l_v_msg_data);
10684                         fnd_file.put_line(fnd_file.log,fnd_message.get);
10685                      ELSIF l_n_msg_count > 1 THEN
10686                         FOR l_n_count IN 1..l_n_msg_count LOOP
10687                             l_v_err_msg := fnd_msg_pub.get(p_msg_index => l_n_count, p_encoded => 'T');
10688                             fnd_message.set_encoded(l_v_err_msg);
10689                             fnd_file.put_line(fnd_file.log,fnd_message.get);
10690                         END LOOP;
10691                      END IF;
10692                   END IF;  -- End if for p_trace_on
10693               END IF;
10694             END LOOP;
10695 
10696             -- Setting the Global Parameter, g_v_wav_calc_flag to N as part Bug# 4634950
10697             -- When the Fee Assessment is submitted and before calling the create_waivers procedure the value of variable, g_v_wav_calc_flag is N.
10698             -- But after the completion of create_waivers this parameter is set 'Y' as create_waivers internally call the Fee Assessment process
10699             g_v_wav_calc_flag := 'N';
10700 
10701             IF (p_trace_on = 'Y') THEN
10702                 fnd_file.put_line(fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX','WAIVER_AMOUNT')||': '||NVL(l_n_sum_waiver_amount,0));
10703                 fnd_file.new_line(fnd_file.log);
10704             END IF;
10705 
10706           END IF;
10707         END IF;
10708 
10709         IF (p_test_run = 'N') THEN
10710           log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10711                       p_v_string => 'Test Run: No, so issuing COMMIT');
10712           COMMIT;
10713         ELSE
10714           log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10715                       p_v_string => 'Test Run: Yes, so issuing ROLLBACK till savepoint fee_calc_sp');
10716 
10717           -- Rollback is not required in case the Fee Assessment is called from Tuition Waivers,
10718           -- since all the insertion/updation operations are performed in procedure finpl_ins_fee_ass and
10719           -- this procedure would be bypassed for Tuition Waivers functionality. Ref Bug# 4639869
10720           IF g_v_wav_calc_flag = 'N' THEN
10721             ROLLBACK TO fee_calc_sp;
10722           END IF;
10723 
10724         END IF;
10725 
10726         p_message_name := NULL;
10727 
10728         log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10729                     p_v_string => 'Finished the Processing Successfully. OUT Variables: Creation Date: '
10730                                   || TO_CHAR(p_creation_dt, 'DD-MON-YYYY HH24:MI:SS') || ', Message: ' || p_message_name);
10731 
10732         RETURN TRUE;
10733 
10734     EXCEPTION
10735         WHEN e_one_record_expected THEN
10736                 log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10737                             p_v_string => 'In Exception Handler of e_one_record_expected.' );
10738                 fnd_message.set_name ('IGS', 'IGS_GE_UNHANDLED_EXP');
10739                 fnd_message.set_token('NAME','IGS_FI_PRC_FEE_ASS.FINP_INS_ENR_FEE_ASS-'||SUBSTR(SQLERRM,1,500));
10740                 igs_ge_msg_stack.add;
10741                 app_exception.raise_exception(NULL, NULL, fnd_message.get);
10742         WHEN OTHERS THEN
10743                 log_to_fnd( p_v_module => 'finp_ins_enr_fee_ass',
10744                             p_v_string => 'In Exception Handler WHEN OTHERS.' );
10745                 fnd_message.set_name ('IGS', 'IGS_GE_UNHANDLED_EXP');
10746                 fnd_message.set_token('NAME','IGS_FI_PRC_FEE_ASS.FINP_INS_ENR_FEE_ASS-'||SUBSTR(SQLERRM,1,500));
10747                 igs_ge_msg_stack.add;
10748                 app_exception.raise_exception;
10749         END ;
10750     END finp_ins_enr_fee_ass;
10751 
10752 FUNCTION finpl_insert_record(p_n_person_id                 IN igs_fi_fee_as_all.person_id%TYPE,
10753                              p_v_course_cd                 IN igs_ps_ver_all.course_cd%TYPE,
10754                              p_v_fee_cal_type              IN igs_fi_fee_as_all.fee_cal_type%TYPE,
10755                              p_n_fee_ci_sequence_number    IN igs_fi_fee_as_all.fee_ci_sequence_number%TYPE)
10756 RETURN BOOLEAN
10757 IS
10758 PRAGMA AUTONOMOUS_TRANSACTION;
10759 /*************************************************************
10760  Created By : Priya Athipatla
10761  Date Created By : 01-Jul-2004
10762  Purpose : Function inserts records into table IGS_FI_SPA_FEE_PRDS
10763            if such a record doesnt exist already. Invoked from
10764            finpl_lock_records().
10765 
10766            Returns TRUE if insertion was successful, FALSE otherwise.
10767 
10768  Know limitations, enhancements or remarks
10769  Change History
10770  Who            When        What
10771  akandreg       24-Apr-2006  Bug 5134627 - Modified TBH callout to pass value for TRANSACTION_TYPE
10772 ***************************************************************/
10773 l_rowid                ROWID;
10774 
10775 BEGIN
10776 
10777    log_to_fnd( p_v_module => 'finpl_insert_record',
10778                    p_v_string => 'Proceeding to insert an Assessment record into IGS_FI_SPA_FEE_PRDS' );
10779 
10780    l_rowid := NULL;
10781    igs_fi_spa_fee_prds_pkg.insert_row ( x_rowid                   => l_rowid,
10782                                         x_person_id               => p_n_person_id,
10783                                         x_course_cd               => p_v_course_cd,
10784                                         x_fee_cal_type            => p_v_fee_cal_type,
10785                                         x_fee_ci_sequence_number  => p_n_fee_ci_sequence_number,
10786                                         x_mode                    => 'R',
10787                                         x_transaction_type        => 'ASSESSMENT'
10788                                       );
10789    COMMIT;
10790    log_to_fnd( p_v_module => 'finpl_insert_record',
10791                p_v_string => 'Record inserted into IGS_FI_SPA_FEE_PRDS, Commit successful, Return TRUE' );
10792 
10793    RETURN TRUE;
10794 
10795 EXCEPTION
10796   WHEN OTHERS THEN
10797      log_to_fnd( p_v_module => 'finpl_insert_record',
10798                  p_v_string => 'Exception section of finpl_insert_record : '||SQLERRM );
10799      IF g_v_wav_calc_flag = 'N' THEN
10800        ROLLBACK TO fee_calc_sp;
10801      END IF;
10802 
10803      RETURN FALSE;
10804 
10805 END finpl_insert_record;
10806 
10807 
10808 FUNCTION  finpl_lock_records(p_n_person_id                 IN igs_fi_fee_as_all.person_id%TYPE,
10809                              p_v_course_cd                 IN igs_ps_ver_all.course_cd%TYPE,
10810                              p_v_fee_cal_type              IN igs_fi_fee_as_all.fee_cal_type%TYPE,
10811                              p_n_fee_ci_sequence_number    IN igs_fi_fee_as_all.fee_ci_sequence_number%TYPE)
10812 RETURN BOOLEAN IS
10813 /*************************************************************
10814  Created By : Priya Athipatla
10815  Date Created By : 01-Jul-2004
10816  Purpose : This function locks the record in the table IGS_FI_SPA_FEE_PRDS
10817            based on the combination of Person-Course-Fee Period that is
10818            passed as the input parameters. Added as a fix to prevent
10819            concurrent running of multiple instances of the process.
10820 
10821            Returns TRUE if locking was successful, FALSE otherwise.
10822 
10823  Know limitations, enhancements or remarks
10824  Change History
10825  Who            When        What
10826  akandreg       31-May-2006 Bug 5134636 - Modified cur_fee_spa to add check on TRANSACTION_TYPE
10827 ***************************************************************/
10828 
10829 CURSOR cur_fee_spa (cp_person_id               igs_fi_spa_fee_prds.person_id%TYPE,
10830                     cp_course_cd               igs_fi_spa_fee_prds.course_cd%TYPE,
10831                     cp_fee_cal_type            igs_fi_spa_fee_prds.fee_cal_type%TYPE,
10832                     cp_fee_ci_sequence_number  igs_fi_spa_fee_prds.fee_ci_sequence_number%TYPE,
10833                     cp_transaction_type        igs_fi_spa_fee_prds.transaction_type%TYPE) IS
10834   SELECT 'x'
10835   FROM igs_fi_spa_fee_prds
10836   WHERE person_id = cp_person_id
10837   AND course_cd = cp_course_cd
10838   AND fee_cal_type = cp_fee_cal_type
10839   AND fee_ci_sequence_number = cp_fee_ci_sequence_number
10840   AND transaction_type = cp_transaction_type
10841   FOR UPDATE NOWAIT;
10842 
10843 l_v_dummy  VARCHAR2(2) := NULL;   -- Dummy variable to hold the value selected in cur_fee_spa
10844 
10845 BEGIN
10846 
10847    log_to_fnd( p_v_module => 'finpl_lock_records',
10848                p_v_string => 'Checking if record already exists in IGS_FI_SPA_FEE_PRDS to lock' );
10849 
10850    OPEN cur_fee_spa(p_n_person_id,
10851                     p_v_course_cd,
10852                     p_v_fee_cal_type,
10853                     p_n_fee_ci_sequence_number,
10854                     'ASSESSMENT');
10855    FETCH cur_fee_spa INTO l_v_dummy;
10856    IF cur_fee_spa%NOTFOUND THEN
10857        -- If the record does not exist in igs_fi_spa_fee_period table, then insert into the table.
10858        log_to_fnd( p_v_module => 'finpl_lock_records',
10859                    p_v_string => 'Record not present in IGS_FI_SPA_FEE_PRDS, so call finpl_insert_record' );
10860        CLOSE cur_fee_spa;
10861        -- Call autonomous function to insert into IGS_FI_SPA_FEE_PRDS
10862        IF finpl_insert_record(p_n_person_id,
10863                               p_v_course_cd,
10864                               p_v_fee_cal_type,
10865                               p_n_fee_ci_sequence_number) THEN
10866          -- After insertion (if insertion was successful), lock the record
10867          log_to_fnd( p_v_module => 'finpl_lock_records',
10868                      p_v_string => 'Insertion of record in IGS_FI_SPA_FEE_PRDS successful, lock and return TRUE');
10869          OPEN cur_fee_spa(p_n_person_id,
10870                           p_v_course_cd,
10871                           p_v_fee_cal_type,
10872                           p_n_fee_ci_sequence_number,
10873                           'ASSESSMENT');
10874          FETCH cur_fee_spa INTO l_v_dummy;
10875          CLOSE cur_fee_spa;
10876          RETURN TRUE;
10877        ELSE
10878          -- Insertion failed, return FALSE
10879          log_to_fnd( p_v_module => 'finpl_lock_records',
10880                      p_v_string => 'Insertion of record into IGS_FI_SPA_FEE_PRDS not successful, return FALSE');
10881          RETURN FALSE;
10882        END IF;
10883    ELSE
10884        -- If record exists in table igs_fi_spa_fee_period, then lock the record.
10885        CLOSE cur_fee_spa;
10886        log_to_fnd( p_v_module => 'finpl_lock_records',
10887                    p_v_string => 'Record exists in IGS_FI_SPA_FEE_PRDS, so lock and return TRUE');
10888        RETURN TRUE;
10889    END IF;  -- End if for cursor cur_fee_spa NOTFOUND
10890 
10891 EXCEPTION
10892   WHEN OTHERS THEN
10893      log_to_fnd( p_v_module => 'finpl_lock_records',
10894                  p_v_string => 'Exception section of finpl_lock_records : '||SQLERRM );
10895 
10896      IF g_v_wav_calc_flag = 'N' THEN
10897        ROLLBACK TO fee_calc_sp;
10898      END IF;
10899 
10900      RETURN FALSE;
10901 
10902 END finpl_lock_records;
10903 
10904 
10905 FUNCTION  finpl_check_header_lines(p_n_person_id       igs_fi_fee_as_all.person_id%TYPE,
10906                                    p_n_transaction_id  igs_fi_fee_as_all.transaction_id%TYPE)
10907 RETURN BOOLEAN IS
10908 /*************************************************************
10909  Created By : Priya Athipatla
10910  Date Created By : 01-Jul-2004
10911  Purpose : This function checks if a header in IGS_FI_FEE_AS and
10912            line records in IGS_FI_FEE_AS_ITEMS have been created
10913            correctly or not.
10914 
10915  Know limitations, enhancements or remarks
10916  Change History
10917  Who            When        What
10918 ***************************************************************/
10919 CURSOR cur_fee_as(cp_n_person_id        igs_fi_fee_as_all.person_id%TYPE,
10920                   cp_n_transaction_id   igs_fi_fee_as_all.transaction_id%TYPE) IS
10921   SELECT SUM(transaction_amount)
10922   FROM igs_fi_fee_as_all
10923   WHERE person_id = cp_n_person_id
10924   AND transaction_id = cp_n_transaction_id;
10925 
10926 CURSOR cur_fee_as_items(cp_n_person_id        igs_fi_fee_as_all.person_id%TYPE,
10927                         cp_n_transaction_id   igs_fi_fee_as_all.transaction_id%TYPE) IS
10928   SELECT amount
10929   FROM igs_fi_fee_as_items
10930   WHERE person_id = cp_n_person_id
10931   AND transaction_id = cp_n_transaction_id;
10932 
10933 l_n_lines_sum      NUMBER := 0.0;
10934 l_n_header_sum     NUMBER := 0.0;
10935 l_b_line_exists    BOOLEAN := FALSE;
10936 
10937 
10938 BEGIN
10939 
10940     log_to_fnd( p_v_module => 'finpl_check_header_lines',
10941                 p_v_string => 'Proceeding to check if header and lines are created correctly');
10942 
10943     -- Obtain total amount in IGS_FI_FEE_AS - the Header table
10944     OPEN cur_fee_as(p_n_person_id, p_n_transaction_id);
10945     FETCH cur_fee_as INTO l_n_header_sum;
10946     IF cur_fee_as%NOTFOUND THEN
10947        log_to_fnd( p_v_module => 'finpl_check_header_lines',
10948                    p_v_string => 'Record not found in IGS_FI_FEE_AS for Person ID: '||p_n_person_id||
10949                                  ' and Transaction ID: '||p_n_transaction_id||
10950                                  '. Returning FALSE');
10951        CLOSE cur_fee_as;
10952        RETURN FALSE;
10953     END IF;
10954     CLOSE cur_fee_as;
10955 
10956     -- Loop through Line records and obtain total amount in IGS_FI_FEE_AS_ITEMS
10957     FOR l_rec_fee_as_items IN cur_fee_as_items(p_n_person_id, p_n_transaction_id) LOOP
10958         l_b_line_exists := TRUE;
10959         -- 'Amount' is a Nullable column, so check for Null
10960         IF l_rec_fee_as_items.amount IS NULL THEN
10961            log_to_fnd( p_v_module => 'finpl_check_header_lines',
10962                        p_v_string => 'Amount in IGS_FI_FEE_AS_ITEMS is NULL for Person ID: '||p_n_person_id||
10963                                      ' and Transaction ID: '||p_n_transaction_id||
10964                                      '. Returning FALSE');
10965            RETURN FALSE;
10966         ELSE
10967            -- Sum of amounts
10968            l_n_lines_sum := l_n_lines_sum + l_rec_fee_as_items.amount;
10969         END IF;
10970     END LOOP;
10971 
10972     -- Check if atleast one line record was found in IGS_FI_FEE_AS_ITEMS for the given transaction
10973     IF NOT l_b_line_exists THEN
10974         log_to_fnd( p_v_module => 'finpl_check_header_lines',
10975                     p_v_string => 'Record not found in IGS_FI_FEE_AS_ITEMS for Person ID: '||p_n_person_id||
10976                                   ' and Transaction ID: '||p_n_transaction_id||'  Returning FALSE');
10977         RETURN FALSE;
10978     END IF;
10979 
10980     log_to_fnd( p_v_module => 'finpl_check_header_lines',
10981                 p_v_string => 'Header and Lines Amount for Person ID: '||p_n_person_id||
10982                               ' and Transaction ID: '||p_n_transaction_id||
10983                               '   Header Amount: '||l_n_header_sum||
10984                               '   Lines Amount: '||l_n_lines_sum);
10985 
10986     -- If there is any mismatch in the amounts in the Header and Lines tables, return FALSE
10987     IF (l_n_lines_sum <> l_n_header_sum) THEN
10988        log_to_fnd( p_v_module => 'finpl_check_header_lines',
10989                    p_v_string => 'Difference in Sum between Header and Lines for Person ID: '||p_n_person_id||
10990                                  ' and Transaction ID: '||p_n_transaction_id||
10991                                  '   Header Amount: '||l_n_header_sum||
10992                                  '   Lines Amount: '||l_n_lines_sum||
10993                                  '. Returning FALSE');
10994        RETURN FALSE;
10995     ELSE
10996       -- Header and Lines sum match, so return TRUE
10997        log_to_fnd( p_v_module => 'finpl_check_header_lines',
10998                    p_v_string => 'Header and Lines Amount match for Person ID: '||p_n_person_id||
10999                                  ' and Transaction ID: '||p_n_transaction_id||
11000                                  '   Header Amount: '||l_n_header_sum||
11001                                  '   Lines Amount: '||l_n_lines_sum||
11002                                  '. Returning TRUE');
11003        RETURN TRUE;
11004     END IF;
11005 
11006 END finpl_check_header_lines;
11007 
11008 PROCEDURE create_retention_charge( p_n_person_id               IN igs_fi_inv_int_all.person_id%TYPE,
11009                                    p_v_course_cd               IN igs_fi_inv_int_all.course_cd%TYPE,
11010                                    p_v_fee_cal_type            IN igs_fi_inv_int_all.fee_cal_type%TYPE,
11011                                    p_n_fee_ci_sequence_number  IN igs_fi_inv_int_all.fee_ci_sequence_number%TYPE,
11012                                    p_v_fee_type                IN igs_fi_inv_int_all.fee_type%TYPE,
11013                                    p_v_fee_cat                 IN igs_fi_inv_int_all.fee_cat%TYPE,
11014                                    p_d_gl_date                 IN igs_fi_invln_int_all.gl_date%TYPE,
11015                                    p_n_uoo_id                  IN igs_fi_invln_int_all.uoo_id%TYPE,
11016                                    p_n_amount                  IN igs_fi_inv_int_all.invoice_amount%TYPE,
11017                                    p_v_fee_type_desc           IN igs_fi_fee_type_all.description%TYPE,
11018                                    p_v_fee_trig_cat            IN igs_fi_fee_type_all.s_fee_trigger_cat%TYPE,
11019                                    p_trace_on                  IN VARCHAR2) AS
11020 /*************************************************************
11021  Created By : Priya Athipatla
11022  Date Created By : 07-Sep-2004
11023  Purpose : Procedure invoked to create a retention charge.
11024  Know limitations, enhancements or remarks
11025  Change History
11026  Who            When        What
11027  abshriva    24-May-2006    Bug 5204728: Introduced p_trace_on in parameter list.
11028  abshriva    12-May-2006    Bug 5217319: Amount Precision change, added API call to allow correct precison into DB
11029  bannamal    03-Jun-2005    Bug#3442712 Unit Level Fee Assessment Build. Modified the call
11030                             to igs_fi_fee_as_items_pkg.insert_row added new parameters
11031                             unit_type_id, unit_class, unit_mode and unit_level.
11032 
11033 ***************************************************************/
11034 
11035   -- Cursor to fetch the Fee Type Description
11036 
11037   l_rowid               ROWID := NULL;
11038   l_n_transaction_id    igs_fi_fee_as_all.transaction_id%TYPE := NULL;
11039   l_v_fee_cat           igs_fi_fee_as_all.fee_cat%TYPE := NULL;
11040   l_v_course_cd         igs_fi_fee_as_all.course_cd%TYPE := NULL;
11041   l_n_invoice_id        igs_fi_inv_int_all.invoice_id%TYPE    := NULL;
11042   l_n_fee_ass_item_id   igs_fi_fee_as_items.fee_ass_item_id%TYPE := NULL;
11043 
11044   l_header_rec          igs_fi_charges_api_pvt.header_rec_type;
11045   l_line_rec            igs_fi_charges_api_pvt.line_tbl_type;
11046   l_line_rec_dummy      igs_fi_charges_api_pvt.line_tbl_type;
11047   l_line_id_tbl         igs_fi_charges_api_pvt.line_id_tbl_type;
11048   l_line_id_tbl_dummy   igs_fi_charges_api_pvt.line_id_tbl_type;
11049 
11050   l_v_status        VARCHAR2(1)    := NULL;
11051   l_n_msg_count     NUMBER         := NULL;
11052   l_v_msg_data      VARCHAR2(2000) := NULL;
11053   l_n_waiver_amt    NUMBER         := NULL;
11054   l_v_invoice_num   igs_fi_inv_int_all.invoice_number%TYPE;
11055 
11056 BEGIN
11057 
11058    log_to_fnd( p_v_module => 'create_retention_charge',
11059                p_v_string => 'Parameters: '|| p_n_person_id ||', '|| p_v_course_cd || ', '|| p_v_fee_cal_type|| ', '||
11060                               p_n_fee_ci_sequence_number||', '||p_v_fee_type||', '|| p_v_fee_cat||', '||TO_CHAR(p_d_gl_date,'DD-MON-YYYY') ||', '||
11061                               p_n_uoo_id||', '||p_n_amount);
11062 
11063    -- Initialize values of Fee Cat and Course Cd
11064    l_v_fee_cat     := p_v_fee_cat;
11065    l_v_course_cd   := p_v_course_cd;
11066 
11067    -- For Institution Type Trigger, Fee Category and Course Code is passed as Null.
11068    IF p_v_fee_trig_cat = 'INSTITUTN' THEN
11069       log_to_fnd( p_v_module => 'create_retention_charge',
11070                   p_v_string => 'Institution Type trigger, so assigning Null to fee_cat and course_cd');
11071       l_v_fee_cat    := NULL;
11072       l_v_course_cd  := NULL;
11073    END IF;
11074 
11075    log_to_fnd( p_v_module => 'create_retention_charge',
11076                p_v_string => 'Inserting AS record for Retention Amount.');
11077    -- Insert the Retention Charge in the Fee Assessment Header table
11078    -- Modified transaction_dt, effective_dt entries as Trunc(Sysdate) as part of Bug 4240402: Timezone impact
11079    igs_fi_fee_as_pkg.insert_row (x_rowid                   => l_rowid,
11080                                  x_person_id               => p_n_person_id,
11081                                  x_transaction_id          => l_n_transaction_id,
11082                                  x_fee_type                => p_v_fee_type,
11083                                  x_fee_cal_type            => p_v_fee_cal_type,
11084                                  x_fee_ci_sequence_number  => p_n_fee_ci_sequence_number,
11085                                  x_fee_cat                 => l_v_fee_cat,
11086                                  x_s_transaction_type      => g_v_retention,
11087                                  x_transaction_dt          => TRUNC(SYSDATE),
11088                                  x_transaction_amount      => igs_fi_gen_gl.get_formatted_amount(p_n_amount),
11089                                  x_currency_cd             => g_v_currency_cd,
11090                                  x_exchange_rate           => 1,
11091                                  x_chg_elements            => NULL,
11092                                  x_effective_dt            => TRUNC(SYSDATE),
11093                                  x_course_cd               => l_v_course_cd,
11094                                  x_notification_dt         => NULL,
11095                                  x_logical_delete_dt       => NULL,
11096                                  x_comments                => NULL,
11097                                  x_mode                    => 'R',
11098                                  x_org_id                  => g_n_org_id);
11099 
11100    l_header_rec.p_person_id              := p_n_person_id;
11101    l_header_rec.p_fee_type               := p_v_fee_type;
11102    l_header_rec.p_fee_cat                := l_v_fee_cat;
11103    l_header_rec.p_fee_cal_type           := p_v_fee_cal_type;
11104    l_header_rec.p_fee_ci_sequence_number := p_n_fee_ci_sequence_number;
11105    l_header_rec.p_course_cd              := l_v_course_cd;
11106    l_header_rec.p_attendance_type        := NULL;
11107    l_header_rec.p_attendance_mode        := NULL;
11108    l_header_rec.p_invoice_amount         := p_n_amount;
11109    l_header_rec.p_invoice_creation_date  := SYSDATE;
11110    l_header_rec.p_invoice_desc           := p_v_fee_type_desc;
11111    l_header_rec.p_transaction_type       := g_v_retention;
11112    l_header_rec.p_currency_cd            := g_v_currency_cd;
11113    l_header_rec.p_exchange_rate          := 1;
11114    l_header_rec.p_effective_date         := SYSDATE;
11115    l_header_rec.p_waiver_flag            := NULL;
11116    l_header_rec.p_waiver_reason          := NULL;
11117    l_header_rec.p_source_transaction_id  := NULL;
11118 
11119    -- Initializing the line record variable
11120    l_line_rec := l_line_rec_dummy;
11121 
11122    -- Setting the values for the line record
11123    l_line_rec(1).p_s_chg_method_type := g_v_chgmthd_flatrate;
11124    l_line_rec(1).p_description       := p_v_fee_type_desc;
11125    l_line_rec(1).p_chg_elements      := NULL;
11126    l_line_rec(1).p_amount            := p_n_amount;
11127    l_line_rec(1).p_d_gl_date         := TRUNC(p_d_gl_date);
11128    l_line_rec(1).p_uoo_id            := p_n_uoo_id;
11129 
11130    -- Initializing the line record
11131    l_line_id_tbl := l_line_id_tbl_dummy;
11132 
11133    log_to_fnd( p_v_module => 'create_retention_charge',
11134                p_v_string => 'Invoking Charges API to create Retention Charge.');
11135    -- Invoke Charges API to create a retention charge.
11136    igs_fi_charges_api_pvt.create_charge( p_api_version   => 2.0,
11137                                          p_init_msg_list => 'F',
11138                                          p_commit        => 'F',
11139                                          p_header_rec    => l_header_rec,
11140                                          p_line_tbl      => l_line_rec,
11141                                          x_invoice_id    => l_n_invoice_id,
11142                                          x_line_id_tbl   => l_line_id_tbl,
11143                                          x_return_status => l_v_status,
11144                                          x_msg_count     => l_n_msg_count,
11145                                          x_msg_data      => l_v_msg_data,
11146                                          x_waiver_amount => l_n_waiver_amt);
11147 
11148    -- If status returned by the Charges API is not 'S' then raise exception
11149    IF l_v_status <> 'S' THEN
11150       log_to_fnd( p_v_module => 'create_retention_charge',
11151                   p_v_string => 'Charges API returned with status <> S, stack message and raise exception');
11152 
11153       IF l_n_msg_count = 1 THEN
11154          fnd_message.set_encoded(l_v_msg_data);
11155       ELSIF l_n_msg_count > 1 THEN
11156         FOR l_n_cntr IN 1 .. l_n_msg_count
11157         LOOP
11158            fnd_message.set_encoded(fnd_msg_pub.get (p_msg_index => l_n_cntr,
11159                                                     p_encoded => 'T')
11160                                   );
11161         END LOOP;
11162       END IF;
11163       app_exception.raise_exception;
11164    END IF;
11165   IF (p_trace_on = 'Y') THEN
11166     l_v_invoice_num := igs_fi_gen_008.get_invoice_number(l_n_invoice_id);
11167     fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'RET_CHG_NUM') || ': ' || l_v_invoice_num);
11168     fnd_file.put_line (fnd_file.log, igs_fi_gen_gl.get_lkp_meaning('IGS_FI_LOCKBOX', 'RET_CHG_AMT') || ': ' || TO_CHAR(p_n_amount));
11169     fnd_file.new_line(fnd_file.log);
11170   END IF;
11171    -- Call the TBH for inserting record in IGS_FI_FEE_AS_ITEMS if Charges API returned successfully
11172   --  Modified fee_effective_dt entry as Trunc(Sysdate) as part of Bug 4240402: Timezone impact
11173    l_rowid := NULL;
11174    l_n_fee_ass_item_id := NULL;
11175    log_to_fnd( p_v_module => 'create_retention_charge',
11176                p_v_string => 'Inserting Fee Assessment Items Record for Rentention charge.');
11177    igs_fi_fee_as_items_pkg.insert_row( x_rowid                  => l_rowid,
11178                                        x_fee_ass_item_id        => l_n_fee_ass_item_id,
11179                                        x_transaction_id         => l_n_transaction_id,
11180                                        x_person_id              => p_n_person_id,
11181                                        x_status                 => 'E',
11182                                        x_fee_type               => p_v_fee_type,
11183                                        x_fee_cat                => l_v_fee_cat ,
11184                                        x_fee_cal_type           => p_v_fee_cal_type ,
11185                                        x_fee_ci_sequence_number => p_n_fee_ci_sequence_number,
11186                                        x_rul_sequence_number    => NULL,
11187                                        x_s_chg_method_type      => g_v_chgmthd_flatrate,
11188                                        x_description            => NULL,
11189                                        x_chg_elements           => NULL,
11190                                        x_amount                 => igs_fi_gen_gl.get_formatted_amount(p_n_amount),
11191                                        x_fee_effective_dt       => TRUNC(SYSDATE),
11192                                        x_course_cd              => l_v_course_cd,
11193                                        x_crs_version_number     => NULL,
11194                                        x_course_attempt_status  => NULL,
11195                                        x_attendance_mode        => NULL,
11196                                        x_attendance_type        => NULL,
11197                                        x_unit_attempt_status    => NULL,
11198                                        x_location_cd            => NULL,
11199                                        x_eftsu                  => NULL,
11200                                        x_credit_points          => NULL,
11201                                        x_logical_delete_date    => NULL,
11202                                        x_invoice_id             => l_n_invoice_id,
11203                                        x_org_unit_cd            => NULL,
11204                                        x_class_standing         => NULL,
11205                                        x_residency_status_cd    => NULL,
11206                                        x_uoo_id                 => p_n_uoo_id,
11207                                        x_chg_rate               => NULL,
11208                                        x_unit_set_cd            => NULL,
11209                                        x_us_version_number      => NULL,
11210                                        x_unit_type_id           => NULL,
11211                                        x_unit_class             => NULL,
11212                                        x_unit_mode              => NULL,
11213                                        x_unit_level             => NULL
11214                                   );
11215    log_to_fnd( p_v_module => 'create_retention_charge',
11216                p_v_string => 'Returning from create_retention_charge');
11217 
11218 END create_retention_charge;
11219 
11220 
11221 FUNCTION finpl_get_org_unit_cd(p_n_party_id   IN hz_parties.party_id%TYPE) RETURN VARCHAR2 AS
11222 /*************************************************************
11223  Created By : Priya Athipatla
11224  Date Created By : 10-Oct-2005
11225  Purpose : Function to return the Party Number for an Organization
11226  Know limitations, enhancements or remarks
11227  Change History
11228  Who            When        What
11229 ***************************************************************/
11230 
11231 -- Cursor to fetch the Org Unit Cd
11232 CURSOR cur_org_unit_cd(cp_n_party_id  hz_parties.party_id%TYPE) IS
11233   SELECT party_number
11234   FROM igs_or_inst_org_base_v
11235   WHERE party_id = cp_n_party_id;
11236 
11237 l_v_org_unit_cd  igs_or_inst_org_base_v.party_number%TYPE;
11238 
11239 BEGIN
11240 
11241    l_v_org_unit_cd := NULL;
11242 
11243    OPEN cur_org_unit_cd(p_n_party_id);
11244    FETCH cur_org_unit_cd INTO l_v_org_unit_cd;
11245    CLOSE cur_org_unit_cd;
11246 
11247    RETURN l_v_org_unit_cd;
11248 
11249 END finpl_get_org_unit_cd;
11250 
11251 END igs_fi_prc_fee_ass;