[Home] [Help]
PACKAGE BODY: APPS.MTL_CCEOI_PROCESS_PVT
Source
1 PACKAGE BODY MTL_CCEOI_PROCESS_PVT AS
2 /* $Header: INVVCCPB.pls 120.12.12020000.7 2013/03/18 06:46:43 jianpyu ship $ */
3 G_PKG_NAME CONSTANT VARCHAR2(30) := 'MTL_CCEOI_PROCESS_PVT';
4
5
6 procedure mdebug(msg in varchar2)
7 is
8 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
9 begin
10 inv_log_util.trace(msg , g_pkg_name || ' ',9);
11 end;
12
13
14 /* Bug 5721960 -Added the procedure */
15
16 PROCEDURE GET_ITEM_COST(
17 p_organization_id IN NUMBER ,
18 p_inventory_item_id IN NUMBER ,
19 p_locator_id IN NUMBER ,
20 p_cost_group_id IN NUMBER,
21 x_item_cost OUT NOCOPY NUMBER )
22
23 IS
24 l_locator_id NUMBER := p_locator_id ;
25 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
26 --Begin Bug 16344740
27 l_process_enabled_flag VARCHAR2(1) := 'N';
28 l_result_code VARCHAR2(30);
29 l_return_status VARCHAR2(30);
30 l_msg_count NUMBER;
31 l_msg_data VARCHAR2(2000);
32 l_transaction_date DATE ;
33 l_cost_mthd VARCHAR2(15);
34 l_cmpntcls NUMBER;
35 l_analysis_code VARCHAR2(15);
36 l_no_of_rows NUMBER;
37 --End Bug 16344740
38 BEGIN
39
40 IF ( l_debug = 1 ) THEN
41 mdebug ( '***get_item_cost***' );
42 END IF;
43
44 IF ( l_locator_id = -1 ) THEN
45 l_locator_id := NULL;
46 END IF;
47 --Begin Bug16344740
48 BEGIN
49 SELECT NVL(process_enabled_flag, 'N') INTO l_process_enabled_flag
50 FROM mtl_parameters
51 WHERE organization_id = p_organization_id;
52 EXCEPTION
53 WHEN NO_DATA_FOUND THEN
54 l_process_enabled_flag := 'N';
55 END;
56 IF l_process_enabled_flag = 'Y' THEN
57 BEGIN
58 IF(l_debug = 1) THEN
59 mdebug('Calling GMF_CMCOMMON.Get_Process_Item_Cost');
60 END IF;
61 BEGIN
62 SELECT Nvl(count_date,SYSDATE)
63 INTO l_transaction_date
64 FROM MTL_CC_ENTRIES_INTERFACE
65 WHERE cc_entry_interface_id = MTL_CCEOI_VAR_PVT.G_cc_entry_interface_id;
66 EXCEPTION
67 WHEN NO_DATA_FOUND THEN
68 l_transaction_date := sysdate;
69 END;
70 l_result_code := GMF_CMCOMMON.Get_Process_Item_Cost
71 ( p_api_version => 1
72 , p_init_msg_list => 'F'
73 , x_return_status => l_return_status
74 , x_msg_count => l_msg_count
75 , x_msg_data => l_msg_data
76 , p_inventory_item_id => p_inventory_item_id
77 , p_organization_id => p_organization_id
78 , p_transaction_date => l_transaction_date /* Cost as on date */
79 , p_detail_flag => 1 /* 1 = total cost, 2 = details; 3 = cost for a specific component class/analysis code, etc. */
80 , p_cost_method => l_cost_mthd /* OPM Cost Method */
81 , p_cost_component_class_id => l_cmpntcls
82 , p_cost_analysis_code => l_analysis_code
83 , x_total_cost => x_item_cost /* total cost */
84 , x_no_of_rows => l_no_of_rows /* number of detail rows retrieved */
85 );
86
87 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
88 x_item_cost := 0;
89 END IF;
90
91 EXCEPTION
92 WHEN OTHERS THEN
93 x_item_cost := 0;
94 END;
95 IF(l_debug = 1) THEN
96 mdebug('OPM Item Cost: ' || x_item_cost);
97 END IF;
98 ELSE
99 -- End Bug 16344740
100 IF ( l_debug = 1 ) THEN
101 mdebug ( 'Value of org_id:'|| p_organization_id );
102 mdebug ( 'Value of item_id:'|| p_inventory_item_id );
103 mdebug ( 'Value of locator_id:'|| p_locator_id );
104 mdebug ( 'Value of cost_group_id:'|| p_cost_group_id );
105 END IF;
106
107 BEGIN
108 SELECT NVL ( ccicv.item_cost, 0 )
109 INTO x_item_cost
110 FROM cst_cg_item_costs_view ccicv,
111 mtl_parameters mp
112 WHERE l_locator_id IS NULL
113 AND ccicv.organization_id = p_organization_id
114 AND ccicv.inventory_item_id = p_inventory_item_id
115 AND ccicv.organization_id = mp.organization_id
116 AND ccicv.cost_group_id =
117 DECODE ( mp.primary_cost_method,
118 1, 1,
119 NVL ( p_cost_group_id , mp.default_cost_group_id)
120 )
121 UNION ALL
122 SELECT NVL ( ccicv.item_cost, 0 )
123 FROM mtl_item_locations mil,
124 cst_cg_item_costs_view ccicv,
125 mtl_parameters mp
126 WHERE l_locator_id IS NOT NULL
127 AND mil.organization_id = p_organization_id
128 AND mil.inventory_location_id = l_locator_id
129 AND mil.project_id IS NULL
130 AND ccicv.organization_id = mil.organization_id
131 AND ccicv.inventory_item_id = p_inventory_item_id
132 AND ccicv.organization_id = mp.organization_id
133 AND ccicv.cost_group_id =
134 DECODE ( mp.primary_cost_method,
135 1, 1,
136 NVL ( p_cost_group_id , mp.default_cost_group_id)
137 )
138 UNION ALL
139 SELECT NVL ( ccicv.item_cost, 0 )
140 FROM mtl_item_locations mil,
141 mrp_project_parameters mrp,
142 cst_cg_item_costs_view ccicv,
143 mtl_parameters mp
144 WHERE l_locator_id IS NOT NULL
145 AND mil.organization_id = p_organization_id
146 AND mil.inventory_location_id = l_locator_id
147 AND mil.project_id IS NOT NULL
148 AND mrp.organization_id = mil.organization_id
149 AND mrp.project_id = mil.project_id
150 AND ccicv.organization_id = mil.organization_id
151 AND ccicv.inventory_item_id = p_inventory_item_id
152 AND ccicv.organization_id = mp.organization_id
153 AND ccicv.cost_group_id =
154 DECODE ( mp.primary_cost_method,
155 1, 1,
156 NVL ( mrp.costing_group_id, 1 )
157 );
158 EXCEPTION
159 WHEN NO_DATA_FOUND THEN
160 x_item_cost := 0;
161 END;
162 END IF;
163 END GET_ITEM_COST;
164 /* End of fix for Bug 5721960 */
165
166
167 -- compute count due date
168 -- pre: MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC contains data
169 -- (call Validate_CountHeader) to fill it out
170 -- post: returns count due date or throws an exception if date cannot be found
171 -- because of invalid data in MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC or
172 -- if anything else goes wrong (e.g end of calendar)
173 function compute_count_due_date(p_date IN DATE) return DATE is
174 l_msg_count NUMBER;
175 l_msg_data VARCHAR2(240);
176 l_return_status VARCHAR2(1);
177 l_result_date DATE;
178 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
179 begin
180 mtl_inv_validate_grp.get_offset_date(
181 p_api_version => 0.9,
182 x_msg_count => l_msg_count,
183 x_msg_data => l_msg_data,
184 x_return_status => l_return_status,
185 p_calendar_code =>
186 mtl_cceoi_var_pvt.g_cycle_count_header_rec.cycle_count_calendar,
187 p_exception_set_id =>
188 mtl_cceoi_var_pvt.g_cycle_count_header_rec.calendar_exception_set,
189 p_start_date => p_date,
190 p_offset_days =>
191 mtl_cceoi_var_pvt.g_cycle_count_header_rec.days_until_late,
192 x_result_date => l_result_date);
193
194 IF (l_debug = 1) THEN
195 mdebug('Due date'||to_char(l_result_date));
196 END IF;
197 if (l_return_status <> fnd_api.g_ret_sts_success) then
198 IF (l_debug = 1) THEN
199 mdebug('error in due date computation');
200 END IF;
201 raise fnd_api.g_exc_unexpected_error;
202 end if;
203
204 return l_result_date;
205
206 end;
207
208 -- this procedure prevents reuse of global variables between calls to
209 -- the public api done within the same session
210 PROCEDURE Reset_Global_Vars
211 IS
212 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
213 BEGIN
214 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC := null;
215 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC := null;
216 MTL_CCEOI_VAR_PVT.G_OPEN_REQUEST := false;
217 MTL_CCEOI_VAR_PVT.G_SKU_REC := null;
218 MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_AMOUNT := null;
219 MTL_CCEOI_VAR_PVT.G_ADJ_VARIANCE_PERCENTAGE := null;
220 MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY := null;
221 MTL_CCEOI_VAR_PVT.G_ITEM_COST := null;
222 MTL_CCEOI_VAR_PVT.G_STOCK_LOCATOR_CONTROL_CODE := null;
223 MTL_CCEOI_VAR_PVT.G_SEQ_NO := null;
224 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID := null;
225 MTL_CCEOI_VAR_PVT.G_ITEM_LOCATOR_TYPE := null;
226 MTL_CCEOI_VAR_PVT.G_SUB_LOCATOR_TYPE := null;
227 MTL_CCEOI_VAR_PVT.G_INVENTORY_ITEM_ID := null;
228 MTL_CCEOI_VAR_PVT.G_ORIENTATION_CODE := null;
229 MTL_CCEOI_VAR_PVT.G_CC_HEADER_ID := null;
230 MTL_CCEOI_VAR_PVT.G_LOCATOR_ID := null;
231 MTL_CCEOI_VAR_PVT.G_PRIMARY_UOM_CODE := null;
232 MTL_CCEOI_VAR_PVT.G_UOM_CODE := null;
233 MTL_CCEOI_VAR_PVT.G_COUNT_QUANTITY := null;
234 MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY := null;
235 MTL_CCEOI_VAR_PVT.G_EMPLOYEE_ID := null;
236 MTL_CCEOI_VAR_PVT.G_COUNT_DATE := null;
237 MTL_CCEOI_VAR_PVT.G_SUBINVENTORY := null;
238 MTL_CCEOI_VAR_PVT.G_ADJUST_ACCOUNT_ID := null;
239 MTL_CCEOI_VAR_PVT.G_REC_IN_SYSTEM := true;
240 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP := null;
241
242 -- BEGIN INVCONV
243 MTL_CCEOI_VAR_PVT.G_TRACKING_QUANTITY_IND := null;
244 MTL_CCEOI_VAR_PVT.G_SECONDARY_DEFAULT_IND := null;
245 MTL_CCEOI_VAR_PVT.G_PROCESS_COSTING_ENABLED_FLAG := null;
246 MTL_CCEOI_VAR_PVT.G_PROCESS_ENABLED_FLAG := null;
247 MTL_CCEOI_VAR_PVT.G_SECONDARY_UOM_CODE := null;
248
249 MTL_CCEOI_VAR_PVT.G_SECONDARY_COUNT_UOM := null;
250 MTL_CCEOI_VAR_PVT.G_SECONDARY_COUNT_QUANTITY := null;
251 MTL_CCEOI_VAR_PVT.G_SECONDARY_SYSTEM_QUANTITY := null;
252 MTL_CCEOI_VAR_PVT.G_LPN_ITEM_SEC_SYSTEM_QTY := null;
253 MTL_CCEOI_VAR_PVT.G_SEC_ADJUSTMENT_QUANTITY := null;
254 -- END INVCONV
255
256 END;
257
258 --
259 --
260 -- Copy the current into the prior columns
261 PROCEDURE Current_To_Prior
262 IS
263 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
264 BEGIN
265 -- Start OF comments
266 -- API name : Current_to_Prior
267 -- TYPE : Private
268 -- Pre-reqs : None
269 -- FUNCTION :
270 -- this PROCEDURE SET the current VALUES of the open count request into
271 -- the system table mtl_cycle_count_entries to the prior column.
272 -- Parameters:
273 -- IN :
274 -- OUT :
275 -- Version: Current Version 0.9
276 -- Changed : Nothing
277 -- No Previous Version 0.0
278 -- Initial version 0.9
279 -- Notes : Note text
280 -- END OF comments
281 DECLARE
282 --
283 dummy integer;
284 BEGIN
285 ---
286 -- SET the current DATE to the pri0r DATE
287 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_DATE_PRIOR:=
288 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.COUNT_DATE_CURRENT;
289 --
290 -- SET the current counter to prior
291 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNTED_BY_EMPLOYEE_ID_PRIOR :=
292 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.COUNTED_BY_EMPLOYEE_ID_CURRENT;
293 --
294 -- SET the COUNT uom to prior
295 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_UOM_PRIOR :=
296 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.COUNT_UOM_CURRENT;
297 --
298 -- SET the current COUNT quantity to first
299 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_QUANTITY_PRIOR :=
300 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.COUNT_QUANTITY_CURRENT;
301 --
302 -- SET the current system quanity to first
303 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SYSTEM_QUANTITY_PRIOR :=
304 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.SYSTEM_QUANTITY_CURRENT;
305 --
306 -- SET the primary uom quantity
307 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.PRIMARY_UOM_QUANTITY_PRIOR :=
308 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.PRIMARY_UOM_QUANTITY_CURRENT;
309 --
310 -- SET the current refernce to first
311 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.REFERENCE_PRIOR :=
312 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.REFERENCE_CURRENT;
313 --
314
315 -- BEGIN INVCONV
316 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_SECONDARY_UOM_PRIOR :=
317 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.COUNT_SECONDARY_UOM_CURRENT;
318 --
319 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SECONDARY_UOM_QUANTITY_PRIOR :=
320 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.SECONDARY_UOM_QUANTITY_CURRENT;
321 --
322 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SECONDARY_SYSTEM_QTY_PRIOR :=
323 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.SECONDARY_SYSTEM_QTY_CURRENT;
324 -- END INVCONV
325
326 END;
327 END;
328
329 --
330 -- Propagates info about first count into updated record
331 PROCEDURE Propagate_First
332 IS
333 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
334 BEGIN
335 -- propagate first count date
336 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_DATE_FIRST :=
337 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.COUNT_DATE_FIRST;
338
339 -- propagate id of employee who first counted the record
340 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNTED_BY_EMPLOYEE_ID_FIRST :=
341 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.COUNTED_BY_EMPLOYEE_ID_FIRST;
342
343 -- propagate count uom used in thefirst count
344 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_UOM_FIRST :=
345 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.COUNT_UOM_FIRST;
346
347 -- propagate count quantity found in the first count
348 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_QUANTITY_FIRST :=
349 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.COUNT_QUANTITY_FIRST;
350
351 -- propagate system quantity for the first count
352 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SYSTEM_QUANTITY_FIRST :=
353 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.SYSTEM_QUANTITY_FIRST;
354
355 -- propagate primary uom quantity for the first count
356 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.PRIMARY_UOM_QUANTITY_FIRST :=
357 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.PRIMARY_UOM_QUANTITY_FIRST;
358
359 -- propagate reference used in the first count
360 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.REFERENCE_FIRST :=
361 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.REFERENCE_FIRST;
362
363 -- BEGIN INVCONV
364 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_SECONDARY_UOM_FIRST :=
365 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.COUNT_SECONDARY_UOM_FIRST;
366 --
367 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SECONDARY_UOM_QUANTITY_FIRST :=
368 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.SECONDARY_UOM_QUANTITY_FIRST;
369 --
370 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SECONDARY_SYSTEM_QTY_FIRST :=
371 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.SECONDARY_SYSTEM_QTY_FIRST;
372 -- END INVCONV
373 END;
374
375 --
376 -- Current information into first information.
377 PROCEDURE Current_To_First(
378 p_reference IN VARCHAR2 DEFAULT NULL,
379 p_primary_uom_quantity IN NUMBER )
380 IS
381 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
382 BEGIN
383 -- Start OF comments
384 -- API name : Current_to_first
385 -- TYPE : Private
386 -- Pre-reqs : None
387 -- FUNCTION :
388 -- this PROCEDURE SET the current VALUES to first. IF this
389 -- IS the first time to INSERT an entry.
390 -- Parameters:
391 -- IN :
392 -- p_reference VARCHAR2(240) (optional)
393 -- default NULL
394 --
395 -- p_primary_uom_quantity IN NUMBER (required)
396 -- primary uom quantity
397 --
398 -- OUT :
399 --
400 -- Version: Current Version 0.9
401 -- Changed : Nothing
402 -- No Previous Version 0.0
403 -- Initial version 0.9
404 -- Notes : Note text
405 -- END OF comments
406 DECLARE
407 --
408 dummy integer;
409 BEGIN
410 ---
411 -- SET the current DATE to the first DATE
412 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_DATE_FIRST :=
413 MTL_CCEOI_VAR_PVT.G_COUNT_DATE;
414 --
415 -- SET the current counter to first
416 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNTED_BY_EMPLOYEE_ID_FIRST :=
417 MTL_CCEOI_VAR_PVT.G_EMPLOYEE_ID;
418 --
419 -- SET the COUNT uom to first
420 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_UOM_FIRST :=
421 MTL_CCEOI_VAR_PVT.G_UOM_CODE;
422 --
423 -- SET the current COUNT quantity to first
424 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_QUANTITY_FIRST :=
425 MTL_CCEOI_VAR_PVT.G_COUNT_QUANTITY;
426 --
427 -- SET the current system quanity to first
428 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SYSTEM_QUANTITY_FIRST :=
429 MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY;
430 --
431 -- SET the primary uom quantity
432 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.PRIMARY_UOM_QUANTITY_FIRST :=
433 p_primary_uom_quantity;
434 --
435 -- SET the current refernce to first
436 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.REFERENCE_FIRST :=
437 p_reference;
438 --
439
440 -- BEGIN INVCONV
441 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_SECONDARY_UOM_FIRST :=
442 MTL_CCEOI_VAR_PVT.G_SECONDARY_COUNT_UOM;
443 --
444 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SECONDARY_UOM_QUANTITY_FIRST :=
445 MTL_CCEOI_VAR_PVT.G_SECONDARY_COUNT_QUANTITY;
446 --
447 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SECONDARY_SYSTEM_QTY_FIRST :=
448 MTL_CCEOI_VAR_PVT.G_SECONDARY_SYSTEM_QUANTITY;
449 -- END INVCONV
450
451 END;
452 END;
453 -- Puts the entry values into current values.
454 PROCEDURE entry_to_current(
455 p_reference IN VARCHAR2 DEFAULT NULL,
456 p_primary_uom_quantity IN NUMBER )
457 IS
458 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
459 BEGIN
460 -- Start OF comments
461 -- API name : Entry_to_Current
462 -- TYPE : Private
463 -- Pre-reqs : None
464 -- FUNCTION :
465 -- Parameters:
466 -- IN :
467 -- p_reference IN VARCHAR2(240) (optional)
468 -- default NULL, IS LIKE a note what IS happened
469 -- Version: Current Version 0.9
470 -- Changed : Nothing
471 -- No Previous Version 0.0
472 -- Initial version 0.9
473 -- Notes : Note text
474 -- END OF comments
475 DECLARE
476 --
477 dummy integer;
478 BEGIN
479 --
480 -- SET the actual interface COUNT DATE to the current
481 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_DATE_CURRENT :=
482 MTL_CCEOI_VAR_PVT.G_COUNT_DATE;
483 --
484 -- SET current counter
485 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNTED_BY_EMPLOYEE_ID_CURRENT :=
486 MTL_CCEOI_VAR_PVT.G_EMPLOYEE_ID;
487 --
488 -- SET COUNT uom
489 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_UOM_CURRENT :=
490 MTL_CCEOI_VAR_PVT.G_UOM_CODE;
491 --
492 -- SET the COUNT quantity
493 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_QUANTITY_CURRENT:=
494 MTL_CCEOI_VAR_PVT.G_COUNT_QUANTITY;
495 --
496 -- SET the current system quantity
497 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SYSTEM_QUANTITY_CURRENT:=
498 MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY;
499 --
500 -- SET the primary uom quantity
501 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.PRIMARY_UOM_QUANTITY_CURRENT :=
502 p_primary_uom_quantity;
503 --
504 -- SET the current reference
505 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.REFERENCE_CURRENT:=
506 p_reference;
507 --
508
509 -- BEGIN INVCONV
510 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_SECONDARY_UOM_CURRENT :=
511 MTL_CCEOI_VAR_PVT.G_SECONDARY_COUNT_UOM;
512 --
513 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SECONDARY_UOM_QUANTITY_CURRENT :=
514 MTL_CCEOI_VAR_PVT.G_SECONDARY_COUNT_QUANTITY;
515 --
516 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SECONDARY_SYSTEM_QTY_CURRENT :=
517 MTL_CCEOI_VAR_PVT.G_SECONDARY_SYSTEM_QUANTITY;
518 -- END INVCONV
519 END;
520 END;
521 -- Final update logic.
522 PROCEDURE Final_Preupdate_Logic(
523 p_reference IN VARCHAR2 DEFAULT NULL,
524 p_primary_uom_quantity IN NUMBER ,
525 p_count_uom IN VARCHAR2 ,
526 p_serial_number IN VARCHAR2 ,
527 p_subinventory IN VARCHAR2 ,
528 p_lot_number IN VARCHAR2 ,
529 p_lot_expiration IN date ,
530 p_revision IN VARCHAR2 ,
531 p_transaction_reason_id IN NUMBER ,
532 p_transaction_process_mode IN NUMBER DEFAULT 3,
533 p_simulate IN VARCHAR2 DEFAULT FND_API.G_FALSE)
534 IS
535 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
536 BEGIN
537 -- Start OF comments
538 -- API name : Final_Update_Logic
539 -- TYPE : Private
540 -- Pre-reqs : None
541 -- FUNCTION :
542 -- Parameters:
543 -- IN :
544 -- p_reference IN VARCHAR2 (optional)
545 -- default NULL
546 --
547 -- p_primary_uom_quantity IN NUMBER -- only useful for update of
548 -- interface tables
549 --
550 -- p_count_uom IN VARCHAR2 (required) XXX will not work if count qty
551 -- is entered through primary_uomqty
552 --
553 -- p_subinventory IN VARCHAR2(required)
554 --
555 -- p_lot_number IN VARCHAR2 (required)
556 --
557 -- p_lot_expiration_date DATE (required)
558 --
559 -- p_revision IN VARCHAR2(required)
560 --
561 -- p_transaction_reasion_id IN NUMBER (required)
562 --
563 -- p_serial_number IN VARCHAR2 (required)
564 --
565 -- p_transaction_process_mode IN NUMBER (required-defaulted)
566 -- default = 3 (Background processing) this parameter is not really used
567 -- since the only way the processing can be done now is in background mode
568 --
569 -- p_simulate IN VARCHAR2 (defaulted)
570 -- default = FND_API.G_FALSE may modify tables other than interface
571 -- FND_API.G_TRUE - may modify only interface tables
572 --
573 -- OUT :
574 -- Version: Current Version 0.9
575 -- Changed : Nothing
576 -- No Previous Version 0.0
577 -- Initial version 0.9
578 -- Notes : Note text
579 -- END OF comments
580 DECLARE
581 --
582 L_from_uom MTL_CYCLE_COUNT_ENTRIES.COUNT_UOM_CURRENT%type;
583 L_txn_uom MTL_CYCLE_COUNT_ENTRIES.COUNT_UOM_CURRENT%type;
584 L_txn_header_id NUMBER;
585 L_txn_temp_id NUMBER;
586 L_serial_prefix MTL_SYSTEM_ITEMS.auto_serial_alpha_prefix%type;
587 L_p_uom_qty NUMBER;
588 L_number_of_counts NUMBER;
589 L_success_flag NUMBER;
590 L_org_id MTL_CYCLE_COUNT_ENTRIES.ORGANIZATION_ID%type;
591 l_txn_return_status NUMBER; -- 8712932
592 l_proc_msg VARCHAR2(3000);
593 l_business_flow_code NUMBER := 8 ;
594
595
596 l_transaction_reason_id number; -- bug 14828280
597
598 --
599 BEGIN
600 --
601 IF (l_debug = 1) THEN
602 MDEBUG( 'Process- Inside Final-Pre-update ');
603 MDEBUG( 'p_transaction_reason_id::'||p_transaction_reason_id);
604 END IF;
605
606
607 l_transaction_reason_id := p_transaction_reason_id; -- bug 14828280
608
609 IF MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.entry_status_code = 5 THEN
610 --
611 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.APPROVAL_DATE := sysdate;
612 --
613 END IF;
614 --
615 L_number_of_counts :=
616 (NVL(MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.number_of_counts, 0) + 1);
617 --
618 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.NUMBER_OF_COUNTS :=
619 L_number_of_counts;
620 --
621
622 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.transaction_reason_id := l_transaction_reason_id; -- bug 14828280
623
624 IF (l_debug = 1) THEN
625 mdebug('Final_Preupdate_Logic: Number of counts => ' || L_number_of_Counts);
626 END IF;
627
628 IF L_number_of_counts = 1 THEN
629 --
630 Entry_To_Current(p_reference => p_reference
631 , p_primary_uom_quantity => p_primary_uom_quantity);
632 --
633 Current_To_First(
634 p_reference => p_reference
635 , p_primary_uom_quantity => p_primary_uom_quantity
636 );
637 --
638 ELSE
639 --
640 Propagate_First;
641 --
642 Current_To_Prior;
643 --
644 Entry_To_Current(
645 p_reference => p_reference
646 , p_primary_uom_quantity => p_primary_uom_quantity);
647 --
648 END IF;
649 --
650 L_from_uom := p_count_uom;
651 L_txn_uom := L_from_uom;
652 --
653 IF (l_debug = 1) THEN
654 MDEBUG( 'Process-Inside F-P-Update Logic: '|| to_char(MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.entry_status_code));
655 MDEBUG( 'F-P-U :AdjQty= '||to_char(MTL_CCEOI_VAR_PVT.G_adjustment_quantity));
656 MDEBUG( 'F-P-U :SecAdjQty= '||to_char(MTL_CCEOI_VAR_PVT.g_sec_adjustment_quantity)); -- INVCONV
657 MDEBUG( 'F-P-U : '||p_simulate);
658 END IF;
659
660 IF MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.entry_status_code = 5
661 AND MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY <> 0
662 AND NOT FND_API.to_Boolean(p_simulate)
663 THEN
664 --
665 IF (l_debug = 1) THEN
666 MDEBUG( 'F-P-U-Inside the If value ');
667 END IF;
668 SELECT mtl_material_transactions_s.nextval
669 INTO
670 L_txn_header_id
671 FROM
672 dual;
673 --
674 IF(p_serial_number IS NOT NULL) THEN
675 --
676 SELECT mtl_material_transactions_s.nextval
677 INTO
678 L_txn_temp_id
679 FROM
680 dual;
681 --
682 SELECT auto_serial_alpha_prefix
683 INTO
684 L_serial_prefix
685 FROM
686 mtl_system_items
687 WHERE
688 inventory_item_id = MTL_CCEOI_VAR_PVT.G_inventory_item_id
689 AND organization_id =
690 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.organization_id;
691 --
692 END IF;
693 --
694 L_org_id:= MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.organization_id;
695 --bug 8526579 made the inv_convert call lot specific to honor lot specific conversions
696 L_p_uom_qty := inv_convert.inv_um_convert(
697 item_id => MTL_CCEOI_VAR_PVT.G_INVENTORY_ITEM_ID
698 ,lot_number=>p_lot_number
699 ,organization_id=>L_org_id
700 , precision => 5
701 , from_quantity => MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY
702 , from_unit => MTL_CCEOI_VAR_PVT.G_UOM_CODE -- L_from_uom
703 , to_unit => MTL_CCEOI_VAR_PVT.G_PRIMARY_UOM_CODE
704 , from_name => NULL
705 , to_name => NULL);
706
707
708 --
709 IF (l_debug = 1) THEN
710 MDEBUG( 'Process-Tolerence:Update Adj Amt ');
711 MDEBUG( 'Account Id '||to_char(MTL_CCEOI_VAR_PVT.G_ADJUST_ACCOUNT_ID));
712 MDEBUG( 'Count Dt '||fnd_date.date_to_canonical(MTL_CCEOI_VAR_PVT.g_count_date));
713 MDEBUG( 'Subinv '||p_subinventory);
714 MDEBUG( 'CountUOM '||p_count_uom);
715 MDEBUG( 'CCEId '||to_char(MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.cycle_count_entry_id));
716 mdebug('serial number='||p_serial_number);
717 END IF;
718
719 IF (l_debug = 1) THEN
720 mdebug('Making a transaction. txn_hdr_id='||L_txn_header_id);
721 mdebug('Making a transaction. txn_tmp_id='||L_txn_temp_id);
722 END IF;
723
724 -- delete record
725 DELETE_RESERVATION (p_subinventory, p_lot_number, p_revision);
726
727 L_success_flag := mtl_cc_transact_pkg.cc_transact(
728 org_id=>
729 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.organization_id
730 , cc_header_id => MTL_CCEOI_VAR_PVT.G_cc_header_id
731 , item_id => MTL_CCEOI_VAR_PVT.G_inventory_item_id
732 , sub=> p_subinventory
733 , PUOMQty=>L_p_uom_qty
734 , TxnQty=>MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY
735 , TxnUOM=> MTL_CCEOI_VAR_PVT.G_UOM_CODE -- p_count_uom
736 , TxnDate=>MTL_CCEOI_VAR_PVT.G_count_date
737 , TxnAcctId=>MTL_CCEOI_VAR_PVT.G_ADJUST_ACCOUNT_ID
738 , LotNum=>p_lot_number
739 , LotExpDate=>p_lot_expiration
740 , rev=>p_revision
741 , locator_id=>MTL_CCEOI_VAR_PVT.G_locator_id
742 , TxnRef=>p_reference
743 , ReasonId=> p_transaction_reason_id
744 , UserId=> MTL_CCEOI_VAR_PVT.G_userid
745 , cc_entry_id=>
746 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.cycle_count_entry_id
747 , LoginId => MTL_CCEOI_VAR_PVT.G_LoginId
748 , TxnProcMode => 3 -- p_transaction_process_mode
749 , TxnHeaderId=>L_txn_header_id
750 , SerialNum=>P_serial_number
751 , TxnTempId=>L_txn_temp_id
752 , SerialPrefix=>L_serial_prefix
753 , lpn_id => MTL_CCEOI_VAR_PVT.G_LPN_ID
754 , cost_group_id => MTL_CCEOI_VAR_PVT.G_COST_GROUP_ID
755 -- BEGIN INVCONV
756 , secUOM => MTL_CCEOI_VAR_PVT.G_SECONDARY_COUNT_UOM
757 , secQty => MTL_CCEOI_VAR_PVT.G_SEC_ADJUSTMENT_QUANTITY
758 -- END INVCONV
759 );
760 -- 8712932 Start
761 -- Calling the transaction maanger to process the temp records for adjustments to be processed.
762 l_txn_return_status :=
763 INV_LPN_TRX_PUB.PROCESS_LPN_TRX ( p_trx_hdr_id => l_txn_header_id,
764 x_proc_msg => l_proc_msg,
765 p_business_flow_code => l_business_flow_code
766 );
767 IF ( l_debug = 1 ) THEN
768 mdebug ( 'Txn return status: ' || l_txn_return_status );
769 END IF;
770
771 IF ( l_txn_return_status <> 0 ) THEN
772 -- This 'Transaction Failed' message is set on the java side
773
774 RAISE FND_API.G_EXC_ERROR;
775 mdebug ( 'Txn failed');
776 END IF;
777
778 -- 8712932 End
779 IF (l_debug = 1) THEN
780 MDEBUG( 'Process-Tolerence:Update Adj Amt Flag '||L_success_flag);
781 END IF;
782 IF NVL(L_txn_header_id, -1) < 0
783 OR NVL(L_success_flag, -1) < 0 THEN
784 --
785 FND_MESSAGE.SET_NAME('INV', 'INV_ADJ_TXN_FAILED');
786 APP_EXCEPTION.RAISE_EXCEPTION;
787 IF (l_debug = 1) THEN
788 MDEBUG( 'Process-Tolerence : Adj Failed ');
789 END IF;
790 --
791 END IF;
792 --
793 /* MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ADJUSTMENT_DATE := sysdate;
794 MTL_CCEOI_VAR_PVT.G_COMMIT_STATUS_FLAG := '1';
795 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.INVENTORTY_ADJUST_ACCOUNT :=
796 MTL_CCEOI_VAR_PVT.G_ADJUST_ACCOUNT_ID;
797 */
798 --
799 END IF;
800 IF (l_debug = 1) THEN
801 MDEBUG( 'Process-Tolerence : End of Adj Qty process ');
802 END IF;
803 END;
804 END;
805 --
806 -- in tolerance.
807 PROCEDURE in_Tolerance(
808 p_reference VARCHAR2 ,
809 p_primary_uom_quantity NUMBER ,
810 p_count_uom VARCHAR2 ,
811 p_subinventory VARCHAR2 ,
812 p_lot_number VARCHAR2 ,
813 p_lot_expiration_date DATE ,
814 p_revision VARCHAR2 ,
815 p_transaction_reason_id NUMBER ,
816 p_serial_number VARCHAR2 ,
817 p_transaction_process_mode NUMBER ,
818 p_simulate IN VARCHAR2 DEFAULT FND_API.G_FALSE)
819 IS
820 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
821 BEGIN
822 -- Start OF comments
823 -- API name : In_TOLERANCE
824 -- TYPE : Private
825 -- Pre-reqs : None
826 -- FUNCTION :
827 -- Parameters:
828 -- IN :
829 -- p_reference IN VARCHAR2 (optional)
830 -- default NULL
831 --
832 -- p_primary_uom_quantity IN NUMBER
833 --
834 -- p_count_uom IN VARCHAR2 (required)
835 --
836 -- p_subinventory IN VARCHAR2(required)
837 --
838 -- p_lot_number IN VARCHAR2 (required)
839 --
840 -- p_lot_expiration_date DATE (required)
841 --
842 -- p_revision IN VARCHAR2(required)
843 --
844 -- p_transaction_reasion_id IN NUMBER (required)
845 --
846 -- p_serial_number IN VARCHAR2 (required)
847 --
848 -- p_transaction_process_mode IN NUMBER (required-defaulted)
849 -- default = 3 (Background processing)
850 --
851 -- p_simulate in varchar2 (defaulted FND_API.G_FALSE)
852 -- G_FALSE - may modify data in tables other than ccoi interface
853 -- G_TRUE - may not modify data in tables othert than ccoi interface
854
855 -- OUT :
856 -- Version: Current Version 0.9
857 -- Changed : Nothing
858 -- No Previous Version 0.0
859 -- Initial version 0.9
860 -- Notes : Note text
861 -- END OF comments
862 DECLARE
863 --
864 dummy integer;
865 --
866 BEGIN
867 IF (MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.approval_option_code = 1
868 AND MTL_CCEOI_VAR_PVT.G_LPN_ID IS NULL)
869 OR (MTL_CCEOI_VAR_PVT.G_LPN_ID IS NOT NULL
870 AND MTL_CCEOI_VAR_PVT.G_CONTAINER_ENABLED_FLAG = 1
871 AND (MTL_CCEOI_VAR_PVT.G_CONTAINER_ADJUSTMENT_OPTION = 2
872 OR MTL_CCEOI_VAR_PVT.G_CONTAINER_DISCREPANCY_OPTION = 2)
873 )
874 THEN
875 --
876 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 2;
877 --
878 ELSE
879 --
880 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 5;
881 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.APPROVAL_TYPE := 1;
882 --
883 END IF;
884 --
885 Final_Preupdate_Logic(
886 p_reference => p_reference
887 , p_primary_uom_quantity => p_primary_uom_quantity
888 , p_count_uom => p_count_uom
889 , p_serial_number => p_serial_number
890 , p_subinventory => p_subinventory
891 , p_lot_number => p_lot_number
892 , p_lot_expiration => p_lot_expiration_date
893 , p_revision => p_revision
894 , p_transaction_reason_id => p_transaction_reason_id
895 , p_transaction_process_mode => p_transaction_process_mode
896 , p_simulate => p_simulate);
897 --
898 END;
899 END;
900 --
901 -- Out of tolerance.
902 PROCEDURE Out_Of_Tolerance(
903 p_reference VARCHAR2 ,
904 p_primary_uom_quantity NUMBER ,
905 p_count_uom VARCHAR2 ,
906 p_subinventory VARCHAR2 ,
907 p_lot_number VARCHAR2 ,
908 p_lot_expiration_date DATE ,
909 p_revision VARCHAR2 ,
910 p_transaction_reason_id NUMBER ,
911 p_serial_number VARCHAR2 ,
912 p_transaction_process_mode NUMBER ,
913 p_simulate IN VARCHAR2 DEFAULT FND_API.G_FALSE)
914 IS
915 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
916 BEGIN
917 -- Start OF comments
918 -- API name : out_OF_TOLERANCE
919 -- TYPE : Private
920 -- Pre-reqs : None
921 -- FUNCTION :
922 -- Parameters:
923 -- IN :
924 -- p_reference IN VARCHAR2 (optional)
925 -- default NULL
926 --
927 -- p_primary_uom_quantity IN NUMBER
928 --
929 -- p_count_uom IN VARCHAR2 (required)
930 --
931 -- p_subinventory IN VARCHAR2(required)
932 --
933 -- p_lot_number IN VARCHAR2 (required)
934 --
935 -- p_lot_expiration_date DATE (required)
936 --
937 -- p_revision IN VARCHAR2(required)
938 --
939 -- p_transaction_reasion_id IN NUMBER (required)
940 --
941 -- p_serial_number IN VARCHAR2 (required)
942 --
943 -- p_transaction_process_mode IN NUMBER (required-defaulted)
944 -- default = 3 (Background processing)
945 --
946 -- p_simulate in varchar2 (defaulted FND_API.G_FALSE)
947 -- G_FALSE - may modify data in tables other than cc interface
948 -- G_TRUE - may not modify data in tables other than cc interface
949 -- OUT :
950 -- Version: Current Version 0.9
951 -- Changed : Nothing
952 -- No Previous Version 0.0
953 -- Initial version 0.9
954 -- Notes : Note text
955 -- END OF comments
956 DECLARE
957 --
958 dummy integer;
959 --
960 BEGIN
961 IF MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.automatic_recount_flag <> 1
962 THEN
963 IF (MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.approval_option_code = 2
964 AND MTL_CCEOI_VAR_PVT.G_LPN_ID IS NULL)
965 OR (MTL_CCEOI_VAR_PVT.G_LPN_ID IS NOT NULL
966 AND MTL_CCEOI_VAR_PVT.G_CONTAINER_ENABLED_FLAG = 1
967 AND MTL_CCEOI_VAR_PVT.G_CONTAINER_ADJUSTMENT_OPTION = 1
968 AND MTL_CCEOI_VAR_PVT.G_CONTAINER_DISCREPANCY_OPTION = 1)
969 THEN
970 --
971 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 5;
972 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.APPROVAL_TYPE := 1;
973 --
974 ELSE
975 --
976 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 2;
977 --
978 END IF;
979 ELSE
980 IF NVL(MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.NUMBER_OF_COUNTS, 0) <
981 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.MAXIMUM_AUTO_RECOUNTS THEN
982 --
983 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 3;
984
985 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_DUE_DATE :=
986 Compute_Count_Due_Date(sysdate);
987 --
988 ELSE
989 --
990 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 2;
991 --
992 END IF;
993 END IF;
994 Final_Preupdate_Logic(
995 p_reference => p_reference
996 , p_primary_uom_quantity => p_primary_uom_quantity
997 , p_count_uom => p_count_uom
998 , p_serial_number => p_serial_number
999 , p_subinventory => p_subinventory
1000 , p_lot_number => p_lot_number
1001 , p_lot_expiration => p_lot_expiration_date
1002 , p_revision => p_revision
1003 , p_transaction_reason_id => p_transaction_reason_id
1004 , p_transaction_process_mode => p_transaction_process_mode
1005 , p_simulate => p_simulate);
1006 --
1007 END;
1008 END;
1009 --
1010 PROCEDURE Tolerance_Logic(
1011 p_pos_meas_err IN NUMBER ,
1012 p_neg_meas_err IN NUMBER ,
1013 p_app_tol_pos IN NUMBER ,
1014 p_app_tol_neg IN NUMBER ,
1015 p_cost_tol_pos IN NUMBER ,
1016 p_cost_tol_neg IN NUMBER ,
1017 p_adjustment_value IN NUMBER ,
1018 p_adjustment_quantity IN NUMBER ,
1019 p_system_quantity IN NUMBER ,
1020 p_approval_option_code IN NUMBER ,
1021 p_interface_rec IN MTL_CCEOI_VAR_PVT.INV_CCEOI_TYPE ,
1022 p_simulate IN VARCHAR2 DEFAULT FND_API.G_FALSE)
1023 IS
1024 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1025 BEGIN
1026 -- Start OF comments
1027 -- API name : Tolerance_logic
1028 -- TYPE : Private
1029 -- Pre-reqs : None
1030 -- FUNCTION :
1031 -- Parameters:
1032 -- IN :
1033 -- p_pos_meas_err IN NUMBER (required)
1034 -- MTL_CYCLE_COUNT_ENTRIES_V.POSITIVE_MEASUREMENT_ERROR
1035 --
1036 -- p_neg_meas_err IN NUMBER (required)
1037 -- MTL_CYCLE_COUNT_ENTRIES_V.NEGATIVE_MEASUREMENT_ERROR
1038 --
1039 -- p_app_tol_pos IN NUMBER (required)
1040 -- MTL_CYCLE_COUNT_ENTRIES_V.APP_TOL_POS
1041 --
1042 -- p_app_tol_neg IN NUMBER (required)
1043 -- MTL_CYCLE_COUNT_ENTRIES_V.APP_TOL_NEG
1044 --
1045 -- p_cost_tol_pos IN NUMBER (required)
1046 -- MTL_CYCLE_COUNT_ENTRIES_V.COST_TOL_POS
1047 --
1048 -- p_cost_tol_neg IN NUMBER (required)
1049 -- MTL_CYCLE_COUNT_ENTRIES_V.COST_TOL_NEG
1050 --
1051 -- p_adjustment_value IN NUMBER (required)
1052 -- MTL_CYCLE_COUNT_ENTRIES_V.ADJUSTMENT_AMOUNT
1053 --
1054 -- p_adjustment_quantity IN NUMBER (required)
1055 -- get the value FROM the global variable
1056 -- MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY
1057 -- MTL_CYCLE_COUNT_ENTRIES.ADJUSTMENT_QUANTITY
1058 --
1059 -- p_system_quantity IN NUMBER (required)
1060 -- gets the value FROM the global variable
1061 -- MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY
1062 -- MTL_CYCLE_COUNT_ENTRIES.SYSTEM_QUANTITY_CURRENT
1063 --
1064 -- p_approval_option_code IN NUMBER (required)
1065 -- MTL_CYCLE_COUNT_HEADERS.APPROVAL_OPTION_CODE
1066 --
1067 -- p_interface_rec IN MTL_CC_ENTRIES_INTERFACE%rowtype
1068 --
1069 -- p_simulate IN varchar2 (default)
1070 -- default = FND_API.G_FALSE - may modify data in other tables
1071 -- FND_API.G_TRUE modify data only in the interface tables
1072 --
1073 -- OUT :
1074 -- Version: Current Version 0.9
1075 -- Changed : Nothing
1076 -- No Previous Version 0.0
1077 -- Initial version 0.9
1078 -- Notes : Note text
1079 -- END OF comments
1080 DECLARE
1081 --
1082 dummy integer;
1083 l_contianer_enabled_flag NUMBER := NULL;
1084 l_contianer_adjustment_option NUMBER := NULL;
1085 l_container_decrepancy_option NUMBER := NULL;
1086 BEGIN
1087 --
1088 IF (l_debug = 1) THEN
1089 MDEBUG( 'Process-Tolerance Logic ');
1090 END IF;
1091
1092 -- Approval option = Always
1093 -- p_approval_option_code = 1 is applicable only when lpn_id is null
1094 -- if lpn_id is not null, check container_adjustment_option = 2
1095 IF (p_approval_option_code = 1 AND p_interface_rec.parent_lpn_id IS NULL) OR
1096 ( p_interface_rec.parent_lpn_id IS NOT NULL
1097 AND MTL_CCEOI_VAR_PVT.G_CONTAINER_ENABLED_FLAG = 1
1098 AND ( MTL_CCEOI_VAR_PVT.G_CONTAINER_ADJUSTMENT_OPTION = 2
1099 OR MTL_CCEOI_VAR_PVT.G_CONTAINER_DISCREPANCY_OPTION = 2 )
1100 )
1101 THEN
1102 --
1103 IF p_adjustment_quantity <> 0 THEN
1104 --
1105 IF p_system_quantity <> 0 THEN
1106 --
1107 IF p_adjustment_quantity < 0 THEN
1108 --
1109 IF p_neg_meas_err IS NOT NULL AND
1110 ABS((p_adjustment_quantity/ p_system_quantity) *100) < p_neg_meas_err THEN
1111 --
1112 -- No adjustments are required
1113 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 5;
1114 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ADJUSTMENT_QUANTITY := 0;
1115 MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY := 0;
1116 --
1117 IF (l_debug = 1) THEN
1118 MDEBUG( 'Tol : before final-pre-update-logic');
1119 END IF;
1120 Final_Preupdate_Logic(
1121 p_reference => p_interface_rec.reference
1122 , p_primary_uom_quantity =>
1123 p_interface_rec.primary_uom_quantity
1124 , p_count_uom =>
1125 p_interface_rec.count_uom
1126 , p_serial_number => p_interface_rec.serial_number
1127 , p_subinventory =>p_interface_rec.subinventory
1128 , p_lot_number =>p_interface_rec.lot_number
1129 , p_lot_expiration =>
1130 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date
1131 , p_revision =>p_interface_rec.revision
1132 , p_transaction_reason_id =>
1133 p_interface_rec.transaction_reason_id
1134 , p_transaction_process_mode => p_interface_rec.process_mode
1135 , p_simulate => p_simulate);
1136 --
1137 IF (l_debug = 1) THEN
1138 MDEBUG( 'Tole : After update logic');
1139 END IF;
1140 ELSE
1141 --
1142 -- #### START OUT OF Tolerance
1143 IF (l_debug = 1) THEN
1144 MDEBUG( 'Before-Out of Tolerance ');
1145 END IF;
1146 Out_Of_Tolerance(
1147 p_reference => p_interface_rec.reference
1148 , p_primary_uom_quantity =>
1149 p_interface_rec.primary_uom_quantity
1150 , p_count_uom => p_interface_rec.count_uom
1151 , p_serial_number => p_interface_rec.serial_number
1152 , p_subinventory =>p_interface_rec.subinventory
1153 , p_lot_number =>p_interface_rec.lot_number
1154 , p_lot_expiration_date =>
1155 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date
1156 , p_revision =>p_interface_rec.revision
1157 , p_transaction_reason_id =>
1158 p_interface_rec.transaction_reason_id
1159 , p_transaction_process_mode => p_interface_rec.process_mode
1160 , p_simulate => p_simulate );
1161 -- #### END OUT OF Tolerance
1162 IF (l_debug = 1) THEN
1163 MDEBUG( 'End of Out-of Tolerance ');
1164 END IF;
1165 --
1166 END IF;
1167 --
1168 ELSE
1169 --
1170 IF p_pos_meas_err IS NOT NULL AND
1171 ABS((p_adjustment_quantity/p_system_quantity) *100) <
1172 p_pos_meas_err THEN
1173 --
1174 -- No adjustment required
1175 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 5;
1176 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ADJUSTMENT_QUANTITY := 0;
1177 MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY := 0;
1178 --
1179 IF (l_debug = 1) THEN
1180 MDEBUG( 'Before preupdate logic - 2');
1181 END IF;
1182 Final_Preupdate_Logic(
1183 p_reference => p_interface_rec.reference
1184 , p_primary_uom_quantity =>
1185 p_interface_rec.primary_uom_quantity
1186 , p_count_uom => p_interface_rec.count_uom
1187 , p_serial_number => p_interface_rec.serial_number
1188 , p_subinventory =>p_interface_rec.subinventory
1189 , p_lot_number =>p_interface_rec.lot_number
1190 , p_lot_expiration =>
1191 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date
1192 , p_revision =>p_interface_rec.revision
1193 , p_transaction_reason_id =>
1194 p_interface_rec.transaction_reason_id
1195 , p_transaction_process_mode => p_interface_rec.process_mode
1196 , p_simulate => p_simulate );
1197 --
1198 IF (l_debug = 1) THEN
1199 MDEBUG( 'preupdate logic-2 -end ');
1200 END IF;
1201 ELSE
1202 --
1203 IF (l_debug = 1) THEN
1204 MDEBUG( 'before start out-of tol -2 ');
1205 END IF;
1206 -- ## Start OUT OF TOLERANCE
1207 Out_Of_Tolerance(
1208 p_reference => p_interface_rec.reference
1209 , p_primary_uom_quantity =>
1210 p_interface_rec.primary_uom_quantity
1211 , p_count_uom =>
1212 p_interface_rec.count_uom
1213 , p_serial_number => p_interface_rec.serial_number
1214 , p_subinventory =>p_interface_rec.subinventory
1215 , p_lot_number =>p_interface_rec.lot_number
1216 , p_lot_expiration_date =>
1217 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date
1218 , p_revision =>p_interface_rec.revision
1219 , p_transaction_reason_id =>
1220 p_interface_rec.transaction_reason_id
1221 , p_transaction_process_mode => p_interface_rec.process_mode
1222 , p_simulate => p_simulate );
1223 -- ## END OUT OF TOLERANCE
1224 --
1225 IF (l_debug = 1) THEN
1226 MDEBUG( 'After out-of-tol- end-2');
1227 END IF;
1228 END IF;
1229 END IF;
1230 -- System quantity = 0
1231 ELSE
1232 --
1233 IF (l_debug = 1) THEN
1234 MDEBUG( 'Process-: Out of tol - 3');
1235 END IF;
1236 Out_Of_Tolerance(
1237 p_reference => p_interface_rec.reference
1238 , p_primary_uom_quantity =>
1239 p_interface_rec.primary_uom_quantity
1240 , p_count_uom =>
1241 p_interface_rec.count_uom
1242 , p_serial_number => p_interface_rec.serial_number
1243 , p_subinventory =>p_interface_rec.subinventory
1244 , p_lot_number =>p_interface_rec.lot_number
1245 , p_lot_expiration_date =>
1246 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date
1247 , p_revision =>p_interface_rec.revision
1248 , p_transaction_reason_id =>
1249 p_interface_rec.transaction_reason_id
1250 , p_transaction_process_mode => p_interface_rec.process_mode
1251 , p_simulate => p_simulate );
1252 --
1253 IF (l_debug = 1) THEN
1254 MDEBUG( 'Out of Tol-3 -end');
1255 END IF;
1256 END IF;
1257 -- if adjustment_qty = 0
1258 ELSE
1259 --
1260 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 5;
1261 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ADJUSTMENT_QUANTITY := 0;
1262 MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY := 0;
1263 --
1264 IF (l_debug = 1) THEN
1265 MDEBUG( 'Before preupdate - 4');
1266 END IF;
1267 Final_Preupdate_Logic(
1268 p_reference => p_interface_rec.reference
1269 , p_primary_uom_quantity =>
1270 p_interface_rec.primary_uom_quantity, p_count_uom =>
1271 p_interface_rec.count_uom
1272 , p_serial_number => p_interface_rec.serial_number
1273 , p_subinventory =>p_interface_rec.subinventory
1274 , p_lot_number =>p_interface_rec.lot_number
1275 , p_lot_expiration =>
1276 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date
1277 , p_revision =>p_interface_rec.revision
1278 , p_transaction_reason_id =>
1279 p_interface_rec.transaction_reason_id
1280 , p_transaction_process_mode => p_interface_rec.process_mode
1281 , p_simulate => p_simulate );
1282 --
1283 IF (l_debug = 1) THEN
1284 MDEBUG( 'End of pre-update - 4');
1285 END IF;
1286 END IF;
1287
1288 -- if optional_option = required if out of tolerance
1289 -- approval option = 2 (never) or approval_option = 3 (out_of_toler)
1290 -- p_approval_option_code = 1 is applicable only when lpn_id is null
1291 -- if lpn_id is not null, check container_adjustment_option = 2
1292 ELSE
1293 --
1294 IF p_adjustment_quantity <> 0 THEN
1295 --
1296 IF p_system_quantity <> 0 THEN
1297 --
1298 IF p_adjustment_quantity < 0 THEN
1299 --
1300 IF p_neg_meas_err IS NOT NULL
1301 AND ABS((p_adjustment_quantity/p_system_quantity) *100) < p_neg_meas_err THEN
1302 --
1303 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 5;
1304 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ADJUSTMENT_QUANTITY := 0;
1305 MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY := 0;
1306 --
1307 IF (l_debug = 1) THEN
1308 MDEBUG( 'before pre-update logic - 5');
1309 END IF;
1310 Final_Preupdate_Logic(
1311 p_reference => p_interface_rec.reference
1312 , p_primary_uom_quantity =>
1313 p_interface_rec.primary_uom_quantity
1314 , p_count_uom => p_interface_rec.count_uom
1315 , p_serial_number => p_interface_rec.serial_number
1316 , p_subinventory =>p_interface_rec.subinventory
1317 , p_lot_number =>p_interface_rec.lot_number
1318 , p_lot_expiration =>
1319 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date
1320 , p_revision =>p_interface_rec.revision
1321 , p_transaction_reason_id =>
1322 p_interface_rec.transaction_reason_id
1323 , p_transaction_process_mode => p_interface_rec.process_mode
1324 , p_simulate => p_simulate );
1325 --
1326 IF (l_debug = 1) THEN
1327 MDEBUG( 'before pre-update logic -end - 5');
1328 END IF;
1329 ELSE
1330 --
1331 IF(p_app_tol_neg IS NOT NULL AND
1332 ABS((p_adjustment_quantity / p_system_quantity) * 100)>p_app_tol_neg) THEN
1333 --
1334 IF (l_debug = 1) THEN
1335 MDEBUG( 'Out of tol if neg tol is not null ');
1336 END IF;
1337 Out_Of_Tolerance(
1338 p_reference => p_interface_rec.reference
1339 , p_primary_uom_quantity =>
1340 p_interface_rec.primary_uom_quantity
1341 , p_count_uom => p_interface_rec.count_uom
1342 , p_serial_number => p_interface_rec.serial_number
1343 , p_subinventory =>p_interface_rec.subinventory
1344 , p_lot_number =>p_interface_rec.lot_number
1345 , p_lot_expiration_date =>
1346 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date
1347 , p_revision =>p_interface_rec.revision
1348 , p_transaction_reason_id =>
1349 p_interface_rec.transaction_reason_id
1350 , p_transaction_process_mode => p_interface_rec.process_mode
1351 , p_simulate => p_simulate );
1352 --
1353 IF (l_debug = 1) THEN
1354 MDEBUG( 'end of tol - if negtol is not null');
1355 END IF;
1356 ELSE
1357 --
1358 IF((p_cost_tol_neg IS NOT NULL) AND
1359 (ABS(p_adjustment_value) > p_cost_tol_neg))
1360 THEN
1361 --
1362 Out_Of_Tolerance(
1363 p_reference => p_interface_rec.reference
1364 , p_primary_uom_quantity =>
1365 p_interface_rec.primary_uom_quantity, p_count_uom =>
1366 p_interface_rec.count_uom
1367 , p_serial_number => p_interface_rec.serial_number
1368 , p_subinventory =>p_interface_rec.subinventory
1369 , p_lot_number =>p_interface_rec.lot_number
1370 , p_lot_expiration_date =>
1371 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date
1372 , p_revision =>p_interface_rec.revision
1373 , p_transaction_reason_id =>
1374 p_interface_rec.transaction_reason_id
1375 , p_transaction_process_mode => p_interface_rec.process_mode
1376 , p_simulate => p_simulate );
1377 --
1378 ELSE
1379 --
1380 IF (l_debug = 1) THEN
1381 MDEBUG( 'Process-Tolerence-In');
1382 END IF;
1383 in_Tolerance(
1384 p_reference => p_interface_rec.reference
1385 , p_primary_uom_quantity =>
1386 p_interface_rec.primary_uom_quantity
1387 , p_count_uom => p_interface_rec.count_uom
1388 , p_serial_number => p_interface_rec.serial_number
1389 , p_subinventory =>p_interface_rec.subinventory
1390 , p_lot_number =>p_interface_rec.lot_number
1391 , p_lot_expiration_date =>
1392 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date
1393 , p_revision =>p_interface_rec.revision
1394 , p_transaction_reason_id =>
1395 p_interface_rec.transaction_reason_id
1396 , p_transaction_process_mode => p_interface_rec.process_mode
1397 , p_simulate => p_simulate );
1398 --
1399 IF (l_debug = 1) THEN
1400 MDEBUG( 'Process-Tolerance -In -End ');
1401 END IF;
1402 END IF;
1403 END IF;
1404 END IF;
1405 -- p_adjustment_quantity >= 0
1406 ELSE
1407 --
1408 IF p_pos_meas_err IS NOT NULL AND
1409 ABS((p_adjustment_quantity/p_system_quantity) *100) < p_pos_meas_err THEN
1410 --
1411 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 5;
1412 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ADJUSTMENT_QUANTITY := 0;
1413 MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY := 0;
1414 --
1415 IF (l_debug = 1) THEN
1416 MDEBUG( 'before final preupdate logic - err is not null');
1417 END IF;
1418 Final_Preupdate_Logic(
1419 p_reference => p_interface_rec.reference
1420 , p_primary_uom_quantity =>
1421 p_interface_rec.primary_uom_quantity, p_count_uom =>
1422 p_interface_rec.count_uom
1423 , p_serial_number => p_interface_rec.serial_number
1424 , p_subinventory =>p_interface_rec.subinventory
1425 , p_lot_number =>p_interface_rec.lot_number
1426 , p_lot_expiration =>
1427 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date
1428 , p_revision =>p_interface_rec.revision
1429 , p_transaction_reason_id =>
1430 p_interface_rec.transaction_reason_id
1431 , p_transaction_process_mode => p_interface_rec.process_mode
1432 , p_simulate => p_simulate );
1433 --
1434 IF (l_debug = 1) THEN
1435 MDEBUG( 'end of preupdate logic - err is not null');
1436 END IF;
1437 ELSE
1438 --
1439 IF(p_app_tol_pos IS NOT NULL AND
1440 ABS((p_adjustment_quantity / p_system_quantity) * 100) > p_app_tol_pos)
1441
1442 THEN
1443 --
1444 Out_Of_Tolerance(
1445 p_reference => p_interface_rec.reference
1446 , p_primary_uom_quantity =>
1447 p_interface_rec.primary_uom_quantity
1448 , p_count_uom => p_interface_rec.count_uom
1449 , p_serial_number => p_interface_rec.serial_number
1450 , p_subinventory =>p_interface_rec.subinventory
1451 , p_lot_number =>p_interface_rec.lot_number
1452 , p_lot_expiration_date =>
1453 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date
1454 , p_revision =>p_interface_rec.revision
1455 , p_transaction_reason_id =>
1456 p_interface_rec.transaction_reason_id
1457 , p_transaction_process_mode => p_interface_rec.process_mode
1458 , p_simulate => p_simulate );
1459 --
1460 ELSE
1461 --
1462 IF(p_cost_tol_pos IS NOT NULL AND
1463 (ABS(p_adjustment_value)
1464 > p_cost_tol_pos))
1465 THEN
1466 --
1467 Out_Of_Tolerance(
1468 p_reference => p_interface_rec.reference
1469 , p_primary_uom_quantity =>
1470 p_interface_rec.primary_uom_quantity
1471 , p_count_uom => p_interface_rec.count_uom
1472 , p_serial_number => p_interface_rec.serial_number
1473 , p_subinventory =>p_interface_rec.subinventory
1474 , p_lot_number =>p_interface_rec.lot_number
1475 , p_lot_expiration_date =>
1476 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date
1477 , p_revision =>p_interface_rec.revision
1478 , p_transaction_reason_id =>
1479 p_interface_rec.transaction_reason_id
1480 , p_transaction_process_mode => p_interface_rec.process_mode
1481 , p_simulate => p_simulate );
1482 --
1483 ELSE
1484 --
1485 in_Tolerance(
1486 p_reference => p_interface_rec.reference
1487 , p_primary_uom_quantity =>
1488 p_interface_rec.primary_uom_quantity, p_count_uom =>
1489 p_interface_rec.count_uom
1490 , p_serial_number => p_interface_rec.serial_number
1491 , p_subinventory =>p_interface_rec.subinventory
1492 , p_lot_number =>p_interface_rec.lot_number
1493 , p_lot_expiration_date =>
1494 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date
1495 , p_revision =>p_interface_rec.revision
1496 , p_transaction_reason_id =>
1497 p_interface_rec.transaction_reason_id
1498 , p_transaction_process_mode => p_interface_rec.process_mode
1499 , p_simulate => p_simulate );
1500 --
1501 END IF;
1502 END IF;
1503 END IF;
1504 END IF;
1505 -- system quantity = 0
1506 ELSE
1507 --
1508 IF (p_app_tol_pos IS NOT NULL AND
1509 ABS((p_adjustment_quantity)*100) >p_app_tol_pos)
1510 THEN
1511 -- ABS((p_adjustment_quantity/p_system_quantity) * 100) >p_app_tol_pos) THEN
1512 --
1513 IF (l_debug = 1) THEN
1514 MDEBUG( 'Process-Out of tolerance ');
1515 END IF;
1516 out_Of_Tolerance(
1517 p_reference => p_interface_rec.reference
1518 , p_primary_uom_quantity =>
1519 p_interface_rec.primary_uom_quantity, p_count_uom =>
1520 p_interface_rec.count_uom
1521 , p_serial_number => p_interface_rec.serial_number
1522 , p_subinventory =>p_interface_rec.subinventory
1523 , p_lot_number =>p_interface_rec.lot_number
1524 , p_lot_expiration_date =>
1525 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date
1526 , p_revision =>p_interface_rec.revision
1527 , p_transaction_reason_id =>
1528 p_interface_rec.transaction_reason_id
1529 , p_transaction_process_mode => p_interface_rec.process_mode
1530 , p_simulate => p_simulate );
1531 --
1532 IF (l_debug = 1) THEN
1533 MDEBUG( 'Process-End of Out of Tolerance');
1534 END IF;
1535 ELSE
1536 --
1537 IF((p_cost_tol_pos IS NOT NULL) AND
1538 (ABS(p_adjustment_value) > p_cost_tol_pos))
1539 THEN
1540 --
1541 Out_Of_Tolerance(
1542 p_reference => p_interface_rec.reference
1543 , p_primary_uom_quantity =>
1544 p_interface_rec.primary_uom_quantity, p_count_uom =>
1545 p_interface_rec.count_uom
1546 , p_serial_number => p_interface_rec.serial_number
1547 , p_subinventory =>p_interface_rec.subinventory
1548 , p_lot_number =>p_interface_rec.lot_number
1549 , p_lot_expiration_date =>
1550 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date
1551 , p_revision =>p_interface_rec.revision
1552 , p_transaction_reason_id =>
1553 p_interface_rec.transaction_reason_id
1554 , p_transaction_process_mode => p_interface_rec.process_mode
1555 , p_simulate => p_simulate );
1556 --
1557 ELSE
1558 --
1559 in_Tolerance(
1560 p_reference => p_interface_rec.reference
1561 , p_primary_uom_quantity =>
1562 p_interface_rec.primary_uom_quantity
1563 , p_count_uom => p_interface_rec.count_uom
1564 , p_serial_number => p_interface_rec.serial_number
1565 , p_subinventory =>p_interface_rec.subinventory
1566 , p_lot_number =>p_interface_rec.lot_number
1567 , p_lot_expiration_date =>
1568 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date
1569 , p_revision =>p_interface_rec.revision
1570 , p_transaction_reason_id =>
1571 p_interface_rec.transaction_reason_id
1572 , p_transaction_process_mode => p_interface_rec.process_mode
1573 , p_simulate => p_simulate );
1574 --
1575 END IF;
1576 END IF;
1577 END IF;
1578 -- adjustment qty = 0
1579 ELSE
1580 --
1581 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 5;
1582 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ADJUSTMENT_QUANTITY := 0;
1583 MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY := 0;
1584 --
1585 Final_Preupdate_Logic(
1586 p_reference => p_interface_rec.reference
1587 , p_primary_uom_quantity =>
1588 p_interface_rec.primary_uom_quantity
1589 , p_count_uom => p_interface_rec.count_uom
1590 , p_serial_number => p_interface_rec.serial_number
1591 , p_subinventory =>p_interface_rec.subinventory
1592 , p_lot_number =>p_interface_rec.lot_number
1593 , p_lot_expiration =>
1594 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date
1595 , p_revision =>p_interface_rec.revision
1596 , p_transaction_reason_id =>
1597 p_interface_rec.transaction_reason_id
1598 , p_transaction_process_mode => p_interface_rec.process_mode
1599 , p_simulate => p_simulate );
1600 --
1601 END IF;
1602 END IF;
1603 --
1604 END;
1605 END;
1606 --
1607 -- Zero count logic. count_type_code
1608 PROCEDURE Zero_Count_Logic(
1609 p_reference IN VARCHAR2 DEFAULT NULL,
1610 p_primary_uom_quantity IN NUMBER )
1611 IS
1612 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1613 BEGIN
1614 -- Start OF comments
1615 -- API name : Zero_Count_logic
1616 -- TYPE : Private
1617 -- Pre-reqs : None
1618 -- FUNCTION :
1619 -- this porcedure IS according to the count_type_code=4
1620 -- (zero COUNT) information without validation INTO
1621 -- temp data source OF cycle COUNT entries
1622 -- MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC_TMP
1623 -- Parameters:
1624 -- IN :
1625 -- p_reference IN VARCHAR2(240) (optional)
1626 -- default NULL, LIKE a note what IS happened
1627 --
1628 -- p_primary_uom_quantity IN NUMBER (required)
1629 -- primary uom quantity
1630 --
1631 -- Version: Current Version 0.9
1632 -- Changed : Nothing
1633 -- No Previous Version 0.0
1634 -- Initial version 0.9
1635 -- Notes : Note text
1636 -- END OF comments
1637 DECLARE
1638 --
1639 dummy integer;
1640 BEGIN
1641 -- SET the system quantity to 0
1642 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SYSTEM_QUANTITY_CURRENT := 0;
1643 -- SET the NUMBER OF counts to 0
1644 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.NUMBER_OF_COUNTS := 1;
1645 --SET the entry status code to completed
1646 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 5;
1647 -- SET approval TYPE to automatic
1648 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.APPROVAL_TYPE := 1;
1649 -- SET the employee id
1650 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNTED_BY_EMPLOYEE_ID_CURRENT :=
1651 MTL_CCEOI_VAR_PVT.G_EMPLOYEE_ID;
1652 -- SET the approval DATE
1653 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.APPROVAL_DATE := SYSDATE;
1654 -- SET the COUNT TYPE CODE TO ZEROCOUNT
1655 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_TYPE_CODE := 4;
1656 --
1657 MTL_CCEOI_PROCESS_PVT.Entry_to_Current
1658 (p_reference => p_reference
1659 , p_primary_uom_quantity => p_primary_uom_quantity );
1660 --
1661 MTL_CCEOI_PROCESS_PVT.Current_to_first
1662 (p_reference => p_reference
1663 , p_primary_uom_quantity => p_primary_uom_quantity
1664 );
1665 --
1666 END;
1667 END;
1668 --
1669 -- Calculates adjustments for Step 4
1670 PROCEDURE Calculate_Adjustment(
1671 p_api_version IN NUMBER ,
1672 p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE,
1673 p_commit IN VARCHAR2 DEFAULT FND_API.G_FALSE,
1674 p_validation_level IN NUMBER DEFAULT FND_API.G_VALID_LEVEL_FULL,
1675 x_return_status OUT NOCOPY VARCHAR2 ,
1676 x_msg_count OUT NOCOPY NUMBER ,
1677 x_msg_data OUT NOCOPY VARCHAR2 ,
1678 x_errorcode OUT NOCOPY NUMBER ,
1679 p_inventory_item_id IN NUMBER ,
1680 p_organization_id IN NUMBER ,
1681 p_lpn_id IN NUMBER ,
1682 p_subinventory IN VARCHAR2 ,
1683 p_count_quantity IN NUMBER ,
1684 p_revision IN VARCHAR2 DEFAULT NULL,
1685 p_locator_id IN NUMBER DEFAULT NULL,
1686 p_lot_number IN VARCHAR2 DEFAULT NULL,
1687 p_serial_number IN VARCHAR2 DEFAULT NULL,
1688 p_serial_number_control_code IN NUMBER ,
1689 p_serial_count_option IN NUMBER ,
1690 p_system_quantity IN NUMBER DEFAULT NULL,
1691 p_secondary_system_quantity IN NUMBER DEFAULT NULL -- INVCONV
1692 )
1693 IS
1694 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1695 BEGIN
1696 -- Start OF comments
1697 -- API name : Calculate_Adjustment
1698 -- TYPE : Private
1699 -- Pre-reqs : None
1700 -- FUNCTION :
1701 -- This PROCEDURE calculates
1702 -- the Adjustment amount, Adjustment Variance percentage AND
1703 -- Adjustment quantity AND store the VALUES INTO the package
1704 -- variables G_ADJUSTMENT_AMOUNT,
1705 -- G_ADJUSTMENT_VARIANCE_PERCENTAGE,
1706 -- G_ADJUSTMENT_QUANTITY OF the package
1707 -- The system quantity IS stored INTO the package variable
1708 -- MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY
1709 -- MTL_CCEOI_VAR_PVZ
1710 --
1711 -- Parameters:
1712 -- IN :
1713 -- p_api_version IN NUMBER (required)
1714 -- API Version of this procedure
1715 --
1716 -- p_init_msg_list IN VARCHAR2 (optional)
1717 -- DEFAULT = FND_API.G_FALSE,
1718 --
1719 -- p_commit IN VARCHAR2 (optional)
1720 -- DEFAULT = FND_API.G_FALSE
1721 --
1722 -- p_validation_level IN NUMBER (optional)
1723 -- DEFAULT = FND_API.G_VALID_LEVEL_FULL,
1724 --
1725 -- p_inventory_item_id IN NUMBER (required)
1726 -- ID OF the inventory item
1727 --
1728 -- p_organization_id IN NUMBER (required)
1729 -- ID OF the organization
1730 --
1731 -- p_subinventory IN VARCHAR2 (required)
1732 --
1733 -- p_revision IN VARCHAR2 (optional - defaulted)
1734 -- default = NULL
1735 -- revision code OF the item, required IF it IS under revision control
1736 --
1737 -- p_locator_id IN NUMBER (optional - defaulted)
1738 -- default = NULL
1739 -- ID OF the locator, required IF it IS under locator control
1740 --
1741 -- p_lot_number IN VARCHAR2 (optional - defaulted)
1742 -- default = NULL
1743 -- Lot NUMBER, required IF it IS under lot control
1744 --
1745 -- p_serial_number IN VARCHAR2 (optional - defaulted)
1746 -- default = NULL
1747 -- Serial NUMBER, required IF this item IN under serial control
1748 --
1749 -- p_count_quantity IN NUMBER (required)
1750 -- Quantity OF the current COUNT FOR teh specific item
1751 --
1752 -- p_serial_number_control_code IN NUMBER (required)
1753 -- FROM TABLE MTL_SYSTEM_ITEMS
1754 --
1755 -- p_serial_count_option IN NUMBER (required)
1756 -- FROM TABLE MTL_CYCLE_COUNT_HEADERS
1757 --
1758 -- p_system_quantity in number (required - defaulted)
1759 -- default null
1760 --
1761 -- OUT :
1762 -- X_return_status OUT NUMBER
1763 -- Result of all the operations
1764 --
1765 -- x_msg_count OUT NUMBER,
1766 --
1767 -- x_msg_data OUT VARCHAR2,
1768 --
1769 -- X_ErrorCode OUT NUMBER
1770 -- 18 = no system quantity FOR serial controlled item
1771 -- Version: Current Version 0.9
1772 -- Changed : Nothing
1773 -- No Previous Version 0.0
1774 -- Initial version 0.9
1775 -- Notes : Note text
1776 -- END OF comments
1777 DECLARE
1778 --
1779 L_primary_uom_adj_qty NUMBER := 0;
1780 L_item_cost NUMBER := 0;
1781 L_counter integer := 0;
1782 L_system_quantity NUMBER:= 0;
1783 L_secondary_system_quantity NUMBER := 0; -- INVCONV
1784 --
1785 L_api_version CONSTANT NUMBER := 0.9;
1786 L_api_name CONSTANT VARCHAR2(30) := 'Calculate_Adjustment';
1787 l_cost_group_id NUMBER;
1788 l_cost_group VARCHAR2(10);
1789 l_return_status VARCHAR2(1);
1790 l_msg_count NUMBER;
1791 l_msg_data VARCHAR2(1000);
1792 BEGIN
1793 -- Standard start of API savepoint
1794 SAVEPOINT Calculate_Adjustment;
1795 --
1796 -- Standard Call to check for call compatibility
1797 IF NOT FND_API.Compatible_API_Call(l_api_version
1798 , p_api_version
1799 , l_api_name
1800 , G_PKG_NAME) THEN
1801 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1802 END IF;
1803 --
1804 -- Initialize message list if p_init_msg_list is set to true
1805 IF FND_API.to_Boolean(p_init_msg_list) THEN
1806 FND_MSG_PUB.initialize;
1807 END IF;
1808 --
1809 -- Initialisize API return status to access
1810 x_return_status := FND_API.G_RET_STS_SUCCESS;
1811 x_errorcode := 0;
1812 MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY := 0;
1813 MTL_CCEOI_VAR_PVT.G_SECONDARY_SYSTEM_QUANTITY := 0; -- INVCONV
1814 --
1815 IF (l_debug = 1) THEN
1816 MDEBUG( 'Process-Inside Calc-Adj Qty');
1817 MDEBUG( 'Count Qty is = '||to_char(p_count_quantity));
1818 END IF;
1819 -- API body
1820 -- Get the system_quantity
1821 -- Calculate system quantity always even if you have the
1822 -- sys qty from entry table
1823 --if (p_system_quantity is NULL ) THEN
1824 --
1825 IF (l_debug = 1) THEN
1826 MDEBUG( 'Process-InsideAdjQty- SysQty is null');
1827 MDEBUG( 'Org '||to_char(p_organization_id));
1828 MDEBUG( 'item '||to_char(p_inventory_item_id));
1829 MDEBUG( 'lpnid'||to_char(MTL_CCEOI_VAR_PVT.G_LPN_ID));
1830 MDEBUG( 'Sub '||p_subinventory);
1831 MDEBUG( 'Lot '||p_lot_number);
1832 MDEBUG( 'Locator '||to_char(p_locator_id));
1833 MDEBUG( 'SerlNo '||p_serial_number);
1834 MDEBUG( 'SerlNoCtrlCd '||to_char(p_serial_number_control_code));
1835 MDEBUG( 'SerlCntOption '||to_char(p_serial_count_option));
1836 END IF;
1837
1838 /* Bug #2650761
1839 * If the cost_group_id is not stamped in the interface record, then
1840 * obtain cost group from the cost group API
1841 */
1842 IF MTL_CCEOI_VAR_PVT.G_COST_GROUP_ID IS NOT NULL THEN
1843 l_cost_group_id := MTL_CCEOI_VAR_PVT.G_COST_GROUP_ID;
1844 ELSE
1845 BEGIN
1846 inv_cost_group_pvt.get_cost_group(
1847 x_cost_group_id => l_cost_group_id,
1848 x_cost_group => l_cost_group,
1849 x_return_status => l_return_status,
1850 x_msg_count => l_msg_count,
1851 x_msg_data => l_msg_data,
1852 p_organization_id => p_organization_id,
1853 p_lpn_id => p_lpn_id,
1854 p_inventory_item_id => p_inventory_item_id,
1855 p_revision => p_revision,
1856 p_subinventory_code => p_subinventory,
1857 p_locator_id => p_locator_id,
1858 p_lot_number => p_lot_number,
1859 p_serial_number => p_serial_number);
1860 EXCEPTION
1861 WHEN OTHERS THEN
1862 l_cost_group_id := NULL;
1863 END;
1864 END IF;
1865
1866 IF (l_debug = 1) THEN
1867 mdebug('cost group id returned is: ' || l_cost_group_id);
1868 END IF;
1869
1870 -- Bug 2823976
1871 IF (p_system_quantity is NULL ) THEN
1872 -- IF p_lpn_id IS NOT NULL THEN
1873 IF MTL_CCEOI_VAR_PVT.G_LPN_ID IS NOT NULL THEN -- 8300310
1874 IF p_inventory_item_id IS NOT NULL THEN
1875 -- Looking for a quanitity for an item withing a specific container.
1876 MTL_INV_UTIL_GRP.Get_LPN_Item_SysQty
1877 (
1878 p_api_version => 0.9
1879 , p_init_msg_lst => fnd_api.g_true
1880 , p_commit => fnd_api.g_true
1881 , x_return_status => x_return_status
1882 , x_msg_count => x_msg_count
1883 , x_msg_data => x_msg_data
1884 , p_organization_id => p_organization_id
1885 -- , p_lpn_id => p_lpn_id
1886 , p_lpn_id => MTL_CCEOI_VAR_PVT.G_LPN_ID -- 8300310
1887 , p_inventory_item_id => p_inventory_item_id
1888 , p_lot_number => p_lot_number
1889 , p_revision => p_revision
1890 , p_serial_number => p_serial_number
1891 , p_cost_group_id => l_cost_group_id
1892 --, p_cost_group_id => MTL_CCEOI_VAR_PVT.G_COST_GROUP_ID
1893 , x_lpn_systemqty => L_system_quantity
1894 , x_lpn_sec_systemqty => L_secondary_system_quantity -- INVCONV
1895 );
1896
1897 IF (l_debug = 1) THEN
1898 mdebug('MTL_INV_UTIL_GRP.Get_LPN_Item_SysQty :' || L_system_quantity);
1899 END IF;
1900
1901
1902 ELSE
1903 IF (l_debug = 1) THEN
1904 mdebug('No Item given use MTL_CCEOI_VAR_PVT.G_LPN_ITEM_SYSTEM_QTY :' || L_system_quantity);
1905 END IF;
1906 -- No item id given, thus system quantity will be same as count quantity
1907 L_system_quantity := MTL_CCEOI_VAR_PVT.G_LPN_ITEM_SYSTEM_QTY;
1908 L_secondary_system_quantity := MTL_CCEOI_VAR_PVT.G_LPN_ITEM_SEC_SYSTEM_QTY; -- INVCONV
1909 END IF;
1910 ELSE
1911
1912 -- No container given, regulare system quantity requested
1913 MTL_INV_UTIL_GRP.Calculate_Systemquantity
1914 (p_api_version => 0.9
1915 ,x_return_status => x_return_status
1916 ,x_msg_count => x_msg_count
1917 ,x_msg_data => x_msg_data
1918 ,p_organization_id => p_organization_id
1919 ,p_inventory_item_id => p_inventory_item_id
1920 ,p_subinventory => p_subinventory
1921 ,p_lot_number => p_lot_number
1922 ,p_revision => p_revision
1923 ,p_locator_id => p_locator_id
1924 , p_cost_group_id => l_cost_group_id
1925 --,p_cost_group_id => MTL_CCEOI_VAR_PVT.G_COST_GROUP_ID
1926 ,p_serial_number => p_serial_number
1927 ,p_serial_number_control => p_serial_number_control_code
1928 ,p_serial_count_option => p_serial_count_option
1929 ,x_system_quantity => L_system_quantity
1930 ,x_sec_system_quantity => L_secondary_system_quantity -- INVCONV
1931 );
1932
1933 IF (l_debug = 1) THEN
1934 mdebug('MTL_INV_UTIL_GRP.Calculate_Systemquantity :' || L_system_quantity);
1935 END IF;
1936
1937 END IF;
1938
1939 -- in G_UOM_CODE UOM
1940 MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY :=
1941 L_system_quantity;
1942
1943 MTL_CCEOI_VAR_PVT.G_SECONDARY_SYSTEM_QUANTITY := L_secondary_system_quantity; -- INVCONV
1944 ELSE
1945
1946 MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY := p_system_quantity;
1947 MTL_CCEOI_VAR_PVT.G_SECONDARY_SYSTEM_QUANTITY := p_secondary_system_quantity; -- INVCONV
1948 END IF; --End Bug 2823976
1949
1950 -- BEGIN INVCONV
1951 IF MTL_CCEOI_VAR_PVT.G_TRACKING_QUANTITY_IND <> 'PS' THEN
1952 MTL_CCEOI_VAR_PVT.G_SECONDARY_SYSTEM_QUANTITY := NULL;
1953 END IF;
1954 -- END INVCONV
1955
1956 IF (l_debug = 1) THEN
1957 MDEBUG( 'Process-InsideCSysQty '||to_char(MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY));
1958 MDEBUG( 'Process-CalQty '||to_char( L_system_quantity));
1959 END IF;
1960 --
1961 /* not reqd due to removal of if statement
1962 else
1963 --
1964 MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY :=
1965 p_system_quantity;
1966 --
1967 IF (l_debug = 1) THEN
1968 MDEBUG(
1969 END IF;
1970 'Process-InsidePSysQty '||to_char(MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY));
1971
1972 END IF;
1973 */
1974 --
1975 -- Different UOMs THEN convert
1976 IF (l_debug = 1) THEN
1977 MDEBUG( 'PUOM UOM '||MTL_CCEOI_VAR_PVT.G_PRIMARY_UOM_CODE||' - '||MTL_CCEOI_VAR_PVT.G_UOM_CODE );
1978 END IF;
1979 IF MTL_CCEOI_VAR_PVT.G_PRIMARY_UOM_CODE <>
1980 MTL_CCEOI_VAR_PVT.G_UOM_CODE THEN
1981 --
1982 IF (l_debug = 1) THEN
1983 MDEBUG( 'Process-Calc.PUOM AdjQty');
1984 END IF;
1985 -- Calculate the primary uom adjustement quantity
1986 -- changes made to convert system qty back to prim.uom qty
1987 --bug 8526579 made the inv_convert call lot specific to honor lot specific conversions
1988 L_primary_uom_adj_qty :=
1989 nvl(INV_CONVERT.inv_um_convert(
1990 item_id =>p_inventory_item_id
1991 ,lot_number=> p_lot_number
1992 ,organization_id=>p_organization_id
1993 , precision => 2
1994 , from_quantity => p_count_quantity
1995 , from_unit => MTL_CCEOI_VAR_PVT.G_UOM_CODE
1996 , to_unit => MTL_CCEOI_VAR_PVT.G_PRIMARY_UOM_CODE
1997 , from_name => NULL
1998 , to_name => NULL
1999 ),0) -
2000 nvl( INV_CONVERT.inv_um_convert(
2001 item_id =>p_inventory_item_id
2002 ,lot_number=> p_lot_number
2003 ,organization_id=>p_organization_id
2004 , precision => 2
2005 , from_quantity => MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY
2006 , from_unit => MTL_CCEOI_VAR_PVT.G_UOM_CODE
2007 , to_unit => MTL_CCEOI_VAR_PVT.G_PRIMARY_UOM_CODE
2008 , from_name => NULL
2009 , to_name => NULL
2010 ),0);
2011
2012 --
2013 IF (l_debug = 1) THEN
2014 MDEBUG( 'CalAdjQty : '||to_char(L_primary_uom_adj_qty));
2015 MDEBUG( 'Process-Calc.AdjQty in Count UOM ');
2016 END IF;
2017 -- Calculate Adjustment quantity IN count_UOM
2018 -- System qty is already calculated in Count UOM Code
2019 -- calculation of adjqty changed by suresh - 10/2/98
2020 MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY :=
2021 p_count_quantity - nvl(MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY,0);
2022 /*
2023 nvl( INV_CONVERT.inv_um_convert(
2024 item_id =>p_inventory_item_id
2025 , precision => 2
2026 , from_quantity => MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY
2027 , from_unit => MTL_CCEOI_VAR_PVT.G_PRIMARY_UOM_CODE
2028 , to_unit => MTL_CCEOI_VAR_PVT.G_UOM_CODE
2029 , from_name => NULL
2030 , to_name => NULL
2031 ),0);
2032 */
2033 IF (l_debug = 1) THEN
2034 MDEBUG( 'AdjQty-2 '||to_char(MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY));
2035 END IF;
2036 --
2037 ELSE
2038 -- Calculate the primary uom adjustement quantity
2039 L_primary_uom_adj_qty :=
2040 nvl(p_count_quantity,0) - nvl(MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY,0);
2041 --
2042 -- Calculate Adjustment quantity IN count_UOM
2043 MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY :=
2044 nvl(p_count_quantity,0) - nvl(MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY,0);
2045 --
2046 IF (l_debug = 1) THEN
2047 MDEBUG( 'AdjQty-3 '||to_char(L_primary_uom_adj_qty));
2048 END IF;
2049 END IF;
2050 --
2051 IF (l_debug = 1) THEN
2052 MDEBUG( 'Process-GetItemCost ');
2053 END IF;
2054
2055 /* Bug 5409309 -Commenting out the following call to get the item cost.
2056 Using the new local procedure get_item_cost
2057 to fetch the item cost
2058 MTL_INV_UTIL_GRP.Get_Item_Cost(
2059 p_api_version => 0.9,
2060 x_return_status => x_return_status,
2061 x_msg_count => x_msg_count,
2062 x_msg_data => x_msg_data,
2063 p_organization_id => p_organization_id,
2064 p_inventory_item_id => p_inventory_item_id,
2065 p_locator_id => p_locator_id,
2066 x_item_cost => L_item_cost); */
2067
2068 --Item Cost
2069
2070 Get_Item_Cost(
2071 p_organization_id => p_organization_id,
2072 p_inventory_item_id => p_inventory_item_id,
2073 p_locator_id => p_locator_id,
2074 p_cost_group_id => l_cost_group_id,
2075 x_item_cost =>l_item_cost) ;
2076
2077 /* End of fix for Bug 5721960*/
2078
2079
2080 --
2081 -- Adjustment Amount
2082 IF (l_debug = 1) THEN
2083 MDEBUG( 'Process-GetItemCost U Cost'||to_char(L_item_cost));
2084 MDEBUG( 'Process-GetItemCost AdjQty'||to_char(L_primary_uom_adj_qty));
2085 END IF;
2086 MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_AMOUNT :=
2087 L_primary_uom_adj_qty * L_item_cost;
2088 --
2089 MTL_CCEOI_VAR_PVT.G_ITEM_COST := L_item_cost;
2090 --
2091 IF MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY > 0 THEN
2092 MTL_CCEOI_VAR_PVT.G_ADJ_VARIANCE_PERCENTAGE :=
2093 100 *(MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY/
2094 MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY);
2095 ELSE
2096 MTL_CCEOI_VAR_PVT.G_ADJ_VARIANCE_PERCENTAGE := NULL;
2097 END IF;
2098 --
2099 /*
2100 -- Commenting out by suresh to not to execute this code for testing
2101 -- item IS NOT under serial control
2102 -- AND system quantity IS 0 error OUT
2103 IF p_serial_number IS NOT NULL
2104 AND MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY = 0 THEN
2105 --
2106 x_errorcode := 17;
2107 FND_MESSAGE.SET_NAME('INV', 'INV_CCEOI_ADJCALC_NO_SERIAL');
2108 FND_MSG_PUB.Add;
2109 RAISE FND_API.G_EXC_ERROR;
2110 --
2111 END IF;
2112 */
2113 --
2114 --
2115 -- END of API body
2116 -- Standard check of p_commit
2117 IF FND_API.to_Boolean(p_commit) THEN
2118 COMMIT;
2119 END IF;
2120 -- Standard call to get message count and if count is 1, get message info
2121 FND_MSG_PUB.Count_And_Get
2122 (p_count => x_msg_count
2123 , p_data => x_msg_data);
2124 EXCEPTION
2125 WHEN FND_API.G_EXC_ERROR THEN
2126 --
2127 ROLLBACK TO Calculate_Adjustment;
2128 --
2129 x_return_status := FND_API.G_RET_STS_ERROR;
2130 --
2131 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
2132 , p_data => x_msg_data);
2133 --
2134 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2135 --
2136 ROLLBACK TO Calculate_Adjustment;
2137 --
2138 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2139 --
2140 x_errorcode := -1;
2141 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
2142 , p_data => x_msg_data);
2143 --
2144 WHEN OTHERS THEN
2145 --
2146 ROLLBACK TO Calculate_Adjustment;
2147 --
2148 x_errorcode := -1;
2149 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2150 --
2151 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
2152 FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
2153 END IF;
2154 --
2155 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
2156 , p_data => x_msg_data);
2157 END;
2158 END;
2159 --
2160 -- Calculate Tolerance
2161 PROCEDURE Calculate_Tolerance(
2162 p_item_app_tol_pos IN NUMBER ,
2163 p_item_app_tol_neg IN NUMBER ,
2164 p_class_app_tol_pos IN NUMBER ,
2165 p_class_app_tol_neg IN NUMBER ,
2166 p_class_cost_tol_pos IN NUMBER ,
2167 p_class_cost_tol_neg IN NUMBER ,
2168 p_head_app_tol_pos IN NUMBER ,
2169 p_head_app_tol_neg IN NUMBER ,
2170 p_head_cost_tol_pos IN NUMBER ,
2171 p_head_cost_tol_neg IN NUMBER ,
2172 p_interface_rec IN MTL_CCEOI_VAR_PVT.INV_CCEOI_TYPE ,
2173 p_simulate IN VARCHAR2 DEFAULT FND_API.G_FALSE)
2174 IS
2175 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2176 BEGIN
2177 -- Start OF comments
2178 -- API name : Calculate_Tolerance
2179 -- TYPE : Private
2180 -- Pre-reqs : None
2181 -- FUNCTION :
2182 -- this PROCEDURE get the pos AND neg approval tolerance
2183 -- AND currency tolerance according to the presedence WHERE
2184 -- it IS defined, begining with the highest level.
2185 -- ITEM > CLASS > HEADER
2186 -- After calculating the tolerances the tolerance logic IS called.
2187 -- Parameters:
2188 -- IN :
2189 --
2190 -- p_item_app_tol_pos IN NUMBER (required)
2191 -- MTL_CYCLE_COUNT_ENTRIES_V.APPROVAL_TOLERANCE_POSITIVE
2192 --
2193 -- p_item_app_tol_neg IN NUMBER (required)
2194 -- MTL_CYCLE_COUNT_ENTRIES_V.APPROVAL_TOLERANCE_NEGATIVE
2195 --
2196 -- p_class_app_tol_pos IN NUMBER (required)
2197 -- MTL_CYCLE_COUNT_ENTRIES_V.CLASS_APP_TOL_POS
2198 --
2199 -- p_class_app_tol_neg IN NUMBER (required)
2200 -- MTL_CYCLE_COUNT_ENTRIES_V.CLASS_APP_TOL_NEG
2201 --
2202 -- p_class_cost_tol_pos IN NUMBER (required)
2203 -- MTL_CYCLE_COUNT_ENTRIES_V.CLASS_COST_TOL_POS
2204 --
2205 -- p_class_cost_tol_neg IN NUMBER (required)
2206 -- MTL_CYCLE_COUNT_ENTRIES_V.CLASS_COST_TOL_NEG
2207 --
2208 -- p_head_app_tol_pos IN NUMBER (required)
2209 -- MTL_CYCLE_COUNT_HEADERS.APPROVAL_TOLERANCE_POSITIVE
2210 --
2211 -- p_head_app_tol_neg IN NUMBER (required)
2212 -- MTL_CYCLE_COUNT_HEADERS.APPROVAL_TOLERANCE_NEGATIVE
2213 --
2214 -- p_head_cost_tol_pos IN NUMBER (required)
2215 -- MTL_CYCLE_COUNT_HEADERS.COST_TOLERANCE_POSITIVE
2216 --
2217 -- p_head_cost_tol_neg IN NUMBER (required)
2218 -- MTL_CYCLE_COUNT_HEADERS.COST_TOLERANCE_NEGATIVE
2219 --
2220 -- p_simulate NUMBER (default = FND_API.G_FALSE)
2221 -- G_FALSE = allow changes to tables other than interface tables
2222 -- G_TRUE = no changes will be made to any outside tables
2223 -- OUT :
2224 --
2225 --
2226 -- Version: Current Version 0.9
2227 -- Changed : Nothing
2228 -- No Previous Version 0.0
2229 -- Initial version 0.9
2230 -- Notes : Note text
2231 -- END OF comments
2232 DECLARE
2233 --
2234 CURSOR L_ItemErrMeas_Csr (itemid in number, org in number) is
2235 select
2236 positive_measurement_error
2237 , negative_measurement_error
2238 from mtl_system_items
2239 where inventory_item_id = itemid
2240 and organization_id = org;
2241 --
2242 L_positive_measurement_error number;
2243 L_negative_measurement_error number;
2244 L_app_tol_pos NUMBER;
2245 L_app_tol_neg NUMBER;
2246 L_cost_tol_pos NUMBER;
2247 L_cost_tol_neg NUMBER;
2248 BEGIN
2249 IF (l_debug = 1) THEN
2250 MDEBUG( 'Inside Calculate Tol ');
2251 END IF;
2252 --
2253 IF p_item_app_tol_pos IS NULL THEN
2254 --
2255 IF p_class_app_tol_pos IS NULL THEN
2256 --
2257 L_app_tol_pos := p_head_app_tol_pos;
2258 --
2259 ELSE
2260 --
2261 L_app_tol_pos := p_class_app_tol_pos;
2262 --
2263 END IF;
2264 --
2265 ELSE
2266 --
2267 L_app_tol_pos := p_item_app_tol_pos;
2268 --
2269 END IF;
2270 --
2271 IF p_item_app_tol_neg IS NULL THEN
2272 --
2273 IF p_class_app_tol_neg IS NULL THEN
2274 --
2275 L_app_tol_neg :=p_head_app_tol_neg;
2276 --
2277 ELSE
2278 --
2279 L_app_tol_neg := p_class_app_tol_neg;
2280 --
2281 END IF;
2282 --
2283 ELSE
2284 --
2285 L_app_tol_neg := p_item_app_tol_neg;
2286 --
2287 END IF;
2288 --
2289 IF p_class_cost_tol_pos IS NULL THEN
2290 --
2291 L_cost_tol_pos := p_head_cost_tol_pos;
2292 --
2293 ELSE
2294 --
2295 L_cost_tol_pos := p_class_cost_tol_pos;
2296 --
2297 END IF;
2298 --
2299 IF p_class_cost_tol_neg IS NULL THEN
2300 --
2301 L_cost_tol_neg := p_head_cost_tol_neg;
2302 --
2303 ELSE
2304 --
2305 L_cost_tol_neg := p_class_cost_tol_neg;
2306 --
2307 END IF;
2308 --
2309 IF (l_debug = 1) THEN
2310 MDEBUG( 'Inside Calculate Tol '|| to_char(MTL_CCEOI_VAR_PVT.G_inventory_item_id)||' - '||to_char(MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.ORGANIZATION_ID));
2311 END IF;
2312
2313 IF (l_debug = 1) THEN
2314 MDEBUG( 'Cal Tol-AdjQty '||to_char(MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY));
2315 END IF;
2316 for c_rec in L_ItemErrMeas_Csr (
2317 MTL_CCEOI_VAR_PVT.G_inventory_item_id,
2318 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.ORGANIZATION_ID) LOOP
2319 --
2320 L_positive_measurement_error := c_rec.positive_measurement_error;
2321 L_negative_measurement_error := c_rec.negative_measurement_error;
2322 --
2323 END LOOP;
2324 --
2325 Tolerance_Logic(
2326 p_pos_meas_err =>L_positive_measurement_error
2327 , p_neg_meas_err => L_negative_measurement_error
2328 , p_app_tol_pos => L_app_tol_pos
2329 , p_app_tol_neg => L_app_tol_neg
2330 , p_cost_tol_pos =>L_cost_tol_pos
2331 , p_cost_tol_neg => L_cost_tol_neg
2332 , p_adjustment_value => MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_AMOUNT
2333 --MTL_CCEOI_VAR_PVT.G_ADJ_VARIANCE_PERCENTAGE
2334 , p_adjustment_quantity =>
2335 MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY
2336 , p_system_quantity =>
2337 MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY
2338 , p_approval_option_code =>
2339 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.APPROVAL_OPTION_CODE
2340 , p_interface_rec => p_interface_rec
2341 , p_simulate => p_simulate
2342 );
2343 --
2344 END;
2345 END;
2346 --
2347 -- Deletes entries in the interface tables
2348 PROCEDURE Delete_CCIEntry(
2349 p_cc_entry_interface_id IN NUMBER )
2350 IS
2351 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2352 BEGIN
2353 -- Start OF comments
2354 -- API name : Delete_CCEOIEntry
2355 -- TYPE : Private
2356 -- Pre-reqs : None
2357 -- FUNCTION :
2358 -- This PROCEDURE delete the entry from the interface table.
2359 -- Parameters:
2360 -- IN :
2361 -- p_cc_entry_interface_id IN NUMBER (required)
2362 -- ID of the interface record/Entry
2363 --
2364 -- END OF comments
2365 DECLARE
2366 --
2367 dummy integer;
2368 --
2369 BEGIN
2370 --
2371 begin
2372 delete from mtl_cc_entries_interface
2373 where cc_entry_interface_id = p_cc_entry_interface_id;
2374 exception when others then
2375 null;
2376 end;
2377 --
2378 END;
2379 END;
2380 --
2381 -- Delete records from the cycle count interface error table
2382 PROCEDURE Delete_CCEOIError(
2383 p_cc_entry_interface_id IN NUMBER )
2384 IS
2385 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2386 BEGIN
2387 -- Start OF comments
2388 -- API name : Delete_CCEOIError
2389 -- TYPE : Private
2390 -- Pre-reqs : None
2391 -- FUNCTION :
2392 -- This PROCEDURE delete the errors of an interface entry
2393 -- Parameters:
2394 -- IN :
2395 -- p_cc_entry_interface_id IN NUMBER (required)
2396 -- ID of the interface record/Entry
2397 --
2398 -- END OF comments
2399 DECLARE
2400 --
2401 dummy integer;
2402 --
2403 BEGIN
2404 --
2405 begin
2406 delete from mtl_cc_interface_errors
2407 where cc_entry_interface_id = p_cc_entry_interface_id;
2408 exception when others then
2409 null;
2410 end;
2411 --
2412 END;
2413 END;
2414
2415 --
2416 --
2417 -- Insert the record into the application tables
2418 /*
2419 Pre-reqs:
2420
2421 INVENTORY_ITEM_ID NOT NULL
2422 SUBINVENTORY NOT NULL
2423 ORGANIZATION_ID NOT NULL
2424
2425 */
2426 PROCEDURE Insert_CCEntry(
2427 p_interface_rec IN MTL_CCEOI_VAR_PVT.INV_CCEOI_TYPE)
2428 IS
2429 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2430 l_user_tt_id NUMBER ; --10268469
2431 BEGIN
2432 -- Start OF comments
2433 -- API name : Insert_CCEntry
2434 -- TYPE : Public
2435 -- Pre-reqs : None
2436 -- FUNCTION :
2437 -- inserts the RECORD INTO MTL_CYCLE_COUNT_ENTRIES TABLE
2438 -- Parameters:
2439 -- IN :
2440 -- p_interface_rec IN CCEOI_Rec_Type (required)
2441 -- complete interface RECORD
2442 -- END OF comments
2443 DECLARE
2444 L_CCEntryId NUMBER;
2445 l_count_due_date DATE;
2446
2447 BEGIN
2448 SELECT
2449 MTL_CYCLE_COUNT_ENTRIES_S.nextval
2450 INTO
2451 L_CCEntryId
2452 FROM
2453 dual;
2454 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.CYCLE_COUNT_ENTRY_ID := L_CCEntryId;
2455 IF (l_debug = 1) THEN
2456 MDEBUG( 'New CCId : '||to_char(L_CCEntryId));
2457 END IF;
2458
2459 l_count_due_date := SYSDATE; -- Bug 16426893 removed validation as its not existing in forms/mobile code
2460
2461 IF (l_debug = 1) THEN
2462 mdebug('date due:'||to_char(l_count_due_date));
2463 END IF;
2464
2465 /*10268469- added code to populate user task type for cycle count*/
2466 BEGIN
2467 SELECT STANDARD_OPERATION_ID INTO l_user_tt_id
2468 FROM BOM_STANDARD_OPERATIONS
2469 WHERE WMS_TASK_TYPE = 3
2470 AND ORGANIZATION_ID = p_interface_rec.ORGANIZATION_ID
2471 AND ROWNUM = 1;
2472 EXCEPTION
2473 WHEN NO_DATA_FOUND THEN
2474 l_user_tt_id:= null;
2475 END;
2476 IF (l_debug = 1) THEN
2477 mdebug('std oper id:'||l_user_tt_id);
2478 end if;
2479
2480
2481 INSERT INTO MTL_CYCLE_COUNT_ENTRIES
2482 ( COST_GROUP_ID
2483 , PARENT_LPN_ID
2484 , OUTERMOST_LPN_ID
2485 , CYCLE_COUNT_ENTRY_ID
2486 , LAST_UPDATE_DATE
2487 , LAST_UPDATED_BY
2488 , CREATION_DATE
2489 , CREATED_BY
2490 , LAST_UPDATE_LOGIN
2491 , COUNT_LIST_SEQUENCE
2492 , COUNT_DATE_FIRST
2493 , COUNT_DATE_CURRENT
2494 , COUNT_DATE_PRIOR
2495 , COUNT_DATE_DUMMY
2496 , COUNTED_BY_EMPLOYEE_ID_FIRST
2497 , COUNTED_BY_EMPLOYEE_ID_CURRENT
2498 , COUNTED_BY_EMPLOYEE_ID_PRIOR
2499 , COUNTED_BY_EMPLOYEE_ID_DUMMY
2500 , COUNT_UOM_FIRST
2501 , COUNT_UOM_CURRENT
2502 , COUNT_UOM_PRIOR
2503 , COUNT_QUANTITY_FIRST
2504 , COUNT_QUANTITY_CURRENT
2505 , COUNT_QUANTITY_PRIOR
2506 , INVENTORY_ITEM_ID
2507 , SUBINVENTORY
2508 , ENTRY_STATUS_CODE
2509 , COUNT_DUE_DATE
2510 , ORGANIZATION_ID
2511 , CYCLE_COUNT_HEADER_ID
2512 , NUMBER_OF_COUNTS
2513 , LOCATOR_ID
2514 , ADJUSTMENT_QUANTITY
2515 , ADJUSTMENT_DATE
2516 , ADJUSTMENT_AMOUNT
2517 , ITEM_UNIT_COST
2518 , INVENTORY_ADJUSTMENT_ACCOUNT
2519 , APPROVAL_DATE
2520 , APPROVER_EMPLOYEE_ID
2521 , REVISION
2522 , LOT_NUMBER
2523 , LOT_CONTROL
2524 , SYSTEM_QUANTITY_FIRST
2525 , SYSTEM_QUANTITY_CURRENT
2526 , SYSTEM_QUANTITY_PRIOR
2527 , REFERENCE_FIRST
2528 , REFERENCE_CURRENT
2529 , REFERENCE_PRIOR
2530 , PRIMARY_UOM_QUANTITY_FIRST
2531 , PRIMARY_UOM_QUANTITY_CURRENT
2532 , PRIMARY_UOM_QUANTITY_PRIOR
2533 , COUNT_TYPE_CODE
2534 , TRANSACTION_REASON_ID
2535 , REQUEST_ID
2536 , PROGRAM_APPLICATION_ID
2537 , PROGRAM_ID
2538 , PROGRAM_UPDATE_DATE
2539 , APPROVAL_TYPE
2540 , ATTRIBUTE_CATEGORY
2541 , ATTRIBUTE1
2542 , ATTRIBUTE2
2543 , ATTRIBUTE3
2544 , ATTRIBUTE4
2545 , ATTRIBUTE5
2546 , ATTRIBUTE6
2547 , ATTRIBUTE7
2548 , ATTRIBUTE8
2549 , ATTRIBUTE9
2550 , ATTRIBUTE10
2551 , ATTRIBUTE11
2552 , ATTRIBUTE12
2553 , ATTRIBUTE13
2554 , ATTRIBUTE14
2555 , ATTRIBUTE15
2556 , SERIAL_NUMBER
2557 , SERIAL_DETAIL
2558 , APPROVAL_CONDITION
2559 , NEG_ADJUSTMENT_QUANTITY
2560 , NEG_ADJUSTMENT_AMOUNT
2561 , EXPORT_FLAG
2562 -- BEGIN INVCONV
2563 , SECONDARY_UOM_QUANTITY_FIRST
2564 , SECONDARY_UOM_QUANTITY_CURRENT
2565 , SECONDARY_UOM_QUANTITY_PRIOR
2566 , COUNT_SECONDARY_UOM_FIRST
2567 , COUNT_SECONDARY_UOM_CURRENT
2568 , COUNT_SECONDARY_UOM_PRIOR
2569 , SECONDARY_SYSTEM_QTY_FIRST
2570 , SECONDARY_SYSTEM_QTY_CURRENT
2571 , SECONDARY_SYSTEM_QTY_PRIOR
2572 , SECONDARY_ADJUSTMENT_QUANTITY
2573 -- END INVCONV
2574 , STANDARD_OPERATION_ID
2575 )
2576 VALUES
2577 ( /* Bug 7517428-Passing the cost group id to insert in MCCE*/
2578 MTL_CCEOI_VAR_PVT.G_COST_GROUP_ID
2579 , MTL_CCEOI_VAR_PVT.G_LPN_ID -- 8300310
2580 , MTL_CCEOI_VAR_PVT.G_LPN_ID
2581 , L_CCEntryId
2582 , sysdate
2583 , MTL_CCEOI_VAR_PVT.G_UserID
2584 , sysdate
2585 , MTL_CCEOI_VAR_PVT.G_UserID
2586 , MTL_CCEOI_VAR_PVT.G_UserID
2587 , nvl(p_interface_rec.COUNT_LIST_SEQUENCE,MTL_CCEOI_VAR_PVT.G_Seq_No)
2588 -- , p_interface_rec.count_list_sequence
2589 , NULL -- MTL_CCEOI_VAR_PVT.G_COUNT_DATE
2590 , NULL -- MTL_CCEOI_VAR_PVT.G_COUNT_DATE
2591 , NULL
2592 , NULL
2593 , NULL -- MTL_CCEOI_VAR_PVT.G_EMPLOYEE_ID
2594 , NULL -- MTL_CCEOI_VAR_PVT.G_EMPLOYEE_ID
2595 , NULL
2596 , NULL
2597 , NULL -- MTL_CCEOI_VAR_PVT.G_UOM_CODE
2598 , NULL -- MTL_CCEOI_VAR_PVT.G_UOM_CODE
2599 , NULL
2600 , NULL -- MTL_CCEOI_VAR_PVT.G_COUNT_QUANTITY
2601 , NULL -- MTL_CCEOI_VAR_PVT.G_COUNT_QUANTITY
2602 , NULL
2603 , MTL_CCEOI_VAR_PVT.G_INVENTORY_ITEM_ID
2604 , MTL_CCEOI_VAR_PVT.G_SUBINVENTORY
2605 , 1
2606 , l_count_due_date
2607 , p_interface_rec.ORGANIZATION_ID
2608 , MTL_CCEOI_VAR_PVT.G_CC_HEADER_ID
2609 , NULL -- 0 XXX number of counts (null for new entries)
2610 , MTL_CCEOI_VAR_PVT.G_LOCATOR_ID
2611 , NULL
2612 , NULL
2613 , NULL
2614 , NULL
2615 , NULL --MTL_CCEOI_VAR_PVT.G_ADJUST_ACCOUNT_ID
2616 , NULL
2617 , NULL
2618 , MTL_CCEOI_VAR_PVT.G_SKU_REC.REVISION -- NULL --Revision
2619 , MTL_CCEOI_VAR_PVT.G_SKU_REC.LOT_NUMBER -- NULL --Lot Number
2620 , decode(MTL_CCEOI_VAR_PVT.G_SKU_REC.LOT_CONTROL_CODE, 1, null,
2621 MTL_CCEOI_VAR_PVT.G_SKU_REC.LOT_CONTROL_CODE)
2622 , NULL -- MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY
2623 , NULL -- MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY
2624 , NULL
2625 , NULL -- p_interface_rec.REFERENCE
2626 , NULL -- p_interface_rec.REFERENCE
2627 , NULL
2628 , NULL
2629 , NULL
2630 , NULL
2631 , 2 -- UNSCHEDULED COUNT
2632 , NULL
2633 , MTL_CCEOI_VAR_PVT.G_RequestID
2634 , MTL_CCEOI_VAR_PVT.G_ProgramAppID
2635 , MTL_CCEOI_VAR_PVT.G_ProgramID
2636 , sysdate
2637 , NULL -- DECODE(
2638 -- MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.APPROVAL_OPTION_CODE,
2639 -- 1, 2, 2, 1, 3, 2, NULL)
2640 , p_interface_rec.ATTRIBUTE_CATEGORY
2641 , p_interface_rec.ATTRIBUTE1
2642 , p_interface_rec.ATTRIBUTE2
2643 , p_interface_rec.ATTRIBUTE3
2644 , p_interface_rec.ATTRIBUTE4
2645 , p_interface_rec.ATTRIBUTE5
2646 , p_interface_rec.ATTRIBUTE6
2647 , p_interface_rec.ATTRIBUTE7
2648 , p_interface_rec.ATTRIBUTE8
2649 , p_interface_rec.ATTRIBUTE9
2650 , p_interface_rec.ATTRIBUTE10
2651 , p_interface_rec.ATTRIBUTE11
2652 , p_interface_rec.ATTRIBUTE12
2653 , p_interface_rec.ATTRIBUTE13
2654 , p_interface_rec.ATTRIBUTE14
2655 , p_interface_rec.ATTRIBUTE15
2656 , p_interface_rec.SERIAL_NUMBER
2657 , NULL
2658 , NULL
2659 , NULL
2660 , NULL
2661 , 1 -- exported... do not forget to unexport
2662 -- BEGIN INVCONV
2663 , NULL
2664 , NULL
2665 , NULL
2666 , NULL
2667 , NULL
2668 , NULL
2669 , NULL
2670 , NULL
2671 , NULL
2672 , NULL
2673 -- END INVCONV
2674 , l_user_tt_id --10268469
2675 );
2676 IF (l_debug = 1) THEN
2677 MDEBUG( 'End of New CCId : '||to_char(L_CCEntryId));
2678 END IF;
2679 EXCEPTION
2680 when others then
2681 IF (l_debug = 1) THEN
2682 MDEBUG( 'Exception Error while Inserting..');
2683 MDEBUG( 'Error: ' || sqlerrm);
2684 END IF;
2685 raise fnd_api.g_exc_unexpected_error;
2686 END;
2687 END;
2688 --
2689 -- Insert the given record into MTL_CC_ENTRIES_INTERFACE
2690 PROCEDURE Insert_CCIEntry(
2691 p_interface_rec IN MTL_CCEOI_VAR_PVT.INV_CCEOI_TYPE ,
2692 x_return_status OUT NOCOPY VARCHAR2 )
2693 IS
2694 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2695 BEGIN
2696 -- Start OF comments
2697 -- API name : Insert_CCIEntry
2698 -- TYPE : Public
2699 -- Pre-reqs : None
2700 -- FUNCTION :
2701 -- inserts the exported RECORD INTO MTL_CC_ENTRIESINTERFACE TABLE
2702 -- Parameters:
2703 -- IN :
2704 -- p_interface_rec IN CCEOI_Rec_Type (required)
2705 -- complete interface RECORD
2706 --
2707 -- OUT :
2708 -- x_return_status VARCHAR2
2709 -- END OF comments
2710 DECLARE
2711 L_CCEOIId NUMBER := p_interface_rec.cc_entry_interface_id;
2712 BEGIN
2713 IF (l_debug = 1) THEN
2714 MDEBUG( 'Insert_CCIEntry: Before creation of new seq id');
2715 END IF;
2716
2717 X_return_status := FND_API.G_RET_STS_SUCCESS;
2718 --
2719
2720 IF p_interface_rec.cc_entry_interface_id IS NULL THEN
2721 BEGIN
2722 SELECT
2723 MTL_CC_ENTRIES_INTERFACE_S1.nextval
2724 INTO
2725 L_CCEOIId
2726 FROM
2727 dual;
2728 EXCEPTION
2729 WHEN OTHERS THEN
2730 IF (l_debug = 1) THEN
2731 mdebug('id creation failed failed');
2732 END IF;
2733 X_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2734 END;
2735 END IF;
2736 --
2737 BEGIN
2738 --
2739 -- Calculate the system quantity
2740 NULL;
2741 --
2742 IF (l_debug = 1) THEN
2743 mdebug('Insert_CCIEntry: ' || L_CCEOIId);
2744 END IF;
2745 INSERT INTO MTL_CC_ENTRIES_INTERFACE
2746 ( cost_group_name
2747 , cost_group_id
2748 , parent_lpn_id
2749 , outermost_lpn_id
2750 , CC_ENTRY_INTERFACE_ID
2751 , organization_id
2752 , last_update_date
2753 , last_updated_by
2754 , creation_date
2755 , created_by
2756 , last_update_login
2757 , CC_ENTRY_INTERFACE_GROUP_ID
2758 , CYCLE_COUNT_ENTRY_ID
2759 , action_code
2760 , cycle_count_header_id
2761 , cycle_count_header_name
2762 , count_list_sequence
2763 , inventory_item_id
2764 , item_segment1
2765 , item_segment2
2766 , item_segment3
2767 , item_segment4
2768 , item_segment5
2769 , item_segment6
2770 , item_segment7
2771 , item_segment8
2772 , item_segment9
2773 , item_segment10
2774 , item_segment11
2775 , item_segment12
2776 , item_segment13
2777 , item_segment14
2778 , item_segment15
2779 , item_segment16
2780 , item_segment17
2781 , item_segment18
2782 , item_segment19
2783 , item_segment20
2784 , revision
2785 , subinventory
2786 , locator_id
2787 , locator_segment1
2788 , locator_segment2
2789 , locator_segment3
2790 , locator_segment4
2791 , locator_segment5
2792 , locator_segment6
2793 , locator_segment7
2794 , locator_segment8
2795 , locator_segment9
2796 , locator_segment10
2797 , locator_segment11
2798 , locator_segment12
2799 , locator_segment13
2800 , locator_segment14
2801 , locator_segment15
2802 , locator_segment16
2803 , locator_segment17
2804 , locator_segment18
2805 , locator_segment19
2806 , locator_segment20
2807 , lot_number
2808 , serial_number
2809 , primary_uom_quantity
2810 , count_uom
2811 , count_unit_of_measure
2812 , count_quantity
2813 , system_quantity
2814 , adjustment_account_id
2815 , account_segment1
2816 , account_segment2
2817 , account_segment3
2818 , account_segment4
2819 , account_segment5
2820 , account_segment6
2821 , account_segment7
2822 , account_segment8
2823 , account_segment9
2824 , account_segment10
2825 , account_segment11
2826 , account_segment12
2827 , account_segment13
2828 , account_segment14
2829 , account_segment15
2830 , account_segment16
2831 , account_segment17
2832 , account_segment18
2833 , account_segment19
2834 , account_segment20
2835 , account_segment21
2836 , account_segment22
2837 , account_segment23
2838 , account_segment24
2839 , account_segment25
2840 , account_segment26
2841 , account_segment27
2842 , account_segment28
2843 , account_segment29
2844 , account_segment30
2845 , count_date
2846 , employee_id
2847 , employee_full_name
2848 , reference
2849 , transaction_reason_id
2850 , transaction_reason
2851 , request_id
2852 , program_application_id
2853 , program_id
2854 , program_update_date
2855 , lock_flag
2856 , process_flag
2857 , process_mode
2858 , valid_flag
2859 , delete_flag
2860 , status_flag
2861 , error_flag
2862 , attribute_category
2863 , attribute1
2864 , attribute2
2865 , attribute3
2866 , attribute4
2867 , attribute5
2868 , attribute6
2869 , attribute7
2870 , attribute8
2871 , attribute9
2872 , attribute10
2873 , attribute11
2874 , attribute12
2875 , attribute13
2876 , attribute14
2877 , attribute15
2878 , project_id
2879 , task_id
2880 -- BEGIN INVCONV
2881 , secondary_uom
2882 , secondary_unit_of_measure
2883 , secondary_count_quantity
2884 , secondary_system_quantity
2885 -- END INVCONV
2886 )
2887 VALUES
2888 ( p_interface_rec.cost_group_name
2889 , p_interface_rec.cost_group_id
2890 , p_interface_rec.parent_lpn_id
2891 , p_interface_rec.outermost_lpn_id
2892 , L_CCEOIId
2893 , p_interface_rec.organization_id
2894 , sysdate
2895 , MTL_CCEOI_VAR_PVT.G_UserID
2896 , sysdate
2897 , MTL_CCEOI_VAR_PVT.G_UserID
2898 , MTL_CCEOI_VAR_PVT.G_LoginID
2899 , P_interface_rec.CC_ENTRY_INTERFACE_GROUP_ID
2900 , P_interface_rec.CYCLE_COUNT_ENTRY_ID
2901 --- was always insert g_process. BUG??
2902 , nvl(p_interface_rec.action_code, MTL_CCEOI_VAR_PVT.G_PROCESS)
2903 , p_interface_rec.cycle_count_header_id
2904 , p_interface_rec.cycle_count_header_name
2905 , nvl(p_interface_rec.COUNT_LIST_SEQUENCE,MTL_CCEOI_VAR_PVT.G_Seq_No)
2906 , p_interface_rec.inventory_item_id
2907 , p_interface_rec.item_segment1
2908 , p_interface_rec.item_segment2
2909 , p_interface_rec.item_segment3
2910 , p_interface_rec.item_segment4
2911 , p_interface_rec.item_segment5
2912 , p_interface_rec.item_segment6
2913 , p_interface_rec.item_segment7
2914 , p_interface_rec.item_segment8
2915 , p_interface_rec.item_segment9
2916 , p_interface_rec.item_segment10
2917 , p_interface_rec.item_segment11
2918 , p_interface_rec.item_segment12
2919 , p_interface_rec.item_segment13
2920 , p_interface_rec.item_segment14
2921 , p_interface_rec.item_segment15
2922 , p_interface_rec.item_segment16
2923 , p_interface_rec.item_segment17
2924 , p_interface_rec.item_segment18
2925 , p_interface_rec.item_segment19
2926 , p_interface_rec.item_segment20
2927 , p_interface_rec.revision
2928 , p_interface_rec.subinventory
2929 , p_interface_rec.locator_id
2930 , p_interface_rec.locator_segment1
2931 , p_interface_rec.locator_segment2
2932 , p_interface_rec.locator_segment3
2933 , p_interface_rec.locator_segment4
2934 , p_interface_rec.locator_segment5
2935 , p_interface_rec.locator_segment6
2936 , p_interface_rec.locator_segment7
2937 , p_interface_rec.locator_segment8
2938 , p_interface_rec.locator_segment9
2939 , p_interface_rec.locator_segment10
2940 , p_interface_rec.locator_segment11
2941 , p_interface_rec.locator_segment12
2942 , p_interface_rec.locator_segment13
2943 , p_interface_rec.locator_segment14
2944 , p_interface_rec.locator_segment15
2945 , p_interface_rec.locator_segment16
2946 , p_interface_rec.locator_segment17
2947 , p_interface_rec.locator_segment18
2948 , p_interface_rec.locator_segment19
2949 , p_interface_rec.locator_segment20
2950 , p_interface_rec.lot_number
2951 , p_interface_rec.serial_number
2952 , p_interface_rec.primary_uom_quantity
2953 , p_interface_rec.count_uom
2954 , p_interface_rec.count_unit_of_measure
2955 , p_interface_rec.count_quantity
2956 , p_interface_rec.system_quantity --MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY
2957 , p_interface_rec.adjustment_account_id
2958 , p_interface_rec.account_segment1
2959 , p_interface_rec.account_segment2
2960 , p_interface_rec.account_segment3
2961 , p_interface_rec.account_segment4
2962 , p_interface_rec.account_segment5
2963 , p_interface_rec.account_segment6
2964 , p_interface_rec.account_segment7
2965 , p_interface_rec.account_segment8
2966 , p_interface_rec.account_segment9
2967 , p_interface_rec.account_segment10
2968 , p_interface_rec.account_segment11
2969 , p_interface_rec.account_segment12
2970 , p_interface_rec.account_segment13
2971 , p_interface_rec.account_segment14
2972 , p_interface_rec.account_segment15
2973 , p_interface_rec.account_segment16
2974 , p_interface_rec.account_segment17
2975 , p_interface_rec.account_segment18
2976 , p_interface_rec.account_segment19
2977 , p_interface_rec.account_segment20
2978 , p_interface_rec.account_segment21
2979 , p_interface_rec.account_segment22
2980 , p_interface_rec.account_segment23
2981 , p_interface_rec.account_segment24
2982 , p_interface_rec.account_segment25
2983 , p_interface_rec.account_segment26
2984 , p_interface_rec.account_segment27
2985 , p_interface_rec.account_segment28
2986 , p_interface_rec.account_segment29
2987 , p_interface_rec.account_segment30
2988 , p_interface_rec.count_date
2989 , p_interface_rec.employee_id
2990 , p_interface_rec.employee_full_name
2991 , p_interface_rec.reference
2992 , p_interface_rec.transaction_reason_id
2993 , p_interface_rec.transaction_reason
2994 , MTL_CCEOI_VAR_PVT.G_RequestID
2995 , MTL_CCEOI_VAR_PVT.G_ProgramAppID
2996 , MTL_CCEOI_VAR_PVT.G_ProgramID
2997 , sysdate
2998 , p_interface_rec.lock_flag
2999 , 1 --p_interface_rec.process_flag
3000 , p_interface_rec.process_mode
3001 , p_interface_rec.valid_flag
3002 , p_interface_rec.delete_flag
3003 , p_interface_rec.status_flag
3004 , p_interface_rec.error_flag
3005 , p_interface_rec.ATTRIBUTE_CATEGORY
3006 , p_interface_rec.attribute1
3007 , p_interface_rec.attribute2
3008 , p_interface_rec.attribute3
3009 , p_interface_rec.attribute4
3010 , p_interface_rec.attribute5
3011 , p_interface_rec.attribute6
3012 , p_interface_rec.attribute7
3013 , p_interface_rec.attribute8
3014 , p_interface_rec.attribute9
3015 , p_interface_rec.attribute10
3016 , p_interface_rec.attribute11
3017 , p_interface_rec.attribute12
3018 , p_interface_rec.attribute13
3019 , p_interface_rec.attribute14
3020 , p_interface_rec.attribute15
3021 , p_interface_rec.project_id
3022 , p_interface_rec.task_id
3023 -- BEGIN INVCONV
3024 , p_interface_rec.secondary_uom
3025 , p_interface_rec.secondary_unit_of_measure
3026 , p_interface_rec.secondary_count_quantity
3027 , p_interface_rec.secondary_system_quantity
3028 -- END INVCONV
3029 );
3030 IF (l_debug = 1) THEN
3031 mdebug('Insert_CCIEntry: Entry Inserted' || L_CCEOIId);
3032 END IF;
3033 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID := L_CCEOIId;
3034 MTL_CCEOI_VAR_PVT.G_REC_IN_SYSTEM := TRUE;
3035 EXCEPTION
3036 WHEN OTHERS THEN
3037 if p_interface_rec.organization_id is null then
3038 x_return_status := fnd_api.g_ret_sts_error;
3039 else
3040 X_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3041 end if;
3042 IF (l_debug = 1) THEN
3043 mdebug('Insert_CCIEntry: ' || sqlerrm);
3044 END IF;
3045 END;
3046 END;
3047 END;
3048 --
3049 -- Insert record into Cycle Count Interface error table
3050 PROCEDURE Insert_CCEOIError(
3051 p_cc_entry_interface_id IN NUMBER ,
3052 p_error_column_name IN VARCHAR2 ,
3053 p_error_table_name IN VARCHAR2 ,
3054 p_message_name IN VARCHAR2 )
3055 IS
3056 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3057 BEGIN
3058 -- Start OF comments
3059 -- API name :insert_CCEOIError
3060 -- TYPE : Private
3061 -- Pre-reqs : None
3062 -- FUNCTION :
3063 -- inserts error information INTO the interface error TABLE
3064 -- Parameters
3065 -- IN:
3066 -- p_cc_entry_interface_id IN NUMBER (required)
3067 -- ID OF the interface RECORD
3068 --
3069 -- p_error_column_name IN VARCHAR2 (required)
3070 -- Columnname OF the errorvalue
3071 --
3072 -- p_error_table_name IN VARCHAR2 (required)
3073 -- tablename OF the errorvalue
3074 --
3075 -- p_message_name IN VARCHAR2 (required)
3076 -- name OF the message
3077 --
3078 -- END OF COMMENT
3079 DECLARE
3080 L_interface_error_id NUMBER;
3081 BEGIN
3082 IF (l_debug = 1) THEN
3083 MDEBUG('Insert error: ' || FND_MESSAGE.GET_STRING('INV', p_message_name));
3084 END IF;
3085 --
3086 SELECT MTL_CC_INTERFACE_ERRORS_S.nextval
3087 INTO
3088 L_interface_error_id
3089 FROM
3090 dual;
3091 --
3092 INSERT INTO mtl_cc_interface_errors(
3093 interface_error_id,
3094 cc_entry_interface_id,
3095 last_update_date,
3096 last_updated_by,
3097 creation_date,
3098 created_by,
3099 last_update_login,
3100 request_id,
3101 program_application_id,
3102 program_id,
3103 program_update_date,
3104 error_message,
3105 error_column_name,
3106 error_table_name,
3107 message_name
3108 )
3109 VALUES
3110 (L_interface_error_id,
3111 p_cc_entry_interface_id,
3112 sysdate,
3113 MTL_CCEOI_VAR_PVT.G_UserID,
3114 sysdate,
3115 MTL_CCEOI_VAR_PVT.G_UserID,
3116 MTL_CCEOI_VAR_PVT.G_LoginID,
3117 MTL_CCEOI_VAR_PVT.G_RequestID,
3118 MTL_CCEOI_VAR_PVT.G_ProgramAppID,
3119 MTL_CCEOI_VAR_PVT.G_ProgramID,
3120 sysdate,
3121 FND_MESSAGE.GET_STRING('INV', p_message_name),
3122 p_error_column_name,
3123 p_error_table_name,
3124 p_message_name);
3125 --
3126 EXCEPTION
3127 WHEN OTHERS THEN
3128 IF (l_debug = 1) THEN
3129 MDEBUG('Insert_CCEOIError - Exception: ' || sqlerrm);
3130 END IF;
3131 END;
3132 END;
3133
3134 --
3135 -- This code was derived from INVATCEN.pld and is full of strange stuff
3136 -- Needs thorough review/rewrite
3137 -- Existing Serial number - checks existance of serial number
3138 -- in a given location and then runs adjustment transaction if necessary
3139 PROCEDURE Existing_Serial_Number(
3140 p_reference IN VARCHAR2 DEFAULT NULL,
3141 p_primary_uom_quantity IN NUMBER ,
3142 p_count_uom IN VARCHAR2 ,
3143 p_serial_number IN VARCHAR2 ,
3144 p_subinventory IN VARCHAR2 ,
3145 p_lot_number IN VARCHAR2 ,
3146 p_lot_expiration IN date ,
3147 p_revision IN VARCHAR2 ,
3148 p_transaction_reason_id IN NUMBER ,
3149 p_transaction_process_mode IN NUMBER DEFAULT 3,
3150 p_simulate IN VARCHAR2 DEFAULT FND_API.G_FALSE)
3151 IS
3152 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3153 BEGIN
3154 -- Start OF comments
3155 -- API name : Existing_Serial_number
3156 -- TYPE : Private
3157 -- Pre-reqs : None
3158 -- FUNCTION :
3159 -- Parameters:
3160 -- IN :
3161 -- p_reference IN VARCHAR2 (optional)
3162 -- default NULL
3163 --
3164 -- p_primary_uom_quantity IN NUMBER
3165 --
3166 -- p_count_uom IN VARCHAR2 (required)
3167 --
3168 -- p_subinventory IN VARCHAR2(required)
3169 --
3170 -- p_lot_number IN VARCHAR2 (required)
3171 --
3172 -- p_lot_expiration_date DATE (required)
3173 --
3174 -- p_revision IN VARCHAR2(required)
3175 --
3176 -- p_transaction_reasion_id IN NUMBER (required)
3177 --
3178 -- p_serial_number IN VARCHAR2 (required)
3179 --
3180 -- p_transaction_process_mode IN NUMBER (required-defaulted)
3181 -- default = 3 (Background processing)
3182 --
3183 -- p_simulate IN VARCHAR2 (defaulted)
3184 -- default = FND_API.G_FALSE - may update data in any tables
3185 -- FND_API.G_TRUE - may only update data in the interface tables
3186 -- OUT :
3187 -- Version: Current Version 0.9
3188 -- Changed : Nothing
3189 -- No Previous Version 0.0
3190 -- Initial version 0.9
3191 -- Notes : Note text
3192 -- END OF comments
3193 DECLARE
3194 --
3195 L_success BOOLEAN;
3196 L_issue VARCHAR2(1) := 'I';
3197 L_Receipt VARCHAR2(1) := 'R';
3198 --
3199 BEGIN
3200 --
3201 --
3202 IF (l_debug = 1) THEN
3203 MDEBUG( 'Inside Existing_Serial_Number');
3204 END IF;
3205
3206
3207 -- XXX there used to be a check for serial detail being 2 (qty only)
3208 -- it is unclear what role serial_detail field plays in 1 serial/entry
3209 -- and therefore i am removing it
3210 -- if the s/n is shown on the system, but was count as missing
3211 IF(MTL_CCEOI_VAR_PVT.G_adjustment_quantity = -1) THEN
3212 -- Adjust if possible
3213 IF MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.serial_adjustment_option = 1 THEN
3214 --
3215 -- Issue
3216 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 5;
3217 l_success := MTL_CCEOI_PROCESS_PVT.check_serial_location(L_issue);
3218
3219 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.NEG_ADJUSTMENT_QUANTITY := 1;
3220 --
3221 IF(L_success = FALSE) THEN
3222 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.APPROVAL_CONDITION := 1;
3223 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 2;
3224 END IF;
3225 --
3226 -- if serial adjustment option is "review all adjustments",
3227 -- THEN send to approval
3228 ELSIF
3229 (MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.serial_adjustment_option = 2) THEN
3230
3231 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.NEG_ADJUSTMENT_QUANTITY := 1;
3232 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.APPROVAL_CONDITION := 3;
3233
3234 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 2;
3235 --
3236 END IF;
3237 -- if the s/n is missing on the system, but was count as present
3238 ELSIF
3239 (MTL_CCEOI_VAR_PVT.G_adjustment_quantity = 1) THEN
3240 --
3241 IF(
3242 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.serial_adjustment_option = 1) THEN
3243 -- Receipt
3244 L_success := MTL_CCEOI_PROCESS_PVT.check_serial_location(L_Receipt);
3245 --
3246 -- in case of failure just send for manual approval for now
3247 IF (L_success = TRUE) THEN
3248
3249 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 5;
3250 ELSE
3251 -- send it for further manual approval
3252 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.APPROVAL_CONDITION := 1;
3253 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 2;
3254 END IF;
3255
3256 --
3257 -- if serial adjustment option is "review all adjustments",
3258 -- then send to approval
3259 ELSIF
3260 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.serial_adjustment_option=2 THEN
3261
3262
3263 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.APPROVAL_CONDITION := 3;
3264 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 2;
3265 --
3266 END IF;
3267 -- all other cases considered as no problem, no adjustment required
3268 ELSE
3269 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.NEG_ADJUSTMENT_QUANTITY := NULL;
3270 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.APPROVAL_CONDITION := NULL;
3271
3272
3273 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 5;
3274 --
3275 --
3276 END IF;
3277 Final_Preupdate_Logic(
3278 p_reference => p_reference
3279 , p_primary_uom_quantity => p_primary_uom_quantity
3280 , p_count_uom => p_count_uom
3281 , p_serial_number => p_serial_number
3282 , p_subinventory => p_subinventory
3283 , p_lot_number => p_lot_number
3284 , p_lot_expiration => p_lot_expiration
3285 , p_revision => p_revision
3286 , p_transaction_reason_id => p_transaction_reason_id
3287 , p_transaction_process_mode => p_transaction_process_mode
3288 , p_simulate => p_simulate);
3289
3290 --
3291 END;
3292 END;
3293 --
3294 -- Set the export flag in the table MTL_CYCLE_COUNT_ENTRIES
3295 PROCEDURE Set_CCExport(
3296 p_api_version IN NUMBER ,
3297 p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE,
3298 p_commit IN VARCHAR2 DEFAULT FND_API.G_FALSE,
3299 p_validation_level IN NUMBER DEFAULT FND_API.G_VALID_LEVEL_FULL,
3300 x_return_status OUT NOCOPY VARCHAR2 ,
3301 x_msg_count OUT NOCOPY NUMBER ,
3302 x_msg_data OUT NOCOPY VARCHAR2 ,
3303 p_cycle_count_entry_id IN NUMBER ,
3304 p_export_flag IN NUMBER )
3305 IS
3306 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3307 BEGIN
3308 -- Start OF comments
3309 -- API name : Set_CCExport
3310 -- TYPE : Private
3311 -- Pre-reqs : None
3312 -- FUNCTION :
3313 -- SET export flag to orginal RECORD IN the MTL_CYCLE_COUNT_ENTRIES TABLE
3314 -- Parameters:
3315 -- IN :
3316 -- p_api_version IN NUMBER (required)
3317 -- API Version of this procedure
3318 --
3319 -- p_init_msg_list IN VARCHAR2 (optional)
3320 -- DEFAULT = FND_API.G_FALSE,
3321 --
3322 -- p_commit IN VARCHAR2 (optional)
3323 -- DEFAULT = FND_API.G_FALSE,
3324 --
3325 -- p_validation_level IN NUMBER (optional)
3326 -- DEFAULT = FND_API.G_VALID_LEVEL_FULL,
3327 --
3328 -- p_cycle_count_entry_id IN NUMBER (required)
3329 -- cycle COUNT entry id
3330 --
3331 -- P_export_flag IN NUMBER (required)
3332 -- 1 = Yes it is exported
3333 -- 2 = No it is not exported
3334 -- value OF the export flag to be SET
3335 -- OUT :
3336 -- X_return_status OUT NUMBER
3337 -- Result of all the operations
3338 -- x_msg_count OUT NUMBER,
3339 -- x_msg_data OUT VARCHAR2,
3340 -- RETURN value OF the Error status
3341 --
3342 -- Version: Current Version 0.9
3343 -- Changed : Nothing
3344 -- No Previous Version 0.0
3345 -- Initial version 0.9
3346 -- Notes : Note text
3347 -- END OF comments
3348 DECLARE
3349 L_api_version CONSTANT NUMBER := 0.9;
3350 L_api_name CONSTANT VARCHAR2(30) := 'Set_CCExport';
3351 BEGIN
3352 -- Standard start of API savepoint
3353 SAVEPOINT Set_CCExport;
3354 --
3355 -- Standard Call to check for call compatibility
3356 IF (l_debug = 1) THEN
3357 MDEBUG( 'SetCCExport : Before API');
3358 END IF;
3359 IF NOT FND_API.Compatible_API_Call(
3360 l_api_version, p_api_version
3361 , l_api_name
3362 , G_PKG_NAME) THEN
3363 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3364 END IF;
3365 IF (l_debug = 1) THEN
3366 MDEBUG( 'SetCCExport : After API');
3367 END IF;
3368 --
3369 -- Initialize message list if p_init_msg_list is set to true
3370 IF FND_API.to_Boolean(p_init_msg_list) THEN
3371 FND_MSG_PUB.initialize;
3372 END IF;
3373 --
3374 IF (l_debug = 1) THEN
3375 MDEBUG( 'SetCCExport : After Init');
3376 END IF;
3377 -- Initialisize API return status to access
3378 x_return_status := FND_API.G_RET_STS_SUCCESS;
3379 --
3380 -- API body
3381 --
3382 IF (l_debug = 1) THEN
3383 MDEBUG( 'SetCCExport : Before Update CCEId '||to_char(p_cycle_count_entry_id) ||' to '|| to_char(p_export_flag));
3384 END IF;
3385
3386 UPDATE mtl_cycle_count_entries
3387 SET
3388 export_flag = p_export_flag
3389 , last_update_date = sysdate
3390 , last_updated_by = MTL_CCEOI_VAR_PVT.G_UserID
3391 , last_update_login = MTL_CCEOI_VAR_PVT.G_LoginID
3392 , request_id = MTL_CCEOI_VAR_PVT.G_RequestID
3393 , program_application_id = MTL_CCEOI_VAR_PVT.G_ProgramAppID
3394 , program_id = MTL_CCEOI_VAR_PVT.G_ProgramID
3395 , program_update_date = sysdate
3396 WHERE
3397 cycle_Count_entry_id = p_cycle_count_entry_id;
3398
3399 /*
3400 IF (l_debug = 1) THEN
3401 MDEBUG( 'SetCCExport : After Update');
3402 END IF;
3403 */
3404 --
3405 IF SQL%ROWCOUNT <> 1 THEN
3406 IF (l_debug = 1) THEN
3407 MDEBUG( 'SetCCExport : Error Update');
3408 END IF;
3409 FND_MESSAGE.SET_NAME('INV', 'INV_CCEOI_COULD_NOT_LOCK');
3410 FND_MSG_PUB.Add;
3411 RAISE FND_API.G_EXC_ERROR;
3412 END IF;
3413 --
3414 -- END of API body
3415 -- Standard check of p_commit
3416 IF FND_API.to_Boolean(p_commit) THEN
3417 COMMIT;
3418 END IF;
3419 -- --
3420 -- Standard call to get message count and if count is 1, get message info
3421 FND_MSG_PUB.Count_And_Get
3422 (p_count => x_msg_count
3423 , p_data => x_msg_data);
3424 EXCEPTION
3425 WHEN FND_API.G_EXC_ERROR THEN
3426 --
3427 ROLLBACK TO Set_CCExport;
3428 --
3429 x_return_status := FND_API.G_RET_STS_ERROR;
3430 --
3431 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
3432 , p_data => x_msg_data);
3433 --
3434 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3435 --
3436 ROLLBACK TO Set_CCExport;
3437 --
3438 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3439 --
3440 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
3441 , p_data => x_msg_data);
3442 --
3443 WHEN OTHERS THEN
3444 --
3445 ROLLBACK TO Set_CCExport;
3446 --
3447 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3448 --
3449 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
3450 FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
3451 END IF;
3452 --
3453 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
3454 , p_data => x_msg_data);
3455 END;
3456 END;
3457 --
3458 -- Set the Flags in the interface table.
3459 PROCEDURE Set_CCEOIFlags(
3460 p_api_version IN NUMBER ,
3461 p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE,
3462 p_commit IN VARCHAR2 DEFAULT FND_API.G_FALSE,
3463 p_validation_level IN NUMBER DEFAULT FND_API.G_VALID_LEVEL_FULL,
3464 x_return_status OUT NOCOPY VARCHAR2 ,
3465 x_msg_count OUT NOCOPY NUMBER ,
3466 x_msg_data OUT NOCOPY VARCHAR2 ,
3467 p_cc_entry_interface_id IN NUMBER ,
3468 p_flags IN VARCHAR2 )
3469 IS
3470 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3471 BEGIN
3472 -- Start OF comments
3473 -- API name : Set_CCEOIFlags
3474 -- TYPE : Private
3475 -- Pre-reqs : None
3476 -- FUNCTION :
3477 -- SET all the flags IN the interface TABLE
3478 -- mtl_cc_entries_interface
3479 -- Parameters:
3480 -- IN :
3481 -- p_api_version IN NUMBER (required)
3482 -- API Version of this procedure
3483 --
3484 -- p_init_msg_list IN VARCHAR2 (optional)
3485 -- DEFAULT = FND_API.G_FALSE,
3486 --
3487 -- p_commit IN VARCHAR2 (optional)
3488 -- DEFAULT = FND_API.G_FALSE,
3489 --
3490 -- p_validation_level IN NUMBER (optional)
3491 -- DEFAULT = FND_API.G_VALID_LEVEL_FULL,
3492 --
3493 -- p_cc_entry_interface_id IN NUMBER (required)
3494 -- cycle COUNT entry interface id
3495 --
3496 -- P_flags IN VARCHAR2(4) (required)
3497 -- value OF the flags. IF one letter IS $, this means
3498 -- that the value OF the column IS NOT changed
3499 -- 1. Letter = Error_flag
3500 -- 2. Letter = delete_flag
3501 -- 3. Letter = status_flag
3502 -- 4. Letter = valid_flag
3503 --
3504 -- OUT :
3505 -- X_return_status OUT NUMBER
3506 -- Result of all the operations
3507 -- x_msg_count OUT NUMBER,
3508 -- x_msg_data OUT VARCHAR2,
3509 -- RETURN value OF the Error status
3510 --
3511 -- Version: Current Version 0.9
3512 -- Changed : Nothing
3513 -- No Previous Version 0.0
3514 -- Initial version 0.9
3515 -- Notes : Note text
3516 -- END OF comments
3517 DECLARE
3518 L_api_version CONSTANT NUMBER := 0.9;
3519 L_api_name CONSTANT VARCHAR2(30) := 'Set_CCEOIFlag';
3520 L_error NUMBER;
3521 L_valid NUMBER;
3522 L_status NUMBER;
3523 L_delete NUMBER;
3524 BEGIN
3525
3526 -- Standard start of API savepoint
3527 SAVEPOINT SET_CCEOIVALID;
3528 --
3529 -- Standard Call to check for call compatibility
3530 IF NOT FND_API.Compatible_API_Call(
3531 l_api_version, p_api_version
3532 , l_api_name
3533 , G_PKG_NAME) THEN
3534 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3535 END IF;
3536
3537 --
3538 -- Initialize message list if p_init_msg_list is set to true
3539 IF FND_API.to_Boolean(p_init_msg_list) THEN
3540 FND_MSG_PUB.initialize;
3541 END IF;
3542
3543 --
3544 -- Initialisize API return status to access
3545 x_return_status := FND_API.G_RET_STS_SUCCESS;
3546 --
3547 -- API body
3548 --
3549 -- UPDATE the flags according to the parameter
3550 --
3551
3552 --MDEBUG( 'Process:Setsflag : IFace ID'||to_char( p_cc_entry_interface_id));
3553
3554 IF (l_debug = 1) THEN
3555 MDEBUG( 'Process:Setsflag-Delete '||p_flags);
3556 END IF;
3557
3558 UPDATE mtl_cc_entries_interface
3559 SET
3560 last_update_date = sysdate
3561 , last_updated_by = MTL_CCEOI_VAR_PVT.G_UserID
3562 , last_update_login = MTL_CCEOI_VAR_PVT.G_LoginID
3563 , request_id = MTL_CCEOI_VAR_PVT.G_RequestID
3564 , program_application_id = MTL_CCEOI_VAR_PVT.G_ProgramAppID
3565 , program_id = MTL_CCEOI_VAR_PVT.G_ProgramID
3566 , program_update_date = sysdate
3567 , error_flag = DECODE(SUBSTR(p_flags, 1, 1), '$', error_flag, SUBSTR(p_flags, 1, 1))
3568 , delete_flag = DECODE(SUBSTR(p_flags, 2, 1), '$', delete_flag, SUBSTR(p_flags, 2, 1))
3569 , status_flag = DECODE(SUBSTR(p_flags, 3, 1), '$', status_flag, SUBSTR(p_flags, 3, 1))
3570 , valid_flag = decode ( SUBSTR(p_flags, 1, 1),'1','2',DECODE(SUBSTR(p_flags, 4, 1), '$', valid_flag, SUBSTR(p_flags, 4, 1)))
3571 -- , cycle_count_entry_id = nvl(cycle_count_entry_id,MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.CYCLE_COUNT_ENTRY_ID)
3572 WHERE
3573 cc_entry_interface_id = p_cc_entry_interface_id;
3574
3575 --
3576 IF SQL%ROWCOUNT <> 1 THEN
3577 FND_MESSAGE.SET_NAME('INV', 'INV_CCEOI_COULD_NOT_LOCK');
3578 FND_MSG_PUB.Add;
3579 RAISE FND_API.G_EXC_ERROR;
3580 END IF;
3581 --
3582 -- END of API body
3583 -- Standard check of p_commit
3584 IF FND_API.to_Boolean(p_commit) THEN
3585 COMMIT;
3586 END IF;
3587 -- --
3588 -- Standard call to get message count and if count is 1, get message info
3589 FND_MSG_PUB.Count_And_Get
3590 (p_count => x_msg_count
3591 , p_data => x_msg_data);
3592 EXCEPTION
3593 WHEN FND_API.G_EXC_ERROR THEN
3594 --
3595 IF (l_debug = 1) THEN
3596 mdebug('Error in Set_CCEOIFlags');
3597 END IF;
3598 ROLLBACK TO Set_CCEOIValid;
3599 --
3600 x_return_status := FND_API.G_RET_STS_ERROR;
3601 --
3602 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
3603 , p_data => x_msg_data);
3604 --
3605 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3606 --
3607 IF (l_debug = 1) THEN
3608 mdebug('Unexpected Error in Set_CCEOIFlags');
3609 END IF;
3610 ROLLBACK TO Set_CCEOIValid;
3611 --
3612 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3613 --
3614 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
3615 , p_data => x_msg_data);
3616 --
3617 WHEN OTHERS THEN
3618 --
3619 IF (l_debug = 1) THEN
3620 mdebug('Other Error in Set_CCEOIFlags');
3621 END IF;
3622 ROLLBACK TO SET_CCEOIVALID;
3623 IF (l_debug = 1) THEN
3624 mdebug('After Rollback for Other Error in Set_CCEOIFlags');
3625 END IF;
3626 --
3627 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3628 --
3629 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
3630 FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
3631 END IF;
3632 --
3633 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
3634 , p_data => x_msg_data);
3635 END;
3636 END;
3637 --
3638 -- Validates the cycle count header
3639 PROCEDURE Validate_CHeader(
3640 p_api_version IN NUMBER ,
3641 p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE,
3642 p_commit IN VARCHAR2 DEFAULT FND_API.G_FALSE,
3643 p_validation_level IN NUMBER DEFAULT FND_API.G_VALID_LEVEL_FULL,
3644 x_return_status OUT NOCOPY VARCHAR2 ,
3645 x_msg_count OUT NOCOPY NUMBER ,
3646 x_msg_data OUT NOCOPY VARCHAR2 ,
3647 x_errorcode OUT NOCOPY NUMBER ,
3648 p_cycle_count_header_id IN NUMBER ,
3649 p_cycle_count_header_name IN VARCHAR2 DEFAULT NULL)
3650 IS
3651 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3652 BEGIN
3653 -- Start OF comments
3654 -- API name : Validate_CHeader
3655 -- TYPE : Private
3656 -- Pre-reqs : None
3657 -- FUNCTION :
3658 -- Validates the cycle COUNT header information.
3659 -- Parameters:
3660 -- IN :
3661 -- p_api_version IN NUMBER (required)
3662 -- API Version of this procedure
3663 --
3664 -- p_init_msg_list IN VARCHAR2 (optional)
3665 -- DEFAULT = FND_API.G_FALSE,
3666 --
3667 -- p_commit IN VARCHAR2 (optional)
3668 -- DEFAULT = FND_API.G_FALSE
3669 --
3670 -- p_validation_level IN NUMBER (optional)
3671 -- DEFAULT = FND_API.G_VALID_LEVEL_FULL,
3672 --
3673 -- p_cycle_count_header_id IN NUMBER default NULL (required - defaulted NULL)
3674 -- Cycle COUNT header ID
3675 --
3676 -- p_cycle_count_header_name IN VARCHAR2 (optional)
3677 -- Default = NULL
3678 -- cycle COUNT header name, only IF ID IS missing
3679 --
3680 -- OUT :
3681 -- X_return_status OUT NUMBER
3682 -- Result of all the operations
3683 --
3684 -- x_msg_count OUT NUMBER,
3685 --
3686 -- x_msg_data OUT VARCHAR2,
3687 --
3688 -- X_ErrorCode OUT NUMBER
3689 -- Version: Current Version 0.9
3690 -- Changed : Nothing
3691 -- No Previous Version 0.0
3692 -- Initial version 0.9
3693 -- Notes : Note text
3694 -- END OF comments
3695 DECLARE
3696 --
3697 L_api_version CONSTANT NUMBER := 0.9;
3698 L_api_name CONSTANT VARCHAR2(30) := 'Validate_CHeader';
3699 BEGIN
3700 -- Standard start of API savepoint
3701 SAVEPOINT Validate_CHeader;
3702 --
3703 -- Standard Call to check for call compatibility
3704 IF NOT FND_API.Compatible_API_Call(l_api_version
3705 , p_api_version
3706 , l_api_name
3707 , G_PKG_NAME) THEN
3708 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3709 END IF;
3710 --
3711 -- Initialize message list if p_init_msg_list is set to true
3712 IF FND_API.to_Boolean(p_init_msg_list) THEN
3713 FND_MSG_PUB.initialize;
3714 END IF;
3715 --
3716 -- Initialisize API return status to access
3717 x_return_status := FND_API.G_RET_STS_SUCCESS;
3718 --
3719 -- API body
3720 IF (l_debug = 1) THEN
3721 mdebug('Process: In Validate_CHeader ' || to_char(p_cycle_count_header_id));
3722 END IF;
3723
3724 -- Validate the cycle COUNT header
3725 MTL_INV_VALIDATE_GRP.Validate_CountHeader(
3726 p_api_version => 0.9,
3727 x_return_status => x_return_status,
3728 x_msg_count => x_msg_count,
3729 x_msg_data => x_msg_data,
3730 X_ErrorCode => x_errorcode,
3731 p_cycle_count_header_id => p_cycle_count_header_id,
3732 p_cycle_count_header_name => p_cycle_count_header_name
3733 );
3734 IF (l_debug = 1) THEN
3735 mdebug('Process: In Validate_CHeader return'||x_return_status);
3736 END IF;
3737 -- Write INTO interface error TABLE
3738 IF x_errorcode = 2 THEN
3739 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
3740 p_cc_entry_interface_id =>
3741 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID, p_error_column_name =>
3742 'CYCLE_COUNT_HEADER_ID'
3743 , p_error_table_name => 'MTL_CYCLE_COUNT_HEADERS'
3744 , p_message_name => 'INV_CCEOI_INVALID_HEADER'
3745 );
3746 ELSIF
3747 x_errorcode = 1 THEN
3748 -- Write INTO interface error TABLE
3749 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
3750 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
3751 , p_error_column_name => 'CYCLE_COUNT_HEADER_ID'
3752 , p_error_table_name => 'MTL_CYCLE_COUNT_HEADERS'
3753 , p_message_name => 'INV_CCEOI_NO_HEADER'
3754 );
3755 ELSIF
3756 x_errorcode = 45 THEN
3757 -- Write INTO interface error TABLE
3758 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
3759 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
3760 , p_error_column_name => 'CYCLE_COUNT_HEADER_ID'
3761 , p_error_table_name => 'MTL_CYCLE_COUNT_HEADERS'
3762 , p_message_name => 'INV_CCEOI_MULT_HEADER'
3763 );
3764 ELSIF x_errorcode = 0 THEN
3765 -- Get stock_locator_control
3766 MTL_INV_VALIDATE_GRP.Get_StockLocatorControlCode(
3767 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.organization_id);
3768 IF (l_debug = 1) THEN
3769 mdebug('Process: In Validate_CHeader derive stock locator ='||to_char(MTL_CCEOI_VAR_PVT.G_STOCK_LOCATOR_CONTROL_CODE));
3770 END IF;
3771
3772 -- derive adjustment account info
3773 MTL_CCEOI_VAR_PVT.G_ADJUST_ACCOUNT_ID :=
3774 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.INVENTORY_ADJUSTMENT_ACCOUNT;
3775 END IF;
3776 --
3777 -- END of API body
3778 -- Standard check of p_commit
3779 IF FND_API.to_Boolean(p_commit) THEN
3780 COMMIT;
3781 END IF;
3782 -- Standard call to get message count and if count is 1, get message info
3783 FND_MSG_PUB.Count_And_Get
3784 (p_count => x_msg_count
3785 , p_data => x_msg_data);
3786 EXCEPTION
3787 WHEN FND_API.G_EXC_ERROR THEN
3788 --
3789 --
3790 x_return_status := FND_API.G_RET_STS_ERROR;
3791 --
3792 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
3793 , p_data => x_msg_data);
3794 --
3795 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3796 --
3797 --
3798 x_errorcode := -1;
3799 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3800 --
3801 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
3802 , p_data => x_msg_data);
3803 --
3804 WHEN OTHERS THEN
3805 --
3806 --
3807 x_errorcode := -1;
3808 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3809 --
3810 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
3811 FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
3812 END IF;
3813 --
3814 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
3815 , p_data => x_msg_data);
3816 END;
3817 END;
3818 --
3819 -- Validate the count list sequence of the cycle count entry
3820 PROCEDURE Validate_CountListSeq(
3821 p_api_version IN NUMBER ,
3822 p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE,
3823 p_commit IN VARCHAR2 DEFAULT FND_API.G_FALSE,
3824 p_validation_level IN NUMBER DEFAULT FND_API.G_VALID_LEVEL_FULL,
3825 x_return_status OUT NOCOPY VARCHAR2 ,
3826 x_msg_count OUT NOCOPY NUMBER ,
3827 x_msg_data OUT NOCOPY VARCHAR2 ,
3828 x_errorcode OUT NOCOPY NUMBER ,
3829 p_cycle_count_header_id IN NUMBER ,
3830 p_cycle_count_entry_id IN NUMBER ,
3831 p_count_list_sequence IN NUMBER ,
3832 p_organization_id IN NUMBER )
3833 IS
3834 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3835 BEGIN
3836 -- Start OF comments
3837 -- API name : Validate_CountListSeq
3838 -- TYPE : Private
3839 -- Pre-reqs : None
3840 -- FUNCTION :
3841 -- Validates the cycle COUNT list sequence for the specified
3842 -- header information.
3843 -- Parameters:
3844 -- IN :
3845 -- p_api_version IN NUMBER (required)
3846 -- API Version of this procedure
3847 --
3848 -- p_init_msg_list IN VARCHAR2 (optional)
3849 -- DEFAULT = FND_API.G_FALSE,
3850 --
3851 -- p_commit IN VARCHAR2 (optional)
3852 -- DEFAULT = FND_API.G_FALSE
3853 --
3854 -- p_validation_level IN NUMBER (optional)
3855 -- DEFAULT = FND_API.G_VALID_LEVEL_FULL,
3856 -- 0 = FOR Export validation
3857 --
3858 -- p_cycle_count_header_id IN NUMBER (required -)
3859 -- Cycle COUNT header ID
3860 --
3861 -- p_count_list_sequence IN NUMBER (required)
3862 -- COUNT list sequence
3863 --
3864 -- p_organization_id IN NUMBER (required)
3865 --
3866 -- OUT :
3867 -- X_return_status OUT NUMBER
3868 -- Result of all the operations
3869 --
3870 -- x_msg_count OUT NUMBER,
3871 --
3872 -- x_msg_data OUT VARCHAR2,
3873 --
3874 -- X_ErrorCode OUT NUMBER
3875 -- Version: Current Version 0.9
3876 -- Changed : Nothing
3877 -- No Previous Version 0.0
3878 -- Initial version 0.9
3879 -- Notes : Note text
3880 -- END OF comments
3881 DECLARE
3882 --
3883 L_api_version CONSTANT NUMBER := 0.9;
3884 L_api_name CONSTANT VARCHAR2(30) := 'Validate_CountListSeq';
3885 BEGIN
3886 -- Standard start of API savepoint
3887 SAVEPOINT Validate_CountListSeq;
3888 --
3889 -- Standard Call to check for call compatibility
3890 IF NOT FND_API.Compatible_API_Call(l_api_version
3891 , p_api_version
3892 , l_api_name
3893 , G_PKG_NAME) THEN
3894 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3895 END IF;
3896 --
3897 -- Initialize message list if p_init_msg_list is set to true
3898 IF FND_API.to_Boolean(p_init_msg_list) THEN
3899 FND_MSG_PUB.initialize;
3900 END IF;
3901 --
3902 -- Initialisize API return status to access
3903 x_return_status := FND_API.G_RET_STS_SUCCESS;
3904 --
3905 -- API body
3906 --
3907 IF (l_debug = 1) THEN
3908 mdebug('Process: In Validate_CountListSequence ' || to_char(p_count_list_sequence));
3909 END IF;
3910 MTL_INV_VALIDATE_GRP.Validate_CountListSequence(
3911 p_api_version => 0.9,
3912 x_return_status => x_return_status,
3913 x_msg_count => x_msg_count,
3914 x_msg_data => x_msg_data,
3915 X_ErrorCode => x_errorcode,
3916 p_cycle_count_header_id => p_cycle_count_header_id,
3917 p_cycle_count_entry_id => p_cycle_count_entry_id,
3918 p_count_list_sequence => p_count_list_sequence,
3919 p_organization_id => p_organization_id
3920 );
3921 IF (l_debug = 1) THEN
3922 mdebug('Process: In Validate_CountListSequence Return='||x_return_status || ' ' || to_char(x_errorcode));
3923 END IF;
3924 --
3925 IF x_errorcode = 46 THEN
3926 -- Write INTO interface error TABLE
3927 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
3928 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
3929 , p_error_column_name => 'CYCLE_COUNT_HEADER_ID'
3930 , p_error_table_name => 'MTL_CYCLE_COUNT_HEADERS'
3931 , p_message_name => 'INV_CCEOI_UNMATCH_LISTSEQ'
3932 );
3933 RAISE FND_API.G_EXC_ERROR;
3934 ELSIF x_errorcode in (65,66) THEN
3935 IF (l_debug = 1) THEN
3936 MDEBUG( 'Validate Seq for Unsch.'||to_char(x_errorcode));
3937 END IF;
3938 -- Get all the item information to store IN package var
3939 MTL_INV_VALIDATE_GRP.Get_Item_SKU(
3940 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC);
3941 ELSIF
3942 x_errorcode = 3 THEN
3943 -- Write INTO interface error TABLE
3944 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
3945 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
3946 , p_error_column_name => 'CYCLE_COUNT_HEADER_ID'
3947 , p_error_table_name => 'MTL_CYCLE_COUNT_HEADERS'
3948 , p_message_name => 'INV_CCEOI_MULT_MATCH_REQ'
3949 );
3950 RAISE FND_API.G_EXC_ERROR;
3951 ELSIF
3952 x_errorcode = 0 THEN
3953 IF (l_debug = 1) THEN
3954 mdebug('Process: In Validate_CountListSequence Derive ItemSKU');
3955 END IF;
3956 -- Get all the item information to store IN package var
3957 MTL_INV_VALIDATE_GRP.Get_Item_SKU(
3958 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC);
3959 END IF;
3960 --
3961 --
3962 -- END of API body
3963 -- Standard check of p_commit
3964 IF FND_API.to_Boolean(p_commit) THEN
3965 COMMIT;
3966 END IF;
3967 -- Standard call to get message count and if count is 1, get message info
3968 FND_MSG_PUB.Count_And_Get
3969 (p_count => x_msg_count
3970 , p_data => x_msg_data);
3971 EXCEPTION
3972 WHEN FND_API.G_EXC_ERROR THEN
3973 --
3974 --
3975 x_return_status := FND_API.G_RET_STS_ERROR;
3976 --
3977 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
3978 , p_data => x_msg_data);
3979 --
3980 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3981 --
3982 --
3983 x_errorcode := -1;
3984 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3985 --
3986 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
3987 , p_data => x_msg_data);
3988 --
3989 WHEN OTHERS THEN
3990 --
3991 --
3992 x_errorcode := -1;
3993 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3994 --
3995 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
3996 FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
3997 END IF;
3998 --
3999 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
4000 , p_data => x_msg_data);
4001 END;
4002 END;
4003 --
4004 -- validate item and sku information
4005 PROCEDURE Validate_ItemSKU(
4006 p_api_version IN NUMBER ,
4007 p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE,
4008 p_commit IN VARCHAR2 DEFAULT FND_API.G_FALSE,
4009 p_validation_level IN NUMBER DEFAULT FND_API.G_VALID_LEVEL_FULL,
4010 x_return_status OUT NOCOPY VARCHAR2 ,
4011 x_msg_count OUT NOCOPY NUMBER ,
4012 x_msg_data OUT NOCOPY VARCHAR2 ,
4013 x_errorcode OUT NOCOPY NUMBER ,
4014 p_cycle_count_header_id IN NUMBER ,
4015 p_inventory_item_rec IN MTL_CCEOI_VAR_PVT.Inv_Item_rec_type ,
4016 p_sku_rec IN MTL_CCEOI_VAR_PVT.Inv_SKU_Rec_Type ,
4017 p_subinventory IN VARCHAR2 ,
4018 p_locator_rec IN MTL_CCEOI_VAR_PVT.INV_LOCATOR_REC_TYPE ,
4019 p_organization_id IN number,
4020 p_simulate IN VARCHAR2 DEFAULT FND_API.G_FALSE )
4021 IS
4022 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4023 BEGIN
4024 -- Start OF comments
4025 -- API name : Validate_ItemSKU
4026 -- TYPE : Private
4027 -- Pre-reqs : None
4028 -- FUNCTION :
4029 -- Validates the item AND SKU information.
4030 -- Parameters:
4031 -- IN :
4032 -- p_api_version IN NUMBER (required)
4033 -- API Version of this procedure
4034 --
4035 -- p_init_msg_list IN VARCHAR2 (optional)
4036 -- DEFAULT = FND_API.G_FALSE,
4037 --
4038 -- p_commit IN VARCHAR2 (optional)
4039 -- DEFAULT = FND_API.G_FALSE
4040 --
4041 -- p_validation_level IN NUMBER (optional)
4042 -- DEFAULT = FND_API.G_VALID_LEVEL_FULL,
4043 --
4044 -- p_cycle_count_header_id IN NUMBER (required)
4045 -- Cycle COUNT header id
4046 --
4047 -- p_inventory_item_rec MTL_CCEOI_VAR_PVT.INV_ITEM_REC_TYPE (required)
4048 -- Item information with segements
4049 --
4050 -- p_sku_rec MTL_CCEOI_VAR_PVT.INV_SKU_REC_TYPE (required)
4051 -- Item SKU information
4052 --
4053 -- p_subinventory IN VARCHAR2 (required)
4054 -- Item Subinventory
4055 --
4056 -- p_locator_rec MTL_CCEOI_VAR_PVT.INV_LOCATOR_REC_TYPE (required)
4057 -- Item locator information
4058 --
4059 -- p_organization_id IN NUMBER (required)
4060 -- organization_id
4061 --
4062 -- OUT :
4063 -- X_return_status OUT NUMBER
4064 -- Result of all the operations
4065 --
4066 -- x_msg_count OUT NUMBER,
4067 --
4068 -- x_msg_data OUT VARCHAR2,
4069 --
4070 -- X_ErrorCode OUT NUMBER
4071 -- Version: Current Version 0.9
4072 -- Changed : Nothing
4073 -- No Previous Version 0.0
4074 -- Initial version 0.9
4075 -- Notes : Note text
4076 -- END OF comments
4077 DECLARE
4078 L_message_name VARCHAR2(100);
4079 L_table_name VARCHAR2(30);
4080 L_column_name VARCHAR2(32);
4081 L_counter integer := 0;
4082 L_P_inventory_item_id NUMBER ;
4083 L_P_locator_id NUMBER ;
4084 L_is_Unscheduled_Request boolean;
4085 --
4086 L_lot INV_Validate.LOT;
4087 L_org INV_Validate.ORG;
4088 L_item INV_Validate.ITEM;
4089 L_sub INV_Validate.SUB;
4090 L_serial INV_Validate.SERIAL;
4091 L_loc INV_Validate.LOCATOR;
4092 --
4093 --Begin changes 3904722
4094 l_ret_value NUMBER;
4095 l_to_serial VARCHAR2(30);
4096 l_msg_data VARCHAR2(2000);
4097 l_serial_quantity NUMBER;
4098 --End changes 3904722
4099 l_count NUMBER; --8300310
4100 CURSOR L_CCEntry_Csr(itemid IN NUMBER, lpnid IN NUMBER, subinv IN VARCHAR2,
4101 org IN NUMBER, header IN NUMBER, loc IN NUMBER, rev IN VARCHAR2,
4102 ser IN VARCHAR2, lot IN VARCHAR2, cost IN NUMBER)
4103 IS SELECT
4104 *
4105 FROM mtl_cycle_count_entries
4106 WHERE
4107 cycle_count_header_id = header
4108 AND organization_id = org
4109 AND inventory_item_id = itemid
4110 AND NVL(parent_lpn_id, -1) = NVL(lpnid, -1)
4111 AND NVL(cost_group_id, -1) = NVL(cost, -1)
4112 AND subinventory = subinv
4113 AND entry_status_code IN(1, 2, 3)
4114 AND(loc IS NULL OR
4115 locator_id = loc)
4116 AND(rev IS NULL OR
4117 revision = rev)
4118 AND(lot IS NULL OR
4119 lot_number = lot)
4120 AND(ser IS NULL OR
4121 serial_number =ser);
4122 --
4123 L_check_locator NUMBER;
4124 L_control_level NUMBER;
4125 --
4126 L_api_version CONSTANT NUMBER := 0.9;
4127 L_api_name CONSTANT VARCHAR2(30) := 'Validate_ItemSKU';
4128 BEGIN
4129 -- Standard start of API savepoint
4130 SAVEPOINT Validate_ItemSKU;
4131 --
4132 -- Standard Call to check for call compatibility
4133 IF NOT FND_API.Compatible_API_Call(l_api_version
4134 , p_api_version
4135 , l_api_name
4136 , G_PKG_NAME) THEN
4137 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4138 END IF;
4139 --
4140 -- Initialize message list if p_init_msg_list is set to true
4141 IF FND_API.to_Boolean(p_init_msg_list) THEN
4142 FND_MSG_PUB.initialize;
4143 END IF;
4144 --
4145 -- Initialisize API return status to access
4146 x_return_status := FND_API.G_RET_STS_SUCCESS;
4147 --
4148 -- API body
4149 IF (l_debug = 1) THEN
4150 mdebug('Process: In Validate_ItemSKU');
4151 END IF;
4152 --
4153 /* Validate API Implementation for Item validation
4154 This is implemented in called function */
4155 MTL_INV_VALIDATE_GRP.Validate_Item(
4156 p_api_version => 0.9,
4157 x_return_status => x_return_status,
4158 x_msg_count => x_msg_count,
4159 x_msg_data => x_msg_data,
4160 x_errorcode => x_errorcode,
4161 p_inventory_item_rec => p_inventory_item_rec,
4162 p_organization_id => p_organization_id,
4163 p_cycle_count_header_id => p_cycle_count_header_id);
4164
4165 IF (l_debug = 1) THEN
4166 MDEBUG( 'Validate_Item Return='||x_return_status);
4167 MDEBUG( 'Validate_Item Return x_errorcode='||x_errorcode);
4168 mdebug('Process: In Validate_ItemSKU Return='||x_return_status); --
4169 END IF;
4170 IF x_errorcode >0 THEN
4171 IF x_errorcode = 4 THEN
4172 L_message_name := 'INV_CCEOI_NO_ITEM';
4173 L_table_name := 'MTL_SYSTEM_ITEMS';
4174 L_column_name := 'INVENTORY_ITEM AND ITEM_SEGMENTS';
4175 ELSIF
4176 x_errorcode = 5 THEN
4177 L_message_name := 'INV_CCEOI_INVALID_ITEM';
4178 L_table_name := 'MTL_CYCLE_COUNT_ITEMS';
4179 L_column_name := 'INVENTORY_ITEM_ID';
4180 END IF;
4181
4182 -- Write INTO interface error TABLE
4183 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
4184 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
4185 , p_error_column_name => L_column_name
4186 , p_error_table_name => L_table_name
4187 , p_message_name => L_message_name
4188 );
4189 --
4190 RAISE FND_API.G_EXC_ERROR;
4191 ELSIF
4192 x_errorcode < 0 THEN
4193 -- Write INTO interface error TABLE
4194 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
4195 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
4196 , p_error_column_name => 'unexpected error'
4197 , p_error_table_name => 'unexpected error'
4198 , p_message_name => 'unexpected error'
4199 );
4200 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4201 END IF;
4202 --
4203 IF (l_debug = 1) THEN
4204 mdebug('Process: In Validate_ItemSKU call Subinv ');
4205 MDEBUG( 'Validate_Sub Inv');
4206 END IF;
4207 -- Validate Subinventory
4208 /* Validate API Implementation for Subinv validation
4209 This is introduced in called API */
4210 MTL_INV_VALIDATE_GRP.Validate_Subinv(
4211 p_api_version => 0.9,
4212 x_return_status => x_return_status,
4213 x_msg_count => x_msg_count,
4214 x_msg_data => x_msg_data,
4215 x_errorcode => x_errorcode,
4216 p_subinventory => p_subinventory,
4217 p_organization_id => p_organization_id,
4218 p_orientation_code =>
4219 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.ORIENTATION_CODE,
4220 p_cycle_count_header_id => p_cycle_count_header_id);
4221
4222 IF (l_debug = 1) THEN
4223 MDEBUG( 'Validate_Item Subinv Return='||x_return_status);
4224 END IF;
4225
4226 --
4227 IF x_errorcode >0 THEN
4228 IF x_errorcode = 7 THEN
4229 L_message_name := 'INV_CCEOI_INVALID_SUB';
4230 L_table_name := 'MTL_CC_SUBINVENTORIES';
4231 L_column_name := 'SUBINVENTORY';
4232 ELSIF
4233 x_errorcode = 6 THEN
4234 L_message_name := 'INV_CCEOI_NO_SUB';
4235 L_table_name := 'No TABLE';
4236 L_column_name := 'No column';
4237 ELSIF
4238 x_errorcode = 8 THEN
4239 L_message_name := 'INV_CCEOI_NON_QTY_TRKD_SUB';
4240 L_table_name := 'MTL_SECONDARY_INVENTORIES';
4241 L_column_name := 'QUANTITY_TRACKED';
4242 END IF;
4243 -- Write INTO interface error TABLE
4244 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
4245 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
4246 , p_error_column_name => L_column_name
4247 , p_error_table_name => L_table_name
4248 , p_message_name => L_message_name
4249 );
4250 --
4251 RAISE FND_API.G_EXC_ERROR;
4252 ELSIF
4253 x_errorcode < 0 THEN
4254 -- Write INTO interface error TABLE
4255 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
4256 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
4257 , p_error_column_name => 'unexpected error'
4258 , p_error_table_name => 'unexpected error'
4259 , p_message_name => 'unexpected error'
4260 );
4261 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4262 END IF;
4263 --
4264 -- IS item under locator control
4265 IF (l_debug = 1) THEN
4266 mdebug('Process: In Validate_ItemSKU call Locator Control');
4267 END IF;
4268 MTL_INV_VALIDATE_GRP.Locator_Control(
4269 p_api_version => 0.9,
4270 x_return_status => x_return_status,
4271 x_msg_count => x_msg_count,
4272 x_msg_data => x_msg_data,
4273 p_org_control => MTL_CCEOI_VAR_PVT.G_STOCK_LOCATOR_CONTROL_CODE,
4274 p_sub_control => MTL_CCEOI_VAR_PVT.G_SUB_LOCATOR_TYPE,
4275 p_item_control => MTL_CCEOI_VAR_PVT.G_SKU_REC.LOCATION_CONTROL_CODE,
4276 -- G_ITEM_LOCATOR_TYPE, -- XXX never set
4277 x_locator_control => L_check_locator,
4278 x_level => L_control_level
4279 );
4280 IF (l_debug = 1) THEN
4281 MDEBUG( 'Validate_Item Locator Control Return='||x_return_status);
4282 MDEBUG( 'Validate_Ctrl Rev : '||p_sku_rec.revision);
4283 MDEBUG( 'Validate_Ctrl Loc : '||to_char(p_locator_rec.locator_id));
4284 END IF;
4285 --
4286 IF (l_debug = 1) THEN
4287 mdebug('Process: In Validate_ItemSKU call Val_Ctrol ');
4288 END IF;
4289 -- Validate Control information
4290 MTL_INV_VALIDATE_GRP.Validate_Ctrol(
4291 p_api_version => 0.9,
4292 x_return_status => x_return_status,
4293 x_msg_count => x_msg_count,
4294 x_msg_data => x_msg_data,
4295 x_errorcode => x_errorcode,
4296 p_inventory_item_id => MTL_CCEOI_VAR_PVT.G_INVENTORY_ITEM_ID,
4297 p_organization_id => p_organization_id,
4298 p_locator_rec => p_locator_rec,
4299 p_lot_number => p_sku_rec.lot_number,
4300 p_revision => p_sku_rec.revision,
4301 p_serial_number => p_sku_rec.serial_number,
4302 p_locator_control => L_check_locator
4303 );
4304 IF (l_debug = 1) THEN
4305 MDEBUG( 'Validate_Item call Val_Ctrol Return='||x_return_status);
4306 mdebug('Process: In Validate_ItemSKU call Val_Ctrol Return='||x_return_status);
4307 END IF;
4308 --
4309 IF x_errorcode >0 THEN
4310 L_table_name := 'MTL_SYSTEM_ITEMS';
4311 IF x_errorcode = 9 THEN
4312 L_message_name := 'INV_CCEOI_NO_LOC';
4313 L_column_name := 'LOCATION_CONTROL_CODE';
4314 ELSIF x_errorcode = 11 THEN
4315 L_message_name := 'INV_CCEOI_NO_REV';
4316 L_column_name := 'REVISION_QTY_CONTROL_CODE';
4317 ELSIF x_errorcode = 13 THEN
4318 L_message_name := 'INV_CCEOI_NO_LOT';
4319 L_column_name := 'LOT_CONTROL_CODE';
4320 ELSIF x_errorcode = 15 THEN
4321 L_message_name := 'INV_CCEOI_NO_SERIAL';
4322 L_column_name := 'SERIAL_NUMBER_CONTROL_CODE';
4323 END IF;
4324 -- Write INTO interface error TABLE
4325 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
4326 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
4327 , p_error_column_name => L_column_name
4328 , p_error_table_name => L_table_name
4329 , p_message_name => L_message_name
4330 );
4331 --
4332 RAISE FND_API.G_EXC_ERROR;
4333 ELSIF
4334 x_errorcode < 0 THEN
4335 -- Write INTO interface error TABLE
4336 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
4337 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
4338 , p_error_column_name => 'unexpected error'
4339 , p_error_table_name => 'unexpected error'
4340 , p_message_name => 'unexpected error'
4341 );
4342 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4343 END IF;
4344 --
4345
4346 -- XXX big mess here (locator check should be based on a control level
4347 -- derived based on control code of org/sub/item not just item )
4348 -- we do not check restricted locator lists
4349 --
4350 IF (l_debug = 1) THEN
4351 MDEBUG( 'Validate Loc Chk: '||to_char(MTL_CCEOI_VAR_PVT.G_SKU_REC.LOCATION_CONTROL_CODE));
4352 END IF;
4353 IF L_check_locator IN(2, 3) THEN
4354 IF (l_debug = 1) THEN
4355 mdebug('Process: In Validate_ItemSKU call Val_Locator');
4356 MDEBUG( 'Validate Loc : '||to_char(p_locator_rec.locator_id));
4357 END IF;
4358 -- Validate Locator
4359 /* Validate API Implementation done in called procedure
4360 since it has multiple call for Locator validation */
4361
4362 MTL_INV_VALIDATE_GRP.Validate_Locator(
4363 p_api_version => 0.9,
4364 x_return_status => x_return_status,
4365 x_msg_count => x_msg_count,
4366 x_msg_data => x_msg_data,
4367 x_errorcode => x_errorcode,
4368 p_locator_rec => p_locator_rec,
4369 p_organization_id => p_organization_id,
4370 p_subinventory => p_subinventory,
4371 p_inventory_item_id => p_inventory_item_rec.inventory_item_id,
4372 p_locator_control => L_check_locator,
4373 p_control_level => L_control_level,
4374 p_restrict_control =>
4375 MTL_CCEOI_VAR_PVT.G_SKU_REC.RESTRICT_LOCATORS_CODE,
4376 p_simulate => p_simulate);
4377 IF (l_debug = 1) THEN
4378 mdebug('Process: In Validate_ItemSKU call Val_Locator Return='||x_return_status);
4379 END IF;
4380 --
4381 IF x_errorcode >0 THEN
4382 IF x_errorcode = 10 THEN
4383 L_table_name := 'MTL_ITEM_LOCATIONS_KFV';
4384 L_message_name := 'INV_CCEOI_INVALID_LOC';
4385 L_column_name := 'INVENTORY_LOCATION_ID';
4386 ELSIF
4387 x_errorcode = 47 THEN
4388 L_table_name := 'MTL_SECONDARY_LOCATORS';
4389 L_message_name := 'INV_CCEOI_LOC_NOT_IN_LIST';
4390 L_column_name := 'SECONDARY_LOCATOR';
4391 END IF;
4392 -- Write INTO interface error TABLE
4393 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
4394 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
4395 , p_error_column_name => L_column_name
4396 , p_error_table_name => L_table_name
4397 , p_message_name => L_message_name
4398 );
4399 RAISE FND_API.G_EXC_ERROR;
4400 ELSIF
4401 x_errorcode < 0 THEN
4402 --
4403 -- Write INTO interface error TABLE
4404 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
4405 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
4406 , p_error_column_name => 'unexpected error'
4407 , p_error_table_name => 'unexpected error'
4408 , p_message_name => 'unexpected error'
4409 );
4410 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4411 END IF;
4412 -- location contorl code is either no locator control, determined at
4413 -- subinv level or determined at item level
4414 ELSE
4415 MTL_CCEOI_VAR_PVT.G_LOCATOR_ID := NULL; -- XXX not sure about that
4416 END IF;
4417 --
4418 -- IS item under revision control
4419 IF MTL_CCEOI_VAR_PVT.G_SKU_REC.REVISION_QTY_CONTROL_CODE = 2 THEN
4420 -- Validate Revision
4421 IF (l_debug = 1) THEN
4422 mdebug('Process: In Validate_ItemSKU call Val_revision ');
4423 END IF;
4424 /* Validate API Implementation for Revision validation */
4425 --
4426 l_org.organization_id := p_organization_id;
4427 l_item.inventory_item_id := MTL_CCEOI_VAR_PVT.G_INVENTORY_ITEM_ID;
4428 --
4429 IF p_sku_rec.revision is null then
4430 x_errorcode := 12 ;
4431 ELSIF INV_Validate.Revision(p_sku_rec.revision,
4432 L_org,
4433 L_item
4434 ) = INV_Validate.T then
4435 MTL_CCEOI_VAR_PVT.G_SKU_REC.REVISION := p_sku_rec.revision;
4436 x_errorcode := 0;
4437 ELSE
4438 x_errorcode := 12;
4439 END IF;
4440 IF (l_debug = 1) THEN
4441 mdebug('Process: In Validate_ItemSKU call Val_revision Return='||x_return_status);
4442 END IF;
4443 --
4444 IF x_errorcode >0 THEN
4445 L_table_name := 'MTL_ITEM_REVISIONS';
4446 L_column_name := 'REVISION';
4447 IF x_errorcode = 11 THEN
4448 L_message_name := 'INV_CCEOI_NO_REV';
4449 ELSIF x_errorcode = 12 THEN
4450 L_message_name := 'INV_CCEOI_LOC_INVALID_REV';
4451 END IF;
4452 -- Write INTO interface error TABLE
4453 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
4454 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
4455 , p_error_column_name => L_column_name
4456 , p_error_table_name => L_table_name
4457 , p_message_name => L_message_name
4458 );
4459 RAISE FND_API.G_EXC_ERROR;
4460 ELSIF
4461 x_errorcode < 0 THEN
4462 --
4463 -- Write INTO interface error TABLE
4464 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
4465 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
4466 , p_error_column_name => 'unexpected error'
4467 , p_error_table_name => 'unexpected error'
4468 , p_message_name => 'unexpected error'
4469 );
4470 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4471 END IF;
4472 END IF;
4473 --
4474 -- IS the item under lot control
4475 IF MTL_CCEOI_VAR_PVT.G_SKU_REC.LOT_CONTROL_CODE = 2 THEN
4476 IF (l_debug = 1) THEN
4477 mdebug('Process: In Validate_ItemSKU call Val_Lot');
4478 MDEBUG( 'Process: In Validate_ItemSKU call Val_Lot');
4479 END IF;
4480 /* Validate API Implementation for lot validation */
4481 --
4482 l_org.organization_id := p_organization_id;
4483 l_sub.secondary_inventory_name := p_subinventory;
4484 l_item.inventory_item_id := MTL_CCEOI_VAR_PVT.G_INVENTORY_ITEM_ID;
4485 l_loc.inventory_location_id := MTL_CCEOI_VAR_PVT.G_LOCATOR_ID;
4486 l_lot.lot_number := p_sku_rec.lot_number ;
4487 --
4488 IF p_sku_rec.lot_number is null then
4489 x_errorcode := 13 ;
4490 /* Bug 4735473-Calling the Lot_Number api passing only lot, org and item to
4491 make the behaviour in sync with that on the desktop.
4492 ELSIF INV_Validate.Lot_Number(L_lot,
4493 L_org,
4494 L_item,
4495 L_sub,
4496 L_loc,
4497 p_sku_rec.revision
4498 ) = INV_Validate.T then */
4499
4500 ELSIF INV_Validate.Lot_Number(L_lot,
4501 L_org,
4502 L_item
4503 ) = INV_Validate.T THEN
4504 /* End of fix for Bug 4735473 */
4505
4506 MTL_CCEOI_VAR_PVT.G_SKU_REC.Lot_Number := l_lot.lot_number;
4507 MTL_CCEOI_VAR_PVT.G_SKU_REC.expiration_date := l_lot.expiration_date;
4508
4509 x_errorcode := 0;
4510 ELSE
4511 x_errorcode := 14;
4512 END IF;
4513 -- Validate Lot
4514 IF (l_debug = 1) THEN
4515 MDEBUG( 'Process: In Validate_ItemSKU call Val_Lot Stat'||x_return_status||' - '||to_char(x_errorcode));
4516 mdebug('Process: In Validate_ItemSKU call Val_Lot Return='||x_return_status);
4517 END IF;
4518 --
4519 IF x_errorcode >0 THEN
4520 IF (l_debug = 1) THEN
4521 MDEBUG( 'Process: In Validate_ItemSKU call Val_Lot Error > 0');
4522 END IF;
4523 L_table_name := 'MTL_LOT_NUMBERS';
4524 L_column_name := 'LOT_NUMBER';
4525 IF x_errorcode = 13 THEN
4526 L_message_name := 'INV_CCEOI_NO_LOT';
4527 ELSIF
4528 x_errorcode = 14 THEN
4529 L_message_name := 'INV_CCEOI_INVALID_LOT'; --changes 3904722
4530 END IF;
4531 -- Write INTO interface error TABLE
4532 IF (l_debug = 1) THEN
4533 MDEBUG( 'Process: In Validate_ItemSKU call Val_Lot Msg '||L_message_name);
4534 END IF;
4535 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
4536 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
4537 , p_error_column_name => L_column_name
4538 , p_error_table_name => L_table_name
4539 , p_message_name => L_message_name
4540 );
4541 RAISE FND_API.G_EXC_ERROR;
4542 ELSIF
4543 x_errorcode < 0 THEN
4544 --
4545 IF (l_debug = 1) THEN
4546 MDEBUG( 'Process: In Validate_ItemSKU call Val_Lot Error < 0');
4547 END IF;
4548 -- Write INTO interface error TABLE
4549 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
4550 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
4551 , p_error_column_name => 'unexpected error'
4552 , p_error_table_name => 'unexpected error'
4553 , p_message_name => 'unexpected error'
4554 );
4555 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4556 END IF;
4557 END IF;
4558 --
4559 -- IS the item under serial control
4560 IF (l_debug = 1) THEN
4561 MDEBUG( 'Before call Validate_Serial-1');
4562 END IF;
4563 IF MTL_CCEOI_VAR_PVT.G_SKU_REC.SERIAL_NUMBER_CONTROL_CODE IN (2,5) THEN
4564 IF (l_debug = 1) THEN
4565 MDEBUG( 'Before call Validate_Serial-2');
4566 END IF;
4567 --Begin changes 3904722
4568 SELECT COUNT_QUANTITY INTO l_serial_quantity
4569 FROM MTL_CC_ENTRIES_INTERFACE
4570 WHERE CC_ENTRY_INTERFACE_ID = MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID;
4571 --End changes 3904722
4572 -- Validate Serial
4573 /* Validate API Implementation for Serial validation */
4574 l_org.organization_id := p_organization_id;
4575 l_sub.secondary_inventory_name := p_subinventory;
4576 l_serial.serial_number := p_sku_rec.serial_number ;
4577 l_item.inventory_item_id := MTL_CCEOI_VAR_PVT.G_INVENTORY_ITEM_ID;
4578 l_loc.inventory_location_id := MTL_CCEOI_VAR_PVT.G_LOCATOR_ID;
4579 l_lot.lot_number := p_sku_rec.lot_number ;
4580 l_item.SERIAL_NUMBER_CONTROL_CODE := MTL_CCEOI_VAR_PVT.G_SKU_REC.SERIAL_NUMBER_CONTROL_CODE; --9113242
4581 --
4582 IF (MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.SERIAL_COUNT_OPTION = 3) THEN
4583 x_errorcode := 102;
4584 ELSIF (MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.SERIAL_COUNT_OPTION = 1) THEN
4585 x_errorcode := 103;
4586 ELSIF p_sku_rec.serial_number is null then
4587 x_errorcode := 15 ;
4588 ELSIF INV_Validate.validate_serial(l_serial,
4589 L_org,
4590 L_item,
4591 L_sub,
4592 L_lot,
4593 L_loc,
4594 p_sku_rec.revision
4595 ) = INV_Validate.T then
4596 -- needs to be checked whether we should store or not
4597 MTL_CCEOI_VAR_PVT.G_SKU_REC.SERIAL_NUMBER := l_serial.serial_number;
4598 x_errorcode := 0;
4599 --Begin changes 3904722
4600 ELSIF MTL_CCEOI_VAR_PVT.G_SKU_REC.SERIAL_NUMBER_CONTROL_CODE = 5 AND
4601 MTL_CCEOI_VAR_PVT.G_SKU_REC.SERIAL_NUMBER IS NULL AND
4602 l_serial_quantity = 1 THEN
4603 l_ret_value := inv_serial_number_pub.validate_serials(
4604 p_org_id => p_organization_id
4605 , p_item_id => p_inventory_item_rec.inventory_item_id
4606 , p_qty => l_serial_quantity
4607 , p_rev => p_sku_rec.revision
4608 , p_lot => p_sku_rec.lot_number
4609 , p_start_ser => p_sku_rec.serial_number
4610 , p_trx_src_id => 9
4611 , p_trx_action_id => 4
4612 , p_subinventory_code => p_subinventory
4613 , p_locator_id => MTL_CCEOI_VAR_PVT.G_LOCATOR_ID
4614 , p_issue_receipt => 'R'
4615 , x_end_ser => l_to_serial
4616 , x_proc_msg => l_msg_data);
4617 IF l_ret_value = 1 THEN
4618 x_errorcode := 16;
4619 ELSE
4620 MTL_CCEOI_VAR_PVT.G_SKU_REC.SERIAL_NUMBER := l_to_serial;
4621 x_errorcode := 0;
4622 END IF;
4623 ELSIF MTL_CCEOI_VAR_PVT.G_SKU_REC.SERIAL_NUMBER_CONTROL_CODE in (2,5) THEN
4624 x_errorcode := 16;
4625 END IF;
4626 --End changes 3904722
4627 IF (l_debug = 1) THEN
4628 MDEBUG( 'After Serial Validation Cd-Stat '||to_char(x_errorcode)||x_return_status);
4629 END IF;
4630 --
4631 IF x_errorcode >0 THEN
4632 L_table_name := 'MTL_SERIAL_NUMBERS';
4633 L_column_name := 'SERIAL_NUMBER';
4634 IF x_errorcode = 15 THEN
4635 L_message_name := 'INV_CCEOI_NO_SERIAL';
4636 ELSIF x_errorcode = 16 THEN
4637 L_message_name := 'INV_CCEOI_INVALID_SERIAL';
4638 ELSIF x_errorcode = 102 THEN
4639 L_message_name := 'INV_CCEOI_MULT_COUNT_SERIAL';
4640 ELSIF x_errorcode = 103 THEN
4641 L_message_name := 'INV_CCEOI_SERIAL_NOT_ALLOWED';
4642 END IF;
4643 --
4644 FND_MESSAGE.SET_NAME('INV',L_message_name);
4645 FND_MSG_PUB.Add;
4646 -- Write INTO interface error TABLE
4647 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
4648 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
4649 , p_error_column_name => L_column_name
4650 , p_error_table_name => L_table_name
4651 , p_message_name => L_message_name
4652 );
4653 RAISE FND_API.G_EXC_ERROR;
4654 ELSIF
4655 x_errorcode < 0 THEN
4656 --
4657 -- Write INTO interface error TABLE
4658 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
4659 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
4660 , p_error_column_name => 'unexpected error'
4661 , p_error_table_name => 'unexpected error'
4662 , p_message_name => 'unexpected error'
4663 );
4664 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4665 END IF;
4666 IF (l_debug = 1) THEN
4667 MDEBUG( 'After call Validate_Serial Error Routine');
4668 END IF;
4669 END IF;
4670
4671 -- deduce whether this is a new unscheduled count request or not
4672 -- by knowing the fact that validate_countlistseq would find this
4673 -- record already
4674 l_is_Unscheduled_Request := FALSE;
4675 if MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.CYCLE_COUNT_ENTRY_ID is null then
4676 l_is_Unscheduled_Request := TRUE;
4677 end if;
4678 --
4679
4680 -- Bug : 8300310 Start
4681 SELECT COUNT(1)
4682 INTO l_count
4683 FROM MTL_CYCLE_COUNT_ENTRIES
4684 WHERE organization_id = p_organization_id
4685 AND subinventory = p_subinventory
4686 AND locator_id = MTL_CCEOI_VAR_PVT.G_LOCATOR_ID
4687 AND inventory_item_id = p_inventory_item_rec.inventory_item_id
4688 AND NVL(parent_lpn_id,-1) = NVL(MTL_CCEOI_VAR_PVT.G_LPN_ID,-1)
4689 AND NVL(lot_number, '@') = NVL(p_sku_rec.lot_number, '@')
4690 AND NVL(revision, '@') = NVL(p_sku_rec.revision, '@')
4691 AND NVL(serial_number, '@') = NVL(p_sku_rec.serial_number, '@')
4692 AND entry_status_code IN (1, 3)
4693 AND cycle_count_header_id = MTL_CCEOI_VAR_PVT.G_CC_HEADER_ID;
4694
4695 IF (l_debug = 1) THEN
4696 MDEBUG('l_count : '|| l_count);
4697 END IF;
4698
4699 IF l_count = 1 THEN
4700 l_is_Unscheduled_Request := FALSE;
4701 mdebug('row exists in mcce, l_in_cc_entries returns true');
4702 END IF;
4703
4704 -- Bug : 8300310 End
4705 --
4706
4707 -- IS there an OPEN request
4708
4709 IF (l_debug = 1) THEN
4710 MDEBUG( 'item : '||to_char(MTL_CCEOI_VAR_PVT.G_INVENTORY_ITEM_ID));
4711 MDEBUG( 'lpnid: '||to_char(MTL_CCEOI_VAR_PVT.G_LPN_ID));
4712 MDEBUG( 'Subinv : '||p_subinventory);
4713 MDEBUG( 'Org :'||to_char(p_organization_id));
4714 MDEBUG( 'Header :'||to_char(p_cycle_count_header_id));
4715 MDEBUG( 'Locator :'||to_char(MTL_CCEOI_VAR_PVT.G_LOCATOR_ID));
4716 MDEBUG( 'Rev :'||p_sku_rec.revision);
4717 MDEBUG( 'Serial :'||p_sku_rec.serial_number);
4718 MDEBUG( 'Lot :'||p_sku_rec.lot_number);
4719 MDEBUG( 'costid: '||to_char(MTL_CCEOI_VAR_PVT.G_COST_GROUP_ID));
4720 END IF;
4721 L_P_locator_id := MTL_CCEOI_VAR_PVT.G_LOCATOR_ID;
4722 L_P_inventory_item_id := MTL_CCEOI_VAR_PVT.G_INVENTORY_ITEM_ID;
4723 MTL_CCEOI_VAR_PVT.G_OPEN_REQUEST := FALSE;
4724 FOR c_rec IN L_CCEntry_Csr(
4725 L_P_inventory_item_id, MTL_CCEOI_VAR_PVT.G_LPN_ID,
4726 p_subinventory, p_organization_id, p_cycle_count_header_id,
4727 L_P_locator_id, p_sku_rec.revision,
4728 p_sku_rec.serial_number, p_sku_rec.lot_number, MTL_CCEOI_VAR_PVT.G_COST_GROUP_ID) LOOP
4729 --
4730 IF (l_debug = 1) THEN
4731 MDEBUG( 'Process: In Validate_ItemSKU call-1 Open Request');
4732 END IF;
4733 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC := c_rec;
4734 MTL_CCEOI_VAR_PVT.G_OPEN_REQUEST := TRUE;
4735 L_counter := L_counter + 1;
4736 IF (l_debug = 1) THEN
4737 MDEBUG( 'Process: In Validate_ItemSKU call-2 Open Request');
4738 mdebug('Process: In Validate_ItemSKU call Open Request');
4739 END IF;
4740 --
4741 END LOOP;
4742 IF (l_debug = 1) THEN
4743 mdebug(' l_counter: ' || to_char(l_counter));
4744 MDEBUG( 'Process: In Validate_ItemSKU call-3 ');
4745 END IF;
4746 --
4747 IF L_counter < 1 AND MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.UNSCHEDULED_COUNT_ENTRY=2 THEN
4748 IF (l_debug = 1) THEN
4749 MDEBUG('Process: In Validate_ItemSKU Unsched not Allowed');
4750 END IF;
4751 x_errorcode := 48;
4752 FND_MESSAGE.SET_NAME('INV', 'INV_CCEOI_NO_CCENTRY');
4753 FND_MSG_PUB.Add;
4754 -- Write INTO interface error TABLE
4755 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
4756 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
4757 , p_error_column_name => '*'
4758 , p_error_table_name => 'MTL_CYCLE_COUNT_ENTRIES'
4759 , p_message_name => 'INV_CCEOI_NO_CCENTRY'
4760 );
4761 RAISE FND_API.G_EXC_ERROR;
4762 ELSIF
4763 L_counter > 1 OR (L_counter = 1 AND l_is_Unscheduled_Request) THEN
4764 -- XXX it is impossible to have multiple open
4765 -- requests existing for the same item/location
4766 -- it feels that we should have checked presense of request
4767 -- with a different count list sequence in case of 1 count (err=27)
4768 x_errorcode := 49;
4769
4770 IF (l_debug = 1) THEN
4771 MDEBUG( 'Process: In Validate_ItemSKU call-4 ');
4772 END IF;
4773 FND_MESSAGE.SET_NAME('INV', 'INV_CCEOI_MULT_REQUESTS');
4774 FND_MSG_PUB.Add;
4775 -- Write INTO interface error TABLE
4776 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
4777 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
4778 , p_error_column_name => '*'
4779 , p_error_table_name => 'MTL_CYCLE_COUNT_ENTRIES'
4780 , p_message_name => 'INV_CCEOI_MULT_REQUESTS'
4781 );
4782 RAISE FND_API.G_EXC_ERROR;
4783 END IF;
4784 --
4785 IF (l_debug = 1) THEN
4786 MDEBUG( 'Process: In Validate_ItemSKU call-5 ');
4787 END IF;
4788 -- END of API body
4789 -- Standard check of p_commit
4790 IF FND_API.to_Boolean(p_commit) THEN
4791 COMMIT;
4792 END IF;
4793 IF (l_debug = 1) THEN
4794 MDEBUG( 'Process: In Validate_ItemSKU call-6 ');
4795 END IF;
4796 -- Standard call to get message count and if count is 1, get message info
4797 FND_MSG_PUB.Count_And_Get
4798 (p_count => x_msg_count
4799 , p_data => x_msg_data);
4800 IF (l_debug = 1) THEN
4801 MDEBUG( 'Process: In Validate_ItemSKU call-7 ');
4802 END IF;
4803 EXCEPTION
4804 WHEN FND_API.G_EXC_ERROR THEN
4805 --
4806 x_return_status := FND_API.G_RET_STS_ERROR;
4807 --
4808 IF (l_debug = 1) THEN
4809 MDEBUG( 'ItemSKU-Error');
4810 END IF;
4811 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
4812 , p_data => x_msg_data);
4813 --
4814 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4815 --
4816 x_errorcode := -1;
4817 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4818 IF (l_debug = 1) THEN
4819 MDEBUG( 'ItemSKU-Unexp Error');
4820 END IF;
4821 --
4822 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
4823 , p_data => x_msg_data);
4824 --
4825 WHEN OTHERS THEN
4826 --
4827 x_errorcode := -1;
4828 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4829 IF (l_debug = 1) THEN
4830 MDEBUG( 'ItemSKU-Others Error');
4831 END IF;
4832 --
4833 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
4834 FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
4835 END IF;
4836 --
4837 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
4838 , p_data => x_msg_data);
4839 END;
4840 END;
4841 --
4842 -- Validate the UOM and quantity information
4843 PROCEDURE Validate_UOMQuantity(
4844 p_api_version IN NUMBER ,
4845 p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE,
4846 p_commit IN VARCHAR2 DEFAULT FND_API.G_FALSE,
4847 p_validation_level IN NUMBER DEFAULT FND_API.G_VALID_LEVEL_FULL,
4848 x_return_status OUT NOCOPY VARCHAR2 ,
4849 x_msg_count OUT NOCOPY NUMBER ,
4850 x_msg_data OUT NOCOPY VARCHAR2 ,
4851 x_errorcode OUT NOCOPY NUMBER ,
4852 p_primary_uom_quantity IN NUMBER DEFAULT NULL,
4853 p_count_uom IN VARCHAR2 DEFAULT NULL,
4854 p_count_unit_of_measure IN VARCHAR2 DEFAULT NULL,
4855 p_organization_id IN NUMBER ,
4856 p_lpn_id IN NUMBER DEFAULT NULL,
4857 p_inventory_item_id IN NUMBER ,
4858 p_count_quantity IN NUMBER ,
4859 p_serial_number IN VARCHAR2 DEFAULT NULL,
4860 p_subinventory IN VARCHAR2 ,
4861 p_revision IN VARCHAR2 DEFAULT NULL,
4862 p_lot_number IN VARCHAR2 ,
4863 p_system_quantity IN NUMBER,
4864 p_secondary_system_quantity IN NUMBER -- INVCONV
4865 )
4866 IS
4867 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4868 BEGIN
4869 -- Start OF comments
4870 -- API name : Validate_UOMQuantity
4871 -- TYPE : Private
4872 -- Pre-reqs : G_PRIMARY_UOM_CODE, G_CYCLE_COUNT_ENTRY_REC.COUNT_TYPE_CODE
4873 -- FUNCTION :
4874 -- Parameters:
4875 -- IN :
4876 -- p_api_version IN NUMBER (required)
4877 -- API Version of this procedure
4878 --
4879 -- p_init_msg_list IN VARCHAR2 (optional)
4880 -- DEFAULT = FND_API.G_FALSE,
4881 --
4882 -- p_commit IN VARCHAR2 (optional)
4883 -- DEFAULT = FND_API.G_FALSE
4884 --
4885 -- p_validation_level IN NUMBER (optional)
4886 -- DEFAULT = FND_API.G_VALID_LEVEL_FULL,
4887 --
4888 -- p_primary_uom_quantity IN NUMBER (required - default)
4889 -- default NULL
4890 -- Quantity within the primary unit OF measure OF the item
4891 --
4892 -- p_count_uom IN VARCHAR2 (required - default)
4893 -- default = NULL
4894 -- Unit OF measure OF the current cycle COUNT entry
4895 --
4896 -- p_count_unit_of_measure IN VARCHAR2 (optional - defaulted)
4897 -- default = NULL
4898 -- unit OF measure name OF the current COUNT
4899 --
4900 -- p_organization_id IN NUMBER (required)
4901 -- ID OF the organization
4902 --
4903 -- p_inventory_item_id IN NUMBER (required)
4904 -- ID OF the current inventory item
4905 --
4906 -- p_count_quantity IN NUMBER (required)
4907 -- COUNT quantity
4908 --
4909 -- p_serial_number IN NUMBER (required - defaulted)
4910 -- default = NULL
4911 -- Serial NUMBER, IF the item IS under serial control
4912 --
4913 -- p_subinventory in number (required)
4914 -- subinventory of the item
4915 --
4916 -- p_revision in varchar2 (required- defaulted)
4917 -- default = null
4918 -- revision of the item
4919 --
4920 -- p_lot_number in varchar2 (required- defaulted)
4921 -- default = null
4922 -- lot number
4923 --
4924 -- p_system_quantity in number (required- defaulted)
4925 -- default = null
4926 --
4927 -- OUT :
4928 -- X_return_status OUT NUMBER
4929 -- Result of all the operations
4930 --
4931 --
4932 -- x_msg_count OUT NUMBER,
4933 --
4934 -- x_msg_data OUT VARCHAR2,
4935 --
4936 -- X_ErrorCode OUT NUMBER
4937 -- Version: Current Version 0.9
4938 -- Changed : Nothing
4939 -- No Previous Version 0.0
4940 -- Initial version 0.9
4941 -- Notes :
4942 -- this function validates presense of count quantity and uom info
4943 -- it also computes adjustment quantity, adjustment amount, item cost,
4944 -- and adjustment variance percentage
4945 -- Sets: G_UOM_CODE (count unit of measure), G_COUNT_QUANTITY (in count UOM)
4946 -- G_ADJUSTMENT_QUANTITY, G_ADJUSTMENT_AMOUNT, G_ITEM_COST,
4947 -- G_ADJ_VARIANCE_PERCENTAGE, G_SYSTEM_QUANTITY
4948 -- END OF comments
4949 DECLARE
4950 L_table_name VARCHAR2(100);
4951 L_column_name VARCHAR2(100);
4952 L_message_name VARCHAR2(30);
4953 --
4954 L_api_version CONSTANT NUMBER := 0.9;
4955 L_api_name CONSTANT VARCHAR2(30) := 'Validate_UOMQuantity';
4956 BEGIN
4957 -- Standard start of API savepoint
4958 SAVEPOINT Validate_UOMQuantity;
4959 --
4960 -- Standard Call to check for call compatibility
4961 IF NOT FND_API.Compatible_API_Call(l_api_version
4962 , p_api_version
4963 , l_api_name
4964 , G_PKG_NAME) THEN
4965 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4966 END IF;
4967 --
4968 -- Initialize message list if p_init_msg_list is set to true
4969 IF FND_API.to_Boolean(p_init_msg_list) THEN
4970 FND_MSG_PUB.initialize;
4971 END IF;
4972 --
4973 -- Initialisize API return status to access
4974 x_return_status := FND_API.G_RET_STS_SUCCESS;
4975 x_errorcode := 0;
4976 --
4977 -- API body
4978 --
4979 IF (l_debug = 1) THEN
4980 MDEBUG( 'Validate_UOMQuantity call. count_type_code ='||nvl(to_char(MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.COUNT_TYPE_CODE), 'NULL'));
4981 END IF;
4982 --
4983 -- comment released by suresh for testing
4984
4985 -- count type code 4 means dummy count - ignore it
4986 IF MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.COUNT_TYPE_CODE = 4 THEN
4987 -- todo: reset count and uom globals to null ? (put 0's ?)
4988 MTL_CCEOI_VAR_PVT.G_UOM_CODE := NULL;
4989 MTL_CCEOI_VAR_PVT.G_COUNT_QUANTITY := NULL;
4990 MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY := NULL;
4991 MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY := NULL;
4992 MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_AMOUNT := NULL;
4993 MTL_CCEOI_VAR_PVT.G_ADJ_VARIANCE_PERCENTAGE := NULL;
4994 MTL_CCEOI_VAR_PVT.G_ITEM_COST := NULL;
4995
4996 -- if scheduled(1), unscheduled(2), control(3) count derive UOM/Qty
4997 ELSIF MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.COUNT_TYPE_CODE
4998 IN (1, 2, 3)
4999 OR
5000 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.COUNT_TYPE_CODE IS NULL
5001 THEN
5002
5003 IF (l_debug = 1) THEN
5004 mdebug('Process: In Validate_UOMQuantity call Validate_PrimaryUOMQty');
5005 END IF;
5006 MTL_INV_VALIDATE_GRP.Validate_PrimaryUomQuantity
5007 (p_api_version => 0.9,
5008 x_return_status => x_return_status,
5009 x_msg_count => x_msg_count,
5010 x_msg_data => x_msg_data,
5011 x_errorcode => x_errorcode,
5012 p_primary_uom_quantity => p_primary_uom_quantity,
5013 p_primary_uom_code => MTL_CCEOI_VAR_PVT.G_PRIMARY_UOM_CODE);
5014
5015 IF (l_debug = 1) THEN
5016 mdebug('Process: In Validate_UOMQuantity call Validate_PrimaryUOMQty Return='||x_return_status);
5017 mdebug('Errorcode :'||to_char(x_errorcode));
5018 END IF;
5019
5020 IF x_errorcode < 0 THEN
5021
5022 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5023 p_cc_entry_interface_id =>
5024 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5025 , p_error_column_name => 'unexpected error'
5026 , p_error_table_name => 'unexpected error'
5027 , p_message_name => 'unexpected error');
5028 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5029
5030 ELSIF x_errorcode = 22 THEN
5031 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5032 p_cc_entry_interface_id =>
5033 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5034 , p_error_column_name => 'COUNT_QUANTITY'
5035 , p_error_table_name => 'MTL_CYCLE_COUNT_ENTRIES'
5036 , p_message_name => 'INV_CCEOI_NEG_QTY');
5037 RAISE FND_API.G_EXC_ERROR;
5038
5039 ELSIF x_errorcode = 60 THEN
5040 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5041 p_cc_entry_interface_id =>
5042 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5043 , p_error_column_name => 'COUNT_QUANTITY'
5044 , p_error_table_name => 'MTL_CYCLE_COUNT_ENTRIES'
5045 , p_message_name => 'INV_SERIAL_QTY_MUST_BE_1');
5046 RAISE FND_API.G_EXC_ERROR;
5047
5048 ELSIF x_errorcode = 61 THEN
5049 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5050 p_cc_entry_interface_id =>
5051 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5052 , p_error_column_name => 'COUNT_QUANTITY'
5053 , p_error_table_name => 'MTL_CYCLE_COUNT_ENTRIES'
5054 , p_message_name => 'INV_GREATER_EQUAL_ZERO');
5055 RAISE FND_API.G_EXC_ERROR;
5056
5057 --
5058 -- primary uom quantity IS NOT populated, THEN validate COUNT uom
5059 ELSIF x_errorcode = 19 THEN
5060 IF (l_debug = 1) THEN
5061 mdebug('Process: In Validate_UOMQuantity call Validate_CountUOM: ' || p_count_uom);
5062 END IF;
5063
5064 MTL_INV_VALIDATE_GRP.Validate_CountUOM(p_api_version => 0.9
5065 , x_msg_count => x_msg_count
5066 , x_msg_data => x_msg_data
5067 , x_return_status => x_return_status
5068 , x_errorcode => x_errorcode
5069 , p_count_uom => p_count_uom
5070 , p_count_unit_of_measure => p_count_unit_of_measure
5071 , p_organization_id => p_organization_id
5072 , p_inventory_item_id => p_inventory_item_id );
5073
5074 IF (l_debug = 1) THEN
5075 MDEBUG( 'After Validate CntUOM Stat '||to_char(x_errorcode)||' - '||x_return_status);
5076 END IF;
5077
5078 IF x_errorcode = 19 THEN
5079
5080 -- Write INTO interface error TABLE
5081 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5082 p_cc_entry_interface_id =>
5083 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5084 , p_error_column_name =>
5085 'UOM_CODE/UNIT_OF_MEASURE'
5086 , p_error_table_name => 'MTL_ITEM_UOMS_VIEW'
5087 , p_message_name => 'INV_CCEOI_NO_UOM'
5088 );
5089 RAISE FND_API.G_EXC_ERROR;
5090
5091 ELSIF x_errorcode = 20 THEN
5092 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5093 p_cc_entry_interface_id =>
5094 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5095 , p_error_column_name =>
5096 'UOM_CODE/UNIT_OF_MEASURE'
5097 , p_error_table_name => 'MTL_ITEM_UOMS_VIEW'
5098 , p_message_name => 'INV_CCEOI_INVALID_UOM'
5099 );
5100 RAISE FND_API.G_EXC_ERROR;
5101
5102 ELSIF x_errorcode < 0 THEN
5103
5104 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5105 p_cc_entry_interface_id =>
5106 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5107 , p_error_column_name => 'unexpected error'
5108 , p_error_table_name => 'unexpected error'
5109 , p_message_name => 'unexpected error');
5110 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5111
5112 END IF;
5113
5114 --mdebug('Process: In Validate_UOMQuantity call Validate_CountQty ');
5115 MTL_INV_VALIDATE_GRP.Validate_CountQuantity(p_api_version => 0.9
5116 , x_return_status => x_return_status
5117 , x_msg_count => x_msg_count
5118 , x_msg_data => x_msg_data
5119 , x_errorcode => x_errorcode
5120 , p_count_quantity => p_count_quantity
5121 );
5122 --MDEBUG( 'ValidateCQty :Stat= '||x_errorcode);
5123 --MDEBUG( 'ValidateCQty :Ctype= '||to_char(MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.COUNT_TYPE_CODE));
5124
5125 --mdebug('Process: In Validate_UOMQuantity call Validate_CountQty Return='||x_return_status);
5126
5127
5128 IF x_errorcode = 22 THEN
5129
5130 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5131 p_cc_entry_interface_id =>
5132 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5133 , p_error_column_name => 'COUNT_QUANTITY'
5134 , p_error_table_name => 'MTL_CYCLE_COUNT_ENTRIES'
5135 , p_message_name => 'INV_CCEOI_NEG_QTY');
5136
5137 RAISE FND_API.G_EXC_ERROR;
5138 ELSIF x_errorcode = 60 THEN
5139
5140 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5141 p_cc_entry_interface_id =>
5142 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5143 , p_error_column_name => 'COUNT_QUANTITY'
5144 , p_error_table_name => 'MTL_CC_ENTRIES_INTERFACE'
5145 , p_message_name => 'INV_SERIAL_QTY_MUST_BE_1');
5146
5147 RAISE FND_API.G_EXC_ERROR;
5148 ELSIF x_errorcode = 61 THEN
5149
5150 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5151 p_cc_entry_interface_id =>
5152 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5153 , p_error_column_name => 'COUNT_QUANTITY'
5154 , p_error_table_name => 'MTL_CC_ENTRIES_INTERFACE'
5155 , p_message_name => 'INV_GREATER_EQUAL_ZERO');
5156
5157 RAISE FND_API.G_EXC_ERROR;
5158
5159 ELSIF x_errorcode < 0 THEN
5160 -- Write INTO interface error TABLE
5161 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5162 p_cc_entry_interface_id =>
5163 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5164 , p_error_column_name => 'unexpected error'
5165 , p_error_table_name => 'unexpected error'
5166 , p_message_name => 'unexpected error');
5167
5168 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5169 END IF;
5170
5171 END IF;
5172
5173
5174 IF (l_debug = 1) THEN
5175 mdebug('Process: In Validate_UOMQuantity call Validate_Calculate_Adj');
5176 END IF;
5177 MTL_CCEOI_PROCESS_PVT.Calculate_Adjustment
5178 (p_api_version => 0.9
5179 , x_return_status => x_return_status
5180 , x_msg_count => x_msg_count
5181 , x_msg_data => x_msg_data
5182 , x_errorcode => x_errorcode
5183 , p_inventory_item_id => p_inventory_item_id
5184 , p_organization_id => p_organization_id
5185 , p_lpn_id => p_lpn_id
5186 , p_subinventory => p_subinventory
5187 , p_revision => p_revision
5188 , p_locator_id => MTL_CCEOI_VAR_PVT.G_LOCATOR_ID
5189 , p_lot_number => p_lot_number
5190 , p_serial_number => p_serial_number
5191 , p_count_quantity => MTL_CCEOI_VAR_PVT.G_COUNT_QUANTITY
5192 , p_serial_number_control_code =>
5193 MTL_CCEOI_VAR_PVT.G_SKU_REC.SERIAL_NUMBER_CONTROL_CODE
5194 , p_serial_count_option =>
5195 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.SERIAL_COUNT_OPTION
5196 , p_system_quantity => p_system_quantity
5197 , p_secondary_system_quantity => p_secondary_system_quantity -- INVCONV
5198 );
5199 IF (l_debug = 1) THEN
5200 mdebug('Process: In Validate_UOMQuantity call Validate_Calculate_Adj Return='||x_return_status);
5201 END IF;
5202 --
5203 IF x_errorcode = 17 THEN -- XXX this code is disabled in CalcAdj()
5204 -- Write INTO interface error TABLE
5205 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5206 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5207 , p_error_column_name => 'TRANSACTION_QUANTITY'
5208 , p_error_table_name => 'MTL_ONHAND_QUANTITIES'
5209 , p_message_name => 'INV_CCEOI_ADJCALC_NO_SERIAL'
5210 );
5211 --
5212 RAISE FND_API.G_EXC_ERROR;
5213 ELSIF
5214 x_errorcode < 0 THEN
5215 -- Write INTO interface error TABLE
5216 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5217 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5218 , p_error_column_name => 'unexpected error'
5219 , p_error_table_name => 'unexpected error'
5220 , p_message_name => 'unexpected error'
5221 );
5222 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5223 END IF;
5224
5225 ELSE -- XXX this is just a precaution (should never happen)
5226 IF (l_debug = 1) THEN
5227 MDEBUG('Invalid count_type_code');
5228 END IF;
5229 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5230 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5231 , p_error_column_name => 'unexpected error'
5232 , p_error_table_name => 'unexpected error'
5233 , p_message_name => 'unexpected error'
5234 );
5235 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5236 END IF;
5237 --
5238 -- END of API body
5239 -- Standard check of p_commit
5240 IF FND_API.to_Boolean(p_commit) THEN
5241 COMMIT;
5242 END IF;
5243 -- Standard call to get message count and if count is 1, get message info
5244 FND_MSG_PUB.Count_And_Get
5245 (p_count => x_msg_count
5246 , p_data => x_msg_data);
5247 EXCEPTION
5248 WHEN FND_API.G_EXC_ERROR THEN
5249 --
5250 x_return_status := FND_API.G_RET_STS_ERROR;
5251 --
5252 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
5253 , p_data => x_msg_data);
5254 --
5255 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5256 --
5257 x_errorcode := -1;
5258 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5259 --
5260 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
5261 , p_data => x_msg_data);
5262 --
5263 WHEN OTHERS THEN
5264 --
5265 x_errorcode := -1;
5266 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5267 --
5268 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
5269 FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
5270 END IF;
5271 --
5272 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
5273 , p_data => x_msg_data);
5274 END;
5275 END;
5276 --
5277 -- Validate count date and counter
5278 PROCEDURE Validate_CDate_Counter(
5279 p_api_version IN NUMBER ,
5280 p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE,
5281 p_commit IN VARCHAR2 DEFAULT FND_API.G_FALSE,
5282 p_validation_level IN NUMBER DEFAULT FND_API.G_VALID_LEVEL_FULL,
5283 x_return_status OUT NOCOPY VARCHAR2 ,
5284 x_msg_count OUT NOCOPY NUMBER ,
5285 x_msg_data OUT NOCOPY VARCHAR2 ,
5286 x_errorcode OUT NOCOPY NUMBER ,
5287 p_employee_id IN NUMBER ,
5288 p_employee_name IN VARCHAR2 DEFAULT NULL,
5289 p_count_date IN DATE )
5290 IS
5291 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5292 BEGIN
5293 -- Start OF comments
5294 -- API name : Validate_CDate_Counter
5295 -- TYPE : Private
5296 -- Pre-reqs : None
5297 -- FUNCTION :
5298 -- Parameters:
5299 -- IN :
5300 -- p_api_version IN NUMBER (required)
5301 -- API Version of this procedure
5302 --
5303 -- p_init_msg_list IN VARCHAR2 (optional)
5304 -- DEFAULT = FND_API.G_FALSE,
5305 --
5306 -- p_commit IN VARCHAR2 (optional)
5307 -- DEFAULT = FND_API.G_FALSE
5308 --
5309 -- p_validation_level IN NUMBER (optional)
5310 -- DEFAULT = FND_API.G_VALID_LEVEL_FULL,
5311 --
5312 -- p_employee_id IN NUMBER (required)
5313 -- EmployeeID OF the counter
5314 --
5315 -- p_employee_name IN VARCHAR2 (optional - defaulted)
5316 -- default = NULL
5317 -- Name OF the counter
5318 --
5319 -- p_count_date IN DATE (required)
5320 -- DATE OF the COUNT
5321 --
5322 -- OUT :
5323 -- X_return_status OUT NUMBER
5324 -- Result of all the operations
5325 --
5326 -- x_msg_count OUT NUMBER,
5327 --
5328 -- x_msg_data OUT VARCHAR2,
5329 --
5330 -- X_ErrorCode OUT NUMBER
5331 -- Version: Current Version 0.9
5332 -- Changed : Nothing
5333 -- No Previous Version 0.0
5334 -- Initial version 0.9
5335 -- Notes : Note text
5336 -- END OF comments
5337 DECLARE
5338 --
5339 L_message_name VARCHAR2(100);
5340 --
5341 L_org INV_Validate.ORG;
5342 L_api_version CONSTANT NUMBER := 0.9;
5343 L_api_name CONSTANT VARCHAR2(30) := 'Validate_CDate_Counter';
5344 L_emp_id NUMBER := p_employee_id;
5345 L_emp_name VARCHAR2(60) := p_employee_name;
5346 L_temp VARCHAR2(60);
5347 BEGIN
5348 -- Standard start of API savepoint
5349 SAVEPOINT Validate_CDate_Counter;
5350 --
5351 -- Standard Call to check for call compatibility
5352 IF NOT FND_API.Compatible_API_Call(l_api_version
5353 , p_api_version
5354 , l_api_name
5355 , G_PKG_NAME) THEN
5356 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5357 END IF;
5358 --
5359 -- Initialize message list if p_init_msg_list is set to true
5360 IF FND_API.to_Boolean(p_init_msg_list) THEN
5361 FND_MSG_PUB.initialize;
5362 END IF;
5363 --
5364 -- Initialisize API return status to access
5365 x_return_status := FND_API.G_RET_STS_SUCCESS;
5366 x_errorcode := 0;
5367 --
5368 -- API body
5369 --
5370 IF (l_debug = 1) THEN
5371 mdebug('Process: In Validate_CDate_Counter call Validate Countdate');
5372 END IF;
5373 MTL_INV_VALIDATE_GRP.Validate_CountDate
5374 -- Prozedur
5375 (p_api_version => 0.9
5376 , x_return_status => x_return_status
5377 , x_msg_count => x_msg_count
5378 , x_msg_data => x_msg_data
5379 , x_errorcode => x_errorcode
5380 , p_count_date => p_count_date
5381 );
5382 IF (l_debug = 1) THEN
5383 MDEBUG( 'ValidateDate Stat '||to_char(x_errorcode)||'-'||x_return_status);
5384 mdebug('Process: In Validate_CDate_Counter call Validate Countdate Return='||x_return_status);
5385 END IF;
5386 --
5387 IF x_errorcode = 23 THEN
5388 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5389 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5390 , p_error_column_name => 'COUNT_DATE'
5391 , p_error_table_name => 'MTL_CYCLE_COUNT_HEADERS'
5392 , p_message_name => 'INV_CCEOI_COUNT_DATE_FUTURE'
5393 );
5394 --
5395 RAISE FND_API.G_EXC_ERROR;
5396 --
5397 ELSIF x_errorcode = 59 THEN -- New errorcode ( existing one )
5398 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5399 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5400 , p_error_column_name => 'COUNT_DATE'
5401 , p_error_table_name => 'MTL_CYCLE_COUNT_HEADERS'
5402 , p_message_name => 'INV_COUNT_DATE_FUTURE'
5403 );
5404 --
5405 RAISE FND_API.G_EXC_ERROR;
5406 ELSIF x_errorcode = 24 THEN
5407 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5408 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5409 , p_error_column_name => 'COUNT_DATE'
5410 , p_error_table_name => 'MTL_CYCLE_COUNT_HEADERS'
5411 , p_message_name => 'INV_CCEOI_NO_OPEN_ADJ_PRD'
5412 );
5413 --
5414 RAISE FND_API.G_EXC_ERROR;
5415
5416 ELSIF
5417 x_errorcode < 0 THEN
5418 -- Write INTO interface error TABLE
5419 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5420 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5421 , p_error_column_name => 'unexpected error'
5422 , p_error_table_name => 'unexpected error'
5423 , p_message_name => 'unexpected error'
5424 );
5425 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5426 END IF;
5427 --
5428 IF (l_debug = 1) THEN
5429 mdebug('Process: In Validate_CDate_Counter call Validate_Employee');
5430 END IF;
5431 /* Validate API Implementation for Empoloyee validation */
5432 l_org.organization_id := MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.organization_id;
5433 --
5434 IF l_emp_id is null and l_emp_name is null then
5435 IF (l_debug = 1) THEN
5436 mdebug('all null');
5437 END IF;
5438 x_errorcode := 25 ;
5439 ELSE
5440 SELECT DISTINCT full_name
5441 INTO L_temp
5442 FROM mtl_employees_current_view
5443 WHERE employee_id = l_emp_id;
5444
5445 if L_temp is null then
5446 x_errorcode := 26;
5447 ELSE
5448 MTL_CCEOI_VAR_PVT.G_EMPLOYEE_ID := l_emp_id;
5449 x_errorcode := 0;
5450 end if;
5451 END IF;
5452 IF (l_debug = 1) THEN
5453 mdebug('Process: In Validate_CDate_Counter call Validate_Employee Return='||x_return_status);
5454 mdebug('Process: In Validate_CDate_Counter call Validate_Employee Code='||x_errorcode);
5455 END IF;
5456 --
5457 IF x_errorcode > 0 THEN
5458 IF x_errorcode = 25 THEN
5459 L_message_name := 'INV_CCEOI_NO_COUNTER';
5460 ELSIF
5461 x_errorcode = 26 THEN
5462 L_message_name := 'INV_CCEOI_INVALID_COUNTER';
5463 ELSIF x_errorcode = 101 THEN
5464 L_message_name := 'INV_CCEOI_NOT_UNIQUE_COUNTER';
5465 END IF;
5466 -- Write INTO interface error TABLE
5467 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5468 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5469 , p_error_column_name => 'EMPLOYEE_ID/NAME'
5470 , p_error_table_name => 'MTL_EMPLOYEES_CURRENT_VIEW'
5471 , p_message_name => L_message_name
5472 );
5473 --
5474 RAISE FND_API.G_EXC_ERROR;
5475 ELSIF
5476 x_errorcode < 0 THEN
5477 -- Write INTO interface error TABLE
5478 MTL_CCEOI_PROCESS_PVT.Insert_CCEOIError(
5479 p_cc_entry_interface_id => MTL_CCEOI_VAR_PVT.G_CC_ENTRY_INTERFACE_ID
5480 , p_error_column_name => 'unexpected error'
5481 , p_error_table_name => 'unexpected error'
5482 , p_message_name => 'unexpected error'
5483 );
5484 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5485 END IF;
5486 --
5487 -- END of API body
5488 -- Standard check of p_commit
5489 IF FND_API.to_Boolean(p_commit) THEN
5490 COMMIT;
5491 END IF;
5492 -- Standard call to get message count and if count is 1, get message info
5493 FND_MSG_PUB.Count_And_Get
5494 (p_count => x_msg_count
5495 , p_data => x_msg_data);
5496 EXCEPTION
5497 WHEN FND_API.G_EXC_ERROR THEN
5498 --
5499 x_return_status := FND_API.G_RET_STS_ERROR;
5500 --
5501 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
5502 , p_data => x_msg_data);
5503 --
5504 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5505 --
5506 x_errorcode := -1;
5507 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5508 --
5509 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
5510 , p_data => x_msg_data);
5511 --
5512 WHEN OTHERS THEN
5513 --
5514 x_errorcode := -1;
5515 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5516 --
5517 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
5518 FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
5519 END IF;
5520 --
5521 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
5522 , p_data => x_msg_data);
5523 END;
5524 END;
5525 --
5526 -- .
5527 --
5528 -- Updates the application tables
5529 PROCEDURE Update_CCEntry(
5530 p_cycle_count_entry_id IN NUMBER )
5531 IS
5532 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5533 BEGIN
5534 -- Start OF comments
5535 -- API name : Update_CCEntry
5536 -- TYPE : Public
5537 -- Pre-reqs : None
5538 -- FUNCTION :
5539 -- UPDATES THE CYCLE COUNT ENTRIES TABLE
5540 -- ITH VALUES FROM THE GLOBAL VARIABLES
5541 -- Parameters:
5542 -- IN :
5543 -- p_cycle_count_entry_idc IN NUMBER (required)
5544 -- END OF comments
5545 DECLARE
5546 l_count_due_date DATE;
5547 BEGIN
5548 IF (l_debug = 1) THEN
5549 MDEBUG( 'Updating CC Entry Id '||to_char(p_cycle_count_entry_id));
5550 MDEBUG( 'Updating CC Entry Stat Cd'||to_char(MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE));
5551 MDEBUG( 'Updating CC Entry emp id'||to_char(MTL_CCEOI_VAR_PVT.G_EMPLOYEE_ID));
5552 MDEBUG( 'Updating CC Entry CntDt'||to_char(MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_DATE_CURRENT));
5553 MDEBUG( 'Updating CC Entry CntQty'||to_char(MTL_CCEOI_VAR_PVT.G_COUNT_Quantity));
5554 MDEBUG( 'Updating CC Entry CntQtyPrior'||to_char(MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_QUANTITY_PRIOR));
5555 END IF;
5556
5557 l_count_due_date :=
5558 nvl(MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_DUE_DATE,
5559 nvl(MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.COUNT_DUE_DATE,
5560 sysdate)); -- Bug16031205 removed validation as its not existing in forms/mobile code
5561
5562 UPDATE MTL_CYCLE_COUNT_ENTRIES
5563 SET
5564 last_update_date =
5565 sysdate
5566 , last_updated_by =
5567 MTL_CCEOI_VAR_PVT.G_UserID
5568 , last_update_login =
5569 MTL_CCEOI_VAR_PVT.G_LoginID
5570 , count_date_first =
5571 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_DATE_FIRST
5572 ,count_date_prior =
5573 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_DATE_PRIOR
5574 , count_date_current =
5575 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_DATE_CURRENT
5576 , counted_by_employee_id_first =
5577 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNTED_BY_EMPLOYEE_ID_FIRST
5578 , counted_by_employee_id_current=
5579 MTL_CCEOI_VAR_PVT.G_EMPLOYEE_ID
5580 , counted_by_employee_id_prior =
5581 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNTED_BY_EMPLOYEE_ID_PRIOR
5582 , counted_by_employee_id_dummy=
5583 MTL_CCEOI_VAR_PVT.G_EMPLOYEE_ID
5584 , count_uom_first =
5585 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_UOM_FIRST
5586 , count_uom_current=
5587 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_UOM_CURRENT
5588 , count_uom_prior=
5589 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_UOM_PRIOR
5590 , count_quantity_first =
5591 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_QUANTITY_FIRST
5592 , count_quantity_current=
5593 MTL_CCEOI_VAR_PVT.G_COUNT_QUANTITY
5594 , count_quantity_prior=
5595 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_QUANTITY_PRIOR
5596 , entry_status_code =
5597 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE
5598 , count_due_date =
5599 l_count_due_date
5600 , number_of_counts=
5601 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.NUMBER_OF_COUNTS
5602 , locator_id =
5603 MTL_CCEOI_VAR_PVT.G_LOCATOR_ID
5604 , adjustment_quantity =
5605 --MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ADJUSTMENT_QUANTITY
5606 MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_QUANTITY
5607 , adjustment_date =
5608 MTL_CCEOI_VAR_PVT.G_COUNT_DATE
5609 , adjustment_amount =
5610 MTL_CCEOI_VAR_PVT.G_ADJUSTMENT_AMOUNT
5611 , inventory_adjustment_account=
5612 decode(MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE, 5, MTL_CCEOI_VAR_PVT.G_ADJUST_ACCOUNT_ID, NULL)
5613 , approval_date =
5614 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.APPROVAL_DATE
5615 , approver_employee_id = null
5616 -- decode( MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.APPROVAL_DATE, null,
5617 -- null,
5618 -- MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNTED_BY_EMPLOYEE_ID_CURRENT)
5619 , revision=
5620 MTL_CCEOI_VAR_PVT.G_SKU_REC.revision
5621 , lot_number=
5622 MTL_CCEOI_VAR_PVT.G_SKU_REC.lot_number
5623 , lot_control =
5624 decode(MTL_CCEOI_VAR_PVT.G_SKU_REC.LOT_CONTROL_CODE, 1, null,
5625 MTL_CCEOI_VAR_PVT.G_SKU_REC.LOT_CONTROL_CODE)
5626 , system_quantity_first =
5627 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SYSTEM_QUANTITY_FIRST
5628 , system_quantity_current=
5629 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SYSTEM_QUANTITY_CURRENT,
5630 system_quantity_prior=
5631 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SYSTEM_QUANTITY_PRIOR
5632 , reference_first =
5633 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.REFERENCE_FIRST
5634 , reference_current=
5635 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.REFERENCE_CURRENT
5636 , reference_prior=
5637 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.REFERENCE_PRIOR
5638 , primary_uom_quantity_first =
5639 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.PRIMARY_UOM_QUANTITY_FIRST
5640 , primary_uom_quantity_prior=
5641 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.PRIMARY_UOM_QUANTITY_PRIOR
5642 , primary_uom_quantity_current=
5643 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.PRIMARY_UOM_QUANTITY_CURRENT
5644 , count_type_code =
5645 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_TYPE_CODE
5646 , transaction_reason_id=
5647 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.TRANSACTION_REASON_ID
5648 , request_id =
5649 MTL_CCEOI_VAR_PVT.G_RequestID
5650 , program_application_id=
5651 MTL_CCEOI_VAR_PVT.G_ProgramAppID
5652 , program_id =
5653 MTL_CCEOI_VAR_PVT.G_ProgramID
5654 , program_update_date =
5655 sysdate
5656 , approval_type =
5657 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.APPROVAL_TYPE
5658 , serial_number =
5659 MTL_CCEOI_VAR_PVT.G_SKU_REC.SERIAL_NUMBER
5660 , serial_detail =
5661 decode(MTL_CCEOI_VAR_PVT.G_SKU_REC.SERIAL_NUMBER, NULL,
5662 0, -- put 0 instead of NULL to be comliant with existing form
5663 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SERIAL_DETAIL)
5664 , approval_condition =
5665 nvl(MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.APPROVAL_CONDITION,0)
5666 -- added nvl(x,0) to have the same output as forms
5667 , neg_adjustment_quantity=
5668 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.NEG_ADJUSTMENT_QUANTITY
5669 , neg_adjustment_amount =
5670 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.NEG_ADJUSTMENT_AMOUNT
5671 , ITEM_UNIT_COST =
5672 MTL_CCEOI_VAR_PVT.G_ITEM_COST
5673 -- BEGIN INVCONV
5674 , Count_Secondary_Uom_First = MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.Count_Secondary_Uom_First
5675 , Count_Secondary_Uom_Current = MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.Count_Secondary_Uom_Current
5676 , Count_Secondary_Uom_Prior = MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.Count_Secondary_Uom_Prior
5677 , Secondary_Uom_Quantity_First = MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.Secondary_Uom_Quantity_First
5678 , Secondary_Uom_Quantity_Current = MTL_CCEOI_VAR_PVT.G_SECONDARY_COUNT_QUANTITY
5679 , Secondary_Uom_Quantity_Prior = MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.Secondary_Uom_Quantity_Prior
5680 , Secondary_System_Qty_First = MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.Secondary_System_Qty_First
5681 , Secondary_System_Qty_Current = MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.Secondary_System_Qty_Current
5682 , Secondary_System_Qty_Prior = MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.Secondary_System_Qty_Prior
5683 , Secondary_Adjustment_Quantity = MTL_CCEOI_VAR_PVT.G_SEC_ADJUSTMENT_QUANTITY
5684 -- END INVCONV
5685 WHERE
5686 cycle_count_entry_id = P_cycle_count_entry_id;
5687 IF (l_debug = 1) THEN
5688 MDEBUG( 'End of Update CC entry');
5689 END IF;
5690 END;
5691 END;
5692
5693 -- Processed the interface record
5694 -- This function will prepare record for being updated into
5695 -- mtl_cycle_count_entries and will also perform a transaction
5696 -- if necessary
5697 -- The logic which handles serial numbers is copied from INVATCEN.pld
5698 -- and will need further review/rewrite
5699 PROCEDURE Process_Data(
5700 p_api_version IN NUMBER ,
5701 p_init_msg_list IN VARCHAR2 DEFAULT FND_API.G_FALSE,
5702 p_commit IN VARCHAR2 DEFAULT FND_API.G_FALSE,
5703 p_validation_level IN NUMBER DEFAULT FND_API.G_VALID_LEVEL_FULL,
5704 x_return_status OUT NOCOPY VARCHAR2 ,
5705 x_msg_count OUT NOCOPY NUMBER ,
5706 x_msg_data OUT NOCOPY VARCHAR2 ,
5707 x_errorcode OUT NOCOPY NUMBER ,
5708 p_simulate IN VARCHAR2 DEFAULT FND_API.G_FALSE,
5709 p_interface_rec IN MTL_CCEOI_VAR_PVT.INV_CCEOI_TYPE )
5710 IS
5711 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5712 BEGIN
5713 -- Start OF comments
5714 -- API name : Process_Data
5715 -- TYPE : Private
5716 -- Pre-reqs : None
5717 -- FUNCTION :
5718 -- process data porcessed the interface RECORD according to the
5719 -- cycle COUNT entries form. this PROCEDURE can only be called
5720 -- BY the PROCEDURE MTL_CCEOI_PROCESS_PVT.Process_Data
5721 -- Parameters:
5722 -- IN :
5723 -- p_api_version IN NUMBER (required)
5724 -- API Version of this procedure
5725 --
5726 -- p_init_msg_list IN VARCHAR2 (optional)
5727 -- DEFAULT = FND_API.G_FALSE,
5728 --
5729 -- p_commit IN VARCHAR2 (optional)
5730 --
5731 -- DEFAULT = FND_API.G_FALSE
5732 -- p_validation_level IN NUMBER (optional)
5733 -- DEFAULT = FND_API.G_VALID_LEVEL_FULL
5734 -- currently unused
5735 --
5736 -- p_simulate IN VARCHAR2 DEFAULT FND_API.G_FALSE
5737 -- G_TRUE - skip any updates/inserts to any non-cc-interface tables
5738 -- G_FALSE - update any tables necessary
5739 --
5740 -- p_interface_rec MTL_CC_ENTRIES_INTERFACE%rowtype (required)
5741 -- interface RECORD parameter
5742 --
5743 -- OUT :
5744 -- X_return_status OUT NUMBER
5745 -- Result of all the operations
5746 --
5747 -- x_msg_count OUT NUMBER,
5748 --
5749 -- x_msg_data OUT VARCHAR2,
5750 --
5751 -- X_ErrorCode OUT NUMBER
5752 -- Version: Current Version 0.9
5753 -- Changed : Nothing
5754 -- No Previous Version 0.0
5755 -- Initial version 0.9
5756 -- Notes : Note text
5757 -- END OF comments
5758 DECLARE
5759 --
5760
5761 L_success NUMBER := 1;
5762 --
5763 --
5764 CURSOR L_TolItemClass_Csr(cheader IN NUMBER,
5765 item in number) IS
5766 select
5767 i.APPROVAL_TOLERANCE_POSITIVE ITEM_TOL_POS
5768 ,i.APPROVAL_TOLERANCE_NEGATIVE ITEM_TOL_NEG
5769 ,c.APPROVAL_TOLERANCE_POSITIVE CLASS_TOL_POS
5770 ,c.APPROVAL_TOLERANCE_NEGATIVE CLASS_TOL_NEG
5771 ,c.COST_TOLERANCE_POSITIVE CLASS_COST_POS
5772 ,c.COST_TOLERANCE_NEGATIVE CLASS_COST_NEG
5773 FROM MTL_CYCLE_COUNT_ITEMS i
5774 , MTL_CYCLE_COUNT_CLASSES c
5775 WHERE i.cycle_count_Header_id = cheader
5776 AND i.inventory_item_id = item
5777 AND c.abc_class_id = i.abc_class_id
5778 AND c.cycle_count_header_id = i.cycle_count_Header_id;
5779 --
5780 L_api_version CONSTANT NUMBER := 0.9;
5781 L_api_name CONSTANT VARCHAR2(30) := 'Process_Data';
5782 BEGIN
5783
5784 IF (l_debug = 1) THEN
5785 MDEBUG( 'Begin process:Count Qty '|| to_char(p_interface_rec.count_quantity));
5786 END IF;
5787
5788 IF (l_debug = 1) THEN
5789 MDEBUG( 'Process Data: Begin ');
5790 MDEBUG( 'Item-CC header -> '||to_char(MTL_CCEOI_VAR_PVT.G_INVENTORY_ITEM_ID)|| ' - '||to_char(MTL_CCEOI_VAR_PVT.G_CC_HEADER_ID));
5791 END IF;
5792
5793 -- Standard start of API savepoint
5794 SAVEPOINT Process_Data;
5795 --
5796 -- Standard Call to check for call compatibility
5797 IF NOT FND_API.Compatible_API_Call(l_api_version
5798 , p_api_version
5799 , l_api_name
5800 , G_PKG_NAME) THEN
5801 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5802 END IF;
5803 --
5804 -- Initialize message list if p_init_msg_list is set to true
5805 IF FND_API.to_Boolean(p_init_msg_list) THEN
5806 FND_MSG_PUB.initialize;
5807 END IF;
5808 --
5809 -- Initialisize API return status to access
5810 x_return_status := FND_API.G_RET_STS_SUCCESS;
5811 x_errorcode := 0;
5812 --
5813 -- API body
5814 IF (l_debug = 1) THEN
5815 MDEBUG('Process: In Process_Data');
5816 END IF;
5817
5818 --
5819 -- zero cycle COUNT
5820 -- SET the current RECORD AND the first to current
5821 -- AND THEN SET the entr_status_code to =5 (completed)
5822 IF MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.COUNT_TYPE_CODE = 4 THEN
5823 --
5824 IF (l_debug = 1) THEN
5825 MDEBUG( 'Process Data: call Zero count');
5826 END IF;
5827 Zero_Count_Logic(
5828 p_reference => p_interface_rec.reference
5829 , p_primary_uom_quantity => p_interface_rec.primary_uom_quantity
5830 );
5831
5832
5833 ELSE
5834 -- non zero-count logic
5835
5836 -- propagate count type code
5837 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.COUNT_TYPE_CODE :=
5838 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.COUNT_TYPE_CODE;
5839
5840 -- without serial control
5841 IF MTL_CCEOI_VAR_PVT.G_SKU_REC.SERIAL_NUMBER_CONTROL_CODE
5842 IN(1, 6) THEN
5843 IF (l_debug = 1) THEN
5844 MDEBUG( 'Process Data: without serial');
5845 MDEBUG( to_char(MTL_CCEOI_VAR_PVT.G_INVENTORY_ITEM_ID)||' - '||to_char(MTL_CCEOI_VAR_PVT.G_CC_HEADER_ID));
5846 END IF;
5847 --
5848
5849 For c_rec in L_TolItemClass_Csr (
5850 MTL_CCEOI_VAR_PVT.G_CC_HEADER_ID,
5851 MTL_CCEOI_VAR_PVT.G_INVENTORY_ITEM_ID)
5852 LOOP
5853
5854 --
5855 IF (l_debug = 1) THEN
5856 MDEBUG( 'Process Data: W/o Sl# Calculate_tol ');
5857 END IF;
5858
5859 Calculate_Tolerance(
5860 p_item_app_tol_pos => c_rec.ITEM_TOL_POS
5861 , p_item_app_tol_neg => c_rec.ITEM_TOL_NEG
5862 , p_class_app_tol_pos => c_rec.CLASS_TOL_POS
5863 , p_class_app_tol_neg => c_rec.CLASS_TOL_NEG
5864 , p_class_cost_tol_pos => c_rec.CLASS_COST_POS
5865 , p_class_cost_tol_neg => c_rec.CLASS_COST_NEG
5866 , p_head_app_tol_pos =>
5867 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.APPROVAL_TOLERANCE_POSITIVE
5868 , p_head_app_tol_neg =>
5869 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.APPROVAL_TOLERANCE_NEGATIVE
5870 , p_head_cost_tol_pos =>
5871 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.COST_TOLERANCE_POSITIVE
5872 , p_head_cost_tol_neg =>
5873 MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.COST_TOLERANCE_NEGATIVE
5874 , p_interface_rec => p_interface_rec
5875 , p_simulate => p_simulate
5876 );
5877 END LOOP;
5878 --
5879 -- with serial control
5880 ELSIF MTL_CCEOI_VAR_PVT.G_SKU_REC.SERIAL_NUMBER_CONTROL_CODE IN(2, 5)
5881 THEN
5882 IF (l_debug = 1) THEN
5883 MDEBUG( 'Process Data: with serial'||mtl_cceoi_var_pvt.g_sku_rec.serial_number);
5884 END IF;
5885
5886 --
5887 -- One ROW per request
5888
5889 IF(MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.serial_count_option = 2)
5890 THEN
5891 IF (l_debug = 1) THEN
5892 MDEBUG( 'Process Data: with serial one per request');
5893 END IF;
5894
5895 --
5896 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SERIAL_DETAIL:= 2;
5897 --
5898
5899 IF MTL_CCEOI_VAR_PVT.G_COUNT_QUANTITY <> MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY THEN
5900 IF (l_debug = 1) THEN
5901 MDEBUG( 'Process Data: Not equal sys and count qties');
5902 MDEBUG( 'Process Data: level '||to_char(p_validation_level));
5903 END IF;
5904 --
5905 IF NOT FND_API.to_Boolean(p_simulate) THEN
5906 --
5907 IF (l_debug = 1) THEN
5908 MDEBUG( 'Process Data: mark RECORD as locked ');
5909 MDEBUG( 'Process Data: Sl# '||p_interface_rec.serial_number);
5910 MDEBUG( 'Process Data: Item# '||to_char(MTL_CCEOI_VAR_PVT.G_inventory_item_id));
5911 MDEBUG( 'Process Data: Org '|| to_char(MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.ORGANIZATION_ID));
5912 MDEBUG( 'Process Data: CCHid '|| to_char(MTL_CCEOI_VAR_PVT.G_CC_HEADER_ID));
5913 MDEBUG( 'Process Data: CCEid '|| to_char(MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.CYCLE_COUNT_ENTRY_ID));
5914 END IF;
5915
5916 -- mark RECORD as locked
5917 serial_check.inv_mark_serial(
5918 from_serial_number => p_interface_rec.serial_number
5919 , to_serial_number => p_interface_rec.serial_number
5920 , item_id => MTL_CCEOI_VAR_PVT.G_inventory_item_id
5921 , org_id => MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.ORGANIZATION_ID
5922 , hdr_id => MTL_CCEOI_VAR_PVT.G_CC_HEADER_ID
5923 , temp_id => MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.CYCLE_COUNT_ENTRY_ID
5924 , lot_temp_id => NULL
5925 , success => L_success);
5926 --
5927 IF(L_success < 0) THEN
5928 --
5929 IF (l_debug = 1) THEN
5930 MDEBUG( 'Process Data: INV_SERIAL_UNAVAILABLE ');
5931 END IF;
5932 FND_MESSAGE.SET_NAME('INV', 'INV_SERIAL_UNAVAILABLE');
5933 FND_MESSAGE.SET_TOKEN('FIRST-SERIAL',
5934 p_interface_rec.serial_number);
5935 FND_MSG_PUB.Add;
5936 --x_errorcode := -1;
5937 x_errorcode := 70;
5938 --RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5939 RAISE FND_API.G_EXC_ERROR;
5940 --
5941 END IF;
5942 END IF;
5943 --
5944 END IF;
5945 --
5946 IF (l_debug = 1) THEN
5947 MDEBUG( 'Process Data:serial one per request call Existing_Serial');
5948 mdebug('Process: In Process_Data with serial one per request call Existing_Serial');
5949 END IF;
5950 Existing_Serial_Number(
5951 p_reference => p_interface_rec.reference
5952 , p_primary_uom_quantity=> p_interface_rec.primary_uom_quantity
5953 , p_count_uom => p_interface_rec.count_uom
5954 , p_subinventory =>p_interface_rec.subinventory
5955 , p_lot_number => p_interface_rec.lot_number
5956 , p_lot_expiration => MTL_CCEOI_VAR_PVT.G_SKU_REC.EXPIRATION_DATE
5957 , p_revision => p_interface_rec.revision
5958 , p_transaction_reason_id => p_interface_rec.transaction_reason_id
5959 , p_serial_number => p_interface_rec.serial_number
5960 , p_transaction_process_mode => p_interface_rec.process_mode
5961 , p_simulate => p_simulate
5962 );
5963
5964 --
5965 -- IF RECORD completed processed OR marked FOR recounting
5966 IF(MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE
5967 IN(3, 5)) THEN
5968 --
5969 IF (l_debug = 1) THEN
5970 MDEBUG( 'Process : with serial one per request Completed');
5971 END IF;
5972
5973 IF (l_debug = 1) THEN
5974 mdebug('Process: In Process_Data with serial one per request Completed');
5975 END IF;
5976
5977 -- if p_validation_level = 1 THEN
5978 if p_simulate = FND_API.G_FALSE THEN
5979 serial_check.inv_unmark_serial(
5980 from_serial_number => p_interface_rec.serial_number
5981 , to_serial_number => p_interface_rec.serial_number
5982 , serial_code => MTL_CCEOI_VAR_PVT.G_SKU_REC.SERIAL_NUMBER_CONTROL_CODE
5983 , hdr_id => MTL_CCEOI_VAR_PVT.G_CC_HEADER_ID
5984 , temp_id => MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.CYCLE_COUNT_ENTRY_ID
5985 , lot_temp_id => NULL);
5986 --
5987
5988 END IF;
5989 --
5990 END IF;
5991 END IF;
5992 END IF;
5993 END IF;
5994 --
5995 -- END of API body
5996 -- Standard check of p_commit
5997 IF FND_API.to_Boolean(p_commit) THEN
5998 COMMIT;
5999 END IF;
6000 -- Standard call to get message count and if count is 1, get message info
6001 FND_MSG_PUB.Count_And_Get
6002 (p_count => x_msg_count
6003 , p_data => x_msg_data);
6004 EXCEPTION
6005 WHEN FND_API.G_EXC_ERROR THEN
6006 --
6007 ROLLBACK TO Process_Data;
6008 --
6009 x_return_status := FND_API.G_RET_STS_ERROR;
6010 --
6011 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
6012 , p_data => x_msg_data);
6013 --
6014 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6015 --
6016 ROLLBACK TO Process_Data;
6017 --
6018 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6019 --
6020 x_errorcode := -1;
6021 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
6022 , p_data => x_msg_data);
6023 --
6024 WHEN OTHERS THEN
6025 --
6026 ROLLBACK TO Process_Data;
6027 --
6028 x_errorcode := -1;
6029 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6030 --
6031 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
6032 FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
6033 END IF;
6034 --
6035 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count
6036 , p_data => x_msg_data);
6037 END;
6038 END;
6039 --
6040 --
6041 -- updates interface record information
6042 PROCEDURE Update_CCIEntry(
6043 p_interface_rec IN MTL_CCEOI_VAR_PVT.INV_CCEOI_TYPE ,
6044 x_return_status OUT NOCOPY VARCHAR2 )
6045 IS
6046 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6047 BEGIN
6048 -- Start OF comments
6049 -- API name : Update_CCIEntry
6050 -- TYPE : Private
6051 -- Pre-reqs : None
6052 -- FUNCTION :
6053 -- this PROCEDURE will UPDATE all columns OF the interface TABLE
6054 -- with the VALUES OF the parameter p_interface_rec. IF this RECORD
6055 -- have p_interface_rec.cycle_count_entry_id IS NOT NULL that means
6056 -- that the RECORD IS exported, THEN only the unexported columns
6057 -- can be updated.
6058 -- Parameters:
6059 -- IN :
6060 -- p_interface_rec MTL_CC_ENTRIES_INTERFACE%ROWTYPE (required)
6061 -- the interface RECORD
6062 --
6063 -- OUT :
6064 -- X_return_status OUT NUMBER
6065 -- Result of all the operations
6066 --
6067 -- Version: Current Version 0.9
6068 -- Changed : Nothing
6069 -- No Previous Version 0.0
6070 -- Initial version 0.9
6071 -- Notes : Note text
6072 -- END OF comments
6073 DECLARE
6074 dummy integer;
6075
6076 BEGIN
6077 X_return_status := FND_API.G_RET_STS_SUCCESS;
6078 -- update RECORD to be successful
6079 --
6080 BEGIN
6081 --
6082 -- An exported RECORD
6083 IF (l_debug = 1) THEN
6084 mdebug('updating iface rcord with cc_entry_interface_id='||p_interface_rec.cc_entry_interface_id);
6085 END IF;
6086 IF p_interface_rec.cycle_count_entry_id IS NOT NULL THEN
6087 --
6088 --
6089 UPDATE MTL_CC_ENTRIES_INTERFACE
6090 SET
6091 last_update_date = sysdate
6092 , last_updated_by = MTL_CCEOI_VAR_PVT.G_UserID
6093 , last_update_login = MTL_CCEOI_VAR_PVT.G_LoginID
6094 , request_id = MTL_CCEOI_VAR_PVT.G_RequestID
6095 , program_application_id = MTL_CCEOI_VAR_PVT.G_ProgramAppID
6096 , program_id = MTL_CCEOI_VAR_PVT.G_ProgramID
6097 , program_update_date = sysdate
6098 , primary_uom_quantity = p_interface_rec.primary_uom_quantity
6099 , count_uom = p_interface_rec.count_uom
6100 , count_unit_of_measure = p_interface_rec.count_unit_of_measure
6101 , count_quantity = p_interface_rec.count_quantity
6102 , count_date =p_interface_rec.count_date
6103 , employee_id = p_interface_rec.employee_id
6104 , employee_full_name = p_interface_rec.employee_full_name
6105 , reference = p_interface_rec.reference
6106 , transaction_reason_id = p_interface_rec.transaction_reason_id
6107 , transaction_reason = p_interface_rec.transaction_reason
6108 , project_id = p_interface_rec.project_id
6109 , task_id = p_interface_rec.task_id
6110 --This code modification done for the bug2311404 by aapaul
6111 , system_quantity = decode(MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY,NULL,
6112 system_quantity,MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY)
6113 , lock_flag = p_interface_rec.lock_flag
6114 -- BEGIN INVCONV
6115 , secondary_uom = p_interface_rec.secondary_uom
6116 , secondary_unit_of_measure = p_interface_rec.secondary_unit_of_measure
6117 , secondary_count_quantity = p_interface_rec.secondary_count_quantity
6118 , secondary_system_quantity = decode(MTL_CCEOI_VAR_PVT.G_SECONDARY_SYSTEM_QUANTITY,NULL,
6119 secondary_system_quantity,MTL_CCEOI_VAR_PVT.G_SECONDARY_SYSTEM_QUANTITY)
6120 -- END INVCONV
6121 WHERE
6122 cc_entry_interface_id = p_interface_rec.cc_entry_interface_id;
6123 --
6124 ELSE
6125 --
6126 UPDATE MTL_CC_ENTRIES_INTERFACE
6127 SET cost_group_name = p_interface_rec.cost_group_name
6128 , cost_group_id = p_interface_rec.cost_group_id
6129 , parent_lpn_id = p_interface_rec.parent_lpn_id
6130 , outermost_lpn_id = p_interface_rec.outermost_lpn_id
6131 , organization_id = p_interface_rec.organization_id
6132 , last_update_date = sysdate
6133 , last_updated_by = MTL_CCEOI_VAR_PVT.G_UserID
6134 , last_update_login = MTL_CCEOI_VAR_PVT.G_LoginID
6135 , action_code = p_interface_rec.action_code
6136 , cycle_count_header_id = p_interface_rec.cycle_count_header_id
6137 , cycle_count_header_name = p_interface_rec.cycle_count_header_name
6138 , count_list_sequence = p_interface_rec.count_list_sequence
6139 , inventory_item_id = p_interface_rec.inventory_item_id
6140 -- , inventory_item = p_interface_rec.inventory_item
6141 , item_segment1 = p_interface_rec.item_segment1
6142 , item_segment2 = p_interface_rec.item_segment2
6143 , item_segment3 = p_interface_rec.item_segment3
6144 , item_segment4 = p_interface_rec.item_segment4
6145 , item_segment5 = p_interface_rec.item_segment5
6146 , item_segment6 = p_interface_rec.item_segment6
6147 , item_segment7 = p_interface_rec.item_segment7
6148 , item_segment8 = p_interface_rec.item_segment8
6149 , item_segment9 = p_interface_rec.item_segment9
6150 , item_segment10 = p_interface_rec.item_segment10
6151 , item_segment11 = p_interface_rec.item_segment11
6152 , item_segment12 = p_interface_rec.item_segment12
6153 , item_segment13 = p_interface_rec.item_segment13
6154 , item_segment14 = p_interface_rec.item_segment14
6155 , item_segment15 = p_interface_rec.item_segment15
6156 , item_segment16 = p_interface_rec.item_segment16
6157 , item_segment17 = p_interface_rec.item_segment17
6158 , item_segment18 =p_interface_rec.item_segment18
6159 , item_segment19 = p_interface_rec.item_segment19
6160 , item_segment20 = p_interface_rec.item_segment20
6161 , revision = p_interface_rec.revision
6162 , subinventory = p_interface_rec.subinventory
6163 , locator_id = p_interface_rec.locator_id
6164 -- , locator = p_interface_rec.locator
6165 , locator_segment1 = p_interface_rec.locator_segment1
6166 , locator_segment2 = p_interface_rec.locator_segment2
6167 , locator_segment3 = p_interface_rec.locator_segment3
6168 , locator_segment4 = p_interface_rec.locator_segment4
6169 , locator_segment5 = p_interface_rec.locator_segment5
6170 , locator_segment6 = p_interface_rec.locator_segment6
6171 , locator_segment7 = p_interface_rec.locator_segment7
6172 , locator_segment8 = p_interface_rec.locator_segment8
6173 , locator_segment9 = p_interface_rec.locator_segment9
6174 , locator_segment10 = p_interface_rec.locator_segment10
6175 , locator_segment11 = p_interface_rec.locator_segment11
6176 , locator_segment12 = p_interface_rec.locator_segment12
6177 , locator_segment13 = p_interface_rec.locator_segment13
6178 , locator_segment14 = p_interface_rec.locator_segment14
6179 , locator_segment15 = p_interface_rec.locator_segment15
6180 , locator_segment16 = p_interface_rec.locator_segment16
6181 , locator_segment17 = p_interface_rec.locator_segment17
6182 , locator_segment18 = p_interface_rec.locator_segment18
6183 , locator_segment19 = p_interface_rec.locator_segment19
6184 , locator_segment20 = p_interface_rec.locator_segment20
6185 , lot_number = p_interface_rec.lot_number
6186 , serial_number = p_interface_rec.serial_number
6187 , primary_uom_quantity = p_interface_rec.primary_uom_quantity
6188 , count_uom = p_interface_rec.count_uom
6189 , count_unit_of_measure = p_interface_rec.count_unit_of_measure
6190 , count_quantity = p_interface_rec.count_quantity
6191 , adjustment_account_id = p_interface_rec.adjustment_account_id
6192 -- , adjustment_account = p_interface_rec.adjustment_account
6193 , account_segment1 = p_interface_rec.account_segment1
6194 , account_segment2 = p_interface_rec.account_segment2
6195 , account_segment3 = p_interface_rec.account_segment3
6196 , account_segment4 = p_interface_rec.account_segment4
6197 , account_segment5 = p_interface_rec.account_segment5
6198 , account_segment6 = p_interface_rec.account_segment6
6199 , account_segment7 = p_interface_rec.account_segment7
6200 , account_segment8 = p_interface_rec.account_segment8
6201 , account_segment9 = p_interface_rec.account_segment9
6202 , account_segment10 = p_interface_rec.account_segment10
6203 , account_segment11 = p_interface_rec.account_segment11
6204 , account_segment12 = p_interface_rec.account_segment12
6205 , account_segment13 = p_interface_rec.account_segment13
6206 , account_segment14 = p_interface_rec.account_segment14
6207 , account_segment15 = p_interface_rec.account_segment15
6208 , account_segment16 = p_interface_rec.account_segment16
6209 , account_segment17 = p_interface_rec.account_segment17
6210 , account_segment18 = p_interface_rec.account_segment18
6211 , account_segment19 = p_interface_rec.account_segment19
6212 , account_segment20 = p_interface_rec.account_segment20
6213 , account_segment21 = p_interface_rec.account_segment21
6214 , account_segment22 = p_interface_rec.account_segment22
6215 , account_segment23 = p_interface_rec.account_segment23
6216 , account_segment24 = p_interface_rec.account_segment24
6217 , account_segment25 = p_interface_rec.account_segment25
6218 , account_segment26 = p_interface_rec.account_segment26
6219 , account_segment27 = p_interface_rec.account_segment27
6220 , account_segment28 = p_interface_rec.account_segment28
6221 , account_segment29 = p_interface_rec.account_segment29
6222 , account_segment30 = p_interface_rec.account_segment30
6223 , count_date =p_interface_rec.count_date
6224 , employee_id = p_interface_rec.employee_id
6225 , employee_full_name = p_interface_rec.employee_full_name
6226 , reference = p_interface_rec.reference
6227 , transaction_reason_id = p_interface_rec.transaction_reason_id
6228 , transaction_reason = p_interface_rec.transaction_reason
6229 , request_id = MTL_CCEOI_VAR_PVT.G_RequestID
6230 , program_application_id = MTL_CCEOI_VAR_PVT.G_ProgramAppID
6231 , program_id = MTL_CCEOI_VAR_PVT.G_ProgramID
6232 , program_update_date = sysdate
6233 , attribute_category = p_interface_rec.attribute_category
6234 , attribute1 = p_interface_rec.attribute1
6235 , attribute2 = p_interface_rec.attribute2
6236 , attribute3 = p_interface_rec.attribute3
6237 , attribute4 = p_interface_rec.attribute4
6238 , attribute5 = p_interface_rec.attribute5
6239 , attribute6 = p_interface_rec.attribute6
6240 , attribute7 = p_interface_rec.attribute7
6241 , attribute8 = p_interface_rec.attribute8
6242 , attribute9 = p_interface_rec.attribute9
6243 , attribute10 = p_interface_rec.attribute10
6244 , attribute11 = p_interface_rec.attribute11
6245 , attribute12 = p_interface_rec.attribute12
6246 , attribute13 = p_interface_rec.attribute13
6247 , attribute14 = p_interface_rec.attribute14
6248 , attribute15 = p_interface_rec.attribute15
6249 , project_id = p_interface_rec.project_id
6250 , task_id = p_interface_rec.task_id
6251 , lock_flag = p_interface_rec.lock_flag
6252 -- BEGIN INVCONV
6253 , secondary_uom = p_interface_rec.secondary_uom
6254 , secondary_unit_of_measure = p_interface_rec.secondary_unit_of_measure
6255 , secondary_count_quantity = p_interface_rec.secondary_count_quantity
6256 -- END INVCONV
6257 WHERE
6258 cc_entry_interface_id = p_interface_rec.cc_entry_interface_id;
6259 --
6260 END IF;
6261 EXCEPTION
6262 WHEN OTHERS THEN
6263 X_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6264 END;
6265 END;
6266 END;
6267
6268
6269
6270
6271 --
6272 -- calls mtl_serial_check.inv_qtybetwn
6273 -- to validate serial location and check whether a serial number
6274 -- can be issued or received
6275 --
6276 -- pre: it is necessary to call all validation routines that would have
6277 -- computed system quantity, count quantity and derive internal variables
6278 -- containing item, org, subinv, locator, etc.
6279 --
6280 -- post:
6281 --
6282 FUNCTION check_serial_location(
6283 P_issue_receipt IN VARCHAR2,
6284 p_simulate IN VARCHAR2 DEFAULT FND_API.G_FALSE )
6285 return BOOLEAN
6286 IS
6287 l_return_status VARCHAR2(1);
6288 l_errorcode NUMBER;
6289 l_msg_data VARCHAR2(240);
6290 l_msg_count NUMBER;
6291 l_serial_number_type NUMBER;
6292 l_prefix VARCHAR2(30);
6293 l_quantity NUMBER;
6294
6295 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6296 BEGIN
6297 SELECT SERIAL_NUMBER_TYPE
6298 INTO l_serial_number_type
6299 FROM MTL_PARAMETERS
6300 WHERE organization_id = MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.ORGANIZATION_ID;
6301
6302 mtl_serial_check.inv_qtybetwn(
6303 p_api_version => 0.9,
6304 x_errorcode => l_errorcode,
6305 x_return_status => l_return_status,
6306 x_msg_count => l_msg_count,
6307 x_msg_data => l_msg_data,
6308 p_item_id => MTL_CCEOI_VAR_PVT.G_INVENTORY_ITEM_ID,
6309 p_organization_id => MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.ORGANIZATION_ID,
6310 p_subinventory => MTL_CCEOI_VAR_PVT.G_SUBINVENTORY,
6311 p_locator_id => MTL_CCEOI_VAR_PVT.G_LOCATOR_ID,
6312 p_revision => MTL_CCEOI_VAR_PVT.G_SKU_REC.REVISION,
6313 p_lot_number => MTL_CCEOI_VAR_PVT.G_SKU_REC.LOT_NUMBER,
6314 p_from_serial_number => MTL_CCEOI_VAR_PVT.G_SKU_REC.SERIAL_NUMBER,
6315 p_to_serial_number => MTL_CCEOI_VAR_PVT.G_SKU_REC.SERIAL_NUMBER,
6316 p_serial_control => MTL_CCEOI_VAR_PVT.G_SKU_REC.SERIAL_NUMBER_CONTROL_CODE,
6317 p_serial_number_type => l_serial_number_type,
6318 p_transaction_action_id => 4,
6319 p_transaction_source_type_id => 9,
6320 x_prefix => l_prefix,
6321 x_quantity => l_quantity,
6322 p_receipt_issue_flag => p_issue_receipt,
6323 p_simulate => p_simulate);
6324
6325
6326 if (l_return_status <> FND_API.G_RET_STS_SUCCESS) then
6327 return (FALSE);
6328 end if;
6329
6330
6331 return (TRUE);
6332 end;
6333
6334 /*
6335 u1 VARCHAR2(30);
6336 u2 VARCHAR2(30);
6337 u3 NUMBER;
6338 u4 VARCHAR2(30);
6339 u5 NUMBER;
6340 u6 NUMBER;
6341 u7 NUMBER;
6342 u8 NUMBER;
6343 u9 NUMBER;
6344 u10 NUMBER;
6345 u11 VARCHAR2(3);
6346 u12 VARCHAR2(30);
6347 u13 VARCHAR2(10);
6348 u14 NUMBER;
6349 u15 VARCHAR2(1);
6350 L_serial_count NUMBER;
6351 --
6352 v_serial_count_option number := MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.SERIAL_COUNT_OPTION ;
6353 v_serial_number_type number := 1;
6354 v_org_id number := MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.ORGANIZATION_ID;
6355 v_serial_number VARCHAR2(30):= MTL_CCEOI_VAR_PVT.G_SKU_REC.SERIAL_NUMBER ;
6356
6357 v_serial_detail number := MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.SERIAL_DETAIL;
6358 v_serial_discrepancy number := MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.SERIAL_DISCREPANCY_OPTION;
6359 v_item_id number := MTL_CCEOI_VAR_PVT.G_INVENTORY_ITEM_ID ;
6360 v_subinv varchar2(10):= MTL_CCEOI_VAR_PVT.G_SUBINVENTORY;
6361 v_revision varchar2(3) := MTL_CCEOI_VAR_PVT.G_SKU_REC.REVISION;
6362 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
6363 v_lot_number VARCHAR2(80):= MTL_CCEOI_VAR_PVT.G_SKU_REC.LOT_NUMBER;
6364 v_msn_serial_number varchar2(30);
6365 v_msn_item_id number;
6366 v_msn_org_id number;
6367 v_msn_subinv varchar2(10);
6368 v_msn_lot_number number;
6369 v_msn_locator_id number;
6370 v_msn_revision varchar2(3);
6371 v_current_status number;
6372 --
6373 P_api_version NUMBER := 0.9;
6374 P_INIT_MSG_LIST VARCHAR2(30) DEFAULT FND_API.G_FALSE;
6375 P_COMMIT VARCHAR2(30) DEFAULT FND_API.G_FALSE;
6376 P_VALIDATION_LEVEL NUMBER := 1;
6377 -- P_VALIDATION_LEVEL NUMBER DEFAULT FND_API.G_VALID_LEVEL_FULL;
6378 X_RETURN_STATUS VARCHAR2(90);
6379 X_MSG_COUNT NUMBER;
6380 X_MSG_DATA VARCHAR2(90);
6381 X_ERRORCODE NUMBER;
6382 --
6383 L_serial_status BOOLEAN := TRUE;
6384 L_ret_value BOOLEAN := TRUE ;
6385 BEGIN
6386 IF (l_debug = 1) THEN
6387 MDEBUG( 'Process- witihin check-serial');
6388 END IF;
6389 IF (MTL_CCEOI_VAR_PVT.G_SYSTEM_QUANTITY = 1 AND MTL_CCEOI_VAR_PVT.G_COUNT_QUANTITY = 1
6390 AND MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.SERIAL_COUNT_OPTION = 2) then
6391 L_ret_value := TRUE;
6392 else
6393 if(v_org_id IS NOT NULL) then
6394 SELECT SERIAL_NUMBER_TYPE
6395 INTO v_serial_number_type
6396 FROM MTL_PARAMETERS
6397 WHERE ORGANIZATION_ID = v_org_id;
6398 end if;
6399 u1 := v_serial_number ;
6400 u2 := v_serial_number ;
6401 u3 := MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.SYSTEM_QUANTITY_CURRENT;
6402 u4 := NULL;
6403 u5 := v_item_id;
6404 u6 := v_org_id;
6405 u7 := v_serial_number_type;
6406 u8 := MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_ENTRY_REC.CYCLE_COUNT_ENTRY_ID;
6407 u9 := to_char(9);
6408 u10:= MTL_CCEOI_VAR_PVT.G_SKU_REC.SERIAL_NUMBER_CONTROL_CODE;
6409 u11:= v_revision;
6410 u12:= v_lot_number;
6411 u13:= v_subinv;
6412 u14:= MTL_CCEOI_VAR_PVT.G_LOCATOR_ID;
6413 u15:= P_issue_receipt;
6414 --
6415 IF (l_debug = 1) THEN
6416 MDEBUG( 'Process- within serial no type ='||to_char(u7));
6417 MDEBUG( 'Process- within item ='||to_char(u5));
6418 MDEBUG( 'Process- within org ='||to_char(u6));
6419 MDEBUG( 'Process- within SerlNoCtrlCd ='||to_char(u10));
6420 MDEBUG( 'Process- within Locator ='||to_char(u14));
6421 MDEBUG( 'Process- within serial ='||u1);
6422 MDEBUG( 'Process- within Lot ='||u12);
6423 MDEBUG( 'Process- within rev ='||u11);
6424 MDEBUG( 'Process- within Rec-Issue ='||u15);
6425 MDEBUG( 'Process- within subinv ='||u13);
6426 MDEBUG( 'Process- within check-serial before call qtybetwn');
6427 END IF;
6428 --
6429 --
6430 MTL_SERIAL_CHECK.INV_QTYBETWN
6431 ( P_API_VERSION=>p_api_version ,
6432 P_INIT_MSG_LIST =>p_init_msg_list,
6433 P_COMMIT =>p_commit,
6434 P_VALIDATION_LEVEL =>p_validation_level,
6435 X_RETURN_STATUS =>x_return_status,
6436 X_MSG_COUNT =>x_msg_count,
6437 X_MSG_DATA =>x_msg_data,
6438 X_ERRORCODE =>x_errorcode,
6439 P_FROM_SERIAL_NUMBER=>u1,
6440 P_TO_SERIAL_NUMBER =>u2,
6441 P_QUANTITY =>u3,
6442 P_PREFIX =>u4,
6443 P_ITEM_ID =>u5,
6444 P_ORGANIZATION_ID =>u6,
6445 P_SERIAL_NUMBER_TYPE=>u7,
6446 P_TRANSACTION_ACTION_ID =>u8,
6447 P_TRANSACTION_SOURCE_TYPE_ID=>u9,
6448 P_SERIAL_CONTROL =>u10,
6449 P_REVISION =>u11,
6450 P_LOT_NUMBER =>u12,
6451 P_SUBINVENTORY =>u13,
6452 P_LOCATOR_ID =>u14,
6453 P_RECEIPT_ISSUE_FLAG =>u15,
6454 P_VALIDATE => 'Y'
6455 );
6456 --L_serial_status := MTL_INV_UTIL_GRP.CHECK_SERIAL_NUMBER_LOCATION (u1,u5,u6,u7,u10,u11,u12,u13,u14,u15);
6457 --
6458
6459 IF (l_debug = 1) THEN
6460 MDEBUG( 'Process- within check-serial after call qtybetwn='||x_return_status);
6461 END IF;
6462
6463 if (x_return_status <> 'S' AND P_issue_receipt = 'R') then
6464 SELECT COUNT(*)
6465 INTO L_serial_count
6466 FROM MTL_SERIAL_NUMBERS
6467 WHERE SERIAL_NUMBER = v_serial_number AND
6468 INVENTORY_ITEM_ID = v_item_id AND
6469 CURRENT_ORGANIZATION_ID = v_org_id AND
6470 CURRENT_STATUS = 3;
6471 if(L_serial_count = 1 AND v_serial_discrepancy = 1 ) then
6472 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.APPROVAL_CONDITION := 1;
6473 MTL_CCEOI_VAR_PVT.G_CC_ENTRY_REC_TMP.ENTRY_STATUS_CODE := 2;
6474 fnd_message.set_name('INV', 'INV_CC_SERIAL_MULTI_TRANSACT2');
6475 fnd_message.set_token('SERIAL', v_serial_number);
6476 fnd_msg_pub.add;
6477
6478 L_ret_value := TRUE;
6479 else
6480 IF (l_debug = 1) THEN
6481 MDEBUG( 'Process- within check-serial-1-INV_CC_SERIAL_DISCREPANCY' );
6482 END IF;
6483 fnd_message.set_name('INV', 'INV_CC_SERIAL_DISCREPANCY');
6484 fnd_msg_pub.add;
6485
6486 L_ret_value := FALSE;
6487 end if;
6488 elsif x_return_status <> 'S' then
6489 IF (l_debug = 1) THEN
6490 MDEBUG( 'Process- within check-serial-2-INV_CC_SERIAL_DISCREPANCY' );
6491 END IF;
6492 fnd_message.set_name('INV', 'INV_CC_SERIAL_DISCREPANCY');
6493 fnd_msg_pub.add;
6494 L_ret_value := FALSE;
6495 end if;
6496 end if;
6497 return (L_ret_value);
6498 END ;
6499 --
6500 */
6501
6502
6503 PROCEDURE DELETE_RESERVATION (
6504 p_subinventory IN VARCHAR2 ,
6505 p_lot_number IN VARCHAR2 ,
6506 p_revision IN VARCHAR2
6507 )
6508 IS
6509 l_mtl_reservation_rec INV_RESERVATION_GLOBAL.MTL_RESERVATION_REC_TYPE
6510 :=INV_CC_RESERVATIONS_PVT.Define_Reserv_Rec_Type;
6511 l_init_msg_lst varchar2(1);
6512 l_error_code NUMBER;
6513 l_return_status VARCHAR2(1);
6514 l_msg_count NUMBER;
6515 l_msg_data VARCHAR2(240);
6516 lmsg varchar2(2000);
6517 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6518 BEGIN
6519 /* passing input variable */
6520 /* delete only cycle count reservation */
6521 l_mtl_reservation_rec.demand_source_type_id := 9;
6522 l_mtl_reservation_rec.organization_id := MTL_CCEOI_VAR_PVT.G_CYCLE_COUNT_HEADER_REC.organization_id;
6523 l_mtl_reservation_rec.inventory_item_id := MTL_CCEOI_VAR_PVT.G_INVENTORY_ITEM_ID;
6524 l_mtl_reservation_rec.subinventory_code := p_subinventory;
6525 l_mtl_reservation_rec.revision := p_revision;
6526 l_mtl_reservation_rec.locator_id := MTL_CCEOI_VAR_PVT.G_LOCATOR_ID;
6527 l_mtl_reservation_rec.lot_number := p_lot_number;
6528 l_mtl_reservation_rec.lpn_id := MTL_CCEOI_VAR_PVT.G_LPN_ID;
6529 --
6530 INV_CC_RESERVATIONS_PVT.Delete_All_Reservation
6531 (
6532 p_api_version_number => 1.0
6533 , p_init_msg_lst => l_init_msg_lst
6534 , p_mtl_reservation_rec => l_mtl_reservation_rec
6535 , x_error_code => l_error_code
6536 , x_return_status => l_return_status
6537 , x_msg_count => l_msg_count
6538 , x_msg_data => l_msg_data
6539 );
6540 IF l_return_status <> 'S' then
6541 IF (l_debug = 1) THEN
6542 mdebug('error in delete all reservations');
6543 END IF;
6544 --FND_MESSAGE.ERROR;
6545 --RAISE FORM_TRIGGER_FAILURE;
6546 END IF;
6547 END DELETE_RESERVATION;
6548
6549 -- BEGIN INVCONV
6550 PROCEDURE validate_secondaryuomqty (
6551 p_api_version IN NUMBER
6552 , p_init_msg_list IN VARCHAR2 DEFAULT fnd_api.g_false
6553 , p_commit IN VARCHAR2 DEFAULT fnd_api.g_false
6554 , p_validation_level IN NUMBER DEFAULT fnd_api.g_valid_level_full
6555 , x_return_status OUT NOCOPY VARCHAR2
6556 , x_msg_count OUT NOCOPY NUMBER
6557 , x_msg_data OUT NOCOPY VARCHAR2
6558 , x_errorcode OUT NOCOPY NUMBER
6559 , p_organization_id IN NUMBER
6560 , p_inventory_item_id IN NUMBER
6561 , p_lpn_id IN NUMBER DEFAULT NULL
6562 , p_serial_number IN VARCHAR2 DEFAULT NULL
6563 , p_subinventory IN VARCHAR2
6564 , p_revision IN VARCHAR2 DEFAULT NULL
6565 , p_lot_number IN VARCHAR2
6566 , p_secondary_uom IN VARCHAR2
6567 , p_secondary_unit_of_measure IN VARCHAR2
6568 , p_secondary_count_quantity IN NUMBER
6569 , p_secondary_system_quantity IN NUMBER
6570 , p_tracking_quantity_ind IN VARCHAR2
6571 , p_secondary_default_ind IN VARCHAR2) IS
6572 --
6573 l_debug NUMBER := NVL (fnd_profile.VALUE ('INV_DEBUG_TRACE'), 0);
6574 l_api_version CONSTANT NUMBER := 0.9;
6575 l_api_name CONSTANT VARCHAR2 (30) := 'Validate_SecondaryUOMQty';
6576 l_table_name VARCHAR2 (100);
6577 l_column_name VARCHAR2 (100);
6578 l_message_name VARCHAR2 (30);
6579 BEGIN
6580 -- Standard start of API savepoint
6581 SAVEPOINT validate_uomquantity;
6582
6583 -- Standard Call to check for call compatibility
6584 IF NOT fnd_api.compatible_api_call (l_api_version
6585 , p_api_version
6586 , l_api_name
6587 , g_pkg_name) THEN
6588 RAISE fnd_api.g_exc_unexpected_error;
6589 END IF;
6590
6591 -- Initialize message list if p_init_msg_list is set to true
6592 IF fnd_api.to_boolean (p_init_msg_list) THEN
6593 fnd_msg_pub.initialize;
6594 END IF;
6595
6596 -- Initialisize API return status to success
6597 x_return_status := fnd_api.g_ret_sts_success;
6598 x_errorcode := 0;
6599
6600 --
6601 IF (l_debug = 1) THEN
6602 mdebug ( 'Validate_SecondaryUOMQty call. count_type_code = '
6603 || NVL (TO_CHAR (mtl_cceoi_var_pvt.g_cycle_count_entry_rec.count_type_code), 'NULL'));
6604 mdebug ('Tracking Quantity Ind ' || p_tracking_quantity_ind);
6605 mdebug ('Secondary Default Ind ' || p_secondary_default_ind);
6606 END IF;
6607
6608 IF mtl_cceoi_var_pvt.g_cycle_count_entry_rec.count_type_code = 4
6609 OR p_tracking_quantity_ind <> 'PS' THEN
6610 mtl_cceoi_var_pvt.g_secondary_count_uom := NULL;
6611 mtl_cceoi_var_pvt.g_secondary_count_quantity := NULL;
6612 mtl_cceoi_var_pvt.g_secondary_system_quantity := NULL;
6613 mtl_cceoi_var_pvt.g_lpn_item_sec_system_qty := NULL;
6614 mtl_cceoi_var_pvt.g_sec_adjustment_quantity := NULL;
6615 ELSIF ( mtl_cceoi_var_pvt.g_cycle_count_entry_rec.count_type_code IN (1, 2, 3)
6616 OR mtl_cceoi_var_pvt.g_cycle_count_entry_rec.count_type_code IS NULL)
6617 AND p_tracking_quantity_ind = 'PS' THEN
6618 IF (l_debug = 1) THEN
6619 mdebug ( 'Process: In Validate_SecondaryUOMQty call Validate_SecondaryCountUOM: '
6620 || p_secondary_uom);
6621 END IF;
6622
6623 mtl_inv_validate_grp.validate_secondarycountuom
6624 (p_api_version => 0.9
6625 , x_msg_count => x_msg_count
6626 , x_msg_data => x_msg_data
6627 , x_return_status => x_return_status
6628 , x_errorcode => x_errorcode
6629 , p_organization_id => p_organization_id
6630 , p_inventory_item_id => p_inventory_item_id
6631 , p_secondary_uom => p_secondary_uom
6632 , p_secondary_unit_of_measure => p_secondary_unit_of_measure
6633 , p_tracking_quantity_ind => p_tracking_quantity_ind);
6634
6635 IF (l_debug = 1) THEN
6636 mdebug ('After Validate Secondary UOM ' || TO_CHAR (x_errorcode) || ' - '
6637 || x_return_status);
6638 END IF;
6639
6640 IF x_errorcode = 20 THEN
6641 -- Write INTO interface error TABLE
6642 mtl_cceoi_process_pvt.insert_cceoierror
6643 (p_cc_entry_interface_id => mtl_cceoi_var_pvt.g_cc_entry_interface_id
6644 , p_error_column_name => 'SECONDARY_UOM_CODE'
6645 , p_error_table_name => 'MTL_SYSTEM_ITEMS'
6646 , p_message_name => 'INV_INCORRECT_SECONDARY_UOM');
6647 RAISE fnd_api.g_exc_error;
6648 END IF;
6649
6650 IF (l_debug = 1) THEN
6651 mdebug ( 'Process: In Validate_SecondaryUOMQty call Validate_SecondaryCountQty: '
6652 || p_secondary_count_quantity);
6653 END IF;
6654
6655 -- Validate Secondary count quantity
6656 -- Need to handle conversions and defaulting
6657 mtl_inv_validate_grp.validate_secondarycountqty
6658 (p_api_version => 0.9
6659 , x_return_status => x_return_status
6660 , x_msg_count => x_msg_count
6661 , x_msg_data => x_msg_data
6662 , x_errorcode => x_errorcode
6663 , p_organization_id => p_organization_id
6664 , p_inventory_item_id => p_inventory_item_id
6665 , p_lot_number => p_lot_number
6666 , p_count_uom => MTL_CCEOI_VAR_PVT.G_UOM_CODE
6667 , p_count_quantity => MTL_CCEOI_VAR_PVT.G_COUNT_QUANTITY
6668 , p_secondary_uom => MTL_CCEOI_VAR_PVT.g_secondary_count_uom
6669 , p_secondary_quantity => p_secondary_count_quantity
6670 , p_tracking_quantity_ind => p_tracking_quantity_ind
6671 , p_secondary_default_ind => p_secondary_default_ind
6672 );
6673
6674 IF (l_debug = 1) THEN
6675 mdebug ('After Validate Secondary Qty ' || TO_CHAR (x_errorcode) || ' - '
6676 || x_return_status);
6677 END IF;
6678
6679 IF x_errorcode = 50 THEN
6680 -- Write INTO interface error TABLE
6681 mtl_cceoi_process_pvt.insert_cceoierror
6682 (p_cc_entry_interface_id => mtl_cceoi_var_pvt.g_cc_entry_interface_id
6683 , p_error_column_name => 'SECONDARY_COUNT_QUANTITY'
6684 , p_error_table_name => 'MTL_CC_ENTRIES_INTERFACE'
6685 , p_message_name => 'INV_NO_CONVERSION_ERR');
6686 RAISE fnd_api.g_exc_error;
6687 ELSIF x_errorcode = 51 THEN
6688 -- Write INTO interface error TABLE
6689 mtl_cceoi_process_pvt.insert_cceoierror
6690 (p_cc_entry_interface_id => mtl_cceoi_var_pvt.g_cc_entry_interface_id
6691 , p_error_column_name => 'SECONDARY_COUNT_QUANTITY'
6692 , p_error_table_name => 'MTL_CC_ENTRIES_INTERFACE'
6693 , p_message_name => 'INV_DEVIATION_CHECK_ERR');
6694 RAISE fnd_api.g_exc_error;
6695 ELSIF x_errorcode = 52 THEN
6696 -- Write INTO interface error TABLE
6697 mtl_cceoi_process_pvt.insert_cceoierror
6698 (p_cc_entry_interface_id => mtl_cceoi_var_pvt.g_cc_entry_interface_id
6699 , p_error_column_name => 'SECONDARY_COUNT_QUANTITY'
6700 , p_error_table_name => 'MTL_CC_ENTRIES_INTERFACE'
6701 , p_message_name => 'INV_CCEOI_NEG_QTY');
6702 RAISE fnd_api.g_exc_error;
6703 END IF;
6704
6705 -- Calculate secondary adjustment quantity
6706 MTL_CCEOI_VAR_PVT.g_sec_adjustment_quantity :=
6707 nvl(MTL_CCEOI_VAR_PVT.g_secondary_count_quantity,0) - nvl(MTL_CCEOI_VAR_PVT.g_secondary_system_quantity,0);
6708
6709 ELSE -- count type code
6710 IF (l_debug = 1) THEN
6711 mdebug ('Invalid count_type_code');
6712 END IF;
6713
6714 mtl_cceoi_process_pvt.insert_cceoierror
6715 (p_cc_entry_interface_id => mtl_cceoi_var_pvt.g_cc_entry_interface_id
6716 , p_error_column_name => 'unexpected error'
6717 , p_error_table_name => 'unexpected error'
6718 , p_message_name => 'unexpected error');
6719 RAISE fnd_api.g_exc_unexpected_error;
6720 END IF; -- count type code
6721
6722 -- Standard check of p_commit
6723 IF fnd_api.to_boolean (p_commit) THEN
6724 COMMIT;
6725 END IF;
6726
6727 -- Standard call to get message count and if count is 1, get message info
6728 fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data);
6729 EXCEPTION
6730 WHEN fnd_api.g_exc_error THEN
6731 ROLLBACK TO validate_secondarycountuom;
6732 x_return_status := fnd_api.g_ret_sts_error;
6733 fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data);
6734 WHEN fnd_api.g_exc_unexpected_error THEN
6735 ROLLBACK TO validate_secondarycountuom;
6736 x_return_status := fnd_api.g_ret_sts_unexp_error;
6737 x_errorcode := -1;
6738 fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data);
6739 WHEN OTHERS THEN
6740 ROLLBACK TO validate_secondarycountuom;
6741 x_errorcode := -1;
6742 x_return_status := fnd_api.g_ret_sts_unexp_error;
6743
6744 IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error) THEN
6745 fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
6746 END IF;
6747
6748 fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data);
6749 END validate_secondaryuomqty;
6750 -- END INVCONV
6751
6752 END MTL_CCEOI_PROCESS_PVT;