DBA Data[Home] [Help]

PACKAGE BODY: APPS.PA_OTC_API

Source


1 Package Body Pa_Otc_Api As
2 -- $Header: PAXVOTCB.pls 120.45.12020000.6 2013/05/15 07:00:00 rboyalap ship $
3 
4     -- Package Variables
5 
6     -- Used to indicate that last index point in the pl/sql detail attribute table that was accessed.
7     G_Detail_Attr_Index             Binary_Integer := 0;
8 
9     -- Used to indicate that last index point in the pl/sql old detail attribute table that was accessed.
10     G_Old_Detail_Attr_Index         Binary_Integer := 0;
11 
12     -- Stores the Timecard Scope BB_ID and BB_OVN and is used to populate in
13     G_Orig_Exp_Txn_Reference1       Pa_Expenditures_All.Orig_Exp_Txn_Reference1%TYPE := Null;
14 
15     G_Time_BB_Id                    Hxc_Time_Building_Blocks.Time_Building_Block_Id%TYPE := Null;
16 
17     -- Used to indicate what was actually happening when unexpected error occurs.
18     G_Stage                         Varchar2(2000);
19 
20     -- Used to indentify the path taken to the point on where an unexpected error occurs.
21     G_Path                          Varchar2(2000) := ' ';
22 
23     -- These pl/sql table are used for flushing out procedure tables
24     G_Msg_Tokens_Table   Pa_Otc_Api.Message_Tokens;
25 
26     -- This pl/sql table stores a list of the expenditure_ending_dates and there associated batch_name
27     -- This pl/sql table is used during the Pre-Import phase of Trx Import
28     G_EndDateBatchName_Table Pa_Otc_Api.EndDateBatchName_Tab;
29 
30     -- Used to store the binary_index for the pl/sql table records inserted into the interface table so that can speed up
31     -- the tieback process.
32     G_Trx_Inserted_Tab     Pa_Otc_Api.Trx_Inserted_Table;
33 
34     -- Used to store the binary_index for pl/sql table records that were directly updated.  This is so that can speed up
35     -- the tieback process.
36     G_Trx_Direct_Upd_Tab   Pa_Otc_Api.Trx_Inserted_Table;
37 
38     -- Used as a check flag for the looping that is now been added in Trx Import for OTL.  The flag is used within
39     -- the exception handler for Upload_Otc_Timecard() procedure.
40     G_Processed_Import_Batch	   Boolean := Null;
41 
42     -- Global arrays for bulk insert into Trx Interface table
43     G_Txn_Interface_Id_Tbl 		Pa_Txn_Interface_Items_Pkg.Txn_Interface_Id_Typ;
44     G_Transaction_Source_Tbl 		Pa_Txn_Interface_Items_Pkg.Transaction_Source_Typ;
45     G_User_Transaction_Source_Tbl 	Pa_Txn_Interface_Items_Pkg.User_Transaction_Source_Typ;
46     G_Batch_Name_Tbl 			Pa_Txn_Interface_Items_Pkg.Batch_Name_Typ;
47     G_Expenditure_End_Date_Tbl 		Pa_Txn_Interface_Items_Pkg.Expenditure_End_Date_Typ;
48     G_Person_Bus_Grp_Name_Tbl 		Pa_Txn_Interface_Items_Pkg.Person_Business_Group_Name_Typ;
49     G_Person_Bus_Grp_Id_Tbl 		Pa_Txn_Interface_Items_Pkg.Person_Business_Group_Id_Typ;
50     G_Employee_Number_Tbl 		Pa_Txn_Interface_Items_Pkg.Employee_Number_Typ;
51     G_Person_Id_Tbl 			Pa_Txn_Interface_Items_Pkg.Person_Id_Typ;
52     G_Organization_Name_Tbl 		Pa_Txn_Interface_Items_Pkg.Organization_Name_Typ;
53     G_Organization_Id_Tbl 		Pa_Txn_Interface_Items_Pkg.Organization_Id_Typ;
54     G_Expenditure_Item_Date_Tbl 	Pa_Txn_Interface_Items_Pkg.Expenditure_Item_Date_Typ;
55     G_Project_Number_Tbl 		Pa_Txn_Interface_Items_Pkg.Project_Number_Typ;
56     G_Project_Id_Tbl 			Pa_Txn_Interface_Items_Pkg.Project_Id_Typ;
57     G_Task_Number_Tbl 			Pa_Txn_Interface_Items_Pkg.Task_Number_Typ;
58     G_Task_Id_Tbl 			Pa_Txn_Interface_Items_Pkg.Task_Id_Typ;
59     G_Expenditure_Type_Tbl 		Pa_Txn_Interface_Items_Pkg.Expenditure_Type_Typ;
60     G_System_Linkage_Tbl 		Pa_Txn_Interface_Items_Pkg.System_Linkage_Typ;
61     G_Non_Labor_Resource_Tbl 		Pa_Txn_Interface_Items_Pkg.Non_Labor_Resource_Typ;
62     G_Non_Labor_Res_Org_Name_Tbl 	Pa_Txn_Interface_Items_Pkg.Non_Labor_Res_Org_Name_Typ;
63     G_Non_Labor_Res_Org_Id_Tbl 		Pa_Txn_Interface_Items_Pkg.Non_Labor_Res_Org_Id_Typ;
64     G_Quantity_Tbl	 		Pa_Txn_Interface_Items_Pkg.Quantity_Typ;
65     G_Raw_Cost_Tbl 			Pa_Txn_Interface_Items_Pkg.Raw_Cost_Typ;
66     G_Raw_Cost_Rate_Tbl 		Pa_Txn_Interface_Items_Pkg.Raw_Cost_Rate_Typ;
67     G_Burden_Cost_Tbl 			Pa_Txn_Interface_Items_Pkg.Burden_Cost_Typ;
68     G_Burden_Cost_Rate_Tbl 		Pa_Txn_Interface_Items_Pkg.Burden_Cost_Rate_Typ;
69     G_Expenditure_Comment_Tbl 		Pa_Txn_Interface_Items_Pkg.Expenditure_Comment_Typ;
70     G_Gl_Date_Tbl 			Pa_Txn_Interface_Items_Pkg.Gl_Date_Typ;
71     G_Transaction_Status_Code_Tbl 	Pa_Txn_Interface_Items_Pkg.Transaction_Status_Code_Typ;
72     G_Trans_Rejection_Code_Tbl 		Pa_Txn_Interface_Items_Pkg.Transaction_Rejection_Code_Typ;
73     G_Orig_Trans_Reference_Tbl 		Pa_Txn_Interface_Items_Pkg.Orig_Transaction_Reference_Typ;
74     G_Unmatched_Neg_Txn_Flag_Tbl 	Pa_Txn_Interface_Items_Pkg.Unmatched_Neg_Txn_Flag_Typ;
75     G_Expenditure_Id_Tbl 		Pa_Txn_Interface_Items_Pkg.Expenditure_Id_Typ;
76     G_Attribute_Category_Tbl 		Pa_Txn_Interface_Items_Pkg.Attribute_Category_Typ;
77     G_Attribute1_Tbl 			Pa_Txn_Interface_Items_Pkg.Attribute1_Typ;
78     G_Attribute2_Tbl 			Pa_Txn_Interface_Items_Pkg.Attribute2_Typ;
79     G_Attribute3_Tbl 			Pa_Txn_Interface_Items_Pkg.Attribute3_Typ;
80     G_Attribute4_Tbl 			Pa_Txn_Interface_Items_Pkg.Attribute4_Typ;
81     G_Attribute5_Tbl 			Pa_Txn_Interface_Items_Pkg.Attribute5_Typ;
82     G_Attribute6_Tbl 			Pa_Txn_Interface_Items_Pkg.Attribute6_Typ;
83     G_Attribute7_Tbl 			Pa_Txn_Interface_Items_Pkg.Attribute7_Typ;
84     G_Attribute8_Tbl 			Pa_Txn_Interface_Items_Pkg.Attribute8_Typ;
85     G_Attribute9_Tbl 			Pa_Txn_Interface_Items_Pkg.Attribute9_Typ;
86     G_Attribute10_Tbl 			Pa_Txn_Interface_Items_Pkg.Attribute10_Typ;
87     G_Dr_Code_Combination_Id_Tbl 	Pa_Txn_Interface_Items_Pkg.Dr_Code_Combination_Id_Typ;
88     G_Cr_Code_Combination_Id_Tbl 	Pa_Txn_Interface_Items_Pkg.Cr_Code_Combination_Id_Typ;
89     G_Cdl_System_Reference1_Tbl 	Pa_Txn_Interface_Items_Pkg.Cdl_System_Reference1_Typ;
90     G_Cdl_System_Reference2_Tbl 	Pa_Txn_Interface_Items_Pkg.Cdl_System_Reference2_Typ;
91     G_Cdl_System_Reference3_Tbl 	Pa_Txn_Interface_Items_Pkg.Cdl_System_Reference3_Typ;
92     G_Interface_Id_Tbl 			Pa_Txn_Interface_Items_Pkg.Interface_Id_Typ;
93     G_Receipt_Currency_Amount_Tbl 	Pa_Txn_Interface_Items_Pkg.Receipt_Currency_Amount_Typ;
94     G_Receipt_Currency_Code_Tbl 	Pa_Txn_Interface_Items_Pkg.Receipt_Currency_Code_Typ;
95     G_Receipt_Exchange_Rate_Tbl 	Pa_Txn_Interface_Items_Pkg.Receipt_Exchange_Rate_Typ;
96     G_Denom_Currency_Code_Tbl 		Pa_Txn_Interface_Items_Pkg.Denom_Currency_Code_Typ;
97     G_Denom_Raw_Cost_Tbl 		Pa_Txn_Interface_Items_Pkg.Denom_Raw_Cost_Typ;
98     G_Denom_Burdened_Cost_Tbl 		Pa_Txn_Interface_Items_Pkg.Denom_Burdened_Cost_Typ;
99     G_Acct_Rate_Date_Tbl 		Pa_Txn_Interface_Items_Pkg.Acct_Rate_Date_Typ;
100     G_Acct_Rate_Type_Tbl 		Pa_Txn_Interface_Items_Pkg.Acct_Rate_Type_Typ;
101     G_Acct_Exchange_Rate_Tbl 		Pa_Txn_Interface_Items_Pkg.Acct_Exchange_Rate_Typ;
102     G_Acct_Raw_Cost_Tbl 		Pa_Txn_Interface_Items_Pkg.Acct_Raw_Cost_Typ;
103     G_Acct_Burdened_Cost_Tbl 		Pa_Txn_Interface_Items_Pkg.Acct_Burdened_Cost_Typ;
104     G_Acct_Exch_Rounding_Limit_Tbl 	Pa_Txn_Interface_Items_Pkg.Acct_Exch_Rounding_Limit_Typ;
105     G_Project_Currency_Code_Tbl 	Pa_Txn_Interface_Items_Pkg.Project_Currency_Code_Typ;
106     G_Project_Rate_Date_Tbl 		Pa_Txn_Interface_Items_Pkg.Project_Rate_Date_Typ;
107     G_Project_Rate_Type_Tbl 		Pa_Txn_Interface_Items_Pkg.Project_Rate_Type_Typ;
108     G_Project_Exchange_Rate_Tbl 	Pa_Txn_Interface_Items_Pkg.Project_Exchange_Rate_Typ;
109     G_Orig_Exp_Txn_Reference1_Tbl 	Pa_Txn_Interface_Items_Pkg.Orig_Exp_Txn_Reference1_Typ;
110     G_Orig_Exp_Txn_Reference2_Tbl 	Pa_Txn_Interface_Items_Pkg.Orig_Exp_Txn_Reference2_Typ;
111     G_Orig_Exp_Txn_Reference3_Tbl 	Pa_Txn_Interface_Items_Pkg.Orig_Exp_Txn_Reference3_Typ;
112     G_Orig_User_Exp_Txn_Ref_Tbl 	Pa_Txn_Interface_Items_Pkg.Orig_User_Exp_Txn_Ref_Typ;
113     G_Vendor_Number_Tbl 		Pa_Txn_Interface_Items_Pkg.Vendor_Number_Typ;
114     G_Vendor_Id_Tbl 			Pa_Txn_Interface_Items_Pkg.Vendor_Id_Typ;
115     G_Override_To_Org_Name_Tbl 		Pa_Txn_Interface_Items_Pkg.Override_To_Org_Name_Typ;
116     G_Override_To_Org_Id_Tbl 		Pa_Txn_Interface_Items_Pkg.Override_To_Org_Id_Typ;
117     G_Reversed_Orig_Txn_Ref_Tbl 	Pa_Txn_Interface_Items_Pkg.Reversed_Orig_Txn_Ref_Typ;
118     G_Billable_Flag_Tbl 		Pa_Txn_Interface_Items_Pkg.Billable_Flag_Typ;
119     G_ProjFunc_Currency_Code_Tbl 	Pa_Txn_Interface_Items_Pkg.ProjFunc_Currency_Code_Typ;
120     G_ProjFunc_Cost_Rate_Date_Tbl 	Pa_Txn_Interface_Items_Pkg.ProjFunc_Cost_Rate_Date_Typ;
121     G_ProjFunc_Cost_Rate_Type_Tbl 	Pa_Txn_Interface_Items_Pkg.ProjFunc_Cost_Rate_Type_Typ;
122     G_ProjFunc_Cost_Exch_Rate_Tbl 	Pa_Txn_Interface_Items_Pkg.ProjFunc_Cost_Exch_Rate_Typ;
123     G_Project_Raw_Cost_Tbl 		Pa_Txn_Interface_Items_Pkg.Project_Raw_Cost_Typ;
124     G_Project_Burdened_Cost_Tbl 	Pa_Txn_Interface_Items_Pkg.Project_Burdened_Cost_Typ;
125     G_Assignment_Name_Tbl 		Pa_Txn_Interface_Items_Pkg.Assignment_Name_Typ;
126     G_Assignment_Id_Tbl 		Pa_Txn_Interface_Items_Pkg.Assignment_Id_Typ;
127     G_Work_Type_Name_Tbl 		Pa_Txn_Interface_Items_Pkg.Work_Type_Name_Typ;
128     G_Work_Type_Id_Tbl 			Pa_Txn_Interface_Items_Pkg.Work_Type_Id_Typ;
129     G_Cdl_System_Reference4_Tbl 	Pa_Txn_Interface_Items_Pkg.Cdl_System_Reference4_Typ;
130     G_Accrual_Flag_Tbl 			Pa_Txn_Interface_Items_Pkg.Accrual_Flag_Typ;
131     G_Last_Update_Date_Tbl		Pa_Txn_Interface_Items_Pkg.Last_Update_Date_Typ;
132     G_Last_Updated_By_Tbl		Pa_Txn_Interface_Items_Pkg.Last_Updated_By_Typ;
133     G_Creation_Date_Tbl			Pa_Txn_Interface_Items_Pkg.Creation_Date_Typ;
134     G_Created_By_Tbl			Pa_Txn_Interface_Items_Pkg.Created_By_Typ;
135     -- PA.M/CWK changes
136     G_PO_Number_Tbl			Pa_Txn_Interface_Items_Pkg.PO_Number_Typ;
137     G_PO_Header_Id_Tbl			Pa_Txn_Interface_Items_Pkg.PO_Header_Id_Typ;
138     G_PO_Line_Num_Tbl			Pa_Txn_Interface_Items_Pkg.PO_Line_Num_Typ;
139     G_PO_Line_Id_Tbl                    Pa_Txn_Interface_Items_Pkg.PO_Line_Id_Typ;
140     G_PO_Price_Type_Tbl                 Pa_Txn_Interface_Items_Pkg.PO_Price_Type_Typ;
141     G_Person_Type_Tbl			Pa_Txn_Interface_Items_Pkg.Person_Type_Typ;
142     -- Other PA.M changes
143     G_Inventory_Item_Id_Tbl             Pa_Txn_Interface_Items_Pkg.Inventory_Item_Id_Typ;
144     G_WIP_Resource_Id_Tbl		Pa_Txn_Interface_Items_Pkg.WIP_Resource_Id_Typ;
145     G_Unit_Of_Measure_Tbl		Pa_Txn_Interface_Items_Pkg.Unit_Of_Measure_Typ;
146 
147     -- 10253400: Payroll integration enhancement for 12.2..start
148     G_JOB_ID_TBL                Pa_Txn_Interface_Items_Pkg.Job_Id_Typ;
149     G_JOB_NAME_TBL              Pa_Txn_Interface_Items_Pkg.Job_Name_Typ;
150     G_Location_Id_Tbl           Pa_Txn_Interface_Items_Pkg.Location_Id_Typ;
151     G_Location_Code_Tbl         Pa_Txn_Interface_Items_Pkg.Location_Code_Typ;
152     G_Pay_Element_Type_Id_Tbl   Pa_Txn_Interface_Items_Pkg.Pay_Element_Type_Id_Typ;
153     -- 10253400: Payroll integration enhancement for 12.2..end
154 
155 	-- Start: Added for CBS Enhancement Bug 16220146
156 	G_Cbs_Element_Id_Tbl        Pa_Txn_Interface_Items_Pkg.Cbs_Element_Id_Typ;
157 	G_Cbs_Element_Name_Tbl      Pa_Txn_Interface_Items_Pkg.Cbs_Element_Name_Typ;
158 	-- End: Added for CBS Enhancement Bug 16220146
159 
160     G_Trx_Import_Index			Binary_Integer := 0;
161 
162     -- Used as a counter to bulk insert.
163     G_Txn_Rec_Count                     Number         := Null;
164 
165     -- Handling unhandled exceptions
166     G_EXCEPT_CNT_ALLOWED		Number         := to_Number(Nvl(Fnd_Profile.Value('HXC_RETRIEVAL_MAX_ERRORS'),0));
167     G_Unhandled_Except_Cnt		Number;
168 
169     G_BAD_OTL_DATA                      Exception;
170     HXC_RETRIEVAL_MAX_ERRORS            Exception;
171 
172     G_Debug_Mode                        Varchar2(1)    := Nvl(Fnd_Profile.Value('PA_DEBUG_MODE'), 'N');
173 
174     -- Begin PA.M/CWK changes
175     G_Po_Line_Id			Number         := Null;
176     G_Vendor_Id				Number         := Null;
177     G_PO_Header_Id			Number         := Null;
178     -- End PA.M/CWK changes
179 
180     -- Added to support performance change in OTL, when creating billable flag record
181     G_Billable_Segment                  HXC_MAPPING_COMPONENTS.SEGMENT%TYPE;
182 
183     /* Added  Variable for  bug 11711383 */
184     G_Delete_op                       Varchar2(10)    :='N';
185     G_Delete_Change                   Varchar2(10)    :='N';
186     G_Detail_Change                   Varchar2(10)    :='N';
187 
188     -- 12i changes
189     G_OU_Tbl                        Pa_Txn_Interface_Items_Pkg.OU_Id_Typ;
190     G_Current_Org_Id                Number := Pa_Moac_Utils.Get_Current_Org_Id;
191 
192 -- =======================================================================
193 -- Start of Comments
194 -- API Name      : TrackPath
195 -- Type          : Private
196 -- Pre-Reqs      : None
197 -- Type          : Procedure
198 -- Function      : This procedure tracks the path thru the code to attach to error messages.
199 --
200 --  Parameters:
201 --
202 --  IN
203 --    P_Function     -  Varchar2  -- ADD or STRIP
204 --    P_Value        -  Varchar2
205 --
206 
207 /*-------------------------------------------------------------------------*/
208 
209    Procedure TrackPath (
210         P_Function IN Varchar2,
211         P_Value    IN Varchar2)
212 
213    Is
214 
215 	l_Value Varchar2(2000) := '->' || P_Value;
216 
217    Begin
218 
219 	G_Stage := 'Entering procedure TrackPath().';
220 
221 	If P_Function = 'ADD' Then
222 
223 		G_Stage := 'TrackPath(): Adding to G_Path.';
224 		G_Path := G_Path || l_Value;
225 
226 	ElsIf P_Function = 'STRIP' Then
227 
228 		G_Stage := 'TrackPath(): Stripping from G_Path.';
229 		G_Path := Substr(G_Path,1,Instr(G_Path,l_Value) - 1);
230 
231 	End If;
232 
233 	G_Stage := 'Leaving procedure TrackPath().';
234 
235    Exception
236 	When Others Then
237 		Raise;
238 
239    End TrackPath;
240 
241 
242 -- =======================================================================
243 -- Start of Comments
244 -- API Name      : Add_Error_To_Table
245 -- Type          : Private
246 -- Pre-Reqs      : None
247 -- Type          : Procedure
248 -- Function      : This procedure populates the error table for any expected errors.
249 --
250 --  Parameters:
251 --
252 --  IN
253 --    P_Message_Table           - Hxc_User_Type_Definition_Grp.Message_Table%TYPE
254 --    P_Message_Name            - Fnd_New_Messages.Message_Name%TYPE
255 --    P_Message_Level           - Varchar2
256 --    P_Message_Field           - Varchar2
257 --    P_Msg_Tokens              - Pa_Otc_Api.Messages_Tokens
258 --    P_Time_Building_Block_Id  - Hxc_Time_Building_Blocks.Time_Building_Block_Id%TYPE
259 --    P_Time_Attribute_Id       - Hxc_Time_Attributes.Time_Attribute_Id%TYPE
260 --    P_Message_App             - Varchar2 Default 'PA'
261 --
262 -- OUT
263 --    P_Message_Table           - Hxc_User_Type_Definition_Grp.Message_Table%TYPE
264 --
265 
266 /*-------------------------------------------------------------------------*/
267 
268     Procedure Add_Error_To_Table(
269           P_Message_Table           IN OUT NOCOPY Hxc_User_Type_Definition_Grp.Message_Table, -- 2672653
270           P_Message_Name            IN            Fnd_New_Messages.Message_Name%TYPE,
271           P_Message_Level           IN            Varchar2,
272           P_Message_Field           IN            Varchar2,
273 		  P_Msg_Tokens              IN            Pa_Otc_Api.Message_Tokens,
274           P_Time_Building_Block_Id  IN            Hxc_Time_Building_Blocks.Time_Building_Block_Id%TYPE,
275           P_Time_Attribute_Id       IN            Hxc_Time_Attributes.Time_Attribute_Id%TYPE,
276 		  P_Message_App             IN            Varchar2 )
277 
278     Is
279 
280         l_Last_Index Number         := P_Message_Table.Last;
281 	    l_Tokens     Varchar2(2000) := Null;
282 
283     Begin
284 
285 	    G_Stage := 'Entering Add_Error_To_Table().';
286         Pa_Otc_Api.TrackPath('ADD','Add_Error_To_Table');
287 
288 	    G_Stage := 'Determine Error token count.';
289 	    If P_Msg_Tokens.Count > 0 Then
290 
291  		    G_Stage := 'Get token data if it exists.';
292         	For i in P_Msg_Tokens.First .. P_Msg_Tokens.Last
293         	Loop
294 
295 			If l_Tokens is Null Then
296 
297 				G_Stage := 'Concatenate the token name and token value 1.';
298         		l_Tokens := P_Msg_Tokens(i).Token_Name || '&' || P_Msg_Tokens(i).Token_Value;
299 
300 			Else
301 
302 				G_Stage := 'Concatenate the token name and token value 2.';
303                 -- Added appending for l_Tokens for bug 4593869
304                 l_Tokens := l_Tokens || '&' || P_Msg_Tokens(i).Token_Name || '&' || P_Msg_Tokens(i).Token_Value;
305 
306 			End If;
307 
308         	End Loop;
309 
310 	    End If;
311 
312 	    G_Stage := 'Get next available index for error table.';
313 	    l_Last_Index := Nvl(l_Last_Index,0) + 1;
314 
315 	    G_Stage := 'Assign message name to error table record.';
316 	    P_Message_Table(l_last_index).Message_Name := P_Message_Name;
317 
318 	    G_Stage := 'Assign message level to error table record.';
319         P_Message_Table(l_last_index).Message_Level := P_Message_Level;
320 
321 	    G_Stage := 'Assign message field to error table record.';
322         P_Message_Table(l_last_index).Message_Field := P_Message_Field;
323 
324 	    G_Stage := 'Assign application short name to error table record.';
325 	    P_Message_Table(l_last_index).Application_Short_Name := P_Message_App;
326 
327 	    G_Stage := 'Assign token string to error table record.';
328 	    P_Message_Table(l_last_index).Message_Tokens := l_Tokens;
329 
330 	    G_Stage := 'Assign Time Building Block Id to error table record.';
331         P_Message_Table(l_last_index).Time_Building_Block_Id := P_Time_Building_Block_Id;
332 
333 	    G_Stage := 'Assign Time Attribute Id to error table record.';
334         P_Message_Table(l_last_index).Time_Attribute_Id := P_Time_Attribute_Id;
335 
336         G_Stage := 'Leaving Add_Error_To_Table() procedure.';
337         Pa_Otc_Api.TrackPath('STRIP','Add_Error_To_Table');
338 
339     Exception
340 	    When Others Then
341 		    Raise;
342 
343     End Add_Error_To_Table;
344 
345 
346 
347 --  ****   TRX IMPORT PROCEDURES AND FUNCTIONS ****
348 
349 -- =======================================================================
350 -- Start of Comments
351 -- API Name      : Upload_Otc_Timecards
352 -- Type          : Public
353 -- Pre-Reqs      : None
354 -- Type          : Procedure
355 -- Function      : This procedure is used to pull approved self service
356 --                 timecards into transaction interface table.  This is an
357 --                 entry point procedure for the pre_import extension call
358 --                 from Trx Import.
359 -- Parameters    :
360 -- IN
361 --           P_Transaction_Source: Unique identifier for source of the txn
362 --           P_Batch: Batch Name to group txns into batches
363 --           P_Xface_Id: Interface Id
364 --           P_User_Id: User Id
365 
366 /*--------------------------------------------------------------------------*/
367 
368    Procedure Upload_Otc_Timecards(P_Transaction_Source IN Pa_Transaction_Interface_All.Transaction_Source%TYPE,
369                                   P_Batch              IN Pa_Transaction_Interface_All.Batch_Name%TYPE,
370                                   P_Xface_Id           IN Pa_Transaction_Interface_All.Txn_Interface_Id%TYPE,
371                                   P_User_Id            IN NUMBER) IS
372 
373      l_Txn_Rowid            RowId := Null;
374      l_Txn_Xface_Id         Pa_Transaction_Interface_All.Txn_Interface_Id%TYPE := NULL;
375      l_Where_Clause         Varchar2(2000);
376      l_Batch_Name           Pa_Transaction_Interface_All.Batch_Name%TYPE;
377      l_Override_Approver_Id Pa_Expenditures_All.Overriding_Approver_Person_Id%TYPE;
378      l_New_Orig_Trx_Ref     Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE;
379      l_Old_Orig_Trx_Ref     Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE;
380      l_Insert_Rec_Flag      Boolean := False;
381      l_Org_Id               Hr_All_Organization_Units.Organization_Id%TYPE := NULL;
382      l_Direct_Update_Flag   Boolean := True; /* changed for bug 13831042 */
383      l_Comment_Or_Dff       Varchar2(3); -- bug 12650576. increased to 3.
384      l_Comment              Varchar2(150);
385      l_New_Timecard_Rec     Pa_Otc_Api.Timecard_Rec;
386      l_Old_Timecard_Rec     Pa_Otc_Api.Timecard_Rec;
387      l_Temp_Timecard_Rec    Pa_Otc_Api.Timecard_Rec := NULL;
388      l_Old_Detail_Index     Binary_Integer := 0;
389      l_Error_Code           Varchar2(30) := NULL;
390      l_dummy                Number := NULL;
391      l_Error_Text           Varchar2(2000);
392 
393      -- Maximum number of eis to be bulkinserted that is allowed
394      L_MAX_RECS_FOR_BULKINSERT          Number := 1000;
395      l_ac_termination_date   per_periods_of_service.actual_termination_date%type;  /* Bug 6698171 */
396 
397      Function GetVendorId(P_Po_Line_Id in Number) RETURN Number
398 
399      Is
400 
401 	    X_Vendor_Id Number := Null;
402 
403      Begin
404 
405 	    If Nvl(G_Po_Line_Id,-9999999) <> P_Po_Line_Id Then
406 
407 		    Select
408 			    h.Vendor_Id
409 		    Into
410 			    X_Vendor_Id
411 		    from
412 			    PO_Headers_All h,
413 		     	PO_Lines_All l
414 		    where
415 			    l.po_line_Id = P_Po_Line_Id
416 		    and	l.po_header_id = h.po_header_Id;
417 
418 		    G_Po_Line_Id := P_Po_Line_Id;
419 		    G_Vendor_Id  := G_Vendor_Id;
420 
421 	    End If;
422 
423 	    Return G_Vendor_Id;
424 
425     Exception
426 	    When Others Then
427 		     Return Null;
428 
429    End GetVendorId;
430 
431    Begin
432 
433      G_Path := ' ';
434 
435      G_Stage := 'Entering Upload_Otc_Timecard(), add procedure to trackpath.';
436      If G_Debug_Mode = 'Y' Then
437 	    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
438         pa_cc_utils.log_message( Pa_Debug.G_Err_Stage,1);
439      End If;
440      Pa_Otc_Api.TrackPath('ADD','Upload_Otc_Timecards');
441 
442      If G_Processed_Import_Batch is Null Then
443 
444         G_Stage := 'Single time process initialization section needed.';
445 	    If G_Debug_Mode = 'Y' Then
446 	       Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
447 	       pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
448 	    End If;
449 
450 	    G_Stage := 'Call BulkInsertReset() procedure for reset.';
451 	    If G_Debug_Mode = 'Y' Then
452            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
453            Pa_Cc_Utils.Log_Message(Pa_Debug.G_Err_Stage,0);
454         End If;
455         Pa_Otc_Api.BulkInsertReset(P_Command => 'RESET');
456 
457 	    G_Stage := 'Initialize what remains.';
458         If G_Debug_Mode = 'Y' Then
459            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
460            Pa_Cc_Utils.Log_Message(Pa_Debug.G_Err_Stage,0);
461         End If;
462         G_Processed_Import_Batch := FALSE;
463         G_EndDateBatchName_Table.Delete;
464 	    G_Unhandled_Except_Cnt := 0;
465 
466      End If;
467 
468      G_Stage := 'Each time Upload_Otc_Timecards() called initializaion of global variables.';
469      If G_Debug_Mode = 'Y' Then
470         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
471         pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
472      End If;
473 
474      G_Old_Detail_Attr_Index := 0;
475      G_Detail_Attr_Index := 0;
476      G_Trx_Inserted_Tab.Delete;
477      G_Trx_Direct_Upd_Tab.Delete;
478      G_Trx_Import_Index := 0;
479      Pa_Trx_Import.G_Batch_Size := 0;
480 
481      -- PA.M/CWK changes
482      G_Po_Line_Id := Null;
483      G_Vendor_Id := Null;
484      G_PO_Header_Id := Null;
485 
486      /* Where clause must restrict the retrieval to the current
487       * operating unit if Multi-Org is Implemented for Projects.
488       */
489      If Pa_Utils.Pa_Morg_Implemented = 'Y' Then
490 
491 	    G_Stage := 'Create where clause.';
492       	If G_Debug_Mode = 'Y' Then
493            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
494       	   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
495       	End If;
496 
497         -- 12i MOAC changes
498 	    -- l_Where_Clause := '[ORG_ID] { = ''' || to_Char(to_Number(SubStr(UserEnv('CLIENT_INFO'),1,10))) ||  ''' }';
499         l_Where_Clause := '[ORG_ID] { = ''' || to_Char(G_Current_Org_Id) ||  ''' }';
500 
501      Else
502 
503 	    G_Stage := 'No where clause.';
504         If G_Debug_Mode = 'Y' Then
505 	       Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
506            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
507         End If;
508 
509 	    l_Where_Clause := NULL;
510 
511      End If;
512 
513      /* Pull the data into the OTL pl/sql tables.
514       *
515       * PL/SQL tables to work with once the procedure execute_retrieval_process is done:
516       *      Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks             Using
517       *      Hxc_User_Type_Definition_Grp.T_Old_Detail_Bld_Blks         Using
518       *      Hxc_User_Type_Definition_Grp.T_Detail_Attributes           Using
519       *      Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes       Using
520       *      Hxc_User_Type_Definition_Grp.T_Day_Bld_Blks                Using for ei date retrieval
521       *      Hxc_User_Type_Definition_Grp.T_Old_Day_Bld_Blks            Using for ei date retrieval
522       *      Hxc_User_Type_Definition_Grp.T_Day_Attributes              Not Using
523       *      Hxc_User_Type_Definition_Grp.T_Old_Day_Attributes          Not Using
524       *      Hxc_User_Type_Definition_Grp.T_Time_Bld_Blks               Not Using
525       *      Hxc_User_Type_Definition_Grp.T_Old_Time_Bld_Blks           Not Using
526       *      Hxc_User_Type_Definition_Grp.T_Time_Attributes             Not Using
527       *      Hxc_User_Type_Definition_Grp.T_Old_Time_Attributes         Not Using
528       *      Hxc_User_Type_Definition_Grp.T_Tx_Detail_Status            Using
529       *      Hxc_User_Type_Definition_Grp.T_Tx_Detail_Exception         Using
530       */
531 
532      G_Stage := 'Call execute retrieval process API.';
533      If G_Debug_Mode = 'Y' Then
534         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
535         pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
536      End If;
537      Hxc_Integration_Layer_V1_Grp.Execute_Retrieval_Process(
538 		P_Process	   => 'Projects Retrieval Process',
539 		P_Transaction_code => Null,
540 		P_Start_Date 	   => Null,
541 		P_End_Date 	   => Null,
542 		P_Incremental 	   => 'Y',
543 		P_Rerun_Flag 	   => 'N',
544 		P_Where_Clause 	   => l_Where_Clause,
545 		P_Scope 	   => 'DAY',
546 		P_Clusive 	   => 'EX');
547 
548      If Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks.COUNT > 0 Then
549 
550 	      Pa_Trx_Import.G_Exit_Main := FALSE;
551 
552 	      G_Stage := 'Loop thru all hxc detail building block records.';
553 	      If G_Debug_Mode = 'Y' Then
554 	           Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
555 	           pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
556 	      End If;
557 	      For i IN Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks.First .. Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks.Last
558 	      Loop
559 
560 	           G_Stage := 'Process bb/ovn: ' || to_char(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id) || ':' ||
561 			              to_char(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).Ovn) ||
562 		                  ' for Resource_Id(Person_Id): ' || to_char(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).Resource_Id);
563                Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
564                pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,1);
565 
566                Begin
567 
568 		            G_Stage := 'Primary condition evaluation within the loop.';
569                     If G_Debug_Mode = 'Y' Then
570                          Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
571                          pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
572                     End If;
573 
574 		            If Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).Changed = 'N' and
575 		               Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).Deleted = 'Y' Then
576 
577 			             G_Stage := 'Item Changed: N, Deleted: Y.';
578 			             Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
579 			             pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,1);
580 
581 
582 			             -- Even though the building block was deleted prior to being imported into projects
583                          -- appearantly attribution data is created and sent via the Generic retrieval process
584                          -- via the Generic retrieval process.  Need to sequence thru to position
585                          -- the global index variable for the next bb to process.
586                          -- Since it was deleted means it does not need to be imported into projects.
587 			             -- There is also no need to look at the old pl/sql tables records.
588 
589 			            G_Stage := 'Call Populate Project Record new 1 for positioning purposes only.';
590                         If G_Debug_Mode = 'Y' Then
591                            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
592                            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
593                         End If;
594 
595                         Pa_Otc_Api.PopulateProjRec(
596                                 P_New_Old_BB   => 'NEW',
597                                 P_BB_Id        => Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id,
598                                 P_Detail_Index => i,
599                                 P_Old_Detl_Ind => l_Old_Detail_Index,
600                                 P_Timecard_Rec => l_New_Timecard_Rec);
601 
602                        	Hxc_User_Type_Definition_Grp.T_Tx_Detail_Status(i) := 'SUCCESS';
603 
604 			            l_insert_rec_flag := FALSE;
605 
606 		            ElsIf Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).Changed = 'N' and
607 		                  Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).Deleted = 'N' Then
608 
609 			             -- If this is the condition then there is only new data to process via PopulateProjRec() procedure
610 			             -- and there is no need to look at the old data via the same procedure.
611 
612 			             G_Stage := 'Item Changed: N, Deleted: N.';
613 			             Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
614 			             pa_cc_Utils.log_message(Pa_Debug.G_Err_Stage,1);
615 
616 			             G_Stage := 'Call Populate Project Record new 2.';
617 		                 If G_Debug_Mode = 'Y' Then
618 		                      Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
619 		                      pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
620 		                 End If;
621 
622 			             Pa_Otc_Api.PopulateProjRec(
623                               P_New_Old_BB   => 'NEW',
624 				              P_BB_Id        => Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id,
625 				              P_Detail_Index => i,
626 				              P_Old_Detl_Ind => l_Old_Detail_Index,
627                               P_Timecard_Rec => l_New_Timecard_Rec);
628 
629 			             G_Stage := 'EI data status check 2.';
630                          If G_Debug_Mode = 'Y' Then
631                              Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
632                              pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
633                          End If;
634 
635 			             If l_New_Timecard_Rec.Status is Not Null Then
636 
637 				              G_Stage := 'New Record Status is not null 2. Timecard status is ' || l_New_Timecard_Rec.Status;
638 				              If G_Debug_Mode = 'Y' Then
639 				                   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
640 				                   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
641 				              End If;
642 
643 				              Hxc_User_Type_Definition_Grp.T_Tx_Detail_Status(i) := 'ERRORS';
644 				              Hxc_User_Type_Definition_Grp.T_Tx_Detail_Exception(i) := l_New_Timecard_Rec.Status;
645 				              l_insert_rec_flag := FALSE;
646 
647 			             Else
648 
649 				               G_Stage := 'Create new orig trx ref 2.';
650                                If G_Debug_Mode = 'Y' Then
651                                     Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
652                                     pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
653                                End If;
654 
655                                l_new_orig_trx_ref :=
656                                         to_char(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id) || ':' ||
657                                         to_char(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).Ovn);
658 
659 				               G_Stage := 'Check if original transaction reference already exists 2';
660                                If G_Debug_Mode = 'Y' Then
661                                     Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
662                                     pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
663                                End If;
664 
665 				               -- Calling the function is a sanity check to confirm that this is solely new data.
666 				               If NOT Pa_Otc_Api.OrigTrxRefValueExists(l_new_orig_trx_ref) Then
667 
668 	                                -- Insert a new record.  There should be no records in either
669 	                        	    -- pl/sql tables t_old_detail_bld_blks or t_old_detail_attributes
670 	                        	    -- for this building block id.
671 	                        	    --
672 
673 	                        	    l_insert_rec_flag := TRUE;
674 
675 					                G_Stage := 'Call the GetBatchName procedure 2';
676 	                        	    If G_Debug_Mode = 'Y' Then
677 	                        	         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
678 	                        	         pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
679 	                        	    End If;
680 
681 					                Pa_Otc_Api.GetBatchName(
682 							             P_Exp_End_Date => l_New_Timecard_Rec.Expenditure_Ending_Date,
683 					        	         X_Batch_Name   => l_Batch_Name);
684 
685 				               Else
686 					                -- This condition result should never happen, but it's here just in case.
687 
688 					                G_Stage := 'Building block/ovn combo already exists in projects 2.';
689                                     If G_Debug_Mode = 'Y' Then
690                                          Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
691                                          pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
692                                     End If;
693 					                l_insert_rec_flag := FALSE;
694 					                Hxc_User_Type_Definition_Grp.T_Tx_Detail_Status(i) := 'SUCCESS';
695 
696 				               End If;
697 
698 			             End If;
699 
700 		            ElsIf Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).Changed = 'Y' and
701                           Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).Deleted = 'N' Then
702 
703 			             G_Stage := 'Item Changed: Y, Deleted: N.';
704 			             Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
705 			             pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
706 
707 			             l_Old_Detail_Index := l_Old_Detail_Index + 1;
708 
709 			             G_Stage := 'Create new orig trx ref 3.';
710         		         If G_Debug_Mode = 'Y' Then
711         		              Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
712         		              pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
713         		         End If;
714 
715 			             l_new_orig_trx_ref :=
716 			                  to_char(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id) || ':' ||
717 			                  to_char(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).Ovn);
718 
719 			             If NOT Pa_Otc_Api.OrigTrxRefValueExists(l_new_orig_trx_ref) Then
720 
721 				              G_Stage := 'Call Populate Project Record new 3a.';
722         			          If G_Debug_Mode = 'Y' Then
723         			               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
724         			               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
725         			          End If;
726 
727                         	  Pa_Otc_Api.PopulateProjRec(
728                                    P_New_Old_BB   => 'NEW',
729 					               P_BB_Id        => Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id,
730 					               P_Detail_Index => i,
731 					               P_Old_Detl_Ind => l_Old_Detail_Index,
732                                    P_timecard_Rec => l_New_Timecard_Rec);
733 
734 				              G_Stage := 'EI data status check 3a.';
735                               If G_Debug_Mode = 'Y' Then
736                                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
737                                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
738                               End If;
739 
740                         	  If l_New_Timecard_Rec.Status is Not Null Then
741 
742 					               G_Stage := 'New Record Status is not null 3a. Timecard status is ' || l_New_Timecard_Rec.Status;
743 					               If G_Debug_Mode = 'Y' Then
744 					                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
745 					                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
746 					               End If;
747 
748                                    Hxc_User_Type_Definition_Grp.T_Tx_Detail_Status(i) := 'ERRORS';
749                                    Hxc_User_Type_Definition_Grp.T_Tx_Detail_Exception(i) := l_New_Timecard_Rec.Status;
750 					               l_insert_rec_Flag := FALSE;
751 
752 					               G_Stage := 'Since the Status is not null 3a has been hit for new record, ' ||
753 						                      'call PopulateProjRec() for old records for positioning ' ||
754 						                      'purposes only to maintain sync with new pl/sql tables.';
755 					               If G_Debug_Mode = 'Y' Then
756 						                Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
757 						                pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
758 					               End If;
759 
760                                    Pa_Otc_Api.PopulateProjRec(
761                                         P_New_Old_BB   => 'OLD',
762                                         P_BB_Id        => Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).bb_id,
763                                         P_Detail_Index => i,
764                                         P_Old_Detl_Ind => l_Old_Detail_Index,
765                                         P_timecard_Rec => l_Old_Timecard_Rec);
766 
767 					               -- We don't care about the handled errors, since using only for positioning
768 					               -- purposees so we don't check the status after the call to the procedure.
769 
770 				              Else
771 
772 					               G_Stage := 'Call Populate Project Record old 3a.';
773         				           If G_Debug_Mode = 'Y' Then
774         				                Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
775         				                pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
776         				           End If;
777 
778                         		   Pa_Otc_Api.PopulateProjRec(
779                                         P_New_Old_BB   => 'OLD',
780 						                P_BB_Id        => Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).bb_id,
781 						                P_Detail_Index => i,
782 						                P_Old_Detl_Ind => l_Old_Detail_Index,
783                                 		P_timecard_Rec => l_Old_Timecard_Rec);
784 
785                                    If l_Old_Timecard_Rec.Status is Not Null Then
786 
787 						                G_Stage := 'Old Record Status is not null 3a. Timecard status is ' || l_Old_Timecard_Rec.Status;
788 						                If G_Debug_Mode = 'Y' Then
789 						                     Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
790 						                     pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
791 						                End If;
792 
793                                         Hxc_User_Type_Definition_Grp.T_Tx_Detail_Status(i) := 'ERRORS';
794                                         Hxc_User_Type_Definition_Grp.T_Tx_Detail_Exception(i) := l_Old_Timecard_Rec.Status;
795 						                l_insert_rec_Flag := FALSE;
796 
797 					               Else
798 
799 						                -- Need to find out what has changed to determine whether or not need to
800 			 			                -- insert record into pa_transaction_interface or update tables
801 			        		            -- pa_expenditure_comments and/or pa_expenditure_items_all.
802 						                G_Stage := 'Call Determine Direct Update 3.';
803         					            If G_Debug_Mode = 'Y' Then
804         					                 Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
805         					                 pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
806         					            End If;
807 
808 						                Pa_Otc_Api.DetermineDirectUpdate(
809 					      		             P_New_Timecard_Rec   => l_New_Timecard_Rec,
810 					      		             P_Old_Timecard_Rec   => l_Old_Timecard_Rec,
811 					      		             P_Direct_Update_Flag => l_direct_update_flag,
812 					      		             P_Comment_or_Dff     => l_Comment_or_Dff);
813 
814 						                If l_direct_update_flag Then
815 
816 							                 l_insert_rec_flag := FALSE;
817 
818                                              G_Stage := 'Direct Update of the exp item in projects.  '  ||
819                                                         'Need to update (C)omment, (D)ff, (B)oth: ' || l_Comment_or_Dff;
820                                              Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
821                                              pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,1);
822 
823 							                 G_Stage := 'Direct Update get trx ref. by calling GetOrigTrxRef '||
824 								                        'to use to update the expenditure item.';
825 							                 If G_Debug_Mode = 'Y' Then
826 								                  Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
827 								                  pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
828 							                 End If;
829 
830 							                 Pa_Otc_Api.GetOrigTrxRef(
831                                                   P_Building_Block_Id => Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id,
832                                                   X_OrigTrxRef        => l_old_orig_trx_ref,
833                                                   X_Status            => l_New_Timecard_Rec.Status);
834 
835 							                 If l_New_Timecard_Rec.Status is not null Then
836 
837 							                      G_Stage := 'Update hxc exception pl/sql tables 1.';
838                                                   If G_Debug_Mode = 'Y' Then
839                                                        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
840                                                        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
841                                                   End If;
842 
843 							                      Hxc_User_Type_Definition_Grp.T_Tx_Detail_Status(i) := 'ERRORS';
844                                         		  Hxc_User_Type_Definition_Grp.T_Tx_Detail_Exception(i) := l_New_Timecard_Rec.Status;
845 							                      Raise G_BAD_OTL_DATA;
846 
847 							                 End If;
848 
849 							                 G_Stage := 'Call Update Changed Original Txn 3.';
850         						             If G_Debug_Mode = 'Y' Then
851         						                  Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
852         						                  pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
853         						             End If;
854 
855 							                 Pa_Otc_Api.UpdateChangedOrigTxn(
856 				        			              P_Old_Orig_Txn_Ref => l_old_orig_trx_ref,
857                							          P_New_Orig_Txn_Ref => l_new_orig_trx_ref,
858                							          P_Comment_or_Dff   => l_comment_or_dff,
859                							          P_Timecard_Rec     => l_new_timecard_rec,
860                							          P_User_Id          => P_User_Id);
861 
862 							                 G_Stage := 'Store the Bb_Id and index in pl/sql table for use ' ||
863                                                         'in tieback process 3a for directly updated ei.';
864                                              If G_Debug_Mode = 'Y' Then
865                                                   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
866                                                   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
867                                              End If;
868 
869                                              G_Trx_Direct_Upd_Tab(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id).BB_Index := i;
870 
871 						                Else
872 
873 							                 l_insert_rec_flag := TRUE;
874 
875 							                 G_Stage := 'Call the GetBatchName procedure 3';
876                         				     If G_Debug_Mode = 'Y' Then
877                         				          Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
878                         				          pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
879                         				     End If;
880 
881                         				     Pa_Otc_Api.GetBatchName(
882 								                  P_Exp_End_Date => l_New_Timecard_Rec.Expenditure_Ending_Date,
883                                                   X_Batch_Name   => l_Batch_Name);
884 
885                         				     G_Stage := 'Get old orig trx ref 3 using the new bb_id/ovn ' || 'combo ' ||
886                                    				        to_char(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id) || ':' ||
887                                    				        to_char(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).Ovn);
888 							                 If G_Debug_Mode = 'Y' Then
889                         				          Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
890                         				          pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
891                         				     End If;
892 
893 							                 -- Bug ?
894 							                 -- Switched from function to procedure to determine if
895 							                 -- ei is available for adjustment in projects
896 							                 G_Stage := 'Calling procedure GetOrigTrxRef() Determine if ' ||
897 								                        'availability of ei for adjusted 1';
898 							                 If G_Debug_Mode = 'Y' Then
899 								                  Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
900 								                  pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
901 							                 End If;
902 
903 							                 Pa_Otc_Api.GetOrigTrxRef(
904 							                      P_Building_Block_Id => Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id,
905 							                      X_OrigTrxRef        => l_old_orig_trx_ref,
906 							                      X_Status            => l_New_Timecard_Rec.Status);
907 
908                                              If l_New_Timecard_Rec.Status is not null Then
909 
910 							                      G_Stage := 'Update hxc exception pl/sql tables 2.';
911 							                      If G_Debug_Mode = 'Y' Then
912 								                       Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path ||	' :: ' || G_Stage;
913 								                       pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
914 							                      End If;
915                                                   Hxc_User_Type_Definition_Grp.T_Tx_Detail_Status(i) := 'ERRORS';
916                                                   Hxc_User_Type_Definition_Grp.T_Tx_Detail_Exception(i) :=
917                                                                                         l_New_Timecard_Rec.Status;
918 							                      Raise G_BAD_OTL_DATA;
919 
920                                              End If;
921 
922 	                      				     -- l_old_orig_trx_ref :=
923                                 		     --	Pa_Otc_Api.GetOrigTrxRef(
924 							                 --	    Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id);
925 
926 							                 -- End bug enhancement
927 
928 							                 G_Stage := 'Call Build Reverse Item 3.';
929 		        				             If G_Debug_Mode = 'Y' Then
930         						                  Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
931         						                  pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
932         						             End If;
933 
934 							                 Pa_Otc_Api.Build_Reverse_Item(
935 								                  P_Old_Orig_Trx_Ref        => l_old_orig_trx_ref,
936 								                  P_New_Orig_Trx_Ref        => l_new_orig_trx_ref,
937 								                  P_Batch_Name              => l_batch_name,
938 								                  P_User_Id                 => P_User_Id,
939 								                  P_Orig_Exp_Txn_Reference1 => l_new_timecard_rec.Orig_Exp_Txn_Reference1,
940 								                  P_Xface_Id                => P_Xface_Id);
941 
942 							                 G_Stage := 'Store the Bb_Id and index in pl/sql table for use ' ||
943 								                        'in tieback process 3b.';
944 							                 If G_Debug_Mode = 'Y' Then
945 							                      Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
946 							                      pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
947 							                 End If;
948 							                 G_Trx_Inserted_Tab(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id).BB_Index := i;
949 
950 						                End If; -- l_direct_update_flag
951 
952 					               End If; -- l_Old_Timecard_Rec.Status
953 
954 				              End If;  -- l_New_Timecard_Rec.Status
955 
956 			             Else
957 
958 			                  -- The bb_id/ovn combo already exists in projects. This happened because
959                               -- during the validation of the timecard it was determined that need to
960                               -- update the ei record orig_transaction_reference column due to the fact that
961                               -- the ovn went up a version but not project specific data has changed.
962                               -- When an approved timecard that has already be sent to projects if a ei has
963                               -- change of the many that exist in the timecard and no other ei was changed
964                               -- and the user decides to click on the "Save for Later" button then all
965                               -- eis in OTL timecard get an incremented ovn number and we need to account for this.
966 
967 		                      G_Stage := 'The bb_id/ovn combo already exists in projects, bypassing BB_Id: ' ||
968 				                         to_char(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id) ||
969                 		                 ':' || to_char(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).Ovn) ||
970 		                                 ' for Resource_Id: ' || to_char(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).Resource_Id);
971 		                      Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Stage;
972 		                      pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,1);
973 
974 				              G_Stage := 'Call Populate Project Record new 3b for positioning purposes only.';
975                               If G_Debug_Mode = 'Y' Then
976                                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
977                                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
978                               End If;
979 
980                               Pa_Otc_Api.PopulateProjRec(
981                                    P_New_Old_BB   => 'NEW',
982                                    P_BB_Id        => Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id,
983                                    P_Detail_Index => i,
984                                    P_Old_Detl_Ind => l_Old_Detail_Index,
985                                    P_timecard_Rec => l_New_Timecard_Rec);
986 
987 				              G_Stage := 'Call Populate Project Record old 3b for positioning purposes only.';
988                               If G_Debug_Mode = 'Y' Then
989                                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
990                                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
991                               End If;
992 
993                               Pa_Otc_Api.PopulateProjRec(
994                                    P_New_Old_BB   => 'OLD',
995                                    P_BB_Id        => Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).bb_id,
996                                    P_Detail_Index => i,
997                                    P_Old_Detl_Ind => l_Old_Detail_Index,
998                                    P_timecard_Rec => l_Old_Timecard_Rec);
999 
1000 				              Hxc_User_Type_Definition_Grp.T_Tx_Detail_Status(i) := 'SUCCESS';
1001 				              l_insert_rec_Flag := FALSE;
1002 
1003 			             End If;
1004 
1005 		            ElsIf Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).Changed = 'Y' and
1006 		                  Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).Deleted = 'Y' Then
1007 
1008 			             -- The item was deleted in OTL after it was imported into Projects.
1009                          -- Need to Reverse out the original transaction.
1010 
1011 			             G_Stage := 'Item Changed: Y, Deleted: Y.';
1012 			             Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1013 			             pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,1);
1014 
1015 			             l_insert_rec_flag := FALSE;
1016                          l_Old_Detail_Index := l_Old_Detail_Index + 1;
1017 
1018 			             G_Stage := 'Create new orig trx ref 4.';
1019         		         If G_Debug_Mode = 'Y' Then
1020         		              Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1021         		              pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1022         		         End If;
1023 
1024                          l_new_orig_trx_ref := to_char(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id) || ':' ||
1025 			                                   to_char(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).Ovn);
1026 
1027 			             G_Stage := 'Call Populate Project Record new 4.';
1028                          If G_Debug_Mode = 'Y' Then
1029                               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1030                               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1031                          End If;
1032 
1033                          Pa_Otc_Api.PopulateProjRec(
1034                               P_New_Old_BB   => 'NEW',
1035                               P_BB_Id        => Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id,
1036                               P_Detail_Index => i,
1037                               P_Old_Detl_Ind => l_Old_Detail_Index,
1038                               P_timecard_Rec => l_New_Timecard_Rec);
1039 
1040 			             G_Stage := 'EI data status check 4.';
1041                          If G_Debug_Mode = 'Y' Then
1042                               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1043                               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1044                          End If;
1045 
1046                          If l_New_Timecard_Rec.Status is Not Null Then
1047 
1048 				              G_Stage := 'Status is not null 4. Timecard status is '  || l_New_Timecard_Rec.Status;
1049 				              If G_Debug_Mode = 'Y' Then
1050 				                   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1051 				                   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1052 				              End If;
1053 
1054                               Hxc_User_Type_Definition_Grp.T_Tx_Detail_Status(i) := 'ERRORS';
1055                               Hxc_User_Type_Definition_Grp.T_Tx_Detail_Exception(i) := l_New_Timecard_Rec.Status;
1056 
1057                               G_Stage := 'Since Status is not null 4 occured for new record, call the ' ||
1058 					                     'PopulateProjRec() procedure for the old record for positioning purposes ' ||
1059 					                     'so as to maintain sync with new pl/sql tables.';
1060                               If G_Debug_Mode = 'Y' Then
1061                                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1062                                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1063                               End If;
1064 
1065                               Pa_Otc_Api.PopulateProjRec(
1066                                    P_New_Old_BB   => 'OLD',
1067                                    P_BB_Id        => Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).bb_id,
1068                                    P_Detail_Index => i,
1069                                    P_Old_Detl_Ind => l_Old_Detail_Index,
1070                                    P_timecard_Rec => l_Old_Timecard_Rec);
1071 
1072 				              -- We don't check the status column since the only purpose for calling the
1073 				              -- procedure is for positioning index values.
1074 
1075 			             Else
1076 
1077 				              G_Stage := 'Call the GetBatchName procedure 4';
1078                         	  If G_Debug_Mode = 'Y' Then
1079                         	       Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1080                         	       pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1081                         	  End If;
1082 
1083                         	  Pa_Otc_Api.GetBatchName(
1084                                    P_Exp_End_Date => l_New_Timecard_Rec.Expenditure_Ending_Date,
1085                                    X_Batch_Name   => l_Batch_Name);
1086 
1087 				              G_Stage := 'Call Populate Project Record old 4 positioning purposes only.';
1088                         	  If G_Debug_Mode = 'Y' Then
1089                         	       Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1090                         	       pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1091                         	  End If;
1092 
1093                         	  Pa_Otc_Api.PopulateProjRec(
1094                                    P_New_Old_BB   => 'OLD',
1095                                    P_BB_Id        => Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).bb_id,
1096                                    P_Detail_Index => i,
1097                                    P_Old_Detl_Ind => l_Old_Detail_Index,
1098                                    P_timecard_Rec => l_Old_Timecard_Rec);
1099 
1100 				              -- We are not checking the status column since the call is for positioning purposes only.
1101 
1102                         	  G_Stage := 'Create old orig trx ref 4 using bb_id/ovn ' ||
1103                           		         to_char(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id) || ':' ||
1104                           		         to_char(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).Ovn);
1105 				              If G_Debug_Mode = 'Y' Then
1106                         	       Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1107                         	       pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1108                         	  End If;
1109 
1110                               -- Switched from function to procedure to determine if
1111                               -- ei is available for adjustment in projects
1112 
1113                               G_Stage := 'Calling procedure GetOrigTrxRef() Determine if ' ||
1114                                          'availability of ei for adjustment 4';
1115                               If G_Debug_Mode = 'Y' Then
1116                                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1117                                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1118                               End If;
1119 
1120                               Pa_Otc_Api.GetOrigTrxRef(
1121                                    P_Building_Block_Id => Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id,
1122                                    X_OrigTrxRef        => l_old_orig_trx_ref,
1123                                    X_Status            => l_New_Timecard_Rec.Status);
1124 
1125                               If l_New_Timecard_Rec.Status is not null Then
1126 
1127 					               G_Stage := 'Updating hxc exception pl/sql tables 3.';
1128 					               If G_Debug_Mode = 'Y' Then
1129                                         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1130                                         pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1131                                    End If;
1132 
1133                                    Hxc_User_Type_Definition_Grp.T_Tx_Detail_Status(i) := 'ERRORS';
1134                                    Hxc_User_Type_Definition_Grp.T_Tx_Detail_Exception(i) := l_New_Timecard_Rec.Status;
1135 					               Raise G_BAD_OTL_DATA;
1136 
1137                               End If;
1138 
1139                         	  -- l_old_orig_trx_ref :=
1140                               -- 	Pa_Otc_Api.GetOrigTrxRef(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id);
1141 
1142 				              -- End switch from function to procedure
1143 
1144 				              G_Stage := 'Call Build Reverse Item 4.';
1145         			          If G_Debug_Mode = 'Y' Then
1146         			               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1147         			               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1148         			          End If;
1149 
1150 				              l_error_code := NULL;
1151 
1152                         	  Pa_Otc_Api.Build_Reverse_Item(
1153                                    P_Old_Orig_Trx_Ref        => l_old_orig_trx_ref,
1154                                    P_New_Orig_Trx_Ref        => l_new_orig_trx_ref,
1155                                    P_Batch_Name              => l_batch_name,
1156 					               P_User_id                 => P_User_Id,
1157 					               P_Orig_Exp_Txn_Reference1 => l_New_Timecard_Rec.Orig_Exp_Txn_Reference1,
1158 					               P_Xface_Id                => P_Xface_id);
1159 
1160 				              G_Stage := 'Store the Bb_Id and index in pl/sql table for use in tieback process 4.';
1161 				              If G_Debug_Mode = 'Y' Then
1162 				                   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1163 				                   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1164 				              End If;
1165 				              G_Trx_Inserted_Tab(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id).BB_Index := i;
1166 
1167 			             End If; -- l_New_Timecard_Rec.Status
1168 
1169 		            End If; -- Change/Delete flags
1170 
1171 		            If l_insert_rec_flag Then
1172 
1173 			             G_Stage := 'Get the next available Transaction Interface Id from sequence.';
1174         		         If G_Debug_Mode = 'Y' Then
1175         		              Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1176         		              pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1177         		         End If;
1178 
1179 			             select pa_txn_interface_s.nextval
1180 			             into l_txn_xface_id
1181 			             from dual;
1182 
1183 	                     G_Stage := 'Store new/changed Trx Import Rec in pl/sql arrays for BB/Ovn: ' || l_New_Orig_Trx_Ref ||
1184                                     ' for Resource_Id(Person_Id): ' || to_char(l_New_Timecard_Rec.Incurred_By_Person_Id);
1185                          Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Stage;
1186 	                     pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,1);
1187 
1188 			             G_Stage := 'Store Trx Import record in pl/sql arrays for bulk insert.';
1189         	             If G_Debug_Mode = 'Y' Then
1190         		              Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1191         		              pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1192         	             End If;
1193 /* Bug 6698171 */ if (l_New_Timecard_Rec.Person_Type = 'EMP') then   /* Added if..else for bug 7505424 */
1194                        patc.check_termination (l_New_Timecard_Rec.Incurred_By_Person_Id, l_New_Timecard_Rec.Expenditure_Item_Date, l_ac_termination_date);
1195                    else
1196                        patc.check_termination_for_cwk(l_New_Timecard_Rec.Incurred_By_Person_Id, l_New_Timecard_Rec.Expenditure_Item_Date, l_ac_termination_date);
1197                    end if;
1198                    -- following if does validation for employee termination
1199                    IF l_New_Timecard_Rec.Expenditure_Item_Date <= nvl(l_ac_termination_date, l_New_Timecard_Rec.Expenditure_Item_Date) then
1200 
1201 			             G_Trx_Import_Index := G_Trx_Import_Index + 1;
1202 
1203                          G_Txn_Interface_Id_Tbl(G_Trx_Import_Index) := l_txn_xface_id;
1204                          G_Transaction_Source_Tbl(G_Trx_Import_Index) := 'ORACLE TIME AND LABOR';
1205                          G_User_Transaction_Source_Tbl(G_Trx_Import_Index) := Null;
1206                          G_Batch_Name_Tbl(G_Trx_Import_Index) := l_batch_name;
1207                          G_Expenditure_End_Date_Tbl(G_Trx_Import_Index) := Pa_Utils.NewGetWeekEnding(l_New_Timecard_Rec.Expenditure_Item_Date);
1208                          G_Person_Bus_Grp_Name_Tbl(G_Trx_Import_Index) := Null;
1209                          G_Person_Bus_Grp_Id_Tbl(G_Trx_Import_Index) := Null;
1210                          G_Employee_Number_Tbl(G_Trx_Import_Index) := Null;
1211                          G_Person_Id_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Incurred_By_Person_Id;
1212                          G_Organization_Name_Tbl(G_Trx_Import_Index) := Null;
1213                          G_Organization_Id_Tbl(G_Trx_Import_Index) := Null;
1214                          G_Expenditure_Item_Date_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Expenditure_Item_Date;
1215                          G_Project_Number_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Project_Number;
1216                          G_Project_Id_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Project_Id;
1217                          G_Task_Number_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Task_Number;
1218                          G_Task_Id_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Task_Id;
1219                          G_Expenditure_Type_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Expenditure_Type;
1220                          G_System_Linkage_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.System_Linkage_Function;
1221                          G_Non_Labor_Resource_Tbl(G_Trx_Import_Index) := Null;
1222                          G_Non_Labor_Res_Org_Name_Tbl(G_Trx_Import_Index) := Null;
1223                          G_Non_Labor_Res_Org_Id_Tbl(G_Trx_Import_Index) := Null;
1224                          G_Quantity_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Quantity;
1225                          G_Raw_Cost_Tbl(G_Trx_Import_Index) := Null;
1226                          G_Raw_Cost_Rate_Tbl(G_Trx_Import_Index) := Null;
1227                          G_Burden_Cost_Tbl(G_Trx_Import_Index) := Null;
1228                          G_Burden_Cost_Rate_Tbl(G_Trx_Import_Index) := Null;
1229                          G_Expenditure_Comment_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Expenditure_Item_Comment;
1230                          G_Gl_Date_Tbl(G_Trx_Import_Index) := Null;
1231                          G_Transaction_Status_Code_Tbl(G_Trx_Import_Index) := 'P';
1232                          G_Trans_Rejection_Code_Tbl(G_Trx_Import_Index) := Null;
1233                          G_Orig_Trans_Reference_Tbl(G_Trx_Import_Index) := l_New_Orig_Trx_Ref;
1234                          G_Unmatched_Neg_Txn_Flag_Tbl(G_Trx_Import_Index) := 'Y';
1235                          G_Expenditure_Id_Tbl(G_Trx_Import_Index) := Null;
1236                          G_Attribute_Category_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Attribute_Category;
1237                          G_Attribute1_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Attribute1;
1238                          G_Attribute2_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Attribute2;
1239                          G_Attribute3_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Attribute3;
1240                          G_Attribute4_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Attribute4;
1241                          G_Attribute5_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Attribute5;
1242                          G_Attribute6_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Attribute6;
1243                          G_Attribute7_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Attribute7;
1244                          G_Attribute8_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Attribute8;
1245                          G_Attribute9_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Attribute9;
1246                          G_Attribute10_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Attribute10;
1247                          G_Dr_Code_Combination_Id_Tbl(G_Trx_Import_Index) := Null;
1248                          G_Cr_Code_Combination_Id_Tbl(G_Trx_Import_Index) := Null;
1249                          G_Cdl_System_Reference1_Tbl(G_Trx_Import_Index) := Null;
1250                          G_Cdl_System_Reference2_Tbl(G_Trx_Import_Index) := Null;
1251                          G_Cdl_System_Reference3_Tbl(G_Trx_Import_Index) := Null;
1252                          G_Interface_Id_Tbl(G_Trx_Import_Index) := P_Xface_Id;
1253                          G_Receipt_Currency_Amount_Tbl(G_Trx_Import_Index) := Null;
1254                          G_Receipt_Currency_Code_Tbl(G_Trx_Import_Index) := Null;
1255                          G_Receipt_Exchange_Rate_Tbl(G_Trx_Import_Index) := Null;
1256                          G_Denom_Currency_Code_Tbl(G_Trx_Import_Index) := Null;
1257                          G_Denom_Raw_Cost_Tbl(G_Trx_Import_Index) := Null;
1258                          G_Denom_Burdened_Cost_Tbl(G_Trx_Import_Index) := Null;
1259                          G_Acct_Rate_Date_Tbl(G_Trx_Import_Index) := Null;
1260                          G_Acct_Rate_Type_Tbl(G_Trx_Import_Index) := Null;
1261                          G_Acct_Exchange_Rate_Tbl(G_Trx_Import_Index) := Null;
1262                          G_Acct_Raw_Cost_Tbl(G_Trx_Import_Index) := Null;
1263                          G_Acct_Burdened_Cost_Tbl(G_Trx_Import_Index) := Null;
1264                          G_Acct_Exch_Rounding_Limit_Tbl(G_Trx_Import_Index) := Null;
1265                          G_Project_Currency_Code_Tbl(G_Trx_Import_Index) := Null;
1266                          G_Project_Rate_Date_Tbl(G_Trx_Import_Index) := Null;
1267                          G_Project_Rate_Type_Tbl(G_Trx_Import_Index) := Null;
1268                          G_Project_Exchange_Rate_Tbl(G_Trx_Import_Index) := Null;
1269                          G_Orig_Exp_Txn_Reference1_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Orig_Exp_Txn_Reference1;
1270                          G_Orig_Exp_Txn_Reference2_Tbl(G_Trx_Import_Index) := Null;
1271                          G_Orig_Exp_Txn_Reference3_Tbl(G_Trx_Import_Index) := Null;
1272                          G_Orig_User_Exp_Txn_Ref_Tbl(G_Trx_Import_Index) := Null;
1273                          G_Vendor_Number_Tbl(G_Trx_Import_Index) := Null;
1274                          G_Vendor_Id_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Vendor_Id; -- PA.M/CWK changes
1275                          G_Override_To_Org_Name_Tbl(G_Trx_Import_Index) := Null;
1276                          G_Override_To_Org_Id_Tbl(G_Trx_Import_Index) := Null;
1277                          G_Reversed_Orig_Txn_Ref_Tbl(G_Trx_Import_Index) := Null;
1278                          G_Billable_Flag_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Billable_Flag;
1279                          G_ProjFunc_Currency_Code_Tbl(G_Trx_Import_Index) := Null;
1280                          G_ProjFunc_Cost_Rate_Date_Tbl(G_Trx_Import_Index) := Null;
1281                          G_ProjFunc_Cost_Rate_Type_Tbl(G_Trx_Import_Index) := Null;
1282                          G_ProjFunc_Cost_Exch_Rate_Tbl(G_Trx_Import_Index) := Null;
1283                          G_Project_Raw_Cost_Tbl(G_Trx_Import_Index) := Null;
1284                          G_Project_Burdened_Cost_Tbl(G_Trx_Import_Index) := Null;
1285                          G_Assignment_Name_Tbl(G_Trx_Import_Index) := Null;
1286                          G_Assignment_Id_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Assignment_Id;
1287                          G_Work_Type_Name_Tbl(G_Trx_Import_Index) := Null;
1288                          G_Work_Type_Id_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Work_Type_Id;
1289 						 pa_cc_utils.log_message('Ravi: loading the variables to pass to xface .. work type id: ' || l_New_Timecard_Rec.Work_Type_Id);
1290                          G_Cdl_System_Reference4_Tbl(G_Trx_Import_Index) := Null;
1291                          G_Accrual_Flag_Tbl(G_Trx_Import_Index) := Null;
1292                          G_Last_Update_Date_Tbl(G_Trx_Import_Index) := sysdate;
1293                          G_Last_Updated_By_Tbl(G_Trx_Import_Index) := P_User_Id;
1294                          G_Creation_Date_Tbl(G_Trx_Import_Index) := sysdate;
1295                          G_Created_By_Tbl(G_Trx_Import_Index) := P_User_Id;
1296 			             -- Begin PA.M/CWK changes
1297 			             G_PO_Number_Tbl(G_Trx_Import_Index) := Null;
1298 			             G_PO_Header_Id_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.PO_Header_Id;
1299 			             G_PO_Line_Num_Tbl(G_Trx_Import_Index) := Null;
1300 			             G_PO_Line_Id_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.PO_Line_Id;
1301 			             G_PO_Price_Type_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.PO_Price_Type;
1302 			             G_Person_Type_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Person_Type;
1303 			             -- End PA.M/CWK changes
1304 			             G_Inventory_Item_Id_Tbl(G_Trx_Import_Index) := Null;
1305 			             G_WIP_Resource_Id_Tbl(G_Trx_Import_Index) := Null;
1306 		                 G_Unit_Of_Measure_Tbl(G_Trx_Import_Index) := Null;
1307                          -- 12i MOAC changes
1308                          G_OU_Tbl(G_Trx_Import_Index) := G_Current_Org_Id;
1309                          -- 10253400: Payroll integration enhancement for 12.2..start
1310                          G_Job_Id_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Job_Id;
1311                          G_Location_Id_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Location_Id;
1312                          G_Job_Name_Tbl(G_Trx_Import_Index) := NULL;
1313                          G_Location_Code_tbl(G_Trx_Import_Index) := NULL;
1314                          G_Pay_Element_Type_Id_tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Pay_Element_Type_Id;
1315                          -- 10253400: Payroll integration enhancement for 12.2..end
1316               -- Start: Added for CBS Enhancement Bug 16220146
1317 						 G_Cbs_Element_Id_Tbl(G_Trx_Import_Index) := l_New_Timecard_Rec.Cbs_Element_Id;
1318 						 G_Cbs_Element_Name_Tbl(G_Trx_Import_Index) := NULL;
1319 						 -- End: Added for CBS Enhancement Bug 16220146
1320 
1321 			             G_Stage := 'Pl/sql record counter increment.';
1322                          If G_Debug_Mode = 'Y' Then
1323                               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1324                               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1325                          End If;
1326 			             G_Txn_Rec_Count := nvl(G_Txn_Rec_Count,0) + 1;
1327 
1328 			             G_Stage := 'Store the Bb_Id and index in pl/sql table for use in tieback process.';
1329                          If G_Debug_Mode = 'Y' Then
1330                               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1331                               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1332                          End If;
1333 			             G_Trx_Inserted_Tab(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id).BB_Index := i;
1334 
1335 		            End If;
1336 
1337 		            G_Stage := 'Check if need to call bulk insert.';
1338                     If G_Debug_Mode = 'Y' Then
1339                          Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1340                          pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1341                     End If;
1342                     If G_Txn_Rec_Count >= L_MAX_RECS_FOR_BULKINSERT Then
1343 
1344 			             G_Stage := 'Call BulkInsertReset() procedure for insert.';
1345                          If G_Debug_Mode = 'Y' Then
1346                               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1347                               Pa_Cc_Utils.Log_Message(Pa_Debug.G_Err_Stage,0);
1348                          End If;
1349                          Pa_Otc_Api.BulkInsertReset(P_Command => 'INSERT');
1350 
1351 			             G_Stage := 'Store total records inserted. Reset counter to 0.';
1352                          If G_Debug_Mode = 'Y' Then
1353                               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1354                               Pa_Cc_Utils.Log_Message(Pa_Debug.G_Err_Stage,0);
1355                          End If;
1356                          Pa_Trx_Import.G_Batch_Size := Nvl(Pa_Trx_Import.G_Batch_Size,0) + G_Txn_Rec_Count;
1357                          G_Txn_Rec_Count := 0;
1358 
1359 		            End If;
1360                    End if;              /* Bug 6698171, End of validation for terminated employee */
1361 
1362                Exception
1363 		            When G_BAD_OTL_DATA Then
1364                 	     Hxc_User_Type_Definition_Grp.T_Tx_Detail_Status(i) := 'ERRORS';
1365                 	     Hxc_User_Type_Definition_Grp.T_Tx_Detail_Exception(i) :=
1366 					     nvl(l_New_Timecard_Rec.Status,l_Old_Timecard_Rec.Status);
1367                 	     G_Unhandled_Except_Cnt := G_Unhandled_Except_Cnt + 1;
1368 
1369 			             G_Stage := 'Unhandled exception count is now ' || to_char(G_Unhandled_Except_Cnt);
1370 			             If G_Debug_Mode = 'Y' Then
1371                               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1372                               Pa_Cc_Utils.Log_Message(Pa_Debug.G_Err_Stage,0);
1373                          End If;
1374 
1375                          If G_Unhandled_Except_Cnt > G_EXCEPT_CNT_ALLOWED Then
1376 
1377                               G_Stage := 'Unhandled exceptions count exceeds maximum allowed of ' ||
1378 					                     to_char(G_EXCEPT_CNT_ALLOWED) || '.  Raising user defined exception!';
1379                               If G_Debug_Mode = 'Y' Then
1380                                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1381                                    Pa_Cc_Utils.Log_Message(Pa_Debug.G_Err_Stage,0);
1382                               End If;
1383 
1384                               Raise HXC_RETRIEVAL_MAX_ERRORS;
1385 
1386 			             End If;
1387 
1388 		            When Others Then
1389 			             Raise;
1390 
1391 	           End;
1392 
1393 	           G_Stage := 'Resetting the pl/sql new and old timecard record variables.';
1394 	           If G_Debug_Mode = 'Y' Then
1395                     Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1396                     Pa_Cc_Utils.Log_Message(Pa_Debug.G_Err_Stage,0);
1397                End If;
1398 	           l_New_Timecard_Rec := l_Temp_Timecard_Rec;
1399 	           l_Old_Timecard_Rec := l_Temp_Timecard_Rec;
1400 
1401 	      End Loop;
1402 
1403 	      G_Stage := 'Exited the loop.  Check if need to call bulk insert for any remaining pl/sql records.';
1404 	      If G_Debug_Mode = 'Y' Then
1405 	           Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1406 	           pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1407 	      End If;
1408 
1409 	      If G_Txn_Rec_Count > 0 Then
1410 
1411 		       G_Stage := 'Call bulk insert for the remaining pl/sql records.';
1412 		       If G_Debug_Mode = 'Y' Then
1413 		            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1414 		            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1415 		       End If;
1416 		       Pa_Otc_Api.BulkInsertReset(P_Command => 'INSERT');
1417 
1418 		       G_Stage := 'Set the final records count for the next import phase.  Reset counter.';
1419                If G_Debug_Mode = 'Y' Then
1420                     Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1421                     pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1422                End If;
1423 		       Pa_Trx_Import.G_Batch_Size := Nvl(Pa_Trx_Import.G_Batch_Size,0) + G_Txn_Rec_Count;
1424 
1425 		       G_Txn_Rec_Count := 0;
1426 
1427           End If;
1428 
1429 	      G_Stage := 'This chunk has ' || to_char(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks.COUNT) ||
1430 	    	         ' records, of which ' || to_char(Pa_Trx_Import.G_Batch_Size) || ' are to be processed' ||
1431 		             ' in the next phase of Trx Import.';
1432 	      If G_Debug_Mode = 'Y' Then
1433 	           Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1434 	           pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,1);
1435 	      End If;
1436 
1437      Else
1438 
1439           G_Stage := 'Last chunk from OTL.  Flag process we are done.  No further records to process.';
1440 	      If G_Debug_Mode = 'Y' Then
1441                Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1442                pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1443           End If;
1444 
1445 	      Pa_Trx_Import.G_Exit_Main := NULL;
1446 	      Pa_Trx_Import.G_Batch_Size := 0;
1447 
1448 	      G_Stage := 'Call Hxc_Generic_Retrieval_Pkg.Update_Transaction_Status() one last time.';
1449           If G_Debug_Mode = 'Y' Then
1450                Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1451                pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1452           End If;
1453           Hxc_Integration_Layer_V1_Grp.Set_Parent_Statuses;
1454           Hxc_Integration_Layer_V1_Grp.Update_Transaction_Status
1455                (P_Process               => 'Projects Retrieval Process',
1456                 P_Status                => 'SUCCESS',
1457                 P_Exception_Description => NULL);
1458 
1459      End If; -- Are there records in the otl pl/sql tables to process
1460 
1461      G_Stage := 'Leaving Upload_Otc_Timecards(), strip procedure from trackpath.';
1462      If G_Debug_Mode = 'Y' Then
1463         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1464         pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,1);
1465      End If;
1466      Pa_Otc_Api.TrackPath('STRIP','Upload_Otc_Timecards');
1467 
1468    Exception
1469 
1470      When HXC_RETRIEVAL_MAX_ERRORS Then
1471 
1472           fnd_message.set_name('HXC','HXC_RET_MAX_ERRORS');
1473 		  l_Error_Text := SUBSTR(fnd_message.get,1,2000);
1474 
1475 		  Hxc_Integration_Layer_V1_Grp.Set_Parent_Statuses;
1476           Hxc_Integration_Layer_V1_Grp.Update_Transaction_Status
1477                (P_Process               => 'Projects Retrieval Process',
1478                 P_Status                => 'ERRORS',
1479                 P_Exception_Description => l_Error_Text);
1480 
1481           fnd_message.set_name('HXC','HXC_RET_MAX_ERRORS');
1482           fnd_message.raise_error;
1483 
1484      When Others Then
1485 
1486        	  If ( SQLERRM = 'ORA-20001: HXC_0012_GNRET_NO_TIMECARDS:' or
1487                SQLERRM = 'ORA-20001: HXC_0013_GNRET_NO_BLD_BLKS:' ) Then
1488 
1489                -- Begin bug 3422899 Customer feedback on this bit of code shows that we should always
1490                --                   suppress these 2 errors and let the report handle that there
1491                --                   was no data to process.
1492                --
1493                -- The G_Processed_Import_Batch is FALSE then this is the first time thru the Trx
1494                -- Import loop which would mean we want to raise.  If G_Processed_Import_Batch is TRUE
1495                -- that meains this is not the first time thru and we would not want to raise an error.
1496                -- The global variable is set to TRUE at the end of the Tieback_Otc_Timecards() procedure.
1497                -- If Not G_Processed_Import_Batch Then
1498                --
1499                --      Hxc_Integration_Layer_V1_Grp.Set_Parent_Statuses;
1500                --      Hxc_Integration_Layer_V1_Grp.Update_Transaction_Status
1501                --                 	(P_Process               => 'Projects Retrieval Process',
1502                --                  	 P_Status                => 'ERRORS',
1503                --                  	 P_Exception_Description =>
1504                --                                 substr('Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage ||
1505                --                                        ' : ' || SQLERRM, 1, 2000));
1506                --
1507 		       -- 	  Fnd_Message.Raise_Error;
1508                --
1509 			   -- End If;
1510 
1511                If SQLERRM = 'ORA-20001: HXC_0012_GNRET_NO_TIMECARDS:' Then
1512 
1513                     fnd_message.set_name('HXC','HXC_0012_GNRET_NO_TIMECARDS');
1514                Else
1515 
1516                     fnd_message.set_name('HXC','HXC_0013_GNRET_NO_BLD_BLKS');
1517 
1518                End If;
1519                Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage || ' : ' || fnd_message.get;
1520                pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,1);
1521 
1522                -- End bug 3422899
1523 
1524 		  Else
1525 
1526                Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage || ' : ' || SQLERRM;
1527                Hxc_Integration_Layer_V1_Grp.Set_Parent_Statuses;
1528          	   Hxc_Integration_Layer_V1_Grp.Update_Transaction_Status
1529              			(P_Process               => 'Projects Retrieval Process',
1530              			 P_Status                => 'ERRORS',
1531              			 P_Exception_Description =>
1532 				          substr('Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage || ' : ' || SQLERRM, 1, 2000));
1533 			   Raise;
1534 
1535 		  End If;
1536 
1537    End Upload_Otc_Timecards;
1538 
1539 
1540 -- =======================================================================
1541 -- Start of Comments
1542 -- API Name      : Build_Reverse_Item
1543 -- Type          : Private
1544 -- Pre-Reqs      : None
1545 -- Type          : Procedure
1546 -- Function      : This procedure is called when need to reverse expenditure_item
1547 --                 already imported into projects and need to create a record to
1548 --                 insert into pa_transaction_interface table for this.
1549 -- Conditions    : 1. Deleted the original item
1550 -- called          2. Changed either project,
1551 --                                   task,
1552 --                                   expenditure_type,
1553 --                                   system_linkage_function,
1554 --                                   quantity
1555 --
1556 -- Parameters    :
1557 -- IN
1558 --           P_Old_Orig_Trx_Ref           Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE
1559 --           P_New_Orig_Trx_Ref           Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE
1560 --           P_Batch_Name                 Pa_Transaction_Interface_All.Batch_Name%TYPE
1561 --           P_User_Id                    Pa_Expenditure_Items_All.Last_Updated_By%TYPE
1562 --           P_Orig_Exp_Txn_Reference1    Pa_Expenditures_All.Orig_Exp_Txn_Reference1%TYPE
1563 --           P_Xface_Id                   Pa_Transaction_Interface_All.Txn_Interface_Id%TYPE
1564 
1565 /*------------------------------------------------------------------------- */
1566 
1567    Procedure Build_Reverse_Item(
1568             P_Old_Orig_Trx_Ref        IN Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE,
1569 	    P_New_Orig_Trx_Ref        IN Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE,
1570 	    P_Batch_Name              IN Pa_Transaction_Interface_All.Batch_Name%TYPE,
1571 	    P_User_Id                 IN Pa_Expenditure_Items_All.Last_Updated_By%TYPE,
1572 	    P_Orig_Exp_Txn_Reference1 IN Pa_Expenditures_All.Orig_Exp_Txn_Reference1%TYPE,
1573 	    P_Xface_Id                IN Pa_Transaction_Interface_All.Txn_Interface_Id%TYPE )
1574 
1575    Is
1576 
1577       l_txn_rowid           RowId := Null;
1578       l_txn_xface_id        Pa_Transaction_Interface_All.Txn_Interface_Id%TYPE := Null;
1579 
1580       l_Exp_End_Date        Pa_Expenditures_All.Expenditure_Ending_Date%TYPE;
1581       l_Inc_By_Org_Id       Hr_Organization_Units.Organization_Id%TYPE;
1582       l_Exp_Item_Date       Pa_Expenditure_Items_All.Expenditure_Item_Date%TYPE;
1583       l_Proj_Id             Pa_Projects_All.Project_Id%TYPE;
1584       l_Task_Id             Pa_Tasks.Task_Id%TYPE;
1585       l_Exp_Type            Pa_Expenditure_Types.Expenditure_Type%TYPE;
1586       l_Sys_Link            Pa_Expenditure_Items_All.System_Linkage_Function%TYPE;
1587       l_Quantity            Pa_Expenditure_Items_All.Quantity%TYPE;
1588       l_Inc_By_Person_Id    Pa_Expenditures_All.Incurred_By_Person_Id%TYPE;
1589       l_Attribute_Category  Pa_Expenditure_Items_All.Attribute_Category%TYPE;
1590       l_Attribute1          Pa_Expenditure_Items_All.Attribute1%TYPE;
1591       l_Attribute2          Pa_Expenditure_Items_All.Attribute2%TYPE;
1592       l_Attribute3          Pa_Expenditure_Items_All.Attribute3%TYPE;
1593       l_Attribute4          Pa_Expenditure_Items_All.Attribute4%TYPE;
1594       l_Attribute5          Pa_Expenditure_Items_All.Attribute5%TYPE;
1595       l_Attribute6          Pa_Expenditure_Items_All.Attribute6%TYPE;
1596       l_Attribute7          Pa_Expenditure_Items_All.Attribute7%TYPE;
1597       l_Attribute8          Pa_Expenditure_Items_All.Attribute8%TYPE;
1598       l_Attribute9          Pa_Expenditure_Items_All.Attribute9%TYPE;
1599       l_Attribute10         Pa_Expenditure_Items_All.Attribute10%TYPE;
1600       l_Assignment_Id       Pa_Expenditure_Items_All.Assignment_Id%TYPE;
1601       l_Work_Type_Id        Pa_Expenditure_Items_All.Work_Type_Id%TYPE;
1602       l_Billable_Flag       Pa_Expenditure_Items_All.Billable_Flag%TYPE;
1603       l_Exp_Comment         Pa_Expenditure_Comments.Expenditure_Comment%TYPE;
1604       -- Begin CWK changes PA.M
1605       l_Person_Type	    Pa_Expenditures_All.Person_Type%TYPE;
1606       l_PO_Line_Id	    Pa_Expenditure_Items_All.PO_Line_Id%TYPE;
1607       l_PO_Price_Type	    Pa_Expenditure_Items_All.PO_Price_Type%TYPE;
1608       l_Vendor_Id	    Pa_Expenditures_All.Vendor_id%TYPE;
1609       l_PO_Header_Id        Number := Null;
1610       l_Dummy_Vendor_Id     Number := Null;
1611       -- End CWK changes PA.M
1612       -- 12i changes
1613       l_Org_Id             Number := Null;
1614       -- bug 10253400: Payroll integration enhancement for 12.2..start
1615       l_Job_Id               Pa_Expenditure_Items_All.Job_Id%TYPE;
1616       l_Location_Id          Pa_Expenditure_Items_All.Location_Id%TYPE;
1617 	  l_Pay_Element_Type_Id  Pa_Expenditure_Items_All.Pay_Element_Type_Id%TYPE;
1618       -- bug 10253400: Payroll integration enhancement for 12.2..end
1619     l_Cbs_Element_Id       PA_Expenditure_Items_All.Cbs_Element_Id%TYPE; -- Added for CBS Enhancement Bug 16220146
1620 
1621    Begin
1622 
1623 	G_Stage := 'Enter Build_Reverse_Item().';
1624     If G_Debug_Mode = 'Y' Then
1625          Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1626          pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1627     End If;
1628 
1629 	G_Stage := 'Add procedure to track path';
1630     If G_Debug_Mode = 'Y' Then
1631 	     Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1632          pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1633     End If;
1634     Pa_Otc_Api.TrackPath('ADD','Build_Reverse_Item');
1635 
1636 	G_Stage := 'Get needed data to build reversing item phase 1.';
1637     If G_Debug_Mode = 'Y' Then
1638          Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1639          pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1640     End If;
1641 
1642 	Select
1643 		EI.Task_Id,
1644 		EI.Project_Id, -- Changed from T.Project_Id
1645         E.Expenditure_Ending_Date,
1646 		E.Incurred_By_Organization_Id,
1647 		E.Incurred_By_Person_Id,
1648 		EI.Expenditure_Item_Date,
1649         EI.Expenditure_Type,
1650 		EI.System_Linkage_Function,
1651 		-(EI.quantity),
1652 		EI.Attribute_Category,
1653 		EI.Attribute1,
1654 		EI.Attribute2,
1655 		EI.Attribute3,
1656 		EI.Attribute4,
1657 		EI.Attribute5,
1658 		EI.Attribute6,
1659 		EI.Attribute7,
1660 		EI.Attribute8,
1661 		EI.Attribute9,
1662 		EI.Attribute10,
1663 		EI.Assignment_Id,
1664 		EI.Work_Type_Id,
1665 		EI.Billable_Flag,
1666 		PEC.Expenditure_Comment,
1667 		-- Begin CWK changes PA.M
1668 		EI.PO_Line_Id,
1669 		EI.PO_Price_Type,
1670 		E.Person_Type,
1671 		E.Vendor_Id,
1672 		-- End CWK changes PA.M
1673         -- 12i changes
1674         ei.org_id,
1675         -- bug 10253400: Payroll integration enhancement for 12.2..start
1676         ei.job_id,
1677         ei.location_id,
1678 		ei.pay_element_type_id
1679         -- bug 10253400: Payroll integration enhancement for 12.2..end
1680     ,ei.Cbs_Element_Id -- Added for CBS Enhancement Bug 16220146
1681 	Into
1682 		l_Task_Id,
1683 		l_Proj_Id,
1684         l_Exp_End_Date,
1685 		l_Inc_By_Org_Id,
1686 		l_Inc_By_Person_Id,
1687 		l_Exp_Item_Date,
1688 		l_Exp_Type,
1689 		l_Sys_Link,
1690  		l_Quantity,
1691 		l_Attribute_Category,
1692 		l_Attribute1,
1693         l_Attribute2,
1694         l_Attribute3,
1695         l_Attribute4,
1696         l_Attribute5,
1697         l_Attribute6,
1698         l_Attribute7,
1699         l_Attribute8,
1700         l_Attribute9,
1701         l_Attribute10,
1702 		l_Assignment_Id,
1703 		l_Work_Type_Id,
1704 		l_Billable_Flag,
1705 		l_Exp_Comment,
1706 		-- Begin CWK changes PA.M
1707 		l_PO_Line_Id,
1708 		l_PO_Price_Type,
1709 		l_Person_Type,
1710 		l_Vendor_Id,
1711 		-- End CWK changes PA.M
1712         -- 12i changes
1713         l_org_id,
1714         -- bug 10253400: Payroll integration enhancement for 12.2..start
1715         l_job_id,
1716         l_location_id,
1717 		l_pay_element_type_id
1718         -- bug 10253400: Payroll integration enhancement for 12.2..end
1719     ,l_Cbs_Element_Id -- Added for CBS Enhancement Bug 16220146
1720 	From
1721 		Pa_Expenditure_Items EI,
1722 		Pa_Expenditure_Comments PEC,
1723 		Pa_Expenditures E
1724 -- 3457943 S.N.
1725 		--Pa_Tasks T
1726 -- 3457943 E.N.
1727 	Where
1728 -- 3457943 S.N.
1729 		--T.Task_Id = EI.Task_Id
1730 -- 3457943 E.N.
1731 	    	E.Expenditure_Id = EI.Expenditure_Id
1732 	And     EI.Expenditure_Item_Id = PEC.Expenditure_Item_Id(+)
1733 	And    	EI.Transaction_Source = 'ORACLE TIME AND LABOR'
1734 	And    	EI.Orig_Transaction_Reference = P_Old_Orig_Trx_Ref
1735 	And     Nvl(EI.Net_Zero_Adjustment_Flag,'N') = 'N'
1736         And     EI.Adjusted_Expenditure_Item_Id is Null;
1737 
1738 	G_Stage := 'Get Transaction Interface Id from sequence for reversing item.';
1739 	If G_Debug_Mode = 'Y' Then
1740 	   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1741 	   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1742 	End If;
1743 
1744         Select Pa_Txn_Interface_S.NextVal
1745 	Into l_Txn_Xface_Id
1746 	From Dual;
1747 
1748 	If l_Person_Type = 'CWK' And l_PO_Line_Id Is Not Null Then
1749 
1750 	        G_Stage := 'Get Supplier Info by calling GetPOInfo() 2.';
1751 		If G_Debug_Mode = 'Y' Then
1752 	        	Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Stage;
1753 	        	pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,1);
1754 		End If;
1755 
1756 		Pa_Otc_Api.GetPOInfo(
1757 			P_Po_Line_Id    => l_PO_Line_Id,
1758 		      	X_Po_Header_Id  => l_PO_Header_Id,
1759 		      	X_Vendor_Id     => l_Dummy_Vendor_Id);
1760 
1761 	End If;
1762 
1763         G_Stage := 'Inserting reversing item into interface table BB/Ovn: ' || P_New_Orig_Trx_Ref ||
1764                    ' for Resource_Id(Person_Id): ' || to_char(l_Inc_By_Person_Id);
1765         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Stage;
1766         pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,1);
1767 
1768 	G_Stage := 'Store record for reversing item into arrays for bulk insert later.';
1769         If G_Debug_Mode = 'Y' Then
1770            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1771            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1772         End If;
1773 
1774         G_Trx_Import_Index := G_Trx_Import_Index + 1;
1775 
1776         G_Txn_Interface_Id_Tbl(G_Trx_Import_Index) := l_Txn_Xface_Id;
1777         G_Transaction_Source_Tbl(G_Trx_Import_Index) := 'ORACLE TIME AND LABOR';
1778         G_User_Transaction_Source_Tbl(G_Trx_Import_Index) := Null;
1779         G_Batch_Name_Tbl(G_Trx_Import_Index) := P_Batch_Name;
1780         G_Expenditure_End_Date_Tbl(G_Trx_Import_Index) := l_Exp_End_Date;
1781         G_Person_Bus_Grp_Name_Tbl(G_Trx_Import_Index) := Null;
1782         G_Person_Bus_Grp_Id_Tbl(G_Trx_Import_Index) := Null;
1783         G_Employee_Number_Tbl(G_Trx_Import_Index) := Null;
1784         G_Person_Id_Tbl(G_Trx_Import_Index) := l_Inc_By_Person_Id;
1785         G_Organization_Name_Tbl(G_Trx_Import_Index) := Null;
1786         G_Organization_Id_Tbl(G_Trx_Import_Index) := l_Inc_By_Org_Id;
1787         G_Expenditure_Item_Date_Tbl(G_Trx_Import_Index) := l_Exp_Item_Date;
1788         G_Project_Number_Tbl(G_Trx_Import_Index) := Null;
1789         G_Project_Id_Tbl(G_Trx_Import_Index) := l_Proj_Id;
1790         G_Task_Number_Tbl(G_Trx_Import_Index) := Null;
1791         G_Task_Id_Tbl(G_Trx_Import_Index) := l_Task_Id;
1792         G_Expenditure_Type_Tbl(G_Trx_Import_Index) := l_Exp_Type;
1793         G_System_Linkage_Tbl(G_Trx_Import_Index) := l_Sys_Link;
1794         G_Non_Labor_Resource_Tbl(G_Trx_Import_Index) := Null;
1795         G_Non_Labor_Res_Org_Name_Tbl(G_Trx_Import_Index) := Null;
1796         G_Non_Labor_Res_Org_Id_Tbl(G_Trx_Import_Index) := Null;
1797         G_Quantity_Tbl(G_Trx_Import_Index) := l_Quantity;
1798         G_Raw_Cost_Tbl(G_Trx_Import_Index) := Null;
1799         G_Raw_Cost_Rate_Tbl(G_Trx_Import_Index) := Null;
1800         G_Burden_Cost_Tbl(G_Trx_Import_Index) := Null;
1801         G_Burden_Cost_Rate_Tbl(G_Trx_Import_Index) := Null;
1802         G_Expenditure_Comment_Tbl(G_Trx_Import_Index) := l_Exp_Comment;
1803         G_Gl_Date_Tbl(G_Trx_Import_Index) := Null;
1804         G_Transaction_Status_Code_Tbl(G_Trx_Import_Index) := 'P';
1805         G_Trans_Rejection_Code_Tbl(G_Trx_Import_Index) := Null;
1806         G_Orig_Trans_Reference_Tbl(G_Trx_Import_Index) := P_New_Orig_Trx_Ref;
1807         G_Unmatched_Neg_Txn_Flag_Tbl(G_Trx_Import_Index) := 'N';
1808         G_Expenditure_Id_Tbl(G_Trx_Import_Index) := Null;
1809         G_Attribute_Category_Tbl(G_Trx_Import_Index) := l_Attribute_Category;
1810         G_Attribute1_Tbl(G_Trx_Import_Index) := l_Attribute1;
1811         G_Attribute2_Tbl(G_Trx_Import_Index) := l_Attribute2;
1812         G_Attribute3_Tbl(G_Trx_Import_Index) := l_Attribute3;
1813         G_Attribute4_Tbl(G_Trx_Import_Index) := l_Attribute4;
1814         G_Attribute5_Tbl(G_Trx_Import_Index) := l_Attribute5;
1815         G_Attribute6_Tbl(G_Trx_Import_Index) := l_Attribute6;
1816         G_Attribute7_Tbl(G_Trx_Import_Index) := l_Attribute7;
1817         G_Attribute8_Tbl(G_Trx_Import_Index) := l_Attribute8;
1818         G_Attribute9_Tbl(G_Trx_Import_Index) := l_Attribute9;
1819         G_Attribute10_Tbl(G_Trx_Import_Index) :=l_Attribute10;
1820         G_Dr_Code_Combination_Id_Tbl(G_Trx_Import_Index) := Null;
1821         G_Cr_Code_Combination_Id_Tbl(G_Trx_Import_Index) := Null;
1822         G_Cdl_System_Reference1_Tbl(G_Trx_Import_Index) := Null;
1823         G_Cdl_System_Reference2_Tbl(G_Trx_Import_Index) := Null;
1824         G_Cdl_System_Reference3_Tbl(G_Trx_Import_Index) := Null;
1825         G_Interface_Id_Tbl(G_Trx_Import_Index) := P_Xface_Id;
1826         G_Receipt_Currency_Amount_Tbl(G_Trx_Import_Index) := Null;
1827         G_Receipt_Currency_Code_Tbl(G_Trx_Import_Index) := Null;
1828         G_Receipt_Exchange_Rate_Tbl(G_Trx_Import_Index) := Null;
1829         G_Denom_Currency_Code_Tbl(G_Trx_Import_Index) := Null;
1830         G_Denom_Raw_Cost_Tbl(G_Trx_Import_Index) := Null;
1831         G_Denom_Burdened_Cost_Tbl(G_Trx_Import_Index) := Null;
1832         G_Acct_Rate_Date_Tbl(G_Trx_Import_Index) := Null;
1833         G_Acct_Rate_Type_Tbl(G_Trx_Import_Index) := Null;
1834         G_Acct_Exchange_Rate_Tbl(G_Trx_Import_Index) := Null;
1835         G_Acct_Raw_Cost_Tbl(G_Trx_Import_Index) := Null;
1836         G_Acct_Burdened_Cost_Tbl(G_Trx_Import_Index) := Null;
1837         G_Acct_Exch_Rounding_Limit_Tbl(G_Trx_Import_Index) := Null;
1838         G_Project_Currency_Code_Tbl(G_Trx_Import_Index) := Null;
1839         G_Project_Rate_Date_Tbl(G_Trx_Import_Index) := Null;
1840         G_Project_Rate_Type_Tbl(G_Trx_Import_Index) := Null;
1841         G_Project_Exchange_Rate_Tbl(G_Trx_Import_Index) := Null;
1842         G_Orig_Exp_Txn_Reference1_Tbl(G_Trx_Import_Index) := P_Orig_Exp_Txn_Reference1;
1843         G_Orig_Exp_Txn_Reference2_Tbl(G_Trx_Import_Index) := Null;
1844         G_Orig_Exp_Txn_Reference3_Tbl(G_Trx_Import_Index) := Null;
1845         G_Orig_User_Exp_Txn_Ref_Tbl(G_Trx_Import_Index) := Null;
1846         G_Vendor_Number_Tbl(G_Trx_Import_Index) := Null;
1847         G_Vendor_Id_Tbl(G_Trx_Import_Index) := l_Vendor_Id; -- PA.M/CWK changes
1848         G_Override_To_Org_Name_Tbl(G_Trx_Import_Index) := Null;
1849         G_Override_To_Org_Id_Tbl(G_Trx_Import_Index) := Null;
1850         G_Reversed_Orig_Txn_Ref_Tbl(G_Trx_Import_Index) := P_Old_Orig_Trx_Ref;
1851         G_Billable_Flag_Tbl(G_Trx_Import_Index) := l_Billable_Flag;
1852         G_ProjFunc_Currency_Code_Tbl(G_Trx_Import_Index) := Null;
1853         G_ProjFunc_Cost_Rate_Date_Tbl(G_Trx_Import_Index) := Null;
1854         G_ProjFunc_Cost_Rate_Type_Tbl(G_Trx_Import_Index) := Null;
1855         G_ProjFunc_Cost_Exch_Rate_Tbl(G_Trx_Import_Index) := Null;
1856         G_Project_Raw_Cost_Tbl(G_Trx_Import_Index) := Null;
1857         G_Project_Burdened_Cost_Tbl(G_Trx_Import_Index) := Null;
1858         G_Assignment_Name_Tbl(G_Trx_Import_Index) := Null;
1859         G_Assignment_Id_Tbl(G_Trx_Import_Index) := l_Assignment_Id;
1860         G_Work_Type_Name_Tbl(G_Trx_Import_Index) := Null;
1861         G_Work_Type_Id_Tbl(G_Trx_Import_Index) := l_Work_Type_Id;
1862         G_Cdl_System_Reference4_Tbl(G_Trx_Import_Index) := Null;
1863         G_Accrual_Flag_Tbl(G_Trx_Import_Index) := Null;
1864         G_Last_Update_Date_Tbl(G_Trx_Import_Index) := SysDate;
1865         G_Last_Updated_By_Tbl(G_Trx_Import_Index) := P_User_Id;
1866         G_Creation_Date_Tbl(G_Trx_Import_Index) := SysDate;
1867         G_Created_By_Tbl(G_Trx_Import_Index) := P_User_Id;
1868 	    -- Begin CWK changes PA.M
1869 	    G_PO_Number_Tbl(G_Trx_Import_Index) := Null;
1870 	    G_PO_Header_Id_Tbl(G_Trx_Import_Index) := l_PO_Header_Id;
1871 	    G_PO_Line_Num_Tbl(G_Trx_Import_Index) := Null;
1872 	    G_Person_Type_Tbl(G_Trx_Import_Index) := l_Person_Type;
1873 	    G_PO_Line_Id_Tbl(G_Trx_Import_Index) := l_PO_Line_Id;
1874 	    G_PO_Price_Type_Tbl(G_Trx_Import_Index) := l_PO_Price_Type;
1875 	    -- End CWK changes PA.M
1876 	    G_INVENTORY_ITEM_ID_Tbl(G_Trx_Import_Index) := Null;
1877 	    G_WIP_RESOURCE_ID_Tbl(G_Trx_Import_Index) := Null;
1878     	G_UNIT_OF_MEASURE_Tbl(G_Trx_Import_Index) := Null;
1879         -- 12i MOAC changes
1880         G_OU_Tbl(G_Trx_Import_Index) := l_org_id;
1881         -- bug 10253400: Payroll integration enhancement for 12.2..start
1882         G_Job_Id_Tbl(G_Trx_Import_Index) := l_job_id;
1883         G_Location_Id_Tbl(G_Trx_Import_Index) := l_location_id;
1884         G_Job_Name_Tbl(G_Trx_Import_Index) := NULL;
1885         G_Location_Code_tbl(G_Trx_Import_Index) := NULL;
1886         G_Pay_Element_Type_Id_tbl(G_Trx_Import_Index) := l_pay_element_type_id;
1887         -- bug 10253400: Payroll integration enhancement for 12.2..end
1888 
1889          -- Start: Added for CBS Enhancement Bug 16220146
1890     		G_Cbs_Element_Id_Tbl(G_Trx_Import_Index) := l_Cbs_Element_Id;
1891     		G_Cbs_Element_Name_Tbl(G_Trx_Import_Index) := NULL;
1892     		-- End: Added for CBS Enhancement Bug 16220146
1893 
1894 	    G_Txn_Rec_Count := Nvl(G_Txn_Rec_Count,0) + 1;
1895 
1896 	    G_Stage := 'About to leave Build_Reverse_Item(), strip procedure from trackpath.';
1897         If G_Debug_Mode = 'Y' Then
1898            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1899            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1900         End If;
1901 	    Pa_Otc_Api.TrackPath('STRIP','Build_Reverse_Item');
1902 
1903 	G_Stage := 'Leaving Build_Reverse_Item().';
1904         If G_Debug_Mode = 'Y' Then
1905            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1906            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1907         End If;
1908 
1909    Exception
1910 	When others then
1911 		Raise;
1912 
1913    End Build_Reverse_Item;
1914 
1915 
1916 -- =======================================================================
1917 -- Start of Comments
1918 -- API Name      : UpdateChangedOrigTxn
1919 -- Type          : Private
1920 -- Pre-Reqs      : None
1921 -- Type          : Procedure
1922 -- Function      : This procedure is used to update the expenditure item directly
1923 --                 for an item that has not being reversed but ONLY the
1924 --                 item comment has been changed and/or the DFF has been changed.
1925 --                 No record will be inserted into table pa_transaction_interface.
1926 --
1927 --       Values for parameter P_Comment_or_Dff
1928 --       -------------------------------------
1929 --                 C for Comment
1930 --                 D for Dff
1931 --                 --B for Both
1932 --                 P for Payroll Element
1933 --                 CD for Comments and DFFs
1934 --                 CP for Comments and Payroll Element
1935 --                 DP for DFFs and Payroll Element
1936 --                 CDP for Comments, DFFs and Payroll Elements
1937 --
1938 -- Parameters    :
1939 -- IN            P_Old_Orig_Txn_Ref   - Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE
1940 --               P_New_Orig_Txn_Ref   - Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE
1941 --               P_Comment_Or_Dff     - Varchar2(1)
1942 --               P_Timecard_Rec       - Pa_Otc_Api.Timecard_Rec
1943 --               P_User_Id            - Pa_Expenditure_Items_All.Last_Updated_By%TYPE
1944 --
1945 -- OUT           NONE
1946 --
1947 
1948 /*--------------------------------------------------------------------------*/
1949 
1950    Procedure  UpdateChangedOrigTxn(
1951                P_Old_Orig_Txn_Ref   IN Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE,
1952                P_New_Orig_Txn_Ref   IN Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE,
1953                P_Comment_Or_Dff     IN Varchar2,
1954 	           P_Timecard_Rec       IN Pa_Otc_Api.Timecard_Rec,
1955 	           P_User_Id            IN Pa_Expenditure_Items_All.Last_Updated_By%TYPE)
1956 
1957    Is
1958 
1959         l_Exp_Item_Id 	    Pa_Expenditure_Items_All.Expenditure_Item_Id%TYPE := Null;
1960 	    l_RowId             RowId;
1961 	    l_Last_Update_Login Pa_Expenditure_Items_All.Last_Update_Login%TYPE := to_Number(Fnd_Profile.Value('LOGIN_ID'));
1962         --Added for bug 4105561
1963         x_request_id               NUMBER(15);
1964         x_program_application_id   NUMBER(15);
1965         x_program_id               NUMBER(15);
1966 
1967         Cursor CheckExpComment (P_Ei_Id IN Number) Is
1968         Select
1969                Count(*)
1970         From
1971                Pa_Expenditure_Comments
1972         Where
1973                Expenditure_Item_Id = P_Ei_Id;
1974 
1975 	    l_Comment_Count     Number := 0;
1976 
1977    Begin
1978 
1979 	    G_Stage := 'Entering UpdateChangedOrigTxn(), add procedure to trackpath.';
1980         If G_Debug_Mode = 'Y' Then
1981            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1982            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1983         End If;
1984 	    Pa_Otc_Api.TrackPath('ADD','UpdateChangedOrigTxn');
1985 
1986 	    G_Stage := 'Get Expenditure Item Id.';
1987         If G_Debug_Mode = 'Y' Then
1988            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
1989            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
1990         End If;
1991 
1992 	    Select
1993 		       RowId,
1994 		       Expenditure_Item_Id
1995 	    Into
1996 		       l_RowId,
1997 		       l_Exp_Item_Id
1998 	    From
1999 		       Pa_Expenditure_Items_All
2000 	    Where
2001 		       Transaction_Source = 'ORACLE TIME AND LABOR'
2002 	    And     Orig_Transaction_Reference = P_Old_Orig_Txn_Ref
2003 	    And	Net_Zero_Adjustment_Flag = 'N'; -- Bug 3480159
2004 
2005             --Added for bug 4105561
2006             X_request_id := FND_GLOBAL.CONC_REQUEST_ID ;
2007             X_program_id := FND_GLOBAL.CONC_PROGRAM_ID  ;
2008             X_program_application_id := FND_GLOBAL.PROG_APPL_ID ;
2009 
2010 	    /* Though the if clause below requires more code, it is
2011 	     * faster code due to potentially less updates taking place
2012 	     * when P_Comment_Or_Dff has a value of B.
2013 	     */
2014 	    G_Stage := 'What updating needs to be done.';
2015         If G_Debug_Mode = 'Y' Then
2016            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2017            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2018         End If;
2019 
2020 		/* 12.2 payroll intg .. rewrote the logic to use the new values for p_comment_or_dff.
2021 		   Based on the combinations possible the code logic is changed */
2022 
2023 	    If P_Comment_Or_Dff in ('C', 'CD', 'CP', 'CDP') Then
2024 
2025 		    G_Stage := 'P_Comment_Or_Dff Is C: Update ei table.';
2026         	If G_Debug_Mode = 'Y' Then
2027         	Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2028         	   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2029         	End If;
2030 
2031 		    Update Pa_Expenditure_Items_All
2032 		    Set Orig_Transaction_Reference = P_New_Orig_Txn_Ref,
2033 		        Last_Updated_By            = P_User_Id,
2034 		        Last_Update_Date           = SysDate,
2035 		        Last_Update_Login          = l_Last_Update_Login,
2036                         Request_id                 = x_request_id,        --Added for bug 4105561
2037                         Program_application_id     = x_program_application_id,
2038                         Program_id                 = x_program_id,
2039                         Program_update_date        = sysdate
2040 		    Where Rowid = l_RowId ;
2041 
2042 		    Open CheckExpComment (P_Ei_Id => l_Exp_Item_Id);
2043 		    Fetch CheckExpComment into l_Comment_Count;
2044 		    Close CheckExpComment;
2045 
2046 		    --If l_Comment_Count = 0 Then
2047 		    If (l_Comment_Count = 0 AND P_Timecard_Rec.Expenditure_Item_Comment IS NOT NULL) Then /* Bug 8885514 */
2048 
2049 			    G_Stage := 'P_Comment_Or_Dff Is C: Insert record into exp comment table.';
2050                 If G_Debug_Mode = 'Y' Then
2051                      Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2052                      pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2053                 End If;
2054 
2055 			    Insert into Pa_Expenditure_Comments
2056 			    (  	Expenditure_Item_Id,
2057  				    Line_Number,
2058  				    Last_Update_Date,
2059  				    Last_Updated_By,
2060  				    Creation_Date,
2061  				    Created_By,
2062  				    Expenditure_Comment,
2063  				    Last_Update_Login,
2064  				    Request_Id,
2065  				    Program_Id,
2066  				    Program_Application_Id,
2067  				    Program_Update_Date )
2068 			    Values (
2069 				    l_Exp_Item_Id,
2070 				    10,
2071 				    SysDate,
2072 				    P_User_Id,
2073 				    SysDate,
2074 				    P_User_Id,
2075 				    P_Timecard_Rec.Expenditure_Item_Comment,
2076 				    l_Last_Update_Login,
2077 		       		    X_request_id,   --Added for bug 4105561
2078 				    X_program_id,
2079 				    X_program_application_id,
2080 				    sysdate);
2081 
2082 		    ElsIf l_Comment_Count > 0 And P_Timecard_Rec.Expenditure_Item_Comment Is Not Null Then  -- Bug 3496762
2083 
2084 			    G_Stage := 'P_Comment_Or_Dff Is C: Update exp comment table.';
2085 			    If G_Debug_Mode = 'Y' Then
2086         		   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2087         		   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2088         		End If;
2089 
2090 			    Update Pa_Expenditure_Comments
2091 			    Set Expenditure_Comment   = P_Timecard_Rec.Expenditure_Item_Comment,
2092 			        Last_Updated_By       = P_User_Id,
2093 			        Last_Update_Date      = SysDate,
2094 			        Last_Update_Login     = l_Last_Update_Login,
2095                                 Request_id            = x_request_id,        --Added for bug 4105561
2096                                 Program_application_id= x_program_application_id,
2097                                 Program_id            = x_program_id,
2098                                 Program_update_date   = sysdate
2099 			    Where Expenditure_Item_Id = l_exp_item_id ;
2100 
2101             ElsIf l_Comment_Count > 0 And P_Timecard_Rec.Expenditure_Item_Comment Is Null Then
2102 
2103                 G_Stage := 'P_Comment_Or_Dff Is B: Remove exp comment from table since comment has been updated to null by the user.';
2104                 If G_Debug_Mode = 'Y' Then
2105                     Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2106                     pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2107                 End If;
2108 
2109                 Delete From Pa_Expenditure_Comments
2110                 Where Expenditure_Item_Id = l_Exp_Item_Id ;
2111 
2112 		    End If;
2113 
2114 	    End If;
2115 
2116 	    If P_Comment_Or_Dff in ('D', 'CD', 'DP', 'CDP') Then
2117 
2118 		    G_Stage := 'P_Comment_Or_Dff Is D: Update ei table.';
2119 		    If G_Debug_Mode = 'Y' Then
2120         	   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2121         	   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2122         	End If;
2123 
2124 		    Update Pa_Expenditure_Items_All
2125 		    Set Orig_Transaction_Reference = P_New_Orig_Txn_Ref,
2126 		        Attribute_category         = P_Timecard_Rec.Attribute_Category,
2127 		        Attribute1                 = P_Timecard_Rec.Attribute1,
2128                 Attribute2                 = P_Timecard_Rec.Attribute2,
2129                 Attribute3                 = P_Timecard_Rec.Attribute3,
2130                 Attribute4                 = P_Timecard_Rec.Attribute4,
2131                 Attribute5                 = P_Timecard_Rec.Attribute5,
2132                 Attribute6                 = P_Timecard_Rec.Attribute6,
2133                 Attribute7                 = P_Timecard_Rec.Attribute7,
2134                 Attribute8                 = P_Timecard_Rec.Attribute8,
2135                 Attribute9                 = P_Timecard_Rec.Attribute9,
2136                 Attribute10                = P_Timecard_Rec.Attribute10,
2137 	            Last_Updated_By            = P_User_Id,
2138                 Last_Update_Date           = SysDate,
2139                 Last_Update_Login          = l_Last_Update_Login,
2140                 Request_id                 = x_request_id,
2141                 Program_application_id     = x_program_application_id,
2142                 Program_id                 = x_program_id,
2143 		        Program_update_date        = sysdate
2144             Where RowId = l_RowId ;
2145 
2146 	    End If;
2147 
2148 	    If P_Comment_Or_Dff in ('P', 'CP', 'DP', 'CDP') Then
2149 
2150 		    G_Stage := 'P_Comment_Or_Dff Is P: Update ei table.';
2151 		    If G_Debug_Mode = 'Y' Then
2152         	   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2153         	   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2154         	End If;
2155 
2156 		    Update Pa_Expenditure_Items_All
2157 		    Set pay_element_type_id        = P_Timecard_Rec.Pay_Element_Type_Id,
2158 		        Orig_Transaction_Reference = P_New_Orig_Txn_Ref,
2159 	            Last_Updated_By            = P_User_Id,
2160                 Last_Update_Date           = SysDate,
2161                 Last_Update_Login          = l_Last_Update_Login,
2162                 Request_id                 = x_request_id,
2163                 Program_application_id     = x_program_application_id,
2164                 Program_id                 = x_program_id,
2165 		        Program_update_date        = sysdate
2166             Where RowId = l_RowId ;
2167 
2168 	    End If;
2169 
2170 	    G_Stage := 'Leaving UpdateChangedOrigTxn(), strip procedure from trackpath.';
2171 	    Pa_Otc_Api.TrackPath('STRIP','UpdateChangedOrigTxn');
2172         If G_Debug_Mode = 'Y' Then
2173 	        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2174             pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2175         End If;
2176 
2177    Exception
2178 	When Others Then
2179 		Raise;
2180 
2181    End UpdateChangedOrigTxn;
2182 
2183 
2184 -- =======================================================================
2185 -- Start of Comments
2186 -- API Name      : Tieback_Otc_Timecards
2187 -- Type          : Public
2188 -- Pre-Reqs      : None
2189 -- Type          : Procedure
2190 -- Function      : This procedure is used to tieback timecards that have been
2191 --                 interfaced to Oracle Projects successfully. This procedure
2192 --                 will stamp the OTL timecard transaction status PL/SQL arrays with the fact that
2193 --                 timecards retrieved have been sucessfully imported.
2194 --                 We do not plan to deal with any exception handling so the transaction exception
2195 --                 arrays will not be used.  This is a entry point from the Trx Import
2196 --                 post_import extension.
2197 --                 We will use the transaction_source and P_Xface_Id and transaction_status_code of 'I'
2198 --                 to pull the data from the interface table for review.
2199 -- Parameters    :
2200 -- IN
2201 --           P_Transaction_source: Unique identifier for source of the txn
2202 --           P_batch: Batch Name to group txns into batches
2203 --           P_xface_id: Interface Id
2204 --           P_user_id: User Id
2205 -- OUT
2206 --   none
2207 /*--------------------------------------------------------------------------*/
2208 
2209    Procedure  Tieback_Otc_Timecards (
2210 				  P_Transaction_Source IN Pa_Transaction_Interface_All.Transaction_Source%TYPE,
2211                                   P_Batch              IN Pa_Transaction_Interface_All.Batch_Name%TYPE,
2212                                   P_Xface_Id           IN Pa_Transaction_Interface_All.Txn_Interface_Id%TYPE,
2213                                   P_User_Id            IN Number)
2214 
2215    Is
2216 
2217 	Cursor TrxRecords (P_Interface_Id IN Pa_Transaction_Interface_All.Interface_Id%TYPE) Is
2218 	Select To_Number(Substr(Orig_Transaction_Reference,1,Instr(Orig_Transaction_Reference,':') - 1)) Detail_BB_Id,
2219 	       Transaction_Status_Code,
2220 	       Transaction_Rejection_Code,
2221 	       Txn_Interface_Id,
2222 	       Expenditure_Id,
2223 	       Expenditure_Item_Id,
2224 	       Orig_Transaction_Reference,
2225 	       Person_Id
2226 	From
2227 	       Pa_Transaction_Interface
2228 	Where
2229 	       Interface_Id = P_Interface_Id
2230 	And    Transaction_Source = 'ORACLE TIME AND LABOR'
2231 	And    Transaction_Status_Code in ('I','R')
2232 	And    Pa_Otc_Api.TrxInCurrentChunk(To_Number(Substr(Orig_Transaction_Reference,1,Instr(Orig_Transaction_Reference,':') - 1))) = 'Y'
2233 	Order by 7,3; -- Bug 3355510
2234 
2235 	TrxRecord        TrxRecords%ROWTYPE;
2236 	l_Detail_Index   Binary_Integer := Null;
2237 	j                Binary_Integer := Null;
2238 
2239    Begin
2240 
2241 	G_Path := ' ';
2242 
2243 	G_Stage := 'Entering Tieback_Otc_Timecards().';
2244 	If G_Debug_Mode = 'Y' Then
2245            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2246            Pa_CC_Utils.Log_Message(Pa_Debug.G_Err_Stage,0);
2247         End If;
2248 	Pa_Otc_Api.TrackPath('ADD','Tieback_Otc_Timecards');
2249 
2250 	G_Stage := 'Open cursor TrxRecords.';
2251 	If G_Debug_Mode = 'Y' Then
2252            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2253            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2254         End If;
2255 
2256 	Open TrxRecords(P_Interface_Id => P_Xface_Id);
2257 
2258 	G_Stage := 'Looping thru the Trx Records.';
2259 	Loop
2260 
2261 		G_Stage := 'Fetch record from cursor TrxRecs.';
2262 		If G_Debug_Mode = 'Y' Then
2263         	   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2264         	   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2265         	End If;
2266 
2267 		Fetch TrxRecords Into TrxRecord;
2268 		Exit When TrxRecords%Notfound;
2269 
2270 		If TrxRecord.Transaction_Status_Code = 'I' Then
2271 
2272                     G_Stage := 'Update Detail Status to SUCCESS for BB_Id: ' || to_char(TrxRecord.Detail_BB_Id) ||
2273                                ' Index position is: ' || to_char((G_Trx_Inserted_Tab(TrxRecord.Detail_BB_Id).BB_Index));
2274 		    If G_Debug_Mode = 'Y' Then
2275                        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2276                        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2277                     End If;
2278 		    Hxc_User_Type_Definition_Grp.T_Tx_Detail_Status(G_Trx_Inserted_Tab(TrxRecord.Detail_BB_Id).BB_Index) :=
2279 										'SUCCESS';
2280 
2281 		ElsIf TrxRecord.Transaction_Status_Code = 'R' Then
2282 
2283                     G_Stage := 'Update Detail Status to ERRORS for BB_Id: ' || to_char(TrxRecord.Detail_BB_Id) ||
2284                                ' Index position is: ' || to_char((G_Trx_Inserted_Tab(TrxRecord.Detail_BB_Id).BB_Index));
2285 		    If G_Debug_Mode = 'Y' Then
2286                        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2287                        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2288                     End If;
2289 
2290 		    /* Since we now have the looping functionality in Trx Import and we can't restrict the cursor
2291 		     * more than it currently is.  We have to make sure that we don't try to update rejected
2292 		     * Trx records from other loops that have already been ran.  They are at a status of 'R'
2293 		     * So we check to first see if it exists in the pl/sql table and then if it does
2294 		     * we update the otl pl/sql table accordingly run.
2295 		     */
2296 
2297                    Hxc_User_Type_Definition_Grp.T_Tx_Detail_Status(G_Trx_Inserted_Tab(TrxRecord.Detail_BB_Id).BB_Index) := 'ERRORS';
2298 
2299 		   If TrxRecord.Transaction_Rejection_Code is not null Then
2300 
2301 			Fnd_Message.Set_Name('PA', TrxRecord.Transaction_Rejection_Code);
2302 		   	Hxc_User_Type_Definition_Grp.T_Tx_Detail_Exception(G_Trx_Inserted_Tab(TrxRecord.Detail_BB_Id).BB_Index) :=
2303  					Substr(Fnd_Message.Get,1,2000);
2304 
2305 -- Begin Bug 3355510 Don't needed to explicitly set the value to null with by default it already is.  This was the problem.
2306 --		   Else
2307 --
2308 --		   	Hxc_User_Type_Definition_Grp.T_Tx_Detail_Exception(G_Trx_Inserted_Tab(TrxRecord.Detail_BB_Id).BB_Index) := Null;
2309 -- End Bug 3355510
2310 
2311 		   End If;
2312 
2313 		End If;
2314 
2315                 G_Stage := 'Tieback Results are Bb_Id/Ovn: ' || TrxRecord.Orig_Transaction_Reference ||
2316                    	   ' Status(I is Success,R is Errors): ' || TrxRecord.Transaction_Status_Code ||
2317 			   ' Exception: ' || TrxRecord.Transaction_Rejection_Code ||
2318                            ' Resource_Id(Person_Id): ' || TrxRecord.Person_Id ||
2319                            ' Exp_Id(Null when Errors): ' || to_char(TrxRecord.Expenditure_Id) ||
2320                            ' Ei_Id(Null when Errors): ' || to_char(TrxRecord.Expenditure_Item_Id);
2321                 Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Stage;
2322                 pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,1);
2323 
2324 	End Loop;
2325 
2326 	G_Stage := 'Loop is done so lose cursor TrxRecs.';
2327 	If G_Debug_Mode = 'Y' Then
2328            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2329            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2330         End If;
2331 
2332 	Close TrxRecords;
2333 
2334 	G_Stage := 'Update the Transaction_Status_Code for successful transactions in interface table.';
2335 	If G_Debug_Mode = 'Y' Then
2336            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2337            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2338         End If;
2339 
2340 	Update Pa_Transaction_Interface
2341 	Set
2342               Transaction_Status_Code = 'A'
2343 	Where
2344               Interface_Id = P_Xface_Id
2345 	And   Transaction_Status_Code = 'I';
2346 
2347 	G_Stage := 'Loop thru and flag as success those building blocks where we directly updated the eis.';
2348 	If G_Debug_Mode = 'Y' Then
2349            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2350            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2351         End If;
2352 
2353 	If G_Trx_Direct_Upd_Tab.COUNT > 0 Then
2354 
2355 	    Loop
2356 
2357                 If j is null then
2358 
2359                          j := G_Trx_Direct_Upd_Tab.First;
2360 
2361 		Else
2362 
2363 			/* The use of NEXT allows us to avoid going thru pl/sql records that do not exist.
2364 			 * The pl/sql table will likely be sparcely populated and only want to deal with those
2365 			 * records that were inserted.
2366 			 * DO NOT CHANGE THIS SO WE DO NOT GET ANY NO_DATA_FOUND ERRORS.
2367 			 */
2368 			j := G_Trx_Direct_Upd_Tab.Next(j);
2369 
2370                 End If;
2371 
2372                 G_Stage := 'Update Detail Status to SUCCESS for direct updated ei BB_Id: ' || to_char(j) ||
2373                            '  Index position is: ' || to_char((G_Trx_Direct_Upd_Tab(j).BB_Index));
2374 		If G_Debug_Mode = 'Y' Then
2375                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2376                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2377                 End If;
2378 
2379                 Hxc_Generic_Retrieval_Pkg.T_Tx_Detail_Status(G_Trx_Direct_Upd_Tab(j).BB_Index) := 'SUCCESS';
2380 		EXIT when j = G_Trx_Direct_Upd_Tab.Last;
2381 
2382 	    End Loop;
2383 
2384 	End If;
2385 
2386 	G_Stage := 'Call OTL API to update transactions';
2387 	If G_Debug_Mode = 'Y' Then
2388            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2389            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2390         End If;
2391 
2392        	Hxc_Integration_Layer_V1_Grp.Set_Parent_Statuses;
2393 	Hxc_Integration_Layer_V1_Grp.Update_Transaction_Status (
2394 				    P_Process               => 'Projects Retrieval Process',
2395                                     P_Status                => 'SUCCESS',
2396                                     P_Exception_Description => NULL);
2397 
2398         G_Stage := 'Set the process import looping flag to true since completed at least loop thru.';
2399 	If G_Debug_Mode = 'Y' Then
2400            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2401            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2402         End If;
2403 	-- G_Processed_Import_Batch effects exception handling in the Upload_Otc_Timecard() procedure.
2404 	-- When G_Processed_Import_Batch is TRUE then the exception handler in Upload_Otc_Timecard()
2405 	-- will ignore 2 HXC exceptions that are thrown when there are no records found by the
2406 	-- HXC Generic Retreival Process to pull for Import.
2407 	G_Processed_Import_Batch := TRUE;
2408 
2409 	G_Stage := 'Leaving Tieback_Otc_Timecards(), strip procedure from trackpath.';
2410 	If G_Debug_Mode = 'Y' Then
2411            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2412            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,1);
2413         End If;
2414 	Pa_Otc_Api.TrackPath('STRIP','Tieback_Otc_Timecards');
2415 
2416    Exception
2417         When Others Then
2418 		Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage || ' : ' || SQLERRM;
2419                 Hxc_Integration_Layer_V1_Grp.Update_Transaction_Status (
2420                                     P_Process               => 'Projects Retrieval Process',
2421                                     P_Status                => 'ERRORS',
2422                                     P_Exception_Description => Pa_Debug.G_err_Stage);
2423                 RAISE;
2424 
2425    End Tieback_Otc_Timecards;
2426 
2427 -- =======================================================================
2428 -- Start of Comments
2429 -- API Name      : DetermineDirectUpdate
2430 -- Type          : Private
2431 -- Pre-Reqs      : None
2432 -- Type          : Procedure
2433 -- Function      : This procedure determines if the expenditure item should be updated directly
2434 --               : or if a reversing entry and a new entry neeed to be inserted into table
2435 --               : pa_transaction_interface_all.  This is done by comparing to see what has
2436 --               : actually changed.  If only the dff and/or the item comment has changed and
2437 --               : nothing else then the item should be directly updated.
2438 --
2439 -- Parameters    :
2440 -- IN
2441 --                P_New_Timecard_Rec  - Pa_Otc_Api.Timecard_Rec
2442 --                P_Old_Timecard_Rec  - Pa_Otc_Api.Timecard_Rec
2443 -- OUT
2444 --                P_Direct_Update_Flag - Boolean
2445 --  /* Commenting for 12.2 as there is an additional condition that need to be returned
2446 --     for p_comment_or_dff. The below values are not applicable.
2447 --                P_comment_or_dff     - Varchar2
2448 --                   B - Both comment and DFFs
2449 --                   C - Comment only
2450 --                   D - DFFs only
2451 --  If the pay element changes, we'll consider it like a comment change
2452 --  and not reverse the item. To accommodate this, the following values are used:
2453 --  p_comment_or_dff variable name is retained, but the values for this are:
2454 --
2455 --          C  - Comment Only
2456 --          D  - DFFs only
2457 --          P  - Pay Element changed
2458 --          CD - Comment and DFF changed
2459 --          CP - Comment and Pay Element changed
2460 --          CDP- Comment, DFF and Pay element all changed
2461 --          DP - DFF and Pay Element changed
2462 --
2463 -- */
2464 /*--------------------------------------------------------------------------*/
2465 
2466   Procedure DetermineDirectUpdate(
2467 			P_New_Timecard_Rec   IN         Pa_Otc_Api.Timecard_Rec,
2468 			P_Old_Timecard_Rec   IN         Pa_Otc_Api.Timecard_Rec,
2469                         P_Direct_Update_Flag OUT NOCOPY Boolean,
2470                         P_Comment_Or_Dff     OUT NOCOPY Varchar2) IS
2471 
2472 	l_Others_Changed  Boolean := False;
2473 	l_Comment_Changed Boolean := False;
2474 	l_DFFs_Changed    Boolean := False;
2475 	/* 12.2 payroll intg change */
2476 	l_PayElem_Changed Boolean := False;
2477 
2478   Begin
2479 	P_Direct_Update_Flag := True; /*Added for bug 13831042*/
2480 
2481 	G_Stage := 'Entering DetermineDirectUpdate(), add procedure to trackpath.';
2482 	If G_Debug_Mode = 'Y' Then
2483            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2484            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2485         End If;
2486 	Pa_Otc_Api.TrackPath('ADD','DetermineDirectUpdate');
2487 
2488 	If P_New_Timecard_Rec.Project_Id              <> P_Old_Timecard_Rec.Project_Id OR  -- bug 3241052
2489 	   P_New_Timecard_Rec.Task_Id                 <> P_Old_Timecard_Rec.Task_Id OR     -- changed from number to id
2490 	   P_New_Timecard_Rec.Expenditure_Type        <> P_Old_Timecard_Rec.Expenditure_Type OR
2491 	   P_New_Timecard_Rec.Expenditure_Item_Date   <> P_Old_Timecard_Rec.Expenditure_Item_Date OR
2492 	   P_New_Timecard_Rec.System_Linkage_Function <> P_Old_Timecard_Rec.System_Linkage_Function OR
2493 	   P_New_Timecard_Rec.Quantity                <> P_Old_Timecard_Rec.Quantity OR
2494 	   P_New_Timecard_Rec.Billable_Flag           <> P_Old_Timecard_Rec.Billable_Flag OR
2495        Nvl(P_New_Timecard_Rec.PO_Line_Id,-99999)  <> Nvl(P_Old_Timecard_Rec.PO_Line_Id,-99999) OR
2496        Nvl(P_New_Timecard_Rec.PO_Price_Type,'-99999') <> Nvl(P_Old_Timecard_Rec.PO_Price_Type,'-99999') --Then
2497        -- bug 10253400: Payroll integration enhancement for 12.2..start
2498        OR
2499        Nvl(P_New_Timecard_Rec.Job_Id, -99)        <> Nvl(P_Old_Timecard_Rec.Job_Id, -99) OR
2500        Nvl(P_New_Timecard_Rec.Work_Type_Id, -99)        <> Nvl(P_Old_Timecard_Rec.Work_Type_Id, -99) OR
2501        Nvl(P_New_Timecard_Rec.Location_Id, -99)        <> Nvl(P_Old_Timecard_Rec.Location_Id, -99) -- THEN
2502        -- bug 10253400: Payroll integration enhancement for 12.2..end
2503 	   OR Nvl(P_New_Timecard_Rec.Cbs_Element_Id, -99)  <> Nvl(P_Old_Timecard_Rec.Cbs_Element_Id, -99) THEN -- Added as part of bug 16794323
2504 
2505 		G_Stage := 'Detail has changed.';
2506 		If G_Debug_Mode = 'Y' Then
2507         	   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2508         	   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2509         	End If;
2510 
2511 		l_Others_Changed := True;
2512 
2513 	End If;
2514 
2515 	If nvl(P_New_Timecard_Rec.Expenditure_Item_Comment,'-9999999999') <>
2516 						nvl(P_Old_Timecard_Rec.Expenditure_Item_Comment,'-9999999999') Then
2517 
2518 		G_Stage := 'Comment has changed.';
2519 		If G_Debug_Mode = 'Y' Then
2520         	   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2521         	   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2522         	End If;
2523 
2524 		l_Comment_Changed := True;
2525 
2526 	End If;
2527 
2528     /* 12.2 payroll intg .. verify a change to the pay element.. start */
2529 	If nvl(P_New_Timecard_Rec.Pay_Element_Type_Id,-999) <>
2530 						       nvl(P_Old_Timecard_Rec.Pay_Element_Type_Id,-999) Then
2531 
2532 		G_Stage := 'Pay Element has changed.';
2533 		If G_Debug_Mode = 'Y' Then
2534         	   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2535         	   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2536         	End If;
2537 
2538 		l_PayElem_Changed := True;
2539 
2540 	End If;
2541     /* 12.2 payroll intg .. verify a change to the pay element.. end */
2542 
2543 	If nvl(P_New_Timecard_Rec.Attribute_Category,'-9999999999') <>
2544 						       nvl(P_Old_Timecard_Rec.Attribute_Category,'-9999999999') OR
2545 	   nvl(P_New_Timecard_Rec.Attribute1,'-9999999999') <> nvl(P_Old_Timecard_Rec.Attribute1,'-9999999999') OR
2546            nvl(P_New_Timecard_Rec.Attribute2,'-9999999999') <> nvl(P_Old_Timecard_Rec.Attribute2,'-9999999999') OR
2547            nvl(P_New_Timecard_Rec.Attribute3,'-9999999999') <> nvl(P_Old_Timecard_Rec.Attribute3,'-9999999999') OR
2548            nvl(P_New_Timecard_Rec.Attribute4,'-9999999999') <> nvl(P_Old_Timecard_Rec.Attribute4,'-9999999999') OR
2549            nvl(P_New_Timecard_Rec.Attribute5,'-9999999999') <> nvl(P_Old_Timecard_Rec.Attribute5,'-9999999999') OR
2550            nvl(P_New_Timecard_Rec.Attribute6,'-9999999999') <> nvl(P_Old_Timecard_Rec.Attribute6,'-9999999999') OR
2551            nvl(P_New_Timecard_Rec.Attribute7,'-9999999999') <> nvl(P_Old_Timecard_Rec.Attribute7,'-9999999999') OR
2552            nvl(P_New_Timecard_Rec.Attribute8,'-9999999999') <> nvl(P_Old_Timecard_Rec.Attribute8,'-9999999999') OR
2553            nvl(P_New_Timecard_Rec.Attribute9,'-9999999999') <> nvl(P_Old_Timecard_Rec.Attribute9,'-9999999999') OR
2554            nvl(P_New_Timecard_Rec.Attribute10,'-9999999999') <> nvl(P_Old_Timecard_Rec.Attribute10,'-9999999999') Then
2555 
2556 		G_Stage := 'DFFs have changed.';
2557 		If G_Debug_Mode = 'Y' Then
2558         	   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2559         	   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2560         	End If;
2561 
2562 		l_DFFs_Changed := True;
2563 
2564 	End If;
2565 
2566 	G_Stage := 'Determine change flag value.';
2567 
2568 	If l_Others_Changed Then
2569 
2570 		G_Stage := 'No Direct Update.';
2571 		If G_Debug_Mode = 'Y' Then
2572         	   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2573         	   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2574         	End If;
2575 		/* No direct update since other columns have been updated besides
2576 		 * the comments and DFFs.
2577 		 */
2578 		P_Direct_Update_Flag := FALSE;
2579 
2580      -- 12.2 payroll intg .. adding additional condition for pay element also
2581 	ElsIf Not l_Others_Changed And (l_Comment_Changed Or l_DFFs_Changed Or l_PayElem_Changed) Then
2582 
2583 		-- Looks like the comment or DFFS where updated in
2584 		-- OTL so will do direct updating of the tables instead of
2585 		-- using TRX_IMPORT.
2586 		--
2587 
2588 		G_Stage := 'Direct Update.';
2589 		If G_Debug_Mode = 'Y' Then
2590         	   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2591         	   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2592        	End If;
2593 
2594 		P_Direct_Update_Flag := TRUE;
2595 
2596 		If (l_Comment_Changed And Not l_DFFs_Changed and Not l_PayElem_Changed) Then
2597 			G_Stage := 'Comments alone changed.';
2598 			If G_Debug_Mode = 'Y' Then
2599         		   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2600         		   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2601         	End If;
2602 			--
2603 			P_Comment_Or_Dff := 'C';
2604 			--
2605 		ElsIf (Not l_Comment_Changed And l_DFFs_Changed and Not l_PayElem_Changed) Then
2606 			G_Stage := 'DFFs alone changed.';
2607 			If G_Debug_Mode = 'Y' Then
2608         		   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2609         		   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2610         		End If;
2611 			--
2612 			P_Comment_Or_Dff := 'D';
2613 			--
2614 		ElsIf (Not l_Comment_Changed And Not l_DFFs_Changed and l_PayElem_Changed) Then
2615 			G_Stage := 'Pay Element alone changed.';
2616 			If G_Debug_Mode = 'Y' Then
2617         		   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2618         		   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2619         		End If;
2620 			--
2621 			P_Comment_Or_Dff := 'P';
2622 			--
2623 		ElsIf (l_Comment_Changed And l_DFFs_Changed and Not l_PayElem_Changed) Then
2624 			G_Stage := 'Comments and DFFs both changed.';
2625 			If G_Debug_Mode = 'Y' Then
2626         		   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2627         		   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2628         		End If;
2629 			--
2630 			P_Comment_Or_Dff := 'CD';
2631 			--
2632 		ElsIf (l_Comment_Changed And Not l_DFFs_Changed and l_PayElem_Changed) Then
2633 			G_Stage := 'Comments and Pay Element both changed.';
2634 			If G_Debug_Mode = 'Y' Then
2635         		   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2636         		   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2637         		End If;
2638 			--
2639 			P_Comment_Or_Dff := 'CP';
2640 			--
2641 		ElsIf (Not l_Comment_Changed And l_DFFs_Changed and l_PayElem_Changed) Then
2642 			G_Stage := 'DFFs and Pay Element both changed.';
2643 			If G_Debug_Mode = 'Y' Then
2644         		   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2645         		   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2646         		End If;
2647 			--
2648 			P_Comment_Or_Dff := 'DP';
2649 			--
2650 		ElsIf (l_Comment_Changed And l_DFFs_Changed and l_PayElem_Changed) Then
2651 
2652 			G_Stage := 'All three changed.';
2653 			If G_Debug_Mode = 'Y' Then
2654         		   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2655         		   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2656         		End If;
2657 			--
2658 			P_Comment_Or_Dff := 'CDP';
2659 			--
2660 		End If;
2661 
2662 	End If;
2663 
2664 	G_Stage := 'Leaving DetermineDirectUpdate(), strip procedure from trackpath.';
2665 	If G_Debug_Mode = 'Y' Then
2666            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2667            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2668         End If;
2669 	Pa_Otc_Api.TrackPath('STRIP','DetermineDirectUpdate');
2670 
2671   Exception
2672 	When Others Then
2673 		Raise;
2674 
2675   End DetermineDirectUpdate;
2676 
2677 
2678 -- =======================================================================
2679 -- Start of Comments
2680 -- API Name      : PopulateProjRec
2681 -- Type          : Private
2682 -- Pre-Reqs      : None
2683 -- Type          : Procedure
2684 -- Function      : This procedure pulls all the data from the OTL pl/sql tables into a projects
2685 --               : oriented structure for easier processing.  It will also get the TIME scope
2686 --               : BB_ID to be stored table pa_expenditures_all.orig_exp_txn_reference1.
2687 --
2688 -- Parameters    :
2689 -- IN
2690 --                P_New_Old_BB   -  Varchar2   Allowed Values:
2691 --						Import values:  'OLD' 'NEW'
2692 --						Validation value:
2693 --                P_BB_Id        -  Hxc_Time_Building_Blocks.Time_Building_Block_Id%TYPE
2694 --                P_Detail_Index -  Binary_Integer
2695 --                P_Old_Detl_Ind -  Binary_Integer
2696 -- OUT
2697 --                P_Timecard_Rec -  Pa_Otc_Api.Timecard_Rec
2698 --
2699 /*--------------------------------------------------------------------------*/
2700 
2701   Procedure PopulateProjRec(
2702      P_New_Old_BB   IN         Varchar2,
2703      P_BB_Id        IN         Hxc_Time_Building_Blocks.Time_Building_Block_Id%TYPE,
2704 	 P_Detail_Index IN         Binary_Integer,
2705 	 P_Old_Detl_Ind IN         Binary_Integer,
2706      P_Timecard_Rec OUT NOCOPY Pa_Otc_Api.Timecard_Rec) IS -- 2672653
2707 
2708 	l_attribute_category Varchar2(100)    := NULL;
2709 	i                    Binary_Integer;
2710 	j                    Binary_Integer;
2711 	l_Rec_Found          Boolean          := False;
2712 	l_error_text         Varchar2(1800)   := Null;
2713 	l_Status_Code        Varchar2(40)     := Null;
2714     l_comment_text       VARCHAR2(2000)   := Null; -- bug 5412033
2715 	-- Start: Added for CBS Enhancement Bug 16220146
2716 	l_Actual_Task_Id     Number           := Null;
2717 	l_Cbs_Element_Id     Number           := Null;
2718 	-- End: Added for CBS Enhancement Bug 16220146
2719 
2720   Begin
2721 
2722 	G_Stage := 'Entering PopulateProjRec(), add procedure to trackpath.';
2723 	If G_Debug_Mode = 'Y' Then
2724 	     Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2725          pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2726     End If;
2727 	Pa_Otc_Api.TrackPath('ADD','PopulateProjRec');
2728 
2729     G_Stage := 'Set Timecard Rec to NULL.';
2730 	If G_Debug_Mode = 'Y' Then
2731          Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2732          pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2733     End If;
2734 
2735 	P_Timecard_Rec := Null;
2736 
2737     G_Stage := 'The current Detail Building Block Id being processed is: ' || to_char(P_BB_Id);
2738 	If G_Debug_Mode = 'Y' Then
2739          Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2740          pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2741     End If;
2742 
2743 	G_Stage := 'Checking if processsing new or old Building Block.';
2744 	If G_Debug_Mode = 'Y' Then
2745          Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2746          pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2747     End If;
2748 
2749     If P_New_Old_BB = 'NEW' Then
2750 
2751          G_Stage := 'Get New Detail Building Block data. Inc by person id(Resource Id): ' ||
2752 			        to_char(Hxc_Generic_Retrieval_Pkg.T_Detail_Bld_Blks(P_Detail_Index).Resource_Id);
2753 		 If G_Debug_Mode = 'Y' Then
2754 		      Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2755         	  pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2756          End If;
2757 
2758 		 P_Timecard_Rec.Incurred_By_Person_Id := Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(P_Detail_Index).Resource_Id;
2759 
2760 		 G_Stage := 'Get New Detail Building Block data. Quantity: ' ||
2761                     to_char(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(P_Detail_Index).Measure);
2762 		 If G_Debug_Mode = 'Y' Then
2763 		      Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2764         	  pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2765          End If;
2766 
2767 		 P_Timecard_Rec.Quantity := Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(P_Detail_Index).Measure;
2768 
2769          /* begin bug 5412033 */
2770 		 G_Stage := 'Get New Detail Building Block data. Expenditure Item Comment: ' ||
2771 			        Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(P_Detail_Index).Comment_Text ||
2772                     '(End of comment)';
2773 		 If G_Debug_Mode = 'Y' Then
2774               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2775               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2776          End If;
2777 
2778          G_Stage := 'Assigning comment to local variable.';
2779          If G_Debug_Mode = 'Y' Then
2780               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2781               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2782          End If;
2783          l_comment_text := Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(P_Detail_Index).Comment_Text;
2784 
2785          G_Stage := 'Checking if comment is not null.';
2786          If G_Debug_Mode = 'Y' Then
2787               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2788               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2789          End If;
2790 
2791          If l_comment_text is not Null Then
2792 
2793               G_Stage := 'The comment is not null so determine the length of comment.';
2794               If G_Debug_Mode = 'Y' Then
2795                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2796                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2797               End If;
2798 
2799               /* Bug 2930551 If the length of the comment_text is greater than 240 then we should only
2800                              grab the first 240 characters. */
2801               -- begin bug 4926265
2802               -- If length(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(P_Detail_Index).Comment_Text) > 240 Then
2803               -- If lengthb(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(P_Detail_Index).Comment_Text) > 240 Then
2804               If lengthb(l_comment_text) > 240 Then
2805 
2806                    If G_Debug_Mode = 'Y' Then
2807                         G_Stage := 'Comment_Text length > 240.';
2808                         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2809                         pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2810                    End If;
2811 
2812                    -- P_Timecard_Rec.Expenditure_Item_Comment :=
2813                    --      substr(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(P_Detail_Index).Comment_Text,1,240);
2814                    -- P_Timecard_Rec.Expenditure_Item_Comment :=
2815                    --      substrb(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(P_Detail_Index).Comment_Text,1,240);
2816                    -- end bug 4926265
2817                    P_Timecard_Rec.Expenditure_Item_Comment := substrb(l_comment_text,1,240);
2818 
2819               Else
2820 
2821                    If G_Debug_Mode = 'Y' Then
2822                         G_Stage := 'Comment_Text length <= 240.';
2823                         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2824                         pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2825                    End If;
2826 
2827                    -- P_Timecard_Rec.Expenditure_Item_Comment :=
2828                    --      Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(P_Detail_Index).Comment_Text;
2829                    P_Timecard_Rec.Expenditure_Item_Comment := l_comment_text;
2830 
2831               End If;
2832 
2833          Else -- l_comment_text is Null
2834 
2835               If G_Debug_Mode = 'Y' Then
2836                    G_Stage := 'Setting the comment to null.';
2837                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2838                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2839               End If;
2840               P_Timecard_Rec.Expenditure_Item_Comment := Null;
2841 
2842          End If; -- l_comment_text is not Null
2843          /* End bug 5412033 */
2844 
2845          G_Stage := 'Get New Detail Building Block data. Exp Item Date, first attempt.';
2846 		 If G_Debug_Mode = 'Y' Then
2847               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2848               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2849          End If;
2850 
2851 		 P_Timecard_Rec.Expenditure_Item_Date :=
2852 						TRUNC(Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(P_Detail_Index).Start_Time);
2853 
2854 		 If P_Timecard_Rec.Expenditure_Item_Date Is Null Then
2855 
2856 		      G_Stage := 'Get New Detail Building Block data. Exp Item Date, second attempt.';
2857 			  If G_Debug_Mode = 'Y' Then
2858 			       Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2859 			       pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2860 			  End If;
2861 
2862 			  i := 1;
2863 
2864               G_Stage := 'Get New Detail Building Block data. Exp Item Date, via day scope building block.';
2865 			  If G_Debug_Mode = 'Y' Then
2866                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2867                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2868               End If;
2869 
2870 			  While   i <= Hxc_User_Type_Definition_Grp.T_Day_Bld_Blks.LAST and NOT l_Rec_Found
2871               Loop
2872 
2873                    G_Stage := 'Check if the current record is the correct DAY ' ||
2874 					          'record to grab Exp Item Date from.';
2875                    If G_Debug_Mode = 'Y' Then
2876                         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2877                         pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2878                    End If;
2879 
2880                    If Hxc_User_Type_Definition_Grp.T_Day_Bld_Blks(i).BB_Id =
2881 					  Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(P_Detail_Index).Parent_BB_Id Then
2882 
2883                         G_Stage := 'Grab the Exp Item Date from new day building block record.';
2884                         If G_Debug_Mode = 'Y' Then
2885                              Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2886                              pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2887                         End If;
2888 
2889                         P_Timecard_Rec.Expenditure_Item_Date := Trunc(Hxc_User_Type_Definition_Grp.T_Day_Bld_Blks(i).Start_Time);
2890 					    l_Rec_Found := TRUE;
2891 
2892                    End If;
2893 
2894 				   i := i + 1;
2895 
2896         	  End Loop;
2897 
2898 		 End If;  -- P_Timecard_Rec.Expenditure_Item_Date Is Null
2899 
2900          G_Stage := 'Exp Item Date(Detail Building Block Start Time): ' || to_char(P_Timecard_Rec.Expenditure_Item_Date);
2901 		 If G_Debug_Mode = 'Y' Then
2902               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2903               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2904          End If;
2905 
2906          G_Stage := 'Get Expenditure Ending Date from new building block data.';
2907          If G_Debug_Mode = 'Y' Then
2908               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2909               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2910          End If;
2911 
2912 		 If P_Timecard_Rec.Expenditure_Item_Date is not null Then
2913 
2914        	      P_Timecard_Rec.Expenditure_Ending_date :=
2915 			  Pa_Utils.NewGetWeekEnding(P_Timecard_Rec.Expenditure_Item_Date);
2916 
2917 		 End If;
2918 
2919 		 -- Begin PA.M/CWK changes
2920 		 -- The person type can be returned as null and will be handled later in the code.
2921 		 G_Stage := 'Get Person_Type New.';
2922 		 If G_Debug_Mode = 'Y' Then
2923               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2924               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2925          End If;
2926 
2927 		 P_Timecard_Rec.Person_Type := GetPersonType(P_Person_Id => P_Timecard_Rec.Incurred_By_Person_Id,
2928 							                         P_Ei_Date   => P_Timecard_Rec.Expenditure_Item_Date);
2929 
2930          G_Stage := 'New Person_Type: ' || P_Timecard_Rec.Person_Type;
2931          If G_Debug_Mode = 'Y' Then
2932               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2933               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2934          End If;
2935 		 -- End PA.M/CWK changes
2936 
2937 		 /* Pull data from the new detail_attributes pl/sql table */
2938 		 G_Stage := 'Get NEW detail bb attribution using for loop.';
2939 		 If G_Debug_Mode = 'Y' Then
2940               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2941               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2942          End If;
2943 
2944          If G_Detail_Attr_Index = 0 Then
2945 
2946               G_Detail_Attr_Index := 1;
2947 
2948          End If;
2949 
2950          i := G_Detail_Attr_Index;
2951 
2952 		 G_Stage := 'Looping thru NEW attibution starting at index position: ' || to_char(i) ;
2953 		 If G_Debug_Mode = 'Y' Then
2954 		      Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2955         	  pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2956          End If;
2957 
2958 		 G_Stage := 'Current position in NEW attribute pl/sql table bb_id value is: ' ||
2959 			        to_char(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).BB_Id);
2960          If G_Debug_Mode = 'Y' Then
2961               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2962               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2963          End If;
2964 
2965 		 While   i <= Hxc_User_Type_Definition_Grp.T_Detail_Attributes.LAST And
2966 			     Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).BB_Id = P_BB_Id
2967 		 Loop
2968 
2969 		      If Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'PROJECT_ID' Then
2970 
2971 		           G_Stage := 'Retrieved Project Id: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
2972                               '  Index position: ' || to_char(i);
2973 		           If G_Debug_Mode = 'Y' Then
2974 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2975         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2976         	       End If;
2977 
2978                    P_Timecard_Rec.Project_Id := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
2979 
2980 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'TASK_ID' Then
2981 
2982                    G_Stage := 'Retrieved Task Id: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
2983 				     	     '  Index position: ' || to_char(i);
2984 			       If G_Debug_Mode = 'Y' Then
2985 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
2986         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
2987         	       End If;
2988 
2989         	       P_Timecard_Rec.Task_Id := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
2990 
2991 				   -- Start: Added for CBS Enhancement Bug 16220146
2992 				   If P_Timecard_Rec.Project_Id Is Not Null And P_Timecard_Rec.Task_Id Is Not Null Then
2993 
2994 					  If PA_ALTERNATE_TASK_PVT.Is_Cbs_Enabled(P_Timecard_Rec.Project_Id) = 'Y' Then
2995 
2996 					     Begin
2997 
2998 						    Select Proj_Element_Id, Cbs_Element_Id
2999 							Into l_Actual_Task_Id, l_Cbs_Element_Id
3000 							From Pa_Alternate_Tasks
3001 							Where Alt_Task_Id = P_Timecard_Rec.Task_Id;
3002 
3003 							P_Timecard_Rec.Task_Id        := l_Actual_Task_Id;
3004 							P_Timecard_Rec.Cbs_Element_Id := l_Cbs_Element_Id;
3005 
3006 						   G_Stage := 'Retrieved Actual Task Id: ' || l_Actual_Task_Id ||' Retrieved Cbs Element Id: ' || l_Cbs_Element_Id || '  Index position: ' || to_char(i);
3007 						   If G_Debug_Mode = 'Y' Then
3008 								Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3009 								pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3010 						   End If;
3011 
3012 						 Exception
3013 						    When Others Then
3014 						       l_Actual_Task_Id := Null;
3015 							   l_Cbs_Element_Id := Null;
3016 							   P_Timecard_Rec.Task_Id        := Null;
3017 							   P_Timecard_Rec.Cbs_Element_Id := Null;
3018 							   Raise;
3019 						 End;
3020 					  Else
3021 					     P_Timecard_Rec.Cbs_Element_Id := Null;
3022 					  End If;
3023 				   End If;
3024 				   -- End: Added for CBS Enhancement Bug 16220146
3025 
3026 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'EXPENDITURE_TYPE' Then
3027 
3028                    G_Stage := 'Retrieved Expenditure Type: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3029 			 	     	      '  Index position: ' || to_char(i);
3030 			       If G_Debug_Mode = 'Y' Then
3031 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3032         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3033         	       End If;
3034 
3035 			       P_Timecard_Rec.Expenditure_Type := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3036 
3037 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'SYSTEM_LINKAGE_FUNCTION' Then
3038 
3039                    G_Stage := 'Retrieve System Linkage Function: ' ||
3040                               Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3041                               '  Index position: ' || to_char(i);
3042 			       If G_Debug_Mode = 'Y' Then
3043 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3044         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3045         	       End If;
3046 
3047 	               P_Timecard_Rec.System_Linkage_Function := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3048 
3049       	      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'OVERRIDING_APPROVER_PERSON_ID' Then
3050 
3051                    G_Stage := 'Retrieve Overidding Approver Person Id: ' ||
3052                               Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3053                               '  Index position: ' || to_char(i);
3054 			       If G_Debug_Mode = 'Y' Then
3055 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3056         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3057         	       End If;
3058 
3059 	 		       P_Timecard_Rec.Override_Approver_Person_Id := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3060 
3061 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'DUMMY PAEXPITDFF CONTEXT' Then
3062 
3063 			       /* The value column contains the following format:
3064 			        *   'PAEXPITDFF - <attribute_category>'
3065 			        * So to get the attribute_category out will need to find the position
3066                     * for ' - ' that is: '<space>-<space>' and then add 3.
3067 			        */
3068 
3069                    G_Stage := 'Get new attribute category: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3070                               '  Index position: ' || to_char(i);
3071 			       If G_Debug_Mode = 'Y' Then
3072                         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3073                         pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3074                    End If;
3075 
3076 			       l_attribute_category := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3077 
3078                    /* Need to check for null so as to avoid the unecessary use of errors using instr
3079                     * to avoid unhandled exceptions.
3080                     */
3081 
3082 			       G_Stage := 'Get new attribute category, checking if Null.';
3083 			       If G_Debug_Mode = 'Y' Then
3084 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3085         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3086         	       End If;
3087 
3088 			       If l_attribute_category is not null Then
3089 
3090 			            G_Stage := 'Get new attribute category, Strip out prefix.';
3091 				        If G_Debug_Mode = 'Y' Then
3092 					         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3093         				     pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3094         		        End If;
3095 
3096         		        P_Timecard_Rec.Attribute_Category := substr(l_attribute_category,instr(l_attribute_category,' - ') + 3);
3097 
3098 			       End If;
3099 
3100 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'PADFFATTRIBUTE1' Then
3101 
3102                    G_Stage := 'Got new attribute1: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3103                               '  Index position: ' || to_char(i);
3104 			       If G_Debug_Mode = 'Y' Then
3105 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3106         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3107         	       End If;
3108 
3109 			       P_Timecard_Rec.Attribute1 := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3110 
3111 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'PADFFATTRIBUTE2' Then
3112 
3113                    G_Stage := 'Got new attribute2: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3114                               '  Index position: ' || to_char(i);
3115 			       If G_Debug_Mode = 'Y' Then
3116 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3117         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3118         	       End If;
3119 
3120         	       P_Timecard_Rec.Attribute2 := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3121 
3122 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'PADFFATTRIBUTE3' Then
3123 
3124                    G_Stage := 'Got new attribute3: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3125                               '  Index position: ' || to_char(i);
3126 			       If G_Debug_Mode = 'Y' Then
3127 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3128         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3129         	       End If;
3130 
3131         	       P_Timecard_Rec.Attribute3 := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3132 
3133 	          ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'PADFFATTRIBUTE4' Then
3134 
3135                    G_Stage := 'Got new attribute4: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3136                               '  Index position: ' || to_char(i);
3137 			       If G_Debug_Mode = 'Y' Then
3138 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3139         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3140         	       End If;
3141 
3142         	       P_Timecard_Rec.Attribute4 := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3143 
3144 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'PADFFATTRIBUTE5' Then
3145 
3146                    G_Stage := 'Got new attribute5: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3147                               '  Index position: ' || to_char(i);
3148 		           If G_Debug_Mode = 'Y' Then
3149 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3150         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3151         	       End If;
3152 
3153         	       P_Timecard_Rec.Attribute5 := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3154 
3155 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'PADFFATTRIBUTE6' Then
3156 
3157                    G_Stage := 'Got new attribute6: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3158                               '  Index position: ' || to_char(i);
3159 			       If G_Debug_Mode = 'Y' Then
3160 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3161         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3162           	       End If;
3163 
3164         	       P_Timecard_Rec.Attribute6 := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3165 
3166 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'PADFFATTRIBUTE7' Then
3167 
3168                    G_Stage := 'Got new attribute7: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3169                               '  Index position: ' || to_char(i);
3170 			       If G_Debug_Mode = 'Y' Then
3171 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3172         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3173         	       End If;
3174 
3175         	       P_Timecard_Rec.Attribute7 := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3176 
3177 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'PADFFATTRIBUTE8' Then
3178 
3179                    G_Stage := 'Got new attribute8: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3180                               '  Index position: ' || to_char(i);
3181 			       If G_Debug_Mode = 'Y' Then
3182 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3183         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3184         	       End If;
3185 
3186         	       P_Timecard_Rec.Attribute8 := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3187 
3188 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'PADFFATTRIBUTE9' Then
3189 
3190                    G_Stage := 'Got new attribute9: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3191                               '  Index position: ' || to_char(i);
3192 			       If G_Debug_Mode = 'Y' Then
3193 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3194         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3195         	       End If;
3196 
3197         	       P_Timecard_Rec.Attribute9 := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3198 
3199 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'PADFFATTRIBUTE10' Then
3200 
3201                    G_Stage := 'Got new attribute10: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3202                               '  Index position: ' || to_char(i);
3203 			       If G_Debug_Mode = 'Y' Then
3204 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3205         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3206         	       End If;
3207 
3208         	       P_Timecard_Rec.Attribute10 := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3209 
3210 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'BILLABLE_FLAG' Then
3211 
3212                    G_Stage := 'Got new Billable Flag: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3213                               '  Index position: ' || to_char(i);
3214 			       If G_Debug_Mode = 'Y' Then
3215 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3216         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3217         	       End If;
3218 
3219            	       P_Timecard_Rec.Billable_Flag := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3220 
3221 		      -- Begin PA.M/CWK changes
3222 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'PO LINE ID' Then
3223 
3224                    G_Stage := 'Retrieved Po Line Id: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3225 					          '  Index position: ' || to_char(i);
3226 			       If G_Debug_Mode = 'Y' Then
3227 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3228         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3229         	       End If;
3230 
3231         	       P_Timecard_Rec.PO_Line_Id := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3232 
3233 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'PO PRICE TYPE' Then
3234 
3235                    G_Stage := 'Retrieved Po Price Type: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3236 					          '  Index position: ' || to_char(i);
3237 			       If G_Debug_Mode = 'Y' Then
3238 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3239         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3240         	       End If;
3241 
3242         	       P_Timecard_Rec.PO_Price_Type := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3243 
3244 		      -- End PA.M/CWK changes
3245               -- bug 10253400: Payroll integration enhancement for 12.2..start
3246 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'JOB_ID' Then
3247 
3248                    G_Stage := 'Retrieved Job ID: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3249 					          '  Index position: ' || to_char(i);
3250 			       If G_Debug_Mode = 'Y' Then
3251 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3252         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3253         	       End If;
3254 
3255         	       P_Timecard_Rec.Job_id := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3256 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'LOCATION_ID' Then
3257 
3258                    G_Stage := 'Retrieved Location ID: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3259 					          '  Index position: ' || to_char(i);
3260 			       If G_Debug_Mode = 'Y' Then
3261 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3262         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3263         	       End If;
3264 
3265         	       P_Timecard_Rec.Location_Id := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3266 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'WORKTYPE_ID' Then
3267 
3268                    G_Stage := 'Retrieved Work Type ID: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3269 					          '  Index position: ' || to_char(i);
3270 			       If G_Debug_Mode = 'Y' Then
3271 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3272         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3273         	       End If;
3274 
3275         	       P_Timecard_Rec.Work_Type_Id := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3276 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Field_Name) = 'DUMMY ELEMENT CONTEXT' Then
3277 
3278 			       /* The value column contains the following format:
3279 			        *   'ELEMENT - <attribute_category>'
3280 			        * So to get the attribute_category out will need to find the position
3281                     * for ' - ' that is: '<space>-<space>' and then add 3.
3282 			        */
3283 
3284                    G_Stage := 'Get new attribute category: ' || Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value ||
3285                               '  Index position: ' || to_char(i);
3286 			       If G_Debug_Mode = 'Y' Then
3287                         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3288                         pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3289                    End If;
3290 
3291 			       l_attribute_category := Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).Value;
3292 
3293                    /* Need to check for null so as to avoid the unecessary use of errors using instr
3294                     * to avoid unhandled exceptions.
3295                     */
3296 
3297 			       G_Stage := 'Get new attribute category, checking if Null.';
3298 			       If G_Debug_Mode = 'Y' Then
3299 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3300         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3301         	       End If;
3302 
3303 			       If l_attribute_category is not null Then
3304 
3305 			            G_Stage := 'Get new attribute category, Strip out prefix.';
3306 				        If G_Debug_Mode = 'Y' Then
3307 					         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3308         				     pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3309         		        End If;
3310 
3311         		        P_Timecard_Rec.Pay_Element_Type_Id := substr(l_attribute_category,instr(l_attribute_category,' - ') + 3);
3312                   End If;
3313 
3314 
3315               -- bug 10253400: Payroll integration enhancement for 12.2..end
3316 
3317 		      End If;
3318 
3319 		      i := i + 1;
3320 
3321 		 End Loop;
3322 
3323 		 G_Stage := 'Exited loop.  No more NEW attribution for BB_Id. Store the current index position ' ||
3324 			        to_char(i) || ' in global variable.';
3325 		 If G_Debug_Mode = 'Y' Then
3326 		      Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3327         	  pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3328          End If;
3329 
3330 		 /* Note that variable G_Detail_Attr_Index is already pointing the the next building block.
3331 		  * This is due to the fact that we are using the while/loop structure and only leaving the loop
3332 		  * when the building block ids no longer match or have reach the end of the pl/sql table.
3333 		  */
3334 
3335 		 G_Detail_Attr_Index := i;
3336 
3337 		 G_Stage := 'Determine why exited loop looking for NEW record attribution.';
3338          If G_Debug_Mode = 'Y' Then
3339               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3340               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3341          End If;
3342 
3343          If i > Hxc_User_Type_Definition_Grp.T_Detail_Attributes.LAST Then
3344 
3345 		      G_Stage := 'Reached last record index position ' ||
3346 			             to_char(Hxc_User_Type_Definition_Grp.T_Detail_Attributes.LAST) || ' ' ||
3347 				         'in NEW attrib pl/sql table.';
3348               If G_Debug_Mode = 'Y' Then
3349                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3350                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3351               End If;
3352 
3353 		 ElsIf Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).BB_Id <> P_BB_Id Then
3354 
3355 		      G_Stage := 'P_BB_Id: ' || to_char(P_BB_Id) || ' --  ' ||
3356 				         'BB_Id in NEW attrib pl/sql: ' ||
3357 				         to_char(Hxc_User_Type_Definition_Grp.T_Detail_Attributes(i).BB_Id) || '.  ' ||
3358 				         'They do not match!';
3359               If G_Debug_Mode = 'Y' Then
3360                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3361                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3362               End If;
3363 
3364 		 End If;
3365 
3366 		 -- Begin PA.M/CWK changes
3367          G_Stage := 'Check Person Type is CWK and PO_Line_Id is Not Null New.';
3368          If G_Debug_Mode = 'Y' Then
3369               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3370               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3371          End If;
3372 
3373 		 If P_Timecard_Rec.Person_Type = 'CWK' and P_Timecard_Rec.PO_Line_Id is Not Null Then
3374 
3375               G_Stage := 'Calling Pa_Otc_Api.GetPOInfo() procedure New.';
3376               If G_Debug_Mode = 'Y' Then
3377                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3378                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3379               End If;
3380 
3381 			  Pa_Otc_Api.GetPOInfo(
3382                          P_Po_Line_Id   => P_Timecard_Rec.PO_Line_Id,
3383 				  	     X_PO_Header_Id => P_Timecard_Rec.PO_Header_Id,
3384 				  	     X_Vendor_Id    => P_Timecard_Rec.Vendor_Id);
3385 
3386 			  G_Stage := 'Got new Vendor Id: ' || to_char(P_Timecard_Rec.Vendor_Id) || ' based on PO_Line_Id';
3387 			  If G_Debug_Mode = 'Y' Then
3388 			       Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3389         		   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3390         	  End If;
3391 
3392 		 Else
3393 
3394               G_Stage := 'Set to null po info, vendor_id, and price_type New.';
3395               If G_Debug_Mode = 'Y' Then
3396                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3397                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3398               End If;
3399 			  P_Timecard_Rec.PO_Line_Id := NULL;
3400 			  P_Timecard_Rec.PO_Header_Id := NULL;
3401 			  P_Timecard_Rec.Vendor_Id := NULL;
3402 			  P_Timecard_Rec.PO_Price_Type := NULL;
3403 
3404 		 End If;
3405 		 -- End PA.M/CWK changes
3406 
3407     Elsif P_New_Old_BB = 'OLD' Then
3408 
3409 		 G_Stage := 'Got Old Detail Building Block data. Incurred by Person Id(Resource Id): ' ||
3410 			        to_char(Hxc_User_Type_Definition_Grp.T_Old_Detail_Bld_Blks(P_Old_Detl_Ind).Resource_Id);
3411 		 If G_Debug_Mode = 'Y' Then
3412 		      Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3413         	  pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3414          End If;
3415 
3416          P_Timecard_Rec.Incurred_By_Person_Id := Hxc_User_Type_Definition_Grp.T_Old_Detail_Bld_Blks(P_Old_Detl_Ind).Resource_Id;
3417 
3418          G_Stage := 'Got Old Detail Building Block data. Incurred by Person Id';
3419 		 If G_Debug_Mode = 'Y' Then
3420               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3421               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3422          End If;
3423 
3424          G_Stage := 'Got Old Detail Building Block data. Quantity: ' ||
3425 			        to_char(Hxc_User_Type_Definition_Grp.T_Old_Detail_Bld_Blks(P_Old_Detl_Ind).Measure);
3426 		 If G_Debug_Mode = 'Y' Then
3427               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3428               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3429          End If;
3430 
3431          P_Timecard_Rec.Quantity := Hxc_User_Type_Definition_Grp.T_Old_Detail_Bld_Blks(P_Old_Detl_Ind).Measure;
3432 
3433          /* Begin bug 5412033 */
3434 		 G_Stage := 'Get Old Detail Building Block data. Expenditure Item Comment: ' ||
3435 			        Hxc_User_Type_Definition_Grp.T_Old_Detail_Bld_Blks(P_Old_Detl_Ind).Comment_Text ||
3436                     '(End of comment)';
3437 		 If G_Debug_Mode = 'Y' Then
3438               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3439               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3440          End If;
3441 
3442          G_Stage := 'Assigning Old comment to local variable.';
3443          If G_Debug_Mode = 'Y' Then
3444               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3445               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3446          End If;
3447          l_comment_text := Hxc_User_Type_Definition_Grp.T_Old_Detail_Bld_Blks(P_Old_Detl_Ind).Comment_Text;
3448 
3449          G_Stage := 'Checking if Old comment is not null.';
3450          If G_Debug_Mode = 'Y' Then
3451               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3452               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3453          End If;
3454 
3455          If l_comment_text is not Null Then
3456 
3457               G_Stage := 'The old comment is not null so determine the length of comment.';
3458               If G_Debug_Mode = 'Y' Then
3459                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3460                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3461               End If;
3462 
3463               /* Bug 2930551 If the length of the comment_text is greater than 240 then we should only
3464                              grab the first 240 characters. */
3465               -- begin bug 4926265
3466               -- If length(Hxc_User_Type_Definition_Grp.T_Old_Detail_Bld_Blks(P_Old_Detl_Ind).Comment_Text) > 240 Then
3467               -- If lengthb(Hxc_User_Type_Definition_Grp.T_Old_Detail_Bld_Blks(P_Old_Detl_Ind).Comment_Text) > 240 Then
3468               If lengthb(l_comment_text) > 240 Then
3469 
3470                    If G_Debug_Mode = 'Y' Then
3471                         G_Stage := 'Old Comment_Text length > 240.';
3472                         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3473                         pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3474                    End If;
3475 
3476                    -- P_Timecard_Rec.Expenditure_Item_Comment :=
3477                    --      substr(Hxc_User_Type_Definition_Grp.T_Old_Detail_Bld_Blks(P_Old_Detl_Ind).Comment_Text,1,240);
3478                    -- P_Timecard_Rec.Expenditure_Item_Comment :=
3479                    --      substrb(Hxc_User_Type_Definition_Grp.T_Old_Detail_Bld_Blks(P_Old_Detl_Ind).Comment_Text,1,240);
3480                    -- end bug 4926265
3481                    P_Timecard_Rec.Expenditure_Item_Comment := substrb(l_comment_text,1,240);
3482 
3483               Else
3484 
3485                    If G_Debug_Mode = 'Y' Then
3486                         G_Stage := 'Old Comment_Text length <= 240.';
3487                         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3488                         pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3489                    End If;
3490 
3491                    -- P_Timecard_Rec.Expenditure_Item_Comment :=
3492                    --      Hxc_User_Type_Definition_Grp.T_Old_Detail_Bld_Blks(P_Old_Detl_Ind).Comment_Text;
3493                    P_Timecard_Rec.Expenditure_Item_Comment := l_comment_text;
3494 
3495               End If;
3496 
3497          Else -- l_comment_text is null
3498 
3499               If G_Debug_Mode = 'Y' Then
3500                    G_Stage := 'Setting the Old comment to null.';
3501                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3502                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3503               End If;
3504               P_Timecard_Rec.Expenditure_Item_Comment := Null;
3505 
3506          End If; -- l_comment_text is not Null
3507          /* End Bug 5412033 */
3508 
3509          G_Stage := 'Get Old Day Building Block data. Exp Item Date. First Attempt.';
3510 		 If G_Debug_Mode = 'Y' Then
3511               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3512               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3513          End If;
3514 
3515                 /* added Trunc function for bug 9793882 */
3516 		 P_Timecard_Rec.Expenditure_Item_Date := trunc(Hxc_User_Type_Definition_Grp.T_Old_Detail_Bld_Blks(P_Old_Detl_Ind).Start_Time);
3517 
3518 		 If P_Timecard_Rec.Expenditure_Item_Date Is Null Then
3519 
3520 		      G_Stage := 'Get Old Day Building Block data. Exp Item Date. Second Attempt.';
3521 			  If G_Debug_Mode = 'Y' Then
3522 			       Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3523 			       pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3524 			  End If;
3525 
3526 			  j := 1;
3527 
3528               G_Stage := 'Get Old Detail Building Block data. Exp Item Date, via old day scope building block.';
3529 			  If G_Debug_Mode = 'Y' Then
3530                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3531                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3532               End If;
3533 
3534               While   j <= Hxc_User_Type_Definition_Grp.T_Old_Day_Bld_Blks.LAST and NOT l_Rec_Found
3535               Loop
3536 
3537                    G_Stage := 'Check if the current record is the correct DAY ' ||
3538 				              'record to grab Exp Item Date from.';
3539                    If G_Debug_Mode = 'Y' Then
3540                         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3541                         pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3542                    End If;
3543 
3544                    If Hxc_User_Type_Definition_Grp.T_Day_Bld_Blks(j).BB_Id =
3545 				      Hxc_User_Type_Definition_Grp.T_Old_Detail_Bld_Blks(P_Old_Detl_Ind).Parent_BB_Id Then
3546 
3547                         G_Stage := 'Grab the Exp Item Date from old day building block record.';
3548                         If G_Debug_Mode = 'Y' Then
3549                              Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3550                         	 pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3551                         End If;
3552 
3553                         P_Timecard_Rec.Expenditure_Item_Date := Trunc(Hxc_User_Type_Definition_Grp.T_Old_Day_Bld_Blks(j).Start_Time);
3554 					    l_Rec_Found := TRUE;
3555 
3556                    End If;
3557 
3558 				   j := j + 1;
3559 
3560               End Loop;
3561 
3562 		 End If;
3563 
3564          G_Stage := 'Exp Item Date(Detail Building Block Start Time): ' || to_char(P_Timecard_Rec.Expenditure_Item_Date);
3565 		 If G_Debug_Mode = 'Y' Then
3566               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3567               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3568          End If;
3569 
3570          G_Stage := 'Get Expenditure Ending Date for old building block data.';
3571          If G_Debug_Mode = 'Y' Then
3572               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3573               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3574          End If;
3575 
3576          P_Timecard_Rec.Expenditure_Ending_date := Pa_Utils.NewGetWeekEnding(P_Timecard_Rec.Expenditure_Item_Date);
3577 
3578 		 G_Stage := 'Old Index check and assignment for use in loop';
3579 		 If G_Debug_Mode = 'Y' Then
3580 		      Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3581         	  Pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3582          End If;
3583 
3584 		 -- Begin PA.M/CWK changes
3585 		 -- The person type can be returned as null and will be handled later in the code.
3586 		 G_Stage := 'Get Person_Type old.';
3587 		 If G_Debug_Mode = 'Y' Then
3588               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3589               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3590          End If;
3591 
3592 		 P_Timecard_Rec.Person_Type := GetPersonType(P_Person_Id => P_Timecard_Rec.Incurred_By_Person_Id,
3593 							                         P_Ei_Date   => P_Timecard_Rec.Expenditure_Item_Date);
3594 
3595          G_Stage := 'Old Person_Type: ' || P_Timecard_Rec.Person_Type;
3596          If G_Debug_Mode = 'Y' Then
3597               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3598               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3599          End If;
3600 		 -- End PA.M/CWK changes
3601 
3602          If G_Old_Detail_Attr_Index = 0 Then
3603 
3604               G_Old_Detail_Attr_Index := 1;
3605 
3606          End If;
3607 
3608          j := G_Old_Detail_Attr_Index;
3609 
3610          /* Pull data from the detail_attributes pl/sql table */
3611          G_Stage := 'Looping thru OLD attibution starting at index position: ' || to_char(j) ;
3612          If G_Debug_Mode = 'Y' Then
3613               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3614               Pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3615          End If;
3616 
3617          G_Stage := 'Current position in OLD attribute pl/sql table bb_id value: ' ||
3618                     to_char(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).BB_Id);
3619          If G_Debug_Mode = 'Y' Then
3620               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3621               pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3622          End If;
3623 
3624          While   j <= Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes.LAST and
3625 			     Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).BB_Id = P_BB_Id
3626          Loop
3627 
3628               If Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'PROJECT_ID' Then
3629 
3630 			       G_Stage := 'Got old Project Id: ' || Hxc_Generic_Retrieval_Pkg.T_Old_Detail_Attributes(j).Value ||
3631 					          '  Index position: ' || to_char(j);
3632 				   If G_Debug_Mode = 'Y' Then
3633 				        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3634         			    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3635         		   End If;
3636 
3637                    P_Timecard_Rec.Project_Id := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3638 
3639               ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'TASK_ID' Then
3640 
3641 			       G_Stage := 'Got old Task Id: ' || Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3642 					          '  Index position: ' || to_char(j);
3643 				   If G_Debug_Mode = 'Y' Then
3644 				        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3645         			    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3646         		   End If;
3647 
3648                    P_Timecard_Rec.Task_Id := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3649 
3650 				   -- Start: Added for CBS Enhancement Bug 16220146
3651 				   If P_Timecard_Rec.Project_Id Is Not Null And P_Timecard_Rec.Task_Id Is Not Null Then
3652 
3653 					  If PA_ALTERNATE_TASK_PVT.Is_Cbs_Enabled(P_Timecard_Rec.Project_Id) = 'Y' Then
3654 
3655 					     Begin
3656 
3657 						    Select Proj_Element_Id, Cbs_Element_Id
3658 							Into l_Actual_Task_Id, l_Cbs_Element_Id
3659 							From Pa_Alternate_Tasks
3660 							Where Alt_Task_Id = P_Timecard_Rec.Task_Id;
3661 
3662 							P_Timecard_Rec.Task_Id        := l_Actual_Task_Id;
3663 							P_Timecard_Rec.Cbs_Element_Id := l_Cbs_Element_Id;
3664 
3665 						 Exception
3666 						    When Others Then
3667 						       l_Actual_Task_Id := Null;
3668 							   l_Cbs_Element_Id := Null;
3669 							   P_Timecard_Rec.Task_Id        := Null;
3670 							   P_Timecard_Rec.Cbs_Element_Id := Null;
3671 							   Raise;
3672 						 End;
3673 					  Else
3674 					     P_Timecard_Rec.Cbs_Element_Id := Null;
3675 					  End If;
3676 				   End If;
3677 				   -- End: Added for CBS Enhancement Bug 16220146
3678 
3679               ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'EXPENDITURE_TYPE' Then
3680 
3681 				   G_Stage := 'Got old Expenditure Type: ' ||
3682                               Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3683 					          '  Index position: ' || to_char(j);
3684 				   If G_Debug_Mode = 'Y' Then
3685 				        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3686         			    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3687         		   End If;
3688 
3689                    P_Timecard_Rec.Expenditure_Type := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3690 
3691               ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'SYSTEM_LINKAGE_FUNCTION' Then
3692 
3693 				   G_Stage := 'Got old System Linkage Function: ' ||
3694                               Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3695 					          '  Index position: ' || to_char(j);
3696 				   If G_Debug_Mode = 'Y' Then
3697 				        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3698         			    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3699         		   End If;
3700 
3701                    P_Timecard_Rec.System_Linkage_Function := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3702 
3703               ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'OVERRIDING_APPROVER_PERSON_ID' Then
3704 
3705 				   G_Stage := 'Got old Overriding Approver Person Id: ' ||
3706                               Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3707 					          '  Index position: ' || to_char(j);
3708 				   If G_Debug_Mode = 'Y' Then
3709 				        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3710         			    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3711         		   End If;
3712 
3713                    P_Timecard_Rec.Override_Approver_Person_Id := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3714 
3715               ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'DUMMY PAEXPITDFF CONTEXT' Then
3716 
3717                    /* The value column contains the following format:
3718                     *   'PAEXPITDFF - <attribute_category>'
3719                     * So to get the attribute_category out will need to find the position
3720                     * for ' - ' that is: '<space>-<space>' and then add 3.
3721                     */
3722 
3723                    G_Stage := 'Get old attribute category info: ' ||
3724                               Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3725 					          '  Index position: ' || to_char(j);
3726 				   If G_Debug_Mode = 'Y' Then
3727                         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3728                         pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3729                    End If;
3730 
3731 				   l_attribute_category := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3732 
3733 				   /* Need to check for null to avoid the unecessary errors using instr
3734                     * avoiding unhandled exceptions.
3735                     */
3736 				   G_Stage := 'Get old attribute category, checking if Null.'|| to_char(j);
3737 				   If G_Debug_Mode = 'Y' Then
3738 				        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3739         			    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3740         		   End If;
3741 
3742                    If l_attribute_category is not null Then
3743 
3744 				        G_Stage := 'Get old attribute category, Strip out prefix.'|| to_char(j);
3745 					    If G_Debug_Mode = 'Y' Then
3746 					         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3747         				     pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3748         				End If;
3749 
3750                         P_Timecard_Rec.Attribute_Category := substr(l_attribute_category,instr(l_attribute_category,' - ') + 3);
3751 
3752                    End If;
3753 
3754               ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'PADFFATTRIBUTE1' Then
3755 
3756 				   G_Stage := 'Got old Attribute1: ' ||
3757                               Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3758 					          '  Index position: ' || to_char(j);
3759 				   If G_Debug_Mode = 'Y' Then
3760 				        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3761         			    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3762         		   End If;
3763 
3764                    P_Timecard_Rec.Attribute1 := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3765 
3766               ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'PADFFATTRIBUTE2' Then
3767 
3768 				   G_Stage := 'Got old Attribute2: ' ||
3769                               Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3770 					          '  Index position: ' || to_char(j);
3771 				   If G_Debug_Mode = 'Y' Then
3772 				        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3773         			    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3774         		   End If;
3775 
3776                    P_Timecard_Rec.Attribute2 := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3777 
3778               ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'PADFFATTRIBUTE3' Then
3779 
3780 				   G_Stage := 'Got old Attribute3: ' ||
3781                               Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3782 					          '  Index position: ' || to_char(j);
3783 				   If G_Debug_Mode = 'Y' Then
3784 				        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3785         			    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3786         		   End If;
3787 
3788                    P_Timecard_Rec.Attribute3 := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3789 
3790              ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'PADFFATTRIBUTE4' Then
3791 
3792 				   G_Stage := 'Got old Attribute4: ' ||
3793                               Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3794 					          '  Index position: ' || to_char(j);
3795 				   If G_Debug_Mode = 'Y' Then
3796 				        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3797         			    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3798         		   End If;
3799 
3800                    P_Timecard_Rec.Attribute4 := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3801 
3802              ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'PADFFATTRIBUTE5' Then
3803 
3804 				   G_Stage := 'Got old Attribute5: ' ||
3805                               Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3806 					          '  Index position: ' || to_char(j);
3807 				   If G_Debug_Mode = 'Y' Then
3808 				        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3809         			    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3810         		   End If;
3811 
3812                    P_Timecard_Rec.Attribute5 := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3813 
3814              ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'PADFFATTRIBUTE6' Then
3815 
3816 				   G_Stage := 'Got old Attribute6: ' ||
3817                               Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3818 					          '  Index position: ' || to_char(j);
3819 				   If G_Debug_Mode = 'Y' Then
3820 				        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3821         			    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3822         		   End If;
3823 
3824                    P_Timecard_Rec.Attribute6 := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3825 
3826              ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'PADFFATTRIBUTE7' Then
3827 
3828 				   G_Stage := 'Got old Attribute7: ' ||
3829                               Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3830 					          '  Index position: ' || to_char(j);
3831 				   If G_Debug_Mode = 'Y' Then
3832 				        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3833         			    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3834         		   End If;
3835 
3836                    P_Timecard_Rec.Attribute7 := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3837 
3838              ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'PADFFATTRIBUTE8' Then
3839 
3840 				   G_Stage := 'Got old Attribute8: ' ||
3841                               Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3842 					          '  Index position: ' || to_char(j);
3843 				   If G_Debug_Mode = 'Y' Then
3844 				        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3845         			    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3846         		   End If;
3847 
3848                    P_Timecard_Rec.Attribute8 := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3849 
3850              ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'PADFFATTRIBUTE9' Then
3851 
3852 				   G_Stage := 'Got old Attribute9: ' ||
3853                               Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3854 					          '  Index position: ' || to_char(j);
3855 				   If G_Debug_Mode = 'Y' Then
3856 				        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3857         			    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3858         		   End If;
3859 
3860                    P_Timecard_Rec.Attribute9 := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3861 
3862              ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'PADFFATTRIBUTE10' Then
3863 
3864 				   G_Stage := 'Got old Attribute10: ' ||
3865                               Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3866 					          '  Index position: ' || to_char(j);
3867 				   If G_Debug_Mode = 'Y' Then
3868 				        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3869         			    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3870         		   End If;
3871 
3872                    P_Timecard_Rec.Attribute10 := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3873 
3874              ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'BILLABLE_FLAG' Then
3875 
3876 				   G_Stage := 'Got old Billable Flag: ' ||
3877                               Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3878 					          '  Index position: ' || to_char(j);
3879 				   If G_Debug_Mode = 'Y' Then
3880 				        Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3881         			    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3882         		   End If;
3883 
3884                    P_Timecard_Rec.Billable_Flag := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3885 
3886 			 -- Begin PA.M/CWK changes
3887              ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'PO LINE ID' Then
3888 
3889 			      G_Stage := 'Got old Po Line Id: ' ||
3890                              Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3891 					         '  Index position: ' || to_char(j);
3892 				  If G_Debug_Mode = 'Y' Then
3893 				       Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3894         			   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3895         		  End If;
3896 
3897                   P_Timecard_Rec.PO_Line_Id := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3898 
3899              ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'PO PRICE TYPE' Then
3900 
3901 			      G_Stage := 'Got old PO Price Type: ' ||
3902                              Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3903 					         '  Index position: ' || to_char(j);
3904 				  If G_Debug_Mode = 'Y' Then
3905 				       Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3906         			   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3907         		  End If;
3908 
3909                   P_Timecard_Rec.PO_Price_Type := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3910 
3911 			 -- End PA.M/CWK changes
3912               -- bug 10253400: Payroll integration enhancement for 12.2..start
3913 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'JOB_ID' Then
3914 
3915                    G_Stage := 'Got old Job ID: ' || Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3916 					          '  Index position: ' || to_char(j);
3917 			       If G_Debug_Mode = 'Y' Then
3918 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3919         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3920         	       End If;
3921 
3922         	       P_Timecard_Rec.Job_id := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3923 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'LOCATION_ID' Then
3924 
3925                    G_Stage := 'Got old Location ID: ' || Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3926 					          '  Index position: ' || to_char(j);
3927 			       If G_Debug_Mode = 'Y' Then
3928 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3929         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3930         	       End If;
3931 
3932         	       P_Timecard_Rec.Location_Id := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3933 
3934 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'WORKTYPE_ID' Then
3935 
3936                    G_Stage := 'Got old Work Type ID: ' || Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3937 					          '  Index position: ' || to_char(j);
3938 			       If G_Debug_Mode = 'Y' Then
3939 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3940         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3941         	       End If;
3942 
3943         	       P_Timecard_Rec.Work_Type_Id := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3944 
3945 		      ElsIf Upper(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Field_Name) = 'DUMMY ELEMENT CONTEXT' Then
3946 
3947 			       /* The value column contains the following format:
3948 			        *   'ELEMENT - <attribute_category>'
3949 			        * So to get the attribute_category out will need to find the position
3950                     * for ' - ' that is: '<space>-<space>' and then add 3.
3951 			        */
3952 
3953                    G_Stage := 'Get old attribute category: ' || Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value ||
3954                               '  Index position: ' || to_char(j);
3955 			       If G_Debug_Mode = 'Y' Then
3956                         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3957                         pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3958                    End If;
3959 
3960 			       l_attribute_category := Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).Value;
3961 
3962                    /* Need to check for null so as to avoid the unecessary use of errors using instr
3963                     * to avoid unhandled exceptions.
3964                     */
3965 
3966 			       G_Stage := 'Get old attribute category, checking if Null.';
3967 			       If G_Debug_Mode = 'Y' Then
3968 			            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3969         		        pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3970         	       End If;
3971 
3972 			       If l_attribute_category is not null Then
3973 
3974 			            G_Stage := 'Get old attribute category, Strip out prefix.';
3975 				        If G_Debug_Mode = 'Y' Then
3976 					         Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3977         				     pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3978         		        End If;
3979 
3980         		        P_Timecard_Rec.Pay_Element_Type_Id := substr(l_attribute_category,instr(l_attribute_category,' - ') + 3);
3981                   End If;
3982 
3983               -- bug 10253400: Payroll integration enhancement for 12.2..end
3984 
3985              End If;
3986 
3987 			 j := j + 1;
3988 
3989         End Loop;
3990 
3991         G_Stage := 'Exited loop.  No more OLD attribution for BB_Id. Store the current index position ' ||
3992                    to_char(j) || ' in global variable.';
3993 		If G_Debug_Mode = 'Y' Then
3994 		     Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
3995         	 pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
3996         End If;
3997 
3998         /* Note that variable G_Old_Detail_Attr_Index is already pointing the the next building block.
3999          * This is due to the fact that we are using the while/loop structure and only leaving the loop
4000          * when the building block ids no longer match or have reach the end of the pl/sql table.
4001          */
4002 
4003 		G_Old_Detail_Attr_Index := j;
4004 
4005         G_Stage := 'Determine why exited loop while looking for OLD record attribution.';
4006         If G_Debug_Mode = 'Y' Then
4007              Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
4008              pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
4009         End If;
4010 
4011         If j > Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes.LAST Then
4012 
4013 		     G_Stage := 'Reached last record index position ' ||
4014                         to_char(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes.LAST) || ' ' ||
4015                         'in OLD attrib pl/sql table.';
4016              If G_Debug_Mode = 'Y' Then
4017                   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
4018                   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
4019              End If;
4020 
4021         ElsIf Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).BB_Id <> P_BB_Id Then
4022 
4023              G_Stage := 'P_BB_Id: ' || to_char(P_BB_Id) || ' --  ' ||
4024                         'BB_Id in OLD attrib pl/sql: ' ||
4025                         to_char(Hxc_User_Type_Definition_Grp.T_Old_Detail_Attributes(j).BB_Id) || '.  ' ||
4026 				        'They do not match!';
4027              If G_Debug_Mode = 'Y' Then
4028                   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
4029                   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
4030              End If;
4031 
4032         End If;
4033 
4034 		-- Begin PA.M/CWK changes
4035         G_Stage := 'Check if P_Timecard_Rec.Person_Type is CWK and PO_Line_Id Is Not Null old.';
4036         If G_Debug_Mode = 'Y' Then
4037              Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
4038              pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
4039         End If;
4040 		If P_Timecard_Rec.Person_Type = 'CWK' and P_Timecard_Rec.PO_Line_Id Is Not Null Then
4041 
4042              G_Stage := 'Calling Pa_Otc_Api.GetPOInfo() procedure old.';
4043              If G_Debug_Mode = 'Y' Then
4044                   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
4045                   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
4046              End If;
4047 
4048 			 Pa_Otc_Api.GetPOInfo(
4049                          P_Po_Line_Id   => P_Timecard_Rec.PO_Line_Id,
4050 				  	     X_PO_Header_Id => P_Timecard_Rec.PO_Header_Id,
4051 				  	     X_Vendor_Id    => P_Timecard_Rec.Vendor_Id);
4052 
4053 			 G_Stage := 'Got old Vendor Id: ' || to_char(P_Timecard_Rec.Vendor_Id) || ' based on PO_Line_Id';
4054 			 If G_Debug_Mode = 'Y' Then
4055 			      Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
4056         		  pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
4057         	 End If;
4058 
4059 		Else
4060 
4061              G_Stage := 'Set po infor, vendor_id and price_type to null old.';
4062              If G_Debug_Mode = 'Y' Then
4063                   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
4064                   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
4065              End If;
4066 
4067 			 P_Timecard_Rec.PO_Line_Id := NULL;
4068 			 P_Timecard_Rec.PO_Header_Id := NULL;
4069 			 P_Timecard_Rec.Vendor_Id := NULL;
4070 			 P_Timecard_Rec.PO_Price_Type := NULL;
4071 
4072 		End If;
4073 		-- End PA.M/CWK changes
4074 
4075     End If;
4076 
4077     G_Stage := 'Checking that needed data was retrieved to properly process building block for import.';
4078     If G_Debug_Mode = 'Y' Then
4079 	     Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
4080 	     pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
4081     End If;
4082 
4083     If P_Timecard_Rec.Project_Id is null and
4084        P_Timecard_Rec.Task_Id is null and
4085        P_Timecard_Rec.Expenditure_Type is null and
4086        P_Timecard_Rec.System_Linkage_Function is null and
4087        P_Timecard_Rec.Quantity is null and
4088        P_Timecard_Rec.Incurred_By_Person_Id is null and
4089        P_Timecard_Rec.Expenditure_Item_Date is null and
4090        P_Timecard_Rec.Expenditure_Ending_Date is null and
4091        P_Timecard_Rec.Billable_Flag is null and
4092 	   P_Timecard_Rec.Person_Type is null Then   -- CWK changes PA.M
4093 
4094          l_Status_Code := 'HXC_RET_NO_TIMECARD_DATA';
4095 
4096 	     If P_New_Old_BB = 'OLD' Then
4097 
4098 		      l_Status_Code := 'HXC_RET_NO_TIMECARD_DATA_OLD';
4099 
4100 		 End If;
4101 
4102 		 fnd_message.set_name('HXC', l_Status_Code);
4103 		 P_Timecard_Rec.Status := SubStr(Fnd_Message.Get,1,2000);
4104 
4105     Elsif P_Timecard_Rec.Project_id is null and
4106           P_Timecard_Rec.Task_id is null and
4107 	      P_Timecard_Rec.Expenditure_Type is null and
4108 	      P_Timecard_Rec.System_Linkage_Function is null and
4109 	      P_Timecard_Rec.Billable_flag is null and
4110 	      P_Timecard_Rec.Person_Type is null Then   -- CWK changes PA.M
4111 
4112 		 l_Status_Code := 'HXC_RET_NO_ATT_DATA';
4113 
4114 		 If P_New_Old_BB = 'OLD' Then
4115 
4116 		      l_Status_Code := 'HXC_RET_NO_ATT_DATA_OLD';
4117 
4118 		 End If;
4119 		 fnd_message.set_name('HXC',l_Status_Code);
4120 		 fnd_message.set_token('STAGE', '1');
4121 		 P_Timecard_Rec.Status := SubStr(Fnd_Message.Get,1,2000);
4122 
4123     ElsIf P_Timecard_Rec.Quantity is null or
4124           P_Timecard_Rec.Incurred_By_Person_Id is null or
4125           P_Timecard_Rec.Expenditure_Item_Date is null Then
4126 
4127          l_Status_Code := 'HXC_RET_NO_BLD_BLK_DATA';
4128 
4129 		 If P_New_Old_BB = 'OLD' Then
4130 
4131 		      l_Status_Code := 'HXC_RET_NO_BLD_BLK_DATA_OLD';
4132 
4133 		 End If;
4134 		 fnd_message.set_name('HXC',l_Status_Code);
4135 		 fnd_message.set_token('STAGE', '1');
4136 		 P_Timecard_Rec.Status := SubStr(Fnd_Message.Get,1,2000);
4137 
4138     ElsIf  P_Timecard_Rec.Billable_flag is null or
4139            P_Timecard_Rec.Project_id is null or
4140            P_Timecard_Rec.Task_id is null or
4141            P_Timecard_Rec.Expenditure_Type is null or
4142            P_Timecard_Rec.System_Linkage_Function is null  or
4143 	       (P_Timecard_Rec.Person_Type = 'CWK' and              -- CWK changes PA.M
4144             P_Timecard_Rec.PO_Line_Id is Not Null  and          -- CWK changes PA.M  -- Bug 3643126
4145 		   (P_Timecard_Rec.PO_Price_Type is Null or	            -- CWK changes PA.M
4146 		    P_Timecard_Rec.Vendor_Id Is Null)) or               -- CWK changes PA.M
4147 	       P_Timecard_Rec.Person_Type is NULL Then              -- CWK changes PA.M
4148 
4149 		 l_Status_Code := 'HXC_RET_NO_ATT_DATA';
4150 
4151 		 If P_New_Old_BB = 'OLD' Then
4152 
4153 		      l_Status_Code := 'HXC_RET_NO_ATT_DATA_OLD';
4154 
4155 		 End If;
4156 		 fnd_message.set_name('HXC',l_Status_Code);
4157 		 fnd_message.set_token('STAGE', '2');
4158 		 P_Timecard_Rec.Status := SubStr(Fnd_Message.Get,1,2000);
4159 
4160     End If;
4161 
4162     G_Stage := 'Leaving PopulateProjRec(), strip procedure from trackpath.';
4163     If G_Debug_Mode = 'Y' Then
4164          Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
4165          pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
4166     End If;
4167     Pa_Otc_Api.TrackPath('STRIP','PopulateProjRec');
4168 
4169   Exception
4170     When Others Then
4171 	     l_error_text := SubStr('Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage || ' --  ' || SqlErrM, 1, 1800);
4172 		 fnd_message.set_name('HXC', 'HXC_RET_UNEXPECTED_ERROR');
4173 		 fnd_message.set_token('ERR', l_Error_Text);
4174 		 P_Timecard_Rec.Status := SubStr(Fnd_Message.Get,1,2000);
4175 
4176          If G_Debug_Mode = 'Y' Then
4177               Pa_Debug.G_err_Stage := P_Timecard_Rec.Status;
4178            	  pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
4179          End If;
4180 
4181          l_error_text := 'Leaving PopulateProjRec() due to unhandled exception, strip procedure from trackpath.';
4182          If G_Debug_Mode = 'Y' Then
4183               Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || l_error_text;
4184            	  pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
4185        	 End If;
4186          Pa_Otc_Api.TrackPath('STRIP','PopulateProjRec');
4187 
4188 		 Raise G_BAD_OTL_DATA;
4189 
4190   End PopulateProjRec;
4191 
4192 -- ========================================================================
4193 -- Start Of Comments
4194 -- API Name      : GetDetailIndex
4195 -- Type          : Private
4196 -- Pre-Reqs      : None
4197 -- Type          : Procedure
4198 -- Return        : n/a
4199 -- Function      : This procedure finds the Index located in the detail pl/sql
4200 --                 Hxc_Generic_Retrieval_Pkg.T_Detail_Bld_Blks table generated
4201 --                 during the generic retrieval process for the
4202 --                 Building_Block_Id that is passed in to it.
4203 --
4204 -- Parameters    :
4205 -- IN
4206 --               P_Detail_BB_Id  - Hxc_Time_Building_Blocks.Resource_Id%TYPE
4207 -- OUT
4208 --               X_Detail_Index  - Binary_Integer
4209 
4210 /*--------------------------------------------------------------------------*/
4211 
4212 
4213    Procedure GetDetailIndex( P_Detail_BB_Id IN         Hxc_Time_Building_Blocks.Time_Building_Block_Id%TYPE,
4214                              X_Detail_Index OUT NOCOPY Binary_Integer)
4215 
4216    Is
4217 
4218    Begin
4219 
4220         G_Stage := 'Entering procedure GetDetailIndex(), add procedure to trackpath.';
4221 	If G_Debug_Mode = 'Y' Then
4222            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
4223            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
4224         End If;
4225         Pa_Otc_Api.TrackPath('ADD','GetDetailIndex');
4226 
4227         G_Stage := 'Begin loop searching for the matching BB_Id.';
4228 	If G_Debug_Mode = 'Y' Then
4229            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
4230            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
4231         End If;
4232 
4233         For i in Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks.FIRST .. Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks.LAST
4234         Loop
4235 
4236                 G_Stage := 'Determine if BB_Id in the pl/sql matches the one provided.';
4237 		If G_Debug_Mode = 'Y' Then
4238         	   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
4239         	   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
4240         	End If;
4241 
4242                 If Hxc_User_Type_Definition_Grp.T_Detail_Bld_Blks(i).BB_Id = P_Detail_BB_Id Then
4243 
4244                         G_Stage := 'Set Index to use since found the one needed.';
4245 			If G_Debug_Mode = 'Y' Then
4246         		   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
4247         		   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
4248         		End If;
4249 
4250                         X_Detail_Index := i;
4251 
4252                         G_Stage := 'Exiting the loop since found the index needed.';
4253 			If G_Debug_Mode = 'Y' Then
4254         		   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
4255         		   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
4256         		End If;
4257 
4258                         EXIT;
4259 
4260                 End If;
4261 
4262         End Loop;
4263 
4264         G_Stage := 'Leaving procedure GetDetailIndex().';
4265 	If G_Debug_Mode = 'Y' Then
4266            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
4267            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
4268         End If;
4269         Pa_Otc_Api.TrackPath('STRIP','GetDetailIndex');
4270 
4271    Exception
4272         When Others Then
4273                 Raise;
4274 
4275    End GetDetailIndex;
4276 
4277 
4278 
4279 
4280 /* UPDATE and VALIDATION ROUTINES */
4281 
4282 -- ========================================================================
4283 -- Start Of Comments
4284 -- API Name      : Projects_Retrieval_Process
4285 -- Type          : Public
4286 -- Pre-Reqs      : None
4287 -- Type          : Function
4288 -- Return        : Varchar2
4289 -- Function      : This function is called to provide the retrieval process name so that the appropriate
4290 --                 attribution is retrieved for validation.
4291 --
4292 
4293 /*--------------------------------------------------------------------------*/
4294 
4295 
4296    Function Projects_Retrieval_Process RETURN Varchar2
4297 
4298    Is
4299 
4300         l_retrieval_process Hxc_Time_Recipients.Application_Retrieval_Function%TYPE;
4301 
4302    Begin
4303 
4304         l_retrieval_process := 'Projects Retrieval Process';
4305 
4306         Return l_retrieval_process;
4307 
4308    End Projects_Retrieval_Process;
4309 
4310 
4311 -- =======================================================================
4312 -- Start of Comments
4313 -- API Name      : Update_Otc_Data
4314 -- Type          : Public
4315 -- Pre-Reqs      : None
4316 -- Type          : Procedure
4317 -- Function      : This procedure is called by the OTL client team server-side
4318 --                 non-user data modification section of their code.
4319 --                 The only intent of the Procedure is get the data in Hxc and
4320 --                 then call the Private procedure Update_Process() to update the
4321 --                 Billable_flag when appropriate.  Then sent the changes back to Hxc.
4322 --
4323 -- Parameters    :
4324 -- IN
4325 --           P_operation            -  Varchar2
4326 
4327 /*------------------------------------------------------------------------- */
4328 
4329   Procedure Update_Otc_Data
4330             (P_Operation            IN Varchar2)
4331 
4332   Is
4333 
4334 	l_Blocks     Hxc_User_Type_Definition_Grp.Timecard_Info;
4335 	l_Attributes Hxc_User_Type_Definition_Grp.App_Attributes_Info;
4336 	l_Messages   Hxc_User_Type_Definition_Grp.Message_Table;
4337 
4338   Begin
4339 
4340 	G_Path := ' ';
4341 
4342         G_Stage := 'Entering Update_Otc_Data() procedure.';
4343         Pa_Otc_Api.TrackPath('ADD','Update_Otc_Data');
4344 
4345 	If P_Operation <> 'MIGRATION' Then
4346 
4347 		G_Stage := 'Call Hxc_Integration_Layer_V1_Grp.Get_App_Hook_Params()';
4348         	Hxc_Integration_Layer_V1_Grp.Get_App_Hook_Params(
4349                         		P_Building_Blocks => l_Blocks,
4350                         		P_App_Attributes  => l_Attributes,
4351                         		P_Messages        => l_Messages);
4352 
4353 		G_Stage := 'Call the Upate_Process() to update the billable flag.';
4354 		Pa_Otc_Api.Update_Process (
4355 					P_Operation       => P_Operation,
4356                     P_Building_Blocks => l_Blocks,
4357                     P_Attribute_Table => l_Attributes);
4358 
4359 		G_Stage := 'Call hxc_self_service_time_deposit.set_app_hook_params()';
4360 		Hxc_Integration_Layer_V1_Grp.Set_App_Hook_Params(
4361                 			P_Building_Blocks => l_Blocks,
4362                 			P_App_Attributes  => l_Attributes,
4363                 			P_Messages        => l_Messages);
4364 
4365 	End If; -- P_Operation
4366 
4367         G_Stage := 'Leaving Update_Otc_Data() procedure.';
4368         Pa_Otc_Api.TrackPath('STRIP','Update_Otc_Data');
4369 
4370   	Exception
4371 	    When Others Then
4372 		Raise_Application_Error(-20010, 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_stage || ' : ' || SqlErrM );
4373 
4374   End Update_Otc_Data;
4375 
4376 
4377 -- =======================================================================
4378 -- Start of Comments
4379 -- API Name      : Update_Process
4380 -- Type          : Private
4381 -- Pre-Reqs      : None
4382 -- Type          : Procedure
4383 -- Function      : This procedure is called by public procedure Update_Process.
4384 --                 The only intent of this procedure is to get the BILLABLE_FLAG
4385 --                 from patc/patcx and return control back to the calling procedure.
4386 --                 No handled errors will be returned to the OTL client team server code calling
4387 --                 procedure. Unhandled exceptions will be allowed.
4388 --
4389 --          P_Operation:  SAVE
4390 --                        SUBMIT
4391 --
4392 -- Parameters:
4393 -- IN
4394 --           P_Operation        -- Varchar2
4395 --           P_Building_Blocks  -- Hxc_User_Type_Definition_Grp.Timecard_Info
4396 --           P_Attribute_Table  -- Hxc_User_Type_Definition_Grp.App_Attributes_Info
4397 -- OUT
4398 --           P_Building_Blocks  -- Hxc_User_Type_Definition_Grp.Timecard_Info
4399 --           P_Attribute_Table  -- Hxc_User_Type_Definition_Grp.App_Attributes_Info
4400 
4401 /*------------------------------------------------------------------------- */
4402 
4403   Procedure Update_Process(
4404                       P_Operation         IN     Varchar2,
4405                       P_Building_Blocks   IN OUT NOCOPY Hxc_User_Type_Definition_Grp.Timecard_Info, -- 2672653
4406                       P_Attribute_Table   IN OUT NOCOPY Hxc_User_Type_Definition_Grp.App_Attributes_Info) -- 2672653
4407 
4408   Is
4409 
4410 	    l_Proj_Attrib_Rec           Pa_Otc_Api.Project_Attribution_Rec;
4411 
4412         /* Stores a single record from the Building Block Table */
4413         l_Building_Block_Record     Hxc_User_Type_Definition_Grp.Building_Block_Info;
4414 
4415         l_BB_Detail_Changed         Varchar2(1)    := 'N';  -- The OTL item has changed.
4416         l_BB_Detail_Deleted         Varchar2(1)    := 'N';  -- The OTL item has been deleted.
4417         l_BB_Detail_Pass            Varchar2(1)    := 'N';  -- The OTL item has changed but values same as in Projects
4418         l_Data_Conflict_Flag        Varchar2(1)    := 'N';  -- If attempt to delete,update after already saved change or
4419                                                             -- delete in OTL that should not have been allowed
4420         l_Adjusted_In_Projects      Varchar2(1)    := 'N';  -- The OTL item was adjusted in Projects already
4421 
4422 	    l_Detail_Attr_Changed       Varchar2(1)    := 'N';
4423 	    l_Logical_Rec_Changed       Varchar2(1)    := 'N';
4424 
4425         l_Msg_Name                  Varchar2(30)   := Null;
4426         l_Msg_Application           Varchar2(3)    := Null;
4427         l_Msg_Type                  Varchar2(30)   := Null;
4428         l_Msg_Token1_Name           Varchar2(30)   := Null;
4429         l_Msg_Token1_Value          Varchar2(30)   := Null;
4430         l_Msg_Token2_Name           Varchar2(30)   := Null;
4431         l_Msg_Token2_Value          Varchar2(30)   := Null;
4432         l_Msg_Token3_Name           Varchar2(30)   := Null;
4433         l_Msg_Token3_Value          Varchar2(30)   := Null;
4434         l_Msg_Count                 Number         := Null;
4435         l_Error_Code                Varchar2(30)   := Null;
4436         l_Error_Type                Varchar2(30)   := Null;
4437 	    l_Status                    Varchar2(30)   := Null;
4438 
4439 	    i			    Binary_Integer := Null;
4440 	    l_calling_module  Varchar2(20);--Added for bug#13803367
4441 
4442   Begin
4443 	   l_calling_module  :='PAXVOTCB'; --Added for bug#13803367
4444 
4445 	G_Stage := 'Entering procedure Update_Process().';
4446         Pa_Otc_Api.TrackPath('ADD','Update_Process');
4447 
4448         G_Stage := 'Loop thru Building Blocks record to validate detail records.';
4449 --      For i in P_Building_Blocks.First .. P_Building_Blocks.Last
4450         Loop
4451 
4452 	    If i is null Then
4453 
4454 		i := P_Building_Blocks.First;
4455 
4456 	    Else
4457 
4458 	    	i := P_Building_Blocks.Next(i);
4459 
4460 	    End If;
4461 
4462         If P_Building_Blocks(i).Scope = 'DETAIL' Then
4463 
4464              G_Stage := 'Copy current record in BB table to BB record variable.';
4465              l_Building_Block_Record := P_Building_Blocks(i);
4466              G_Stage := 'Pull out the data to friendlier formated variables.';
4467              /* Pull out the data to project friendly variables */
4468              /* Bug 4318639
4469              Pa_Otc_Api.RetrieveProjAttribution( */
4470              Pa_Otc_Api.RetrieveProjAttribForUpd(
4471                   P_Building_Block_Rec  => l_Building_Block_Record,
4472                   P_Building_Block      => P_Building_Blocks,
4473                   P_Attribute_Table     => P_Attribute_Table,
4474                   X_Detail_Attr_Changed => l_Detail_Attr_Changed,
4475                   X_Proj_Attrib_Rec     => l_Proj_Attrib_Rec);
4476 
4477 		     G_Stage := 'Determine building block change flag value to pass.';
4478 		     If l_Detail_Attr_Changed = 'Y' OR P_Building_Blocks(i).Changed = 'Y' Then
4479 
4480 			      l_Logical_Rec_Changed := 'Y';
4481 
4482 		     Else
4483 
4484 			      l_Logical_Rec_Changed := 'N';
4485 
4486 		     End If;
4487 
4488              G_Stage := 'Determine the processing flags for using further in code.';
4489              Pa_Otc_Api.DetermineProcessingFlags(
4490                         P_BB_Id                => P_Building_Blocks(i).Time_Building_Block_Id,
4491                         P_BB_Ovn               => P_Building_Blocks(i).Object_Version_Number,
4492                         P_BB_Date_To           => P_Building_Blocks(i).Date_To,
4493                         P_BB_Changed           => l_Logical_Rec_Changed,
4494                         P_BB_New               => P_Building_Blocks(i).New,
4495                         P_Proj_Attribute_Rec   => l_Proj_Attrib_Rec,
4496                         P_Mode                 => 'UPDATE',
4497                         P_Process_Flag         => P_Building_Blocks(i).Process,
4498                         X_BB_Detail_Changed    => l_BB_Detail_Changed,
4499                         X_Data_Conflict_Flag   => l_Data_Conflict_Flag,
4500                         X_BB_Detail_Deleted    => l_BB_Detail_Deleted,
4501                         X_Adj_in_Projects_Flag => l_Adjusted_In_Projects);
4502 
4503 			/* Added  below statement  for  bug 11711383 */
4504 			G_Delete_op      := l_BB_Detail_Deleted;
4505 			G_Delete_Change  := l_Logical_Rec_Changed;
4506 			G_Detail_Change  := l_BB_Detail_Changed;
4507 
4508 		     If  /* l_BB_Detail_Deleted = 'N' and  */  -- again commented for 11656282 /* removed the comments for bug 10033549 */--Commented for  bug 8546092  / 8284884
4509 		       (l_BB_Detail_Deleted = 'N' OR (l_BB_Detail_Deleted = 'Y'
4510 			and l_Proj_Attrib_Rec.Quantity is null)) and /*Added for bug#13803367 */
4511 		       (l_BB_Detail_Changed = 'Y' or P_Building_Blocks(i).New = 'Y') and
4512 		        l_Adjusted_In_Projects = 'N' and
4513 		        l_Data_Conflict_Flag = 'N' Then
4514 
4515 			/*Start changes for bug#13803367 */
4516 
4517 			IF (l_BB_Detail_Deleted = 'Y' and
4518 			l_Proj_Attrib_Rec.Quantity is null) THEN
4519 			--{
4520 				l_calling_module  :='PAXVOTCBDEL';
4521 			--}
4522 			ELSE
4523 			--{
4524 				l_calling_module  :='PAXVOTCB';
4525 			--}
4526 			END IF;
4527 			/*End changes for bug#13803367 */
4528 
4529 			      l_Status := Null;
4530 
4531                	  G_Stage := 'Firing patc(). Only want the Billable Flag and no validation checked.';
4532 
4533                	  Pa_Transactions_Pub.Validate_Transaction(
4534                                 X_Project_Id          => l_Proj_Attrib_Rec.Project_Id,
4535                                 X_Task_Id             => l_Proj_Attrib_Rec.Task_Id,
4536                                 X_Ei_Date             => l_Proj_Attrib_Rec.Expenditure_Item_Date,
4537                                 X_Expenditure_Type    => l_Proj_Attrib_Rec.Expenditure_Type,
4538                                 X_Non_Labor_Resource  => Null,
4539                                 X_Person_Id           => l_Proj_Attrib_Rec.Inc_By_Person_Id,
4540                                 X_Billable_Flag       => l_Proj_Attrib_Rec.Billable_Flag,
4541                                 X_Quantity            => l_Proj_Attrib_Rec.Quantity,
4542                                 X_Transfer_Ei         => Null,
4543                                 X_Incurred_By_Org_Id  => Null,  -- letting patc get it
4544                                 X_NL_Resource_Org_Id  => Null,
4545                                 X_Transaction_Source  => 'ORACLE TIME AND LABOR',
4546                                 X_Calling_Module      => l_calling_module, --Added for bug#13803367
4547                                 X_Vendor_Id           => l_Proj_Attrib_Rec.Vendor_Id,  -- PA.M/CWK changes
4548                                 X_Entered_By_User_Id  => l_Proj_Attrib_Rec.Inc_By_Person_Id,
4549                                 X_Attribute_Category  => l_Proj_Attrib_Rec.Attrib_Category,
4550                                 X_Attribute1          => l_Proj_Attrib_Rec.Attribute1,
4551                                 X_Attribute2          => l_Proj_Attrib_Rec.Attribute2,
4552                                 X_Attribute3          => l_Proj_Attrib_Rec.Attribute3,
4553                                 X_Attribute4          => l_Proj_Attrib_Rec.Attribute4,
4554                                 X_Attribute5          => l_Proj_Attrib_Rec.Attribute5,
4555                                 X_Attribute6          => l_Proj_Attrib_Rec.Attribute6,
4556                                 X_Attribute7          => l_Proj_Attrib_Rec.Attribute7,
4557                                 X_Attribute8          => l_Proj_Attrib_Rec.Attribute8,
4558                                 X_Attribute9          => l_Proj_Attrib_Rec.Attribute9,
4559                                 X_Attribute10         => l_Proj_Attrib_Rec.Attribute10,
4560                                 -- MC columns are NULL because OTL does not support
4561                                 -- multi-currency
4562                                 X_Denom_Currency_Code => Null,
4563                                 X_Acct_Currency_Code  => Null,
4564                                 X_Denom_Raw_Cost      => Null,
4565                                 X_Acct_Raw_Cost       => Null,
4566                                 X_Acct_Rate_Type      => Null,
4567                                 X_Acct_Rate_Date      => Null,
4568                                 X_Acct_Exchange_Rate  => Null,
4569                                 X_Msg_Application     => l_Msg_Application,
4570                                 X_Msg_Type            => l_Msg_Type,
4571                                 X_Msg_Token1          => l_Msg_Token1_Name,
4572                                 X_Msg_Token2          => l_Msg_Token2_Name,
4573                                 X_Msg_Token3          => l_Msg_Token3_Name,
4574                                 X_Msg_Count           => l_Msg_Count,
4575                                 X_Msg_Data            => l_Status,
4576                                 -- PA.M/CWK changes
4577                                 P_Po_Header_Id	      => l_Proj_Attrib_Rec.Po_Header_Id,
4578                                 P_Po_Line_Id	      => l_Proj_Attrib_Rec.Po_Line_Id,
4579                                 P_Person_Type	      => l_Proj_Attrib_Rec.Person_Type,
4580                                 P_Po_Price_Type	      => l_Proj_Attrib_Rec.Po_Price_Type,
4581                                 P_Sys_Link_Function   => l_Proj_Attrib_Rec.Sys_Linkage_Func,
4582                                 -- bug 10253400: Payroll integration enhancement for 12.2..start
4583 								P_Job_id              => l_Proj_Attrib_Rec.Job_Id,
4584 								p_Location_Id         => l_Proj_Attrib_Rec.location_id);
4585                                 -- bug 10253400: Payroll integration enhancement for 12.2..end
4586 
4587 
4588 
4589              G_Stage := 'Check the returned status from patc.';
4590              If ( l_Status is null  OR
4591                 ( l_Status is NOT NULL AND nvl(l_Msg_Type,'W') <> 'E') ) Then  /*Bug4518893*/
4592 
4593                   G_Stage := 'Patc returned status that is Null.';
4594 
4595                   -- Populate the Billable Flag in the pl/sql table
4596                   -- Bug 4318639 Added IF condition to see if the billable_flag_index is populated.
4597                   --             If no project related data was entered or there is no project_id attribution data in the
4598                   --             attribution pl/sql table then we are able to build the billable_flag attribution record in
4599                   --             Pa_Otc_Api.RetrieveProjAttribForUpd() so won't be able to assign the billable_flag to the
4600                   --             attribution record.
4601                   G_Stage := 'Check if billable_flag attribution pl/sql record exists.';
4602                   If l_Proj_Attrib_Rec.Billable_Flag_Index is Not Null Then
4603                        G_Stage := 'Populate the Billable Flag in the attribution pl/sql table record.';
4604                        P_Attribute_Table(l_Proj_Attrib_Rec.Billable_Flag_Index).Attribute_Value := l_Proj_Attrib_Rec.Billable_Flag;
4605                   End If;
4606 
4607              End If; -- l_Status is null
4608 
4609 		End If;  -- Detail building block not deleted and has changed.
4610 
4611 	    End If; -- Detail Scope building block record
4612 
4613 	    G_Stage := 'Check to exit loop.';
4614 	    Exit When i = P_Building_Blocks.Last;
4615 
4616 	End Loop;  -- End of looping thru the building_block table
4617 
4618 	G_Stage := 'Leaving procedure Update_Process().';
4619 	Pa_Otc_Api.TrackPath('STRIP','Update_Process');
4620 
4621   Exception
4622      	When Others Then
4623 		Raise;
4624 
4625   End Update_Process;
4626 
4627 
4628 -- =======================================================================
4629 -- Start of Comments
4630 -- API Name      : Validate_Otc_Data
4631 -- Type          : Public
4632 -- Pre-Reqs      : None
4633 -- Type          : Procedure
4634 -- Function      : This procedure is called by the OTL client team server-side
4635 --                 Validation section of their code. The only intent of the
4636 --                 Procedure is manipulate the parameters passed in and then call
4637 --                 the Private procedure Validate_Process() to Validate the data.
4638 --
4639 -- Parameters    :
4640 -- IN
4641 --           P_operation -  Varchar2
4642 
4643 /*------------------------------------------------------------------------- */
4644 
4645   Procedure Validate_Otc_Data
4646             (P_Operation IN Varchar2)
4647 
4648   Is
4649 
4650 	l_Blocks     Hxc_User_Type_Definition_Grp.Timecard_Info;
4651 	l_Attributes Hxc_User_Type_Definition_Grp.App_Attributes_Info;
4652 	l_Messages   Hxc_User_Type_Definition_Grp.Message_Table;
4653 
4654   Begin
4655 
4656 	G_Path := ' ';
4657 
4658         G_Stage := 'Entering procedure Validate_Otc_Data().';
4659         Pa_Otc_Api.TrackPath('ADD','Validate_Otc_Data');
4660 
4661 	If P_Operation <> 'MIGRATION' Then
4662 
4663          G_Stage := 'Call hxc_self_service_time_deposit.get_app_hook_params()';
4664          Hxc_Integration_Layer_V1_Grp.Get_App_Hook_Params(
4665                 				P_Building_Blocks => l_Blocks,
4666                 				P_App_Attributes  => l_Attributes,
4667                 				P_Messages        => l_Messages);
4668 
4669          G_Stage := 'Call the Validate_Process() to validate data.';
4670          Pa_Otc_Api.Validate_Process (
4671                      P_Operation       => P_Operation,
4672                      P_Building_Blocks => l_Blocks,
4673                      P_Attribute_Table => l_Attributes,
4674 				     P_Message_Table   => l_Messages);
4675 
4676          If l_Messages.COUNT > 0 Then
4677 
4678                  G_Stage := 'Call hxc_self_service_time_deposit.set_app_hook_params()';
4679 			     Hxc_Integration_Layer_V1_Grp.Set_App_Hook_Params(
4680                 				P_Building_Blocks => l_Blocks,
4681                 				P_App_Attributes  => l_Attributes,
4682                 				P_Messages        => l_Messages);
4683 
4684          End If; -- l_Message.COUNT
4685 
4686 	End If; -- P_Operation
4687 
4688         G_Stage := 'Leaving procedure Validate_Otc_Data().';
4689         Pa_Otc_Api.TrackPath('STRIP','Validate_Otc_Data');
4690 
4691   Exception
4692         When Others Then
4693                 Raise_Application_Error(-20020,'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_stage || ' : ' || SQLERRM );
4694 
4695   End Validate_Otc_Data;
4696 
4697 
4698 -- =======================================================================
4699 -- Start of Comments
4700 -- API Name      : Validate_Process
4701 -- Type          : Private
4702 -- Pre-Reqs      : None
4703 -- Type          : Procedure
4704 -- Function      : This procedure validates the Timecard Header/lines
4705 --                 information entered by the user.
4706 --
4707 --          P_Operation:  SAVE
4708 --                        SUBMIT
4709 --
4710 --
4711 -- Parameters    :
4712 -- IN
4713 --           P_Operation        -- Varchar2
4714 --           P_Building_Blocks  -- Hxc_User_Type_Definition_Grp.Timecard_Info
4715 --           P_Attribute_Table  -- Hxc_User_Type_Definition_Grp.App_Attributes_Info
4716 -- OUT
4717 --           P_Message_Table    -- Hxc_User_Type_Definition_Grp.Message_Table
4718 
4719 /*------------------------------------------------------------------------- */
4720 
4721    Procedure Validate_Process(
4722                      P_Operation         IN            Varchar2,
4723                      P_Building_Blocks   IN            Hxc_User_Type_Definition_Grp.Timecard_Info,
4724                      P_Attribute_Table   IN            Hxc_User_Type_Definition_Grp.App_Attributes_Info,
4725                      P_Message_Table     IN OUT NOCOPY Hxc_User_Type_Definition_Grp.Message_Table) -- 2672653
4726 
4727   Is
4728 
4729         l_Status                    Varchar2(30) := Null;
4730         l_Exp_Status                Varchar2(30) := Null;
4731         l_Not_Bypass_Patc_Flag      Boolean := True;
4732 	    l_Error_Level               Varchar2(10) := Null; /* Added for Bug#2798986 */
4733 
4734         /* The OTL item has been imported into projects and max orig_transaction_reference does not match
4735          * its equivalent in OTL( to_char(BB_ID) || to_char(BB_OVN) ) Then l_BB_Detail_Changed = 'Y' else 'N'
4736          */
4737         l_BB_Detail_Changed         Varchar2(1) := 'N';  -- The OTL item has changed.
4738         l_BB_Detail_Deleted         Varchar2(1) := 'N';  -- The OTL item has been deleted.
4739         l_Data_Conflict_Flag        Varchar2(1) := 'N';  -- If attempt to delete,update after already saved change or
4740                                                          -- delete in OTL that should not have been allowed
4741         l_Adjusted_In_Projects      Varchar2(1) := 'N';  -- The OTL item was adjusted in Projects already
4742 
4743 	    l_Detail_Attr_Changed       Varchar2(1) := 'N';
4744 	    l_Logical_Rec_Changed       Varchar2(1) := 'N';
4745 
4746         l_Inc_By_Org_Id             Pa_Expenditures_All.Incurred_By_Organization_Id%TYPE := Null;
4747         l_Job_Id                    Pa_Expenditure_Items_All.Job_Id%TYPE:= Null;
4748         l_Ovr_Approver_Person_Id    Pa_Expenditures_All.Overriding_Approver_Person_Id%TYPE := Null;
4749 
4750         l_Bill_Flag_Meaning         Fnd_Lookups.Meaning%TYPE := Null;
4751 
4752         l_Proj_Attrib_Rec           Pa_Otc_Api.Project_Attribution_Rec;
4753 
4754         l_Msg_Name                  VARCHAR2(30)          := Null;
4755         l_Msg_Application           VARCHAR2(2)           := Null;
4756         l_Msg_Type                  VARCHAR2(30)          := Null;
4757         l_Msg_Token1_Name           VARCHAR2(30)          := Null;
4758 	    l_Msg_Token1_Value          VARCHAR2(2000)        := Null;
4759         l_Msg_Token2_Name           VARCHAR2(30)          := Null;
4760         l_Msg_Token2_Value          VARCHAR2(2000)        := Null;
4761         l_Msg_Token3_Name           VARCHAR2(30)          := Null;
4762         l_Msg_Token3_Value          VARCHAR2(2000)        := Null;
4763 	    l_dummy_Message             VARCHAR2(2000)        := Null;
4764         l_Msg_Count                 NUMBER                := Null;
4765         l_Error_Code                VARCHAR2(30)          := Null;
4766         l_Error_Type                VARCHAR2(30)          := Null;
4767 
4768    	    l_Error_Stack   	        Varchar2(2000);
4769    	    l_Old_Stack         	    Varchar2(2000);
4770    	    l_Error_Stage   	        Varchar2(2000);
4771    	    l_Error_Message 	        Varchar2(2000);
4772 
4773 	    -- Variables for dff validation
4774    	    l_recDFlexR                 Fnd_Dflex.Dflex_R;
4775    	    l_recDFlexDR                Fnd_Dflex.Dflex_Dr;
4776    	    l_recContextsDR             Fnd_Dflex.Contexts_Dr;
4777    	    l_arrDflex                  Pa_Self_Service_Dflex_Pub.Dflex_Array;
4778    	    l_strContext                Varchar2(30); -- Changed length from 20 to 30.  Bug 4036480
4779    	    l_strReferenceField         Varchar2(200);
4780 	    l_bresult                   Boolean;
4781 
4782         /* Variables needed for running of the summary-validation and Business Message APIs */
4783         l_Timecard_Table            Pa_Otc_Api.Timecard_Table;
4784         l_Timecard_Table_Week       Pa_Otc_Api.Timecard_Table;
4785         l_Weeks_To_Process          Binary_Integer := 0;
4786         l_Exp_Ending_Date_Check     Pa_Expenditures_All.Expenditure_Ending_Date%TYPE := Null;
4787         l_Timecard_Table_Index      Binary_Integer := 0;
4788         l_Time_Building_Block_Id    Hxc_Time_Building_Blocks.Time_Building_Block_Id%TYPE := Null;
4789 	    l_Approval_Status           Hxc_Time_Building_Blocks.Approval_Status%TYPE := Null;
4790 
4791         TYPE Exp_End_Date_Rec IS Record (
4792           Expenditure_Ending_Date     Pa_Expenditures_All.Expenditure_Ending_Date%TYPE,
4793           Incurred_By_Person_Id       Pa_Expenditures_All.Incurred_By_Person_Id%TYPE);
4794 
4795         TYPE Exp_End_Date_Tab IS Table OF Exp_End_Date_Rec
4796           INDEX BY Binary_Integer;
4797 
4798         l_Detail_BB_Id  Hxc_Time_Building_Blocks.Time_Building_Block_Id%TYPE := Null;
4799         l_Detail_BB_Ovn Hxc_Time_Building_Blocks.Object_Version_Number%TYPE  := Null;
4800 
4801         l_Exp_End_Date_Tab Exp_End_Date_Tab;
4802 
4803         /* Stores a single record from the Building Block Table */
4804         l_Building_Block_Record Hxc_User_Type_Definition_Grp.Building_Block_Info;
4805 
4806         Cursor GetBillFlagMeaning(P_Lookup_Code IN VARCHAR2) Is
4807         Select
4808                Meaning
4809         From
4810                Fnd_Lookups
4811         Where
4812                Lookup_Type = 'YES_NO'
4813         And    Lookup_Code = P_Lookup_Code;
4814 
4815 		/* For Bug 7645561*/
4816 		Cursor Check_Term_with_pay(p_person_id IN NUMBER) is
4817 		select max(person_id) from per_all_assignments_f paf,per_assignment_status_types past
4818 		where paf.person_id = p_person_id
4819 		and  paf.assignment_status_type_id = past.assignment_status_type_id
4820 		and  past.per_system_status = 'TERM_ASSIGN';
4821 		/* For Bug 7645561*/
4822 
4823 		test_term_with_pay  Number := Null;
4824 
4825 	    E_Unhandled_Exception 	Exception;
4826 	    E_Dff_Exception       	Exception;
4827 
4828 	    l_Header_Pass_Val_Flag 	Varchar2(1) := Null;
4829 	    i 		       	Binary_Integer := Null;
4830 	-- Added for bug 8345301
4831         l_closed_proj_flag          Varchar2(1) := 'N';
4832         l_bbid   Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE := Null;
4833 	l_calling_module     VARCHAR2(20); /*Added for bug#13803367 */
4834 
4835   Begin
4836 	l_calling_module  :='PAXVOTCB'; /*Added for bug#13803367 */
4837 
4838 	G_Stage := 'Entering procedure Validate_Process().';
4839 	Pa_Otc_Api.TrackPath('ADD','Validate_Process');
4840 
4841 	-- The out variables are used in the summary level validation and the business message
4842 	-- API calls.
4843 
4844 	G_Stage := 'Find and Validate Header Record in the Building Blocks Pl/Sql table.';
4845 	Pa_Otc_Api.FindandValidateHeader(
4846          P_Building_Blocks_Table  => P_Building_Blocks,
4847          P_Attribute_Table        => P_Attribute_Table,
4848          P_Message_Table          => P_Message_Table,
4849          X_TimeBB_Id              => l_Time_Building_Block_Id,
4850          X_Ovr_Approver_Person_Id => l_Ovr_Approver_Person_Id,
4851          X_Pass_Val_Flag          => l_Header_Pass_Val_Flag,
4852          X_Approval_Status        => l_Approval_Status);
4853 
4854 	If l_Header_Pass_Val_Flag = 'N' Then
4855 
4856 		RETURN;
4857 
4858 	End If;
4859 
4860 	-- Initializing dff validation procedures
4861 	G_Stage := 'Call procedure Pa_Self_Service_Dflex_Pub.InitDFlex().';
4862     Pa_Self_Service_Dflex_Pub.InitDFlex(
4863          P_StrProductName => 'PA',
4864          P_StrDFlexName   => 'PA_EXPENDITURE_ITEMS_DESC_FLEX',
4865          P_sErrorStack    => l_Error_Stack,
4866          X_RecDFlexR      => l_RecDFlexR,
4867          X_RecDFlexDR     => l_RecDFlexDR,
4868          X_RecContextsDR  => l_RecContextsDR,
4869          X_sErrorType     => l_Error_Type,
4870          X_sErrorStack    => l_Error_Stack,
4871          X_sErrorStage    => l_Error_Stage,
4872          X_sErrorMessage  => l_Error_Message);
4873 
4874     --If an unexpected error occured in InitDFlex
4875     --then raise the exception.
4876 
4877     If (l_Error_Type = 'U') Then
4878 
4879          Raise E_Dff_Exception;
4880 
4881     End If;
4882 
4883     -- Call IsDFlexUsed to determine whether any desc flex segments
4884     -- are defined.  If no, then it is not necessary to perform DFF
4885     -- validation.
4886 
4887 	G_Stage := 'Call Pa_Self_Service_Dflex_Pub.IsDFlexUsed().';
4888     Pa_Self_Service_Dflex_Pub.IsDFlexUsed(
4889          P_RecDFlexR     => l_RecDFlexR,
4890          P_RecContextsDR => l_RecContextsDR,
4891          P_sErrorStack   => l_Error_Stack,
4892          X_bResult       => l_bResult,
4893          X_sErrorType    => l_Error_Type,
4894          X_sErrorStack   => l_Error_Stack,
4895          X_sErrorStage   => l_Error_Stage,
4896          X_sErrorMessage => l_Error_Message);
4897 
4898     --If an unexpected error occured in IsDFlexUsed then raise the exception.
4899 
4900     If (l_Error_Type = 'U') Then
4901 
4902          Raise E_Dff_Exception;
4903 
4904     End If;
4905 
4906     --Call GetDFlexReferenceField to determine the Reference field for the DFF, either
4907     --system_linkage_function or expenditure_type in this case.
4908 
4909 	G_Stage := 'Call Pa_Self_Service_Dflex_Pub.GetDFlexReferenceField().';
4910     Pa_Self_Service_DFlex_Pub.GetDFlexReferenceField(
4911          P_RecDFlexDR        => l_RecDFlexDR,
4912          P_sErrorStack       => l_Error_Stack,
4913          X_StrReferenceField => l_strReferenceField,
4914          X_sErrorType        => l_Error_Type,
4915          X_sErrorStack       => l_Error_Stack,
4916          X_sErrorStage       => l_Error_Stage,
4917          X_sErrorMessage     => l_Error_Message);
4918 
4919     --If an unexpected error occured in GetDFlexReferenceField then raise the exception.
4920 
4921     If (l_Error_Type = 'U') Then
4922 
4923          Raise E_Dff_Exception;
4924 
4925     End If;
4926 
4927     G_Stage := 'Loop thru Building Blocks record to validate detail records.';
4928     Loop
4929 
4930 	     If i is null Then
4931 
4932 		      i := P_Building_Blocks.First;
4933 
4934 	     Else
4935 
4936 		      i := P_Building_Blocks.Next(i);
4937 
4938 	     End If;
4939 
4940 	     If P_Building_Blocks(i).Scope = 'DETAIL' Then
4941 
4942 	          G_Stage := 'Init variables within loop.';
4943 	          l_Building_Block_Record := P_Building_Blocks(i);
4944 	          l_Detail_Attr_Changed := 'N';
4945 
4946               G_Stage := 'Pull out the data to friendlier formated variables.';
4947                --  Pull out the data to project friendly variables
4948               Pa_Otc_Api.RetrieveProjAttribution(
4949                    P_Building_Block_Rec  => l_Building_Block_Record,
4950 			       P_Building_Block      => P_Building_Blocks,
4951                    P_Attribute_Table     => P_Attribute_Table,
4952 			       X_Detail_Attr_Changed => l_Detail_Attr_Changed,
4953 			       X_Proj_Attrib_Rec     => l_Proj_Attrib_Rec);
4954 
4955 		      G_Stage := 'Determine record change flag value.';
4956 		      If l_Detail_Attr_Changed = 'Y' OR P_Building_Blocks(i).Changed = 'Y' Then
4957 
4958 			       l_Logical_Rec_Changed := 'Y';
4959 
4960 		      Else
4961 
4962 			       l_Logical_Rec_Changed := 'N';
4963 
4964 		      End If;
4965 
4966        /* bug 8345301 Code starts */
4967 
4968                 G_Stage := 'Trying to modify an item on a closed project.';
4969 				l_bbid := to_char( P_Building_Blocks(i).Time_Building_Block_Id) || ':%';
4970 
4971 				Begin
4972 				     Select
4973 						'Y'
4974 						into l_closed_proj_flag from  dual
4975 						where  exists  (select 1
4976 				    From
4977 				        Pa_Expenditure_Items_All ei,
4978 					pa_projects_all  ppa
4979 				    Where
4980 					    ei.project_id <>  l_Proj_Attrib_Rec.PROJECT_ID  and
4981 				        ei.project_id =  ppa.project_id and
4982 						nvl(ei.net_zero_adjustment_flag, 'N') <> 'Y' and
4983 				        ei.Transaction_Source = 'ORACLE TIME AND LABOR' and
4984 				        ei.Orig_Transaction_Reference like l_bbid
4985 		               --and ppa.project_status_code = 'CLOSED'
4986 			         AND PA_PROJECT_UTILS.check_prj_stus_action_allowed(ppa.PROJECT_STATUS_CODE, 'NEW_TXNS') = 'N' --Bug 8532951
4987 			       );
4988 				 Exception
4989 				 When  NO_DATA_FOUND Then
4990 				   l_closed_proj_flag := 'N';
4991 				 End;
4992 
4993 
4994 
4995 				If  l_closed_proj_flag = 'Y'  Then
4996 				 -- Add record to error table.
4997 	                            Pa_Otc_Api.Add_Error_To_Table(
4998 	                                 P_Message_Table           => P_Message_Table,
4999 	                                 P_Message_Name            => 'PA_NEW_TXNS_NOT_ALLOWED',
5000 	                                 P_Message_Level           => 'ERROR',
5001 	                                 P_Message_Field           => NULL,
5002 	                                 P_Msg_Tokens              => G_Msg_Tokens_Table,
5003 	                                 --P_Time_Building_Block_Id  => NULL,
5004 									 P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5005 	                                 P_Time_Attribute_Id       => NULL);
5006 			  end if ;
5007 
5008            /* bug 8345301 Code ends  */
5009 
5010 
5011 
5012               G_Stage := 'Determine the processing flags for use further in code.';
5013               Pa_Otc_Api.DetermineProcessingFlags(
5014                    P_BB_Id                => P_Building_Blocks(i).Time_Building_Block_Id,
5015                    P_BB_Ovn               => P_Building_Blocks(i).Object_Version_Number,
5016 			       P_BB_Date_To           => P_Building_Blocks(i).Date_To,
5017 			       P_BB_Changed           => l_Logical_Rec_Changed,
5018 			       P_BB_New               => P_Building_Blocks(i).New,
5019 			       P_Proj_Attribute_Rec   => l_Proj_Attrib_Rec,
5020 			       P_Mode                 => 'VALIDATE',
5021                    P_Process_Flag         => P_Building_Blocks(i).Process,
5022                    X_BB_Detail_Changed    => l_BB_Detail_Changed,
5023 			       X_Data_Conflict_Flag   => l_Data_Conflict_Flag,
5024 			       X_BB_Detail_Deleted    => l_BB_Detail_Deleted,
5025                    X_Adj_in_Projects_Flag => l_Adjusted_In_Projects);
5026 
5027 		     -- If the Building Block(BB) can be adjusted in OTL then that will consistently be the case
5028              -- until the BB is imported into projects at which point the ei associated to the
5029 		     -- BB and Object_Version_Number combo can be adjusted or reversed out prior to any attempt to
5030              -- adjust the BB in OTL.  Anotherwards, once adjusted on OTL then can't adjust in Projects
5031 		     -- and vice versa.
5032 		     --
5033              -- If l_Adjusted_In_Projects is 'Y' then
5034 		     --   An adjustment was made in Projects so can't adjust in OTL.
5035              -- If l_Adjusted_In_Projects is 'N' then
5036 		     --   No adjustment was made in projects so it can be adjusted in OTL
5037 		     --   or it is not in projects yet and can do whatever wanted.
5038              --
5039 
5040 		     If l_Adjusted_In_Projects  = 'Y' Then
5041 
5042 			      G_Stage := 'Item is Adjusted.';
5043 
5044 		   	      If l_BB_Detail_Deleted = 'Y' Then
5045 
5046 				       G_Stage := 'Building Block has been deleted.';
5047 
5048                        -- Really don't need to process this record any further.
5049                        -- The timecard cannot be save or submitted due to this.  Period!
5050 
5051 				       If l_Data_Conflict_Flag = 'Y' Then
5052 
5053 					        G_Stage := 'Not allowed to delete Item In OTL data conflict - Inserting error rec.';
5054 
5055                             G_Msg_Tokens_Table.Delete;
5056 
5057                             -- Add record to error table.
5058                             Pa_Otc_Api.Add_Error_To_Table(
5059                                  P_Message_Table           => P_Message_Table,
5060                                  P_Message_Name            => 'PA_TR_UNDO_DEL_IN_OTC',
5061                                  P_Message_Level           => 'ERROR',
5062                                  P_Message_Field           => NULL,
5063                                  P_Msg_Tokens              => G_Msg_Tokens_Table,
5064                                  P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5065                                  P_Time_Attribute_Id       => NULL);
5066 
5067 				       Else
5068 
5069 					        G_Stage := 'Not allowed to Delete Item In OTL - Inserting error rec.';
5070 					        G_Msg_Tokens_Table.Delete;
5071 
5072                             -- Add record to error table.
5073                             Pa_Otc_Api.Add_Error_To_Table(
5074                                  P_Message_Table           => P_Message_Table,
5075                                  P_Message_Name            => 'PA_NO_DEL_EX_ITEM',
5076                                  P_Message_Level           => 'ERROR',
5077                                  P_Message_Field           => NULL,
5078                                  P_Msg_Tokens              => G_Msg_Tokens_Table,
5079                                  P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5080                                  P_Time_Attribute_Id       => NULL);
5081 
5082 				       End If;  -- Data Confict or SUBMIT
5083 
5084 			      End If; -- l_BB_Detail_Deleted is Y
5085 
5086                   If l_BB_Detail_Changed = 'Y' and l_BB_Detail_Deleted = 'N' Then
5087 
5088 				       If l_Data_Conflict_Flag = 'Y' Then
5089 
5090 					        -- Really don't need to process this record any further.
5091 					        -- The timecard cannot be save due to this.  Period!
5092 
5093                             G_Stage := 'Not allowed to Adjust Item In OTL confict - Inserting error rec.';
5094 					        G_Msg_Tokens_Table.Delete;
5095 
5096                             -- Add record to error table.
5097                             Pa_Otc_Api.Add_Error_To_Table(
5098                                  P_Message_Table           => P_Message_Table,
5099                                  P_Message_Name            => 'PA_TR_UNDO_CHGE_IN_OTC',
5100                                  P_Message_Level           => 'ERROR',
5101                                  P_Message_Field           => NULL,
5102                                  P_Msg_Tokens              => G_Msg_Tokens_Table,
5103                                  P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5104                                  P_Time_Attribute_Id       => NULL);
5105 
5106 				       Else
5107 
5108 					        G_Stage := 'Not allowed to Adjust Item In OTL - Inserting error rec.';
5109 
5110 					        G_Msg_Tokens_Table.Delete;
5111 
5112 					        -- Add record to error table.
5113 					        Pa_Otc_Api.Add_Error_To_Table(
5114        	           			     P_Message_Table           => P_Message_Table,
5115        	           			     P_Message_Name            => 'PA_TR_ADJ_NO_NET_ZERO',
5116                   			     P_Message_Level           => 'ERROR',
5117                   			     P_Message_Field           => NULL,
5118                   			     P_Msg_Tokens              => G_Msg_Tokens_Table,
5119                   			     P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5120                   			     P_Time_Attribute_Id       => NULL);
5121 
5122 				       End If; -- l_Data_Conflict_Flag is 'Y'
5123 
5124                   End If;  -- l_BB_Detail_Changed is Y and l_BB_Detail_Deleted is N
5125 
5126 		     End If; -- l_Adjusted_In_Projects is Y
5127 
5128 		     If  /* l_BB_Detail_Deleted = 'N' and  */  -- again commented for 11656282 /* removed the comments for bug 10033549 */--Commented for  bug 8546092  / 8284884
5129 		       (l_BB_Detail_Deleted = 'N' OR (l_BB_Detail_Deleted = 'Y'
5130                       and l_Proj_Attrib_Rec.Quantity is null)) and --Added for bug#13803367
5131 			l_Adjusted_In_Projects = 'N' and
5132 		        ( l_BB_Detail_Changed = 'Y' or P_Building_Blocks(i).New = 'Y') Then
5133 
5134 			/*Added for bug#13803367*/
5135 			IF (l_BB_Detail_Deleted = 'Y' and
5136 			l_Proj_Attrib_Rec.Quantity is null) THEN
5137 			--{
5138 				l_calling_module  :='PAXVOTCBDEL';
5139 			--}
5140 			ELSE
5141 			--{
5142 				l_calling_module  :='PAXVOTCB';
5143 			--}
5144 			END IF;
5145 
5146 			/*End of changes for bug#13803367*/
5147 
5148 			      G_Stage := 'Check the Unit Of Measure value.';
5149                   If l_Proj_Attrib_Rec.UOM <> 'HOURS' Then
5150 
5151                        -- Really don't need to process this record any further.
5152                        -- The timecard cannot be save due to this.  Period!
5153 
5154                        G_Stage := 'Cannot have data where UOM is not HOURS - Inserting error rec.';
5155 
5156                        G_Msg_Tokens_Table.Delete;
5157 
5158                        -- Add record to error table.
5159                        Pa_Otc_Api.Add_Error_To_Table(
5160                             P_Message_Table           => P_Message_Table,
5161                             P_Message_Name            => 'PA_UOM_MUST_BE_HOURS',
5162                             P_Message_Level           => 'ERROR',
5163                             P_Message_Field           => NULL,
5164                             P_Msg_Tokens              => G_Msg_Tokens_Table,
5165                             P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5166                             P_Time_Attribute_Id       => NULL);
5167 
5168                   End If; -- l_UOM <> 'HOURS'
5169 
5170 			      G_Stage := 'Check for quantity being negative.';
5171                   If l_Proj_Attrib_Rec.Quantity < 0 And
5172 			         Nvl(Fnd_Profile.Value('PA_SST_ALLOW_NEGATIVE_TXN'),'N') = 'N' Then
5173 
5174 				       -- If the quantity is less than 0 and the profile is set to not allow
5175                        -- for negative transactions then raise error in error table.
5176 				       --
5177                        -- Really don't need to process this record any further.
5178                        -- The timecard cannot be save due to this.  Period!
5179 
5180                        G_Stage := 'Negative quantity not allowed In OTL - Inserting error rec.';
5181                        G_Msg_Tokens_Table.Delete;
5182 
5183                        -- Add record to error table.
5184                        Pa_Otc_Api.Add_Error_To_Table(
5185                             P_Message_Table           => P_Message_Table,
5186                             P_Message_Name            => 'PA_SU_NEGATIVE_NUM_NOT_ALLOWED',
5187                             P_Message_Level           => 'ERROR',
5188                             P_Message_Field           => NULL,
5189                             P_Msg_Tokens              => G_Msg_Tokens_Table,
5190                             P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5191                             P_Time_Attribute_Id       => NULL);
5192 
5193                   End If; -- P_Building_Blocks_Table(i).Measure is negative and it is not allowed
5194 
5195 			      -- Begin PA.M/CWK changes
5196 			      If l_Proj_Attrib_Rec.Person_Type not in ('CWK','EMP') Then
5197 
5198 	                   G_Stage := 'Invalid Person Type - Inserting error rec.';
5199         	           G_Msg_Tokens_Table.Delete;
5200 
5201                 	   -- Add record to error table.
5202                        Pa_Otc_Api.Add_Error_To_Table(
5203                             P_Message_Table           => P_Message_Table,
5204 	                        P_Message_Name            => 'PA_INVALID_PERSON_TYPE',
5205         	                P_Message_Level           => 'ERROR',
5206                 	        P_Message_Field           => NULL,
5207                         	P_Msg_Tokens              => G_Msg_Tokens_Table,
5208                             P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5209 	                        P_Time_Attribute_Id       => NULL);
5210 
5211 				-- Bug 13356442
5212 			      ElsIf l_Proj_Attrib_Rec.Person_Type = 'CWK' and l_Proj_Attrib_Rec.Project_Id is not null Then
5213 
5214 				       If Pa_Pjc_Cwk_Utils.Is_Cwk_Tc_Xface_Allowed(l_Proj_Attrib_Rec.Project_Id) <> 'Y' And
5215                           l_Proj_Attrib_Rec.PO_Line_Id Is Not Null And
5216                           l_Proj_Attrib_Rec.Sys_Linkage_Func in ('OT','ST') Then
5217 
5218 	                        G_Stage := 'Project organization does not allow CWK timecards - Inserting error rec.';
5219         	                G_Msg_Tokens_Table.Delete;
5220 
5221                 	        -- Add record to error table.
5222                         	Pa_Otc_Api.Add_Error_To_Table(
5223                                  P_Message_Table           => P_Message_Table,
5224 	                             P_Message_Name            => 'PA_CWK_TC_NOT_ALLOWED',
5225         	                     P_Message_Level           => 'ERROR',
5226                 	             P_Message_Field           => NULL,
5227                         	     P_Msg_Tokens              => G_Msg_Tokens_Table,
5228                                  P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5229 	                             P_Time_Attribute_Id       => NULL);
5230 
5231 				       Else
5232 
5233                             G_Stage := 'Check if the CWK working is creating timecard with PO reference.';
5234                             If l_Proj_Attrib_Rec.PO_Line_Id Is Not Null Then
5235 
5236                                  G_Stage := 'Check if the PO_Price_Type is populated.  It is required.';
5237 					             If l_Proj_Attrib_Rec.PO_Price_Type is Null Then
5238 
5239 	                                  G_Stage := 'Price Type is null - Inserting error rec.';
5240         	                          G_Msg_Tokens_Table.Delete;
5241 
5242                 	                  -- Add record to error table.
5243                         	          Pa_Otc_Api.Add_Error_To_Table(
5244                                 	       P_Message_Table           => P_Message_Table,
5245 	                                       P_Message_Name            => 'PA_CWK_PRICE_TYPE_NULL',
5246         	                               P_Message_Level           => 'ERROR',
5247                 	                       P_Message_Field           => NULL,
5248                         	               P_Msg_Tokens              => G_Msg_Tokens_Table,
5249                                 	       P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5250 	                                       P_Time_Attribute_Id       => NULL);
5251 
5252 					             ElsIf l_Proj_Attrib_Rec.Vendor_Id is Null Then
5253 
5254 	                                  G_Stage := 'Derived Vendor Id is null - Inserting error rec.';
5255         	                          G_Msg_Tokens_Table.Delete;
5256 
5257                 	                  -- Add record to error table.
5258                         	          Pa_Otc_Api.Add_Error_To_Table(
5259                                 	       P_Message_Table           => P_Message_Table,
5260 	                                       P_Message_Name            => 'PA_CWK_VEND_INFO_NULL',
5261         	                               P_Message_Level           => 'ERROR',
5262                 	                       P_Message_Field           => NULL,
5263                         	               P_Msg_Tokens              => G_Msg_Tokens_Table,
5264                                 	       P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5265 	                                       P_Time_Attribute_Id       => NULL);
5266 
5267 					             End If;
5268 
5269                             End If;  -- l_Proj_Attrib_Rec.PO_Line_Id Is Not Null
5270 
5271 				       End If;
5272 
5273 			      End If;
5274 			      -- End PA.M/CWK changes
5275 
5276 			      -- Get Project Number
5277 			      l_Error_Code := Null;
5278 			      G_stage := 'Get Project Number.';
5279 			      Pa_Otc_Api.Validate_Project_Exists(
5280 				       P_Project_Id     => l_Proj_Attrib_Rec.Project_Id,
5281                        X_Error_Code     => l_Error_Code,
5282                        X_Error_Type     => l_Error_Type,
5283                        X_Project_Number => l_Proj_Attrib_Rec.Project_Number);
5284 
5285 			      If l_Error_Code is Not Null Then
5286 
5287 				       G_Stage := 'Get Project Number - Inserting error rec.';
5288                        G_Msg_Tokens_Table.Delete;
5289 
5290 				       -- Add record to error table.
5291                        Pa_Otc_Api.Add_Error_To_Table(
5292                             P_Message_Table           => P_Message_Table,
5293                             P_Message_Name            => l_Error_Code,
5294                             P_Message_Level           => 'ERROR',
5295                             P_Message_Field           => 'PROJECT_ID',
5296                             P_Msg_Tokens              => G_Msg_Tokens_Table,
5297                             P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5298                             P_Time_Attribute_Id       => l_Proj_Attrib_Rec.Proj_Attr_Id);
5299 
5300 			      End If; -- l_Error_Code is not NULL
5301 
5302 			      -- Get Task Number
5303 			      l_Error_Code := Null;
5304 			      G_stage := 'Get Task Number.';
5305 			      Pa_Otc_Api.Validate_Task_Exists(
5306                        P_Task_Id     => l_Proj_Attrib_Rec.Task_Id,
5307 					   P_Project_Id  => l_Proj_Attrib_Rec.Project_Id,
5308                        X_Error_Code  => l_Error_Code,
5309                        X_Error_Type  => l_Error_Type,
5310                        X_Task_Number => l_Proj_Attrib_Rec.Task_Number);
5311 
5312                   If l_Error_Code is Not Null Then
5313 
5314 				       G_Stage := 'Get Task Number - Inserting error rec.';
5315                        G_Msg_Tokens_Table.Delete;
5316 
5317                        -- Add record to error table.
5318                        Pa_Otc_Api.Add_Error_To_Table(
5319                             P_Message_Table           => P_Message_Table,
5320                             P_Message_Name            => l_Error_Code,
5321                             P_Message_Level           => 'ERROR',
5322                             P_Message_Field           => 'TASK_ID',
5323                             P_Msg_Tokens              => G_Msg_Tokens_Table,
5324                             P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5325                             P_Time_Attribute_Id       => l_Proj_Attrib_Rec.Task_Attr_Id);
5326 
5327                   End If;
5328 
5329 			      -- Get Work Type Name
5330 			      l_Error_Code := Null;
5331 			      G_stage := 'Get Work Type Info.';
5332 			      Pa_Otc_Api.Validate_Work_Type_Exists(
5333 				       P_Work_Type_Id   => l_Proj_Attrib_Rec.Work_Type_Id,
5334                		   P_Exp_Item_Date  => l_Proj_Attrib_Rec.Expenditure_Item_Date,
5335                        X_Error_Code     => l_Error_Code,
5336                        X_Error_Type     => l_Error_Type);
5337 
5338 			      If l_Error_Code is Not Null Then
5339 
5340 				       G_Stage := 'Get Work Type Info - Inserting error rec.';
5341                        G_Msg_Tokens_Table.Delete;
5342 
5343 				       -- Add record to error table.
5344                        Pa_Otc_Api.Add_Error_To_Table(
5345                             P_Message_Table           => P_Message_Table,
5346                             P_Message_Name            => l_Error_Code,
5347                             P_Message_Level           => 'ERROR',
5348                             P_Message_Field           => 'WORK_TYPE_ID',
5349                             P_Msg_Tokens              => G_Msg_Tokens_Table,
5350                             P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5351                             P_Time_Attribute_Id       => l_Proj_Attrib_Rec.Work_Type_Attr_Id);
5352 
5353 			      End If; -- l_Error_Code is not NULL
5354 
5355 			      -- Get Job info
5356 			      l_Error_Code := Null;
5357 			      G_stage := 'Get Job Info.';
5358 			      Pa_Otc_Api.Validate_Job_Exists(
5359 				       P_Job_Id         => l_Proj_Attrib_Rec.Job_Id,
5360                		   P_Exp_Item_Date  => l_Proj_Attrib_Rec.Expenditure_Item_Date,
5361                        X_Error_Code     => l_Error_Code,
5362                        X_Error_Type     => l_Error_Type);
5363 
5364 			      If l_Error_Code is Not Null Then
5365 
5366 				       G_Stage := 'Get Job Info - Inserting error rec.';
5367                        G_Msg_Tokens_Table.Delete;
5368 
5369 				       -- Add record to error table.
5370                        Pa_Otc_Api.Add_Error_To_Table(
5371                             P_Message_Table           => P_Message_Table,
5372                             P_Message_Name            => l_Error_Code,
5373                             P_Message_Level           => 'ERROR',
5374                             P_Message_Field           => 'JOB_ID',
5375                             P_Msg_Tokens              => G_Msg_Tokens_Table,
5376                             P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5377                             P_Time_Attribute_Id       => l_Proj_Attrib_Rec.Job_Id_Attr_Id);
5378 
5379 			      End If; -- l_Error_Code is not NULL
5380 
5381 			      -- Get Work Type Name
5382 			      l_Error_Code := Null;
5383 			      G_stage := 'Get Location Info.';
5384 			      Pa_Otc_Api.Validate_Location_Exists(
5385 				       P_Location_Id    => l_Proj_Attrib_Rec.Location_Id,
5386                		   P_Exp_Item_Date  => l_Proj_Attrib_Rec.Expenditure_Item_Date,
5387                        X_Error_Code     => l_Error_Code,
5388                        X_Error_Type     => l_Error_Type);
5389 
5390 			      If l_Error_Code is Not Null Then
5391 
5392 				       G_Stage := 'Get Location Info - Inserting error rec.';
5393                        G_Msg_Tokens_Table.Delete;
5394 
5395 				       -- Add record to error table.
5396                        Pa_Otc_Api.Add_Error_To_Table(
5397                             P_Message_Table           => P_Message_Table,
5398                             P_Message_Name            => l_Error_Code,
5399                             P_Message_Level           => 'ERROR',
5400                             P_Message_Field           => 'LOCATION_ID',
5401                             P_Msg_Tokens              => G_Msg_Tokens_Table,
5402                             P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5403                             P_Time_Attribute_Id       => l_Proj_Attrib_Rec.Location_Id_Attr_Id);
5404 
5405 			      End If; -- l_Error_Code is not NULL
5406 
5407 			      -- Validate the expenditure type and system linkage function
5408 			      G_Stage := 'Validation the expenditure type and system linkage function.';
5409 			      l_Error_Code := Null;
5410 
5411 			      Pa_Otc_Api.Validate_Exp_Type_Exists(
5412                	       P_System_Linkage   => l_Proj_Attrib_Rec.Sys_Linkage_Func,
5413                		   P_Expenditure_Type => l_Proj_Attrib_Rec.Expenditure_Type,
5414                		   P_Exp_Item_Date    => l_Proj_Attrib_Rec.Expenditure_Item_Date,
5415                		   X_Error_Type       => l_Error_Type,
5416                		   X_Error_Code       => l_Error_Code);
5417 
5418 			      If l_Error_Code is Not Null Then
5419 
5420 				       G_Stage := 'Validate the exp type and syst link func - Inserting error rec.';
5421                        -- Add record to error table.
5422 
5423                        G_Msg_Tokens_Table.Delete;
5424 
5425 				       If l_Proj_Attrib_Rec.Sys_Linkage_Func Is Null OR
5426 				          l_Proj_Attrib_Rec.Sys_Linkage_Func Not in ('OT','ST') Then
5427 
5428                             Pa_Otc_Api.Add_Error_To_Table(
5429                                  P_Message_Table           => P_Message_Table,
5430                                  P_Message_Name            => l_Error_Code,
5431                                  P_Message_Level           => 'ERROR',
5432                                  P_Message_Field           => 'SYSTEM_LINKAGE_FUNCTION',
5433                                  P_Msg_Tokens              => G_Msg_Tokens_Table,
5434                                  P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5435                                  P_Time_Attribute_Id       => l_Proj_Attrib_Rec.Sys_Link_Attr_Id);
5436 
5437 				       Else
5438 
5439                             Pa_Otc_Api.Add_Error_To_Table(
5440                                  P_Message_Table           => P_Message_Table,
5441                                  P_Message_Name            => l_Error_Code,
5442                                  P_Message_Level           => 'ERROR',
5443                                  P_Message_Field           => 'EXPENDITURE_TYPE',
5444                                  P_Msg_Tokens              => G_Msg_Tokens_Table,
5445                                  P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5446                                  P_Time_Attribute_Id       => l_Proj_Attrib_Rec.Exp_Type_Attr_Id);
5447 
5448 				       End If; -- l_Sys_Linkage_Func
5449 
5450 			      ElsIf l_Proj_Attrib_Rec.Sys_Linkage_Func Not in ('OT','ST') Then
5451 
5452 				       G_Stage := 'Invalid sys link func - Inserting error rec.';
5453                        -- Add record to error table.
5454 
5455 				       G_Msg_Tokens_Table.Delete;
5456 
5457                        Pa_Otc_Api.Add_Error_To_Table(
5458 					        P_Message_Table           => P_Message_Table,
5459 					        P_Message_Name            => 'INVALID_ETYPE_SYSLINK',
5460 					        P_Message_Level           => 'ERROR',
5461 					        P_Message_Field           => 'SYSTEM_LINKAGE_FUNCTION',
5462 					        P_Msg_Tokens              => G_Msg_Tokens_Table,
5463 					        P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5464 					        P_Time_Attribute_Id       => l_Proj_Attrib_Rec.Sys_Link_Attr_Id);
5465 
5466 			      End If; -- l_Error_Code is not null
5467 
5468 			      -- Get Incurred_By_Organization_Id
5469 			      l_Error_Code := Null;
5470 			      l_Inc_By_Org_Id := Null;
5471 			      G_Stage := 'Get Incurred by Organization Id.';
5472    			      l_Inc_By_Org_Id := Pa_Utils.GetEmpOrgId(
5473                        				      X_Person_Id => l_Proj_Attrib_Rec.Inc_By_Person_Id,
5474                        				      X_Date      => l_Proj_Attrib_Rec.Expenditure_Item_Date);
5475 
5476 			      If l_Inc_By_Org_Id is Null Then
5477 
5478 				       G_Stage := 'Get Inc by Org Id - Inserting error rec.';
5479                        G_Msg_Tokens_Table.Delete;
5480 
5481 				       G_Msg_Tokens_Table(1).Token_Name := 'EXPDATE';
5482 				       G_Msg_Tokens_Table(1).Token_Value :=
5483 					   fnd_date.date_to_displaydate(l_Proj_Attrib_Rec.Expenditure_Item_Date);
5484 
5485                        -- Add record to error table.
5486                        Pa_Otc_Api.Add_Error_To_Table(
5487                             P_Message_Table           => P_Message_Table,
5488                             P_Message_Name            => 'NO_ASSIGNMENT',
5489                             P_Message_Level           => 'ERROR',
5490                             P_Message_Field           => Null,
5491                             P_Msg_Tokens              => G_Msg_Tokens_Table,
5492                             P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5493                             P_Time_Attribute_Id       => Null);
5494 
5495                   Else
5496 
5497 				       -- If the employee is assigned to an organization then it makes sense to check
5498 				       -- to see if there is a job assigned to the employee
5499 				       -- If there is no org then there is no need to check job since the same
5500 				       -- error message is used.
5501 
5502 		        	   -- Check Job_Id
5503 		        	   G_Stage := 'Check for Job Id.';
5504                        -- Bug 10253400.. 12.2 payroll intg .. validate if user entered the job ..otherwise derive as is currently done.
5505 				       --l_Job_Id := Null;
5506                        -- get the job_id entered and validate it. If job is not entered then existing logic derives it.
5507                        l_job_Id := l_Proj_Attrib_Rec.Job_Id;
5508 
5509                        if l_Job_Id is not null then
5510                            l_Job_Id := pa_utils.getjobid(x_job_id => l_Proj_Attrib_Rec.Job_Id,
5511                                                          x_date   => l_Proj_Attrib_Rec.Expenditure_Item_Date);
5512                        else
5513                            l_Job_Id := Pa_Utils.GetEmpJobId (
5514                                             X_person_id => l_Proj_Attrib_Rec.Inc_By_Person_Id,
5515                                             X_date      => l_Proj_Attrib_Rec.Expenditure_Item_Date);
5516 
5517                        end if; -- l_job_id is not null
5518                        -- Bug 10253400.. 12.2 payroll intg .. end
5519                        If l_Job_Id is Null Then
5520 
5521                             G_Msg_Tokens_Table.Delete;
5522 
5523                             G_Msg_Tokens_Table(1).Token_Name := 'EXPDATE';
5524                             G_Msg_Tokens_Table(1).Token_Value :=
5525                             fnd_date.date_to_displaydate(l_Proj_Attrib_Rec.Expenditure_Item_Date);
5526 
5527                             G_Stage := 'Check Job Id - Inserting error rec.';
5528 
5529                             -- Add record to error table.
5530                             Pa_Otc_Api.Add_Error_To_Table(
5531                                  P_Message_Table           => P_Message_Table,
5532                                  P_Message_Name            => 'NO_ASSIGNMENT',
5533                                  P_Message_Level           => 'ERROR',
5534                                  P_Message_Field           => Null,
5535                                  P_Msg_Tokens              => G_Msg_Tokens_Table,
5536                                  P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5537                                  P_Time_Attribute_Id       => Null);
5538 
5539                        End If; -- l_Job_Id check
5540 			      End If; -- l_Inc_By_Org_Id check
5541 
5542 			      -- DFF validation section.
5543 			      If l_bResult Then
5544 
5545 	    		       If (l_StrReferenceField = 'SYSTEM_LINKAGE_FUNCTION') Then
5546 
5547  	             	        l_StrContext := l_Proj_Attrib_Rec.Sys_Linkage_Func;
5548 
5549   	    			   ElsIf (l_StrReferenceField = 'EXPENDITURE_TYPE') Then
5550 
5551  	             			l_StrContext := l_Proj_Attrib_Rec.Expenditure_Type;
5552 
5553  	     			   Else
5554 
5555  	             			l_StrContext := Null;
5556 
5557 	      			   End If;
5558 
5559 	        		   G_Stage := 'Customer has defined Dffs and enabled them.  ' ||
5560 			                      'Populate dflex array with attributes 1 - 10.';
5561 
5562                        l_ArrDFlex(1)  := l_Proj_Attrib_Rec.Attribute1;
5563                        l_ArrDFlex(2)  := l_Proj_Attrib_Rec.Attribute2;
5564                        l_ArrDFlex(3)  := l_Proj_Attrib_Rec.Attribute3;
5565                        l_ArrDFlex(4)  := l_Proj_Attrib_Rec.Attribute4;
5566                        l_ArrDFlex(5)  := l_Proj_Attrib_Rec.Attribute5;
5567                        l_ArrDFlex(6)  := l_Proj_Attrib_Rec.Attribute6;
5568                        l_ArrDFlex(7)  := l_Proj_Attrib_Rec.Attribute7;
5569                        l_ArrDflex(8)  := l_Proj_Attrib_Rec.Attribute8;
5570                        l_ArrDFlex(9)  := l_Proj_Attrib_Rec.Attribute9;
5571                        l_ArrDFlex(10) := l_Proj_Attrib_Rec.Attribute10;
5572 
5573 				       G_Stage := 'Call Pa_Self_Service_Dflex_Pub.ValidateDFlex().';
5574                        Pa_Self_Service_Dflex_Pub.ValidateDFlex(
5575                             P_StrProductName => 'PA',
5576                             P_StrDFlexName   => 'PA_EXPENDITURE_ITEMS_DESC_FLEX',
5577                             P_RecContextsDR  => l_RecContextsDR,
5578                             P_StrContextName => l_StrContext,
5579                             P_ArrDFlex       => l_ArrDFlex,
5580                             P_sErrorStack    => l_Error_Stack,
5581                             X_sErrorType     => l_Error_Type,
5582                             X_sErrorStack    => l_Error_Stack,
5583                             X_sErrorStage    => l_Error_Stage,
5584                             X_sErrorMessage  => l_Error_Message);
5585 
5586                        --If an unexpected error occured in ValidateDFlex then raise the exception.
5587 
5588                        If (l_Error_Type = 'U') Then
5589 
5590                             Raise E_Dff_Exception;
5591 
5592   				       ElsIf l_Error_Type = 'E' Then
5593 
5594   					        -- Can only provide generic message since can't pass back
5595   					        -- messages to OTL. Only message names and token info.
5596 
5597   					        G_Msg_Tokens_Table.Delete;
5598 
5599   					        Pa_Otc_Api.Add_Error_To_Table(
5600                                  P_Message_Table           => P_Message_Table,
5601                                  P_Message_Name            => 'PA_DFF_VALIDATION_FAILED',
5602                                  P_Message_Level           => 'ERROR',
5603                                  P_Message_Field           => Null,
5604                                  P_Msg_Tokens              => G_Msg_Tokens_Table,
5605                                  P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5606                                  P_Time_Attribute_Id       => Null);
5607 
5608   				       End If;
5609 
5610   			      End If;
5611 
5612 			      -- Transaction Control validation call.
5613 
5614 			      l_Status := Null;
5615 
5616 		    	  G_Stage := 'Firing patc call.';
5617         		  Pa_Transactions_Pub.Validate_Transaction(
5618                        X_Project_Id          => l_Proj_Attrib_Rec.Project_Id,
5619                        X_Task_Id             => l_Proj_Attrib_Rec.Task_Id,
5620                        X_Ei_Date             => l_Proj_Attrib_Rec.Expenditure_Item_Date,
5621                        X_Expenditure_Type    => l_Proj_Attrib_Rec.Expenditure_Type,
5622                        X_Non_Labor_Resource  => Null,
5623                        X_Person_Id           => l_Proj_Attrib_Rec.Inc_By_Person_Id,
5624                        X_Billable_Flag       => l_Proj_Attrib_Rec.Billable_Flag2,
5625                        X_Quantity            => l_Proj_Attrib_Rec.Quantity,
5626                        X_Transfer_Ei         => Null,
5627                        X_Incurred_By_Org_Id  => Null,  -- letting patc get it
5628                        X_NL_Resource_Org_Id  => Null,
5629                        X_Transaction_Source  => 'ORACLE TIME AND LABOR',
5630                        X_Calling_Module      => l_calling_module, /*Added for bug#13803367 */
5631                        X_Vendor_Id           => l_Proj_Attrib_Rec.Vendor_Id,
5632                        X_Entered_By_User_Id  => l_Proj_Attrib_Rec.Inc_By_Person_Id,
5633                        X_Attribute_Category  => l_Proj_Attrib_Rec.Attrib_Category,
5634                        X_Attribute1          => l_Proj_Attrib_Rec.Attribute1,
5635                        X_Attribute2          => l_Proj_Attrib_Rec.Attribute2,
5636                        X_Attribute3          => l_Proj_Attrib_Rec.Attribute3,
5637                        X_Attribute4          => l_Proj_Attrib_Rec.Attribute4,
5638                        X_Attribute5          => l_Proj_Attrib_Rec.Attribute5,
5639                        X_Attribute6          => l_Proj_Attrib_Rec.Attribute6,
5640                        X_Attribute7          => l_Proj_Attrib_Rec.Attribute7,
5641                        X_Attribute8          => l_Proj_Attrib_Rec.Attribute8,
5642                        X_Attribute9          => l_Proj_Attrib_Rec.Attribute9,
5643                        X_Attribute10         => l_Proj_Attrib_Rec.Attribute10,
5644                        -- MC columns are NULL because OTL does not support
5645                        -- multi-currency
5646                        X_Denom_Currency_Code => Null,
5647                        X_Acct_Currency_Code  => Null,
5648                        X_Denom_Raw_Cost      => Null,
5649                        X_Acct_Raw_Cost       => Null,
5650                        X_Acct_Rate_Type      => Null,
5651                        X_Acct_Rate_Date      => Null,
5652                        X_Acct_Exchange_Rate  => Null,
5653                        X_Msg_Application     => l_Msg_Application,
5654                        X_Msg_Type            => l_Msg_Type,
5655                        X_Msg_Token1          => l_Msg_Token1_Value,
5656                        X_Msg_Token2          => l_Msg_Token2_Value,
5657                        X_Msg_Token3          => l_Msg_Token3_Value,
5658                        X_Msg_Count           => l_Msg_Count,
5659                        X_Msg_Data            => l_Status,
5660 		               P_Po_Header_Id	     => l_Proj_Attrib_Rec.Po_Header_Id,
5661 		               P_Po_Line_Id	         => l_Proj_Attrib_Rec.Po_Line_Id,
5662 		               P_Person_Type	     => l_Proj_Attrib_Rec.Person_Type,
5663 		               P_Po_Price_Type	     => l_Proj_Attrib_Rec.Po_Price_Type,
5664 		               P_Sys_Link_Function   => l_Proj_Attrib_Rec.Sys_Linkage_Func,
5665                        -- Bug 10253400.. 12.2 payroll intg .. start
5666                        P_Job_Id              => l_Proj_Attrib_Rec.Job_Id,
5667                        P_Location_Id         => l_Proj_Attrib_Rec.Location_id);
5668                        -- Bug 10253400.. 12.2 payroll intg .. end
5669 
5670 					   /* Bug 7645561*/
5671 					   Open Check_Term_with_pay(l_Proj_Attrib_Rec.Inc_By_Person_Id);
5672 					   fetch Check_Term_with_pay into test_term_with_pay;
5673 					   Close Check_Term_with_pay;
5674 
5675 
5676 /* Bug 7645561*/
5677             If (l_status <> 'PA_NO_ASSIGNMENT' or test_term_with_pay is Null) then
5678 	        	  -- check if patc has returned any errors
5679         		  If l_Status is Not Null Then
5680 
5681 				       If Pa_Otc_Api.IsNumber(l_Status) Then
5682 
5683 					        Raise E_Unhandled_Exception;
5684 
5685 				       Else
5686 
5687 					        G_Stage := 'Patc returned status that is Not Null - Inserting error rec.';
5688                             G_Msg_Tokens_Table.Delete;
5689 
5690 					        If l_Msg_Token1_Value is not null Then
5691 
5692 						         G_Msg_Tokens_Table(1).Token_Name := 'PATC_MSG_TOKEN1';
5693 						         G_Msg_Tokens_Table(1).Token_Value := l_Msg_Token1_Value;
5694 
5695                             -- Begin message token is not defined for bug#4593869
5696                             Else
5697 
5698                                  G_Msg_Tokens_Table(1).Token_Name := 'PATC_MSG_TOKEN1';
5699                                  G_Msg_Tokens_Table(1).Token_Value := FND_API.G_MISS_CHAR;
5700 
5701                             -- End message token is not defined for bug#4593869
5702 					        End If;
5703 
5704                             If l_Msg_Token2_Value is not null Then
5705 
5706                                  G_Msg_Tokens_Table(2).Token_Name := 'PATC_MSG_TOKEN2';
5707                                  G_Msg_Tokens_Table(2).Token_Value := l_Msg_Token2_Value;
5708 
5709                             -- Begin message token is not defined for bug#4593869
5710                             Else
5711 
5712                                  G_Msg_Tokens_Table(2).Token_Name := 'PATC_MSG_TOKEN2';
5713                                  G_Msg_Tokens_Table(2).Token_Value := FND_API.G_MISS_CHAR;
5714 
5715                             -- End message token is not defined for bug#4593869
5716                             End If;
5717 
5718                             If l_Msg_Token3_Value is not null Then
5719 
5720                                  G_Msg_Tokens_Table(3).Token_Name := 'PATC_MSG_TOKEN3';
5721                                  G_Msg_Tokens_Table(3).Token_Value := l_Msg_Token3_Value;
5722 
5723                             -- Begin message token is not defined for bug#4593869
5724                             Else
5725 
5726                                  G_Msg_Tokens_Table(3).Token_Name := 'PATC_MSG_TOKEN3';
5727                                  G_Msg_Tokens_Table(3).Token_Value := FND_API.G_MISS_CHAR;
5728 
5729                             -- End message token is not defined for bug#4593869
5730                             End If;
5731 
5732 				       End If;
5733 
5734                        If l_Msg_Application is Null Then
5735 
5736 					        l_Msg_Application := 'PA';
5737 
5738 				       End If;
5739 
5740                        /* Added following if condition for Bug#2798986 */
5741 				       If l_Msg_Type = 'W' Then
5742 
5743 				            l_Error_Level := 'WARNING';
5744 
5745 				       ElsIf l_Msg_Type = 'E' Then
5746 
5747 				            l_Error_Level := 'ERROR';
5748 
5749 				       End If;
5750 
5751 				       If l_Status <> 'NO_ASSIGNMENT' Then
5752 
5753                             Pa_Otc_Api.Add_Error_To_Table(
5754                                  P_Message_Table           => P_Message_Table,
5755                                  P_Message_Name            => l_Status,
5756                                  P_Message_Level           => l_Error_Level, /* Bug#2798986 */
5757                                  P_Message_Field           => Null,
5758                                  P_Msg_Tokens              => G_Msg_Tokens_Table,
5759                                  P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5760                                  P_Time_Attribute_Id       => Null,
5761 						         P_Message_App             => l_Msg_Application);
5762 
5763 				       End If;
5764 
5765                        -- Begin Bug 4518893
5766                        If l_Msg_Type = 'W' Then
5767 
5768                             /* Check if the billable flag was change externally either by other app
5769                              * in OTL or by third party.
5770                              */
5771                             If l_Proj_Attrib_Rec.Billable_Flag <> l_Proj_Attrib_Rec.Billable_Flag2 Then
5772 
5773                                  /* l_Billable_Flag is coming from the pl/sql table
5774                                   * This can occur if another app changes project,task,billable_flag
5775                                   * in update phase of validation logic and billable no longer
5776                                   * matches what patc returns.
5777                                   */
5778 
5779                                   G_Stage := 'Get translated value for Billable_flag code using fnd_lookups.';
5780                                   l_Bill_Flag_Meaning := Null;
5781 
5782                                   G_Stage := 'Open cursor getBillFlagMeaning.';
5783                                   Open GetBillFlagMeaning(l_Proj_Attrib_Rec.Billable_Flag);
5784 
5785                                   G_Stage := 'Fetch data for cursor getBillFlagMeaning.';
5786                                   Fetch GetBillFlagMeaning into l_Bill_Flag_Meaning;
5787 
5788                                   G_Stage := 'Close cursor GetBillFlagMeaning.';
5789                                   Close GetBillFlagMeaning;
5790 
5791                                   G_Stage := 'Invalid external change of billable flag  - Inserting error rec.';
5792                                   G_Msg_Tokens_Table.Delete;
5793 
5794                                   G_Msg_Tokens_Table(1).Token_Name := 'BILL_FLAG';
5795                                   G_Msg_Tokens_Table(1).Token_Value := l_Bill_Flag_Meaning;
5796 
5797                                   -- Add record to error message table.
5798                                   Pa_Otc_Api.Add_Error_To_Table(
5799                                        P_Message_Table           => P_Message_Table,
5800                                        P_Message_Name            => 'BILL_FLAG_CHGE_INVALID',
5801                                        P_Message_Level           => 'ERROR',
5802                                        P_Message_Field           => 'BILLABLE_FLAG',
5803                                        P_Msg_Tokens              => G_Msg_Tokens_Table,
5804                                        P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5805                                        P_Time_Attribute_Id       => l_Proj_Attrib_Rec.Billable_Flag_Attr_Id);
5806 
5807                             End If; -- l_Proj_Attrib_Rec.Billable_Flag <> l_Proj_Attrib_Rec.Billable_Flag2
5808 
5809                        End If; -- l_Msg_Type = 'W'
5810                        -- end bug 4518893
5811 
5812 		     	  Else -- l_Status is Not Null
5813 
5814 				       /* Check if the billable flag was change externally either by other app
5815 				        * in OTL or by third party.
5816 				        */
5817 				       If l_Proj_Attrib_Rec.Billable_Flag <> l_Proj_Attrib_Rec.Billable_Flag2 Then
5818 
5819 					        /* l_Billable_Flag is coming from the pl/sql table
5820 					         * This can occur if another app changes project,task,billable_flag
5821 					         * in update phase of validation logic and billable no longer
5822 					         * matches what patc returns.
5823 					         */
5824 
5825 					        G_Stage := 'Get translated value for Billable_flag code using fnd_lookups.';
5826 					        l_Bill_Flag_Meaning := Null;
5827 
5828 					        G_Stage := 'Open cursor getBillFlagMeaning.';
5829 					        Open GetBillFlagMeaning(l_Proj_Attrib_Rec.Billable_Flag);
5830 
5831 				            G_Stage := 'Fetch data for cursor getBillFlagMeaning.';
5832 					        Fetch GetBillFlagMeaning into l_Bill_Flag_Meaning;
5833 
5834 					        G_Stage := 'Close cursor GetBillFlagMeaning.';
5835 					        Close GetBillFlagMeaning;
5836 
5837                             G_Stage := 'Invalid external change of billable flag  - Inserting error rec.';
5838 	                        G_Msg_Tokens_Table.Delete;
5839 
5840 					        G_Msg_Tokens_Table(1).Token_Name := 'BILL_FLAG';
5841 					        G_Msg_Tokens_Table(1).Token_Value := l_Bill_Flag_Meaning;
5842 
5843                             -- Add record to error message table.
5844                             Pa_Otc_Api.Add_Error_To_Table(
5845                                  P_Message_Table           => P_Message_Table,
5846                                  P_Message_Name            => 'BILL_FLAG_CHGE_INVALID',
5847                                  P_Message_Level           => 'ERROR',
5848                                  P_Message_Field           => 'BILLABLE_FLAG',
5849                                  P_Msg_Tokens              => G_Msg_Tokens_Table,
5850                                  P_Time_Building_Block_Id  => P_Building_Blocks(i).Time_Building_Block_Id,
5851                                  P_Time_Attribute_Id       => l_Proj_Attrib_Rec.Billable_Flag_Attr_Id);
5852 
5853 				       End If; -- l_Proj_Attrib_Rec.billable_flag <> l_Proj_Attrib_Rec.billable_flag2
5854 
5855                   End If; -- l_Status check
5856 				  End If; -- Bug 7645561
5857 
5858              End If; -- l_Adjusted_In_Projects = 'N' and l_BB_Detail_Changed = 'Y' and l_BB_Detail_Deleted = 'N'
5859 
5860              If P_Message_Table.Count = 0 and l_BB_Detail_Deleted = 'N' Then
5861 
5862 			      -- Add ei record to l_Timecard_Table
5863 			      G_Stage := 'Add ei record to l_Timecard_Table for use by extensions.';
5864 
5865 			      l_Timecard_Table_Index := l_Timecard_Table_Index + 1;
5866 			      l_Timecard_Table(l_Timecard_Table_Index).Project_Number := l_Proj_Attrib_Rec.Project_Number;
5867         	      l_Timecard_Table(l_Timecard_Table_Index).Project_Id     := l_Proj_Attrib_Rec.Project_id;
5868         	      l_Timecard_Table(l_Timecard_Table_Index).Task_Number    := l_Proj_Attrib_Rec.Task_Number;
5869         	      l_Timecard_Table(l_Timecard_Table_Index).Task_Id        := l_Proj_Attrib_Rec.Task_Id;
5870 			      l_Timecard_Table(l_Timecard_Table_Index).Expenditure_Type := l_Proj_Attrib_Rec.Expenditure_Type;
5871 			      l_Timecard_Table(l_Timecard_Table_Index).System_Linkage_Function := l_Proj_Attrib_Rec.Sys_Linkage_Func;
5872         	      l_Timecard_Table(l_Timecard_Table_Index).Quantity := l_Proj_Attrib_Rec.Quantity;
5873         	      l_Timecard_Table(l_Timecard_Table_Index).Incurred_By_Person_Id := l_Proj_Attrib_Rec.Inc_By_Person_Id;
5874         	      l_Timecard_Table(l_Timecard_Table_Index).Override_Approver_Person_Id := l_Ovr_Approver_Person_Id;
5875         	      l_Timecard_Table(l_Timecard_Table_Index).Expenditure_Item_Date := l_Proj_Attrib_Rec.Expenditure_Item_Date;
5876         	      l_Timecard_Table(l_Timecard_Table_Index).Expenditure_Ending_Date := l_Proj_Attrib_Rec.Exp_Ending_Date;
5877         	      l_Timecard_Table(l_Timecard_Table_Index).Attribute_Category := l_Proj_Attrib_Rec.Attrib_Category;
5878         	      l_Timecard_Table(l_Timecard_Table_Index).Attribute1 := l_Proj_Attrib_Rec.Attribute1;
5879         	      l_Timecard_Table(l_Timecard_Table_Index).Attribute2 := l_Proj_Attrib_Rec.Attribute2;
5880         	      l_Timecard_Table(l_Timecard_Table_Index).Attribute3 := l_Proj_Attrib_Rec.Attribute3;
5881         	      l_Timecard_Table(l_Timecard_Table_Index).Attribute4 := l_Proj_Attrib_Rec.Attribute4;
5882         	      l_Timecard_Table(l_Timecard_Table_Index).Attribute5 := l_Proj_Attrib_Rec.Attribute5;
5883         	      l_Timecard_Table(l_Timecard_Table_Index).Attribute6 := l_Proj_Attrib_Rec.Attribute6;
5884         	      l_Timecard_Table(l_Timecard_Table_Index).Attribute7 := l_Proj_Attrib_Rec.Attribute7;
5885         	      l_Timecard_Table(l_Timecard_Table_Index).Attribute8 := l_Proj_Attrib_Rec.Attribute8;
5886         	      l_Timecard_Table(l_Timecard_Table_Index).Attribute9 := l_Proj_Attrib_Rec.Attribute9;
5887         	      l_Timecard_Table(l_Timecard_Table_Index).Attribute10 := l_Proj_Attrib_Rec.Attribute10;
5888         	      l_Timecard_Table(l_Timecard_Table_Index).Billable_Flag := l_Proj_Attrib_Rec.Billable_Flag;
5889         	      l_Timecard_Table(l_Timecard_Table_Index).Expenditure_Item_Comment := l_Proj_Attrib_Rec.Expenditure_Item_Comment;
5890 			      l_Timecard_Table(l_Timecard_Table_Index).Approval_Status := l_Approval_Status;
5891                   /* Begin bug 5087510 PA.M CWK changes. */
5892                   l_Timecard_Table(l_Timecard_Table_Index).Po_Line_Id := l_Proj_Attrib_Rec.Po_Line_Id;
5893                   l_Timecard_Table(l_Timecard_Table_Index).PO_Price_Type := l_Proj_Attrib_Rec.PO_Price_Type;
5894                   l_Timecard_Table(l_Timecard_Table_Index).Person_Type := l_Proj_Attrib_Rec.Person_Type;
5895                   l_Timecard_Table(l_Timecard_Table_Index).Po_Header_Id := l_Proj_Attrib_Rec.Po_Header_Id;
5896                   /* End bug 5087510 */
5897                   /* Bug 4022269 added action column to allowed summary validation extension to
5898                    * be able to determine if OTL timecard is being saved or submitted.
5899                    */
5900                   l_Timecard_Table(l_Timecard_Table_Index).Action := P_Operation; -- Validate values: SAVE or SUBMIT
5901 
5902                   -- Bug 10253400.. 12.2 payroll intg .. start
5903                   l_Timecard_Table(l_Timecard_Table_Index).Job_Id := l_Proj_Attrib_Rec.Job_Id;
5904                   l_Timecard_Table(l_Timecard_Table_Index).Location_Id := l_Proj_Attrib_Rec.Location_Id;
5905                   l_Timecard_Table(l_Timecard_Table_Index).Pay_Element_Type_Id := l_Proj_Attrib_Rec.Pay_Element_Type_Id;
5906                   -- Bug 10253400.. 12.2 payroll intg .. end
5907                   l_Timecard_Table(l_Timecard_Table_Index).Cbs_Element_Id := l_Proj_Attrib_Rec.Cbs_Element_Id; -- Added for CBS Enhancement Bug 16220146
5908 
5909 			      -- Though this is not needed it helps to clarify that a reset these local
5910 			      -- variables is assumed at this point.
5911 			      --
5912 			      G_Stage := 'Reset variable used for table insert';
5913 			      l_Proj_Attrib_Rec := Null;
5914 
5915 		     End If; -- P_Message_Table.Count = 0
5916 
5917 	    End If; -- Detail Scope Building Block
5918 
5919 	    G_Stage := 'Check to exit loop.';
5920 	    Exit When i = P_Building_Blocks.Last;
5921 
5922    End Loop; -- Processing Building Blocks Loop
5923 
5924    G_Stage := 'Done with Processing Building Blocks loop.';
5925    If P_Message_Table.Count = 0 and l_Timecard_Table.COUNT > 0 Then
5926 
5927         /* Not need to null out l_msg_name and l_exp_status but doing so for clarity. */
5928 		l_Msg_Name := Null;
5929 
5930 		G_Stage := 'Calling Summary-validation Extension';
5931  		-- Summary level Validation Call
5932         Pagtcx.Summary_Validation_Extension(
5933              P_Timecard_Table        => l_Timecard_Table,
5934              P_Module                => 'OTL',
5935              X_Expenditure_Id        => Null,
5936              X_Incurred_By_Person_Id => l_Timecard_Table(1).Incurred_By_Person_Id,
5937              X_Expenditure_End_Date  => Null,
5938              X_Exp_Class_Code        => 'PT',
5939              X_Status                => l_Exp_Status,
5940              X_Comment               => l_Msg_Name);
5941 
5942 		If l_Exp_Status = 'REJECTED' Then
5943 
5944 			-- Add record to error message table
5945 			G_Stage := 'Calling Summary-validation Extension - Insert Error Rec.';
5946             G_Msg_Tokens_Table.Delete;
5947 
5948             Pa_Otc_Api.Add_Error_To_Table(
5949                  P_Message_Table           => P_Message_Table,
5950                  P_Message_Name            => l_Msg_Name,
5951                  P_Message_Level           => 'ERROR',
5952                  P_Message_Field           => Null,
5953                  P_Msg_Tokens              => G_Msg_Tokens_Table,
5954                  P_Time_Building_Block_Id  => NULL, --Bug5215484  l_Time_Building_Block_Id,
5955                  P_Time_Attribute_Id       => Null);
5956 
5957 		End If;
5958 
5959 		If Nvl(Fnd_Profile.Value('PA_SST_ENABLE_BUS_MSG'),'N') = 'Y' Then
5960 
5961 	       	 -- Business Message Call
5962 			 G_Stage := 'Calling Business Message API';
5963              Pa_Time_Client_Extn.Display_Business_Message(
5964                   P_Timecard_Table       => l_Timecard_Table,
5965 		          P_Module               => 'OTL',
5966                   P_Person_id            => l_Timecard_Table(1).Incurred_By_Person_Id,
5967                   P_Week_Ending_Date     => Null,
5968                   X_Msg_Application_Name => l_Msg_Application,
5969                   X_Message_Data         => l_Msg_Name,
5970                   X_Msg_Token1_Name      => l_Msg_Token1_Name,
5971                   X_Msg_Token1_Value     => l_Msg_Token1_Value ,
5972                   X_Msg_Token2_Name      => l_Msg_Token2_Name,
5973                   X_Msg_Token2_Value     => l_Msg_token2_Value,
5974                   X_Msg_Token3_Name      => l_Msg_Token3_Name,
5975                   X_Msg_Token3_Value     => l_Msg_Token3_Value);
5976 
5977 			 If l_Msg_Name is Not Null Then
5978 
5979                   -- Add record to error message table
5980                   G_Stage := 'Calling Business Message API - Insert Business Rec Msg.';
5981 		          G_Msg_Tokens_Table.Delete;
5982 
5983 				  If l_Msg_Token1_Name is Not Null Then
5984 
5985 				       G_Msg_Tokens_Table(1).Token_Name := l_Msg_Token1_Name;
5986 					   G_Msg_Tokens_Table(1).Token_Value := l_Msg_Token1_Value;
5987 
5988 				  End If;
5989 
5990                   If l_Msg_Token2_Name is Not Null Then
5991 
5992                        G_Msg_Tokens_Table(2).Token_Name := l_Msg_Token2_Name;
5993                        G_Msg_Tokens_Table(2).Token_Value := l_Msg_Token2_Value;
5994 
5995                   End If;
5996 
5997                   If l_Msg_Token3_Name is Not Null Then
5998 
5999                        G_Msg_Tokens_Table(3).Token_Name := l_Msg_Token3_Name;
6000                        G_Msg_Tokens_Table(3).Token_Value := l_Msg_Token3_Value;
6001 
6002                   End If;
6003 
6004 				  If l_Msg_Application is Null Then
6005 
6006 				       l_Msg_Application := 'PA';
6007 
6008 				  End If;
6009 
6010                   Pa_Otc_Api.Add_Error_To_Table(
6011                        P_Message_Table           => P_Message_Table,
6012                        P_Message_Name            => l_Msg_Name,
6013                        P_Message_Level           => 'BUSINESS',
6014                        P_Message_Field           => Null,
6015                        P_Msg_Tokens              => G_Msg_Tokens_Table,
6016                        P_Time_Building_Block_Id  => NULL, --Bug5215484  l_Time_Building_Block_Id,
6017                        P_Time_Attribute_Id       => Null,
6018 				       P_Message_App             => l_Msg_Application);
6019 
6020 			 End If; -- l_Msg_Name is Not Null
6021 
6022 		End If; -- Profile 'PA_SST_ENABLE_BUS_MSG' = 'Y'
6023 
6024 		G_Stage := 'Last point of looping thru all the weeks.';
6025 
6026     End If; -- P_Message_Table.Count = 0 and l_Timecard_Table.Count > 0
6027 
6028     G_Stage := 'Leaving procedure Validate_Process().';
6029     Pa_Otc_Api.TrackPath('STRIP','Validate_Process');
6030 
6031   Exception
6032 	When E_Unhandled_Exception Then
6033 		Raise_Application_Error(-20021,SqlErrm(to_number(l_Status)));
6034 
6035 	When E_Dff_Exception Then
6036 		G_Stage := G_Stage || ' => ' || l_Error_Stage;
6037 		Raise_Application_Error(-20021,l_Error_Message);
6038 
6039         When Others Then
6040                 Raise;
6041 
6042   End Validate_Process;
6043 
6044 
6045 -- =======================================================================
6046 -- Start of Comments
6047 -- API Name      : Validate_Project_Exists
6048 -- Type          : Private
6049 -- Pre-Reqs      : None
6050 -- Type          : Procedure
6051 -- Function      : This procedure accepts the Project_Id
6052 --                 as IN parameter and ckecks if this project exists in
6053 --                 Oracle Projects.  This procedure does not perform any
6054 --                 extensive project related validations.  If the project
6055 --                 exists in Oracle Projects, X_project_Number will be populated
6056 --                 with segment1, else X_project_number will be null.
6057 -- Parameters    :
6058 -- IN
6059 --           P_Project_Id - Pa_Projects_All.Project_Id%TYPE
6060 -- OUT
6061 --           X_Error_Code - Varchar2
6062 --           X_Error_Type - Varchar2
6063 --           X_Project_Id - Pa_Projects_All.Segment1%TYPE
6064 
6065 /*-------------------------------------------------------------------------*/
6066 
6067   Procedure Validate_Project_Exists(
6068 			P_Project_Id     IN         Pa_Projects_All.Project_Id%TYPE,
6069                         X_Error_Code     OUT NOCOPY Varchar2,
6070                         X_Error_Type     OUT NOCOPY Varchar2,
6071 			X_Project_Number OUT NOCOPY Pa_Projects_All.Segment1%TYPE)
6072   Is
6073 
6074     /* begin bug 4766396
6075 	Cursor GetProjInfo(P_Proj_Id IN Pa_Projects_All.Project_Id%TYPE) Is
6076 	Select
6077                 Project_Number
6078 	From
6079                 Pa_Online_Projects_V
6080 	Where
6081                 Project_Id = P_Proj_Id; */
6082 
6083     Cursor GetProjInfo(P_Proj_Id IN Pa_Projects_All.Project_Id%TYPE) IS
6084     select
6085           p.segment1
6086     from  Pa_Online_Projects_V pp,
6087           pa_projects_all p
6088     where pp.Project_Id = P_Proj_Id
6089     and   pp.project_id = p.project_id;
6090     /* end bug 4766396 */
6091 
6092 	l_Proj_Num     Pa_Projects_All.Segment1%TYPE := Null;
6093 
6094   Begin
6095 
6096 	G_Stage := 'Entering procedure Validate_Project_Exists().';
6097 	Pa_Otc_Api.TrackPath('ADD','Validate_Project_Exists');
6098 
6099    	If P_Project_Id is Not Null Then
6100 
6101 		G_Stage := 'Open cursor GetProjInfo.';
6102 		Open GetProjInfo(P_Project_Id);
6103 
6104 		G_Stage := 'Fetch Project info from cursor.';
6105 		Fetch GetProjInfo Into l_Proj_Num;
6106 
6107 		G_Stage := 'Close cursor GetProjInfo.';
6108 		Close GetProjInfo;
6109 
6110       		If l_Proj_Num is Null Then
6111 
6112 			G_Stage := 'No project number was returned - Invalid project.';
6113 
6114          		-- This implies that this project is no longer valid to use. This
6115 			-- can be due to many different reasons.
6116 			-- Providing the specific reason why the project can no longer be
6117 			-- used is impractical, so a generic message is sent back to the user.
6118 
6119          		X_Error_Type := 'E';
6120          		X_Error_Code := 'INVALID_PROJECT';
6121 
6122 		ELSE
6123 
6124 			X_Project_Number := l_Proj_Num;
6125 
6126       		End If; -- End l_Proj_Num is null
6127 
6128    	Else  -- Project id is null
6129 
6130 		G_Stage := 'The Project Id parameter are Null - Invalid parameter values.';
6131 
6132       		-- Both project id and project number are null,
6133       		-- this should not occur under normal situations.
6134       		-- if this occurs then populate error_type with 'E'
6135       		-- (normal Error).
6136 
6137       		X_Error_Type :=  'E';
6138       		X_Error_Code := 'PA_PROJ_PARAM_IS_NULL';
6139 
6140    	End If; -- End Project Id is not null
6141 
6142 	G_Stage := 'Leaving procedure Validate_Project_Exists().';
6143 	Pa_Otc_Api.TrackPath('STRIP','Validate_Project_Exists');
6144 
6145    EXCEPTION
6146 	When Others Then
6147    		Raise;
6148 
6149    End Validate_Project_Exists;
6150 
6151 
6152 -- =======================================================================
6153 -- Start of Comments
6154 -- API Name      : Validate_Task_Exists
6155 -- Type          : Private
6156 -- Pre-Reqs      : None
6157 -- Type          : Procedure
6158 -- Function      : This procedure accepts the Project_Id, Task_Number
6159 --                 IN parameters and ckecks if this task exists in
6160 --                 pa_online_task_v.  This procedure does not perform any
6161 --                 extensive task related validations.  If the task
6162 --                 exists in the online view, X_task_Id will be populated
6163 --                 with task_id, else X_task_id will be null.
6164 -- Parameters    :
6165 -- IN
6166 --           P_Task_Id     - Pa_Tasks.Task_Id%TYPE
6167 --           P_Project_Id  - Pa_Projects.Project_Id%TYPE
6168 -- OUT
6169 --           X_Error_Code  - Varchar2
6170 --           X_Error_Type  - Varchar2
6171 --           X_Task_Number - Pa_Tasks.Task_Number%TYPE
6172 /*-------------------------------------------------------------------------*/
6173 
6174    Procedure Validate_Task_Exists(
6175                         P_Task_Id     IN         Pa_Tasks.Task_Id%TYPE,
6176 			P_Project_Id  IN         Pa_Projects.Project_Id%TYPE,
6177                         X_Error_Code  OUT NOCOPY Varchar2,
6178                         X_Error_Type  OUT NOCOPY Varchar2,
6179 			X_Task_Number OUT NOCOPY Pa_Tasks.Task_Number%TYPE)
6180    Is
6181 
6182 	l_Task_Num  Pa_Tasks.Task_Number%TYPE := Null;
6183 	l_Task_Name Pa_Tasks.Task_Name%TYPE := Null;
6184 
6185     /* begin bug 4766396
6186 	Cursor Validate_ProjTask_Combo(P_Prj_Id IN Number,
6187 				       P_Tsk_Id IN Number) Is
6188 	Select
6189               Task_Number
6190 	From
6191               Pa_Online_Tasks_V
6192 	Where
6193               Task_Id    = P_Tsk_Id
6194 	And       Project_Id = P_Prj_Id; */
6195 
6196     cursor Validate_ProjTask_Combo(P_Prj_Id IN NUMBER,
6197                                    P_Tsk_Id IN NUMBER) is
6198     select
6199           t.task_number
6200     from  pa_online_tasks_v tt,
6201           pa_tasks t
6202     where
6203           tt.task_id    = P_Tsk_Id
6204     and   tt.project_id = P_Prj_Id
6205     and   t.task_id     = tt.task_id;
6206     /* end bug 4766396 */
6207 
6208    Begin
6209 
6210    	-- Validate project_id parameter
6211 
6212 	G_Stage := 'Entering procedure Validate_Task_Exists().';
6213 	Pa_Otc_Api.TrackPath('ADD','Validate_Task_Exists');
6214 
6215       	If P_Task_Id is Not Null Then
6216 
6217 		G_Stage := 'Parameter P_Task_Id is not Null, get Task Info.';
6218 		Pa_Utils.GetTaskInfo (
6219                         X_Task_Id   => P_Task_Id,
6220                         X_Task_Num  => l_Task_Num,
6221                         X_Task_Name => l_Task_Name);
6222 
6223        		-- Check if retrieved task number for the task id.
6224 		-- If it didn't then the task id is invalid,
6225 		-- return normal error.
6226 
6227          	If l_Task_Num is Null Then
6228 
6229 			G_Stage := 'The returned Task Number is Null so error out.';
6230             		X_Error_Type := 'E';
6231             		X_Error_Code := 'INVALID_TASK';
6232 
6233 		Else -- Check the project/task combo being valid
6234 
6235 			G_Stage := 'Open cursor Validate_ProjTask_Combo.';
6236 			Open Validate_ProjTask_Combo(P_Project_Id,P_Task_Id);
6237 
6238 			G_Stage := 'Fetch data from cursor Validate_ProjTask_Combo.';
6239 			Fetch Validate_ProjTask_Combo into l_Task_Num;
6240 
6241 			G_Stage := 'Close cursor Validate_ProjTask_Combo.';
6242 			Close Validate_ProjTask_Combo;
6243 
6244 			If l_Task_Num is Null Then
6245 
6246 				G_Stage := 'Invalid Project/Task combination.  Populate error code.';
6247 				X_Error_Type := 'E';
6248 				X_Error_Code := 'PA_INVALID_PROJ_TASK_COMB';
6249 
6250 			Else
6251 
6252 				G_Stage := 'The Project/Task combination is valid.';
6253 
6254 				X_Task_Number := l_Task_Num;
6255 
6256 			End If;
6257 
6258          	End If; -- end l_Task_Number is null
6259 
6260       	Else -- Task Id is Null
6261 
6262 		G_Stage := 'The parameter P_Task_Id is Null so error out.';
6263          	X_Error_Type := 'E';
6264          	X_Error_Code := 'INVALID_TASK';
6265 
6266       	End If; -- End P_Task_Id is not null
6267 
6268 	G_Stage := 'Leaving procedure Validate_Task_Exists().';
6269 	Pa_Otc_Api.TrackPath('STRIP','Validate_Task_Exists');
6270 
6271    Exception
6272 	When Others Then
6273    	   Raise;
6274 
6275    End Validate_Task_Exists;
6276 
6277 
6278 -- ==========================================================================
6279 -- Start of Comments
6280 -- API Name      : Validate_Exp_Type_Exists
6281 -- Type          : Private
6282 -- Pre-Reqs      : None
6283 -- Type          : Procedure
6284 -- Function      : This procedure checks if the system linkage/expenditure type
6285 --                 combination exists in the database for the given date.
6286 -- Parameters    :
6287 -- IN
6288 --           P_System_Linkage   - Pa_System_Linkages.Function%TYPE
6289 --           P_Expenditure_Type - Pa_Expenditure_Types.Expenditure_Type%TYPE
6290 --           P_Exp_Item_date    - Pa_Expenditure_Items_All.Expenditure_Item_Date%TYPE
6291 -- OUT
6292 --           X_Error_Code       - Varchar2
6293 --           X_Error_Type       - Varchar2
6294 
6295 /*--------------------------------------------------------------------------*/
6296 
6297    Procedure Validate_Exp_Type_Exists(
6298                P_System_Linkage   IN         Pa_System_Linkages.Function%TYPE,
6299                P_Expenditure_Type IN         Pa_Expenditure_Types.Expenditure_Type%TYPE,
6300 	       P_Exp_Item_Date    IN         Pa_Expenditure_Items_All.Expenditure_Item_Date%TYPE,
6301                X_Error_Type       OUT NOCOPY Varchar2,
6302                X_Error_Code       OUT NOCOPY Varchar2) Is
6303 
6304       Cursor Cur_Etype_Slink (P_EI_Date IN Date,
6305 			      P_Sys_Link_Func IN Varchar2,
6306 			      P_Exp_Type IN Varchar2) Is
6307       Select
6308              System_Linkage_Function,
6309              Expenditure_Type
6310       From
6311              Pa_Online_Expenditure_Types_V
6312       Where
6313              System_Linkage_Function = P_Sys_Link_Func
6314       And    Expenditure_Type        = P_Exp_Type
6315       And    P_Exp_Item_Date Between Sys_Link_Start_Date_Active
6316 				                 And Nvl(Sys_Link_End_Date_Active,P_EI_Date)
6317       And    P_Exp_Item_Date Between Expnd_Typ_Start_Date_Active
6318 				                 And Nvl(Expnd_Typ_End_Date_Active,P_EI_Date)
6319       And    system_linkage_function in ('ST','OT'); -- bug 5020394
6320 
6321       Rec_Ets Cur_Etype_Slink%RowType;
6322 
6323    Begin
6324 
6325 	G_Stage := 'Entering procedure Validate_Exp_Type_Exists().';
6326 	Pa_Otc_Api.TrackPath('ADD','Validate_Exp_Type_Exists');
6327 
6328 	G_Stage := 'Open cursor Fetch AdjustmentAllowed.';
6329    	Open Cur_Etype_Slink(P_Exp_Item_Date,P_System_Linkage,P_Expenditure_Type);
6330 
6331 	G_Stage := 'Fetch from cursor Cur_Etype_Slink.';
6332    	Fetch Cur_Etype_Slink Into Rec_Ets;
6333 
6334 	G_Stage := 'Close cursor Cur_Etype_Slink.';
6335    	Close Cur_Etype_Slink;
6336 
6337 	G_Stage := 'Check if exp type sys link func conditions passed muster.';
6338    	If Rec_Ets.Expenditure_Type is Null Then
6339 
6340 		G_Stage := 'Expenditure Type is null so error out.';
6341       		X_Error_Type := 'E';
6342       		X_Error_Code := 'INVALID_ETYPE_SYSLINK';
6343 
6344    	End If;
6345 
6346 	G_Stage := 'Leaving procedure Validate_Exp_Type_Exists().';
6347 	Pa_Otc_Api.TrackPath('STRIP','Validate_Exp_Type_Exists');
6348 
6349    Exception
6350 	When Others Then
6351    		Raise;
6352 
6353    End Validate_Exp_Type_Exists;
6354 
6355 
6356 -- ===========================================================================
6357 -- API Name      : Validate_overriding_approver
6358 -- Type          : Private
6359 -- Pre-Reqs      : None
6360 -- Type          : Procedure
6361 -- Function      : This function validates the overriding approver entered
6362 --                 in timecard header screen.  If the approver_id is passed
6363 --                 then it is implied that the overriding approver is picked
6364 --                 from the LOV provided in enter timecard header screen, in
6365 --                 this case it is not necessary to validate the overriding
6366 --                 approver bcoz the LOV displays only valid approvers.
6367 --                 However if the overriding approver_id is null and
6368 --                 overriding approver_name is provided, then the approver
6369 --                 name is validated against pa_exp_ovrrde_approver_v view.
6370 --
6371 -- Parameters    :
6372 --  IN
6373 --           P_Approver_Id - Per_People_F.Person_Id%TYPE
6374 --
6375 --  OUT
6376 --           X_Approver_Id - Per_People_F.Person_Id%TYPE
6377 --           X_Error_Type  - Varchar2
6378 --           X_Error_Code  - Varchar2
6379 /* ------------------------------------------------------------------------*/
6380 
6381    Procedure Validate_Overriding_Approver(
6382 		    P_Approver_Id IN         Per_People_F.Person_Id%TYPE,
6383                     X_Approver_Id OUT NOCOPY Per_People_F.Person_Id%TYPE,
6384                     X_Error_Type  OUT NOCOPY Varchar2,
6385                     X_Error_Code  OUT NOCOPY Varchar2) Is
6386 
6387    Begin
6388 
6389 	G_Stage := 'Entering procedure Validate_Overriding_Approver().';
6390 	Pa_Otc_Api.TrackPath('ADD','Validate_Overriding_Approver');
6391 
6392 	G_Stage := 'Check if Approver Id populated or not.';
6393    	If P_Approver_Id is Not Null Then
6394 
6395       		/*
6396        		 * Performance related change:
6397        		 * distinct clause added in this query so that the view Pa_Exp_Ovrrde_Approver_V
6398        		 * gets merged.
6399        		 */
6400 		G_Stage := 'Get Overriding Approver Id.';
6401       		Select
6402                         Distinct
6403 			Person_Id
6404       		Into
6405 			X_Approver_Id
6406       		From
6407 			Pa_Exp_Ovrrde_Approver_V
6408       		Where
6409 			Person_Id = P_Approver_Id;
6410 
6411 	Else -- P_Approver_Id is Null.
6412 
6413 		Raise No_Data_Found;
6414 
6415    	End If; -- End Approver_Id is not null
6416 
6417 	G_Stage := 'Leaving procedure Validate_Overriding_Approver().';
6418 	Pa_Otc_Api.TrackPath('STRIP','Validate_Overriding_Approver');
6419 
6420    Exception
6421 	When No_Data_Found Then
6422    		X_Error_Type := 'E';
6423    		X_Error_Code := 'PA_OVRRDE_APPROVER_NOT_VALID';
6424 
6425 	When Too_Many_Rows Then
6426    		X_Error_Type := 'E';
6427    		X_Error_Code := 'PA_TOO_MANY_OVRRD_APPROVER';
6428 
6429 	When Others Then
6430    		Raise;
6431 
6432    End Validate_Overriding_Approver;
6433 
6434 -- =======================================================================
6435 -- Start of Comments
6436 -- API Name      : Validate_Work_Type_Exists
6437 -- Type          : Private
6438 -- Pre-Reqs      : None
6439 -- Type          : Procedure
6440 -- Function      : This procedure accepts the Work_Type_Id
6441 --                 as IN parameter and ckecks if the work type exists in
6442 --                 Oracle Projects.  This procedure does not perform any
6443 --                 extensive project related validations.  If the work type
6444 --                 exists in Oracle Projects, X_Error_Code will be null.
6445 -- Parameters    :
6446 -- IN
6447 --           P_Work_Type_Id - Pa_Projects_All.work_Type_Id%TYPE
6448 -- OUT
6449 --           X_Error_Code - Varchar2
6450 --           X_Error_Type - Varchar2
6451 
6452 /*-------------------------------------------------------------------------*/
6453 
6454   Procedure Validate_Work_Type_Exists(
6455                         P_Work_Type_Id   IN  PA_Work_Types_B.Work_Type_Id%TYPE,
6456                         P_Exp_Item_Date  IN  Pa_Expenditure_Items_All.Expenditure_Item_Date%TYPE,
6457                         X_Error_Code     OUT NOCOPY Varchar2,
6458                         X_Error_Type     OUT NOCOPY Varchar2)
6459   Is
6460 
6461 
6462     Cursor GetWorkTypeInfo(P_Work_Type_Id IN PA_Work_Types_B.Work_Type_Id%TYPE) IS
6463     select
6464           name
6465     from  pa_work_types_v w
6466     where w.work_type_Id = P_Work_Type_Id
6467       and p_Exp_Item_Date between start_date_active and nvl(end_date_active, p_exp_item_date);
6468 
6469     /* end bug 4766396 */
6470 
6471 	l_work_type_name     Pa_Work_Types_TL.name%TYPE := Null;
6472 
6473   Begin
6474 
6475 	G_Stage := 'Entering procedure Validate_Work_Type_Exists().';
6476 	Pa_Otc_Api.TrackPath('ADD','Validate_Work_Type_Exists');
6477 
6478    	If P_Work_Type_Id is Not Null Then
6479 
6480 		G_Stage := 'Open cursor GetWorkTypeInfo.';
6481 		Open GetWorkTypeInfo(p_work_type_id);
6482 
6483 		G_Stage := 'Fetch Project info from cursor.';
6484 		Fetch GetWorkTypeInfo Into l_Work_Type_Name;
6485 
6486 		G_Stage := 'Close cursor GetWorkTypeInfo.';
6487 		Close GetWorkTypeInfo;
6488 
6489       	If l_Work_Type_Name is Null Then
6490 
6491 			G_Stage := 'No work type was returned - Invalid Work Type';
6492 
6493             -- This implies that this project is no longer valid to use. This
6494 			-- can be due to many different reasons.
6495 			-- Providing the specific reason why the project can no longer be
6496 			-- used is impractical, so a generic message is sent back to the user.
6497 
6498          		X_Error_Type := 'E';
6499          		X_Error_Code := 'INVALID_WORK_TYPE';
6500 
6501       	End If; -- End l_work_Type_Name is null
6502 
6503    	End If; -- End Work Type Id is not null
6504 
6505 	G_Stage := 'Leaving procedure Validate_Work_Type_Exists().';
6506 	Pa_Otc_Api.TrackPath('STRIP','Validate_Work_Type_Exists');
6507 
6508    EXCEPTION
6509 	When Others Then
6510    		Raise;
6511 
6512    End Validate_Work_Type_Exists;
6513 
6514 -- =======================================================================
6515 -- Start of Comments
6516 -- API Name      : Validate_Job_Exists
6517 -- Type          : Private
6518 -- Pre-Reqs      : None
6519 -- Type          : Procedure
6520 -- Function      : This procedure accepts the Job_Id
6521 --                 as IN parameter and ckecks if the job exists.
6522 --                 This procedure does not perform any extensive validations.
6523 --                 If the job exists, X_Error_Code will be null.
6524 -- Parameters    :
6525 -- IN
6526 --           P_Job_Id - Pa_Expenditure_items_All.Job_Id%TYPE
6527 -- OUT
6528 --           X_Error_Code - Varchar2
6529 --           X_Error_Type - Varchar2
6530 
6531 /*-------------------------------------------------------------------------*/
6532 
6533   Procedure Validate_Job_Exists(
6534                         P_Job_Id         IN  Pa_Expenditure_items_All.Job_Id%TYPE,
6535                         P_Exp_Item_Date  IN  Pa_Expenditure_Items_All.Expenditure_Item_Date%TYPE,
6536                         X_Error_Code     OUT NOCOPY Varchar2,
6537                         X_Error_Type     OUT NOCOPY Varchar2)
6538   Is
6539 
6540 
6541     Cursor GetJobInfo(P_Job_Id IN Pa_Expenditure_items_All.Job_Id%TYPE) IS
6542     select
6543           name
6544     from  per_jobs_v w
6545     where w.job_Id = P_job_Id
6546       and p_Exp_Item_Date between date_from and nvl(date_to, p_exp_item_date)
6547       and ((PA_CROSS_BUSINESS_GRP.IsCrossBGProfile = 'N' AND
6548           fnd_profile.value('PER_BUSINESS_GROUP_ID') = W.BUSINESS_GROUP_ID)
6549           OR
6550           PA_CROSS_BUSINESS_GRP.IsCrossBGProfile = 'Y');
6551 
6552     /* end bug 4766396 */
6553 
6554 	l_job_name     per_jobs_tl.name%TYPE := Null;
6555 
6556   Begin
6557 
6558 	G_Stage := 'Entering procedure Validate_Job_Exists().';
6559 	Pa_Otc_Api.TrackPath('ADD','Validate_Job_Exists');
6560 
6561    	If P_Job_Id is Not Null Then
6562 
6563 		G_Stage := 'Open cursor GetJobInfo.';
6564 		Open GetJobInfo(P_Job_Id);
6565 
6566 		G_Stage := 'Fetch Project info from cursor.';
6567 		Fetch GetJobInfo Into l_Job_Name;
6568 
6569 		G_Stage := 'Close cursor GetJobInfo.';
6570 		Close GetJobInfo;
6571 
6572       	If l_Job_Name is Null Then
6573 
6574 			G_Stage := 'No work type was returned - Invalid Work Type';
6575 
6576             -- This implies that this project is no longer valid to use. This
6577 			-- can be due to many different reasons.
6578 			-- Providing the specific reason why the project can no longer be
6579 			-- used is impractical, so a generic message is sent back to the user.
6580 
6581          		X_Error_Type := 'E';
6582          		X_Error_Code := 'INVALID_JOB';
6583 
6584       	End If; -- End l_JOB is null
6585 
6586    	End If; -- End Job ID is not null
6587 
6588 	G_Stage := 'Leaving procedure Validate_Job_Exists().';
6589 	Pa_Otc_Api.TrackPath('STRIP','Validate_Job_Exists');
6590 
6591    EXCEPTION
6592 	When Others Then
6593    		Raise;
6594 
6595    End Validate_Job_Exists;
6596 
6597 -- =======================================================================
6598 -- Start of Comments
6599 -- API Name      : Validate_Location_Exists
6600 -- Type          : Private
6601 -- Pre-Reqs      : None
6602 -- Type          : Procedure
6603 -- Function      : This procedure accepts the Work_Type_Id
6604 --                 as IN parameter and ckecks if the work type exists in
6605 --                 Oracle Projects.  This procedure does not perform any
6606 --                 extensive project related validations.  If the work type
6607 --                 exists in Oracle Projects, X_Error_Code will be null.
6608 -- Parameters    :
6609 -- IN
6610 --           P_Location_ID - Pa_Expenditure_Items_All.Location_ID%TYPE
6611 -- OUT
6612 --           X_Error_Code - Varchar2
6613 --           X_Error_Type - Varchar2
6614 
6615 /*-------------------------------------------------------------------------*/
6616 
6617   Procedure Validate_Location_Exists(
6618                         p_location_id    IN  PA_Expenditure_Items_all.Location_ID%TYPE,
6619                         P_Exp_Item_Date  IN  Pa_Expenditure_Items_All.Expenditure_Item_Date%TYPE,
6620                         X_Error_Code     OUT NOCOPY Varchar2,
6621                         X_Error_Type     OUT NOCOPY Varchar2)
6622   Is
6623 
6624 
6625     Cursor GetLocationInfo(P_Location_Id IN Pa_Expenditure_Items_All.Location_Id%TYPE) IS
6626     select l.location_code
6627       from hr_locations l
6628      where location_id = P_Location_Id
6629        and p_exp_item_date <= nvl(l.inactive_date, p_exp_item_date)
6630        and l.location_use = 'HR';
6631 
6632   l_location_code     hr_locations.location_code%TYPE := Null;
6633 
6634   Begin
6635 
6636 	G_Stage := 'Entering procedure Validate_Location_Exists().';
6637 	Pa_Otc_Api.TrackPath('ADD','Validate_Location_Exists');
6638 
6639    	If p_location_id is Not Null Then
6640 
6641 		G_Stage := 'Open cursor GetLocationInfo.';
6642 		Open GetLocationInfo(p_location_id);
6643 
6644 		G_Stage := 'Fetch Project info from cursor.';
6645 		Fetch GetLocationInfo Into l_location_code;
6646 
6647 		G_Stage := 'Close cursor GetLocationInfo.';
6648 		Close GetLocationInfo;
6649 
6650       	If l_location_code is Null Then
6651 
6652 			G_Stage := 'No work type was returned - Invalid Location';
6653 
6654          		X_Error_Type := 'E';
6655          		X_Error_Code := 'INVALID_LOCATION';
6656 
6657       	End If; -- End p_location_id is null
6658 
6659    	End If; -- End p_location_id is not null
6660 
6661 	G_Stage := 'Leaving procedure Validate_Location_Exists().';
6662 	Pa_Otc_Api.TrackPath('STRIP','Validate_Location_Exists');
6663 
6664    EXCEPTION
6665 	When Others Then
6666    		Raise;
6667 
6668    End Validate_Location_Exists;
6669 
6670 
6671 -- =======================================================================
6672 -- Start of Comments
6673 -- API Name      : DetermineProcessingFlags
6674 -- Type          : Private
6675 -- Pre-Reqs      : None
6676 -- Type          : Procedure
6677 -- Return        : n/a
6678 -- Function      : This procedure deteremines the three flags necessary for processing
6679 --                 of the data further along in the main processing routine
6680 --                 Update_Validate_Timecard() which class this procedure at the for each
6681 --                 DETAIL record being looped thru.
6682 --
6683 -- Parameters    :
6684 -- IN
6685 --		P_BB_Id                - Hxc_Time_Building_Blocks.Time_Building_Block_Id%TYPE
6686 --      P_BB_Ovn	           - Hxc_Time_Building_Blocks.Object_Version_Number%TYPE
6687 --      P_BB_Date_To           - Hxc_Time_Building_Blocks.Date_To%TYPE
6688 --      P_BB_Changed           - VARCHAR2
6689 --      P_BB_New               - VARCHAR2
6690 --      P_Proj_Attribute_Rec   - Pa_Otc_Api.Project_Attribution_Rec
6691 --      P_Mode                 - VARCHAR2(10)
6692 --      P_Process_Flag         - Varchar2(30)
6693 -- OUT
6694 --		X_BB_Detail_Changed    - VARCHAR2(1)
6695 --		X_Data_Conflict_Flag   - VARCHAR2(1)
6696 --      X_BB_Detail_Deleted    - VARCHAR2(1)
6697 --      X_Adj_in_Projects_Flag - VARCHAR2(1)
6698 --
6699 
6700 /*--------------------------------------------------------------------------*/
6701 
6702    Procedure DetermineProcessingFlags (
6703 		P_BB_Id                IN         Hxc_Time_Building_Blocks.Time_Building_Block_Id%TYPE,
6704 		P_BB_Ovn               IN         Hxc_Time_Building_Blocks.Object_Version_Number%TYPE,
6705 		P_BB_Date_To           IN         Hxc_Time_Building_Blocks.Date_To%TYPE,
6706 		P_BB_Changed           IN         Varchar2,
6707 		P_BB_New               IN         Varchar2,
6708 		P_Proj_Attribute_Rec   IN         Pa_Otc_Api.Project_Attribution_Rec,
6709 		P_Mode                 IN         Varchar2,
6710         P_Process_Flag         IN         Varchar2,
6711 		X_BB_Detail_Changed    OUT NOCOPY Varchar2,
6712 		X_Data_Conflict_Flag   OUT NOCOPY Varchar2,
6713 		X_BB_Detail_Deleted    OUT NOCOPY Varchar2,
6714 		X_Adj_in_Projects_Flag OUT NOCOPY Varchar2)
6715 
6716    Is
6717 
6718 	l_Orig_Trx_Ref     Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE := Null;
6719 	l_Net_Zero_flag    Pa_Expenditure_Items_All.Net_Zero_Adjustment_Flag%TYPE := 'N';
6720 	l_Max_Version      Number := 0;
6721 	l_RowId            RowId;
6722 	l_Exp_Item_Id      Pa_Expenditure_Items_All.Expenditure_Item_Id%TYPE;
6723 	l_Exp_Item_Comment Pa_Expenditure_Comments.Expenditure_Comment%TYPE;
6724 	l_Ovn_Check_Value  Number := 0;
6725     -- Bug 10253400.. 12.2 payroll intg .. start
6726     l_job_id           Pa_Expenditure_Items_All.Job_id%TYPE;
6727     l_location_id      Pa_Expenditure_Items_All.Location_id%TYPE;
6728     l_pay_element_type_id     Pa_Expenditure_Items_All.pay_element_type_id%TYPE;
6729     -- Bug 10253400.. 12.2 payroll intg .. end
6730 
6731 l_Cbs_Element_Id   PA_Expenditure_Items_All.Cbs_Element_Id%TYPE; -- Added for CBS Enhancement Bug 16220146
6732 
6733 	 /*Start -changes for bug:7604482 */
6734  	                  l_Proj_Id             Pa_Projects_All.Project_Id%TYPE;
6735  	                  l_Task_Id             Pa_Tasks.Task_Id%TYPE;
6736  	                  l_Exp_Type            Pa_Expenditure_Types.Expenditure_Type%TYPE;
6737  	 /*End -changes for bug:7604482 */
6738 
6739 	Cursor AdjustmentRecords (P_Orig_Trx_Ref IN Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE) Is
6740 	Select
6741 		RowId,
6742 		Expenditure_Item_Id,
6743                 Net_Zero_Adjustment_Flag,
6744 		Orig_Transaction_Reference
6745         From
6746                 Pa_Expenditure_Items_All
6747         Where
6748                 Transaction_Source = 'ORACLE TIME AND LABOR'
6749         And     Orig_Transaction_Reference like l_orig_trx_ref
6750 	Order By Orig_Transaction_Reference;
6751 
6752         Cursor EiIsChanged ( P_RowId IN RowId ) Is
6753         Select
6754 		'Y'
6755         From
6756 		Pa_Expenditure_Items_All ei,
6757                 Pa_Expenditure_Comments c
6758 	Where
6759           	ei.Expenditure_Item_Id            =  c.Expenditure_Item_Id(+)
6760 	And    (ei.Task_Id                        <> nvl(P_Proj_Attribute_Rec.Task_Id,-99)
6761         Or      ei.Expenditure_Type               <> nvl(P_Proj_Attribute_Rec.Expenditure_Type,'-999999999')
6762         Or      ei.System_Linkage_Function        <> nvl(P_Proj_Attribute_Rec.Sys_Linkage_Func,'-99')
6763         Or      ei.Quantity                       <> nvl(P_Proj_Attribute_Rec.Quantity,-99)
6764         Or      nvl(ei.Attribute_Category,'-99')  <> nvl(P_Proj_Attribute_Rec.Attrib_Category,'-99')
6765         Or      nvl(ei.Attribute1,'-99')          <> nvl(P_Proj_Attribute_Rec.Attribute1,'-99')
6766         Or      nvl(ei.Attribute2,'-99')          <> nvl(P_Proj_Attribute_Rec.Attribute2,'-99')
6767         Or      nvl(ei.Attribute3,'-99')          <> nvl(P_Proj_Attribute_Rec.Attribute3,'-99')
6768         Or      nvl(ei.Attribute4,'-99')          <> nvl(P_Proj_Attribute_Rec.Attribute4,'-99')
6769         Or      nvl(ei.Attribute5,'-99')          <> nvl(P_Proj_Attribute_Rec.Attribute5,'-99')
6770         Or      nvl(ei.Attribute6,'-99')          <> nvl(P_Proj_Attribute_Rec.Attribute6,'-99')
6771         Or      nvl(ei.Attribute7,'-99')          <> nvl(P_Proj_Attribute_Rec.Attribute7,'-99')
6772         Or      nvl(ei.Attribute8,'-99')          <> nvl(P_Proj_Attribute_Rec.Attribute8,'-99')
6773         Or      nvl(ei.Attribute9,'-99')          <> nvl(P_Proj_Attribute_Rec.Attribute9,'-99')
6774         Or      nvl(ei.Attribute10,'-99')         <> nvl(P_Proj_Attribute_Rec.Attribute10,'-99')
6775         Or      nvl(c.Expenditure_Comment,'-99')  <> nvl(P_Proj_Attribute_Rec.Expenditure_Item_Comment,'-99')
6776         Or      nvl(ei.PO_Line_Id,-99)            <> nvl(P_Proj_Attribute_Rec.PO_Line_Id,-99)
6777         Or      nvl(ei.PO_Price_Type,'-99')       <> nvl(P_Proj_Attribute_Rec.PO_Price_Type,'-99')
6778         -- Bug 10253400.. 12.2 payroll intg .. start
6779         Or      nvl(ei.job_id, -99)               <> nvl(P_Proj_Attribute_Rec.Job_Id, nvl(ei.job_id, -99))
6780         Or      nvl(ei.location_id, -99)          <> nvl(P_Proj_Attribute_Rec.Location_Id, nvl(ei.location_id, -99))
6781         Or      nvl(ei.pay_element_type_id, -99)     <> nvl(P_Proj_Attribute_Rec.Pay_Element_Type_Id, nvl(ei.pay_element_type_id, -99))
6782         -- Bug 10253400.. 12.2 payroll intg .. end
6783         Or      nvl(ei.Cbs_Element_Id, -99)     <> nvl(P_Proj_Attribute_Rec.Cbs_Element_Id, nvl(ei.Cbs_Element_Id, -99))) -- Added for CBS Enhancement Bug 16220146
6784         And     ei.RowId                          =  P_RowId;
6785 --Bug 14796976
6786 	AdjRec AdjustmentRecords%RowType;
6787         l_Orig_Transaction_Reference Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE;
6788         l_Ei_Changed_Flag Varchar2(1) := 'N';
6789 
6790 	E_Exception Exception;
6791 
6792    Begin
6793 
6794 	G_Stage := 'Entering procedure DetermineProcessingFlags().';
6795 	Pa_Otc_Api.TrackPath('ADD','DetermineProcessingFlags');
6796 
6797 	G_Stage := 'Initialize the out parameters to No.';
6798         X_BB_Detail_Changed    := 'N';
6799         X_Data_Conflict_Flag   := 'N';
6800         X_BB_Detail_Deleted    := 'N';
6801         X_Adj_in_Projects_Flag := 'N';
6802 
6803         G_Stage := 'Check for deleted detail bb.';
6804         If P_BB_Date_To <> Hr_General.End_Of_Time Then
6805 
6806 		G_Stage := 'Detail bb block has been deleted.';
6807                	X_BB_Detail_Deleted := 'Y';
6808 
6809         End If;
6810 
6811 	-- If an item has been deleted in OTL then P_BB_Changed = Y as well.
6812 
6813 	G_Stage := 'Check and setting the ovn value to scan Project ei table with';
6814 	If P_BB_Changed = 'Y' and P_BB_New = 'N' Then
6815 
6816 		G_Stage := 'The detail scope bb has changed.';
6817 		l_Ovn_Check_Value := P_BB_Ovn + 1;
6818 		X_BB_Detail_Changed := 'Y';
6819 
6820 	ElsIf X_BB_Detail_Deleted = 'Y' Then
6821 
6822         G_Stage := 'The detail scope bb is being deleted.';
6823 		l_Ovn_Check_Value := P_BB_Ovn + 1;
6824 
6825     ElsIf P_Process_Flag = 'Y' Then
6826 
6827         -- Only the header for the timecard has been changed and not the detail
6828         -- building block, but the detail bb ovn still needs to be incremented.
6829         G_Stage := 'The detail scope bb is being processed.';
6830         l_Ovn_Check_Value := P_BB_Ovn + 1;
6831 
6832 	Else
6833 
6834 		l_Ovn_Check_Value := P_BB_Ovn;
6835 
6836 	End If;
6837 
6838 	/* Build the value for "where like" clause in cursor to check for in projects
6839 	 * in cursor call.
6840 	 */
6841 
6842 	G_Stage := 'Create conditional variable value.';
6843 	l_orig_trx_ref := to_char(P_BB_Id) || ':%';
6844 
6845 	G_Stage := 'Open cursor AdjustmentRecords.';
6846 	Open AdjustmentRecords (l_orig_trx_ref);
6847 
6848 	G_Stage := 'Start Loop for cursor AdjustmentRecords.';
6849 	Loop
6850 
6851 		G_Stage := 'Fetch AdjustmentRecords.';
6852 		Fetch AdjustmentRecords into AdjRec;
6853 
6854 		/* If there are no records then the exit routine is fire the first time
6855 		 * it is executed and the default value for the net zero flag of 'N' will be used.
6856 		 */
6857 		Exit When AdjustmentRecords%NOTFOUND;
6858 
6859 		/* Since the original_transaction_reference columns is a concatenation of Building Block Id
6860 		 * and the Object Version Number for the OTL record being processed, we need to determine the
6861 		 * max Object Version Number always for determining if adjustments can be done, since we only
6862 		 * want to look at the last record imported into Projects for this with the same Building Block
6863 		 * Id in the pa_expenditure_items table.
6864 		 */
6865 
6866 		G_Stage := 'Check match condition.';
6867 		If l_Max_Version < To_Number(Substr(AdjRec.Orig_Transaction_Reference,
6868 						Instr(AdjRec.Orig_Transaction_Reference,':') + 1)) Then
6869 
6870 			G_Stage := 'Store nzf, row_id, ei_id, orig_trans_ref, and Max Version variables.';
6871 			l_Net_Zero_flag := AdjRec.Net_Zero_Adjustment_Flag;
6872 			l_Max_Version := To_Number(Substr(AdjRec.Orig_Transaction_Reference,
6873 					     		Instr(AdjRec.Orig_Transaction_Reference,':') + 1));
6874 			l_RowId := AdjRec.RowId;
6875 			l_Exp_Item_Id := AdjRec.Expenditure_Item_Id;
6876 			l_Orig_Transaction_Reference := AdjRec.Orig_Transaction_Reference;
6877 
6878 		ElsIf l_Max_Version = To_Number(Substr(AdjRec.Orig_Transaction_Reference,
6879                                                 Instr(AdjRec.Orig_Transaction_Reference,':') + 1)) And
6880 		      nvl(AdjRec.Net_Zero_Adjustment_Flag,'N') <> 'Y' Then
6881 
6882                         /* If an earlier adjustment was made in OTL and that was sent to Project via Trx Import
6883                          * there will be two ei records with the same Orig_Transaction_Reference.  Both need to
6884                          * be looked at since one will have a Net_Zero_Adjustment_Flag = 'Y' and the other will not.
6885                          */
6886 
6887 			G_Stage := 'Store nzf, row_id, ei_id variables where org_trx_ref is same.';
6888 			l_Net_Zero_flag := AdjRec.Net_Zero_Adjustment_Flag;
6889 			l_RowId := AdjRec.RowId;
6890 			l_Exp_Item_Id := AdjRec.Expenditure_Item_Id;
6891 
6892 		End If;
6893 
6894 	End Loop;
6895 
6896 	G_Stage := 'Close cursor AdjustmentRecords.';
6897 	Close AdjustmentRecords;
6898 
6899 	/* If l_Max_Version = 0 Then the OTL Building Block was never imported into Projects.
6900 	 * If l_Max_Version > 0 Then the OTL Building Block has been imported at least once into Projects.
6901 	 */
6902 
6903 	G_Stage := 'Determining if BB sent for validation is a change from the one in projects.';
6904 	If l_Max_Version > 0 Then
6905 
6906 		/* l_Max_Version should always be less than or equal to the Object_Version_Number
6907                	 * passed to this procedure. It should never be greater than the Object_Version_Number passed in.
6908 		 * If l_Max_Version = l_Ovn_Check_Value Then the bb was not changed and can ignore further testing.
6909 		 */
6910 		If l_Max_Version < l_Ovn_Check_Value Then
6911 
6912 			G_Stage := 'Open cursor EiIsChanged.';
6913                		Open EiIsChanged( l_RowId ) ;
6914 
6915 			G_Stage := 'Fetch from cursor EiIsChanged.';
6916                		Fetch EiIsChanged into l_Ei_Changed_Flag;
6917 
6918 			G_Stage := 'Close cursor EiIsChanged.';
6919                		Close EiIsChanged;
6920 
6921                		If l_Ei_Changed_Flag = 'N' Then
6922 
6923 				If P_Mode = 'VALIDATE' and
6924                    ( P_BB_Changed = 'Y' or P_Process_Flag = 'Y' ) and
6925 				   X_BB_Detail_Deleted = 'N' Then
6926 
6927 			   	   	G_Stage := 'Only Ovn has changed.  Update the orig_transaction_reference of the ei.';
6928                     Update Pa_Expenditure_Items_all  --for Bug# 13519235
6929                     Set
6930                          Orig_Transaction_Reference = To_Char(P_BB_Id) || ':' || To_Char(l_Ovn_Check_Value),
6931                          last_update_date = sysdate,
6932                          last_updated_by = to_Number(Fnd_Profile.Value('USER_ID')),
6933                          last_update_login = to_Number(Fnd_Profile.Value('LOGIN_ID'))
6934                     Where
6935                          RowId = l_RowId;
6936                        /*Start-Changes for Bug:7604482 */
6937                        -- Bug 10253400.. 12.2 payroll intg .. include the job, location and pay element
6938                         -- Bug 16220146: Added cbs_element_id in the below select
6939  	                   select  project_id , task_id, expenditure_type,
6940                                job_id, location_id, pay_element_type_id, cbs_element_id
6941  	                      into    l_Proj_Id , l_task_id , l_Exp_Type,
6942                                l_job_id, l_location_id, l_pay_element_type_id, l_Cbs_Element_Id
6943  	                    from Pa_Expenditure_Items_all  --for Bug# 13519235
6944  	                    where RowId = l_RowId;
6945 
6946                   -- Bug 10253400.. 12.2 payroll intg .. extend the check to include job, location and pay element
6947                   -- Bug 16220146: extended the check for cbs_element_id
6948  	              IF (l_Proj_Id <> nvl(P_Proj_Attribute_Rec.project_Id,-99)or l_Task_Id <> nvl(P_Proj_Attribute_Rec.Task_Id,-99)
6949                       Or l_Exp_Type  <> nvl(P_Proj_Attribute_Rec.Expenditure_Type,'-999999999')
6950                       or nvl(l_job_id, -99) <> nvl(P_Proj_Attribute_Rec.job_Id,-99)
6951                       Or nvl(l_pay_element_type_id, -99) <> nvl(P_Proj_Attribute_Rec.pay_element_type_id, -99)
6952                       or nvl(l_location_id, -99) <> nvl(P_Proj_Attribute_Rec.location_Id,-99)
6953                       Or nvl(l_Cbs_Element_Id, -99) <> nvl(P_Proj_Attribute_Rec.Cbs_Element_Id,-99)) then
6954  	                    G_Stage := 'Set the BB_Detail_Changed flag to Y.';
6955  	                    X_BB_Detail_Changed := 'Y';
6956  	               ELSE
6957 		    -- Since only the ovn has changed we don't care about net zero flag value.
6958                     -- And we can ignore the change over all since we are updating the
6959                     -- ei record to store the new ovn.  No change we care about has occurred.
6960                     G_Stage := 'Set the BB_Detail_Changed flag to N.';
6961                     X_BB_Detail_Changed := 'N';
6962 		      END IF;
6963  	           /*End-Changes for Bug:7604482*/
6964 			      /* Bug 2283011  The changed_flag is coming in as 'N' for deleted items not 'Y' so
6965                                  we don't need to consider it value then.
6966 		 		ElsIf P_BB_Changed = 'Y' and */
6967 				ElsIf X_BB_Detail_Deleted = 'Y' and
6968 				      l_Net_Zero_flag = 'Y' Then
6969 
6970 					G_Stage := 'BB/EI has been already changed in Projects, so cannot delete.';
6971 					X_Adj_in_Projects_Flag := 'Y';
6972 
6973 				End If;
6974 
6975 			Else -- The OTL detail block record is different from what is in Projects.
6976 
6977 			    	G_Stage := 'Check net zero flag value to indicate adj in Projects.';
6978                			/* Note that If net zero flag is 'Y' then l_max_version > 0 */
6979                			If l_Net_Zero_flag = 'Y' Then
6980 
6981 				   	G_Stage := 'BB/EI has been already changed in Projects, so cannot change.';
6982                        		   	X_Adj_in_Projects_Flag := 'Y' ;
6983 
6984 				   	G_Stage := 'Checking for Data confict.';
6985 				   	If P_BB_Changed = 'N' and X_BB_Detail_Deleted = 'N' Then
6986 
6987 				   		G_Stage := 'Data conflict exists.';
6988                                    		X_Data_Conflict_Flag := 'Y';
6989 
6990 				   	End If;
6991 
6992                			End If; -- Net_Zero_Flag
6993 
6994                		End If; -- l_Ei_Changed_Flag = 'N'
6995 
6996 		End If; -- l_Max_Version < l_Ovn_Check_Value
6997 
6998 	End If; -- l_Max_Version > 0
6999 
7000 	G_Stage := 'Leaving procedure DetermineProcessingFlags().';
7001 	Pa_Otc_Api.TrackPath('STRIP','DetermineProcessingFlags');
7002 
7003    Exception
7004 	When Others Then
7005 		Raise;
7006 
7007    End DetermineProcessingFlags;
7008 
7009 
7010 -- =======================================================================
7011 -- Start of Comments
7012 -- API Name      : AdjustAllowedToOTCItem
7013 -- Type          : Public
7014 -- Pre-Reqs      : None
7015 -- Type          : Procedure
7016 -- Function      : This procedure is used to check and see if an OTL expenditure item that
7017 --                 has been imported into Projects can adjusted in Projects by calling the
7018 --                 API Hxc_Generic_Retrieval_Utils.Time_Bld_Blk_Changed.
7019 --
7020 -- Parameters    :
7021 -- IN            P_Orig_Txn_Reference - Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE
7022 -- OUT           X_Flag               - Varchar2(1)
7023 --
7024 /*--------------------------------------------------------------------------*/
7025 
7026    Procedure  AdjustAllowedToOTCItem(
7027                      P_Orig_Txn_Reference IN         Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE,
7028 		     X_flag               OUT NOCOPY BOOLEAN) Is
7029 
7030       l_BB_Id        Hxc_Time_Building_Blocks.Time_Building_Block_Id%TYPE;
7031       l_BB_Ovn       Hxc_Time_Building_Blocks.Object_Version_Number%TYPE;
7032       l_Changed_Flag Boolean := False;
7033 
7034    Begin
7035 
7036         G_Stage := 'Entering procedure AdjustAllowedToOTCItem().';
7037         Pa_Otc_Api.TrackPath('ADD','AdjustAllowedToOTCItem');
7038 
7039 	G_Path := ' ';
7040 
7041 	G_Stage := 'Check if the original transaction reference is null or not.';
7042 	If P_Orig_Txn_Reference Is Not Null Then
7043 
7044 		G_Stage := 'BB Id and BB Ovn.';
7045 		l_BB_Id := To_Number(SubStr(P_Orig_Txn_Reference,1,InStr(P_Orig_Txn_Reference,':') - 1));
7046 		l_BB_Ovn := To_Number(SubStr(P_Orig_Txn_Reference,InStr(P_Orig_Txn_Reference,':') + 1));
7047 
7048 		G_Stage := 'Call Hxc_Integration_Layer_V1_Grp.Time_Bld_Blk_Changed API.';
7049 		l_Changed_Flag := Hxc_Integration_Layer_V1_Grp.Time_Bld_Blk_Changed(
7050 					P_Bb_Id => l_bb_id,
7051 					P_Bb_Ovn => l_bb_ovn);
7052 
7053 		G_Stage := 'Set out going flag based on what OTL is saying.';
7054 		If l_Changed_Flag Then
7055 
7056 			X_flag := False;
7057 
7058 		Else
7059 
7060 			X_Flag := True;
7061 
7062 		End If;
7063 
7064 	Else
7065 
7066                 /* Did not originate in OTL.  This item is a resulting child of the
7067 		 * original OTL item that was adjusted.  So want to always default it
7068 		 * so that it can adjusted and let other code restrictions in PA handle
7069 		 * whether or not the expenditure item can be adjusted.
7070 		 */
7071 		X_Flag := True;
7072 
7073 	End If;
7074 
7075 	G_Stage := 'Leaving procedure AdjustAllowedToOTCItem().';
7076 	Pa_Otc_Api.TrackPath('STRIP','AdjustAllowedToOTCItem');
7077 
7078    Exception
7079 	When Others Then
7080 		Raise_Application_Error(-20003,'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage || ' : ' || SQLERRM);
7081 
7082    End AdjustAllowedToOTCItem;
7083 
7084 
7085 -- =======================================================================
7086 -- Start of Comments
7087 -- API Name      : ProjectTaskUsed
7088 -- Type          : Public
7089 -- Pre-Reqs      : None
7090 -- Type          : Procedure
7091 -- Return        : n/a
7092 -- Function      : This procedure is used to check to see if there are Project OTL
7093 --                 expenditure items that are using a specific project or task. Will be calling
7094 --                 an OTL API to determine this.  If parameters are not properly populated then
7095 --                 return TRUE.
7096 --
7097 -- Parameters    :
7098 -- IN            P_Search_Attribute - Varchar2 -- 'PROJECT_ID' or 'TASK_ID'
7099 --               P_Search_Value     - Number   -- Project_Id or Task_Id
7100 -- OUT           X_Used             - Boolean
7101 --
7102 
7103 /*--------------------------------------------------------------------------*/
7104 
7105    Procedure ProjectTaskUsed(
7106 				P_Search_Attribute IN         Varchar2,
7107 				P_Search_Value     IN         Number,
7108 				X_Used             OUT NOCOPY Boolean)
7109 
7110    Is
7111 
7112 	l_Attribute_Exists Boolean := False;
7113 
7114    Begin
7115 
7116 	G_Stage := 'Entering procedure ProjectTaskUsed().';
7117 	Pa_Otc_Api.TrackPath('ADD','ProjectTaskUsed');
7118 
7119         G_Path := ' ';
7120 
7121 	G_Stage := 'Check that the parameters is valid.';
7122 	If P_Search_Attribute in ('PROJECT','TASK') and P_Search_Value is not null Then
7123 
7124 		If P_Search_Attribute = 'PROJECT' Then
7125 
7126 			G_Stage := 'Call Hxc_Integration_Layer_V1_Grp.Chk_Mapping_Exists() API to check if project exists.';
7127                 	l_Attribute_Exists := Hxc_Integration_Layer_V1_Grp.Chk_Mapping_Exists (
7128 					   P_Bld_Blk_Info_Type => 'PROJECTS'
7129                                    ,       P_Field_Name        => 'Project_Id'
7130                                    ,       P_Field_Value       => P_Search_Value
7131                                    ,       P_status            => 'WORKING' -- 8360516
7132                                    ,       P_Scope             => 'DETAIL');
7133 
7134 		Else
7135 
7136 			G_Stage := 'Call Hxc_Integration_Layer_V1_Grp.Chk_Mapping_Exists() API to check if task exists.';
7137 			l_Attribute_Exists := Hxc_Integration_Layer_V1_Grp.Chk_Mapping_Exists (
7138                                            P_Bld_Blk_Info_Type => 'PROJECTS'
7139                                    ,       P_Field_Name        => 'Task_Id'
7140                                    ,       P_Field_Value       => P_Search_Value
7141                                    ,       P_status            => 'WORKING' -- 8360516
7142                                    ,       P_Scope             => 'DETAIL');
7143 
7144 		End If;
7145 
7146 
7147 		X_Used := l_Attribute_Exists;
7148 
7149 	Else
7150 
7151 		X_Used := True;
7152 
7153 	End If;
7154 
7155 	G_Stage := 'Leaving procedure ProjectTaskUsed().';
7156 	Pa_Otc_Api.TrackPath('STRIP','ProjectTaskUsed');
7157 
7158    Exception
7159 	When Others Then
7160 		Raise_Application_Error(-20005,'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage || ' : ' || SQLERRM);
7161 
7162    End ProjectTaskUsed;
7163 
7164 -- =======================================================================
7165 -- Start of Comments
7166 -- API Name      : ProjectTaskPurgeable
7167 -- Type          : Public
7168 -- Pre-Reqs      : None
7169 -- Type          : Procedure
7170 -- Return        : n/a
7171 -- Function      : This procedure is used to check to see if there are Project OTC
7172 --                 expenditure items that are using a specific project or task that have/have not been
7173 --                 imported successfullying into projects.  Will be calling
7174 --                 an OTC API to determine this.  If parameters are not properly populated then
7175 --                 return TRUE.
7176 --
7177 -- Parameters    :
7178 -- IN            P_Search_Attribute - Varchar2 -- 'PROJECT' or 'TASK'
7179 --               P_Search_Value     - Number   -- Project_Id or Task_Id
7180 -- OUT           X_Purgeable        - Boolean
7181 --
7182 
7183 /*--------------------------------------------------------------------------*/
7184 
7185    Procedure ProjectTaskPurgeable(P_Search_Attribute IN         Varchar2,
7186                                   P_Search_Value     IN         Number,
7187                                   X_Purgeable        OUT NOCOPY Boolean)
7188 
7189    Is
7190 
7191         l_Attribute_Purgeable Boolean := False;
7192 
7193    Begin
7194 
7195         G_Stage := 'Entering procedure ProjectTaskPurgeable().';
7196         Pa_Otc_Api.TrackPath('ADD','ProjectTaskPurgeable');
7197 
7198         G_Path := ' ';
7199 
7200         G_Stage := 'Check that the parameters is valid.';
7201         If P_Search_Attribute in ('PROJECT','TASK') And P_Search_Value is Not Null Then
7202 
7203                 If P_Search_Attribute = 'PROJECT' Then
7204 
7205                         G_Stage := 'Call Hxc_Integration_Layer_V1_Grp.Chk_Mapping_Exists() API procedure to check if project purgeable.';
7206                         l_Attribute_Purgeable := Hxc_Integration_Layer_V1_Grp.Chk_Mapping_Exists (
7207                                                        P_Bld_Blk_Info_Type      => 'PROJECTS'
7208                                                ,       P_Field_Name             => 'Project_Id'
7209                                                ,       P_Field_Value            => P_Search_Value
7210                                                ,       P_Scope                  => 'DETAIL'
7211 				               ,       P_Retrieval_Process_Name => 'Projects Retrieval Process');
7212 
7213                 Else
7214 
7215                         G_Stage := 'Call Hxc_Integration_Layer_V1_Grp.Chk_Mapping_Exists() API procedure to check if task purgeable.';
7216                         l_Attribute_Purgeable := Hxc_Integration_Layer_V1_Grp.Chk_Mapping_Exists (
7217                                                        P_Bld_Blk_Info_Type      => 'PROJECTS'
7218                                                ,       P_Field_Name             => 'Task_Id'
7219                                                ,       P_Field_Value            => P_Search_Value
7220                                                ,       P_Scope                  => 'DETAIL'
7221 				               ,       P_Retrieval_Process_Name => 'Projects Retrieval Process');
7222 
7223                 End If;
7224 
7225 
7226 		/* Chk_Mapping_Exists() returns TRUE if the field name / value combination exist but have
7227 		 * not yet been transferred. FALSE, if they have been transferred or the
7228 		 * combination does not exist.
7229 	         */
7230 		If l_Attribute_Purgeable Then
7231 
7232                 	X_Purgeable := False;
7233 
7234 		Else
7235 
7236 			X_Purgeable := True;
7237 
7238 		End If;
7239 
7240         Else
7241 
7242                 X_Purgeable := False;
7243 
7244         End If;
7245 
7246         G_Stage := 'Leaving procedure ProjectTaskPurgeable().';
7247         Pa_Otc_Api.TrackPath('STRIP','ProjectTaskPurgeable');
7248 
7249    Exception
7250         When Others Then
7251                 Raise_Application_Error(-20006,'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage || ' : ' || SQLERRM);
7252 
7253    End ProjectTaskPurgeable;
7254 
7255 
7256 -- ========================================================================
7257 -- Start Of Comments
7258 -- API Name      : RetrieveProjAttribution
7259 -- Type          : Private
7260 -- Pre-Reqs      : None
7261 -- Type          : Procedure
7262 -- Return        : n/a
7263 -- Function      : This procedure is used to pull out the needed project specific data from
7264 --                 the OTL pl/sql table P_Attribute_Table.
7265 --
7266 -- Parameters    :
7267 -- IN            P_Building_Block_Rec  - Hxc_User_Type_Definition_Grp.Building_Block_Info
7268 --               P_Building_Block      - Hxc_User_Type_Definition_Grp.Timecard_Info
7269 --               P_Attribute_Table     - Hxc_User_Type_Definition_Grp.App_Attributes_Info
7270 --               X_Detail_Attr_Changed - Varchar2
7271 -- OUT
7272 --               X_Detail_Attr_Changed - Varchar2
7273 --               X_Proj_Attrib_Rec     - Pa_Otc_Api.Project_Attribution_Rec
7274 --
7275 
7276 /*--------------------------------------------------------------------------*/
7277 
7278    Procedure RetrieveProjAttribution(
7279         P_Building_Block_Rec  IN            Hxc_User_Type_Definition_Grp.Building_Block_Info,
7280 		P_Building_Block      IN            Hxc_User_Type_Definition_Grp.Timecard_Info,
7281         P_Attribute_Table     IN            Hxc_User_Type_Definition_Grp.App_Attributes_Info,
7282 		X_Detail_Attr_Changed IN OUT NOCOPY Varchar2,
7283         X_Proj_Attrib_Rec     OUT    NOCOPY Pa_Otc_Api.Project_Attribution_Rec) -- 2672653
7284 
7285    Is
7286 
7287 	    j Binary_Integer := Null;
7288 	    i Binary_Integer := Null;
7289         l_Attrib_Category Varchar2(30) := Null;
7290 		-- Start: Added for CBS Enhancement Bug 16220146
7291 		l_Actual_Task_Id     Number           := Null;
7292 		l_Cbs_Element_Id     Number           := Null;
7293 		-- End: Added for CBS Enhancement Bug 16220146
7294 
7295    Begin
7296 
7297         G_Stage := 'Entering procedure RetrieveProjAttribution().';
7298         Pa_Otc_Api.TrackPath('ADD','RetrieveProjAttribution');
7299 
7300         G_Stage := 'Entering attribute table loop.';
7301         Loop
7302 
7303 		     If j is null Then
7304 
7305 		          j := P_Attribute_Table.First;
7306 
7307 		     Else
7308 
7309 			      j := P_Attribute_Table.Next(j);
7310 
7311 		     End If;
7312 
7313 		     G_Stage := 'Looping thru attribute pl/sql table yanking out project attribution for current record.';
7314 		     If P_Attribute_Table(j).Building_Block_Id = P_Building_Block_Rec.Time_Building_Block_Id Then
7315 
7316                   If Upper(P_Attribute_Table(j).Attribute_Name) = 'PROJECT_ID' Then
7317 
7318 			           G_Stage := 'Get Project Id.';
7319                        X_Proj_Attrib_Rec.Project_Id   := To_Number(P_Attribute_Table(j).Attribute_Value);
7320 				       G_Stage := 'Get Project Attribute Id.';
7321 				       X_Proj_Attrib_Rec.Proj_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
7322 				       -- X_Proj_Attrib_Rec.Proj_Attr_Ovn := P_Attribute_Table(j).Object_Version_Number;
7323 
7324 				       G_Stage := 'Check project  changed flag.';
7325                        If P_Attribute_Table(j).Changed <> 'N' Then
7326 				            X_Detail_Attr_Changed := 'Y';
7327 			           End If;
7328 
7329                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'TASK_ID' Then
7330 
7331 			           G_Stage := 'Get Task Id.';
7332                        X_Proj_Attrib_Rec.Task_Id      := To_Number(P_Attribute_Table(j).Attribute_Value);
7333 				       G_Stage := 'Get Task Attribute Id';
7334 				       X_Proj_Attrib_Rec.Task_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
7335 
7336                        G_Stage := 'Check task changed flag.';
7337                        If P_Attribute_Table(j).Changed <> 'N' Then
7338                             X_Detail_Attr_Changed := 'Y';
7339                        End If;
7340 
7341 				     -- Start: Added for CBS Enhancement Bug 16220146
7342 				     If X_Proj_Attrib_Rec.Project_Id Is Not Null And X_Proj_Attrib_Rec.Task_Id Is Not Null Then
7343 
7344 					    If PA_ALTERNATE_TASK_PVT.Is_Cbs_Enabled(X_Proj_Attrib_Rec.Project_Id) = 'Y' Then
7345 
7346 					       Begin
7347 
7348 						      Select Proj_Element_Id, Cbs_Element_Id
7349 							  Into l_Actual_Task_Id, l_Cbs_Element_Id
7350 							  From Pa_Alternate_Tasks
7351 							  Where Alt_Task_Id = X_Proj_Attrib_Rec.Task_Id;
7352 
7353 							  X_Proj_Attrib_Rec.Task_Id        := l_Actual_Task_Id;
7354 							  X_Proj_Attrib_Rec.Cbs_Element_Id := l_Cbs_Element_Id;
7355 
7356 						   Exception
7357 						      When Others Then
7358 						         l_Actual_Task_Id := Null;
7359 							     l_Cbs_Element_Id := Null;
7360 							     X_Proj_Attrib_Rec.Task_Id        := Null;
7361 							     X_Proj_Attrib_Rec.Cbs_Element_Id := Null;
7362 							     Raise;
7363 						   End;
7364 					    Else
7365 					       X_Proj_Attrib_Rec.Cbs_Element_Id := Null;
7366 					    End If;
7367 				     End If;
7368 				     -- End: Added for CBS Enhancement Bug 16220146
7369 
7370                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'EXPENDITURE_TYPE' Then
7371 
7372 			           G_Stage := 'Get Expenditure Type.';
7373                        X_Proj_Attrib_Rec.Expenditure_Type := P_Attribute_Table(j).Attribute_Value;
7374 				       G_Stage := 'Get Expenditure Type Attribute Id';
7375 				       X_Proj_Attrib_Rec.Exp_Type_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
7376 
7377                        G_Stage := 'Check expenditure_type changed flag.';
7378                        If P_Attribute_Table(j).Changed <> 'N' Then
7379                             X_Detail_Attr_Changed := 'Y';
7380                        End If;
7381 
7382                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'SYSTEM_LINKAGE_FUNCTION' Then
7383 
7384 			           G_Stage := 'Get Sys Link Func.';
7385                        X_Proj_Attrib_Rec.Sys_Linkage_Func := P_Attribute_Table(j).Attribute_Value;
7386 				       G_Stage := 'Get Sys Link Func Attribute Id.';
7387 				       X_Proj_Attrib_Rec.Sys_Link_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
7388 
7389                        G_Stage := 'Check sys link func changed flag.';
7390                        If P_Attribute_Table(j).Changed <> 'N' Then
7391                             X_Detail_Attr_Changed := 'Y';
7392                        End If;
7393 
7394                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'DUMMY PAEXPITDFF CONTEXT' Then
7395 
7396                        /* The value column contains the following format:
7397                         *   'PAEXPITDFF - <attribute_category>'
7398                         * So to get the attribute_category out will need to find the position
7399                         * for ' - ' that is: '<space>-<space>' and then add 3.
7400                         */
7401 
7402                        l_Attrib_Category := P_Attribute_Table(j).Attribute_Value;
7403 
7404                        /* Need to check for null to avoid the unecessary errors using instr
7405                         * avoiding unhandled exceptions.
7406                         */
7407                        If l_Attrib_Category is not null Then
7408 
7409 				            G_Stage := 'Get DFF Attribute Category.';
7410                             X_Proj_Attrib_Rec.Attrib_Category := substr(l_Attrib_Category, instr(l_Attrib_category,' - ') + 3);
7411 
7412                        End If;
7413 
7414                        G_Stage := 'Check Attribute Category changed flag.';
7415                        If P_Attribute_Table(j).Changed <> 'N' Then
7416                             X_Detail_Attr_Changed := 'Y';
7417                        End If;
7418 
7419                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE1' Then
7420 
7421 			           G_Stage := 'Get DFF Attribute 1.';
7422                        X_Proj_Attrib_Rec.Attribute1 := P_Attribute_Table(j).Attribute_Value;
7423 
7424                        G_Stage := 'Check DFF Attribute 1 changed flag.';
7425                        If P_Attribute_Table(j).Changed <> 'N' Then
7426                             X_Detail_Attr_Changed := 'Y';
7427                        End If;
7428 
7429                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE2' Then
7430 
7431 				       G_Stage := 'Get DFF Attribute 2.';
7432                        X_Proj_Attrib_Rec.Attribute2 := P_Attribute_Table(j).Attribute_Value;
7433 
7434                        G_Stage := 'Check DFF Attribute 2 changed flag.';
7435                        If P_Attribute_Table(j).Changed <> 'N' Then
7436                             X_Detail_Attr_Changed := 'Y';
7437                        End If;
7438 
7439                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE3' Then
7440 
7441 				       G_Stage := 'Get DFF Attribute 3.';
7442                        X_Proj_Attrib_Rec.Attribute3 := P_Attribute_Table(j).Attribute_Value;
7443 
7444                        G_Stage := 'Check DFF Attribute 3 changed flag.';
7445                        If P_Attribute_Table(j).Changed <> 'N' Then
7446                             X_Detail_Attr_Changed := 'Y';
7447                        End If;
7448 
7449                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE4' Then
7450 
7451 				       G_Stage := 'Get DFF Attribute 4.';
7452                        X_Proj_Attrib_Rec.Attribute4 := P_Attribute_Table(j).Attribute_Value;
7453 
7454                        G_Stage := 'Check DFF Attribute 4 changed flag.';
7455                        If P_Attribute_Table(j).Changed <> 'N' Then
7456                             X_Detail_Attr_Changed := 'Y';
7457                        End If;
7458 
7459                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE5' Then
7460 
7461 				       G_Stage := 'Get DFF Attribute 5.';
7462                        X_Proj_Attrib_Rec.Attribute5 := P_Attribute_Table(j).Attribute_Value;
7463 
7464                        G_Stage := 'Check DFF Attribute 5 changed flag.';
7465                        If P_Attribute_Table(j).Changed <> 'N' Then
7466 				            X_Detail_Attr_Changed := 'Y';
7467                        End If;
7468 
7469                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE6' Then
7470 
7471 				       G_Stage := 'Get DFF Attribute 6.';
7472                        X_Proj_Attrib_Rec.Attribute6 := P_Attribute_Table(j).Attribute_Value;
7473 
7474                        G_Stage := 'Check DFF Attribute 6 changed flag.';
7475                        If P_Attribute_Table(j).Changed <> 'N' Then
7476 				            X_Detail_Attr_Changed := 'Y';
7477                        End If;
7478 
7479                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE7' Then
7480 
7481 				       G_Stage := 'Get DFF Attribute 7.';
7482                        X_Proj_Attrib_Rec.Attribute7 := P_Attribute_Table(j).Attribute_Value;
7483 
7484                        G_Stage := 'Check DFF Attribute 7 changed flag.';
7485                        If P_Attribute_Table(j).Changed <> 'N' Then
7486                             X_Detail_Attr_Changed := 'Y';
7487                        End If;
7488 
7489                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE8' Then
7490 
7491 				       G_Stage := 'Get DFF Attribute 8.';
7492                        X_Proj_Attrib_Rec.Attribute8 := P_Attribute_Table(j).Attribute_Value;
7493 
7494                        G_Stage := 'Check DFF Attribute 8 changed flag.';
7495                        If P_Attribute_Table(j).Changed <> 'N' Then
7496                             X_Detail_Attr_Changed := 'Y';
7497                        End If;
7498 
7499                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE9' Then
7500 
7501 				       G_Stage := 'Get DFF Attribute 9.';
7502                        X_Proj_Attrib_Rec.Attribute9 := P_Attribute_Table(j).Attribute_Value;
7503 
7504                        G_Stage := 'Check DFF Attribute 9 changed flag.';
7505                        If P_Attribute_Table(j).Changed <> 'N' Then
7506                             X_Detail_Attr_Changed := 'Y';
7507                        End If;
7508 
7509                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE10' Then
7510 
7511 				       G_Stage := 'Get DFF Attribute 10.';
7512                        X_Proj_Attrib_Rec.Attribute10 := P_Attribute_Table(j).Attribute_Value;
7513 
7514                        G_Stage := 'Check DFF Attribute 10 changed flag.';
7515                        If P_Attribute_Table(j).Changed <> 'N' Then
7516                             X_Detail_Attr_Changed := 'Y';
7517                        End If;
7518 
7519                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'BILLABLE_FLAG' Then
7520 
7521 				       G_Stage := 'Get Billable Flag Index value.';
7522                        X_Proj_Attrib_Rec.Billable_Flag_Index := j;
7523 
7524 				       G_Stage := 'Get Billable Flag.';
7525 				       X_Proj_Attrib_Rec.Billable_Flag := P_Attribute_Table(j).Attribute_Value;
7526 
7527 				       G_Stage := 'Get Billable Flag Attribute Id.';
7528 				       X_Proj_Attrib_Rec.Billable_Flag_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
7529 
7530 				       -- G_Stage := 'Get Billable Flag Attribute Ovn.';
7531 				       -- X_Proj_Attrib_Rec.Billable_Flag_Attr_Ovn := P_Attribute_Table(j).Object_Version_Number;
7532 
7533 			      -- Begin CWK changes PA.M
7534 			      ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PO LINE ID' Then
7535 
7536 				       G_Stage := 'Get PO_Line Number.';
7537                        X_Proj_Attrib_Rec.Po_Line_Id := P_Attribute_Table(j).Attribute_Value;
7538 				       G_Stage := 'Get PO Line Id Attribute Id.';
7539 				       X_Proj_Attrib_Rec.PO_Line_Id_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
7540 
7541                        G_Stage := 'Check PO_Line Number change flag.';
7542                        If P_Attribute_Table(j).Changed <> 'N' Then
7543                             X_Detail_Attr_Changed := 'Y';
7544                        End If;
7545 
7546 			      ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PO PRICE TYPE' Then
7547 
7548 				       G_Stage := 'Get Price Type.';
7549                        X_Proj_Attrib_Rec.PO_Price_Type := P_Attribute_Table(j).Attribute_Value;
7550 				       G_Stage := 'Get Price Type Attribute Id.';
7551 				       X_Proj_Attrib_Rec.PO_Price_Type_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
7552 
7553                        G_Stage := 'Check Price Type change flag.';
7554                        If P_Attribute_Table(j).Changed <> 'N' Then
7555                             X_Detail_Attr_Changed := 'Y';
7556                        End If;
7557 
7558 			      -- End CWK changes PA.M
7559                   -- Bug 10253400.. 12.2 payroll intg .. start
7560 			      ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'JOB_ID' Then
7561 
7562 				       G_Stage := 'Get Job Id.';
7563                        X_Proj_Attrib_Rec.Job_Id := P_Attribute_Table(j).Attribute_Value;
7564 				       G_Stage := 'Get Job Id Attribute Id.';
7565 				       X_Proj_Attrib_Rec.Job_Id_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
7566 
7567                        G_Stage := 'Check Job Id change flag.';
7568                        If P_Attribute_Table(j).Changed <> 'N' Then
7569                             X_Detail_Attr_Changed := 'Y';
7570                        End If;
7571 			      ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'LOCATION_ID' Then
7572 
7573 				       G_Stage := 'Get Location Id.';
7574                        X_Proj_Attrib_Rec.Location_Id := P_Attribute_Table(j).Attribute_Value;
7575 				       G_Stage := 'Get Location_Id Attribute Id.';
7576 				       X_Proj_Attrib_Rec.Location_Id_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
7577 
7578                        G_Stage := 'Check Location_Id change flag.';
7579                        If P_Attribute_Table(j).Changed <> 'N' Then
7580                             X_Detail_Attr_Changed := 'Y';
7581                        End If;
7582 			      ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'WORKTYPE_ID' Then
7583 
7584 				       G_Stage := 'Get Work Type Id.';
7585                        X_Proj_Attrib_Rec.Work_Type_Id := P_Attribute_Table(j).Attribute_Value;
7586 				       G_Stage := 'Get Work Type Attribute Id.';
7587 				       X_Proj_Attrib_Rec.Work_Type_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
7588 
7589                        G_Stage := 'Check Work Type Id change flag.';
7590                        If P_Attribute_Table(j).Changed <> 'N' Then
7591                             X_Detail_Attr_Changed := 'Y';
7592                        End If;
7593                   End If;
7594                   -- Bug 10253400.. 12.2 payroll intg .. end
7595 
7596 		     End If;  -- The correct building block to pull data from.
7597 
7598 		     G_Stage := 'Exit loop check.';
7599 		     Exit When j = P_Attribute_Table.Last;
7600 
7601         End Loop;
7602 
7603 	    G_Stage := 'Get Expenditure Item Date using loop to grab from DAY scope record.';
7604 	    /* The Start Time column in the DETAIL scope record passed to this procedure will not be populated.
7605            So we must grab the Start Time column value from the DAY scope.  We will loop thru the same table
7606            containing the entire timecard and find the correct DAY scope record for the detail scope record that
7607            we are currently working on. */
7608 
7609 	    Loop
7610 
7611 	         If i is null Then
7612 
7613 		          i := P_Building_Block.First;
7614 
7615 		     Else
7616 
7617 			      i := P_Building_Block.Next(i);
7618 
7619 		     End If;
7620 
7621 		     G_Stage := 'Check if the current record is the correct DAY record to grab Exp Item Date from.';
7622 		     If P_Building_Block(i).Time_Building_Block_Id = P_Building_Block_Rec.Parent_Building_Block_Id and
7623 		        P_Building_Block(i).Scope = 'DAY' Then
7624 
7625 		          G_Stage := 'Grab the Exp Item Date and exit the loop.';
7626 			      X_Proj_Attrib_Rec.Expenditure_Item_Date := Trunc(P_Building_Block(i).Start_Time);
7627 			      Exit;
7628 
7629 		     End If;
7630 
7631         End Loop;
7632 
7633 	    G_Stage := 'Get Expenditure Ending Date.';
7634 	    X_Proj_Attrib_Rec.Exp_Ending_date := Pa_Utils.NewGetWeekEnding(X_Proj_Attrib_Rec.Expenditure_Item_Date);
7635 
7636 	    G_Stage := 'Get Unit of Measure.';
7637 	    X_Proj_Attrib_Rec.UOM := P_Building_Block_Rec.Unit_Of_Measure;
7638 
7639 	    G_Stage := 'Get Inc By Person Id.';
7640 	    X_Proj_Attrib_Rec.Inc_By_Person_Id := P_Building_Block_Rec.Resource_Id;
7641 
7642 	    G_Stage := 'Get the Quantity.';
7643 	    X_Proj_Attrib_Rec.Quantity := to_number(P_Building_Block_Rec.Measure);
7644 
7645 	    G_Stage := 'Get the Expenditure Item Comment.';
7646         /* Bug 2930551 Check for length and truncate if needed */
7647         -- begin bug 4926265
7648         -- If length(P_Building_Block_Rec.Comment_Text) > 240 Then
7649         If lengthb(P_Building_Block_Rec.Comment_Text) > 240 Then
7650 
7651              -- X_Proj_Attrib_Rec.Expenditure_Item_Comment := substr(P_Building_Block_Rec.Comment_Text,1,240);
7652              X_Proj_Attrib_Rec.Expenditure_Item_Comment := substrb(P_Building_Block_Rec.Comment_Text,1,240);
7653              -- end  bug 4926265
7654 
7655         Else
7656 
7657              X_Proj_Attrib_Rec.Expenditure_Item_Comment := P_Building_Block_Rec.Comment_Text;
7658 
7659         End If;
7660 
7661 	    -- Beging CWK changes PA.M
7662 	    G_Stage := 'Get Person_Type.';
7663 	    X_Proj_Attrib_Rec.Person_Type := Pa_Otc_Api.GetPersonType(
7664                                               P_Person_Id => X_Proj_Attrib_Rec.Inc_By_Person_Id,
7665 						                      P_Ei_Date   => X_Proj_Attrib_Rec.Expenditure_Item_Date);
7666 
7667 
7668 	    If X_Proj_Attrib_Rec.Person_Type = 'CWK' And X_Proj_Attrib_Rec.Po_Line_Id Is Not Null Then
7669 
7670 	         G_Stage := 'Get PO Info.';
7671 		     PA_Otc_Api.GetPOInfo(
7672                   P_PO_Line_Id   => X_Proj_Attrib_Rec.Po_Line_Id,
7673 			      X_PO_Header_Id => X_Proj_Attrib_Rec.PO_Header_Id,
7674 			      X_Vendor_Id    => X_Proj_Attrib_Rec.Vendor_Id);
7675 
7676 	    End If;
7677 
7678 	    -- End CWK changes PA.M
7679 	    G_Stage := 'Leaving procedure RetrieveProjAttribution().';
7680 	    Pa_Otc_Api.TrackPath('STRIP','RetrieveProjAttribution');
7681 
7682    Exception
7683 	    When Others Then
7684 	         Raise;
7685 
7686    End RetrieveProjAttribution;
7687 
7688 
7689 -- ========================================================================
7690 -- Start Of Comments
7691 -- API Name      : RetrieveProjAttribForUpd
7692 -- Type          : Private
7693 -- Pre-Reqs      : None
7694 -- Type          : Procedure
7695 -- Return        : n/a
7696 -- Function      : This procedure is used to pull out the needed project specific data from
7697 --                 the OTL pl/sql table P_Attribute_Table.
7698 --
7699 -- Parameters    :
7700 -- IN            P_Building_Block_Rec  - Hxc_User_Type_Definition_Grp.Building_Block_Info
7701 --               P_Building_Block      - Hxc_User_Type_Definition_Grp.Timecard_Info
7702 --               P_Attribute_Table     - Hxc_User_Type_Definition_Grp.App_Attributes_Info
7703 --               X_Detail_Attr_Changed - Varchar2
7704 -- OUT
7705 --               P_Attribute_Table     - Hxc_User_Type_Definition_Grp.App_Attributes_Info
7706 --               X_Detail_Attr_Changed - Varchar2
7707 --               X_Proj_Attrib_Rec     - Pa_Otc_Api.Project_Attribution_Rec
7708 --
7709 
7710 /*--------------------------------------------------------------------------*/
7711 
7712    Procedure RetrieveProjAttribForUpd(
7713         P_Building_Block_Rec  IN            Hxc_User_Type_Definition_Grp.Building_Block_Info,
7714         P_Building_Block      IN            Hxc_User_Type_Definition_Grp.Timecard_Info,
7715         P_Attribute_Table     IN OUT NOCOPY Hxc_User_Type_Definition_Grp.App_Attributes_Info,
7716         X_Detail_Attr_Changed IN OUT NOCOPY Varchar2,
7717         X_Proj_Attrib_Rec        OUT NOCOPY Pa_Otc_Api.Project_Attribution_Rec) -- 2672653
7718 
7719    Is
7720 
7721 	    j Binary_Integer := Null;
7722 	    i Binary_Integer := Null;
7723         l_Attrib_Category Varchar2(30) := Null;
7724         found_billable   BOOLEAN ;
7725         billable_index   BINARY_INTEGER := Null;
7726         project_index    BINARY_INTEGER := Null;
7727 		-- Start: Added for CBS Enhancement Bug 16220146
7728 		l_Actual_Task_Id     Number           := Null;
7729 		l_Cbs_Element_Id     Number           := Null;
7730 		-- End: Added for CBS Enhancement Bug 16220146
7731 
7732    Begin
7733 
7734         G_Stage := 'Entering procedure RetrieveProjAttribution().';
7735         Pa_Otc_Api.TrackPath('ADD','RetrieveProjAttribution');
7736 
7737         found_billable := false;
7738 
7739         G_Stage := 'Entering attribute table loop.';
7740         Loop
7741 
7742 		     If j is null Then
7743 
7744 		          j := P_Attribute_Table.First;
7745 
7746 		     Else
7747 
7748 			      j := P_Attribute_Table.Next(j);
7749 
7750 		     End If;
7751 
7752 		     G_Stage := 'Looping thru attribute pl/sql table yanking out project attribution for current record.';
7753 		     If P_Attribute_Table(j).Building_Block_Id = P_Building_Block_Rec.Time_Building_Block_Id Then
7754 
7755                   If Upper(P_Attribute_Table(j).Attribute_Name) = 'PROJECT_ID' Then
7756 
7757 			           G_Stage := 'Get Project Id.';
7758                        project_index := j;
7759                        X_Proj_Attrib_Rec.Project_Id   := To_Number(P_Attribute_Table(j).Attribute_Value);
7760 				       G_Stage := 'Get Project Attribute Id.';
7761 				       X_Proj_Attrib_Rec.Proj_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
7762 				       -- X_Proj_Attrib_Rec.Proj_Attr_Ovn := P_Attribute_Table(j).Object_Version_Number;
7763 
7764 				       G_Stage := 'Check project  changed flag.';
7765                        If P_Attribute_Table(j).Changed <> 'N' Then
7766 				            X_Detail_Attr_Changed := 'Y';
7767 			           End If;
7768 
7769                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'TASK_ID' Then
7770 
7771 			           G_Stage := 'Get Task Id.';
7772                        X_Proj_Attrib_Rec.Task_Id      := To_Number(P_Attribute_Table(j).Attribute_Value);
7773 				       G_Stage := 'Get Task Attribute Id';
7774 				       X_Proj_Attrib_Rec.Task_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
7775 
7776                        G_Stage := 'Check task changed flag.';
7777                        If P_Attribute_Table(j).Changed <> 'N' Then
7778                             X_Detail_Attr_Changed := 'Y';
7779                        End If;
7780 
7781 				     -- Start: Added for CBS Enhancement Bug 16220146
7782 				     If X_Proj_Attrib_Rec.Project_Id Is Not Null And X_Proj_Attrib_Rec.Task_Id Is Not Null Then
7783 
7784 					    If PA_ALTERNATE_TASK_PVT.Is_Cbs_Enabled(X_Proj_Attrib_Rec.Project_Id) = 'Y' Then
7785 
7786 					       Begin
7787 
7788 						      Select Proj_Element_Id, Cbs_Element_Id
7789 							  Into l_Actual_Task_Id, l_Cbs_Element_Id
7790 							  From Pa_Alternate_Tasks
7791 							  Where Alt_Task_Id = X_Proj_Attrib_Rec.Task_Id;
7792 
7793 							  X_Proj_Attrib_Rec.Task_Id        := l_Actual_Task_Id;
7794 							  X_Proj_Attrib_Rec.Cbs_Element_Id := l_Cbs_Element_Id;
7795 
7796 						   Exception
7797 						      When Others Then
7798 						         l_Actual_Task_Id := Null;
7799 							     l_Cbs_Element_Id := Null;
7800 							     X_Proj_Attrib_Rec.Task_Id        := Null;
7801 							     X_Proj_Attrib_Rec.Cbs_Element_Id := Null;
7802 							     Raise;
7803 						   End;
7804 					    Else
7805 					       X_Proj_Attrib_Rec.Cbs_Element_Id := Null;
7806 					    End If;
7807 				     End If;
7808 				     -- End: Added for CBS Enhancement Bug 16220146
7809 
7810                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'EXPENDITURE_TYPE' Then
7811 
7812 			           G_Stage := 'Get Expenditure Type.';
7813                        X_Proj_Attrib_Rec.Expenditure_Type := P_Attribute_Table(j).Attribute_Value;
7814 				       G_Stage := 'Get Expenditure Type Attribute Id';
7815 				       X_Proj_Attrib_Rec.Exp_Type_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
7816 
7817                        G_Stage := 'Check expenditure_type changed flag.';
7818                        If P_Attribute_Table(j).Changed <> 'N' Then
7819                             X_Detail_Attr_Changed := 'Y';
7820                        End If;
7821 
7822                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'SYSTEM_LINKAGE_FUNCTION' Then
7823 
7824 			           G_Stage := 'Get Sys Link Func.';
7825                        X_Proj_Attrib_Rec.Sys_Linkage_Func := P_Attribute_Table(j).Attribute_Value;
7826 				       G_Stage := 'Get Sys Link Func Attribute Id.';
7827 				       X_Proj_Attrib_Rec.Sys_Link_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
7828 
7829                        G_Stage := 'Check sys link func changed flag.';
7830                        If P_Attribute_Table(j).Changed <> 'N' Then
7831                             X_Detail_Attr_Changed := 'Y';
7832                        End If;
7833 
7834                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'DUMMY PAEXPITDFF CONTEXT' Then
7835 
7836                        /* The value column contains the following format:
7837                         *   'PAEXPITDFF - <attribute_category>'
7838                         * So to get the attribute_category out will need to find the position
7839                         * for ' - ' that is: '<space>-<space>' and then add 3.
7840                         */
7841 
7842                        l_Attrib_Category := P_Attribute_Table(j).Attribute_Value;
7843 
7844                        /* Need to check for null to avoid the unecessary errors using instr
7845                         * avoiding unhandled exceptions.
7846                         */
7847                        If l_Attrib_Category is not null Then
7848 
7849 				            G_Stage := 'Get DFF Attribute Category.';
7850                             X_Proj_Attrib_Rec.Attrib_Category := substr(l_Attrib_Category, instr(l_Attrib_category,' - ') + 3);
7851 
7852                        End If;
7853 
7854                        G_Stage := 'Check Attribute Category changed flag.';
7855                        If P_Attribute_Table(j).Changed <> 'N' Then
7856                             X_Detail_Attr_Changed := 'Y';
7857                        End If;
7858 
7859                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE1' Then
7860 
7861 			           G_Stage := 'Get DFF Attribute 1.';
7862                        X_Proj_Attrib_Rec.Attribute1 := P_Attribute_Table(j).Attribute_Value;
7863 
7864                        G_Stage := 'Check DFF Attribute 1 changed flag.';
7865                        If P_Attribute_Table(j).Changed <> 'N' Then
7866                             X_Detail_Attr_Changed := 'Y';
7867                        End If;
7868 
7869                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE2' Then
7870 
7871 				       G_Stage := 'Get DFF Attribute 2.';
7872                        X_Proj_Attrib_Rec.Attribute2 := P_Attribute_Table(j).Attribute_Value;
7873 
7874                        G_Stage := 'Check DFF Attribute 2 changed flag.';
7875                        If P_Attribute_Table(j).Changed <> 'N' Then
7876                             X_Detail_Attr_Changed := 'Y';
7877                        End If;
7878 
7879                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE3' Then
7880 
7881 				       G_Stage := 'Get DFF Attribute 3.';
7882                        X_Proj_Attrib_Rec.Attribute3 := P_Attribute_Table(j).Attribute_Value;
7883 
7884                        G_Stage := 'Check DFF Attribute 3 changed flag.';
7885                        If P_Attribute_Table(j).Changed <> 'N' Then
7886                             X_Detail_Attr_Changed := 'Y';
7887                        End If;
7888 
7889                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE4' Then
7890 
7891 				       G_Stage := 'Get DFF Attribute 4.';
7892                        X_Proj_Attrib_Rec.Attribute4 := P_Attribute_Table(j).Attribute_Value;
7893 
7894                        G_Stage := 'Check DFF Attribute 4 changed flag.';
7895                        If P_Attribute_Table(j).Changed <> 'N' Then
7896                             X_Detail_Attr_Changed := 'Y';
7897                        End If;
7898 
7899                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE5' Then
7900 
7901 				       G_Stage := 'Get DFF Attribute 5.';
7902                        X_Proj_Attrib_Rec.Attribute5 := P_Attribute_Table(j).Attribute_Value;
7903 
7904                        G_Stage := 'Check DFF Attribute 5 changed flag.';
7905                        If P_Attribute_Table(j).Changed <> 'N' Then
7906 				            X_Detail_Attr_Changed := 'Y';
7907                        End If;
7908 
7909                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE6' Then
7910 
7911 				       G_Stage := 'Get DFF Attribute 6.';
7912                        X_Proj_Attrib_Rec.Attribute6 := P_Attribute_Table(j).Attribute_Value;
7913 
7914                        G_Stage := 'Check DFF Attribute 6 changed flag.';
7915                        If P_Attribute_Table(j).Changed <> 'N' Then
7916 				            X_Detail_Attr_Changed := 'Y';
7917                        End If;
7918 
7919                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE7' Then
7920 
7921 				       G_Stage := 'Get DFF Attribute 7.';
7922                        X_Proj_Attrib_Rec.Attribute7 := P_Attribute_Table(j).Attribute_Value;
7923 
7924                        G_Stage := 'Check DFF Attribute 7 changed flag.';
7925                        If P_Attribute_Table(j).Changed <> 'N' Then
7926                             X_Detail_Attr_Changed := 'Y';
7927                        End If;
7928 
7929                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE8' Then
7930 
7931 				       G_Stage := 'Get DFF Attribute 8.';
7932                        X_Proj_Attrib_Rec.Attribute8 := P_Attribute_Table(j).Attribute_Value;
7933 
7934                        G_Stage := 'Check DFF Attribute 8 changed flag.';
7935                        If P_Attribute_Table(j).Changed <> 'N' Then
7936                             X_Detail_Attr_Changed := 'Y';
7937                        End If;
7938 
7939                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE9' Then
7940 
7941 				       G_Stage := 'Get DFF Attribute 9.';
7942                        X_Proj_Attrib_Rec.Attribute9 := P_Attribute_Table(j).Attribute_Value;
7943 
7944                        G_Stage := 'Check DFF Attribute 9 changed flag.';
7945                        If P_Attribute_Table(j).Changed <> 'N' Then
7946                             X_Detail_Attr_Changed := 'Y';
7947                        End If;
7948 
7949                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PADFFATTRIBUTE10' Then
7950 
7951 				       G_Stage := 'Get DFF Attribute 10.';
7952                        X_Proj_Attrib_Rec.Attribute10 := P_Attribute_Table(j).Attribute_Value;
7953 
7954                        G_Stage := 'Check DFF Attribute 10 changed flag.';
7955                        If P_Attribute_Table(j).Changed <> 'N' Then
7956                             X_Detail_Attr_Changed := 'Y';
7957                        End If;
7958 
7959                   ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'BILLABLE_FLAG' Then
7960 
7961 				       G_Stage := 'Get Billable Flag Index value.';
7962                        X_Proj_Attrib_Rec.Billable_Flag_Index := j;
7963 
7964 				       G_Stage := 'Get Billable Flag.';
7965 				       X_Proj_Attrib_Rec.Billable_Flag := P_Attribute_Table(j).Attribute_Value;
7966 
7967 				       G_Stage := 'Get Billable Flag Attribute Id.';
7968 				       X_Proj_Attrib_Rec.Billable_Flag_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
7969 
7970 				       -- G_Stage := 'Get Billable Flag Attribute Ovn.';
7971 				       -- X_Proj_Attrib_Rec.Billable_Flag_Attr_Ovn := P_Attribute_Table(j).Object_Version_Number;
7972 
7973                        G_Stage := 'Found Billable Flag Attribute.';
7974                        found_billable := true;
7975 
7976 			      -- Begin CWK changes PA.M
7977 			      ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PO LINE ID' Then
7978 
7979 				       G_Stage := 'Get PO_Line Number.';
7980                        X_Proj_Attrib_Rec.Po_Line_Id := P_Attribute_Table(j).Attribute_Value;
7981 				       G_Stage := 'Get PO Line Id Attribute Id.';
7982 				       X_Proj_Attrib_Rec.PO_Line_Id_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
7983 
7984                        G_Stage := 'Check PO_Line Number change flag.';
7985                        If P_Attribute_Table(j).Changed <> 'N' Then
7986                             X_Detail_Attr_Changed := 'Y';
7987                        End If;
7988 
7989 			      ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'PO PRICE TYPE' Then
7990 
7991 				       G_Stage := 'Get Price Type.';
7992                        X_Proj_Attrib_Rec.PO_Price_Type := P_Attribute_Table(j).Attribute_Value;
7993 				       G_Stage := 'Get Price Type Attribute Id.';
7994 				       X_Proj_Attrib_Rec.PO_Price_Type_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
7995 
7996                        G_Stage := 'Check Price Type change flag.';
7997                        If P_Attribute_Table(j).Changed <> 'N' Then
7998                             X_Detail_Attr_Changed := 'Y';
7999                        End If;
8000 
8001 			      -- End CWK changes PA.M
8002                   -- Bug 10253400.. 12.2 payroll intg .. start
8003 			      ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'JOB_ID' Then
8004 
8005 				       G_Stage := 'Get Job ID';
8006                        X_Proj_Attrib_Rec.Job_Id := P_Attribute_Table(j).Attribute_Value;
8007 				       G_Stage := 'Get Job ID Attribute Id.';
8008 				       X_Proj_Attrib_Rec.Job_Id_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
8009 
8010                        G_Stage := 'Check Job ID change flag.';
8011                        If P_Attribute_Table(j).Changed <> 'N' Then
8012                             X_Detail_Attr_Changed := 'Y';
8013                        End If;
8014 
8015 			      ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'LOCATION_ID' Then
8016 
8017 				       G_Stage := 'Get Location ID';
8018                        X_Proj_Attrib_Rec.Location_Id := P_Attribute_Table(j).Attribute_Value;
8019 				       G_Stage := 'Get Location ID Attribute Id.';
8020 				       X_Proj_Attrib_Rec.Location_Id_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
8021 
8022                        G_Stage := 'Check Location ID change flag.';
8023                        If P_Attribute_Table(j).Changed <> 'N' Then
8024                             X_Detail_Attr_Changed := 'Y';
8025                        End If;
8026 			      ElsIf Upper(P_Attribute_Table(j).Attribute_Name) = 'WORKTYPE_ID' Then
8027 
8028 				       G_Stage := 'Get Work Type ID';
8029                        X_Proj_Attrib_Rec.Work_Type_Id := P_Attribute_Table(j).Attribute_Value;
8030 				       G_Stage := 'Get Work Type ID Attribute Id.';
8031 				       X_Proj_Attrib_Rec.Work_Type_Attr_Id := P_Attribute_Table(j).Time_Attribute_Id;
8032 
8033                        G_Stage := 'Check Work Type ID change flag.';
8034                        If P_Attribute_Table(j).Changed <> 'N' Then
8035                             X_Detail_Attr_Changed := 'Y';
8036                        End If;
8037 
8038                   End If;
8039                   -- Bug 10253400.. 12.2 payroll intg .. end
8040 		     End If;  -- The correct building block to pull data from.
8041 
8042 		     G_Stage := 'Exit loop check.';
8043 		     Exit When j = P_Attribute_Table.Last;
8044 
8045         End Loop;
8046 
8047         G_Stage := 'Check if found billable_flag.';
8048         If(NOT found_billable) Then
8049 
8050              --
8051              -- We must add the billable flag to the attribute structure, and set the values
8052              -- appropriately.  We permit the normal processing of the PA code to determine
8053              -- if this value should be changed.
8054              --
8055              G_Stage := 'Did not find billable_flag so get next available index.';
8056              billable_index := P_Attribute_Table.Last+1;
8057              --
8058              -- Find the billable segment name
8059              -- Cache it, since we don't want to issue the statement
8060              -- more than we need to, and the value should be session
8061              -- independent.
8062              --
8063              G_Stage := 'Check if already know the dff segment for the billable_flag.';
8064              If(G_Billable_Segment is null) then
8065 
8066                   G_Stage := 'Get the segment for the billable_flag from hxc table.';
8067                   select mc.segment
8068                   Into   G_Billable_Segment
8069                   from hxc_mapping_components mc,
8070                   hxc_bld_blk_info_types bbit
8071                   where mc.field_name = 'BILLABLE_FLAG'
8072                   and bbit.bld_blk_info_type_id = mc.bld_blk_info_type_id
8073                   and bbit.bld_blk_info_type = 'PROJECTS';
8074 
8075              End If;
8076 
8077              If project_index is not null then
8078                   --
8079                   -- Add the (null) value
8080                   -- the PROJECTS attribute is a seeded one, but is customizable by the customer.
8081                   --
8082                   G_Stage := 'Create the billable_flag attribute record.';
8083                   P_Attribute_Table(billable_index).time_attribute_id := P_Attribute_Table(project_index).time_attribute_id;
8084                   P_Attribute_Table(billable_index).building_block_id := P_Attribute_Table(project_index).building_block_id;
8085                   P_Attribute_Table(billable_index).attribute_name := 'BILLABLE_FLAG';
8086                   P_Attribute_Table(billable_index).attribute_value := null;
8087                   P_Attribute_Table(billable_index).attribute_index := P_Attribute_Table(project_index).attribute_index;
8088                   P_Attribute_Table(billable_index).segment := G_Billable_Segment;
8089                   P_Attribute_Table(billable_index).bld_blk_info_type := P_Attribute_Table(project_index).bld_blk_info_type;
8090                   P_Attribute_Table(billable_index).category := P_Attribute_Table(project_index).category;
8091                   P_Attribute_Table(billable_index).updated := 'N';
8092                   P_Attribute_Table(billable_index).changed := 'N';
8093                   --
8094                   -- Set internal Project attributes based on above value
8095                   --
8096                   X_Proj_Attrib_Rec.Billable_Flag_Index := billable_index;
8097                   X_Proj_Attrib_Rec.Billable_Flag := Null;
8098                   X_Proj_Attrib_Rec.Billable_Flag_Attr_Id := P_Attribute_Table(billable_index).Time_Attribute_Id;
8099 
8100              End If;
8101 
8102      End If; -- Did we find the billable flag?
8103 
8104 	 G_Stage := 'Get Expenditure Item Date using loop to grab from DAY scope record.';
8105 	 /* The Start Time column in the DETAIL scope record passed to this procedure will not be populated.
8106         So we must grab the Start Time column value from the DAY scope.  We will loop thru the same table
8107         containing the entire timecard and find the correct DAY scope record for the detail scope record that
8108         we are currently working on. */
8109 
8110 	 Loop
8111 
8112 	         If i is null Then
8113 
8114 		          i := P_Building_Block.First;
8115 
8116 		     Else
8117 
8118 			      i := P_Building_Block.Next(i);
8119 
8120 		     End If;
8121 
8122 		     G_Stage := 'Check if the current record is the correct DAY record to grab Exp Item Date from.';
8123 		     If P_Building_Block(i).Time_Building_Block_Id = P_Building_Block_Rec.Parent_Building_Block_Id and
8124 		        P_Building_Block(i).Scope = 'DAY' Then
8125 
8126 		          G_Stage := 'Grab the Exp Item Date and exit the loop.';
8127 			      X_Proj_Attrib_Rec.Expenditure_Item_Date := Trunc(P_Building_Block(i).Start_Time);
8128 			      Exit;
8129 
8130 		     End If;
8131 
8132      End Loop;
8133 
8134 	 G_Stage := 'Get Expenditure Ending Date.';
8135 	 X_Proj_Attrib_Rec.Exp_Ending_date := Pa_Utils.NewGetWeekEnding(X_Proj_Attrib_Rec.Expenditure_Item_Date);
8136 
8137 	 G_Stage := 'Get Unit of Measure.';
8138 	 X_Proj_Attrib_Rec.UOM := P_Building_Block_Rec.Unit_Of_Measure;
8139 
8140 	 G_Stage := 'Get Inc By Person Id.';
8141 	 X_Proj_Attrib_Rec.Inc_By_Person_Id := P_Building_Block_Rec.Resource_Id;
8142 
8143 	 G_Stage := 'Get the Quantity.';
8144 	 X_Proj_Attrib_Rec.Quantity := to_number(P_Building_Block_Rec.Measure);
8145 
8146 	 G_Stage := 'Get the Expenditure Item Comment.';
8147      /* Bug 2930551 Check for length and truncate if needed */
8148      -- begin bug 4926265
8149      -- If length(P_Building_Block_Rec.Comment_Text) > 240 Then
8150      If lengthb(P_Building_Block_Rec.Comment_Text) > 240 Then
8151 
8152           -- X_Proj_Attrib_Rec.Expenditure_Item_Comment := substr(P_Building_Block_Rec.Comment_Text,1,240);
8153           X_Proj_Attrib_Rec.Expenditure_Item_Comment := substrb(P_Building_Block_Rec.Comment_Text,1,240);
8154           -- end bug 4926265
8155 
8156      Else
8157 
8158           X_Proj_Attrib_Rec.Expenditure_Item_Comment := P_Building_Block_Rec.Comment_Text;
8159 
8160      End If;
8161 
8162 	 -- Beging CWK changes PA.M
8163 	 G_Stage := 'Get Person_Type.';
8164 	 X_Proj_Attrib_Rec.Person_Type := Pa_Otc_Api.GetPersonType(
8165                                               P_Person_Id => X_Proj_Attrib_Rec.Inc_By_Person_Id,
8166 						                      P_Ei_Date   => X_Proj_Attrib_Rec.Expenditure_Item_Date);
8167 
8168 
8169 	 If X_Proj_Attrib_Rec.Person_Type = 'CWK' And X_Proj_Attrib_Rec.Po_Line_Id Is Not Null Then
8170 
8171 	      G_Stage := 'Get PO Info.';
8172 		  PA_Otc_Api.GetPOInfo(
8173                   P_PO_Line_Id   => X_Proj_Attrib_Rec.Po_Line_Id,
8174 			      X_PO_Header_Id => X_Proj_Attrib_Rec.PO_Header_Id,
8175 			      X_Vendor_Id    => X_Proj_Attrib_Rec.Vendor_Id);
8176 
8177 	 End If;
8178 
8179 	 -- End CWK changes PA.M
8180 	 G_Stage := 'Leaving procedure RetrieveProjAttribution().';
8181 	 Pa_Otc_Api.TrackPath('STRIP','RetrieveProjAttribution');
8182 
8183    Exception
8184 	    When Others Then
8185 	         Raise;
8186 
8187    End RetrieveProjAttribForUpd;
8188 
8189 -- ========================================================================
8190 -- Start Of Comments
8191 -- API Name      : GetPRMAssignTemplates
8192 -- Type          : Public
8193 -- Pre-Reqs      : None
8194 -- Type          : Procedure
8195 -- Return        : n/a
8196 -- Function      : This procedure is used to pull from PRM the Forecast Assignment data and provide
8197 --                 it as template data for OTL.  It will not have TASK information in it.  It will
8198 --                 be placed in OTL friendly format for the OTL team to populate the current timecard
8199 --                 with the Forecast Assignment data.  Validation for expenditure_type and system_linkage_function
8200 --                 combinations will take place within the code before passing it to OTL.  Any combo that
8201 --                 is not valid for the day in question will not be pulled over.
8202 --
8203 -- Parameters    :
8204 -- IN            P_Resource_Id - Hxc_Time_Building_Blocks.Resource_Id%TYPE
8205 --               P_Start_Date  - Hxc_Time_Building_Blocks.Start_Time%TYPE
8206 --               P_Stop_Date   - Hxc_Time_Building_Blocks.Stop_Time%TYPE
8207 -- OUT
8208 --               P_Attributes  - Varchar2
8209 --               P_Timecard    - Varchar2
8210 --               P_Messages    - Varchar2
8211 
8212 
8213 /*--------------------------------------------------------------------------*/
8214 
8215    Procedure GetPRMAssignTemplates(
8216                 P_Resource_Id IN         Hxc_Time_Building_Blocks.Resource_Id%TYPE,
8217                 P_Start_Date  IN         Hxc_Time_Building_Blocks.Start_Time%TYPE,
8218                 P_Stop_Date   IN         Hxc_Time_Building_Blocks.Stop_Time%TYPE,
8219                 P_Attributes  OUT NOCOPY Varchar2,
8220                 P_Timecard    OUT NOCOPY Varchar2,
8221                 P_Messages    OUT NOCOPY Varchar2)
8222 
8223    Is
8224 
8225 	l_BB_Index                Binary_Integer := 0;
8226 	l_Attrib_Index            Binary_Integer := 0;
8227 	l_Time_Building_Block_Id  Number := 1;
8228 	l_Day_Parent_BB_Id        Number := Null;
8229 	l_Org_Id                  Number := Null;
8230 	l_Valid_ExpTypClass_Combo Varchar2(1) := Null;
8231 	l_Val_Proj_Flag           Varchar2(1) := Null;
8232 
8233 	l_Building_Blocks_Table Hxc_User_Type_Definition_Grp.Timecard_Info;
8234 	l_Attribute_Table       Hxc_User_Type_Definition_Grp.App_Attributes_info;
8235 	l_Message_Table         Hxc_User_Type_Definition_Grp.Message_Table;
8236 
8237 	l_dummy_bb_Table        Hxc_User_Type_Definition_Grp.Timecard_Info;
8238 	l_dummy_Attrib_Table    Hxc_User_Type_Definition_Grp.App_Attributes_info;
8239 
8240 	/* If the profile value is NULL or 'N' then we want to retrieve all the records
8241 	 * irregardless of the value stored in column Provisional_Flag.
8242 	 * If the profile value is 'Y' then we only want to retrieve those records
8243 	 * where column Provisional_Flag = 'Y'.
8244 	 */
8245 /* Begin bug 5011267
8246     Cursor PRMAssignments(
8247         P_Emp_Id      IN Number,
8248 		P_Start_Date  IN Date,
8249 		P_Stop_Date   IN Date,
8250 		P_Exp_Org_Id  IN Number) is
8251 	Select
8252 		FI.Project_Id,
8253 		P.Segment1,
8254 		FI.Item_Date,
8255 		FI.Expenditure_Type,
8256 		FI.Expenditure_Type_Class,
8257 		FI.Item_Quantity
8258 	From
8259 		Pa_Forecast_Items FI,
8260 		Pa_Projects_All P,
8261 		Pa_Project_Assignments PPA
8262 	Where
8263 		Person_Id = P_Emp_Id
8264 	And	Item_Date Between P_Start_Date
8265 	                      And P_Stop_Date
8266 	And Forecast_Item_Type in ('A','U')
8267     And FI.Project_Id = P.Project_Id
8268 	And PPA.assignment_id = FI.assignment_id
8269 	And FI.delete_flag = 'N'
8270 	And Nvl(FI.expenditure_org_id,-99) = Nvl(P_Exp_Org_Id,-99)
8271 	And Nvl(FI.Item_Quantity,0) <> 0
8272     Order by 2,4,3; -- project/exp_type/item_date
8273     */
8274 
8275     /* Begin Bug 5366183
8276     Cursor PRMAssignments(
8277             P_Emp_Id      IN Number,
8278             P_Start_Date  IN Date,
8279             P_Stop_Date   IN Date,
8280             P_Exp_Org_Id  IN Number) is
8281     Select
8282             FI.Project_Id,
8283             P.Segment1,
8284             FI.Item_Date,
8285             FI.Expenditure_Type,
8286             FI.Expenditure_Type_Class,
8287             FI.Item_Quantity
8288     From
8289             Pa_Forecast_Items FI,
8290             Pa_Projects_All P
8291     Where
8292             Person_Id = P_Emp_Id
8293     And Item_Date Between P_Start_Date
8294                       And P_Stop_Date
8295     And Forecast_Item_Type = 'A'
8296     And FI.Project_Id = P.Project_Id
8297     And FI.delete_flag = 'N'
8298     And FI.expenditure_org_id = P_Exp_Org_Id
8299     And FI.Item_Quantity <> 0
8300     Order by 2,4,3; -- project/exp_type/item_date
8301     */
8302     /* End bug 5011267 */
8303 
8304     Cursor PRMAssignments(
8305                     P_Emp_Id      IN Number,
8306                     P_Start_Date  IN Date,
8307                     P_Stop_Date   IN Date,
8308                     P_Exp_Org_Id  IN Number) is
8309     Select
8310             FI.Project_Id,
8311             P.Segment1,
8312             FI.Item_Date,
8313             FI.Expenditure_Type,
8314             FI.Expenditure_Type_Class,
8315             FI.Item_Quantity
8316     From
8317             Pa_Forecast_Items FI,
8318             Pa_Projects_All P,
8319             Pa_Resource_Txn_Attributes PTA
8320     Where
8321             PTA.Person_Id = P_Emp_Id
8322     And FI.Resource_id = PTA.Resource_id
8323     And FI.Item_Date Between P_Start_Date
8324                      And P_Stop_Date
8325     And FI.Forecast_Item_Type = 'A'
8326     And FI.Project_Id = P.Project_Id
8327     And FI.delete_flag = 'N'
8328     And FI.expenditure_org_id = P_Exp_Org_Id
8329     And FI.Item_Quantity <> 0
8330     Order by 2,4,3; -- project/exp_type/item_date
8331     /* End bug 5366183 */
8332 
8333    	/* Expenditure_Type_Class is the system_linkage_function */
8334 	--  Cursor ValidateExpTypeAndClass (P_Exp_Item_Date  IN Date,
8335     -- 					P_Exp_Type       IN Varchar2,
8336     -- 					P_Exp_Type_Class IN Varchar2) Is
8337     -- 	Select
8338     -- 		'Y'
8339     -- 	From
8340     -- 		Pa_Online_Expenditure_Types_V
8341     -- 	Where
8342     -- 		Expenditure_Type = P_Exp_Type
8343     -- 	And     System_Linkage_Function = P_Exp_Type_Class
8344     -- 	And     Trunc(P_Exp_Item_Date) Between Expnd_Typ_Start_Date_Active
8345     -- 					   And nvl(Expnd_Typ_End_Date_Active, P_Exp_Item_Date)
8346     -- 	And     Trunc(P_Exp_Item_Date) Between Sys_Link_Start_Date_Active
8347     -- 					   And nvl(Sys_Link_End_Date_Active, P_Exp_Item_Date);
8348 
8349 	PRMAssignRecs  PRMAssignments%ROWTYPE;
8350 
8351 	-- Cursor ValidateProject ( P_Project_Id IN Pa_Projects_All.Project_Id%TYPE ) Is
8352 	-- Select
8353 	-- 	'Y'
8354 	-- From
8355 	-- 	Pa_Online_Projects_V
8356 	-- Where
8357     -- 	Project_Id = P_Project_Id;
8358 
8359    	TYPE Day_Rec IS Record (
8360         	Day_Index_Number Binary_Integer,
8361         	Date_for_Day     Date);
8362 
8363    	TYPE Day_Table IS Table OF Day_Rec
8364         	INDEX BY Binary_Integer;
8365 
8366    	l_Day_Table       Day_Table;
8367 	l_Days_in_Period  Number := 0;
8368 
8369 
8370    Begin
8371 
8372 	G_Path := ' ';
8373 
8374     G_Stage := 'Entering procedure GetPRMAssignTemplates().';
8375     Pa_Otc_Api.TrackPath('ADD','GetPRMAssignTemplates');
8376 
8377 	G_Stage := 'Initialize the pl/sql message table.';
8378 	l_Message_Table.Delete;
8379     l_Building_Blocks_Table.Delete;
8380     l_Attribute_Table.Delete;
8381     l_dummy_bb_Table.Delete;
8382     l_dummy_Attrib_Table.Delete;
8383 
8384     /* Begin Bug 3766110
8385       There is no reason to do any validation in building the template data
8386       since the data will get validated when the OTL user submits the timecard.
8387 
8388 	  -- The default period length for a timecard is a week for Projects OTL timecards.
8389 	  -- But that can be changed.  If the default is kept, then we want to make sure that
8390 	  -- the week ending date is consistant with Projects implementation.
8391 
8392 	  l_Days_in_Period := Trunc(P_Stop_Date) - Trunc(P_Start_Date) + 1;
8393 
8394 	  G_Stage := 'Checking start and end dates.  Check if OTL using week long timecards.';
8395       If l_Days_in_Period = 7 Then
8396 
8397 		G_Stage := 'Checking end the Stop_Date passed in matches WeekEnding dates in Projects.';
8398         If Pa_Utils.NewGetWeekEnding(Trunc(P_Stop_Date)) <> Trunc(P_Stop_Date) Then
8399 
8400              G_Msg_Tokens_Table.Delete;
8401 
8402              -- Add record to error table.
8403              Pa_Otc_Api.Add_Error_To_Table(
8404                    P_Message_Table           => l_Message_Table,
8405                    P_Message_Name            => 'PA_INVALID_WEEK_ENDING_DATE',
8406                    P_Message_Level           => 'ERROR',
8407                    P_Message_Field           => Null,
8408                    P_Msg_Tokens              => G_Msg_Tokens_Table,
8409                    P_Time_Building_Block_Id  => Null,
8410                    P_Time_Attribute_Id       => Null);
8411 
8412        	End If;
8413 
8414 	End If;
8415 
8416     End bug 3766110 */
8417 
8418     l_Days_in_Period := Trunc(P_Stop_Date) - Trunc(P_Start_Date) + 1;
8419 
8420     /* Begin bug 3766110
8421 	G_Stage := 'If messages now exist in pl/sql table then do not do any further processing.  OTL not properly setup.';
8422 	If l_Message_Table.Count = 0 Then
8423     End bug 3766110 */
8424 
8425 		G_Stage := 'Assigning null dummy tables to the BB and Attribution pl/sql tables. ';
8426 		l_Building_Blocks_Table := l_dummy_BB_Table;
8427 		l_Attribute_Table       := l_dummy_Attrib_Table;
8428 
8429 		G_Stage := 'Check Multi Org';
8430 		If Pa_Utils.Pa_Morg_Implemented = 'Y' Then
8431 
8432 			l_Org_Id := Fnd_Profile.Value('ORG_ID');
8433 
8434 		End If;
8435 
8436 		-- Insert Timecard Scope record
8437 		G_Stage := 'Build/Insert Timecard Scope BB record.';
8438 		l_BB_Index := l_BB_Index + 1;
8439 		l_Building_Blocks_Table(l_BB_Index).Resource_Id := P_Resource_Id;
8440 		l_Building_Blocks_Table(l_BB_Index).Start_Time := P_Start_Date;
8441 		l_Building_Blocks_Table(l_BB_Index).Stop_Time := P_Stop_Date;
8442 		l_Building_Blocks_Table(l_BB_Index).Scope := 'TIMECARD';
8443 		l_Building_Blocks_Table(l_BB_Index).Date_From := SysDate;
8444 		l_Building_Blocks_Table(l_BB_Index).Date_To := Hr_General.End_Of_Time;
8445 		l_Building_Blocks_Table(l_BB_Index).New := 'Y';
8446 		l_Building_Blocks_Table(l_BB_Index).Resource_Type := 'PERSON';
8447 		l_Building_Blocks_Table(l_BB_Index).Type := 'RANGE';
8448 		l_Building_Blocks_Table(l_BB_Index).Parent_Building_Block_Id := Null;
8449 		l_Building_Blocks_Table(l_BB_Index).Parent_Building_Block_Ovn := Null;
8450 		l_Building_Blocks_Table(l_BB_Index).Approval_Status := 'WORKING';
8451 		l_Building_Blocks_Table(l_BB_Index).Approval_Style_Id := Null;
8452 		l_Building_Blocks_Table(l_BB_Index).Time_Building_Block_Id := l_Time_Building_Block_Id;
8453 		l_Building_Blocks_Table(l_BB_Index).Object_Version_Number := 1;
8454 		l_Building_Blocks_Table(l_BB_Index).Comment_Text := Null;
8455 		l_Building_Blocks_Table(l_BB_Index).Measure := Null;
8456 		l_Building_Blocks_Table(l_BB_Index).Unit_Of_Measure := Null;
8457 
8458 
8459 		-- Insert Day Scope records.
8460 		G_Stage := 'Build/Insert day scope records using loop based on the number of days in timecard period.';
8461 		For i in 1 .. l_Days_in_Period
8462 		loop
8463 
8464         		G_Stage := 'Create Day Scope Record 1.';
8465         		l_BB_Index := l_BB_Index + 1;
8466         		l_Time_Building_Block_Id := l_Time_Building_Block_Id + 1;
8467 
8468         		l_Building_Blocks_Table(l_BB_Index).Resource_Id := P_Resource_Id;
8469         		l_Building_Blocks_Table(l_BB_Index).Start_Time := P_Start_Date + i - 1;
8470         		l_Building_Blocks_Table(l_BB_Index).Stop_Time := P_Start_Date + i - 1;
8471         		l_Building_Blocks_Table(l_BB_Index).Scope := 'DAY';
8472         		l_Building_Blocks_Table(l_BB_Index).Date_From := SysDate;
8473         		l_Building_Blocks_Table(l_BB_Index).Date_To := Hr_General.End_Of_Time;
8474         		l_Building_Blocks_Table(l_BB_Index).New := 'Y';
8475         		l_Building_Blocks_Table(l_BB_Index).Resource_Type := 'PERSON';
8476         		l_Building_Blocks_Table(l_BB_Index).Type := 'RANGE';
8477         		l_Building_Blocks_Table(l_BB_Index).Parent_Building_Block_Id := 1;
8478         		l_Building_Blocks_Table(l_BB_Index).Parent_Building_Block_Ovn := 1;
8479         		l_Building_Blocks_Table(l_BB_Index).Approval_Status := 'WORKING';
8480         		l_Building_Blocks_Table(l_BB_Index).Approval_Style_Id := Null;
8481         		l_Building_Blocks_Table(l_BB_Index).Time_Building_Block_Id := l_Time_Building_Block_Id;
8482         		l_Building_Blocks_Table(l_BB_Index).Object_Version_Number := 1;
8483         		l_Building_Blocks_Table(l_BB_Index).Comment_Text := Null;
8484         		l_Building_Blocks_Table(l_BB_Index).Measure := Null;
8485         		l_Building_Blocks_Table(l_BB_Index).Unit_Of_Measure := Null;
8486 
8487 			l_Day_Table(i).Day_Index_Number := l_BB_Index;
8488 			l_Day_Table(i).Date_for_Day := l_Building_Blocks_Table(l_BB_Index).Start_Time;
8489 
8490 		End Loop;
8491 
8492 		-- Create Detail Scope Records as appropriate
8493         G_Stage := 'Open cursor PRMAssignments to get detail scope data.';
8494         Open PRMAssignments (
8495 			     P_Emp_Id     => P_Resource_Id,
8496 			     P_Start_Date => P_Start_Date,
8497 			     P_Stop_Date  => P_Stop_Date,
8498 			     P_Exp_Org_Id => l_Org_Id);
8499 
8500         G_Stage := 'Start Loop for cursor PRMAssignments.';
8501         Loop
8502 
8503 			G_Stage := 'Fetch forecast assignment record into record.';
8504 			Fetch PRMAssignments into PRMAssignRecs;
8505 			Exit When PRMAssignments%NotFound;
8506 
8507             /* Begin bug 3766110
8508               There is no reason to do any validation in building the template data
8509               since the data will get validated when the OTL user submits the timecard.
8510 
8511 			  Check if the expenditure and system_linkage_function combo is valid for the
8512 			  date in question.
8513 
8514 			l_Valid_ExpTypClass_Combo := 'N';
8515 
8516 			G_Stage := 'Validate Expenditure_Type/Expenditure_Type_Class, open cursor.';
8517 			Open ValidateExpTypeAndClass(
8518 					     PRMAssignRecs.Item_Date,
8519 					     PRMAssignRecs.Expenditure_Type,
8520 					     PRMAssignRecs.Expenditure_Type_Class);
8521 
8522 			G_Stage := 'Validate Expenditure_Type/Expenditure_Type_Class, fetch cursor data.';
8523 			Fetch ValidateExpTypeAndClass Into l_Valid_ExpTypClass_Combo;
8524 
8525 			G_Stage := 'Validate Expenditure_Type/Expenditure_Type_Class, close cursor.';
8526 			Close ValidateExpTypeAndClass;
8527 
8528 			l_Val_Proj_Flag := 'N';
8529 
8530 			G_Stage := 'Validate Project, open cursor.';
8531 			Open ValidateProject(PRMAssignRecs.Project_Id);
8532 
8533 			G_Stage := 'Validate Project, fetch cursor data.';
8534 			Fetch ValidateProject Into l_Val_Proj_Flag;
8535 
8536 			G_Stage := 'Validate Project, close cursor.';
8537 			Close ValidateProject;
8538 
8539 			If l_Valid_ExpTypClass_Combo = 'Y' and l_Val_Proj_Flag = 'Y' Then
8540             */
8541             -- End bug 3766110
8542 
8543 				G_Stage := 'Building and insert detail scope record.';
8544 
8545 				l_BB_Index := l_BB_Index + 1;
8546 				l_Time_Building_Block_Id := l_Time_Building_Block_Id + 1;
8547 
8548 				<<Day_Loop>>
8549 				For p in l_Day_Table.FIRST .. l_Day_Table.LAST
8550 				Loop
8551 
8552 					If l_Day_Table(p).Date_For_Day = PRMAssignRecs.Item_Date Then
8553 
8554 						l_Day_Parent_BB_Id := l_Day_Table(p).Day_Index_Number;
8555 						Exit Day_Loop;
8556 
8557 					End If;
8558 
8559 				End Loop Day_Loop;
8560 
8561                 l_Building_Blocks_Table(l_BB_Index).Resource_Id := P_Resource_Id;
8562                 l_Building_Blocks_Table(l_BB_Index).Start_Time := Null;
8563                 l_Building_Blocks_Table(l_BB_Index).Stop_Time := Null;
8564                 l_Building_Blocks_Table(l_BB_Index).Scope := 'DETAIL';
8565                 l_Building_Blocks_Table(l_BB_Index).Date_From := SysDate;
8566                 l_Building_Blocks_Table(l_BB_Index).Date_To := Hr_General.End_Of_Time;
8567                 l_Building_Blocks_Table(l_BB_Index).New := 'Y';
8568                 l_Building_Blocks_Table(l_BB_Index).Resource_Type := 'PERSON';
8569                 l_Building_Blocks_Table(l_BB_Index).Type := 'MEASURE';
8570 				l_Building_Blocks_Table(l_BB_Index).Parent_Building_Block_Id := l_Day_Parent_BB_Id;
8571 				l_Building_Blocks_Table(l_BB_Index).Parent_Building_Block_Ovn := 1;
8572 				l_Building_Blocks_Table(l_BB_Index).Approval_Status := 'WORKING';
8573 				l_Building_Blocks_Table(l_BB_Index).Approval_Style_Id := Null;
8574                 l_Building_Blocks_Table(l_BB_Index).Time_Building_Block_Id := l_Time_Building_Block_Id;
8575                 l_Building_Blocks_Table(l_BB_Index).Object_Version_Number := 1;
8576                 l_Building_Blocks_Table(l_BB_Index).Comment_Text := Null;
8577                 l_Building_Blocks_Table(l_BB_Index).Measure := PRMAssignRecs.Item_Quantity;
8578                 l_Building_Blocks_Table(l_BB_Index).Unit_Of_Measure := 'HOURS';
8579 
8580 				-- Create Detail Scope Attribution
8581 
8582 				G_Stage := 'Building and insert detail scope attribution records.';
8583 				-- Project Id
8584 
8585 				G_Stage := 'Building and insert detail scope attribution record project_Id.';
8586 				l_Attrib_Index := l_Attrib_Index + 1;
8587 
8588                 l_Attribute_Table(l_Attrib_Index).Time_Attribute_Id := l_Time_Building_Block_Id;
8589                 l_Attribute_Table(l_Attrib_Index).Building_Block_Id := l_Time_Building_Block_Id;
8590                 l_Attribute_Table(l_Attrib_Index).Attribute_Name := 'Project_Id';
8591                 l_Attribute_Table(l_Attrib_Index).Attribute_Value := PRMAssignRecs.Project_Id;
8592                 l_Attribute_Table(l_Attrib_Index).Updated := 'N';
8593                 l_Attribute_Table(l_Attrib_Index).Bld_Blk_Info_Type := 'PROJECTS';
8594 				l_Attribute_Table(l_Attrib_Index).Category := 'PROJECTS';
8595 
8596 				-- Expenditure Type
8597 
8598 				G_Stage := 'Building and insert detail scope attribution record Expenditure Type.';
8599 				l_Attrib_Index := l_Attrib_Index + 1;
8600 
8601                 l_Attribute_Table(l_Attrib_Index).Time_Attribute_Id := l_Time_Building_Block_Id;
8602                 l_Attribute_Table(l_Attrib_Index).Building_Block_Id := l_Time_Building_Block_Id;
8603                 l_Attribute_Table(l_Attrib_Index).Attribute_Name := 'Expenditure_Type';
8604                 l_Attribute_Table(l_Attrib_Index).Attribute_Value := PRMAssignRecs.Expenditure_Type;
8605                 l_Attribute_Table(l_Attrib_Index).Updated := 'N';
8606                 l_Attribute_Table(l_Attrib_Index).Bld_Blk_Info_Type := 'PROJECTS';
8607 				l_Attribute_Table(l_Attrib_Index).Category := 'PROJECTS';
8608 
8609 				-- System Linkage Function
8610 
8611 				G_Stage := 'Building and insert detail scope attribution record Expenditure_Type_Class.';
8612 				l_Attrib_Index := l_Attrib_Index + 1;
8613 
8614                 l_Attribute_Table(l_Attrib_Index).Time_Attribute_Id := l_Time_Building_Block_Id;
8615                 l_Attribute_Table(l_Attrib_Index).Building_Block_Id := l_Time_Building_Block_Id;
8616                 l_Attribute_Table(l_Attrib_Index).Attribute_Name := 'SYSTEM_LINKAGE_FUNCTION';
8617                 l_Attribute_Table(l_Attrib_Index).Attribute_Value := PRMAssignRecs.Expenditure_Type_Class;
8618                 l_Attribute_Table(l_Attrib_Index).Updated := 'N';
8619                 l_Attribute_Table(l_Attrib_Index).Bld_Blk_Info_Type := 'PROJECTS';
8620 				l_Attribute_Table(l_Attrib_Index).Category := 'PROJECTS';
8621 
8622             /* Begin bug 3766110
8623 			Else
8624 
8625 				G_Msg_Tokens_Table.Delete;
8626 
8627 				If l_Val_Proj_Flag = 'N' Then
8628 
8629 					G_Stage := 'Create error message for Invalid Project in PRM Template.';
8630 					Pa_Otc_Api.Add_Error_To_Table(
8631                   		P_Message_Table           => l_Message_Table,
8632                   		P_Message_Name            => 'INVALID_PROJECT',
8633                   		P_Message_Level           => 'ERROR',
8634                   		P_Message_Field           => 'Project_Id',
8635                   		P_Msg_Tokens              => G_Msg_Tokens_Table,
8636                   		P_Time_Building_Block_Id  => Null,
8637                   		P_Time_Attribute_Id       => Null);
8638 
8639 				End If;
8640 
8641 				If l_Valid_ExpTypClass_Combo = 'N' Then
8642 
8643 					G_Stage := 'Create error message for Invalid Exp Type/Sys ' ||
8644 					           'Link func in PRM Template.';
8645                     Pa_Otc_Api.Add_Error_To_Table(
8646                          P_Message_Table           => l_Message_Table,
8647                          P_Message_Name            => 'INVALID_ETYPE_SYSLINK',
8648                          P_Message_Level           => 'ERROR',
8649                          P_Message_Field           => 'Expenditure_Type',
8650                          P_Msg_Tokens              => G_Msg_Tokens_Table,
8651                          P_Time_Building_Block_Id  => Null,
8652                          P_Time_Attribute_Id       => Null);
8653 
8654 				End If;
8655 
8656 			End If; -- Valid ExpTypeClass Combo
8657             */
8658             -- End bug 3766110
8659 
8660 		End Loop; -- Cursor with the data from PRM Assignment forecast data.
8661 
8662 		G_Stage := 'Closing cursor PRMAssignments.';
8663 		Close PRMAssignments;
8664 
8665 	-- End If; Bug 3766110
8666 
8667 
8668 	-- The building blocs table will at least have the timecard scope record and the 7 day scope records
8669 	-- so there must be more than 8 records in the pl/sql table to determine if there is data to send back to OTL.
8670 	-- There cannot be any records in the message table as that would mean error and don't want to pass
8671     -- back a partial set of building blocks.
8672 	If l_Building_Blocks_Table.Count > 1 Then -- and l_Message_Table.Count = 0 Then bug 3766110
8673 
8674 		G_Stage := 'Convert Building Blocks pl/sql table to varchar2.';
8675 		P_Timecard := Hxc_Integration_Layer_V1_Grp.Blocks_To_String( P_Blocks => l_Building_Blocks_Table );
8676 
8677 		G_Stage := 'Convert Attribution pl/sql table to varchar2.';
8678 		P_Attributes := Hxc_Integration_Layer_V1_Grp.Attributes_To_String ( P_Attributes => l_Attribute_Table );
8679 
8680 	End If;
8681 
8682     -- Begin bug 3766110
8683 
8684 	-- If l_Message_Table.Count > 0 Then
8685 
8686 	--     G_Stage := 'Convert Message pl/sql table to varchar2.';
8687 	-- 	P_Messages := Hxc_Integration_Layer_V1_Grp.Messages_to_String ( P_Messages => l_Message_Table );
8688 
8689 	-- End If;
8690 
8691     -- End Bug 3766110
8692 
8693     G_Stage := 'Leaving procedure GetPRMAssignTemplates().';
8694     Pa_Otc_Api.TrackPath('STRIP','GetPRMAssignTemplates');
8695 
8696    Exception
8697 	When Others then
8698 		Raise_Application_Error(-20007,'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage || ' : ' || SQLERRM);
8699 
8700    End GetPRMAssignTemplates;
8701 
8702 -- ========================================================================
8703 -- Start Of Comments
8704 -- API Name      : FindandValidateHeader
8705 -- Type          : Private
8706 -- Pre-Reqs      : None
8707 -- Type          : Procedure
8708 -- Return        : n/a
8709 -- Function      : This procedure finds and validate the Timecard Header record.
8710 --                 This procedure is only called when Mode is VALIDATE.
8711 --
8712 -- Parameters    :
8713 -- IN
8714 --           P_Building_Blocks_Table  - Hxc_User_Type_Definition_Grp.Timecard_Info
8715 --           P_Attribute_Table        - Hxc_User_Type_Definition_Grp.App_Attributes_Info
8716 --           P_Message_Table          - Hxc_User_Type_Definition_Grp.Message_Table
8717 -- OUT
8718 --           P_Message_Table          - Hxc_User_Type_Definition_Grp.Message_Table
8719 --           X_TimeBB_Id              - Hxc_Time_Building_Blocks.Time_Building_Block_Id%TYPE
8720 --           X_Ovr_Approver_Person_Id - Pa_Expenditures_All.Overriding_Approver_Person_Id%TYPE
8721 --           X_Timecard_Ending_Date   - Date
8722 
8723 /*--------------------------------------------------------------------------*/
8724 
8725 
8726    Procedure FindandValidateHeader(
8727 			P_Building_Blocks_Table  IN            Hxc_User_Type_Definition_Grp.Timecard_Info,
8728                         P_Attribute_Table        IN            Hxc_User_Type_Definition_Grp.App_Attributes_Info,
8729 			P_Message_Table          IN OUT NOCOPY Hxc_User_Type_Definition_Grp.Message_Table, -- 2672653
8730                         X_TimeBB_Id                 OUT NOCOPY Hxc_Time_Building_Blocks.Time_Building_Block_Id%TYPE,
8731 			X_Ovr_Approver_Person_Id    OUT NOCOPY Pa_Expenditures_All.Overriding_Approver_Person_Id%TYPE,
8732 			X_Pass_Val_Flag             OUT NOCOPY Varchar2,
8733 			X_Approval_Status           OUT NOCOPY Hxc_Time_Building_Blocks.Approval_Status%TYPE)
8734 
8735    Is
8736 
8737 	l_Error_Code      Varchar2(30)   := Null;
8738 	l_Error_Type      Varchar2(30)   := Null;
8739 
8740 	l_Pass_Val_Flag   Varchar2(1)    := 'Y';
8741 	l_TimeBB_Ovn      Number         := Null;
8742 	i                 Binary_Integer := Null;
8743 	x		  Binary_Integer := Null;
8744 	l_Found           Boolean        := Null;
8745         l_pref_table  hxc_preference_evaluation.t_pref_table;
8746         l_period_type varchar2(50);/* bug 5890771 */
8747 	l_termination_date Date := Null; /* Added the variable for bug 7584432 */
8748         l_assign_end_date_flag Number := 0; /* Added the variable for bug 8528840 */
8749 
8750 	 cursor check_tc_period (p_rec_id number) is
8751 	     select hrp.period_type
8752 	       from hxc_recurring_periods hrp
8753 	      where hrp.recurring_period_id = p_rec_id;
8754       /* Added the cursor for bug 7584432 */
8755 	      Cursor get_termination_date(p_person_id number, p_stop_date DATE) is
8756 	      Select max(effective_end_date) from per_people_f
8757 	      where person_id = p_person_id and
8758 	      effective_end_date <= p_stop_date and
8759 	      (current_employee_flag = 'Y' or current_npw_flag = 'Y');
8760 
8761             /* Added the cursor for bug 8528840 */
8762               Cursor is_assignment_end_date(p_person_id number, p_stop_date DATE) is
8763               Select '1' from per_assignments_f where
8764               person_id = p_person_id and
8765               trunc(p_stop_date) + 1 between effective_start_date and effective_end_date
8766               and  assignment_status_type_id in (select assignment_status_type_id
8767               from PER_ASSIGNMENT_STATUS_TYPES where per_system_status = 'SUSP_ASSIGN');
8768 
8769 
8770    Begin
8771 
8772         G_Stage := 'Entering FindandValidateHeader procedure.';
8773         Pa_Otc_Api.TrackPath('ADD','FindandValidateHeader');
8774 
8775         Loop
8776 
8777 	        If i is Null Then
8778 
8779 			     i := P_Building_Blocks_Table.First;
8780 
8781 		    Else
8782 
8783 			     i := P_Building_Blocks_Table.Next(i);
8784 
8785 		    End If;
8786 
8787 		    G_Stage := 'Get the Time Scope Building Block Id.';
8788 		    If P_Building_Blocks_Table(i).Scope = 'TIMECARD' Then
8789 		       /* bug 5890771*/
8790                   hxc_preference_evaluation.resource_preferences(
8791                    p_resource_id   =>  P_Building_Blocks_Table(i).resource_id
8792            ,       p_pref_code_list=> 'TC_W_TCRD_PERIOD'
8793            ,       p_pref_table    => l_pref_table );
8794 
8795 		   open check_tc_period(l_pref_table(l_pref_table.first).attribute1);
8796 	           fetch check_tc_period into l_period_type;
8797 		   close check_tc_period;
8798 		         X_TimeBB_Id := P_Building_Blocks_Table(i).Time_Building_Block_Id;
8799 		         l_TimeBB_Ovn := P_Building_Blocks_Table(i).Object_Version_Number;
8800 		         X_Approval_Status := P_Building_Blocks_Table(i).Approval_Status;
8801 
8802 		  /* bug 5890771 If Trunc(P_Building_Blocks_Table(i).Stop_Time) - Trunc(P_Building_Blocks_Table(i).Start_Time) = 6 Then*/
8803 		   if l_period_type = 'Week' then
8804 
8805 			          -- The default timecard period in OTL is a week.
8806 
8807 		              If Pa_Utils.NewGetWeekEnding(Trunc(P_Building_Blocks_Table(i).Stop_Time)) <>
8808 			                                          Trunc(P_Building_Blocks_Table(i).Stop_Time) Then
8809 
8810 		                               /* change for bug 8528840 start here */
8811                                                  open is_assignment_end_date(P_Building_Blocks_Table(i).resource_id,P_Building_Blocks_Table(i).Stop_Time);
8812                                                  fetch is_assignment_end_date into l_assign_end_date_flag;
8813 
8814                                                  If is_assignment_end_date%NOTFOUND Then
8815                                                    l_assign_end_date_flag := 0;
8816                                                  End If;
8817                                                  /* change for bug 8528840 end here */
8818 
8819 
8820                                   	           -- The the week ending dates don't match.  This is not allowed.
8821 				            /* change for bug 7584432 start here */
8822 
8823 			 			   open get_termination_date(P_Building_Blocks_Table(i).resource_id,P_Building_Blocks_Table(i).Stop_Time);
8824 			 			  fetch get_termination_date into l_termination_date;
8825 							 close get_termination_date;
8826 			 		          if(l_assign_end_date_flag = 0) Then /* Added for bug 8528840 */
8827 			 			  if Trunc(nvl(l_termination_date,P_Building_Blocks_Table(i).Stop_Time + 1)) <> Trunc(P_Building_Blocks_Table(i).Stop_Time) Then
8828 
8829 			 			   /* change for bug 7584432 end here */
8830 
8831 				/* Added  below statement  for  bug 11711383 */
8832 				IF (G_Detail_Change = 'N' and  G_Delete_Change = 'Y') Then
8833 
8834 				           X_Pass_Val_Flag := 'N';
8835 				           G_Msg_Tokens_Table.Delete;
8836 
8837                            -- Add record to error table.
8838                            Pa_Otc_Api.Add_Error_To_Table(
8839                                 P_Message_Table           => P_Message_Table,
8840                                 P_Message_Name            => 'PA_INVALID_WEEK_ENDING_DATE',
8841                                 P_Message_Level           => 'ERROR',
8842                                 P_Message_Field           => Null,
8843                                 P_Msg_Tokens              => G_Msg_Tokens_Table,
8844                                 P_Time_Building_Block_Id  => X_TimeBB_Id,
8845                                 P_Time_Attribute_Id       => Null);
8846 
8847                         End if;  /*Added  bug 7584432  */
8848 
8849                         End If; /* Added for bug 8528840 */
8850 		  	          End If;
8851 
8852 		         End If;
8853 
8854 			 End If;
8855 
8856                  -- R12 change
8857                  -- This section of code is conditionally getting the override approver person id if the
8858                  -- overriding approver flag is set to Yes and AutoApproval is set to No.  This is not
8859                  -- correct.  We need only be concerned about the autoapproval flag.
8860                  -- If Nvl(Fnd_Profile.Value('PA_ONLINE_OVERRIDE_APPROVER'),'N') = 'Y' Then
8861                  If Nvl(Fnd_Profile.Value('PA_PTE_AUTOAPPROVE_TS'),'N') = 'N' Then
8862 
8863                       /* This variable is being used in the summary validate and
8864                        * business message section of the procedure.
8865                        */
8866 
8867 		              l_Found := False;
8868 
8869                       G_Stage := 'Time block found.  Need to pull out Overriding Approver if exists.';
8870 		              Loop
8871 
8872 			               If x is null Then
8873 
8874 				                G_Stage := 'Get first record in attribution table.';
8875 				                x := P_Attribute_Table.First;
8876 
8877 			               Else
8878 
8879 				                G_Stage := 'Get next record in attribution table.';
8880 				                x := P_Attribute_Table.Next(x);
8881 
8882 			               End If;
8883 
8884 			               G_Stage := 'Check if found the correct record in attribution table.';
8885                            If X_TimeBB_Id = P_Attribute_Table(x).Building_Block_Id And
8886                               Upper(P_Attribute_Table(x).Attribute_Name) = 'OVERRIDING_APPROVER_PERSON_ID' And
8887                               P_Attribute_Table(x).Bld_Blk_Info_Type = 'APPROVAL' Then
8888 
8889 			                    l_Found := True;
8890 
8891                                 /* If there is attribute name 'OVERRIDING_APPROVER_PERSON_ID' is found then
8892                                  * the user populate the field during entry else the user left it alone even
8893                                  * though the user could have assigned an overriding approver.
8894                                  */
8895 
8896                                 G_Stage := 'Call Validate_Overriding_Approver procedure.';
8897                                 Pa_Otc_Api.Validate_Overriding_Approver(
8898                                    P_Approver_Id => to_number(P_Attribute_Table(x).Attribute_Value),
8899                                    X_Approver_Id => X_Ovr_Approver_Person_Id,
8900                                    X_Error_Code  => l_Error_Code,
8901                                    X_Error_Type  => l_Error_Type);
8902 
8903                                 If l_Error_Code Is Not Null Then
8904 
8905                                      G_Stage := 'Validate Overriding Approver - Inserting error rec.';
8906 				                     G_Msg_Tokens_Table.Delete;
8907 
8908                                      -- Add record to error table.
8909                                      Pa_Otc_Api.Add_Error_To_Table(
8910                                         P_Message_Table           => P_Message_Table,
8911                                         P_Message_Name            => l_Error_Code,
8912                                         P_Message_Level           => 'ERROR',
8913                                         P_Message_Field           => 'OVERRIDING_APPROVER_PERSON_ID',
8914                                         P_Msg_Tokens              => G_Msg_Tokens_Table,
8915                                         P_Time_Building_Block_Id  => X_TimeBB_Id,
8916                                         P_Time_Attribute_Id       => P_Attribute_Table(x).Time_Attribute_Id);
8917 
8918                                 End If; --  l_Error_Code Is Not Null
8919 
8920                                 G_Stage := 'Since found the Overriding Approver rec and validated then exit out of loop.';
8921                                 Exit;
8922 
8923                            End If;  -- Same building block id and attribute_name and BB info type.
8924 
8925 			               G_Stage := 'In case of incorrect implementation of overriding approver check if last record.';
8926 			               Exit When x = P_Attribute_Table.LAST;
8927 
8928                       End Loop; -- Loop for Overriding Approver Person Id at Time Scope.
8929 
8930                       /* R12 changes.
8931                        * We no longer require the overriding approver to be populated.
8932                        * But will pull it if it is there.
8933 		              G_Stage := 'Check if found the overriding approver person_id record in attribute table.';
8934 		              If Not l_Found Then
8935 
8936 		                   G_Stage := 'No attribute record was found for overriding approver when there should have been.';
8937                            G_Msg_Tokens_Table.Delete;
8938 
8939                            -- Add record to error table.
8940                            Pa_Otc_Api.Add_Error_To_Table(
8941                                 P_Message_Table           => P_Message_Table,
8942                                 P_Message_Name            => 'PA_OVRRDE_APPROVER_NOT_VALID',
8943                                 P_Message_Level           => 'ERROR',
8944                                 P_Message_Field           => 'OVERRIDING_APPROVER_PERSON_ID',
8945                                 P_Msg_Tokens              => G_Msg_Tokens_Table,
8946                                 P_Time_Building_Block_Id  => X_TimeBB_Id,
8947                                 P_Time_Attribute_Id       => Null);
8948 
8949 			               X_Pass_Val_Flag := 'N';
8950 
8951 		              End If;
8952                       */
8953 
8954                  End If; -- Check if Override approver needs to be pulled if exists
8955 
8956 		         G_Stage := 'Exit the loop since found the header record and validated it.';
8957                  Exit;
8958 
8959 		     End If; --  Scope is TIMECARD
8960 
8961         End Loop; -- Processing Building Blocks to find Header info and validate.';
8962 
8963 	    G_Stage := 'Check if header pass validation and set flag.';
8964 	    If X_Pass_Val_Flag is null Then
8965 
8966 		     X_Pass_Val_Flag := 'Y';
8967 
8968 	    End If;
8969 
8970         G_Stage := 'Leaving FindandValidateHeader() procedure.';
8971         Pa_Otc_Api.TrackPath('STRIP','FindandValidateHeader');
8972 
8973    Exception
8974 	When Others Then
8975 		Raise;
8976 
8977    End FindandValidateHeader;
8978 
8979 -- =======================================================================
8980 -- Start of Comments
8981 -- API Name      : Wf_AutoApproval_BusMsg
8982 -- Type          : Public
8983 -- Pre-Reqs      : None
8984 -- Type          : Procedure
8985 -- Function      : This procedure is called by the OTL client team.
8986 --                 Calls the PA_CLIENT_EXTN_PTE.Get_Exp_AutoApproval() and
8987 --                 the PA_TIME_CLIENT_EXTN.Display_Business_Message().
8988 --
8989 -- Parameters    :
8990 -- OUT
8991 --           X_AutoApproval_Flag    -  Varchar2
8992 --           X_Messages             -  Varchar2
8993 
8994 /*------------------------------------------------------------------------- */
8995 
8996   Procedure Wf_AutoApproval_BusMsg
8997             (X_AutoApproval_Flag    OUT NOCOPY Varchar2
8998             ,X_Messages             OUT NOCOPY Varchar2)
8999 
9000   Is
9001 
9002         l_Timecard_Table         Pa_Otc_Api.Timecard_Table;
9003         l_Inc_By_Person_Id       Pa_Expenditures_All.Incurred_By_Person_Id%TYPE;
9004 	l_Overriding_Approver_Id Pa_Expenditures_All.Overriding_Approver_Person_Id%TYPE;
9005 
9006         /* Stores a single record from the Building Block Table */
9007         l_Building_Block_Record  Hxc_User_Type_Definition_Grp.Building_Block_Info;
9008 
9009 	l_Message_Name           Varchar2(30);
9010 	l_Message_Table          Hxc_User_Type_Definition_Grp.Message_Table;
9011 
9012         l_Status                 Number(10);
9013         l_Appl_Id                Varchar2(10);
9014         l_Msg_Name               Varchar2(30);
9015         l_Msg_Application        Varchar2(10);
9016         l_Msg_Token1_Name        Varchar2(30);
9017         l_Msg_Token1_Value       Varchar2(255);
9018         l_Msg_Token2_Name        Varchar2(30);
9019         l_Msg_Token2_Value       Varchar2(255);
9020         l_Msg_Token3_Name        Varchar2(30);
9021         l_Msg_Token3_Value       Varchar2(255);
9022 
9023   Begin
9024 
9025 	G_Path := ' ';
9026 
9027 	G_Stage := 'Entering Wf_AutoApproval_BusMsg() procedure.';
9028         Pa_Otc_Api.TrackPath('ADD','Wf_AutoApproval_BusMsg');
9029 
9030 	G_Stage := 'Initialize the hxc pl/sql tables that will be used.';
9031         l_Timecard_Table.delete;
9032 	l_Message_Table.delete;
9033 
9034 	G_Stage := 'Calling Pa_Otc_Api.CreateProjTimecardTable()';
9035         Pa_Otc_Api.CreateProjTimecardTable(
9036                 X_Inc_By_Person_Id       => l_Inc_By_Person_Id,
9037                 X_Timecard_Table         => l_Timecard_Table,
9038                 X_Overriding_Approver_Id => l_Overriding_Approver_Id );
9039 
9040 	G_Stage := 'Calling Pa_Client_Extn_Pte.Get_Exp_AutoApproval()';
9041 	Pa_Client_Extn_Pte.Get_Exp_AutoApproval (
9042 	        X_Source          => 'PA',
9043                 X_Exp_Class_Code  => 'PT',
9044                 X_Txn_Id          => Null,
9045                 X_Exp_Ending_Date => Null,
9046                 X_Person_Id       => l_Inc_By_Person_Id,
9047                 P_Timecard_Table  => l_Timecard_Table,
9048                 P_Module          => 'OTL',
9049                 X_Approved        => X_AutoApproval_Flag );
9050 
9051 	If X_AutoApproval_Flag NOT IN ('N','Y') Then
9052 
9053 		G_Stage := 'AutoApproval Extension does not return valid value. Create error message.';
9054 		l_Message_Name := 'PA_TR_INVALID_AUTOAPPROVAL_FLG';
9055 		X_AutoApproval_Flag := Null;
9056 
9057 		G_Msg_Tokens_Table.Delete;
9058 
9059                 Pa_Otc_Api.Add_Error_To_Table(
9060                 	P_Message_Table           => l_Message_Table,
9061                         P_Message_Name            => l_Message_Name,
9062                         P_Message_Level           => 'ERROR',
9063                         P_Message_Field           => Null,
9064                         P_Msg_Tokens              => G_Msg_Tokens_Table,
9065                         P_Time_Building_Block_Id  => Null,
9066                         P_Time_Attribute_Id       => Null);
9067 
9068 	End If;
9069 
9070 	/* If the AutoApproval flag is Yes then there is no reason to get the business message for this
9071          * timecard.
9072          */
9073         If X_AutoApproval_Flag = 'N' and Nvl(Fnd_Profile.Value('PA_SST_ENABLE_BUS_MSG'),'N') = 'Y' Then
9074 
9075 		G_Stage := 'Calling Pa_Time_Client_Extn.Display_Business_Message()';
9076                 Pa_Time_Client_Extn.Display_Business_Message(
9077                          P_Timecard_Table       => l_Timecard_Table,
9078                          P_Module               => 'OTL',
9079                          P_Person_id            => l_Inc_By_Person_Id,
9080                          P_Week_Ending_Date     => Null,
9081                          X_Msg_Application_Name => l_Msg_Application,
9082                          X_Message_Data         => l_Msg_Name,
9083                          X_Msg_Token1_Name      => l_Msg_Token1_Name,
9084                          X_Msg_Token1_Value     => l_Msg_Token1_Value ,
9085                          X_Msg_Token2_Name      => l_Msg_Token2_Name,
9086                          X_Msg_Token2_Value     => l_Msg_token2_Value,
9087                          X_Msg_Token3_Name      => l_Msg_Token3_Name,
9088                          X_Msg_Token3_Value     => l_Msg_Token3_Value);
9089 
9090                 If l_Msg_Name is Not Null Then
9091 
9092 			 G_Stage := 'Message was returned from Display_Business_Message Extension.  Create message.';
9093                          G_Msg_Tokens_Table.Delete;
9094 
9095                          If l_Msg_Token1_Name Is Not Null Then
9096 
9097                                 G_Msg_Tokens_Table(1).Token_Name := l_Msg_Token1_Name;
9098                                 G_Msg_Tokens_Table(1).Token_Value := l_Msg_Token1_Value;
9099 
9100                          End If;
9101 
9102                          If l_Msg_Token2_Name Is Not Null Then
9103 
9104                                 G_Msg_Tokens_Table(2).Token_Name := l_Msg_Token2_Name;
9105                                 G_Msg_Tokens_Table(2).Token_Value := l_Msg_Token2_Value;
9106 
9107                          End If;
9108 
9109                          If l_Msg_Token3_Name Is Not Null Then
9110 
9111                                 G_Msg_Tokens_Table(3).Token_Name := l_Msg_Token3_Name;
9112                                 G_Msg_Tokens_Table(3).Token_Value := l_Msg_Token3_Value;
9113 
9114                          End If;
9115 
9116 			 If l_Msg_Application Is Null Then
9117 
9118 				l_Msg_Application := 'PA';
9119 
9120 			 End If;
9121 
9122                          Pa_Otc_Api.Add_Error_To_Table(
9123                                     P_Message_Table           => l_Message_Table,
9124                                     P_Message_Name            => l_Msg_Name,
9125                                     P_Message_Level           => 'BUSINESS',
9126                                     P_Message_Field           => Null,
9127                                     P_Msg_Tokens              => G_Msg_Tokens_Table,
9128                                     P_Time_Building_Block_Id  => Null,
9129                                     P_Time_Attribute_Id       => Null,
9130 				    P_Message_App             => l_Msg_Application);
9131 
9132                 End If; -- l_Msg_Name Is Not Null
9133 
9134         End If; -- Profile 'PA_SST_ENABLE_BUS_MSG' = 'Y'
9135 
9136 	If l_Message_Table.Count > 0 Then
9137 
9138 		G_Stage := 'Calling Hxc_Deposit_Wrapper_Utilities.Messages_To_String().';
9139         	X_Messages := Hxc_Integration_Layer_V1_Grp.Messages_To_String(P_Messages => l_Message_Table);
9140         End If;
9141 
9142 	G_Stage := 'Leaving Wf_AutoApproval_BusMsg() procedure.';
9143         Pa_Otc_Api.TrackPath('STRIP','Wf_AutoApproval_BusMsg');
9144 
9145   Exception
9146 	When Others Then
9147 		Raise_Application_Error(-20500, 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_stage || ' : ' || SQLERRM );
9148 
9149   End Wf_AutoApproval_BusMsg;
9150 
9151 -- =======================================================================
9152 -- Start of Comments
9153 -- API Name      : Wf_RouteTo_CheckApproval
9154 -- Type          : Public
9155 -- Pre-Reqs      : None
9156 -- Type          : Procedure
9157 -- Function      : This procedure is called by the OTL client team.
9158 --                 The only intent of the procedure is manipulate
9159 --                 the parameters passed in and then call
9160 --                 the PaRoutingX.Route_To_Extension().
9161 --
9162 -- Parameters    :
9163 -- IN
9164 --           P_Previous_Approver_Id -  Number
9165 -- OUT
9166 --           X_Approver_Person_Id   -  Number
9167 --           X_Messages             -  Varchar2
9168 
9169 /*------------------------------------------------------------------------- */
9170 
9171   Procedure Wf_RouteTo_CheckApproval(
9172             P_Previous_Approver_Id IN         Number,
9173             X_Approver_Person_Id   OUT NOCOPY Number,
9174             X_Messages             OUT NOCOPY Varchar2)
9175 
9176   Is
9177 
9178         l_Timecard_Table         Pa_Otc_Api.Timecard_Table;
9179         l_Inc_By_Person_Id       Pa_Expenditures_All.Incurred_By_Person_Id%TYPE;
9180 	l_Overriding_Approver_Id Pa_Expenditures_All.Overriding_Approver_Person_Id%TYPE := Null;
9181 
9182         l_Message_Table          Hxc_User_Type_Definition_Grp.Message_Table;
9183 	l_Message_Name           Varchar2(30);
9184 
9185         l_Status                 Number(10);
9186         l_Msg_App                Varchar2(10);
9187         l_Msg_Code               Varchar2(30);
9188         l_Token_1                Varchar2(255);
9189         l_Token_2                Varchar2(255);
9190         l_Token_3                Varchar2(255);
9191         l_Token_4                Varchar2(255);
9192         l_Token_5                Varchar2(255);
9193 
9194 	l_Approval_Flag          Varchar2(30) := 'COMPLETE:FAIL';  -- Do not change!
9195 
9196         Unexpected_Error         Exception;
9197 
9198   Begin
9199 
9200         G_Path := ' ';
9201 
9202         G_Stage := 'Entering Wf_RouteTo_CheckApproval() procedure.';
9203         Pa_Otc_Api.TrackPath('ADD','Wf_RouteTo_CheckApproval');
9204 
9205         G_Stage := 'Initialize the PA pl/sql tables that will be used.';
9206         l_Timecard_Table.Delete;
9207 
9208 	G_Stage := 'Calling Pa_Otc_Api.CreateProjTimecardTable()';
9209         Pa_Otc_Api.CreateProjTimecardTable(
9210                 X_Inc_By_Person_Id       => l_Inc_By_Person_Id,
9211                 X_Timecard_Table         => l_Timecard_Table,
9212  	        X_Overriding_Approver_Id => l_Overriding_Approver_Id);
9213 
9214 	If P_Previous_Approver_Id is Not Null Then
9215 
9216 		G_Stage := 'Previous_Approver is not null call Pa_Client_Extn_Rte.Check_Approval().';
9217 
9218         	Pa_Client_Extn_Rte.Check_Approval(
9219                         X_Expenditure_Id        => Null,
9220                         X_Incurred_By_Person_Id => l_Inc_By_Person_Id,
9221                         X_Expenditure_End_Date  => Null,
9222                         X_Exp_Class_Code        => 'PT',
9223                         X_Amount                => Null,
9224                         X_Approver_Id           => P_Previous_Approver_Id,
9225                         X_Routed_To_Mode        => 'SUPERVISOR',
9226                         P_Timecard_Table        => l_Timecard_Table,
9227                         P_Module                => 'OTL',
9228                         X_Status                => l_Status,
9229                         X_Application_Id        => l_Msg_App,
9230                         X_Message_Code          => l_Msg_Code,
9231                         X_Token_1               => l_Token_1,   -- Token Name --> 'TOKEN_1'
9232                         X_Token_2               => l_Token_2,   -- Token Name --> 'TOKEN_2'
9233                         X_Token_3               => l_Token_3,   -- Token Name --> 'TOKEN_3'
9234                         X_Token_4               => l_Token_4,   -- Token Name --> 'TOKEN_4'
9235                         X_Token_5               => l_Token_5 ); -- Token Name --> 'TOKEN_5'
9236 
9237         	If l_Status = 0 Then
9238 
9239 			G_Stage := 'Previous Approver had final authority to approve the timecard.';
9240         		l_Approval_Flag := 'COMPLETE:PASS';
9241 
9242         	ElsIf l_Status < 0 Then
9243 
9244 			G_Stage := 'Unexpected error occurred in the called routine Pa_Client_Extn_Rte.Check_Approval().';
9245                 	Raise Unexpected_Error;
9246 
9247         	Else  -- l_Status > 0
9248 
9249 			G_Stage := 'The previous approver did not have the final authority to approve the timecard.';
9250                 	l_Approval_Flag := 'COMPLETE:FAIL';
9251 
9252                 	G_Msg_Tokens_Table.Delete;
9253 
9254                 	If l_Msg_Code Is Not Null Then
9255 
9256 				G_Stage := 'A message has been passed back from Pa_Client_Extn_Rte.Check_Approval().  ' ||
9257 					   'Create a message.';
9258                 		If l_Token_1 Is Not Null Then
9259 
9260                         		G_Msg_Tokens_Table(1).Token_Name := 'TOKEN_1';
9261                                 	G_Msg_Tokens_Table(1).Token_Value := l_Token_1;
9262 
9263                         	End If;
9264 
9265                         	If l_Token_2 Is Not Null Then
9266 
9267                         		G_Msg_Tokens_Table(2).Token_Name := 'TOKEN_2';
9268                                 	G_Msg_Tokens_Table(2).Token_Value := l_Token_2;
9269 
9270                         	End If;
9271 
9272                         	If l_Token_3 Is Not Null Then
9273 
9274                                 	G_Msg_Tokens_Table(3).Token_Name := 'TOKEN_3';
9275                                 	G_Msg_Tokens_Table(3).Token_Value := l_Token_3;
9276 
9277                         	End If;
9278 
9279                         	If l_Token_4 Is Not Null Then
9280 
9281                                 	G_Msg_Tokens_Table(4).Token_Name := 'TOKEN_4';
9282                                 	G_Msg_Tokens_Table(4).Token_Value := l_Token_4;
9283 
9284                         	End If;
9285 
9286                         	If l_Token_5 Is Not Null Then
9287 
9288                                 	G_Msg_Tokens_Table(5).Token_Name := 'TOKEN_5';
9289                                 	G_Msg_Tokens_Table(5).Token_Value := l_Token_5;
9290 
9291                         	End If;
9292 
9293 
9294 				If l_Msg_App Is Null Then
9295 
9296 					l_Msg_App := 'PA';
9297 
9298 				End If;
9299 
9300                         	Pa_Otc_Api.Add_Error_To_Table (
9301                                 	P_Message_Table           => l_Message_Table,
9302                                 	P_Message_Name            => l_Msg_Code,
9303                                 	P_Message_Level           => 'ERROR',
9304                                 	P_Message_Field           => Null,
9305                                 	P_Msg_Tokens              => G_Msg_Tokens_Table,
9306                                 	P_Time_Building_Block_Id  => Null,
9307                                 	P_Time_Attribute_Id       => Null,
9308 					P_Message_App             => l_Msg_App);
9309 
9310 			End If; -- Message Code Is Not Null
9311 
9312 		End If; -- l_Status
9313 
9314 	End If; -- P_Previous_Approver_Id Is Not Null
9315 
9316 	/* If the previous approver does not have the authority to make the final decision then
9317 	 * the approval flag will be 'COMPLETE:FAIL'.  If the previous approver did have the
9318          * authority to have final approval for the timecard being process then the approval
9319          * flag will be 'COMPLETE:PASS' in which case the route_to_extension does not need
9320          * to be called.
9321          */
9322 
9323 	-- Approver authority flag check
9324 	If l_Approval_Flag = 'COMPLETE:FAIL' Then
9325 
9326 		G_Stage := 'Checking who the next approver should be.';
9327 		/* Want to check and see if there is an overriding approver to send the timecard to for approval.
9328 		 * For this to be correct need to make sure that this part is only called when the timecard is submitted.
9329 		 * That is why we check if the previous approver is null.  It has to be null upon submission.
9330 		 */
9331 		-- Bug 2773066
9332 		-- We don't need to check if the profile is set at this point.
9333 		-- If the overriding approver is populated then use it when appropriate.
9334 		-- If Nvl(Fnd_Profile.Value('PA_ONLINE_OVERRIDE_APPROVER'),'N') = 'Y' And
9335 		If l_Overriding_Approver_Id Is Not Null And
9336 	 	   P_Previous_Approver_Id Is Null Then
9337 
9338 			X_Approver_Person_Id := l_Overriding_Approver_Id;
9339 
9340 		Else
9341 
9342 			G_Stage := 'The previous approver did not have the final authority to approve the timecard.  ' ||
9343 			           'Call PaRoutingX.Route_To_Extension() to get the next approver in line.';
9344 
9345         		PaRoutingX.Route_To_Extension(
9346             			X_Expenditure_Id               => Null,
9347             	        	X_Incurred_By_Person_Id        => l_Inc_By_Person_Id,
9348             	        	X_Expenditure_End_Date         => Null,
9349             	        	X_Exp_Class_Code               => 'PT',
9350             	        	X_Previous_Approver_Person_Id  => P_Previous_Approver_Id,
9351             	        	P_Timecard_Table               => l_Timecard_Table,
9352             	        	P_Module                       => 'OTL',
9353             	        	X_Route_To_Person_Id           => X_Approver_Person_Id );
9354 
9355 			If P_Previous_Approver_Id Is Null And X_Approver_Person_Id Is Null Then
9356 
9357 				G_Stage := 'There is no previous approver and no one to route the timecard to.  ' ||
9358 				           'Create error message.';
9359 				l_Message_Name := 'PA_TR_NO_ROUTE_TO_PERSON';
9360 
9361 				G_Msg_Tokens_Table.Delete;
9362 
9363                         	Pa_Otc_Api.Add_Error_To_Table(
9364                                 	P_Message_Table           => l_Message_Table,
9365                                     	P_Message_Name            => l_Message_Name,
9366                                     	P_Message_Level           => 'ERROR',
9367                                     	P_Message_Field           => Null,
9368                                     	P_Msg_Tokens              => G_Msg_Tokens_Table,
9369                                     	P_Time_Building_Block_Id  => Null,
9370                                     	P_Time_Attribute_Id       => Null);
9371 
9372 			ElsIf P_Previous_Approver_Id Is Not Null And X_Approver_Person_Id Is Null Then
9373 
9374 				G_Stage := 'There is no one to route the timecard to.  ' ||
9375 				           'Create an error message.';
9376 				l_Message_Name := 'PA_NO_APPROVER_FOUND';
9377 				G_Msg_Tokens_Table.Delete;
9378 
9379                         	Pa_Otc_Api.Add_Error_To_Table(
9380                                     	P_Message_Table           => l_Message_Table,
9381                                     	P_Message_Name            => l_Message_Name,
9382                                     	P_Message_Level           => 'ERROR',
9383                                         P_Message_Field           => Null,
9384                                         P_Msg_Tokens              => G_Msg_Tokens_Table,
9385                                         P_Time_Building_Block_Id  => Null,
9386                                     	P_Time_Attribute_Id       => Null);
9387 
9388         		End If; -- l_Msg_Name Is Not Null
9389 
9390 		End If; -- checking of overriding approver
9391 
9392 	ElsIf  l_Approval_Flag = 'COMPLETE:PASS' Then
9393 
9394 		G_Stage := 'The timecard has final approval.  Set approver person id to -99.';
9395 
9396 		/* If the previous approver had the final authority to approver the timecard, then
9397 		 * pass back -99 for the next approver to route to so that OTL knows that no further
9398                  * approvers are needed.
9399 		 */
9400 		X_Approver_Person_Id := -99;
9401 
9402 	End If; -- Approver authority flag check
9403 
9404         If l_Message_Table.Count > 0 Then
9405 
9406 		G_Stage := 'Messages have been created convert to varchar by calling ' ||
9407 			   'Hxc_Integration_Layer_V1_Grp.Messages_To_String().';
9408         	X_Messages := Hxc_Integration_Layer_V1_Grp.Messages_To_String(P_Messages => l_Message_Table);
9409         End If;
9410 
9411         G_Stage := 'Leaving Wf_RouteTo_CheckApproval() procedure.';
9412         Pa_Otc_Api.TrackPath('STRIP','Wf_RouteTo_CheckApproval');
9413 
9414   Exception
9415         When Others Then
9416         	Raise_Application_Error(-20600, 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_stage || ' : ' || SQLERRM );
9417 
9418   End Wf_RouteTo_CheckApproval;
9419 
9420 -- =======================================================================
9421 -- Start of Comments
9422 -- API Name      : CreateProjTimecardTable
9423 -- Type          : Private
9424 -- Pre-Reqs      : None
9425 -- Type          : Procedure
9426 -- Function      : This procedure create pl/sql table of OTL data in
9427 --                 project friendly format.
9428 --
9429 -- Parameters    :
9430 -- OUT
9431 --           X_Inc_By_Person_Id       - Pa_Expenditures_All.Incurred_By_Person_Id%TYPE
9432 --           X_Timecard_Table         - Pa_Otc_Api.Timecard_Table
9433 --           X_Overriding_Approver_Id - Pa_Expenditures_All.Overriding_Approver_Person_Id%TYPE
9434 
9435 /*------------------------------------------------------------------------- */
9436 
9437   Procedure CreateProjTimecardTable(
9438 	    X_Inc_By_Person_Id       OUT NOCOPY Pa_Expenditures_All.Incurred_By_Person_Id%TYPE,
9439             X_Timecard_Table         OUT NOCOPY Pa_Otc_Api.Timecard_Table, --2672653
9440             X_Overriding_Approver_Id OUT NOCOPY Pa_Expenditures_All.Overriding_Approver_Person_Id%TYPE)
9441 
9442   Is
9443 
9444         l_Proj_Attrib_Rec       Pa_Otc_Api.Project_Attribution_Rec;
9445         j                       Binary_Integer := 0;
9446 
9447 	l_Time_Building_Blocks Hxc_User_Type_Definition_Grp.Timecard_Info;
9448 	l_Time_Attributes      Hxc_User_Type_Definition_Grp.App_Attributes_Info;
9449 	l_Detail_Attr_Changed  Varchar2(1) := 'N';
9450 
9451         /* Stores a single record from the Building Block Table */
9452         l_Building_Block_Record     Hxc_User_Type_Definition_Grp.Building_Block_Info;
9453 
9454   Begin
9455 
9456         G_Stage := 'Entering CreateProjTimecardTable() procedure.';
9457         Pa_Otc_Api.TrackPath('ADD','CreateProjTimecardTable');
9458 
9459 	G_Stage := 'Initialize PA structure pl/sql table.';
9460 
9461 	X_Timecard_Table.delete;
9462 
9463 	G_Stage := 'Get the hxc pl/sql building block and attribution tables.';
9464         l_Time_Building_Blocks := Hxc_Integration_Layer_V1_Grp.Get_Wf_G_Time_Building_Blocks;
9465         l_Time_Attributes      := Hxc_Integration_Layer_V1_Grp.Get_Wf_G_Time_App_Attributes;
9466 
9467 	G_Stage := 'Begin looping thru hxc pl/sql building block table.';
9468         For i in l_Time_Building_Blocks.FIRST .. l_Time_Building_Blocks.LAST
9469         Loop
9470 
9471 		G_Stage := 'Check if overriding approver exists when the scope is TIMECARD.';
9472 		-- Bug 2773066
9473 		-- We don't need to check the overriding approver profile.
9474 		-- If it is populated then it should be picked up and used when and if needed.
9475         -- If Nvl(Fnd_Profile.Value('PA_ONLINE_OVERRIDE_APPROVER'),'N') = 'Y' And
9476 		If l_Time_Building_Blocks(i).Scope = 'TIMECARD' Then
9477 
9478 			G_Stage := 'Now loop thru and attribution records for the TIMECARD scope building block.';
9479                 	<<Approval_Attribs_Loop>>
9480                         For q in l_Time_Attributes.FIRST .. l_Time_Attributes.LAST
9481                         Loop
9482 
9483 				G_Stage := 'Check for overriding approver attribution record exists.';
9484                         	If l_Time_Building_Blocks(i).Time_Building_Block_Id =
9485                                                         l_Time_Attributes(q).Building_Block_Id And
9486                                    Upper(l_Time_Attributes(q).Attribute_Name) = 'OVERRIDING_APPROVER_PERSON_ID' And
9487 				   l_Time_Attributes(q).Bld_Blk_Info_Type = 'APPROVAL' Then
9488 
9489 					G_Stage := 'Assign overriding approver to out paramanter';
9490                                    	X_Overriding_Approver_Id := l_Time_Attributes(q).Attribute_Value;
9491 
9492 					G_Stage := 'Exit Approval_Attribs_Loop.';
9493                                         Exit Approval_Attribs_Loop;
9494 
9495                                 End If;
9496 
9497                         End Loop Approval_Attribs_Loop;
9498 
9499        		End If;
9500 
9501 		G_Stage := 'Check if building block scope is DETAIL.';
9502                 If l_Time_Building_Blocks(i).Scope = 'DETAIL' Then
9503 
9504                         G_Stage := 'Initialize variables for loop.';
9505                         l_Building_Block_Record := l_Time_Building_Blocks(i);
9506 			l_Detail_Attr_Changed   := 'N';
9507 
9508                         G_Stage := 'Pull out the data to PA friendly format by calling RetrieveProjAttribution().';
9509                         Pa_Otc_Api.RetrieveProjAttribution(
9510                                 P_Building_Block_Rec  => l_Building_Block_Record,
9511                                 P_Building_Block      => l_Time_Building_Blocks,
9512                                 P_Attribute_Table     => l_Time_Attributes,
9513 				X_Detail_Attr_Changed => l_Detail_Attr_Changed,
9514                                 X_Proj_Attrib_Rec     => l_Proj_Attrib_Rec);
9515 
9516                         j := j + 1;
9517 
9518 			G_Stage := 'Push the PA friendly format pl/sql record into pl/sql table.';
9519                         X_Timecard_Table(j).Project_Number 		:= l_Proj_Attrib_Rec.Project_Number;
9520                         X_Timecard_Table(j).Project_Id     		:= l_Proj_Attrib_Rec.Project_id;
9521                         X_Timecard_Table(j).Task_Number    		:= l_Proj_Attrib_Rec.Task_Number;
9522                         X_Timecard_Table(j).Task_Id        		:= l_Proj_Attrib_Rec.Task_Id;
9523                         X_Timecard_Table(j).Expenditure_Type 		:= l_Proj_Attrib_Rec.Expenditure_Type;
9524                         X_Timecard_Table(j).System_Linkage_Function 	:= l_Proj_Attrib_Rec.Sys_Linkage_Func;
9525                         X_Timecard_Table(j).Quantity 			:= l_Proj_Attrib_Rec.Quantity;
9526                         X_Timecard_Table(j).Incurred_By_Person_Id 	:= l_Proj_Attrib_Rec.Inc_By_Person_Id;
9527                         X_Timecard_Table(j).Override_Approver_Person_Id := Null;
9528                         X_Timecard_Table(j).Expenditure_Item_Date 	:= l_Proj_Attrib_Rec.Expenditure_Item_Date;
9529                         X_Timecard_Table(j).Expenditure_Ending_Date 	:= l_Proj_Attrib_Rec.Exp_Ending_Date;
9530                         X_Timecard_Table(j).Attribute_Category 		:= l_Proj_Attrib_Rec.Attrib_Category;
9531                         X_Timecard_Table(j).Attribute1 			:= l_Proj_Attrib_Rec.Attribute1;
9532                         X_Timecard_Table(j).Attribute2 			:= l_Proj_Attrib_Rec.Attribute2;
9533                         X_Timecard_Table(j).Attribute3 			:= l_Proj_Attrib_Rec.Attribute3;
9534                         X_Timecard_Table(j).Attribute4 			:= l_Proj_Attrib_Rec.Attribute4;
9535                         X_Timecard_Table(j).Attribute5 			:= l_Proj_Attrib_Rec.Attribute5;
9536                         X_Timecard_Table(j).Attribute6 			:= l_Proj_Attrib_Rec.Attribute6;
9537                         X_Timecard_Table(j).Attribute7 			:= l_Proj_Attrib_Rec.Attribute7;
9538                         X_Timecard_Table(j).Attribute8 			:= l_Proj_Attrib_Rec.Attribute8;
9539                         X_Timecard_Table(j).Attribute9 			:= l_Proj_Attrib_Rec.Attribute9;
9540                         X_Timecard_Table(j).Attribute10 		:= l_Proj_Attrib_Rec.Attribute10;
9541                         X_Timecard_Table(j).Billable_Flag 		:= l_Proj_Attrib_Rec.Billable_Flag;
9542                         X_Timecard_Table(j).Expenditure_Item_Comment 	:= l_Proj_Attrib_Rec.Expenditure_Item_Comment;
9543                         X_Timecard_Table(j).Orig_Exp_Txn_Reference1  	:= Null;
9544                         -- Bug 10253400.. 12.2 payroll intg .. start
9545                         X_Timecard_Table(j).Job_Id 	:= l_Proj_Attrib_Rec.Job_Id;
9546                         X_Timecard_Table(j).Location_Id 	:= l_Proj_Attrib_Rec.Location_Id;
9547                         X_Timecard_Table(j).Pay_Element_Type_Id	:= l_Proj_Attrib_Rec.Pay_Element_Type_Id;
9548                         -- Bug 10253400.. 12.2 payroll intg .. end
9549                         X_Timecard_Table(j).Cbs_Element_Id	:= l_Proj_Attrib_Rec.Cbs_Element_Id; -- Added for CBS Enhancement Bug 16220146
9550 
9551                 End If;
9552 
9553 		G_Stage := 'Grab the Inc By Person Id to return as our parameter.';
9554 		X_Inc_By_Person_Id := l_Proj_Attrib_Rec.Inc_By_Person_Id;
9555 
9556         End Loop;
9557 
9558 	G_Stage := 'Leaving CreateProjTimecardTable() procedure.';
9559         Pa_Otc_Api.TrackPath('STRIP','CreateProjTimecardTable');
9560 
9561   Exception
9562 	When Others Then
9563 		Raise;
9564 
9565   End CreateProjTimecardTable;
9566 
9567 
9568 -- =======================================================================
9569 -- Start of Comments
9570 -- API Name      : OrigTrxRefValueExists
9571 -- Type          : Private
9572 -- Pre-Reqs      : None
9573 -- Type          : Function
9574 -- Function      : This function checks to see if the detail scope bb_id/ovn
9575 --                 combination is already in Projects.  This can occur during
9576 --                 validation of the timecard under certain conditions.  The
9577 --                 orig_transaction_reference columns may get updated during
9578 --                 validation to resink with OTL.  (Changes are made that
9579 --                 projects does not recognize and doesn't want to, thus the ovn changes in OTL.)
9580 --
9581 -- Parameters    :
9582 -- IN
9583 --           P_Orig_Transaction_Reference - Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE
9584 
9585 /*------------------------------------------------------------------------- */
9586 
9587   Function OrigTrxRefValueExists
9588 		( P_Orig_Transaction_Reference IN Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE) Return Boolean
9589 
9590   Is
9591 
9592 	l_Exists_Flag VARCHAR2(1) := 'N';
9593 
9594   Begin
9595 
9596 	Select
9597                distinct 'Y' -- Bug#9374217: Added distinct clause to avoid the ORA-1422 error.
9598 	Into
9599                l_Exists_Flag
9600 	From
9601                Pa_Expenditure_Items_All
9602 	Where
9603                Transaction_Source = 'ORACLE TIME AND LABOR'
9604 	And    Orig_Transaction_Reference = P_Orig_Transaction_Reference;
9605 
9606 	If l_Exists_Flag = 'Y' Then
9607 
9608 		Return ( True ) ;
9609 
9610 	Else
9611 
9612 		Return ( False );
9613 
9614 	End If;
9615 
9616   Exception
9617 	When No_Data_Found Then
9618 		Return ( False );
9619 	When Others Then
9620 		Raise;
9621 
9622   End OrigTrxRefValueExists;
9623 
9624 
9625 -- =======================================================================
9626 -- Start of Comments
9627 -- API Name      : ChkAdjustAllowedToOTCItem
9628 -- Type          : Public
9629 -- Pre-Reqs      : None
9630 -- Type          : Function
9631 -- Function      : This function s used to check and see if an OTL expenditure item that
9632 --                 has been imported into Projects can adjusted in Projects by calling the
9633 --                 API Hxc_Generic_Retrieval_Utils.Time_Bld_Blk_Changed.
9634 --
9635 -- Parameters    :
9636 -- IN            P_Orig_Txn_Reference - Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE
9637 --
9638 /*--------------------------------------------------------------------------*/
9639 
9640   Function ChkAdjustAllowedToOTCItem
9641 	(P_Orig_Txn_Reference IN Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE) Return Varchar2
9642 
9643   Is
9644 
9645       l_BB_Id  Hxc_Time_Building_Blocks.Time_Building_Block_Id%TYPE := Null;
9646       l_BB_Ovn Hxc_Time_Building_Blocks.Object_Version_Number%TYPE := Null;
9647 
9648   Begin
9649 
9650 	-- Check if the original transaction reference is null or not.
9651 	If P_Orig_Txn_Reference Is Not Null Then
9652 
9653       		l_BB_Id := to_number(substr(P_Orig_Txn_Reference,1,instr(P_Orig_Txn_Reference,':') - 1));
9654       		l_BB_Ovn := to_number(substr(P_Orig_Txn_Reference,instr(P_Orig_Txn_Reference,':') + 1));
9655 
9656       		/* The hxc function returns the case of whether or not there is a higher ovn value in the OTL table
9657       		 * than the ovn value we are passing in.
9658       		 * Therefore we actually want to return the opposite of that to the calling procedure/view.
9659        		 */
9660       		If Hxc_Integration_Layer_V1_Grp.Time_Bld_Blk_Changed( P_BB_Id => l_BB_id, P_BB_Ovn => l_BB_Ovn)  Then
9661 
9662 			Return ( 'N' );
9663 
9664       		Else
9665 
9666 			Return ( 'Y' );
9667 
9668 		End If;
9669 
9670 	Else
9671 
9672                 /* Did not originate in OTL.  This item is a resulting child of the
9673                  * original OTL item that was adjusted.  So want to always default it
9674                  * so that it can adjusted and let other code restrictions in PA handle
9675                  * whether or not the expenditure item can be adjusted.
9676                  */
9677 		Return ( 'Y' );
9678 
9679       	End If;
9680 
9681   Exception
9682 	When Others Then
9683 		Raise;
9684 
9685   End ChkAdjustAllowedToOTCItem;
9686 
9687 
9688 -- =======================================================================
9689 -- Start of Comments
9690 -- API Name      : GetBatchName
9691 -- Type          : Private
9692 -- Pre-Reqs      : None
9693 -- Type          : Procedure
9694 -- Function      : This procedure returns a batch name for Trx Import to used based on the
9695 --               : expenditure_ending_date passed in.  Each time a new batch is created a new
9696 --               : record is added to a pl/sql table holding the Ending_Date Batch_Name so as
9697 --               : to only create single batch_name for each Ending_Date for a Trx Import run.
9698 --               : Used in the Upload_Otc_Timecards() procedure.
9699 --
9700 -- Parameters    :
9701 -- IN
9702 --		P_Exp_End_Date - Pa_Transaction_Interface_All.Expenditure_Ending_Date%TYPE
9703 -- OUT
9704 --              X_Batch_Name   - Pa_Transaction_Interface_All.Batch_Name%TYPE
9705 /*--------------------------------------------------------------------------*/
9706 
9707   Procedure GetBatchName (P_Exp_End_Date IN         Pa_Transaction_Interface_All.Expenditure_Ending_Date%TYPE,
9708                           X_Batch_Name   OUT NOCOPY Pa_Transaction_Interface_All.Batch_Name%TYPE)
9709 
9710   Is
9711 
9712 	l_Found_Match Boolean := False;
9713 	l_Date_String Varchar2(10);
9714 	l_Sequence_No Number;
9715 	l_New_Index   Binary_Integer := 0;
9716 	l_debug_text  Varchar2(200);
9717 
9718   Begin
9719 
9720         G_Stage := 'Entering GetBatchName(), add procedure to trackpath.';
9721 	If G_Debug_Mode = 'Y' Then
9722            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
9723            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
9724         End If;
9725         Pa_Otc_Api.TrackPath('ADD','GetBatchName');
9726 
9727 	If G_EndDateBatchName_Table.Count > 0 Then
9728 
9729 		G_Stage := 'There are already batch name recs in pl/sql table.  See if find a matching one via loop.';
9730 		If G_Debug_Mode = 'Y' Then
9731         	   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
9732         	   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
9733         	End If;
9734 
9735 		For i IN G_EndDateBatchName_Table.First .. G_EndDateBatchName_Table.Last
9736 		Loop
9737 
9738 			If G_EndDateBatchName_Table(i).Expenditure_Ending_Date = P_Exp_End_Date Then
9739 
9740 				X_Batch_Name  := G_EndDateBatchName_Table(i).Batch_Name;
9741 				l_Found_Match := True;
9742 
9743 			End If;
9744 
9745 		End Loop;
9746 
9747                 G_Stage := 'Done searching for matching batch name record via loop.';
9748 		If G_Debug_Mode = 'Y' Then
9749                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
9750                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
9751                 End If;
9752 
9753 	End If; -- G_EndDateBatchName_Table.Count > 0
9754 
9755 	If Not l_Found_Match Then
9756 
9757         	/* Create a batch Name for Import run.*/
9758 		G_Stage := 'Get string of sysdate in YYMMDD format.';
9759 		If G_Debug_Mode = 'Y' Then
9760         	   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
9761         	   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
9762         	End If;
9763 
9764         	Select
9765                        To_Char(P_Exp_End_Date,'YYMMDD')
9766         	Into
9767                        l_Date_String
9768         	From
9769                        Dual;
9770 
9771         	G_Stage := 'Use mod(pa_expenditure_groups_s.nextval,1000) to create number value.';
9772 		If G_Debug_Mode = 'Y' Then
9773         	   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
9774         	   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
9775         	End If;
9776 
9777         	SELECT
9778                        Mod(Pa_Expenditure_Groups_S.NextVal,1000)
9779         	INTO
9780                        l_Sequence_No
9781         	FROM
9782                        Dual;
9783 
9784         	G_Stage := 'Create a batch Name for Import run.';
9785 		If G_Debug_Mode = 'Y' Then
9786         	   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
9787         	   pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
9788         	End If;
9789 
9790         	X_Batch_Name := l_Date_String || '-' || To_Char(l_Sequence_No);
9791 
9792 		l_New_Index := G_EndDateBatchName_Table.Count + 1;
9793 
9794 		G_EndDateBatchName_Table(l_New_Index).Expenditure_Ending_Date := P_Exp_End_Date;
9795 		G_EndDateBatchName_Table(l_New_Index).Batch_Name := X_Batch_Name;
9796 
9797 	End If; -- Not l_Found_Match
9798 
9799         G_Stage := 'Leaving GetBatchName(), strip procedure from trackpath.';
9800 	If G_Debug_Mode = 'Y' Then
9801            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
9802            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
9803         End If;
9804         Pa_Otc_Api.TrackPath('STRIP','GetBatchName');
9805 
9806   Exception
9807 	When Others Then
9808         	l_debug_text := 'Leaving GetBatchName() due to unhandled exception, strip procedure from trackpath.';
9809         	If G_Debug_Mode = 'Y' Then
9810            		Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || l_debug_text;
9811            		pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
9812         	End If;
9813         	Pa_Otc_Api.TrackPath('STRIP','GetBatchName');
9814 		Raise;
9815 
9816   End GetBatchName;
9817 
9818 -- =======================================================================
9819 -- Start of Comments
9820 -- API Name      : IsNumber
9821 -- Type          : Private
9822 -- Pre-Reqs      : None
9823 -- Type          : Function
9824 -- Returns       : BOOLEAN
9825 -- Function      : This functions determines if the varchar passed back is a number.
9826 --               : Used in the Validate_Process() procedure.
9827 --
9828 -- Parameters    :
9829 -- IN
9830 --              P_Value - Varchar2
9831 /*--------------------------------------------------------------------------*/
9832 
9833   Function IsNumber (P_Value IN Varchar2) Return Boolean
9834 
9835   Is
9836 
9837 	l_Converted_Value Number := Null;
9838 
9839   Begin
9840 
9841 	l_Converted_Value := to_Number(P_Value);
9842 	Return ( True );
9843 
9844   Exception
9845 
9846 	When Others Then
9847 		Return ( False );
9848 
9849   End IsNumber;
9850 
9851 
9852 -- =======================================================================
9853 -- Start of Comments
9854 -- API Name      : GetOrigTrxRef
9855 -- Type          : Private
9856 -- Pre-Reqs      : None
9857 -- Type          : Procedure
9858 -- Returns       :
9859 -- Function      : This procedure determines the max orig_transaction_reference to
9860 --               : return based on the Building Block Id passed in.
9861 --               : Since this procedure is only called when OTL is sending a detail bb for
9862 --               : adjustment of existing data in Projects a NO_DATA_FOUND error means data corruption
9863 --               : Used in the Upload_Otc_Timecards() procedure.
9864 --
9865 -- Parameters    :
9866 -- IN
9867 --              P_Building_Block_Id - Number
9868 -- OUT
9869 --              X_OrigTrxRef        - Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE
9870 --              X_Status            - Varchar2
9871 /*--------------------------------------------------------------------------*/
9872 
9873   Procedure GetOrigTrxRef (P_Building_Block_Id IN         Number,
9874 		           X_OrigTrxRef        OUT NOCOPY Varchar2,
9875 			   X_Status            OUT NOCOPY Varchar2)
9876 
9877   Is
9878 
9879 	l_Search     Pa_Expenditure_Items_All.Orig_Transaction_Reference%TYPE;
9880 	l_Error_Text Varchar2(1800);
9881 
9882   Begin
9883 
9884         G_Stage := 'Entering GetOrigTrxRef(), add procedure to trackpath.';
9885         If G_Debug_Mode = 'Y' Then
9886            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
9887            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,1);
9888         End If;
9889         Pa_Otc_Api.TrackPath('ADD','GetOrigTrxRef');
9890 
9891         G_Stage := 'Build search string.';
9892         If G_Debug_Mode = 'Y' Then
9893            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
9894            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,1);
9895         End If;
9896 	l_Search := to_char(P_Building_Block_Id) || ':%';
9897 
9898         G_Stage := 'Search ei table for available ei record.';
9899         If G_Debug_Mode = 'Y' Then
9900            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
9901            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,1);
9902         End If;
9903 	Select
9904 		Orig_Transaction_Reference
9905 	Into
9906 		X_OrigTrxRef
9907 	From
9908 		Pa_Expenditure_Items_All
9909 	Where
9910 		Orig_Transaction_Reference like l_Search
9911 	And   	Transaction_Source = 'ORACLE TIME AND LABOR'
9912 	And     Nvl(Net_Zero_Adjustment_Flag,'N') = 'N'
9913 	And     Adjusted_Expenditure_Item_Id is Null
9914 	And 	to_number(substr(Orig_Transaction_Reference,instr(Orig_Transaction_Reference,':') + 1)) = (
9915 		Select
9916 		    	Max(to_Number(Substr(Orig_Transaction_Reference,instr(Orig_Transaction_Reference,':') + 1)))
9917 		From
9918 		    	Pa_Expenditure_Items_All
9919 		Where
9920 		    	Orig_Transaction_Reference like l_Search
9921 		And 	Transaction_Source = 'ORACLE TIME AND LABOR'
9922                 And     Nvl(Net_Zero_Adjustment_Flag,'N') = 'N'
9923 		And     Adjusted_Expenditure_Item_Id is Null);
9924 
9925         G_Stage := 'Leaving GetOrigTrxRef(), strip procedure from trackpath.';
9926         If G_Debug_Mode = 'Y' Then
9927            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
9928            pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
9929         End If;
9930         Pa_Otc_Api.TrackPath('STRIP','GetOrigTrxRef');
9931 
9932   Exception
9933 	When No_Data_Found Then
9934 		-- Data corruption exists if this happens here.
9935                 l_error_text := SubStr('Pa_Otc_Api ::: ' || G_Path || ' : ' || G_Stage || ' --  ' ||
9936 				SqlErrM, 1, 1800);
9937                 fnd_message.set_name('HXC', 'HXC_RET_UNEXPECTED_ERROR');
9938                 fnd_message.set_token('ERR', l_error_text);
9939                 X_Status := SubStr(fnd_message.get,1,2000);
9940 
9941                 G_Stage := 'Leaving GetOrigTrxRef() due to unhandled exception, strip procedure from trackpath';
9942                 If G_Debug_Mode = 'Y' Then
9943                    Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
9944                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
9945                 End If;
9946                 Pa_Otc_Api.TrackPath('STRIP','GetOrigTrxRef');
9947 
9948                 If G_Debug_Mode = 'Y' Then
9949                    Pa_Debug.G_err_Stage := l_error_text;
9950                    pa_cc_utils.log_message(Pa_Debug.G_Err_Stage,0);
9951                 End If;
9952 
9953 	When Others Then
9954 		Raise;
9955 
9956   End GetOrigTrxRef;
9957 
9958 -- =======================================================================
9959 -- Start of Comments
9960 -- API Name      : GetAdditionalTrxData
9961 -- Type          : Private
9962 -- Pre-Reqs      : None
9963 -- Type          : Procedure
9964 -- Returns       :
9965 -- Function      : Gets all the addition data needed to insert records into the Trx Interface table
9966 --               : Used in the Upload_Otc_Timecards() procedure.
9967 --
9968 -- Parameters    :
9969 -- IN
9970 --      P_Ei_Date      Date
9971 --      P_Person_Id    Number
9972 -- OUT
9973 --      X_Org_Id       Number
9974 --      X_Error_Status Varchar2
9975 
9976 /*--------------------------------------------------------------------------*/
9977 
9978   Procedure GetAdditionalTrxData (P_Ei_Date      IN         Date,
9979                                   P_Person_Id    IN         Number,
9980                                   X_Org_Id       OUT NOCOPY Number,
9981                                   X_Error_Status OUT NOCOPY Varchar2)
9982 
9983  Is
9984 
9985  Begin
9986 
9987         G_Stage := 'Entering GetAdditionalTrxData(), add procedure to trackpath.';
9988 	If G_Debug_Mode = 'Y' Then
9989            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
9990            pa_cc_utils.log_message('GetAdditionalTrxData: ' || Pa_Debug.G_Err_Stage,0);
9991         End If;
9992         Pa_Otc_Api.TrackPath('ADD','GetAdditionalTrxData');
9993 
9994         G_Stage := 'Get Incurred by Organization Id.';
9995 	If G_Debug_Mode = 'Y' Then
9996            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
9997            pa_cc_utils.log_message('GetAdditionalTrxData: ' || Pa_Debug.G_Err_Stage,0);
9998         End If;
9999 
10000         Pa_Utils3.GetCachedOrgId( P_Inc_By_Per_Id => P_Person_Id,
10001                                   P_Exp_Item_Date => P_EI_Date,
10002                                   X_Inc_By_Org_Id => X_Org_Id);
10003 
10004         G_Stage := 'Incurred by Organization Id is ' || to_char(X_Org_Id) ;
10005 	If G_Debug_Mode = 'Y' Then
10006            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
10007            pa_cc_utils.log_message('GetAdditionalTrxData: ' || Pa_Debug.G_Err_Stage,0);
10008         End If;
10009 
10010 	X_Error_Status := Null;
10011 
10012         G_Stage := 'Leaving GetAdditionalTrxData(), strip procedure from trackpath.';
10013 	If G_Debug_Mode = 'Y' Then
10014            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
10015            Pa_Cc_Utils.Log_Message('GetAdditionalTrxData: ' || Pa_Debug.G_Err_Stage,0);
10016         End If;
10017         Pa_Otc_Api.TrackPath('STRIP','GetAdditionalTrxData');
10018 
10019  Exception
10020     When Others Then
10021 	X_Error_Status := 'Could not get Incurred by Organization Id.';
10022         G_Stage := 'Leaving GetAdditionalTrxData() in exception handler.';
10023         If G_Debug_Mode = 'Y' Then
10024            Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
10025            pa_cc_utils.log_message('GetAdditionalTrxData: ' || Pa_Debug.G_Err_Stage,0);
10026         End If;
10027 	Pa_Otc_Api.TrackPath('STRIP','GetAdditionalTrxData');
10028 
10029  End GetAdditionalTrxData;
10030 
10031 
10032 -- =======================================================================
10033 -- Start of Comments
10034 -- API Name      : BulkInsertReset
10035 -- Type          : Private
10036 -- Pre-Reqs      : None
10037 -- Type          : Procedure
10038 -- Returns       :
10039 -- Function      : Calls bulk insert API.
10040 --               : Empties out all the global pl/sql arrays used for the bulk insert.
10041 --               : If the P_Command is 'INSERT' then the bulk insert command table handler is executed,
10042 --               : then the pl/sql table arrays are reset for the next time thru.
10043 --               : If the P_Command is 'RESET' then pl/sql table arrays are only reset.
10044 --               : Used in the Upload_Otc_Timecards() procedure.
10045 --
10046 -- Parameters    :
10047 -- IN            :
10048 --               : P_Command   Varchar2
10049 -- OUT           : n/a
10050 
10051 /*--------------------------------------------------------------------------*/
10052 
10053   Procedure BulkInsertReset (P_Command IN Varchar2)
10054 
10055   Is
10056 
10057   Begin
10058 
10059 	G_Stage := 'Entering BulkInsertReset(), add procedure to trackpath.';
10060 	If G_Debug_Mode = 'Y' Then
10061 	   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
10062 	   pa_cc_utils.log_message('BulkInsertReset: ' || Pa_Debug.G_Err_Stage,0);
10063 	End If;
10064 	Pa_Otc_Api.TrackPath('ADD','BulkInsertReset');
10065 
10066 	If P_Command = 'INSERT' Then
10067 
10068 		G_Stage := 'Bulk Insert records into Interface table via Pa_Txn_Interface_Items_Pkg.Bulk_Insert().';
10069 		If G_Debug_Mode = 'Y' Then
10070 		   Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
10071 		   pa_cc_utils.log_message('BulkInsertReset: ' || Pa_Debug.G_Err_Stage,0);
10072 		End If;
10073 
10074 		Pa_Txn_Interface_Items_Pkg.Bulk_Insert(
10075 			   P_Txn_Interface_Id_Tbl               => G_Txn_Interface_Id_Tbl,
10076 			   P_Transaction_Source_Tbl             => G_Transaction_Source_Tbl,
10077 			   P_User_Transaction_Source_Tbl        => G_User_Transaction_Source_Tbl,
10078 			   P_Batch_Name_Tbl                     => G_Batch_Name_Tbl,
10079 			   P_Expenditure_End_Date_Tbl           => G_Expenditure_End_Date_Tbl,
10080 			   P_Person_Bus_Grp_Name_Tbl            => G_Person_Bus_Grp_Name_Tbl,
10081 			   P_Person_Bus_Grp_Id_Tbl              => G_Person_Bus_Grp_Id_Tbl,
10082 			   P_Employee_Number_Tbl                => G_Employee_Number_Tbl,
10083 			   P_Person_Id_Tbl                      => G_Person_Id_Tbl,
10084 			   P_Organization_Name_Tbl              => G_Organization_Name_Tbl,
10085 			   P_Organization_Id_Tbl                => G_Organization_Id_Tbl,
10086 			   P_Expenditure_Item_Date_Tbl          => G_Expenditure_Item_Date_Tbl,
10087 			   P_Project_Number_Tbl                 => G_Project_Number_Tbl,
10088 			   P_Project_Id_Tbl                     => G_Project_Id_Tbl,
10089 			   P_Task_Number_Tbl                    => G_Task_Number_Tbl,
10090 			   P_Task_Id_Tbl                        => G_Task_Id_Tbl,
10091 			   P_Expenditure_Type_Tbl               => G_Expenditure_Type_Tbl,
10092 			   P_System_Linkage_Tbl                 => G_System_Linkage_Tbl,
10093 			   P_Non_Labor_Resource_Tbl             => G_Non_Labor_Resource_Tbl,
10094 			   P_Non_Labor_Res_Org_Name_Tbl         => G_Non_Labor_Res_Org_Name_Tbl,
10095 			   P_Non_Labor_Res_Org_Id_Tbl           => G_Non_Labor_Res_Org_Id_Tbl,
10096 			   P_Quantity_Tbl                       => G_Quantity_Tbl,
10097 			   P_Raw_Cost_Tbl                       => G_Raw_Cost_Tbl,
10098 			   P_Raw_Cost_Rate_Tbl                  => G_Raw_Cost_Rate_Tbl,
10099 			   P_Burden_Cost_Tbl                    => G_Burden_Cost_Tbl,
10100 			   P_Burden_Cost_Rate_Tbl               => G_Burden_Cost_Rate_Tbl,
10101 			   P_Expenditure_Comment_Tbl            => G_Expenditure_Comment_Tbl,
10102 			   P_Gl_Date_Tbl                        => G_Gl_Date_Tbl,
10103 			   P_Transaction_Status_Code_Tbl        => G_Transaction_Status_Code_Tbl,
10104 			   P_Trans_Rejection_Code_Tbl           => G_Trans_Rejection_Code_Tbl,
10105 			   P_Orig_Trans_Reference_Tbl           => G_Orig_Trans_Reference_Tbl,
10106 			   P_Unmatched_Neg_Txn_Flag_Tbl         => G_Unmatched_Neg_Txn_Flag_Tbl,
10107 			   P_Expenditure_Id_Tbl                 => G_Expenditure_Id_Tbl,
10108 			   P_Attribute_Category_Tbl             => G_Attribute_Category_Tbl,
10109 			   P_Attribute1_Tbl                     => G_Attribute1_Tbl,
10110 			   P_Attribute2_Tbl                     => G_Attribute2_Tbl,
10111 			   P_Attribute3_Tbl                     => G_Attribute3_Tbl,
10112 			   P_Attribute4_Tbl                     => G_Attribute4_Tbl,
10113 			   P_Attribute5_Tbl                     => G_Attribute5_Tbl,
10114 			   P_Attribute6_Tbl                     => G_Attribute6_Tbl,
10115 			   P_Attribute7_Tbl                     => G_Attribute7_Tbl,
10116 			   P_Attribute8_Tbl                     => G_Attribute8_Tbl,
10117 			   P_Attribute9_Tbl                     => G_Attribute9_Tbl,
10118 			   P_Attribute10_Tbl                    => G_Attribute10_Tbl,
10119 			   P_Dr_Code_Combination_Id_Tbl         => G_Dr_Code_Combination_Id_Tbl,
10120 			   P_Cr_Code_Combination_Id_Tbl         => G_Cr_Code_Combination_Id_Tbl,
10121 			   P_Cdl_System_Reference1_Tbl          => G_Cdl_System_Reference1_Tbl,
10122 			   P_Cdl_System_Reference2_Tbl          => G_Cdl_System_Reference2_Tbl,
10123 			   P_Cdl_System_Reference3_Tbl          => G_Cdl_System_Reference3_Tbl,
10124 			   P_Interface_Id_Tbl                   => G_Interface_Id_Tbl,
10125 			   P_Receipt_Currency_Amount_Tbl        => G_Receipt_Currency_Amount_Tbl,
10126 			   P_Receipt_Currency_Code_Tbl          => G_Receipt_Currency_Code_Tbl,
10127 			   P_Receipt_Exchange_Rate_Tbl          => G_Receipt_Exchange_Rate_Tbl,
10128 			   P_Denom_Currency_Code_Tbl            => G_Denom_Currency_Code_Tbl,
10129 			   P_Denom_Raw_Cost_Tbl                 => G_Denom_Raw_Cost_Tbl,
10130 			   P_Denom_Burdened_Cost_Tbl            => G_Denom_Burdened_Cost_Tbl,
10131 			   P_Acct_Rate_Date_Tbl                 => G_Acct_Rate_Date_Tbl,
10132 			   P_Acct_Rate_Type_Tbl                 => G_Acct_Rate_Type_Tbl,
10133 			   P_Acct_Exchange_Rate_Tbl             => G_Acct_Exchange_Rate_Tbl,
10134 			   P_Acct_Raw_Cost_Tbl                  => G_Acct_Raw_Cost_Tbl,
10135 			   P_Acct_Burdened_Cost_Tbl             => G_Acct_Burdened_Cost_Tbl,
10136 			   P_Acct_Exch_Rounding_Limit_Tbl       => G_Acct_Exch_Rounding_Limit_Tbl,
10137 			   P_Project_Currency_Code_Tbl          => G_Project_Currency_Code_Tbl,
10138 			   P_Project_Rate_Date_Tbl              => G_Project_Rate_Date_Tbl,
10139 			   P_Project_Rate_Type_Tbl              => G_Project_Rate_Type_Tbl,
10140 			   P_Project_Exchange_Rate_Tbl          => G_Project_Exchange_Rate_Tbl,
10141 			   P_Orig_Exp_Txn_Reference1_Tbl        => G_Orig_Exp_Txn_Reference1_Tbl,
10142 			   P_Orig_Exp_Txn_Reference2_Tbl        => G_Orig_Exp_Txn_Reference2_Tbl,
10143 			   P_Orig_Exp_Txn_Reference3_Tbl        => G_Orig_Exp_Txn_Reference3_Tbl,
10144 			   P_Orig_User_Exp_Txn_Ref_Tbl          => G_Orig_User_Exp_Txn_Ref_Tbl,
10145 			   P_Vendor_Number_Tbl                  => G_Vendor_Number_Tbl,
10146 			   P_Vendor_Id_Tbl                      => G_Vendor_Id_Tbl,
10147 			   P_Override_To_Org_Name_Tbl           => G_Override_To_Org_Name_Tbl,
10148 			   P_Override_To_Org_Id_Tbl             => G_Override_To_Org_Id_Tbl,
10149 			   P_Reversed_Orig_Txn_Ref_Tbl          => G_Reversed_Orig_Txn_Ref_Tbl,
10150 			   P_Billable_Flag_Tbl                  => G_Billable_Flag_Tbl,
10151 			   P_ProjFunc_Currency_Code_Tbl         => G_ProjFunc_Currency_Code_Tbl,
10152 			   P_ProjFunc_Cost_Rate_Date_Tbl        => G_ProjFunc_Cost_Rate_Date_Tbl,
10153 			   P_ProjFunc_Cost_Rate_Type_Tbl        => G_ProjFunc_Cost_Rate_Type_Tbl,
10154 			   P_ProjFunc_Cost_Exch_Rate_Tbl        => G_ProjFunc_Cost_Exch_Rate_Tbl,
10155 			   P_Project_Raw_Cost_Tbl               => G_Project_Raw_Cost_Tbl,
10156 			   P_Project_Burdened_Cost_Tbl          => G_Project_Burdened_Cost_Tbl,
10157 			   P_Assignment_Name_Tbl                => G_Assignment_Name_Tbl,
10158 			   P_Assignment_Id_Tbl                  => G_Assignment_Id_Tbl,
10159 			   P_Work_Type_Name_Tbl                 => G_Work_Type_Name_Tbl,
10160 			   P_Work_Type_Id_Tbl                   => G_Work_Type_Id_Tbl,
10161 			   P_Cdl_System_Reference4_Tbl          => G_Cdl_System_Reference4_Tbl,
10162 			   P_Accrual_Flag_Tbl                   => G_Accrual_Flag_Tbl,
10163 			   P_Last_Update_Date_Tbl               => G_Last_Update_Date_Tbl,
10164 			   P_Last_Updated_By_Tbl                => G_Last_Updated_By_Tbl,
10165 			   P_Creation_Date_Tbl                  => G_Creation_Date_Tbl,
10166 			   P_Created_By_Tbl                     => G_Created_By_Tbl,
10167 			   P_PO_Number_Tbl			            => G_PO_Number_Tbl,
10168 			   P_PO_Header_Id_Tbl			        => G_PO_Header_Id_Tbl,
10169 			   P_PO_Line_Num_Tbl			        => G_PO_Line_Num_Tbl,
10170 			   P_PO_Line_Id_Tbl                     => G_PO_Line_Id_Tbl,
10171 			   P_PO_Price_Type_Tbl                  => G_PO_Price_Type_Tbl,
10172 			   P_Person_Type_Tbl                    => G_Person_Type_Tbl,
10173 			   P_Inventory_Item_Id_Tbl              => G_Inventory_Item_Id_Tbl,
10174 			   P_WIP_Resource_Id_Tbl		        => G_WIP_Resource_Id_Tbl,
10175     		   P_Unit_Of_Measure_Tbl		        => G_Unit_Of_Measure_Tbl,
10176                P_Org_Id_Tbl                         => G_OU_Tbl,
10177                -- Bug 10253400.. 12.2 payroll intg .. start
10178                P_Job_Id_Tbl                         => G_Job_Id_Tbl,
10179                p_Job_Name_Tbl                       => G_Job_Name_Tbl,
10180                p_location_Code_tbl                  => G_Location_Code_Tbl,
10181                p_pay_element_Type_Id_tbl            => G_Pay_Element_Type_Id_Tbl,
10182                P_Location_Id_Tbl                    => G_Location_ID_Tbl
10183                -- Bug 10253400.. 12.2 payroll intg .. end
10184 			   -- Start: Added for CBS Enhancement Bug 16220146
10185 			   ,P_Cbs_Element_Id_Tbl                 => G_Cbs_Element_Id_Tbl
10186 			   ,P_Cbs_Element_Name_Tbl               => G_Cbs_Element_Name_Tbl
10187 			   -- End: Added for CBS Enhancement Bug 16220146
10188 			   );
10189 
10190 	End If;
10191 
10192 	If P_Command in ( 'INSERT', 'RESET' ) Then
10193 
10194         G_Stage := 'Reset all pl/sql table arrays used for bulk insert.';
10195 		If G_Debug_Mode = 'Y' Then
10196              Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
10197              pa_cc_utils.log_message('BulkInsertReset: ' || Pa_Debug.G_Err_Stage,0);
10198         End If;
10199 
10200 		G_Txn_Interface_Id_Tbl.Delete;
10201 		G_Transaction_Source_Tbl.Delete;
10202 		G_User_Transaction_Source_Tbl.Delete;
10203 		G_Batch_Name_Tbl.Delete;
10204 		G_Expenditure_End_Date_Tbl.Delete;
10205 		G_Person_Bus_Grp_Name_Tbl.Delete;
10206 		G_Person_Bus_Grp_Id_Tbl.Delete;
10207 		G_Employee_Number_Tbl.Delete;
10208 		G_Person_Id_Tbl.Delete;
10209 		G_Organization_Name_Tbl.Delete;
10210 		G_Organization_Id_Tbl.Delete;
10211 		G_Expenditure_Item_Date_Tbl.Delete;
10212 		G_Project_Number_Tbl.Delete;
10213 		G_Project_Id_Tbl.Delete;
10214 		G_Task_Number_Tbl.Delete;
10215 		G_Task_Id_Tbl.Delete;
10216 		G_Expenditure_Type_Tbl.Delete;
10217 		G_System_Linkage_Tbl.Delete;
10218 		G_Non_Labor_Resource_Tbl.Delete;
10219 		G_Non_Labor_Res_Org_Name_Tbl.Delete;
10220 		G_Non_Labor_Res_Org_Id_Tbl.Delete;
10221 		G_Quantity_Tbl.Delete;
10222 		G_Raw_Cost_Tbl.Delete;
10223 		G_Raw_Cost_Rate_Tbl.Delete;
10224 		G_Burden_Cost_Tbl.Delete;
10225 		G_Burden_Cost_Rate_Tbl.Delete;
10226 		G_Expenditure_Comment_Tbl.Delete;
10227 		G_Gl_Date_Tbl.Delete;
10228 		G_Transaction_Status_Code_Tbl.Delete;
10229 		G_Trans_Rejection_Code_Tbl.Delete;
10230 		G_Orig_Trans_Reference_Tbl.Delete;
10231 		G_Unmatched_Neg_Txn_Flag_Tbl.Delete;
10232 		G_Expenditure_Id_Tbl.Delete;
10233 		G_Attribute_Category_Tbl.Delete;
10234 		G_Attribute1_Tbl.Delete;
10235 		G_Attribute2_Tbl.Delete;
10236 		G_Attribute3_Tbl.Delete;
10237 		G_Attribute4_Tbl.Delete;
10238 		G_Attribute5_Tbl.Delete;
10239 		G_Attribute6_Tbl.Delete;
10240 		G_Attribute7_Tbl.Delete;
10241 		G_Attribute8_Tbl.Delete;
10242 		G_Attribute9_Tbl.Delete;
10243 		G_Attribute10_Tbl.Delete;
10244 		G_Dr_Code_Combination_Id_Tbl.Delete;
10245 		G_Cr_Code_Combination_Id_Tbl.Delete;
10246 		G_Cdl_System_Reference1_Tbl.Delete;
10247 		G_Cdl_System_Reference2_Tbl.Delete;
10248 		G_Cdl_System_Reference3_Tbl.Delete;
10249 		G_Interface_Id_Tbl.Delete;
10250 		G_Receipt_Currency_Amount_Tbl.Delete;
10251 		G_Receipt_Currency_Code_Tbl.Delete;
10252 		G_Receipt_Exchange_Rate_Tbl.Delete;
10253 		G_Denom_Currency_Code_Tbl.Delete;
10254 		G_Denom_Raw_Cost_Tbl.Delete;
10255 		G_Denom_Burdened_Cost_Tbl.Delete;
10256 		G_Acct_Rate_Date_Tbl.Delete;
10257 		G_Acct_Rate_Type_Tbl.Delete;
10258 		G_Acct_Exchange_Rate_Tbl.Delete;
10259 		G_Acct_Raw_Cost_Tbl.Delete;
10260 		G_Acct_Burdened_Cost_Tbl.Delete;
10261 		G_Acct_Exch_Rounding_Limit_Tbl.Delete;
10262 		G_Project_Currency_Code_Tbl.Delete;
10263 		G_Project_Rate_Date_Tbl.Delete;
10264 		G_Project_Rate_Type_Tbl.Delete;
10265 		G_Project_Exchange_Rate_Tbl.Delete;
10266 		G_Orig_Exp_Txn_Reference1_Tbl.Delete;
10267 		G_Orig_Exp_Txn_Reference2_Tbl.Delete;
10268 		G_Orig_Exp_Txn_Reference3_Tbl.Delete;
10269 		G_Orig_User_Exp_Txn_Ref_Tbl.Delete;
10270 		G_Vendor_Number_Tbl.Delete;
10271 		G_Vendor_Id_Tbl.Delete;
10272 		G_Override_To_Org_Name_Tbl.Delete;
10273 		G_Override_To_Org_Id_Tbl.Delete;
10274 		G_Reversed_Orig_Txn_Ref_Tbl.Delete;
10275 		G_Billable_Flag_Tbl.Delete;
10276 		G_ProjFunc_Currency_Code_Tbl.Delete;
10277 		G_ProjFunc_Cost_Rate_Date_Tbl.Delete;
10278 		G_ProjFunc_Cost_Rate_Type_Tbl.Delete;
10279 		G_ProjFunc_Cost_Exch_Rate_Tbl.Delete;
10280 		G_Project_Raw_Cost_Tbl.Delete;
10281 		G_Project_Burdened_Cost_Tbl.Delete;
10282 		G_Assignment_Name_Tbl.Delete;
10283 		G_Assignment_Id_Tbl.Delete;
10284 		G_Work_Type_Name_Tbl.Delete;
10285 		G_Work_Type_Id_Tbl.Delete;
10286 		G_Cdl_System_Reference4_Tbl.Delete;
10287 		G_Accrual_Flag_Tbl.Delete;
10288 		G_Last_Update_Date_Tbl.Delete;
10289 		G_Last_Updated_By_Tbl.Delete;
10290 		G_Creation_Date_Tbl.Delete;
10291 		G_Created_By_Tbl.Delete;
10292 		-- Begin PA.M/CWK changes
10293 		G_PO_Number_Tbl.Delete;
10294 		G_PO_Header_Id_Tbl.Delete;
10295 		G_PO_Line_Num_Tbl.Delete;
10296 		G_PO_Line_Id_Tbl.Delete;
10297 		G_PO_Price_Type_Tbl.Delete;
10298 		G_Person_Type_Tbl.Delete;
10299 		-- End PA.M/CWK changes
10300 		G_Inventory_Item_Id_Tbl.Delete;
10301 		G_WIP_Resource_Id_Tbl.Delete;
10302     	G_Unit_Of_Measure_Tbl.Delete;
10303         -- 12i MOAC changes
10304         G_OU_Tbl.Delete;
10305         -- Bug 10253400.. 12.2 payroll intg .. start
10306         G_Job_Id_Tbl.delete;
10307         G_Location_Id_Tbl.delete;
10308         G_Job_Name_Tbl.delete;
10309         G_Location_Code_Tbl.delete;
10310         G_Pay_Element_Type_Id_Tbl.delete;
10311         -- Bug 10253400.. 12.2 payroll intg .. end
10312         -- Bug 10253400.. 12.2 payroll intg .. end
10313 		-- Start: Added for CBS Enhancement Bug 16220146
10314 		G_Cbs_Element_Id_Tbl.delete;
10315 		G_Cbs_Element_Name_Tbl.delete;
10316 		-- End: Added for CBS Enhancement Bug 16220146
10317 
10318 	End If;
10319 
10320     G_Stage := 'Leaving BulkInsertReset(), strip procedure from trackpath.';
10321 	If G_Debug_Mode = 'Y' Then
10322          Pa_Debug.G_err_Stage := 'Pa_Otc_Api ::: ' || G_Path || ' :: ' || G_Stage;
10323          Pa_Cc_Utils.Log_Message('BulkInsertReset: ' || Pa_Debug.G_Err_Stage,0);
10324     End If;
10325     Pa_Otc_Api.TrackPath('STRIP','BulkInsertReset');
10326 
10327   Exception
10328 	When Others Then
10329 		Raise;
10330 
10331   End BulkInsertReset;
10332 
10333 -- =======================================================================
10334 -- Start of Comments
10335 -- API Name      : TrxInCurrentChunk
10336 -- Type          : Private
10337 -- Pre-Reqs      : None
10338 -- Type          : Function
10339 -- Returns       : Varchar2
10340 -- Function      : Determine if the Trx in part of the current chunk being processed.
10341 --               : Since we now have the looping functionality in Trx Import and we have to restrict the cursor
10342 --               : more in what it picks up.  We have to make sure that we don't try to update rejected
10343 --               : Trx records from other loops that have already been ran.  They are at a status of 'R'
10344 --               : So we check to see if it exists in the pl/sql table and then if it does
10345 --               : we update the otl pl/sql table accordingly run.
10346 --               : Used in the Tieback_Otc_Timecards() procedure.
10347 --
10348 -- Parameters    :
10349 -- IN            :
10350 --               : P_Detail_BB_Id  - Number
10351 -- OUT           : n/a
10352 
10353 /*--------------------------------------------------------------------------*/
10354 
10355   Function TrxInCurrentChunk (P_Detail_BB_Id IN Number) Return Varchar2 Is
10356 
10357   Begin
10358 
10359         If G_Trx_Inserted_Tab.Exists(P_Detail_BB_Id) Then
10360 
10361                 Return ( 'Y' );
10362 
10363         Else
10364 
10365                 Return ( 'N' );
10366 
10367         End If;
10368 
10369   Exception
10370 	When Others Then
10371 		Raise;
10372 
10373 
10374   End TrxInCurrentChunk;
10375 
10376 -- =======================================================================
10377 -- Start of Comments
10378 -- API Name      : GetProjectManager
10379 -- Type          : Public
10380 -- Pre-Reqs      : None
10381 -- Type          : Function
10382 -- Returns       : Number
10383 -- Function      : Returns the current project manager, person_id, for a project
10384 --
10385 -- Parameters    :
10386 -- IN            :
10387 --               : P_Project_Id  - Number
10388 -- OUT           : n/a
10389 
10390 /*--------------------------------------------------------------------------*/
10391 
10392   Function GetProjectManager ( P_Project_Id IN Number ) Return Number Is
10393 
10394         l_Proj_Mgr_Person_Id Number := Null;
10395 
10396   Begin
10397 
10398          l_Proj_Mgr_Person_Id := Pa_Projects_Maint_Utils.Get_Project_Manager(p_project_id);
10399          Return l_Proj_Mgr_Person_Id;
10400 
10401   Exception
10402         When Others Then
10403                 Raise;
10404 
10405 
10406   End GetProjectManager;
10407 
10408 -- =======================================================================
10409 -- Start of Comments
10410 -- API Name      : GetPersonType
10411 -- Type          : Private
10412 -- Pre-Reqs      : None
10413 -- Type          : Function
10414 -- Returns       : Varchar2
10415 -- Function      : Returns the Person Type based on the employee id.
10416 --                 Valid Values: 'CWK' or 'EMP'
10417 --
10418 -- Parameters    :
10419 -- IN            :
10420 --               : P_Person_Id  - NUMBER
10421 --		 : P_Ei_Date    - DATE
10422 -- OUT           : n/a
10423 
10424 /*--------------------------------------------------------------------------*/
10425 
10426   Function GetPersonType ( P_Person_Id IN Number, P_Ei_Date IN Date) Return Varchar2
10427 
10428   Is
10429 
10430 	X_Person_Type Pa_Expenditures_All.Person_Type%TYPE := Null;
10431 
10432   Begin
10433 
10434 	Select
10435 		Decode(Current_Npw_Flag,'Y','CWK','EMP')
10436 	Into
10437 		X_Person_Type
10438 	From
10439 		Per_People_F
10440 	Where
10441 		P_Ei_Date between Effective_Start_Date
10442 			      and Effective_End_Date
10443 	And	Person_Id = P_Person_Id;
10444 
10445 	Return ( X_Person_Type );
10446 
10447   Exception
10448 	When Others Then
10449 		Return ( Null );
10450 
10451   End GetPersonType;
10452 
10453 
10454 -- =======================================================================
10455 -- Start of Comments
10456 -- API Name      : GetPOInfo
10457 -- Type          : Private
10458 -- Pre-Reqs      : None
10459 -- Type          : Procedure
10460 -- Returns       : n/a
10461 -- Function      : Returns the Vendor_Id and PO_Header_Id
10462 --
10463 -- Parameters    :
10464 -- IN            :
10465 --               : P_PO_Line_Id   - Number
10466 -- OUT           :
10467 --		 : X_Po_Header_Id - Number
10468 --		 : X_Vendor_Id    - Number
10469 
10470 /*--------------------------------------------------------------------------*/
10471 
10472   Procedure GetPOInfo(P_Po_Line_Id   In         Number,
10473 		      X_Po_Header_Id OUT NOCOPY Number,
10474 		      X_Vendor_Id    OUT NOCOPY Number)
10475 
10476   Is
10477 
10478 	l_Vendor_Id 	Number := Null;
10479 	l_Po_Header_Id  Number := Null;
10480 
10481   Begin
10482 
10483 	If nvl(G_Po_Line_Id,-99999) <> P_Po_Line_Id Then
10484 
10485 		Select
10486 			h.Vendor_Id,
10487 			h.Po_Header_Id
10488 		Into
10489 			l_Vendor_Id,
10490 			l_Po_Header_Id
10491 		from
10492 			PO_Headers_All h,
10493 		     	PO_Lines_All l
10494 		where
10495 			l.po_line_Id = P_Po_Line_Id
10496 		and	l.po_header_id = h.po_header_Id;
10497 
10498 		G_Po_Line_Id   := P_Po_Line_Id;
10499 		G_Vendor_Id    := l_Vendor_Id;
10500 		G_PO_Header_Id := l_Po_Header_Id;
10501 
10502 	End If;
10503 
10504 	X_Po_Header_Id := G_PO_Header_Id;
10505 	X_Vendor_Id := G_Vendor_Id;
10506 
10507   Exception
10508 	When Others Then
10509 		Null;
10510 
10511   End GetPOInfo;
10512 
10513 
10514 END Pa_Otc_Api ;