DBA Data[Home] [Help]

PACKAGE BODY: APPS.OZF_ACTBUDGETS_PVT

Source


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