DBA Data[Home] [Help]

PACKAGE BODY: APPS.PA_ADJUSTMENTS

Source


1 PACKAGE BODY PA_ADJUSTMENTS AS
2 /* $Header: PAXTADJB.pls 120.80.12010000.8 2008/11/06 14:08:26 anuragar ship $ */
3 
4   RESOURCE_BUSY     EXCEPTION;
5   PRAGMA EXCEPTION_INIT( RESOURCE_BUSY, -0054 );
6 
7   ExpOrganizationTab      PA_PLSQL_DATATYPES.IdTabTyp;
8   ExpOrgTab               PA_PLSQL_DATATYPES.IdTabTyp;
9   TaskIdTab               PA_PLSQL_DATATYPES.IdTabTyp;
10   ExpItemDateTab          PA_PLSQL_DATATYPES.DateTabTyp;
11   ExpTypeTab              PA_PLSQL_DATATYPES.Char30TabTyp ;
12   IncurredByPersonIdTab   PA_PLSQL_DATATYPES.IdTabTyp;
13   TrxSourceTab            PA_PLSQL_DATATYPES.Char30TabTyp ;
14   NlrOrganizationIdTab    PA_PLSQL_DATATYPES.IdTabTyp;
15   SysLinkageTab           PA_PLSQL_DATATYPES.Char30TabTyp;
16   CrossChargeCodeTab      PA_PLSQL_DATATYPES.Char1TabTyp;
17   DenomTpCurrCodeTab      PA_PLSQL_DATATYPES.Char15TabTyp ;
18   P_DEBUG_MODE BOOLEAN     := pa_cc_utils.g_debug_mode;
19 
20 /* R12 Changes Start */
21   TYPE METHODS IS RECORD ( ORG_ID NUMBER
22                          , METHOD VARCHAR2(25));
23   TYPE METHODS_TAB IS TABLE OF METHODS INDEX BY BINARY_INTEGER;
24   G_AUTOMATIC_OFFSET_METHOD METHODS_TAB;
25 
26   G_VENDOR_ID               NUMBER;
27   G_ORG_ID                  NUMBER;
28   G_SET_OF_BOOKS_ID         NUMBER;
29   G_GL_DATE                 DATE;
30   G_COA_ID                  NUMBER;
31   G_EMP_ID                  NUMBER;
32   G_EMP_CCID                NUMBER;
33   G_INVOICE_DISTRIBUTION_ID NUMBER;
34   G_EXPENSE_TYPE            NUMBER;
35   G_EXP_ITEM_ID             NUMBER;
36   G_OLD_CCID                NUMBER;
37   G_NEW_CCID                NUMBER;
38 /* R12 Changes End */
39 
40 /* R12 Changes Start */
41   G_PO_HEADER_ID NUMBER;
42   G_PO_NUM VARCHAR2(20);
43   G_PO_DATE DATE;
44   G_PO_LINE_NUM NUMBER;
45   G_PO_DIST_NUM NUMBER;
46   G_PO_DIST_ID NUMBER;
47 
48   G_INV_TYPE_CODE VARCHAR2(30);
49   G_INV_TYPE VARCHAR2(80);
50   G_INV_LINE_TYPE_CODE VARCHAR2(30);
51   G_INV_LINE_TYPE VARCHAR2(80);
52   G_INV_DIST_TYPE_CODE VARCHAR2(30);
53   G_INV_DIST_TYPE VARCHAR2(80);
54   G_PAYMENT_TYPE_CODE VARCHAR2(30); /* 4914048 */
55   G_PAYMENT_TYPE VARCHAR2(80); /* 4914048 */
56   G_PO_DIST_TYPE_CODE VARCHAR2(30);
57   G_PO_DIST_TYPE VARCHAR2(80);
58   G_RCV_TXN_TYPE_CODE VARCHAR2(30);
59   G_RCV_TXN_TYPE VARCHAR2(80);
60 
61   G_RCV_TXN_ID NUMBER;
62   G_RCV_NUM VARCHAR2(30);
63   G_RCV_DATE DATE;
64 
65   G_INV_ID NUMBER;
66   G_INV_NUM VARCHAR2(50);
67   G_INV_DATE DATE;
68 /* R12 Changes End */
69 
70 /* Bug 5235354 - Start */
71   TYPE LEDGER_CNT IS RECORD ( ORG_ID NUMBER
72                             , CNT NUMBER);
73   TYPE LEDGER_CNT_TAB IS TABLE OF LEDGER_CNT INDEX BY BINARY_INTEGER;
74   G_LEDGER_CNT LEDGER_CNT_TAB;
75 /* Bug 5235354 - End */
76 
77 
78 /*Bug# 5874347 - Start*/
79 Function getprojburdenflag(p_project_id in number) return varchar2
80 IS
81 X_proj_bcost_flag VARCHAR2(10) DEFAULT 'N';
82 BEGIN
83        SELECT  nvl(burden_cost_flag,'N')
84         INTO   X_proj_bcost_flag
85         FROM   pa_projects_all proj,
86                pa_project_types_all ptype
87         WHERE  proj.project_type = ptype.project_type
88           AND  nvl(proj.org_id, -99) = nvl(ptype.org_id,-99)
89           AND  project_id = p_Project_id ;
90 return(X_proj_bcost_flag);
91 Exception
92 WHEN NO_DATA_FOUND THEN
93 X_proj_bcost_flag :='N';
94 return(X_proj_bcost_flag);
95 END getprojburdenflag;
96 /*Bug# 5874347 - End */
97 
98 -- ========================================================================
99 -- PROCEDURE CheckStatus
100 -- ========================================================================
101 
102   PROCEDURE CheckStatus( status_indicator IN OUT NOCOPY NUMBER )
103   IS
104   BEGIN
105 
106     IF ( status_indicator <> 0 ) THEN
107       RAISE SUBROUTINE_ERROR;
108     ELSIF ( status_indicator = 0 ) THEN
109       status_indicator := NULL;
110     END IF;
111 
112   END CheckStatus;
113 
114 
115 --=========================================================================
116 -- PROCEDURE print_message
117 --========================================================================
118 PROCEDURE print_message(p_msg_token1  IN varchar2) IS
119 			--,p_msg_token2  IN varchar2 ) IS
120 
121 
122 BEGIN
123 	If p_msg_token1 is not null --or p_msg_token2 is not null
124 	   then
125 		--dbms_output.put_line('LOG: '||p_msg_token1);
126 		--r_debug.r_msg(p_msg =>'LOG: '||p_msg_token1);
127 		   pa_cc_utils.log_message('get_denom_curr_code: ' || substr(p_msg_token1,1,250), 0 );
128                 null;
129 	End If;
130 
131 	Return;
132 
133 END print_message;
134 
135 FUNCTION is_proj_billable(p_task_id   IN  number) return varchar2 IS
136 
137 	l_billable  varchar2(1) := 'N';
138 
139 BEGIN
140 
141 	SELECT 'Y'
142         INTO l_billable
143 	FROM pa_projects_all pp,
144 	     pa_tasks t,
145 	     pa_project_types_all  pt	/** Bug fix 2262118  **/
146 	WHERE t.task_id = p_task_id
147 	AND   pp.project_id = t.project_id
148 	AND   pp.project_type = pt.project_type
149     AND   pt.PROJECT_TYPE_CLASS_CODE in ('CAPITAL','CONTRACT')
150     -- start 12i MOAC changes
151 	-- AND   nvl(pp.org_id ,-99) = nvl(pt.org_id ,-99) ;
152     AND   pp.org_id = pt.org_id ;
153 
154         return l_billable;
155 
156 EXCEPTION
157 
158        WHEN NO_DATA_FOUND then
159 		return 'N';
160 
161        WHEN OTHERS THEN
162 		return 'N';
163 
164 END is_proj_billable ;
165 
166 -- ========================================================================
167 -- FUNCTION VerifyOrigItem
168 -- ========================================================================
169 
170   FUNCTION VerifyOrigItem ( X_person_id                IN NUMBER
171                           , X_org_id                   IN NUMBER
172                           , X_item_date                IN DATE
173                           , X_task_id                  IN NUMBER
174                           , X_exp_type                 IN VARCHAR2
175                           , X_system_linkage_function  IN VARCHAR2
176                           , X_nl_org_id                IN NUMBER
177                           , X_nl_resource              IN VARCHAR2
178                           , X_quantity                 IN NUMBER
179                           , X_denom_raw_cost           IN NUMBER
180 		                    , X_trx_source               IN VARCHAR2
181 			                 , X_denom_currency_code      IN VARCHAR2
182 			                 , X_acct_raw_cost            IN NUMBER
183                           -- SST Change
184                           , X_reversed_orig_txn_reference  IN OUT NOCOPY VARCHAR2
185                           ) RETURN  NUMBER
186   IS
187     orig_item_id       NUMBER DEFAULT NULL;
188   CURSOR cur_origtxn IS
189     SELECT
190             min(i.expenditure_item_id),
191             -- SST Change: If X_reversed_orig_txn_reference is not NULL
192             -- then we already have the reversing item's
193             -- orig_transaction_reference, otherwise get the
194             -- reversing item's orig_transaction_reference
195             decode(X_reversed_orig_txn_reference,NULL,
196                    i.orig_transaction_reference,
197                    X_reversed_orig_txn_reference) orig_txn_reference
198       FROM
199             pa_transaction_sources ts
200     ,       pa_expenditure_items i
201     ,       pa_expenditures e
202      WHERE
203             i.expenditure_item_date = X_item_date
204        AND  i.expenditure_type ||''     = X_exp_type
205        AND  i.system_linkage_function ||'' = X_system_linkage_function
206        AND  i.task_id               = X_task_id
207        AND  ( i.quantity * -1 ) = X_quantity
208        AND  i.transaction_source = ts.transaction_source
209        AND  (   (     ts.costed_flag = 'Y'
210                   AND ( i.denom_raw_cost * -1) = pa_currency.round_trans_currency_amt(X_denom_raw_cost,X_denom_currency_code))
211              OR ( ts.costed_flag = 'N' ) )
212         AND  (   (     ts.gl_accounted_flag = 'Y'
213                   AND ( i.acct_raw_cost * -1) =
214                       pa_currency.round_currency_amt(X_acct_raw_cost))
215              OR ( ts.gl_accounted_flag = 'N' ) )
216        AND  i.expenditure_id = e.expenditure_id
217        AND  ( ( e.incurred_by_person_id = X_person_id )
218                                OR
219             ( ( e.incurred_by_person_id IS NULL ) AND
220               ( e.incurred_by_organization_id = X_org_id ) ) )
221        AND  nvl( i.organization_id, -1 ) = nvl( X_nl_org_id, -1 )
222        AND  nvl( i.non_labor_resource, 'DUMMY' ) =
223                              nvl( X_nl_resource, 'DUMMY' )
224        AND  i.transaction_source ||'' = X_trx_source
225        AND  nvl( i.net_zero_adjustment_flag, 'N' ) = 'N'
226 		 AND  pa_adjustments.ei_adjusted_in_cache(i.expenditure_item_id) = 'N'
227        -- SSt changes: If we have the orig_txn_ref of the reversing item,
228        -- then the item we find must have the matching orig_txn_reference.
229        -- If we don't have the orig_txn_reference of the reversing item,
230        -- then the item we find does not need to satisfy the following
231        -- condition
232        AND (i.orig_transaction_reference = X_reversed_orig_txn_reference OR
233             X_reversed_orig_txn_reference IS NULL)
234        GROUP BY decode(X_reversed_orig_txn_reference,NULL,
235                    i.orig_transaction_reference,
236                    X_reversed_orig_txn_reference);
237 
238     BEGIN
239 
240     OPEN cur_origtxn;
241     FETCH cur_origtxn INTO orig_item_id,X_reversed_orig_txn_reference;
242     CLOSE cur_origtxn;
243 
244     RETURN ( orig_item_id );
245 
246   EXCEPTION
247     WHEN  NO_DATA_FOUND  THEN
248       RETURN ( NULL );
249 
250   END VerifyOrigItem;
251 
252 
253 
254 -- ========================================================================
255 -- PROCEDURE CommentChange
256 -- ========================================================================
257 
258   PROCEDURE   CommentChange( X_exp_item_id  IN NUMBER
259                            , X_new_comment  IN VARCHAR2
260                            , X_user         IN NUMBER
261                            , X_login        IN NUMBER
262                            , X_status       OUT NOCOPY NUMBER )
263   IS
264     dummy        NUMBER;
265     temp_status  NUMBER DEFAULT NULL;
266 
267     -- ------------------------------------------------------------------
268     -- PROCEDURE CommentChange.DelComment
269     -- ------------------------------------------------------------------
270 
271     PROCEDURE  DelComment( X_exp_item_id  IN NUMBER
272                          , X_status       OUT NOCOPY NUMBER )
273     IS
274     BEGIN
275       DELETE FROM pa_expenditure_comments
276             WHERE
277                    expenditure_item_id = X_exp_item_id;
278 
279       X_status := 0;
280 
281     EXCEPTION
282       WHEN  OTHERS  THEN
283         X_status := SQLCODE;
284         RAISE;
285 
286     END  DelComment;
287 
288 
289     -- ------------------------------------------------------------------
290     -- PROCEDURE CommentChange.UpdComment
291     -- ------------------------------------------------------------------
292 
293     PROCEDURE  UpdComment( X_exp_item_id  IN NUMBER
294                          , X_new_comment  IN VARCHAR2
295                          , X_user         IN NUMBER
296                          , X_login        IN NUMBER
297                          , X_status       OUT NOCOPY NUMBER )
298     IS
299     BEGIN
300 
301       UPDATE pa_expenditure_comments
302          SET
303              expenditure_comment = X_new_comment
304       ,      last_update_date    = sysdate
305       ,      last_updated_by     = X_user
306       ,      last_update_login   = X_login
307        WHERE
308              expenditure_item_id = X_exp_item_id;
309 
310       X_status := 0;
311 
312     EXCEPTION
313       WHEN  OTHERS  THEN
314         X_status := SQLCODE;
315         RAISE;
316 
317     END  UpdComment;
318 
319   BEGIN
320 
321     SELECT count(*)
322       INTO dummy
323       FROM sys.dual
324      WHERE EXISTS
325              ( SELECT NULL
326                  FROM pa_expenditure_comments
327                 WHERE expenditure_item_id = X_exp_item_id);
328 
329     IF( dummy = 0 ) THEN
330 
331       pa_transactions.InsItemComment( X_exp_item_id
332                                     , X_new_comment
333                                     , X_user
334                                     , X_login
335                                     , temp_status );
336       CheckStatus( temp_status );
337 
338     ELSIF(    dummy <> 0
339           AND X_new_comment IS NOT NULL ) THEN
340 
341       UpdComment( X_exp_item_id
342                 , X_new_comment
343                 , X_user
344                 , X_login
345                 , temp_status );
346       CheckStatus( temp_status );
347 
348     ELSIF(    dummy <> 0
349           AND X_new_comment IS NULL ) THEN
350 
351        DelComment( X_exp_item_id
352                  , temp_status );
353 
354     END IF;
355 
356     X_status := 0;
357 
358   EXCEPTION
359     WHEN  OTHERS  THEN
360       X_status := SQLCODE;
361       RAISE;
362 
363   END  CommentChange;
364 
365 
366 
367 -- ========================================================================
368 -- PROCEDURE InsAuditRec
369 -- ========================================================================
370 
371 
372   PROCEDURE  InsAuditRec( X_exp_item_id       IN NUMBER
373                         , X_adj_activity      IN VARCHAR2
374                         , X_module            IN VARCHAR2
375                         , X_user              IN NUMBER
376                         , X_login             IN NUMBER
377                         , X_status            OUT NOCOPY NUMBER
378                         , X_who_req_id        IN NUMBER
379                         , X_who_prog_id       IN NUMBER
380                         , X_who_prog_app_id   IN NUMBER
381                         , X_who_prog_upd_date IN DATE
382 			, X_rejection_code    IN VARCHAR2 )
383   IS
384   BEGIN
385     INSERT INTO pa_expend_item_adj_activities (
386           expenditure_item_id
387        ,  last_update_date
388        ,  last_updated_by
389        ,  creation_date
390        ,  created_by
391        ,  last_update_login
392        ,  activity_date
393        ,  exception_activity_code
394        ,  module_code
395        ,  request_id
396        ,  program_application_id
397        ,  program_id
398        ,  program_update_date
399        ,  rejection_code)
400     VALUES (
401           X_exp_item_id              -- expenditure_item_id
402        ,  sysdate                    -- last_update_date
403        ,  X_user                     -- last_updated_by
404        ,  sysdate                    -- creation_date
405        ,  X_user                     -- created_by
406        ,  X_login                    -- last_update_login
407        ,  sysdate                    -- activity_date
408        ,  X_adj_activity             -- exception_activity_code
409        ,  X_module                   -- module_code
410        ,  X_who_req_id               -- request_id
411        ,  X_who_prog_app_id          -- program_application_id
412        ,  X_who_prog_id              -- program_id
413        ,  X_who_prog_upd_date        -- program_update_date
414        ,  X_rejection_code );        -- rejection_code
415 
416     X_status := 0;
417 
418   EXCEPTION
419     WHEN  OTHERS  THEN
420       X_status := SQLCODE;
421       RAISE;
422 
423   END  InsAuditRec;
424 
425 
426 -- ========================================================================
427 -- PROCEDURE  SetNetZero
428 -- ========================================================================
429 
430   PROCEDURE  SetNetZero( X_exp_item_id   IN NUMBER
431                        , X_user          IN NUMBER
432                        , X_login         IN NUMBER
433                        , X_status        OUT NOCOPY NUMBER )
434   IS
435     BEGIN
436       UPDATE pa_expenditure_items_all ei
437          SET
438               ei.net_zero_adjustment_flag = 'Y'
439       ,       ei.last_update_date         = sysdate
440       ,       ei.last_updated_by          = X_user
441       ,       ei.last_update_login        = X_login
442        WHERE
443               ei.expenditure_item_id = X_exp_item_id;
444 
445       X_status := 0;
446 
447     EXCEPTION
448       WHEN  OTHERS  THEN
449         X_status := SQLCODE;
450         RAISE;
451 
452   END  SetNetZero;
453 
454 
455 -- ========================================================================
456 -- PROCEDURE BackoutItem
457 -- ========================================================================
458 
459   PROCEDURE  BackoutItem( X_exp_item_id      IN NUMBER
460                         , X_expenditure_id   IN NUMBER
461                         , X_adj_activity     IN VARCHAR2
462                         , X_module           IN VARCHAR2
463                         , X_user             IN NUMBER
464                         , X_login            IN NUMBER
465                         , X_status           OUT NOCOPY NUMBER )
466   IS
467     X_backout_id     NUMBER(15);
468     temp_status      NUMBER DEFAULT NULL;
469     item_comment     VARCHAR2(240);
470 
471   BEGIN
472 
473     X_backout_id := pa_utils.GetNextEiId;
474 
475     INSERT INTO pa_expenditure_items_all(
476          expenditure_item_id
477        , task_id
478        , expenditure_type
479        , system_linkage_function
480        , expenditure_item_date
481        , expenditure_id
482        , override_to_organization_id
483        , last_update_date
484        , last_updated_by
485        , creation_date
486        , created_by
487        , last_update_login
488        , quantity
489        , revenue_distributed_flag
490        , bill_hold_flag
491        , billable_flag
492        , bill_rate_multiplier
493        , cost_distributed_flag
494        , raw_cost
495        , raw_cost_rate
496        , burden_cost
497        , burden_cost_rate
498        , cost_ind_compiled_set_id
499        , non_labor_resource
500        , organization_id
501        , adjusted_expenditure_item_id
502        , net_zero_adjustment_flag
503        , attribute_category
504        , attribute1
505        , attribute2
506        , attribute3
507        , attribute4
508        , attribute5
509        , attribute6
510        , attribute7
511        , attribute8
512        , attribute9
513        , attribute10
514        , transferred_from_exp_item_id
515        , transaction_source
516        , orig_transaction_reference
517        , source_expenditure_item_id
518        , job_id
519        , org_id
520        , labor_cost_multiplier_name
521        , receipt_currency_amount
522        , receipt_currency_code
523        , receipt_exchange_rate
524        , denom_currency_code
525        , denom_raw_cost
526        , denom_burdened_cost
527        , acct_currency_code
528        , acct_rate_date
529        , acct_rate_type
530        , acct_exchange_rate
531        , acct_raw_cost
532        , acct_burdened_cost
533        , acct_exchange_rounding_limit
534        , project_currency_code
535        , project_rate_date
536        , project_rate_type
537        , project_exchange_rate
538        , cc_cross_charge_code
539        , cc_prvdr_organization_id
540        , cc_recvr_organization_id
541        , cc_rejection_code
542        , denom_tp_currency_code
543        , denom_transfer_price
544        , acct_tp_rate_type
545        , acct_tp_rate_date
546        , acct_tp_exchange_rate
547        , acct_transfer_price
548        , projacct_transfer_price
549        , cc_markup_base_code
550        , tp_base_amount
551        , cc_cross_charge_type
552        , recvr_org_id
553        , cc_bl_distributed_code
554        , cc_ic_processed_code
555        , tp_ind_compiled_set_id
556        , tp_bill_rate
557        , tp_bill_markup_percentage
558        , tp_schedule_line_percentage
559        , tp_rule_percentage
560        , cost_job_id
561        , tp_job_id
562        , prov_proj_bill_job_id
563        , assignment_id
564        , work_type_id
565        , projfunc_currency_code
566        , projfunc_cost_rate_date
567        , projfunc_cost_rate_type
568        , projfunc_cost_exchange_rate
569        , project_raw_cost
570        , project_burdened_cost
571        , project_id
572        , project_tp_rate_date
573        , project_tp_rate_type
574        , project_tp_exchange_rate
575        , project_transfer_price
576        , tp_amt_type_code
577 /* inserting cost_burden_distributed_flag for 2661921 */
578        , cost_burden_distributed_flag
579        , capital_event_id
580        , wip_resource_id
581        , inventory_item_id
582        , unit_of_measure
583 /* R12 Changes - Start */
584        , document_header_id
585        , document_distribution_id
586        , document_line_number
587        , document_payment_id
588        , vendor_id
589        , document_type
590        , document_distribution_type )
591 /* R12 Changes - End */
592     SELECT
593           X_backout_id                     -- expenditure_item_id
594        ,  ei.task_id                       -- task_id
595        ,  ei.expenditure_type              -- expenditure_type
596        ,  ei.system_linkage_function       -- system_linkage_function
597        ,  ei.expenditure_item_date         -- expenditure_item_date
598        ,  nvl( X_expenditure_id,
599                 ei.expenditure_id )        -- expenditure_id
600        ,  ei.override_to_organization_id   -- override exp organization
601        ,  sysdate                          -- last_update_date
602        ,  X_user                           -- last_updated_by
603        ,  sysdate                          -- creation_date
604        ,  X_user                           -- created_by
605        ,  X_login                          -- last_update_login
606        ,  (0 - ei.quantity)                -- quantity
607        ,  'N'                              -- revenue_distributed_flag
608        ,  ei.bill_hold_flag                -- bill_hold_flag
609        ,  ei.billable_flag                 -- billable_flag
610        ,  ei.bill_rate_multiplier          -- bill_rate_multiplier
611        ,  'N'                              -- cost_distributed_flag
612        ,  (0 - ei.raw_cost)                -- raw_cost
613        ,  ei.raw_cost_rate                 -- raw_cost_rate
614        ,  (0 - ei.burden_cost)             -- raw_cost
615        ,  ei.burden_cost_rate              -- raw_cost_rate
616        ,  ei.cost_ind_compiled_set_id      -- cost_ind_compiled_set_id
617        ,  ei.non_labor_resource            -- non_labor_resource
618        ,  ei.organization_id               -- organization_id
619        ,  ei.expenditure_item_id           -- adjusted_expenditure_item_id
620        ,  'Y'                              -- net_zero_adjustment_flag
621        ,  ei.attribute_category            -- attribute_category
622        ,  ei.attribute1                    -- attribute1
623        ,  ei.attribute2                    -- attribute2
624        ,  ei.attribute3                    -- attribute3
625        ,  ei.attribute4                    -- attribute4
626        ,  ei.attribute5                    -- attribute5
627        ,  ei.attribute6                    -- attribute6
628        ,  ei.attribute7                    -- attribute7
629        ,  ei.attribute8                    -- attribute8
630        ,  ei.attribute9                    -- attribute9
631        ,  ei.attribute10                   -- attribute10
632        ,  ei.transferred_from_exp_item_id  -- tfr from exp item id
633        ,  ei.transaction_source            -- transaction_source
634        ,  decode(ei.transaction_source,'PTE TIME',NULL,
635           decode(ei.transaction_source,'PTE EXPENSE',NULL,
636 	  decode(ei.transaction_source,'ORACLE TIME AND LABOR',NULL,
637 	  decode(ei.transaction_source,'Oracle Self Service Time',NULL,
638                    ei.orig_transaction_reference)))) -- orig_transaction_reference
639        ,  ei.source_expenditure_item_id    -- source_expenditure_item_id
640        ,  ei.job_id                        -- job_id
641        ,  ei.org_id                        -- org_id
642        ,  ei.labor_cost_multiplier_name    -- labor_cost_multiplier_name
643        , (0 - ei.receipt_currency_amount)  -- receipt_currency_amount
644        ,  ei.receipt_currency_code         -- receipt_currency_code
645        ,  ei.receipt_exchange_rate         -- receipt_exchange_rate
646        ,  ei.denom_currency_code           -- denom_currency_code
647        ,  (0 - ei.denom_raw_cost)          -- denom_raw_cost
648        ,  (0 - ei.denom_burdened_cost)     -- denom_burdened_cost
649        ,  ei.acct_currency_code            -- acct_currency_code
650        ,  ei.acct_rate_date                -- acct_rate_date
651        ,  ei.acct_rate_type                -- acct_rate_type
652        ,  ei.acct_exchange_rate            -- acct_exchange_rate
653        ,  (0 - ei.acct_raw_cost)           -- acct_raw_cost
654        ,  (0 - ei.acct_burdened_cost)      -- acct_burdened_cost
655        ,  ei.acct_exchange_rounding_limit  -- acct_exchange_rounding_limit
656        ,  ei.project_currency_code         -- project_currency_code
657        ,  ei.project_rate_date             -- project_rate_date
658        ,  ei.project_rate_type             -- project_rate_type
659        ,  ei.project_exchange_rate         -- project_exchange_rate
660        ,  ei.cc_cross_charge_code          -- cc_cross_charge_code
661        ,  ei.cc_prvdr_organization_id      -- cc_prvdr_organization_id
662        ,  ei.cc_recvr_organization_id      -- cc_recvr_organization_id
663        ,  ei.cc_rejection_code             -- cc_rejection_code
664        ,  ei.denom_tp_currency_code        -- denom_tp_currency_code
665        ,  (0 - ei.denom_transfer_price)    -- denom_transfer_price
666        ,  ei.acct_tp_rate_type             -- acct_tp_rate_type
667        ,  ei.acct_tp_rate_date             -- acct_tp_rate_date
668        ,  ei.acct_tp_exchange_rate         -- acct_tp_exchange_rate
669        ,  (0 - ei.acct_transfer_price)     -- acct_transfer_price
670        ,  (0 - ei.projacct_transfer_price) -- projacct_transfer_price
671        ,  ei.cc_markup_base_code           -- cc_markup_base_code
672        ,  (0 - ei.tp_base_amount)          -- tp_base_amount
673        ,  ei.cc_cross_charge_type          -- cc_cross_charge_type
674        ,  ei.recvr_org_id                  -- recvr_org_id
675        ,  ei.cc_bl_distributed_code        -- cc_bl_distributed_code
676        ,  ei.cc_ic_processed_code          -- cc_ic_processed_code
677        ,  ei.tp_ind_compiled_set_id        -- tp_ind_compiled_set_id
678        ,  ei.tp_bill_rate                  -- tp_bill_rate
679        ,  ei.tp_bill_markup_percentage     -- tp_bill_markup_percentage
680        ,  ei.tp_schedule_line_percentage   -- tp_schedule_line_percentage
681        ,  ei.tp_rule_percentage            -- tp_rule_percentage
682        ,  ei.cost_job_id                   -- cost_job_id
683        ,  ei.tp_job_id                     -- tp_job_id
684        ,  ei.prov_proj_bill_job_id         -- prov_proj_bill_job_id
685        ,  ei.assignment_id
686        ,  ei.work_type_id
687        ,  ei.projfunc_currency_code
688        ,  ei.projfunc_cost_rate_date
689        ,  ei.projfunc_cost_rate_type
690        ,  ei.projfunc_cost_exchange_rate
691        ,  (0 - ei.project_raw_cost)         -- project raw cost
692        ,  (0 - ei.project_burdened_cost)    -- project burended cost
693        ,  ei.project_id
694        ,  ei.project_tp_rate_date
695        ,  ei.project_tp_rate_type
696        ,  ei.project_tp_exchange_rate
697        ,  (0 - ei.project_transfer_price)
698        ,  ei.tp_amt_type_code
699 /* inserting cost_burden_distributed_flag for 2661921 */
700        ,  decode(ei.cost_ind_compiled_set_id,null,'X','N')
701        ,  capital_event_id
702        , wip_resource_id
703        , inventory_item_id
704        , unit_of_measure
705 /* R12 Changes - Start */
706        ,  ei.document_header_id
707        ,  ei.document_distribution_id
708        ,  ei.document_line_number
709        ,  ei.document_payment_id
710        ,  ei.vendor_id ei_vendor_id
711        ,  ei.document_type
712        ,  ei.document_distribution_type
713 /* R12 Changes - End */
714       FROM
715             pa_expenditure_items_all ei
716      WHERE
717             ei.expenditure_item_id = X_exp_item_id;
718 
719  /* Fix for Bug 3684711 */
720  /* Adding grants integrations to support entry of automatically reversing batches. */
721  IF ( pa_gms_api.vert_install  and x_adj_activity = 'PERIOD-END ACCRUAL REVERSAL' ) THEN
722     /*
723     ** The purpose of the following packet is to create award distribution lines for the
724     ** reversal expenditure item.
725     */
726     gms_awards_dist_pkg.copy_exp_adls( p_exp_item_id     => x_exp_item_id,
727 				       p_backout_item_id => x_backout_id,
728 				       p_adj_activity    => x_adj_activity,
729 				       p_module          => x_module,
730 				       p_user            => x_user,
731 				       p_login           => x_login,
732 				       x_status          => temp_status ) ;
733 
734     CheckStatus( status_indicator => temp_status );
735 
736  END IF ;
737 
738 /* Fix for bug 2211472 */
739 /* Adding the comment of original expenditure_item to the reversed expenditure item
740 and storing it in  pa_expenditure_comments table */
741  BEGIN
742  SELECT
743               ec.expenditure_comment
744         INTO
745               item_comment
746         FROM
747               pa_expenditure_comments ec
748        WHERE
749               ec.expenditure_item_id = X_exp_item_id;
750     EXCEPTION
751       WHEN  NO_DATA_FOUND  THEN
752       NULL;
753  END;
754 
755 
756  IF ( item_comment IS NOT NULL ) THEN
757 
758         pa_transactions.InsItemComment( X_ei_id    => X_backout_id
759                                       , X_ei_comment  =>       item_comment
760                                       , X_user        =>        X_user
761                                       , X_login       =>        X_login
762                                       , X_status      =>        temp_status );
763 
764         CheckStatus( status_indicator => temp_status );
765 
766       END IF;
767 /* End of Fix for bug 2211472 */
768 /*
769       Project Summarization changes:
770       Store the backout_id in the global variable
771      */
772     Pa_Adjustments.BackOutId := X_backout_id;
773 
774     SetNetZero( X_exp_item_id
775               , X_user
776               , X_login
777               , temp_status );
778     CheckStatus( temp_status );
779 
780     InsAuditRec( X_backout_id
781                , X_adj_activity
782                , X_module
783                , X_user
784                , X_login
785                , temp_status
786 	/* R12 Changes Start */
787 	       , G_REQUEST_ID
788                , G_PROGRAM_ID
789 	       , G_PROG_APPL_ID
790 	       , sysdate );
791  	/* R12 Changes End */
792     CheckStatus( temp_status );
793 
794     /* -- MRC Elimination
795     IF ( G_update_mrc_data = 'Y' ) THEN
796 
797        BackOutMrcItem(X_exp_item_id  =>X_exp_item_id,
798                    X_backout_id   => X_backout_id,
799                    X_adj_activity => X_adj_activity,
800                    X_module       => X_module,
801                    X_user         => X_user,
802                    X_login        => X_login,
803                    X_status       => temp_status);
804        CheckStatus(temp_status);
805     END IF;
806     */
807 
808   X_status := 0;
809 
810   EXCEPTION
811     WHEN  OTHERS  THEN
812       X_status := SQLCODE;
813       RAISE;
814 
815   END  BackoutItem;
816 
817 -- ========================================================================
818 -- PROCEDURE BackoutMrcItem
819 -- ========================================================================
820 /*  MRC Elimination
821   PROCEDURE  BackoutMrcItem( X_exp_item_id      IN NUMBER
822                         , X_backout_id       IN NUMBER
823                         , X_adj_activity     IN VARCHAR2
824                         , X_module           IN VARCHAR2
825                         , X_user             IN NUMBER
826                         , X_login            IN NUMBER
827                         , X_status           OUT NOCOPY NUMBER )
828   IS
829     temp_status      NUMBER DEFAULT NULL;
830 
831   BEGIN
832 
833 
834      INSERT into pa_mc_exp_items_all(
835                      SET_OF_BOOKS_ID,
836                      EXPENDITURE_ITEM_ID,
837                      RAW_COST,
838                      RAW_COST_RATE,
839                      BURDEN_COST,
840                      BURDEN_COST_RATE,
841                      NET_ZERO_ADJUSTMENT_FLAG,
842                      TRANSFERRED_FROM_EXP_ITEM_ID,
843                      PRC_ASSIGNMENT_ID,
844                      CURRENCY_CODE,
845                      COST_EXCHANGE_RATE,
846                      COST_CONVERSION_DATE,
847                      COST_RATE_TYPE,
848                      TRANSFER_PRICE,
849                      TP_EXCHANGE_RATE,
850                      TP_CONVERSION_DATE,
851                      TP_RATE_TYPE)
852 
853         SELECT       SET_OF_BOOKS_ID,
854                      X_backout_id,
855                      -1*RAW_COST,
856                      RAW_COST_RATE,
857                      -1*BURDEN_COST,
858                      BURDEN_COST_RATE,
859                      'Y', -- net_zero_adjustment_flag
860                      NULL,-- Transferred_from_expenditure_item_id
861                      PRC_ASSIGNMENT_ID,
862                      CURRENCY_CODE,
863                      COST_EXCHANGE_RATE,
864                      COST_CONVERSION_DATE,
865                      COST_RATE_TYPE,
866                      -1*TRANSFER_PRICE,
867                      TP_EXCHANGE_RATE,
868                      TP_CONVERSION_DATE,
869                      TP_RATE_TYPE
870        FROM pa_mc_exp_items_all
871       WHERE expenditure_item_id = X_exp_item_id;
872 
873   EXCEPTION
874     WHEN  OTHERS  THEN
875       X_status := SQLCODE;
876       RAISE;
877 END BackoutMrcItem;
878 */
879 -- ========================================================================
880 --  PROCEDURE  ReverseRelatedItems
881 -- ========================================================================
882 
883   PROCEDURE  ReverseRelatedItems( X_source_exp_item_id  IN NUMBER
884                                 , X_expenditure_id      IN NUMBER
885                                 , X_module              IN VARCHAR2
886                                 , X_user                IN NUMBER
887                                 , X_login               IN NUMBER
888                                 , X_status              OUT NOCOPY NUMBER )
889   IS
890 
891     temp_status   NUMBER DEFAULT NULL;
892 
893     CURSOR  GetRelatedItems  IS
894       SELECT
895               ei.expenditure_item_id
896         FROM
897               pa_expenditure_items_all ei
898        WHERE
899               ei.source_expenditure_item_id = X_source_exp_item_id
900          AND  nvl(ei.net_zero_adjustment_flag, 'N') <> 'Y';
901 
902   BEGIN
903 
904     FOR  eachRec  IN GetRelatedItems LOOP
905 
906       InsAuditRec( eachRec.expenditure_item_id
907                  , 'RELATED ITEM ORIGINATING'
908                  , X_module
909                  , X_user
910                  , X_login
911                  , temp_status
912 	/* R12 Changes Start */
913 	         , G_REQUEST_ID
914                  , G_PROGRAM_ID
915 	         , G_PROG_APPL_ID
916 	         , sysdate );
917  	/* R12 Changes End */
918       CheckStatus( temp_status );
919 
920 
921       BackoutItem( eachRec.expenditure_item_id
922                  , X_expenditure_id
923                  , 'RELATED ITEM BACK-OUT'
924                  , X_module
925                  , X_user
926                  , X_login
927                  , temp_status );
928       CheckStatus( temp_status );
929 
930 -- ---------------------------------------------------------------------------
931 -- Fix for bug 429816. What was happening is :
932 -- ExpItm   AdjEI   TfrEI   SrcEI   Qty    Raw_Cost
933 -- -------  ------  ------  ------  -----  --------
934 --  1                                5      100
935 --  2                         1      0      20
936 --  3         1                     -5     -100
937 --  4         2               1*     0     -20
938 --
939 --  The problem is that the reversing related item (4) was showing the Original
940 --  item(1) as its SourceEI and not the reversing item(3) as its SourceEI
941 -- ---------------------------------------------------------------------------
942 -- Fix for bug 604023. What was happening is :
943 -- ExpItm   AdjEI   TfrEI   SrcEI   Qty    Raw_Cost
944 -- -------  ------  ------  ------  -----  --------
945 --  1                                5      100
946 --  2                        1       0      20
947 --  (After the 1st transfer)
948 --  3        1                      -5     -100
949 --  4        2               3       0     -20
950 --  5                1               5      100
951 --  6                        5       0      20 (After Distribute Labor)
952 --  (After the 2nd transfer)
953 --  7        3                      -5     -100
954 --  8        4               NULL*   0     -20
955 --  9                5               5      100
956 --  This NULL is populated because the sub-query in the following update checks
957 --  for 'transferred_from _exp_item_id is null'. As a part of the fix removed the
958 --  condition 'ei1.transferred_from_exp_item_id is null' from the where clause
959 --  in the sub-query.
960 --------------------------------------------------------------------------------
961 
962 
963       Update pa_expenditure_items_all ei
964          set ei.source_expenditure_item_id =
965                     (select ei1.expenditure_item_id
966                        from pa_expenditure_items_all ei1
967                       where ei1.adjusted_expenditure_item_id =
968                                                           X_source_exp_item_id)
969        where ei.adjusted_expenditure_item_id = eachRec.expenditure_item_id;
970 
971 -- End Fix--------------------------------------------------------------------
972 
973     END LOOP;
974 
975     X_status := 0;
976 
977     EXCEPTION
978       WHEN  OTHERS  THEN
979         X_status := SQLCODE;
980         RAISE;
981 
982   END  ReverseRelatedItems;
983 
984 -- ========================================================================
985 -- PROCEDURE RecalcRelatedItems
986 -- ========================================================================
987 -- This procedure has been created for Bug # 720199. This will be called by the
988 -- RecalcRev procedure to ensure that the related item also has the revenue distributed
989 -- flag set to 'N' when a relcalc revenue adjustment is done
990 -- Since, the related item adjustment is always done in the background, the number of
991 -- items adjusted is shown as 1 even though in the background, 2 items are adjusted
992 -- the source and the related item.As the user sees only 1 item being adjusted, we
993 -- display the num adjusted successfully as 1
994 
995 -- bug # 900114. Removed code which sets raw cost and cost rate to null
996 -- in this procedure
997 
998      PROCEDURE  RecalcRelatedItems( X_expenditure_item_id  IN NUMBER
999                                   , X_user                 IN NUMBER
1000                                   , X_login                IN NUMBER
1001                                   , X_module               IN VARCHAR2
1002                                   , X_status               OUT NOCOPY NUMBER )
1003      IS
1004 
1005      temp_status         NUMBER DEFAULT NULL;
1006 
1007             CURSOR GetRelatedItems IS
1008          SELECT
1009                  expenditure_item_id
1010            FROM
1011                  pa_expenditure_items_all
1012           WHERE
1013                  source_expenditure_item_id = X_expenditure_item_id;
1014      BEGIN
1015 
1016        FOR eachRec IN GetRelatedItems LOOP
1017 
1018          UPDATE pa_expenditure_items_all
1019             SET
1020                  revenue_distributed_flag = 'N'
1021          ,       last_updated_by = X_user
1022          ,       last_update_date = sysdate
1023          ,       last_update_login = X_login
1024            WHERE
1025              expenditure_item_id = eachRec.expenditure_item_id;
1026 
1027 
1028          pa_adjustments.InsAuditRec( eachRec.expenditure_item_id
1029                                    , 'REVENUE RECALC'
1030                                    , X_module
1031                                    , X_user
1032                                    , X_login
1033                                    , temp_status
1034 				/* R12 Changes Start */
1035 	                           , G_REQUEST_ID
1036           	                   , G_PROGRAM_ID
1037 	                           , G_PROG_APPL_ID
1038 	                           , sysdate );
1039  				/* R12 Changes End */
1040          CheckStatus( temp_status );
1041 
1042        END LOOP;
1043 
1044      X_status := 0;
1045 
1046      EXCEPTION
1047        WHEN  OTHERS  THEN
1048          X_status := SQLCODE;
1049          RAISE;
1050 
1051      END  RecalcRelatedItems;
1052 
1053 
1054 -- ========================================================================
1055 -- PROCEDURE RecalcRev
1056 -- ========================================================================
1057 
1058   PROCEDURE  RecalcRev( ItemsIdTab       IN pa_utils.IdTabTyp
1059                       , AdjustsIdTab     IN pa_utils.IdTabTyp
1060                       , X_user           IN NUMBER
1061                       , X_login          IN NUMBER
1062                       , X_module         IN VARCHAR2
1063                       , rows             IN NUMBER
1064                       , X_status         OUT NOCOPY NUMBER )
1065   IS
1066      temp_status       NUMBER DEFAULT NULL;
1067   BEGIN
1068     FOR i IN 1..rows LOOP
1069 
1070       UPDATE pa_expenditure_items_all ei
1071          SET
1072              ei.revenue_distributed_flag = 'N'
1073       ,      ei.last_update_date = sysdate
1074       ,      ei.last_updated_by = X_user
1075       ,      ei.last_update_login = X_login
1076        WHERE
1077              ei.expenditure_item_id = ItemsIdTab(i);
1078 
1079       InsAuditRec( ItemsIdTab(i)
1080                  , 'REVENUE RECALC'
1081                  , X_module
1082                  , X_user
1083                  , X_login
1084                  , temp_status
1085 	/* R12 Changes Start */
1086 	         , G_REQUEST_ID
1087           	 , G_PROGRAM_ID
1088 	         , G_PROG_APPL_ID
1089 	         , sysdate );
1090  	/* R12 Changes End */
1091       CheckStatus( temp_status );
1092 
1093       IF ( AdjustsIdTab(i) IS NOT NULL ) THEN
1094 
1095         UPDATE pa_expenditure_items_all eia
1096            SET
1097                eia.revenue_distributed_flag = 'N'
1098         ,      eia.last_update_date = sysdate
1099         ,      eia.last_updated_by = X_user
1100         ,      eia.last_update_login = X_login
1101          WHERE
1102                eia.expenditure_item_id = AdjustsIdTab(i);
1103 
1104         InsAuditRec( AdjustsIdTab(i)
1105                    , 'REVENUE RECALC'
1106                    , X_module
1107                    , X_user
1108                    , X_login
1109                    , temp_status
1110 		/* R12 Changes Start */
1111 	           , G_REQUEST_ID
1112           	   , G_PROGRAM_ID
1113 	           , G_PROG_APPL_ID
1114 	           , sysdate );
1115  		/* R12 Changes End */
1116         CheckStatus( temp_status );
1117 
1118       END IF;
1119 -- This part has been added for Bug # 720199. Calls the newly created procedure
1120 -- to set revenue distributed flag to 'N' for related items as well.
1121 
1122       RecalcRelatedItems( ItemsIdTab(i)
1123                         , X_user
1124                         , X_login
1125                         , X_module
1126                         , temp_status );
1127       CheckStatus( temp_status );
1128     END LOOP;
1129 
1130     X_status := 0;
1131 
1132   EXCEPTION
1133     WHEN  OTHERS  THEN
1134       X_status := SQLCODE;
1135       RAISE;
1136 
1137   END  RecalcRev;
1138 
1139 
1140 
1141 -- ========================================================================
1142 -- PROCEDURE RecalcCostRev
1143 -- ========================================================================
1144 
1145   PROCEDURE  RecalcCostRev( ItemsIdTab       IN pa_utils.IdTabTyp
1146                           , AdjustsIdTab     IN pa_utils.IdTabTyp
1147                           , X_user           IN NUMBER
1148                           , X_login          IN NUMBER
1149                           , X_module         IN VARCHAR2
1150                           , rows             IN NUMBER
1151                           , X_num_processed  OUT NOCOPY NUMBER
1152                           , X_status         OUT NOCOPY NUMBER )
1153   IS
1154      temp_status         NUMBER DEFAULT NULL;
1155      item_count          NUMBER := 0;
1156      trx_source_costed   VARCHAR2(1) DEFAULT 'N';
1157      trx_source_accounted VARCHAr2(1) DEFAULT 'N';
1158      trx_source_burden    VARCHAR2(1) DEFAULT 'N';
1159      system_linkage      VARCHAR2(30);
1160 
1161      PROCEDURE  RecalcRelatedItems( X_expenditure_item_id  IN NUMBER
1162                                   , X_user                 IN NUMBER
1163                                   , X_login                IN NUMBER
1164                                   , X_module               IN VARCHAR2
1165                                   , X_status               OUT NOCOPY NUMBER )
1166      IS
1167        CURSOR GetRelatedItems IS
1168          SELECT
1169                  expenditure_item_id
1170            FROM
1171                  pa_expenditure_items_all
1172           WHERE
1173                  source_expenditure_item_id = X_expenditure_item_id;
1174      BEGIN
1175 
1176        FOR eachRec IN GetRelatedItems LOOP
1177 
1178          UPDATE pa_expenditure_items_all
1179             SET
1180                  cost_distributed_flag = 'N'
1181          ,       revenue_distributed_flag = 'N'
1182          ,       denom_raw_cost = NULL
1183          ,       raw_cost_rate = NULL
1184          ,       acct_raw_cost = NULL
1185          ,       raw_cost      = NULL
1186      /* Added denom_currency_code for Bug#2291180 */
1187          ,       denom_currency_code = pa_adjustments.get_denom_curr_code(transaction_source,expenditure_type,denom_currency_code,acct_currency_code,system_linkage_function)
1188          ,       denom_burdened_cost = NULL
1189          ,       acct_burdened_cost = NULL
1190          ,       burden_cost_rate = NULL
1191          ,       burden_cost        = NULL
1192 	 /* Begin Burdening Changes - PA.L */
1193 	 ,       adjustment_type    = 'RECALC_RAW'
1194 	 /* End Burdening Changes - PA.L */
1195 	 ,       project_raw_cost   = NULL
1196          ,       project_burdened_cost = NULL
1197          ,       last_updated_by = X_user
1198          ,       last_update_date = sysdate
1199          ,       last_update_login = X_login
1200            WHERE
1201                  expenditure_item_id = eachRec.expenditure_item_id;
1202 
1203          item_count := item_count + 1;
1204 
1205          pa_adjustments.InsAuditRec( eachRec.expenditure_item_id
1206                                    , 'COST AND REV RECALC'
1207                                    , X_module
1208                                    , X_user
1209                                    , X_login
1210                                    , temp_status
1211 				/* R12 Changes Start */
1212 		 	           , G_REQUEST_ID
1213           	 		   , G_PROGRAM_ID
1214 	                           , G_PROG_APPL_ID
1215 	                           , sysdate );
1216 			 	/* R12 Changes End */
1217          CheckStatus( temp_status );
1218 
1219        END LOOP;
1220 
1221      X_status := 0;
1222 
1223      EXCEPTION
1224        WHEN  OTHERS  THEN
1225          X_status := SQLCODE;
1226          RAISE;
1227 
1228      END  RecalcRelatedItems;
1229 
1230 
1231   BEGIN
1232     FOR i IN 1..rows LOOP
1233 
1234       SELECT
1235               nvl( txs.costed_flag, 'N' )
1236       ,       nvl(txs.gl_accounted_flag,'N')
1237       ,       nvl(txs.allow_burden_flag, 'N')
1238       ,       ei.system_linkage_function INTO
1239               trx_source_costed
1240       ,       trx_source_accounted
1241       ,       trx_source_burden
1242       ,       system_linkage
1243         FROM
1244               pa_expenditure_items_all ei
1245       ,       pa_transaction_sources txs
1246        WHERE
1247               ei.transaction_source = txs.transaction_source(+)
1248          AND  ei.expenditure_item_id = ItemsIdTab(i);
1249 
1250 /* R12 Changes - Added system linkage ER in addition to VI. In R12, users
1251                  cannot create Expense Reports in Projects. The following change
1252                  will prohibit the user from recalculating cost for historical
1253                  Expense Reports created in Projects */
1254       UPDATE pa_expenditure_items_all ei
1255          SET
1256              ei.cost_distributed_flag = 'N'
1257        /*  Reverted: Added for bug #2027985
1258              decode( system_linkage, 'VI', ei.cost_distributed_flag,
1259                                      'ER', ei.cost_distributed_flag,
1260               decode( trx_source_costed, 'N', 'N', ei.cost_distributed_flag ) )
1261         End of fix for #2027985 */
1262       ,      ei.revenue_distributed_flag = 'N'
1263       ,      ei.denom_raw_cost =
1264                decode( system_linkage, 'VI', ei.denom_raw_cost,
1265                                        'ER', ei.denom_raw_cost,
1266                   decode( trx_source_costed, 'N', NULL, ei.denom_raw_cost ) )
1267       ,      ei.raw_cost_rate =
1268                decode( system_linkage, 'VI', ei.raw_cost_rate,
1269                                        'ER', ei.raw_cost_rate,
1270                   decode( trx_source_costed, 'N', NULL, ei.raw_cost_rate ) )
1271       ,      ei.acct_raw_cost =
1272                decode( system_linkage, 'VI', ei.acct_raw_cost,
1273                                        'ER', ei.acct_raw_cost, /* Bug 5191357 */
1274                  decode( trx_source_accounted, 'N', NULL, ei.acct_raw_cost) )
1275       ,      ei.raw_cost = NULL
1276       ,      ei.denom_burdened_cost = decode( trx_source_burden, 'N',
1277                   decode(system_linkage, 'BTC', ei.denom_burdened_cost,  NULL),decode(getprojburdenflag(ei.project_id),'N',NULL,ei.denom_burdened_cost) ) /*Added for bug:7157616*/
1278      /* Added denom_currency_code for Bug#2291180 */
1279       ,      ei.denom_currency_code = pa_adjustments.get_denom_curr_code(ei.transaction_source,ei.expenditure_type, ei.denom_currency_code, ei.acct_currency_code, ei.system_linkage_function)
1280       ,      ei.acct_burdened_cost =  NULL
1281       ,      ei.burden_cost_rate = NULL
1282       ,      ei.burden_cost = NULL
1283       /* Begin Burdening Changes - PA.L */
1284       ,      ei.adjustment_type = 'RECALC_RAW'
1285       /* End Burdening Changes - PA.L */
1286       ,      ei.project_raw_cost  =  NULL
1287       ,      ei.project_burdened_cost  =  NULL
1288       ,      ei.last_update_date = sysdate
1289       ,      ei.last_updated_by = X_user
1290       ,      ei.last_update_login = X_login
1291        WHERE
1292              ei.expenditure_item_id = ItemsIdTab(i);
1293 
1294       item_count := item_count + 1;
1295 
1296       InsAuditRec( ItemsIdTab(i)
1297                  , 'COST AND REV RECALC'
1298                  , X_module
1299                  , X_user
1300                  , X_login
1301                  , temp_status
1302 	/* R12 Changes Start */
1303 	         , G_REQUEST_ID
1304           	 , G_PROGRAM_ID
1305 	         , G_PROG_APPL_ID
1306 	         , sysdate );
1307  	/* R12 Changes End */
1308       CheckStatus( temp_status );
1309 
1310       IF ( AdjustsIdTab(i) IS NOT NULL ) THEN
1311 
1312         UPDATE pa_expenditure_items_all ei
1313            SET
1314                ei.cost_distributed_flag = 'N'
1315        /*  Reverted : Added for bug #2027985
1316              decode( system_linkage, 'VI', ei.cost_distributed_flag,
1317                                      'ER', ei.cost_distributed_flag,
1318               decode( trx_source_costed, 'N', 'N', ei.cost_distributed_flag ) )
1319         End of fix for #2027985 */
1320         ,      ei.revenue_distributed_flag = 'N'
1321         ,      ei.denom_raw_cost =
1322                  decode( system_linkage, 'VI', ei.denom_raw_cost,
1323                                          'ER', ei.denom_raw_cost,
1324                   decode( trx_source_costed, 'N', NULL, ei.denom_raw_cost ) )
1325         ,      ei.raw_cost_rate =
1326                  decode( system_linkage, 'VI', ei.raw_cost_rate,
1327                                          'ER', ei.raw_cost_rate,
1328                   decode( trx_source_costed, 'N', NULL, ei.raw_cost_rate ) )
1329         ,      ei.acct_raw_cost =
1330                  decode( system_linkage, 'VI', ei.acct_raw_cost,
1331                                          'ER', ei.acct_raw_cost,
1332                   decode( trx_source_accounted, 'N', NULL, ei.acct_raw_cost ) )
1333         ,      ei.raw_cost = NULL
1334         ,     ei.denom_burdened_cost =
1335              decode( trx_source_burden, 'N', NULL, decode(getprojburdenflag(ei.project_id),'N',NULL,ei.denom_burdened_cost) ) /*Added for bug:7157616*/
1336      /* Added denom_currency_code for Bug#2291180 */
1337       ,      ei.denom_currency_code = pa_adjustments.get_denom_curr_code(ei.transaction_source,ei.expenditure_type, ei.denom_currency_code, ei.acct_currency_code, ei.system_linkage_function)
1338         ,      ei.acct_burdened_cost = NULL
1339         ,      ei.burden_cost_rate = NULL
1340         ,      ei.burden_cost = NULL
1341         ,      ei.project_burdened_cost = NULL
1342         ,      ei.project_raw_cost = NULL
1343         ,      ei.last_update_date = sysdate
1344         ,      ei.last_updated_by = X_user
1345         ,      ei.last_update_login = X_login
1346            WHERE
1347                  ei.expenditure_item_id = AdjustsIdTab(i);
1348 
1349         item_count := item_count + 1;
1350 
1351         InsAuditRec( AdjustsIdTab(i)
1352                    , 'COST AND REV RECALC'
1353                    , X_module
1354                    , X_user
1355                    , X_login
1356                    , temp_status
1357 	/* R12 Changes Start */
1358 	         , G_REQUEST_ID
1359           	 , G_PROGRAM_ID
1360 	         , G_PROG_APPL_ID
1361 	         , sysdate );
1362  	/* R12 Changes End */
1363         CheckStatus( temp_status );
1364 
1365       END IF;
1366 
1367       RecalcRelatedItems( ItemsIdTab(i)
1368                         , X_user
1369                         , X_login
1370                         , X_module
1371                         , temp_status );
1372       CheckStatus( temp_status );
1373 
1374     END LOOP;
1375 
1376     X_status := 0;
1377     X_num_processed := item_count;
1378   EXCEPTION
1379     WHEN  OTHERS  THEN
1380       X_status := SQLCODE;
1381       RAISE;
1382 
1383   END  RecalcCostRev;
1384 
1385 
1386 
1387 -- ========================================================================
1388 -- PROCEDURE RecalcIndCost
1389 -- ========================================================================
1390 
1391   PROCEDURE  RecalcIndCost( ItemsIdTab          IN pa_utils.IdTabTyp
1392                           , AdjustsIdTab       IN pa_utils.IdTabTyp
1393                           , X_user           IN NUMBER
1394                           , X_login          IN NUMBER
1395                           , X_module         IN VARCHAR2
1396                           , rows             IN BINARY_INTEGER
1397                           , X_status         OUT NOCOPY NUMBER )
1398   IS
1399      temp_status          NUMBER DEFAULT NULL;
1400      trx_source_burden    VARCHAR2(1) DEFAULT 'N';
1401      system_linkage       VARCHAR2(30);
1402 
1403   BEGIN
1404     FOR i IN 1..rows LOOP
1405 
1406       SELECT
1407              nvl(txs.allow_burden_flag, 'N'),
1408              ei.system_linkage_function
1409       INTO
1410              trx_source_burden,
1411              system_linkage
1412       FROM
1413               pa_expenditure_items_all ei
1414       ,       pa_transaction_sources txs
1415        WHERE
1416               ei.transaction_source = txs.transaction_source(+)
1417       AND  ei.expenditure_item_id = ItemsIdTab(i);
1418 
1419 	-- Added the Decode function for the acct_burdened_cost,burden_cost_rate,burden_cost
1420 	-- to fix the bug fix : 1490316
1421 
1422        UPDATE pa_expenditure_items_all ei
1423          SET
1424              ei.cost_distributed_flag = 'N'
1425       ,      ei.denom_burdened_cost =
1426              decode( trx_source_burden, 'N',
1427                   decode(system_linkage, 'BTC', ei.denom_burdened_cost,  NULL), ei.denom_burdened_cost )
1428       ,      ei.acct_burdened_cost =
1429              decode( trx_source_burden, 'N',
1430                   decode(system_linkage, 'BTC', ei.acct_burdened_cost ,NULL),ei.acct_burdened_cost)
1431       ,      ei.burden_cost_rate =
1432              decode( trx_source_burden, 'N',
1433                   decode(system_linkage, 'BTC',ei.burden_cost_rate ,NULL),ei.burden_cost_rate)
1434       ,      ei.burden_cost =
1435              decode( trx_source_burden, 'N',
1436                   decode(system_linkage, 'BTC',ei.burden_cost,NULL),ei.burden_cost)
1437       ,      ei.project_burdened_cost =
1438              decode( trx_source_burden, 'N',
1439                   decode(system_linkage, 'BTC',ei.project_burdened_cost,NULL),ei.project_burdened_cost)
1440       /* Begin Burdening Changes - PA.L */
1441       ,      ei.adjustment_type = decode(ei.adjustment_type, 'RECALC_RAW', ei.adjustment_type
1442                                     , decode(ei.system_linkage_function, 'BTC', 'RECALC_RAW', 'RECALC_BURDEN'))
1443       /* End Burdening Changes - PA.L */
1444       ,      ei.last_update_date = sysdate
1445       ,      ei.last_updated_by = X_user
1446       ,      ei.last_update_login = X_login
1447        WHERE
1448              ei.expenditure_item_id = ItemsIdTab(i);
1449 
1450       InsAuditRec( ItemsIdTab(i)
1451                  , 'INDIRECT COST RECALC'
1452                  , X_module
1453                  , X_user
1454                  , X_login
1455                  , temp_status
1456 	/* R12 Changes Start */
1457 	         , G_REQUEST_ID
1458           	 , G_PROGRAM_ID
1459 	         , G_PROG_APPL_ID
1460 	         , sysdate );
1461  	/* R12 Changes End */
1462       CheckStatus( temp_status );
1463 
1464       IF ( AdjustsIdTab(i) IS NOT NULL ) THEN
1465 
1466         UPDATE pa_expenditure_items_all eia
1467            SET
1468                eia.cost_distributed_flag = 'N'
1469         ,      eia.denom_burdened_cost =
1470                decode( trx_source_burden, 'N', NULL, eia.denom_burdened_cost )
1471         ,      eia.acct_burdened_cost =  NULL
1472         ,      eia.burden_cost_rate = NULL
1473         ,      eia.burden_cost = NULL
1474         ,      eia.project_burdened_cost = NULL
1475         ,      eia.last_update_date = sysdate
1476         ,      eia.last_updated_by = X_user
1477         ,      eia.last_update_login = X_login
1478          WHERE
1479                eia.expenditure_item_id = AdjustsIdTab(i);
1480 
1481         InsAuditRec( AdjustsIdTab(i)
1482                    , 'INDIRECT COST RECALC'
1483                    , X_module
1484                    , X_user
1485                    , X_login
1486                    , temp_status
1487 	/* R12 Changes Start */
1488 	         , G_REQUEST_ID
1489           	 , G_PROGRAM_ID
1490 	         , G_PROG_APPL_ID
1491 	         , sysdate );
1492  	/* R12 Changes End */
1493         CheckStatus( temp_status );
1494 
1495       END IF;
1496     END LOOP;
1497 
1498     X_status := 0;
1499 
1500   EXCEPTION
1501     WHEN  OTHERS  THEN
1502       X_status := SQLCODE;
1503       RAISE;
1504 
1505   END  RecalcIndCost;
1506 
1507 
1508 -- ========================================================================
1509 -- PROCEDURE RecalcRawCost
1510 -- ========================================================================
1511 
1512   -- This is the exact same procedure as RecalcCostRev, except it
1513   -- inserts the action 'RAW COST RECALC' into the adjustment activity
1514   -- table, instead of 'COST AND REV RECALC'.  Used for indirect and
1515   -- capital (v4.0) projects, where the latter action would not make sense.
1516 
1517   PROCEDURE  RecalcRawCost( ItemsIdTab       IN pa_utils.IdTabTyp
1518                           , AdjustsIdTab     IN pa_utils.IdTabTyp
1519                           , X_user           IN NUMBER
1520                           , X_login          IN NUMBER
1521                           , X_module         IN VARCHAR2
1522                           , rows             IN NUMBER
1523                           , X_num_processed  OUT NOCOPY NUMBER
1524                           , X_status         OUT NOCOPY NUMBER )
1525   IS
1526      temp_status         NUMBER DEFAULT NULL;
1527      item_count          NUMBER := 0;
1528      trx_source_costed   VARCHAR2(1) DEFAULT 'N';
1529      trx_source_accounted VARCHAR2(1) DEFAULT 'N';
1530      trx_source_burden    VARCHAR2(1) DEFAULT 'N';
1531      system_linkage      VARCHAR2(30);
1532 
1533      PROCEDURE  RecalcRelatedItems( X_expenditure_item_id  IN NUMBER
1534                                   , X_user                 IN NUMBER
1535                                   , X_login                IN NUMBER
1536                                   , X_module               IN VARCHAR2
1537                                   , X_status               OUT NOCOPY NUMBER )
1538      IS
1539        CURSOR GetRelatedItems IS
1540          SELECT
1541                  expenditure_item_id
1542            FROM
1543                  pa_expenditure_items_all
1544           WHERE
1545                  source_expenditure_item_id = X_expenditure_item_id;
1546      BEGIN
1547 
1548        FOR eachRec IN GetRelatedItems LOOP
1549 
1550          UPDATE pa_expenditure_items_all
1551             SET
1552                  cost_distributed_flag = 'N'
1553          ,       revenue_distributed_flag = 'N'
1554          ,       denom_raw_cost = NULL
1555          ,       acct_raw_cost = NULL
1556          ,       raw_cost = NULL
1557          ,       raw_cost_rate = NULL
1558      /* Added denom_currency_code for Bug#2291180 */
1559         ,        denom_currency_code = pa_adjustments.get_denom_curr_code(transaction_source,expenditure_type,denom_currency_code,acct_currency_code,system_linkage_function)
1560          ,       denom_burdened_cost = NULL
1561          ,       acct_burdened_cost = NULL
1562          ,       burden_cost_rate = NULL
1563          ,       burden_cost        = NULL
1564 	 /* Begin Burdening Changes - PA.L */
1565 	 ,       adjustment_type    = 'RECALC_RAW'
1566 	 /* End Burdening Changes - PA.L */
1567          ,       project_raw_cost  = NULL
1568          ,       project_burdened_cost  = NULL
1569          ,       last_updated_by = X_user
1570          ,       last_update_date = sysdate
1571          ,       last_update_login = X_login
1572            WHERE
1573                  expenditure_item_id = eachRec.expenditure_item_id;
1574 
1575          item_count := item_count + 1;
1576 
1577          pa_adjustments.InsAuditRec( eachRec.expenditure_item_id
1578                                    , 'RAW COST RECALC'
1579                                    , X_module
1580                                    , X_user
1581                                    , X_login
1582                                    , temp_status
1583 				/* R12 Changes Start */
1584 	                           , G_REQUEST_ID
1585           	                   , G_PROGRAM_ID
1586 	                           , G_PROG_APPL_ID
1587 	                           , sysdate );
1588  				/* R12 Changes End */
1589          CheckStatus( temp_status );
1590 
1591        END LOOP;
1592 
1593      X_status := 0;
1594 
1595      EXCEPTION
1596        WHEN  OTHERS  THEN
1597          X_status := SQLCODE;
1598          RAISE;
1599 
1600      END  RecalcRelatedItems;
1601 
1602 
1603   BEGIN
1604     FOR i IN 1..rows LOOP
1605 
1606       SELECT
1607               nvl( txs.costed_flag, 'N' )
1608       ,       nvl(txs.gl_accounted_flag,'N')
1609       ,       nvl(txs.allow_burden_flag, 'N')
1610       ,       ei.system_linkage_function
1611         INTO
1612               trx_source_costed
1613       ,       trx_source_accounted
1614       ,       trx_source_burden
1615       ,       system_linkage
1616         FROM
1617               pa_expenditure_items_all ei
1618       ,       pa_transaction_sources txs
1619        WHERE
1620               ei.transaction_source = txs.transaction_source(+)
1621          AND  ei.expenditure_item_id = ItemsIdTab(i);
1622 
1623 /* R12 Changes - Added system linkage ER in addition to VI. In R12, users
1624                  cannot create Expense Reports in Projects. The following change
1625                  will prohibit the user from recalculating cost for historical
1626                  Expense Reports created in Projects */
1627       UPDATE pa_expenditure_items_all ei
1628          SET
1629              ei.cost_distributed_flag = 'N'
1630        /* Reverted: Added for bug #2027985
1631              decode( system_linkage, 'VI', ei.cost_distributed_flag,
1632                                      'ER', ei.cost_distributed_flag,
1633               decode( trx_source_costed, 'N', 'N', ei.cost_distributed_flag ) )
1634         End of fix for #2027985 */
1635       ,      ei.revenue_distributed_flag = 'N'
1636       ,      ei.denom_raw_cost =
1637                decode( system_linkage, 'VI', ei.denom_raw_cost,
1638                                        'ER', ei.denom_raw_cost,
1639                   decode( trx_source_costed, 'N', NULL, ei.denom_raw_cost ) )
1640       ,      ei.raw_cost_rate =
1641                decode( system_linkage, 'VI', ei.raw_cost_rate,
1642                                        'ER', ei.raw_cost_rate,
1643                   decode( trx_source_costed, 'N', NULL, ei.raw_cost_rate ) )
1644       ,      ei.acct_raw_cost =
1645                decode( system_linkage, 'VI', ei.acct_raw_cost,
1646                                        'ER', ei.acct_raw_cost,
1647                   decode( trx_source_accounted, 'N', NULL, ei.acct_raw_cost ) )
1648       ,      ei.raw_cost = NULL
1649       ,       ei.denom_burdened_cost =decode( trx_source_burden, 'N',
1650                   decode(system_linkage, 'BTC', ei.denom_burdened_cost,  NULL)
1651                           ,decode(getprojburdenflag(ei.project_id),'N',NULL,ei.denom_burdened_cost))  /*added for bug:7157616*/
1652      /* Added denom_currency_code for Bug#2291180 */
1653       ,      ei.denom_currency_code = pa_adjustments.get_denom_curr_code(ei.transaction_source,ei.expenditure_type, ei.denom_currency_code, ei.acct_currency_code, ei.system_linkage_function)
1654       ,      ei.acct_burdened_cost = NULL
1655       ,      ei.burden_cost_rate = NULL
1656       ,      ei.burden_cost = NULL
1657       /* Begin Burdening Changes - PA.L */
1658       ,      ei.adjustment_type = 'RECALC_RAW'
1659       /* End Burdening Changes - PA.L */
1660       ,      ei.project_raw_cost = null
1661       ,      ei.project_burdened_cost  =  null
1662       ,      ei.last_update_date = sysdate
1663       ,      ei.last_updated_by = X_user
1664       ,      ei.last_update_login = X_login
1665        WHERE
1666              ei.expenditure_item_id = ItemsIdTab(i);
1667 
1668       item_count := item_count + 1;
1669 
1670       InsAuditRec( ItemsIdTab(i)
1671                  , 'RAW COST RECALC'
1672                  , X_module
1673                  , X_user
1674                  , X_login
1675                  , temp_status
1676 	/* R12 Changes Start */
1677 	         , G_REQUEST_ID
1678           	 , G_PROGRAM_ID
1679 	         , G_PROG_APPL_ID
1680 	         , sysdate );
1681  	/* R12 Changes End */
1682       CheckStatus( temp_status );
1683 
1684       IF ( AdjustsIdTab(i) IS NOT NULL ) THEN
1685 
1686         UPDATE pa_expenditure_items_all ei
1687            SET
1688                ei.cost_distributed_flag ='N'
1689        /* Reverted: Added for bug #2027985
1690              decode( system_linkage, 'VI', ei.cost_distributed_flag,
1691                                      'ER', ei.cost_distributed_flag,
1692               decode( trx_source_costed, 'N', 'N', ei.cost_distributed_flag ) )
1693         End of fix for #2027985 */
1694         ,      ei.revenue_distributed_flag = 'N'
1695         ,      ei.denom_raw_cost =
1696                  decode( system_linkage, 'VI', ei.denom_raw_cost,
1697                                          'ER', ei.denom_raw_cost,
1698                   decode( trx_source_costed, 'N', NULL, ei.denom_raw_cost ) )
1699         ,      ei.raw_cost_rate =
1700                  decode( system_linkage, 'VI', ei.raw_cost_rate,
1701                                          'ER', ei.raw_cost_rate,
1702                   decode( trx_source_costed, 'N', NULL, ei.raw_cost_rate ) )
1703         ,      ei.acct_raw_cost =
1704                  decode( system_linkage, 'VI', ei.acct_raw_cost,
1705                                          'ER', ei.acct_raw_cost,
1706                   decode( trx_source_accounted, 'N', NULL, ei.acct_raw_cost ) )
1707         ,      ei.denom_burdened_cost =
1708              decode( trx_source_burden, 'N', NULL, decode(getprojburdenflag(ei.project_id),'N',NULL,ei.denom_burdened_cost) ) /*added for bug:7157616*/
1709      /* Added denom_currency_code for Bug#2291180 */
1710         ,      ei.denom_currency_code = pa_adjustments.get_denom_curr_code(ei.transaction_source,ei.expenditure_type, ei.denom_currency_code, ei.acct_currency_code, ei.system_linkage_function)
1711         ,      ei.acct_burdened_cost = NULL
1712         ,      ei.burden_cost_rate = NULL
1713         ,      ei.burden_cost = NULL
1714         ,      ei.raw_cost = NULL
1715         ,      ei.project_burdened_cost  =  null
1716         ,      ei.project_raw_cost  =  null
1717         ,      ei.last_update_date = sysdate
1718         ,      ei.last_updated_by = X_user
1719         ,      ei.last_update_login = X_login
1720            WHERE
1721                  ei.expenditure_item_id = AdjustsIdTab(i);
1722 
1723         item_count := item_count + 1;
1724 
1725         InsAuditRec( AdjustsIdTab(i)
1726                    , 'RAW COST RECALC'
1727                    , X_module
1728                    , X_user
1729                    , X_login
1730                    , temp_status
1731 	/* R12 Changes Start */
1732 	         , G_REQUEST_ID
1733           	 , G_PROGRAM_ID
1734 	         , G_PROG_APPL_ID
1735 	         , sysdate );
1736  	/* R12 Changes End */
1737         CheckStatus( temp_status );
1738 
1739       END IF;
1740 
1741       RecalcRelatedItems( ItemsIdTab(i)
1742                         , X_user
1743                         , X_login
1744                         , X_module
1745                         , temp_status );
1746       CheckStatus( temp_status );
1747 
1748     END LOOP;
1749 
1750     X_status := 0;
1751     X_num_processed := item_count;
1752 
1753   EXCEPTION
1754     WHEN  OTHERS  THEN
1755       X_status := SQLCODE;
1756       RAISE;
1757 
1758   END  RecalcRawCost;
1759 
1760 
1761 -- ========================================================================
1762 -- PROCEDURE RecalcCapCost
1763 -- ========================================================================
1764 
1765   -- This is the exact same as RecalcIndCost, except it also sets the
1766   -- revenue_distributed_flag to 'N'.  Used for expenditure items
1767   -- belonging to CAPITAL projects (v4.0).
1768 
1769   PROCEDURE  RecalcCapCost( ItemsIdTab          IN pa_utils.IdTabTyp
1770                           , AdjustsIdTab       IN pa_utils.IdTabTyp
1771                           , X_user           IN NUMBER
1772                           , X_login          IN NUMBER
1773                           , X_module         IN VARCHAR2
1774                           , rows             IN BINARY_INTEGER
1775                           , X_status         OUT NOCOPY NUMBER )
1776   IS
1777      temp_status       NUMBER DEFAULT NULL;
1778      trx_source_burden    VARCHAR2(1) DEFAULT 'N';
1779      system_linkage      VARCHAR2(30);
1780 
1781   BEGIN
1782     FOR i IN 1..rows LOOP
1783 
1784         SELECT
1785              nvl(txs.allow_burden_flag, 'N'),
1786              ei.system_linkage_function
1787         INTO
1788              trx_source_burden,
1789              system_linkage
1790         FROM
1791               pa_expenditure_items_all ei
1792       ,       pa_transaction_sources txs
1793        WHERE
1794               ei.transaction_source = txs.transaction_source(+)
1795        AND  ei.expenditure_item_id = ItemsIdTab(i);
1796 
1797 	--- Added the decode function for the following columns acct_burdened_cost,burden_cost_rate,
1798 	--- burden_cost as a bug fix : 1490316, it enables to recalc BTC ei only for the accounting
1799 	--- purpose.
1800 
1801       UPDATE pa_expenditure_items_all ei
1802          SET
1803              ei.cost_distributed_flag = 'N'
1804       ,      ei.revenue_distributed_flag = 'N'
1805       ,      ei.denom_burdened_cost =
1806              decode( trx_source_burden, 'N',
1807                   decode(system_linkage, 'BTC', ei.denom_burdened_cost,  NULL), ei.denom_burdened_cost )
1808       ,      ei.acct_burdened_cost =
1809              decode( trx_source_burden, 'N',
1810                   decode(system_linkage, 'BTC', ei.acct_burdened_cost,NULL), ei.acct_burdened_cost )
1811       ,      ei.burden_cost_rate =
1812              decode( trx_source_burden, 'N',
1813                   decode(system_linkage, 'BTC', ei.burden_cost_rate , NULL),  ei.burden_cost_rate )
1814       ,      ei.burden_cost =
1815              decode( trx_source_burden, 'N',
1816                   decode(system_linkage, 'BTC',ei.burden_cost , NULL ),ei.burden_cost )
1817       ,      ei.project_burdened_cost =
1818              decode( trx_source_burden, 'N',
1819                   decode(system_linkage, 'BTC',ei.project_burdened_cost , NULL ),ei.project_burdened_cost )
1820       /* Begin Burdening Changes - PA.L */
1821       ,      ei.adjustment_type = decode(ei.adjustment_type, 'RECALC_RAW', ei.adjustment_type
1822                                       , decode(ei.system_linkage_function, 'BTC', 'RECALC_BURDEN'))
1823       /* End Burdening Changes - PA.L */
1824       ,      ei.last_update_date = sysdate
1825       ,      ei.last_updated_by = X_user
1826       ,      ei.last_update_login = X_login
1827        WHERE
1828              ei.expenditure_item_id = ItemsIdTab(i);
1829 
1830       InsAuditRec( ItemsIdTab(i)
1831                  , 'INDIRECT COST RECALC'
1832                  , X_module
1833                  , X_user
1834                  , X_login
1835                  , temp_status
1836 	/* R12 Changes Start */
1837 	         , G_REQUEST_ID
1838           	 , G_PROGRAM_ID
1839 	         , G_PROG_APPL_ID
1840 	         , sysdate );
1841  	/* R12 Changes End */
1842       CheckStatus( temp_status );
1843 
1844       IF ( AdjustsIdTab(i) IS NOT NULL ) THEN
1845 
1846         UPDATE pa_expenditure_items_all eia
1847            SET
1848                eia.cost_distributed_flag = 'N'
1849         ,      eia.denom_burdened_cost =
1850                decode( trx_source_burden, 'N', NULL, eia.denom_burdened_cost )
1851         ,      eia.acct_burdened_cost =  NULL
1852         ,      eia.burden_cost_rate = NULL
1853         ,      eia.burden_cost = NULL
1854         ,      eia.project_burdened_cost = NULL
1855         ,      eia.last_update_date = sysdate
1856         ,      eia.last_updated_by = X_user
1857         ,      eia.last_update_login = X_login
1858          WHERE
1859                eia.expenditure_item_id = AdjustsIdTab(i);
1860 
1861         InsAuditRec( AdjustsIdTab(i)
1862                    , 'INDIRECT COST RECALC'
1863                    , X_module
1864                    , X_user
1865                    , X_login
1866                    , temp_status
1867 	/* R12 Changes Start */
1868 	           , G_REQUEST_ID
1869             	   , G_PROGRAM_ID
1870 	           , G_PROG_APPL_ID
1871 	           , sysdate );
1872  	/* R12 Changes End */
1873         CheckStatus( temp_status );
1874 
1875       END IF;
1876     END LOOP;
1877 
1878     X_status := 0;
1879 
1880   EXCEPTION
1881     WHEN  OTHERS  THEN
1882       X_status := SQLCODE;
1883       RAISE;
1884 
1885   END  RecalcCapCost;
1886 
1887 
1888 --   Fix for Bug # 553129. dhituval on 27-APR
1889 --====================================================================
1890 -- Function GetInvId
1891 --====================================================================
1892 
1893  FUNCTION GetInvId(X_expenditure_item_id NUMBER) return VARCHAR2 is
1894 
1895  v_system_reference2  VARCHAR2(30);
1896  v_exp_item_id        NUMBER;
1897 
1898  CURSOR c2 is
1899 
1900  select expenditure_item_id
1901  from pa_expenditure_items_all peia
1902  where  exists( select null
1903                from pa_cost_distribution_lines_all cdl
1904                where cdl.expenditure_item_id = peia.expenditure_item_id)
1905  start with expenditure_item_id = X_expenditure_item_id
1906  connect by prior transferred_from_exp_item_id = expenditure_item_id ;
1907 
1908  BEGIN
1909 
1910  for rec in c2 LOOP
1911 
1912  select system_reference2 into v_system_reference2
1913  from pa_cost_distribution_lines_all
1914  where expenditure_item_id = rec.expenditure_item_id
1915  and  line_num_reversed is null
1916  and  reversed_flag is null
1917  and  line_type = 'R';
1918 
1919  END LOOP;
1920 
1921  return v_system_reference2;
1922 
1923  end GetInvId;
1924 
1925 
1926 --=======================================================================
1927 -- Function InvStatus
1928 --=======================================================================
1929 /* R12 changes */
1930    FUNCTION InvStatus( X_system_reference2  VARCHAR2
1931                      , X_system_linkage_function VARCHAR2)
1932    return VARCHAR2 is
1933 
1934 -- to check if invoice is cancelled or paid
1935 CURSOR check_inv_cur(p_invoice_id NUMBER) is
1936 SELECT CANCELLED_DATE,
1937        CANCELLED_BY
1938 FROM   ap_invoices_all
1939 WHERE  invoice_id = p_invoice_id
1940 FOR UPDATE OF INVOICE_ID NOWAIT;
1941 -- to lock the invoice during validation
1942 
1943 l_cancelled_date DATE;
1944 l_cancelled_by NUMBER;
1945 
1946    X_error_code  VARCHAR2(30);
1947 
1948    Resource_busy EXCEPTION ;
1949    PRAGMA EXCEPTION_INIT(Resource_busy,-00054) ;
1950 
1951    BEGIN
1952 
1953 	X_error_code := 'N';
1954 
1955         SAVEPOINT AP_PA_REL_LOCK;
1956         OPEN check_inv_cur(X_system_reference2);
1957         FETCH check_inv_cur
1958          INTO l_cancelled_date
1959              ,l_cancelled_by;
1960         CLOSE check_inv_cur;
1961 
1962 /* check if invoice is cancelled (l_cancelled_date or l_cancelled_by is NOT NULL),
1963    this check will not be done if the adjustment action is BILLABLE/NON-BILLABLE */
1964         IF  (l_cancelled_date IS NOT NULL
1965         OR  l_cancelled_by IS NOT NULL) THEN
1966           X_Error_code := 'PA_INV_CANCELLED';
1967         END IF;
1968 
1969 /* Release lock if adjustment is not allowed on expenditure item for this invoice */
1970         IF X_error_code <> 'N' THEN
1971           ROLLBACK to AP_PA_REL_LOCK;
1972         END IF;
1973         RETURN X_error_code;
1974 
1975   EXCEPTION
1976     when Resource_busy then
1977       IF x_system_linkage_function = 'VI' THEN
1978         X_error_code := 'PA_ADJ_INV_OPEN_IN_AP';
1979       ELSE /* must be ER */
1980         X_error_code := 'PA_ADJ_ER_OPEN_IN_AP';
1981       END IF;
1982       RETURN X_error_code ;
1983     RAISE ;
1984     when others then
1985     RAISE;
1986 
1987  END InvStatus;
1988 
1989 
1990 -- ========================================================================
1991 -- PROCEDURE Hold
1992 -- ========================================================================
1993 
1994   PROCEDURE  Hold( ItemsIdTab        IN pa_utils.IdTabTyp
1995                  , AdjustsIdTab     IN pa_utils.IdTabTyp
1996                  , X_hold         IN VARCHAR2
1997                  , X_adj_activity IN VARCHAR2
1998                  , X_user         IN NUMBER
1999                  , X_login        IN NUMBER
2000                  , X_module       IN VARCHAR2
2001                  , rows           IN BINARY_INTEGER
2002                  , X_status       OUT NOCOPY NUMBER )
2003   IS
2004     temp_status      NUMBER DEFAULT NULL;
2005   BEGIN
2006 
2007     FOR i IN 1..rows LOOP
2008 
2009       UPDATE pa_expenditure_items_all ei
2010          SET
2011               ei.bill_hold_flag           = X_hold
2012       ,       ei.last_updated_by          = X_user
2013       ,       ei.last_update_date         = sysdate
2014       ,       ei.last_update_login        = X_login
2015        WHERE
2016               ei.expenditure_item_id = ItemsIdTab(i);
2017 
2018       InsAuditRec( ItemsIdTab(i)
2019                  , X_adj_activity
2020                  , X_module
2021                  , X_user
2022                  , X_login
2023                  , temp_status
2024 	/* R12 Changes Start */
2025 	         , G_REQUEST_ID
2026           	 , G_PROGRAM_ID
2027 	         , G_PROG_APPL_ID
2028 	         , sysdate );
2029  	/* R12 Changes End */
2030       CheckStatus( temp_status );
2031 
2032       IF ( AdjustsIdTab(i) IS NOT NULL ) THEN
2033 
2034         UPDATE pa_expenditure_items_all eia
2035            SET
2036                 eia.bill_hold_flag           = X_hold
2037         ,       eia.last_updated_by          = X_user
2038         ,       eia.last_update_date         = sysdate
2039         ,       eia.last_update_login        = X_login
2040          WHERE
2041                 eia.expenditure_item_id = AdjustsIdTab(i);
2042 
2043         InsAuditRec( AdjustsIdTab(i)
2044                    , X_adj_activity
2045                    , X_module
2046                    , X_user
2047                    , X_login
2048                    , temp_status
2049 	/* R12 Changes Start */
2050   	           , G_REQUEST_ID
2051           	   , G_PROGRAM_ID
2052 	           , G_PROG_APPL_ID
2053 	           , sysdate );
2054  	/* R12 Changes End */
2055         CheckStatus( temp_status );
2056 
2057        END IF;
2058 
2059     END LOOP;
2060 
2061     X_status := 0;
2062 
2063   EXCEPTION
2064     WHEN  OTHERS  THEN
2065       X_status := SQLCODE;
2066       RAISE;
2067 
2068   END  Hold;
2069 
2070 -- ========================================================================
2071 --  Start of work type  adjustments
2072 -- ========================================================================
2073 /** Logic:
2074  *  If PA: Transaction Billability derived from Work Type = YES
2075  *         and  change in work type results in change in the billablity
2076  *         then update EI with cost_distributed_flag = 'N' so that
2077  *         costing process will generate reverse and new cdls
2078  *         IF change in work type NOT results in chagne in billablity
2079  *         then create new and reverse cdls with transfer status_code = 'G'
2080  *         and Util summarize_flag  = 'N' and update EI with cost_distributed_flag = 'Y'
2081  *         so that the cdls are not picked up by summarized programm
2082  *  If PA: Transaction Billability derived from Work Type = NO
2083  *         work type and Billabiltiy are two independent process so
2084  *         then create new and reverse cdls with transfer status_code = 'G'
2085  *         and Util summarize_flag  = 'N'
2086  *         To change the billability of the transaction user has to run the
2087  *         Reclass Billable / Non Billable adjustments seperately
2088  **/
2089 PROCEDURE  work_type_adjustment
2090 	           ( ItemsIdTab         IN pa_utils.IdTabTyp
2091              --, AdjustsIdTab      IN pa_utils.IdTabTyp
2092                , p_billable        IN VARCHAR2
2093 		       , p_work_type_id    IN NUMBER
2094                , p_adj_activity    IN VARCHAR2
2095                , p_user            IN NUMBER
2096                , p_login           IN NUMBER
2097                , p_module          IN VARCHAR2
2098                , p_rows            IN BINARY_INTEGER
2099                , p_TpAmtTypCodeTab        IN pa_utils.Char30TabTyp
2100                , p_dest_tp_amt_type_code  IN VARCHAR2
2101                , x_status          OUT NOCOPY NUMBER )
2102 IS
2103     	l_temp_status      NUMBER DEFAULT NULL;
2104     	l_err_code         NUMBER ;
2105     	l_err_stage        VARCHAR2(2000);
2106     	l_err_stack        VARCHAR2(255) ;
2107 
2108     	l_new_billability  VARCHAR2(10);
2109     	l_old_billability  VARCHAR2(10);
2110 	    l_old_work_type_id NUMBER ;
2111         l_profile_option   VARCHAR2(1);
2112 	    l_change_in_billable VARCHAR2(1);
2113 	    l_gl_accounted_flag  VARCHAR2(1);
2114         l_proj_type_class_code        VARCHAR2(80);
2115         l_billable_cap_flag           VARCHAR2(15);
2116 	    l_reverse_cdl_status          varchar2(1) :='S' ;
2117 
2118     	FUNCTION cdl_creation
2119                    ( p_exp_item_id      IN NUMBER
2120                     , p_billable        IN VARCHAR2
2121                     , p_work_type_id    IN NUMBER
2122                     , p_adj_activity    IN VARCHAR2
2123                     , p_user            IN NUMBER
2124                     , p_login           IN NUMBER
2125                     , p_module          IN VARCHAR2
2126                     , p_mode            IN VARCHAR2
2127                     , x_status          OUT NOCOPY NUMBER
2128 		            , p_billable_change IN VARCHAR2
2129                     , p_tp_amt_type_code      IN VARCHAR2
2130                     , p_dest_tp_amt_type_code IN VARCHAR2) return varchar2 IS
2131 
2132           l_transaction_source      	VARCHAR2(30);
2133           l_gl_accounted_flag       	VARCHAR2(1);
2134           l_denom_currency_code     	VARCHAR2(15);
2135           l_acct_currency_code      	VARCHAR2(15);
2136           l_acct_rate_date          	DATE;
2137           l_acct_rate_type          	VARCHAR2(30);
2138           l_acct_exchange_rate      	NUMBER;
2139           l_project_currency_code   	VARCHAR2(15);
2140           l_project_rate_date       	DATE;
2141           l_project_rate_type       	VARCHAR2(30);
2142           l_project_exchange_rate   	NUMBER;
2143           l_system_linkage_function 	VARCHAR2(30);
2144           l_projfunc_currency_code   	VARCHAR2(15);
2145           l_projfunc_cost_rate_date     DATE;
2146           l_projfunc_cost_rate_type     VARCHAR2(30);
2147           l_projfunc_cost_exchg_rate    NUMBER;
2148           l_work_type_id                NUMBER;
2149           l_reverse_cdl_status          varchar2(1) :='S' ;
2150 
2151       	BEGIN
2152 
2153             BEGIN
2154              IF P_DEBUG_MODE  THEN
2155                 print_message('get_denom_curr_code: ' || 'inside cdl_creation api before SELECT ');
2156              END IF;
2157          	SELECT
2158 		        ei.transaction_source,
2159                 tr.gl_accounted_flag,
2160                 ei.denom_currency_code,
2161                 ei.acct_currency_code,
2162                 ei.acct_rate_date,
2163                 ei.acct_rate_type,
2164                 ei.acct_exchange_rate,
2165                 ei.project_currency_code,
2166                 ei.project_rate_date,
2167                 ei.project_rate_type,
2168                 ei.project_exchange_rate,
2169                 tr.system_linkage_function,
2170                 ei.projfunc_currency_code,
2171                 ei.projfunc_cost_rate_date,
2172                 ei.projfunc_cost_rate_type,
2173                 ei.projfunc_cost_exchange_rate,
2174                 ei.work_type_id
2175          	INTO
2176 		l_transaction_source,
2177                 l_gl_accounted_flag,
2178                 l_denom_currency_code,
2179                 l_acct_currency_code,
2180                 l_acct_rate_date,
2181                 l_acct_rate_type,
2182                 l_acct_exchange_rate,
2183                 l_project_currency_code,
2184                 l_project_rate_date,
2185                 l_project_rate_type,
2186                 l_project_exchange_rate,
2187                 l_system_linkage_function,
2188                 l_projfunc_currency_code,
2189                 l_projfunc_cost_rate_date,
2190                 l_projfunc_cost_rate_type,
2191                 l_projfunc_cost_exchg_rate,
2192                 l_work_type_id
2193           	FROM  pa_expenditure_items_all ei,
2194                 	pa_transaction_sources tr
2195           	WHERE tr.transaction_source(+) = ei.transaction_source
2196             	AND expenditure_item_id   = p_exp_item_id;
2197 
2198 		IF P_DEBUG_MODE  THEN
2199 		   print_message('get_denom_curr_code: ' || 'inside cdl_creation api after SELECT ');
2200 		END IF;
2201 
2202 
2203         	IF ( l_gl_accounted_flag = 'Y' and l_system_linkage_function <> 'VI' )
2204                     OR ( p_billable_change = 'N')   then
2205 
2206 		        IF P_DEBUG_MODE  THEN
2207 		           print_message('get_denom_curr_code: ' || 'calling pa_costing reversecdl api from work type adjustment api');
2208 		        END IF;
2209             		Pa_Costing.ReverseCdl
2210 				( X_expenditure_item_id            =>  p_exp_item_id
2211                                  , X_billable_flag                  =>  p_billable
2212                                  , X_amount                         =>  NULL
2213                                  , X_quantity                       =>  NULL
2214                                  , X_burdened_cost                  =>  NULL
2215                                  , X_dr_ccid                        =>  NULL
2216                                  , X_cr_ccid                        =>  NULL
2217                                  , X_tr_source_accounted            =>  'Y'
2218                                  , X_line_type                      =>  'R'
2219                                  , X_user                           =>  p_user
2220                                  , X_denom_currency_code            =>  l_denom_currency_code
2221                                  , X_denom_raw_cost                 =>  NULL
2222                                  , X_denom_burden_cost              =>  NULL
2223                                  , X_acct_currency_code             =>  l_acct_currency_code
2224                                  , X_acct_rate_date                 =>  l_acct_rate_date
2225                                  , X_acct_rate_type                 =>  l_acct_rate_type
2226                                  , X_acct_exchange_rate             =>  l_acct_exchange_rate
2227                                  , X_acct_raw_cost                  =>  NULL
2228                                  , X_acct_burdened_cost             =>  NULL
2229                                  , X_project_currency_code          =>  l_project_currency_code
2230                                  , X_project_rate_date              =>  l_project_rate_date
2231                                  , X_project_rate_type              =>  l_project_rate_type
2232                                  , X_project_exchange_rate          =>  l_project_exchange_rate
2233                                  , X_err_code                       =>  l_err_code
2234                                  , X_err_stage                      =>  l_err_stage
2235                                  , X_err_stack                      =>  l_err_stack
2236                                  , P_Projfunc_currency_code         =>  l_projfunc_currency_code
2237                                  , P_Projfunc_cost_rate_date        =>  l_projfunc_cost_rate_date
2238                                  , P_Projfunc_cost_rate_type        =>  l_projfunc_cost_rate_type
2239                                  , P_Projfunc_cost_exchange_rate    =>  l_projfunc_cost_exchg_rate
2240                                  , P_project_raw_cost               =>  null
2241                                  , P_project_burdened_cost          =>  null
2242                                  , P_Work_Type_Id                   =>  p_work_type_id
2243 				 , p_mode                           =>  p_mode
2244                                  );
2245 			IF P_DEBUG_MODE  THEN
2246 			   print_message('get_denom_curr_code: ' || 'end of reverse cdl api');
2247 			END IF;
2248 			l_reverse_cdl_status := 'S';
2249 
2250 		ELSE
2251 			l_reverse_cdl_status := 'E';
2252 
2253                 END IF;
2254 
2255               EXCEPTION
2256                      WHEN NO_DATA_FOUND THEN
2257                         IF P_DEBUG_MODE  THEN
2258                            print_message('get_denom_curr_code: ' || 'no data found in cdl creation api');
2259                         END IF;
2260                         l_reverse_cdl_status := 'E';
2261                         NULL;
2262 
2263 		     WHEN OTHERS then
2264 			l_reverse_cdl_status := 'U';
2265 			RAISE;
2266 			NULL;
2267               END ;
2268 
2269 	      RETURN l_reverse_cdl_status;
2270 
2271 
2272       	EXCEPTION
2273          	WHEN NO_DATA_FOUND THEN
2274 			IF P_DEBUG_MODE  THEN
2275 			   print_message('get_denom_curr_code: ' || 'no data found in cdl creation api');
2276 			END IF;
2277 			RETURN l_reverse_cdl_status;
2278               		NULL ;
2279          	WHEN OTHERS THEN
2280 			IF P_DEBUG_MODE  THEN
2281 			   print_message('get_denom_curr_code: ' || 'others in cdl creation ='||sqlcode);
2282 			END IF;
2283 			x_status := sqlcode;
2284                		RAISE ;
2285 
2286    	END cdl_creation;
2287 
2288 BEGIN
2289 
2290 
2291 	IF P_DEBUG_MODE  THEN
2292 	   print_message('get_denom_curr_code: ' || 'inside work type adjustment api before loop');
2293 	END IF;
2294 
2295     FOR i IN 1..p_rows LOOP
2296 
2297 	IF P_DEBUG_MODE  THEN
2298 	   print_message ('get_denom_curr_code: ' || 'before select exp_item ='||ItemsIdTab(i));
2299 	END IF;
2300         /** check the change in work type results in change in billabity **/
2301          SELECT EI.work_type_id
2302                 ,nvl(tr.gl_accounted_flag,'N')
2303 	            ,pt.PROJECT_TYPE_CLASS_CODE
2304 		        ,nvl(ei.billable_flag ,'N')
2305          INTO   l_old_work_type_id
2306                 ,l_gl_accounted_flag
2307                 ,l_proj_type_class_code
2308 		        ,l_old_billability
2309          FROM   pa_expenditure_items_all EI
2310                 ,pa_transaction_sources tr
2311 	            ,pa_project_types_all pt /** Bug fix 2262118  **/
2312 	            ,pa_projects_all pp
2313 		        -- ,pa_tasks t /* Bug 3457922 */
2314          WHERE tr.transaction_source(+) = ei.transaction_source
2315          AND   ei.expenditure_item_id = ItemsIdTab(i)
2316 	     -- AND   t.task_id = ei.task_id  /* Bug 3457922 */
2317 	     -- AND   pp.project_id = t.project_id /* Bug 3457922 */
2318          AND   pp.project_id = ei.project_id   /* Added : Bug 3457922 */
2319          AND   pp.project_type = pt.project_type
2320          -- start 12i MOAC changes
2321 	     -- AND   nvl(pp.org_id ,-99) = nvl(pt.org_id ,-99) ;
2322          AND   pp.org_id = pt.org_id;
2323          -- end 12i MAOC changes
2324 
2325 	/** we are not supposed to change the work type and billable flag
2326          *  if the destination work type results in  billable for the project_type
2327          *  is INDIRECT  we should not process . this check is already placed
2328          *  forms LOV to pick only non billable work types for indirect project
2329          *  at the item level addjustments , the same is not possible for
2330          *  massadjust. SO if this api is called from massadjust . we should return
2331          *  without processing
2332          **/
2333 
2334 	 IF (l_proj_type_class_code = 'INDIRECT') then
2335 		        SELECT nvl(BILLABLE_CAPITALIZABLE_FLAG,'N')
2336 			    INTO  l_billable_cap_flag
2337         		FROM  pa_work_types_b -- bug 4668802 changed from pa_work_types_v to pa_work_types_b
2338         		WHERE work_type_id = p_work_type_id
2339 			    AND   trunc(sysdate) between start_date_active and
2340 				                             nvl(end_date_active,sysdate);
2341 
2342 		If  l_billable_cap_flag = 'Y' then
2343 		    RETURN;
2344 		End if;
2345 
2346 	 END IF;
2347 
2348 	IF P_DEBUG_MODE  THEN
2349 	   print_message ('get_denom_curr_code: ' || 'after select l_old_work_type_id ['||l_old_work_type_id||
2350                        ']l_gl_accounted_flag['||l_gl_accounted_flag||']l_old_billability['||l_old_billability||']' );
2351 	END IF;
2352 
2353         l_profile_option := pa_utils4.IS_WORKTYPE_BILLABLE_ENABLED ;
2354 
2355 	If l_profile_option = 'Y' and l_proj_type_class_code  in ('CAPITAL','CONTRACT') then
2356 
2357 
2358 		l_new_billability := PA_UTILS4.get_trxn_work_billabilty
2359 				(p_work_type_id       => p_work_type_id
2360                             	,p_tc_extn_bill_flag  => NULL );
2361 
2362 		/*** Commented out this portion due to following issue
2363                  ** Initially set the work type profile to 'N' and transaction is entered with billability = 'Y'
2364                  ** Now set the work type profile to 'Y', As the old and new worktype results no change in billability
2365                  ** then EI will never be updated with the billablity change . in order to fix this
2366                  ** donot derive old billabity based on worktype
2367         	    l_old_billability := PA_UTILS4.get_trxn_work_billabilty
2368                                 (p_work_type_id       => l_old_work_type_id
2369                                 ,p_tc_extn_bill_flag  => NULL );
2370 		 **/
2371 
2372 		IF l_new_billability <> l_old_billability then
2373 
2374 			l_change_in_billable := 'Y';
2375 		Else
2376 			l_change_in_billable := 'N';
2377 		End if;
2378 
2379 	Else
2380 
2381 		l_change_in_billable := 'N';
2382 
2383 	End if;
2384 
2385 	--l_profile_option := pa_utils4.IS_WORKTYPE_BILLABLE_ENABLED ;
2386 
2387 	IF P_DEBUG_MODE  THEN
2388 	   print_message('get_denom_curr_code: ' || 'l_old_billability['||l_old_billability||
2389 		      ']l_new_billability['||l_new_billability||
2390                       ']p_oldTpAMTcode['||p_TpAmtTypCodeTab(i)||']p_newTpAMTcode['||p_dest_tp_amt_type_code||
2391 	              ']l_old_work_type_id['||l_old_work_type_id||']l_new_work_type_id['||p_work_type_id||
2392 		      ']l_profile_option ['||l_profile_option||']l_change_in_billable['||l_change_in_billable||
2393 		      ']l_gl_accounted_flag['||l_gl_accounted_flag||']'  );
2394 	END IF;
2395 
2396 	IF l_change_in_billable = 'Y' AND l_gl_accounted_flag = 'Y'  THEN
2397                 /** create reverse and new cdls with transfer status code = 'P'
2398 		 ** and pass new billable flag to create cdl api **/
2399                 IF P_DEBUG_MODE  THEN
2400                    print_message('get_denom_curr_code: ' || 'calling cdl_creation api');
2401                 END IF;
2402                 l_reverse_cdl_status := cdl_creation
2403                    ( p_exp_item_id      => ItemsIdTab(i)
2404                     , p_billable        => l_new_billability
2405                     , p_work_type_id    => p_work_type_id
2406                     , p_adj_activity    => p_adj_activity
2407                     , p_user            => p_user
2408                     , p_login           => p_login
2409                     , p_module          => p_module
2410                     , p_mode            => 'WORK_TYP_ADJ' -- passing 'WORK_TYP_ADJ', bug 3357936
2411                     , x_status          => x_status
2412 		    , p_billable_change => l_change_in_billable
2413                     , p_tp_amt_type_code      => p_TpAmtTypCodeTab(i)
2414                     , p_dest_tp_amt_type_code => p_dest_tp_amt_type_code
2415                     );
2416                 IF P_DEBUG_MODE  THEN
2417                    print_message('get_denom_curr_code: ' || 'after  cdl_creating api');
2418                 END IF;
2419 
2420 	Elsif l_change_in_billable = 'N' then
2421 		/** create reverse and new cdls with transfer status code = 'G' **/
2422 		IF P_DEBUG_MODE  THEN
2423 		   print_message('get_denom_curr_code: ' || 'calling cdl_creation api');
2424 		END IF;
2425         	l_reverse_cdl_status := cdl_creation
2426                    ( p_exp_item_id      => ItemsIdTab(i)
2427                     , p_billable        => null
2428                     , p_work_type_id    => p_work_type_id
2429                     , p_adj_activity    => p_adj_activity
2430                     , p_user            => p_user
2431                     , p_login           => p_login
2432                     , p_module          => p_module
2433                     , p_mode            => 'WORK_TYP_ADJ' -- Bug 5561542
2434 		    , x_status          => x_status
2435 		    , p_billable_change => l_change_in_billable
2436                     , p_tp_amt_type_code      => p_TpAmtTypCodeTab(i)
2437                     , p_dest_tp_amt_type_code => p_dest_tp_amt_type_code
2438                     );
2439 		IF P_DEBUG_MODE  THEN
2440 		   print_message('get_denom_curr_code: ' || 'after  cdl_creating api');
2441 		END IF;
2442 
2443 	END IF; -- end of change_in_billable
2444 
2445       		/**
2446                	*Project summarization changes Mark ei as cost distributed if cdls are created
2447                 * mark cost distributed flag to 'Y' else mark it as 'N'
2448                 **/
2449 		IF P_DEBUG_MODE  THEN
2450 		   print_message('get_denom_curr_code: ' || 'calling update of EI');
2451 		END IF;
2452 		/**
2453 		Burdening changes (PA.L)
2454 		Work type adjusment API is modified, If the transaction is already
2455 		adjusted by burdening or other adjustment process, this API should
2456 		NOT set the cost distributed flag to 'Y'
2457 		Matrx for updating the cost dist flag
2458 		OrgCostDist  BillablityChange   GlAccted  CdlCreation  UpdCostDist
2459 		------------------------------------------------------------------
2460   		Y             Y                Y         success       Y
2461   		N             Y                Y         success       N
2462   		Y/N           Y                Y         No cdls       N
2463   		Y/N           Y                N          ---          N
2464   		Y             N                -         success       Y
2465   		Y/N           N                -         No cdls       N
2466 		Solution: added decode(nvl(ei.cost_distributed_flag,'N'),'Y','Y','N')
2467 		**/
2468                 UPDATE  pa_expenditure_items_all ei
2469                 SET     ei.work_type_id              = p_work_type_id
2470                         ,ei.cost_distributed_flag    =
2471 				decode(l_change_in_billable,
2472 				   'Y', decode(l_gl_accounted_flag,
2473 					      'N','N',
2474 					      'Y',decode(l_reverse_cdl_status
2475 							,'S',decode(nvl(ei.cost_distributed_flag,'N'),'Y','Y','N')
2476 							,'N')
2477                                                ),
2478 				   'N',decode(l_reverse_cdl_status,'S',
2479                                           decode(nvl(ei.cost_distributed_flag,'N'),'Y','Y','N'),'N'))
2480                         ,ei.revenue_distributed_flag = 'N'
2481                         ,ei.billable_flag            = decode(l_change_in_billable,'Y',l_new_billability,ei.billable_flag)
2482                         ,ei.last_updated_by          = p_user
2483                         ,ei.last_update_date         = sysdate
2484                         ,ei.last_update_login        = p_login
2485                         ,ei.tp_amt_type_code         = PA_UTILS4.get_tp_amt_type_code
2486                                                                 (p_work_type_id)
2487                         ,cc_bl_distributed_code      = DECODE(p_dest_tp_amt_type_code, p_TpAmtTypCodeTab(i),
2488                                                               cc_bl_distributed_code,
2489                                                               decode(cc_bl_distributed_code,'X','X','N'))
2490                         ,cc_ic_processed_code        = DECODE(p_dest_tp_amt_type_code, p_TpAmtTypCodeTab(i),
2491                                                               cc_ic_processed_code,
2492                                                               decode(cc_ic_processed_code,'X','X','N'))
2493                         /* Begin Burdening Changes - PA.L */
2494                         ,ei.adjustment_type          = NULL
2495                         /* End Burdening Changes - PA.L */
2496                 WHERE
2497                         ei.expenditure_item_id = ItemsIdTab(i);
2498 
2499                 IF P_DEBUG_MODE  THEN
2500                    print_message('get_denom_curr_code: ' || 'Num of rows updated ['||sql%rowcount||
2501                                 ']with work type ['||p_work_type_id||']' );
2502                 END IF;
2503 
2504                 InsAuditRec( X_exp_item_id    =>       ItemsIdTab(i)
2505                         , X_adj_activity      =>       p_adj_activity
2506                         , X_module            =>       p_module
2507                         , X_user              =>       p_user
2508                         , X_login             =>       p_login
2509                         , X_status            =>       l_temp_status
2510 		/* R12 Changes Start */
2511                         , X_who_req_id        =>       G_REQUEST_ID
2512                         , X_who_prog_id       =>       G_PROGRAM_ID
2513                         , X_who_prog_app_id   =>       G_PROG_APPL_ID
2514                         , X_who_prog_upd_date =>       sysdate);
2515 		/* R12 Changes End */
2516 
2517                 CheckStatus( status_indicator => l_temp_status );
2518 
2519 
2520      END LOOP;
2521 
2522      X_status := 0;
2523 
2524 EXCEPTION
2525      WHEN  OTHERS  THEN
2526 	IF P_DEBUG_MODE  THEN
2527 	   print_message('get_denom_curr_code: ' || ' others exection in work type adjustments api');
2528 	END IF;
2529 	X_status := SQLCODE;
2530 	RAISE;
2531 
2532 END  work_type_adjustment;
2533 --===========================================================================
2534 -- End of work type adjustments
2535 --===========================================================================
2536 
2537 
2538 -- ========================================================================
2539 -- PROCEDURE Reclass
2540 -- ========================================================================
2541 
2542   PROCEDURE  Reclass( ItemsIdTab        IN pa_utils.IdTabTyp
2543                     , AdjustsIdTab      IN pa_utils.IdTabTyp
2544                     , X_billable        IN VARCHAR2
2545                     , X_adj_activity    IN VARCHAR2
2546                     , X_user            IN NUMBER
2547                     , X_login           IN NUMBER
2548                     , X_module          IN VARCHAR2
2549                     , rows              IN BINARY_INTEGER
2550                     , X_status          OUT NOCOPY NUMBER )
2551   IS
2552     temp_status      NUMBER DEFAULT NULL;
2553     err_code         NUMBER ;
2554     err_stage        VARCHAR2(2000);
2555     err_stack        VARCHAR2(255) ;
2556   BEGIN
2557 
2558     FOR i IN 1..rows LOOP
2559 
2560       UPDATE  pa_expenditure_items_all ei
2561       SET     ei.billable_flag            = X_billable
2562       ,       ei.revenue_distributed_flag = 'N'
2563       ,       ei.cost_distributed_flag    = 'N'
2564       /* Begin Burdening Changes - PA.L */
2565       ,       ei.adjustment_type          = NULL
2566       /* End Burdening Changes - PA.L */
2567       ,       ei.last_updated_by          = X_user
2568       ,       ei.last_update_date         = sysdate
2569       ,       ei.last_update_login        = X_login
2570       WHERE
2571               ei.expenditure_item_id = ItemsIdTab(i);
2572 
2573       DECLARE
2574           p_transaction_source      VARCHAR2(30);
2575           p_gl_accounted_flag       VARCHAR2(1);
2576           p_denom_currency_code     VARCHAR2(15);
2577 	      p_acct_currency_code      VARCHAR2(15);
2578 	      p_acct_rate_date          DATE;
2579 	      p_acct_rate_type          VARCHAR2(30);
2580 	      p_acct_exchange_rate      NUMBER;
2581 	      p_project_currency_code   VARCHAR2(15);
2582           p_project_rate_date       DATE;
2583           p_project_rate_type       VARCHAR2(30);
2584           p_project_exchange_rate   NUMBER;
2585           p_system_linkage_function VARCHAR2(30);
2586 	      l_projfunc_currency_code   VARCHAR2(15);
2587           l_projfunc_cost_rate_date       DATE;
2588           l_projfunc_cost_rate_type       VARCHAR2(30);
2589           l_projfunc_cost_exchg_rate   NUMBER;
2590           l_work_type_id               NUMBER;
2591 
2592       BEGIN
2593          SELECT ei.transaction_source,
2594                 tr.gl_accounted_flag,
2595                 ei.denom_currency_code,
2596                 ei.acct_currency_code,
2597 	            ei.acct_rate_date,
2598                 ei.acct_rate_type,
2599 	            ei.acct_exchange_rate,
2600                 ei.project_currency_code,
2601                 ei.project_rate_date,
2602 	            ei.project_rate_type,
2603                 ei.project_exchange_rate,
2604                 tr.system_linkage_function,
2605 		        ei.projfunc_currency_code,
2606                 ei.projfunc_cost_rate_date,
2607                 ei.projfunc_cost_rate_type,
2608                 ei.projfunc_cost_exchange_rate,
2609 		        ei.work_type_id
2610          INTO   p_transaction_source,
2611                 p_gl_accounted_flag,
2612 	            p_denom_currency_code,
2613                 p_acct_currency_code,
2614 		        p_acct_rate_date,
2615                 p_acct_rate_type,
2616 		        p_acct_exchange_rate,
2617 	            p_project_currency_code,
2618                 p_project_rate_date,
2619 		        p_project_rate_type,
2620                 p_project_exchange_rate,
2621                 p_system_linkage_function,
2622           	    l_projfunc_currency_code,
2623           	    l_projfunc_cost_rate_date,
2624           	    l_projfunc_cost_rate_type,
2625           	    l_projfunc_cost_exchg_rate,
2626 		        l_work_type_id
2627           FROM  pa_expenditure_items_all ei,
2628                 pa_transaction_sources tr
2629           WHERE tr.transaction_source = ei.transaction_source
2630             AND expenditure_item_id   = ItemsIdTab(i) ;
2631 
2632 -- Added to IF condition below: p_system_linkage_function <> 'VI' to resolve bug # 1764279
2633 -- Added to IF condition below: p_transaction_source <> 'AP EXPENSE' to resolve bug# 2323103
2634 -- Modified IF condition below:
2635 --     ((p_system_linkage_function <> 'VI') or
2636 --      (p_system_linkage_function = 'VI' and p_transaction_source = 'PO RECEIPT '))
2637 --                                                                                   to resolve bug# 2853597
2638 -- Removed AP INVOICE transaction source to resolve the bug#3162892.
2639  /* Added sys link <> INV for Bug#3693497*/
2640 /* Bug 4610677 - Reversal CDL will not be created for GL Accounted VI and ER transactions */
2641         IF p_gl_accounted_flag = 'Y' and
2642            p_system_linkage_function NOT IN ('VI','ER','INV') THEN
2643 
2644             Pa_Costing.ReverseCdl( X_expenditure_item_id            =>	ItemsIdTab(i)
2645                                  , X_billable_flag                  =>	X_billable
2646                                  , X_amount                         =>	NULL
2647                                  , X_quantity                       =>	NULL
2648                                  , X_burdened_cost                  =>	NULL
2649                                  , X_dr_ccid                        =>	NULL
2650                                  , X_cr_ccid                        =>	NULL
2651                                  , X_tr_source_accounted            =>	'Y'
2652                                  , X_line_type                      =>	'R'
2653                                  , X_user                           =>	X_user
2654                                  , X_denom_currency_code            =>	p_denom_currency_code
2655                                  , X_denom_raw_cost                 =>	NULL
2656                                  , X_denom_burden_cost              =>	NULL
2657                                  , X_acct_currency_code             =>	p_acct_currency_code
2658                                  , X_acct_rate_date                 =>	p_acct_rate_date
2659                                  , X_acct_rate_type                 =>	p_acct_rate_type
2660                                  , X_acct_exchange_rate             =>	p_acct_exchange_rate
2661                                  , X_acct_raw_cost                  =>	NULL
2662                                  , X_acct_burdened_cost             =>	NULL
2663                                  , X_project_currency_code          =>	p_project_currency_code
2664                                  , X_project_rate_date              =>	p_project_rate_date
2665                                  , X_project_rate_type              =>	p_project_rate_type
2666                                  , X_project_exchange_rate          =>	p_project_exchange_rate
2667                                  , X_err_code                       =>	err_code
2668                                  , X_err_stage                      =>	err_stage
2669                                  , X_err_stack                      =>	err_stack
2670      			                 , P_Projfunc_currency_code         =>  l_projfunc_currency_code
2671    				                 , P_Projfunc_cost_rate_date        =>  l_projfunc_cost_rate_date
2672    				                 , P_Projfunc_cost_rate_type        =>  l_projfunc_cost_rate_type
2673    				                 , P_Projfunc_cost_exchange_rate    =>  l_projfunc_cost_exchg_rate
2674    				                 , P_project_raw_cost               =>  null
2675    				                 , P_project_burdened_cost          =>  null
2676    				                 , P_Work_Type_Id                   =>  l_work_type_id
2677 				                 , p_mode                           =>  'RECLASS'); -- passed reclass BUG 3357936
2678 
2679               /*
2680                   Project summarization changes
2681                   Mark ei as cost distributed
2682                */
2683                -- start 12i MOAC changes
2684                -- UPDATE pa_expenditure_items
2685                UPDATE pa_expenditure_items_all
2686                -- end 12i MOAC changes
2687                SET    cost_distributed_flag = 'Y'
2688                WHERE  expenditure_item_id = ItemsIdTab(i);
2689 
2690           END IF;
2691       EXCEPTION
2692          WHEN NO_DATA_FOUND THEN
2693               NULL ;
2694          WHEN OTHERS THEN
2695                RAISE ;
2696       END ;
2697 
2698       InsAuditRec( X_exp_item_id       =>	ItemsIdTab(i)
2699                  , X_adj_activity      =>	X_adj_activity
2700                  , X_module            =>	X_module
2701                  , X_user              =>	X_user
2702                  , X_login             =>	X_login
2703                  , X_status            =>	temp_status
2704 	/* R12 Changes Start */
2705                  , X_who_req_id        =>       G_REQUEST_ID
2706                  , X_who_prog_id       =>       G_PROGRAM_ID
2707                  , X_who_prog_app_id   =>       G_PROG_APPL_ID
2708                  , X_who_prog_upd_date =>       sysdate);
2709 	/* R12 Changes End */
2710       CheckStatus( status_indicator => temp_status );
2711 
2712       IF ( AdjustsIdTab(i) IS NOT NULL ) THEN
2713 
2714 
2715         UPDATE pa_expenditure_items_all eia
2716            SET
2717                eia.billable_flag            = X_billable
2718         ,      eia.revenue_distributed_flag = 'N'
2719         ,      eia.cost_distributed_flag    = 'N'
2720         ,      eia.last_updated_by          = X_user
2721         ,      eia.last_update_date         = sysdate
2722         ,      eia.last_update_login        = X_login
2723          WHERE
2724                eia.expenditure_item_id = AdjustsIdTab(i);
2725 
2726         DECLARE
2727 
2728           p_transaction_source      VARCHAR2(30);
2729           p_gl_accounted_flag       VARCHAR2(1);
2730           p_denom_currency_code     VARCHAR2(15);
2731 	      p_acct_currency_code      VARCHAR2(15);
2732 	      p_acct_rate_date          DATE;
2733 	      p_acct_rate_type          VARCHAR2(30);
2734 	      p_acct_exchange_rate      NUMBER;
2735 	      p_project_currency_code   VARCHAR2(15);
2736           p_project_rate_date       DATE;
2737           p_project_rate_type       VARCHAR2(30);
2738           p_project_exchange_rate   NUMBER;
2739           l_projfunc_currency_code   VARCHAR2(15);
2740           l_projfunc_cost_rate_date       DATE;
2741           l_projfunc_cost_rate_type       VARCHAR2(30);
2742           l_projfunc_cost_exchg_rate   NUMBER;
2743           l_work_type_id               NUMBER;
2744 
2745         BEGIN
2746 
2747            SELECT ei.transaction_source,
2748                   tr.gl_accounted_flag,
2749                   ei.denom_currency_code,
2750                   ei.acct_currency_code,
2751 		          ei.acct_rate_date,
2752                   ei.acct_rate_type,
2753 		          ei.acct_exchange_rate,
2754                   ei.project_currency_code,
2755                   ei.project_rate_date,
2756 		          ei.project_rate_type,
2757                   ei.project_exchange_rate,
2758                   ei.projfunc_currency_code,
2759                   ei.projfunc_cost_rate_date,
2760                   ei.projfunc_cost_rate_type,
2761                   ei.projfunc_cost_exchange_rate,
2762                   ei.work_type_id
2763            INTO   p_transaction_source,
2764                   p_gl_accounted_flag,
2765 	              p_denom_currency_code,
2766                   p_acct_currency_code,
2767 		          p_acct_rate_date,
2768                   p_acct_rate_type,
2769 		          p_acct_exchange_rate,
2770 	              p_project_currency_code,
2771                   p_project_rate_date,
2772 		          p_project_rate_type,
2773                   p_project_exchange_rate,
2774                   l_projfunc_currency_code,
2775                   l_projfunc_cost_rate_date,
2776                   l_projfunc_cost_rate_type,
2777                   l_projfunc_cost_exchg_rate,
2778                   l_work_type_id
2779            FROM   pa_expenditure_items_all ei,
2780                   pa_transaction_sources tr
2781            WHERE  tr.transaction_source = ei.transaction_source
2782              AND  expenditure_item_id = AdjustsIdTab(i) ;
2783 
2784            IF p_gl_accounted_flag = 'Y' THEN
2785 
2786               Pa_Costing.ReverseCdl( X_expenditure_item_id            => AdjustsIdTab(i)
2787                                    , X_billable_flag                  => X_billable
2788                                    , X_amount                         => NULL
2789                                    , X_quantity                       => NULL
2790                                    , X_burdened_cost                  => NULL
2791                                    , X_dr_ccid                        => NULL
2792                                    , X_cr_ccid                        => NULL
2793                                    , X_tr_source_accounted            => 'Y'
2794                                    , X_line_type                      => 'R'
2795                                    , X_user                           => X_user
2796                                    , X_denom_currency_code            => p_denom_currency_code
2797                                    , X_denom_raw_cost                 => NULL
2798                                    , X_denom_burden_cost              => NULL
2799                                    , X_acct_currency_code             => p_acct_currency_code
2800                                    , X_acct_rate_date                 => p_acct_rate_date
2801                                    , X_acct_rate_type                 => p_acct_rate_type
2802                                    , X_acct_exchange_rate             => p_acct_exchange_rate
2803                                    , X_acct_raw_cost                  => NULL
2804                                    , X_acct_burdened_cost             => NULL
2805                                    , X_project_currency_code          => p_project_currency_code
2806                                    , X_project_rate_date              => p_project_rate_date
2807                                    , X_project_rate_type              => p_project_rate_type
2808                                    , X_project_exchange_rate          => p_project_exchange_rate
2809                                    , X_err_code                       => err_code
2810                                    , X_err_stage                      => err_stage
2811                                    , X_err_stack                      => err_stack
2812                                    , P_Projfunc_currency_code         => l_projfunc_currency_code
2813                                    , P_Projfunc_cost_rate_date        => l_projfunc_cost_rate_date
2814                                    , P_Projfunc_cost_rate_type        => l_projfunc_cost_rate_type
2815                                    , P_Projfunc_cost_exchange_rate    => l_projfunc_cost_exchg_rate
2816                                    , P_project_raw_cost               => null
2817                                    , P_project_burdened_cost          => null
2818                                    , P_Work_Type_Id                   => l_work_type_id
2819 				                   , p_mode                           => 'RECLASS'); -- passing reclass, bug 3357936
2820               /*
2821                   Project summarization changes
2822                   Mark ei as cost distributed
2823                */
2824                -- start 12i MOAC changes
2825                -- UPDATE pa_expenditure_items
2826                UPDATE pa_expenditure_items_all
2827                -- end 12i MOAC changes
2828                SET    cost_distributed_flag = 'Y'
2829                WHERE  expenditure_item_id = AdjustsIdTab(i);
2830 
2831             END IF  ;
2832 
2833         EXCEPTION
2834            WHEN NO_DATA_FOUND THEN
2835                 NULL ;
2836            WHEN OTHERS THEN
2837                  RAISE ;
2838         END ;
2839 
2840         InsAuditRec( X_exp_item_id       =>	AdjustsIdTab(i)
2841                    , X_adj_activity      =>	X_adj_activity
2842                    , X_module            =>	X_module
2843                    , X_user              =>	X_user
2844                    , X_login             =>	X_login
2845                    , X_status            =>	temp_status
2846 	/* R12 Changes Start */
2847                    , X_who_req_id        =>     G_REQUEST_ID
2848                    , X_who_prog_id       =>     G_PROGRAM_ID
2849                    , X_who_prog_app_id   =>     G_PROG_APPL_ID
2850                    , X_who_prog_upd_date =>     sysdate);
2851 	/* R12 Changes End */
2852 
2853         CheckStatus( status_indicator => temp_status );
2854 
2855       END IF;
2856 
2857     END LOOP;
2858 
2859     X_status := 0;
2860 
2861   EXCEPTION
2862     WHEN  OTHERS  THEN
2863       X_status := SQLCODE;
2864       RAISE;
2865 
2866   END  Reclass;
2867 
2868 
2869 -- ========================================================================
2870 -- PROCEDURE Split
2871 -- ========================================================================
2872 
2873    PROCEDURE Split( X_exp_item_id               IN NUMBER
2874                   , X_item1_qty                 IN NUMBER
2875                   , X_item1_raw_cost            IN NUMBER
2876                   , X_item1_burden_cost         IN NUMBER
2877                   , X_item1_bill_flag           IN VARCHAR2
2878                   , X_item1_hold_flag           IN VARCHAR2
2879                   , X_item2_qty                 IN NUMBER
2880                   , X_item2_raw_cost            IN NUMBER
2881                   , X_item2_burden_cost         IN NUMBER
2882                   , X_item1_receipt_curr_amt    IN NUMBER
2883                   , X_item2_receipt_curr_amt    IN NUMBER
2884                   , X_item1_denom_raw_cost      IN NUMBER
2885                   , X_item2_denom_raw_cost      IN NUMBER
2886                   , X_item1_denom_burdened_cost IN NUMBER
2887                   , X_item2_denom_burdened_cost IN NUMBER
2888                   , X_Item1_acct_raw_cost       IN NUMBER
2889                   , X_item2_acct_raw_cost       IN NUMBER
2890                   , X_item1_acct_burdened_cost  IN NUMBER
2891                   , X_item2_acct_burdened_cost  IN NUMBER
2892                   , X_item2_bill_flag           IN VARCHAR2
2893                   , X_item2_hold_flag           IN VARCHAR2
2894                   , X_user                      IN NUMBER
2895                   , X_login                     IN NUMBER
2896                   , X_module                    IN VARCHAR2
2897                   , X_status                    OUT NOCOPY NUMBER
2898                   , p_item1_project_raw_cost      IN NUMBER    -- project raw
2899                   , p_item1_project_burden_cost   IN NUMBER    -- project burden
2900                   , p_item2_project_raw_cost      IN NUMBER    -- project raw
2901                   , p_item2_project_burden_cost   IN NUMBER    -- project burden
2902                  )
2903   IS
2904 
2905     item_qty                 NUMBER;
2906     item_raw_cost            NUMBER;
2907     item_burden_cost         NUMBER ;
2908     item_receipt_curr_amt    NUMBER;
2909     item_denom_raw_cost      NUMBER;
2910     item_denom_burdened_cost NUMBER;
2911     item_acct_raw_cost       NUMBER;
2912     item_acct_burdened_cost  NUMBER;
2913     item_bill_flag           VARCHAR2(1);
2914     item_hold_flag           VARCHAR2(1);
2915     new_item_id              NUMBER(15);
2916     item_comment             VARCHAR2(240);
2917     temp_status              NUMBER DEFAULT NULL;
2918     item_project_raw_cost    NUMBER;
2919     item_project_burdened_cost NUMBER ;
2920 
2921   /* EFC bug2259454 changes */
2922     l_denom_currency_code    VARCHAR2(30);
2923     l_exp_type               VARCHAR2(30);
2924     l_denom_cur_code         VARCHAR2(30);
2925     l_acct_cur_code          VARCHAR2(30);
2926     l_sys_link_func          VARCHAR2(3);
2927     l_denom_raw_cost         NUMBER := NULL;
2928     l_transaction_source     pa_expenditure_items_all.transaction_source%type;
2929     l_expenditure_id         pa_expenditure_items_all.expenditure_id%type;
2930     l_person_id              pa_expenditures_all.incurred_by_person_id%type;
2931     l_expenditure_item_date  Date;
2932 
2933 /* Commented the following code as part of Bug#2291180 -- Start */
2934 /*  Bug#2291180
2935     function get_denom_curr_code (l_exp_type in varchar2,
2936                                   l_denom_currency_code in varchar2,
2937                                   l_acct_currency_code in varchar2,
2938                                   l_system_linkage_function in varchar2,
2939                                   l_denom_raw_cost in number) return varchar2 is
2940 
2941          l_cost_rate_flag varchar2(30);
2942          l_return varchar2(30);
2943 
2944     Begin
2945 
2946 	If l_denom_raw_cost is null Then
2947         	If l_system_linkage_function in ('ST','OT') Then
2948                 	If l_acct_currency_code = l_denom_currency_code Then
2949                         	l_return := l_denom_currency_code;
2950                	 	Else
2951                         	l_return := pa_currency.get_currency_code;
2952                 	End If;
2953         	Else
2954                 	select cost_rate_flag
2955                 	into l_cost_rate_flag
2956                 	from pa_expenditure_types
2957                 	where expenditure_type = l_exp_type;
2958 
2959                 	If l_cost_rate_flag = 'Y' Then
2960                         	If l_acct_currency_code = l_denom_currency_code Then
2961                                 	l_return := l_denom_currency_code;
2962                         	Else
2963                                 	l_return := pa_currency.get_currency_code;
2964                         	End If;
2965                 	Else
2966                         	l_return := l_denom_currency_code;
2967                 	End If;
2968         	End If;
2969     	Else
2970         	l_return := l_denom_currency_code;
2971     	End if;
2972 
2973     	return l_return;
2974 
2975     End get_denom_curr_code;
2976  Bug#2291180 */
2977     /* End EFC bug2259454 changes */
2978 /* Commented the above code as part of Bug#2291180 -- End */
2979 
2980   BEGIN
2981 
2982 	IF P_DEBUG_MODE  THEN
2983 	   print_message('get_denom_curr_code: ' || 'Inside split server side api calling insaudit rec api');
2984 	END IF;
2985     	InsAuditRec( X_exp_item_id       =>	X_exp_item_id
2986                    , X_adj_activity      =>	'SPLIT ORIGINATING'
2987                    , X_module            =>	X_module
2988                    , X_user              =>	X_user
2989                    , X_login             =>	X_login
2990                    , X_status            =>	temp_status );
2991 
2992     	CheckStatus( status_indicator => temp_status );
2993 	IF P_DEBUG_MODE  THEN
2994 	   print_message('get_denom_curr_code: ' || 'caling back out  api');
2995 	END IF;
2996 
2997         BackoutItem( X_exp_item_id      =>	X_exp_item_id
2998                    , X_expenditure_id   =>	NULL
2999                    , X_adj_activity     =>	'SPLIT BACK-OUT'
3000                    , X_module           =>	X_module
3001                    , X_user             =>	X_user
3002                    , X_login            =>	X_login
3003                    , X_status           =>	temp_status );
3004 
3005         CheckStatus( status_indicator => temp_status );
3006 
3007     /*
3008         Project Summarization changes
3009         Call procedure to create CDL for the backout item (if necessary)
3010      */
3011 
3012 	IF P_DEBUG_MODE  THEN
3013 	   print_message('get_denom_curr_code: ' || 'calling Pa_Costing.CreateReverseCdl api');
3014 	END IF;
3015 
3016         Pa_Costing.CreateReverseCdl( X_exp_item_id => X_exp_item_id,
3017                                      X_backout_id  => Pa_Adjustments.BackOutId,
3018                                      X_user        => X_user,
3019                                      X_status      => temp_status);
3020 
3021         CheckStatus( status_indicator => temp_status );
3022 
3023         IF P_DEBUG_MODE  THEN
3024            print_message('get_denom_curr_code: ' || 'calling ReverseRelatedItems api');
3025         END IF;
3026 
3027     	ReverseRelatedItems( X_source_exp_item_id  => X_exp_item_id
3028                            , X_expenditure_id      => NULL
3029                            , X_module              => X_module
3030                            , X_user                => X_user
3031                            , X_login               => X_login
3032                            , X_status              => temp_status );
3033 
3034     	CheckStatus( status_indicator => temp_status );
3035 
3036     	BEGIN
3037 
3038       		SELECT
3039               		ec.expenditure_comment
3040         	INTO
3041               		item_comment
3042         	FROM
3043               		pa_expenditure_comments ec
3044        		WHERE
3045               		ec.expenditure_item_id = X_exp_item_id;
3046 
3047     	EXCEPTION
3048       		WHEN  NO_DATA_FOUND  THEN
3049         		NULL;
3050    	END;
3051 
3052    	/* Begin EFC bug2259454 changes */
3053     	select
3054                 transaction_source,
3055         	expenditure_type,
3056         	denom_currency_code,
3057         	acct_currency_code,
3058         	system_linkage_function,
3059         	denom_raw_cost,
3060 		expenditure_id ,
3061 		expenditure_item_date
3062     	into
3063                 l_transaction_source,
3064         	l_exp_type,
3065         	l_denom_cur_code,
3066         	l_acct_cur_code,
3067         	l_sys_link_func,
3068         	l_denom_raw_cost,
3069 		l_expenditure_id,
3070 		l_expenditure_item_date
3071     	from
3072         	pa_expenditure_items_all
3073     	where
3074         	expenditure_item_id = X_exp_item_id;
3075 
3076 	/* bug fix: 2798742 */
3077 	select
3078 		Incurred_by_person_id
3079 	into
3080 		l_person_id
3081 	from
3082 		pa_expenditures_all
3083 	where   expenditure_id = l_expenditure_id;
3084 	/* end of bug fix:2798742 */
3085 
3086     	l_denom_currency_code := get_denom_curr_code(l_transaction_source,
3087                                                      l_exp_type,
3088                                                      l_denom_cur_code,
3089                                                      l_acct_cur_code,
3090                                                      l_sys_link_func,
3091 					             'SPLIT'   /* bug fix: 2798742 */
3092 						     ,l_person_id
3093 						     ,l_expenditure_item_date);
3094 
3095 	/* End EFC bug2259454 changes */
3096 
3097     	FOR i IN 1..2 LOOP
3098 
3099       		IF ( i = 1 ) THEN
3100 
3101         		item_qty                 := X_item1_qty ;
3102         		item_raw_cost            := X_item1_raw_cost;
3103         		item_burden_cost         := X_item1_burden_cost;
3104         		item_bill_flag           := X_item1_bill_flag;
3105         		item_hold_flag           := X_item1_hold_flag;
3106         		item_receipt_curr_amt    := X_item1_receipt_curr_amt ;
3107         		item_denom_raw_cost      := X_item1_denom_raw_cost ;
3108         		item_denom_burdened_cost := X_item1_denom_burdened_cost;
3109         		item_acct_raw_cost       := X_item1_acct_raw_cost;
3110         		item_acct_burdened_cost  := X_item1_acct_burdened_cost;
3111         		item_project_raw_cost    := p_item1_project_raw_cost;
3112         		item_project_burdened_cost := p_item1_project_burden_cost;
3113 
3114       		ELSE
3115 
3116         		item_qty                 := X_item2_qty ;
3117         		item_raw_cost            := X_item2_raw_cost;
3118         		item_burden_cost         := X_item2_burden_cost;
3119         		item_bill_flag           := X_item2_bill_flag;
3120         		item_hold_flag           := X_item2_hold_flag;
3121         		item_receipt_curr_amt    := X_item2_receipt_curr_amt ;
3122         		item_denom_raw_cost      := X_item2_denom_raw_cost ;
3123         		item_denom_burdened_cost := X_item2_denom_burdened_cost;
3124         		item_acct_raw_cost       := X_item2_acct_raw_cost;
3125         		item_acct_burdened_cost  := X_item2_acct_burdened_cost;
3126         		item_project_raw_cost    := p_item2_project_raw_cost;
3127         		item_project_burdened_cost := p_item2_project_burden_cost;
3128 
3129       		END IF;
3130 
3131       		new_item_id := pa_utils.GetNextEiId;
3132 
3133 		IF P_DEBUG_MODE  THEN
3134 		   print_message('get_denom_curr_code: ' || 'calling insert into EI');
3135 		END IF;
3136 
3137       		INSERT INTO pa_expenditure_items_all(
3138        			  expenditure_item_id
3139        			, task_id
3140        			, expenditure_type
3141        			, system_linkage_function
3142        			, expenditure_item_date
3143        			, expenditure_id
3144        			, override_to_organization_id
3145        			, last_update_date
3146        			, last_updated_by
3147        			, creation_date
3148        			, created_by
3149        			, last_update_login
3150        			, quantity
3151        			, revenue_distributed_flag
3152        			, bill_hold_flag
3153        			, billable_flag
3154        			, bill_rate_multiplier
3155        			, cost_distributed_flag
3156        			, raw_cost
3157        			, raw_cost_rate
3158        			, burden_cost
3159        			, burden_cost_rate                    /*1765164*/
3160        			, non_labor_resource
3161        			, organization_id
3162        			, transferred_from_exp_item_id
3163        			, attribute_category
3164        			, attribute1
3165        			, attribute2
3166        			, attribute3
3167        			, attribute4
3168        			, attribute5
3169        			, attribute6
3170        			, attribute7
3171        			, attribute8
3172        			, attribute9
3173        			, attribute10
3174        			, transaction_source
3175                         ,  orig_transaction_reference    /* Bug 2373450 */
3176        			, job_id
3177        			, org_id
3178        			, labor_cost_multiplier_name
3179        			, receipt_currency_amount
3180        			, receipt_currency_code
3181        			, receipt_exchange_rate
3182        			, denom_currency_code
3183       			, denom_raw_cost
3184        			, denom_burdened_cost
3185        			, acct_currency_code
3186        			, acct_rate_date
3187        			, acct_rate_type
3188        			, acct_exchange_rate
3189        			, acct_raw_cost
3190        			, acct_burdened_cost
3191        			, acct_exchange_rounding_limit
3192        			, project_currency_code
3193        			, project_rate_type
3194        			, project_rate_date
3195        			, project_exchange_rate
3196        			, cost_ind_compiled_set_id /* added for bug 1765164 */
3197 		     /* For split, all the CC attributes are calculated again, following the
3198    		  	revenue/billing model */
3199        		     /* , cc_cross_charge_code
3200        			, cc_prvdr_organization_id
3201        			, cc_recvr_organization_id
3202        			, cc_rejection_code
3203        			, denom_tp_currency_code
3204        			, denom_transfer_price
3205        			, acct_tp_rate_type
3206        			, acct_tp_rate_date
3207        			, acct_tp_exchange_rate
3208        			, acct_transfer_price
3209        			, projacct_transfer_price
3210        			, cc_markup_base_code
3211        			, tp_base_amount
3212        			, cc_cross_charge_type
3213        			, recvr_org_id
3214        			, cc_bl_distributed_code
3215        			, cc_ic_processed_code
3216        			, tp_ind_compiled_set_id
3217        			, tp_bill_rate
3218        			, tp_bill_markup_percentage
3219        			, tp_schedule_line_percentage
3220        			, tp_rule_percentage  */
3221        			, recvr_org_id         /*Bug# 2028917*/
3222        			, assignment_id
3223        			, work_type_id
3224        			, projfunc_currency_code
3225        			, projfunc_cost_rate_type
3226        			, projfunc_cost_rate_date
3227        			, projfunc_cost_exchange_rate
3228        			, project_raw_cost
3229        			, project_burdened_cost
3230        		    /** , project_tp_rate_type
3231        			, project_tp_rate_date
3232        			, project_tp_exchange_rate
3233        			, project_transfer_price **/
3234        			, project_id
3235        			, tp_amt_type_code   /** added for bug 3117718 **/
3236                         , inventory_item_id -- Bug 4320459
3237                         , unit_of_measure -- Bug 4320459
3238                  /* R12 Changes - Start */
3239                         , document_header_id
3240                         , document_distribution_id
3241                         , document_line_number
3242                         , document_payment_id
3243                         , vendor_id
3244                         , document_type
3245                         , document_distribution_type
3246                  /* R12 Changes - End */
3247        		)
3248       		SELECT
3249       		        new_item_id                     -- expenditure_item_id
3250       		,       ei.task_id                      -- task_id
3251       		,       ei.expenditure_type             -- expenditure_type
3252       		,       ei.system_linkage_function      -- system_linkage_function
3253       		,       ei.expenditure_item_date        -- expenditure_item_date
3254       		,       ei.expenditure_id               -- expenditure_id
3255       		,       ei.override_to_organization_id  -- override_to_organization_id
3256       		,       sysdate                         -- last_update_date
3257       		,       X_user                          -- last_updated_by
3258       		,       sysdate                         -- creation_date
3259       		,       X_user                          -- created_by
3260       		,       X_login                         -- last_update_login
3261       		,       item_qty                        -- quantity
3262       		,       'N'                             -- revenue_distributed_flag
3263       		,       item_hold_flag                  -- bill_hold_flag
3264       		,       item_bill_flag                  -- billable_flag
3265       		,       ei.bill_rate_multiplier         -- bill_rate_multiplier
3266       		,       'N'                             -- cost_distributed_flag
3267       		,       item_raw_cost                   -- raw_cost
3268       		,       ei.raw_cost_rate                -- raw_cost_rate
3269       		,       item_burden_cost                -- burden_cost
3270       		,       ei.burden_cost_rate             -- burden_cost_rate /*1765164*/
3271       		,       ei.non_labor_resource           -- non_labor_resource
3272       		,       ei.organization_id              -- organization_id
3273       		,       ei.expenditure_item_id          -- adjusted_expenditure_item_id
3274       		,       ei.attribute_category           -- attribute_category
3275       		,       ei.attribute1                   -- attribute1
3276       		,       ei.attribute2                   -- attribute2
3277       		,       ei.attribute3                   -- attribute3
3278       		,       ei.attribute4                   -- attribute4
3279       		,       ei.attribute5                   -- attribute5
3280       		,       ei.attribute6                   -- attribute6
3281       		,       ei.attribute7                   -- attribute7
3282       		,       ei.attribute8                   -- attribute8
3283       		,       ei.attribute9                   -- attribute9
3284       		,       ei.attribute10                  -- attribute10
3285       		,       ei.transaction_source           -- transaction_source
3286                 ,       decode(ei.transaction_source,'PTE TIME',NULL,
3287                         decode(ei.transaction_source,'PTE EXPENSE',NULL,
3288                         decode(ei.transaction_source,'ORACLE TIME AND LABOR',NULL,
3289                         decode(ei.transaction_source,'Oracle Self Service Time',NULL,
3290                               ei.orig_transaction_reference)))) orig_transaction_reference  /* Bug2373450 */
3291       		,       ei.job_id                       -- job_id
3292       		,       ei.org_id                       -- org_id
3293       		,       ei.labor_cost_multiplier_name   -- labor_cost_multiplier_name
3294       		,       item_receipt_curr_amt           -- receipt currency amount
3295       		,       ei.receipt_currency_code        -- receipt currency code
3296       		,       ei.receipt_exchange_rate        -- receipt exchange rate
3297       	         /***,       ei.denom_currency_code          -- denomination currency code **/
3298 		,       l_denom_currency_code           -- denomiation currency code EFC bug2259454 changes
3299       		,       item_denom_raw_cost             -- denomination raw cost
3300       		,       item_denom_burdened_cost        -- denomination burdened cost
3301       		,       ei.acct_currency_code           -- accounting currency code
3302       		,       ei.acct_rate_date               -- accounting rate date
3303       		,       ei.acct_rate_type               -- accounting rate type
3304       		,       ei.acct_exchange_rate           -- accounting exchange rate
3305       		,       item_acct_raw_cost              -- accounting raw cost
3306       		,       item_acct_burdened_cost         -- accounting burdened cost
3307       		,       ei.acct_exchange_rounding_limit -- accounting exchange rounding limit
3308       		,       ei.project_currency_code        -- project currency code
3309       		,       ei.project_rate_type            -- project rate type
3310       		,       ei.project_rate_date            -- project rate date
3311       		,       ei.project_exchange_rate        -- accounting exchange rate
3312       		,       ei.cost_ind_compiled_set_id     -- cost compiled set id added for 1765164
3313     	/*      ,  	ei.cc_cross_charge_code          -- cc_cross_charge_code
3314        		,  	ei.cc_prvdr_organization_id      -- cc_prvdr_organization_id
3315        		,  	ei.cc_recvr_organization_id      -- cc_recvr_organization_id
3316        		,  	ei.cc_rejection_code             -- cc_rejection_code
3317        		,  	ei.denom_tp_currency_code        -- denom_tp_currency_code
3318        		,  	ei.denom_transfer_price          -- denom_transfer_price
3319        		,  	ei.acct_tp_rate_type             -- acct_tp_rate_type
3320        		, 	ei.acct_tp_rate_date             -- acct_tp_rate_date
3321        		,  	ei.acct_tp_exchange_rate         -- acct_tp_exchange_rate
3322        		,  	ei.acct_transfer_price           -- acct_transfer_price
3323        		,  	ei.projacct_transfer_price        -- projacct_transfer_price
3324        		,  	ei.cc_markup_base_code           -- cc_markup_base_code
3325        		,  	ei.tp_base_amount                -- tp_base_amount
3326        		,  	ei.cc_cross_charge_type          -- cc_cross_charge_type
3327        		,  	ei.recvr_org_id                  -- recvr_org_id
3328        		,  	ei.cc_bl_distributed_code        -- cc_bl_distributed_code
3329        		,  	ei.cc_ic_processed_code          -- cc_ic_processed_code
3330        		,  	ei.tp_ind_compiled_set_id        -- tp_ind_compiled_set_id
3331        		,  	ei.tp_bill_rate                  -- tp_bill_rate
3332        		,  	ei.tp_bill_markup_percentage     -- tp_bill_markup_percentage
3333        		,  	ei.tp_schedule_line_percentage   -- tp_schedule_line_percentage
3334       	 	,  	ei.tp_rule_percentage            -- tp_rule_percentage */
3335        		,  	ei.recvr_org_id                  -- recvr_org_id       /*Bug# 2028917*/
3336        		, 	assignment_id
3337        		, 	work_type_id
3338        		, 	projfunc_currency_code
3339        		, 	projfunc_cost_rate_type
3340        		, 	projfunc_cost_rate_date
3341        		, 	projfunc_cost_exchange_rate
3342        		, 	item_project_raw_cost
3343        		, 	item_project_burdened_cost
3344       	/* 	, 	project_tp_rate_type
3345        		, 	project_tp_rate_date
3346        		, 	project_tp_exchange_rate
3347        		, 	project_transfer_price **/
3348        		, 	project_id
3349  		,       ei.tp_amt_type_code   /** added for bug 3117718 **/
3350                 ,       ei.inventory_item_id -- Bug 4320459
3351                 ,       ei.unit_of_measure   -- Bug 4320459
3352          /* R12 Changes - Start */
3353                 ,       ei.document_header_id
3354                 ,       ei.document_distribution_id
3355                 ,       ei.document_line_number
3356                 ,       ei.document_payment_id
3357                 ,       ei.vendor_id
3358                 ,       ei.document_type
3359                 ,       ei.document_distribution_type
3360          /* R12 Changes - End */
3361 
3362       		FROM
3363               		pa_expenditure_items_all ei
3364       		WHERE
3365               		ei.expenditure_item_id = X_exp_item_id;
3366 
3367 		IF P_DEBUG_MODE  THEN
3368 		   print_message('get_denom_curr_code: ' || 'Num of rows inserted in split['||sql%rowcount||']' );
3369 		END IF;
3370 
3371       		IF ( item_comment IS NOT NULL ) THEN
3372 
3373         	pa_transactions.InsItemComment(
3374 					X_ei_id       =>	new_item_id
3375                                       , X_ei_comment  =>	item_comment
3376                                       , X_user        =>	X_user
3377                                       , X_login       =>	X_login
3378                                       , X_status      =>	temp_status );
3379 
3380         	CheckStatus( status_indicator => temp_status );
3381 
3382       	END IF;
3383 
3384       	InsAuditRec(
3385 		   X_exp_item_id       =>	new_item_id
3386                  , X_adj_activity      =>	'SPLIT DESTINATION'
3387                  , X_module            =>	X_module
3388                  , X_user              =>	X_user
3389                  , X_login             =>	X_login
3390                  , X_status            =>	temp_status );
3391 
3392       	CheckStatus( status_indicator => temp_status );
3393 
3394     END LOOP;
3395 
3396     IF P_DEBUG_MODE  THEN
3397        print_message('get_denom_curr_code: ' || 'end of split api');
3398     END IF;
3399 
3400     X_status := 0;
3401 
3402   EXCEPTION
3403     WHEN  OTHERS  THEN
3404       X_status := SQLCODE;
3405       IF P_DEBUG_MODE  THEN
3406          print_message('get_denom_curr_code: ' || 'status ='||X_status);
3407       END IF;
3408       RAISE;
3409 
3410   END  Split;
3411 
3412 
3413 -- ========================================================================
3414 -- PROCEDURE Transfer
3415 -- ========================================================================
3416 
3417   PROCEDURE Transfer ( ItemsIdTab              IN  pa_utils.IdTabTyp
3418                      , X_dest_prj_id           IN  NUMBER
3419                      , X_dest_task_id          IN  NUMBER
3420 		             , X_project_currency_code IN  VARCHAR2
3421 		             , X_project_rate_type     IN  VARCHAR2
3422 		             , X_project_rate_date     IN  DATE
3423 		             , X_project_exchange_rate IN  NUMBER
3424                      , X_user                  IN  NUMBER
3425                      , X_login                 IN  NUMBER
3426                      , X_module                IN  VARCHAR2
3427                      , X_adjust_level          IN  VARCHAR2
3428                      , rows                    IN  BINARY_INTEGER
3429                      , X_num_processed         OUT NOCOPY NUMBER
3430                      , X_num_rejected          OUT NOCOPY NUMBER
3431                      , X_outcome               OUT NOCOPY VARCHAR2
3432 		             , X_msg_application       OUT NOCOPY VARCHAR2
3433 		             , X_msg_type	       OUT NOCOPY VARCHAR2
3434 		             , X_msg_token1 	       OUT NOCOPY VARCHAR2
3435 		             , X_msg_token2	       OUT NOCOPY VARCHAR2
3436 		             , X_msg_token3	       OUT NOCOPY VARCHAR2
3437 		             , X_msg_count	       OUT NOCOPY Number
3438                      , p_projfunc_currency_code IN VARCHAR2
3439                      , p_projfunc_cost_rate_type     IN VARCHAR2
3440                      , p_projfunc_cost_rate_date     IN DATE
3441                      , p_projfunc_cost_exchg_rate IN NUMBER
3442                      , p_assignment_id         IN  NUMBER
3443                      , p_work_type_id          IN  NUMBER	) IS
3444 
3445     dummy                  NUMBER DEFAULT 0;
3446     temp_num_processed     NUMBER DEFAULT 0;
3447     temp_num_rejected      NUMBER DEFAULT 0;
3448     temp_status            NUMBER DEFAULT NULL;
3449     temp_outcome           VARCHAR2(30) DEFAULT NULL;
3450     temp_stage             NUMBER;
3451     temp_msg_application   VARCHAR2(30)  :='PA';
3452     temp_msg_type	   VARCHAR2(1)   :='E';
3453     temp_msg_token1	   VARCHAR2(240) :='';
3454     temp_msg_token2	   VARCHAR2(240) :='';
3455     temp_msg_token3	   VARCHAR2(240) :='';
3456     temp_msg_count	   NUMBER ;
3457 
3458     l_project_rate_date     DATE         := X_project_rate_date;
3459     l_project_rate_type     VARCHAR2(30) := X_project_rate_type;
3460     l_project_exchange_rate NUMBER       := X_project_exchange_rate;
3461 
3462     l_projfunc_cost_rate_date     DATE         := p_projfunc_cost_rate_date;
3463     l_projfunc_cost_rate_type     VARCHAR2(30) := p_projfunc_cost_rate_type;
3464     l_projfunc_cost_exchg_rate    NUMBER       := p_projfunc_cost_exchg_rate;
3465     l_denom_currency_code         VARCHAR2(30) := NULL;
3466 
3467     l_assignment_id         NUMBER;
3468     l_assignment_name       VARCHAR2(80);
3469     l_work_type_id          NUMBER;
3470     l_work_type_name        VARCHAR2(80);
3471     l_tp_amt_type_code      VARCHAR2(80);
3472     l_error_status          VARCHAR2(80);
3473     l_error_message_code    VARCHAR2(800);
3474     l_dest_lcm             VARCHAR2(20) DEFAULT NULL;
3475     l_acct_rate_date       date;
3476     l_acct_rate_type       varchar2(100);
3477     l_acct_exchange_rate   number;
3478     l_project_currency_code varchar2(100) := x_project_currency_code;
3479     l_denom_burdened_cost   NUMBER; --Added for bug 6031129
3480 
3481 
3482 /* changing the cursor select below for the raw_cost and burden_cost
3483   to make it null always. The costing program would fill in the raw cost
3484   with the acct_raw_cost for VI and ER when the curr codes are same */
3485 
3486     CURSOR Items ( X_expenditure_item_id IN NUMBER ) IS
3487       SELECT
3488           ei.billable_flag
3489        ,  ei.bill_hold_flag
3490        ,  NULL raw_cost
3491        ,  decode(ei.system_linkage_function, 'VI',
3492                  ei2.raw_cost_rate,
3493                  decode(ts.costed_flag,
3494 			'Y', ei2.raw_cost_rate,
3495 			NULL)) raw_cost_rate
3496        ,  NULL burden_cost
3497           /*,  decode( ei.system_linkage_function, 'VI',
3498                        ei.override_to_organization_id, NULL ) override_to_org */
3499            /* Modified For Bug2235662 */
3500        ,   decode(ei.system_linkage_function,
3501 		  'VI',ei.override_to_organization_id,
3502 		  'ER',decode(ei.transaction_source,
3503 			      null,null,
3504 			      ei.override_to_organization_id),
3505 		  null) override_to_org
3506        ,   ei.organization_id   nl_resource_org_id
3507        ,   ei.transaction_source
3508        ,   ei.vendor_id vendor_id /* R12 Changes - removed reference to cdl.system_reference1 */
3509        ,   ei.attribute_category
3510        ,   ei.attribute1
3511        ,   ei.attribute2
3512        ,   ei.attribute3
3513        ,   ei.attribute4
3514        ,   ei.attribute5
3515        ,   ei.attribute6
3516        ,   ei.attribute7
3517        ,   ei.attribute8
3518        ,   ei.attribute9
3519        ,   ei.attribute10
3520        ,   ec.expenditure_comment
3521        ,   decode(ei.system_linkage_function, 'VI',
3522            NVL(ei.override_to_organization_id,e.incurred_by_organization_id), /*Modified for bug 7422380*/
3523              e.incurred_by_organization_id )   inc_by_org_id
3524        ,   e.incurred_by_person_id inc_by_person_id
3525        ,   ei.expenditure_item_date
3526        ,   decode(ei.transaction_source,'PTE TIME',NULL,
3527            decode(ei.transaction_source,'PTE EXPENSE',NULL,
3528            decode(ei.transaction_source,'ORACLE TIME AND LABOR',NULL,
3529            decode(ei.transaction_source,'Oracle Self Service Time',NULL,
3530                  ei.orig_transaction_reference)))) orig_transaction_reference
3531        ,   ei.expenditure_type
3532        ,   ei.system_linkage_function
3533        ,   ei.non_labor_resource
3534        ,   ei.quantity
3535        ,   e.expenditure_id
3536        ,   ei.expenditure_item_id transferred_from_exp_item_id
3537        ,   ei.adjusted_expenditure_item_id expenditure_item_id
3538        ,   ei.job_id
3539        ,   ei.org_id
3540        ,   ei.burden_sum_dest_run_id
3541        ,   ei.receipt_currency_amount
3542        ,   ei.receipt_currency_code
3543        ,   ei.receipt_exchange_rate
3544        ,   ei.denom_currency_code
3545        ,  decode(ei.system_linkage_function, 'VI', ei2.denom_raw_cost,
3546           'ER', ei2.denom_raw_cost,decode( ts.costed_flag, 'Y',
3547            ei2.denom_raw_cost, NULL)) denom_raw_cost
3548        ,  decode( ts.allow_burden_flag, 'Y',decode(getprojburdenflag(ei.project_id),'N',NULL,
3549            ei2.denom_burdened_cost), NULL) denom_burdened_cost  /*Bug# 5874347*/
3550        ,   ei.acct_currency_code
3551        ,   decode(ei.system_linkage_function,'VI',ei2.acct_rate_date,
3552            'ER',ei2.acct_rate_date, decode(ts.gl_accounted_flag,'Y',
3553         	ei2.acct_rate_date,decode(ei.acct_rate_type,'User',ei.acct_rate_date,NULL))) acct_rate_date --Bug#3787213
3554        ,   decode(ei.system_linkage_function,'VI',ei2.acct_rate_type,
3555         	'ER',ei2.acct_rate_type, decode(ts.gl_accounted_flag,'Y',
3556 		ei2.acct_rate_type,decode(ei.acct_rate_type,'User',ei.acct_rate_type,NULL))) acct_rate_type  --Bug#3787213
3557        ,   decode(ei.system_linkage_function,'VI',ei2.acct_exchange_rate,
3558 		'ER',ei2.acct_exchange_rate, decode(ts.gl_accounted_flag,'Y',
3559 		ei2.acct_exchange_rate,decode(ei.acct_rate_type,'User',ei.acct_exchange_rate,NULL))) acct_exchange_rate  --Bug#3787213
3560        ,  decode(ei.system_linkage_function, 'VI', ei2.acct_raw_cost,
3561 		'ER', ei2.acct_raw_cost, decode( ts.gl_accounted_flag, 'Y',
3562 		ei2.acct_raw_cost, NULL)) acct_raw_cost
3563        ,   ei.acct_exchange_rounding_limit
3564        ,   decode(ei.system_linkage_function, 'VI','Y', 'ER','Y',
3565         	nvl(ts.gl_accounted_flag,'N')) gl_accounted_flag
3566        /* ,  ei.cc_cross_charge_code          -- cc_cross_charge_code
3567        ,  ei.cc_prvdr_organization_id      -- cc_prvdr_organization_id
3568        ,  ei.cc_recvr_organization_id      -- cc_recvr_organization_id
3569        ,  ei.cc_rejection_code             -- cc_rejection_code
3570        ,  ei.denom_tp_currency_code        -- denom_tp_currency_code
3571        ,  ei.denom_transfer_price          -- denom_transfer_price
3572        ,  ei.acct_tp_rate_type             -- acct_tp_rate_type
3573        ,  ei.acct_tp_rate_date             -- acct_tp_rate_date
3574        ,  ei.acct_tp_exchange_rate         -- acct_tp_exchange_rate
3575        ,  ei.acct_transfer_price           -- acct_transfer_price
3576        ,  ei.projacct_transfer_price        -- projacct_transfer_price
3577        ,  ei.cc_markup_base_code           -- cc_markup_base_code
3578        ,  ei.tp_base_amount                -- tp_base_amount
3579        ,  ei.cc_cross_charge_type          -- cc_cross_charge_type
3580        ,  ei.recvr_org_id                  -- recvr_org_id
3581        ,  ei.cc_bl_distributed_code        -- cc_bl_distributed_code
3582        ,  ei.cc_ic_processed_code          -- cc_ic_processed_code
3583        ,  ei.tp_ind_compiled_set_id        -- tp_ind_compiled_set_id
3584        ,  ei.tp_bill_rate                  -- tp_bill_rate
3585        ,  ei.tp_bill_markup_percentage     -- tp_bill_markup_percentage
3586        ,  ei.tp_schedule_line_percentage   -- tp_schedule_line_percentage
3587        ,  ei.tp_rule_percentage            -- tp_rule_percentage
3588          */
3589        ,  NULL  project_raw_cost
3590        ,  NULL  project_burdened_cost
3591        ,  ei.assignment_id
3592        ,  ei.work_type_id
3593        ,  ei.project_rate_type
3594        ,  ei.project_rate_date
3595        ,  ei.project_exchange_rate
3596        ,  e.person_type -- Fix for bug : 3681318
3597        ,  decode(ei.system_linkage_function,'BTC',ei.acct_burdened_cost,null) acct_burdened_cost /* bug 3669152 */
3598        ,  ei.project_currency_code        --Start of Bug#3787213. 5 Columns added
3599        ,  ei.projfunc_currency_code
3600        ,  ei.projfunc_cost_rate_type
3601        ,  ei.projfunc_cost_rate_date
3602        ,  ei.projfunc_cost_exchange_rate  --End of Bug#3787213.
3603        ,  ei.inventory_item_id -- Bug 4320459
3604        ,  ei.unit_of_measure   -- Bug 4320459
3605 /* R12 Changes -Start */
3606        ,  ei.document_header_id
3607        ,  ei.document_distribution_id
3608        ,  ei.document_line_number
3609        ,  ei.document_payment_id
3610        ,  ei.vendor_id ei_vendor_id
3611        ,  ei.document_type
3612        ,  ei.document_distribution_type
3613 /* R12 Changes - End */
3614      FROM
3615            pa_expenditures_all e
3616        ,   pa_expenditure_items_all ei
3617        ,   pa_expenditure_items_all ei2
3618        ,   pa_transaction_sources ts
3619        ,   pa_expenditure_comments ec
3620 /* R12 changes - Removed table pa_cost_distribution_lines */
3621     WHERE
3622            e.expenditure_id           = ei.expenditure_id
3623       AND  ei.expenditure_item_id     = ei2.expenditure_item_id
3624 /* R12 Changes - Removed join conditions for pa_cost_distribution_lines table */
3625       AND  ei2.transaction_source     = ts.transaction_source (+)
3626       AND  ei.expenditure_item_id     = X_expenditure_item_id
3627       AND  ec.expenditure_item_id  (+)= ei.expenditure_item_id ;
3628 
3629 /* Commented the following code as part of Bug#2291180 -- Start
3630   -- EFC bug2259454 changes
3631   Function get_denom_curr_code2 (l_exp_type in varchar2,
3632 		                 l_denom_currency_code in varchar2,
3633 		                 l_acct_currency_code in varchar2,
3634 		                 l_system_linkage_function in varchar2) return varchar2 is
3635 
3636      l_cost_rate_flag varchar2(30);
3637      l_return varchar2(30);
3638 
3639   Begin
3640 
3641 	If l_system_linkage_function in ('ST','OT') Then
3642 		If l_acct_currency_code = l_denom_currency_code Then
3643 			l_return := l_denom_currency_code;
3644 		Else
3645 			l_return := pa_currency.get_currency_code;
3646 		End If;
3647 	Else
3648         	select cost_rate_flag
3649         	into l_cost_rate_flag
3650         	from pa_expenditure_types
3651         	where expenditure_type = l_exp_type;
3652 
3653 		If l_cost_rate_flag = 'Y' Then
3654 			If l_acct_currency_code = l_denom_currency_code Then
3655 				l_return := l_denom_currency_code;
3656 			Else
3657 				l_return := pa_currency.get_currency_code;
3658 			End If;
3659 		Else
3660                       	l_return := l_denom_currency_code;
3661 		End If;
3662 	End If;
3663 
3664 	return l_return;
3665 
3666   End get_denom_curr_code2;
3667  Commented the above code as part of Bug#2291180 -- End */
3668 
3669 -- Start of Transfer main PL/SQL block
3670 
3671   BEGIN
3672 
3673     IF P_DEBUG_MODE  THEN
3674        print_message('get_denom_curr_code: ' || 'inside Transfer api');
3675     END IF;
3676     l_dest_lcm  := pa_utils2.GetLaborCostMultiplier(X_dest_task_id);
3677     FOR i IN 1..rows LOOP
3678 
3679       FOR  EiRec  IN Items( ItemsIdTab(i) )  LOOP
3680 
3681 	/** derive the destination project currency code based on destination task and destination project **/
3682 	--IF X_project_currency_code is NULL then
3683 	    BEGIN
3684 		SELECT decode(project_currency_code,NULL,projfunc_currency_code,project_currency_code)
3685 		INTO l_project_currency_code
3686 		FROM pa_projects_all
3687 		WHERE project_id = x_dest_prj_id;
3688 	    EXCEPTION
3689 		WHEN NO_DATA_FOUND then
3690 		        Raise;
3691 
3692 		WHEN OTHERS  then
3693 			Raise;
3694 	    END;
3695 
3696 	--End if;
3697 
3698       /* BEGIN
3699         --Added this block for bug 5759574
3700 		--Reverted this check for bug 7454045
3701 
3702          SELECT w.name
3703          INTO l_work_type_name
3704          FROM pa_work_types_v w
3705          WHERE w.work_type_id = eirec.work_type_id;
3706 
3707        EXCEPTION
3708          WHEN others THEN
3709          NULL;
3710        END; */
3711 
3712 	IF P_DEBUG_MODE  THEN
3713 	   print_message('get_denom_curr_code: ' || 'calling get work type assignment api');
3714 	END IF;
3715 	/** derive work type and assignment for the destination task , project **/
3716  	Pa_Utils4.Get_Work_Assignment (
3717 	    p_person_id  	     => EiRec.inc_by_person_id
3718 	   ,p_project_id 	     => X_dest_prj_id
3719 	   ,p_task_id    	     => X_dest_task_id
3720 	   ,p_ei_date    	     => EiRec.expenditure_item_date
3721 	   ,p_system_linkage 	 => EiRec.system_linkage_function
3722 	   ,x_assignment_id  	 => l_assignment_id
3723        ,x_assignment_name 	 => l_assignment_name
3724        ,x_work_type_id    	 => l_work_type_id
3725        ,x_work_type_name  	 => l_work_type_name
3726 	   ,x_tp_amt_type_code 	 => l_tp_amt_type_code
3727        ,x_return_status    	 => l_error_status
3728        ,x_error_message_code => l_error_message_code);
3729 
3730 	-- EFC bug2259454 change
3731 	l_denom_currency_code := get_denom_curr_code (EiRec.transaction_source,
3732                                                   EiRec.expenditure_type,
3733 						                          EiRec.denom_currency_code,
3734                                                   EiRec.acct_currency_code,
3735 						                          EiRec.system_linkage_function);
3736 
3737 	IF P_DEBUG_MODE  THEN
3738 	   print_message('get_denom_curr_code: ' || 'after get work assign l_assignment_id['||l_assignment_id||
3739 	              ']l_assignment_name['||l_assignment_name||']l_work_type_id ['||l_work_type_id||
3740 		      ']l_work_type_name['||l_work_type_name||']x_tp_amt_type_code['||l_tp_amt_type_code|| ']' );
3741 	END IF;
3742 	l_acct_rate_date           := EiRec.acct_rate_date;
3743 	l_acct_rate_type           := EiRec.acct_rate_type;
3744 	l_acct_exchange_rate       := EiRec.acct_exchange_rate;
3745 /*Bug#3787213. Added if condition for validating the source and destination currency code for rate type 'User'
3746 If source and destination currencies are same for User rate_type then we are copying the rate_type,
3747 rate_date, and exchange_rate.
3748 */
3749 	IF EiRec.project_currency_code = l_project_currency_code
3750 	   and EiRec.projfunc_currency_code = p_projfunc_currency_code
3751 	   and l_acct_rate_type = 'User' THEN
3752 
3753 		l_project_rate_type        := EiRec.project_rate_type;
3754 		l_project_rate_date        := EiRec.project_rate_date;
3755 		l_project_exchange_rate    := EiRec.project_exchange_rate;
3756 		l_projfunc_cost_rate_type  := EiRec.projfunc_cost_rate_type;
3757 		l_projfunc_cost_rate_date  := EiRec.projfunc_cost_rate_date;
3758 		l_projfunc_cost_exchg_rate := EiRec.projfunc_cost_exchange_rate;
3759 
3760 	ELSE
3761 
3762 		pa_multi_currency_txn.get_currency_attributes (
3763 		   P_TASK_ID               	=> X_dest_task_id,
3764 		   P_EI_DATE               	=> Eirec.expenditure_item_date,
3765 		   P_CALLING_MODULE        	=> 'TRANSFER',
3766 	--     P_DENOM_CURR_CODE       	=> EiRec.denom_currency_code,
3767 		   P_DENOM_CURR_CODE        => l_denom_currency_code,  -- EFC bug2259454 change
3768 		   P_ACCT_CURR_CODE        	=> EiRec.acct_currency_code,
3769 		   P_ACCOUNTED_FLAG        	=> EiRec.gl_accounted_flag,
3770 		   x_ACCT_RATE_DATE        	=> l_acct_rate_date,
3771 		   x_ACCT_RATE_TYPE        	=> l_acct_rate_type,
3772 		   x_ACCT_EXCH_RATE        	=> l_acct_exchange_rate,
3773 		   P_project_curr_code     	=> l_project_currency_code,
3774 		   x_project_rate_type     	=> l_project_rate_type,
3775 		   x_project_rate_date     	=> l_project_rate_date,
3776 		   x_project_exch_rate     	=> l_project_exchange_rate,
3777 		   P_PROJFUNC_CURR_CODE    	=> p_projfunc_currency_code,
3778 		   x_PROJFUNC_COST_RATE_TYPE => l_projfunc_cost_rate_type,
3779 		   x_PROJFUNC_COST_RATE_DATE => l_projfunc_cost_rate_date,
3780 		   x_PROJFUNC_COST_EXCH_RATE => l_projfunc_cost_exchg_rate,
3781 		   P_SYSTEM_LINKAGE         => EiRec.system_linkage_function,
3782 		   x_status                	=> temp_outcome,
3783 		   x_stage                 	=> temp_stage);
3784 	END IF;
3785 
3786 	IF P_DEBUG_MODE  THEN
3787 	   print_message('get_denom_curr_code: ' || 'after multi currency p_projfunc_currency_code['||p_projfunc_currency_code||
3788 	              ']l_projfunc_cost_rate_type['||l_projfunc_cost_rate_type||
3789 		      ']l_projfunc_cost_rate_date['||l_projfunc_cost_rate_date||
3790 		      ']l_projfunc_cost_exchg_rate['||l_projfunc_cost_exchg_rate||
3791 		      ']l_project_currency_code['||l_project_currency_code||
3792 		      ']l_project_rate_type ['||l_project_rate_type||']l_project_rate_date ['||l_project_rate_date||
3793 		      ']l_project_exchange_rate['||l_project_exchange_rate||']' );
3794 	END IF;
3795 
3796 
3797 	IF ( temp_outcome IS NOT NULL ) THEN
3798 
3799 		IF ( X_adjust_level = 'I' ) THEN
3800 		 	X_outcome := temp_outcome;
3801 		  	RETURN;
3802 		ELSE
3803 			temp_num_rejected := temp_num_rejected + 1;
3804 	  	    /* R12 Changes Start */
3805 	        InsAuditRec( ItemsIdTab(i)
3806                	           , 'TRANSFER DESTINATION'
3807                   	   , X_module
3808 	                   , X_user
3809           	           , X_login
3810                   	   , temp_status
3811 	                   , G_REQUEST_ID
3812           	           , G_PROGRAM_ID
3813                   	   , G_PROG_APPL_ID
3814 	                   , sysdate
3815           	           , temp_outcome);
3816 	                CheckStatus(temp_status);
3817 	  	    /* R12 Changes End */
3818           	temp_outcome := NULL;
3819 		END IF;
3820 
3821 	ELSE
3822 
3823       		EiRec.expenditure_item_id := pa_utils.GetNextEiId;
3824       		pa_transactions_pub.validate_transaction(
3825                        X_project_id           => X_dest_prj_id
3826                      , X_task_id 	      => X_dest_task_id
3827                      , X_ei_date 	      => EiRec.expenditure_item_date
3828                      , X_expenditure_type     => EiRec.expenditure_type
3829                      , X_non_labor_resource   => EiRec.non_labor_resource
3830                      , X_person_id 	      => EiRec.inc_by_person_id
3831                      , X_quantity 	      => EiRec.quantity
3832 --                   , X_denom_currency_code  => EiRec.denom_currency_code
3833 		             , X_denom_currency_code  => l_denom_currency_code  -- EFC bug2259454 change
3834 		             , X_acct_currency_code   => EiRec.Acct_currency_code
3835 		             , X_denom_raw_cost       => EiRec.denom_raw_cost
3836 		             , X_acct_raw_cost 	      => EiRec.acct_raw_cost
3837 		             , X_acct_rate_type       => l_acct_rate_type        --Bug#3787213. Eirec.acct_rate_type
3838 		             , X_acct_rate_date       => l_acct_rate_date        --Bug#3787213. Eirec.acct_rate_date
3839 		             , X_acct_exchange_rate   => l_acct_exchange_rate    --Bug#3787213. Eirec.acct_exchange_rate
3840                      , X_transfer_ei 	      => EiRec.transferred_from_exp_item_id
3841                      , X_incurred_by_org_id   => EiRec.inc_by_org_id
3842                      , X_nl_resource_org_id   => EiRec.nl_resource_org_id
3843                      , X_transaction_source   => EiRec.transaction_source
3844                      , X_calling_module       => X_module
3845                      , X_vendor_id 	      => EiRec.vendor_id
3846                      , X_entered_by_user_id   => X_user
3847                      , X_attribute_category   => EiRec.attribute_category
3848                      , X_attribute1 	      => EiRec.attribute1
3849                      , X_attribute2 	      => EiRec.attribute2
3850                      , X_attribute3 	      => EiRec.attribute3
3851                      , X_attribute4 	      => EiRec.attribute4
3852                      , X_attribute5 	      => EiRec.attribute5
3853                      , X_attribute6 	      => EiRec.attribute6
3854                      , X_attribute7 	      => EiRec.attribute7
3855                      , X_attribute8 	      => EiRec.attribute8
3856                      , X_attribute9 	      => EiRec.attribute9
3857                      , X_attribute10 	      => EiRec.attribute10
3858 		             , X_attribute11          => ''
3859 		             , X_attribute12 	      => ''
3860 		             , X_attribute13 	      => ''
3861 		             , X_attribute14 	      => ''
3862 		             , X_attribute15 	      => ''
3863 		             , X_msg_application      => temp_msg_application
3864 		             , X_msg_type 	      => temp_msg_type
3865 		             , X_msg_token1 	      => temp_msg_token1
3866 		             , X_msg_token2 	      => temp_msg_token2
3867 		             , X_msg_token3 	      => temp_msg_token3
3868 		             , X_msg_count 	      => temp_msg_count
3869                      , X_msg_data 	      => temp_outcome
3870                      , X_billable_flag        => EiRec.billable_flag
3871             	     , p_projfunc_currency_code => p_projfunc_currency_code
3872             	     , p_projfunc_cost_rate_type => l_projfunc_cost_rate_type
3873             	     , p_projfunc_cost_rate_date => l_projfunc_cost_rate_date
3874             	     , p_projfunc_cost_exchg_rate =>l_projfunc_cost_exchg_rate
3875             	     , p_assignment_id          => l_assignment_id
3876             	     , p_work_type_id           => l_work_type_id
3877 		             , p_sys_link_function      => EiRec.system_linkage_function
3878                      , p_person_type           =>  EiRec.person_type );   -- Fix for bug : 3681318
3879 
3880             /* Start of Bug 2648550 */
3881 		    l_assignment_id := PATC.G_OVERIDE_ASSIGNMENT_ID;
3882 		    l_work_type_id := PATC.G_OVERIDE_WORK_TYPE_ID;
3883 		    l_tp_amt_type_code := PATC.G_OVERIDE_TP_AMT_TYPE_CODE;
3884             /* End of Bug 2648550 */
3885 
3886 		    IF ( temp_outcome IS NOT NULL AND ( temp_msg_type = 'E' ) ) THEN /* Added msg_type check for Bug 4906816 */
3887 			/*Changes for 7371988 Starts here*/
3888 
3889         		IF ( X_adjust_level = 'I' ) THEN
3890           			X_outcome         := temp_outcome;
3891 			 	    X_msg_application := temp_msg_application;
3892 			 	    X_msg_type        := temp_msg_type;
3893 			 	    X_msg_token1      := temp_msg_token1;
3894 			 	    X_msg_token2      := temp_msg_token2;
3895 			 	    X_msg_token3      := temp_msg_token3;
3896 			 	    X_msg_count       := temp_msg_count;
3897           			RETURN;
3898 				ELSE
3899           			temp_num_rejected := temp_num_rejected + 1;
3900           			temp_outcome      := NULL;
3901         		END IF;
3902 
3903 			ELSE
3904 
3905 		/* Added for Bug 4906816 */
3906 				IF ( ( temp_outcome IS NOT NULL ) AND ( temp_msg_type = 'W' ) ) THEN
3907 					IF ( X_adjust_level = 'I' ) THEN
3908 					X_outcome         := temp_outcome;
3909 					X_msg_application := temp_msg_application;
3910 					X_msg_type        := temp_msg_type;
3911 					X_msg_token1      := temp_msg_token1;
3912 					X_msg_token2      := temp_msg_token2;
3913 					X_msg_token3      := temp_msg_token3;
3914 					X_msg_count       := temp_msg_count;
3915 					END IF;
3916 				END IF;
3917 
3918           			--temp_num_rejected := temp_num_rejected + 1;
3919 		  	        /* R12 Changes Start */
3920 		            InsAuditRec( ItemsIdTab(i)
3921 	            	               , 'TRANSFER DESTINATION'
3922 	                  	       , X_module
3923 		                       , X_user
3924 	          	               , X_login
3925         	          	       , temp_status
3926 	        	               , G_REQUEST_ID
3927           	        	       , G_PROGRAM_ID
3928                   	               , G_PROG_APPL_ID
3929 		                       , sysdate
3930         	  	               , temp_outcome);
3931 	        	    CheckStatus(temp_status);
3932 		  	        /* R12 Changes End */
3933           			temp_outcome      := NULL;
3934 
3935         		--END IF;
3936 
3937 		    --ELSE
3938 /*Changes for 7371988 ends here*/
3939       			temp_num_processed := temp_num_processed + 1;
3940 
3941                             select decode(getprojburdenflag(X_dest_prj_id),   -- Bug#Bug6031129
3942                                           'N',null,EiRec.denom_burdened_cost)
3943                             into  l_denom_burdened_cost
3944                             from dual;
3945 
3946 			    /* NO IC Changes required. A transfer is considered a new txn
3947 			       For new txns the Cross Charge attributes are populated by
3948 			       IC processes.
3949 			    */
3950       			pa_transactions.LoadEi(
3951                                     X_expenditure_item_id     =>	EiRec.expenditure_item_id
3952                                    ,X_expenditure_id          =>	EiRec.expenditure_id
3953                                    ,X_expenditure_item_date   =>	EiRec.expenditure_item_date
3954                                    ,X_project_id              =>	X_dest_prj_id  --NULL
3955                                    ,X_task_id                 =>	X_dest_task_id
3956                                    ,X_expenditure_type        =>	EiRec.expenditure_type
3957                                    ,X_non_labor_resource      =>	EiRec.non_labor_resource
3958                                    ,X_nl_resource_org_id      =>	EiRec.nl_resource_org_id
3959                                    ,X_quantity                =>	EiRec.quantity
3960                                    ,X_raw_cost                =>        EiRec.raw_cost
3961                                    ,X_raw_cost_rate           =>	EiRec.raw_cost_rate
3962                                    ,X_override_to_org_id      =>	EiRec.override_to_org
3963                                    ,X_billable_flag           =>	EiRec.billable_flag
3964                                    ,X_bill_hold_flag          =>	EiRec.bill_hold_flag
3965                                    ,X_orig_transaction_ref    =>	EiRec.orig_transaction_reference
3966                                    ,X_transferred_from_ei     =>	EiRec.transferred_from_exp_item_id
3967                                    ,X_adj_expend_item_id      =>	to_number( NULL )
3968                                    ,X_attribute_category      =>	EiRec.attribute_category
3969                                    ,X_attribute1              =>	EiRec.attribute1
3970                                    ,X_attribute2              =>	EiRec.attribute2
3971                                    ,X_attribute3              =>	EiRec.attribute3
3972                                    ,X_attribute4              =>	EiRec.attribute4
3973                                    ,X_attribute5              =>	EiRec.attribute5
3974                                    ,X_attribute6              =>	EiRec.attribute6
3975                                    ,X_attribute7              =>	EiRec.attribute7
3976                                    ,X_attribute8              =>	EiRec.attribute8
3977                                    ,X_attribute9              =>	EiRec.attribute9
3978                                    ,X_attribute10             =>	EiRec.attribute10
3979                                    ,X_ei_comment              =>	EiRec.expenditure_comment
3980                                    ,X_transaction_source      =>	EiRec.transaction_source
3981                                    ,X_source_exp_item_id      =>	to_number( NULL )
3982                                    ,i                         =>	temp_num_processed
3983                                    ,X_job_id                  =>	EiRec.job_id
3984                                    ,X_org_id                  =>	EiRec.org_id
3985                                    ,X_labor_cost_multiplier_name =>     l_dest_lcm
3986                                    ,X_drccid                  =>	NULL
3987                                    ,X_crccid                  =>	NULL
3988                                    ,X_cdlsr1                  =>	NULL
3989                                    ,X_cdlsr2                  =>	NULL
3990                                    ,X_cdlsr3                  =>	NULL
3991                                    ,X_gldate                  =>	NULL
3992                                    ,X_bcost                   =>	NULL  /* Bug#1263399 */
3993                                    ,X_bcostrate               =>	NULL
3994                                    ,X_etypeclass              =>	EiRec.system_linkage_function
3995                                    ,X_burden_sum_dest_run_id  =>	EiRec.burden_sum_dest_run_id
3996                                    ,X_burden_compile_set_id   =>	NULL
3997                                    ,X_receipt_currency_amount =>	EiRec.receipt_currency_amount
3998                                    ,X_receipt_currency_code   =>	EiRec.receipt_currency_code
3999                                    ,X_receipt_exchange_rate   =>	EiRec.receipt_exchange_rate
4000                                    -- ,X_denom_currency_code     =>	EiRec.denom_currency_code
4001 				                   ,X_denom_currency_code     =>        l_denom_currency_code -- EFC bug2259454 change
4002                                    ,X_denom_raw_cost          =>	EiRec.denom_raw_cost
4003                                    ,X_denom_burdened_cost     =>	l_denom_burdened_cost  -- Bug#6031129
4004                                    ,X_acct_currency_code      =>	EiRec.acct_currency_code
4005                                    ,X_acct_rate_date          =>	l_acct_rate_date     --Bug#3787213. Eirec.acct_rate_date
4006                                    ,X_acct_rate_type          =>	l_acct_rate_type     --Bug#3787213. Eirec.acct_rate_type
4007                                    ,X_acct_exchange_rate      =>	l_acct_exchange_rate --Bug#3787213. Eirec.acct_exchange_rate
4008                                    ,X_acct_raw_cost           =>	EiRec.acct_raw_cost
4009                                    ,X_acct_burdened_cost      =>        EiRec.acct_burdened_cost /* bug 3669152 */
4010                                    ,X_acct_exchange_rounding_limit  =>	EiRec.acct_exchange_rounding_limit
4011                                    ,X_project_currency_code   =>	l_project_currency_code
4012                                    ,X_project_rate_date       =>	l_project_rate_date
4013                                    ,X_project_rate_type       =>	l_project_rate_type
4014                                    ,X_project_exchange_rate   =>	l_project_exchange_rate
4015                    		           , p_assignment_id                =>  l_assignment_id
4016                    		           , p_work_type_id                 =>  l_work_type_id
4017                    		           , p_projfunc_currency_code       =>  p_projfunc_currency_code
4018                    		           , p_projfunc_cost_rate_date      =>  l_projfunc_cost_rate_date
4019                    		           , p_projfunc_cost_rate_type      =>  l_projfunc_cost_rate_type
4020                    		           , p_projfunc_cost_exchange_rate  =>  l_projfunc_cost_exchg_rate
4021                    		           , p_project_raw_cost             =>  EiRec.project_raw_cost
4022                    		           , p_project_burdened_cost        =>  EiRec.project_burdened_cost
4023 				                   , p_tp_amt_type_code             =>  l_tp_amt_type_code
4024                                    , p_Inventory_Item_Id      =>       EiRec.inventory_item_id -- Bug 4320459
4025                                    , p_Unit_Of_Measure        =>       EiRec.unit_of_measure -- Bug 4320459
4026                  /* R12 Changes - Start */
4027  		                  , p_document_header_id      =>       EiRec.document_header_id
4028      		                  , p_document_distribution_id =>      EiRec.document_distribution_id
4029 		                  , p_document_line_number    =>       EiRec.document_line_number
4030 		                  , p_document_payment_id     =>       EiRec.document_payment_id
4031 		                  , p_vendor_id               =>       EiRec.vendor_id
4032 		                  , p_document_type           =>       EiRec.document_type
4033 		                  , p_document_distribution_type =>    EiRec.document_distribution_type
4034                  /* R12 Changes - End */
4035                                   ) ;
4036 
4037 		END IF; -- End temp_outcome is not null for get_status
4038 
4039 	END IF; -- End temp_outcome is not null for get_currency_attributes
4040 
4041     END LOOP;
4042 
4043   END LOOP;
4044 
4045   pa_transactions.InsItems( X_user                =>	X_user
4046                             , X_login             =>	X_login
4047                             , X_module            =>	X_module
4048                             , X_calling_process   =>	'TRANSFER'
4049                             , Rows                =>	temp_num_processed
4050                             , X_status            => 	temp_status
4051                             , X_gl_flag           =>	NULL );
4052 
4053     -- -------------------------------------------------------------------------
4054     -- OGM_0.0 : OGM needs to create additional details for each expenditure
4055     -- item created here. VERT_ADJUST_ITEMS does that for vertical applications.
4056     -- If temp_status is not null it does nothing else process the additional
4057     -- details and set temp_status in case of system exceptions.
4058     -- --------------------------------------------------------------------------
4059     PA_GMS_API.VERT_ADJUST_ITEMS( 'TRANSFER', temp_num_processed, temp_status ) ;
4060 
4061     CheckStatus( status_indicator => temp_status );
4062 
4063     X_num_processed := temp_num_processed;
4064     X_num_rejected  := temp_num_rejected;
4065     /* X_outcome       := NULL; Bug 4906816 - Commented to carry forward warnings also */
4066 
4067   EXCEPTION
4068     WHEN  OTHERS  THEN
4069       X_outcome := SQLCODE;
4070       RAISE;
4071 
4072   END  Transfer;
4073 
4074 
4075 -- ========================================================================
4076 -- PROCEDURE Adjust
4077 -- ========================================================================
4078 -- Added new parameters acct rate attributes for the new rate adjustments
4079 
4080   PROCEDURE  Adjust( X_adj_action           IN VARCHAR2
4081                    , X_module               IN VARCHAR2
4082                    , X_user                 IN NUMBER
4083                    , X_login                IN NUMBER
4084                    , X_project_id           IN NUMBER
4085                    , X_adjust_level         IN VARCHAR2
4086                    , X_expenditure_item_id  IN NUMBER
4087                    , X_dest_prj_id          IN NUMBER
4088                    , X_dest_task_id         IN NUMBER
4089                    , X_project_currency_code IN VARCHAR2
4090                    , X_project_rate_type     IN VARCHAR2
4091                    , X_project_rate_date     IN DATE
4092                    , X_project_exchange_rate IN NUMBER
4093 		           , X_acct_rate_type        IN VARCHAR2
4094 		           , X_acct_rate_date        IN DATE
4095 		           , X_acct_exchange_rate    IN NUMBER
4096                    , X_task_id              IN NUMBER
4097                    , X_inc_by_person_id     IN NUMBER
4098                    , X_inc_by_org_id        IN NUMBER
4099                    , X_ei_date_low          IN DATE
4100                    , X_ei_date_high         IN DATE
4101                    , X_system_linkage       IN VARCHAR2
4102                    , X_expenditure_type     IN VARCHAR2
4103                    , X_vendor_id            IN NUMBER
4104                    , X_nl_resource_org_id   IN NUMBER
4105                    , X_nl_resource          IN VARCHAR2
4106                    , X_bill_status          IN VARCHAR2
4107                    , X_hold_flag            IN VARCHAR2
4108                    , X_expenditure_comment  IN VARCHAR2
4109                    , X_inv_num              IN NUMBER
4110                    , X_inv_line_num         IN NUMBER
4111                    , X_cc_code              IN VARCHAR2
4112                    , X_cc_type              IN VARCHAR2
4113                    , X_bl_dist_code         IN VARCHAR2
4114                    , X_ic_proc_code         IN VARCHAR2
4115                    , X_prvdr_orgnzn_id      IN NUMBER
4116                    , X_recvr_orgnzn_id      IN NUMBER
4117                    , X_outcome              OUT NOCOPY VARCHAR2
4118                    , X_num_processed        OUT NOCOPY NUMBER
4119                    , X_num_rejected         OUT NOCOPY NUMBER
4120 	               , X_msg_application 	  OUT NOCOPY VARCHAR2
4121 		           , X_msg_type		  OUT NOCOPY VARCHAR2
4122 	               , X_msg_token1 	  OUT NOCOPY VARCHAR2
4123 		           , X_msg_token2  	  OUT NOCOPY VARCHAR2
4124 		           , X_msg_token3  	  OUT NOCOPY VARCHAR2
4125 		           , X_msg_count	  OUT NOCOPY Number
4126                     /* added for proj currency  and additional EI attributes **/
4127                    , p_assignment_id                IN NUMBER
4128                    , p_work_type_id                 IN NUMBER
4129                    , p_projfunc_currency_code       IN varchar2
4130                    , p_projfunc_cost_rate_date      IN date
4131                    , p_projfunc_cost_rate_type      IN varchar2
4132                    , p_projfunc_cost_exchange_rate  IN number
4133                    , p_project_raw_cost             IN number
4134                    , p_project_burdened_cost        IN number
4135                    , p_project_tp_currency_code     IN varchar2
4136                    , p_project_tp_cost_rate_date    IN date
4137                    , p_project_tp_cost_rate_type    IN  varchar2
4138                    , p_project_tp_cost_exchg_rate   IN number
4139                    , p_project_transfer_price       IN number
4140                    , p_dest_work_type_id            IN NUMBER
4141                    , p_tp_amt_type_code             IN varchar2
4142                    , p_dest_tp_amt_type_code        IN varchar2
4143                     /** end of proj currency  and additional EI attributes **/
4144                     ) IS
4145 
4146     ItemsIdTab              pa_utils.IdTabTyp;
4147     AdjustsIdTab            pa_utils.IdTabTyp;
4148     DenomCurrCodeTab        pa_utils.Char15TabTyp;
4149     ProjCurrCodeTab         pa_utils.Char15TabTyp;
4150     ProjFuncCurrCodeTab     pa_utils.Char15TabTyp;
4151 
4152     TpAmtTypCodeTab         pa_utils.Char30TabTyp;
4153 
4154     dummy               	NUMBER;
4155     temp_outcome        	VARCHAR2(30) DEFAULT NULL;
4156     temp_status         	NUMBER DEFAULT NULL;
4157     temp_num_processed  	NUMBER DEFAULT 0;
4158     temp_num_rejected   	NUMBER DEFAULT 0;
4159 	temp_msg_application   VARCHAR2(30) :='PA';
4160 	temp_msg_type				VARCHAR2(1) := 'E';
4161 	temp_msg_token1			Varchar2(240) := '';
4162 	temp_msg_token2			Varchar2(240) :='';
4163 	temp_msg_token3			Varchar2(240) :='';
4164 	temp_msg_count			Number ;
4165     i                   	BINARY_INTEGER := 0;
4166     adj_ei              	number;
4167     RelLockStatus number := 0;  /* Bug#3598333 */
4168 
4169 
4170     CURSOR  GetPrjExpSummary  IS
4171       SELECT
4172               ei.expenditure_item_id
4173       ,       eia.expenditure_item_id   adj_expenditure_item_id
4174         FROM
4175               pa_expenditures_all e
4176       ,       pa_expenditure_items_all ei
4177       ,       pa_expenditure_items_all eia
4178        WHERE
4179               ei.expenditure_item_id = eia.adjusted_expenditure_item_id (+)
4180          AND  ei.expenditure_id = e.expenditure_id
4181          AND  ei.task_id IN
4182 
4183 		( SELECT
4184                           t.task_id
4185                     FROM
4186                           pa_tasks t
4187                    WHERE
4188                           t.project_id = X_project_id
4189                      AND  t.task_id = nvl( X_task_id, t.task_id )
4190 		)
4191 
4192          AND  (    X_inc_by_person_id IS NULL
4193                 OR e.incurred_by_person_id = X_inc_by_person_id )
4194          AND  (    X_inc_by_org_id IS NULL
4195                 OR e.incurred_by_organization_id = X_inc_by_org_id
4196                 OR (    e.incurred_by_organization_id IS NULL
4197                     AND ei.override_to_organization_id = X_inc_by_org_id ))
4198          AND  (    X_vendor_id IS NULL
4199                 OR X_vendor_id = ei.vendor_id) /* R12 changes - Removed reference t ocdl.system_reference1 */
4200          AND  (    X_system_linkage IS NULL
4201                 OR  ei.system_linkage_function = X_system_linkage )
4202 /* commented the following lines for mfg changes and added the one line above
4203                 OR EXISTS
4204                      ( SELECT  NULL
4205                          FROM
4206                                pa_expenditure_types et
4207                         WHERE
4208                                et.expenditure_type = ei.expenditure_type
4209                           AND  ei.system_linkage_function = X_system_linkage ))
4210 */
4211          AND  ei.expenditure_type =
4212                    nvl( X_expenditure_type, ei.expenditure_type )
4213          AND  (    X_nl_resource_org_id IS NULL
4214                 OR ei.organization_id = X_nl_resource_org_id )
4215          AND  (    X_nl_resource IS NULL
4216                 OR ei.non_labor_resource = X_nl_resource )
4217          AND  (    X_hold_flag IS NULL
4218                 OR ei.bill_hold_flag = decode( X_hold_flag, 'B',
4219                    decode( ei.bill_hold_flag, 'N', 'Z', ei.bill_hold_flag ),
4220                       ei.bill_hold_flag ) )
4221          AND  ei.expenditure_item_date BETWEEN
4222                      nvl( X_ei_date_low, ei.expenditure_item_date )
4223                  AND nvl( X_ei_date_high, ei.expenditure_item_date )
4224          AND  ei.adjusted_expenditure_item_id IS NULL
4225          AND  (        X_bill_status IS NULL
4226                 OR
4227                    (   X_bill_status = 'U'
4228                     AND ei.project_id IS NULL
4229                     AND NOT EXISTS (
4230                         SELECT NULL
4231                           FROM
4232                                 pa_proj_invoice_details_view idv
4233                          WHERE
4234                                 idv.project_id+0 = X_project_id
4235                            AND  idv.expenditure_item_id =
4236                                                ei.expenditure_item_id ) )
4237                 OR
4238                    (    X_bill_status IN ( 'P', 'R', 'B' )
4239                     AND EXISTS (
4240                         SELECT
4241                                NULL
4242                           FROM
4243                                 pa_draft_invoices i
4244                         ,       pa_draft_invoice_items ii
4245                          WHERE
4246                                 i.project_id+0 = X_project_id
4247                            AND  i.project_id = ii.project_id
4248                            AND  i.draft_invoice_num = ii.draft_invoice_num
4249                            AND  nvl(ii.event_task_id, -1) =
4250                                    nvl(ei.event_task_id, -1)
4251                            AND  ii.project_id = ei.project_id
4252                            AND  ii.event_num = ei.event_num
4253                            AND  nvl( i.released_by_person_id, -1 ) =
4254                                  decode( X_bill_status, 'P', -1,
4255                                    'R', i.released_by_person_id,
4256                                    'B', nvl( i.released_by_person_id, -1), -2)))
4257                )
4258             AND (     1 = 2
4259 	       OR ( X_adj_action = 'CHANGE WORK TYPE ATTRIBUTE'  /** proj currency changes **/
4260                    AND nvl( ei.net_zero_adjustment_flag, 'N' ) <> 'Y'
4261                    AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4262                    AND ei.work_type_id <> p_dest_work_type_id
4263                    AND e.expenditure_status_code = 'APPROVED'
4264                   )
4265                OR
4266                   (    X_adj_action = 'PROJECT OR TASK CHANGE'
4267                    AND nvl( ei.net_zero_adjustment_flag, 'N' ) <> 'Y'
4268                    AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4269                    AND ei.task_id <> X_dest_task_id
4270                    AND e.expenditure_status_code = 'APPROVED'
4271                    AND ei.source_expenditure_item_id IS NULL
4272                   )
4273                OR
4274                   (    X_adj_action = 'BILLING HOLD'
4275                    AND ei.bill_hold_flag in ( 'N', 'O' ) )
4276                OR
4277                   (    X_adj_action = 'BILLING HOLD RELEASE'
4278                    AND ei.bill_hold_flag in ( 'Y', 'O' ) )
4279                OR
4280                   (    X_adj_action = 'BILLABLE RECLASS'
4281                    AND ei.billable_flag <> 'Y'
4282                    AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4283                    AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4284                   )
4285                OR
4286                   (    X_adj_action = 'NON-BILLABLE RECLASS'
4287                    AND ei.billable_flag = 'Y'
4288                    AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4289                    AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4290                   )
4291                OR
4292                   (    X_adj_action = 'CAPITALIZABLE RECLASS'
4293                    AND ei.billable_flag <> 'Y'
4294                    AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4295                    AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4296 		   AND exists (select 1
4297 		               From pa_tasks t
4298 		               Where t.task_id = ei.task_id
4299 		               And t.retirement_cost_flag = 'N')
4300 
4301                   )
4302                OR
4303                   (    X_adj_action = 'NON-CAPITALIZABLE RECLASS'
4304                    AND ei.billable_flag = 'Y'
4305                    AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4306                    AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4307                    AND exists (select 1
4308                                From pa_tasks t
4309                                Where t.task_id = ei.task_id
4310                                And t.retirement_cost_flag = 'N')
4311                   )
4312                OR
4313                   (    X_adj_action = 'REVENUE RECALC'
4314                    AND ei.revenue_distributed_flag||'' IN ( 'Y', 'P' )
4315                    AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4316                    AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4317                   )
4318                OR
4319                   (    X_adj_action = 'ONE-TIME BILLING HOLD'
4320                    AND ei.bill_hold_flag IN ( 'N', 'Y' ) )
4321                OR
4322                   (    X_adj_action = 'COST AND REV RECALC'
4323                    AND (   ei.revenue_distributed_flag||'' IN ( 'Y', 'P' )
4324                         OR (    ei.cost_distributed_flag||'' = 'Y'
4325                              OR ei.denom_raw_cost IS NOT NULL ) )
4326                    AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4327                    AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4328                    AND ei.source_expenditure_item_id IS NULL
4329                    AND nvl( ei.net_zero_adjustment_flag, 'N' ) <> 'Y'
4330                   )
4331                OR
4332                   (    X_adj_action = 'CAPITAL COST RECALC'
4333                    AND ei.cost_distributed_flag||'' = 'Y' )
4334                OR
4335                   (    X_adj_action = 'RAW COST RECALC'
4336                    AND ei.cost_distributed_flag||'' = 'Y' )
4337                OR
4338                   (    X_adj_action = 'INDIRECT COST RECALC'
4339                    AND ei.cost_distributed_flag||'' = 'Y' ) )
4340       FOR UPDATE OF ei.expenditure_item_id, eia.expenditure_item_id NOWAIT;
4341 
4342 
4343       CURSOR  GetPrjExpItem
4344       IS
4345       SELECT
4346               ei.expenditure_item_id
4347       ,       eia.expenditure_item_id  adj_expenditure_item_id
4348         FROM
4349               pa_expenditures_all e
4350       ,       pa_expenditure_items_all ei
4351       ,       pa_expenditure_items_all eia
4352        WHERE
4353               ei.expenditure_item_id = eia.adjusted_expenditure_item_id (+)
4354          AND  ei.expenditure_id = e.expenditure_id
4355          AND  ei.expenditure_item_id = X_expenditure_item_id
4356          AND ( 1 = 2
4357                OR X_adj_action = 'EXP COMMENT CHANGE'
4358 	       OR (X_adj_action = 'CHANGE WORK TYPE ATTRIBUTE'  /** proj currency changes **/
4359                AND nvl( ei.net_zero_adjustment_flag, 'N' ) <> 'Y'
4360                AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4361                AND ei.work_type_id  <> p_dest_work_type_id
4362                AND e.expenditure_status_code = 'APPROVED'
4363               )
4364                OR
4365               (    X_adj_action = 'PROJECT OR TASK CHANGE'
4366                AND nvl( ei.net_zero_adjustment_flag, 'N' ) <> 'Y'
4367                AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4368                AND ei.task_id <> X_dest_task_id
4369                AND e.expenditure_status_code = 'APPROVED'
4370                AND ei.source_expenditure_item_id IS NULL
4371               )
4372             OR
4373                (    X_adj_action = 'BILLING HOLD'
4374                 AND ei.bill_hold_flag in ( 'N', 'O' ) )
4375             OR
4376                (    X_adj_action = 'BILLING HOLD RELEASE'
4377                 AND ei.bill_hold_flag in ( 'Y', 'O' ) )
4378             OR
4379                (    X_adj_action = 'BILLABLE RECLASS'
4380                 AND ei.billable_flag <> 'Y'
4381                 AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4382                 AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4383                )
4384             OR
4385                (    X_adj_action = 'NON-BILLABLE RECLASS'
4386                 AND ei.billable_flag = 'Y'
4387                 AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4388                 AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4389                )
4390             OR
4391                (    X_adj_action = 'CAPITALIZABLE RECLASS'
4392                 AND ei.billable_flag <> 'Y'
4393                 AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4394                 AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4395                 AND exists (select 1
4396                             From pa_tasks t
4397                             Where t.task_id = ei.task_id
4398                             And t.retirement_cost_flag = 'N')
4399                )
4400             OR
4401                (    X_adj_action = 'NON-CAPITALIZABLE RECLASS'
4402                 AND ei.billable_flag = 'Y'
4403                 AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4404                 AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4405                 AND exists (select 1
4406                             From pa_tasks t
4407                             Where t.task_id = ei.task_id
4408                             And t.retirement_cost_flag = 'N')
4409                )
4410             OR
4411                (    X_adj_action = 'REVENUE RECALC'
4412                 AND ei.revenue_distributed_flag||'' IN ( 'Y', 'P' )
4413                 AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4414                 AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4415                )
4416             OR
4417                (    X_adj_action = 'ONE-TIME BILLING HOLD'
4418                 AND ei.bill_hold_flag IN ( 'N', 'Y' ) )
4419             OR
4420                (    X_adj_action = 'COST AND REV RECALC'
4421                 AND (   ei.revenue_distributed_flag||'' IN ( 'Y', 'P' )
4422                      OR (    ei.cost_distributed_flag||'' = 'Y'
4423                           OR ei.denom_raw_cost IS NOT NULL ) )
4424                 AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4425                 AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4426                 AND ei.source_expenditure_item_id IS NULL
4427                 AND nvl( ei.net_zero_adjustment_flag, 'N' ) <> 'Y'
4428                )
4429             OR
4430                (    X_adj_action = 'CAPITAL COST RECALC'
4431                 AND ei.cost_distributed_flag||'' = 'Y' )
4432             OR
4433                (    X_adj_action = 'RAW COST RECALC'
4434                 AND ei.cost_distributed_flag||'' = 'Y' )
4435             OR
4436                (    X_adj_action = 'INDIRECT COST RECALC'
4437                 AND ei.cost_distributed_flag||'' = 'Y' ) )
4438       FOR UPDATE OF ei.expenditure_item_id, eia.expenditure_item_id NOWAIT;
4439 
4440 
4441       CURSOR  GetInvExpSummary
4442       IS
4443       SELECT
4444               ei.expenditure_item_id
4445       ,       eia.expenditure_item_id   adj_expenditure_item_id
4446         FROM
4447               pa_cust_rev_dist_lines r
4448       ,       pa_expenditure_items_all ei
4449       ,       pa_expenditure_items_all eia
4450        WHERE
4451               ei.expenditure_item_id = eia.adjusted_expenditure_item_id (+)
4452          AND  ei.adjusted_expenditure_item_id IS NULL
4453          AND  r.project_id = X_project_id
4454          AND  r.draft_invoice_num = X_inv_num
4455          AND  r.draft_invoice_item_line_num =
4456                  nvl( X_inv_line_num, r.draft_invoice_item_line_num )
4457          AND  r.expenditure_item_id = ei.expenditure_item_id
4458          AND  (       1 = 2
4459 	       OR ( X_adj_action = 'CHANGE WORK TYPE ATTRIBUTE'  /** proj currency changes **/
4460                AND nvl( ei.net_zero_adjustment_flag, 'N' ) <> 'Y'
4461                AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4462                AND ei.work_type_id <> p_dest_work_type_id
4463 	       )
4464 
4465                OR
4466               (    X_adj_action = 'PROJECT OR TASK CHANGE'
4467                AND nvl( ei.net_zero_adjustment_flag, 'N' ) <> 'Y'
4468                AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4469                AND ei.task_id <> X_dest_task_id
4470                AND ei.source_expenditure_item_id IS NULL
4471               )
4472                OR
4473                  (    X_adj_action = 'BILLING HOLD'
4474                   AND ei.bill_hold_flag IN ( 'N', 'O' ) )
4475                OR
4476                  (    X_adj_action = 'BILLING HOLD RELEASE'
4477                   AND ei.bill_hold_flag IN ( 'Y', 'O' ) )
4478                OR
4479                  (    X_adj_action = 'NON-BILLABLE RECLASS'
4480                   AND ei.billable_flag = 'Y'
4481                   AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4482                   AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4483                  )
4484                OR
4485                  (    X_adj_action = 'REVENUE RECALC'
4486                   AND ei.revenue_distributed_flag||'' IN ( 'Y', 'P' )
4487                   AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4488                   AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4489                  )
4490                OR
4491                  (    X_adj_action = 'ONE-TIME BILLING HOLD'
4492                   AND ei.bill_hold_flag IN ( 'N', 'Y' ) )
4493                OR
4494                  (    X_adj_action = 'COST AND REV RECALC'
4495                   AND (   ei.revenue_distributed_flag||'' IN ( 'Y', 'P' )
4496                        OR (    ei.cost_distributed_flag||'' = 'Y'
4497                             OR ei.denom_raw_cost IS NOT NULL ) )
4498                   AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4499                   AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4500                   AND ei.source_expenditure_item_id IS NULL
4501                   AND nvl( ei.net_zero_adjustment_flag, 'N' ) <> 'Y'
4502                  ) )
4503       FOR UPDATE OF ei.expenditure_item_id, eia.expenditure_item_id NOWAIT;
4504 
4505 
4506 
4507       CURSOR GetInvExpSummary2
4508       IS
4509       SELECT
4510               ei.expenditure_item_id
4511       ,       eia.expenditure_item_id  adj_expenditure_item_id
4512         FROM
4513               pa_draft_invoice_items ii
4514       ,       pa_expenditure_items_all ei
4515       ,       pa_expenditure_items_all eia
4516        WHERE
4517               /* Bug # 3457873
4518 	      ei.task_id IN (
4519                     SELECT task_id
4520                       FROM pa_tasks
4521                      WHERE project_id = X_project_id )
4522 	     */
4523               ei.project_id = X_project_id /* Bug # 3457873 */
4524          AND  ei.expenditure_item_id = eia.adjusted_expenditure_item_id (+)
4525          AND  ei.adjusted_expenditure_item_id IS NULL
4526          AND  ii.project_id = X_project_id
4527          AND  ii.draft_invoice_num = X_inv_num
4528          AND  ii.line_num = nvl( X_inv_line_num, ii.line_num )
4529          AND  ii.project_id = ei.project_id
4530          AND  nvl( ii.event_task_id, -1 ) = nvl( ei.event_task_id, -1 )
4531          AND  ii.event_num = ei.event_num
4532          AND  (       1 = 2
4533 	       OR ( X_adj_action = 'CHANGE WORK TYPE ATTRIBUTE'  /** proj currency changes **/
4534                   AND nvl( ei.net_zero_adjustment_flag, 'N' ) <> 'Y'
4535                   AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4536                   AND ei.work_type_id <> p_dest_work_type_id
4537                  )
4538                OR
4539                  (    X_adj_action = 'BILLING HOLD'
4540                   AND ei.bill_hold_flag IN ( 'N', 'O' ) )
4541                OR
4542                  (    X_adj_action = 'BILLING HOLD RELEASE'
4543                   AND ei.bill_hold_flag IN ( 'Y', 'O' ) )
4544                OR
4545                  (    X_adj_action = 'NON-BILLABLE RECLASS'
4546                   AND ei.billable_flag = 'Y'
4547                   AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4548                   AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4549                  )
4550                OR
4551                  (    X_adj_action = 'REVENUE RECALC'
4552                   AND ei.revenue_distributed_flag||'' IN ( 'Y', 'P' )
4553                   AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4554                   AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4555                  )
4556                OR
4557                  (    X_adj_action = 'ONE-TIME BILLING HOLD'
4558                   AND ei.bill_hold_flag IN ( 'N', 'Y' ) )
4559                OR
4560                  (    X_adj_action = 'COST AND REV RECALC'
4561                   AND (   ei.revenue_distributed_flag||'' IN ( 'Y', 'P' )
4562                        OR (    ei.cost_distributed_flag||'' = 'Y'
4563                             OR ei.denom_raw_cost IS NOT NULL ) )
4564                   AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4565                   AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4566                   AND ei.source_expenditure_item_id IS NULL
4567                   AND nvl( ei.net_zero_adjustment_flag, 'N' ) <> 'N'
4568                  )
4569                OR
4570                  (    X_adj_action = 'PROJECT OR TASK CHANGE'
4571                   AND nvl( ei.net_zero_adjustment_flag, 'N' ) <> 'Y'
4572                   AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4573                   AND ei.task_id <> X_dest_task_id
4574                   AND ei.source_expenditure_item_id IS NULL
4575                  ) )
4576       FOR UPDATE OF ei.expenditure_item_id, eia.expenditure_item_id NOWAIT;
4577 
4578 
4579       CURSOR GetInvExpItem
4580       IS
4581       SELECT
4582               ei.expenditure_item_id
4583       ,       eia.expenditure_item_id   adj_expenditure_item_id
4584         FROM
4585               pa_expenditure_items_all ei
4586       ,       pa_expenditure_items_all eia
4587        WHERE
4588               ei.expenditure_item_id = eia.adjusted_expenditure_item_id (+)
4589          AND  ei.expenditure_item_id =  X_expenditure_item_id
4590          AND  (       1 = 2
4591                OR X_adj_action = 'EXP COMMENT CHANGE'
4592 	       OR ( X_adj_action = 'CHANGE WORK TYPE ATTRIBUTE'  /** proj currency changes **/
4593                   AND nvl( ei.net_zero_adjustment_flag, 'N' ) <> 'Y'
4594                   AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4595                   AND ei.work_type_id <> p_dest_work_type_id
4596                  )
4597                OR
4598                  (    X_adj_action = 'BILLING HOLD'
4599                   AND ei.bill_hold_flag IN ( 'N', 'O' ) )
4600                OR
4601                  (    X_adj_action = 'BILLING HOLD RELEASE'
4602                   AND ei.bill_hold_flag IN ( 'Y', 'O' ) )
4603                OR
4604                  (    X_adj_action = 'NON-BILLABLE RECLASS'
4605                   AND ei.billable_flag = 'Y'
4606                   AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4607                   AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4608                  )
4609                OR
4610                  (    X_adj_action = 'REVENUE RECALC'
4611                   AND ei.revenue_distributed_flag||'' IN ( 'Y', 'P' )
4612                   AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4613                   AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4614                  )
4615                OR
4616                  (    X_adj_action = 'ONE-TIME BILLING HOLD'
4617                   AND ei.bill_hold_flag IN ( 'N', 'Y' ) )
4618                OR
4619                  (    X_adj_action = 'COST AND REV RECALC'
4620                   AND (   ei.revenue_distributed_flag||'' IN ( 'Y', 'P' )
4621                        OR (    ei.cost_distributed_flag||'' = 'Y'
4622                             OR ei.denom_raw_cost IS NOT NULL ) )
4623                   AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4624                   AND nvl( eia.converted_flag, 'N' ) <> 'Y'
4625                   AND ei.source_expenditure_item_id IS NULL
4626                   AND nvl( ei.net_zero_adjustment_flag, 'N') <> 'Y'
4627                  )
4628                OR
4629                  (    X_adj_action = 'PROJECT OR TASK CHANGE'
4630                   AND nvl( ei.net_zero_adjustment_flag, 'N' ) <> 'Y'
4631                   AND nvl( ei.converted_flag, 'N' ) <> 'Y'
4632                   AND ei.task_id <> X_dest_task_id
4633                   AND ei.source_expenditure_item_id IS NULL
4634                  ) )
4635        FOR UPDATE OF ei.expenditure_item_id, eia.expenditure_item_id NOWAIT;
4636 
4637 
4638   BEGIN
4639 
4640 	IF P_DEBUG_MODE  THEN
4641 	   print_message('get_denom_curr_code: ' || 'Inside the pa_adjustment pkg IN PARAMS x_module ['||X_module||']X_adjust_level ['||X_adjust_level||
4642        ']X_adj_action['||X_adj_action||']p_work_type_id ['||p_work_type_id||']p_dest_work_type_id['||p_dest_work_type_id||
4643        ']expenditure_item_id['||x_expenditure_item_id||']p_projfunc_currency_code['||p_projfunc_currency_code||
4644        ']p_projfunc_cost_rate_date ['||p_projfunc_cost_rate_date||']p_projfunc_cost_rate_type['
4645 	||p_projfunc_cost_rate_type||']p_projfunc_cost_exchange_rate['||p_projfunc_cost_exchange_rate||
4646         ']p_project_raw_cost['||p_project_raw_cost||']p_project_burdened_cost['||p_project_burdened_cost||
4647         ']X_project_currency_code['||X_project_currency_code||']X_project_rate_type['||X_project_rate_type||
4648         ']X_project_rate_date['||X_project_rate_date||']X_project_exchange_rate ['||X_project_exchange_rate||
4649         ']X_acct_rate_type['||X_acct_rate_type||'] X_acct_rate_date['||X_acct_rate_date||
4650         ']X_acct_exchange_rate['||X_acct_exchange_rate||']' );
4651 	END IF;
4652 
4653     i := 0;
4654 
4655     -- PAXPRRPE - This is called from GUI EI Adjustment form (PAXTRAPE.fmb).
4656     -- PAXINADI - This is called from GUI Invoice Reveiew form (PAXINRVW.fmb).
4657     -- The Name PAXPRRPE/PAXINADI has not been changed because this is being
4658     -- used by the client as this is what gets passed to transaction
4659     -- control extension.
4660     -- Adjust_level will always be at the Item(I) level from V4 onwards,
4661     -- Summary ('S') adjust level has been kept for compatiblity purposes
4662     -- for X_modules PAXPRRPE and PAXINADI
4663     IF ( X_module = 'PAXPRRPE' ) THEN
4664 
4665       IF ( X_adjust_level = 'S' ) THEN
4666 
4667         FOR  EachRec  IN GetPrjExpSummary LOOP
4668           i := i + 1;
4669           ItemsIdTab(i)    := EachRec.expenditure_item_id;
4670           AdjustsIdTab(i)  := EachRec.adj_expenditure_item_id;
4671         END LOOP;
4672 
4673     ELSIF ( X_adjust_level = 'I' ) THEN
4674 
4675       -- FOR  EachRec  IN GetPrjExpItem LOOP
4676       --   i := i + 1;
4677       --   ItemsIdTab(i)    := EachRec.expenditure_item_id;
4678       --   AdjustsIdTab(i)  := EachRec.adj_expenditure_item_id;
4679       -- END LOOP;
4680 
4681       i := 1;
4682       ItemsIdTab(i) := X_expenditure_item_id;
4683       DenomCurrCodeTab(i)     := NULL ;
4684       ProjCurrCodeTab(i)      := X_project_currency_code ;
4685       ProjFuncCurrCodeTab(i)  := p_projfunc_currency_code;
4686       TpAmtTypCodeTab(i)      := p_tp_amt_type_code;
4687 
4688       IF ( X_adj_action in ('PROJECT OR TASK CHANGE', 'RAW COST RECALC' ,
4689                             'CAPITAL COST RECALC', 'INDIRECT COST RECALC',
4690                             'REVENUE RECALC', 'COST AND REV RECALC')
4691          ) THEN
4692         AdjustsIdTab(i)  := NULL;
4693       ELSE
4694         BEGIN
4695           -- get the adjusted ei also
4696           SELECT expenditure_item_id adj
4697             INTO adj_ei
4698             FROM pa_expenditure_items_all
4699            WHERE adjusted_expenditure_item_id = X_expenditure_item_id;
4700 
4701            AdjustsIdTab(i)  := adj_ei;
4702         EXCEPTION
4703            WHEN NO_DATA_FOUND then
4704              AdjustsIdTab(i)  := NULL;
4705            WHEN others then
4706              raise;
4707         END;
4708       END IF;
4709 
4710 
4711     END IF;
4712 
4713     IF ( i = 0 ) THEN
4714       X_outcome := 'PA_PR_NO_ITEMS_PROC';
4715       X_num_processed := 0;
4716       X_num_rejected  := 0;
4717       RETURN;
4718     END IF;
4719 
4720   ELSIF ( X_module = 'PAXINADI' ) THEN
4721 
4722     IF ( X_adjust_level = 'S' ) THEN
4723 
4724       FOR  EachRec  IN GetInvExpSummary LOOP
4725         i := i + 1;
4726         ItemsIdTab(i)    := EachRec.expenditure_item_id;
4727         AdjustsIdTab(i)  := EachRec.adj_expenditure_item_id;
4728       END LOOP;
4729 
4730       FOR EachRec IN GetInvExpSummary2 LOOP
4731         i := i + 1;
4732         ItemsIdTab(i)    := EachRec.expenditure_item_id;
4733         AdjustsIdTab(i)  := EachRec.adj_expenditure_item_id;
4734       END LOOP;
4735 
4736     ELSIF ( X_adjust_level = 'I' ) THEN
4737 
4738       -- FOR  EachRec  IN GetInvExpItem LOOP
4739       --   i := i + 1;
4740       --   ItemsIdTab(i)    := EachRec.expenditure_item_id;
4741       --   AdjustsIdTab(i)  := EachRec.adj_expenditure_item_id;
4742       -- END LOOP;
4743 
4744       i := 1;
4745       ItemsIdTab(i) := X_expenditure_item_id;
4746 
4747 /*Bug # 2249022 Added as it is missing */
4748       DenomCurrCodeTab(i)     := NULL ;
4749       ProjCurrCodeTab(i)      := X_project_currency_code ;
4750       ProjFuncCurrCodeTab(i)  := p_projfunc_currency_code;
4751       TpAmtTypCodeTab(i)      := p_tp_amt_type_code;
4752 /*Bug # 2249022 End */
4753 
4754       IF ( X_adj_action in ('PROJECT OR TASK CHANGE', 'RAW COST RECALC' ,
4755                             'CAPITAL COST RECALC', 'INDIRECT COST RECALC',
4756                             'REVENUE RECALC', 'COST AND REV RECALC')
4757          ) THEN
4758         AdjustsIdTab(i)  := NULL;
4759       ELSE
4760         BEGIN
4761           -- get the adjusted ei also
4762           SELECT expenditure_item_id adj
4763             INTO adj_ei
4764             FROM pa_expenditure_items_all
4765            WHERE adjusted_expenditure_item_id = X_expenditure_item_id;
4766 
4767            AdjustsIdTab(i)  := adj_ei;
4768         EXCEPTION
4769            WHEN NO_DATA_FOUND then
4770              AdjustsIdTab(i)  := NULL;
4771            WHEN others then
4772              raise;
4773         END;
4774       END IF;
4775 
4776 
4777     END IF;
4778 
4779     IF ( i = 0 ) THEN
4780       X_outcome := 'PA_PR_NO_ITEMS_PROC';
4781       X_num_processed := 0;
4782       X_num_rejected  := 0;
4783       RETURN;
4784     END IF;
4785 
4786 END IF;
4787 
4788 
4789 
4790 IF ( X_adj_action = 'BILLABLE RECLASS' ) THEN
4791 
4792 Reclass( ItemsIdTab
4793      , AdjustsIdTab
4794      , 'Y'
4795      , X_adj_action
4796      , X_user
4797      , X_login
4798      , X_module
4799      , i
4800      , temp_status );
4801 CheckStatus( temp_status );
4802 
4803 ELSIF ( X_adj_action = 'NON-BILLABLE RECLASS' ) THEN
4804 
4805 Reclass( ItemsIdTab
4806      , AdjustsIdTab
4807      , 'N'
4808      , X_adj_action
4809      , X_user
4810      , X_login
4811      , X_module
4812      , i
4813      , temp_status );
4814 CheckStatus( temp_status );
4815 
4816 ELSIF ( X_adj_action = 'CAPITALIZABLE RECLASS' ) THEN
4817 
4818 Reclass( ItemsIdTab
4819      , AdjustsIdTab
4820      , 'Y'
4821      , X_adj_action
4822      , X_user
4823      , X_login
4824      , X_module
4825      , i
4826      , temp_status );
4827 CheckStatus( temp_status );
4828 
4829 ELSIF ( X_adj_action = 'NON-CAPITALIZABLE RECLASS' ) THEN
4830 
4831 Reclass( ItemsIdTab
4832      , AdjustsIdTab
4833      , 'N'
4834      , X_adj_action
4835      , X_user
4836      , X_login
4837      , X_module
4838      , i
4839      , temp_status );
4840 CheckStatus( temp_status );
4841 
4842 ELSIF ( X_adj_action = 'BILLING HOLD' ) THEN
4843 
4844 Hold( ItemsIdTab
4845   , AdjustsIdTab
4846   , 'Y'
4847   , X_adj_action
4848   , X_user
4849   , X_login
4850   , X_module
4851   , i
4852   , temp_status );
4853 CheckStatus( temp_status );
4854 
4855 ELSIF ( X_adj_action = 'BILLING HOLD RELEASE' ) THEN
4856 
4857 Hold( ItemsIdTab
4858   , AdjustsIdTab
4859   , 'N'
4860   , X_adj_action
4861   , X_user
4862   , X_login
4863   , X_module
4864   , i
4865   , temp_status );
4866 CheckStatus( temp_status );
4867 
4868 ELSIF ( X_adj_action = 'ONE-TIME BILLING HOLD' ) THEN
4869 
4870 Hold( ItemsIdTab
4871   , AdjustsIdTab
4872   , 'O'
4873   , X_adj_action
4874   , X_user
4875   , X_login
4876   , X_module
4877   , i
4878   , temp_status );
4879 CheckStatus( temp_status );
4880 
4881 ELSIF ( X_adj_action = 'INDIRECT COST RECALC' ) THEN
4882 
4883 RecalcIndCost( ItemsIdTab
4884 	   , AdjustsIdTab
4885 	   , X_user
4886 	   , X_login
4887 	   , X_module
4888 	   , i
4889 	   , temp_status );
4890 CheckStatus( temp_status );
4891 
4892 ELSIF ( X_adj_action = 'COST AND REV RECALC' ) THEN
4893 
4894 RecalcCostRev( ItemsIdTab
4895 	   , AdjustsIdTab
4896 	   , X_user
4897 	   , X_login
4898 	   , X_module
4899 	   , i
4900 	   , temp_num_processed
4901 	   , temp_status );
4902 CheckStatus( temp_status );
4903 
4904 ELSIF ( X_adj_action = 'REVENUE RECALC' ) THEN
4905 
4906 RecalcRev( ItemsIdTab
4907        , AdjustsIdTab
4908        , X_user
4909        , X_login
4910        , X_module
4911        , i
4912        , temp_status );
4913 CheckStatus( temp_status );
4914 
4915 ELSIF ( X_adj_action = 'CAPITAL COST RECALC' ) THEN
4916 
4917 RecalcCapCost( ItemsIdTab
4918 	   , AdjustsIdTab
4919 	   , X_user
4920 	   , X_login
4921 	   , X_module
4922 	   , i
4923 	   , temp_status );
4924 CheckStatus( temp_status );
4925 
4926 ELSIF ( X_adj_action = 'RAW COST RECALC' ) THEN
4927 
4928 RecalcRawCost( ItemsIdTab
4929 	   , AdjustsIdTab
4930 	   , X_user
4931 	   , X_login
4932 	   , X_module
4933 	   , i
4934 	   , temp_num_processed
4935 	   , temp_status );
4936 CheckStatus( temp_status );
4937 
4938 -- call to the new rate attribute adjustment procedures
4939 ELSIF ( X_adj_action = 'CHANGE FUNC ATTRIBUTE' ) THEN
4940 
4941   ChangeFuncAttributes(ItemsIdTab
4942                           , X_adjust_level
4943                           , X_user
4944                           , X_login
4945                           , X_module
4946                           , X_acct_rate_type
4947 			  , X_acct_rate_date
4948 			  , X_acct_exchange_rate
4949                           , DenomCurrCodeTab
4950                           , ProjCurrCodeTab
4951                           , i
4952                           , temp_num_processed
4953                           , temp_num_rejected
4954                           , temp_status
4955 		 	  , ProjFuncCurrCodeTab) ;
4956 CheckStatus( temp_status );
4957 
4958 -- call to the new rate attribute adjustment procedures for project currency
4959 ELSIF ( X_adj_action = 'CHANGE PROJ ATTRIBUTE' ) THEN
4960 
4961  ChangeProjAttributes(ItemsIdTab
4962                           , X_adjust_level
4963                           , X_user
4964                           , X_login
4965                           , X_module
4966                           , X_project_rate_type
4967                           , X_project_rate_date
4968                           , X_project_exchange_rate
4969                           , DenomCurrCodeTab
4970                           , ProjCurrCodeTab
4971                           , i
4972                           , temp_num_processed
4973                           , temp_num_rejected
4974                           , temp_status         ) ;
4975 CheckStatus( temp_status );
4976 
4977 -- call to the new rate attribute adjustment procedures for project functional currency
4978 ELSIF ( X_adj_action = 'CHANGE PROJ FUNC ATTRIBUTE' ) THEN
4979 
4980  ChangeProjFuncAttributes(ItemsIdTab
4981                           , X_adjust_level
4982                           , X_user
4983                           , X_login
4984                           , X_module
4985                           , p_projfunc_cost_rate_type
4986                           , p_projfunc_cost_rate_date
4987                           , p_projfunc_cost_exchange_rate
4988                           , DenomCurrCodeTab
4989                           , ProjFuncCurrCodeTab
4990                           , i
4991                           , temp_num_processed
4992                           , temp_num_rejected
4993                           , temp_status         ) ;
4994 CheckStatus( temp_status );
4995 
4996 
4997 -- Call to the 3 new Cross Charge Adjustment routines
4998 
4999 ELSIF ( X_adj_action = 'REPROCESS CROSS CHARGE' ) THEN
5000 
5001              ReprocessCrossCharge(ItemsIdTab
5002                                 , X_adjust_level
5003                                 , X_user
5004                                 , X_login
5005                                 , X_module
5006                                 , X_cc_code
5007                                 , X_cc_type
5008                                 , X_bl_dist_code
5009                                 , X_ic_proc_code
5010                                 , X_prvdr_orgnzn_id
5011                                 , X_recvr_orgnzn_id
5012                                 , i
5013                                 , temp_num_processed
5014                                 , temp_status         );
5015 
5016        CheckStatus( temp_status );
5017 
5018 ELSIF ( X_adj_action = 'MARK NO CC PROCESS' ) THEN
5019 
5020               MarkNoCCProcess    (ItemsIdTab
5021                                 , X_adjust_level
5022                                 , X_user
5023                                 , X_login
5024                                 , X_module
5025                                 , X_bl_dist_code
5026                                 , X_ic_proc_code
5027                                 , i
5028                                 , temp_num_processed
5029                                 , temp_status         ) ;
5030 
5031         CheckStatus( temp_status );
5032 
5033 ELSIF ( X_adj_action = 'CHANGE TP ATTRIBUTE' ) THEN
5034 
5035          ChangeTPAttributes(ItemsIdTab
5036                           , X_adjust_level
5037                           , X_user
5038                           , X_login
5039                           , X_module
5040                           , X_acct_rate_type
5041                           , X_acct_rate_date
5042                           , X_acct_exchange_rate
5043     	                  , X_bl_dist_code
5044                           , X_ic_proc_code
5045                           , DenomCurrCodeTab
5046                           , i
5047                           , temp_num_processed
5048                           , temp_num_rejected
5049                           , temp_status
5050                           , p_PROJECT_TP_COST_RATE_DATE
5051                           , p_PROJECT_TP_COST_RATE_TYPE
5052                           , p_PROJECT_TP_COST_EXCHG_RATE ) ;
5053 
5054        CheckStatus( temp_status );
5055 
5056 
5057 ELSIF ( X_adj_action = 'PROJECT OR TASK CHANGE' ) THEN
5058 
5059 /* Bug#3598333 */
5060 FOR j in 1..i LOOP
5061            If pa_debug.Acquire_user_lock( 'PA_EI_ADJUST_'||to_char( ItemsIdTab(i)))<>0 then
5062              FND_MESSAGE.SET_NAME('FND','FORM_RECORD_CHANGED');
5063              APP_EXCEPTION.RAISE_EXCEPTION; /* AcquireLock */
5064            end if;
5065 END LOOP;
5066 /* Bug#3598333 */
5067 
5068 Transfer( ItemsIdTab
5069       , X_dest_prj_id
5070       , X_dest_task_id
5071       , X_project_currency_code
5072       , X_project_rate_type
5073       , X_project_rate_date
5074       , X_project_exchange_rate
5075       , X_user
5076       , X_login
5077       , X_module
5078       , X_adjust_level
5079       , i
5080       , temp_num_processed
5081       , temp_num_rejected
5082       , temp_outcome
5083       , temp_msg_application
5084       , temp_msg_type
5085       , temp_msg_token1
5086       , temp_msg_token2
5087       , temp_msg_token3
5088       , temp_msg_count
5089       , p_projfunc_currency_code
5090       , p_projfunc_cost_rate_type
5091       , p_projfunc_cost_rate_date
5092       , p_projfunc_cost_exchange_rate
5093       , p_assignment_id
5094       , p_work_type_id );
5095 
5096 /* Bug#3598333 */
5097 /*Changes for 7371988 Starts here -- We will release the lock, hence issuing a commit in PAXEIADJ.pld now, instead of here for messages seeded in Client Extension*/
5098 IF ( temp_msg_type not in ('E','W')) then
5099         FOR j in 1..i LOOP
5100            If pa_debug.release_user_lock( 'PA_EI_ADJUST_'||to_char( ItemsIdTab(i)))<>0 then
5101              FND_MESSAGE.SET_NAME('PA','PA_CAP_CANNOT_RELS_LOCK');
5102              APP_EXCEPTION.RAISE_EXCEPTION; /* AcquireLock */
5103            end if;
5104 		   /*Changes for 7371988 end here -- We will release the lock, hence issuing a commit in PAXEIADJ.pld now, instead of here for messages seeded in Client Extension*/
5105         END LOOP;
5106 /* Bug#3598333 */
5107 END IF;
5108 
5109 IF ( temp_outcome IS NOT NULL AND ( temp_msg_type = 'E' ) ) THEN /* Added msg_type check for Bug 4906816 */
5110 /* Bug#3598333 */
5111 FOR j in 1..i LOOP
5112     RelLockStatus :=  pa_debug.release_user_lock( 'PA_EI_ADJUST_'||to_char( ItemsIdTab(i)));
5113 END LOOP;
5114 /* Bug#3598333 */
5115 RAISE INVALID_ITEM;
5116 END IF;
5117 
5118 ELSIF ( X_adj_action = 'EXP COMMENT CHANGE' ) THEN
5119 
5120 CommentChange( ItemsIdTab(i)
5121 	   , X_expenditure_comment
5122 	   , X_user
5123 	   , X_login
5124 	   , temp_status );
5125 CheckStatus( temp_status );
5126 
5127 /**  start proj currency changes **/
5128 ELSIF ( X_adj_action = 'CHANGE WORK TYPE ATTRIBUTE' ) THEN
5129 
5130  IF P_DEBUG_MODE  THEN
5131     print_message('get_denom_curr_code: ' || 'calling work_type_adjustment api from adjust pkg');
5132  END IF;
5133 
5134 
5135 	work_type_adjustment
5136                    ( ItemsIdTab        => ItemsIdTab
5137                     --, AdjustsIdTab   => AdjustsIdTab
5138                     , p_billable       => NULL
5139                     , p_work_type_id   =>p_dest_work_type_id
5140                     , p_adj_activity   =>X_adjust_level
5141                     , p_user           =>X_user
5142                     , p_login          =>X_login
5143                     , p_module         =>X_module
5144                     , p_rows           => i
5145                     , p_TpAmtTypCodeTab       => TpAmtTypCodeTab
5146                     , p_dest_tp_amt_type_code => p_dest_tp_amt_type_code
5147                     , x_status         => temp_status);
5148 	IF P_DEBUG_MODE  THEN
5149 	   print_message('get_denom_curr_code: ' || 'end of work_type_adjustment api from adjust pkg x_status ='||temp_status);
5150 	END IF;
5151 
5152 	CheckStatus( temp_status );
5153 	IF P_DEBUG_MODE  THEN
5154 	   print_message('get_denom_curr_code: ' || 'after checkstatus api');
5155 	END IF;
5156 
5157 /** end proj currency changes **/
5158 END IF;
5159 
5160 X_num_processed := temp_num_processed;
5161 X_num_rejected  := temp_num_rejected;
5162 /*X_outcome       := NULL;
5163  Added for Bug 4906816 */
5164          X_outcome := temp_outcome;
5165          X_msg_application := temp_msg_application;
5166          X_msg_type   := temp_msg_type;
5167          X_msg_token1 := temp_msg_token1;
5168          X_msg_token2 := temp_msg_token2;
5169          X_msg_token3 := temp_msg_token3;
5170          X_msg_count  := temp_msg_count;
5171 
5172 EXCEPTION
5173    WHEN  INVALID_ITEM  THEN
5174 	IF P_DEBUG_MODE  THEN
5175 	   print_message('get_denom_curr_code: ' || 'INVALID_ITEM in adjust api X_outcome ='||temp_outcome);
5176 	END IF;
5177     X_outcome := temp_outcome;
5178 	 X_msg_application := temp_msg_application;
5179 	 X_msg_type   := temp_msg_type;
5180 	 X_msg_token1 := temp_msg_token1;
5181 	 X_msg_token2 := temp_msg_token2;
5182 	 X_msg_token3 := temp_msg_token3;
5183 	 X_msg_count  := temp_msg_count;
5184   WHEN RESOURCE_BUSY THEN
5185      X_outcome := 'PA_ALL_COULD_NOT_LOCK';
5186 	IF P_DEBUG_MODE  THEN
5187 	   print_message('get_denom_curr_code: ' || 'RESOURCE_BUSY in adjust api X_outcome ='||X_outcome);
5188 	END IF;
5189   WHEN  OTHERS  THEN
5190      X_outcome := SQLCODE;
5191 	IF P_DEBUG_MODE  THEN
5192 	   print_message('get_denom_curr_code: ' || 'OTHERS in adjust api X_outcome ='||X_outcome);
5193 	END IF;
5194      RAISE;
5195 
5196 END  Adjust;
5197 
5198 -- ========================================================================
5199 -- PROCEDURE MassAdjust
5200 -- ========================================================================
5201 
5202 -- This package was created to improve the performance allowing multiple
5203 -- items to be submitted for adjustments together
5204 
5205   /*
5206    * IC related changes:
5207    * New parameter added
5208    */
5209 
5210   PROCEDURE  MassAdjust(
5211              X_adj_action                IN VARCHAR2
5212            , X_module                    IN VARCHAR2
5213            , X_user                      IN NUMBER
5214            , X_login                     IN NUMBER
5215            , X_project_id                IN NUMBER
5216            , X_dest_prj_id               IN NUMBER
5217            , X_dest_task_id              IN NUMBER
5218            , X_project_currency_code     IN VARCHAR2
5219            , X_project_rate_type         IN VARCHAR2
5220            , X_project_rate_date         IN DATE
5221            , X_project_exchange_rate     IN NUMBER
5222            , X_acct_rate_type            IN VARCHAR2
5223 	   , X_acct_rate_date            IN DATE
5224 	   , X_acct_exchange_rate        IN NUMBER
5225            , X_task_id                   IN NUMBER
5226            , X_inc_by_person_id          IN NUMBER
5227            , X_inc_by_org_id             IN NUMBER
5228            , X_ei_date_low               IN DATE
5229            , X_ei_date_high              IN DATE
5230            , X_ex_end_date_low           IN DATE
5231            , X_ex_end_date_high          IN DATE
5232            , X_system_linkage            IN VARCHAR2
5233            , X_expenditure_type          IN VARCHAR2
5234            , X_expenditure_catg          IN VARCHAR2
5235            , X_expenditure_group         IN VARCHAR2
5236            , X_vendor_id                 IN NUMBER
5237            , X_job_id                    IN NUMBER
5238            , X_nl_resource_org_id        IN NUMBER
5239            , X_nl_resource               IN VARCHAR2
5240            , X_transaction_source        IN VARCHAR2
5241            , X_cost_distributed_flag     IN VARCHAR2
5242            , X_revenue_distributed_flag  IN VARCHAR2
5243            , X_grouped_cip_flag          IN VARCHAR2
5244            , X_bill_status               IN VARCHAR2
5245            , X_hold_flag                 IN VARCHAR2
5246            , X_billable_flag             IN VARCHAR2
5247            , X_capitalizable_flag        IN VARCHAR2
5248            , X_net_zero_adjust_flag      IN VARCHAR2
5249            , X_inv_num                   IN NUMBER
5250            , X_inv_line_num              IN NUMBER
5251            , X_cc_code_to_be_determined  IN VARCHAR2
5252            , X_cc_code_not_crosscharged  IN VARCHAR2
5253            , X_cc_code_intra_ou          IN VARCHAR2
5254            , X_cc_code_inter_ou          IN VARCHAR2
5255            , X_cc_code_intercompany      IN VARCHAR2
5256            , X_cc_type_no_processing     IN VARCHAR2
5257            , X_cc_type_b_and_l           IN VARCHAR2
5258            , X_cc_type_ic_billing        IN VARCHAR2
5259            , X_cc_prvdr_organization_id  IN NUMBER
5260            , X_cc_prvdr_ou               IN NUMBER
5261            , X_cc_recvr_organization_id  IN NUMBER
5262            , X_cc_recvr_ou               IN NUMBER
5263            , X_cc_bl_distributed_code    IN VARCHAR2
5264            , X_cc_ic_processed_code      IN VARCHAR2
5265            , X_expenditure_item_id       IN NUMBER
5266            , X_outcome                   OUT NOCOPY VARCHAR2
5267            , X_num_processed             OUT NOCOPY NUMBER
5268            , X_num_rejected              OUT NOCOPY NUMBER
5269            /* added for proj currency  and additional EI attributes **/
5270            , p_assignment_id                IN NUMBER
5271            , p_work_type_id                 IN NUMBER
5272            , p_projfunc_currency_code       IN varchar2
5273            , p_projfunc_cost_rate_date      IN date
5274            , p_projfunc_cost_rate_type      IN varchar2
5275            , p_projfunc_cost_exchange_rate  IN number
5276            , p_project_raw_cost             IN number
5277            , p_project_burdened_cost        IN number
5278            , p_project_tp_currency_code     IN varchar2
5279            , p_project_tp_cost_rate_date    IN date
5280            , p_project_tp_cost_rate_type    IN  varchar2
5281            , p_project_tp_cost_exchg_rate   IN number
5282            , p_project_transfer_price       IN number
5283            , p_dest_work_type_id            IN NUMBER
5284            , p_dest_tp_amt_type_code        IN varchar2
5285            , p_dest_wt_start_date           IN date
5286            , p_dest_wt_end_date             IN date
5287            -- Additional attributes added for FP 'L'
5288            , p_grouped_rwip_flag            IN varchar2
5289            , p_capital_event_number         IN number
5290            , p_start_gl_date                IN date
5291            , p_end_gl_date                  IN date
5292            , p_start_pa_date                IN date
5293            , p_end_pa_date                  IN date
5294            , p_recvr_start_gl_date          IN date
5295            , p_recvr_end_gl_date            IN date
5296            , p_recvr_start_pa_date          IN date
5297            , p_recvr_end_pa_date            IN date
5298 /* R12 Changes - Start */
5299            , p_invoice_id                   IN NUMBER
5300            , p_invoice_line_number          IN NUMBER
5301            , p_include_related_tax_lines    IN VARCHAR2
5302 	   , p_receipt_number               IN VARCHAR2
5303 	   , p_check_id                     IN NUMBER  /* 4914048 */
5304            , p_org_id                       IN NUMBER
5305            , p_dest_award_id                IN NUMBER
5306            , p_rev_exp_items_req_adjust     IN VARCHAR2
5307            , p_award_id                     IN NUMBER /* 5194785 */
5308            , p_expensed_flag                IN VARCHAR2
5309            , p_wip_resource_id              IN NUMBER
5310            , p_inventory_item_id            IN NUMBER
5311 /* R12 Changes - End */
5312             ) IS
5313     ItemsIdTab               pa_utils.IdTabTyp;
5314     AdjustsIdTab             pa_utils.IdTabTyp;
5315     ItemsIdCapTab            pa_utils.IdTabTyp;
5316     AdjustsIdCapTab          pa_utils.IdTabTyp;
5317     ItemsIdNCapTab           pa_utils.IdTabTyp;
5318     AdjustsIdNCapTab         pa_utils.IdTabTyp;
5319     DenomCurrCodeTab         pa_utils.Char15TabTyp;
5320     ProjCurrCodeTab          pa_utils.Char15TabTyp;
5321     ProjFuncCurrCodeTab      pa_utils.Char15TabTyp;
5322     ProjTpCurrCodeTab        pa_utils.Char15TabTyp;
5323 
5324     TpAmtTypCodeTab          pa_utils.Char30TabTyp;
5325 
5326     dummy                       NUMBER;
5327     l_project_start_date        DATE;
5328     l_project_completion_date   DATE;
5329     l_task_start_date           DATE;
5330     l_task_completion_date      DATE;
5331     temp_outcome                VARCHAR2(30) DEFAULT NULL;
5332     temp_status              NUMBER DEFAULT NULL;
5333     temp_num_processed       NUMBER DEFAULT 0;
5334     temp_num_rejected        NUMBER DEFAULT 0;
5335     num_processed            NUMBER DEFAULT 0;
5336     num_rejected             NUMBER DEFAULT 0;
5337     i                        BINARY_INTEGER := 0;
5338     j                        BINARY_INTEGER := 0;
5339     k                        BINARY_INTEGER := 0;
5340     l                        BINARY_INTEGER := 0;
5341     adj_ei                   number;
5342 
5343 /* R12 Changes Start - Changed size to 32000 */
5344      l_query_string                 VARCHAR2(32000);
5345 /* R12 Changes End */
5346      v_reserve_rec                  VARCHAR2(2000);
5347      select_clause                  VARCHAR2(2000);
5348      reprocess_cc_select            VARCHAR2(2000);
5349      v_sql_stm1                     VARCHAR2(2000);
5350      v_sql_stm2	                    VARCHAR2(2000);
5351      v_sql_stm3	                    VARCHAR2(2000);
5352      v_sql_stm4                     VARCHAR2(2000);
5353      v_transfer                     VARCHAR2(2000);
5354      v_bill_hld                     VARCHAR2(2000);
5355      v_bill_hold_rel                VARCHAR2(2000);
5356      v_bill_reclass                 VARCHAR2(2000);
5357      v_non_bill_reclass             VARCHAR2(2000);
5358      v_capital_reclass              VARCHAR2(2000);
5359      v_non_capital_reclass          VARCHAR2(2000);
5360      v_revenue_recalc               VARCHAR2(2000);
5361      v_bill_hold_once               VARCHAR2(2000);
5362      v_cst_rev_recalc               VARCHAR2(2000);
5363      v_cst_recalc                   VARCHAR2(2000);
5364      v_ind_cst_recalc               VARCHAR2(2000);
5365      v_rev_dist_flag                VARCHAR2(2000);
5366      v_grpd_cip_flag                VARCHAR2(2000);
5367      v_grpd_rwip_flag               VARCHAR2(2000);
5368 /* R12 Changes Start - Changed size to 32000 */
5369      where_clause                   VARCHAR2(32000);
5370 /* R12 Changes End */
5371      from_clause                    VARCHAR2(2000);
5372      v_condition1                   VARCHAR2(2000);
5373      v_condition2                   VARCHAR2(2000);
5374      v_condition3                   VARCHAR2(2000);
5375      v_condition4                   VARCHAR2(2000);
5376      /*
5377       * IC related changes
5378       * new variable added to append the query criteria
5379       */
5380      v_condition5                   VARCHAR2(2000);
5381      v_system_linkage               VARCHAR2(30);
5382      v_invoice_id                   NUMBER;
5383      v_allow_adjustments            VARCHAR2(30):='N';
5384 
5385      v_cursor_adj_id                INTEGER ;
5386      v_open_cursor                  INTEGER ;
5387 
5388      v_expenditure_item_id          NUMBER(15);
5389      v_adj_expenditure_item_id      NUMBER(15);
5390      v_project_type_class_code      VARCHAR2(30);
5391      v_denom_currency_code          VARCHAR2(15);
5392      v_project_currency_code        VARCHAR2(15);
5393      v_denom_tp_currency_code       VARCHAR2(15);
5394      v_func_attr		    VARCHAR2(2000);
5395      v_proj_attr		    VARCHAR2(2000);
5396      v_projfunc_attr		    VARCHAR2(2000);
5397      l_dummy1                       NUMBER ;
5398      l_dummy2                       NUMBER ;
5399      l_dummy3                       NUMBER ;
5400      l_rate_date_code               VARCHAR2(1) ;
5401      v_reprocess_cc                 VARCHAR2(2000);
5402      v_no_cc_process                VARCHAR2(2000);
5403      v_change_tp_attr               VARCHAR2(2000);
5404      v_cc_code                      VARCHAR2(1) ;
5405      v_exp_organization_id          NUMBER ;
5406      v_exp_org_id                   NUMBER ;
5407      v_exp_item_date                DATE;
5408      v_task_id                      NUMBER ;
5409      v_exp_type                     VARCHAR2(30);
5410      v_incurred_by_person_id        NUMBER ;
5411      v_trx_source                   VARCHAR2(30);
5412      v_nlr_organization_id          NUMBER ;
5413 
5414     /** proj currency and EI attrib related chagnes **/
5415 
5416      l_projfunc_currency_code       varchar2(15);
5417      l_projfunc_cost_rate_date      date;
5418      l_projfunc_cost_rate_type      varchar2(30);
5419      l_projfunc_cost_exchange_rate  number;
5420      l_project_tp_currency_code     varchar2(15);
5421      l_assignment_id                number;
5422      l_work_type_id                 number;
5423      l_condition6                   varchar2(2000);
5424      l_work_type_change             varchar2(2000);
5425      l_tp_amt_type_code             varchar2(30);
5426      l_transaction_source           varchar2(30);	/* Bug 3951679 : Added */
5427      l_capital_event_id             number;
5428 /* R12 Changes - Start */
5429      l_project_id                   number;
5430      l_old_org_id                   number := -99;
5431      l_billable_flag                varchar2(1);
5432      l_document_header_id           number;
5433      l_document_line_number         number;
5434      l_document_distribution_id     number;
5435      l_document_type                varchar2(30);
5436      l_vendor_id                    number;
5437      l_gl_accounted                 varchar2(1);
5438      l_document_payment_id          PA_EXPENDITURE_ITEMS_ALL.DOCUMENT_PAYMENT_ID%TYPE; /* Bug 5006835 */
5439      l_encoded_error_message        varchar2(2000);
5440      l_error_message_name           varchar2(30);
5441      l_application_short_name       varchar2(30);
5442      l_net_zero_adjustment_flag     PA_EXPENDITURE_ITEMS_ALL.NET_ZERO_ADJUSTMENT_FLAG%TYPE;
5443      l_converted_flag               PA_EXPENDITURE_ITEMS_ALL.CONVERTED_FLAG%TYPE;
5444      l_expenditure_status_code      PA_EXPENDITURES_ALL.EXPENDITURE_STATUS_CODE%TYPE;
5445      l_allow_adjustments_flag       PA_TRANSACTION_SOURCES.ALLOW_ADJUSTMENTS_FLAG%TYPE;
5446      l_burden_sum_dest_run_id       PA_EXPENDITURE_ITEMS_ALL.BURDEN_SUM_DEST_RUN_ID%TYPE;
5447      l_document_distribution_type   PA_EXPENDITURE_ITEMS_ALL.DOCUMENT_DISTRIBUTION_TYPE%TYPE;
5448      l_source_expenditure_item_id   PA_EXPENDITURE_ITEMS_ALL.SOURCE_EXPENDITURE_ITEM_ID%TYPE;
5449      l_acct_currency_code           PA_EXPENDITURE_ITEMS_ALL.ACCT_CURRENCY_CODE%TYPE;
5450      l_adjusted_expenditure_item_id PA_EXPENDITURE_ITEMS_ALL.ADJUSTED_EXPENDITURE_ITEM_ID%TYPE;
5451      l_orig_transaction_reference   PA_EXPENDITURE_ITEMS_ALL.ORIG_TRANSACTION_REFERENCE%TYPE;
5452      l_project_status_code          PA_PROJECTS_ALL.PROJECT_STATUS_CODE%TYPE;
5453      l_adjust_allowed               BOOLEAN := TRUE;
5454      l_award_id                     GMS_AWARDS_ALL.AWARD_ID%TYPE; /* Bug 5436420 */
5455      l_project_id_cache             PA_PROJECTS_ALL.PROJECT_ID%TYPE := -1; /* Bug 5441891 */
5456      l_transaction_source_cache     PA_TRANSACTION_SOURCES.TRANSACTION_SOURCE%TYPE := 'NULL'; /* Bug 5441891 */
5457      l_commit_count                 NUMBER := 0; /* Bug 5501593 */
5458 /* R12 Changes - End */
5459   BEGIN
5460 /* R12 Changes - Start */
5461 
5462 	IF X_module = 'PATXMAS' THEN
5463 	    G_REQUEST_ID := FND_GLOBAL.CONC_REQUEST_ID;
5464 	    G_PROGRAM_ID := FND_GLOBAL.CONC_PROGRAM_ID;
5465 	    G_PROG_APPL_ID := FND_GLOBAL.PROG_APPL_ID;
5466 	END IF;
5467 
5468         IF p_org_id IS NOT NULL THEN
5469             pa_multi_currency.init ;
5470         END IF;
5471 
5472 
5473 /* *** Opens a cursor for processing ********************************************************* */
5474 
5475       v_cursor_adj_id := dbms_sql.open_cursor ;
5476 
5477 /* ******************************************************************************************* */
5478 
5479 
5480 /* ** The following section constructs character strings that are used to create a query ***** */
5481 
5482       select_clause := 'SELECT'
5483                     || ' ei.expenditure_item_id'
5484                     || ',ei.org_id'
5485                     || ',ei.project_id'
5486                     || ',ei.net_zero_adjustment_flag'
5487                     || ',ei.converted_flag'
5488                     || ',e.expenditure_status_code'
5489                     || ',ei.burden_sum_dest_run_id'
5490                     || ',ei.document_header_id'
5491                     || ',ei.transaction_source'
5492                     || ',ei.document_type'
5493                     || ',ei.document_distribution_type'
5494                     || ',ei.document_payment_id'
5495                     || ',ei.source_expenditure_item_id'
5496                     || ',ei.system_linkage_function'
5497                     || ',ei.acct_currency_code'
5498                     || ',ei.denom_currency_code'
5499                     || ',ei.denom_tp_currency_code'
5500                     || ',ei.projfunc_currency_code'
5501                     || ',ei.cc_cross_charge_code'
5502                     || ',ei.adjusted_expenditure_item_id'
5503                     || ',ei.orig_transaction_reference'
5504                     || ',ei.expenditure_item_date'
5505                     || ',ei.billable_flag'
5506                     || ',ei.task_id'
5507                     || ',ei.expenditure_type'
5508                     || ',ei.vendor_id'
5509                     || ',nvl(ei.override_to_organization_id, e.incurred_by_organization_id)'
5510                     || ',e.incurred_by_person_id'
5511                     || ',ei.document_line_number'
5512                     || ',ei.document_distribution_id'
5513                     || ',ei.project_currency_code'
5514                     || ',ei.tp_amt_type_code'
5515                     || ',ei.organization_id';
5516 
5517       from_clause := ' FROM'
5518                   || ' pa_expenditure_items_all ei'
5519                   || ',pa_expenditures_all e';
5520 
5521       where_clause := ' WHERE ei.expenditure_id = e.expenditure_id';
5522 
5523       if p_org_id is not null then
5524             where_clause := where_clause || ' AND ei.org_id = :org_id';
5525       end if;
5526 
5527       if x_project_id is not null then
5528             where_clause := where_clause || ' AND ei.project_id = :project_id';
5529             if x_task_id is not null then
5530                   where_clause := where_clause || ' AND ei.task_id = :task_id';
5531             end if;
5532             if p_award_id is not null then
5533                   where_clause := where_clause
5534                                || ' AND ei.expenditure_item_id in ('
5535                                || ' SELECT adl.expenditure_item_id'
5536                                || '   FROM gms_award_distributions adl'
5537                                || '  WHERE adl.adl_line_num = 1'
5538                                || '    AND adl.document_type = ''EXP'''
5539                                || '    AND adl.adl_status = ''A'''
5540                                || '    AND adl.project_id = :project_id'
5541                                || '    AND adl.award_id = :award_id )';
5542             end if;
5543       end if;
5544 
5545       if x_expenditure_item_id is not null then
5546             where_clause := where_clause || ' AND ei.expenditure_item_id = :expenditure_item_id';
5547       end if;
5548 
5549       if x_inc_by_org_id is not null then
5550             where_clause := where_clause || ' AND (e.incurred_by_organization_id = :inc_by_org_id' ||
5551                                             ' OR  (e.incurred_by_organization_id is NULL' ||
5552                                             ' AND  ei.override_to_organization_id = :inc_by_org_id ))';
5553       end if ;
5554 
5555       if x_system_linkage is not null then
5556             where_clause := where_clause || ' AND ei.system_linkage_function = :system_linkage';
5557       end if;
5558 
5559       if x_expenditure_type is not null then
5560             where_clause := where_clause || ' AND ei.expenditure_type = :expenditure_type';
5561       end if;
5562 
5563       if x_ei_date_low is not null then
5564             where_clause := where_clause || ' AND ei.expenditure_item_date >= trunc(:ei_date_low)';
5565       end if;
5566 
5567       if x_ei_date_high is not null then
5568             where_clause := where_clause || ' AND ei.expenditure_item_date <= trunc(:ei_date_high)';
5569       end if;
5570 
5571       if x_expenditure_catg is not null then
5572             where_clause := where_clause || ' AND 1 = (SELECT 1'
5573                                          || '            FROM pa_expenditure_types et'
5574                                          || '           WHERE et.expenditure_type = ei.expenditure_type'
5575                                          || '             AND et.expenditure_category = :expenditure_catg)';
5576       end if;
5577 
5578       if x_ex_end_date_low is not null then
5579             where_clause := where_clause || ' AND e.expenditure_ending_date >= trunc(pa_utils.getweekending(:ex_end_date_low) - 6)';
5580       end if;
5581 
5582       if x_ex_end_date_high is not null then
5583             where_clause := where_clause || ' AND e.expenditure_ending_date <= trunc(pa_utils.getweekending(:ex_end_date_high))';
5584       end if;
5585 
5586       if x_expenditure_group is not null then
5587             where_clause := where_clause || ' AND e.expenditure_group = :expenditure_group';
5588       end if;
5589 
5590       if x_transaction_source is not NULL then
5591             where_clause := where_clause || ' AND ei.transaction_source = :transaction_source';
5592       end if;
5593 
5594       if p_work_type_id is not null then
5595             where_clause := where_clause || ' AND ei.work_type_id = :work_type_id';
5596       end If;
5597 
5598       if x_cost_distributed_flag is not null then
5599             where_clause := where_clause || ' AND ei.cost_distributed_flag = :cost_distributed_flag';
5600       end if;
5601 
5602       if x_billable_flag is not null then
5603             where_clause := where_clause || ' AND 1 = (SELECT 1'
5604                                          || '            FROM pa_project_types_all pt'
5605                                          || '               , pa_projects_all p'
5606                                          || '           WHERE p.project_type = pt.project_type'
5607                                          || '             AND p.org_id = pt.org_id'
5608                                          || '             AND p.project_id = ei.project_id'
5609                                          || '             AND pt.project_type_class_code <> ''CAPITAL'')'
5610                                          || ' AND ei.billable_flag = :billable_flag';
5611       end if;
5612 
5613       if x_hold_flag is not null then
5614             if x_hold_flag = 'B' then
5615                   where_clause := where_clause || ' AND ei.bill_hold_flag in ( ''Y'', ''O'')';
5616             else
5617                   where_clause := where_clause || ' and ei.bill_hold_flag = :hold_flag';
5618             end if;
5619       end if;
5620 
5621       if x_bill_status is not null then
5622             if x_bill_status = 'Y' then
5623                   where_clause := where_clause || ' AND (ei.event_num is not null'
5624                                                || ' OR   EXISTS (SELECT 1'
5625                                                || '                FROM pa_cust_rev_dist_lines_all r'
5626                                                || '               WHERE r.expenditure_item_id = ei.expenditure_item_id'
5627                                                || '                 AND r.draft_invoice_num is not null'
5628                                                || '              HAVING sum(nvl(r.bill_trans_bill_amount, 0)) <> 0'
5629                                                || '            GROUP BY r.expenditure_item_id))';
5630             elsif x_bill_status = 'N' then
5631                   where_clause := where_clause || ' AND (ei.event_num is not null'
5632                                                || ' AND  NOT EXISTS (SELECT 1'
5633                                                || '                    FROM pa_cust_rev_dist_lines_all r'
5634                                                || '                   WHERE r.expenditure_item_id = ei.expenditure_item_id'
5635                                                || '                     AND r.draft_invoice_num is not null'
5636                                                || '                  HAVING sum(nvl(r.bill_trans_bill_amount, 0)) <> 0'
5637                                                || '                GROUP BY r.expenditure_item_id))';
5638             end if;
5639       end if;
5640 
5641       if x_revenue_distributed_flag is not null then
5642             where_clause := where_clause || ' AND 1 = (SELECT 1'
5643                                          || '            FROM pa_project_types_all pt'
5644                                          || '               , pa_projects_all p'
5645                                          || '           WHERE p.project_type = pt.project_type'
5646                                          || '             AND p.org_id = pt.org_id'
5647                                          || '             AND p.project_id = ei.project_id'
5648                                          || '             AND pt.project_type_class_code <> ''CAPITAL'')'
5649                                          || ' AND ei.revenue_distributed_flag = :revenue_distributed_flag';
5650       end if;
5651 
5652       if X_inc_by_person_id is not null then
5653             where_clause := where_clause || ' AND e.incurred_by_person_id = :incurred_by_person_id';
5654       end if ;
5655 
5656       if X_job_id  is not null then
5657             where_clause := where_clause || ' AND ei.job_id  = :job_id';
5658       end if;
5659 
5660       if p_assignment_id is not null then
5661             where_clause := where_clause ||' AND ei.assignment_id = :assignment_id';
5662       end if;
5663 
5664       if X_nl_resource_org_id is not null then
5665             where_clause := where_clause || ' AND ei.organization_id = :nl_resource_org_id';
5666       end if;
5667 
5668       if p_wip_resource_id is not null then
5669             where_clause := where_clause || ' AND ei.wip_resource_id = :wip_resource_id';
5670       end if;
5671 
5672       if p_inventory_item_id is not null then
5673             where_clause := where_clause || ' AND ei.inventory_item_id = :inventory_item_id';
5674       end if;
5675 
5676       if x_vendor_id is not null then
5677             where_clause := where_clause || ' and e.vendor_id = :vendor_id';
5678       end if;
5679 
5680       IF p_invoice_id IS NOT NULL THEN
5681             IF x_transaction_source IS NULL THEN
5682                   where_clause := where_clause ||
5683                          ' and ei.transaction_source in ' ||
5684                          ' (''AP INVOICE'',''INTERPROJECT_AP_INVOICES'',''AP VARIANCE'',''AP NRTAX'',''AP DISCOUNTS''' ||
5685                          ' ,''AP EXPENSE'',''CSE_IPV_ADJUSTMENT'',''CSE_IPV_ADJUSTMENT_DEPR'',''AP ERV'') ';
5686             END IF;
5687 		where_clause := where_clause || ' AND ei.document_header_id = :invoice_id ';
5688 
5689             IF p_include_related_tax_lines = 'Y' THEN
5690                   where_clause := where_clause ||
5691                                ' and ei.document_distribution_id in' ||
5692                                ' ( select apdist.invoice_distribution_id' ||
5693                                '     from ap_invoice_distributions_all apdist' ||
5694                                '    where apdist.invoice_id = :invoice_id' ||
5695                                '      and apdist.invoice_line_number = :invoice_line_number' ||
5696                                '   union all' ||
5697                                '   select apdist1.invoice_distribution_id' ||
5698                                '     from ap_invoice_distributions_all apdist1' ||
5699                                '    where apdist1.charge_Applicable_to_dist_id in' ||
5700                                '         ( select apdist2.invoice_distribution_id' ||
5701                                '             from ap_invoice_distributions_all apdist2' ||
5702                                '            where apdist2.invoice_id = :invoice_id' ||
5703                                '              and apdist2.invoice_line_number = :invoice_line_number)' ||
5704                                '      and apdist1.line_type_lookup_code in (''NONREC_TAX'', ''TIPV'', ''TERV'', ''TRV''))'; /* Bug 5403294 */
5705             ELSIF p_invoice_line_number IS NOT NULL THEN
5706                   where_clause := where_clause || ' and ei.document_line_number = :invoice_line_number';
5707             END IF;
5708 	END IF;
5709 
5710       IF p_receipt_number IS NOT NULL THEN
5711             IF x_transaction_source IS NULL THEN
5712                   where_clause := where_clause ||
5713                                ' and ei.transaction_source in ' ||
5714                                ' (''PO RECEIPT'',''PO RECEIPT NRTAX'',''PO RECEIPT NRTAX PRICE ADJ'',''PO RECEIPT PRICE ADJ''' ||
5715                                ' ,''CSE_PO_RECEIPT'',''CSE_PO_RECEIPT_DEPR'') ';
5716             END IF;
5717 		where_clause := where_clause ||
5718                          ' and ei.document_distribution_id in' ||
5719                          ' (select rcvtxn.transaction_id' ||
5720                          ' from rcv_shipment_headers rcvhead' ||
5721                          ' , rcv_transactions rcvtxn' ||
5722                          ' where rcvhead.shipment_header_id =' ||
5723                          ' rcvtxn.shipment_header_id' ||
5724                          ' and rcvhead.receipt_num = :receipt_number)';
5725       END IF;
5726 
5727 	IF p_check_id IS NOT NULL THEN
5728             where_clause := where_clause ||
5729                          ' and ei.document_payment_id in' ||
5730                          ' (select invoice_payment_id' ||
5731                          ' from ap_invoice_payments_all' ||
5732                          ' where check_id = :check_id) ';
5733       END IF;
5734 
5735       IF p_rev_exp_items_req_adjust = 'Y' THEN
5736             where_clause := where_clause
5737                          || ' AND ei.transaction_source IN (''AP VARIANCE'',''AP INVOICE'',''AP NRTAX'',''AP DISCOUNTS'',''AP ERV'''
5738                          || '                              ,''INTERCOMPANY_AP_INVOICES'',''INTERPROJECT_AP_INVOICES'',''AP EXPENSE'''
5739                          || '                              ,''PO RECEIPT'',''PO RECEIPT NRTAX'''
5740                          || '                              ,''PO RECEIPT NRTAX PRICE ADJ'''
5741                          || '                              ,''PO RECEIPT PRICE ADJ'')'
5742                          || ' AND EXISTS (select NULL'
5743                          || '               from pa_cost_distribution_lines cdl1'
5744                          || '              where cdl1.expenditure_item_id = ei.expenditure_item_id'
5745                          || '                and cdl1.line_num = 1'
5746                          || '                and NVL(cdl1.reversed_flag,''N'') <> ''Y'')'
5747                          || ' AND ei.net_zero_adjustment_flag = ''N'''
5748                          || ' AND ei.transferred_from_exp_item_id IS NULL'
5749                          || ' AND pa_adjustments.is_orphaned_src_sys_reversal(ei.document_distribution_id,ei.transaction_source) = ''Y'''; /* 4901129 */
5750       END IF;
5751 
5752       if  X_cc_code_to_be_determined <> 'N'
5753       or  X_cc_code_not_crosscharged <> 'XX'
5754       or  X_cc_code_intra_ou         <> 'XX'
5755       or  X_cc_code_inter_ou         <> 'XX'
5756       or  X_cc_code_intercompany     <> 'XX' then
5757             where_clause := where_clause ||
5758                           ' AND ei.cc_cross_charge_type IN (:cc_code_not_crosscharged, :cc_code_intra_ou,' ||
5759                           ' :cc_code_inter_ou, :cc_code_intercompany)';
5760             if X_cc_code_to_be_determined = 'Y' then
5761                   where_clause := where_clause || ' OR ei.cc_cross_charge_type IS NULL';
5762             end if;
5763       end if;
5764 
5765       if  X_cc_type_no_processing <> 'Z'
5766       or  X_cc_type_b_and_l       <> 'Z'
5767       or  X_cc_type_ic_billing    <> 'Z' then
5768             where_clause := where_clause
5769                          || ' AND ei.cc_cross_charge_code IN'
5770                          || ' (:cc_type_no_processing, :cc_type_b_and_l, :cc_type_ic_billing)';
5771       end if;
5772 
5773       if  X_cc_bl_distributed_code is not null then
5774             where_clause := where_clause || ' AND ei.cc_bl_distributed_code = :cc_bl_distributed_code';
5775       end if;
5776 
5777       if  X_cc_ic_processed_code is not null then
5778             where_clause := where_clause || ' AND ei.cc_ic_processed_code = :cc_ic_processed_code';
5779       end if;
5780 
5781       if  X_cc_prvdr_organization_id is not null then
5782             where_clause := where_clause || ' AND ei.cc_prvdr_organization_id = :cc_prvdr_organization_id';
5783       end if;
5784 
5785       if  X_cc_prvdr_ou is not null then
5786             where_clause := where_clause || ' AND ei.org_id = :cc_prvdr_ou';
5787       end if;
5788 
5789       if  p_start_gl_date is not null
5790       and p_end_gl_date is not null then
5791             where_clause := where_clause
5792                          || ' AND pa_expenditures_utils.Get_Latest_GL_Date(ei.expenditure_item_id)'
5793                          || ' BETWEEN trunc(:start_gl_date) AND trunc(:end_gl_date)';
5794       elsif p_start_gl_date is not null then
5795             where_clause := where_clause
5796                          || ' AND pa_expenditures_utils.Get_Latest_GL_Date(ei.expenditure_item_id) >= trunc(:start_gl_date)';
5797       elsif p_end_gl_date is not null then
5798             where_clause := where_clause
5799                          || ' AND pa_expenditures_utils.Get_Latest_GL_Date(ei.expenditure_item_id) >= trunc(:end_gl_date)';
5800       end if ;
5801 
5802       if  p_start_pa_date is not null
5803       and p_end_pa_date is not null then
5804             where_clause := where_clause
5805                          || ' AND pa_expenditures_utils.Get_Latest_PA_Date(ei.expenditure_item_id)'
5806                          || ' BETWEEN trunc(:start_pa_date) AND trunc(:end_pa_date)';
5807       elsif p_start_pa_date is not null then
5808             where_clause := where_clause
5809                          || ' AND pa_expenditures_utils.Get_Latest_PA_Date(ei.expenditure_item_id) >= trunc(:start_pa_date)';
5810       elsif p_end_pa_date is not null then
5811             where_clause := where_clause
5812                          || ' AND pa_expenditures_utils.Get_Latest_PA_Date(ei.expenditure_item_id) >= trunc(:end_pa_date)';
5813       end if ;
5814 
5815       if  X_cc_recvr_organization_id is not null then
5816             where_clause := where_clause || ' AND ei.cc_recvr_organization_id = :cc_recvr_organization_id';
5817       end if;
5818 
5819       if  X_cc_recvr_ou is not null then
5820             where_clause := where_clause || ' AND ei.recvr_org_id = :cc_recvr_ou';
5821       end if;
5822 
5823       if  p_recvr_start_gl_date is not null
5824       and p_recvr_end_gl_date is not null then
5825             where_clause := where_clause
5826                          || ' AND pa_expenditures_utils.Get_Latest_GL_Date(ei.expenditure_item_id)'
5827                          || ' BETWEEN trunc(:recvr_start_gl_date) AND trunc(:recvr_end_gl_date)';
5828       elsif p_recvr_start_gl_date is not null then
5829             where_clause := where_clause
5830                          || ' AND pa_expenditures_utils.Get_Latest_GL_Date(ei.expenditure_item_id) >= trunc(:recvr_start_gl_date)';
5831       elsif p_recvr_end_gl_date is not null then
5832             where_clause := where_clause
5833                          || ' AND pa_expenditures_utils.Get_Latest_GL_Date(ei.expenditure_item_id) >= trunc(:recvr_end_gl_date)';
5834       end if ;
5835 
5836       if  p_recvr_start_pa_date is not null
5837       and p_recvr_end_pa_date is not null then
5838             where_clause := where_clause
5839                          || ' AND pa_expenditures_utils.Get_Latest_PA_Date(ei.expenditure_item_id)'
5840                          || ' BETWEEN trunc(:recvr_start_pa_date) AND trunc(:recvr_end_pa_date)';
5841       elsif p_recvr_start_pa_date is not null then
5842             where_clause := where_clause
5843                          || ' AND pa_expenditures_utils.Get_Latest_PA_Date(ei.expenditure_item_id) >= trunc(:recvr_start_pa_date)';
5844       elsif p_recvr_end_pa_date is not null then
5845             where_clause := where_clause
5846                          || ' AND pa_expenditures_utils.Get_Latest_PA_Date(ei.expenditure_item_id) >= trunc(:recvr_end_pa_date)';
5847       end if ;
5848 
5849       if x_capitalizable_flag is not null then
5850             where_clause := where_clause || ' AND 1 = (SELECT 1'
5851                                          || '            FROM pa_project_types_all pt'
5852                                          || '               , pa_projects_all p'
5853                                          || '           WHERE p.project_type = pt.project_type'
5854                                          || '             AND p.org_id = pt.org_id'
5855                                          || '             AND p.project_id = ei.project_id'
5856                                          || '             AND pt.project_type_class_code = ''CAPITAL'')'
5857                                          || ' AND ei.billable_flag = :capitalizable_flag';
5858       end if;
5859 
5860       if x_grouped_cip_flag is not null then
5861             where_clause := where_clause || ' AND 1 = (SELECT 1'
5862                                          || '            FROM pa_project_types_all pt'
5863                                          || '               , pa_projects_all p'
5864                                          || '           WHERE p.project_type = pt.project_type'
5865                                          || '             AND p.org_id = pt.org_id'
5866                                          || '             AND p.project_id = ei.project_id'
5867                                          || '             AND pt.project_type_class_code = ''CAPITAL'')'
5868                                          || ' AND 1 = (SELECT 1'
5869                                          || '            FROM pa_tasks t'
5870                                          || '           WHERE t.task_id = ei.task_id'
5871                                          || '             AND t.retirement_cost_flag = ''N'')'
5872                                          || ' AND ei.revenue_distributed_flag = :grouped_cip_flag';
5873       end if;
5874 
5875       if p_grouped_rwip_flag is not null then
5876             where_clause := where_clause || ' AND 1 = (SELECT 1'
5877                                          || '            FROM pa_project_types_all pt'
5878                                          || '               , pa_projects_all p'
5879                                          || '           WHERE p.project_type = pt.project_type'
5880                                          || '             AND p.org_id = pt.org_id'
5881                                          || '             AND p.project_id = ei.project_id'
5882                                          || '             AND pt.project_type_class_code = ''CAPITAL'')'
5883                                          || ' AND 1 = (SELECT 1'
5884                                          || '            FROM pa_tasks t'
5885                                          || '           WHERE t.task_id = ei.task_id'
5886                                          || '             AND t.retirement_cost_flag = ''Y'')'
5887                                          || ' AND ei.revenue_distributed_flag = :grouped_rwip_flag';
5888       end if;
5889 
5890       if p_expensed_flag = 'Y' then /* Bug 5393328 */
5891             where_clause := where_clause || ' AND 1 = (SELECT 1'
5892                                          || '            FROM pa_project_types_all pt'
5893                                          || '               , pa_projects_all p'
5894                                          || '           WHERE p.project_type = pt.project_type'
5895                                          || '             AND p.org_id = pt.org_id'
5896                                          || '             AND p.project_id = ei.project_id'
5897                                          || '             AND pt.project_type_class_code = ''CAPITAL'')'
5898                                          || ' AND 1 = (SELECT 1'
5899                                          || '            FROM pa_tasks t'
5900                                          || '           WHERE t.task_id = ei.task_id'
5901                                          || '             AND t.billable_flag = ''N'''
5902                                          || '             AND t.retirement_cost_flag = ''N'')';
5903       end if;
5904 
5905       if p_capital_event_number = -1 then
5906            where_clause := where_clause || ' AND ei.capital_event_id = -1';
5907       elsif p_capital_event_number is not null then
5908            where_clause := where_clause || ' AND EXISTS ('
5909                                         || '       SELECT null'
5910                                         || '         FROM pa_capital_events'
5911                                         || '        WHERE capital_event_number = :capital_event_number'
5912                                         || '          AND project_id = :project_id';
5913       end if;
5914 
5915       if x_net_zero_adjust_flag = 'Y' then
5916             where_clause := where_clause || ' AND NVL(ei.net_zero_adjustment_flag, ''N'') <> ''Y''';
5917       end if;
5918 
5919 
5920       v_reserve_rec  := ' FOR UPDATE OF ei.expenditure_item_id NOWAIT';
5921 
5922 
5923       dbms_sql.parse( v_cursor_adj_id
5924                     , select_clause || from_clause || where_clause -- || v_reserve_rec - Commenting for bug 5501593
5925                     , dbms_sql.v7);
5926 
5927 
5928       if p_org_id is not null then
5929             dbms_sql.bind_variable(v_cursor_adj_id, ':org_id', p_org_id);
5930       end if;
5931 
5932       if x_project_id is not null then
5933             dbms_sql.bind_variable(v_cursor_adj_id, ':project_id', x_project_id);
5934             if x_task_id is not null then
5935                   dbms_sql.bind_variable(v_cursor_adj_id, ':task_id', x_task_id);
5936             end if;
5937             if p_award_id is not null then
5938                   dbms_sql.bind_variable(v_cursor_adj_id,':award_id', p_award_id);
5939             end if;
5940       end if;
5941 
5942       if x_expenditure_item_id is not null then
5943             dbms_sql.bind_variable(v_cursor_adj_id, ':expenditure_item_id', x_expenditure_item_id);
5944       end if;
5945 
5946       if x_inc_by_org_id is not null then
5947             dbms_sql.bind_variable(v_cursor_adj_id, ':inc_by_org_id', x_inc_by_org_id);
5948       end if ;
5949 
5950       if x_system_linkage is not null then
5951             dbms_sql.bind_variable(v_cursor_adj_id, ':system_linkage', x_system_linkage);
5952       end if;
5953 
5954       if x_expenditure_type is not null then
5955             dbms_sql.bind_variable(v_cursor_adj_id, ':expenditure_type', x_expenditure_type);
5956       end if;
5957 
5958       if x_ei_date_low is not null then
5959             dbms_sql.bind_variable(v_cursor_adj_id, ':ei_date_low', x_ei_date_low);
5960       end if;
5961 
5962       if x_ei_date_high is not null then
5963             dbms_sql.bind_variable(v_cursor_adj_id, ':ei_date_high', x_ei_date_high);
5964       end if;
5965 
5966       if x_expenditure_catg is not null then
5967             dbms_sql.bind_variable(v_cursor_adj_id, ':expenditure_catg', x_expenditure_catg);
5968       end if;
5969 
5970       if x_ex_end_date_low is not null then
5971             dbms_sql.bind_variable(v_cursor_adj_id, ':ex_end_date_low', x_ex_end_date_low);
5972       end if;
5973 
5974       if x_ex_end_date_high is not null then
5975             dbms_sql.bind_variable(v_cursor_adj_id, ':ex_end_date_high', x_ex_end_date_high);
5976       end if;
5977 
5978       if x_expenditure_group is not null then
5979             dbms_sql.bind_variable(v_cursor_adj_id, ':expenditure_group', x_expenditure_group);
5980       end if;
5981 
5982       if x_transaction_source is not NULL then
5983             dbms_sql.bind_variable(v_cursor_adj_id, ':transaction_source', x_transaction_source);
5984       end if;
5985 
5986       if p_work_type_id is not null then
5987             dbms_sql.bind_variable(v_cursor_adj_id, ':work_type_id', p_work_type_id);
5988       end If;
5989 
5990       if x_cost_distributed_flag is not null then
5991             dbms_sql.bind_variable(v_cursor_adj_id, ':cost_distributed_flag', x_cost_distributed_flag);
5992       end if;
5993 
5994       if x_billable_flag is not null then
5995             dbms_sql.bind_variable(v_cursor_adj_id, ':billable_flag', x_billable_flag);
5996       end if;
5997 
5998       if x_hold_flag is not null then
5999             if x_hold_flag <> 'B' then
6000                   dbms_sql.bind_variable(v_cursor_adj_id, ':hold_flag', x_hold_flag);
6001             end if;
6002       end if;
6003 
6004       if x_revenue_distributed_flag is not null then
6005             dbms_sql.bind_variable(v_cursor_adj_id, ':revenue_distributed_flag', x_revenue_distributed_flag);
6006       end if;
6007 
6008       if X_inc_by_person_id is not null then
6009             dbms_sql.bind_variable(v_cursor_adj_id, ':incurred_by_person_id', X_inc_by_person_id);
6010       end if ;
6011 
6012       if X_job_id  is not null then
6013             dbms_sql.bind_variable(v_cursor_adj_id, ':job_id', X_job_id);
6014       end if;
6015 
6016       if p_assignment_id is not null then
6017             dbms_sql.bind_variable(v_cursor_adj_id, ':assignment_id', p_assignment_id);
6018       end if;
6019 
6020       if X_nl_resource_org_id is not null then
6021             dbms_sql.bind_variable(v_cursor_adj_id, ':nl_resource_org_id', X_nl_resource_org_id);
6022       end if;
6023 
6024       if p_wip_resource_id is not null then
6025             dbms_sql.bind_variable(v_cursor_adj_id, ':wip_resource_id', p_wip_resource_id);
6026       end if;
6027 
6028       if p_inventory_item_id is not null then
6029             dbms_sql.bind_variable(v_cursor_adj_id, ':inventory_item_id', p_inventory_item_id);
6030       end if;
6031 
6032       if x_vendor_id is not null then
6033             dbms_sql.bind_variable(v_cursor_adj_id, ':vendor_id', x_vendor_id);
6034       end if;
6035 
6036       IF p_invoice_id IS NOT NULL THEN
6037 		dbms_sql.bind_variable(v_cursor_adj_id, ':invoice_id', p_invoice_id);
6038             IF p_invoice_line_number IS NOT NULL THEN
6039                   dbms_sql.bind_variable(v_cursor_adj_id, ':invoice_line_number', p_invoice_line_number);
6040             END IF;
6041 	END IF;
6042 
6043       IF p_receipt_number IS NOT NULL THEN
6044 		dbms_sql.bind_variable(v_cursor_adj_id, ':receipt_number', p_receipt_number);
6045       END IF;
6046 
6047 	IF p_check_id IS NOT NULL THEN
6048             dbms_sql.bind_variable(v_cursor_adj_id, ':check_id', p_check_id);
6049       END IF;
6050 
6051       if  X_cc_code_to_be_determined <> 'N'
6052       or  X_cc_code_not_crosscharged <> 'XX'
6053       or  X_cc_code_intra_ou         <> 'XX'
6054       or  X_cc_code_inter_ou         <> 'XX'
6055       or  X_cc_code_intercompany     <> 'XX' then
6056             dbms_sql.bind_variable(v_cursor_adj_id, ':cc_code_not_crosscharged', X_cc_code_not_crosscharged);
6057             dbms_sql.bind_variable(v_cursor_adj_id, ':cc_code_intra_ou', X_cc_code_intra_ou);
6058             dbms_sql.bind_variable(v_cursor_adj_id, ':cc_code_inter_ou', X_cc_code_inter_ou);
6059             dbms_sql.bind_variable(v_cursor_adj_id, ':cc_code_intercompany', X_cc_code_intercompany);
6060       end if;
6061 
6062       if  X_cc_type_no_processing <> 'Z'
6063       or  X_cc_type_b_and_l       <> 'Z'
6064       or  X_cc_type_ic_billing    <> 'Z' then
6065             dbms_sql.bind_variable(v_cursor_adj_id, ':cc_type_no_processing', X_cc_type_no_processing);
6066             dbms_sql.bind_variable(v_cursor_adj_id, ':cc_type_b_and_l', X_cc_type_b_and_l);
6067             dbms_sql.bind_variable(v_cursor_adj_id, ':cc_type_ic_billing', X_cc_type_ic_billing);
6068       end if;
6069 
6070       if  X_cc_bl_distributed_code is not null then
6071             dbms_sql.bind_variable(v_cursor_adj_id, ':cc_bl_distributed_code', X_cc_bl_distributed_code);
6072       end if;
6073 
6074       if  X_cc_ic_processed_code is not null then
6075             dbms_sql.bind_variable(v_cursor_adj_id, ':cc_ic_processed_code', X_cc_ic_processed_code);
6076       end if;
6077 
6078       if  X_cc_prvdr_organization_id is not null then
6079             dbms_sql.bind_variable(v_cursor_adj_id, ':cc_prvdr_organization_id', X_cc_prvdr_organization_id);
6080       end if;
6081 
6082       if  X_cc_prvdr_ou is not null then
6083             dbms_sql.bind_variable(v_cursor_adj_id, ':cc_prvdr_ou', X_cc_prvdr_ou);
6084       end if;
6085 
6086       if p_start_gl_date is not null then
6087             dbms_sql.bind_variable(v_cursor_adj_id, ':start_gl_date', p_start_gl_date);
6088       end if;
6089 
6090       if p_end_gl_date is not null then
6091             dbms_sql.bind_variable(v_cursor_adj_id, ':end_gl_date', p_end_gl_date);
6092       end if ;
6093 
6094       if p_start_pa_date is not null then
6095             dbms_sql.bind_variable(v_cursor_adj_id, ':start_pa_date', p_start_pa_date);
6096       end if;
6097 
6098       if p_end_pa_date is not null then
6099             dbms_sql.bind_variable(v_cursor_adj_id, ':end_pa_date', p_end_pa_date);
6100       end if ;
6101 
6102       if  X_cc_recvr_organization_id is not null then
6103             dbms_sql.bind_variable(v_cursor_adj_id, ':cc_recvr_organization_id', X_cc_recvr_organization_id);
6104       end if;
6105 
6106       if  X_cc_recvr_ou is not null then
6107             dbms_sql.bind_variable(v_cursor_adj_id, ':cc_recvr_ou', X_cc_recvr_ou);
6108       end if;
6109 
6110       if p_recvr_start_gl_date is not null then
6111             dbms_sql.bind_variable(v_cursor_adj_id, ':recvr_start_gl_date', p_recvr_start_gl_date);
6112       end if;
6113 
6114       if p_recvr_end_gl_date is not null then
6115             dbms_sql.bind_variable(v_cursor_adj_id, ':recvr_end_gl_date', p_recvr_end_gl_date);
6116       end if ;
6117 
6118       if p_recvr_start_pa_date is not null then
6119             dbms_sql.bind_variable(v_cursor_adj_id, ':recvr_start_pa_date', p_recvr_start_pa_date);
6120       end if;
6121 
6122       if p_recvr_end_pa_date is not null then
6123             dbms_sql.bind_variable(v_cursor_adj_id, ':recvr_end_pa_date', p_recvr_end_pa_date);
6124       end if ;
6125 
6126       if x_capitalizable_flag is not null then
6127             dbms_sql.bind_variable(v_cursor_adj_id, ':capitalizable_flag', x_capitalizable_flag);
6128       end if;
6129 
6130       if x_grouped_cip_flag is not null then
6131             dbms_sql.bind_variable(v_cursor_adj_id, ':grouped_cip_flag', x_grouped_cip_flag);
6132       end if;
6133 
6134       if p_grouped_rwip_flag is not null then
6135             dbms_sql.bind_variable(v_cursor_adj_id, ':grouped_rwip_flag', p_grouped_rwip_flag);
6136       end if;
6137 
6138       if p_capital_event_number is not null then
6139            if p_capital_event_number <> -1 then
6140                  dbms_sql.bind_variable(v_cursor_adj_id, ':capital_event_number', p_capital_event_number);
6141            end if;
6142       end if;
6143 
6144 
6145       dbms_sql.define_column(v_cursor_adj_id, 1,  v_expenditure_item_id);
6146       dbms_sql.define_column(v_cursor_adj_id, 2,  v_exp_org_id);
6147       dbms_sql.define_column(v_cursor_adj_id, 3,  l_project_id);
6148       dbms_sql.define_column(v_cursor_adj_id, 4,  l_net_zero_adjustment_flag, 1);
6149       dbms_sql.define_column(v_cursor_adj_id, 5,  l_converted_flag, 1);
6150       dbms_sql.define_column(v_cursor_adj_id, 6,  l_expenditure_status_code, 30);
6151       dbms_sql.define_column(v_cursor_adj_id, 7,  l_burden_sum_dest_run_id);
6152       dbms_sql.define_column(v_cursor_adj_id, 8,  l_document_header_id);
6153       dbms_sql.define_column(v_cursor_adj_id, 9,  l_transaction_source, 30);
6154       dbms_sql.define_column(v_cursor_adj_id, 10, l_document_type, 30);
6155       dbms_sql.define_column(v_cursor_adj_id, 11, l_document_distribution_type, 30);
6156       dbms_sql.define_column(v_cursor_adj_id, 12, l_document_payment_id);
6157       dbms_sql.define_column(v_cursor_adj_id, 13, l_source_expenditure_item_id);
6158       dbms_sql.define_column(v_cursor_adj_id, 14, v_system_linkage, 30);
6159       dbms_sql.define_column(v_cursor_adj_id, 15, l_acct_currency_code, 15);
6160       dbms_sql.define_column(v_cursor_adj_id, 16, v_denom_currency_code, 15);
6161       dbms_sql.define_column(v_cursor_adj_id, 17, v_denom_tp_currency_code, 15);
6162       dbms_sql.define_column(v_cursor_adj_id, 18, l_projfunc_currency_code, 15);
6163       dbms_sql.define_column(v_cursor_adj_id, 19, v_cc_code, 1);
6164       dbms_sql.define_column(v_cursor_adj_id, 20, l_adjusted_expenditure_item_id);
6165       dbms_sql.define_column(v_cursor_adj_id, 21, l_orig_transaction_reference, 30);
6166       dbms_sql.define_column(v_cursor_adj_id, 22, v_exp_item_date);
6167       dbms_sql.define_column(v_cursor_adj_id, 23, l_billable_flag, 1);
6168       dbms_sql.define_column(v_cursor_adj_id, 24, v_task_id);
6169       dbms_sql.define_column(v_cursor_adj_id, 25, v_exp_type, 30);
6170       dbms_sql.define_column(v_cursor_adj_id, 26, l_vendor_id);
6171       dbms_sql.define_column(v_cursor_adj_id, 27, v_exp_organization_id);
6172       dbms_sql.define_column(v_cursor_adj_id, 28, v_incurred_by_person_id);
6173       dbms_sql.define_column(v_cursor_adj_id, 29, l_document_line_number);
6174       dbms_sql.define_column(v_cursor_adj_id, 30, l_document_distribution_id);
6175       dbms_sql.define_column(v_cursor_adj_id, 31, v_project_currency_code, 15);
6176       dbms_sql.define_column(v_cursor_adj_id, 32, l_tp_amt_type_code, 30);
6177       dbms_sql.define_column(v_cursor_adj_id, 33, v_nlr_organization_id);
6178 
6179 
6180 
6181 
6182 
6183 
6184     IF ( X_module IN ( 'PAXPRRPE','PAXPREPR','PAXBAUPD','PATXMAS') ) THEN
6185      v_open_cursor := dbms_sql.execute(v_cursor_adj_id);
6186         LOOP
6187           /* Fetch the rows into the buffer    ************************* */
6188 	  IF P_DEBUG_MODE  THEN
6189 	     print_message('get_denom_curr_code: ' || 'Fetch the rows into the buffer');
6190 	  END IF;
6191 
6192           If dbms_sql.fetch_rows(v_cursor_adj_id) = 0 then
6193               --Exit the loop once all the records are fetched
6194 
6195              exit ;
6196           end if ;
6197 
6198           /*** Retrieve the rows from the buffer into PLSQL variables ****/
6199       dbms_sql.column_value(v_cursor_adj_id, 1,  v_expenditure_item_id);
6200       dbms_sql.column_value(v_cursor_adj_id, 2,  v_exp_org_id);
6201       dbms_sql.column_value(v_cursor_adj_id, 3,  l_project_id);
6202       dbms_sql.column_value(v_cursor_adj_id, 4,  l_net_zero_adjustment_flag);
6203       dbms_sql.column_value(v_cursor_adj_id, 5,  l_converted_flag);
6204       dbms_sql.column_value(v_cursor_adj_id, 6,  l_expenditure_status_code);
6205       dbms_sql.column_value(v_cursor_adj_id, 7,  l_burden_sum_dest_run_id);
6206       dbms_sql.column_value(v_cursor_adj_id, 8,  l_document_header_id);
6207       dbms_sql.column_value(v_cursor_adj_id, 9,  l_transaction_source);
6208       dbms_sql.column_value(v_cursor_adj_id, 10, l_document_type);
6209       dbms_sql.column_value(v_cursor_adj_id, 11, l_document_distribution_type);
6210       dbms_sql.column_value(v_cursor_adj_id, 12, l_document_payment_id);
6211       dbms_sql.column_value(v_cursor_adj_id, 13, l_source_expenditure_item_id);
6212       dbms_sql.column_value(v_cursor_adj_id, 14, v_system_linkage);
6213       dbms_sql.column_value(v_cursor_adj_id, 15, l_acct_currency_code);
6214       dbms_sql.column_value(v_cursor_adj_id, 16, v_denom_currency_code);
6215       dbms_sql.column_value(v_cursor_adj_id, 17, v_denom_tp_currency_code);
6216       dbms_sql.column_value(v_cursor_adj_id, 18, l_projfunc_currency_code);
6217       dbms_sql.column_value(v_cursor_adj_id, 19, v_cc_code);
6218       dbms_sql.column_value(v_cursor_adj_id, 20, l_adjusted_expenditure_item_id);
6219       dbms_sql.column_value(v_cursor_adj_id, 21, l_orig_transaction_reference);
6220       dbms_sql.column_value(v_cursor_adj_id, 22, v_exp_item_date);
6221       dbms_sql.column_value(v_cursor_adj_id, 23, l_billable_flag);
6222       dbms_sql.column_value(v_cursor_adj_id, 24, v_task_id);
6223       dbms_sql.column_value(v_cursor_adj_id, 25, v_exp_type);
6224       dbms_sql.column_value(v_cursor_adj_id, 26, l_vendor_id);
6225       dbms_sql.column_value(v_cursor_adj_id, 27, v_exp_organization_id);
6226       dbms_sql.column_value(v_cursor_adj_id, 28, v_incurred_by_person_id);
6227       dbms_sql.column_value(v_cursor_adj_id, 29, l_document_line_number);
6228       dbms_sql.column_value(v_cursor_adj_id, 30, l_document_distribution_id);
6229       dbms_sql.column_value(v_cursor_adj_id, 31, v_project_currency_code);
6230       dbms_sql.column_value(v_cursor_adj_id, 32, l_tp_amt_type_code);
6231       dbms_sql.column_value(v_cursor_adj_id, 33, v_nlr_organization_id);
6232 
6233 /* Bug 5441891 - Start */
6234       IF l_project_id  <> l_project_id_cache THEN
6235         SELECT pt.project_type_class_code
6236              , p.project_status_code
6237           INTO v_project_type_class_code
6238              , l_project_status_code
6239           FROM pa_project_types_all pt
6240              , pa_projects_all p
6241          WHERE p.project_type = pt.project_type
6242            AND p.org_id = pt.org_id
6243            AND p.project_id = l_project_id;
6244         l_project_id_cache := l_project_id;
6245       END IF;
6246 
6247       IF l_transaction_source IS NULL THEN
6248         l_allow_adjustments_flag := NULL;
6249         l_gl_accounted := NULL;
6250       ELSE
6251         IF l_transaction_source <> l_transaction_source_cache THEN
6252           SELECT tr.allow_adjustments_flag
6253                , tr.gl_accounted_flag
6254             INTO l_allow_adjustments_flag
6255                , l_gl_accounted
6256             FROM pa_transaction_sources tr
6257            WHERE tr.transaction_source = l_transaction_source;
6258           l_transaction_source_cache := l_transaction_source;
6259         END IF;
6260       END IF;
6261 /* Bug 5441891 - End */
6262 
6263 /* R12 Changes Start - Set org context if not already set */
6264       IF p_org_id IS NULL THEN
6265           IF v_exp_org_id <> l_old_org_id THEN
6266               PA_MOAC_UTILS.SET_POLICY_CONTEXT('S',v_exp_org_id);
6267               l_old_org_id := v_exp_org_id;
6268           END IF;
6269           pa_multi_currency.init;
6270       END IF;
6271 /* R12 Changes End */
6272 
6273            v_allow_adjustments := 'N';
6274 
6275 /* Bug 5501593 - Checking if the expenditure can be locked for update or not */
6276            DECLARE
6277                l_dummy VARCHAR2(1);
6278                row_locked EXCEPTION;
6279                PRAGMA EXCEPTION_INIT(row_locked, -54);
6280            BEGIN
6281                SELECT NULL
6282                INTO l_dummy
6283                FROM pa_expenditure_items_all
6284                WHERE expenditure_item_id = v_expenditure_item_id
6285                FOR UPDATE OF expenditure_item_id NOWAIT;
6286            EXCEPTION
6287                WHEN row_locked THEN
6288                    v_allow_adjustments := 'PA_ADJ_EXP_ITEMS_LOCKED';
6289            END;
6290 /* Bug 5501593 - End */
6291 
6292          if  v_allow_adjustments = 'N'
6293          and x_adj_action in ( 'BILLABLE RECLASS'
6294                              , 'NON-BILLABLE RECLASS'
6295                              , 'BILLING HOLD'
6296                              , 'ONE-TIME BILLING HOLD'
6297                              , 'BILLING HOLD RELEASE'
6298                              , 'COST AND REV RECALC'
6299                              , 'REVENUE RECALC')
6300          and v_project_type_class_code = 'CAPITAL' then
6301              v_allow_adjustments := 'PA_TR_APE_ITEM_IN_CAP_PROJ';
6302          end if;
6303 
6304          if  v_allow_adjustments = 'N'
6305          and x_adj_action in ( 'BILLABLE RECLASS'
6306                              , 'NON-BILLABLE RECLASS'
6307                              , 'BILLING HOLD'
6308                              , 'ONE-TIME BILLING HOLD'
6309                              , 'BILLING HOLD RELEASE'
6310                              , 'COST AND REV RECALC'
6311                              , 'REVENUE RECALC')
6312          and v_project_type_class_code = 'INDIRECT'
6313          and not pa_gms_api.is_sponsored_project(l_project_id) then
6314              v_allow_adjustments := 'PA_TR_APE_ITEM_IN_IND_PROJ';
6315          end if;
6316 
6317          if  v_allow_adjustments = 'N'
6318          and x_adj_action in ( 'CAPITALIZABLE RECLASS'
6319                              , 'NON-CAPITALIZABLE RECLASS')
6320          and v_project_type_class_code <> 'CAPITAL' then
6321              v_allow_adjustments := 'PA_TR_APE_ITEM_NOT_IN_CAP_PROJ';
6322          end if;
6323 
6324          if  v_allow_adjustments = 'N'
6325          and x_adj_action in ( 'BILLABLE RECLASS'
6326                              , 'NON-BILLABLE RECLASS'
6327                              , 'BILLING HOLD'
6328                              , 'ONE-TIME BILLING HOLD'
6329                              , 'BILLING HOLD RELEASE'
6330                              , 'CAPITALIZABLE RECLASS'
6331                              , 'NON-CAPITALIZABLE RECLASS'
6332                              , 'REPROCESS CROSS CHARGE'
6333                              , 'CHANGE FUNC ATTRIBUTE'
6334                              , 'CHANGE PROJ FUNC ATTRIBUTE'
6335                              , 'CHANGE TP ATTRIBUTE'
6336                              , 'CHANGE WORK TYPE ATTRIBUTE'
6337                              , 'MARK NO CC PROCESS'
6338                              , 'RAW COST RECALC'
6339                              , 'INDIRECT COST RECALC'
6340                              , 'COST AND REV RECALC'
6341                              , 'REVENUE RECALC'
6342                              , 'PROJECT OR TASK CHANGE')
6343          and l_net_zero_adjustment_flag = 'Y' then
6344              v_allow_adjustments := 'PA_TR_APE_CANT_ADJ_NET_ZERO';
6345          end if;
6346 
6347          if  v_allow_adjustments = 'N'
6348          and x_adj_action in ( 'BILLABLE RECLASS'
6349                              , 'NON-BILLABLE RECLASS'
6350                              , 'CAPITALIZABLE RECLASS'
6351                              , 'NON-CAPITALIZABLE RECLASS'
6352                              , 'REPROCESS CROSS CHARGE'
6353                              , 'CHANGE FUNC ATTRIBUTE'
6354                              , 'CHANGE PROJ FUNC ATTRIBUTE'
6355                              , 'CHANGE TP ATTRIBUTE'
6356                              , 'CHANGE WORK TYPE ATTRIBUTE'
6357                              , 'MARK NO CC PROCESS'
6358                              , 'RAW COST RECALC'
6359                              , 'INDIRECT COST RECALC'
6360                              , 'COST AND REV RECALC'
6361                              , 'REVENUE RECALC'
6362                              , 'PROJECT OR TASK CHANGE')
6363          and l_converted_flag = 'Y' then
6364              v_allow_adjustments := 'PA_TR_APE_CANT_ADJ_CONV';
6365          end if;
6366 
6367          if  v_allow_adjustments = 'N'
6368          and x_adj_action in ( 'BILLABLE RECLASS'
6369                              , 'NON-BILLABLE RECLASS'
6370                              , 'CAPITALIZABLE RECLASS'
6371                              , 'NON-CAPITALIZABLE RECLASS'
6372                              , 'REPROCESS CROSS CHARGE'
6373                              , 'CHANGE FUNC ATTRIBUTE'
6374                              , 'CHANGE PROJ FUNC ATTRIBUTE'
6375                              , 'CHANGE TP ATTRIBUTE'
6376                              , 'CHANGE WORK TYPE ATTRIBUTE'
6377                              , 'MARK NO CC PROCESS'
6378                              , 'RAW COST RECALC'
6379                              , 'INDIRECT COST RECALC'
6380                              , 'COST AND REV RECALC'
6381                              , 'REVENUE RECALC'
6382                              , 'PROJECT OR TASK CHANGE')
6383          and l_expenditure_status_code <> 'APPROVED' then
6384              v_allow_adjustments := 'PA_TR_APE_CANT_ADJ_NON_APPR';
6385          end if;
6386 
6387          if  v_allow_adjustments = 'N'
6388          and x_adj_action in ( 'BILLABLE RECLASS'
6389                              , 'NON-BILLABLE RECLASS'
6390                              , 'CAPITALIZABLE RECLASS'
6391                              , 'NON-CAPITALIZABLE RECLASS'
6392                              , 'REPROCESS CROSS CHARGE'
6393                              , 'CHANGE FUNC ATTRIBUTE'
6394                              , 'RAW COST RECALC'
6395                              , 'INDIRECT COST RECALC'
6396                              , 'COST AND REV RECALC'
6397                              , 'PROJECT OR TASK CHANGE')
6398          and l_allow_adjustments_flag = 'N' then
6399              v_allow_adjustments := 'PA_TR_APE_NO_ADJUST';
6400          end if;
6401 
6402 /* Bug 5364389 - Start */
6403          if  v_allow_adjustments = 'N'
6404          and x_adj_action in ( 'CHANGE WORK TYPE ATTRIBUTE')
6405          and l_allow_adjustments_flag = 'N'
6406          and NVL(PA_UTILS4.get_trxn_work_billabilty(p_dest_work_type_id, NULL),l_billable_flag) <> l_billable_flag then
6407              v_allow_adjustments := 'PA_TR_APE_NO_ADJUST';
6408          end if;
6409 /* Bug 5364389 - End */
6410 
6411 /* Bug 5579712 - Start */
6412          if  v_allow_adjustments = 'N'
6413          and x_adj_action in ( 'CHANGE WORK TYPE ATTRIBUTE')
6414          and v_project_type_class_code = 'INDIRECT' then
6415            declare
6416              l_billable_capitalizable_flag pa_work_types_b.billable_capitalizable_flag%TYPE;
6417            begin
6418              select billable_capitalizable_flag
6419                into l_billable_capitalizable_flag
6420                from pa_work_types_b
6421               where work_type_id = p_dest_work_type_id;
6422              if l_billable_capitalizable_flag = 'Y' then
6423                v_allow_adjustments := 'PA_ADJ_WT_IND_PRJ_NOT_ALLOW';
6424              end if;
6425            end;
6426          end if;
6427 /* Bug 5579712 - End */
6428 
6429          if  v_allow_adjustments = 'N'
6430          and x_adj_action in ( 'BILLABLE RECLASS'
6431                              , 'NON-BILLABLE RECLASS'
6432                              , 'BILLING HOLD'
6433                              , 'ONE-TIME BILLING HOLD'
6434                              , 'BILLING HOLD RELEASE'
6435                              , 'CAPITALIZABLE RECLASS'
6436                              , 'NON-CAPITALIZABLE RECLASS'
6437                              , 'REPROCESS CROSS CHARGE'
6438                              , 'CHANGE FUNC ATTRIBUTE'
6439                              , 'CHANGE PROJ FUNC ATTRIBUTE'
6440                              , 'CHANGE TP ATTRIBUTE'
6441                              , 'CHANGE WORK TYPE ATTRIBUTE'
6442                              , 'MARK NO CC PROCESS'
6443                              , 'RAW COST RECALC'
6444                              , 'INDIRECT COST RECALC'
6445                              , 'COST AND REV RECALC'
6446                              , 'REVENUE RECALC'
6447                              , 'PROJECT OR TASK CHANGE')
6448          and pa_project_utils.check_prj_stus_action_allowed(l_project_status_code,'ADJUST_TXNS') <> 'Y' then
6449              v_allow_adjustments := 'PA_TR_APE_PRJ_STS_NO_ADJUST';
6450          end if;
6451 
6452          if  v_allow_adjustments = 'N'
6453          and x_adj_action in ( 'BILLABLE RECLASS'
6454                              , 'NON-BILLABLE RECLASS'
6455                              , 'CAPITALIZABLE RECLASS'
6456                              , 'NON-CAPITALIZABLE RECLASS'
6457                              , 'REPROCESS CROSS CHARGE'
6458                              , 'CHANGE FUNC ATTRIBUTE'
6459                              , 'CHANGE PROJ FUNC ATTRIBUTE'
6460                              , 'CHANGE TP ATTRIBUTE'
6461                              , 'CHANGE WORK TYPE ATTRIBUTE'
6462                              , 'MARK NO CC PROCESS'
6463                              , 'RAW COST RECALC'
6464                              , 'COST AND REV RECALC'
6465                              , 'PROJECT OR TASK CHANGE')
6466          and l_burden_sum_dest_run_id IS NOT NULL then
6467              v_allow_adjustments := 'PA_TR_APE_BURDEN_COST_TR';
6468          end if;
6469 
6470          if  v_allow_adjustments = 'N'
6471          and x_adj_action in ( 'BILLABLE RECLASS'
6472                              , 'NON-BILLABLE RECLASS'
6473                              , 'BILLING HOLD'
6474                              , 'ONE-TIME BILLING HOLD'
6475                              , 'BILLING HOLD RELEASE'
6476                              , 'CAPITALIZABLE RECLASS'
6477                              , 'NON-CAPITALIZABLE RECLASS'
6478                              , 'REPROCESS CROSS CHARGE'
6479                              , 'CHANGE PROJ FUNC ATTRIBUTE'
6480                              , 'CHANGE TP ATTRIBUTE'
6481                              , 'CHANGE WORK TYPE ATTRIBUTE'
6482                              , 'MARK NO CC PROCESS'
6483                              , 'RAW COST RECALC'
6484                              , 'INDIRECT COST RECALC'
6485                              , 'COST AND REV RECALC'
6486                              , 'REVENUE RECALC'
6487                              , 'PROJECT OR TASK CHANGE')
6488          and l_transaction_source in ( 'AP INVOICE'
6489                                      , 'INTERPROJECT_AP_INVOICES'
6490                                      , 'AP VARIANCE'
6491                                      , 'AP NRTAX'
6492                                      , 'AP DISCOUNTS'
6493                                      , 'AP EXPENSE'
6494                                      , 'PO RECEIPT'
6495                                      , 'PO RECEIPT NRTAX'
6496                                      , 'PO RECEIPT NRTAX PRICE ADJ'
6497                                      , 'PO RECEIPT PRICE ADJ')
6498          and l_document_header_id is NULL then
6499              v_allow_adjustments := 'PA_SI_ADJ_NOT_UPGRADED_TO_R12';
6500          end if;
6501 
6502          if  v_allow_adjustments = 'N'
6503          and x_adj_action in ( 'BILLABLE RECLASS'
6504                              , 'NON-BILLABLE RECLASS'
6505                              , 'BILLING HOLD'
6506                              , 'ONE-TIME BILLING HOLD'
6507                              , 'BILLING HOLD RELEASE'
6508                              , 'CAPITALIZABLE RECLASS'
6509                              , 'NON-CAPITALIZABLE RECLASS'
6510                              , 'REPROCESS CROSS CHARGE'
6511                              , 'CHANGE PROJ FUNC ATTRIBUTE'
6512                              , 'CHANGE TP ATTRIBUTE'
6513                              , 'CHANGE WORK TYPE ATTRIBUTE'
6514                              , 'MARK NO CC PROCESS'
6515                              , 'RAW COST RECALC'
6516                              , 'INDIRECT COST RECALC'
6517                              , 'COST AND REV RECALC'
6518                              , 'REVENUE RECALC'
6519                              , 'PROJECT OR TASK CHANGE')
6520          and l_transaction_source in ('AP INVOICE','AP EXPENSE','INTERPROJECT_AP_INVOICES','AP VARIANCE','AP NRTAX')
6521          and l_document_type = 'PREPAYMENT' then
6522              v_allow_adjustments := 'PA_SI_ADJ_PREPAY_NOT_ALLOW';
6523          end if;
6524 
6525          if  v_allow_adjustments = 'N'
6526          and x_adj_action in ( 'BILLABLE RECLASS'
6527                              , 'NON-BILLABLE RECLASS'
6528                              , 'BILLING HOLD'
6529                              , 'ONE-TIME BILLING HOLD'
6530                              , 'BILLING HOLD RELEASE'
6531                              , 'CAPITALIZABLE RECLASS'
6532                              , 'NON-CAPITALIZABLE RECLASS'
6533                              , 'REPROCESS CROSS CHARGE'
6534                              , 'CHANGE PROJ FUNC ATTRIBUTE'
6535                              , 'CHANGE TP ATTRIBUTE'
6536                              , 'CHANGE WORK TYPE ATTRIBUTE'
6537                              , 'MARK NO CC PROCESS'
6538                              , 'RAW COST RECALC'
6539                              , 'INDIRECT COST RECALC'
6540                              , 'COST AND REV RECALC'
6541                              , 'REVENUE RECALC'
6542                              , 'PROJECT OR TASK CHANGE')
6543          and l_transaction_source in ('AP DISCOUNTS')
6544          and l_document_type = 'PREPAYMENT' then
6545              v_allow_adjustments := 'PA_SI_ADJ_PREPAY_DIS_NOT_ALLOW';
6546          end if;
6547 
6548          if  v_allow_adjustments = 'N'
6549          and x_adj_action in ( 'BILLABLE RECLASS'
6550                              , 'NON-BILLABLE RECLASS'
6551                              , 'BILLING HOLD'
6552                              , 'ONE-TIME BILLING HOLD'
6553                              , 'BILLING HOLD RELEASE'
6554                              , 'CAPITALIZABLE RECLASS'
6555                              , 'NON-CAPITALIZABLE RECLASS'
6556                              , 'REPROCESS CROSS CHARGE'
6557                              , 'CHANGE FUNC ATTRIBUTE'
6558                              , 'CHANGE PROJ FUNC ATTRIBUTE'
6559                              , 'CHANGE TP ATTRIBUTE'
6560                              , 'CHANGE WORK TYPE ATTRIBUTE'
6561                              , 'MARK NO CC PROCESS'
6562                              , 'RAW COST RECALC'
6563                              , 'INDIRECT COST RECALC'
6564                              , 'COST AND REV RECALC'
6565                              , 'REVENUE RECALC'
6566                              , 'PROJECT OR TASK CHANGE')
6567          and l_transaction_source in ('AP INVOICE','AP EXPENSE','INTERPROJECT_AP_INVOICES','AP VARIANCE','AP NRTAX')
6568          and ( l_document_distribution_type = 'PREPAY'
6569           or   IsRelatedToPrepayApp(l_document_distribution_id))
6570          and l_document_payment_id is NULL then
6571              v_allow_adjustments := 'PA_SI_ADJ_PREPAY_APP_NOT_ALLOW';
6572          end if;
6573 
6574          if  v_allow_adjustments = 'N'
6575          and x_adj_action in ( 'REPROCESS CROSS CHARGE'
6576                              , 'CHANGE FUNC ATTRIBUTE'
6577                              , 'CHANGE PROJ FUNC ATTRIBUTE'
6578                              , 'CHANGE TP ATTRIBUTE'
6579                              , 'MARK NO CC PROCESS'
6580                              , 'RAW COST RECALC'
6581                              , 'INDIRECT COST RECALC'
6582                              , 'COST AND REV RECALC'
6583                              , 'PROJECT OR TASK CHANGE')
6584          and l_source_expenditure_item_id is not null then
6585              v_allow_adjustments := 'PA_TR_APE_CANT_ADJ_REL';
6586          end if;
6587 
6588          if  v_allow_adjustments = 'N'
6589          and x_adj_action in ( 'CHANGE FUNC ATTRIBUTE')
6590          and v_system_linkage in ('VI', 'ER') then
6591              v_allow_adjustments := 'PA_TR_APE_CANT_ADJ_ER_VI';
6592          end if;
6593 
6594          if  v_allow_adjustments = 'N'
6595          and x_adj_action in ( 'CHANGE FUNC ATTRIBUTE')
6596          and l_acct_currency_code = v_denom_currency_code then
6597              v_allow_adjustments := 'PA_TR_APE_ACCT_DENOM_CURR_SAME';
6598          end if;
6599 
6600          if  v_allow_adjustments = 'N'
6601          and x_adj_action in ( 'CHANGE TP ATTRIBUTE')
6602          and l_acct_currency_code = v_denom_tp_currency_code then
6603              v_allow_adjustments := 'PA_TR_APE_ACCT_DENOM_CURR_SAME';
6604          end if;
6605 
6606          if  v_allow_adjustments = 'N'
6607          and x_adj_action in ( 'CHANGE PROJ FUNC ATTRIBUTE')
6608          and l_projfunc_currency_code = v_denom_currency_code then
6609              v_allow_adjustments := 'PA_TR_APE_PRJ_DENOM_CURR_SAME';
6610          end if;
6611 
6612          if  v_allow_adjustments = 'N'
6613          and x_adj_action in ( 'CHANGE TP ATTRIBUTE')
6614          and v_cc_code in ( 'N', 'X') then
6615              v_allow_adjustments := 'PA_TR_APE_CC_CODE_NO_ADJUST';
6616          end if;
6617 
6618          if  v_allow_adjustments = 'N'
6619          and x_adj_action in ( 'CHANGE WORK TYPE ATTRIBUTE'
6620                              , 'PROJECT OR TASK CHANGE')
6621          and l_adjusted_expenditure_item_id is not null then
6622              v_allow_adjustments := 'PA_TR_APE_CANT_ADJ_ADJ';
6623          end if;
6624 
6625          if  v_allow_adjustments = 'N'
6626          and x_adj_action in ( 'MARK NO CC PROCESS')
6627          and v_cc_code = 'N' then
6628              v_allow_adjustments := 'PA_TR_APE_MARK_NO_CC_PROC';
6629          end if;
6630 
6631          if  v_allow_adjustments = 'N'
6632          and x_adj_action in ( 'MARK NO CC PROCESS')
6633          and v_cc_code = 'X' then
6634              v_allow_adjustments := 'PA_TR_CC_SET_NA';
6635          end if;
6636 
6637          if  v_allow_adjustments = 'N'
6638          and x_adj_action in ( 'RAW COST RECALC')
6639          and v_project_type_class_code = 'CONTRACT' then
6640              v_allow_adjustments := 'PA_TR_APE_ITEM_IN_CON_PROJ';
6641          end if;
6642 
6643          if  v_allow_adjustments = 'N'
6644          and x_adj_action in ( 'PROJECT OR TASK CHANGE')
6645          and l_transaction_source = 'ORACLE TIME AND LABOR' then
6646              Pa_Otc_Api.AdjustAllowedToOTCItem(l_orig_transaction_reference,l_adjust_allowed);
6647              if not l_adjust_allowed then
6648                  v_allow_adjustments := 'PA_CANT_TRAN_OTC_ITEM';
6649              end if;
6650          end if;
6651 
6652          if  v_allow_adjustments = 'N'
6653          and x_adj_action in ( 'PROJECT OR TASK CHANGE') then
6654              declare
6655                  l_start_date DATE;
6656                  l_end_date DATE;
6657                  cursor proj_start_end_date is
6658                  select start_date, completion_date
6659                    from pa_projects_all
6660                   where project_id = X_dest_prj_id;
6661              begin
6662                  open proj_start_end_date;
6663                  fetch proj_start_end_date into l_start_date, l_end_date;
6664                  close proj_start_end_date;
6665                  if not (v_exp_item_date between l_start_date and nvl(l_end_date, v_exp_item_date)) then
6666                      v_allow_adjustments := 'PA_EX_PROJECT_DATE';
6667                  end if;
6668              end;
6669          end if;
6670 
6671          if  v_allow_adjustments = 'N'
6672          and x_adj_action in ( 'PROJECT OR TASK CHANGE') then
6673              declare
6674                  l_start_date DATE;
6675                  l_end_date DATE;
6676                  cursor task_start_end_date is
6677                  select start_date, completion_date
6678                    from pa_tasks
6679                   where task_id = X_dest_task_id;
6680              begin
6681                  open task_start_end_date;
6682                  fetch task_start_end_date into l_start_date, l_end_date;
6683                  close task_start_end_date;
6684                  if not (v_exp_item_date between l_start_date and nvl(l_end_date, v_exp_item_date)) then
6685                      v_allow_adjustments := 'PA_EXP_TASK_EFF';
6686                  end if;
6687              end;
6688          end if;
6689 
6690          if  v_allow_adjustments = 'N'
6691          and ((v_system_linkage = 'VI'
6692          and   l_transaction_source in ('AP INVOICE', 'INTERCOMPANY_AP_INVOICES', 'AP ERV', /* Bug 5235354 */
6693                                      'INTERPROJECT_AP_INVOICES', 'AP VARIANCE' , 'AP NRTAX' , 'AP DISCOUNTS'))
6694          or  (v_system_linkage = 'ER' and l_transaction_source = 'AP EXPENSE')) then
6695 /* R12 Changes Start */
6696 		IF X_adj_action not in ('BILLABLE RECLASS','NON-BILLABLE RECLASS') THEN
6697  			v_allow_adjustments := InvStatus(X_system_reference2 => l_document_header_id
6698                                                         ,X_system_linkage_function => v_system_linkage);
6699 		END IF;
6700          end if;
6701 
6702 /* Bug 5235354 - Start */
6703          IF  v_allow_adjustments = 'N'
6704          AND l_transaction_source IN ( 'AP ERV', 'PO RECEIPT', 'PO RECEIPT NRTAX'
6705                                      , 'PO RECEIPT NRTAX PRICE ADJ', 'PO RECEIPT PRICE ADJ')
6706          AND ( X_adj_action IN ( 'PROJECT OR TASK CHANGE'
6707                                , 'BILLABLE RECLASS'
6708                                , 'NON-BILLABLE RECLASS'
6709                                , 'CAPITALIZABLE RECLASS'
6710                                , 'NON-CAPITALIZABLE RECLASS'
6711                                , 'RAW COST RECALC'
6712                                , 'COST AND REV RECALC')
6713           OR ( X_adj_action = 'CHANGE WORK TYPE ATTRIBUTE'
6714          AND   NVL(PA_UTILS4.get_trxn_work_billabilty(p_dest_work_type_id, NULL),l_billable_flag) <> l_billable_flag)) THEN
6715 
6716              IF  NVL(FND_PROFILE.VALUE('PA_ALLOW_RCV_ERV_ADJ_WHEN_JOURNAL_CONVERT'), 'N') = 'N'
6717              AND RepCurrOrSecLedgerDiffCurr(v_exp_org_id) THEN
6718 
6719                  IF l_transaction_source = 'AP ERV'
6720                  AND not PA_Adjustments.IsPeriodEndAccrual(l_document_distribution_id) THEN /* Bug 5381260 */
6721                      v_allow_adjustments := 'PA_ERV_PROF_SET_TO_NO';
6722                  END IF;
6723                  IF l_transaction_source IN ( 'PO RECEIPT', 'PO RECEIPT NRTAX'
6724                                             , 'PO RECEIPT NRTAX PRICE ADJ', 'PO RECEIPT PRICE ADJ') THEN
6725                      v_allow_adjustments := 'PA_RCV_PROF_SET_TO_NO';
6726                  END IF;
6727 
6728              END IF;
6729 
6730          END IF;
6731 /* Bug 5235354 - End */
6732 
6733          IF  v_allow_adjustments = 'N'
6734          AND l_transaction_source IN ( 'AP INVOICE', 'INTERCOMPANY_AP_INVOICES', 'INTERPROJECT_AP_INVOICES', 'AP ERV' /* Bug 5235354 */
6735                                      , 'AP VARIANCE', 'AP NRTAX', 'AP DISCOUNTS', 'AP EXPENSE', 'PO RECEIPT'
6736                                      , 'PO RECEIPT NRTAX', 'PO RECEIPT NRTAX PRICE ADJ', 'PO RECEIPT PRICE ADJ')
6737          AND ( X_adj_action IN ( 'PROJECT OR TASK CHANGE'
6738                                , 'BILLABLE RECLASS'
6739                                , 'NON-BILLABLE RECLASS'
6740                                , 'CAPITALIZABLE RECLASS'
6741                                , 'NON-CAPITALIZABLE RECLASS'
6742                                , 'RAW COST RECALC'
6743                                , 'COST AND REV RECALC')
6744           OR ( X_adj_action = 'CHANGE WORK TYPE ATTRIBUTE'
6745          AND   NVL(PA_UTILS4.get_trxn_work_billabilty(p_dest_work_type_id, NULL),l_billable_flag) <> l_billable_flag)) THEN
6746 
6747              IF pa_adjustments.is_recoverability_affected
6748                          (p_expenditure_item_id => v_expenditure_item_id
6749                          ,p_org_id => v_exp_org_id
6750                          ,p_system_linkage_function => v_system_linkage
6751                          ,p_transaction_source => l_transaction_source
6752                          ,p_action => X_adj_action
6753                          ,p_project_id => NVL(x_dest_prj_id,l_project_id)
6754                          ,p_task_id => NVL(x_dest_task_id,v_task_id)
6755                          ,p_expenditure_type => v_exp_type
6756                          ,p_vendor_id => l_vendor_id
6757                          ,p_expenditure_organization_id => v_exp_organization_id
6758                          ,p_expenditure_item_date => v_exp_item_date
6759                          ,p_emp_id => v_incurred_by_person_id
6760                          ,p_document_header_id => l_document_header_id
6761                          ,p_document_line_number => l_document_line_number
6762                          ,p_document_distribution_id => l_document_distribution_id
6763                          ,p_document_type => l_document_type
6764                          ,p_award_id => NVL(p_dest_award_id,PA_GMS_API.VERT_GET_EI_AWARD_ID(v_expenditure_item_id))
6765                          ,p_billable_flag1 => l_billable_flag
6766                          ,x_error_message_name => l_error_message_name /* Bug 4997739 */
6767                          ,x_encoded_error_message => l_encoded_error_message) THEN /* Bug 4997739 */
6768 
6769 /* Bug 4997739 - Trap exceptions from workflow or eBTax API */
6770                IF l_encoded_error_message IS NOT NULL THEN
6771                  fnd_message.parse_encoded(l_encoded_error_message,l_application_short_name,l_error_message_name);
6772                  v_allow_adjustments := l_error_message_name;
6773                ELSE
6774                  v_allow_adjustments := l_error_message_name;
6775                END IF;
6776              END IF;
6777 
6778          END IF;
6779 
6780          IF  v_allow_adjustments = 'N'
6781          AND v_system_linkage IN ('VI','ER')
6782          AND l_gl_accounted = 'Y'
6783          AND ( X_adj_action IN ( 'PROJECT OR TASK CHANGE'
6784                                , 'BILLABLE RECLASS'
6785                                , 'NON-BILLABLE RECLASS'
6786                                , 'CAPITALIZABLE RECLASS'
6787                                , 'NON-CAPITALIZABLE RECLASS'
6788                                , 'RAW COST RECALC'
6789                                , 'COST AND REV RECALC')
6790           OR ( X_adj_action = 'CHANGE WORK TYPE ATTRIBUTE'
6791          AND   NVL(PA_UTILS4.get_trxn_work_billabilty(p_dest_work_type_id, NULL),l_billable_flag) <> l_billable_flag)) THEN
6792 
6793              IF NOT pa_adjustments.Allow_Adjust_with_Auto_Offset
6794                          (p_expenditure_item_id => v_expenditure_item_id
6795                          ,p_org_id => v_exp_org_id
6796                          ,p_system_linkage_function => v_system_linkage
6797                          ,p_transaction_source => l_transaction_source
6798                          ,p_action => X_adj_action
6799                          ,p_project_id => NVL(x_dest_prj_id,l_project_id)
6800                          ,p_task_id => NVL(x_dest_task_id,v_task_id)
6801                          ,p_expenditure_type => v_exp_type
6802                          ,p_vendor_id => l_vendor_id
6803                          ,p_expenditure_organization_id => v_exp_organization_id
6804                          ,p_expenditure_item_date => v_exp_item_date
6805                          ,p_emp_id => v_incurred_by_person_id
6806                          ,p_invoice_distribution_id => l_document_distribution_id
6807                          ,p_invoice_payment_id => l_document_payment_id /* Bug 5006835 */
6808                          ,p_award_id => NVL(p_dest_award_id,PA_GMS_API.VERT_GET_EI_AWARD_ID(v_expenditure_item_id))
6809                          ,p_billable_flag1 => l_billable_flag
6810                          ,x_encoded_error_message => l_encoded_error_message) THEN /* Bug 4997739 */
6811 
6812 /* Bug 4997739 - Trap exceptions from workflow */
6813                IF l_encoded_error_message IS NOT NULL THEN
6814                  fnd_message.parse_encoded(l_encoded_error_message,l_application_short_name,l_error_message_name);
6815                  v_allow_adjustments := l_error_message_name;
6816                ELSE
6817                  v_allow_adjustments := 'PA_SI_ADJ_LB_ACC_CHG_NOT_ALLOW';
6818                END IF;
6819 
6820              END IF;
6821 
6822          END IF;
6823 
6824 /* Bug 5436420 - PA_GMS_API.VERT_TRANSFER will verify for award dates and statuses and the
6825                  expenditure type. Added the adjustment actions Capitalizable, Non-Capitalizable,
6826                  Recalculate Raw Cost, Recalculate Burden Cost, Billable, Non-Billable, Bill Hold,
6827                  Once-Time Hold, Release Hold, Recalculate Revenue, Recalculate Cost/Revenue */
6828          IF  v_allow_adjustments = 'N'
6829          AND X_adj_action IN ( 'BILLABLE RECLASS'
6830                              , 'NON-BILLABLE RECLASS'
6831                              , 'BILLING HOLD'
6832                              , 'ONE-TIME BILLING HOLD'
6833                              , 'BILLING HOLD RELEASE'
6834                              , 'CAPITALIZABLE RECLASS'
6835                              , 'NON-CAPITALIZABLE RECLASS'
6836                              , 'RAW COST RECALC'
6837                              , 'INDIRECT COST RECALC'
6838                              , 'COST AND REV RECALC'
6839                              , 'REVENUE RECALC'
6840                              , 'PROJECT OR TASK CHANGE')
6841          AND NOT PA_GMS_API.VERT_TRANSFER(v_expenditure_item_id,v_allow_adjustments) THEN
6842 
6843            NULL;
6844 
6845          END IF;
6846 
6847 /* Bug 5436420 - 1) For Non-Sponsored projects, adjustment should be disllowed if the source
6848                     and destination tasks are same.
6849                  2) For Sponsored Projects, adjustment should allowed if the source task,
6850                     award are both equal to the destination task,award respectively. */
6851          if  v_allow_adjustments = 'N'
6852          and x_Adj_action in ( 'PROJECT OR TASK CHANGE')
6853          and v_task_id = x_dest_task_id then
6854              l_award_id := PA_GMS_API.VERT_GET_EI_AWARD_ID(v_expenditure_item_id);
6855              if  l_award_id is null
6856              and p_dest_award_id is null then
6857                  v_allow_adjustments := 'PA_TR_APE_CANT_XFER_TO_SELF';
6858              elsif l_award_id = p_dest_award_id then
6859                  v_allow_adjustments := 'GMS_TR_SOURCE_DEST_AWARDS_SAME';
6860              end if;
6861          end if;
6862 /* R12 Changes End */
6863 
6864           IF v_allow_adjustments <> 'N' THEN
6865 
6866            	temp_num_rejected := temp_num_rejected + 1;
6867 	     /* R12 Changes Start */
6868 	        InsAuditRec( v_expenditure_item_id
6869             	           , X_adj_action
6870                   	   , X_module
6871 	                   , X_user
6872           	           , X_login
6873                   	   , temp_status
6874 	                   , G_REQUEST_ID
6875           	           , G_PROGRAM_ID
6876                   	   , G_PROG_APPL_ID
6877 	                   , sysdate
6878           	           , v_allow_adjustments);
6879 	                CheckStatus(temp_status);
6880             /* R12 changes End */
6881             j := j + 1 ;
6882 
6883           else
6884 
6885           i := i + 1;
6886 
6887              IF X_adj_action <> 'INDIRECT COST RECALC' then
6888                 ItemsIdTab(i)    := v_expenditure_item_id;
6889                 AdjustsIdTab(i)  := NULL;
6890                 DenomCurrCodeTab(i) := v_denom_currency_code ;
6891                 ProjCurrCodeTab(i)  := v_project_currency_code ;
6892                 SysLinkageTab(i)    := v_system_linkage ;
6893                 CrossChargeCodeTab(i) := v_cc_code ;
6894                 DenomTpCurrCodeTab(i) := v_denom_tp_currency_code ;
6895 		ProjFuncCurrCodeTab(i) := l_projfunc_currency_code;
6896 
6897                 TpAmtTypCodeTab(i)     := l_tp_amt_type_code;
6898 
6899                 IF X_adj_action = 'REPROCESS CROSS CHARGE' then
6900                    ExpOrganizationTab(i) := v_exp_organization_id ;
6901                    ExpOrgTab(i)          := v_exp_org_id ;
6902                    TaskIdTab(i)          := v_task_id ;
6903                    ExpItemDateTab(i)     := v_exp_item_date ;
6904                    ExpTypeTab(i)         := v_exp_type ;
6905                    IncurredByPersonIdTab(i) := v_incurred_by_person_id ;
6906                    TrxSourceTab(i)          := l_transaction_source ;
6907                    NlrOrganizationIdTab(i)  := v_nlr_organization_id ;
6908                 END IF ;
6909 
6910              ELSE
6911                 IF v_project_type_class_code <> 'CAPITAL' then
6912                     k := k + 1;
6913                     ItemsIdNCapTab(k)    := v_expenditure_item_id;
6914                     AdjustsIdNCapTab(k)  := NULL;
6915                 ELSE
6916                     l := l + 1;
6917                     ItemsIdCapTab(l)     := v_expenditure_item_id;
6918                     AdjustsIdCapTab(l)   := NULL;
6919                 END IF;
6920              END IF;
6921 
6922              IF i >= 500 then
6923 
6924 		IF P_DEBUG_MODE  THEN
6925 		   print_message('get_denom_curr_code: ' || 'calling massaction ');
6926 		END IF;
6927                 IF X_adj_action <>  'INDIRECT COST RECALC' then
6928                    MassAction( ItemsIdTab
6929                              , AdjustsIdTab
6930                              , X_adj_action
6931                              , X_module
6932                              , X_user
6933                              , X_login
6934                              , i
6935                              , X_dest_prj_id
6936                              , X_dest_task_id
6937                 	     , X_project_currency_code
6938                              , X_project_rate_type
6939                              , X_project_rate_date
6940                              , X_project_exchange_rate
6941                              , X_acct_rate_type
6942 			     , X_acct_rate_date
6943 			     , X_acct_exchange_rate
6944 			     , DenomCurrCodeTab
6945                              , ProjCurrCodeTab
6946                              , temp_status
6947                              , num_processed
6948                              , num_rejected
6949            		     , ProjFuncCurrCodeTab
6950            		     , p_projfunc_cost_rate_type
6951            		     , p_projfunc_cost_rate_date
6952            		     , p_projfunc_cost_exchange_rate
6953            		     , p_project_tp_cost_rate_type
6954            		     , p_project_tp_cost_rate_date
6955            		     , p_project_tp_cost_exchg_rate
6956            		     , p_assignment_id
6957            		     , p_dest_work_type_id
6958 			     , p_projfunc_currency_code
6959                              , TpAmtTypCodeTab
6960                              , p_dest_tp_amt_type_code);
6961                    temp_num_processed := temp_num_processed + num_processed;
6962                    temp_num_rejected  := temp_num_rejected  + num_rejected ;
6963 
6964                 ELSE
6965 
6966                    MassAction( ItemsIdNCapTab
6967                              , AdjustsIdNCapTab
6968                              , 'INDIRECT COST RECALC'
6969                              , X_module
6970                              , X_user
6971                              , X_login
6972                              , k
6973                              , X_dest_prj_id
6974                              , X_dest_task_id
6975                 	     , X_project_currency_code
6976                              , X_project_rate_type
6977                              , X_project_rate_date
6978                              , X_project_exchange_rate
6979                              , X_acct_rate_type
6980 			     , X_acct_rate_date
6981 			     , X_acct_exchange_rate
6982 			     , DenomCurrCodeTab
6983                              , ProjCurrCodeTab
6984                              , temp_status
6985                              , num_processed
6986                              , num_rejected
6987                              , ProjFuncCurrCodeTab
6988                              , p_projfunc_cost_rate_type
6989                              , p_projfunc_cost_rate_date
6990                              , p_projfunc_cost_exchange_rate
6991                              , p_project_tp_cost_rate_type
6992                              , p_project_tp_cost_rate_date
6993                              , p_project_tp_cost_exchg_rate
6994                              , p_assignment_id
6995                              , p_dest_work_type_id
6996 			     , p_projfunc_currency_code
6997                              , TpAmtTypCodeTab
6998                              , p_dest_tp_amt_type_code);
6999                    temp_num_processed := temp_num_processed + num_processed;
7000                    temp_num_rejected  := temp_num_rejected  + num_rejected ;
7001 
7002                    MassAction( ItemsIdCapTab
7003                              , AdjustsIdCapTab
7004                              , 'CAPITAL COST RECALC'
7005                              , X_module
7006                              , X_user
7007                              , X_login
7008                              , l
7009                              , X_dest_prj_id
7010                              , X_dest_task_id
7011                 	     , X_project_currency_code
7012                 	     , X_project_rate_type
7013                              , X_project_rate_date
7014                              , X_project_exchange_rate
7015                              , X_acct_rate_type
7016 			     , X_acct_rate_date
7017 			     , X_acct_exchange_rate
7018 			     , DenomCurrCodeTab
7019                              , ProjCurrCodeTab
7020                              , temp_status
7021                              , num_processed
7022                              , num_rejected
7023                              , ProjFuncCurrCodeTab
7024                              , p_projfunc_cost_rate_type
7025                              , p_projfunc_cost_rate_date
7026                              , p_projfunc_cost_exchange_rate
7027                              , p_project_tp_cost_rate_type
7028                              , p_project_tp_cost_rate_date
7029                              , p_project_tp_cost_exchg_rate
7030                              , p_assignment_id
7031                              , p_dest_work_type_id
7032 			     , p_projfunc_currency_code
7033                              , TpAmtTypCodeTab
7034                              , p_dest_tp_amt_type_code);
7035                    temp_num_processed := temp_num_processed + num_processed;
7036                    temp_num_rejected  := temp_num_rejected  + num_rejected ;
7037                  END IF;
7038 
7039                  j := j + i;
7040                  i := 0;
7041                  k := 0;
7042                  l := 0;
7043 
7044                  IF ( temp_outcome IS NOT NULL ) THEN
7045                     RAISE INVALID_ITEM;
7046                  END IF;
7047 	    IF P_DEBUG_MODE  THEN
7048 	       print_message('get_denom_curr_code: ' || 'after mass action');
7049 	    END IF;
7050 
7051 /* Bug 5501593 - Start */
7052 /* Commit after 5000 transactions have been processed */
7053                l_commit_count := l_commit_count + 500;
7054                IF l_commit_count >= 5000 THEN
7055                    commit;
7056                    l_commit_count := 0;
7057                END IF;
7058 /* Bug 5501593 - End */
7059 
7060            END IF;
7061        END IF;
7062        END LOOP;
7063 
7064 -- Added a close cursor since this was causing problems when this
7065 -- procedure was called multiple times. Customer - Oakridge
7066      IF P_DEBUG_MODE  THEN
7067         print_message('get_denom_curr_code: ' || 'close the cursor ');
7068      END IF;
7069      dbms_sql.close_cursor(v_cursor_adj_id)  ;
7070 
7071        IF i >= 1 then
7072            IF X_adj_action <>  'INDIRECT COST RECALC' then
7073  	IF P_DEBUG_MODE  THEN
7074  	   print_message('get_denom_curr_code: ' || 'i is ['||i||'] denom_currcode[' ||v_denom_currency_code||']' );
7075  	END IF;
7076                 MassAction( ItemsIdTab
7077                           , AdjustsIdTab
7078                           , X_adj_action
7079                           , X_module
7080                           , X_user
7081                           , X_login
7082                           , i
7083                           , X_dest_prj_id
7084                           , X_dest_task_id
7085                 	  , X_project_currency_code
7086                           , X_project_rate_type
7087                           , X_project_rate_date
7088                           , X_project_exchange_rate
7089                           , X_acct_rate_type
7090 			  , X_acct_rate_date
7091 			  , X_acct_exchange_rate
7092 			  , DenomCurrCodeTab
7093                           , ProjCurrCodeTab
7094                           , temp_status
7095                           , num_processed
7096                           , num_rejected
7097                           , ProjFuncCurrCodeTab
7098                           , p_projfunc_cost_rate_type
7099                           , p_projfunc_cost_rate_date
7100                           , p_projfunc_cost_exchange_rate
7101                           , p_project_tp_cost_rate_type
7102                           , p_project_tp_cost_rate_date
7103                           , p_project_tp_cost_exchg_rate
7104                           , p_assignment_id
7105                           , p_dest_work_type_id
7106 			  , p_projfunc_currency_code
7107                           , TpAmtTypCodeTab
7108                           , p_dest_tp_amt_type_code);
7109                    temp_num_processed := temp_num_processed + num_processed;
7110                    temp_num_rejected  := temp_num_rejected  + num_rejected ;
7111             ELSE
7112                 MassAction( ItemsIdNCapTab
7113                           , AdjustsIdNCapTab
7114                           , 'INDIRECT COST RECALC'
7115                           , X_module
7116                           , X_user
7117                           , X_login
7118                           , k
7119                           , X_dest_prj_id
7120                           , X_dest_task_id
7121                 	  , X_project_currency_code
7122                 	  , X_project_rate_type
7123                 	  , X_project_rate_date
7124                 	  , X_project_exchange_rate
7125                           , X_acct_rate_type
7126 			  , X_acct_rate_date
7127 			  , X_acct_exchange_rate
7128 			  , DenomCurrCodeTab
7129                           , ProjCurrCodeTab
7130                           , temp_status
7131                           , num_processed
7132                           , num_rejected
7133                           , ProjFuncCurrCodeTab
7134                           , p_projfunc_cost_rate_type
7135                           , p_projfunc_cost_rate_date
7136                           , p_projfunc_cost_exchange_rate
7137                           , p_project_tp_cost_rate_type
7138                           , p_project_tp_cost_rate_date
7139                           , p_project_tp_cost_exchg_rate
7140                           , p_assignment_id
7141                           , p_dest_work_type_id
7142 			  , p_projfunc_currency_code
7143                           , TpAmtTypCodeTab
7144                           , p_dest_tp_amt_type_code );
7145                    temp_num_processed := temp_num_processed + num_processed;
7146                    temp_num_rejected  := temp_num_rejected  + num_rejected ;
7147 
7148                 MassAction( ItemsIdCapTab
7149                           , AdjustsIdCapTab
7150                           , 'CAPITAL COST RECALC'
7151                           , X_module
7152                           , X_user
7153                           , X_login
7154                           , l
7155                           , X_dest_prj_id
7156                           , X_dest_task_id
7157                 	  , X_project_currency_code
7158                 	  , X_project_rate_type
7159                		  , X_project_rate_date
7160                 	  , X_project_exchange_rate
7161                           , X_acct_rate_type
7162 			  , X_acct_rate_date
7163 			  , X_acct_exchange_rate
7164 			  , DenomCurrCodeTab
7165                           , ProjCurrCodeTab
7166                           , temp_status
7167                           , num_processed
7168                           , num_rejected
7169                           , ProjFuncCurrCodeTab
7170                           , p_projfunc_cost_rate_type
7171                           , p_projfunc_cost_rate_date
7172                           , p_projfunc_cost_exchange_rate
7173                           , p_project_tp_cost_rate_type
7174                           , p_project_tp_cost_rate_date
7175                           , p_project_tp_cost_exchg_rate
7176                           , p_assignment_id
7177                           , p_dest_work_type_id
7178 			  , p_projfunc_currency_code
7179                           , TpAmtTypCodeTab
7180                           , p_dest_tp_amt_type_code);
7181                    temp_num_processed := temp_num_processed + num_processed;
7182                    temp_num_rejected  := temp_num_rejected  + num_rejected ;
7183             END IF;
7184          END IF;
7185 
7186          j := j + i ;
7187          i := 0;
7188          k := 0;
7189          l := 0;
7190 
7191    IF ( j = 0 ) THEN
7192         X_outcome := 'PA_PR_NO_ITEMS_PROC';
7193         X_num_processed := 0;
7194         X_num_rejected  := 0;
7195         RETURN;
7196    END IF;
7197 
7198    END IF;
7199  IF P_DEBUG_MODE  THEN
7200     print_message('get_denom_curr_code: ' || 'temp num process is[ '||temp_num_processed||']num reject is[ '||temp_num_rejected
7201 	      ||']End of Mass Adjust api');
7202  END IF;
7203 
7204 X_num_processed := temp_num_processed;
7205 X_num_rejected  := temp_num_rejected;
7206 X_outcome       := NULL;
7207 
7208 EXCEPTION
7209    WHEN  INVALID_ITEM  THEN
7210      IF P_DEBUG_MODE  THEN
7211         print_message('get_denom_curr_code: ' || 'execption INVALID_ITEM IN mass adjust');
7212      END IF;
7213      X_outcome := temp_outcome;
7214   WHEN RESOURCE_BUSY THEN
7215      X_outcome := 'PA_ALL_COULD_NOT_LOCK';
7216 	IF P_DEBUG_MODE  THEN
7217 	   print_message('get_denom_curr_code: ' || 'execption RESOURCE_BUSY IN mass adjust PA_ALL_COULD_NOT_LOCK');
7218 	END IF;
7219      RAISE ;
7220   WHEN  OTHERS  THEN
7221      IF P_DEBUG_MODE  THEN
7222         print_message('get_denom_curr_code: ' || 'execption OTHERS IN mass adjust '||SQLCODE||sqlerrm);
7223      END IF;
7224      X_outcome := SQLCODE;
7225      RAISE;
7226 
7227 END  MassAdjust;
7228 
7229 -- ========================================================================
7230 -- PROCEDURE MassAction
7231 -- ========================================================================
7232 
7233 -- This procedure was created to improve the performance allowing multiple
7234 
7235   PROCEDURE  MassAction(
7236              ItemsIdTab                  IN pa_utils.IdTabTyp
7237            , AdjustsIdTab                IN pa_utils.IdTabTyp
7238            , X_adj_action                IN VARCHAR2
7239            , X_module                    IN VARCHAR2
7240            , X_user                      IN NUMBER
7241            , X_login                     IN NUMBER
7242            , X_num_rows                  IN NUMBER
7243            , X_dest_prj_id               IN NUMBER
7244            , X_dest_task_id              IN NUMBER
7245 	   , X_project_currency_code IN VARCHAR2
7246            , X_project_rate_type     IN VARCHAR2
7247            , X_project_rate_date     IN DATE
7248            , X_project_exchange_rate IN NUMBER
7249            , X_acct_rate_type        IN VARCHAR2
7250 	   , X_acct_rate_date        IN DATE
7251 	   , X_acct_exchange_rate     IN NUMBER
7252            , DenomCurrCodeTab          IN pa_utils.Char15TabTyp
7253            , ProjCurrCodeTab           IN pa_utils.Char15TabTyp
7254            , X_status                    OUT NOCOPY VARCHAR2
7255            , X_num_processed             OUT NOCOPY NUMBER
7256            , X_num_rejected              OUT NOCOPY NUMBER
7257 	   , ProjFuncCurrCodeTab           IN pa_utils.Char15TabTyp
7258 	   , p_projfunc_cost_rate_type     IN VARCHAR2
7259            , p_projfunc_cost_rate_date     IN date
7260            , p_projfunc_cost_exchange_rate IN NUMBER
7261 	   , p_project_tp_cost_rate_type   IN VARCHAR2
7262            , p_project_tp_cost_rate_date   IN DATE
7263            , p_project_tp_cost_exchg_rate  IN NUMBER
7264 	   , p_assignment_id               IN NUMBER
7265            , p_work_type_id                IN NUMBER
7266 	   , p_projfunc_currency_code      IN VARCHAR2
7267            , p_TpAmtTypCodeTab             IN pa_utils.Char30TabTyp
7268            , p_dest_tp_amt_type_code       IN VARCHAR2     )
7269 
7270   IS
7271     dummy               NUMBER;
7272     temp_outcome        VARCHAR2(30) DEFAULT NULL;
7273     temp_status         NUMBER DEFAULT NULL;
7274     temp_num_processed  NUMBER DEFAULT 0;
7275     temp_num_rejected   NUMBER DEFAULT 0;
7276 	 temp_msg_application  VARCHAR2(30);
7277 	 temp_msg_type		   VARCHAR2(1);
7278 	 temp_msg_token1 	   VARCHAR2(240);
7279 	 temp_msg_token2	 	VARCHAR2(240);
7280 	 temp_msg_token3	 	VARCHAR2(240);
7281 	 temp_msg_count	 	Number;
7282     i                   BINARY_INTEGER := 0;
7283     j                   BINARY_INTEGER := 0;
7284     k                   BINARY_INTEGER := 0;
7285     l                   BINARY_INTEGER := 0;
7286     adj_ei              number;
7287 
7288     l_projfunc_currency_code    varchar2(15);
7289 
7290   BEGIN
7291 
7292 	IF P_DEBUG_MODE  THEN
7293 	   print_message('get_denom_curr_code: ' || 'Entering MassAction api adjust action ['||X_adj_action||']proj func cur code ['
7294 	||p_projfunc_currency_code||']work type ['||p_work_type_id||']assignment id ['||p_assignment_id||']' );
7295 	END IF;
7296 
7297     /** commented and passing the IN param to Transfer api
7298      IF ProjFuncCurrCodeTab.EXISTS(1) then
7299 	    l_projfunc_currency_code := ProjFuncCurrCodeTab(1);
7300      END IF;
7301      **/
7302 
7303      l_projfunc_currency_code := p_projfunc_currency_code;
7304 
7305 
7306       IF ( X_adj_action = 'BILLABLE RECLASS' ) THEN
7307 
7308          Reclass( ItemsIdTab
7309                 , AdjustsIdTab
7310                 , 'Y'
7311                 , X_adj_action
7312                 , X_user
7313                 , X_login
7314                 , X_module
7315                 , X_num_rows
7316                 , temp_status );
7317 
7318          CheckStatus( temp_status );
7319          temp_num_processed := X_num_rows ;
7320 
7321       ELSIF ( X_adj_action = 'NON-BILLABLE RECLASS' ) THEN
7322 
7323          Reclass( ItemsIdTab
7324                 , AdjustsIdTab
7325                 , 'N'
7326                 , X_adj_action
7327                 , X_user
7328                 , X_login
7329                 , X_module
7330                 , X_num_rows
7331                 , temp_status );
7332          CheckStatus( temp_status );
7333          temp_num_processed := X_num_rows ;
7334 
7335       ELSIF ( X_adj_action = 'CAPITALIZABLE RECLASS' ) THEN
7336 
7337          Reclass( ItemsIdTab
7338                 , AdjustsIdTab
7339                 , 'Y'
7340                 , X_adj_action
7341                 , X_user
7342                 , X_login
7343                 , X_module
7344                 , X_num_rows
7345                 , temp_status );
7346          CheckStatus( temp_status );
7347          temp_num_processed := X_num_rows ;
7348 
7349       ELSIF ( X_adj_action = 'NON-CAPITALIZABLE RECLASS' ) THEN
7350 
7351          Reclass( ItemsIdTab
7352                 , AdjustsIdTab
7353                 , 'N'
7354                 , X_adj_action
7355                 , X_user
7356                 , X_login
7357                 , X_module
7358                 , X_num_rows
7359                 , temp_status );
7360          CheckStatus( temp_status );
7361          temp_num_processed := X_num_rows ;
7362 
7363       ELSIF ( X_adj_action = 'BILLING HOLD' ) THEN
7364 
7365             Hold( ItemsIdTab
7366                 , AdjustsIdTab
7367                 , 'Y'
7368                 , X_adj_action
7369                 , X_user
7370                 , X_login
7371                 , X_module
7372                 , X_num_rows
7373                 , temp_status );
7374          CheckStatus( temp_status );
7375          temp_num_processed := X_num_rows ;
7376 
7377       ELSIF ( X_adj_action = 'BILLING HOLD RELEASE' ) THEN
7378 
7379             Hold( ItemsIdTab
7380                 , AdjustsIdTab
7381                 , 'N'
7382                 , X_adj_action
7383                 , X_user
7384                 , X_login
7385                 , X_module
7386                 , X_num_rows
7387                 , temp_status );
7388           CheckStatus( temp_status );
7389          temp_num_processed := X_num_rows ;
7390 
7391      ELSIF ( X_adj_action = 'ONE-TIME BILLING HOLD' ) THEN
7392 
7393             Hold( ItemsIdTab
7394                 , AdjustsIdTab
7395                 , 'O'
7396                 , X_adj_action
7397                 , X_user
7398                 , X_login
7399                 , X_module
7400                 , X_num_rows
7401                 , temp_status );
7402           CheckStatus( temp_status );
7403          temp_num_processed := X_num_rows ;
7404 
7405     ELSIF ( X_adj_action = 'INDIRECT COST RECALC' ) THEN
7406 
7407        RecalcIndCost( ItemsIdTab
7408                 , AdjustsIdTab
7409                 , X_user
7410                 , X_login
7411                 , X_module
7412                 , X_num_rows
7413                 , temp_status );
7414      CheckStatus( temp_status );
7415      temp_num_processed := X_num_rows ;
7416 
7417     ELSIF ( X_adj_action = 'COST AND REV RECALC' ) THEN
7418        RecalcCostRev( ItemsIdTab
7419                 , AdjustsIdTab
7420                 , X_user
7421                 , X_login
7422                 , X_module
7423                 , X_num_rows
7424                 , temp_num_processed
7425                 , temp_status );
7426         CheckStatus( temp_status );
7427 
7428     ELSIF ( X_adj_action = 'REVENUE RECALC' ) THEN
7429 
7430        RecalcRev( ItemsIdTab
7431                 , AdjustsIdTab
7432                 , X_user
7433                 , X_login
7434                 , X_module
7435                 , X_num_rows
7436                 , temp_status );
7437         CheckStatus( temp_status );
7438         temp_num_processed := X_num_rows ;
7439 
7440     ELSIF ( X_adj_action = 'CAPITAL COST RECALC' ) THEN
7441 
7442        RecalcCapCost( ItemsIdTab
7443                 , AdjustsIdTab
7444                 , X_user
7445                 , X_login
7446                 , X_module
7447                 , X_num_rows
7448                 , temp_status );
7449         CheckStatus( temp_status );
7450         temp_num_processed := X_num_rows ;
7451 
7452     ELSIF ( X_adj_action = 'RAW COST RECALC' ) THEN
7453 
7454         RecalcRawCost( ItemsIdTab
7455                 , AdjustsIdTab
7456                 , X_user
7457                 , X_login
7458 		, X_module
7459                 , X_num_rows
7460                 , temp_num_processed
7461                 , temp_status );
7462         CheckStatus( temp_status );
7463 
7464     -- call to the new rate attribute adjustment procedures
7465     ELSIF ( X_adj_action = 'CHANGE FUNC ATTRIBUTE' ) THEN
7466          ChangeFuncAttributes(ItemsIdTab
7467                           , 'S'
7468                           , X_user
7469                           , X_login
7470                           , X_module
7471                           , X_acct_rate_type
7472 			  , X_acct_rate_date
7473 			  , X_acct_exchange_rate
7474 			  , DenomCurrCodeTab
7475                           , ProjCurrCodeTab
7476                           , X_num_rows
7477                           , temp_num_processed
7478                           , temp_num_rejected
7479                           , temp_status
7480 			  , ProjFuncCurrCodeTab) ;
7481           CheckStatus( temp_status );
7482 
7483      -- call to the new rate attribute adjustment procedures
7484      ELSIF ( X_adj_action = 'CHANGE PROJ ATTRIBUTE' ) THEN
7485 
7486          ChangeProjAttributes(ItemsIdTab
7487                           , 'S'
7488                           , X_user
7489                           , X_login
7490                           , X_module
7491                           , X_project_rate_type
7492                           , X_project_rate_date
7493                           , X_project_exchange_rate
7494                           , DenomCurrCodeTab
7495                           , ProjCurrCodeTab
7496                           , X_num_rows
7497                           , temp_num_processed
7498                           , temp_num_rejected
7499                           , temp_status         ) ;
7500           CheckStatus( temp_status );
7501      -- call to the new project funcational rate attribute adjustment procedures
7502      ELSIF ( X_adj_action = 'CHANGE PROJ FUNC ATTRIBUTE' ) THEN
7503 
7504          ChangeProjFuncAttributes(ItemsIdTab
7505                           , 'S'
7506                           , X_user
7507                           , X_login
7508                           , X_module
7509                           , p_projfunc_cost_rate_type
7510                           , p_projfunc_cost_rate_date
7511                           , p_projfunc_cost_exchange_rate
7512                           , DenomCurrCodeTab
7513                           , ProjFuncCurrCodeTab
7514                           , X_num_rows
7515                           , temp_num_processed
7516                           , temp_num_rejected
7517                           , temp_status         ) ;
7518           CheckStatus( temp_status );
7519 
7520     ELSIF ( X_adj_action = 'REPROCESS CROSS CHARGE' ) THEN
7521           ReprocessCrossCharge (ItemsIdTab
7522          			  , 'S'
7523            			  , X_user
7524            			  , X_login
7525            			  , X_module
7526                			  , Null
7527 			      	  , Null
7528 				  , Null
7529 				  , Null
7530                                   , Null
7531                                   , Null
7532             			  , X_num_rows
7533            			  , temp_num_processed
7534            			  , temp_status ) ;
7535      CheckStatus( temp_status );
7536     ELSIF ( X_adj_action = 'MARK NO CC PROCESS' ) THEN
7537            MarkNoCCProcess (ItemsIdTab
7538           			 , 'S'
7539            			 , X_user
7540            			 , X_login
7541            			 , X_module
7542  				 , Null
7543 				 , Null
7544             			 , X_num_rows
7545            			 , temp_num_processed
7546            			 , temp_status ) ;
7547        CheckStatus( temp_status );
7548     ELSIF ( X_adj_action = 'CHANGE TP ATTRIBUTE' ) THEN
7549 	    ChangeTpAttributes(ItemsIdTab
7550                           , 'S'
7551                           , X_user
7552                           , X_login
7553                           , X_module
7554                           , X_acct_rate_type
7555                           , X_acct_rate_date
7556                           , X_acct_exchange_rate
7557 	      	          , Null
7558 		          , Null
7559                           , DenomCurrCodeTab
7560                           , X_num_rows
7561                           , temp_num_processed
7562                           , temp_num_rejected
7563                           , temp_status
7564                           , p_PROJECT_TP_COST_RATE_DATE
7565                           , p_PROJECT_TP_COST_RATE_TYPE
7566                           , p_PROJECT_TP_COST_EXCHG_RATE) ;
7567       CheckStatus( temp_status );
7568     ELSIF ( X_adj_action = 'PROJECT OR TASK CHANGE' ) THEN
7569 
7570         Transfer( ItemsIdTab
7571                 , X_dest_prj_id
7572                 , X_dest_task_id
7573                 , X_project_currency_code
7574                 , X_project_rate_type
7575                 , X_project_rate_date
7576                 , X_project_exchange_rate
7577                 , X_user
7578                 , X_login
7579                 , X_module
7580                 , 'S'
7581                 , X_num_rows
7582                 , temp_num_processed
7583                 , temp_num_rejected
7584                 , temp_outcome
7585 		, temp_msg_application
7586 		, temp_msg_type
7587 		, temp_msg_token1
7588 		, temp_msg_token2
7589 		, temp_msg_token3
7590 		, temp_msg_count
7591                 , l_projfunc_currency_code
7592                 , p_projfunc_cost_rate_type
7593                 , p_projfunc_cost_rate_date
7594                 , p_projfunc_cost_exchange_rate
7595                 , p_assignment_id
7596                 , p_work_type_id);
7597 
7598       		IF ( temp_outcome IS NOT NULL AND ( temp_msg_type = 'E' ) ) THEN /* Added msg_type check for Bug 4906816 */
7599           		RAISE INVALID_ITEM;
7600       		END IF;
7601 	/**  start proj currency changes **/
7602     ELSIF ( X_adj_action = 'CHANGE WORK TYPE ATTRIBUTE' ) THEN
7603 
7604 	IF P_DEBUG_MODE  THEN
7605 	   print_message('get_denom_curr_code: ' || 'calling work_type_adjustment api');
7606 	END IF;
7607         	work_type_adjustment
7608                    ( ItemsIdTab        => ItemsIdTab
7609                     --, AdjustsIdTab   => AdjustsIdTab
7610                     , p_billable       => NULL
7611                     , p_work_type_id   =>p_work_type_id
7612                     , p_adj_activity   =>X_adj_action
7613                     , p_user           =>X_user
7614                     , p_login          =>X_login
7615                     , p_module         =>X_module
7616                     , p_rows           =>X_num_rows
7617                     , p_TpAmtTypCodeTab       => p_TpAmtTypCodeTab
7618                     , p_dest_tp_amt_type_code => p_dest_tp_amt_type_code
7619                     , x_status         => temp_status);
7620 
7621 	IF P_DEBUG_MODE  THEN
7622 	   print_message('get_denom_curr_code: ' || 'end of work type adjustment api');
7623 	END IF;
7624 
7625         	CheckStatus( temp_status );
7626 		temp_num_processed := X_num_rows ;
7627 
7628 	/** end proj currency changes **/
7629 
7630     END IF;
7631 
7632 
7633 X_num_processed := temp_num_processed;
7634 X_num_rejected  := temp_num_rejected;
7635 X_status        := NULL;
7636 
7637 EXCEPTION
7638    WHEN  INVALID_ITEM  THEN
7639      X_status := temp_outcome;
7640   WHEN RESOURCE_BUSY THEN
7641      X_status := 'PA_ALL_COULD_NOT_LOCK';
7642   WHEN  OTHERS  THEN
7643      X_status := SQLCODE;
7644      RAISE;
7645 
7646 END  MassAction;
7647 
7648 
7649 /*----------------------------------------------------------------------------
7650  -- See Package specs for detail comments for this ei_adjusted_in_cache.
7651 ----------------------------------------------------------------------------*/
7652 FUNCTION ei_adjusted_in_cache(X_exp_item_id In Number) RETURN Varchar2
7653 IS
7654 l_exp_item_id Number(15) := NULL;
7655 
7656 BEGIN
7657 
7658    l_exp_item_id := pa_adjustments.ExpAdjItemTab(X_exp_item_id);
7659    RETURN('Y');
7660 
7661 EXCEPTION WHEN NO_DATA_FOUND THEN
7662    RETURN('N');
7663 WHEN OTHERS THEN
7664    raise;
7665 END ei_adjusted_in_cache;
7666 
7667 
7668 -- Fix for bug # 913353. in the decode for the project attributes
7669 -- replaced acct_rate_type etc with X_acct_rate_type
7670 
7671   PROCEDURE  ChangeFuncAttributes(ItemsIdTab          IN pa_utils.IdTabTyp
7672                           , X_adjust_level   IN VARCHAR2
7673                           , X_user           IN NUMBER
7674                           , X_login          IN NUMBER
7675                           , X_module         IN VARCHAR2
7676                           , X_acct_rate_type IN VARCHAR2
7677 			  , X_acct_rate_date IN DATE
7678 			  , X_acct_exchange_rate IN NUMBER
7679                           , DenomCurrCodeTab IN pa_utils.Char15TabTyp
7680 			  , ProjCurrCodeTab  IN  pa_utils.Char15TabTyp
7681                           , rows             IN NUMBER
7682                           , X_num_processed  OUT NOCOPY NUMBER
7683                           , X_num_rejected   OUT NOCOPY NUMBER
7684                           , X_status         OUT NOCOPY NUMBER
7685                           , ProjfuncCurrCodeTab IN pa_utils.Char15TabTyp  ) IS
7686 
7687      temp_status         NUMBER DEFAULT NULL;
7688      item_count          NUMBER := 0;
7689      failed_count        NUMBER := 0 ;
7690      l_status            VARCHAR2(240)DEFAULT NULL ;
7691      l_acct_exchange_rate NUMBER := X_acct_exchange_rate;
7692      l_acct_rate_type  VARCHAR2(30) := X_acct_rate_type ;
7693      l_acct_rate_date  DATE         := X_acct_rate_date ;
7694      l_dummy1            NUMBER ;
7695      l_dummy2            NUMBER ;
7696      l_dummy3            NUMBER ;
7697 
7698  -- pa_multi_currency.init ;
7699 
7700      PROCEDURE  RecalcRelatedItems( X_expenditure_item_id  IN NUMBER
7701                                   , X_user                 IN NUMBER
7702                                   , X_login                IN NUMBER
7703                                   , X_acct_rate_type       IN VARCHAR2
7704 			          , X_acct_rate_date       IN DATE
7705 			          , X_acct_exchange_rate   IN NUMBER
7706 			          , X_project_currency_code IN VARCHAR2
7707                                   , X_module               IN VARCHAR2
7708                                   , X_status               OUT NOCOPY NUMBER
7709                                   , p_projfunc_currency_code IN VARCHAR2)
7710      IS
7711        CURSOR GetRelatedItems IS
7712          SELECT
7713                  expenditure_item_id
7714            FROM
7715                  pa_expenditure_items_all
7716           WHERE
7717                  source_expenditure_item_id = X_expenditure_item_id;
7718      BEGIN
7719 
7720        FOR eachRec IN GetRelatedItems LOOP
7721 
7722          UPDATE pa_expenditure_items_all
7723             SET
7724                  cost_distributed_flag = 'N'
7725          ,       revenue_distributed_flag = 'N'
7726          ,       acct_rate_type = X_acct_rate_type
7727          ,       acct_rate_date = X_acct_rate_date
7728          ,       acct_exchange_rate = X_acct_exchange_rate
7729          ,       project_rate_type = DECODE(X_project_currency_code,
7730                  		       pa_multi_currency.G_accounting_currency_code,
7731   				       X_acct_rate_type,project_rate_type )
7732          ,       project_rate_date = DECODE(X_project_currency_code,
7733                  			pa_multi_currency.G_accounting_currency_code,
7734 					X_acct_rate_date, project_rate_date )
7735          ,       project_exchange_rate = DECODE(X_project_currency_code,
7736                  			pa_multi_currency.G_accounting_currency_code,
7737 					X_acct_exchange_rate,project_exchange_rate )
7738          ,       acct_raw_cost = NULL
7739          ,       acct_burdened_cost = NULL
7740          ,       project_raw_cost = DECODE(X_project_currency_code,
7741                  		pa_multi_currency.G_accounting_currency_code, NULL, project_raw_cost )
7742          ,       project_burdened_cost = DECODE(X_project_currency_code,
7743                  		pa_multi_currency.G_accounting_currency_code, NULL,project_burdened_cost )
7744          ,       last_updated_by = X_user
7745          ,       last_update_date = sysdate
7746          ,       last_update_login = X_login
7747          ,       projfunc_cost_rate_type = DECODE(p_projfunc_currency_code,
7748                                        pa_multi_currency.G_accounting_currency_code,
7749                                        X_acct_rate_type,projfunc_cost_rate_type )
7750          ,       projfunc_cost_rate_date = DECODE(p_projfunc_currency_code,
7751                                         pa_multi_currency.G_accounting_currency_code,
7752                                         X_acct_rate_date, projfunc_cost_rate_date )
7753          ,       projfunc_cost_exchange_rate = DECODE(p_projfunc_currency_code,
7754                                         pa_multi_currency.G_accounting_currency_code,
7755                                         X_acct_exchange_rate,projfunc_cost_exchange_rate )
7756          ,       raw_cost = DECODE(p_projfunc_currency_code,
7757                                 pa_multi_currency.G_accounting_currency_code, NULL, raw_cost )
7758          ,       burden_cost = DECODE(p_projfunc_currency_code,
7759                                 pa_multi_currency.G_accounting_currency_code, NULL,burden_cost )
7760 
7761            WHERE
7762                  expenditure_item_id = eachRec.expenditure_item_id;
7763 
7764          item_count := item_count + 1;
7765 
7766          pa_adjustments.InsAuditRec( eachRec.expenditure_item_id
7767                                    , 'CHANGE FUNC ATTRIBUTE'
7768                                    , X_module
7769                                    , X_user
7770                                    , X_login
7771                                    , temp_status
7772 				/* R12 Changes Start */
7773 	                           , G_REQUEST_ID
7774           	                   , G_PROGRAM_ID
7775 	                           , G_PROG_APPL_ID
7776 	                           , sysdate );
7777  				/* R12 Changes End */
7778          CheckStatus( temp_status );
7779 
7780        END LOOP;
7781 
7782      X_status := 0;
7783 
7784      EXCEPTION
7785        WHEN  OTHERS  THEN
7786          X_status := SQLCODE;
7787          RAISE;
7788 
7789      END  RecalcRelatedItems;
7790 
7791 
7792   BEGIN
7793 
7794 	IF P_DEBUG_MODE  THEN
7795 	   print_message('get_denom_curr_code: ' || 'inside changefunccurrenc attri api');
7796 	END IF;
7797     FOR i IN 1..rows LOOP
7798 
7799 	IF P_DEBUG_MODE  THEN
7800 	   print_message('get_denom_curr_code: ' || 'DenomCurrCodeTab(i)['||DenomCurrCodeTab(i)||']ProjCurrCodeTab(i)['||ProjCurrCodeTab(i)||
7801 	']ProjfuncCurrCodeTab(i)['||ProjFuncCurrCodeTab(i) || ']' );
7802 	END IF;
7803        pa_multi_currency.init ;
7804    IF X_adjust_level = 'S' THEN
7805 
7806 	IF P_DEBUG_MODE  THEN
7807 	   print_message('get_denom_curr_code: ' || 'calling pa_multi currency api');
7808 	END IF;
7809        pa_multi_currency.convert_amount( DenomCurrCodeTab(i)
7810                                         , pa_multi_currency.G_accounting_currency_code
7811                                         , l_acct_rate_date
7812                                         , l_acct_rate_type
7813                                         , null
7814                                         , 'Y'
7815                                         , 'Y'
7816                                         , l_dummy1
7817                                         , l_dummy2
7818                                         , l_dummy3
7819                                         , l_acct_exchange_rate
7820                                         , l_status  ) ;
7821 
7822 	IF P_DEBUG_MODE  THEN
7823 	   print_message('get_denom_curr_code: ' || 'l_acct_rate_date['||l_acct_rate_date||']l_acct_rate_type['||l_acct_rate_type
7824 		    ||']G_accounting_currency_code['||pa_multi_currency.G_accounting_currency_code
7825 		    ||']l_acct_exchange_rate['||l_acct_exchange_rate||']' );
7826 	END IF;
7827     END IF ;
7828 
7829         IF l_status is not null then
7830               failed_count := failed_count + 1 ;
7831 	/* R12 Changes Start */
7832               InsAuditRec( ItemsIdTab(i)
7833                          , 'CHANGE FUNC ATTRIBUTE'
7834                          , X_module
7835                          , X_user
7836                          , X_login
7837                          , temp_status
7838                          , G_REQUEST_ID
7839                          , G_PROGRAM_ID
7840                          , G_PROG_APPL_ID
7841                          , sysdate
7842                          , l_status);
7843               CheckStatus(temp_status);
7844 	/* R12 Changes End */
7845 
7846         ELSE
7847 
7848         UPDATE pa_expenditure_items_all ei
7849          SET
7850              ei.cost_distributed_flag = 'N'
7851       ,      ei.revenue_distributed_flag = 'N'
7852       ,       acct_rate_type = X_acct_rate_type
7853       ,       acct_rate_date = X_acct_rate_date
7854       ,       acct_exchange_rate = l_acct_exchange_rate
7855       ,       project_rate_type = DECODE(ProjCurrCodeTab(i),
7856               				pa_multi_currency.G_accounting_currency_code,
7857 					X_acct_rate_type, project_rate_type )
7858       ,       project_rate_date = DECODE(ProjCurrCodeTab(i),
7859               				pa_multi_currency.G_accounting_currency_code,
7860 					X_acct_rate_date, project_rate_date )
7861       ,       project_exchange_rate = DECODE(ProjCurrCodeTab(i),
7862               				pa_multi_currency.G_accounting_currency_code,
7863               				X_acct_exchange_rate , project_exchange_rate )
7864       ,       acct_raw_cost = NULL
7865       ,       acct_burdened_cost = NULL
7866       ,       project_raw_cost = DECODE(ProjCurrCodeTab(i),
7867               			pa_multi_currency.G_accounting_currency_code, NULL, project_raw_cost )
7868       ,       project_burdened_cost = DECODE(ProjCurrCodeTab(i),
7869               			pa_multi_currency.G_accounting_currency_code, NULL, project_burdened_cost )
7870       ,      ei.last_update_date = sysdate
7871       ,      ei.last_updated_by = X_user
7872       ,      ei.last_update_login = X_login
7873          ,       projfunc_cost_rate_type = DECODE(ProjFuncCurrCodeTab(i),
7874                                        pa_multi_currency.G_accounting_currency_code,
7875                                        X_acct_rate_type,projfunc_cost_rate_type )
7876          ,       projfunc_cost_rate_date = DECODE(ProjFuncCurrCodeTab(i),
7877                                         pa_multi_currency.G_accounting_currency_code,
7878                                         X_acct_rate_date, projfunc_cost_rate_date )
7879          ,       projfunc_cost_exchange_rate = DECODE(ProjFuncCurrCodeTab(i),
7880                                         pa_multi_currency.G_accounting_currency_code,
7881                                         X_acct_exchange_rate,projfunc_cost_exchange_rate )
7882          ,       raw_cost = DECODE(ProjFuncCurrCodeTab(i),
7883                                 pa_multi_currency.G_accounting_currency_code, NULL, raw_cost )
7884          ,       burden_cost = DECODE(ProjFuncCurrCodeTab(i),
7885                                 pa_multi_currency.G_accounting_currency_code, NULL,burden_cost )
7886        WHERE
7887              ei.expenditure_item_id = ItemsIdTab(i);
7888 
7889       item_count := item_count + 1;
7890 
7891       InsAuditRec( ItemsIdTab(i)
7892                  , 'CHANGE FUNC ATTRIBUTE'
7893                  , X_module
7894                  , X_user
7895                  , X_login
7896                  , temp_status
7897 	/* R12 Changes Start */
7898 	         , G_REQUEST_ID
7899           	 , G_PROGRAM_ID
7900 	         , G_PROG_APPL_ID
7901 	         , sysdate );
7902  	/* R12 Changes End */
7903       CheckStatus( temp_status );
7904 
7905     RecalcRelatedItems( ItemsIdTab(i)
7906                         , X_user
7907                         , X_login
7908                         , X_acct_rate_type
7909                         , X_acct_rate_date
7910                         , l_acct_exchange_rate
7911                         , ProjCurrCodeTab(i)
7912                         , X_module
7913                         , temp_status
7914                         , ProjFuncCurrCodeTab(i));
7915       CheckStatus( temp_status );
7916 
7917     END IF ;
7918     END LOOP;
7919 
7920     X_status := 0;
7921     X_num_processed := item_count;
7922     X_num_rejected  := failed_count ;
7923 
7924   EXCEPTION
7925     WHEN  OTHERS  THEN
7926       X_status := SQLCODE;
7927       RAISE;
7928 
7929   END  ChangeFuncAttributes;
7930 
7931 /** This api is newly added to convert / change the project functional currency attributes
7932  *  this is called from EI enquiry form for EI adjustments
7933  */
7934   PROCEDURE  ChangeProjFuncAttributes
7935                          (ItemsIdTab                 	IN pa_utils.IdTabTyp
7936                           , p_adjust_level           	IN VARCHAR2
7937                           , p_user                   	IN NUMBER
7938                           , p_login                  	IN NUMBER
7939                           , p_module                 	IN VARCHAR2
7940                           , p_projfunc_cost_rate_type   IN VARCHAR2
7941                           , p_projfunc_cost_rate_date   IN DATE
7942                           , p_projfunc_cost_exchg_rate  IN NUMBER
7943                           , p_DenomCurrCodeTab          IN pa_utils.Char15TabTyp
7944                           , p_ProjFuncCurrCodeTab       IN pa_utils.Char15TabTyp
7945                           , p_rows                      IN NUMBER
7946                           , X_num_processed             OUT NOCOPY NUMBER
7947                           , X_num_rejected              OUT NOCOPY NUMBER
7948                           , X_status                    OUT NOCOPY NUMBER
7949                          ) IS
7950 
7951      temp_status         NUMBER DEFAULT NULL;
7952      item_count          NUMBER := 0;
7953      failed_count        NUMBER := 0 ;
7954      l_status            VARCHAR2(240)DEFAULT NULL ;
7955      l_projfunc_cost_exchg_rate NUMBER := p_projfunc_cost_exchg_rate;
7956      l_projfunc_cost_rate_type  VARCHAR2(30) := p_projfunc_cost_rate_type;
7957      l_projfunc_cost_rate_date  DATE         := p_projfunc_cost_rate_date;
7958      l_dummy1            NUMBER ;
7959      l_dummy2            NUMBER ;
7960      l_dummy3            NUMBER ;
7961      PROCEDURE  RecalcRelatedItems( X_expenditure_item_id  IN NUMBER
7962                                   , X_user                 IN NUMBER
7963                                   , X_login                IN NUMBER
7964                                   , X_projfunc_cost_rate_type        IN VARCHAR2
7965                                   , X_projfunc_cost_rate_date       IN DATE
7966                                   , X_projfunc_cost_exchg_rate      IN NUMBER
7967                                   , X_projfunc_currency_code         IN VARCHAR2
7968                                   , X_module               IN VARCHAR2
7969                                   , X_status               OUT NOCOPY NUMBER
7970                                   )
7971      IS
7972        CURSOR GetRelatedItems IS
7973          SELECT
7974                  expenditure_item_id
7975            FROM
7976                  pa_expenditure_items_all
7977           WHERE
7978                  source_expenditure_item_id = X_expenditure_item_id;
7979      BEGIN
7980        FOR eachRec IN GetRelatedItems LOOP
7981 
7982          UPDATE pa_expenditure_items_all
7983             SET
7984                  cost_distributed_flag = 'N'
7985          ,       revenue_distributed_flag = 'N'
7986          ,       projfunc_cost_rate_type = X_projfunc_cost_rate_type
7987          ,       projfunc_cost_rate_date = X_projfunc_cost_rate_date
7988          ,       projfunc_cost_exchange_rate =X_projfunc_cost_exchg_rate
7989          ,       raw_cost = NULL
7990          ,       burden_cost = NULL
7991          ,       acct_rate_type = DECODE(X_projfunc_currency_code,
7992                                          pa_multi_currency.G_accounting_currency_code,
7993                                          X_projfunc_cost_rate_type, acct_rate_type )
7994          ,       acct_rate_date = DECODE(X_projfunc_currency_code,
7995                                          pa_multi_currency.G_accounting_currency_code,
7996                                          X_projfunc_cost_rate_date , acct_rate_date )
7997          ,       acct_exchange_rate = DECODE(X_projfunc_currency_code,
7998                  		             pa_multi_currency.G_accounting_currency_code,
7999                                              X_projfunc_cost_exchg_rate , acct_exchange_rate )
8000          ,       acct_raw_cost = DECODE(X_projfunc_currency_code,
8001                                         pa_multi_currency.G_accounting_currency_code,
8002                                         NULL, acct_raw_cost )
8003          ,       acct_burdened_cost = DECODE(X_projfunc_currency_code,
8004                                         pa_multi_currency.G_accounting_currency_code,
8005                                         NULL,acct_burdened_cost )
8006         /** added for project currency changes **/
8007          ,       project_rate_type = DECODE(x_projfunc_currency_code,project_currency_code,
8008                                          x_projfunc_cost_rate_type, project_rate_type )
8009          ,       project_rate_date = DECODE(x_projfunc_currency_code,project_currency_code,
8010                                          X_projfunc_cost_rate_date , project_rate_date )
8011          ,       project_exchange_rate = DECODE(x_projfunc_currency_code,project_currency_code,
8012                                              p_projfunc_cost_exchg_rate , project_exchange_rate )
8013 	 ,       project_raw_cost = DECODE(x_projfunc_currency_code,project_currency_code,
8014 					  NULL ,project_raw_cost)
8015 	 ,       project_burdened_cost = DECODE(x_projfunc_currency_code,project_currency_code,
8016 					 NULL,project_burdened_cost)
8017         /** end of changes **/
8018          ,       last_updated_by = X_user
8019          ,       last_update_date = sysdate
8020          ,       last_update_login = X_login
8021            WHERE
8022                  expenditure_item_id = eachRec.expenditure_item_id;
8023 
8024          item_count := item_count + 1;
8025 
8026          pa_adjustments.InsAuditRec( eachRec.expenditure_item_id
8027                                    , 'CHANGE PROJ FUNC ATTRIBUTE'
8028                                    , X_module
8029                                    , X_user
8030                                    , X_login
8031                                    , temp_status
8032 				/* R12 Changes Start */
8033 	                           , G_REQUEST_ID
8034           	                   , G_PROGRAM_ID
8035 	                           , G_PROG_APPL_ID
8036 	                           , sysdate );
8037  				/* R12 Changes End */
8038          CheckStatus( temp_status );
8039 
8040        END LOOP;
8041 
8042      X_status := 0;
8043 
8044      EXCEPTION
8045        WHEN  OTHERS  THEN
8046          X_status := SQLCODE;
8047          RAISE;
8048 
8049      END  RecalcRelatedItems;
8050   BEGIN
8051     FOR i IN 1..p_rows LOOP
8052 
8053 	IF P_DEBUG_MODE  THEN
8054 	   print_message('get_denom_curr_code: ' || 'Inside the ProjFuncCurrCode api p_DenomCurrCodeTab(i)['||p_DenomCurrCodeTab(i)||
8055 	']p_ProjFuncCurrCodeTab(i)['||p_ProjFuncCurrCodeTab(i)||']l_projfunc_cost_rate_date['
8056         ||l_projfunc_cost_rate_date||']l_projfunc_cost_rate_type['||l_projfunc_cost_rate_type||']' );
8057 	END IF;
8058 
8059       pa_multi_currency.init ;
8060     IF p_adjust_level = 'S' THEN
8061 	IF P_DEBUG_MODE  THEN
8062 	   print_message('get_denom_curr_code: ' || 'calling pa_multi_currency api');
8063 	END IF;
8064        pa_multi_currency.convert_amount( p_DenomCurrCodeTab(i)
8065                                         ,p_ProjFuncCurrCodeTab(i)
8066                                         , l_projfunc_cost_rate_date
8067                                         , l_projfunc_cost_rate_type
8068                                         , null
8069                                         , 'Y'
8070                                         , 'Y'
8071                                         , l_dummy1
8072                                         , l_dummy2
8073                                         , l_dummy3
8074                                         , l_projfunc_cost_exchg_rate
8075                                         , l_status  ) ;
8076 
8077 	IF P_DEBUG_MODE  THEN
8078 	   print_message('get_denom_curr_code: ' || 'l_projfunc_cost_exchg_rate['||l_projfunc_cost_exchg_rate||']l_projfunc_cost_rate_date['
8079 	||l_projfunc_cost_rate_date||']l_projfunc_cost_rate_type['||l_projfunc_cost_rate_type||']' );
8080 	END IF;
8081      END IF ;
8082 
8083         IF l_status is not null then
8084               failed_count := failed_count + 1 ;
8085 	/* R12 Changes Start */
8086               InsAuditRec( ItemsIdTab(i)
8087                          , 'CHANGE FUNC ATTRIBUTE'
8088                          , p_module
8089                          , p_user
8090                          , p_login
8091                          , temp_status
8092                          , G_REQUEST_ID
8093                          , G_PROGRAM_ID
8094                          , G_PROG_APPL_ID
8095                          , sysdate
8096                          , l_status);
8097               CheckStatus(temp_status);
8098 	/* R12 Changes End */
8099 
8100         ELSE
8101       UPDATE pa_expenditure_items_all ei
8102          SET
8103              ei.cost_distributed_flag = 'N'
8104       ,      ei.revenue_distributed_flag = 'N'
8105       ,       projfunc_cost_rate_type = p_projfunc_cost_rate_type
8106       ,       projfunc_cost_rate_date = p_projfunc_cost_rate_date
8107       ,       projfunc_cost_exchange_rate = l_projfunc_cost_exchg_rate
8108       ,       raw_cost = NULL
8109       ,       burden_cost = NULL
8110       ,       acct_rate_type = DECODE(p_ProjFuncCurrCodeTab(i),
8111               				pa_multi_currency.G_accounting_currency_code,
8112 					p_projfunc_cost_rate_type, acct_rate_type )
8113       ,       acct_rate_date = DECODE(p_ProjFuncCurrCodeTab(i),
8114               				pa_multi_currency.G_accounting_currency_code,
8115 					p_projfunc_cost_rate_date , acct_rate_date )
8116       ,       acct_exchange_rate = DECODE(p_ProjFuncCurrCodeTab(i),
8117               				 pa_multi_currency.G_accounting_currency_code,
8118               				 l_projfunc_cost_exchg_rate , acct_exchange_rate )
8119       ,       acct_raw_cost = DECODE(p_ProjFuncCurrCodeTab(i),
8120               			     	pa_multi_currency.G_accounting_currency_code,
8121 				     	NULL, acct_raw_cost )
8122       ,       acct_burdened_cost = DECODE(p_ProjFuncCurrCodeTab(i),
8123               				pa_multi_currency.G_accounting_currency_code,
8124               				NULL,acct_burdened_cost )
8125         /** added for project currency changes **/
8126          ,       project_rate_type = DECODE(p_ProjFuncCurrCodeTab(i), project_currency_code,
8127                                          p_projfunc_cost_rate_type, project_rate_type )
8128          ,       project_rate_date = DECODE(p_ProjFuncCurrCodeTab(i), project_currency_code,
8129                                          p_projfunc_cost_rate_date , project_rate_date )
8130          ,       project_exchange_rate = DECODE(p_ProjFuncCurrCodeTab(i), project_currency_code,
8131                                              l_projfunc_cost_exchg_rate , project_exchange_rate )
8132          ,       project_raw_cost = DECODE(p_ProjFuncCurrCodeTab(i), project_currency_code,
8133                                           NULL ,project_raw_cost)
8134          ,       project_burdened_cost = DECODE(p_ProjFuncCurrCodeTab(i), project_currency_code,
8135                                          NULL,project_burdened_cost)
8136         /** end of changes **/
8137       ,      ei.last_update_date = sysdate
8138       ,      ei.last_updated_by = p_user
8139       ,      ei.last_update_login = p_login
8140        WHERE
8141              ei.expenditure_item_id = ItemsIdTab(i);
8142 
8143 	IF P_DEBUG_MODE  THEN
8144 	   print_message('get_denom_curr_code: ' || 'Num of rows update for eis ='||sql%rowcount);
8145 	END IF;
8146       item_count := item_count + 1;
8147       InsAuditRec( ItemsIdTab(i)
8148                  , 'CHANGE PROJ FUNC ATTRIBUTE'
8149                  , p_module
8150                  , p_user
8151                  , p_login
8152                  , temp_status
8153 	/* R12 Changes Start */
8154 	         , G_REQUEST_ID
8155           	 , G_PROGRAM_ID
8156 	         , G_PROG_APPL_ID
8157 	         , sysdate);
8158  	/* R12 Changes End */
8159       CheckStatus( temp_status );
8160 
8161 	IF P_DEBUG_MODE  THEN
8162 	   print_message('get_denom_curr_code: ' || 'calling RecalcRelatedItems items ');
8163 	END IF;
8164 
8165     RecalcRelatedItems( ItemsIdTab(i)
8166                         , p_user
8167                         , p_login
8168                         , p_projfunc_cost_rate_type
8169                         , p_projfunc_cost_rate_date
8170                         , l_projfunc_cost_exchg_rate
8171                         , p_ProjFuncCurrCodeTab(i)
8172                         , p_module
8173                         , temp_status );
8174       CheckStatus( temp_status );
8175 
8176     END IF;
8177     END LOOP;
8178 
8179     X_status := 0;
8180     X_num_processed := item_count;
8181     X_num_rejected  := failed_count ;
8182 
8183   EXCEPTION
8184     WHEN  OTHERS  THEN
8185       X_status := SQLCODE;
8186       RAISE;
8187 
8188   END  ChangeProjFuncAttributes;
8189 
8190 /** This api update the EI table when project curenncy attributes are changed **/
8191 
8192   PROCEDURE  ChangeProjAttributes(ItemsIdTab          IN pa_utils.IdTabTyp
8193                           , X_adjust_level   IN VARCHAR2
8194                           , X_user           IN NUMBER
8195                           , X_login          IN NUMBER
8196                           , X_module         IN VARCHAR2
8197                           , X_project_rate_type IN VARCHAR2
8198 			  , X_project_rate_date IN DATE
8199 			  , X_project_exchange_rate IN NUMBER
8200                           , DenomCurrCodeTab IN pa_utils.Char15TabTyp
8201                           , ProjCurrCodeTab IN  pa_utils.Char15TabTyp
8202                           , rows             IN NUMBER
8203                           , X_num_processed  OUT NOCOPY NUMBER
8204                           , X_num_rejected   OUT NOCOPY NUMBER
8205                           , X_status         OUT NOCOPY NUMBER ) IS
8206 
8207      temp_status         NUMBER DEFAULT NULL;
8208      item_count          NUMBER := 0;
8209      failed_count        NUMBER := 0 ;
8210      l_status            VARCHAR2(240)DEFAULT NULL ;
8211      l_project_exchange_rate NUMBER := X_project_exchange_rate;
8212      l_project_rate_type  VARCHAR2(30) := X_project_rate_type ;
8213      l_project_rate_date  DATE         := X_project_rate_date ;
8214      l_dummy1            NUMBER ;
8215      l_dummy2            NUMBER ;
8216      l_dummy3            NUMBER ;
8217 
8218 -- pa_multi_currency.init ;
8219 
8220      PROCEDURE  RecalcRelatedItems( X_expenditure_item_id  IN NUMBER
8221                                   , X_user                 IN NUMBER
8222                                   , X_login                IN NUMBER
8223                                   , X_project_rate_type       IN VARCHAR2
8224 			          , X_project_rate_date       IN DATE
8225 			          , X_project_exchange_rate   IN NUMBER
8226 			          , X_project_currency_code IN VARCHAR2
8227                                   , X_module               IN VARCHAR2
8228                                   , X_status               OUT NOCOPY NUMBER )
8229      IS
8230        CURSOR GetRelatedItems IS
8231          SELECT
8232                  expenditure_item_id
8233            FROM
8234                  pa_expenditure_items_all
8235           WHERE
8236                  source_expenditure_item_id = X_expenditure_item_id;
8237      BEGIN
8238 
8239        FOR eachRec IN GetRelatedItems LOOP
8240 
8241          UPDATE pa_expenditure_items_all
8242             SET
8243                  cost_distributed_flag = 'N'
8244          ,       revenue_distributed_flag = 'N'
8245          ,       project_rate_type = X_project_rate_type
8246          ,       project_rate_date = X_project_rate_date
8247          ,       project_exchange_rate = X_project_exchange_rate
8248          ,       acct_rate_type = DECODE(X_project_currency_code,
8249                  			pa_multi_currency.G_accounting_currency_code,
8250 					X_project_rate_type, acct_rate_type )
8251          ,       acct_rate_date = DECODE(X_project_currency_code,
8252                  			pa_multi_currency.G_accounting_currency_code,
8253 					X_project_rate_date, acct_rate_date )
8254          ,       acct_exchange_rate = DECODE(X_project_currency_code,
8255                  			 pa_multi_currency.G_accounting_currency_code,
8256                  			 X_project_exchange_rate , acct_exchange_rate )
8257          ,       project_raw_cost = NULL
8258          ,       project_burdened_cost = NULL
8259          ,       acct_raw_cost = DECODE(X_project_currency_code,
8260                  			pa_multi_currency.G_accounting_currency_code,
8261 					NULL, acct_raw_cost )
8262          ,       acct_burdened_cost = DECODE(X_project_currency_code,
8263 					pa_multi_currency.G_accounting_currency_code,
8264 					NULL,acct_burdened_cost )
8265          ,       last_updated_by = X_user
8266          ,       last_update_date = sysdate
8267          ,       last_update_login = X_login
8268            WHERE
8269                  expenditure_item_id = eachRec.expenditure_item_id;
8270 
8271          item_count := item_count + 1;
8272 
8273          pa_adjustments.InsAuditRec( eachRec.expenditure_item_id
8274                                    , 'CHANGE PROJ ATTRIBUTE'
8275                                    , X_module
8276                                    , X_user
8277                                    , X_login
8278                                    , temp_status
8279 				/* R12 Changes Start */
8280 	                           , G_REQUEST_ID
8281           	                   , G_PROGRAM_ID
8282 	                           , G_PROG_APPL_ID
8283 	                           , sysdate );
8284  				/* R12 Changes End */
8285          CheckStatus( temp_status );
8286 
8287        END LOOP;
8288 
8289      X_status := 0;
8290 
8291      EXCEPTION
8292        WHEN  OTHERS  THEN
8293          X_status := SQLCODE;
8294          RAISE;
8295 
8296      END  RecalcRelatedItems;
8297 
8298   BEGIN
8299     FOR i IN 1..rows LOOP
8300 
8301       pa_multi_currency.init ;
8302     IF X_adjust_level = 'S' THEN
8303        pa_multi_currency.convert_amount( DenomCurrCodeTab(i)
8304                                         ,ProjCurrCodeTab(i)
8305                                         , l_project_rate_date
8306                                         , l_project_rate_type
8307                                         , null
8308                                         , 'Y'
8309                                         , 'Y'
8310                                         , l_dummy1
8311                                         , l_dummy2
8312                                         , l_dummy3
8313                                         , l_project_exchange_rate
8314                                         , l_status  ) ;
8315      END IF ;
8316 
8317         IF l_status is not null then
8318               failed_count := failed_count + 1 ;
8319 	/* R12 Changes Start */
8320               InsAuditRec( ItemsIdTab(i)
8321                          , 'CHANGE FUNC ATTRIBUTE'
8322                          , X_module
8323                          , X_user
8324                          , X_login
8325                          , temp_status
8326                          , G_REQUEST_ID
8327                          , G_PROGRAM_ID
8328                          , G_PROG_APPL_ID
8329                          , sysdate
8330                          , l_status);
8331               CheckStatus(temp_status);
8332 	/* R12 Changes End */
8333         ELSE
8334 
8335       UPDATE pa_expenditure_items_all ei
8336          SET
8337              ei.cost_distributed_flag = 'N'
8338       ,      ei.revenue_distributed_flag = 'N'
8339       ,       project_rate_type = X_project_rate_type
8340       ,       project_rate_date = X_project_rate_date
8341       ,       project_exchange_rate = l_project_exchange_rate
8342       ,       acct_rate_type = DECODE(ProjCurrCodeTab(i),
8343               				pa_multi_currency.G_accounting_currency_code,
8344 					X_project_rate_type, acct_rate_type )
8345       ,       acct_rate_date = DECODE(ProjCurrCodeTab(i),
8346               				pa_multi_currency.G_accounting_currency_code,
8347 					X_project_rate_date , acct_rate_date )
8348       ,       acct_exchange_rate = DECODE(ProjCurrCodeTab(i),
8349               				pa_multi_currency.G_accounting_currency_code,
8350               				X_project_exchange_rate , acct_exchange_rate )
8351       ,       project_raw_cost = NULL
8352       ,       project_burdened_cost = NULL
8353       ,       acct_raw_cost = DECODE(ProjCurrCodeTab(i),
8354               			pa_multi_currency.G_accounting_currency_code,
8355 				NULL, acct_raw_cost )
8356       ,       acct_burdened_cost = DECODE(ProjCurrCodeTab(i),
8357               				pa_multi_currency.G_accounting_currency_code,
8358               				NULL,acct_burdened_cost )
8359       ,      ei.last_update_date = sysdate
8360       ,      ei.last_updated_by = X_user
8361       ,      ei.last_update_login = X_login
8362        WHERE
8363              ei.expenditure_item_id = ItemsIdTab(i);
8364 
8365       item_count := item_count + 1;
8366       InsAuditRec( ItemsIdTab(i)
8367                  , 'CHANGE PROJ ATTRIBUTE'
8368                  , X_module
8369                  , X_user
8370                  , X_login
8371                  , temp_status
8372 	/* R12 Changes Start */
8373 	         , G_REQUEST_ID
8374           	 , G_PROGRAM_ID
8375 	         , G_PROG_APPL_ID
8376 	         , sysdate );
8377  	/* R12 Changes End */
8378       CheckStatus( temp_status );
8379 
8380     RecalcRelatedItems( ItemsIdTab(i)
8381                         , X_user
8382                         , X_login
8383                         , X_project_rate_type
8384                         , X_project_rate_date
8385                         , l_project_exchange_rate
8386                         , ProjCurrCodeTab(i)
8387                         , X_module
8388                         , temp_status );
8389       CheckStatus( temp_status );
8390 
8391     END IF;
8392     END LOOP;
8393 
8394     X_status := 0;
8395     X_num_processed := item_count;
8396     X_num_rejected  := failed_count ;
8397 
8398   EXCEPTION
8399     WHEN  OTHERS  THEN
8400       X_status := SQLCODE;
8401       RAISE;
8402 
8403   END  ChangeProjAttributes;
8404 
8405 -- New procedure for the Cross Charge Adjustments
8406 
8407   PROCEDURE  ReprocessCrossCharge(ItemsIdTab       IN pa_utils.IdTabTyp
8408                                 , X_adjust_level   IN VARCHAR2
8409                                 , X_user           IN NUMBER
8410                                 , X_login          IN NUMBER
8411                                 , X_module         IN VARCHAR2
8412                                 , X_cc_code        IN VARCHAR2
8413                                 , X_cc_type        IN VARCHAR2
8414                                 , X_bl_dist_code   IN VARCHAR2
8415                                 , X_ic_proc_code   IN VARCHAR2
8416                                 , X_prvdr_orgnzn_id IN NUMBER
8417                                 , X_recvr_orgnzn_id IN NUMBER
8418                                 , rows             IN NUMBER
8419                                 , X_num_processed  OUT NOCOPY NUMBER
8420                                 , X_status         OUT NOCOPY NUMBER ) IS
8421 
8422      temp_status         NUMBER DEFAULT NULL;
8423      item_count          NUMBER := 0;
8424      l_project_id                   NUMBER;
8425      l_task_id                      NUMBER;
8426      l_expenditure_item_date        DATE;
8427      l_expenditure_type             VARCHAR2(30);
8428      l_incurred_by_person_id        NUMBER;
8429      l_system_linkage_function      VARCHAR2(30);
8430      l_transaction_source           VARCHAR2(30);
8431      l_nlr_organization_id          NUMBER;
8432      l_cc_code_old                  VARCHAR2(1):= NULL;
8433      l_cc_code                      VARCHAR2(1):= NULL;
8434      l_bl_dist_code                 VARCHAR2(1):= NULL;
8435      l_ic_proc_code                 VARCHAR2(1):= NULL;
8436      l_Status                       VARCHAR2(10);
8437      l_cc_Type                      VARCHAR2(2):= NULL;
8438      l_PrvdrOrganizationId          NUMBER := NULL;
8439      l_RecvrOrganizationId          NUMBER := NULL;
8440      l_RecvrOrgId                   NUMBER;
8441      l_Error_Stage                  VARCHAR2(10);
8442      l_Error_Code                   NUMBER;
8443 
8444     PROCEDURE  RecalcRelatedItems( X_expenditure_item_id  IN NUMBER
8445                                   , X_user                 IN NUMBER
8446                                   , X_login                IN NUMBER
8447                                   , X_module               IN VARCHAR2
8448                                   , X_status               OUT NOCOPY NUMBER )
8449      IS
8450        CURSOR GetRelatedItems IS
8451          SELECT
8452                  expenditure_item_id
8453          FROM
8454                  pa_expenditure_items_all
8455          WHERE
8456                  source_expenditure_item_id = X_expenditure_item_id;
8457      BEGIN
8458 
8459        FOR eachRec IN GetRelatedItems LOOP
8460 
8461          UPDATE pa_expenditure_items_all
8462          SET
8463           cc_cross_charge_code =DECODE(X_adjust_level,'I', X_cc_code, l_cc_code)
8464       ,   cc_cross_charge_type = DECODE(X_adjust_level,'I',X_cc_type, l_cc_type)
8465       ,   cc_bl_distributed_code = DECODE(X_adjust_level,'I',X_bl_dist_code,                                              l_bl_dist_code)
8466       ,   cc_ic_processed_code  =  DECODE(X_adjust_level,'I',X_ic_proc_code,                                              l_ic_proc_code)
8467       ,   cc_prvdr_organization_id = DECODE(X_adjust_level,'I',X_prvdr_orgnzn_id,                                                l_PrvdrOrganizationId)
8468       ,   cc_recvr_organization_id = DECODE(X_adjust_level,'I',X_recvr_orgnzn_id,                                                 l_RecvrOrganizationId)
8469       ,	  denom_tp_currency_code = NULL
8470       ,	  acct_tp_rate_type  = NULL
8471       ,	  acct_tp_rate_date   =  NULL
8472       ,	  acct_tp_exchange_rate =  NULL
8473       ,   denom_transfer_price = NULL
8474       ,	  acct_transfer_price = NULL
8475       ,   projacct_transfer_price = NULL
8476       ,   cc_markup_base_code= NULL
8477       ,   tp_base_amount = NULL
8478       ,   tp_ind_compiled_set_id = NULL
8479       ,   tp_bill_rate  = NULL
8480       ,   tp_bill_markup_percentage = NULL
8481       ,   tp_schedule_line_percentage = NULL
8482       ,   tp_rule_percentage = NULL
8483       ,   last_updated_by = X_user
8484       ,   last_update_date = sysdate
8485       ,   last_update_login = X_login
8486       ,   PROJECT_TP_RATE_DATE = null
8487       ,   PROJECT_TP_RATE_TYPE = null
8488       ,   PROJECT_TP_EXCHANGE_RATE = null
8489       ,   PROJECT_TRANSFER_PRICE = null
8490       ,   PROJFUNC_TP_RATE_DATE  = null
8491       ,   PROJFUNC_TP_RATE_TYPE  = null
8492       ,   PROJFUNC_TP_EXCHANGE_RATE = null
8493       ,   PROJFUNC_TRANSFER_PRICE = null
8494           WHERE
8495            expenditure_item_id = eachRec.expenditure_item_id;
8496 
8497          item_count := item_count + 1;
8498 
8499          pa_adjustments.InsAuditRec( eachRec.expenditure_item_id
8500                                    , 'REPROCESS CROSS CHARGE'
8501                                    , X_module
8502                                    , X_user
8503                                    , X_login
8504                                    , temp_status
8505 				/* R12 Changes Start */
8506 	                           , G_REQUEST_ID
8507           	                   , G_PROGRAM_ID
8508 	                           , G_PROG_APPL_ID
8509 	                           , sysdate );
8510  				/* R12 Changes End */
8511          CheckStatus( temp_status );
8512 
8513        END LOOP;
8514 
8515      X_status := 0;
8516 
8517      EXCEPTION
8518        WHEN  OTHERS  THEN
8519          X_status := SQLCODE;
8520          RAISE;
8521 
8522      END  RecalcRelatedItems;
8523 
8524 
8525 BEGIN
8526 
8527     FOR i IN 1..rows LOOP
8528  IF X_adjust_level = 'S' THEN
8529 
8530 -- Decided to fetch the columns needed for passing to the identification
8531 -- API during the MassAdjust select instead of writing a separate
8532 -- select here for performance reasons. We are storing the values fetched
8533 -- in global variables instead of passing as parameters to this procedure
8534 -- as the code was already complete and decided not to add more parameter
8535 -- which would require re testing
8536 
8537  IF P_DEBUG_MODE  THEN
8538     print_message('get_denom_curr_code: ' || 'before call to CC API, exp item is ['||to_char(ItemsIdTab(i))||']expdateis[ '
8539 	||to_char(ExpItemDateTab(i))||']exp org['||to_char(ExpOrganizationTab(i))||']OU[ '||to_char(ExpOrgTab(i))
8540 	||']exp type[ '||ExpTypeTab(i)||']' );
8541  END IF;
8542 
8543    pa_cc_ident.pa_cc_identify_txn_adj(ExpOrganizationTab(i),
8544    				ExpOrgTab(i),
8545 				null,
8546 				TaskIdTab(i),
8547 				ExpItemDateTab(i),
8548                                 ItemsIdTab(i),
8549 				ExpTypeTab(i),
8550 				IncurredByPersonIdTab(i),
8551 				SysLinkageTab(i),
8552                                 NULL, -- proj organization id
8553                                 null, -- PrjOrgId,
8554                                 TrxSourceTab(i),
8555                                 NlrOrganizationIdTab(i),
8556                                 null, -- PrvdrLEId
8557                                 null, -- RecvrLEId
8558                                 l_Status,
8559                                 l_cc_Type,
8560                                 l_cc_Code,
8561                                 l_PrvdrOrganizationId,
8562                                 l_RecvrOrganizationId,
8563                                 l_RecvrOrgId,
8564                                 l_Error_Stage,
8565                                 l_Error_Code,
8566 				X_Calling_Module        => null /* Modified for 3234973 */);
8567 
8568   l_cc_code_old := CrossChargeCodeTab(i) ;
8569 
8570    print_message('Before setting l_cc_code_old['||l_cc_code_old||']l_cc_code['||l_cc_code||']');
8571 
8572   if l_cc_code_old in ( 'N', 'X', 'P') /* Bug 4732956 */
8573   and l_cc_code = 'I' THEN
8574            l_ic_proc_code := 'N';
8575 	   l_bl_dist_code := 'X' ;
8576   elsif l_cc_code_old in ( 'N', 'X', 'P') /* Bug 4732956 */
8577   and l_cc_code = 'B' THEN
8578            /* Bug fix: 3065461 setting the bl_dist_code to N instead of X for reprocess CC items
8579             * when adjustment like No Process cross charge done first and then reporcess cross charge is made
8580            --l_ic_proc_code := 'N';
8581            --l_bl_dist_code := 'X' ;
8582            */
8583            l_ic_proc_code := 'X';
8584            l_bl_dist_code := 'N' ;
8585            /* end of bug fix:3065461 */
8586   elsif  l_cc_code_old = 'B'
8587   and l_cc_code = 'I' THEN
8588            l_ic_proc_code := 'N';
8589 	   l_bl_dist_code := 'N' ;
8590   elsif l_cc_code_old = 'B'
8591   and l_cc_code in ( 'N', 'X') THEN
8592            l_ic_proc_code := 'X';
8593 	   l_bl_dist_code := 'N' ;
8594   elsif l_cc_code_old = 'I'
8595   and l_cc_code in ( 'N', 'X') THEN
8596            l_ic_proc_code := 'N';
8597 	   l_bl_dist_code := 'X' ;
8598 /* Bug 4732956 - Start */
8599   elsif l_cc_code_old = 'P'
8600   and l_cc_code in ('N','X') THEN
8601            l_ic_proc_code := 'X';
8602            l_bl_dist_code := 'X' ;
8603 /* Bug 4732956 - End */
8604   elsif l_cc_code_old = 'I'
8605   and l_cc_code = 'B' THEN
8606            l_ic_proc_code := 'N';
8607 	   l_bl_dist_code := 'N' ;
8608   elsif l_cc_code_old = l_cc_code and
8609         l_cc_code_old = 'B' then
8610   -- This means that the cc code and/or the cc type has not changed
8611   -- but the user wants to do a reprocess CC , maybe in order to
8612   -- recalculate the TP amounts again. Hence, in this case, we
8613   -- set the appropriate flag to 'N'
8614            l_ic_proc_code := 'X';
8615            l_bl_dist_code := 'N' ;
8616   elsif l_cc_code_old = l_cc_code and
8617         l_cc_code_old = 'I' then
8618           l_ic_proc_code := 'N';
8619            l_bl_dist_code := 'X' ;
8620 /*** Bug 2215272 change the if condition
8621  *** elsif l_cc_code_old = l_cc_code and **/
8622   elsif l_cc_code in ('N','X') and
8623         l_cc_code_old in ('N', 'X') then
8624            l_ic_proc_code := 'X';
8625            l_bl_dist_code := 'X' ;
8626   end if;
8627  END IF;
8628 
8629   print_message('After setting l_ic_proc_code ['||l_ic_proc_code||']l_bl_dist_code['||l_bl_dist_code||
8630          ']X_cc_code['||X_cc_code||']X_cc_type['||X_cc_type||']X_bl_dist_code['||X_bl_dist_code||
8631          ']X_ic_proc_code['||X_ic_proc_code||']X_prvdr_orgnzn_id['||X_prvdr_orgnzn_id||
8632          ']X_recvr_orgnzn_id['||X_recvr_orgnzn_id||']l_PrvdrOrganizationId['||l_PrvdrOrganizationId||
8633          ']l_RecvrOrganizationId['||l_RecvrOrganizationId||']');
8634 
8635          UPDATE pa_expenditure_items_all
8636          SET
8637           cc_cross_charge_code =DECODE(X_adjust_level,'I', X_cc_code, l_cc_code)
8638       ,   cc_cross_charge_type = DECODE(X_adjust_level,'I',X_cc_type, l_cc_type)
8639       ,   cc_bl_distributed_code = DECODE(X_adjust_level,'I',X_bl_dist_code,                                              l_bl_dist_code)
8640       ,   cc_ic_processed_code  =  DECODE(X_adjust_level,'I',X_ic_proc_code,                                              l_ic_proc_code)
8641       ,   cc_prvdr_organization_id = DECODE(X_adjust_level,'I',X_prvdr_orgnzn_id,                                                l_PrvdrOrganizationId)
8642       ,   cc_recvr_organization_id = DECODE(X_adjust_level,'I',X_recvr_orgnzn_id,                                                 l_RecvrOrganizationId)
8643       ,	  denom_tp_currency_code = NULL
8644       ,	  acct_tp_rate_type  = NULL
8645       ,	  acct_tp_rate_date   =  NULL
8646       ,	  acct_tp_exchange_rate =  NULL
8647       ,   denom_transfer_price = NULL
8648       ,	  acct_transfer_price = NULL
8649       ,   projacct_transfer_price = NULL
8650       ,   cc_markup_base_code= NULL
8651       ,   tp_base_amount = NULL
8652       ,   tp_ind_compiled_set_id = NULL
8653       ,   tp_bill_rate  = NULL
8654       ,   tp_bill_markup_percentage = NULL
8655       ,   tp_schedule_line_percentage = NULL
8656       ,   tp_rule_percentage = NULL
8657       ,   last_updated_by = X_user
8658       ,   last_update_date = sysdate
8659       ,   last_update_login = X_login
8660       ,   PROJECT_TP_RATE_DATE = null
8661       ,   PROJECT_TP_RATE_TYPE = null
8662       ,   PROJECT_TP_EXCHANGE_RATE = null
8663       ,   PROJECT_TRANSFER_PRICE = null
8664       ,   PROJFUNC_TP_RATE_DATE  = null
8665       ,   PROJFUNC_TP_RATE_TYPE  = null
8666       ,   PROJFUNC_TP_EXCHANGE_RATE = null
8667       ,   PROJFUNC_TRANSFER_PRICE = null
8668           WHERE
8669           expenditure_item_id = ItemsIdTab(i);
8670       item_count := item_count + 1;
8671 
8672       InsAuditRec( ItemsIdTab(i)
8673                  , 'REPROCESS CROSS CHARGE'
8674                  , X_module
8675                  , X_user
8676                  , X_login
8677                  , temp_status
8678 	/* R12 Changes Start */
8679 	         , G_REQUEST_ID
8680           	 , G_PROGRAM_ID
8681 	         , G_PROG_APPL_ID
8682 	         , sysdate );
8683  	/* R12 Changes End */
8684       CheckStatus( temp_status );
8685 
8686 
8687       RecalcRelatedItems( ItemsIdTab(i)
8688                         , X_user
8689                         , X_login
8690                         , X_module
8691                         , temp_status );
8692       CheckStatus( temp_status );
8693 
8694     END LOOP;
8695 
8696     X_status := 0;
8697     X_num_processed := item_count;
8698 
8699   EXCEPTION
8700     WHEN  OTHERS  THEN
8701       X_status := SQLCODE;
8702       RAISE;
8703 END ReprocessCrossCharge ;
8704 
8705   PROCEDURE  MarkNoCCProcess    (ItemsIdTab       IN pa_utils.IdTabTyp
8706                                 , X_adjust_level   IN VARCHAR2
8707                                 , X_user           IN NUMBER
8708                                 , X_login          IN NUMBER
8709                                 , X_module         IN VARCHAR2
8710                                 , X_bl_dist_code   IN VARCHAR2
8711                                 , X_ic_proc_code   IN VARCHAR2
8712                                 , rows             IN NUMBER
8713                                 , X_num_processed  OUT NOCOPY NUMBER
8714                                 , X_status         OUT NOCOPY NUMBER ) IS
8715 
8716      temp_status         NUMBER DEFAULT NULL;
8717      item_count          NUMBER := 0;
8718      l_cc_code_old                  VARCHAR2(1):= NULL;
8719      l_bl_dist_code                 VARCHAR2(1):= NULL;
8720      l_ic_proc_code                 VARCHAR2(1):= NULL;
8721 
8722     PROCEDURE  RecalcRelatedItems( X_expenditure_item_id  IN NUMBER
8723                                   , X_user                 IN NUMBER
8724                                   , X_login                IN NUMBER
8725                                   , X_module               IN VARCHAR2
8726                                   , X_status               OUT NOCOPY NUMBER )
8727      IS
8728        CURSOR GetRelatedItems IS
8729          SELECT
8730                  expenditure_item_id
8731          FROM
8732                  pa_expenditure_items_all
8733          WHERE
8734                  source_expenditure_item_id = X_expenditure_item_id;
8735      BEGIN
8736  --print_message('in related ei');
8737       FOR eachRec IN GetRelatedItems LOOP
8738  --print_message('in related ei loop');
8739          UPDATE pa_expenditure_items_all
8740          SET
8741           cc_cross_charge_code = 'N'
8742       ,   cc_bl_distributed_code = DECODE(X_adjust_level,'I',X_bl_dist_code,                                              l_bl_dist_code)
8743       ,   cc_ic_processed_code  =  DECODE(X_adjust_level,'I',X_ic_proc_code,                                              l_ic_proc_code)
8744       ,	  denom_tp_currency_code = NULL
8745       ,	  acct_tp_rate_type  = NULL
8746       ,	  acct_tp_rate_date   =  NULL
8747       ,	  acct_tp_exchange_rate =  NULL
8748       ,   denom_transfer_price = NULL
8749       ,	  acct_transfer_price = NULL
8750       ,   projacct_transfer_price = NULL
8751       ,   cc_markup_base_code= NULL
8752       ,   tp_base_amount = NULL
8753       ,   tp_ind_compiled_set_id = NULL
8754       ,   tp_bill_rate  = NULL
8755       ,   tp_bill_markup_percentage = NULL
8756       ,   tp_schedule_line_percentage = NULL
8757       ,   tp_rule_percentage = NULL
8758       ,   last_updated_by = X_user
8759       ,   last_update_date = sysdate
8760       ,   last_update_login = X_login
8761       ,   PROJECT_TP_RATE_DATE = null
8762       ,   PROJECT_TP_RATE_TYPE = null
8763       ,   PROJECT_TP_EXCHANGE_RATE = null
8764       ,   PROJECT_TRANSFER_PRICE = null
8765       ,   PROJFUNC_TP_RATE_DATE  = null
8766       ,   PROJFUNC_TP_RATE_TYPE  = null
8767       ,   PROJFUNC_TP_EXCHANGE_RATE = null
8768       ,   PROJFUNC_TRANSFER_PRICE = null
8769           WHERE
8770            expenditure_item_id = eachRec.expenditure_item_id;
8771 
8772          item_count := item_count + 1;
8773 
8774          pa_adjustments.InsAuditRec( eachRec.expenditure_item_id
8775                                    , 'MARK NO CC PROCESS'
8776                                    , X_module
8777                                    , X_user
8778                                    , X_login
8779                                    , temp_status
8780 				/* R12 Changes Start */
8781 	                           , G_REQUEST_ID
8782           	                   , G_PROGRAM_ID
8783 	                           , G_PROG_APPL_ID
8784 	                           , sysdate );
8785  				/* R12 Changes End */
8786          CheckStatus( temp_status );
8787 
8788        END LOOP;
8789 
8790      X_status := 0;
8791 
8792      EXCEPTION
8793        WHEN  OTHERS  THEN
8794          X_status := SQLCODE;
8795          RAISE;
8796 
8797      END  RecalcRelatedItems;
8798 
8799 
8800 BEGIN
8801     FOR i IN 1..rows LOOP
8802  IF X_adjust_level = 'S' THEN
8803    l_cc_code_old := CrossChargeCodeTab(i) ;
8804 
8805   if    l_cc_code_old = 'B'then
8806            l_ic_proc_code := 'X';
8807 	   l_bl_dist_code := 'N' ;
8808   elsif l_cc_code_old = 'I'then
8809            l_ic_proc_code := 'N';
8810 	   l_bl_dist_code := 'X' ;
8811   end if;
8812  END IF;
8813 
8814 
8815          UPDATE pa_expenditure_items_all
8816          SET
8817           cc_cross_charge_code = 'N'
8818       ,   cc_bl_distributed_code = DECODE(X_adjust_level,'I',X_bl_dist_code,                                              l_bl_dist_code)
8819       ,   cc_ic_processed_code  =  DECODE(X_adjust_level,'I',X_ic_proc_code,                                              l_ic_proc_code)
8820       ,	  denom_tp_currency_code = NULL
8821       ,	  acct_tp_rate_type  = NULL
8822       ,	  acct_tp_rate_date   =  NULL
8823       ,	  acct_tp_exchange_rate =  NULL
8824       ,   denom_transfer_price = NULL
8825       ,	  acct_transfer_price = NULL
8826       ,   projacct_transfer_price = NULL
8827       ,   cc_markup_base_code= NULL
8828       ,   tp_base_amount = NULL
8829       ,   tp_ind_compiled_set_id = NULL
8830       ,   tp_bill_rate  = NULL
8831       ,   tp_bill_markup_percentage = NULL
8832       ,   tp_schedule_line_percentage = NULL
8833       ,   tp_rule_percentage = NULL
8834       ,   last_updated_by = X_user
8835       ,   last_update_date = sysdate
8836       ,   last_update_login = X_login
8837       ,   PROJECT_TP_RATE_DATE = null
8838       ,   PROJECT_TP_RATE_TYPE = null
8839       ,   PROJECT_TP_EXCHANGE_RATE = null
8840       ,   PROJECT_TRANSFER_PRICE = null
8841       ,   PROJFUNC_TP_RATE_DATE  = null
8842       ,   PROJFUNC_TP_RATE_TYPE  = null
8843       ,   PROJFUNC_TP_EXCHANGE_RATE = null
8844       ,   PROJFUNC_TRANSFER_PRICE = null
8845 
8846           WHERE
8847           expenditure_item_id = ItemsIdTab(i);
8848 
8849       item_count := item_count + 1;
8850 
8851       InsAuditRec( ItemsIdTab(i)
8852                  , 'MARK NO CC PROCESS'
8853                  , X_module
8854                  , X_user
8855                  , X_login
8856                  , temp_status
8857 	/* R12 Changes Start */
8858 	         , G_REQUEST_ID
8859           	 , G_PROGRAM_ID
8860 	         , G_PROG_APPL_ID
8861 	         , sysdate );
8862  	/* R12 Changes End */
8863       CheckStatus( temp_status );
8864 
8865  IF P_DEBUG_MODE  THEN
8866     print_message('get_denom_curr_code: ' || 'ei is '||to_char(ItemsIdTab(i)));
8867  END IF;
8868       RecalcRelatedItems( ItemsIdTab(i)
8869                         , X_user
8870                         , X_login
8871                         , X_module
8872                         , temp_status );
8873       CheckStatus( temp_status );
8874 
8875     END LOOP;
8876 
8877     X_status := 0; X_status := 0;
8878     X_num_processed := item_count;
8879 
8880   EXCEPTION
8881     WHEN  OTHERS  THEN
8882       X_status := SQLCODE;
8883       RAISE;
8884   END MarkNoCCProcess ;
8885 
8886   PROCEDURE  ChangeTPAttributes(ItemsIdTab          IN pa_utils.IdTabTyp
8887                           , X_adjust_level          IN VARCHAR2
8888                           , X_user                  IN NUMBER
8889                           , X_login                 IN NUMBER
8890                           , X_module                IN VARCHAR2
8891                           , X_acct_tp_rate_type     IN VARCHAR2
8892                           , X_acct_tp_rate_date     IN DATE
8893                           , X_acct_tp_exchange_rate IN NUMBER
8894     	                  , X_bl_dist_code          IN VARCHAR2
8895                           , X_ic_proc_code          IN VARCHAR2
8896                           , DenomCurrCodeTab        IN pa_utils.Char15TabTyp
8897                           , rows                    IN NUMBER
8898                           , X_num_processed         OUT NOCOPY NUMBER
8899                           , X_num_rejected          OUT NOCOPY NUMBER
8900                           , X_status                OUT NOCOPY NUMBER
8901  			  , p_PROJECT_TP_COST_RATE_DATE   IN   DATE
8902  			  , p_PROJECT_TP_COST_RATE_TYPE   IN   VARCHAR2
8903  			  , p_PROJECT_TP_COST_EXCHG_RATE  IN   NUMBER
8904                           )  IS
8905 
8906      temp_status         NUMBER DEFAULT NULL;
8907      item_count          NUMBER := 0;
8908      failed_count        NUMBER := 0 ;
8909      l_status            VARCHAR2(240)DEFAULT NULL ;
8910      l_acct_exchange_rate NUMBER    := X_acct_tp_exchange_rate;
8911      l_acct_rate_type  VARCHAR2(30) := X_acct_tp_rate_type ;
8912      l_acct_rate_date  DATE         := X_acct_tp_rate_date ;
8913      l_dummy1            NUMBER ;
8914      l_dummy2            NUMBER ;
8915      l_dummy3            NUMBER ;
8916      l_cc_code_old       VARCHAR2(1):= NULL;
8917      l_bl_dist_code      VARCHAR2(1):= NULL;
8918      l_ic_proc_code      VARCHAR2(1):= NULL;
8919 
8920      PROCEDURE  RecalcRelatedItems( X_expenditure_item_id  IN NUMBER
8921                                   , X_user                 IN NUMBER
8922                                   , X_login                IN NUMBER
8923                                   , X_acct_tp_rate_type    IN VARCHAR2
8924                                   , X_acct_tp_rate_date    IN DATE
8925                                   , X_acct_tp_exchange_rateIN NUMBER
8926                                   , X_module               IN VARCHAR2
8927                                   , X_status               OUT NOCOPY NUMBER
8928                           	  , p_PROJECT_TP_COST_RATE_DATE      IN   DATE  default null
8929                           	  , p_PROJECT_TP_COST_RATE_TYPE      IN   VARCHAR2 default null
8930                           	  , p_PROJECT_TP_COST_EXCHG_RATE  IN   NUMBER default null )
8931      IS
8932        CURSOR GetRelatedItems IS
8933          SELECT
8934                  expenditure_item_id
8935            FROM
8936                  pa_expenditure_items_all
8937           WHERE
8938                  source_expenditure_item_id = X_expenditure_item_id;
8939      BEGIN
8940 
8941        FOR eachRec IN GetRelatedItems LOOP
8942 
8943          UPDATE pa_expenditure_items_all
8944 
8945           SET
8946            cc_bl_distributed_code = DECODE(X_adjust_level,'I',X_bl_dist_code,                                              l_bl_dist_code)
8947          , cc_ic_processed_code  =  DECODE(X_adjust_level,'I',X_ic_proc_code,                                              l_ic_proc_code)
8948          , acct_tp_rate_type = X_acct_tp_rate_type
8949          , acct_tp_rate_date = X_acct_tp_rate_date
8950          , acct_tp_exchange_rate = l_acct_exchange_rate
8951         --- , PROJECT_TP_RATE_DATE = p_PROJECT_TP_COST_RATE_DATE
8952         --- , PROJECT_TP_RATE_TYPE = p_PROJECT_TP_COST_RATE_TYPE
8953         --- , PROJECT_TP_EXCHANGE_RATE = p_PROJECT_TP_COST_EXCHG_RATE
8954          , PROJECT_TRANSFER_PRICE = NULL
8955          , PROJFUNC_TRANSFER_PRICE = NULL
8956          , denom_transfer_price = NULL
8957          , acct_transfer_price = NULL
8958          , last_updated_by = X_user
8959          , last_update_date = sysdate
8960          , last_update_login = X_login
8961            WHERE
8962                  expenditure_item_id = eachRec.expenditure_item_id;
8963 
8964          item_count := item_count + 1;
8965 
8966          pa_adjustments.InsAuditRec( eachRec.expenditure_item_id
8967                                    , 'CHANGE TP ATTRIBUTE'
8968                                    , X_module
8969                                    , X_user
8970                                    , X_login
8971                                    , temp_status
8972 				/* R12 Changes Start */
8973 	                           , G_REQUEST_ID
8974           	                   , G_PROGRAM_ID
8975 	                           , G_PROG_APPL_ID
8976 	                           , sysdate );
8977  				/* R12 Changes End */
8978          CheckStatus( temp_status );
8979 
8980        END LOOP;
8981 
8982      X_status := 0;
8983 
8984      EXCEPTION
8985        WHEN  OTHERS  THEN
8986          X_status := SQLCODE;
8987          RAISE;
8988 
8989      END  RecalcRelatedItems;
8990 
8991 
8992   BEGIN
8993     FOR i IN 1..rows LOOP
8994        pa_multi_currency.init ;
8995      IF X_adjust_level = 'S' THEN
8996         l_cc_code_old := CrossChargeCodeTab(i);
8997 
8998      if l_cc_code_old = 'B' then
8999            l_ic_proc_code := 'X';
9000 	   l_bl_dist_code := 'N' ;
9001      elsif l_cc_code_old = 'I' then
9002            l_ic_proc_code := 'N';
9003 	   l_bl_dist_code := 'X' ;
9004      end if;
9005  IF P_DEBUG_MODE  THEN
9006     print_message('get_denom_curr_code: ' || 'X rate is['||to_char(X_acct_tp_exchange_rate)||']l rate ['||to_char(l_acct_exchange_rate)||']' );
9007  END IF;
9008 
9009        pa_multi_currency.convert_amount( DenomTpCurrCodeTab(i)
9010                                  , pa_multi_currency.G_accounting_currency_code
9011                                  , l_acct_rate_date
9012                                  , l_acct_rate_type
9013                                  , null
9014                                  , 'Y'
9015                                  , 'Y'
9016                                  , l_dummy1
9017                                  , l_dummy2
9018                                  , l_dummy3
9019                                  , l_acct_exchange_rate
9020                                  , l_status  ) ;
9021  IF P_DEBUG_MODE  THEN
9022     print_message('get_denom_curr_code: ' || 'X rate after convert amt ['||to_char(l_acct_exchange_rate)||']status ['||l_status||']' );
9023  END IF;
9024  END IF ;
9025 
9026 
9027   IF l_status is not null then
9028               failed_count := failed_count + 1 ;
9029 	/* R12 Changes Start */
9030               InsAuditRec( ItemsIdTab(i)
9031                          , 'CHANGE FUNC ATTRIBUTE'
9032                          , X_module
9033                          , X_user
9034                          , X_login
9035                          , temp_status
9036                          , G_REQUEST_ID
9037                          , G_PROGRAM_ID
9038                          , G_PROG_APPL_ID
9039                          , sysdate
9040                          , l_status);
9041               CheckStatus(temp_status);
9042 	/* R12 Changes End */
9043   ELSE
9044 
9045         UPDATE pa_expenditure_items_all ei
9046          SET
9047          cc_bl_distributed_code = DECODE(X_adjust_level, 'I', X_bl_dist_code,                                            l_bl_dist_code)
9048        , cc_ic_processed_code  =  DECODE(X_adjust_level, 'I',X_ic_proc_code,                                             l_ic_proc_code)
9049        , acct_tp_rate_type = X_acct_tp_rate_type
9050        , acct_tp_rate_date = X_acct_tp_rate_date
9051        , acct_tp_exchange_rate = l_acct_exchange_rate
9052        , denom_transfer_price = NULL
9053        , acct_transfer_price = NULL
9054        , last_updated_by = X_user
9055        , last_update_date = sysdate
9056        , last_update_login = X_login
9057        ---, PROJECT_TP_RATE_DATE = p_PROJECT_TP_COST_RATE_DATE
9058        ---, PROJECT_TP_RATE_TYPE = p_PROJECT_TP_COST_RATE_TYPE
9059        ---, PROJECT_TP_EXCHANGE_RATE = p_PROJECT_TP_COST_EXCHG_RATE
9060        , PROJECT_TRANSFER_PRICE = NULL
9061        , PROJFUNC_TRANSFER_PRICE = NULL
9062 
9063         WHERE
9064          ei.expenditure_item_id = ItemsIdTab(i);
9065 
9066       item_count := item_count + 1;
9067 
9068       InsAuditRec( ItemsIdTab(i)
9069                  , 'CHANGE TP ATTRIBUTE'
9070                  , X_module
9071                  , X_user
9072                  , X_login
9073                  , temp_status
9074 	/* R12 Changes Start */
9075 	         , G_REQUEST_ID
9076           	 , G_PROGRAM_ID
9077 	         , G_PROG_APPL_ID
9078 	         , sysdate );
9079  	/* R12 Changes End */
9080       CheckStatus( temp_status );
9081 
9082     RecalcRelatedItems( ItemsIdTab(i)
9083                         , X_user
9084                         , X_login
9085                         , X_acct_tp_rate_type
9086                         , X_acct_tp_rate_date
9087                         , l_acct_exchange_rate
9088                         , X_module
9089                         , temp_status );
9090       CheckStatus( temp_status );
9091 
9092     END IF ;
9093     END LOOP;
9094 
9095     X_status := 0;
9096     X_num_processed := item_count;
9097     X_num_rejected  := failed_count ;
9098 
9099   EXCEPTION
9100     WHEN  OTHERS  THEN
9101       X_status := SQLCODE;
9102       RAISE;
9103 
9104   END  ChangeTPAttributes;
9105 
9106 
9107 PROCEDURE Allow_Adjustment(
9108                              p_transaction_source                   IN VARCHAR2,
9109                              p_orig_transaction_reference           IN VARCHAR2,
9110                              p_expenditure_type_class               IN VARCHAR2,
9111                              p_expenditure_type                     IN VARCHAR2,
9112                              p_expenditure_item_id                  IN NUMBER,
9113                              p_expenditure_item_date                IN DATE,
9114                              p_employee_number                      IN VARCHAR2,
9115                              p_expenditure_org_name                 IN VARCHAR2,
9116                              p_project_number                       IN VARCHAR2,
9117                              p_task_number                          IN VARCHAR2,
9118                              p_non_labor_resource                   IN VARCHAR2,
9119                              p_non_labor_resource_org_name          IN VARCHAR2,
9120                              p_quantity                             IN NUMBER,
9121                              p_raw_cost                             IN NUMBER,
9122                              p_attribute_category                   IN VARCHAR2,
9123                              p_attribute1                           IN VARCHAR2,
9124                              p_attribute2                           IN VARCHAR2,
9125                              p_attribute3                           IN VARCHAR2,
9126                              p_attribute4                           IN VARCHAR2,
9127                              p_attribute5                           IN VARCHAR2,
9128                              p_attribute6                           IN VARCHAR2,
9129                              p_attribute7                           IN VARCHAR2,
9130                              p_attribute8                           IN VARCHAR2,
9131                              p_attribute9                           IN VARCHAR2,
9132                              p_attribute10                          IN VARCHAR2,
9133                              p_org_id                               IN NUMBER,
9134                              x_allow_adjustment_code                OUT NOCOPY VARCHAR2,
9135                              x_return_status                        OUT NOCOPY VARCHAR2,
9136                              x_application_code                     OUT NOCOPY VARCHAR2,
9137                              x_message_code                         OUT NOCOPY VARCHAR2,
9138                              x_token_name1                          OUT NOCOPY VARCHAR2,
9139                              x_token_val1                           OUT NOCOPY VARCHAR2,
9140                              x_token_name2                          OUT NOCOPY VARCHAR2,
9141                              x_token_val2                           OUT NOCOPY VARCHAR2,
9142                              x_token_name3                          OUT NOCOPY VARCHAR2,
9143                              x_token_val3                           OUT NOCOPY VARCHAR2)
9144 
9145 IS
9146 
9147 TYPE net_zero_ei_date_rec_type IS RECORD (
9148      net_zero_adjustment_flag_1     pa_expenditure_items_all.net_zero_adjustment_flag%TYPE DEFAULT NULL,
9149      expenditure_item_date_1        pa_expenditure_items_all.expenditure_item_date%TYPE DEFAULT NULL,
9150      net_zero_adjustment_flag_2     pa_expenditure_items_all.net_zero_adjustment_flag%TYPE DEFAULT NULL,
9151      expenditure_item_date_2        pa_expenditure_items_all.expenditure_item_date%TYPE DEFAULT NULL,
9152      net_zero_adjustment_flag_3     pa_expenditure_items_all.net_zero_adjustment_flag%TYPE DEFAULT NULL,
9153      expenditure_item_date_3        pa_expenditure_items_all.expenditure_item_date%TYPE DEFAULT NULL,
9154      net_zero_adjustment_flag_4     pa_expenditure_items_all.net_zero_adjustment_flag%TYPE DEFAULT NULL,
9155      expenditure_item_date_4        pa_expenditure_items_all.expenditure_item_date%TYPE DEFAULT NULL,
9156      net_zero_adjustment_flag_5     pa_expenditure_items_all.net_zero_adjustment_flag%TYPE DEFAULT NULL,
9157      expenditure_item_date_5        pa_expenditure_items_all.expenditure_item_date%TYPE DEFAULT NULL,
9158      net_zero_adjustment_flag_6     pa_expenditure_items_all.net_zero_adjustment_flag%TYPE DEFAULT NULL,
9159      expenditure_item_date_6        pa_expenditure_items_all.expenditure_item_date%TYPE DEFAULT NULL,
9160      net_zero_adjustment_flag_7     pa_expenditure_items_all.net_zero_adjustment_flag%TYPE DEFAULT NULL,
9161      expenditure_item_date_7        pa_expenditure_items_all.expenditure_item_date%TYPE DEFAULT NULL);
9162 
9163 l_net_zero_ei_date         net_zero_ei_date_rec_type;
9164 l_allow_adjustment_flag    VARCHAR2(1);
9165 l_predefined_flag          VARCHAR2(1);
9166 
9167 CURSOR allow_adjustment IS
9168 SELECT allow_adjustments_flag, predefined_flag
9169 FROM   pa_transaction_sources
9170 WHERE  transaction_source = p_transaction_source;
9171 
9172 CURSOR sst_adjustment IS
9173 SELECT net_zero_adjustment_flag_1,
9174        expenditure_item_date_1,
9175        net_zero_adjustment_flag_2,
9176        expenditure_item_date_2,
9177        net_zero_adjustment_flag_3,
9178        expenditure_item_date_3,
9179        net_zero_adjustment_flag_4,
9180        expenditure_item_date_4,
9181        net_zero_adjustment_flag_5,
9182        expenditure_item_date_5,
9183        net_zero_adjustment_flag_6,
9184        expenditure_item_date_6,
9185        net_zero_adjustment_flag_7,
9186        expenditure_item_date_7
9187 FROM   PA_EI_DENORM
9188 WHERE  denorm_id = p_orig_transaction_reference;
9189 
9190 l_test NUMBER;
9191 
9192 BEGIN
9193 
9194 --If the transaction source is NULL then the item was not imported to Projects
9195 --from an external system so RETURN.
9196 
9197 
9198 IF (p_transaction_source IS NULL) THEN
9199 
9200      x_return_status := 'S';
9201 
9202      RETURN;
9203 
9204 END IF; --p_transaction_source is null
9205 
9206 --If p_transaction_source is Oracle Self Service Time then check if the item has
9207 --already been adjusted in Self Service Time.
9208 
9209 IF (p_transaction_source = 'Oracle Self Service Time') THEN
9210 
9211      OPEN sst_adjustment;
9212 
9213      FETCH sst_adjustment INTO l_net_zero_ei_date;
9214 
9215      --If no records are in the cursor then the item was not found in SST.
9216      --This indicates data corruption.  No adjustment will be allowed.
9217 
9218      IF (sst_adjustment%ROWCOUNT = 0) THEN
9219 
9220           x_allow_adjustment_code := 'N';
9221 
9222           x_return_status := 'E';
9223 
9224           x_application_code := 'PA';
9225 
9226           x_message_code := 'PA_SST_ITEM_NOT_FOUND';
9227 
9228      ELSIF (l_net_zero_ei_date.expenditure_item_date_1 = p_expenditure_item_date) AND
9229         (l_net_zero_ei_date.net_zero_adjustment_flag_1 = 'Y') THEN
9230 
9231           x_allow_adjustment_code := 'N';
9232           x_return_status := 'S';
9233 
9234      ELSIF (l_net_zero_ei_date.expenditure_item_date_2 = p_expenditure_item_date) AND
9235            (l_net_zero_ei_date.net_zero_adjustment_flag_2 = 'Y') THEN
9236 
9237           x_allow_adjustment_code := 'N';
9238           x_return_status := 'S';
9239 
9240      ELSIF (l_net_zero_ei_date.expenditure_item_date_3 = p_expenditure_item_date) AND
9241            (l_net_zero_ei_date.net_zero_adjustment_flag_3 = 'Y') THEN
9242 
9243           x_allow_adjustment_code := 'N';
9244           x_return_status := 'S';
9245 
9246      ELSIF (l_net_zero_ei_date.expenditure_item_date_4 = p_expenditure_item_date) AND
9247            (l_net_zero_ei_date.net_zero_adjustment_flag_4 = 'Y') THEN
9248 
9249           x_allow_adjustment_code := 'N';
9250           x_return_status := 'S';
9251 
9252      ELSIF (l_net_zero_ei_date.expenditure_item_date_5 = p_expenditure_item_date) AND
9253            (l_net_zero_ei_date.net_zero_adjustment_flag_5 = 'Y') THEN
9254 
9255           x_allow_adjustment_code := 'N';
9256           x_return_status := 'S';
9257 
9258      ELSIF (l_net_zero_ei_date.expenditure_item_date_6 = p_expenditure_item_date) AND
9259            (l_net_zero_ei_date.net_zero_adjustment_flag_6 = 'Y') THEN
9260 
9261           x_allow_adjustment_code := 'N';
9262           x_return_status := 'S';
9263 
9264      ELSIF (l_net_zero_ei_date.expenditure_item_date_7 = p_expenditure_item_date) AND
9265            (l_net_zero_ei_date.net_zero_adjustment_flag_7 = 'Y') THEN
9266 
9267           x_allow_adjustment_code := 'N';
9268           x_return_status := 'S';
9269 
9270      --If the net_zero_adjustmentment_flag <> 'Y' then an adjustment should be allowed.
9271 
9272      ELSE x_allow_adjustment_code := 'Y';
9273           x_return_status := 'S';
9274 
9275      END IF;
9276 
9277      CLOSE sst_adjustment;
9278 
9279 --If the transaction source is NOT NULL and is NOT SST then
9280 --open the allow_adjustment cursor.
9281 
9282 ELSE OPEN allow_adjustment;
9283 
9284      FETCH allow_adjustment INTO l_allow_adjustment_flag, l_predefined_flag;
9285 
9286      CLOSE allow_adjustment;
9287 
9288      --If the transaction source is seeded then set x_allow_adjustment_code
9289      --to the allow_adjustment_flag for that transaction source.
9290 
9291      IF (l_predefined_flag = 'Y') THEN
9292 
9293           x_allow_adjustment_code := l_allow_adjustment_flag;
9294           x_return_status := 'S';
9295 
9296      --If the transaction source is not seeded then call
9297      --the Allow Adjustment client extension.  By default, the
9298      --allow_adjustment_extn will return the allow_adjustment_flag
9299      --for the given transaction source.
9300 
9301      ELSE PA_TRANSACTIONS_PUB.Allow_Adjustment_Extn(
9302                              p_transaction_source => p_transaction_source,
9303                              p_allow_adjustment_flag => l_allow_adjustment_flag,
9304                              p_orig_transaction_reference => p_orig_transaction_reference,
9305                              p_expenditure_type_class => p_expenditure_type_class,
9306                              p_expenditure_type => p_expenditure_type,
9307                              p_expenditure_item_id => p_expenditure_item_id,
9308                              p_expenditure_item_date => p_expenditure_item_date,
9309                              p_employee_number => p_employee_number,
9310                              p_expenditure_org_name => p_expenditure_org_name,
9311                              p_project_number => p_project_number,
9312                              p_task_number => p_task_number,
9313                              p_non_labor_resource => p_non_labor_resource,
9314                              p_non_labor_resource_org_name => p_non_labor_resource_org_name,
9315                              p_quantity => p_quantity,
9316                              p_raw_cost => p_raw_cost,
9317                              p_attribute_category => p_attribute_category,
9318                              p_attribute1 => p_attribute1,
9319                              p_attribute2 => p_attribute2,
9320                              p_attribute3 => p_attribute3,
9321                              p_attribute4 => p_attribute4,
9322                              p_attribute5 => p_attribute5,
9323                              p_attribute6 => p_attribute6,
9324                              p_attribute7 => p_attribute7,
9325                              p_attribute8 => p_attribute8,
9326                              p_attribute9 => p_attribute9,
9327                              p_attribute10 => p_attribute10,
9328                              p_org_id => p_org_id,
9329                              x_allow_adjustment_code => x_allow_adjustment_code,
9330                              x_return_status => x_return_status,
9331                              x_application_code => x_application_code,
9332                              x_message_code => x_message_code,
9333                              x_token_name1 => x_token_name1,
9334                              x_token_val1 => x_token_val1,
9335                              x_token_name2 => x_token_name2,
9336                              x_token_val2 => x_token_val2,
9337                              x_token_name3 => x_token_name3,
9338                              x_token_val3 => x_token_val3);
9339 
9340      End IF; --l_predefined_flag = 'Y'
9341 
9342 END IF; --p_transaction_source = 'Oracle Self Service Time'
9343 
9344 EXCEPTION
9345 
9346      WHEN others THEN
9347 
9348           x_return_status := 'U';
9349 
9350           x_message_code := to_char(SQLCODE);
9351 
9352 END Allow_Adjustment;
9353 
9354 /* This public function get_denom_curr_code() is added for bug#2291180 */
9355 FUNCTION get_denom_curr_code
9356 	(p_transaction_source        IN VARCHAR2
9357          , p_exp_type                IN VARCHAR2
9358          , p_denom_currency_code     IN VARCHAR2
9359          , p_acct_currency_code      IN VARCHAR2
9360          , p_system_linkage_function IN VARCHAR2
9361          , p_calling_mode            IN VARCHAR2 default 'ADJUST' /*Bugfix:2798742 */
9362          , p_person_id               IN NUMBER   default NULL    /*Bugfix:2798742 */
9363 	 , p_ei_date                 IN DATE     default NULL   /*Bugfix:2798742 */
9364                              ) RETURN VARCHAR2 IS
9365 
9366    l_return_currency_code     pa_expenditure_items_all.denom_currency_code%type;
9367    l_gl_accounted_flag        pa_transaction_sources.gl_accounted_flag%type;
9368    l_costed_flag              pa_transaction_sources.costed_flag%type;  /* added bug 3142879 */
9369    l_cost_rate_flag           pa_expenditure_types.cost_rate_flag%type;
9370    l_job_id                   pa_expenditure_items_all.job_id%TYPE;
9371    l_organization_id          pa_expenditures_all.incurred_by_organization_id%TYPE;
9372    l_cost_rate                pa_bill_rates_all.rate%TYPE;
9373    l_start_date               Date;
9374    l_end_date                 Date;
9375    l_org_labor_sch_rule_id    pa_org_labor_sch_rule.org_labor_sch_rule_id%TYPE;
9376    l_costing_rule             pa_compensation_rule_sets.compensation_rule_set%TYPE;
9377    l_rate_sch_id              pa_std_bill_rate_schedules_all.bill_rate_sch_id%TYPE;
9378    l_acct_rate_type           pa_expenditure_items_all.acct_rate_type%TYPE;
9379    l_acct_rate_date_code      pa_implementations_all.acct_rate_date_code%TYPE;
9380    l_acct_exch_rate           pa_org_labor_sch_rule.acct_exchange_rate%TYPE;
9381    l_ot_project_id            pa_projects_all.project_id%TYPE;
9382    l_ot_task_id               pa_tasks.task_id%TYPE;
9383    l_err_stage                number;
9384    l_err_code                 varchar2(1000);
9385    OTHERS_EXCEPTION           EXCEPTION;
9386 
9387 BEGIN
9388 
9389      /* If Transaction Source is Null, set the flag to 'N' */
9390       IF p_transaction_source IS NULL THEN
9391           l_gl_accounted_flag := 'N';
9392           l_costed_flag       := 'N';/* added bug 3142879 */
9393       ELSE
9394             SELECT  gl_accounted_flag, costed_flag
9395               INTO  l_gl_accounted_flag, l_costed_flag  /* added costed flag bug 3142879 */
9396               FROM  pa_transaction_sources
9397              WHERE  transaction_source = p_transaction_source;
9398        END IF;
9399 
9400       /* Get the cost_rate_flag */
9401        BEGIN
9402             SELECT  cost_rate_flag
9403               INTO  l_cost_rate_flag
9404               FROM  pa_expenditure_types
9405              WHERE  expenditure_type = p_exp_type;
9406 
9407         EXCEPTION
9408         WHEN NO_DATA_FOUND THEN
9409                  l_cost_rate_flag := 'N';
9410 
9411         END;  /* cost_rate_flag */
9412 
9413    /*
9414       Do not do any processing if the EI is externally accounted
9415       or
9416       EI(s) are from the Expense Reports entered in PA.
9417       For ST/OT/Usages, if acct_currency_code <> denom_currency_code,
9418       then return functional currency code from the SOB.
9419       Else if cost_rate_flag is Y and acct_currency_code <> denom_currency_code
9420       then return functional currency code from the SOB.
9421    */
9422 
9423    IF (l_gl_accounted_flag = 'Y') OR (l_costed_flag = 'Y') OR /* added costed flag bug 3142879 */
9424       (p_transaction_source IS NULL and p_system_linkage_function = 'ER') THEN
9425 
9426         l_return_currency_code := p_denom_currency_code;
9427 
9428    ELSIF p_system_linkage_function in ('ST','OT') THEN
9429        /** Start of Bug fix:2798742 */
9430          IF p_acct_currency_code = p_denom_currency_code THEN
9431                   l_return_currency_code := p_denom_currency_code;
9432          ELSE
9433             /* bug fix:2822620 get_labor_rate API should be called only for Split, as these EIs are not
9434              * cost distributed again, where as for Transfer case, New currency code will be
9435              * derived during cost distribution process
9436              */
9437             IF p_calling_mode = 'SPLIT' Then
9438 
9439 		  l_return_currency_code := null;
9440                   --Derive denorm_currency_code based on rate
9441 		     PA_COST_RATE_PUB.get_labor_rate
9442 			( p_person_id              => p_person_id
9443                           ,p_txn_date              => p_ei_date
9444                           ,p_calling_module        => 'STAFFED'
9445                           ,x_job_id                => l_job_id
9446                           ,x_organization_id       => l_organization_id
9447                           ,x_cost_rate             => l_cost_rate
9448                           ,x_start_date_active     => l_start_date
9449                           ,x_end_date_active       => l_end_date
9450                           ,x_org_labor_sch_rule_id => l_org_labor_sch_rule_id
9451                           ,x_costing_rule          => l_costing_rule
9452                           ,x_rate_sch_id           => l_rate_sch_id
9453                           ,x_cost_rate_curr_code   => l_return_currency_code
9454                           ,x_acct_rate_type        => l_acct_rate_type
9455                           ,x_acct_rate_date_code   => l_acct_rate_date_code
9456                           ,x_acct_exch_rate        => l_acct_exch_rate
9457                           ,x_ot_project_id         => l_ot_project_id
9458                           ,x_ot_task_id            => l_ot_task_id
9459                           ,x_err_stage             => l_err_stage
9460                           ,x_err_code              => l_err_code
9461                          );
9462 	       print_message('l_return_currency_code['||l_return_currency_code||']l_err_stage['||l_err_stage||
9463 		     ']l_err_code['||l_err_code||']');
9464 
9465                 /* bug fix 2822620 --If l_return_currency_code IS NOT NULL Then **/
9466                 If l_return_currency_code IS NULL Then
9467 
9468                         Raise OTHERS_EXCEPTION;
9469 
9470                 End If;
9471 
9472              ELse  -- calling_mode = 'ADJUST'
9473                  print_message('Calling mode ADJUST so return account currency code');
9474                         l_return_currency_code := pa_currency.get_currency_code;
9475              End If;
9476 
9477 
9478          END IF;
9479        /** End of Bug fix:2798742 */
9480    ELSIF l_cost_rate_flag = 'Y' THEN
9481 
9482          IF p_acct_currency_code = p_denom_currency_code THEN
9483                   l_return_currency_code := p_denom_currency_code;
9484          ELSE
9485                   l_return_currency_code := pa_currency.get_currency_code;
9486          END IF;
9487 
9488    ELSE
9489          l_return_currency_code := p_denom_currency_code;
9490 
9491    END IF;
9492 
9493    RETURN l_return_currency_code;
9494 
9495 EXCEPTION
9496 WHEN OTHERS_EXCEPTION THEN
9497         print_message('inside OTHERS_EXCEPTION l_return_currency_code['||l_return_currency_code||']');
9498         If l_return_currency_code IS NULL Then
9499                 RAISE;
9500         ELSE
9501                 return l_return_currency_code;
9502         END IF;
9503 
9504 WHEN OTHERS THEN
9505         If l_return_currency_code IS NULL Then
9506                 RAISE;
9507         ELSE
9508                 return l_return_currency_code;
9509         END IF;
9510         RAISE;
9511 
9512 END get_denom_curr_code;
9513 
9514 /* R12 Changes Start */
9515   PROCEDURE Get_Old_and_New_CCID(
9516     p_expenditure_item_id         IN         NUMBER
9517    ,p_project_id                  IN         NUMBER
9518    ,p_task_id                     IN         NUMBER
9519    ,p_expenditure_type            IN         VARCHAR2
9520    ,p_vendor_id                   IN         NUMBER
9521    ,p_expenditure_organization_id IN         NUMBER
9522    ,p_expenditure_item_date       IN         DATE
9523    ,p_billable_flag               IN         VARCHAR2
9524    ,p_org_id                      IN         NUMBER
9525    ,p_emp_id                      IN         NUMBER
9526    ,p_award_id                    IN         NUMBER
9527    ,p_system_linkage_function     IN         VARCHAR2
9528    ,p_transaction_source          IN         VARCHAR2
9529    ,p_invoice_distribution_id     IN         NUMBER
9530    ,x_old_ccid                    OUT NOCOPY VARCHAR2
9531    ,x_new_ccid                    OUT NOCOPY VARCHAR2
9532    ,x_encoded_error_message       OUT NOCOPY VARCHAR2) IS /* Bug 4997739 */
9533 
9534     l_pa_gl_app_id                NUMBER := 8721;
9535     l_concat_segs                 VARCHAR2(240);
9536     l_concat_ids		  VARCHAR2(240);
9537     l_concat_descrs		  VARCHAR2(240);
9538     l_vendor_id                   NUMBER;
9539     l_gl_date                     DATE;
9540     l_sob_id                      NUMBER;
9541     l_coa_id                      NUMBER;
9542     l_emp_ccid                    NUMBER;
9543     l_expense_type                NUMBER;
9544     l_encoded_error_message       VARCHAR2(2000);
9545 
9546 /* this cursor derives the set of books and the chart of account
9547    associated with Organization in which the transaction was entered */
9548     CURSOR C_SOB_COA_CUR IS
9549     SELECT IMP.SET_OF_BOOKS_ID
9550          , GL.CHART_OF_ACCOUNTS_ID
9551       FROM GL_LEDGERS_PUBLIC_V GL
9552          , PA_IMPLEMENTATIONS IMP
9553      WHERE GL.LEDGER_ID = IMP.SET_OF_BOOKS_ID;
9554 
9555 /* this cursor gets the vendor id of the employee for which the ER was entered */
9556     CURSOR C_VENDOR_ID_CUR(p_emp_id NUMBER) IS
9557     SELECT VENDOR_ID
9558       FROM PO_VENDORS_AP_V
9559      WHERE ACTIVE_FLAG = 'Y'
9560        AND ENABLED_FLAG = 'Y'
9561        AND EMPLOYEE_ID = p_emp_id;
9562 
9563 /* this cursor gets the CCID of the employee for ehich the ER was entered */
9564     CURSOR C_EMP_CCID_CUR(p_emp_id NUMBER, p_sob_id NUMBER) IS
9565     SELECT DEFAULT_CODE_COMB_ID
9566       FROM PER_ASSIGNMENTS_F
9567      WHERE PERSON_ID = p_emp_id
9568        AND SET_OF_BOOKS_ID = p_sob_id
9569        AND TRUNC(SYSDATE) BETWEEN TRUNC(EFFECTIVE_START_DATE)
9570        AND NVL(TRUNC(EFFECTIVE_END_DATE), TRUNC(SYSDATE));
9571 
9572 /* this cursor get the expense type */
9573     CURSOR C_EXPENSE_TYPE_CUR(p_invoice_distribution_id NUMBER) IS
9574     SELECT WEB_PARAMETER_ID
9575       FROM AP_INVOICE_DISTRIBUTIONS
9576      WHERE INVOICE_DISTRIBUTION_ID = p_invoice_distribution_id;
9577 
9578 /* this cursor gets the old ccid and gl date */
9579     CURSOR C_OLD_CCID_AND_GL_DATE_CUR(p_expenditure_item_id NUMBER) IS
9580     SELECT DR_CODE_COMBINATION_ID, GL_DATE
9581       FROM PA_COST_DISTRIBUTION_LINES
9582      WHERE EXPENDITURE_ITEM_ID = ( SELECT EXPENDITURE_ITEM_ID
9583                                      FROM PA_EXPENDITURE_ITEMS
9584                                     WHERE TRANSFERRED_FROM_EXP_ITEM_ID IS NULL
9585                                START WITH EXPENDITURE_ITEM_ID = p_expenditure_item_id
9586                          CONNECT BY PRIOR TRANSFERRED_FROM_EXP_ITEM_ID = EXPENDITURE_ITEM_ID)
9587        AND TRANSFER_STATUS_CODE = 'V';
9588 
9589   workflow_exception EXCEPTION;
9590   PRAGMA EXCEPTION_INIT(workflow_exception,-20001);
9591 
9592   BEGIN
9593 
9594 /* Check if the organization is cached. If yes then it implies that
9595    the Chart of Accounts is also cached */
9596     IF p_org_id <> NVL(G_ORG_ID,-99) THEN
9597 
9598 /* If not, get new chart of accounts id */
9599       OPEN C_SOB_COA_CUR;
9600       FETCH C_SOB_COA_CUR INTO l_sob_id, l_coa_id;
9601       CLOSE C_SOB_COA_CUR;
9602 
9603     END IF;
9604 
9605     IF p_system_linkage_function = 'ER' THEN
9606 
9607 /* For ERs, check if employee id is cached. If yes, then it implies that
9608    vendor information is also cached */
9609       IF  p_vendor_id IS NULL
9610       AND p_emp_id <> NVL(G_EMP_ID,-99) THEN
9611 
9612 /* If not, get employee id */
9613         OPEN C_VENDOR_ID_CUR(p_emp_id);
9614         FETCH C_VENDOR_ID_CUR INTO l_vendor_id;
9615         CLOSE C_VENDOR_ID_CUR;
9616 
9617       END IF;
9618 
9619 /* For ERs, check if employee id and set of books id is cached. If yes,
9620    then it implies that the employee ccid is also cached */
9621       IF  p_emp_id <> NVL(G_EMP_ID,-99)
9622       OR  l_sob_id <> NVL(G_SET_OF_BOOKS_ID,-99) THEN
9623 
9624 /* If not, get new employee ccid */
9625         OPEN C_EMP_CCID_CUR(p_emp_id, l_sob_id);
9626         FETCH C_EMP_CCID_CUR INTO l_emp_ccid;
9627         CLOSE C_EMP_CCID_CUR;
9628 
9629       END IF;
9630 
9631 /* For ERs from Payables, check if invoice distribution id is cached. If yes, it implies
9632    thet the expense type is also cached */
9633       IF  p_transaction_source = 'AP EXPENSE'
9634       AND p_invoice_distribution_id <> NVL(G_INVOICE_DISTRIBUTION_ID,-99) THEN
9635 
9636 /* If not, get expense type */
9637         OPEN C_EXPENSE_TYPE_CUR(p_invoice_distribution_id);
9638         FETCH C_EXPENSE_TYPE_CUR into l_expense_type;
9639         CLOSE C_EXPENSE_TYPE_CUR;
9640 
9641       END IF;
9642 
9643     END IF;
9644 
9645 /* Update cache */
9646     G_ORG_ID := NVL(p_org_id, G_ORG_ID);
9647     G_SET_OF_BOOKS_ID := NVL(l_sob_id,G_SET_OF_BOOKS_ID);
9648     G_COA_ID := NVL(l_coa_id, G_COA_ID);
9649     G_VENDOR_ID := NVL(p_vendor_id,NVL(l_vendor_id,G_VENDOR_ID));
9650     G_EMP_ID := NVL(p_emp_id, G_EMP_ID); /* 4991601 */
9651     G_EMP_CCID := NVL(l_emp_ccid, G_EMP_CCID);
9652     G_INVOICE_DISTRIBUTION_ID := NVL(p_invoice_distribution_id,G_INVOICE_DISTRIBUTION_ID);
9653     G_EXPENSE_TYPE := NVL(l_expense_type, G_EXPENSE_TYPE);
9654 
9655     OPEN C_OLD_CCID_AND_GL_DATE_CUR(p_expenditure_item_id);
9656     FETCH C_OLD_CCID_AND_GL_DATE_CUR INTO x_old_ccid, l_gl_date;
9657     CLOSE C_OLD_CCID_AND_GL_DATE_CUR;
9658 
9659     IF p_system_linkage_function = 'VI' THEN
9660 
9661 /* For Supplier Costs, we have to pass the accounting data
9662    as a parameter. We derive the latest open GL period */
9663 
9664       l_gl_date := NVL(pa_utils2.get_prvdr_gl_date(p_reference_date => l_gl_date
9665                                                   ,p_application_id => l_pa_gl_app_id
9666                                                   ,p_set_of_books_id => G_SET_OF_BOOKS_ID),l_gl_date);
9667 
9668 /* Call Supplier Invoice Account Generator Workflow */
9669       IF NOT pa_acc_gen_wf_pkg.ap_inv_generate_account
9670           (p_expenditure_item_id => p_expenditure_item_id
9671           ,p_project_id => p_project_id
9672           ,p_task_id => p_task_id
9673           ,p_expenditure_type => p_expenditure_type
9674           ,p_vendor_id => G_VENDOR_ID
9675           ,p_expenditure_organization_id => p_expenditure_organization_id
9676           ,p_expenditure_item_date => p_expenditure_item_date
9677           ,p_billable_flag => p_billable_flag
9678           ,p_chart_of_accounts_id => G_COA_ID
9679           ,p_attribute_category => NULL
9680           ,p_attribute1 => NULL
9681           ,p_attribute2 => NULL
9682           ,p_attribute3 => NULL
9683           ,p_attribute4 => NULL
9684           ,p_attribute5 => NULL
9685           ,p_attribute6 => NULL
9686           ,p_attribute7 => NULL
9687           ,p_attribute8 => NULL
9688           ,p_attribute9 => NULL
9689           ,p_attribute10 => NULL
9690           ,p_attribute11 => NULL
9691           ,p_attribute12 => NULL
9692           ,p_attribute13 => NULL
9693           ,p_attribute14 => NULL
9694           ,p_attribute15 => NULL
9695           ,p_dist_attribute_category => NULL
9696           ,p_dist_attribute1 => NULL
9697           ,p_dist_attribute2 => NULL
9698           ,p_dist_attribute3 => NULL
9699           ,p_dist_attribute4 => NULL
9700           ,p_dist_attribute5 => NULL
9701           ,p_dist_attribute6 => NULL
9702           ,p_dist_attribute7 => NULL
9703           ,p_dist_attribute8 => NULL
9704           ,p_dist_attribute9 => NULL
9705           ,p_dist_attribute10 => NULL
9706           ,p_dist_attribute11 => NULL
9707           ,p_dist_attribute12 => NULL
9708           ,p_dist_attribute13 => NULL
9709           ,p_dist_attribute14 => NULL
9710           ,p_dist_attribute15 => NULL
9711           ,x_return_ccid => x_new_ccid /* Bug 4610677 */
9712           ,x_concat_segs => l_concat_segs
9713           ,x_concat_ids => l_concat_ids
9714           ,x_concat_descrs => l_concat_descrs
9715           ,x_error_message  => l_encoded_error_message /* Bug 4997739 */
9716           ,p_award_id => p_award_id
9717           ,p_accounting_date => l_gl_date) THEN
9718 
9719 /* Raise an exception if the workflow returns with an error */
9720 /* 4627975 - Set the encoded message on the message stack before raising exception */
9721         x_encoded_error_message := l_encoded_error_message; /* Bug 4997739 */
9722 
9723       END IF;
9724     ELSE
9725 
9726 /* Call Expense Report Account Generator Workflow */
9727       IF NOT pa_acc_gen_wf_pkg.ap_er_generate_account
9728           (p_expenditure_item_id => p_expenditure_item_id
9729           ,p_project_id => p_project_id
9730           ,p_task_id => p_task_id
9731           ,p_expenditure_type => p_expenditure_type
9732           ,p_vendor_id => G_VENDOR_ID
9733           ,p_expenditure_organization_id => p_expenditure_organization_id
9734           ,p_expenditure_item_date => p_expenditure_item_date
9735           ,p_billable_flag => p_billable_flag
9736           ,p_chart_of_accounts_id => G_COA_ID
9737           ,p_calling_module => 'APXINWKB'
9738           ,p_employee_id => G_EMP_ID
9739           ,p_employee_ccid => G_EMP_CCID
9740           ,p_expense_type => G_EXPENSE_TYPE
9741           ,p_expense_cc => NULL
9742           ,p_attribute_category => NULL
9743           ,p_attribute1 => NULL
9744           ,p_attribute2 => NULL
9745           ,p_attribute3 => NULL
9746           ,p_attribute4 => NULL
9747           ,p_attribute5 => NULL
9748           ,p_attribute6 => NULL
9749           ,p_attribute7 => NULL
9750           ,p_attribute8 => NULL
9751           ,p_attribute9 => NULL
9752           ,p_attribute10 => NULL
9753           ,p_attribute11 => NULL
9754           ,p_attribute12 => NULL
9755           ,p_attribute13 => NULL
9756           ,p_attribute14 => NULL
9757           ,p_attribute15 => NULL
9758           ,p_line_attribute_category => NULL
9759           ,p_line_attribute1 => NULL
9760           ,p_line_attribute2 => NULL
9761           ,p_line_attribute3 => NULL
9762           ,p_line_attribute4 => NULL
9763           ,p_line_attribute5 => NULL
9764           ,p_line_attribute6 => NULL
9765           ,p_line_attribute7 => NULL
9766           ,p_line_attribute8 => NULL
9767           ,p_line_attribute9 => NULL
9768           ,p_line_attribute10 => NULL
9769           ,p_line_attribute11 => NULL
9770           ,p_line_attribute12 => NULL
9771           ,p_line_attribute13 => NULL
9772           ,p_line_attribute14 => NULL
9773           ,p_line_attribute15 => NULL
9774           ,x_return_ccid => x_new_ccid /* Bug 4610677 */
9775           ,x_concat_segs => l_concat_segs
9776           ,x_concat_ids => l_concat_ids
9777           ,x_concat_descrs => l_concat_descrs
9778           ,x_error_message  => l_encoded_error_message /* Bug 4997739 */
9779           ,p_award_id => p_award_id) THEN
9780 
9781 /* Raise an exception if the workflow returns with an error */
9782 /* 4627975 - Set the encoded message on the message stack before raising exception */
9783         x_encoded_error_message := l_encoded_error_message; /* Bug 4997739 */
9784 
9785       END IF;
9786 
9787     END IF;
9788 
9789   END Get_Old_and_New_CCID;
9790 
9791   FUNCTION get_auto_offsets_segments
9792         (p_auto_offset_option AP_SYSTEM_PARAMETERS.liability_post_lookup_code%TYPE
9793         ,P_base_ccid  NUMBER
9794         ,p_coa_id NUMBER) return varchar2 is
9795 
9796     l_base_segments                FND_FLEX_EXT.SEGMENTARRAY ;
9797     l_overlay_segments             FND_FLEX_EXT.SEGMENTARRAY ;
9798     l_segments                     FND_FLEX_EXT.SEGMENTARRAY ;
9799     l_num_of_segments              NUMBER ;
9800     l_result                       BOOLEAN ;
9801     l_flex_qualifier_name          VARCHAR2(100);
9802     l_flex_segment_num             NUMBER;
9803     l_return_segments              varchar2(200) := null;
9804 
9805 
9806   BEGIN
9807 
9808 /* Get flexfield qualifier segment number */
9809 
9810     IF (p_auto_offset_option = 'ACCOUNT_SEGMENT_VALUE') THEN
9811 
9812       l_flex_qualifier_name := 'GL_ACCOUNT' ;
9813 
9814     ELSIF (p_auto_offset_option = 'BALANCING_SEGMENT') THEN
9815 
9816       l_flex_qualifier_name := 'GL_BALANCING' ;
9817 
9818     ELSIF (p_auto_offset_option = 'NONE') THEN
9819 
9820       RETURN NULL;
9821 
9822     END IF;
9823 
9824     l_result := FND_FLEX_APIS.GET_QUALIFIER_SEGNUM(101
9825                                                   ,'GL#'
9826                                                   ,p_coa_id
9827                                                   ,l_flex_qualifier_name
9828                                                   ,l_flex_segment_num);
9829 
9830 /* Get the segments of the given account */
9831     IF (NOT FND_FLEX_EXT.GET_SEGMENTS('SQLGL'
9832                                      ,'GL#'
9833                                      , p_coa_id
9834                                      ,P_base_ccid
9835                                      ,l_num_of_segments
9836                                      ,l_base_segments)) THEN
9837 
9838       RETURN -1 ;
9839 
9840     END IF;
9841 
9842 /* Get the Balancing Segment or Accounting Segment based on the auto-offset option */
9843     FOR i IN 1.. l_num_of_segments LOOP
9844 
9845       IF (l_Flex_Qualifier_Name = 'GL_BALANCING') THEN
9846 
9847         IF (i = l_flex_segment_num) THEN
9848 
9849           l_segments(i) := l_base_segments(i);
9850           l_return_segments := l_segments(i);
9851 
9852         END IF;
9853 
9854       ELSIF (l_Flex_Qualifier_Name = 'GL_ACCOUNT') THEN
9855 
9856         IF (i = l_flex_segment_num) THEN
9857 
9858           l_segments(i) := l_base_segments(i);
9859 
9860         ELSE
9861 
9862           l_segments(i) := l_base_segments(i);
9863           l_return_segments :=  l_return_segments || l_segments(i) ;
9864 
9865         END IF;
9866 
9867       END IF;
9868 
9869     END LOOP;
9870 
9871     return l_return_segments;
9872 
9873   END get_auto_offsets_segments;
9874 
9875 FUNCTION Allow_Adjust_with_Auto_Offset
9876          (p_expenditure_item_id         IN NUMBER,
9877           p_org_id                      IN NUMBER,
9878           p_system_linkage_function     IN VARCHAR2,
9879           p_transaction_source          IN VARCHAR2,
9880           P_action                      IN VARCHAR2,
9881           P_project_id                  IN NUMBER,
9882           P_task_id                     IN NUMBER,
9883           p_expenditure_type            IN VARCHAR2,
9884           p_vendor_id                   IN NUMBER,
9885           p_expenditure_organization_id IN NUMBER,
9886           p_expenditure_item_date       IN DATE,
9887           p_emp_id                      IN NUMBER,
9888           p_invoice_distribution_id     IN NUMBER,
9889           p_invoice_payment_id          IN AP_INVOICE_PAYMENTS_ALL.INVOICE_PAYMENT_ID%TYPE, /* Bug 5006835 */
9890           p_award_id                    IN NUMBER,
9891           p_billable_flag1              IN VARCHAR2,
9892           p_billable_flag2              IN VARCHAR2,
9893           x_encoded_error_message       OUT NOCOPY VARCHAR2) /* Bug 4997739 */
9894 RETURN BOOLEAN IS
9895 
9896   l_automatic_offset_method VARCHAR2(25) := 'UNKNOWN';
9897   l_billable_flag           VARCHAR2(1);
9898   l_return                  BOOLEAN := TRUE;
9899   l_pooled_flag             VARCHAR(1); /* Bug 5006835 */
9900   l_encoded_error_message   VARCHAR2(2000); /* Bug 4997739 */
9901   l_historical_flag         PA_EXPENDITURE_ITEMS_ALL.HISTORICAL_FLAG%TYPE := 'N'; /* Bug 5551933 */
9902 
9903   CURSOR c_get_ap_offset_method IS
9904   SELECT LIABILITY_POST_LOOKUP_CODE
9905     FROM AP_SYSTEM_PARAMETERS;
9906 
9907 /* Bug 5006835 - Start */
9908 /* This cursor is used to determine if the disbursement bank account is pooled
9909    for a payment in cash basis accounting setup */
9910   CURSOR c_get_pooled_flag(p_invoice_payment_id AP_INVOICE_PAYMENTS_ALL.INVOICE_PAYMENT_ID%TYPE) IS
9911   SELECT B.POOLED_FLAG
9912     FROM CE_BANK_ACCOUNTS B
9913        , AP_CHECKS_ALL C
9914        , AP_INVOICE_PAYMENTS_ALL A
9915    WHERE A.INVOICE_PAYMENT_ID = p_invoice_payment_id
9916      AND A.CHECK_ID = C.CHECK_ID
9917      AND C.CE_BANK_ACCT_USE_ID = B.BANK_ACCOUNT_ID;
9918 /* Bug 5006835 - End */
9919 
9920 BEGIN
9921 
9922 /* Bug 5006835 - Start */
9923     IF PA_UTILS4.get_ledger_cash_basis_flag = 'Y' THEN
9924 
9925 /* Bug 5551933 - Start */
9926       IF p_transaction_source = 'AP DISCOUNTS' THEN
9927 
9928 /* Bug 5559214 - Start */
9929         SELECT nvl(historical_flag, 'N')
9930         INTO l_historical_flag
9931         FROM ap_invoice_distributions_all
9932         WHERE invoice_distribution_id = p_invoice_distribution_id;
9933 /* Bug 5559214 - End */
9934 
9935       END IF;
9936 
9937       IF  l_historical_flag = 'N'
9938       AND p_invoice_payment_id IS NOT NULL THEN /* Bug 5455212 */
9939 
9940         OPEN c_get_pooled_flag(p_invoice_payment_id);
9941         FETCH c_get_pooled_flag INTO l_pooled_flag;
9942         CLOSE c_get_pooled_flag;
9943 
9944         IF NVL(l_pooled_flag, 'N') = 'N' THEN
9945 
9946           RETURN TRUE;
9947 
9948         END IF;
9949 
9950       END IF;
9951 /* Bug 5551933 - End */
9952 
9953     END IF;
9954 /* Bug 5006835 - End */
9955 
9956 /* Account can change only when the project, task, billability or capitalizability changes */
9957     IF G_AUTOMATIC_OFFSET_METHOD.COUNT = 0 THEN
9958 
9959 /* If cache is empty, then populate the PL/SQL table with the offset method and
9960    corresponding org_id */
9961       OPEN c_get_ap_offset_method;
9962       FETCH c_get_ap_offset_method
9963       INTO l_automatic_offset_method;
9964       CLOSE c_get_ap_offset_method;
9965 
9966       G_AUTOMATIC_OFFSET_METHOD(1).ORG_ID := p_org_id;
9967       G_AUTOMATIC_OFFSET_METHOD(1).METHOD := l_automatic_offset_method;
9968 
9969     ELSE
9970 
9971 /* else check the cache to see if the automatic offset method is cached for this org */
9972       FOR i IN G_AUTOMATIC_OFFSET_METHOD.FIRST..G_AUTOMATIC_OFFSET_METHOD.LAST LOOP
9973 
9974         IF G_AUTOMATIC_OFFSET_METHOD(i).ORG_ID = p_org_id THEN
9975 
9976           l_automatic_offset_method := G_AUTOMATIC_OFFSET_METHOD(i).METHOD;
9977           EXIT;
9978 
9979         END IF;
9980 
9981       END LOOP;
9982 
9983       IF l_automatic_offset_method = 'UNKNOWN' THEN
9984 
9985 /* if the offset method is still undetermined, it means that it was not found in the cahce.
9986    So it has to be derived using the cursor and the cache has to be updated */
9987         OPEN c_get_ap_offset_method;
9988         FETCH c_get_ap_offset_method
9989         INTO l_automatic_offset_method;
9990         CLOSE c_get_ap_offset_method;
9991 
9992         G_AUTOMATIC_OFFSET_METHOD(G_AUTOMATIC_OFFSET_METHOD.LAST + 1).ORG_ID := p_org_id;
9993         G_AUTOMATIC_OFFSET_METHOD(G_AUTOMATIC_OFFSET_METHOD.LAST + 1).METHOD := l_automatic_offset_method;
9994 
9995       END IF;
9996 
9997     END IF;
9998 
9999     IF l_automatic_offset_method IS NOT NULL THEN
10000 
10001 /* If automatic adjustment is enabled, then check if the transaction can be adjusted or not */
10002 
10003 /* we can set the billable/capitalizable flag based on the adjustment action */
10004       IF p_action IN ('BILLABLE RECLASS','CAPITALIZABLE RECLASS') THEN
10005 
10006         l_billable_flag := 'Y';
10007 
10008       ELSIF p_action IN ('NON-BILLABLE RECLASS','NON-CAPITALIZABLE RECLASS') THEN
10009 
10010         l_billable_flag := 'N';
10011 
10012       ELSE
10013 
10014         l_billable_flag := p_billable_flag1;
10015 
10016       END IF;
10017 
10018 /* get the original and new Charge account */
10019       IF p_expenditure_item_id <> NVL(G_EXP_ITEM_ID,-99) THEN
10020         get_old_and_new_ccid(p_expenditure_item_id
10021                             ,p_project_id
10022                             ,p_task_id
10023                             ,p_expenditure_type
10024                             ,p_vendor_id
10025                             ,p_expenditure_organization_id
10026                             ,p_expenditure_item_date
10027                             ,l_billable_flag
10028                             ,p_org_id
10029                             ,p_emp_id
10030                             ,p_award_id
10031                             ,p_system_linkage_function
10032                             ,p_transaction_source
10033                             ,p_invoice_distribution_id
10034                             ,G_OLD_CCID
10035                             ,G_NEW_CCID
10036                             ,l_encoded_error_message); /* Bug 4997739 */
10037 /* Bug 4997739 - Return false if there were any errors in workflow */
10038         IF l_encoded_error_message IS NOT NULL THEN
10039           x_encoded_error_message := l_encoded_error_message;
10040           RETURN FALSE;
10041         END IF;
10042         G_EXP_ITEM_ID := p_expenditure_item_id;
10043       END IF;
10044 
10045 /* check if the liability account is affected */
10046       IF get_auto_offsets_segments(l_automatic_offset_method,G_OLD_CCID,G_COA_ID)
10047              <> get_auto_offsets_segments(l_automatic_offset_method,G_NEW_CCID,G_COA_ID) THEN
10048 
10049 /* if yes, then set the return value to FALSE */
10050         l_return := FALSE;
10051 
10052       END IF;
10053 
10054       IF  l_return = TRUE
10055       AND p_action = 'SPLIT' THEN
10056 
10057 /* if the adjustment action is split, then the second part of the split transaction
10058    also has to be verified */
10059         IF p_expenditure_item_id <> NVL(G_EXP_ITEM_ID,-99) THEN
10060           get_old_and_new_ccid(p_expenditure_item_id
10061                               ,p_project_id
10062                               ,p_task_id
10063                               ,p_expenditure_type
10064                               ,p_vendor_id
10065                               ,p_expenditure_organization_id
10066                               ,p_expenditure_item_date
10067                               ,p_billable_flag2
10068                               ,p_org_id
10069                               ,p_emp_id
10070                               ,p_award_id
10071                               ,p_system_linkage_function
10072                               ,p_transaction_source
10073                               ,p_invoice_distribution_id
10074                               ,G_OLD_CCID
10075                               ,G_NEW_CCID
10076                               ,l_encoded_error_message); /* Bug 4997739 */
10077 /* Bug 4997739 - Return false if there were any errors in workflow */
10078           IF l_encoded_error_message IS NOT NULL THEN
10079             x_encoded_error_message := l_encoded_error_message;
10080             RETURN FALSE;
10081           END IF;
10082           G_EXP_ITEM_ID := p_expenditure_item_id;
10083         END IF;
10084 
10085         IF get_auto_offsets_segments(l_automatic_offset_method,G_OLD_CCID,G_COA_ID)
10086                <> get_auto_offsets_segments(l_automatic_offset_method,G_NEW_CCID,G_COA_ID) THEN
10087 
10088           l_return := FALSE;
10089 
10090         END IF;
10091 
10092       END IF;
10093 
10094     END IF;
10095 
10096   RETURN l_return;
10097 
10098 END Allow_Adjust_with_Auto_Offset;
10099 /* R12 changes End */
10100 
10101 /* R12 Changes Start */
10102 FUNCTION Get_Displayed_Field
10103     ( p_lookup_type varchar2
10104     , p_lookup_code varchar2)
10105 RETURN VARCHAR2 IS
10106 
10107   CURSOR C_Inv_Displayed_Field_Cur IS
10108   SELECT displayed_field
10109     FROM ap_lookup_codes
10110    WHERE lookup_type = p_lookup_type
10111      AND lookup_code = p_lookup_code;
10112 
10113   CURSOR C_PO_Displayed_Field_Cur IS
10114   SELECT displayed_field
10115     FROM po_lookup_codes
10116    WHERE lookup_type = p_lookup_type
10117      AND lookup_code = p_lookup_code;
10118 
10119 BEGIN
10120 
10121   IF  p_lookup_type = 'INVOICE TYPE' THEN
10122 
10123     IF p_lookup_code <> NVL(G_INV_TYPE_CODE,-99) THEN
10124 
10125       OPEN C_Inv_Displayed_Field_Cur;
10126       FETCH C_Inv_Displayed_Field_Cur
10127        INTO G_INV_TYPE;
10128       CLOSE C_Inv_Displayed_Field_Cur;
10129 
10130       G_INV_TYPE_CODE := p_lookup_code;
10131 
10132     END IF;
10133 
10134     RETURN G_INV_TYPE;
10135 
10136   END IF;
10137 
10138   IF  p_lookup_type = 'INVOICE LINE TYPE' THEN
10139 
10140     IF p_lookup_code <> NVL(G_INV_LINE_TYPE_CODE,-99) THEN
10141 
10142       OPEN C_Inv_Displayed_Field_Cur;
10143       FETCH C_Inv_Displayed_Field_Cur
10144        INTO G_INV_LINE_TYPE;
10145       CLOSE C_Inv_Displayed_Field_Cur;
10146 
10147       G_INV_LINE_TYPE_CODE := p_lookup_code;
10148 
10149     END IF;
10150 
10151     RETURN G_INV_LINE_TYPE;
10152 
10153   END IF;
10154 
10155   IF  p_lookup_type = 'INVOICE DISTRIBUTION TYPE' THEN
10156 
10157     IF p_lookup_code <> NVL(G_INV_DIST_TYPE_CODE,-99) THEN
10158 
10159       OPEN C_Inv_Displayed_Field_Cur;
10160       FETCH C_Inv_Displayed_Field_Cur
10161        INTO G_INV_DIST_TYPE;
10162       CLOSE C_Inv_Displayed_Field_Cur;
10163 
10164       G_INV_DIST_TYPE_CODE := p_lookup_code;
10165 
10166     END IF;
10167 
10168     RETURN G_INV_DIST_TYPE;
10169 
10170   END IF;
10171 
10172 /* Bug 4914048 - Start */
10173   IF  p_lookup_type = 'PAYMENT TYPE' THEN
10174 
10175     IF p_lookup_code <> NVL(G_PAYMENT_TYPE_CODE,-99) THEN
10176 
10177       OPEN C_Inv_Displayed_Field_Cur;
10178       FETCH C_Inv_Displayed_Field_Cur
10179        INTO G_PAYMENT_TYPE;
10180       CLOSE C_Inv_Displayed_Field_Cur;
10181 
10182       G_PAYMENT_TYPE_CODE := p_lookup_code;
10183 
10184     END IF;
10185 
10186     RETURN G_PAYMENT_TYPE;
10187 
10188   END IF;
10189 /* Bug 4914048 - End */
10190 
10191   IF  p_lookup_type = 'PO TYPE' THEN
10192 
10193     IF p_lookup_code <> NVL(G_PO_DIST_TYPE_CODE,-99) THEN
10194 
10195       OPEN C_PO_Displayed_Field_Cur;
10196       FETCH C_PO_Displayed_Field_Cur
10197        INTO G_PO_DIST_TYPE;
10198       CLOSE C_PO_Displayed_Field_Cur;
10199 
10200       G_PO_DIST_TYPE_CODE := p_lookup_code;
10201 
10202     END IF;
10203 
10204     RETURN G_PO_DIST_TYPE;
10205 
10206   END IF;
10207 
10208   IF  p_lookup_type = 'RCV TRANSACTION TYPE' THEN
10209 
10210     IF p_lookup_code <> NVL(G_RCV_TXN_TYPE_CODE,-99) THEN
10211 
10212       OPEN C_PO_Displayed_Field_Cur;
10213       FETCH C_PO_Displayed_Field_Cur
10214        INTO G_RCV_TXN_TYPE;
10215       CLOSE C_PO_Displayed_Field_Cur;
10216 
10217       G_RCV_TXN_TYPE_CODE := p_lookup_code;
10218 
10219     END IF;
10220 
10221     RETURN G_RCV_TXN_TYPE;
10222 
10223   END IF;
10224 
10225   RETURN NULL;
10226 
10227 END Get_Displayed_Field;
10228 
10229 FUNCTION Get_PO_Info
10230     ( p_key varchar2
10231     , p_po_distribution_id number)
10232 RETURN VARCHAR2 IS
10233 
10234   l_po_distribution_type_code varchar2(30);
10235 
10236   CURSOR C_PO_Info_Cur IS
10237   SELECT po.po_header_id
10238        , po.segment1
10239        , po.creation_date
10240        , po_line.line_num
10241        , po_dist.distribution_num
10242        , po_dist.distribution_type
10243     FROM po_headers po
10244        , po_lines po_line
10245        , po_distributions po_dist
10246    WHERE po.po_header_id = po_line.po_header_id
10247      AND po_line.po_line_id = po_dist.po_line_id
10248      AND po_dist.po_distribution_id = p_po_distribution_id;
10249 BEGIN
10250 
10251   IF p_po_distribution_id IS NULL THEN
10252 
10253     RETURN NULL;
10254 
10255   END IF;
10256 
10257   IF  NVL(G_PO_DIST_ID,-99) <> p_po_distribution_id THEN
10258 
10259     OPEN C_PO_Info_Cur;
10260     FETCH C_PO_Info_Cur
10261      INTO G_PO_HEADER_ID
10262         , G_PO_NUM
10263         , G_PO_DATE
10264         , G_PO_LINE_NUM
10265         , G_PO_DIST_NUM
10266         , l_po_distribution_type_code;
10267     CLOSE C_PO_Info_Cur;
10268 
10269     G_PO_DIST_TYPE := Get_Displayed_Field('PO TYPE', l_po_distribution_type_code);
10270 
10271     G_PO_DIST_ID := p_po_distribution_id;
10272 
10273   END IF;
10274 
10275   CASE p_key
10276     WHEN 'PO HEADER ID' THEN RETURN G_PO_HEADER_ID;
10277     WHEN 'PO NUM'       THEN RETURN G_PO_NUM;
10278     WHEN 'PO DATE'      THEN RETURN to_char(G_PO_DATE,'DD-MON-YYYY');
10279     WHEN 'PO LINE NUM'  THEN RETURN G_PO_LINE_NUM;
10280     WHEN 'PO DIST NUM'  THEN RETURN G_PO_DIST_NUM;
10281     WHEN 'PO TYPE'      THEN RETURN G_PO_DIST_TYPE;
10282   END CASE;
10283 
10284 EXCEPTION
10285   WHEN OTHERS THEN
10286     G_PO_DIST_ID := NULL;
10287     G_PO_HEADER_ID := NULL;
10288     G_PO_NUM := NULL;
10289     G_PO_DATE := NULL;
10290     G_PO_LINE_NUM := NULL;
10291     G_PO_DIST_NUM := NULL;
10292     G_PO_DIST_TYPE := NULL;
10293     RAISE;
10294 
10295 END Get_PO_Info;
10296 
10297 FUNCTION Get_Rcv_Info
10298     ( p_key varchar2
10299     , p_rcv_transaction_id number)
10300 RETURN VARCHAR2 IS
10301 
10302   l_rcv_transaction_type_code varchar2(30);
10303 
10304   CURSOR C_Rcv_Info_Cur IS
10305   SELECT rcv.receipt_num
10306        , rcvtxn.transaction_date
10307        , rcvtxn.transaction_type
10308     FROM rcv_shipment_headers rcv
10309        , rcv_transactions rcvtxn
10310    WHERE rcv.shipment_header_id = rcvtxn.shipment_header_id
10311      AND rcvtxn.transaction_id = p_rcv_transaction_id;
10312 
10313 BEGIN
10314 
10315   IF p_rcv_transaction_id IS NULL THEN
10316 
10317     RETURN NULL;
10318 
10319   END IF;
10320 
10321   IF NVL(G_RCV_TXN_ID,-1) <> p_rcv_transaction_id THEN
10322 
10323     OPEN C_Rcv_Info_Cur;
10324     FETCH C_Rcv_Info_Cur
10325      INTO G_RCV_NUM
10326         , G_RCV_DATE
10327         , l_rcv_transaction_type_code;
10328     CLOSE C_Rcv_Info_Cur;
10329 
10330     G_RCV_TXN_TYPE := Get_Displayed_Field('RCV TRANSACTION TYPE', l_rcv_transaction_type_code);
10331 
10332     G_RCV_TXN_ID := p_rcv_transaction_id;
10333 
10334   END IF;
10335 
10336   CASE p_key
10337     WHEN 'RECEIPT NUMBER'       THEN RETURN G_RCV_NUM;
10338     WHEN 'RECEIPT DATE'         THEN RETURN to_char(G_RCV_DATE,'DD-MON-YYYY');
10339     WHEN 'RCV TRANSACTION TYPE' THEN RETURN G_RCV_TXN_TYPE;
10340   END CASE;
10341 
10342 EXCEPTION
10343   WHEN OTHERS THEN
10344     G_RCV_TXN_ID := NULL;
10345     G_RCV_NUM := NULL;
10346     G_RCV_DATE := NULL;
10347     RAISE;
10348 
10349 END Get_Rcv_Info;
10350 
10351 FUNCTION Get_Inv_Info
10352     ( p_key varchar2
10353     , p_invoice_id number)
10354 RETURN VARCHAR2 IS
10355 
10356   l_inv_type_code varchar2(30);
10357 
10358   CURSOR C_Inv_Info_Cur IS
10359   SELECT ap.invoice_type_lookup_code
10360        , ap.invoice_num
10361        , ap.invoice_date
10362     FROM ap_invoices ap
10363    WHERE ap.invoice_id = p_invoice_id;
10364 
10365 BEGIN
10366 
10367   IF p_invoice_id IS NULL THEN
10368 
10369     RETURN NULL;
10370 
10371   END IF;
10372 
10373   IF NVL(G_INV_ID,-1) <> p_invoice_id THEN
10374 
10375     OPEN C_Inv_Info_Cur;
10376     FETCH C_Inv_Info_Cur
10377      INTO l_inv_type_code
10378         , G_INV_NUM
10379         , G_INV_DATE;
10380     CLOSE C_Inv_Info_Cur;
10381 
10382     G_INV_TYPE := Get_Displayed_Field('INVOICE TYPE', l_inv_type_code);
10383 
10384     G_INV_ID := p_invoice_id;
10385 
10386   END IF;
10387 
10388   CASE p_key
10389     WHEN 'INVOICE TYPE'         THEN RETURN G_INV_TYPE;
10390     WHEN 'INVOICE NUMBER'       THEN RETURN G_INV_NUM;
10391     WHEN 'INVOICE DATE'         THEN RETURN to_char(G_INV_DATE,'DD-MON-YYYY');
10392   END CASE;
10393 
10394 EXCEPTION
10395   WHEN OTHERS THEN
10396     G_INV_ID := NULL;
10397     G_INV_NUM := NULL;
10398     G_INV_DATE := NULL;
10399     RAISE;
10400 
10401 END Get_Inv_Info;
10402 
10403 --=======================================================================
10404 -- Function is_recoverability_affected
10405 --=======================================================================
10406    FUNCTION is_recoverability_affected
10407          (p_expenditure_item_id         IN NUMBER,
10408           p_org_id                      IN NUMBER,
10409           p_system_linkage_function     IN VARCHAR2,
10410           p_transaction_source          IN VARCHAR2,
10411           P_action                      IN VARCHAR2,
10412           P_project_id                  IN NUMBER,
10413           P_task_id                     IN NUMBER,
10414           p_expenditure_type            IN VARCHAR2,
10415           p_vendor_id                   IN NUMBER,
10416           p_expenditure_organization_id IN NUMBER,
10417           p_expenditure_item_date       IN DATE,
10418           p_emp_id                      IN NUMBER,
10419           p_document_header_id          IN NUMBER,
10420           p_document_line_number        IN NUMBER,
10421           p_document_distribution_id    IN NUMBER,
10422           p_document_type               IN VARCHAR2,
10423           p_award_id                    IN NUMBER,
10424           p_billable_flag1              IN VARCHAR2,
10425           p_billable_flag2              IN VARCHAR2,
10426           x_error_message_name          OUT NOCOPY VARCHAR2, /* Bug 4997739 */
10427           x_encoded_error_message       OUT NOCOPY VARCHAR2) /* Bug 4997739 */
10428    return BOOLEAN is
10429 
10430      l_billable_flag           VARCHAR2(1);
10431      l_po_line_location_id     NUMBER;
10432      l_old_ccid                NUMBER;
10433      l_new_ccid                NUMBER;
10434      l_return                  BOOLEAN := FALSE;
10435      l_pa_item_info_tbl ZX_API_PUB.pa_item_info_tbl_type;
10436      l_return_status VARCHAR2(1);
10437      l_msg_count NUMBER;
10438      X_error_code  VARCHAR2(30);
10439      l_encoded_error_message VARCHAR2(2000);
10440      l_parent_distribution_id AP_INVOICE_DISTRIBUTIONS_ALL.INVOICE_DISTRIBUTION_ID%TYPE; /* Bug 5386471 */
10441      l_parent_line_number AP_INVOICE_DISTRIBUTIONS_ALL.INVOICE_LINE_NUMBER%TYPE; /* Bug 5386471 */
10442      l_ccid_changed BOOLEAN := FALSE; /* Bug 5440305 */
10443 
10444      CURSOR c_po_shipment_id_cur(p_po_distribution_id NUMBER) IS
10445      SELECT LINE_LOCATION_ID
10446        FROM PO_DISTRIBUTIONS
10447       WHERE PO_DISTRIBUTION_ID = p_po_distribution_id;
10448 
10449 /* Bug 5386471 - Start */
10450      CURSOR c_parent_distribution_id_cur(p_invoice_distribution_id AP_INVOICE_DISTRIBUTIONS_ALL.INVOICE_DISTRIBUTION_ID%TYPE) IS
10451      SELECT NVL(charge_applicable_to_dist_id,NVL(related_id, invoice_distribution_id))
10452        FROM ap_invoice_distributions_all
10453       WHERE invoice_distribution_id = p_invoice_distribution_id;
10454 
10455      CURSOR c_parent_line_number_cur(p_parent_distribution_id AP_INVOICE_DISTRIBUTIONS_ALL.INVOICE_DISTRIBUTION_ID%TYPE) IS
10456      SELECT invoice_line_number
10457        FROM ap_invoice_distributions_all
10458       WHERE invoice_distribution_id = p_parent_distribution_id;
10459 /* Bug 5386471 - End */
10460 
10461      etax_exception EXCEPTION;
10462      PRAGMA EXCEPTION_INIT(etax_exception,-20001);
10463    BEGIN
10464 /* check if the tax recovery rate can change */
10465       IF p_action IN ('BILLABLE RECLASS','CAPITALIZABLE RECLASS') THEN
10466 
10467         l_billable_flag := 'Y';
10468 
10469       ELSIF p_action IN ('NON-BILLABLE RECLASS','NON-CAPITALIZABLE RECLASS') THEN
10470 
10471         l_billable_flag := 'N';
10472 
10473       ELSE
10474 
10475         l_billable_flag := p_billable_flag1;
10476 
10477       END IF;
10478 
10479 /* get the original and new Charge account */
10480       IF p_expenditure_item_id <> NVL(G_EXP_ITEM_ID,-99) THEN
10481 
10482         get_old_and_new_ccid(p_expenditure_item_id
10483                             ,p_project_id
10484                             ,p_task_id
10485                             ,p_expenditure_type
10486                             ,p_vendor_id
10487                             ,p_expenditure_organization_id
10488                             ,p_expenditure_item_date
10489                             ,l_billable_flag
10490                             ,p_org_id
10491                             ,p_emp_id
10492                             ,p_award_id
10493                             ,p_system_linkage_function
10494                             ,p_transaction_source
10495                             ,p_document_distribution_id
10496                             ,G_OLD_CCID
10497                             ,G_NEW_CCID
10498                             ,l_encoded_error_message); /* Bug 4997739 */
10499 /* Bug 4997739 - Return true if there were any errors in workflow */
10500         IF l_encoded_error_message IS NOT NULL THEN
10501           x_encoded_error_message := l_encoded_error_message;
10502           RETURN TRUE;
10503         END IF;
10504         G_EXP_ITEM_ID := p_expenditure_item_id;
10505 
10506       END IF;
10507 
10508 /* Bug 5440305 - Set flag if the account changes */
10509       IF G_OLD_CCID <> G_NEW_CCID THEN
10510 
10511           l_ccid_changed := TRUE;
10512 
10513       END IF;
10514 
10515       IF p_transaction_source IN ('AP INVOICE'
10516                                  ,'INTERCOMPANY_AP_INVOICES'
10517                                  ,'INTERPROJECT_AP_INVOICES'
10518                                  ,'AP VARIANCE'
10519                                  ,'AP NRTAX'
10520                                  ,'AP DISCOUNTS'
10521                                  ,'AP EXPENSE'
10522                                  ,'AP ERV') THEN /* Bug 5235354 */
10523 
10524 /* Bug 5386471 - Start */
10525           OPEN c_parent_distribution_id_cur(p_document_distribution_id);
10526           FETCH c_parent_distribution_id_cur
10527            INTO l_parent_distribution_id;
10528           CLOSE c_parent_distribution_id_cur;
10529 
10530           IF l_parent_distribution_id =  p_document_distribution_id THEN
10531             l_parent_line_number := p_document_line_number;
10532           ELSE
10533             OPEN c_parent_line_number_cur(l_parent_distribution_id);
10534             FETCH c_parent_line_number_cur
10535              INTO l_parent_line_number;
10536             CLOSE c_parent_line_number_cur;
10537           END IF;
10538 /* Bug 5386471 - End */
10539 
10540           l_pa_item_info_tbl(1).APPLICATION_ID       := 200; --(Oracle payables application Id)
10541           l_pa_item_info_tbl(1).ENTITY_CODE          := 'AP_INVOICES';
10542           CASE p_document_type
10543             WHEN 'STANDARD'       THEN l_pa_item_info_tbl(1).EVENT_CLASS_CODE := 'STANDARD INVOICES';
10544             WHEN 'PREPAYMENT'     THEN l_pa_item_info_tbl(1).EVENT_CLASS_CODE := 'PREPAYMENT INVOICES';
10545             WHEN 'EXPENSE REPORT' THEN l_pa_item_info_tbl(1).EVENT_CLASS_CODE := 'EXPENSE REPORTS';
10546 /* Bug 5386471 - Start */
10547             WHEN 'CREDIT'         THEN l_pa_item_info_tbl(1).EVENT_CLASS_CODE := 'STANDARD INVOICES';
10548             WHEN 'DEBIT'          THEN l_pa_item_info_tbl(1).EVENT_CLASS_CODE := 'STANDARD INVOICES';
10549             WHEN 'MIXED'          THEN l_pa_item_info_tbl(1).EVENT_CLASS_CODE := 'STANDARD INVOICES';
10550 /* Bug 5386471 - End */
10551             ELSE                       l_pa_item_info_tbl(1).EVENT_CLASS_CODE := NULL;
10552           END CASE;
10553           l_pa_item_info_tbl(1).TRX_ID               := p_document_header_id;
10554           l_pa_item_info_tbl(1).TRX_LINE_ID          := l_parent_line_number; /* Bug 5386471 */
10555           l_pa_item_info_tbl(1).TRX_LEVEL_TYPE       := 'LINE';
10556           l_pa_item_info_tbl(1).ITEM_EXPENSE_DIST_ID := l_parent_distribution_id; /* Bug 5386471 */
10557           l_pa_item_info_tbl(1).NEW_ACCOUNT_CCID     := G_NEW_CCID;
10558           l_pa_item_info_tbl(1).NEW_ACCOUNT_STRING   := NULL;
10559           l_pa_item_info_tbl(1).NEW_PROJECT_ID       := p_project_id;
10560           l_pa_item_info_tbl(1).NEW_TASK_ID          := p_task_id;
10561           l_pa_item_info_tbl(1).RECOVERABILITY_AFFECTED := FALSE;
10562 
10563       ELSIF p_transaction_source IN ('PO RECEIPT'
10564                                     ,'PO RECEIPT NRTAX'
10565                                     ,'PO RECEIPT NRTAX PRICE ADJ'
10566                                     ,'PO RECEIPT PRICE ADJ') THEN
10567 
10568 /* Bug 5386471 - Start */
10569           OPEN c_po_shipment_id_cur(p_document_line_number);
10570           FETCH c_po_shipment_id_cur
10571            INTO l_po_line_location_id;
10572           CLOSE c_po_shipment_id_cur;
10573 /* Bug 5386471 - End */
10574 
10575           l_pa_item_info_tbl(1).APPLICATION_ID       := 201; --(Oracle purchasing application Id)
10576           l_pa_item_info_tbl(1).ENTITY_CODE          := 'PURCHASE_ORDER';
10577           l_pa_item_info_tbl(1).EVENT_CLASS_CODE     := 'PO_PA';
10578           l_pa_item_info_tbl(1).TRX_ID               := p_document_header_id;
10579           l_pa_item_info_tbl(1).TRX_LINE_ID          := l_po_line_location_id;
10580           l_pa_item_info_tbl(1).TRX_LEVEL_TYPE       := 'SHIPMENT'; /* Bug 5386471 */
10581           l_pa_item_info_tbl(1).ITEM_EXPENSE_DIST_ID := p_document_line_number; /* Bug 5386471 */
10582           l_pa_item_info_tbl(1).NEW_ACCOUNT_CCID     := G_NEW_CCID;
10583           l_pa_item_info_tbl(1).NEW_ACCOUNT_STRING   := NULL ;
10584           l_pa_item_info_tbl(1).NEW_PROJECT_ID       := p_project_id;
10585           l_pa_item_info_tbl(1).NEW_TASK_ID          := p_task_id;
10586           l_pa_item_info_tbl(1).RECOVERABILITY_AFFECTED := FALSE;
10587 
10588       END IF;
10589 
10590 /* Bug 5440305 - eBTax API will be called only if there is a change in the account */
10591       IF l_ccid_changed THEN
10592 
10593         l_ccid_changed := FALSE; /* Bug 5440305 - Reset the flag */
10594 
10595         ZX_API_PUB.is_recoverability_affected(
10596                    p_api_version        => 1.0,
10597                    p_init_msg_list      => FND_API.G_TRUE,
10598                    p_commit             => NULL,
10599                    p_validation_level   => NULL,
10600                    x_return_status      => l_return_status,
10601                    x_msg_count          => l_msg_count,
10602                    x_msg_data           => X_error_code,
10603                    p_pa_item_info_tbl   => l_pa_item_info_tbl);
10604 
10605         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10606 
10607           x_error_message_name := 'PA_SI_ADJ_ETAX_EXCEPTION';
10608           RETURN TRUE;
10609 
10610         END IF;
10611 
10612         IF l_pa_item_info_tbl(1).RECOVERABILITY_AFFECTED THEN
10613 
10614           l_return := TRUE;
10615 
10616         END IF;
10617 
10618       END IF;
10619 
10620       IF  l_return = FALSE
10621       AND p_action = 'SPLIT' THEN
10622 
10623 /* if the adjustment action is split, then the second part of the split transaction
10624    also has to be verified */
10625         IF p_expenditure_item_id <> NVL(G_EXP_ITEM_ID,-99) THEN
10626 
10627           get_old_and_new_ccid(p_expenditure_item_id
10628                               ,p_project_id
10629                               ,p_task_id
10630                               ,p_expenditure_type
10631                               ,p_vendor_id
10632                               ,p_expenditure_organization_id
10633                               ,p_expenditure_item_date
10634                               ,p_billable_flag2
10635                               ,p_org_id
10636                               ,p_emp_id
10637                               ,p_award_id
10638                               ,p_system_linkage_function
10639                               ,p_transaction_source
10640                               ,p_document_distribution_id
10641                               ,G_OLD_CCID
10642                               ,G_NEW_CCID
10643                               ,l_encoded_error_message); /* Bug 4997739 */
10644 /* Bug 4997739 - Return true if there were any errors in workflow */
10645           IF l_encoded_error_message IS NOT NULL THEN
10646             x_encoded_error_message := l_encoded_error_message;
10647             RETURN TRUE;
10648           END IF;
10649 
10650           G_EXP_ITEM_ID := p_expenditure_item_id;
10651 
10652         END IF;
10653 
10654 /* Bug 5440305 - Set flag if the account changes */
10655         IF G_OLD_CCID <> G_NEW_CCID THEN
10656 
10657           l_ccid_changed := TRUE;
10658 
10659         END IF;
10660 
10661         l_pa_item_info_tbl(1).NEW_ACCOUNT_CCID     := G_NEW_CCID;
10662 
10663 /* Bug 5440305 - eBTax API will be called only if there is a change in the account */
10664         IF l_ccid_changed THEN
10665 
10666           l_ccid_changed := FALSE; /* Bug 5440305 - Reset the flag */
10667           ZX_API_PUB.is_recoverability_affected(
10668                    p_api_version        => 1.0,
10669                    p_init_msg_list      => FND_API.G_TRUE,
10670                    p_commit             => NULL,
10671                    p_validation_level   => NULL,
10672                    x_return_status      => l_return_status,
10673                    x_msg_count          => l_msg_count,
10674                    x_msg_data           => X_error_code,
10675                    p_pa_item_info_tbl   => l_pa_item_info_tbl);
10676 
10677           IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10678 
10679             x_error_message_name := 'PA_SI_ADJ_ETAX_EXCEPTION';
10680             RETURN TRUE;
10681 
10682           END IF;
10683 
10684           IF l_pa_item_info_tbl(1).RECOVERABILITY_AFFECTED THEN
10685 
10686             l_return := TRUE;
10687 
10688           END IF;
10689 
10690         END IF;
10691 
10692       END IF;
10693 
10694       IF l_return = TRUE THEN
10695 
10696         x_error_message_name := 'PA_SI_ADJ_NRTAX_CHG_NOT_ALLOW';
10697 
10698       END IF;
10699 
10700       RETURN l_return;
10701 
10702  END is_recoverability_affected;
10703 /* R12 Changes End */
10704 
10705 /* Bug 4901129 - Start */
10706 FUNCTION is_orphaned_src_sys_reversal( p_document_distribution_id IN PA_EXPENDITURE_ITEMS_ALL.DOCUMENT_DISTRIBUTION_ID%TYPE
10707                                      , p_transaction_source IN PA_EXPENDITURE_ITEMS_ALL.TRANSACTION_SOURCE%TYPE)
10708 RETURN VARCHAR2 IS
10709   l_result                   VARCHAR2(1) := 'N';
10710 
10711   CURSOR c_get_count IS
10712   SELECT DECODE(count(*),0,'N','Y')
10713     FROM pa_expenditure_items_all ei /* Bug 5561597 */
10714    WHERE ( ei.document_header_id, ei.document_distribution_id) IN
10715          ( SELECT apdist2.invoice_id, apdist2.invoice_distribution_id /* Bug 5561597 */
10716              FROM ap_invoice_distributions_all apdist1, /* Bug 5561597 */
10717                   ap_invoice_distributions_all apdist2 /* Bug 5561597 */
10718             WHERE p_document_distribution_id = apdist1.invoice_distribution_id
10719               AND apdist1.reversal_flag = 'Y'
10720               AND apdist1.parent_reversal_id = apdist2.invoice_distribution_id
10721               AND apdist2.old_distribution_id IS NOT NULL
10722               AND p_transaction_source IN ('AP VARIANCE','AP INVOICE'
10723                     ,'AP DISCOUNTS','INTERCOMPANY_AP_INVOICES','INTERPROJECT_AP_INVOICES'
10724                     ,'AP NRTAX','AP EXPENSE','AP ERV') /* Bug 5235354 */
10725          UNION ALL
10726            SELECT rcv2.po_header_id, rcv2.transaction_id
10727              FROM rcv_transactions rcv1
10728                 , rcv_transactions rcv2
10729             WHERE rcv1.transaction_id = p_document_distribution_id
10730               AND rcv1.transaction_type in ('RETURN TO RECEIVING','RETURN TO VENDOR','CORRECT')
10731               AND rcv1.parent_transaction_id = rcv2.transaction_id
10732               AND p_transaction_source IN ('PO RECEIPT','PO RECEIPT NRTAX',
10733                                  'PO RECEIPT NRTAX PRICE ADJ','PO RECEIPT PRICE ADJ'))
10734      AND (   ei.net_zero_adjustment_flag = 'Y'
10735          OR EXISTS ( SELECT NULL
10736                        FROM pa_cost_distribution_lines_all cdl2
10737                       WHERE cdl2.expenditure_item_id = ei.expenditure_item_id
10738                         AND cdl2.line_num = 1
10739                         AND cdl2.reversed_flag = 'Y'));
10740 BEGIN
10741   OPEN c_get_count;
10742   FETCH c_get_count INTO l_result;
10743   CLOSE c_get_count;
10744 
10745   RETURN l_result;
10746 END is_orphaned_src_sys_reversal;
10747 /* Bug 4901129 - End */
10748 
10749 /* Bug 5235354 - Start */
10750 FUNCTION RepCurrOrSecLedgerDiffCurr(p_org_id PA_EXPENDITURE_ITEMS_ALL.ORG_ID%TYPE)
10751 RETURN BOOLEAN IS
10752 
10753 l_count NUMBER := -1;
10754 l_return BOOLEAN := FALSE;
10755 
10756 CURSOR c_rep_curr_or_sec_ledger is
10757 SELECT COUNT(*)
10758 FROM gl_ledgers_v gl,
10759   pa_implementations imp
10760 WHERE imp.set_of_books_id = gl.ledger_id
10761  AND (EXISTS
10762   (SELECT NULL
10763    FROM gl_secondary_ledger_rships_v sl,
10764      xla_subledger_options_v xso
10765    WHERE sl.primary_ledger_id = gl.ledger_id
10766    AND sl.currency_code <> gl.currency_code
10767    AND sl.relationship_enabled_flag = 'Y'
10768    AND xso.application_id = 275
10769    AND xso.enabled_flag = 'Y'
10770    AND xso.ledger_id = sl.ledger_id)
10771  OR EXISTS
10772   (SELECT NULL
10773    FROM gl_alc_ledger_rships_v alc
10774    WHERE alc.primary_ledger_id = gl.ledger_id
10775    AND alc.currency_code <> gl.currency_code
10776    AND alc.application_id = 275
10777    AND relationship_enabled_flag = 'Y'));
10778 
10779 BEGIN
10780   IF G_LEDGER_CNT.COUNT = 0 THEN
10781 
10782 /* If cache is empty, then populate the PL/SQL table with the query result and
10783    corresponding org_id */
10784     OPEN c_rep_curr_or_sec_ledger;
10785     FETCH c_rep_curr_or_sec_ledger INTO l_count;
10786     CLOSE c_rep_curr_or_sec_ledger ;
10787 
10788     G_LEDGER_CNT(1).ORG_ID := p_org_id;
10789     G_LEDGER_CNT(1).CNT := l_count;
10790 
10791   ELSE
10792 
10793 /* else check the cache to see if it is cached for this org */
10794     FOR i IN G_LEDGER_CNT.FIRST..G_LEDGER_CNT.LAST LOOP
10795 
10796       IF G_LEDGER_CNT(i).ORG_ID = p_org_id THEN
10797 
10798         l_count := G_LEDGER_CNT(i).CNT;
10799         EXIT;
10800 
10801       END IF;
10802 
10803     END LOOP;
10804 
10805     IF l_count = -1  THEN
10806 
10807 /* if it is still undetermined, it means that it was not found in the cahce.
10808    So it has to be derived using the cursor and the cache has to be updated */
10809       OPEN c_rep_curr_or_sec_ledger;
10810       FETCH c_rep_curr_or_sec_ledger INTO l_count;
10811       CLOSE c_rep_curr_or_sec_ledger ;
10812 
10813       G_LEDGER_CNT(G_LEDGER_CNT.LAST + 1).ORG_ID := p_org_id;
10814       G_LEDGER_CNT(G_LEDGER_CNT.LAST + 1).CNT := l_count;
10815 
10816     END IF;
10817 
10818   END IF;
10819 
10820   IF l_count > 0 THEN
10821     l_return := TRUE;
10822   END IF;
10823 
10824   RETURN l_return;
10825 
10826 END RepCurrOrSecLedgerDiffCurr;
10827 /* Bug 5235354 - End */
10828 
10829 /* Bug 5381260 - Start */
10830 FUNCTION IsPeriodEndAccrual(p_invoice_distribution_id AP_INVOICE_DISTRIBUTIONS_ALL.INVOICE_DISTRIBUTION_ID%TYPE)
10831 RETURN BOOLEAN IS
10832   l_accrue_on_receipt_flag PO_LINE_LOCATIONS_ALL.ACCRUE_ON_RECEIPT_FLAG%TYPE;
10833   l_result BOOLEAN := TRUE;
10834 
10835   CURSOR c_get_accrue_on_receipt_flag IS
10836   SELECT poll.accrue_on_receipt_flag
10837     FROM po_line_locations_all poll
10838        , po_distributions_all pod
10839        , ap_invoice_distributions_all aid
10840    WHERE poll.line_location_id = pod.line_location_id
10841      AND pod.po_distribution_id = aid.po_distribution_id
10842      AND aid.invoice_distribution_id = p_invoice_distribution_id;
10843 BEGIN
10844   OPEN c_get_accrue_on_receipt_flag;
10845   FETCH c_get_accrue_on_receipt_flag INTO l_accrue_on_receipt_flag;
10846   CLOSE c_get_Accrue_on_receipt_flag;
10847 
10848   IF l_accrue_on_receipt_flag = 'Y' THEN
10849     l_result := FALSE;
10850   END IF;
10851 
10852   RETURN l_result;
10853 END IsPeriodEndAccrual;
10854 /* Bug 5381260 - End */
10855 
10856 /* Bug 5501250 - Start */
10857 FUNCTION IsRelatedToPrepayApp(
10858   p_invoice_distribution_id AP_INVOICE_DISTRIBUTIONS_ALL.INVOICE_DISTRIBUTION_ID%TYPE
10859 ) RETURN BOOLEAN IS
10860   l_dummy varchar2(1);
10861 BEGIN
10862   SELECT NULL
10863     INTO l_dummy
10864     FROM ap_invoice_distributions_all dist
10865    WHERE dist.invoice_distribution_id = p_invoice_distribution_id
10866      AND EXISTS (
10867            SELECT NULL
10868              FROM ap_invoice_distributions_all ppdist
10869             WHERE ppdist.invoice_distribution_id = dist.charge_applicable_to_dist_id
10870               AND ppdist.line_type_lookup_code = 'PREPAY'
10871          );
10872   RETURN TRUE;
10873 EXCEPTION
10874   WHEN NO_DATA_FOUND THEN
10875     RETURN FALSE;
10876 END IsRelatedToPrepayApp;
10877 /* Bug 5501250 - End */
10878 
10879 END PA_ADJUSTMENTS ;