DBA Data[Home] [Help]

PACKAGE BODY: APPS.HRSTRDBI

Source


1 package body hrstrdbi as
2 /* $Header: pestrdbi.pkb 115.60 2002/12/09 13:56:53 eumenyio ship $ */
3 /*
4 --
5 -- Copyright (c) Oracle Corporation 1991, 1992, 1993. All rights reserved.
6 --
7 /*
8    NAME
9       pestrdbi.pkb     - create static entity database items
10 --
11    DESCRIPTION
12       This procedure is to be run once only on a new account.  It creates all
13       the static database items used in formula writing and Quick Paint.  This
14       includes the formula types and their contexts.
15 --
16   MODIFIED (DD-MM-YYYY)
17      dcasemor   02-DEC-2002 - Added assignment_category to
18                               SEH_ASS_PERSON_DETAILS_PERF.
19      divicker   28-NOV-2002 - rename ue BIS_PERSON_ASSIGNMENT_DETAILS to
20                               BIS_PERSON_ASSIGNMENT_DETAILS_PERF
21      mreid      26-NOV-2002 - Added Date Earned route
22                               SEH_ASG_LAST_EARNED_PER_NUM
23      skota	30-OCT-2002 - moved the database items to new routes
24      divicker   08-OCT-2002 - added 'ASSIGNMENT_ACTION_DATES_ROUTE' etc
25      divicker   07-OCT-2002 - changed list of Net to Gross contexts
26                               added mod function
27      divicker   02-SEP-2002 - dbis ASG_LAST_PROPOSED_SALARY_CHANGE and
28                               ASG_LAST_PROPOSED_SALARY_PERCENT changed to
29                               use proposed_salary_n
30      dcasemor   16-SEP-2002 - Bug 2571440. Changed the route of
31                               ACCRUAL_PLAN_PAYROLL_PROCESS_3 so that it only
32                               picks up PTO elements which are balance related.
33      dcasemor   05-SEP-2002 - Bug 1791902. Changed the formula text for
34                               PTO_PAYROLL_CARRYOVER.
35      divicker   29-AUG-2002 - Added formula_type 'Payroll Run Proration'
36      alogue     28-AUG-2002 - Added new dbitems LAST_REG_PAYMENT_PERIOD and
37                               LAST_REG_PAYMENT_PERIOD_START_DATE. Bug 2527079.
38      alogue     17-JUN-2002 - Addition of hint to dbitems using SEH_ASS_LAST_PER_NUM
39                               route to optimise performance.
40      divicker   13-JUN-2002 - change Promotion formula to Promotion_template
41                               added SEH_ASSIGNMENT_DETAILS route, ue, dbi
42      divicker   06-JUN-2002 - added Promotion formula type
43                               added to route SEH_ASS_PERSON_DETAILS_2
44                               added dbi ASG_CHANGE_REASON
45      divicker   27-MAY-2002 - added routes HRI_ASG_DETAILS, HRI_ASG_INHRTD_WRK_CNDTNS
46                             - change to TEMPLATE_FTE and TEMPLATE_HEAD formulae
47      divicker   17-MAY-2002 - use PTU_PERSON_TYPE instead of PERSON for CAGR
48      divicker   26-NOV-2001 - Added CON_NATIONAL_IDENTIFIER dbi for US EOY
49                             - Added CAGR formula type and formulae
50                             - HR_CAGR_TEMPLATE and HR_CAGR_PYS_TEMPLATE
51      jgoswami   25-OCT-2001 - Added dbi PER_1099R_NAME Fix for Bug 2072482
52      divicker   25-OCT-2001 - removed source_action_id null check from
53                               ACCRUAL_PLAN_PAYROLL_PROCESS_3 route
54      dcasemor   12-OCT-2001 - Removed some comments from the Fast Formula
55                               PTO_PAYROLL_BALANCE_CALCULATION.
56      divicker   11-OCT-2001 - Added dbi PTU_REC_PERSON_TYPE
57      dcasemor   10-OCT-2001 - Removed a bracket from the fast formula
58                               TEMPLATE_ABSENCE_DURATION.
59      divicker   07-SEP-2001 - merge of peorgrte.sql, peposrte.sql
60                               That is: addition of ASG_ORG_ROUTE and
61                               ASG_POS_ROUTE routes.
62      divicker   07-SEP-2001 - ACCRUAL_PLAN_PAYROLL_PROCESS_3 run_result logic
63                               added
64                               TEMPLATE_ABSENCE_DURATION fix to default times
65      divicker   04-SEP-2001 - Add PTU versions of PER_PERSON_TYPE,
66                               SUP_PERSON_TYPE, CON_PERSON_TYPE
67      alogue     09-AUG-2001 - Fix to route SEH_SADMIN_SALARY_ELEMENT.
68                               Bug 1927280.
69      alogue     02-AUG-2001 - Fix to route contexts usages for
70                               ACCRUAL_PLAN_PAYROLL_PROCESS_2.
71      mreid      20-JUL-2001 - Changed PTO formula to reference
72                               ENTRY_PROCESSED_IN_PERIOD
73      alogue     17-JUL-2001 - New function ENTRY_PROCESSED_IN_PERIOD.
74      alogue     09-JUL-2001 - New formula PTO_ORACLE_SKIP_RULE,
75                               PTO_PAYROLL_BALANCE_CALCULATION,
76                               PTO_SIMPLE_BALANCE_MULTIPLIER,
77                               PTO_HD_ANNIVERSARY_BALANCE,
78                               PTO_HD_ANNIVERSARY_PERIOD_ACCRUAL,
79                               PTO_HD_ANNIVERSARY_CARRYOVER,
80                               PTO_TAGGING_FORMULA.
81                               Changes to PTO_PAYROLL_PERIOD_ACCRUAL,
82                               PTO_PAYROLL_CALCULATION and
83                               PTO_PAYROLL_CARRYOVER formula.
84                               New routes ACCRUAL_PLAN_PAYROLL_PROCESS_1,
85                               ACCRUAL_PLAN_PAYROLL_PROCESS_2,
86                               ACCRUAL_PLAN_PAYROLL_PROCESS_3 and their user entities
87                               and dbitems.
88      mreid      03-JUL-2001 - Corrected ACCRUAL_PLAN_CONT_SERVICE_DATES
89                               and ACCRUAL_PLAN_ENROLLMENT_DATES.
90      alogue     12-JUN-2001 - Amended ACCRUAL_PLAN_CONT_SERVICE_DATES route.
91      alogue     31-MAY-2001 - Amended ACCRUAL_PLAN_ENROLLMENT_DATES route
92                               and ACCRUAL_PLAN_CONT_SERVICE_DATES route.
93      alogue     24-MAY-2001 - New CURRENT_ELEMENT_TYPE_ID dbitem.
94      dcasemor   08-MAR-2001 - Bug 1610788.
95                               Added PERSON_ID context to Accrual formula type.
96      alogue     06-MAR-2001 - New ENTRY_END_DATE dbitem,
97      alogue     11-DEC-2000 - New ELEMENT_TYPE_ATTRIBUTES route,
98                               ELEMENT_TYPE_ATTRIBUTES user entity, and
99                               ELEMENT_NAME dbitem.
100      alogue     30-NOV-2000 - New PAY_EARNED_PERIOD_CORE route, PAY_PD_DETAILS_CORE
101                               user entity, and PAY_EARNED dbitems.
102      alogue     26-SEP-2000 - Fix to CHECK_RATE_TYPE formula.
103                               Source_text into Oracle Payroll
104                               ff_ftype_context_usages.
105      alogue     05-JUN-2000 - Fixes to SEH_ASSIGN_HR_ADDRESS, SEH_PER_PERSON_ADDRESS,
106                               and SEH_CON_PERSON_ADDRESS route texts.
107      alogue     17-MAY-2000 - R11.5 Concurrent patch Entity Horizon changes:
108                               Change to SEH_PER_PERSON_DETAILS, bug 1096840.
109      alogue     12-MAY-2000 - R11.5 Concurrent patch Entity Horizon changes:
110                               New route SEH_SADMIN_SALARY_PROPOSALS_2.
111                               New route PER_TIME_PERIODS_INFO and dbitems.
112                               Fix to formula QH_ASSIGNMENT_NAME.
113                               New dbitem SUP_EMAIL_ADDRESS.
114      alogue     07-APR-2000 - R11.5 Concurrent patch Entity Horizon changes:
115                               Performance changes to SEH_ASSIGN_HR_ADDRESS,
116                               SEH_CON_PERSON_ADDRESS and SEH_PER_PERSON_ADDRESS
117                               use fnd_territories_tl.
118                               Change to PTO_PAYROLL_CALCULATION formula.
119                               Change to PTO_SIMPLE_MULTIPLIER formula.
120                               Change to PTO_SIMPLE_PERIOD_ACCRUAL formula.
121                               Change to PTO_SIMPLE_CARRYOVER formula.
122                               Change to CALCULATE_PAYROLL_PERIODS function.
123                               Iterative Engine support.
124                               New route ASSIGNMENT_CONTRACTS_ROUTE and
125                               accompanying dbitems.
126                               New formula QH_ASSIGNMENT_NAME.
127      alogue     08-NOV-1999 - R11.5 Entity Horizon changes:
128                               Change to PTO_PAYROLL_CALCULATION formula.
129                               Change to PTO_SIMPLE_MULTIPLIER formula.
130                               Change to PTO_SIMPLE_CARRYOVER formula.
131                               Change to PTO_ROLLING_ACCRUAL formula.
132                               Change to PTO_PAYROLL_CARRYOVER formula.
133                               Change to ACCRUAL_PLAN_ENROLLMENT_DATES,
134                               ACCRUAL_PLAN_CONT_SERVICE_DATES routes.
135                               New BIS dbitems ASG_EMPLOYMENT_CATEGORY_CODE,
136                               ASG_PRIMARY_CODE and ASG_FREQ_CODE.
137                               Change to TEMPLATE_BIS_DAYS_TO_HOURS formula.
138                               Change to TEMPLATE_HEAD formula.
139                               Change to TEMPLATE_FTE formula.
140      alogue     26-OCT-1999 - R11.5 Entity Horizon changes:
141                               New dbitem ASG_SALARY_BASIS_ANNUALIZATION_FACTOR
142                               ASG_SALARY_BASIS_GRADE_ANNUALIZATION_FACTOR.
143                               Change to ASSIGNMENT_FULL_TIME_CONDITIONS route.
144                               Change to SEH_ASS_PERSON_DETAILS route.
145                               Change to SEH_REC_DETAILS route.
146                               Change to SEH_SUP_DETAILS route.
147                               New formula TEMPLATE_ABSENCE_DURATION.
148                               New function COUNT_WORKING_DAYS.
149                               Change to PTO_PAYROLL_CALCULATION formula.
150                               New PAY_EARNED_PERIOD_CORE route, PAY_PD_DETAILS_CORE
151                               user entity, and PAY_EARNED dbitems.
152      alogue     02-JUN-1999 - R11.5 Entity Horizon changes: Fixes to
153                               PTO_PAYROLL_CALCULATION, PTO_ROLLING_ACCRUAL
154                               and PTO_SIMPLE_MULTIPLIER.
155                               New ff_function CHK_NAT_ID_FORMAT.
156      alogue     25-JUN-1999 - R11.5 Entity Horizon changes:
157                               New dbitems : PER_PREFIX, PER_SUFFIX,
158                               PER_ADR_COUNTRY_CODE and ENTRY_START_DATE.
159      alogue     24-MAY-1999 - R11.5 Entity Horizon changes:
160                               New formula TEMPLATE_BIS_TRAINING_CONVERT_DURATION.
161                               New context SOURCE_TEXT.
162                               New Accrual formula types + changes to formulae..
163      alogue     26-APR-1999 - R11.5 Entity Horizon changes: Canonical Date and
164                               Canonical Number support.
165                               New ff_context source_id.
166                               Accrual plan changes: ACCRUAL_PLAN_ENROLLMENT_DATES
167                               and ACCRUAL_PLAN_CONT_SERVICE_DATES.
168                               Fix to ACCRUAL_PLAN_SERVICE_DATES.
169                               New formula PTO_INELIGIBILITY_CALCULATION.
170                               New formula CHECK_RATE_TYPE.
171                               New procedure insert_user_tables to seed
172                               user tables.
173      alogue     16-MAR-1999 - R11.5 Entity Horizon changes:
174                               Outer join for per_phones in SEH_PER_PERSON_DETAILS
175                               New ACCRUAL formula type.
176                               Route ACCRUAL_PLAN_VALUES and its dbitems.
177                               Route CARRIED_OVER_VALUES and its dbitems.
178                               Route ACCRUAL_PLAN_SERVICE_DATES and its dbitems.
179                               Route ACCRUAL_PLAN_DATES and its dbitems.
180                               Added TEMPLATE_BIS_DAYS_TO_HOURS, TEMPLATE_FTE,
181                               TEMPLATE_HEAD, EXAMPLE_BIS_OT_BAND1 to
182                               ff_formulas_f.
183                               Created insert_formula to insert PTO_PAYROLL_CARRYOVER,
184                               PTO_PAYROLL_PERIOD_ACCRUAL, PTO_PAYROLL_CALCULATION,
185                               PTO_ROLLING_CARRYOVER, PTO_ROLLING_PERIOD_ACCRUAL,
186                               PTO_ROLLING_ACCRUAL, PTO_SIMPLE_CARRYOVER,
187                               PTO_SIMPLE_PERIOD_ACCRUAL, PTO_SIMPLE_MULTIPLIER
188                               into ff_formulas_f.
189                               Created insert_functions to insert GET_HOURS_WORKED,
190                               CURRENCY_CONVERT_AMOUNT, GET_RATE_TYPE,
191                               CHECK_RATE_TYPE and accrual functions
192                               into ff_functions.
193      alogue     11-JAN-1999 - R11.5 Entity Horizon changes:
194                               OAB and other new ff_contexts, route
195                               ASSIGNMENT_BUDGET_VALUES and dbitems,
196                               ASSIGNMENT_FULL_TIME_CONDITIONS route
197                               and dbitems.
198                               R11.5 change whereby date contexts are passed
199                               into routes as dates (and thus don't require
200                               a to_date() on them).
201                               Change to SEH_SADMIN_LAST_PERFORM_REV route.
202                               New routes SEH_CON_PERSON_DETAILS_2,
203                               SEH_ASS_PERSON_DETAILS_3, SEH_PER_PERSON_DETAILS_2
204                               and dbitems.
205      alogue     13-JUL-1998 - Legislative Check formula type.
206      alogue     20-MAY-1998 - Performance fixes for SEH_ASS_PERSON_DETAILS and
207                               SEH_PER_PERSON_DETAILS routes.
208      alogue     13-NOV-1997 - Rename PER_CONTACTS table to
209                               PER_CONTACT_RELATIONSHIPS.
210      alogue     11-NOV-1997 - user entity PAY_PAYROLLS_ENTITY fix.
211      alogue     07-NOV-1997 - New database item EMP_PROJ_TERM_DATE.
212      rfine      13-OCT-97   110.5  563034  Changed parent table name from
213                                            PER_PEOPLE_F to PER_ALL_PEOPLE_F
214      alogue     07-OCT-1997 - fix of SEH_ASS_PERSON_DETAILS route.
215      alogue     12-AUG-1997 - per_phones put into various routes
216      alogue     07-AUG-1997 - ff_context TAX_GROUP.
217      alogue     05-AUG-1997 - Rename use of fnd_territories to
218                               fnd_territories_vl.
219      alogue     29-MAY-1997 - Fix to PAY_PAYROLLS_ROUTE.
220      alogue     19-MAY-1997 - Renamed database item ARREARS_FLAG to
221                               PAYROLL_ARREARS_FLAG.
222      alogue     07-APR-1997 - New routes: TARGET_PAYROLL_ACTION_ROUTE
223                               (for action_type item) and PAY_PAYROLLS_ROUTE
224                               (for arrears_flag item) for advance pay.
225                               Also tidy up reflecting bug 374466
226                               SEH_ASS_PERSON_DETAILS route fix.
227      mwcallag   01-SEP-1995 - sysdate and Session date routes and DB items
228                               added.
229      mwcallag   24-APR-1995 - Cheque number DB items added (UK, US spelling).
230      mwcallag   31-MAR-1995 - Entity for PAY_PROC_PERIOD_NUMBER DB items now
231                               has not_found_allowed = 'Y'.
232      mwcallag   06-JAN-1995 - Performance changes resulting from the DEC
233                               Benchmark.  These include:
234                               --
235                               A new route : SEH_ASS_PERSON_DETAILS_2  - this
236                               holds DB items that were previously being slowed
237                               down in route SEH_ASS_PERSON_DETAILS.
238                               --
239                               Index for pay_basis_id disabled in the route
240                               SEH_SADMIN_SALARY_ELEMENT.
241                               --
242                               The following routes used to use the synonym
243                               fnd_lookups.  Originally this was a simple
244                               table, but now is a complex view, and hence
245                               these routes now refer to the view hr_lookups,
246                               and also use the application id column (= 800)
247                               for improved performance:
248                               SEH_PER_PERSON_DETAILS
249                               SEH_ASS_PERSON_DETAILS
250                               SEH_CON_PERSON_DETAILS
251                               SEH_REC_DETAILS
252                               SEH_SUP_DETAILS
253                               --
254                               The following routes use the view hr_lookups.
255                               They have been modified to also use the
256                               application id column (= 800) for improved
257                               performance:
258                               SEH_EMP_PERSON_SERVICE_2
259                               SEH_SADMIN_SALARY_BASIS
260                               SEH_SADMIN_SALARY_PROPOSALS
261                               SEH_ASSIGN_HR_ADDRESS_US
262                               SEH_ASSIGN_ADDRESS_US
263                               SEH_ASSIGN_HR_ADDRESS_UK
264                               SEH_ASSIGN_ADDRESS_UK
265                               --
266      mwcallag   24-OCT-1994 - New context of ORIGINAL_ENTRY_ID added to
267                               payroll and element skip formual types
268      mwcallag   15-OCT-1994 - Various changes ready for US benchmark:
269                               Date restriction added to Person and contact
270                               address routes (bug no. 240009).
271                               SEH_PAY_DETAILS route now uses the context of
272                               payroll action rather than payroll id to improve
273                               performance.
274                               New DB item added to route SEH_PAY_DETAILS:
275                               PAY_PROC_PERIOD_NUMBER
276                               PAY_PROC_PERIOD_ID
277                               PAY_PROC_PERIOD_NAME
278                               --
279                               'PAY_PROC_PERIOD_NUMBER' replaces the old
280                               'ASG_PROC_PERIOD_NUMBER' DB item.
281                               ASG_LAST_PROC_PERIOD_NUMBER route changed to use
282                               the context of assignment id (the previous
283                               change to use payroll action was wrong), also
284                               uses the DB change of time_period_id on the
285                               payroll actions table to improve performance.
286                               New DB item added to this route:
287                               ASG_LAST_PROC_PERIOD_NAME
288                               ASG_LAST_PROC_PERIOD_ID
289                               ASG_LAST_PROC_PAYROLL_NAME
290                               --
291      mwcallag   28-JUL-1994 - Payroll period DB items added.
292      mwcallag   16-JUN-1994 - Route SEH_EMP_PERSON_SERVICE_2 altered, nvl
293                               added.
294                               This ensures a row is always returned.
295      mwcallag   29-APR-1994 - Route SEH_ASS_LAST_PER_NUM tuned, now uses the
296                               context of payroll action id rather than
297                               assignment id. (ASG_LAST_PROC_PERIOD_NUMBER).
298                               Route SEH_EMP_PERSON_SERVICE split into 2 for
299                               performance purposes.
300      mwcallag   25-MAR-1994 - Not found flag for all ASG_%_LAST% DB item
301                               set to yes.
302      mwcallag   18-MAR-1994 - Not found flag for ASG_LAST_PROC_PERIOD_NUMBER
303                               set to yes - there wont be an entry for the
304                               first run.
305      mwcallag   28-FEB-1994 - Database name changed from 'ASS_%' to 'ASG_%'.
306      mwcallag   11-JAN-1994 - New context of Element type id added to
307                               ff_contexts.
308      mwcallag   06-JAN-1994 - Contact routes changed to use contact_person_id.
309      mwcallag   15-DEC-1993 - HR location (general, GB and US) DB items added.
310                               G417 ASS_SALARY changed to Number data type.
311                               ASS_SALARY_BASIS_CODE DB item added.
312      mwcallag   09-DEC-1993 - G337 Payroll DB items added: PAY_PERIODS_PER_YEAR
313                               and PAY_PROC_PERIOD_DATE_PAID.
314      mwcallag   02-DEC-1993 - Salary Admin Db items added.
315      mwcallag   02-NOV-1993 - 'User Table Validation' formula type added.
316      mwcallag   22-OCT-1993 - Further formula types and contexts added.
317      mwcallag   08-OCT-1993 - Payroll DB items : null allowed set to 'N'.
318      mwcallag   07-SEP-1993 - ********************************
319                               * DIVERGENCE FROM FROZEN CODE  *
320                               ********************************
321                               More Static DB items added, together with
322                               new routes for payroll processing.
323      mwcallag   31-AUG-1993 - Person type definition texts changed from
324                               'system_person_type' to 'user_person_type'.
325                               Payroll formula type changed to include fewer
326                               context usages.
327      mwcallag   11-AUG-1993 - New contexts for payment formula type.
328      mwcallag   22-JUL-1993 - Routine split into 2 procedures for easier
329                               re-building.
330      mwcallag   20-JUL-1993 - Some DB items changed from number to text type.
331      mwcallag   21-JUN-1993 - 'Element Input Validation' formula type added.
332      mwcallag   15-JUN-1993 - minor changes to routes to ensure a row is
333                               always returned (outer joins added, etc).
334      mwcallag   04-JUN-1993 - general mods and application details route added
335      mwcallag   28-MAY-1993 - minor change to person assignment details route.
336      mwcallag   26-MAY-1993 - creator type changed following database change.
337      mwcallag   17-MAY-1993 - created.
338 */
339 procedure insert_context is
340 --
341 --   +==================================================================+
342 --   |    Insert FF contexts                                            |
343 --   +==================================================================+
344 --
345 begin
346    declare
347       procedure do_insert (l_context_name varchar2, l_data_type varchar2) is
348          x number;
349       begin
350          x := ffdict.get_context_level;
351          --
352          hr_utility.set_location('hrstrdbi.ff_context_do_insert', 1);
353          insert into ff_contexts
354          (context_id,
355           context_level,
356           context_name,
357           data_type)
358          values
359          (ff_contexts_s.nextval,
360           x,
361           l_context_name,
362           l_data_type);
363       end;
364    begin
365       do_insert ('BUSINESS_GROUP_ID',     'N');
366       do_insert ('PAYROLL_ID',            'N');
367       do_insert ('PAYROLL_ACTION_ID',     'N');
368       do_insert ('ASSIGNMENT_ID',         'N');
369       do_insert ('ASSIGNMENT_ACTION_ID',  'N');
370       do_insert ('DATE_EARNED',           'D');
371       do_insert ('ORG_PAY_METHOD_ID',     'N');
372       do_insert ('PER_PAY_METHOD_ID',     'N');
373       do_insert ('ORGANIZATION_ID',       'N');
374       do_insert ('TAX_UNIT_ID',           'N');
375       do_insert ('JURISDICTION_CODE',     'T');
376       do_insert ('BALANCE_DATE',          'D');
377       do_insert ('ELEMENT_ENTRY_ID',      'N');
378       do_insert ('ELEMENT_TYPE_ID',       'N');
379       do_insert ('ORIGINAL_ENTRY_ID',     'N');
380       do_insert ('TAX_GROUP',             'T');
381       do_insert ('PGM_ID',                'N');
382       do_insert ('PL_ID',                 'N');
383       do_insert ('PL_TYP_ID',             'N');
384       do_insert ('OPT_ID',                'N');
385       do_insert ('LER_ID',                'N');
386       do_insert ('COMM_TYP_ID',           'N');
387       do_insert ('ACT_TYP_ID',            'N');
388       do_insert ('ACCRUAL_PLAN_ID',       'N');
389       do_insert ('PERSON_ID',             'N');
390       do_insert ('SOURCE_ID',             'N');
391       do_insert ('SOURCE_TEXT',           'T');
392    end;
393 --
394 --   +==================================================================+
395 --   |    Insert FF formula type and contexts                           |
396 --   +==================================================================+
397 --
398    declare
399        procedure do_insert
400        (
401            p_formula_type_name  in varchar2
402        ) is
403        begin
404            hr_utility.set_location('hrstrdbi.ff_type_do_insert', 1);
405            insert into ff_formula_types
406                  (formula_type_id,
407                   formula_type_name,
408                   last_update_date,
409                   last_updated_by,
410                   last_update_login,
411                   created_by,
412                   creation_date)
413           values (ff_formula_types_s.nextval,
414                   p_formula_type_name,
415                   sysdate,
416                   0,
417                   0,
418                   0,
419                   sysdate);
420        end do_insert;
421     begin
422        do_insert ('Oracle Payroll');
423        hr_utility.set_location('hrstrdbi.insert_context', 1);
424        insert into ff_ftype_context_usages (formula_type_id, context_id)
425        select ff_formula_types_s.currval, CON.context_id
426        from ff_contexts CON
427        where context_name in ('BUSINESS_GROUP_ID',
428                               'PAYROLL_ID',
429                               'PAYROLL_ACTION_ID',
430                               'ASSIGNMENT_ID',
431                               'ASSIGNMENT_ACTION_ID',
432                               'DATE_EARNED',
433 			      'TAX_UNIT_ID',
434 			      'JURISDICTION_CODE',
435 			      'BALANCE_DATE',
436                               'ELEMENT_ENTRY_ID',
437                               'ELEMENT_TYPE_ID',
438                               'ORIGINAL_ENTRY_ID',
439                               'SOURCE_ID',
440                               'TAX_GROUP',
441                               'SOURCE_TEXT');
442        --
443        do_insert ('Payment');
444        hr_utility.set_location('hrstrdbi.insert_context', 2);
445        insert into ff_ftype_context_usages (formula_type_id, context_id)
446        select ff_formula_types_s.currval, CON.context_id
447        from ff_contexts CON
448        where context_name in ('BUSINESS_GROUP_ID',
449                               'PAYROLL_ID',
450                               'PAYROLL_ACTION_ID',
451                               'ASSIGNMENT_ID',
452                               'ASSIGNMENT_ACTION_ID',
453                               'DATE_EARNED',
454 			      'ORG_PAY_METHOD_ID',
455 			      'PER_PAY_METHOD_ID',
456 			      'ORGANIZATION_ID',
457 			      'TAX_UNIT_ID',
458 			      'JURISDICTION_CODE');
459        --
460        do_insert ('Assignment Set');
461        hr_utility.set_location('hrstrdbi.insert_context', 3);
462        insert into ff_ftype_context_usages (formula_type_id, context_id)
463        select ff_formula_types_s.currval, CON.context_id
464        from ff_contexts CON
465        where context_name in ('DATE_EARNED', 'ASSIGNMENT_ID');
466        --
467        do_insert ('QuickPaint');
468        hr_utility.set_location('hrstrdbi.insert_context', 4);
469        insert into ff_ftype_context_usages (formula_type_id, context_id)
470        select ff_formula_types_s.currval, CON.context_id
471        from ff_contexts CON
472        where context_name in ('DATE_EARNED', 'ASSIGNMENT_ID');
473        --
474        do_insert ('Element Input Validation');
475        hr_utility.set_location('hrstrdbi.insert_context', 5);
476        insert into ff_ftype_context_usages (formula_type_id, context_id)
477        select ff_formula_types_s.currval, CON.context_id
478        from ff_contexts CON
479        where context_name in ('DATE_EARNED',
480                               'ASSIGNMENT_ID', 'BUSINESS_GROUP_ID');
481        --
482        do_insert ('Element Skip');
483        hr_utility.set_location('hrstrdbi.insert_context', 6);
484        insert into ff_ftype_context_usages (formula_type_id, context_id)
485        select ff_formula_types_s.currval, CON.context_id
486        from ff_contexts CON
487        where context_name in ('BUSINESS_GROUP_ID',
488                               'PAYROLL_ID',
489                               'PAYROLL_ACTION_ID',
490                               'ASSIGNMENT_ID',
491                               'ASSIGNMENT_ACTION_ID',
492                               'DATE_EARNED',
493                               'TAX_UNIT_ID',
494                               'JURISDICTION_CODE',
495 			      'ELEMENT_ENTRY_ID',
496                               'ELEMENT_TYPE_ID',
497                               'ORIGINAL_ENTRY_ID',
498                               'SOURCE_ID',
499                               'TAX_GROUP');
500        --
501        do_insert ('Legislative Check');
502        hr_utility.set_location('hrstrdbi.insert_context', 7);
503        insert into ff_ftype_context_usages (formula_type_id, context_id)
504        select ff_formula_types_s.currval, CON.context_id
505        from ff_contexts CON
506        where context_name in ('ASSIGNMENT_ID',
507                               'ASSIGNMENT_ACTION_ID',
508                               'DATE_EARNED');
509        --
510        do_insert ('Accrual');
511        hr_utility.set_location('hrstrdbi.insert_context', 8);
512        insert into ff_ftype_context_usages (formula_type_id, context_id)
513        select ff_formula_types_s.currval, CON.context_id
514        from ff_contexts CON
515        where context_name in ('ASSIGNMENT_ID',
516                               'ASSIGNMENT_ACTION_ID',
517                               'DATE_EARNED',
518                               'ACCRUAL_PLAN_ID',
519                               'PAYROLL_ID',
520                               'BUSINESS_GROUP_ID',
521                               'PERSON_ID');
522        --
523        do_insert ('Accrual Subformula');
524        hr_utility.set_location('hrstrdbi.insert_context', 9);
525        insert into ff_ftype_context_usages (formula_type_id, context_id)
526        select ff_formula_types_s.currval, CON.context_id
527        from ff_contexts CON
528        where context_name in ('ASSIGNMENT_ID',
529                               'DATE_EARNED',
530                               'ACCRUAL_PLAN_ID',
531                               'PAYROLL_ID',
532                               'BUSINESS_GROUP_ID');
533        --
534        do_insert ('Accrual Carryover');
535        hr_utility.set_location('hrstrdbi.insert_context', 10);
536        insert into ff_ftype_context_usages (formula_type_id, context_id)
537        select ff_formula_types_s.currval, CON.context_id
538        from ff_contexts CON
539        where context_name in ('ASSIGNMENT_ID',
540                               'DATE_EARNED',
541                               'ACCRUAL_PLAN_ID',
542                               'PAYROLL_ID',
543                               'BUSINESS_GROUP_ID');
544        --
545        do_insert ('Accrual Ineligibility');
546        hr_utility.set_location('hrstrdbi.insert_context', 11);
547        insert into ff_ftype_context_usages (formula_type_id, context_id)
548        select ff_formula_types_s.currval, CON.context_id
549        from ff_contexts CON
550        where context_name in ('ASSIGNMENT_ID',
551                               'DATE_EARNED',
552                               'ACCRUAL_PLAN_ID',
553                               'PAYROLL_ID',
554                               'BUSINESS_GROUP_ID');
555        --
556        do_insert ('Net to Gross');
557        hr_utility.set_location('hrstrdbi.insert_context', 12);
558        insert into ff_ftype_context_usages (formula_type_id, context_id)
559        select ff_formula_types_s.currval, CON.context_id
560        from ff_contexts CON
561        where context_name in ('BUSINESS_GROUP_ID',
562                               'PAYROLL_ID',
563                               'PAYROLL_ACTION_ID',
564                               'ASSIGNMENT_ID',
565                               'DATE_EARNED',
566                               'ELEMENT_ENTRY_ID',
567                               'ASSIGNMENT_ACTION_ID',
568                               'ELEMENT_TYPE_ID');
569        --
570        do_insert('CAGR');
571        hr_utility.set_location('hrstrdbi.insert_context', 13);
572        insert into ff_ftype_context_usages (formula_type_id, context_id)
573        select ff_formula_types_s.currval, CON.context_id
574        from ff_contexts CON
575        where context_name in ('BUSINESS_GROUP_ID',
576                               'PAYROLL_ID',
577                               'ASSIGNMENT_ID',
578                               'DATE_EARNED',
579                               'ORGANIZATION_ID',
580                               'TAX_UNIT_ID',
581                               'PERSON_ID');
582        --
583        do_insert('Promotion');
584        hr_utility.set_location('hrstrdbi.insert_context', 14);
585        insert into ff_ftype_context_usages (formula_type_id, context_id)
586        select ff_formula_types_s.currval, CON.context_id
587        from ff_contexts CON
588        where context_name in ('ASSIGNMENT_ID',
589                               'DATE_EARNED');
590        --
591        do_insert('Payroll Run Proration');
592        hr_utility.set_location('hrstrdbi.insert_context', 15);
593        insert into ff_ftype_context_usages (formula_type_id, context_id)
594        select ff_formula_types_s.currval, CON.context_id
595        from ff_contexts CON
596        where context_name in ('BUSINESS_GROUP_ID',
597                               'PAYROLL_ID',
598                               'PAYROLL_ACTION_ID',
599                               'ASSIGNMENT_ID',
600                               'ASSIGNMENT_ACTION_ID',
601                               'DATE_EARNED',
602                               'TAX_UNIT_ID',
603                               'JURISDICTION_CODE',
604                               'BALANCE_DATE',
605                               'ELEMENT_ENTRY_ID',
606                               'ELEMENT_TYPE_ID',
607                               'ORIGINAL_ENTRY_ID',
608                               'TAX_GROUP',
609                               'SOURCE_ID',
610                               'SOURCE_TEXT');
611        --
612        -- This formula type does not use any contexts:
613        --
614        do_insert ('User Table Validation');
615     end;
616     --
617 end insert_context;
618 --
619 PROCEDURE insert_routes_db_items is
620 l_text                          long;
621 l_date_earned_context_id        number;
622 l_assign_id_context_id          number;
623 l_assign_action_id_context_id   number;
624 l_payroll_id_context_id         number;
625 l_payroll_action_id_context_id  number;
626 l_accrual_plan_id_context_id    number;
627 l_original_entry_id             number;
628 l_element_entry_id              number;
629 l_element_type_id               number;
630 l_route_parameters_id           number;
631 --
632 -- ******** local procedure : insert_route_parameters  ********
633 --
634 procedure insert_route_parameters
635 (
636     p_parameter_name  in  varchar2,
637     p_data_type       in  varchar2,
638     p_sequence_no     in  number
639 ) is
640 begin
641     hr_utility.set_location('hrstrdbi.insert_route_parameters', 1);
642     insert into ff_route_parameters
643           (route_id,
644            sequence_no,
645            parameter_name,
646            data_type,
647            route_parameter_id)
648    select  ff_routes_s.currval,
649            p_sequence_no,
650            p_parameter_name,
651            p_data_type,
652            ff_route_parameters_s.nextval
653    from    dual;
654 end insert_route_parameters;
655 --
656 -- ******** local procedure : insert_route_parameter_values  ********
657 --
658 procedure insert_route_parameter_values
659 (
660     p_route_parameter_id  in  number,
661     p_value               in  varchar2
662 ) is
663 begin
664     hr_utility.set_location('hrstrdbi.insert_route_parameter_values', 1);
665     insert into ff_route_parameter_values
666            (route_parameter_id,
667             user_entity_id,
668             value,
669             last_update_date,
670             creation_date)
671     values (p_route_parameter_id,
672             ff_user_entities_s.currval,
673             p_value,
674             sysdate,
675             sysdate);
676 end insert_route_parameter_values;
677 --
678 -- ******** local procedure : insert_route_context_usages  ********
679 --
680 procedure insert_route_context_usages
681 (
682     p_context_id    in  number,
683     p_sequence_no   in  number
684 ) is
685 begin
686     hr_utility.set_location('hrstrdbi.insert_route_context_usages', 1);
687     insert into ff_route_context_usages
688            (route_id,
689             context_id,
690             sequence_no)
691     select  ff_routes_s.currval,
692             p_context_id,
693             p_sequence_no
694     from    dual;
695 end insert_route_context_usages;
696 --
697 -- ******** local procedure : insert_user_entity  ********
698 --
699 procedure insert_user_entity
700 (
701     p_user_entity_name       in varchar2,
702     p_description            in varchar2,
703     p_notfound_allowed_flag  in varchar2 default 'N'
704 ) is
705 begin
706     hr_utility.set_location('hrstrdbi.insert_user_entity', 1);
707     insert into ff_user_entities
708            (user_entity_id,
709             business_group_id,
710             legislation_code,
711             route_id,
712             notfound_allowed_flag,
713             user_entity_name,
714             creator_id,
715             creator_type,
716             entity_description,
717             last_update_date,
718             last_updated_by,
719             last_update_login,
720             created_by,
721             creation_date)
722     --
723     values (ff_user_entities_s.nextval,
724             null,
725             null,
726             ff_routes_s.currval,
727             p_notfound_allowed_flag,
728             p_user_entity_name,
729             0,
730             'SEH',
731             p_description,
732             sysdate,
733             0,
734             0,
735             0,
736             sysdate);
737 end insert_user_entity;
738 --
739 -- ******** local procedure : insert_database_item  ********
740 --
741 procedure insert_database_item
742 (
743     p_user_name          in varchar2,
744     p_definition_text    in varchar2,
745     p_description        in varchar2,
746     p_data_type          in varchar2,
747     p_null_allowed_flag  in varchar2
748 ) is
749 begin
750     hr_utility.set_location('hrstrdbi.insert_database_item', 1);
751     hr_utility.trace ('creating : ' || p_user_name);
752     insert into ff_database_items (
753             user_name,
754             user_entity_id,
755             data_type,
756             definition_text,
757             null_allowed_flag,
758             description,
759             last_update_date,
760             last_updated_by,
761             last_update_login,
762             created_by,
763             creation_date)
764     --
765     values (p_user_name,
766             ff_user_entities_s.currval,
767             p_data_type,
768             p_definition_text,
769             p_null_allowed_flag,
770             p_description,
771             sysdate,
772             0,
773             0,
774             0,
775             sysdate);
776 end insert_database_item;
777 --
778 --
779 -- ******** local procedure : insert_route  ********
780 --
781 procedure insert_route
782 (
783     p_route_name    in varchar2,
784     p_description   in varchar2,
785     p_text          in varchar2
786 ) is
787 begin
788     hr_utility.trace ('creating route : ' || p_route_name);
789     hr_utility.set_location('hrstrdbi.insert_route', 1);
790     insert into ff_routes
791            (route_id,
792             route_name,
793             user_defined_flag,
794             description,
795             text,
796             last_update_date,
797             last_updated_by,
798             last_update_login,
799             created_by,
800             creation_date)
801     values (ff_routes_s.nextval,
802             p_route_name,
803             'N',
804             p_description,
805             p_text,
806             sysdate,
807             0,
808             0,
809             0,
810             sysdate);
811 end insert_route;
812 --
813 ------------------------------ begin -------------------------------
814 --
815 BEGIN
816     --
817     -- get the context ids from the context table
818     --
819     hr_utility.set_location('hrstrdbi.insert_routes_db_items', 1);
820     select context_id
821     into   l_date_earned_context_id
822     from   ff_contexts
823     where  context_name = 'DATE_EARNED';
824     --
825     hr_utility.set_location('hrstrdbi.insert_routes_db_items', 2);
826     select context_id
827     into   l_assign_id_context_id
828     from   ff_contexts
829     where  context_name = 'ASSIGNMENT_ID';
830     --
831     hr_utility.set_location('hrstrdbi.insert_routes_db_items', 3);
832     select context_id
833     into   l_payroll_action_id_context_id
834     from   ff_contexts
835     where  context_name = 'PAYROLL_ACTION_ID';
836     --
837     hr_utility.set_location('hrstrdbi.insert_routes_db_items', 4);
838     select context_id
839     into   l_assign_action_id_context_id
840     from   ff_contexts
841     where  context_name = 'ASSIGNMENT_ACTION_ID';
842     --
843     hr_utility.set_location('hrstrdbi.insert_routes_db_items', 5);
844     select context_id
845     into   l_payroll_id_context_id
846     from   ff_contexts
847     where  context_name = 'PAYROLL_ID';
848     --
849     hr_utility.set_location('hrstrdbi.insert_routes_db_items', 6);
850     select context_id
851     into   l_accrual_plan_id_context_id
852     from   ff_contexts
853     where  context_name = 'ACCRUAL_PLAN_ID';
854     --
855     hr_utility.set_location('hrstrdbi.insert_routes_db_items', 7);
856     select context_id
857     into   l_original_entry_id
858     from   ff_contexts
859     where  context_name = 'ORIGINAL_ENTRY_ID';
860     --
861     hr_utility.set_location('hrstrdbi.insert_routes_db_items', 8);
862     select context_id
863     into   l_element_entry_id
864     from   ff_contexts
865     where  context_name = 'ELEMENT_ENTRY_ID';
866     --
867     hr_utility.set_location('hrstrdbi.insert_routes_db_items', 9);
868     select context_id
869     into   l_element_type_id
870     from   ff_contexts
871     where  context_name = 'ELEMENT_TYPE_ID';
872     --
873     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++
874     --                                                       +
875     -- Route for person details : SEH_PER_PERSON_DETAILS     +
876     --                                                       +
877     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++
878     --
879     l_text := '/* Person details */
880           per_all_people_f       PEOPLE
881   ,       per_person_types       PTYPE
882   ,       per_phones             PHONE
883   ,       fnd_sessions           SES
884   ,       hr_lookups             a
885   ,       hr_lookups             c
886   ,       hr_lookups             d
887   ,       hr_lookups             e
888   ,       hr_lookups             f
889   ,       hr_lookups             g
890   ,       hr_lookups             h
891   ,       hr_lookups             i
892   ,       per_all_assignments_f  ASSIGN
893   where   &B1 BETWEEN ASSIGN.effective_start_date
894                    AND ASSIGN.effective_end_date
895   and     ASSIGN.assignment_id = &B2
896   and     PEOPLE.person_id     = ASSIGN.person_id
897   and     &B1 BETWEEN PEOPLE.effective_start_date
898                    AND PEOPLE.effective_end_date
899   and     PTYPE.person_type_id = PEOPLE.person_type_id
900   and     PHONE.parent_id (+) = PEOPLE.person_id
901   AND     PHONE.parent_table (+)= ''PER_PEOPLE_F''
902   and     PHONE.phone_type (+)= ''W1''
903   AND     &B1 BETWEEN NVL(PHONE.date_from(+),&B1)
904                    AND NVL(PHONE.date_to(+),&B1)
905   and     a.lookup_type        = ''YES_NO''
906   and     a.lookup_code        = nvl(PEOPLE.current_applicant_flag,''N'')
907   and     a.application_id     = 800
908   and     c.lookup_type        = ''YES_NO''
909   and     c.lookup_code        = nvl(PEOPLE.current_employee_flag,''N'')
910   and     c.application_id     = 800
911   and     d.lookup_type        = ''REGISTERED_DISABLED''
912   and     d.lookup_code        = nvl(PEOPLE.registered_disabled_flag,''N'')
913   and     d.application_id     = 800
914   and     e.lookup_type     (+)= ''HOME_OFFICE''
915   and     e.lookup_code     (+)= PEOPLE.expense_check_send_to_address
916   and     e.application_id  (+)= 800
917   and     f.lookup_type     (+)= ''MAR_STATUS''
918   and     f.lookup_code     (+)= PEOPLE.marital_status
919   and     f.application_id  (+)= 800
920   and     g.lookup_type     (+)= ''NATIONALITY''
921   and     g.lookup_code     (+)= PEOPLE.nationality
922   and     g.application_id  (+)= 800
923   and     h.lookup_type     (+)= ''SEX''
924   and     h.lookup_code     (+)= PEOPLE.sex
925   and     h.application_id  (+)= 800
926   and     i.lookup_type     (+)= ''TITLE''
927   and     i.lookup_code     (+)= PEOPLE.title
928   and     i.application_id  (+)= 800
929   and     SES.session_id       = USERENV(''SESSIONID'')';
930     --
931     insert_route ('SEH_PER_PERSON_DETAILS',
932                   'person details route',
933                   l_text);
934     --
935     insert_route_context_usages (l_date_earned_context_id, 1);
936     insert_route_context_usages (l_assign_id_context_id,   2);
937     --
938     insert_user_entity ('PERSON_DETAILS',
939                         'person details for an assignment');
940     --
941     -- insert database items for the route defined above:
942     --
943     -- Moved all the database items to SEH_PER_PERSON_DETAILS_PERF
944     --
945     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
946     --                                                            +
947     -- Route for person details : SEH_PER_PERSON_DETAILS_PERF     +
948     --                                                            +
949     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
950     --
951     l_text := '/* Person details */
952           per_all_people_f       PEOPLE
953   ,       per_person_types       PTYPE
954   ,       per_phones             PHONE
955   ,       fnd_sessions           SES
956   ,       hr_lookups             a
957   ,       hr_lookups             c
958   ,       hr_lookups             d
959   ,       per_all_assignments_f  ASSIGN
960   where   &B1 BETWEEN ASSIGN.effective_start_date
961                    AND ASSIGN.effective_end_date
962   and     ASSIGN.assignment_id = &B2
963   and     PEOPLE.person_id     = ASSIGN.person_id
964   and     &B1 BETWEEN PEOPLE.effective_start_date
965                    AND PEOPLE.effective_end_date
966   and     PTYPE.person_type_id = PEOPLE.person_type_id
967   and     PHONE.parent_id (+) = PEOPLE.person_id
968   AND     PHONE.parent_table (+)= ''PER_PEOPLE_F''
969   and     PHONE.phone_type (+)= ''W1''
970   AND     &B1 BETWEEN NVL(PHONE.date_from(+),&B1)
971                    AND NVL(PHONE.date_to(+),&B1)
972   and     a.lookup_type        = ''YES_NO''
973   and     a.lookup_code        = nvl(PEOPLE.current_applicant_flag,''N'')
974   and     a.application_id     = 800
975   and     c.lookup_type        = ''YES_NO''
976   and     c.lookup_code        = nvl(PEOPLE.current_employee_flag,''N'')
977   and     c.application_id     = 800
978   and     d.lookup_type        = ''REGISTERED_DISABLED''
979   and     d.lookup_code        = nvl(PEOPLE.registered_disabled_flag,''N'')
980   and     d.application_id     = 800
981   and     SES.session_id       = USERENV(''SESSIONID'')';
982     --
983     insert_route ('SEH_PER_PERSON_DETAILS_PERF',
984                   'person details route (performant version)',
985                   l_text);
986     --
987     insert_route_context_usages (l_date_earned_context_id, 1);
988     insert_route_context_usages (l_assign_id_context_id,   2);
989     --
990     insert_user_entity ('PERSON_DETAILS_PERF',
991                         'person details for an assignment (performant version)');
992     --
993     -- insert database items for the route defined above:
994     --
995     insert_database_item ('PER_PERSON_TYPE',
996                           'PTYPE.user_person_type',
997                           'Type of person, eg. employee, applicant, etc.',
998                           'T',
999                           'N');
1000     --
1001     insert_database_item ('PTU_PER_PERSON_TYPE',
1002                           'hr_person_type_usage_info.get_user_person_type(SES.effective_date, PEOPLE.person_id) user_person_type',
1003                           'Type of person, eg. employee, applicant, etc.',
1004                           'T',
1005                           'N');
1006     --
1007     insert_database_item ('PER_LAST_NAME',
1008                           'PEOPLE.last_name',
1009                           'The person''s last name',
1010                           'T',
1011                           'N');
1012     --
1013     insert_database_item ('PER_FIRST_NAME',
1014                           'PEOPLE.first_name',
1015                           'The person''s first name',
1016                           'T',
1017                           'Y');
1018     --
1019     insert_database_item ('PER_KNOWN_AS',
1020                           'PEOPLE.known_as',
1021                           'The person''s preferred name',
1022                           'T',
1023                           'Y');
1024     --
1025     insert_database_item ('PER_MIDDLE_NAMES',
1026                           'PEOPLE.middle_names',
1027                           'The person''s middle names',
1028                           'T',
1029                           'Y');
1030     --
1031     insert_database_item ('PER_FULL_NAME',
1032                           'PEOPLE.full_name',
1033                           'The person''s full name',
1034                           'T',
1035                           'Y');
1036     --
1037     insert_database_item ('PER_APPLICANT_NUMBER',
1038                           'PEOPLE.applicant_number',
1039                           'The person''s applicant number',
1040                           'T',
1041                           'Y');
1042     --
1043     insert_database_item ('PER_DATE_VERIFIED',
1044                           'PEOPLE.date_employee_data_verified',
1045          'The date the employee last verified his/her personal data',
1046                           'D',
1047                           'Y');
1048     --
1049     insert_database_item ('PER_DATE_OF_BIRTH',
1050                           'PEOPLE.date_of_birth',
1051                           'The person''s date of birth',
1052                           'D',
1053                           'Y');
1054     --
1055     insert_database_item ('PER_EMP_NUMBER',
1056                           'PEOPLE.employee_number',
1057                           'The person''s employee number',
1058                           'T',
1059                           'Y');
1060     --
1061     insert_database_item ('PER_NATIONAL_IDENTIFIER',
1062                           'PEOPLE.national_identifier',
1063                           'The person''s national identifier',
1064                           'T',
1065                           'Y');
1066     --
1067     insert_database_item ('PER_PREV_LAST_NAME',
1068                           'PEOPLE.previous_last_name',
1069                           'The person''s previous last name',
1070                           'T',
1071                           'Y');
1072     --
1073     insert_database_item ('PER_WORK_PHONE',
1074                           'NVL(PHONE.phone_number,PEOPLE.work_telephone)',
1075                           'The person''s work telephone number',
1076                           'T',
1077                           'Y');
1078     --
1079     insert_database_item ('PER_MAIL_DESTINATION',
1080                           'PEOPLE.expense_check_send_to_address',
1081                           'The person''s mail destination',
1082                           'T',
1083                           'Y');
1084     --
1085     insert_database_item ('PER_AGE',
1086           'TRUNC(MONTHS_BETWEEN(SES.EFFECTIVE_DATE, PEOPLE.date_of_birth)/12)',
1087                           'The person''s age',
1088                           'N',
1089                           'Y');
1090     --
1091     insert_database_item ('PER_CURRENT_APP',
1092                           'a.meaning',
1093                        'Whether the person is a current applicant (yes/no)',
1094                           'T',
1095                           'Y');
1096     --
1097     insert_database_item ('PER_CURRENT_EMP',
1098                           'c.meaning',
1099                  'Whether the person is a current employee (yes/no)',
1100                           'T',
1101                           'Y');
1102     --
1103     insert_database_item ('PER_DISABLED',
1104                           'd.meaning',
1105                           'Whether the person is disabled (yes/no)',
1106                           'T',
1107                           'Y');
1108     --
1109     insert_database_item ('PER_SEND_EXPENSES',
1110         		  'hr_general.decode_lookup(''HOME_OFFICE'',
1111         		      PEOPLE.expense_check_send_to_address)',
1112                     'Where to send the person''s expenses (home/office)',
1113                           'T',
1114                           'Y');
1115     --
1116     insert_database_item ('PER_MARITAL_STATUS',
1117                           'hr_general.decode_lookup(''MAR_STATUS'',
1118                          	 PEOPLE.marital_status)',
1119                           'The person''s maritial status',
1120                           'T',
1121                           'Y');
1122     --
1123     insert_database_item ('PER_NATIONALITY',
1124                           'hr_general.decode_lookup(''NATIONALITY'',
1125                           	PEOPLE.nationality)',
1126                           'The person''s nationality',
1127                           'T',
1128                           'Y');
1129     --
1130     insert_database_item ('PER_SEX',
1131                           'hr_general.decode_lookup(''SEX'',PEOPLE.sex)',
1132                           'The person''s sex',
1133                           'T',
1134                           'Y');
1135     --
1136     insert_database_item ('PER_TITLE',
1137                           'hr_general.decode_lookup(''TITLE'',PEOPLE.title)',
1138                           'The person''s title',
1139                           'T',
1140                           'Y');
1141     --
1142     insert_database_item ('PER_PREFIX',
1143                           'PEOPLE.pre_name_adjunct',
1144                           'The employee''s name prefix',
1145                           'T',
1146                           'Y');
1147     --
1148     insert_database_item ('PER_SUFFIX',
1149                           'PEOPLE.suffix',
1150                           'The employee''s name suffix',
1151                           'T',
1152                           'Y');
1153     --
1154     insert_database_item ('PER_1099R_NAME',
1155                           '''TRANSFER_LN=''||people.last_name||''TRANSFER_FN=''||
1156                             people.first_name||''TRANSFER_MN=''|| people.middle_names||
1157                             ''TRANSFER_SSN=''||people.national_identifier',
1158                           'Employee Details for 1099R',
1159                           'T',
1160                           'N');
1161     --
1162     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1163     --                                                       +
1164     -- Route for person details : SEH_PER_PERSON_DETAILS_2   +
1165     --                                                       +
1166     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1167     --
1168     l_text := '/* Person details */
1169         per_all_assignments_f           ASSIGN
1170        ,per_all_people_f                PEOPLE
1171        ,hr_lookups                      HL1
1172        ,hr_lookups                      HL2
1173        ,hr_lookups                      HL3
1174        ,fnd_sessions                    SES
1175 where   &B1 BETWEEN ASSIGN.effective_start_date
1176                  AND ASSIGN.effective_end_date
1177 and     ASSIGN.assignment_id           = &B2
1178 and     PEOPLE.person_id               = ASSIGN.person_id
1179 and     &B1 BETWEEN PEOPLE.effective_start_date
1180                  AND PEOPLE.effective_end_date
1181 and     HL1.application_id           (+)= 800
1182 and     HL1.lookup_type              (+)= ''YES_NO''
1183 and     HL1.lookup_code              (+)= nvl(PEOPLE.coord_ben_no_cvg_flag,''N'')
1184 and     HL2.application_id           (+)= 800
1185 and     HL2.lookup_type              (+)= ''YES_NO''
1186 and     HL2.lookup_code              (+)= nvl(PEOPLE.dpdnt_vlntry_svce_flag,''N'')
1187 and     HL3.application_id           (+)= 800
1188 and     HL3.lookup_type              (+)= ''TOBACCO_USER''
1189 and     HL3.lookup_code              (+)= PEOPLE.uses_tobacco_flag
1190 and     SES.session_id                  = USERENV(''sessionid'')';
1191     --
1192     insert_route ('SEH_PER_PERSON_DETAILS_2',
1193                   'person details',
1194                   l_text);
1195     --
1196     insert_route_context_usages (l_date_earned_context_id, 1);
1197     insert_route_context_usages (l_assign_id_context_id,   2);
1198     --
1199     insert_user_entity ('PERSON_DETAILS_2',
1200                         'person details 2');
1201     --
1202     -- insert database items for the route defined above:
1203     --
1204     -- Moved all the database items to PEOPLE.uses_tobacco_flag
1205     --
1206     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1207     --                                                            +
1208     -- Route for person details : SEH_PER_PERSON_DETAILS_2_PERF   +
1209     --                                                            +
1210     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1211     --
1212     l_text := '/* Person details */
1213         per_all_assignments_f           ASSIGN
1214        ,per_all_people_f                PEOPLE
1215        ,fnd_sessions                    SES
1216 where   &B1 BETWEEN ASSIGN.effective_start_date
1217                  AND ASSIGN.effective_end_date
1218 and     ASSIGN.assignment_id           = &B2
1219 and     PEOPLE.person_id               = ASSIGN.person_id
1220 and     &B1 BETWEEN PEOPLE.effective_start_date
1221                  AND PEOPLE.effective_end_date
1222 and     SES.session_id                  = USERENV(''sessionid'')';
1223     --
1224     insert_route ('SEH_PER_PERSON_DETAILS_2_PERF',
1225                   'person details (performant version)',
1226                   l_text);
1227     --
1228     insert_route_context_usages (l_date_earned_context_id, 1);
1229     insert_route_context_usages (l_assign_id_context_id,   2);
1230     --
1231     insert_user_entity ('PERSON_DETAILS_2_PERF',
1232                         'person details 2 (performant version)');
1233     --
1234     -- insert database items for the route defined above:
1235     --
1236     insert_database_item ('PER_DPDNT_ADOPTION_DATE',
1237                           'PEOPLE.DPDNT_ADOPTION_DATE',
1238                           'Dependents Adoption Date',
1239                           'D',
1240                           'Y');
1241     --
1242     insert_database_item ('PER_RECEIPT_OF_DEATH_CERT_DATE',
1243                           'PEOPLE.RECEIPT_OF_DEATH_CERT_DATE',
1244                           'Date of receipt of the persons death certificate',
1245                           'D',
1246                           'Y');
1247     --
1248     insert_database_item ('PER_ORIGINAL_DATE_OF_HIRE',
1249                           'PEOPLE.ORIGINAL_DATE_OF_HIRE',
1250                           'Date the person was first hired',
1251                           'D',
1252                           'Y');
1253     --
1254     insert_database_item ('PER_DATE_OF_DEATH',
1255                           'PEOPLE.DATE_OF_DEATH',
1256                           'Persons date of death',
1257                           'D',
1258                           'Y');
1259     --
1260     insert_database_item ('PER_COORD_BEN_MED_PLN_NO',
1261                           'PEOPLE.COORD_BEN_MED_PLN_NO',
1262                           'Coordination of Benefits Medical Plan Number',
1263                           'T',
1264                           'Y');
1265     --
1266     insert_database_item ('PER_COORD_BEN_NO_CVG_FLAG',
1267                           'hr_general.decode_lookup(''YES_NO'',
1268                           	nvl(PEOPLE.coord_ben_no_cvg_flag,''N''))',
1269                           'Coordination of Benefits No Other Coverage',
1270                           'T',
1271                           'Y');
1272     --
1273     insert_database_item ('PER_DPDNT_VLNTRY_SVCE_FLAG',
1274                           'hr_general.decode_lookup(''YES_NO'',
1275                            	nvl(PEOPLE.dpdnt_vlntry_svce_flag,''N''))',
1276                           'Dependant on voluntary service',
1277                           'T',
1278                           'Y');
1279     --
1280     insert_database_item ('PER_BENEFIT_GROUP_ID',
1281                           'PEOPLE.BENEFIT_GROUP_ID',
1282                           'Benefit Group ID',
1283                           'N',
1284                           'Y');
1285     --
1286     insert_database_item ('PER_USES_TOBACCO_FLAG',
1287                           'hr_general.decode_lookup(''TOBACCO_USER'',
1288                           	PEOPLE.uses_tobacco_flag)',
1289                           'Uses Tobacco Flag',
1290                           'T',
1291                           'Y');
1292     --
1293     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1294     --                                                               +
1295     -- Route for person period of service : SEH_EMP_PERSON_SERVICE_1 +
1296     --                                                               +
1297     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1298     --
1299     -- This route has been split into 2 for performance purposes.  The date
1300     -- DB items are used in the payroll formulae.
1301     --
1302     l_text := '/* Person current period of service date details */
1303         per_all_assignments_f                   ASSIGN
1304 ,       per_periods_of_service                  SERVICE
1305 where   &B1 BETWEEN ASSIGN.effective_start_date
1306                  AND ASSIGN.effective_end_date
1307 and     ASSIGN.assignment_id                  = &B2
1308 and     SERVICE.period_of_Service_id       (+)= ASSIGN.period_of_service_id';
1309     --
1310     insert_route ('SEH_EMP_PERSON_SERVICE_1',
1311                   'employee person period of service route 1 (date details)',
1312                   l_text);
1313     --
1314     insert_route_context_usages (l_date_earned_context_id, 1);
1315     insert_route_context_usages (l_assign_id_context_id,   2);
1316     --
1317     insert_user_entity ('EMPLOYEE_PERSON_SERVICE_DETAILS_1',
1318                         'employee person current service date details');
1319     --
1320     -- insert database items for the route defined above:
1321     --
1322     insert_database_item ('EMP_HIRE_DATE',
1323                           'SERVICE.date_start',
1324                           'The employee''s hire date',
1325                           'D',
1326                           'Y');
1327     --
1328     insert_database_item ('EMP_TERM_DATE',
1329                           'SERVICE.actual_termination_date',
1330                           'The employee''s termination date',
1331                           'D',
1332                           'Y');
1333     --
1334     insert_database_item ('EMP_LAST_PROCESS_DATE',
1335                           'SERVICE.last_standard_process_date',
1336                           'The date the employee was last processed',
1337                           'D',
1338                           'Y');
1339     --
1340     insert_database_item ('EMP_PROJ_TERM_DATE',
1341                           'SERVICE.projected_termination_date',
1342                           'The employee''s projected termination date',
1343                           'D',
1344                           'Y');
1345     --
1346     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1347     --                                                               +
1348     -- Route for person period of service : SEH_EMP_PERSON_SERVICE_2 +
1349     --                                                               +
1350     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1351     --
1352     l_text := '/* Person current period of service other details */
1353         per_all_assignments_f                   ASSIGN
1354 ,       per_periods_of_service                  SERVICE
1355 ,       per_all_people_f                        PEOPLE
1356 ,       hr_lookups                              LOOK1
1357 where   &B1 BETWEEN ASSIGN.effective_start_date
1358                  AND ASSIGN.effective_end_date
1359 and     ASSIGN.assignment_id                  = &B2
1360 and     SERVICE.period_of_Service_id       (+)= ASSIGN.period_of_service_id
1361 and     LOOK1.lookup_code                  (+)= SERVICE.leaving_reason
1362 and     LOOK1.lookup_type                  (+)= ''LEAV_REAS''
1363 and     LOOK1.application_id               (+)= 800
1364 and     PEOPLE.person_id           (+)= SERVICE.termination_accepted_person_id
1365 and     &B1 between nvl (PEOPLE.effective_start_date, &B1)
1366                  and nvl (PEOPLE.effective_end_date, &B1)';
1367     --
1368     insert_route ('SEH_EMP_PERSON_SERVICE_2',
1369                   'employee person period of service route (other details)',
1370                   l_text);
1371     --
1372     insert_route_context_usages (l_date_earned_context_id, 1);
1373     insert_route_context_usages (l_assign_id_context_id,   2);
1374     --
1375     insert_user_entity ('EMPLOYEE_PERSON_SERVICE_DETAILS_2',
1376                         'employee person current service other details');
1377     --
1378     -- insert database items for the route defined above:
1379     --
1380     insert_database_item ('EMP_LEAVING_REASON',
1381                           'LOOK1.meaning',
1382                           'The reason the employee left',
1383                           'T',
1384                           'Y');
1385     --
1386     insert_database_item ('EMP_TERM_ACCEPTED_BY',
1387                           'PEOPLE.full_name',
1388                           'The person who accepted the employee''s notice',
1389                           'T',
1390                           'Y');
1391     --
1392     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1393     --                                                           +
1394     -- Route for person address details : SEH_PER_PERSON_ADDRESS +
1395     --                                                           +
1396     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1397     --
1398     l_text := '/* Person address details */
1399 	per_all_assignments_f  ASSIGN
1400 ,	per_addresses          ADDR
1401 ,	fnd_territories_tl     a
1402 where	&B1 BETWEEN ASSIGN.effective_start_date
1403                  AND ASSIGN.effective_end_date
1404 and     ASSIGN.assignment_id   = &B2
1405 and	ADDR.person_id      (+)= ASSIGN.person_id
1406 and	ADDR.primary_flag   (+)= ''Y''
1407 and     &B1 BETWEEN nvl(ADDR.date_from, &B1)
1408                  AND nvl(ADDR.date_to, &B1)
1409 and	a.territory_code    (+)= ADDR.country
1410 and 	a.language          (+)= userenv(''LANG'')';
1411     --
1412     insert_route ('SEH_PER_PERSON_ADDRESS',
1413                   'employee person address route',
1414                   l_text);
1415     --
1416     insert_route_context_usages (l_date_earned_context_id, 1);
1417     insert_route_context_usages (l_assign_id_context_id,   2);
1418     --
1419     insert_user_entity ('EMPLOYEE_PERSON_ADDRESS_DETAILS',
1420                         'employee person address details');
1421     --
1422     -- insert database items for the route defined above:
1423     --
1424     --
1425     insert_database_item ('PER_ADR_DATE_FROM',
1426                           'ADDR.date_from',
1427      'The first date on which the person can be contacted at this address',
1428                           'D',
1429                           'Y');
1430     --
1431     insert_database_item ('PER_ADR_DATE_TO',
1432                           'ADDR.date_to',
1433         'The last date on which the person can be contacted at this address',
1434                           'D',
1435                           'Y');
1436     --
1437     insert_database_item ('PER_ADR_LINE_1',
1438                           'ADDR.address_line1',
1439                           'The first line of the person''s address',
1440                           'T',
1441                           'Y');
1442     --
1443     insert_database_item ('PER_ADR_LINE_2',
1444                           'ADDR.address_line2',
1445                           'The second line of the person''s address',
1446                           'T',
1447                           'Y');
1448     --
1449     insert_database_item ('PER_ADR_LINE_3',
1450                           'ADDR.address_line3',
1451                           'The third line of the person''s address',
1452                           'T',
1453                           'Y');
1454     --
1455     insert_database_item ('PER_ADR_CITY',
1456                           'ADDR.town_or_city',
1457                           'The name of the person''s town or city',
1458                           'T',
1459                           'Y');
1460     --
1461     insert_database_item ('PER_ADR_REGION_1',
1462                           'ADDR.region_1',
1463                           'The first line of the person''s region',
1464                           'T',
1465                           'Y');
1466     --
1467     insert_database_item ('PER_ADR_REGION_2',
1468                           'ADDR.region_2',
1469                           'The second line of the person''s region',
1470                           'T',
1471                           'Y');
1472     --
1473     insert_database_item ('PER_ADR_REGION_3',
1474                           'ADDR.region_3',
1475                           'The third line of the person''s region',
1476                           'T',
1477                           'Y');
1478     --
1479     insert_database_item ('PER_ADR_POSTAL_CODE',
1480                           'ADDR.postal_code',
1481                           'The person''s postal code',
1482                           'T',
1483                           'Y');
1484     --
1485     insert_database_item ('PER_ADR_PHONE_1',
1486                           'ADDR.TELEPHONE_NUMBER_1',
1487                           'The person''s first contact number',
1488                           'T',
1489                           'Y');
1490     --
1491     insert_database_item ('PER_ADR_PHONE_2',
1492                           'ADDR.TELEPHONE_NUMBER_2',
1493                           'The person''s second contact number',
1494                           'T',
1495                           'Y');
1496     --
1497     insert_database_item ('PER_ADR_PHONE_3',
1498                           'ADDR.TELEPHONE_NUMBER_3',
1499                           'The person''s third contact number',
1500                           'T',
1501                           'Y');
1502     --
1503     insert_database_item ('PER_ADR_COUNTRY',
1504                           'a.territory_short_name',
1505                           'The name of the person''s country',
1506                           'T',
1507                           'Y');
1508     --
1509     insert_database_item ('PER_ADR_COUNTRY_CODE',
1510                           'a.territory_code',
1511                           '** Person''s country code **',
1512                           'T',
1513                           'Y');
1514     --
1515     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1516     --                                                              +
1517     -- Route for person assignment details : SEH_ASS_PERSON_DETAILS +
1518     --                                                              +
1519     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1520     --
1521 
1522    l_text := '/* Person assignment details */
1523         per_grades                       GRADE
1524 ,       per_jobs                         JOB
1525 ,       per_assignment_status_types      AST
1526 ,       pay_all_payrolls_f               PAYROLL
1527 ,       hr_locations                     LOC
1528 ,       hr_all_organization_units        ORG
1529 ,       pay_people_groups                GRP
1530 ,       per_all_vacancies                VAC
1531 ,       per_all_people_f                 PEOPLE1
1532 ,       per_all_people_f                 PEOPLE2
1533 ,       hr_all_positions_f               POS1
1534 ,       hr_all_positions_f               POS2
1535 ,       hr_all_positions_f               POS3
1536 ,       hr_lookups                       HR1
1537 ,       hr_lookups                       HR2
1538 ,       hr_lookups                       HR4
1539 ,       hr_lookups                       HR5
1540 ,       hr_lookups                       HR6
1541 ,       hr_lookups                       HR7
1542 ,       hr_lookups                       FND1
1543 ,       hr_lookups                       FND2
1544 ,       per_all_assignments_f            ASSIGN
1545 where   &B1 BETWEEN ASSIGN.effective_start_date
1546                  AND ASSIGN.effective_end_date
1547 and     &B1 BETWEEN POS1.effective_start_date(+)
1548                  AND POS1.effective_end_date(+)
1549 and     &B1 BETWEEN POS2.effective_start_date(+)
1550                  AND POS2.effective_end_date(+)
1551 and     &B1 BETWEEN POS3.effective_start_date(+)
1552                  AND POS3.effective_end_date(+)
1553 and     ASSIGN.assignment_id           = &B2
1554 and     GRADE.grade_id              (+)= ASSIGN.grade_id
1555 and     JOB.job_id                  (+)= ASSIGN.job_id
1556 and     AST.assignment_status_type_id  = ASSIGN.assignment_status_type_id
1557 and     PAYROLL.payroll_id          (+)= ASSIGN.payroll_id
1558 and     &B1 between nvl (PAYROLL.effective_start_date, &B1)
1559                  and nvl (PAYROLL.effective_end_date, &B1)
1560 and     LOC.location_id             (+)= ASSIGN.location_id
1561 and     ORG.organization_id            = ASSIGN.organization_id
1562 and     GRP.people_group_id         (+)= ASSIGN.people_group_id
1563 and     VAC.vacancy_id              (+)= ASSIGN.vacancy_id
1564 and     HR1.lookup_code                = ASSIGN.assignment_type
1565 and     HR1.lookup_type                = ''EMP_APL''
1566 and     HR1.application_id             = 800
1567 and     HR2.lookup_code             (+)= ASSIGN.probation_unit
1568 and     HR2.lookup_type             (+)= ''UNITS''
1569 and     HR2.application_id          (+)= 800
1570 and     FND1.lookup_code               = ASSIGN.primary_flag
1571 and     FND1.lookup_type               = ''YES_NO''
1572 and     FND1.application_id            = 800
1573 and     FND2.lookup_code            (+)= ASSIGN.manager_flag
1574 and     FND2.lookup_type            (+)= ''YES_NO''
1575 and     FND2.application_id         (+)= 800
1576 and     PEOPLE1.person_id           (+)= ASSIGN.recruiter_id
1577 and     PEOPLE2.person_id           (+)= ASSIGN.supervisor_id
1578 and     POS1.position_id            (+)= ASSIGN.position_id
1579 and     HR4.lookup_code             (+)= POS1.frequency
1580 and     HR4.lookup_type             (+)= ''FREQUENCY''
1581 and     HR4.application_id          (+)= 800
1582 and     HR5.lookup_code             (+)= ASSIGN.employment_category
1583 and     HR5.lookup_type             (+)= ''EMP_CAT''
1584 and     HR5.application_id          (+)= 800
1585 and     HR6.lookup_code             (+)= ASSIGN.perf_review_period_frequency
1586 and     HR6.lookup_type             (+)= ''FREQUENCY''
1587 and     HR6.application_id          (+)= 800
1588 and     HR7.lookup_code             (+)= ASSIGN.sal_review_period_frequency
1589 and     HR7.lookup_type             (+)= ''FREQUENCY''
1590 and     HR7.application_id          (+)= 800
1591 and     POS2.position_id            (+)= POS1.successor_position_id
1592 and     POS3.position_id            (+)= POS1.relief_position_id';
1593     --
1594     insert_route ('SEH_ASS_PERSON_DETAILS',
1595                   'person assignment route',
1596                   l_text);
1597     --
1598     insert_route_context_usages (l_date_earned_context_id, 1);
1599     insert_route_context_usages (l_assign_id_context_id,   2);
1600     --
1601     insert_user_entity ('PERSON_ASSIGNMENT_DETAILS',
1602                         'person assignment details');
1603     --
1604     -- insert database items for the route defined above:
1605     --
1606     --
1607     -- Moved all the database items to SEH_ASS_PERSON_DETAILS_PERF
1608     --
1609     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1610     --                                                                   +
1611     -- Route for person assignment details : SEH_ASS_PERSON_DETAILS_PERF +
1612     --                                                                   +
1613     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1614     --
1615 
1616    l_text := '/* Person assignment details */
1617         per_grades                       GRADE
1618 ,       per_jobs                         JOB
1619 ,       per_assignment_status_types      AST
1620 ,       pay_all_payrolls_f               PAYROLL
1621 ,       hr_locations                     LOC
1622 ,       hr_all_organization_units        ORG
1623 ,       pay_people_groups                GRP
1624 ,       per_all_vacancies                VAC
1625 ,       per_all_people_f                 PEOPLE1
1626 ,       per_all_people_f                 PEOPLE2
1627 ,       hr_all_positions_f               POS1
1628 ,       hr_all_positions_f               POS2
1629 ,       hr_all_positions_f               POS3
1630 ,       hr_lookups                       HR1
1631 ,       hr_lookups                       FND1
1632 ,       per_all_assignments_f            ASSIGN
1633 where   &B1 BETWEEN ASSIGN.effective_start_date
1634                  AND ASSIGN.effective_end_date
1635 and     &B1 BETWEEN POS1.effective_start_date(+)
1636                  AND POS1.effective_end_date(+)
1637 and     &B1 BETWEEN POS2.effective_start_date(+)
1638                  AND POS2.effective_end_date(+)
1639 and     &B1 BETWEEN POS3.effective_start_date(+)
1640                  AND POS3.effective_end_date(+)
1641 and     ASSIGN.assignment_id           = &B2
1642 and     GRADE.grade_id              (+)= ASSIGN.grade_id
1643 and     JOB.job_id                  (+)= ASSIGN.job_id
1644 and     AST.assignment_status_type_id  = ASSIGN.assignment_status_type_id
1645 and     PAYROLL.payroll_id          (+)= ASSIGN.payroll_id
1646 and     &B1 between nvl (PAYROLL.effective_start_date, &B1)
1647                  and nvl (PAYROLL.effective_end_date, &B1)
1648 and     LOC.location_id             (+)= ASSIGN.location_id
1649 and     ORG.organization_id            = ASSIGN.organization_id
1650 and     GRP.people_group_id         (+)= ASSIGN.people_group_id
1651 and     VAC.vacancy_id              (+)= ASSIGN.vacancy_id
1652 and     HR1.lookup_code                = ASSIGN.assignment_type
1653 and     HR1.lookup_type                = ''EMP_APL''
1654 and     HR1.application_id             = 800
1655 and     FND1.lookup_code               = ASSIGN.primary_flag
1656 and     FND1.lookup_type               = ''YES_NO''
1657 and     FND1.application_id            = 800
1658 and     PEOPLE1.person_id           (+)= ASSIGN.recruiter_id
1659 and     PEOPLE2.person_id           (+)= ASSIGN.supervisor_id
1660 and     POS1.position_id            (+)= ASSIGN.position_id
1661 and     POS2.position_id            (+)= POS1.successor_position_id
1662 and     POS3.position_id            (+)= POS1.relief_position_id';
1663     --
1664     insert_route ('SEH_ASS_PERSON_DETAILS_PERF',
1665                   'person assignment route (performant version)',
1666                   l_text);
1667     --
1668     insert_route_context_usages (l_date_earned_context_id, 1);
1669     insert_route_context_usages (l_assign_id_context_id,   2);
1670     --
1671     insert_user_entity ('PERSON_ASSIGNMENT_DETAILS_PERF',
1672                         'person assignment details ( performant version )');
1673     --
1674     -- insert database items for the route defined above:
1675     --
1676     --
1677     insert_database_item ('ASG_GRADE',
1678                           'GRADE.name',
1679                           'The employee''s grade',
1680                           'T',
1681                           'Y');
1682     --
1683     insert_database_item ('ASG_GRADE_DATE_FROM',
1684                           'GRADE.date_from',
1685           'The date from which this assignment grade information is effective',
1686                           'D',
1687                           'Y');
1688     --
1689     insert_database_item ('ASG_GRADE_DATE_TO',
1690                           'GRADE.date_to',
1691            'The date to which this assignment grade information is effective',
1692                           'D',
1693                           'Y');
1694     --
1695     insert_database_item ('ASG_JOB',
1696                           'JOB.name',
1697                           'The employee''s job',
1698                           'T',
1699                           'Y');
1700     --
1701     insert_database_item ('ASG_JOB_DATE_FROM',
1702                           'JOB.date_from',
1703             'The date from which this assignment job information is effective',
1704                           'D',
1705                           'Y');
1706     --
1707     insert_database_item ('ASG_JOB_DATE_TO',
1708                           'JOB.date_to',
1709              'The date to which this assignment job information is effective',
1710                           'D',
1711                           'Y');
1712     --
1713     insert_database_item ('ASG_STATUS',
1714                           'AST.user_status',
1715                           'The primary status for the assignment',
1716                           'T',
1717                           'N');
1718     --
1719     insert_database_item ('ASG_PAYROLL',
1720                           'PAYROLL.payroll_name',
1721                           'The employee''s payroll',
1722                           'T',
1723                           'Y');
1724     --
1725     insert_database_item ('ASG_LOCATION',
1726                           'LOC.location_code',
1727                           'The employee''s location',
1728                           'T',
1729                           'Y');
1730     --
1731     insert_database_item ('ASG_LOC_INACTIVE_DATE',
1732                           'LOC.inactive_date',
1733                     'The date to which the location information is effective',
1734                           'D',
1735                           'Y');
1736     --
1737     insert_database_item ('ASG_ORG',
1738                           'ORG.name',
1739                           'The employee''s organization',
1740                           'T',
1741                           'N');
1742     --
1743     insert_database_item ('ASG_ORG_DATE_FROM',
1744                           'ORG.date_from',
1745        'The date from which assignment organization information is effective',
1746                           'D',
1747                           'N');
1748     --
1749     insert_database_item ('ASG_ORG_DATE_TO',
1750                           'ORG.date_to',
1751          'The date to which assignment organization information is effective',
1752                           'D',
1753                           'Y');
1754     --
1755     insert_database_item ('ASG_GROUP',
1756                           'GRP.group_name',
1757                           'The employee''s group',
1758                           'T',
1759                           'Y');
1760     --
1761     insert_database_item ('ASG_VACANCY',
1762                           'VAC.name',
1763                           'The name of the vacancy applied for',
1764                           'T',
1765                           'Y');
1766     --
1767     insert_database_item ('ASG_TYPE',
1768                           'HR1.meaning',
1769                          'Whether this assignment is an employee or applicant',
1770                           'T',
1771                           'Y');
1772     --
1773     insert_database_item ('ASG_PROB_UNITS',
1774                           'hr_general.decode_lookup(''UNITS'',
1775                           	ASSIGN.probation_unit)',
1776                           'The units of the assignment''s probation period',
1777                           'T',
1778                           'Y');
1779     --
1780     insert_database_item ('ASG_PRIMARY',
1781                           'FND1.meaning',
1782                 	  'Whether this is the employee''s primary assignment (yes/no)',
1783                           'T',
1784                           'N');
1785     --
1786     insert_database_item ('ASG_MANAGER',
1787                           'hr_general.decode_lookup(''YES_NO'',
1788                           		ASSIGN.manager_flag)',
1789                'Whether the assignment is a managerial assignment (yes/no)',
1790                           'T',
1791                           'Y');
1792     --
1793     insert_database_item ('ASG_POSITION',
1794                           'POS1.name',
1795                           'The employee''s position',
1796                           'T',
1797                           'Y');
1798     --
1799     insert_database_item ('ASG_POS_DATE_FROM',
1800                           'POS1.date_effective',
1801       'The date from which this assignment position information is effective',
1802                           'D',
1803                           'Y');
1804     --
1805     insert_database_item ('ASG_POS_DATE_TO',
1806                           'POS1.date_end',
1807         'The date to which this assignment position information is effective',
1808                           'D',
1809                           'Y');
1810     --
1811     insert_database_item ('ASG_POS_HOURS',
1812                           'POS1.working_hours',
1813                      'The standard number of working hours for the position',
1814                           'N',
1815                           'Y');
1816     --
1817     insert_database_item ('ASG_POS_START_TIME',
1818                           'POS1.time_normal_start',
1819                        'The standard start time for the assignment position',
1820                           'T',
1821                           'Y');
1822     --
1823     insert_database_item ('ASG_POS_END_TIME',
1824                           'POS1.time_normal_finish',
1825                           'The standard end time for the assignment position',
1826                           'T',
1827                           'Y');
1828     --
1829     insert_database_item ('ASG_POS_PROB_PERIOD',
1830                           'POS1.probation_period',
1831                           'The probation period for the assignment position',
1832                           'N',
1833                           'Y');
1834     --
1835     insert_database_item ('ASG_POS_FREQ',
1836                           'hr_general.decode_lookup(''FREQUENCY'',
1837                           	POS1.frequency)',
1838        'The frequency for which the assignment position''s hours is measured',
1839                           'T',
1840                           'Y');
1841     --
1842     insert_database_item ('ASG_SUCCESSOR',
1843                           'POS2.name',
1844                       'The position name that will succeed into this position',
1845                           'T',
1846                           'Y');
1847     --
1848     insert_database_item ('ASG_RELIEF',
1849                           'POS3.name',
1850              'The relief position if the current position hoilder is absent',
1851                           'T',
1852                           'Y');
1853     --
1854     insert_database_item ('ASG_REC_FULL_NAME',
1855                           'PEOPLE1.full_name',
1856                           'The full name for the recruiter',
1857                           'T',
1858                           'Y');
1859     --
1860     insert_database_item ('ASG_SUP_FULL_NAME',
1861                           'PEOPLE2.full_name',
1862                           'The full name for the supervisor',
1863                           'T',
1864                           'Y');
1865     --
1866     -- Some salary admin DB items:
1867     --
1868     insert_database_item ('ASG_EMPLOYMENT_CATEGORY',
1869                           'hr_general.decode_lookup(''EMP_CAT'',
1870                           	ASSIGN.employment_category)',
1871                           'The employment category for the assignment',
1872                           'T',
1873                           'Y');
1874     --
1875     insert_database_item ('ASG_ASSIGNMENT_CATEGORY',
1876                           'decode(ASSIGN.employment_category
1877                                  ,''E'', hr_general.decode_lookup(''EMP_CAT'',
1878                           	         ASSIGN.employment_category)
1879                                  ,''C'', hr_general.decode_lookup(''CWK_ASG_CATEGORY'',
1880                                          ASSIGN.employment_category))',
1881                           'The assignment category for the assignment',
1882                           'T',
1883                           'Y');
1884     --
1885     insert_database_item ('ASG_PERFORMANCE_REVIEW_FREQUENCY',
1886                           'hr_general.decode_lookup(''FREQUENCY'',
1887                           	ASSIGN.perf_review_period_frequency)',
1888                  'The performance review frequency for the assignment',
1889                           'T',
1890                           'Y');
1891     --
1892     insert_database_item ('ASG_SALARY_REVIEW_FREQUENCY',
1893                           'hr_general.decode_lookup(''FREQUENCY'',
1894                           	ASSIGN.sal_review_period_frequency)',
1895                           'The salary review frequency for the assignment',
1896                           'T',
1897                           'Y');
1898     --
1899     -- BIS DBitems
1900     --
1901     insert_database_item ('ASG_PRIMARY_CODE',
1902                           'FND1.lookup_code',
1903                           'Primary Code',
1904                           'T',
1905                           'N');
1906     --
1907     insert_user_entity ('BIS_PERSON_ASSIGNMENT_DETAILS_PERF',
1908                         'person assignment details',
1909                         'Y');
1910     --
1911     insert_database_item ('ASG_EMPLOYMENT_CATEGORY_CODE',
1912                           'ASSIGN.employment_category',
1913                           'Employment Category Code',
1914                           'T',
1915                           'Y');
1916     --
1917     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1918     --                                                                +
1919     -- Route for person assignment details : SEH_ASS_PERSON_DETAILS_2 +
1920     --                                                                +
1921     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1922     --
1923     -- Split from above route to improve performance of key DB items
1924     --
1925     --
1926     l_text := '/* Person assignment details 2 */
1927 per_all_assignments_f         ASSIGN,
1928 hr_lookups                    HR3,
1929 hr_lookups                    HR4
1930 where &B1 BETWEEN ASSIGN.effective_start_date
1931                AND ASSIGN.effective_end_date
1932 and     ASSIGN.assignment_id                = &B2
1933 and     HR3.application_id               (+)= 800
1934 and     HR3.lookup_code                  (+)= ASSIGN.frequency
1935 and     HR3.lookup_type                  (+)= ''FREQUENCY''
1936 and     HR4.application_id               (+)= 800
1937 and     HR4.lookup_code                  (+)= ASSIGN.change_reason
1938 and     HR4.lookup_type                  (+)= ''EMP_ASSIGN_REASON''';
1939     --
1940     insert_route ('SEH_ASS_PERSON_DETAILS_2',
1941                   'person assignment route 2',
1942                   l_text);
1943     --
1944     insert_route_context_usages (l_date_earned_context_id, 1);
1945     insert_route_context_usages (l_assign_id_context_id,   2);
1946     --
1947     insert_user_entity ('PERSON_ASSIGNMENT_DETAILS_2',
1948                         'person assignment details 2');
1949     --
1950     -- insert database items for the route defined above:
1951     --
1952     --
1953     insert_database_item ('ASG_DATE_FROM',
1954                           'ASSIGN.effective_start_date',
1955                'The date from which this assignment information is effective',
1956                           'D',
1957                           'N');
1958     --
1959     insert_database_item ('ASG_DATE_TO',
1960                           'ASSIGN.effective_end_date',
1961                 'The date to which this assignment information is effective',
1962                           'D',
1963                           'N');
1964     --
1965     insert_database_item ('ASG_INT_ADDR_LINE',
1966                           'ASSIGN.internal_address_line',
1967                           'The internal address of the assignment',
1968                           'T',
1969                           'Y');
1970     --
1971     insert_database_item ('ASG_ASSIGNMENT_SEQUENCE',
1972                           'ASSIGN.assignment_sequence',
1973                           'This is used as a default for assignment number',
1974                           'N',
1975                           'N');
1976     --
1977     insert_database_item ('ASG_NUMBER',
1978                           'ASSIGN.assignment_number',
1979                           'The assignment number',
1980                           'T',
1981                           'Y');
1982     --
1983     insert_database_item ('ASG_PROB_END_DATE',
1984                           'ASSIGN.date_probation_end',
1985                           'The probation period end date',
1986                           'D',
1987                           'Y');
1988     --
1989     insert_database_item ('ASG_PROB_PERIOD',
1990                           'ASSIGN.probation_period',
1991                           'The assignment''s probation period',
1992                           'N',
1993                           'Y');
1994     --
1995     insert_database_item ('ASG_HOURS',
1996                           'ASSIGN.normal_hours',
1997                      'The standard number of working hours for the assignment',
1998                           'N',
1999                           'Y');
2000     --
2001     insert_database_item ('ASG_START_TIME',
2002                           'ASSIGN.time_normal_start',
2003                           'The standard start time for the assignment',
2004                           'T',
2005                           'Y');
2006     --
2007     insert_database_item ('ASG_END_TIME',
2008                           'ASSIGN.time_normal_finish',
2009                           'The standard end time for the assignment',
2010                           'T',
2011                           'Y');
2012     --
2013     insert_database_item ('ASG_PERFORMANCE_REVIEW_PERIOD',
2014                           'ASSIGN.perf_review_period',
2015                           'The performance review period for the assignment',
2016                           'N',
2017                           'Y');
2018     --
2019     insert_database_item ('ASG_SALARY_REVIEW_PERIOD',
2020                           'ASSIGN.sal_review_period',
2021                           'The salary review period for the assignment',
2022                           'N',
2023                           'Y');
2024     --
2025     insert_database_item ('ASG_FREQ',
2026                           'HR3.meaning',
2027           'The frequency for which the assignment working hours are measured',
2028                           'T',
2029                           'Y');
2030     --
2031     insert_database_item ('ASG_CHANGE_REASON',
2032                           'HR4.meaning',
2033                           'The change reason for the assignment',
2034                           'T',
2035                           'Y');
2036     --
2037     -- BIS DBitems
2038     --
2039     insert_user_entity ('BIS_PERSON_ASSIGNMENT_DETAILS_2',
2040                         'person assignment details 2',
2041                         'Y');
2042     --
2043     insert_database_item ('ASG_FREQ_CODE',
2044                           'HR3.lookup_code',
2045                           'Assignment Working Hours Frequency Code',
2046                           'T',
2047                           'Y');
2048     --
2049     --
2050     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2051     --                                                                +
2052     -- Route for person assignment details : SEH_ASS_PERSON_DETAILS_3 +
2053     --                                                                +
2054     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2055     --
2056     l_text := '/* Person assignment details 3 */
2057         per_all_assignments_f           ASSIGN
2058        ,hr_lookups                      HR1
2059        ,hr_lookups                      HR2
2060 where   &B1 BETWEEN ASSIGN.effective_start_date
2061                  AND ASSIGN.effective_end_date
2062 and     ASSIGN.assignment_id           = &B2
2063 and     HR1.application_id          (+) = 800
2064 and     HR1.lookup_type             (+) = ''YES_NO''
2065 and     HR1.lookup_code             (+) = nvl(ASSIGN.LABOUR_UNION_MEMBER_FLAG,''N'')
2066 and     HR2.application_id          (+) = 800
2067 and     HR2.lookup_type             (+) = ''BARGAINING_UNIT_CODE''
2068 and     HR2.lookup_code             (+) = ASSIGN.BARGAINING_UNIT_CODE';
2069     --
2070     insert_route ('SEH_ASS_PERSON_DETAILS_3',
2071                   'person assignment route 3',
2072                   l_text);
2073     --
2074     insert_route_context_usages (l_date_earned_context_id, 1);
2075     insert_route_context_usages (l_assign_id_context_id,   2);
2076     --
2077     insert_user_entity ('PERSON_ASSIGNMENT_DETAILS_3',
2078                         'person assignment details 3');
2079     --
2080     -- insert database items for the route defined above:
2081     --
2082     -- moved the database items to SEH_ASS_PERSON_DETAILS_3_PERF
2083     --
2084     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2085     --                                                                     +
2086     -- Route for person assignment details : SEH_ASS_PERSON_DETAILS_3_PERF +
2087     --                                                                     +
2088     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2089     --
2090     l_text := '/* Person assignment details 3 */
2091         per_all_assignments_f           ASSIGN
2092 where   &B1 BETWEEN ASSIGN.effective_start_date
2093                  AND ASSIGN.effective_end_date
2094 and     ASSIGN.assignment_id           = &B2';
2095     --
2096     insert_route ('SEH_ASS_PERSON_DETAILS_3_PERF',
2097                   'person assignment route 3 (performant version)',
2098                   l_text);
2099     --
2100     insert_route_context_usages (l_date_earned_context_id, 1);
2101     insert_route_context_usages (l_assign_id_context_id,   2);
2102     --
2103     insert_user_entity ('PERSON_ASSIGNMENT_DETAILS_3_PERF',
2104                         'person assignment details 3 (performant version)');
2105     --
2106     -- insert database items for the route defined above:
2107     --
2108     insert_database_item ('ASG_LABOUR_UNION_MEMBER_FLAG',
2109                           'hr_general.decode_lookup(''YES_NO'',
2110                           	nvl(ASSIGN.LABOUR_UNION_MEMBER_FLAG,''N''))',
2111                           'Labour Union Member',
2112                           'T',
2113                           'Y');
2114     --
2115     insert_database_item ('ASG_BARGAINING_UNIT_CODE',
2116                           'hr_general.decode_lookup(''BARGAINING_UNIT_CODE'',
2117                           	ASSIGN.BARGAINING_UNIT_CODE)',
2118                           'Bargaining Unit Code',
2119                           'T',
2120                           'Y');
2121     --
2122     --++++++++++++++++++++++++++++++++++++++++++++++++++++++
2123     --                                                     +
2124     -- Route for contact details : SEH_CON_PERSON_DETAILS  +
2125     --                                                     +
2126     --++++++++++++++++++++++++++++++++++++++++++++++++++++++
2127     --
2128     l_text := '/* contact person details */
2129         per_all_assignments_f                ASSIGN
2130 ,       per_contact_relationships            CONTACT
2131 ,       per_all_people_f                     PEOPLE
2132 ,	per_person_types                     PTYPE
2133 ,       per_phones                           PHONE
2134 ,       fnd_sessions                         SES
2135 ,	hr_lookups                           a
2136 ,	hr_lookups                           c
2137 ,	hr_lookups                           d
2138 ,       hr_lookups                           f
2139 ,       hr_lookups                           g
2140 ,       hr_lookups                           h
2141 ,       hr_lookups                           i
2142 ,       hr_lookups                           j
2143 where   &B1 BETWEEN ASSIGN.effective_start_date
2144                  AND ASSIGN.effective_end_date
2145 and     ASSIGN.assignment_id               = &B2
2146 and     CONTACT.person_id               (+)= ASSIGN.person_id
2147 and     CONTACT.primary_contact_flag    (+)= ''Y''
2148 and     PEOPLE.person_id                (+)= CONTACT.contact_person_id
2149 and     &B1 BETWEEN nvl (PEOPLE.effective_start_date, &B1)
2150                  AND nvl (PEOPLE.effective_end_date, &B1)
2151 and	PTYPE.person_type_id (+)= PEOPLE.person_type_id
2152 and     PHONE.parent_id (+) = PEOPLE.person_id
2153 and     PHONE.parent_table (+)= ''PER_ALL_PEOPLE_F''
2154 and     PHONE.phone_type (+)= ''W1''
2155 and     &B1 BETWEEN NVL(PHONE.date_from, &B1)
2156                  AND NVL(PHONE.date_to, &B1)
2157 and	a.lookup_type           = ''YES_NO''
2158 and	a.lookup_code           = nvl(PEOPLE.current_applicant_flag,''N'')
2159 and     a.application_id        = 800
2160 and	c.lookup_type           = ''YES_NO''
2161 and	c.lookup_code           = nvl(PEOPLE.current_employee_flag,''N'')
2162 and     c.application_id        = 800
2163 and	d.lookup_type           = ''YES_NO''
2164 and	d.lookup_code           = nvl(PEOPLE.registered_disabled_flag,''N'')
2165 and     d.application_id        = 800
2166 and     f.lookup_type        (+)= ''MAR_STATUS''
2167 and     f.lookup_code        (+)= PEOPLE.marital_status
2168 and     f.application_id     (+)= 800
2169 and     g.lookup_type        (+)= ''NATIONALITY''
2170 and     g.lookup_code        (+)= PEOPLE.nationality
2171 and     g.application_id     (+)= 800
2172 and     h.lookup_type        (+)= ''SEX''
2173 and     h.lookup_code        (+)= PEOPLE.sex
2174 and     h.application_id     (+)= 800
2175 and     i.lookup_type        (+)= ''TITLE''
2176 and     i.lookup_code        (+)= PEOPLE.title
2177 and     i.application_id     (+)= 800
2178 and     j.lookup_type        (+)= ''CONTACT''
2179 and     j.lookup_code        (+)= CONTACT.contact_type
2180 and     j.application_id     (+)= 800
2181 and     SES.session_id          = USERENV(''SESSIONID'')';
2182     --
2183     insert_route ('SEH_CON_PERSON_DETAILS',
2184                   'assignment contact details',
2185                   l_text);
2186     --
2187     insert_route_context_usages (l_date_earned_context_id, 1);
2188     insert_route_context_usages (l_assign_id_context_id,   2);
2189     --
2190     insert_user_entity ('ASSIGNMENT_CONTACT_DETAILS',
2191                         'assignment contact details');
2192     --
2193     -- insert database items for the route defined above:
2194     --
2195     --
2196     -- Database items have been moved to SEH_CON_PERSON_DETAILS_PERF
2197     --
2198     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2199     --                                                          +
2200     -- Route for contact details : SEH_CON_PERSON_DETAILS_PERF  +
2201     --                                                          +
2202     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2203     --
2204     l_text := '/* contact person details */
2205         per_all_assignments_f                ASSIGN
2206 ,       per_contact_relationships            CONTACT
2207 ,       per_all_people_f                     PEOPLE
2208 ,	per_person_types                     PTYPE
2209 ,       per_phones                           PHONE
2210 ,       fnd_sessions                         SES
2211 ,	hr_lookups                           a
2212 ,	hr_lookups                           c
2213 ,	hr_lookups                           d
2214 where   &B1 BETWEEN ASSIGN.effective_start_date
2215                  AND ASSIGN.effective_end_date
2216 and     ASSIGN.assignment_id               = &B2
2217 and     CONTACT.person_id               (+)= ASSIGN.person_id
2218 and     CONTACT.primary_contact_flag    (+)= ''Y''
2219 and     PEOPLE.person_id                (+)= CONTACT.contact_person_id
2220 and     &B1 BETWEEN nvl (PEOPLE.effective_start_date, &B1)
2221                  AND nvl (PEOPLE.effective_end_date, &B1)
2222 and	PTYPE.person_type_id (+)= PEOPLE.person_type_id
2223 and     PHONE.parent_id (+) = PEOPLE.person_id
2224 and     PHONE.parent_table (+)= ''PER_ALL_PEOPLE_F''
2225 and     PHONE.phone_type (+)= ''W1''
2226 and     &B1 BETWEEN NVL(PHONE.date_from, &B1)
2227                  AND NVL(PHONE.date_to, &B1)
2228 and	a.lookup_type           = ''YES_NO''
2229 and	a.lookup_code           = nvl(PEOPLE.current_applicant_flag,''N'')
2230 and     a.application_id        = 800
2231 and	c.lookup_type           = ''YES_NO''
2232 and	c.lookup_code           = nvl(PEOPLE.current_employee_flag,''N'')
2233 and     c.application_id        = 800
2234 and	d.lookup_type           = ''YES_NO''
2235 and	d.lookup_code           = nvl(PEOPLE.registered_disabled_flag,''N'')
2236 and     d.application_id        = 800
2237 and     SES.session_id          = USERENV(''SESSIONID'')';
2238     --
2239     insert_route ('SEH_CON_PERSON_DETAILS_PERF',
2240                   'assignment contact details (performant version)',
2241                   l_text);
2242     --
2243     insert_route_context_usages (l_date_earned_context_id, 1);
2244     insert_route_context_usages (l_assign_id_context_id,   2);
2245     --
2246     insert_user_entity ('ASSIGNMENT_CONTACT_DETAILS_PERF',
2247                         'assignment contact details (performant version)');
2248     --
2249     -- insert database items for the route defined above:
2250     --
2251     --
2252     --
2253     insert_database_item ('CON_NATIONAL_IDENTIFIER',
2254                           'PEOPLE.national_identifier',
2255                           'The contacts national identifier',
2256                           'T',
2257                           'Y');
2258     --
2259     insert_database_item ('CON_START_DATE',
2260                           'PEOPLE.effective_start_date',
2261                 'The date from which this contact information is effective',
2262                           'D',
2263                           'Y');
2264     --
2265     insert_database_item ('CON_END_DATE',
2266                           'PEOPLE.effective_end_date',
2267                   'The date to which this contact information is effective',
2268                           'D',
2269                           'Y');
2270     --
2271     insert_database_item ('CON_FULL_NAME',
2272                           'PEOPLE.full_name',
2273                           'The contact''s full name',
2274                           'T',
2275                           'Y');
2276     --
2277     insert_database_item ('CON_LAST_NAME',
2278                           'PEOPLE.last_name',
2279                           'The contact''s last name',
2280                           'T',
2281                           'Y');
2282     --
2283     insert_database_item ('CON_FIRST_NAME',
2284                           'PEOPLE.first_name',
2285                           'The contact''s first name',
2286                           'T',
2287                           'Y');
2288     --
2289     insert_database_item ('CON_KNOWN_AS',
2290                           'PEOPLE.known_as',
2291                           'The contact''s preferred name',
2292                           'T',
2293                           'Y');
2294     --
2295     insert_database_item ('CON_MIDDLE_NAMES',
2296                           'PEOPLE.middle_names',
2297                           'The contact''s middle names',
2298                           'T',
2299                           'Y');
2300     --
2301     insert_database_item ('CON_APP_NUMBER',
2302                           'PEOPLE.applicant_number',
2303                           'The contact''s applicant number',
2304                           'T',
2305                           'Y');
2306     --
2307     insert_database_item ('CON_DATE_OF_BIRTH',
2308                           'PEOPLE.date_of_birth',
2309                           'The contact''s date of birth',
2310                           'D',
2311                           'Y');
2312     --
2313     insert_database_item ('CON_EMP_NUMBER',
2314                           'PEOPLE.employee_number',
2315                           'The contact''s employee number',
2316                           'T',
2317                           'Y');
2318     --
2319     insert_database_item ('CON_WORK_PHONE',
2320                           'NVL(PHONE.phone_number,PEOPLE.work_telephone)',
2321                           'The contact''s work telephone number',
2322                           'T',
2323                           'Y');
2324     --
2325     insert_database_item ('CON_AGE',
2326          'TRUNC(MONTHS_BETWEEN(SES.EFFECTIVE_DATE, PEOPLE.date_of_birth)/12)',
2327                           'The contact''s age',
2328                           'N',
2329                           'Y');
2330     --
2331     insert_database_item ('CON_PERSON_TYPE',
2332                           'PTYPE.user_person_type',
2333                           'The contact''s person type,  employee, etc.',
2334                           'T',
2335                           'Y');
2336     --
2337     insert_database_item ('PTU_CON_PERSON_TYPE',
2338                           'hr_person_type_usage_info.get_user_person_type(SES.effective_date,PEOPLE.person_id) user_person_type',
2339                           'The contact''s person type,  employee, etc.',
2340                           'T',
2341                           'Y');
2342     --
2343     insert_database_item ('CON_CURRENT_APP',
2344                           'a.meaning',
2345                       'Whether the contact is a current applicant (yes/no)',
2346                           'T',
2347                           'Y');
2348     insert_database_item ('CON_CURRENT_EMP',
2349                           'c.meaning',
2350                           'Whether the contact is a current employee (yes/no)',
2351                           'T',
2352                           'Y');
2353     --
2354     insert_database_item ('CON_DISABLED',
2355                           'd.meaning',
2356                           'Whether the contact is disabled (yes/no)',
2357                           'T',
2358                           'Y');
2359     --
2360     insert_database_item ('CON_MARITAL_STATUS',
2361                           'hr_general.decode_lookup(''MAR_STATUS'',
2362                           	PEOPLE.marital_status)',
2363                           'The contact''s maritial status',
2364                           'T',
2365                           'Y');
2366     --
2367     insert_database_item ('CON_NATIONALITY',
2368                           'hr_general.decode_lookup(''NATIONALITY'',
2369                           	PEOPLE.nationality)',
2370                           'The contact''s nationality',
2371                           'T',
2372                           'Y');
2373     --
2374     insert_database_item ('CON_SEX',
2375                           'hr_general.decode_lookup(''SEX'',
2376                           	PEOPLE.sex)',
2377                           'The contact''s sex',
2378                           'T',
2379                           'Y');
2380     --
2381     insert_database_item ('CON_TITLE',
2382                           'hr_general.decode_lookup(''TITLE'',
2383                           	PEOPLE.title)',
2384                           'The contact''s title',
2385                           'T',
2386                           'Y');
2387     --
2388     insert_database_item ('CON_RELATIONSHIP',
2389                           'hr_general.decode_lookup(''CONTACT'',
2390                           	CONTACT.contact_type)',
2391                    'The relationship of the contact to the employee',
2392                           'T',
2393                           'Y');
2394     --
2395     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2396     --                                                       +
2397     -- Route for contact details : SEH_CON_PERSON_DETAILS_2  +
2398     --                                                       +
2399     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2400     --
2401     l_text := '/* contact person details */
2402                 per_all_assignments_f                ASSIGN
2403         ,       per_contact_relationships            CONTACT
2404         ,       per_all_people_f                     PEOPLE
2405         ,       ben_ler_f                            BEN1
2406         ,       ben_ler_f                            BEN2
2407         ,       fnd_sessions                         SES
2408         ,       hr_lookups                           a
2409         ,       hr_lookups                           b
2410         ,       hr_lookups                           c
2411         ,       hr_lookups                           d
2412         ,       hr_lookups                           e
2413 
2414     where   &B1 BETWEEN ASSIGN.effective_start_date
2415                      AND ASSIGN.effective_end_date
2416     and     ASSIGN.assignment_id               = &B2
2417     and     CONTACT.person_id               (+)= ASSIGN.person_id
2418     and     CONTACT.primary_contact_flag    (+)= ''Y''
2419     and     PEOPLE.person_id                (+)= CONTACT.contact_person_id
2420     and     &B1 BETWEEN PEOPLE.effective_start_date
2421                      AND PEOPLE.effective_end_date
2422     and     BEN1.ler_id           (+)= CONTACT.start_life_reason_id
2423     and     BEN2.ler_id           (+)= CONTACT.end_life_reason_id
2424     and     a.lookup_type           = ''YES_NO''
2425     and     a.lookup_code           = nvl(CONTACT.RLTD_PER_RSDS_W_DSGNTR_FLAG,''N'')
2426     and     a.application_id        = 800
2427     and     b.lookup_type           = ''YES_NO''
2428     and     b.lookup_code           = nvl(CONTACT.PERSONAL_FLAG,''N'')
2429     and     b.application_id        = 800
2430     and     c.lookup_type           = ''YES_NO''
2431     and     c.lookup_code           = nvl(CONTACT.THIRD_PARTY_PAY_FLAG,''N'')
2432     and     c.application_id        = 800
2433     and     d.lookup_type           = ''YES_NO''
2434     and     d.lookup_code           = nvl(CONTACT.BENEFICIARY_FLAG,''N'')
2435     and     d.application_id        = 800
2436     and     e.lookup_type           = ''YES_NO''
2437     and     e.lookup_code           = nvl(CONTACT.DEPENDENT_FLAG,''N'')
2438     and     e.application_id        = 800
2439     and     SES.session_id          = USERENV(''SESSIONID'')';
2440     --
2441     insert_route ('SEH_CON_PERSON_DETAILS_2',
2442                   'contact details',
2443                   l_text);
2444     --
2445     insert_route_context_usages (l_date_earned_context_id, 1);
2446     insert_route_context_usages (l_assign_id_context_id,   2);
2447     --
2448     insert_user_entity ('CONTACT_DETAILS',
2449                         'contact details');
2450     --
2451     -- insert database items for the route defined above:
2452     --
2453     --
2454     --
2455     insert_database_item ('CON_DATE_START',
2456                           'CONTACT.DATE_START',
2457                 'Start date of the contact relationship',
2458                           'D',
2459                           'Y');
2460     --
2461     insert_database_item ('CON_DATE_END',
2462                           'CONTACT.DATE_END',
2463                 'End date of the contact relationship',
2464                           'D',
2465                           'Y');
2466     --
2467     insert_database_item ('CON_START_LIFE_REASON_ID',
2468                           'BEN1.name',
2469                   'Reason for the start of the relationship',
2470                           'T',
2471                           'Y');
2472     --
2473     insert_database_item ('CON_END_LIFE_REASON_ID',
2474                           'BEN2.name',
2475                   'Reason for the end of the relationship',
2476                           'T',
2477                           'Y');
2478     --
2479     insert_database_item ('CON_RLTD_PER_RSDS_W_DSGNTR',
2480                           'a.meaning',
2481                           'Related person resides with designator',
2482                           'T',
2483                           'Y');
2484     --
2485     insert_database_item ('CON_PERSONAL_FLAG',
2486                           'b.meaning',
2487                           'Personal Relationship Flag',
2488                           'T',
2489                           'Y');
2490     --
2491     insert_database_item ('CON_THIRD_PARTY_PAY_FLAG',
2492                           'c.meaning',
2493                           'Third Party Payments Relationship Flag',
2494                           'T',
2495                           'Y');
2496     --
2497     insert_database_item ('CON_BENEFICIARY_FLAG',
2498                           'd.meaning',
2499                           'Beneficiary Flag',
2500                           'T',
2501                           'Y');
2502     --
2503     insert_database_item ('CON_DEPENDENT_FLAG',
2504                           'e.meaning',
2505                           'Dependent Flag',
2506                           'T',
2507                           'Y');
2508     --
2509     insert_database_item ('CON_SEQUENCE_NUMBER',
2510                           'CONTACT.SEQUENCE_NUMBER',
2511                           'Sequence number',
2512                           'N',
2513                           'Y');
2514 
2515     --
2516     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2517     --                                                             +
2518     -- Route for contact address details : SEH_CON_PERSON_ADDRESS  +
2519     --                                                             +
2520     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2521     --
2522     l_text := '/* contact address details */
2523         per_all_assignments_f                ASSIGN
2524 ,       per_contact_relationships            CONTACT
2525 ,       per_all_people_f                     PEOPLE
2526 ,	per_addresses                        ADDR
2527 ,	fnd_territories_tl                   a
2528 ,	fnd_territories_tl                   b
2529 where	&B1 BETWEEN ASSIGN.effective_start_date
2530                  AND ASSIGN.effective_end_date
2531 and     ASSIGN.assignment_id               = &B2
2532 and     CONTACT.person_id               (+)= ASSIGN.person_id
2533 and     CONTACT.primary_contact_flag    (+)= ''Y''
2534 and     &B1 BETWEEN nvl(ADDR.date_from, &B1)
2535                  AND nvl(ADDR.date_to, &B1)
2536 and     PEOPLE.person_id                (+)= CONTACT.contact_person_id
2537 and     &B1 BETWEEN nvl (PEOPLE.effective_start_date, &B1)
2538                  AND nvl (PEOPLE.effective_end_date, &B1)
2539 and	ADDR.person_id                  (+)=  PEOPLE.person_id
2540 and	ADDR.primary_flag               (+)= ''Y''
2541 and	a.territory_code                (+)= ADDR.country
2542 and	a.language                      (+)= userenv(''LANG'')
2543 and	b.territory_code                (+)= ADDR.style
2544 and	b.language                      (+)= userenv(''LANG'')';
2545     --
2546     insert_route ('SEH_CON_PERSON_ADDRESS',
2547                   'contact address details',
2548                   l_text);
2549     --
2550     insert_route_context_usages (l_date_earned_context_id, 1);
2551     insert_route_context_usages (l_assign_id_context_id,   2);
2552     --
2553     insert_user_entity ('CONTACT_ADDRESS_DETAILS',
2554                         'contact address details');
2555     --
2556     -- insert database items for the route defined above:
2557     --
2558     --
2559     insert_database_item ('CON_ADR_DATE_FROM',
2560                           'ADDR.date_from',
2561      'The first date on which the contact can be contacted at this address',
2562                           'D',
2563                           'Y');
2564     --
2565     insert_database_item ('CON_ADR_DATE_TO',
2566                           'ADDR.date_to',
2567      'The last date on which the contact can be contacted at this address',
2568                           'D',
2569                           'Y');
2570     --
2571     insert_database_item ('CON_ADR_LINE_1',
2572                           'ADDR.address_line1',
2573                           'The first line of the contact''s address',
2574                           'T',
2575                           'Y');
2576     --
2577     insert_database_item ('CON_ADR_LINE_2',
2578                           'ADDR.address_line2',
2579                           'The second line of the contact''s address',
2580                           'T',
2581                           'Y');
2582     --
2583     insert_database_item ('CON_ADR_LINE_3',
2584                           'ADDR.address_line3',
2585                           'The third line of the contact''s address',
2586                           'T',
2587                           'Y');
2588     --
2589     insert_database_item ('CON_ADR_CITY',
2590                           'ADDR.town_or_city',
2591                           'The name of the contact''s town or city',
2592                           'T',
2593                           'Y');
2594     --
2595     insert_database_item ('CON_ADR_REGION_1',
2596                           'ADDR.region_1',
2597                           'The first line of the contact''s region',
2598                           'T',
2599                           'Y');
2600     --
2601     insert_database_item ('CON_ADR_REGION_2',
2602                           'ADDR.region_2',
2603                           'The second line of the contact''s region',
2604                           'T',
2605                           'Y');
2606     --
2607     insert_database_item ('CON_ADR_REGION_3',
2608                           'ADDR.region_3',
2609                           'The third line of the contact''s region',
2610                           'T',
2611                           'Y');
2612     --
2613     insert_database_item ('CON_ADR_POSTAL_CODE',
2614                           'ADDR.postal_code',
2615                           'The contact''s postal code',
2616                           'T',
2617                           'Y');
2618     --
2619     insert_database_item ('CON_ADR_PHONE_1',
2620                           'ADDR.telephone_number_1',
2621                           'The contact''s first telephone number',
2622                           'T',
2623                           'Y');
2624     --
2625     insert_database_item ('CON_ADR_PHONE_2',
2626                           'ADDR.telephone_number_2',
2627                           'The contact''s second telephone number',
2628                           'T',
2629                           'Y');
2630     --
2631     insert_database_item ('CON_ADR_PHONE_3',
2632                           'ADDR.telephone_number_3',
2633                           'The contact''s third telephone number',
2634                           'T',
2635                           'Y');
2636     --
2637     insert_database_item ('CON_ADR_COUNTRY',
2638                           'a.territory_short_name',
2639                           'The name of the contact''s country',
2640                           'T',
2641                           'Y');
2642     --
2643     --++++++++++++++++++++++++++++++++++++++++++++++++
2644     --                                               +
2645     -- Route for recruiter details : SEH_REC_DETAILS +
2646     --                                               +
2647     --++++++++++++++++++++++++++++++++++++++++++++++++
2648     --
2649     l_text := '/* recruiter details */
2650         per_all_assignments_f                ASSIGN
2651 ,       per_all_assignments_f                RASSIGN
2652 ,       per_all_people_f                     PEOPLE
2653 ,	per_person_types                     PTYPE
2654 ,       per_phones                           PHONE
2655 ,       per_grades                           GRADE
2656 ,       per_jobs                             JOB
2657 ,       hr_locations                         LOC
2658 ,       hr_all_organization_units            ORG
2659 ,       hr_all_positions_f                   POS
2660 ,	hr_lookups                           a
2661 ,	hr_lookups                           c
2662 ,	hr_lookups                           d
2663 where   &B1 BETWEEN ASSIGN.effective_start_date
2664                  AND ASSIGN.effective_end_date
2665 and     &B1 BETWEEN POS.effective_start_date(+)
2666                  AND POS.effective_end_date(+)
2667 and     ASSIGN.assignment_id               = &B2
2668 and     PEOPLE.person_id                (+)= ASSIGN.recruiter_id
2669 and     &B1 BETWEEN nvl (PEOPLE.effective_start_date, &B1)
2670                  AND nvl (PEOPLE.effective_end_date, &B1)
2671 and	PTYPE.person_type_id (+)= PEOPLE.person_type_id
2672 and     PHONE.parent_id (+) = PEOPLE.person_id
2673 and     PHONE.parent_table (+)= ''PER_ALL_PEOPLE_F''
2674 and     PHONE.phone_type (+)= ''W1''
2675 and     &B1 BETWEEN NVL(PHONE.date_from, &B1)
2676                  AND NVL(PHONE.date_to, &B1)
2677 and	a.lookup_type           = ''YES_NO''
2678 and	a.lookup_code           = nvl(PEOPLE.current_applicant_flag,''N'')
2679 and     a.application_id        = 800
2680 and	c.lookup_type           = ''YES_NO''
2681 and	c.lookup_code           = nvl(PEOPLE.current_employee_flag,''N'')
2682 and     c.application_id        = 800
2683 and     RASSIGN.person_id    (+)= ASSIGN.recruiter_id
2684 and     RASSIGN.primary_flag (+)= ''Y''
2685 and     &B1 BETWEEN nvl (RASSIGN.effective_start_date, &B1)
2686                  AND nvl (RASSIGN.effective_end_date, &B1)
2687 and     GRADE.grade_id       (+)= RASSIGN.grade_id
2688 and     JOB.job_id           (+)= RASSIGN.job_id
2689 and     LOC.location_id      (+)= RASSIGN.location_id
2690 and     ORG.organization_id  (+)= RASSIGN.organization_id
2691 and     POS.position_id      (+)= RASSIGN.position_id
2692 and     d.lookup_type        (+)= ''YES_NO''
2693 and     d.application_id     (+)= 800
2694 and     d.lookup_code        (+)= RASSIGN.manager_flag';
2695     --
2696     insert_route ('SEH_REC_DETAILS',
2697                   'recruiter details',
2698                   l_text);
2699     --
2700     insert_route_context_usages (l_date_earned_context_id, 1);
2701     insert_route_context_usages (l_assign_id_context_id,   2);
2702     --
2703     insert_user_entity ('RECRUITER_DETAILS',
2704                         'recruiter details');
2705     --
2706     -- insert database items for the route defined above:
2707     --
2708     -- Moved the databse items to SEH_REC_DETAILS_PERF
2709     --
2710     --+++++++++++++++++++++++++++++++++++++++++++++++++++++
2711     --                                                    +
2712     -- Route for recruiter details : SEH_REC_DETAILS_PERF +
2713     --                                                    +
2714     --+++++++++++++++++++++++++++++++++++++++++++++++++++++
2715     --
2716     l_text := '/* recruiter details */
2717         per_all_assignments_f                ASSIGN
2718 ,       per_all_assignments_f                RASSIGN
2719 ,       per_all_people_f                     PEOPLE
2720 ,	per_person_types                     PTYPE
2721 ,       per_phones                           PHONE
2722 ,       per_grades                           GRADE
2723 ,       per_jobs                             JOB
2724 ,       hr_locations                         LOC
2725 ,       hr_all_organization_units            ORG
2726 ,       hr_all_positions_f                   POS
2727 ,	hr_lookups                           a
2728 ,	hr_lookups                           c
2729 where   &B1 BETWEEN ASSIGN.effective_start_date
2730                  AND ASSIGN.effective_end_date
2731 and     &B1 BETWEEN POS.effective_start_date(+)
2732                  AND POS.effective_end_date(+)
2733 and     ASSIGN.assignment_id               = &B2
2734 and     PEOPLE.person_id                (+)= ASSIGN.recruiter_id
2735 and     &B1 BETWEEN nvl (PEOPLE.effective_start_date, &B1)
2736                  AND nvl (PEOPLE.effective_end_date, &B1)
2737 and	PTYPE.person_type_id (+)= PEOPLE.person_type_id
2738 and     PHONE.parent_id (+) = PEOPLE.person_id
2739 and     PHONE.parent_table (+)= ''PER_ALL_PEOPLE_F''
2740 and     PHONE.phone_type (+)= ''W1''
2741 and     &B1 BETWEEN NVL(PHONE.date_from, &B1)
2742                  AND NVL(PHONE.date_to, &B1)
2743 and	a.lookup_type           = ''YES_NO''
2744 and	a.lookup_code           = nvl(PEOPLE.current_applicant_flag,''N'')
2745 and     a.application_id        = 800
2746 and	c.lookup_type           = ''YES_NO''
2747 and	c.lookup_code           = nvl(PEOPLE.current_employee_flag,''N'')
2748 and     c.application_id        = 800
2749 and     RASSIGN.person_id    (+)= ASSIGN.recruiter_id
2750 and     RASSIGN.primary_flag (+)= ''Y''
2751 and     &B1 BETWEEN nvl (RASSIGN.effective_start_date, &B1)
2752                  AND nvl (RASSIGN.effective_end_date, &B1)
2753 and     GRADE.grade_id       (+)= RASSIGN.grade_id
2754 and     JOB.job_id           (+)= RASSIGN.job_id
2755 and     LOC.location_id      (+)= RASSIGN.location_id
2756 and     ORG.organization_id  (+)= RASSIGN.organization_id
2757 and     POS.position_id      (+)= RASSIGN.position_id';
2758     --
2759     insert_route ('SEH_REC_DETAILS_PERF',
2760                   'recruiter details (performant version)',
2761                   l_text);
2762     --
2763     insert_route_context_usages (l_date_earned_context_id, 1);
2764     insert_route_context_usages (l_assign_id_context_id,   2);
2765     --
2766     insert_user_entity ('RECRUITER_DETAILS_PERF',
2767                         'recruiter details (performant version)');
2768     --
2769     -- insert database items for the route defined above:
2770     --
2771     --
2772     insert_database_item ('REC_EMP_NUMBER',
2773                           'PEOPLE.employee_number',
2774                           'The recruiter''s employee number',
2775                           'T',
2776                           'Y');
2777     --
2778     insert_database_item ('REC_WORK_PHONE',
2779                           'NVL(PHONE.phone_number,PEOPLE.work_telephone)',
2780                           'The recruiter''s work telephone number',
2781                           'T',
2782                           'Y');
2783     --
2784     insert_database_item ('REC_PERSON_TYPE',
2785                           'PTYPE.user_person_type',
2786                           'Type of person, eg. employee, applicant, etc.',
2787                           'T',
2788                           'Y');
2789     --
2790     insert_database_item ('PTU_REC_PERSON_TYPE',
2791                           'hr_person_type_usage_info.get_user_person_type(people.effective_end_date, people.person_id) user_person_type',
2792                           'Type of person, eg. employee, applicant, etc.',
2793                           'T',
2794                           'Y');
2795     --
2796     insert_database_item ('REC_CURRENT_APP',
2797                           'a.meaning',
2798                        'Whether the recruiter is a current applicant (yes/no)',
2799                           'T',
2800                           'Y');
2801     --
2802     insert_database_item ('REC_CURRENT_EMP',
2803                           'c.meaning',
2804                         'Whether the recruiter is a current employee (yes/no)',
2805                           'T',
2806                           'Y');
2807     --
2808     insert_database_item ('REC_GRADE',
2809                           'Grade.name',
2810                           'The grade of the recruiter',
2811                           'T',
2812                           'Y');
2813     --
2814     insert_database_item ('REC_JOB',
2815                           'JOB.name',
2816                           'The job of the recruiter',
2817                           'T',
2818                           'Y');
2819     --
2820     insert_database_item ('REC_LOCATION',
2821                           'LOC.location_code',
2822                           'The location of the recruiter',
2823                           'T',
2824                           'Y');
2825     --
2826     insert_database_item ('REC_ORG',
2827                           'ORG.name',
2828                           'The organization name of the recruiter',
2829                           'T',
2830                           'Y');
2831     --
2832     insert_database_item ('REC_INT_ADDR_LINE',
2833                           'RASSIGN.internal_address_line',
2834                           'The internal address of the recruiter',
2835                           'T',
2836                           'Y');
2837     --
2838     insert_database_item ('REC_MANAGER',
2839                           'hr_general.decode_lookup(''YES_NO'',
2840                           	RASSIGN.manager_flag)',
2841                'Whether the assignment is a managerial assignment (yes/no)',
2842                           'T',
2843                           'Y');
2844     --
2845     insert_database_item ('REC_POSITION',
2846                           'POS.name',
2847                           'The position name of the recruiter',
2848                           'T',
2849                           'Y');
2850     --
2851     --+++++++++++++++++++++++++++++++++++++++++++++++++
2852     --                                                +
2853     -- Route for supervisor details : SEH_SUP_DETAILS +
2854     --                                                +
2855     --+++++++++++++++++++++++++++++++++++++++++++++++++
2856     --
2857     l_text := '/* supervisor details */
2858         per_all_assignments_f                ASSIGN
2859 ,       per_all_assignments_f                SASSIGN
2860 ,       per_all_people_f                     PEOPLE
2861 ,       per_person_types                     PTYPE
2862 ,       per_phones                           PHONE
2863 ,       per_grades                           GRADE
2864 ,       per_jobs                             JOB
2865 ,       hr_locations                         LOC
2866 ,       hr_all_organization_units            ORG
2867 ,       hr_all_positions_f                   POS
2868 ,	hr_lookups                           c
2869 ,	hr_lookups                           d
2870 where   &B1 BETWEEN ASSIGN.effective_start_date
2871                  AND ASSIGN.effective_end_date
2872 and     &B1 BETWEEN ASSIGN.effective_start_date(+)
2873                  AND ASSIGN.effective_end_date(+)
2874 and     ASSIGN.assignment_id               = &B2
2875 and     PEOPLE.person_id                (+)= ASSIGN.supervisor_id
2876 and     &B1 BETWEEN nvl (PEOPLE.effective_start_date, &B1)
2877                  AND nvl (PEOPLE.effective_end_date, &B1)
2878 and	PTYPE.person_type_id            (+)= PEOPLE.person_type_id
2879 and     PHONE.parent_id (+) = PEOPLE.person_id
2880 and     PHONE.parent_table (+)= ''PER_ALL_PEOPLE_F''
2881 and     PHONE.phone_type (+)= ''W1''
2882 and     &B1 BETWEEN NVL(PHONE.date_from, &B1)
2883                  AND NVL(PHONE.date_to, &B1)
2884 and     SASSIGN.person_id               (+)= ASSIGN.supervisor_id
2885 and     &B1 BETWEEN nvl (SASSIGN.effective_start_date, &B1)
2886                  AND nvl (SASSIGN.effective_end_date, &B1)
2887 and     SASSIGN.primary_flag (+)= ''Y''
2888 and     GRADE.grade_id       (+)= SASSIGN.grade_id
2889 and     JOB.job_id           (+)= SASSIGN.job_id
2890 and     LOC.location_id      (+)= SASSIGN.location_id
2891 and     ORG.organization_id  (+)= SASSIGN.organization_id
2892 and     POS.position_id      (+)= SASSIGN.position_id
2893 and	c.lookup_type           = ''YES_NO''
2894 and	c.lookup_code           = nvl(PEOPLE.current_employee_flag,''N'')
2895 and     c.application_id        = 800
2896 and     d.lookup_type        (+)= ''YES_NO''
2897 and     d.application_id     (+)= 800
2898 and     d.lookup_code        (+)= SASSIGN.manager_flag';
2899     --
2900     insert_route ('SEH_SUP_DETAILS',
2901                   'supervisor details',
2902                   l_text);
2903     --
2904     insert_route_context_usages (l_date_earned_context_id, 1);
2905     insert_route_context_usages (l_assign_id_context_id,   2);
2906     --
2907     insert_user_entity ('SUPERVISOR_DETAILS',
2908                         'supervisor details');
2909     --
2910     -- insert database items for the route defined above:
2911     --
2912     --
2913     -- moved the database items to SEH_SUP_DETAILS_PERF
2914     --
2915     --++++++++++++++++++++++++++++++++++++++++++++++++++++++
2916     --                                                     +
2917     -- Route for supervisor details : SEH_SUP_DETAILS_PERF +
2918     --                                                     +
2919     --++++++++++++++++++++++++++++++++++++++++++++++++++++++
2920     --
2921     l_text := '/* supervisor details */
2922         per_all_assignments_f                ASSIGN
2923 ,       per_all_assignments_f                SASSIGN
2924 ,       per_all_people_f                     PEOPLE
2925 ,       per_person_types                     PTYPE
2926 ,       per_phones                           PHONE
2927 ,       per_grades                           GRADE
2928 ,       per_jobs                             JOB
2929 ,       hr_locations                         LOC
2930 ,       hr_all_organization_units            ORG
2931 ,       hr_all_positions_f                   POS
2932 ,	hr_lookups                           c
2933 where   &B1 BETWEEN ASSIGN.effective_start_date
2934                  AND ASSIGN.effective_end_date
2935 and     &B1 BETWEEN ASSIGN.effective_start_date(+)
2936                  AND ASSIGN.effective_end_date(+)
2937 and     ASSIGN.assignment_id               = &B2
2938 and     PEOPLE.person_id                (+)= ASSIGN.supervisor_id
2939 and     &B1 BETWEEN nvl (PEOPLE.effective_start_date, &B1)
2940                  AND nvl (PEOPLE.effective_end_date, &B1)
2941 and	PTYPE.person_type_id            (+)= PEOPLE.person_type_id
2942 and     PHONE.parent_id (+) = PEOPLE.person_id
2943 and     PHONE.parent_table (+)= ''PER_ALL_PEOPLE_F''
2944 and     PHONE.phone_type (+)= ''W1''
2945 and     &B1 BETWEEN NVL(PHONE.date_from, &B1)
2946                  AND NVL(PHONE.date_to, &B1)
2947 and     SASSIGN.person_id               (+)= ASSIGN.supervisor_id
2948 and     &B1 BETWEEN nvl (SASSIGN.effective_start_date, &B1)
2949                  AND nvl (SASSIGN.effective_end_date, &B1)
2950 and     SASSIGN.primary_flag (+)= ''Y''
2951 and     GRADE.grade_id       (+)= SASSIGN.grade_id
2952 and     JOB.job_id           (+)= SASSIGN.job_id
2953 and     LOC.location_id      (+)= SASSIGN.location_id
2954 and     ORG.organization_id  (+)= SASSIGN.organization_id
2955 and     POS.position_id      (+)= SASSIGN.position_id
2956 and	c.lookup_type           = ''YES_NO''
2957 and	c.lookup_code           = nvl(PEOPLE.current_employee_flag,''N'')
2958 and     c.application_id        = 800';
2959     --
2960     insert_route ('SEH_SUP_DETAILS_PERF',
2961                   'supervisor details (performant version)',
2962                   l_text);
2963     --
2964     insert_route_context_usages (l_date_earned_context_id, 1);
2965     insert_route_context_usages (l_assign_id_context_id,   2);
2966     --
2967     insert_user_entity ('SUPERVISOR_DETAILS_PERF',
2968                         'supervisor details (performant version)');
2969     --
2970     -- insert database items for the route defined above:
2971     --
2972     --
2973     --
2974     insert_database_item ('SUP_EMP_NUMBER',
2975                           'PEOPLE.employee_number',
2976                           'The employee number of the supervisor',
2977                           'T',
2978                           'Y');
2979     --
2980     insert_database_item ('SUP_WORK_PHONE',
2981                           'NVL(PHONE.phone_number,PEOPLE.work_telephone)',
2982                           'The supervisor''s work telephone number',
2983                           'T',
2984                           'Y');
2985     --
2986     insert_database_item ('SUP_PERSON_TYPE',
2987                           'PTYPE.user_person_type',
2988                           'Type of person, eg. employee, applicant, etc.',
2989                           'T',
2990                           'Y');
2991     --
2992     insert_database_item ('PTU_SUP_PERSON_TYPE',
2993                           'hr_person_type_usage_info.get_user_person_type(PEOPLE.effective_end_date,PEOPLE.person_id) user_person_type',
2994                           'Type of person, eg. employee, applicant, etc.',
2995                           'T',
2996                           'Y');
2997     --
2998     insert_database_item ('SUP_DATE_FROM',
2999                           'SASSIGN.effective_start_date',
3000            'The date from which this supervisor information is effective',
3001                           'D',
3002                           'Y');
3003     --
3004     insert_database_item ('SUP_DATE_TO',
3005                           'SASSIGN.effective_end_date',
3006              'The date to which this supervisor information is effective',
3007                           'D',
3008                           'Y');
3009     --
3010     insert_database_item ('SUP_INT_ADDR_LINE',
3011                           'SASSIGN.internal_address_line',
3012                           'The internal address of the supervisor',
3013                           'T',
3014                           'Y');
3015     --
3016     insert_database_item ('SUP_GRADE',
3017                           'Grade.name',
3018                           'The grade of the supervisor',
3019                           'T',
3020                           'Y');
3021     --
3022     insert_database_item ('SUP_JOB',
3023                           'JOB.name',
3024                           'The job of the supervisor',
3025                           'T',
3026                           'Y');
3027     --
3028     insert_database_item ('SUP_LOCATION',
3029                           'LOC.location_code',
3030                           'The location of the the supervisor',
3031                           'T',
3032                           'Y');
3033     --
3034     insert_database_item ('SUP_ORG',
3035                           'ORG.name',
3036                           'The organization name of the supervisor',
3037                           'T',
3038                           'Y');
3039     --
3040     insert_database_item ('SUP_POSITION',
3041                           'POS.name',
3042                           'The position name of the supervisor',
3043                           'T',
3044                           'Y');
3045     --
3046     insert_database_item ('SUP_CURRENT_EMP',
3047                           'c.meaning',
3048                     'Whether the supervisor is a current employee (yes/no)',
3049                           'T',
3050                           'Y');
3051     --
3052     insert_database_item ('SUP_MANAGER',
3053                           'hr_general.decode_lookup(''YES_NO'',
3054                           	SASSIGN.manager_flag)',
3055                  'Whether the assignment is a managerial assignment (yes/no)',
3056                           'T',
3057                           'Y');
3058     --
3059     insert_database_item ('SUP_EMAIL_ADDRESS',
3060                           'people.email_address',
3061                           'Persons email address',
3062                           'T',
3063                           'Y');
3064     --
3065     --++++++++++++++++++++++++++++++++++++++++++++++++++
3066     --                                                 +
3067     -- Route for application details : SEH_APL_DETAILS +
3068     --                                                 +
3069     --++++++++++++++++++++++++++++++++++++++++++++++++++
3070     --
3071     l_text := '/* application details */
3072         per_all_assignments_f                ASSIGN
3073 ,       per_applications                     APPLIC
3074 where   &B1 BETWEEN ASSIGN.effective_start_date
3075                  AND ASSIGN.effective_end_date
3076 and     ASSIGN.assignment_id               = &B2
3077 and     APPLIC.application_id           (+)= ASSIGN.application_id';
3078     --
3079     insert_route ('SEH_APL_DETAILS',
3080                   'application details',
3081                   l_text);
3082     --
3083     insert_route_context_usages (l_date_earned_context_id, 1);
3084     insert_route_context_usages (l_assign_id_context_id,   2);
3085     --
3086     insert_user_entity ('APPLICATION_DETAILS',
3087                         'application details');
3088     --
3089     -- insert database items for the route defined above:
3090     --
3091     insert_database_item ('APL_DATE_RECEIVED',
3092                           'APPLIC.date_received',
3093                           'The date the application was received',
3094                           'D',
3095                           'Y');
3096     --
3097     insert_database_item ('APL_DATE_END',
3098                           'APPLIC.date_end',
3099                           'The date the application ended',
3100                           'D',
3101                           'Y');
3102     --
3103     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3104     --                                                             +
3105     -- Route for Date Paid personal status : SEH_ASS_PER_STATUS_DP +
3106     --                                                             +
3107     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3108     --
3109     l_text := '/* Personal status (Date paid context) */
3110         per_assignment_status_types         STYPE
3111 ,       per_assignments_f                   ASSIGN
3112 ,       fnd_sessions                        SES
3113 where   ASSIGN.assignment_id              = &B1
3114 and     SES.session_id                    = USERENV(''SESSIONID'')
3115 and     SES.effective_date          between ASSIGN.effective_start_date
3116                                         and ASSIGN.effective_end_date
3117 and     STYPE.assignment_status_type_id   = ASSIGN.assignment_status_type_id';
3118     --
3119     insert_route ('SEH_ASS_PER_STATUS_DP',
3120                   'Personal status (Date paid context)',
3121                   l_text);
3122     --
3123     insert_route_context_usages (l_assign_id_context_id,   1);
3124     --
3125     insert_user_entity ('ASSIGNMENT_DP_STATUS',
3126                         'Personal status (Date paid context)');
3127     --
3128     -- insert database items for the route defined above:
3129     --
3130     insert_database_item ('ASG_PER_STATUS_DP',
3131                           'STYPE.per_system_status',
3132                      'Personal status for the assignment (Date paid context)',
3133                           'T',
3134                           'Y');
3135     --
3136     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3137     --                                                               +
3138     -- Route for last processed period number : SEH_ASS_LAST_PER_NUM +
3139     -- (Date Paid route)                                             +
3140     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3141     --
3142     l_text := '/* Period number the assignment last processed */
3143        pay_assignment_actions            ASSACT
3144 ,      pay_payroll_actions               PACT
3145 ,      pay_payrolls_f                    PAYROLL
3146 ,      per_time_periods                  TIMEP
3147 where  ASSACT.assignment_id            = &B1
3148 and    ASSACT.action_sequence =
3149       (
3150        select max (ASSACT2.action_sequence)
3151        from   pay_payroll_actions              PACT2
3152        ,      pay_assignment_actions           ASSACT2
3153        where  ASSACT2.assignment_id          = &B1
3154        and    ASSACT2.action_status          = ''C''
3155        and    PACT2.payroll_action_id        = ASSACT2.payroll_action_id
3156        and    PACT2.action_type             in (''R'', ''Q'')
3157       )
3158 and    PACT.payroll_action_id          = ASSACT.payroll_action_id
3159 and    PACT.time_period_id             = TIMEP.time_period_id
3160 and    PAYROLL.payroll_id              = PACT.payroll_id
3161 and    PACT.effective_date       BETWEEN PAYROLL.effective_start_date
3162                                      AND PAYROLL.effective_end_date';
3163     --
3164     insert_route ('SEH_ASS_LAST_PER_NUM',
3165                   'Period number the assignment last processed',
3166                   l_text);
3167     --
3168     insert_route_context_usages (l_assign_id_context_id, 1);
3169     --
3170     insert_user_entity ('LAST_PER_NUMBER',
3171                         'Period number the assignment last processed',
3172                         'Y');
3173     --
3174     -- insert database items for the route defined above:
3175     --
3176     insert_database_item ('ASG_LAST_PROC_PERIOD_NUMBER',
3177                           '/*+ INDEX(ASSACT PAY_ASSIGNMENT_ACTIONS N1)*/ TIMEP.period_num',
3178                      'The period number the assignment was last processed',
3179                           'N',
3180                           'N');
3181     --
3182     insert_database_item ('ASG_LAST_PROC_PERIOD_NAME',
3183                           '/*+ INDEX(ASSACT PAY_ASSIGNMENT_ACTIONS N1)*/ TIMEP.period_name',
3184                           'The period name the assignment was last processed',
3185                           'T',
3186                           'N');
3187     --
3188     insert_database_item ('ASG_LAST_PROC_PERIOD_ID',
3189                           '/*+ INDEX(ASSACT PAY_ASSIGNMENT_ACTIONS N1)*/ TIMEP.time_period_id',
3190                           'The Time period id the assignment was last processed',
3191                           'N',
3192                           'N');
3193     --
3194     insert_database_item ('ASG_LAST_PROC_PAYROLL_NAME',
3195                           '/*+ INDEX(ASSACT PAY_ASSIGNMENT_ACTIONS N1)*/ PAYROLL.payroll_name',
3196                           'The payroll name the assignment was last processed',
3197                           'T',
3198                           'N');
3199     --
3200     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3201     --                                                                      +
3202     -- Route for last processed period number : SEH_ASG_LAST_EARNED_PER_NUM +
3203     -- (Date Earned route)                                                  +
3204     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3205     --
3206     l_text := '/* Period number the assignment last processed */
3207        pay_assignment_actions            ASSACT
3208 ,      pay_payroll_actions               PACT
3209 ,      pay_payrolls_f                    PAYROLL
3210 ,      per_time_periods                  TIMEP
3211 where  ASSACT.assignment_id            = &B1
3212 and    ASSACT.action_sequence =
3213       (
3214        select max (ASSACT2.action_sequence)
3215        from   pay_payroll_actions              PACT2
3216        ,      pay_assignment_actions           ASSACT2
3217        where  ASSACT2.assignment_id          = &B1
3218        and    ASSACT2.action_status          = ''C''
3219        and    PACT2.payroll_action_id        = ASSACT2.payroll_action_id
3220        and    PACT2.action_type             in (''R'', ''Q'')
3221       )
3222 and    PACT.payroll_action_id          = ASSACT.payroll_action_id
3223 and    PACT.time_period_id             = TIMEP.time_period_id
3224 and    PAYROLL.payroll_id              = PACT.payroll_id
3225 and    PACT.date_earned       BETWEEN PAYROLL.effective_start_date
3226                                   AND PAYROLL.effective_end_date';
3227     --
3228     insert_route ('SEH_ASG_LAST_EARNED_PER_NUM',
3229                   'Period number the assignment last processed as of date earned',
3230                   l_text);
3231     --
3232     insert_route_context_usages (l_assign_id_context_id, 1);
3233     --
3234     insert_user_entity ('LAST_EARNED_PER_NUMBER',
3235                         'Period number the assignment last processed as of date earned',
3236                         'Y');
3237     --
3238     -- insert database items for the route defined above:
3239     --
3240     insert_database_item ('ASG_LAST_EARNED_PERIOD_NUMBER',
3241                           '/*+ INDEX(ASSACT PAY_ASSIGNMENT_ACTIONS N1)*/ TIMEP.period_num',
3242                      'The period number the assignment was last processed as of date earned',
3243                           'N',
3244                           'N');
3245     --
3246     insert_database_item ('ASG_LAST_EARNED_PERIOD_NAME',
3247                           '/*+ INDEX(ASSACT PAY_ASSIGNMENT_ACTIONS N1)*/ TIMEP.period_name',
3248                           'The period name the assignment was last processed as of date earned',
3249                           'T',
3250                           'N');
3251     --
3252     insert_database_item ('ASG_LAST_EARNED_PERIOD_ID',
3253                           '/*+ INDEX(ASSACT PAY_ASSIGNMENT_ACTIONS N1)*/ TIMEP.time_period_id',
3254                           'The Time period id the assignment was last processed as of date earned',
3255                           'N',
3256                           'N');
3257     --
3258     insert_database_item ('ASG_LAST_EARNED_PAYROLL_NAME',
3259                           '/*+ INDEX(ASSACT PAY_ASSIGNMENT_ACTIONS N1)*/ PAYROLL.payroll_name',
3260                           'The payroll name the assignment was last processed as of date earned',
3261                           'T',
3262                           'N');
3263     --
3264     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++
3265     --                                                      +
3266     -- Route for Assignment start date : SEH_ASS_START_DATE +
3267     --                                                      +
3268     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++
3269     --
3270     l_text := '/*  Assignment start date */
3271     per_assignments_f
3272 where   assignment_id       = &B1';
3273     --
3274     insert_route ('SEH_ASS_START_DATE',
3275                   'Start date for the assignment',
3276                   l_text);
3277     --
3278     insert_route_context_usages (l_assign_id_context_id,   1);
3279     --
3280     insert_user_entity ('ASS_START_DATE',
3281                         'The start date of the assignment');
3282     --
3283     -- insert database items for the route defined above:
3284     --
3285     insert_database_item ('ASG_START_DATE',
3286                           'min (effective_start_date)',
3287                           'The start date of the assignment',
3288                           'D',
3289                           'Y');
3290     --
3291     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++
3292     --                                                      +
3293     -- Route for Assignment action : SEH_ASS_ACTION         +
3294     --                                                      +
3295     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++
3296     --
3297     l_text := '/*  Assignment action route */
3298     pay_assignment_actions
3299 where   assignment_action_id  = &B1';
3300     --
3301     insert_route ('SEH_ASS_ACTION',
3302                   'Assignment action route',
3303                   l_text);
3304     --
3305     insert_route_context_usages (l_assign_action_id_context_id,   1);
3306     --
3307     insert_user_entity ('SEH_ASS_ACTION',
3308                         'Assignment action route');
3309     --
3310     -- insert database items for the route defined above:
3311     --
3312     insert_database_item ('CHEQUE_UK_NUMBER',
3313                           'serial_number',
3314               'The cheque number for the assignment action (UK spelling)',
3315                           'T',
3316                           'Y');
3317     --
3318     insert_database_item ('CHECK_US_NUMBER',
3319                           'serial_number',
3320               'The cheque number for the assignment action (US spelling)',
3321                           'T',
3322                           'Y');
3323     --
3324     --++++++++++++++++++++++++++++++++++++++++++++++
3325     --                                             +
3326     -- Route for Payroll details : SEH_PAY_DETAILS +
3327     --                                             +
3328     --++++++++++++++++++++++++++++++++++++++++++++++
3329     --
3330     l_text := '/*  Payroll details */
3331         pay_payroll_actions                      PACTION
3332 ,       per_time_periods                         TPERIOD
3333 ,       per_time_period_types                    TPTYPE
3334 where   PACTION.payroll_action_id              = &B1
3335 and     TPERIOD.time_period_id                 = PACTION.time_period_id
3336 and     TPTYPE.period_type                     = TPERIOD.period_type';
3337     --
3338     insert_route ('SEH_PAY_DETAILS',
3339                   'Payroll details',
3340                   l_text);
3341     --
3342     insert_route_context_usages (l_payroll_action_id_context_id, 1);
3343     --
3344     insert_user_entity ('PAY_DETAILS',
3345                         'Payroll details',
3346                         'Y');
3347     --
3348     -- insert database items for the route defined above:
3349     --
3350     --
3351     insert_database_item ('PAY_PROC_PERIOD_NUMBER',
3352                           'TPERIOD.period_num',
3353                           'The current period number for the payroll',
3354                           'N',
3355                           'N');
3356     --
3357     insert_database_item ('PAY_PROC_PERIOD_START_DATE',
3358                           'TPERIOD.start_date',
3359                           'The start date of the payroll period',
3360                           'D',
3361                           'N');
3362     --
3363     insert_database_item ('PAY_PROC_PERIOD_END_DATE',
3364                           'TPERIOD.end_date',
3365                           'The end date of the payroll period',
3366                           'D',
3367                           'N');
3368     --
3369     insert_database_item ('PAY_PROC_PERIOD_DIRECT_DEPOSIT_DATE',
3370                           'TPERIOD.default_dd_date',
3371                           'The direct deposit date for the payroll period',
3372                           'D',
3373                           'Y');
3374     --
3375     insert_database_item ('PAY_PROC_PERIOD_PAY_ADVICE_DATE',
3376                           'TPERIOD.pay_advice_date',
3377                           'The pay advice date for the payroll period',
3378                           'D',
3379                           'Y');
3380     --
3381     insert_database_item ('PAY_PROC_PERIOD_CUT_OFF_DATE',
3382                           'TPERIOD.cut_off_date',
3383                           'The cut off date for the payroll period',
3384                           'D',
3385                           'Y');
3386     --
3387     insert_database_item ('PAY_PROC_PERIOD_ID',
3388                           'TPERIOD.time_period_id',
3389                           'The id of the time period for the payroll',
3390                           'N',
3391                           'N');
3392     --
3393     insert_database_item ('PAY_PROC_PERIOD_NAME',
3394                           'TPERIOD.period_name',
3395                           'The period name for the payroll',
3396                           'T',
3397                           'N');
3398     --
3399     insert_database_item ('PAY_PERIODS_PER_YEAR',
3400                           'TPTYPE.number_per_fiscal_year',
3401                           'The number of payable periods in the year',
3402                           'N',
3403                           'N');
3404     --
3405     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3406     --                                                            +
3407     -- Route for Payroll Action details : SEH_PAY_ACTION_DETAILS  +
3408     --                                                            +
3409     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3410     --
3411     l_text := '/*  Payroll action details */
3412        pay_payroll_actions            PACTION
3413 where  PACTION.payroll_action_id    = &B1';
3414     --
3415     insert_route ('SEH_PAY_ACTION_DETAILS',
3416                   'Payroll action details',
3417                   l_text);
3418     --
3419     insert_route_context_usages (l_payroll_action_id_context_id, 1);
3420     --
3421     insert_user_entity ('PAY_ACTION_DETAILS',
3422                         'Payroll action details');
3423     --
3424     -- insert database items for the route defined above:
3425     --
3426     --
3427     insert_database_item ('PAY_PROC_PERIOD_DATE_PAID',
3428                           'PACTION.effective_date',
3429                           'The date the payroll was paid',
3430                           'D',
3431                           'N');
3432     --
3433     -- Some salary admin DB items:
3434     --
3435     --+++++++++++++++++++++++++++++++++++++++++++++++++++
3436     --                                                  +
3437     -- Route for Salary Basis : SEH_SADMIN_SALARY_BASIS +
3438     --                                                  +
3439     --+++++++++++++++++++++++++++++++++++++++++++++++++++
3440     --
3441     l_text := '/* Salary basis route for salary admin */
3442         per_assignments_f                      ASSIGN
3443 ,       per_pay_bases                          BASES
3444 ,       pay_input_values_f                     INPUTV
3445 ,       pay_element_types_f                    ETYPE
3446 ,       pay_rates                              RATE
3447 ,       hr_lookups                             HR1
3448 ,       hr_lookups                             HR2
3449 where   &B1 BETWEEN ASSIGN.effective_start_date
3450                  AND ASSIGN.effective_end_date
3451 and     ASSIGN.assignment_id                 = &B2
3452 and     BASES.pay_basis_id                (+)= ASSIGN.pay_basis_id
3453 and     INPUTV.input_value_id             (+)= BASES.input_value_id
3454 and     &B1 between nvl (INPUTV.effective_start_date, &B1)
3455                  and nvl (INPUTV.effective_end_date, &B1)
3456 and     ETYPE.element_type_id             (+)= INPUTV.element_type_id
3457 and     &B1 between nvl (ETYPE.effective_start_date, &B1)
3458                  and nvl (ETYPE.effective_end_date, &B1)
3459 and     RATE.rate_id                      (+)= BASES.rate_id
3460 and     HR1.lookup_code                   (+)= BASES.pay_basis
3461 and     HR1.lookup_type                   (+)= ''PAY_BASIS''
3462 and     HR1.application_id                (+)= 800
3463 and     HR2.lookup_code                   (+)= BASES.rate_basis
3464 and     HR2.application_id                (+)= 800
3465 and     HR2.lookup_type                   (+)= ''PAY_BASIS''';
3466     --
3467     insert_route ('SEH_SADMIN_SALARY_BASIS',
3468                   'Salary basis route for salary admin',
3469                   l_text);
3470     --
3471     insert_route_context_usages (l_date_earned_context_id, 1);
3472     insert_route_context_usages (l_assign_id_context_id,   2);
3473     --
3474     insert_user_entity ('SADMIN_SALARY_BASIS',
3475                         'Salary basis');
3476     --
3477     -- insert database items for the route defined above:
3478     --
3479     -- moved the databse items to SEH_SADMIN_SALARY_BASIS_PERF
3480     --
3481     -- Some salary admin DB items:
3482     --
3483     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3484     --                                                       +
3485     -- Route for Salary Basis : SEH_SADMIN_SALARY_BASIS_PERF +
3486     --                                                       +
3487     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3488     --
3489     l_text := '/* Salary basis route for salary admin */
3490         per_assignments_f                      ASSIGN
3491 ,       per_pay_bases                          BASES
3492 ,       pay_input_values_f                     INPUTV
3493 ,       pay_element_types_f                    ETYPE
3494 ,       pay_rates                              RATE
3495 where   &B1 BETWEEN ASSIGN.effective_start_date
3496                  AND ASSIGN.effective_end_date
3497 and     ASSIGN.assignment_id                 = &B2
3498 and     BASES.pay_basis_id                (+)= ASSIGN.pay_basis_id
3499 and     INPUTV.input_value_id             (+)= BASES.input_value_id
3500 and     &B1 between nvl (INPUTV.effective_start_date, &B1)
3501                  and nvl (INPUTV.effective_end_date, &B1)
3502 and     ETYPE.element_type_id             (+)= INPUTV.element_type_id
3503 and     &B1 between nvl (ETYPE.effective_start_date, &B1)
3504                  and nvl (ETYPE.effective_end_date, &B1)
3505 and     RATE.rate_id                      (+)= BASES.rate_id';
3506     --
3507     insert_route ('SEH_SADMIN_SALARY_BASIS_PERF',
3508                   'Salary basis route for salary admin (performant version)',
3509                   l_text);
3510     --
3511     insert_route_context_usages (l_date_earned_context_id, 1);
3512     insert_route_context_usages (l_assign_id_context_id,   2);
3513     --
3514     insert_user_entity ('SADMIN_SALARY_BASIS_PERF',
3515                         'Salary basis (performant version)');
3516     --
3517     -- insert database items for the route defined above:
3518     --
3519     insert_database_item ('ASG_SALARY_BASIS_NAME',
3520                           'BASES.name',
3521                           'The salary basis name for the assignment',
3522                           'T',
3523                           'Y');
3524     --
3525     insert_database_item ('ASG_SALARY_BASIS',
3526                           'hr_general.decode_lookup(''PAY_BASIS'',
3527                           	BASES.pay_basis)',
3528     'The payment basis (ie. frequency) for the assignment, eg. monthly',
3529                           'T',
3530                           'Y');
3531     --
3532     insert_database_item ('ASG_SALARY_BASIS_CODE',
3533                           'BASES.pay_basis',
3534                           'The payment basis lookup code for the assignment',
3535                           'T',
3536                           'Y');
3537     --
3538     insert_database_item ('ASG_SALARY_BASIS_ANNUALIZATION_FACTOR',
3539                           'BASES.pay_annualization_factor',
3540                           'The payment basis pay annualization factor for the assignment',
3541                           'N',
3542                           'Y');
3543     --
3544     insert_database_item ('ASG_SALARY_BASIS_GRADE_ANNUALIZATION_FACTOR',
3545                           'BASES.grade_annualization_factor',
3546                           'The payment basis grade annualization factor for the assignment',
3547                           'N',
3548                           'Y');
3549     --
3550     insert_database_item ('ASG_SALARY_ELEMENT',
3551                           'ETYPE.element_name',
3552                           'The display element name',
3553                           'T',
3554                           'Y');
3555     --
3556     insert_database_item ('ASG_SALARY_ELEMENT_VALUE_NAME',
3557                           'INPUTV.name',
3558                           'The display input value name',
3559                           'T',
3560                           'Y');
3561     --
3562     insert_database_item ('ASG_SALARY_GRADE_RATE',
3563                           'RATE.name',
3564                           'The display rate name',
3565                           'T',
3566                           'Y');
3567     --
3568     insert_database_item ('ASG_SALARY_RATE_BASIS',
3569                           'hr_general.decode_lookup(''PAY_BASIS'',
3570                           	BASES.rate_basis)',
3571                           'The salary rate basis (ie. frequency)',
3572                           'T',
3573                           'Y');
3574     --
3575     --+++++++++++++++++++++++++++++++++++++++++++++++++++++
3576     --                                                    +
3577     -- Route for Salary Basis : SEH_SADMIN_SALARY_ELEMENT +
3578     --                                                    +
3579     --+++++++++++++++++++++++++++++++++++++++++++++++++++++
3580     --
3581     l_text := '/* Salary element route for salary admin */
3582         per_assignments_f                      ASSIGN
3583 ,       per_pay_bases                          BASES
3584 ,       pay_element_entries_f                  EE
3585 ,       pay_element_entry_values_f             EEV
3586 where   &B1 BETWEEN ASSIGN.effective_start_date
3587                  AND ASSIGN.effective_end_date
3588 and     ASSIGN.assignment_id                 = &B2
3589 and     BASES.pay_basis_id                +0 = ASSIGN.pay_basis_id
3590 and     EEV.input_value_id                   = BASES.input_value_id
3591 and     &B1 BETWEEN EEV.effective_start_date
3592                  AND EEV.effective_end_date
3593 and     EE.assignment_id                     = ASSIGN.assignment_id
3594 and     EE.entry_type = ''E''
3595 and     &B1 BETWEEN EE.effective_start_date
3596                  AND EE.effective_end_date
3597 and     EEV.element_entry_id                 = EE.element_entry_id';
3598     --
3599     insert_route ('SEH_SADMIN_SALARY_ELEMENT',
3600                   'Salary element route for salary admin',
3601                   l_text);
3602     --
3603     insert_route_context_usages (l_date_earned_context_id, 1);
3604     insert_route_context_usages (l_assign_id_context_id,   2);
3605     --
3606     -- since the above route could fail (eg. if the assignment is not on the
3607     -- payroll) both null allowed and not found allowed are set to yes, and
3608     -- this DB item is on its own.
3609     --
3610     insert_user_entity ('SADMIN_SALARY_ELEMENT',
3611                         'Salary element',
3612                         'Y');
3613     --
3614     -- insert database items for the route defined above:
3615     --
3616     insert_database_item ('ASG_SALARY',
3617                           'fnd_number.canonical_to_number (EEV.screen_entry_value)',
3618                           'The current salary for an employee',
3619                           'N',
3620                           'Y');
3621     --
3622     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3623     --                                                          +
3624     -- Route for Salary proposals : SEH_SADMIN_SALARY_PROPOSALS +
3625     --                                                          +
3626     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3627     --
3628     l_text := '/* Salary Proposals route for salary admin */
3629         per_pay_proposals            PRO
3630 ,       pay_element_entries_f        EE
3631 ,       hr_lookups                   HR1
3632 ,       hr_lookups                   HRNO
3633 ,       hr_lookups                   HRYES
3634 where   PRO.assignment_id          = &B2
3635 and     HR1.lookup_code         (+)= PRO.proposal_reason
3636 and     HR1.lookup_type         (+)= ''PROPOSAL_REASON''
3637 and     HRNO.lookup_code           = ''N''
3638 and     HRNO.lookup_type           = ''YES_NO''
3639 and     HRNO.application_id        = 800
3640 and     HRYES.lookup_code          = ''Y''
3641 and     HRYES.lookup_type          = ''YES_NO''
3642 and     HRYES.application_id       = 800
3643 and     EE.creator_id           (+)= PRO.pay_proposal_id
3644 and     EE.creator_type         (+)= ''SP''
3645 and     PRO.change_date =
3646         (select  max (PRO2.change_date)
3647          from    per_pay_proposals         PRO2
3648          where   PRO2.change_date       <= &B1
3649          and     PRO2.assignment_id      = PRO.assignment_id)';
3650     --
3651     insert_route ('SEH_SADMIN_SALARY_PROPOSALS',
3652                   'Salary Proposals route for salary admin',
3653                   l_text);
3654     --
3655     insert_route_context_usages (l_date_earned_context_id, 1);
3656     insert_route_context_usages (l_assign_id_context_id,   2);
3657     --
3658     insert_user_entity ('SEH_SADMIN_SALARY_PROPOSALS',
3659                         'Salary element',
3660                         'Y');
3661     --
3662     -- insert database items for the route defined above:
3663     --
3664     -- moved the database item to SEH_SADMIN_SALARY_PROPOSALS_PERF
3665     --
3666     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3667     --                                                               +
3668     -- Route for Salary proposals : SEH_SADMIN_SALARY_PROPOSALS_PERF +
3669     --                                                               +
3670     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3671     --
3672     l_text := '/* Salary Proposals route for salary admin */
3673         per_pay_proposals            PRO
3674 ,       pay_element_entries_f        EE
3675 ,       hr_lookups                   HRNO
3676 ,       hr_lookups                   HRYES
3677 where   PRO.assignment_id          = &B2
3678 and     HR1.lookup_code         (+)= PRO.proposal_reason
3679 and     HR1.lookup_type         (+)= ''PROPOSAL_REASON''
3680 and     HRNO.lookup_code           = ''N''
3681 and     HRNO.lookup_type           = ''YES_NO''
3682 and     HRNO.application_id        = 800
3683 and     HRYES.lookup_code          = ''Y''
3684 and     HRYES.lookup_type          = ''YES_NO''
3685 and     HRYES.application_id       = 800
3686 and     EE.creator_id           (+)= PRO.pay_proposal_id
3687 and     EE.creator_type         (+)= ''SP''
3688 and     PRO.change_date =
3689         (select  max (PRO2.change_date)
3690          from    per_pay_proposals         PRO2
3691          where   PRO2.change_date       <= &B1
3692          and     PRO2.assignment_id      = PRO.assignment_id)';
3693     --
3694     insert_route ('SEH_SADMIN_SALARY_PROPOSALS_PERF',
3695                   'Salary Proposals route for salary admin ( performant version)',
3696                   l_text);
3697     --
3698     insert_route_context_usages (l_date_earned_context_id, 1);
3699     insert_route_context_usages (l_assign_id_context_id,   2);
3700     --
3701     insert_user_entity ('SEH_SADMIN_SALARY_PROPOSALS_PERF',
3702                         'Salary element (performant version)',
3703                         'Y');
3704     --
3705     -- insert database items for the route defined above:
3706     --
3707     insert_database_item ('ASG_LAST_SALARY_CHANGE_APPROVED',
3708           'decode (EE.element_entry_id, null, HRNO.meaning, HRYES.meaning)',
3709               'Whether the last proposed salary change has been approved ',
3710                           'T',
3711                           'N');
3712     --
3713     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3714     --                                                            +
3715     -- Route for Salary proposals : SEH_SADMIN_SALARY_PROPOSALS_2 +
3716     --                                                            +
3717     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3718     --
3719     l_text := '/* Salary Proposals route for salary admin */
3720         per_pay_proposals            PRO
3721 ,       hr_lookups                   HR1
3722 ,       hr_lookups                   HRNO
3723 ,       hr_lookups                   HRYES
3724 where   PRO.assignment_id          = &B2
3725 and     HR1.lookup_code         (+)= PRO.proposal_reason
3726 and     HR1.lookup_type         (+)= ''PROPOSAL_REASON''
3727 and     HRNO.lookup_code           = ''N''
3728 and     HRNO.lookup_type           = ''YES_NO''
3729 and     HRNO.application_id        = 800
3730 and     HRYES.lookup_code          = ''Y''
3731 and     HRYES.lookup_type          = ''YES_NO''
3732 and     HRYES.application_id       = 800
3733 and     PRO.change_date =
3734         (select  max (PRO2.change_date)
3735          from    per_pay_proposals          PRO2
3736          where   PRO2.change_date        <= &B1
3737          and     PRO2.assignment_id       = PRO.assignment_id)';
3738     --
3739     insert_route ('SEH_SADMIN_SALARY_PROPOSALS_2',
3740                   'Salary Proposals route for salary admin',
3741                   l_text);
3742     --
3743     insert_route_context_usages (l_date_earned_context_id, 1);
3744     insert_route_context_usages (l_assign_id_context_id,   2);
3745     --
3746     insert_user_entity ('SEH_SADMIN_SALARY_PROPOSALS_2',
3747                         'Salary element',
3748                         'Y');
3749     --
3750     -- insert database items for the route defined above:
3751     --
3752     -- moved the database items to SEH_SADMIN_SALARY_PROPOSALS_2_PERF
3753     --
3754     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3755     --                                                                 +
3756     -- Route for Salary proposals : SEH_SADMIN_SALARY_PROPOSALS_2_PERF +
3757     --                                                                 +
3758     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3759     --
3760     l_text := '/* Salary Proposals route for salary admin */
3761         per_pay_proposals            PRO
3762 ,       hr_lookups                   HRNO
3763 ,       hr_lookups                   HRYES
3764 where   PRO.assignment_id          = &B2
3765 and     HRNO.lookup_code           = ''N''
3766 and     HRNO.lookup_type           = ''YES_NO''
3767 and     HRNO.application_id        = 800
3768 and     HRYES.lookup_code          = ''Y''
3769 and     HRYES.lookup_type          = ''YES_NO''
3770 and     HRYES.application_id       = 800
3771 and     PRO.change_date =
3772         (select  max (PRO2.change_date)
3773          from    per_pay_proposals          PRO2
3774          where   PRO2.change_date        <= &B1
3775          and     PRO2.assignment_id       = PRO.assignment_id)';
3776     --
3777     insert_route ('SEH_SADMIN_SALARY_PROPOSALS_2_PERF',
3778                   'Salary Proposals route for salary admin (performant version)',
3779                   l_text);
3780     --
3781     insert_route_context_usages (l_date_earned_context_id, 1);
3782     insert_route_context_usages (l_assign_id_context_id,   2);
3783     --
3784     insert_user_entity ('SEH_SADMIN_SALARY_PROPOSALS_2_PERF',
3785                         'Salary element (performant version)',
3786                         'Y');
3787     --
3788     -- insert database items for the route defined above:
3789     --
3790     --
3791     insert_database_item ('ASG_LAST_SALARY_DATE',
3792                           'PRO.change_date',
3793                           'The last salary change date',
3794                           'D',
3795                           'Y');
3796     --
3797     insert_database_item ('ASG_LAST_CHANGE_REASON',
3798                           'hr_general.decode_lookup(''PROPOSAL_REASON'',
3799                           	PRO.proposal_reason)',
3800                           'The reason the salary was changed',
3801                           'T',
3802                           'Y');
3803     --
3804     insert_database_item ('ASG_NEXT_SALARY_DATE',
3805                           'PRO.next_sal_review_date',
3806                           'The date of the next salary change',
3807                           'D',
3808                           'Y');
3809     --
3810     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3811     --                                                                    +
3812     -- Route for last performance review : SEH_SADMIN_LAST_PERFORM_REVIEW +
3813     --                                                                    +
3814     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3815     --
3816     l_text := '/* Last performance review route for salary admin */
3817         per_performance_reviews PRO
3818 ,       per_assignments_f ASG
3819 ,       per_events EVENT
3820 ,       hr_lookups HR1
3821 ,       hr_lookups HR2
3822 ,       hr_locations LOC
3823 where   ASG.assignment_id                    = &B2
3824 and     &B1 between ASG.effective_start_date
3825                  and ASG.effective_end_date
3826 and     PRO.person_id                        = ASG.person_id
3827 and     PRO.review_date                      =
3828         (select  max (PRO2.review_date)
3829          from    per_performance_reviews       PRO2
3830          where   PRO2.person_id        = PRO.person_id
3831          and     PRO2.review_date     <= &B1)
3832 and     EVENT.event_id                    (+)= PRO.event_id
3833 and     HR1.lookup_code                   (+)= EVENT.type
3834 and     HR1.lookup_type                   (+)= ''EMP_INTERVIEW_TYPE''
3835 and     HR2.lookup_code                   (+)= PRO.performance_rating
3836 and     HR2.lookup_type                   (+)= ''PERFORMANCE_RATING''
3837 and     LOC.location_id                   (+)= EVENT.location_id';
3838     --
3839     insert_route ('SEH_SADMIN_LAST_PERFORM_REVIEW',
3840                   'Last performance review route for salary admin',
3841                   l_text);
3842     --
3843     insert_route_context_usages (l_date_earned_context_id, 1);
3844     insert_route_context_usages (l_assign_id_context_id,   2);
3845     --
3846     insert_user_entity ('SEH_SADMIN_LAST_REVIEW',
3847                         'Salary element',
3848                         'Y');
3849     --
3850     -- insert database items for the route defined above:
3851     --
3852     -- moved the database items to SEH_SADMIN_LAST_PERFORM_REVIEW_PERF
3853     --
3854     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3855     --                                                                         +
3856     -- Route for last performance review : SEH_SADMIN_LAST_PERFORM_REVIEW_PERF +
3857     --                                                                         +
3858     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3859     --
3860     l_text := '/* Last performance review route for salary admin */
3861         per_performance_reviews PRO
3862 ,       per_assignments_f ASG
3863 ,       per_events EVENT
3864 ,       hr_locations LOC
3865 where   ASG.assignment_id                    = &B2
3866 and     &B1 between ASG.effective_start_date
3867                  and ASG.effective_end_date
3868 and     PRO.person_id                        = ASG.person_id
3869 and     PRO.review_date                      =
3870         (select  max (PRO2.review_date)
3871          from    per_performance_reviews       PRO2
3872          where   PRO2.person_id        = PRO.person_id
3873          and     PRO2.review_date     <= &B1)
3874 and     EVENT.event_id                    (+)= PRO.event_id
3875 and     LOC.location_id                   (+)= EVENT.location_id';
3876     --
3877     insert_route ('SEH_SADMIN_LAST_PERFORM_REVIEW_PERF',
3878                   'Last performance review route for salary admin (performant version)',
3879                   l_text);
3880     --
3881     insert_route_context_usages (l_date_earned_context_id, 1);
3882     insert_route_context_usages (l_assign_id_context_id,   2);
3883     --
3884     insert_user_entity ('SEH_SADMIN_LAST_REVIEW_PERF',
3885                         'Salary element (performant version)',
3886                         'Y');
3887     --
3888     -- insert database items for the route defined above:
3889     --
3890     insert_database_item ('ASG_LAST_PERFORMANCE_DATE',
3891           'decode (PRO.event_id, null, PRO.review_date, EVENT.date_start)',
3892                           'Last performance review date',
3893                           'D',
3894                           'Y');
3895     --
3896     insert_database_item ('ASG_LAST_PERFORMANCE_TYPE',
3897                           'hr_general.decode_lookup(''EMP_INTERVIEW_TYPE'',
3898                           	EVENT.type)',
3899                           'Last performance review type',
3900                           'T',
3901                           'Y');
3902     --
3903     insert_database_item ('ASG_LAST_PERFORMANCE_LOCATION',
3904                           'LOC.location_code',
3905                           'Last performance review location',
3906                           'T',
3907                           'Y');
3908     --
3909     insert_database_item ('ASG_LAST_PERFORMANCE_RATING',
3910                           'hr_general.decode_lookup(''PERFORMANCE_RATING'',
3911                           	PRO.performance_rating)',
3912                           'Last performance review rating',
3913                           'T',
3914                           'Y');
3915     --
3916     insert_database_item ('ASG_NEXT_PERFORMANCE_DATE',
3917                           'PRO.next_perf_review_date',
3918                           'Next performance review date',
3919                           'D',
3920                           'Y');
3921     --
3922     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3923     --                                                                    +
3924     -- Route for last salary change : SEH_SADMIN_LAST_SALARY_CHANGE       +
3925     --                                                                    +
3926     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3927     --
3928     l_text := '/* Last salary change route for salary admin */
3929         pay_element_entries_f                EE
3930 ,       pay_element_entry_values_f           EEV
3931 ,       per_pay_bases                        BASES1
3932 ,       per_pay_bases                        BASES2
3933 ,       per_pay_proposals                    PRO
3934 ,       per_assignments_f                    ASSIGN1
3935 ,       per_assignments_f                    ASSIGN2
3936 where   EEV.effective_start_date           = EE.effective_start_date
3937 /*  ^ Every change of entry results in a change of the entry values also  */
3938 and     EE.assignment_id                   = &B2
3939 and     EEV.element_entry_id               = EE.element_entry_id
3940 and     EEV.input_value_id                 = BASES1.input_value_id
3941 and     PRO.assignment_id                  = &B2
3942 and     (PRO.change_date - 1)        between EE.effective_start_date
3943                                          and EE.effective_end_date
3944 /* ^ finds the last salary entry  amongst others */
3945 and     ASSIGN2.pay_basis_id               = BASES2.pay_basis_id
3946 and     ASSIGN1.pay_basis_id               = BASES1.pay_basis_id
3947 and     (PRO.change_date - 1)        between ASSIGN1.effective_start_date
3948                                          and ASSIGN1.effective_end_date
3949 /* ^ find the assignment record for the last actual salary change */
3950 and     PRO.change_date              between ASSIGN2.effective_start_date
3951                                          and ASSIGN2.effective_end_date
3952 /* ^ find the assignment record on the day of the proposed change */
3953 and     ASSIGN2.assignment_id              = PRO.assignment_id
3954 and     ASSIGN1.assignment_id              = PRO.assignment_id
3955 and     PRO.change_date =
3956         (select  max(PRO2.change_date)
3957          from    per_pay_proposals        PRO2
3958          where   PRO2.change_date      <= &B1
3959          and     PRO2.assignment_id     = PRO.assignment_id)';
3960     --
3961     insert_route ('SEH_SADMIN_LAST_SALARY_CHANGE',
3962                   'Last salary change route for salary admin',
3963                   l_text);
3964     --
3965     insert_route_context_usages (l_date_earned_context_id, 1);
3966     insert_route_context_usages (l_assign_id_context_id,   2);
3967     --
3968     insert_user_entity ('SEH_SADMIN_LAST_SALARY_CHANGE',
3969                         'Last salary change',
3970                         'Y');
3971     --
3972     -- insert database items for the route defined above:
3973     --
3974     insert_database_item ('ASG_LAST_PROPOSED_SALARY_CHANGE',
3975    'decode(BASES1.pay_basis, BASES2.pay_basis, (PRO.proposed_salary_n -
3976     EEV.screen_entry_value), null)',
3977                           'The proposed salary change',
3978                           'N',
3979                           'Y');
3980     --
3981     insert_database_item ('ASG_LAST_PROPOSED_SALARY_PERCENT',
3982   'decode(BASES1.pay_basis, BASES2.pay_basis, (((PRO.proposed_salary_n -
3983    EEV.screen_entry_value) *100)/EEV.screen_entry_value), null)',
3984                           'The proposed salary change as a percentage',
3985                           'N',
3986                           'Y');
3987     --
3988     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3989     --                                                                    +
3990     -- Route for general HR addresss : SEH_ASSIGN_HR_ADDRESS              +
3991     --                                                                    +
3992     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3993     --
3994     l_text := '/* The work address for the assignment (general legislation) */
3995         per_all_assignments_f                  ASSIGN
3996 ,       hr_locations                           HRLOC
3997 ,       fnd_territories_tl                     TER
3998 where	&B1 BETWEEN ASSIGN.effective_start_date
3999                  AND ASSIGN.effective_end_date
4000 and     ASSIGN.assignment_id                 = &B2
4001 and     HRLOC.location_id                    = ASSIGN.location_id
4002 and     TER.territory_code                (+)= HRLOC.country
4003 and     TER.language                      (+)= userenv(''LANG'')';
4004     --
4005     insert_route ('SEH_ASSIGN_HR_ADDRESS',
4006                   'The work address for the assignment (general legislation)',
4007                   l_text);
4008     --
4009     insert_route_context_usages (l_date_earned_context_id, 1);
4010     insert_route_context_usages (l_assign_id_context_id,   2);
4011     --
4012     insert_user_entity ('SEH_ASSIGN_HR_ADDRESS',
4013                  'The work address for the assignment (general legislation)',
4014                         'Y');
4015     --
4016     -- insert database items for the route defined above:
4017     --
4018     --
4019     insert_database_item ('LOC_ADR_LINE_1',
4020                           'HRLOC.address_line_1',
4021                           'The first line of the assignment''s work address',
4022                           'T',
4023                           'Y');
4024     --
4025     insert_database_item ('LOC_ADR_LINE_2',
4026                           'HRLOC.address_line_2',
4027                           'The second line of the assignment''s work address',
4028                           'T',
4029                           'Y');
4030     --
4031     insert_database_item ('LOC_ADR_LINE_3',
4032                           'HRLOC.address_line_3',
4033                           'The third line of the assignment''s work address',
4034                           'T',
4035                           'Y');
4036     --
4037     insert_database_item ('LOC_ADR_POSTAL_CODE',
4038                           'HRLOC.postal_code',
4039                           'The postal code for the assignment''s work address',
4040                           'T',
4041                           'Y');
4042     --
4043     insert_database_item ('LOC_ADR_REGION_1',
4044                           'HRLOC.region_1',
4045                           'The first line of the assignment''s region',
4046                           'T',
4047                           'Y');
4048     --
4049     insert_database_item ('LOC_ADR_REGION_2',
4050                           'HRLOC.region_2',
4051                           'The second line of the assignment''s region',
4052                           'T',
4053                           'Y');
4054     --
4055     insert_database_item ('LOC_ADR_REGION_3',
4056                           'HRLOC.region_3',
4057                           'The third line of the assignment''s region',
4058                           'T',
4059                           'Y');
4060     --
4061     insert_database_item ('LOC_ADR_PHONE_1',
4062                           'HRLOC.telephone_number_1',
4063                           'The assignment''s first work telephone number',
4064                           'T',
4065                           'Y');
4066     --
4067     insert_database_item ('LOC_ADR_PHONE_2',
4068                           'HRLOC.telephone_number_2',
4069                           'The assignment''s second work telephone number',
4070                           'T',
4071                           'Y');
4072     --
4073     insert_database_item ('LOC_ADR_PHONE_3',
4074                           'HRLOC.telephone_number_3',
4075                           'The assignment''s third work telephone number',
4076                           'T',
4077                           'Y');
4078     --
4079     insert_database_item ('LOC_ADR_CITY',
4080                           'HRLOC.town_or_city',
4081                           'The town or city where the assignment works',
4082                           'T',
4083                           'Y');
4084     --
4085     insert_database_item ('LOC_ADR_COUNTRY',
4086                           'TER.territory_short_name',
4087                           'The country where the assignment works',
4088                           'T',
4089                           'Y');
4090     --
4091     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4092     --                                                                    +
4093     -- Route for US HR addresss : SEH_ASSIGN_HR_ADDRESS_US                +
4094     --                                                                    +
4095     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4096     --
4097     l_text := '/* The work address for the assignment (US legislation) */
4098         per_all_assignments_f                  ASSIGN
4099 ,       hr_locations                           HRLOC
4100 ,       hr_lookups                             HR1
4101 where	&B1 BETWEEN ASSIGN.effective_start_date
4102                  AND ASSIGN.effective_end_date
4103 and     ASSIGN.assignment_id                 = &B2
4104 and     HRLOC.location_id                    = ASSIGN.location_id
4105 and     HRLOC.style                          = ''US''
4106 and     HR1.lookup_code                   (+)= HRLOC.region_2
4107 and     HR1.application_id                (+)= 800
4108 and     HR1.lookup_type                   (+)= ''US_STATE''';
4109     --
4110     insert_route ('SEH_ASSIGN_HR_ADDRESS_US',
4111                   'The work address for the assignment (US legislation)',
4112                   l_text);
4113     --
4114     insert_route_context_usages (l_date_earned_context_id, 1);
4115     insert_route_context_usages (l_assign_id_context_id,   2);
4116     --
4117     insert_user_entity ('SEH_ASSIGN_HR_ADDRESS_US',
4118                  'The work address for the assignment (US legislation)',
4119                         'Y');
4120     --
4121     -- insert database items for the route defined above:
4122     --
4123     insert_database_item ('LOC_ADR_US_COUNTY',
4124                           'HRLOC.region_1',
4125                           'The assignment''s work county (US only)',
4126                           'T',
4127                           'Y');
4128     --
4129     insert_database_item ('LOC_ADR_US_STATE',
4130                           'HR1.meaning',
4131                           'The assignment''s work state (US only)',
4132                           'T',
4133                           'Y');
4134     --
4135     insert_database_item ('LOC_ADR_US_STATE_CODE',
4136                           'HRLOC.region_2',
4137                           'The assignment''s work state code (US only)',
4138                           'T',
4139                           'Y');
4140     --
4141     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4142     --                                                                    +
4143     -- Route for US home addresss : SEH_ASSIGN_ADDRESS_US                 +
4144     --                                                                    +
4145     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4146     --
4147     l_text := '/* The home address for the assignment (US legislation) */
4148         per_all_assignments_f                  ASSIGN
4149 ,	per_addresses                          ADDR
4150 ,       hr_lookups                             HR1
4151 where	&B1 BETWEEN ASSIGN.effective_start_date
4152                  AND ASSIGN.effective_end_date
4153 and     ASSIGN.assignment_id                 = &B2
4154 and	ADDR.person_id                    (+)= ASSIGN.person_id
4155 and	ADDR.primary_flag                 (+)= ''Y''
4156 and	ADDR.style                           = ''US''
4157 and     HR1.lookup_code                   (+)= ADDR.region_2
4158 and     HR1.application_id                (+)= 800
4159 and     HR1.lookup_type                   (+)= ''US_STATE''';
4160     --
4161     insert_route ('SEH_ASSIGN_ADDRESS_US',
4162                   'The home address for the assignment (US legislation)',
4163                   l_text);
4164     --
4165     insert_route_context_usages (l_date_earned_context_id, 1);
4166     insert_route_context_usages (l_assign_id_context_id,   2);
4167     --
4168     insert_user_entity ('SEH_ASSIGN_ADDRESS_US',
4169                  'The home address for the assignment (US legislation)',
4170                         'Y');
4171     --
4172     -- insert database items for the route defined above:
4173     --
4174     insert_database_item ('PER_ADR_US_COUNTY',
4175                           'ADDR.region_1',
4176                           'The assignment''s county (US only)',
4177                           'T',
4178                           'Y');
4179     --
4180     insert_database_item ('PER_ADR_US_STATE',
4181                           'HR1.meaning',
4182                           'The assignment''s state (US only)',
4183                           'T',
4184                           'Y');
4185     --
4186     insert_database_item ('PER_ADR_US_STATE_CODE',
4187                           'ADDR.region_2',
4188                           'The assignment''s state code (US only)',
4189                           'T',
4190                           'Y');
4191     --
4192     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4193     --                                                                    +
4194     -- Route for UK HR addresss : SEH_ASSIGN_HR_ADDRESS_UK                +
4195     --                                                                    +
4196     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4197     --
4198     l_text := '/* The work address for the assignment (GB legislation) */
4199         per_all_assignments_f                  ASSIGN
4200 ,       hr_locations                           HRLOC
4201 ,       hr_lookups                             HR1
4202 where	&B1 BETWEEN ASSIGN.effective_start_date
4203                  AND ASSIGN.effective_end_date
4204 and     ASSIGN.assignment_id                 = &B2
4205 and     HRLOC.location_id                    = ASSIGN.location_id
4206 and     HRLOC.style                          = ''GB''
4207 and     HR1.lookup_code                   (+)= HRLOC.region_1
4208 and     HR1.application_id                (+)= 800
4209 and     HR1.lookup_type                   (+)= ''GB_COUNTY''';
4210     --
4211     insert_route ('SEH_ASSIGN_HR_ADDRESS_UK',
4212                   'The work address for the assignment (GB legislation)',
4213                   l_text);
4214     --
4215     insert_route_context_usages (l_date_earned_context_id, 1);
4216     insert_route_context_usages (l_assign_id_context_id,   2);
4217     --
4218     insert_user_entity ('SEH_ASSIGN_HR_ADDRESS_UK',
4219                  'The work address for the assignment (GB legislation)',
4220                         'Y');
4221     --
4222     -- insert database items for the route defined above:
4223     --
4224     insert_database_item ('LOC_ADR_UK_COUNTY',
4225                           'HR1.meaning',
4226                           'The assignment''s work county (UK only)',
4227                           'T',
4228                           'Y');
4229     --
4230     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4231     --                                                                    +
4232     -- Route for UK home addresss : SEH_ASSIGN_ADDRESS_UK                 +
4233     --                                                                    +
4234     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4235     --
4236     l_text := '/* The home address for the assignment (GB legislation) */
4237         per_all_assignments_f                  ASSIGN
4238 ,	per_addresses                          ADDR
4239 ,       hr_lookups                             HR1
4240 where	&B1 BETWEEN ASSIGN.effective_start_date
4241                  AND ASSIGN.effective_end_date
4242 and     ASSIGN.assignment_id                 = &B2
4243 and	ADDR.person_id                    (+)= ASSIGN.person_id
4244 and	ADDR.primary_flag                 (+)= ''Y''
4245 and	ADDR.style                           = ''GB''
4246 and     HR1.lookup_code                   (+)= ADDR.region_1
4247 and     HR1.application_id                (+)= 800
4248 and     HR1.lookup_type                   (+)= ''GB_COUNTY''';
4249     --
4250     insert_route ('SEH_ASSIGN_ADDRESS_UK',
4251                   'The home address for the assignment (GB legislation)',
4252                   l_text);
4253     --
4254     insert_route_context_usages (l_date_earned_context_id, 1);
4255     insert_route_context_usages (l_assign_id_context_id,   2);
4256     --
4257     insert_user_entity ('SEH_ASSIGN_ADDRESS_UK',
4258                  'The home address for the assignment (GB legislation)',
4259                         'Y');
4260     --
4261     -- insert database items for the route defined above:
4262     --
4263     insert_database_item ('PER_ADR_UK_COUNTY',
4264                           'HR1.meaning',
4265                           'The assignment''s home county (UK only)',
4266                           'T',
4267                           'Y');
4268     --
4269     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4270     --                                                                    +
4271     --  Route for sysdate : SEH_SYSDATE                                   +
4272     --                                                                    +
4273     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4274     --
4275     l_text := 'dual';
4276     --
4277         insert_route ('SEH_SYSDATE',
4278                       'sysdate route',
4279                       l_text);
4280     --
4281     insert_user_entity ('SEH_SYSDATE',
4282                         'sysdate route');
4283     --
4284     -- insert database items for the route defined above:
4285     --
4286     --
4287     insert_database_item ('SYSDATE',
4288                           'sysdate',
4289                           'The system date',
4290                           'D',
4291                           'N');
4292     --
4293     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4294     --                                                                    +
4295     --  Route for session date : SEH_SESSION_DATE                         +
4296     --                                                                    +
4297     --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4298     --
4299     l_text := 'fnd_sessions where session_id = userenv(''sessionid'')';
4300     --
4301         insert_route ('SEH_SESSION_DATE',
4302                       'session date route',
4303                       l_text);
4304     --
4305     insert_user_entity ('SEH_SESSION_DATE',
4306                         'session date route',
4307                         'Y');
4308     --
4309     -- insert database items for the route defined above:
4310     --
4311     --
4312     insert_database_item ('SESSION_DATE',
4313                           'effective_date',
4314                           'The session date',
4315                           'D',
4316                           'N');
4317     --
4318     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4319     --                                                         +
4320     -- Route for target payroll action : TARGET_PAYROLL_ACTION +
4321     --                                                         +
4322     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4323     --
4324     l_text := '/* route for target_payroll_action */
4325        pay_payroll_actions PAC
4326 ,      pay_payroll_actions TARGET
4327 WHERE PAC.target_payroll_action_id = TARGET.payroll_action_id
4328 AND   PAC.payroll_action_id = &B1';
4329     --
4330     insert_route ('TARGET_PAYROLL_ACTION_ROUTE',
4331                   'Route for Target payroll action',
4332                   l_text);
4333     --
4334     insert_route_context_usages (l_payroll_action_id_context_id, 1);
4335     --
4336     insert_user_entity ('TARGET_PAYROLL_ACTION_ENTITY',
4337                         'Entity for payroll target action',
4338                         'Y');
4339     --
4340     -- insert database items for the route defined above:
4341     --
4342     insert_database_item ('ACTION_TYPE',
4343                           'TARGET.ACTION_TYPE',
4344                           'Actual Value of Action_Type',
4345                           'T',
4346                           'N');
4347     --
4348     --++++++++++++++++++++++++++++++++++++++++++++++++
4349     --                                               +
4350     -- Route for payroll arrears flag : PAY_PAYROLLS +
4351     --                                               +
4352     --++++++++++++++++++++++++++++++++++++++++++++++++
4353     --
4354     l_text := '/* route for pay_payrolls */
4355        pay_payrolls_f PAYROLL
4356 WHERE  &B1 BETWEEN PAYROLL.effective_start_date
4357                 AND PAYROLL.effective_end_date
4358 AND    PAYROLL.payroll_id = &B2';
4359     --
4360     insert_route ('PAY_PAYROLLS_ROUTE',
4361                   'Route for pay_payrolls',
4362                   l_text);
4363     --
4364     insert_route_context_usages (l_date_earned_context_id, 1);
4365     insert_route_context_usages (l_payroll_id_context_id, 2);
4366     --
4367     insert_user_entity ('PAY_PAYROLLS_ENTITY',
4368                         'Entity for pay_payrolls',
4369                         'Y');
4370     --
4371     -- insert database items for the route defined above:
4372     --
4373     insert_database_item ('PAYROLL_ARREARS_FLAG',
4374                           'PAYROLL.ARREARS_FLAG',
4375                           'Actual Value of Arrears_Flag',
4376                           'T',
4377                           'Y');
4378     --
4379     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4380     --                                                               +
4381     -- Route for assignment budget values : ASSIGNMENT_BUDGET_VALUES +
4382     --                                                               +
4383     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4384     --
4385     l_text := '/* route for assignment budget values */
4386         per_assignment_budget_values_f           BUDGET
4387 where   BUDGET.assignment_id                   = &B1
4388 and     BUDGET.unit                            = &U1
4389 and     &B2 between BUDGET.effective_start_date
4390 and     BUDGET.effective_end_date';
4391     --
4392     insert_route ('ASSIGNMENT_BUDGET_VALUES',
4393                   'Route for Assignment Budget Values',
4394                   l_text);
4395     --
4396     insert_route_context_usages (l_assign_id_context_id,   1);
4397     insert_route_context_usages (l_date_earned_context_id, 2);
4398     --
4399     insert_route_parameters ('UNIT', 'T', 1);
4400     --
4401     insert_user_entity ('ASSIGNMENT_FTE_BUDGET_VALUES',
4402                         'Entity for FTE Assignment Budget Values',
4403                         'Y');
4404     --
4405     select ff_route_parameters_s.currval
4406     into   l_route_parameters_id
4407     from   dual;
4408     --
4409     insert_route_parameter_values ( l_route_parameters_id,
4410                                     '''FTE''');
4411     --
4412     -- insert database items for the route defined above:
4413     --
4414     insert_database_item ('ASG_FTE_VALUE',
4415                           'BUDGET.VALUE',
4416                           'Full Time Equivalent Budget Actual Value',
4417                           'N',
4418                           'N');
4419     --
4420     insert_user_entity ('ASSIGNMENT_HEAD_BUDGET_VALUES',
4421                         'Entity for Assignment HEAD Budget Values',
4422                         'Y');
4423     --
4424     insert_route_parameter_values ( l_route_parameters_id,
4425                                     '''HEAD''');
4426     --
4427     -- insert database items for the route defined above:
4428     --
4429     insert_database_item ('ASG_HEAD_VALUE',
4430                           'BUDGET.VALUE',
4431                           'HEAD Budget Actual Value',
4432                           'N',
4433                           'N');
4434     --
4435     insert_user_entity ('ASSIGNMENT_MONEY_BUDGET_VALUES',
4436                         'Entity for Assignment Money Budget Values',
4437                         'Y');
4438     --
4439     insert_route_parameter_values ( l_route_parameters_id,
4440                                     '''MONEY''');
4441     --
4442     -- insert database items for the route defined above:
4443     --
4444     insert_database_item ('ASG_MONEY_VALUE',
4445                           'BUDGET.VALUE',
4446                           'Money Budget Actual Value',
4447                           'N',
4448                           'N');
4449     --
4450     insert_user_entity ('ASSIGNMENT_PFT_BUDGET_VALUES',
4451                         'Entity for Assignment PFT Budget Values',
4452                         'Y');
4453     --
4454     insert_route_parameter_values ( l_route_parameters_id,
4455                                     '''PFT''');
4456     --
4457     -- insert database items for the route defined above:
4458     --
4459     insert_database_item ('ASG_PFT_VALUE',
4460                           'BUDGET.VALUE',
4461                           'PFT Budget Actual Value',
4462                           'N',
4463                           'N');
4464     --
4465     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4466     --                                                               +
4467     -- Route for assignment full time conditions :                   +
4468     --                               ASSIGNMENT_FULL_TIME_CONDITIONS +
4469     --                                                               +
4470     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4471     --
4472     l_text := '/* route for assignment inherited normal working conditions */
4473    per_all_assignments_f    ASSIGN
4474 ,  hr_positions_f     POS
4475 ,  per_organization_units    ORG
4476 ,  per_business_groups    BUS
4477 where &B1 BETWEEN ASSIGN.effective_start_date
4478                AND ASSIGN.effective_end_date
4479 AND  &B1 BETWEEN POS.effective_start_date(+)
4480               AND POS.effective_end_date(+)
4481 and  ASSIGN.assignment_id   = &B2
4482 and  ASSIGN.position_id    = POS.position_id (+)
4483 and  ASSIGN.organization_id    = ORG.organization_id
4484 and  ASSIGN.business_group_id   = BUS.business_group_id
4485 and  ( POS.FREQUENCY is not null
4486  OR ORG.FREQUENCY is not null
4487  OR BUS.FREQUENCY is not null)';
4488     --
4489     insert_route ('ASSIGNMENT_FULL_TIME_CONDITIONS',
4490                   'Route for Assignment Full Time Conditions for pay_payrolls',
4491                   l_text);
4492     --
4493     insert_route_context_usages (l_date_earned_context_id, 1);
4494     insert_route_context_usages (l_assign_id_context_id,   2);
4495     --
4496     insert_user_entity ('ASSIGNMENT_FULL_TIME_CONDITIONS',
4497                         'Entity for Assignment Full Time Conditions',
4498                         'Y');
4499     --
4500     -- insert database items for the route defined above:
4501     --
4502     insert_database_item ('ASG_FULL_TIME_HOURS',
4503                           'nvl(POS.WORKING_HOURS,nvl(ORG.WORKING_HOURS,BUS.WORKING_HOURS))',
4504                           'Full Time Working Hours',
4505                           'N',
4506                           'N');
4507     --
4508     insert_database_item ('ASG_FULL_TIME_FREQ',
4509                           'nvl(POS.FREQUENCY,nvl(ORG.FREQUENCY,BUS.FREQUENCY))',
4510                           'Full Time Frequency',
4511                           'T',
4512                           'N');
4513     --
4514     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4515     --                                                               +
4516     -- Route for accrual plans :                                     +
4517     --                               ACCRUAL_PLAN_VALUES             +
4518     --                                                               +
4519     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4520     --
4521 l_text := '/* route for assignment budget values */
4522         pay_accrual_plans           PAP
4523 where   PAP.accrual_plan_id = &B1';
4524     --
4525     insert_route ('ACCRUAL_PLAN_VALUES',
4526                   'Route for Accrual Plans',
4527                   l_text);
4528     --
4529     insert_route_context_usages (l_accrual_plan_id_context_id, 1);
4530     --
4531     insert_user_entity ('ACP_NAME',
4532                         'Entity for Accrual PLans',
4533                         'Y');
4534     --
4535     -- insert database items for the route defined above:
4536     --
4537     insert_database_item ('ACP_NAME',
4538                           'PAP.ACCRUAL_PLAN_NAME',
4539                           'Name of accrual plan',
4540                           'T',
4541                           'N');
4542     --
4543     insert_database_item ('ACP_CATEGORY',
4544                           'PAP.ACCRUAL_CATEGORY',
4545                           'Accrual Category - Sick, Vacation etc',
4546                           'T',
4547                           'N');
4548     --
4549     insert_database_item ('ACP_START',
4550                           'PAP.ACCRUAL_START',
4551                           'Accrual Start - BOY, HD etc',
4552                           'T',
4553                           'Y');
4554     --
4555     insert_database_item ('ACP_UOM',
4556                           'PAP.ACCRUAL_UNITS_OF_MEASURE',
4557                           'Unit of measure used for accrual plan',
4558                           'T',
4559                           'N');
4560     --
4561     insert_database_item ('ACP_INELIGIBILITY_PERIOD_TYPE',
4562                           'PAP.INELIGIBLE_PERIOD_TYPE',
4563                           'Type of period before eligibility commences',
4564                           'T',
4565                           'Y');
4566     --
4567     insert_database_item ('ACP_INELIGIBILITY_PERIOD_LENGTH',
4568                           'PAP.INELIGIBLE_PERIOD_LENGTH',
4569                           'Number of periods before eligibility is attained',
4570                           'N',
4571                           'Y');
4572     --
4573     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4574     --                                                               +
4575     -- Route for accrual plan values :                               +
4576     --                               CARRIED_OVER_VALUES             +
4577     --                                                               +
4578     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4579     --
4580 l_text := '/* route for carry over values */
4581         pay_accrual_plans           PAP,
4582         pay_element_entries_f       PEE,
4583         pay_element_entry_values_f  PEV1,
4584         pay_element_entry_values_f  PEV2
4585 where   PAP.accrual_plan_id = &B1
4586 and     pap.co_date_input_value_id = pev1.input_value_id
4587 and     pap.co_input_value_id = pev2.input_value_id
4588 and     pev1.element_entry_id = pev2.element_entry_id
4589 and     pev1.element_entry_id = pee.element_entry_id
4590 and     pee.assignment_id = &B2
4591 and     pev1.screen_entry_value < fnd_date.date_to_canonical(&B3)
4592 and not exists (select 1
4593                 from pay_element_entry_values_f pev3,
4594                      pay_element_entries_f      pee1
4595                 where pee1.element_entry_id = pev3.element_entry_id
4596                 and pev3.element_entry_id != pev1.element_entry_id
4597                 and pev3.input_value_id = pev1.input_value_id
4598                 and pev3.screen_entry_value <= fnd_date.date_to_canonical(&B3)
4599                 and (  (pev3.screen_entry_value > pev1.screen_entry_value)
4600                     or (pev3.screen_entry_value = pev1.screen_entry_value)
4601                         and pee1.entry_type = ''S''))';
4602     --
4603     insert_route ('CARRIED_OVER_VALUES',
4604                   'Route for Accrual Plans',
4605                   l_text);
4606     --
4607     insert_route_context_usages (l_accrual_plan_id_context_id, 1);
4608     insert_route_context_usages (l_assign_id_context_id, 2);
4609     insert_route_context_usages (l_date_earned_context_id, 3);
4610     --
4611     insert_user_entity ('ACP_CARRIED_OVER_PTO',
4612                         'Entity for carried over values',
4613                         'Y');
4614     --
4615     -- insert database items for the route defined above:
4616     --
4617     insert_database_item ('ACP_CARRIED_OVER_PTO',
4618                           'PEV2.SCREEN_ENTRY_VALUE',
4619                           'Amount of PTO carried over',
4620                           'N',
4621                           'N');
4622     --
4623     insert_database_item ('ACP_CARRIED_OVER_DATE',
4624                           'PEV1.SCREEN_ENTRY_VALUE',
4625                           'Date on which CO is effective',
4626                           'N',
4627                           'N');
4628     --
4629     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4630     --                                                               +
4631     -- Route for accrual plan service dates :                        +
4632     --                               ACCRUAL_PLAN_SERVICE_DATES      +
4633     --                                                               +
4634     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4635     --
4636 l_text := '/* route for service dates used in accrual plan calculations */
4637          per_all_assignments_f asg,
4638          per_periods_of_service pps
4639   where  asg.assignment_id = &B1
4640   and    &B2 between asg.effective_start_date
4641               and     asg.effective_end_date
4642   and    asg.period_of_service_id = pps.period_of_service_id';
4643     --
4644     insert_route ('ACCRUAL_PLAN_SERVICE_DATES',
4645                   'Route for Accrual Plan Service Dates',
4646                   l_text);
4647     --
4648     insert_route_context_usages (l_assign_id_context_id, 1);
4649     insert_route_context_usages (l_date_earned_context_id, 2);
4650     --
4651     insert_user_entity ('ACP_SERVICE_DATES',
4652                         'Entity for accrual plan service dates',
4653                         'Y');
4654     --
4655     -- insert database items for the route defined above:
4656     --
4657     insert_database_item ('ACP_TERMINATION_DATE',
4658                           'PPS.ACTUAL_TERMINATION_DATE',
4659                           'Termination Date',
4660                           'D',
4661                           'Y');
4662     --
4663     insert_database_item ('ACP_SERVICE_START_DATE',
4664                           'PPS.DATE_START',
4665                           'Hire Date',
4666                           'D',
4667                           'N');
4668     --
4669     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4670     --                                                               +
4671     -- Route for accrual plan dates :                                +
4672     --                               ACCRUAL_PLAN_ENROLLMENT_DATES   +
4673     --                                                               +
4674     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4675     --
4676 l_text := '/* route for dates used in accrual plan calculations */
4677          pay_element_entries_f pee,
4678          pay_element_links_f pel,
4679          pay_element_types_f pet,
4680          pay_accrual_plans pap
4681   where  pee.element_link_id = pel.element_link_id
4682   and    pel.element_type_id = pet.element_type_id
4683   and    pet.element_type_id = pap.accrual_plan_element_type_id
4684   and    pee.entry_type =''E''
4685   and    pee.assignment_id = &B2
4686   and    pap.accrual_plan_id = &B1
4687   and    &B3 between pee.effective_start_date
4688               and     pee.effective_end_date
4689   and    &B3 between pel.effective_start_date
4690               and     pel.effective_end_date
4691   and    &B3 between pet.effective_start_date
4692               and     pet.effective_end_date';
4693     --
4694     insert_route ('ACCRUAL_PLAN_ENROLLMENT_DATES',
4695                   'Route for Accrual Plan Dates',
4696                   l_text);
4697     --
4698     insert_route_context_usages (l_accrual_plan_id_context_id, 1);
4699     insert_route_context_usages (l_assign_id_context_id, 2);
4700     insert_route_context_usages (l_date_earned_context_id, 3);
4701     --
4702     insert_user_entity ('ACCRUAL_PLAN_ENROLLMENT_DATES',
4703                         'Entity for Date of enrollment in a plan',
4704                         'Y');
4705     --
4706     -- insert database items for the route defined above:
4707     --
4708     insert_database_item ('ACP_ENROLLMENT_START_DATE',
4709                           'LEAST(PEE.EFFECTIVE_START_DATE)',
4710                           'Enrollment Date',
4711                           'D',
4712                           'N');
4713     --
4714     insert_database_item ('ACP_ENROLLMENT_END_DATE',
4715                           'GREATEST(PEE.EFFECTIVE_END_DATE)',
4716                           'Enrollment Date',
4717                           'D',
4718                           'N');
4719     --
4720     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4721     --                                                               +
4722     -- Route for accrual plan dates :                                +
4723     --                               ACCRUAL_PLAN_CONT_SERVICE_DATES +
4724     --                                                               +
4725     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4726     --
4727 l_text := '/* route for dates used in accrual plan calculations */
4728          pay_element_entries_f pee,
4729          pay_element_entry_values_f pev,
4730          pay_input_values_f piv,
4731          pay_accrual_plans pap,
4732          pay_element_links_f pel,
4733          pay_element_types_f pet
4734   where  pev.element_entry_id = pee.element_entry_id
4735   and    pee.element_link_id = pel.element_link_id
4736   and    pel.element_type_id = pet.element_type_id
4737   and    pap.accrual_plan_element_type_id = pet.element_type_id
4738   and    piv.input_value_id = pev.input_value_id
4739   and    piv.element_type_id = pet.element_type_id
4740   and    pee.entry_type =''E''
4741   and    pee.assignment_id = &B2
4742   and    pap.accrual_plan_id = &B1
4743   and    &B3 between pet.effective_start_date
4744               and     pet.effective_end_date
4745   and    &B3 between pel.effective_start_date
4746               and     pel.effective_end_date
4747   and    &B3 between pee.effective_start_date
4748               and     pee.effective_end_date
4749   and    &B3 between piv.effective_start_date
4750               and     piv.effective_end_date
4751   and    &B3 between pev.effective_start_date
4752               and     pev.effective_end_date
4753   and    piv.name = ''Continuous Service Date''';
4754     --
4755     insert_route ('ACCRUAL_PLAN_CONT_SERVICE_DATES',
4756                   'Route for Accrual Plan Dates',
4757                   l_text);
4758     --
4759     insert_route_context_usages (l_accrual_plan_id_context_id, 1);
4760     insert_route_context_usages (l_assign_id_context_id, 2);
4761     insert_route_context_usages (l_date_earned_context_id, 3);
4762     --
4763     insert_user_entity ('ACCRUAL_PLAN_CONT_SERVICE_DATES',
4764                         'Entity for CSD of person enrolled in plan',
4765                         'Y');
4766     --
4767     -- insert database items for the route defined above:
4768     --
4769     insert_database_item ('ACP_CONTINUOUS_SERVICE_DATE',
4770                           'FND_DATE.CANONICAL_TO_DATE(PEV.SCREEN_ENTRY_VALUE)',
4771                           'Continuous Service Date',
4772                           'D',
4773                           'Y');
4774     --
4775     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4776     --                                                               +
4777     -- Route for original entry attributes dates :                   +
4778     --                               ORIGINAL_ENTRY_ATTRIBUTES       +
4779     --                                                               +
4780     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4781     --
4782 l_text := '/* route for original entry attributes */
4783         pay_element_entries_f                    TARGET
4784 where   TARGET.element_entry_id                = &B1';
4785     --
4786     insert_route ('ORIGINAL_ENTRY_ATTRIBUTES',
4787                   'Route for Original Element Entry attributes',
4788                   l_text);
4789     --
4790     insert_route_context_usages (l_original_entry_id, 1);
4791     --
4792     insert_user_entity ('ORIGINAL_ENTRY_ATTRIBUTES',
4793                         'Entity for original entry details');
4794     --
4795     insert_database_item ('ENTRY_START_DATE',
4796                           'min(TARGET.effective_start_date)',
4797                           'start date of the original entry',
4798                           'D',
4799                           'N');
4800     --
4801     insert_database_item ('ENTRY_END_DATE',
4802                           'max(TARGET.effective_end_date)',
4803                           'end date of the original entry',
4804                           'D',
4805                           'N');
4806     --
4807     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4808     --                                                               +
4809     -- Route for  date earned dbitems :                              +
4810     --                               PAY_EARNED_PERIOD               +
4811     --                                                               +
4812     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4813     --
4814 l_text := '/* route pay earned period (core) */
4815             per_time_periods ptp,
4816             pay_payroll_actions ppa
4817 where ppa.date_earned BETWEEN ptp.START_DATE and ptp.END_DATE
4818   and ppa.payroll_action_id = &B1
4819   and ptp.payroll_id = ppa.payroll_id';
4820     --
4821     insert_route ('PAY_EARNED_PERIOD_CORE',
4822                   'Route for pay earned period',
4823                   l_text);
4824     --
4825     insert_route_context_usages (l_payroll_action_id_context_id, 1);
4826     --
4827     insert_user_entity ('PAY_PD_DETAILS_CORE',
4828                         'Entity for original entry details',
4829                         'Y');
4830     --
4831     insert_database_item ('PAY_EARNED_START_DATE',
4832                           'PTP.start_date',
4833                           'The start date of the earned period',
4834                           'D',
4835                           'N');
4836     --
4837     insert_database_item ('PAY_EARNED_END_DATE',
4838                           'PTP.end_date',
4839                           'The end date of the earned period',
4840                           'D',
4841                           'N');
4842     --
4843     insert_database_item ('PAY_EARNED_DIRECT_DEPOSIT_DATE',
4844                           'PTP.default_dd_date',
4845                           'The direct deposit date of the earned period',
4846                           'D',
4847                           'N');
4848     --
4849     insert_database_item ('PAY_EARNED_PAY_ADVICE_DATE',
4850                           'PTP.pay_advice_date',
4851                           'The pay advice date of the earned period',
4852                           'D',
4853                           'N');
4854     --
4855     insert_database_item ('PAY_EARNED_CUT_OFF_DATE',
4856                           'PTP.cut_off_date',
4857                           'The cut off date of the earned period',
4858                           'D',
4859                           'N');
4860     --
4861     insert_database_item ('PAY_EARNED_PERIOD_NAME',
4862                           'PTP.period_name',
4863                           'The period name for the earned period',
4864                           'T',
4865                           'N');
4866     --
4867     insert_database_item ('PAY_EARNED_PERIOD_NUMBER',
4868                           'PTP.period_num',
4869                           'The period number for the earned period',
4870                           'N',
4871                           'N');
4872     --
4873     insert_database_item ('PAY_EARNED_PERIOD_ID',
4874                           'PTP.time_period_id',
4875                           'The time period id for the earned period',
4876                           'N',
4877                           'N');
4878     --
4879     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4880     --                                                               +
4881     -- Route for gross up amount retrieval :                         +
4882     --                               GROSSUP_AMOUNT                  +
4883     --                                                               +
4884     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4885     --
4886 l_text := '/* route for gross up amount */
4887      pay_defined_balances pdb,
4888      pay_assignment_actions paa,
4889      pay_balance_types      pbt,
4890      pay_run_results        prr,
4891      pay_payroll_actions    ppa,
4892      per_business_groups    pbg
4893 where paa.assignment_action_id = &B1
4894 and   paa.payroll_action_id = ppa.payroll_action_id
4895 and   ppa.business_group_id = pbg.business_group_id
4896 and   pbt.balance_type_id = pdb.balance_type_id
4897 and   ((pbt.business_group_id = ppa.business_group_id)
4898        or (pbt.legislation_code = pbg.legislation_code
4899            and pbt.business_group_id is null)
4900        or (pbt.legislation_code is null
4901            and pbt.business_group_id is null)
4902       )
4903 and   pdb.grossup_allowed_flag = ''Y''
4904 and   paa.assignment_action_id = prr.assignment_action_id
4905 and   prr.source_id = &B2
4906 and   prr.source_type = ''E''
4907 and   not exists (select ''''
4908                     from pay_grossup_bal_exclusions pgb
4909                    where prr.source_id = pgb.source_id
4910                      and pgb.balance_type_id = pbt.balance_type_id
4911                      and pgb.source_type = ''EE''
4912                   )
4913 and   not exists (select ''''
4914                     from pay_grossup_bal_exclusions pgb
4915                    where prr.element_type_id = pgb.source_id
4916                      and pgb.balance_type_id = pbt.balance_type_id
4917                      and pgb.source_type = ''ET''
4918                   )';
4919     --
4920     insert_route ('GROSSUP_AMOUNT',
4921                   'Route for gross up amount',
4922                   l_text);
4923     --
4924     insert_route_context_usages (l_assign_action_id_context_id,   1);
4925     insert_route_context_usages (l_element_entry_id, 2);
4926     --
4927     insert_user_entity ('GROSSUP_AMOUNT',
4928                         'Entity for gross up');
4929     --
4930     insert_database_item ('GROSSUP_AMOUNT',
4931                           'nvl(sum(pay_balance_pkg.get_value(pdb.defined_balance_id,paa.assignment_action_id)), 0)',
4932                           'Gross up amount to be added to the Net',
4933                           'N',
4934                           'N');
4935     --
4936     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4937     --                                                               +
4938     -- Route for  assignment contracts :                             +
4939     --                               ASSIGNMENT_CONTRACTS_ROUTE      +
4940     --                                                               +
4941     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4942     --
4943 l_text := '/* route for contracts */
4944      per_contracts_f           target,
4945      per_all_assignments_f     asg
4946   where asg.assignment_id   = &B1
4947   and   target.contract_id (+) = asg.contract_id
4948   and   &B2 between asg.effective_start_date and asg.effective_end_date
4949   and  &B2 between target.effective_start_date and target.effective_end_date';
4950     --
4951     insert_route ('ASSIGNMENT_CONTRACTS_ROUTE',
4952                   'Route for Assignment Contracts',
4953                   l_text);
4954     --
4955     insert_route_context_usages (l_assign_id_context_id, 1);
4956     insert_route_context_usages (l_date_earned_context_id, 2);
4957     --
4958     insert_user_entity ('insert_route_context_usages',
4959                         'Entity for Assignment Contracts',
4960                         'Y');
4961     --
4962     insert_database_item ('CTR_TYPE',
4963                           'target.type',
4964                           'Contract Type (code)',
4965                           'T',
4966                           'Y');
4967     --
4968     insert_database_item ('CTR_STATUS',
4969                           'target.status',
4970                           'Contract Status (code)',
4971                           'T',
4972                           'Y');
4973     --
4974     insert_database_item ('CTR_TYPE_MEANING',
4975                           'hr_general.decode_lookup(''CONTRACT_TYPE'',target.type)',
4976                           'Contract Type (meaning)',
4977                           'T',
4978                           'Y');
4979     --
4980     insert_database_item ('CTR_STATUS_MEANING',
4981                           'hr_general.decode_lookup(''CONTRACT_STATUS'',target.status)',
4982                           'Contract Status (meaning)',
4983                           'T',
4984                           'Y');
4985     --
4986     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4987     --                                                               +
4988     -- Route for  time periods :                                     +
4989     --                               PER_TIME_PERIODS_INFO           +
4990     --                                                               +
4991     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4992     --
4993 l_text := '/* PER_TIME_PERIODS_INFO */
4994 pay_payroll_actions paction,
4995 per_time_periods target
4996 where   paction.payroll_action_id = &B1
4997 and     target.payroll_id = paction.payroll_id
4998 and     to_char(target.regular_payment_date,''YYYY'') = to_char(paction.effective_date,''YYYY'')';
4999     --
5000     insert_route ('PER_TIME_PERIODS_INFO',
5001                   'PER_TIME_PERIODS_INFO based on payroll_action_id and effective_date',
5002                   l_text);
5003     --
5004     insert_route_context_usages (l_payroll_action_id_context_id, 1);
5005     --
5006     insert_user_entity ('PER_TIME_PERIOD_DETAILS',
5007                         'PER_TIME_PERIOD_DETAILS',
5008                         'Y');
5009     --
5010     insert_database_item ('PAY_NO_OF_SCHEDULED_PAYMENTS',
5011                           'Count(target.REGULAR_PAYMENT_DATE)',
5012                           'Number of Scheduled Payments Per Year',
5013                           'N',
5014                           'Y');
5015     --
5016     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5017     --                                                               +
5018     -- Route for  element types attributes periods :                 +
5019     --                               ELEMENT_TYPE_ATTRIBUTES         +
5020     --                                                               +
5021     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5022     --
5023 l_text := '/* route for element type attributes */
5024         pay_element_types_f                    TARGET
5025 where   TARGET.element_type_id                = &B1
5026 and     &B2
5027         BETWEEN TARGET.effective_start_date and TARGET.effective_end_date ';
5028     --
5029     insert_route ('ELEMENT_TYPE_ATTRIBUTES',
5030                   'Route for Element Type attributes',
5031                   l_text);
5032     --
5033     insert_route_context_usages (l_element_type_id, 1);
5034     insert_route_context_usages (l_date_earned_context_id, 2);
5035     --
5036     insert_user_entity ('ELEMENT_TYPE_ATTRIBUTES',
5037                         'Entity for element type details');
5038     --
5039     insert_database_item ('ELEMENT_NAME',
5040                           'TARGET.element_name',
5041                           'element name of the element being processed',
5042                           'T',
5043                           'N');
5044     --
5045     insert_database_item ('CURRENT_ELEMENT_TYPE_ID',
5046                           'TARGET.element_type_id',
5047                           'The element type id of the element being processed',
5048                           'N',
5049                           'N');
5050     --
5051     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5052     --                                                               +
5053     -- Route for accrual plan dates :                                +
5054     --                               ACCRUAL_PLAN_PAYROLL_PROCESS_1  +
5055     --                                                               +
5056     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5057     --
5058 l_text := '/* route for dates used in accrual plan calculations */
5059          pay_element_entries_f pee,
5060          pay_accrual_plans pap,
5061          pay_element_links_f pel
5062   where  pap.accrual_plan_element_type_id = pel.element_type_id
5063   and    pel.element_link_id = pee.element_link_id
5064   and    pee.element_entry_id = &B1
5065   and    &B2 between pee.effective_start_date
5066               and     pee.effective_end_date';
5067     --
5068     insert_route ('ACCRUAL_PLAN_PAYROLL_PROCESS_1',
5069                   'Route for Accrual Plan ID',
5070                   l_text);
5071     --
5072     insert_route_context_usages (l_element_entry_id, 1);
5073     insert_route_context_usages (l_date_earned_context_id, 2);
5074     --
5075     insert_user_entity ('ACCRUAL_PLAN_PAYROLL_PROCESS_1',
5076                         'Entity for ID of a plan',
5077                         'Y');
5078     --
5079     insert_database_item ('PTO_ACCRUAL_PLAN_ID',
5080                           'DISTINCT PAP.ACCRUAL_PLAN_ID',
5081                           'Accrual Plan ID',
5082                           'N',
5083                           'N');
5084     --
5085     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5086     --                                                               +
5087     -- Route for accrual plan dates :                                +
5088     --                               ACCRUAL_PLAN_PAYROLL_PROCESS_2  +
5089     --                                                               +
5090     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5091     --
5092 l_text := '
5093          pay_assignment_actions paa,
5094          pay_payroll_actions ppa
5095   where  ppa.payroll_action_id = paa.payroll_action_id
5096   and    paa.assignment_action_id = &B1';
5097     --
5098     insert_route ('ACCRUAL_PLAN_PAYROLL_PROCESS_2',
5099                   'Route for Accrual Plan Dates',
5100                   l_text);
5101     --
5102     insert_route_context_usages (l_assign_action_id_context_id,   1);
5103     --
5104     insert_user_entity ('ACCRUAL_PLAN_PAYROLL_PROCESS_2',
5105                         'Entity for start and end calculation dates for pto',
5106                         'Y');
5107     --
5108     insert_database_item ('PTO_DATE_PAID_CALCULATION_DATE',
5109                           'PPA.EFFECTIVE_DATE',
5110                           'Date Paid for current period',
5111                           'D',
5112                           'Y');
5113     --
5114     insert_database_item ('PTO_DATE_EARNED_CALCULATION_DATE',
5115                           'PPA.DATE_EARNED',
5116                           'Date Earned for current period',
5117                           'D',
5118                           'Y');
5119     --
5120     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5121     --                                                               +
5122     -- Route for accrual plan dates :                                +
5123     --                               ACCRUAL_PLAN_PAYROLL_PROCESS_3  +
5124     --                                                               +
5125     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5126     --
5127 l_text := '/* route for dates used in accrual plan calculations */
5128          pay_assignment_actions paa,
5129          pay_assignment_actions paa2,
5130          pay_payroll_actions ppa,
5131          pay_run_results prr
5132   where  paa.assignment_action_id = &B1
5133   and    paa2.assignment_id = paa.assignment_id
5134   and    paa2.payroll_action_id = ppa.payroll_action_id
5135   and    paa2.action_sequence < paa.action_sequence
5136   and    paa2.action_status = ''C''
5137   and    paa2.assignment_action_id = prr.assignment_action_id
5138   and    prr.element_type_id = (SELECT pap.balance_element_type_id
5139                                 FROM   pay_accrual_plans pap
5140                                 WHERE  pap.accrual_plan_element_type_id = &B2)
5141   and    ppa.action_type in (''R'',''Q'',''V'',''B'')';
5142     --
5143     insert_route ('ACCRUAL_PLAN_PAYROLL_PROCESS_3',
5144                   'Route for Accrual Plan Dates',
5145                   l_text);
5146     --
5147     insert_route_context_usages (l_assign_action_id_context_id, 1);
5148     insert_route_context_usages (l_element_type_id, 2);
5149     --
5150     insert_user_entity ('ACCRUAL_PLAN_PAYROLL_PROCESS_3',
5151                         'Entity for start and end calculation dates for pto',
5152                         'Y');
5153     --
5154     insert_database_item ('PTO_DATE_PAID_START_DATE',
5155                           'MAX(PPA.EFFECTIVE_DATE) + 1',
5156                           'Date Paid for previous period',
5157                           'D',
5158                           'Y');
5159     --
5160     insert_database_item ('PTO_DATE_EARNED_START_DATE',
5161                           'MAX(PPA.DATE_EARNED) + 1',
5162                           'Date Earned for previous period',
5163                           'D',
5164                           'Y');
5165     --
5166     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5167     --                                                               +
5168     -- Route for Assignment Organizations:                           +
5169     --                               ASG_ORG_ROUTE                   +
5170     --                                                               +
5171     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5172 l_text := '/* Route for Assignment Organizations */
5173            hr_all_organization_units target
5174           ,hr_locations loc
5175           ,hr_lookups org_type
5176           ,hr_lookups int_ext
5177           ,per_all_assignments_f ASSIGN
5178   where target.location_id=loc.location_id(+)
5179   and  target.type=org_type.lookup_code(+)
5180   and (org_type.lookup_type=''ORG_TYPE''
5181        or target.type is null)
5182   and  target.internal_external_flag=int_ext.lookup_code(+)
5183   and (int_ext.lookup_type=''INTL_EXTL''
5184        or target.internal_external_flag is null)
5185   and &B1 between ASSIGN.effective_start_date
5186       and ASSIGN.effective_end_date
5187   and ASSIGN.assignment_id = &B2
5188   and ASSIGN.organization_id=target.organization_id';
5189     --
5190     insert_route ('ASG_ORG_ROUTE',
5191                   'Route for Assignment Organizations',
5192                   l_text);
5193     --
5194     insert_route_context_usages (l_date_earned_context_id, 1);
5195     insert_route_context_usages (l_assign_id_context_id,   2);
5196     --
5197     insert_user_entity ('ASG_ORG',
5198                         'The Assignment Organization User Entity',
5199                         'Y');
5200     --
5201     insert_database_item ('ASG_ORG_LOCATION',
5202                           'loc.location_code',
5203                           'Assignment Organization Location',
5204                           'T',
5205                           'Y');
5206     --
5207     insert_database_item ('ASG_ORG_TYPE',
5208                           'org_type.meaning',
5209                           'Assignment Organization Type',
5210                           'T',
5211                           'Y');
5212     --
5213     insert_database_item ('ASG_ORG_INT_EXT',
5214                           'int_ext.meaning',
5215                           'Assignment Organization Internal External Flag',
5216                           'T',
5217                           'Y');
5218     --
5219     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5220     --                                                               +
5221     -- Route for Assignment Organizations:                           +
5222     --                               ASG_POS_ROUTE                   +
5223     --                                                               +
5224     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5225     --
5226 l_text := '/* Route for Assignment Positions */
5227            hr_all_positions_f target
5228           ,hr_locations loc
5229           ,hr_lookups frequency
5230           ,hr_lookups probation
5231           ,per_all_assignments_f ASSIGN
5232   where target.location_id=loc.location_id(+)
5233   and  target.frequency=frequency.lookup_code(+)
5234   and (frequency.lookup_type=''FREQUENCY''
5235        or target.frequency is null)
5236   and  target.probation_period_unit_cd=probation.lookup_code(+)
5237   and (probation.lookup_type=''QUALIFYING_UNITS''
5238        or target.probation_period_unit_cd is null)
5239   and &B1 between ASSIGN.effective_start_date
5240       and ASSIGN.effective_end_date
5241   and ASSIGN.assignment_id = &B2
5242   and ASSIGN.position_id=target.position_id
5243   and &B1 between target.effective_start_date
5244       and target.effective_end_date';
5245     --
5246     insert_route ('ASG_POS_ROUTE',
5247                   'Route for Assignment Positions',
5248                   l_text);
5249     --
5250     insert_route_context_usages (l_date_earned_context_id, 1);
5251     insert_route_context_usages (l_assign_id_context_id,   2);
5252     --
5253     insert_user_entity ('ASG_POS',
5254                         'The Assignment Position User Entity',
5255                         'Y');
5256     --
5257     insert_database_item ('ASG_POS_LOCATION',
5258                           'loc.location_code',
5259                           'Assignment Position Location',
5260                           'T',
5261                           'Y');
5262     --
5263     insert_database_item ('ASG_POS_FREQUENCY',
5264                           'frequency.meaning',
5265                           'Assignment Position Frequency',
5266                           'T',
5267                           'Y');
5268     --
5269     insert_database_item ('ASG_POS_WORKING_HOURS',
5270                           'target.working_hours',
5271                           'Assignment Position Working Hours',
5272                           'N',
5273                           'Y');
5274     --
5275     insert_database_item ('ASG_POS_PROBATION_PERIOD',
5276                           'target.probation_period',
5277                           'Assignment Position Probation Period',
5278                           'T',
5279                           'Y');
5280     --
5281     insert_database_item ('ASG_POS_PROBATION_PERIOD_UNITS',
5282                           'period.meaning',
5283                           'Assignment Position Probation Period Units',
5284                           'T',
5285                           'Y');
5286     --
5287     insert_database_item ('ASG_POS_FTE',
5288                           'target.fte',
5289                           'Assignment Position FTE',
5290                           'T',
5291                           'Y');
5292     --
5293     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5294     --                                                               +
5295     -- Route for Assignment Details                                  +
5296     --                               SEH_ASSIGNMENT_DETAILS          +
5297     --                                                               +
5298     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5299     --
5300     l_text := '/* Assignment Details */
5301         per_all_assignments_f     ASSIGN
5302         WHERE &B1 BETWEEN ASSIGN.effective_start_date AND
5303                            ASSIGN.effective_end_date
5304         AND &B2 = ASSIGN.ASSIGNMENT_ID';
5305 
5306     insert_route ('SEH_ASSIGNMENT_DETAILS',
5307                   'Assignment Details',
5308                   l_text);
5309     --
5310     insert_route_context_usages (l_date_earned_context_id, 1);
5311     insert_route_context_usages (l_assign_id_context_id,   2);
5312     --
5313     insert_user_entity ('SEH_ASSIGNMENT_DETAILS',
5314                         'Assignment Details',
5315                         'Y');
5316     --
5317     insert_database_item ('ASG_WORK_AT_HOME',
5318                           'ASSIGN.work_at_home',
5319                           'The work at home code for an assignment',
5320                           'T',
5321                           'Y');
5322     --
5323     --
5324     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5325     --                                                               +
5326     -- Route for HRI Assignment Details                              +
5327     --                               HRI_ASG_DETAILS                 +
5328     --                                                               +
5329     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5330     --
5331     l_text := '/* HRI Assignment Details */
5332         per_all_assignments_f     asg
5333         WHERE &B1 BETWEEN asg.effective_start_date AND asg.effective_end_date
5334         AND &B2 = asg.assignment_id';
5335 
5336     insert_route ('HRI_ASG_DETAILS',
5337                   'HRI Assignment only',
5338                   l_text);
5339     --
5340     insert_route_context_usages (l_date_earned_context_id, 1);
5341     insert_route_context_usages (l_assign_id_context_id,   2);
5342     --
5343     insert_user_entity ('HRI_ASG_DETAILS',
5344                         'HRI Assignment Details',
5345                         'Y');
5346     --
5347     insert_database_item ('HRI_ASG_PRIMARY_CODE',
5348                           'asg.primary_flag',
5349                           'Primary Assignment Code',
5350                           'T',
5351                           'N');
5352     insert_database_item ('HRI_ASG_EMPLOYMENT_CATEGORY_CODE',
5353                           'asg.employment_category',
5354                           'Employment Category Code',
5355                           'T',
5356                           'Y');
5357     insert_database_item ('HRI_ASG_FREQ_CODE',
5358                           'asg.frequency',
5359                           'Assignment Working Hours Frequency Code',
5360                           'T',
5361                           'Y');
5362     insert_database_item ('HRI_ASG_HOURS',
5363                           'asg.normal_hours',
5364                           'Assignment Normal Working Hours',
5365                           'N',
5366                           'Y');
5367 
5368     --
5369     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5370     --                                                               +
5371     -- Route for HRI Assignment Details                              +
5372     --                               HRI_ASG_INHRTD_WRK_CNDTNS       +
5373     --                                                               +
5374     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5375     l_text := '/* HRI Assignment Inherited Working Conditions */
5376         per_all_assignments_f          asg
5377         ,hr_all_positions_f            hpf
5378         ,hr_organization_information   oi_org
5379         ,hr_organization_information   oi_bus
5380         WHERE &B1 BETWEEN asg.effective_start_date
5381               AND asg.effective_end_date
5382         AND   &B1 BETWEEN hpf.effective_start_date(+)
5383               AND hpf.effective_end_date(+)
5384         AND   asg.assignment_id   = &B2
5385         AND   asg.position_id    = hpf.position_id (+)
5386         AND   asg.organization_id    = oi_org.organization_id (+)
5387         AND   oi_org.org_information_context (+) = ''Work Day Information''
5388         AND   asg.business_group_id   = oi_bus.organization_id (+)
5389         AND   oi_bus.org_information_context (+) = ''Work Day Information''
5390         AND  ( hpf.frequency is not null
5391               OR oi_org.org_information4 is not null
5392               OR oi_bus.org_information4 is not null)';
5393 
5394     insert_route ('HRI_ASG_INHRTD_WRK_CNDTNS',
5395                   'HRI Assignment Inherited Working Conditions',
5396                   l_text);
5397     --
5398     insert_route_context_usages (l_date_earned_context_id, 1);
5399     insert_route_context_usages (l_assign_id_context_id,   2);
5400     --
5401     insert_user_entity ('HRI_ASG_INHRTD_WRK_CNDTNS',
5402                         'HRI Assignment Inherited Working Conditions',
5403                         'Y');
5404     --
5405     insert_database_item ('HRI_ASG_FULL_TIME_HOURS',
5406                           'NVL(hpf.working_hours,NVL(oi_org.org_information3,oi_bus.org_information3))',
5407                           'Full Time Working Hours',
5408                           'N',
5409                           'Y');
5410     insert_database_item ('HRI_ASG_FULL_TIME_FREQ',
5411                           'NVL(hpf.frequency,NVL(oi_org.org_information4,oi_bus.org_information4))',
5412                           'Full Time Frequency',
5413                           'T',
5414                           'N');
5415 
5416     --
5417     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5418     --                                                               +
5419     -- Route for LAST_REG_PAYMENT_PERIOD                             +
5420     --                               LAST_REGULAR_PAYMENT_PERIOD     +
5421     --                                                               +
5422     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5423     l_text := '/* LAST_REG_PAYMENT_PERIOD */
5424         pay_payroll_actions paction,
5425         per_time_periods    target
5426         where paction.payroll_action_id = &B1
5427         and   target.payroll_id = paction.payroll_id
5428         and to_char(target.regular_payment_date,''YYYY'')=to_char(paction.effective_date,''YYYY'')
5429         and   target.regular_payment_date <= paction.effective_date';
5430     --
5431     insert_route ('LAST_REGULAR_PAYMENT_PERIOD',
5432                   'Last Regular Payment Period',
5433                   l_text);
5434     --
5435     insert_route_context_usages (l_payroll_action_id_context_id, 1);
5436     --
5437     insert_user_entity ('LAST_REGULAR_PAYMENT_PERIOD',
5438                         'Last Regular Payment Period',
5439                         'Y');
5440     --
5441     insert_database_item ('LAST_REG_PAYMENT_PERIOD',
5442                           'nvl(max(period_num), 1)',
5443                           'Last Regular Payment Period',
5444                           'N',
5445                           'N');
5446     --
5447     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5448     --                                                               +
5449     -- Route for LAST_REG_PAYMENT_PERIOD_START_DATE                  +
5450     --                      LAST_REG_PAYMENT_PERIOD_START_DATE       +
5451     --                                                               +
5452     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5453     l_text := '/* LAST_REG_PAYMENT_PERIOD_START_DATE */
5454       pay_payroll_actions paction,
5455       per_time_periods target
5456       where paction.payroll_action_id = &B1
5457       and   target.payroll_id = paction.payroll_id
5458       and  (target.regular_payment_date <= paction.effective_date
5459       or    target.regular_payment_date =
5460                     (select min (tp.regular_payment_date)
5461                      from pay_payroll_actions ppa,
5462                           per_time_periods tp
5463                      where ppa.payroll_action_id = &B1
5464                      and   tp.payroll_id         = ppa.payroll_id
5465                      and   to_char(tp.regular_payment_date,''YYYY'') =
5466                            to_char(ppa.effective_date,''YYYY'')))';
5467     --
5468     insert_route ('LAST_REG_PAYMENT_PERIOD_START_DATE',
5469                   'Last Regular Payment Period Start Date',
5470                   l_text);
5471     --
5472     insert_route_context_usages (l_payroll_action_id_context_id, 1);
5473     --
5474     insert_user_entity ('LAST_REG_PAYMENT_PERIOD_START_DATE',
5475                         'Last Regular Payment Period Start Date',
5476                         'Y');
5477     --
5478     insert_database_item ('LAST_REG_PAYMENT_PERIOD_START_DATE',
5479                           'Max(target.START_DATE)',
5480                           'Last Regular Payment Period Start Date',
5481                           'D',
5482                           'N');
5483 
5484     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5485     --                                                               +
5486     -- Route for  ASSIGNMENT_ACTION_DATES_ROUTE                      +
5487     --                                                               +
5488     --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5489     l_text := '/* ASSIGNMENT_ACTION_DATES_ROUTE */
5490              pay_assignment_actions target,
5491              pay_assignment_actions paa
5492   	where target.assignment_action_id = paa.source_action_id
5493 	  and paa.assignment_action_id = &B1';
5494 
5495     --
5496     insert_route ('ASSIGNMENT_ACTION_DATES_ROUTE',
5497                   'Assignment Action Start Date',
5498                   l_text);
5499     --
5500     insert_route_context_usages (l_assign_action_id_context_id, 1);
5501     --
5502     insert_user_entity ('ASSIGNMENT_ACTION_DATES_UENT',
5503                         'Entity for the assignment Action Dates',
5504                         'Y');
5505     --
5506     insert_database_item ('ASSIGNMENT_ACTION_START_DATE',
5507                           'target.START_DATE',
5508                           'Assignment Action Start Date',
5509                           'D',
5510                           'Y');
5511 
5512     insert_database_item ('ASSIGNMENT_ACTION_END_DATE',
5513                           'target.END_DATE',
5514                           'Assignment Action End Date',
5515                           'D',
5516                           'Y');
5517 
5518 
5519 --
5520 end insert_routes_db_items;
5521 --
5522 PROCEDURE insert_functions is
5523 l_text                          long;
5524 l_function_id                   number;
5525 --
5526    procedure load_function(p_name       varchar2
5527                           ,p_type       varchar2
5528                           ,p_definition varchar2
5529                           ,p_description varchar2
5530                           ,p_function_id out nocopy number
5531                           ,p_alias      varchar2 default null) is
5532       l_function_id number;
5533    begin
5534       --
5535       select ff_functions_s.nextval
5536       into l_function_id
5537       from dual;
5538       --
5539       insert into ff_functions
5540       (FUNCTION_ID
5541       ,BUSINESS_GROUP_ID
5542       ,LEGISLATION_CODE
5543       ,CLASS
5544       ,NAME
5545       ,ALIAS_NAME
5546       ,DATA_TYPE
5547       ,DEFINITION
5548       ,LAST_UPDATE_DATE
5549       ,LAST_UPDATED_BY
5550       ,LAST_UPDATE_LOGIN
5551       ,CREATED_BY
5552       ,CREATION_DATE
5553       ,DESCRIPTION
5554       )
5555       values(l_function_id
5556       ,      null
5557       ,      null
5558       ,      'E'
5559       ,      p_name
5560       ,      p_alias
5561       ,      p_type
5562       ,      p_definition
5563       ,      sysdate
5564       ,      -1
5565       ,      -1
5566       ,      -1
5567       ,      sysdate
5568       ,      p_description
5569       );
5570       --
5571       p_function_id := l_function_id;
5572       --
5573    end;
5574    --
5575    procedure load_parameter(p_sequence_no number
5576                            ,p_function_id number
5577                            ,p_data_type   varchar2
5578                            ,p_name        varchar2
5579                             ) is
5580 
5581    begin
5582      --
5583      insert into ff_function_parameters
5584      (FUNCTION_ID
5585      ,SEQUENCE_NUMBER
5586      ,CLASS
5587      ,CONTINUING_PARAMETER
5588      ,DATA_TYPE
5589      ,NAME
5590      ,OPTIONAL
5591       )
5592      values
5593      (p_function_id
5594      ,p_sequence_no
5595      ,'I'
5596      ,'N'
5597      ,p_data_type
5598      ,p_name
5599      ,'N'
5600      );
5601      --
5602    end;
5603    --
5604    procedure load_context_usage(p_sequence_no  number
5605                                ,p_function_id  number
5606                                ,p_context_name varchar2
5607                                 ) is
5608      l_context_id number;
5609    begin
5610      --
5611      select context_id
5612      into l_context_id
5613      from ff_contexts
5614      where context_name = p_context_name;
5615      --
5616      insert into ff_function_context_usages
5617      (FUNCTION_ID
5618      ,SEQUENCE_NUMBER
5619      ,CONTEXT_ID
5620      )
5621      values
5622      (p_function_id
5623 	     ,p_sequence_no
5624      ,l_context_id
5625      );
5626      --
5627    end;
5628    --
5629 begin
5630 --
5631      --
5632      --  PLSQL mod function
5633      --
5634      hr_utility.set_location ('hrstrdbi.insert_functions' , 10);
5635      load_function('MOD',
5636                    'N',
5637                    'MOD',
5638                    'Function to implement plsql mod function',
5639                    l_function_id,
5640                    'MODULUS'
5641                    );
5642      --
5643      hr_utility.set_location ('hrstrdbi.insert_functions' , 11);
5644      load_parameter(1,
5645                     l_function_id,
5646                     'N', 'P_VAL1');
5647      --
5648      hr_utility.set_location ('hrstrdbi.insert_functions' , 12);
5649      load_parameter(2,
5650                     l_function_id,
5651                     'N', 'P_VAL2');
5652      --
5653      -- The following function GET_HOURS_WORKED is used by report HRUTLHRS.
5654      --
5655      hr_utility.set_location ('hrstrdbi.insert_functions' , 10);
5656      load_function('GET_HOURS_WORKED',
5657 		   'N',
5658 		   'hrfastanswers.get_hours_worked',
5659 		   'Function to return the number of overtime hours worked',
5660 		   l_function_id
5661 		   );
5662      --
5663      hr_utility.set_location ('hrstrdbi.insert_functions' , 11);
5664      load_parameter(1,
5665 		    l_function_id,
5666 		    'N', 'P_MULTIPLE');
5667      --
5668      hr_utility.set_location ('hrstrdbi.insert_functions', 12);
5669      load_context_usage(1,
5670 			l_function_id,
5671 			'ASSIGNMENT_ID');
5672      --
5673      hr_utility.set_location ('hrstrdbi.insert_functions', 13);
5674      load_context_usage(2,
5675 			l_function_id,
5676 			'DATE_EARNED');
5677      --
5678      hr_utility.set_location ('hrstrdbi.insert_functions', 14);
5679      --
5680      --  CURRENCY_CONVERT_AMOUNT function
5681      --
5682      load_function('CURRENCY_CONVERT_AMOUNT',
5683                    'N',
5684                    'HR_currency_pkg.convert_amount',
5685                    null,
5686                    l_function_id
5687                    );
5688      --
5689      load_parameter(1,
5690                     l_function_id,
5691                     'T', 'from_currency');
5692      --
5693      load_parameter(2,
5694                     l_function_id,
5695                     'T', 'to_currency');
5696      --
5697      load_parameter(3,
5698                     l_function_id,
5699                     'D', 'conversion_date');
5700      --
5701      load_parameter(4,
5702                     l_function_id,
5703                     'N', 'amount');
5704      --
5705      load_parameter(5,
5706                     l_function_id,
5707                     'T', 'rate_type');
5708      --
5709      hr_utility.set_location ('hrstrdbi.insert_functions', 15);
5710      --
5711      --  GET_RATE_TYPE function
5712      --
5713      load_function('GET_RATE_TYPE',
5714                    'N',
5715                    'HR_currency_pkg.get_rate_type',
5716                    null,
5717                    l_function_id
5718                    );
5719      --
5720      load_parameter(1,
5721                     l_function_id,
5722                     'N', 'business_group_id');
5723      --
5724      load_parameter(2,
5725                     l_function_id,
5726                     'D', 'conversion_date');
5727      --
5728      load_parameter(3,
5729                     l_function_id,
5730                     'T', 'processing_type');
5731      --
5732      hr_utility.set_location ('hrstrdbi.insert_functions', 16);
5733      --
5734      --  CHECK_RATE_TYPE function
5735      --
5736      load_function('CHECK_RATE_TYPE',
5737                    'N',
5738                    'HR_currency_pkg.check_rate_type',
5739                    null,
5740                    l_function_id
5741                    );
5742      --
5743      load_parameter(1,
5744                     l_function_id,
5745                     'T', 'rate_type');
5746      --
5747      hr_utility.set_location ('hrstrdbi.insert_functions', 17);
5748      --
5749      --  accrual functions
5750      --
5751 	/********* CALCULATE_PAYROLL_PERIODS ***********************/
5752 	--
5753 	load_function('CALCULATE_PAYROLL_PERIODS',
5754 		      'N',
5755 		      'PER_UTILITY_FUNCTIONS.CALCULATE_PAYROLL_PERIODS',
5756                       null,
5757 		      l_function_id
5758 		      );
5759 	--
5760 	load_context_usage(1,
5761 			   l_function_id,
5762 			   'PAYROLL_ID');
5763 	--
5764 	load_context_usage(2,
5765 			   l_function_id,
5766 			   'DATE_EARNED');
5767 	--
5768 	/********* LOOP_CONTROL ***********************/
5769 	--
5770 	load_function('LOOP_CONTROL',
5771 		      'N',
5772 		      'PER_FORMULA_FUNCTIONS.LOOP_CONTROL',
5773                       null,
5774 		      l_function_id);
5775 	--
5776 	load_parameter(1,
5777 		       l_function_id,
5778 		       'T', 'p_formula_name');
5779 	--
5780 	load_context_usage(1,
5781 			   l_function_id,
5782 			   'BUSINESS_GROUP_ID');
5783 	--
5784 	load_context_usage(2,
5785 			   l_function_id,
5786 			   'DATE_EARNED');
5787 	--
5788 	load_context_usage(3,
5789 			   l_function_id,
5790 			   'ASSIGNMENT_ID');
5791 	--
5792 	load_context_usage(4,
5793 			   l_function_id,
5794 			   'PAYROLL_ID');
5795 	--
5796 	load_context_usage(5,
5797 			   l_function_id,
5798 			   'ACCRUAL_PLAN_ID');
5799 	--
5800 	/********* SET_DATE ***********************/
5801 	--
5802 	load_function('SET_DATE',
5803 		      'N',
5804 		      'PER_FORMULA_FUNCTIONS.SET_DATE',
5805                       null,
5806 		      l_function_id);
5807 	--
5808 	load_parameter(1,
5809 		       l_function_id,
5810 		       'T', 'p_name');
5811 	--
5812 	load_parameter(2,
5813 		       l_function_id,
5814 		       'D', 'p_value');
5815 	--
5816 	/*********  SET_TEXT ***********************/
5817 	--
5818 	load_function('SET_TEXT',
5819 		      'N',
5820 		      'PER_FORMULA_FUNCTIONS.SET_TEXT',
5821                       null,
5822 		      l_function_id);
5823 	--
5824 	load_parameter(1,
5825 		       l_function_id,
5826 		       'T', 'p_name');
5827 	--
5828 	load_parameter(2,
5829 		       l_function_id,
5830 		       'T', 'p_value');
5831 	--
5832 	/********* GET_TEXT ***********************/
5833 	--
5834 	load_function('GET_TEXT',
5835 		      'T',
5836 		      'PER_FORMULA_FUNCTIONS.GET_TEXT',
5837                       null,
5838 		      l_function_id);
5839 	--
5840 	load_parameter(1,
5841 		       l_function_id,
5842 		       'T', 'p_name');
5843 	--
5844 	/********* GET_DATE ***********************/
5845 	--
5846 	load_function('GET_DATE',
5847 		      'D',
5848 		      'PER_FORMULA_FUNCTIONS.GET_DATE',
5849                       null,
5850 		      l_function_id);
5851 	--
5852 	load_parameter(1,
5853 		       l_function_id,
5854 		       'T', 'p_name');
5855 	--
5856 	/********* ISNULL ***********************/
5857 	--
5858 	load_function('ISNULL',
5859 		      'T',
5860 		      'PER_FORMULA_FUNCTIONS.ISNULL',
5861                       null,
5862 		      l_function_id);
5863 	--
5864 	load_parameter(1,
5865 		       l_function_id,
5866 		       'T', 'p_value');
5867 	--
5868 	/********* ISNULL ***********************/
5869 	--
5870 	load_function('ISNULL',
5871 		      'N',
5872 		      'PER_FORMULA_FUNCTIONS.ISNULL',
5873                       null,
5874 		      l_function_id);
5875 	--
5876 	load_parameter(1,
5877 		       l_function_id,
5878 		       'N', 'p_value');
5879 	--
5880 	/********* ISNULL ***********************/
5881 	--
5882 	load_function('ISNULL',
5883 		      'D',
5884 		      'PER_FORMULA_FUNCTIONS.ISNULL',
5885                       null,
5886 		      l_function_id);
5887 	--
5888 	load_parameter(1,
5889 		       l_function_id,
5890                     'D', 'p_value');
5891      --
5892      /********* REMOVE_GLOBALS ***********************/
5893      --
5894      load_function('REMOVE_GLOBALS',
5895                    'N',
5896                    'PER_FORMULA_FUNCTIONS.REMOVE_GLOBALS',
5897                    null,
5898                    l_function_id);
5899      --
5900      /********* CLEAR_GLOBALS ***********************/
5901      --
5902      load_function('CLEAR_GLOBALS',
5903                    'N',
5904                    'PER_FORMULA_FUNCTIONS.CLEAR_GLOBALS',
5905                    null,
5906                    l_function_id);
5907      --
5908      /********* DEBUG ***********************/
5909      --
5910      load_function('DEBUG',
5911                    'N',
5912                    'PER_FORMULA_FUNCTIONS.DEBUG',
5913                    null,
5914                    l_function_id);
5915      --
5916      load_parameter(1,
5917                     l_function_id,
5918                     'T', 'p_message');
5919      --
5920      /********* RAISE_ERROR ***********************/
5921      --
5922      load_function('RAISE_ERROR',
5923                    'N',
5924                    'PER_FORMULA_FUNCTIONS.RAISE_ERROR',
5925                    null,
5926                    l_function_id);
5927      --
5928      load_parameter(1,
5929                     l_function_id,
5930                     'N', 'p_application_id');
5931      --
5932      load_parameter(2,
5933                     l_function_id,
5934                     'T', 'p_message_name');
5935      --
5936      /********* GET_PAYROLL_PERIOD ***********************/
5937      --
5938      load_function('GET_PAYROLL_PERIOD',
5939                    'N',
5940                    'PER_UTILITY_FUNCTIONS.GET_PAYROLL_PERIOD',
5941                    null,
5942                    l_function_id);
5943      --
5944      load_parameter(1,
5945                     l_function_id,
5946                     'D', 'p_date_in_period');
5947      --
5948      load_context_usage(1,
5949                         l_function_id,
5950                         'PAYROLL_ID');
5951      --
5952      /********* GET_ACCRUAL_BAND ***********************/
5953      --
5954      load_function('GET_ACCRUAL_BAND',
5955                    'N',
5956                    'PER_UTILITY_FUNCTIONS.GET_ACCRUAL_BAND',
5957                    null,
5958                    l_function_id);
5959      --
5960      load_parameter(1,
5961                     l_function_id,
5962                     'N', 'p_number_of_years');
5963      --
5964      load_context_usage(1,
5965                         l_function_id,
5966                         'ACCRUAL_PLAN_ID');
5967      --
5968      /********* CALL_FORMULA ***********************/
5969      --
5970      load_function('CALL_FORMULA',
5971                    'N',
5972                    'PER_FORMULA_FUNCTIONS.CALL_FORMULA',
5973                    null,
5974                    l_function_id);
5975      --
5976      load_parameter(1,
5977                     l_function_id,
5978                     'T', 'p_formula_name');
5979      --
5980      load_context_usage(1,
5981                         l_function_id,
5982                         'BUSINESS_GROUP_ID');
5983      --
5984      load_context_usage(2,
5985                         l_function_id,
5986                         'DATE_EARNED');
5987      --
5988      load_context_usage(3,
5989                         l_function_id,
5990                         'ASSIGNMENT_ID');
5991      --
5992      load_context_usage(4,
5993                         l_function_id,
5994                         'PAYROLL_ID');
5995      --
5996      load_context_usage(5,
5997                         l_function_id,
5998                         'ACCRUAL_PLAN_ID');
5999      --
6000      /********* GET_NUMBER ***********************/
6001      --
6002      load_function('GET_NUMBER',
6003                    'N',
6004                    'PER_FORMULA_FUNCTIONS.GET_NUMBER',
6005                    null,
6006                    l_function_id);
6007      --
6008      load_parameter(1,
6009                     l_function_id,
6010                     'T', 'p_name');
6011      --
6012      /********* GET_ASSIGNMENT_STATUS ***********************/
6013      --
6014      load_function('GET_ASSIGNMENT_STATUS',
6015                    'N',
6016                    'PER_UTILITY_FUNCTIONS.GET_ASSIGNMENT_STATUS',
6017                    null,
6018                    l_function_id);
6019      --
6020      load_parameter(1,
6021                     l_function_id,
6022                     'D', 'p_effective_date');
6023      --
6024      load_context_usage(1,
6025                         l_function_id,
6026                         'ASSIGNMENT_ID');
6027      --
6028      /********* GET_PERIOD_DATES ***********************/
6029      --
6030      load_function('GET_PERIOD_DATES',
6031                    'N',
6032                    'PER_UTILITY_FUNCTIONS.GET_PERIOD_DATES',
6033                    null,
6034                    l_function_id);
6035      --
6036      load_parameter(1,
6037                     l_function_id,
6038                     'D', 'p_date_in_period');
6039      --
6040      load_parameter(2,
6041                     l_function_id,
6042                     'T', 'p_period_unit');
6043      --
6044      load_parameter(3,
6045                     l_function_id,
6046                     'D', 'p_base_start_date');
6047      --
6048      load_parameter(4,
6049                     l_function_id,
6050                     'N', 'p_unit_multiplier');
6051      --
6052      /********* SET_NUMBER ***********************/
6053      --
6054      load_function('SET_NUMBER',
6055                    'N',
6056                    'PER_FORMULA_FUNCTIONS.SET_NUMBER',
6057                    null,
6058                    l_function_id);
6059      --
6060      load_parameter(1,
6061                     l_function_id,
6062                     'T', 'p_name');
6063      --
6064      load_parameter(2,
6065                     l_function_id,
6066                     'N', 'p_value');
6067      --
6068      /********* GET_OTHER_NET_CONTRIBUTION ***********************/
6069      --
6070      load_function('GET_OTHER_NET_CONTRIBUTION',
6071                    'N',
6072                    'PER_ACCRUAL_CALC_FUNCTIONS.GET_OTHER_NET_CONTRIBUTION',
6073                    null,
6074                    l_function_id);
6075      --
6076      load_parameter(1,
6077                     l_function_id,
6078                     'D', 'p_calculation_date');
6079      --
6080      load_parameter(2,
6081                     l_function_id,
6082                     'D', 'p_start_date');
6083      --
6084      load_context_usage(1,
6085                         l_function_id,
6086                         'ASSIGNMENT_ID');
6087      --
6088      load_context_usage(2,
6089                         l_function_id,
6090                         'ACCRUAL_PLAN_ID');
6091      --
6092      /********* PUT_MESSAGE ***********************/
6093      --
6094      load_function('PUT_MESSAGE',
6095                    'N',
6096                    'PER_ACCRUAL_MESSAGE_PKG.PUT_MESSAGE',
6097                    null,
6098                    l_function_id);
6099      --
6100      load_parameter(1,
6101                     l_function_id,
6102                     'T', 'P_MESSAGE');
6103      --
6104      /********* GET_ABSENCE ***********************/
6105      --
6106      load_function('GET_ABSENCE',
6107                    'N',
6108                    'PER_ACCRUAL_CALC_FUNCTIONS.GET_ABSENCE',
6109                    null,
6110                    l_function_id);
6111      --
6112      load_parameter(1,
6113                     l_function_id,
6114                     'D', 'p_calculation_date');
6115      --
6116      load_parameter(2,
6117                     l_function_id,
6118                     'D', 'p_start_date');
6119      --
6120      load_context_usage(1,
6121                         l_function_id,
6122                         'ASSIGNMENT_ID');
6123      --
6124      load_context_usage(2,
6125                         l_function_id,
6126                         'ACCRUAL_PLAN_ID');
6127      --
6128      /********* GET_CARRY_OVER ***********************/
6129      --
6130      load_function('GET_CARRY_OVER',
6131                    'N',
6132                    'PER_ACCRUAL_CALC_FUNCTIONS.GET_CARRY_OVER',
6133                    null,
6134                    l_function_id);
6135      --
6136      load_parameter(1,
6137                     l_function_id,
6138                     'D', 'p_calculation_date');
6139      --
6140      load_parameter(2,
6141                     l_function_id,
6142                     'D', 'p_start_date');
6143      --
6144      load_context_usage(1,
6145                         l_function_id,
6146                         'ASSIGNMENT_ID');
6147      --
6148      load_context_usage(2,
6149                         l_function_id,
6150                         'ACCRUAL_PLAN_ID');
6151      --
6152      hr_utility.set_location ('hrstrdbi.insert_functions', 15);
6153      --
6154      load_function('CHK_NAT_ID_FORMAT',
6155                    'T',
6156                    'hr_ni_chk_pkg.chk_nat_id_format',
6157                    null,
6158                    l_function_id);
6159      --
6160      load_parameter(1,
6161                     l_function_id,
6162                     'T', 'national_identifer');
6163      --
6164      load_parameter(2,
6165                     l_function_id,
6166                     'T', 'format');
6167      --
6168      hr_utility.set_location ('hrstrdbi.insert_functions', 16);
6169      --
6170      load_function('COUNT_WORKING_DAYS',
6171                    'T',
6172                    'hr_cal_abs_dur_pkg.count_working_days',
6173                    null,
6174                    l_function_id);
6175      --
6176      load_parameter(1,
6177                     l_function_id,
6178                     'T', 'starting_date');
6179      --
6180      load_parameter(2,
6181                     l_function_id,
6182                     'T', 'total_days');
6183      --
6184      hr_utility.set_location ('hrstrdbi.insert_functions', 17);
6185      --
6186      /********* ITERATION_INITIALISE ***********************/
6187      --
6188      load_function('ITERATION_INITIALISE',
6189                    'N',
6190                    'pay_iterate.initialise',
6191                    null,
6192                    l_function_id);
6193      --
6194      load_parameter(1,
6195                     l_function_id,
6196                     'N', 'High Value');
6197      --
6198      load_parameter(2,
6199                     l_function_id,
6200                     'N', 'Low Value');
6201      --
6202      load_parameter(3,
6203                     l_function_id,
6204                     'N', 'Target Value');
6205      --
6206      load_context_usage(1,
6207                         l_function_id,
6208                         'ELEMENT_ENTRY_ID');
6209      --
6210      hr_utility.set_location ('hrstrdbi.insert_functions', 18);
6211      --
6212      /********* ITERATION_GET_INTERPOLATION ****************/
6213      --
6214      load_function('ITERATION_GET_INTERPOLATION',
6215                    'N',
6216                    'pay_iterate.get_interpolation_guess',
6217                    null,
6218                    l_function_id);
6219      --
6220      load_parameter(1,
6221                     l_function_id,
6222                     'N', 'Result Value');
6223      --
6224      load_context_usage(1,
6225                         l_function_id,
6226                         'ELEMENT_ENTRY_ID');
6227      --
6228      hr_utility.set_location ('hrstrdbi.insert_functions', 19);
6229      --
6230      /********* ITERATION_GET_BINARY ***********************/
6231      --
6232      load_function('ITERATION_GET_BINARY',
6233                    'N',
6234                    'pay_iterate.get_binary_guess',
6235                    null,
6236                    l_function_id);
6237      --
6238      load_parameter(1,
6239                     l_function_id,
6240                     'T', 'Mode');
6241      --
6242      load_context_usage(1,
6243                         l_function_id,
6244                         'ELEMENT_ENTRY_ID');
6245      --
6246      hr_utility.set_location ('hrstrdbi.insert_functions', 20);
6247      --
6248      /********* ITERATION_GET_HIGH ***********************/
6249      --
6250      load_function('ITERATION_GET_HIGH',
6251                    'N',
6252                    'pay_iterate.get_high_value',
6253                    null,
6254                    l_function_id);
6255      --
6256      load_context_usage(1,
6257                         l_function_id,
6258                         'ELEMENT_ENTRY_ID');
6259      --
6260      hr_utility.set_location ('hrstrdbi.insert_functions', 21);
6261      --
6262      /********* ITERATION_GET_LOW ***********************/
6263      --
6264      load_function('ITERATION_GET_LOW',
6265                    'N',
6266                    'pay_iterate.get_low_value',
6267                    null,
6268                    l_function_id);
6269      --
6270      load_context_usage(1,
6271                         l_function_id,
6272                         'ELEMENT_ENTRY_ID');
6273      --
6274      /********* ITERATION_GET_LOW ***********************/
6275      --
6276      load_function('ENTRY_PROCESSED_IN_PERIOD',
6277                    'T',
6278                    'pay_consumed_entry.consumed_entry',
6279                    'returns Y if the entry has been processed in a prior run in period',
6280                    l_function_id);
6281      --
6282      load_context_usage(1,
6283                         l_function_id,
6284                         'DATE_EARNED');
6285      --
6286      load_context_usage(2,
6287                         l_function_id,
6288                         'PAYROLL_ID');
6289      --
6290      load_context_usage(3,
6291                         l_function_id,
6292                         'ORIGINAL_ENTRY_ID');
6293      --
6294 --
6295 end insert_functions;
6296 --
6297 --
6298 PROCEDURE insert_formula is
6299 l_text                          long;
6300 l_ftype_id                      number;
6301 --
6302 begin
6303 --
6304      --
6305      --  BIS template formula TEMPLATE_BIS_DAYS_TO_HOURS
6306      --
6307 l_text := '
6308 /*********************************************************************
6309 FORMULA NAME: TEMPLATE_BIS_DAYS_TO_HOURS
6310 FORMULA TYPE: Quickpaint
6311 DESCRIPTION:  Converts a number of Days to a number of Hours
6312 --
6313 INPUTS:         days_worked
6314 --
6315 DBI Required:   ASG_FULL_TIME_FREQ
6316                 ASG_FULL_TIME_HOURS
6317                 ASG_FREQ_CODE
6318                 ASG_HOURS
6319 --
6320 Change History
6321 --------------
6322 Author     Date       Version  Bug      Description
6323 ---------  ---------  -------  -------  -----------
6324 S.Bhattal  30-SEP-99  115.0    1008543  Created - non-translatable
6325 					database items fixed.
6326 ********************************************************************/
6327 
6328 /* Updatable Values Section */
6329 
6330 /* Defaults Section */
6331 
6332 DEFAULT FOR asg_full_time_freq IS ''X''
6333 DEFAULT FOR asg_full_time_hours IS 0
6334 DEFAULT FOR asg_freq_code IS ''X''
6335 DEFAULT FOR asg_hours IS 0
6336 
6337 /* Inputs Section */
6338 
6339 INPUTS ARE days_worked
6340 
6341 /* Main Body of Formula */
6342 
6343 /* Set up the default number of working hours per day */
6344 /* This is only used if no Working Conditions have been */
6345 /* entered at any level */
6346 dflt_hours_per_day = 8
6347 
6348 /* Set up constants to use to divide the number of hours */
6349 /* specified on a Working Conditions to get the number */
6350 /* of working hours per day */
6351 working_days_per_week = 5
6352 working_days_per_month = 21
6353 
6354 
6355 IF (asg_freq_code WAS NOT DEFAULTED) AND
6356    (asg_hours WAS NOT DEFAULTED)
6357 THEN
6358 (
6359   hours = asg_hours
6360   freq  = asg_freq_code
6361 )
6362 ELSE
6363 (
6364   IF (asg_full_time_freq WAS NOT DEFAULTED) AND
6365      (asg_full_time_hours WAS NOT DEFAULTED)
6366   THEN
6367   (
6368     hours = asg_full_time_hours
6369     freq = asg_full_time_freq
6370   )
6371   ELSE
6372   (
6373      hours = dflt_hours_per_day
6374      freq = ''D''
6375   )
6376 )
6377 
6378 IF (freq = ''D'')
6379 THEN
6380   hours_worked = days_worked * hours
6381 
6382 ELSE IF (freq = ''W'')
6383 THEN
6384   hours_worked = days_worked * (hours / working_days_per_week)
6385 
6386 ELSE IF (freq = ''M'')
6387 THEN
6388   hours_worked = days_worked * (hours / working_days_per_month)
6389 
6390 ELSE
6391   hours_worked = 0
6392 
6393 hours_worked = ROUND(hours_worked,2)
6394 
6395 RETURN hours_worked
6396 ';
6397     --
6398     select formula_type_id
6399     into   l_ftype_id
6400     from   ff_formula_types
6401     where  formula_type_name = 'QuickPaint';
6402     --
6403     INSERT INTO ff_formulas_f
6404     (formula_id,
6405      effective_start_date,
6406      effective_end_date,
6407      business_group_id,
6408      legislation_code,
6409      formula_type_id,
6410      formula_name,
6411      description,
6412      formula_text,
6413      sticky_flag)
6414     VALUES
6415     (ff_formulas_s.nextval,
6416      to_date('01/01/0001','DD/MM/YYYY'),
6417      to_date('31/12/4712','DD/MM/YYYY'),
6418      NULL,
6419      NULL,
6420      l_ftype_id,
6421      'TEMPLATE_BIS_DAYS_TO_HOURS',
6422      'Template conversion from Days to Hours',
6423      l_text,
6424      NULL);
6425      --
6426      hr_utility.set_location ('hrstrdbi.insert_formula', 114);
6427      --
6428      --  BIS template formula TEMPLATE_FTE
6429      --
6430 l_text := '
6431 /*********************************************************************
6432 FORMULA NAME: TEMPLATE_FTE
6433 FORMULA TYPE: Quickpaint
6434 DESCRIPTION:  Calculates Assignment Full Time Equivalent value based on
6435               a) the value entered in Assignmnet Budget Values Form
6436               b) if part time worker the ratio of the normal conditions
6437                  for the position, organization or business group actually
6438                  worked
6439 --
6440 INPUTS:         None
6441 --
6442 DBI Required:
6443                 HRI_ASG_FULL_TIME_FREQ
6444                 HRI_ASG_FULL_TIME_HOURS
6445                 HRI_ASG_EMPLOYMENT_CATEGORY_CODE
6446                 HRI_ASG_FREQ_CODE
6447                 HRI_ASG_HOURS
6448 --
6449 Change History
6450 --
6451 Author     Date       Version  Bug      Description
6452 ---------  ---------  -------  -------  -----------
6453 S.Bhattal  30-SEP-99  115.0    1008543  Created - non-translatable
6454 					database items fixed.
6455 					ASG_FTE_VALUE removed.
6456 D.Vickers  27-MAY-2002                  HRI dbis now used
6457 ********************************************************************/
6458 
6459 /* Updatable Values Section */
6460 
6461 /* Defaults Section */
6462 
6463 DEFAULT FOR hri_asg_full_time_freq IS ''X''
6464 DEFAULT FOR hri_asg_full_time_hours IS 0
6465 DEFAULT FOR hri_asg_employment_category_code IS ''X''
6466 DEFAULT FOR hri_asg_freq_code IS ''X''
6467 DEFAULT FOR hri_asg_hours IS 0
6468 
6469 /* Inputs Section */
6470 
6471 /* Main Body of Formula */
6472 /* Set up the number of working hours per day, week and month
6473 These figures are used to determine the proportion of  available time a person w
6474 orks and the proportion of available time a Position, Organization or Business G
6475 roup usually works */
6476 
6477 daily_hours = 8
6478 weekly_hours = 40
6479 monthly_hours = 169
6480 default_fte=0
6481 
6482 /* If employment category is not entered then FTE cannot be calculated */
6483 
6484    IF hri_asg_employment_category_code WAS DEFAULTED THEN
6485       fte = default_fte
6486 
6487    ELSE
6488 /* If assignment is Full Time then FTE=1 */
6489 
6490       IF hri_asg_employment_category_code = ''FR''
6491       OR hri_asg_employment_category_code = ''FT'' THEN
6492          fte = 1
6493 
6494    ELSE
6495 /* If assignment is Part Time the FTE depends on working hours */
6496 
6497       IF hri_asg_employment_category_code = ''PR''
6498       OR hri_asg_employment_category_code = ''PT'' THEN
6499 
6500 /* If either the assignment conditions or those of position, organization or bus
6501 iness group are not entered then FTE cannot be calculated */
6502 
6503          IF hri_asg_full_time_freq WAS DEFAULTED
6504          OR hri_asg_freq_code WAS DEFAULTED THEN
6505             fte = default_fte
6506 
6507          ELSE
6508 /* If assignment normal frequency is not the same as position, organization or b
6509 usiness group frequency then it is necessary to convert the number of hours work
6510 ed into a standard unit */
6511 /* Note the value of asg_full_time_freq is the lookup_code, not the meaning
6512 so requires no translation */
6513             IF NOT hri_asg_full_time_freq = hri_asg_freq_code THEN
6514             (
6515                IF hri_asg_full_time_freq = ''H'' THEN
6516                   hours = 1
6517                ELSE IF hri_asg_full_time_freq = ''D'' THEN
6518                   hours = daily_hours
6519                ELSE IF hri_asg_full_time_freq = ''W'' THEN
6520                   hours = weekly_hours
6521                ELSE IF hri_asg_full_time_freq = ''M'' THEN
6522                   hours = monthly_hours
6523                ELSE
6524                   hours = 0
6525 
6526 /* For the position, organization, business group working hours calculate the pr
6527 oportion of available hours in the month that are worked */
6528 
6529                IF hours = 0 THEN
6530                   full_time_month_ratio = 0
6531                ELSE
6532                   full_time_month_ratio = hri_asg_full_time_hours / hours
6533 
6534 /* Now repeat the above for the assignment normal conditions */
6535 
6536              IF hri_asg_freq_code = ''HO'' THEN
6537                   hours = 1
6538                ELSE IF hri_asg_freq_code = ''D'' THEN
6539                   hours = daily_hours
6540                ELSE IF hri_asg_freq_code = ''W'' THEN
6541                   hours = weekly_hours
6542                ELSE IF hri_asg_freq_code = ''M'' THEN
6543                   hours = monthly_hours
6544                ELSE
6545                   hours = 0
6546 
6547 /* For the assignment working hours calculate the proportion of available hours
6548 in the month that are worked */
6549 
6550                IF hours = 0 THEN
6551                   asg_month_ratio = 0
6552                ELSE
6553                   asg_month_ratio = hri_asg_hours / hours
6554 
6555 /* Now calculate the ratio of hours worked by the assignment to those worked in
6556 the position, organization or business group (this is the FTE) */
6557 
6558                IF asg_month_ratio = 0 OR full_time_month_ratio = 0 THEN
6559                   fte = default_fte
6560                ELSE
6561                   fte = asg_month_ratio / full_time_month_ratio
6562             )
6563             ELSE
6564                fte = hri_asg_hours / hri_asg_full_time_hours
6565 
6566    ELSE
6567 
6568 /* If employment category is not Part Time or Full Time the cannot calculate FTE
6569  */
6570       fte = default_fte
6571 
6572 /* Round the calculated figure to 2 decimal places */
6573 fte = ROUND(fte,2)
6574 
6575 RETURN fte
6576 ';
6577     --
6578     select formula_type_id
6579     into   l_ftype_id
6580     from   ff_formula_types
6581     where  formula_type_name = 'QuickPaint';
6582     --
6583     INSERT INTO ff_formulas_f
6584     (formula_id,
6585      effective_start_date,
6586      effective_end_date,
6587      business_group_id,
6588      legislation_code,
6589      formula_type_id,
6590      formula_name,
6591      description,
6592      formula_text,
6593      sticky_flag)
6594     VALUES
6595     (ff_formulas_s.nextval,
6596      to_date('01/01/0001','DD/MM/YYYY'),
6597      to_date('31/12/4712','DD/MM/YYYY'),
6598      NULL,
6599      NULL,
6600      l_ftype_id,
6601      'TEMPLATE_FTE',
6602      'Calculates Assignment Full Time Equivalent Value',
6603      l_text,
6604      NULL);
6605      --
6606      hr_utility.set_location ('hrstrdbi.insert_formula', 115);
6607      --
6608      --  BIS template formula TEMPLATE_HEAD
6609      --
6610 l_text := '
6611 /*********************************************************************
6612 FORMULA NAME: TEMPLATE_HEAD
6613 FORMULA TYPE: Quickpaint
6614 DESCRIPTION:  Calculates Assignment Headcount value based on
6615               a) the value entered in Assignmnet Budget Values Form
6616               b) if assignment is primary then 1 else 0
6617 --
6618 INPUTS:         None
6619 --
6620 DBI Required:   ASG_PRIMARY_CODE
6621 --
6622 Change History
6623 --
6624 Author     Date       Version  Bug      Description
6625 ---------  ---------  -------  -------  -----------
6626 S.Bhattal  30-SEP-99  115.0    1008671  Created - non-translatable
6627 					database items fixed.
6628 					ASG_HEAD_VALUE removed.
6629 D.Vickers  27-MAY-2002                  Use HRI dbis
6630 ********************************************************************/
6631 
6632 /* Updatable Values Section */
6633 
6634 /* Defaults Section */
6635 
6636 DEFAULT FOR hri_asg_primary_code IS ''Y''
6637 
6638 /* Inputs Section */
6639 
6640 /* Main Body of Formula */
6641         IF hri_asg_primary_code = ''Y'' THEN
6642                 headcount = 1
6643         ELSE
6644                 headcount = 0
6645 
6646 /* Round the value to 2 decimal places */
6647 headcount = ROUND(headcount,2)
6648 
6649 RETURN headcount
6650 ';
6651      --
6652      select formula_type_id
6653      into   l_ftype_id
6654      from   ff_formula_types
6655      where  formula_type_name = 'QuickPaint';
6656      --
6657       INSERT INTO ff_formulas_f
6658      (formula_id,
6659       effective_start_date,
6660       effective_end_date,
6661       business_group_id,
6662       legislation_code,
6663       formula_type_id,
6664       formula_name,
6665       description,
6666       formula_text,
6667       sticky_flag)
6668    VALUES
6669      (ff_formulas_s.nextval,
6670       to_date('01/01/0001','DD/MM/YYYY'),
6671       to_date('31/12/4712','DD/MM/YYYY'),
6672       NULL,
6673       NULL,
6674       l_ftype_id,
6675       'TEMPLATE_HEAD',
6676       'Calculates Assignment Headcount Value',
6677       l_text,
6678       NULL);
6679      --
6680      hr_utility.set_location ('hrstrdbi.insert_formula', 116);
6681      --
6682      --  BIS template formula EXAMPLE_BIS_OT_BAND1
6683      --
6684 l_text := '
6685 /*********************************************************************
6686 FORMULA NAME: EXAMPLE_BIS_OT_BAND1
6687 FORMULA TYPE: Quickpaint
6688 DESCRIPTION:  This is an example of the syntax required for the
6689 	      fast formualae which need to be set up for use with
6690 	      the Hours Worked Analysis Report.  The function
6691 	      get_hours_worked calculates total hours worked from
6692 	      the Overtime element seeded with US Payroll.
6693 --
6694 INPUTS:         None
6695 --
6696 DBI Required:   None
6697 --
6698 Change History
6699 --------------
6700 Date       Author    Version    Description
6701 ----       ------    -------    -----------
6702 10 Sep 98  jmay      110.0      Created
6703 --
6704 16-SEP-98  mmillmor  110.2      Added a header
6705 --
6706 26 Nov 98  sbhattal  110.3      Create FastFormula type Quickpaint if it
6707 				does not exist (required for fresh HR databases
6708 				which have not had the HR post-install steps
6709 				applied, or for BIS customers who do not have
6710 				HR).
6711 --
6712 ********************************************************************/
6713 
6714 /* Updatable Values Section */
6715 
6716 /* Defaults Section */
6717 
6718 /* Inputs Section */
6719 
6720 /* Main Body of Formula */
6721 hours_worked = get_hours_worked(1.5)
6722 
6723 RETURN hours_worked
6724 ';
6725     --
6726     select formula_type_id
6727     into   l_ftype_id
6728     from   ff_formula_types
6729     where  formula_type_name = 'QuickPaint';
6730     --
6731       INSERT INTO ff_formulas_f
6732      (formula_id,
6733       effective_start_date,
6734       effective_end_date,
6735       business_group_id,
6736       legislation_code,
6737       formula_type_id,
6738       formula_name,
6739       description,
6740       formula_text,
6741       sticky_flag)
6742    VALUES
6743      (ff_formulas_s.nextval,
6744       to_date('01/01/0001','DD/MM/YYYY'),
6745       to_date('31/12/4712','DD/MM/YYYY'),
6746       NULL,
6747       NULL,
6748       l_ftype_id,
6749       'EXAMPLE_BIS_OT_BAND1',
6750       'Calculate Overtime',
6751       l_text,
6752       NULL);
6753      --
6754      hr_utility.set_location ('hrstrdbi.insert_formula', 117);
6755     --
6756 l_text := '
6757 DEFAULT FOR ACP_CONTINUOUS_SERVICE_DATE IS ''4712/12/31 00:00:00'' (date)
6758 DEFAULT FOR ACP_SERVICE_START_DATE IS ''4712/12/31 00:00:00'' (date)
6759 
6760 INPUTS ARE
6761 Calculation_Date (date),
6762 Accrual_term (text)
6763 
6764 IF (Accrual_Term = ''CURRENT'') THEN
6765 (
6766   /* Set the effective date of the carryover to the end date
6767      of the last payroll period of this year */
6768   Temp_Effective_date = to_date(''3112'' + to_char(Calculation_date, ''YYYY''), ''DDMMYYYY'')
6769 
6770   E = GET_PAYROLL_PERIOD(Temp_Effective_date)
6771   Calculation_Period_SD  = get_date(''PAYROLL_PERIOD_START_DATE'')
6772   Calculation_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
6773 
6774   IF (to_char(Calculation_Period_ED, ''YYYY'') <> to_char(Calculation_Period_SD, ''YYYY'')) THEN
6775   (
6776     E = GET_PAYROLL_PERIOD(add_days(Calculation_Period_SD, -1))
6777     Calculation_Period_SD  = get_date(''PAYROLL_PERIOD_START_DATE'')
6778     Calculation_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
6779   )
6780 
6781   Effective_date = Calculation_Period_ED
6782 
6783   /* Set the expiry date of the carryover to the end date
6784      of the last payroll period of next year */
6785   Temp_Expiry_date = to_date(''3112'' + to_char(add_years(Calculation_date, 1)
6786                                         ,''YYYY''), ''DDMMYYYY'')
6787 
6788   E = GET_PAYROLL_PERIOD(Temp_Expiry_date)
6789   Calculation_Period_SD = get_date(''PAYROLL_PERIOD_START_DATE'')
6790   Calculation_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
6791 
6792   IF (to_char(Calculation_Period_ED, ''YYYY'') <> to_char(Calculation_Period_SD,''YYYY'')) THEN
6793   (
6794    E = GET_PAYROLL_PERIOD(add_days(Calculation_Period_SD, -1))
6795     Calculation_Period_SD  = get_date(''PAYROLL_PERIOD_START_DATE'')
6796     Calculation_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
6797   )
6798 
6799   Expiry_Date = Calculation_Period_ED
6800 
6801 )
6802 ELSE IF (Accrual_term = ''PREVIOUS'') THEN
6803 (
6804   /* Set the effective date of the carryover to the end date
6805      of the last payroll period of last year */
6806   Temp_Effective_date = ADD_DAYS(to_date(''0101'' + to_char(Calculation_date, ''YYYY''), ''DDMMYYYY''), -1)
6807 
6808   E = GET_PAYROLL_PERIOD(Temp_Effective_date)
6809   Calculation_Period_SD  = get_date(''PAYROLL_PERIOD_START_DATE'')
6810   Calculation_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
6811 
6812   IF (to_char(Calculation_Period_ED, ''YYYY'') <> to_char(Calculation_Period_SD, ''YYYY'')) THEN
6813   (
6814     E = GET_PAYROLL_PERIOD(add_days(Calculation_Period_SD, -1))
6815     Calculation_Period_SD  = get_date(''PAYROLL_PERIOD_START_DATE'')
6816     Calculation_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
6817   )
6818 
6819   Effective_date = Calculation_Period_ED
6820 
6821   /* Set the expiry date of the carryover to the end date
6822      of the last payroll period of this year */
6823   Temp_Expiry_date = to_date(''3112'' + to_char(Calculation_date, ''YYYY''), ''DDMMYYYY'')
6824 
6825   E = GET_PAYROLL_PERIOD(Temp_Expiry_date)
6826   Calculation_Period_SD  = get_date(''PAYROLL_PERIOD_START_DATE'')
6827   Calculation_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
6828 
6829   IF (to_char(Calculation_Period_ED, ''YYYY'') <> to_char(Calculation_Period_SD, ''YYYY'')) THEN
6830   (
6831     E = GET_PAYROLL_PERIOD(add_days(Calculation_Period_SD, -1))
6832     Calculation_Period_SD  = get_date(''PAYROLL_PERIOD_START_DATE'')
6833     Calculation_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
6834   )
6835 
6836   Expiry_Date = Calculation_Period_ED
6837 )
6838 
6839 IF ACP_CONTINUOUS_SERVICE_DATE WAS DEFAULTED THEN
6840 (
6841   Continuous_Service_Date = ACP_SERVICE_START_DATE
6842 )
6843 ELSE
6844 (
6845   Continuous_Service_Date = ACP_CONTINUOUS_SERVICE_DATE
6846 )
6847 
6848 Years_service = floor(months_between(Effective_date, Continuous_Service_Date) / 12)
6849 
6850 IF (GET_ACCRUAL_BAND(years_service) = 0) THEN
6851 (
6852   Max_carryover = GET_NUMBER(''MAX_CARRY_OVER'')
6853 )
6854 ELSE
6855 (
6856   Max_carryover = 0
6857 )
6858 
6859 Process = ''YES''
6860 
6861 RETURN Max_Carryover, Effective_date, Expiry_Date, Process
6862 ';
6863     --
6864     select formula_type_id
6865     into   l_ftype_id
6866     from   ff_formula_types
6867     where  formula_type_name = 'Accrual Carryover';
6868     --
6869       INSERT INTO ff_formulas_f
6870      (formula_id,
6871       effective_start_date,
6872       effective_end_date,
6873       business_group_id,
6874       legislation_code,
6875       formula_type_id,
6876       formula_name,
6877       description,
6878       formula_text,
6879       sticky_flag)
6880    VALUES
6881      (ff_formulas_s.nextval,
6882       to_date('01/01/0001','DD/MM/YYYY'),
6883       to_date('31/12/4712','DD/MM/YYYY'),
6884       NULL,
6885       NULL,
6886       l_ftype_id,
6887       'PTO_PAYROLL_CARRYOVER',
6888       'Seeded carry over payroll formula for PTO accruals',
6889       l_text,
6890       NULL);
6891      --
6892      hr_utility.set_location ('hrstrdbi.insert_formula', 118);
6893     --
6894 l_text := '
6895 /* ------------------------------------------------------------------------
6896     NAME : PTO_PAYROLL_PERIOD_ACCRUAL
6897     This formula calculates the amount of PTO accrued for a particular payroll period
6898    ---------------------------------------------------------------------*/
6899 
6900 /*------------------------------------------------------------------------
6901     Get the global variable to be used in this formula
6902  ------------------------------------------------------------------------*/
6903 
6904 Payroll_Year_Number_Of_Periods = get_number(''PAYROLL_YEAR_NUMBER_OF_PERIODS'')
6905 Continuous_Service_Date = get_date(''CONTINUOUS_SERVICE_DATE'')
6906 Total_Accrued_PTO = get_number(''TOTAL_ACCRUED_PTO'')
6907 Period_SD = get_date(''PERIOD_SD'')
6908 Period_ED = get_date(''PERIOD_ED'')
6909 Last_Period_SD = get_date(''LAST_PERIOD_SD'')
6910 Last_Period_ED = get_date(''LAST_PERIOD_ED'')
6911 Payroll_Year_SD = get_date(''PAYROLL_YEAR_SD'')
6912 
6913 /*----------------------------------------------------------------------
6914     Determine the Accrual Band that applies this period
6915     1. If upper limit is not set then find the band spanning the continuous service number of years
6916     2. If the band is not found then end the processing for this period
6917     3. If continuous service is less than the upper limit then use the globals as they are
6918     4. If continuous service is greater than or equal to the upper limit then reset the globals
6919   ----------------------------------------------------------------------*/
6920 
6921 Annual_Rate = get_number(''ANNUAL_RATE'')
6922 Upper_Limit = get_number(''UPPER_LIMIT'')
6923 Ceiling = get_number(''CEILING'')
6924 
6925 Years_Service = Floor(Months_Between(Period_ED,Continuous_Service_Date)/12)
6926 
6927 IF (Upper_Limit = 0 OR
6928      Years_Service >= Upper_Limit ) THEN
6929    (
6930     IF ( GET_ACCRUAL_BAND(Years_Service) = 0 ) THEN
6931         (
6932          Annual_Rate = get_number(''ANNUAL_RATE'')
6933          Upper_Limit = get_number(''UPPER_LIMIT'')
6934          Ceiling = get_number(''CEILING'')
6935         )
6936     ELSE
6937        (
6938         Continue_Processing_Flag = ''N''
6939         Return Continue_Processing_Flag
6940         )
6941    )
6942 
6943 Accrual_Rate = Annual_Rate / Payroll_Year_Number_Of_Periods
6944 
6945 /* ----------------------------------------------------------------------
6946     Calculate the Amount Accrued this Period excluding time where
6947     the assignment was not active.
6948    ---------------------------------------------------------------------*/
6949 
6950 Assignment_Inactive_Days = GET_ASG_INACTIVE_DAYS(Period_SD, Period_ED)
6951 
6952 IF Assignment_Inactive_Days <> 0 THEN
6953     (
6954      Working_Days = GET_WORKING_DAYS(Period_SD, Period_ED)
6955          IF Working_Days = Assignment_Inactive_Days THEN
6956               (
6957                Multiplier = 0
6958                )
6959          ELSE
6960               (
6961                Multiplier = 1 - (Assignment_Inactive_Days / Working_Days)
6962                )
6963      )
6964 ELSE
6965    (
6966     Multiplier = 1
6967     )
6968 
6969 Period_Accrued_PTO = Accrual_Rate * Multiplier
6970 
6971 /* ----------------------------------------------------------------------
6972     Calculate any absence or bought/sold time etc. to be accounted for in this period.
6973    ---------------------------------------------------------------------*/
6974 
6975 Absence = GET_ABSENCE(Period_ED, Payroll_Year_SD)
6976 CarryOver = GET_CARRY_OVER(Period_ED, Payroll_Year_SD)
6977 Other = GET_OTHER_NET_CONTRIBUTION(Period_ED, Payroll_Year_SD)
6978 
6979 Period_Others = CarryOver + Other - Absence
6980 
6981 /* ----------------------------------------------------------------------
6982     Now establish whether the Accrual this period has gone over the ceiling if one exists
6983    ----------------------------------------------------------------------*/
6984 
6985 IF (Ceiling > 0) THEN
6986     (
6987      IF (Total_Accrued_PTO + Period_Accrued_PTO + Period_Others > Ceiling) THEN
6988          (
6989           Amount_Over_Ceiling = Total_Accrued_PTO + Period_Accrued_PTO + Period_Others - Ceiling
6990           IF (Amount_Over_Ceiling > Period_Accrued_PTO) THEN
6991                (
6992                Period_Accrued_PTO = 0
6993                )
6994           ELSE
6995               (
6996                Period_Accrued_PTO = Period_Accrued_PTO - Amount_Over_Ceiling
6997               )
6998           )
6999      )
7000 
7001 /*---------------------------------------------------------------------
7002     Set the Running Total
7003   ---------------------------------------------------------------------*/
7004 
7005 E = set_number(''TOTAL_ACCRUED_PTO'',Total_Accrued_PTO + Period_Accrued_PTO)
7006 
7007 
7008 /* ----------------------------------------------------------------------
7009     Establish whether the current period is the last one, if so end the processing, otherwise get the
7010     next period
7011 ------------------------------------------------------------------------*/
7012 
7013 IF Period_SD = Last_Period_SD THEN
7014     (
7015     Continue_Processing_Flag = ''N''
7016     )
7017 ELSE
7018    (
7019     E = GET_PAYROLL_PERIOD(ADD_DAYS(Period_ED,1))
7020     E = set_date(''PERIOD_SD'',get_date(''PAYROLL_PERIOD_START_DATE''))
7021     E = set_date(''PERIOD_ED'',get_date(''PAYROLL_PERIOD_END_DATE''))
7022 
7023    Continue_Processing_Flag = ''Y''
7024    )
7025 
7026 Return Continue_Processing_Flag
7027 ';
7028     --
7029     select formula_type_id
7030     into   l_ftype_id
7031     from   ff_formula_types
7032     where  formula_type_name = 'Accrual Subformula';
7033     --
7034      INSERT INTO ff_formulas_f
7035      (formula_id,
7036       effective_start_date,
7037       effective_end_date,
7038       business_group_id,
7039       legislation_code,
7040       formula_type_id,
7041       formula_name,
7042       description,
7043       formula_text,
7044       sticky_flag)
7045    VALUES
7046      (ff_formulas_s.nextval,
7047       to_date('01/01/0001','DD/MM/YYYY'),
7048       to_date('31/12/4712','DD/MM/YYYY'),
7049       NULL,
7050       NULL,
7051       l_ftype_id,
7052       'PTO_PAYROLL_PERIOD_ACCRUAL',
7053       'Seeded looping payroll formula for PTO accruals',
7054       l_text,
7055       NULL);
7056     --
7057     hr_utility.set_location ('hrstrdbi.insert_formula', 119);
7058     --
7059 l_text := '
7060 /* ------------------------------------------------------------------------
7061     NAME : PTO_PAYROLL_CALCULATION
7062     This formula calculates the dates between which an assignment is to accrue time
7063    ---------------------------------------------------------------------*/
7064 
7065 DEFAULT FOR ACP_START IS ''HD''
7066 DEFAULT FOR ACP_INELIGIBILITY_PERIOD_TYPE IS ''CM''
7067 DEFAULT FOR ACP_INELIGIBILITY_PERIOD_LENGTH IS 0
7068 DEFAULT FOR ACP_CONTINUOUS_SERVICE_DATE IS ''4712/12/31 00:00:00'' (date)
7069 DEFAULT FOR ACP_ENROLLMENT_END_DATE IS ''4712/12/31 00:00:00'' (date)
7070 DEFAULT FOR ACP_TERMINATION_DATE IS ''4712/12/31 00:00:00'' (date)
7071 DEFAULT FOR ACP_ENROLLMENT_START_DATE IS ''4712/12/31 00:00:00'' (date)
7072 DEFAULT FOR ACP_SERVICE_START_DATE IS ''4712/12/31 00:00:00'' (date)
7073 
7074 INPUTS ARE
7075 Calculation_Date (date)
7076 
7077 E = CALCULATE_PAYROLL_PERIODS()
7078 
7079 /*-----------------------------------------------------------------------
7080    For the payroll year that spans the Calculation Date
7081    get the first days of the payroll year
7082   ----------------------------------------------------------------------- */
7083 
7084 Payroll_Year_First_Valid_Date = GET_DATE(''PAYROLL_YEAR_FIRST_VALID_DATE'')
7085 E = SET_DATE(''PAYROLL_YEAR_SD'', Payroll_Year_First_Valid_Date)
7086 
7087 /* ------------------------------------------------------------------------
7088    Set the Calculation_Date to the Termination Date / Enrollment end date if not defaulted
7089 -------------------------------------------------------------------------- */
7090 
7091 IF NOT (ACP_TERMINATION_DATE WAS DEFAULTED) OR
7092     NOT (ACP_ENROLLMENT_END_DATE WAS DEFAULTED) THEN
7093 (
7094   Early_End_Date = least(ACP_TERMINATION_DATE, ACP_ENROLLMENT_END_DATE)
7095 
7096   IF (Early_End_Date < Calculation_Date) THEN
7097   (
7098     Calculation_Date = Early_End_Date
7099   )
7100 )
7101 
7102 /* ------------------------------------------------------------------------
7103    Get the last whole payroll period prior to the Calculation Date and ensure that it is within the
7104    Payroll Year (if the Calculation Date is the End of a Period then use that period)
7105    ------------------------------------------------------------------------ */
7106 
7107 E = GET_PAYROLL_PERIOD(Calculation_Date)
7108 Calculation_Period_SD  = get_date(''PAYROLL_PERIOD_START_DATE'')
7109 Calculation_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
7110 
7111 IF (Calculation_Date <> Calculation_Period_ED) THEN
7112     (
7113      E = GET_PAYROLL_PERIOD(ADD_DAYS(Calculation_Period_SD,-1))
7114     Calculation_Period_SD  = get_date(''PAYROLL_PERIOD_START_DATE'')
7115     Calculation_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
7116    )
7117 
7118 
7119 /* ------------------------------------------------------------------------
7120    Set the Continuous Service Global Variable, whilst also
7121    ensuring that the continuous service date is before the Calculation Period
7122   ------------------------------------------------------------------------ */
7123 
7124 IF (ACP_CONTINUOUS_SERVICE_DATE WAS DEFAULTED) THEN
7125     (
7126     E = set_date(''CONTINUOUS_SERVICE_DATE'', ACP_SERVICE_START_DATE)
7127     )
7128 ELSE IF(ACP_CONTINUOUS_SERVICE_DATE > Calculation_Period_SD) THEN
7129    (
7130     Total_Accrued_PTO = 0
7131     E = PUT_MESSAGE(''HR_52796_PTO_FML_CSD'')
7132     E = set_date(''CONTINUOUS_SERVICE_DATE'', ACP_CONTINUOUS_SERVICE_DATE)
7133    )
7134 ELSE
7135   (
7136     E = set_date(''CONTINUOUS_SERVICE_DATE'', ACP_CONTINUOUS_SERVICE_DATE)
7137   )
7138 
7139 /* ------------------------------------------------------------------------
7140    Determine the Accrual Start Rule and modify the start date of the accrual calculation accordingly
7141 
7142    N.B. In this calculation the Accrual Start Rule determines the date from which a person may first accrue
7143    PTO. The Ineligibility Rule determines the period of time during which the PTO is not registered.
7144    Once this date has passed the accrual is registered from the date determined by the Accrual Start Rule.
7145  ------------------------------------------------------------------------ */
7146 
7147 Continuous_Service_Date = get_date(''CONTINUOUS_SERVICE_DATE'')
7148 
7149 IF (ACP_START = ''BOY'') THEN
7150     (
7151      First_Eligible_To_Accrue_Date =
7152          to_date(''01/01/''||to_char(add_months(Continuous_Service_Date, 12), ''YYYY''),
7153                        ''DD/MM/YYYY'')
7154      )
7155 ELSE IF (ACP_START = ''PLUS_SIX_MONTHS'') THEN
7156     (
7157      First_Eligible_To_Accrue_Date = add_months(Continuous_Service_Date,6)
7158      )
7159 ELSE IF (ACP_START = ''HD'') THEN
7160     (
7161      First_Eligible_To_Accrue_Date  = Continuous_Service_Date
7162      )
7163 
7164 /*------------------------------------------------------------------------
7165    Determine the date on which accrued PTo may first be registered, i.e the date on which the
7166    Ineligibility Period expires
7167    ------------------------------------------------------------------------ */
7168 
7169 Accrual_Ineligibility_Expired_Date = First_Eligible_To_Accrue_Date
7170 
7171 IF (ACP_START <> ''PLUS_SIX_MONTHS'' AND
7172      ACP_INELIGIBILITY_PERIOD_LENGTH > 0) THEN
7173    (
7174    IF ACP_INELIGIBILITY_PERIOD_TYPE = ''BM'' THEN
7175       (
7176       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
7177                                                     ACP_INELIGIBILITY_PERIOD_LENGTH*2)
7178       )
7179    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''F'' THEN
7180       (
7181       Accrual_Ineligibility_Expired_Date = add_days(Continuous_Service_Date,
7182                                                     ACP_INELIGIBILITY_PERIOD_LENGTH*14)
7183       )
7184    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''CM'' THEN
7185       (
7186       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
7187                                                       ACP_INELIGIBILITY_PERIOD_LENGTH)
7188       )
7189    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''LM'' THEN
7190       (
7191       Accrual_Ineligibility_Expired_Date = add_days(Continuous_Service_Date,
7192                                                   ACP_INELIGIBILITY_PERIOD_LENGTH*28)
7193       )
7194    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''Q'' THEN
7195       (
7196       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
7197                                                       ACP_INELIGIBILITY_PERIOD_LENGTH*3)
7198       )
7199    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''SM'' THEN
7200       (
7201       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
7202                                                       ACP_INELIGIBILITY_PERIOD_LENGTH/2)
7203       )
7204    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''SY'' THEN
7205       (
7206       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
7207                                                       ACP_INELIGIBILITY_PERIOD_LENGTH*6)
7208       )
7209    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''W'' THEN
7210       (
7211       Accrual_Ineligibility_Expired_Date = add_days(Continuous_Service_Date,
7212                                                     ACP_INELIGIBILITY_PERIOD_LENGTH*7)
7213       )
7214    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''Y'' THEN
7215       (
7216       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
7217                                                       ACP_INELIGIBILITY_PERIOD_LENGTH*12)
7218       )
7219 
7220    IF Accrual_Ineligibility_Expired_Date > First_Eligible_To_Accrue_Date
7221    AND Calculation_Date < Accrual_Ineligibility_Expired_Date THEN
7222       (
7223       First_Eligible_To_Accrue_Date = Accrual_Ineligibility_Expired_Date
7224       )
7225    )
7226 
7227 
7228 /* ----------------------------------------------------------------------
7229   If the employee is eligible to accrue before the start of this year,
7230   we must get the period dates for the first period of the year.
7231   Otherwise, we do not need these dates, as we will never accrue that
7232   far back.
7233 ----------------------------------------------------------------------- */
7234 
7235 IF First_Eligible_To_Accrue_Date <= Payroll_Year_First_Valid_Date THEN
7236 (
7237   E = GET_PAYROLL_PERIOD(Payroll_Year_First_Valid_Date)
7238 
7239   Payroll_Year_1st_Period_SD = get_date(''PAYROLL_PERIOD_START_DATE'')
7240   Payroll_Year_1st_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
7241 
7242   IF Payroll_Year_1st_Period_SD <> Payroll_Year_First_Valid_Date THEN
7243   (
7244      E = GET_PAYROLL_PERIOD(ADD_DAYS(Payroll_Year_1st_Period_ED, 1))
7245 
7246     Payroll_Year_1st_Period_SD = get_date(''PAYROLL_PERIOD_START_DATE'')
7247     Payroll_Year_1st_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
7248   )
7249 
7250   Effective_Start_Date = Payroll_Year_First_Valid_Date
7251 
7252 )
7253 ELSE
7254 (
7255   /* ------------------------------------------------------------------------
7256    Get the first full payroll period following the First_Eligible_To_Accrue_Date
7257    (if it falls on the beginning of the period then use that period)
7258   ------------------------------------------------------------------------- */
7259 
7260   E = GET_PAYROLL_PERIOD(First_Eligible_To_Accrue_Date )
7261   First_Eligible_To_Accrue_Period_SD  = get_date(''PAYROLL_PERIOD_START_DATE'')
7262   First_Eligible_To_Accrue_Period_ED  = get_date(''PAYROLL_PERIOD_END_DATE'')
7263 
7264   IF First_Eligible_To_Accrue_Date <> First_Eligible_To_Accrue_Period_SD THEN
7265   (
7266     E = GET_PAYROLL_PERIOD(add_days(First_Eligible_To_Accrue_Period_ED,1))
7267     First_Eligible_To_Accrue_Period_SD  = get_date(''PAYROLL_PERIOD_START_DATE'')
7268     First_Eligible_To_Accrue_Period_ED  = get_date(''PAYROLL_PERIOD_END_DATE'')
7269    )
7270 
7271   IF (First_Eligible_To_Accrue_Period_SD > Calculation_Period_ED) THEN
7272   (
7273     Total_Accrued_PTO = 0
7274     E = PUT_MESSAGE(''HR_52793_PTO_FML_ASG_INELIG'')
7275   )
7276 
7277 
7278   Payroll_Year_1st_Period_SD = First_Eligible_To_Accrue_Period_SD
7279   Payroll_Year_1st_Period_ED = First_Eligible_To_Accrue_Period_ED
7280 
7281   Effective_Start_Date = First_Eligible_To_Accrue_Date
7282 
7283 )
7284   Effective_Start_Date = GREATEST(Effective_Start_Date, ACP_ENROLLMENT_START_DATE)
7285 
7286 
7287 /* -----------------------------------------------------------------
7288   Output messages based on calculated date
7289 ----------------------------------------------------------------- */
7290 
7291 IF (Early_End_Date < Payroll_Year_1st_Period_ED) THEN
7292 (
7293   Total_Accrued_PTO = 0
7294   E = PUT_MESSAGE(''HR_52794_PTO_FML_ASG_TER'')
7295 )
7296 
7297 If (Calculation_Period_ED < Payroll_Year_1st_Period_ED) THEN
7298 (
7299   Total_Accrued_PTO = 0
7300   E = PUT_MESSAGE(''HR_52795_PTO_FML_CALC_DATE'')
7301 )
7302 
7303 
7304 
7305 /* ------------------------------------------------------------------------
7306    Determine the date on which PTO actually starts accruing based on Hire Date,
7307    Continuous Service Date and plan Enrollment Start Date. Remember, we have already determined
7308    whether to user hire date or CSD earlier in the formula.
7309    If this date is after the 1st period and the fisrt eligible date then establish the first full payroll period
7310    after this date (if the Actual Start Date falls on the beginning of a payroll period then use this period)
7311  ------------------------------------------------------------------------ */
7312 
7313  Enrollment_Start_Date = ACP_ENROLLMENT_START_DATE
7314 
7315  Actual_Accrual_Start_Date = GREATEST(Enrollment_Start_Date,
7316                                       Continuous_Service_Date,
7317                                       Payroll_Year_1st_Period_SD)
7318 
7319 /* -------------------------------------------------------------------------
7320        Determine the actual start of the accrual calculation
7321 -------------------------------------------------------------------------*/
7322 IF (Actual_Accrual_Start_Date > Payroll_Year_1st_Period_SD AND
7323      Actual_Accrual_Start_Date > First_Eligible_To_Accrue_Date) THEN
7324     (
7325      E = GET_PAYROLL_PERIOD(Actual_Accrual_Start_Date)
7326 
7327      Accrual_Start_Period_SD = get_date(''PAYROLL_PERIOD_START_DATE'')
7328      Accrual_Start_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
7329 
7330      IF Actual_Accrual_Start_Date > Accrual_Start_Period_SD THEN
7331          (
7332           E = GET_PAYROLL_PERIOD(add_days(Accrual_Start_Period_ED,1))
7333 
7334           Accrual_Start_Period_SD = get_date(''PAYROLL_PERIOD_START_DATE'')
7335           Accrual_Start_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
7336          )
7337 
7338 /* -----------------------------------------------------------------
7339         If the Actual Acrual Period is after the Calculation Period then end the processing.
7340 ----------------------------------------------------------------- */
7341         IF (Accrual_Start_Period_SD > Calculation_Period_ED) THEN
7342             (
7343             Total_Accrued_PTO = 0
7344             E = PUT_MESSAGE(''HR_52797_PTO_FML_ACT_ACCRUAL'')
7345             )
7346      )
7347 
7348 ELSE IF (First_Eligible_To_Accrue_Date > Payroll_Year_1st_Period_SD) THEN
7349      (
7350           Accrual_Start_Period_SD = First_Eligible_To_Accrue_Period_SD
7351           Accrual_Start_Period_ED = First_Eligible_To_Accrue_Period_ED
7352      )
7353 ELSE
7354     (
7355           Accrual_Start_Period_SD = Payroll_Year_1st_Period_SD
7356           Accrual_Start_Period_ED = Payroll_Year_1st_Period_ED
7357     )
7358 
7359  /* -------------------------------------------------------------------
7360        Now set up the information that will be used in when looping through the payroll periods
7361 --------------------------------------------------------------------- */
7362 
7363 IF Calculation_Period_ED >= Accrual_Start_Period_ED THEN
7364 (
7365 E = set_date(''PERIOD_SD'',Accrual_Start_Period_SD)
7366 E = set_date(''PERIOD_ED'',Accrual_Start_Period_ED)
7367 E = set_date(''LAST_PERIOD_SD'',Calculation_Period_SD)
7368 E = set_date(''LAST_PERIOD_ED'',Calculation_Period_ED)
7369 E = set_number(''TOTAL_ACCRUED_PTO'',0)
7370 
7371 /* -------------------------------------------------------------------
7372        Initialize Band Information
7373 -------------------------------------------------------------------- */
7374 
7375 E = set_number(''ANNUAL_RATE'', 0)
7376 E = set_number(''UPPER_LIMIT'', 0)
7377 E = set_number(''CEILING'', 0)
7378 
7379 E = LOOP_CONTROL(''PTO_PAYROLL_PERIOD_ACCRUAL'')
7380 
7381 Total_Accrued_PTO = get_number(''TOTAL_ACCRUED_PTO'')
7382 )
7383 
7384 IF Accrual_Start_Period_SD <= Calculation_Period_SD THEN
7385 (
7386   Accrual_end_date = Calculation_Period_ED
7387 )
7388 
7389 IF Effective_Start_Date > Actual_Accrual_Start_Date THEN
7390 (
7391   Effective_Start_Date = Actual_Accrual_Start_Date
7392 )
7393 
7394 Effective_End_Date = Calculation_Date
7395 
7396 IF Effective_Start_Date >= Effective_End_Date THEN
7397 (
7398   Effective_Start_Date = least(Effective_End_Date, Accrual_Start_Period_SD)
7399 )
7400 
7401 RETURN Total_Accrued_PTO, Effective_start_date, Effective_end_date, Accrual_end_date
7402 ';
7403     --
7404     select formula_type_id
7405     into   l_ftype_id
7406     from   ff_formula_types
7407     where  formula_type_name = 'Accrual';
7408     --
7409      INSERT INTO ff_formulas_f
7410      (formula_id,
7411       effective_start_date,
7412       effective_end_date,
7413       business_group_id,
7414       legislation_code,
7415       formula_type_id,
7416       formula_name,
7417       description,
7418       formula_text,
7419       sticky_flag)
7420    VALUES
7421      (ff_formulas_s.nextval,
7422       to_date('01/01/0001','DD/MM/YYYY'),
7423       to_date('31/12/4712','DD/MM/YYYY'),
7424       NULL,
7425       NULL,
7426       l_ftype_id,
7427       'PTO_PAYROLL_CALCULATION',
7428       'Seeded top level payroll formula for PTO accruals',
7429       l_text,
7430       NULL);
7431     --
7432     hr_utility.set_location ('hrstrdbi.insert_formula', 120);
7433     --
7434 l_text := '
7435 /* ------------------------------------------------------------------------
7436     NAME : PTO_ROLLING_CARRYOVER
7437     This formula is the seeded carryover formula for the rolling year accrual plan. Alth ough
7438     carryover has no meaning for a plan of this kind, we still require a formula for use by the absence
7439     screen. This formula simply returns calculation date, and zero.
7440    ---------------------------------------------------------------------*/
7441 
7442 INPUTS ARE
7443 Calculation_Date (date)
7444 
7445 Max_Carryover = 0
7446 Effective_Date = Calculation_Date
7447 Expiry_Date = Calculation_Date
7448 
7449 RETURN Max_Carryover, Effective_date, Expiry_Date
7450 ';
7451     --
7452     select formula_type_id
7453     into   l_ftype_id
7454     from   ff_formula_types
7455     where  formula_type_name = 'Accrual Carryover';
7456     --
7457     INSERT INTO ff_formulas_f
7458      (formula_id,
7459       effective_start_date,
7460       effective_end_date,
7461       business_group_id,
7462       legislation_code,
7463       formula_type_id,
7464       formula_name,
7465       description,
7466       formula_text,
7467       sticky_flag)
7468    VALUES
7469      (ff_formulas_s.nextval,
7470       to_date('01/01/0001','DD/MM/YYYY'),
7471       to_date('31/12/4712','DD/MM/YYYY'),
7472       NULL,
7473       NULL,
7474       l_ftype_id,
7475       'PTO_ROLLING_CARRYOVER',
7476       'Seeded carry over rolling formula for PTO accruals',
7477       l_text,
7478       NULL);
7479     --
7480     hr_utility.set_location ('hrstrdbi.insert_formula', 121);
7481     --
7482 l_text := '
7483 /* ------------------------------------------------------------------------
7484     NAME : PTO_ROLLING_PERIOD_ACCRUAL
7485     This formula calculates the amount of PTO accrued for a particular period. It is a seeded formula
7486     called by PTO_ROLLING_ACCRUAL.
7487    ----------------------------------------------------------------------*/
7488 
7489 /*-----------------------------------------------------------------------
7490     Get the global variables to be used in this formula
7491  ------------------------------------------------------------------------*/
7492 
7493 Continuous_Service_Date = get_date(''CONTINUOUS_SERVICE_DATE'')
7494 End_of_Term = get_date(''END_OF_TERM'')
7495 Beginning_of_Term = get_date(''BEGINNING_OF_TERM'')
7496 Total_Accrued_PTO = get_number(''TOTAL_ACCRUED_PTO'')
7497 Period_SD = get_date(''PERIOD_SD'')
7498 Period_ED = get_date(''PERIOD_ED'')
7499 Last_Period_SD = get_date(''LAST_PERIOD_SD'')
7500 Last_Period_ED = get_date(''LAST_PERIOD_ED'')
7501 
7502 Accrual_Rate = get_number(''ACCRUAL_RATE'')
7503 Accruing_Frequency = get_text(''ACCRUING_FREQUENCY'')
7504 Accruing_Multiplier = get_number(''ACCRUING_MULTIPLIER'')
7505 
7506 Ceiling = get_number(''CEILING'')
7507 
7508 /* ----------------------------------------------------------------------
7509     Calculate the Amount Accrued this Period
7510    ---------------------------------------------------------------------*/
7511 
7512 Period_Accrued_PTO = Accrual_Rate
7513 
7514 /* ----------------------------------------------------------------------
7515     Calculate any absence or bought/sold time etc. to be accounted for in this period.
7516    ---------------------------------------------------------------------*/
7517 
7518 Absence = GET_ABSENCE(Period_ED, Beginning_of_Term)
7519 CarryOver = GET_CARRY_OVER(Period_ED, Beginning_of_Term)
7520 Other = GET_OTHER_NET_CONTRIBUTION(Period_ED, Beginning_of_Term)
7521 
7522 Period_Others = CarryOver + Other - Absence
7523 
7524 /* ----------------------------------------------------------------------
7525     Now establish whether the Accrual this period has gone over the ceiling if one exists. If so,
7526     reduce the accrual by the amount over the ceiling.
7527    ----------------------------------------------------------------------*/
7528 
7529 IF (Ceiling > 0) THEN
7530     (
7531      IF (Total_Accrued_PTO + Period_Accrued_PTO + Period_Others > Ceiling) THEN
7532          (
7533           Amount_Over_Ceiling = Total_Accrued_PTO + Period_Accrued_PTO + Period_Others - Ceiling
7534           IF (Amount_Over_Ceiling > Period_Accrued_PTO) THEN
7535                (
7536                Period_Accrued_PTO = 0
7537                )
7538           ELSE
7539               (
7540                Period_Accrued_PTO = Period_Accrued_PTO - Amount_Over_Ceiling
7541               )
7542           )
7543      )
7544 
7545 /*---------------------------------------------------------------------
7546     Set the Running Total
7547   ---------------------------------------------------------------------*/
7548 
7549 E = set_number(''TOTAL_ACCRUED_PTO'',Total_Accrued_PTO + Period_Accrued_PTO)
7550 
7551 /* ---------------------------------------------------------------------
7552     Establish whether the current period is the last one, if so end the processing, otherwise get the
7553     next period
7554 ------------------------------------------------------------------------*/
7555 
7556 IF Period_SD >= Last_Period_SD THEN
7557     (
7558     Continue_Processing_Flag = ''N''
7559     )
7560 ELSE
7561    (
7562     E = GET_PERIOD_DATES(ADD_DAYS(Period_ED,1),
7563                                                Accruing_Frequency,
7564                                                End_of_Term,
7565                                                Accruing_Multiplier)
7566 
7567     E = set_date(''PERIOD_SD'', get_date(''PERIOD_START_DATE''))
7568     E = set_date(''PERIOD_ED'', get_date(''PERIOD_END_DATE''))
7569 
7570    Continue_Processing_Flag = ''Y''
7571    )
7572 
7573 Return Continue_Processing_Flag
7574 ';
7575     --
7576     select formula_type_id
7577     into   l_ftype_id
7578     from   ff_formula_types
7579     where  formula_type_name = 'Accrual Subformula';
7580     --
7581     INSERT INTO ff_formulas_f
7582      (formula_id,
7583       effective_start_date,
7584       effective_end_date,
7585       business_group_id,
7586       legislation_code,
7587       formula_type_id,
7588       formula_name,
7589       description,
7590       formula_text,
7591       sticky_flag)
7592    VALUES
7593      (ff_formulas_s.nextval,
7594       to_date('01/01/0001','DD/MM/YYYY'),
7595       to_date('31/12/4712','DD/MM/YYYY'),
7596       NULL,
7597       NULL,
7598       l_ftype_id,
7599       'PTO_ROLLING_PERIOD_ACCRUAL',
7600       'Seeded looping rolling formula for PTO accruals',
7601       l_text,
7602       NULL);
7603     --
7604     hr_utility.set_location ('hrstrdbi.insert_formula', 122);
7605     --
7606 l_text := '
7607 /* ------------------------------------------------------------------------
7608     NAME : PTO_ROLLING_ACCRUAL
7609     This seeded formula calculates the dates between which an assignment is to accrue time. It calls
7610     another formula (PTO_ROLLING_PERIOD_ACCRUAL) to calculate the gross accrual in each period.
7611     It is designed to be used with the carryover formula, PTO_ROLLING_CARRYOVER.
7612    ---------------------------------------------------------------------*/
7613 
7614 DEFAULT FOR ACP_INELIGIBILITY_PERIOD_TYPE IS ''CM''
7615 DEFAULT FOR ACP_INELIGIBILITY_PERIOD_LENGTH IS 0
7616 DEFAULT FOR ACP_CONTINUOUS_SERVICE_DATE IS ''4712/12/31 00:00:00'' (date)
7617 DEFAULT FOR ACP_ENROLLMENT_END_DATE IS ''4712/12/31 00:00:00'' (date)
7618 DEFAULT FOR ACP_TERMINATION_DATE IS ''4712/12/31 00:00:00'' (date)
7619 DEFAULT FOR ACP_ENROLLMENT_START_DATE IS ''4712/12/31 00:00:00'' (date)
7620 DEFAULT FOR ACP_SERVICE_START_DATE IS ''4712/12/31 00:00:00'' (date)
7621 
7622 INPUTS ARE
7623 Calculation_Date (date)
7624 
7625 E = SET_NUMBER(''CEILING'', 20)
7626 E = SET_NUMBER(''ACCRUAL_RATE'', 2)
7627 
7628 Accruing_Frequency = ''M''   /* Month */
7629 Accruing_Multiplier = 1
7630 
7631 E = SET_TEXT(''ACCRUING_FREQUENCY'', Accruing_Frequency)
7632 E = SET_NUMBER(''ACCRUING_MULTIPLIER'', Accruing_Multiplier)
7633 
7634 /* ------------------------------------------------------------------------
7635    Set the Continuous Service Global Variable to hire date, unless a continuous service date was
7636    entered for the employee.
7637   ------------------------------------------------------------------------ */
7638 
7639 IF (ACP_CONTINUOUS_SERVICE_DATE WAS DEFAULTED) THEN
7640     (
7641     E = set_date(''CONTINUOUS_SERVICE_DATE'', ACP_SERVICE_START_DATE)
7642     )
7643 ELSE
7644   (
7645     E = set_date(''CONTINUOUS_SERVICE_DATE'', ACP_CONTINUOUS_SERVICE_DATE)
7646   )
7647 
7648 Continuous_Service_Date = get_date(''CONTINUOUS_SERVICE_DATE'')
7649 
7650 /* ------------------------------------------------------------------------
7651    Set the Calculation_Date to the Termination Date, or enrollment end date, if either is not null
7652 -------------------------------------------------------------------------- */
7653 
7654 IF NOT (ACP_TERMINATION_DATE WAS DEFAULTED) OR
7655     NOT (ACP_ENROLLMENT_END_DATE WAS DEFAULTED) THEN
7656 (
7657   Early_End_Date = least(ACP_TERMINATION_DATE, ACP_ENROLLMENT_END_DATE)
7658 
7659   IF (Early_End_Date < Calculation_Date) THEN
7660   (
7661     Calculation_Date = Early_End_Date
7662   )
7663 )
7664 
7665 
7666 /* ------------------------------------------------------------------------
7667    Get the whole period prior which has Calculation Date as its end date.
7668    ------------------------------------------------------------------------ */
7669 
7670 E = GET_PERIOD_DATES(ADD_DAYS(Calculation_Date, 1),
7671                                            Accruing_Frequency,
7672                                            ADD_DAYS(Calculation_Date, 1),
7673                                            Accruing_Multiplier)
7674 
7675 Dummy_Period_SD  = get_date(''PERIOD_START_DATE'')
7676 
7677 E = SET_DATE(''END_OF_TERM'', Dummy_Period_SD)
7678 
7679 E = GET_PERIOD_DATES(ADD_DAYS(Dummy_Period_SD, -1),
7680                                            Accruing_Frequency,
7681                                            Dummy_period_SD,
7682                                            Accruing_Multiplier)
7683 
7684 Calculation_Period_SD  = get_date(''PERIOD_START_DATE'')
7685 Calculation_Period_ED = get_date(''PERIOD_END_DATE'')
7686 
7687 /*------------------------------------------------------------------------
7688    Get the first period to be considered within the rolling year
7689 ---------------------------------------------------------------------------*/
7690 
7691 First_Period_In_Year = Greatest(Add_Days(Add_Years(Calculation_Period_ED, -1), 1),
7692                                                         Continuous_Service_date)
7693 
7694 E = GET_PERIOD_DATES(First_period_in_year,
7695                                           Accruing_Frequency,
7696                                           Dummy_Period_SD,
7697                                           Accruing_Multiplier)
7698 
7699 First_Period_In_Year_SD  = get_date(''PERIOD_START_DATE'')
7700 First_Period_In_Year_ED = get_date(''PERIOD_END_DATE'')
7701 
7702 IF First_Period_In_year_SD < First_Period_In_Year THEN
7703 (
7704   E = GET_PERIOD_DATES(ADD_DAYS(First_period_in_year_ED, 1),
7705                                             Accruing_Frequency,
7706                                             Dummy_Period_SD,
7707                                             Accruing_Multiplier)
7708 
7709   First_Period_In_Year_SD  = get_date(''PERIOD_START_DATE'')
7710   First_Period_In_Year_ED = get_date(''PERIOD_END_DATE'')
7711 )
7712 
7713 E = set_date(''BEGINNING_OF_TERM'', First_Period_In_Year_SD)
7714 
7715 First_Eligible_To_Accrue_Date  = Continuous_Service_Date
7716 
7717 /*------------------------------------------------------------------------
7718    Determine the date on which accrued PTO may first be registered, i.e the date on which the
7719    Ineligibility Period expires
7720    ------------------------------------------------------------------------ */
7721 
7722 Accrual_Ineligibility_Expired_Date = First_Eligible_To_Accrue_Date
7723 
7724 IF ACP_INELIGIBILITY_PERIOD_LENGTH > 0 THEN
7725    (
7726    IF ACP_INELIGIBILITY_PERIOD_TYPE = ''BM'' THEN
7727       (
7728       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
7729                                                                                         ACP_INELIGIBILITY_PERIOD_LENGTH*2)
7730       )
7731    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''F'' THEN
7732       (
7733       Accrual_Ineligibility_Expired_Date = add_days(Continuous_Service_Date,
7734                                                                                    ACP_INELIGIBILITY_PERIOD_LENGTH*14)
7735       )
7736    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''CM'' THEN
7737       (
7738       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
7739                                                                                         ACP_INELIGIBILITY_PERIOD_LENGTH)
7740       )
7741    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''LM'' THEN
7742       (
7743       Accrual_Ineligibility_Expired_Date = add_days(Continuous_Service_Date,
7744                                                                                     ACP_INELIGIBILITY_PERIOD_LENGTH*28)
7745       )
7746    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''Q'' THEN
7747       (
7748       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
7749                                                                                         ACP_INELIGIBILITY_PERIOD_LENGTH*3)
7750       )
7751    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''SM'' THEN
7752       (
7753       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
7754                                                                                         ACP_INELIGIBILITY_PERIOD_LENGTH/2)
7755       )
7756    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''SY'' THEN
7757       (
7758       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
7759                                                                                         ACP_INELIGIBILITY_PERIOD_LENGTH*6)
7760       )
7761    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''W'' THEN
7762       (
7763       Accrual_Ineligibility_Expired_Date = add_days(Continuous_Service_Date,
7764                                                                                    ACP_INELIGIBILITY_PERIOD_LENGTH*7)
7765       )
7766    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''Y'' THEN
7767       (
7768       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
7769                                                                                         ACP_INELIGIBILITY_PERIOD_LENGTH*12)
7770       )
7771 
7772    IF Accrual_Ineligibility_Expired_Date > First_Eligible_To_Accrue_Date
7773    AND Calculation_Date < Accrual_Ineligibility_Expired_Date THEN
7774       (
7775       First_Eligible_To_Accrue_Date = Accrual_Ineligibility_Expired_Date
7776       )
7777    )
7778 
7779 /* ------------------------------------------------------------------------
7780    Get the first full period following the First_Eligible_To_Accrue_Date
7781    (if it falls on the beginning of the period then use that period)
7782 ------------------------------------------------------------------------- */
7783 
7784 IF First_Eligible_To_Accrue_Date > First_Period_In_Year_SD THEN
7785 (
7786   E = GET_PERIOD_DATES(First_Eligible_To_Accrue_Date,
7787                                              Accruing_Frequency,
7788                                              Dummy_Period_SD,
7789                                              Accruing_Multiplier)
7790 
7791   First_Eligible_To_Accrue_Period_SD  = get_date(''PERIOD_START_DATE'')
7792   First_Eligible_To_Accrue_Period_ED  = get_date(''PERIOD_END_DATE'')
7793 
7794   IF First_Eligible_To_Accrue_Date <> First_Eligible_To_Accrue_Period_SD THEN
7795   (
7796     E = GET_PERIOD_DATES(ADD_DAYS(First_Eligible_To_Accrue_Period_ED, 1),
7797                                               Accruing_Frequency,
7798                                               Dummy_Period_SD,
7799                                               Accruing_Multiplier)
7800 
7801     First_Eligible_To_Accrue_Period_SD  = get_date(''PERIOD_START_DATE'')
7802     First_Eligible_To_Accrue_Period_ED = get_date(''PERIOD_END_DATE'')
7803   )
7804 
7805   IF (First_Eligible_To_Accrue_Period_SD > Calculation_Period_ED) THEN
7806      (
7807        Total_Accrued_PTO = 0
7808        E = PUT_MESSAGE(''HR_52793_PTO_FML_ASG_INELIG'')
7809     )
7810 )
7811 ELSE
7812 (
7813   First_Eligible_To_Accrue_Period_SD  = First_Period_In_Year_SD
7814   First_Eligible_To_Accrue_Period_ED  = First_Period_In_Year_ED
7815 )
7816 
7817 /* ------------------------------------------------------------------------
7818    Determine the date on which PTO actually starts accruing based on Hire Date,
7819    Continuous Service Date and plan Enrollment Start Date. Remember, we have already determined
7820    whether to user hire date or CSD earlier in the formula.
7821    If this date is after the 1st period and the fisrt eligible date then establish the first full period
7822    after this date (if the Actual Start Date falls on the beginning of a period then use this period)
7823  ------------------------------------------------------------------------ */
7824 
7825 IF Continuous_Service_date = ACP_CONTINUOUS_SERVICE_DATE THEN
7826 (
7827   Actual_Accrual_Start_Date = Continuous_service_Date
7828 )
7829 ELSE
7830 (
7831   Actual_Accrual_Start_Date = greatest(Continuous_Service_Date,
7832                                        ACP_ENROLLMENT_START_DATE,
7833                                        First_Period_In_Year_SD)
7834 )
7835 
7836 /* -------------------------------------------------------------------------
7837        Determine the actual start of the accrual calculation
7838 -------------------------------------------------------------------------*/
7839 IF (Actual_Accrual_Start_Date > First_Eligible_To_Accrue_Period_SD AND
7840       Actual_Accrual_Start_Date > First_Period_In_Year_SD) THEN
7841     (
7842      E = GET_PERIOD_DATES(Actual_Accrual_Start_Date,
7843                                                 Accruing_Frequency,
7844                                                 Dummy_Period_SD,
7845                                                 Accruing_Multiplier)
7846 
7847      Accrual_Start_Period_SD = get_date(''PERIOD_START_DATE'')
7848      Accrual_Start_Period_ED = get_date(''PERIOD_END_DATE'')
7849 
7850      IF Accrual_start_period_SD <> Actual_Accrual_Start_Date THEN
7851      (
7852        E = GET_PERIOD_DATES(Add_Days(Accrual_Start_Period_ED, 1),
7853                                                   Accruing_Frequency,
7854                                                   Dummy_Period_SD,
7855                                                   Accruing_Multiplier)
7856 
7857        Accrual_Start_Period_SD = get_date(''PERIOD_START_DATE'')
7858        Accrual_Start_Period_ED = get_date(''PERIOD_END_DATE'')
7859      )
7860 
7861 /* -----------------------------------------------------------------
7862         If the Actual Accrual Period is after the Calculation Period then end the processing.
7863 ----------------------------------------------------------------- */
7864         IF (Accrual_Start_Period_SD > Calculation_Period_ED) THEN
7865             (
7866             Total_Accrued_PTO = 0
7867             E = PUT_MESSAGE(''HR_52797_PTO_FML_ACT_ACCRUAL'')
7868             )
7869      )
7870 ELSE IF (First_Eligible_To_Accrue_Period_SD > First_Period_In_Year_SD) THEN
7871      (
7872           Accrual_Start_Period_SD = First_Eligible_To_Accrue_Period_SD
7873           Accrual_Start_Period_ED = First_Eligible_To_Accrue_Period_ED
7874      )
7875 ELSE
7876     (
7877           Accrual_Start_Period_SD = First_Period_In_Year_SD
7878           Accrual_Start_Period_ED = First_Period_In_Year_ED
7879     )
7880 
7881  /* -------------------------------------------------------------------
7882        Now set up the information that will be used in when looping through the periods
7883 --------------------------------------------------------------------- */
7884 E = set_number(''TOTAL_ACCRUED_PTO'',0)
7885 
7886 IF Calculation_Date >= Accrual_Start_Period_ED THEN
7887 (
7888 E = set_date(''PERIOD_SD'',Accrual_Start_Period_SD)
7889 E = set_date(''PERIOD_ED'',Accrual_Start_Period_ED)
7890 E = set_date(''LAST_PERIOD_SD'',Calculation_Period_SD)
7891 E = set_date(''LAST_PERIOD_ED'',Calculation_Period_ED)
7892 
7893 E = LOOP_CONTROL(''PTO_ROLLING_PERIOD_ACCRUAL'')
7894 
7895 )
7896 
7897 Total_Accrued_PTO = get_number(''TOTAL_ACCRUED_PTO'')
7898 
7899 IF Accrual_Start_Period_SD <= Calculation_Period_SD THEN
7900 (
7901   Accrual_end_date = Calculation_Period_ED
7902 )
7903 
7904 Effective_Start_Date = Actual_Accrual_Start_Date
7905 Effective_End_Date = Calculation_Date
7906 
7907 IF Effective_Start_Date >= Effective_End_Date THEN
7908 (
7909   Effective_Start_Date = least(Effective_End_Date, Actual_Accrual_Start_Date)
7910 )
7911 
7912 RETURN Total_Accrued_PTO, Effective_start_date, Effective_end_date, Accrual_end_date
7913 ';
7914     --
7915     select formula_type_id
7916     into   l_ftype_id
7917     from   ff_formula_types
7918     where  formula_type_name = 'Accrual';
7919     --
7920     INSERT INTO ff_formulas_f
7921      (formula_id,
7922       effective_start_date,
7923       effective_end_date,
7924       business_group_id,
7925       legislation_code,
7926       formula_type_id,
7927       formula_name,
7928       description,
7929       formula_text,
7930       sticky_flag)
7931    VALUES
7932      (ff_formulas_s.nextval,
7933       to_date('01/01/0001','DD/MM/YYYY'),
7934       to_date('31/12/4712','DD/MM/YYYY'),
7935       NULL,
7936       NULL,
7937       l_ftype_id,
7938       'PTO_ROLLING_ACCRUAL',
7939       'Seeded top level rolling formula for PTO accruals',
7940       l_text,
7941       NULL);
7942     --
7943     hr_utility.set_location ('hrstrdbi.insert_formula', 123);
7944     --
7945 l_text := '
7946 /* ------------------------------------------------------------------------
7947     NAME : PTO_SIMPLE_CARRYOVER
7948     This formula is the seeded carryover folmula for our simple multiplier accrual plan
7949    ---------------------------------------------------------------------*/
7950 
7951 DEFAULT FOR ACP_CONTINUOUS_SERVICE_DATE IS ''4712/12/31 00:00:00'' (date)
7952 DEFAULT FOR ACP_SERVICE_START_DATE IS ''4712/12/31 00:00:00'' (date)
7953 
7954 INPUTS ARE
7955 Calculation_Date (date),
7956 Accrual_term (text)
7957 
7958 Effective_Date = to_date(''3105'' + to_char(Calculation_date, ''YYYY''), ''DDMMYYYY'')
7959 
7960 IF (Accrual_Term = ''CURRENT'') AND (Effective_Date < Calculation_Date) THEN
7961 (
7962   Effective_date = ADD_YEARS(Effective_Date, 1)
7963 )
7964 ELSE IF (Accrual_term = ''PREVIOUS'') AND (Effective_Date >= Calculation_Date) THEN
7965 (
7966   Effective_date = ADD_YEARS(Effective_Date, -1)
7967 )
7968 
7969 Expiry_Date = add_years(effective_date, 1)
7970 
7971 Max_carryover = 5
7972 Process = ''YES''
7973 
7974 RETURN Max_Carryover, Effective_date, Expiry_Date, Process
7975 
7976 ';
7977     --
7978     select formula_type_id
7979     into   l_ftype_id
7980     from   ff_formula_types
7981     where  formula_type_name = 'Accrual Carryover';
7982     --
7983     INSERT INTO ff_formulas_f
7984      (formula_id,
7985       effective_start_date,
7986       effective_end_date,
7987       business_group_id,
7988       legislation_code,
7989       formula_type_id,
7990       formula_name,
7991       description,
7992       formula_text,
7993       sticky_flag)
7994    VALUES
7995      (ff_formulas_s.nextval,
7996       to_date('01/01/0001','DD/MM/YYYY'),
7997       to_date('31/12/4712','DD/MM/YYYY'),
7998       NULL,
7999       NULL,
8000       l_ftype_id,
8001       'PTO_SIMPLE_CARRYOVER',
8002       'Seeded simple carryover formula for PTO accruals',
8003       l_text,
8004       NULL);
8005     --
8006     hr_utility.set_location ('hrstrdbi.insert_formula', 124);
8007     --
8008 l_text := '
8009 /* ------------------------------------------------------------------------
8010     NAME : PTO_SIMPLE_MULTIPLIER_PERIOD_ACCRUAL
8011     This formula calculates the amount of PTO accrued for a particular period
8012    ---------------------------------------------------------------------*/
8013 
8014 /*------------------------------------------------------------------------
8015     Get the global variable to be used in this formula
8016  ------------------------------------------------------------------------*/
8017 
8018 Continuous_Service_Date = get_date(''CONTINUOUS_SERVICE_DATE'')
8019 Total_Accrued_PTO = get_number(''TOTAL_ACCRUED_PTO'')
8020 Period_SD = get_date(''PERIOD_SD'')
8021 Period_ED = get_date(''PERIOD_ED'')
8022 Last_Period_SD = get_date(''LAST_PERIOD_SD'')
8023 Last_Period_ED = get_date(''LAST_PERIOD_ED'')
8024 
8025 Accrual_Rate = get_number(''ACCRUAL_RATE'')
8026 Accruing_Frequency = get_text(''ACCRUING_FREQUENCY'')
8027 Accruing_Multiplier = get_number(''ACCRUING_MULTIPLIER'')
8028 Beginning_of_Calculation_Year = get_date(''BEGINNING_OF_CALCULATION_YEAR'')
8029 
8030 Ceiling = get_number(''CEILING'')
8031 
8032 /* ----------------------------------------------------------------------
8033     Calculate the Amount Accrued this Period
8034    ---------------------------------------------------------------------*/
8035 
8036 Period_Accrued_PTO = Accrual_Rate
8037 
8038 /* ----------------------------------------------------------------------
8039     Calculate any absence or bought/sold time etc. to be accounted for in this period.
8040    ---------------------------------------------------------------------*/
8041 
8042 Absence = GET_ABSENCE(Period_ED, Beginning_of_Calculation_Year)
8043 CarryOver = GET_CARRY_OVER(Period_ED, Beginning_of_Calculation_Year)
8044 Other = GET_OTHER_NET_CONTRIBUTION(Period_ED, Beginning_of_Calculation_Year)
8045 
8046 Period_Others = CarryOver + Other - Absence
8047 
8048 /* ----------------------------------------------------------------------
8049     Now establish whether the Accrual this period has gone over the ceiling if one exists
8050    ----------------------------------------------------------------------*/
8051 
8052 IF (Ceiling > 0) THEN
8053     (
8054      IF (Total_Accrued_PTO + Period_Accrued_PTO + Period_Others > Ceiling) THEN
8055          (
8056           Amount_Over_Ceiling = Total_Accrued_PTO + Period_Accrued_PTO + Period_Others - Ceiling
8057           IF (Amount_Over_Ceiling > Period_Accrued_PTO) THEN
8058                (
8059                Period_Accrued_PTO = 0
8060                )
8061           ELSE
8062               (
8063                Period_Accrued_PTO = Period_Accrued_PTO - Amount_Over_Ceiling
8064               )
8065           )
8066      )
8067 
8068 /*---------------------------------------------------------------------
8069     Set the Running Total
8070   ---------------------------------------------------------------------*/
8071 
8072 E = set_number(''TOTAL_ACCRUED_PTO'',Total_Accrued_PTO + Period_Accrued_PTO)
8073 
8074 
8075 /* ----------------------------------------------------------------------
8076     Establish whether the current period is the last one, if so end the processing, otherwise get the
8077     next period
8078 ------------------------------------------------------------------------*/
8079 
8080 IF Period_SD = Last_Period_SD THEN
8081     (
8082     Continue_Processing_Flag = ''N''
8083     )
8084 ELSE
8085    (
8086     E = GET_PERIOD_DATES(ADD_DAYS(Period_ED,1),
8087                                                Accruing_Frequency,
8088                                                Beginning_of_Calculation_Year,
8089                                                Accruing_Multiplier)
8090 
8091     E = set_date(''PERIOD_SD'', get_date(''PERIOD_START_DATE''))
8092     E = set_date(''PERIOD_ED'', get_date(''PERIOD_END_DATE''))
8093 
8094    Continue_Processing_Flag = ''Y''
8095    )
8096 
8097 Return Continue_Processing_Flag
8098 ';
8099     --
8100     select formula_type_id
8101     into   l_ftype_id
8102     from   ff_formula_types
8103     where  formula_type_name = 'Accrual Subformula';
8104     --
8105     INSERT INTO ff_formulas_f
8106      (formula_id,
8107       effective_start_date,
8108       effective_end_date,
8109       business_group_id,
8110       legislation_code,
8111       formula_type_id,
8112       formula_name,
8113       description,
8114       formula_text,
8115       sticky_flag)
8116    VALUES
8117      (ff_formulas_s.nextval,
8118       to_date('01/01/0001','DD/MM/YYYY'),
8119       to_date('31/12/4712','DD/MM/YYYY'),
8120       NULL,
8121       NULL,
8122       l_ftype_id,
8123       'PTO_SIMPLE_PERIOD_ACCRUAL',
8124       'Seeded simple looping formula for PTO accruals',
8125       l_text,
8126       NULL);
8127     --
8128     hr_utility.set_location ('hrstrdbi.insert_formula', 125);
8129     --
8130 l_text := '
8131 /* ------------------------------------------------------------------------
8132     NAME : PTO_SIMPLE_MULTIPLIER
8133     This formula calculates the start and end dates for out simple multiplier.
8134    ---------------------------------------------------------------------*/
8135 
8136 DEFAULT FOR ACP_INELIGIBILITY_PERIOD_TYPE IS ''CM''
8137 DEFAULT FOR ACP_INELIGIBILITY_PERIOD_LENGTH IS 0
8138 DEFAULT FOR ACP_CONTINUOUS_SERVICE_DATE IS ''4712/12/31 00:00:00'' (date)
8139 DEFAULT FOR ACP_ENROLLMENT_END_DATE IS ''4712/12/31 00:00:00'' (date)
8140 DEFAULT FOR ACP_TERMINATION_DATE IS ''4712/12/31 00:00:00'' (date)
8141 DEFAULT FOR ACP_ENROLLMENT_START_DATE IS ''4712/12/31 00:00:00'' (date)
8142 DEFAULT FOR ACP_SERVICE_START_DATE IS ''4712/12/31 00:00:00'' (date)
8143 
8144 INPUTS ARE
8145 Calculation_Date (date)
8146 
8147 E = SET_NUMBER(''CEILING'', 20)
8148 E = SET_NUMBER(''ACCRUAL_RATE'', 2)
8149 
8150 Accruing_Frequency = ''M''   /* Month */
8151 Accruing_Multiplier = 1
8152 
8153 E = SET_TEXT(''ACCRUING_FREQUENCY'', Accruing_Frequency)
8154 E = SET_NUMBER(''ACCRUING_MULTIPLIER'', Accruing_Multiplier)
8155 
8156 Beginning_Of_Calculation_Year = to_date(''0106''||to_char(Calculation_Date,''YYYY''),''DDMMYYYY'')
8157 
8158 IF Beginning_Of_Calculation_Year > Calculation_Date THEN
8159 (
8160   Beginning_of_Calculation_Year = ADD_MONTHS(Beginning_Of_Calculation_Year, -12)
8161 )
8162 
8163 E = SET_DATE(''BEGINNING_OF_CALCULATION_YEAR'', Beginning_Of_Calculation_Year)
8164 
8165 E = GET_PERIOD_DATES(Beginning_of_Calculation_Year,
8166                                           Accruing_Frequency,
8167                                           Beginning_Of_Calculation_Year,
8168                                           Accruing_Multiplier)
8169 
8170 First_Period_SD = get_date(''PERIOD_START_DATE'')
8171 First_Period_ED = get_date(''PERIOD_END_DATE'')
8172 
8173 /* ------------------------------------------------------------------------
8174    Set the Calculation_Date to the Termination Date if not null
8175 -------------------------------------------------------------------------- */
8176 
8177 IF NOT (ACP_TERMINATION_DATE WAS DEFAULTED) OR
8178     NOT (ACP_ENROLLMENT_END_DATE WAS DEFAULTED) THEN
8179 (
8180   Early_End_Date = least(ACP_TERMINATION_DATE, ACP_ENROLLMENT_END_DATE)
8181 
8182   IF (Early_End_Date < First_Period_ED) THEN
8183   (
8184     Total_Accrued_PTO = 0
8185     E = PUT_MESSAGE(''HR_52794_PTO_FML_ASG_TER'')
8186    )
8187 
8188   IF (Early_End_Date < Calculation_Date) THEN
8189   (
8190     Calculation_Date = Early_End_Date
8191   )
8192 )
8193 
8194 /* ------------------------------------------------------------------------
8195    Get the last whole period prior to the Calculation Date and ensure that it is within the
8196    Year (if the Calculation Date is the End of a Period then use that period)
8197    ------------------------------------------------------------------------ */
8198 
8199 E = GET_PERIOD_DATES(Calculation_Date,
8200                                           Accruing_Frequency,
8201                                           Beginning_of_Calculation_Year,
8202                                           Accruing_Multiplier)
8203 
8204 Calculation_Period_SD  = get_date(''PERIOD_START_DATE'')
8205 Calculation_Period_ED = get_date(''PERIOD_END_DATE'')
8206 
8207 IF (Calculation_Date <> Calculation_Period_ED) THEN
8208     (
8209      E = GET_PERIOD_DATES(ADD_DAYS(Calculation_Period_SD,-1),
8210                                                 Accruing_Frequency,
8211                                                 Beginning_of_Calculation_Year,
8212                                                 Accruing_Multiplier)
8213 
8214     Calculation_Period_SD  = get_date(''PERIOD_START_DATE'')
8215     Calculation_Period_ED = get_date(''PERIOD_END_DATE'')
8216    )
8217 
8218 If (Calculation_Period_ED < First_Period_ED) THEN
8219    (
8220     Total_Accrued_PTO = 0
8221     E = PUT_MESSAGE(''HR_52795_PTO_FML_CALC_DATE'')
8222     )
8223 
8224 /* ------------------------------------------------------------------------
8225    Set the Continuous Service Global Variable, whilst also
8226    ensuring that the continuous service date is before the Calculation Period
8227   ------------------------------------------------------------------------ */
8228 
8229 IF (ACP_CONTINUOUS_SERVICE_DATE WAS DEFAULTED) THEN
8230     (
8231     E = set_date(''CONTINUOUS_SERVICE_DATE'', ACP_SERVICE_START_DATE)
8232     )
8233 ELSE IF(ACP_CONTINUOUS_SERVICE_DATE > Calculation_Period_SD) THEN
8234    (
8235     Total_Accrued_PTO = 0
8236     E = PUT_MESSAGE(''HR_52796_PTO_FML_CSD'')
8237     E = set_date(''CONTINUOUS_SERVICE_DATE'', ACP_CONTINUOUS_SERVICE_DATE)
8238    )
8239 ELSE
8240   (
8241     E = set_date(''CONTINUOUS_SERVICE_DATE'', ACP_CONTINUOUS_SERVICE_DATE)
8242   )
8243 
8244 Continuous_Service_Date = get_date(''CONTINUOUS_SERVICE_DATE'')
8245 
8246 First_Eligible_To_Accrue_Date  = Continuous_Service_Date
8247 
8248 /*------------------------------------------------------------------------
8249    Determine the date on which accrued PTo may first be registered, i.e the date on which the
8250    Ineligibility Period expires
8251    ------------------------------------------------------------------------ */
8252 
8253 Accrual_Ineligibility_Expired_Date = First_Eligible_To_Accrue_Date
8254 
8255 IF (ACP_INELIGIBILITY_PERIOD_LENGTH > 0) THEN
8256    (
8257    IF ACP_INELIGIBILITY_PERIOD_TYPE = ''BM'' THEN
8258       (
8259       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
8260                                                                                         ACP_INELIGIBILITY_PERIOD_LENGTH*2)
8261       )
8262    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''F'' THEN
8263       (
8264       Accrual_Ineligibility_Expired_Date = add_days(Continuous_Service_Date,
8265                                                                                    ACP_INELIGIBILITY_PERIOD_LENGTH*14)
8266       )
8267    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''CM'' THEN
8268       (
8269       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
8270                                                                                         ACP_INELIGIBILITY_PERIOD_LENGTH)
8271       )
8272    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''LM'' THEN
8273       (
8274       Accrual_Ineligibility_Expired_Date = add_days(Continuous_Service_Date,
8275                                                                                     ACP_INELIGIBILITY_PERIOD_LENGTH*28)
8276       )
8277    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''Q'' THEN
8278       (
8279       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
8280                                                                                         ACP_INELIGIBILITY_PERIOD_LENGTH*3)
8281       )
8282    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''SM'' THEN
8283       (
8284       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
8285                                                                                         ACP_INELIGIBILITY_PERIOD_LENGTH/2)
8286       )
8287    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''SY'' THEN
8288       (
8289       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
8290                                                                                         ACP_INELIGIBILITY_PERIOD_LENGTH*6)
8291       )
8292    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''W'' THEN
8293       (
8294       Accrual_Ineligibility_Expired_Date = add_days(Continuous_Service_Date,
8295                                                                                    ACP_INELIGIBILITY_PERIOD_LENGTH*7)
8296       )
8297    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''Y'' THEN
8298       (
8299       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
8300                                                                                         ACP_INELIGIBILITY_PERIOD_LENGTH*12)
8301       )
8302 
8303    IF Accrual_Ineligibility_Expired_Date > First_Eligible_To_Accrue_Date
8304    AND Calculation_Date < Accrual_Ineligibility_Expired_Date THEN
8305       (
8306       First_Eligible_To_Accrue_Date = Accrual_Ineligibility_Expired_Date
8307       )
8308    )
8309 
8310 /* ------------------------------------------------------------------------
8311    Get the first full period following the First_Eligible_To_Accrue_Date
8312    (if it falls on the beginning of the period then use that period)
8313 ------------------------------------------------------------------------- */
8314 
8315 IF First_Eligible_To_Accrue_Date > Beginning_Of_Calculation_Year THEN
8316 (
8317   E = GET_PERIOD_DATES(First_Eligible_To_Accrue_Date,
8318                                              Accruing_Frequency,
8319                                              Beginning_Of_Calculation_Year,
8320                                              Accruing_Multiplier)
8321 
8322   First_Eligible_To_Accrue_Period_SD  = get_date(''PERIOD_START_DATE'')
8323   First_Eligible_To_Accrue_Period_ED  = get_date(''PERIOD_END_DATE'')
8324 
8325   IF First_Eligible_To_Accrue_Date <> First_Eligible_To_Accrue_Period_SD THEN
8326       (
8327        E = GET_PERIOD_DATES(add_days(First_Eligible_To_Accrue_Period_ED,1),
8328                                                   Accruing_Frequency,
8329                                                   Beginning_Of_Calculation_Year,
8330                                                   Accruing_Multiplier)
8331 
8332        First_Eligible_To_Accrue_Period_SD  = get_date(''PERIOD_START_DATE'')
8333        First_Eligible_To_Accrue_Period_ED  = get_date(''PERIOD_END_DATE'')
8334        )
8335 
8336   IF (First_Eligible_To_Accrue_Period_SD > Calculation_Period_ED) THEN
8337      (
8338        Total_Accrued_PTO = 0
8339        E = PUT_MESSAGE(''HR_52793_PTO_FML_ASG_INELIG'')
8340     )
8341 )
8342 ELSE
8343 (
8344   First_Eligible_To_Accrue_Period_SD  = First_Period_SD
8345   First_Eligible_To_Accrue_Period_ED  = First_Period_ED
8346 )
8347 /* ------------------------------------------------------------------------
8348    Determine the date on which PTO actually starts accruing based on Hire Date,
8349    Continuous Service Date and plan Enrollment Start Date. Remember, we have already determined
8350    whether to user hire date or CSD earlier in the formula.
8351    If this date is after the 1st period and the fisrt eligible date then establish the first full period
8352    after this date (if the Actual Start Date falls on the beginning of a period then use this period)
8353  ------------------------------------------------------------------------ */
8354 
8355 IF Continuous_Service_date = ACP_CONTINUOUS_SERVICE_DATE THEN
8356 (
8357   Actual_Accrual_Start_Date = Continuous_service_Date
8358 )
8359 ELSE
8360 (
8361   Actual_Accrual_Start_Date = greatest(Continuous_Service_Date,
8362                                        ACP_ENROLLMENT_START_DATE,
8363                                        First_Period_SD)
8364 )
8365 
8366 /* -------------------------------------------------------------------------
8367        Determine the actual start of the accrual calculation
8368 -------------------------------------------------------------------------*/
8369 IF (Actual_Accrual_Start_Date > First_Period_SD AND
8370      Actual_Accrual_Start_Date > First_Eligible_To_Accrue_Period_SD) THEN
8371     (
8372      E = GET_PERIOD_DATES(Actual_Accrual_Start_Date,
8373                                                 Accruing_Frequency,
8374                                                 Beginning_Of_Calculation_Year,
8375                                                 Accruing_Multiplier)
8376 
8377      Accrual_Start_Period_SD = get_date(''PERIOD_START_DATE'')
8378      Accrual_Start_Period_ED = get_date(''PERIOD_END_DATE'')
8379 
8380      IF Actual_Accrual_Start_Date > Accrual_Start_Period_SD THEN
8381          (
8382           E = GET_PERIOD_DATES(add_days(Accrual_Start_Period_ED,1),
8383                                                      Accruing_Frequency,
8384                                                      Beginning_of_Calculation_Year,
8385                                                      Accruing_Multiplier)
8386 
8387           Accrual_Start_Period_SD = get_date(''PERIOD_START_DATE'')
8388           Accrual_Start_Period_ED = get_date(''PERIOD_END_DATE'')
8389          )
8390 
8391 /* -----------------------------------------------------------------
8392         If the Actual Acrual Period is after the Calculation Period then end the processing.
8393 ----------------------------------------------------------------- */
8394         IF (Accrual_Start_Period_SD > Calculation_Period_ED) THEN
8395             (
8396             Total_Accrued_PTO = 0
8397             E = PUT_MESSAGE(''HR_52797_PTO_FML_ACT_ACCRUAL'')
8398             )
8399      )
8400 
8401 ELSE IF (First_Eligible_To_Accrue_Period_SD > First_Period_SD) THEN
8402      (
8403           Accrual_Start_Period_SD = First_Eligible_To_Accrue_Period_SD
8404           Accrual_Start_Period_ED = First_Eligible_To_Accrue_Period_ED
8405      )
8406 ELSE
8407      (
8408           Accrual_Start_Period_SD = First_Period_SD
8409           Accrual_Start_Period_ED = First_Period_ED
8410     )
8411 
8412  /* -------------------------------------------------------------------
8413        Now set up the information that will be used in when looping through the periods
8414 --------------------------------------------------------------------- */
8415 IF Calculation_Period_ED >= Accrual_Start_Period_ED THEN
8416 (
8417 E = set_date(''PERIOD_SD'',Accrual_Start_Period_SD)
8418 E = set_date(''PERIOD_ED'',Accrual_Start_Period_ED)
8419 E = set_date(''LAST_PERIOD_SD'',Calculation_Period_SD)
8420 E = set_date(''LAST_PERIOD_ED'',Calculation_Period_ED)
8421 E = set_number(''TOTAL_ACCRUED_PTO'',0)
8422 
8423 E = LOOP_CONTROL(''PTO_SIMPLE_PERIOD_ACCRUAL'')
8424 
8425 Total_Accrued_PTO = get_number(''TOTAL_ACCRUED_PTO'')
8426 )
8427 
8428 IF Accrual_Start_Period_SD <= Calculation_Period_SD THEN
8429 (
8430   Accrual_end_date = Calculation_Period_ED
8431 )
8432 
8433 Effective_Start_Date = Accrual_Start_Period_SD
8434 Effective_End_Date = Calculation_Date
8435 
8436 IF Effective_Start_Date >= Effective_End_Date THEN
8437 (
8438   Effective_Start_Date = Effective_End_Date
8439 )
8440 
8441 RETURN Total_Accrued_PTO, Effective_start_date, Effective_end_date, Accrual_end_date
8442 ';
8443     --
8444     select formula_type_id
8445     into   l_ftype_id
8446     from   ff_formula_types
8447     where  formula_type_name = 'Accrual';
8448     --
8449     INSERT INTO ff_formulas_f
8450      (formula_id,
8451       effective_start_date,
8452       effective_end_date,
8453       business_group_id,
8454       legislation_code,
8455       formula_type_id,
8456       formula_name,
8457       description,
8458       formula_text,
8459       sticky_flag)
8460    VALUES
8461      (ff_formulas_s.nextval,
8462       to_date('01/01/0001','DD/MM/YYYY'),
8463       to_date('31/12/4712','DD/MM/YYYY'),
8464       NULL,
8465       NULL,
8466       l_ftype_id,
8467       'PTO_SIMPLE_MULTIPLIER',
8468       'Seeded simple top level formula for PTO accruals',
8469       l_text,
8470       NULL);
8471     --
8472 --
8473     hr_utility.set_location ('hrstrdbi.insert_formula', 126);
8474 --
8475 l_text := '
8476 /* ------------------------------------------------------------------------
8477     NAME : PTO_INELIGIBILITY_CALCULATION
8478    ---------------------------------------------------------------------*/
8479 
8480 DEFAULT FOR ACP_START IS ''HD''
8481 DEFAULT FOR ACP_INELIGIBILITY_PERIOD_TYPE IS ''CM''
8482 DEFAULT FOR ACP_INELIGIBILITY_PERIOD_LENGTH IS 0
8483 DEFAULT FOR ACP_CONTINUOUS_SERVICE_DATE IS ''4712/12/31 00:00:00'' (date)
8484 DEFAULT FOR ACP_ENROLLMENT_END_DATE IS ''4712/12/31 00:00:00'' (date)
8485 DEFAULT FOR ACP_TERMINATION_DATE IS ''4712/12/31 00:00:00'' (date)
8486 DEFAULT FOR ACP_ENROLLMENT_START_DATE IS ''4712/12/31 00:00:00'' (date)
8487 DEFAULT FOR ACP_SERVICE_START_DATE IS ''4712/12/31 00:00:00'' (date)
8488 
8489 INPUTS ARE
8490 Calculation_Date (date)
8491 
8492 /* ------------------------------------------------------------------------
8493    Set the Calculation_Date to the Termination Date / Enrollment end date if not defaulted
8494 ------------------------------------------------------------------------ */
8495 
8496 IF NOT (ACP_TERMINATION_DATE WAS DEFAULTED) OR
8497     NOT (ACP_ENROLLMENT_END_DATE WAS DEFAULTED) THEN
8498 (
8499   Early_End_Date = least(ACP_TERMINATION_DATE, ACP_ENROLLMENT_END_DATE)
8500 
8501 
8502   IF (Early_End_Date < Calculation_Date) THEN
8503   (
8504     Calculation_Date = Early_End_Date
8505   )
8506 )
8507 
8508 /* ------------------------------------------------------------------------
8509    Set the Continuous Service Global Variable, whilst also
8510    ensuring that the continuous service date is before the Calculation Period
8511   ------------------------------------------------------------------------ */
8512 
8513 IF (ACP_CONTINUOUS_SERVICE_DATE WAS DEFAULTED) THEN
8514     (
8515     Continuous_Service_Date = ACP_SERVICE_START_DATE
8516     )
8517 ELSE
8518   (
8519     Continuous_Service_Date = ACP_CONTINUOUS_SERVICE_DATE
8520   )
8521 
8522 IF (ACP_START = ''BOY'') THEN
8523     (
8524      First_Eligible_To_Accrue_Date =
8525          to_date(''01/01/''||to_char(add_days(add_months(Continuous_Service_Date, 12), -1), ''YYYY''),
8526                        ''DD/MM/YYYY'')
8527      )
8528 ELSE IF (ACP_START = ''PLUS_SIX_MONTHS'') THEN
8529     (
8530      First_Eligible_To_Accrue_Date = add_months(Continuous_Service_Date,6)
8531      )
8532 ELSE IF (ACP_START = ''HD'') THEN
8533     (
8534      First_Eligible_To_Accrue_Date  = Continuous_Service_Date
8535      )
8536 
8537 /*------------------------------------------------------------------------
8538    Determine the date on which accrued PTo may first be registered, i.e the date on which the
8539    Ineligibility Period expires
8540    ------------------------------------------------------------------------ */
8541 
8542 Accrual_Ineligibility_Expired_Date = First_Eligible_To_Accrue_Date
8543 
8544 IF (ACP_INELIGIBILITY_PERIOD_LENGTH > 0) THEN
8545    (
8546    IF ACP_INELIGIBILITY_PERIOD_TYPE = ''BM'' THEN
8547       (
8548       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
8549                                                      ACP_INELIGIBILITY_PERIOD_LENGTH*2)
8550       )
8551    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''F'' THEN
8552       (
8553       Accrual_Ineligibility_Expired_Date = add_days(Continuous_Service_Date,
8554                                                    ACP_INELIGIBILITY_PERIOD_LENGTH*14)
8555       )
8556    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''CM'' THEN
8557       (
8558       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
8559                                                      ACP_INELIGIBILITY_PERIOD_LENGTH)
8560       )
8561    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''LM'' THEN
8562       (
8563       Accrual_Ineligibility_Expired_Date = add_days(Continuous_Service_Date,
8564                                                    ACP_INELIGIBILITY_PERIOD_LENGTH*28)
8565       )
8566    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''Q'' THEN
8567       (
8568       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
8569                                                      ACP_INELIGIBILITY_PERIOD_LENGTH*3)
8570       )
8571    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''SM'' THEN
8572       (
8573       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
8574                                                      ACP_INELIGIBILITY_PERIOD_LENGTH/2)
8575       )
8576    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''SY'' THEN
8577       (
8578       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
8579                                                      ACP_INELIGIBILITY_PERIOD_LENGTH*6)
8580       )
8581    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''W'' THEN
8582       (
8583       Accrual_Ineligibility_Expired_Date = add_days(Continuous_Service_Date,
8584                                                    ACP_INELIGIBILITY_PERIOD_LENGTH*7)
8585       )
8586    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''Y'' THEN
8587       (
8588       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
8589                                                      ACP_INELIGIBILITY_PERIOD_LENGTH*12)
8590       )
8591 
8592    )
8593 
8594 IF Calculation_Date > greatest(Accrual_Ineligibility_Expired_Date,
8595 			       First_Eligible_To_Accrue_Date) THEN
8596 (
8597   Assignment_eligible = ''Y''
8598 )
8599 ELSE
8600 (
8601   Assignment_eligible = ''N''
8602 )
8603 
8604 RETURN Assignment_eligible
8605 ';
8606     --
8607     select formula_type_id
8608     into   l_ftype_id
8609     from   ff_formula_types
8610     where  formula_type_name = 'Accrual Ineligibility';
8611     --
8612     INSERT INTO ff_formulas_f
8613      (formula_id,
8614       effective_start_date,
8615       effective_end_date,
8616       business_group_id,
8617       legislation_code,
8618       formula_type_id,
8619       formula_name,
8620       description,
8621       formula_text,
8622       sticky_flag)
8623    VALUES
8624      (ff_formulas_s.nextval,
8625       to_date('01/01/0001','DD/MM/YYYY'),
8626       to_date('31/12/4712','DD/MM/YYYY'),
8627       NULL,
8628       NULL,
8629       l_ftype_id,
8630       'PTO_INELIGIBILITY_CALCULATION',
8631       'Seeded formula allowing paymix to cope with PTO accruals upgrade',
8632       l_text,
8633       NULL);
8634     --
8635     hr_utility.set_location ('hrstrdbi.insert_formula', 127);
8636     --
8637 l_text := ' /**************************************************************
8638 FORMULA NAME: CHECK_RATE_TYPE
8639 FORMULA TYPE:  User Table Validation
8640 DESCRIPTION:     Check rate type exists in GL_DAILY_CONVERSION_TYPES
8641 History
8642 02 Feb 1999     wkerr        First Created.
8643 ***************************************************************/
8644 INPUTS ARE entry_value (text)
8645 rt = check_rate_type(entry_value)
8646 IF rt = -1 THEN
8647 (
8648         formula_status = ''E''
8649         formula_message = ''Rate type does not exist.''
8650 )
8651 ELSE IF rt = -2 THEN
8652 (
8653         formula_status = ''E''
8654         formula_message = ''User Rate type is not allowed.''
8655 )
8656 ELSE
8657         formula_status = ''S''
8658 RETURN formula_status, formula_message
8659  ';
8660     --
8661     select formula_type_id
8662     into   l_ftype_id
8663     from   ff_formula_types
8664     where  formula_type_name = 'User Table Validation';
8665     --
8666     INSERT INTO ff_formulas_f
8667      (formula_id,
8668       effective_start_date,
8669       effective_end_date,
8670       business_group_id,
8671       legislation_code,
8672       formula_type_id,
8673       formula_name,
8674       description,
8675       formula_text,
8676       sticky_flag)
8677    VALUES
8678      (ff_formulas_s.nextval,
8679       to_date('01/01/0001','DD/MM/YYYY'),
8680       to_date('31/12/4712','DD/MM/YYYY'),
8681       NULL,
8682       NULL,
8683       l_ftype_id,
8684       'CHECK_RATE_TYPE',
8685       'Checks that conversion type exists',
8686       l_text,
8687       NULL);
8688     --
8689     hr_utility.set_location ('hrstrdbi.insert_formula', 128);
8690     --
8691 l_text := '/*******************************************************************
8692 FORMULA NAME: TEMPLATE_BIS_TRAINING_CONVERT_DURATION
8693 FORMULA TYPE: Quickpaint
8694 DESCRIPTION:  Converts a duration value to from one units to another
8695 --
8696 INPUTS:  from_duration_units
8697          to_duration_units
8698          from_duration
8699          activity_version_name
8700          event_name
8701 --
8702 RETURNS: to_duration
8703 --
8704 DBI Required:   None
8705 --
8706 Change History
8707 12 Mar 1999     Created       Barry Goodsell
8708 ********************************************************************/
8709 /* Updatable Values Section */
8710 
8711 /* Defaults Section */
8712 
8713 /* Inputs Section */
8714 INPUTS ARE from_duration_units (text)
8715 ,          from_duration (number)
8716 ,          to_duration_units (text)
8717 ,          activity_version_name (text)
8718 ,          event_name (text)
8719 
8720 /* Main Body of Formula */
8721 hours_per_day   = 8
8722 hours_per_week  = hours_per_day * 5
8723 hours_per_month = hours_per_week * 4.225
8724 hours_per_year  = hours_per_month * 12
8725 
8726 /* Calculate Duration in Hours */
8727 IF (from_duration_units = ''Y'') THEN
8728   hours = from_duration * hours_per_year
8729 ELSE IF (from_duration_units = ''M'') THEN
8730   hours = from_duration * hours_per_month
8731 ELSE IF (from_duration_units = ''W'') THEN
8732   hours = from_duration * hours_per_week
8733 ELSE IF (from_duration_units = ''D'') THEN
8734   hours = from_duration * hours_per_day
8735 ELSE IF (from_duration_units = ''H'') THEN
8736   hours = from_duration
8737 ELSE
8738   hours = 0
8739 
8740 /* Calculate Duration in desired units */
8741 IF (to_duration_units = ''H'') THEN
8742   to_duration = hours
8743 ELSE IF (to_duration_units = ''D'') THEN
8744   to_duration = hours / hours_per_day
8745 ELSE IF (to_duration_units = ''W'') THEN
8746   to_duration = hours / hours_per_week
8747 ELSE IF (to_duration_units = ''M'') THEN
8748   to_duration = hours / hours_per_month
8749 ELSE IF (to_duration_units = ''Y'') THEN
8750   to_duration = hours / hours_per_year
8751 ELSE
8752   to_duration = 0
8753 
8754 RETURN to_duration
8755 ';
8756     --
8757     select formula_type_id
8758     into   l_ftype_id
8759     from   ff_formula_types
8760     where  formula_type_name = 'QuickPaint';
8761     --
8762     INSERT INTO ff_formulas_f
8763      (formula_id,
8764       effective_start_date,
8765       effective_end_date,
8766       business_group_id,
8767       legislation_code,
8768       formula_type_id,
8769       formula_name,
8770       description,
8771       formula_text,
8772       sticky_flag)
8773    VALUES
8774      (ff_formulas_s.nextval,
8775       to_date('01/01/0001','DD/MM/YYYY'),
8776       to_date('31/12/4712','DD/MM/YYYY'),
8777       NULL,
8778       NULL,
8779       l_ftype_id,
8780       'TEMPLATE_BIS_TRAINING_CONVERT_DURATION',
8781       'Seeded formula to Calculate Training Duration',
8782       l_text,
8783       NULL);
8784     --
8785     hr_utility.set_location ('hrstrdbi.insert_formula', 128);
8786     --
8787 l_text := '/*
8788 FORMULA NAME: TEMPLATE_ABSENCE_DURATION
8789 FORMULA TYPE: Quickpaint
8790 DESCRIPTION:  Calculates the Employee''s Absence
8791               Duration in days or hours. The profile
8792               ''HR: Absence Duration Auto Overwrite''
8793               determines if an existing duration value
8794               can change automatically or not.
8795 --
8796 INPUTS:
8797              - days_or_hours: the units of the absence
8798              - date_start: the absence start date
8799              - date_end: the absence end date
8800              - time_start: the absence start time
8801              - time_end: the absence end time
8802 --
8803 DBI Required:
8804              - asg_start_time :  the assignment start time
8805              - asg_end_time: the assignment end time
8806              - asg_pos_start_time: the positon start time
8807              - asg_pos_end_time: the position end time
8808 --
8809 Change History
8810 01 Sep 99       jmoyano         Created
8811 10 Oct 01       dcasemor        end_day was being set to
8812                                 asg_start_time. Also allowed
8813                                 hours to be defaulted if no
8814                                 UOM is set and hours have been
8815                                 entered.
8816 */
8817 /* Main Body of Formula */
8818 INPUTS ARE days_or_hours(text),
8819            date_start (date),
8820            date_end (date),
8821            time_start (text),
8822            time_end (text)
8823 /* default values */
8824 DEFAULT FOR days_or_hours IS ''D''
8825 DEFAULT FOR time_start IS ''09:00''
8826 DEFAULT FOR time_end IS ''17:00''
8827 DEFAULT FOR date_start IS ''0001/01/01 00:00:00'' (DATE)
8828 DEFAULT FOR date_end IS ''4712/12/31 00:00:00'' (DATE)
8829 /* database items */
8830 DEFAULT FOR asg_start_time IS ''09:00''
8831 DEFAULT FOR asg_end_time IS ''17:00''
8832 DEFAULT FOR asg_pos_start_time IS ''09:00''
8833 DEFAULT FOR asg_pos_end_time IS ''17:00''
8834 /* local variables */
8835 error_or_warning = '' ''
8836 invalid_msg = '' ''
8837 duration = ''0''
8838 number_of_days = 0
8839 /* Defaults Section */
8840 /* default values for working day, these are only used if no
8841 working conditions can be found */
8842 begin_day = ''09:00''
8843 end_day = ''17:00''
8844 
8845 IF ((date_start WAS DEFAULTED) or (date_end WAS DEFAULTED)) then
8846   duration = ''0''
8847 else
8848 (
8849   number_of_days = days_between(date_end,date_start)
8850 /* absence in hours */
8851   IF days_or_hours = ''H''
8852   OR (days_or_hours WAS DEFAULTED
8853       AND time_start WAS NOT DEFAULTED
8854       AND time_end WAS NOT DEFAULTED) THEN
8855   (
8856 /* look for the assignment values*/
8857       If ((asg_start_time WAS NOT DEFAULTED) and
8858           (asg_end_time WAS NOT DEFAULTED)) then
8859       (
8860          begin_day = asg_start_time
8861          end_day = asg_end_time
8862       )
8863       else
8864       (
8865 /* look for the position values */
8866         if ((asg_pos_start_time  WAS NOT DEFAULTED) and
8867             (asg_pos_end_time WAS NOT DEFAULTED)) then
8868         (
8869            begin_day = asg_pos_start_time
8870            end_day = asg_pos_end_time
8871         )
8872       )
8873 /* compute hours per day */
8874       hours_per_day =  ((to_num(substr(end_day,1,2))*60 +
8875                          to_num(substr(end_day,4,2))) -
8876                         (to_num(substr(begin_day,1,2))*60 +
8877                          to_num(substr(begin_day,4,2)))) / 60
8878 /* absence takes place during the same day */
8879       IF number_of_days = 0 THEN
8880         duration = to_char(((to_num(substr(time_end,1,2))*60 +
8881                              to_num(substr(time_end,4,2))) -
8882                             (to_num(substr(time_start,1,2))*60 +
8883                              to_num(substr(time_start,4,2)))) / 60)
8884 /* more than one day */
8885       ELSE
8886         (
8887           duration = to_char(( (to_num(substr(time_end,1,2))*60 +
8888                                 to_num(substr(time_end,4,2))) -
8889                                (to_num(substr(begin_day,1,2))*60 +
8890                                 to_num(substr(begin_day,4,2))) +
8891                                (to_num(substr(end_day,1,2))*60 +
8892                                 to_num(substr(end_day,4,2))) -
8893                                (to_num(substr(time_start,1,2))*60 +
8894                                 to_num(substr(time_start,4,2))) ) / 60)
8895           duration = to_char(to_num(duration) +
8896                 (DAYS_BETWEEN(date_end,date_start) - 1)* hours_per_day)
8897         )
8898   )
8899 /* absence in days */
8900   ELSE
8901   (
8902     duration = to_char(DAYS_BETWEEN(date_end,date_start) + 1)
8903   )
8904 /* use of error messages:
8905   if to_num(duration) = 0 then
8906   (
8907     duration = ''FAILED''
8908     invalid_msg = ''HR_ABSENCE_CANNOT_BE_ZERO''
8909   )
8910 */
8911 )
8912 return duration, invalid_msg';
8913     --
8914     INSERT INTO ff_formulas_f
8915      (formula_id,
8916       effective_start_date,
8917       effective_end_date,
8918       business_group_id,
8919       legislation_code,
8920       formula_type_id,
8921       formula_name,
8922       description,
8923       formula_text,
8924       sticky_flag)
8925    VALUES
8926      (ff_formulas_s.nextval,
8927       to_date('01/01/0001','DD/MM/YYYY'),
8928       to_date('31/12/4712','DD/MM/YYYY'),
8929       NULL,
8930       NULL,
8931       l_ftype_id,
8932       'TEMPLATE_ABSENCE_DURATION',
8933       'formula template for absence duration calculation',
8934       l_text,
8935       NULL);
8936     --
8937     hr_utility.set_location ('hrstrdbi.insert_formula', 129);
8938 --
8939   l_text := '
8940 /******************************************************************************
8941  *
8942  * Formula Name : CALC_GROSSUP_PAY_VALUE
8943  *
8944  * Description  : Simple formula to calculate the gross pay based on the
8945  *                net pay and additional amount.
8946  *
8947  *  Change History
8948  *  --------------
8949  *
8950  *  Who        Date       Description
8951  *  ---------- ---------- --------------------------------------------------
8952  *  N.Bristow  24-NOV-99  Created.
8953  *
8954  *****************************************************************************/
8955 inputs are amount(number),
8956            additional_amount (number)
8957 payment_amount = amount + additional_amount
8958 return payment_amount';
8959     --
8960     select formula_type_id
8961     into   l_ftype_id
8962     from   ff_formula_types
8963     where  formula_type_name = 'Oracle Payroll';
8964     --
8965     INSERT INTO ff_formulas_f
8966      (formula_id,
8967       effective_start_date,
8968       effective_end_date,
8969       business_group_id,
8970       legislation_code,
8971       formula_type_id,
8972       formula_name,
8973       description,
8974       formula_text,
8975       sticky_flag)
8976    VALUES
8977      (ff_formulas_s.nextval,
8978       to_date('01/01/0001','DD/MM/YYYY'),
8979       to_date('31/12/4712','DD/MM/YYYY'),
8980       NULL,
8981       NULL,
8982       l_ftype_id,
8983       'CALC_GROSSUP_PAY_VALUE',
8984       'This formula is used in the grossup calculations',
8985       l_text,
8986       NULL);
8987     --
8988     hr_utility.set_location ('hrstrdbi.insert_formula', 130);
8989     --
8990   l_text := '
8991 /******************************************************************************
8992  *
8993  * Formula Name : DEFAULT_GROSSUP
8994  *
8995  * Description  : This formula calculates the additional amount needed
8996  *                on top of a specified Net pay, that is need to reach tje
8997  *                the gross amount (before deductions).
8998  *
8999  *  Change History
9000  *  --------------
9001  *
9002  *  Who        Date       Description
9003  *  ---------- ---------- --------------------------------------------------
9004  *  N.Bristow  24-NOV-99  Created.
9005  *
9006  *****************************************************************************/
9007 default for low_gross is -999
9008 default for high_gross is -999
9009 default for additional_amount is -999
9010 default for pay_value is -999
9011 inputs are amount(number),
9012            low_gross(number),
9013            high_gross(number),
9014            to_within(number),
9015            additional_amount(number),
9016            method(text),
9017            pay_value(number)
9018 stopper = 1
9019 /* Do any initialisation needed */
9020 if (low_gross = -999  or high_gross = -999) then
9021  ( if (low_gross = -999) then
9022       low_gross = amount
9023    if (high_gross = -999) then
9024       high_gross = amount*2
9025    dummy = ITERATION_INITIALISE(high_gross, low_gross, amount)
9026    /*
9027      Now get the initial guess
9028    */
9029    if method = ''INTERPOLATION'' then
9030    (
9031       new_guess = ITERATION_GET_INTERPOLATION(0)
9032    )
9033    else
9034    (
9035       new_guess = ITERATION_GET_BINARY(''INCREASE'')
9036    )
9037    additional_amount = new_guess - amount
9038 
9039    return low_gross, high_gross, additional_amount )
9040 /* Heres the real processing */
9041 grossup_balance = GROSSUP_AMOUNT
9042 if (additional_amount = grossup_balance) then
9043     return stopper
9044 if (additional_amount + to_within >= grossup_balance
9045     and additional_amount - to_within <= grossup_balance) then
9046 (
9047     remainder = additional_amount - grossup_balance
9048     return remainder, stopper
9049 )
9050 /*
9051 if (additional_amount + to_within >= grossup_balance) then
9052 (
9053     mesg = grossup_balance
9054     remainder = additional_amount - grossup_balance
9055     return remainder, stopper, grossup_balance
9056 )
9057 else
9058 (
9059    if (additional_amount - to_within <= grossup_balance) then
9060    (
9061     mesg = 2
9062       remainder = additional_amount - grossup_balance
9063       return remainder, stopper, mesg
9064    )
9065 )
9066 */
9067 
9068 /* OK we have not found the correct value so we have to guess a new value */
9069 
9070 if method = ''INTERPOLATION'' then
9071 (
9072    changer = additional_amount - grossup_balance
9073    new_guess = ITERATION_GET_INTERPOLATION(changer)
9074    low_gross = ITERATION_GET_LOW()
9075    high_gross = ITERATION_GET_HIGH()
9076    additional_amount = new_guess - amount
9077    additional_amount = round(additional_amount,2)
9078    return additional_amount, low_gross, high_gross, grossup_balance, changer
9079 )
9080 else
9081 (
9082    /* It must be binary method */
9083    if additional_amount < grossup_balance then
9084    (
9085        mesg = ''TO LOW Increasing''
9086        new_guess = ITERATION_GET_BINARY(''INCREASE'')
9087    )
9088    else
9089    (
9090        mesg = ''TO HIGH reducing''
9091        new_guess = ITERATION_GET_BINARY(''REDUCE'')
9092    )
9093 
9094    low_gross = ITERATION_GET_LOW()
9095    high_gross = ITERATION_GET_HIGH()
9096    additional_amount = new_guess - amount
9097    return additional_amount, low_gross, high_gross, mesg, grossup_balance
9098 )
9099 ';
9100     --
9101     select formula_type_id
9102     into   l_ftype_id
9103     from   ff_formula_types
9104     where  formula_type_name = 'Net to Gross';
9105     --
9106     INSERT INTO ff_formulas_f
9107      (formula_id,
9108       effective_start_date,
9109       effective_end_date,
9110       business_group_id,
9111       legislation_code,
9112       formula_type_id,
9113       formula_name,
9114       description,
9115       formula_text,
9116       sticky_flag)
9117    VALUES
9118      (ff_formulas_s.nextval,
9119       to_date('01/01/0001','DD/MM/YYYY'),
9120       to_date('31/12/4712','DD/MM/YYYY'),
9121       NULL,
9122       NULL,
9123       l_ftype_id,
9124       'DEFAULT_GROSSUP',
9125       'This formula is used in the grossup calculations',
9126       l_text,
9127       NULL);
9128     --
9129     hr_utility.set_location ('hrstrdbi.insert_formula', 131);
9130     --
9131   l_text := '
9132 /******************************************************************************
9133  *
9134  * Formula Name : QH_ASSIGNMENT_NAME
9135  *
9136  ******************************************************************************/
9137 DEFAULT FOR asg_job is '' ''
9138 DEFAULT FOR asg_org is '' ''
9139 
9140 assignment_name=asg_job||''.''||asg_org
9141 
9142 RETURN assignment_name';
9143     --
9144     select formula_type_id
9145     into   l_ftype_id
9146     from   ff_formula_types
9147     where  formula_type_name = 'QuickPaint';
9148     --
9149     INSERT INTO ff_formulas_f
9150      (formula_id,
9151       effective_start_date,
9152       effective_end_date,
9153       business_group_id,
9154       legislation_code,
9155       formula_type_id,
9156       formula_name,
9157       description,
9158       formula_text,
9159       sticky_flag)
9160    VALUES
9161      (ff_formulas_s.nextval,
9162       to_date('01/01/0001','DD/MM/YYYY'),
9163       to_date('31/12/4712','DD/MM/YYYY'),
9164       NULL,
9165       NULL,
9166       l_ftype_id,
9167       'QH_ASSIGNMENT_NAME',
9168       'This formula is used to get a job assignment_name',
9169       l_text,
9170       NULL);
9171     --
9172     hr_utility.set_location ('hrstrdbi.insert_formula', 132);
9173     --
9174     l_text := '
9175 /* ------------------------------------------------------------------------
9176     FORMULA NAME : PTO_ORACLE_SKIP_RULE
9177     FORMULA_TYPE : Element Skip
9178     DESCRIPTION  : Skip rule to prevent PTO accrual elements from being
9179                    processed more than once in a payroll period. This
9180                    formula is system assigned to the accrual plan elements
9181                    when a new accrual plan is created.
9182    ---------------------------------------------------------------------*/
9183 
9184   /* Defaults Section */
9185 
9186   default for SKIP_FLAG IS ''N''
9187 
9188   /* Formula Body */
9189 
9190   already_processed = ENTRY_PROCESSED_IN_PERIOD()
9191 
9192   IF already_processed = ''Y'' THEN
9193      (
9194       SKIP_FLAG = ''Y''
9195       mesg = ''Element skipped. Already processed this period.''
9196      )
9197   ELSE
9198      (
9199       SKIP_FLAG = ''N''
9200      )
9201 
9202 RETURN SKIP_FLAG';
9203     --
9204     select formula_type_id
9205     into   l_ftype_id
9206     from   ff_formula_types
9207     where  formula_type_name = 'Element Skip';
9208     --
9209      INSERT INTO ff_formulas_f
9210      (formula_id,
9211       effective_start_date,
9212       effective_end_date,
9213       business_group_id,
9214       legislation_code,
9215       formula_type_id,
9216       formula_name,
9217       description,
9218       formula_text,
9219       sticky_flag)
9220    VALUES
9221      (ff_formulas_s.nextval,
9222       to_date('01/01/0001','DD/MM/YYYY'),
9223       to_date('31/12/4712','DD/MM/YYYY'),
9224       NULL,
9225       NULL,
9226       l_ftype_id,
9227       'PTO_ORACLE_SKIP_RULE',
9228       'Skips PTO elements that have already been processed in the same period',
9229       l_text,
9230       NULL);
9231     --
9232     hr_utility.set_location ('hrstrdbi.insert_formula', 133);
9233     --
9234 l_text := '
9235 /* ------------------------------------------------------------------------
9236     NAME : PTO_PAYROLL_BALANCE_CALCULATION
9237     This formula calculates the dates between which an assignment is to accrue.
9238     It is based on PTO_PAYROLL_CALCULATION, but has been amended to allow its
9239     use with the payroll balance functionality.
9240    ---------------------------------------------------------------------*/
9241 
9242 DEFAULT FOR ACP_START IS ''HD''
9243 DEFAULT FOR ACP_INELIGIBILITY_PERIOD_TYPE IS ''CM''
9244 DEFAULT FOR ACP_INELIGIBILITY_PERIOD_LENGTH IS 0
9245 DEFAULT FOR ACP_CONTINUOUS_SERVICE_DATE IS ''4712/12/31 00:00:00'' (date)
9246 DEFAULT FOR ACP_ENROLLMENT_END_DATE IS ''4712/12/31 00:00:00'' (date)
9247 DEFAULT FOR ACP_TERMINATION_DATE IS ''4712/12/31 00:00:00'' (date)
9248 DEFAULT FOR ACP_ENROLLMENT_START_DATE IS ''4712/12/31 00:00:00'' (date)
9249 DEFAULT FOR ACP_SERVICE_START_DATE IS ''4712/12/31 00:00:00'' (date)
9250 
9251 default for Accrual_Start_Date is ''4712/12/31 00:00:00'' (date)
9252 default for Accrual_Latest_Balance is 0
9253 
9254 INPUTS ARE
9255 Calculation_Date (date),
9256 Accrual_Start_Date (date),
9257 Accrual_Latest_Balance
9258 
9259 E = CALCULATE_PAYROLL_PERIODS()
9260 
9261 /*-----------------------------------------------------------------------
9262    For the payroll year that spans the Calculation Date
9263    get the first days of the payroll year. If we have a latest balance,
9264    we use the Accrual Start Date.
9265   ----------------------------------------------------------------------- */
9266 
9267 Payroll_Year_First_Valid_Date = GET_DATE(''PAYROLL_YEAR_FIRST_VALID_DATE'')
9268 
9269 
9270 IF Accrual_Start_Date < Payroll_Year_First_Valid_Date THEN
9271 (
9272   Accrual_Start_Date = Payroll_Year_First_Valid_Date
9273 )
9274 
9275 
9276 IF NOT (Accrual_Start_Date WAS DEFAULTED) THEN
9277 (
9278   E = SET_DATE(''PAYROLL_YEAR_SD'', Accrual_Start_Date)
9279 )
9280 ELSE
9281 (
9282   E = SET_DATE(''PAYROLL_YEAR_SD'', Payroll_Year_First_Valid_Date)
9283 )
9284 
9285 
9286 /* ------------------------------------------------------------------------
9287    Set the Calculation_Date to the Termination Date / Enrollment end date if not defaulted
9288 -------------------------------------------------------------------------- */
9289 
9290 IF NOT (ACP_TERMINATION_DATE WAS DEFAULTED) OR
9291     NOT (ACP_ENROLLMENT_END_DATE WAS DEFAULTED) THEN
9292 (
9293   Early_End_Date = least(ACP_TERMINATION_DATE, ACP_ENROLLMENT_END_DATE)
9294 
9295   IF (Early_End_Date < Calculation_Date) THEN
9296   (
9297     Calculation_Date = Early_End_Date
9298   )
9299 )
9300 
9301 /* ------------------------------------------------------------------------
9302    Get the last whole payroll period prior to the Calculation Date and ensure that it is within the
9303    Payroll Year (if the Calculation Date is the End of a Period then use that period)
9304    ------------------------------------------------------------------------ */
9305 
9306 E = GET_PAYROLL_PERIOD(Calculation_Date)
9307 Calculation_Period_SD  = get_date(''PAYROLL_PERIOD_START_DATE'')
9308 Calculation_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
9309 
9310 IF (Calculation_Date <> Calculation_Period_ED) AND
9311    (Calculation_Period_SD > Payroll_Year_First_Valid_Date) THEN
9312     (
9313      E = GET_PAYROLL_PERIOD(ADD_DAYS(Calculation_Period_SD,-1))
9314     Calculation_Period_SD  = get_date(''PAYROLL_PERIOD_START_DATE'')
9315     Calculation_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
9316    )
9317 ELSE IF (Calculation_Period_SD = Payroll_Year_First_Valid_Date) AND
9318         (Calculation_Date <> Calculation_Period_ED) THEN
9319   (
9320     Calculation_Period_ED = ADD_DAYS(Calculation_Period_SD,-1)
9321   )
9322 
9323 
9324 /* ------------------------------------------------------------------------
9325    Set the Continuous Service Global Variable, whilst also
9326    ensuring that the continuous service date is before the Calculation Period
9327   ------------------------------------------------------------------------ */
9328 
9329 IF (ACP_CONTINUOUS_SERVICE_DATE WAS DEFAULTED) THEN
9330     (
9331     E = set_date(''CONTINUOUS_SERVICE_DATE'', ACP_SERVICE_START_DATE)
9332     )
9333 ELSE IF(ACP_CONTINUOUS_SERVICE_DATE > Calculation_Period_SD) THEN
9334    (
9335     Total_Accrued_PTO = 0
9336     E = PUT_MESSAGE(''HR_52796_PTO_FML_CSD'')
9337     E = set_date(''CONTINUOUS_SERVICE_DATE'', ACP_CONTINUOUS_SERVICE_DATE)
9338    )
9339 ELSE
9340   (
9341     E = set_date(''CONTINUOUS_SERVICE_DATE'', ACP_CONTINUOUS_SERVICE_DATE)
9342   )
9343 
9344 /* ------------------------------------------------------------------------
9345    Determine the Accrual Start Rule and modify the start date of the accrual calculation accordingly
9346 
9347    N.B. In this calculation the Accrual Start Rule determines the date from which a person may first accrue
9348    PTO. The Ineligibility Rule determines the period of time during which the PTO is not registered.
9349    Once this date has passed the accrual is registered from the date determined by the Accrual Start Rule.
9350  ------------------------------------------------------------------------ */
9351 
9352 Continuous_Service_Date = get_date(''CONTINUOUS_SERVICE_DATE'')
9353 
9354 IF (ACP_START = ''BOY'') THEN
9355     (
9356      First_Eligible_To_Accrue_Date =
9357          to_date(''01/01/''||to_char(add_months(Continuous_Service_Date, 12), ''YYYY''),
9358                  ''DD/MM/YYYY'')
9359      )
9360 ELSE IF (ACP_START = ''PLUS_SIX_MONTHS'') THEN
9361     (
9362      First_Eligible_To_Accrue_Date = add_months(Continuous_Service_Date,6)
9363      )
9364 ELSE IF (ACP_START = ''HD'') THEN
9365     (
9366      First_Eligible_To_Accrue_Date  = Continuous_Service_Date
9367      )
9368 
9369 /*------------------------------------------------------------------------
9370    Determine the date on which accrued PTo may first be registered, i.e the date on which the
9371    Ineligibility Period expires
9372    ------------------------------------------------------------------------ */
9373 
9374 Accrual_Ineligibility_Expired_Date = First_Eligible_To_Accrue_Date
9375 
9376 IF (ACP_START <> ''PLUS_SIX_MONTHS'' AND
9377      ACP_INELIGIBILITY_PERIOD_LENGTH > 0) THEN
9378    (
9379    IF ACP_INELIGIBILITY_PERIOD_TYPE = ''BM'' THEN
9380       (
9381       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
9382                                                     ACP_INELIGIBILITY_PERIOD_LENGTH*2)
9383       )
9384    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''F'' THEN
9385       (
9386       Accrual_Ineligibility_Expired_Date = add_days(Continuous_Service_Date,
9387                                                     ACP_INELIGIBILITY_PERIOD_LENGTH*14)
9388       )
9389    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''CM'' THEN
9390       (
9391       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
9392                                                       ACP_INELIGIBILITY_PERIOD_LENGTH)
9393       )
9394    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''LM'' THEN
9395       (
9396       Accrual_Ineligibility_Expired_Date = add_days(Continuous_Service_Date,
9397                                                   ACP_INELIGIBILITY_PERIOD_LENGTH*28)
9398       )
9399    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''Q'' THEN
9400       (
9401       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
9402                                                       ACP_INELIGIBILITY_PERIOD_LENGTH*3)
9403       )
9404    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''SM'' THEN
9405       (
9406       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
9407                                                       ACP_INELIGIBILITY_PERIOD_LENGTH/2)
9408       )
9409    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''SY'' THEN
9410       (
9411       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
9412                                                       ACP_INELIGIBILITY_PERIOD_LENGTH*6)
9413       )
9414    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''W'' THEN
9415       (
9416       Accrual_Ineligibility_Expired_Date = add_days(Continuous_Service_Date,
9417                                                     ACP_INELIGIBILITY_PERIOD_LENGTH*7)
9418       )
9419    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''Y'' THEN
9420       (
9421       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
9422                                                       ACP_INELIGIBILITY_PERIOD_LENGTH*12)
9423       )
9424 
9425    IF Accrual_Ineligibility_Expired_Date > First_Eligible_To_Accrue_Date
9426    AND Calculation_Date < Accrual_Ineligibility_Expired_Date THEN
9427       (
9428       First_Eligible_To_Accrue_Date = Accrual_Ineligibility_Expired_Date
9429       )
9430    )
9431 
9432 
9433 /* ----------------------------------------------------------------------
9434   If the employee is eligible to accrue before the start of this year,
9435   we must get the period dates for the first period of the year.
9436   Otherwise, we do not need these dates, as we will never accrue that
9437   far back.
9438 ----------------------------------------------------------------------- */
9439 
9440 IF (not Accrual_Start_Date was defaulted) AND
9441    ((Calculation_Date < Accrual_Ineligibility_Expired_Date) OR
9442     (Accrual_Start_Date > Accrual_Ineligibility_Expired_Date)) THEN
9443 (
9444 
9445 /*
9446  * This function checks for unprocessed plan element entries, and
9447  * returns the EE effective start date of the earliest it finds. This may
9448  * be useful if we amend the design to process a partial year starting at
9449  * this date.
9450  *
9451  * At the moment, however, we simply recalculate for the entire plan term
9452  * in these circumstances, so Adjusted_Start_Date is never used
9453  */
9454 
9455   Adjusted_Start_Date = Get_Start_Date(Accrual_Start_Date,
9456                                        Payroll_Year_First_Valid_Date)
9457 
9458   IF (Adjusted_Start_Date < Accrual_Start_Date) THEN
9459   (
9460     Process_Full_Term = ''Y''
9461   )
9462   ELSE
9463   (
9464     Process_Full_Term = ''N''
9465   )
9466 )
9467 ELSE
9468 (
9469   Process_Full_Term = ''Y''
9470 )
9471 
9472 Latest_Balance = 0
9473 
9474 IF (Process_Full_Term = ''N'') AND
9475    (Accrual_Start_Date >= First_Eligible_To_Accrue_Date) THEN
9476 (
9477   E = GET_PAYROLL_PERIOD(Adjusted_Start_Date)
9478   Payroll_Year_1st_Period_SD = get_date(''PAYROLL_PERIOD_START_DATE'')
9479   Payroll_Year_1st_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
9480 
9481   Latest_Balance = Accrual_Latest_Balance
9482   Effective_Start_Date = Adjusted_Start_Date
9483 
9484   IF First_Eligible_To_Accrue_Date > Payroll_Year_1st_Period_SD THEN
9485   (
9486      E = GET_PAYROLL_PERIOD(ADD_DAYS(Payroll_Year_1st_Period_ED, 1))
9487 
9488     Payroll_Year_1st_Period_SD = get_date(''PAYROLL_PERIOD_START_DATE'')
9489     Payroll_Year_1st_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
9490   )
9491 
9492 )
9493 ELSE IF First_Eligible_To_Accrue_Date <= Payroll_Year_First_Valid_Date THEN
9494 (
9495   IF (not Accrual_Start_Date was defaulted) THEN
9496   (
9497     Latest_Balance = Accrual_Latest_Balance
9498   )
9499   ELSE
9500   (
9501     Latest_Balance = 0
9502   )
9503 
9504   E = GET_PAYROLL_PERIOD(Payroll_Year_First_Valid_Date)
9505 
9506   Payroll_Year_1st_Period_SD = get_date(''PAYROLL_PERIOD_START_DATE'')
9507   Payroll_Year_1st_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
9508 
9509   IF Payroll_Year_1st_Period_SD <> Payroll_Year_First_Valid_Date THEN
9510   (
9511      E = GET_PAYROLL_PERIOD(ADD_DAYS(Payroll_Year_1st_Period_ED, 1))
9512 
9513     Payroll_Year_1st_Period_SD = get_date(''PAYROLL_PERIOD_START_DATE'')
9514     Payroll_Year_1st_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
9515   )
9516 
9517   Effective_Start_Date = Payroll_Year_First_Valid_Date
9518 )
9519 ELSE
9520 (
9521   /* ------------------------------------------------------------------------
9522    Get the first full payroll period following the First_Eligible_To_Accrue_Date
9523    (if it falls on the beginning of the period then use that period)
9524   ------------------------------------------------------------------------- */
9525   IF (not Accrual_Start_Date was defaulted) THEN
9526   (
9527     Latest_Balance = Accrual_Latest_Balance
9528   )
9529   ELSE
9530   (
9531     Latest_Balance = 0
9532   )
9533 
9534   E = GET_PAYROLL_PERIOD(First_Eligible_To_Accrue_Date )
9535   First_Eligible_To_Accrue_Period_SD  = get_date(''PAYROLL_PERIOD_START_DATE'')
9536   First_Eligible_To_Accrue_Period_ED  = get_date(''PAYROLL_PERIOD_END_DATE'')
9537 
9538   IF First_Eligible_To_Accrue_Date <> First_Eligible_To_Accrue_Period_SD THEN
9539   (
9540     E = GET_PAYROLL_PERIOD(add_days(First_Eligible_To_Accrue_Period_ED,1))
9541     First_Eligible_To_Accrue_Period_SD  = get_date(''PAYROLL_PERIOD_START_DATE'')
9542     First_Eligible_To_Accrue_Period_ED  = get_date(''PAYROLL_PERIOD_END_DATE'')
9543    )
9544 
9545   IF (First_Eligible_To_Accrue_Period_SD > Calculation_Period_ED) THEN
9546   (
9547     Total_Accrued_PTO = 0
9548     E = PUT_MESSAGE(''HR_52793_PTO_FML_ASG_INELIG'')
9549   )
9550 
9551   Payroll_Year_1st_Period_SD = First_Eligible_To_Accrue_Period_SD
9552   Payroll_Year_1st_Period_ED = First_Eligible_To_Accrue_Period_ED
9553 
9554   Effective_Start_Date = First_Eligible_To_Accrue_Date
9555 )
9556 
9557   Effective_Start_Date = GREATEST(Effective_Start_Date, ACP_ENROLLMENT_START_DATE)
9558 
9559 /* -----------------------------------------------------------------
9560   Output messages based on calculated date
9561 ----------------------------------------------------------------- */
9562 
9563 IF (Early_End_Date < Payroll_Year_1st_Period_ED) THEN
9564 (
9565   Total_Accrued_PTO = 0
9566   E = PUT_MESSAGE(''HR_52794_PTO_FML_ASG_TER'')
9567 )
9568 
9569 If (Calculation_Period_ED < Payroll_Year_1st_Period_ED) THEN
9570 (
9571   Total_Accrued_PTO = 0
9572   E = PUT_MESSAGE(''HR_52795_PTO_FML_CALC_DATE'')
9573 )
9574 
9575 
9576 
9577 /* ------------------------------------------------------------------------
9578    Determine the date on which PTO actually starts accruing based on Hire Date,
9579    Continuous Service Date and plan Enrollment Start Date. Remember, we have
9580    already determined whether to user hire date or CSD earlier in the formula.
9581    If this date is after the 1st period and the fisrt eligible date then
9582    establish the first full payroll period after this date
9583    (if the Actual Start Date falls on the beginning of a payroll period then
9584    use this period)
9585  ------------------------------------------------------------------------ */
9586 
9587 
9588   Enrollment_Start_Date = ACP_ENROLLMENT_START_DATE
9589 
9590   Actual_Accrual_Start_Date = GREATEST(Enrollment_Start_Date,
9591                                        Continuous_Service_Date,
9592                                        Payroll_Year_1st_Period_SD)
9593 
9594 /* -------------------------------------------------------------------------
9595        Determine the actual start of the accrual calculation
9596 -------------------------------------------------------------------------*/
9597 IF (Actual_Accrual_Start_Date > Payroll_Year_1st_Period_SD AND
9598      Actual_Accrual_Start_Date > First_Eligible_To_Accrue_Date) THEN
9599     (
9600      E = GET_PAYROLL_PERIOD(Actual_Accrual_Start_Date)
9601 
9602      Accrual_Start_Period_SD = get_date(''PAYROLL_PERIOD_START_DATE'')
9603      Accrual_Start_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
9604 
9605      IF Actual_Accrual_Start_Date > Accrual_Start_Period_SD THEN
9606          (
9607           E = GET_PAYROLL_PERIOD(add_days(Accrual_Start_Period_ED,1))
9608 
9609           Accrual_Start_Period_SD = get_date(''PAYROLL_PERIOD_START_DATE'')
9610           Accrual_Start_Period_ED = get_date(''PAYROLL_PERIOD_END_DATE'')
9611          )
9612 
9613 /* -----------------------------------------------------------------
9614         If the Actual Acrual Period is after the Calculation Period then end the processing.
9615 ----------------------------------------------------------------- */
9616         IF (Accrual_Start_Period_SD > Calculation_Period_ED) THEN
9617             (
9618             Total_Accrued_PTO = 0
9619             E = PUT_MESSAGE(''HR_52797_PTO_FML_ACT_ACCRUAL'')
9620             )
9621      )
9622 
9623 ELSE IF (First_Eligible_To_Accrue_Date > Payroll_Year_1st_Period_SD) THEN
9624      (
9625           Accrual_Start_Period_SD = First_Eligible_To_Accrue_Period_SD
9626           Accrual_Start_Period_ED = First_Eligible_To_Accrue_Period_ED
9627      )
9628 ELSE
9629     (
9630           Accrual_Start_Period_SD = Payroll_Year_1st_Period_SD
9631           Accrual_Start_Period_ED = Payroll_Year_1st_Period_ED
9632     )
9633 
9634  /* -------------------------------------------------------------------
9635        Now set up the information that will be used in when looping
9636        through the payroll periods
9637 --------------------------------------------------------------------- */
9638 
9639 IF Calculation_Period_ED >= Accrual_Start_Period_ED THEN
9640 (
9641 E = set_date(''PERIOD_SD'',Accrual_Start_Period_SD)
9642 E = set_date(''PERIOD_ED'',Accrual_Start_Period_ED)
9643 E = set_date(''LAST_PERIOD_SD'',Calculation_Period_SD)
9644 E = set_date(''LAST_PERIOD_ED'',Calculation_Period_ED)
9645 
9646 IF (Process_Full_Term = ''N'') THEN
9647 (
9648   E = set_number(''TOTAL_ACCRUED_PTO'', Latest_Balance)
9649 )
9650 ELSE
9651 (
9652   E = set_number(''TOTAL_ACCRUED_PTO'', 0)
9653 )
9654 
9655 /* -------------------------------------------------------------------
9656        Initialize Band Information
9657 -------------------------------------------------------------------- */
9658 
9659 E = set_number(''ANNUAL_RATE'', 0)
9660 E = set_number(''UPPER_LIMIT'', 0)
9661 E = set_number(''CEILING'', 0)
9662 
9663 E = LOOP_CONTROL(''PTO_PAYROLL_PERIOD_ACCRUAL'')
9664 
9665 Total_Accrued_PTO = get_number(''TOTAL_ACCRUED_PTO'') - Latest_Balance
9666 )
9667 
9668 IF Accrual_Start_Period_SD <= Calculation_Period_SD THEN
9669 (
9670   Accrual_end_date = Calculation_Period_ED
9671 )
9672 
9673 IF Process_Full_Term = ''Y'' AND
9674    Effective_Start_Date > Actual_Accrual_Start_Date THEN
9675 (
9676   Effective_Start_Date = Actual_Accrual_Start_Date
9677 )
9678 
9679 Effective_End_Date = Calculation_Date
9680 
9681 IF Effective_Start_Date >= Effective_End_Date THEN
9682 (
9683   Effective_Start_Date = least(Effective_End_Date, Accrual_Start_Period_SD)
9684 )
9685 
9686 RETURN Total_Accrued_PTO, Effective_start_date, Effective_end_date, Accrual_end_date
9687 ';
9688     --
9689     select formula_type_id
9690     into   l_ftype_id
9691     from   ff_formula_types
9692     where  formula_type_name = 'Accrual';
9693     --
9694      INSERT INTO ff_formulas_f
9695      (formula_id,
9696       effective_start_date,
9697       effective_end_date,
9698       business_group_id,
9699       legislation_code,
9700       formula_type_id,
9701       formula_name,
9702       description,
9703       formula_text,
9704       sticky_flag)
9705    VALUES
9706      (ff_formulas_s.nextval,
9707       to_date('01/01/0001','DD/MM/YYYY'),
9708       to_date('31/12/4712','DD/MM/YYYY'),
9709       NULL,
9710       NULL,
9711       l_ftype_id,
9712       'PTO_PAYROLL_BALANCE_CALCULATION',
9713       'Seeded top level payroll formula for PTO accruals',
9714       l_text,
9715       NULL);
9716     --
9717     hr_utility.set_location ('hrstrdbi.insert_formula', 134);
9718     --
9719 l_text := '
9720 /* ------------------------------------------------------------------------
9721     NAME : PTO_SIMPLE_BALANCE_MULTIPLIER
9722     This formula calculates the start and end dates for out simple multiplier.
9723     This formula calculates the dates between which an assignment is to accrue.
9724     It is based on PTO_SIMPLE_MULTIPLIER, but has been amended to allow its
9725     use in the new payroll balance functionality. It may not be used out of the box
9726     but must be amended, according to the documentaion, by inserting the
9727     name of the database item which was created with your defined balance.
9728     This defined balance should have been created immediately after the
9729     accrual plan.
9730    ---------------------------------------------------------------------*/
9731 
9732 DEFAULT FOR ACP_INELIGIBILITY_PERIOD_TYPE IS ''CM''
9733 DEFAULT FOR ACP_INELIGIBILITY_PERIOD_LENGTH IS 0
9734 DEFAULT FOR ACP_CONTINUOUS_SERVICE_DATE IS ''4712/12/31 00:00:00'' (date)
9735 DEFAULT FOR ACP_ENROLLMENT_END_DATE IS ''4712/12/31 00:00:00'' (date)
9736 DEFAULT FOR ACP_TERMINATION_DATE IS ''4712/12/31 00:00:00'' (date)
9737 DEFAULT FOR ACP_ENROLLMENT_START_DATE IS ''4712/12/31 00:00:00'' (date)
9738 DEFAULT FOR ACP_SERVICE_START_DATE IS ''4712/12/31 00:00:00'' (date)
9739 
9740 default for Accrual_Start_Date is ''4712/12/31 00:00:00'' (date)
9741 default for Accrual_Latest_Balance is 0
9742 
9743 INPUTS ARE
9744 Calculation_Date (date),
9745 Accrual_Start_Date (date),
9746 Accrual_Latest_Balance
9747 
9748 E = SET_NUMBER(''CEILING'', 20)
9749 E = SET_NUMBER(''ACCRUAL_RATE'', 2)
9750 
9751 Accruing_Frequency = ''M''   /* Month */
9752 Accruing_Multiplier = 1
9753 
9754 E = SET_TEXT(''ACCRUING_FREQUENCY'', Accruing_Frequency)
9755 E = SET_NUMBER(''ACCRUING_MULTIPLIER'', Accruing_Multiplier)
9756 
9757 Beginning_Of_Calculation_Year = to_date(''0106''||to_char(Calculation_Date,''YYYY''),
9758                                         ''DDMMYYYY'')
9759 
9760 IF (Beginning_Of_Calculation_Year > Calculation_Date) THEN
9761 (
9762   Beginning_of_Calculation_Year = ADD_MONTHS(Beginning_Of_Calculation_Year, -12)
9763 )
9764 
9765 IF Accrual_Start_Date < Beginning_Of_Calculation_Year THEN
9766 (
9767   Accrual_Start_Date = Beginning_Of_Calculation_Year
9768 )
9769 
9770 E = SET_DATE(''BEGINNING_OF_CALCULATION_YEAR'', Beginning_Of_Calculation_Year)
9771 
9772 E = GET_PERIOD_DATES(Beginning_of_Calculation_Year,
9773                      Accruing_Frequency,
9774                      Beginning_Of_Calculation_Year,
9775                      Accruing_Multiplier)
9776 
9777 First_Period_SD = get_date(''PERIOD_START_DATE'')
9778 First_Period_ED = get_date(''PERIOD_END_DATE'')
9779 
9780 /* ------------------------------------------------------------------------
9781    Set the Calculation_Date to the Termination Date if not null
9782 -------------------------------------------------------------------------- */
9783 
9784 IF NOT (ACP_TERMINATION_DATE WAS DEFAULTED) OR
9785     NOT (ACP_ENROLLMENT_END_DATE WAS DEFAULTED) THEN
9786 (
9787   Early_End_Date = least(ACP_TERMINATION_DATE, ACP_ENROLLMENT_END_DATE)
9788 
9789   IF (Early_End_Date < First_Period_ED) THEN
9790   (
9791     Total_Accrued_PTO = 0
9792     E = PUT_MESSAGE(''HR_52794_PTO_FML_ASG_TER'')
9793    )
9794 
9795   IF (Early_End_Date < Calculation_Date) THEN
9796   (
9797     Calculation_Date = Early_End_Date
9798   )
9799 )
9800 
9801 /* ------------------------------------------------------------------------
9802    Get the last whole period prior to the Calculation Date and ensure that it is within the
9803    Year (if the Calculation Date is the End of a Period then use that period)
9804    ------------------------------------------------------------------------ */
9805 
9806 E = GET_PERIOD_DATES(Calculation_Date,
9807                      Accruing_Frequency,
9808                      Beginning_of_Calculation_Year,
9809                      Accruing_Multiplier)
9810 
9811 Calculation_Period_SD  = get_date(''PERIOD_START_DATE'')
9812 Calculation_Period_ED = get_date(''PERIOD_END_DATE'')
9813 
9814 IF (Calculation_Date <> Calculation_Period_ED) THEN
9815     (
9816      E = GET_PERIOD_DATES(ADD_DAYS(Calculation_Period_SD,-1),
9817                                                 Accruing_Frequency,
9818                                                 Beginning_of_Calculation_Year,
9819                                                 Accruing_Multiplier)
9820 
9821     Calculation_Period_SD  = get_date(''PERIOD_START_DATE'')
9822     Calculation_Period_ED = get_date(''PERIOD_END_DATE'')
9823    )
9824 
9825 If (Calculation_Period_ED < First_Period_ED) THEN
9826    (
9827     Total_Accrued_PTO = 0
9828     E = PUT_MESSAGE(''HR_52795_PTO_FML_CALC_DATE'')
9829     )
9830 
9831 /* ------------------------------------------------------------------------
9832    Set the Continuous Service Global Variable, whilst also
9833    ensuring that the continuous service date is before the Calculation Period
9834   ------------------------------------------------------------------------ */
9835 
9836 IF (ACP_CONTINUOUS_SERVICE_DATE WAS DEFAULTED) THEN
9837     (
9838     E = set_date(''CONTINUOUS_SERVICE_DATE'', ACP_SERVICE_START_DATE)
9839     )
9840 ELSE IF(ACP_CONTINUOUS_SERVICE_DATE > Calculation_Period_SD) THEN
9841    (
9842     Total_Accrued_PTO = 0
9843     E = PUT_MESSAGE(''HR_52796_PTO_FML_CSD'')
9844     E = set_date(''CONTINUOUS_SERVICE_DATE'', ACP_CONTINUOUS_SERVICE_DATE)
9845    )
9846 ELSE
9847   (
9848     E = set_date(''CONTINUOUS_SERVICE_DATE'', ACP_CONTINUOUS_SERVICE_DATE)
9849   )
9850 
9851 Continuous_Service_Date = get_date(''CONTINUOUS_SERVICE_DATE'')
9852 
9853 First_Eligible_To_Accrue_Date  = Continuous_Service_Date
9854 
9855 /*------------------------------------------------------------------------
9856    Determine the date on which accrued PTo may first be registered, i.e the date on which the
9857    Ineligibility Period expires
9858    ------------------------------------------------------------------------ */
9859 
9860 Accrual_Ineligibility_Expired_Date = First_Eligible_To_Accrue_Date
9861 
9862 IF (ACP_INELIGIBILITY_PERIOD_LENGTH > 0) THEN
9863    (
9864    IF ACP_INELIGIBILITY_PERIOD_TYPE = ''BM'' THEN
9865       (
9866       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
9867                                                       ACP_INELIGIBILITY_PERIOD_LENGTH*2)
9868       )
9869    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''F'' THEN
9870       (
9871       Accrual_Ineligibility_Expired_Date = add_days(Continuous_Service_Date,
9872                                                     ACP_INELIGIBILITY_PERIOD_LENGTH*14)
9873       )
9874    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''CM'' THEN
9875       (
9876       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
9877                                                       ACP_INELIGIBILITY_PERIOD_LENGTH)
9878       )
9879    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''LM'' THEN
9880       (
9881       Accrual_Ineligibility_Expired_Date = add_days(Continuous_Service_Date,
9882                                                     ACP_INELIGIBILITY_PERIOD_LENGTH*28)
9883       )
9884    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''Q'' THEN
9885       (
9886       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
9887                                                       ACP_INELIGIBILITY_PERIOD_LENGTH*3)
9888       )
9889    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''SM'' THEN
9890       (
9891       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
9892                                                       ACP_INELIGIBILITY_PERIOD_LENGTH/2)
9893       )
9894    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''SY'' THEN
9895       (
9896       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
9897                                                       ACP_INELIGIBILITY_PERIOD_LENGTH*6)
9898       )
9899    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''W'' THEN
9900       (
9901       Accrual_Ineligibility_Expired_Date = add_days(Continuous_Service_Date,
9902                                                     ACP_INELIGIBILITY_PERIOD_LENGTH*7)
9903       )
9904    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''Y'' THEN
9905       (
9906       Accrual_Ineligibility_Expired_Date = add_months(Continuous_Service_Date,
9907                                                       ACP_INELIGIBILITY_PERIOD_LENGTH*12)
9908       )
9909 
9910    IF Accrual_Ineligibility_Expired_Date > First_Eligible_To_Accrue_Date
9911    AND Calculation_Date < Accrual_Ineligibility_Expired_Date THEN
9912       (
9913       First_Eligible_To_Accrue_Date = Accrual_Ineligibility_Expired_Date
9914       )
9915    )
9916 
9917 /* ------------------------------------------------------------------------
9918    Get the first full period following the First_Eligible_To_Accrue_Date
9919    (if it falls on the beginning of the period then use that period)
9920 ------------------------------------------------------------------------- */
9921 
9922 Latest_Balance = 0
9923 
9924 IF (not Accrual_Start_Date was defaulted) AND
9925    ((Calculation_Date < Accrual_Ineligibility_Expired_Date) OR
9926     (Accrual_Start_Date > Accrual_Ineligibility_Expired_Date)) THEN
9927 (
9928   Adjusted_Start_Date = Get_Start_Date(Accrual_Start_Date,
9929                                        Beginning_Of_Calculation_Year)
9930 
9931   IF (Adjusted_Start_Date < Accrual_Start_Date) THEN
9932   (
9933     Process_Full_Term = ''Y''
9934   )
9935   ELSE
9936   (
9937     Process_Full_Term = ''N''
9938   )
9939 )
9940 ELSE
9941 (
9942   Process_Full_Term = ''Y''
9943 )
9944 
9945 IF (Process_Full_Term = ''N'') AND
9946    (Accrual_Start_Date >= First_Eligible_To_Accrue_Date) THEN
9947 (
9948 
9949   E = GET_PERIOD_DATES(Adjusted_Start_Date,
9950                        Accruing_Frequency,
9951                        Beginning_Of_Calculation_Year,
9952                        Accruing_Multiplier)
9953 
9954   First_Eligible_To_Accrue_Period_SD = get_date(''PERIOD_START_DATE'')
9955   First_Eligible_To_Accrue_Period_ED = get_date(''PERIOD_END_DATE'')
9956 
9957   Latest_Balance = Accrual_Latest_Balance
9958   Effective_Start_Date = Accrual_Start_Date
9959 
9960 )
9961 ELSE IF First_Eligible_To_Accrue_Date > Beginning_Of_Calculation_Year THEN
9962 (
9963   IF (not Accrual_Start_Date was defaulted) THEN
9964   (
9965     Latest_Balance = Accrual_Latest_Balance
9966   )
9967   ELSE
9968   (
9969     Latest_Balance = 0
9970   )
9971 
9972   E = GET_PERIOD_DATES(First_Eligible_To_Accrue_Date,
9973                        Accruing_Frequency,
9974                        Beginning_Of_Calculation_Year,
9975                        Accruing_Multiplier)
9976 
9977   First_Eligible_To_Accrue_Period_SD  = get_date(''PERIOD_START_DATE'')
9978   First_Eligible_To_Accrue_Period_ED  = get_date(''PERIOD_END_DATE'')
9979 
9980   IF First_Eligible_To_Accrue_Date <> First_Eligible_To_Accrue_Period_SD THEN
9981       (
9982        E = GET_PERIOD_DATES(add_days(First_Eligible_To_Accrue_Period_ED,1),
9983                                                   Accruing_Frequency,
9984                                                   Beginning_Of_Calculation_Year,
9985                                                   Accruing_Multiplier)
9986 
9987        First_Eligible_To_Accrue_Period_SD  = get_date(''PERIOD_START_DATE'')
9988        First_Eligible_To_Accrue_Period_ED  = get_date(''PERIOD_END_DATE'')
9989        )
9990 
9991   IF (First_Eligible_To_Accrue_Period_SD > Calculation_Period_ED) THEN
9992      (
9993        Total_Accrued_PTO = 0
9994        E = PUT_MESSAGE(''HR_52793_PTO_FML_ASG_INELIG'')
9995     )
9996 
9997   Effective_Start_Date = First_Eligible_To_Accrue_Date
9998 )
9999 ELSE
10000 (
10001   IF (not Accrual_Start_Date was defaulted) THEN
10002   (
10003     Latest_Balance = Accrual_Latest_Balance
10004   )
10005   ELSE
10006   (
10007     Latest_Balance = 0
10008   )
10009 
10010   First_Eligible_To_Accrue_Period_SD  = First_Period_SD
10011   First_Eligible_To_Accrue_Period_ED  = First_Period_ED
10012 
10013   Effective_Start_Date = Beginning_Of_Calculation_Year
10014 )
10015 /* ------------------------------------------------------------------------
10016    Determine the date on which PTO actually starts accruing based on Hire Date,
10017    Continuous Service Date and plan Enrollment Start Date. Remember, we have already determined
10018    whether to user hire date or CSD earlier in the formula.
10019    If this date is after the 1st period and the fisrt eligible date then establish the first full period
10020    after this date (if the Actual Start Date falls on the beginning of a period then use this period)
10021  ------------------------------------------------------------------------ */
10022 
10023 IF Continuous_Service_date = ACP_CONTINUOUS_SERVICE_DATE THEN
10024 (
10025   Actual_Accrual_Start_Date = Continuous_service_Date
10026 )
10027 ELSE
10028 (
10029   Actual_Accrual_Start_Date = greatest(Continuous_Service_Date,
10030                                        ACP_ENROLLMENT_START_DATE,
10031                                        First_Period_SD)
10032 )
10033 
10034 /* -------------------------------------------------------------------------
10035        Determine the actual start of the accrual calculation
10036 -------------------------------------------------------------------------*/
10037 IF (Actual_Accrual_Start_Date > First_Period_SD AND
10038      Actual_Accrual_Start_Date > First_Eligible_To_Accrue_Period_SD) THEN
10039     (
10040      E = GET_PERIOD_DATES(Actual_Accrual_Start_Date,
10041                           Accruing_Frequency,
10042                           Beginning_Of_Calculation_Year,
10043                           Accruing_Multiplier)
10044 
10045      Accrual_Start_Period_SD = get_date(''PERIOD_START_DATE'')
10046      Accrual_Start_Period_ED = get_date(''PERIOD_END_DATE'')
10047 
10048      IF Actual_Accrual_Start_Date > Accrual_Start_Period_SD THEN
10049          (
10050           E = GET_PERIOD_DATES(add_days(Accrual_Start_Period_ED,1),
10051                                Accruing_Frequency,
10052                                Beginning_of_Calculation_Year,
10053                                Accruing_Multiplier)
10054 
10055           Accrual_Start_Period_SD = get_date(''PERIOD_START_DATE'')
10056           Accrual_Start_Period_ED = get_date(''PERIOD_END_DATE'')
10057          )
10058 
10059 /* -----------------------------------------------------------------
10060         If the Actual Acrual Period is after the Calculation Period then end the processing.
10061 ----------------------------------------------------------------- */
10062         IF (Accrual_Start_Period_SD > Calculation_Period_ED) THEN
10063             (
10064             Total_Accrued_PTO = 0
10065             E = PUT_MESSAGE(''HR_52797_PTO_FML_ACT_ACCRUAL'')
10066             )
10067      )
10068 
10069 ELSE IF (First_Eligible_To_Accrue_Period_SD > First_Period_SD) THEN
10070      (
10071       Accrual_Start_Period_SD = First_Eligible_To_Accrue_Period_SD
10072       Accrual_Start_Period_ED = First_Eligible_To_Accrue_Period_ED
10073      )
10074 ELSE
10075     (
10076       Accrual_Start_Period_SD = First_Period_SD
10077       Accrual_Start_Period_ED = First_Period_ED
10078     )
10079 
10080  /* -------------------------------------------------------------------
10081        Now set up the information that will be used in when looping through the periods
10082 --------------------------------------------------------------------- */
10083 
10084 IF Calculation_Period_ED >= Accrual_Start_Period_ED THEN
10085 (
10086   E = set_date(''PERIOD_SD'',Accrual_Start_Period_SD)
10087   E = set_date(''PERIOD_ED'',Accrual_Start_Period_ED)
10088   E = set_date(''LAST_PERIOD_SD'',Calculation_Period_SD)
10089   E = set_date(''LAST_PERIOD_ED'',Calculation_Period_ED)
10090 
10091   IF (Process_Full_Term = ''N'') THEN
10092   (
10093     E = set_number(''TOTAL_ACCRUED_PTO'', Latest_Balance)
10094   )
10095   ELSE
10096   (
10097     E = set_number(''TOTAL_ACCRUED_PTO'', 0)
10098   )
10099 
10100   E = LOOP_CONTROL(''PTO_SIMPLE_PERIOD_ACCRUAL'')
10101 
10102   Total_Accrued_PTO = get_number(''TOTAL_ACCRUED_PTO'') - Latest_Balance
10103 
10104 )
10105 ELSE
10106 (
10107   Total_Accrued_PTO = 0
10108 )
10109 
10110 
10111 IF Accrual_Start_Period_SD <= Calculation_Period_SD THEN
10112 (
10113   Accrual_end_date = Calculation_Period_ED
10114 )
10115 
10116 IF Process_Full_Term = ''Y'' AND
10117    Effective_Start_Date > Actual_Accrual_Start_Date THEN
10118 (
10119   Effective_Start_Date = Actual_Accrual_Start_Date
10120 )
10121 
10122 Effective_End_Date = Calculation_Date
10123 
10124 IF Effective_Start_Date >= Effective_End_Date THEN
10125 (
10126   Effective_Start_Date = Effective_End_Date
10127 )
10128 
10129 RETURN Total_Accrued_PTO, Effective_start_date, Effective_end_date, Accrual_end_date
10130 ';
10131     --
10132     select formula_type_id
10133     into   l_ftype_id
10134     from   ff_formula_types
10135     where  formula_type_name = 'Accrual';
10136     --
10137      INSERT INTO ff_formulas_f
10138      (formula_id,
10139       effective_start_date,
10140       effective_end_date,
10141       business_group_id,
10142       legislation_code,
10143       formula_type_id,
10144       formula_name,
10145       description,
10146       formula_text,
10147       sticky_flag)
10148    VALUES
10149      (ff_formulas_s.nextval,
10150       to_date('01/01/0001','DD/MM/YYYY'),
10151       to_date('31/12/4712','DD/MM/YYYY'),
10152       NULL,
10153       NULL,
10154       l_ftype_id,
10155       'PTO_SIMPLE_BALANCE_MULTIPLIER',
10156       'Seeded top level formula for PTO accruals',
10157       l_text,
10158       NULL);
10159     --
10160     hr_utility.set_location ('hrstrdbi.insert_formula', 135);
10161     --
10162 l_text := '
10163 /* ------------------------------------------------------------------------
10164     NAME : PTO_HD_ANNIVERSARY_BALANCE
10165     This formula calculates the start and end dates for a simple multiplier.
10166     This formula calculates the dates between which an assignment is to accrue.
10167    ---------------------------------------------------------------------*/
10168 
10169 DEFAULT FOR ACP_INELIGIBILITY_PERIOD_TYPE IS ''CM''
10170 DEFAULT FOR ACP_INELIGIBILITY_PERIOD_LENGTH IS 0
10171 DEFAULT FOR ACP_CONTINUOUS_SERVICE_DATE IS ''4712/12/31 00:00:00'' (date)
10172 DEFAULT FOR ACP_ENROLLMENT_END_DATE IS ''4712/12/31 00:00:00'' (date)
10173 DEFAULT FOR ACP_TERMINATION_DATE IS ''4712/12/31 00:00:00'' (date)
10174 DEFAULT FOR ACP_ENROLLMENT_START_DATE IS ''4712/12/31 00:00:00'' (date)
10175 DEFAULT FOR ACP_SERVICE_START_DATE IS ''4712/12/31 00:00:00'' (date)
10176 
10177 default for Accrual_Start_Date is ''4712/12/31 00:00:00'' (date)
10178 default for Accrual_Latest_Balance is 0
10179 
10180 INPUTS ARE
10181 Calculation_Date (date),
10182 Accrual_Start_Date (date),
10183 Accrual_Latest_Balance
10184 
10185 E = SET_NUMBER(''CEILING'', 20)
10186 E = SET_NUMBER(''ACCRUAL_RATE'', 2)
10187 
10188 Accruing_Frequency = ''M''   /* Month */
10189 Accruing_Multiplier = 1
10190 
10191 E = SET_TEXT(''ACCRUING_FREQUENCY'', Accruing_Frequency)
10192 E = SET_NUMBER(''ACCRUING_MULTIPLIER'', Accruing_Multiplier)
10193 
10194 Hire_Date_Anniversary = add_months(ACP_SERVICE_START_DATE,
10195                                   trunc(months_between(Calculation_Date,
10196                                                        ACP_SERVICE_START_DATE) / 12) * 12)
10197 
10198 IF Accrual_Start_Date < Hire_Date_Anniversary THEN
10199 (
10200   Accrual_Start_Date = Hire_Date_Anniversary
10201 )
10202 
10203 E = SET_DATE(''HIRE_DATE_ANNIVERSARY'', Hire_Date_Anniversary)
10204 
10205 E = GET_PERIOD_DATES(Hire_Date_Anniversary,
10206                      Accruing_Frequency,
10207                      Hire_Date_Anniversary,
10208                      Accruing_Multiplier)
10209 
10210 First_Period_SD = get_date(''PERIOD_START_DATE'')
10211 First_Period_ED = get_date(''PERIOD_END_DATE'')
10212 
10213 /* ------------------------------------------------------------------------
10214    Set the Calculation_Date to the Termination Date if not null
10215 -------------------------------------------------------------------------- */
10216 
10217 IF NOT (ACP_TERMINATION_DATE WAS DEFAULTED) OR
10218     NOT (ACP_ENROLLMENT_END_DATE WAS DEFAULTED) THEN
10219 (
10220   Early_End_Date = least(ACP_TERMINATION_DATE, ACP_ENROLLMENT_END_DATE)
10221 
10222   IF (Early_End_Date < First_Period_ED) THEN
10223   (
10224     Total_Accrued_PTO = 0
10225     E = PUT_MESSAGE(''HR_52794_PTO_FML_ASG_TER'')
10226    )
10227 
10228   IF (Early_End_Date < Calculation_Date) THEN
10229   (
10230     Calculation_Date = Early_End_Date
10231   )
10232 )
10233 
10234 /* ------------------------------------------------------------------------
10235    Get the last whole period prior to the Calculation Date and ensure that it is within the
10236    Year (if the Calculation Date is the End of a Period then use that period)
10237    ------------------------------------------------------------------------ */
10238 
10239 E = GET_PERIOD_DATES(Calculation_Date,
10240                      Accruing_Frequency,
10241                      Hire_Date_Anniversary,
10242                      Accruing_Multiplier)
10243 
10244 Calculation_Period_SD  = get_date(''PERIOD_START_DATE'')
10245 Calculation_Period_ED = get_date(''PERIOD_END_DATE'')
10246 
10247 IF (Calculation_Date <> Calculation_Period_ED) THEN
10248     (
10249      E = GET_PERIOD_DATES(ADD_DAYS(Calculation_Period_SD,-1),
10250                                                 Accruing_Frequency,
10251                                                 Hire_Date_Anniversary,
10252                                                 Accruing_Multiplier)
10253 
10254     Calculation_Period_SD  = get_date(''PERIOD_START_DATE'')
10255     Calculation_Period_ED = get_date(''PERIOD_END_DATE'')
10256    )
10257 
10258 If (Calculation_Period_ED < First_Period_ED) THEN
10259    (
10260     Total_Accrued_PTO = 0
10261     E = PUT_MESSAGE(''HR_52795_PTO_FML_CALC_DATE'')
10262     )
10263 
10264 /* ------------------------------------------------------------------------
10265    Set the Continuous Service Global Variable, whilst also
10266    ensuring that the continuous service date is before the Calculation Period
10267   ------------------------------------------------------------------------ */
10268 
10269 IF (ACP_CONTINUOUS_SERVICE_DATE WAS DEFAULTED) THEN
10270     (
10271     E = set_date(''SERVICE_START_DATE'', ACP_SERVICE_START_DATE)
10272     )
10273 ELSE IF(ACP_CONTINUOUS_SERVICE_DATE > Calculation_Period_SD) THEN
10274    (
10275     Total_Accrued_PTO = 0
10276     E = PUT_MESSAGE(''HR_52796_PTO_FML_CSD'')
10277     E = set_date(''SERVICE_START_DATE'', ACP_CONTINUOUS_SERVICE_DATE)
10278    )
10279 ELSE
10280   (
10281     E = set_date(''SERVICE_START_DATE'', ACP_CONTINUOUS_SERVICE_DATE)
10282   )
10283 
10284 /*
10285 E = set_date(''SERVICE_START_DATE'', ACP_SERVICE_START_DATE)
10286 */
10287 Service_Start_Date = get_date(''SERVICE_START_DATE'')
10288 
10289 First_Eligible_To_Accrue_Date  = Service_Start_Date
10290 
10291 
10292 /*------------------------------------------------------------------------
10293    Determine the date on which accrued PTo may first be registered, i.e the date on which the
10294    Ineligibility Period expires
10295    ------------------------------------------------------------------------ */
10296 
10297 Accrual_Ineligibility_Expired_Date = First_Eligible_To_Accrue_Date
10298 
10299 IF (ACP_INELIGIBILITY_PERIOD_LENGTH > 0) THEN
10300    (
10301    IF ACP_INELIGIBILITY_PERIOD_TYPE = ''BM'' THEN
10302       (
10303       Accrual_Ineligibility_Expired_Date = add_months(Service_Start_Date,
10304                                                       ACP_INELIGIBILITY_PERIOD_LENGTH*2)
10305       )
10306    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''F'' THEN
10307       (
10308       Accrual_Ineligibility_Expired_Date = add_days(Service_Start_Date,
10309                                                     ACP_INELIGIBILITY_PERIOD_LENGTH*14)
10310       )
10311    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''CM'' THEN
10312       (
10313       Accrual_Ineligibility_Expired_Date = add_months(Service_Start_Date,
10314                                                       ACP_INELIGIBILITY_PERIOD_LENGTH)
10315       )
10316    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''LM'' THEN
10317       (
10318       Accrual_Ineligibility_Expired_Date = add_days(Service_Start_Date,
10319                                                     ACP_INELIGIBILITY_PERIOD_LENGTH*28)
10320       )
10321    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''Q'' THEN
10322       (
10323       Accrual_Ineligibility_Expired_Date = add_months(Service_Start_Date,
10324                                                       ACP_INELIGIBILITY_PERIOD_LENGTH*3)
10325       )
10326    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''SM'' THEN
10327       (
10328       Accrual_Ineligibility_Expired_Date = add_months(Service_Start_Date,
10329                                                       ACP_INELIGIBILITY_PERIOD_LENGTH/2)
10330       )
10331    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''SY'' THEN
10332       (
10333       Accrual_Ineligibility_Expired_Date = add_months(Service_Start_Date,
10334                                                       ACP_INELIGIBILITY_PERIOD_LENGTH*6)
10335       )
10336    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''W'' THEN
10337       (
10338       Accrual_Ineligibility_Expired_Date = add_days(Service_Start_Date,
10339                                                     ACP_INELIGIBILITY_PERIOD_LENGTH*7)
10340       )
10341    ELSE IF ACP_INELIGIBILITY_PERIOD_TYPE = ''Y'' THEN
10342       (
10343       Accrual_Ineligibility_Expired_Date = add_months(Service_Start_Date,
10344                                                       ACP_INELIGIBILITY_PERIOD_LENGTH*12)
10345       )
10346 
10347    IF Accrual_Ineligibility_Expired_Date > First_Eligible_To_Accrue_Date
10348    AND Calculation_Date < Accrual_Ineligibility_Expired_Date THEN
10349       (
10350       First_Eligible_To_Accrue_Date = Accrual_Ineligibility_Expired_Date
10351       )
10352    )
10353 
10354 /* ------------------------------------------------------------------------
10355    Get the first full period following the First_Eligible_To_Accrue_Date
10356    (if it falls on the beginning of the period then use that period)
10357 ------------------------------------------------------------------------- */
10358 
10359 Latest_Balance = 0
10360 
10361 IF (not Accrual_Start_Date was defaulted) AND
10362    ((Calculation_Date < Accrual_Ineligibility_Expired_Date) OR
10363     (Accrual_Start_Date > Accrual_Ineligibility_Expired_Date)) THEN
10364 (
10365   Adjusted_Start_Date = Get_Start_Date(Accrual_Start_Date,
10366                                        Hire_Date_Anniversary)
10367 
10368   IF (Adjusted_Start_Date < Accrual_Start_Date) THEN
10369   (
10370     Process_Full_Term = ''Y''
10371   )
10372   ELSE
10373   (
10374     Process_Full_Term = ''N''
10375   )
10376 )
10377 ELSE
10378 (
10379   Process_Full_Term = ''Y''
10380 )
10381 
10382 IF (Process_Full_Term = ''N'') AND
10383    (Accrual_Start_Date >= First_Eligible_To_Accrue_Date) THEN
10384 (
10385 
10386   E = GET_PERIOD_DATES(Adjusted_Start_Date,
10387                        Accruing_Frequency,
10388                        Hire_Date_Anniversary,
10389                        Accruing_Multiplier)
10390 
10391   First_Eligible_To_Accrue_Period_SD = get_date(''PERIOD_START_DATE'')
10392   First_Eligible_To_Accrue_Period_ED = get_date(''PERIOD_END_DATE'')
10393 
10394   Latest_Balance = Accrual_Latest_Balance
10395   Effective_Start_Date = Accrual_Start_Date
10396 
10397 )
10398 ELSE IF First_Eligible_To_Accrue_Date > Hire_Date_Anniversary THEN
10399 (
10400   IF (not Accrual_Start_Date was defaulted) THEN
10401   (
10402     Latest_Balance = Accrual_Latest_Balance
10403   )
10404   ELSE
10405   (
10406     Latest_Balance = 0
10407   )
10408 
10409   E = GET_PERIOD_DATES(First_Eligible_To_Accrue_Date,
10410                        Accruing_Frequency,
10411                        Hire_Date_Anniversary,
10412                        Accruing_Multiplier)
10413 
10414   First_Eligible_To_Accrue_Period_SD  = get_date(''PERIOD_START_DATE'')
10415   First_Eligible_To_Accrue_Period_ED  = get_date(''PERIOD_END_DATE'')
10416 
10417   IF First_Eligible_To_Accrue_Date <> First_Eligible_To_Accrue_Period_SD THEN
10418       (
10419        E = GET_PERIOD_DATES(add_days(First_Eligible_To_Accrue_Period_ED,1),
10420                                                   Accruing_Frequency,
10421                                                   Hire_Date_Anniversary,
10422                                                   Accruing_Multiplier)
10423 
10424        First_Eligible_To_Accrue_Period_SD  = get_date(''PERIOD_START_DATE'')
10425        First_Eligible_To_Accrue_Period_ED  = get_date(''PERIOD_END_DATE'')
10426        )
10427 
10428   IF (First_Eligible_To_Accrue_Period_SD > Calculation_Period_ED) THEN
10429      (
10430        Total_Accrued_PTO = 0
10431        E = PUT_MESSAGE(''HR_52793_PTO_FML_ASG_INELIG'')
10432     )
10433 
10434   Effective_Start_Date = First_Eligible_To_Accrue_Date
10435 
10436 )
10437 ELSE
10438 (
10439   IF (not Accrual_Start_Date was defaulted) THEN
10440   (
10441     Latest_Balance = Accrual_Latest_Balance
10442   )
10443   ELSE
10444   (
10445     Latest_Balance = 0
10446   )
10447 
10448   First_Eligible_To_Accrue_Period_SD  = First_Period_SD
10449   First_Eligible_To_Accrue_Period_ED  = First_Period_ED
10450 
10451   Effective_Start_Date = Hire_Date_Anniversary
10452 )
10453 /* ------------------------------------------------------------------------
10454    Determine the date on which PTO actually starts accruing based on Hire Date,
10455    Service Start Date and plan Enrollment Start Date.
10456    If this date is after the 1st period and the fisrt eligible date then
10457    establish the first full period after this date (if the Actual Start
10458    Date falls on the beginning of a period then use this period)
10459  ------------------------------------------------------------------------ */
10460 
10461 Actual_Accrual_Start_Date = greatest(Service_Start_Date,
10462                                      ACP_ENROLLMENT_START_DATE,
10463                                      First_Period_SD)
10464 
10465 /* -------------------------------------------------------------------------
10466        Determine the actual start of the accrual calculation
10467 -------------------------------------------------------------------------*/
10468 IF (Actual_Accrual_Start_Date > First_Period_SD AND
10469      Actual_Accrual_Start_Date > First_Eligible_To_Accrue_Period_SD) THEN
10470     (
10471      E = GET_PERIOD_DATES(Actual_Accrual_Start_Date,
10472                           Accruing_Frequency,
10473                           Hire_Date_Anniversary,
10474                           Accruing_Multiplier)
10475 
10476      Accrual_Start_Period_SD = get_date(''PERIOD_START_DATE'')
10477      Accrual_Start_Period_ED = get_date(''PERIOD_END_DATE'')
10478 
10479      IF Actual_Accrual_Start_Date > Accrual_Start_Period_SD THEN
10480          (
10481           E = GET_PERIOD_DATES(add_days(Accrual_Start_Period_ED,1),
10482                                Accruing_Frequency,
10483                                Hire_Date_Anniversary,
10484                                Accruing_Multiplier)
10485 
10486           Accrual_Start_Period_SD = get_date(''PERIOD_START_DATE'')
10487           Accrual_Start_Period_ED = get_date(''PERIOD_END_DATE'')
10488          )
10489 
10490 /* -----------------------------------------------------------------
10491         If the Actual Acrual Period is after the Calculation Period then end the processing.
10492 ----------------------------------------------------------------- */
10493         IF (Accrual_Start_Period_SD > Calculation_Period_ED) THEN
10494             (
10495             Total_Accrued_PTO = 0
10496             E = PUT_MESSAGE(''HR_52797_PTO_FML_ACT_ACCRUAL'')
10497             )
10498      )
10499 
10500 ELSE IF (First_Eligible_To_Accrue_Period_SD > First_Period_SD) THEN
10501      (
10502       Accrual_Start_Period_SD = First_Eligible_To_Accrue_Period_SD
10503       Accrual_Start_Period_ED = First_Eligible_To_Accrue_Period_ED
10504      )
10505 ELSE
10506     (
10507       Accrual_Start_Period_SD = First_Period_SD
10508       Accrual_Start_Period_ED = First_Period_ED
10509     )
10510 
10511  /* -------------------------------------------------------------------
10512        Now set up the information that will be used in when looping through the periods
10513 --------------------------------------------------------------------- */
10514 
10515 IF Calculation_Period_ED >= Accrual_Start_Period_ED THEN
10516 (
10517   E = set_date(''PERIOD_SD'',Accrual_Start_Period_SD)
10518   E = set_date(''PERIOD_ED'',Accrual_Start_Period_ED)
10519   E = set_date(''LAST_PERIOD_SD'',Calculation_Period_SD)
10520   E = set_date(''LAST_PERIOD_ED'',Calculation_Period_ED)
10521 
10522   IF (Process_Full_Term = ''N'') THEN
10523   (
10524     E = set_number(''TOTAL_ACCRUED_PTO'', Latest_Balance)
10525   )
10526   ELSE
10527   (
10528     E = set_number(''TOTAL_ACCRUED_PTO'', 0)
10529   )
10530 
10531   E = LOOP_CONTROL(''PTO_HD_ANNIVERSARY_PERIOD_ACCRUAL'')
10532 
10533   Total_Accrued_PTO = get_number(''TOTAL_ACCRUED_PTO'') - Latest_Balance
10534 
10535 )
10536 ELSE
10537 (
10538   Total_Accrued_PTO = 0
10539 )
10540 
10541 
10542 IF Accrual_Start_Period_SD <= Calculation_Period_SD THEN
10543 (
10544   Accrual_end_date = Calculation_Period_ED
10545 )
10546 
10547 IF Process_Full_Term = ''Y'' AND
10548    Effective_Start_Date > Actual_Accrual_Start_Date THEN
10549 (
10550   Effective_Start_Date = Actual_Accrual_Start_Date
10551 )
10552 
10553 Effective_End_Date = Calculation_Date
10554 
10555 IF Effective_Start_Date >= Effective_End_Date THEN
10556 (
10557   Effective_Start_Date = Effective_End_Date
10558 )
10559 
10560 RETURN Total_Accrued_PTO, Effective_start_date, Effective_end_date, Accrual_end_date
10561 ';
10562     --
10563     select formula_type_id
10564     into   l_ftype_id
10565     from   ff_formula_types
10566     where  formula_type_name = 'Accrual';
10567     --
10568      INSERT INTO ff_formulas_f
10569      (formula_id,
10570       effective_start_date,
10571       effective_end_date,
10572       business_group_id,
10573       legislation_code,
10574       formula_type_id,
10575       formula_name,
10576       description,
10577       formula_text,
10578       sticky_flag)
10579    VALUES
10580      (ff_formulas_s.nextval,
10581       to_date('01/01/0001','DD/MM/YYYY'),
10582       to_date('31/12/4712','DD/MM/YYYY'),
10583       NULL,
10584       NULL,
10585       l_ftype_id,
10586       'PTO_HD_ANNIVERSARY_BALANCE',
10587       'Seeded simple top level formula for PTO accruals',
10588       l_text,
10589       NULL);
10590     --
10591     hr_utility.set_location ('hrstrdbi.insert_formula', 136);
10592     --
10593 l_text := '
10594 /* ------------------------------------------------------------------------
10595     NAME : PTO_HD_ANNIVERSARY_PERIOD_ACCRUAL
10596     This formula calculates the amount of PTO accrued for a particular period
10597    ---------------------------------------------------------------------*/
10598 
10599 /*------------------------------------------------------------------------
10600     Get the global variable to be used in this formula
10601  ------------------------------------------------------------------------*/
10602 
10603 Service_Start_Date = get_date(''SERVICE_START_DATE'')
10604 Total_Accrued_PTO = get_number(''TOTAL_ACCRUED_PTO'')
10605 Period_SD = get_date(''PERIOD_SD'')
10606 Period_ED = get_date(''PERIOD_ED'')
10607 Last_Period_SD = get_date(''LAST_PERIOD_SD'')
10608 Last_Period_ED = get_date(''LAST_PERIOD_ED'')
10609 
10610 Accrual_Rate = get_number(''ACCRUAL_RATE'')
10611 Accruing_Frequency = get_text(''ACCRUING_FREQUENCY'')
10612 Accruing_Multiplier = get_number(''ACCRUING_MULTIPLIER'')
10613 Hire_Date_Anniversary = get_date(''HIRE_DATE_ANNIVERSARY'')
10614 
10615 Ceiling = get_number(''CEILING'')
10616 
10617 /* ----------------------------------------------------------------------
10618     Calculate the Amount Accrued this Period
10619    ---------------------------------------------------------------------*/
10620 
10621 Period_Accrued_PTO = Accrual_Rate
10622 
10623 /* ----------------------------------------------------------------------
10624     Calculate any absence or bought/sold time etc. to be accounted for in this period.
10625    ---------------------------------------------------------------------*/
10626 
10627 Absence = GET_ABSENCE(Period_ED, Hire_Date_Anniversary)
10628 CarryOver = GET_CARRY_OVER(Period_ED, Hire_Date_Anniversary)
10629 Other = GET_OTHER_NET_CONTRIBUTION(Period_ED, Hire_Date_Anniversary)
10630 
10631 Period_Others = CarryOver + Other - Absence
10632 
10633 /* ----------------------------------------------------------------------
10634     Now establish whether the Accrual this period has gone over the ceiling if one exists
10635    ----------------------------------------------------------------------*/
10636 
10637 IF (Ceiling > 0) THEN
10638     (
10639      IF (Total_Accrued_PTO + Period_Accrued_PTO + Period_Others > Ceiling) THEN
10640          (
10641           Amount_Over_Ceiling = Total_Accrued_PTO + Period_Accrued_PTO + Period_Others - Ceiling
10642           IF (Amount_Over_Ceiling > Period_Accrued_PTO) THEN
10643                (
10644                Period_Accrued_PTO = 0
10645                )
10646           ELSE
10647               (
10648                Period_Accrued_PTO = Period_Accrued_PTO - Amount_Over_Ceiling
10649               )
10650           )
10651      )
10652 
10653 /*---------------------------------------------------------------------
10654     Set the Running Total
10655   ---------------------------------------------------------------------*/
10656 
10657 E = set_number(''TOTAL_ACCRUED_PTO'',Total_Accrued_PTO + Period_Accrued_PTO)
10658 
10659 
10660 /* ----------------------------------------------------------------------
10661     Establish whether the current period is the last one, if so end the processing, otherwise get the
10662     next period
10663 ------------------------------------------------------------------------*/
10664 
10665 IF Period_SD >= Last_Period_SD THEN
10666     (
10667     Continue_Processing_Flag = ''N''
10668     )
10669 ELSE
10670    (
10671     E = GET_PERIOD_DATES(ADD_DAYS(Period_ED,1),
10672                          Accruing_Frequency,
10673                          Hire_Date_Anniversary,
10674                          Accruing_Multiplier)
10675 
10676     E = set_date(''PERIOD_SD'', get_date(''PERIOD_START_DATE''))
10677     E = set_date(''PERIOD_ED'', get_date(''PERIOD_END_DATE''))
10678 
10679    Continue_Processing_Flag = ''Y''
10680    )
10681 
10682 Return Continue_Processing_Flag
10683 ';
10684     --
10685     select formula_type_id
10686     into   l_ftype_id
10687     from   ff_formula_types
10688     where  formula_type_name = 'Accrual Subformula';
10689     --
10690      INSERT INTO ff_formulas_f
10691      (formula_id,
10692       effective_start_date,
10693       effective_end_date,
10694       business_group_id,
10695       legislation_code,
10696       formula_type_id,
10697       formula_name,
10698       description,
10699       formula_text,
10700       sticky_flag)
10701    VALUES
10702      (ff_formulas_s.nextval,
10703       to_date('01/01/0001','DD/MM/YYYY'),
10704       to_date('31/12/4712','DD/MM/YYYY'),
10705       NULL,
10706       NULL,
10707       l_ftype_id,
10708       'PTO_HD_ANNIVERSARY_PERIOD_ACCRUAL',
10709       'Seeded hire date anniversary looping formula for PTO accruals',
10710       l_text,
10711       NULL);
10712     --
10713     hr_utility.set_location ('hrstrdbi.insert_formula', 137);
10714     --
10715 l_text := '
10716 /* ------------------------------------------------------------------------
10717     NAME : PTO_HD_ANNIVERSARY_CARRYOVER
10718     This formula is the seeded carryover formula for our
10719     hire date anniversary accrual plan
10720    ---------------------------------------------------------------------*/
10721 
10722 DEFAULT FOR ACP_SERVICE_START_DATE IS ''4712/12/31 00:00:00'' (date)
10723 
10724 INPUTS ARE
10725 Calculation_Date (date),
10726 Accrual_term (text)
10727 
10728 Effective_Date = add_months(ACP_SERVICE_START_DATE,
10729                             trunc(months_between(Calculation_Date,
10730                                                  ACP_SERVICE_START_DATE) / 12) * 12)
10731 
10732 IF (Accrual_Term = ''CURRENT'') THEN
10733 (
10734   Effective_date = ADD_YEARS(Effective_Date, 1)
10735 )
10736 
10737 Effective_Date = add_days(Effective_Date, -1)
10738 Expiry_Date = add_years(effective_date, 1)
10739 Max_carryover = 5
10740 Process = ''YES''
10741 
10742 RETURN Max_Carryover, Effective_date, Expiry_Date, Process
10743 
10744 ';
10745     --
10746     select formula_type_id
10747     into   l_ftype_id
10748     from   ff_formula_types
10749     where  formula_type_name = 'Accrual Carryover';
10750     --
10751      INSERT INTO ff_formulas_f
10752      (formula_id,
10753       effective_start_date,
10754       effective_end_date,
10755       business_group_id,
10756       legislation_code,
10757       formula_type_id,
10758       formula_name,
10759       description,
10760       formula_text,
10761       sticky_flag)
10762    VALUES
10763      (ff_formulas_s.nextval,
10764       to_date('01/01/0001','DD/MM/YYYY'),
10765       to_date('31/12/4712','DD/MM/YYYY'),
10766       NULL,
10767       NULL,
10768       l_ftype_id,
10769       'PTO_HD_ANNIVERSARY_CARRYOVER',
10770       'Seeded simple carryover formula for PTO accruals',
10771       l_text,
10772       NULL);
10773     --
10774     hr_utility.set_location ('hrstrdbi.insert_formula', 138);
10775     --
10776 l_text := '
10777 /* -------------------------------------------------------
10778     NAME : PTO_TAGGING_FORMULA
10779     This formula returns the element entry id of retrospective
10780     elements which require tagging during the payroll run.
10781    ---------------------------------------------------------*/
10782 
10783 retro_element_entry_id = get_retro_element()
10784 
10785 if retro_element_entry_id = -1 then
10786 (
10787   RETURN
10788 )
10789 else
10790 (
10791   RETURN retro_element_entry_id
10792 )
10793 ';
10794     --
10795     select formula_type_id
10796     into   l_ftype_id
10797     from   ff_formula_types
10798     where  formula_type_name = 'Oracle Payroll';
10799     --
10800      INSERT INTO ff_formulas_f
10801      (formula_id,
10802       effective_start_date,
10803       effective_end_date,
10804       business_group_id,
10805       legislation_code,
10806       formula_type_id,
10807       formula_name,
10808       description,
10809       formula_text,
10810       sticky_flag)
10811    VALUES
10812      (ff_formulas_s.nextval,
10813       to_date('01/01/0001','DD/MM/YYYY'),
10814       to_date('31/12/4712','DD/MM/YYYY'),
10815       NULL,
10816       NULL,
10817       l_ftype_id,
10818       'PTO_TAGGING_FORMULA',
10819       'Seeded top level payroll formula for PTO accruals',
10820       l_text,
10821       NULL);
10822     --
10823     hr_utility.set_location ('hrstrdbi.insert_formula', 139);
10824     --
10825 l_text := '
10826 /* -------------------------------------------------------
10827     NAME : HR_CAGR_PYS_TEMPLATE
10828    ---------------------------------------------------------*/
10829 DEFAULT FOR ASG_EMPLOYMENT_CATEGORY_CODE IS ''FR''
10830 DEFAULT FOR PTU_PER_PERSON_TYPE IS              ''X''
10831 DEFAULT FOR ASG_LABOUR_UNION_MEMBER_FLAG  IS  ''N''
10832 DEFAULT FOR LOC_ADR_CITY                 IS   ''X''
10833 DEFAULT FOR LOC_ADR_COUNTRY             IS    ''X''
10834 DEFAULT FOR PER_AGE                      IS   0
10835 DEFAULT FOR PER_DISABLED                 IS   ''N''
10836 DEFAULT FOR PER_DISABLED                 IS   ''N''
10837 DEFAULT FOR PER_MARITAL_STATUS           IS   ''U''
10838 DEFAULT FOR PER_SEX                      IS   ''M''
10839 VALUE               = to_text(0)
10840 RANGE_FROM          = to_text(0)
10841 RANGE_TO            = to_text(0)
10842 PARENT_SPINE_ID     = ''0''
10843 STEP_ID             = ''0''
10844 FROM_STEP_ID        = ''0''
10845 TO_STEP_ID          = ''0''
10846 GRADE_SPINE_ID      = ''0''
10847 If      (PTU_PER_PERSON_TYPE              LIKE ''Employee%''
10848         AND ASG_EMPLOYMENT_CATEGORY_CODE = ''FR''
10849         AND ASG_LABOUR_UNION_MEMBER_FLAG = ''Y''
10850         AND LOC_ADR_COUNTRY              <> ''FRG''
10851         AND PER_AGE                      < 35
10852         AND PER_DISABLED                 = ''N''          ) THEN
10853 (
10854 VALUE           = to_text(500)
10855 RANGE_FROM      = to_text(500)
10856 RANGE_TO        = to_text(500)
10857 )
10858 If      (PTU_PER_PERSON_TYPE              LIKE ''Employee%''
10859         AND ASG_EMPLOYMENT_CATEGORY_CODE = ''FR''
10860         AND ASG_LABOUR_UNION_MEMBER_FLAG = ''Y''
10861         AND LOC_ADR_COUNTRY              = ''FRG''
10862         AND PER_AGE                      > 45
10863         AND PER_AGE                      < 50           ) THEN
10864 (
10865 VALUE                     = to_text(to_number(VALUE)+100)
10866 RANGE_FROM                = to_text(to_number(VALUE)+100)
10867 RANGE_TO                  = to_text(to_number(VALUE)+200)
10868 )
10869 IF ( PER_DISABLED = ''N'')
10870 THEN
10871 (
10872 VALUE = to_text(to_number(VALUE)+100)
10873 RANGE_FROM = to_text(to_number(RANGE_FROM)+200)
10874 RANGE_TO = to_text(to_number(RANGE_TO)+300)
10875 )
10876 IF ( ASG_EMPLOYMENT_CATEGORY_CODE = ''FR'' )
10877 THEN
10878 (
10879 VALUE = to_text(to_number(VALUE)+999)
10880 RANGE_FROM = to_text(to_number(RANGE_FROM)+444)
10881 RANGE_TO = to_text(to_number(RANGE_TO)+333)
10882 )
10883 IF ( PER_AGE < 35 )
10884 THEN
10885 (
10886 VALUE = to_text(to_number(VALUE)+999)
10887 RANGE_FROM = to_text(to_number(RANGE_FROM)+444)
10888 RANGE_TO = to_text(to_number(RANGE_TO)+333)
10889 )
10890 parent_spine_id = to_text(100)
10891 return      PARENT_SPINE_ID
10892 ,           STEP_ID
10893 ,           FROM_STEP_ID
10894 ,           TO_STEP_ID
10895 ,           GRADE_SPINE_ID
10896 ';
10897     --
10898     select formula_type_id
10899     into   l_ftype_id
10900     from   ff_formula_types
10901     where  formula_type_name = 'CAGR';
10902     --
10903      INSERT INTO ff_formulas_f
10904      (formula_id,
10905       effective_start_date,
10906       effective_end_date,
10907       business_group_id,
10908       legislation_code,
10909       formula_type_id,
10910       formula_name,
10911       description,
10912       formula_text,
10913       sticky_flag)
10914    VALUES
10915      (ff_formulas_s.nextval,
10916       to_date('01-01-1951','DD-MM-YYYY'),
10917       to_date('31-12-4712','DD-MM-YYYY'),
10918       NULL,
10919       NULL,
10920       l_ftype_id,
10921       'HR_CAGR_PYS_TEMPLATE',
10922       'HR_CAGR_PYS_TEMPLATE',
10923       l_text,
10924       NULL);
10925     --
10926     hr_utility.set_location ('hrstrdbi.insert_formula', 140);
10927     --
10928 l_text := '
10929 /* -------------------------------------------------------
10930     NAME : HR_CAGR_TEMPLATE
10931    ---------------------------------------------------------*/
10932 DEFAULT FOR ASG_EMPLOYMENT_CATEGORY_CODE IS ''FR''
10933 DEFAULT FOR PTU_PER_PERSON_TYPE IS              ''X''
10934 DEFAULT FOR ASG_LABOUR_UNION_MEMBER_FLAG  IS  ''N''
10935 DEFAULT FOR LOC_ADR_CITY                 IS   ''X''
10936 DEFAULT FOR LOC_ADR_COUNTRY             IS    ''X''
10937 DEFAULT FOR PER_AGE                      IS   0
10938 DEFAULT FOR PER_DISABLED                 IS   ''N''
10939 DEFAULT FOR PER_DISABLED                 IS   ''N''
10940 DEFAULT FOR PER_MARITAL_STATUS           IS   ''U''
10941 DEFAULT FOR PER_SEX                      IS   ''M''
10942 VALUE               = to_text(0)
10943 RANGE_FROM          = to_text(0)
10944 RANGE_TO            = to_text(0)
10945 PARENT_SPINE_ID     = ''0''
10946 STEP_ID             = ''0''
10947 FROM_STEP_ID        = ''0''
10948 TO_STEP_ID          = ''0''
10949 GRADE_SPINE_ID      = ''0''
10950 If      (PTU_PER_PERSON_TYPE              LIKE ''Employee%''
10951         AND ASG_EMPLOYMENT_CATEGORY_CODE = ''FR''
10952         AND ASG_LABOUR_UNION_MEMBER_FLAG = ''Y''
10953         AND LOC_ADR_COUNTRY              <> ''FRG''
10954         AND PER_AGE                      < 35
10955         AND PER_DISABLED                 = ''N''          ) THEN
10956 (
10957 VALUE           = to_text(500)
10958 RANGE_FROM      = to_text(500)
10959 RANGE_TO        = to_text(500)
10960 )
10961 If      (PTU_PER_PERSON_TYPE              LIKE ''Employee%''
10962         AND ASG_EMPLOYMENT_CATEGORY_CODE = ''FR''
10963         AND ASG_LABOUR_UNION_MEMBER_FLAG = ''Y''
10964         AND LOC_ADR_COUNTRY              = ''FRG''
10965         AND PER_AGE                      > 45
10966         AND PER_AGE                      < 50           ) THEN
10967 (
10968 VALUE                     = to_text(to_number(VALUE)+100)
10969 RANGE_FROM                = to_text(to_number(VALUE)+100)
10970 RANGE_TO                  = to_text(to_number(VALUE)+200)
10971 )
10972 IF ( PER_DISABLED = ''N'')
10973 THEN
10974 (
10975 VALUE = to_text(to_number(VALUE)+100)
10976 RANGE_FROM = to_text(to_number(RANGE_FROM)+200)
10977 RANGE_TO = to_text(to_number(RANGE_TO)+300)
10978 )
10979 IF ( ASG_EMPLOYMENT_CATEGORY_CODE = ''FR'' )
10980 THEN
10981 (
10982 VALUE = to_text(to_number(VALUE)+999)
10983 RANGE_FROM = to_text(to_number(RANGE_FROM)+444)
10984 RANGE_TO = to_text(to_number(RANGE_TO)+333)
10985 )
10986 IF ( PER_AGE < 35 )
10987 THEN
10988 (
10989 VALUE = to_text(to_number(VALUE)+999)
10990 RANGE_FROM = to_text(to_number(RANGE_FROM)+444)
10991 RANGE_TO = to_text(to_number(RANGE_TO)+333)
10992 )
10993 return      VALUE
10994 ,           RANGE_FROM
10995 /* ,           RANGE_TO
10996 ,           PARENT_SPINE_ID
10997 ,           GRADE_SPINE_ID
10998 ,           FROM_STEP_ID
10999 ,           TO_STEP_ID  */
11000 ';
11001     --
11002     select formula_type_id
11003     into   l_ftype_id
11004     from   ff_formula_types
11005     where  formula_type_name = 'CAGR';
11006     --
11007      INSERT INTO ff_formulas_f
11008      (formula_id,
11009       effective_start_date,
11010       effective_end_date,
11011       business_group_id,
11012       legislation_code,
11013       formula_type_id,
11014       formula_name,
11015       description,
11016       formula_text,
11017       sticky_flag)
11018    VALUES
11019      (ff_formulas_s.nextval,
11020       to_date('01-01-1951','DD-MM-YYYY'),
11021       to_date('31-12-4712','DD-MM-YYYY'),
11022       NULL,
11023       NULL,
11024       l_ftype_id,
11025       'HR_CAGR_TEMPLATE',
11026       'HR_CAGR_TEMPLATE',
11027       l_text,
11028       NULL);
11029     --
11030     hr_utility.set_location ('hrstrdbi.insert_formula', 141);
11031     --
11032 l_text := '
11033 /****************************************************************
11034 FORMULA NAME: PROMOTION_TEMPLATE
11035 FORMULA TYPE: Promotion
11036 DESCRIPTION:  This formula determines whether or not an employee
11037               has received a promotion as of the date earned
11038               being passed into the formula.
11039               When called from the promotions package, this
11040               formula will be used to calculate the number of
11041               promotions which have occurred over a specified
11042               period.
11043               To use this functionality please copy the code
11044               into a new formula named PROMOTION with a type of
11045               Promotion and uncomment the code.
11046               Then, to use the default functionality, set
11047               up an assignment change reason with a meaning of
11048               Promotion in the lookup table EMP_ASSIGN_REASON
11049               This formula can also be customized, by either
11050               using different change reasons, additional change
11051               reasons, or by using different criteria with
11052               which to define promotion.
11053               For instance, additional change reasons of
11054               HQ Move and Position Change could be added in the
11055               same way as Promotion so that the formula will
11056               record a promotion when there is a change reason
11057               of Promotion, HQ Move or Position Change.
11058               Also grade changes could be used as promotion
11059               criteria, for instance, instead of the change
11060               reason.  This would require a different database
11061               item such as ASG_GRADE or ASG_GRADE_DATE_FROM.
11062               The formula could return a count of 1 where
11063               ASG_GRADE_DATE_FROM = DATE_EARNED, thus recording
11064               grade changes as promotions.
11065 INPUTS:
11066 RETURNS:      A count which will return a 1 if a promotion has
11067               occurred,according to rules described above and a
11068               0 if one has not.
11069 DBI Required: none are required, but the default formula uses
11070               asg_change_reason :  the assignment change reason
11071 *****************************************************************/
11072 default for ASG_CHANGE_REASON  is ''Record Reason''
11073 l_count = 0
11074 /**************************************************************
11075 Example code - this will count all occurrences where Assignment
11076 Change Reason is Promotion
11077 **************************************************************/
11078 /****
11079 ==
11080 uncomment code below for default functionality, or customize
11081 ==
11082 ****/
11083 /*
11084 if ASG_CHANGE_REASON = ''Promotion'' then
11085 (
11086   l_count = 1
11087 )
11088 else
11089 (
11090   l_count = 0
11091 )
11092 */
11093 return l_count';
11094 
11095    select formula_type_id
11096    into l_ftype_id
11097    from ff_formula_types
11098    where formula_type_name = 'Promotion';
11099     --
11100     INSERT INTO ff_formulas_f
11101      (formula_id,
11102       effective_start_date,
11103       effective_end_date,
11104       business_group_id,
11105       legislation_code,
11106       formula_type_id,
11107       formula_name,
11108       description,
11109       formula_text,
11110       sticky_flag)
11111    VALUES
11112      (ff_formulas_s.nextval,
11113       to_date('01/01/0001','DD/MM/YYYY'),
11114       to_date('31/12/4712','DD/MM/YYYY'),
11115       NULL,
11116       NULL,
11117       l_ftype_id,
11118       'PROMOTION_TEMPLATE',
11119       'Seeded Promotions Formula',
11120       l_text,
11121       NULL);
11122     --
11123     hr_utility.set_location ('hrstrdbi.insert_formula', 142);
11124     --
11125 --
11126 end insert_formula;
11127 --
11128 procedure insert_user_tables is
11129 --
11130   l_formula_id number;
11131 begin
11132     hr_utility.set_location ('hrstrdbi.insert_user_tables', 1);
11133     --
11134    BEGIN
11135      select formula_id into l_formula_id
11136       FROM ff_formulas_f
11137       WHERE formula_name = 'CHECK_RATE_TYPE'
11138       AND EFFECTIVE_START_DATE = to_date('01-01-0001', 'DD-MM-YYYY')
11139       AND EFFECTIVE_END_DATE = to_date('31-12-4712', 'DD-MM-YYYY');
11140    EXCEPTION
11141       WHEN OTHERS then
11142          l_formula_id := null;
11143    END;
11144 --
11145    insert into pay_user_tables (
11146                               USER_TABLE_ID
11147                             , BUSINESS_GROUP_ID
11148                             , LEGISLATION_CODE
11149                             , RANGE_OR_MATCH
11150                             , USER_KEY_UNITS
11151                             , USER_TABLE_NAME
11152                             , LEGISLATION_SUBGROUP
11153                             , USER_ROW_TITLE
11154                             , LAST_UPDATE_DATE
11155                             , LAST_UPDATED_BY
11156                             , LAST_UPDATE_LOGIN
11157                             , CREATED_BY
11158                             , CREATION_DATE
11159                             )
11160               select          pay_user_tables_s.nextval
11161                             , NULL
11162 		            , NULL
11163                             , 'M'
11164                             , 'T'
11165                             , 'EXCHANGE_RATE_TYPES'
11166                             , NULL
11167                             , 'Processing Type'
11168                             , trunc(sysdate)
11169                             , NULL
11170                             , NULL
11171                             , NULL
11172                             , trunc(sysdate)
11173                 from         sys.dual;
11174    --
11175    insert into pay_user_columns (
11176  		USER_COLUMN_ID
11177 		,BUSINESS_GROUP_ID
11178 		,LEGISLATION_CODE
11179 		,USER_TABLE_ID
11180 		,FORMULA_ID
11181 		,USER_COLUMN_NAME
11182 		,LEGISLATION_SUBGROUP
11183 		,LAST_UPDATE_DATE
11184 		,LAST_UPDATED_BY
11185 		,LAST_UPDATE_LOGIN
11186 		,CREATED_BY
11187 		,CREATION_DATE )
11188 	 select pay_user_columns_s.nextval
11189 		,''
11190 		,NULL
11191 		,udt.user_table_id
11192 		,l_formula_id
11193 		,'Conversion Rate Type'
11194 		,''
11195 		,sysdate
11196 		,1
11197 		,1
11198 		,1
11199 		,sysdate
11200 	 from pay_user_tables udt
11201          where udt.user_table_name = 'EXCHANGE_RATE_TYPES';
11202   --
11203   insert into pay_user_rows (
11204  		USER_ROW_ID
11205  	        ,EFFECTIVE_START_DATE
11206 	        ,EFFECTIVE_END_DATE
11207 		,BUSINESS_GROUP_ID
11208 		,LEGISLATION_CODE
11209 		,USER_TABLE_ID
11210 		,ROW_LOW_RANGE_OR_NAME
11211 		,LEGISLATION_SUBGROUP
11212 		,ROW_HIGH_RANGE
11213 		,LAST_UPDATE_DATE
11214 		,LAST_UPDATED_BY
11215 		,LAST_UPDATE_LOGIN
11216 		,CREATED_BY
11217 		,CREATION_DATE )
11218          select pay_user_rows_s.nextval
11219    	        , to_date('01-01-0001', 'DD-MM-YYYY')
11220 		, to_date('31-12-4712', 'DD-MM-YYYY')
11221 		,NULL
11222 		,NULL
11223 		,udt.user_table_id
11224 		,'BIS'
11225 		,''
11226 		,''
11227 	        ,''
11228 		,1
11229 		,1
11230 		,1
11231 		,sysdate
11232 	from pay_user_tables udt
11233         where udt.user_table_name = 'EXCHANGE_RATE_TYPES';
11234   --
11235   insert into pay_user_rows (
11236  		USER_ROW_ID
11237  	        ,EFFECTIVE_START_DATE
11238 	        ,EFFECTIVE_END_DATE
11239 		,BUSINESS_GROUP_ID
11240 		,LEGISLATION_CODE
11241 		,USER_TABLE_ID
11242 		,ROW_LOW_RANGE_OR_NAME
11243 		,LEGISLATION_SUBGROUP
11244 		,ROW_HIGH_RANGE
11245 		,LAST_UPDATE_DATE
11246 		,LAST_UPDATED_BY
11247 		,LAST_UPDATE_LOGIN
11248 		,CREATED_BY
11249 		,CREATION_DATE )
11250 	 select pay_user_rows_s.nextval
11251    	        , to_date('01-01-0001', 'DD-MM-YYYY')
11252 		, to_date('31-12-4712', 'DD-MM-YYYY')
11253 		,NULL
11254 		,NULL
11255 		,udt.user_table_id
11256 		,'HRMS'
11257 		,''
11258 		,''
11259 	        ,''
11260 		,1
11261 		,1
11262 		,1
11263 		,sysdate
11264 	 from pay_user_tables udt
11265 	 where udt.user_table_name = 'EXCHANGE_RATE_TYPES';
11266   --
11267   insert into pay_user_rows (
11268  		USER_ROW_ID
11269  	        ,EFFECTIVE_START_DATE
11270 	        ,EFFECTIVE_END_DATE
11271 		,BUSINESS_GROUP_ID
11272 		,LEGISLATION_CODE
11273 		,USER_TABLE_ID
11274 		,ROW_LOW_RANGE_OR_NAME
11275 		,LEGISLATION_SUBGROUP
11276 		,ROW_HIGH_RANGE
11277 		,LAST_UPDATE_DATE
11278 		,LAST_UPDATED_BY
11279 		,LAST_UPDATE_LOGIN
11280 		,CREATED_BY
11281 		,CREATION_DATE )
11282 	 select pay_user_rows_s.nextval
11283    	        , to_date('01-01-0001', 'DD-MM-YYYY')
11284 		, to_date('31-12-4712', 'DD-MM-YYYY')
11285 		,NULL
11286 		,NULL
11287 		,udt.user_table_id
11288 		,'PAY'
11289 		,''
11290 		,''
11291 	        ,''
11292 		,1
11293 		,1
11294 		,1
11295 		,sysdate
11296 	 from pay_user_tables udt
11297 	 where udt.user_table_name = 'EXCHANGE_RATE_TYPES';
11298     --
11299     hr_utility.set_location ('hrstrdbi.insert_user_tables', 2);
11300 --
11301 end insert_user_tables;
11302 --
11303 procedure insert_monetary_units is
11304  TYPE eur_info_type is RECORD (name VARCHAR2(150), value NUMBER);
11305  TYPE eur_info_tab IS TABLE OF eur_info_type INDEX BY BINARY_INTEGER;
11306  eur_info eur_info_tab;
11307 begin
11308   eur_info(1).name := 'Five Hundred Euros'; eur_info(1).value := 500;
11309   eur_info(2).name := 'Two Hundred Euros'; eur_info(2).value := 200;
11310   eur_info(3).name := 'One Hundred Euros'; eur_info(3).value := 100;
11311   eur_info(4).name := 'Fifty Euros'; eur_info(4).value := 50;
11312   eur_info(5).name := 'Twenty Euros'; eur_info(5).value := 20;
11313   eur_info(6).name := 'Ten Euros'; eur_info(6).value := 10;
11314   eur_info(7).name := 'Five Euros'; eur_info(7).value := 5;
11315   eur_info(8).name := 'Two Euros'; eur_info(8).value := 2;
11316   eur_info(9).name := 'One Euro'; eur_info(9).value := 1;
11317   eur_info(10).name := 'Fifty Cents'; eur_info(10).value := 0.5;
11318   eur_info(11).name := 'Twenty Cents'; eur_info(11).value := 0.2;
11319   eur_info(12).name := 'Ten Cents'; eur_info(12).value := 0.1;
11320   eur_info(13).name := 'Five Cents'; eur_info(13).value := 0.05;
11321   eur_info(14).name := 'Two Cents'; eur_info(14).value := 0.02;
11322   eur_info(15).name := 'One Cent'; eur_info(15).value := 0.01;
11323 
11324   FOR i in 1..15 LOOP
11325 
11326     insert into pay_monetary_units
11327     (MONETARY_UNIT_ID,
11328      CURRENCY_CODE,
11329      MONETARY_UNIT_NAME,
11330      RELATIVE_VALUE,
11331      COMMENTS,
11332      CREATION_DATE)
11333      values
11334      (pay_monetary_units_s.nextval,
11335       'EUR',
11336       eur_info(i).name,
11337       eur_info(i).value,
11338       NULL,
11339       sysdate);
11340 
11341   END LOOP;
11342 
11343 end insert_monetary_units;
11344 --
11345 procedure create_dbi_startup is
11346 begin
11347     insert_context;
11348     insert_routes_db_items;
11349     insert_functions;
11350     insert_formula;
11351     insert_user_tables;
11352     insert_monetary_units;
11353 end create_dbi_startup;
11354 end hrstrdbi;