[Home] [Help]
PACKAGE BODY: APPS.WMS_CATCH_WEIGHT_GRP
Source
1 PACKAGE BODY WMS_CATCH_WEIGHT_GRP AS
2 /* $Header: WMSGCWTB.pls 115.7 2004/04/08 23:53:17 jsheu noship $ */
3
4 -- Global constant holding the package name
5 g_pkg_name CONSTANT VARCHAR2(30) := 'WMS_CATCH_WEIGHT_GRP';
6 g_pkg_version CONSTANT VARCHAR2(100) := '$Header: WMSGCWTB.pls 115.7 2004/04/08 23:53:17 jsheu noship $';
7
8 g_precision CONSTANT NUMBER := 5;
9
10 PROCEDURE print_debug( p_message VARCHAR2, p_level NUMBER ) IS
11 BEGIN
12 --dbms_output.put_line(p_message);
13 inv_log_util.trace(
14 p_message => p_message
15 , p_module => g_pkg_name
16 , p_level => p_level);
17 END print_debug;
18
19 FUNCTION Get_Default_Secondary_Quantity (
20 p_api_version IN NUMBER
21 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
22 , p_validation_level IN NUMBER := fnd_api.g_valid_level_full
23 , x_return_status OUT NOCOPY VARCHAR2
24 , x_msg_count OUT NOCOPY NUMBER
25 , x_msg_data OUT NOCOPY VARCHAR2
26 , p_organization_id IN NUMBER
27 , p_inventory_item_id IN NUMBER
28 , p_quantity IN NUMBER
29 , p_uom_code IN VARCHAR2
30 , x_secondary_quantity OUT NOCOPY NUMBER
31 , x_secondary_uom_code OUT NOCOPY VARCHAR2
32 ) RETURN VARCHAR2 IS
33 l_api_name CONSTANT VARCHAR2(30) := 'Get_Default_Secondary_Quantity';
34 l_api_version CONSTANT NUMBER := 1.0;
35 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
36 l_progress VARCHAR2(500) := '0';
37 l_msgdata VARCHAR2(1000);
38
39 -- Variables for validation
40 l_result NUMBER;
41 l_org inv_validate.org;
42 l_item inv_validate.item;
43
44 -- Variables for processing
45 l_tracking_quantity_ind VARCHAR2(30);
46 l_ont_pricing_qty_source VARCHAR2(30);
47 l_secondary_default_ind VARCHAR2(30);
48 l_secondary_quantity NUMBER;
49 l_secondary_uom_code VARCHAR2(3);
50 l_uom_deviation_high NUMBER;
51 l_uom_deviation_low NUMBER;
52
53 BEGIN
54 -- Standard call to check for call compatibility.
55 IF NOT fnd_api.compatible_api_call(l_api_version, p_api_version, l_api_name, g_pkg_name) THEN
56 fnd_message.set_name('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
57 fnd_msg_pub.ADD;
58 RAISE fnd_api.g_exc_error;
59 END IF;
60
61 -- Initialize message list if p_init_msg_list is set to TRUE.
62 IF fnd_api.to_boolean(p_init_msg_list) THEN
63 fnd_msg_pub.initialize;
64 END IF;
65
66 -- Initialize API return status to success
67 x_return_status := fnd_api.g_ret_sts_success;
68
69 IF ( l_debug = 1 ) THEN
70 print_debug(l_api_name || ' Entered ' || g_pkg_version, 1);
71 END IF;
72
73 IF ( p_validation_level <> fnd_api.g_valid_level_none ) THEN
74 l_progress := 'Validate Organization ID';
75 l_org.organization_id := p_organization_id;
76 l_result := inv_validate.ORGANIZATION(l_org);
77
78 IF ( l_result = inv_validate.f ) THEN
79 IF ( l_debug = 1 ) THEN
80 print_debug(p_organization_id || ' is not a valid org id', 1);
81 END IF;
82 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_ORG');
83 fnd_msg_pub.ADD;
84 RAISE fnd_api.g_exc_error;
85 END IF;
86
87 l_progress := 'Validate Inventory Item ID';
88 l_item.inventory_item_id := p_inventory_item_id;
89 l_result := inv_validate.inventory_item(l_item, l_org);
90
91 IF ( l_result = inv_validate.f ) THEN
92 IF (l_debug = 1) THEN
93 print_debug(p_inventory_item_id || ' is not a valid inventory item id', 1);
94 END IF;
95 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_ITEM');
96 fnd_msg_pub.ADD;
97 RAISE fnd_api.g_exc_error;
98 END IF;
99
100 l_progress := 'Validate Quantity';
101 IF ( p_quantity < 0 ) THEN
102 IF (l_debug = 1) THEN
103 print_debug(p_quantity ||' is not a valid quantity', 1);
104 END IF;
105 fnd_message.set_name('WMS', 'WMS_INVALID_QTY');
106 fnd_msg_pub.ADD;
107 RAISE fnd_api.g_exc_error;
108 END IF;
109
110 l_progress := 'Validate UOM code';
111 l_result := inv_validate.uom(p_uom_code, l_org, l_item);
112
113 IF ( l_result = inv_validate.f ) THEN
114 IF ( l_debug = 1 ) THEN
115 print_debug(p_uom_code || ' is an invalid UOM', 1);
116 END IF;
117 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_UOM');
118 fnd_msg_pub.ADD;
119 RAISE fnd_api.g_exc_error;
120 END IF;
121 END IF;
122
123 WMS_CATCH_WEIGHT_PVT.Get_Catch_Weight_Attributes (
124 p_api_version => 1.0
125 , x_return_status => x_return_status
126 , x_msg_count => x_msg_count
127 , x_msg_data => x_msg_data
128 , p_organization_id => p_organization_id
129 , p_inventory_item_id => p_inventory_item_id
130 , x_tracking_quantity_ind => l_tracking_quantity_ind
131 , x_ont_pricing_qty_source => l_ont_pricing_qty_source
132 , x_secondary_default_ind => l_secondary_default_ind
133 , x_secondary_quantity => l_secondary_quantity
134 , x_secondary_uom_code => x_secondary_uom_code
135 , x_uom_deviation_high => l_uom_deviation_high
136 , x_uom_deviation_low => l_uom_deviation_low );
137
138 IF ( x_return_status <> fnd_api.g_ret_sts_success ) THEN
139 IF ( l_debug = 1 ) THEN
140 print_debug('Call to Get_Catch_Weight_Attributes failed', 1);
141 END IF;
142 IF ( x_return_status = fnd_api.g_ret_sts_error ) THEN
143 RAISE FND_API.G_EXC_ERROR;
144 ELSE
145 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
146 END IF;
147 END IF;
148
149 l_progress := 'Got CW attributes';
150 -- If item is secondary priced and is not default restricted calculate the default
151 -- secondary value based off the secondary uom.
152 IF ( l_ont_pricing_qty_source = G_PRICE_SECONDARY ) THEN
153 IF ( x_secondary_uom_code IS NULL ) THEN
154 IF (l_debug = 1) THEN
155 print_debug('Secondary UOM is not defined for this secondary priced item', 1);
156 END IF;
157 fnd_message.set_name('WMS', 'WMS_SEC_UOM_UNDEF_ERROR');
158 fnd_msg_pub.ADD;
159 RAISE FND_API.G_EXC_ERROR;
160 END IF;
161
162 l_progress := 'Converting secondary qty';
163 x_secondary_quantity := inv_convert.inv_um_convert(
164 p_inventory_item_id
165 , g_precision
166 , p_quantity
167 , p_uom_code
168 , x_secondary_uom_code
169 , NULL
170 , NULL );
171 IF ( x_secondary_quantity < 0 ) THEN
172 IF ( l_debug = 1 ) THEN
173 print_debug('Error converting to from '||p_uom_code||' to '||x_secondary_uom_code, 1);
174 END IF;
175 fnd_message.set_name('INV', 'INV_UOM_CONVERSION_ERROR');
176 fnd_message.set_token('uom1', p_uom_code);
177 fnd_message.set_token('uom2', x_secondary_uom_code);
178 fnd_message.set_token('module', l_api_name);
179 fnd_msg_pub.ADD;
180 RAISE FND_API.G_EXC_ERROR;
181 END IF;
182 l_progress := 'Done converting secondary qty';
183 ELSE
184 x_secondary_quantity := NULL;
185 x_secondary_uom_code := NULL;
186 END IF;
187
188 IF ( l_debug = 1 ) THEN
189 print_debug(l_api_name || ' Exited ret='||l_ont_pricing_qty_source, 1);
190 print_debug('secqty='||x_secondary_quantity||' secuom='||x_secondary_uom_code, 4);
191 END IF;
192
193 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
194
195 RETURN l_ont_pricing_qty_source;
196 EXCEPTION
197 WHEN FND_API.G_EXC_ERROR THEN
198 x_return_status := fnd_api.g_ret_sts_error;
199 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
200 IF (l_debug = 1) THEN
201 FOR i in 1..x_msg_count LOOP
202 l_msgdata := substr(l_msgdata||' | '||substr(fnd_msg_pub.get(x_msg_count-i+1, 'F'), 0, 200),1,2000);
203 END LOOP;
204 print_debug(l_api_name ||' Error progress= '||l_progress||'SQL error: '|| SQLERRM(SQLCODE), 1);
205 print_debug('msg: '||l_msgdata, 1);
206 END IF;
207 RETURN NULL;
208 WHEN OTHERS THEN
209 x_return_status := fnd_api.g_ret_sts_unexp_error;
210 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
211 IF (l_debug = 1) THEN
212 print_debug(l_api_name ||' Error progress= '||l_progress||'SQL error: '|| SQLERRM(SQLCODE), 1);
213 END IF;
214 RETURN NULL;
215 END Get_Default_Secondary_Quantity;
216
217 END WMS_CATCH_WEIGHT_GRP;