DBA Data[Home] [Help]

PACKAGE BODY: APPS.OZF_ACTBUDGETS_PVT

Source


1 PACKAGE BODY ozf_actbudgets_pvt AS
2 /*$Header: ozfvbdgb.pls 120.39.12020000.4 2012/10/18 04:27:39 kdass ship $*/
3    -- NAME
4    --   OZF_ACTBUDGETS_PVT
5    --
6    -- HISTORY
7    -- 04/12/2000  sugupta  CREATED
8    --  25-Jun-2000   choang   Commented out show errors and uncommented exit
9    --  14-Aug-2000   choang   1) Removed colums: contribution_amount, contribution_currency,
10    --                         contribution_uom.  2) Added columns: request_amount, request_currency,
11    --                         approved_amount, approved_original_amount, approved_in_currency, sent_amount, sent_currency,
12    --                         transaction_type.  3) Modified partner_po_number to varchar2(50).
13    --  16-Aug-2000   choang   Implemented Approve_ActBudget and Reject_ActBudget
14    --  18-Aug-2000   choang   Added calls to Fund's API for update of the fund according to the action
15    --                         on the budget source: 1) submit for approval - add to forecast budget of
16    --                         the fund 2) approve - add to commited budget of the fund 3) reject - subtract
17    --                         from the forecast budget of the fund.
18    --  20-Aug-2000   choang   Added user_status_id.
19    --  22-Aug-2000   choang   Added get_approver(), can_modify() and is_account_closed().
20    --  24-Aug-2000   choang   approval and rejection of budget should also include approver_id.
21    --  30-Aug-2000   choang   Corr ected currency conversion values when budget source is submitted for approval.
22    --  05-Sep-2000   choang   Fixed bug 1397577 - added deliverable as consumer of budget source.
23    --                         Modified call to ozf_funds_pvt.update_fund to include p_mode = 'WORKFLOW'
24    --                         to by-pass validation of budget status.
25    --  12-Sep-2000   choang   1) Moved approval API's to OZF_BudgetApproval_PVT.
26    --                         2) Removed get_approver()  3) Modified trigger_approval_process()
27    --  14-Sep-2000   choang   Moved approval processing steps into procedure process_approval().
28    --  17-Sep-2000   choang   Added status_id's to call to ams_approval_pvt.start_lineapproval.
29    --                         Added revert_approval for wf approval error handling.
30    --  29-Sep-2000   choang   Added partner in budget source id validation.
31    --  07-Nov-2000   choang   Rejected records do not count as record when considering
32    --                         for cue card "tick".
33    --  23-Jan-2001   mpande   Added validation in validation_actbudget_rec  for not to submit for approval when the requested amount is 0
34    --      BUG# 1604000
35    --  31-Jan-2001   mpande   Removed access from ozf_fund_details_V to ozf_funds_all_vl for cross organzation validation.
36    --  02/10/2001    mpande   BUG #1637319 only for INternal rollout
37    --  22-Feb-2001   mpande   Modified for All Hornet changes.
38    --                          1) Addded 7 new  columns and added functional validation
39    --                          2) ALL FUND_TRANSFERS and requests are going to be performed from this table--  Added code for that
40    --                          3) Integrated with notes API to create justification and comments
41    --  04/26/2001   MPande    1)Added code for utilizarions , requesterId , date_requred_by , transfertype and respective validations
42    --                         2) Added code for Parent sourc_id -- This value is always Budget id
43    --                         3) Added Code for transfer_type - Utilizations
44    --                         4) Added Code fo rApproval reqd
45    --                         5) Removed utlization API to ozf_fund_Adjustment_pvt
46    --                         6) can modify , is account closed -- procedure removed
47    --                         7) Made all functional changes reqd for different types of transfer
48    -- 06/072001    feliu      Added partner_holding_type, partner_address_id, vendor_id.
49    -- 06/14/2001   mpande     Added code for EONE .
50    -- 10/12/2001   mpande     Changed Code to submit partner approval also (not for approval )
51    --                         Commented Product Eligibility validation
52    -- 10/22/2001   mpande    Changed code different owner allocation bug
53   --  10/23/2001   feliu      Added recal_flag column and one more input p_act_util_rec in create_act_budgets.
54   --  11/07/2001   feliu      Changed process_approval to update recal_committed column.
55   --  01/15/2002   feliu      change to partner_party_id from partner_id to fix budg 2182197.
56   --  01/21/2002   feliu      change back partner_id from partner_party_id.
57   --  03/21/2002   mpande     added because Deliverables reconciliation was not working properly
58   --  04/16/2002   feliu      Moved some functions to OZF_ACTBUDGETRULES_PVT to reduce this file size.
59   --  6/11/2002    mpande     Fully accrued budget would have no committment
60  --   10/28/2002   feliu       Change for 11.5.9
61  --   10/27/2002   feliu      added offer validation.
62   --  10/28/2002   feliu     added scan_unit,scan_unit_remaining,activity_product_id,scan_type_id for act_util_rec_type.
63   --  12/05/2002   feliu      fixed nocopy issue.
64 --    12/23/2002   feliu       Changed for chargback.
65   --  03/21/2003   feliu      fixed bug 2861097 by:
66   --                          1.for budget transfer, call start wowkflow after update act budget.
67   --   10-May-2004 feliu add business event for budget request approval.
68  --    11-Aug-2004 rimehrot   Modified code to avoid duplicate currency conversion in process_approval.
69    --   12/08/2004  feliu       fix bug 4032144.
70   --  02/25/2005  feliu       fix bug 4174002.
71   --  05/19/2005  gramanat    Added support for Offer Worksheet(WKST) to source from Budgets.
72   --  08/05/2005  feliu       1. not create record in ozf_funds_utilized_all_b for REQUEST.
73   --                          2. change validate for check_transfer_amount_exists.
74   --                          3. calculate src_curr_request_amount before validation.
75   --  08/17/2005  sangara     fix 11.5.9 bug 4553660
76   --  09/05/2005  rimehrot    fix r12 bug 4030115
77   --  11/16/2005  kdass       fixed bug 4728515
78   --  03/16/2006  kdass       fixed bug 5080481 - exposed flexfields
79   --  03/31/2006  kdass       fixed bug 5101720 - query fund_request_curr_code if offer has no currency defined
80   --  17/May/2006 asylvia     fixed bug 5190932 - Message text for error OZF_NO_LEDGER_FOUND changed
81   --  6/6/6       mkothari    reverted changes due to bug 5143254 - special price currency reqd
82   --  08/01/2008  nirprasa    fixed bug 7030415
83   --  10/08/2008  nirprasa    fixed bug 7425189
84   --  10/08/2008  nirprasa    fixed bug 7505085 and rounding issues of bug 7425189.
85   --                          skip the conversion for reconciliation flow of src_curr_req_amt.
86   --  01/15/2009  nirprasa    fixed bug 7697861.
87   --  06/12/2009  kdass       bug 8532055 - ADD EXCHANGE RATE DATE PARAM TO OZF_FUND_UTILIZED_PUB.CREATE_FUND_ADJUSTMENT API
88   --  07/24/2009  kdass       Bug 8726683 - SSD Adjustments ER - Return utilization_id to the adjustment API
89   --  2/17/2010   nepanda     Bug 9131648 : multi currency changes
90   --  5/5/2010    nepanda     Bug 9625995 : Transaction currency value in Recalculated commited page is not getting converted.
91   --  04/01/2011  muthsubr    Fix for bug#8867381 - IDSM BATCH PAYMENT INITIALIZATION ERROR
92   --  04/01/2011  muthsubr    For TPA Parallel Execution ER Bug#9614703.
93   --  10/5/2011   nepanda     Fix for bug 12911854 : rounded the amount values in ozf_act_budgets table
94   --  10/17/2012  nepanda     Fix for Bug 14724414 - tst1213:getting error while approving accrual offer [changes made on ver 120.21.12010000.16]
95   -- Note
96    -- Please refer the spec for validation rules in this table
97    -- The following is the mapping of the currency Columns
98    -- request_currency -- act_budget_used_by_id Currency
99    -- approved_in_currency -- budget_source_id Currency
100    ----------------------------------------------------------------------------------------------------
101 
102    g_package_name     CONSTANT VARCHAR2 (30) := 'OZF_ACTBUDGETS_PVT';
103    g_file_name        CONSTANT VARCHAR2 (12) := 'ozfvbdgb.pls';
104    g_cons_fund_mode   CONSTANT VARCHAR2 (30) := 'ADJUST';
105    g_recal_flag CONSTANT VARCHAR2(1) :=  NVL(fnd_profile.value('OZF_BUDGET_ADJ_ALLOW_RECAL'),'N');
106    g_universal_currency   CONSTANT VARCHAR2 (15) := fnd_profile.VALUE ('OZF_UNIV_CURR_CODE');
107    G_DEBUG BOOLEAN := FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_debug_high);
108 
109 
110 /*****************************************************************************************/
111 -- Start of Comments
112 --
113    --
114    -- NAME
115    --    trigger_approval_process
116    -- PURPOSE
117    --    Handle Workflow approval request processing.
118 /*****************************************************************************************/
119    PROCEDURE trigger_approval_process (
120       p_act_budget_rec         IN       act_budgets_rec_type
121      ,x_act_budget_rec         IN OUT NOCOPY   act_budgets_rec_type
122      ,x_return_status          OUT NOCOPY      VARCHAR2
123      ,x_msg_count              OUT NOCOPY      NUMBER
124      ,x_msg_data               OUT NOCOPY      VARCHAR2
125      ,p_parent_process_flag    IN       VARCHAR2
126      ,p_parent_process_key     IN       VARCHAR2
127      ,p_parent_context         IN       VARCHAR2
128      ,p_parent_approval_flag   IN       VARCHAR2
129      ,p_continue_flow          IN       VARCHAR2
130      ,p_child_approval_flag    IN       VARCHAR2 := fnd_api.g_false
131       -- 10/22/2001   mpande    Changed code different owner allocation bug
132      ,p_requestor_owner_flag   IN       VARCHAR2 := 'N'
133      ,x_start_flow_flag        OUT NOCOPY   VARCHAR2
134         -- added on 03/20/03
135    ); -- added 05/22/2001 mpande
136 
137 
138 /*****************************************************************************************/
139 -- Start of Comments
140    --
141    -- NAME
142    --    process_approval
143    -- PURPOSE
144    --    Handle all tasks needed before a budget line
145    --    can be approved.
146 /*****************************************************************************************/
147    PROCEDURE process_approval (
148       p_act_budget_rec   IN       act_budgets_rec_type
149      ,x_act_budget_rec   OUT NOCOPY      act_budgets_rec_type
150      ,x_return_status    OUT NOCOPY      VARCHAR2
151      ,x_msg_count        OUT NOCOPY      NUMBER
152      ,x_msg_data         OUT NOCOPY      VARCHAR2
153      ,p_mode             IN       VARCHAR2 :='UPDATE'-- added by mpande 12/27/2001
154    );
155 
156 /*****************************************************************************************/
157 -- Start of Comments
158    --
159    -- NAME
160    --    process_approval
161    -- PURPOSE
162    --    Handle all tasks needed before a budget line
163    --    can be approved.
164    -- 27/10/2009  muthsubr   Added  p_use_fund_staging_tables, px_ozf_funds_old_rectype,
165    --                        px_ozf_funds_new_rectype for bug#8867381.
166    -- 29/11/2010  muthsubr   Altered px_ozf_funds_new_rectype to px_ozf_funds_new_tbl
167 --                           for TPA Parallel Execution ER Bug#9614703.
168 /*****************************************************************************************/
169    PROCEDURE process_approval (
170       p_act_budget_rec   IN       act_budgets_rec_type
171      ,x_act_budget_rec   OUT NOCOPY      act_budgets_rec_type
172      ,x_return_status    OUT NOCOPY      VARCHAR2
173      ,x_msg_count        OUT NOCOPY      NUMBER
174      ,x_msg_data         OUT NOCOPY      VARCHAR2
175      ,p_mode             IN       VARCHAR2 :='UPDATE'-- added by mpande 12/27/2001
176      ,p_resale_batch_id  IN  NUMBER DEFAULT NULL
177      ,p_batch_type           IN  VARCHAR2
178      ,p_use_fund_staging_tables IN VARCHAR2 DEFAULT 'F'
179      ,px_ozf_funds_old_rectype  IN      OZF_UTILITY_PVT.ozf_funds_all_b_rectype
180      ,px_ozf_funds_new_tbl  IN OUT NOCOPY   OZF_UTILITY_PVT.ozf_funds_table  -- For TPA Parallel Execution ER - 9614703
181    );
182 /*****************************************************************************************/
183 -- Start of Comments
184    --
185    -- NAME
186    --    Revert_Approval
187    -- PURPOSE
188    --    Revert the changes done when a budget line is
189    --    submitted for approval.  For FUND lines, revert
190    --    the planned amount.
191 /*****************************************************************************************/
192    PROCEDURE revert_approval (
193       p_act_budget_rec   IN       act_budgets_rec_type
194      ,p_use_fund_staging_tables  IN VARCHAR2
195      ,x_act_budget_rec   OUT NOCOPY      act_budgets_rec_type
196      ,x_return_status    OUT NOCOPY      VARCHAR2
197      ,x_msg_count        OUT NOCOPY      NUMBER
198      ,x_msg_data         OUT NOCOPY      VARCHAR2
199    );
200 
201 -----------------------------------------------------------------------
202 -- PROCEDURE
203 --    raise_business_event
204 --
205 -- HISTORY
206 --    05/08/2004  feliu  Created.
207 -----------------------------------------------------------------------
208 
209 
210 PROCEDURE raise_business_event(p_object_id IN NUMBER)
211 IS
212 l_item_key varchar2(30);
213 l_parameter_list wf_parameter_list_t;
214 BEGIN
215   l_item_key := p_object_id ||'_'|| TO_CHAR(SYSDATE,'DDMMRRRRHH24MISS');
216   l_parameter_list := WF_PARAMETER_LIST_T();
217 
218 
219   IF G_DEBUG THEN
220     ozf_utility_pvt.debug_message(' activity budget  Id is :'||p_object_id );
221   END IF;
222 
223     wf_event.AddParameterToList(p_name           => 'P_ACTBUDGET_ID',
224                               p_value          => p_object_id,
225                               p_parameterlist  => l_parameter_list);
226 
227    IF G_DEBUG THEN
228        ozf_utility_pvt.debug_message('Item Key is  :'||l_item_key);
229   END IF;
230 
231     wf_event.raise( p_event_name =>'oracle.apps.ozf.fund.request.approval',
232                   p_event_key  => l_item_key,
233                   p_parameters => l_parameter_list);
234 
235 
236 EXCEPTION
237 WHEN OTHERS THEN
238 RAISE Fnd_Api.g_exc_error;
239 ozf_utility_pvt.debug_message('Exception in raising business event');
240 END;
241 
242 /*****************************************************************************************/
243 -- Start of Comments
244 --
245 -- NAME
246 --   Create_Act_Budgets
247 --
248 -- PURPOSE
249 --   This procedure is to create a Budget record that satisfy caller needs
250 --
251 -- HISTORY
252 -- 04/12/2000  sugupta  CREATED
253 -- 14-Aug-2000 choang   Modified for spec signature change.
254 -- 22-Feb-2001 mpande   Modified for Hornet changes.
255 -- 29-OCT-2001 feliu    Modified for recalculating committment.
256 -- End of Comments
257 /*****************************************************************************************/
258    PROCEDURE create_act_budgets (
259       p_api_version        IN       NUMBER
260      ,p_init_msg_list      IN       VARCHAR2 := fnd_api.g_false
261      ,p_commit             IN       VARCHAR2 := fnd_api.g_false
262      ,p_validation_level   IN       NUMBER := fnd_api.g_valid_level_full
263      ,x_return_status      OUT NOCOPY      VARCHAR2
264      ,x_msg_count          OUT NOCOPY      NUMBER
265      ,x_msg_data           OUT NOCOPY      VARCHAR2
266      ,p_act_budgets_rec    IN       act_budgets_rec_type
267      ,x_act_budget_id      OUT NOCOPY      NUMBER
268    ) IS
269      BEGIN
270      create_act_budgets (
271               p_api_version        => p_api_version
272              ,p_init_msg_list      => p_init_msg_list
273              ,p_commit             => p_commit
274              ,p_validation_level   => p_validation_level
275              ,x_return_status      => x_return_status
276              ,x_msg_count          => x_msg_count
277              ,x_msg_data           => x_msg_data
278              ,p_act_budgets_rec    => p_act_budgets_rec
279              ,p_act_util_rec       => G_MISS_ACT_UTIL_REC
280              ,x_act_budget_id      => x_act_budget_id
281              ,p_approval_flag      => fnd_api.g_false
282              --p_approval_flag      IN       VARCHAR2 := fnd_api.g_false  means approval required
283            );
284 
285    END create_act_budgets;
286 
287 
288    /****************************************************************************
289     *  Ying Zhao: 06/21/2004 overloaded function to return actual utilized amount for chargeback
290     *             added x_utilized_amount
291     */
292    PROCEDURE create_act_budgets (
293       p_api_version        IN       NUMBER
294      ,p_init_msg_list      IN       VARCHAR2 := fnd_api.g_false
295      ,p_commit             IN       VARCHAR2 := fnd_api.g_false
296      ,p_validation_level   IN       NUMBER := fnd_api.g_valid_level_full
297      ,x_return_status      OUT NOCOPY      VARCHAR2
298      ,x_msg_count          OUT NOCOPY      NUMBER
299      ,x_msg_data           OUT NOCOPY      VARCHAR2
300      ,p_act_budgets_rec    IN       act_budgets_rec_type
301      ,p_act_util_rec       IN       act_util_rec_type
302      ,x_act_budget_id      OUT NOCOPY      NUMBER
303      ,p_approval_flag      IN       VARCHAR2 := fnd_api.g_false
304    ) IS
305      l_utilized_amount     NUMBER;
306    BEGIN
307      create_act_budgets (
308               p_api_version        => p_api_version
309              ,p_init_msg_list      => p_init_msg_list
310              ,p_commit             => p_commit
311              ,p_validation_level   => p_validation_level
312              ,x_return_status      => x_return_status
313              ,x_msg_count          => x_msg_count
314              ,x_msg_data           => x_msg_data
315              ,p_act_budgets_rec    => p_act_budgets_rec
316              ,p_act_util_rec       => p_act_util_rec
317              ,x_act_budget_id      => x_act_budget_id
318              ,p_approval_flag      => p_approval_flag
319              ,x_utilized_amount    => l_utilized_amount
320            );
321    END create_act_budgets;
322 
323 
324    /****************************************************************************
325     * 27/10/2009  muthsubr      Overloaded create_act_budgets adding p_use_fund_staging_tables,
326     *                           px_ozf_funds_old_rectype, px_ozf_funds_new_rectype for bug#8867381.
327     * 29/11/2010  muthsubr      Altered px_ozf_funds_new_rectype to px_ozf_funds_new_tbl
328     *                           for TPA Parallel Execution ER Bug#9614703.
329     *****************************************************************************/
330    PROCEDURE create_act_budgets (
331       p_api_version        IN       NUMBER
332      ,p_init_msg_list      IN       VARCHAR2 := fnd_api.g_false
333      ,p_commit             IN       VARCHAR2 := fnd_api.g_false
334      ,p_validation_level   IN       NUMBER := fnd_api.g_valid_level_full
335      ,x_return_status      OUT NOCOPY      VARCHAR2
336      ,x_msg_count          OUT NOCOPY      NUMBER
337      ,x_msg_data           OUT NOCOPY      VARCHAR2
338      ,p_act_budgets_rec    IN       act_budgets_rec_type
339      ,p_act_util_rec       IN       act_util_rec_type
340      ,x_act_budget_id      OUT NOCOPY      NUMBER
341      ,p_approval_flag      IN       VARCHAR2 := fnd_api.g_false
342      ,x_utilized_amount    OUT NOCOPY      NUMBER
343    ) IS
344      l_utilized_amount     NUMBER;
345      l_resale_batch_id     NUMBER;
346      l_use_fund_staging_tables VARCHAR2(1) := 'F';
347      lx_ozf_act_budgets_tbl  OZF_UTILITY_PVT.ozf_act_budgets_table;
348      lx_ozf_funds_old_rectype OZF_UTILITY_PVT.ozf_funds_all_b_rectype;
349      lx_ozf_funds_new_tbl OZF_UTILITY_PVT.ozf_funds_table;
350      l_batch_type VARCHAR2(30);
351    BEGIN
352 
353      --kdass - added for Bug 8726683
354      create_act_budgets (
355               p_api_version        => p_api_version
356              ,p_init_msg_list      => p_init_msg_list
357              ,p_commit             => p_commit
358              ,p_validation_level   => p_validation_level
359              ,x_return_status      => x_return_status
360              ,x_msg_count          => x_msg_count
361              ,x_msg_data           => x_msg_data
362              ,p_act_budgets_rec    => p_act_budgets_rec
363              ,p_act_util_rec       => p_act_util_rec
364              ,x_act_budget_id      => x_act_budget_id
365              ,p_approval_flag      => p_approval_flag
366              ,x_utilized_amount    => x_utilized_amount
367              ,p_resale_batch_id    => l_resale_batch_id
368              ,p_batch_type           =>    l_batch_type
369              ,p_use_fund_staging_tables => l_use_fund_staging_tables
370              ,px_ozf_act_budgets_tbl =>  lx_ozf_act_budgets_tbl
371              ,px_ozf_funds_old_rectype  =>  lx_ozf_funds_old_rectype
372              ,px_ozf_funds_new_tbl  =>  lx_ozf_funds_new_tbl                    -- For TPA Parallel Execution ER - 9614703
373            );
374    END create_act_budgets;
375 
376     --nirprasa added for bug
377     PROCEDURE create_act_budgets (
378       p_api_version        IN       NUMBER
379      ,p_init_msg_list      IN       VARCHAR2 := fnd_api.g_false
380      ,p_commit             IN       VARCHAR2 := fnd_api.g_false
381      ,p_validation_level   IN       NUMBER := fnd_api.g_valid_level_full
382      ,x_return_status      OUT NOCOPY      VARCHAR2
383      ,x_msg_count          OUT NOCOPY      NUMBER
384      ,x_msg_data           OUT NOCOPY      VARCHAR2
385      ,p_act_budgets_rec    IN       act_budgets_rec_type
386      ,p_act_util_rec       IN       act_util_rec_type
387      ,x_act_budget_id      OUT NOCOPY      NUMBER
388      ,p_approval_flag      IN       VARCHAR2 := fnd_api.g_false
389      ,x_utilized_amount    OUT NOCOPY      NUMBER
390      ,x_utilization_id OUT NOCOPY      NUMBER
391    ) IS
392      l_utilized_amount     NUMBER;
393      l_resale_batch_id     NUMBER;
394      l_use_fund_staging_tables VARCHAR2(1) := 'F';
395      lx_ozf_act_budgets_tbl   OZF_UTILITY_PVT.ozf_act_budgets_table;
396      lx_ozf_funds_old_rectype OZF_UTILITY_PVT.ozf_funds_all_b_rectype;
397      lx_ozf_funds_new_tbl     OZF_UTILITY_PVT.ozf_funds_table;
398      l_batch_type VARCHAR2(30);
399    BEGIN
400      create_act_budgets (
401               p_api_version        => p_api_version
402              ,p_init_msg_list      => p_init_msg_list
403              ,p_commit             => p_commit
404              ,p_validation_level   => p_validation_level
405              ,x_return_status      => x_return_status
406              ,x_msg_count          => x_msg_count
407              ,x_msg_data           => x_msg_data
408              ,p_act_budgets_rec    => p_act_budgets_rec
409              ,p_act_util_rec       => p_act_util_rec
410              ,x_act_budget_id      => x_act_budget_id
411              ,p_approval_flag      => p_approval_flag
412              ,x_utilized_amount    => l_utilized_amount
413              ,p_resale_batch_id    =>  l_resale_batch_id
414              ,p_batch_type           =>    l_batch_type
415              ,p_use_fund_staging_tables =>  l_use_fund_staging_tables
416              ,px_ozf_act_budgets_tbl =>  lx_ozf_act_budgets_tbl
417              ,px_ozf_funds_old_rectype  =>  lx_ozf_funds_old_rectype
418              ,px_ozf_funds_new_tbl  =>  lx_ozf_funds_new_tbl                            -- For TPA Parallel Execution ER - 9614703
419              ,x_utilization_id  => x_utilization_id
420            );
421    END create_act_budgets;
422 
423 
424    /*****************************************************************************************/
425 -- Start of Comments
426 --
427 -- NAME
428 --   Create_Act_Budgets
429 --
430 -- PURPOSE
431 --   This procedure is to create a Budget record that satisfy caller needs
432 --
433 -- HISTORY
434 -- 04/12/2000  sugupta  CREATED
435 -- 14-Aug-2000 choang   Modified for spec signature change.
436 -- 22-Feb-2001 mpande   Modified for Hornet changes.
437 -- 29-OCT-2001 feliu    Modified for recalculating committment.
438 -- 12/18/2001  mpande   Added code for checkbook _v
439                         -- p_approval_flag      IN       VARCHAR2 := fnd_api.g_false  means approval required
440                         -- request amount would always be in act_budget_used_by curr
441 -- 27/10/2009  muthsubr Overloaded create_act_budgets adding p_use_fund_staging_tables,
442 --                      px_ozf_funds_old_rectype, px_ozf_funds_new_rectype for bug#8867381.
443 -- 29/11/2010  muthsubr Altered px_ozf_funds_new_rectype to px_ozf_funds_new_tbl
444 --                      for TPA Parallel Execution ER Bug#9614703.
445 -- End of Comments
446 /*****************************************************************************************/
447    PROCEDURE create_act_budgets (
448       p_api_version        IN       NUMBER
449      ,p_init_msg_list      IN       VARCHAR2 := fnd_api.g_false
450      ,p_commit             IN       VARCHAR2 := fnd_api.g_false
451      ,p_validation_level   IN       NUMBER := fnd_api.g_valid_level_full
452      ,x_return_status      OUT NOCOPY      VARCHAR2
453      ,x_msg_count          OUT NOCOPY      NUMBER
454      ,x_msg_data           OUT NOCOPY      VARCHAR2
455      ,p_act_budgets_rec    IN       act_budgets_rec_type
456      ,p_act_util_rec       IN       act_util_rec_type
457      ,x_act_budget_id      OUT NOCOPY      NUMBER
458      ,p_approval_flag      IN       VARCHAR2 := fnd_api.g_false
459      ,x_utilized_amount    OUT NOCOPY      NUMBER              -- yzhao: 06/21/2004 added for chargeback
460      ,p_resale_batch_id    IN  NUMBER
461      ,p_batch_type           IN  VARCHAR2
462      ,p_use_fund_staging_tables IN       VARCHAR2
463      ,px_ozf_act_budgets_tbl IN OUT  NOCOPY  OZF_UTILITY_PVT.ozf_act_budgets_table
464      ,px_ozf_funds_old_rectype  IN      OZF_UTILITY_PVT.ozf_funds_all_b_rectype
465      ,px_ozf_funds_new_tbl  IN OUT  NOCOPY  OZF_UTILITY_PVT.ozf_funds_table   -- For TPA Parallel Execution ER - 9614703
466    ) IS
467    l_utilization_id NUMBER;
468    BEGIN
469      --nirprasa added for bug 9383565
470      create_act_budgets (
471               p_api_version        => p_api_version
472              ,p_init_msg_list      => p_init_msg_list
473              ,p_commit             => p_commit
474              ,p_validation_level   => p_validation_level
475              ,x_return_status      => x_return_status
476              ,x_msg_count          => x_msg_count
477              ,x_msg_data           => x_msg_data
478              ,p_act_budgets_rec    => p_act_budgets_rec
479              ,p_act_util_rec       => p_act_util_rec
480              ,x_act_budget_id      => x_act_budget_id
481              ,p_approval_flag      => p_approval_flag
482              ,x_utilized_amount    => x_utilized_amount
483              ,p_resale_batch_id    => p_resale_batch_id
484              ,p_batch_type           =>    p_batch_type
485              ,p_use_fund_staging_tables => p_use_fund_staging_tables
486              ,px_ozf_act_budgets_tbl =>  px_ozf_act_budgets_tbl
487              ,px_ozf_funds_old_rectype  =>  px_ozf_funds_old_rectype
488              ,px_ozf_funds_new_tbl  =>  px_ozf_funds_new_tbl            -- For TPA Parallel Execution ER - 9614703
489              ,x_utilization_id  => l_utilization_id
490            );
491    END create_act_budgets;
492 
493    PROCEDURE create_act_budgets (
494       p_api_version        IN       NUMBER
495      ,p_init_msg_list      IN       VARCHAR2 := fnd_api.g_false
496      ,p_commit             IN       VARCHAR2 := fnd_api.g_false
497      ,p_validation_level   IN       NUMBER := fnd_api.g_valid_level_full
498      ,x_return_status      OUT NOCOPY      VARCHAR2
499      ,x_msg_count          OUT NOCOPY      NUMBER
500      ,x_msg_data           OUT NOCOPY      VARCHAR2
501      ,p_act_budgets_rec    IN       act_budgets_rec_type
502      ,p_act_util_rec       IN       act_util_rec_type
503      ,x_act_budget_id      OUT NOCOPY      NUMBER
504      ,p_approval_flag      IN       VARCHAR2 := fnd_api.g_false
505      ,x_utilized_amount    OUT NOCOPY      NUMBER              -- yzhao: 06/21/2004 added for chargeback
506      ,p_resale_batch_id    IN  NUMBER
507      ,p_batch_type           IN  VARCHAR2
508      ,p_use_fund_staging_tables IN       VARCHAR2
509      ,px_ozf_act_budgets_tbl IN OUT  NOCOPY  OZF_UTILITY_PVT.ozf_act_budgets_table
510      ,px_ozf_funds_old_rectype  IN      OZF_UTILITY_PVT.ozf_funds_all_b_rectype
511      ,px_ozf_funds_new_tbl  IN OUT  NOCOPY  OZF_UTILITY_PVT.ozf_funds_table     -- For TPA Parallel Execution ER - 9614703
512      ,x_utilization_id     OUT NOCOPY      NUMBER --nirprasa added for bug 9383565
513    ) IS
514       l_api_name      CONSTANT VARCHAR2 (30)        := 'Create_Act_Budgets';
515       l_api_version   CONSTANT NUMBER               := 1.0;
516       l_full_name     CONSTANT VARCHAR2 (60)        :=    g_package_name
517                                                        || '.'
518                                                        || l_api_name;
519       l_status_type   CONSTANT VARCHAR2 (30)        := 'OZF_BUDGETSOURCE_STATUS';
520       -- Status Local Variables
521       l_return_status          VARCHAR2 (1); -- Return value from procedures
522       l_act_budgets_rec        act_budgets_rec_type := p_act_budgets_rec;
523       l_act_util_rec           act_util_rec_type := p_act_util_rec;
524       l_temp_rec               act_budgets_rec_type := p_act_budgets_rec;
525       l_act_budget_id          NUMBER;
526       l_dummy                  NUMBER;
527       l_fund_transfer_flag     VARCHAR2 (1)         := 'N';
528       l_request_id   NUMBER;
529       l_custom_setup_id NUMBER;
530       l_fund_reconc_msg VARCHAR2(4000);
531       l_act_bud_cst_msg VARCHAR2(4000);
532 
533       CURSOR c_offer_info(p_object_id IN NUMBER) IS
534         SELECT custom_setup_id
535         FROM ozf_offers
536         WHERE qp_list_header_id = p_object_id;
537 
538       CURSOR c_act_budget_id IS
539          SELECT ozf_act_budgets_s.NEXTVAL
540            FROM DUAL;
541 
542       CURSOR c_id_exists (p_id IN NUMBER) IS
543          SELECT 1
544            FROM ozf_act_budgets
545           WHERE activity_budget_id = p_id;
546 
547       CURSOR c_check_quota (p_type IN VARCHAR2, p_fund_id IN NUMBER) IS
548          SELECT 1
549          FROM  ozf_funds_all_b
550          WHERE 'FUND' = p_type
551            AND fund_type = 'QUOTA'
552            AND fund_id = p_fund_id;
553 
554      --Added for bug 7030415
555 
556        CURSOR c_get_conversion_type( p_org_id IN NUMBER) IS
557        SELECT exchange_rate_type
558        FROM   ozf_sys_parameters_all
559        WHERE  org_id = p_org_id;
560 
561       -- nepanda : Fix for 12911854
562       CURSOR c_get_gl_info(p_ledger_id IN NUMBER) IS
563       SELECT currency_code
564       FROM   gl_ledgers_public_v
565       WHERE  ledger_id = p_ledger_id;
566 
567       l_fc_amount                  NUMBER;
568       l_set_of_books_id            NUMBER;
569       l_mrc_sob_type_code          VARCHAR2(30);
570       l_fc_currency_code           VARCHAR2(150);
571       l_exchange_rate_type         VARCHAR2(150) := FND_API.G_MISS_CHAR;
572       l_exchange_rate              NUMBER;
573       -- mpande for changed checkbook view 12/17/2001
574       l_src_curr_request_amt       NUMBER;
575       l_src_currency               VARCHAR2(150);
576       l_rate                       NUMBER;
577       l_check_validation   VARCHAR2(50) := fnd_profile.value('OZF_CHECK_MKTG_PROD_ELIG');
578       l_ledger_id                  NUMBER;
579       l_ledger_name                VARCHAR2(30);
580       l_is_quota                   NUMBER := NULL;
581 
582       --nirprasa,12.1.1
583       l_transaction_currency       VARCHAR2(150);
584       l_temp_request_amount        NUMBER;
585       l_temp_approved_amount       NUMBER;
586       l_temp_aprvd_orig_amount       NUMBER;
587    BEGIN
588       IF G_DEBUG THEN
589          ozf_utility_pvt.debug_message (   l_full_name
590                                      || ': start');
591       END IF;
592       -- Standard Start of API savepoint
593       SAVEPOINT create_act_budgets_pvt;
594 
595       -- Standard call to check for call compatibility.
596       IF NOT fnd_api.compatible_api_call (l_api_version, p_api_version, l_api_name, g_package_name) THEN
597          RAISE fnd_api.g_exc_unexpected_error;
598       END IF;
599 
600       ozf_utility_pvt.debug_message(' create_Act_budgets.plan_currency_code mg: '  || p_act_util_rec.plan_currency_code);
601 
602       -- Initialize message list IF p_init_msg_list is set to TRUE.
603       IF fnd_api.to_boolean (p_init_msg_list) THEN
604          fnd_msg_pub.initialize;
605       END IF;
606 
607       --  Initialize API return status to success
608       x_return_status            := fnd_api.g_ret_sts_success;
609 
610       -- API body
611       -- Initialize default values before validation
612       -- Get ID for activity budget from sequence.
613 
614       IF l_act_budgets_rec.activity_budget_id IS NULL THEN
615          LOOP
616             l_dummy                    := NULL;
617             OPEN c_act_budget_id;
618             FETCH c_act_budget_id INTO l_act_budgets_rec.activity_budget_id;
619             CLOSE c_act_budget_id;
620             OPEN c_id_exists (l_act_budgets_rec.activity_budget_id);
621             FETCH c_id_exists INTO l_dummy;
622             CLOSE c_id_exists;
623             EXIT WHEN l_dummy IS NULL;
624          END LOOP;
625       END IF;
626 
627      IF G_DEBUG THEN
628      ozf_utility_pvt.debug_message ('request_currency '||l_act_budgets_rec.request_currency);
629      ozf_utility_pvt.debug_message ('arc_act_budget_used_by '||l_act_budgets_rec.arc_act_budget_used_by);
630      ozf_utility_pvt.debug_message ('act_budget_used_by_id '||l_act_budgets_rec.act_budget_used_by_id);
631      END IF;
632 
633      IF l_act_budgets_rec.request_currency IS NULL
634      OR l_act_budgets_rec.request_currency = FND_API.G_MISS_CHAR THEN
635       l_act_budgets_rec.request_currency :=
636             get_object_currency (
637                l_act_budgets_rec.arc_act_budget_used_by
638               ,l_act_budgets_rec.act_budget_used_by_id
639               ,l_return_status
640             );
641      END IF;
642      --nirprasa,ER 8399134
643      l_transaction_currency := l_act_util_rec.plan_currency_code;
644       IF l_act_budgets_rec.request_currency <> l_transaction_currency
645         AND l_act_budgets_rec.arc_act_budget_used_by = 'OFFR' THEN
646           l_act_budgets_rec.request_currency := l_transaction_currency;
647       END IF;
648 
649      --Added for bug 7425189
650      l_fund_reconc_msg := fnd_message.get_string ('OZF', 'OZF_FUND_RECONCILE');
651      l_act_bud_cst_msg := fnd_message.get_string ('OZF', 'OZF_ACT_BUDG_CST_UTIL');
652 
653       /*12/19/2001 mpande Added code for UI requirement , when a object is transfering money he would request in
654        object's currency and not source currency since here the source is the object, in case of transfer */
655       IF l_act_budgets_rec.transfer_type = 'TRANSFER' THEN
656          l_act_budgets_rec.approved_in_currency :=
657             get_object_currency (
658                l_act_budgets_rec.budget_source_type
659               ,l_act_budgets_rec.budget_source_id
660               ,l_return_status
661             );
662          IF G_DEBUG THEN
663             ozf_utility_pvt.debug_message ('approved_in_currency '||l_act_budgets_rec.approved_in_currency);
664             ozf_utility_pvt.debug_message ('request_currency '||l_act_budgets_rec.request_currency);
665             ozf_utility_pvt.debug_message ('request_amount '||l_act_budgets_rec.request_amount);
666             ozf_utility_pvt.debug_message ('src_curr_req_amt '||l_act_budgets_rec.src_curr_req_amt);
667             ozf_utility_pvt.debug_message ('budget_source_type '||l_act_budgets_rec.budget_source_type);
668             ozf_utility_pvt.debug_message ('l_transaction_currency '||l_transaction_currency);
669          END IF;
670          --nirprasa,12.2 Condition l_act_budgets_rec.budget_source_type <> 'FUND' THEN
671          --is used instead of l_act_budgets_rec.budget_source_type = 'OFFR' THEN
672          --because the same code gets executed for marketing objects also.
673          --Except for 'fund transfer' this code will be executed for all object transfer.
674          IF l_act_budgets_rec.approved_in_currency <> l_transaction_currency
675          AND l_act_budgets_rec.budget_source_type <> 'FUND' THEN
676                 --nepanda :  fixed for bug # 9625995 : no need to convert approved in curr to transaction curr.
677                 -- all calculations are done based on approved in curr as the budget curr
678              l_act_budgets_rec.approved_in_currency := l_act_budgets_rec.approved_in_currency; --l_transaction_currency;
679          END IF;
680          -- do this only if it is null because , in other case request amount should be passed correctly
681          IF l_act_budgets_rec.request_amount IS NULL AND l_act_budgets_rec.src_curr_req_amt IS NOT NULL THEN
682             IF l_act_budgets_rec.request_currency = l_act_budgets_rec.approved_in_currency THEN
683                -- don't need to convert if currencies are equal
684                l_act_budgets_rec.request_amount := l_act_budgets_rec.src_curr_req_amt;
685             ELSE
686 
687 
688                IF G_DEBUG THEN
689                   ozf_utility_pvt.debug_message (   l_full_name
690                                      || ' l_act_budgets_rec.exchange_rate_date1: ' || l_act_budgets_rec.exchange_rate_date);
691                END IF;
692 
693                ozf_utility_pvt.convert_currency (
694                   x_return_status => l_return_status
695                  ,p_from_currency => l_act_budgets_rec.approved_in_currency
696                  ,p_to_currency   => l_act_budgets_rec.request_currency
697                  ,p_conv_date     => l_act_budgets_rec.exchange_rate_date --bug 7425189, 8532055
698                  ,p_from_amount   => l_act_budgets_rec.src_curr_req_amt
699                  ,x_to_amount     => l_act_budgets_rec.request_amount
700                );
701               /*
702                -- convert the src_curr_request amount to the act_used_by  currency request amount.
703                --Added for bug 7425189, pass exchange_rate_date = approval date of REQUEST
704               IF l_act_budgets_rec.justification IN (l_fund_reconc_msg,l_act_bud_cst_msg)
705                 AND l_act_budgets_rec.exchange_rate_date IS NOT NULL
706                 AND l_act_budgets_rec.transfer_type = 'TRANSFER' THEN
707                ozf_utility_pvt.convert_currency (
708                   x_return_status=> l_return_status
709                  ,p_from_currency=> l_act_budgets_rec.approved_in_currency
710                  ,p_to_currency=> l_act_budgets_rec.request_currency
711                  ,p_conv_date=> l_act_budgets_rec.exchange_rate_date
712                  ,p_from_amount=> l_act_budgets_rec.src_curr_req_amt
713                  ,x_to_amount=> l_act_budgets_rec.request_amount
714                );
715               ELSE
716 
717                ozf_utility_pvt.convert_currency (
718                   x_return_status=> l_return_status
719                  ,p_from_currency=> l_act_budgets_rec.approved_in_currency
720                  ,p_to_currency=> l_act_budgets_rec.request_currency
721                  ,p_from_amount=> l_act_budgets_rec.src_curr_req_amt
722                  ,x_to_amount=> l_act_budgets_rec.request_amount
723                );
724               END IF;
725               */
726 
727                IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
728                   RAISE fnd_api.g_exc_unexpected_error;
729                ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
730                   RAISE fnd_api.g_exc_error;
731                END IF;
732             END IF;
733          END IF;
734       END IF;
735      /* End OF Change mpande 12/19/2001 */
736 
737       IF l_act_budgets_rec.request_currency IS NULL THEN
738          ozf_utility_pvt.error_message ('OZF_ACT_BUDG_NO_CURRENCY');
739          x_return_status            := fnd_api.g_ret_sts_error;
740       END IF;
741 
742       IF l_return_status = fnd_api.g_ret_sts_error THEN
743          RAISE fnd_api.g_exc_error;
744       ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
745          RAISE fnd_api.g_exc_unexpected_error;
746       END IF;
747 
748       -- Added 04/26/2001 mpande for new functionality changes for hornet
749       ---System Populates the parent Source Id
750       IF l_act_budgets_rec.transfer_type IN ('RELEASE', 'RESERVE') THEN
751          l_act_budgets_rec.status_code := 'APPROVED';
752          l_act_budgets_rec.approved_amount := l_act_budgets_rec.request_amount;
753          l_act_budgets_rec.approved_original_amount := l_act_budgets_rec.request_amount;
754          l_act_budgets_rec.approved_in_currency := l_act_budgets_rec.request_currency;
755 
756       ELSIF p_approval_flag = fnd_api.g_true THEN  -- Added by feliu for recalculating committment.
757          l_act_budgets_rec.status_code := 'APPROVED';
758          -- yzhao: 10/20/2003 automatically populate approved amount, currency information if it is not passed in
759          --l_act_budgets_rec.approved_amount := l_act_budgets_rec.approved_amount;
760          --l_act_budgets_rec.approved_original_amount := l_act_budgets_rec.approved_original_amount;
761          --l_act_budgets_rec.approved_in_currency := l_act_budgets_rec.approved_in_currency;
762       ELSIF l_act_budgets_rec.transfer_type IN ('TRANSFER', 'UTILIZED') THEN
763          l_act_budgets_rec.status_code := NVL (l_act_budgets_rec.status_code, 'NEW');
764       ELSE
765          l_act_budgets_rec.status_code := 'NEW';
766       END IF;
767 
768           -- Add by feliu on 05/22/04 for referal.
769       IF  l_act_budgets_rec.arc_act_budget_used_by = 'OFFR' THEN
770           OPEN c_offer_info(l_act_budgets_rec.act_budget_used_by_id);
771           FETCH c_offer_info INTO l_custom_setup_id;
772           CLOSE c_offer_info;
773        END IF;
774 
775       IF  l_act_budgets_rec.status_code = 'APPROVED'
776            AND NVL(l_custom_setup_id,0) = 105
777           AND NVL(l_check_validation, 'NO') <> 'NO'
778           AND l_act_budgets_rec.arc_act_budget_used_by = 'OFFR'
779           AND l_act_budgets_rec.budget_source_type = 'FUND'
780           AND  l_act_budgets_rec.transfer_type = 'REQUEST'  THEN
781                 l_act_budgets_rec.status_code := 'PENDING_VALIDATION';
782       END IF;
783 
784       IF G_DEBUG THEN
785          ozf_utility_pvt.debug_message ('approved_amount '|| l_act_budgets_rec.approved_amount);
786          ozf_utility_pvt.debug_message ('status_code '|| l_act_budgets_rec.status_code);
787       END IF;
788 
789       -- yzhao: 10/20/2003 automatically populate approved amount, currency information if it is not passed in
790       IF l_act_budgets_rec.status_code = 'APPROVED' THEN
791          IF l_act_budgets_rec.approval_date IS NULL OR
792             l_act_budgets_rec.approval_date = fnd_api.g_miss_date THEN
793             l_act_budgets_rec.approval_date := sysdate;
794          END IF;
795 
796          IF l_act_budgets_rec.approver_id IS NULL OR
797             l_act_budgets_rec.approver_id = fnd_api.g_miss_num THEN
798             l_act_budgets_rec.approver_id := ams_utility_pvt.get_resource_id (fnd_global.user_id);
799          END IF;
800 
801          IF l_act_budgets_rec.approved_amount IS NULL OR
802             l_act_budgets_rec.approved_amount = fnd_api.g_miss_num THEN
803             l_act_budgets_rec.approved_amount := l_act_budgets_rec.request_amount;
804          END IF;
805 
806          IF l_act_budgets_rec.approved_in_currency IS NULL OR
807             l_act_budgets_rec.approved_in_currency = fnd_api.g_miss_char THEN
808             l_act_budgets_rec.approved_in_currency :=
809                get_object_currency (
810                  l_act_budgets_rec.budget_source_type
811                 ,l_act_budgets_rec.budget_source_id
812                 ,l_return_status
813                );
814                --nirprasa,12.2 now should use transaction currency
815                IF l_act_budgets_rec.approved_in_currency <> l_transaction_currency
816                   AND l_act_budgets_rec.arc_act_budget_used_by = 'OFFR' THEN
817                      l_act_budgets_rec.approved_in_currency := l_transaction_currency;
818                END IF;
819             IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
820                RAISE fnd_api.g_exc_unexpected_error;
821             ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
822                RAISE fnd_api.g_exc_error;
823             END IF;
824          END IF;
825 
826 
827 
828          IF l_act_budgets_rec.approved_original_amount IS NULL OR
829             l_act_budgets_rec.approved_original_amount = fnd_api.g_miss_num THEN
830 
831              IF l_act_budgets_rec.request_currency = l_act_budgets_rec.approved_in_currency THEN
832                 -- don't need to convert if currencies are equal
833                 l_act_budgets_rec.approved_original_amount := l_act_budgets_rec.request_amount;
834              ELSE
835 
836                 --No change required.continue using conversion type profile.
837                 --since this code is used for fund sourcing.
838                 --In case of utilization flow If condition is true always.
839                 --Else never gets executed for utilization.
840 
841                IF G_DEBUG THEN
842                   ozf_utility_pvt.debug_message (   l_full_name
843                                      || ' l_act_budgets_rec.exchange_rate_date2: ' || l_act_budgets_rec.exchange_rate_date);
844                END IF;
845 
846                ozf_utility_pvt.convert_currency (
847                   x_return_status => l_return_status
848                  ,p_from_currency => l_act_budgets_rec.request_currency
849                  ,p_to_currency   => l_act_budgets_rec.approved_in_currency
850                  ,p_conv_date     => l_act_budgets_rec.exchange_rate_date --bug 7425189, 8532055
851                  ,p_from_amount   => l_act_budgets_rec.request_amount
852                  ,x_to_amount     => l_act_budgets_rec.approved_original_amount
853                 );
854 
855                 /*
856                 --nirprasa, for bug 7425189, this code gets executed for TRANSFER, i.e while
857                 --reconciling unutilized committed amount
858                 IF l_act_budgets_rec.justification IN (l_fund_reconc_msg,l_act_bud_cst_msg)
859                 AND l_act_budgets_rec.exchange_rate_date IS NOT NULL
860                 AND l_act_budgets_rec.transfer_type = 'TRANSFER' THEN
861                 ozf_utility_pvt.convert_currency (
862                   x_return_status=> l_return_status
863                  ,p_from_currency=> l_act_budgets_rec.request_currency
864                  ,p_to_currency=> l_act_budgets_rec.approved_in_currency
865                  ,p_conv_date=> l_act_budgets_rec.exchange_rate_date
866                  ,p_from_amount=> l_act_budgets_rec.request_amount
867                  ,x_to_amount=> l_act_budgets_rec.approved_original_amount
868                 );
869 
870                 ELSE
871 
872                 ozf_utility_pvt.convert_currency (
873                   x_return_status=> l_return_status
874                  ,p_from_currency=> l_act_budgets_rec.request_currency
875                  ,p_to_currency=> l_act_budgets_rec.approved_in_currency
876                  ,p_from_amount=> l_act_budgets_rec.request_amount
877                  ,x_to_amount=> l_act_budgets_rec.approved_original_amount
878                 );
879                 END IF;
880                 */
881 
882 
883                 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
884                    RAISE fnd_api.g_exc_unexpected_error;
885                 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
886                    RAISE fnd_api.g_exc_error;
887                 END IF;
888              END IF;
889          END IF;
890       END IF;   -- IF l_act_budgets_rec.status_code = 'APPROVED' THEN
891 
892       l_act_budgets_rec.user_status_id :=
893               ozf_utility_pvt.get_default_user_status (l_status_type, l_act_budgets_rec.status_code);
894 
895       IF l_return_status = fnd_api.g_ret_sts_error THEN
896          RAISE fnd_api.g_exc_error;
897       ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
898          RAISE fnd_api.g_exc_unexpected_error;
899       END IF;
900 
901 
902 ----------------------- validate -----------------------
903       IF G_DEBUG THEN
904          ozf_utility_pvt.debug_message (   l_full_name
905                                      || ': validate');
906       END IF;
907 
908       -- mpande added to populate request amount in request currency 12/17/2001 src_curr_request_amt
909       IF l_act_budgets_rec.budget_source_type IN ('PTNR','OPTN') THEN
910          l_src_currency := l_act_budgets_rec.request_currency ;
911       ELSE
912       l_src_currency :=
913             get_object_currency (
914                l_act_budgets_rec.budget_source_type
915               ,l_act_budgets_rec.budget_source_id
916               ,l_return_status
917             );
918       END IF;
919 
920       IF G_DEBUG THEN
921          ozf_utility_pvt.debug_message (   l_api_name||'l_src_currency '|| l_src_currency);
922          ozf_utility_pvt.debug_message (   l_api_name||'budget_source_type '|| l_act_budgets_rec.budget_source_type);
923          ozf_utility_pvt.debug_message (   l_api_name||'budget_source_id '|| l_act_budgets_rec.budget_source_id);
924       END IF;
925 
926       --This call is for transfer_type='UTILIZED'/'REQUEST' both cases.
927       --So, I need to do the conversion in case of utilized
928 
929 
930       --Added for bug 7030415 , get the rate based on org only if it is for utilized.
931       IF l_act_budgets_rec.transfer_type = 'UTILIZED' THEN
932          OPEN c_get_conversion_type(l_act_util_rec.org_id);
933          FETCH c_get_conversion_type INTO l_exchange_rate_type;
934          CLOSE c_get_conversion_type;
935       ELSE
936          l_exchange_rate_type := FND_API.G_MISS_CHAR;
937       END IF;
938 
939       IF NVL(l_act_budgets_rec.request_amount,0) <> 0 THEN
940 
941          IF G_DEBUG THEN
942             ozf_utility_pvt.debug_message (   l_full_name
943                         || ' l_act_budgets_rec.exchange_rate_date3: ' || l_act_budgets_rec.exchange_rate_date);
944          END IF;
945 
946       --For bug 7425189
947        IF l_act_budgets_rec.justification IN (l_fund_reconc_msg,l_act_bud_cst_msg)
948           AND l_act_budgets_rec.exchange_rate_date IS NOT NULL
949           AND l_act_budgets_rec.transfer_type = 'TRANSFER' THEN
950           IF l_act_budgets_rec.src_curr_req_amt IS NULL THEN
951            ozf_utility_pvt.convert_currency(
952             p_from_currency   => l_act_budgets_rec.request_currency
953            ,p_to_currency     => l_src_currency
954            ,p_conv_date       => l_act_budgets_rec.exchange_rate_date
955            ,p_from_amount     => l_act_budgets_rec.request_amount
956            ,x_return_status   => l_return_status
957            ,x_to_amount       => l_act_budgets_rec.src_curr_req_amt
958            ,x_rate            => l_rate);
959           END IF;
960         ELSE
961 
962          ozf_utility_pvt.convert_currency(
963             p_from_currency   => l_act_budgets_rec.request_currency
964            ,p_to_currency     => l_src_currency
965            ,p_conv_type       => l_exchange_rate_type
966            ,p_conv_date       => l_act_budgets_rec.exchange_rate_date --bug 8532055
967            ,p_from_amount     => l_act_budgets_rec.request_amount
968            ,x_return_status   => l_return_status
969            ,x_to_amount       => l_act_budgets_rec.src_curr_req_amt
970            ,x_rate            => l_rate);
971         END IF;
972 
973          IF l_return_status = fnd_api.g_ret_sts_error THEN
974             RAISE fnd_api.g_exc_error;
975          ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
976             RAISE fnd_api.g_exc_unexpected_error;
977          END IF;
978       END IF;
979 
980       validate_act_budgets (
981          p_api_version=> 1.0
982         ,p_init_msg_list=> fnd_api.g_false
983         ,p_validation_level=> p_validation_level
984         ,x_return_status=> l_return_status
985         ,x_msg_count=> x_msg_count
986         ,x_msg_data=> x_msg_data
987         ,p_act_budgets_rec=> l_act_budgets_rec
988       );
989 
990       -- If any errors happen abort API.
991       IF l_return_status = fnd_api.g_ret_sts_error THEN
992          RAISE fnd_api.g_exc_error;
993       ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
994          RAISE fnd_api.g_exc_unexpected_error;
995       END IF;
996       -- Added 04/26/2001 mpande for new functionality changes for hornet
997       IF      l_act_budgets_rec.budget_source_type = 'FUND'
998           AND l_act_budgets_rec.arc_act_budget_used_by = 'FUND' THEN
999          l_fund_transfer_flag       := 'Y';
1000       END IF;
1001 
1002       IF NVL(l_act_budgets_rec.approved_amount,0) <> 0 THEN
1003          -- R12: yzhao Oct. 10, 2005 get ledger when calculating functional currency
1004          IF G_DEBUG THEN
1005              ozf_utility_pvt.debug_message (   l_api_name
1006                                          || ': create_act_budgets   before getting ledger  util.org_id='
1007                                          || l_act_util_rec.org_id);
1008          END IF;
1009 
1010          IF l_act_util_rec.org_id IS NOT NULL THEN
1011             MO_UTILS.Get_Ledger_Info (
1012                     p_operating_unit     =>  l_act_util_rec.org_id,
1013                     p_ledger_id          =>  l_ledger_id,
1014                     p_ledger_name        =>  l_ledger_name
1015             );
1016             IF G_DEBUG THEN
1017                  ozf_utility_pvt.debug_message (   l_api_name
1018                                              || ': create_act_budgets   ledger for util.org_id('
1019                                              || l_act_util_rec.org_id || ')=' || l_ledger_id);
1020             END IF;
1021          ELSE
1022             ozf_utility_pvt.get_object_org_ledger(p_object_type => l_act_budgets_rec.arc_act_budget_used_by
1023                                                 , p_object_id   => l_act_budgets_rec.act_budget_used_by_id
1024                                                 , x_org_id      => l_act_util_rec.org_id
1025                                                 , x_ledger_id   => l_ledger_id
1026                                                 , x_return_status => l_return_status
1027                                            );
1028             IF G_DEBUG THEN
1029                  ozf_utility_pvt.debug_message (   l_api_name
1030                                              || ': create_act_budgets   ledger for '
1031                                              || l_act_budgets_rec.arc_act_budget_used_by
1032                                              || '  id('
1033                                              || l_act_budgets_rec.act_budget_used_by_id
1034                                              || ') returns ' || l_return_status
1035                                              || '  ledger_id=' || l_ledger_id);
1036             END IF;
1037             IF l_return_status = fnd_api.g_ret_sts_error THEN
1038                RAISE fnd_api.g_exc_error;
1039             ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
1040                 RAISE fnd_api.g_exc_unexpected_error;
1041             END IF;
1042          END IF;
1043 
1044          --kdass 16-NOV-2005 bug 4728515 - for quota, bypass ledger check
1045          OPEN  c_check_quota (l_act_budgets_rec.budget_source_type, l_act_budgets_rec.budget_source_id);
1046          FETCH c_check_quota INTO l_is_quota;
1047          CLOSE c_check_quota;
1048 
1049          IF l_is_quota IS NULL THEN
1050             -- yzhao: R12 Oct 19 2005 No need to calculate functional currency if it is for marketing use
1051             IF l_ledger_id IS NULL THEN
1052                IF l_act_budgets_rec.budget_source_type NOT IN ('CAMP', 'CSCH', 'EVEO', 'EVEH', 'EONE') AND
1053                   l_act_budgets_rec.arc_act_budget_used_by NOT IN ('CAMP', 'CSCH', 'EVEO', 'EVEH', 'EONE') THEN
1054                   IF G_DEBUG THEN
1055                      ozf_utility_pvt.debug_message (   l_api_name
1056                                                  || ': create_act_budgets   ledger not found for '
1057                                                  || l_act_budgets_rec.arc_act_budget_used_by
1058                                                  || '  id('
1059                                                  || l_act_budgets_rec.act_budget_used_by_id);
1060                   END IF;
1061                   IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
1062                      fnd_message.set_name ('OZF', 'OZF_NO_LEDGER_FOUND');
1063                      --Message OZF_NO_LEDGER_FOUND changed fix bug 5190932
1064                      --fnd_message.set_token('OBJECT_TYPE', l_act_budgets_rec.arc_act_budget_used_by);
1065                      --fnd_message.set_token('OBJECT_ID', l_act_budgets_rec.act_budget_used_by_id);
1066                      fnd_msg_pub.ADD;
1067                   END IF;
1068                   x_return_status            := fnd_api.g_ret_sts_error;
1069                   RAISE fnd_api.g_exc_error;
1070                END IF;
1071             ELSE
1072 
1073 
1074                --Added for bug 7030415,  l_act_util_rec.org_id is available. use it for time being.
1075                --Column approved_amount_fc is used in Offer's Performance cuecard.
1076                --get the conversion type. This doesn't get called in case of committed/planned amounts.
1077 
1078                OPEN c_get_conversion_type(l_act_util_rec.org_id);
1079                FETCH c_get_conversion_type INTO l_exchange_rate_type;
1080                CLOSE c_get_conversion_type;
1081 
1082                IF G_DEBUG THEN
1083                   ozf_utility_pvt.debug_message (   l_full_name
1084                                      || ' l_act_budgets_rec.exchange_rate_date4: ' || l_act_budgets_rec.exchange_rate_date);
1085                END IF;
1086 
1087               --For bug 7425189, get exchange date based on approval date
1088               IF l_act_budgets_rec.justification IN (l_fund_reconc_msg,l_act_bud_cst_msg)
1089                 AND l_act_budgets_rec.exchange_rate_date IS NOT NULL
1090                 AND l_act_budgets_rec.transfer_type = 'TRANSFER' THEN
1091                   l_exchange_rate_type := NULL;
1092                  ozf_utility_pvt.calculate_functional_currency(
1093                    p_from_amount        => l_act_budgets_rec.approved_amount
1094                   ,p_conv_date          => l_act_budgets_rec.exchange_rate_date
1095                   ,p_tc_currency_code   => l_act_budgets_rec.request_currency
1096                   ,p_ledger_id          => l_ledger_id
1097                   ,x_to_amount          => l_fc_amount
1098                   ,x_mrc_sob_type_code  => l_mrc_sob_type_code
1099                   ,x_fc_currency_code   => l_fc_currency_code
1100                   ,x_exchange_rate_type => l_exchange_rate_type
1101                   ,x_exchange_rate      => l_exchange_rate
1102                   ,x_return_status      => l_return_status);
1103 
1104               ELSE
1105 
1106                ozf_utility_pvt.calculate_functional_currency(
1107                    p_from_amount        => l_act_budgets_rec.approved_amount
1108                    ,p_conv_date         => l_act_budgets_rec.exchange_rate_date --bug 8532055
1109                   ,p_tc_currency_code   => l_act_budgets_rec.request_currency
1110                   ,p_ledger_id          => l_ledger_id
1111                   ,x_to_amount          => l_fc_amount
1112                   ,x_mrc_sob_type_code  => l_mrc_sob_type_code
1113                   ,x_fc_currency_code   => l_fc_currency_code
1114                   ,x_exchange_rate_type => l_exchange_rate_type
1115                   ,x_exchange_rate      => l_exchange_rate
1116                   ,x_return_status      => l_return_status);
1117 
1118               END IF;
1119 
1120                IF l_return_status = fnd_api.g_ret_sts_error THEN
1121                   RAISE fnd_api.g_exc_error;
1122                ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
1123                   RAISE fnd_api.g_exc_unexpected_error;
1124                END IF;
1125             END IF;
1126          END IF;
1127       END IF;
1128 
1129       IF l_act_budgets_rec.transfer_type = 'UTILIZED'
1130       AND l_src_currency <> l_act_budgets_rec.request_currency THEN
1131          l_temp_request_amount := l_act_budgets_rec.request_amount;
1132          l_temp_approved_amount := l_act_budgets_rec.approved_amount;
1133          l_temp_aprvd_orig_amount := l_act_budgets_rec.approved_original_amount;
1134 
1135          IF G_DEBUG THEN
1136          ozf_utility_pvt.debug_message (   l_api_name||'l_temp_request_amount '|| l_temp_request_amount);
1137          ozf_utility_pvt.debug_message (   l_api_name||'l_temp_approved_amount '|| l_temp_approved_amount);
1138          ozf_utility_pvt.debug_message (   l_api_name||'l_temp_aprvd_orig_amount '|| l_temp_aprvd_orig_amount);
1139          ozf_utility_pvt.debug_message (   l_api_name||'src_curr_req_amt '|| l_act_budgets_rec.src_curr_req_amt);
1140          END IF;
1141 
1142          l_act_budgets_rec.request_amount := l_act_budgets_rec.src_curr_req_amt;
1143          l_act_budgets_rec.approved_original_amount := l_act_budgets_rec.src_curr_req_amt;
1144          l_act_budgets_rec.approved_amount := l_act_budgets_rec.src_curr_req_amt;
1145       END IF;
1146       -- nepanda : Fix for 12911854
1147       if l_act_budgets_rec.approved_in_currency is not null then
1148       l_act_budgets_rec.src_curr_req_amt := ozf_utility_pvt.currround(l_act_budgets_rec.src_curr_req_amt, l_act_budgets_rec.approved_in_currency);
1149       end if;
1150 
1151       if l_act_budgets_rec.request_currency is not null then
1152         l_act_budgets_rec.approved_amount := ozf_utility_pvt.currround(l_act_budgets_rec.approved_amount, l_act_budgets_rec.request_currency);
1153       end if;
1154 
1155       if l_act_budgets_rec.approved_in_currency is not null then
1156       l_act_budgets_rec.approved_original_amount := ozf_utility_pvt.currround(l_act_budgets_rec.approved_original_amount, l_act_budgets_rec.approved_in_currency);
1157       end if;
1158 
1159       if l_act_budgets_rec.parent_src_curr is not null then
1160       l_act_budgets_rec.parent_src_apprvd_amt := ozf_utility_pvt.currround(l_act_budgets_rec.parent_src_apprvd_amt, l_act_budgets_rec.parent_src_curr);
1161       end if;
1162 
1163       IF l_ledger_id IS NOT NULL THEN
1164               OPEN c_get_gl_info(l_ledger_id);
1165               FETCH c_get_gl_info INTO l_fc_currency_code;
1166               CLOSE c_get_gl_info;
1167               if l_fc_currency_code is not null then
1168                 l_fc_amount := ozf_utility_pvt.currround(l_fc_amount, l_fc_currency_code);
1169               end if;
1170       END IF;
1171 
1172       IF l_fc_amount = l_act_budgets_rec.request_amount THEN
1173          if l_act_budgets_rec.request_currency is not null then
1174                 l_fc_amount := ozf_utility_pvt.currround(l_act_budgets_rec.request_amount, l_act_budgets_rec.request_currency);
1175          end if;
1176       END IF;
1177       if l_act_budgets_rec.request_currency is not null then
1178         l_act_budgets_rec.request_amount := ozf_utility_pvt.currround(l_act_budgets_rec.request_amount, l_act_budgets_rec.request_currency);
1179       end if;
1180 
1181       INSERT INTO ozf_act_budgets
1182                   (activity_budget_id, -- standard who columns
1183                   last_update_date
1184                   , last_updated_by
1185                   , creation_date
1186                   ,created_by, last_update_login -- other columns
1187                   ,object_version_number
1188                   ,act_budget_used_by_id
1189                   ,arc_act_budget_used_by, budget_source_type
1190                   ,budget_source_id, transaction_type
1191                   ,request_amount, request_currency
1192                   ,request_date, user_status_id
1193                   ,status_code, approved_amount
1194                   ,approved_original_amount
1195                   ,approved_in_currency
1196                   ,approval_date, approver_id
1197                   ,spent_amount, partner_po_number
1198                   ,partner_po_date, partner_po_approver
1199                   ,posted_flag, adjusted_flag
1200                   ,parent_act_budget_id, contact_id
1201                   ,reason_code, transfer_type
1202                   ,requester_id
1203                   ,date_required_by
1204                   ,parent_source_id
1205                   ,parent_src_curr
1206                   ,parent_src_apprvd_amt
1207                   ,partner_holding_type
1208                   ,partner_address_id, vendor_id
1209                   ,owner_id
1210                   ,recal_flag
1211                   ,attribute_category, attribute1
1212                   ,attribute2, attribute3
1213                   ,attribute4, attribute5
1214                   ,attribute6, attribute7
1215                   ,attribute8, attribute9
1216                   ,attribute10, attribute11
1217                   ,attribute12, attribute13
1218                   ,attribute14, attribute15
1219                   ,approved_amount_fc
1220                   ,src_curr_request_amt
1221                   )
1222            VALUES (l_act_budgets_rec.activity_budget_id, -- standard who columns
1223                                                         SYSDATE, fnd_global.user_id, SYSDATE
1224                   ,fnd_global.user_id, fnd_global.conc_login_id, 1
1225                   , -- object_version_number
1226                    l_act_budgets_rec.act_budget_used_by_id
1227                   ,l_act_budgets_rec.arc_act_budget_used_by, l_act_budgets_rec.budget_source_type
1228                   ,l_act_budgets_rec.budget_source_id, l_act_budgets_rec.transaction_type
1229                   ,l_act_budgets_rec.request_amount, l_act_budgets_rec.request_currency
1230                   ,NVL (l_act_budgets_rec.request_date, SYSDATE), l_act_budgets_rec.user_status_id
1231                   ,NVL (l_act_budgets_rec.status_code, 'NEW'), l_act_budgets_rec.approved_amount
1232                   ,l_act_budgets_rec.approved_original_amount
1233                   ,l_act_budgets_rec.approved_in_currency
1234                   ,l_act_budgets_rec.approval_date
1235                   ,l_act_budgets_rec.approver_id
1236                   ,l_act_budgets_rec.spent_amount, l_act_budgets_rec.partner_po_number
1237                   ,l_act_budgets_rec.partner_po_date, l_act_budgets_rec.partner_po_approver
1238                   ,l_act_budgets_rec.posted_flag, l_act_budgets_rec.adjusted_flag
1239                   ,l_act_budgets_rec.parent_act_budget_id, l_act_budgets_rec.contact_id
1240                   ,l_act_budgets_rec.reason_code, l_act_budgets_rec.transfer_type
1241                   ,NVL (
1242                       l_act_budgets_rec.requester_id
1243                      ,ozf_utility_pvt.get_resource_id (fnd_global.user_id)
1244                    ) --l_act_budgets_rec.requester_id
1245                   ,l_act_budgets_rec.date_required_by
1246                   ,null --l_act_budgets_rec.parent_source_id
1247                   ,l_act_budgets_rec.parent_src_curr
1248                   ,l_act_budgets_rec.parent_src_apprvd_amt
1249                   ,l_act_budgets_rec.partner_holding_type
1250                   ,l_act_budgets_rec.partner_address_id, l_act_budgets_rec.vendor_id
1251                   ,l_act_budgets_rec.owner_id
1252                   ,l_act_budgets_rec.recal_flag
1253                   ,p_act_budgets_rec.attribute_category, p_act_budgets_rec.attribute1
1254                   ,p_act_budgets_rec.attribute2, p_act_budgets_rec.attribute3
1255                   ,p_act_budgets_rec.attribute4, p_act_budgets_rec.attribute5
1256                   ,p_act_budgets_rec.attribute6, p_act_budgets_rec.attribute7
1257                   ,p_act_budgets_rec.attribute8, p_act_budgets_rec.attribute9
1258                   ,p_act_budgets_rec.attribute10, p_act_budgets_rec.attribute11
1259                   ,p_act_budgets_rec.attribute12, p_act_budgets_rec.attribute13
1260                   ,p_act_budgets_rec.attribute14, p_act_budgets_rec.attribute15
1261                   ,l_fc_amount
1262                   ,l_act_budgets_rec.src_curr_req_amt);
1263 
1264       -- 02/22/2001 mpande Calls to ozf_object_attribute API was removed from this place.
1265       -- because the functionality has changed from Hornet release.
1266       -- set OUT value
1267       x_act_budget_id            := l_act_budgets_rec.activity_budget_id;
1268 
1269       IF l_act_budgets_rec.transfer_type = 'UTILIZED'
1270       AND l_src_currency <> l_act_budgets_rec.request_currency THEN
1271 
1272          IF G_DEBUG THEN
1273             ozf_utility_pvt.debug_message (   l_api_name|| l_temp_request_amount);
1274             ozf_utility_pvt.debug_message (   l_api_name|| l_temp_approved_amount);
1275             ozf_utility_pvt.debug_message (   l_api_name|| l_temp_aprvd_orig_amount);
1276          END IF;
1277 
1278          l_act_budgets_rec.request_amount := l_temp_request_amount;
1279          l_act_budgets_rec.approved_original_amount := l_temp_aprvd_orig_amount;
1280          l_act_budgets_rec.approved_amount := l_temp_approved_amount;
1281       END IF;
1282       IF l_act_budgets_rec.justification IS NOT NULL AND l_act_budgets_rec.transfer_type <> 'UTILIZED' THEN
1283          OZF_ACTBUDGETRULES_PVT.create_note (
1284             p_activity_type=> 'FREQ'
1285            ,p_activity_id=> l_act_budgets_rec.activity_budget_id
1286            ,p_note=> l_act_budgets_rec.justification
1287            ,p_note_type=> 'AMS_JUSTIFICATION'
1288            ,p_user=> NVL (
1289                         l_act_budgets_rec.requester_id
1290                        ,ozf_utility_pvt.get_resource_id (fnd_global.user_id)
1291                      )
1292            ,x_msg_count=> x_msg_count
1293            ,x_msg_data=> x_msg_data
1294            ,x_return_status=> l_return_status
1295          );
1296       END IF;
1297 
1298       IF l_return_status <> fnd_api.g_ret_sts_success THEN
1299          RAISE fnd_api.g_exc_error;
1300       END IF;
1301 
1302       -- update the fudn for release and reserve
1303       -- if the adjust_flag = 'Y' or null then only update the fund otherwise donot.
1304       -- during fund updating this flag is passed 'N'
1305       IF      l_act_budgets_rec.transfer_type IN ('RELEASE', 'RESERVE')
1306           AND NVL (l_act_budgets_rec.adjusted_flag, 'Y') = 'Y' THEN
1307          ozf_fund_request_apr_pvt.approve_holdback (
1308             p_commit=> fnd_api.g_false
1309            ,p_act_budget_id=> l_act_budget_id
1310            ,p_transfer_type=> l_act_budgets_rec.transfer_type
1311            ,p_transac_fund_id=> l_act_budgets_rec.budget_source_id
1312            ,p_requester_id=> l_act_budgets_rec.requester_id
1313            ,p_approver_id=> l_act_budgets_rec.requester_id
1314            ,p_requested_amount=> l_act_budgets_rec.request_amount
1315            ,x_return_status=> l_return_status
1316            ,x_msg_count=> x_msg_count
1317            ,x_msg_data=> x_msg_data
1318          );
1319 
1320          IF l_return_status <> fnd_api.g_ret_sts_success THEN
1321             RAISE fnd_api.g_exc_error;
1322          END IF;
1323       END IF;
1324 
1325       -- 02/23/2001 mpande whenever user enters a amount as utlized
1326       -- For this amount a utilized record is entered in fund_utilized table
1327       --That means the budget is utilized . Budget Utlized for offers take place through orders
1328       IF G_DEBUG THEN
1329          ozf_utility_pvt.debug_message (   l_api_name
1330                                      || ': check items');
1331       END IF;
1332 
1333       -- 06/25/2001 mpande changed by mpande
1334       IF l_act_budgets_rec.status_code = 'APPROVED'
1335           AND l_act_budgets_rec.transfer_type NOT IN ('RELEASE', 'RESERVE')
1336           -- donot create a record in utilization for partners
1337           AND l_act_budgets_rec.budget_source_type <> 'PTNR'  THEN
1338          --added by feliu on 08/03/2005. only created utilization for UTILIZED.
1339          IF l_act_budgets_rec.transfer_type = 'UTILIZED' THEN
1340         -- For Bug#8867381, introduced p_use_fund_staging_tables for staging table impln of chargeback flow
1341         -- and px_ozf_act_budgets_tbl for PLSQL table impln of storing budgets value.
1342         -- and px_ozf_funds_old_rectype for taking the funds old values
1343             -- For TPA Parallel Execution ER Bug#9614703
1344         -- and changed px_ozf_funds_new_rectype to px_ozf_funds_new_tbl.
1345 
1346            ozf_fund_adjustment_pvt.create_fund_utilization (
1347             p_act_budget_rec=> l_act_budgets_rec
1348            ,x_return_status=> l_return_status
1349            ,x_msg_count=> x_msg_count
1350            ,x_msg_data=> x_msg_data
1351            ,p_act_util_rec => l_act_util_rec
1352            ,x_utilized_amount =>  x_utilized_amount
1353            ,p_batch_type             =>    p_batch_type
1354            ,p_use_fund_staging_tables => p_use_fund_staging_tables
1355            ,px_ozf_act_budgets_tbl => px_ozf_act_budgets_tbl
1356            ,px_ozf_funds_old_rectype => px_ozf_funds_old_rectype
1357            ,px_ozf_funds_new_tbl     => px_ozf_funds_new_tbl  -- For TPA Parallel Execution ER Bug#9614703
1358            ,x_utilization_id   => x_utilization_id --nirprasa - added for Bug 9383565
1359            );
1360 
1361 
1362          IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
1363             RAISE fnd_api.g_exc_unexpected_error;
1364          ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
1365             RAISE fnd_api.g_exc_error;
1366          END IF;
1367        END IF;
1368 
1369        IF (l_act_budgets_rec.arc_act_budget_used_by ='CAMP' AND l_act_budgets_rec.budget_source_type = 'CSCH') OR
1370          (l_act_budgets_rec.arc_act_budget_used_by ='EVEH' AND l_act_budgets_rec.budget_source_type = 'EVEO') OR
1371          (l_act_budgets_rec.arc_act_budget_used_by ='CAMP' AND l_act_budgets_rec.budget_source_type = 'OFFR')  THEN
1372 
1373           create_child_act_budget (
1374                   x_return_status      => l_return_status,
1375                   x_msg_count          =>  x_msg_count,
1376                   x_msg_data           => x_msg_data,
1377                   p_act_budgets_rec    => l_act_budgets_rec,
1378                   p_exchange_rate_type => l_exchange_rate_type
1379 
1380             );
1381 
1382          IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
1383             RAISE fnd_api.g_exc_unexpected_error;
1384          ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
1385             RAISE fnd_api.g_exc_error;
1386          END IF;
1387 
1388       END IF;
1389 
1390         -- For Bug#8867381, introduced p_use_fund_staging_tables for staging table impln of chargeback flow
1391         -- and px_ozf_funds_old_rectype for taking the funds old values
1392             -- For TPA Parallel Execution ER Bug#9614703
1393         -- and changed px_ozf_funds_new_rectype to px_ozf_funds_new_tbl.
1394 
1395          process_approval (
1396             p_act_budget_rec=> l_act_budgets_rec
1397            ,x_act_budget_rec=> l_temp_rec
1398            ,x_return_status=> l_return_status
1399            ,x_msg_count=> x_msg_count
1400            ,x_msg_data=> x_msg_data
1401            ,p_mode    => 'CREATE'
1402            ,p_resale_batch_id => p_resale_batch_id
1403            ,p_batch_type             =>    p_batch_type
1404            ,p_use_fund_staging_tables => p_use_fund_staging_tables
1405            ,px_ozf_funds_old_rectype => px_ozf_funds_old_rectype
1406            ,px_ozf_funds_new_tbl => px_ozf_funds_new_tbl  -- For TPA Parallel Execution ER Bug#9614703
1407          );
1408 
1409          IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
1410             RAISE fnd_api.g_exc_unexpected_error;
1411          ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
1412             RAISE fnd_api.g_exc_error;
1413          END IF;
1414       END IF;
1415      -- Add by feliu on 05/22/04 for referal.
1416       IF  l_act_budgets_rec.status_code =  'PENDING_VALIDATION'  THEN
1417              l_request_id := fnd_request.submit_request (
1418                             application   => 'OZF',
1419                             program       => 'OZFVALIELIG',
1420                             start_time    => sysdate,
1421                             argument1     => l_act_budgets_rec.act_budget_used_by_id,
1422                             argument2     =>'OFFR',
1423                             argument3     =>l_act_budgets_rec.activity_budget_id
1424                          );
1425             COMMIT;
1426       END IF;
1427 
1428       /******** 01/03/2002 mpande added for partner requirement -- to send a notification to the vendor****/
1429       IF l_act_budgets_rec.transfer_type = 'REQUEST' AND  l_act_budgets_rec.vendor_id IS NOT NULL
1430         THEN
1431          ozf_budgetapproval_pvt.notify_vendor (
1432            p_act_budget_rec=> l_act_budgets_rec
1433            ,x_return_status=> l_return_status
1434            ,x_msg_count=> x_msg_count
1435            ,x_msg_data=> x_msg_data
1436          );
1437 
1438          IF l_return_status <> fnd_api.g_ret_sts_success THEN
1439             RAISE fnd_api.g_exc_error;
1440          END IF;
1441       END IF;
1442       /***** END OF Addition for Partner ********/
1443       --
1444       -- END of API body.
1445       --
1446       -- Standard check of p_commit.
1447       IF fnd_api.to_boolean (p_commit) THEN
1448          COMMIT WORK;
1449       END IF;
1450 
1451       -- Standard call to get message count AND IF count is 1, get message info.
1452       fnd_msg_pub.count_and_get (
1453          p_count=> x_msg_count
1454         ,p_data=> x_msg_data
1455         ,p_encoded=> fnd_api.g_false
1456       );
1457    EXCEPTION
1458       WHEN fnd_api.g_exc_error THEN
1459          ROLLBACK TO create_act_budgets_pvt;
1460          x_return_status            := fnd_api.g_ret_sts_error;
1461          fnd_msg_pub.count_and_get (
1462             p_count=> x_msg_count
1463            ,p_data=> x_msg_data
1464            ,p_encoded=> fnd_api.g_false
1465          );
1466       WHEN fnd_api.g_exc_unexpected_error THEN
1467          ROLLBACK TO create_act_budgets_pvt;
1468          x_return_status            := fnd_api.g_ret_sts_unexp_error;
1469          fnd_msg_pub.count_and_get (
1470             p_count=> x_msg_count
1471            ,p_data=> x_msg_data
1472            ,p_encoded=> fnd_api.g_false
1473          );
1474       WHEN OTHERS THEN
1475          ROLLBACK TO create_act_budgets_pvt;
1476          x_return_status            := fnd_api.g_ret_sts_unexp_error;
1477 
1478          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error) THEN
1479             fnd_msg_pub.add_exc_msg (g_package_name, l_api_name);
1480          END IF;
1481 
1482          fnd_msg_pub.count_and_get (
1483             p_count=> x_msg_count
1484            ,p_data=> x_msg_data
1485            ,p_encoded=> fnd_api.g_false
1486          );
1487    END create_act_budgets;
1488 
1489 
1490 /*****************************************************************************************/
1491 -- Start of Comments
1492 --
1493 -- NAME
1494 --   Update_Act_Budgets
1495 --
1496 -- PURPOSE
1497 --   This procedure is to update a Budget record that satisfy caller needs
1498 --
1499 -- HISTORY
1500 -- 04/12/2000  sugupta  CREATED
1501 -- 14-Aug-2000 choang   Modified for spec signature change.
1502 -- 22-Feb-2001 mpande   Modified for Hornet changes.
1503 -- End of Comments
1504 /*****************************************************************************************/
1505    PROCEDURE update_act_budgets (
1506       p_api_version        IN       NUMBER
1507      ,p_init_msg_list      IN       VARCHAR2 := fnd_api.g_false
1508      ,p_commit             IN       VARCHAR2 := fnd_api.g_false
1509      ,p_validation_level   IN       NUMBER := fnd_api.g_valid_level_full
1510      ,x_return_status      OUT NOCOPY      VARCHAR2
1511      ,x_msg_count          OUT NOCOPY      NUMBER
1512      ,x_msg_data           OUT NOCOPY      VARCHAR2
1513      ,p_act_budgets_rec    IN       act_budgets_rec_type
1514    ) IS
1515       l_utilized_amount    NUMBER;
1516    BEGIN
1517       update_act_budgets (
1518          p_api_version=> p_api_version
1519         ,p_init_msg_list=> p_init_msg_list
1520         ,p_commit=> p_commit
1521         ,p_validation_level=> p_validation_level
1522         ,x_return_status=> x_return_status
1523         ,x_msg_count=> x_msg_count
1524         ,x_msg_data=> x_msg_data
1525         ,p_act_budgets_rec=> p_act_budgets_rec
1526         ,p_parent_process_flag=> fnd_api.g_false
1527         ,p_parent_process_key=> fnd_api.g_miss_char
1528         ,p_parent_context=> fnd_api.g_miss_char
1529         ,p_parent_approval_flag=> fnd_api.g_false
1530         ,p_continue_flow=> fnd_api.g_false
1531         ,p_child_approval_flag=> fnd_api.g_false
1532         -- 10/22/2001   mpande    Changed code different owner allocation bug
1533         ,p_requestor_owner_flag  => 'N'
1534         ,x_utilized_amount => l_utilized_amount
1535       );
1536    END update_act_budgets;
1537 
1538    /*****************************************************************************************/
1539 -- Start of Comments
1540 --
1541 -- NAME
1542 --   Update_Act_Budgets
1543 --
1544 -- PURPOSE
1545 --   This procedure is overloaded to take care of fund child approval
1546 --
1547 -- HISTORY
1548 -- 05/22/2001  mpande  CREATED
1549 -- End of Comments
1550 /*****************************************************************************************/
1551    PROCEDURE update_act_budgets (
1552       p_api_version           IN       NUMBER
1553      ,p_init_msg_list         IN       VARCHAR2 := fnd_api.g_false
1554      ,p_commit                IN       VARCHAR2 := fnd_api.g_false
1555      ,p_validation_level      IN       NUMBER := fnd_api.g_valid_level_full
1556      ,x_return_status         OUT NOCOPY      VARCHAR2
1557      ,x_msg_count             OUT NOCOPY      NUMBER
1558      ,x_msg_data              OUT NOCOPY      VARCHAR2
1559      ,p_act_budgets_rec       IN       act_budgets_rec_type
1560      ,p_child_approval_flag   IN       VARCHAR2
1561       -- 10/22/2001   mpande    Changed code different owner allocation bug
1562      ,p_requestor_owner_flag  IN       VARCHAR2 := 'N'
1563      ,p_act_util_rec          IN       act_util_rec_type := NULL
1564    ) IS
1565      l_utilized_amount        NUMBER;
1566    BEGIN
1567       update_act_budgets (
1568          p_api_version=> p_api_version
1569         ,p_init_msg_list=> p_init_msg_list
1570         ,p_commit=> p_commit
1571         ,p_validation_level=> p_validation_level
1572         ,x_return_status=> x_return_status
1573         ,x_msg_count=> x_msg_count
1574         ,x_msg_data=> x_msg_data
1575         ,p_act_budgets_rec=> p_act_budgets_rec
1576         ,p_child_approval_flag=> p_child_approval_flag
1577         ,p_parent_process_flag=> fnd_api.g_false
1578         ,p_parent_process_key=> fnd_api.g_miss_char
1579         ,p_parent_context=> fnd_api.g_miss_char
1580         ,p_parent_approval_flag=> fnd_api.g_false
1581         ,p_continue_flow=> fnd_api.g_false
1582         -- 10/22/2001   mpande    Changed code different owner allocation bug
1583         ,p_requestor_owner_flag  => p_requestor_owner_flag
1584         ,p_act_util_rec   => p_act_util_rec
1585         ,x_utilized_amount => l_utilized_amount
1586       );
1587    END update_act_budgets;
1588 
1589 
1590   /****************************************************************************
1591    -- yzhao: 06/21/2004  added x_utilized_amount to return actual utilized amount
1592    */
1593    PROCEDURE update_act_budgets (
1594       p_api_version           IN       NUMBER
1595      ,p_init_msg_list         IN       VARCHAR2 := fnd_api.g_false
1596      ,p_commit                IN       VARCHAR2 := fnd_api.g_false
1597      ,p_validation_level      IN       NUMBER := fnd_api.g_valid_level_full
1598      ,x_return_status         OUT NOCOPY      VARCHAR2
1599      ,x_msg_count             OUT NOCOPY      NUMBER
1600      ,x_msg_data              OUT NOCOPY      VARCHAR2
1601      ,p_act_budgets_rec       IN       act_budgets_rec_type
1602      ,p_child_approval_flag   IN       VARCHAR2
1603       -- 10/22/2001   mpande    Changed code different owner allocation bug
1604      ,p_requestor_owner_flag  IN       VARCHAR2 := 'N'
1605      ,p_act_util_rec          IN       act_util_rec_type := NULL
1606      ,x_utilized_amount       OUT NOCOPY      NUMBER        -- yzhao: added 06/21/2004 to return actual utilized amount
1607    ) IS
1608    BEGIN
1609       update_act_budgets (
1610          p_api_version=> p_api_version
1611         ,p_init_msg_list=> p_init_msg_list
1612         ,p_commit=> p_commit
1613         ,p_validation_level=> p_validation_level
1614         ,x_return_status=> x_return_status
1615         ,x_msg_count=> x_msg_count
1616         ,x_msg_data=> x_msg_data
1617         ,p_act_budgets_rec=> p_act_budgets_rec
1618         ,p_child_approval_flag=> p_child_approval_flag
1619         ,p_parent_process_flag=> fnd_api.g_false
1620         ,p_parent_process_key=> fnd_api.g_miss_char
1621         ,p_parent_context=> fnd_api.g_miss_char
1622         ,p_parent_approval_flag=> fnd_api.g_false
1623         ,p_continue_flow=> fnd_api.g_false
1624         -- 10/22/2001   mpande    Changed code different owner allocation bug
1625         ,p_requestor_owner_flag  => p_requestor_owner_flag
1626         ,p_act_util_rec   => p_act_util_rec
1627         ,x_utilized_amount => x_utilized_amount
1628       );
1629    END update_act_budgets;
1630 
1631 
1632 /****************************************************************************/
1633 -- Start of Comments
1634 --
1635 --    API name    : Update_Act_Budgets
1636 --    Type        : Private
1637 --    Function    : Update a row in OZF_ACT_Budgets table
1638 --    Note        : This overloaded procedure is to be called from
1639 --                  Workflow to maintain the context.
1640 ---- 29-JUNE-2004  feliu   added.
1641 -- End Of Comments
1642 /****************************************************************************/
1643    PROCEDURE update_act_budgets (
1644       p_api_version            IN       NUMBER
1645      ,p_init_msg_list          IN       VARCHAR2 := fnd_api.g_false
1646      ,p_commit                 IN       VARCHAR2 := fnd_api.g_false
1647      ,p_validation_level       IN       NUMBER := fnd_api.g_valid_level_full
1648      ,x_return_status          OUT NOCOPY      VARCHAR2
1649      ,x_msg_count              OUT NOCOPY      NUMBER
1650      ,x_msg_data               OUT NOCOPY      VARCHAR2
1651      ,p_act_budgets_rec        IN       act_budgets_rec_type
1652      ,p_parent_process_flag    IN       VARCHAR2
1653      ,p_parent_process_key     IN       VARCHAR2
1654      ,p_parent_context         IN       VARCHAR2
1655      ,p_parent_approval_flag   IN       VARCHAR2
1656      ,p_continue_flow          IN       VARCHAR2
1657      ,p_child_approval_flag    IN       VARCHAR2 := fnd_api.g_false
1658      ,p_requestor_owner_flag   IN       VARCHAR2 := 'N'
1659      ,p_act_util_rec           IN       act_util_rec_type  := NULL
1660    ) IS
1661     l_utilized_amount        NUMBER;
1662    BEGIN
1663       update_act_budgets (
1664          p_api_version=> p_api_version
1665         ,p_init_msg_list=> p_init_msg_list
1666         ,p_commit=> p_commit
1667         ,p_validation_level=> p_validation_level
1668         ,x_return_status=> x_return_status
1669         ,x_msg_count=> x_msg_count
1670         ,x_msg_data=> x_msg_data
1671         ,p_act_budgets_rec=> p_act_budgets_rec
1672         ,p_child_approval_flag=> p_child_approval_flag
1673         ,p_parent_process_flag=>p_parent_process_flag
1674         ,p_parent_process_key=>p_parent_process_key
1675         ,p_parent_context=> p_parent_context
1676         ,p_parent_approval_flag=> p_parent_approval_flag
1677         ,p_continue_flow=> p_continue_flow
1678         ,p_requestor_owner_flag  => p_requestor_owner_flag
1679         ,p_act_util_rec   => p_act_util_rec
1680         ,x_utilized_amount => l_utilized_amount
1681       );
1682    END update_act_budgets;
1683 
1684 
1685    PROCEDURE update_act_budgets (
1686       p_api_version            IN       NUMBER
1687      ,p_init_msg_list          IN       VARCHAR2 := fnd_api.g_false
1688      ,p_commit                 IN       VARCHAR2 := fnd_api.g_false
1689      ,p_validation_level       IN       NUMBER := fnd_api.g_valid_level_full
1690      ,x_return_status          OUT NOCOPY      VARCHAR2
1691      ,x_msg_count              OUT NOCOPY      NUMBER
1692      ,x_msg_data               OUT NOCOPY      VARCHAR2
1693      ,p_act_budgets_rec        IN       act_budgets_rec_type
1694      ,p_parent_process_flag    IN       VARCHAR2
1695      ,p_parent_process_key     IN       VARCHAR2
1696      ,p_parent_context         IN       VARCHAR2
1697      ,p_parent_approval_flag   IN       VARCHAR2
1698      ,p_continue_flow          IN       VARCHAR2
1699      ,p_child_approval_flag    IN       VARCHAR2 := fnd_api.g_false
1700      ,p_requestor_owner_flag   IN       VARCHAR2 := 'N'
1701      ,p_act_util_rec           IN       act_util_rec_type  := NULL
1702      ,x_utilized_amount        OUT NOCOPY     NUMBER
1703    ) IS
1704     l_utilization_id        NUMBER;
1705    BEGIN
1706 
1707       --kdass - added for Bug 8726683
1708       update_act_budgets (
1709          p_api_version=> p_api_version
1710         ,p_init_msg_list=> p_init_msg_list
1711         ,p_commit=> p_commit
1712         ,p_validation_level=> p_validation_level
1713         ,x_return_status=> x_return_status
1714         ,x_msg_count=> x_msg_count
1715         ,x_msg_data=> x_msg_data
1716         ,p_act_budgets_rec=> p_act_budgets_rec
1717         ,p_child_approval_flag=> p_child_approval_flag
1718         ,p_parent_process_flag=>p_parent_process_flag
1719         ,p_parent_process_key=>p_parent_process_key
1720         ,p_parent_context=> p_parent_context
1721         ,p_parent_approval_flag=> p_parent_approval_flag
1722         ,p_continue_flow=> p_continue_flow
1723         ,p_requestor_owner_flag  => p_requestor_owner_flag
1724         ,p_act_util_rec   => p_act_util_rec
1725         ,x_utilized_amount => x_utilized_amount
1726         ,x_utilization_id  => l_utilization_id
1727       );
1728    END update_act_budgets;
1729 
1730 
1731    PROCEDURE update_act_budgets (
1732       p_api_version            IN       NUMBER
1733      ,p_init_msg_list          IN       VARCHAR2 := fnd_api.g_false
1734      ,p_commit                 IN       VARCHAR2 := fnd_api.g_false
1735      ,p_validation_level       IN       NUMBER := fnd_api.g_valid_level_full
1736      ,x_return_status          OUT NOCOPY      VARCHAR2
1737      ,x_msg_count              OUT NOCOPY      NUMBER
1738      ,x_msg_data               OUT NOCOPY      VARCHAR2
1739      ,p_act_budgets_rec        IN       act_budgets_rec_type
1740      ,p_parent_process_flag    IN       VARCHAR2
1741      ,p_parent_process_key     IN       VARCHAR2
1742      ,p_parent_context         IN       VARCHAR2
1743      ,p_parent_approval_flag   IN       VARCHAR2
1744      ,p_continue_flow          IN       VARCHAR2
1745      ,p_child_approval_flag    IN       VARCHAR2 := fnd_api.g_false
1746      ,p_requestor_owner_flag   IN       VARCHAR2 := 'N'
1747      ,p_act_util_rec           IN       act_util_rec_type  := NULL
1748      ,x_utilized_amount        OUT NOCOPY     NUMBER                -- yzhao: 06/21/2004 added to return actual utilized amount\
1749      ,x_utilization_id         OUT NOCOPY     NUMBER ) IS
1750 
1751          l_old_act_budgets_rec  act_budgets_rec_type;
1752      l_use_fund_staging_tables VARCHAR2(1) := 'F';
1753      l_ozf_act_budgets_tbl  OZF_UTILITY_PVT.ozf_act_budgets_table;
1754      lx_ozf_funds_old_rectype OZF_UTILITY_PVT.ozf_funds_all_b_rectype;
1755      lx_ozf_funds_new_tbl OZF_UTILITY_PVT.ozf_funds_table;
1756      l_batch_type VARCHAR2(30);
1757 
1758       BEGIN
1759 
1760       update_act_budgets (
1761          p_api_version=> p_api_version
1762         ,p_init_msg_list=> p_init_msg_list
1763         ,p_commit=> p_commit
1764         ,p_validation_level=> p_validation_level
1765         ,x_return_status=> x_return_status
1766         ,x_msg_count=> x_msg_count
1767         ,x_msg_data=> x_msg_data
1768         ,p_old_act_budgets_rec => l_old_act_budgets_rec
1769         ,p_act_budgets_rec=> p_act_budgets_rec
1770         ,p_child_approval_flag=> p_child_approval_flag
1771         ,p_parent_process_flag=>p_parent_process_flag
1772         ,p_parent_process_key=>p_parent_process_key
1773         ,p_parent_context=> p_parent_context
1774         ,p_parent_approval_flag=> p_parent_approval_flag
1775         ,p_continue_flow=> p_continue_flow
1776         ,p_requestor_owner_flag  => p_requestor_owner_flag
1777         ,p_act_util_rec   => p_act_util_rec
1778         ,x_utilized_amount => x_utilized_amount
1779             ,p_batch_type            =>    l_batch_type
1780         ,p_use_fund_staging_tables => l_use_fund_staging_tables
1781         ,px_ozf_act_budgets_tbl =>  l_ozf_act_budgets_tbl
1782         ,px_ozf_funds_old_rectype =>  lx_ozf_funds_old_rectype
1783         ,px_ozf_funds_new_tbl =>  lx_ozf_funds_new_tbl          -- For TPA Parallel Execution ER - 9614703
1784                 ,x_utilization_id  => x_utilization_id
1785       );
1786    END update_act_budgets;
1787 
1788 
1789 /****************************************************************************/
1790 -- Start of Comments
1791 --
1792 --    API name    : Update_Act_Budgets
1793 --    Type        : Private
1794 --    Function    : Update a row in OZF_ACT_Budgets table
1795 --    Note        : This overloaded procedure is to be called from
1796 --                  Workflow to maintain the context.
1797 ---- 22-Feb-2001 mpande   Modified for Hornet changes.
1798 --   05/22/2001  mpande   Signature changes for fund child approval
1799 --   08/26/2002  feliu    added status of "PENDING_VALIDATION"
1800 --   27/10/2009  muthsubr Added px_ozf_act_budgets_tbl, p_use_fund_staging_tables
1801 --                        px_ozf_funds_old_rectype, px_ozf_funds_new_rectype
1802 --                        for bug#8867381.
1803 --   29/11/2010  muthsubr Altered px_ozf_funds_new_rectype to px_ozf_funds_new_tbl
1804 --                        for TPA Parallel Execution ER Bug#9614703.
1805 -- End Of Comments
1806 /****************************************************************************/
1807    PROCEDURE update_act_budgets (
1808       p_api_version            IN       NUMBER
1809      ,p_init_msg_list          IN       VARCHAR2 := fnd_api.g_false
1810      ,p_commit                 IN       VARCHAR2 := fnd_api.g_false
1811      ,p_validation_level       IN       NUMBER := fnd_api.g_valid_level_full
1812      ,x_return_status          OUT NOCOPY      VARCHAR2
1813      ,x_msg_count              OUT NOCOPY      NUMBER
1814      ,x_msg_data               OUT NOCOPY      VARCHAR2
1815      ,p_old_act_budgets_rec    IN       act_budgets_rec_type
1816      ,p_act_budgets_rec        IN       act_budgets_rec_type
1817      ,p_parent_process_flag    IN       VARCHAR2
1818      ,p_parent_process_key     IN       VARCHAR2
1819      ,p_parent_context         IN       VARCHAR2
1820      ,p_parent_approval_flag   IN       VARCHAR2
1821      ,p_continue_flow          IN       VARCHAR2
1822      ,p_child_approval_flag    IN       VARCHAR2 := fnd_api.g_false
1823      ,p_requestor_owner_flag   IN       VARCHAR2 := 'N'
1824      ,p_act_util_rec           IN       act_util_rec_type     -- For Bug#8867381 removed  ':= NULL'
1825      ,x_utilized_amount        OUT  NOCOPY     NUMBER                -- yzhao: 06/21/2004 added to return actual utilized amount
1826      ,p_batch_type           IN  VARCHAR2
1827      ,p_use_fund_staging_tables IN      VARCHAR2
1828      ,px_ozf_act_budgets_tbl    IN OUT  NOCOPY  OZF_UTILITY_PVT.ozf_act_budgets_table
1829      ,px_ozf_funds_old_rectype  IN      OZF_UTILITY_PVT.ozf_funds_all_b_rectype
1830      ,px_ozf_funds_new_tbl  IN OUT  NOCOPY  OZF_UTILITY_PVT.ozf_funds_table     -- For TPA Parallel Execution ER - 9614703
1831    ) IS
1832    l_utilization_id        NUMBER;  --nirprasa - added for Bug 9383565
1833    BEGIN
1834       update_act_budgets (
1835          p_api_version=> p_api_version
1836         ,p_init_msg_list=> p_init_msg_list
1837         ,p_commit=> p_commit
1838         ,p_validation_level=> p_validation_level
1839         ,x_return_status=> x_return_status
1840         ,x_msg_count=> x_msg_count
1841         ,x_msg_data=> x_msg_data
1842         ,p_old_act_budgets_rec => p_old_act_budgets_rec
1843         ,p_act_budgets_rec=> p_act_budgets_rec
1844         ,p_child_approval_flag=> p_child_approval_flag
1845         ,p_parent_process_flag=>p_parent_process_flag
1846         ,p_parent_process_key=>p_parent_process_key
1847         ,p_parent_context=> p_parent_context
1848         ,p_parent_approval_flag=> p_parent_approval_flag
1849         ,p_continue_flow=> p_continue_flow
1850         ,p_requestor_owner_flag  => p_requestor_owner_flag
1851         ,p_act_util_rec   => p_act_util_rec
1852         ,x_utilized_amount => x_utilized_amount
1853         ,p_batch_type        =>    p_batch_type
1854         ,p_use_fund_staging_tables => p_use_fund_staging_tables
1855         ,px_ozf_act_budgets_tbl =>  px_ozf_act_budgets_tbl
1856         ,px_ozf_funds_old_rectype =>  px_ozf_funds_old_rectype
1857         ,px_ozf_funds_new_tbl =>  px_ozf_funds_new_tbl                  -- For TPA Parallel Execution ER - 9614703
1858         ,x_utilization_id  => l_utilization_id
1859       );
1860    END update_act_budgets;
1861 
1862    PROCEDURE update_act_budgets (
1863       p_api_version            IN       NUMBER
1864      ,p_init_msg_list          IN       VARCHAR2 := fnd_api.g_false
1865      ,p_commit                 IN       VARCHAR2 := fnd_api.g_false
1866      ,p_validation_level       IN       NUMBER := fnd_api.g_valid_level_full
1867      ,x_return_status          OUT NOCOPY      VARCHAR2
1868      ,x_msg_count              OUT NOCOPY      NUMBER
1869      ,x_msg_data               OUT NOCOPY      VARCHAR2
1870      ,p_old_act_budgets_rec    IN       act_budgets_rec_type
1871      ,p_act_budgets_rec        IN       act_budgets_rec_type
1872      ,p_parent_process_flag    IN       VARCHAR2
1873      ,p_parent_process_key     IN       VARCHAR2
1874      ,p_parent_context         IN       VARCHAR2
1875      ,p_parent_approval_flag   IN       VARCHAR2
1876      ,p_continue_flow          IN       VARCHAR2
1877      ,p_child_approval_flag    IN       VARCHAR2 := fnd_api.g_false
1878      ,p_requestor_owner_flag   IN       VARCHAR2 := 'N'
1879      ,p_act_util_rec           IN       act_util_rec_type     -- For Bug#8867381 removed  ':= NULL'
1880      ,x_utilized_amount        OUT  NOCOPY     NUMBER                -- yzhao: 06/21/2004 added to return actual utilized amount
1881      ,p_batch_type           IN  VARCHAR2
1882      ,p_use_fund_staging_tables IN      VARCHAR2
1883      ,px_ozf_act_budgets_tbl    IN OUT  NOCOPY  OZF_UTILITY_PVT.ozf_act_budgets_table
1884      ,px_ozf_funds_old_rectype  IN      OZF_UTILITY_PVT.ozf_funds_all_b_rectype
1885      ,px_ozf_funds_new_tbl  IN OUT  NOCOPY  OZF_UTILITY_PVT.ozf_funds_table     -- For TPA Parallel Execution ER - 9614703
1886      ,x_utilization_id         OUT NOCOPY     NUMBER --nirprasa - added for Bug 9383565
1887    ) IS
1888       l_api_name            CONSTANT VARCHAR2 (30)               := 'Update_Act_Budgets';
1889       l_api_version         CONSTANT NUMBER                      := 1.0;
1890       l_status_type         CONSTANT VARCHAR2 (30)               := 'OZF_BUDGETSOURCE_STATUS';
1891       l_rejected_code       CONSTANT VARCHAR2 (30)               := 'REJECTED';
1892       -- Status Local Variables
1893       l_return_status                VARCHAR2 (1); -- Return value from procedures
1894       l_dummy                        NUMBER;
1895       l_act_budgets_rec              act_budgets_rec_type;
1896       l_old_act_budgets_rec          act_budgets_rec_type := p_old_act_budgets_rec;
1897       l_temp_rec                     act_budgets_rec_type;
1898       l_act_util_rec                 act_util_rec_type      := p_act_util_rec;
1899       l_old_status_code                  VARCHAR2 (30); -- Used to capture the current status code
1900       l_fund_rec                     ozf_funds_pvt.fund_rec_type;
1901       l_fund_object_version_number   NUMBER;
1902       l_fund_currency_tc             VARCHAR2 (15); -- a fund's transactional currency code
1903       l_fund_planned_amount          NUMBER;
1904       l_fund_committed_amount        NUMBER;
1905       l_request_id                   NUMBER;
1906       l_approver_id                  NUMBER;
1907       l_is_requestor_owner           VARCHAR2 (2);
1908       l_fund_transfer_flag           VARCHAR2 (1)                := 'N';
1909       l_old_approved_amount          NUMBER;
1910       l_start_flow_flag            VARCHAR2 (1) := 'N';
1911       l_new_status_id              NUMBER;
1912       l_reject_status_id           NUMBER;
1913       l_exceed_flag            VARCHAR2 (1)
1914                                           := NVL (fnd_profile.VALUE ('OZF_COMM_BUDGET_EXCEED'), 'N');
1915       -- For Bug#8867381
1916       l_use_fund_staging_tables VARCHAR2(1):= p_use_fund_staging_tables;
1917       l_resale_batch_id      NUMBER := p_act_util_rec.reference_id; -- batch_id is set in Create_Adj_And_Utilization
1918 
1919       l_budget_count  NUMBER;
1920       l_req_id        NUMBER;
1921       l_operation     VARCHAR2(6);
1922 
1923       CURSOR c_current_status IS
1924          SELECT status_code,  approved_amount, parent_src_apprvd_amt
1925            FROM ozf_act_budgets
1926           WHERE activity_budget_id = p_act_budgets_rec.activity_budget_id;
1927 
1928       --
1929       -- the planned_amt will be used in approval submission,
1930       -- approval and rejection.  the committed_amt will only
1931       -- be used in the approval.
1932       CURSOR c_fund (l_fund_id IN NUMBER) IS
1933          SELECT object_version_number, currency_code_tc, planned_amt
1934            FROM ozf_funds_all_b
1935           WHERE fund_id = l_fund_id;
1936 
1937       CURSOR c_check_quota (p_type IN VARCHAR2, p_fund_id IN NUMBER) IS
1938          SELECT 1
1939          FROM  ozf_funds_all_b
1940          WHERE 'FUND' = p_type
1941            AND fund_type = 'QUOTA'
1942            AND fund_id = p_fund_id;
1943 
1944       l_fc_amount                  NUMBER;
1945       l_set_of_books_id            NUMBER;
1946       l_mrc_sob_type_code          VARCHAR2(30);
1947       l_fc_currency_code           VARCHAR2(150);
1948       l_exchange_rate_type         VARCHAR2(30) :=  FND_API.G_MISS_CHAR; --Added for bug 7030415
1949       l_exchange_rate              NUMBER;
1950       -- mpande for changed checkbook view 12/17/2001
1951       l_src_curr_request_amt       NUMBER;
1952       l_src_currency               VARCHAR2(150);
1953       l_rate                       NUMBER;
1954       l_old_parent_src_amt         NUMBER;
1955       l_check_validation   VARCHAR2(50) := fnd_profile.value('OZF_CHECK_MKTG_PROD_ELIG');
1956       l_offer_status               VARCHAR2(30);
1957       l_objfundsum_rec             ozf_objfundsum_pvt.objfundsum_rec_type := NULL;
1958       l_univ_amount                NUMBER;
1959       l_objfundsum_id              NUMBER;
1960       l_ledger_id                  NUMBER;
1961       l_ledger_name                VARCHAR2(30);
1962       l_is_quota                   NUMBER := NULL;
1963 
1964       --nirprasa, for bug 7425189
1965       l_fund_reconc_msg            VARCHAR2(4000);
1966       l_act_bud_cst_msg            VARCHAR2(4000);
1967 
1968       --nirprasa, added for multi currency enhancement
1969       l_transaction_currency       VARCHAR2(15);
1970 --feliu
1971 /*      CURSOR c_offer_status IS
1972          SELECT status_code
1973          FROM ozf_offers
1974          WHERE qp_list_header_id = p_act_budgets_rec.act_budget_used_by_id;
1975       fix bug 3116943 by feliu 08/28/03
1976 */
1977       CURSOR c_offer_status(l_qp_header_id IN NUMBER) IS
1978          SELECT status_code
1979          FROM ozf_offers
1980          WHERE qp_list_header_id = l_qp_header_id;
1981 
1982       -- yzhao: R12 insert/update ozf_object_fund_summary table
1983       CURSOR c_get_objfundsum_rec(p_object_type IN VARCHAR2, p_object_id IN NUMBER, p_fund_id IN NUMBER) IS
1984          SELECT objfundsum_id
1985               , object_version_number
1986               , planned_amt
1987               , plan_curr_planned_amt
1988               , univ_curr_planned_amt
1989          FROM   ozf_object_fund_summary
1990          WHERE  object_type = p_object_type
1991          AND    object_id = p_object_id
1992          AND    fund_id = p_fund_id;
1993 
1994        -- Added for bug 7030415
1995        CURSOR c_get_conversion_type( p_org_id IN NUMBER) IS
1996           SELECT exchange_rate_type
1997           FROM   ozf_sys_parameters_all
1998           WHERE  org_id = p_org_id;
1999 
2000        l_temp_request_amount  NUMBER;
2001        l_temp_approved_amount  NUMBER;
2002        l_temp_aprvd_orig_amount  NUMBER;
2003 
2004       -- nepanda : Fix for 12911854
2005       CURSOR c_get_gl_info(p_ledger_id IN NUMBER) IS
2006       SELECT currency_code
2007       FROM   gl_ledgers_public_v
2008       WHERE  ledger_id = p_ledger_id;
2009 
2010    BEGIN
2011       -- Standard Start of API savepoint
2012       SAVEPOINT update_act_budgets_pvt;
2013 
2014       -- Standard call to check for call compatibility.
2015       IF NOT fnd_api.compatible_api_call (l_api_version, p_api_version, l_api_name, g_package_name) THEN
2016          RAISE fnd_api.g_exc_unexpected_error;
2017       END IF;
2018 
2019        ozf_utility_pvt.debug_message(' update_Act_budgets.plan_currency_code mg: '  || p_act_util_rec.plan_currency_code);
2020 
2021       -- Initialize message list IF p_init_msg_list is set to TRUE.
2022       IF fnd_api.to_boolean (p_init_msg_list) THEN
2023          fnd_msg_pub.initialize;
2024       END IF;
2025 
2026       --  Initialize API return status to success
2027       x_return_status            := fnd_api.g_ret_sts_success;
2028       --
2029       -- API body
2030       --
2031      complete_act_budgets_rec (p_act_budgets_rec, l_act_budgets_rec);
2032       -- we have to set the currency always because the activity currency might change
2033       -- after creation of the budgets
2034       --nirprasa, get the transaction currency for null currency offers
2035      IF l_act_budgets_rec.request_currency IS NULL
2036      OR l_act_budgets_rec.request_currency = FND_API.G_MISS_CHAR THEN
2037      l_act_budgets_rec.request_currency :=
2038             get_object_currency (
2039                l_act_budgets_rec.arc_act_budget_used_by
2040               ,l_act_budgets_rec.act_budget_used_by_id
2041               ,l_return_status
2042             );
2043      END IF;
2044 
2045      l_transaction_currency := l_act_util_rec.plan_currency_code;
2046 
2047       IF l_act_budgets_rec.request_currency <> l_transaction_currency
2048         AND l_act_budgets_rec.arc_act_budget_used_by = 'OFFR' THEN
2049           l_act_budgets_rec.request_currency := l_transaction_currency;
2050       END IF;
2051      --nirprasa, for bug 7425189
2052      l_fund_reconc_msg := fnd_message.get_string ('OZF', 'OZF_FUND_RECONCILE');
2053      l_act_bud_cst_msg := fnd_message.get_string ('OZF', 'OZF_ACT_BUDG_CST_UTIL');
2054 
2055      IF G_DEBUG THEN
2056         ozf_utility_pvt.debug_message ('request_amount '||l_act_budgets_rec.request_amount);
2057         ozf_utility_pvt.debug_message('plan_curr_amount '|| p_act_util_rec.plan_curr_amount);
2058      END IF;
2059 
2060       /*12/19/2001 mpande Added code for UI requirement , when a object is transfering money he would request in
2061        object's currency and not source currency since here the source is the object, in case of transfer */
2062      IF l_act_budgets_rec.transfer_type = 'TRANSFER' THEN
2063          l_act_budgets_rec.approved_in_currency :=
2064             get_object_currency (
2065                l_act_budgets_rec.budget_source_type
2066               ,l_act_budgets_rec.budget_source_id
2067               ,l_return_status
2068             );
2069             IF G_DEBUG THEN
2070                ozf_utility_pvt.debug_message ('approved_in_currency '||l_act_budgets_rec.approved_in_currency);
2071                ozf_utility_pvt.debug_message ('request_currency '||l_act_budgets_rec.request_currency);
2072                ozf_utility_pvt.debug_message ('request_amount '||l_act_budgets_rec.request_amount);
2073                ozf_utility_pvt.debug_message ('src_curr_req_amt '||l_act_budgets_rec.src_curr_req_amt);
2074                ozf_utility_pvt.debug_message ('budget_source_type '||l_act_budgets_rec.budget_source_type);
2075                ozf_utility_pvt.debug_message ('l_transaction_currency '||l_transaction_currency);
2076             END IF;
2077          -- do this only if it is null because , in other case request amount should be passed correctly
2078          IF p_act_budgets_rec.request_amount IS NULL AND p_act_budgets_rec.src_curr_req_amt IS NOT NULL
2079             AND p_act_budgets_rec.src_curr_req_amt <> FND_API.g_miss_num THEN
2080 
2081             IF l_act_budgets_rec.request_currency = l_act_budgets_rec.approved_in_currency THEN
2082                -- don't need to convert if currencies are equal
2083                l_act_budgets_rec.request_amount := l_act_budgets_rec.src_curr_req_amt;
2084             ELSE
2085                -- convert the src_curr_request amount to the act_used_by  currency request amount.
2086                --This code will not be executed for transfer_type='UTILIZED'
2087                --In case of util/earned amt creation.
2088 
2089                IF G_DEBUG THEN
2090                   ozf_utility_pvt.debug_message (   l_api_name
2091                                      || ' l_act_budgets_rec.exchange_rate_date1: ' || l_act_budgets_rec.exchange_rate_date);
2092                END IF;
2093 
2094                ozf_utility_pvt.convert_currency (
2095                   x_return_status => l_return_status
2096                  ,p_from_currency => l_act_budgets_rec.approved_in_currency
2097                  ,p_to_currency   => l_act_budgets_rec.request_currency
2098                  ,p_conv_date     => l_act_budgets_rec.exchange_rate_date --bug 7425189, 8532055
2099                  ,p_from_amount   => l_act_budgets_rec.src_curr_req_amt
2100                  ,x_to_amount     => l_act_budgets_rec.request_amount
2101                );
2102 
2103                /*
2104 
2105                 --Added for bug 7425189
2106                 IF l_act_budgets_rec.justification IN (l_fund_reconc_msg,l_act_bud_cst_msg)
2107                 AND l_act_budgets_rec.exchange_rate_date IS NOT NULL THEN
2108 
2109                ozf_utility_pvt.convert_currency (
2110                   x_return_status=> l_return_status
2111                  ,p_from_currency=> l_act_budgets_rec.approved_in_currency
2112                  ,p_to_currency=> l_act_budgets_rec.request_currency
2113                  ,p_conv_date=> l_act_budgets_rec.exchange_rate_date
2114                  ,p_from_amount=> l_act_budgets_rec.src_curr_req_amt
2115                  ,x_to_amount=> l_act_budgets_rec.request_amount
2116                );
2117                ELSE
2118                 ozf_utility_pvt.convert_currency (
2119                   x_return_status=> l_return_status
2120                  ,p_from_currency=> l_act_budgets_rec.approved_in_currency
2121                  ,p_to_currency=> l_act_budgets_rec.request_currency
2122                  ,p_from_amount=> l_act_budgets_rec.src_curr_req_amt
2123                  ,x_to_amount=> l_act_budgets_rec.request_amount
2124                );
2125                END IF;
2126                */
2127 
2128                IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2129                   RAISE fnd_api.g_exc_unexpected_error;
2130                ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
2131                   RAISE fnd_api.g_exc_error;
2132                END IF;
2133             END IF;
2134          END IF;
2135      END IF;
2136      /* End OF CHange mpande 12/19/2001 */
2137 
2138       IF l_act_budgets_rec.request_currency IS NULL THEN
2139          ozf_utility_pvt.error_message ('OZF_ACT_BUDG_NO_CURRENCY');
2140          x_return_status            := fnd_api.g_ret_sts_error;
2141       END IF;
2142 
2143       IF l_return_status = fnd_api.g_ret_sts_error THEN
2144          RAISE fnd_api.g_exc_error;
2145       ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2146          RAISE fnd_api.g_exc_unexpected_error;
2147       END IF;
2148 
2149       IF l_act_budgets_rec.user_status_id IS NULL THEN
2150          l_act_budgets_rec.user_status_id :=
2151              ozf_utility_pvt.get_default_user_status (l_status_type, l_act_budgets_rec.status_code);
2152       ELSE
2153          l_act_budgets_rec.status_code :=
2154                           ozf_utility_pvt.get_system_status_code (l_act_budgets_rec.user_status_id);
2155       END IF;
2156 
2157       -- status rules for updating replace the record with one which
2158       -- only allows update of specific fields according to the status of the budget
2159       -- source line.  User can only drive the  approval process through status.
2160       OPEN c_current_status;
2161       FETCH c_current_status INTO l_old_status_code, l_old_approved_amount,l_old_parent_src_amt;
2162 
2163       IF c_current_status%NOTFOUND THEN
2164          CLOSE c_current_status;
2165          ozf_utility_pvt.error_message ('OZF_API_RECORD_NOT_FOUND');
2166          RAISE fnd_api.g_exc_unexpected_error;
2167       END IF;
2168 
2169       CLOSE c_current_status;
2170 
2171 
2172 
2173       IF l_old_status_code = 'CLOSED' THEN
2174          ozf_utility_pvt.error_message ('OZF_ACT_BUDG_REJECTED');
2175          RAISE fnd_api.g_exc_error;
2176       ELSIF l_old_status_code = 'REJECTED' THEN
2177          ozf_utility_pvt.error_message ('OZF_ACT_BUDG_REJECTED');
2178          RAISE fnd_api.g_exc_error;
2179       --
2180       -- Cases of valid approval:
2181       --    1) WF approval process responds to request to APPROVE, in which case, old status
2182       --       equals PENDING and new status equals APPROVED.
2183       --    2) No WF approval requried, in which case, approved_in_currency and approved_original_amount
2184       --       have values.
2185       ELSIF (    (l_old_status_code = 'PENDING' OR l_old_status_code = 'PENDING_VALIDATION')
2186              AND l_act_budgets_rec.status_code = 'APPROVED'
2187             ) THEN
2188         --for pending validation, need pass approved_in_currency.fixed bug 2853987 by feliu.
2189 
2190          IF l_old_status_code = 'PENDING_VALIDATION' THEN
2191             --l_act_budgets_rec.approved_in_currency := l_act_budgets_rec.request_currency;
2192             --fix bug 3354280 by feliu on 02/07/04
2193         l_act_budgets_rec.approved_in_currency :=get_object_currency (
2194                                              l_act_budgets_rec.budget_source_type
2195                                             ,l_act_budgets_rec.budget_source_id
2196                                             ,l_return_status
2197                                           );
2198      END IF;
2199      -- The WF approval process will make a call to
2200          -- the update API with a status of APPROVED
2201 
2202         -- For Bug#8867381, introduced p_use_fund_staging_tables for staging table impln of chargeback flow
2203         -- and px_ozf_funds_old_rectype for taking the funds old values
2204             -- For TPA Parallel Execution ER Bug#9614703
2205         -- and changed px_ozf_funds_new_rectype to px_ozf_funds_new_tbl.
2206 
2207          process_approval (
2208             p_act_budget_rec=> l_act_budgets_rec
2209            ,x_act_budget_rec=> l_temp_rec
2210            ,x_return_status=> l_return_status
2211            ,x_msg_count=> x_msg_count
2212            ,x_msg_data=> x_msg_data
2213            ,p_resale_batch_id=> l_resale_batch_id
2214                ,p_batch_type     =>    p_batch_type
2215            ,p_use_fund_staging_tables   => p_use_fund_staging_tables
2216            ,px_ozf_funds_old_rectype    =>      px_ozf_funds_old_rectype
2217            ,px_ozf_funds_new_tbl    =>      px_ozf_funds_new_tbl                -- For TPA Parallel Execution ER - 9614703
2218          );
2219 
2220          IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2221             RAISE fnd_api.g_exc_unexpected_error;
2222          ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
2223             RAISE fnd_api.g_exc_error;
2224          END IF;
2225 
2226          complete_act_budgets_rec (l_temp_rec, l_act_budgets_rec);
2227       ELSIF      l_old_status_code = 'PENDING'
2228              AND l_act_budgets_rec.status_code = 'REJECTED' THEN
2229          IF l_act_budgets_rec.budget_source_type = 'FUND'  AND l_act_budgets_rec.arc_act_budget_used_by <> 'FUND'THEN
2230            --- fix bug 4174002  to exclude budget transfer since not planned_amt  exists for pending status.
2231             -- if the budget source is a fund, then the fund's planned amount must be decreased
2232             -- by the request_amount during approval submission.
2233             ozf_funds_pvt.init_fund_rec (l_fund_rec);
2234             OPEN c_fund (l_act_budgets_rec.budget_source_id);
2235             FETCH c_fund INTO l_fund_object_version_number
2236                              ,l_fund_currency_tc
2237                              ,l_fund_planned_amount;
2238             CLOSE c_fund;
2239             l_fund_rec.fund_id         := l_act_budgets_rec.budget_source_id;
2240             l_fund_rec.object_version_number := l_fund_object_version_number;
2241 
2242             IF l_act_budgets_rec.request_currency = l_fund_currency_tc THEN
2243                -- don't need to convert if currencies are equal
2244                l_fund_rec.planned_amt     := l_act_budgets_rec.request_amount;
2245             ELSE
2246                -- convert the request amount to the fund's  currency.  the planned amount for a fund
2247                -- is stored in the table as a value based on the transactional currency, so the
2248                -- request amount must also be based on the  same currency.
2249                ozf_utility_pvt.convert_currency (
2250                   x_return_status=> l_return_status
2251                  ,p_from_currency=> l_act_budgets_rec.request_currency
2252                  ,p_to_currency=> l_fund_currency_tc
2253                  ,p_from_amount=> l_act_budgets_rec.request_amount
2254                  ,x_to_amount=> l_fund_rec.planned_amt
2255                );
2256 
2257                IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2258                   RAISE fnd_api.g_exc_unexpected_error;
2259                ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
2260                   RAISE fnd_api.g_exc_error;
2261                END IF;
2262             END IF;
2263 
2264             -- R12: yzhao BEGIN ozf_object_fund_summary decrease planned_amount
2265             IF g_universal_currency = l_act_budgets_rec.request_currency THEN
2266                l_univ_amount := l_act_budgets_rec.request_amount;
2267             ELSIF g_universal_currency = l_fund_currency_tc THEN
2268                l_univ_amount := l_fund_rec.planned_amt;
2269             ELSE
2270                ozf_utility_pvt.convert_currency (
2271                      x_return_status=> l_return_status
2272                     ,p_from_currency=> l_act_budgets_rec.request_currency
2273                     ,p_to_currency=> g_universal_currency
2274                     ,p_from_amount=> l_act_budgets_rec.request_amount
2275                     ,x_to_amount=> l_univ_amount
2276                );
2277 
2278                IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2279                   RAISE fnd_api.g_exc_unexpected_error;
2280                ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
2281                   RAISE fnd_api.g_exc_error;
2282                END IF;
2283             END IF;
2284 
2285 
2286             IF p_use_fund_staging_tables <> 'T' THEN
2287                     l_objfundsum_rec := NULL;
2288                     OPEN c_get_objfundsum_rec(l_act_budgets_rec.arc_act_budget_used_by
2289                                             , l_act_budgets_rec.act_budget_used_by_id
2290                                             , l_act_budgets_rec.budget_source_id);
2291                     FETCH c_get_objfundsum_rec INTO l_objfundsum_rec.objfundsum_id
2292                                                   , l_objfundsum_rec.object_version_number
2293                                                   , l_objfundsum_rec.planned_amt
2294                                                   , l_objfundsum_rec.plan_curr_planned_amt
2295                                                   , l_objfundsum_rec.univ_curr_planned_amt;
2296                     IF c_get_objfundsum_rec%NOTFOUND THEN
2297                        CLOSE c_get_objfundsum_rec;
2298                        IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_error) THEN
2299                           fnd_message.set_name('OZF', 'OZF_OBJFUNDSUM_RECORD_NOT_FOUND');
2300                           fnd_msg_pub.add;
2301                        END IF;
2302                        RAISE fnd_api.g_exc_error;
2303                     END IF;
2304                     CLOSE c_get_objfundsum_rec;
2305                     l_objfundsum_rec.planned_amt := NVL(l_objfundsum_rec.planned_amt, 0) + NVL (l_fund_rec.planned_amt, 0);
2306                     l_objfundsum_rec.plan_curr_planned_amt := NVL(l_objfundsum_rec.plan_curr_planned_amt, 0)
2307                                                             + NVL(l_act_budgets_rec.request_amount, 0);
2308                     l_objfundsum_rec.univ_curr_planned_amt := NVL(l_objfundsum_rec.univ_curr_planned_amt, 0) + NVL(l_univ_amount, 0);
2309                     ozf_objfundsum_pvt.update_objfundsum(
2310                            p_api_version                => 1.0,
2311                            p_init_msg_list              => Fnd_Api.G_FALSE,
2312                            p_validation_level           => Fnd_Api.G_VALID_LEVEL_NONE,
2313                            p_objfundsum_rec             => l_objfundsum_rec,
2314                            x_return_status              => l_return_status,
2315                            x_msg_count                  => x_msg_count,
2316                            x_msg_data                   => x_msg_data
2317                     );
2318                     IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2319                        RAISE fnd_api.g_exc_unexpected_error;
2320                     ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
2321                        RAISE fnd_api.g_exc_error;
2322                     END IF;
2323                     -- R12: yzhao END ozf_object_fund_summary decrease planned_amount
2324            END IF;
2325 
2326             -- subtract the request amount, l_fund_rec.planned_amt, to the
2327             -- fund's planned amount, l_fund_planned_amount.
2328             l_fund_rec.planned_amt     :=   l_fund_planned_amount
2329                                           - l_fund_rec.planned_amt;
2330             ozf_funds_pvt.update_fund (
2331                p_api_version=> 1.0
2332               ,p_init_msg_list=> fnd_api.g_false
2333               , -- allow the calling API to handle
2334                p_commit=> fnd_api.g_false
2335               , -- allow the calling API to handle
2336                p_validation_level=> p_validation_level
2337               ,x_return_status=> l_return_status
2338               ,x_msg_count=> x_msg_count
2339               ,x_msg_data=> x_msg_data
2340               ,p_fund_rec=> l_fund_rec
2341               ,p_mode=> g_cons_fund_mode
2342             );
2343 
2344             IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2345                RAISE fnd_api.g_exc_unexpected_error;
2346             ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
2347                RAISE fnd_api.g_exc_error;
2348             END IF;
2349 
2350          END IF; -- if source type = FUND
2351       ELSIF      (l_old_status_code = 'PENDING' OR l_old_status_code = 'PENDING_VALIDATION')
2352              AND l_act_budgets_rec.status_code = 'NEW' THEN
2353          -- an error occurred during the approval process, revert back to NEW
2354          -- if budget source is a FUND, then revert the planned amount.
2355          init_act_budgets_rec (l_temp_rec);
2356          revert_approval (
2357             l_act_budgets_rec
2358            ,p_use_fund_staging_tables
2359            ,l_temp_rec
2360            ,x_return_status
2361            ,x_msg_count
2362            ,x_msg_data
2363          );
2364          complete_act_budgets_rec (l_temp_rec, l_act_budgets_rec);
2365       ELSIF l_old_status_code = 'NEW' THEN
2366          -- new budget source lines can get a new requested budget amount
2367 
2368          init_act_budgets_rec (l_temp_rec);
2369          l_temp_rec.activity_budget_id := l_act_budgets_rec.activity_budget_id;
2370          l_temp_rec.object_version_number := l_act_budgets_rec.object_version_number;
2371          l_temp_rec.spent_amount    := l_act_budgets_rec.spent_amount;
2372          l_temp_rec.request_amount  := l_act_budgets_rec.request_amount;
2373          l_temp_rec.date_required_by := l_act_budgets_rec.date_required_by;
2374          l_temp_rec.justification   := l_act_budgets_rec.justification;
2375          l_temp_rec.reason_code     := l_act_budgets_rec.reason_code;
2376          l_temp_rec.partner_holding_type := l_act_budgets_rec.partner_holding_type;
2377          l_temp_rec.partner_address_id := l_act_budgets_rec.partner_address_id;
2378          l_temp_rec.vendor_id       := l_act_budgets_rec.vendor_id;
2379          l_temp_rec.budget_source_id       := l_act_budgets_rec.budget_source_id;
2380          l_temp_rec.comment   := l_act_budgets_rec.comment;
2381          l_temp_rec.partner_po_number   := l_act_budgets_rec.partner_po_number;
2382          l_temp_rec.owner_id   := l_act_budgets_rec.owner_id;
2383          l_temp_rec.act_budget_used_by_id := l_act_budgets_rec.act_budget_used_by_id;
2384          l_temp_rec.arc_act_budget_used_by := l_act_budgets_rec.arc_act_budget_used_by;
2385          l_temp_rec.budget_source_type       := l_act_budgets_rec.budget_source_type;
2386      --
2387          -- changing status from NEW to APPROVED is equivalent to submitting for approval.
2388          IF l_act_budgets_rec.status_code = 'APPROVED' THEN
2389             l_temp_rec.status_code     := 'PENDING';
2390 
2391             IF      l_act_budgets_rec.budget_source_type = 'FUND'
2392                 AND l_act_budgets_rec.arc_act_budget_used_by <> 'FUND' THEN
2393                -- if the budget source is a fund, then the fund's planned amount must be incremented
2394                -- by the request_amount during approval submission.
2395                ozf_funds_pvt.init_fund_rec (l_fund_rec);
2396                OPEN c_fund (l_act_budgets_rec.budget_source_id);
2397                FETCH c_fund INTO l_fund_object_version_number
2398                                 ,l_fund_currency_tc
2399                                 ,l_fund_planned_amount;
2400                CLOSE c_fund;
2401                l_fund_rec.fund_id         := l_act_budgets_rec.budget_source_id;
2402                l_fund_rec.object_version_number := l_fund_object_version_number;
2403 
2404                IF l_act_budgets_rec.request_currency = l_fund_currency_tc THEN
2405                   -- don't need to convert if currencies are equal
2406                   l_fund_rec.planned_amt     := l_act_budgets_rec.request_amount;
2407                ELSE
2408                   -- convert the request amount to the fund's currency.  the planned amount for a fund
2409                   -- is stored in the table as a value based on the transactional currency, so the
2410                   -- request amount must also be based on the same currency.
2411 
2412                   ozf_utility_pvt.convert_currency (
2413                      x_return_status=> l_return_status
2414                     ,p_from_currency=> l_act_budgets_rec.request_currency
2415                     ,p_to_currency=> l_fund_currency_tc
2416                     ,p_from_amount=> l_act_budgets_rec.request_amount
2417                     ,x_to_amount=> l_fund_rec.planned_amt
2418                   );
2419 
2420                   IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2421                      RAISE fnd_api.g_exc_unexpected_error;
2422                   ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
2423                      RAISE fnd_api.g_exc_error;
2424                   END IF;
2425                END IF;
2426 
2427                -- R12: yzhao BEGIN ozf_object_fund_summary increase planned_amount
2428                IF g_universal_currency = l_act_budgets_rec.request_currency THEN
2429                   l_univ_amount := l_act_budgets_rec.request_amount;
2430                ELSIF g_universal_currency = l_fund_currency_tc THEN
2431                   l_univ_amount := l_fund_rec.planned_amt;
2432                ELSE
2433                   ozf_utility_pvt.convert_currency (
2434                      x_return_status=> l_return_status
2435                     ,p_from_currency=> l_act_budgets_rec.request_currency
2436                     ,p_to_currency=> g_universal_currency
2437                     ,p_from_amount=> l_act_budgets_rec.request_amount
2438                     ,x_to_amount=> l_univ_amount
2439                   );
2440 
2441                   IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2442                      RAISE fnd_api.g_exc_unexpected_error;
2443                   ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
2444                      RAISE fnd_api.g_exc_error;
2445                   END IF;
2446                END IF;
2447 
2448                l_objfundsum_rec := NULL;
2449                OPEN c_get_objfundsum_rec(l_act_budgets_rec.arc_act_budget_used_by
2450                                        , l_act_budgets_rec.act_budget_used_by_id
2451                                        , l_act_budgets_rec.budget_source_id);
2452                FETCH c_get_objfundsum_rec INTO l_objfundsum_rec.objfundsum_id
2453                                              , l_objfundsum_rec.object_version_number
2454                                              , l_objfundsum_rec.planned_amt
2455                                              , l_objfundsum_rec.plan_curr_planned_amt
2456                                              , l_objfundsum_rec.univ_curr_planned_amt;
2457                CLOSE c_get_objfundsum_rec;
2458                l_objfundsum_rec.fund_id := l_act_budgets_rec.budget_source_id;
2459                l_objfundsum_rec.fund_currency := l_fund_currency_tc;
2460                l_objfundsum_rec.object_type := l_act_budgets_rec.arc_act_budget_used_by;
2461                l_objfundsum_rec.object_id := l_act_budgets_rec.act_budget_used_by_id;
2462                l_objfundsum_rec.object_currency := l_act_budgets_rec.request_currency;
2463                l_objfundsum_rec.planned_amt := NVL(l_objfundsum_rec.planned_amt, 0) + NVL (l_fund_rec.planned_amt, 0);
2464                l_objfundsum_rec.plan_curr_planned_amt := NVL(l_objfundsum_rec.plan_curr_planned_amt, 0)
2465                                                        + NVL(l_act_budgets_rec.request_amount, 0);
2466                l_objfundsum_rec.univ_curr_planned_amt := NVL(l_objfundsum_rec.univ_curr_planned_amt, 0) + NVL(l_univ_amount, 0);
2467                IF l_objfundsum_rec.objfundsum_id IS NULL THEN
2468                            ozf_objfundsum_pvt.create_objfundsum(
2469                                p_api_version                => 1.0,
2470                                p_init_msg_list              => Fnd_Api.G_FALSE,
2471                                p_validation_level           => Fnd_Api.G_VALID_LEVEL_NONE,
2472                                p_objfundsum_rec             => l_objfundsum_rec,
2473                                x_return_status              => l_return_status,
2474                                x_msg_count                  => x_msg_count,
2475                                x_msg_data                   => x_msg_data,
2476                                x_objfundsum_id              => l_objfundsum_id
2477                            );
2478                ELSE
2479 
2480                         IF p_use_fund_staging_tables <> 'T' THEN
2481                            ozf_objfundsum_pvt.update_objfundsum(
2482                                p_api_version                => 1.0,
2483                                p_init_msg_list              => Fnd_Api.G_FALSE,
2484                                p_validation_level           => Fnd_Api.G_VALID_LEVEL_NONE,
2485                                p_objfundsum_rec             => l_objfundsum_rec,
2486                                x_return_status              => l_return_status,
2487                                x_msg_count                  => x_msg_count,
2488                                x_msg_data                   => x_msg_data
2489                            );
2490                        END IF;
2491                        IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2492                           RAISE fnd_api.g_exc_unexpected_error;
2493                        ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
2494                           RAISE fnd_api.g_exc_error;
2495                        END IF;
2496                        -- R12: yzhao END insert/update ozf_object_fund_summary table for planned_amount
2497                END IF;
2498 
2499                -- increase fund's planned amount by the new request amount
2500                l_fund_rec.planned_amt     :=
2501                                       NVL (l_fund_rec.planned_amt, 0)
2502                                     + NVL (l_fund_planned_amount, 0);
2503 
2504                -- 02/23/2001 mpande you cannot plan for more than the available budget amount
2505 
2506                -- 02/18/2004 feliu  check profile, if profile is N, then validate, otherwise not validate.
2507                IF l_exceed_flag = 'N' THEN
2508                   IF OZF_ACTBUDGETRULES_PVT.budget_has_enough_money (
2509                      p_source_id=> l_act_budgets_rec.budget_source_id
2510                     ,p_approved_amount=> l_fund_rec.planned_amt
2511                     ) = fnd_api.g_false THEN
2512                      ozf_utility_pvt.error_message ('OZF_ACT_BUDG_NO_MONEY');
2513                      RAISE fnd_api.g_exc_error;
2514                   END IF;
2515                END IF;
2516 
2517                ozf_funds_pvt.update_fund (
2518                   p_api_version=> 1.0
2519                  ,p_init_msg_list=> fnd_api.g_false
2520                  ,p_commit=> fnd_api.g_false
2521                  ,p_validation_level=> p_validation_level
2522                  ,x_return_status=> l_return_status
2523                  ,x_msg_count=> x_msg_count
2524                  ,x_msg_data=> x_msg_data
2525                  ,p_fund_rec=> l_fund_rec
2526                  ,p_mode=> g_cons_fund_mode
2527                );
2528 
2529                IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2530                   RAISE fnd_api.g_exc_unexpected_error;
2531                ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
2532                   RAISE fnd_api.g_exc_error;
2533                END IF;
2534 
2535             END IF; -- if source type = FUND
2536 
2537 
2538             -- call the approval API
2539             trigger_approval_process (
2540                p_act_budget_rec=> l_act_budgets_rec
2541               ,x_act_budget_rec=> l_temp_rec
2542               ,x_return_status=> l_return_status
2543               ,x_msg_count=> x_msg_count
2544               ,x_msg_data=> x_msg_data
2545               ,p_parent_process_flag=> p_parent_process_flag
2546               ,p_parent_process_key=> p_parent_process_key
2547               ,p_parent_context=> p_parent_context
2548               ,p_parent_approval_flag=> p_parent_approval_flag
2549               ,p_continue_flow=> p_continue_flow
2550               ,p_child_approval_flag=> p_child_approval_flag ---- added 05/22/2001 mpande
2551               ,p_requestor_owner_flag => p_requestor_owner_flag ---- added 10/19/2001 mpande
2552           ,x_start_flow_flag  => l_start_flow_flag -- if 'Y', need start workflow after updating.
2553             );
2554 
2555             IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2556                RAISE fnd_api.g_exc_unexpected_error;
2557             ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
2558                RAISE fnd_api.g_exc_error;
2559             END IF;
2560 
2561          END IF; -- if new.status_code = APPROVED
2562 
2563          complete_act_budgets_rec (l_temp_rec, l_act_budgets_rec);
2564       ELSE
2565          -- a approved utlized record could be updated with the new amount
2566          IF l_act_budgets_rec.transfer_type IN ('UTILIZED') THEN
2567             IF l_act_budgets_rec.status_code = 'APPROVED' THEN
2568                l_act_budgets_rec.approved_amount := l_act_budgets_rec.request_amount;
2569                l_act_budgets_rec.approved_in_currency :=
2570                      get_object_currency (
2571                         l_act_budgets_rec.arc_act_budget_used_by
2572                        ,l_act_budgets_rec.act_budget_used_by_id
2573                        ,l_return_status
2574                      );
2575                --nirprasa,12.1.1 now should use transaction currency
2576                IF l_act_budgets_rec.approved_in_currency <> l_transaction_currency
2577                   AND l_act_budgets_rec.arc_act_budget_used_by = 'OFFR' THEN
2578                      l_act_budgets_rec.approved_in_currency := l_transaction_currency;
2579                END IF;
2580 
2581                IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2582                   RAISE fnd_api.g_exc_unexpected_error;
2583                ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
2584                   RAISE fnd_api.g_exc_error;
2585                END IF;
2586 
2587                IF l_act_budgets_rec.request_currency = l_act_budgets_rec.approved_in_currency THEN
2588                   -- don't need to convert if currencies are equal
2589                   l_act_budgets_rec.approved_original_amount := l_act_budgets_rec.request_amount;
2590                ELSE
2591                   -- convert the request amount to the fund's  currency.
2592                   --both request_currency and approved_in_currency are in offer's transaction currency
2593                   --in case of accruals. Still do the conversion.
2594 
2595                   OPEN c_get_conversion_type(l_act_util_rec.org_id);
2596                   FETCH c_get_conversion_type INTO l_exchange_rate_type;
2597                   CLOSE c_get_conversion_type;
2598 
2599                   IF G_DEBUG THEN
2600                      ozf_utility_pvt.debug_message (   l_api_name
2601                                      || ' l_act_budgets_rec.exchange_rate_date2: ' || l_act_budgets_rec.exchange_rate_date);
2602                   END IF;
2603 
2604                   ozf_utility_pvt.convert_currency (
2605                      x_return_status=> l_return_status
2606                     ,p_from_currency=> l_act_budgets_rec.request_currency
2607                     ,p_to_currency=> l_act_budgets_rec.approved_in_currency
2608                     ,p_conv_type=> l_exchange_rate_type
2609                     ,p_conv_date=> l_act_budgets_rec.exchange_rate_date --bug 7425189, 8532055
2610                     ,p_from_amount=> l_act_budgets_rec.request_amount
2611                     ,x_to_amount=> l_act_budgets_rec.approved_original_amount
2612                     ,x_rate=> l_rate
2613                   );
2614 
2615                   /*
2616                   --Added for bug 7425189
2617                   IF l_act_budgets_rec.justification IN (l_fund_reconc_msg,l_act_bud_cst_msg)
2618                   AND l_act_budgets_rec.exchange_rate_date IS NOT NULL THEN
2619                   ozf_utility_pvt.convert_currency (
2620                      x_return_status=> l_return_status
2621                     ,p_from_currency=> l_act_budgets_rec.request_currency
2622                     ,p_to_currency=> l_act_budgets_rec.approved_in_currency
2623                     ,p_conv_type=> l_exchange_rate_type
2624                     ,p_conv_date=> l_act_budgets_rec.exchange_rate_date
2625                     ,p_from_amount=> l_act_budgets_rec.request_amount
2626                     ,x_to_amount=> l_act_budgets_rec.approved_original_amount
2627                     ,x_rate=> l_rate
2628                   );
2629 
2630                   ELSE
2631                   ozf_utility_pvt.convert_currency (
2632                      x_return_status=> l_return_status
2633                     ,p_from_currency=> l_act_budgets_rec.request_currency
2634                     ,p_to_currency=> l_act_budgets_rec.approved_in_currency
2635                     ,p_conv_type=> l_exchange_rate_type
2636                     ,p_from_amount=> l_act_budgets_rec.request_amount
2637                     ,x_to_amount=> l_act_budgets_rec.approved_original_amount
2638                     ,x_rate=> l_rate
2639                   );
2640 
2641 
2642                   END IF;
2643                   */
2644 
2645                   IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2646                      RAISE fnd_api.g_exc_unexpected_error;
2647                   ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
2648                      RAISE fnd_api.g_exc_error;
2649                   END IF;
2650                END IF;
2651             END IF;
2652          END IF;
2653       END IF;
2654 
2655       -- get the corresponding user_status_id
2656       -- for the given status_code.
2657       l_act_budgets_rec.user_status_id :=
2658               ozf_utility_pvt.get_default_user_status (l_status_type, l_act_budgets_rec.status_code);
2659       IF G_DEBUG THEN
2660          ozf_utility_pvt.debug_message (   l_api_name
2661                                      || ': check items');
2662       END IF;
2663       l_act_budgets_rec.comment :=   p_act_budgets_rec.comment;
2664 
2665       -- mpande added to populate request amount in request currency 12/17/2001 src_curr_request_amt
2666       IF l_act_budgets_rec.budget_source_type IN ('PTNR','OPTN') THEN
2667          -- for these objects money is in the request currency
2668          l_src_currency := l_act_budgets_rec.request_currency ;
2669       ELSE
2670       l_src_currency :=
2671             get_object_currency (
2672                l_act_budgets_rec.budget_source_type
2673               ,l_act_budgets_rec.budget_source_id
2674               ,l_return_status
2675             );
2676       END IF;
2677       IF G_DEBUG THEN
2678       ozf_utility_pvt.debug_message (   l_api_name
2679                                      || ': l_src_currency '||l_src_currency);
2680       ozf_utility_pvt.debug_message (   l_api_name
2681                                      || ': l_act_budgets_rec.request_currency'
2682                                      || l_act_budgets_rec.request_currency);
2683       ozf_utility_pvt.debug_message (   l_api_name
2684                                      || ': l_act_budgets_rec.request_amount'
2685                                      || l_act_budgets_rec.request_amount);
2686       END IF;
2687 
2688       --Added for bug 7030415
2689 
2690       IF l_act_budgets_rec.transfer_type IN ('UTILIZED') THEN
2691         OPEN c_get_conversion_type(l_act_util_rec.org_id);
2692         FETCH c_get_conversion_type INTO l_exchange_rate_type;
2693         CLOSE c_get_conversion_type;
2694       ELSE
2695       l_exchange_rate_type := FND_API.G_MISS_CHAR;
2696       END IF;
2697 
2698       IF NVL(l_act_budgets_rec.request_amount,0) <> 0 THEN
2699 
2700          IF G_DEBUG THEN
2701             ozf_utility_pvt.debug_message (   l_api_name
2702                              || ' l_act_budgets_rec.exchange_rate_date3: ' || l_act_budgets_rec.exchange_rate_date);
2703          END IF;
2704 
2705           --Added for bug 7425189
2706           IF l_act_budgets_rec.justification IN (l_fund_reconc_msg,l_act_bud_cst_msg)
2707           AND l_act_budgets_rec.exchange_rate_date IS NOT NULL THEN
2708 
2709             IF l_act_budgets_rec.src_curr_req_amt IS NULL THEN
2710             ozf_utility_pvt.convert_currency(
2711             p_from_currency   => l_act_budgets_rec.request_currency
2712            ,p_to_currency     => l_src_currency
2713            ,p_conv_type       => l_exchange_rate_type
2714            ,p_conv_date       => l_act_budgets_rec.exchange_rate_date
2715            ,p_from_amount     => l_act_budgets_rec.request_amount
2716            ,x_return_status   => l_return_status
2717            ,x_to_amount       => l_src_curr_request_amt
2718            ,x_rate            => l_rate);
2719            END IF;
2720           ELSE
2721             ozf_utility_pvt.convert_currency(
2722             p_from_currency   => l_act_budgets_rec.request_currency
2723            ,p_to_currency     => l_src_currency
2724            ,p_conv_type       => l_exchange_rate_type
2725            ,p_conv_date       => l_act_budgets_rec.exchange_rate_date --bug 8532055
2726            ,p_from_amount     => l_act_budgets_rec.request_amount
2727            ,x_return_status   => l_return_status
2728            ,x_to_amount       => l_src_curr_request_amt
2729            ,x_rate            => l_rate);
2730          END IF;
2731 
2732          IF l_return_status = fnd_api.g_ret_sts_error THEN
2733             RAISE fnd_api.g_exc_error;
2734          ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2735             RAISE fnd_api.g_exc_unexpected_error;
2736          END IF;
2737       END IF;
2738       IF G_DEBUG THEN
2739       ozf_utility_pvt.debug_message (   l_api_name
2740                                      || ': l_act_budgets_rec.src_curr_req_amt'
2741                                      || l_act_budgets_rec.src_curr_req_amt);
2742       END IF;
2743       IF p_validation_level >= jtf_plsql_api.g_valid_level_item THEN
2744          validate_act_budgets_items (
2745             p_act_budgets_rec=> l_act_budgets_rec
2746            ,p_validation_mode=> jtf_plsql_api.g_update
2747            ,x_return_status=> l_return_status
2748          );
2749 
2750          -- If any errors happen abort API.
2751          IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2752             RAISE fnd_api.g_exc_unexpected_error;
2753          ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
2754             RAISE fnd_api.g_exc_error;
2755          END IF;
2756       END IF;
2757 
2758       IF G_DEBUG THEN
2759          ozf_utility_pvt.debug_message (   l_api_name
2760                                      || ': check records');
2761       END IF;
2762 
2763       IF p_validation_level >= jtf_plsql_api.g_valid_level_record THEN
2764          validate_act_budgets_record (
2765             p_act_budgets_rec=> l_act_budgets_rec
2766            ,p_validation_mode=> jtf_plsql_api.g_update
2767            ,x_return_status=> l_return_status
2768          );
2769 
2770          IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2771             RAISE fnd_api.g_exc_unexpected_error;
2772          ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
2773             RAISE fnd_api.g_exc_error;
2774          END IF;
2775       END IF;
2776 
2777       -- Added 04/26/2001 mpande for new functionality changes for hornet
2778       IF      l_act_budgets_rec.budget_source_type = 'FUND'
2779           AND l_act_budgets_rec.arc_act_budget_used_by = 'FUND' THEN
2780          l_fund_transfer_flag       := 'Y';
2781      IF l_act_budgets_rec.status_code = 'APPROVED'  THEN
2782            l_act_budgets_rec.approval_date := SYSDATE;
2783          END IF;
2784       END IF;
2785 
2786       IF l_return_status = fnd_api.g_ret_sts_error THEN
2787          RAISE fnd_api.g_exc_error;
2788       ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2789          RAISE fnd_api.g_exc_unexpected_error;
2790       END IF;
2791 
2792 
2793 
2794 
2795 
2796 
2797       IF NVL(l_act_budgets_rec.approved_amount,0) <> 0 THEN
2798          -- R12: yzhao Oct. 10, 2005 get budget ledger when calculating functional currency
2799          IF l_act_util_rec.org_id IS NOT NULL THEN
2800             MO_UTILS.Get_Ledger_Info (
2801                     p_operating_unit     =>  l_act_util_rec.org_id,
2802                     p_ledger_id          =>  l_ledger_id,
2803                     p_ledger_name        =>  l_ledger_name
2804             );
2805             IF G_DEBUG THEN
2806                  ozf_utility_pvt.debug_message (   l_api_name
2807                                              || ': create_act_budgets   ledger for util.org_id('
2808                                              || l_act_util_rec.org_id || ')=' || l_ledger_id);
2809             END IF;
2810             ozf_utility_pvt.write_conc_log (   l_api_name
2811                                              || ': create_act_budgets   ledger for util.org_id('
2812                                              || l_act_util_rec.org_id || ')=' || l_ledger_id);
2813          ELSE
2814 
2815             ozf_utility_pvt.get_object_org_ledger(p_object_type => l_act_budgets_rec.arc_act_budget_used_by
2816                                                 , p_object_id   => l_act_budgets_rec.act_budget_used_by_id
2817                                                 , x_org_id      => l_act_util_rec.org_id
2818                                                 , x_ledger_id   => l_ledger_id
2819                                                 , x_return_status => l_return_status
2820                                            );
2821             IF G_DEBUG THEN
2822                  ozf_utility_pvt.debug_message (   l_api_name
2823                                              || ': create_act_budgets   ledger for '
2824                                              || l_act_budgets_rec.arc_act_budget_used_by
2825                                              || '  id('
2826                                              || l_act_budgets_rec.act_budget_used_by_id
2827                                              || ') returns ' || l_return_status
2828                                              || '  ledger_id=' || l_ledger_id);
2829             END IF;
2830                   ozf_utility_pvt.write_conc_log (   l_api_name
2831                                              || ': create_act_budgets   ledger for '
2832                                              || l_act_budgets_rec.arc_act_budget_used_by
2833                                              || '  id('
2834                                              || l_act_budgets_rec.act_budget_used_by_id
2835                                              || ') returns ' || l_return_status
2836                                              || '  ledger_id=' || l_ledger_id);
2837             IF l_return_status = fnd_api.g_ret_sts_error THEN
2838                RAISE fnd_api.g_exc_error;
2839             ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2840                 RAISE fnd_api.g_exc_unexpected_error;
2841             END IF;
2842          END IF;
2843 
2844 
2845 
2846          --kdass 16-NOV-2005 bug 4728515 - for quota, bypass ledger check
2847          OPEN  c_check_quota (l_act_budgets_rec.budget_source_type, l_act_budgets_rec.budget_source_id);
2848          FETCH c_check_quota INTO l_is_quota;
2849          CLOSE c_check_quota;
2850 
2851          IF l_is_quota IS NULL THEN
2852             -- yzhao: R12 Oct 19 2005 No need to calculate functional currency if it is for marketing use
2853             IF l_ledger_id IS NULL AND l_is_quota IS NULL THEN
2854                IF l_act_budgets_rec.budget_source_type NOT IN ('CAMP', 'CSCH', 'EVEO', 'EVEH', 'EONE') AND
2855                   l_act_budgets_rec.arc_act_budget_used_by NOT IN ('CAMP', 'CSCH', 'EVEO', 'EVEH', 'EONE') THEN
2856                   IF G_DEBUG THEN
2857                      ozf_utility_pvt.debug_message (   l_api_name
2858                                                  || ': create_act_budgets   ledger not found for '
2859                                                  || l_act_budgets_rec.arc_act_budget_used_by
2860                                                  || '  id('
2861                                                  || l_act_budgets_rec.act_budget_used_by_id);
2862                   END IF;
2863                   IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
2864                      fnd_message.set_name ('OZF', 'OZF_NO_LEDGER_FOUND');
2865                      --Message OZF_NO_LEDGER_FOUND changed fix bug 5190932
2866                      --fnd_message.set_token('OBJECT_TYPE', l_act_budgets_rec.arc_act_budget_used_by);
2867                      --fnd_message.set_token('OBJECT_ID', l_act_budgets_rec.act_budget_used_by_id);
2868                      fnd_msg_pub.ADD;
2869                   END IF;
2870                   x_return_status            := fnd_api.g_ret_sts_error;
2871                   RAISE fnd_api.g_exc_error;
2872                END IF;
2873             ELSE
2874                 --Added for bug 7030415
2875                 OPEN c_get_conversion_type(l_act_util_rec.org_id);
2876                 FETCH c_get_conversion_type INTO l_exchange_rate_type;
2877                 CLOSE c_get_conversion_type;
2878 
2879 
2880                 IF G_DEBUG THEN
2881                    ozf_utility_pvt.debug_message (   l_api_name
2882                              || ' l_act_budgets_rec.exchange_rate_date4: ' || l_act_budgets_rec.exchange_rate_date);
2883                 END IF;
2884 
2885                   --Added for bug 7425189
2886                   IF l_act_budgets_rec.justification IN (l_fund_reconc_msg,l_act_bud_cst_msg)
2887                   AND l_act_budgets_rec.exchange_rate_date IS NOT NULL THEN
2888                     l_exchange_rate_type := NULL;
2889                     ozf_utility_pvt.calculate_functional_currency(
2890                            p_from_amount        => l_act_budgets_rec.approved_amount
2891                           ,p_conv_date          => l_act_budgets_rec.exchange_rate_date
2892                           ,p_tc_currency_code   => l_act_budgets_rec.request_currency
2893                           ,p_ledger_id          => l_ledger_id
2894                           ,x_to_amount          => l_fc_amount
2895                           ,x_mrc_sob_type_code  => l_mrc_sob_type_code
2896                           ,x_fc_currency_code   => l_fc_currency_code
2897                           ,x_exchange_rate_type => l_exchange_rate_type
2898                           ,x_exchange_rate      => l_exchange_rate
2899                           ,x_return_status      => l_return_status);
2900                   ELSE
2901                     ozf_utility_pvt.calculate_functional_currency(
2902                          p_from_amount        => l_act_budgets_rec.approved_amount
2903                         ,p_conv_date          => l_act_budgets_rec.exchange_rate_date --bug 8532055
2904                         ,p_tc_currency_code   => l_act_budgets_rec.request_currency
2905                         ,p_ledger_id          => l_ledger_id
2906                         ,x_to_amount          => l_fc_amount
2907                         ,x_mrc_sob_type_code  => l_mrc_sob_type_code
2908                         ,x_fc_currency_code   => l_fc_currency_code
2909                         ,x_exchange_rate_type => l_exchange_rate_type
2910                         ,x_exchange_rate      => l_exchange_rate
2911                         ,x_return_status      => l_return_status);
2912                   END IF;
2913 
2914                IF l_return_status = fnd_api.g_ret_sts_error THEN
2915                   RAISE fnd_api.g_exc_error;
2916                ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2917                   RAISE fnd_api.g_exc_unexpected_error;
2918                END IF;
2919             END IF;
2920          END IF;
2921       END IF;
2922 
2923    -- For BUG#8867381(+)
2924    -- l_use_fund_staging_tables flag is set only for chargeback flow and will insert the records into
2925    -- plsql tables and pass it on to OZF_RESALE_COMMON_PVT.UPDATE_OZF_ACT_BUDGETS procedure for updating
2926    -- the main table.
2927 
2928    IF l_use_fund_staging_tables <> 'T' then
2929 
2930            IF G_DEBUG THEN
2931             ozf_utility_pvt.debug_message('Going to update mode as l_use_fund_staging_tables is :'||l_use_fund_staging_tables );
2932             ozf_utility_pvt.debug_message('request_amount :'|| l_act_budgets_rec.request_amount );
2933           END IF;
2934 
2935       -- Perform the database operation
2936       UPDATE ozf_act_budgets
2937          SET last_update_date = SYSDATE
2938             ,last_updated_by = fnd_global.user_id
2939             ,last_update_login = fnd_global.conc_login_id
2940             ,object_version_number =   l_act_budgets_rec.object_version_number
2941                                      + 1
2942             ,act_budget_used_by_id = l_act_budgets_rec.act_budget_used_by_id
2943             ,arc_act_budget_used_by = l_act_budgets_rec.arc_act_budget_used_by
2944             ,budget_source_type = l_act_budgets_rec.budget_source_type
2945             ,budget_source_id = l_act_budgets_rec.budget_source_id
2946             ,transaction_type = l_act_budgets_rec.transaction_type
2947             ,request_amount = l_act_budgets_rec.request_amount
2948             ,request_currency = l_act_budgets_rec.request_currency
2949             ,request_date = NVL (l_act_budgets_rec.request_date, SYSDATE)
2950             ,user_status_id = l_act_budgets_rec.user_status_id
2951             ,status_code = l_act_budgets_rec.status_code
2952             ,approved_amount = l_act_budgets_rec.approved_amount
2953             ,approved_original_amount = l_act_budgets_rec.approved_original_amount
2954             ,approved_in_currency = l_act_budgets_rec.approved_in_currency
2955             ,approval_date = l_act_budgets_rec.approval_date
2956             ,approver_id = l_act_budgets_rec.approver_id
2957             ,spent_amount = l_act_budgets_rec.spent_amount
2958             ,partner_po_number = l_act_budgets_rec.partner_po_number
2959             ,partner_po_date = l_act_budgets_rec.partner_po_date
2960             ,partner_po_approver = l_act_budgets_rec.partner_po_approver
2961             ,posted_flag = l_act_budgets_rec.posted_flag
2962             ,adjusted_flag = l_act_budgets_rec.adjusted_flag
2963             ,transfer_type = l_act_budgets_rec.transfer_type
2964             ,reason_code = l_act_budgets_rec.reason_code
2965             ,parent_act_budget_id = l_act_budgets_rec.parent_act_budget_id
2966             ,contact_id = l_act_budgets_rec.contact_id
2967             ,requester_id = NVL (
2968                                l_act_budgets_rec.requester_id
2969                               ,ozf_utility_pvt.get_resource_id (fnd_global.user_id)
2970                             ) --l_act_budgets_rec.requester_id
2971             ,date_required_by = l_act_budgets_rec.date_required_by
2972             ,parent_source_id = l_act_budgets_rec.parent_source_id,
2973              parent_src_curr = l_act_budgets_rec.parent_src_curr,
2974              parent_src_apprvd_amt = l_act_budgets_rec.parent_src_apprvd_amt,
2975              partner_holding_type = l_act_budgets_rec.partner_holding_type
2976             ,partner_address_id = l_act_budgets_rec.partner_address_id
2977             ,vendor_id = l_act_budgets_rec.vendor_id
2978             ,owner_id = l_act_budgets_rec.owner_id
2979             ,recal_flag = l_act_budgets_rec.recal_flag
2980             ,attribute_category = p_act_budgets_rec.attribute_category
2981             ,attribute1 = p_act_budgets_rec.attribute1
2982             ,attribute2 = p_act_budgets_rec.attribute2
2983             ,attribute3 = p_act_budgets_rec.attribute3
2984             ,attribute4 = p_act_budgets_rec.attribute4
2985             ,attribute5 = p_act_budgets_rec.attribute5
2986             ,attribute6 = p_act_budgets_rec.attribute6
2987             ,attribute7 = p_act_budgets_rec.attribute7
2988             ,attribute8 = p_act_budgets_rec.attribute8
2989             ,attribute9 = p_act_budgets_rec.attribute9
2990             ,attribute10 = p_act_budgets_rec.attribute10
2991             ,attribute11 = p_act_budgets_rec.attribute11
2992             ,attribute12 = p_act_budgets_rec.attribute12
2993             ,attribute13 = p_act_budgets_rec.attribute13
2994             ,attribute14 = p_act_budgets_rec.attribute14
2995             ,attribute15 = p_act_budgets_rec.attribute15
2996             -- 11/16/2001 mpande
2997             ,approved_amount_fc = l_fc_amount
2998             -- 12/17/2001 mpande
2999             ,src_curr_request_amt = l_src_curr_request_amt
3000        WHERE activity_budget_id = l_act_budgets_rec.activity_budget_id
3001          AND object_version_number = l_act_budgets_rec.object_version_number;
3002 
3003       IF (SQL%NOTFOUND) THEN
3004          -- Error, check the msg level and added an error message to the
3005          -- API message list
3006          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
3007             fnd_message.set_name ('OZF', 'OZF_API_RECORD_NOT_FOUND');
3008             fnd_msg_pub.ADD;
3009          END IF;
3010 
3011          RAISE fnd_api.g_exc_unexpected_error;
3012       END IF;
3013 
3014       /*IF l_act_budgets_rec.transfer_type = 'UTILIZED'
3015       AND l_src_currency <> l_act_budgets_rec.request_currency THEN
3016          l_act_budgets_rec.request_amount := l_temp_request_amount;
3017          l_act_budgets_rec.approved_original_amount := l_temp_aprvd_orig_amount;
3018          l_act_budgets_rec.approved_amount := l_temp_approved_amount;
3019       END IF;*/
3020 
3021   ELSE
3022         --//Copied the following code from above to rectify Scan Data offer activation issue (+)
3023         IF l_act_budgets_rec.request_amount IS NULL OR l_act_budgets_rec.request_amount = FND_API.G_MISS_NUM THEN
3024                 l_act_budgets_rec.request_amount := 0;
3025         END IF;
3026         IF l_act_budgets_rec.approved_amount IS NULL OR l_act_budgets_rec.approved_amount = FND_API.G_MISS_NUM THEN
3027                 l_act_budgets_rec.approved_amount := 0;
3028         END IF;
3029         IF l_act_budgets_rec.approved_original_amount IS NULL OR l_act_budgets_rec.approved_original_amount = FND_API.G_MISS_NUM THEN
3030                 l_act_budgets_rec.approved_original_amount := 0;
3031         END IF;
3032         IF l_fc_amount IS NULL OR l_fc_amount = FND_API.G_MISS_NUM THEN
3033                 l_fc_amount := 0;
3034         END IF;
3035         IF l_act_budgets_rec.parent_src_apprvd_amt IS NULL OR l_act_budgets_rec.parent_src_apprvd_amt = FND_API.G_MISS_NUM THEN
3036                 l_act_budgets_rec.parent_src_apprvd_amt := 0;
3037         END IF;
3038         IF l_src_curr_request_amt IS NULL OR l_src_curr_request_amt = FND_API.G_MISS_NUM THEN
3039                 l_src_curr_request_amt := 0;
3040         END IF;
3041         --//rectify Scan Data offer activation issue (-)
3042 
3043 -- nepanda : Fix for 12911854
3044 if l_act_budgets_rec.approved_in_currency is not null then
3045       l_act_budgets_rec.src_curr_req_amt := ozf_utility_pvt.currround(l_src_curr_request_amt, l_act_budgets_rec.approved_in_currency);
3046 end if;
3047 
3048 if l_act_budgets_rec.request_currency is not null then
3049         l_act_budgets_rec.approved_amount := ozf_utility_pvt.currround(l_act_budgets_rec.approved_amount, l_act_budgets_rec.request_currency);
3050 end if;
3051 
3052 if l_act_budgets_rec.approved_in_currency is not null then
3053       l_act_budgets_rec.approved_original_amount := ozf_utility_pvt.currround(l_act_budgets_rec.approved_original_amount, l_act_budgets_rec.approved_in_currency);
3054 end if;
3055 
3056 if l_act_budgets_rec.parent_src_curr is not null then
3057       l_act_budgets_rec.parent_src_apprvd_amt := ozf_utility_pvt.currround(l_act_budgets_rec.parent_src_apprvd_amt, l_act_budgets_rec.parent_src_curr);
3058 end if;
3059 
3060 IF l_ledger_id IS NOT NULL THEN
3061         OPEN c_get_gl_info(l_ledger_id);
3062         FETCH c_get_gl_info INTO l_fc_currency_code;
3063         CLOSE c_get_gl_info;
3064         if l_fc_currency_code is not null then
3065            l_fc_amount := ozf_utility_pvt.currround(l_fc_amount, l_fc_currency_code);
3066         end if;
3067 END IF;
3068 
3069 IF l_fc_amount = l_act_budgets_rec.request_amount THEN
3070    if l_act_budgets_rec.request_currency is not null then
3071       l_fc_amount := ozf_utility_pvt.currround(l_act_budgets_rec.request_amount, l_act_budgets_rec.request_currency);
3072    end if;
3073 END IF;
3074 
3075 if l_act_budgets_rec.request_currency is not null then
3076       l_act_budgets_rec.request_amount := ozf_utility_pvt.currround(l_act_budgets_rec.request_amount, l_act_budgets_rec.request_currency);
3077 end if;
3078 
3079         l_request_id := fnd_global.conc_request_id;
3080         l_budget_count := 0;
3081         l_operation := 'INSERT';
3082 
3083         --13-DEC-2010 kdass - TPA Parallel Execution ER - 9614703
3084         IF px_ozf_act_budgets_tbl.COUNT > 0 THEN
3085            FOR i IN 1 .. px_ozf_act_budgets_tbl.COUNT
3086            LOOP
3087               IF l_act_budgets_rec.activity_budget_id = px_ozf_act_budgets_tbl(i).ACTIVITY_BUDGET_ID
3088                AND l_resale_batch_id = px_ozf_act_budgets_tbl(i).RESALE_BATCH_ID THEN
3089                  l_operation := 'UPDATE';
3090                  l_budget_count := i;
3091                  GOTO START_OPERATION;
3092               END IF;
3093            END LOOP;
3094         END IF;
3095 
3096         <<START_OPERATION>>
3097         IF l_operation = 'UPDATE' THEN
3098 
3099            px_ozf_act_budgets_tbl(l_budget_count).RESALE_BATCH_ID          := l_resale_batch_id;
3100            px_ozf_act_budgets_tbl(l_budget_count).ACTIVITY_BUDGET_ID       := l_act_budgets_rec.activity_budget_id;
3101            px_ozf_act_budgets_tbl(l_budget_count).REQUEST_AMOUNT           := NVL(px_ozf_act_budgets_tbl(l_budget_count).REQUEST_AMOUNT,0)
3102                                                                               + NVL(l_act_budgets_rec.request_amount,0)
3103                                                                               - NVL(l_old_act_budgets_rec.request_amount,0);
3104            px_ozf_act_budgets_tbl(l_budget_count).APPROVED_AMOUNT          := NVL(px_ozf_act_budgets_tbl(l_budget_count).APPROVED_AMOUNT,0)
3105                                                                               + NVL(l_act_budgets_rec.approved_amount,0)
3106                                                                               - NVL(l_old_act_budgets_rec.approved_amount,0);
3107            px_ozf_act_budgets_tbl(l_budget_count).APPROVED_ORIGINAL_AMOUNT := NVL(px_ozf_act_budgets_tbl(l_budget_count).APPROVED_ORIGINAL_AMOUNT,0)
3108                                                                               + NVL(l_act_budgets_rec.approved_original_amount,0)
3109                                                                               - NVL(l_old_act_budgets_rec.approved_original_amount,0);
3110            px_ozf_act_budgets_tbl(l_budget_count).APPROVED_AMOUNT_FC       := NVL(px_ozf_act_budgets_tbl(l_budget_count).APPROVED_AMOUNT_FC,0)
3111                                                                               + NVL(l_fc_amount,0)
3112                                                                               - NVL(l_old_act_budgets_rec.approved_amount_fc,0);
3113            px_ozf_act_budgets_tbl(l_budget_count).PARENT_SRC_APPRVD_AMT    := 0;
3114            px_ozf_act_budgets_tbl(l_budget_count).SRC_CURR_REQUEST_AMT     := NVL(px_ozf_act_budgets_tbl(l_budget_count).SRC_CURR_REQUEST_AMT,0)
3115                                                                               + NVL(l_src_curr_request_amt,0)
3116                                                                               - NVL(l_old_act_budgets_rec.src_curr_request_amt,0);
3117            px_ozf_act_budgets_tbl(l_budget_count).BATCH_TYPE               := p_batch_type;
3118            px_ozf_act_budgets_tbl(l_budget_count).REQUEST_ID               := l_req_id;
3119 
3120         ELSIF l_operation = 'INSERT' THEN
3121 
3122            l_budget_count := px_ozf_act_budgets_tbl.COUNT + 1;
3123            px_ozf_act_budgets_tbl(l_budget_count).RESALE_BATCH_ID          := l_resale_batch_id;
3124            px_ozf_act_budgets_tbl(l_budget_count).ACTIVITY_BUDGET_ID       := l_act_budgets_rec.activity_budget_id;
3125            px_ozf_act_budgets_tbl(l_budget_count).REQUEST_AMOUNT           := NVL(l_act_budgets_rec.request_amount,0) - NVL(l_old_act_budgets_rec.request_amount,0);
3126            px_ozf_act_budgets_tbl(l_budget_count).APPROVED_AMOUNT          := NVL(l_act_budgets_rec.approved_amount,0) - NVL(l_old_act_budgets_rec.approved_amount,0);
3127            px_ozf_act_budgets_tbl(l_budget_count).APPROVED_ORIGINAL_AMOUNT := NVL(l_act_budgets_rec.approved_original_amount,0) - NVL(l_old_act_budgets_rec.approved_original_amount,0);
3128            px_ozf_act_budgets_tbl(l_budget_count).APPROVED_AMOUNT_FC       := NVL(l_fc_amount,0) - NVL(l_old_act_budgets_rec.approved_amount_fc,0);
3129            px_ozf_act_budgets_tbl(l_budget_count).PARENT_SRC_APPRVD_AMT    := 0;
3130            px_ozf_act_budgets_tbl(l_budget_count).SRC_CURR_REQUEST_AMT     := NVL(l_src_curr_request_amt,0) - NVL(l_old_act_budgets_rec.src_curr_request_amt,0);
3131            px_ozf_act_budgets_tbl(l_budget_count).BATCH_TYPE               := p_batch_type;
3132            px_ozf_act_budgets_tbl(l_budget_count).REQUEST_ID               := l_req_id;
3133 
3134         END IF;
3135 
3136 
3137         -- For BUG#8867381(-)
3138 
3139   END IF; -- end of l_use_fund_staging_tables
3140 
3141       IF l_start_flow_flag = 'Y' THEN
3142 
3143          l_new_status_id :=
3144             ozf_utility_pvt.get_default_user_status('OZF_BUDGETSOURCE_STATUS', 'APPROVED');
3145          l_reject_status_id :=
3146             ozf_utility_pvt.get_default_user_status('OZF_BUDGETSOURCE_STATUS', 'REJECTED');
3147 
3148            ams_gen_approval_pvt.startprocess(
3149             p_activity_type =>  'FREQ'
3150            ,p_activity_id => l_act_budgets_rec.activity_budget_id
3151            ,p_approval_type => 'BUDGET'
3152            ,p_object_version_number => l_act_budgets_rec.object_version_number + 1
3153            ,p_orig_stat_id => l_act_budgets_rec.user_status_id
3154            ,p_new_stat_id => l_new_status_id
3155            ,p_reject_stat_id => l_reject_status_id
3156            ,p_requester_userid => l_act_budgets_rec.requester_id
3157            ,p_notes_from_requester => l_act_budgets_rec.justification
3158            ,p_workflowprocess => 'AMSGAPP'
3159            ,p_item_type => 'AMSGAPP'
3160            ,p_gen_process_flag => 'N');
3161 
3162 
3163       END IF;
3164 
3165       IF      l_act_budgets_rec.COMMENT IS NOT NULL
3166           AND l_act_budgets_rec.COMMENT <> fnd_api.g_miss_char THEN
3167          OZF_ACTBUDGETRULES_PVT.create_note (
3168             p_activity_type=> 'FREQ'
3169            ,p_activity_id=> l_act_budgets_rec.activity_budget_id
3170            ,p_note=> l_act_budgets_rec.COMMENT
3171            ,p_note_type=> 'AMS_COMMENT'
3172            ,p_user=> NVL (
3173                         l_act_budgets_rec.requester_id
3174                        ,ozf_utility_pvt.get_resource_id (fnd_global.user_id)
3175                      )
3176            ,x_msg_count=> x_msg_count
3177            ,x_msg_data=> x_msg_data
3178            ,x_return_status=> l_return_status
3179          );
3180 
3181          IF l_return_status <> fnd_api.g_ret_sts_success THEN
3182             RAISE fnd_api.g_exc_error;
3183          END IF;
3184       END IF;
3185 
3186       IF      l_act_budgets_rec.justification IS NOT NULL
3187           AND l_act_budgets_rec.justification <> fnd_api.g_miss_char THEN
3188          OZF_ACTBUDGETRULES_PVT.create_note (
3189             p_activity_type=> 'FREQ'
3190            ,p_activity_id=> l_act_budgets_rec.activity_budget_id
3191            ,p_note=> l_act_budgets_rec.justification
3192            ,p_note_type=> 'AMS_JUSTIFICATION'
3193            ,p_user=> NVL (
3194                         l_act_budgets_rec.requester_id
3195                        ,ozf_utility_pvt.get_resource_id (fnd_global.user_id)
3196                      )
3197            ,x_msg_count=> x_msg_count
3198            ,x_msg_data=> x_msg_data
3199            ,x_return_status=> l_return_status
3200          );
3201 
3202          IF l_return_status <> fnd_api.g_ret_sts_success THEN
3203             RAISE fnd_api.g_exc_error;
3204          END IF;
3205       END IF;
3206 
3207       -- 06/25/2001 mpande changed
3208       IF l_act_budgets_rec.status_code = 'APPROVED'
3209                                                     THEN
3210           -- the amount passes should be the  new utilization amount and not the
3211           -- whole amount
3212    /*       IF l_old_status_code = 'APPROVED' THEN
3213              l_act_budgets_rec.request_amount := l_act_budgets_rec.approved_amount -  l_old_approved_amount ;
3214              l_act_budgets_rec.approved_amount := l_act_budgets_rec.approved_amount -  l_old_approved_amount ;
3215              l_act_budgets_rec.parent_src_apprvd_amt := l_act_budgets_rec.parent_src_apprvd_amt ;
3216           END IF;
3217      */
3218          -- raise business event when approval request.
3219          raise_business_event(p_object_id => l_act_budgets_rec.activity_budget_id );
3220 
3221          -- added by feliu on 08/03/2005. only created utilization for UTILIZED.
3222          IF l_act_budgets_rec.transfer_type = 'UTILIZED' THEN
3223 
3224           -- the amount passes should be the  new utilization amount and not the
3225           -- whole amount
3226           IF l_old_status_code = 'APPROVED' THEN
3227              l_act_budgets_rec.request_amount := l_act_budgets_rec.approved_amount -  l_old_approved_amount ;
3228              l_act_budgets_rec.approved_amount := l_act_budgets_rec.approved_amount -  l_old_approved_amount ;
3229              l_act_budgets_rec.parent_src_apprvd_amt := l_act_budgets_rec.parent_src_apprvd_amt ;
3230           END IF;
3231            l_act_util_rec.plan_curr_amount := p_act_util_rec.plan_curr_amount;
3232            l_act_util_rec.plan_curr_amount_remaining := p_act_util_rec.plan_curr_amount_remaining;
3233            l_act_util_rec.plan_currency_code := p_act_util_rec.plan_currency_code;
3234         -- For Bug#8867381, introduced p_use_fund_staging_tables for staging table impln of chargeback flow
3235         -- and px_ozf_act_budgets_tbl for PLSQL table impln of storing budgets value.
3236         -- and px_ozf_funds_old_rectype for taking the funds old values
3237             -- For TPA Parallel Execution ER Bug#9614703
3238         -- and changed px_ozf_funds_new_rectype to px_ozf_funds_new_tbl.
3239 
3240 
3241            ozf_fund_adjustment_pvt.create_fund_utilization (
3242             p_act_budget_rec=> l_act_budgets_rec
3243            ,x_return_status=> l_return_status
3244            ,x_msg_count=> x_msg_count
3245            ,x_msg_data=> x_msg_data
3246            ,p_act_util_rec => l_act_util_rec
3247            ,x_utilized_amount => x_utilized_amount    -- yzhao: 06/21/2004 added to return actual utilized amount
3248            ,p_batch_type             =>    p_batch_type
3249            ,p_use_fund_staging_tables => p_use_fund_staging_tables
3250            ,px_ozf_act_budgets_tbl => px_ozf_act_budgets_tbl
3251            ,px_ozf_funds_old_rectype => px_ozf_funds_old_rectype
3252            ,px_ozf_funds_new_tbl => px_ozf_funds_new_tbl        -- For TPA Parallel Execution ER Bug#9614703
3253            ,x_utilization_id  => x_utilization_id  --nirprasa - added for Bug 9383565
3254            );
3255 
3256 
3257          IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
3258             RAISE fnd_api.g_exc_unexpected_error;
3259          ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
3260             RAISE fnd_api.g_exc_error;
3261          END IF;
3262        END IF; --l_act_budgets_rec.transfer_type = 'UTILIZED'
3263 
3264        IF (l_act_budgets_rec.budget_source_type ='CAMP' AND l_act_budgets_rec.arc_act_budget_used_by = 'CSCH') OR
3265          (l_act_budgets_rec.budget_source_type ='EVEH' AND l_act_budgets_rec.arc_act_budget_used_by = 'EVEO') OR
3266          (l_act_budgets_rec.budget_source_type ='CAMP' AND l_act_budgets_rec.arc_act_budget_used_by = 'OFFR') OR
3267          (l_act_budgets_rec.arc_act_budget_used_by ='CAMP' AND l_act_budgets_rec.budget_source_type = 'CSCH') OR
3268          (l_act_budgets_rec.arc_act_budget_used_by ='EVEH' AND l_act_budgets_rec.budget_source_type = 'EVEO') OR
3269          (l_act_budgets_rec.arc_act_budget_used_by ='CAMP' AND l_act_budgets_rec.budget_source_type = 'OFFR')  THEN
3270 
3271 
3272           create_child_act_budget (
3273                   x_return_status      => l_return_status,
3274                   x_msg_count          =>  x_msg_count,
3275                   x_msg_data           => x_msg_data,
3276                   p_act_budgets_rec    => l_act_budgets_rec,
3277                   p_exchange_rate_type => l_exchange_rate_type
3278             );
3279 
3280 
3281          IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
3282             RAISE fnd_api.g_exc_unexpected_error;
3283          ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
3284             RAISE fnd_api.g_exc_error;
3285          END IF;
3286 
3287       END IF;
3288 
3289 
3290       END IF;
3291 
3292       --
3293       -- Since "REJECTED" records do not count as a record
3294       -- for the cue card "tick", validate on update that
3295       -- only non-rejected records exist.
3296       -- 02/22/2001  mpande REmoved all object attribute calls from here
3297 
3298       IF      l_old_status_code = 'NEW'
3299           AND l_act_budgets_rec.status_code = 'APPROVED' THEN
3300          -- initiate WF approval and return; WF will
3301          -- call an API to update the relevent columns.
3302 
3303          -- check to see if commit is needed before returning
3304          IF fnd_api.to_boolean (p_commit) THEN
3305             COMMIT WORK;
3306          END IF;
3307 
3308          RETURN;
3309       END IF;
3310 
3311       -- added by feliu for offer validation.
3312       IF NVL(l_check_validation, 'NO') <> 'NO'
3313          AND l_act_budgets_rec.arc_act_budget_used_by = 'OFFR'
3314          AND l_act_budgets_rec.budget_source_type = 'FUND'
3315          AND l_act_budgets_rec.status_code = 'PENDING_VALIDATION' THEN
3316 
3317          OPEN c_offer_status(l_act_budgets_rec.act_budget_used_by_id);
3318          FETCH c_offer_status INTO l_offer_status;
3319          CLOSE c_offer_status;
3320 
3321          IF l_offer_status = 'ACTIVE' THEN
3322              l_request_id := fnd_request.submit_request (
3323                             application   => 'OZF',
3324                             program       => 'OZFVALIELIG',
3325                             start_time    => sysdate,
3326                             argument1     => l_act_budgets_rec.act_budget_used_by_id,
3327                             argument2     =>'OFFR',
3328                             argument3     =>l_act_budgets_rec.activity_budget_id
3329                          );
3330             COMMIT;
3331          END IF;
3332       END IF;
3333 
3334       -- END of API body.
3335       --
3336       -- Standard check of p_commit.
3337       IF fnd_api.to_boolean (p_commit) THEN
3338          COMMIT WORK;
3339       END IF;
3340 
3341       -- Standard call to get message count AND IF count is 1, get message info.
3342       fnd_msg_pub.count_and_get (
3343          p_count=> x_msg_count
3344         ,p_data=> x_msg_data
3345         ,p_encoded=> fnd_api.g_false
3346       );
3347    EXCEPTION
3348       WHEN fnd_api.g_exc_error THEN
3349          ROLLBACK TO update_act_budgets_pvt;
3350          x_return_status            := fnd_api.g_ret_sts_error;
3351          fnd_msg_pub.count_and_get (
3352             p_count=> x_msg_count
3353            ,p_data=> x_msg_data
3354            ,p_encoded=> fnd_api.g_false
3355          );
3356       WHEN fnd_api.g_exc_unexpected_error THEN
3357          ROLLBACK TO update_act_budgets_pvt;
3358          x_return_status            := fnd_api.g_ret_sts_unexp_error;
3359          fnd_msg_pub.count_and_get (
3360             p_count=> x_msg_count
3361            ,p_data=> x_msg_data
3362            ,p_encoded=> fnd_api.g_false
3363          );
3364       WHEN OTHERS THEN
3365          ROLLBACK TO update_act_budgets_pvt;
3366          x_return_status            := fnd_api.g_ret_sts_unexp_error;
3367 
3368          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error) THEN
3369             fnd_msg_pub.add_exc_msg (g_package_name, l_api_name);
3370          END IF;
3371 
3372          fnd_msg_pub.count_and_get (
3373             p_count=> x_msg_count
3374            ,p_data=> x_msg_data
3375            ,p_encoded=> fnd_api.g_false
3376          );
3377    END update_act_budgets;
3378 
3379 
3380 /*****************************************************************************************/
3381 -- Start of Comments
3382 --
3383 -- NAME
3384 --   Delete_Act_Budgets
3385 --
3386 -- PURPOSE
3387 --   This procedure is to delete a budget record that satisfy caller needs
3388 --
3389 -- HISTORY
3390 -- 04/12/2000  sugupta  CREATED
3391 -- 22-Feb-2001 mpande   Modified for Hornet changes.
3392 -- End of Comments
3393 /*****************************************************************************************/
3394    PROCEDURE delete_act_budgets (
3395       p_api_version        IN       NUMBER
3396      ,p_init_msg_list      IN       VARCHAR2 := fnd_api.g_false
3397      ,p_commit             IN       VARCHAR2 := fnd_api.g_false
3398      ,p_validation_level   IN       NUMBER := fnd_api.g_valid_level_full
3399      ,x_return_status      OUT NOCOPY      VARCHAR2
3400      ,x_msg_count          OUT NOCOPY      NUMBER
3401      ,x_msg_data           OUT NOCOPY      VARCHAR2
3402      ,p_act_budget_id      IN       NUMBER
3403      ,p_object_version     IN       NUMBER
3404    ) IS
3405       l_api_name        CONSTANT VARCHAR2 (30) := 'Delete_Act_Budgets';
3406       l_api_version     CONSTANT NUMBER        := 1.0;
3407       l_rejected_code   CONSTANT VARCHAR2 (30) := 'REJECTED';
3408       -- Status Local Variables
3409       l_return_status            VARCHAR2 (1); -- Return value from procedures
3410       l_act_budget_id            NUMBER        := p_act_budget_id;
3411       l_status_code              VARCHAR2 (30);
3412 
3413       CURSOR c_status (p_act_budget_id IN NUMBER) IS
3414          SELECT status_code
3415            FROM ozf_act_budgets
3416           WHERE activity_budget_id = p_act_budget_id;
3417    BEGIN
3418       -- Standard Start of API savepoint
3419       SAVEPOINT delete_act_budgets_pvt;
3420 
3421       -- Standard call to check for call compatibility.
3422       IF NOT fnd_api.compatible_api_call (l_api_version, p_api_version, l_api_name, g_package_name) THEN
3423          RAISE fnd_api.g_exc_unexpected_error;
3424       END IF;
3425 
3426       -- Initialize message list IF p_init_msg_list is set to TRUE.
3427       IF fnd_api.to_boolean (p_init_msg_list) THEN
3428          fnd_msg_pub.initialize;
3429       END IF;
3430 
3431       --  Initialize API return status to success
3432       x_return_status            := fnd_api.g_ret_sts_success;
3433       --
3434       -- API body
3435       --
3436 
3437       OPEN c_status (l_act_budget_id);
3438       FETCH c_status INTO l_status_code;
3439       CLOSE c_status;
3440 
3441       IF l_status_code NOT IN ('NEW') THEN
3442          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
3443             fnd_message.set_name ('OZF', 'OZF_ACT_BUDGET_NO_DELETE');
3444             fnd_msg_pub.ADD;
3445          END IF;
3446 
3447          RAISE fnd_api.g_exc_error;
3448       END IF;
3449 
3450       -- Perform the database operation
3451       -- Delete header data
3452       DELETE FROM ozf_act_budgets
3453             WHERE activity_budget_id = l_act_budget_id
3454               AND object_version_number = p_object_version;
3455 
3456       IF SQL%NOTFOUND THEN
3457          --
3458          -- Add error message to API message list.
3459          --
3460          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
3461             fnd_message.set_name ('OZF', 'OZF_API_RECORD_NOT_FOUND');
3462             fnd_msg_pub.ADD;
3463          END IF;
3464 
3465          RAISE fnd_api.g_exc_error;
3466       END IF;
3467 
3468       --
3469       -- END of API body.
3470       --
3471       -- Standard check of p_commit.
3472       IF fnd_api.to_boolean (p_commit) THEN
3473          COMMIT WORK;
3474       END IF;
3475 
3476       -- Standard call to get message count AND IF count is 1, get message info.
3477       fnd_msg_pub.count_and_get (
3478          p_count=> x_msg_count
3479         ,p_data=> x_msg_data
3480         ,p_encoded=> fnd_api.g_false
3481       );
3482    EXCEPTION
3483       WHEN fnd_api.g_exc_error THEN
3484          ROLLBACK TO delete_act_budgets_pvt;
3485          x_return_status            := fnd_api.g_ret_sts_error;
3486          fnd_msg_pub.count_and_get (
3487             p_count=> x_msg_count
3488            ,p_data=> x_msg_data
3489            ,p_encoded=> fnd_api.g_false
3490          );
3491       WHEN fnd_api.g_exc_unexpected_error THEN
3492          ROLLBACK TO delete_act_budgets_pvt;
3493          x_return_status            := fnd_api.g_ret_sts_unexp_error;
3494          fnd_msg_pub.count_and_get (
3495             p_count=> x_msg_count
3496            ,p_data=> x_msg_data
3497            ,p_encoded=> fnd_api.g_false
3498          );
3499       WHEN OTHERS THEN
3500          ROLLBACK TO delete_act_budgets_pvt;
3501          x_return_status            := fnd_api.g_ret_sts_unexp_error;
3502 
3503          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error) THEN
3504             fnd_msg_pub.add_exc_msg (g_package_name, l_api_name);
3505          END IF;
3506 
3507          fnd_msg_pub.count_and_get (
3508             p_count=> x_msg_count
3509            ,p_data=> x_msg_data
3510            ,p_encoded=> fnd_api.g_false
3511          );
3512    END delete_act_budgets;
3513 
3514 
3515 /*****************************************************************************************/
3516 -- Start of Comments
3517 --
3518 -- NAME
3519 --   Lock_Act_Budgets
3520 --
3521 -- PURPOSE
3522 --   This procedure is to lock a budget record that satisfy caller needs
3523 --
3524 -- HISTORY
3525 -- 04/12/2000  sugupta  CREATED
3526 -- End of Comments
3527 /*****************************************************************************************/
3528    PROCEDURE lock_act_budgets (
3529       p_api_version        IN       NUMBER
3530      ,p_init_msg_list      IN       VARCHAR2 := fnd_api.g_false
3531      ,p_validation_level   IN       NUMBER := fnd_api.g_valid_level_full
3532      ,x_return_status      OUT NOCOPY      VARCHAR2
3533      ,x_msg_count          OUT NOCOPY      NUMBER
3534      ,x_msg_data           OUT NOCOPY      VARCHAR2
3535      ,p_act_budget_id      IN       NUMBER
3536      ,p_object_version     IN       NUMBER
3537    ) IS
3538       l_api_name      CONSTANT VARCHAR2 (30) := 'Lock_Act_Budgets';
3539       l_api_version   CONSTANT NUMBER        := 1.0;
3540       -- Status Local Variables
3541       l_return_status          VARCHAR2 (1); -- Return value from procedures
3542       l_status_code            VARCHAR2 (30);
3543 
3544       CURSOR c_act_budget IS
3545          SELECT        status_code
3546                   FROM ozf_act_budgets
3547                  WHERE activity_budget_id = p_act_budget_id
3548                    AND object_version_number = p_object_version
3549          FOR UPDATE OF activity_budget_id NOWAIT;
3550    BEGIN
3551       -- Standard call to check for call compatibility.
3552       IF NOT fnd_api.compatible_api_call (l_api_version, p_api_version, l_api_name, g_package_name) THEN
3553          RAISE fnd_api.g_exc_unexpected_error;
3554       END IF;
3555 
3556       -- Initialize message list if p_init_msg_list is set to TRUE.
3557       IF fnd_api.to_boolean (p_init_msg_list) THEN
3558          fnd_msg_pub.initialize;
3559       END IF;
3560 
3561       --  Initialize API return status to success
3562       x_return_status            := fnd_api.g_ret_sts_success;
3563       --
3564       -- API body
3565       --
3566       -- Perform the database operation
3567       OPEN c_act_budget;
3568       FETCH c_act_budget INTO l_status_code;
3569 
3570       IF (c_act_budget%NOTFOUND) THEN
3571          CLOSE c_act_budget;
3572 
3573          -- Error, check the msg level and added an error message to the
3574          -- API message list
3575          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN -- MMSG
3576             fnd_message.set_name ('OZF', 'OZF_API_RECORD_NOT_FOUND');
3577             fnd_msg_pub.ADD;
3578          END IF;
3579 
3580          RAISE fnd_api.g_exc_error;
3581       END IF;
3582 
3583       CLOSE c_act_budget;
3584       --
3585       -- END of API body.
3586       --
3587       -- Standard call to get message count AND IF count is 1, get message info.
3588       fnd_msg_pub.count_and_get (
3589          p_count=> x_msg_count
3590         ,p_data=> x_msg_data
3591         ,p_encoded=> fnd_api.g_false
3592       );
3593    EXCEPTION
3594       WHEN fnd_api.g_exc_error THEN
3595          x_return_status            := fnd_api.g_ret_sts_error;
3596          fnd_msg_pub.count_and_get (
3597             p_count=> x_msg_count
3598            ,p_data=> x_msg_data
3599            ,p_encoded=> fnd_api.g_false
3600          );
3601       WHEN fnd_api.g_exc_unexpected_error THEN
3602          x_return_status            := fnd_api.g_ret_sts_unexp_error;
3603          fnd_msg_pub.count_and_get (
3604             p_count=> x_msg_count
3605            ,p_data=> x_msg_data
3606            ,p_encoded=> fnd_api.g_false
3607          );
3608       WHEN ozf_utility_pvt.resource_locked THEN
3609          x_return_status            := fnd_api.g_ret_sts_error;
3610 
3611          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
3612             fnd_message.set_name ('OZF', 'OZF_API_RESOURCE_LOCKED');
3613             fnd_msg_pub.ADD;
3614          END IF;
3615 
3616          fnd_msg_pub.count_and_get (
3617             p_count=> x_msg_count
3618            ,p_data=> x_msg_data
3619            ,p_encoded=> fnd_api.g_false
3620          );
3621       WHEN OTHERS THEN
3622          x_return_status            := fnd_api.g_ret_sts_unexp_error;
3623 
3624          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error) THEN
3625             fnd_msg_pub.add_exc_msg (g_package_name, l_api_name);
3626          END IF;
3627 
3628          fnd_msg_pub.count_and_get (
3629             p_count=> x_msg_count
3630            ,p_data=> x_msg_data
3631            ,p_encoded=> fnd_api.g_false
3632          );
3633    END lock_act_budgets;
3634 
3635 
3636 /*****************************************************************************************/
3637 -- Start of Comments
3638 --
3639 -- NAME
3640 --   Validate_Act_Budgets
3641 --
3642 -- PURPOSE
3643 --   This procedure is to validate an activity budget record
3644 --
3645 -- HISTORY
3646 -- 04/12/2000  sugupta  CREATED
3647 -- End of Comments
3648 /*****************************************************************************************/
3649    PROCEDURE validate_act_budgets (
3650       p_api_version        IN       NUMBER
3651      ,p_init_msg_list      IN       VARCHAR2 := fnd_api.g_false
3652      ,p_validation_level   IN       NUMBER := fnd_api.g_valid_level_full
3653      ,x_return_status      OUT NOCOPY      VARCHAR2
3654      ,x_msg_count          OUT NOCOPY      NUMBER
3655      ,x_msg_data           OUT NOCOPY      VARCHAR2
3656      ,p_act_budgets_rec    IN       act_budgets_rec_type
3657    ) IS
3658       l_api_name      CONSTANT VARCHAR2 (30)        := 'Validate_Act_Budgets';
3659       l_api_version   CONSTANT NUMBER               := 1.0;
3660       l_full_name     CONSTANT VARCHAR2 (60)        :=    g_package_name
3661                                                        || '.'
3662                                                        || l_api_name;
3663       -- Status Local Variables
3664       l_return_status          VARCHAR2 (1); -- Return value from procedures
3665       l_act_budgets_rec        act_budgets_rec_type := p_act_budgets_rec;
3666       l_act_budget_id          NUMBER;
3667    BEGIN
3668       -- Standard call to check for call compatibility.
3669       IF NOT fnd_api.compatible_api_call (l_api_version, p_api_version, l_api_name, g_package_name) THEN
3670          RAISE fnd_api.g_exc_unexpected_error;
3671       END IF;
3672 
3673       -- Initialize message list if p_init_msg_list is set to TRUE.
3674       IF fnd_api.to_boolean (p_init_msg_list) THEN
3675          fnd_msg_pub.initialize;
3676       END IF;
3677 
3678       --  Initialize API return status to success
3679       x_return_status            := fnd_api.g_ret_sts_success;
3680       --
3681       -- API body
3682       --
3683       IF G_DEBUG THEN
3684          ozf_utility_pvt.debug_message (   l_full_name
3685                                      || ': check items');
3686       END IF;
3687 
3688       IF p_validation_level >= jtf_plsql_api.g_valid_level_item THEN
3689          validate_act_budgets_items (
3690             p_act_budgets_rec=> l_act_budgets_rec
3691            ,p_validation_mode=> jtf_plsql_api.g_create
3692            ,x_return_status=> l_return_status
3693          );
3694 
3695          -- If any errors happen abort API.
3696          IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
3697             RAISE fnd_api.g_exc_unexpected_error;
3698          ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
3699             RAISE fnd_api.g_exc_error;
3700          END IF;
3701       END IF;
3702 
3703       -- Perform cross attribute validation and missing attribute checks. Record
3704       -- level validation.
3705       IF G_DEBUG THEN
3706          ozf_utility_pvt.debug_message (   l_full_name
3707                                      || ': check record level');
3708       END IF;
3709 
3710       IF p_validation_level >= jtf_plsql_api.g_valid_level_record THEN
3711          validate_act_budgets_record (
3712             p_act_budgets_rec=> l_act_budgets_rec
3713            ,p_validation_mode=> jtf_plsql_api.g_create
3714            ,x_return_status=> l_return_status
3715          );
3716 
3717          -- If any errors happen abort API.
3718          IF l_return_status = fnd_api.g_ret_sts_error THEN
3719             RAISE fnd_api.g_exc_error;
3720          ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
3721             RAISE fnd_api.g_exc_unexpected_error;
3722          END IF;
3723       END IF;
3724 
3725 
3726 --
3727 -- END of API body.
3728 --
3729 -------------------- finish --------------------------
3730       fnd_msg_pub.count_and_get (
3731          p_encoded=> fnd_api.g_false
3732         ,p_count=> x_msg_count
3733         ,p_data=> x_msg_data
3734       );
3735    EXCEPTION
3736       WHEN fnd_api.g_exc_error THEN
3737          x_return_status            := fnd_api.g_ret_sts_error;
3738          fnd_msg_pub.count_and_get (
3739             p_count=> x_msg_count
3740            ,p_data=> x_msg_data
3741            ,p_encoded=> fnd_api.g_false
3742          );
3743       WHEN fnd_api.g_exc_unexpected_error THEN
3744          x_return_status            := fnd_api.g_ret_sts_unexp_error;
3745          fnd_msg_pub.count_and_get (
3746             p_count=> x_msg_count
3747            ,p_data=> x_msg_data
3748            ,p_encoded=> fnd_api.g_false
3749          );
3750       WHEN OTHERS THEN
3751          x_return_status            := fnd_api.g_ret_sts_unexp_error;
3752 
3753          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error) THEN
3754             fnd_msg_pub.add_exc_msg (g_package_name, l_api_name);
3755          END IF;
3756 
3757          fnd_msg_pub.count_and_get (
3758             p_count=> x_msg_count
3759            ,p_data=> x_msg_data
3760            ,p_encoded=> fnd_api.g_false
3761          );
3762    END validate_act_budgets;
3763 
3764 
3765 /*****************************************************************************************/
3766 -- Start of Comments
3767 --
3768 -- NAME
3769 --   Validate_Act_Budgets_Items
3770 --
3771 -- PURPOSE
3772 --   This procedure is to validate busget items
3773 -- HISTORY
3774 -- 24-Aug-2000 choang   Changed ozf_fund_details_v to ozf_fund_details_v
3775 -- 22-Feb-2001 mpande   Modified for Hornet changes.
3776 -- End of Comments
3777 /*****************************************************************************************/
3778    PROCEDURE validate_act_budgets_items (
3779       p_act_budgets_rec   IN       act_budgets_rec_type
3780      ,p_validation_mode   IN       VARCHAR2 := jtf_plsql_api.g_create
3781      ,x_return_status     OUT NOCOPY      VARCHAR2
3782    ) IS
3783       l_table_name   VARCHAR2 (30);
3784       l_pk_name      VARCHAR2 (30);
3785       l_pk_value     VARCHAR2 (30);
3786    BEGIN
3787       --  Initialize API/Procedure return status to success
3788       x_return_status            := fnd_api.g_ret_sts_success;
3789 
3790       -- Check required parameters
3791       IF (   p_act_budgets_rec.act_budget_used_by_id = fnd_api.g_miss_num
3792           OR p_act_budgets_rec.act_budget_used_by_id IS NULL
3793          ) THEN
3794          -- missing required fields
3795          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
3796             fnd_message.set_name ('OZF', 'OZF_ACT_BUDG_NO_USEDBYID');
3797             fnd_msg_pub.ADD;
3798          END IF;
3799 
3800          x_return_status            := fnd_api.g_ret_sts_error;
3801          -- If any error happens abort API.
3802          RETURN;
3803       END IF;
3804 
3805       --- budget sourrce id
3806       IF (   p_act_budgets_rec.budget_source_id = fnd_api.g_miss_num
3807           OR p_act_budgets_rec.budget_source_id IS NULL
3808          ) THEN
3809          -- missing required fields
3810          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
3811             fnd_message.set_name ('OZF', 'OZF_ACT_BUDG_NO_SOURCEID');
3812             fnd_msg_pub.ADD;
3813          END IF;
3814 
3815          x_return_status            := fnd_api.g_ret_sts_error;
3816          -- If any error happens abort API.
3817          RETURN;
3818       END IF;
3819 
3820       -- budget source type
3821       IF (   p_act_budgets_rec.budget_source_type = fnd_api.g_miss_char
3822           OR p_act_budgets_rec.budget_source_type IS NULL
3823          ) THEN
3824          -- missing required fields
3825          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
3826             fnd_message.set_name ('OZF', 'OZF_ACT_BUDG_NO_SOURCETYPE');
3827             fnd_msg_pub.ADD;
3828          END IF;
3829 
3830          x_return_status            := fnd_api.g_ret_sts_error;
3831          -- If any error happens abort API.
3832          RETURN;
3833       END IF;
3834 
3835       -- transfer type
3836       IF (   p_act_budgets_rec.transfer_type = fnd_api.g_miss_char
3837           OR p_act_budgets_rec.transfer_type IS NULL
3838          ) THEN
3839          -- missing required fields
3840          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
3841             fnd_message.set_name ('OZF', 'OZF_ACT_BUDG_NO_TRANSYPE');
3842             fnd_msg_pub.ADD;
3843          END IF;
3844 
3845          x_return_status            := fnd_api.g_ret_sts_error;
3846          -- If any error happens abort API.
3847          RETURN;
3848       END IF;
3849 
3850       -- arc_act_budget_used_by
3851       IF (   p_act_budgets_rec.arc_act_budget_used_by = fnd_api.g_miss_char
3852           OR p_act_budgets_rec.arc_act_budget_used_by IS NULL
3853          ) THEN
3854          -- missing required fields
3855          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
3856             fnd_message.set_name ('OZF', 'OZF_ACT_BUDG_NO_USEDBY');
3857             fnd_msg_pub.ADD;
3858          END IF;
3859 
3860          x_return_status            := fnd_api.g_ret_sts_error;
3861          -- If any error happens abort API.
3862          RETURN;
3863       END IF;
3864 
3865       -- Validate the currency code.
3866       -- Currency code is set in the create API and it
3867       -- cannot be updated, so failure condition should
3868       -- only happen during create.
3869 
3870       IF (   p_act_budgets_rec.request_currency IS NULL
3871           OR p_act_budgets_rec.request_currency = fnd_api.g_miss_char
3872          ) THEN
3873          ozf_utility_pvt.error_message ('OZF_ACT_BUDG_NO_CURRENCY');
3874          x_return_status            := fnd_api.g_ret_sts_error;
3875          RETURN;
3876       END IF;
3877       --   Validate uniqueness
3878       IF      p_validation_mode = jtf_plsql_api.g_create
3879           AND p_act_budgets_rec.activity_budget_id IS NOT NULL THEN
3880          IF ozf_utility_pvt.check_uniqueness (
3881                'ozf_Act_budgets'
3882               ,   'ACTIVITY_BUDGET_ID = '
3883                || p_act_budgets_rec.activity_budget_id
3884             ) = fnd_api.g_false THEN
3885             IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
3886                fnd_message.set_name ('OZF', 'OZF_ACT_BUDG_DUPLICATE_ID');
3887                fnd_msg_pub.ADD;
3888             END IF;
3889 
3890             x_return_status            := fnd_api.g_ret_sts_error;
3891             RETURN;
3892          END IF;
3893       END IF;
3894 
3895       --
3896       --   check for lookups....arc_act_budget_used_by
3897       --   TO DO: check ozf object in ozf lookup OZF_SYS_ARC_QUALIFIER, ams object in ams lookup AMS_SYS_ARC_QUALIFIER
3898 
3899       IF p_act_budgets_rec.arc_act_budget_used_by <> fnd_api.g_miss_char THEN
3900          IF ams_utility_pvt.check_lookup_exists (
3901                p_lookup_type=> 'AMS_SYS_ARC_QUALIFIER'
3902               ,p_lookup_code=> p_act_budgets_rec.arc_act_budget_used_by
3903             ) = fnd_api.g_false THEN
3904             IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
3905                ozf_utility_pvt.debug_message ( 'Used By:'||p_act_budgets_rec.arc_act_budget_used_by);
3906                fnd_message.set_name ('OZF', 'OZF_ACT_BUDG_BAD_USEDBY');
3907                fnd_msg_pub.ADD;
3908             END IF;
3909 
3910             x_return_status            := fnd_api.g_ret_sts_error;
3911             RETURN;
3912          END IF;
3913       END IF;
3914 
3915       --
3916       --   check for lookups....BUDGET_SOURCE_TYPE
3917       --
3918       IF p_act_budgets_rec.budget_source_type <> fnd_api.g_miss_char THEN
3919          IF ozf_utility_pvt.check_lookup_exists (
3920                p_lookup_type=> 'OZF_FUND_SOURCE'
3921               ,p_lookup_code=> p_act_budgets_rec.budget_source_type
3922             ) = fnd_api.g_false THEN
3923             IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
3924                fnd_message.set_name ('OZF', 'OZF_ACT_BUDG_BAD_SRCTYPE');
3925                fnd_msg_pub.ADD;
3926             END IF;
3927 
3928             x_return_status            := fnd_api.g_ret_sts_error;
3929             RETURN;
3930          END IF;
3931       END IF;
3932 
3933       --
3934       -- Begin Validate Referential
3935       --
3936       -- Check FK parameter: act_budget_used_by_id #1
3937       IF p_act_budgets_rec.act_budget_used_by_id <> fnd_api.g_miss_num THEN
3938          IF p_act_budgets_rec.arc_act_budget_used_by = ('EVEH') THEN
3939             l_table_name               := 'AMS_EVENT_HEADERS_VL';
3940             l_pk_name                  := 'EVENT_HEADER_ID';
3941          ELSIF p_act_budgets_rec.arc_act_budget_used_by IN ( 'EVEO','EONE') THEN
3942             l_table_name               := 'AMS_EVENT_OFFERS_VL';
3943             l_pk_name                  := 'EVENT_OFFER_ID';
3944          ELSIF p_act_budgets_rec.arc_act_budget_used_by = 'CAMP' THEN
3945             l_table_name               := 'AMS_CAMPAIGNS_VL';
3946             l_pk_name                  := 'CAMPAIGN_ID';
3947          -- 02/23/2001 mpande ADDED for Hornet reqmt
3948          ELSIF p_act_budgets_rec.arc_act_budget_used_by = 'OFFR'
3949             OR p_act_budgets_rec.arc_act_budget_used_by = 'PRIC' THEN    -- yzhao: 10/20/2003 added for price list
3950             l_table_name               := 'QP_LIST_HEADERS_ALL_B';       -- Fix for bug # 14724414
3951             l_pk_name                  := 'LIST_HEADER_ID';
3952          ELSIF p_act_budgets_rec.arc_act_budget_used_by = 'WKST' THEN
3953             l_table_name               := 'OZF_WORKSHEET_HEADERS_VL';
3954             l_pk_name                  := 'WORKSHEET_HEADER_ID';
3955          ELSIF p_act_budgets_rec.arc_act_budget_used_by = 'USER' THEN
3956             l_table_name               := 'ams_jtf_rs_emp_v';
3957             l_pk_name                  := 'RESOURCE_ID';
3958          ELSIF p_act_budgets_rec.arc_act_budget_used_by = 'DELV' THEN
3959             -- choang - 05-sep-2000
3960             -- Fix for bug 1397577.
3961             l_table_name               := 'AMS_DELIVERABLES_VL';
3962             l_pk_name                  := 'DELIVERABLE_ID';
3963          ELSIF p_act_budgets_rec.arc_act_budget_used_by = 'CSCH' THEN
3964             l_table_name               := 'AMS_CAMPAIGN_SCHEDULES_VL';
3965             l_pk_name                  := 'SCHEDULE_ID';
3966          ELSIF p_act_budgets_rec.arc_act_budget_used_by = 'FUND' THEN
3967             l_table_name               := 'OZF_FUNDS_ALL_B';
3968             l_pk_name                  := 'FUND_ID';
3969          ELSIF p_act_budgets_rec.arc_act_budget_used_by = 'SOFT_FUND' THEN
3970             l_table_name               := 'OZF_REQUEST_HEADERS_ALL_B';
3971             l_pk_name                  := 'REQUEST_HEADER_ID';
3972          ELSIF p_act_budgets_rec.arc_act_budget_used_by = 'SPECIAL_PRICE' THEN
3973             l_table_name               := 'OZF_REQUEST_HEADERS_ALL_B';
3974             l_pk_name                  := 'REQUEST_HEADER_ID';
3975          END IF;
3976 
3977          l_pk_value                 := p_act_budgets_rec.act_budget_used_by_id;
3978 
3979          IF ozf_utility_pvt.check_fk_exists (
3980                p_table_name=> l_table_name
3981               ,p_pk_name=> l_pk_name
3982               ,p_pk_value=> l_pk_value
3983             ) = fnd_api.g_false THEN
3984             IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
3985                fnd_message.set_name ('OZF', 'OZF_ACT_BUDG_BAD_USEDBYID');
3986                fnd_msg_pub.ADD;
3987             END IF;
3988 
3989             x_return_status            := fnd_api.g_ret_sts_error;
3990             -- If any errors happen abort API/Procedure.
3991             RETURN;
3992          END IF; -- check_fk_exists
3993       END IF;
3994 
3995       -- Check FK parameter: BUDGET_SOURCE_ID #2
3996       -- Partner funds will not have a budget source ID
3997       IF      p_act_budgets_rec.budget_source_id <> fnd_api.g_miss_num
3998           AND p_act_budgets_rec.budget_source_id IS NOT NULL THEN
3999          IF p_act_budgets_rec.budget_source_type = 'EVEH' THEN
4000             l_table_name               := 'AMS_EVENT_HEADERS_VL';
4001             l_pk_name                  := 'EVENT_HEADER_ID';
4002          ELSIF p_act_budgets_rec.budget_source_type IN ('EONE', 'EVEO') THEN
4003             l_table_name               := 'AMS_EVENT_OFFERS_VL';
4004             l_pk_name                  := 'EVENT_OFFER_ID';
4005          ELSIF p_act_budgets_rec.budget_source_type = 'CAMP' THEN
4006             l_table_name               := 'AMS_CAMPAIGNS_VL';
4007             l_pk_name                  := 'CAMPAIGN_ID';
4008          ELSIF p_act_budgets_rec.budget_source_type = 'CSCH' THEN
4009             l_table_name               := 'AMS_CAMPAIGN_SCHEDULES_VL';
4010             l_pk_name                  := 'SCHEDULE_ID';
4011          ELSIF p_act_budgets_rec.budget_source_type = 'SOFT_FUND' THEN
4012             l_table_name               := 'OZF_REQUEST_HEADERS_ALL_B';
4013             l_pk_name                  := 'REQUEST_HEADER_ID';
4014          ELSIF p_act_budgets_rec.budget_source_type = 'SPECIAL_PRICE' THEN
4015             l_table_name               := 'OZF_REQUEST_HEADERS_ALL_B';
4016             l_pk_name                  := 'REQUEST_HEADER_ID';
4017          ELSIF p_act_budgets_rec.budget_source_type = 'FUND' THEN
4018             --  31-Jan-2001   mpande   Removed access from ozf_fund_details_V to ozf_funds_all_vl for cross organzation validation.
4019             --         l_table_name := 'AMS_FUND_DETAILS_V';
4020             l_table_name               := 'OZF_FUNDS_ALL_B';
4021             l_pk_name                  := 'FUND_ID';
4022          ELSIF p_act_budgets_rec.budget_source_type = 'PTNR' THEN
4023             l_table_name               := 'PV_PARTNERS_V';
4024             -- 09/05/2001 mpande changed as per partners new functioanlity
4025             l_pk_name                  := 'PARTNER_ID';
4026          ELSIF p_act_budgets_rec.budget_source_type = 'USER' THEN
4027             l_table_name               := 'ams_jtf_rs_emp_v';
4028             l_pk_name                  := 'RESOURCE_ID';
4029          /* 07/27/2001 yzhao ADDED for Hornet reqmt
4030             10/24/2003 yzhao ADDED for PRIC */
4031          ELSIF p_act_budgets_rec.budget_source_type = 'OFFR'
4032             OR p_act_budgets_rec.budget_source_type = 'PRIC' THEN
4033             l_table_name               := 'QP_LIST_HEADERS_ALL_B'; -- Fix for bug # 14724414
4034             l_pk_name                  := 'LIST_HEADER_ID';
4035          ELSIF p_act_budgets_rec.owner_id IS NOT NULL or
4036           p_act_budgets_rec.owner_id <> FND_API.g_miss_num THEN
4037             l_table_name               := 'ams_jtf_rs_emp_v';
4038             l_pk_name                  := 'RESOURCE_ID';
4039          -- 03/21/2002 mpande added because Deliverables reconciliation was not working properly
4040          ELSIF p_act_budgets_rec.budget_source_type = 'DELV' THEN
4041             l_table_name               := 'AMS_DELIVERABLES_VL';
4042             l_pk_name                  := 'DELIVERABLE_ID';
4043          END IF;
4044 
4045          l_pk_value                 := p_act_budgets_rec.budget_source_id;
4046 
4047          IF ozf_utility_pvt.check_fk_exists (
4048                p_table_name=> l_table_name
4049               ,p_pk_name=> l_pk_name
4050               ,p_pk_value=> l_pk_value
4051             ) = fnd_api.g_false THEN
4052             IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
4053                fnd_message.set_name ('OZF', 'OZF_ACT_BUDG_BAD_SRCID');
4054                fnd_msg_pub.ADD;
4055             END IF;
4056 
4057             x_return_status            := fnd_api.g_ret_sts_error;
4058             -- If any errors happen abort API/Procedure.
4059             RETURN;
4060          END IF; -- check_fk_exists
4061       END IF;
4062 
4063       /* R12: yzhao July 29, 2005 comment out check FK for approver_id and requester_id
4064               the check is not essential. These two ids are FYI only, and not referred any where
4065               in the past, several customers had issue with this checking.
4066               For example, if the original user who created UTILIZED record left the company,
4067                   following update on UTILIZED record failed with approver not exists error,
4068                   which does not make sense.
4069 
4070       -- Check FK parameter: approver_id
4071       IF p_act_budgets_rec.approver_id <> fnd_api.g_miss_num THEN
4072          l_table_name               := 'ams_jtf_rs_emp_v';
4073          l_pk_name                  := 'RESOURCE_ID';
4074          l_pk_value                 := p_act_budgets_rec.approver_id;
4075 
4076          IF ozf_utility_pvt.check_fk_exists (
4077                p_table_name=> l_table_name
4078               ,p_pk_name=> l_pk_name
4079               ,p_pk_value=> l_pk_value
4080             ) = fnd_api.g_false THEN
4081             IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
4082                fnd_message.set_name ('OZF', 'OZF_ACT_BUDG_BAD_APPRID');
4083                fnd_msg_pub.ADD;
4084             END IF;
4085 
4086             x_return_status            := fnd_api.g_ret_sts_error;
4087             -- If any errors happen abort API/Procedure.
4088             RETURN;
4089          END IF; -- check_fk_exists
4090       END IF;
4091 
4092       -- Check FK parameter: approver_id
4093       IF p_act_budgets_rec.requester_id <> fnd_api.g_miss_num THEN
4094          l_table_name               := 'ams_jtf_rs_emp_v';
4095          l_pk_name                  := 'RESOURCE_ID';
4096          l_pk_value                 := p_act_budgets_rec.requester_id;
4097 
4098          IF ozf_utility_pvt.check_fk_exists (
4099                p_table_name=> l_table_name
4100               ,p_pk_name=> l_pk_name
4101               ,p_pk_value=> l_pk_value
4102             ) = fnd_api.g_false THEN
4103             IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
4104                fnd_message.set_name ('OZF', 'OZF_ACT_BUDG_BAD_APPRID');
4105                fnd_msg_pub.ADD;
4106             END IF;
4107 
4108             x_return_status            := fnd_api.g_ret_sts_error;
4109             -- If any errors happen abort API/Procedure.
4110             RETURN;
4111          END IF; -- check_fk_exists
4112       END IF;
4113    -- Check FK parameter:uom
4114    -- include checks for UOM, CURRENCY, approver_id
4115    -- include checks that PO fields are not null for SRC TYPE of PARTNER
4116    */
4117 
4118    END validate_act_budgets_items;
4119 
4120 
4121 
4122 /*****************************************************************************************/
4123 -- Start of Comments
4124 --
4125 -- NAME
4126 --   Validate_Act_Budgets_Record
4127 --
4128 -- PURPOSE
4129 --   This procedure is to validate budget record
4130 --
4131 -- NOTES
4132 -- HISTORY
4133 -- 22-Aug-2000 choang   Added validation of credit request amounts.
4134 -- 23-Jan-2001 mpande   Added validation in validation_actbudget_rec  for not
4135 --    to submit for approval when the requested amount is 0.  BUG# 1604000
4136 -- 22-Feb-2001 mpande   Modified for Hornet changes.
4137 -- 08/05/2005  feliu    modified for R12.
4138 -- End of Comments
4139 /*****************************************************************************************/
4140    PROCEDURE validate_act_budgets_record (
4141       p_act_budgets_rec   IN       act_budgets_rec_type
4142      ,p_validation_mode   IN       VARCHAR2 := jtf_plsql_api.g_create
4143      ,x_return_status     OUT NOCOPY      VARCHAR2
4144    ) IS
4145       l_api_name      CONSTANT VARCHAR2 (30) := 'Validate_Act_Budgets_Record';
4146       l_api_version   CONSTANT NUMBER        := 1.0;
4147       -- Status Local Variables
4148       l_return_status          VARCHAR2 (1); -- Return value from procedures
4149       l_owner_currency         VARCHAR2 (15);
4150       -- flag indicating it is a fund to fund transfer.
4151       l_fund_transfer_flag     VARCHAR2 (1)  := fnd_api.g_false;
4152       l_check_amount           NUMBER := 0 ;
4153       l_old_approved_amount    NUMBER := 0 ;
4154       l_dummy                  VARCHAR2(3);
4155       l_exc_util_check         VARCHAR2(1):= 'F';
4156       CURSOR c_current_amount IS
4157          SELECT  approved_amount
4158            FROM ozf_act_budgets
4159           WHERE activity_budget_id = p_act_budgets_rec.activity_budget_id;
4160 
4161  -- Bug Fix 4030115.
4162  -- An offer not autogenerated from a budget should not be allow to make a negative request from a fully accrued budget.
4163 
4164      CURSOR c_fund_type (p_fund_id IN NUMBER , p_list_header_id IN NUMBER) IS
4165         SELECT 'X'
4166           FROM ozf_funds_all_b ozf
4167          WHERE  ozf.fund_type = 'FULLY_ACCRUED' and ozf.fund_id = p_fund_id
4168           and  ozf.plan_id = p_list_header_id;
4169 
4170      -- sangara - Bug - 4553660
4171      CURSOR c_get_offer_info(l_qp_list_header_id IN NUMBER) IS
4172         SELECT offer_type, org_id
4173         FROM ozf_offers
4174         WHERE qp_list_header_id = l_qp_list_header_id;
4175 
4176      l_offerType        VARCHAR2(30);
4177      l_offerOrgId         NUMBER;
4178      l_offerLedger        NUMBER;
4179      l_offerLedgerName VARCHAR2(30);
4180 
4181      CURSOR c_get_budget_ledger_id (p_fund_id IN NUMBER) IS
4182      SELECT NVL(ledger_id,0)
4183      FROM ozf_funds_all_b
4184      WHERE fund_id = p_fund_id;
4185 
4186      l_budgetLedger     NUMBER;
4187      -- sangara - Bug - 4553660 -- changes end
4188 
4189 
4190    BEGIN
4191       -- Standard call to check for call compatibility.
4192       IF NOT fnd_api.compatible_api_call (l_api_version, l_api_version, l_api_name, g_package_name) THEN
4193          RAISE fnd_api.g_exc_unexpected_error;
4194       END IF;
4195 
4196       --  Initialize API return status to success
4197       x_return_status            := fnd_api.g_ret_sts_success;
4198 
4199       --
4200       -- API body
4201       /****************** commented by mpande 02/10/2001 only for INternal rollout*************
4202       /****************** changed by mpande**********************
4203       ---budget  requested amount should always be positive be it credit or debit transaction --
4204          IF  NVL(p_act_budgets_rec.request_amount,0) <= 0 THEN
4205             OZF_Utility_PVT.error_message ('OZF_ACT_BUDG_NEG_REQUEST');
4206             x_return_status := FND_API.g_ret_sts_error;
4207          END IF;
4208       ********************************************************************************************/
4209 
4210       -- 22-Feb-2001 mpande
4211       --budget  requested amount should always be positive be it credit or debit transaction --
4212       -- this is not true for fully accrued budgets 08/16/2001
4213       -- -- Bug Fix 4030115.
4214       /*
4215       IF p_act_budgets_rec.budget_source_type = 'FUND' AND
4216           p_act_budgets_rec.arc_act_budget_used_by = 'OFFR' THEN
4217         OPEN c_fund_type( p_act_budgets_rec.budget_source_id, p_act_budgets_rec.act_budget_used_by_id) ;
4218         FETCH c_fund_type INTO l_dummy;
4219         CLOSE c_fund_type;
4220        END IF;
4221 */
4222   --    IF l_dummy IS NULL THEN
4223       -- 02/20/2002 added by mpande for negative utilization
4224       -- allow to create budget request with zero amount, not negative amount.
4225       -- fixed by feliu on 02/02/2006.
4226          IF p_act_budgets_rec.transfer_type <> 'UTILIZED' THEN
4227             IF NVL (p_act_budgets_rec.request_amount, 0) <0 THEN
4228                ozf_utility_pvt.error_message ('OZF_ACT_BUDG_NEG_REQUEST');
4229                x_return_status            := fnd_api.g_ret_sts_error;
4230             END IF;
4231          END IF;
4232     --  END IF;
4233 
4234       -- 22-Feb-2001 mpande
4235       --budget  spent amount cannot be greateer than the approved amount
4236       /* 03/01/2002 mpande commented this is not there any more
4237       IF NVL (p_act_budgets_rec.spent_amount, 0) > NVL (p_act_budgets_rec.approved_amount, 0) THEN
4238          ozf_utility_pvt.error_message ('OZF_ACT_BUDG_EXCESS_SPENT');
4239          x_return_status            := fnd_api.g_ret_sts_error;
4240       END IF;
4241       */
4242 
4243       -- 04/10/2001 mpande Hornet changes
4244       IF      p_act_budgets_rec.arc_act_budget_used_by = 'FUND'
4245           AND p_act_budgets_rec.budget_source_type = 'FUND' THEN
4246          l_fund_transfer_flag       := fnd_api.g_true;
4247       END IF;
4248 
4249       IF l_fund_transfer_flag = fnd_api.g_false THEN
4250             -- only utilized records could be updated. transfer, request cannot be updated
4251             IF p_validation_mode   = jtf_plsql_api.g_update THEN
4252              OPEN c_current_amount;
4253              FETCH c_current_amount INTO l_old_approved_amount;
4254 
4255              IF c_current_amount%NOTFOUND THEN
4256                 CLOSE c_current_amount;
4257                 ozf_utility_pvt.error_message ('OZF_API_RECORD_NOT_FOUND');
4258                 RAISE fnd_api.g_exc_unexpected_error;
4259              END IF;
4260 
4261              CLOSE c_current_amount;
4262             END IF;
4263 
4264 
4265             /* sangara - Bug - 4553660 - OFFER ACCURAL NOT IMPORTING TO GL.
4266              For non order-related offers(lumpsum, scan data), we should validate budget and offer's SOB (R12 - legder) at the time of budget request.
4267 
4268              For order-related offers, since offer is global and can be applied to orders from any org, we can not validate at budget request creation.
4269              We need to document that we only support budget utilization within single SOB setup. In case order is from a different SOB than
4270              budget's, Funds Accrual Engine gives warning.
4271             */
4272             IF  p_act_budgets_rec.arc_act_budget_used_by = 'OFFR' AND
4273                 p_act_budgets_rec.budget_source_type = 'FUND' THEN
4274 
4275                  OPEN c_get_offer_info(p_act_budgets_rec.act_budget_used_by_id);
4276                  FETCH c_get_offer_info INTO l_offerType, l_offerOrgId;
4277                  CLOSE c_get_offer_info;
4278 
4279                  IF l_offerType IN ('LUMPSUM', 'SCAN_DATA' ) THEN
4280 
4281                        -- Get the set_of_books_id for given org_id
4282                        MO_UTILS.Get_Ledger_Info (
4283                          p_operating_unit     =>  l_offerOrgId,
4284                          p_ledger_id          =>  l_offerLedger,
4285                          p_ledger_name        =>  l_offerLedgerName
4286                        );
4287 
4288                       OPEN c_get_budget_ledger_id (p_act_budgets_rec.budget_source_id);
4289                       FETCH c_get_budget_ledger_id INTO l_budgetLedger;
4290                       CLOSE c_get_budget_ledger_id;
4291 
4292                      IF NVL(l_budgetLedger, 0) <> 0 AND NVL(l_budgetLedger, 0) <> l_offerLedger THEN
4293                             ozf_utility_pvt.error_message ('OZF_BUDGET_OFFR_LEDG_MISMATCH');
4294                             x_return_status := fnd_api.g_ret_sts_error;
4295                             RAISE fnd_api.g_exc_error;
4296                      END IF;
4297 
4298                  END IF;
4299               END IF;
4300             -- sangara changes end
4301 
4302             --IF p_act_budgets_rec.status_code = 'APPROVED' THEN
4303             IF p_act_budgets_rec.transfer_type = 'UTILIZED' THEN
4304                l_check_amount             := p_act_budgets_rec.approved_amount - l_old_approved_amount;
4305             ELSE
4306                l_check_amount             := p_act_budgets_rec.src_curr_req_amt;
4307                -- For TRANSFER, it is the amount in budget source.
4308             END IF;
4309 
4310                 -- 6/11/2002 mpande fully accrued budget would have no committment
4311             --    l_dummy := NULL;
4312 
4313    /*
4314            IF p_act_budgets_rec.transfer_type = 'UTILIZED' THEN
4315                OPEN c_fund_type( p_act_budgets_rec.parent_source_id, p_list_header_id IN NUMBER) IS
4316                FETCH c_fund_type INTO l_dummy;
4317                CLOSE c_fund_type;
4318             END IF;
4319    */
4320             -- 10/23/2002 #2636800 commented by mpande for performance for utilized we donot wannt to check it
4321             -- mpande changed the transfer amount check clause.
4322             IF p_act_budgets_rec.transfer_type = 'TRANSFER' THEN
4323                IF (p_act_budgets_rec.arc_act_budget_used_by ='CAMP' AND p_act_budgets_rec.budget_source_type = 'CSCH') OR
4324                   (p_act_budgets_rec.arc_act_budget_used_by ='EVEH' AND p_act_budgets_rec.budget_source_type = 'EVEO') OR
4325                   (p_act_budgets_rec.arc_act_budget_used_by ='CAMP' AND p_act_budgets_rec.budget_source_type = 'OFFR')  THEN
4326                   l_exc_util_check := 'F' ;
4327                ELSE
4328                   l_exc_util_check := 'T' ;
4329                END IF;
4330             ELSIF p_act_budgets_rec.transfer_type = 'UTILIZED'  THEN
4331                 /*
4332                   For utilization from accrual, it is handled in accrual engine.
4333                   The utilization here is for marketing object, offer adjustment, third party accrual,
4334                   and Chargeback.
4335                   The recal-committed is only for all offers except ('LUMPSUM', 'TERMS','SCAN_DATA')
4336                 */
4337                IF g_recal_flag = 'N' AND p_act_budgets_rec.arc_act_budget_used_by = 'OFFR' THEN
4338                  l_exc_util_check := 'T'; -- for offer without recal_committed.
4339                ELSIF p_act_budgets_rec.arc_act_budget_used_by IN ('CAMP','CSCH','EVEH','EONE','EVEO','DELV') THEN
4340                    l_exc_util_check := 'T' ; -- check for marketing object.
4341                --ELSE
4342                  -- l_exc_util_check := 'F' ; -- for p_object_type IN ('PTNR','PRIC','WKST') and offer with recal_committed.
4343                END IF;
4344            -- ELSE
4345              --   l_exc_util_check := 'F' ; -- for REQUEST, do not check.
4346              END IF;
4347 
4348             IF l_exc_util_check = 'T' THEN
4349 
4350               OZF_ACTBUDGETRULES_PVT.check_transfer_amount_exists (
4351                p_act_budgets_rec.budget_source_id-- for 'TRANSFER', it is object id.
4352               ,p_act_budgets_rec.budget_source_type -- for 'TRANSFER', it is object type.
4353               ,p_act_budgets_rec.act_budget_used_by_id
4354               ,p_act_budgets_rec.arc_act_budget_used_by
4355               ,l_check_amount
4356               ,p_act_budgets_rec.transfer_type
4357               ,l_return_status
4358               );
4359             END IF;
4360 
4361             IF l_return_status <> fnd_api.g_ret_sts_success THEN
4362                x_return_status            := fnd_api.g_ret_sts_error;
4363             END IF;
4364          -- donot check for utilized and transfer records -- they are not souring 08/09/2001 mpande
4365          --  Request amount can not more than estimated amount when object is DRAFT status.
4366          -- don't validate for child records from sourcing from parent.
4367          IF p_act_budgets_rec.transfer_type = 'REQUEST' AND p_act_budgets_rec.parent_act_budget_id is NULL
4368          AND p_act_budgets_rec.arc_act_budget_used_by IN ('OFFR','CAMP','CSCH','EVEH','EONE','EVEO','DELV') THEN
4369             IF OZF_ACTBUDGETRULES_PVT.can_plan_more_budget (
4370                p_object_type=> p_act_budgets_rec.arc_act_budget_used_by
4371               ,p_object_id=> p_act_budgets_rec.act_budget_used_by_id
4372               ,p_request_amount=> p_act_budgets_rec.request_amount
4373               ,p_act_budget_id=> p_act_budgets_rec.activity_budget_id
4374             ) = fnd_api.g_false THEN
4375             ozf_utility_pvt.error_message ( 'OZF_ACT_BUDG_EXC_OBJ_AMT');
4376             x_return_status            := fnd_api.g_ret_sts_error;
4377             END IF;
4378          END IF ;
4379 
4380          --- we will match activity and category for others also later
4381          --- 02/20/2002 mpande added the validation for offers also
4382   /*       IF      p_act_budgets_rec.arc_act_budget_used_by IN ('CSCH','OFFR')
4383              AND p_act_budgets_rec.budget_source_type = 'FUND' THEN
4384             OZF_ACTBUDGETRULES_PVT.check_cat_activity_match (
4385                p_act_budgets_rec.act_budget_used_by_id
4386               ,p_act_budgets_rec.arc_act_budget_used_by
4387               ,p_act_budgets_rec.budget_source_id
4388               ,l_return_status
4389             );
4390 
4391             IF l_return_status <> fnd_api.g_ret_sts_success THEN
4392                x_return_status            := fnd_api.g_ret_sts_error;
4393             END IF;
4394          END IF; */
4395          -- 10/30/2001 mpande commented prod and market validation
4396          -- as per Leela.
4397          /*
4398          IF p_act_budgets_rec.budget_source_type = 'FUND' THEN
4399             OZF_ACTBUDGETRULES_PVT.check_market_elig_match (
4400                p_act_budgets_rec.act_budget_used_by_id
4401               ,p_act_budgets_rec.arc_act_budget_used_by
4402               ,p_act_budgets_rec.budget_source_id
4403               ,l_return_status
4404             );
4405 
4406             IF l_return_status <> fnd_api.g_ret_sts_success THEN
4407                x_return_status            := fnd_api.g_ret_sts_error;
4408             ELSE
4409                /* yzhao: 07/20/2001  check product eligibility
4410                OZF_ACTBUDGETRULES_PVT.check_prod_elig_match (
4411                  p_act_budgets_rec.act_budget_used_by_id,
4412                  p_act_budgets_rec.arc_act_budget_used_by,
4413                  p_act_budgets_rec.budget_source_id,
4414                  l_return_status
4415                );
4416 
4417                IF l_return_status <> fnd_api.g_ret_sts_success THEN
4418                   x_return_status            := fnd_api.g_ret_sts_error;
4419                END IF;
4420             END IF;
4421          END IF;
4422          */
4423 
4424       END IF;
4425 
4426       -- Check that transfer cannot be from and to the same source if it s not utlized record for the object
4427       IF p_act_budgets_rec.transfer_type NOT IN ('UTILIZED', 'RELEASE', 'RESERVE') THEN
4428          IF p_act_budgets_rec.arc_act_budget_used_by = p_act_budgets_rec.budget_source_type THEN
4429             IF p_act_budgets_rec.act_budget_used_by_id = p_act_budgets_rec.budget_source_id THEN
4430                ozf_utility_pvt.error_message ('OZF_FROM_TO_TRANSFER_SAME');
4431                x_return_status            := fnd_api.g_ret_sts_error;
4432             END IF;
4433          END IF;
4434       END IF;
4435    -- put in checks for date: required by date cannot be less than sysdate
4436 
4437      IF p_act_budgets_rec.date_required_by IS NOT NULL
4438          AND p_act_budgets_rec.date_required_by <> FND_API.G_MISS_DATE THEN
4439        IF p_act_budgets_rec.date_required_by < TRUNC(SYSDATE)  THEN
4440         Fnd_Message.SET_NAME('OZF','OZF_ACT_REQDBYDATE_LT_SYSDATE');
4441         Fnd_Msg_Pub.ADD;
4442         RAISE FND_API.G_EXC_ERROR;
4443        END IF;
4444       END IF;
4445 
4446    --
4447    -- END of API body.
4448    --
4449    END validate_act_budgets_record;
4450 
4451 /*****************************************************************************************/
4452 -- Start of Comments
4453 --
4454 -- NAME
4455 --   complete_act_budgets_rec
4456 --
4457 -- PURPOSE
4458 --   This procedure is to complete budget record
4459 --
4460 -- NOTES
4461 -- HISTORY
4462 -- End of Comments
4463 /*****************************************************************************************/
4464    PROCEDURE complete_act_budgets_rec (
4465       p_act_budgets_rec   IN       act_budgets_rec_type
4466      ,x_act_budgets_rec   OUT NOCOPY      act_budgets_rec_type
4467    ) IS
4468       CURSOR c_budget IS
4469          SELECT *
4470            FROM ozf_act_budgets
4471           WHERE activity_budget_id = p_act_budgets_rec.activity_budget_id;
4472 
4473       l_act_budgets_rec   c_budget%ROWTYPE;
4474    BEGIN
4475       x_act_budgets_rec          := p_act_budgets_rec;
4476       OPEN c_budget;
4477       FETCH c_budget INTO l_act_budgets_rec;
4478 
4479       IF c_budget%NOTFOUND THEN
4480          CLOSE c_budget;
4481 
4482          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
4483             fnd_message.set_name ('OZF', 'OZF_API_RECORD_NOT_FOUND');
4484             fnd_msg_pub.ADD;
4485          END IF;
4486 
4487          RAISE fnd_api.g_exc_error;
4488       END IF;
4489 
4490       CLOSE c_budget;
4491 
4492       --
4493       -- Usually, object_version_number is required from API calls,
4494       -- but this exception is made because approvals and rejections
4495       -- do not have to be synced to the screen record.  The same
4496       -- may apply for account closing.
4497       IF p_act_budgets_rec.object_version_number = fnd_api.g_miss_num THEN
4498          x_act_budgets_rec.object_version_number := NULL;
4499       END IF;
4500       IF p_act_budgets_rec.object_version_number IS NULL THEN
4501          x_act_budgets_rec.object_version_number := l_act_budgets_rec.object_version_number;
4502       END IF;
4503 
4504       IF p_act_budgets_rec.act_budget_used_by_id = fnd_api.g_miss_num THEN
4505          x_act_budgets_rec.act_budget_used_by_id := NULL;
4506       END IF;
4507       IF p_act_budgets_rec.act_budget_used_by_id IS NULL THEN
4508          x_act_budgets_rec.act_budget_used_by_id := l_act_budgets_rec.act_budget_used_by_id;
4509       END IF;
4510 
4511       IF p_act_budgets_rec.arc_act_budget_used_by = fnd_api.g_miss_char THEN
4512          x_act_budgets_rec.arc_act_budget_used_by := NULL;
4513       END IF;
4514       IF p_act_budgets_rec.arc_act_budget_used_by IS NULL THEN
4515          x_act_budgets_rec.arc_act_budget_used_by := l_act_budgets_rec.arc_act_budget_used_by;
4516       END IF;
4517 
4518       IF p_act_budgets_rec.budget_source_type = fnd_api.g_miss_char THEN
4519          x_act_budgets_rec.budget_source_type := NULL;
4520       END IF;
4521       IF p_act_budgets_rec.budget_source_type IS NULL THEN
4522          x_act_budgets_rec.budget_source_type := l_act_budgets_rec.budget_source_type;
4523       END IF;
4524 
4525       IF p_act_budgets_rec.budget_source_id = fnd_api.g_miss_num THEN
4526          x_act_budgets_rec.budget_source_id := NULL;
4527       END IF;
4528       IF p_act_budgets_rec.budget_source_id IS NULL THEN
4529          x_act_budgets_rec.budget_source_id := l_act_budgets_rec.budget_source_id;
4530       END IF;
4531 
4532       IF p_act_budgets_rec.transaction_type = fnd_api.g_miss_char THEN
4533          x_act_budgets_rec.transaction_type := NULL;
4534       END IF;
4535       IF p_act_budgets_rec.transaction_type IS NULL THEN
4536          x_act_budgets_rec.transaction_type := l_act_budgets_rec.transaction_type;
4537       END IF;
4538 
4539       IF p_act_budgets_rec.request_amount = fnd_api.g_miss_num THEN
4540          x_act_budgets_rec.request_amount := NULL;
4541       END IF;
4542       IF p_act_budgets_rec.request_amount IS NULL THEN
4543          x_act_budgets_rec.request_amount := l_act_budgets_rec.request_amount;
4544       END IF;
4545 
4546       IF p_act_budgets_rec.request_currency = fnd_api.g_miss_char THEN
4547          x_act_budgets_rec.request_currency := NULL;
4548       END IF;
4549       IF p_act_budgets_rec.request_currency IS NULL THEN
4550          x_act_budgets_rec.request_currency := l_act_budgets_rec.request_currency;
4551       END IF;
4552 
4553       IF p_act_budgets_rec.request_date = fnd_api.g_miss_date THEN
4554          x_act_budgets_rec.request_date := NULL;
4555       END IF;
4556       IF p_act_budgets_rec.request_date IS NULL THEN
4557          x_act_budgets_rec.request_date := l_act_budgets_rec.request_date;
4558       END IF;
4559 
4560       IF p_act_budgets_rec.status_code = fnd_api.g_miss_char THEN
4561          x_act_budgets_rec.status_code := NULL;
4562       END IF;
4563       IF p_act_budgets_rec.status_code IS NULL THEN
4564          x_act_budgets_rec.status_code := l_act_budgets_rec.status_code;
4565       END IF;
4566 
4567       IF p_act_budgets_rec.approved_amount = fnd_api.g_miss_num THEN
4568          x_act_budgets_rec.approved_amount := NULL;
4569       END IF;
4570       IF p_act_budgets_rec.approved_amount IS NULL THEN
4571          x_act_budgets_rec.approved_amount := l_act_budgets_rec.approved_amount;
4572       END IF;
4573 
4574       IF p_act_budgets_rec.approved_original_amount = fnd_api.g_miss_num THEN
4575          x_act_budgets_rec.approved_original_amount := NULL;
4576       END IF;
4577       IF p_act_budgets_rec.approved_original_amount IS NULL THEN
4578          x_act_budgets_rec.approved_original_amount := l_act_budgets_rec.approved_original_amount;
4579       END IF;
4580 
4581       IF p_act_budgets_rec.approved_in_currency = fnd_api.g_miss_char THEN
4582          x_act_budgets_rec.approved_in_currency := NULL;
4583       END IF;
4584       IF p_act_budgets_rec.approved_in_currency IS NULL THEN
4585          x_act_budgets_rec.approved_in_currency := l_act_budgets_rec.approved_in_currency;
4586       END IF;
4587 
4588       IF p_act_budgets_rec.approval_date = fnd_api.g_miss_date THEN
4589          x_act_budgets_rec.approval_date := NULL;
4590       END IF;
4591       IF p_act_budgets_rec.approval_date IS NULL THEN
4592          x_act_budgets_rec.approval_date := l_act_budgets_rec.approval_date;
4593       END IF;
4594 
4595       IF p_act_budgets_rec.approver_id = fnd_api.g_miss_num THEN
4596          x_act_budgets_rec.approver_id := NULL;
4597       END IF;
4598       IF p_act_budgets_rec.approver_id IS NULL THEN
4599          x_act_budgets_rec.approver_id := l_act_budgets_rec.approver_id;
4600       END IF;
4601 
4602       IF p_act_budgets_rec.spent_amount = fnd_api.g_miss_num THEN
4603          x_act_budgets_rec.spent_amount := NULL;
4604       END IF;
4605       IF p_act_budgets_rec.spent_amount IS NULL THEN
4606          x_act_budgets_rec.spent_amount := l_act_budgets_rec.spent_amount;
4607       END IF;
4608 
4609       IF p_act_budgets_rec.partner_po_number = fnd_api.g_miss_char THEN
4610          x_act_budgets_rec.partner_po_number := NULL;
4611       END IF;
4612       IF p_act_budgets_rec.partner_po_number IS NULL THEN
4613          x_act_budgets_rec.partner_po_number := l_act_budgets_rec.partner_po_number;
4614       END IF;
4615 
4616       IF p_act_budgets_rec.partner_po_date = fnd_api.g_miss_date THEN
4617          x_act_budgets_rec.partner_po_date := NULL;
4618       END IF;
4619       IF p_act_budgets_rec.partner_po_date IS NULL THEN
4620          x_act_budgets_rec.partner_po_date := l_act_budgets_rec.partner_po_date;
4621       END IF;
4622 
4623       IF p_act_budgets_rec.partner_po_approver = fnd_api.g_miss_char THEN
4624          x_act_budgets_rec.partner_po_approver := NULL;
4625       END IF;
4626       IF p_act_budgets_rec.partner_po_approver IS NULL THEN
4627          x_act_budgets_rec.partner_po_approver := l_act_budgets_rec.partner_po_approver;
4628       END IF;
4629 
4630       IF p_act_budgets_rec.posted_flag = fnd_api.g_miss_char THEN
4631          x_act_budgets_rec.posted_flag := NULL;
4632       END IF;
4633       IF p_act_budgets_rec.posted_flag IS NULL THEN
4634          x_act_budgets_rec.posted_flag := l_act_budgets_rec.posted_flag;
4635       END IF;
4636 
4637       IF p_act_budgets_rec.adjusted_flag = fnd_api.g_miss_char THEN
4638          x_act_budgets_rec.adjusted_flag := NULL;
4639       END IF;
4640       IF p_act_budgets_rec.adjusted_flag IS NULL THEN
4641          x_act_budgets_rec.adjusted_flag := l_act_budgets_rec.adjusted_flag;
4642       END IF;
4643 
4644       IF p_act_budgets_rec.transfer_type = fnd_api.g_miss_char THEN
4645          x_act_budgets_rec.transfer_type := NULL;
4646       END IF;
4647       IF p_act_budgets_rec.transfer_type IS NULL THEN
4648          x_act_budgets_rec.transfer_type := l_act_budgets_rec.transfer_type;
4649       END IF;
4650 
4651       IF p_act_budgets_rec.reason_code = fnd_api.g_miss_char THEN
4652          x_act_budgets_rec.reason_code := NULL;
4653       END IF;
4654       IF p_act_budgets_rec.reason_code IS NULL THEN
4655          x_act_budgets_rec.reason_code := l_act_budgets_rec.reason_code;
4656       END IF;
4657 
4658       IF p_act_budgets_rec.requester_id = fnd_api.g_miss_num THEN
4659          x_act_budgets_rec.requester_id := NULL;
4660       END IF;
4661       IF p_act_budgets_rec.requester_id IS NULL THEN
4662          x_act_budgets_rec.requester_id := l_act_budgets_rec.requester_id;
4663       END IF;
4664 
4665       IF p_act_budgets_rec.date_required_by = fnd_api.g_miss_date THEN
4666          x_act_budgets_rec.date_required_by := NULL;
4667       END IF;
4668       IF p_act_budgets_rec.date_required_by IS NULL THEN
4669          x_act_budgets_rec.date_required_by := l_act_budgets_rec.date_required_by;
4670       END IF;
4671 
4672       IF p_act_budgets_rec.contact_id = fnd_api.g_miss_num THEN
4673          x_act_budgets_rec.contact_id := NULL;
4674       END IF;
4675       IF p_act_budgets_rec.contact_id IS NULL THEN
4676          x_act_budgets_rec.contact_id := l_act_budgets_rec.contact_id;
4677       END IF;
4678 
4679       IF p_act_budgets_rec.parent_act_budget_id = fnd_api.g_miss_num THEN
4680          x_act_budgets_rec.parent_act_budget_id := NULL;
4681       END IF;
4682       IF p_act_budgets_rec.parent_act_budget_id IS NULL THEN
4683          x_act_budgets_rec.parent_act_budget_id := l_act_budgets_rec.parent_act_budget_id;
4684       END IF;
4685 
4686       --kdass 24-JUN-2005 fix for bug 4440342, set parent_source_id to null so that the API get_parent_src is called
4687       /*
4688 
4689       IF p_act_budgets_rec.parent_source_id = fnd_api.g_miss_num THEN
4690          x_act_budgets_rec.parent_source_id := NULL;
4691       END IF;
4692       IF p_act_budgets_rec.parent_source_id IS NULL THEN
4693          x_act_budgets_rec.parent_source_id := l_act_budgets_rec.parent_source_id;
4694       END IF;
4695       */
4696 
4697       IF p_act_budgets_rec.src_curr_req_amt = fnd_api.g_miss_num THEN
4698          x_act_budgets_rec.src_curr_req_amt := NULL;
4699       END IF;
4700       IF p_act_budgets_rec.src_curr_req_amt IS NULL THEN
4701          x_act_budgets_rec.src_curr_req_amt := l_act_budgets_rec.src_curr_request_amt;
4702       END IF;
4703 
4704 
4705       IF p_act_budgets_rec.partner_holding_type = fnd_api.g_miss_char THEN
4706          x_act_budgets_rec.partner_holding_type := NULL;
4707       END IF;
4708       IF p_act_budgets_rec.partner_holding_type IS NULL THEN
4709          x_act_budgets_rec.partner_holding_type := l_act_budgets_rec.partner_holding_type;
4710       END IF;
4711 
4712       IF p_act_budgets_rec.partner_address_id = fnd_api.g_miss_num THEN
4713          x_act_budgets_rec.partner_address_id := NULL;
4714       END IF;
4715       IF p_act_budgets_rec.partner_address_id IS NULL THEN
4716          x_act_budgets_rec.partner_address_id := l_act_budgets_rec.partner_address_id;
4717       END IF;
4718 
4719       IF p_act_budgets_rec.vendor_id = fnd_api.g_miss_num THEN
4720          x_act_budgets_rec.vendor_id := NULL;
4721       END IF;
4722       IF p_act_budgets_rec.vendor_id IS NULL THEN
4723          x_act_budgets_rec.vendor_id := l_act_budgets_rec.vendor_id;
4724       END IF;
4725 
4726       IF p_act_budgets_rec.owner_id = fnd_api.g_miss_num THEN
4727          x_act_budgets_rec.owner_id := NULL;
4728       END IF;
4729       IF p_act_budgets_rec.owner_id IS NULL THEN
4730          x_act_budgets_rec.owner_id := l_act_budgets_rec.owner_id;
4731       END IF;
4732 
4733       IF p_act_budgets_rec.recal_flag = fnd_api.g_miss_char THEN
4734          x_act_budgets_rec.recal_flag := NULL;
4735       END IF;
4736       IF p_act_budgets_rec.recal_flag IS NULL THEN
4737          x_act_budgets_rec.recal_flag := l_act_budgets_rec.recal_flag;
4738       END IF;
4739 
4740       IF p_act_budgets_rec.attribute_category = fnd_api.g_miss_char THEN
4741          x_act_budgets_rec.attribute_category := NULL;
4742       END IF;
4743       IF p_act_budgets_rec.attribute_category IS NULL THEN
4744          x_act_budgets_rec.attribute_category := l_act_budgets_rec.attribute_category;
4745       END IF;
4746 
4747       IF p_act_budgets_rec.attribute1 = fnd_api.g_miss_char THEN
4748          x_act_budgets_rec.attribute1 := NULL;
4749       END IF;
4750       IF p_act_budgets_rec.attribute1 IS NULL THEN
4751          x_act_budgets_rec.attribute1 := l_act_budgets_rec.attribute1;
4752       END IF;
4753 
4754       IF p_act_budgets_rec.attribute2 = fnd_api.g_miss_char THEN
4755          x_act_budgets_rec.attribute2 := NULL;
4756       END IF;
4757       IF p_act_budgets_rec.attribute2 IS NULL THEN
4758          x_act_budgets_rec.attribute2 := l_act_budgets_rec.attribute2;
4759       END IF;
4760 
4761       IF p_act_budgets_rec.attribute3 = fnd_api.g_miss_char THEN
4762          x_act_budgets_rec.attribute3 := NULL;
4763       END IF;
4764       IF p_act_budgets_rec.attribute3 IS NULL THEN
4765          x_act_budgets_rec.attribute3 := l_act_budgets_rec.attribute3;
4766       END IF;
4767 
4768       IF p_act_budgets_rec.attribute4 = fnd_api.g_miss_char THEN
4769          x_act_budgets_rec.attribute4 := NULL;
4770       END IF;
4771       IF p_act_budgets_rec.attribute4 IS NULL THEN
4772          x_act_budgets_rec.attribute4 := l_act_budgets_rec.attribute4;
4773       END IF;
4774 
4775       IF p_act_budgets_rec.attribute5 = fnd_api.g_miss_char THEN
4776          x_act_budgets_rec.attribute5 := NULL;
4777       END IF;
4778       IF p_act_budgets_rec.attribute5 IS NULL THEN
4779          x_act_budgets_rec.attribute5 := l_act_budgets_rec.attribute5;
4780       END IF;
4781 
4782       IF p_act_budgets_rec.attribute6 = fnd_api.g_miss_char THEN
4783          x_act_budgets_rec.attribute6 := NULL;
4784       END IF;
4785       IF p_act_budgets_rec.attribute6 IS NULL THEN
4786          x_act_budgets_rec.attribute6 := l_act_budgets_rec.attribute6;
4787       END IF;
4788 
4789       IF p_act_budgets_rec.attribute7 = fnd_api.g_miss_char THEN
4790          x_act_budgets_rec.attribute7 := NULL;
4791       END IF;
4792       IF p_act_budgets_rec.attribute7 IS NULL THEN
4793          x_act_budgets_rec.attribute7 := l_act_budgets_rec.attribute7;
4794       END IF;
4795 
4796       IF p_act_budgets_rec.attribute8 = fnd_api.g_miss_char THEN
4797          x_act_budgets_rec.attribute8 := NULL;
4798       END IF;
4799       IF p_act_budgets_rec.attribute8 IS NULL THEN
4800          x_act_budgets_rec.attribute8 := l_act_budgets_rec.attribute8;
4801       END IF;
4802 
4803       IF p_act_budgets_rec.attribute9 = fnd_api.g_miss_char THEN
4804          x_act_budgets_rec.attribute9 := NULL;
4805       END IF;
4806       IF p_act_budgets_rec.attribute9 IS NULL THEN
4807          x_act_budgets_rec.attribute9 := l_act_budgets_rec.attribute9;
4808       END IF;
4809 
4810       IF p_act_budgets_rec.attribute10 = fnd_api.g_miss_char THEN
4811          x_act_budgets_rec.attribute10 := NULL;
4812       END IF;
4813       IF p_act_budgets_rec.attribute10 IS NULL THEN
4814          x_act_budgets_rec.attribute10 := l_act_budgets_rec.attribute10;
4815       END IF;
4816 
4817       IF p_act_budgets_rec.attribute11 = fnd_api.g_miss_char THEN
4818          x_act_budgets_rec.attribute11 := NULL;
4819       END IF;
4820       IF p_act_budgets_rec.attribute11 IS NULL THEN
4821          x_act_budgets_rec.attribute11 := l_act_budgets_rec.attribute11;
4822       END IF;
4823 
4824       IF p_act_budgets_rec.attribute12 = fnd_api.g_miss_char THEN
4825          x_act_budgets_rec.attribute12 := NULL;
4826       END IF;
4827       IF p_act_budgets_rec.attribute12 IS NULL THEN
4828          x_act_budgets_rec.attribute12 := l_act_budgets_rec.attribute12;
4829       END IF;
4830 
4831       IF p_act_budgets_rec.attribute13 = fnd_api.g_miss_char THEN
4832          x_act_budgets_rec.attribute13 := NULL;
4833       END IF;
4834       IF p_act_budgets_rec.attribute13 IS NULL THEN
4835          x_act_budgets_rec.attribute13 := l_act_budgets_rec.attribute13;
4836       END IF;
4837 
4838       IF p_act_budgets_rec.attribute14 = fnd_api.g_miss_char THEN
4839          x_act_budgets_rec.attribute14 := NULL;
4840       END IF;
4841       IF p_act_budgets_rec.attribute14 IS NULL THEN
4842          x_act_budgets_rec.attribute14 := l_act_budgets_rec.attribute14;
4843       END IF;
4844 
4845       IF p_act_budgets_rec.attribute15 = fnd_api.g_miss_char THEN
4846          x_act_budgets_rec.attribute15 := NULL;
4847       END IF;
4848       IF p_act_budgets_rec.attribute15 IS NULL THEN
4849          x_act_budgets_rec.attribute15 := l_act_budgets_rec.attribute15;
4850       END IF;
4851       --added by feliu since 11.5.9
4852  /*     IF p_act_budgets_rec.user_status_id = fnd_api.g_miss_num THEN
4853          x_act_budgets_rec.user_status_id := l_act_budgets_rec.user_status_id;
4854       END IF;
4855 */
4856       IF p_act_budgets_rec.parent_src_curr = fnd_api.g_miss_char THEN
4857          x_act_budgets_rec.parent_src_curr := NULL;
4858       END IF;
4859       IF p_act_budgets_rec.parent_src_curr IS NULL THEN
4860          x_act_budgets_rec.parent_src_curr := l_act_budgets_rec.parent_src_curr;
4861       END IF;
4862 
4863       IF p_act_budgets_rec.parent_src_apprvd_amt = fnd_api.g_miss_num THEN
4864          x_act_budgets_rec.parent_src_apprvd_amt := NULL;
4865       END IF;
4866       IF p_act_budgets_rec.parent_src_apprvd_amt IS NULL THEN
4867          x_act_budgets_rec.parent_src_apprvd_amt := l_act_budgets_rec.parent_src_apprvd_amt;
4868       END IF;
4869 
4870 
4871    END complete_act_budgets_rec;
4872 
4873 
4874 /*****************************************************************************************/
4875 -- Start of Comments
4876 --
4877 -- NAME
4878 --    Init_Act_Budgets_Rec
4879 -- PURPOSE
4880 --    Initialize all column values to FND_API.g_miss_char/num/date
4881 -- HISTORY
4882 -- 15-Aug-2000 choang   Created.
4883 -- 22-Feb-2001 mpande   Modified for Hornet changes.
4884 /*****************************************************************************************/
4885    PROCEDURE init_act_budgets_rec (x_act_budgets_rec OUT NOCOPY act_budgets_rec_type) IS
4886    BEGIN
4887       RETURN;
4888    END init_act_budgets_rec;
4889 
4890 /*****************************************************************************************/
4891 -- Start of Comments
4892    --
4893    -- NAME
4894    --    trigger_approval_process
4895    -- PURPOSE
4896    --    Handle Workflow approval request processing.
4897    -- HISTORY
4898    -- 12-Sep-2000 choang   Created.
4899    --  03/23/2001 mpande   Added code for fund transfer
4900    --  05/23/2001 mpande   changed the default falg
4901    -- 08/27/2002  FELIU    added offer validation.
4902 /*****************************************************************************************/
4903    PROCEDURE trigger_approval_process (
4904       p_act_budget_rec         IN       act_budgets_rec_type
4905      ,x_act_budget_rec         IN OUT NOCOPY   act_budgets_rec_type
4906      ,x_return_status          OUT NOCOPY      VARCHAR2
4907      ,x_msg_count              OUT NOCOPY      NUMBER
4908      ,x_msg_data               OUT NOCOPY      VARCHAR2
4909      ,p_parent_process_flag    IN       VARCHAR2
4910      ,p_parent_process_key     IN       VARCHAR2
4911      ,p_parent_context         IN       VARCHAR2
4912      ,p_parent_approval_flag   IN       VARCHAR2
4913      ,p_continue_flow          IN       VARCHAR2
4914      ,p_child_approval_flag    IN       VARCHAR2 := fnd_api.g_false -- -- added 05/22/2001 mpande
4915      ,p_requestor_owner_flag   IN       VARCHAR2 := 'N' -- -- added 10/19/2001 mpande
4916      ,x_start_flow_flag        OUT NOCOPY     VARCHAR2
4917   ) IS
4918       l_budget_status_type   CONSTANT VARCHAR2 (30) := 'OZF_BUDGETSOURCE_STATUS';
4919       l_return_status                 VARCHAR2 (1);
4920       l_approved_in_currency          VARCHAR2 (15);
4921       l_approved_amount               NUMBER;
4922       l_orig_status                   NUMBER;
4923       l_new_status                    NUMBER;
4924       l_reject_status                 NUMBER;
4925       l_request_id                    NUMBER;
4926       l_approver_id                   NUMBER;
4927       l_is_requestor_owner            VARCHAR2 (2)  ; -- changed 09/07/2001 mpande
4928       l_allocation_flag               VARCHAR2 (2)  ; -- changed 09/07/2001 mpande
4929       l_approval_for_id               NUMBER;
4930       l_approval_fm_id                NUMBER;
4931       l_check_validation   VARCHAR2(50) := fnd_profile.value('OZF_CHECK_MKTG_PROD_ELIG');
4932       l_act_budget_rec        act_budgets_rec_type := x_act_budget_rec ;
4933       l_temp_act_rec          act_budgets_rec_type;
4934       l_start_flow_flag               VARCHAR2(1) := 'N';
4935       l_custom_setup_id      NUMBER;
4936 
4937       CURSOR c_user_status_id (p_status_code IN VARCHAR2) IS
4938          SELECT user_status_id
4939            FROM ams_user_statuses_vl
4940           WHERE system_status_type = l_budget_status_type
4941             AND system_status_code = p_status_code
4942             AND default_flag = 'Y'; -- this should be yes and not 'N'
4943       -- 09/07/2001 mpande added
4944       CURSOR c_source_fund_owner(
4945          p_source_fund_id   NUMBER)
4946       IS
4947          SELECT   owner
4948          FROM     ozf_funds_all_b
4949          WHERE  fund_id = p_source_fund_id;
4950 
4951       CURSOR c_offer_info(p_object_id IN NUMBER) IS
4952         SELECT custom_setup_id
4953         FROM ozf_offers
4954         WHERE qp_list_header_id = p_object_id;
4955 
4956    BEGIN
4957       -- fund to fund approval
4958       IF      p_act_budget_rec.arc_act_budget_used_by = 'FUND'
4959           AND p_act_budget_rec.budget_source_type = 'FUND' THEN
4960             l_approval_for_id          := p_act_budget_rec.act_budget_used_by_id;
4961             l_approval_fm_id           := p_act_budget_rec.budget_source_id;
4962 
4963          -- submit for budget approval
4964          IF p_child_approval_flag = fnd_api.g_false THEN
4965             -- yzhao: 03/14/2003 when p_requestor_owner_flag=Y, it is from allocation, should bypass workflow approval
4966             l_allocation_flag := p_requestor_owner_flag;
4967             ozf_fund_request_apr_pvt.create_fund_request (
4968                p_commit=> fnd_api.g_false
4969               ,p_approval_for_id=> l_approval_for_id
4970               ,p_requester_id=> p_act_budget_rec.requester_id
4971               ,p_requested_amount=> p_act_budget_rec.request_amount
4972               ,p_approval_fm=> 'FUND'
4973               ,p_approval_fm_id=> l_approval_fm_id
4974               ,p_transfer_type=> p_act_budget_rec.transfer_type
4975               ,p_child_flag=> 'N'
4976               ,p_allocation_flag => l_allocation_flag    -- yzhao: 03/14/2003 11.5.9 for allocation activation of budget hierarchy, always pass as 'Y'; all others 'N'
4977               ,p_act_budget_id=> p_act_budget_rec.activity_budget_id
4978               ,p_justification=> p_act_budget_rec.justification
4979               ,x_return_status=> l_return_status
4980               ,x_msg_count=> x_msg_count
4981               ,x_msg_data=> x_msg_data
4982               ,x_request_id=> l_request_id
4983               ,x_approver_id=> l_approver_id
4984               ,x_is_requester_owner=> l_is_requestor_owner
4985             );
4986             --used to start process.
4987             IF l_is_requestor_owner ='N' THEN
4988                l_start_flow_flag := 'Y';
4989             END IF;
4990 
4991             IF l_return_status = fnd_api.g_ret_sts_error THEN
4992                RAISE fnd_api.g_exc_error;
4993             ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
4994                RAISE fnd_api.g_exc_unexpected_error;
4995             END IF;
4996 
4997          ELSE
4998          -- 10/22/2001   mpande    Changed code different owner allocation bug
4999          l_is_requestor_owner := p_requestor_owner_flag;
5000          END IF;
5001 
5002 
5003          IF l_is_requestor_owner = 'Y' THEN
5004             l_approved_in_currency     := get_object_currency (
5005                                              p_act_budget_rec.budget_source_type
5006                                             ,p_act_budget_rec.budget_source_id
5007                                             ,l_return_status
5008                                           );
5009 
5010             IF l_return_status = fnd_api.g_ret_sts_error THEN
5011                RAISE fnd_api.g_exc_error;
5012             ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5013                RAISE fnd_api.g_exc_unexpected_error;
5014             END IF;
5015 
5016             IF l_approved_in_currency <> p_act_budget_rec.request_currency THEN
5017                ozf_utility_pvt.convert_currency (
5018                   x_return_status=> l_return_status
5019                  ,p_from_currency=> p_act_budget_rec.request_currency
5020                  ,p_to_currency=> l_approved_in_currency
5021                  ,p_from_amount=> p_act_budget_rec.request_amount
5022                  ,x_to_amount=> l_approved_amount
5023                );
5024 
5025                IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5026                   RAISE fnd_api.g_exc_unexpected_error;
5027                ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
5028                   RAISE fnd_api.g_exc_error;
5029                END IF;
5030             ELSE
5031                l_approved_amount          := p_act_budget_rec.request_amount;
5032             END IF;
5033 
5034             l_act_budget_rec.approved_amount := p_act_budget_rec.request_amount;
5035             l_act_budget_rec.approved_in_currency := l_approved_in_currency;
5036             l_act_budget_rec.approved_original_amount := l_approved_amount;
5037             l_act_budget_rec.approver_id := p_act_budget_rec.requester_id ;
5038             l_act_budget_rec.status_code := 'APPROVED';
5039             complete_act_budgets_rec (l_act_budget_rec, x_act_budget_rec);
5040          END IF;
5041       ELSIF p_act_budget_rec.budget_source_type = 'PTNR' THEN       -- Partner funds are automatically approved
5042             l_act_budget_rec.approved_amount := p_act_budget_rec.request_amount;
5043             l_act_budget_rec.approved_original_amount := p_act_budget_rec.request_amount;
5044             l_act_budget_rec.approved_in_currency := p_act_budget_rec.request_currency;
5045             l_act_budget_rec.status_code := 'APPROVED';
5046             complete_act_budgets_rec (l_act_budget_rec, x_act_budget_rec);
5047       ELSE -- object's budget approval
5048          -- If approval is required, indicated by the existense of the
5049          -- attribute_avaliable_flag of BAPL, then initiate the Workflow process
5050          -- with the call to ams_approval_pvt.start_lineapproval, otherwise,
5051          -- the approved amount is equal to the requested amount.
5052          IF OZF_ACTBUDGETRULES_PVT.check_approval_required (
5053                p_act_budget_rec.arc_act_budget_used_by
5054               ,p_act_budget_rec.act_budget_used_by_id
5055               ,p_act_budget_rec.budget_source_type
5056               ,p_act_budget_rec.budget_source_id
5057               ,p_act_budget_rec.transfer_type
5058             ) = fnd_api.g_true THEN
5059 
5060             --
5061             -- For performance considerations, consolidate the three
5062             -- cursor open and fetches into one by using DECODE on
5063             -- status_code in the select and IN in the WHERE.
5064             OPEN c_user_status_id ('NEW');
5065             FETCH c_user_status_id INTO l_orig_status;
5066             CLOSE c_user_status_id;
5067             OPEN c_user_status_id (p_act_budget_rec.status_code); -- this status_code should be approved
5068             FETCH c_user_status_id INTO l_new_status;
5069             CLOSE c_user_status_id;
5070             OPEN c_user_status_id ('REJECTED');
5071             FETCH c_user_status_id INTO l_reject_status;
5072             CLOSE c_user_status_id;
5073             ams_approval_pvt.start_lineapproval (
5074                p_api_version=> 1.0
5075               ,p_init_msg_list=> fnd_api.g_false
5076               ,p_commit=> fnd_api.g_false
5077               ,p_validation_level=> fnd_api.g_valid_level_full
5078               ,x_return_status=> l_return_status
5079               ,x_msg_data=> x_msg_data
5080               ,x_msg_count=> x_msg_count
5081               ,p_user_id=> ozf_utility_pvt.get_resource_id (fnd_global.user_id)
5082               ,p_act_budget_id=> p_act_budget_rec.activity_budget_id
5083               ,p_orig_status_id=> l_orig_status
5084               ,p_new_status_id=> l_new_status
5085               ,p_rejected_status_id=> l_reject_status
5086               ,p_parent_process_flag=> p_parent_process_flag
5087               ,p_parent_process_key=> p_parent_process_key
5088               ,p_parent_context=> p_parent_context
5089               ,p_parent_approval_flag=> p_parent_approval_flag
5090               ,p_continue_flow=> p_continue_flow
5091             );
5092 
5093             IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5094                RAISE fnd_api.g_exc_unexpected_error;
5095             ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
5096                RAISE fnd_api.g_exc_error;
5097             END IF;
5098          ELSE
5099 
5100             l_approved_in_currency     := get_object_currency (
5101                                              p_act_budget_rec.budget_source_type
5102                                             ,p_act_budget_rec.budget_source_id
5103                                             ,l_return_status
5104                                           );
5105 
5106             IF l_return_status = fnd_api.g_ret_sts_error THEN
5107                RAISE fnd_api.g_exc_error;
5108             ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5109                RAISE fnd_api.g_exc_unexpected_error;
5110             END IF;
5111 
5112             IF l_approved_in_currency <> p_act_budget_rec.request_currency THEN
5113                ozf_utility_pvt.convert_currency (
5114                   x_return_status=> l_return_status
5115                  ,p_from_currency=> p_act_budget_rec.request_currency
5116                  ,p_to_currency=> l_approved_in_currency
5117                  ,p_from_amount=> p_act_budget_rec.request_amount
5118                  ,x_to_amount=> l_approved_amount
5119                );
5120 
5121                IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5122                   RAISE fnd_api.g_exc_unexpected_error;
5123                ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
5124                   RAISE fnd_api.g_exc_error;
5125                END IF;
5126             ELSE
5127                l_approved_amount          := p_act_budget_rec.request_amount;
5128             END IF;
5129        /*     l_act_budget_rec.approved_amount := p_act_budget_rec.request_amount;
5130             l_act_budget_rec.approved_in_currency := l_approved_in_currency;
5131             l_act_budget_rec.approved_original_amount := l_approved_amount;
5132             l_act_budget_rec.approver_id := x_act_budget_rec.requester_id;
5133             l_act_budget_rec.comment := p_act_budget_rec.comment;
5134             l_act_budget_rec.status_code := 'APPROVED';
5135          */   complete_act_budgets_rec (l_act_budget_rec, l_temp_act_rec);
5136          -- added by feliu on 05/05/04 for special pricing and softfund.
5137        IF  l_temp_act_rec.arc_act_budget_used_by = 'OFFR' THEN
5138           OPEN c_offer_info(l_temp_act_rec.act_budget_used_by_id);
5139           FETCH c_offer_info INTO l_custom_setup_id;
5140           CLOSE c_offer_info;
5141        END IF;
5142 
5143         IF NVL(l_check_validation, 'NO') <> 'NO' -- for offer validation
5144               AND l_temp_act_rec.arc_act_budget_used_by = 'OFFR'
5145               AND NVL(l_custom_setup_id,0) NOT IN (110,115,116,117)  -- exclude budget request for softunf and special pricing.
5146               AND l_temp_act_rec.budget_source_type = 'FUND' THEN
5147                  l_temp_act_rec.status_code := 'PENDING_VALIDATION';
5148                  l_temp_act_rec.approved_in_currency := l_approved_in_currency;
5149                  x_act_budget_rec := l_temp_act_rec;
5150             ELSE
5151               l_temp_act_rec.approved_amount := p_act_budget_rec.request_amount;
5152               l_temp_act_rec.approved_in_currency := l_approved_in_currency;
5153               l_temp_act_rec.approved_original_amount := l_approved_amount;
5154               l_temp_act_rec.approver_id := x_act_budget_rec.requester_id;
5155               l_temp_act_rec.comment := p_act_budget_rec.comment;
5156               l_temp_act_rec.status_code := 'APPROVED';
5157                process_approval (
5158                p_act_budget_rec=> l_temp_act_rec
5159               ,x_act_budget_rec=> x_act_budget_rec
5160               ,x_return_status=> l_return_status
5161               ,x_msg_count=> x_msg_count
5162               ,x_msg_data=> x_msg_data
5163             );
5164             END IF;
5165         END IF;
5166       END IF;
5167       x_start_flow_flag :=l_start_flow_flag;
5168    END trigger_approval_process;
5169 
5170 /*****************************************************************************************/
5171 -- Start of Comments
5172    --
5173    -- NAME
5174    --    get_object_currency
5175    -- PURPOSE
5176    --    Return the currency code of the object trying to
5177    --    associate a budget.
5178    -- NOTE
5179    --    To support other objects, the function will need
5180    --    to be modified.
5181    -- HISTORY
5182    -- 15-Aug-2000  choang     Created.
5183    -- 01-Sep-2000  choang     ARC qualifier for deliverables should be DELV
5184    -- 02/22/2001   mpande    Added validation for offer
5185    --    12/23/2002   feliu       Changed for chargback.
5186    -- 10/21/2003   yzhao      Added for price list
5187 /*****************************************************************************************/
5188    FUNCTION get_object_currency (
5189       p_object          IN       VARCHAR2
5190      ,p_object_id       IN       NUMBER
5191      ,x_return_status   OUT NOCOPY      VARCHAR2
5192    )
5193       RETURN VARCHAR2 IS
5194       l_currency_code   VARCHAR2 (15);
5195 
5196       CURSOR c_campaign IS
5197          SELECT transaction_currency_code
5198            FROM ams_campaigns_vl
5199           WHERE campaign_id = p_object_id;
5200 
5201       CURSOR c_campaign_schl IS
5202          SELECT transaction_currency_code
5203            FROM ams_campaign_schedules_vl
5204           WHERE schedule_id = p_object_id;
5205 
5206       CURSOR c_eheader IS
5207          SELECT currency_code_tc
5208            FROM ams_event_headers_vl
5209           WHERE event_header_id = p_object_id;
5210 
5211       CURSOR c_eoffer IS
5212          SELECT currency_code_tc
5213            FROM ams_event_offers_vl
5214           WHERE event_offer_id = p_object_id;
5215 
5216       CURSOR c_deliverable IS
5217          SELECT transaction_currency_code
5218            FROM ams_deliverables_vl
5219           WHERE deliverable_id = p_object_id;
5220 
5221       CURSOR c_fund IS
5222          SELECT currency_code_tc
5223            FROM ozf_funds_all_b
5224           WHERE fund_id = p_object_id;
5225 
5226       CURSOR c_offer IS
5227          SELECT nvl(transaction_currency_code, fund_request_curr_code)
5228            FROM ozf_offers
5229           WHERE qp_list_header_id = p_object_id;
5230 
5231       CURSOR c_pricelist IS
5232          SELECT currency_code
5233            FROM qp_list_headers_b
5234           WHERE list_header_id = p_object_id;
5235 
5236       CURSOR c_worksheet IS
5237          SELECT currency_code
5238            FROM ozf_worksheet_headers_vl
5239           WHERE worksheet_header_id = p_object_id;
5240 
5241       CURSOR c_soft_fund IS
5242          SELECT currency_code
5243            FROM ozf_request_headers_all_b
5244           WHERE request_header_id = p_object_id;
5245 
5246       CURSOR c_special_price IS
5247          SELECT currency_code
5248            FROM ozf_request_headers_all_b
5249           WHERE request_header_id = p_object_id;
5250 
5251    BEGIN
5252       x_return_status            := fnd_api.g_ret_sts_success;
5253 
5254       -- Campaign
5255       IF p_object = 'CAMP' THEN
5256          OPEN c_campaign;
5257          FETCH c_campaign INTO l_currency_code;
5258 
5259          IF c_campaign%NOTFOUND THEN
5260             CLOSE c_campaign;
5261             ozf_utility_pvt.error_message ('OZF_ACT_BUDG_NO_CURRENCY');
5262             x_return_status            := fnd_api.g_ret_sts_error;
5263             RAISE fnd_api.g_exc_error;
5264          END IF;
5265 
5266          CLOSE c_campaign;
5267       -- Campaign Schdules
5268       ELSIF p_object = 'CSCH' THEN
5269          OPEN c_campaign_schl;
5270          FETCH c_campaign_schl INTO l_currency_code;
5271 
5272          IF c_campaign_schl%NOTFOUND THEN
5273             CLOSE c_campaign_schl;
5274             ozf_utility_pvt.error_message ('OZF_ACT_BUDG_NO_CURRENCY');
5275             x_return_status            := fnd_api.g_ret_sts_error;
5276             RAISE fnd_api.g_exc_error;
5277          END IF;
5278 
5279          CLOSE c_campaign_schl;
5280       -- Event Header/Rollup Event
5281       ELSIF p_object = 'EVEH' THEN
5282          OPEN c_eheader;
5283          FETCH c_eheader INTO l_currency_code;
5284 
5285          IF c_eheader%NOTFOUND THEN
5286             CLOSE c_eheader;
5287             ozf_utility_pvt.error_message ('OZF_ACT_BUDG_NO_CURRENCY');
5288             x_return_status            := fnd_api.g_ret_sts_error;
5289             RAISE fnd_api.g_exc_error;
5290          END IF;
5291 
5292          CLOSE c_eheader;
5293       -- Event Offer/Execution Event
5294       ELSIF p_object IN ('EONE','EVEO') THEN
5295          OPEN c_eoffer;
5296          FETCH c_eoffer INTO l_currency_code;
5297 
5298          IF c_eoffer%NOTFOUND THEN
5299             CLOSE c_eoffer;
5300             ozf_utility_pvt.error_message ('OZF_ACT_BUDG_NO_CURRENCY');
5301             x_return_status            := fnd_api.g_ret_sts_error;
5302             RAISE fnd_api.g_exc_error;
5303          END IF;
5304 
5305          CLOSE c_eoffer;
5306       -- Deliverable
5307       ELSIF p_object = 'DELV' THEN
5308          OPEN c_deliverable;
5309          FETCH c_deliverable INTO l_currency_code;
5310 
5311          IF c_deliverable%NOTFOUND THEN
5312             CLOSE c_deliverable;
5313             ozf_utility_pvt.error_message ('OZF_ACT_BUDG_NO_CURRENCY');
5314             x_return_status            := fnd_api.g_ret_sts_error;
5315             RAISE fnd_api.g_exc_error;
5316          END IF;
5317 
5318          CLOSE c_deliverable;
5319       ELSIF p_object = 'FUND' THEN
5320          OPEN c_fund;
5321          FETCH c_fund INTO l_currency_code;
5322 
5323          IF c_fund%NOTFOUND THEN
5324             CLOSE c_fund;
5325             ozf_utility_pvt.error_message ('OZF_ACT_BUDG_NO_CURRENCY');
5326             x_return_status            := fnd_api.g_ret_sts_error;
5327             RAISE fnd_api.g_exc_error;
5328          END IF;
5329 
5330          CLOSE c_fund;
5331       -- yzhao: 10/20/2003 for price list   ELSIF p_object = 'OFFR' THEN
5332       ELSIF p_object = 'OFFR'  THEN
5333          OPEN c_offer;
5334          FETCH c_offer INTO l_currency_code;
5335 
5336          IF c_offer%NOTFOUND THEN
5337             CLOSE c_offer;
5338             ozf_utility_pvt.error_message ('OZF_ACT_BUDG_NO_CURRENCY');
5339             x_return_status            := fnd_api.g_ret_sts_error;
5340             RAISE fnd_api.g_exc_error;
5341          END IF;
5342 
5343          CLOSE c_offer;
5344       ELSIF p_object = 'PRIC' THEN
5345          OPEN c_pricelist;
5346          FETCH c_pricelist INTO l_currency_code;
5347 
5348          IF c_pricelist%NOTFOUND THEN
5349             CLOSE c_pricelist;
5350             ozf_utility_pvt.error_message ('OZF_ACT_BUDG_NO_CURRENCY');
5351             x_return_status            := fnd_api.g_ret_sts_error;
5352             RAISE fnd_api.g_exc_error;
5353          END IF;
5354 
5355          CLOSE c_pricelist;
5356       ELSIF p_object = 'WKST' THEN
5357          OPEN c_worksheet;
5358          FETCH c_worksheet INTO l_currency_code;
5359 
5360          IF c_worksheet%NOTFOUND THEN
5361             CLOSE c_worksheet;
5362             ozf_utility_pvt.error_message ('OZF_ACT_BUDG_NO_CURRENCY');
5363             x_return_status            := fnd_api.g_ret_sts_error;
5364             RAISE fnd_api.g_exc_error;
5365          END IF;
5366 
5367          CLOSE c_worksheet;
5368       ELSIF p_object = 'SOFT_FUND' THEN
5369          OPEN c_soft_fund;
5370          FETCH c_soft_fund INTO l_currency_code;
5371 
5372          IF c_soft_fund%NOTFOUND THEN
5373             CLOSE c_soft_fund;
5374             ozf_utility_pvt.error_message ('OZF_ACT_BUDG_NO_CURRENCY');
5375             x_return_status            := fnd_api.g_ret_sts_error;
5376             RAISE fnd_api.g_exc_error;
5377          END IF;
5378 
5379          CLOSE c_soft_fund;
5380       ELSIF p_object = 'SPECIAL_PRICE' THEN
5381          OPEN c_special_price;
5382          FETCH c_special_price INTO l_currency_code;
5383 
5384          IF c_special_price%NOTFOUND THEN
5385             CLOSE c_special_price;
5386             ozf_utility_pvt.error_message ('OZF_ACT_BUDG_NO_CURRENCY');
5387             x_return_status            := fnd_api.g_ret_sts_error;
5388             RAISE fnd_api.g_exc_error;
5389          END IF;
5390 
5391          CLOSE c_special_price;
5392       ELSE
5393 
5394          ozf_utility_pvt.error_message ('OZF_ACT_BUDG_NO_CURRENCY');
5395          x_return_status            := fnd_api.g_ret_sts_error;
5396          RAISE fnd_api.g_exc_error;
5397       END IF;
5398 
5399       RETURN l_currency_code;
5400    EXCEPTION
5401       WHEN OTHERS THEN
5402          x_return_status            := fnd_api.g_ret_sts_error;
5403 
5404          IF c_campaign%ISOPEN THEN
5405             CLOSE c_campaign;
5406          END IF;
5407 
5408          IF c_campaign_schl%ISOPEN THEN
5409             CLOSE c_campaign_schl;
5410          END IF;
5411 
5412          IF c_eheader%ISOPEN THEN
5413             CLOSE c_eheader;
5414          END IF;
5415 
5416          IF c_eoffer%ISOPEN THEN
5417             CLOSE c_eoffer;
5418          END IF;
5419 
5420          IF c_deliverable%ISOPEN THEN
5421             CLOSE c_deliverable;
5422          END IF;
5423 
5424          IF c_offer%ISOPEN THEN
5425             CLOSE c_offer;
5426          END IF;
5427 
5428          IF c_fund%ISOPEN THEN
5429             CLOSE c_fund;
5430          END IF;
5431 
5432          IF c_soft_fund%ISOPEN THEN
5433             CLOSE c_soft_fund;
5434          END IF;
5435 
5436          IF c_special_price%ISOPEN THEN
5437             CLOSE c_special_price;
5438          END IF;
5439 
5440          RAISE;
5441    END get_object_currency;
5442 
5443 
5444 /*****************************************************************************************/
5445    --
5446    -- NAME
5447    --    process_approval
5448    -- PURPOSE
5449    --    Handle all tasks needed before a budget line
5450    --    can be approved.
5451    -- HISTORY
5452    -- 14-Sep-2000 choang   Created.
5453    -- 05/02/2001  mpande   Updated
5454    -- 07-NOV-2001  Feliu   Added updating of recal_committed amount.
5455    -- 27/10/2009  muthsubr Added  p_use_fund_staging_tables, px_ozf_funds_old_rectype,
5456    --                      px_ozf_funds_new_rectype for bug#8867381.
5457    -- 29/11/2010  muthsubr Altered px_ozf_funds_new_rectype to px_ozf_funds_new_tbl
5458    --                      for TPA Parallel Execution ER Bug#9614703.
5459 /*****************************************************************************************/
5460    PROCEDURE process_approval (
5461       p_act_budget_rec   IN       act_budgets_rec_type
5462      ,x_act_budget_rec   OUT NOCOPY      act_budgets_rec_type
5463      ,x_return_status    OUT NOCOPY      VARCHAR2
5464      ,x_msg_count        OUT NOCOPY      NUMBER
5465      ,x_msg_data         OUT NOCOPY      VARCHAR2
5466      ,p_mode             IN       VARCHAR2 :='UPDATE'-- added by mpande 12/27/2001
5467    ) IS
5468      l_resale_batch_id  NUMBER;
5469      l_use_fund_staging_tables VARCHAR2(1)      := 'F';
5470      lx_ozf_funds_old_rectype OZF_UTILITY_PVT.ozf_funds_all_b_rectype;
5471      lx_ozf_funds_new_tbl OZF_UTILITY_PVT.ozf_funds_table;
5472      l_batch_type VARCHAR2(30);
5473    BEGIN
5474    process_approval (
5475       p_act_budget_rec   =>      p_act_budget_rec
5476      ,x_act_budget_rec   =>      x_act_budget_rec
5477      ,x_return_status    =>      x_return_status
5478      ,x_msg_count        =>      x_msg_count
5479      ,x_msg_data         =>      x_msg_data
5480      ,p_mode             =>      p_mode
5481      ,p_resale_batch_id  =>      l_resale_batch_id
5482      ,p_batch_type           =>    l_batch_type
5483      ,p_use_fund_staging_tables => l_use_fund_staging_tables
5484      ,px_ozf_funds_old_rectype  =>  lx_ozf_funds_old_rectype
5485      ,px_ozf_funds_new_tbl  =>  lx_ozf_funds_new_tbl                    -- For TPA Parallel Execution ER Bug#9614703
5486      );
5487    END process_approval;
5488 
5489 /*****************************************************************************************/
5490 -- Start of Comments
5491    /****************************************************
5492    -- the code for two methods Removed by mpande 04/30/2001
5493       1) can modify , is account closed
5494    *******************************************************************/
5495    --
5496    -- NAME
5497    --    process_approval
5498    -- PURPOSE
5499    --    Handle all tasks needed before a budget line
5500    --    can be approved.
5501    -- HISTORY
5502    -- 14-Sep-2000 choang   Created.
5503    -- 05/02/2001  mpande   Updated
5504    -- 07-NOV-2001  Feliu   Added updating of recal_committed amount.
5505    -- 27/10/2009  muthsubr Added  p_use_fund_staging_tables, px_ozf_funds_old_rectype,
5506    --                      px_ozf_funds_new_rectype for bug#8867381.
5507    -- 29/11/2010  muthsubr Altered px_ozf_funds_new_rectype to px_ozf_funds_new_tbl
5508    --                      for TPA Parallel Execution ER Bug#9614703.
5509 /*****************************************************************************************/
5510    PROCEDURE process_approval (
5511       p_act_budget_rec   IN       act_budgets_rec_type
5512      ,x_act_budget_rec   OUT NOCOPY      act_budgets_rec_type
5513      ,x_return_status    OUT NOCOPY      VARCHAR2
5514      ,x_msg_count        OUT NOCOPY      NUMBER
5515      ,x_msg_data         OUT NOCOPY      VARCHAR2
5516      ,p_mode             IN       VARCHAR2 :='UPDATE'-- added by mpande 12/27/2001
5517      ,p_resale_batch_id  IN  NUMBER
5518      ,p_batch_type           IN  VARCHAR2
5519      ,p_use_fund_staging_tables IN VARCHAR2
5520      ,px_ozf_funds_old_rectype  IN      OZF_UTILITY_PVT.ozf_funds_all_b_rectype
5521      ,px_ozf_funds_new_tbl  IN OUT  NOCOPY  OZF_UTILITY_PVT.ozf_funds_table             -- For TPA Parallel Execution ER Bug#9614703
5522    ) IS
5523       l_api_name            CONSTANT VARCHAR2 (30)               := 'Process_Approval';
5524       l_return_status                VARCHAR2 (1);
5525       l_temp_rec                     act_budgets_rec_type;
5526       l_temp_in_rec                  act_budgets_rec_type;
5527       l_fund_rec                     ozf_funds_pvt.fund_rec_type;
5528       l_fund_object_version_number   NUMBER;
5529       l_fund_currency_tc             VARCHAR2 (15); -- a fund's transactional currency code
5530       l_fund_planned_amount          NUMBER;
5531       l_fund_committed_amount        NUMBER;
5532       l_fund_transfer_flag           VARCHAR2 (1)                := fnd_api.g_false;
5533       l_fund_recal_committed_amount  NUMBER;
5534       l_univ_planned_amount          NUMBER;
5535       l_univ_committed_amount        NUMBER;
5536       l_objfundsum_rec               ozf_objfundsum_pvt.objfundsum_rec_type := NULL;
5537       l_objfundsum_id     NUMBER;
5538 
5539       l_fund_reconc_msg VARCHAR2(4000);
5540       l_act_bud_cst_msg VARCHAR2(4000);
5541 
5542       CURSOR c_fund (l_fund_id IN NUMBER) IS
5543          SELECT object_version_number, currency_code_tc, planned_amt, committed_amt, recal_committed
5544            FROM ozf_funds_all_b
5545           WHERE fund_id = l_fund_id;
5546 
5547       -- yzhao: R12 update ozf_object_fund_summary table
5548       CURSOR c_get_objfundsum_rec(p_object_type IN VARCHAR2, p_object_id IN NUMBER, p_fund_id IN NUMBER) IS
5549          SELECT objfundsum_id
5550               , object_version_number
5551               , planned_amt
5552               , committed_amt
5553               , recal_committed_amt
5554               , plan_curr_planned_amt
5555               , plan_curr_committed_amt
5556               , plan_curr_recal_committed_amt
5557               , univ_curr_planned_amt
5558               , univ_curr_committed_amt
5559               , univ_curr_recal_committed_amt
5560          FROM   ozf_object_fund_summary
5561          WHERE  object_type = p_object_type
5562          AND    object_id = p_object_id
5563          AND    fund_id = p_fund_id;
5564 
5565    BEGIN
5566       IF G_DEBUG THEN
5567          ozf_utility_pvt.debug_message (   g_package_name
5568                                      || '.'
5569                                      || l_api_name
5570                                      || ': start');
5571       END IF;
5572 
5573       -- The from currency should be passed in before currency
5574       -- conversion can be performed.
5575       IF    p_act_budget_rec.approved_in_currency IS NULL
5576          OR p_act_budget_rec.approved_in_currency = fnd_api.g_miss_char THEN
5577          ozf_utility_pvt.error_message ('OZF_ACT_BUDGET_NO_APPR_CURR');
5578          RAISE fnd_api.g_exc_error;
5579       END IF;
5580 
5581      --Added for bug 7425189
5582      l_fund_reconc_msg := fnd_message.get_string ('OZF', 'OZF_FUND_RECONCILE');
5583      l_act_bud_cst_msg := fnd_message.get_string ('OZF', 'OZF_ACT_BUDG_CST_UTIL');
5584 
5585       -- check if parent has enough money. add by feliu on 03/26/04 to fix bug 3463554
5586       IF (p_act_budget_rec.budget_source_type ='CAMP' AND p_act_budget_rec.arc_act_budget_used_by = 'CSCH') OR
5587          (p_act_budget_rec.budget_source_type ='EVEH' AND p_act_budget_rec.arc_act_budget_used_by = 'EVEO')  OR
5588          (p_act_budget_rec.budget_source_type ='CAMP' AND p_act_budget_rec.arc_act_budget_used_by = 'OFFR')  -- added to fix bug 4018381
5589          THEN
5590         IF ozf_ACTBUDGETRULES_PVT.source_has_enough_money (
5591            p_source_type  => p_act_budget_rec.budget_source_type,
5592             p_source_id    => p_act_budget_rec.budget_source_id,
5593             p_approved_amount => p_act_budget_rec.approved_original_amount
5594          ) = FND_API.g_false THEN
5595             ozf_Utility_PVT.error_message ('OZF_ACT_BUDG_NO_MONEY');
5596             RAISE FND_API.g_exc_error;
5597          END IF;
5598       END IF;
5599 
5600       IF p_mode = 'UPDATE' THEN
5601          init_act_budgets_rec (l_temp_in_rec);
5602       END IF;
5603 
5604 
5605 
5606 
5607       l_temp_in_rec.activity_budget_id := p_act_budget_rec.activity_budget_id;
5608       l_temp_in_rec.object_version_number := p_act_budget_rec.object_version_number;
5609       l_temp_in_rec.approver_id     := p_act_budget_rec.approver_id;
5610      -- l_temp_in_rec.approved_original_amount := NVL(p_act_budget_rec.approved_original_amount,p_act_budget_rec.request_amount);
5611       --approved_original_amount is in approved_in_currency and can not use request_currency.
5612       l_temp_in_rec.approved_original_amount := p_act_budget_rec.approved_original_amount;
5613       l_temp_in_rec.approved_in_currency := p_act_budget_rec.approved_in_currency;
5614       l_temp_in_rec.status_code     := p_act_budget_rec.status_code;
5615       l_temp_in_rec.comment     := p_act_budget_rec.comment;
5616       l_temp_in_rec.src_curr_req_amt     := p_act_budget_rec.src_curr_req_amt;
5617       --
5618       -- Fill in the rest of the columns, to be able to reference
5619       -- request_currency.
5620       -- 12/27/2001
5621       IF G_DEBUG THEN
5622          ozf_utility_pvt.debug_message (p_act_budget_rec.request_currency);
5623          ozf_utility_pvt.debug_message (p_act_budget_rec.request_amount);
5624          ozf_utility_pvt.debug_message (p_act_budget_rec.transfer_type);
5625       END IF;
5626       IF p_mode = 'UPDATE' THEN
5627         complete_act_budgets_rec (l_temp_in_rec, l_temp_rec);
5628       ELSE
5629 
5630          l_temp_rec.request_currency := p_act_budget_rec.request_currency;
5631          l_temp_rec.request_amount := p_act_budget_rec.request_amount;
5632          l_temp_rec.budget_source_type := p_act_budget_rec.budget_source_type;
5633          l_temp_rec.budget_source_id := p_act_budget_rec.budget_source_id;
5634          l_temp_rec.arc_Act_budget_used_by := p_act_budget_rec.arc_act_budget_used_by;
5635          l_temp_rec.act_budget_used_by_id := p_act_budget_rec.act_budget_used_by_id;
5636          l_temp_rec.transfer_type := p_act_budget_rec.transfer_type;
5637          l_temp_rec.approved_in_currency := p_act_budget_rec.approved_in_currency;
5638          l_temp_rec.approved_original_amount := p_act_budget_rec.approved_original_amount;
5639          l_temp_rec.parent_source_id := p_act_budget_rec.parent_source_id;
5640 
5641       END IF;
5642 
5643       -- added by feliu on 03/05/04 to fix bug 3487649
5644       -- modified by rimehrot to avoid duplicate currency conversion. If approved_original_amount
5645       -- is null, approved_amount is same as request_amount. Else approved_amount is obtained from
5646       -- approved_original_amount.
5647 
5648 
5649       IF l_temp_rec.approved_original_amount IS NULL THEN
5650          l_temp_rec.approved_amount := l_temp_rec.request_amount;
5651          IF l_temp_rec.approved_in_currency = l_temp_rec.request_currency THEN
5652             l_temp_rec.approved_original_amount := l_temp_rec.request_amount;
5653          ELSE
5654          -- call the currency conversion wrapper
5655          --In case of accruals creation, l_temp_rec.request_currency and l_temp_rec.approved_in_currency
5656          --are same(offer curr). check OZF_Adjustment_EXT_PVT.adjustment_net_accrual.
5657          --use conversion type profile.
5658 
5659             IF G_DEBUG THEN
5660                ozf_utility_pvt.debug_message (   l_api_name
5661                              || ' p_act_budget_rec.exchange_rate_date1: ' || p_act_budget_rec.exchange_rate_date);
5662             END IF;
5663 
5664             ozf_utility_pvt.convert_currency (
5665                 x_return_status => l_return_status
5666                ,p_from_currency => l_temp_rec.request_currency
5667                ,p_to_currency   => l_temp_rec.approved_in_currency
5668                ,p_conv_date     => p_act_budget_rec.exchange_rate_date --bug 7425189, 8532055
5669                ,p_from_amount   => l_temp_rec.request_amount
5670                ,x_to_amount     => l_temp_rec.approved_original_amount
5671             );
5672 
5673         /*
5674         --Added for bug 7425189
5675         IF p_act_budget_rec.justification IN (l_fund_reconc_msg,l_act_bud_cst_msg)
5676         AND p_act_budget_rec.exchange_rate_date IS NOT NULL THEN
5677            ozf_utility_pvt.convert_currency (
5678                x_return_status=> l_return_status
5679                ,p_from_currency=> l_temp_rec.request_currency
5680                ,p_to_currency=> l_temp_rec.approved_in_currency
5681                ,p_conv_date=> p_act_budget_rec.exchange_rate_date
5682                ,p_from_amount=> l_temp_rec.request_amount
5683                ,x_to_amount=> l_temp_rec.approved_original_amount
5684             );
5685         ELSE
5686 
5687            ozf_utility_pvt.convert_currency (
5688                x_return_status=> l_return_status
5689                ,p_from_currency=> l_temp_rec.request_currency
5690                ,p_to_currency=> l_temp_rec.approved_in_currency
5691                ,p_from_amount=> l_temp_rec.request_amount
5692                ,x_to_amount=> l_temp_rec.approved_original_amount
5693             );
5694         END IF;
5695         */
5696 
5697             IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5698                RAISE fnd_api.g_exc_unexpected_error;
5699             ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
5700                RAISE fnd_api.g_exc_error;
5701             END IF;
5702          END IF;
5703       ELSE
5704           -- approved_original_amount is not null.
5705           IF l_temp_rec.approved_in_currency = l_temp_rec.request_currency THEN
5706           -- don't need to convert if currencies are equal
5707              l_temp_rec.approved_amount := l_temp_rec.approved_original_amount;
5708           ELSE
5709                  -- call the currency conversion wrapper
5710                  -- do not convert twice if the approved_original_amount is same as that requested.
5711              IF l_temp_rec.approved_original_amount = l_temp_rec.src_curr_req_amt THEN
5712                 l_temp_rec.approved_amount := l_temp_rec.request_amount;
5713              ELSE
5714 
5715                 IF G_DEBUG THEN
5716                    ozf_utility_pvt.debug_message (   l_api_name
5717                            || ' p_act_budget_rec.exchange_rate_date2: ' || p_act_budget_rec.exchange_rate_date);
5718                 END IF;
5719 
5720                 ozf_utility_pvt.convert_currency (
5721                     x_return_status => l_return_status
5722                    ,p_from_currency => l_temp_rec.approved_in_currency
5723                    ,p_to_currency   => l_temp_rec.request_currency
5724                    ,p_conv_date     => p_act_budget_rec.exchange_rate_date --bug 7425189, 8532055
5725                    ,p_from_amount   => l_temp_rec.approved_original_amount
5726                    ,x_to_amount     => l_temp_rec.approved_amount
5727                  );
5728 
5729              /*
5730              --Added for bug 7425189
5731              IF p_act_budget_rec.justification IN (l_fund_reconc_msg,l_act_bud_cst_msg)
5732              AND p_act_budget_rec.exchange_rate_date IS NOT NULL THEN
5733                 ozf_utility_pvt.convert_currency (
5734                     x_return_status=> l_return_status
5735                    ,p_from_currency=> l_temp_rec.approved_in_currency
5736                    ,p_to_currency=> l_temp_rec.request_currency
5737                    ,p_conv_date=> p_act_budget_rec.exchange_rate_date
5738                    ,p_from_amount=> l_temp_rec.approved_original_amount
5739                    ,x_to_amount=> l_temp_rec.approved_amount
5740                  );
5741              ELSE
5742                 ozf_utility_pvt.convert_currency (
5743                     x_return_status=> l_return_status
5744                    ,p_from_currency=> l_temp_rec.approved_in_currency
5745                    ,p_to_currency=> l_temp_rec.request_currency
5746                    ,p_from_amount=> l_temp_rec.approved_original_amount
5747                    ,x_to_amount=> l_temp_rec.approved_amount
5748                  );
5749 
5750              END IF;
5751              */
5752 
5753                  IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5754                     RAISE fnd_api.g_exc_unexpected_error;
5755                  ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
5756                     RAISE fnd_api.g_exc_error;
5757                  END IF;
5758              END IF;
5759           END IF;
5760       END IF;
5761       -- end of added by feliu on 03/05/04
5762 
5763 
5764       l_temp_rec.approval_date   := NVL (p_act_budget_rec.approval_date, SYSDATE);
5765 
5766       IF      l_temp_rec.budget_source_type = 'FUND'
5767           AND l_temp_rec.arc_act_budget_used_by = 'FUND' THEN
5768          l_fund_transfer_flag       := fnd_api.g_true;
5769       END IF;
5770 
5771       IF l_fund_transfer_flag = fnd_api.g_false THEN
5772          -- if the budget source is a fund , then the
5773          -- fund's planned amount must be decreased
5774          -- by the request_amount during approval
5775          -- submission.
5776          IF    l_temp_rec.budget_source_type = 'FUND'
5777             OR l_temp_rec.arc_act_budget_used_by = 'FUND' THEN
5778             ozf_funds_pvt.init_fund_rec (l_fund_rec);
5779 
5780             l_objfundsum_rec := NULL;
5781 
5782             IF l_temp_rec.budget_source_type = 'FUND' THEN
5783                OPEN c_fund (l_temp_rec.budget_source_id);
5784                FETCH c_fund INTO l_fund_object_version_number
5785                                 ,l_fund_currency_tc
5786                                 ,l_fund_planned_amount
5787                                 ,l_fund_committed_amount
5788                                 ,l_fund_recal_committed_amount;
5789                CLOSE c_fund;
5790                l_fund_rec.fund_id         := l_temp_rec.budget_source_id;
5791 
5792                -- R12: yzhao ozf_object_fund_summary
5793 
5794                OPEN c_get_objfundsum_rec(l_temp_rec.arc_act_budget_used_by
5795                                        , l_temp_rec.act_budget_used_by_id
5796                                        , l_temp_rec.budget_source_id);
5797 
5798             ELSIF l_temp_rec.arc_act_budget_used_by = 'FUND' THEN
5799                OPEN c_fund (l_temp_rec.act_budget_used_by_id);
5800                FETCH c_fund INTO l_fund_object_version_number
5801                                 ,l_fund_currency_tc
5802                                 ,l_fund_planned_amount
5803                                 ,l_fund_committed_amount
5804                                 ,l_fund_recal_committed_amount;
5805                CLOSE c_fund;
5806                l_fund_rec.fund_id         := l_temp_rec.act_budget_used_by_id;
5807                -- R12: yzhao ozf_object_fund_summary
5808 
5809                OPEN c_get_objfundsum_rec(l_temp_rec.budget_source_type
5810                                        , l_temp_rec.budget_source_id
5811                                        , l_temp_rec.act_budget_used_by_id);
5812             END IF;
5813 
5814 /*
5815             IF c_get_objfundsum_rec%NOTFOUND THEN
5816                CLOSE c_get_objfundsum_rec;
5817                IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_error) THEN
5818                   fnd_message.set_name('OZF', 'OZF_OBJFUNDSUM_RECORD_NOT_FOUND');
5819                   fnd_msg_pub.add;
5820                END IF;
5821                RAISE fnd_api.g_exc_error;
5822             END IF;
5823 */
5824             FETCH c_get_objfundsum_rec INTO l_objfundsum_rec.objfundsum_id
5825                                           , l_objfundsum_rec.object_version_number
5826                                           , l_objfundsum_rec.planned_amt
5827                                           , l_objfundsum_rec.committed_amt
5828                                           , l_objfundsum_rec.recal_committed_amt
5829                                           , l_objfundsum_rec.plan_curr_planned_amt
5830                                           , l_objfundsum_rec.plan_curr_committed_amt
5831                                           , l_objfundsum_rec.plan_curr_recal_committed_amt
5832                                           , l_objfundsum_rec.univ_curr_planned_amt
5833                                           , l_objfundsum_rec.univ_curr_committed_amt
5834                                           , l_objfundsum_rec.univ_curr_recal_committed_amt;
5835             CLOSE c_get_objfundsum_rec;
5836             -- R12: yzhao END ozf_object_fund_summary
5837 
5838 
5839             l_fund_rec.object_version_number := l_fund_object_version_number;
5840 
5841             -- this is always during transfer
5842             IF l_temp_rec.request_currency = l_fund_currency_tc THEN
5843                -- don't need to convert if currencies are equal
5844                l_fund_rec.planned_amt     := l_temp_rec.request_amount;
5845             ELSE
5846                -- convert the request amount to the fund's
5847                -- currency.  the planned amount for a fund
5848                -- is stored in the table as a value based
5849                -- on the transactional currency, so the
5850                -- request amount must also be based on the
5851                -- same currency.
5852                --7030415,
5853 
5854                 IF G_DEBUG THEN
5855                    ozf_utility_pvt.debug_message (   l_api_name
5856                            || ' p_act_budget_rec.exchange_rate_date3: ' || p_act_budget_rec.exchange_rate_date);
5857                 END IF;
5858 
5859                 ozf_utility_pvt.convert_currency (
5860                   x_return_status => l_return_status
5861                  ,p_from_currency => l_temp_rec.request_currency
5862                  ,p_to_currency   => l_fund_currency_tc
5863                  ,p_conv_date     => p_act_budget_rec.exchange_rate_date --bug 7425189, 8532055
5864                  ,p_from_amount   => l_temp_rec.request_amount
5865                  ,x_to_amount     => l_fund_rec.planned_amt
5866                );
5867 
5868                /*
5869                --Added for bug 7425189
5870 
5871             IF p_act_budget_rec.justification IN (l_fund_reconc_msg,l_act_bud_cst_msg)
5872                 AND p_act_budget_rec.exchange_rate_date IS NOT NULL THEN
5873 
5874                ozf_utility_pvt.convert_currency (
5875                   x_return_status=> l_return_status
5876                  ,p_from_currency=> l_temp_rec.request_currency
5877                  ,p_to_currency=> l_fund_currency_tc
5878                  ,p_conv_date=> p_act_budget_rec.exchange_rate_date
5879                  ,p_from_amount=> l_temp_rec.request_amount
5880                  ,x_to_amount=> l_fund_rec.planned_amt
5881                );
5882            ELSE
5883            ozf_utility_pvt.convert_currency (
5884                   x_return_status=> l_return_status
5885                  ,p_from_currency=> l_temp_rec.request_currency
5886                  ,p_to_currency=> l_fund_currency_tc
5887                  ,p_from_amount=> l_temp_rec.request_amount
5888                  ,x_to_amount=> l_fund_rec.planned_amt
5889                );
5890            END IF;
5891            */
5892                IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5893                   RAISE fnd_api.g_exc_unexpected_error;
5894                ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
5895                   RAISE fnd_api.g_exc_error;
5896                END IF;
5897             END IF;
5898 
5899             IF l_temp_rec.transfer_type = 'REQUEST' THEN
5900                 IF l_temp_rec.approved_in_currency = l_fund_currency_tc THEN
5901                    -- don't need to convert if currencies are equal
5902                    l_fund_rec.committed_amt   := l_temp_rec.approved_original_amount;
5903                 ELSE
5904                    -- convert the approved amount to the fund's
5905                    -- currency.  the committed amount for a fund
5906                    -- is stored in the table as a value based
5907                    -- on the transactional currency, so the
5908                    -- approved amount must also be based on the
5909                    -- same currency.  for best results, we'll use
5910                    -- the original approved amount for conversion.
5911                    -- 12/26/2001 mpande changed here for transfer
5912                    --Since this conversion is for updating planned/committed amounts.
5913                    --In case of utilization the transfer_type is 'UTILIZED'.
5914                    --So this part will not be executed.
5915 
5916                    ozf_utility_pvt.convert_currency (
5917                       x_return_status=> l_return_status
5918                      ,p_from_currency=> l_temp_rec.approved_in_currency
5919                      ,p_to_currency=> l_fund_currency_tc
5920                      ,p_from_amount=> l_temp_rec.approved_original_amount
5921                      ,x_to_amount=> l_fund_rec.committed_amt
5922                    );
5923 
5924                    IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5925                       RAISE fnd_api.g_exc_unexpected_error;
5926                    ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
5927                       RAISE fnd_api.g_exc_error;
5928                    END IF;
5929                 END IF;
5930             ELSE
5931                 -- in case of transfer the fund amount is approved amount
5932                 l_fund_rec.committed_amt := l_temp_rec.approved_amount;
5933             END IF ;
5934 
5935 
5936                    --Since the conversion given below is used in case
5937                    --of transfer_type='REQUEST'/'TRANSFER'. hence
5938                    --So this part will not be executed in case of transfer_type='UTILIZED'.
5939             -- R12: yzhao ozf_object_fund_summary
5940             IF g_universal_currency = l_temp_rec.request_currency THEN
5941                l_univ_planned_amount := l_temp_rec.request_amount;
5942                l_univ_committed_amount := l_temp_rec.approved_amount;
5943             ELSIF g_universal_currency = l_fund_currency_tc THEN
5944                l_univ_planned_amount := l_fund_rec.planned_amt;
5945                l_univ_committed_amount := l_fund_rec.committed_amt;
5946             ELSE
5947 
5948                 IF G_DEBUG THEN
5949                    ozf_utility_pvt.debug_message (   l_api_name
5950                            || ' p_act_budget_rec.exchange_rate_date4: ' || p_act_budget_rec.exchange_rate_date);
5951                 END IF;
5952 
5953                 ozf_utility_pvt.convert_currency (
5954                      x_return_status => l_return_status
5955                     ,p_from_currency => l_temp_rec.request_currency
5956                     ,p_to_currency   => g_universal_currency
5957                     ,p_conv_date     => p_act_budget_rec.exchange_rate_date --bug 7425189, 8532055
5958                     ,p_from_amount   => l_temp_rec.request_amount
5959                     ,x_to_amount     => l_univ_planned_amount
5960                   );
5961 
5962                 /*
5963                 --Added for bug 7425189
5964                 IF p_act_budget_rec.justification IN (l_fund_reconc_msg,l_act_bud_cst_msg)
5965                 AND p_act_budget_rec.exchange_rate_date IS NOT NULL THEN
5966                    ozf_utility_pvt.convert_currency (
5967                      x_return_status=> l_return_status
5968                     ,p_from_currency=> l_temp_rec.request_currency
5969                     ,p_to_currency=> g_universal_currency
5970                     ,p_conv_date=> p_act_budget_rec.exchange_rate_date
5971                     ,p_from_amount=> l_temp_rec.request_amount
5972                     ,x_to_amount=> l_univ_planned_amount
5973                   );
5974                ELSE
5975                   ozf_utility_pvt.convert_currency (
5976                      x_return_status=> l_return_status
5977                     ,p_from_currency=> l_temp_rec.request_currency
5978                     ,p_to_currency=> g_universal_currency
5979                     ,p_from_amount=> l_temp_rec.request_amount
5980                     ,x_to_amount=> l_univ_planned_amount
5981                );
5982                END IF;
5983                IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5984                   RAISE fnd_api.g_exc_unexpected_error;
5985                ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
5986                   RAISE fnd_api.g_exc_error;
5987                END IF;
5988                */
5989 
5990                IF l_temp_rec.request_amount = l_temp_rec.approved_amount THEN
5991                   l_univ_committed_amount := l_univ_planned_amount;
5992                ELSE
5993 
5994                   IF G_DEBUG THEN
5995                      ozf_utility_pvt.debug_message (   l_api_name
5996                            || ' p_act_budget_rec.exchange_rate_date5: ' || p_act_budget_rec.exchange_rate_date);
5997                   END IF;
5998 
5999                   ozf_utility_pvt.convert_currency (
6000                      x_return_status => l_return_status
6001                     ,p_from_currency => l_temp_rec.request_currency
6002                     ,p_to_currency   => g_universal_currency
6003                     ,p_conv_date     => p_act_budget_rec.exchange_rate_date --bug 7425189, 8532055
6004                     ,p_from_amount   => l_temp_rec.approved_amount
6005                     ,x_to_amount     => l_univ_committed_amount
6006                   );
6007 
6008                   /*
6009                   --Added for bug 7425189
6010                   IF p_act_budget_rec.justification IN (l_fund_reconc_msg,l_act_bud_cst_msg)
6011                   AND p_act_budget_rec.exchange_rate_date IS NOT NULL THEN
6012                     ozf_utility_pvt.convert_currency (
6013                      x_return_status=> l_return_status
6014                     ,p_from_currency=> l_temp_rec.request_currency
6015                     ,p_to_currency=> g_universal_currency
6016                     ,p_conv_date=> p_act_budget_rec.exchange_rate_date
6017                     ,p_from_amount=> l_temp_rec.approved_amount
6018                     ,x_to_amount=> l_univ_committed_amount
6019                   );
6020 
6021                  ELSE
6022                   ozf_utility_pvt.convert_currency (
6023                      x_return_status=> l_return_status
6024                     ,p_from_currency=> l_temp_rec.request_currency
6025                     ,p_to_currency=> g_universal_currency
6026                     ,p_from_amount=> l_temp_rec.approved_amount
6027                     ,x_to_amount=> l_univ_committed_amount
6028                   );
6029                  END IF;
6030                  */
6031 
6032                   IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6033                      RAISE fnd_api.g_exc_unexpected_error;
6034                   ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
6035                      RAISE fnd_api.g_exc_error;
6036                   END IF;
6037                END IF;
6038             END IF;
6039 
6040             IF G_DEBUG THEN
6041                ozf_utility_pvt.debug_message (
6042                   ' process_approval(): fund_currency=' || l_fund_currency_tc
6043                || '  request_curr=' || l_temp_rec.request_currency
6044                || '  approved_in_curr=' || l_temp_rec.approved_in_currency
6045                || '  univ_curr=' || g_universal_currency
6046                );
6047                ozf_utility_pvt.debug_message (
6048                   '  in fund currency: planned_amt=' || l_fund_rec.planned_amt
6049                || '  committed_amt=' || l_fund_rec.committed_amt
6050                || '  l_univ_planned_amount=' || l_univ_planned_amount
6051                || '  l_univ_committed_amount=' || l_univ_committed_amount
6052             );
6053             END IF;
6054             -- R12: yzhao END ozf_object_fund_summary
6055 
6056             IF p_mode = 'UPDATE' THEN
6057                IF l_temp_rec.transfer_type = 'REQUEST' THEN
6058                   -- R12: yzhao ozf_object_fund_summary decrease planned amount
6059                   l_objfundsum_rec.planned_amt := NVL(l_objfundsum_rec.planned_amt, 0) - NVL (l_fund_rec.planned_amt, 0);
6060                   l_objfundsum_rec.plan_curr_planned_amt := NVL(l_objfundsum_rec.plan_curr_planned_amt, 0)
6061                                                           - NVL(l_temp_rec.request_amount, 0);
6062                   l_objfundsum_rec.univ_curr_planned_amt := NVL(l_objfundsum_rec.univ_curr_planned_amt, 0)
6063                                                           - NVL(l_univ_planned_amount, 0);
6064                   -- R12: yzhao END ozf_object_fund_summary decrease planned amount
6065                   l_fund_rec.planned_amt     :=   l_fund_planned_amount
6066                                                 - l_fund_rec.planned_amt;
6067                ELSE
6068                   l_fund_rec.planned_amt     := l_fund_planned_amount;
6069                END IF;
6070             -- 03/01/2002 added else for all other transactions we donot want to touch fund planned_Amt
6071             ELSE
6072                l_fund_rec.planned_amt     := l_fund_planned_amount;
6073             END IF;
6074 
6075 
6076 
6077             -- Add the approved amount to the fund's committed amount
6078             IF l_temp_rec.transfer_type = 'REQUEST' THEN
6079                IF NVL(p_act_budget_rec.recal_flag,'N') = 'N' THEN
6080                   l_fund_rec.committed_amt   :=
6081                                  NVL (l_fund_committed_amount, 0)
6082                                + NVL (l_fund_rec.committed_amt, 0);
6083                   -- R12: yzhao ozf_object_fund_summary increase committed amount
6084                   l_objfundsum_rec.committed_amt := NVL(l_objfundsum_rec.committed_amt, 0)
6085                                                   + NVL (l_temp_rec.approved_original_amount, 0);
6086                   l_objfundsum_rec.plan_curr_committed_amt := NVL(l_objfundsum_rec.plan_curr_committed_amt, 0)
6087                                                             + NVL(l_temp_rec.approved_amount, 0);
6088                   l_objfundsum_rec.univ_curr_committed_amt := NVL(l_objfundsum_rec.univ_curr_committed_amt, 0)
6089                                                             + NVL(l_univ_committed_amount, 0);
6090                   -- R12: yzhao END ozf_object_fund_summary increase committed amount
6091                ELSE
6092                   l_fund_rec.committed_amt   :=
6093                                  NVL (l_fund_committed_amount, 0);
6094                END IF;
6095                -- always add the recal committed
6096                l_fund_rec.recal_committed   :=
6097                                  NVL (l_fund_recal_committed_amount, 0)
6098                                 + NVL (l_temp_rec.approved_original_amount, 0);
6099                l_objfundsum_rec.recal_committed_amt := NVL(l_objfundsum_rec.recal_committed_amt, 0)
6100                                                      + NVL (l_temp_rec.approved_original_amount, 0);
6101                l_objfundsum_rec.plan_curr_recal_committed_amt := NVL(l_objfundsum_rec.plan_curr_recal_committed_amt, 0)
6102                                                          + NVL(l_temp_rec.approved_amount, 0);
6103                l_objfundsum_rec.univ_curr_recal_committed_amt := NVL(l_objfundsum_rec.univ_curr_recal_committed_amt, 0)
6104                                                          + NVL(l_univ_committed_amount, 0);
6105 
6106             ELSIF l_temp_rec.transfer_type = 'TRANSFER' THEN
6107 
6108                IF NVL(p_act_budget_rec.recal_flag,'N') = 'N' THEN
6109 
6110                    l_fund_rec.committed_amt   :=
6111                                  NVL (l_fund_committed_amount, 0)
6112                                - NVL (l_fund_rec.committed_amt, 0);
6113                    -- R12: yzhao ozf_object_fund_summary decrease committed amount
6114                    IF G_DEBUG THEN
6115                    ozf_utility_pvt.debug_message('******************************************************************');
6116                    ozf_utility_pvt.debug_message('committed_amt '||l_objfundsum_rec.committed_amt);
6117                    ozf_utility_pvt.debug_message('approved_amount '||l_temp_rec.approved_amount);
6118                    ozf_utility_pvt.debug_message('plan_curr_committed_amt '||l_objfundsum_rec.plan_curr_committed_amt);
6119                    ozf_utility_pvt.debug_message('approved_original_amount '||l_temp_rec.approved_original_amount);
6120                    ozf_utility_pvt.debug_message('univ_curr_committed_amt '||l_objfundsum_rec.univ_curr_committed_amt);
6121                    ozf_utility_pvt.debug_message('l_univ_committed_amount '||l_univ_committed_amount);
6122                    END IF;
6123                    l_objfundsum_rec.committed_amt := NVL(l_objfundsum_rec.committed_amt, 0)
6124                                                    - NVL (l_temp_rec.approved_amount, 0);
6125                    l_objfundsum_rec.plan_curr_committed_amt := NVL(l_objfundsum_rec.plan_curr_committed_amt, 0)
6126                                                              - NVL(l_temp_rec.approved_original_amount, 0);
6127                    l_objfundsum_rec.univ_curr_committed_amt := NVL(l_objfundsum_rec.univ_curr_committed_amt, 0)
6128                                                              - NVL(l_univ_committed_amount, 0);
6129 
6130                ELSE
6131                   l_fund_rec.committed_amt   :=
6132                                  NVL (l_fund_committed_amount, 0);
6133                END IF;
6134                l_fund_rec.recal_committed   :=
6135                                  NVL (l_fund_recal_committed_amount, 0)
6136                                - NVL (l_temp_rec.approved_amount, 0);
6137                -- R12: yzhao ozf_object_fund_summary decrease recal-committed amount
6138                l_objfundsum_rec.recal_committed_amt := NVL(l_objfundsum_rec.recal_committed_amt, 0)
6139                                                      - NVL (l_temp_rec.approved_amount, 0);
6140                l_objfundsum_rec.plan_curr_recal_committed_amt := NVL(l_objfundsum_rec.plan_curr_recal_committed_amt, 0)
6141                                                          - NVL(l_temp_rec.approved_original_amount, 0);
6142                l_objfundsum_rec.univ_curr_recal_committed_amt := NVL(l_objfundsum_rec.univ_curr_recal_committed_amt, 0)
6143                                                          - NVL(l_univ_committed_amount, 0);
6144                -- R12: yzhao END ozf_object_fund_summary decrease committed amount
6145             END IF;
6146 
6147             IF G_DEBUG THEN
6148                ozf_utility_pvt.debug_message ('bef update fund ');
6149             END IF;
6150 
6151             --Added for bug 7425189, use these 3 columns in fund API to disttinguish the
6152             --call from reconcile API.
6153             IF p_act_budget_rec.justification IN (l_fund_reconc_msg,l_act_bud_cst_msg)
6154             AND p_act_budget_rec.exchange_rate_date IS NOT NULL THEN
6155                 --l_fund_rec.exchange_rate_date := p_act_budget_rec.exchange_rate_date;
6156                 l_fund_rec.description := p_act_budget_rec.justification;
6157                 l_fund_rec.fund_usage := 'TRANSFER';
6158             END IF;
6159 
6160             --bug 8532055
6161             l_fund_rec.exchange_rate_date := p_act_budget_rec.exchange_rate_date;
6162 
6163           -- For Bug#8867381, introduced p_use_fund_staging_tables for staging table impln of chargeback flow
6164           -- and p_resale_batch_id of the batch affected.
6165           -- and px_ozf_funds_old_rectype for taking the funds old values
6166           -- For TPA Parallel Execution ER Bug#9614703
6167           -- and changed px_ozf_funds_new_rectype to px_ozf_funds_new_tbl.
6168 
6169                 ozf_funds_pvt.update_fund (
6170                        p_api_version=> 1.0
6171                       ,p_init_msg_list=> fnd_api.g_false
6172                       ,p_commit=> fnd_api.g_false
6173                       ,p_validation_level=> fnd_api.g_valid_level_full
6174                       ,x_return_status=> l_return_status
6175                       ,x_msg_count=> x_msg_count
6176                       ,x_msg_data=> x_msg_data
6177                       ,p_fund_rec=> l_fund_rec
6178                       ,p_mode=> g_cons_fund_mode
6179               ,p_resale_batch_id => p_resale_batch_id
6180               ,p_batch_type          =>    p_batch_type
6181               ,p_use_fund_staging_tables => p_use_fund_staging_tables
6182               ,px_ozf_funds_old_rectype =>      px_ozf_funds_old_rectype
6183               ,px_ozf_funds_new_tbl     =>      px_ozf_funds_new_tbl  -- For TPA Parallel Execution ER Bug#9614703
6184                     );
6185 
6186             IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6187                RAISE fnd_api.g_exc_unexpected_error;
6188             ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
6189                RAISE fnd_api.g_exc_error;
6190             END IF;
6191 
6192             -- R12: yzhao ozf_object_fund_summary update planned_amount/committed_amount
6193 
6194 
6195                IF l_objfundsum_rec.objfundsum_id IS NULL THEN
6196                   l_objfundsum_rec.fund_id := l_temp_rec.budget_source_id;
6197                   l_objfundsum_rec.fund_currency := l_temp_rec.approved_in_currency;
6198                   l_objfundsum_rec.object_type := l_temp_rec.arc_act_budget_used_by;
6199                   l_objfundsum_rec.object_id := l_temp_rec.act_budget_used_by_id;
6200                   l_objfundsum_rec.object_currency := l_temp_rec.request_currency;
6201 
6202 
6203                   IF l_temp_rec.parent_source_id is NOT NULL THEN
6204                      l_objfundsum_rec.reference_object_id := l_temp_rec.parent_source_id;
6205                      l_objfundsum_rec.source_from_parent := 'Y';
6206                      IF l_objfundsum_rec.object_type ='OFFR' OR
6207                         l_objfundsum_rec.object_type = 'CSCH' THEN
6208                         l_objfundsum_rec.reference_object_type := 'CAMP';
6209                      ELSIF l_objfundsum_rec.object_type = 'EVEO' THEN
6210                         l_objfundsum_rec.reference_object_type := 'EVEH';
6211                      END IF;
6212                   END IF;
6213 
6214                   ozf_objfundsum_pvt.create_objfundsum(
6215                        p_api_version                => 1.0,
6216                        p_init_msg_list              => Fnd_Api.G_FALSE,
6217                        p_validation_level           => Fnd_Api.G_VALID_LEVEL_NONE,
6218                        p_objfundsum_rec             => l_objfundsum_rec,
6219                        p_conv_date                  => p_act_budget_rec.exchange_rate_date, --bug 8532055
6220                        x_return_status              => l_return_status,
6221                        x_msg_count                  => x_msg_count,
6222                        x_msg_data                   => x_msg_data,
6223                        x_objfundsum_id              => l_objfundsum_id
6224                   );
6225                ELSE
6226 
6227                   IF G_DEBUG THEN
6228                      ozf_utility_pvt.debug_message('committed_amt '||l_objfundsum_rec.committed_amt);
6229                      ozf_utility_pvt.debug_message('plan_curr_committed_amt '||l_objfundsum_rec.plan_curr_committed_amt);
6230                      ozf_utility_pvt.debug_message('univ_curr_committed_amt '||l_objfundsum_rec.univ_curr_committed_amt);
6231                      ozf_utility_pvt.debug_message('******************************************************************');
6232                   END IF;
6233 
6234                  /* Obj_fundsum changes */
6235                   IF p_use_fund_staging_tables <> 'T' THEN
6236 
6237                   ozf_objfundsum_pvt.update_objfundsum(
6238                        p_api_version                => 1.0,
6239                        p_init_msg_list              => Fnd_Api.G_FALSE,
6240                        p_validation_level           => Fnd_Api.G_VALID_LEVEL_NONE,
6241                        p_objfundsum_rec             => l_objfundsum_rec,
6242                        p_conv_date                  => p_act_budget_rec.exchange_rate_date, --bug 7425189, 8532055
6243                        x_return_status              => l_return_status,
6244                        x_msg_count                  => x_msg_count,
6245                        x_msg_data                   => x_msg_data
6246                   );
6247 
6248                   END IF;
6249 
6250                 /*
6251                 --Added for bug 7425189, call this private API, only meant for budget reconcile.
6252                 IF p_act_budget_rec.justification IN (l_fund_reconc_msg,l_act_bud_cst_msg)
6253                   AND p_act_budget_rec.exchange_rate_date IS NOT NULL THEN
6254                   IF G_DEBUG THEN
6255                     ozf_utility_pvt.debug_message('committed_amt '||l_objfundsum_rec.committed_amt);
6256                    ozf_utility_pvt.debug_message('plan_curr_committed_amt '||l_objfundsum_rec.plan_curr_committed_amt);
6257                    ozf_utility_pvt.debug_message('univ_curr_committed_amt '||l_objfundsum_rec.univ_curr_committed_amt);
6258                    ozf_utility_pvt.debug_message('******************************************************************');
6259                     END IF;
6260                    update_reconcile_objfundsum(
6261                    p_api_version                => 1.0,
6262                    p_init_msg_list              => Fnd_Api.G_FALSE,
6263                    p_validation_level           => Fnd_Api.G_VALID_LEVEL_NONE,
6264                    p_objfundsum_rec             => l_objfundsum_rec,
6265                    p_conv_date                  => p_act_budget_rec.exchange_rate_date,
6266                    x_return_status              => l_return_status,
6267                    x_msg_count                  => x_msg_count,
6268                    x_msg_data                   => x_msg_data
6269                    );
6270                 ELSE
6271                   ozf_objfundsum_pvt.update_objfundsum(
6272                    p_api_version                => 1.0,
6273                    p_init_msg_list              => Fnd_Api.G_FALSE,
6274                    p_validation_level           => Fnd_Api.G_VALID_LEVEL_NONE,
6275                    p_objfundsum_rec             => l_objfundsum_rec,
6276                    x_return_status              => l_return_status,
6277                    x_msg_count                  => x_msg_count,
6278                    x_msg_data                   => x_msg_data
6279                    );
6280                 END IF;
6281                 */
6282              END IF;
6283 
6284 
6285             IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6286                RAISE fnd_api.g_exc_unexpected_error;
6287             ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
6288                RAISE fnd_api.g_exc_error;
6289             END IF;
6290             -- R12: yzhao END ozf_object_fund_summary decrease planned_amount/committed_amount
6291 
6292          END IF; -- end for fund check
6293       ELSE
6294          NULL;
6295       END IF; -- for fund transfer flag check
6296 
6297       x_act_budget_rec           := l_temp_rec;
6298       IF G_DEBUG THEN
6299          ozf_utility_pvt.debug_message (   g_package_name
6300                                      || '.'
6301                                      || l_api_name
6302                                      || ': end');
6303       END IF;
6304    END process_approval;
6305 
6306 /*****************************************************************************************/
6307 -- Start of Comments
6308    --
6309    -- NAME
6310    --    Revert_Approval
6311    -- PURPOSE
6312    --    Revert the changes done when a budget line is
6313    --    submitted for approval.  For FUND lines, revert
6314    --    the planned amount.
6315    -- HISTORY
6316    -- 17-Sep-2000 choang   created.
6317 /*****************************************************************************************/
6318    PROCEDURE revert_approval (
6319       p_act_budget_rec   IN       act_budgets_rec_type
6320      ,p_use_fund_staging_tables IN VARCHAR2
6321      ,x_act_budget_rec   OUT NOCOPY      act_budgets_rec_type
6322      ,x_return_status    OUT NOCOPY      VARCHAR2
6323      ,x_msg_count        OUT NOCOPY      NUMBER
6324      ,x_msg_data         OUT NOCOPY      VARCHAR2
6325    ) IS
6326       l_return_status                VARCHAR2 (1);
6327       l_temp_rec                     act_budgets_rec_type        := p_act_budget_rec;
6328       l_fund_rec                     ozf_funds_pvt.fund_rec_type;
6329       l_fund_object_version_number   NUMBER;
6330       l_fund_currency_tc             VARCHAR2 (15); -- a fund's transactional currency code
6331       l_fund_planned_amount          NUMBER;
6332       l_univ_planned_amount          NUMBER;
6333       l_objfundsum_rec               ozf_objfundsum_pvt.objfundsum_rec_type := NULL;
6334 
6335       CURSOR c_fund (l_fund_id IN NUMBER) IS
6336          SELECT object_version_number, currency_code_tc, planned_amt
6337            FROM ozf_funds_all_b
6338           WHERE fund_id = l_fund_id;
6339 
6340       -- yzhao: R12 update ozf_object_fund_summary table
6341       CURSOR c_get_objfundsum_rec(p_object_type IN VARCHAR2, p_object_id IN NUMBER, p_fund_id IN NUMBER) IS
6342          SELECT objfundsum_id
6343               , object_version_number
6344               , planned_amt
6345               , plan_curr_planned_amt
6346               , univ_curr_planned_amt
6347          FROM   ozf_object_fund_summary
6348          WHERE  object_type = p_object_type
6349          AND    object_id = p_object_id
6350          AND    fund_id = p_fund_id;
6351 
6352    BEGIN
6353       l_temp_rec.status_code     := 'NEW';
6354       l_temp_rec.comment     := p_act_budget_rec.comment;
6355 
6356       --- fix bug 4174002  to exclude budget transfer since not planned_amt  exists for pending status.
6357       IF l_temp_rec.budget_source_type = 'FUND'  AND l_temp_rec.arc_act_budget_used_by <> 'FUND' THEN
6358          -- if the budget source is a fund, then the
6359          -- fund's planned amount must be incremented
6360          -- by the request_amount during approval
6361          -- submission.
6362          ozf_funds_pvt.init_fund_rec (l_fund_rec);
6363          OPEN c_fund (l_temp_rec.budget_source_id);
6364          FETCH c_fund INTO l_fund_object_version_number, l_fund_currency_tc, l_fund_planned_amount;
6365          CLOSE c_fund;
6366          l_fund_rec.fund_id         := l_temp_rec.budget_source_id;
6367          l_fund_rec.object_version_number := l_fund_object_version_number;
6368 
6369          IF l_temp_rec.request_currency = l_fund_currency_tc THEN
6370             -- don't need to convert if currencies are equal
6371             l_fund_rec.planned_amt     := l_temp_rec.request_amount;
6372          ELSE
6373             -- convert the request amount to the fund's
6374             -- currency.  the planned amount for a fund
6375             -- is stored in the table as a value based
6376             -- on the transactional currency, so the
6377             -- request amount must also be based on the
6378             -- same currency.
6379             ozf_utility_pvt.convert_currency (
6380                x_return_status=> l_return_status
6381               ,p_from_currency=> l_temp_rec.request_currency
6382               ,p_to_currency=> l_fund_currency_tc
6383               ,p_from_amount=> l_temp_rec.request_amount
6384               ,x_to_amount=> l_fund_rec.planned_amt
6385             );
6386 
6387             IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6388                RAISE fnd_api.g_exc_unexpected_error;
6389             ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
6390                RAISE fnd_api.g_exc_error;
6391             END IF;
6392          END IF;
6393 
6394          -- R12: yzhao ozf_object_fund_summary decrease planned_amt
6395          OPEN c_get_objfundsum_rec(l_temp_rec.arc_act_budget_used_by
6396                                  , l_temp_rec.act_budget_used_by_id
6397                                  , l_temp_rec.budget_source_id);
6398          FETCH c_get_objfundsum_rec INTO l_objfundsum_rec.objfundsum_id
6399                                        , l_objfundsum_rec.object_version_number
6400                                        , l_objfundsum_rec.planned_amt
6401                                        , l_objfundsum_rec.plan_curr_planned_amt
6402                                        , l_objfundsum_rec.univ_curr_planned_amt;
6403          IF c_get_objfundsum_rec%NOTFOUND THEN
6404             CLOSE c_get_objfundsum_rec;
6405             IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_error) THEN
6406                fnd_message.set_name('OZF', 'OZF_OBJFUNDSUM_RECORD_NOT_FOUND');
6407                fnd_msg_pub.add;
6408             END IF;
6409             RAISE fnd_api.g_exc_error;
6410          END IF;
6411          CLOSE c_get_objfundsum_rec;
6412          IF g_universal_currency = l_temp_rec.request_currency THEN
6413             l_univ_planned_amount := l_temp_rec.request_amount;
6414          ELSIF g_universal_currency = l_fund_currency_tc THEN
6415             l_univ_planned_amount := l_fund_rec.planned_amt;
6416          ELSE
6417             ozf_utility_pvt.convert_currency (
6418                   x_return_status=> l_return_status
6419                  ,p_from_currency=> l_temp_rec.request_currency
6420                  ,p_to_currency=> g_universal_currency
6421                  ,p_from_amount=> l_temp_rec.request_amount
6422                  ,x_to_amount=> l_univ_planned_amount
6423             );
6424             IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6425                RAISE fnd_api.g_exc_unexpected_error;
6426             ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
6427                RAISE fnd_api.g_exc_error;
6428             END IF;
6429          END IF;
6430 
6431           IF p_use_fund_staging_tables <> 'T' THEN
6432 
6433                  l_objfundsum_rec.planned_amt := NVL(l_objfundsum_rec.planned_amt, 0) - NVL(l_fund_rec.planned_amt, 0);
6434                  l_objfundsum_rec.plan_curr_planned_amt := NVL(l_objfundsum_rec.plan_curr_planned_amt, 0)
6435                                                          - NVL(l_temp_rec.request_amount, 0);
6436                  l_objfundsum_rec.univ_curr_planned_amt := NVL(l_objfundsum_rec.univ_curr_planned_amt, 0)
6437                                                          - NVL(l_univ_planned_amount, 0);
6438                  ozf_objfundsum_pvt.update_objfundsum(
6439                            p_api_version                => 1.0,
6440                            p_init_msg_list              => Fnd_Api.G_FALSE,
6441                            p_validation_level           => Fnd_Api.G_VALID_LEVEL_NONE,
6442                            p_objfundsum_rec             => l_objfundsum_rec,
6443                            x_return_status              => l_return_status,
6444                            x_msg_count                  => x_msg_count,
6445                            x_msg_data                   => x_msg_data
6446                  );
6447                  IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6448                     RAISE fnd_api.g_exc_unexpected_error;
6449                  ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
6450                     RAISE fnd_api.g_exc_error;
6451                  END IF;
6452                  -- R12: yzhao END ozf_object_fund_summary decrease planned amount
6453           END IF;
6454 
6455          -- subtract the request amount, l_fund_rec.planned_amt, from the
6456          -- fund's planned amount, l_fund_planned_amount.
6457          l_fund_rec.planned_amt     :=
6458                                       NVL (l_fund_planned_amount, 0)
6459                                     - NVL (l_fund_rec.planned_amt, 0);
6460          ozf_funds_pvt.update_fund (
6461             p_api_version=> 1.0
6462            ,p_init_msg_list=> fnd_api.g_false
6463            , -- allow the calling API to handle
6464             p_commit=> fnd_api.g_false
6465            , -- allow the calling API to handle
6466             p_validation_level=> fnd_api.g_valid_level_full
6467            ,x_return_status=> l_return_status
6468            ,x_msg_count=> x_msg_count
6469            ,x_msg_data=> x_msg_data
6470            ,p_fund_rec=> l_fund_rec
6471            ,p_mode=> g_cons_fund_mode
6472          );
6473 
6474          IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6475             RAISE fnd_api.g_exc_unexpected_error;
6476          ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
6477             RAISE fnd_api.g_exc_error;
6478          END IF;
6479       END IF; -- if source type = FUND
6480 
6481       x_act_budget_rec           := l_temp_rec;
6482    END revert_approval;
6483 
6484 
6485 
6486 ---------------------------------------------------------------------
6487 -- PROCEDURE
6488 --    create_child_act_budget
6489 --
6490 -- PURPOSE
6491 --This API will be called by create_act_budgets and updat_act_budgets to create
6492 -- child budget requests when sourcing from parent.
6493 
6494 -- PARAMETERS
6495 --      x_return_status     OUT NOCOPY      VARCHAR2,
6496 --      x_msg_count         OUT NOCOPY      NUMBER,
6497 --      x_msg_data          OUT NOCOPY      VARCHAR2,
6498 --      p_act_budgets_rec   IN       ozf_actbudgets_pvt.act_budgets_rec_type
6499 
6500 -- NOTES
6501 -- HISTORY
6502 --    09/24/2002  feliu  Create.
6503 ----------------------------------------------------------------------
6504 
6505 PROCEDURE  create_child_act_budget (
6506       x_return_status      OUT NOCOPY      VARCHAR2,
6507       x_msg_count          OUT NOCOPY      NUMBER,
6508       x_msg_data           OUT NOCOPY      VARCHAR2,
6509       p_act_budgets_rec    IN       ozf_actbudgets_pvt.act_budgets_rec_type,
6510       p_exchange_rate_type IN VARCHAR2 DEFAULT FND_API.G_MISS_CHAR
6511    ) IS
6512 
6513       l_return_status             VARCHAR2 (10)                           := fnd_api.g_ret_sts_success;
6514       l_api_name         CONSTANT VARCHAR2 (30)                           := 'create_child_act_budget';
6515       l_api_version      CONSTANT NUMBER                                  := 1.0;
6516       l_msg_data               VARCHAR2 (2000);
6517       l_msg_count              NUMBER;
6518       l_full_name        CONSTANT VARCHAR2 (90)                           :=    g_package_name
6519                                                                              || '.'
6520                                                                              || l_api_name;
6521       l_acctd_amount      NUMBER;
6522       l_total_amount      NUMBER; -- campaign currency
6523       l_amount            NUMBER;
6524       l_converted_amt     NUMBER;
6525       l_amount_remaining  NUMBER   := p_act_budgets_rec.approved_amount;
6526       l_obj_currency      VARCHAR2 (30) := p_act_budgets_rec.request_currency; -- object currency.
6527       l_obj_id            NUMBER;  -- campaign currency
6528       l_act_budgets_rec           ozf_actbudgets_pvt.act_budgets_rec_type;
6529       l_act_util_rec          ozf_actbudgets_pvt.act_util_rec_type ;
6530       l_act_budget_id     NUMBER;
6531       l_rate              NUMBER;
6532       l_obj_type          VARCHAR2(30);
6533 
6534 --nirprasa, fix for bug 8938326. p_obj_type can have values CAMP and EVEH both. So removed the hardcoded
6535       --value CAMP from both the cursors.
6536       CURSOR c_parent_source (p_object_id IN NUMBER, p_obj_type IN VARCHAR2) IS
6537         SELECT fund_id
6538                ,fund_currency
6539                ,NVL(committed_amt,0)-NVL(utilized_amt,0) total_amount
6540                ,NVL(univ_curr_committed_amt,0) total_acctd_amount
6541         FROM ozf_object_fund_summary
6542         WHERE object_id =p_object_id
6543         AND object_type = p_obj_type;
6544 
6545      CURSOR c_total_acct_amt (p_object_id IN NUMBER, p_obj_type IN VARCHAR2) IS
6546         SELECT SUM(NVL(univ_curr_committed_amt,0))
6547         FROM ozf_object_fund_summary
6548         WHERE object_id =p_object_id
6549         AND object_type = p_obj_type;
6550 
6551    BEGIN
6552 
6553       SAVEPOINT create_child_act_budget;
6554 
6555       IF G_DEBUG THEN
6556          ozf_utility_pvt.debug_message (   l_full_name || ': start');
6557       END IF;
6558 
6559       x_return_status            := fnd_api.g_ret_sts_success;
6560 
6561     /*  IF fnd_api.to_boolean (p_init_msg_list) THEN
6562          fnd_msg_pub.initialize;
6563       END IF;
6564 
6565       IF NOT fnd_api.compatible_api_call (l_api_version, p_api_version, l_api_name, g_pkg_name) THEN
6566          RAISE fnd_api.g_exc_unexpected_error;
6567       END IF;
6568 */
6569 
6570       l_act_budgets_rec.transfer_type := p_act_budgets_rec.transfer_type;
6571 
6572       IF l_act_budgets_rec.transfer_type = 'REQUEST' THEN
6573          l_obj_id := p_act_budgets_rec.budget_source_id;
6574          l_obj_type := p_act_budgets_rec.budget_source_type; --fix for bug 8938326
6575          l_total_amount := p_act_budgets_rec.approved_amount;
6576          l_obj_currency := p_act_budgets_rec.request_currency;
6577       ELSE
6578          l_obj_id := p_act_budgets_rec.act_budget_used_by_id;
6579          l_obj_type := p_act_budgets_rec.arc_act_budget_used_by;
6580          l_total_amount := p_act_budgets_rec.approved_original_amount;
6581          l_obj_currency := p_act_budgets_rec.approved_in_currency;
6582      END IF;
6583 
6584       l_act_budgets_rec.parent_source_id := l_obj_id;
6585       l_act_budgets_rec.parent_act_budget_id := p_act_budgets_rec.activity_budget_id;
6586 
6587       IF G_DEBUG THEN
6588          ozf_utility_pvt.debug_message (   ': l_total_amount: ' || l_total_amount );
6589       END IF;
6590 
6591       OPEN c_total_acct_amt(l_obj_id,l_obj_type); --fix for bug 8938326
6592       FETCH c_total_acct_amt INTO l_acctd_amount;
6593       CLOSE c_total_acct_amt;
6594 
6595       FOR l_budget_util_rec IN c_parent_source(l_obj_id, l_obj_type) LOOP --fix for bug 8938326
6596 
6597           EXIT WHEN c_parent_source%NOTFOUND;
6598 
6599           l_amount := ozf_utility_pvt.currround(l_budget_util_rec.total_acctd_amount / l_acctd_amount * l_total_amount, l_obj_currency);
6600 
6601           l_amount_remaining :=l_amount_remaining - l_amount;
6602 
6603           IF l_budget_util_rec.fund_currency <> l_obj_currency THEN
6604 
6605 
6606           --Added for bug 7030415, This code gets executed when offer sources from Campaign.
6607              ozf_utility_pvt.convert_currency (
6608                       x_return_status=> x_return_status
6609                      ,p_from_currency=> l_obj_currency
6610                      ,p_to_currency=> l_budget_util_rec.fund_currency
6611                      ,p_conv_type=> p_exchange_rate_type
6612                      ,p_from_amount=> l_amount
6613                      ,x_to_amount=> l_converted_amt
6614                      ,x_rate=> l_rate
6615                      );
6616           ELSE
6617             l_converted_amt := l_amount;
6618           END IF;
6619 
6620           IF G_DEBUG THEN
6621              ozf_utility_pvt.debug_message (   l_full_name || ': l_amount: ' || l_amount);
6622              ozf_utility_pvt.debug_message (   l_full_name || ': l_converted_amt' || l_converted_amt);
6623           END IF;
6624 
6625           IF l_act_budgets_rec.transfer_type = 'REQUEST' THEN
6626              l_act_budgets_rec.budget_source_type := 'FUND';
6627              l_act_budgets_rec.budget_source_id := l_budget_util_rec.fund_id;
6628              l_act_budgets_rec.act_budget_used_by_id := p_act_budgets_rec.act_budget_used_by_id;
6629              l_act_budgets_rec.arc_act_budget_used_by := p_act_budgets_rec.arc_act_budget_used_by;
6630              l_act_budgets_rec.request_amount := l_amount; -- in object currency.
6631              l_act_budgets_rec.request_currency := l_obj_currency;
6632              l_act_budgets_rec.approved_in_currency := l_budget_util_rec.fund_currency;
6633              l_act_budgets_rec.approved_original_amount :=l_converted_amt;
6634        ELSE
6635              l_act_budgets_rec.arc_act_budget_used_by := 'FUND';
6636              l_act_budgets_rec.act_budget_used_by_id := l_budget_util_rec.fund_id;
6637              l_act_budgets_rec.budget_source_id := p_act_budgets_rec.budget_source_id;
6638              l_act_budgets_rec.budget_source_type := p_act_budgets_rec.budget_source_type;
6639              l_act_budgets_rec.request_amount := l_converted_amt; -- in object currency.
6640              l_act_budgets_rec.request_currency := l_budget_util_rec.fund_currency;
6641              l_act_budgets_rec.approved_in_currency := l_obj_currency;
6642              l_act_budgets_rec.approved_original_amount :=l_amount;
6643        END IF;
6644 
6645          l_act_budgets_rec.status_code := 'APPROVED';
6646          l_act_budgets_rec.request_date := SYSDATE;
6647          l_act_budgets_rec.user_status_id :=
6648                                          ozf_utility_pvt.get_default_user_status (
6649                                              'OZF_BUDGETSOURCE_STATUS'
6650                                              ,l_act_budgets_rec.status_code
6651                                             );
6652          l_act_budgets_rec.approval_date := SYSDATE;
6653          l_act_budgets_rec.approver_id :=  ozf_utility_pvt.get_resource_id (fnd_global.user_id);
6654          l_act_budgets_rec.requester_id := ozf_utility_pvt.get_resource_id (fnd_global.user_id);
6655 
6656          ozf_actbudgets_pvt.create_act_budgets (
6657            p_api_version=> l_api_version
6658           ,x_return_status=> l_return_status
6659           ,x_msg_count=> l_msg_count
6660           ,x_msg_data=> l_msg_data
6661           ,p_act_budgets_rec=> l_act_budgets_rec
6662           ,p_act_util_rec=> l_act_util_rec
6663           ,x_act_budget_id=> l_act_budget_id
6664           ,p_approval_flag=> fnd_api.g_true
6665          );
6666 
6667 
6668          IF NOT (l_return_status = fnd_api.g_ret_sts_success) THEN
6669              ROLLBACK TO create_child_act_budget;
6670              fnd_msg_pub.count_and_get (
6671               p_count=> x_msg_count
6672              ,p_data=> x_msg_data
6673              ,p_encoded=> fnd_api.g_false
6674              );
6675          END IF;
6676 
6677          IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6678             RAISE fnd_api.g_exc_unexpected_error;
6679          ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
6680             RAISE fnd_api.g_exc_error;
6681          END IF;
6682 
6683          EXIT WHEN l_amount_remaining <= 0;
6684 
6685 
6686       END LOOP;
6687 
6688        fnd_msg_pub.count_and_get (
6689          p_encoded=> fnd_api.g_false
6690         ,p_count=> x_msg_count
6691         ,p_data=> x_msg_data
6692       );
6693 
6694 
6695       IF G_DEBUG THEN
6696          ozf_utility_pvt.debug_message (   l_full_name
6697                                      || ': end');
6698       END IF;
6699 
6700   EXCEPTION
6701       WHEN fnd_api.g_exc_error THEN
6702          ROLLBACK TO create_child_act_budget;
6703          x_return_status            := fnd_api.g_ret_sts_error;
6704          fnd_msg_pub.count_and_get (
6705             p_count=> x_msg_count
6706            ,p_data=> x_msg_data
6707            ,p_encoded=> fnd_api.g_false
6708          );
6709       WHEN fnd_api.g_exc_unexpected_error THEN
6710          ROLLBACK TO create_child_act_budget;
6711          x_return_status            := fnd_api.g_ret_sts_unexp_error;
6712          fnd_msg_pub.count_and_get (
6713             p_count=> x_msg_count
6714            ,p_data=> x_msg_data
6715            ,p_encoded=> fnd_api.g_false
6716          );
6717       WHEN OTHERS THEN
6718          ROLLBACK TO create_child_act_budget;
6719          x_return_status            := fnd_api.g_ret_sts_unexp_error;
6720 
6721          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error) THEN
6722             fnd_msg_pub.add_exc_msg (g_package_name, l_api_name);
6723          END IF;
6724 
6725          fnd_msg_pub.count_and_get (
6726             p_count=> x_msg_count
6727            ,p_data=> x_msg_data
6728            ,p_encoded=> fnd_api.g_false
6729          );
6730 
6731     END create_child_act_budget;
6732 
6733 /*commented for bug 8532055
6734 -- nirprasa, Added for bug 7425189
6735 -- NAME
6736 --    complete_amount_fields
6737 --
6738 -- PURPOSE
6739 --    This Procedure fills in amount in fund/object/universal currency if not passed in
6740 --        x_amount_1           converted amount in p_currency_1
6741 --        x_amount_2           converted amount in p_currency_2
6742 --        x_amount_3           converted amount in universal_currency
6743 --     Its accepts conversion date
6744 --
6745 -- NOTES
6746 --
6747 -- HISTORY
6748 --
6749 PROCEDURE complete_amount_fields (
6750    p_currency_1                 IN  VARCHAR2,
6751    p_amount_1                   IN  NUMBER,
6752    p_currency_2                 IN  VARCHAR2,
6753    p_conv_date                  IN  DATE,
6754    p_amount_2                   IN  NUMBER,
6755    p_amount_3                   IN  NUMBER,
6756    x_amount_1                   OUT NOCOPY NUMBER,
6757    x_amount_2                   OUT NOCOPY NUMBER,
6758    x_amount_3                   OUT NOCOPY NUMBER,
6759    x_return_status              OUT NOCOPY VARCHAR2,
6760    x_msg_count                  OUT NOCOPY NUMBER,
6761    x_msg_data                   OUT NOCOPY VARCHAR2
6762 )
6763 IS
6764   l_return_status               VARCHAR2(30);
6765 BEGIN
6766    x_amount_1 := p_amount_1;
6767    x_amount_2 := p_amount_2;
6768    x_amount_3 := p_amount_3;
6769 
6770 
6771 
6772    IF NVL(p_amount_1, 0) <> 0 THEN
6773       IF NVL(p_amount_2, 0) = 0 THEN
6774           -- fill in amount 2 from amount 1
6775           IF p_currency_1 = p_currency_2 THEN
6776              x_amount_2 := p_amount_1;
6777           ELSE
6778              ozf_utility_pvt.convert_currency (
6779                      x_return_status=> l_return_status
6780                     ,p_from_currency=> p_currency_1
6781                     ,p_to_currency=> p_currency_2
6782                     ,p_conv_date=> p_conv_date
6783                     ,p_from_amount=> p_amount_1
6784                     ,x_to_amount=> x_amount_2
6785              );
6786              IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6787                 RAISE fnd_api.g_exc_unexpected_error;
6788              ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
6789                 RAISE fnd_api.g_exc_error;
6790              END IF;
6791           END IF;
6792       END IF;
6793 
6794       IF NVL(p_amount_3, 0) = 0 THEN
6795           -- fill in amount in universal currency from amount 1
6796           IF g_universal_currency = p_currency_1 THEN
6797              x_amount_3 := p_amount_1;
6798           ELSE
6799              ozf_utility_pvt.convert_currency (
6800                      x_return_status=> l_return_status
6801                     ,p_from_currency=> p_currency_1
6802                     ,p_to_currency=> g_universal_currency
6803                     ,p_conv_date=> p_conv_date
6804                     ,p_from_amount=> p_amount_1
6805                     ,x_to_amount=> x_amount_3
6806              );
6807              IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6808                 RAISE fnd_api.g_exc_unexpected_error;
6809              ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
6810                 RAISE fnd_api.g_exc_error;
6811              END IF;
6812           END IF;
6813       END IF;
6814    ELSE
6815       IF NVL(p_amount_2, 0) <> 0 THEN
6816           -- fill in amount 1 from amount 2
6817           IF p_currency_1 = p_currency_2 THEN
6818              x_amount_1 := p_amount_2;
6819           ELSE
6820              ozf_utility_pvt.convert_currency (
6821                      x_return_status=> l_return_status
6822                     ,p_from_currency=> p_currency_2
6823                     ,p_to_currency=> p_currency_1
6824                     ,p_conv_date=> p_conv_date
6825                     ,p_from_amount=> p_amount_2
6826                     ,x_to_amount=> x_amount_1
6827              );
6828              IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6829                 RAISE fnd_api.g_exc_unexpected_error;
6830              ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
6831                 RAISE fnd_api.g_exc_error;
6832              END IF;
6833           END IF;
6834 
6835           IF NVL(p_amount_3, 0) = 0 THEN
6836               -- fill in amount in universal currency from amount 2
6837               IF g_universal_currency = p_currency_2 THEN
6838                  x_amount_3 := p_amount_2;
6839               ELSE
6840                  ozf_utility_pvt.convert_currency (
6841                          x_return_status=> l_return_status
6842                         ,p_from_currency=> p_currency_2
6843                         ,p_to_currency=> g_universal_currency
6844                         ,p_conv_date=> p_conv_date
6845                         ,p_from_amount=> p_amount_2
6846                         ,x_to_amount=> x_amount_3
6847                  );
6848                  IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6849                     RAISE fnd_api.g_exc_unexpected_error;
6850                  ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
6851                     RAISE fnd_api.g_exc_error;
6852                  END IF;
6853               END IF;
6854           END IF;
6855       END IF;
6856    END IF;
6857 END complete_amount_fields;
6858 
6859 
6860 --nirprasa, Added for bug 7425189,
6861 -- NAME
6862 --    update_reconcile_objfundsum
6863 --
6864 -- PURPOSE
6865 --    This Procedure updates record in object fund summary table
6866 --    for offer's budget reconcile. This API is same as update_objfundsum
6867 --    except it accepts conversion date.
6868 -- NOTES
6869 --
6870 -- HISTORY
6871 
6872 PROCEDURE update_reconcile_objfundsum (
6873    p_api_version                IN  NUMBER,
6874    p_init_msg_list              IN  VARCHAR2 := Fnd_Api.G_FALSE,
6875    p_validation_level           IN  NUMBER := Fnd_Api.G_VALID_LEVEL_FULL,
6876    p_objfundsum_rec             IN  OZF_OBJFUNDSUM_PVT.objfundsum_rec_type,
6877    p_conv_date                  IN  DATE,
6878    x_return_status              OUT NOCOPY VARCHAR2,
6879    x_msg_count                  OUT NOCOPY NUMBER,
6880    x_msg_data                   OUT NOCOPY VARCHAR2
6881 )
6882 IS
6883    G_PKG_NAME CONSTANT VARCHAR2(30) := 'OZF_ACTBUDGETS_PVT';
6884    L_API_VERSION    CONSTANT NUMBER := 1.0;
6885    L_API_NAME       CONSTANT VARCHAR2(30) := 'update_reconcile_objfundsum';
6886    L_FULL_NAME      CONSTANT VARCHAR2(60) := g_pkg_name ||'.'|| l_api_name;
6887 
6888    l_return_status   VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
6889    l_objfundsum_rec  OZF_OBJFUNDSUM_PVT.objfundsum_rec_type := p_objfundsum_rec;
6890    l_amount_1                 NUMBER;
6891    l_amount_2                 NUMBER;
6892    l_amount_3                 NUMBER;
6893 
6894 BEGIN
6895 
6896    IF (G_DEBUG) THEN
6897       ozf_utility_pvt.debug_message('Now updating objfundsum_id: '||p_objfundsum_rec.objfundsum_id);
6898    END IF;
6899 
6900    SAVEPOINT sp_update_reconcile_objfundsum;
6901 
6902    IF (G_DEBUG) THEN
6903        ozf_utility_pvt.debug_message(l_full_name||': start');
6904    END IF;
6905 
6906    IF Fnd_Api.To_Boolean (p_init_msg_list) THEN
6907       Fnd_Msg_Pub.Initialize;
6908    END IF;
6909 
6910    IF NOT Fnd_Api.Compatible_API_Call (L_API_VERSION,
6911                                        p_api_version,
6912                                        L_API_NAME,
6913                                        G_PKG_NAME)
6914    THEN
6915       RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
6916    END IF;
6917 
6918    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
6919 
6920    IF (G_DEBUG) THEN
6921       ozf_utility_pvt.debug_message(l_full_name ||': validate');
6922    END IF;
6923 
6924    -- replace g_miss_char/num/date with current column values
6925    OZF_OBJFUNDSUM_PVT.Complete_objfundsum_Rec(p_objfundsum_rec, l_objfundsum_rec);
6926 
6927    -- currency conversion for planned amount
6928    complete_amount_fields (
6929        p_currency_1                 => l_objfundsum_rec.object_currency,
6930        p_amount_1                   => l_objfundsum_rec.plan_curr_planned_amt,
6931        p_currency_2                 => l_objfundsum_rec.fund_currency,
6932        p_amount_2                   => l_objfundsum_rec.planned_amt,
6933        p_amount_3                   => l_objfundsum_rec.univ_curr_planned_amt,
6934        p_conv_date                  => p_conv_date,
6935        x_amount_1                   => l_amount_1,
6936        x_amount_2                   => l_amount_2,
6937        x_amount_3                   => l_amount_3,
6938        x_return_status              => l_return_status,
6939        x_msg_count                  => x_msg_count,
6940        x_msg_data                   => x_msg_data
6941    );
6942 
6943 
6944    IF l_return_status = Fnd_Api.G_RET_STS_ERROR THEN
6945       RAISE Fnd_Api.G_EXC_ERROR;
6946    ELSIF l_return_status = Fnd_Api.G_RET_STS_UNEXP_ERROR THEN
6947       RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
6948    END IF;
6949    l_objfundsum_rec.plan_curr_planned_amt := l_amount_1;
6950    l_objfundsum_rec.planned_amt := l_amount_2;
6951    l_objfundsum_rec.univ_curr_planned_amt := l_amount_3;
6952 
6953 
6954 
6955    -- currency conversion for committed amount
6956    complete_amount_fields (
6957        p_currency_1                 => l_objfundsum_rec.object_currency,
6958        p_amount_1                   => l_objfundsum_rec.plan_curr_committed_amt,
6959        p_currency_2                 => l_objfundsum_rec.fund_currency,
6960        p_amount_2                   => l_objfundsum_rec.committed_amt,
6961        p_amount_3                   => l_objfundsum_rec.univ_curr_committed_amt,
6962        p_conv_date                  => p_conv_date,
6963        x_amount_1                   => l_amount_1,
6964        x_amount_2                   => l_amount_2,
6965        x_amount_3                   => l_amount_3,
6966        x_return_status              => l_return_status,
6967        x_msg_count                  => x_msg_count,
6968        x_msg_data                   => x_msg_data
6969    );
6970    IF l_return_status = Fnd_Api.G_RET_STS_ERROR THEN
6971       RAISE Fnd_Api.G_EXC_ERROR;
6972    ELSIF l_return_status = Fnd_Api.G_RET_STS_UNEXP_ERROR THEN
6973       RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
6974    END IF;
6975 
6976 
6977 
6978    l_objfundsum_rec.plan_curr_committed_amt := l_amount_1;
6979    l_objfundsum_rec.committed_amt := l_amount_2;
6980    l_objfundsum_rec.univ_curr_committed_amt := l_amount_3;
6981 
6982 
6983 
6984    -- currency conversion for recal committed amount
6985    complete_amount_fields (
6986        p_currency_1                 => l_objfundsum_rec.object_currency,
6987        p_amount_1                   => l_objfundsum_rec.plan_curr_recal_committed_amt,
6988        p_currency_2                 => l_objfundsum_rec.fund_currency,
6989        p_amount_2                   => l_objfundsum_rec.recal_committed_amt,
6990        p_amount_3                   => l_objfundsum_rec.univ_curr_recal_committed_amt,
6991        p_conv_date                  => p_conv_date,
6992        x_amount_1                   => l_amount_1,
6993        x_amount_2                   => l_amount_2,
6994        x_amount_3                   => l_amount_3,
6995        x_return_status              => l_return_status,
6996        x_msg_count                  => x_msg_count,
6997        x_msg_data                   => x_msg_data
6998    );
6999    IF l_return_status = Fnd_Api.G_RET_STS_ERROR THEN
7000       RAISE Fnd_Api.G_EXC_ERROR;
7001    ELSIF l_return_status = Fnd_Api.G_RET_STS_UNEXP_ERROR THEN
7002       RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
7003    END IF;
7004    l_objfundsum_rec.plan_curr_recal_committed_amt := l_amount_1;
7005    l_objfundsum_rec.recal_committed_amt := l_amount_2;
7006    l_objfundsum_rec.univ_curr_recal_committed_amt := l_amount_3;
7007 
7008    -- currency conversion for utilized amount
7009    complete_amount_fields (
7010        p_currency_1                 => l_objfundsum_rec.object_currency,
7011        p_amount_1                   => l_objfundsum_rec.plan_curr_utilized_amt,
7012        p_currency_2                 => l_objfundsum_rec.fund_currency,
7013        p_amount_2                   => l_objfundsum_rec.utilized_amt,
7014        p_amount_3                   => l_objfundsum_rec.univ_curr_utilized_amt,
7015        p_conv_date                  => p_conv_date,
7016        x_amount_1                   => l_amount_1,
7017        x_amount_2                   => l_amount_2,
7018        x_amount_3                   => l_amount_3,
7019        x_return_status              => l_return_status,
7020        x_msg_count                  => x_msg_count,
7021        x_msg_data                   => x_msg_data
7022    );
7023    IF l_return_status = Fnd_Api.G_RET_STS_ERROR THEN
7024       RAISE Fnd_Api.G_EXC_ERROR;
7025    ELSIF l_return_status = Fnd_Api.G_RET_STS_UNEXP_ERROR THEN
7026       RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
7027    END IF;
7028 
7029    l_objfundsum_rec.plan_curr_utilized_amt := l_amount_1;
7030    l_objfundsum_rec.utilized_amt := l_amount_2;
7031    l_objfundsum_rec.univ_curr_utilized_amt := l_amount_3;
7032 
7033   -- currency conversion for earned amount
7034    complete_amount_fields (
7035        p_currency_1                 => l_objfundsum_rec.object_currency,
7036        p_amount_1                   => l_objfundsum_rec.plan_curr_earned_amt,
7037        p_currency_2                 => l_objfundsum_rec.fund_currency,
7038        p_amount_2                   => l_objfundsum_rec.earned_amt,
7039        p_amount_3                   => l_objfundsum_rec.univ_curr_earned_amt,
7040        p_conv_date                  => p_conv_date,
7041        x_amount_1                   => l_amount_1,
7042        x_amount_2                   => l_amount_2,
7043        x_amount_3                   => l_amount_3,
7044        x_return_status              => l_return_status,
7045        x_msg_count                  => x_msg_count,
7046        x_msg_data                   => x_msg_data
7047    );
7048    IF l_return_status = Fnd_Api.G_RET_STS_ERROR THEN
7049       RAISE Fnd_Api.G_EXC_ERROR;
7050    ELSIF l_return_status = Fnd_Api.G_RET_STS_UNEXP_ERROR THEN
7051       RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
7052    END IF;
7053    l_objfundsum_rec.plan_curr_earned_amt := l_amount_1;
7054    l_objfundsum_rec.earned_amt := l_amount_2;
7055    l_objfundsum_rec.univ_curr_earned_amt := l_amount_3;
7056 
7057    -- currency conversion for paid amount
7058    complete_amount_fields (
7059        p_currency_1                 => l_objfundsum_rec.object_currency,
7060        p_amount_1                   => l_objfundsum_rec.plan_curr_paid_amt,
7061        p_currency_2                 => l_objfundsum_rec.fund_currency,
7062        p_amount_2                   => l_objfundsum_rec.paid_amt,
7063        p_amount_3                   => l_objfundsum_rec.univ_curr_paid_amt,
7064        p_conv_date                  => p_conv_date,
7065        x_amount_1                   => l_amount_1,
7066        x_amount_2                   => l_amount_2,
7067        x_amount_3                   => l_amount_3,
7068        x_return_status              => l_return_status,
7069        x_msg_count                  => x_msg_count,
7070        x_msg_data                   => x_msg_data
7071    );
7072    IF l_return_status = Fnd_Api.G_RET_STS_ERROR THEN
7073       RAISE Fnd_Api.G_EXC_ERROR;
7074    ELSIF l_return_status = Fnd_Api.G_RET_STS_UNEXP_ERROR THEN
7075       RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
7076    END IF;
7077    l_objfundsum_rec.plan_curr_paid_amt := l_amount_1;
7078    l_objfundsum_rec.paid_amt := l_amount_2;
7079    l_objfundsum_rec.univ_curr_paid_amt := l_amount_3;
7080 
7081    IF p_validation_level >= Jtf_Plsql_Api.g_valid_level_item THEN
7082       OZF_OBJFUNDSUM_PVT.Validate_objfundsum (
7083           p_api_version               => l_api_version,
7084           p_init_msg_list             => p_init_msg_list,
7085           p_validation_level          => p_validation_level,
7086           p_objfundsum_rec            => l_objfundsum_rec,
7087           x_msg_count                 => x_msg_count,
7088           x_msg_data                  => x_msg_data,
7089           x_return_status             => l_return_status
7090       );
7091       IF l_return_status = Fnd_Api.g_ret_sts_unexp_error THEN
7092          RAISE Fnd_Api.g_exc_unexpected_error;
7093       ELSIF l_return_status = Fnd_Api.g_ret_sts_error THEN
7094          RAISE Fnd_Api.g_exc_error;
7095       END IF;
7096    END IF;
7097 
7098 
7099    IF (G_DEBUG) THEN
7100      ozf_utility_pvt.debug_message(l_full_name ||': update object fund summary Table');
7101    END IF;
7102 
7103    UPDATE ozf_object_fund_summary
7104       SET object_version_number= object_version_number + 1,
7105           last_update_date         = SYSDATE,
7106           last_updated_by          = Fnd_Global.User_ID,
7107           last_update_login        = Fnd_Global.Conc_Login_ID,
7108           fund_id                  = l_objfundsum_rec.fund_id,
7109           fund_currency            = l_objfundsum_rec.fund_currency,
7110           object_type              = l_objfundsum_rec.object_type,
7111           object_id                = l_objfundsum_rec.object_id,
7112           object_currency          = l_objfundsum_rec.object_currency,
7113           reference_object_type    = l_objfundsum_rec.reference_object_type,
7114           reference_object_id      = l_objfundsum_rec.reference_object_id,
7115           source_from_parent       = l_objfundsum_rec.source_from_parent,
7116           planned_amt              = l_objfundsum_rec.planned_amt,
7117           committed_amt            = l_objfundsum_rec.committed_amt,
7118           recal_committed_amt      = l_objfundsum_rec.recal_committed_amt,
7119           utilized_amt             = l_objfundsum_rec.utilized_amt,
7120           earned_amt               = l_objfundsum_rec.earned_amt,
7121           paid_amt                 = l_objfundsum_rec.paid_amt,
7122           plan_curr_planned_amt    = l_objfundsum_rec.plan_curr_planned_amt,
7123           plan_curr_committed_amt  = l_objfundsum_rec.plan_curr_committed_amt,
7124           plan_curr_recal_committed_amt  = l_objfundsum_rec.plan_curr_recal_committed_amt,
7125           plan_curr_utilized_amt   = l_objfundsum_rec.plan_curr_utilized_amt,
7126           plan_curr_earned_amt     = l_objfundsum_rec.plan_curr_earned_amt,
7127           plan_curr_paid_amt       = l_objfundsum_rec.plan_curr_paid_amt,
7128           univ_curr_planned_amt    = l_objfundsum_rec.univ_curr_planned_amt,
7129           univ_curr_committed_amt  = l_objfundsum_rec.univ_curr_committed_amt,
7130           univ_curr_recal_committed_amt  = l_objfundsum_rec.univ_curr_recal_committed_amt,
7131           univ_curr_utilized_amt   = l_objfundsum_rec.univ_curr_utilized_amt,
7132           univ_curr_earned_amt     = l_objfundsum_rec.univ_curr_earned_amt,
7133           univ_curr_paid_amt       = l_objfundsum_rec.univ_curr_paid_amt,
7134           attribute_category       = l_objfundsum_rec.attribute_category,
7135           attribute1               = l_objfundsum_rec.attribute1,
7136           attribute2               = l_objfundsum_rec.attribute2,
7137           attribute3               = l_objfundsum_rec.attribute3,
7138           attribute4               = l_objfundsum_rec.attribute4,
7139           attribute5               = l_objfundsum_rec.attribute5,
7140           attribute6               = l_objfundsum_rec.attribute6,
7141           attribute7               = l_objfundsum_rec.attribute7,
7142           attribute8               = l_objfundsum_rec.attribute8,
7143           attribute9               = l_objfundsum_rec.attribute9,
7144           attribute10              = l_objfundsum_rec.attribute10,
7145           attribute11              = l_objfundsum_rec.attribute11,
7146           attribute12              = l_objfundsum_rec.attribute12,
7147           attribute13              = l_objfundsum_rec.attribute13,
7148           attribute14              = l_objfundsum_rec.attribute14,
7149           attribute15              = l_objfundsum_rec.attribute15
7150     WHERE objfundsum_id = l_objfundsum_rec.objfundsum_id
7151     AND   object_version_number = l_objfundsum_rec.object_version_number;
7152 
7153    IF  (SQL%NOTFOUND) THEN
7154       IF Fnd_Msg_Pub.check_msg_level(Fnd_Msg_Pub.g_msg_lvl_error) THEN
7155          Fnd_Message.set_name('OZF', 'OZF_API_RECORD_NOT_FOUND');
7156          Fnd_Msg_Pub.ADD;
7157       END IF;
7158       RAISE Fnd_Api.g_exc_error;
7159    END IF;
7160 
7161    Fnd_Msg_Pub.Count_And_Get (
7162       p_count           =>    x_msg_count,
7163       p_data            =>    x_msg_data,
7164       p_encoded         =>    Fnd_Api.G_FALSE
7165    );
7166 
7167    IF (G_DEBUG) THEN
7168       ozf_utility_pvt.debug_message(l_full_name ||': end');
7169    END IF;
7170 
7171 
7172 EXCEPTION
7173    WHEN Fnd_Api.G_EXC_ERROR THEN
7174       ROLLBACK TO SP_update_reconcile_objfundsum;
7175       x_return_status := Fnd_Api.G_RET_STS_ERROR;
7176       Fnd_Msg_Pub.Count_And_Get (
7177          p_count         =>     x_msg_count,
7178          p_data          =>     x_msg_data,
7179          p_encoded       =>     FND_API.G_FALSE
7180       );
7181    WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
7182       ROLLBACK TO SP_update_reconcile_objfundsum;
7183       x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
7184       Fnd_Msg_Pub.Count_And_Get (
7185          p_count         =>     x_msg_count,
7186          p_data          =>     x_msg_data,
7187          p_encoded       =>   FND_API.G_FALSE
7188       );
7189    WHEN OTHERS THEN
7190       ROLLBACK TO SP_update_reconcile_objfundsum;
7191       x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
7192       IF Fnd_Msg_Pub.Check_Msg_Level (Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR) THEN
7193          Fnd_Msg_Pub.Add_Exc_Msg (G_PKG_NAME, L_API_NAME);
7194       END IF;
7195       Fnd_Msg_Pub.Count_And_Get (
7196          p_count         =>     x_msg_count,
7197          p_data          =>     x_msg_data,
7198          p_encoded       =>   FND_API.G_FALSE
7199       );
7200 END update_reconcile_objfundsum;
7201 */
7202 
7203 END ozf_actbudgets_pvt;