DBA Data[Home] [Help]

PACKAGE BODY: APPS.CN_TRX_FACTOR_PVT

Source


1 PACKAGE BODY cn_trx_factor_pvt AS
2    /*$Header: cnvtxftb.pls 120.3 2006/01/12 00:00:29 chanthon noship $*/
3    g_pkg_name           CONSTANT VARCHAR2 (30) := 'CN_TRX_FACTOR_PVT';
4 
5 --|/*-----------------------------------------------------------------------+
6 --|
7 --|  Procedure Name : CHECK_VALID_QUOTAS
8 --|
9 --|----------------------------------------------------------------------- */
10    PROCEDURE check_valid_quotas (
11       x_return_status            OUT NOCOPY VARCHAR2,
12       x_msg_count                OUT NOCOPY NUMBER,
13       x_msg_data                 OUT NOCOPY VARCHAR2,
14       p_quota_name               IN       VARCHAR2,
15       p_org_id                   IN       NUMBER,
16       p_rev_class_name           IN       VARCHAR2,
17       x_quota_id                 OUT NOCOPY NUMBER,
18       x_quota_rule_id            OUT NOCOPY NUMBER,
19       x_rev_class_id             OUT NOCOPY NUMBER,
20       p_loading_status           IN       VARCHAR2,
21       x_loading_status           OUT NOCOPY VARCHAR2
22    )
23    IS
24       l_api_name           CONSTANT VARCHAR2 (30) := 'Validate_trx_factors';
25       l_lkup_meaning                cn_lookups.meaning%TYPE;
26       l_loading_status              VARCHAR2 (80);
27    BEGIN
28       --  Initialize API return status to success
29       x_return_status := fnd_api.g_ret_sts_success;
30       x_loading_status := p_loading_status;
31       --+
32       -- Check Miss And Null Parameters.
33       --+
34       l_lkup_meaning := cn_api.get_lkup_meaning ('QUOTA_NAME', 'PM_OBJECT_TYPE');
35 
36       IF ((cn_api.chk_null_char_para (p_char_para           => p_quota_name,
37                                       p_obj_name            => l_lkup_meaning,
38                                       p_loading_status      => x_loading_status,
39                                       x_loading_status      => l_loading_status
40                                      )
41           ) = fnd_api.g_true
42          )
43       THEN
44          RAISE fnd_api.g_exc_error;
45       END IF;
46 
47       l_lkup_meaning := cn_api.get_lkup_meaning ('', 'PM_OBJECT_TYPE');
48 
49       IF ((cn_api.chk_null_char_para (p_char_para           => p_rev_class_name,
50                                       p_obj_name            => l_lkup_meaning,
51                                       p_loading_status      => x_loading_status,
52                                       x_loading_status      => l_loading_status
53                                      )
54           ) = fnd_api.g_true
55          )
56       THEN
57          RAISE fnd_api.g_exc_error;
58       END IF;
59 
60       -- Quota ID
61       x_quota_id := cn_chk_plan_element_pkg.get_quota_id (LTRIM (RTRIM (p_quota_name)), p_org_id);
62 
63       IF p_quota_name IS NOT NULL
64       THEN
65          IF x_quota_id IS NULL
66          THEN
67             IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
68             THEN
69                fnd_message.set_name ('CN', 'CN_PLN_NOT_EXIST');
70                fnd_message.set_token ('PE_NAME', p_quota_name);
71                fnd_msg_pub.ADD;
72                RAISE fnd_api.g_exc_error;
73             END IF;
74          END IF;
75       END IF;
76 
77       -- Get the Revenue Class ID
78       x_rev_class_id := cn_api.get_rev_class_id (LTRIM (RTRIM (p_rev_class_name)), p_org_id);
79       -- get the Quota Rule ID
80       x_quota_rule_id := cn_chk_plan_element_pkg.get_quota_rule_id (x_quota_id, x_rev_class_id);
81 
82       IF p_rev_class_name IS NOT NULL
83       THEN
84          IF x_rev_class_id IS NULL
85          THEN
86             IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
87             THEN
88                fnd_message.set_name ('CN', 'CN_REV_CLASS_NOT_EXIST');
89                fnd_msg_pub.ADD;
90             END IF;
91 
92             RAISE fnd_api.g_exc_error;
93          END IF;
94       ELSE
95          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
96          THEN
97             fnd_message.set_name ('CN', 'CN_REV_CLASS_NOT_ASSIGNED');
98             fnd_msg_pub.ADD;
99          END IF;
100 
101          RAISE fnd_api.g_exc_error;
102       END IF;
103 
104       IF x_quota_rule_id IS NULL
105       THEN
106          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
107          THEN
108             fnd_message.set_name ('CN', 'CN_QUOTA_RULE_NOT_EXIST');
109             fnd_msg_pub.ADD;
110          END IF;
111 
112          RAISE fnd_api.g_exc_error;
113       END IF;
114    -- End Check Valid Quotas.
115    END check_valid_quotas;
116 
117 -- Start of comments
118 --    API name        : Create_Trx_Factor
119 --    Type            : Private.
120 --    Function        :
121 --    Pre-reqs        : None.
122 --    Parameters      :
123 --    IN              : p_api_version         IN NUMBER       Required
124 --                      p_init_msg_list       IN VARCHAR2     Optional
125 --                        Default = FND_API.G_FALSE
126 --                      p_commit              IN VARCHAR2     Optional
127 --                        Default = FND_API.G_FALSE
128 --                      p_validation_level    IN NUMBER       Optional
129 --                        Default = FND_API.G_VALID_LEVEL_FULL
130 --                      p_trx_factor        IN  trx_factor_rec_type
131 --    OUT             : x_return_status       OUT     VARCHAR2(1)
132 --                      x_msg_count           OUT     NUMBER
133 --                      x_msg_data            OUT     VARCHAR2(2000)
134 --                      x_trx_factor_id        OUT     NUMBER
135 --    Version :         Current version       1.0
136 --    Notes           : Note text
137 --
138 -- End of comments
139    PROCEDURE create_trx_factor (
140       p_api_version              IN       NUMBER,
141       p_init_msg_list            IN       VARCHAR2 := fnd_api.g_false,
142       p_commit                   IN       VARCHAR2 := fnd_api.g_false,
143       p_validation_level         IN       NUMBER := fnd_api.g_valid_level_full,
144       p_trx_factor               IN OUT NOCOPY trx_factor_rec_type,
145       x_return_status            OUT NOCOPY VARCHAR2,
146       x_msg_count                OUT NOCOPY NUMBER,
147       x_msg_data                 OUT NOCOPY VARCHAR2
148    )
149    IS
150       l_api_name           CONSTANT VARCHAR2 (30) := 'Create_Trx_Factor';
151       l_api_version        CONSTANT NUMBER := 1.0;
152       l_temp_count                  NUMBER;
153    BEGIN
154       -- Standard Start of API savepoint
155       SAVEPOINT create_trx_factor;
156 
157       -- Standard call to check for call compatibility.
158       IF NOT fnd_api.compatible_api_call (l_api_version, p_api_version, l_api_name, g_pkg_name)
159       THEN
160          RAISE fnd_api.g_exc_unexpected_error;
161       END IF;
162 
163       -- Initialize message list if p_init_msg_list is set to TRUE.
164       IF fnd_api.to_boolean (p_init_msg_list)
165       THEN
166          fnd_msg_pub.initialize;
167       END IF;
168 
169       --  Initialize API return status to success
170       x_return_status := fnd_api.g_ret_sts_success;
171       -- API body
172 
173       -- This will never be used
174       RAISE fnd_api.g_exc_unexpected_error;
175 
176       -- End of API body.
177       -- Standard check of p_commit.
178       IF fnd_api.to_boolean (p_commit)
179       THEN
180          COMMIT WORK;
181       END IF;
182 
183       -- Standard call to get message count and if count is 1, get message info.
184       fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
185    EXCEPTION
186       WHEN fnd_api.g_exc_error
187       THEN
188          ROLLBACK TO create_trx_factor;
189          x_return_status := fnd_api.g_ret_sts_error;
190          fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
191       WHEN fnd_api.g_exc_unexpected_error
192       THEN
193          ROLLBACK TO create_trx_factor;
194          x_return_status := fnd_api.g_ret_sts_unexp_error;
195          fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
196       WHEN OTHERS
197       THEN
198          ROLLBACK TO create_trx_factor;
199          x_return_status := fnd_api.g_ret_sts_unexp_error;
200 
201          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error)
202          THEN
203             fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
204          END IF;
205 
206          fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
207    END create_trx_factor;
208 
209    -- Start of comments
210    --    API name        : Validate_Trx_Factor
211    --    Type            : Private.
212    --    Function        :
213    --    Pre-reqs        : None.
214    --    Parameters      :
215    --    IN              : p_api_version         IN NUMBER       Required
216    --                      p_init_msg_list       IN VARCHAR2     Optional
217    --                        Default = FND_API.G_FALSE
218    --                      p_commit              IN VARCHAR2     Optional
219    --                        Default = FND_API.G_FALSE
220    --                      p_validation_level    IN NUMBER       Optional
221    --                        Default = FND_API.G_VALID_LEVEL_FULL
222    --                      p_trx_factor        IN  trx_factor_rec_type
223    --    OUT             : x_return_status       OUT     VARCHAR2(1)
224    --                      x_msg_count           OUT     NUMBER
225    --                      x_msg_data            OUT     VARCHAR2(2000)
226    --                      x_trx_factor_id        OUT     NUMBER
227    --    Version :         Current version       1.0
228    --    Notes           : Note text
229    --
230    -- End of comments
231    PROCEDURE validate_trx_factor (
232       p_api_version              IN       NUMBER,
233       p_init_msg_list            IN       VARCHAR2 := fnd_api.g_false,
234       p_commit                   IN       VARCHAR2 := fnd_api.g_false,
235       p_validation_level         IN       NUMBER := fnd_api.g_valid_level_full,
236       p_action                   IN       VARCHAR2,
237       p_trx_factor               IN OUT NOCOPY trx_factor_rec_type,
238       p_old_trx_factor           IN       trx_factor_rec_type := g_miss_trx_factor_rec,
239       x_return_status            OUT NOCOPY VARCHAR2,
240       x_msg_count                OUT NOCOPY NUMBER,
241       x_msg_data                 OUT NOCOPY VARCHAR2
242    )
243    IS
244       l_api_name           CONSTANT VARCHAR2 (30) := 'validate_trx_factor';
245       l_api_version        CONSTANT NUMBER := 1.0;
246       l_temp_count                  NUMBER;
247       l_trx_name                    VARCHAR2 (80);
248    BEGIN
249       -- Standard Start of API savepoint
250       SAVEPOINT validate_trx_factor;
251 
252       -- Standard call to check for call compatibility.
253       IF NOT fnd_api.compatible_api_call (l_api_version, p_api_version, l_api_name, g_pkg_name)
254       THEN
255          RAISE fnd_api.g_exc_unexpected_error;
256       END IF;
257 
258       -- Initialize message list if p_init_msg_list is set to TRUE.
259       IF fnd_api.to_boolean (p_init_msg_list)
260       THEN
261          fnd_msg_pub.initialize;
262       END IF;
263 
264       --  Initialize API return status to success
265       x_return_status := fnd_api.g_ret_sts_success;
266 
267       -- 1. name can not be null
268       IF (p_trx_factor.trx_type IS NOT NULL)
269       THEN
270          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
271          THEN
272             BEGIN
273                --clku bug 2376751
274                SELECT meaning
275                  INTO l_trx_name
276                  FROM cn_lookups
277                 WHERE lookup_type = 'TRX TYPES' AND lookup_code = p_trx_factor.trx_type;
278             EXCEPTION
279                WHEN NO_DATA_FOUND
280                THEN
281                   fnd_message.set_name ('CN', 'CN_TRX_TYPE_NOT_EXISTS');
282                   fnd_message.set_token ('TRANSACTION_TYPE', p_trx_factor.trx_type);
283                   fnd_msg_pub.ADD;
284                   RAISE fnd_api.g_exc_error;
285             END;
286          END IF;
287       ELSE
288          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
289          THEN
290              IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
291              THEN
292                 fnd_message.set_name ('CN', 'CN_INPUT_CANT_NULL');
293                 fnd_message.set_token ('INPUT_NAME',cn_api.get_lkup_meaning ('TRX_TYPE', 'PE_OBJECT_TYPE'));
294                 fnd_msg_pub.ADD;
295              END IF;
296          END IF ;
297          RAISE fnd_api.g_exc_error;
298       END IF;
299 
300       IF p_trx_factor.event_factor IS NULL
301       THEN
302            IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
303            THEN
304                 fnd_message.set_name ('CN', 'CN_INPUT_CANT_NULL');
305                 fnd_message.set_token ('INPUT_NAME',cn_api.get_lkup_meaning ('EVENT_FACTOR', 'PE_OBJECT_TYPE'));
306                 fnd_msg_pub.ADD;
307            END IF;
308            RAISE fnd_api.g_exc_error;
309       END IF ;
310 
311       IF p_trx_factor.quota_id IS NULL
312       THEN
313          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
314          THEN
315             fnd_message.set_name ('CN', 'CN_INVALID_DATA');
316             fnd_message.set_token ('OBJ_NAME', NVL (cn_api.get_lkup_meaning ('PE', 'INPUT_TOKEN'), 'PE'));
317             fnd_msg_pub.ADD;
318          END IF;
319 
320          RAISE fnd_api.g_exc_error;
321       END IF;
322 
323       IF p_trx_factor.revenue_class_id IS NULL
324       THEN
325          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
326          THEN
327             fnd_message.set_name ('CN', 'CN_REV_CLASS_NOT_ASSIGNED');
328             fnd_msg_pub.ADD;
329          END IF;
330          RAISE fnd_api.g_exc_error;
331       END IF;
332 
333       IF p_trx_factor.quota_rule_id IS NULL
334       THEN
335          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
336          THEN
337             fnd_message.set_name ('CN', 'CN_QUOTA_RULE_NOT_EXIST');
338             fnd_msg_pub.ADD;
339          END IF;
340 
341          RAISE fnd_api.g_exc_error;
342       END IF;
343 
344       IF p_action = 'UPDATE'
345       THEN
346          IF p_trx_factor.trx_type <> p_old_trx_factor.trx_type
347          THEN
348             IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
349             THEN
350                fnd_message.set_name ('CN', 'CN_FIELD_NOT_UPDATABLE');
351                fnd_message.set_token ('FIELD_NAME', NVL (cn_api.get_lkup_meaning ('TRX_TYPE', 'PE_OBJECT_TYPE'), 'TRX_TYPE'));
352                fnd_msg_pub.ADD;
353             END IF;
354 
355             RAISE fnd_api.g_exc_error;
356          END IF;
357 
358          IF p_trx_factor.quota_id <> p_old_trx_factor.quota_id
359          THEN
360             IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
361             THEN
362                fnd_message.set_name ('CN', 'CN_FIELD_NOT_UPDATABLE');
363                fnd_message.set_token ('FIELD_NAME', NVL (cn_api.get_lkup_meaning ('PE', 'INPUT_TOKEN'), 'PE'));
364                fnd_msg_pub.ADD;
365             END IF;
366 
367             RAISE fnd_api.g_exc_error;
368          END IF;
369 
370          IF p_trx_factor.quota_rule_id <> p_old_trx_factor.quota_rule_id
371          THEN
372             IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
373             THEN
374                fnd_message.set_name ('CN', 'CN_FIELD_NOT_UPDATABLE');
375                fnd_message.set_token ('FIELD_NAME', NVL (cn_api.get_lkup_meaning ('RC_ASSIGN', 'PE_OBJECT_TYPE'), 'RC_ASSIGN'));
376                fnd_msg_pub.ADD;
377             END IF;
378 
379             RAISE fnd_api.g_exc_error;
380          END IF;
381 
382          IF p_trx_factor.revenue_class_id <> p_old_trx_factor.revenue_class_id
383          THEN
384             IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
385             THEN
386                fnd_message.set_name ('CN', 'CN_FIELD_NOT_UPDATABLE');
387                fnd_message.set_token ('FIELD_NAME', NVL (cn_api.get_lkup_meaning ('RC', 'INPUT_TOKEN'), 'TRX_TYPE'));
388                fnd_msg_pub.ADD;
389             END IF;
390 
391             RAISE fnd_api.g_exc_error;
392          END IF;
393       END IF;
394 
395       SELECT COUNT (*)
396         INTO l_temp_count
397         FROM cn_trx_factors
398        WHERE revenue_class_id = p_trx_factor.revenue_class_id
399          AND quota_id = p_trx_factor.quota_id
400          AND quota_rule_id = p_trx_factor.quota_rule_id
401          AND trx_type = p_trx_factor.trx_type
402          AND trx_factor_id = p_trx_factor.trx_factor_id;
403 
404       IF l_temp_count < 1
405       THEN
406          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
407          THEN
408             fnd_message.set_name ('CN', 'CN_INCONSISTENT_DATA');
409             fnd_message.set_token ('INPUT1', cn_api.get_lkup_meaning ('RC', 'INPUT_TOKEN'));
410             fnd_message.set_token ('INPUT2', cn_api.get_lkup_meaning ('PE', 'INPUT_TOKEN'));
411             fnd_message.set_token ('INPUT3', cn_api.get_lkup_meaning ('RC_ASSIGN', 'PE_OBJECT_TYPE'));
412             fnd_message.set_token ('INPUT4', cn_api.get_lkup_meaning ('TRX_TYPE', 'PE_OBJECT_TYPE'));
413             fnd_message.set_token ('INPUT5', ' ');
414             fnd_msg_pub.ADD;
415          END IF;
416 
417          RAISE fnd_api.g_exc_error;
418       END IF;
419 
420       -- 2. trx type must be unique
421       SELECT COUNT (1)
422         INTO l_temp_count
423         FROM cn_trx_factors
424        WHERE quota_rule_id = p_trx_factor.quota_rule_id
425          AND trx_type = p_trx_factor.trx_type
426          AND trx_factor_id <> p_trx_factor.trx_factor_id
427          AND ROWNUM = 1;
428 
429       IF l_temp_count <> 0
430       THEN
431          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
432          THEN
433             fnd_message.set_name ('CN', 'CN_INPUT_MUST_UNIQUE');
434             fnd_msg_pub.ADD;
435          END IF;
436 
437          RAISE fnd_api.g_exc_error;
438       END IF;
439 
440       --DBMS_OUTPUT.PUT_LINE('OrgId:'||p_trx_factor.org_id||'|'||p_trx_factor.quota_id) ;
441       IF NOT cn_plan_element_pvt.is_valid_org(p_trx_factor.org_id, p_trx_factor.quota_id)
442       THEN
443           RAISE fnd_api.g_exc_error;
444       END IF ;
445 
446       -- 1. check object version number
447       IF p_old_trx_factor.object_version_number <> NVL (p_trx_factor.object_version_number, -1)
448       THEN
449          fnd_message.set_name ('CN', 'CN_RECORD_CHANGED');
450          fnd_msg_pub.ADD;
451          RAISE fnd_api.g_exc_error;
452       END IF;
453 
454       -- Standard call to get message count and if count is 1, get message info.
455       fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
456    EXCEPTION
457       WHEN fnd_api.g_exc_error
458       THEN
459          ROLLBACK TO validate_trx_factor;
460          x_return_status := fnd_api.g_ret_sts_error;
461          fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
462       WHEN fnd_api.g_exc_unexpected_error
463       THEN
464          ROLLBACK TO validate_trx_factor;
465          x_return_status := fnd_api.g_ret_sts_unexp_error;
466          fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
467       WHEN OTHERS
468       THEN
469          ROLLBACK TO validate_trx_factor;
470          x_return_status := fnd_api.g_ret_sts_unexp_error;
471 
472          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error)
473          THEN
474             fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
475          END IF;
476 
477          fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
478    END validate_trx_factor;
479 
480  -- Start of comments
481 --      API name        : Update_Trx_Factor
482 --      Type            : Private.
483 --      Function        :
484 --      Pre-reqs        : None.
485 --      Parameters      :
486 --      IN              : p_api_version       IN NUMBER       Required
487 --                        p_init_msg_list     IN VARCHAR2     Optional
488 --                          Default = FND_API.G_FALSE
489 --                        p_commit            IN VARCHAR2     Optional
490 --                          Default = FND_API.G_FALSE
491 --                        p_validation_level  IN NUMBER       Optional
492 --                          Default = FND_API.G_VALID_LEVEL_FULL
493 --                        p_trx_factor         IN trx_factor_rec_type
494 --      OUT             : x_return_status     OUT     VARCHAR2(1)
495 --                        x_msg_count         OUT     NUMBER
496 --                        x_msg_data          OUT     VARCHAR2(2000)
497 --      Version :         Current version     1.0
498 --      Notes           : Note text
499 --
500 -- End of comments
501    PROCEDURE update_trx_factor (
502       p_api_version              IN       NUMBER,
503       p_init_msg_list            IN       VARCHAR2 := fnd_api.g_false,
504       p_commit                   IN       VARCHAR2 := fnd_api.g_false,
505       p_validation_level         IN       NUMBER := fnd_api.g_valid_level_full,
506       p_trx_factor               IN OUT NOCOPY trx_factor_rec_type,
507       x_return_status            OUT NOCOPY VARCHAR2,
508       x_msg_count                OUT NOCOPY NUMBER,
509       x_msg_data                 OUT NOCOPY VARCHAR2
510    )
511    IS
512       l_api_name           CONSTANT VARCHAR2 (30) := 'Update_Trx_Factor';
513       l_api_version        CONSTANT NUMBER := 1.0;
514 
515       CURSOR trx_factor_csr (
516          factor_id                           NUMBER
517       )
518       IS
519          SELECT *
520            FROM cn_trx_factors
521           WHERE trx_factor_id = factor_id;
522 
523       l_old_trx_factor              trx_factor_csr%ROWTYPE;
524       l_old_rec                     trx_factor_rec_type;
525       l_temp_count                  NUMBER;
526       l_quota_rule_id               NUMBER;
527       l_quota_name                  cn_quotas.NAME%TYPE;
528       l_loading_status              VARCHAR2 (1000);
529       --clku bug 2376751
530       l_row_id                      NUMBER;
531       g_last_update_date            DATE := SYSDATE;
532       g_last_updated_by             NUMBER := fnd_global.user_id;
533       g_creation_date               DATE := SYSDATE;
534       g_created_by                  NUMBER := fnd_global.user_id;
535       g_last_update_login           NUMBER := fnd_global.login_id;
536       l_rev_class_name              cn_revenue_classes.NAME%TYPE;
537       l_factor_name                 VARCHAR2(200);
538       l_note_msg                    VARCHAR2 (2000);
539       l_note_id                     NUMBER;
540    BEGIN
541       -- Standard Start of API savepoint
542       SAVEPOINT update_trx_factor;
543 
544       -- Standard call to check for call compatibility.
545       IF NOT fnd_api.compatible_api_call (l_api_version, p_api_version, l_api_name, g_pkg_name)
546       THEN
547          RAISE fnd_api.g_exc_unexpected_error;
548       END IF;
549 
550       -- Initialize message list if p_init_msg_list is set to TRUE.
551       IF fnd_api.to_boolean (p_init_msg_list)
552       THEN
553          fnd_msg_pub.initialize;
554       END IF;
555 
556       --  Initialize API return status to success
557       x_return_status := fnd_api.g_ret_sts_success;
558 
559       OPEN trx_factor_csr (p_trx_factor.trx_factor_id);
560 
561       FETCH trx_factor_csr
562        INTO l_old_trx_factor;
563 
564       IF trx_factor_csr%NOTFOUND
565       THEN
566          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
567          THEN
568             fnd_message.set_name ('CN', 'CN_INVALID_DATA');
569             fnd_message.set_token ('OBJ_NAME', NVL (cn_api.get_lkup_meaning ('TRX_FACTOR', 'PE_OBJECT_TYPE'), 'TRX_FACTOR'));
570             fnd_msg_pub.ADD;
571          END IF;
572 
573          RAISE fnd_api.g_exc_error;
574       END IF;
575 
576       CLOSE trx_factor_csr;
577 
578       -- get the old rec
579       l_old_rec.trx_factor_id := l_old_trx_factor.trx_factor_id;
580       l_old_rec.revenue_class_id := l_old_trx_factor.revenue_class_id;
581       l_old_rec.quota_id := l_old_trx_factor.quota_id;
582       l_old_rec.quota_rule_id := l_old_trx_factor.quota_rule_id;
583       l_old_rec.event_factor := l_old_trx_factor.event_factor;
584       l_old_rec.trx_type := l_old_trx_factor.trx_type;
585       l_old_rec.object_version_number := l_old_trx_factor.object_version_number;
586       -- validate the trx factor
587       validate_trx_factor (p_api_version           => l_api_version,
588                            p_init_msg_list         => p_init_msg_list,
589                            p_commit                => p_commit,
590                            p_validation_level      => p_validation_level,
591                            p_action                => 'UPDATE',
592                            p_trx_factor            => p_trx_factor,
593                            p_old_trx_factor        => l_old_rec,
594                            x_return_status         => x_return_status,
595                            x_msg_count             => x_msg_count,
596                            x_msg_data              => x_msg_data
597                           );
598 
599       IF (x_return_status <> fnd_api.g_ret_sts_success)
600       THEN
601          RAISE fnd_api.g_exc_error;
602       END IF;
603 
604       -- update the record
605       -- org_id depends on the plan elements org_id
606       cn_trx_factors_pkg.begin_record (x_operation                  => 'UPDATE',
607                                        x_rowid                      => l_row_id,
608                                        x_trx_factor_id              => p_trx_factor.trx_factor_id,
609                                        x_object_version_number      => p_trx_factor.object_version_number,
610                                        x_event_factor               => p_trx_factor.event_factor,
611                                        x_event_factor_old           => l_old_trx_factor.event_factor,
612                                        x_revenue_class_id           => p_trx_factor.revenue_class_id,
613                                        x_last_update_date           => g_last_update_date,
614                                        x_last_updated_by            => g_last_updated_by,
615                                        x_creation_date              => l_old_trx_factor.creation_date,
616                                        x_created_by                 => l_old_trx_factor.created_by,
617                                        x_last_update_login          => g_last_update_login,
618                                        x_quota_id                   => p_trx_factor.quota_id,
619                                        x_quota_rule_id              => p_trx_factor.quota_rule_id,
620                                        x_trx_type                   => p_trx_factor.trx_type,
621                                        x_trx_type_name              => NULL,
622                                        x_program_type               => NULL,
623                                        x_status_code                => NULL,
624                                        x_org_id                     => NULL
625                                       );
626 
627         --GENERATE NOTE FOR THE UPDATE
628         IF (l_old_rec.event_factor <> p_trx_factor.event_factor) THEN
629          --Get Revenue Class Name
630          select NAME into l_rev_class_name from cn_revenue_classes
631          where REVENUE_CLASS_ID = p_trx_factor.revenue_class_id
632          and org_id = p_trx_factor.org_id;
633          --Get Factor Name
634          l_factor_name := cn_api.get_lkup_meaning(p_trx_factor.trx_type, 'TRX TYPES');
635          --Start Creating the note
636          fnd_message.set_name ('CN', 'CNR12_NOTE_COMPPLAN_ASPE_DEL');
637          fnd_message.set_token('PROD', l_rev_class_name);
638          fnd_message.set_token('FACTOR_TYPE', l_factor_name);
639          fnd_message.set_token('OLD_FACTOR', l_old_rec.event_factor);
640          fnd_message.set_token('NEW_FACTOR', p_trx_factor.event_factor);
641 
642          l_note_msg := fnd_message.get;
643          jtf_notes_pub.create_note
644                     (p_api_version             => 1.0,
645                      x_return_status           => x_return_status,
646                      x_msg_count               => x_msg_count,
647                      x_msg_data                => x_msg_data,
648                      p_source_object_id        => p_trx_factor.quota_id,
649                      p_source_object_code      => 'CN_QUOTAS',
650                      p_notes                   => l_note_msg,
651                      p_notes_detail            => l_note_msg,
652                      p_note_type               => 'CN_SYSGEN', -- for system generated
653                      x_jtf_note_id             => l_note_id    -- returned
654                      );
655         END IF;
656 
657         IF (x_return_status <> fnd_api.g_ret_sts_success)
658         THEN
659           RAISE fnd_api.g_exc_error;
660         END IF;
661 
662       -- End of API body.
663       -- Standard check of p_commit.
664       IF fnd_api.to_boolean (p_commit)
665       THEN
666          COMMIT WORK;
667       END IF;
668 
669       -- Standard call to get message count and if count is 1, get message info.
670       fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
671    EXCEPTION
672       WHEN fnd_api.g_exc_error
673       THEN
674          ROLLBACK TO update_trx_factor;
675          x_return_status := fnd_api.g_ret_sts_error;
676          fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
677       WHEN fnd_api.g_exc_unexpected_error
678       THEN
679          ROLLBACK TO update_trx_factor;
680          x_return_status := fnd_api.g_ret_sts_unexp_error;
681          fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
682       WHEN OTHERS
683       THEN
684          ROLLBACK TO update_trx_factor;
685          x_return_status := fnd_api.g_ret_sts_unexp_error;
686 
687          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error)
688          THEN
689             fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
690          END IF;
691 
692          fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
693    END update_trx_factor;
694 
695    -- Start of comments
696    --    API name        : update_trx_factors
697    --    Type            : Private.
698    --    Function        :
699    --    Pre-reqs        : None.
700    --    Parameters      :
701    --    IN              : p_api_version         IN NUMBER       Required
702    --                      p_init_msg_list       IN VARCHAR2     Optional
703    --                        Default = FND_API.G_FALSE
704    --                      p_commit              IN VARCHAR2     Optional
705    --                        Default = FND_API.G_FALSE
706    --                      p_validation_level    IN NUMBER       Optional
707    --                        Default = FND_API.G_VALID_LEVEL_FULL
708    --                      p_trx_factor        IN  trx_factor_rec_type
709    --    OUT             : x_return_status       OUT     VARCHAR2(1)
710    --                      x_msg_count           OUT     NUMBER
711    --                      x_msg_data            OUT     VARCHAR2(2000)
712    --                      x_trx_factor_id        OUT     NUMBER
713    --    Version :         Current version       1.0
714    --    Notes           : Note text
715    --
716    -- End of comments
717    PROCEDURE update_trx_factors (
718       p_api_version              IN       NUMBER,
719       p_init_msg_list            IN       VARCHAR2 := fnd_api.g_false,
720       p_commit                   IN       VARCHAR2 := fnd_api.g_false,
721       p_validation_level         IN       NUMBER := fnd_api.g_valid_level_full,
722       p_org_id                   IN       NUMBER,
723       p_quota_name               IN       VARCHAR2,
724       p_revenue_class_name       IN       VARCHAR2 := NULL,
725       p_trx_factor_rec_tbl       IN       cn_plan_element_pub.trx_factor_rec_tbl_type,
726       x_return_status            OUT NOCOPY VARCHAR2,
727       x_msg_count                OUT NOCOPY NUMBER,
728       x_msg_data                 OUT NOCOPY VARCHAR2,
729       x_loading_status           OUT NOCOPY VARCHAR2
730    )
731    IS
732       l_api_name           CONSTANT VARCHAR2 (30) := 'Update_Trx_Factors';
733       l_api_version        CONSTANT NUMBER := 1.0;
734       l_quota_id                    NUMBER;
735       l_quota_rule_id               NUMBER;
736       l_rev_class_id                NUMBER;
737       l_rev_class_name              cn_revenue_classes.NAME%TYPE;
738       l_trx_factor_rec              cn_trx_factor_pvt.trx_factor_rec_type;
739       l_loading_status              VARCHAR2 (80);
740       l_rev_class_names_array       jtf_varchar2_table_4000;
741    BEGIN
742       --
743       -- Standard Start of API savepoint
744       -- +
745       SAVEPOINT update_trx_factors;
746 
747       --+
748       -- Standard call to check for call compatibility.
749       --+
750       IF NOT fnd_api.compatible_api_call (l_api_version, p_api_version, l_api_name, g_pkg_name)
751       THEN
752          RAISE fnd_api.g_exc_unexpected_error;
753       END IF;
754 
755       --+
756       -- Initialize message list if p_init_msg_list is set to TRUE.
757       -- +
758       IF fnd_api.to_boolean (p_init_msg_list)
759       THEN
760          fnd_msg_pub.initialize;
761       END IF;
762 
763       -- +
764       --  Initialize API return status to success
765       --+
766       x_return_status := fnd_api.g_ret_sts_success;
767 
768       IF p_trx_factor_rec_tbl.COUNT > 0
769       THEN
770          -- API body
771          -- Store the User Input Value into The Local Variable.
772          -- Standard check of p_commit.
773          --+
774          -- Check if plan element name is missing or null even for Delete the Q Rule
775          IF ((cn_api.chk_miss_char_para (p_char_para           => p_quota_name,
776                                          p_para_name           => cn_chk_plan_element_pkg.g_pe_name,
777                                          p_loading_status      => x_loading_status,
778                                          x_loading_status      => l_loading_status
779                                         )
780              ) = fnd_api.g_true
781             )
782          THEN
783             RAISE fnd_api.g_exc_error;
784          ELSIF ((cn_api.chk_null_char_para (p_char_para           => p_quota_name,
785                                             p_obj_name            => cn_chk_plan_element_pkg.g_pe_name,
786                                             p_loading_status      => x_loading_status,
787                                             x_loading_status      => l_loading_status
788                                            )
789                 ) = fnd_api.g_true
790                )
791          THEN
792             RAISE fnd_api.g_exc_error;
793          END IF;
794 
795          -- Get the Quota ID
796          l_quota_id := cn_chk_plan_element_pkg.get_quota_id (LTRIM (RTRIM (p_quota_name)), p_org_id);
797 
798          -- Raise an Error If quota id is null but name is not null
799          IF l_quota_id IS NULL AND p_quota_name IS NOT NULL
800          THEN
801             IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
802             THEN
803                fnd_message.set_name ('CN', 'CN_PLN_NOT_EXIST');
804                fnd_message.set_token ('PE_NAME', p_quota_name);
805                fnd_msg_pub.ADD;
806             END IF;
807 
808             x_loading_status := 'CN_PLN_NOT_EXIST';
809             RAISE fnd_api.g_exc_error;
810          END IF;
811 
812          -- if revenue class is not given, check for all
813          IF p_revenue_class_name IS NULL
814          THEN
815             SELECT rc.NAME AS revenue_class_name
816             BULK COLLECT INTO l_rev_class_names_array
817               FROM cn_quota_rules qr,
818                    cn_revenue_classes rc
819              WHERE qr.quota_id = l_quota_id AND qr.revenue_class_id = rc.revenue_class_id;
820          ELSE
821             l_rev_class_names_array := jtf_varchar2_table_4000 (p_revenue_class_name);
822          END IF;
823 
824          FOR i IN l_rev_class_names_array.FIRST .. l_rev_class_names_array.LAST
825          LOOP
826             l_rev_class_name := RTRIM (LTRIM (l_rev_class_names_array (i)));
827 -------------------------------------------------------
828 -- Check and Fetch values of the rev class assignment
829 -- whose trx factors will be updated
830 --------------------------------------------------------
831             check_valid_quotas (x_return_status       => x_return_status,
832                                 x_msg_count           => x_msg_count,
833                                 x_msg_data            => x_msg_data,
834                                 p_quota_name          => p_quota_name,
835                                 p_rev_class_name      => l_rev_class_name,
836                                 x_quota_id            => l_quota_id,
837                                 x_quota_rule_id       => l_quota_rule_id,
838                                 x_rev_class_id        => l_rev_class_id,
839                                 p_loading_status      => x_loading_status,
840                                 x_loading_status      => l_loading_status,
841                                 p_org_id              => p_org_id
842                                );
843 
844             FOR i IN p_trx_factor_rec_tbl.FIRST .. p_trx_factor_rec_tbl.LAST
845             LOOP
846                -- fetching using the names because we dont have an id.
847                l_trx_factor_rec.revenue_class_id := l_rev_class_id;
848                l_trx_factor_rec.quota_id := l_quota_id;
849                l_trx_factor_rec.quota_rule_id := l_quota_rule_id;
850                l_trx_factor_rec.event_factor := p_trx_factor_rec_tbl (i).event_factor;
851                l_trx_factor_rec.trx_type := p_trx_factor_rec_tbl (i).trx_type;
852 
853                BEGIN
854                   SELECT trx_factor_id,
855                          object_version_number
856                     INTO l_trx_factor_rec.trx_factor_id,
857                          l_trx_factor_rec.object_version_number
858                     FROM cn_trx_factors
859                    WHERE quota_rule_id = l_trx_factor_rec.quota_rule_id
860                      AND trx_type = l_trx_factor_rec.trx_type
861                      AND quota_id = l_trx_factor_rec.quota_id
862                      AND revenue_class_id = l_trx_factor_rec.revenue_class_id;
863                EXCEPTION
864                   WHEN NO_DATA_FOUND
865                   THEN
866                      IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error)
867                      THEN
868                         fnd_message.set_name ('CN', 'CN_INVALID_DATA');
869                         fnd_message.set_token ('OBJ_NAME', NVL (cn_api.get_lkup_meaning ('TRX_FACTOR', 'PE_OBJECT_TYPE'), 'TRX_FACTOR'));
870                         fnd_msg_pub.ADD;
871                      END IF;
872 
873                      RAISE fnd_api.g_exc_error;
874                END;
875 
876                IF RTRIM (LTRIM (p_trx_factor_rec_tbl (i).rev_class_name)) = l_rev_class_name
877                THEN
878                   update_trx_factor (p_api_version           => l_api_version,
879                                      p_init_msg_list         => p_init_msg_list,
880                                      p_commit                => p_commit,
881                                      p_validation_level      => p_validation_level,
882                                      p_trx_factor            => l_trx_factor_rec,
883                                      x_return_status         => x_return_status,
884                                      x_msg_count             => x_msg_count,
885                                      x_msg_data              => x_msg_data
886                                     );
887 
888                   IF (x_return_status <> fnd_api.g_ret_sts_success)
889                   THEN
890                      RAISE fnd_api.g_exc_error;
891                   END IF;
892                ELSE
893                   fnd_message.set_name ('CN', 'CN_INCONSISTENT_REV_CLASS');
894                   fnd_msg_pub.ADD;
895                   RAISE fnd_api.g_exc_error;
896                END IF;
897             END LOOP;
898 
899             cn_chk_plan_element_pkg.chk_trx_factor (x_return_status       => x_return_status,
900                                                     p_quota_rule_id       => l_quota_rule_id,
901                                                     p_rev_class_name      => l_rev_class_name,
902                                                     p_loading_status      => x_loading_status,
903                                                     x_loading_status      => l_loading_status
904                                                    );
905             x_loading_status := l_loading_status;
906 
907             IF (x_return_status <> fnd_api.g_ret_sts_success)
908             THEN
909                RAISE fnd_api.g_exc_error;
910             END IF;
911          END LOOP;
912       END IF;
913 
914       -- End of API body.
915       -- Standard check of p_commit.
916       --+
917       IF fnd_api.to_boolean (p_commit)
918       THEN
919          COMMIT WORK;
920       END IF;
921 
922       --+
923       -- Standard call to get message count and if count is 1, get message info.
924       --+
925       fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
926    EXCEPTION
927       WHEN fnd_api.g_exc_error
928       THEN
929          ROLLBACK TO update_trx_factors;
930          x_return_status := fnd_api.g_ret_sts_error;
931          fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
932       WHEN fnd_api.g_exc_unexpected_error
933       THEN
934          ROLLBACK TO update_trx_factors;
935          x_loading_status := 'UNEXPECTED_ERR';
936          x_return_status := fnd_api.g_ret_sts_unexp_error;
937          fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
938       WHEN OTHERS
939       THEN
940          ROLLBACK TO update_trx_factors;
941          x_loading_status := 'UNEXPECTED_ERR';
942          x_return_status := fnd_api.g_ret_sts_unexp_error;
943 
944          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error)
945          THEN
946             fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
947          END IF;
948 
949          fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
950    END update_trx_factors;
951 
952 -- Start of comments
953 --      API name        : Delete_Trx_Factor
954 --      Type            : Private.
955 --      Function        :
956 --      Pre-reqs        : None.
957 --      Parameters      :
958 --      IN              : p_api_version       IN NUMBER       Required
959 --                        p_init_msg_list     IN VARCHAR2     Optional
960 --                          Default = FND_API.G_FALSE
961 --                        p_commit            IN VARCHAR2     Optional
962 --                          Default = FND_API.G_FALSE
963 --                        p_validation_level  IN NUMBER       Optional
964 --                          Default = FND_API.G_VALID_LEVEL_FULL
965 --                        p_trx_factor         IN trx_factor_rec_type
966 --      OUT             : x_return_status     OUT     VARCHAR2(1)
967 --                        x_msg_count         OUT     NUMBER
968 --                        x_msg_data          OUT     VARCHAR2(2000)
969 --      Version :         Current version     1.0
970 --      Notes           : Note text
971 --
972 -- End of comments
973    PROCEDURE delete_trx_factor (
974       p_api_version              IN       NUMBER,
975       p_init_msg_list            IN       VARCHAR2 := fnd_api.g_false,
976       p_commit                   IN       VARCHAR2 := fnd_api.g_false,
977       p_validation_level         IN       NUMBER := fnd_api.g_valid_level_full,
978       p_trx_factor               IN OUT NOCOPY trx_factor_rec_type,
979       x_return_status            OUT NOCOPY VARCHAR2,
980       x_msg_count                OUT NOCOPY NUMBER,
981       x_msg_data                 OUT NOCOPY VARCHAR2
982    )
983    IS
984       l_api_name           CONSTANT VARCHAR2 (30) := 'Delete_Trx_Factor';
985       l_api_version        CONSTANT NUMBER := 1.0;
986       l_temp_count                  NUMBER;
987    BEGIN
988       -- Standard Start of API savepoint
989       SAVEPOINT delete_trx_factor;
990 
991       -- Standard call to check for call compatibility.
992       IF NOT fnd_api.compatible_api_call (l_api_version, p_api_version, l_api_name, g_pkg_name)
993       THEN
994          RAISE fnd_api.g_exc_unexpected_error;
995       END IF;
996 
997       -- Initialize message list if p_init_msg_list is set to TRUE.
998       IF fnd_api.to_boolean (p_init_msg_list)
999       THEN
1000          fnd_msg_pub.initialize;
1001       END IF;
1002 
1003       --  Initialize API return status to success
1004       x_return_status := fnd_api.g_ret_sts_success;
1005       -- API body
1006 
1007       -- This will never be used
1008       RAISE fnd_api.g_exc_unexpected_error;
1009 
1010       -- End of API body.
1011       -- Standard check of p_commit.
1012       IF fnd_api.to_boolean (p_commit)
1013       THEN
1014          COMMIT WORK;
1015       END IF;
1016 
1017       -- Standard call to get message count and if count is 1, get message info.
1018       fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
1019    EXCEPTION
1020       WHEN fnd_api.g_exc_error
1021       THEN
1022          ROLLBACK TO delete_trx_factor;
1023          x_return_status := fnd_api.g_ret_sts_error;
1024          fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
1025       WHEN fnd_api.g_exc_unexpected_error
1026       THEN
1027          ROLLBACK TO delete_trx_factor;
1028          x_return_status := fnd_api.g_ret_sts_unexp_error;
1029          fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
1030       WHEN OTHERS
1031       THEN
1032          ROLLBACK TO delete_trx_factor;
1033          x_return_status := fnd_api.g_ret_sts_unexp_error;
1034 
1035          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error)
1036          THEN
1037             fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
1038          END IF;
1039 
1040          fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
1041    END delete_trx_factor;
1042 
1043 -- Start of comments
1044 --      API name        : Get_Trx_Factor
1045 --      Type            : Private.
1046 --      Function        :
1047 --      Pre-reqs        : None.
1048 --      Parameters      :
1049 --      IN              : p_api_version       IN NUMBER       Required
1050 --                        p_init_msg_list     IN VARCHAR2     Optional
1051 --                          Default = FND_API.G_FALSE
1052 --                        p_commit            IN VARCHAR2     Optional
1053 --                          Default = FND_API.G_FALSE
1054 --                        p_validation_level  IN NUMBER       Optional
1055 --                          Default = FND_API.G_VALID_LEVEL_FULL
1056 --                        p_quota_rule_id      IN NUMBER
1057 --      OUT             : x_return_status     OUT     VARCHAR2(1)
1058 --                        x_msg_count         OUT     NUMBER
1059 --                        x_msg_data          OUT     VARCHAR2(2000)
1060 --                        x_trx_factor         OUT     trx_factor_tbl_type
1061 --      Version :         Current version     1.0
1062 --      Notes           : Note text
1063 --
1064 -- End of comments
1065    PROCEDURE get_trx_factor (
1066       p_api_version              IN       NUMBER,
1067       p_init_msg_list            IN       VARCHAR2 := fnd_api.g_false,
1068       p_commit                   IN       VARCHAR2 := fnd_api.g_false,
1069       p_validation_level         IN       NUMBER := fnd_api.g_valid_level_full,
1070       p_quota_rule_id            IN       NUMBER,
1071       x_trx_factor               OUT NOCOPY trx_factor_tbl_type,
1072       x_return_status            OUT NOCOPY VARCHAR2,
1073       x_msg_count                OUT NOCOPY NUMBER,
1074       x_msg_data                 OUT NOCOPY VARCHAR2
1075    )
1076    IS
1077       l_api_name           CONSTANT VARCHAR2 (30) := 'Get_Trx_Factor';
1078       l_api_version        CONSTANT NUMBER := 1.0;
1079 
1080       CURSOR l_trx_factor_cr
1081       IS
1082          SELECT *
1083            FROM cn_trx_factors
1084           WHERE quota_rule_id = p_quota_rule_id;
1085 
1086       l_counter                     NUMBER;
1087    BEGIN
1088       -- Standard Start of API savepoint
1089       SAVEPOINT get_trx_factor;
1090 
1091       -- Standard call to check for call compatibility.
1092       IF NOT fnd_api.compatible_api_call (l_api_version, p_api_version, l_api_name, g_pkg_name)
1093       THEN
1094          RAISE fnd_api.g_exc_unexpected_error;
1095       END IF;
1096 
1097       -- Initialize message list if p_init_msg_list is set to TRUE.
1098       IF fnd_api.to_boolean (p_init_msg_list)
1099       THEN
1100          fnd_msg_pub.initialize;
1101       END IF;
1102 
1103       --  Initialize API return status to success
1104       x_return_status := fnd_api.g_ret_sts_success;
1105       -- API body
1106       x_trx_factor := g_miss_trx_factor_rec_tb;
1107       l_counter := 0;
1108 
1109       FOR l_trx_factor IN l_trx_factor_cr
1110       LOOP
1111          l_counter := l_counter + 1;
1112          x_trx_factor (l_counter).trx_factor_id := l_trx_factor.trx_factor_id;
1113          x_trx_factor (l_counter).revenue_class_id := l_trx_factor.revenue_class_id;
1114          x_trx_factor (l_counter).quota_id := l_trx_factor.quota_id;
1115          x_trx_factor (l_counter).quota_rule_id := l_trx_factor.quota_rule_id;
1116          x_trx_factor (l_counter).event_factor := l_trx_factor.event_factor;
1117          x_trx_factor (l_counter).trx_type := l_trx_factor.trx_type;
1118          x_trx_factor (l_counter).object_version_number := l_trx_factor.object_version_number;
1119       END LOOP;
1120 
1121       -- End of API body.
1122       -- Standard check of p_commit.
1123       IF fnd_api.to_boolean (p_commit)
1124       THEN
1125          COMMIT WORK;
1126       END IF;
1127 
1128       -- Standard call to get message count and if count is 1, get message info.
1129       fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
1130    EXCEPTION
1131       WHEN fnd_api.g_exc_error
1132       THEN
1133          ROLLBACK TO get_trx_factor;
1134          x_return_status := fnd_api.g_ret_sts_error;
1135          fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
1136       WHEN fnd_api.g_exc_unexpected_error
1137       THEN
1138          ROLLBACK TO get_trx_factor;
1139          x_return_status := fnd_api.g_ret_sts_unexp_error;
1140          fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
1141       WHEN OTHERS
1142       THEN
1143          ROLLBACK TO get_trx_factor;
1144          x_return_status := fnd_api.g_ret_sts_unexp_error;
1145 
1146          IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error)
1147          THEN
1148             fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
1149          END IF;
1150 
1151          fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
1152    END get_trx_factor;
1153 END cn_trx_factor_pvt;