DBA Data[Home] [Help]

PACKAGE BODY: APPS.PJI_FM_PLAN_CAL_RLPS

Source


1 PACKAGE BODY PJI_FM_PLAN_CAL_RLPS AS
2 /* $Header: PJIPP04B.pls 120.17.12020000.2 2012/07/18 10:54:16 admarath ship $ */
3 
4 
5 g_package_name VARCHAR2(100) := 'PJI_FM_PLAN_CAL_RLPS';
6 
7 g_worker_id NUMBER := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
8 g_default_prg_level NUMBER        := 0;
9 
10 
11 PROCEDURE PRINT_TIME(p_tag IN VARCHAR2);
12 
13 
14 
15 PROCEDURE CREATE_FP_PA_ROLLUP IS -- Public
16 BEGIN
17   CREATE_FP_PA_PRI_ROLLUP ;
18 EXCEPTION
19   WHEN OTHERS THEN
20     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
21                              p_procedure_name => 'CREATE_FP_PA_ROLLUP');
22     RAISE;
23 END;
24 
25 
26 PROCEDURE CREATE_FP_GL_ROLLUP IS -- Public
27 BEGIN
28   CREATE_FP_GL_PRI_ROLLUP ;
29 EXCEPTION
30   WHEN OTHERS THEN
31     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
32                              p_procedure_name => 'CREATE_FP_GL_ROLLUP');
33     RAISE;
34 END;
35 
36 PROCEDURE CREATE_FP_NONTP_ROLLUP IS -- Public. Not needed.
37 BEGIN
38   NULL;
39 EXCEPTION
40   WHEN OTHERS THEN
41     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
42                              p_procedure_name => 'CREATE_FP_NONTP_ROLLUP');
43     RAISE;
44 END;
45 
46 
47 PROCEDURE CREATE_FP_ENT_ROLLUP IS -- Public
48 BEGIN
49 
50   /* Added for bug 13030627 */
51   if PJI_UTILS.GET_PARAMETER('PJP_SIN_PRG') = 'Y' then
52 
53      PJI_PJP_PRG_PERF_ALL.CREATE_FP_ENT_ROLLUP;
54 
55   else
56 
57   g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
58 
59   INSERT INTO PJI_FP_AGGR_PJP1
60   (
61        WORKER_ID
62      , PRG_LEVEL
63      , PROJECT_ID
64      , PROJECT_ORG_ID
65      , PROJECT_ORGANIZATION_ID
66      , PROJECT_ELEMENT_ID
67      , TIME_ID
68      , PERIOD_TYPE_ID
69      , CALENDAR_TYPE
70      , RBS_AGGR_LEVEL
71      , WBS_ROLLUP_FLAG
72      , PRG_ROLLUP_FLAG
73      , CURR_RECORD_TYPE_ID
74      , CURRENCY_CODE
75      , RBS_ELEMENT_ID
76      , RBS_VERSION_ID
77      , PLAN_VERSION_ID
78      , PLAN_TYPE_ID
79      , RAW_COST
80      , BRDN_COST
81      , REVENUE
82      , BILL_RAW_COST
83      , BILL_BRDN_COST
84      , BILL_LABOR_RAW_COST
85      , BILL_LABOR_BRDN_COST
86      , BILL_LABOR_HRS
87      , EQUIPMENT_RAW_COST
88      , EQUIPMENT_BRDN_COST
89      , CAPITALIZABLE_RAW_COST
90      , CAPITALIZABLE_BRDN_COST
91      , LABOR_RAW_COST
92      , LABOR_BRDN_COST
93      , LABOR_HRS
94      , LABOR_REVENUE
95      , EQUIPMENT_HOURS
96      , BILLABLE_EQUIPMENT_HOURS
97      , SUP_INV_COMMITTED_COST
98      , PO_COMMITTED_COST
99      , PR_COMMITTED_COST
100      , OTH_COMMITTED_COST
101        , ACT_LABOR_HRS
102 	   , ACT_EQUIP_HRS
103 	   , ACT_LABOR_BRDN_COST
104 	   , ACT_EQUIP_BRDN_COST
105 	   , ACT_BRDN_COST
106 	   , ACT_RAW_COST
107 	   , ACT_REVENUE
108          , ACT_LABOR_RAW_COST
109          , ACT_EQUIP_RAW_COST
110 	   , ETC_LABOR_HRS
111 	   , ETC_EQUIP_HRS
112 	   , ETC_LABOR_BRDN_COST
113 	   , ETC_EQUIP_BRDN_COST
114 	   , ETC_BRDN_COST
115          , ETC_RAW_COST
116          , ETC_LABOR_RAW_COST
117          , ETC_EQUIP_RAW_COST
118      , CUSTOM1
119      , CUSTOM2
120      , CUSTOM3
121      , CUSTOM4
122      , CUSTOM5
123      , CUSTOM6
124      , CUSTOM7
125      , CUSTOM8
126      , CUSTOM9
127      , CUSTOM10
128      , CUSTOM11
129      , CUSTOM12
130      , CUSTOM13
131      , CUSTOM14
132      , CUSTOM15
133      , LINE_TYPE
134      , PLAN_TYPE_CODE    /* 4471527 */
135   )
136   SELECT * FROM (
137   SELECT
138       g_worker_id
139     , g_default_prg_level
140     , fact1.PROJECT_ID
141     , fact1.PROJECT_ORG_ID
142     , fact1.PROJECT_ORGANIZATION_ID
143     , fact1.PROJECT_ELEMENT_ID
144     , DECODE (
145                (grouping(qtr.ENT_YEAR_ID) || grouping(period.ENT_QTR_ID) || grouping(period.ENT_PERIOD_ID) )
146              , '000', period.ENT_PERIOD_ID
147              , '001', period.ENT_QTR_ID
148              , '011', qtr.ENT_YEAR_ID
149              , '111', -1 ) TIME_ID
150     , DECODE (
151                (grouping(qtr.ENT_YEAR_ID) || grouping(period.ENT_QTR_ID) || grouping(period.ENT_PERIOD_ID) )
152              , '000', 32
153              , '001', 64
154              , '011', 128
155              , '111', 2048 ) PERIOD_TYPE_ID
156     , DECODE (
157                grouping(qtr.ENT_YEAR_ID)
158              , 0 , 'E'
159              , 'A') CALENDAR_TYPE
160     , RBS_AGGR_LEVEL
161     , WBS_ROLLUP_FLAG
162     , PRG_ROLLUP_FLAG
163     , fact1.CURR_RECORD_TYPE_ID
164     , fact1.CURRENCY_CODE
165     , fact1.RBS_ELEMENT_ID
166     , fact1.RBS_VERSION_ID
167     , fact1.PLAN_VERSION_ID
168     , fact1.plan_type_id
169     , SUM(fact1.RAW_COST)
170     , SUM(fact1.BRDN_COST)
171     , SUM(fact1.REVENUE)
172     , SUM(fact1.BILL_RAW_COST)
173     , SUM(fact1.BILL_BRDN_COST )
174     , SUM(fact1.BILL_LABOR_RAW_COST)
175     , SUM(fact1.BILL_LABOR_BRDN_COST )
176     , SUM(fact1.BILL_LABOR_HRS )
177     , SUM(fact1.EQUIPMENT_RAW_COST )
178     , SUM(fact1.EQUIPMENT_BRDN_COST )
179     , SUM(fact1.CAPITALIZABLE_RAW_COST )
180     , SUM(fact1.CAPITALIZABLE_BRDN_COST )
181     , SUM(fact1.LABOR_RAW_COST )
182     , SUM(fact1.LABOR_BRDN_COST )
183     , SUM(fact1.LABOR_HRS)
184     , SUM(fact1.LABOR_REVENUE)
185     , SUM(fact1.EQUIPMENT_HOURS)
186     , SUM(fact1.BILLABLE_EQUIPMENT_HOURS)
187     , SUM(fact1.SUP_INV_COMMITTED_COST)
188     , SUM(fact1.PO_COMMITTED_COST   )
189     , SUM(fact1.PR_COMMITTED_COST  )
190     , SUM(fact1.OTH_COMMITTED_COST)
191        , SUM(fact1.ACT_LABOR_HRS)
192 	 , SUM(fact1.ACT_EQUIP_HRS)
193 	 , SUM(fact1.ACT_LABOR_BRDN_COST)
194 	 , SUM(fact1.ACT_EQUIP_BRDN_COST)
195 	 , SUM(fact1.ACT_BRDN_COST)
196 	 , SUM(fact1.ACT_RAW_COST)
197 	 , SUM(fact1.ACT_REVENUE)
198        , SUM(fact1.ACT_LABOR_RAW_COST)
199        , SUM(fact1.ACT_EQUIP_RAW_COST)
200 	 , SUM(fact1.ETC_LABOR_HRS)
201 	 , SUM(fact1.ETC_EQUIP_HRS)
202 	 , SUM(fact1.ETC_LABOR_BRDN_COST)
203 	 , SUM(fact1.ETC_EQUIP_BRDN_COST)
204 	 , SUM(fact1.ETC_BRDN_COST )
205        , SUM(fact1.ETC_RAW_COST )
206        , SUM(fact1.ETC_LABOR_RAW_COST)
207        , SUM(fact1.ETC_EQUIP_RAW_COST)
208     , SUM(CUSTOM1	)
209     , SUM(CUSTOM2	)
210     , SUM(CUSTOM3	)
211     , SUM(CUSTOM4	)
212     , SUM(CUSTOM5	)
213     , SUM(CUSTOM6	)
214     , SUM(CUSTOM7	)
215     , SUM(CUSTOM8	)
216     , SUM(CUSTOM9	)
217     , SUM(CUSTOM10	)
218     , SUM(CUSTOM11	)
219     , SUM(CUSTOM12	)
220     , SUM(CUSTOM13	)
221     , SUM(CUSTOM14	)
222     , SUM(CUSTOM15)
223     , 'ENTR'
224     , PLAN_TYPE_CODE     /* 4471527 */
225     FROM
226 	  PJI_FP_AGGR_PJP1 fact1
227       , pji_time_ENT_PERIOD period
228 	, pji_time_ENT_QTR    qtr
229     WHERE
230         fact1.calendar_type = 'E'
231     AND period.ENT_period_id = fact1.time_id
232     AND period.ENT_qtr_id = qtr.ENT_qtr_id
233     AND fact1.period_type_id = 32
234     AND fact1.worker_id = g_worker_id
235 	GROUP BY
236  	  fact1.PROJECT_ID
237     , fact1.PROJECT_ORG_ID
238     , fact1.PROJECT_ORGANIZATION_ID
239     , fact1.PROJECT_ELEMENT_ID
240     , fact1.calendar_type
241     , RBS_AGGR_LEVEL
242     , WBS_ROLLUP_FLAG
243     , PRG_ROLLUP_FLAG
244     , fact1.CURR_RECORD_TYPE_ID
245     , fact1.CURRENCY_CODE
246     , fact1.RBS_ELEMENT_ID
247     , fact1.RBS_VERSION_ID
248     , fact1.PLAN_VERSION_ID
249     , fact1.plan_type_id
250     , fact1.plan_type_code    /*4471527 */
251     , rollup (qtr.ENT_YEAR_ID,
252               period.ENT_QTR_ID,
253               period.ENT_PERIOD_ID))
254    WHERE period_type_id > 32
255      AND period_type_id < 2048;
256 
257    end if;
258 
259 EXCEPTION
260   WHEN OTHERS THEN
261     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
262                              p_procedure_name => 'CREATE_FP_ENT_ROLLUP');
263     RAISE;
264 END;
265 
266 
267 PROCEDURE CREATE_FP_PA_PRI_ROLLUP IS
268 
269     -- l_last_update_date     date   := SYSDATE;
270     -- l_last_updated_by      NUMBER := FND_GLOBAL.USER_ID;
271     -- l_creation_date        date   := SYSDATE;
272     -- l_created_by           NUMBER := FND_GLOBAL.USER_ID;
273     -- l_last_update_login    NUMBER := FND_GLOBAL.LOGIN_ID;
274     l_calendar_type        VARCHAR2(15) := 'P';
275     l_line_type            VARCHAR2(15) := 'PAR';
276 
277 BEGIN
278 
279   /* Added for bug 13030627 */
280   if PJI_UTILS.GET_PARAMETER('PJP_SIN_PRG') = 'Y' then
281 
282      PJI_PJP_PRG_PERF_ALL.CREATE_FP_PA_PRI_ROLLUP;
283 
284   else
285 
286   g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
287 
288   INSERT INTO pji_fp_aggr_pjp1
289   (
290          WORKER_ID
291        , PRG_LEVEL
292        , PROJECT_ID
293        , PROJECT_ORG_ID
294        , PROJECT_ORGANIZATION_ID
295        , PROJECT_ELEMENT_ID
296        , TIME_ID
297        , PERIOD_TYPE_ID
298        , CALENDAR_TYPE
299        , RBS_AGGR_LEVEL
300        , WBS_ROLLUP_FLAG
301        , PRG_ROLLUP_FLAG
302        , CURR_RECORD_TYPE_ID
303        , CURRENCY_CODE
304        , RBS_ELEMENT_ID
305        , RBS_VERSION_ID
306        , PLAN_VERSION_ID
307        , PLAN_TYPE_ID
308        , RAW_COST
309        , BRDN_COST
310        , REVENUE
311        , BILL_RAW_COST
312        , BILL_BRDN_COST
313        , BILL_LABOR_RAW_COST
314        , BILL_LABOR_BRDN_COST
315        , BILL_LABOR_HRS
316        , EQUIPMENT_RAW_COST
317        , EQUIPMENT_BRDN_COST
318        , CAPITALIZABLE_RAW_COST
319        , CAPITALIZABLE_BRDN_COST
320        , LABOR_RAW_COST
321        , LABOR_BRDN_COST
322        , LABOR_HRS
323        , LABOR_REVENUE
324        , EQUIPMENT_HOURS
325        , BILLABLE_EQUIPMENT_HOURS
326        , SUP_INV_COMMITTED_COST
327        , PO_COMMITTED_COST
328        , PR_COMMITTED_COST
329        , OTH_COMMITTED_COST
330        , ACT_LABOR_HRS
331 	   , ACT_EQUIP_HRS
332 	   , ACT_LABOR_BRDN_COST
333 	   , ACT_EQUIP_BRDN_COST
334 	   , ACT_BRDN_COST
335 	   , ACT_RAW_COST
336 	   , ACT_REVENUE
337          , ACT_LABOR_RAW_COST
338          , ACT_EQUIP_RAW_COST
339 	   , ETC_LABOR_HRS
340 	   , ETC_EQUIP_HRS
341 	   , ETC_LABOR_BRDN_COST
342 	   , ETC_EQUIP_BRDN_COST
343 	   , ETC_BRDN_COST
344          , ETC_RAW_COST
345          , ETC_LABOR_RAW_COST
346          , ETC_EQUIP_RAW_COST
347        , CUSTOM1
348        , CUSTOM2
349        , CUSTOM3
350        , CUSTOM4
351        , CUSTOM5
352        , CUSTOM6
353        , CUSTOM7
354        , CUSTOM8
355        , CUSTOM9
356        , CUSTOM10
357        , CUSTOM11
358        , CUSTOM12
359        , CUSTOM13
360        , CUSTOM14
361        , CUSTOM15
362        , LINE_TYPE
363        , PLAN_TYPE_CODE    /* 4471527 */
364        -- , RATE_DANGLING_FLAG
365        -- , TIME_DANGLING_FLAG
366        -- , START_DATE
367        -- , END_DATE
368     )
369   SELECT * FROM (
370   SELECT
371        g_worker_id -- partition id
372     , g_default_prg_level
373     , fact1.PROJECT_ID
374     , fact1.PROJECT_ORG_ID
375     , fact1.PROJECT_ORGANIZATION_ID
376     , fact1.PROJECT_ELEMENT_ID
377     , DECODE (
378                (grouping(qtr.CAL_YEAR_ID) || grouping(period.CAL_QTR_ID) || grouping(period.CAL_PERIOD_ID) )
379              , '000', period.CAL_PERIOD_ID
380              , '001', period.CAL_QTR_ID
381              , '011', qtr.CAL_YEAR_ID
382              , '111', -1 ) TIME_ID
383     , DECODE (
384                (grouping(qtr.CAL_YEAR_ID) || grouping(period.CAL_QTR_ID) || grouping(period.CAL_PERIOD_ID) )
385              , '000', 32
386              , '001', 64
387              , '011', 128
388              , '111', 2048 ) PERIOD_TYPE_ID
389     , DECODE (
390                grouping(qtr.CAL_YEAR_ID)
391              , 0 , l_calendar_type
392              , 'A') CALENDAR_TYPE
393     , fact1.RBS_AGGR_LEVEL
394     , fact1.WBS_ROLLUP_FLAG
395     , fact1.PRG_ROLLUP_FLAG
396     , fact1.CURR_RECORD_TYPE_ID
397     , fact1.CURRENCY_CODE
398     , fact1.RBS_ELEMENT_ID
399     , fact1.RBS_VERSION_ID
400     , fact1.PLAN_VERSION_ID
401 	, fact1.PLAN_TYPE_ID
402     , SUM(fact1.RAW_COST)  RAW_COST
403     , SUM(fact1.BRDN_COST)  BRDN_COST
404     , SUM(fact1.REVENUE)  REVENUE
405     , SUM(fact1.BILL_RAW_COST)  BILL_RAW_COST
406     , SUM(fact1.BILL_BRDN_COST )  BILL_BRDN_COST
407     , SUM(fact1.BILL_LABOR_RAW_COST)  BILL_LABOR_RAW_COST
408     , SUM(fact1.BILL_LABOR_BRDN_COST )  BILL_LABOR_BRDN_COST
409     , SUM(fact1.BILL_LABOR_HRS )  BILL_LABOR_HRS
410     , SUM(fact1.EQUIPMENT_RAW_COST )  EQUIPMENT_RAW_COST
411     , SUM(fact1.EQUIPMENT_BRDN_COST ) EQUIPMENT_BRDN_COST
412     , SUM(fact1.CAPITALIZABLE_RAW_COST ) CAPITALIZABLE_RAW_COST
413     , SUM(fact1.CAPITALIZABLE_BRDN_COST )   CAPITALIZABLE_BRDN_COST
414     , SUM(fact1.LABOR_RAW_COST )  LABOR_RAW_COST
415     , SUM(fact1.LABOR_BRDN_COST ) LABOR_BRDN_COST
416     , SUM(fact1.LABOR_HRS)  LABOR_HRS
417     , SUM(fact1.LABOR_REVENUE)    LABOR_REVENUE
418     , SUM(fact1.EQUIPMENT_HOURS)  EQUIPMENT_HOURS
419     , SUM(fact1.BILLABLE_EQUIPMENT_HOURS)  BILLABLE_EQUIPMENT_HOURS
420     , SUM(fact1.SUP_INV_COMMITTED_COST)   SUP_INV_COMMITTED_COST
421     , SUM(fact1.PO_COMMITTED_COST   )  PO_COMMITTED_COST
422     , SUM(fact1.PR_COMMITTED_COST  ) PR_COMMITTED_COST
423     , SUM(fact1.OTH_COMMITTED_COST)  OTH_COMMITTED_COST
424        , SUM(fact1.ACT_LABOR_HRS)
425 	 , SUM(fact1.ACT_EQUIP_HRS)
426 	 , SUM(fact1.ACT_LABOR_BRDN_COST)
427 	 , SUM(fact1.ACT_EQUIP_BRDN_COST)
428 	 , SUM(fact1.ACT_BRDN_COST)
429 	 , SUM(fact1.ACT_RAW_COST)
430 	 , SUM(fact1.ACT_REVENUE)
431        , SUM(fact1.ACT_LABOR_RAW_COST)
432        , SUM(fact1.ACT_EQUIP_RAW_COST)
433 	 , SUM(fact1.ETC_LABOR_HRS)
434 	 , SUM(fact1.ETC_EQUIP_HRS)
435 	 , SUM(fact1.ETC_LABOR_BRDN_COST)
436 	 , SUM(fact1.ETC_EQUIP_BRDN_COST)
437 	 , SUM(fact1.ETC_BRDN_COST )
438        , SUM(fact1.ETC_RAW_COST )
439        , SUM(fact1.ETC_LABOR_RAW_COST)
440        , SUM(fact1.ETC_EQUIP_RAW_COST)
441     , SUM(CUSTOM1	) CUSTOM1
442     , SUM(CUSTOM2	) CUSTOM2
443     , SUM(CUSTOM3	) CUSTOM3
444     , SUM(CUSTOM4	) CUSTOM4
445     , SUM(CUSTOM5	) CUSTOM5
446     , SUM(CUSTOM6	) CUSTOM6
447     , SUM(CUSTOM7	) CUSTOM7
448     , SUM(CUSTOM8	) CUSTOM8
449     , SUM(CUSTOM9	) CUSTOM9
450     , SUM(CUSTOM10	) CUSTOM10
451     , SUM(CUSTOM11	) CUSTOM11
452     , SUM(CUSTOM12	) CUSTOM12
453     , SUM(CUSTOM13	) CUSTOM13
454     , SUM(CUSTOM14	) CUSTOM14
455     , SUM(CUSTOM15) CUSTOM15
456 	, l_line_type line_type
457    , fact1.plan_type_code   plan_type_code   /* 4471527  */
458     FROM
459 	pji_fp_aggr_pjp1 fact1
460     , pji_time_CAL_PERIOD period
461     , pji_time_CAL_QTR    qtr
462     WHERE
463         fact1.calendar_type = 'P'
464     AND period.cal_period_id = fact1.time_id
465     AND period.cal_qtr_id = qtr.cal_qtr_id
466     AND fact1.period_type_id = 32 -- > 0 -- <>  -1
467     AND fact1.worker_id = g_worker_id
468    GROUP BY
469 	fact1.PROJECT_ID
470     , fact1.PROJECT_ORGANIZATION_ID
471     , fact1.PROJECT_ORG_ID
472     , fact1.PROJECT_ELEMENT_ID
473     , rollup (qtr.CAL_YEAR_ID,
474               period.CAL_QTR_ID,
475               period.CAL_PERIOD_ID)
476     , fact1.calendar_type
477     , fact1.RBS_AGGR_LEVEL
478     , fact1.WBS_ROLLUP_FLAG
479     , fact1.PRG_ROLLUP_FLAG
480     , fact1.CURR_RECORD_TYPE_ID
481     , fact1.CURRENCY_CODE
482     , fact1.RBS_ELEMENT_ID
483     , fact1.RBS_VERSION_ID
484     , fact1.PLAN_VERSION_ID
485     , fact1.PLAN_TYPE_ID
486     , fact1.PLAN_TYPE_CODE )    /* 4471527 */
487     WHERE period_type_id > 32
488      AND period_type_id < 2048;
489 
490 	end if ;
491 
492 EXCEPTION
493   WHEN OTHERS THEN
494     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
495                              p_procedure_name => 'CREATE_FP_PA_PRI_ROLLUP');
496     RAISE;
497 END;
498 
499 
500 PROCEDURE CREATE_FP_GL_PRI_ROLLUP IS
501     l_last_update_login    NUMBER := FND_GLOBAL.LOGIN_ID;
502     l_calendar_type        VARCHAR2(15) := 'G';
503     l_line_type            VARCHAR2(15) := 'GLR';
504 
505 BEGIN
506 
507   /* Added for bug 13030627 */
508   if PJI_UTILS.GET_PARAMETER('PJP_SIN_PRG') = 'Y' then
509 
510      PJI_PJP_PRG_PERF_ALL.CREATE_FP_GL_PRI_ROLLUP;
511 
512   else
513 
514   g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
515 
516   INSERT INTO pji_fp_aggr_pjp1
517   (
518        WORKER_ID
519      , PRG_LEVEL
520      , PROJECT_ID
521      , PROJECT_ORG_ID
522      , PROJECT_ORGANIZATION_ID
523      , PROJECT_ELEMENT_ID
524      , TIME_ID
525      , PERIOD_TYPE_ID
526      , CALENDAR_TYPE
527      , RBS_AGGR_LEVEL
528      , WBS_ROLLUP_FLAG
529      , PRG_ROLLUP_FLAG
530      , CURR_RECORD_TYPE_ID
531      , CURRENCY_CODE
532      , RBS_ELEMENT_ID
533      , RBS_VERSION_ID
534      , PLAN_VERSION_ID
535      , PLAN_TYPE_ID
536      , RAW_COST
537      , BRDN_COST
538      , REVENUE
539      , BILL_RAW_COST
540      , BILL_BRDN_COST
541      , BILL_LABOR_RAW_COST
542      , BILL_LABOR_BRDN_COST
543      , BILL_LABOR_HRS
544      , EQUIPMENT_RAW_COST
545      , EQUIPMENT_BRDN_COST
546      , CAPITALIZABLE_RAW_COST
547      , CAPITALIZABLE_BRDN_COST
548      , LABOR_RAW_COST
549      , LABOR_BRDN_COST
550      , LABOR_HRS
551      , LABOR_REVENUE
552      , EQUIPMENT_HOURS
553      , BILLABLE_EQUIPMENT_HOURS
554      , SUP_INV_COMMITTED_COST
555      , PO_COMMITTED_COST
556      , PR_COMMITTED_COST
557      , OTH_COMMITTED_COST
558        , ACT_LABOR_HRS
559 	   , ACT_EQUIP_HRS
560 	   , ACT_LABOR_BRDN_COST
561 	   , ACT_EQUIP_BRDN_COST
562 	   , ACT_BRDN_COST
563 	   , ACT_RAW_COST
564 	   , ACT_REVENUE
565          , ACT_LABOR_RAW_COST
566          , ACT_EQUIP_RAW_COST
567 	   , ETC_LABOR_HRS
568 	   , ETC_EQUIP_HRS
569 	   , ETC_LABOR_BRDN_COST
570 	   , ETC_EQUIP_BRDN_COST
571 	   , ETC_BRDN_COST
572          , ETC_RAW_COST
573          , ETC_LABOR_RAW_COST
574          , ETC_EQUIP_RAW_COST
575      , CUSTOM1
576      , CUSTOM2
577      , CUSTOM3
578      , CUSTOM4
579      , CUSTOM5
580      , CUSTOM6
581      , CUSTOM7
582      , CUSTOM8
583      , CUSTOM9
584      , CUSTOM10
585      , CUSTOM11
586      , CUSTOM12
587      , CUSTOM13
588      , CUSTOM14
589      , CUSTOM15
590      , LINE_TYPE
591      , PLAN_TYPE_CODE    /* 4471527 */
592   )
593   SELECT * FROM (
594   SELECT  /*+ ordered */  /* Added for bug 11843459 */
595     -- GROUPING(qtr.CAL_YEAR_ID)  gy
596     -- , GROUPING(period.CAL_QTR_ID)  gq
597     -- , GROUPING(period.CAL_PERIOD_ID)  gp
598 	-- ,
599       g_worker_id
600     , g_default_prg_level
601     , fact1.PROJECT_ID
602     , fact1.PROJECT_ORG_ID
603     , fact1.PROJECT_ORGANIZATION_ID
604     -- -- -- , fact1.PARTITION_ID
605     , fact1.PROJECT_ELEMENT_ID
606     , DECODE (
607                (grouping(qtr.CAL_YEAR_ID) || grouping(period.CAL_QTR_ID) || grouping(period.CAL_PERIOD_ID) )
608              , '000', period.CAL_PERIOD_ID
609              , '001', period.CAL_QTR_ID
610              , '011', qtr.CAL_YEAR_ID
611              , '111', -1 ) TIME_ID
612     , DECODE (
613                (grouping(qtr.CAL_YEAR_ID) || grouping(period.CAL_QTR_ID) || grouping(period.CAL_PERIOD_ID) )
614              , '000', 32
615              , '001', 64
616              , '011', 128
617              , '111', 2048 ) PERIOD_TYPE_ID
618     , DECODE (
619                grouping(qtr.CAL_YEAR_ID)
620              , 0 , l_calendar_type
621              , 'A') CALENDAR_TYPE
622     , fact1.RBS_AGGR_LEVEL
623     , fact1.WBS_ROLLUP_FLAG
624     , fact1.PRG_ROLLUP_FLAG
625     , fact1.CURR_RECORD_TYPE_ID
626     , fact1.CURRENCY_CODE
627     , fact1.RBS_ELEMENT_ID
628     , fact1.RBS_VERSION_ID
629     , fact1.PLAN_VERSION_ID
630 	, fact1.PLAN_TYPE_ID
631     , SUM(fact1.RAW_COST)  RAW_COST
632     , SUM(fact1.BRDN_COST)  BRDN_COST
633     , SUM(fact1.REVENUE)  REVENUE
634     , SUM(fact1.BILL_RAW_COST)  BILL_RAW_COST
635     , SUM(fact1.BILL_BRDN_COST )  BILL_BRDN_COST
636     , SUM(fact1.BILL_LABOR_RAW_COST)  BILL_LABOR_RAW_COST
637     , SUM(fact1.BILL_LABOR_BRDN_COST )  BILL_LABOR_BRDN_COST
638     , SUM(fact1.BILL_LABOR_HRS )  BILL_LABOR_HRS
639     , SUM(fact1.EQUIPMENT_RAW_COST )  EQUIPMENT_RAW_COST
640     , SUM(fact1.EQUIPMENT_BRDN_COST ) EQUIPMENT_BRDN_COST
641     , SUM(fact1.CAPITALIZABLE_RAW_COST ) CAPITALIZABLE_RAW_COST
642     , SUM(fact1.CAPITALIZABLE_BRDN_COST )   CAPITALIZABLE_BRDN_COST
643     , SUM(fact1.LABOR_RAW_COST )  LABOR_RAW_COST
644     , SUM(fact1.LABOR_BRDN_COST ) LABOR_BRDN_COST
645     , SUM(fact1.LABOR_HRS)  LABOR_HRS
646     , SUM(fact1.LABOR_REVENUE)    LABOR_REVENUE
647     , SUM(fact1.EQUIPMENT_HOURS)  EQUIPMENT_HOURS
648     , SUM(fact1.BILLABLE_EQUIPMENT_HOURS)  BILLABLE_EQUIPMENT_HOURS
649     , SUM(fact1.SUP_INV_COMMITTED_COST)   SUP_INV_COMMITTED_COST
650     , SUM(fact1.PO_COMMITTED_COST   )  PO_COMMITTED_COST
651     , SUM(fact1.PR_COMMITTED_COST  ) PR_COMMITTED_COST
652     , SUM(fact1.OTH_COMMITTED_COST)  OTH_COMMITTED_COST
653        , SUM(fact1.ACT_LABOR_HRS)
654 	 , SUM(fact1.ACT_EQUIP_HRS)
655 	 , SUM(fact1.ACT_LABOR_BRDN_COST)
656 	 , SUM(fact1.ACT_EQUIP_BRDN_COST)
657 	 , SUM(fact1.ACT_BRDN_COST)
658 	 , SUM(fact1.ACT_RAW_COST)
659 	 , SUM(fact1.ACT_REVENUE)
660        , SUM(fact1.ACT_LABOR_RAW_COST)
661        , SUM(fact1.ACT_EQUIP_RAW_COST)
662 	 , SUM(fact1.ETC_LABOR_HRS)
663 	 , SUM(fact1.ETC_EQUIP_HRS)
664 	 , SUM(fact1.ETC_LABOR_BRDN_COST)
665 	 , SUM(fact1.ETC_EQUIP_BRDN_COST)
666 	 , SUM(fact1.ETC_BRDN_COST )
667        , SUM(fact1.ETC_RAW_COST )
668        , SUM(fact1.ETC_LABOR_RAW_COST)
669        , SUM(fact1.ETC_EQUIP_RAW_COST)
670     , SUM(CUSTOM1	) CUSTOM1
671     , SUM(CUSTOM2	) CUSTOM2
672     , SUM(CUSTOM3	) CUSTOM3
673     , SUM(CUSTOM4	) CUSTOM4
674     , SUM(CUSTOM5	) CUSTOM5
675     , SUM(CUSTOM6	) CUSTOM6
676     , SUM(CUSTOM7	) CUSTOM7
677     , SUM(CUSTOM8	) CUSTOM8
678     , SUM(CUSTOM9	) CUSTOM9
679     , SUM(CUSTOM10	) CUSTOM10
680     , SUM(CUSTOM11	) CUSTOM11
681     , SUM(CUSTOM12	) CUSTOM12
682     , SUM(CUSTOM13	) CUSTOM13
683     , SUM(CUSTOM14	) CUSTOM14
684     , SUM(CUSTOM15) CUSTOM15
685     , l_line_type
686     , fact1.PLAN_TYPE_CODE PLAN_TYPE_CODE   /* 4471527 */
687     FROM
688 	pji_fp_aggr_pjp1 fact1
689     , pji_time_CAL_PERIOD period
690     , pji_time_CAL_QTR    qtr
691     WHERE
692         fact1.calendar_type = l_calendar_type
693     AND period.cal_period_id = fact1.time_id
694     AND period.cal_qtr_id = qtr.cal_qtr_id
695     AND fact1.period_type_id = 32 -- <>  1
696     AND fact1.worker_id = g_worker_id
697    GROUP BY
698 	fact1.PROJECT_ID
699     , fact1.PROJECT_ORGANIZATION_ID
700     , fact1.PROJECT_ORG_ID
701     , fact1.PROJECT_ELEMENT_ID
702     , rollup (qtr.CAL_YEAR_ID,
703               period.CAL_QTR_ID,
704               period.CAL_PERIOD_ID)
705     , fact1.calendar_type
706     , fact1.RBS_AGGR_LEVEL
707     , fact1.WBS_ROLLUP_FLAG
708     , fact1.PRG_ROLLUP_FLAG
709     , fact1.CURR_RECORD_TYPE_ID
710     , fact1.CURRENCY_CODE
711     , fact1.RBS_ELEMENT_ID
712     , fact1.RBS_VERSION_ID
713     , fact1.PLAN_VERSION_ID
714     , fact1.PLAN_TYPE_ID
715     , fact1.PLAN_TYPE_CODE )    /* 4471527 */
716    WHERE period_type_id in (64,128);  /* Modified for bug 11843459 */
717 
718    end if;
719 
720 EXCEPTION
721   WHEN OTHERS THEN
722     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
723                              p_procedure_name => 'CREATE_FP_GL_PRI_ROLLUP');
724     RAISE;
725 END;
726 
727 
728 PROCEDURE CREATE_FP_ALL_T_PRI_ROLLUP (
729   p_calendar_type IN VARCHAR2 := 'G' ) IS
730 
731   l_line_type VARCHAR2(10) := NULL;
732   l_plan_type_id              Number; --Bug 6381284
733 
734 BEGIN
735 
736   /* Added for bug 13030627 */
737   if PJI_UTILS.GET_PARAMETER('PJP_SIN_PRG') = 'Y' then
738 
739      PJI_PJP_PRG_PERF_ALL.CREATE_FP_ALL_T_PRI_ROLLUP;
740 
741   else
742 
743   g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
744 
745   /* Added calendar type 'C' for bug 6381284 */
746   IF (p_calendar_type NOT IN ('P', 'G', 'C') ) THEN
747     RETURN;
748   ELSE
749     IF (p_calendar_type = 'P') THEN
750       l_line_type := 'PAR';
751     ELSIF (p_calendar_type = 'G') THEN
752       l_line_type := 'GLR';
753     ELSE
754       l_line_type := 'CLR';
755     END IF;
756   END IF;
757 
758   SELECT fin_plan_type_id
759         INTO l_plan_type_id
760   FROM PA_FIN_PLAN_TYPES_B
761   WHERE USE_FOR_WORKPLAN_FLAG='Y';
762 
763   /*IF (p_calendar_type NOT IN ('P', 'G') ) THEN
764     RETURN;
765   ELSE
766     IF (p_calendar_type = 'P') THEN
767       l_line_type := 'PAR';
768     ELSE
769       l_line_type := 'GLR';
770     END IF;
771   END IF;*/
772 
773   /*
774     INSERT INTO PJI_FM_EXTR_PLNVER4
775     (
776       WORKER_ID                ,
777       PROJECT_ID               ,
778       PLAN_VERSION_ID          ,
779       WBS_STRUCT_VERSION_ID    ,
780       RBS_STRUCT_VERSION_ID    ,
781       PLAN_TYPE_CODE           ,
782       PLAN_TYPE_ID             ,
783       TIME_PHASED_TYPE_CODE    ,
784       TIME_DANGLING_FLAG       ,
785       RATE_DANGLING_FLAG       ,
786       PROJECT_TYPE_CLASS       ,
787       WP_FLAG                  ,
788 	CURRENT_FLAG             ,
789 	ORIGINAL_FLAG            ,
790 	CURRENT_ORIGINAL_FLAG    ,
791 	BASELINED_FLAG        	 ,
792 	SECONDARY_RBS_FLAG       ,
793       LP_FLAG
794     )
795      (
796 	 SELECT
797             g_worker_id
798           , map.project_id                      project_id
799           , -1                                 plan_version_id
800           , whd.wbs_version_id                 wbs_struct_version_id
801           , rhd.rbs_version_id                 rbs_struct_version_id -- extract for this rbs version id
802           , NULL                               plan_type_code
803           , TO_NUMBER(NULL)                    plan_type_id
804           , 'G'                               time_phased_type_code
805           , NULL                             time_dangling_flag   -- to be used for dangling check.
806           , NULL                             rate_dangling_flag   -- to be used for dangling check.
807           , NULL                             PROJECT_TYPE_CLASS
808           , NULL                              is_wp_flag
809           , NULL                              current_flag
810           , NULL                              original_flag
811           , NULL                              current_original_flag
812           , NULL                              baselined_flag
813           , NULL                              SECONDARY_RBS_FLAG
814           , 'Y'                               lp_flag
815       FROM
816            pji_pjp_proj_batch_map map
817 		 , pji_pjp_rbs_header rhd
818 		 , pji_pjp_wbs_header whd
819       WHERE 1=1
820           -- AND map.PROJECT_ACTIVE_FLAG = 'Y'
821           AND map.worker_id = g_worker_id
822 		  AND whd.plan_version_id = -1
823 		  AND rhd.plan_version_id = -1
824 		  AND whd.project_id = map.project_id
825 		  AND rhd.project_id = map.project_id);
826   */
827 
828 if p_calendar_type = 'C' then /* Added for bug 11843459 */
829  INSERT INTO PJI_FP_AGGR_PJP1
830   (
831        WORKER_ID
832      , PRG_LEVEL
833      , PROJECT_ID
834      , PROJECT_ORG_ID
835      , PROJECT_ORGANIZATION_ID
836      , PROJECT_ELEMENT_ID
837      , TIME_ID
838      , PERIOD_TYPE_ID
839      , CALENDAR_TYPE
840      , RBS_AGGR_LEVEL
841      , WBS_ROLLUP_FLAG
842      , PRG_ROLLUP_FLAG
843      , CURR_RECORD_TYPE_ID
844      , CURRENCY_CODE
845      , RBS_ELEMENT_ID
846      , RBS_VERSION_ID
847      , PLAN_VERSION_ID
848      , PLAN_TYPE_ID
849      , RAW_COST
850      , BRDN_COST
851      , REVENUE
852      , BILL_RAW_COST
853      , BILL_BRDN_COST
854      , BILL_LABOR_RAW_COST
855      , BILL_LABOR_BRDN_COST
856      , BILL_LABOR_HRS
857      , EQUIPMENT_RAW_COST
858      , EQUIPMENT_BRDN_COST
859      , CAPITALIZABLE_RAW_COST
860      , CAPITALIZABLE_BRDN_COST
861      , LABOR_RAW_COST
862      , LABOR_BRDN_COST
863      , LABOR_HRS
864      , LABOR_REVENUE
865      , EQUIPMENT_HOURS
866      , BILLABLE_EQUIPMENT_HOURS
867      , SUP_INV_COMMITTED_COST
868      , PO_COMMITTED_COST
869      , PR_COMMITTED_COST
870      , OTH_COMMITTED_COST
871        , ACT_LABOR_HRS
872 	   , ACT_EQUIP_HRS
873 	   , ACT_LABOR_BRDN_COST
874 	   , ACT_EQUIP_BRDN_COST
875 	   , ACT_BRDN_COST
876 	   , ACT_RAW_COST
877 	   , ACT_REVENUE
878          , ACT_LABOR_RAW_COST
879          , ACT_EQUIP_RAW_COST
880 	   , ETC_LABOR_HRS
881 	   , ETC_EQUIP_HRS
882 	   , ETC_LABOR_BRDN_COST
883 	   , ETC_EQUIP_BRDN_COST
884 	   , ETC_BRDN_COST
885          , ETC_RAW_COST
886          , ETC_LABOR_RAW_COST
887          , ETC_EQUIP_RAW_COST
888      , CUSTOM1
889      , CUSTOM2
890      , CUSTOM3
891      , CUSTOM4
892      , CUSTOM5
893      , CUSTOM6
894      , CUSTOM7
895      , CUSTOM8
896      , CUSTOM9
897      , CUSTOM10
898      , CUSTOM11
899      , CUSTOM12
900      , CUSTOM13
901      , CUSTOM14
902      , CUSTOM15
903      , LINE_TYPE
904      , PLAN_TYPE_CODE   /* 4471527 */
905   )
906   SELECT * FROM (
907   SELECT
908     -- GROUPING(qtr.CAL_YEAR_ID)  gy
909     -- , GROUPING(period.CAL_QTR_ID)  gq
910     -- , GROUPING(period.CAL_PERIOD_ID)  gp
911 	-- ,
912       g_worker_id
913     , g_default_prg_level
914     , fact1.PROJECT_ID
915     , fact1.PROJECT_ORG_ID
916     , fact1.PROJECT_ORGANIZATION_ID
917     -- -- -- , fact1.PARTITION_ID
918     , fact1.PROJECT_ELEMENT_ID
919     , DECODE (
920                (grouping(qtr.CAL_YEAR_ID) || grouping(period.CAL_QTR_ID) || grouping(period.CAL_PERIOD_ID) )
921              , '000', period.CAL_PERIOD_ID
922              , '001', period.CAL_QTR_ID
923              , '011', qtr.CAL_YEAR_ID
924              , '111', -1 ) TIME_ID
925     , DECODE (
926                (grouping(qtr.CAL_YEAR_ID) || grouping(period.CAL_QTR_ID) || grouping(period.CAL_PERIOD_ID) )
927              , '000', 32
928              , '001', 64
929              , '011', 128
930              , '111', 2048 ) PERIOD_TYPE_ID
931     , DECODE (
932                grouping(qtr.CAL_YEAR_ID)
933              , 0 ,p_calendar_type
934              , 'A') CALENDAR_TYPE
935     , fact1.RBS_AGGR_LEVEL
936     , fact1.WBS_ROLLUP_FLAG
937     , fact1.PRG_ROLLUP_FLAG
938     , fact1.CURR_RECORD_TYPE_ID
939     , fact1.CURRENCY_CODE
940     , fact1.RBS_ELEMENT_ID
941     , fact1.RBS_VERSION_ID
942     , fact1.PLAN_VERSION_ID
943 	, fact1.PLAN_TYPE_ID
944     , SUM(fact1.RAW_COST)  RAW_COST
945     , SUM(fact1.BRDN_COST)  BRDN_COST
946     , SUM(fact1.REVENUE)  REVENUE
947     , SUM(fact1.BILL_RAW_COST)  BILL_RAW_COST
948     , SUM(fact1.BILL_BRDN_COST )  BILL_BRDN_COST
949     , SUM(fact1.BILL_LABOR_RAW_COST)  BILL_LABOR_RAW_COST
950     , SUM(fact1.BILL_LABOR_BRDN_COST )  BILL_LABOR_BRDN_COST
951     , SUM(fact1.BILL_LABOR_HRS )  BILL_LABOR_HRS
952     , SUM(fact1.EQUIPMENT_RAW_COST )  EQUIPMENT_RAW_COST
953     , SUM(fact1.EQUIPMENT_BRDN_COST ) EQUIPMENT_BRDN_COST
954     , SUM(fact1.CAPITALIZABLE_RAW_COST ) CAPITALIZABLE_RAW_COST
955     , SUM(fact1.CAPITALIZABLE_BRDN_COST )   CAPITALIZABLE_BRDN_COST
956     , SUM(fact1.LABOR_RAW_COST )  LABOR_RAW_COST
957     , SUM(fact1.LABOR_BRDN_COST ) LABOR_BRDN_COST
958     , SUM(fact1.LABOR_HRS)  LABOR_HRS
959     , SUM(fact1.LABOR_REVENUE)    LABOR_REVENUE
960     , SUM(fact1.EQUIPMENT_HOURS)  EQUIPMENT_HOURS
961     , SUM(fact1.BILLABLE_EQUIPMENT_HOURS)  BILLABLE_EQUIPMENT_HOURS
962     , SUM(fact1.SUP_INV_COMMITTED_COST)   SUP_INV_COMMITTED_COST
963     , SUM(fact1.PO_COMMITTED_COST   )  PO_COMMITTED_COST
964     , SUM(fact1.PR_COMMITTED_COST  ) PR_COMMITTED_COST
965     , SUM(fact1.OTH_COMMITTED_COST)  OTH_COMMITTED_COST
966        , SUM(fact1.ACT_LABOR_HRS)
967 	 , SUM(fact1.ACT_EQUIP_HRS)
968 	 , SUM(fact1.ACT_LABOR_BRDN_COST)
969 	 , SUM(fact1.ACT_EQUIP_BRDN_COST)
970 	 , SUM(fact1.ACT_BRDN_COST)
971 	 , SUM(fact1.ACT_RAW_COST)
972 	 , SUM(fact1.ACT_REVENUE)
973        , SUM(fact1.ACT_LABOR_RAW_COST)
974        , SUM(fact1.ACT_EQUIP_RAW_COST)
975 	 , SUM(fact1.ETC_LABOR_HRS)
976 	 , SUM(fact1.ETC_EQUIP_HRS)
977 	 , SUM(fact1.ETC_LABOR_BRDN_COST)
978 	 , SUM(fact1.ETC_EQUIP_BRDN_COST)
979 	 , SUM(fact1.ETC_BRDN_COST )
980        , SUM(fact1.ETC_RAW_COST )
981        , SUM(fact1.ETC_LABOR_RAW_COST)
982        , SUM(fact1.ETC_EQUIP_RAW_COST)
983     , SUM(CUSTOM1	) CUSTOM1
984     , SUM(CUSTOM2	) CUSTOM2
985     , SUM(CUSTOM3	) CUSTOM3
986     , SUM(CUSTOM4	) CUSTOM4
987     , SUM(CUSTOM5	) CUSTOM5
988     , SUM(CUSTOM6	) CUSTOM6
989     , SUM(CUSTOM7	) CUSTOM7
990     , SUM(CUSTOM8	) CUSTOM8
991     , SUM(CUSTOM9	) CUSTOM9
992     , SUM(CUSTOM10	) CUSTOM10
993     , SUM(CUSTOM11	) CUSTOM11
994     , SUM(CUSTOM12	) CUSTOM12
995     , SUM(CUSTOM13	) CUSTOM13
996     , SUM(CUSTOM14	) CUSTOM14
997     , SUM(CUSTOM15) CUSTOM15
998     ,l_line_type
999     , fact1.PLAN_TYPE_CODE PLAN_TYPE_CODE   /* 4471527 */
1000     FROM
1001 	PJI_FP_AGGR_PJP1 fact1
1002     , pji_time_CAL_PERIOD period
1003     , pji_time_CAL_QTR    qtr
1004     , pji_fm_extr_plnver4 ver
1005     WHERE
1006         -- cal type changes for bug 6381284
1007         --fact1.calendar_type = p_calendar_type
1008         fact1.calendar_type in ( p_calendar_type
1009   				 , DECODE (p_calendar_type ,'C','G','X')
1010 				   , DECODE (p_calendar_type ,'C',
1011 				             DECODE(ver.plan_version_id,-1,'X',-3,'X',-4,'X',
1012 				                    DECODE(fact1.plan_type_id,l_plan_type_id,'P','X')),'X'))
1013     AND period.cal_period_id = fact1.time_id
1014     AND period.cal_qtr_id = qtr.cal_qtr_id
1015     AND fact1.period_type_id = 32 -- <>  -1
1016     AND ver.time_phased_type_code IN ('P', 'G') -- If non time phased plan, non need to create 2048 slice separately.
1017     AND ver.project_id = fact1.project_id
1018     AND ver.plan_version_id = fact1.plan_version_id
1019     AND ver.plan_type_code = fact1.plan_type_code   /* 4471527*/
1020     AND fact1.worker_id = g_worker_id
1021     AND ver.worker_id = g_worker_id
1022     AND fact1.rbs_version_id = NVL(ver.rbs_struct_version_id, -1)
1023    GROUP BY
1024 	fact1.PROJECT_ID
1025     , fact1.PROJECT_ORGANIZATION_ID
1026     , fact1.PROJECT_ORG_ID
1027     -- -- -- , fact1.PARTITION_ID
1028     , fact1.PROJECT_ELEMENT_ID
1029     , rollup (qtr.CAL_YEAR_ID,
1030               period.CAL_QTR_ID,
1031               period.CAL_PERIOD_ID)
1032     , fact1.calendar_type
1033     , fact1.RBS_AGGR_LEVEL
1034     , fact1.WBS_ROLLUP_FLAG
1035     , fact1.PRG_ROLLUP_FLAG
1036     , fact1.CURR_RECORD_TYPE_ID
1037     , fact1.CURRENCY_CODE
1038     , fact1.RBS_ELEMENT_ID
1039     , fact1.RBS_VERSION_ID
1040     , fact1.PLAN_VERSION_ID
1041     , fact1.PLAN_TYPE_ID
1042     , fact1.PLAN_TYPE_CODE )       /*4471527 */
1043    WHERE period_type_id = 2048;
1044 
1045 else /* Added for bug 11843459 */
1046 
1047  INSERT INTO PJI_FP_AGGR_PJP1
1048   (
1049        WORKER_ID
1050      , PRG_LEVEL
1051      , PROJECT_ID
1052      , PROJECT_ORG_ID
1053      , PROJECT_ORGANIZATION_ID
1054      , PROJECT_ELEMENT_ID
1055      , TIME_ID
1056      , PERIOD_TYPE_ID
1057      , CALENDAR_TYPE
1058      , RBS_AGGR_LEVEL
1059      , WBS_ROLLUP_FLAG
1060      , PRG_ROLLUP_FLAG
1061      , CURR_RECORD_TYPE_ID
1062      , CURRENCY_CODE
1063      , RBS_ELEMENT_ID
1064      , RBS_VERSION_ID
1065      , PLAN_VERSION_ID
1066      , PLAN_TYPE_ID
1067      , RAW_COST
1068      , BRDN_COST
1069      , REVENUE
1070      , BILL_RAW_COST
1071      , BILL_BRDN_COST
1072      , BILL_LABOR_RAW_COST
1073      , BILL_LABOR_BRDN_COST
1074      , BILL_LABOR_HRS
1075      , EQUIPMENT_RAW_COST
1076      , EQUIPMENT_BRDN_COST
1077      , CAPITALIZABLE_RAW_COST
1078      , CAPITALIZABLE_BRDN_COST
1079      , LABOR_RAW_COST
1080      , LABOR_BRDN_COST
1081      , LABOR_HRS
1082      , LABOR_REVENUE
1083      , EQUIPMENT_HOURS
1084      , BILLABLE_EQUIPMENT_HOURS
1085      , SUP_INV_COMMITTED_COST
1086      , PO_COMMITTED_COST
1087      , PR_COMMITTED_COST
1088      , OTH_COMMITTED_COST
1089        , ACT_LABOR_HRS
1090 	   , ACT_EQUIP_HRS
1091 	   , ACT_LABOR_BRDN_COST
1092 	   , ACT_EQUIP_BRDN_COST
1093 	   , ACT_BRDN_COST
1094 	   , ACT_RAW_COST
1095 	   , ACT_REVENUE
1096          , ACT_LABOR_RAW_COST
1097          , ACT_EQUIP_RAW_COST
1098 	   , ETC_LABOR_HRS
1099 	   , ETC_EQUIP_HRS
1100 	   , ETC_LABOR_BRDN_COST
1101 	   , ETC_EQUIP_BRDN_COST
1102 	   , ETC_BRDN_COST
1103          , ETC_RAW_COST
1104          , ETC_LABOR_RAW_COST
1105          , ETC_EQUIP_RAW_COST
1106      , CUSTOM1
1107      , CUSTOM2
1108      , CUSTOM3
1109      , CUSTOM4
1110      , CUSTOM5
1111      , CUSTOM6
1112      , CUSTOM7
1113      , CUSTOM8
1114      , CUSTOM9
1115      , CUSTOM10
1116      , CUSTOM11
1117      , CUSTOM12
1118      , CUSTOM13
1119      , CUSTOM14
1120      , CUSTOM15
1121      , LINE_TYPE
1122      , PLAN_TYPE_CODE
1123   )
1124   SELECT * FROM (
1125   SELECT /*+ ordered */
1126       g_worker_id
1127     , g_default_prg_level
1128     , fact1.PROJECT_ID
1129     , fact1.PROJECT_ORG_ID
1130     , fact1.PROJECT_ORGANIZATION_ID
1131     , fact1.PROJECT_ELEMENT_ID
1132     , DECODE (
1133                (grouping(qtr.CAL_YEAR_ID) || grouping(period.CAL_QTR_ID) || grouping(period.CAL_PERIOD_ID) )
1134              , '000', period.CAL_PERIOD_ID
1135              , '001', period.CAL_QTR_ID
1136              , '011', qtr.CAL_YEAR_ID
1137              , '111', -1 ) TIME_ID
1138     , DECODE (
1139                (grouping(qtr.CAL_YEAR_ID) || grouping(period.CAL_QTR_ID) || grouping(period.CAL_PERIOD_ID) )
1140              , '000', 32
1141              , '001', 64
1142              , '011', 128
1143              , '111', 2048 ) PERIOD_TYPE_ID
1144     , DECODE (
1145                grouping(qtr.CAL_YEAR_ID)
1146              , 0 ,p_calendar_type
1147              , 'A') CALENDAR_TYPE
1148     , fact1.RBS_AGGR_LEVEL
1149     , fact1.WBS_ROLLUP_FLAG
1150     , fact1.PRG_ROLLUP_FLAG
1151     , fact1.CURR_RECORD_TYPE_ID
1152     , fact1.CURRENCY_CODE
1153     , fact1.RBS_ELEMENT_ID
1154     , fact1.RBS_VERSION_ID
1155     , fact1.PLAN_VERSION_ID
1156 	, fact1.PLAN_TYPE_ID
1157     , SUM(fact1.RAW_COST)  RAW_COST
1158     , SUM(fact1.BRDN_COST)  BRDN_COST
1159     , SUM(fact1.REVENUE)  REVENUE
1160     , SUM(fact1.BILL_RAW_COST)  BILL_RAW_COST
1161     , SUM(fact1.BILL_BRDN_COST )  BILL_BRDN_COST
1162     , SUM(fact1.BILL_LABOR_RAW_COST)  BILL_LABOR_RAW_COST
1163     , SUM(fact1.BILL_LABOR_BRDN_COST )  BILL_LABOR_BRDN_COST
1164     , SUM(fact1.BILL_LABOR_HRS )  BILL_LABOR_HRS
1165     , SUM(fact1.EQUIPMENT_RAW_COST )  EQUIPMENT_RAW_COST
1166     , SUM(fact1.EQUIPMENT_BRDN_COST ) EQUIPMENT_BRDN_COST
1167     , SUM(fact1.CAPITALIZABLE_RAW_COST ) CAPITALIZABLE_RAW_COST
1168     , SUM(fact1.CAPITALIZABLE_BRDN_COST )   CAPITALIZABLE_BRDN_COST
1169     , SUM(fact1.LABOR_RAW_COST )  LABOR_RAW_COST
1170     , SUM(fact1.LABOR_BRDN_COST ) LABOR_BRDN_COST
1171     , SUM(fact1.LABOR_HRS)  LABOR_HRS
1172     , SUM(fact1.LABOR_REVENUE)    LABOR_REVENUE
1173     , SUM(fact1.EQUIPMENT_HOURS)  EQUIPMENT_HOURS
1174     , SUM(fact1.BILLABLE_EQUIPMENT_HOURS)  BILLABLE_EQUIPMENT_HOURS
1175     , SUM(fact1.SUP_INV_COMMITTED_COST)   SUP_INV_COMMITTED_COST
1176     , SUM(fact1.PO_COMMITTED_COST   )  PO_COMMITTED_COST
1177     , SUM(fact1.PR_COMMITTED_COST  ) PR_COMMITTED_COST
1178     , SUM(fact1.OTH_COMMITTED_COST)  OTH_COMMITTED_COST
1179        , SUM(fact1.ACT_LABOR_HRS)
1180 	 , SUM(fact1.ACT_EQUIP_HRS)
1181 	 , SUM(fact1.ACT_LABOR_BRDN_COST)
1182 	 , SUM(fact1.ACT_EQUIP_BRDN_COST)
1183 	 , SUM(fact1.ACT_BRDN_COST)
1184 	 , SUM(fact1.ACT_RAW_COST)
1185 	 , SUM(fact1.ACT_REVENUE)
1186        , SUM(fact1.ACT_LABOR_RAW_COST)
1187        , SUM(fact1.ACT_EQUIP_RAW_COST)
1188 	 , SUM(fact1.ETC_LABOR_HRS)
1189 	 , SUM(fact1.ETC_EQUIP_HRS)
1190 	 , SUM(fact1.ETC_LABOR_BRDN_COST)
1191 	 , SUM(fact1.ETC_EQUIP_BRDN_COST)
1192 	 , SUM(fact1.ETC_BRDN_COST )
1193        , SUM(fact1.ETC_RAW_COST )
1194        , SUM(fact1.ETC_LABOR_RAW_COST)
1195        , SUM(fact1.ETC_EQUIP_RAW_COST)
1196     , SUM(CUSTOM1	) CUSTOM1
1197     , SUM(CUSTOM2	) CUSTOM2
1198     , SUM(CUSTOM3	) CUSTOM3
1199     , SUM(CUSTOM4	) CUSTOM4
1200     , SUM(CUSTOM5	) CUSTOM5
1201     , SUM(CUSTOM6	) CUSTOM6
1202     , SUM(CUSTOM7	) CUSTOM7
1203     , SUM(CUSTOM8	) CUSTOM8
1204     , SUM(CUSTOM9	) CUSTOM9
1205     , SUM(CUSTOM10	) CUSTOM10
1206     , SUM(CUSTOM11	) CUSTOM11
1207     , SUM(CUSTOM12	) CUSTOM12
1208     , SUM(CUSTOM13	) CUSTOM13
1209     , SUM(CUSTOM14	) CUSTOM14
1210     , SUM(CUSTOM15) CUSTOM15
1211     ,l_line_type
1212     , fact1.PLAN_TYPE_CODE PLAN_TYPE_CODE
1213     FROM
1214 	PJI_FP_AGGR_PJP1 fact1
1215     , pji_time_CAL_PERIOD period
1216     , pji_time_CAL_QTR    qtr
1217     , pji_fm_extr_plnver4 ver
1218     WHERE
1219         fact1.calendar_type = p_calendar_type
1220     AND period.cal_period_id = fact1.time_id
1221     AND period.cal_qtr_id = qtr.cal_qtr_id
1222     AND fact1.period_type_id = 32 -- <>  -1
1223     AND ver.time_phased_type_code IN ('P', 'G') -- If non time phased plan, non need to create 2048 slice separately.
1224     AND ver.project_id = fact1.project_id
1225     AND ver.plan_version_id = fact1.plan_version_id
1226     AND ver.plan_type_code = fact1.plan_type_code
1227     AND fact1.worker_id = g_worker_id
1228     AND ver.worker_id = g_worker_id
1229     AND fact1.rbs_version_id = NVL(ver.rbs_struct_version_id, -1)
1230    GROUP BY
1231 	fact1.PROJECT_ID
1232     , fact1.PROJECT_ORGANIZATION_ID
1233     , fact1.PROJECT_ORG_ID
1234     , fact1.PROJECT_ELEMENT_ID
1235     , rollup (qtr.CAL_YEAR_ID,
1236               period.CAL_QTR_ID,
1237               period.CAL_PERIOD_ID)
1238     , fact1.calendar_type
1239     , fact1.RBS_AGGR_LEVEL
1240     , fact1.WBS_ROLLUP_FLAG
1241     , fact1.PRG_ROLLUP_FLAG
1242     , fact1.CURR_RECORD_TYPE_ID
1243     , fact1.CURRENCY_CODE
1244     , fact1.RBS_ELEMENT_ID
1245     , fact1.RBS_VERSION_ID
1246     , fact1.PLAN_VERSION_ID
1247     , fact1.PLAN_TYPE_ID
1248     , fact1.PLAN_TYPE_CODE )
1249    WHERE period_type_id = 2048;
1250 
1251 end if; /* Added for bug 11843459 */
1252    -- DELETE FROM PJI_FM_EXTR_PLNVER4
1253    -- WHERE plan_version_id = -1
1254    --  AND worker_id = g_worker_id;
1255 
1256 end if;
1257 
1258 EXCEPTION
1259   WHEN OTHERS THEN
1260     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
1261                              p_procedure_name => 'CREATE_FP_ALL_T_PRI_ROLLUP');
1262     RAISE;
1263 END;
1264 
1265 
1266 PROCEDURE CREATE_FP_ALLT_PRI_AGGREGATE IS
1267 BEGIN
1268  NULL;
1269 EXCEPTION
1270   WHEN OTHERS THEN
1271     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
1272                              p_procedure_name => 'CREATE_FP_ALLT_PRI_AGGREGATE');
1273     RAISE;
1274 END;
1275 
1276 
1277 PROCEDURE CREATE_FP_ALLT_SEC_AGGREGATE IS
1278 BEGIN
1279 
1280   NULL;
1281 
1282 EXCEPTION
1283   WHEN OTHERS THEN
1284     RAISE;
1285 END;
1286 
1287 
1288 PROCEDURE CREATE_FP_PA_SEC_ROLLUP IS
1289 BEGIN
1290   NULL;
1291 EXCEPTION
1292   WHEN OTHERS THEN
1293     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
1294                              p_procedure_name => 'CREATE_FP_PA_SEC_ROLLUP');
1295     RAISE;
1296 END;
1297 
1298 
1299 PROCEDURE CREATE_FP_GL_SEC_ROLLUP IS
1300 BEGIN
1301 
1302   NULL;
1303 
1304 EXCEPTION
1305   WHEN OTHERS THEN
1306     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
1307                              p_procedure_name => 'CREATE_FP_GL_SEC_ROLLUP');
1308     RAISE;
1309 END;
1310 
1311 
1312 PROCEDURE CREATE_FP_ENT_SEC_ROLLUP IS
1313 BEGIN
1314   NULL;
1315 EXCEPTION
1316   WHEN OTHERS THEN
1317     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
1318                              p_procedure_name => 'CREATE_FP_ENT_SEC_ROLLUP');
1319     RAISE;
1320 END;
1321 
1322 
1323 PROCEDURE CREATE_AC_PA_ROLLUP IS
1324 BEGIN
1325 
1326     g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
1327 
1328     INSERT INTO PJI_AC_AGGR_PJP1
1329     (
1330        WORKER_ID
1331      , PRG_LEVEL
1332      , PROJECT_ID
1333      , PROJECT_ORG_ID
1334      , PROJECT_ORGANIZATION_ID
1335      -- , PARTITION_ID
1336      , PROJECT_ELEMENT_ID
1337      , TIME_ID
1338      , PERIOD_TYPE_ID
1339      , CALENDAR_TYPE
1340      , WBS_ROLLUP_FLAG
1341      , PRG_ROLLUP_FLAG
1342      , CURR_RECORD_TYPE_ID
1343      , CURRENCY_CODE
1344      , REVENUE
1345      , INITIAL_FUNDING_AMOUNT
1346      , INITIAL_FUNDING_COUNT
1347      , ADDITIONAL_FUNDING_AMOUNT
1348      , ADDITIONAL_FUNDING_COUNT
1349      , CANCELLED_FUNDING_AMOUNT
1350      , CANCELLED_FUNDING_COUNT
1351      , FUNDING_ADJUSTMENT_AMOUNT
1352      , FUNDING_ADJUSTMENT_COUNT
1353      , REVENUE_WRITEOFF
1354      , AR_INVOICE_AMOUNT
1355      , AR_INVOICE_COUNT
1356      , AR_CASH_APPLIED_AMOUNT
1357      , AR_INVOICE_WRITE_OFF_AMOUNT
1358      , AR_INVOICE_WRITEOFF_COUNT
1359      , AR_CREDIT_MEMO_AMOUNT
1360      , AR_CREDIT_MEMO_COUNT
1361      , UNBILLED_RECEIVABLES
1362      , UNEARNED_REVENUE
1363      , AR_UNAPPR_INVOICE_AMOUNT
1364      , AR_UNAPPR_INVOICE_COUNT
1365      , AR_APPR_INVOICE_AMOUNT
1366      , AR_APPR_INVOICE_COUNT
1367      , AR_AMOUNT_DUE
1368      , AR_COUNT_DUE
1369      , AR_AMOUNT_OVERDUE
1370      , AR_COUNT_OVERDUE
1371      , DORMANT_BACKLOG_INACTIV
1372      , DORMANT_BACKLOG_START
1373      , LOST_BACKLOG
1374      , ACTIVE_BACKLOG
1375      , REVENUE_AT_RISK
1376      , CUSTOM1
1377      , CUSTOM2
1378      , CUSTOM3
1379      , CUSTOM4
1380      , CUSTOM5
1381      , CUSTOM6
1382      , CUSTOM7
1383      , CUSTOM8
1384      , CUSTOM9
1385      , CUSTOM10
1386      , CUSTOM11
1387      , CUSTOM12
1388      , CUSTOM13
1389      , CUSTOM14
1390      , CUSTOM15
1391     )
1392   SELECT * FROM (
1393     SELECT
1394       -- GROUPING(qtr.CAL_YEAR_ID)  gy
1395       -- , GROUPING(period.CAL_QTR_ID)  gq
1396       -- , GROUPING(period.CAL_PERIOD_ID)  gp
1397       -- ,
1398        g_worker_id
1399      , g_default_prg_level
1400      , fact1.PROJECT_ID
1401      , fact1.PROJECT_ORG_ID
1402      , fact1.PROJECT_ORGANIZATION_ID
1403      -- -- -- , fact1.PARTITION_ID
1404      , fact1.PROJECT_ELEMENT_ID
1405      , DECODE (
1406                (grouping(qtr.CAL_YEAR_ID) || grouping(period.CAL_QTR_ID) || grouping(period.CAL_PERIOD_ID) )
1407              , '000', period.CAL_PERIOD_ID
1408              , '001', period.CAL_QTR_ID
1409              , '011', qtr.CAL_YEAR_ID
1410              , '111', -1 ) TIME_ID
1411      , DECODE (
1412                (grouping(qtr.CAL_YEAR_ID) || grouping(period.CAL_QTR_ID) || grouping(period.CAL_PERIOD_ID) )
1413              , '000', 32
1414              , '001', 64
1415              , '011', 128
1416              , '111', 2048 ) PERIOD_TYPE_ID
1417      , fact1.CALENDAR_TYPE
1418      , fact1.WBS_ROLLUP_FLAG
1419      , fact1.PRG_ROLLUP_FLAG
1420      , fact1.CURR_RECORD_TYPE_ID
1421      , fact1.CURRENCY_CODE
1422      , SUM(fact1.REVENUE )
1423      , SUM(fact1.INITIAL_FUNDING_AMOUNT )
1424      , SUM(fact1.INITIAL_FUNDING_COUNT)
1425      , SUM(fact1.ADDITIONAL_FUNDING_AMOUNT)
1426      , SUM(fact1.ADDITIONAL_FUNDING_COUNT  )
1427      , SUM(fact1.CANCELLED_FUNDING_AMOUNT)
1428      , SUM(fact1.CANCELLED_FUNDING_COUNT)
1429      , SUM(fact1.FUNDING_ADJUSTMENT_AMOUNT)
1430      , SUM(fact1.FUNDING_ADJUSTMENT_COUNT)
1431      , SUM(fact1.REVENUE_WRITEOFF)
1432      , SUM(fact1.AR_INVOICE_AMOUNT)
1433      , SUM(fact1.AR_INVOICE_COUNT)
1434      , SUM(fact1.AR_CASH_APPLIED_AMOUNT)
1435      , SUM(fact1.AR_INVOICE_WRITE_OFF_AMOUNT)
1436      , SUM(fact1.AR_INVOICE_WRITEOFF_COUNT)
1437      , SUM(fact1.AR_CREDIT_MEMO_AMOUNT)
1438      , SUM(fact1.AR_CREDIT_MEMO_COUNT)
1439      , SUM(fact1.UNBILLED_RECEIVABLES)
1440      , SUM(fact1.UNEARNED_REVENUE)
1441      , SUM(fact1.AR_UNAPPR_INVOICE_AMOUNT)
1442      , SUM(fact1.AR_UNAPPR_INVOICE_COUNT)
1443      , SUM(fact1.AR_APPR_INVOICE_AMOUNT)
1444      , SUM(fact1.AR_APPR_INVOICE_COUNT)
1445      , SUM(fact1.AR_AMOUNT_DUE)
1446      , SUM(fact1.AR_COUNT_DUE)
1447      , SUM(fact1.AR_AMOUNT_OVERDUE)
1448      , SUM(fact1.AR_COUNT_OVERDUE)
1449      , SUM(fact1.DORMANT_BACKLOG_INACTIV)
1450      , SUM(fact1.DORMANT_BACKLOG_START)
1451      , SUM(fact1.LOST_BACKLOG)
1452      , SUM(fact1.ACTIVE_BACKLOG)
1453      , SUM(fact1.REVENUE_AT_RISK)
1454      , SUM(fact1.CUSTOM1)
1455      , SUM(fact1.CUSTOM2)
1456      , SUM(fact1.CUSTOM3)
1457      , SUM(fact1.CUSTOM4)
1458      , SUM(fact1.CUSTOM5)
1459      , SUM(fact1.CUSTOM6)
1460      , SUM(fact1.CUSTOM7)
1461      , SUM(fact1.CUSTOM8)
1462      , SUM(fact1.CUSTOM9)
1463      , SUM(fact1.CUSTOM10)
1464      , SUM(fact1.CUSTOM11)
1465      , SUM(fact1.CUSTOM12)
1466      , SUM(fact1.CUSTOM13)
1467      , SUM(fact1.CUSTOM14)
1468      , SUM(fact1.CUSTOM15)
1469     FROM
1470       PJI_AC_AGGR_PJP1 fact1
1471     , pji_time_CAL_PERIOD period
1472 	, pji_time_CAL_QTR    qtr
1473     WHERE
1474         fact1.calendar_type = 'P'
1475     AND period.cal_period_id = fact1.time_id
1476     AND period.cal_qtr_id = qtr.cal_qtr_id
1477     AND fact1.period_type_id = 32
1478     AND fact1.worker_id = g_worker_id
1479 	GROUP BY
1480        fact1.PROJECT_ID
1481      , fact1.PROJECT_ORG_ID
1482      , fact1.PROJECT_ORGANIZATION_ID
1483      -- -- -- , fact1.PARTITION_ID
1484      , fact1.PROJECT_ELEMENT_ID
1485      , fact1.CALENDAR_TYPE
1486      , rollup (qtr.CAL_YEAR_ID,
1487                period.CAL_QTR_ID,
1488                period.CAL_PERIOD_ID)
1489      , fact1.WBS_ROLLUP_FLAG
1490      , fact1.PRG_ROLLUP_FLAG
1491      , fact1.CURR_RECORD_TYPE_ID
1492      , fact1.CURRENCY_CODE  )
1493    WHERE 1=1
1494      AND period_type_id > 32
1495      AND period_type_id < 2048;
1496 
1497 
1498 EXCEPTION
1499   WHEN OTHERS THEN
1500     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
1501                              p_procedure_name => 'CREATE_AC_PA_ROLLUP');
1502     RAISE;
1503 END;
1504 
1505 
1506 PROCEDURE CREATE_AC_GL_ROLLUP IS
1507 BEGIN
1508 
1509     g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
1510 
1511     INSERT INTO PJI_AC_AGGR_PJP1
1512     (
1513        worker_id
1514      , PRG_LEVEL
1515      , PROJECT_ID
1516      , PROJECT_ORG_ID
1517      , PROJECT_ORGANIZATION_ID
1518      -- , PARTITION_ID
1519      , PROJECT_ELEMENT_ID
1520      , TIME_ID
1521      , PERIOD_TYPE_ID
1522      , CALENDAR_TYPE
1523      , WBS_ROLLUP_FLAG
1524      , PRG_ROLLUP_FLAG
1525      , CURR_RECORD_TYPE_ID
1526      , CURRENCY_CODE
1527      , REVENUE
1528      , INITIAL_FUNDING_AMOUNT
1529      , INITIAL_FUNDING_COUNT
1530      , ADDITIONAL_FUNDING_AMOUNT
1531      , ADDITIONAL_FUNDING_COUNT
1532      , CANCELLED_FUNDING_AMOUNT
1533      , CANCELLED_FUNDING_COUNT
1534      , FUNDING_ADJUSTMENT_AMOUNT
1535      , FUNDING_ADJUSTMENT_COUNT
1536      , REVENUE_WRITEOFF
1537      , AR_INVOICE_AMOUNT
1538      , AR_INVOICE_COUNT
1539      , AR_CASH_APPLIED_AMOUNT
1540      , AR_INVOICE_WRITE_OFF_AMOUNT
1541      , AR_INVOICE_WRITEOFF_COUNT
1542      , AR_CREDIT_MEMO_AMOUNT
1543      , AR_CREDIT_MEMO_COUNT
1544      , UNBILLED_RECEIVABLES
1545      , UNEARNED_REVENUE
1546      , AR_UNAPPR_INVOICE_AMOUNT
1547      , AR_UNAPPR_INVOICE_COUNT
1548      , AR_APPR_INVOICE_AMOUNT
1549      , AR_APPR_INVOICE_COUNT
1550      , AR_AMOUNT_DUE
1551      , AR_COUNT_DUE
1552      , AR_AMOUNT_OVERDUE
1553      , AR_COUNT_OVERDUE
1554      , DORMANT_BACKLOG_INACTIV
1555      , DORMANT_BACKLOG_START
1556      , LOST_BACKLOG
1557      , ACTIVE_BACKLOG
1558      , REVENUE_AT_RISK
1559      , CUSTOM1
1560      , CUSTOM2
1561      , CUSTOM3
1562      , CUSTOM4
1563      , CUSTOM5
1564      , CUSTOM6
1565      , CUSTOM7
1566      , CUSTOM8
1567      , CUSTOM9
1568      , CUSTOM10
1569      , CUSTOM11
1570      , CUSTOM12
1571      , CUSTOM13
1572      , CUSTOM14
1573      , CUSTOM15
1574     )
1575   SELECT * FROM (
1576     SELECT
1577       -- GROUPING(qtr.CAL_YEAR_ID)  gy
1578       -- , GROUPING(period.CAL_QTR_ID)  gq
1579       -- , GROUPING(period.CAL_PERIOD_ID)  gp
1580       -- ,
1581        g_worker_id
1582      , g_default_prg_level
1583      , fact1.PROJECT_ID
1584      , fact1.PROJECT_ORG_ID
1585      , fact1.PROJECT_ORGANIZATION_ID
1586      -- -- -- , fact1.PARTITION_ID
1587      , fact1.PROJECT_ELEMENT_ID
1588      , DECODE (
1589                (grouping(qtr.CAL_YEAR_ID) || grouping(period.CAL_QTR_ID) || grouping(period.CAL_PERIOD_ID) )
1590              , '000', period.CAL_PERIOD_ID
1591              , '001', period.CAL_QTR_ID
1592              , '011', qtr.CAL_YEAR_ID
1593              , '111', -1 ) TIME_ID
1594      , DECODE (
1595                (grouping(qtr.CAL_YEAR_ID) || grouping(period.CAL_QTR_ID) || grouping(period.CAL_PERIOD_ID) )
1596              , '000', 32
1597              , '001', 64
1598              , '011', 128
1599              , '111', 2048 ) PERIOD_TYPE_ID
1600      , fact1.CALENDAR_TYPE
1601      , fact1.WBS_ROLLUP_FLAG
1602      , fact1.PRG_ROLLUP_FLAG
1603      , fact1.CURR_RECORD_TYPE_ID
1604      , fact1.CURRENCY_CODE
1605      , SUM(fact1.REVENUE )
1606      , SUM(fact1.INITIAL_FUNDING_AMOUNT )
1607      , SUM(fact1.INITIAL_FUNDING_COUNT)
1608      , SUM(fact1.ADDITIONAL_FUNDING_AMOUNT)
1609      , SUM(fact1.ADDITIONAL_FUNDING_COUNT  )
1610      , SUM(fact1.CANCELLED_FUNDING_AMOUNT)
1611      , SUM(fact1.CANCELLED_FUNDING_COUNT)
1612      , SUM(fact1.FUNDING_ADJUSTMENT_AMOUNT)
1613      , SUM(fact1.FUNDING_ADJUSTMENT_COUNT)
1614      , SUM(fact1.REVENUE_WRITEOFF)
1615      , SUM(fact1.AR_INVOICE_AMOUNT)
1616      , SUM(fact1.AR_INVOICE_COUNT)
1617      , SUM(fact1.AR_CASH_APPLIED_AMOUNT)
1618      , SUM(fact1.AR_INVOICE_WRITE_OFF_AMOUNT)
1619      , SUM(fact1.AR_INVOICE_WRITEOFF_COUNT)
1620      , SUM(fact1.AR_CREDIT_MEMO_AMOUNT)
1621      , SUM(fact1.AR_CREDIT_MEMO_COUNT)
1622      , SUM(fact1.UNBILLED_RECEIVABLES)
1623      , SUM(fact1.UNEARNED_REVENUE)
1624      , SUM(fact1.AR_UNAPPR_INVOICE_AMOUNT)
1625      , SUM(fact1.AR_UNAPPR_INVOICE_COUNT)
1626      , SUM(fact1.AR_APPR_INVOICE_AMOUNT)
1627      , SUM(fact1.AR_APPR_INVOICE_COUNT)
1628      , SUM(fact1.AR_AMOUNT_DUE)
1629      , SUM(fact1.AR_COUNT_DUE)
1630      , SUM(fact1.AR_AMOUNT_OVERDUE)
1631      , SUM(fact1.AR_COUNT_OVERDUE)
1632      , SUM(fact1.DORMANT_BACKLOG_INACTIV)
1633      , SUM(fact1.DORMANT_BACKLOG_START)
1634      , SUM(fact1.LOST_BACKLOG)
1635      , SUM(fact1.ACTIVE_BACKLOG)
1636      , SUM(fact1.REVENUE_AT_RISK)
1637      , SUM(fact1.CUSTOM1)
1638      , SUM(fact1.CUSTOM2)
1639      , SUM(fact1.CUSTOM3)
1640      , SUM(fact1.CUSTOM4)
1641      , SUM(fact1.CUSTOM5)
1642      , SUM(fact1.CUSTOM6)
1643      , SUM(fact1.CUSTOM7)
1644      , SUM(fact1.CUSTOM8)
1645      , SUM(fact1.CUSTOM9)
1646      , SUM(fact1.CUSTOM10)
1647      , SUM(fact1.CUSTOM11)
1648      , SUM(fact1.CUSTOM12)
1649      , SUM(fact1.CUSTOM13)
1650      , SUM(fact1.CUSTOM14)
1651      , SUM(fact1.CUSTOM15)
1652     FROM
1653       PJI_AC_AGGR_PJP1 fact1
1654     , pji_time_CAL_PERIOD period
1655 	, pji_time_CAL_QTR    qtr
1656     WHERE
1657           fact1.calendar_type = 'G'
1658       AND period.cal_period_id = fact1.time_id
1659 	AND period.cal_qtr_id = qtr.cal_qtr_id
1660       AND fact1.period_type_id = 32
1661       AND fact1.worker_id = g_worker_id
1662     GROUP BY
1663        fact1.PROJECT_ID
1664      , fact1.PROJECT_ORG_ID
1665      , fact1.PROJECT_ORGANIZATION_ID
1666      -- -- -- , fact1.PARTITION_ID
1667      , fact1.PROJECT_ELEMENT_ID
1668      , fact1.CALENDAR_TYPE
1669      , rollup (qtr.CAL_YEAR_ID,
1670                period.CAL_QTR_ID,
1671                period.CAL_PERIOD_ID)
1672      , fact1.WBS_ROLLUP_FLAG
1673      , fact1.PRG_ROLLUP_FLAG
1674      , fact1.CURR_RECORD_TYPE_ID
1675      , fact1.CURRENCY_CODE)
1676    WHERE 1=1
1677      AND period_type_id > 32
1678      AND period_type_id < 2048;
1679 
1680 EXCEPTION
1681   WHEN OTHERS THEN
1682     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
1683                              p_procedure_name => 'CREATE_AC_GL_ROLLUP');
1684     RAISE;
1685 END;
1686 
1687 
1688 PROCEDURE CREATE_AC_ENT_ROLLUP IS
1689 BEGIN
1690 
1691   g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
1692 
1693   INSERT INTO PJI_AC_AGGR_PJP1
1694   (
1695        worker_id
1696      , PRG_LEVEL
1697      , PROJECT_ID
1698      , PROJECT_ORG_ID
1699      , PROJECT_ORGANIZATION_ID
1700      -- , PARTITION_ID
1701      , PROJECT_ELEMENT_ID
1702      , TIME_ID
1703      , PERIOD_TYPE_ID
1704      , CALENDAR_TYPE
1705      , WBS_ROLLUP_FLAG
1706      , PRG_ROLLUP_FLAG
1707      , CURR_RECORD_TYPE_ID
1708      , CURRENCY_CODE
1709      , REVENUE
1710      , INITIAL_FUNDING_AMOUNT
1711      , INITIAL_FUNDING_COUNT
1712      , ADDITIONAL_FUNDING_AMOUNT
1713      , ADDITIONAL_FUNDING_COUNT
1714      , CANCELLED_FUNDING_AMOUNT
1715      , CANCELLED_FUNDING_COUNT
1716      , FUNDING_ADJUSTMENT_AMOUNT
1717      , FUNDING_ADJUSTMENT_COUNT
1718      , REVENUE_WRITEOFF
1719      , AR_INVOICE_AMOUNT
1720      , AR_INVOICE_COUNT
1721      , AR_CASH_APPLIED_AMOUNT
1722      , AR_INVOICE_WRITE_OFF_AMOUNT
1723      , AR_INVOICE_WRITEOFF_COUNT
1724      , AR_CREDIT_MEMO_AMOUNT
1725      , AR_CREDIT_MEMO_COUNT
1726      , UNBILLED_RECEIVABLES
1727      , UNEARNED_REVENUE
1728      , AR_UNAPPR_INVOICE_AMOUNT
1729      , AR_UNAPPR_INVOICE_COUNT
1730      , AR_APPR_INVOICE_AMOUNT
1731      , AR_APPR_INVOICE_COUNT
1732      , AR_AMOUNT_DUE
1733      , AR_COUNT_DUE
1734      , AR_AMOUNT_OVERDUE
1735      , AR_COUNT_OVERDUE
1736      , DORMANT_BACKLOG_INACTIV
1737      , DORMANT_BACKLOG_START
1738      , LOST_BACKLOG
1739      , ACTIVE_BACKLOG
1740      , REVENUE_AT_RISK
1741      , CUSTOM1
1742      , CUSTOM2
1743      , CUSTOM3
1744      , CUSTOM4
1745      , CUSTOM5
1746      , CUSTOM6
1747      , CUSTOM7
1748      , CUSTOM8
1749      , CUSTOM9
1750      , CUSTOM10
1751      , CUSTOM11
1752      , CUSTOM12
1753      , CUSTOM13
1754      , CUSTOM14
1755      , CUSTOM15
1756   )
1757   SELECT * FROM (
1758   SELECT
1759       -- GROUPING(qtr.CAL_YEAR_ID)  gy
1760       -- , GROUPING(period.CAL_QTR_ID)  gq
1761       -- , GROUPING(period.CAL_PERIOD_ID)  gp
1762       -- ,
1763        g_worker_id
1764      , g_default_prg_level
1765      , fact1.PROJECT_ID
1766      , fact1.PROJECT_ORG_ID
1767      , fact1.PROJECT_ORGANIZATION_ID
1768      -- -- -- , fact1.PARTITION_ID
1769      , fact1.PROJECT_ELEMENT_ID
1770      , DECODE (
1771                (grouping(qtr.ENT_YEAR_ID) || grouping(period.ENT_QTR_ID) || grouping(period.ENT_PERIOD_ID) )
1772              , '000', period.ENT_PERIOD_ID
1773              , '001', period.ENT_QTR_ID
1774              , '011', qtr.ENT_YEAR_ID
1775              , '111', -1 ) TIME_ID
1776      , DECODE (
1777                (grouping(qtr.ENT_YEAR_ID) || grouping(period.ENT_QTR_ID) || grouping(period.ENT_PERIOD_ID) )
1778              , '000', 32
1779              , '001', 64
1780              , '011', 128
1781              , '111', 2048 ) PERIOD_TYPE_ID
1782      , fact1.CALENDAR_TYPE
1783      , fact1.WBS_ROLLUP_FLAG
1784      , fact1.PRG_ROLLUP_FLAG
1785      , fact1.CURR_RECORD_TYPE_ID
1786      , fact1.CURRENCY_CODE
1787      , SUM(fact1.REVENUE )
1788      , SUM(fact1.INITIAL_FUNDING_AMOUNT )
1789      , SUM(fact1.INITIAL_FUNDING_COUNT)
1790      , SUM(fact1.ADDITIONAL_FUNDING_AMOUNT)
1791      , SUM(fact1.ADDITIONAL_FUNDING_COUNT  )
1792      , SUM(fact1.CANCELLED_FUNDING_AMOUNT)
1793      , SUM(fact1.CANCELLED_FUNDING_COUNT)
1794      , SUM(fact1.FUNDING_ADJUSTMENT_AMOUNT)
1795      , SUM(fact1.FUNDING_ADJUSTMENT_COUNT)
1796      , SUM(fact1.REVENUE_WRITEOFF)
1797      , SUM(fact1.AR_INVOICE_AMOUNT)
1798      , SUM(fact1.AR_INVOICE_COUNT)
1799      , SUM(fact1.AR_CASH_APPLIED_AMOUNT)
1800      , SUM(fact1.AR_INVOICE_WRITE_OFF_AMOUNT)
1801      , SUM(fact1.AR_INVOICE_WRITEOFF_COUNT)
1802      , SUM(fact1.AR_CREDIT_MEMO_AMOUNT)
1803      , SUM(fact1.AR_CREDIT_MEMO_COUNT)
1804      , SUM(fact1.UNBILLED_RECEIVABLES)
1805      , SUM(fact1.UNEARNED_REVENUE)
1806      , SUM(fact1.AR_UNAPPR_INVOICE_AMOUNT)
1807      , SUM(fact1.AR_UNAPPR_INVOICE_COUNT)
1808      , SUM(fact1.AR_APPR_INVOICE_AMOUNT)
1809      , SUM(fact1.AR_APPR_INVOICE_COUNT)
1810      , SUM(fact1.AR_AMOUNT_DUE)
1811      , SUM(fact1.AR_COUNT_DUE)
1812      , SUM(fact1.AR_AMOUNT_OVERDUE)
1813      , SUM(fact1.AR_COUNT_OVERDUE)
1814      , SUM(fact1.DORMANT_BACKLOG_INACTIV)
1815      , SUM(fact1.DORMANT_BACKLOG_START)
1816      , SUM(fact1.LOST_BACKLOG)
1817      , SUM(fact1.ACTIVE_BACKLOG)
1818      , SUM(fact1.REVENUE_AT_RISK)
1819      , SUM(fact1.CUSTOM1)
1820      , SUM(fact1.CUSTOM2)
1821      , SUM(fact1.CUSTOM3)
1822      , SUM(fact1.CUSTOM4)
1823      , SUM(fact1.CUSTOM5)
1824      , SUM(fact1.CUSTOM6)
1825      , SUM(fact1.CUSTOM7)
1826      , SUM(fact1.CUSTOM8)
1827      , SUM(fact1.CUSTOM9)
1828      , SUM(fact1.CUSTOM10)
1829      , SUM(fact1.CUSTOM11)
1830      , SUM(fact1.CUSTOM12)
1831      , SUM(fact1.CUSTOM13)
1832      , SUM(fact1.CUSTOM14)
1833      , SUM(fact1.CUSTOM15)
1834     FROM
1835 	   PJI_AC_AGGR_PJP1 fact1
1836      , pji_time_ENT_PERIOD period
1837  	 , pji_time_ENT_QTR    qtr
1838     WHERE
1839         fact1.calendar_type = 'E'
1840     AND period.ENT_period_id = fact1.time_id
1841     AND period.ENT_qtr_id = qtr.ENT_qtr_id
1842     AND fact1.period_type_id = 32
1843     AND fact1.worker_id = g_worker_id
1844 	GROUP BY
1845        fact1.PROJECT_ID
1846      , fact1.PROJECT_ORG_ID
1847      , fact1.PROJECT_ORGANIZATION_ID
1848      -- -- -- , fact1.PARTITION_ID
1849      , fact1.PROJECT_ELEMENT_ID
1850      , fact1.CALENDAR_TYPE
1851      , fact1.WBS_ROLLUP_FLAG
1852      , fact1.PRG_ROLLUP_FLAG
1853      , fact1.CURR_RECORD_TYPE_ID
1854      , fact1.CURRENCY_CODE
1855      , rollup (qtr.ENT_YEAR_ID,
1856               period.ENT_QTR_ID,
1857               period.ENT_PERIOD_ID))
1858    WHERE 1=1
1859      AND period_type_id > 32
1860      AND period_type_id < 2048;
1861 
1862 EXCEPTION
1863   WHEN OTHERS THEN
1864     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
1865                              p_procedure_name => 'CREATE_AC_ENT_ROLLUP');
1866     RAISE;
1867 END;
1868 
1869 
1870 
1871 PROCEDURE CREATE_AC_ALL_T_PRI_ROLLUP (
1872   p_calendar_type IN VARCHAR2 := 'G' ) IS
1873     -- l_last_update_date     date   := SYSDATE;
1874     -- l_last_updated_by      NUMBER := FND_GLOBAL.USER_ID;
1875     -- l_creation_date        date   := SYSDATE;
1876     -- l_created_by           NUMBER := FND_GLOBAL.USER_ID;
1877     l_last_update_login    NUMBER := FND_GLOBAL.LOGIN_ID;
1878     l_line_type            VARCHAR2(15);
1879 
1880 BEGIN
1881 
1882   g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
1883 
1884   IF (p_calendar_type NOT IN ('P', 'G') ) THEN
1885     RETURN;
1886   ELSE
1887     IF (p_calendar_type = 'P') THEN
1888       l_line_type := 'PAR';
1889     ELSE
1890       l_line_type := 'GLR';
1891     END IF;
1892   END IF;
1893 
1894     g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
1895 
1896     INSERT INTO PJI_AC_AGGR_PJP1
1897     (
1898        worker_id
1899      , PRG_LEVEL
1900      , PROJECT_ID
1901      , PROJECT_ORG_ID
1902      , PROJECT_ORGANIZATION_ID
1903      -- , PARTITION_ID
1904      , PROJECT_ELEMENT_ID
1905      , TIME_ID
1906      , PERIOD_TYPE_ID
1907      , CALENDAR_TYPE
1908      , WBS_ROLLUP_FLAG
1909      , PRG_ROLLUP_FLAG
1910      , CURR_RECORD_TYPE_ID
1911      , CURRENCY_CODE
1912      , REVENUE
1913      , INITIAL_FUNDING_AMOUNT
1914      , INITIAL_FUNDING_COUNT
1915      , ADDITIONAL_FUNDING_AMOUNT
1916      , ADDITIONAL_FUNDING_COUNT
1917      , CANCELLED_FUNDING_AMOUNT
1918      , CANCELLED_FUNDING_COUNT
1919      , FUNDING_ADJUSTMENT_AMOUNT
1920      , FUNDING_ADJUSTMENT_COUNT
1921      , REVENUE_WRITEOFF
1922      , AR_INVOICE_AMOUNT
1923      , AR_INVOICE_COUNT
1924      , AR_CASH_APPLIED_AMOUNT
1925      , AR_INVOICE_WRITE_OFF_AMOUNT
1926      , AR_INVOICE_WRITEOFF_COUNT
1927      , AR_CREDIT_MEMO_AMOUNT
1928      , AR_CREDIT_MEMO_COUNT
1929      , UNBILLED_RECEIVABLES
1930      , UNEARNED_REVENUE
1931      , AR_UNAPPR_INVOICE_AMOUNT
1932      , AR_UNAPPR_INVOICE_COUNT
1933      , AR_APPR_INVOICE_AMOUNT
1934      , AR_APPR_INVOICE_COUNT
1935      , AR_AMOUNT_DUE
1936      , AR_COUNT_DUE
1937      , AR_AMOUNT_OVERDUE
1938      , AR_COUNT_OVERDUE
1939      , DORMANT_BACKLOG_INACTIV
1940      , DORMANT_BACKLOG_START
1941      , LOST_BACKLOG
1942      , ACTIVE_BACKLOG
1943      , REVENUE_AT_RISK
1944      , CUSTOM1
1945      , CUSTOM2
1946      , CUSTOM3
1947      , CUSTOM4
1948      , CUSTOM5
1949      , CUSTOM6
1950      , CUSTOM7
1951      , CUSTOM8
1952      , CUSTOM9
1953      , CUSTOM10
1954      , CUSTOM11
1955      , CUSTOM12
1956      , CUSTOM13
1957      , CUSTOM14
1958      , CUSTOM15
1959     )
1960   SELECT * FROM (
1961     SELECT
1962       -- GROUPING(qtr.CAL_YEAR_ID)  gy
1963       -- , GROUPING(period.CAL_QTR_ID)  gq
1964       -- , GROUPING(period.CAL_PERIOD_ID)  gp
1965       -- ,
1966        g_worker_id
1967      , g_default_prg_level PRG_LEVEL
1968      , fact1.PROJECT_ID
1969      , fact1.PROJECT_ORG_ID
1970      , fact1.PROJECT_ORGANIZATION_ID
1971      -- -- -- , fact1.PARTITION_ID
1972      , fact1.PROJECT_ELEMENT_ID
1973      , DECODE (
1974                (grouping(qtr.CAL_YEAR_ID) || grouping(period.CAL_QTR_ID) || grouping(period.CAL_PERIOD_ID) )
1975              , '000', period.CAL_PERIOD_ID
1976              , '001', period.CAL_QTR_ID
1977              , '011', qtr.CAL_YEAR_ID
1978              , '111', -1 ) TIME_ID
1979      , DECODE (
1980                (grouping(qtr.CAL_YEAR_ID) || grouping(period.CAL_QTR_ID) || grouping(period.CAL_PERIOD_ID) )
1981              , '000', 32
1982              , '001', 64
1983              , '011', 128
1984              , '111', 2048 ) PERIOD_TYPE_ID
1985     , DECODE (
1986                grouping(qtr.CAL_YEAR_ID)
1987              , 0 , fact1.CALENDAR_TYPE
1988              , 'A') CALENDAR_TYPE
1989      , fact1.WBS_ROLLUP_FLAG
1990      , fact1.PRG_ROLLUP_FLAG
1991      , fact1.CURR_RECORD_TYPE_ID
1992      , fact1.CURRENCY_CODE
1993      , SUM(fact1.REVENUE )
1994      , SUM(fact1.INITIAL_FUNDING_AMOUNT )
1995      , SUM(fact1.INITIAL_FUNDING_COUNT)
1996      , SUM(fact1.ADDITIONAL_FUNDING_AMOUNT)
1997      , SUM(fact1.ADDITIONAL_FUNDING_COUNT  )
1998      , SUM(fact1.CANCELLED_FUNDING_AMOUNT)
1999      , SUM(fact1.CANCELLED_FUNDING_COUNT)
2000      , SUM(fact1.FUNDING_ADJUSTMENT_AMOUNT)
2001      , SUM(fact1.FUNDING_ADJUSTMENT_COUNT)
2002      , SUM(fact1.REVENUE_WRITEOFF)
2003      , SUM(fact1.AR_INVOICE_AMOUNT)
2004      , SUM(fact1.AR_INVOICE_COUNT)
2005      , SUM(fact1.AR_CASH_APPLIED_AMOUNT)
2006      , SUM(fact1.AR_INVOICE_WRITE_OFF_AMOUNT)
2007      , SUM(fact1.AR_INVOICE_WRITEOFF_COUNT)
2008      , SUM(fact1.AR_CREDIT_MEMO_AMOUNT)
2009      , SUM(fact1.AR_CREDIT_MEMO_COUNT)
2010      , SUM(fact1.UNBILLED_RECEIVABLES)
2011      , SUM(fact1.UNEARNED_REVENUE)
2012      , SUM(fact1.AR_UNAPPR_INVOICE_AMOUNT)
2013      , SUM(fact1.AR_UNAPPR_INVOICE_COUNT)
2014      , SUM(fact1.AR_APPR_INVOICE_AMOUNT)
2015      , SUM(fact1.AR_APPR_INVOICE_COUNT)
2016      , SUM(fact1.AR_AMOUNT_DUE)
2017      , SUM(fact1.AR_COUNT_DUE)
2018      , SUM(fact1.AR_AMOUNT_OVERDUE)
2019      , SUM(fact1.AR_COUNT_OVERDUE)
2020      , SUM(fact1.DORMANT_BACKLOG_INACTIV)
2021      , SUM(fact1.DORMANT_BACKLOG_START)
2022      , SUM(fact1.LOST_BACKLOG)
2023      , SUM(fact1.ACTIVE_BACKLOG)
2024      , SUM(fact1.REVENUE_AT_RISK)
2025      , SUM(fact1.CUSTOM1)
2026      , SUM(fact1.CUSTOM2)
2027      , SUM(fact1.CUSTOM3)
2028      , SUM(fact1.CUSTOM4)
2029      , SUM(fact1.CUSTOM5)
2030      , SUM(fact1.CUSTOM6)
2031      , SUM(fact1.CUSTOM7)
2032      , SUM(fact1.CUSTOM8)
2033      , SUM(fact1.CUSTOM9)
2034      , SUM(fact1.CUSTOM10)
2035      , SUM(fact1.CUSTOM11)
2036      , SUM(fact1.CUSTOM12)
2037      , SUM(fact1.CUSTOM13)
2038      , SUM(fact1.CUSTOM14)
2039      , SUM(fact1.CUSTOM15)
2040     FROM
2041       PJI_AC_AGGR_PJP1 fact1
2042     , pji_time_CAL_PERIOD period
2043 	, pji_time_CAL_QTR    qtr
2044     WHERE
2045           fact1.calendar_type = p_calendar_type
2046       AND period.cal_period_id = fact1.time_id
2047 	AND period.cal_qtr_id = qtr.cal_qtr_id
2048       AND fact1.period_type_id = 32
2049       AND fact1.worker_id = g_worker_id
2050     GROUP BY
2051        fact1.PROJECT_ID
2052      , fact1.PROJECT_ORG_ID
2053      , fact1.PROJECT_ORGANIZATION_ID
2054      -- -- -- , fact1.PARTITION_ID
2055      , fact1.PROJECT_ELEMENT_ID
2056      , fact1.CALENDAR_TYPE
2057      , rollup (qtr.CAL_YEAR_ID,
2058                period.CAL_QTR_ID,
2059                period.CAL_PERIOD_ID)
2060      , fact1.WBS_ROLLUP_FLAG
2061      , fact1.PRG_ROLLUP_FLAG
2062      , fact1.CURR_RECORD_TYPE_ID
2063      , fact1.CURRENCY_CODE )
2064    WHERE 1=1
2065      AND period_type_id = 2048;
2066 
2067 EXCEPTION
2068   WHEN OTHERS THEN
2069     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
2070                              p_procedure_name => 'CREATE_AC_ALL_T_PRI_ROLLUP');
2071     RAISE;
2072 END;
2073 
2074 
2075 --
2076 -- Prorate PA, GL entered entries in pjp1 table.
2077 --
2078 PROCEDURE PRORATE_TO_ENT_PG_PJP1_D IS
2079 BEGIN
2080 
2081   /* Added for bug 13030627 */
2082   if PJI_UTILS.GET_PARAMETER('PJP_SIN_PRG') = 'Y' then
2083 
2084      PJI_PJP_PRG_PERF_ALL.PRORATE_TO_ENT_PG_PJP1_D;
2085 
2086   else
2087 
2088    g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
2089 
2090 /* Commented for bug 4005006
2091     INSERT INTO pji_fp_aggr_pjp1
2092     (
2093        WORKER_ID
2094      , PRG_LEVEL
2095      , PROJECT_ID
2096      , PROJECT_ORG_ID
2097      , PROJECT_ORGANIZATION_ID
2098      -- , PARTITION_ID
2099      , PROJECT_ELEMENT_ID
2100      , TIME_ID
2101      , PERIOD_TYPE_ID
2102      , CALENDAR_TYPE
2103      , RBS_AGGR_LEVEL
2104      , WBS_ROLLUP_FLAG
2105      , PRG_ROLLUP_FLAG
2106      , CURR_RECORD_TYPE_ID
2107      , CURRENCY_CODE
2108      , RBS_ELEMENT_ID
2109      , RBS_VERSION_ID
2110      , PLAN_VERSION_ID
2111      , PLAN_TYPE_ID
2112      , RAW_COST
2113      , BRDN_COST
2114      , REVENUE
2115      , BILL_RAW_COST
2116      , BILL_BRDN_COST
2117      , BILL_LABOR_RAW_COST
2118      , BILL_LABOR_BRDN_COST
2119      , BILL_LABOR_HRS
2120      , EQUIPMENT_RAW_COST
2121      , EQUIPMENT_BRDN_COST
2122      , CAPITALIZABLE_RAW_COST
2123      , CAPITALIZABLE_BRDN_COST
2124      , LABOR_RAW_COST
2125      , LABOR_BRDN_COST
2126      , LABOR_HRS
2127      , LABOR_REVENUE
2128      , EQUIPMENT_HOURS
2129      , BILLABLE_EQUIPMENT_HOURS
2130      , SUP_INV_COMMITTED_COST
2131      , PO_COMMITTED_COST
2132      , PR_COMMITTED_COST
2133      , OTH_COMMITTED_COST
2134        , ACT_LABOR_HRS
2135 	   , ACT_EQUIP_HRS
2136 	   , ACT_LABOR_BRDN_COST
2137 	   , ACT_EQUIP_BRDN_COST
2138 	   , ACT_BRDN_COST
2139 	   , ACT_RAW_COST
2140 	   , ACT_REVENUE
2141          , ACT_LABOR_RAW_COST
2142          , ACT_EQUIP_RAW_COST
2143 	   , ETC_LABOR_HRS
2144 	   , ETC_EQUIP_HRS
2145 	   , ETC_LABOR_BRDN_COST
2146 	   , ETC_EQUIP_BRDN_COST
2147 	   , ETC_BRDN_COST
2148          , ETC_RAW_COST
2149          , ETC_LABOR_RAW_COST
2150          , ETC_EQUIP_RAW_COST
2151      , CUSTOM1
2152      , CUSTOM2
2153      , CUSTOM3
2154      , CUSTOM4
2155      , CUSTOM5
2156      , CUSTOM6
2157      , CUSTOM7
2158      , CUSTOM8
2159      , CUSTOM9
2160      , CUSTOM10
2161      , CUSTOM11
2162      , CUSTOM12
2163      , CUSTOM13
2164      , CUSTOM14
2165      , CUSTOM15
2166 	 , LINE_TYPE
2167 	 , TIME_DANGLING_FLAG
2168 	 , RATE_DANGLING_FLAG
2169 	)
2170    SELECT
2171        g_worker_id worker_id
2172      , g_default_prg_level
2173      , a.PROJECT_ID
2174      , a.PROJECT_ORG_ID
2175      , a.PROJECT_ORGANIZATION_ID
2176      , a.PROJECT_ELEMENT_ID
2177      , a.TIME_ID
2178      , a.PERIOD_TYPE_ID
2179      , a.CALENDAR_TYPE
2180      , a.RBS_AGGR_LEVEL
2181      , a.WBS_ROLLUP_FLAG
2182      , a.PRG_ROLLUP_FLAG
2183      , a.CURR_RECORD_TYPE_ID
2184      , a.CURRENCY_CODE
2185      , a.RBS_ELEMENT_ID
2186      , a.RBS_VERSION_ID
2187      , a.PLAN_VERSION_ID
2188      , a.PLAN_TYPE_ID
2189      , SUM(a.RAW_COST       )
2190      , SUM(a.BRDN_COST 	)
2191      , SUM(a.REVENUE	)
2192      , SUM(a.BILL_RAW_COST )
2193      , SUM(a.BILL_BRDN_COST )
2194      , SUM(a.BILL_LABOR_RAW_COST )
2195      , SUM(a.BILL_LABOR_BRDN_COST )
2196      , SUM(a.BILL_LABOR_HRS )
2197      , SUM(a.EQUIPMENT_RAW_COST )
2198      , SUM(a.EQUIPMENT_BRDN_COST )
2199      , SUM(a.CAPITALIZABLE_RAW_COST )
2200      , SUM(a.CAPITALIZABLE_BRDN_COST )
2201      , SUM(a.LABOR_RAW_COST )
2202      , SUM(a.LABOR_BRDN_COST)
2203      , SUM(a.LABOR_HRS )
2204      , SUM(a.LABOR_REVENUE )
2205      , SUM(a.EQUIPMENT_HOURS )
2206      , SUM(a.BILLABLE_EQUIPMENT_HOURS)
2207      , SUM(a.SUP_INV_COMMITTED_COST)
2208      , SUM(a.PO_COMMITTED_COST )
2209      , SUM(a.PR_COMMITTED_COST )
2210      , SUM(a.OTH_COMMITTED_COST)
2211        , SUM(a.ACT_LABOR_HRS)
2212 	   , SUM(a.ACT_EQUIP_HRS)
2213 	   , SUM(a.ACT_LABOR_BRDN_COST)
2214 	   , SUM(a.ACT_EQUIP_BRDN_COST)
2215 	   , SUM(a.ACT_BRDN_COST    )
2216 	   , SUM(a.ACT_RAW_COST    )
2217 	   , SUM(a.ACT_REVENUE    )
2218          , SUM(a.ACT_LABOR_RAW_COST)
2219          , SUM(a.ACT_EQUIP_RAW_COST)
2220 	   , SUM(a.ETC_LABOR_HRS         )
2221 	   , SUM(a.ETC_EQUIP_HRS        )
2222 	   , SUM(a.ETC_LABOR_BRDN_COST )
2223 	   , SUM(a.ETC_EQUIP_BRDN_COST)
2224 	   , SUM(a.ETC_BRDN_COST )
2225          , SUM(a.ETC_RAW_COST)
2226          , SUM(a.ETC_LABOR_RAW_COST)
2227          , SUM(a.ETC_EQUIP_RAW_COST)
2228      , SUM(a.CUSTOM1	)
2229      , SUM(a.CUSTOM2	)
2230      , SUM(a.CUSTOM3	)
2231      , SUM(a.CUSTOM4	)
2232      , SUM(a.CUSTOM5	)
2233      , SUM(a.CUSTOM6	)
2234      , SUM(a.CUSTOM7	)
2235      , SUM(a.CUSTOM8	)
2236      , SUM(a.CUSTOM9	)
2237      , SUM(a.CUSTOM10	)
2238      , SUM(a.CUSTOM11	)
2239      , SUM(a.CUSTOM12	)
2240      , SUM(a.CUSTOM13	)
2241      , SUM(a.CUSTOM14	)
2242      , SUM(a.CUSTOM15	)
2243 	 , a.LINE_TYPE
2244 	 , a.TIME_DANGLING_FLAG
2245 	 , a.RATE_DANGLING_FLAG
2246    FROM (
2247    SELECT
2248          fact.project_id  project_id
2249    	 , fact.project_ORG_ID project_ORG_ID
2250    	 , fact.project_ORGANIZATION_ID project_ORGANIZATION_ID
2251      -- , fact.PARTITION_ID PARTITION_ID
2252    	 , fact.PROJECT_ELEMENT_ID PROJECT_ELEMENT_ID
2253    	 , pa_cal.ent_period_id TIME_ID
2254    	 , fact.PERIOD_TYPE_ID PERIOD_TYPE_ID
2255    	 , 'E' CALENDAR_TYPE -- fact.CALENDAR_TYPE
2256      , fact.RBS_AGGR_LEVEL
2257      , fact.WBS_ROLLUP_FLAG
2258      , fact.PRG_ROLLUP_FLAG
2259    	 , fact.CURR_RECORD_TYPE_ID CURR_RECORD_TYPE_ID
2260    	 , fact.CURRENCY_CODE CURRENCY_CODE
2261    	 , fact.RBS_ELEMENT_ID RBS_ELEMENT_ID
2262    	 , fact.RBS_VERSION_ID RBS_VERSION_ID
2263    	 , fact.PLAN_VERSION_ID PLAN_VERSION_ID
2264 	 , fact.PLAN_TYPE_ID  PLAN_TYPE_ID
2265 	 , ROUND (
2266              NVL (
2267             DECODE (
2268                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2269 			  , '00'   , fact.raw_cost
2270 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2271 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2272 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2273 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2274 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2275 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2276 			  , '0-1'  , fact.raw_cost
2277 			  , '1-1'  , fact.raw_cost
2278 			  , 0  ) -- end decode
2279 			    , 0  ) -- end nvl
2280 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2281 						* PJI_UTILS.GET_MAU (fact.currency_code)	raw_cost
2282 	 , ROUND (
2283              NVL (
2284             DECODE (
2285                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2286 			 , '00'   , fact.brdn_cost
2287 			 , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2288 			 , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2289 			 , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2290 			 , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2291 			 , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2292 			 , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2293 			 , '0-1'  , fact.brdn_cost
2294 			 , '1-1'  , fact.brdn_cost
2295 			 , 0  ) -- end decode
2296 			  , 0  ) -- end nvl
2297 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2298 						* PJI_UTILS.GET_MAU (fact.currency_code)	brdn_cost
2299 	 , ROUND (
2300              NVL (
2301             DECODE (
2302                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2303 			 , '00'   , fact.revenue
2304 			 , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.revenue / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2305 			 , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.revenue / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2306 			 , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.revenue / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2307 			 , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.revenue / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2308 			 , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.revenue / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2309 			 , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.revenue / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2310 			 , '0-1'  , fact.revenue
2311 			 , '1-1'  , fact.revenue
2312 			 , 0  ) -- end decode
2313 			  , 0  ) -- end nvl
2314 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2315 						* PJI_UTILS.GET_MAU (fact.currency_code)	revenue
2316 	 , ROUND (
2317              NVL (
2318             DECODE (
2319                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2320 			  , '00'   , fact.bill_raw_cost
2321 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2322 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2323 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.bill_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2324 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.bill_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2325 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2326 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2327 			  , '0-1'  , fact.bill_raw_cost
2328 			  , '1-1'  , fact.bill_raw_cost
2329 			  , 0  ) -- end decode
2330 			    , 0  ) -- end nvl
2331 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2332 						* PJI_UTILS.GET_MAU (fact.currency_code)	bill_raw_cost
2333 	 , ROUND (
2334              NVL (
2335             DECODE (
2336                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2337 			  , '00'   , fact.bill_brdn_cost
2338 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2339 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2340 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.bill_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2341 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.bill_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2342 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2343 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2344 			  , '0-1'  , fact.bill_brdn_cost
2345 			  , '1-1'  , fact.bill_brdn_cost
2346 			  , 0  ) -- end decode
2347 			    , 0  ) -- end nvl
2348 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2349 						* PJI_UTILS.GET_MAU (fact.currency_code)	bill_brdn_cost
2350 	 , ROUND (
2351              NVL (
2352             DECODE (
2353                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2354 			  , '00'   , fact.bill_labor_raw_cost
2355 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_labor_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2356 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_labor_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2357 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.bill_labor_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2358 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.bill_labor_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2359 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_labor_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2360 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_labor_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2361 			  , '0-1'  , fact.bill_labor_raw_cost
2362 			  , '1-1'  , fact.bill_labor_raw_cost
2363 			  , 0  ) -- end decode
2364 			    , 0  ) -- end nvl
2365 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2366 						* PJI_UTILS.GET_MAU (fact.currency_code)	bill_labor_raw_cost
2367 	 , ROUND (
2368              NVL (
2369             DECODE (
2370                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2371 			  , '00'   , fact.bill_labor_brdn_cost
2372 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_labor_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2373 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_labor_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2374 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.bill_labor_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2375 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.bill_labor_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2376 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_labor_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2377 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_labor_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2378 			  , '0-1'  , fact.bill_labor_brdn_cost
2379 			  , '1-1'  , fact.bill_labor_brdn_cost
2380 			  , 0  ) -- end decode
2381 			    , 0  ) -- end nvl
2382 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2383 						* PJI_UTILS.GET_MAU (fact.currency_code)	bill_labor_brdn_cost
2384 	 , ROUND (
2385              NVL (
2386             DECODE (
2387                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2388 			  , '00'   , fact.bill_labor_hrs
2389 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_labor_hrs / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2390 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_labor_hrs / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2391 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.bill_labor_hrs / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2392 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.bill_labor_hrs / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2393 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_labor_hrs / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2394 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.bill_labor_hrs / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2395 			  , '0-1'  , fact.bill_labor_hrs
2396 			  , '1-1'  , fact.bill_labor_hrs
2397 			  , 0  ) -- end decode
2398 			    , 0  ) -- end nvl
2399 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2400 						* PJI_UTILS.GET_MAU (fact.currency_code)	bill_labor_hrs
2401 	 , ROUND (
2402              NVL (
2403             DECODE (
2404                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2405 			  , '00'   , fact.equipment_raw_cost
2406 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.equipment_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2407 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.equipment_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2408 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.equipment_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2409 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.equipment_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2410 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.equipment_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2411 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.equipment_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2412 			  , '0-1'  , fact.equipment_raw_cost
2413 			  , '1-1'  , fact.equipment_raw_cost
2414 			  , 0  ) -- end decode
2415 			    , 0  ) -- end nvl
2416 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2417 						* PJI_UTILS.GET_MAU (fact.currency_code)	equipment_raw_cost
2418 	 , ROUND (
2419              NVL (
2420             DECODE (
2421                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2422 			  , '00'   , fact.equipment_brdn_cost
2423 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.equipment_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2424 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.equipment_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2425 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.equipment_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2426 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.equipment_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2427 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.equipment_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2428 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.equipment_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2429 			  , '0-1'  , fact.equipment_brdn_cost
2430 			  , '1-1'  , fact.equipment_brdn_cost
2431 			  , 0  ) -- end decode
2432 			    , 0  ) -- end nvl
2433 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2434 						* PJI_UTILS.GET_MAU (fact.currency_code)	equipment_brdn_cost
2435 	 , ROUND (
2436              NVL (
2437             DECODE (
2438                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2439 			  , '00'   , fact.capitalizable_raw_cost
2440 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.capitalizable_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2441 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.capitalizable_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2442 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.capitalizable_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2443 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.capitalizable_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2444 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.capitalizable_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2445 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.capitalizable_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2446 			  , '0-1'  , fact.capitalizable_raw_cost
2447 			  , '1-1'  , fact.capitalizable_raw_cost
2448 			  , 0  ) -- end decode
2449 			    , 0  ) -- end nvl
2450 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2451 						* PJI_UTILS.GET_MAU (fact.currency_code)	capitalizable_raw_cost
2452 	 , ROUND (
2453              NVL (
2454             DECODE (
2455                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2456 			  , '00'   , fact.capitalizable_brdn_cost
2457 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.capitalizable_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2458 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.capitalizable_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2459 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.capitalizable_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2460 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.capitalizable_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2461 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.capitalizable_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2462 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.capitalizable_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2463 			  , '0-1'  , fact.capitalizable_brdn_cost
2464 			  , '1-1'  , fact.capitalizable_brdn_cost
2465 			  , 0  ) -- end decode
2466 			    , 0  ) -- end nvl
2467 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2468 						* PJI_UTILS.GET_MAU (fact.currency_code)	capitalizable_brdn_cost
2469 	 , ROUND (
2470              NVL (
2471             DECODE (
2472                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2473 			  , '00'   , fact.labor_raw_cost
2474 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.labor_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2475 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.labor_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2476 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.labor_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2477 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.labor_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2478 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.labor_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2479 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.labor_raw_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2480 			  , '0-1'  , fact.labor_raw_cost
2481 			  , '1-1'  , fact.labor_raw_cost
2482 			  , 0  ) -- end decode
2483 			    , 0  ) -- end nvl
2484 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2485 						* PJI_UTILS.GET_MAU (fact.currency_code)	labor_raw_cost
2486 	 , ROUND (
2487              NVL (
2488             DECODE (
2489                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2490 			  , '00'   , fact.labor_brdn_cost
2491 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.labor_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2492 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.labor_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2493 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.labor_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2494 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.labor_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2495 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.labor_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2496 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.labor_brdn_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2497 			  , '0-1'  , fact.labor_brdn_cost
2498 			  , '1-1'  , fact.labor_brdn_cost
2499 			  , 0  ) -- end decode
2500 			    , 0  ) -- end nvl
2501 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2502 						* PJI_UTILS.GET_MAU (fact.currency_code)	labor_brdn_cost
2503 	 , ROUND (
2504              NVL (
2505             DECODE (
2506                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2507 			  , '00'   , fact.labor_hrs
2508 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.labor_hrs / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2509 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.labor_hrs / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2510 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.labor_hrs / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2511 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.labor_hrs / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2512 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.labor_hrs / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2513 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.labor_hrs / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2514 			  , '0-1'  , fact.labor_hrs
2515 			  , '1-1'  , fact.labor_hrs
2516 			  , 0  ) -- end decode
2517 			    , 0  ) -- end nvl
2518 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2519 						* PJI_UTILS.GET_MAU (fact.currency_code)	labor_hrs
2520 	 , ROUND (
2521              NVL (
2522             DECODE (
2523                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2524 			  , '00'   , fact.labor_revenue
2525 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.labor_revenue / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2526 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.labor_revenue / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2527 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.labor_revenue / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2528 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.labor_revenue / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2529 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.labor_revenue / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2530 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.labor_revenue / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2531 			  , '0-1'  , fact.labor_revenue
2532 			  , '1-1'  , fact.labor_revenue
2533 			  , 0  ) -- end decode
2534 			    , 0  ) -- end nvl
2535 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2536 						* PJI_UTILS.GET_MAU (fact.currency_code)	labor_revenue
2537 	 , ROUND (
2538              NVL (
2539             DECODE (
2540                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2541 			  , '00'   , fact.equipment_hours
2542 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.equipment_hours / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2543 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.equipment_hours / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2544 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.equipment_hours / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2545 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.equipment_hours / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2546 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.equipment_hours / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2547 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.equipment_hours / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2548 			  , '0-1'  , fact.equipment_hours
2549 			  , '1-1'  , fact.equipment_hours
2550 			  , 0  ) -- end decode
2551 			    , 0  ) -- end nvl
2552 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2553 						* PJI_UTILS.GET_MAU (fact.currency_code)	equipment_hours
2554 	 , ROUND (
2555              NVL (
2556             DECODE (
2557                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2558 			  , '00'   , fact.billable_equipment_hours
2559 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.billable_equipment_hours / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2560 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.billable_equipment_hours / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2561 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.billable_equipment_hours / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2562 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.billable_equipment_hours / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2563 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.billable_equipment_hours / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2564 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.billable_equipment_hours / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2565 			  , '0-1'  , fact.billable_equipment_hours
2566 			  , '1-1'  , fact.billable_equipment_hours
2567 			  , 0  ) -- end decode
2568 			    , 0  ) -- end nvl
2569 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2570 						* PJI_UTILS.GET_MAU (fact.currency_code)	billable_equipment_hours
2571 	 , ROUND (
2572              NVL (
2573             DECODE (
2574                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2575 			  , '00'   , fact.sup_inv_committed_cost
2576 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.sup_inv_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2577 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.sup_inv_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2578 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.sup_inv_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2579 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.sup_inv_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2580 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.sup_inv_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2581 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.sup_inv_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2582 			  , '0-1'  , fact.sup_inv_committed_cost
2583 			  , '1-1'  , fact.sup_inv_committed_cost
2584 			  , 0  ) -- end decode
2585 			    , 0  ) -- end nvl
2586 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2587 						* PJI_UTILS.GET_MAU (fact.currency_code)	sup_inv_committed_cost
2588 	 , ROUND (
2589              NVL (
2590             DECODE (
2591                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2592 			  , '00'   , fact.po_committed_cost
2593 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.po_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2594 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.po_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2595 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.po_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2596 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.po_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2597 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.po_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2598 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.po_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2599 			  , '0-1'  , fact.po_committed_cost
2600 			  , '1-1'  , fact.po_committed_cost
2601 			  , 0  ) -- end decode
2602 			    , 0  ) -- end nvl
2603 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2604 						* PJI_UTILS.GET_MAU (fact.currency_code)	po_committed_cost
2605 	 , ROUND (
2606              NVL (
2607             DECODE (
2608                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2609 			  , '00'   , fact.pr_committed_cost
2610 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.pr_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2611 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.pr_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2612 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.pr_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2613 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.pr_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2614 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.pr_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2615 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.pr_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2616 			  , '0-1'  , fact.pr_committed_cost
2617 			  , '1-1'  , fact.pr_committed_cost
2618 			  , 0  ) -- end decode
2619 			    , 0  ) -- end nvl
2620 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2621 						* PJI_UTILS.GET_MAU (fact.currency_code)	pr_committed_cost
2622 	 , ROUND (
2623              NVL (
2624             DECODE (
2625                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2626 			  , '00'   , fact.oth_committed_cost
2627 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.oth_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2628 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.oth_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2629 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.oth_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2630 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.oth_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2631 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.oth_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2632 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.oth_committed_cost / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2633 			  , '0-1'  , fact.oth_committed_cost
2634 			  , '1-1'  , fact.oth_committed_cost
2635 			  , 0  ) -- end decode
2636 			    , 0  ) -- end nvl
2637 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2638 						* PJI_UTILS.GET_MAU (fact.currency_code)	oth_committed_cost
2639 	 , ROUND (
2640              NVL (
2641             DECODE (
2642                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2643 			  , '00'   , fact.ACT_LABOR_HRS
2644 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_LABOR_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2645 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_LABOR_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2646 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ACT_LABOR_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2647 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ACT_LABOR_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2648 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_LABOR_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2649 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_LABOR_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2650 			  , '0-1'  , fact.ACT_LABOR_HRS
2651 			  , '1-1'  , fact.ACT_LABOR_HRS
2652 			  , 0  ) -- end decode
2653 			    , 0  ) -- end nvl
2654 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2655 						* PJI_UTILS.GET_MAU (fact.currency_code)	ACT_LABOR_HRS
2656 	 , ROUND (
2657              NVL (
2658             DECODE (
2659                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2660 			  , '00'   , fact.ACT_EQUIP_HRS
2661 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_EQUIP_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2662 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_EQUIP_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2663 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ACT_EQUIP_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2664 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ACT_EQUIP_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2665 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_EQUIP_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2666 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_EQUIP_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2667 			  , '0-1'  , fact.ACT_EQUIP_HRS
2668 			  , '1-1'  , fact.ACT_EQUIP_HRS
2669 			  , 0  ) -- end decode
2670 			    , 0  ) -- end nvl
2671 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2672 						* PJI_UTILS.GET_MAU (fact.currency_code)	ACT_EQUIP_HRS
2673 	 , ROUND (
2674              NVL (
2675             DECODE (
2676                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2677 			  , '00'   , fact.ACT_LABOR_BRDN_COST
2678 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_LABOR_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2679 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_LABOR_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2680 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ACT_LABOR_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2681 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ACT_LABOR_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2682 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_LABOR_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2683 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_LABOR_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2684 			  , '0-1'  , fact.ACT_LABOR_BRDN_COST
2685 			  , '1-1'  , fact.ACT_LABOR_BRDN_COST
2686 			  , 0  ) -- end decode
2687 			    , 0  ) -- end nvl
2688 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2689 						* PJI_UTILS.GET_MAU (fact.currency_code)	ACT_LABOR_BRDN_COST
2690 	 , ROUND (
2691              NVL (
2692             DECODE (
2693                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2694 			  , '00'   , fact.ACT_EQUIP_BRDN_COST
2695 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_EQUIP_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2696 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_EQUIP_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2697 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ACT_EQUIP_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2698 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ACT_EQUIP_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2699 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_EQUIP_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2700 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_EQUIP_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2701 			  , '0-1'  , fact.ACT_EQUIP_BRDN_COST
2702 			  , '1-1'  , fact.ACT_EQUIP_BRDN_COST
2703 			  , 0  ) -- end decode
2704 			    , 0  ) -- end nvl
2705 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2706 						* PJI_UTILS.GET_MAU (fact.currency_code)	ACT_EQUIP_BRDN_COST
2707 	 , ROUND (
2708              NVL (
2709             DECODE (
2710                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2711 			  , '00'   , fact.ACT_BRDN_COST
2712 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2713 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2714 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ACT_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2715 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ACT_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2716 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2717 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2718 			  , '0-1'  , fact.ACT_BRDN_COST
2719 			  , '1-1'  , fact.ACT_BRDN_COST
2720 			  , 0  ) -- end decode
2721 			    , 0  ) -- end nvl
2722 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2723 						* PJI_UTILS.GET_MAU (fact.currency_code)	ACT_BRDN_COST
2724 	 , ROUND (
2725              NVL (
2726             DECODE (
2727                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2728 			  , '00'   , fact.ACT_RAW_COST
2729 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2730 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2731 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ACT_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2732 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ACT_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2733 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2734 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2735 			  , '0-1'  , fact.ACT_RAW_COST
2736 			  , '1-1'  , fact.ACT_RAW_COST
2737 			  , 0  ) -- end decode
2738 			    , 0  ) -- end nvl
2739 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2740 						* PJI_UTILS.GET_MAU (fact.currency_code)	ACT_RAW_COST
2741 	 , ROUND (
2742              NVL (
2743             DECODE (
2744                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2745 			  , '00'   , fact.ACT_REVENUE
2746 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_REVENUE / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2747 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_REVENUE / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2748 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ACT_REVENUE / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2749 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ACT_REVENUE / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2750 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_REVENUE / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2751 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_REVENUE / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2752 			  , '0-1'  , fact.ACT_REVENUE
2753 			  , '1-1'  , fact.ACT_REVENUE
2754 			  , 0  ) -- end decode
2755 			    , 0  ) -- end nvl
2756 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2757 						* PJI_UTILS.GET_MAU (fact.currency_code)	ACT_REVENUE
2758 	 , ROUND (
2759              NVL (
2760             DECODE (
2761                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2762 			  , '00'   , fact.ACT_LABOR_RAW_COST
2763 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_LABOR_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2764 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_LABOR_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2765 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ACT_LABOR_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2766 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ACT_LABOR_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2767 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_LABOR_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2768 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_LABOR_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2769 			  , '0-1'  , fact.ACT_LABOR_RAW_COST
2770 			  , '1-1'  , fact.ACT_LABOR_RAW_COST
2771 			  , 0  ) -- end decode
2772 			    , 0  ) -- end nvl
2773 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2774 						* PJI_UTILS.GET_MAU (fact.currency_code)	ACT_LABOR_RAW_COST
2775 	 , ROUND (
2776              NVL (
2777             DECODE (
2778                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2779 			  , '00'   , fact.ACT_EQUIP_RAW_COST
2780 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_EQUIP_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2781 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_EQUIP_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2782 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ACT_EQUIP_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2783 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ACT_EQUIP_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2784 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_EQUIP_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2785 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ACT_EQUIP_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2786 			  , '0-1'  , fact.ACT_EQUIP_RAW_COST
2787 			  , '1-1'  , fact.ACT_EQUIP_RAW_COST
2788 			  , 0  ) -- end decode
2789 			    , 0  ) -- end nvl
2790 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2791 						* PJI_UTILS.GET_MAU (fact.currency_code)	ACT_EQUIP_RAW_COST
2792 	 , ROUND (
2793              NVL (
2794             DECODE (
2795                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2796 			  , '00'   , fact.ETC_LABOR_HRS
2797 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_LABOR_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2798 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_LABOR_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2799 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ETC_LABOR_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2800 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ETC_LABOR_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2801 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_LABOR_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2802 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_LABOR_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2803 			  , '0-1'  , fact.ETC_LABOR_HRS
2804 			  , '1-1'  , fact.ETC_LABOR_HRS
2805 			  , 0  ) -- end decode
2806 			    , 0  ) -- end nvl
2807 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2808 						* PJI_UTILS.GET_MAU (fact.currency_code)	ETC_LABOR_HRS
2809 	 , ROUND (
2810              NVL (
2811             DECODE (
2812                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2813 			  , '00'   , fact.ETC_EQUIP_HRS
2814 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_EQUIP_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2815 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_EQUIP_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2816 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ETC_EQUIP_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2817 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ETC_EQUIP_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2818 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_EQUIP_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2819 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_EQUIP_HRS / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2820 			  , '0-1'  , fact.ETC_EQUIP_HRS
2821 			  , '1-1'  , fact.ETC_EQUIP_HRS
2822 			  , 0  ) -- end decode
2823 			    , 0  ) -- end nvl
2824 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2825 						* PJI_UTILS.GET_MAU (fact.currency_code)	ETC_EQUIP_HRS
2826 	 , ROUND (
2827              NVL (
2828             DECODE (
2829                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2830 			  , '00'   , fact.ETC_LABOR_BRDN_COST
2831 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_LABOR_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2832 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_LABOR_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2833 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ETC_LABOR_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2834 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ETC_LABOR_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2835 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_LABOR_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2836 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_LABOR_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2837 			  , '0-1'  , fact.ETC_LABOR_BRDN_COST
2838 			  , '1-1'  , fact.ETC_LABOR_BRDN_COST
2839 			  , 0  ) -- end decode
2840 			    , 0  ) -- end nvl
2841 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2842 						* PJI_UTILS.GET_MAU (fact.currency_code)	ETC_LABOR_BRDN_COST
2843 	 , ROUND (
2844              NVL (
2845             DECODE (
2846                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2847 			  , '00'   , fact.ETC_EQUIP_BRDN_COST
2848 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_EQUIP_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2849 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_EQUIP_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2850 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ETC_EQUIP_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2851 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ETC_EQUIP_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2852 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_EQUIP_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2853 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_EQUIP_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2854 			  , '0-1'  , fact.ETC_EQUIP_BRDN_COST
2855 			  , '1-1'  , fact.ETC_EQUIP_BRDN_COST
2856 			  , 0  ) -- end decode
2857 			    , 0  ) -- end nvl
2858 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2859 						* PJI_UTILS.GET_MAU (fact.currency_code)	ETC_EQUIP_BRDN_COST
2860 	 , ROUND (
2861              NVL (
2862             DECODE (
2863                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2864 			  , '00'   , fact.ETC_BRDN_COST
2865 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2866 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2867 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ETC_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2868 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ETC_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2869 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2870 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_BRDN_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2871 			  , '0-1'  , fact.ETC_BRDN_COST
2872 			  , '1-1'  , fact.ETC_BRDN_COST
2873 			  , 0  ) -- end decode
2874 			    , 0  ) -- end nvl
2875 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2876 						* PJI_UTILS.GET_MAU (fact.currency_code)	ETC_BRDN_COST
2877 	 , ROUND (
2878              NVL (
2879             DECODE (
2880                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2881 			  , '00'   , fact.ETC_RAW_COST
2882 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2883 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2884 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ETC_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2885 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ETC_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2886 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2887 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2888 			  , '0-1'  , fact.ETC_RAW_COST
2889 			  , '1-1'  , fact.ETC_RAW_COST
2890 			  , 0  ) -- end decode
2891 			    , 0  ) -- end nvl
2892 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2893 						* PJI_UTILS.GET_MAU (fact.currency_code)	ETC_RAW_COST
2894 	 , ROUND (
2895              NVL (
2896             DECODE (
2897                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2898 			  , '00'   , fact.ETC_LABOR_RAW_COST
2899 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_LABOR_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2900 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_LABOR_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2901 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ETC_LABOR_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2902 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ETC_LABOR_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2903 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_LABOR_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2904 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_LABOR_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2905 			  , '0-1'  , fact.ETC_LABOR_RAW_COST
2906 			  , '1-1'  , fact.ETC_LABOR_RAW_COST
2907 			  , 0  ) -- end decode
2908 			    , 0  ) -- end nvl
2909 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2910 						* PJI_UTILS.GET_MAU (fact.currency_code)	ETC_LABOR_RAW_COST
2911 	 , ROUND (
2912              NVL (
2913             DECODE (
2914                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2915 			  , '00'   , fact.ETC_EQUIP_RAW_COST
2916 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_EQUIP_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2917 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_EQUIP_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2918 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ETC_EQUIP_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2919 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.ETC_EQUIP_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2920 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_EQUIP_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2921 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.ETC_EQUIP_RAW_COST / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2922 			  , '0-1'  , fact.ETC_EQUIP_RAW_COST
2923 			  , '1-1'  , fact.ETC_EQUIP_RAW_COST
2924 			  , 0  ) -- end decode
2925 			    , 0  ) -- end nvl
2926 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2927 						* PJI_UTILS.GET_MAU (fact.currency_code)	ETC_EQUIP_RAW_COST
2928 	 , ROUND (
2929              NVL (
2930             DECODE (
2931                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2932 			  , '00'   , fact.custom1
2933 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom1 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2934 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom1 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2935 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom1 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2936 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom1 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2937 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom1 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2938 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom1 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2939 			  , '0-1'  , fact.custom1
2940 			  , '1-1'  , fact.custom1
2941 			  , 0  ) -- end decode
2942 			    , 0  ) -- end nvl
2943 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2944 						* PJI_UTILS.GET_MAU (fact.currency_code)	custom1
2945 	 , ROUND (
2946              NVL (
2947             DECODE (
2948                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2949 			  , '00'   , fact.custom2
2950 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom2 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2951 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom2 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2952 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom2 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2953 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom2 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2954 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom2 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2955 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom2 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2956 			  , '0-1'  , fact.custom2
2957 			  , '1-1'  , fact.custom2
2958 			  , 0  ) -- end decode
2959 			    , 0  ) -- end nvl
2960 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2961 						* PJI_UTILS.GET_MAU (fact.currency_code)	custom2
2962 	 , ROUND (
2963              NVL (
2964             DECODE (
2965                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2966 			  , '00'   , fact.custom3
2967 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom3 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2968 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom3 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2969 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom3 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2970 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom3 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2971 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom3 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2972 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom3 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2973 			  , '0-1'  , fact.custom3
2974 			  , '1-1'  , fact.custom3
2975 			  , 0  ) -- end decode
2976 			    , 0  ) -- end nvl
2977 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2978 						* PJI_UTILS.GET_MAU (fact.currency_code)	custom3
2979 	 , ROUND (
2980              NVL (
2981             DECODE (
2982                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
2983 			  , '00'   , fact.custom4
2984 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom4 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2985 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom4 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2986 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom4 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2987 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom4 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2988 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom4 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2989 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom4 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
2990 			  , '0-1'  , fact.custom4
2991 			  , '1-1'  , fact.custom4
2992 			  , 0  ) -- end decode
2993 			    , 0  ) -- end nvl
2994 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
2995 						* PJI_UTILS.GET_MAU (fact.currency_code)	custom4
2996 	 , ROUND (
2997              NVL (
2998             DECODE (
2999                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
3000 			  , '00'   , fact.custom5
3001 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom5 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3002 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom5 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3003 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom5 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3004 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom5 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3005 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom5 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3006 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom5 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3007 			  , '0-1'  , fact.custom5
3008 			  , '1-1'  , fact.custom5
3009 			  , 0  ) -- end decode
3010 			    , 0  ) -- end nvl
3011 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
3012 						* PJI_UTILS.GET_MAU (fact.currency_code)	custom5
3013 	 , ROUND (
3014              NVL (
3015             DECODE (
3016                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
3017 			  , '00'   , fact.custom6
3018 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom6 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3019 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom6 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3020 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom6 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3021 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom6 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3022 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom6 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3023 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom6 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3024 			  , '0-1'  , fact.custom6
3025 			  , '1-1'  , fact.custom6
3026 			  , 0  ) -- end decode
3027 			    , 0  ) -- end nvl
3028 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
3029 						* PJI_UTILS.GET_MAU (fact.currency_code)	custom6
3030 	 , ROUND (
3031              NVL (
3032             DECODE (
3033                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
3034 			  , '00'   , fact.custom7
3035 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom7 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3036 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom7 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3037 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom7 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3038 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom7 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3039 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom7 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3040 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom7 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3041 			  , '0-1'  , fact.custom7
3042 			  , '1-1'  , fact.custom7
3043 			  , 0  ) -- end decode
3044 			    , 0  ) -- end nvl
3045 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
3046 						* PJI_UTILS.GET_MAU (fact.currency_code)	custom7
3047 	 , ROUND (
3048              NVL (
3049             DECODE (
3050                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
3051 			  , '00'   , fact.custom8
3052 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom8 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3053 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom8 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3054 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom8 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3055 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom8 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3056 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom8 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3057 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom8 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3058 			  , '0-1'  , fact.custom8
3059 			  , '1-1'  , fact.custom8
3060 			  , 0  ) -- end decode
3061 			    , 0  ) -- end nvl
3062 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
3063 						* PJI_UTILS.GET_MAU (fact.currency_code)	custom8
3064 	 , ROUND (
3065              NVL (
3066             DECODE (
3067                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
3068 			  , '00'   , fact.custom9
3069 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom9 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3070 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom9 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3071 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom9 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3072 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom9 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3073 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom9 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3074 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom9 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3075 			  , '0-1'  , fact.custom9
3076 			  , '1-1'  , fact.custom9
3077 			  , 0  ) -- end decode
3078 			    , 0  ) -- end nvl
3079 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
3080 						* PJI_UTILS.GET_MAU (fact.currency_code)	custom9
3081 	 , ROUND (
3082              NVL (
3083             DECODE (
3084                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
3085 			  , '00'   , fact.custom10
3086 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom10 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3087 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom10 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3088 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom10 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3089 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom10 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3090 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom10 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3091 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom10 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3092 			  , '0-1'  , fact.custom10
3093 			  , '1-1'  , fact.custom10
3094 			  , 0  ) -- end decode
3095 			    , 0  ) -- end nvl
3096 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
3097 						* PJI_UTILS.GET_MAU (fact.currency_code)	custom10
3098 	 , ROUND (
3099              NVL (
3100             DECODE (
3101                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
3102 			  , '00'   , fact.custom11
3103 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom11 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3104 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom11 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3105 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom11 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3106 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom11 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3107 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom11 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3108 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom11 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3109 			  , '0-1'  , fact.custom11
3110 			  , '1-1'  , fact.custom11
3111 			  , 0  ) -- end decode
3112 			    , 0  ) -- end nvl
3113 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
3114 						* PJI_UTILS.GET_MAU (fact.currency_code)	custom11
3115 	 , ROUND (
3116              NVL (
3117             DECODE (
3118                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
3119 			  , '00'   , fact.custom12
3120 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom12 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3121 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom12 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3122 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom12 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3123 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom12 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3124 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom12 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3125 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom12 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3126 			  , '0-1'  , fact.custom12
3127 			  , '1-1'  , fact.custom12
3128 			  , 0  ) -- end decode
3129 			    , 0  ) -- end nvl
3130 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
3131 						* PJI_UTILS.GET_MAU (fact.currency_code)	custom12
3132 	 , ROUND (
3133              NVL (
3134             DECODE (
3135                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
3136 			  , '00'   , fact.custom13
3137 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom13 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3138 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom13 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3139 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom13 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3140 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom13 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3141 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom13 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3142 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom13 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3143 			  , '0-1'  , fact.custom13
3144 			  , '1-1'  , fact.custom13
3145 			  , 0  ) -- end decode
3146 			    , 0  ) -- end nvl
3147 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
3148 						* PJI_UTILS.GET_MAU (fact.currency_code)	custom13
3149 	 , ROUND (
3150              NVL (
3151             DECODE (
3152                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
3153 			  , '00'   , fact.custom14
3154 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom14 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3155 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom14 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3156 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom14 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3157 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom14 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3158 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom14 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3159 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom14 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3160 			  , '0-1'  , fact.custom14
3161 			  , '1-1'  , fact.custom14
3162 			  , 0  ) -- end decode
3163 			    , 0  ) -- end nvl
3164 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
3165 						* PJI_UTILS.GET_MAU (fact.currency_code)	custom14
3166 	 , ROUND (
3167              NVL (
3168             DECODE (
3169                      ( sign (non_pa_cal.start_date - pa_cal.start_date) || sign (non_pa_cal.end_date - pa_cal.end_date) )
3170 			  , '00'   , fact.custom15
3171 			  , '01'   , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom15 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3172 			  , '-11'  , (pa_cal.end_date - pa_cal.start_date + 1) * fact.custom15 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3173 			  , '10'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom15 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3174 			  , '11'   , (pa_cal.end_date - non_pa_cal.start_date + 1) * fact.custom15 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3175 			  , '-10'  , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom15 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3176 			  , '-1-1' , (non_pa_cal.end_date - pa_cal.start_date + 1) * fact.custom15 / (non_pa_cal.end_date - non_pa_cal.start_date + 1)
3177 			  , '0-1'  , fact.custom15
3178 			  , '1-1'  , fact.custom15
3179 			  , 0  ) -- end decode
3180 			    , 0  ) -- end nvl
3181 			/ PJI_UTILS.GET_MAU (fact.currency_code) )  -- end round
3182 						* PJI_UTILS.GET_MAU (fact.currency_code)	custom15
3183      , 'CF'   line_type
3184 	 , fact.time_dangling_flag time_dangling_flag
3185 	 , fact.rate_dangling_flag rate_dangling_flag
3186    FROM   pji_fp_aggr_pjp1 fact
3187         , pji_time_cal_period  non_pa_cal
3188    	 , pji_time_ent_period  pa_cal
3189        , pji_fm_extr_plnver4  ver
3190    WHERE  fact.CALENDAR_TYPE IN ('P', 'G')
3191       AND fact.worker_id = g_worker_id
3192       AND non_pa_cal.cal_period_id = fact.time_id
3193       AND fact.line_type like 'OF%'
3194       AND (
3195 	       ( pa_cal.start_date >= non_pa_cal.start_date  AND pa_cal.end_date <= non_pa_cal.end_date )
3196 	    OR ( pa_cal.start_date <= non_pa_cal.start_date  AND pa_cal.end_date >= non_pa_cal.end_date )
3197 	    OR ( pa_cal.start_date <= non_pa_cal.start_date  AND pa_cal.end_date <= non_pa_cal.end_date AND pa_cal.end_date >= non_pa_cal.start_date )
3198 	    OR ( pa_cal.start_date >= non_pa_cal.start_date  AND pa_cal.end_date >= non_pa_cal.end_date AND pa_cal.start_date <= non_pa_cal.end_date )
3199           )
3200       AND fact.time_dangling_flag IS NULL
3201       AND fact.rate_dangling_flag IS NULL
3202       AND fact.period_type_id = 32
3203       AND fact.plan_version_id = ver.plan_version_id
3204       AND ver.wp_flag = 'N'
3205       AND ver.baselined_flag = 'Y'
3206 	AND fact.rbs_version_id = NVL(ver.rbs_struct_version_id, -1)
3207       AND ver.plan_version_id > 0
3208 	  ) a
3209 	  GROUP BY
3210 	   a.PROJECT_ID
3211      , a.PROJECT_ORG_ID
3212      , a.PROJECT_ORGANIZATION_ID
3213      , a.PROJECT_ELEMENT_ID
3214      , a.TIME_ID
3215      , a.PERIOD_TYPE_ID
3216      , a.CALENDAR_TYPE
3217      , a.RBS_AGGR_LEVEL
3218      , a.WBS_ROLLUP_FLAG
3219      , a.PRG_ROLLUP_FLAG
3220      , a.CURR_RECORD_TYPE_ID
3221      , a.CURRENCY_CODE
3222      , a.RBS_ELEMENT_ID
3223      , a.RBS_VERSION_ID
3224      , a.PLAN_VERSION_ID
3225      , a.PLAN_TYPE_ID
3226 	 , a.LINE_TYPE
3227 	 , a.TIME_DANGLING_FLAG
3228 	 , a.RATE_DANGLING_FLAG;
3229   End of bug 4005006*/
3230 
3231     INSERT INTO pji_fp_aggr_pjp1
3232     (
3233        WORKER_ID
3234      , PROJECT_ID
3235      , PROJECT_ORG_ID
3236      , PROJECT_ORGANIZATION_ID
3237      -- , PARTITION_ID
3238      , PROJECT_ELEMENT_ID
3239      , TIME_ID
3240      , PERIOD_TYPE_ID
3241      , CALENDAR_TYPE
3242      , RBS_AGGR_LEVEL
3243      , WBS_ROLLUP_FLAG
3244      , PRG_ROLLUP_FLAG
3245      , CURR_RECORD_TYPE_ID
3246      , CURRENCY_CODE
3247      , RBS_ELEMENT_ID
3248      , RBS_VERSION_ID
3249      , PLAN_VERSION_ID
3250      , PLAN_TYPE_ID
3251      , RAW_COST
3252      , BRDN_COST
3253      , REVENUE
3254      , BILL_RAW_COST
3255      , BILL_BRDN_COST
3256      , BILL_LABOR_RAW_COST
3257      , BILL_LABOR_BRDN_COST
3258      , BILL_LABOR_HRS
3259      , EQUIPMENT_RAW_COST
3260      , EQUIPMENT_BRDN_COST
3261      , CAPITALIZABLE_RAW_COST
3262      , CAPITALIZABLE_BRDN_COST
3263      , LABOR_RAW_COST
3264      , LABOR_BRDN_COST
3265      , LABOR_HRS
3266      , LABOR_REVENUE
3267      , EQUIPMENT_HOURS
3268      , BILLABLE_EQUIPMENT_HOURS
3269      , SUP_INV_COMMITTED_COST
3270      , PO_COMMITTED_COST
3271      , PR_COMMITTED_COST
3272      , OTH_COMMITTED_COST
3273      , ACT_LABOR_HRS
3274      , ACT_EQUIP_HRS
3275      , ACT_LABOR_BRDN_COST
3276      , ACT_EQUIP_BRDN_COST
3277      , ACT_BRDN_COST
3278      , ACT_RAW_COST
3279      , ACT_REVENUE
3280      , ACT_LABOR_RAW_COST
3281      , ACT_EQUIP_RAW_COST
3282      , ETC_LABOR_HRS
3283      , ETC_EQUIP_HRS
3284      , ETC_LABOR_BRDN_COST
3285      , ETC_EQUIP_BRDN_COST
3286      , ETC_BRDN_COST
3287      , ETC_RAW_COST
3288      , ETC_LABOR_RAW_COST
3289      , ETC_EQUIP_RAW_COST
3290      , CUSTOM1
3291      , CUSTOM2
3292      , CUSTOM3
3293      , CUSTOM4
3294      , CUSTOM5
3295      , CUSTOM6
3296      , CUSTOM7
3297      , CUSTOM8
3298      , CUSTOM9
3299      , CUSTOM10
3300      , CUSTOM11
3301      , CUSTOM12
3302      , CUSTOM13
3303      , CUSTOM14
3304      , CUSTOM15
3305      , TIME_DANGLING_FLAG
3306      , RATE_DANGLING_FLAG
3307      , PRG_LEVEL
3308      , PLAN_TYPE_CODE    /* 4471527 */
3309 	)
3310    SELECT
3311            g_worker_id worker_id
3312          , a.PROJECT_ID
3313          , a.PROJECT_ORG_ID
3314          , a.PROJECT_ORGANIZATION_ID
3315          , a.PROJECT_ELEMENT_ID
3316          , a.TIME_ID
3317          , a.PERIOD_TYPE_ID
3318          , a.CALENDAR_TYPE
3319          , a.RBS_AGGR_LEVEL
3320          , a.WBS_ROLLUP_FLAG
3321          , a.PRG_ROLLUP_FLAG
3322          , a.CURR_RECORD_TYPE_ID
3323          , a.CURRENCY_CODE
3324          , a.RBS_ELEMENT_ID
3325          , a.RBS_VERSION_ID
3326          , a.PLAN_VERSION_ID
3327          , a.PLAN_TYPE_ID
3328 	 , SUM(ROUND (nvl(a.raw_cost,0)*a.factor/a.mau)*a.mau) raw_cost
3329 	 , SUM(ROUND (nvl(a.brdn_cost,0)*a.factor/a.mau)*a.mau) brdn_cost
3330 	 , SUM(ROUND (nvl(a.revenue,0)*a.factor/a.mau)*a.mau) revenue
3331 	 , SUM(ROUND (nvl(a.bill_raw_cost,0)*a.factor/a.mau)*a.mau) bill_raw_cost
3332 	 , SUM(ROUND (nvl(a.bill_brdn_cost,0)*a.factor/a.mau)*a.mau) bill_brdn_cost
3333 	 , SUM(ROUND (nvl(a.bill_labor_raw_cost,0)*a.factor/a.mau)*a.mau) bill_labor_raw_cost
3334 	 , SUM(ROUND (nvl(a.bill_labor_brdn_cost,0)*a.factor/a.mau)*a.mau) bill_labor_brdn_cost
3335 	 , SUM(ROUND (nvl(a.bill_labor_hrs,0)*a.factor/a.mau)*a.mau) bill_labor_hrs
3336 	 , SUM(ROUND (nvl(a.equipment_raw_cost,0)*a.factor/a.mau)*a.mau) equipment_raw_cost
3337 	 , SUM(ROUND (nvl(a.equipment_brdn_cost,0)*a.factor/a.mau)*a.mau) equipment_brdn_cost
3338 	 , SUM(ROUND (nvl(a.capitalizable_raw_cost,0)*a.factor/a.mau)*a.mau) capitalizable_raw_cost
3339 	 , SUM(ROUND (nvl(a.capitalizable_brdn_cost,0)*a.factor/a.mau)*a.mau) capitalizable_brdn_cost
3340 	 , SUM(ROUND (nvl(a.labor_raw_cost,0)*a.factor/a.mau)*a.mau) labor_raw_cost
3341 	 , SUM(ROUND (nvl(a.labor_brdn_cost,0)*a.factor/a.mau)*a.mau) labor_brdn_cost
3342 	 , SUM(ROUND (nvl(a.labor_hrs,0)*a.factor/a.mau)*a.mau) labor_hrs
3343 	 , SUM(ROUND (nvl(a.labor_revenue,0)*a.factor/a.mau)*a.mau) labor_revenue
3344 	 , SUM(ROUND (nvl(a.equipment_hours,0)*a.factor/a.mau)*a.mau) equipment_hours
3345 	 , SUM(ROUND (nvl(a.billable_equipment_hours,0)*a.factor/a.mau)*a.mau) billable_equipment_hours
3346 	 , SUM(ROUND (nvl(a.sup_inv_committed_cost,0)*a.factor/a.mau)*a.mau) sup_inv_committed_cost
3347 	 , SUM(ROUND (nvl(a.po_committed_cost,0)*a.factor/a.mau)*a.mau) po_committed_cost
3348 	 , SUM(ROUND (nvl(a.pr_committed_cost,0)*a.factor/a.mau)*a.mau) pr_committed_cost
3349 	 , SUM(ROUND (nvl(a.oth_committed_cost,0)*a.factor/a.mau)*a.mau) oth_committed_cost
3350 	 , SUM(ROUND (nvl(a.ACT_LABOR_HRS,0)*a.factor/a.mau)*a.mau) ACT_LABOR_HRS
3351 	 , SUM(ROUND (nvl(a.ACT_EQUIP_HRS,0)*a.factor/a.mau)*a.mau) ACT_EQUIP_HRS
3352 	 , SUM(ROUND (nvl(a.ACT_LABOR_BRDN_COST,0)*a.factor/a.mau)*a.mau) ACT_LABOR_BRDN_COST
3353 	 , SUM(ROUND (nvl(a.ACT_EQUIP_BRDN_COST,0)*a.factor/a.mau)*a.mau) ACT_EQUIP_BRDN_COST
3354 	 , SUM(ROUND (nvl(a.ACT_BRDN_COST,0)*a.factor/a.mau)*a.mau) ACT_BRDN_COST
3355 	 , SUM(ROUND (nvl(a.ACT_RAW_COST,0)*a.factor/a.mau)*a.mau) ACT_RAW_COST
3356 	 , SUM(ROUND (nvl(a.ACT_REVENUE,0)*a.factor/a.mau)*a.mau) ACT_REVENUE
3357 	 , SUM(ROUND (nvl(a.ACT_LABOR_RAW_COST,0)*a.factor/a.mau)*a.mau) ACT_LABOR_RAW_COST
3358 	 , SUM(ROUND (nvl(a.ACT_EQUIP_RAW_COST,0)*a.factor/a.mau)*a.mau) ACT_EQUIP_RAW_COST
3359 	 , SUM(ROUND (nvl(a.ETC_LABOR_HRS,0)*a.factor/a.mau)*a.mau) ETC_LABOR_HRS
3360 	 , SUM(ROUND (nvl(a.ETC_EQUIP_HRS,0)*a.factor/a.mau)*a.mau) ETC_EQUIP_HRS
3361 	 , SUM(ROUND (nvl(a.ETC_LABOR_BRDN_COST,0)*a.factor/a.mau)*a.mau) ETC_LABOR_BRDN_COST
3362 	 , SUM(ROUND (nvl(a.ETC_EQUIP_BRDN_COST,0)*a.factor/a.mau)*a.mau) ETC_EQUIP_BRDN_COST
3363 	 , SUM(ROUND (nvl(a.ETC_BRDN_COST,0)*a.factor/a.mau)*a.mau) ETC_BRDN_COST
3364 	 , SUM(ROUND (nvl(a.ETC_RAW_COST,0)*a.factor/a.mau)*a.mau) ETC_RAW_COST
3365 	 , SUM(ROUND (nvl(a.ETC_LABOR_RAW_COST,0)*a.factor/a.mau)*a.mau) ETC_LABOR_RAW_COST
3366 	 , SUM(ROUND (nvl(a.ETC_EQUIP_RAW_COST,0)*a.factor/a.mau)*a.mau) ETC_EQUIP_RAW_COST
3367 	 , SUM(ROUND (nvl(a.custom1,0)*a.factor/a.mau)*a.mau) custom1
3368 	 , SUM(ROUND (nvl(a.custom2,0)*a.factor/a.mau)*a.mau) custom2
3369 	 , SUM(ROUND (nvl(a.custom3,0)*a.factor/a.mau)*a.mau) custom3
3370 	 , SUM(ROUND (nvl(a.custom4,0)*a.factor/a.mau)*a.mau) custom4
3371 	 , SUM(ROUND (nvl(a.custom5,0)*a.factor/a.mau)*a.mau) custom5
3372 	 , SUM(ROUND (nvl(a.custom6,0)*a.factor/a.mau)*a.mau) custom6
3373 	 , SUM(ROUND (nvl(a.custom7,0)*a.factor/a.mau)*a.mau) custom7
3374 	 , SUM(ROUND (nvl(a.custom8,0)*a.factor/a.mau)*a.mau) custom8
3375 	 , SUM(ROUND (nvl(a.custom9,0)*a.factor/a.mau)*a.mau) custom9
3376 	 , SUM(ROUND (nvl(a.custom10,0)*a.factor/a.mau)*a.mau) custom10
3377 	 , SUM(ROUND (nvl(a.custom11,0)*a.factor/a.mau)*a.mau) custom11
3378 	 , SUM(ROUND (nvl(a.custom12,0)*a.factor/a.mau)*a.mau) custom12
3379 	 , SUM(ROUND (nvl(a.custom13,0)*a.factor/a.mau)*a.mau) custom13
3380 	 , SUM(ROUND (nvl(a.custom14,0)*a.factor/a.mau)*a.mau) custom14
3381 	 , SUM(ROUND (nvl(a.custom15,0)*a.factor/a.mau)*a.mau) custom15
3382          , a.TIME_DANGLING_FLAG
3383          , a.RATE_DANGLING_FLAG
3384          , g_default_prg_level prg_level
3385          , a.PLAN_TYPE_CODE  PLAN_TYPE_CODE   /* 4471527 */
3386    FROM (
3387    SELECT /*+ NO_MERGE */
3388          fact.project_id  project_id
3389    	 , fact.project_ORG_ID project_ORG_ID
3390    	 , fact.project_ORGANIZATION_ID project_ORGANIZATION_ID
3391    	 , fact.PROJECT_ELEMENT_ID PROJECT_ELEMENT_ID
3392    	 , pa_cal.ent_period_id TIME_ID
3393    	 , fact.PERIOD_TYPE_ID PERIOD_TYPE_ID
3394    	 , 'E' CALENDAR_TYPE -- fact.CALENDAR_TYPE
3395          , fact.RBS_AGGR_LEVEL
3396          , fact.WBS_ROLLUP_FLAG
3397          , fact.PRG_ROLLUP_FLAG
3398    	 , fact.CURR_RECORD_TYPE_ID CURR_RECORD_TYPE_ID
3399    	 , fact.CURRENCY_CODE CURRENCY_CODE
3400    	 , fact.RBS_ELEMENT_ID RBS_ELEMENT_ID
3401    	 , fact.RBS_VERSION_ID RBS_VERSION_ID
3402    	 , fact.PLAN_VERSION_ID PLAN_VERSION_ID
3403 	 , fact.PLAN_TYPE_ID  PLAN_TYPE_ID
3404 	 , fact.raw_cost
3405 	 , fact.brdn_cost
3406 	 , fact.revenue
3407 	 , fact.bill_raw_cost
3408 	 , fact.bill_brdn_cost
3409 	 , fact.bill_labor_raw_cost
3410 	 , fact.bill_labor_brdn_cost
3411 	 , fact.bill_labor_hrs
3412 	 , fact.equipment_raw_cost
3413 	 , fact.equipment_brdn_cost
3414 	 , fact.capitalizable_raw_cost
3415 	 , fact.capitalizable_brdn_cost
3416 	 , fact.labor_raw_cost
3417 	 , fact.labor_brdn_cost
3418 	 , fact.labor_hrs
3419 	 , fact.labor_revenue
3420 	 , fact.equipment_hours
3421 	 , fact.billable_equipment_hours
3422 	 , fact.sup_inv_committed_cost
3423 	 , fact.po_committed_cost
3424 	 , fact.pr_committed_cost
3425 	 , fact.oth_committed_cost
3426 	 , fact.ACT_LABOR_HRS
3427 	 , fact.ACT_EQUIP_HRS
3428 	 , fact.ACT_LABOR_BRDN_COST
3429 	 , fact.ACT_EQUIP_BRDN_COST
3430 	 , fact.ACT_BRDN_COST
3431 	 , fact.ACT_RAW_COST
3432 	 , fact.ACT_REVENUE
3433 	 , fact.ACT_LABOR_RAW_COST
3434 	 , fact.ACT_EQUIP_RAW_COST
3435 	 , fact.ETC_LABOR_HRS
3436 	 , fact.ETC_EQUIP_HRS
3437 	 , fact.ETC_LABOR_BRDN_COST
3438 	 , fact.ETC_EQUIP_BRDN_COST
3439 	 , fact.ETC_BRDN_COST
3440 	 , fact.ETC_RAW_COST
3441 	 , fact.ETC_LABOR_RAW_COST
3442 	 , fact.ETC_EQUIP_RAW_COST
3443 	 , fact.custom1
3444 	 , fact.custom2
3445 	 , fact.custom3
3446 	 , fact.custom4
3447 	 , fact.custom5
3448 	 , fact.custom6
3449 	 , fact.custom7
3450 	 , fact.custom8
3451 	 , fact.custom9
3452 	 , fact.custom10
3453 	 , fact.custom11
3454 	 , fact.custom12
3455 	 , fact.custom13
3456 	 , fact.custom14
3457 	 , fact.custom15
3458 	 , fact.time_dangling_flag time_dangling_flag
3459 	 , fact.rate_dangling_flag rate_dangling_flag
3460          , cur.mau mau
3461          , (LEAST(non_pa_cal.end_date,pa_cal.end_date) -
3462                     Greatest(non_pa_cal.start_date,pa_cal.start_date)+1)
3463                               / (non_pa_cal.end_date - non_pa_cal.start_date+1) factor
3464          , fact.plan_type_code plan_type_code  /* 4471527 */
3465    FROM   pji_fp_aggr_pjp1 fact
3466         , pji_time_cal_period_v  non_pa_cal
3467         , pji_time_ent_period_v  pa_cal
3468         , pji_fm_extr_plnver4  ver
3469         , (SELECT currency_code,
3470                    decode(nvl(MINIMUM_ACCOUNTABLE_UNIT, power(10, (-1 * PRECISION))),
3471                       null, 0.01,
3472                          0, 1,
3473                          nvl(MINIMUM_ACCOUNTABLE_UNIT, power(10, (-1 * PRECISION)))) mau
3474               FROM FND_CURRENCIES) cur
3475    WHERE  fact.CALENDAR_TYPE IN ('P', 'G')
3476       AND fact.worker_id = g_worker_id
3477       AND VER.worker_id = g_worker_id
3478       AND non_pa_cal.cal_period_id = fact.time_id
3479       AND fact.line_type like 'OF%'
3480       AND non_pa_cal.start_date<= pa_cal.end_date
3481       AND non_pa_cal.end_Date >=pa_cal.start_date
3482       AND fact.currency_code = cur.currency_code
3483       AND fact.time_dangling_flag IS NULL
3484       AND fact.rate_dangling_flag IS NULL
3485       AND fact.period_type_id = 32
3486       AND fact.plan_version_id = ver.plan_version_id
3487       AND fact.plan_type_code = ver.plan_type_code     /* 4471527 */
3488       AND ver.wp_flag = 'N'
3489       AND ver.baselined_flag = 'Y'
3490 	AND fact.rbs_version_id = NVL (ver.rbs_struct_version_id , -1)
3491       AND ver.plan_version_id > 0
3492 	  ) a
3493 
3494      WHERE a.factor >0
3495 	  GROUP BY
3496 	   a.PROJECT_ID
3497      , a.PROJECT_ORG_ID
3498      , a.PROJECT_ORGANIZATION_ID
3499      , a.PROJECT_ELEMENT_ID
3500      , a.TIME_ID
3501      , a.PERIOD_TYPE_ID
3502      , a.CALENDAR_TYPE
3503      , a.RBS_AGGR_LEVEL
3504      , a.WBS_ROLLUP_FLAG
3505      , a.PRG_ROLLUP_FLAG
3506      , a.CURR_RECORD_TYPE_ID
3507      , a.CURRENCY_CODE
3508      , a.RBS_ELEMENT_ID
3509      , a.RBS_VERSION_ID
3510      , a.PLAN_VERSION_ID
3511      , a.PLAN_TYPE_ID
3512      , a.TIME_DANGLING_FLAG
3513      , a.RATE_DANGLING_FLAG
3514      , a.PLAN_TYPE_CODE ;      /* 4471527 */
3515 
3516 	end if;
3517 
3518 
3519 EXCEPTION
3520   WHEN OTHERS THEN
3521     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
3522                              p_procedure_name => ' PRORATE_TO_ENT_PG_PJP1_D ');
3523     RAISE;
3524 END;
3525 
3526 
3527 PROCEDURE PRORATE_TO_ENT_PG_FPRL_D IS
3528 BEGIN
3529 
3530     g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
3531 
3532 EXCEPTION
3533   WHEN OTHERS THEN
3534     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
3535                              p_procedure_name => 'PRORATE_TO_ENT_PG_FPRL_D ');
3536     RAISE;
3537 END;
3538 
3539 
3540 PROCEDURE PRORATE_TO_ENT_N_PJP1_D IS
3541 BEGIN
3542 
3543   /* Added for bug 13030627 */
3544   if PJI_UTILS.GET_PARAMETER('PJP_SIN_PRG') = 'Y' then
3545 
3546      PJI_PJP_PRG_PERF_ALL.PRORATE_TO_ENT_N_PJP1_D;
3547 
3548   else
3549 
3550   g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
3551 
3552     INSERT INTO pji_fp_aggr_pjp1  -- Non time phased entries in pjp1 table.
3553     (
3554        WORKER_ID
3555      , PROJECT_ID
3556      , PROJECT_ORG_ID
3557      , PROJECT_ORGANIZATION_ID
3558      , PROJECT_ELEMENT_ID
3559      , TIME_ID
3560      , PERIOD_TYPE_ID
3561      , CALENDAR_TYPE
3562      , RBS_AGGR_LEVEL
3563      , WBS_ROLLUP_FLAG
3564      , PRG_ROLLUP_FLAG
3565      , CURR_RECORD_TYPE_ID
3566      , CURRENCY_CODE
3567      , RBS_ELEMENT_ID
3568      , RBS_VERSION_ID
3569      , PLAN_VERSION_ID
3570      , PLAN_TYPE_ID
3571      , RAW_COST
3572      , BRDN_COST
3573      , REVENUE
3574      , BILL_RAW_COST
3575      , BILL_BRDN_COST
3576      , BILL_LABOR_RAW_COST
3577      , BILL_LABOR_BRDN_COST
3578      , BILL_LABOR_HRS
3579      , EQUIPMENT_RAW_COST
3580      , EQUIPMENT_BRDN_COST
3581      , CAPITALIZABLE_RAW_COST
3582      , CAPITALIZABLE_BRDN_COST
3583      , LABOR_RAW_COST
3584      , LABOR_BRDN_COST
3585      , LABOR_HRS
3586      , LABOR_REVENUE
3587      , EQUIPMENT_HOURS
3588      , BILLABLE_EQUIPMENT_HOURS
3589      , SUP_INV_COMMITTED_COST
3590      , PO_COMMITTED_COST
3591      , PR_COMMITTED_COST
3592      , OTH_COMMITTED_COST
3593      , ACT_LABOR_HRS
3594      , ACT_EQUIP_HRS
3595      , ACT_LABOR_BRDN_COST
3596      , ACT_EQUIP_BRDN_COST
3597      , ACT_BRDN_COST
3598      , ACT_RAW_COST
3599      , ACT_REVENUE
3600      , ACT_LABOR_RAW_COST
3601      , ACT_EQUIP_RAW_COST
3602      , ETC_LABOR_HRS
3603      , ETC_EQUIP_HRS
3604      , ETC_LABOR_BRDN_COST
3605      , ETC_EQUIP_BRDN_COST
3606      , ETC_BRDN_COST
3607      , ETC_RAW_COST
3608      , ETC_LABOR_RAW_COST
3609      , ETC_EQUIP_RAW_COST
3610      , CUSTOM1
3611      , CUSTOM2
3612      , CUSTOM3
3613      , CUSTOM4
3614      , CUSTOM5
3615      , CUSTOM6
3616      , CUSTOM7
3617      , CUSTOM8
3618      , CUSTOM9
3619      , CUSTOM10
3620      , CUSTOM11
3621      , CUSTOM12
3622      , CUSTOM13
3623      , CUSTOM14
3624      , CUSTOM15
3625      , TIME_DANGLING_FLAG
3626      , RATE_DANGLING_FLAG
3627      , PRG_LEVEL
3628      , PLAN_TYPE_CODE    /* 4471527 */
3629    )
3630    SELECT
3631            g_worker_id worker_id
3632          , a.PROJECT_ID
3633          , a.PROJECT_ORG_ID
3634          , a.PROJECT_ORGANIZATION_ID
3635          , a.PROJECT_ELEMENT_ID
3636          , a.TIME_ID
3637          , 32 -- a.PERIOD_TYPE_ID
3638          , a.CALENDAR_TYPE
3639          , a.RBS_AGGR_LEVEL
3640          , a.WBS_ROLLUP_FLAG
3641          , a.PRG_ROLLUP_FLAG
3642          , a.CURR_RECORD_TYPE_ID
3643          , a.CURRENCY_CODE
3644          , a.RBS_ELEMENT_ID
3645          , a.RBS_VERSION_ID
3646          , a.PLAN_VERSION_ID
3647          , a.PLAN_TYPE_ID
3648 	 , SUM(ROUND (nvl(a.raw_cost,0)*a.factor/a.mau)*a.mau) raw_cost
3649 	 , SUM(ROUND (nvl(a.brdn_cost,0)*a.factor/a.mau)*a.mau) brdn_cost
3650 	 , SUM(ROUND (nvl(a.revenue,0)*a.factor/a.mau)*a.mau) revenue
3651 	 , SUM(ROUND (nvl(a.bill_raw_cost,0)*a.factor/a.mau)*a.mau) bill_raw_cost
3652 	 , SUM(ROUND (nvl(a.bill_brdn_cost,0)*a.factor/a.mau)*a.mau) bill_brdn_cost
3653 	 , SUM(ROUND (nvl(a.bill_labor_raw_cost,0)*a.factor/a.mau)*a.mau) bill_labor_raw_cost
3654 	 , SUM(ROUND (nvl(a.bill_labor_brdn_cost,0)*a.factor/a.mau)*a.mau) bill_labor_brdn_cost
3655 	 , SUM(ROUND (nvl(a.bill_labor_hrs,0)*a.factor/a.mau)*a.mau) bill_labor_hrs
3656 	 , SUM(ROUND (nvl(a.equipment_raw_cost,0)*a.factor/a.mau)*a.mau) equipment_raw_cost
3657 	 , SUM(ROUND (nvl(a.equipment_brdn_cost,0)*a.factor/a.mau)*a.mau) equipment_brdn_cost
3658 	 , SUM(ROUND (nvl(a.capitalizable_raw_cost,0)*a.factor/a.mau)*a.mau) capitalizable_raw_cost
3659 	 , SUM(ROUND (nvl(a.capitalizable_brdn_cost,0)*a.factor/a.mau)*a.mau) capitalizable_brdn_cost
3660 	 , SUM(ROUND (nvl(a.labor_raw_cost,0)*a.factor/a.mau)*a.mau) labor_raw_cost
3661 	 , SUM(ROUND (nvl(a.labor_brdn_cost,0)*a.factor/a.mau)*a.mau) labor_brdn_cost
3662 	 , SUM(ROUND (nvl(a.labor_hrs,0)*a.factor/a.mau)*a.mau) labor_hrs
3663 	 , SUM(ROUND (nvl(a.labor_revenue,0)*a.factor/a.mau)*a.mau) labor_revenue
3664 	 , SUM(ROUND (nvl(a.equipment_hours,0)*a.factor/a.mau)*a.mau) equipment_hours
3665 	 , SUM(ROUND (nvl(a.billable_equipment_hours,0)*a.factor/a.mau)*a.mau) billable_equipment_hours
3666 	 , SUM(ROUND (nvl(a.sup_inv_committed_cost,0)*a.factor/a.mau)*a.mau) sup_inv_committed_cost
3667 	 , SUM(ROUND (nvl(a.po_committed_cost,0)*a.factor/a.mau)*a.mau) po_committed_cost
3668 	 , SUM(ROUND (nvl(a.pr_committed_cost,0)*a.factor/a.mau)*a.mau) pr_committed_cost
3669 	 , SUM(ROUND (nvl(a.oth_committed_cost,0)*a.factor/a.mau)*a.mau) oth_committed_cost
3670 	 , SUM(ROUND (nvl(a.ACT_LABOR_HRS,0)*a.factor/a.mau)*a.mau) ACT_LABOR_HRS
3671 	 , SUM(ROUND (nvl(a.ACT_EQUIP_HRS,0)*a.factor/a.mau)*a.mau) ACT_EQUIP_HRS
3672 	 , SUM(ROUND (nvl(a.ACT_LABOR_BRDN_COST,0)*a.factor/a.mau)*a.mau) ACT_LABOR_BRDN_COST
3673 	 , SUM(ROUND (nvl(a.ACT_EQUIP_BRDN_COST,0)*a.factor/a.mau)*a.mau) ACT_EQUIP_BRDN_COST
3674 	 , SUM(ROUND (nvl(a.ACT_BRDN_COST,0)*a.factor/a.mau)*a.mau) ACT_BRDN_COST
3675 	 , SUM(ROUND (nvl(a.ACT_RAW_COST,0)*a.factor/a.mau)*a.mau) ACT_RAW_COST
3676 	 , SUM(ROUND (nvl(a.ACT_REVENUE,0)*a.factor/a.mau)*a.mau) ACT_REVENUE
3677 	 , SUM(ROUND (nvl(a.ACT_LABOR_RAW_COST,0)*a.factor/a.mau)*a.mau) ACT_LABOR_RAW_COST
3678 	 , SUM(ROUND (nvl(a.ACT_EQUIP_RAW_COST,0)*a.factor/a.mau)*a.mau) ACT_EQUIP_RAW_COST
3679 	 , SUM(ROUND (nvl(a.ETC_LABOR_HRS,0)*a.factor/a.mau)*a.mau) ETC_LABOR_HRS
3680 	 , SUM(ROUND (nvl(a.ETC_EQUIP_HRS,0)*a.factor/a.mau)*a.mau) ETC_EQUIP_HRS
3681 	 , SUM(ROUND (nvl(a.ETC_LABOR_BRDN_COST,0)*a.factor/a.mau)*a.mau) ETC_LABOR_BRDN_COST
3682 	 , SUM(ROUND (nvl(a.ETC_EQUIP_BRDN_COST,0)*a.factor/a.mau)*a.mau) ETC_EQUIP_BRDN_COST
3683 	 , SUM(ROUND (nvl(a.ETC_BRDN_COST,0)*a.factor/a.mau)*a.mau) ETC_BRDN_COST
3684 	 , SUM(ROUND (nvl(a.ETC_RAW_COST,0)*a.factor/a.mau)*a.mau) ETC_RAW_COST
3685 	 , SUM(ROUND (nvl(a.ETC_LABOR_RAW_COST,0)*a.factor/a.mau)*a.mau) ETC_LABOR_RAW_COST
3686 	 , SUM(ROUND (nvl(a.ETC_EQUIP_RAW_COST,0)*a.factor/a.mau)*a.mau) ETC_EQUIP_RAW_COST
3687 	 , SUM(ROUND (nvl(a.custom1,0)*a.factor/a.mau)*a.mau) custom1
3688 	 , SUM(ROUND (nvl(a.custom2,0)*a.factor/a.mau)*a.mau) custom2
3689 	 , SUM(ROUND (nvl(a.custom3,0)*a.factor/a.mau)*a.mau) custom3
3690 	 , SUM(ROUND (nvl(a.custom4,0)*a.factor/a.mau)*a.mau) custom4
3691 	 , SUM(ROUND (nvl(a.custom5,0)*a.factor/a.mau)*a.mau) custom5
3692 	 , SUM(ROUND (nvl(a.custom6,0)*a.factor/a.mau)*a.mau) custom6
3693 	 , SUM(ROUND (nvl(a.custom7,0)*a.factor/a.mau)*a.mau) custom7
3694 	 , SUM(ROUND (nvl(a.custom8,0)*a.factor/a.mau)*a.mau) custom8
3695 	 , SUM(ROUND (nvl(a.custom9,0)*a.factor/a.mau)*a.mau) custom9
3696 	 , SUM(ROUND (nvl(a.custom10,0)*a.factor/a.mau)*a.mau) custom10
3697 	 , SUM(ROUND (nvl(a.custom11,0)*a.factor/a.mau)*a.mau) custom11
3698 	 , SUM(ROUND (nvl(a.custom12,0)*a.factor/a.mau)*a.mau) custom12
3699 	 , SUM(ROUND (nvl(a.custom13,0)*a.factor/a.mau)*a.mau) custom13
3700 	 , SUM(ROUND (nvl(a.custom14,0)*a.factor/a.mau)*a.mau) custom14
3701 	 , SUM(ROUND (nvl(a.custom15,0)*a.factor/a.mau)*a.mau) custom15
3702          , a.TIME_DANGLING_FLAG
3703          , a.RATE_DANGLING_FLAG
3704          , g_default_prg_level prg_level
3705          , a.plan_type_code plan_type_code /* 4471527 */
3706    FROM (
3707    SELECT /*+ NO_MERGE */
3708            fact.project_id  project_id
3709    	 , fact.project_ORG_ID project_ORG_ID
3710    	 , fact.project_ORGANIZATION_ID project_ORGANIZATION_ID
3711    	 , fact.PROJECT_ELEMENT_ID PROJECT_ELEMENT_ID
3712    	 , entCal.ent_period_id TIME_ID
3713    	 , fact.PERIOD_TYPE_ID PERIOD_TYPE_ID
3714    	 , 'E' CALENDAR_TYPE -- fact.CALENDAR_TYPE
3715          , fact.RBS_AGGR_LEVEL
3716          , fact.WBS_ROLLUP_FLAG
3717          , fact.PRG_ROLLUP_FLAG
3718    	 , fact.CURR_RECORD_TYPE_ID CURR_RECORD_TYPE_ID
3719    	 , fact.CURRENCY_CODE CURRENCY_CODE
3720    	 , fact.RBS_ELEMENT_ID RBS_ELEMENT_ID
3721    	 , fact.RBS_VERSION_ID RBS_VERSION_ID
3722    	 , fact.PLAN_VERSION_ID PLAN_VERSION_ID
3723 	 , fact.PLAN_TYPE_ID  PLAN_TYPE_ID
3724 	 , fact.raw_cost
3725 	 , fact.brdn_cost
3726 	 , fact.revenue
3727 	 , fact.bill_raw_cost
3728 	 , fact.bill_brdn_cost
3729 	 , fact.bill_labor_raw_cost
3730 	 , fact.bill_labor_brdn_cost
3731 	 , fact.bill_labor_hrs
3732 	 , fact.equipment_raw_cost
3733 	 , fact.equipment_brdn_cost
3734 	 , fact.capitalizable_raw_cost
3735 	 , fact.capitalizable_brdn_cost
3736 	 , fact.labor_raw_cost
3737 	 , fact.labor_brdn_cost
3738 	 , fact.labor_hrs
3739 	 , fact.labor_revenue
3740 	 , fact.equipment_hours
3741 	 , fact.billable_equipment_hours
3742 	 , fact.sup_inv_committed_cost
3743 	 , fact.po_committed_cost
3744 	 , fact.pr_committed_cost
3745 	 , fact.oth_committed_cost
3746 	 , fact.ACT_LABOR_HRS
3747 	 , fact.ACT_EQUIP_HRS
3748 	 , fact.ACT_LABOR_BRDN_COST
3749 	 , fact.ACT_EQUIP_BRDN_COST
3750 	 , fact.ACT_BRDN_COST
3751 	 , fact.ACT_RAW_COST
3752 	 , fact.ACT_REVENUE
3753 	 , fact.ACT_LABOR_RAW_COST
3754 	 , fact.ACT_EQUIP_RAW_COST
3755 	 , fact.ETC_LABOR_HRS
3756 	 , fact.ETC_EQUIP_HRS
3757 	 , fact.ETC_LABOR_BRDN_COST
3758 	 , fact.ETC_EQUIP_BRDN_COST
3759 	 , fact.ETC_BRDN_COST
3760 	 , fact.ETC_RAW_COST
3761 	 , fact.ETC_LABOR_RAW_COST
3762 	 , fact.ETC_EQUIP_RAW_COST
3763 	 , fact.custom1
3764 	 , fact.custom2
3765 	 , fact.custom3
3766 	 , fact.custom4
3767 	 , fact.custom5
3768 	 , fact.custom6
3769 	 , fact.custom7
3770 	 , fact.custom8
3771 	 , fact.custom9
3772 	 , fact.custom10
3773 	 , fact.custom11
3774 	 , fact.custom12
3775 	 , fact.custom13
3776 	 , fact.custom14
3777 	 , fact.custom15
3778 	 , fact.time_dangling_flag time_dangling_flag
3779 	 , fact.rate_dangling_flag rate_dangling_flag
3780          , cur.mau mau
3781          , (LEAST(fact.end_date,entCal.end_date) - Greatest(fact.start_date,entCal.start_date)+1)
3782                               / (fact.end_date - fact.start_date+1) factor
3783          , fact.plan_type_code plan_type_code   /* 4471527 */
3784    FROM   pji_fp_aggr_pjp1 fact
3785         , pji_time_ent_period_v  entCal
3786         , pji_fm_extr_plnver4  ver
3787         , (SELECT currency_code,
3788                    decode(nvl(MINIMUM_ACCOUNTABLE_UNIT, power(10, (-1 * PRECISION))),
3789                       null, 0.01,
3790                          0, 1,
3791                          nvl(MINIMUM_ACCOUNTABLE_UNIT, power(10, (-1 * PRECISION)))) mau
3792               FROM FND_CURRENCIES) cur
3793    WHERE  1=1
3794       AND fact.CALENDAR_TYPE = 'A'
3795       AND fact.worker_id = g_worker_id
3796       AND ver.worker_id = g_worker_id
3797       AND fact.start_date IS NOT NULL
3798       AND fact.end_date IS NOT NULL
3799       AND fact.time_dangling_flag IS NULL
3800       AND fact.rate_dangling_flag IS NULL
3801       AND fact.line_type = 'NTP'
3802       AND fact.period_type_id = 2048
3803       AND fact.plan_version_id = ver.plan_version_id
3804       AND fact.plan_type_code = ver.plan_type_code  /* 4471527 */
3805       AND ver.wp_flag = 'N'
3806       AND ver.baselined_flag = 'Y'
3807       AND ver.time_phased_type_code = 'N'
3808 	AND fact.rbs_version_id = NVL(ver.rbs_struct_version_id , -1)
3809       AND cur.currency_code = fact.currency_code
3810       AND ( fact.start_date <= entCal.end_date AND fact.end_date >= entCal.start_date )
3811       AND ver.plan_version_id > 0
3812 	  ) a
3813    WHERE a.factor>0
3814   GROUP BY
3815        a.PROJECT_ID
3816      , a.PROJECT_ORG_ID
3817      , a.PROJECT_ORGANIZATION_ID
3818      , a.PROJECT_ELEMENT_ID
3819      , a.TIME_ID
3820      , a.PERIOD_TYPE_ID
3821      , a.CALENDAR_TYPE
3822      , a.RBS_AGGR_LEVEL
3823      , a.WBS_ROLLUP_FLAG
3824      , a.PRG_ROLLUP_FLAG
3825      , a.CURR_RECORD_TYPE_ID
3826      , a.CURRENCY_CODE
3827      , a.RBS_ELEMENT_ID
3828      , a.RBS_VERSION_ID
3829      , a.PLAN_VERSION_ID
3830      , a.PLAN_TYPE_ID
3831      , a.TIME_DANGLING_FLAG
3832      , a.RATE_DANGLING_FLAG
3833      , a.PLAN_TYPE_CODE  ;     /* 4471527 */
3834 
3835 	end if;
3836 
3837 EXCEPTION
3838   WHEN OTHERS THEN
3839     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
3840                              p_procedure_name => ' PRORATE_TO_ENT_N_PJP1_D ');
3841     RAISE;
3842 END;
3843 
3844 
3845 PROCEDURE PRORATE_TO_ENT_PG_PJP1_SE(p_prorating_format IN VARCHAR2) IS
3846 BEGIN
3847 
3848     g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
3849 
3850 /* Commented for bug 4005006
3851 
3852     INSERT INTO pji_fp_aggr_pjp1   -- PA, GL calendar entries.
3853     (
3854        WORKER_ID
3855      , PROJECT_ID
3856      , PROJECT_ORG_ID
3857      , PROJECT_ORGANIZATION_ID
3858      -- , PARTITION_ID
3859      , PROJECT_ELEMENT_ID
3860      , TIME_ID
3861      , PERIOD_TYPE_ID
3862      , CALENDAR_TYPE
3863      , RBS_AGGR_LEVEL
3864      , WBS_ROLLUP_FLAG
3865      , PRG_ROLLUP_FLAG
3866      , CURR_RECORD_TYPE_ID
3867      , CURRENCY_CODE
3868      , RBS_ELEMENT_ID
3869      , RBS_VERSION_ID
3870      , PLAN_VERSION_ID
3871      , PLAN_TYPE_ID
3872      , RAW_COST
3873      , BRDN_COST
3874      , REVENUE
3875      , BILL_RAW_COST
3876      , BILL_BRDN_COST
3877      , BILL_LABOR_RAW_COST
3878      , BILL_LABOR_BRDN_COST
3879      , BILL_LABOR_HRS
3880      , EQUIPMENT_RAW_COST
3881      , EQUIPMENT_BRDN_COST
3882      , CAPITALIZABLE_RAW_COST
3883      , CAPITALIZABLE_BRDN_COST
3884      , LABOR_RAW_COST
3885      , LABOR_BRDN_COST
3886      , LABOR_HRS
3887      , LABOR_REVENUE
3888      , EQUIPMENT_HOURS
3889      , BILLABLE_EQUIPMENT_HOURS
3890      , SUP_INV_COMMITTED_COST
3891      , PO_COMMITTED_COST
3892      , PR_COMMITTED_COST
3893      , OTH_COMMITTED_COST
3894        , ACT_LABOR_HRS
3895 	   , ACT_EQUIP_HRS
3896 	   , ACT_LABOR_BRDN_COST
3897 	   , ACT_EQUIP_BRDN_COST
3898 	   , ACT_BRDN_COST
3899 	   , ACT_RAW_COST
3900 	   , ACT_REVENUE
3901          , ACT_LABOR_RAW_COST
3902          , ACT_EQUIP_RAW_COST
3903 	   , ETC_LABOR_HRS
3904 	   , ETC_EQUIP_HRS
3905 	   , ETC_LABOR_BRDN_COST
3906 	   , ETC_EQUIP_BRDN_COST
3907 	   , ETC_BRDN_COST
3908          , ETC_RAW_COST
3909          , ETC_LABOR_RAW_COST
3910          , ETC_EQUIP_RAW_COST
3911      , CUSTOM1
3912      , CUSTOM2
3913      , CUSTOM3
3914      , CUSTOM4
3915      , CUSTOM5
3916      , CUSTOM6
3917      , CUSTOM7
3918      , CUSTOM8
3919      , CUSTOM9
3920      , CUSTOM10
3921      , CUSTOM11
3922      , CUSTOM12
3923      , CUSTOM13
3924      , CUSTOM14
3925      , CUSTOM15
3926 	 , LINE_TYPE
3927 	 , TIME_DANGLING_FLAG
3928 	 , RATE_DANGLING_FLAG
3929 	 , PRG_LEVEL
3930 	)
3931    SELECT
3932          g_worker_id WORKER_ID
3933        , fact.project_id  project_id
3934 	 , fact.PROJECT_ORG_ID project_org_id
3935 	 , fact.PROJECT_ORGANIZATION_ID project_organization_id
3936      -- , fact.PARTITION_ID PARTITION_ID
3937    	 , fact.PROJECT_ELEMENT_ID PROJECT_ELEMENT_ID
3938    	 , pa_cal.ent_period_id TIME_ID
3939    	 , fact.PERIOD_TYPE_ID PERIOD_TYPE_ID
3940    	 , 'E' CALENDAR_TYPE -- fact.CALENDAR_TYPE
3941      , fact.RBS_AGGR_LEVEL RBS_AGGR_LEVEL
3942      , fact.WBS_ROLLUP_FLAG WBS_ROLLUP_FLAG
3943      , fact.PRG_ROLLUP_FLAG PRG_ROLLUP_FLAG
3944      , fact.CURR_RECORD_TYPE_ID CURR_RECORD_TYPE_ID
3945    	 , fact.CURRENCY_CODE CURRENCY_CODE
3946    	 , fact.RBS_ELEMENT_ID RBS_ELEMENT_ID
3947    	 , fact.RBS_VERSION_ID RBS_VERSION_ID
3948    	 , fact.PLAN_VERSION_ID PLAN_VERSION_ID
3949    	 , fact.PLAN_TYPE_ID PLAN_TYPE_ID
3950    	 , MAX(fact.RAW_COST)	 raw_cost
3951    	 , MAX(fact.BRDN_COST) BRDN_COST
3952    	 , MAX(fact.REVENUE) REVENUE
3953    	 , MAX(fact.BILL_RAW_COST) BILL_RAW_COST
3954    	 , MAX(fact.BILL_BRDN_COST) BILL_BRDN_COST
3955    	 , MAX(fact.BILL_LABOR_RAW_COST) BILL_LABOR_RAW_COST
3956    	 , MAX(fact.BILL_LABOR_BRDN_COST) BILL_LABOR_BRDN_COST
3957    	 , MAX(fact.BILL_LABOR_HRS) BILL_LABOR_HRS
3958    	 , MAX(fact.EQUIPMENT_RAW_COST) EQUIPMENT_RAW_COST
3959    	 , MAX(fact.EQUIPMENT_BRDN_COST) EQUIPMENT_BRDN_COST
3960    	 , MAX(fact.CAPITALIZABLE_RAW_COST) CAPITALIZABLE_RAW_COST
3961    	 , MAX(fact.CAPITALIZABLE_BRDN_COST) CAPITALIZABLE_BRDN_COST
3962    	 , MAX(fact.LABOR_RAW_COST) LABOR_RAW_COST
3963    	 , MAX(fact.LABOR_BRDN_COST) LABOR_BRDN_COST
3964    	 , MAX(fact.LABOR_HRS) LABOR_HRS
3965    	 , MAX(fact.LABOR_REVENUE) LABOR_REVENUE
3966    	 , MAX(fact.EQUIPMENT_HOURS) EQUIPMENT_HOURS
3967    	 , MAX(fact.BILLABLE_EQUIPMENT_HOURS) BILLABLE_EQUIPMENT_HOURS
3968    	 , MAX(fact.SUP_INV_COMMITTED_COST) SUP_INV_COMMITTED_COST
3969    	 , MAX(fact.PO_COMMITTED_COST) PO_COMMITTED_COST
3970    	 , MAX(fact.PR_COMMITTED_COST) PR_COMMITTED_COST
3971    	 , MAX(fact.OTH_COMMITTED_COST) OTH_COMMITTED_COST
3972        , MAX(fact.ACT_LABOR_HRS )
3973 	 , MAX(fact.ACT_EQUIP_HRS )
3974 	 , MAX(fact.ACT_LABOR_BRDN_COST )
3975 	 , MAX(fact.ACT_EQUIP_BRDN_COST )
3976 	 , MAX(fact.ACT_BRDN_COST )
3977 	 , MAX(fact.ACT_RAW_COST )
3978 	 , MAX(fact.ACT_REVENUE )
3979        , MAX(fact.ACT_LABOR_RAW_COST)
3980        , MAX(fact.ACT_EQUIP_RAW_COST)
3981 	 , MAX(fact.ETC_LABOR_HRS )
3982 	 , MAX(fact.ETC_EQUIP_HRS )
3983 	 , MAX(fact.ETC_LABOR_BRDN_COST )
3984 	 , MAX(fact.ETC_EQUIP_BRDN_COST )
3985 	 , MAX(fact.ETC_BRDN_COST )
3986        , MAX(fact.ETC_RAW_COST )
3987        , MAX(fact.ETC_LABOR_RAW_COST)
3988        , MAX(fact.ETC_EQUIP_RAW_COST)
3989    	 , MAX(fact.CUSTOM1) CUSTOM1
3990    	 , MAX(fact.CUSTOM2) CUSTOM2
3991    	 , MAX(fact.CUSTOM3) CUSTOM3
3992    	 , MAX(fact.CUSTOM4) CUSTOM4
3993    	 , MAX(fact.CUSTOM5) CUSTOM5
3994    	 , MAX(fact.CUSTOM6) CUSTOM6
3995    	 , MAX(fact.CUSTOM7) CUSTOM7
3996    	 , MAX(fact.CUSTOM8) CUSTOM8
3997    	 , MAX(fact.CUSTOM9) CUSTOM9
3998    	 , MAX(fact.CUSTOM10) CUSTOM10
3999    	 , MAX(fact.CUSTOM11) CUSTOM11
4000    	 , MAX(fact.CUSTOM12) CUSTOM12
4001    	 , MAX(fact.CUSTOM13) CUSTOM13
4002    	 , MAX(fact.CUSTOM14) CUSTOM14
4003    	 , MAX(fact.CUSTOM15) CUSTOM15
4004    	 -- , DECODE ('E', 'E', MAX(pa_cal.start_date), 'S', MIN(pa_cal.start_date)) start_date
4005    	 -- , DECODE ('E', 'E', MAX(pa_cal.end_date), 'S', MIN(pa_cal.end_date))	 end_date
4006      , 'CF'   line_type
4007 	 , fact.TIME_DANGLING_FLAG  TIME_DANGLING_FLAG
4008 	 , fact.RATE_DANGLING_FLAG  RATE_DANGLING_FLAG
4009 	 , g_default_prg_level PRG_LEVEL
4010    FROM   pji_fp_aggr_pjp1 fact
4011         , pji_time_cal_period  non_pa_cal
4012         -- , pji_org_extr_info  orginfo
4013    	  , pji_time_ent_period  pa_cal
4014         , pji_fm_extr_plnver4  ver
4015    WHERE  fact.CALENDAR_TYPE IN ('P', 'G')
4016       AND fact.worker_id = g_worker_id
4017       AND ver.worker_id = g_worker_id
4018       AND non_pa_cal.cal_period_id = fact.time_id
4019       AND fact.line_type like 'OF%'
4020 	AND fact.TIME_DANGLING_FLAG  IS NULL
4021 	AND fact.RATE_DANGLING_FLAG  IS NULL
4022       AND ( non_pa_cal.start_date <= pa_cal.end_date AND non_pa_cal.end_date >= pa_cal.start_date )
4023       AND fact.period_type_id = 32
4024       AND fact.plan_version_id = ver.plan_version_id
4025       AND ver.wp_flag = 'N'
4026       AND ver.baselined_flag = 'Y'
4027 	AND fact.rbs_version_id = NVL(ver.rbs_struct_version_id , -1)
4028       AND ver.plan_version_id > 0
4029    GROUP BY
4030        fact.project_id
4031 	 , fact.PROJECT_ORG_ID
4032 	 , fact.PROJECT_ORGANIZATION_ID
4033      -- , fact.PARTITION_ID
4034    	 , fact.PROJECT_ELEMENT_ID
4035    	 , pa_cal.ent_period_id
4036    	 , fact.PERIOD_TYPE_ID
4037    	 , fact.CALENDAR_TYPE
4038      , fact.RBS_AGGR_LEVEL
4039      , fact.WBS_ROLLUP_FLAG
4040      , fact.PRG_ROLLUP_FLAG
4041      , fact.CURR_RECORD_TYPE_ID
4042    	 , fact.CURRENCY_CODE
4043    	 , fact.RBS_ELEMENT_ID
4044    	 , fact.RBS_VERSION_ID
4045    	 , fact.PLAN_VERSION_ID
4046    	 , fact.PLAN_TYPE_ID
4047 	 , fact.TIME_DANGLING_FLAG
4048 	 , fact.RATE_DANGLING_FLAG;
4049 End of bug 4005006*/
4050 
4051     INSERT INTO pji_fp_aggr_pjp1   -- PA, GL calendar entries.
4052     (
4053        WORKER_ID
4054      , PROJECT_ID
4055      , PROJECT_ORG_ID
4056      , PROJECT_ORGANIZATION_ID
4057      , PROJECT_ELEMENT_ID
4058      , TIME_ID
4059      , PERIOD_TYPE_ID
4060      , CALENDAR_TYPE
4061      , RBS_AGGR_LEVEL
4062      , WBS_ROLLUP_FLAG
4063      , PRG_ROLLUP_FLAG
4064      , CURR_RECORD_TYPE_ID
4065      , CURRENCY_CODE
4066      , RBS_ELEMENT_ID
4067      , RBS_VERSION_ID
4068      , PLAN_VERSION_ID
4069      , PLAN_TYPE_ID
4070      , RAW_COST
4071      , BRDN_COST
4072      , REVENUE
4073      , BILL_RAW_COST
4074      , BILL_BRDN_COST
4075      , BILL_LABOR_RAW_COST
4076      , BILL_LABOR_BRDN_COST
4077      , BILL_LABOR_HRS
4078      , EQUIPMENT_RAW_COST
4079      , EQUIPMENT_BRDN_COST
4080      , CAPITALIZABLE_RAW_COST
4081      , CAPITALIZABLE_BRDN_COST
4082      , LABOR_RAW_COST
4083      , LABOR_BRDN_COST
4084      , LABOR_HRS
4085      , LABOR_REVENUE
4086      , EQUIPMENT_HOURS
4087      , BILLABLE_EQUIPMENT_HOURS
4088      , SUP_INV_COMMITTED_COST
4089      , PO_COMMITTED_COST
4090      , PR_COMMITTED_COST
4091      , OTH_COMMITTED_COST
4092      , ACT_LABOR_HRS
4093      , ACT_EQUIP_HRS
4094      , ACT_LABOR_BRDN_COST
4095      , ACT_EQUIP_BRDN_COST
4096      , ACT_BRDN_COST
4097      , ACT_RAW_COST
4098      , ACT_REVENUE
4099      , ACT_LABOR_RAW_COST
4100      , ACT_EQUIP_RAW_COST
4101      , ETC_LABOR_HRS
4102      , ETC_EQUIP_HRS
4103      , ETC_LABOR_BRDN_COST
4104      , ETC_EQUIP_BRDN_COST
4105      , ETC_BRDN_COST
4106      , ETC_RAW_COST
4107      , ETC_LABOR_RAW_COST
4108      , ETC_EQUIP_RAW_COST
4109      , CUSTOM1
4110      , CUSTOM2
4111      , CUSTOM3
4112      , CUSTOM4
4113      , CUSTOM5
4114      , CUSTOM6
4115      , CUSTOM7
4116      , CUSTOM8
4117      , CUSTOM9
4118      , CUSTOM10
4119      , CUSTOM11
4120      , CUSTOM12
4121      , CUSTOM13
4122      , CUSTOM14
4123      , CUSTOM15
4124      , TIME_DANGLING_FLAG
4125      , RATE_DANGLING_FLAG
4126      , PRG_LEVEL
4127      , PLAN_TYPE_CODE    /* 4471527 */
4128    )
4129    SELECT
4130            g_worker_id WORKER_ID
4131          , fact.project_id  project_id
4132 	 , fact.PROJECT_ORG_ID project_org_id
4133 	 , fact.PROJECT_ORGANIZATION_ID project_organization_id
4134    	 , fact.PROJECT_ELEMENT_ID PROJECT_ELEMENT_ID
4135    	 , pa_cal.ent_period_id TIME_ID
4136    	 , fact.PERIOD_TYPE_ID PERIOD_TYPE_ID
4137    	 , 'E' CALENDAR_TYPE -- fact.CALENDAR_TYPE
4138          , fact.RBS_AGGR_LEVEL RBS_AGGR_LEVEL
4139          , fact.WBS_ROLLUP_FLAG WBS_ROLLUP_FLAG
4140          , fact.PRG_ROLLUP_FLAG PRG_ROLLUP_FLAG
4141          , fact.CURR_RECORD_TYPE_ID CURR_RECORD_TYPE_ID
4142    	 , fact.CURRENCY_CODE CURRENCY_CODE
4143    	 , fact.RBS_ELEMENT_ID RBS_ELEMENT_ID
4144    	 , fact.RBS_VERSION_ID RBS_VERSION_ID
4145    	 , fact.PLAN_VERSION_ID PLAN_VERSION_ID
4146    	 , fact.PLAN_TYPE_ID PLAN_TYPE_ID
4147    	 , SUM(fact.RAW_COST)	 raw_cost
4148    	 , SUM(fact.BRDN_COST) BRDN_COST
4149    	 , SUM(fact.REVENUE) REVENUE
4150    	 , SUM(fact.BILL_RAW_COST) BILL_RAW_COST
4151    	 , SUM(fact.BILL_BRDN_COST) BILL_BRDN_COST
4152    	 , SUM(fact.BILL_LABOR_RAW_COST) BILL_LABOR_RAW_COST
4153    	 , SUM(fact.BILL_LABOR_BRDN_COST) BILL_LABOR_BRDN_COST
4154    	 , SUM(fact.BILL_LABOR_HRS) BILL_LABOR_HRS
4155    	 , SUM(fact.EQUIPMENT_RAW_COST) EQUIPMENT_RAW_COST
4156    	 , SUM(fact.EQUIPMENT_BRDN_COST) EQUIPMENT_BRDN_COST
4157    	 , SUM(fact.CAPITALIZABLE_RAW_COST) CAPITALIZABLE_RAW_COST
4158    	 , SUM(fact.CAPITALIZABLE_BRDN_COST) CAPITALIZABLE_BRDN_COST
4159    	 , SUM(fact.LABOR_RAW_COST) LABOR_RAW_COST
4160    	 , SUM(fact.LABOR_BRDN_COST) LABOR_BRDN_COST
4161    	 , SUM(fact.LABOR_HRS) LABOR_HRS
4162    	 , SUM(fact.LABOR_REVENUE) LABOR_REVENUE
4163    	 , SUM(fact.EQUIPMENT_HOURS) EQUIPMENT_HOURS
4164    	 , SUM(fact.BILLABLE_EQUIPMENT_HOURS) BILLABLE_EQUIPMENT_HOURS
4165    	 , SUM(fact.SUP_INV_COMMITTED_COST) SUP_INV_COMMITTED_COST
4166    	 , SUM(fact.PO_COMMITTED_COST) PO_COMMITTED_COST
4167    	 , SUM(fact.PR_COMMITTED_COST) PR_COMMITTED_COST
4168    	 , SUM(fact.OTH_COMMITTED_COST) OTH_COMMITTED_COST
4169          , SUM(fact.ACT_LABOR_HRS )
4170 	 , SUM(fact.ACT_EQUIP_HRS )
4171 	 , SUM(fact.ACT_LABOR_BRDN_COST )
4172 	 , SUM(fact.ACT_EQUIP_BRDN_COST )
4173 	 , SUM(fact.ACT_BRDN_COST )
4174 	 , SUM(fact.ACT_RAW_COST )
4175 	 , SUM(fact.ACT_REVENUE )
4176          , SUM(fact.ACT_LABOR_RAW_COST)
4177          , SUM(fact.ACT_EQUIP_RAW_COST)
4178 	 , SUM(fact.ETC_LABOR_HRS )
4179 	 , SUM(fact.ETC_EQUIP_HRS )
4180 	 , SUM(fact.ETC_LABOR_BRDN_COST )
4181 	 , SUM(fact.ETC_EQUIP_BRDN_COST )
4182 	 , SUM(fact.ETC_BRDN_COST )
4183          , SUM(fact.ETC_RAW_COST )
4184          , SUM(fact.ETC_LABOR_RAW_COST)
4185          , SUM(fact.ETC_EQUIP_RAW_COST)
4186    	 , SUM(fact.CUSTOM1) CUSTOM1
4187    	 , SUM(fact.CUSTOM2) CUSTOM2
4188    	 , SUM(fact.CUSTOM3) CUSTOM3
4189    	 , SUM(fact.CUSTOM4) CUSTOM4
4190    	 , SUM(fact.CUSTOM5) CUSTOM5
4191    	 , SUM(fact.CUSTOM6) CUSTOM6
4192    	 , SUM(fact.CUSTOM7) CUSTOM7
4193    	 , SUM(fact.CUSTOM8) CUSTOM8
4194    	 , SUM(fact.CUSTOM9) CUSTOM9
4195    	 , SUM(fact.CUSTOM10) CUSTOM10
4196    	 , SUM(fact.CUSTOM11) CUSTOM11
4197    	 , SUM(fact.CUSTOM12) CUSTOM12
4198    	 , SUM(fact.CUSTOM13) CUSTOM13
4199    	 , SUM(fact.CUSTOM14) CUSTOM14
4200    	 , SUM(fact.CUSTOM15) CUSTOM15
4201 	 , fact.TIME_DANGLING_FLAG  TIME_DANGLING_FLAG
4202 	 , fact.RATE_DANGLING_FLAG  RATE_DANGLING_FLAG
4203          , g_default_prg_level prg_level
4204          , fact.PLAN_TYPE_CODE   PLAN_TYPE_CODE   /* 4471527 */
4205    FROM   pji_fp_aggr_pjp1 fact
4206         , pji_time_cal_period_v  non_pa_cal
4207    	, pji_time_ent_period_v  pa_cal
4208         , pji_fm_extr_plnver4  ver
4209    WHERE  fact.CALENDAR_TYPE IN ('P', 'G')
4210       AND fact.worker_id = g_worker_id
4211       AND ver.worker_id = g_worker_id
4212       AND non_pa_cal.cal_period_id = fact.time_id
4213       AND fact.line_type like 'OF%'
4214       AND fact.TIME_DANGLING_FLAG  IS NULL
4215       AND fact.RATE_DANGLING_FLAG  IS NULL
4216       AND ( non_pa_cal.start_date <= pa_cal.end_date AND non_pa_cal.end_date >= pa_cal.start_date )
4217       AND fact.period_type_id = 32
4218       AND fact.plan_version_id = ver.plan_version_id
4219      AND fact.plan_type_code = ver.plan_type_code /* 4471527 */
4220       AND ver.wp_flag = 'N'
4221       AND ver.baselined_flag = 'Y'
4222 	AND fact.rbs_version_id = NVL(ver.rbs_struct_version_id , -1)
4223       AND ver.plan_version_id > 0
4224       AND DECODE(p_prorating_format,'S',
4225              DECODE(SIGN(non_pa_cal.start_Date-pa_cal.start_date),-1,0,1),
4226              DECODE(SIGN(non_pa_cal.end_Date - pa_cal.end_date), 1,0,1))=1
4227    GROUP BY
4228            fact.project_id
4229 	 , fact.PROJECT_ORG_ID
4230 	 , fact.PROJECT_ORGANIZATION_ID
4231    	 , fact.PROJECT_ELEMENT_ID
4232    	 , pa_cal.ent_period_id
4233    	 , fact.PERIOD_TYPE_ID
4234    	 , fact.CALENDAR_TYPE
4235          , fact.RBS_AGGR_LEVEL
4236          , fact.WBS_ROLLUP_FLAG
4237          , fact.PRG_ROLLUP_FLAG
4238          , fact.CURR_RECORD_TYPE_ID
4239    	 , fact.CURRENCY_CODE
4240    	 , fact.RBS_ELEMENT_ID
4241    	 , fact.RBS_VERSION_ID
4242    	 , fact.PLAN_VERSION_ID
4243    	 , fact.PLAN_TYPE_ID
4244 	 , fact.TIME_DANGLING_FLAG
4245 	 , fact.RATE_DANGLING_FLAG
4246               , fact .PLAN_TYPE_CODE ;      /* 4471527 */
4247 
4248 EXCEPTION
4249   WHEN OTHERS THEN
4250     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
4251                              p_procedure_name => 'PRORATE_TO_ENT_PG_PJP1_SE');
4252     RAISE;
4253 END;
4254 
4255 
4256 PROCEDURE PRORATE_TO_ENT_PG_FPRL_SE IS
4257 BEGIN
4258 
4259     g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
4260 
4261 EXCEPTION
4262   WHEN OTHERS THEN
4263     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
4264                              p_procedure_name => 'PRORATE_TO_ENT_PG_FPRL_SE');
4265     RAISE;
4266 END;
4267 
4268 
4269 PROCEDURE PRORATE_TO_ENT_N_PJP1_SE(p_prorating_format varchar2) IS
4270 BEGIN
4271 
4272     g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
4273 
4274     INSERT INTO pji_fp_aggr_pjp1  -- Non time phased entries.
4275     (
4276        WORKER_ID
4277      , PROJECT_ID
4278      , PROJECT_ORG_ID
4279      , PROJECT_ORGANIZATION_ID
4280      , PROJECT_ELEMENT_ID
4281      , TIME_ID
4282      , PERIOD_TYPE_ID
4283      , CALENDAR_TYPE
4284      , RBS_AGGR_LEVEL
4285      , WBS_ROLLUP_FLAG
4286      , PRG_ROLLUP_FLAG
4287      , CURR_RECORD_TYPE_ID
4288      , CURRENCY_CODE
4289      , RBS_ELEMENT_ID
4290      , RBS_VERSION_ID
4291      , PLAN_VERSION_ID
4292      , PLAN_TYPE_ID
4293      , RAW_COST
4294      , BRDN_COST
4295      , REVENUE
4296      , BILL_RAW_COST
4297      , BILL_BRDN_COST
4298      , BILL_LABOR_RAW_COST
4299      , BILL_LABOR_BRDN_COST
4300      , BILL_LABOR_HRS
4301      , EQUIPMENT_RAW_COST
4302      , EQUIPMENT_BRDN_COST
4303      , CAPITALIZABLE_RAW_COST
4304      , CAPITALIZABLE_BRDN_COST
4305      , LABOR_RAW_COST
4306      , LABOR_BRDN_COST
4307      , LABOR_HRS
4308      , LABOR_REVENUE
4309      , EQUIPMENT_HOURS
4310      , BILLABLE_EQUIPMENT_HOURS
4311      , SUP_INV_COMMITTED_COST
4312      , PO_COMMITTED_COST
4313      , PR_COMMITTED_COST
4314      , OTH_COMMITTED_COST
4315      , ACT_LABOR_HRS
4316      , ACT_EQUIP_HRS
4317      , ACT_LABOR_BRDN_COST
4318      , ACT_EQUIP_BRDN_COST
4319      , ACT_BRDN_COST
4320      , ACT_RAW_COST
4321      , ACT_REVENUE
4322      , ACT_LABOR_RAW_COST
4323      , ACT_EQUIP_RAW_COST
4324      , ETC_LABOR_HRS
4325      , ETC_EQUIP_HRS
4326      , ETC_LABOR_BRDN_COST
4327      , ETC_EQUIP_BRDN_COST
4328      , ETC_BRDN_COST
4329      , ETC_RAW_COST
4330      , ETC_LABOR_RAW_COST
4331      , ETC_EQUIP_RAW_COST
4332      , CUSTOM1
4333      , CUSTOM2
4334      , CUSTOM3
4335      , CUSTOM4
4336      , CUSTOM5
4337      , CUSTOM6
4338      , CUSTOM7
4339      , CUSTOM8
4340      , CUSTOM9
4341      , CUSTOM10
4342      , CUSTOM11
4343      , CUSTOM12
4344      , CUSTOM13
4345      , CUSTOM14
4346      , CUSTOM15
4347      , TIME_DANGLING_FLAG
4348      , RATE_DANGLING_FLAG
4349      , PRG_LEVEL
4350      , PLAN_TYPE_CODE    /* 4471527 */
4351    )
4352    SELECT
4353            g_worker_id WORKER_ID
4354          , fact.project_id  project_id
4355 	 , fact.PROJECT_ORG_ID project_org_id
4356 	 , fact.PROJECT_ORGANIZATION_ID project_organization_id
4357    	 , fact.PROJECT_ELEMENT_ID PROJECT_ELEMENT_ID
4358    	 , pa_cal.ent_period_id TIME_ID
4359    	 , 32 -- fact.PERIOD_TYPE_ID PERIOD_TYPE_ID
4360    	 , 'E' CALENDAR_TYPE -- fact.CALENDAR_TYPE
4361          , fact.RBS_AGGR_LEVEL RBS_AGGR_LEVEL
4362          , fact.WBS_ROLLUP_FLAG WBS_ROLLUP_FLAG
4363          , fact.PRG_ROLLUP_FLAG PRG_ROLLUP_FLAG
4364          , fact.CURR_RECORD_TYPE_ID CURR_RECORD_TYPE_ID
4365    	 , fact.CURRENCY_CODE CURRENCY_CODE
4366    	 , fact.RBS_ELEMENT_ID RBS_ELEMENT_ID
4367    	 , fact.RBS_VERSION_ID RBS_VERSION_ID
4368    	 , fact.PLAN_VERSION_ID PLAN_VERSION_ID
4369    	 , fact.PLAN_TYPE_ID PLAN_TYPE_ID
4370    	 , SUM(fact.RAW_COST)	 raw_cost
4371    	 , SUM(fact.BRDN_COST) BRDN_COST
4372    	 , SUM(fact.REVENUE) REVENUE
4373    	 , SUM(fact.BILL_RAW_COST) BILL_RAW_COST
4374    	 , SUM(fact.BILL_BRDN_COST) BILL_BRDN_COST
4375    	 , SUM(fact.BILL_LABOR_RAW_COST) BILL_LABOR_RAW_COST
4376    	 , SUM(fact.BILL_LABOR_BRDN_COST) BILL_LABOR_BRDN_COST
4377    	 , SUM(fact.BILL_LABOR_HRS) BILL_LABOR_HRS
4378    	 , SUM(fact.EQUIPMENT_RAW_COST) EQUIPMENT_RAW_COST
4379    	 , SUM(fact.EQUIPMENT_BRDN_COST) EQUIPMENT_BRDN_COST
4380    	 , SUM(fact.CAPITALIZABLE_RAW_COST) CAPITALIZABLE_RAW_COST
4381    	 , SUM(fact.CAPITALIZABLE_BRDN_COST) CAPITALIZABLE_BRDN_COST
4382    	 , SUM(fact.LABOR_RAW_COST) LABOR_RAW_COST
4383    	 , SUM(fact.LABOR_BRDN_COST) LABOR_BRDN_COST
4384    	 , SUM(fact.LABOR_HRS) LABOR_HRS
4385    	 , SUM(fact.LABOR_REVENUE) LABOR_REVENUE
4386    	 , SUM(fact.EQUIPMENT_HOURS) EQUIPMENT_HOURS
4387    	 , SUM(fact.BILLABLE_EQUIPMENT_HOURS) BILLABLE_EQUIPMENT_HOURS
4388    	 , SUM(fact.SUP_INV_COMMITTED_COST) SUP_INV_COMMITTED_COST
4389    	 , SUM(fact.PO_COMMITTED_COST) PO_COMMITTED_COST
4390    	 , SUM(fact.PR_COMMITTED_COST) PR_COMMITTED_COST
4391    	 , SUM(fact.OTH_COMMITTED_COST) OTH_COMMITTED_COST
4392          , SUM(fact.ACT_LABOR_HRS )
4393 	 , SUM(fact.ACT_EQUIP_HRS )
4394 	 , SUM(fact.ACT_LABOR_BRDN_COST )
4395 	 , SUM(fact.ACT_EQUIP_BRDN_COST )
4396 	 , SUM(fact.ACT_BRDN_COST )
4397 	 , SUM(fact.ACT_RAW_COST )
4398 	 , SUM(fact.ACT_REVENUE )
4399          , SUM(fact.ACT_LABOR_RAW_COST)
4400          , SUM(fact.ACT_EQUIP_RAW_COST)
4401 	 , SUM(fact.ETC_LABOR_HRS )
4402 	 , SUM(fact.ETC_EQUIP_HRS )
4403 	 , SUM(fact.ETC_LABOR_BRDN_COST )
4404 	 , SUM(fact.ETC_EQUIP_BRDN_COST )
4405 	 , SUM(fact.ETC_BRDN_COST )
4406          , SUM(fact.ETC_RAW_COST )
4407          , SUM(fact.ETC_LABOR_RAW_COST)
4408          , SUM(fact.ETC_EQUIP_RAW_COST)
4409    	 , SUM(fact.CUSTOM1) CUSTOM1
4410    	 , SUM(fact.CUSTOM2) CUSTOM2
4411    	 , SUM(fact.CUSTOM3) CUSTOM3
4412    	 , SUM(fact.CUSTOM4) CUSTOM4
4413    	 , SUM(fact.CUSTOM5) CUSTOM5
4414    	 , SUM(fact.CUSTOM6) CUSTOM6
4415    	 , SUM(fact.CUSTOM7) CUSTOM7
4416    	 , SUM(fact.CUSTOM8) CUSTOM8
4417    	 , SUM(fact.CUSTOM9) CUSTOM9
4418    	 , SUM(fact.CUSTOM10) CUSTOM10
4419    	 , SUM(fact.CUSTOM11) CUSTOM11
4420    	 , SUM(fact.CUSTOM12) CUSTOM12
4421    	 , SUM(fact.CUSTOM13) CUSTOM13
4422    	 , SUM(fact.CUSTOM14) CUSTOM14
4423    	 , SUM(fact.CUSTOM15) CUSTOM15
4424 	 , fact.TIME_DANGLING_FLAG  TIME_DANGLING_FLAG
4425 	 , fact.RATE_DANGLING_FLAG  RATE_DANGLING_FLAG
4426          , g_default_prg_level prg_level
4427          , fact.PLAN_TYPE_CODE PLAN_TYPE_CODE   /* 4471527 */
4428    FROM    pji_fp_aggr_pjp1 fact
4429    	 , pji_time_ent_period_v  pa_cal
4430          , pji_fm_extr_plnver4  ver
4431    WHERE  fact.CALENDAR_TYPE = 'A'
4432       AND fact.worker_id = g_worker_id
4433       AND ver.worker_id = g_worker_id
4434       AND fact.line_type = 'NTP'
4435       AND fact.start_date IS NOT NULL
4436       AND fact.end_date IS NOT NULL
4437       AND fact.TIME_DANGLING_FLAG  IS NULL
4438       AND fact.RATE_DANGLING_FLAG  IS NULL
4439       AND ( fact.start_date <= pa_cal.end_date AND fact.end_date >= pa_cal.start_date )
4440       AND DECODE(p_prorating_format,'S',
4441              DECODE(SIGN(fact.start_Date-pa_cal.start_date),-1,0,1),
4442              DECODE(SIGN(fact.end_Date - pa_cal.end_date), 1,0,1))=1
4443       AND fact.period_type_id = 2048
4444       AND fact.plan_version_id = ver.plan_version_id
4445       AND fact.plan_type_code = ver.plan_type_code    /* 4471527 */
4446       AND ver.wp_flag = 'N'
4447       AND ver.baselined_flag = 'Y'
4448       AND ver.time_phased_type_code = 'N'
4449 	AND fact.rbs_version_id = NVL(ver.rbs_struct_version_id , -1)
4450       AND ver.plan_version_id > 0
4451    GROUP BY
4452            fact.project_id
4453 	 , fact.PROJECT_ORG_ID
4454 	 , fact.PROJECT_ORGANIZATION_ID
4455    	 , fact.PROJECT_ELEMENT_ID
4456    	 , pa_cal.ent_period_id
4457    	 , fact.PERIOD_TYPE_ID
4458  	 , fact.CALENDAR_TYPE
4459          , fact.RBS_AGGR_LEVEL
4460          , fact.WBS_ROLLUP_FLAG
4461          , fact.PRG_ROLLUP_FLAG
4462          , fact.CURR_RECORD_TYPE_ID
4463    	 , fact.CURRENCY_CODE
4464    	 , fact.RBS_ELEMENT_ID
4465    	 , fact.RBS_VERSION_ID
4466    	 , fact.PLAN_VERSION_ID
4467    	 , fact.PLAN_TYPE_ID
4468 	 , fact.TIME_DANGLING_FLAG
4469 	 , fact.RATE_DANGLING_FLAG
4470               , fact.PLAN_TYPE_CODE ;     /* 4471527 */
4471 
4472 EXCEPTION
4473   WHEN OTHERS THEN
4474     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
4475                              p_procedure_name => 'PRORATE_TO_ENT_N_PJP1_SE');
4476     RAISE;
4477 END;
4478 
4479 
4480 PROCEDURE PRORATE_TO_PAGL_PGE_PJP1_D (p_calendar_type   IN   VARCHAR2 := NULL) IS
4481 BEGIN
4482 
4483   /* Added for bug 13030627 */
4484   if PJI_UTILS.GET_PARAMETER('PJP_SIN_PRG') = 'Y' then
4485 
4486      PJI_PJP_PRG_PERF_ALL.PRORATE_TO_PAGL_PGE_PJP1_D;
4487 
4488   else
4489 
4490     g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
4491 
4492     INSERT INTO pji_fp_aggr_pjp1
4493     (
4494        worker_id
4495      , PROJECT_ID
4496      , PROJECT_ORG_ID
4497      , PROJECT_ORGANIZATION_ID
4498      -- , PARTITION_ID
4499      , PROJECT_ELEMENT_ID
4500      , TIME_ID
4501      , PERIOD_TYPE_ID
4502      , CALENDAR_TYPE
4503      , RBS_AGGR_LEVEL
4504      , WBS_ROLLUP_FLAG
4505      , PRG_ROLLUP_FLAG
4506      , CURR_RECORD_TYPE_ID
4507      , CURRENCY_CODE
4508      , RBS_ELEMENT_ID
4509      , RBS_VERSION_ID
4510      , PLAN_VERSION_ID
4511      , PLAN_TYPE_ID
4512      , RAW_COST
4513      , BRDN_COST
4514      , REVENUE
4515      , BILL_RAW_COST
4516      , BILL_BRDN_COST
4517      , BILL_LABOR_RAW_COST
4518      , BILL_LABOR_BRDN_COST
4519      , BILL_LABOR_HRS
4520      , EQUIPMENT_RAW_COST
4521      , EQUIPMENT_BRDN_COST
4522      , CAPITALIZABLE_RAW_COST
4523      , CAPITALIZABLE_BRDN_COST
4524      , LABOR_RAW_COST
4525      , LABOR_BRDN_COST
4526      , LABOR_HRS
4527      , LABOR_REVENUE
4528      , EQUIPMENT_HOURS
4529      , BILLABLE_EQUIPMENT_HOURS
4530      , SUP_INV_COMMITTED_COST
4531      , PO_COMMITTED_COST
4532      , PR_COMMITTED_COST
4533      , OTH_COMMITTED_COST
4534      , ACT_LABOR_HRS
4535      , ACT_EQUIP_HRS
4536      , ACT_LABOR_BRDN_COST
4537      , ACT_EQUIP_BRDN_COST
4538      , ACT_BRDN_COST
4539      , ACT_RAW_COST
4540      , ACT_REVENUE
4541      , ACT_LABOR_RAW_COST
4542      , ACT_EQUIP_RAW_COST
4543      , ETC_LABOR_HRS
4544      , ETC_EQUIP_HRS
4545      , ETC_LABOR_BRDN_COST
4546      , ETC_EQUIP_BRDN_COST
4547      , ETC_BRDN_COST
4548      , ETC_RAW_COST
4549      , ETC_LABOR_RAW_COST
4550      , ETC_EQUIP_RAW_COST
4551      , CUSTOM1
4552      , CUSTOM2
4553      , CUSTOM3
4554      , CUSTOM4
4555      , CUSTOM5
4556      , CUSTOM6
4557      , CUSTOM7
4558      , CUSTOM8
4559      , CUSTOM9
4560      , CUSTOM10
4561      , CUSTOM11
4562      , CUSTOM12
4563      , CUSTOM13
4564      , CUSTOM14
4565      , CUSTOM15
4566      , TIME_DANGLING_FLAG
4567      , RATE_DANGLING_FLAG
4568      , PRG_LEVEL
4569      , PLAN_TYPE_CODE      /* 4471527 */
4570 	)
4571    SELECT
4572        g_worker_id worker_id
4573      , a.PROJECT_ID
4574      , a.PROJECT_ORG_ID
4575      , a.PROJECT_ORGANIZATION_ID
4576      , a.PROJECT_ELEMENT_ID
4577      , a.TIME_ID
4578      , a.PERIOD_TYPE_ID
4579      , a.CALENDAR_TYPE
4580      , a.RBS_AGGR_LEVEL
4581      , a.WBS_ROLLUP_FLAG
4582      , a.PRG_ROLLUP_FLAG
4583      , a.CURR_RECORD_TYPE_ID
4584      , a.CURRENCY_CODE
4585      , a.RBS_ELEMENT_ID
4586      , a.RBS_VERSION_ID
4587      , a.PLAN_VERSION_ID
4588      , a.PLAN_TYPE_ID
4589      , SUM(a.RAW_COST       )
4590      , SUM(a.BRDN_COST 	)
4591      , SUM(a.REVENUE	)
4592      , SUM(a.BILL_RAW_COST )
4593      , SUM(a.BILL_BRDN_COST )
4594      , SUM(a.BILL_LABOR_RAW_COST )
4595      , SUM(a.BILL_LABOR_BRDN_COST )
4596      , SUM(a.BILL_LABOR_HRS )
4597      , SUM(a.EQUIPMENT_RAW_COST )
4598      , SUM(a.EQUIPMENT_BRDN_COST )
4599      , SUM(a.CAPITALIZABLE_RAW_COST )
4600      , SUM(a.CAPITALIZABLE_BRDN_COST )
4601      , SUM(a.LABOR_RAW_COST )
4602      , SUM(a.LABOR_BRDN_COST)
4603      , SUM(a.LABOR_HRS )
4604      , SUM(a.LABOR_REVENUE )
4605      , SUM(a.EQUIPMENT_HOURS )
4606      , SUM(a.BILLABLE_EQUIPMENT_HOURS)
4607      , SUM(a.SUP_INV_COMMITTED_COST)
4608      , SUM(a.PO_COMMITTED_COST )
4609      , SUM(a.PR_COMMITTED_COST )
4610      , SUM(a.OTH_COMMITTED_COST)
4611      , SUM(a.ACT_LABOR_HRS)
4612      , SUM(a.ACT_EQUIP_HRS)
4613      , SUM(a.ACT_LABOR_BRDN_COST)
4614      , SUM(a.ACT_EQUIP_BRDN_COST)
4615      , SUM(a.ACT_BRDN_COST    )
4616      , SUM(a.ACT_RAW_COST    )
4617      , SUM(a.ACT_REVENUE    )
4618      , SUM(a.ACT_LABOR_RAW_COST)
4619      , SUM(a.ACT_EQUIP_RAW_COST)
4620      , SUM(a.ETC_LABOR_HRS         )
4621      , SUM(a.ETC_EQUIP_HRS        )
4622      , SUM(a.ETC_LABOR_BRDN_COST )
4623      , SUM(a.ETC_EQUIP_BRDN_COST)
4624      , SUM(a.ETC_BRDN_COST )
4625      , SUM(a.ETC_RAW_COST)
4626      , SUM(a.ETC_LABOR_RAW_COST)
4627      , SUM(a.ETC_EQUIP_RAW_COST)
4628      , SUM(a.CUSTOM1	)
4629      , SUM(a.CUSTOM2	)
4630      , SUM(a.CUSTOM3	)
4631      , SUM(a.CUSTOM4	)
4632      , SUM(a.CUSTOM5	)
4633      , SUM(a.CUSTOM6	)
4634      , SUM(a.CUSTOM7	)
4635      , SUM(a.CUSTOM8	)
4636      , SUM(a.CUSTOM9	)
4637      , SUM(a.CUSTOM10	)
4638      , SUM(a.CUSTOM11	)
4639      , SUM(a.CUSTOM12	)
4640      , SUM(a.CUSTOM13	)
4641      , SUM(a.CUSTOM14	)
4642      , SUM(a.CUSTOM15	)
4643      , a.TIME_DANGLING_FLAG
4644      , a.RATE_DANGLING_FLAG
4645      , g_default_prg_level prg_level
4646      , a.plan_type_code plan_type_code    /* 4471527 */
4647    FROM (
4648    SELECT
4649            fact.project_id  project_id
4650    	 , fact.project_ORG_ID project_ORG_ID
4651    	 , fact.project_ORGANIZATION_ID project_ORGANIZATION_ID
4652       -- , fact.PARTITION_ID PARTITION_ID
4653    	 , fact.PROJECT_ELEMENT_ID PROJECT_ELEMENT_ID
4654    	 , calDet.sec_cal_period_id TIME_ID
4655    	 , fact.PERIOD_TYPE_ID PERIOD_TYPE_ID
4656    	 , DECODE(fact.CALENDAR_TYPE, 'P', 'G', 'G', 'P') CALENDAR_TYPE
4657          , fact.RBS_AGGR_LEVEL
4658          , fact.WBS_ROLLUP_FLAG
4659          , fact.PRG_ROLLUP_FLAG
4660    	 , fact.CURR_RECORD_TYPE_ID CURR_RECORD_TYPE_ID
4661    	 , fact.CURRENCY_CODE CURRENCY_CODE
4662    	 , fact.RBS_ELEMENT_ID RBS_ELEMENT_ID
4663    	 , fact.RBS_VERSION_ID RBS_VERSION_ID
4664    	 , fact.PLAN_VERSION_ID PLAN_VERSION_ID
4665 	 , fact.PLAN_TYPE_ID  PLAN_TYPE_ID
4666 	 , ROUND (nvl(fact.raw_cost,0)*calDet.factor/cur.mau)*cur.mau raw_cost
4667 	 , ROUND (nvl(fact.brdn_cost,0)*calDet.factor/cur.mau)*cur.mau brdn_cost
4668 	 , ROUND (nvl(fact.revenue,0)*calDet.factor/cur.mau)*cur.mau revenue
4669 	 , ROUND (nvl(fact.bill_raw_cost,0)*calDet.factor/cur.mau)*cur.mau bill_raw_cost
4670 	 , ROUND (nvl(fact.bill_brdn_cost,0)*calDet.factor/cur.mau)*cur.mau bill_brdn_cost
4671 	 , ROUND (nvl(fact.bill_labor_raw_cost,0)*calDet.factor/cur.mau)*cur.mau bill_labor_raw_cost
4672 	 , ROUND (nvl(fact.bill_labor_brdn_cost,0)*calDet.factor/cur.mau)*cur.mau bill_labor_brdn_cost
4673 	 , ROUND (nvl(fact.bill_labor_hrs,0)*calDet.factor/cur.mau)*cur.mau bill_labor_hrs
4674 	 , ROUND (nvl(fact.equipment_raw_cost,0)*calDet.factor/cur.mau)*cur.mau equipment_raw_cost
4675 	 , ROUND (nvl(fact.equipment_brdn_cost,0)*calDet.factor/cur.mau)*cur.mau equipment_brdn_cost
4676 	 , ROUND (nvl(fact.capitalizable_raw_cost,0)*calDet.factor/cur.mau)*cur.mau capitalizable_raw_cost
4677 	 , ROUND (nvl(fact.capitalizable_brdn_cost,0)*calDet.factor/cur.mau)*cur.mau capitalizable_brdn_cost
4678 	 , ROUND (nvl(fact.labor_raw_cost,0)*calDet.factor/cur.mau)*cur.mau labor_raw_cost
4679 	 , ROUND (nvl(fact.labor_brdn_cost,0)*calDet.factor/cur.mau)*cur.mau labor_brdn_cost
4680 	 , ROUND (nvl(fact.labor_hrs,0)*calDet.factor/cur.mau)*cur.mau labor_hrs
4681 	 , ROUND (nvl(fact.labor_revenue,0)*calDet.factor/cur.mau)*cur.mau labor_revenue
4682 	 , ROUND (nvl(fact.equipment_hours,0)*calDet.factor/cur.mau)*cur.mau equipment_hours
4683 	 , ROUND (nvl(fact.billable_equipment_hours,0)*calDet.factor/cur.mau)*cur.mau billable_equipment_hours
4684 	 , ROUND (nvl(fact.sup_inv_committed_cost,0)*calDet.factor/cur.mau)*cur.mau sup_inv_committed_cost
4685 	 , ROUND (nvl(fact.po_committed_cost,0)*calDet.factor/cur.mau)*cur.mau po_committed_cost
4686 	 , ROUND (nvl(fact.pr_committed_cost,0)*calDet.factor/cur.mau)*cur.mau pr_committed_cost
4687 	 , ROUND (nvl(fact.oth_committed_cost,0)*calDet.factor/cur.mau)*cur.mau oth_committed_cost
4688 	 , ROUND (nvl(fact.ACT_LABOR_HRS,0)*calDet.factor/cur.mau)*cur.mau ACT_LABOR_HRS
4689 	 , ROUND (nvl(fact.ACT_EQUIP_HRS,0)*calDet.factor/cur.mau)*cur.mau ACT_EQUIP_HRS
4690 	 , ROUND (nvl(fact.ACT_LABOR_BRDN_COST,0)*calDet.factor/cur.mau)*cur.mau ACT_LABOR_BRDN_COST
4691 	 , ROUND (nvl(fact.ACT_EQUIP_BRDN_COST,0)*calDet.factor/cur.mau)*cur.mau ACT_EQUIP_BRDN_COST
4692 	 , ROUND (nvl(fact.ACT_BRDN_COST,0)*calDet.factor/cur.mau)*cur.mau ACT_BRDN_COST
4693 	 , ROUND (nvl(fact.ACT_RAW_COST,0)*calDet.factor/cur.mau)*cur.mau ACT_RAW_COST
4694 	 , ROUND (nvl(fact.ACT_REVENUE,0)*calDet.factor/cur.mau)*cur.mau ACT_REVENUE
4695 	 , ROUND (nvl(fact.ACT_LABOR_RAW_COST,0)*calDet.factor/cur.mau)*cur.mau ACT_LABOR_RAW_COST
4696 	 , ROUND (nvl(fact.ACT_EQUIP_RAW_COST,0)*calDet.factor/cur.mau)*cur.mau ACT_EQUIP_RAW_COST
4697 	 , ROUND (nvl(fact.ETC_LABOR_HRS,0)*calDet.factor/cur.mau)*cur.mau ETC_LABOR_HRS
4698 	 , ROUND (nvl(fact.ETC_EQUIP_HRS,0)*calDet.factor/cur.mau)*cur.mau ETC_EQUIP_HRS
4699 	 , ROUND (nvl(fact.ETC_LABOR_BRDN_COST,0)*calDet.factor/cur.mau)*cur.mau ETC_LABOR_BRDN_COST
4700 	 , ROUND (nvl(fact.ETC_EQUIP_BRDN_COST,0)*calDet.factor/cur.mau)*cur.mau ETC_EQUIP_BRDN_COST
4701 	 , ROUND (nvl(fact.ETC_BRDN_COST,0)*calDet.factor/cur.mau)*cur.mau ETC_BRDN_COST
4702 	 , ROUND (nvl(fact.ETC_RAW_COST,0)*calDet.factor/cur.mau)*cur.mau ETC_RAW_COST
4703 	 , ROUND (nvl(fact.ETC_LABOR_RAW_COST,0)*calDet.factor/cur.mau)*cur.mau ETC_LABOR_RAW_COST
4704 	 , ROUND (nvl(fact.ETC_EQUIP_RAW_COST,0)*calDet.factor/cur.mau)*cur.mau ETC_EQUIP_RAW_COST
4705 	 , ROUND (nvl(fact.custom1,0)*calDet.factor/cur.mau)*cur.mau custom1
4706 	 , ROUND (nvl(fact.custom2,0)*calDet.factor/cur.mau)*cur.mau custom2
4707 	 , ROUND (nvl(fact.custom3,0)*calDet.factor/cur.mau)*cur.mau custom3
4708 	 , ROUND (nvl(fact.custom4,0)*calDet.factor/cur.mau)*cur.mau custom4
4709 	 , ROUND (nvl(fact.custom5,0)*calDet.factor/cur.mau)*cur.mau custom5
4710 	 , ROUND (nvl(fact.custom6,0)*calDet.factor/cur.mau)*cur.mau custom6
4711 	 , ROUND (nvl(fact.custom7,0)*calDet.factor/cur.mau)*cur.mau custom7
4712 	 , ROUND (nvl(fact.custom8,0)*calDet.factor/cur.mau)*cur.mau custom8
4713 	 , ROUND (nvl(fact.custom9,0)*calDet.factor/cur.mau)*cur.mau custom9
4714 	 , ROUND (nvl(fact.custom10,0)*calDet.factor/cur.mau)*cur.mau custom10
4715 	 , ROUND (nvl(fact.custom11,0)*calDet.factor/cur.mau)*cur.mau custom11
4716 	 , ROUND (nvl(fact.custom12,0)*calDet.factor/cur.mau)*cur.mau custom12
4717 	 , ROUND (nvl(fact.custom13,0)*calDet.factor/cur.mau)*cur.mau custom13
4718 	 , ROUND (nvl(fact.custom14,0)*calDet.factor/cur.mau)*cur.mau custom14
4719 	 , ROUND (nvl(fact.custom15,0)*calDet.factor/cur.mau)*cur.mau custom15
4720 	 , fact.time_dangling_flag time_dangling_flag
4721 	 , fact.rate_dangling_flag rate_dangling_flag
4722               , fact.plan_type_code plan_type_code    /* 4471527 */
4723    FROM   pji_fp_aggr_pjp1 fact,
4724          (SELECT  /*+ NO_MERGE */ (LEAST(pri.end_date,sec.end_date) - Greatest(pri.start_date,sec.start_date)+1)
4725 	                      / (pri.end_date - pri.start_date+1) factor,
4726 	         ppa.project_id,
4727 	         ver.rbs_struct_Version_id rbs_struct_version_id,
4728 		 ver.plan_version_id plan_Version_id,
4729                           ver.plan_type_code plan_type_code ,    /* 4471527 */
4730 		 pri.cal_period_id pri_cal_period_id,
4731 		 sec.cal_period_id sec_cal_period_id,
4732 		 orginfo.org_id
4733 	    FROM
4734                  pji_time_cal_period_v  pri
4735                , pji_org_extr_info  orginfo
4736                , pji_time_cal_period_v  sec
4737                , pji_fm_extr_plnver4  ver
4738 	       , pa_projects_all ppa
4739            WHERE  1=1
4740              AND ppa.org_id=orginfo.org_id
4741              AND ver.worker_id = g_worker_id
4742              AND pri.calendar_id in (orginfo.gl_calendar_id,orginfo.pa_calendar_id)
4743              AND sec.calendar_id in (orginfo.gl_calendar_id,orginfo.pa_calendar_id)
4744              AND ppa.project_id=ver.project_id
4745              AND decode(ver.time_phased_type_code,
4746                        'P',orginfo.pa_calendar_id,'G',orginfo.gl_calendar_id)=pri.calendar_id
4747              AND decode(ver.time_phased_type_code,
4748                        'G',orginfo.pa_calendar_id,'P',orginfo.gl_calendar_id)=sec.calendar_id
4749              AND ver.wp_flag = 'N'
4750              AND ( sec.start_date <= pri.end_date AND sec.end_date >= pri.start_date )
4751              AND ver.baselined_flag = 'Y'
4752              AND ver.plan_version_id > 0 ) calDet,
4753 	   (SELECT currency_code,
4754 	           decode(nvl(MINIMUM_ACCOUNTABLE_UNIT, power(10, (-1 * PRECISION))),
4755 		      null, 0.01,
4756 		         0, 1,
4757 			 nvl(MINIMUM_ACCOUNTABLE_UNIT, power(10, (-1 * PRECISION)))) mau
4758 	      FROM FND_CURRENCIES) cur
4759     WHERE 1=1
4760       AND calDet.factor > 0
4761 	AND fact.rbs_version_id = NVL(calDet.rbs_struct_version_id , -1)
4762       AND fact.CALENDAR_TYPE <> p_calendar_type
4763       AND fact.worker_id = g_worker_id
4764       AND fact.CALENDAR_TYPE IN ('P', 'G')
4765       AND CalDet.pri_cal_period_id = fact.time_id
4766       AND calDet.org_id = fact.PROJECT_ORG_ID
4767       AND fact.time_dangling_flag IS NULL
4768       AND fact.rate_dangling_flag IS NULL
4769       AND fact.period_type_id = 32
4770       AND fact.line_type like 'OF%' -- 4518721
4771       AND fact.plan_version_id = calDet.plan_version_id
4772       AND fact.plan_type_code = calDet.plan_type_code      /* 4471527 */
4773       AND cur.currency_code = fact.currency_code
4774 	  ) a
4775 	  GROUP BY
4776 	   a.PROJECT_ID
4777      , a.PROJECT_ORG_ID
4778      , a.PROJECT_ORGANIZATION_ID
4779      , a.PROJECT_ELEMENT_ID
4780      , a.TIME_ID
4781      , a.PERIOD_TYPE_ID
4782      , a.CALENDAR_TYPE
4783      , a.RBS_AGGR_LEVEL
4784      , a.WBS_ROLLUP_FLAG
4785      , a.PRG_ROLLUP_FLAG
4786      , a.CURR_RECORD_TYPE_ID
4787      , a.CURRENCY_CODE
4788      , a.RBS_ELEMENT_ID
4789      , a.RBS_VERSION_ID
4790      , a.PLAN_VERSION_ID
4791      , a.PLAN_TYPE_ID
4792      , a.TIME_DANGLING_FLAG
4793      , a.RATE_DANGLING_FLAG
4794      , a.plan_type_code ;     /*   4471527 */
4795 
4796 	 end if;
4797 
4798 EXCEPTION
4799   WHEN OTHERS THEN
4800     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
4801                              p_procedure_name => ' PRORATE_TO_PAGL_PGE_PJP1_D ');
4802     RAISE;
4803 END;
4804 
4805 
4806 PROCEDURE PRORATE_TO_PAGL_PGE_FPRL_D (p_calendar_type   IN   VARCHAR2 := NULL) IS
4807 BEGIN
4808 
4809     g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
4810 
4811 EXCEPTION
4812   WHEN OTHERS THEN
4813     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
4814                              p_procedure_name => 'PRORATE_TO_PAGL_PGE_FPRL_D ');
4815     RAISE;
4816 END;
4817 
4818 
4819 PROCEDURE PRORATE_TO_PAGL_N_PJP1_D (p_calendar_type   IN   VARCHAR2 := NULL) IS
4820 BEGIN
4821 
4822   /* Added for bug 13030627 */
4823   if PJI_UTILS.GET_PARAMETER('PJP_SIN_PRG') = 'Y' then
4824 
4825      PJI_PJP_PRG_PERF_ALL.PRORATE_TO_PAGL_N_PJP1_D;
4826 
4827   else
4828 
4829     IF (p_calendar_type NOT IN ('P', 'G')) THEN
4830       RETURN;
4831     END IF;
4832 
4833     g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
4834 
4835     INSERT INTO pji_fp_aggr_pjp1  -- Non time phased entries..
4836     (
4837        worker_id
4838      , PROJECT_ID
4839      , PROJECT_ORG_ID
4840      , PROJECT_ORGANIZATION_ID
4841      -- , PARTITION_ID
4842      , PROJECT_ELEMENT_ID
4843      , TIME_ID
4844      , PERIOD_TYPE_ID
4845      , CALENDAR_TYPE
4846      , RBS_AGGR_LEVEL
4847      , WBS_ROLLUP_FLAG
4848      , PRG_ROLLUP_FLAG
4849      , CURR_RECORD_TYPE_ID
4850      , CURRENCY_CODE
4851      , RBS_ELEMENT_ID
4852      , RBS_VERSION_ID
4853      , PLAN_VERSION_ID
4854      , PLAN_TYPE_ID
4855      , RAW_COST
4856      , BRDN_COST
4857      , REVENUE
4858      , BILL_RAW_COST
4859      , BILL_BRDN_COST
4860      , BILL_LABOR_RAW_COST
4861      , BILL_LABOR_BRDN_COST
4862      , BILL_LABOR_HRS
4863      , EQUIPMENT_RAW_COST
4864      , EQUIPMENT_BRDN_COST
4865      , CAPITALIZABLE_RAW_COST
4866      , CAPITALIZABLE_BRDN_COST
4867      , LABOR_RAW_COST
4868      , LABOR_BRDN_COST
4869      , LABOR_HRS
4870      , LABOR_REVENUE
4871      , EQUIPMENT_HOURS
4872      , BILLABLE_EQUIPMENT_HOURS
4873      , SUP_INV_COMMITTED_COST
4874      , PO_COMMITTED_COST
4875      , PR_COMMITTED_COST
4876      , OTH_COMMITTED_COST
4877      , ACT_LABOR_HRS
4878      , ACT_EQUIP_HRS
4879      , ACT_LABOR_BRDN_COST
4880      , ACT_EQUIP_BRDN_COST
4881      , ACT_BRDN_COST
4882      , ACT_RAW_COST
4883      , ACT_REVENUE
4884      , ACT_LABOR_RAW_COST
4885      , ACT_EQUIP_RAW_COST
4886      , ETC_LABOR_HRS
4887      , ETC_EQUIP_HRS
4888      , ETC_LABOR_BRDN_COST
4889      , ETC_EQUIP_BRDN_COST
4890      , ETC_BRDN_COST
4891      , ETC_RAW_COST
4892      , ETC_LABOR_RAW_COST
4893      , ETC_EQUIP_RAW_COST
4894      , CUSTOM1
4895      , CUSTOM2
4896      , CUSTOM3
4897      , CUSTOM4
4898      , CUSTOM5
4899      , CUSTOM6
4900      , CUSTOM7
4901      , CUSTOM8
4902      , CUSTOM9
4903      , CUSTOM10
4904      , CUSTOM11
4905      , CUSTOM12
4906      , CUSTOM13
4907      , CUSTOM14
4908      , CUSTOM15
4909      , TIME_DANGLING_FLAG
4910      , RATE_DANGLING_FLAG
4911      , PRG_LEVEL
4912      , PLAN_TYPE_CODE     /* 4471527 */
4913 	)
4914    SELECT
4915        g_worker_id  worker_id
4916      , a.PROJECT_ID
4917      , a.PROJECT_ORG_ID
4918      , a.PROJECT_ORGANIZATION_ID
4919      , a.PROJECT_ELEMENT_ID
4920      , a.TIME_ID
4921      , 32 -- a.PERIOD_TYPE_ID
4922      , a.CALENDAR_TYPE
4923      , a.RBS_AGGR_LEVEL
4924      , a.WBS_ROLLUP_FLAG
4925      , a.PRG_ROLLUP_FLAG
4926      , a.CURR_RECORD_TYPE_ID
4927      , a.CURRENCY_CODE
4928      , a.RBS_ELEMENT_ID
4929      , a.RBS_VERSION_ID
4930      , a.PLAN_VERSION_ID
4931      , a.PLAN_TYPE_ID
4932      , SUM(ROUND (nvl(a.raw_cost,0)*a.factor/a.mau)*a.mau) raw_cost
4933      , SUM(ROUND (nvl(a.brdn_cost,0)*a.factor/a.mau)*a.mau) brdn_cost
4934      , SUM(ROUND (nvl(a.revenue,0)*a.factor/a.mau)*a.mau) revenue
4935      , SUM(ROUND (nvl(a.bill_raw_cost,0)*a.factor/a.mau)*a.mau) bill_raw_cost
4936      , SUM(ROUND (nvl(a.bill_brdn_cost,0)*a.factor/a.mau)*a.mau) bill_brdn_cost
4937      , SUM(ROUND (nvl(a.bill_labor_raw_cost,0)*a.factor/a.mau)*a.mau) bill_labor_raw_cost
4938      , SUM(ROUND (nvl(a.bill_labor_brdn_cost,0)*a.factor/a.mau)*a.mau) bill_labor_brdn_cost
4939      , SUM(ROUND (nvl(a.bill_labor_hrs,0)*a.factor/a.mau)*a.mau) bill_labor_hrs
4940      , SUM(ROUND (nvl(a.equipment_raw_cost,0)*a.factor/a.mau)*a.mau) equipment_raw_cost
4941      , SUM(ROUND (nvl(a.equipment_brdn_cost,0)*a.factor/a.mau)*a.mau) equipment_brdn_cost
4942      , SUM(ROUND (nvl(a.capitalizable_raw_cost,0)*a.factor/a.mau)*a.mau) capitalizable_raw_cost
4943      , SUM(ROUND (nvl(a.capitalizable_brdn_cost,0)*a.factor/a.mau)*a.mau) capitalizable_brdn_cost
4944      , SUM(ROUND (nvl(a.labor_raw_cost,0)*a.factor/a.mau)*a.mau) labor_raw_cost
4945      , SUM(ROUND (nvl(a.labor_brdn_cost,0)*a.factor/a.mau)*a.mau) labor_brdn_cost
4946      , SUM(ROUND (nvl(a.labor_hrs,0)*a.factor/a.mau)*a.mau) labor_hrs
4947      , SUM(ROUND (nvl(a.labor_revenue,0)*a.factor/a.mau)*a.mau) labor_revenue
4948      , SUM(ROUND (nvl(a.equipment_hours,0)*a.factor/a.mau)*a.mau) equipment_hours
4949      , SUM(ROUND (nvl(a.billable_equipment_hours,0)*a.factor/a.mau)*a.mau) billable_equipment_hours
4950      , SUM(ROUND (nvl(a.sup_inv_committed_cost,0)*a.factor/a.mau)*a.mau) sup_inv_committed_cost
4951      , SUM(ROUND (nvl(a.po_committed_cost,0)*a.factor/a.mau)*a.mau) po_committed_cost
4952      , SUM(ROUND (nvl(a.pr_committed_cost,0)*a.factor/a.mau)*a.mau) pr_committed_cost
4953      , SUM(ROUND (nvl(a.oth_committed_cost,0)*a.factor/a.mau)*a.mau) oth_committed_cost
4954      , SUM(ROUND (nvl(a.ACT_LABOR_HRS,0)*a.factor/a.mau)*a.mau) ACT_LABOR_HRS
4955      , SUM(ROUND (nvl(a.ACT_EQUIP_HRS,0)*a.factor/a.mau)*a.mau) ACT_EQUIP_HRS
4956      , SUM(ROUND (nvl(a.ACT_LABOR_BRDN_COST,0)*a.factor/a.mau)*a.mau) ACT_LABOR_BRDN_COST
4957      , SUM(ROUND (nvl(a.ACT_EQUIP_BRDN_COST,0)*a.factor/a.mau)*a.mau) ACT_EQUIP_BRDN_COST
4958      , SUM(ROUND (nvl(a.ACT_BRDN_COST,0)*a.factor/a.mau)*a.mau) ACT_BRDN_COST
4959      , SUM(ROUND (nvl(a.ACT_RAW_COST,0)*a.factor/a.mau)*a.mau) ACT_RAW_COST
4960      , SUM(ROUND (nvl(a.ACT_REVENUE,0)*a.factor/a.mau)*a.mau) ACT_REVENUE
4961      , SUM(ROUND (nvl(a.ACT_LABOR_RAW_COST,0)*a.factor/a.mau)*a.mau) ACT_LABOR_RAW_COST
4962      , SUM(ROUND (nvl(a.ACT_EQUIP_RAW_COST,0)*a.factor/a.mau)*a.mau) ACT_EQUIP_RAW_COST
4963      , SUM(ROUND (nvl(a.ETC_LABOR_HRS,0)*a.factor/a.mau)*a.mau) ETC_LABOR_HRS
4964      , SUM(ROUND (nvl(a.ETC_EQUIP_HRS,0)*a.factor/a.mau)*a.mau) ETC_EQUIP_HRS
4965      , SUM(ROUND (nvl(a.ETC_LABOR_BRDN_COST,0)*a.factor/a.mau)*a.mau) ETC_LABOR_BRDN_COST
4966      , SUM(ROUND (nvl(a.ETC_EQUIP_BRDN_COST,0)*a.factor/a.mau)*a.mau) ETC_EQUIP_BRDN_COST
4967      , SUM(ROUND (nvl(a.ETC_BRDN_COST,0)*a.factor/a.mau)*a.mau) ETC_BRDN_COST
4968      , SUM(ROUND (nvl(a.ETC_RAW_COST,0)*a.factor/a.mau)*a.mau) ETC_RAW_COST
4969      , SUM(ROUND (nvl(a.ETC_LABOR_RAW_COST,0)*a.factor/a.mau)*a.mau) ETC_LABOR_RAW_COST
4970      , SUM(ROUND (nvl(a.ETC_EQUIP_RAW_COST,0)*a.factor/a.mau)*a.mau) ETC_EQUIP_RAW_COST
4971      , SUM(ROUND (nvl(a.custom1,0)*a.factor/a.mau)*a.mau) custom1
4972      , SUM(ROUND (nvl(a.custom2,0)*a.factor/a.mau)*a.mau) custom2
4973      , SUM(ROUND (nvl(a.custom3,0)*a.factor/a.mau)*a.mau) custom3
4974      , SUM(ROUND (nvl(a.custom4,0)*a.factor/a.mau)*a.mau) custom4
4975      , SUM(ROUND (nvl(a.custom5,0)*a.factor/a.mau)*a.mau) custom5
4976      , SUM(ROUND (nvl(a.custom6,0)*a.factor/a.mau)*a.mau) custom6
4977      , SUM(ROUND (nvl(a.custom7,0)*a.factor/a.mau)*a.mau) custom7
4978      , SUM(ROUND (nvl(a.custom8,0)*a.factor/a.mau)*a.mau) custom8
4979      , SUM(ROUND (nvl(a.custom9,0)*a.factor/a.mau)*a.mau) custom9
4980      , SUM(ROUND (nvl(a.custom10,0)*a.factor/a.mau)*a.mau) custom10
4981      , SUM(ROUND (nvl(a.custom11,0)*a.factor/a.mau)*a.mau) custom11
4982      , SUM(ROUND (nvl(a.custom12,0)*a.factor/a.mau)*a.mau) custom12
4983      , SUM(ROUND (nvl(a.custom13,0)*a.factor/a.mau)*a.mau) custom13
4984      , SUM(ROUND (nvl(a.custom14,0)*a.factor/a.mau)*a.mau) custom14
4985      , SUM(ROUND (nvl(a.custom15,0)*a.factor/a.mau)*a.mau) custom15
4986      , a.TIME_DANGLING_FLAG
4987      , a.RATE_DANGLING_FLAG
4988      , g_default_prg_level prg_level
4989      , a.PLAN_TYPE_CODE  PLAN_TYPE_CODE    /* 4471527 */
4990   FROM (
4991    SELECT /*+ NO_MERGE */
4992            fact.project_id  project_id
4993    	 , fact.project_ORG_ID project_ORG_ID
4994    	 , fact.project_ORGANIZATION_ID project_ORGANIZATION_ID
4995    	 , fact.PROJECT_ELEMENT_ID PROJECT_ELEMENT_ID
4996    	 , pa_cal.cal_period_id TIME_ID
4997    	 , fact.PERIOD_TYPE_ID PERIOD_TYPE_ID
4998          , p_calendar_type  CALENDAR_TYPE
4999          , fact.RBS_AGGR_LEVEL
5000          , fact.WBS_ROLLUP_FLAG
5001          , fact.PRG_ROLLUP_FLAG
5002    	 , fact.CURR_RECORD_TYPE_ID CURR_RECORD_TYPE_ID
5003    	 , fact.CURRENCY_CODE CURRENCY_CODE
5004    	 , fact.RBS_ELEMENT_ID RBS_ELEMENT_ID
5005    	 , fact.RBS_VERSION_ID RBS_VERSION_ID
5006    	 , fact.PLAN_VERSION_ID PLAN_VERSION_ID
5007 	 , fact.PLAN_TYPE_ID  PLAN_TYPE_ID
5008          , fact.raw_cost
5009          , fact.brdn_cost
5010          , fact.revenue
5011          , fact.bill_raw_cost
5012          , fact.bill_brdn_cost
5013          , fact.bill_labor_raw_cost
5014          , fact.bill_labor_brdn_cost
5015          , fact.bill_labor_hrs
5016          , fact.equipment_raw_cost
5017          , fact.equipment_brdn_cost
5018          , fact.capitalizable_raw_cost
5019          , fact.capitalizable_brdn_cost
5020          , fact.labor_raw_cost
5021          , fact.labor_brdn_cost
5022          , fact.labor_hrs
5023          , fact.labor_revenue
5024          , fact.equipment_hours
5025          , fact.billable_equipment_hours
5026          , fact.sup_inv_committed_cost
5027          , fact.po_committed_cost
5028          , fact.pr_committed_cost
5029          , fact.oth_committed_cost
5030          , fact.ACT_LABOR_HRS
5031          , fact.ACT_EQUIP_HRS
5032          , fact.ACT_LABOR_BRDN_COST
5033          , fact.ACT_EQUIP_BRDN_COST
5034          , fact.ACT_BRDN_COST
5035          , fact.ACT_RAW_COST
5036          , fact.ACT_REVENUE
5037          , fact.ACT_LABOR_RAW_COST
5038          , fact.ACT_EQUIP_RAW_COST
5039          , fact.ETC_LABOR_HRS
5040          , fact.ETC_EQUIP_HRS
5041          , fact.ETC_LABOR_BRDN_COST
5042          , fact.ETC_EQUIP_BRDN_COST
5043          , fact.ETC_BRDN_COST
5044          , fact.ETC_RAW_COST
5045          , fact.ETC_LABOR_RAW_COST
5046          , fact.ETC_EQUIP_RAW_COST
5047          , fact.custom1
5048          , fact.custom2
5049          , fact.custom3
5050          , fact.custom4
5051          , fact.custom5
5052          , fact.custom6
5053          , fact.custom7
5054          , fact.custom8
5055          , fact.custom9
5056          , fact.custom10
5057          , fact.custom11
5058          , fact.custom12
5059          , fact.custom13
5060          , fact.custom14
5061          , fact.custom15
5062 	 , NULL time_dangling_flag
5063 	 , NULL rate_dangling_flag
5064          , cur.mau mau
5065          , (LEAST(fact.end_date,pa_cal.end_date) - Greatest(fact.start_date,pa_cal.start_date)+1)
5066                               / (fact.end_date - fact.start_date+1) factor
5067         , fact.plan_type_code  plan_type_code  /* 4471527 */
5068    FROM    pji_fp_aggr_pjp1 fact
5069    	 , pji_org_extr_info  orginfo
5070    	 , pji_time_cal_period_v  pa_cal
5071          , pji_fm_extr_plnver4  ver
5072          ,(SELECT currency_code,
5073                    decode(nvl(MINIMUM_ACCOUNTABLE_UNIT, power(10, (-1 * PRECISION))),
5074                       null, 0.01,
5075                          0, 1,
5076                          nvl(MINIMUM_ACCOUNTABLE_UNIT, power(10, (-1 * PRECISION)))) mau
5077               FROM FND_CURRENCIES) cur
5078    WHERE  1=1
5079       AND fact.CALENDAR_TYPE = 'A'
5080       AND fact.worker_id = g_worker_id
5081       AND ver.worker_id = g_worker_id
5082       AND fact.start_date IS NOT NULL
5083       AND fact.end_date IS NOT NULL
5084       AND fact.time_dangling_flag IS NULL
5085       AND fact.rate_dangling_flag IS NULL
5086       AND orginfo.org_id = fact.PROJECT_ORG_ID
5087       AND DECODE(p_calendar_type
5088                , 'P', orginfo.pa_calendar_id
5089                , 'G', orginfo.gl_calendar_id) = pa_cal.calendar_id
5090       AND fact.line_type = 'NTP'
5091       AND fact.period_type_id = 2048
5092       AND fact.plan_version_id = ver.plan_version_id
5093       AND fact.plan_type_code = ver.plan_type_code   /* 4471527 */
5094       AND ver.wp_flag = 'N'
5095       AND ver.baselined_flag = 'Y'
5096       AND ver.time_phased_type_code = 'N'
5097       AND ( fact.start_date <= pa_cal.end_date AND fact.end_date >= pa_cal.start_date )
5098 	AND fact.rbs_version_id = NVL(ver.rbs_struct_version_id , -1)
5099       AND cur.currency_code = fact.currency_code
5100       AND ver.plan_version_id > 0
5101 	  ) a
5102       WHERE a.factor >0
5103    GROUP BY
5104        a.PROJECT_ID
5105      , a.PROJECT_ORG_ID
5106      , a.PROJECT_ORGANIZATION_ID
5107      , a.PROJECT_ELEMENT_ID
5108      , a.TIME_ID
5109      , a.PERIOD_TYPE_ID
5110      , a.CALENDAR_TYPE
5111      , a.RBS_AGGR_LEVEL
5112      , a.WBS_ROLLUP_FLAG
5113      , a.PRG_ROLLUP_FLAG
5114      , a.CURR_RECORD_TYPE_ID
5115      , a.CURRENCY_CODE
5116      , a.RBS_ELEMENT_ID
5117      , a.RBS_VERSION_ID
5118      , a.PLAN_VERSION_ID
5119      , a.PLAN_TYPE_ID
5120 	 , a.TIME_DANGLING_FLAG
5121 	 , a.RATE_DANGLING_FLAG
5122               , a.PLAN_TYPE_CODE ;    /* 4471527 */
5123 
5124     end if;
5125 
5126 EXCEPTION
5127   WHEN OTHERS THEN
5128     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
5129                              p_procedure_name => ' PRORATE_TO_PAGL_N_PJP1_D ');
5130     RAISE;
5131 END;
5132 
5133 
5134 PROCEDURE PRORATE_TO_PAGL_PGE_PJP1_SE (p_calendar_type   IN   VARCHAR2 := NULL,
5135                                         p_prorating_format IN  VARCHAR2) IS
5136 BEGIN
5137 
5138      g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
5139 
5140     INSERT INTO pji_fp_aggr_pjp1 -- For PA/GL entries.
5141     (
5142        worker_id
5143      , PROJECT_ID
5144      , PROJECT_ORG_ID
5145      , PROJECT_ORGANIZATION_ID
5146      , PROJECT_ELEMENT_ID
5147      , TIME_ID
5148      , PERIOD_TYPE_ID
5149      , CALENDAR_TYPE
5150      , RBS_AGGR_LEVEL
5151      , WBS_ROLLUP_FLAG
5152      , PRG_ROLLUP_FLAG
5153      , CURR_RECORD_TYPE_ID
5154      , CURRENCY_CODE
5155      , RBS_ELEMENT_ID
5156      , RBS_VERSION_ID
5157      , PLAN_VERSION_ID
5158      , PLAN_TYPE_ID
5159      , RAW_COST
5160      , BRDN_COST
5161      , REVENUE
5162      , BILL_RAW_COST
5163      , BILL_BRDN_COST
5164      , BILL_LABOR_RAW_COST
5165      , BILL_LABOR_BRDN_COST
5166      , BILL_LABOR_HRS
5167      , EQUIPMENT_RAW_COST
5168      , EQUIPMENT_BRDN_COST
5169      , CAPITALIZABLE_RAW_COST
5170      , CAPITALIZABLE_BRDN_COST
5171      , LABOR_RAW_COST
5172      , LABOR_BRDN_COST
5173      , LABOR_HRS
5174      , LABOR_REVENUE
5175      , EQUIPMENT_HOURS
5176      , BILLABLE_EQUIPMENT_HOURS
5177      , SUP_INV_COMMITTED_COST
5178      , PO_COMMITTED_COST
5179      , PR_COMMITTED_COST
5180      , OTH_COMMITTED_COST
5181      , ACT_LABOR_HRS
5182      , ACT_EQUIP_HRS
5183      , ACT_LABOR_BRDN_COST
5184      , ACT_EQUIP_BRDN_COST
5185      , ACT_BRDN_COST
5186      , ACT_RAW_COST
5187      , ACT_REVENUE
5188      , ACT_LABOR_RAW_COST
5189      , ACT_EQUIP_RAW_COST
5190      , ETC_LABOR_HRS
5191      , ETC_EQUIP_HRS
5192      , ETC_LABOR_BRDN_COST
5193      , ETC_EQUIP_BRDN_COST
5194      , ETC_BRDN_COST
5195      , ETC_RAW_COST
5196      , ETC_LABOR_RAW_COST
5197      , ETC_EQUIP_RAW_COST
5198      , CUSTOM1
5199      , CUSTOM2
5200      , CUSTOM3
5201      , CUSTOM4
5202      , CUSTOM5
5203      , CUSTOM6
5204      , CUSTOM7
5205      , CUSTOM8
5206      , CUSTOM9
5207      , CUSTOM10
5208      , CUSTOM11
5209      , CUSTOM12
5210      , CUSTOM13
5211      , CUSTOM14
5212      , CUSTOM15
5213      , TIME_DANGLING_FLAG
5214      , RATE_DANGLING_FLAG
5215      , PRG_LEVEL
5216      , PLAN_TYPE_CODE   /* 4471527 */
5217 	)
5218    SELECT
5219            g_worker_id
5220          , fact.project_id  project_id
5221 	 , fact.PROJECT_ORG_ID project_org_id
5222 	 , fact.PROJECT_ORGANIZATION_ID project_organization_id
5223    	 , fact.PROJECT_ELEMENT_ID PROJECT_ELEMENT_ID
5224    	 , pa_cal.cal_period_id TIME_ID
5225    	 , fact.PERIOD_TYPE_ID PERIOD_TYPE_ID
5226    	 , DECODE(fact.CALENDAR_TYPE, 'P', 'G', 'G', 'P') CALENDAR_TYPE
5227          , fact.RBS_AGGR_LEVEL RBS_AGGR_LEVEL
5228          , fact.WBS_ROLLUP_FLAG WBS_ROLLUP_FLAG
5229          , fact.PRG_ROLLUP_FLAG PRG_ROLLUP_FLAG
5230          , fact.CURR_RECORD_TYPE_ID CURR_RECORD_TYPE_ID
5231    	 , fact.CURRENCY_CODE CURRENCY_CODE
5232    	 , fact.RBS_ELEMENT_ID RBS_ELEMENT_ID
5233    	 , fact.RBS_VERSION_ID RBS_VERSION_ID
5234    	 , fact.PLAN_VERSION_ID PLAN_VERSION_ID
5235    	 , fact.PLAN_TYPE_ID PLAN_TYPE_ID
5236    	 , SUM(fact.RAW_COST)	 raw_cost
5237    	 , SUM(fact.BRDN_COST) BRDN_COST
5238    	 , SUM(fact.REVENUE) REVENUE
5239    	 , SUM(fact.BILL_RAW_COST) BILL_RAW_COST
5240    	 , SUM(fact.BILL_BRDN_COST) BILL_BRDN_COST
5241    	 , SUM(fact.BILL_LABOR_RAW_COST) BILL_LABOR_RAW_COST
5242    	 , SUM(fact.BILL_LABOR_BRDN_COST) BILL_LABOR_BRDN_COST
5243    	 , SUM(fact.BILL_LABOR_HRS) BILL_LABOR_HRS
5244    	 , SUM(fact.EQUIPMENT_RAW_COST) EQUIPMENT_RAW_COST
5245    	 , SUM(fact.EQUIPMENT_BRDN_COST) EQUIPMENT_BRDN_COST
5246    	 , SUM(fact.CAPITALIZABLE_RAW_COST) CAPITALIZABLE_RAW_COST
5247    	 , SUM(fact.CAPITALIZABLE_BRDN_COST) CAPITALIZABLE_BRDN_COST
5248    	 , SUM(fact.LABOR_RAW_COST) LABOR_RAW_COST
5249    	 , SUM(fact.LABOR_BRDN_COST) LABOR_BRDN_COST
5250    	 , SUM(fact.LABOR_HRS) LABOR_HRS
5251    	 , SUM(fact.LABOR_REVENUE) LABOR_REVENUE
5252    	 , SUM(fact.EQUIPMENT_HOURS) EQUIPMENT_HOURS
5253    	 , SUM(fact.BILLABLE_EQUIPMENT_HOURS) BILLABLE_EQUIPMENT_HOURS
5254    	 , SUM(fact.SUP_INV_COMMITTED_COST) SUP_INV_COMMITTED_COST
5255    	 , SUM(fact.PO_COMMITTED_COST) PO_COMMITTED_COST
5256    	 , SUM(fact.PR_COMMITTED_COST) PR_COMMITTED_COST
5257    	 , SUM(fact.OTH_COMMITTED_COST) OTH_COMMITTED_COST
5258          , SUM(fact.ACT_LABOR_HRS )
5259 	 , SUM(fact.ACT_EQUIP_HRS )
5260 	 , SUM(fact.ACT_LABOR_BRDN_COST )
5261 	 , SUM(fact.ACT_EQUIP_BRDN_COST )
5262 	 , SUM(fact.ACT_BRDN_COST )
5263 	 , SUM(fact.ACT_RAW_COST )
5264 	 , SUM(fact.ACT_REVENUE )
5265          , SUM(fact.ACT_LABOR_RAW_COST)
5266          , SUM(fact.ACT_EQUIP_RAW_COST)
5267 	 , SUM(fact.ETC_LABOR_HRS )
5268 	 , SUM(fact.ETC_EQUIP_HRS )
5269 	 , SUM(fact.ETC_LABOR_BRDN_COST )
5270 	 , SUM(fact.ETC_EQUIP_BRDN_COST )
5271 	 , SUM(fact.ETC_BRDN_COST )
5272          , SUM(fact.ETC_RAW_COST )
5273          , SUM(fact.ETC_LABOR_RAW_COST)
5274          , SUM(fact.ETC_EQUIP_RAW_COST)
5275    	 , SUM(fact.CUSTOM1) CUSTOM1
5276    	 , SUM(fact.CUSTOM2) CUSTOM2
5277    	 , SUM(fact.CUSTOM3) CUSTOM3
5278    	 , SUM(fact.CUSTOM4) CUSTOM4
5279    	 , SUM(fact.CUSTOM5) CUSTOM5
5280    	 , SUM(fact.CUSTOM6) CUSTOM6
5281    	 , SUM(fact.CUSTOM7) CUSTOM7
5282    	 , SUM(fact.CUSTOM8) CUSTOM8
5283    	 , SUM(fact.CUSTOM9) CUSTOM9
5284    	 , SUM(fact.CUSTOM10) CUSTOM10
5285    	 , SUM(fact.CUSTOM11) CUSTOM11
5286    	 , SUM(fact.CUSTOM12) CUSTOM12
5287    	 , SUM(fact.CUSTOM13) CUSTOM13
5288    	 , SUM(fact.CUSTOM14) CUSTOM14
5289    	 , SUM(fact.CUSTOM15) CUSTOM15
5290 	 , NULL TIME_DANGLING_FLAG
5291 	 , NULL RATE_DANGLING_FLAG
5292          , g_default_prg_level prg_level
5293          , fact.PLAN_TYPE_CODE PLAN_TYPE_CODE    /* 4471527 */
5294      FROM  pji_fp_aggr_pjp1 fact
5295          , pji_time_cal_period_v  non_pa_cal
5296    	 , pji_org_extr_info  orginfo
5297    	 , pji_time_cal_period_v  pa_cal
5298          , pji_fm_extr_plnver4  ver
5299    WHERE  fact.CALENDAR_TYPE <> p_calendar_type
5300       AND fact.worker_id = g_worker_id
5301       AND ver.worker_id = g_worker_id
5302       AND fact.CALENDAR_TYPE IN ('P', 'G')
5303       AND non_pa_cal.cal_period_id = fact.time_id
5304       AND fact.line_type like 'OF%'
5305       AND orginfo.org_id = fact.PROJECT_ORG_ID
5306       AND DECODE(fact.calendar_type, 'P', orginfo.gl_calendar_id, 'G', orginfo.pa_calendar_id) = pa_cal.calendar_id
5307       AND ( non_pa_cal.start_date <= pa_cal.end_date AND non_pa_cal.end_date >= pa_cal.start_date )
5308       AND fact.period_type_id = 32
5309       AND fact.plan_version_id = ver.plan_version_id
5310       AND fact.plan_type_code = ver.plan_type_code   /* 4471527 */
5311       AND ver.wp_flag = 'N'
5312       AND ver.baselined_flag = 'Y'
5313 	AND fact.rbs_version_id = NVL(ver.rbs_struct_version_id , -1)
5314       AND DECODE(p_prorating_format,'S',
5315              DECODE(SIGN(non_pa_cal.start_Date-pa_cal.start_date),-1,0,1),
5316              DECODE(SIGN(non_pa_cal.end_Date - pa_cal.end_date), 1,0,1))=1
5317       AND ver.plan_version_id > 0
5318    GROUP BY
5319            fact.project_id
5320 	 , fact.PROJECT_ORG_ID
5321 	 , fact.PROJECT_ORGANIZATION_ID
5322    	 , fact.PROJECT_ELEMENT_ID
5323    	 , pa_cal.cal_period_id
5324    	 , fact.PERIOD_TYPE_ID
5325    	 , fact.CALENDAR_TYPE
5326          , fact.RBS_AGGR_LEVEL
5327          , fact.WBS_ROLLUP_FLAG
5328          , fact.PRG_ROLLUP_FLAG
5329          , fact.CURR_RECORD_TYPE_ID
5330    	 , fact.CURRENCY_CODE
5331    	 , fact.RBS_ELEMENT_ID
5332    	 , fact.RBS_VERSION_ID
5333    	 , fact.PLAN_VERSION_ID
5334    	 , fact.PLAN_TYPE_ID
5335               , fact.PLAN_TYPE_CODE;   /* 4471527 */
5336 
5337 
5338 
5339 EXCEPTION
5340   WHEN OTHERS THEN
5341     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
5342                              p_procedure_name => 'PRORATE_TO_PAGL_PGE_PJP1_SE');
5343     RAISE;
5344 END;
5345 
5346 
5347 PROCEDURE PRORATE_TO_PAGL_PGE_FPRL_SE (p_calendar_type   IN   VARCHAR2 := NULL) IS
5348 BEGIN
5349 
5350    g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
5351 
5352 EXCEPTION
5353   WHEN OTHERS THEN
5354     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
5355                              p_procedure_name => 'PRORATE_TO_PAGL_PGE_FPRL_SE');
5356     RAISE;
5357 END;
5358 
5359 
5360 PROCEDURE PRORATE_TO_PAGL_N_PJP1_SE (p_calendar_type   IN   VARCHAR2 := NULL,
5361                                      p_prorating_format IN VARCHAR2) IS
5362 BEGIN
5363 
5364     g_worker_id  := PJI_PJP_FP_CURR_WRAP.GET_WORKER_ID;
5365 
5366     INSERT INTO pji_fp_aggr_pjp1 -- For non time phased entries.
5367     (
5368        worker_id
5369      , PROJECT_ID
5370      , PROJECT_ORG_ID
5371      , PROJECT_ORGANIZATION_ID
5372      , PROJECT_ELEMENT_ID
5373      , TIME_ID
5374      , PERIOD_TYPE_ID
5375      , CALENDAR_TYPE
5376      , RBS_AGGR_LEVEL
5377      , WBS_ROLLUP_FLAG
5378      , PRG_ROLLUP_FLAG
5379      , CURR_RECORD_TYPE_ID
5380      , CURRENCY_CODE
5381      , RBS_ELEMENT_ID
5382      , RBS_VERSION_ID
5383      , PLAN_VERSION_ID
5384      , PLAN_TYPE_ID
5385      , RAW_COST
5386      , BRDN_COST
5387      , REVENUE
5388      , BILL_RAW_COST
5389      , BILL_BRDN_COST
5390      , BILL_LABOR_RAW_COST
5391      , BILL_LABOR_BRDN_COST
5392      , BILL_LABOR_HRS
5393      , EQUIPMENT_RAW_COST
5394      , EQUIPMENT_BRDN_COST
5395      , CAPITALIZABLE_RAW_COST
5396      , CAPITALIZABLE_BRDN_COST
5397      , LABOR_RAW_COST
5398      , LABOR_BRDN_COST
5399      , LABOR_HRS
5400      , LABOR_REVENUE
5401      , EQUIPMENT_HOURS
5402      , BILLABLE_EQUIPMENT_HOURS
5403      , SUP_INV_COMMITTED_COST
5404      , PO_COMMITTED_COST
5405      , PR_COMMITTED_COST
5406      , OTH_COMMITTED_COST
5407      , ACT_LABOR_HRS
5408      , ACT_EQUIP_HRS
5409      , ACT_LABOR_BRDN_COST
5410      , ACT_EQUIP_BRDN_COST
5411      , ACT_BRDN_COST
5412      , ACT_RAW_COST
5413      , ACT_REVENUE
5414      , ACT_LABOR_RAW_COST
5415      , ACT_EQUIP_RAW_COST
5416      , ETC_LABOR_HRS
5417      , ETC_EQUIP_HRS
5418      , ETC_LABOR_BRDN_COST
5419      , ETC_EQUIP_BRDN_COST
5420      , ETC_BRDN_COST
5421      , ETC_RAW_COST
5422      , ETC_LABOR_RAW_COST
5423      , ETC_EQUIP_RAW_COST
5424      , CUSTOM1
5425      , CUSTOM2
5426      , CUSTOM3
5427      , CUSTOM4
5428      , CUSTOM5
5429      , CUSTOM6
5430      , CUSTOM7
5431      , CUSTOM8
5432      , CUSTOM9
5433      , CUSTOM10
5434      , CUSTOM11
5435      , CUSTOM12
5436      , CUSTOM13
5437      , CUSTOM14
5438      , CUSTOM15
5439      , TIME_DANGLING_FLAG
5440      , RATE_DANGLING_FLAG
5441      , PRG_LEVEL
5442      , PLAN_TYPE_CODE  /* 4471527 */
5443    )
5444    SELECT
5445            g_worker_id
5446          , fact.project_id  project_id
5447 	 , fact.PROJECT_ORG_ID project_org_id
5448 	 , fact.PROJECT_ORGANIZATION_ID project_organization_id
5449    	 , fact.PROJECT_ELEMENT_ID PROJECT_ELEMENT_ID
5450    	 , pa_cal.cal_period_id TIME_ID
5451    	 , 32 -- fact.PERIOD_TYPE_ID PERIOD_TYPE_ID
5452          -- Bug 13982637
5453          --, DECODE(pa_cal.calendar_id,orginfo.pa_calendar_id,'P',orginfo.gl_calendar_id,'G') CALENDAR_TYPE
5454          , p_calendar_type CALENDAR_TYPE
5455          -- End Bug 13982637
5456          , fact.RBS_AGGR_LEVEL RBS_AGGR_LEVEL
5457          , fact.WBS_ROLLUP_FLAG WBS_ROLLUP_FLAG
5458          , fact.PRG_ROLLUP_FLAG PRG_ROLLUP_FLAG
5459          , fact.CURR_RECORD_TYPE_ID CURR_RECORD_TYPE_ID
5460    	 , fact.CURRENCY_CODE CURRENCY_CODE
5461    	 , fact.RBS_ELEMENT_ID RBS_ELEMENT_ID
5462    	 , fact.RBS_VERSION_ID RBS_VERSION_ID
5463    	 , fact.PLAN_VERSION_ID PLAN_VERSION_ID
5464    	 , fact.PLAN_TYPE_ID PLAN_TYPE_ID
5465    	 , SUM(fact.RAW_COST)	 raw_cost
5466    	 , SUM(fact.BRDN_COST) BRDN_COST
5467    	 , SUM(fact.REVENUE) REVENUE
5468    	 , SUM(fact.BILL_RAW_COST) BILL_RAW_COST
5469    	 , SUM(fact.BILL_BRDN_COST) BILL_BRDN_COST
5470    	 , SUM(fact.BILL_LABOR_RAW_COST) BILL_LABOR_RAW_COST
5471    	 , SUM(fact.BILL_LABOR_BRDN_COST) BILL_LABOR_BRDN_COST
5472    	 , SUM(fact.BILL_LABOR_HRS) BILL_LABOR_HRS
5473    	 , SUM(fact.EQUIPMENT_RAW_COST) EQUIPMENT_RAW_COST
5474    	 , SUM(fact.EQUIPMENT_BRDN_COST) EQUIPMENT_BRDN_COST
5475    	 , SUM(fact.CAPITALIZABLE_RAW_COST) CAPITALIZABLE_RAW_COST
5476    	 , SUM(fact.CAPITALIZABLE_BRDN_COST) CAPITALIZABLE_BRDN_COST
5477    	 , SUM(fact.LABOR_RAW_COST) LABOR_RAW_COST
5478    	 , SUM(fact.LABOR_BRDN_COST) LABOR_BRDN_COST
5479    	 , SUM(fact.LABOR_HRS) LABOR_HRS
5480    	 , SUM(fact.LABOR_REVENUE) LABOR_REVENUE
5481    	 , SUM(fact.EQUIPMENT_HOURS) EQUIPMENT_HOURS
5482    	 , SUM(fact.BILLABLE_EQUIPMENT_HOURS) BILLABLE_EQUIPMENT_HOURS
5483    	 , SUM(fact.SUP_INV_COMMITTED_COST) SUP_INV_COMMITTED_COST
5484    	 , SUM(fact.PO_COMMITTED_COST) PO_COMMITTED_COST
5485    	 , SUM(fact.PR_COMMITTED_COST) PR_COMMITTED_COST
5486    	 , SUM(fact.OTH_COMMITTED_COST) OTH_COMMITTED_COST
5487          , SUM(fact.ACT_LABOR_HRS )
5488 	 , SUM(fact.ACT_EQUIP_HRS )
5489 	 , SUM(fact.ACT_LABOR_BRDN_COST )
5490 	 , SUM(fact.ACT_EQUIP_BRDN_COST )
5491 	 , SUM(fact.ACT_BRDN_COST )
5492 	 , SUM(fact.ACT_RAW_COST )
5493 	 , SUM(fact.ACT_REVENUE )
5494          , SUM(fact.ACT_LABOR_RAW_COST)
5495          , SUM(fact.ACT_EQUIP_RAW_COST)
5496 	 , SUM(fact.ETC_LABOR_HRS )
5497 	 , SUM(fact.ETC_EQUIP_HRS )
5498 	 , SUM(fact.ETC_LABOR_BRDN_COST )
5499 	 , SUM(fact.ETC_EQUIP_BRDN_COST )
5500 	 , SUM(fact.ETC_BRDN_COST )
5501          , SUM(fact.ETC_RAW_COST )
5502          , SUM(fact.ETC_LABOR_RAW_COST)
5503          , SUM(fact.ETC_EQUIP_RAW_COST)
5504    	 , SUM(fact.CUSTOM1) CUSTOM1
5505    	 , SUM(fact.CUSTOM2) CUSTOM2
5506    	 , SUM(fact.CUSTOM3) CUSTOM3
5507    	 , SUM(fact.CUSTOM4) CUSTOM4
5508    	 , SUM(fact.CUSTOM5) CUSTOM5
5509    	 , SUM(fact.CUSTOM6) CUSTOM6
5510    	 , SUM(fact.CUSTOM7) CUSTOM7
5511    	 , SUM(fact.CUSTOM8) CUSTOM8
5512    	 , SUM(fact.CUSTOM9) CUSTOM9
5513    	 , SUM(fact.CUSTOM10) CUSTOM10
5514    	 , SUM(fact.CUSTOM11) CUSTOM11
5515    	 , SUM(fact.CUSTOM12) CUSTOM12
5516    	 , SUM(fact.CUSTOM13) CUSTOM13
5517    	 , SUM(fact.CUSTOM14) CUSTOM14
5518    	 , SUM(fact.CUSTOM15) CUSTOM15
5519 	 , NULL  TIME_DANGLING_FLAG
5520 	 , NULL  RATE_DANGLING_FLAG
5521          , g_default_prg_level prg_level
5522          , fact.plan_type_code PLAN_TYPE_CODE   /* 4471527 */
5523       FROM pji_fp_aggr_pjp1 fact
5524    	 , pji_org_extr_info  orginfo
5525    	 , pji_time_cal_period_v  pa_cal
5526          , pji_fm_extr_plnver4  ver
5527    WHERE  1=1
5528       AND fact.CALENDAR_TYPE = 'A'
5529       AND orginfo.org_id = fact.PROJECT_ORG_ID
5530       AND DECODE(p_calendar_type
5531                , 'P', orginfo.pa_calendar_id
5532                , 'G', orginfo.gl_calendar_id) = pa_cal.calendar_id
5533       AND fact.start_date IS NOT NULL
5534       AND fact.end_date IS NOT NULL
5535       AND fact.period_type_id = 2048
5536       AND fact.plan_version_id = ver.plan_version_id
5537       AND fact.plan_type_code = ver.plan_type_code /* 4471527 */
5538       AND ver.wp_flag = 'N'
5539       AND ver.baselined_flag = 'Y'
5540       AND ver.time_phased_type_code = 'N'
5541       AND fact.line_type = 'NTP'
5542       AND fact.worker_id = g_worker_id
5543       AND ver.worker_id = g_worker_id
5544 	AND fact.rbs_version_id = NVL(ver.rbs_struct_version_id , -1)
5545       AND ( fact.start_date <= pa_cal.end_date AND fact.end_date >= pa_cal.start_date )
5546       AND DECODE(p_prorating_format,'S',
5547              DECODE(SIGN(fact.start_Date-pa_cal.start_date),-1,0,1),
5548              DECODE(SIGN(fact.end_Date - pa_cal.end_date), 1,0,1))=1
5549       AND ver.plan_version_id > 0
5550    GROUP BY
5551            fact.project_id
5552 	 , fact.PROJECT_ORG_ID
5553 	 , fact.PROJECT_ORGANIZATION_ID
5554    	 , fact.PROJECT_ELEMENT_ID
5555    	 , pa_cal.cal_period_id
5556    	 , fact.PERIOD_TYPE_ID
5557    	 , fact.CALENDAR_TYPE
5558          , fact.RBS_AGGR_LEVEL
5559          , fact.WBS_ROLLUP_FLAG
5560          , fact.PRG_ROLLUP_FLAG
5561          , fact.CURR_RECORD_TYPE_ID
5562    	 , fact.CURRENCY_CODE
5563    	 , fact.RBS_ELEMENT_ID
5564    	 , fact.RBS_VERSION_ID
5565    	 , fact.PLAN_VERSION_ID
5566    	 , fact.PLAN_TYPE_ID
5567               , fact.PLAN_TYPE_CODE   /* 4471527 */
5568 	 , fact.TIME_DANGLING_FLAG
5569 	 , fact.RATE_DANGLING_FLAG
5570          -- Bug 13982637
5571 	 --,  DECODE(pa_cal.calendar_id,orginfo.pa_calendar_id,'P',orginfo.gl_calendar_id,'G');
5572          , p_calendar_type;
5573          -- End Bug 13982637
5574 
5575 
5576 
5577 EXCEPTION
5578   WHEN OTHERS THEN
5579     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
5580                              p_procedure_name => 'PRORATE_TO_PAGL_N_PJP1_SE');
5581     RAISE;
5582 END;
5583 
5584 
5585 ----------
5586 -- Print time API to measure time taken by each api. Also useful for debugging.
5587 ----------
5588 PROCEDURE PRINT_TIME(p_tag IN VARCHAR2) IS
5589 BEGIN
5590   PJI_PJP_FP_CURR_WRAP.print_time(p_tag);
5591 EXCEPTION
5592   WHEN OTHERS THEN
5593     FND_MSG_PUB.add_exc_msg( p_pkg_name       => g_package_name ,
5594                              p_procedure_name => 'PRINT_TIME');
5595     RAISE;
5596 END;
5597 
5598 
5599 END PJI_FM_PLAN_CAL_RLPS;