DBA Data[Home] [Help]

PACKAGE BODY: APPS.GMF_PROCESS_COST_PUB

Source


1 PACKAGE BODY GMF_PROCESS_COST_PUB AS
2 /* $Header: GMFPPCPB.pls 120.0 2005/11/21 14:04:03 sschinch noship $ */
3 
4 /************************************************************************************
5   *  PROCEDURE
6   *     Get_Priod_Period_Cost
7   *
8   *  DESCRIPTION
9   *     This procedure will return prior period cost for an organization/item for the cost
10   *     type defined in fiscal policy.
11   *
12   *  AUTHOR
13   *    Sukarna Reddy Chinchod 21-NOV-2005
14   *
15   *  INPUT PARAMETERS
16   *   p_inventory_item_id
17   *   p_organization_id
18   *   p_transaction_date
19   *
20   *  OUTPUT PARAMETERS
21   *	Returns Prior cost of an item.
22   *	Status 'S' or 'E'
23   *
24   * HISTORY
25   *
26   **************************************************************************************/
27 
28 PROCEDURE Get_Prior_Period_Cost(p_inventory_item_id IN          NUMBER,
29                                 p_organization_id   IN          NUMBER,
30                                 p_transaction_date  IN          DATE,
31                                 x_unit_cost         OUT NOCOPY  NUMBER,
32                                 x_msg_data          OUT NOCOPY  VARCHAR2,
33                                 x_return_status     OUT NOCOPY  VARCHAR2
34                                ) IS
35 
36   CURSOR cur_get_prior_period(p_le_id NUMBER,
37                               p_ct_id NUMBER,
38                               p_end_date DATE) IS
39     SELECT gps.end_date
40       FROM gmf_period_statuses gps
41      WHERE end_date < p_end_date
42        AND legal_entity_id = p_le_id
43        AND cost_type_id    = p_ct_id
44     ORDER BY end_date desc
45   ;
46 
47   l_le_id                 NUMBER;
48   l_cost_type_id          NUMBER;
49   l_cost_type             NUMBER;
50   l_end_date              DATE;
51   l_prior_period_end_date DATE;
52   l_msg_count         NUMBER;
53   l_no_of_rows        NUMBER;
54   l_cost_method	             cm_mthd_mst.cost_mthd_code%TYPE;
55   l_cost_component_class_id  cm_cmpt_mst.cost_cmpntcls_id%TYPE;
56   l_cost_analysis_code       cm_alys_mst.cost_analysis_code%TYPE;
57   l_ret_val NUMBER;
58 BEGIN
59   x_return_status := FND_API.G_RET_STS_SUCCESS;
60 
61   IF (p_inventory_item_id IS NULL OR p_organization_id IS NULL OR p_transaction_date IS NULL) THEN
62     x_return_status := FND_API.G_RET_STS_ERROR;
63     x_msg_data := 'Invalid Parameters';
64     RETURN;
65   END IF;
66 
67   BEGIN
68   SELECT gfp.legal_entity_id,
69          gfp.cost_type_id,
70          mthd.cost_type
71   INTO   l_le_id,
72          l_cost_type_id,
73          l_cost_type
74   FROM   gmf_fiscal_policies gfp,
75          cm_mthd_mst mthd,
76          org_organization_definitions ood,
77          mtl_parameters mp
78   WHERE  gfp.cost_type_id = mthd.cost_type_id
79        AND gfp.legal_entity_id = ood.legal_entity
80        AND ood.organization_id = p_organization_id
81        AND mp.organization_id = p_organization_id
82        AND mp.process_enabled_flag = 'Y'
83        AND mthd.delete_mark = 0
84        AND gfp.delete_mark  = 0
85        ;
86   EXCEPTION
87   WHEN NO_DATA_FOUND THEN
88     x_return_status := FND_API.G_RET_STS_ERROR;
89     x_msg_data := 'Invalid value for organization parameter or Invalid Cost Type or Invalid Fiscal Policy';
90     RETURN;
91   END;
92   /* If it is a lot cost type then its not supported */
93   IF (l_cost_type = 6) THEN
94     x_return_status := FND_API.G_RET_STS_ERROR;
95     x_msg_data      := 'Lot Cost Type is not applicable to retrieve Prior Period Cost';
96     RETURN;
97   END IF;
98 
99 
100   -- Get Prior Period End Date
101   OPEN cur_get_prior_period(l_le_id,l_cost_type_id,p_transaction_date);
102   FETCH cur_get_prior_period INTO l_prior_period_end_date;
103   CLOSE cur_get_prior_period;
104 
105   IF (l_prior_period_end_date IS NULL) THEN
106     x_return_status := FND_API.G_RET_STS_ERROR;
107     x_msg_data := 'No Prior Period for current transaction date.';
108     RETURN;
109   END IF;
110 
111   /* Call get cost routine from here */
112 
113   l_ret_val := GMF_CMCOMMON.Get_Process_Item_Cost (
114                      1.0
115                    , fnd_api.g_true
116                    , x_return_status
117                    , l_msg_count
118                    , x_msg_data
119                    , p_inventory_item_id
120                    , p_organization_id
121                    , l_prior_period_end_date
122                    , 1
123                    , l_cost_method
124                    , l_cost_component_class_id
125                    , l_cost_analysis_code
126                    , x_unit_cost
127                    , l_no_of_rows
128                    );
129 END Get_Prior_Period_Cost;
130 
131 END GMF_PROCESS_COST_PUB;