DBA Data[Home] [Help]

PACKAGE BODY: APPS.CSD_RETURNS_BI_UTIL

Source


1 PACKAGE BODY CSD_RETURNS_BI_UTIL AS
2     /* $Header: csdurbib.pls 120.0.12010000.1 2010/04/14 23:22:25 swai noship $ */
3 
4     /*--------------------------------------------------------*/
5     /* function name: CONVERT_INV_UOM                         */
6     /* description : function used to convert quantities from */
7     /*               one inventory UOM to another             */
8     /* Called from : Depot Repair Returns BI dashboard        */
9     /* Input Parm  :                                          */
10     /*   p_qty               NUMBER    qty to convert         */
11     /*   p_from_uom          VARCHAR2  From UOM code          */
12     /*   p_to_uom            VARCHAR2  To UOM code            */
13     /*   p_error_val         NUMBER    Value to return if qty */
14     /*                                 is null or conversion  */
15     /*                                 errored out            */
16     /* Output:                                                */
17     /*        NUMBER  Converted currency amount               */
18     /*                Returns null if there is an error       */
19     /* Change Hist :                                          */
20     /*--------------------------------------------------------*/
21     FUNCTION CONVERT_INV_UOM (p_qty       IN NUMBER,
22                               p_from_uom  IN VARCHAR2,
23                               p_to_uom    IN VARCHAR2,
24                               p_error_val IN NUMBER) RETURN NUMBER
25     IS
26         l_converted_value NUMBER := NULL;
27     BEGIN
28         if (p_qty is null) then
29             l_converted_value := p_error_val;
30         else
31             l_converted_value := inv_convert.inv_um_convert(
32                                             item_id       => 0,
33                                             precision     => 38,
34                                             from_quantity => p_qty,
35                                             from_unit     => p_from_uom,
36                                             to_unit       => p_to_uom ,
37                                             from_name     => NULL,
38                                             to_name       => NULL);
39 
40             if (l_converted_value = -99999) then
41                 l_converted_value := p_error_val;
42             end if;
43         end if;
44         return l_converted_value;
45     END CONVERT_INV_UOM;
46 
47 
48     /*--------------------------------------------------------*/
49     /* function name: CONVERT_CURRENCY                        */
50     /* description : function used to convert currency -      */
51     /* Called from : Depot Repair Returns BI dashboard        */
52     /* Input Parm  :                                          */
53     /*   p_amount            NUMBER    Amount to convert      */
54     /*   p_from_currency     VARCHAR2  From currency code     */
55     /*   p_to_currency       VARCHAR2  To Currency code       */
56     /*   p_error_val         NUMBER    Value to return if amt */
57     /*                                 is null or conversion  */
58     /*                                 errored out            */
59     /* Output:                                                */
60     /*        NUMBER  Converted currency amount               */
61     /*                Returns null if there is an error       */
62     /* Change Hist :                                          */
63     /*--------------------------------------------------------*/
64     FUNCTION CONVERT_CURRENCY( p_amount          IN   NUMBER,
65                                p_from_currency   IN   VARCHAR2,
66                                p_to_currency     IN   VARCHAR2,
67                                p_conversion_date IN   DATE,
68                                p_error_val       IN   NUMBER
69     ) RETURN NUMBER
70     IS
71         l_return_status VARCHAR2(1);
72         l_msg_count NUMBER;
73         l_msg_data VARCHAR2(2000);
74         l_conv_amount NUMBER;
75         l_conversion_type          VARCHAR2(30);
76         l_max_roll_days            NUMBER;
77     BEGIN
78         -- Check if conversion type profile is set. If not then raise error.
79         l_conversion_type := FND_PROFILE.value('CSD_CURRENCY_CONVERSION_TYPE');
80         IF (l_conversion_type IS NULL) THEN
81            l_conversion_type := 'User';
82         END IF;
83 
84         --Get the max roll days from the profile.
85         l_max_roll_days := FND_PROFILE.value('CSD_CURRENCY_MAX_ROLL');
86 
87 
88         if (p_amount is null) then
89             l_conv_amount := p_error_val;
90         else
91             l_conv_amount := gl_currency_api.convert_closest_amount_sql (
92                     x_from_currency     => p_from_currency,
93                     x_to_currency       => p_to_currency,
94                     x_conversion_date   => p_conversion_date,
95                     x_conversion_type   => l_conversion_type,
96                     x_user_rate         => null,
97                     x_amount            => p_amount,
98                     x_max_roll_days     => l_max_roll_days);
99             if l_conv_amount = -1 then     -- NO_RATE
100                 l_conv_amount := p_error_val;
101             elsif l_conv_amount = -2 then  -- INVALID_CURRENCY
102                 l_conv_amount := p_error_val;
103             end if;
104         end if;
105         return l_conv_amount;
106     END CONVERT_CURRENCY;
107 
108 END CSD_RETURNS_BI_UTIL;