[Home] [Help]
PACKAGE BODY: APPS.CSD_UPDATE_PROGRAMS_PVT
Source
1 Package Body CSD_UPDATE_PROGRAMS_PVT as
2 /* $Header: csddrclb.pls 120.21.12020000.9 2013/04/14 00:44:40 takwong ship $ */
3
4 /* --------------------------------------*/
5 /* Define global variables */
6 /* --------------------------------------*/
7
8 G_PKG_NAME CONSTANT VARCHAR2(30) := 'CSD_UPDATE_PROGRAMS_PVT';
9 G_FILE_NAME CONSTANT VARCHAR2(30) := 'csddrclb.pls';
10
11 -- Global variable for storing the debug level
12 G_debug_level number := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
13
14
15 --bug#8261344
16 G_CSD_RET_STS_WARNING CONSTANT VARCHAR2(1) := 'W';
17
18
19 -- Added by Vijay 10/22/04
20 TYPE RCPT_LINES_Rec_Type IS RECORD
21 (
22 rma_number oe_order_headers_all.order_number%type,
23 rma_header_id oe_order_headers_all.header_id%type ,
24 line_id oe_order_lines_all.line_id%type ,
25 rma_line_number oe_order_lines_all.line_number%type ,
26 inventory_item_id oe_order_lines_all.inventory_item_id%type,
27 org_name hr_all_organization_units.name%type ,
28 organization_id rcv_transactions.organization_id%type,
29 unit_of_measure rcv_transactions.unit_of_measure%type,
30 received_quantity rcv_transactions.quantity%type ,
31 received_date rcv_transactions.transaction_date%type ,
32 transaction_id rcv_transactions.transaction_id%type,
33 subinventory rcv_transactions.subinventory%type,
34 locator_id rcv_transactions.locator_id%type,
35 transaction_type rcv_transactions.transaction_type%type,
36 ro_serial_number csd_repairs.serial_number%type ,
37 repair_number csd_repairs.repair_number%type,
38 ro_uom csd_repairs.unit_of_measure%type,
39 ro_item_id csd_repairs.inventory_item_id%type ,
40 product_transaction_id csd_product_transactions.product_transaction_id%type,
41 repair_line_id csd_product_transactions.repair_line_id%type,
42 action_code csd_product_transactions.action_code%type,
43 action_type csd_product_transactions.action_type%type, --bug#10099900
44 source_serial_number csd_product_transactions.source_serial_number%type,
45 source_instance_id csd_product_transactions.source_instance_id%type,
46 prod_txn_recd_qty csd_product_transactions.quantity_received%type,
47 estimate_quantity cs_estimate_details.quantity_required%type ,
48 est_order_line_id cs_estimate_details.order_line_id%type ,
49 prod_txn_item_id cs_estimate_details.inventory_item_id%type
50 );
51
52 TYPE IO_RCPT_LINES_Rec_Type IS RECORD
53 (
54 product_transaction_id csd_product_transactions.PRODUCT_TRANSACTION_ID%type,
55 prod_txn_status csd_product_transactions.PROD_TXN_STATUS%type,
56 repair_line_id csd_product_transactions.REPAIR_LINE_ID%type,
57 order_header_id csd_product_transactions.ORDER_HEADER_ID%type,
58 order_line_id csd_product_transactions.ORDER_LINE_ID%type,
59 req_header_id csd_product_transactions.REQ_HEADER_ID%type,
60 req_line_id csd_product_transactions.REPAIR_LINE_ID%type,
61 prod_txn_rcvd_qty csd_product_transactions.quantity_received%type,
62 ro_qty csd_repairs.quantity%type,
63 ro_rcvd_qty csd_repairs.quantity_rcvd%type,
64 inventory_item_id csd_repairs.inventory_item_id%type,
65 ro_uom csd_repairs.unit_of_measure%type,
66 requisition_number po_requisition_headers_all.segment1%type,
67 ordered_quantity oe_order_lines_all.ordered_quantity%type,
68 order_number oe_order_headers_all.order_number%type
69 );
70
71 TYPE SHIP_LINES_Rec_Type IS RECORD
72 (
73 shipped_serial_num wsh_serial_numbers.fm_serial_number%type,
74 lot_number wsh_delivery_details.lot_number%type ,
75 revision wsh_delivery_details.revision%type ,
76 subinv wsh_delivery_details.subinventory%type ,
77 requested_quantity wsh_delivery_details.requested_quantity%type,
78 shipped_quantity wsh_delivery_details.shipped_quantity%type,
79 delivery_detail_id wsh_delivery_details.delivery_detail_id%type,
80 shipped_uom wsh_delivery_details.requested_quantity_uom%type ,
81 inventory_item_id wsh_delivery_details.inventory_item_id%type ,
82 organization_id wsh_delivery_details.organization_id%type,
83 order_number wsh_delivery_details.source_header_number%type ,
84 sales_order_header wsh_delivery_details.source_header_id%type ,
85 locator_id wsh_delivery_details.locator_id%type,
86 released_status wsh_delivery_details.released_status%type, --bug#14657082 --bug#15859195
87 order_line_number oe_order_lines_all.line_number%type ,
88 date_shipped oe_order_lines_all.actual_shipment_date%type ,
89 line_id oe_order_lines_all.line_id%type , --Bug#6779806
90 repair_number csd_repairs.repair_number%type,
91 repair_line_id csd_repairs.repair_line_id%type,
92 ro_uom csd_repairs.unit_of_measure%type ,
93 ro_item_id csd_repairs.inventory_item_id%type ,
94 estimate_quantity cs_estimate_details.quantity_required%type ,
95 prod_txn_serial_num csd_product_transactions.source_serial_number%type ,
96 source_instance_id csd_product_transactions.source_instance_id%type,
97 product_transaction_id csd_product_transactions.product_transaction_id%type,
98 action_code csd_product_transactions.action_code%type,
99 delivery_name wsh_new_deliveries.name%type ,
100 org_name hr_all_organization_units.name%type
101 );
102 TYPE IO_SHIP_LINES_Rec_Type IS RECORD
103 (
104 header_id oe_order_lines_all.header_id%type,
105 line_id oe_order_lines_all.line_id%type,
106 ordered_quantity oe_order_lines_all.ordered_quantity%type,
107 req_header_id oe_order_lines_all.source_document_id%type ,
108 req_line_id oe_order_lines_all.source_document_line_id%type ,
109 req_number oe_order_lines_all.orig_sys_document_ref%type ,
110 inventory_item_id oe_order_lines_all.inventory_item_id%type,
111 shipment_date oe_order_lines_all.actual_shipment_date%type ,
112 delivery_detail_id wsh_delivery_details.delivery_detail_id%type,
113 shipped_quantity wsh_delivery_details.shipped_quantity%type,
114 del_line_serial_num wsh_serial_numbers.fm_serial_number%type ,
115 lot_number wsh_delivery_details .lot_number%type,
116 subinventory wsh_delivery_details .subinventory%type,
117 locator_id wsh_delivery_details .locator_id%type,
118 organization_id wsh_delivery_details .organization_id%type,
119 released_status wsh_delivery_details .released_status%type,
120 requested_quantity wsh_delivery_details .requested_quantity%type,
121 order_number wsh_delivery_details .source_header_number%type ,
122 source_organization_id po_requisition_lines_all.source_organization_id%type,
123 source_subinventory po_requisition_lines_all.source_subinventory%type,
124 destination_organization_id po_requisition_lines_all.destination_organization_id%type,
125 destination_subinventory po_requisition_lines_all.destination_subinventory%type,
126 serial_number_control_code mtl_system_items.serial_number_control_code%type,
127 lot_control_code mtl_system_items.lot_control_code%type,
128 requisition_number po_requisition_headers_all.segment1%type ,
129 source_org_name hr_all_organization_units.name%type ,
130 destination_org_name hr_all_organization_units.name%type ,
131 txn_source_id mtl_txn_request_lines.txn_source_id%type
132 );
133
134 TYPE JOB_COMPLETION_Rec_Type IS RECORD
135 (
136 repair_job_xref_id CSD_REPAIR_JOB_XREF.repair_job_xref_id%type,
137 wip_entity_id CSD_REPAIR_JOB_XREF.wip_entity_id%type,
138 repair_line_id CSD_REPAIR_JOB_XREF.repair_line_id%type,
139 allocated_comp_qty CSD_REPAIR_JOB_XREF.quantity_completed%type ,
140 allocated_job_qty CSD_REPAIR_JOB_XREF.quantity%type ,
141 organization_id CSD_REPAIR_JOB_XREF.organization_id%type,
142 repair_number CSD_REPAIRS.repair_number%type,
143 promise_date CSD_REPAIRS.promise_date%type,
144 ro_serial_num CSD_REPAIRS.serial_number%type ,
145 ro_item_id CSD_REPAIRS.inventory_item_id%type ,
146 job_completed_qty WIP_DISCRETE_JOBS.quantity_completed%type ,
147 job_qty WIP_DISCRETE_JOBS.start_quantity%type ,
148 date_completed WIP_DISCRETE_JOBS.date_completed%type,
149 job_item_id WIP_DISCRETE_JOBS.primary_item_id%type,
150 wip_entity_name WIP_ENTITIES.wip_entity_name%type,
151 serial_number_control_code MTL_SYSTEM_ITEMS.serial_number_control_code%type
152
153 );
154
155 TYPE JOB_CREATION_Rec_Type IS RECORD
156 (
157 repair_job_xref_id CSD_REPAIR_JOB_XREF.repair_job_xref_id%type,
158 repair_line_id CSD_REPAIR_JOB_XREF.repair_line_id%type,
159 organization_id CSD_REPAIR_JOB_XREF.organization_id%type,
160 allocated_job_qty CSD_REPAIR_JOB_XREF.quantity%type ,
161 wip_entity_id WIP_ENTITIES.wip_entity_id%type,
162 wip_entity_name WIP_ENTITIES.wip_entity_name%type,
163 job_qty WIP_DISCRETE_JOBS.start_quantity%type ,
164 creation_date WIP_DISCRETE_JOBS.creation_date%type
165 );
166
167 --------------------
168 PROCEDURE check_for_cancelled_order(p_repair_line_id NUMBER);
169 /*-------------------------------------------------------------------------------------*/
170 /* Function name: DEBUG */
171 /* Description : Logs the debug message */
172 /* Called from : Called from Update API */
173 /* */
174 /* STANDARD PARAMETERS */
175 /* In Parameters : */
176 /* p_message Required Debug message that needs to be logged */
177 /* p_mod_name Required Module name */
178 /* p_severity_level Required Severity level */
179 /* Output Parameters: */
180 /* NON-STANDARD PARAMETERS */
181 /* In Parameters */
182 /* Out parameters */
183 /* Change Hist : */
184 /* 09/20/03 vlakaman Initial Creation. */
185 /*-------------------------------------------------------------------------------------*/
186
187 Procedure DEBUG
188 (p_message in varchar2,
189 p_mod_name in varchar2,
190 p_severity_level in number
191 ) IS
192
193 -- Variables used in FND Log
194 l_stat_level number := FND_LOG.LEVEL_STATEMENT;
195 l_proc_level number := FND_LOG.LEVEL_PROCEDURE;
196 l_event_level number := FND_LOG.LEVEL_EVENT;
197 l_excep_level number := FND_LOG.LEVEL_EXCEPTION;
198 l_error_level number := FND_LOG.LEVEL_ERROR;
199 l_unexp_level number := FND_LOG.LEVEL_UNEXPECTED;
200
201 BEGIN
202
203 IF p_severity_level = 1 THEN
204 IF ( l_stat_level >= G_debug_level) THEN
205 FND_LOG.STRING(l_stat_level,p_mod_name,p_message);
206 END IF;
207 ELSIF p_severity_level = 2 THEN
208 IF ( l_proc_level >= G_debug_level) THEN
209 FND_LOG.STRING(l_proc_level,p_mod_name,p_message);
210 END IF;
211 ELSIF p_severity_level = 3 THEN
212 IF ( l_event_level >= G_debug_level) THEN
213 FND_LOG.STRING(l_event_level,p_mod_name,p_message);
214 END IF;
215 ELSIF p_severity_level = 4 THEN
216 IF ( l_excep_level >= G_debug_level) THEN
217 FND_LOG.STRING(l_excep_level,p_mod_name,p_message);
218 END IF;
219 ELSIF p_severity_level = 5 THEN
220 IF ( l_error_level >= G_debug_level) THEN
221 FND_LOG.STRING(l_error_level,p_mod_name,p_message);
222 END IF;
223 ELSIF p_severity_level = 6 THEN
224 IF ( l_unexp_level >= G_debug_level) THEN
225 FND_LOG.STRING(l_unexp_level,p_mod_name,p_message);
226 END IF;
227 END IF;
228
229 END DEBUG;
230
231 /*-------------------------------------------------------------------------------------*/
232 /* Function name: INIT_ACTIVITY_REC */
233 /* Description : Initialize the activity record */
234 /* Called from : Called from Update API */
235 /* */
236 /* STANDARD PARAMETERS */
237 /* In Parameters : */
238 /* Output Parameters: */
239 /* NON-STANDARD PARAMETERS */
240 /* In Parameters */
241 /* Out parameters */
242 /* Change Hist : */
243 /* 09/20/03 vlakaman Initial Creation. */
244 /*-------------------------------------------------------------------------------------*/
245
246 Function INIT_ACTIVITY_REC RETURN csd_update_programs_pvt.activity_rec_type IS
247 l_activity_rec activity_rec_type;
248 BEGIN
249 -- Initialize all the in the activity record
250 l_activity_rec.REPAIR_HISTORY_ID := NULL;
251 l_activity_rec.REPAIR_LINE_ID := NULL;
252 l_activity_rec.REQUEST_ID := NULL;
253 l_activity_rec.PROGRAM_ID := NULL;
254 l_activity_rec.PROGRAM_APPLICATION_ID := NULL;
255 l_activity_rec.PROGRAM_UPDATE_DATE := NULL;
256 l_activity_rec.EVENT_CODE := NULL;
257 l_activity_rec.ACTION_CODE := NULL;
258 l_activity_rec.EVENT_DATE := NULL;
259 l_activity_rec.QUANTITY := NULL;
260 l_activity_rec.PARAMN1 := NULL;
261 l_activity_rec.PARAMN2 := NULL;
262 l_activity_rec.PARAMN3 := NULL;
263 l_activity_rec.PARAMN4 := NULL;
264 l_activity_rec.PARAMN5 := NULL;
265 l_activity_rec.PARAMN6 := NULL;
266 l_activity_rec.PARAMN7 := NULL;
267 l_activity_rec.PARAMN8 := NULL;
268 l_activity_rec.PARAMN9 := NULL;
269 l_activity_rec.PARAMN10 := NULL;
270 l_activity_rec.PARAMC1 := NULL;
271 l_activity_rec.PARAMC2 := NULL;
272 l_activity_rec.PARAMC3 := NULL;
273 l_activity_rec.PARAMC4 := NULL;
274 l_activity_rec.PARAMC5 := NULL;
275 l_activity_rec.PARAMC6 := NULL;
276 l_activity_rec.PARAMC7 := NULL;
277 l_activity_rec.PARAMC8 := NULL;
278 l_activity_rec.PARAMC9 := NULL;
279 l_activity_rec.PARAMC10 := NULL;
280 l_activity_rec.PARAMD1 := NULL;
281 l_activity_rec.PARAMD2 := NULL;
282 l_activity_rec.PARAMD3 := NULL;
283 l_activity_rec.PARAMD4 := NULL;
284 l_activity_rec.PARAMD5 := NULL;
285 l_activity_rec.PARAMD6 := NULL;
286 l_activity_rec.PARAMD7 := NULL;
287 l_activity_rec.PARAMD8 := NULL;
288 l_activity_rec.PARAMD9 := NULL;
289 l_activity_rec.PARAMD10 := NULL;
290 l_activity_rec.ATTRIBUTE_CATEGORY := NULL;
291 l_activity_rec.ATTRIBUTE1 := NULL;
292 l_activity_rec.ATTRIBUTE2 := NULL;
293 l_activity_rec.ATTRIBUTE3 := NULL;
294 l_activity_rec.ATTRIBUTE4 := NULL;
295 l_activity_rec.ATTRIBUTE5 := NULL;
296 l_activity_rec.ATTRIBUTE6 := NULL;
297 l_activity_rec.ATTRIBUTE7 := NULL;
298 l_activity_rec.ATTRIBUTE8 := NULL;
299 l_activity_rec.ATTRIBUTE9 := NULL;
300 l_activity_rec.ATTRIBUTE10 := NULL;
301 l_activity_rec.ATTRIBUTE11 := NULL;
302 l_activity_rec.ATTRIBUTE12 := NULL;
303 l_activity_rec.ATTRIBUTE13 := NULL;
304 l_activity_rec.ATTRIBUTE14 := NULL;
305 l_activity_rec.ATTRIBUTE15 := NULL;
306 l_activity_rec.OBJECT_VERSION_NUMBER := NULL;
307
308 -- Return the initialized activity record
309 RETURN l_activity_rec;
310 END INIT_ACTIVITY_REC;
311
312 /*-------------------------------------------------------------------------------------*/
313 /* Procedure name: Convert_to_RO_uom */
314 /* Description : Procedure to convert the qty into Repair Order UOM */
315 /* Logistics lines could be created with different UOM than the one on */
316 /* repair order */
317 /* Called from : Called from Update API (SO_RCV_UPDATE,SO_SHIP_UPDATE) */
318 /* */
319 /* STANDARD PARAMETERS */
320 /* In Parameters : */
321 /* */
322 /* Output Parameters: */
323 /* x_return_status VARCHAR2 Return status of the API */
324 /* */
325 /* NON-STANDARD PARAMETERS */
326 /* In Parameters */
327 /* p_to_uom VARCHAR2 Required RO Unit of measure */
328 /* p_item_id NUMBER Required Inventory Item Id */
329 /* p_from_uom VARCHAR2 Conditionaly Required Needed for receiving lines */
330 /* p_from_uom_code VARCHAR2 Conditionaly Required Needed for shipping lines */
331 /* p_from_quantity NUMBER Required Transaction quantity */
332 /* Out parameters */
333 /* x_result_quantity NUMBER converted qty in Repair Order UOM */
334 /* */
335 /* Change Hist : */
336 /* 09/20/03 vlakaman Initial Creation. */
337 /*-------------------------------------------------------------------------------------*/
338
339 Procedure CONVERT_TO_RO_UOM
340 (x_return_status OUT NOCOPY VARCHAR2,
341 p_to_uom_code IN varchar2,
342 p_item_id IN NUMBER,
343 p_from_uom IN varchar2,
344 p_from_uom_code in varchar2,
345 p_from_quantity IN number,
346 x_result_quantity OUT NOCOPY number
347 ) IS
348
349 -- Standard variables
350 l_api_name CONSTANT VARCHAR2(30) := 'CONVERT_TO_RO_UOM';
351 l_api_version CONSTANT NUMBER := 1.0;
352
353 -- Variables used in the API
354 l_from_uom_code mtl_units_of_measure.uom_code%type;
355
356 -- Variables used in FND Log
357 l_error_level number := FND_LOG.LEVEL_ERROR;
358 l_mod_name varchar2(2000) := 'csd.plsql.csd_update_programs_pvt.convert_to_ro_uom';
359
360 BEGIN
361 -- Standard Start of API savepoint
362 SAVEPOINT CONV_TO_RO_UOM;
363
364 -- Initialize API return status to success
365 x_return_status := FND_API.G_RET_STS_SUCCESS;
366
367 -- Api body starts
368 Debug('At the Beginning of Convert_to_RO_uom',l_mod_name,1);
369
370 -- Derive the uom code from uom name
371 IF (NVL(p_from_uom_code, 'ZZZ') = 'ZZZ') THEN
372 Begin
373 select uom_code
374 into l_from_uom_code
375 from mtl_units_of_measure
376 where unit_of_measure = p_from_uom;
377 Exception
378 WHEN NO_DATA_FOUND THEN
379 IF ( l_error_level >= G_debug_level) THEN
380 fnd_message.set_name('CSD','CSD_UOM_MISSING');
381 fnd_message.set_token('UOM',p_from_uom);
382 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
383 ELSE
384 fnd_message.set_name('CSD','CSD_UOM_MISSING');
385 fnd_message.set_token('UOM',p_from_uom);
386 fnd_msg_pub.add;
387 END IF;
388 RAISE FND_API.G_EXC_ERROR;
389 WHEN TOO_MANY_ROWS THEN
390 IF ( l_error_level >= G_debug_level) THEN
391 fnd_message.set_name('CSD','CSD_MANY_UOM_FOUND');
392 fnd_message.set_token('UOM',p_from_uom);
393 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
394 ELSE
395 fnd_message.set_name('CSD','CSD_MANY_UOM_FOUND');
396 fnd_message.set_token('UOM',p_from_uom);
397 fnd_msg_pub.add;
398 END IF;
399 RAISE FND_API.G_EXC_ERROR;
400 End;
401 Else
402 -- assign the uom code if it is passed to the api
403 l_from_uom_code := p_from_uom_code;
404 END IF;
405
406 -- Call the inventory api to convert the quantity
407 -- from one UOM to another UOM.
408 -- Only if the repair order UOM is different than the
409 -- l_from_uom_code, the inv api is called
410 IF p_to_uom_code <> l_from_uom_code THEN
411 x_result_quantity := inv_convert.inv_um_convert(
412 p_item_id ,
413 2,
414 p_from_quantity,
415 l_from_uom_code,
416 p_to_uom_code,
417 null,
418 null);
419
420 -- if the inv_convert api fails then it returns -99999
421 IF x_result_quantity < 0 then
422 IF ( l_error_level >= G_debug_level) THEN
423 fnd_message.set_name('CSD','CSD_INV_UM_CONV_FAILED');
424 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
425 ELSE
426 fnd_message.set_name('CSD','CSD_INV_UM_CONV_FAILED');
427 fnd_msg_pub.add;
428 END IF;
429 RAISE FND_API.G_EXC_ERROR;
430 END IF;
431 ELSE
432 x_result_quantity := p_from_quantity;
433 END IF;
434
435 EXCEPTION
436 WHEN FND_API.G_EXC_ERROR THEN
437 Debug('In FND_API.G_EXC_ERROR exception',l_mod_name,4);
438 ROLLBACK TO CONV_TO_RO_UOM;
439 x_return_status := FND_API.G_RET_STS_ERROR ;
440 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
441 Debug('In FND_API.G_EXC_UNEXPECTED_ERROR exception',l_mod_name,4);
442 ROLLBACK TO CONV_TO_RO_UOM;
443 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
444 WHEN OTHERS THEN
445 Debug('In OTHERS exception',l_mod_name,4);
446 ROLLBACK TO CONV_TO_RO_UOM;
447 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
448 End CONVERT_TO_RO_UOM;
449
450 /*-------------------------------------------------------------------------------------*/
451 /* Procedure name: LOG_ACTIVITY */
452 /* Description : Procedure called for logging activity */
453 /* */
454 /* Called from : Called from all the api */
455 /* STANDARD PARAMETERS */
456 /* In Parameters : */
457 /* p_api_version NUMBER Required Api Version number */
458 /* p_init_msg_list VARCHAR2 Optional To Initialize message stack */
459 /* p_commit VARCHAR2 Optional Commits in API */
460 /* p_validation_level NUMBER Optional validation level */
461 /* */
462 /* Output Parameters: */
463 /* x_return_status VARCHAR2 Return status of the API */
464 /* x_msg_count NUMBER Number of messages in stack */
465 /* x_msg_data VARCHAR2 Error Message from message stack */
466 /* */
467 /* NON-STANDARD PARAMETERS */
468 /* In Parameters */
469 /* p_activity_rec RECORD TYPE Activity record type */
470 /* Output Parameter : */
471 /* Change Hist : */
472 /* 09/20/03 vlakaman Initial Creation. */
473 /*-------------------------------------------------------------------------------------*/
474
475 Procedure LOG_ACTIVITY
476 ( p_api_version IN NUMBER,
477 p_commit IN VARCHAR2,
478 p_init_msg_list IN VARCHAR2,
479 p_validation_level IN NUMBER,
480 x_return_status OUT NOCOPY VARCHAR2,
481 x_msg_count OUT NOCOPY NUMBER,
482 x_msg_data OUT NOCOPY VARCHAR2,
483 p_activity_rec IN activity_rec_type
484 ) IS
485
486 -- Standard Variables
487 l_api_name CONSTANT VARCHAR2(30) := 'LOG_ACTIVITY';
488 l_api_version CONSTANT NUMBER := 1.0;
489
490 -- Variables used in API
491 l_rep_hist_id NUMBER;
492
493 -- Variable used in FND log
494 l_error_level number := FND_LOG.LEVEL_ERROR;
495 l_mod_name varchar2(2000) := 'csd.plsql.csd_update_programs_pvt.log_activity';
496
497 BEGIN
498 -- Standard Start of API savepoint
499 SAVEPOINT LOG_ACTIVITY;
500
501 -- Initialize API return status to success
502 x_return_status := FND_API.G_RET_STS_SUCCESS;
503
504 -- Debug messages
505 Debug('At the beginning of log_activity api',l_mod_name,1);
506
507 -- Standard call to check for call compatibility.
508 IF NOT FND_API.Compatible_API_Call (l_api_version,
509 p_api_version,
510 l_api_name ,
511 G_PKG_NAME )
512 THEN
513 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
514 END IF;
515
516 -- Initialize message list if p_init_msg_list is set to TRUE.
517 IF FND_API.to_Boolean( p_init_msg_list ) THEN
518 FND_MSG_PUB.initialize;
519 END IF;
520
521 -- Debug messages
522 Debug('p_EVENT_CODE ='||p_activity_rec.EVENT_CODE,l_mod_name,1);
523 Debug('p_activity_rec.paramn1 ='||p_activity_rec.paramn1,l_mod_name,1);
524 Debug('p_activity_rec.paramn2 ='||p_activity_rec.paramn2,l_mod_name,1);
525
526 -- need not validate the values passed in activity record
527 -- as these values are validated by the calling API
528 -- If this API is used by other programs, then we need to
529 -- validate the values passed in the activity record
530
531 -- Debug messages
532 Debug('Calling Validate_And_Write',l_mod_name,2);
533
534 -- Since the repair history Id is in/out parameter
535 -- I need to define a variable and pass the variable to API
536 l_rep_hist_id := p_activity_rec.REPAIR_HISTORY_ID;
537
538 -- Calling Validate_And_Write to log activity
539 -- Except for the who columns, all the values from
540 -- p_activity_rec are passed to the Validate_And_Write api.
541 CSD_TO_FORM_REPAIR_HISTORY.Validate_And_Write (
542 P_Api_Version_Number => p_api_version,
543 P_Init_Msg_List => p_init_msg_list,
544 P_Commit => p_commit,
545 p_validation_level => null, --p_validation_level,
546 p_action_code => p_activity_rec.action_code,
547 px_REPAIR_HISTORY_ID => l_rep_hist_id,
548 p_OBJECT_VERSION_NUMBER => p_activity_rec.object_version_number,
549 p_REQUEST_ID => p_activity_rec.request_id,
550 p_PROGRAM_ID => p_activity_rec.program_id,
551 p_PROGRAM_APPLICATION_ID => p_activity_rec.program_application_id,
552 p_PROGRAM_UPDATE_DATE => p_activity_rec.program_update_date,
553 p_CREATED_BY => fnd_global.user_id,
554 p_CREATION_DATE => sysdate,
555 p_LAST_UPDATED_BY => fnd_global.user_id,
556 p_LAST_UPDATE_DATE => sysdate,
557 p_REPAIR_LINE_ID => p_activity_rec.repair_line_id,
558 p_EVENT_CODE => p_activity_rec.event_code,
559 p_EVENT_DATE => p_activity_rec.event_date,
560 p_QUANTITY => p_activity_rec.quantity,
561 p_PARAMN1 => p_activity_rec.paramn1,
562 p_PARAMN2 => p_activity_rec.paramn2,
563 p_PARAMN3 => p_activity_rec.paramn3,
564 p_PARAMN4 => p_activity_rec.paramn4,
565 p_PARAMN5 => p_activity_rec.paramn5,
566 p_PARAMN6 => p_activity_rec.paramn6,
567 p_PARAMN7 => p_activity_rec.paramn7,
568 p_PARAMN8 => p_activity_rec.paramn8,
569 p_PARAMN9 => p_activity_rec.paramn9,
570 p_PARAMN10 => p_activity_rec.paramn10,
571 p_PARAMC1 => p_activity_rec.paramc1,
572 p_PARAMC2 => p_activity_rec.paramc2,
573 p_PARAMC3 => p_activity_rec.paramc3,
574 p_PARAMC4 => p_activity_rec.paramc4,
575 p_PARAMC5 => p_activity_rec.paramc5,
576 p_PARAMC6 => p_activity_rec.paramc6,
577 p_PARAMC7 => p_activity_rec.paramc7,
578 p_PARAMC8 => p_activity_rec.paramc8,
579 p_PARAMC9 => p_activity_rec.paramc9,
580 p_PARAMC10 => p_activity_rec.paramc10,
581 p_PARAMD1 => p_activity_rec.paramd1,
582 p_PARAMD2 => p_activity_rec.paramd2,
583 p_PARAMD3 => p_activity_rec.paramd3,
584 p_PARAMD4 => p_activity_rec.paramd4,
585 p_PARAMD5 => p_activity_rec.paramd5,
586 p_PARAMD6 => p_activity_rec.paramd6,
587 p_PARAMD7 => p_activity_rec.paramd7,
588 p_PARAMD8 => p_activity_rec.paramd8,
589 p_PARAMD9 => p_activity_rec.paramd9,
590 p_PARAMD10 => p_activity_rec.paramd10,
591 p_ATTRIBUTE_CATEGORY => p_activity_rec.attribute_category,
592 p_ATTRIBUTE1 => p_activity_rec.attribute1,
593 p_ATTRIBUTE2 => p_activity_rec.attribute2,
594 p_ATTRIBUTE3 => p_activity_rec.attribute3,
595 p_ATTRIBUTE4 => p_activity_rec.attribute4,
596 p_ATTRIBUTE5 => p_activity_rec.attribute5,
597 p_ATTRIBUTE6 => p_activity_rec.attribute6,
598 p_ATTRIBUTE7 => p_activity_rec.attribute7,
599 p_ATTRIBUTE8 => p_activity_rec.attribute8,
600 p_ATTRIBUTE9 => p_activity_rec.attribute9,
601 p_ATTRIBUTE10 => p_activity_rec.attribute10,
602 p_ATTRIBUTE11 => p_activity_rec.attribute11,
603 p_ATTRIBUTE12 => p_activity_rec.attribute12,
604 p_ATTRIBUTE13 => p_activity_rec.attribute13,
605 p_ATTRIBUTE14 => p_activity_rec.attribute14,
606 p_ATTRIBUTE15 => p_activity_rec.attribute15,
607 p_LAST_UPDATE_LOGIN => null,
608 X_Return_Status => x_return_status,
609 X_Msg_Count => x_msg_count,
610 X_Msg_Data => x_msg_data );
611
612 -- Debug messages
613 Debug('x_return_status from Validate_And_Write ='||x_return_status,l_mod_name,2);
614
615 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
616 Debug('Validate_And_Write api failed ',l_mod_name,4);
617 RAISE FND_API.G_EXC_ERROR;
618 END IF;
619
620 -- Standard check of p_commit.
621 IF FND_API.To_Boolean( p_commit ) THEN
622 COMMIT WORK;
623 END IF;
624
625 -- Standard call to get message count and IF count is get message info.
626 FND_MSG_PUB.Count_And_Get
627 (p_count => x_msg_count,
628 p_data => x_msg_data );
629 EXCEPTION
630 WHEN FND_API.G_EXC_ERROR THEN
631 Debug('In FND_API.G_EXC_ERROR exception',l_mod_name,4);
632 ROLLBACK TO LOG_ACTIVITY;
633 x_return_status := FND_API.G_RET_STS_ERROR ;
634 FND_MSG_PUB.Count_And_Get
635 (p_count => x_msg_count,
636 p_data => x_msg_data );
637 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
638 Debug('In FND_API.G_EXC_UNEXPECTED_ERROR exception',l_mod_name,4);
639 ROLLBACK TO LOG_ACTIVITY;
640 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
641 FND_MSG_PUB.Count_And_Get
642 ( p_count => x_msg_count,
643 p_data => x_msg_data );
644 WHEN OTHERS THEN
645 Debug('In OTHERS exception',l_mod_name,4 );
646 ROLLBACK TO LOG_ACTIVITY;
647 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
648 IF FND_MSG_PUB.Check_Msg_Level
649 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
650 THEN
651 FND_MSG_PUB.Add_Exc_Msg
652 (G_PKG_NAME ,
653 l_api_name );
654 END IF;
655 FND_MSG_PUB.Count_And_Get
656 (p_count => x_msg_count,
657 p_data => x_msg_data );
658 END LOG_ACTIVITY;
659
660 /*-------------------------------------------------------------------------------------*/
661 /* Procedure name: JOB_COMPLETION_UPDATE */
662 /* Description : Procedure called from wip_update API to update the completed qty */
663 /* It also logs activity for the job completion */
664 /* Called from : Called from WIP_Update API */
665 /* STANDARD PARAMETERS */
666 /* In Parameters : */
667 /* p_api_version NUMBER Required Api Version number */
668 /* p_init_msg_list VARCHAR2 Optional To Initialize message stack */
669 /* p_commit VARCHAR2 Optional Commits in API */
670 /* p_validation_level NUMBER Optional validation level */
671 /* */
672 /* Output Parameters: */
673 /* x_return_status VARCHAR2 Return status of the API */
674 /* x_msg_count NUMBER Number of messages in stack */
675 /* x_msg_data VARCHAR2 Error Message from message stack */
676 /* */
677 /* NON-STANDARD PARAMETERS */
678 /* In Parameters */
679 /* p_repair_line_id NUMBER Optional Repair Order Line Id */
680 /* Output Parm : */
681 /* Change Hist : */
682 /* 09/20/03 vlakaman Initial Creation. */
683 /*-------------------------------------------------------------------------------------*/
684
685 Procedure JOB_COMPLETION_UPDATE
686 ( p_api_version IN NUMBER,
687 p_commit IN VARCHAR2,
688 p_init_msg_list IN VARCHAR2,
689 p_validation_level IN NUMBER,
690 x_return_status OUT NOCOPY VARCHAR2,
691 x_msg_count OUT NOCOPY NUMBER,
692 x_msg_data OUT NOCOPY VARCHAR2,
693 p_repair_line_id IN NUMBER
694 ) IS
695
696 -- Standard Variables
697 l_api_name CONSTANT VARCHAR2(30) := 'WIP_UPDATE';
698 l_api_version CONSTANT NUMBER := 1.0;
699
700 -- Variables used in the program
701 l_rep_hist_id NUMBER;
702 l_total_rec NUMBER:= 0;
703 l_completed_qty NUMBER;
704 l_remaining_qty NUMBER;
705 l_total_qty NUMBER;
706 l_update_qty NUMBER;
707 l_count NUMBER;
708 l_dummy varchar2(30);
709 l_commit_size NUMBER := 500;
710 l_msg_text VARCHAR2(2000);
711 l_mtl_trx_id NUMBER;
712 l_mtl_trx_date DATE;
713 l_mtl_serial_num mtl_unit_transactions.serial_number%type;
714 l_mtl_subinv mtl_material_transactions.subinventory_code%type;
715 l_SN_mismatch BOOLEAN := FALSE;
716
717 l_ro_count NUMBER ; ---Added by vijay to put ro count in JC event
718
719 -- Define a record of activity_rec_type
720 l_activity_rec activity_rec_type;
721
722 -- Variable used in FND log
723 l_error_level number := FND_LOG.LEVEL_ERROR;
724 l_mod_name varchar2(2000) := 'csd.plsql.csd_update_programs_pvt.job_completion_update';
725
726 -- User defined exception
727 SKIP_RECORD EXCEPTION;
728
729 -- This cursor gets all the records in csd_repair_job_xref for which
730 -- the completed qty is less than the allocated
731 -- for the given repair line id, 11/9/04: Vijay
732 Cursor REPAIR_JOBS( p_rep_line_id in number )IS
733 SELECT
734 crj.repair_job_xref_id,
735 crj.wip_entity_id,
736 crj.repair_line_id,
737 crj.quantity_completed allocated_comp_qty,
738 crj.quantity allocated_job_qty,
739 crj.organization_id,
740 cra.repair_number,
741 cra.promise_date,
742 cra.serial_number ro_serial_num,
743 cra.inventory_item_id ro_item_id,
744 wdj.quantity_completed job_completed_qty,
745 wdj.start_quantity job_qty,
746 wdj.date_completed,
747 wdj.primary_item_id job_item_id,
748 we.wip_entity_name,
749 mtl.serial_number_control_code
750 from CSD_REPAIR_JOB_XREF crj,
751 CSD_REPAIRS cra,
752 WIP_DISCRETE_JOBS wdj,
753 WIP_ENTITIES we,
754 MTL_SYSTEM_ITEMS mtl
755 where wdj.wip_entity_id = crj.wip_entity_id
756 and we.wip_entity_id = wdj.wip_entity_id
757 and crj.repair_line_id = cra.repair_line_id
758 and crj.organization_id = mtl.organization_id
759 and crj.inventory_item_id = mtl.inventory_item_id
760 and (crj.quantity - nvl(crj.quantity_completed,0)) > 0
761 and cra.repair_line_id = p_rep_line_id
762 and nvl(wdj.quantity_completed,0) > 0
763 order by crj.wip_entity_id, cra.promise_date;
764
765 -- This cursor gets all the records in csd_repair_job_xref for which
766 -- the completed qty is less than the allocated
767 -- all records irrespective of rep_line_id 11/9/04: Vijay
768 Cursor REPAIR_JOBS_ALL IS
769 SELECT
770 crj.repair_job_xref_id,
771 crj.wip_entity_id,
772 crj.repair_line_id,
773 crj.quantity_completed allocated_comp_qty,
774 crj.quantity allocated_job_qty,
775 crj.organization_id,
776 cra.repair_number,
777 cra.promise_date,
778 cra.serial_number ro_serial_num,
779 cra.inventory_item_id ro_item_id,
780 wdj.quantity_completed job_completed_qty,
781 wdj.start_quantity job_qty,
782 wdj.date_completed,
783 wdj.primary_item_id job_item_id,
784 we.wip_entity_name,
785 mtl.serial_number_control_code
786 from CSD_REPAIR_JOB_XREF crj,
787 CSD_REPAIRS cra,
788 WIP_DISCRETE_JOBS wdj,
789 WIP_ENTITIES we,
790 MTL_SYSTEM_ITEMS mtl
791 where wdj.wip_entity_id = crj.wip_entity_id
792 and we.wip_entity_id = wdj.wip_entity_id
793 and crj.repair_line_id = cra.repair_line_id
794 and crj.organization_id = mtl.organization_id
795 and crj.inventory_item_id = mtl.inventory_item_id
796 and (crj.quantity - nvl(crj.quantity_completed,0)) > 0
797 and nvl(wdj.quantity_completed,0) > 0
798 order by crj.wip_entity_id, cra.promise_date;
799
800 -- Added by Vijay 11/9/04
801 JOB JOB_COMPLETION_REC_TYPE;
802
803
804 -- This cursor gets all the material txns for the wip_entity_id
805 -- WIP Completion Txn Types has transaction_action_id=31
806 -- and transaction_source_type_id = 5
807 Cursor Get_mtl_txns (p_entity_id in number) IS
808 select subinventory_code,
809 transaction_quantity,
810 transaction_id,
811 transaction_date
812 from mtl_material_transactions mtl
813 where mtl.transaction_source_id = p_entity_id
814 and mtl.transaction_source_type_id = 5 -- Job or Schedule
815 and mtl.transaction_action_id = 31;-- Wip Assembly Completion
816
817
818 BEGIN
819 -- Standard Start of API savepoint
820 SAVEPOINT JOB_COMPLETION_UPDATE;
821
822 -- Initialize API return status to success
823 x_return_status := FND_API.G_RET_STS_SUCCESS;
824
825 -- Debug messages
826 Debug('At the Beginning of JOB_COMPLETION_UPDATE',l_mod_name,1);
827
828 -- Standard call to check for call compatibility.
829 IF NOT FND_API.Compatible_API_Call (l_api_version,
830 p_api_version,
831 l_api_name ,
832 G_PKG_NAME )
833 THEN
834 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
835 END IF;
836
837 -- Initialize message list if p_init_msg_list is set to TRUE.
838 IF FND_API.to_Boolean( p_init_msg_list ) THEN
839 FND_MSG_PUB.initialize;
840 END IF;
841
842 -- Keep the record count
843 l_count := 0;
844
845 -- Code does not handle the following scenarios
846 -- 1. Cancelled WIP Job
847 -- Eric is going to check why a Job is cancelled. Based on that
848 -- a course of action will be taken
849 -- 2. Overcompletion
850 -- It has decided to ignore the overcompleted quantity
851 -- 3. Return to WIP Job after completion
852 -- It needs to be handled asap
853 -- It will be discussed with PM and done as phase II project
854
855 -- Get all the records that have job completed
856 --FOR JOB in Repair_Jobs( p_repair_line_id )
857 IF(p_repair_line_Id is null) THEN
858 OPEN Repair_Jobs_ALL;
859 ELSE
860 OPEN Repair_Jobs(p_repair_line_id);
861 END IF;
862
863 LOOP
864 BEGIN
865
866 IF(p_repair_line_Id is null) THEN
867 FETCH Repair_Jobs_ALL INTO Job;
868 EXIT WHEN Repair_Jobs_ALL%NOTFOUND;
869 ELSE
870 FETCH Repair_Jobs INTO Job;
871 EXIT WHEN Repair_Jobs%NOTFOUND;
872 END IF;
873 -- savepoint
874 SAVEPOINT Job_Completion;
875
876 -- Debug messages
877 Debug('wip_entity_id ='||TO_CHAR(job.wip_entity_id),l_mod_name,1);
878 Debug('repair_line_id ='||TO_CHAR(job.repair_line_id),l_mod_name,1);
879 Debug('quantity_completed ='||TO_CHAR(job.job_completed_qty),l_mod_name,1);
880 Debug('quantity ='||TO_CHAR(job.job_qty),l_mod_name,1);
881
882 --Get the sum of completed quantity from csd_repair_job_xref
883 select nvl(sum(quantity_completed),0), count(repair_line_id) ---Added by vijay
884 into l_completed_qty, l_ro_count ----------------------------to put ro count in JC event
885 from csd_repair_job_xref
886 where wip_entity_id = JOB.wip_entity_id;
887
888 l_ro_count := nvl(l_ro_Count,0); --Added by vijay to put ro count in JC event
889
890 -- Calculate the remaining qty to be processed
891 -- Using NVL in SQL statement is much expensive than in a variable
892 l_remaining_qty := nvl(JOB.job_completed_qty,0) - l_completed_qty;
893
894 -- Debug messages
895 Debug('l_remaining_qty ='||TO_CHAR(l_remaining_qty),l_mod_name,1);
896 Debug('l_completed_qty ='||TO_CHAR(l_completed_qty),l_mod_name,1);
897
898 -- Using NVL in SQL statement is much expensive than in a variable
899 IF ((nvl(JOB.allocated_job_qty,0) - nvl(JOB.allocated_comp_qty,0)) <= l_remaining_qty) then
900 l_remaining_qty := (nvl(JOB.allocated_job_qty,0) - nvl(JOB.allocated_comp_qty,0)) ;
901 END IF;
902
903 -- Debug messages
904 Debug('l_remaining_qty ='||TO_CHAR(l_remaining_qty),l_mod_name,1);
905 Debug('Serial Num Control Code='||JOB.serial_number_control_code,l_mod_name,1);
906
907 -- Only if the remaining qty > 0 then process the record
908 -- It needs to be processed differently depending on the item definition
909 -- 1. Serialized at inventory receipt and Pre-defined
910 -- 2. Non-Serialized and Serial Control at sales order issue
911 --
912 -- If the item is pre-defined or at inventory receipt, the serial number
913 -- is entered while completing the job. The serial number is stored in
914 -- mtl_unit_transactions table. So the serial number can be matched to
915 -- the serial number on repair order and the repair order is updated
916 -- with the completed qty. But if the wip job is for upgrade, then the
917 -- repair order item is different then the item on the WIP job. So if
918 -- it is upgrade then the completion qty is updated based on the
919 -- promise date
920 --
921 -- If the item is non-serialized and serialized at SO issue then
922 -- the completion qty is updated based on the promise date
923
924 IF l_remaining_qty > 0 then
925 IF JOB.serial_number_control_code in (2,5) THEN
926 -- Serialized at inventory receipt and Pre-defined
927 -- In WIP_DISCRETE_JOBS
928 -- Job Name Job Id Start Qty Completion Qty Completion Subinv
929 -- W1 1121 10 10
930 --
931 -- MTL_MATERIAL_TRANSACTIONS
932 -- Txn Id Job ID Txn Qty Completion Subinv
933 -- M1 1121 2 FGI
934 -- M2 1121 8 Stores
935 --
936 -- MTL_UNIT_TRANSACTIONS
937 --
938 -- Txn Id Serial Number Subinv
939 -- M1 SN1 FGI
940 -- M2 SN2 FGI
941 -- . .
942 -- M10 SN10 Stores
943 -- The wip job is created for the same item on the repair order
944 -- It is not an upgrade
945 IF JOB.ro_item_id = JOB.job_item_id THEN
946 BEGIN
947 Select mt.transaction_id,
948 mt.transaction_date,
949 mt.subinventory_code
950 into l_mtl_trx_id,
951 l_mtl_trx_date,
952 l_mtl_subinv
953 from mtl_material_transactions mt,
954 mtl_unit_transactions mut
955 where mt.transaction_id = mut.transaction_id
956 and mt.transaction_source_id = JOB.wip_entity_id
957 and mt.transaction_source_type_id = 5 -- Job or Schedule
958 and mt.transaction_action_id = 31 -- Wip Assembly Completion
959 and mut.serial_number = JOB.ro_serial_num
960 and mt.inventory_item_id = JOB.ro_item_id;
961
962 -- Update csd_repair_job_xref with qty completed
963 update csd_repair_job_xref
964 set quantity_completed = nvl(quantity_completed,0) + 1,
965 object_version_number = object_version_number+1,
966 last_update_date = sysdate,
967 last_updated_by = fnd_global.user_id,
968 last_update_login = fnd_global.login_id
969 where repair_job_xref_id = JOB.repair_job_xref_id;
970 IF SQL%NOTFOUND THEN
971 IF ( l_error_level >= G_debug_level) THEN
972 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_XREF_UPD_FAILED');
973 FND_MESSAGE.SET_TOKEN('REP_JOB_XREF_ID',JOB.repair_job_xref_id );
974 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
975 ELSE
976 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_XREF_UPD_FAILED');
977 FND_MESSAGE.SET_TOKEN('REP_JOB_XREF_ID',JOB.repair_job_xref_id );
978 FND_MSG_PUB.ADD;
979 END IF;
980 RAISE FND_API.G_EXC_ERROR;
981 End IF;
982
983 -- Initialize the activity rec
984 l_activity_rec := INIT_ACTIVITY_REC ;
985
986 -- Assign the values for activity record
987 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
988 l_activity_rec.REPAIR_LINE_ID := JOB.repair_line_id;
989 l_activity_rec.EVENT_CODE := 'JC';
990 l_activity_rec.ACTION_CODE := 0;
991 l_activity_rec.EVENT_DATE := l_mtl_trx_date;
992 l_activity_rec.QUANTITY := JOB.job_completed_qty;
993 l_activity_rec.PARAMN1 := JOB.organization_id;
994 l_activity_rec.PARAMN3 := l_mtl_trx_id;
995 l_activity_rec.PARAMN4 := JOB.wip_entity_id;
996 l_activity_rec.PARAMN5 := 1;
997 l_activity_rec.PARAMN6 := l_ro_count;
998 l_activity_rec.PARAMC1 := l_mtl_subinv;
999 l_activity_rec.PARAMC2 := JOB.wip_entity_name;
1000 l_activity_rec.PARAMC3 := JOB.ro_serial_num;
1001 l_activity_rec.OBJECT_VERSION_NUMBER := null;
1002
1003 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
1004
1005 -- Calling LOG_ACTIVITY for logging activity
1006 -- for job completion
1007 LOG_ACTIVITY
1008 ( p_api_version => p_api_version,
1009 p_commit => p_commit,
1010 p_init_msg_list => p_init_msg_list,
1011 p_validation_level => p_validation_level,
1012 x_return_status => x_return_status,
1013 x_msg_count => x_msg_count,
1014 x_msg_data => x_msg_data,
1015 p_activity_rec => l_activity_rec );
1016
1017 Debug('x_return_status from LOG_ACTIVITY ='||x_return_status,l_mod_name,2);
1018 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
1019 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
1020 RAISE FND_API.G_EXC_ERROR;
1021 END IF;
1022 l_SN_mismatch := FALSE;
1023 EXCEPTION
1024 WHEN NO_DATA_FOUND THEN
1025 l_SN_mismatch := TRUE;
1026 END;
1027
1028 -- While issuing the assembly to WIP Job, user could issue
1029 -- a wrong serial number. So that could result in mismatch
1030 -- of serial number
1031 -- Repair Job XRef
1032 -- RO Num Item Qty Job Serial Num
1033 -- R1 A 1 W1 Sn1
1034 -- R2 A 1 W1 Sn2
1035 -- R3 A 1 W1 Sn3
1036 --
1037 -- Wip Discrete Jobs
1038 -- Job Start Qty Comp Qty
1039 -- W1 3 3
1040 --
1041 -- MTL Material Transactions
1042 -- Mtl Txn Id Txn Qty SubInv
1043 -- M1 2 FGI
1044 -- M2 1 Stores
1045 -- MTL Unit Txns
1046 -- Mtl Txn Id Serial Num
1047 -- M1 Sn2
1048 -- M1 Sn9
1049 -- M2 Sn11
1050 -- It needs to be matched in the following manner
1051 -- RO Num RO Serial Num Comp Serial Num
1052 -- R1 Sn1 Sn9
1053 -- R2 Sn2 Sn2
1054 -- R3 Sn3 Sn11
1055 IF l_SN_mismatch THEN
1056 BEGIN
1057 Select mt.transaction_id,
1058 mt.transaction_date,
1059 mut.serial_number,
1060 mt.subinventory_code
1061 into l_mtl_trx_id,
1062 l_mtl_trx_date,
1063 l_mtl_serial_num,
1064 l_mtl_subinv
1065 from mtl_material_transactions mt,
1066 mtl_unit_transactions mut
1067 where mt.transaction_id = mut.transaction_id
1068 and mt.transaction_source_id = JOB.wip_entity_id
1069 and mt.transaction_source_type_id = 5 -- Job or Schedule
1070 and mt.transaction_action_id = 31 -- Wip Assembly Completion
1071 and mut.serial_number not in (select crh.paramc3
1072 from csd_repair_history crh,
1073 csd_repair_job_xref crj
1074 where crh.repair_line_id = crj.repair_line_id
1075 and crj.wip_entity_id = JOB.wip_entity_id
1076 and crh.event_code = 'JC')
1077 and mut.serial_number not in (Select cra.serial_number
1078 from csd_repairs cra,
1079 csd_repair_job_xref crj
1080 where cra.repair_line_id = crj.repair_line_id
1081 and crj.wip_entity_id = JOB.wip_entity_id
1082 and cra.serial_number is not null)
1083 and rownum = 1;
1084
1085 -- Update csd_repair_job_xref with qty completed
1086 update csd_repair_job_xref
1087 set quantity_completed = nvl(quantity_completed,0) + 1,
1088 object_version_number = object_version_number+1,
1089 last_update_date = sysdate,
1090 last_updated_by = fnd_global.user_id,
1091 last_update_login = fnd_global.login_id
1092 where repair_job_xref_id = JOB.repair_job_xref_id;
1093 IF SQL%NOTFOUND THEN
1094 IF ( l_error_level >= G_debug_level) THEN
1095 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_XREF_UPD_FAILED');
1096 FND_MESSAGE.SET_TOKEN('REP_JOB_XREF_ID',JOB.repair_job_xref_id );
1097 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
1098 ELSE
1099 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_XREF_UPD_FAILED');
1100 FND_MESSAGE.SET_TOKEN('REP_JOB_XREF_ID',JOB.repair_job_xref_id );
1101 FND_MSG_PUB.ADD;
1102 END IF;
1103 RAISE FND_API.G_EXC_ERROR;
1104 End IF;
1105
1106 -- Initialize the activity rec
1107 l_activity_rec := INIT_ACTIVITY_REC ;
1108
1109 -- Assign the values for activity record
1110 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
1111 l_activity_rec.REPAIR_LINE_ID := JOB.repair_line_id;
1112 l_activity_rec.EVENT_CODE := 'JCA';
1113 l_activity_rec.ACTION_CODE := 0;
1114 l_activity_rec.EVENT_DATE := l_mtl_trx_date;
1115 l_activity_rec.QUANTITY := null;
1116 l_activity_rec.PARAMN1 := JOB.organization_id;
1117 l_activity_rec.PARAMN3 := l_mtl_trx_id;
1118 l_activity_rec.PARAMN4 := JOB.wip_entity_id;
1119 l_activity_rec.PARAMN6 := l_ro_count;
1120 l_activity_rec.PARAMC1 := l_mtl_serial_num ;
1121 l_activity_rec.PARAMC2 := JOB.ro_serial_num ;
1122 l_activity_rec.OBJECT_VERSION_NUMBER := null;
1123
1124 Debug('Calling LOG_ACTIVITY ',l_mod_name,2);
1125 -- Calling LOG_ACTIVITY for logging activity
1126 -- When the completed serial number does not match
1127 -- with the repair order serial number
1128 LOG_ACTIVITY
1129 ( p_api_version => p_api_version,
1130 p_commit => p_commit,
1131 p_init_msg_list => p_init_msg_list,
1132 p_validation_level => p_validation_level,
1133 x_return_status => x_return_status,
1134 x_msg_count => x_msg_count,
1135 x_msg_data => x_msg_data,
1136 p_activity_rec => l_activity_rec );
1137
1138 Debug('x_return_status from LOG_ACTIVITY ='||x_return_status,l_mod_name,2);
1139 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
1140 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
1141 RAISE FND_API.G_EXC_ERROR;
1142 END IF;
1143
1144
1145 -- Initialize the activity rec
1146 l_activity_rec := INIT_ACTIVITY_REC ;
1147
1148 -- Assign the values for activity record
1149 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
1150 l_activity_rec.REPAIR_LINE_ID := JOB.repair_line_id;
1151 l_activity_rec.EVENT_CODE := 'JC';
1152 l_activity_rec.ACTION_CODE := 0;
1153 l_activity_rec.EVENT_DATE := l_mtl_trx_date;
1154 l_activity_rec.QUANTITY := JOB.job_completed_qty;
1155 l_activity_rec.PARAMN1 := JOB.organization_id;
1156 l_activity_rec.PARAMN3 := l_mtl_trx_id;
1157 l_activity_rec.PARAMN4 := JOB.wip_entity_id;
1158 l_activity_rec.PARAMN5 := 1;
1159 l_activity_rec.PARAMN6 := l_ro_count;
1160 l_activity_rec.PARAMC1 := l_mtl_subinv;
1161 l_activity_rec.PARAMC2 := JOB.wip_entity_name;
1162 l_activity_rec.PARAMC3 := l_mtl_serial_num;
1163 l_activity_rec.OBJECT_VERSION_NUMBER := null;
1164
1165 Debug('Calling LOG_ACTIVITY ',l_mod_name,2);
1166 -- Calling LOG_ACTIVITY for logging activity
1167 -- for job completion
1168 LOG_ACTIVITY
1169 ( p_api_version => p_api_version,
1170 p_commit => p_commit,
1171 p_init_msg_list => p_init_msg_list,
1172 p_validation_level => p_validation_level,
1173 x_return_status => x_return_status,
1174 x_msg_count => x_msg_count,
1175 x_msg_data => x_msg_data,
1176 p_activity_rec => l_activity_rec );
1177
1178 Debug('x_return_status from LOG_ACTIVITY ='||x_return_status,l_mod_name,2);
1179 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
1180 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
1181 RAISE FND_API.G_EXC_ERROR;
1182 END IF;
1183
1184 EXCEPTION
1185 WHEN NO_DATA_FOUND THEN
1186 NULL;
1187 END;
1188
1189 END IF;
1190
1191 ELSE
1192 -- In case of upgrade, the wip job is submitted for the upgraded item,
1193 -- which is different then the item on the repair order
1194 BEGIN
1195 Select mt.transaction_id,
1196 mt.transaction_date,
1197 mut.serial_number,
1198 mt.subinventory_code
1199 into l_mtl_trx_id,
1200 l_mtl_trx_date,
1201 l_mtl_serial_num,
1202 l_mtl_subinv
1203 from mtl_material_transactions mt,
1204 mtl_unit_transactions mut
1205 where mt.transaction_id = mut.transaction_id
1206 and mt.transaction_source_id = JOB.wip_entity_id
1207 and mt.transaction_source_type_id = 5 -- Job or Schedule
1208 and mt.transaction_action_id = 31 -- Wip Assembly Completion
1209 and mut.serial_number not in (select crh.paramc3
1210 from csd_repair_history crh,
1211 csd_repair_job_xref crj
1212 where crh.repair_line_id = crj.repair_line_id
1213 and crj.wip_entity_id = JOB.wip_entity_id
1214 and crh.event_code = 'JC')
1215 and rownum = 1;
1216
1217 -- Update csd_repair_job_xref with qty completed
1218 update csd_repair_job_xref
1219 set quantity_completed = nvl(quantity_completed,0) + 1,
1220 object_version_number = object_version_number+1,
1221 last_update_date = sysdate,
1222 last_updated_by = fnd_global.user_id,
1223 last_update_login = fnd_global.login_id
1224 where repair_job_xref_id = JOB.repair_job_xref_id;
1225 IF SQL%NOTFOUND THEN
1226 IF ( l_error_level >= G_debug_level) THEN
1227 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_XREF_UPD_FAILED');
1228 FND_MESSAGE.SET_TOKEN('REP_JOB_XREF_ID',JOB.repair_job_xref_id );
1229 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
1230 ELSE
1231 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_XREF_UPD_FAILED');
1232 FND_MESSAGE.SET_TOKEN('REP_JOB_XREF_ID',JOB.repair_job_xref_id );
1233 FND_MSG_PUB.ADD;
1234 END IF;
1235 RAISE FND_API.G_EXC_ERROR;
1236 End IF;
1237
1238 -- Initialize the activity rec
1239 l_activity_rec := INIT_ACTIVITY_REC ;
1240
1241 -- Assign the values for activity record
1242 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
1243 l_activity_rec.REPAIR_LINE_ID := JOB.repair_line_id;
1244 l_activity_rec.EVENT_CODE := 'JC';
1245 l_activity_rec.ACTION_CODE := 0;
1246 l_activity_rec.EVENT_DATE := l_mtl_trx_date;
1247 l_activity_rec.QUANTITY := JOB.job_completed_qty;
1248 l_activity_rec.PARAMN1 := JOB.organization_id;
1249 l_activity_rec.PARAMN3 := l_mtl_trx_id;
1250 l_activity_rec.PARAMN4 := JOB.wip_entity_id;
1251 l_activity_rec.PARAMN5 := 1;
1252 l_activity_rec.PARAMN6 := l_ro_count;
1253 l_activity_rec.PARAMC1 := l_mtl_subinv;
1254 l_activity_rec.PARAMC2 := JOB.wip_entity_name;
1255 l_activity_rec.PARAMC3 := l_mtl_serial_num;
1256 l_activity_rec.OBJECT_VERSION_NUMBER := null;
1257
1258 Debug('Calling LOG_ACTIVITY ',l_mod_name,2);
1259 -- Calling LOG_ACTIVITY for logging activity
1260 -- for job completion
1261 LOG_ACTIVITY
1262 ( p_api_version => p_api_version,
1263 p_commit => p_commit,
1264 p_init_msg_list => p_init_msg_list,
1265 p_validation_level => p_validation_level,
1266 x_return_status => x_return_status,
1267 x_msg_count => x_msg_count,
1268 x_msg_data => x_msg_data,
1269 p_activity_rec => l_activity_rec );
1270
1271 Debug('x_return_status from LOG_ACTIVITY ='||x_return_status,l_mod_name,2);
1272 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
1273 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
1274 RAISE FND_API.G_EXC_ERROR;
1275 END IF;
1276
1277 EXCEPTION
1278 WHEN NO_DATA_FOUND THEN
1279 IF ( l_error_level >= G_debug_level) THEN
1280 FND_MESSAGE.SET_NAME('CSD','CSD_INV_WIP_ENTITY_ID');
1281 FND_MESSAGE.SET_TOKEN('WIP_ENTITY_ID',JOB.wip_entity_id );
1282 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
1283 ELSE
1284 FND_MESSAGE.SET_NAME('CSD','CSD_INV_WIP_ENTITY_ID');
1285 FND_MESSAGE.SET_TOKEN('WIP_ENTITY_ID',JOB.wip_entity_id );
1286 FND_MSG_PUB.ADD;
1287 END IF;
1288 RAISE FND_API.G_EXC_ERROR;
1289 END;
1290 END IF;
1291
1292 ELSE
1293 -- This scenario is for the serialized item at sales order issue and non-serialized
1294 -- In WIP_DISCRETE_JOBS
1295 -- Job Name Job Id Start Qty Completion Qty Completion Subinv
1296 -- W1 1121 10 10
1297 --
1298 -- MTL_MATERIAL_TRANSACTIONS
1299 -- Txn Id Job ID Txn Qty Completion Subinv
1300 -- M1 1121 2 FGI
1301 -- M2 1121 8 Stores
1302 FOR MTL in Get_mtl_txns(JOB.wip_entity_id)
1303 LOOP
1304 BEGIN
1305 -- Debug messages
1306 Debug('l_remaining_qty ='||TO_CHAR(l_remaining_qty),l_mod_name,1);
1307 IF l_remaining_qty <= 0 then
1308 -- exit the loop if nothing to process
1309 Exit;
1310 ELSE
1311 SELECT nvl(SUM(paramn5),0)
1312 INTO l_total_qty
1313 FROM CSD_REPAIR_HISTORY
1314 WHERE paramn3 = MTL.transaction_id
1315 AND paramn4 = JOB.wip_entity_id
1316 AND event_Code= 'JC';
1317
1318 -- Debug messages
1319 Debug('l_total_qty ='||TO_CHAR(l_total_qty),l_mod_name,1);
1320
1321 IF (nvl(MTL.transaction_quantity,0) - l_total_qty)> 0 THEN
1322 If (l_remaining_qty > (nvl(MTL.transaction_quantity,0) - l_total_qty)) then
1323 l_remaining_qty := l_remaining_qty - (nvl(MTL.transaction_quantity,0) - l_total_qty);
1324 l_update_qty := (nvl(MTL.transaction_quantity,0) - l_total_qty);
1325 ELSE
1326 l_update_Qty := l_remaining_qty;
1327 l_remaining_qty := 0;
1328 END IF;
1329
1330 -- Debug messages
1331 Debug('l_update_Qty ='||TO_CHAR(l_update_Qty),l_mod_name,1);
1332 Debug('l_remaining_qty ='||TO_CHAR(l_remaining_qty),l_mod_name,1);
1333
1334 -- Update csd_repair_job_xref with qty completed
1335 update csd_repair_job_xref
1336 set quantity_completed = nvl(quantity_completed,0) + NVL(l_update_qty,0),
1337 object_version_number = object_version_number+1,
1338 last_update_date = sysdate,
1339 last_updated_by = fnd_global.user_id,
1340 last_update_login = fnd_global.login_id
1341 where repair_job_xref_id = JOB.repair_job_xref_id;
1342 IF SQL%NOTFOUND THEN
1343 IF ( l_error_level >= G_debug_level) THEN
1344 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_XREF_UPD_FAILED');
1345 FND_MESSAGE.SET_TOKEN('REP_JOB_XREF_ID',JOB.repair_job_xref_id );
1346 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
1347 ELSE
1348 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_XREF_UPD_FAILED');
1349 FND_MESSAGE.SET_TOKEN('REP_JOB_XREF_ID',JOB.repair_job_xref_id );
1350 FND_MSG_PUB.ADD;
1351 END IF;
1352 RAISE FND_API.G_EXC_ERROR;
1353 End IF;
1354
1355 -- Initialize the activity rec
1356 l_activity_rec := INIT_ACTIVITY_REC ;
1357
1358 -- Assign the values for activity record
1359 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
1360 l_activity_rec.REPAIR_LINE_ID := JOB.repair_line_id;
1361 l_activity_rec.EVENT_CODE := 'JC';
1362 l_activity_rec.ACTION_CODE := 0;
1363 l_activity_rec.EVENT_DATE := MTL.transaction_date;
1364 l_activity_rec.QUANTITY := JOB.job_completed_qty;
1365 l_activity_rec.PARAMN1 := JOB.organization_id;
1366 l_activity_rec.PARAMN3 := MTL.transaction_id;
1367 l_activity_rec.PARAMN4 := JOB.wip_entity_id;
1368 l_activity_rec.PARAMN5 := l_update_qty;
1369 l_activity_rec.PARAMN6 := l_ro_count;
1370 l_activity_rec.PARAMC1 := MTL.subinventory_code;
1371 l_activity_rec.PARAMC2 := JOB.wip_entity_name;
1372 l_activity_rec.OBJECT_VERSION_NUMBER := null;
1373
1374 Debug('Calling LOG_ACTIVITY ',l_mod_name,2);
1375
1376 -- Calling LOG_ACTIVITY for logging activity
1377 -- for job completion
1378 LOG_ACTIVITY
1379 ( p_api_version => p_api_version,
1380 p_commit => p_commit,
1381 p_init_msg_list => p_init_msg_list,
1382 p_validation_level => p_validation_level,
1383 x_return_status => x_return_status,
1384 x_msg_count => x_msg_count,
1385 x_msg_data => x_msg_data,
1386 p_activity_rec => l_activity_rec );
1387
1388 Debug('x_return_status from LOG_ACTIVITY ='||x_return_status,l_mod_name,2);
1389 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
1390 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
1391 RAISE FND_API.G_EXC_ERROR;
1392 END IF;
1393 END IF; --IF (MTL.transaction_quantity - l_total_qty)> 0
1394 END IF;-- if l_remaining_qty <=0
1395
1396 EXCEPTION
1397 WHEN FND_API.G_EXC_ERROR THEN
1398 RAISE FND_API.G_EXC_ERROR;
1399 END;
1400 END LOOP; -- MTL cursor
1401
1402 END IF; -- end if serial_number_control_code (2,5)
1403 END IF;-- if l_remaining_qty >0
1404
1405 -- Increment if the record is processed successfully
1406 l_total_rec := l_total_rec + 1;
1407 Exception
1408 WHEN FND_API.G_EXC_ERROR THEN
1409 ROLLBACK TO JOB_COMPLETION;
1410 --x_return_status := FND_API.G_RET_STS_ERROR ;
1411 -- In case of error, exit the loop. It could rarely fail
1412 -- rollback the current record but commit the processed records
1413 --exit;
1414 WHEN SKIP_RECORD THEN
1415 NULL;
1416 WHEN OTHERS THEN
1417 ROLLBACK TO JOB_COMPLETION;
1418 --x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1419 -- In case of error, exit the loop. It could rarely fail
1420 -- rollback the current record but commit the processed records
1421 --exit;
1422 END;
1423
1424 -- Commit for every 500 records
1425 -- one should COMMIT less frequently within a PL/SQL loop to
1426 -- prevent ORA-1555 (Snapshot too old) errors
1427 l_count := l_count+1;
1428 IF mod(l_count, l_commit_size) = 0 THEN -- Commit every 500 records
1429 IF FND_API.To_Boolean( p_commit ) THEN
1430 COMMIT WORK;
1431 END IF;
1432 END IF;
1433
1434 END LOOP; -- JOB Cursor
1435
1436 --vijay 11/9/04
1437
1438 IF(Repair_Jobs_ALL%ISOPEN ) THEN
1439 CLOSE Repair_Jobs_ALL;
1440 END IF;
1441 IF(Repair_Jobs%ISOPEN ) THEN
1442 CLOSE Repair_Jobs;
1443 END IF;
1444
1445
1446 -- Log messages for the number of records processed
1447 fnd_message.set_name('CSD','CSD_DRC_WIP_REC_PROC');
1448 fnd_message.set_token('TOT_REC',to_char(l_total_rec));
1449 FND_MSG_PUB.ADD;
1450
1451 -- Retrive the message from the msg stack
1452 l_msg_text := fnd_message.get;
1453
1454 -- Log the number of records processed in concurrent program output and log file
1455 fnd_file.put_line(fnd_file.log,l_msg_text);
1456 fnd_file.put_line(fnd_file.output,l_msg_text);
1457
1458 -- Debug message
1459 Debug(l_msg_text,l_mod_name,1 );
1460
1461 -- Standard check of p_commit.
1462 IF FND_API.To_Boolean( p_commit ) THEN
1463 COMMIT WORK;
1464 END IF;
1465
1466 -- Standard call to get message count and IF count is get message info.
1467 FND_MSG_PUB.Count_And_Get
1468 (p_count => x_msg_count,
1469 p_data => x_msg_data );
1470 EXCEPTION
1471 WHEN FND_API.G_EXC_ERROR THEN
1472 Debug('In FND_API.G_EXC_ERROR exception',l_mod_name,4);
1473 ROLLBACK TO JOB_COMPLETION_UPDATE;
1474 x_return_status := FND_API.G_RET_STS_ERROR ;
1475 FND_MSG_PUB.Count_And_Get
1476 (p_count => x_msg_count,
1477 p_data => x_msg_data );
1478 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1479 Debug('In FND_API.G_EXC_UNEXPECTED_ERROR exception',l_mod_name,4);
1480 ROLLBACK TO JOB_COMPLETION_UPDATE;
1481 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1482 FND_MSG_PUB.Count_And_Get
1483 ( p_count => x_msg_count,
1484 p_data => x_msg_data );
1485 WHEN OTHERS THEN
1486 Debug('In OTHERS exception',l_mod_name,4);
1487 ROLLBACK TO JOB_COMPLETION_UPDATE;
1488 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1489 IF FND_MSG_PUB.Check_Msg_Level
1490 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1491 THEN
1492 FND_MSG_PUB.Add_Exc_Msg
1493 (G_PKG_NAME ,
1494 l_api_name );
1495 END IF;
1496 FND_MSG_PUB.Count_And_Get
1497 (p_count => x_msg_count,
1498 p_data => x_msg_data );
1499 END JOB_COMPLETION_UPDATE;
1500
1501 /*-------------------------------------------------------------------------------------*/
1502 /* Procedure name: JOB_CREATION_UPDATE */
1503 /* Description : Procedure called from wip_update API to update the wip entity Id */
1504 /* for the new jobs created by the WIP Mass Load concurrent program */
1505 /* Called from : Called from WIP_Update API */
1506 /* STANDARD PARAMETERS */
1507 /* In Parameters : */
1508 /* p_api_version NUMBER Required Api Version number */
1509 /* p_init_msg_list VARCHAR2 Optional To Initialize message stack */
1510 /* p_commit VARCHAR2 Optional Commits in API */
1511 /* p_validation_level NUMBER Optional validation level */
1512 /* */
1513 /* Output Parameters: */
1514 /* x_return_status VARCHAR2 Return status of the API */
1515 /* x_msg_count NUMBER Number of messages in stack */
1516 /* x_msg_data VARCHAR2 Error Message from message stack */
1517 /* */
1518 /* NON-STANDARD PARAMETERS */
1519 /* In Parameters */
1520 /* p_repair_line_id NUMBER Optional Repair Order Line Id */
1521 /* Output Parameter : */
1522 /* Change Hist : */
1523 /* 09/20/03 vlakaman Initial Creation. */
1524 /* */
1525 /*-------------------------------------------------------------------------------------*/
1526
1527 Procedure JOB_CREATION_UPDATE
1528 ( p_api_version IN NUMBER,
1529 p_commit IN VARCHAR2,
1530 p_init_msg_list IN VARCHAR2,
1531 p_validation_level IN NUMBER,
1532 x_return_status OUT NOCOPY VARCHAR2,
1533 x_msg_count OUT NOCOPY NUMBER,
1534 x_msg_data OUT NOCOPY VARCHAR2,
1535 p_repair_line_id IN NUMBER
1536 ) IS
1537
1538 --Standard variables
1539 l_api_name CONSTANT VARCHAR2(30) := 'JOB_CREATION_UPDATE';
1540 l_api_version CONSTANT NUMBER := 1.0;
1541
1542 -- Variables used in the program
1543 l_rep_hist_id NUMBER;
1544 l_total_rec NUMBER:= 0;
1545 l_update_qty NUMBER;
1546 l_count NUMBER;
1547 l_dummy varchar2(30);
1548 l_commit_size NUMBER := 500;
1549
1550 -- activity record
1551 l_activity_rec activity_rec_type;
1552
1553 -- Variable used in FND log
1554 l_error_level number := FND_LOG.LEVEL_ERROR;
1555 l_mod_name varchar2(2000) := 'csd.plsql.csd_update_programs_pvt.job_creation_update';
1556
1557 -- This cursor gets all the records in csd_repair_job_xref
1558 -- that does not have wip_entity_id.
1559 --Cursor split into two to remove OR condition
1560 -- Vijay 11/9/04
1561 Cursor JOB_CREATION( p_rep_line_id in number )IS
1562 SELECT
1563 crj.repair_job_xref_id,
1564 crj.repair_line_id,
1565 crj.organization_id,
1566 crj.quantity allocated_job_qty,
1567 we.wip_entity_id,
1568 we.wip_entity_name,
1569 wdj.start_quantity job_qty,
1570 wdj.creation_date
1571 from CSD_REPAIR_JOB_XREF crj,
1572 WIP_ENTITIES we,
1573 wip_discrete_jobs wdj
1574 where wdj.wip_entity_id = we.wip_entity_id
1575 and crj.job_name = we.wip_entity_name
1576 and crj.organization_id = we.organization_id
1577 and crj.repair_line_id = p_rep_line_id
1578 and crj.wip_entity_id is null;
1579 -- This cursor gets all the records in csd_repair_job_xref
1580 -- that does not have wip_entity_id.
1581 Cursor JOB_CREATION_ALL IS
1582 SELECT
1583 crj.repair_job_xref_id,
1584 crj.repair_line_id,
1585 crj.organization_id,
1586 crj.quantity allocated_job_qty,
1587 we.wip_entity_id,
1588 we.wip_entity_name,
1589 wdj.start_quantity job_qty,
1590 wdj.creation_date
1591 from CSD_REPAIR_JOB_XREF crj,
1592 WIP_ENTITIES we,
1593 wip_discrete_jobs wdj
1594 where wdj.wip_entity_id = we.wip_entity_id
1595 and crj.job_name = we.wip_entity_name
1596 and crj.organization_id = we.organization_id
1597 and crj.wip_entity_id is null;
1598 --Vijay 11/9/04
1599 K JOB_CREATION_Rec_Type;
1600 BEGIN
1601 -- Standard Start of API savepoint
1602 SAVEPOINT JOB_CREATION_UPDATE;
1603
1604 -- Initialize API return status to success
1605 x_return_status := FND_API.G_RET_STS_SUCCESS;
1606
1607 -- Debug messages
1608 Debug('At the Beginning of JOB_CREATION_UPDATE',l_mod_name,1);
1609
1610 -- Standard call to check for call compatibility.
1611 IF NOT FND_API.Compatible_API_Call (l_api_version,
1612 p_api_version,
1613 l_api_name ,
1614 G_PKG_NAME )
1615 THEN
1616 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1617 END IF;
1618
1619 -- Initialize message list if p_init_msg_list is set to TRUE.
1620 IF FND_API.to_Boolean( p_init_msg_list ) THEN
1621 FND_MSG_PUB.initialize;
1622 END IF;
1623
1624 -- Keeping the running total of the records
1625 -- for commiting purpose
1626 l_count := 0;
1627
1628 -- When Jobs are created from the UI, a record is inserted in csd_repair_job_xref
1629 -- with the job name. Once the WIP Job is created in wip_discrete_jobs
1630 -- then the update program will find the wip_entity_id and update it.
1631 -- Also it updates the quantity_in_wip in the csd_repairs with Job start quantity
1632 --
1633 -- When the WIP Job is submitted from the UI, the record would look as follows:
1634 -- CSD_REPAIR_JOB_XREF
1635 -- Repair Job Repair Order Allocated Qty Job Name Job Qty Wip_entity_ID
1636 -- RJ1 R1 1 JOB1 3
1637 -- RJ2 R2 1 JOB1 3
1638 -- RJ3 R3 1 JOB1 3
1639 --
1640 -- After Running the Update Program the record would look as follows:
1641 -- CSD_REPAIR_JOB_XREF
1642 -- Repair Job Repair Order Allocated Qty Job Name Job Qty Wip_entity_ID
1643 -- RJ1 R1 1 JOB1 3 1121
1644 -- RJ2 R2 1 JOB1 3 1121
1645 -- RJ3 R3 1 JOB1 3 1121
1646 --FOR K IN Job_Creation ( p_repair_line_id )
1647 IF(p_repair_line_Id is null) THEN
1648 OPEN Job_Creation_ALL;
1649 ELSE
1650 OPEN Job_Creation (p_repair_line_id);
1651 END IF;
1652
1653 LOOP
1654 BEGIN
1655
1656 IF(p_repair_line_Id is null) THEN
1657 FETCH Job_Creation_ALL INTO K;
1658 EXIT WHEN Job_Creation_ALL%NOTFOUND;
1659 ELSE
1660 FETCH Job_Creation INTO K;
1661 EXIT WHEN Job_Creation %NOTFOUND;
1662 END IF;
1663 -- savepoint
1664 SAVEPOINT Job_Creation;
1665
1666 -- Debug Messages
1667 Debug('wip_entity_id ='||K.wip_entity_id,l_mod_name,1);
1668 Debug('Logging activity for Job creation',l_mod_name,1);
1669
1670 -- Initialize the activity rec
1671 l_activity_rec := INIT_ACTIVITY_REC ;
1672
1673 -- Assign the values for activity record
1674 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
1675 l_activity_rec.REPAIR_LINE_ID := K.repair_line_id;
1676 l_activity_rec.EVENT_CODE := 'JS';
1677 l_activity_rec.ACTION_CODE := 0;
1678 l_activity_rec.EVENT_DATE := K.creation_date;
1679 l_activity_rec.QUANTITY := K.job_qty;
1680 l_activity_rec.PARAMN1 := k.wip_entity_id;
1681 l_activity_rec.PARAMN2 := k.organization_id;
1682 l_activity_rec.PARAMN5 := K.allocated_job_qty;
1683 l_activity_rec.PARAMC1 := K.wip_entity_name;
1684 l_activity_rec.OBJECT_VERSION_NUMBER := null;
1685
1686 -- Debug Messages
1687 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
1688
1689 -- Calling LOG_ACTIVITY for logging activity
1690 -- for job creation
1691 LOG_ACTIVITY
1692 ( p_api_version => p_api_version,
1693 p_commit => p_commit,
1694 p_init_msg_list => p_init_msg_list,
1695 p_validation_level => p_validation_level,
1696 x_return_status => x_return_status,
1697 x_msg_count => x_msg_count,
1698 x_msg_data => x_msg_data,
1699 p_activity_rec => l_activity_rec );
1700
1701 -- Debug Messages
1702 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
1703
1704 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
1705 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
1706 RAISE FND_API.G_EXC_ERROR;
1707 END IF;
1708
1709 -- Updating csd_repair_job_xref with the wip_entity_id
1710 Update csd_repair_job_xref
1711 set wip_entity_id = K.wip_entity_id,
1712 object_version_number = object_version_number+1,
1713 last_update_date = sysdate,
1714 last_updated_by = fnd_global.user_id,
1715 last_update_login = fnd_global.login_id
1716 where repair_job_xref_id = K.repair_job_xref_id;
1717 IF SQL%NOTFOUND THEN
1718 IF ( l_error_level >= G_debug_level) THEN
1719 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_XREF_UPD_FAILED');
1720 FND_MESSAGE.SET_TOKEN('REP_JOB_XREF_ID',K.repair_job_xref_id );
1721 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
1722 ELSE
1723 FND_MESSAGE.SET_NAME('CSD','CSD_JOB_XREF_UPD_FAILED');
1724 FND_MESSAGE.SET_TOKEN('REP_JOB_XREF_ID',K.repair_job_xref_id );
1725 FND_MSG_PUB.ADD;
1726 END IF;
1727 RAISE FND_API.G_EXC_ERROR;
1728 End IF;
1729
1730 -- Updating repair order with the Job allocated qty
1731 Update csd_repairs
1732 set quantity_in_wip = NVL(quantity_in_wip,0) + K.allocated_job_qty,
1733 last_update_date = sysdate,
1734 last_updated_by = fnd_global.user_id,
1735 object_version_number = object_version_number+1,
1736 last_update_login = fnd_global.login_id
1737 where repair_line_id = K.repair_line_id;
1738 IF SQL%NOTFOUND THEN
1739 IF ( l_error_level >= G_debug_level) THEN
1740 FND_MESSAGE.SET_NAME('CSD','CSD_RO_UPD_FAILED');
1741 FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',K.repair_line_id );
1742 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
1743 ELSE
1744 FND_MESSAGE.SET_NAME('CSD','CSD_RO_UPD_FAILED');
1745 FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',K.repair_line_id );
1746 FND_MSG_PUB.ADD;
1747 END IF;
1748 RAISE FND_API.G_EXC_ERROR;
1749 End IF;
1750
1751 Exception
1752 WHEN FND_API.G_EXC_ERROR THEN
1753 ROLLBACK TO JOB_CREATION;
1754 --x_return_status := FND_API.G_RET_STS_ERROR ;
1755 -- exit the loop in case of error. Commit the processed records
1756 -- but rollback the current error record
1757 --exit;
1758 WHEN OTHERS THEN
1759 ROLLBACK TO JOB_CREATION;
1760 --x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1761 -- exit the loop in case of error. Commit the processed records
1762 -- but rollback the current error record
1763 --exit;
1764 END;
1765 -- Commit for every 500 records
1766 -- one should COMMIT less frequently within a PL/SQL loop to
1767 -- prevent ORA-1555 (Snapshot too old) errors
1768 l_count := l_count+1;
1769 IF mod(l_count, l_commit_size) = 0 THEN -- Commit every 500 records
1770 IF FND_API.To_Boolean( p_commit ) THEN
1771 COMMIT WORK;
1772 END IF;
1773 END IF;
1774 END LOOP; -- End of Job Creation activity
1775
1776 --Vijay 11/9/04
1777
1778 IF(Job_Creation_ALL%ISOPEN ) THEN
1779 CLOSE Job_Creation_ALL;
1780 END IF;
1781 IF(Job_Creation%ISOPEN ) THEN
1782 CLOSE Job_Creation;
1783 END IF;
1784
1785
1786 -- Standard check of p_commit.
1787 IF FND_API.To_Boolean( p_commit ) THEN
1788 COMMIT WORK;
1789 END IF;
1790
1791 -- Standard call to get message count and IF count is get message info.
1792 FND_MSG_PUB.Count_And_Get
1793 (p_count => x_msg_count,
1794 p_data => x_msg_data );
1795 EXCEPTION
1796 WHEN FND_API.G_EXC_ERROR THEN
1797 Debug('In FND_API.G_EXC_ERROR exception',l_mod_name,4);
1798 ROLLBACK TO JOB_CREATION_UPDATE;
1799 x_return_status := FND_API.G_RET_STS_ERROR ;
1800 FND_MSG_PUB.Count_And_Get
1801 (p_count => x_msg_count,
1802 p_data => x_msg_data );
1803 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1804 Debug('In FND_API.G_EXC_UNEXPECTED_ERROR exception',l_mod_name,4);
1805 ROLLBACK TO JOB_CREATION_UPDATE;
1806 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1807 FND_MSG_PUB.Count_And_Get
1808 ( p_count => x_msg_count,
1809 p_data => x_msg_data );
1810 WHEN OTHERS THEN
1811 Debug('In OTHERS exception',l_mod_name,4);
1812 ROLLBACK TO JOB_CREATION_UPDATE;
1813 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1814 IF FND_MSG_PUB.Check_Msg_Level
1815 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1816 THEN
1817 FND_MSG_PUB.Add_Exc_Msg
1818 (G_PKG_NAME ,
1819 l_api_name );
1820 END IF;
1821 FND_MSG_PUB.Count_And_Get
1822 (p_count => x_msg_count,
1823 p_data => x_msg_data );
1824 END JOB_CREATION_UPDATE;
1825
1826 /*-------------------------------------------------------------------------------------*/
1827 /* Procedure name: RECEIPTS_UPDATE */
1828 /* Description : Procedure called from the UI to update the depot tables */
1829 /* for the receipts against RMA/Internal Requisitions. It calls */
1830 /* RMA_RCV_UPDATE and IO_RCV_UPDATE to process RMA and IO respectively */
1831 /* Called from : Called from Depot Repair UI */
1832 /* STANDARD PARAMETERS */
1833 /* In Parameters : */
1834 /* p_api_version NUMBER Required Api Version number */
1835 /* p_init_msg_list VARCHAR2 Optional To Initialize message stack */
1836 /* p_commit VARCHAR2 Optional Commits in API */
1837 /* p_validation_level NUMBER Optional validation level */
1838 /* */
1839 /* Output Parameters: */
1840 /* x_return_status VARCHAR2 Return status of the API */
1841 /* x_msg_count NUMBER Number of messages in stack */
1842 /* x_msg_data VARCHAR2 Error Message from message stack */
1843 /* */
1844 /* NON-STANDARD PARAMETERS */
1845 /* In Parameters */
1846 /* p_order_header_id NUMBER Optional Interal sales order Id */
1847 /* p_internal_order_flag VARCHAR2 Required Order Type; Possible values -'Y','N' */
1848 /* p_repair_line_id NUMBER Optional Repair Order Line Id */
1849 /* Output Parameter : */
1850 /* Change Hist : */
1851 /* 09/20/03 vlakaman Initial Creation. */
1852 /*-------------------------------------------------------------------------------------*/
1853
1854 Procedure RECEIPTS_UPDATE
1855 ( p_api_version IN NUMBER,
1856 p_commit IN VARCHAR2,
1857 p_init_msg_list IN VARCHAR2,
1858 p_validation_level IN NUMBER,
1859 x_return_status OUT NOCOPY VARCHAR2,
1860 x_msg_count OUT NOCOPY NUMBER,
1861 x_msg_data OUT NOCOPY VARCHAR2,
1862 p_internal_order_flag IN VARCHAR2,
1863 p_order_header_id IN NUMBER,
1864 p_repair_line_id IN NUMBER,
1865 p_past_num_of_days IN NUMBER DEFAULT NULL ----bug#6753684, 6742512
1866 ) IS
1867
1868 --Standard variables
1869 l_api_name CONSTANT VARCHAR2(30) := 'RECEIPTS_UPDATE';
1870 l_api_version CONSTANT NUMBER := 1.0;
1871
1872 -- Variable used in FND log
1873 l_error_level number := FND_LOG.LEVEL_ERROR;
1874 l_mod_name varchar2(2000) := 'csd.plsql.csd_update_programs_pvt.receipts_update';
1875
1876 --bug#8261344
1877 l_return_status varchar2(1);
1878 l_msg_data_warning VARCHAR2(30000);
1879
1880 BEGIN
1881 -- Standard Start of API savepoint
1882 SAVEPOINT RECEIPTS_UPDATE;
1883
1884 -- Initialize API return status to success
1885 x_return_status := FND_API.G_RET_STS_SUCCESS;
1886
1887 -- Log the api name in the log file
1888 Debug('At the Beginning of Receipts_update',l_mod_name,1);
1889 Debug('p_internal_order_flag ='||p_internal_order_flag,l_mod_name,1);
1890 Debug('p_order_header_id ='||p_order_header_id,l_mod_name,1);
1891 Debug('p_repair_line_id ='||p_repair_line_id,l_mod_name,1);
1892
1893 -- Standard call to check for call compatibility.
1894 IF NOT FND_API.Compatible_API_Call (l_api_version,
1895 p_api_version,
1896 l_api_name ,
1897 G_PKG_NAME )
1898 THEN
1899 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1900 END IF;
1901
1902 -- Initialize message list if p_init_msg_list is set to TRUE.
1903 IF FND_API.to_Boolean( p_init_msg_list ) THEN
1904 FND_MSG_PUB.initialize;
1905 END IF;
1906
1907 -- Api body starts
1908 IF p_internal_order_flag = 'Y' then
1909
1910 Debug('Calling IO_SHIP_UPDATE API',l_mod_name,2);
1911 -- Call the api for processing the shipment against
1912 -- internal orders
1913 IO_SHIP_UPDATE
1914 ( p_api_version => p_api_version,
1915 p_commit => p_commit ,
1916 p_init_msg_list => p_init_msg_list,
1917 p_validation_level => p_validation_level,
1918 x_return_status => x_return_status,
1919 x_msg_count => x_msg_count,
1920 x_msg_data => x_msg_data ,
1921 p_order_header_id => p_order_header_id );
1922
1923 -- Debug messages
1924 Debug('Return Status from IO_SHIP_UPDATE API :'||x_return_status,l_mod_name,2);
1925 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
1926 Debug('IO_SHIP_UPDATE failed',l_mod_name,4);
1927 RAISE FND_API.G_EXC_ERROR;
1928 END IF;
1929
1930 Debug('Calling IO_RCV_UPDATE API',l_mod_name,2);
1931 -- Call the api for processing the receipt against
1932 -- internal requisition
1933 IO_RCV_UPDATE
1934 ( p_api_version => p_api_version,
1935 p_commit => p_commit ,
1936 p_init_msg_list => p_init_msg_list,
1937 p_validation_level => p_validation_level,
1938 x_return_status => x_return_status,
1939 x_msg_count => x_msg_count,
1940 x_msg_data => x_msg_data ,
1941 p_order_header_id => p_order_header_id );
1942
1943 -- Debug messages
1944 Debug('Return Status from IO_RCV_UPDATE API :'||x_return_status,l_mod_name,2);
1945 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
1946 Debug('IO_RCV_UPDATE failed',l_mod_name,4);
1947 RAISE FND_API.G_EXC_ERROR;
1948 END IF;
1949 Else
1950 -- Debug messages
1951 Debug('Calling RMA_RCV_UPDATE API',l_mod_name,2);
1952 -- Call the api for processing the receipts against RMA
1953 RMA_RCV_UPDATE
1954 ( p_api_version => p_api_version,
1955 p_commit => p_commit ,
1956 p_init_msg_list => p_init_msg_list,
1957 p_validation_level => p_validation_level,
1958 x_return_status => l_return_status,
1959 x_msg_count => x_msg_count,
1960 x_msg_data => x_msg_data ,
1961 p_repair_line_id => p_repair_line_id,
1962 p_past_num_of_days => p_past_num_of_days);
1963
1964 -- Debug messages
1965 Debug('Return Status from RMA_RCV_UPDATE API :'||l_return_status,l_mod_name,2);
1966
1967
1968 --bug#8261344
1969 -- swai: bug 12547701 change if statement
1970 If ((l_return_status = G_CSD_RET_STS_WARNING) and -- p_repair_line_id is null
1971 (NVL(fnd_profile.value('CSD_LOGISTICS_PROGRAM_ERROR'), 'S') <> 'S')) Then
1972 Debug('RMA_RCV_UPDATE Warning message',l_mod_name,4);
1973
1974 Debug('x_msg_count :'||x_msg_count,l_mod_name,2);
1975 Debug('x_msg_data :'||x_msg_data,l_mod_name,2);
1976
1977
1978 -- swai: bug 12547701: do not pop the messages off the stack
1979 -- warnings should leave the messages on the stack for the
1980 -- calling procedure to handle.
1981 /*
1982 l_msg_data_warning := null;
1983 -- Concatenate the message from the message stack
1984 IF x_msg_count >= 1 then
1985 FOR i IN 1..x_msg_count LOOP
1986 l_msg_data_warning := l_msg_data_warning ||' : '||FND_MSG_PUB.Get(i,FND_API.G_FALSE) ;
1987 Debug('l_msg_data_warning loop :'||l_msg_data_warning,l_mod_name,2);
1988 END LOOP ;
1989 END IF ;
1990 Debug(l_msg_data_warning,l_mod_name,4);
1991 */
1992 ELSIF NOT(l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
1993 Debug('RMA_RCV_UPDATE failed',l_mod_name,4);
1994 RAISE FND_API.G_EXC_ERROR;
1995 END IF;
1996
1997 End If;
1998
1999 -- bug#7497790, 12.1 FP, subhat.
2000 -- automatically update RO status when item is received.
2001 -- dont show any error messages. Pass p_validation_level = fnd_api.g_valid_level_full to receive messages.
2002 csd_repairs_util.auto_update_ro_status(
2003 p_api_version => 1,
2004 p_commit => p_commit,
2005 p_init_msg_list => FND_API.G_FALSE, -- swai: bug 12547701 do not clear msg stack
2006 p_repair_line_id => p_repair_line_id,
2007 x_return_status => x_return_status,
2008 x_msg_count => x_msg_count,
2009 x_msg_data => x_msg_data,
2010 p_event => 'RECEIVE',
2011 p_validation_level => fnd_api.g_valid_level_none);
2012 -- end bug#7497790, 12.1 FP, subhat.
2013
2014 -- Standard check of p_commit.
2015 IF FND_API.To_Boolean( p_commit ) THEN
2016 COMMIT WORK;
2017 END IF;
2018
2019 -- Standard call to get message count and IF count is get message info.
2020 FND_MSG_PUB.Count_And_Get
2021 (p_count => x_msg_count,
2022 p_data => x_msg_data );
2023
2024 --bug#8261344
2025 -- swai: bug 12547701 change if statement
2026 If ((l_return_status = G_CSD_RET_STS_WARNING) AND
2027 (NVL(fnd_profile.value('CSD_LOGISTICS_PROGRAM_ERROR'), 'S') <> 'S'))THEN
2028 x_return_status := l_return_status;
2029 -- x_msg_data := l_msg_data_warning; -- swai: bug 12547701
2030 END IF;
2031
2032 EXCEPTION
2033 WHEN FND_API.G_EXC_ERROR THEN
2034 Debug('In FND_API.G_EXC_ERROR exception',l_mod_name,4 );
2035 -- As we are committing the processed records in the inner APIs
2036 -- so we rollback only if the p_commit='F'
2037 IF NOT(FND_API.To_Boolean( p_commit )) THEN
2038 ROLLBACK TO RECEIPTS_UPDATE;
2039 END IF;
2040 x_return_status := FND_API.G_RET_STS_ERROR ;
2041 FND_MSG_PUB.Count_And_Get
2042 (p_count => x_msg_count,
2043 p_data => x_msg_data );
2044 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2045 Debug('In FND_API.G_EXC_UNEXPECTED_ERROR exception',l_mod_name,4 );
2046 IF ( l_error_level >= G_debug_level) THEN
2047 fnd_message.set_name('CSD','CSD_SQL_ERROR');
2048 fnd_message.set_token('SQLERRM',SQLERRM);
2049 fnd_message.set_token('SQLCODE',SQLCODE);
2050 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
2051 END If;
2052 -- As we are committing the processed records in the inner APIs
2053 -- so we rollback only if the p_commit='F'
2054 IF NOT(FND_API.To_Boolean( p_commit )) THEN
2055 ROLLBACK TO RECEIPTS_UPDATE;
2056 END IF;
2057 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2058 FND_MSG_PUB.Count_And_Get
2059 ( p_count => x_msg_count,
2060 p_data => x_msg_data );
2061 WHEN OTHERS THEN
2062 Debug('In OTHERS exception',l_mod_name,4 );
2063 IF ( l_error_level >= G_debug_level) THEN
2064 fnd_message.set_name('CSD','CSD_SQL_ERROR');
2065 fnd_message.set_token('SQLERRM',SQLERRM);
2066 fnd_message.set_token('SQLCODE',SQLCODE);
2067 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
2068 END If;
2069 -- As we are committing the processed records in the inner APIs
2070 -- so we rollback only if the p_commit='F'
2071 IF NOT(FND_API.To_Boolean( p_commit )) THEN
2072 ROLLBACK TO RECEIPTS_UPDATE;
2073 END IF;
2074 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2075 IF FND_MSG_PUB.Check_Msg_Level
2076 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2077 THEN
2078 FND_MSG_PUB.Add_Exc_Msg
2079 (G_PKG_NAME ,
2080 l_api_name );
2081 END IF;
2082 FND_MSG_PUB.Count_And_Get
2083 (p_count => x_msg_count,
2084 p_data => x_msg_data );
2085 END RECEIPTS_UPDATE;
2086
2087 /*-------------------------------------------------------------------------------------*/
2088 /* Procedure name: RMA_RCV_UPDATE */
2089 /* Description : Procedure called from the update API to update the depot tables */
2090 /* for the receipts against RMA. It also logs activities for accept */
2091 /* reject txn lines */
2092 /* Called from : Called from RECEIPTS_UPDATE API */
2093 /* STANDARD PARAMETERS */
2094 /* In Parameters : */
2095 /* p_api_version NUMBER Required Api Version number */
2096 /* p_init_msg_list VARCHAR2 Optional To Initialize message stack */
2097 /* p_commit VARCHAR2 Optional Commits in API */
2098 /* p_validation_level NUMBER Optional validation level */
2099 /* */
2100 /* Output Parameters: */
2101 /* x_return_status VARCHAR2 Return status of the API */
2102 /* x_msg_count NUMBER Number of messages in stack */
2103 /* x_msg_data VARCHAR2 Error Message from message stack */
2104 /* */
2105 /* NON-STANDARD PARAMETERS */
2106 /* In Parameters */
2107 /* p_repair_line_id NUMBER Optional Repair Order Line Id */
2108 /* Output Parameter : */
2109 /* Change Hist : */
2110 /* 09/20/03 vlakaman Initial Creation. */
2111 /*-------------------------------------------------------------------------------------*/
2112
2113 Procedure RMA_RCV_UPDATE
2114 ( p_api_version IN NUMBER,
2115 p_commit IN VARCHAR2,
2116 p_init_msg_list IN VARCHAR2,
2117 p_validation_level IN NUMBER,
2118 x_return_status OUT NOCOPY VARCHAR2,
2119 x_msg_count OUT NOCOPY NUMBER,
2120 x_msg_data OUT NOCOPY VARCHAR2,
2121 p_repair_line_id IN NUMBER,
2122 p_past_num_of_days IN NUMBER DEFAULT NULL) ----bug#6753684, 6742512
2123 IS
2124
2125
2126 -- Standard Variables
2127 l_api_name CONSTANT VARCHAR2(30) := 'RMA_RCV_UPDATE';
2128 l_api_version CONSTANT NUMBER := 1.0;
2129
2130 -- Variables used in the program
2131 l_total_records number;
2132 l_rep_hist_id number;
2133 l_result_quantity number;
2134 l_repair_line_id NUMBER;
2135 l_prod_txn_id NUMBER;
2136 l_accept_qty NUMBER;
2137 l_reject_qty NUMBER;
2138 l_st_serial_num mtl_serial_numbers.serial_number%type;
2139 l_dummy varchar2(30);
2140 l_lot_number mtl_lot_numbers.lot_number%type;
2141 l_ro_reject_qty NUMBER;
2142 l_commit_size NUMBER := 500;
2143 l_srl_ctl_code mtl_system_items.serial_number_control_code%type;
2144 l_lot_ctl_code mtl_system_items.lot_control_code%type;
2145 l_ib_flag mtl_system_items.comms_nl_trackable_flag%type;
2146 l_instance_id csi_item_instances.instance_id%type;
2147 l_prod_txn_status csd_product_transactions.prod_txn_status%type;
2148
2149 -- activity record
2150 l_activity_rec activity_rec_type;
2151
2152 --bug#6753684, 6742512
2153 l_From_Date Date;
2154 l_TO_Date Date;
2155
2156 -- Variables for FND Log
2157 l_error_level number := FND_LOG.LEVEL_ERROR;
2158 l_mod_name varchar2(2000) := 'csd.plsql.csd_update_programs_pvt.rma_rcv_update';
2159
2160 -- User defined exceptions
2161 SKIP_RECORD EXCEPTION;
2162
2163 --bug#8261344
2164 l_skip_record BOOLEAN := FALSE;
2165 l_warning_return BOOLEAN := FALSE;
2166
2167 -- subhat, resolve by date enhancements.
2168 l_resolve_date_calc_at VARCHAR2(30);
2169 l_contract_line_id NUMBER;
2170 l_business_process_id NUMBER;
2171 l_severity_id NUMBER;
2172 x_resolve_by_date DATE;
2173
2174 CURSOR RECEIPT_LINES IS
2175 SELECT
2176 oeh.order_number rma_number,
2177 oeh.header_id rma_header_id,
2178 oel.line_id ,
2179 oel.line_number rma_line_number,
2180 oel.inventory_item_id,
2181 haou.name org_name,
2182 rcvt.organization_id,
2183 rcvt.unit_of_measure,
2184 rcvt.quantity received_quantity,
2185 rcvt.transaction_date received_date,
2186 rcvt.transaction_id,
2187 rcvt.subinventory,
2188 rcvt.locator_id,
2189 rcvt.transaction_type,
2190 cra.serial_number ro_serial_number,
2191 cra.repair_number,
2192 cra.unit_of_measure ro_uom,
2193 cra.inventory_item_id ro_item_id,
2194 cpt.product_transaction_id,
2195 cpt.repair_line_id,
2196 cpt.action_code,
2197 cpt.action_type, --bug#10099900
2198 cpt.source_serial_number,
2199 cpt.source_instance_id,
2200 cpt.quantity_received prod_txn_recd_qty,
2201 abs(ced.quantity_required) estimate_quantity,
2202 ced.order_line_id est_order_line_id,
2203 ced.inventory_item_id prod_txn_item_id
2204 FROM csd_product_transactions cpt,
2205 cs_estimate_details ced,
2206 csd_repairs cra,
2207 rcv_transactions rcvt,
2208 oe_order_headers_all oeh,
2209 oe_order_lines_all oel,
2210 hr_all_organization_units haou
2211 WHERE cpt.action_type in ('RMA', 'RMA_THIRD_PTY') -- excluded walk-in-receipt as it is going off
2212 AND cpt.prod_txn_status in ( 'BOOKED', 'SUBMITTED')
2213 AND ced.order_header_id is not null
2214 AND rcvt.oe_order_line_id = ced.order_line_id ----bug#6753684, 6742512
2215 AND rcvt.oe_order_header_id = ced.order_header_id ----bug#6753684, 6742512
2216 AND ced.source_code = 'DR'
2217 AND ced.estimate_detail_id = cpt.estimate_detail_id
2218 AND cra.repair_line_id = cpt.repair_line_id
2219 AND oeh.header_id = ced.order_header_id
2220 AND oel.header_id = oeh.header_id
2221 AND rcvt.oe_order_line_id = oel.line_id
2222 AND rcvt.transaction_type in ('DELIVER','ACCEPT','REJECT')
2223 AND rcvt.source_document_code = 'RMA'
2224 AND rcvt.organization_id = haou.organization_id
2225 AND NOT EXISTS
2226 (SELECT 'X'
2227 FROM csd_repair_history crh
2228 WHERE crh.repair_line_id = cpt.repair_line_id
2229 AND event_code = decode(rcvt.transaction_type,
2230 'DELIVER','RR',
2231 'ACCEPT', 'IP',
2232 'REJECT','IP','')
2233 AND paramn1 = rcvt.transaction_id)
2234
2235 AND ((ced.QUANTITY_REQUIRED < -1
2236 AND oel.line_id in ( Select line_id
2237 from oe_order_lines_all oel1
2238 start with oel1.line_id = ced.order_line_id
2239 connect by prior oel1.line_id = oel1.split_from_line_id
2240 and oel1.shipped_quantity is not null
2241 and oel1.header_id = oeh.header_id))
2242 OR (ced.QUANTITY_REQUIRED = -1
2243 AND ced.ORDER_LINE_ID = oel.LINE_ID));
2244
2245 /* Fixed bug#6753684,
2246
2247 New cursor added for batch processing.This cursor takes two parameter
2248 p_from_date and p_to_date. These dates are compared with the creation date
2249 of repair order. Only repair order created during this period are considered
2250 for Depot Receipt Update to improve performance.
2251 */
2252 CURSOR RECEIPT_LINES_BY_DATE( p_from_Date Date, p_to_Date Date ) IS
2253 SELECT
2254 oeh.order_number rma_number,
2255 oeh.header_id rma_header_id,
2256 oel.line_id ,
2257 oel.line_number rma_line_number,
2258 oel.inventory_item_id,
2259 haou.name org_name,
2260 rcvt.organization_id,
2261 rcvt.unit_of_measure,
2262 rcvt.quantity received_quantity,
2263 rcvt.transaction_date received_date,
2264 rcvt.transaction_id,
2265 rcvt.subinventory,
2266 rcvt.locator_id,
2267 rcvt.transaction_type,
2268 cra.serial_number ro_serial_number,
2269 cra.repair_number,
2270 cra.unit_of_measure ro_uom,
2271 cra.inventory_item_id ro_item_id,
2272 cpt.product_transaction_id,
2273 cpt.repair_line_id,
2274 cpt.action_code,
2275 cpt.action_type, --bug#10099900
2276 cpt.source_serial_number,
2277 cpt.source_instance_id,
2278 cpt.quantity_received prod_txn_recd_qty,
2279 abs(ced.quantity_required) estimate_quantity,
2280 ced.order_line_id est_order_line_id,
2281 ced.inventory_item_id prod_txn_item_id
2282 FROM csd_product_transactions cpt,
2283 cs_estimate_details ced,
2284 csd_repairs cra,
2285 rcv_transactions rcvt,
2286 oe_order_headers_all oeh,
2287 oe_order_lines_all oel,
2288 hr_all_organization_units haou
2289 WHERE cra.creation_date between p_from_date and p_to_date
2290 AND cpt.action_type in ('RMA', 'RMA_THIRD_PTY') -- excluded walk-in-receipt as it is going off
2291 AND cpt.prod_txn_status in ( 'BOOKED', 'SUBMITTED')
2292 AND ced.order_header_id is not null
2293 AND rcvt.oe_order_line_id = ced.order_line_id ----bug#6753684, 6742512
2294 AND rcvt.oe_order_header_id = ced.order_header_id ----bug#6753684, 6742512
2295 AND ced.source_code = 'DR'
2296 AND ced.estimate_detail_id = cpt.estimate_detail_id
2297 AND cra.repair_line_id = cpt.repair_line_id
2298 AND oeh.header_id = ced.order_header_id
2299 AND oel.header_id = oeh.header_id
2300 AND rcvt.oe_order_line_id = oel.line_id
2301 AND rcvt.transaction_type in ('DELIVER','ACCEPT','REJECT')
2302 AND rcvt.source_document_code = 'RMA'
2303 AND rcvt.organization_id = haou.organization_id
2304 AND NOT EXISTS
2305 (SELECT 'X'
2306 FROM csd_repair_history crh
2307 WHERE crh.repair_line_id = cpt.repair_line_id
2308 AND event_code = decode(rcvt.transaction_type,
2309 'DELIVER','RR',
2310 'ACCEPT', 'IP',
2311 'REJECT','IP','')
2312 AND paramn1 = rcvt.transaction_id)
2313
2314 AND ((ced.QUANTITY_REQUIRED < -1
2315 AND oel.line_id in ( Select line_id
2316 from oe_order_lines_all oel1
2317 start with oel1.line_id = ced.order_line_id
2318 connect by prior oel1.line_id = oel1.split_from_line_id
2319 and oel1.shipped_quantity is not null
2320 and oel1.header_id = oeh.header_id))
2321 OR (ced.QUANTITY_REQUIRED = -1
2322 AND ced.ORDER_LINE_ID = oel.LINE_ID));
2323
2324
2325 CURSOR RECEIPT_LINES_RO(p_repair_line_id NUMBER) IS
2326 SELECT
2327 oeh.order_number rma_number,
2328 oeh.header_id rma_header_id,
2329 oel.line_id ,
2330 oel.line_number rma_line_number,
2331 oel.inventory_item_id,
2332 haou.name org_name,
2333 rcvt.organization_id,
2334 rcvt.unit_of_measure,
2335 rcvt.quantity received_quantity,
2336 rcvt.transaction_date received_date,
2337 rcvt.transaction_id,
2338 rcvt.subinventory,
2339 rcvt.locator_id,
2340 rcvt.transaction_type,
2341 cra.serial_number ro_serial_number,
2342 cra.repair_number,
2343 cra.unit_of_measure ro_uom,
2344 cra.inventory_item_id ro_item_id,
2345 cpt.product_transaction_id,
2346 cpt.repair_line_id,
2347 cpt.action_code,
2348 cpt.action_type, --bug#10099900
2349 cpt.source_serial_number,
2350 cpt.source_instance_id,
2351 cpt.quantity_received prod_txn_recd_qty,
2352 abs(ced.quantity_required) estimate_quantity,
2353 ced.order_line_id est_order_line_id,
2354 ced.inventory_item_id prod_txn_item_id
2355 FROM hr_all_organization_units haou,
2356 csd_repairs cra,
2357 oe_order_headers_all oeh,
2358 oe_order_lines_all oel,
2359 rcv_transactions rcvt,
2360 cs_estimate_details ced,
2361 csd_product_transactions cpt
2362 WHERE cpt.repair_line_id = p_repair_line_id
2363 AND cpt.action_type in ('RMA', 'RMA_THIRD_PTY') -- excluded walk-in-receipt as it is going off
2364 AND cpt.prod_txn_status in ( 'BOOKED', 'SUBMITTED')
2365 AND ced.order_header_id is not null
2366 AND rcvt.oe_order_line_id = ced.order_line_id ----bug#6753684, 6742512
2367 AND rcvt.oe_order_header_id = ced.order_header_id ----bug#6753684, 6742512
2368 AND ced.source_code = 'DR'
2369 AND ced.estimate_detail_id = cpt.estimate_detail_id
2370 AND cra.repair_line_id = cpt.repair_line_id
2371 AND oeh.header_id = ced.order_header_id
2372 AND oel.header_id = oeh.header_id
2373 AND rcvt.oe_order_line_id = oel.line_id
2374 AND rcvt.transaction_type in ('DELIVER','ACCEPT','REJECT')
2375 AND rcvt.source_document_code = 'RMA'
2376 AND rcvt.organization_id = haou.organization_id
2377 AND NOT EXISTS
2378 (SELECT 'X'
2379 FROM csd_repair_history crh
2380 WHERE crh.repair_line_id = cpt.repair_line_id
2381 AND event_code = decode(rcvt.transaction_type,
2382 'DELIVER','RR',
2383 'ACCEPT', 'IP',
2384 'REJECT','IP','')
2385 AND paramn1 = rcvt.transaction_id)
2386
2387
2388 AND ((ced.QUANTITY_REQUIRED < -1
2389 AND oel.line_id in ( Select line_id
2390 from oe_order_lines_all oel1
2391 start with oel1.line_id = ced.order_line_id
2392 connect by prior oel1.line_id = oel1.split_from_line_id
2393 and oel1.shipped_quantity is not null
2394 and oel1.header_id = oeh.header_id))
2395 OR (ced.QUANTITY_REQUIRED = -1
2396 AND ced.ORDER_LINE_ID = oel.LINE_ID));
2397
2398 I RCPT_LINES_Rec_Type;
2399
2400
2401 --- cursor for Cancelled orders...
2402 CURSOR Cur_Cancelled_repair_lines IS
2403 SELECT cra.REPAIR_LINE_ID
2404 FROM csd_repairs cra,
2405 cs_estimate_details ced,
2406 csd_product_transactions cpt
2407 WHERE cpt.action_type in ('RMA', 'RMA_THIRD_PTY')
2408 AND cpt.prod_txn_status in ( 'BOOKED', 'SUBMITTED')
2409 AND ced.order_header_id is not null
2410 AND ced.source_code = 'DR'
2411 AND ced.estimate_detail_id = cpt.estimate_detail_id
2412 AND cra.repair_line_id = cpt.repair_line_id;
2413
2414
2415 -- Cursor that gets the serial number and lot number
2416 -- for the rcv txn id
2417 Cursor rcv_txn_serial_num (p_txn_id in number) is
2418 select rst.serial_num,
2419 rst.lot_num
2420 from rcv_serial_transactions rst,
2421 rcv_transactions rt
2422 where rt.transaction_id = p_txn_id
2423 and rst.transaction_id = rt.transaction_id;
2424
2425
2426 BEGIN
2427 -- Standard Start of API savepoint
2428 SAVEPOINT RMA_RCV_UPDATE;
2429
2430 -- Initialize API return status to success
2431 x_return_status := FND_API.G_RET_STS_SUCCESS;
2432
2433 -- Debug messages
2434 Debug('At the Beginning of RMA_RCV_UPDATE',l_mod_name,1);
2435 Debug('Repair Line Id ='||to_char(p_repair_line_id),l_mod_name,1);
2436
2437 -- Standard call to check for call compatibility.
2438 IF NOT FND_API.Compatible_API_Call (l_api_version,
2439 p_api_version,
2440 l_api_name ,
2441 G_PKG_NAME )
2442 THEN
2443 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2444 END IF;
2445
2446 -- Initialize message list if p_init_msg_list is set to TRUE.
2447 IF FND_API.to_Boolean( p_init_msg_list ) THEN
2448 FND_MSG_PUB.initialize;
2449 END IF;
2450
2451 -- Api body starts
2452
2453 -- Validate the repair line id
2454 -- bugfix 4423818 : We need to validate only if p_repair_line_id is NOT NULL
2455 IF(p_repair_line_id is NOT NULL ) THEN
2456 IF NOT(csd_process_util.validate_rep_line_id(p_repair_line_id)) THEN
2457 RAISE FND_API.G_EXC_ERROR;
2458 END IF;
2459 END IF;
2460
2461 -- Assign the number of processed records in this variable
2462 l_total_records := 0;
2463
2464 --bug#8261344
2465 l_warning_return:= FALSE;
2466 l_skip_record := FALSE;
2467
2468 -- Selects all the receipts lines that have accept,reject,deliver
2469 -- transaction type
2470 -- 1. Serialized
2471 -- BEFORE RECEIVING
2472 -- Repair Order
2473 -- RO NUM RO Type Qty SN rcvd Qty
2474 -- R1 RR 1 SN1
2475 -- Product Txn
2476 -- Prod Txn RO Num Est Line Est Qty SN Subinv rcvd Qty
2477 -- P1 R1 C1 1 SN1
2478 --
2479 -- AFTER RECEIVING and running the update program
2480 -- Repair Order
2481 -- RO NUM RO Type Qty SN rcvd Qty
2482 -- R1 RR 1 SN9 1
2483 --
2484 -- RCV Lines
2485 -- Txn Id Txn Type Parent Txn Id Ord Line Qty SN Subinv
2486 -- T1 ACCEPT L1
2487 -- T2 DELIVER T1 L1 1 SN9 FGI
2488 --
2489 -- Product Txn
2490 -- Prod Txn RO Num Est Line Est Qty SN Subinv Rcvd Qty
2491 -- P1 R1 C1 1 SN9 FGI 1
2492 --
2493 -- 2. Non-Serialized
2494 -- BEFORE RECEIVING
2495 -- Repair Order
2496 -- RO NUM RO Type Qty SN rcvd Qty
2497 -- R1 RR 3
2498 -- Product Txn
2499 -- Prod Txn RO Num Est Line Est Qty SN Subinv rcvd Qty
2500 -- P1 R1 C1 3
2501 -- AFTER SHIPMENT and running the update program
2502 -- Repair Order
2503 -- RO NUM RO Type Qty SN rcvd Qty rejected Qty
2504 -- R1 RR 3 2 1
2505 --
2506 -- RCV Lines
2507 -- Txn Id Txn Type Parent Txn Id Ord Line Qty SN Subinv
2508 -- T1 ACCEPT L1
2509 -- T2 DELIVER T1 L1 2 FGI
2510 -- T3 REJECT L1 1
2511 --
2512 -- Product Txn
2513 -- Prod Txn RO Num Est Line Est Qty SN Subinv rcvd Qty
2514 -- P1 R1 C1 3 FGI 2
2515 --
2516
2517 IF(p_repair_line_id is null) THEN
2518 If (p_past_num_of_days Is Null) Then
2519 OPEN RECEIPT_LINES;
2520 Else
2521 l_From_Date := sysdate - (p_past_num_of_days +1 ) ;
2522 l_TO_Date := Sysdate + 1;
2523 OPEN RECEIPT_LINES_BY_DATE(l_From_Date , l_To_Date); ----bug#6753684, 6742512
2524 End If;
2525 ELSE
2526 OPEN RECEIPT_LINES_RO(p_repair_line_id);
2527 END IF;
2528
2529
2530 LOOP
2531
2532 IF(p_repair_line_id is null) THEN
2533 If (p_past_num_of_days Is Null) Then
2534 FETCH RECEIPT_LINES INTO I;
2535 exit when RECEIPT_LINES%NOTFOUND;
2536 else
2537 FETCH RECEIPT_LINES_BY_DATE INTO I; ----bug#6753684, 6742512
2538 exit when RECEIPT_LINES_BY_DATE%NOTFOUND;
2539 end if;
2540 ELSE
2541 FETCH RECEIPT_LINES_RO INTO I;
2542 exit when RECEIPT_LINES_RO%NOTFOUND;
2543 END IF;
2544
2545
2546 BEGIN
2547 -- savepoint
2548 SAVEPOINT RECEIPT_LINES;
2549
2550 IF I.transaction_type = 'ACCEPT' THEN
2551 -- Log activities for the accept transaction
2552
2553 l_accept_qty := I.received_quantity;
2554 l_reject_qty := 0;
2555
2556 -- Initialize the activity rec
2557 l_activity_rec := INIT_ACTIVITY_REC ;
2558
2559 -- Assign the values for activity record
2560 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
2561 l_activity_rec.REPAIR_LINE_ID := I.repair_line_id;
2562 l_activity_rec.EVENT_CODE := 'IP';
2563 l_activity_rec.ACTION_CODE := 0;
2564 l_activity_rec.EVENT_DATE := I.received_date;
2565 l_activity_rec.QUANTITY := null;
2566 l_activity_rec.PARAMN1 := I.transaction_id;
2567 l_activity_rec.PARAMN2 := I.rma_header_id;
2568 l_activity_rec.PARAMN3 := l_accept_qty;
2569 l_activity_rec.PARAMN4 := l_reject_qty;
2570 l_activity_rec.PARAMN5 := I.line_id;
2571 l_activity_rec.PARAMC1 := I.rma_number;
2572 l_activity_rec.PARAMC2 := I.subinventory;
2573 l_activity_rec.OBJECT_VERSION_NUMBER := null;
2574
2575 -- Debug Messages
2576 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
2577
2578 -- Calling LOG_ACTIVITY for logging activity
2579 -- accept receiving txn
2580 LOG_ACTIVITY
2581 ( p_api_version => p_api_version,
2582 p_commit => p_commit,
2583 p_init_msg_list => p_init_msg_list,
2584 p_validation_level => p_validation_level,
2585 x_return_status => x_return_status,
2586 x_msg_count => x_msg_count,
2587 x_msg_data => x_msg_data,
2588 p_activity_rec => l_activity_rec );
2589
2590 -- Debug Messages
2591 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
2592 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
2593 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
2594 RAISE FND_API.G_EXC_ERROR;
2595 END IF;
2596
2597 ELSIF I.transaction_type = 'REJECT' then
2598 -- Log activities for the reject transactions
2599
2600 l_accept_qty := 0;
2601 l_reject_qty := I.received_quantity;
2602
2603 -- Initialize the activity rec
2604 l_activity_rec := INIT_ACTIVITY_REC ;
2605
2606 -- Assign the values for activity record
2607 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
2608 l_activity_rec.REPAIR_LINE_ID := I.repair_line_id;
2609 l_activity_rec.EVENT_CODE := 'IP';
2610 l_activity_rec.ACTION_CODE := 0;
2611 l_activity_rec.EVENT_DATE := I.received_date;
2612 l_activity_rec.QUANTITY := null;
2613 l_activity_rec.PARAMN1 := I.transaction_id;
2614 l_activity_rec.PARAMN2 := I.rma_header_id;
2615 l_activity_rec.PARAMN3 := l_accept_qty;
2616 l_activity_rec.PARAMN4 := l_reject_qty;
2617 l_activity_rec.PARAMN5 := I.line_id;
2618 l_activity_rec.PARAMC1 := I.rma_number;
2619 l_activity_rec.PARAMC2 := I.subinventory;
2620 l_activity_rec.OBJECT_VERSION_NUMBER := null;
2621
2622 -- Debug Messages
2623 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
2624
2625 -- Calling LOG_ACTIVITY for logging activity
2626 -- reject receiving transactions
2627 LOG_ACTIVITY
2628 ( p_api_version => p_api_version,
2629 p_commit => p_commit,
2630 p_init_msg_list => p_init_msg_list,
2631 p_validation_level => p_validation_level,
2632 x_return_status => x_return_status,
2633 x_msg_count => x_msg_count,
2634 x_msg_data => x_msg_data,
2635 p_activity_rec => l_activity_rec );
2636
2637 -- Debug Messages
2638 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
2639 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
2640 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
2641 RAISE FND_API.G_EXC_ERROR;
2642 END IF;
2643
2644 ElSIF I.transaction_type = 'DELIVER' then
2645 --Log activities for the deliver transaction
2646 --Log actvities for the receipts of the item and the received serial number does
2647 --not match with the one on the product txns
2648
2649 --Debug messages
2650 Debug('Repair_Line_id ='||to_char(i.repair_line_id),l_mod_name,1);
2651 Debug('Rma Number ='||I.rma_number,l_mod_name,1);
2652 Debug('Transaction_id ='||to_char(i.transaction_id),l_mod_name,1);
2653 Debug('Inv_Item id ='||to_char(i.inventory_item_id),l_mod_name,1);
2654 Debug('Receiving Org ='||to_char(i.organization_id),l_mod_name,1);
2655
2656 -- Check if the item is serialized or non-serialized
2657 Begin
2658 select serial_number_control_code,
2659 lot_control_code,
2660 comms_nl_trackable_flag
2661 into l_srl_ctl_code,
2662 l_lot_ctl_code,
2663 l_ib_flag
2664 from mtl_system_items
2665 where inventory_item_id = i.inventory_item_id
2666 and organization_id = i.organization_id;
2667 Exception
2668 When no_data_found then
2669 IF ( l_error_level >= G_debug_level) THEN
2670 fnd_message.set_name('CSD','CSD_INV_ITEM_ID');
2671 fnd_message.set_token('ITEM_ID',I.inventory_item_id);
2672 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
2673 ELSE
2674 fnd_message.set_name('CSD','CSD_INV_ITEM_ID');
2675 fnd_message.set_token('ITEM_ID',I.inventory_item_id);
2676 fnd_msg_pub.add;
2677 END IF;
2678 RAISE FND_API.G_EXC_ERROR;
2679 When others then
2680 Debug('In Others exception',l_mod_name,4);
2681 RAISE FND_API.G_EXC_ERROR;
2682 End;
2683
2684 Debug('Serial Num Ctl Code ='||TO_CHAR(l_srl_ctl_code),l_mod_name,1);
2685 Debug('Lot Ctl Code ='||TO_CHAR(l_lot_ctl_code),l_mod_name,1);
2686 Debug('IB Flag ='||l_ib_flag,l_mod_name,1);
2687
2688 IF l_srl_ctl_code in (2,5,6) THEN
2689
2690 -- Item is serialized
2691 -- Opening the cursor for getting the received
2692 -- serial number
2693 Open rcv_txn_serial_num(i.transaction_id );
2694 Fetch rcv_txn_serial_num into l_st_serial_num, l_lot_number;
2695 IF (rcv_txn_serial_num%NOTFOUND) THEN
2696 IF ( l_error_level >= G_debug_level) THEN
2697 FND_MESSAGE.SET_NAME('CSD','CSD_SERIAL_NUM_MISSING');
2698 FND_MESSAGE.SET_TOKEN('TXN_ID',i.transaction_id);
2699 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
2700 ELSE
2701 FND_MESSAGE.SET_NAME('CSD','CSD_SERIAL_NUM_MISSING');
2702 FND_MESSAGE.SET_TOKEN('TXN_ID',i.transaction_id);
2703 FND_MSG_PUB.ADD;
2704 END IF;
2705 RAISE FND_API.G_EXC_ERROR;
2706 END IF;
2707 -- Close the cursor
2708 If rcv_txn_serial_num %isopen then
2709 close rcv_txn_serial_num ;
2710 End if;
2711
2712 Debug('Rcv Txn Serial_num ='||l_st_serial_num,l_mod_name,1);
2713 Debug('Prod Txn serial_num ='||I.SOURCE_SERIAL_NUMBER,l_mod_name,1);
2714 Debug('Lot number ='||l_lot_number,l_mod_name,1);
2715 -- swai debug 12547701:
2716 -- uncomment this line for debugging to test IB instance discrepancy
2717 -- l_st_serial_num := 'SWTEST';
2718
2719 -- Get the instance Id from the rcvd serial number
2720 IF NVL(l_ib_flag,'N') = 'Y' THEN
2721 BEGIN
2722 Select instance_id
2723 into l_instance_id
2724 from csi_item_instances
2725 where inventory_item_id = I.inventory_item_id
2726 and serial_number = l_st_serial_num; --bug#8261344
2727 --and instance_usage_code = 'IN_INVENTORY';
2728 EXCEPTION
2729 WHEN NO_DATA_FOUND THEN
2730 IF ( l_error_level >= G_debug_level) THEN
2731 FND_MESSAGE.SET_NAME('CSD','CSD_INSTANCE_MISSING');
2732 FND_MESSAGE.SET_TOKEN('SERIAL_NUM',l_st_serial_num);
2733 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
2734 FND_MSG_PUB.ADD; -- swai: bug 12547701 need to add message to the stack
2735 ELSE
2736 FND_MESSAGE.SET_NAME('CSD','CSD_INSTANCE_MISSING');
2737 FND_MESSAGE.SET_TOKEN('SERIAL_NUM',l_st_serial_num);
2738 FND_MSG_PUB.ADD;
2739 END IF;
2740
2741 --RAISE FND_API.G_EXC_ERROR;
2742 --bug#8261344
2743 -- swai: bug 12547701 updated if statement
2744 IF(NVL(fnd_profile.value('CSD_LOGISTICS_PROGRAM_ERROR'), 'S') = 'S') THEN
2745 RAISE FND_API.G_EXC_ERROR;
2746 else
2747 l_skip_record := TRUE;
2748 l_warning_return := TRUE;
2749 end if;
2750
2751 Debug(' Could not find any IB instance for the Serial Num ='||l_st_serial_num, l_mod_name,1);
2752 WHEN TOO_MANY_ROWS THEN
2753 IF ( l_error_level >= G_debug_level) THEN
2754 FND_MESSAGE.SET_NAME('CSD','CSD_FOUND_MANY_INSTANCE');
2755 FND_MESSAGE.SET_TOKEN('SERIAL_NUM',l_st_serial_num);
2756 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
2757 FND_MSG_PUB.ADD; -- swai: bug 12547701 need to add message to the stack
2758 ELSE
2759 FND_MESSAGE.SET_NAME('CSD','CSD_FOUND_MANY_INSTANCE');
2760 FND_MESSAGE.SET_TOKEN('SERIAL_NUM',l_st_serial_num);
2761 FND_MSG_PUB.ADD;
2762 END IF;
2763 RAISE FND_API.G_EXC_ERROR;
2764 Debug(' Found many IB instance for the Serial Num ='||l_st_serial_num, l_mod_name,1);
2765 END;
2766 ELSE
2767 l_instance_id := NULL;
2768 END IF;
2769
2770 -- If the item on prod txn is same as the order line and
2771 -- the serial number does not match with the received serial number
2772 -- then log activity for serial number mismatch
2773 IF (l_st_serial_num <> I.SOURCE_SERIAL_NUMBER) AND
2774 (I.prod_txn_item_id = I.inventory_item_id) and NOT(l_skip_record) THEN --bug#8261344
2775
2776
2777 -- Initialize the activity rec
2778 l_activity_rec := INIT_ACTIVITY_REC ;
2779
2780 -- Assign the values for activity record
2781 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
2782 l_activity_rec.REPAIR_LINE_ID := I.repair_line_id;
2783 l_activity_rec.EVENT_CODE := 'RSC';
2784 l_activity_rec.ACTION_CODE := 0;
2785 l_activity_rec.EVENT_DATE := I.received_date;
2786 l_activity_rec.QUANTITY := null;
2787 l_activity_rec.PARAMN1 := I.transaction_id;
2788 l_activity_rec.PARAMN2 := i.rma_line_number;
2789 l_activity_rec.PARAMN6 := I.rma_header_id;
2790 l_activity_rec.PARAMC1 := I.subinventory;
2791 l_activity_rec.PARAMC2 := I.rma_number;
2792 l_activity_rec.PARAMC3 := I.source_serial_number; -- prod txn serial num
2793 l_activity_rec.PARAMC4 := l_st_serial_num; -- rcvd serial num
2794 l_activity_rec.OBJECT_VERSION_NUMBER := null;
2795
2796 -- Debug Messages
2797 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
2798
2799 -- Calling LOG_ACTIVITY for logging activity
2800 -- Serial number mismatch
2801 LOG_ACTIVITY
2802 ( p_api_version => p_api_version,
2803 p_commit => p_commit,
2804 p_init_msg_list => p_init_msg_list,
2805 p_validation_level => p_validation_level,
2806 x_return_status => x_return_status,
2807 x_msg_count => x_msg_count,
2808 x_msg_data => x_msg_data,
2809 p_activity_rec => l_activity_rec );
2810
2811 -- Debug Messages
2812 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
2813 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
2814 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
2815 RAISE FND_API.G_EXC_ERROR;
2816 END IF;
2817 End IF; --end for IF (l_st_serial_num <> I.SOURCE_SERIAL_NUMBER)
2818
2819 ELSE ---esle for IF l_srl_ctl_code in (2,5,6)
2820 -- Non-Serialized item
2821 l_st_serial_num := NULL;
2822
2823 IF nvl(l_ib_flag,'N')= 'Y' THEN
2824 l_instance_id := I.source_instance_id;
2825 Else
2826 l_instance_id := NULL;
2827 End if;
2828
2829 --lot_control_code = 1 No control
2830 --lot_control_code = 2 Full control
2831 IF l_lot_ctl_code = 2 THEN
2832 BEGIN
2833 Select lot_num
2834 into l_lot_number
2835 from rcv_lot_transactions
2836 where source_transaction_id = I.transaction_id;
2837 EXCEPTION
2838 WHEN NO_DATA_FOUND THEN
2839 IF ( l_error_level >= G_debug_level) THEN
2840 fnd_message.set_name('CSD','CSD_INV_ITEM_ID');
2841 fnd_message.set_token('ITEM_ID',I.inventory_item_id);
2842 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
2843 ELSE
2844 fnd_message.set_name('CSD','CSD_INV_ITEM_ID');
2845 fnd_message.set_token('ITEM_ID',I.inventory_item_id);
2846 fnd_msg_pub.add;
2847 END IF;
2848 RAISE FND_API.G_EXC_ERROR;
2849
2850 --bug#16017759
2851 WHEN TOO_MANY_ROWS THEN
2852 -- that means multiple lotnumbers were entered during receipt (repair_quantity > 1)
2853 -- bug 160177759
2854 --l_lot_number := '<multiple>';
2855 l_lot_number := NULL; --we will update null value to column: lot number on the csd_product_transactions
2856 --bug#16017759
2857 END;
2858 ELSE
2859 l_lot_number := NULL;
2860 END IF; --end for IF l_lot_ctl_code = 2
2861 END IF; -- End of logging activity for SN change
2862
2863
2864 If NOT(l_skip_record) Then --bug#8261344
2865 Debug('inside of l_skip record ',l_mod_name,2);
2866
2867 -- Only if the item on RO matches with the item
2868 -- on order_line_id, call the convert api
2869 IF I.ro_item_id = I.inventory_item_id THEN
2870
2871 Debug('Calling CONVERT_TO_RO_UOM ',l_mod_name,2);
2872 -- Converting the received qty to UOM
2873 -- on the repair order
2874 CONVERT_TO_RO_UOM
2875 ( x_return_status => x_return_status
2876 ,p_to_uom_code => i.ro_uom
2877 ,p_item_id => i.inventory_item_id
2878 ,p_from_uom => i.unit_of_measure
2879 ,p_from_uom_code => NULL
2880 ,p_from_quantity => i.received_quantity
2881 ,x_result_quantity => l_result_quantity);
2882
2883 Debug('Return Status from CONVERT_TO_RO_UOM '||x_return_status,l_mod_name,2);
2884 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
2885 Debug('CONVERT_TO_RO_UOM failed ',l_mod_name,4);
2886 RAISE FND_API.G_EXC_ERROR;
2887 END IF;
2888 Else
2889 l_result_quantity := NVL(i.received_quantity,0);
2890 END IF;
2891 Debug('l_result_quantity='||TO_CHAR(l_result_quantity),l_mod_name,1);
2892
2893 -- Update csd_repairs only if the action code is
2894 -- cust_prod or exchange ----bug#10099900
2895 IF (I.action_code in ( 'CUST_PROD','EXCHANGE') and I.action_type in ('RMA')) then
2896
2897 IF I.ro_item_id = I.inventory_item_id THEN
2898 -- Update the serial num and instance id if the item on ro
2899 -- is same as prod txn
2900 update csd_repairs
2901 set quantity_rcvd = nvl(quantity_rcvd,0)+ l_result_quantity,
2902 object_version_number = object_version_number+1,
2903 customer_product_id = l_instance_id,
2904 serial_number = l_st_serial_num,
2905 last_update_date = sysdate,
2906 last_updated_by = fnd_global.user_id,
2907 last_update_login = fnd_global.login_id
2908 where repair_line_id = I.repair_line_id;
2909 IF SQL%NOTFOUND THEN
2910 IF ( l_error_level >= G_debug_level) THEN
2911 fnd_message.set_name('CSD','CSD_RO_UPD_FAILED');
2912 fnd_message.set_token('REPAIR_LINE_ID',I.repair_line_id);
2913 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
2914 ELSE
2915 fnd_message.set_name('CSD','CSD_RO_UPD_FAILED');
2916 fnd_message.set_token('REPAIR_LINE_ID',I.repair_line_id);
2917 fnd_msg_pub.add;
2918 END IF;
2919 RAISE FND_API.G_EXC_ERROR;
2920 END IF;
2921
2922 ELSE
2923 -- Update the qty if the item on ro
2924 -- is not same as prod txn
2925 update csd_repairs
2926 set quantity_rcvd = nvl(quantity_rcvd,0)+ l_result_quantity,
2927 object_version_number = object_version_number+1,
2928 last_update_date = sysdate,
2929 last_updated_by = fnd_global.user_id,
2930 last_update_login = fnd_global.login_id
2931 where repair_line_id = I.repair_line_id;
2932 IF SQL%NOTFOUND THEN
2933 IF ( l_error_level >= G_debug_level) THEN
2934 fnd_message.set_name('CSD','CSD_RO_UPD_FAILED');
2935 fnd_message.set_token('REPAIR_LINE_ID',I.repair_line_id);
2936 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
2937 ELSE
2938 fnd_message.set_name('CSD','CSD_RO_UPD_FAILED');
2939 fnd_message.set_token('REPAIR_LINE_ID',I.repair_line_id);
2940 fnd_msg_pub.add;
2941 END IF;
2942 RAISE FND_API.G_EXC_ERROR;
2943 END IF;
2944
2945 END IF;
2946 End If;
2947
2948 IF nvl(I.prod_txn_recd_qty,0) + nvl(I.received_quantity,0) = I.estimate_quantity THEN
2949 l_prod_txn_status := 'RECEIVED';
2950 ELSE
2951 l_prod_txn_status := 'BOOKED';
2952 END IF;
2953
2954 -- Update the quantity received,locator id, lot number
2955 Update csd_product_transactions
2956 set sub_inventory = I.subinventory,
2957 locator_id = I.locator_id,
2958 lot_number_rcvd = l_lot_number,
2959 source_instance_id = l_instance_id,
2960 source_serial_number = l_st_serial_num,
2961 quantity_received = nvl(quantity_received,0) + nvl(I.received_quantity,0),
2962 prod_txn_status = l_prod_txn_status,
2963 object_version_number = object_version_number+1,
2964 last_update_date = sysdate,
2965 last_updated_by = fnd_global.user_id,
2966 last_update_login = fnd_global.login_id
2967 WHERE product_transaction_id = i.product_transaction_id;
2968 IF SQL%NOTFOUND THEN
2969 IF ( l_error_level >= G_debug_level) THEN
2970 fnd_message.set_name('CSD','CSD_PROD_TXN_UPD_FAILED');
2971 fnd_message.set_token('PROD_TXN_ID',I.product_transaction_id);
2972 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
2973 ELSE
2974 fnd_message.set_name('CSD','CSD_PROD_TXN_UPD_FAILED');
2975 fnd_message.set_token('PROD_TXN_ID',I.product_transaction_id);
2976 fnd_msg_pub.add;
2977 END IF;
2978 RAISE FND_API.G_EXC_ERROR;
2979 END IF;
2980
2981 fnd_message.set_name('CSD','CSD_DRC_RMA_RECEIPT');
2982 fnd_message.set_token('RMA_NO',i.rma_number);
2983 fnd_message.set_token('REP_NO',i.repair_number);
2984 fnd_message.set_token('QTY_RCVD',to_char(i.received_quantity));
2985 FND_MSG_PUB.ADD;
2986
2987 --bug#13505961
2988 --need to update the received organization_id
2989 UPDATE CS_ESTIMATE_DETAILS
2990 set transaction_inventory_org = i.organization_id
2991 where estimate_detail_id = (select estimate_detail_id from CSD_PRODUCT_TRANSACTIONS
2992 where product_transaction_id = i.product_transaction_id);
2993
2994 --bug#13505961
2995
2996 -- Debug message
2997 Debug(fnd_message.get,l_mod_name,1);
2998
2999 -- Log messages in concurrent log and output file
3000 fnd_file.put_line(fnd_file.log, fnd_message.get);
3001
3002 -- Initialize the activity rec
3003 l_activity_rec := INIT_ACTIVITY_REC ;
3004
3005 -- Assign the values for activity record
3006 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
3007 l_activity_rec.REPAIR_LINE_ID := I.repair_line_id;
3008 l_activity_rec.EVENT_CODE := 'RR';
3009 l_activity_rec.ACTION_CODE := 0;
3010 l_activity_rec.EVENT_DATE := I.received_date;
3011 l_activity_rec.QUANTITY := I.received_quantity;
3012 l_activity_rec.PARAMN1 := I.transaction_id;
3013 l_activity_rec.PARAMN2 := i.rma_line_number;
3014 l_activity_rec.PARAMN3 := i.organization_id;
3015 l_activity_rec.PARAMN6 := I.rma_header_id;
3016 l_activity_rec.PARAMC1 := I.subinventory;
3017 l_activity_rec.PARAMC2 := I.rma_number;
3018 l_activity_rec.PARAMC3 := I.org_name;
3019 l_activity_rec.OBJECT_VERSION_NUMBER := null;
3020
3021 -- Debug Messages
3022 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
3023
3024 -- Calling LOG_ACTIVITY for logging activity
3025 -- receipt of the item
3026 LOG_ACTIVITY
3027 ( p_api_version => p_api_version,
3028 p_commit => p_commit,
3029 p_init_msg_list => p_init_msg_list,
3030 p_validation_level => p_validation_level,
3031 x_return_status => x_return_status,
3032 x_msg_count => x_msg_count,
3033 x_msg_data => x_msg_data,
3034 p_activity_rec => l_activity_rec );
3035
3036 -- Debug Messages
3037 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
3038 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
3039 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
3040 RAISE FND_API.G_EXC_ERROR;
3041 END IF;
3042
3043 -- subhat, resolve by date enhancement. Calculate resolve by date if calculation is set as RMA_RECEIPT.
3044 IF I.action_code IN ( 'CUST_PROD','EXCHANGE') AND I.action_type in ('RMA')
3045 THEN
3046 IF I.ro_item_id = I.inventory_item_id
3047 THEN
3048 SELECT crtb.res_dt_calc_point,crtb.business_process_id,
3049 cs.incident_severity_id,cr.contract_line_id
3050 INTO l_resolve_date_calc_at,l_business_process_id,l_severity_id,
3051 l_contract_line_id
3052 FROM csd_repairs cr, csd_repair_types_b crtb,cs_incidents_all_b cs
3053 WHERE cr.repair_line_id = i.repair_line_id
3054 AND cr.repair_type_id = crtb.repair_type_id
3055 AND cr.incident_id = cs.incident_id;
3056
3057 IF l_resolve_date_calc_at = 'RMA_RECEIPT' AND l_contract_line_id IS NOT NULL
3058 THEN
3059 -- get resolve by date
3060 csd_repairs_util.get_contract_resolve_by_date(
3061 p_contract_line_id => l_contract_line_id,
3062 p_bus_proc_id => l_business_process_id,
3063 p_severity_id => l_severity_id,
3064 p_request_date => i.received_date,
3065 x_return_status => x_return_status,
3066 x_msg_count => x_msg_count,
3067 x_msg_data => x_msg_data,
3068 x_resolve_by_date => x_resolve_by_date);
3069 -- all errors from this API should not be raised. We log it as an error message.
3070 IF x_return_status <> fnd_api.g_ret_sts_success
3071 THEN
3072 Debug('The resolve by date calculation errored out.',l_mod_name,1);
3073 Debug('Possibly a missing contracts setup.',l_mod_name,1);
3074 Debug('message count is '||x_msg_count||' and message data is '||x_msg_data,l_mod_name,1);
3075 END IF;
3076 -- we dont need a NVL for x_resolve_by_date or comparision with FND_API.g_miss_date.
3077 -- in case the get_contract_resolve_by_date errors out, it should not corrupt the out
3078 -- variable.
3079
3080 UPDATE csd_repairs SET resolve_by_date = x_resolve_by_date
3081 WHERE repair_line_id = i.repair_line_id;
3082 END IF;
3083 END IF;
3084 END IF;
3085
3086 End if; --end if NOT(l_skip_record) --bug#8261344
3087
3088 END IF;
3089
3090 -- Commit for every 500 records
3091 -- one should COMMIT less frequently within a PL/SQL loop to
3092 -- prevent ORA-1555 (Snapshot too old) errors
3093
3094 --bug#8261344
3095 If NOT(l_skip_record) Then
3096 l_total_records := l_total_records + 1;
3097 end if;
3098 IF mod(l_total_records, l_commit_size) = 0 THEN -- Commit every 500 records
3099 IF FND_API.To_Boolean( p_commit ) THEN
3100 COMMIT WORK;
3101 END IF;
3102 END IF;
3103
3104 --bug#8261344
3105 l_skip_record := FALSE;
3106
3107 EXCEPTION
3108 WHEN FND_API.G_EXC_ERROR THEN
3109 ROLLBACK TO RECEIPT_LINES;
3110 x_return_status := FND_API.G_RET_STS_ERROR ;
3111 EXIT;
3112 -- In case of error, exit the loop. Commit the processed records
3113 -- and rollback the error record
3114 -- RAISE FND_API.G_EXC_ERROR;
3115 WHEN SKIP_RECORD THEN
3116 NULL;
3117 END;
3118 END LOOP;
3119
3120
3121 ------------ process cancelled orders.
3122 Debug('processing cancelled orders in RMA_RCV_UPDATE',l_mod_name,1);
3123 if(p_repair_line_id is not null) then
3124 Debug('processing repairline['||p_repair_line_id||']',l_mod_name,1);
3125 Check_for_Cancelled_order(p_repair_line_id);
3126 else
3127 FOR Repln_Rec in Cur_Cancelled_repair_lines
3128 LOOP
3129 Debug('processing repairline['||repln_rec.repair_line_id||']',l_mod_name,1);
3130 check_for_cancelled_order(Repln_rec.Repair_line_id);
3131 END LOOP;
3132 End if;
3133 Debug('At the end of processing cancelled orders in RMA_RCV_UPDATE',l_mod_name,1);
3134 -----------------------
3135
3136
3137 --Added by Vijay 11/4/04
3138 IF(RECEIPT_LINES%ISOPEN) THEN
3139 CLOSE RECEIPT_LINES;
3140 END IF;
3141 IF(RECEIPT_LINES_RO%ISOPEN) THEN
3142 CLOSE RECEIPT_LINES_RO;
3143 END IF;
3144
3145 IF(RECEIPT_LINES_BY_DATE%ISOPEN) THEN
3146 CLOSE RECEIPT_LINES_BY_DATE;
3147 END IF;
3148
3149 -- Log seed messages for the number of records
3150 -- processed by rma update
3151 fnd_message.set_name('CSD','CSD_DRC_RMA_TOT_REC_PROC');
3152 fnd_message.set_token('TOT_REC',to_char(l_total_records));
3153 FND_MSG_PUB.ADD;
3154
3155 -- Debug Messages
3156 Debug(fnd_message.get,l_mod_name,1);
3157
3158 -- Log the number of records processed in concurrent
3159 -- program output and log file
3160 fnd_file.put_line(fnd_file.log,fnd_message.get);
3161 fnd_file.put_line(fnd_file.output,fnd_message.get);
3162
3163 -- Standard check of p_commit.
3164 IF FND_API.To_Boolean( p_commit ) THEN
3165 COMMIT WORK;
3166 END IF;
3167
3168 --bug#8261344
3169 If (l_warning_return) THEN
3170 x_return_status := G_CSD_RET_STS_WARNING;
3171 End if;
3172
3173 -- Standard call to get message count and IF count is get message info.
3174 FND_MSG_PUB.Count_And_Get
3175 (p_count => x_msg_count,
3176 p_data => x_msg_data );
3177 EXCEPTION
3178 WHEN FND_API.G_EXC_ERROR THEN
3179 Debug('In FND_API.G_EXC_ERROR exception',l_mod_name,4 );
3180 ROLLBACK TO RMA_RCV_UPDATE;
3181 x_return_status := FND_API.G_RET_STS_ERROR ;
3182 FND_MSG_PUB.Count_And_Get
3183 (p_count => x_msg_count,
3184 p_data => x_msg_data );
3185 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3186 Debug('In FND_API.G_EXC_UNEXPECTED_ERROR exception',l_mod_name,4 );
3187 ROLLBACK TO RMA_RCV_UPDATE;
3188 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
3189 FND_MSG_PUB.Count_And_Get
3190 ( p_count => x_msg_count,
3191 p_data => x_msg_data );
3192 WHEN OTHERS THEN
3193 Debug('In OTHERS exception',l_mod_name,4 );
3194 ROLLBACK TO RMA_RCV_UPDATE;
3195 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
3196 IF FND_MSG_PUB.Check_Msg_Level
3197 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3198 THEN
3199 FND_MSG_PUB.Add_Exc_Msg
3200 (G_PKG_NAME ,
3201 l_api_name );
3202 END IF;
3203 FND_MSG_PUB.Count_And_Get
3204 (p_count => x_msg_count,
3205 p_data => x_msg_data );
3206 END RMA_RCV_UPDATE;
3207
3208 /*-------------------------------------------------------------------------------------*/
3209 /* Procedure name: IO_RCV_UPDATE */
3210 /* Description : Procedure called from the Update api to update the depot tables */
3211 /* for the receipts against Internal Requisitions */
3212 /* It also logs activities for accept reject txn lines */
3213 /* Called from : Called from RECEIPTS_UPDATE API */
3214 /* STANDARD PARAMETERS */
3215 /* In Parameters : */
3216 /* p_api_version NUMBER Required Api Version number */
3217 /* p_init_msg_list VARCHAR2 Optional To Initialize message stack */
3218 /* p_commit VARCHAR2 Optional Commits in API */
3219 /* p_validation_level NUMBER Optional validation level */
3220 /* */
3221 /* Output Parameters: */
3222 /* x_return_status VARCHAR2 Return status of the API */
3223 /* x_msg_count NUMBER Number of messages in stack */
3224 /* x_msg_data VARCHAR2 Error Message from message stack */
3225 /* */
3226 /* NON-STANDARD PARAMETERS */
3227 /* In Parameters */
3228 /* p_order_header_id NUMBER Optional Internal sales order Id */
3229 /* Output Parm : */
3230 /* Change Hist : */
3231 /* 09/20/03 vlakaman Initial Creation. */
3232 /*-------------------------------------------------------------------------------------*/
3233
3234 Procedure IO_RCV_UPDATE
3235 ( p_api_version IN NUMBER,
3236 p_commit IN VARCHAR2,
3237 p_init_msg_list IN VARCHAR2,
3238 p_validation_level IN NUMBER,
3239 x_return_status OUT NOCOPY VARCHAR2,
3240 x_msg_count OUT NOCOPY NUMBER,
3241 x_msg_data OUT NOCOPY VARCHAR2,
3242 p_order_header_id IN NUMBER
3243 ) IS
3244
3245 -- Standard variables
3246 l_api_name CONSTANT VARCHAR2(30) := 'IO_RCV_UPDATE';
3247 l_api_version CONSTANT NUMBER := 1.0;
3248
3249 -- Variables used in API
3250 l_rep_hist_id number;
3251 l_dummy varchar2(30);
3252 l_serialized_flag boolean;
3253 l_ord_remaining_qty number := 0;
3254 l_prod_txn_exists boolean;
3255 l_prod_txn_id number := NULL;
3256 l_prod_txn_status csd_product_transactions.prod_txn_status%type;
3257 l_total_qty number;
3258 l_total_del_qty number;
3259 l_total_accept_qty number;
3260 l_total_reject_qty number;
3261 l_pt_accept_qty number;
3262 l_pt_reject_qty number;
3263 l_pt_del_qty number;
3264 l_accept_qty number;
3265 l_reject_qty number;
3266 l_serial_num MTL_SERIAL_NUMBERS.SERIAL_NUMBER%TYPE;
3267 l_lot_num MTL_LOT_NUMBERS.LOT_NUMBER%TYPE;
3268 l_rep_line_id number;
3269 l_rcvd_qty number;
3270 l_line_qty number;
3271 l_line_del_qty number;
3272 l_sub_inv varchar2(80);
3273 l_instance_id number;
3274
3275 -- activity record
3276 l_activity_rec activity_rec_type;
3277
3278 -- Variable for the FND log file
3279 l_error_level number := FND_LOG.LEVEL_ERROR;
3280 l_mod_name varchar2(2000) := 'csd.plsql.csd_update_programs_pvt.io_rcv_update';
3281
3282 -- User defined exception
3283 SKIP_RECORD EXCEPTION;
3284 PROCESS_ERROR EXCEPTION;
3285
3286 -- Cursor to get the ro and product txn lines
3287 --
3288 CURSOR GET_RO_PROD_TXN_LINES_ALL IS
3289 select cpt.product_transaction_id,
3290 cpt.prod_txn_status,
3291 cpt.repair_line_id,
3292 cpt.order_header_id,
3293 cpt.order_line_id,
3294 cpt.req_header_id,
3295 cpt.req_line_id,
3296 nvl(cpt.quantity_received,0) prod_txn_rcvd_qty,
3297 cra.quantity ro_qty,
3298 cra.quantity_rcvd ro_rcvd_qty,
3299 cra.inventory_item_id,
3300 cra.unit_of_measure ro_uom,
3301 prh.segment1 requisition_number,
3302 oel.ordered_quantity,
3303 oeh.order_number
3304 from csd_product_transactions cpt,
3305 csd_repairs cra,
3306 po_requisition_headers_all prh,
3307 oe_order_lines_all oel,
3308 oe_order_headers_all oeh
3309 where cpt.repair_line_id = cra.repair_line_id
3310 AND cpt.req_header_id = prh.requisition_header_id
3311 AND cpt.order_line_id = oel.line_id
3312 AND oel.header_id = oeh.header_id
3313 AND cpt.action_type = 'MOVE_IN'
3314 AND cpt.action_code = 'DEFECTIVES'
3315 AND cpt.prod_txn_status = 'SHIPPED'
3316 AND cpt.order_line_id is not null
3317 --Vijay 11/4/04
3318 -- AND (p_ord_header_id IS null OR p_ord_header_id = cpt.order_header_id)
3319 AND nvl(cra.quantity_rcvd,0) < cra.quantity;
3320
3321 --Begin Vijay 11/4/04
3322 -- Cursor to get the ro and product txn lines
3323 -- for the order header id
3324 CURSOR GET_RO_PROD_TXN_LINES (p_ord_header_id in number) IS
3325 select cpt.product_transaction_id,
3326 cpt.prod_txn_status,
3327 cpt.repair_line_id,
3328 cpt.order_header_id,
3329 cpt.order_line_id,
3330 cpt.req_header_id,
3331 cpt.req_line_id,
3332 nvl(cpt.quantity_received,0) prod_txn_rcvd_qty,
3333 cra.quantity ro_qty,
3334 cra.quantity_rcvd ro_rcvd_qty,
3335 cra.inventory_item_id,
3336 cra.unit_of_measure ro_uom,
3337 prh.segment1 requisition_number,
3338 oel.ordered_quantity,
3339 oeh.order_number
3340 from csd_product_transactions cpt,
3341 csd_repairs cra,
3342 po_requisition_headers_all prh,
3343 oe_order_lines_all oel,
3344 oe_order_headers_all oeh
3345 where cpt.repair_line_id = cra.repair_line_id
3346 AND cpt.req_header_id = prh.requisition_header_id
3347 AND cpt.order_line_id = oel.line_id
3348 AND oel.header_id = oeh.header_id
3349 AND cpt.action_type = 'MOVE_IN'
3350 AND cpt.action_code = 'DEFECTIVES'
3351 AND cpt.prod_txn_status = 'SHIPPED'
3352 AND cpt.order_line_id is not null
3353 AND cpt.order_header_id = p_ord_header_id
3354 AND nvl(cra.quantity_rcvd,0) < cra.quantity;
3355
3356 RO IO_RCPT_LINES_Rec_Type;
3357 --End Vijay 11/4/04
3358
3359
3360 -- Cursor to get all the rcv txn lines of transaction type
3361 -- DELIVER,REJECT,ACCEPT type
3362 CURSOR GET_RCV_LINES (p_req_line_id in number) IS
3363 select rcv.transaction_id,
3364 rcv.quantity rcvd_qty,
3365 rcv.unit_of_measure,
3366 rcv.subinventory,
3367 rcv.locator_id,
3368 rcv.organization_id,
3369 rcv.transaction_date received_date,
3370 rcv.transaction_type,
3371 rcv.shipment_header_id,
3372 rcv.shipment_line_id,
3373 prl.item_id,
3374 prl.destination_organization_id inv_org_id,
3375 prl.quantity requisition_qty,
3376 prh.segment1 requirement_number,
3377 mtl.serial_number_control_code,
3378 mtl.comms_nl_trackable_flag ib_flag,
3379 mtl.lot_control_code,
3380 hao.name org_name
3381 from rcv_transactions rcv,
3382 po_requisition_lines_all prl,
3383 po_requisition_headers_all prh,
3384 mtl_system_items mtl,
3385 hr_all_organization_units hao
3386 where rcv.requisition_line_id = prl.requisition_line_id
3387 and prl.item_id = mtl.inventory_item_id
3388 and prl.destination_organization_id = mtl.organization_id
3389 and prl.requisition_header_id = prh.requisition_header_id
3390 and rcv.requisition_line_id = p_req_line_id
3391 and hao.organization_id = rcv.organization_id
3392 and rcv.transaction_type in ('DELIVER','ACCEPT','REJECT');
3393
3394 -- Cursor to get the deliver txn line for the
3395 -- specific txn id
3396 CURSOR DELIVER_LINES (p_txn_id in number) IS
3397 Select rcvt.transaction_id,
3398 rcvt.transaction_date received_date,
3399 rcvt.subinventory,
3400 rcvt.quantity rcvd_qty,
3401 rcvt.organization_id,
3402 rcvt.locator_id,
3403 hao.name org_name
3404 from rcv_transactions rcvt,
3405 hr_all_organization_units hao
3406 where rcvt.parent_transaction_id = p_txn_id
3407 and rcvt.transaction_type = 'DELIVER';
3408
3409 CURSOR ORDER_INFO (p_ord_header_id in number) IS
3410 Select distinct
3411 order_header_id,
3412 order_line_id
3413 from csd_product_transactions
3414 where order_header_id = p_ord_header_id
3415 AND action_type = 'MOVE_IN'
3416 AND action_code = 'DEFECTIVES'
3417 AND prod_txn_status = 'SHIPPED';
3418
3419 BEGIN
3420 -- Standard Start of API savepoint
3421 SAVEPOINT IO_RCV_UPDATE;
3422
3423 -- Initialize API return status to success
3424 x_return_status := FND_API.G_RET_STS_SUCCESS;
3425
3426 -- Debug messages
3427 Debug('Beginning of IO_RCV_UPDATE',l_mod_name,1);
3428 Debug('Order Header Id='||to_char(p_order_header_id),l_mod_name,1);
3429
3430 -- Standard call to check for call compatibility.
3431 IF NOT FND_API.Compatible_API_Call (l_api_version,
3432 p_api_version,
3433 l_api_name ,
3434 G_PKG_NAME )
3435 THEN
3436 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3437 END IF;
3438
3439 -- Initialize message list if p_init_msg_list is set to TRUE.
3440 IF FND_API.to_Boolean( p_init_msg_list ) THEN
3441 FND_MSG_PUB.initialize;
3442 END IF;
3443
3444 -- Api body starts
3445
3446 -- In case of Internal orders, the product txns are stamped
3447 -- with the order header id and line id.
3448 -- So Validate if it exists in csd_product_transactions
3449 IF NVL(p_order_header_id,-999) <> -999 THEN
3450 BEGIN
3451 select 'EXISTS'
3452 into l_dummy
3453 from oe_order_headers_all oeh,
3454 po_requisition_headers_all prh
3455 where oeh.source_document_id = prh.requisition_header_id
3456 and oeh.header_id = p_order_header_id
3457 and exists (select 'x'
3458 from csd_product_transactions cpt
3459 where cpt.action_type = 'MOVE_IN'
3460 and cpt.action_code = 'DEFECTIVES'
3461 and cpt.order_header_id = oeh.header_id);
3462 EXCEPTION
3463 WHEN NO_DATA_FOUND THEN
3464 IF ( l_error_level >= G_debug_level) THEN
3465 fnd_message.set_name('CSD','CSD_INV_ORD_HEADER_ID');
3466 fnd_message.set_token('HEADER_ID',p_order_header_id);
3467 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
3468 ELSE
3469 fnd_message.set_name('CSD','CSD_INV_ORD_HEADER_ID');
3470 fnd_message.set_token('HEADER_ID',p_order_header_id);
3471 fnd_msg_pub.add;
3472 END IF;
3473 RAISE FND_API.G_EXC_ERROR;
3474 END;
3475 END IF;
3476
3477
3478 --Loops thro the received lines that have txn type -'DELIVER','ACCEPT','REJECT'
3479 --While Processing the ACCEPT/REJECT txn lines, it also check if there is
3480 --any deliver txn lines with the parent txn id. If it finds then it also
3481 --update the delivered qty and logs activity for the deliver txns.
3482 -- Order Line
3483 --
3484 -- Line Id Header Id Ord Qty Split_from_line_id
3485 -- L1 H1 1
3486 -- L2 H1 2 L1
3487 -- L3 H1 1 L2
3488 --
3489 -- RCV Lines
3490 -- Txn Id Txn Type Qty Ord Line Id Parent Txn Id
3491 -- T1 ACCEPT 1 L1
3492 -- T2 ACCEPT 2 L2
3493 -- T3 REJECT 1 L3
3494 -- T4 DELIVER 1 L1 T1
3495 -- T5 DELIVER 2 L2 T2
3496 --
3497 --
3498 -- 1. Non- Serial
3499 --
3500 -- RO RO Qty Prod Txn Ord Line Ord Header Line Qty
3501 -- RO1 4 P1 L1 H1 1
3502 -- RO1 4 P2 L2 H1 2
3503 -- RO1 4 P3 L3 H1 1
3504 -- 2. Serial
3505 --
3506 -- RO RO Qty Prod Txn Ord Line Ord Header Line Qty
3507 -- RO1 1 P1 L1 H1 1
3508 -- RO2 1 P2 L2 H1 1
3509 -- RO3 1 P3 L2 H1 1
3510 -- RO4 1 P4 L1 H1 1
3511 --
3512 -- THE PROGRAM IGNORES THE DELIVERED QUANTITY AGAINST THE REJECT TRANSACTIONS
3513 -- NEED TO REVIEW WITH PM AND IMPLEMENT AS A PHASE II PROJECT
3514
3515 IF(p_order_header_id is null) THEN
3516 OPEN GET_RO_PROD_TXN_LINES_All;
3517 else
3518 OPEN GET_RO_PROD_TXN_LINES(p_order_header_id);
3519 END IF;
3520
3521
3522 /* Changed FOr loop for splitting the cursor : vijay 11/4/04*/
3523 --FOR RO IN GET_RO_PROD_TXN_LINES( p_order_header_id )
3524 LOOP
3525 BEGIN
3526 IF(p_order_header_id is null) THEN
3527 FETCH GET_RO_PROD_TXN_LINES_All INTO RO;
3528 EXIT WHEN GET_RO_PROD_TXN_LINES_All%NOTFOUND ;
3529 else
3530 FETCH GET_RO_PROD_TXN_LINES INTO RO;
3531 EXIT WHEN GET_RO_PROD_TXN_LINES%NOTFOUND ;
3532 END IF;
3533
3534 -- savepoint
3535 SAVEPOINT RCV_LINES;
3536
3537 -- Debug messages
3538 Debug('In RO loop',l_mod_name,1);
3539
3540 FOR RCV IN GET_RCV_LINES (RO.req_line_id)
3541 LOOP
3542 BEGIN
3543 -- Debug messages
3544 Debug('In RCV loop',l_mod_name,1);
3545
3546 IF RCV.transaction_type = 'ACCEPT' THEN
3547 --Handles Inspection Required Routing options
3548
3549 -- Debug messages
3550 Debug('Processing Accept txn types',l_mod_name,1);
3551
3552 select nvl(sum(paramn3),0)
3553 into l_total_accept_qty
3554 from csd_repair_history crh
3555 where crh.event_code = 'IP'
3556 and crh.paramn1 = RCV.transaction_id;
3557
3558 -- Debug messages
3559 Debug('l_total_accept_qty :'||l_total_accept_qty,l_mod_name,1);
3560 IF nvl(l_total_accept_qty,0) >= nvl(RCV.rcvd_qty,0) THEN
3561 -- Debug messages
3562 Debug('Skipping the record ',l_mod_name,1);
3563 RAISE SKIP_RECORD;
3564 END IF;
3565
3566 select nvl(sum(paramn4),0), nvl(sum(paramn3),0)
3567 into l_pt_reject_qty, l_pt_accept_qty
3568 from csd_repair_history crh
3569 where crh.event_code = 'IP'
3570 and crh.paramn2 = RO.product_transaction_id;
3571 -- Debug messages
3572 Debug('l_pt_reject_qty :'||l_pt_reject_qty,l_mod_name,1);
3573 Debug('l_pt_accept_qty :'||l_pt_accept_qty,l_mod_name,1);
3574
3575 IF RCV.serial_number_control_code in (2,5,6) THEN
3576 l_line_qty := RO.ro_qty;
3577 ELSE
3578 l_line_qty := RO.ordered_quantity;
3579 END IF;
3580
3581 -- Debug messages
3582 Debug('l_line_qty :'||l_line_qty,l_mod_name,1);
3583
3584 IF (l_pt_reject_qty + l_pt_accept_qty) >= l_line_qty THEN
3585 -- Debug messages
3586 Debug('Exiting the RCV loop',l_mod_name,1);
3587 EXIT;
3588 ELSE
3589 l_accept_qty := l_line_qty -(l_pt_reject_qty + l_pt_accept_qty);
3590 IF RCV.rcvd_qty < l_accept_qty THEN
3591 l_accept_qty := RCV.rcvd_qty;
3592 END IF;
3593 END IF;
3594
3595
3596 IF RCV.serial_number_control_code in (2,5,6) THEN
3597 l_accept_qty := 1 ;
3598 ELSE
3599 l_accept_qty := l_accept_qty - l_total_accept_qty ;
3600 END IF;
3601
3602 -- Debug messages
3603 Debug('l_accept_qty :'||l_accept_qty,l_mod_name,1);
3604
3605 -- Initialize the activity rec
3606 l_activity_rec := INIT_ACTIVITY_REC ;
3607
3608 -- Assign the values for activity record
3609 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
3610 l_activity_rec.REPAIR_LINE_ID := RO.repair_line_id;
3611 l_activity_rec.EVENT_CODE := 'IP';
3612 l_activity_rec.ACTION_CODE := 0;
3613 l_activity_rec.EVENT_DATE := RCV.received_date;
3614 l_activity_rec.QUANTITY := l_accept_qty;
3615 l_activity_rec.PARAMN1 := RCV.transaction_id;
3616 l_activity_rec.PARAMN2 := RO.product_transaction_id;
3617 l_activity_rec.PARAMN3 := l_accept_qty;
3618 l_activity_rec.PARAMN6 := RO.req_header_id;
3619 l_activity_rec.PARAMC1 := RO.requisition_number ;
3620 l_activity_rec.PARAMC2 := RCV.subinventory;
3621 l_activity_rec.OBJECT_VERSION_NUMBER := null;
3622
3623 -- Debug Messages
3624 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
3625
3626 -- Calling LOG_ACTIVITY for logging activity
3627 LOG_ACTIVITY
3628 ( p_api_version => p_api_version,
3629 p_commit => p_commit,
3630 p_init_msg_list => p_init_msg_list,
3631 p_validation_level => p_validation_level,
3632 x_return_status => x_return_status,
3633 x_msg_count => x_msg_count,
3634 x_msg_data => x_msg_data,
3635 p_activity_rec => l_activity_rec );
3636
3637 -- Debug Messages
3638 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
3639 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
3640 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
3641 RAISE FND_API.G_EXC_ERROR;
3642 END IF;
3643
3644 -- Check if there are "DELIVER" txn lines against the accept lines
3645 -- If found, then process the deliver lines also
3646 FOR DEL IN DELIVER_LINES(RCV.transaction_id)
3647 LOOP
3648 BEGIN
3649 -- Debug messages
3650 Debug('In DEL Loop ',l_mod_name,1);
3651
3652 select nvl(sum(quantity),0)
3653 into l_total_del_qty
3654 from csd_repair_history crh
3655 where crh.event_code = 'RRI'
3656 and crh.paramn1 = DEL.transaction_id;
3657 -- Debug messages
3658 Debug('l_total_del_qty : '||l_total_del_qty,l_mod_name,1);
3659
3660 IF l_total_del_qty >= DEL.rcvd_qty THEN
3661 -- Debug messages
3662 Debug('Skipping the record',l_mod_name,1);
3663 RAISE SKIP_RECORD;
3664 END IF;
3665
3666 select nvl(sum(quantity),0)
3667 into l_pt_del_qty
3668 from csd_repair_history crh
3669 where crh.event_code = 'RRI'
3670 and crh.paramn2 = RO.product_transaction_id;
3671 -- Debug messages
3672 Debug('l_pt_del_qty : '||l_pt_del_qty,l_mod_name,1);
3673
3674 IF RCV.serial_number_control_code in (2,5,6) THEN
3675 -- SERIALIZED CASE
3676 Begin
3677 select rcvt.serial_num,
3678 rcvt.lot_num
3679 into l_serial_num,
3680 l_lot_num
3681 from rcv_serial_transactions rcvt
3682 where rcvt.transaction_id = DEL.transaction_id
3683 and rownum = 1
3684 and not exists (Select 'NOT EXIST'
3685 from csd_repairs cra,
3686 csd_product_transactions cpt
3687 where cra.repair_line_id = cpt.repair_line_id
3688 and cpt.action_type = 'MOVE_IN'
3689 and cpt.order_header_id = ro.order_header_id
3690 and cra.serial_number = rcvt.serial_num);
3691 Exception
3692 WHEN NO_DATA_FOUND THEN
3693 IF ( l_error_level >= G_debug_level) THEN
3694 fnd_message.set_name('CSD','CSD_SERIAL_NUM_MISSING');
3695 fnd_message.set_token('TXN_ID',DEL.transaction_id);
3696 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
3697 ELSE
3698 fnd_message.set_name('CSD','CSD_SERIAL_NUM_MISSING');
3699 fnd_message.set_token('TXN_ID',DEL.transaction_id);
3700 fnd_msg_pub.add;
3701 END If;
3702 RAISE PROCESS_ERROR;
3703 END;
3704 -- Get the instance id from
3705 -- installbase tables
3706 IF NVL(RCV.ib_flag,'N') = 'Y' THEN
3707 BEGIN
3708 Select instance_id
3709 into l_instance_id
3710 from csi_item_instances
3711 where inventory_item_id = RCV.item_id
3712 and serial_number = l_serial_num;
3713 Exception
3714 When NO_DATA_FOUND THEN
3715 IF ( l_error_level >= G_debug_level) THEN
3716 fnd_message.set_name('CSD','CSD_ITEM_INSTANCE_MISSING');
3717 fnd_message.set_token('SERIAL_NUM',l_serial_num);
3718 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
3719 ELSE
3720 fnd_message.set_name('CSD','CSD_ITEM_INSTANCE_MISSING');
3721 fnd_message.set_token('SERIAL_NUM',l_serial_num);
3722 fnd_msg_pub.add;
3723 END If;
3724 When Others THEN
3725 IF ( l_error_level >= G_debug_level) THEN
3726 fnd_message.set_name('CSD','CSD_INV_SERIAL_NUM');
3727 fnd_message.set_token('SERIAL_NUM',l_serial_num);
3728 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
3729 ELSE
3730 fnd_message.set_name('CSD','CSD_INV_SERIAL_NUM');
3731 fnd_message.set_token('SERIAL_NUM',l_serial_num);
3732 fnd_msg_pub.add;
3733 END If;
3734 End;
3735 ELSE
3736 l_instance_id := NULL;
3737 END If;
3738
3739 l_line_del_qty := RO.ro_qty;
3740 ELSE
3741 -- Non-Serialized Case
3742 l_serial_num := NULL;
3743 l_line_del_qty := RO.ordered_quantity;
3744 l_instance_id := NULL;
3745
3746 --lot_control_code = 1 No control
3747 --lot_control_code = 2 Full control
3748 IF RCV.lot_control_code = 2 THEN
3749 BEGIN
3750 Select lot_num
3751 into l_lot_num
3752 from rcv_lot_transactions
3753 where source_transaction_id = DEL.transaction_id;
3754 EXCEPTION
3755 WHEN NO_DATA_FOUND THEN
3756 IF ( l_error_level >= G_debug_level) THEN
3757 fnd_message.set_name('CSD','CSD_INV_TXN_ID');
3758 fnd_message.set_token('TXN_ID',DEL.transaction_id);
3759 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
3760 ELSE
3761 fnd_message.set_name('CSD','CSD_INV_TXN_ID');
3762 fnd_message.set_token('TXN_ID',DEL.transaction_id);
3763 fnd_msg_pub.add;
3764 END IF;
3765 RAISE FND_API.G_EXC_ERROR;
3766 END;
3767 ELSE
3768 l_lot_num := NULL;
3769 END IF;
3770 END IF;
3771
3772 IF l_pt_del_qty >= l_line_del_qty THEN
3773 -- Debug messages
3774 Debug('Exiting the loop',l_mod_name,1);
3775 EXIT;
3776 ELSE
3777 l_rcvd_qty := l_line_del_qty - l_pt_del_qty ;
3778 IF DEL.rcvd_qty < l_rcvd_qty THEN
3779 l_rcvd_qty := DEL.rcvd_qty;
3780 END IF;
3781 END IF;
3782
3783 IF RCV.serial_number_control_code in (2,5,6) THEN
3784 l_rcvd_qty := 1;
3785 ELSE
3786 l_rcvd_qty := l_rcvd_qty - l_total_del_qty;
3787 END IF;
3788
3789 -- Debug messages
3790 Debug('l_rcvd_qty : '||l_rcvd_qty,l_mod_name,1);
3791
3792 -- Update the serial number on repair order
3793 -- with the rcvd serial number
3794 UPDATE CSD_REPAIRS
3795 SET SERIAL_NUMBER = l_serial_num,
3796 quantity_rcvd = nvl(quantity_rcvd,0) + l_rcvd_qty,
3797 customer_product_id = l_instance_id,
3798 object_version_number = object_version_number+1,
3799 last_update_date = sysdate,
3800 last_updated_by = fnd_global.user_id,
3801 last_update_login = fnd_global.login_id
3802 WHERE repair_line_id = RO.repair_line_id;
3803 IF SQL%NOTFOUND THEN
3804 IF ( l_error_level >= G_debug_level) THEN
3805 fnd_message.set_name('CSD','CSD_RO_UPD_FAILED');
3806 fnd_message.set_token('REPAIR_LINE_ID',RO.repair_line_id);
3807 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
3808 ELSE
3809 fnd_message.set_name('CSD','CSD_RO_UPD_FAILED');
3810 fnd_message.set_token('REPAIR_LINE_ID',RO.repair_line_id);
3811 fnd_msg_pub.add;
3812 END IF;
3813 RAISE PROCESS_ERROR;
3814 END IF;
3815
3816 -- Updating the product txn with the serial number,lot number
3817 -- qty rcvd and subinventory
3818 -- sub_inventory_rcvd is used for IO and subinventory column
3819 -- is used for the regular RMA
3820 UPDATE CSD_PRODUCT_TRANSACTIONS
3821 SET SOURCE_SERIAL_NUMBER = l_serial_num,
3822 source_instance_id = l_instance_id,
3823 LOT_NUMBER_RCVD = l_lot_num,
3824 LOCATOR_ID = DEL.locator_id,
3825 QUANTITY_RECEIVED = NVL(QUANTITY_RECEIVED,0) + l_rcvd_qty,
3826 SUB_INVENTORY_RCVD = DEL.subinventory,
3827 object_version_number = object_version_number+1,
3828 last_update_date = sysdate,
3829 last_updated_by = fnd_global.user_id,
3830 last_update_login = fnd_global.login_id
3831 WHERE product_transaction_id = RO.product_transaction_id;
3832 IF SQL%NOTFOUND THEN
3833 IF ( l_error_level >= G_debug_level) THEN
3834 fnd_message.set_name('CSD','CSD_PROD_TXN_UPD_FAILED');
3835 fnd_message.set_token('PROD_TXN_ID',RO.product_transaction_id);
3836 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
3837 ELSE
3838 fnd_message.set_name('CSD','CSD_PROD_TXN_UPD_FAILED');
3839 fnd_message.set_token('PROD_TXN_ID',RO.product_transaction_id);
3840 fnd_msg_pub.add;
3841 END IF;
3842 RAISE PROCESS_ERROR;
3843 END IF;
3844
3845 IF RCV.serial_number_control_code in (2,5,6) THEN
3846 UPDATE CSD_PRODUCT_TRANSACTIONS
3847 SET prod_txn_status = 'RECEIVED',
3848 object_version_number = object_version_number+1,
3849 last_update_date = sysdate,
3850 last_updated_by = fnd_global.user_id,
3851 last_update_login = fnd_global.login_id
3852 WHERE product_transaction_id = RO.product_transaction_id;
3853 ELSE
3854 UPDATE CSD_PRODUCT_TRANSACTIONS
3855 SET prod_txn_status = 'RECEIVED',
3856 object_version_number = object_version_number+1,
3857 last_update_date = sysdate,
3858 last_updated_by = fnd_global.user_id,
3859 last_update_login = fnd_global.login_id
3860 WHERE quantity_received = RO.ordered_quantity
3861 and product_transaction_id = RO.product_transaction_id;
3862 END IF;
3863
3864 -- Initialize the activity rec
3865 l_activity_rec := INIT_ACTIVITY_REC ;
3866
3867 -- Assign the values for activity record
3868 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
3869 l_activity_rec.REPAIR_LINE_ID := RO.repair_line_id;
3870 l_activity_rec.EVENT_CODE := 'RRI';
3871 l_activity_rec.ACTION_CODE := 0;
3872 l_activity_rec.EVENT_DATE := DEL.received_date;
3873 l_activity_rec.QUANTITY := l_rcvd_qty;
3874 l_activity_rec.PARAMN1 := DEL.transaction_id;
3875 l_activity_rec.PARAMN2 := RO.product_transaction_id;
3876 l_activity_rec.PARAMN3 := DEL.organization_id;
3877 l_activity_rec.PARAMN6 := RO.req_header_id;
3878 l_activity_rec.PARAMC1 := RO.order_number;
3879 l_activity_rec.PARAMC2 := RO.requisition_number;
3880 l_activity_rec.PARAMC3 := DEL.org_name;
3881 l_activity_rec.PARAMC4 := DEL.subinventory;
3882 l_activity_rec.OBJECT_VERSION_NUMBER := null;
3883
3884 -- Debug Messages
3885 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
3886
3887 -- Calling LOG_ACTIVITY for logging activity
3888 -- Receipt of item against Internal Requisition
3889 LOG_ACTIVITY
3890 ( p_api_version => p_api_version,
3891 p_commit => p_commit,
3892 p_init_msg_list => p_init_msg_list,
3893 p_validation_level => p_validation_level,
3894 x_return_status => x_return_status,
3895 x_msg_count => x_msg_count,
3896 x_msg_data => x_msg_data,
3897 p_activity_rec => l_activity_rec );
3898
3899 -- Debug Messages
3900 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
3901 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
3902 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
3903 RAISE FND_API.G_EXC_ERROR;
3904 END IF;
3905
3906 IF (l_pt_del_qty + l_rcvd_qty) >= l_line_del_qty THEN
3907 Debug(' Exiting the DEL loop',l_mod_name,1);
3908 EXIT;
3909 END IF;
3910 Exception
3911 WHEN PROCESS_ERROR THEN
3912 Debug('In process_error exception ',l_mod_name,4);
3913 RAISE PROCESS_ERROR;
3914 WHEN SKIP_RECORD THEN
3915 NULL;
3916 END;
3917 END LOOP; -- end of delivery lines
3918
3919 IF (l_pt_reject_qty+ l_pt_accept_qty + l_accept_qty)>= l_line_qty THEN
3920 Debug('Exiting RCV the loop ',l_mod_name,1);
3921 EXIT;
3922 END IF;
3923
3924 ELSIF RCV.transaction_type = 'REJECT' THEN
3925 -- Handles Inspection Required routing option
3926
3927 select nvl(sum(paramn4),0)
3928 into l_total_reject_qty
3929 from csd_repair_history crh
3930 where crh.event_code = 'IP'
3931 and crh.paramn1 = RCV.transaction_id;
3932 IF l_total_reject_qty >= RCV.rcvd_qty THEN
3933 -- Debug messages
3934 Debug('Skipping the record ',l_mod_name,1);
3935 RAISE SKIP_RECORD;
3936 END IF;
3937
3938 select nvl(sum(paramn3),0),nvl(sum(paramn4),0)
3939 into l_pt_accept_qty, l_pt_reject_qty
3940 from csd_repair_history crh
3941 where crh.event_code = 'IP'
3942 and crh.paramn2 = RO.product_transaction_id;
3943 -- Debug messages
3944 Debug('l_pt_accept_qty'||l_pt_accept_qty,l_mod_name,1);
3945 Debug('l_pt_reject_qty'||l_pt_reject_qty,l_mod_name,1);
3946
3947 IF RCV.serial_number_control_code in (2,5,6) THEN
3948 l_line_qty := 1;
3949 ELSE
3950 l_line_qty := RO.ordered_quantity;
3951 END IF;
3952 IF l_pt_accept_qty+ l_pt_reject_qty >= l_line_qty THEN
3953 -- Debug messages
3954 Debug('Exiting the loop ',l_mod_name,1);
3955 EXIT;
3956 ELSE
3957 l_reject_qty := l_line_qty- (l_pt_accept_qty+ l_pt_reject_qty);
3958 IF RCV.rcvd_qty < l_reject_qty THEN
3959 l_reject_qty := RCV.rcvd_qty;
3960 END IF;
3961 END IF;
3962
3963 IF RCV.serial_number_control_code in (2,5,6) THEN
3964 l_reject_qty := 1;
3965 ELSE
3966 l_reject_qty := l_reject_qty - l_total_reject_qty;
3967 END IF;
3968
3969 -- Debug messages
3970 Debug('l_reject_qty'||l_reject_qty,l_mod_name,1);
3971
3972 -- Initialize the activity rec
3973 l_activity_rec := INIT_ACTIVITY_REC ;
3974
3975 -- Assign the values for activity record
3976 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
3977 l_activity_rec.REPAIR_LINE_ID := RO.repair_line_id;
3978 l_activity_rec.EVENT_CODE := 'IP';
3979 l_activity_rec.ACTION_CODE := 0;
3980 l_activity_rec.EVENT_DATE := RCV.received_date;
3981 l_activity_rec.QUANTITY := l_reject_qty;
3982 l_activity_rec.PARAMN1 := RCV.transaction_id;
3983 l_activity_rec.PARAMN2 := RO.product_transaction_id;
3984 l_activity_rec.PARAMN3 := null;
3985 l_activity_rec.PARAMN4 := l_reject_qty;
3986 l_activity_rec.PARAMN6 := RO.req_header_id;
3987 l_activity_rec.PARAMC1 := RO.requisition_number;
3988 l_activity_rec.PARAMC2 := rcv.subinventory;
3989 l_activity_rec.OBJECT_VERSION_NUMBER := null;
3990
3991 -- Debug Messages
3992 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
3993
3994 -- Calling LOG_ACTIVITY for logging activity
3995 LOG_ACTIVITY
3996 ( p_api_version => p_api_version,
3997 p_commit => p_commit,
3998 p_init_msg_list => p_init_msg_list,
3999 p_validation_level => p_validation_level,
4000 x_return_status => x_return_status,
4001 x_msg_count => x_msg_count,
4002 x_msg_data => x_msg_data,
4003 p_activity_rec => l_activity_rec );
4004
4005 -- Debug Messages
4006 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
4007 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
4008 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
4009 RAISE FND_API.G_EXC_ERROR;
4010 END IF;
4011
4012 -- Check if there are "DELIVER" txn lines against the reject lines
4013 -- If found, then process the deliver lines also
4014 FOR DEL IN DELIVER_LINES(RCV.transaction_id)
4015 LOOP
4016 BEGIN
4017 -- Debug messages
4018 Debug('In DEL Loop ',l_mod_name,1);
4019
4020 select nvl(sum(quantity),0)
4021 into l_total_del_qty
4022 from csd_repair_history crh
4023 where crh.event_code = 'RRI'
4024 and crh.paramn1 = DEL.transaction_id;
4025 -- Debug messages
4026 Debug('l_total_del_qty : '||l_total_del_qty,l_mod_name,1);
4027
4028 IF l_total_del_qty >= DEL.rcvd_qty THEN
4029 -- Debug messages
4030 Debug('Skipping the record',l_mod_name,1);
4031 RAISE SKIP_RECORD;
4032 END IF;
4033
4034 select nvl(sum(quantity),0)
4035 into l_pt_del_qty
4036 from csd_repair_history crh
4037 where crh.event_code = 'RRI'
4038 and crh.paramn2 = RO.product_transaction_id;
4039 -- Debug messages
4040 Debug('l_pt_del_qty : '||l_pt_del_qty,l_mod_name,1);
4041
4042 IF RCV.serial_number_control_code in (2,5,6) THEN
4043 -- SERIALIZED CASE
4044 Begin
4045 select rcvt.serial_num,
4046 rcvt.lot_num
4047 into l_serial_num,
4048 l_lot_num
4049 from rcv_serial_transactions rcvt
4050 where rcvt.transaction_id = DEL.transaction_id
4051 and rownum = 1
4052 and not exists (Select 'NOT EXIST'
4053 from csd_repairs cra,
4054 csd_product_transactions cpt
4055 where cra.repair_line_id = cpt.repair_line_id
4056 and cpt.action_type = 'MOVE_IN'
4057 and cpt.order_header_id = ro.order_header_id
4058 and cra.serial_number = rcvt.serial_num);
4059 Exception
4060 WHEN NO_DATA_FOUND THEN
4061 IF ( l_error_level >= G_debug_level) THEN
4062 fnd_message.set_name('CSD','CSD_SERIAL_NUM_MISSING');
4063 fnd_message.set_token('TXN_ID',DEL.transaction_id);
4064 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
4065 ELSE
4066 fnd_message.set_name('CSD','CSD_SERIAL_NUM_MISSING');
4067 fnd_message.set_token('TXN_ID',DEL.transaction_id);
4068 fnd_msg_pub.add;
4069 END If;
4070 RAISE PROCESS_ERROR;
4071 END;
4072 -- Get the instance id from
4073 -- installbase tables
4074 IF NVL(RCV.ib_flag,'N') = 'Y' THEN
4075 BEGIN
4076 Select instance_id
4077 into l_instance_id
4078 from csi_item_instances
4079 where inventory_item_id = RCV.item_id
4080 and serial_number = l_serial_num;
4081 Exception
4082 When NO_DATA_FOUND THEN
4083 IF ( l_error_level >= G_debug_level) THEN
4084 fnd_message.set_name('CSD','CSD_ITEM_INSTANCE_MISSING');
4085 fnd_message.set_token('SERIAL_NUM',l_serial_num);
4086 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
4087 ELSE
4088 fnd_message.set_name('CSD','CSD_ITEM_INSTANCE_MISSING');
4089 fnd_message.set_token('SERIAL_NUM',l_serial_num);
4090 fnd_msg_pub.add;
4091 END If;
4092 When Others THEN
4093 IF ( l_error_level >= G_debug_level) THEN
4094 fnd_message.set_name('CSD','CSD_INV_SERIAL_NUM');
4095 fnd_message.set_token('SERIAL_NUM',l_serial_num);
4096 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
4097 ELSE
4098 fnd_message.set_name('CSD','CSD_INV_SERIAL_NUM');
4099 fnd_message.set_token('SERIAL_NUM',l_serial_num);
4100 fnd_msg_pub.add;
4101 END If;
4102 End;
4103 ELSE
4104 l_instance_id := NULL;
4105 END IF;
4106
4107 l_line_del_qty := RO.ro_qty;
4108 ELSE
4109 -- Non-Serialized Case
4110 l_serial_num := NULL;
4111 l_line_del_qty := RO.ordered_quantity;
4112 l_instance_id := NULL;
4113
4114 --lot_control_code = 1 No control
4115 --lot_control_code = 2 Full control
4116 IF RCV.lot_control_code = 2 THEN
4117 BEGIN
4118 Select lot_num
4119 into l_lot_num
4120 from rcv_lot_transactions
4121 where source_transaction_id = DEL.transaction_id;
4122 EXCEPTION
4123 WHEN NO_DATA_FOUND THEN
4124 IF ( l_error_level >= G_debug_level) THEN
4125 fnd_message.set_name('CSD','CSD_INV_TXN_ID');
4126 fnd_message.set_token('TXN_ID',DEL.transaction_id);
4127 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
4128 ELSE
4129 fnd_message.set_name('CSD','CSD_INV_TXN_ID');
4130 fnd_message.set_token('TXN_ID',DEL.transaction_id);
4131 fnd_msg_pub.add;
4132 END IF;
4133 RAISE FND_API.G_EXC_ERROR;
4134 END;
4135 ELSE
4136 l_lot_num := NULL;
4137 END IF;
4138 END IF;
4139
4140 IF l_pt_del_qty >= l_line_del_qty THEN
4141 -- Debug messages
4142 Debug('Exiting the loop',l_mod_name,1);
4143 EXIT;
4144 ELSE
4145 l_rcvd_qty := l_line_del_qty - l_pt_del_qty ;
4146 IF DEL.rcvd_qty < l_rcvd_qty THEN
4147 l_rcvd_qty := DEL.rcvd_qty;
4148 END IF;
4149 END IF;
4150
4151 IF RCV.serial_number_control_code in (2,5,6) THEN
4152 l_rcvd_qty := 1;
4153 ELSE
4154 l_rcvd_qty := l_rcvd_qty - l_total_del_qty;
4155 END IF;
4156
4157 -- Debug messages
4158 Debug('l_rcvd_qty : '||l_rcvd_qty,l_mod_name,1);
4159
4160 -- Update the serial number on repair order
4161 -- with the rcvd serial number
4162 UPDATE CSD_REPAIRS
4163 SET SERIAL_NUMBER = l_serial_num,
4164 quantity_rcvd = nvl(quantity_rcvd,0) + l_rcvd_qty,
4165 customer_product_id = l_instance_id,
4166 object_version_number = object_version_number+1,
4167 last_update_date = sysdate,
4168 last_updated_by = fnd_global.user_id,
4169 last_update_login = fnd_global.login_id
4170 WHERE repair_line_id = RO.repair_line_id;
4171 IF SQL%NOTFOUND THEN
4172 IF ( l_error_level >= G_debug_level) THEN
4173 fnd_message.set_name('CSD','CSD_RO_UPD_FAILED');
4174 fnd_message.set_token('REPAIR_LINE_ID',RO.repair_line_id);
4175 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
4176 ELSE
4177 fnd_message.set_name('CSD','CSD_RO_UPD_FAILED');
4178 fnd_message.set_token('REPAIR_LINE_ID',RO.repair_line_id);
4179 fnd_msg_pub.add;
4180 END IF;
4181 RAISE PROCESS_ERROR;
4182 END IF;
4183
4184
4185 -- Updating the product txn with the serial number,lot number
4186 -- qty rcvd and subinventory
4187 -- sub_inventory_rcvd is used for IO and subinventory column
4188 -- is used for the regular RMA
4189 UPDATE CSD_PRODUCT_TRANSACTIONS
4190 SET SOURCE_SERIAL_NUMBER = l_serial_num,
4191 source_instance_id = l_instance_id,
4192 LOT_NUMBER_RCVD = l_lot_num,
4193 LOCATOR_ID = DEL.locator_id,
4194 QUANTITY_RECEIVED = NVL(QUANTITY_RECEIVED,0) + l_rcvd_qty,
4195 SUB_INVENTORY_RCVD = DEL.subinventory,
4196 object_version_number = object_version_number+1,
4197 last_update_date = sysdate,
4198 last_updated_by = fnd_global.user_id,
4199 last_update_login = fnd_global.login_id
4200 WHERE product_transaction_id = RO.product_transaction_id;
4201 IF SQL%NOTFOUND THEN
4202 IF ( l_error_level >= G_debug_level) THEN
4203 fnd_message.set_name('CSD','CSD_PROD_TXN_UPD_FAILED');
4204 fnd_message.set_token('PROD_TXN_ID',RO.product_transaction_id);
4205 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
4206 ELSE
4207 fnd_message.set_name('CSD','CSD_PROD_TXN_UPD_FAILED');
4208 fnd_message.set_token('PROD_TXN_ID',RO.product_transaction_id);
4209 fnd_msg_pub.add;
4210 END IF;
4211 RAISE PROCESS_ERROR;
4212 END IF;
4213
4214 IF RCV.serial_number_control_code in (2,5,6) THEN
4215 UPDATE CSD_PRODUCT_TRANSACTIONS
4216 SET prod_txn_status = 'RECEIVED',
4217 object_version_number = object_version_number+1,
4218 last_update_date = sysdate,
4219 last_updated_by = fnd_global.user_id,
4220 last_update_login = fnd_global.login_id
4221 WHERE product_transaction_id = RO.product_transaction_id;
4222
4223 ELSE
4224 UPDATE CSD_PRODUCT_TRANSACTIONS
4225 SET prod_txn_status = 'RECEIVED',
4226 object_version_number = object_version_number+1,
4227 last_update_date = sysdate,
4228 last_updated_by = fnd_global.user_id,
4229 last_update_login = fnd_global.login_id
4230 WHERE quantity_received = RO.ordered_quantity
4231 and product_transaction_id = RO.product_transaction_id;
4232 END IF;
4233
4234 -- Initialize the activity rec
4235 l_activity_rec := INIT_ACTIVITY_REC ;
4236
4237 -- Assign the values for activity record
4238 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
4239 l_activity_rec.REPAIR_LINE_ID := RO.repair_line_id;
4240 l_activity_rec.EVENT_CODE := 'RRI';
4241 l_activity_rec.ACTION_CODE := 0;
4242 l_activity_rec.EVENT_DATE := DEL.received_date;
4243 l_activity_rec.QUANTITY := l_rcvd_qty;
4244 l_activity_rec.PARAMN1 := DEL.transaction_id;
4245 l_activity_rec.PARAMN2 := RO.product_transaction_id;
4246 l_activity_rec.PARAMN3 := DEL.organization_id;
4247 l_activity_rec.PARAMN6 := RO.req_header_id;
4248 l_activity_rec.PARAMC1 := RO.order_number;
4249 l_activity_rec.PARAMC2 := RO.requisition_number;
4250 l_activity_rec.PARAMC3 := DEL.org_name;
4251 l_activity_rec.PARAMC4 := DEL.subinventory;
4252 l_activity_rec.OBJECT_VERSION_NUMBER := null;
4253
4254 -- Debug Messages
4255 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
4256
4257 -- Calling LOG_ACTIVITY for logging activity
4258 -- Receipt of item against Internal Requisition
4259 LOG_ACTIVITY
4260 ( p_api_version => p_api_version,
4261 p_commit => p_commit,
4262 p_init_msg_list => p_init_msg_list,
4263 p_validation_level => p_validation_level,
4264 x_return_status => x_return_status,
4265 x_msg_count => x_msg_count,
4266 x_msg_data => x_msg_data,
4267 p_activity_rec => l_activity_rec );
4268
4269 -- Debug Messages
4270 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
4271 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
4272 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
4273 RAISE FND_API.G_EXC_ERROR;
4274 END IF;
4275
4276 IF (l_pt_del_qty + l_rcvd_qty) >= l_line_del_qty THEN
4277 Debug(' Exiting the DEL loop',l_mod_name,1);
4278 EXIT;
4279 END IF;
4280 Exception
4281 WHEN PROCESS_ERROR THEN
4282 Debug('In process_error exception ',l_mod_name,4);
4283 RAISE PROCESS_ERROR;
4284 WHEN SKIP_RECORD THEN
4285 NULL;
4286 END;
4287 END LOOP; -- end of delivery lines
4288
4289 IF l_pt_accept_qty+ l_pt_reject_qty+ l_reject_qty >= l_line_qty THEN
4290 Debug(' Exiting the RCV loop',l_mod_name,1);
4291 EXIT;
4292 END IF;
4293
4294 ELSIF RCV.transaction_type = 'DELIVER' THEN
4295 -- Handles the Direct Delivery and standard routing options
4296
4297 select nvl(sum(quantity),0)
4298 into l_total_qty
4299 from csd_repair_history crh
4300 where crh.event_code = 'RRI'
4301 and crh.paramn1 = RCV.transaction_id;
4302 IF l_total_qty >= RCV.rcvd_qty THEN
4303 -- Debug messages
4304 Debug(' Skipping the record',l_mod_name,1);
4305 RAISE SKIP_RECORD;
4306 END IF;
4307
4308 select nvl(sum(quantity),0)
4309 into l_pt_del_qty
4310 from csd_repair_history crh
4311 where crh.event_code = 'RRI'
4312 and paramn2 = RO.product_transaction_id;
4313
4314 -- Debug messages
4315 Debug('l_pt_reject_qty='||l_pt_reject_qty,l_mod_name,1);
4316 Debug('l_pt_del_qty ='||l_pt_del_qty,l_mod_name,1);
4317
4318 IF RCV.serial_number_control_code in (2,5,6) THEN
4319 -- SERIALIZED AND LOT CONTROLLED CASE
4320 l_line_qty := RO.ro_qty;
4321 Begin
4322 select rcvt.serial_num,
4323 rcvt.lot_num
4324 into l_serial_num,
4325 l_lot_num
4326 from rcv_serial_transactions rcvt
4327 where rcvt.transaction_id = RCV.transaction_id
4328 and rownum = 1
4329 and not exists (Select 'NOT EXIST'
4330 from csd_repairs cra,
4331 csd_product_transactions cpt
4332 where cra.repair_line_id = cpt.repair_line_id
4333 and cpt.order_header_id = ro.order_header_id
4334 and cra.serial_number = rcvt.serial_num);
4335 Exception
4336 WHEN NO_DATA_FOUND THEN
4337 IF ( l_error_level >= G_debug_level) THEN
4338 fnd_message.set_name('CSD','CSD_SERIAL_NUM_MISSING');
4339 fnd_message.set_token('TXN_ID',RCV.transaction_id);
4340 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
4341 ELSE
4342 fnd_message.set_name('CSD','CSD_SERIAL_NUM_MISSING');
4343 fnd_message.set_token('TXN_ID',RCV.transaction_id);
4344 fnd_msg_pub.add;
4345 END IF;
4346 RAISE PROCESS_ERROR;
4347 END;
4348
4349 -- Get the instance id from
4350 -- installbase tables
4351 IF NVL(RCV.ib_flag,'N') = 'Y' THEN
4352 BEGIN
4353 Select instance_id
4354 into l_instance_id
4355 from csi_item_instances
4356 where inventory_item_id = RCV.item_id
4357 and serial_number = l_serial_num;
4358 Exception
4359 When NO_DATA_FOUND THEN
4360 IF ( l_error_level >= G_debug_level) THEN
4361 fnd_message.set_name('CSD','CSD_ITEM_INSTANCE_MISSING');
4362 fnd_message.set_token('SERIAL_NUM',l_serial_num);
4363 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
4364 ELSE
4365 fnd_message.set_name('CSD','CSD_ITEM_INSTANCE_MISSING');
4366 fnd_message.set_token('SERIAL_NUM',l_serial_num);
4367 fnd_msg_pub.add;
4368 END If;
4369 When Others THEN
4370 IF ( l_error_level >= G_debug_level) THEN
4371 fnd_message.set_name('CSD','CSD_INV_SERIAL_NUM');
4372 fnd_message.set_token('SERIAL_NUM',l_serial_num);
4373 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
4374 ELSE
4375 fnd_message.set_name('CSD','CSD_INV_SERIAL_NUM');
4376 fnd_message.set_token('SERIAL_NUM',l_serial_num);
4377 fnd_msg_pub.add;
4378 END If;
4379 End;
4380 ELSE
4381 l_instance_id := NULL;
4382 END IF;
4383 ELSE
4384 -- Non-Serialized Case but lot controlled
4385 l_serial_num := NULL;
4386 l_line_qty := RO.ordered_quantity;
4387 l_instance_id := NULL;
4388
4389 --lot_control_code = 1 No control
4390 --lot_control_code = 2 Full control
4391 IF RCV.lot_control_code = 2 THEN
4392 BEGIN
4393 Select lot_num
4394 into l_lot_num
4395 from rcv_lot_transactions
4396 where source_transaction_id = RCV.transaction_id;
4397 EXCEPTION
4398 WHEN NO_DATA_FOUND THEN
4399 IF ( l_error_level >= G_debug_level) THEN
4400 fnd_message.set_name('CSD','CSD_INV_TXN_ID');
4401 fnd_message.set_token('TXN_ID',RCV.transaction_id);
4402 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
4403 ELSE
4404 fnd_message.set_name('CSD','CSD_INV_TXN_ID');
4405 fnd_message.set_token('TXN_ID',RCV.transaction_id);
4406 fnd_msg_pub.add;
4407 END IF;
4408 RAISE FND_API.G_EXC_ERROR;
4409 END;
4410 ELSE
4411 -- Non-Serialized Case but not lot controlled
4412 l_lot_num := NULL;
4413 END IF;
4414 END IF;
4415
4416 IF l_pt_del_qty >= l_line_qty THEN
4417 Debug(' EXiting the RCV Loop',l_mod_name,1);
4418 EXIT;
4419 ELSE
4420 l_rcvd_qty := l_line_qty - l_pt_del_qty;
4421 IF RCV.rcvd_qty < l_rcvd_qty THEN
4422 l_rcvd_qty := RCV.rcvd_qty;
4423 END IF;
4424 END IF;
4425
4426 IF RCV.serial_number_control_code in (2,5,6) THEN
4427 l_rcvd_qty := 1;
4428 ELSE
4429 l_rcvd_qty := l_rcvd_qty - l_total_qty;
4430 END IF;
4431
4432 -- Debug messages
4433 Debug('l_rcvd_qty'||l_rcvd_qty,l_mod_name,1);
4434
4435 -- Update repair order with the rcvd serial number
4436 -- and the rcvd qty
4437 UPDATE CSD_REPAIRS
4438 SET SERIAL_NUMBER = l_serial_num,
4439 quantity_rcvd = nvl(quantity_rcvd,0) + l_rcvd_qty,
4440 customer_product_id = l_instance_id,
4441 object_version_number = object_version_number+1,
4442 last_update_date = sysdate,
4443 last_updated_by = fnd_global.user_id,
4444 last_update_login = fnd_global.login_id
4445 WHERE repair_line_id = RO.repair_line_id;
4446 IF SQL%NOTFOUND THEN
4447 IF ( l_error_level >= G_debug_level) THEN
4448 fnd_message.set_name('CSD','CSD_RO_UPD_FAILED');
4449 fnd_message.set_token('REPAIR_LINE_ID',RO.repair_line_id);
4450 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
4451 ELSE
4452 fnd_message.set_name('CSD','CSD_RO_UPD_FAILED');
4453 fnd_message.set_token('REPAIR_LINE_ID',RO.repair_line_id);
4454 fnd_msg_pub.add;
4455 END IF;
4456 RAISE PROCESS_ERROR;
4457 END IF;
4458
4459
4460 -- Update product txn with the rcvd serial number,lot number
4461 -- locator id, sub inv, status and the rcvd qty
4462 UPDATE CSD_PRODUCT_TRANSACTIONS
4463 SET SOURCE_SERIAL_NUMBER = l_serial_num,
4464 source_instance_id = l_instance_id,
4465 LOT_NUMBER_RCVD = l_lot_num,
4466 QUANTITY_RECEIVED = NVL(QUANTITY_RECEIVED,0) + l_rcvd_qty,
4467 SUB_INVENTORY_RCVD= RCV.subinventory,
4468 LOCATOR_ID = RCV.locator_id,
4469 object_version_number = object_version_number+1,
4470 last_update_date = sysdate,
4471 last_updated_by = fnd_global.user_id,
4472 last_update_login = fnd_global.login_id
4473 WHERE product_transaction_id = RO.product_transaction_id;
4474 IF SQL%NOTFOUND THEN
4475 IF ( l_error_level >= G_debug_level) THEN
4476 fnd_message.set_name('CSD','CSD_PROD_TXN_UPD_FAILED');
4477 fnd_message.set_token('PROD_TXN_ID',RO.product_transaction_id);
4478 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
4479 ELSE
4480 fnd_message.set_name('CSD','CSD_PROD_TXN_UPD_FAILED');
4481 fnd_message.set_token('PROD_TXN_ID',RO.product_transaction_id);
4482 fnd_msg_pub.add;
4483 END IF;
4484 RAISE PROCESS_ERROR;
4485 END IF;
4486
4487 IF RCV.serial_number_control_code in (2,5,6) THEN
4488 UPDATE CSD_PRODUCT_TRANSACTIONS
4489 SET prod_txn_status = 'RECEIVED',
4490 object_version_number = object_version_number+1,
4491 last_update_date = sysdate,
4492 last_updated_by = fnd_global.user_id,
4493 last_update_login = fnd_global.login_id
4494 WHERE product_transaction_id = RO.product_transaction_id;
4495 ELSE
4496 UPDATE CSD_PRODUCT_TRANSACTIONS
4497 SET prod_txn_status = 'RECEIVED',
4498 object_version_number = object_version_number+1,
4499 last_update_date = sysdate,
4500 last_updated_by = fnd_global.user_id,
4501 last_update_login = fnd_global.login_id
4502 WHERE quantity_received = RO.ordered_quantity
4503 and product_transaction_id = RO.product_transaction_id;
4504 END IF;
4505
4506 -- Initialize the activity rec
4507 l_activity_rec := INIT_ACTIVITY_REC ;
4508
4509 -- Assign the values for activity record
4510 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
4511 l_activity_rec.REPAIR_LINE_ID := RO.repair_line_id;
4512 l_activity_rec.EVENT_CODE := 'RRI';
4513 l_activity_rec.ACTION_CODE := 0;
4514 l_activity_rec.EVENT_DATE := RCV.received_date;
4515 l_activity_rec.QUANTITY := l_rcvd_qty;
4516 l_activity_rec.PARAMN1 := RCV.transaction_id;
4517 l_activity_rec.PARAMN2 := RO.product_transaction_id;
4518 l_activity_rec.PARAMN3 := RCV.organization_id;
4519 l_activity_rec.PARAMN6 := RO.req_header_id;
4520 l_activity_rec.PARAMC1 := RO.order_number;
4521 l_activity_rec.PARAMC2 := RO.requisition_number;
4522 l_activity_rec.PARAMC3 := RCV.org_name;
4523 l_activity_rec.PARAMC4 := RCV.subinventory;
4524 l_activity_rec.OBJECT_VERSION_NUMBER := null;
4525
4526 -- Debug Messages
4527 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
4528
4529 -- Calling LOG_ACTIVITY for logging activity
4530 LOG_ACTIVITY
4531 ( p_api_version => p_api_version,
4532 p_commit => p_commit,
4533 p_init_msg_list => p_init_msg_list,
4534 p_validation_level => p_validation_level,
4535 x_return_status => x_return_status,
4536 x_msg_count => x_msg_count,
4537 x_msg_data => x_msg_data,
4538 p_activity_rec => l_activity_rec );
4539
4540 -- Debug Messages
4541 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
4542 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
4543 Debug('LOG_ACTIVITY api failed ',l_mod_name,1);
4544 RAISE FND_API.G_EXC_ERROR;
4545 END IF;
4546
4547 IF l_pt_del_qty+ l_rcvd_qty >= l_line_qty THEN
4548 Debug(' exiting the RCV loop',l_mod_name,1);
4549 EXIT;
4550 END IF;
4551 END IF;
4552 Exception
4553 WHEN PROCESS_ERROR THEN
4554 Debug(' In Process error exception',l_mod_name,4);
4555 RAISE PROCESS_ERROR;
4556 WHEN SKIP_RECORD THEN
4557 NULL;
4558 END;
4559 END LOOP;
4560 Exception
4561 WHEN PROCESS_ERROR THEN
4562 ROLLBACK TO RCV_LINES;
4563 Debug(' In Process error exception, exiting the loop',l_mod_name,1);
4564 -- In case of error, exit the loop. Commit the processed records
4565 -- and rollback the error record
4566 --RAISE FND_API.G_EXC_ERROR;
4567 x_return_status := FND_API.G_RET_STS_ERROR ;
4568 EXIT;
4569 END;
4570 END LOOP;
4571
4572 --Added by Vijay 11/4/04
4573 IF(GET_RO_PROD_TXN_LINES_All%ISOPEN) THEN
4574 CLOSE GET_RO_PROD_TXN_LINES_All;
4575 END IF;
4576 IF(GET_RO_PROD_TXN_LINES%ISOPEN) THEN
4577 CLOSE GET_RO_PROD_TXN_LINES;
4578 END IF;
4579
4580
4581 -- Standard check of p_commit.
4582 IF FND_API.To_Boolean( p_commit ) THEN
4583 COMMIT WORK;
4584 END IF;
4585
4586 -- Standard call to get message count and IF count is get message info.
4587 FND_MSG_PUB.Count_And_Get
4588 (p_count => x_msg_count,
4589 p_data => x_msg_data);
4590 EXCEPTION
4591 WHEN FND_API.G_EXC_ERROR THEN
4592 Debug('In FND_API.G_EXC_ERROR exception',l_mod_name,4);
4593 ROLLBACK TO IO_RCV_UPDATE;
4594 x_return_status := FND_API.G_RET_STS_ERROR ;
4595 FND_MSG_PUB.Count_And_Get
4596 (p_count => x_msg_count,
4597 p_data => x_msg_data );
4598 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4599 Debug('In FND_API.G_EXC_UNEXPECTED_ERROR exception',l_mod_name,4);
4600 ROLLBACK TO IO_RCV_UPDATE;
4601 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4602 FND_MSG_PUB.Count_And_Get
4603 ( p_count => x_msg_count,
4604 p_data => x_msg_data );
4605 WHEN OTHERS THEN
4606 Debug('In OTHERS exception',l_mod_name,4);
4607 ROLLBACK TO IO_RCV_UPDATE;
4608 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4609 IF FND_MSG_PUB.Check_Msg_Level
4610 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4611 THEN
4612 FND_MSG_PUB.Add_Exc_Msg
4613 (G_PKG_NAME ,
4614 l_api_name );
4615 END IF;
4616 FND_MSG_PUB.Count_And_Get
4617 (p_count => x_msg_count,
4618 p_data => x_msg_data );
4619 END IO_RCV_UPDATE;
4620
4621
4622 /*-------------------------------------------------------------------------------------*/
4623 /* Procedure name: IO_RCV_UPDATE_MOVE_OUT */
4624 /* Description : Procedure called from the Update api to update the depot tables */
4625 /* for the receipts against Internal Requisitions for move out line */
4626 /* It also logs activities for accept reject txn lines */
4627 /* Called from : Called from SHIP_UPDATE API */
4628 /* STANDARD PARAMETERS */
4629 /* In Parameters : */
4630 /* p_api_version NUMBER Required Api Version number */
4631 /* p_init_msg_list VARCHAR2 Optional To Initialize message stack */
4632 /* p_commit VARCHAR2 Optional Commits in API */
4633 /* p_validation_level NUMBER Optional validation level */
4634 /* */
4635 /* Output Parameters: */
4636 /* x_return_status VARCHAR2 Return status of the API */
4637 /* x_msg_count NUMBER Number of messages in stack */
4638 /* x_msg_data VARCHAR2 Error Message from message stack */
4639 /* */
4640 /* NON-STANDARD PARAMETERS */
4641 /* In Parameters */
4642 /* p_order_header_id NUMBER Optional Internal sales order Id */
4643 /* Output Parm : */
4644 /* Change Hist : */
4645 /* 24-Apr-2007 swai Initial Creation. Bug#5564180 / FP#5845995 */
4646 /*-------------------------------------------------------------------------------------*/
4647
4648 Procedure IO_RCV_UPDATE_MOVE_OUT
4649 ( p_api_version IN NUMBER,
4650 p_commit IN VARCHAR2,
4651 p_init_msg_list IN VARCHAR2,
4652 p_validation_level IN NUMBER,
4653 x_return_status OUT NOCOPY VARCHAR2,
4654 x_msg_count OUT NOCOPY NUMBER,
4655 x_msg_data OUT NOCOPY VARCHAR2,
4656 p_order_header_id IN NUMBER
4657 ) IS
4658
4659 -- Standard variables
4660 l_api_name CONSTANT VARCHAR2(30) := 'IO_RCV_UPDATE_MOVE_OUT';
4661 l_api_version CONSTANT NUMBER := 1.0;
4662
4663 -- Variables used in API
4664 l_rep_hist_id number;
4665 l_dummy varchar2(30);
4666 l_serialized_flag boolean;
4667 l_ord_remaining_qty number := 0;
4668 l_prod_txn_exists boolean;
4669 l_prod_txn_id number := NULL;
4670 l_prod_txn_status csd_product_transactions.prod_txn_status%type;
4671 l_total_qty number;
4672 l_total_del_qty number;
4673 l_total_accept_qty number;
4674 l_total_reject_qty number;
4675 l_pt_accept_qty number;
4676 l_pt_reject_qty number;
4677 l_pt_del_qty number;
4678 l_accept_qty number;
4679 l_reject_qty number;
4680 l_serial_num MTL_SERIAL_NUMBERS.SERIAL_NUMBER%TYPE;
4681 l_lot_num MTL_LOT_NUMBERS.LOT_NUMBER%TYPE;
4682 l_rep_line_id number;
4683 l_rcvd_qty number;
4684 l_line_qty number;
4685 l_line_del_qty number;
4686 l_sub_inv varchar2(80);
4687 l_instance_id number;
4688
4689 -- activity record
4690 l_activity_rec activity_rec_type;
4691
4692 -- Variable for the FND log file
4693 l_error_level number := FND_LOG.LEVEL_ERROR;
4694 l_mod_name varchar2(2000) := 'csd.plsql.csd_update_programs_pvt.io_rcv_update_move_out';
4695
4696 -- User defined exception
4697 SKIP_RECORD EXCEPTION;
4698 PROCESS_ERROR EXCEPTION;
4699
4700 -- Cursor to get the ro and product txn lines
4701 --
4702 CURSOR GET_RO_PROD_TXN_LINES_ALL IS
4703 select cpt.product_transaction_id,
4704 cpt.prod_txn_status,
4705 cpt.repair_line_id,
4706 cpt.order_header_id,
4707 cpt.order_line_id,
4708 cpt.req_header_id,
4709 cpt.req_line_id,
4710 nvl(cpt.quantity_received,0) prod_txn_rcvd_qty,
4711 cra.quantity ro_qty,
4712 cra.quantity_rcvd ro_rcvd_qty,
4713 cra.inventory_item_id,
4714 cra.unit_of_measure ro_uom,
4715 prh.segment1 requisition_number,
4716 oel.ordered_quantity,
4717 oeh.order_number
4718 from csd_product_transactions cpt,
4719 csd_repairs cra,
4720 po_requisition_headers_all prh,
4721 oe_order_lines_all oel,
4722 oe_order_headers_all oeh
4723 where cpt.repair_line_id = cra.repair_line_id
4724 AND cpt.req_header_id = prh.requisition_header_id
4725 AND cpt.order_line_id = oel.line_id
4726 AND oel.header_id = oeh.header_id
4727 AND cpt.action_type = 'MOVE_OUT'
4728 AND cpt.action_code = 'USABLES'
4729 AND cpt.prod_txn_status = 'SHIPPED'
4730 AND cpt.order_line_id is not null;
4731 /*Bug#5564180/FP#5845995 below condition is not required for move out line
4732 otherwise once the move in line is received the move out line
4733 will not be updated with status received */
4734 -- AND nvl(cra.quantity_rcvd,0) < cra.quantity;
4735
4736 -- Cursor to get the ro and product txn lines
4737 -- for the order header id
4738 CURSOR GET_RO_PROD_TXN_LINES (p_ord_header_id in number) IS
4739 select cpt.product_transaction_id,
4740 cpt.prod_txn_status,
4741 cpt.repair_line_id,
4742 cpt.order_header_id,
4743 cpt.order_line_id,
4744 cpt.req_header_id,
4745 cpt.req_line_id,
4746 nvl(cpt.quantity_received,0) prod_txn_rcvd_qty,
4747 cra.quantity ro_qty,
4748 cra.quantity_rcvd ro_rcvd_qty,
4749 cra.inventory_item_id,
4750 cra.unit_of_measure ro_uom,
4751 prh.segment1 requisition_number,
4752 oel.ordered_quantity,
4753 oeh.order_number
4754 from csd_product_transactions cpt,
4755 csd_repairs cra,
4756 po_requisition_headers_all prh,
4757 oe_order_lines_all oel,
4758 oe_order_headers_all oeh
4759 where cpt.repair_line_id = cra.repair_line_id
4760 AND cpt.req_header_id = prh.requisition_header_id
4761 AND cpt.order_line_id = oel.line_id
4762 AND oel.header_id = oeh.header_id
4763 AND cpt.action_type = 'MOVE_OUT'
4764 AND cpt.action_code = 'USABLES'
4765 AND cpt.prod_txn_status = 'SHIPPED'
4766 AND cpt.order_line_id is not null
4767 AND cpt.order_header_id = p_ord_header_id;
4768 /*Bug#5564180/FP#5845995 below condition not required for move out line
4769 otherwise once the move in line is received the move out line will
4770 not be updated with status received */
4771 -- AND nvl(cra.quantity_rcvd,0) < cra.quantity;
4772
4773 RO IO_RCPT_LINES_Rec_Type;
4774
4775
4776 -- Cursor to get all the rcv txn lines of transaction type
4777 -- DELIVER,REJECT,ACCEPT type
4778 CURSOR GET_RCV_LINES (p_req_line_id in number) IS
4779 select rcv.transaction_id,
4780 rcv.quantity rcvd_qty,
4781 rcv.unit_of_measure,
4782 rcv.subinventory,
4783 rcv.locator_id,
4784 rcv.organization_id,
4785 rcv.transaction_date received_date,
4786 rcv.transaction_type,
4787 rcv.shipment_header_id,
4788 rcv.shipment_line_id,
4789 prl.item_id,
4790 prl.destination_organization_id inv_org_id,
4791 prl.quantity requisition_qty,
4792 prh.segment1 requirement_number,
4793 mtl.serial_number_control_code,
4794 mtl.comms_nl_trackable_flag ib_flag,
4795 mtl.lot_control_code,
4796 hao.name org_name
4797 from rcv_transactions rcv,
4798 po_requisition_lines_all prl,
4799 po_requisition_headers_all prh,
4800 mtl_system_items mtl,
4801 hr_all_organization_units hao
4802 where rcv.requisition_line_id = prl.requisition_line_id
4803 and prl.item_id = mtl.inventory_item_id
4804 and prl.destination_organization_id = mtl.organization_id
4805 and prl.requisition_header_id = prh.requisition_header_id
4806 and rcv.requisition_line_id = p_req_line_id
4807 and hao.organization_id = rcv.organization_id
4808 and rcv.transaction_type in ('DELIVER','ACCEPT','REJECT');
4809
4810 -- Cursor to get the deliver txn line for the
4811 -- specific txn id
4812 CURSOR DELIVER_LINES (p_txn_id in number) IS
4813 Select rcvt.transaction_id,
4814 rcvt.transaction_date received_date,
4815 rcvt.subinventory,
4816 rcvt.quantity rcvd_qty,
4817 rcvt.organization_id,
4818 rcvt.locator_id,
4819 hao.name org_name
4820 from rcv_transactions rcvt,
4821 hr_all_organization_units hao
4822 where rcvt.parent_transaction_id = p_txn_id
4823 and rcvt.transaction_type = 'DELIVER';
4824
4825 CURSOR ORDER_INFO (p_ord_header_id in number) IS
4826 Select distinct
4827 order_header_id,
4828 order_line_id
4829 from csd_product_transactions
4830 where order_header_id = p_ord_header_id
4831 AND action_type = 'MOVE_OUT'
4832 AND action_code = 'USABLES'
4833 AND prod_txn_status = 'SHIPPED';
4834
4835 BEGIN
4836 -- Standard Start of API savepoint
4837 SAVEPOINT IO_RCV_UPDATE_MOVE_OUT;
4838
4839 -- Initialize API return status to success
4840 x_return_status := FND_API.G_RET_STS_SUCCESS;
4841
4842 -- Debug messages
4843 Debug('Beginning of IO_RCV_UPDATE_MOVE_OUT',l_mod_name,1);
4844 Debug('Order Header Id='||to_char(p_order_header_id),l_mod_name,1);
4845
4846 -- Standard call to check for call compatibility.
4847 IF NOT FND_API.Compatible_API_Call (l_api_version,
4848 p_api_version,
4849 l_api_name ,
4850 G_PKG_NAME )
4851 THEN
4852 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4853 END IF;
4854
4855 -- Initialize message list if p_init_msg_list is set to TRUE.
4856 IF FND_API.to_Boolean( p_init_msg_list ) THEN
4857 FND_MSG_PUB.initialize;
4858 END IF;
4859
4860 -- Api body starts
4861
4862 -- In case of Internal orders, the product txns are stamped
4863 -- with the order header id and line id.
4864 -- So Validate if it exists in csd_product_transactions
4865 IF NVL(p_order_header_id,-999) <> -999 THEN
4866 BEGIN
4867 select 'EXISTS'
4868 into l_dummy
4869 from oe_order_headers_all oeh,
4870 po_requisition_headers_all prh
4871 where oeh.source_document_id = prh.requisition_header_id
4872 and oeh.header_id = p_order_header_id
4873 and exists (select 'x'
4874 from csd_product_transactions cpt
4875 where cpt.action_type = 'MOVE_OUT'
4876 and cpt.action_code = 'USABLES'
4877 and cpt.order_header_id = oeh.header_id);
4878 EXCEPTION
4879 WHEN NO_DATA_FOUND THEN
4880 IF ( l_error_level >= G_debug_level) THEN
4881 fnd_message.set_name('CSD','CSD_INV_ORD_HEADER_ID');
4882 fnd_message.set_token('HEADER_ID',p_order_header_id);
4883 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
4884 ELSE
4885 fnd_message.set_name('CSD','CSD_INV_ORD_HEADER_ID');
4886 fnd_message.set_token('HEADER_ID',p_order_header_id);
4887 fnd_msg_pub.add;
4888 END IF;
4889 RAISE FND_API.G_EXC_ERROR;
4890 END;
4891 END IF;
4892
4893
4894 --Loops thro the received lines that have txn type -'DELIVER','ACCEPT','REJECT'
4895 --While Processing the ACCEPT/REJECT txn lines, it also check if there is
4896 --any deliver txn lines with the parent txn id. If it finds then it also
4897 --update the delivered qty and logs activity for the deliver txns.
4898 -- Order Line
4899 --
4900 -- Line Id Header Id Ord Qty Split_from_line_id
4901 -- L1 H1 1
4902 -- L2 H1 2 L1
4903 -- L3 H1 1 L2
4904 --
4905 -- RCV Lines
4906 -- Txn Id Txn Type Qty Ord Line Id Parent Txn Id
4907 -- T1 ACCEPT 1 L1
4908 -- T2 ACCEPT 2 L2
4909 -- T3 REJECT 1 L3
4910 -- T4 DELIVER 1 L1 T1
4911 -- T5 DELIVER 2 L2 T2
4912 --
4913 --
4914 -- 1. Non- Serial
4915 --
4916 -- RO RO Qty Prod Txn Ord Line Ord Header Line Qty
4917 -- RO1 4 P1 L1 H1 1
4918 -- RO1 4 P2 L2 H1 2
4919 -- RO1 4 P3 L3 H1 1
4920 -- 2. Serial
4921 --
4922 -- RO RO Qty Prod Txn Ord Line Ord Header Line Qty
4923 -- RO1 1 P1 L1 H1 1
4924 -- RO2 1 P2 L2 H1 1
4925 -- RO3 1 P3 L2 H1 1
4926 -- RO4 1 P4 L1 H1 1
4927 --
4928 -- THE PROGRAM IGNORES THE DELIVERED QUANTITY AGAINST THE REJECT TRANSACTIONS
4929 -- NEED TO REVIEW WITH PM AND IMPLEMENT AS A PHASE II PROJECT
4930
4931 IF(p_order_header_id is null) THEN
4932 OPEN GET_RO_PROD_TXN_LINES_All;
4933 else
4934 OPEN GET_RO_PROD_TXN_LINES(p_order_header_id);
4935 END IF;
4936
4937
4938 /* Changed FOr loop for splitting the cursor : vijay 11/4/04*/
4939 --FOR RO IN GET_RO_PROD_TXN_LINES( p_order_header_id )
4940 LOOP
4941 BEGIN
4942 IF(p_order_header_id is null) THEN
4943 FETCH GET_RO_PROD_TXN_LINES_All INTO RO;
4944 EXIT WHEN GET_RO_PROD_TXN_LINES_All%NOTFOUND ;
4945 else
4946 FETCH GET_RO_PROD_TXN_LINES INTO RO;
4947 EXIT WHEN GET_RO_PROD_TXN_LINES%NOTFOUND ;
4948 END IF;
4949
4950 -- savepoint
4951 SAVEPOINT RCV_LINES;
4952
4953 -- Debug messages
4954 Debug('In RO loop',l_mod_name,1);
4955
4956 FOR RCV IN GET_RCV_LINES (RO.req_line_id)
4957 LOOP
4958 BEGIN
4959 -- Debug messages
4960 Debug('In RCV loop',l_mod_name,1);
4961
4962 IF RCV.transaction_type = 'ACCEPT' THEN
4963 --Handles Inspection Required Routing options
4964
4965 -- Debug messages
4966 Debug('Processing Accept txn types',l_mod_name,1);
4967
4968 select nvl(sum(paramn3),0)
4969 into l_total_accept_qty
4970 from csd_repair_history crh
4971 where crh.event_code = 'IP'
4972 and crh.paramn1 = RCV.transaction_id;
4973
4974 -- Debug messages
4975 Debug('l_total_accept_qty :'||l_total_accept_qty,l_mod_name,1);
4976 IF nvl(l_total_accept_qty,0) >= nvl(RCV.rcvd_qty,0) THEN
4977 -- Debug messages
4978 Debug('Skipping the record ',l_mod_name,1);
4979 RAISE SKIP_RECORD;
4980 END IF;
4981
4982 select nvl(sum(paramn4),0), nvl(sum(paramn3),0)
4983 into l_pt_reject_qty, l_pt_accept_qty
4984 from csd_repair_history crh
4985 where crh.event_code = 'IP'
4986 and crh.paramn2 = RO.product_transaction_id;
4987 -- Debug messages
4988 Debug('l_pt_reject_qty :'||l_pt_reject_qty,l_mod_name,1);
4989 Debug('l_pt_accept_qty :'||l_pt_accept_qty,l_mod_name,1);
4990
4991 IF RCV.serial_number_control_code in (2,5,6) THEN
4992 l_line_qty := RO.ro_qty;
4993 ELSE
4994 l_line_qty := RO.ordered_quantity;
4995 END IF;
4996
4997 -- Debug messages
4998 Debug('l_line_qty :'||l_line_qty,l_mod_name,1);
4999
5000 IF (l_pt_reject_qty + l_pt_accept_qty) >= l_line_qty THEN
5001 -- Debug messages
5002 Debug('Exiting the RCV loop',l_mod_name,1);
5003 EXIT;
5004 ELSE
5005 l_accept_qty := l_line_qty -(l_pt_reject_qty + l_pt_accept_qty);
5006 IF RCV.rcvd_qty < l_accept_qty THEN
5007 l_accept_qty := RCV.rcvd_qty;
5008 END IF;
5009 END IF;
5010
5011
5012 IF RCV.serial_number_control_code in (2,5,6) THEN
5013 l_accept_qty := 1 ;
5014 ELSE
5015 l_accept_qty := l_accept_qty - l_total_accept_qty ;
5016 END IF;
5017
5018 -- Debug messages
5019 Debug('l_accept_qty :'||l_accept_qty,l_mod_name,1);
5020
5021 -- Initialize the activity rec
5022 l_activity_rec := INIT_ACTIVITY_REC ;
5023
5024 -- Assign the values for activity record
5025 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
5026 l_activity_rec.REPAIR_LINE_ID := RO.repair_line_id;
5027 l_activity_rec.EVENT_CODE := 'IP';
5028 l_activity_rec.ACTION_CODE := 0;
5029 l_activity_rec.EVENT_DATE := RCV.received_date;
5030 l_activity_rec.QUANTITY := l_accept_qty;
5031 l_activity_rec.PARAMN1 := RCV.transaction_id;
5032 l_activity_rec.PARAMN2 := RO.product_transaction_id;
5033 l_activity_rec.PARAMN3 := l_accept_qty;
5034 l_activity_rec.PARAMN6 := RO.req_header_id;
5035 l_activity_rec.PARAMC1 := RO.requisition_number ;
5036 l_activity_rec.PARAMC2 := RCV.subinventory;
5037 l_activity_rec.OBJECT_VERSION_NUMBER := null;
5038
5039 -- Debug Messages
5040 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
5041
5042 -- Calling LOG_ACTIVITY for logging activity
5043 LOG_ACTIVITY
5044 ( p_api_version => p_api_version,
5045 p_commit => p_commit,
5046 p_init_msg_list => p_init_msg_list,
5047 p_validation_level => p_validation_level,
5048 x_return_status => x_return_status,
5049 x_msg_count => x_msg_count,
5050 x_msg_data => x_msg_data,
5051 p_activity_rec => l_activity_rec );
5052
5053 -- Debug Messages
5054 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
5055 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
5056 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
5057 RAISE FND_API.G_EXC_ERROR;
5058 END IF;
5059
5060 -- Check if there are "DELIVER" txn lines against the accept lines
5061 -- If found, then process the deliver lines also
5062 FOR DEL IN DELIVER_LINES(RCV.transaction_id)
5063 LOOP
5064 BEGIN
5065 -- Debug messages
5066 Debug('In DEL Loop ',l_mod_name,1);
5067
5068 select nvl(sum(quantity),0)
5069 into l_total_del_qty
5070 from csd_repair_history crh
5071 where crh.event_code = 'RRI'
5072 and crh.paramn1 = DEL.transaction_id;
5073 -- Debug messages
5074 Debug('l_total_del_qty : '||l_total_del_qty,l_mod_name,1);
5075
5076 IF l_total_del_qty >= DEL.rcvd_qty THEN
5077 -- Debug messages
5078 Debug('Skipping the record',l_mod_name,1);
5079 RAISE SKIP_RECORD;
5080 END IF;
5081
5082 select nvl(sum(quantity),0)
5083 into l_pt_del_qty
5084 from csd_repair_history crh
5085 where crh.event_code = 'RRI'
5086 and crh.paramn2 = RO.product_transaction_id;
5087 -- Debug messages
5088 Debug('l_pt_del_qty : '||l_pt_del_qty,l_mod_name,1);
5089
5090 IF RCV.serial_number_control_code in (2,5,6) THEN
5091 -- SERIALIZED CASE
5092 Begin
5093 select rcvt.serial_num,
5094 rcvt.lot_num
5095 into l_serial_num,
5096 l_lot_num
5097 from rcv_serial_transactions rcvt
5098 where rcvt.transaction_id = DEL.transaction_id
5099 and rownum = 1
5100 and not exists (Select 'NOT EXIST'
5101 from csd_repairs cra,
5102 csd_product_transactions cpt
5103 where cra.repair_line_id = cpt.repair_line_id
5104 and cpt.action_type = 'MOVE_OUT'
5105 and cpt.order_header_id = ro.order_header_id
5106 and cra.serial_number = rcvt.serial_num);
5107 Exception
5108 WHEN NO_DATA_FOUND THEN
5109 IF ( l_error_level >= G_debug_level) THEN
5110 fnd_message.set_name('CSD','CSD_SERIAL_NUM_MISSING');
5111 fnd_message.set_token('TXN_ID',DEL.transaction_id);
5112 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
5113 ELSE
5114 fnd_message.set_name('CSD','CSD_SERIAL_NUM_MISSING');
5115 fnd_message.set_token('TXN_ID',DEL.transaction_id);
5116 fnd_msg_pub.add;
5117 END If;
5118 RAISE PROCESS_ERROR;
5119 END;
5120 -- Get the instance id from
5121 -- installbase tables
5122 IF NVL(RCV.ib_flag,'N') = 'Y' THEN
5123 BEGIN
5124 Select instance_id
5125 into l_instance_id
5126 from csi_item_instances
5127 where inventory_item_id = RCV.item_id
5128 and serial_number = l_serial_num;
5129 Exception
5130 When NO_DATA_FOUND THEN
5131 IF ( l_error_level >= G_debug_level) THEN
5132 fnd_message.set_name('CSD','CSD_ITEM_INSTANCE_MISSING');
5133 fnd_message.set_token('SERIAL_NUM',l_serial_num);
5134 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
5135 ELSE
5136 fnd_message.set_name('CSD','CSD_ITEM_INSTANCE_MISSING');
5137 fnd_message.set_token('SERIAL_NUM',l_serial_num);
5138 fnd_msg_pub.add;
5139 END If;
5140 When Others THEN
5141 IF ( l_error_level >= G_debug_level) THEN
5142 fnd_message.set_name('CSD','CSD_INV_SERIAL_NUM');
5143 fnd_message.set_token('SERIAL_NUM',l_serial_num);
5144 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
5145 ELSE
5146 fnd_message.set_name('CSD','CSD_INV_SERIAL_NUM');
5147 fnd_message.set_token('SERIAL_NUM',l_serial_num);
5148 fnd_msg_pub.add;
5149 END If;
5150 End;
5151 ELSE
5152 l_instance_id := NULL;
5153 END If;
5154
5155 l_line_del_qty := RO.ro_qty;
5156 ELSE
5157 -- Non-Serialized Case
5158 l_serial_num := NULL;
5159 l_line_del_qty := RO.ordered_quantity;
5160 l_instance_id := NULL;
5161
5162 --lot_control_code = 1 No control
5163 --lot_control_code = 2 Full control
5164 IF RCV.lot_control_code = 2 THEN
5165 BEGIN
5166 Select lot_num
5167 into l_lot_num
5168 from rcv_lot_transactions
5169 where source_transaction_id = DEL.transaction_id;
5170 EXCEPTION
5171 WHEN NO_DATA_FOUND THEN
5172 IF ( l_error_level >= G_debug_level) THEN
5173 fnd_message.set_name('CSD','CSD_INV_TXN_ID');
5174 fnd_message.set_token('TXN_ID',DEL.transaction_id);
5175 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
5176 ELSE
5177 fnd_message.set_name('CSD','CSD_INV_TXN_ID');
5178 fnd_message.set_token('TXN_ID',DEL.transaction_id);
5179 fnd_msg_pub.add;
5180 END IF;
5181 RAISE FND_API.G_EXC_ERROR;
5182 END;
5183 ELSE
5184 l_lot_num := NULL;
5185 END IF;
5186 END IF;
5187
5188 IF l_pt_del_qty >= l_line_del_qty THEN
5189 -- Debug messages
5190 Debug('Exiting the loop',l_mod_name,1);
5191 EXIT;
5192 ELSE
5193 l_rcvd_qty := l_line_del_qty - l_pt_del_qty ;
5194 IF DEL.rcvd_qty < l_rcvd_qty THEN
5195 l_rcvd_qty := DEL.rcvd_qty;
5196 END IF;
5197 END IF;
5198
5199 IF RCV.serial_number_control_code in (2,5,6) THEN
5200 l_rcvd_qty := 1;
5201 ELSE
5202 l_rcvd_qty := l_rcvd_qty - l_total_del_qty;
5203 END IF;
5204
5205 -- Debug messages
5206 Debug('l_rcvd_qty : '||l_rcvd_qty,l_mod_name,1);
5207
5208 -- Update the serial number on repair order
5209 -- with the rcvd serial number
5210 /*Bug#5564180/FP#5845995 Move out line should not update the received quantity of
5211 RO. Move out line should not change the serial and instance number of RO
5212 so commenting the below query
5213 */
5214 /*
5215 UPDATE CSD_REPAIRS
5216 SET SERIAL_NUMBER = l_serial_num,
5217 quantity_rcvd = nvl(quantity_rcvd,0) + l_rcvd_qty,
5218 customer_product_id = l_instance_id,
5219 object_version_number = object_version_number+1,
5220 last_update_date = sysdate,
5221 last_updated_by = fnd_global.user_id,
5222 last_update_login = fnd_global.login_id
5223 WHERE repair_line_id = RO.repair_line_id;
5224 IF SQL%NOTFOUND THEN
5225 IF ( l_error_level >= G_debug_level) THEN
5226 fnd_message.set_name('CSD','CSD_RO_UPD_FAILED');
5227 fnd_message.set_token('REPAIR_LINE_ID',RO.repair_line_id);
5228 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
5229 ELSE
5230 fnd_message.set_name('CSD','CSD_RO_UPD_FAILED');
5231 fnd_message.set_token('REPAIR_LINE_ID',RO.repair_line_id);
5232 fnd_msg_pub.add;
5233 END IF;
5234 RAISE PROCESS_ERROR;
5235 END IF;
5236 */
5237 -- Updating the product txn with the serial number,lot number
5238 -- qty rcvd and subinventory
5239 -- sub_inventory_rcvd is used for IO and subinventory column
5240 -- is used for the regular RMA
5241 UPDATE CSD_PRODUCT_TRANSACTIONS
5242 SET SOURCE_SERIAL_NUMBER = l_serial_num,
5243 source_instance_id = l_instance_id,
5244 LOT_NUMBER_RCVD = l_lot_num,
5245 LOCATOR_ID = DEL.locator_id,
5246 QUANTITY_RECEIVED = NVL(QUANTITY_RECEIVED,0) + l_rcvd_qty,
5247 SUB_INVENTORY_RCVD = DEL.subinventory,
5248 object_version_number = object_version_number+1,
5249 last_update_date = sysdate,
5250 last_updated_by = fnd_global.user_id,
5251 last_update_login = fnd_global.login_id
5252 WHERE product_transaction_id = RO.product_transaction_id;
5253 IF SQL%NOTFOUND THEN
5254 IF ( l_error_level >= G_debug_level) THEN
5255 fnd_message.set_name('CSD','CSD_PROD_TXN_UPD_FAILED');
5256 fnd_message.set_token('PROD_TXN_ID',RO.product_transaction_id);
5257 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
5258 ELSE
5259 fnd_message.set_name('CSD','CSD_PROD_TXN_UPD_FAILED');
5260 fnd_message.set_token('PROD_TXN_ID',RO.product_transaction_id);
5261 fnd_msg_pub.add;
5262 END IF;
5263 RAISE PROCESS_ERROR;
5264 END IF;
5265
5266 IF RCV.serial_number_control_code in (2,5,6) THEN
5267 UPDATE CSD_PRODUCT_TRANSACTIONS
5268 SET prod_txn_status = 'RECEIVED',
5269 object_version_number = object_version_number+1,
5270 last_update_date = sysdate,
5271 last_updated_by = fnd_global.user_id,
5272 last_update_login = fnd_global.login_id
5273 WHERE product_transaction_id = RO.product_transaction_id;
5274 ELSE
5275 UPDATE CSD_PRODUCT_TRANSACTIONS
5276 SET prod_txn_status = 'RECEIVED',
5277 object_version_number = object_version_number+1,
5278 last_update_date = sysdate,
5279 last_updated_by = fnd_global.user_id,
5280 last_update_login = fnd_global.login_id
5281 WHERE quantity_received = RO.ordered_quantity
5282 and product_transaction_id = RO.product_transaction_id;
5283 END IF;
5284
5285 -- Initialize the activity rec
5286 l_activity_rec := INIT_ACTIVITY_REC ;
5287
5288 -- Assign the values for activity record
5289 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
5290 l_activity_rec.REPAIR_LINE_ID := RO.repair_line_id;
5291 l_activity_rec.EVENT_CODE := 'RRI';
5292 l_activity_rec.ACTION_CODE := 0;
5293 l_activity_rec.EVENT_DATE := DEL.received_date;
5294 l_activity_rec.QUANTITY := l_rcvd_qty;
5295 l_activity_rec.PARAMN1 := DEL.transaction_id;
5296 l_activity_rec.PARAMN2 := RO.product_transaction_id;
5297 l_activity_rec.PARAMN3 := DEL.organization_id;
5298 l_activity_rec.PARAMN6 := RO.req_header_id;
5299 l_activity_rec.PARAMC1 := RO.order_number;
5300 l_activity_rec.PARAMC2 := RO.requisition_number;
5301 l_activity_rec.PARAMC3 := DEL.org_name;
5302 l_activity_rec.PARAMC4 := DEL.subinventory;
5303 l_activity_rec.OBJECT_VERSION_NUMBER := null;
5304
5305 -- Debug Messages
5306 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
5307
5308 -- Calling LOG_ACTIVITY for logging activity
5309 -- Receipt of item against Internal Requisition
5310 LOG_ACTIVITY
5311 ( p_api_version => p_api_version,
5312 p_commit => p_commit,
5313 p_init_msg_list => p_init_msg_list,
5314 p_validation_level => p_validation_level,
5315 x_return_status => x_return_status,
5316 x_msg_count => x_msg_count,
5317 x_msg_data => x_msg_data,
5318 p_activity_rec => l_activity_rec );
5319
5320 -- Debug Messages
5321 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
5322 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
5323 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
5324 RAISE FND_API.G_EXC_ERROR;
5325 END IF;
5326
5327 IF (l_pt_del_qty + l_rcvd_qty) >= l_line_del_qty THEN
5328 Debug(' Exiting the DEL loop',l_mod_name,1);
5329 EXIT;
5330 END IF;
5331 Exception
5332 WHEN PROCESS_ERROR THEN
5333 Debug('In process_error exception ',l_mod_name,4);
5334 RAISE PROCESS_ERROR;
5335 WHEN SKIP_RECORD THEN
5336 NULL;
5337 END;
5338 END LOOP; -- end of delivery lines
5339
5340 IF (l_pt_reject_qty+ l_pt_accept_qty + l_accept_qty)>= l_line_qty THEN
5341 Debug('Exiting RCV the loop ',l_mod_name,1);
5342 EXIT;
5343 END IF;
5344
5345 ELSIF RCV.transaction_type = 'REJECT' THEN
5346 -- Handles Inspection Required routing option
5347
5348 select nvl(sum(paramn4),0)
5349 into l_total_reject_qty
5350 from csd_repair_history crh
5351 where crh.event_code = 'IP'
5352 and crh.paramn1 = RCV.transaction_id;
5353 IF l_total_reject_qty >= RCV.rcvd_qty THEN
5354 -- Debug messages
5355 Debug('Skipping the record ',l_mod_name,1);
5356 RAISE SKIP_RECORD;
5357 END IF;
5358
5359 select nvl(sum(paramn3),0),nvl(sum(paramn4),0)
5360 into l_pt_accept_qty, l_pt_reject_qty
5361 from csd_repair_history crh
5362 where crh.event_code = 'IP'
5363 and crh.paramn2 = RO.product_transaction_id;
5364 -- Debug messages
5365 Debug('l_pt_accept_qty'||l_pt_accept_qty,l_mod_name,1);
5366 Debug('l_pt_reject_qty'||l_pt_reject_qty,l_mod_name,1);
5367
5368 IF RCV.serial_number_control_code in (2,5,6) THEN
5369 l_line_qty := 1;
5370 ELSE
5371 l_line_qty := RO.ordered_quantity;
5372 END IF;
5373 IF l_pt_accept_qty+ l_pt_reject_qty >= l_line_qty THEN
5374 -- Debug messages
5375 Debug('Exiting the loop ',l_mod_name,1);
5376 EXIT;
5377 ELSE
5378 l_reject_qty := l_line_qty- (l_pt_accept_qty+ l_pt_reject_qty);
5379 IF RCV.rcvd_qty < l_reject_qty THEN
5380 l_reject_qty := RCV.rcvd_qty;
5381 END IF;
5382 END IF;
5383
5384 IF RCV.serial_number_control_code in (2,5,6) THEN
5385 l_reject_qty := 1;
5386 ELSE
5387 l_reject_qty := l_reject_qty - l_total_reject_qty;
5388 END IF;
5389
5390 -- Debug messages
5391 Debug('l_reject_qty'||l_reject_qty,l_mod_name,1);
5392
5393 -- Initialize the activity rec
5394 l_activity_rec := INIT_ACTIVITY_REC ;
5395
5396 -- Assign the values for activity record
5397 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
5398 l_activity_rec.REPAIR_LINE_ID := RO.repair_line_id;
5399 l_activity_rec.EVENT_CODE := 'IP';
5400 l_activity_rec.ACTION_CODE := 0;
5401 l_activity_rec.EVENT_DATE := RCV.received_date;
5402 l_activity_rec.QUANTITY := l_reject_qty;
5403 l_activity_rec.PARAMN1 := RCV.transaction_id;
5404 l_activity_rec.PARAMN2 := RO.product_transaction_id;
5405 l_activity_rec.PARAMN3 := null;
5406 l_activity_rec.PARAMN4 := l_reject_qty;
5407 l_activity_rec.PARAMN6 := RO.req_header_id;
5408 l_activity_rec.PARAMC1 := RO.requisition_number;
5409 l_activity_rec.PARAMC2 := rcv.subinventory;
5410 l_activity_rec.OBJECT_VERSION_NUMBER := null;
5411
5412 -- Debug Messages
5413 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
5414
5415 -- Calling LOG_ACTIVITY for logging activity
5416 LOG_ACTIVITY
5417 ( p_api_version => p_api_version,
5418 p_commit => p_commit,
5419 p_init_msg_list => p_init_msg_list,
5420 p_validation_level => p_validation_level,
5421 x_return_status => x_return_status,
5422 x_msg_count => x_msg_count,
5423 x_msg_data => x_msg_data,
5424 p_activity_rec => l_activity_rec );
5425
5426 -- Debug Messages
5427 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
5428 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
5429 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
5430 RAISE FND_API.G_EXC_ERROR;
5431 END IF;
5432
5433 -- Check if there are "DELIVER" txn lines against the reject lines
5434 -- If found, then process the deliver lines also
5435 FOR DEL IN DELIVER_LINES(RCV.transaction_id)
5436 LOOP
5437 BEGIN
5438 -- Debug messages
5439 Debug('In DEL Loop ',l_mod_name,1);
5440
5441 select nvl(sum(quantity),0)
5442 into l_total_del_qty
5443 from csd_repair_history crh
5444 where crh.event_code = 'RRI'
5445 and crh.paramn1 = DEL.transaction_id;
5446 -- Debug messages
5447 Debug('l_total_del_qty : '||l_total_del_qty,l_mod_name,1);
5448
5449 IF l_total_del_qty >= DEL.rcvd_qty THEN
5450 -- Debug messages
5451 Debug('Skipping the record',l_mod_name,1);
5452 RAISE SKIP_RECORD;
5453 END IF;
5454
5455 select nvl(sum(quantity),0)
5456 into l_pt_del_qty
5457 from csd_repair_history crh
5458 where crh.event_code = 'RRI'
5459 and crh.paramn2 = RO.product_transaction_id;
5460 -- Debug messages
5461 Debug('l_pt_del_qty : '||l_pt_del_qty,l_mod_name,1);
5462
5463 IF RCV.serial_number_control_code in (2,5,6) THEN
5464 -- SERIALIZED CASE
5465 Begin
5466 select rcvt.serial_num,
5467 rcvt.lot_num
5468 into l_serial_num,
5469 l_lot_num
5470 from rcv_serial_transactions rcvt
5471 where rcvt.transaction_id = DEL.transaction_id
5472 and rownum = 1
5473 and not exists (Select 'NOT EXIST'
5474 from csd_repairs cra,
5475 csd_product_transactions cpt
5476 where cra.repair_line_id = cpt.repair_line_id
5477 and cpt.action_type = 'MOVE_OUT'
5478 and cpt.order_header_id = ro.order_header_id
5479 and cra.serial_number = rcvt.serial_num);
5480 Exception
5481 WHEN NO_DATA_FOUND THEN
5482 IF ( l_error_level >= G_debug_level) THEN
5483 fnd_message.set_name('CSD','CSD_SERIAL_NUM_MISSING');
5484 fnd_message.set_token('TXN_ID',DEL.transaction_id);
5485 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
5486 ELSE
5487 fnd_message.set_name('CSD','CSD_SERIAL_NUM_MISSING');
5488 fnd_message.set_token('TXN_ID',DEL.transaction_id);
5489 fnd_msg_pub.add;
5490 END If;
5491 RAISE PROCESS_ERROR;
5492 END;
5493 -- Get the instance id from
5494 -- installbase tables
5495 IF NVL(RCV.ib_flag,'N') = 'Y' THEN
5496 BEGIN
5497 Select instance_id
5498 into l_instance_id
5499 from csi_item_instances
5500 where inventory_item_id = RCV.item_id
5501 and serial_number = l_serial_num;
5502 Exception
5503 When NO_DATA_FOUND THEN
5504 IF ( l_error_level >= G_debug_level) THEN
5505 fnd_message.set_name('CSD','CSD_ITEM_INSTANCE_MISSING');
5506 fnd_message.set_token('SERIAL_NUM',l_serial_num);
5507 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
5508 ELSE
5509 fnd_message.set_name('CSD','CSD_ITEM_INSTANCE_MISSING');
5510 fnd_message.set_token('SERIAL_NUM',l_serial_num);
5511 fnd_msg_pub.add;
5512 END If;
5513 When Others THEN
5514 IF ( l_error_level >= G_debug_level) THEN
5515 fnd_message.set_name('CSD','CSD_INV_SERIAL_NUM');
5516 fnd_message.set_token('SERIAL_NUM',l_serial_num);
5517 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
5518 ELSE
5519 fnd_message.set_name('CSD','CSD_INV_SERIAL_NUM');
5520 fnd_message.set_token('SERIAL_NUM',l_serial_num);
5521 fnd_msg_pub.add;
5522 END If;
5523 End;
5524 ELSE
5525 l_instance_id := NULL;
5526 END IF;
5527
5528 l_line_del_qty := RO.ro_qty;
5529 ELSE
5530 -- Non-Serialized Case
5531 l_serial_num := NULL;
5532 l_line_del_qty := RO.ordered_quantity;
5533 l_instance_id := NULL;
5534
5535 --lot_control_code = 1 No control
5536 --lot_control_code = 2 Full control
5537 IF RCV.lot_control_code = 2 THEN
5538 BEGIN
5539 Select lot_num
5540 into l_lot_num
5541 from rcv_lot_transactions
5542 where source_transaction_id = DEL.transaction_id;
5543 EXCEPTION
5544 WHEN NO_DATA_FOUND THEN
5545 IF ( l_error_level >= G_debug_level) THEN
5546 fnd_message.set_name('CSD','CSD_INV_TXN_ID');
5547 fnd_message.set_token('TXN_ID',DEL.transaction_id);
5548 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
5549 ELSE
5550 fnd_message.set_name('CSD','CSD_INV_TXN_ID');
5551 fnd_message.set_token('TXN_ID',DEL.transaction_id);
5552 fnd_msg_pub.add;
5553 END IF;
5554 RAISE FND_API.G_EXC_ERROR;
5555 END;
5556 ELSE
5557 l_lot_num := NULL;
5558 END IF;
5559 END IF;
5560
5561 IF l_pt_del_qty >= l_line_del_qty THEN
5562 -- Debug messages
5563 Debug('Exiting the loop',l_mod_name,1);
5564 EXIT;
5565 ELSE
5566 l_rcvd_qty := l_line_del_qty - l_pt_del_qty ;
5567 IF DEL.rcvd_qty < l_rcvd_qty THEN
5568 l_rcvd_qty := DEL.rcvd_qty;
5569 END IF;
5570 END IF;
5571
5572 IF RCV.serial_number_control_code in (2,5,6) THEN
5573 l_rcvd_qty := 1;
5574 ELSE
5575 l_rcvd_qty := l_rcvd_qty - l_total_del_qty;
5576 END IF;
5577
5578 -- Debug messages
5579 Debug('l_rcvd_qty : '||l_rcvd_qty,l_mod_name,1);
5580
5581 -- Update the serial number on repair order
5582 -- with the rcvd serial number
5583 /*Bug#5564180/FP#5845995 Move out line should not update the received quantity of
5584 RO. Move out line should not change the serial and instance number of RO
5585 so commenting the below query
5586 */
5587 /*
5588 UPDATE CSD_REPAIRS
5589 SET SERIAL_NUMBER = l_serial_num,
5590 quantity_rcvd = nvl(quantity_rcvd,0) + l_rcvd_qty,
5591 customer_product_id = l_instance_id,
5592 object_version_number = object_version_number+1,
5593 last_update_date = sysdate,
5594 last_updated_by = fnd_global.user_id,
5595 last_update_login = fnd_global.login_id
5596 WHERE repair_line_id = RO.repair_line_id;
5597 IF SQL%NOTFOUND THEN
5598 IF ( l_error_level >= G_debug_level) THEN
5599 fnd_message.set_name('CSD','CSD_RO_UPD_FAILED');
5600 fnd_message.set_token('REPAIR_LINE_ID',RO.repair_line_id);
5601 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
5602 ELSE
5603 fnd_message.set_name('CSD','CSD_RO_UPD_FAILED');
5604 fnd_message.set_token('REPAIR_LINE_ID',RO.repair_line_id);
5605 fnd_msg_pub.add;
5606 END IF;
5607 RAISE PROCESS_ERROR;
5608 END IF;
5609 */
5610
5611 -- Updating the product txn with the serial number,lot number
5612 -- qty rcvd and subinventory
5613 -- sub_inventory_rcvd is used for IO and subinventory column
5614 -- is used for the regular RMA
5615 UPDATE CSD_PRODUCT_TRANSACTIONS
5616 SET SOURCE_SERIAL_NUMBER = l_serial_num,
5617 source_instance_id = l_instance_id,
5618 LOT_NUMBER_RCVD = l_lot_num,
5619 LOCATOR_ID = DEL.locator_id,
5620 QUANTITY_RECEIVED = NVL(QUANTITY_RECEIVED,0) + l_rcvd_qty,
5621 SUB_INVENTORY_RCVD = DEL.subinventory,
5622 object_version_number = object_version_number+1,
5623 last_update_date = sysdate,
5624 last_updated_by = fnd_global.user_id,
5625 last_update_login = fnd_global.login_id
5626 WHERE product_transaction_id = RO.product_transaction_id;
5627 IF SQL%NOTFOUND THEN
5628 IF ( l_error_level >= G_debug_level) THEN
5629 fnd_message.set_name('CSD','CSD_PROD_TXN_UPD_FAILED');
5630 fnd_message.set_token('PROD_TXN_ID',RO.product_transaction_id);
5631 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
5632 ELSE
5633 fnd_message.set_name('CSD','CSD_PROD_TXN_UPD_FAILED');
5634 fnd_message.set_token('PROD_TXN_ID',RO.product_transaction_id);
5635 fnd_msg_pub.add;
5636 END IF;
5637 RAISE PROCESS_ERROR;
5638 END IF;
5639
5640 IF RCV.serial_number_control_code in (2,5,6) THEN
5641 UPDATE CSD_PRODUCT_TRANSACTIONS
5642 SET prod_txn_status = 'RECEIVED',
5643 object_version_number = object_version_number+1,
5644 last_update_date = sysdate,
5645 last_updated_by = fnd_global.user_id,
5646 last_update_login = fnd_global.login_id
5647 WHERE product_transaction_id = RO.product_transaction_id;
5648
5649 ELSE
5650 UPDATE CSD_PRODUCT_TRANSACTIONS
5651 SET prod_txn_status = 'RECEIVED',
5652 object_version_number = object_version_number+1,
5653 last_update_date = sysdate,
5654 last_updated_by = fnd_global.user_id,
5655 last_update_login = fnd_global.login_id
5656 WHERE quantity_received = RO.ordered_quantity
5657 and product_transaction_id = RO.product_transaction_id;
5658 END IF;
5659
5660 -- Initialize the activity rec
5661 l_activity_rec := INIT_ACTIVITY_REC ;
5662
5663 -- Assign the values for activity record
5664 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
5665 l_activity_rec.REPAIR_LINE_ID := RO.repair_line_id;
5666 l_activity_rec.EVENT_CODE := 'RRI';
5667 l_activity_rec.ACTION_CODE := 0;
5668 l_activity_rec.EVENT_DATE := DEL.received_date;
5669 l_activity_rec.QUANTITY := l_rcvd_qty;
5670 l_activity_rec.PARAMN1 := DEL.transaction_id;
5671 l_activity_rec.PARAMN2 := RO.product_transaction_id;
5672 l_activity_rec.PARAMN3 := DEL.organization_id;
5673 l_activity_rec.PARAMN6 := RO.req_header_id;
5674 l_activity_rec.PARAMC1 := RO.order_number;
5675 l_activity_rec.PARAMC2 := RO.requisition_number;
5676 l_activity_rec.PARAMC3 := DEL.org_name;
5677 l_activity_rec.PARAMC4 := DEL.subinventory;
5678 l_activity_rec.OBJECT_VERSION_NUMBER := null;
5679
5680 -- Debug Messages
5681 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
5682
5683 -- Calling LOG_ACTIVITY for logging activity
5684 -- Receipt of item against Internal Requisition
5685 LOG_ACTIVITY
5686 ( p_api_version => p_api_version,
5687 p_commit => p_commit,
5688 p_init_msg_list => p_init_msg_list,
5689 p_validation_level => p_validation_level,
5690 x_return_status => x_return_status,
5691 x_msg_count => x_msg_count,
5692 x_msg_data => x_msg_data,
5693 p_activity_rec => l_activity_rec );
5694
5695 -- Debug Messages
5696 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
5697 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
5698 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
5699 RAISE FND_API.G_EXC_ERROR;
5700 END IF;
5701
5702 IF (l_pt_del_qty + l_rcvd_qty) >= l_line_del_qty THEN
5703 Debug(' Exiting the DEL loop',l_mod_name,1);
5704 EXIT;
5705 END IF;
5706 Exception
5707 WHEN PROCESS_ERROR THEN
5708 Debug('In process_error exception ',l_mod_name,4);
5709 RAISE PROCESS_ERROR;
5710 WHEN SKIP_RECORD THEN
5711 NULL;
5712 END;
5713 END LOOP; -- end of delivery lines
5714
5715 IF l_pt_accept_qty+ l_pt_reject_qty+ l_reject_qty >= l_line_qty THEN
5716 Debug(' Exiting the RCV loop',l_mod_name,1);
5717 EXIT;
5718 END IF;
5719
5720 ELSIF RCV.transaction_type = 'DELIVER' THEN
5721 -- Handles the Direct Delivery and standard routing options
5722
5723 select nvl(sum(quantity),0)
5724 into l_total_qty
5725 from csd_repair_history crh
5726 where crh.event_code = 'RRI'
5727 and crh.paramn1 = RCV.transaction_id;
5728 IF l_total_qty >= RCV.rcvd_qty THEN
5729 -- Debug messages
5730 Debug(' Skipping the record',l_mod_name,1);
5731 RAISE SKIP_RECORD;
5732 END IF;
5733
5734 select nvl(sum(quantity),0)
5735 into l_pt_del_qty
5736 from csd_repair_history crh
5737 where crh.event_code = 'RRI'
5738 and paramn2 = RO.product_transaction_id;
5739
5740 -- Debug messages
5741 Debug('l_pt_reject_qty='||l_pt_reject_qty,l_mod_name,1);
5742 Debug('l_pt_del_qty ='||l_pt_del_qty,l_mod_name,1);
5743
5744 IF RCV.serial_number_control_code in (2,5,6) THEN
5745 -- SERIALIZED AND LOT CONTROLLED CASE
5746 l_line_qty := RO.ro_qty;
5747 Begin
5748 select rcvt.serial_num,
5749 rcvt.lot_num
5750 into l_serial_num,
5751 l_lot_num
5752 from rcv_serial_transactions rcvt
5753 where rcvt.transaction_id = RCV.transaction_id
5754 and rownum = 1;
5755
5756 --bug#7452134.
5757 --Due to bug#7452134, the customer BROOKS AUTOMATION ran into this issue if they
5758 --try to recieve an item from diff operating unit. When user click update logistic
5759 --button, then this error raising. From what I see on the customer's environment
5760 --This code (condition) should not be here. I am not sure why we are checking
5761 --the serial number in the production transaction table. After commented this
5762 --condition, it worked for the customer.
5763 -- and not exists (Select 'NOT EXIST'
5764 -- from csd_repairs cra,
5765 -- csd_product_transactions cpt
5766 -- where cra.repair_line_id = cpt.repair_line_id
5767 -- and cpt.order_header_id = ro.order_header_id
5768 -- and cra.serial_number = rcvt.serial_num);
5769 Exception
5770 WHEN NO_DATA_FOUND THEN
5771 IF ( l_error_level >= G_debug_level) THEN
5772 fnd_message.set_name('CSD','CSD_SERIAL_NUM_MISSING');
5773 fnd_message.set_token('TXN_ID',RCV.transaction_id);
5774 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
5775 ELSE
5776 fnd_message.set_name('CSD','CSD_SERIAL_NUM_MISSING');
5777 fnd_message.set_token('TXN_ID',RCV.transaction_id);
5778 fnd_msg_pub.add;
5779 END IF;
5780 RAISE PROCESS_ERROR;
5781 END;
5782
5783 -- Get the instance id from
5784 -- installbase tables
5785 IF NVL(RCV.ib_flag,'N') = 'Y' THEN
5786 BEGIN
5787 Select instance_id
5788 into l_instance_id
5789 from csi_item_instances
5790 where inventory_item_id = RCV.item_id
5791 and serial_number = l_serial_num;
5792 Exception
5793 When NO_DATA_FOUND THEN
5794 IF ( l_error_level >= G_debug_level) THEN
5795 fnd_message.set_name('CSD','CSD_ITEM_INSTANCE_MISSING');
5796 fnd_message.set_token('SERIAL_NUM',l_serial_num);
5797 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
5798 ELSE
5799 fnd_message.set_name('CSD','CSD_ITEM_INSTANCE_MISSING');
5800 fnd_message.set_token('SERIAL_NUM',l_serial_num);
5801 fnd_msg_pub.add;
5802 END If;
5803 When Others THEN
5804 IF ( l_error_level >= G_debug_level) THEN
5805 fnd_message.set_name('CSD','CSD_INV_SERIAL_NUM');
5806 fnd_message.set_token('SERIAL_NUM',l_serial_num);
5807 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
5808 ELSE
5809 fnd_message.set_name('CSD','CSD_INV_SERIAL_NUM');
5810 fnd_message.set_token('SERIAL_NUM',l_serial_num);
5811 fnd_msg_pub.add;
5812 END If;
5813 End;
5814 ELSE
5815 l_instance_id := NULL;
5816 END IF;
5817 ELSE
5818 -- Non-Serialized Case but lot controlled
5819 l_serial_num := NULL;
5820 l_line_qty := RO.ordered_quantity;
5821 l_instance_id := NULL;
5822
5823 --lot_control_code = 1 No control
5824 --lot_control_code = 2 Full control
5825 IF RCV.lot_control_code = 2 THEN
5826 BEGIN
5827 Select lot_num
5828 into l_lot_num
5829 from rcv_lot_transactions
5830 where source_transaction_id = RCV.transaction_id;
5831 EXCEPTION
5832 WHEN NO_DATA_FOUND THEN
5833 IF ( l_error_level >= G_debug_level) THEN
5834 fnd_message.set_name('CSD','CSD_INV_TXN_ID');
5835 fnd_message.set_token('TXN_ID',RCV.transaction_id);
5836 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
5837 ELSE
5838 fnd_message.set_name('CSD','CSD_INV_TXN_ID');
5839 fnd_message.set_token('TXN_ID',RCV.transaction_id);
5840 fnd_msg_pub.add;
5841 END IF;
5842 RAISE FND_API.G_EXC_ERROR;
5843 END;
5844 ELSE
5845 -- Non-Serialized Case but not lot controlled
5846 l_lot_num := NULL;
5847 END IF;
5848 END IF;
5849
5850 IF l_pt_del_qty >= l_line_qty THEN
5851 Debug(' EXiting the RCV Loop',l_mod_name,1);
5852 EXIT;
5853 ELSE
5854 l_rcvd_qty := l_line_qty - l_pt_del_qty;
5855 IF RCV.rcvd_qty < l_rcvd_qty THEN
5856 l_rcvd_qty := RCV.rcvd_qty;
5857 END IF;
5858 END IF;
5859
5860 IF RCV.serial_number_control_code in (2,5,6) THEN
5861 l_rcvd_qty := 1;
5862 ELSE
5863 l_rcvd_qty := l_rcvd_qty - l_total_qty;
5864 END IF;
5865
5866 -- Debug messages
5867 Debug('l_rcvd_qty'||l_rcvd_qty,l_mod_name,1);
5868
5869 -- Update repair order with the rcvd serial number
5870 -- and the rcvd qty
5871 /*Bug#5564180/FP#5845995 Move out line should not update the received quantity of
5872 RO. Move out line should not change the serial and instance number of RO
5873 so commenting the below query
5874 */
5875 /*
5876 UPDATE CSD_REPAIRS
5877 SET SERIAL_NUMBER = l_serial_num,
5878 quantity_rcvd = nvl(quantity_rcvd,0) + l_rcvd_qty,
5879 customer_product_id = l_instance_id,
5880 object_version_number = object_version_number+1,
5881 last_update_date = sysdate,
5882 last_updated_by = fnd_global.user_id,
5883 last_update_login = fnd_global.login_id
5884 WHERE repair_line_id = RO.repair_line_id;
5885 IF SQL%NOTFOUND THEN
5886 IF ( l_error_level >= G_debug_level) THEN
5887 fnd_message.set_name('CSD','CSD_RO_UPD_FAILED');
5888 fnd_message.set_token('REPAIR_LINE_ID',RO.repair_line_id);
5889 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
5890 ELSE
5891 fnd_message.set_name('CSD','CSD_RO_UPD_FAILED');
5892 fnd_message.set_token('REPAIR_LINE_ID',RO.repair_line_id);
5893 fnd_msg_pub.add;
5894 END IF;
5895 RAISE PROCESS_ERROR;
5896 END IF;
5897 */
5898
5899 -- Update product txn with the rcvd serial number,lot number
5900 -- locator id, sub inv, status and the rcvd qty
5901 UPDATE CSD_PRODUCT_TRANSACTIONS
5902 SET SOURCE_SERIAL_NUMBER = l_serial_num,
5903 source_instance_id = l_instance_id,
5904 LOT_NUMBER_RCVD = l_lot_num,
5905 QUANTITY_RECEIVED = NVL(QUANTITY_RECEIVED,0) + l_rcvd_qty,
5906 SUB_INVENTORY_RCVD= RCV.subinventory,
5907 LOCATOR_ID = RCV.locator_id,
5908 object_version_number = object_version_number+1,
5909 last_update_date = sysdate,
5910 last_updated_by = fnd_global.user_id,
5911 last_update_login = fnd_global.login_id
5912 WHERE product_transaction_id = RO.product_transaction_id;
5913 IF SQL%NOTFOUND THEN
5914 IF ( l_error_level >= G_debug_level) THEN
5915 fnd_message.set_name('CSD','CSD_PROD_TXN_UPD_FAILED');
5916 fnd_message.set_token('PROD_TXN_ID',RO.product_transaction_id);
5917 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
5918 ELSE
5919 fnd_message.set_name('CSD','CSD_PROD_TXN_UPD_FAILED');
5920 fnd_message.set_token('PROD_TXN_ID',RO.product_transaction_id);
5921 fnd_msg_pub.add;
5922 END IF;
5923 RAISE PROCESS_ERROR;
5924 END IF;
5925
5926 IF RCV.serial_number_control_code in (2,5,6) THEN
5927 UPDATE CSD_PRODUCT_TRANSACTIONS
5928 SET prod_txn_status = 'RECEIVED',
5929 object_version_number = object_version_number+1,
5930 last_update_date = sysdate,
5931 last_updated_by = fnd_global.user_id,
5932 last_update_login = fnd_global.login_id
5933 WHERE product_transaction_id = RO.product_transaction_id;
5934 ELSE
5935 UPDATE CSD_PRODUCT_TRANSACTIONS
5936 SET prod_txn_status = 'RECEIVED',
5937 object_version_number = object_version_number+1,
5938 last_update_date = sysdate,
5939 last_updated_by = fnd_global.user_id,
5940 last_update_login = fnd_global.login_id
5941 WHERE quantity_received = RO.ordered_quantity
5942 and product_transaction_id = RO.product_transaction_id;
5943 END IF;
5944
5945 -- Initialize the activity rec
5946 l_activity_rec := INIT_ACTIVITY_REC ;
5947
5948 -- Assign the values for activity record
5949 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
5950 l_activity_rec.REPAIR_LINE_ID := RO.repair_line_id;
5951 l_activity_rec.EVENT_CODE := 'RRI';
5952 l_activity_rec.ACTION_CODE := 0;
5953 l_activity_rec.EVENT_DATE := RCV.received_date;
5954 l_activity_rec.QUANTITY := l_rcvd_qty;
5955 l_activity_rec.PARAMN1 := RCV.transaction_id;
5956 l_activity_rec.PARAMN2 := RO.product_transaction_id;
5957 l_activity_rec.PARAMN3 := RCV.organization_id;
5958 l_activity_rec.PARAMN6 := RO.req_header_id;
5959 l_activity_rec.PARAMC1 := RO.order_number;
5960 l_activity_rec.PARAMC2 := RO.requisition_number;
5961 l_activity_rec.PARAMC3 := RCV.org_name;
5962 l_activity_rec.PARAMC4 := RCV.subinventory;
5963 l_activity_rec.OBJECT_VERSION_NUMBER := null;
5964
5965 -- Debug Messages
5966 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
5967
5968 -- Calling LOG_ACTIVITY for logging activity
5969 LOG_ACTIVITY
5970 ( p_api_version => p_api_version,
5971 p_commit => p_commit,
5972 p_init_msg_list => p_init_msg_list,
5973 p_validation_level => p_validation_level,
5974 x_return_status => x_return_status,
5975 x_msg_count => x_msg_count,
5976 x_msg_data => x_msg_data,
5977 p_activity_rec => l_activity_rec );
5978
5979 -- Debug Messages
5980 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
5981 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
5982 Debug('LOG_ACTIVITY api failed ',l_mod_name,1);
5983 RAISE FND_API.G_EXC_ERROR;
5984 END IF;
5985
5986 IF l_pt_del_qty+ l_rcvd_qty >= l_line_qty THEN
5987 Debug(' exiting the RCV loop',l_mod_name,1);
5988 EXIT;
5989 END IF;
5990 END IF;
5991 Exception
5992 WHEN PROCESS_ERROR THEN
5993 Debug(' In Process error exception',l_mod_name,4);
5994 RAISE PROCESS_ERROR;
5995 WHEN SKIP_RECORD THEN
5996 NULL;
5997 END;
5998 END LOOP;
5999 Exception
6000 WHEN PROCESS_ERROR THEN
6001 ROLLBACK TO RCV_LINES;
6002 Debug(' In Process error exception, exiting the loop',l_mod_name,1);
6003 -- In case of error, exit the loop. Commit the processed records
6004 -- and rollback the error record
6005 --RAISE FND_API.G_EXC_ERROR;
6006 x_return_status := FND_API.G_RET_STS_ERROR ;
6007 EXIT;
6008 END;
6009 END LOOP;
6010
6011 --Added by Vijay 11/4/04
6012 IF(GET_RO_PROD_TXN_LINES_All%ISOPEN) THEN
6013 CLOSE GET_RO_PROD_TXN_LINES_All;
6014 END IF;
6015 IF(GET_RO_PROD_TXN_LINES%ISOPEN) THEN
6016 CLOSE GET_RO_PROD_TXN_LINES;
6017 END IF;
6018
6019
6020 -- Standard check of p_commit.
6021 IF FND_API.To_Boolean( p_commit ) THEN
6022 COMMIT WORK;
6023 END IF;
6024
6025 -- Standard call to get message count and IF count is get message info.
6026 FND_MSG_PUB.Count_And_Get
6027 (p_count => x_msg_count,
6028 p_data => x_msg_data);
6029 EXCEPTION
6030 WHEN FND_API.G_EXC_ERROR THEN
6031 Debug('In FND_API.G_EXC_ERROR exception',l_mod_name,4);
6032 ROLLBACK TO IO_RCV_UPDATE_MOVE_OUT;
6033 x_return_status := FND_API.G_RET_STS_ERROR ;
6034 FND_MSG_PUB.Count_And_Get
6035 (p_count => x_msg_count,
6036 p_data => x_msg_data );
6037 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6038 Debug('In FND_API.G_EXC_UNEXPECTED_ERROR exception',l_mod_name,4);
6039 ROLLBACK TO IO_RCV_UPDATE_MOVE_OUT;
6040 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6041 FND_MSG_PUB.Count_And_Get
6042 ( p_count => x_msg_count,
6043 p_data => x_msg_data );
6044 WHEN OTHERS THEN
6045 Debug('In OTHERS exception',l_mod_name,4);
6046 ROLLBACK TO IO_RCV_UPDATE_MOVE_OUT;
6047 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6048 IF FND_MSG_PUB.Check_Msg_Level
6049 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6050 THEN
6051 FND_MSG_PUB.Add_Exc_Msg
6052 (G_PKG_NAME ,
6053 l_api_name );
6054 END IF;
6055 FND_MSG_PUB.Count_And_Get
6056 (p_count => x_msg_count,
6057 p_data => x_msg_data );
6058 END IO_RCV_UPDATE_MOVE_OUT;
6059
6060 /*-------------------------------------------------------------------------------------*/
6061 /* Procedure name: SHIP_UPDATE */
6062 /* Description : Procedure called from the UI to update the depot tables */
6063 /* for the shipment against regular sales order/Internal Sales Order */
6064 /* It calls SO_SHIP_UPDATE and IO_SHIP_UPDATE to process sales order */
6065 /* and internal sales order */
6066 /* Called from : Called from Depot Repair UI */
6067 /* STANDARD PARAMETERS */
6068 /* In Parameters : */
6069 /* p_api_version NUMBER Required Api Version number */
6070 /* p_init_msg_list VARCHAR2 Optional To Initialize message stack */
6071 /* p_commit VARCHAR2 Optional Commits in API */
6072 /* p_validation_level NUMBER Optional validation level */
6073 /* */
6074 /* Output Parameters: */
6075 /* x_return_status VARCHAR2 Return status of the API */
6076 /* x_msg_count NUMBER Number of messages in stack */
6077 /* x_msg_data VARCHAR2 Error Message from message stack */
6078 /* */
6079 /* NON-STANDARD PARAMETERS */
6080 /* In Parameters */
6081 /* p_order_header_id NUMBER Optional Interal sales order Id */
6082 /* p_internal_order_flag VARCHAR2 Required Order Type; Possible values -'Y','N' */
6083 /* p_repair_line_id NUMBER Optional Repair Order Line Id */
6084 /* Output Parm : */
6085 /* Change Hist : */
6086 /* 09/20/03 vlakaman Initial Creation. */
6087 /*-------------------------------------------------------------------------------------*/
6088
6089 Procedure SHIP_UPDATE
6090 ( p_api_version IN NUMBER,
6091 p_commit IN VARCHAR2,
6092 p_init_msg_list IN VARCHAR2,
6093 p_validation_level IN NUMBER,
6094 x_return_status OUT NOCOPY VARCHAR2,
6095 x_msg_count OUT NOCOPY NUMBER,
6096 x_msg_data OUT NOCOPY VARCHAR2,
6097 p_internal_order_flag IN VARCHAR2,
6098 p_order_header_id IN NUMBER,
6099 p_repair_line_id IN NUMBER,
6100 p_past_num_of_days IN NUMBER DEFAULT NULL) ----bug#6753684, 6742512
6101 IS
6102
6103 -- Standard Variables
6104 l_api_name CONSTANT VARCHAR2(30) := 'SHIPMENT_UPDATE';
6105 l_api_version CONSTANT NUMBER := 1.0;
6106
6107 -- Variables in FND log
6108 l_error_level number := FND_LOG.LEVEL_ERROR;
6109 l_mod_name varchar2(2000) := 'csd.plsql.csd_update_programs_pvt.ship_update';
6110
6111 --bug#8261344
6112 l_return_status varchar2(1);
6113 l_msg_data_warning VARCHAR2(30000);
6114
6115
6116 BEGIN
6117 -- Standard Start of API savepoint
6118 SAVEPOINT SHIP_UPDATE;
6119
6120 -- Initialize API return status to success
6121 x_return_status := FND_API.G_RET_STS_SUCCESS;
6122
6123 -- Log the api name in the log file
6124 Debug('At the Beginning of shipment Update ',l_mod_name,1);
6125 Debug('p_internal_order_flag ='||p_internal_order_flag,l_mod_name,1);
6126 Debug('p_order_header_id ='||p_order_header_id,l_mod_name,1);
6127 Debug('p_repair_line_id ='||p_repair_line_id,l_mod_name,1);
6128
6129 -- Standard call to check for call compatibility.
6130 IF NOT FND_API.Compatible_API_Call (l_api_version,
6131 p_api_version,
6132 l_api_name ,
6133 G_PKG_NAME )
6134 THEN
6135 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6136 END IF;
6137
6138 -- Initialize message list if p_init_msg_list is set to TRUE.
6139 IF FND_API.to_Boolean( p_init_msg_list ) THEN
6140 FND_MSG_PUB.initialize;
6141 END IF;
6142
6143 -- Api body starts
6144 IF p_internal_order_flag = 'Y' then
6145 Debug('Calling IO_SHIP_UPDATE ',l_mod_name,2);
6146 -- Call the api for processing of shipment against internal order
6147 IO_SHIP_UPDATE
6148 ( p_api_version => p_api_version,
6149 p_commit => p_commit ,
6150 p_init_msg_list => p_init_msg_list,
6151 p_validation_level => p_validation_level,
6152 x_return_status => x_return_status,
6153 x_msg_count => x_msg_count,
6154 x_msg_data => x_msg_data ,
6155 p_order_header_id => p_order_header_id);
6156
6157 Debug('Return status from IO_SHIP_UPDATE '||x_return_status,l_mod_name,2);
6158 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
6159 Debug('IO_SHIP_UPDATE failed ',l_mod_name,4);
6160 RAISE FND_API.G_EXC_ERROR;
6161 END IF;
6162
6163 /*Fixed for bug#5564180/FP#5845995
6164 Call to API IO_RCV_UPDATE_MOVE_OUT is added so that
6165 move out line can be updated for receiving in destination
6166 organization.
6167 */
6168 Debug('Calling IO_RCV_UPDATE_MOVE_OUT API',l_mod_name,2);
6169 -- Call the api for processing the receipt against
6170 -- internal requisition
6171 IO_RCV_UPDATE_MOVE_OUT
6172 ( p_api_version => p_api_version,
6173 p_commit => p_commit ,
6174 p_init_msg_list => p_init_msg_list,
6175 p_validation_level => p_validation_level,
6176 x_return_status => x_return_status,
6177 x_msg_count => x_msg_count,
6178 x_msg_data => x_msg_data ,
6179 p_order_header_id => p_order_header_id );
6180
6181 -- Debug messages
6182 Debug('Return Status from IO_RCV_UPDATE_MOVE_OUT :'||x_return_status,l_mod_name,2);
6183 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
6184 Debug('IO_RCV_UPDATE_MOVE_OUT failed',l_mod_name,4);
6185 RAISE FND_API.G_EXC_ERROR;
6186 END IF;
6187
6188
6189 Else
6190 Debug('Calling SO_SHIP_UPDATE ',l_mod_name,2);
6191 -- Call the api for processing sales order
6192 SO_SHIP_UPDATE
6193 ( p_api_version => p_api_version,
6194 p_commit => p_commit ,
6195 p_init_msg_list => p_init_msg_list,
6196 p_validation_level => p_validation_level,
6197 x_return_status => l_return_status,
6198 x_msg_count => x_msg_count,
6199 x_msg_data => x_msg_data ,
6200 p_repair_line_id => p_repair_line_id,
6201 p_past_num_of_days => p_past_num_of_days);
6202
6203 Debug('Return status from SO_SHIP_UPDATE '||l_return_status,l_mod_name,2);
6204
6205 --bug#8261344
6206 -- swai: bug 12547701 changed if statement
6207 If ((l_return_status = G_CSD_RET_STS_WARNING) AND
6208 (NVL(fnd_profile.value('CSD_LOGISTICS_PROGRAM_ERROR'), 'S') <> 'S')) Then
6209 Debug('SO_SHIP_UPDATE Warning message',l_mod_name,4);
6210 Debug('x_msg_count :'||x_msg_count,l_mod_name,2);
6211 Debug('x_msg_data :'||x_msg_data,l_mod_name,2);
6212
6213 -- swai: bug 12547701: do not pop the messages off the stack
6214 -- warnings should leave the messages on the stack for the
6215 -- calling procedure to handle.
6216 /*
6217 l_msg_data_warning := null;
6218 -- Concatenate the message from the message stack
6219 IF x_msg_count >= 1 then
6220 FOR i IN 1..x_msg_count LOOP
6221 l_msg_data_warning := l_msg_data_warning ||' : '||FND_MSG_PUB.Get(i,FND_API.G_FALSE) ;
6222 Debug('l_msg_data_warning loop :'||l_msg_data_warning,l_mod_name,2);
6223 END LOOP ;
6224 END IF ;
6225 Debug(l_msg_data_warning,l_mod_name,4);
6226 */
6227 ELSIF NOT(l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
6228 Debug('SO_SHIP_UPDATE failed ',l_mod_name,4);
6229 RAISE FND_API.G_EXC_ERROR;
6230 END IF;
6231
6232 End If;
6233
6234 -- Standard check of p_commit.
6235 IF FND_API.To_Boolean( p_commit ) THEN
6236 COMMIT WORK;
6237 END IF;
6238
6239 -- Standard call to get message count and IF count is get message info.
6240 FND_MSG_PUB.Count_And_Get
6241 (p_count => x_msg_count,
6242 p_data => x_msg_data );
6243
6244 --bug#8261344
6245 -- swai: bug 12547701 updated if statement
6246 If ((l_return_status = G_CSD_RET_STS_WARNING) AND
6247 (NVL(fnd_profile.value('CSD_LOGISTICS_PROGRAM_ERROR'), 'S') <> 'S'))THEN
6248 x_return_status := l_return_status;
6249 -- x_msg_data := l_msg_data_warning; -- swai: bug 12547701
6250 END IF;
6251
6252 EXCEPTION
6253 WHEN FND_API.G_EXC_ERROR THEN
6254 Debug('In FND_API.G_EXC_ERROR Exception ',l_mod_name,4);
6255 -- As we commit the processed records in the inner APIs
6256 -- so we rollback only if the p_commit= 'F'
6257 IF NOT(FND_API.To_Boolean( p_commit )) THEN
6258 ROLLBACK TO SHIP_UPDATE;
6259 END IF;
6260 x_return_status := FND_API.G_RET_STS_ERROR ;
6261 FND_MSG_PUB.Count_And_Get
6262 (p_count => x_msg_count,
6263 p_data => x_msg_data );
6264 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6265 Debug('In FND_API.G_EXC_UNEXPECTED_ERROR Exception',l_mod_name,4);
6266 IF ( l_error_level >= G_debug_level) THEN
6267 fnd_message.set_name('CSD','CSD_SQL_ERROR');
6268 fnd_message.set_token('SQLERRM',SQLERRM);
6269 fnd_message.set_token('SQLCODE',SQLCODE);
6270 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
6271 END If;
6272 -- As we commit the processed records in the inner APIs
6273 -- so we rollback only if the p_commit= 'F'
6274 IF NOT(FND_API.To_Boolean( p_commit )) THEN
6275 ROLLBACK TO SHIP_UPDATE;
6276 END IF;
6277 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6278 FND_MSG_PUB.Count_And_Get
6279 ( p_count => x_msg_count,
6280 p_data => x_msg_data );
6281 WHEN OTHERS THEN
6282 Debug('In OTHERS Exception',l_mod_name,4);
6283 IF ( l_error_level >= G_debug_level) THEN
6284 fnd_message.set_name('CSD','CSD_SQL_ERROR');
6285 fnd_message.set_token('SQLERRM',SQLERRM);
6286 fnd_message.set_token('SQLCODE',SQLCODE);
6287 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
6288 END If;
6289 -- As we commit the processed records in the inner APIs
6290 -- so we rollback only if the p_commit= 'F'
6291 IF NOT(FND_API.To_Boolean( p_commit )) THEN
6292 ROLLBACK TO SHIP_UPDATE;
6293 END IF;
6294 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6295 IF FND_MSG_PUB.Check_Msg_Level
6296 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6297 THEN
6298 FND_MSG_PUB.Add_Exc_Msg
6299 (G_PKG_NAME ,
6300 l_api_name );
6301 END IF;
6302 FND_MSG_PUB.Count_And_Get
6303 (p_count => x_msg_count,
6304 p_data => x_msg_data );
6305 END SHIP_UPDATE;
6306
6307 /*-------------------------------------------------------------------------------------*/
6308 /* Procedure name: SO_SHIP_UPDATE */
6309 /* Description : Procedure called from the Update api to update the depot tables */
6310 /* for the shipment against sales order */
6311 /* It also logs activities for the deliver txn lines */
6312 /* Called from : Called from SHIP_UPDATE API */
6313 /* STANDARD PARAMETERS */
6314 /* In Parameters : */
6315 /* p_api_version NUMBER Required Api Version number */
6316 /* p_init_msg_list VARCHAR2 Optional To Initialize message stack */
6317 /* p_commit VARCHAR2 Optional Commits in API */
6318 /* p_validation_level NUMBER Optional validation level */
6319 /* */
6320 /* Output Parameters: */
6321 /* x_return_status VARCHAR2 Return status of the API */
6322 /* x_msg_count NUMBER Number of messages in stack */
6323 /* x_msg_data VARCHAR2 Error Message from message stack */
6324 /* */
6325 /* NON-STANDARD PARAMETERS */
6326 /* In Parameters */
6327 /* p_repair_line_id NUMBER Optional Repair Order Line Id */
6328 /* Output Parm : */
6329 /* Change Hist : */
6330 /* 09/20/03 vlakaman Initial Creation. */
6331 /*-------------------------------------------------------------------------------------*/
6332
6333
6334 PROCEDURE SO_SHIP_UPDATE
6335 ( p_api_version IN NUMBER,
6336 p_commit IN VARCHAR2,
6337 p_init_msg_list IN VARCHAR2,
6338 p_validation_level IN NUMBER,
6339 x_return_status OUT NOCOPY VARCHAR2,
6340 x_msg_count OUT NOCOPY NUMBER,
6341 x_msg_data OUT NOCOPY VARCHAR2,
6342 p_repair_line_id IN NUMBER,
6343 p_past_num_of_days IN NUMBER DEFAULT NULL) ----bug#6753684, 6742512
6344 IS
6345
6346
6347 --Cursor split into to by Vijay 11/4/04 one without repair line and
6348 -- one with repair line.
6349 -- Cursor to get all the shipment lines
6350 Cursor SHIPMENT_LINES_ALL is
6351 select
6352 ---changed to fix 3801614 , added dsn.serial_number if dd.serial_number is null
6353 nvl(dd.serial_number, dsn.fm_serial_number) shipped_serial_num,
6354 dd.lot_number lot_number,
6355 dd.revision revision,
6356 dd.subinventory subinv,
6357 dd.requested_quantity,
6358 dd.shipped_quantity,
6359 dd.delivery_detail_id,
6360 dd.requested_quantity_uom shipped_uom,
6361 dd.inventory_item_id ,
6362 dd.organization_id,
6363 dd.source_header_number order_number,
6364 dd.source_header_id sales_order_header,
6365 dd.locator_id,
6366 dd.released_status, --bug#14657082 --bug#15859195
6367 oel.line_number order_line_number,
6368 oel.actual_shipment_date date_shipped,
6369 oel.line_id, --Bug#6779806
6370 cra.repair_number,
6371 cra.repair_line_id,
6372 cra.unit_of_measure ro_uom,
6373 cra.inventory_item_id ro_item_id,
6374 ced.quantity_required estimate_quantity,
6375 cpt.source_serial_number prod_txn_serial_num,
6376 cpt.source_instance_id,
6377 cpt.product_transaction_id,
6378 cpt.action_code,
6379 wnd.name delivery_name,
6380 hao.name org_name
6381 from
6382 csd_product_transactions cpt,
6383 cs_estimate_details ced,
6384 csd_repairs cra,
6385 wsh_delivery_details dd ,
6386 wsh_serial_numbers dsn,--Added to fix 3801614
6387 --Changed to view from table, bug: 4341784
6388 wsh_delivery_assignments_v wda,
6389 wsh_new_deliveries wnd,
6390 oe_order_lines_all oel,
6391 hr_all_organization_units hao
6392 Where cpt.action_type in ('SHIP', 'SHIP_THIRD_PTY') -- Walk-in-issue will be changed to ship
6393 AND cpt.estimate_detail_id = ced.estimate_detail_id
6394 AND dd.delivery_detail_id = wda.delivery_detail_id
6395 AND dd.delivery_detail_id = dsn.delivery_detail_id(+) --Added to fix 3801614
6396 AND dd.organization_id = hao.organization_id
6397 AND wda.delivery_id = wnd.delivery_id
6398 AND cpt.repair_line_id = cra.repair_line_id
6399 AND ced.order_header_id = oel.header_id
6400 AND ced.order_line_id = oel.line_id ----bug#6753684, 6742512
6401 AND dd.source_header_id = ced.order_header_id ----bug#6753684, 6742512
6402 AND dd.source_line_id = ced.order_line_id ----bug#6753684, 6742512
6403 AND dd.source_header_id = oel.header_id ----bug#6753684, 6742512
6404 AND dd.source_line_id = oel.line_id
6405 AND dd.source_code = 'OE' -- 4423818
6406 AND dd.released_status in ('C','I','Y') --bug#14657082, 15859195
6407 AND ced.source_code = 'DR'
6408 AND not exists
6409 (select 'NOT EXIST'
6410 from csd_repair_history crh
6411 where crh.repair_line_id = cpt.repair_line_id
6412 and crh.paramn1 = dd.delivery_detail_id
6413 and event_code = 'PS')
6414 AND oel.line_id in ( Select line_id
6415 from oe_order_lines_all oel1
6416 start with oel1.line_id = ced.order_line_id
6417 connect by prior oel1.line_id = oel1.split_from_line_id
6418 and oel1.shipped_quantity is not null
6419 and oel1.header_id = oel.header_id);
6420
6421 /* Fixed bug#6753684, 6742512
6422 New cursor added for batch processing.This cursor takes two parameter
6423 p_from_date and p_to_date. These dates are compared with the creation date
6424 of repair order. Only repair order created during this period are considered
6425 for Depot Shipment Update to improve performance.
6426 */
6427 Cursor SHIPMENT_LINES_BY_DATE( p_from_Date Date, p_to_Date Date ) is
6428 select
6429 ---changed to fix 3801614 , added dsn.serial_number if dd.serial_number is null
6430 nvl(dd.serial_number, dsn.fm_serial_number) shipped_serial_num,
6431 dd.lot_number lot_number,
6432 dd.revision revision,
6433 dd.subinventory subinv,
6434 dd.requested_quantity,
6435 dd.shipped_quantity,
6436 dd.delivery_detail_id,
6437 dd.requested_quantity_uom shipped_uom,
6438 dd.inventory_item_id ,
6439 dd.organization_id,
6440 dd.source_header_number order_number,
6441 dd.source_header_id sales_order_header,
6442 dd.locator_id,
6443 dd.released_status, --bug#14657082 --bug#15859195
6444 oel.line_number order_line_number,
6445 oel.actual_shipment_date date_shipped,
6446 oel.line_id, --Bug#6779806
6447 cra.repair_number,
6448 cra.repair_line_id,
6449 cra.unit_of_measure ro_uom,
6450 cra.inventory_item_id ro_item_id,
6451 ced.quantity_required estimate_quantity,
6452 cpt.source_serial_number prod_txn_serial_num,
6453 cpt.source_instance_id,
6454 cpt.product_transaction_id,
6455 cpt.action_code,
6456 wnd.name delivery_name,
6457 hao.name org_name
6458 from
6459 csd_product_transactions cpt,
6460 cs_estimate_details ced,
6461 csd_repairs cra,
6462 wsh_delivery_details dd ,
6463 wsh_serial_numbers dsn,--Added to fix 3801614
6464 --Changed to view from table, bug: 4341784
6465 wsh_delivery_assignments_v wda,
6466 wsh_new_deliveries wnd,
6467 oe_order_lines_all oel,
6468 hr_all_organization_units hao
6469 Where cra.creation_date between p_from_date and p_to_date
6470 AND cpt.action_type in ('SHIP', 'SHIP_THIRD_PTY') -- Walk-in-issue will be changed to ship
6471 AND cpt.estimate_detail_id = ced.estimate_detail_id
6472 AND dd.delivery_detail_id = wda.delivery_detail_id
6473 AND dd.delivery_detail_id = dsn.delivery_detail_id(+) --Added to fix 3801614
6474 AND dd.organization_id = hao.organization_id
6475 AND wda.delivery_id = wnd.delivery_id
6476 AND cpt.repair_line_id = cra.repair_line_id
6477 AND ced.order_header_id = oel.header_id
6478 AND ced.order_line_id = oel.line_id ----bug#6753684, 6742512
6479 AND dd.source_header_id = ced.order_header_id ----bug#6753684, 6742512
6480 AND dd.source_line_id = ced.order_line_id ----bug#6753684, 6742512
6481 AND dd.source_header_id = oel.header_id ----bug#6753684, 6742512
6482 AND dd.source_line_id = oel.line_id
6483 AND dd.source_code = 'OE' -- 4423818
6484 AND dd.released_status in ('C','I','Y') --bug#14657082, --15859195
6485 AND ced.source_code = 'DR'
6486 AND not exists
6487 (select 'NOT EXIST'
6488 from csd_repair_history crh
6489 where crh.repair_line_id = cpt.repair_line_id
6490 and crh.paramn1 = dd.delivery_detail_id
6491 and event_code = 'PS')
6492 AND oel.line_id in ( Select line_id
6493 from oe_order_lines_all oel1
6494 start with oel1.line_id = ced.order_line_id
6495 connect by prior oel1.line_id = oel1.split_from_line_id
6496 and oel1.shipped_quantity is not null
6497 and oel1.header_id = oel.header_id);
6498
6499
6500 -- recrd type var to get the column values into
6501 I SHIP_LINES_Rec_Type ;
6502 -- Cursor to get all the shipment lines for the
6503 -- specific repair line id
6504 -- Changed by Vijay to remove OR condition on repair line if
6505 -- bug fix 3162163
6506
6507 -- 12.1 FP bug#7551078, subhat.
6508 -- need to pick up only those ship lines which have source type as OE.
6509 -- There can be multiple delivery lines for the same sales order or
6510 -- the source_line_id in wsh_delivery_details can be same for OKE ship lines and
6511 -- OE ship lines.
6512 Cursor SHIPMENT_LINES ( p_repair_line_id in number) is
6513 select
6514 ---changed to fix 3801614 , added dsn.serial_number if dd.serial_number is null
6515 nvl(dd.serial_number, dsn.fm_serial_number) shipped_serial_num,
6516 dd.lot_number lot_number,
6517 dd.revision revision,
6518 dd.subinventory subinv,
6519 dd.requested_quantity,
6520 dd.shipped_quantity,
6521 dd.delivery_detail_id,
6522 dd.requested_quantity_uom shipped_uom,
6523 dd.inventory_item_id ,
6524 dd.organization_id,
6525 dd.source_header_number order_number,
6526 dd.source_header_id sales_order_header,
6527 dd.locator_id,
6528 dd.released_status, --bug#14657082 --15859195
6529 oel.line_number order_line_number,
6530 oel.actual_shipment_date date_shipped,
6531 oel.line_id, --Bug#6779806
6532 cra.repair_number,
6533 cra.repair_line_id,
6534 cra.unit_of_measure ro_uom,
6535 cra.inventory_item_id ro_item_id,
6536 ced.quantity_required estimate_quantity,
6537 cpt.source_serial_number prod_txn_serial_num,
6538 cpt.source_instance_id,
6539 cpt.product_transaction_id,
6540 cpt.action_code,
6541 wnd.name delivery_name,
6542 hao.name org_name
6543 from
6544 csd_product_transactions cpt,
6545 cs_estimate_details ced,
6546 csd_repairs cra,
6547 wsh_delivery_details dd ,
6548 wsh_serial_numbers dsn,--Added to fix 3801614
6549 --Changed to view from table, bug: 4341784
6550 wsh_delivery_assignments_v wda,
6551 wsh_new_deliveries wnd,
6552 oe_order_lines_all oel,
6553 hr_all_organization_units hao
6554 Where cpt.action_type in ('SHIP', 'SHIP_THIRD_PTY') -- Walk-in-issue will be changed to ship
6555 AND cpt.estimate_detail_id = ced.estimate_detail_id
6556 AND dd.delivery_detail_id = wda.delivery_detail_id
6557 AND dd.delivery_detail_id = dsn.delivery_detail_id(+) --Added to fix 3801614
6558 AND dd.organization_id = hao.organization_id
6559 AND wda.delivery_id = wnd.delivery_id
6560 AND cpt.repair_line_id = cra.repair_line_id
6561 AND ced.order_header_id = oel.header_id
6562 AND dd.source_line_id = oel.line_id
6563 AND dd.released_status in ('C','I', 'Y') --bug#14657082 --bug#15859195
6564 AND ced.source_code = 'DR'
6565 AND dd.source_code = 'OE' -- 12.1 FP bug#7551078, subhat
6566 AND not exists
6567 (select 'NOT EXIST'
6568 from csd_repair_history crh
6569 where crh.repair_line_id = cpt.repair_line_id
6570 and crh.paramn1 = dd.delivery_detail_id
6571 and event_code = 'PS')
6572 AND cpt.repair_line_id = p_repair_line_id
6573 AND oel.line_id in ( Select line_id
6574 from oe_order_lines_all oel1
6575 start with oel1.line_id = ced.order_line_id
6576 connect by prior oel1.line_id = oel1.split_from_line_id
6577 and oel1.shipped_quantity is not null
6578 and oel1.header_id = oel.header_id);
6579 -- There is a concern for performance as I am using connect by clause
6580 -- Need to check with the performance team if there is a workaround
6581 -- Otherwise the logic has to be changed
6582
6583 --- cursor for Cancelled orders...
6584 CURSOR Cur_Cancelled_repair_lines IS
6585 SELECT cra.REPAIR_LINE_ID
6586 FROM csd_repairs cra,
6587 cs_estimate_details ced,
6588 csd_product_transactions cpt
6589 WHERE cpt.action_type in ('SHIP', 'SHIP_THIRD_PTY')
6590 AND cpt.prod_txn_status in ( 'BOOKED', 'SUBMITTED')
6591 AND ced.order_header_id is not null
6592 AND ced.source_code = 'DR'
6593 AND ced.estimate_detail_id = cpt.estimate_detail_id
6594 AND cra.repair_line_id = cpt.repair_line_id;
6595
6596 --Bug#6779806
6597 CURSOR cur_get_instance_id(p_order_line_id number, p_inventory_item_id number)
6598 IS
6599 SELECT instance_id
6600 FROM csi_item_instances
6601 WHERE last_oe_order_line_id = p_order_line_id
6602 AND inventory_item_id = p_inventory_item_id;
6603
6604 --Bug#6779806
6605 l_enable_update_instance VARCHAR2(1);
6606
6607
6608 -- Standard variables
6609 l_api_name CONSTANT VARCHAR2(30) := 'SO_SHIP_UPDATE';
6610 l_api_version CONSTANT NUMBER := 1.0;
6611
6612 -- Variables used in the program
6613 l_serialized BOOLEAN;
6614 l_rep_hist_id NUMBER;
6615 l_result_ship_qty NUMBER;
6616 l_total_records NUMBER;
6617 l_dummy varchar2(30);
6618 l_commit_size NUMBER := 500;
6619 l_instance_id csi_item_instances.instance_id%type;
6620 l_ib_flag mtl_system_items.comms_nl_trackable_flag%type;
6621 l_srl_ctl_code mtl_system_items.serial_number_control_code%type;
6622
6623 -- activity record
6624 l_activity_rec activity_rec_type;
6625
6626 --bug#6753684, 6742512
6627 l_From_Date Date;
6628 l_TO_Date Date;
6629
6630 -- Variables used for FND Log
6631 l_error_level number := FND_LOG.LEVEL_ERROR;
6632 l_mod_name varchar2(2000) := 'csd.plsql.csd_update_programs_pvt.so_ship_update';
6633
6634 --bug#8261344
6635 l_skip_record BOOLEAN := FALSE;
6636 l_warning_return BOOLEAN := FALSE;
6637
6638 --bug#7572853
6639 l_flag NUMBER;
6640
6641 BEGIN
6642 -- Standard Start of API savepoint
6643 SAVEPOINT SO_SHIP_UPDATE;
6644
6645 -- Initialize API return status to success
6646 x_return_status := FND_API.G_RET_STS_SUCCESS;
6647 l_flag := 0; -- bug#7572853
6648
6649 -- Debug messages
6650 Debug('At the Beginning of ship Update ',l_mod_name,1);
6651 Debug('Repair Line Id ='||p_repair_line_id,l_mod_name,1);
6652
6653 -- Standard call to check for call compatibility.
6654 IF NOT FND_API.Compatible_API_Call (l_api_version,
6655 p_api_version,
6656 l_api_name ,
6657 G_PKG_NAME )
6658 THEN
6659 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6660 END IF;
6661
6662 -- Initialize message list if p_init_msg_list is set to TRUE.
6663 IF FND_API.to_Boolean( p_init_msg_list ) THEN
6664 FND_MSG_PUB.initialize;
6665 END IF;
6666
6667 -- Api body starts
6668
6669 -- Validate the repair line id
6670 -- bugfix 4423818 : We need to validate only if p_repair_line_id is NOT NULL
6671 IF(p_repair_line_id is NOT NULL ) THEN
6672 IF NOT(csd_process_util.validate_rep_line_id(p_repair_line_id)) THEN
6673 RAISE FND_API.G_EXC_ERROR;
6674 END IF;
6675 END IF;
6676
6677 --Bug#6779806
6678 --get the profile value:
6679 --CSD: Update Instance Number on Shipped Lines for Non-Serialized Installed Base Item
6680 l_enable_update_instance := nvl(FND_PROFILE.VALUE('CSD_UPDATE_INSTANCE_ID_FOR_NON_S_IB'), 'N');
6681
6682 -- Keep count of number of records
6683 l_total_records := 0;
6684
6685 --bug#8261344
6686 l_warning_return:= FALSE;
6687 l_skip_record := FALSE;
6688
6689
6690 -- Select all the delivery lines that are shipped and does not have
6691 -- activity logged against the repair order
6692 -- 1. Serialized
6693 -- BEFORE SHIPMENT
6694 -- Repair Order
6695 -- RO NUM RO Type Qty SN shipped Qty
6696 -- R1 RR 1 SN1
6697 -- Product Txn
6698 -- Prod Txn RO Num Est Line Est Qty SN Subinv shipped Qty
6699 -- P1 R1 C1 1 SN1
6700 --
6701 -- AFTER SHIPMENT and running the update program
6702 -- Repair Order
6703 -- RO NUM RO Type Qty SN shipped Qty
6704 -- R1 RR 1 SN9 1
6705 --
6706 -- Delivery Lines
6707 -- Del Line Ord Line Qty SN Subinv
6708 -- D1 L1 1 SN9 FGI
6709 --
6710 -- Product Txn
6711 -- Prod Txn RO Num Est Line Est Qty SN Subinv Shipped Qty
6712 -- P1 R1 C1 1 SN9 FGI 1
6713 --
6714 -- 2. Non-Serialized
6715 -- BEFORE SHIPMENT
6716 -- Repair Order
6717 -- RO NUM RO Type Qty SN shipped Qty
6718 -- R1 RR 3
6719 -- Product Txn
6720 -- Prod Txn RO Num Est Line Est Qty SN Subinv shipped Qty
6721 -- P1 R1 C1 3
6722 -- AFTER SHIPMENT and running the update program
6723 -- Repair Order
6724 -- RO NUM RO Type Qty SN shipped Qty
6725 -- R1 RR 3 3
6726 --
6727 -- Delivery Lines
6728 -- Del Line Ord Line Qty SN Subinv
6729 -- D1 L1 1 FGI
6730 -- D2 L2 2 FGI
6731 -- Product Txn
6732 -- Prod Txn RO Num Est Line Est Qty SN Subinv Shipped Qty
6733 -- P1 R1 C1 3 FGI 3
6734 --
6735 /* For loop changed to loop to open different
6736 cursors based on p_repair_line_id value.
6737 Bug fix 3162163, Vijay 11/4/04
6738 */
6739 --FOR I IN SHIPMENT_LINES (p_repair_line_id)
6740 IF(p_repair_line_Id is null) THEN
6741 If (p_past_num_of_days Is Null) Then
6742 OPEN SHIPMENT_LINES_ALL;
6743 Else
6744 l_From_Date := sysdate - (p_past_num_of_days +1 ) ;
6745 l_TO_Date := Sysdate + 1;
6746 OPEN SHIPMENT_LINES_BY_DATE(l_From_Date , l_To_Date); ----bug#6753684, 6742512
6747 End If;
6748 ELSE
6749 OPEN SHIPMENT_LINES(p_repair_line_id);
6750 END IF;
6751
6752 LOOP
6753 BEGIN
6754
6755 IF(p_repair_line_Id is null) THEN
6756 If (p_past_num_of_days Is Null) Then
6757 FETCH SHIPMENT_LINES_ALL INTO I;
6758 EXIT WHEN SHIPMENT_LINES_ALL%NOTFOUND;
6759 else
6760 FETCH SHIPMENT_LINES_BY_DATE INTO I; ----bug#6753684, 6742512
6761 EXIT WHEN SHIPMENT_LINES_BY_DATE%NOTFOUND;
6762 end if;
6763 ELSE
6764 FETCH SHIPMENT_LINES INTO I;
6765 EXIT WHEN SHIPMENT_LINES%NOTFOUND;
6766 END IF;
6767
6768
6769 -- savepoint
6770 SAVEPOINT SHIPMENT_LINES;
6771
6772 --update product transaction status to 'pick released' only if line in released status
6773 --bug#14657082 --15859195
6774 If ((I.released_status = 'Y') and (I.date_shipped is null)) then
6775 -- Updating the product txn with the status
6776 -- if the line qty is fully rcvd
6777 update csd_product_transactions
6778 set prod_txn_status = 'RELEASED',
6779 release_sales_order_flag = 'Y',
6780 object_version_number = object_version_number+1,
6781 last_update_date = sysdate,
6782 last_updated_by = fnd_global.user_id,
6783 last_update_login = fnd_global.login_id
6784 where product_transaction_id = I.product_transaction_id ;
6785 End if;
6786 --bug#14657082 --15859195
6787
6788
6789 -- bug#7285024
6790 -- There could be data discrepancy between OM status and Shipping status in which
6791 -- OM thinks the line is shipped but Shipping has not shipped yet.
6792 -- Only process the prod txn line if shipped date from shiping tables is not null.
6793 -- cursor queries have not been changed to incorporate this check due to performance
6794 -- issues with checking not null.
6795 -- Date shipped is checked instead of Shipping status since we are not sure exactly
6796 -- which statuses map to a shipped line, but all shipped items must have a ship date.
6797 -- Note: the date_shipped is required column in the depot history table.
6798 If (I.date_shipped is not null) then
6799
6800 Debug('Order number ='||I.order_number,l_mod_name,1);
6801 Debug('Repair number ='||I.repair_number,l_mod_name,1);
6802 Debug('Shipped quantity ='||TO_CHAR(I.shipped_quantity),l_mod_name,1);
6803 Debug('Inventory item id ='||TO_CHAR(I.inventory_item_id),l_mod_name,1);
6804 Debug('Organization id ='||TO_CHAR(I.Organization_id),l_mod_name,1);
6805
6806 Begin
6807 select serial_number_control_code,
6808 comms_nl_trackable_flag
6809 into l_srl_ctl_code,
6810 l_ib_flag
6811 from mtl_system_items
6812 where inventory_item_id = i.inventory_item_id
6813 and organization_id = i.organization_id;
6814 Exception
6815 When no_data_found then
6816 IF ( l_error_level >= G_debug_level) THEN
6817 fnd_message.set_name('CSD','CSD_INVALID_INVENTORY_ITEM');
6818 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
6819 ELSE
6820 fnd_message.set_name('CSD','CSD_INVALID_INVENTORY_ITEM');
6821 fnd_msg_pub.add;
6822 END IF;
6823 RAISE FND_API.G_EXC_ERROR;
6824 End;
6825
6826 IF l_srl_ctl_code in (2,5,6) THEN
6827 Debug('Item is Serialized',l_mod_name,1);
6828 l_serialized := TRUE;
6829 ELSE
6830 Debug('Item is Non-Serialized',l_mod_name,1);
6831 l_serialized := FALSE;
6832 END IF;
6833
6834 IF l_serialized AND
6835 I.ro_item_id = I.inventory_item_id AND
6836 I.prod_txn_serial_num <> I.shipped_serial_num THEN
6837
6838 -- Initialize the activity rec
6839 l_activity_rec := INIT_ACTIVITY_REC ;
6840
6841 -- Assign the values for activity record
6842 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
6843 l_activity_rec.REPAIR_LINE_ID := I.repair_line_id;
6844 l_activity_rec.EVENT_CODE := 'SSC';
6845 l_activity_rec.ACTION_CODE := 0;
6846 l_activity_rec.EVENT_DATE := I.date_shipped;
6847 l_activity_rec.QUANTITY := null;
6848 l_activity_rec.PARAMN1 := i.delivery_detail_id;
6849 l_activity_rec.PARAMN2 := i.order_line_number;
6850 l_activity_rec.PARAMC2 := i.delivery_name;
6851 l_activity_rec.PARAMC3 := i.prod_txn_serial_num;
6852 l_activity_rec.PARAMC4 := i.shipped_serial_num;
6853 l_activity_rec.OBJECT_VERSION_NUMBER := null;
6854
6855 -- Debug Messages
6856 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
6857
6858 -- Calling LOG_ACTIVITY for logging activity
6859 -- if serial number on product txn does not match
6860 -- with the shipped serial number
6861 LOG_ACTIVITY
6862 ( p_api_version => p_api_version,
6863 p_commit => p_commit,
6864 p_init_msg_list => p_init_msg_list,
6865 p_validation_level => p_validation_level,
6866 x_return_status => x_return_status,
6867 x_msg_count => x_msg_count,
6868 x_msg_data => x_msg_data,
6869 p_activity_rec => l_activity_rec );
6870
6871 -- Debug Messages
6872 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
6873 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
6874 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
6875 RAISE FND_API.G_EXC_ERROR;
6876 END IF;
6877
6878 END IF; -- end of serial number mismatch
6879
6880 -- Only if the item on the RO is same as the one on
6881 -- product txn, then call the convert API
6882 IF I.ro_item_id = I.inventory_item_id THEN
6883
6884 -- Debug messages
6885 Debug('Calling CONVERT_TO_RO_uom ',l_mod_name,2);
6886
6887 -- Converting the shipped qty to RO UOM
6888 CONVERT_TO_RO_UOM
6889 ( x_return_status => x_return_status
6890 ,p_to_uom_code => i.ro_uom
6891 ,p_item_id => i.inventory_item_id
6892 ,p_from_uom => NULL
6893 ,p_from_uom_code => i.shipped_uom
6894 ,p_from_quantity => i.shipped_quantity
6895 ,x_result_quantity => l_result_ship_qty);
6896
6897 -- Debug messages
6898 Debug('Return Status from CONVERT_TO_RO_uom :'||x_return_status,l_mod_name,2);
6899 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
6900 Debug('CONVERT_TO_RO_uom api failed ',l_mod_name,4);
6901 RAISE FND_API.G_EXC_ERROR;
6902 END IF;
6903 ELSE
6904 l_result_ship_qty := I.shipped_quantity;
6905 END IF;
6906
6907 -- Update repair orders only for the following action codes
6908 IF I.action_code in ( 'CUST_PROD','EXCHANGE','REPLACEMENT') then
6909 -- Updating the repair order with qty
6910 update csd_repairs
6911 set quantity_shipped = nvl(quantity_shipped,0)+l_result_ship_qty,
6912 object_version_number = object_version_number+1,
6913 last_update_date = sysdate,
6914 last_updated_by = fnd_global.user_id,
6915 last_update_login = fnd_global.login_id
6916 where repair_line_id = I.repair_line_id;
6917 IF SQL%NOTFOUND THEN
6918 IF ( l_error_level >= G_debug_level) THEN
6919 fnd_message.set_name('CSD','CSD_RO_UPD_FAILED');
6920 fnd_message.set_token('REPAIR_LINE_ID',I.repair_line_id);
6921 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
6922 ELSE
6923 fnd_message.set_name('CSD','CSD_RO_UPD_FAILED');
6924 fnd_message.set_token('REPAIR_LINE_ID',I.repair_line_id);
6925 fnd_msg_pub.add;
6926 END IF;
6927 RAISE FND_API.G_EXC_ERROR;
6928 END IF;
6929 END IF;
6930
6931
6932 IF l_serialized and
6933 nvl(l_ib_flag,'N') = 'Y' THEN
6934 Begin
6935 Select instance_id
6936 into l_instance_id
6937 from csi_item_instances
6938 where inventory_item_id = I.inventory_item_id
6939 and serial_number = I.shipped_serial_num; --bug#8261344
6940 --and serial_number = 'SWTEST'; --swai: bug 12547701 comment this to debug IB instance missing
6941 Exception
6942 When No_Data_Found then
6943 /*Fixed for bug#5563369
6944 Correct message name CSD_INSTANCE_MISSING is used instead of
6945 CSD_INV_INSTANCE_ID.
6946 */
6947 IF ( l_error_level >= G_debug_level) THEN
6948 fnd_message.set_name('CSD','CSD_INSTANCE_MISSING');
6949 fnd_message.set_token('SERIAL_NUM',I.shipped_serial_num);
6950 fnd_msg_pub.add;
6951 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
6952 fnd_file.put_line(fnd_file.log, fnd_message.get);
6953 ELSE
6954 fnd_message.set_name('CSD','CSD_INSTANCE_MISSING');
6955 fnd_message.set_token('SERIAL_NUM',I.shipped_serial_num);
6956 fnd_msg_pub.add;
6957 fnd_file.put_line(fnd_file.log, fnd_message.get);
6958 /*Fixed for bug#5563369
6959 Correct message name CSD_INSTANCE_MISSING is used instead of
6960 CSD_INV_INSTANCE_ID.
6961 */
6962 END IF;
6963
6964 --bug#8261344
6965 -- swai: bug 12547701 changed if statement
6966 IF(NVL(fnd_profile.value('CSD_LOGISTICS_PROGRAM_ERROR'), 'S') = 'S') THEN
6967 RAISE FND_API.G_EXC_ERROR;
6968 else
6969 -- RAISE FND_API.G_EXC_ERROR;
6970 l_skip_record := TRUE;
6971 l_warning_return := TRUE;
6972 end if;
6973 Debug(' Could not find any IB instance for the Serial Num ='||I.shipped_serial_num, l_mod_name,1);
6974
6975 When OTHERS then
6976 IF ( l_error_level >= G_debug_level) THEN
6977 fnd_message.set_name('CSD','CSD_INSTANCE_MISSING');
6978 fnd_message.set_token('SERIAL_NUM',I.shipped_serial_num);
6979 fnd_msg_pub.add;
6980 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
6981 fnd_file.put_line(fnd_file.log, fnd_message.get);
6982 ELSE
6983 fnd_message.set_name('CSD','CSD_INSTANCE_MISSING');
6984 fnd_message.set_token('SERIAL_NUM',I.shipped_serial_num);
6985 fnd_msg_pub.add;
6986 fnd_file.put_line(fnd_file.log, fnd_message.get);
6987 END IF;
6988 RAISE FND_API.G_EXC_ERROR;
6989 End;
6990
6991 --bug#6779806
6992 ELSIF (nvl(l_ib_flag,'N') = 'Y') THEN
6993 IF (l_enable_update_instance ='Y') THEN
6994 Open cur_get_instance_id(I.line_id,I.inventory_item_id);
6995 Fetch cur_get_instance_id into l_instance_id;
6996 Close cur_get_instance_id;
6997 else
6998 l_instance_id := I.source_instance_id;
6999 end if;
7000 Else
7001 l_instance_id := I.source_instance_id;
7002 End If;
7003
7004
7005 Debug('serial number before if skip reord ='||I.shipped_serial_num, l_mod_name,1);
7006
7007 If NOT(l_skip_record) Then --bug#8261344
7008
7009 -- Updating the product txn with qty,subinventory,lot number
7010 -- locator id
7011 update csd_product_transactions
7012 set sub_inventory = i.subinv,
7013 lot_number = i.lot_number,
7014 quantity_shipped = nvl(quantity_shipped,0)+I.shipped_quantity,
7015 locator_id = i.locator_id,
7016 source_serial_number = i.shipped_serial_num,
7017 source_instance_id = l_instance_id,
7018 object_version_number = object_version_number+1,
7019 last_update_date = sysdate,
7020 last_updated_by = fnd_global.user_id,
7021 last_update_login = fnd_global.login_id
7022 where product_transaction_id = i.product_transaction_id ;
7023 IF SQL%NOTFOUND THEN
7024 IF ( l_error_level >= G_debug_level) THEN
7025 fnd_message.set_name('CSD','CSD_PROD_TXN_UPD_FAILED');
7026 fnd_message.set_token('PROD_TXN_ID',I.product_transaction_id);
7027 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
7028 ELSE
7029 fnd_message.set_name('CSD','CSD_PROD_TXN_UPD_FAILED');
7030 fnd_message.set_token('PROD_TXN_ID',I.product_transaction_id);
7031 fnd_msg_pub.add;
7032 END IF;
7033 RAISE FND_API.G_EXC_ERROR;
7034 END IF;
7035
7036 -- Updating the product txn with the status
7037 -- if the line qty is fully rcvd
7038 update csd_product_transactions
7039 set prod_txn_status = 'SHIPPED',
7040 object_version_number = object_version_number+1,
7041 last_update_date = sysdate,
7042 last_updated_by = fnd_global.user_id,
7043 last_update_login = fnd_global.login_id
7044 where nvl(quantity_shipped,0) = I.estimate_quantity
7045 and product_transaction_id = i.product_transaction_id ;
7046
7047 --bug#7572853 begin
7048 l_flag := 0;
7049 --The following procedure is user hooks for the customer.
7050 --the parameter l_flag always return 0 on the default package CSD_UPDATE_SHIP_PROGRAM_CUHK
7051 --please see package spec and body CSD_UPDATE_SHIP_PROGRAM_CUHK for the definition
7052 CSD_UPDATE_SHIP_PROGRAM_CUHK.POST_UPDATE_PROD_TXN(
7053 p_repair_line_id => I.repair_line_id,
7054 p_product_transaction_id => i.product_transaction_id,
7055 p_instance_id => l_instance_id,
7056 p_comms_nl_trackable_flag => l_ib_flag,
7057 p_action_code => I.action_code,
7058 x_flag => l_flag,
7059 x_return_status => x_return_status,
7060 x_msg_count => x_msg_count,
7061 x_msg_data => x_msg_data
7062 );
7063 -- Debug Messages
7064 Debug('after call POST_UPDATE_PROD_TXN l_flag '||l_flag,l_mod_name,2);
7065 Debug('Return Status from CSD_UPDATE_SHIP_PROGRAM_CUHK:'||x_return_status,l_mod_name,2);
7066 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
7067 Debug('POST_UPDATE_PROD_TXN api failed ',l_mod_name,4);
7068 RAISE FND_API.G_EXC_ERROR;
7069 END IF;
7070
7071 Debug('l_flag '||l_flag,l_mod_name,2);
7072
7073 If (l_flag = 0) then
7074 --bug#7572853 end
7075
7076 --Bug#6779806
7077 IF (NOT(l_serialized) and (nvl(l_ib_flag,'N') = 'Y')
7078 and (l_instance_id is null)
7079 and (l_enable_update_instance ='Y')) then
7080 --do nothing
7081 --due to csi_item_instances has not update the instance id yet
7082 --It is update by the concurent program.
7083 --if there is not instance id yet, we don't want to
7084 --update the history table
7085 null;
7086 ELSE
7087
7088 -- Initialize the activity rec
7089 l_activity_rec := INIT_ACTIVITY_REC ;
7090
7091 -- Assign the values for activity record
7092 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
7093 l_activity_rec.REPAIR_LINE_ID := I.repair_line_id;
7094 l_activity_rec.EVENT_CODE := 'PS';
7095 l_activity_rec.ACTION_CODE := 0;
7096 l_activity_rec.EVENT_DATE := I.date_shipped;
7097 l_activity_rec.QUANTITY := l_result_ship_qty;
7098 l_activity_rec.PARAMN1 := i.delivery_detail_id;
7099 l_activity_rec.PARAMN2 := i.order_line_number;
7100 l_activity_rec.PARAMN3 := i.organization_id;
7101 l_activity_rec.PARAMC2 := i.delivery_name;
7102 l_activity_rec.PARAMC3 := i.org_name;
7103 l_activity_rec.PARAMC4 := i.subinv;
7104 l_activity_rec.OBJECT_VERSION_NUMBER := null;
7105
7106 -- Debug Messages
7107 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
7108
7109 -- Calling LOG_ACTIVITY for logging activity
7110 -- shipped delivery lines
7111 LOG_ACTIVITY
7112 ( p_api_version => p_api_version,
7113 p_commit => p_commit,
7114 p_init_msg_list => p_init_msg_list,
7115 p_validation_level => p_validation_level,
7116 x_return_status => x_return_status,
7117 x_msg_count => x_msg_count,
7118 x_msg_data => x_msg_data,
7119 p_activity_rec => l_activity_rec );
7120
7121 -- Debug Messages
7122 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
7123 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
7124 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
7125 RAISE FND_API.G_EXC_ERROR;
7126 END IF;
7127
7128 END IF;
7129 end if; --end if (l_flag = ) Bug 7572853
7130
7131 End if; --end if NOT(l_skip_record) --bug#8261344
7132
7133 End if; --end If (I.date_shipped is not null) --bug#7285024
7134
7135 EXCEPTION
7136 WHEN FND_API.G_EXC_ERROR THEN
7137 Debug('In FND_API.G_EXC_ERROR EXCEPTION',l_mod_name,4);
7138 ROLLBACK TO SHIPMENT_LINES;
7139 -- In case of error, exit the loop. Commit the processed records
7140 -- and rollback the error record
7141 --RAISE FND_API.G_EXC_ERROR;
7142 x_return_status := FND_API.G_RET_STS_ERROR ;
7143 EXIT;
7144 END;
7145 -- Commit for every 500 records
7146 -- one should COMMIT less frequently within a PL/SQL loop to
7147 -- prevent ORA-1555 (Snapshot too old) errors
7148
7149 --bug#8261344
7150 If NOT(l_skip_record) Then
7151 l_total_records := l_total_records + 1;
7152 end if;
7153 IF mod(l_total_records, l_commit_size) = 0 THEN -- Commit every 500 records
7154 IF FND_API.To_Boolean( p_commit ) THEN
7155 COMMIT WORK;
7156 END IF;
7157 END IF;
7158
7159 --bug#8261344
7160 l_skip_record := FALSE;
7161
7162 END LOOP;
7163
7164 IF(SHIPMENT_LINES_ALL%ISOPEN ) THEN
7165 CLOSE SHIPMENT_LINES_ALL;
7166 END IF;
7167 IF(SHIPMENT_LINES%ISOPEN ) THEN
7168 CLOSE SHIPMENT_LINES;
7169 END IF;
7170 IF(SHIPMENT_LINES_BY_DATE%ISOPEN ) THEN
7171 CLOSE SHIPMENT_LINES_BY_DATE;
7172 END IF;
7173
7174 ------------ process cancelled orders.
7175 Debug('processing cancelled orders in SO_SHIP_UPDATE',l_mod_name,1);
7176 if(p_repair_line_id is not null) then
7177 Debug('processing repairline['||p_repair_line_id||']',l_mod_name,1);
7178 Check_for_Cancelled_order(p_repair_line_id);
7179 else
7180 FOR Repln_Rec in Cur_Cancelled_repair_lines
7181 LOOP
7182 Debug('processing repairline['||repln_rec.repair_line_id||']',l_mod_name,1);
7183 check_for_cancelled_order(Repln_rec.Repair_line_id);
7184 END LOOP;
7185 End if;
7186 Debug('At the end of processing cancelled orders in SO_SHIP_UPDATE',l_mod_name,1);
7187 -----------------------
7188
7189 -- Log seeded messages for the number of processed records
7190 fnd_message.set_name('CSD','CSD_DRC_SHIP_TOTAL_REC_PROC');
7191 fnd_message.set_token('TOT_REC',to_char(l_total_records));
7192 FND_MSG_PUB.ADD;
7193
7194 -- Debug messages
7195 Debug(fnd_message.get,l_mod_name,1);
7196
7197 -- Log messages in the concurrent log and output file
7198 fnd_file.put_line(fnd_file.log,fnd_message.get);
7199 fnd_file.put_line(fnd_file.output,fnd_message.get);
7200
7201 -- Standard check of p_commit.
7202 IF FND_API.To_Boolean( p_commit ) THEN
7203 COMMIT WORK;
7204 END IF;
7205
7206 --bug#8261344
7207 If (l_warning_return) THEN
7208 x_return_status := G_CSD_RET_STS_WARNING;
7209 End if;
7210
7211 -- Standard call to get message count and IF count is get message info.
7212 FND_MSG_PUB.Count_And_Get
7213 (p_count => x_msg_count,
7214 p_data => x_msg_data);
7215
7216 EXCEPTION
7217 WHEN FND_API.G_EXC_ERROR THEN
7218 Debug('FND_API.G_EXC_ERROR Exception',l_mod_name,4);
7219 ROLLBACK TO SO_SHIP_UPDATE;
7220 x_return_status := FND_API.G_RET_STS_ERROR ;
7221 FND_MSG_PUB.Count_And_Get
7222 (p_count => x_msg_count,
7223 p_data => x_msg_data );
7224 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7225 Debug('FND_API.G_EXC_UNEXPECTED_ERROR Exception',l_mod_name,4);
7226 ROLLBACK TO SO_SHIP_UPDATE;
7227 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
7228 FND_MSG_PUB.Count_And_Get
7229 ( p_count => x_msg_count,
7230 p_data => x_msg_data );
7231 WHEN OTHERS THEN
7232 Debug('OTHERS Exception',l_mod_name,4);
7233 ROLLBACK TO SO_SHIP_UPDATE;
7234 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
7235 IF FND_MSG_PUB.Check_Msg_Level
7236 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
7237 THEN
7238 FND_MSG_PUB.Add_Exc_Msg
7239 (G_PKG_NAME ,
7240 l_api_name );
7241 END IF;
7242 FND_MSG_PUB.Count_And_Get
7243 (p_count => x_msg_count,
7244 p_data => x_msg_data );
7245 END SO_SHIP_UPDATE;
7246
7247
7248 /*-------------------------------------------------------------------------------------*/
7249 /* Procedure name: IO_SHIP_UPDATE */
7250 /* Description : Procedure called from the Update api to update the depot tables */
7251 /* for the shipment against Internal sales order */
7252 /* It also logs activities for the deliver txn lines */
7253 /* Called from : Called from SHIP_UPDATE API */
7254 /* STANDARD PARAMETERS */
7255 /* In Parameters : */
7256 /* p_api_version NUMBER Required Api Version number */
7257 /* p_init_msg_list VARCHAR2 Optional To Initialize message stack */
7258 /* p_commit VARCHAR2 Optional Commits in API */
7259 /* p_validation_level NUMBER Optional validation level */
7260 /* */
7261 /* Output Parameters: */
7262 /* x_return_status VARCHAR2 Return status of the API */
7263 /* x_msg_count NUMBER Number of messages in stack */
7264 /* x_msg_data VARCHAR2 Error Message from message stack */
7265 /* */
7266 /* NON-STANDARD PARAMETERS */
7267 /* In Parameters */
7268 /* p_order_header_id NUMBER Optional Interal sales order Id */
7269 /* Output Parm : */
7270 /* Change Hist : */
7271 /* 09/20/03 vlakaman Initial Creation. */
7272 /*-------------------------------------------------------------------------------------*/
7273
7274 PROCEDURE IO_SHIP_UPDATE
7275 ( p_api_version IN NUMBER,
7276 p_commit IN VARCHAR2,
7277 p_init_msg_list IN VARCHAR2,
7278 p_validation_level IN NUMBER,
7279 x_return_status OUT NOCOPY VARCHAR2,
7280 x_msg_count OUT NOCOPY NUMBER,
7281 x_msg_data OUT NOCOPY VARCHAR2,
7282 p_order_header_id IN NUMBER
7283 ) IS
7284
7285 -- Cursor to get all the order lines for a
7286 -- specific order header id
7287 --Chnaged the cursor to remove the OR condition on the repair line id.
7288 --Vijay 11/4/04
7289 --saupadhy 04/15/05 : BUg# 4279958 : Problem: When partial Shipping is done for both
7290 -- move_in and Move_Out lines,only first shiplines information is updated on logistics lines
7291 -- subsequest so lines information is not updated.
7292 -- Cause: Cursors Delivery_Lines and Delivery_lines_all have hard join with mtl_trx_lines table.
7293 -- Records in this table are created only when so line is shipped. In partial shipping scenario, if
7294 -- second line is not shipped at the time update logistics program is run then, it will never be
7295 -- created after update logistics program is run for the first ship line.
7296 -- Solution: Hard Join with Mtl_Trx_line is replaced with outer join.
7297 CURSOR DELIVERY_LINES (p_ord_header_id in number) IS
7298 Select oel.header_id,
7299 oel.line_id,
7300 oel.ordered_quantity,
7301 oel.source_document_id req_header_id,
7302 oel.source_document_line_id req_line_id,
7303 oel.orig_sys_document_ref req_number,
7304 oel.inventory_item_id,
7305 oel.actual_shipment_date shipment_date,
7306 dd.delivery_detail_id,
7307 dd.shipped_quantity,
7308 ---changed to fix 3801614 , added dsn.serial_number if dd.serial_number is null
7309 nvl(dd.serial_number,dsn.fm_serial_number) del_line_serial_num,
7310 --dd.serial_number del_line_serial_num,
7311 dd.lot_number,
7312 dd.subinventory,
7313 dd.locator_id,
7314 dd.organization_id,
7315 dd.released_status,
7316 dd.requested_quantity,
7317 dd.source_header_number order_number,
7318 prl.source_organization_id,
7319 prl.source_subinventory,
7320 prl.destination_organization_id,
7321 prl.destination_subinventory,
7322 mtl.serial_number_control_code,
7323 mtl.lot_control_code,
7324 prh.segment1 requisition_number,
7325 hao.name source_org_name,
7326 hao1.name destination_org_name,
7327 trl.txn_source_id
7328 from oe_order_lines_all oel,
7329 wsh_delivery_details dd,
7330 wsh_serial_numbers dsn,--Added to fix 3801614
7331 po_requisition_lines_all prl,
7332 po_requisition_headers_all prh,
7333 mtl_system_items mtl,
7334 hr_all_organization_units hao,
7335 hr_all_organization_units hao1,
7336 mtl_txn_request_lines trl
7337 where oel.header_id = p_ord_header_id
7338 and oel.line_id = dd.source_line_id
7339 and oel.header_id = dd.source_header_id
7340 and prl.requisition_header_id = prh.requisition_header_id
7341 and hao.organization_id = dd.organization_id
7342 and hao1.organization_id = prl.destination_organization_id
7343 and oel.source_document_line_id = prl.requisition_line_id
7344 and oel.ship_from_org_id = mtl.organization_id
7345 and oel.inventory_item_id= mtl.inventory_item_id
7346 and dd.move_order_line_id = trl.line_id(+) -- Added to fix 4279958
7347 and dd.delivery_detail_id = dsn.delivery_detail_id(+) --Added to fix 3801614
7348 and exists (Select 'x'
7349 from csd_product_transactions cpt
7350 where cpt.order_header_id = oel.header_id
7351 and cpt.prod_txn_status in ('BOOKED','RELEASED'));
7352
7353 -- New Cursor for all delivery lines.
7354 CURSOR DELIVERY_LINES_ALL IS
7355 Select oel.header_id,
7356 oel.line_id,
7357 oel.ordered_quantity,
7358 oel.source_document_id req_header_id,
7359 oel.source_document_line_id req_line_id,
7360 oel.orig_sys_document_ref req_number,
7361 oel.inventory_item_id,
7362 oel.actual_shipment_date shipment_date,
7363 dd.delivery_detail_id,
7364 dd.shipped_quantity,
7365 ---changed to fix 3801614 , added dsn.serial_number if dd.serial_number is null
7366 nvl(dd.serial_number,dsn.fm_serial_number) del_line_serial_num,
7367 --dd.serial_number del_line_serial_num,
7368 dd.lot_number,
7369 dd.subinventory,
7370 dd.locator_id,
7371 dd.organization_id,
7372 dd.released_status,
7373 dd.requested_quantity,
7374 dd.source_header_number order_number,
7375 prl.source_organization_id,
7376 prl.source_subinventory,
7377 prl.destination_organization_id,
7378 prl.destination_subinventory,
7379 mtl.serial_number_control_code,
7380 mtl.lot_control_code,
7381 prh.segment1 requisition_number,
7382 hao.name source_org_name,
7383 hao1.name destination_org_name,
7384 trl.txn_source_id
7385 from oe_order_lines_all oel,
7386 wsh_delivery_details dd,
7387 wsh_serial_numbers dsn,--Added to fix 3801614
7388 po_requisition_lines_all prl,
7389 po_requisition_headers_all prh,
7390 mtl_system_items mtl,
7391 hr_all_organization_units hao,
7392 hr_all_organization_units hao1,
7393 mtl_txn_request_lines trl
7394 where oel.line_id = dd.source_line_id
7395 and oel.header_id = dd.source_header_id
7396 and prl.requisition_header_id = prh.requisition_header_id
7397 and hao.organization_id = dd.organization_id
7398 and hao1.organization_id = prl.destination_organization_id
7399 and oel.source_document_line_id = prl.requisition_line_id
7400 and oel.ship_from_org_id = mtl.organization_id
7401 and oel.inventory_item_id= mtl.inventory_item_id
7402 and dd.move_order_line_id = trl.line_id(+) -- Added to fix 4279958
7403 and dd.delivery_detail_id = dsn.delivery_detail_id(+) --Added to fix 3801614
7404 and exists (Select 'x'
7405 from csd_product_transactions cpt
7406 where cpt.order_header_id = oel.header_id
7407 and cpt.prod_txn_status in ('BOOKED','RELEASED'));
7408
7409
7410 --record tpye to hold delivery lines record selected from the cursor
7411 --above
7412 del IO_SHIP_LINES_Rec_Type;
7413
7414 -- Cursor that gets all unit txn
7415 -- for delivery detail id
7416 Cursor MTL_UNIT_TXN ( p_del_line_id in number, p_txn_src_id in number ) is
7417 select
7418 mut.subinventory_code,
7419 mut.locator_id,
7420 mut.serial_number,
7421 mtl.transaction_id
7422 from mtl_material_transactions mtl,
7423 mtl_unit_transactions mut
7424 where mtl.transaction_id = mut.transaction_id
7425 and mtl.transaction_source_type_id = 8 -- Internal Order
7426 and mtl.transaction_type_id in (50, 62,54,34)
7427 and mtl.picking_line_id = p_del_line_id
7428 and mtl.transaction_source_id = p_txn_src_id ;
7429
7430 -- Cursor that gets all unit txn
7431 -- for delivery detail id. If the item is lot controlled
7432 -- and serial controlled item then need to join
7433 -- with MTL_TRANSACTION_LOT_NUMBERS
7434 Cursor MTL_UNIT_LOT_TXN ( p_del_line_id in number,p_txn_src_id in number ) is
7435 select
7436 mut.subinventory_code,
7437 mut.locator_id,
7438 mut.serial_number,
7439 mtl.transaction_id
7440 from MTL_TRANSACTION_LOT_NUMBERS mln,
7441 mtl_unit_transactions mut,
7442 mtl_material_transactions mtl
7443 WHERE MLN.SERIAL_TRANSACTION_ID = mut.transaction_id
7444 and mln.transaction_id = mtl.transaction_id
7445 and mtl.transaction_source_type_id = 8 -- Internal Order
7446 and mtl.transaction_type_id in ( 50,62,54,34)
7447 and mtl.picking_line_id = p_del_line_id
7448 and mtl.transaction_source_id = p_txn_src_id ;
7449
7450 -- Standard variables
7451 l_api_name CONSTANT VARCHAR2(30) := 'IO_SHIP_UPDATE';
7452 l_api_version CONSTANT NUMBER := 1.0;
7453
7454 -- Variables used by the API
7455 l_rep_hist_id NUMBER;
7456 l_dummy varchar2(30);
7457 l_total_qty number;
7458 l_total_del_qty number;
7459 l_serialized_flag boolean;
7460 l_log_activity boolean;
7461 l_prod_txn_exists boolean;
7462 l_serial_num mtl_serial_numbers.serial_number%type;
7463 l_lot_num mtl_lot_numbers.lot_number%type;
7464 l_rep_line_id number;
7465 l_remaining_qty number;
7466 l_shipped_qty number;
7467 l_pt_line_qty number;
7468 l_pt_shipped_qty number;
7469 l_total_shipped_qty number;
7470 l_prod_txn_shipped_qty number;
7471 l_action_type csd_product_transactions.action_type%type;
7472 l_action_code csd_product_transactions.action_code%type;
7473 l_prod_txn_id number := NULL;
7474 l_prod_txn_status csd_product_transactions.prod_txn_status%type ;
7475 l_release_so_flag csd_product_transactions.release_sales_order_flag%type ;
7476 l_ship_so_flag csd_product_transactions.ship_sales_order_flag%type ;
7477 l_qty_shipped number;
7478
7479 -- activity record
7480 l_activity_rec activity_rec_type;
7481
7482 -- Variables for the FND Log
7483 l_error_level number := FND_LOG.LEVEL_ERROR;
7484 l_mod_name varchar2(2000) := 'csd.plsql.csd_update_programs_pvt.io_ship_update';
7485
7486 -- User defined exception
7487 PROCESS_ERROR EXCEPTION;
7488 SKIP_RECORD EXCEPTION;
7489
7490 BEGIN
7491
7492 -- Standard Start of API savepoint
7493 SAVEPOINT IO_SHIP_UPDATE;
7494
7495 -- Initialize API return status to success
7496 x_return_status := FND_API.G_RET_STS_SUCCESS;
7497
7498 Debug('At the Beginning of IO_SHIP_UPDATE',l_mod_name,1 );
7499 Debug('Order Header Id ='||p_order_header_id,l_mod_name,1);
7500
7501 -- Standard call to check for call compatibility.
7502 IF NOT FND_API.Compatible_API_Call (l_api_version,
7503 p_api_version,
7504 l_api_name ,
7505 G_PKG_NAME )
7506 THEN
7507 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7508 END IF;
7509
7510 -- Initialize message list if p_init_msg_list is set to TRUE.
7511 IF FND_API.to_Boolean( p_init_msg_list ) THEN
7512 FND_MSG_PUB.initialize;
7513 END IF;
7514
7515 -- Api body starts
7516
7517 -- In case of Internal orders, the product txns are stamped
7518 -- with the order header id and line id.
7519 -- So Validate if it exists in csd_product_transactions
7520 IF NVL(p_order_header_id,-999) <> -999 THEN
7521 BEGIN
7522 select 'EXISTS'
7523 into l_dummy
7524 from oe_order_headers_all oeh,
7525 po_requisition_headers_all prh
7526 where oeh.source_document_id = prh.requisition_header_id
7527 and oeh.header_id = p_order_header_id
7528 and exists (select 'x'
7529 from csd_product_transactions cpt
7530 where cpt.order_header_id = oeh.header_id );
7531 EXCEPTION
7532 WHEN NO_DATA_FOUND THEN
7533 IF ( l_error_level >= G_debug_level) THEN
7534 fnd_message.set_name('CSD','CSD_INV_ORD_HEADER_ID');
7535 fnd_message.set_token('HEADER_ID',p_order_header_id);
7536 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
7537 ELSE
7538 fnd_message.set_name('CSD','CSD_INV_ORD_HEADER_ID');
7539 fnd_message.set_token('HEADER_ID',p_order_header_id);
7540 fnd_msg_pub.add;
7541 END IF;
7542 RAISE FND_API.G_EXC_ERROR;
7543 END;
7544 END IF;
7545
7546 --FOR DEL in DELIVERY_LINES(p_order_header_id)
7547 IF(p_order_header_Id is null) THEN
7548 OPEN DELIVERY_LINES_ALL;
7549 ELSE
7550 OPEN DELIVERY_LINES(p_order_header_id);
7551 END IF;
7552
7553 LOOP
7554 BEGIN
7555
7556 IF(p_order_header_Id is null) THEN
7557 FETCH DELIVERY_LINES_ALL INTO del;
7558 EXIT WHEN DELIVERY_LINES_ALL%NOTFOUND;
7559 ELSE
7560 FETCH DELIVERY_LINES INTO del;
7561 EXIT WHEN DELIVERY_LINES%NOTFOUND;
7562 END IF;
7563
7564 -- Savepoint
7565 SAVEPOINT ORDER_LINES;
7566
7567 -- Debug messages
7568 Debug('DEL.header_id ='||DEL.header_id,l_mod_name,1);
7569
7570 -- Get the action type and action code
7571 -- for the product txn line
7572 Begin
7573 select action_type,
7574 action_code
7575 into l_action_type,
7576 l_action_code
7577 from csd_product_transactions
7578 where order_header_id = DEL.header_id
7579 and rownum = 1;
7580 EXCEPTION
7581 WHEN NO_DATA_FOUND THEN
7582 IF ( l_error_level >= G_debug_level) THEN
7583 fnd_message.set_name('CSD','CSD_INV_ORD_HEADER_ID');
7584 fnd_message.set_token('HEADER_ID',DEL.header_id);
7585 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
7586 ELSE
7587 fnd_message.set_name('CSD','CSD_INV_ORD_HEADER_ID');
7588 fnd_message.set_token('HEADER_ID',DEL.header_id);
7589 fnd_msg_pub.add;
7590 END IF;
7591 RAISE FND_API.G_EXC_ERROR;
7592 END;
7593
7594 -- Debug messages
7595 Debug('l_action_type ='||l_action_type,l_mod_name,1);
7596 Debug('l_action_code ='||l_action_code,l_mod_name,1);
7597
7598 IF DEL.released_status in ('I','C') THEN
7599 l_release_so_flag := 'Y';
7600 l_ship_so_flag := 'Y';
7601 l_prod_txn_status := 'SHIPPED';
7602 ELSIF DEL.released_status = 'Y' THEN
7603 l_release_so_flag := 'Y';
7604 l_ship_so_flag := 'N';
7605 l_prod_txn_status := 'RELEASED';
7606 ELSE
7607 l_release_so_flag := 'N';
7608 l_ship_so_flag := 'N';
7609 l_prod_txn_status := 'BOOKED';
7610 END IF;
7611
7612
7613 IF l_action_type = 'MOVE_IN' THEN
7614
7615 -- Move-In case
7616 Debug('Processing the move-in lines ',l_mod_name,1);
7617
7618 Select nvl(sum(quantity_shipped),0)
7619 into l_total_shipped_qty
7620 from csd_product_transactions
7621 where action_type = 'MOVE_IN'
7622 and action_code = 'DEFECTIVES'
7623 and order_line_id = DEL.line_id
7624 and order_header_id = DEL.header_id;
7625
7626 -- Debug messages
7627 Debug('l_total_shipped_qty= '||l_total_shipped_qty,l_mod_name,1);
7628
7629 IF l_total_shipped_qty >= DEL.shipped_quantity THEN
7630 -- Debug messages
7631 Debug('Skipping the record ',l_mod_name,1);
7632 RAISE SKIP_RECORD;
7633 END IF;
7634
7635 -- Debug messages
7636 Debug('serial_number_control_code ='||DEL.serial_number_control_code,l_mod_name,1);
7637
7638 IF DEL.serial_number_control_code = 1 THEN
7639
7640 -- Non-Serialized case
7641 Debug('Item Is Non-Serialized ',l_mod_name,1);
7642
7643 --Initialize the variables
7644 l_prod_txn_id := NULL;
7645
7646 -- Check if the product txn exists
7647 -- for the order line and header id
7648 BEGIN
7649 Select product_transaction_id,
7650 repair_line_id
7651 into l_prod_txn_id,
7652 l_rep_line_id
7653 from csd_product_transactions
7654 where order_header_id = DEL.header_id
7655 and order_line_id = DEL.line_id
7656 and action_type = l_action_type
7657 and action_code = l_action_code;
7658 Debug('Product txn exist',l_mod_name,1);
7659 l_prod_txn_exists := TRUE;
7660 EXCEPTION
7661 When NO_DATA_FOUND then
7662 Debug('Product txn does not exist',l_mod_name,1);
7663 l_prod_txn_exists := FALSE;
7664 END;
7665
7666 IF l_prod_txn_exists THEN
7667 --If product txn exist then update the shipped qty and the status
7668 UPDATE CSD_PRODUCT_TRANSACTIONS
7669 SET quantity_shipped = nvl(quantity_shipped,0) + nvl(DEL.shipped_quantity,0),
7670 sub_inventory = DEL.subinventory,
7671 lot_number = DEL.lot_number,
7672 locator_id = DEL.locator_id,
7673 release_sales_order_flag = l_release_so_flag,
7674 ship_sales_order_flag = l_ship_so_flag,
7675 prod_txn_status = l_prod_txn_status,
7676 object_version_number = object_version_number+1,
7677 last_update_date = sysdate,
7678 last_updated_by = fnd_global.user_id,
7679 last_update_login = fnd_global.login_id
7680 WHERE product_transaction_id = l_prod_txn_id;
7681 IF SQL%NOTFOUND THEN
7682 IF ( l_error_level >= G_debug_level) THEN
7683 fnd_message.set_name('CSD','CSD_INV_PROD_TXN_ID');
7684 fnd_message.set_token('PROD_TXN_ID',l_prod_txn_id);
7685 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
7686 ELSE
7687 fnd_message.set_name('CSD','CSD_INV_PROD_TXN_ID');
7688 fnd_message.set_token('PROD_TXN_ID',l_prod_txn_id);
7689 fnd_msg_pub.add;
7690 END IF;
7691 RAISE PROCESS_ERROR;
7692 END IF;
7693
7694 ELSE -- product txn does not exist
7695 -- If product txn does not exist then insert a product txn for the
7696 -- split order line
7697 -- Get the repair line id for the order header id
7698 Begin
7699 Select repair_line_id
7700 into l_rep_line_id
7701 from csd_product_transactions
7702 where order_header_id = DEL.header_id
7703 and action_type = l_action_type
7704 and action_code = l_action_code
7705 and rownum = 1;
7706 Exception
7707 WHEN NO_DATA_FOUND THEN
7708 IF ( l_error_level >= G_debug_level) THEN
7709 fnd_message.set_name('CSD','CSD_INV_ORD_HEADER_ID');
7710 fnd_message.set_token('ORDER_HEADER_ID',DEL.header_id);
7711 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
7712 ELSE
7713 fnd_message.set_name('CSD','CSD_INV_ORD_HEADER_ID');
7714 fnd_message.set_token('ORDER_HEADER_ID',DEL.header_id);
7715 fnd_msg_pub.add;
7716 END IF;
7717 RAISE PROCESS_ERROR;
7718 End;
7719 Begin
7720 Debug('Calling CSD_PRODUCT_TRANSACTIONS_PKG.INSERT_ROW',l_mod_name,2);
7721 CSD_PRODUCT_TRANSACTIONS_PKG.INSERT_ROW
7722 (px_PRODUCT_TRANSACTION_ID => l_prod_txn_id,
7723 p_REPAIR_LINE_ID => l_rep_line_id,
7724 p_ESTIMATE_DETAIL_ID => NULL,
7725 p_ACTION_TYPE => l_action_type,
7726 p_ACTION_CODE => l_action_code,
7727 p_LOT_NUMBER => DEL.lot_number,
7728 p_SUB_INVENTORY => DEL.subinventory,
7729 p_INTERFACE_TO_OM_FLAG => 'Y',
7730 p_BOOK_SALES_ORDER_FLAG => 'Y',
7731 p_RELEASE_SALES_ORDER_FLAG => l_release_so_flag,
7732 p_SHIP_SALES_ORDER_FLAG => l_ship_so_flag,
7733 p_PROD_TXN_STATUS => l_prod_txn_status,
7734 p_PROD_TXN_CODE => '',
7735 p_LAST_UPDATE_DATE => sysdate,
7736 p_CREATION_DATE => sysdate,
7737 p_LAST_UPDATED_BY => fnd_global.user_id,
7738 p_CREATED_BY => fnd_global.user_id,
7739 p_LAST_UPDATE_LOGIN => null,
7740 p_ATTRIBUTE1 => '',
7741 p_ATTRIBUTE2 => '',
7742 p_ATTRIBUTE3 => '',
7743 p_ATTRIBUTE4 => '',
7744 p_ATTRIBUTE5 => '',
7745 p_ATTRIBUTE6 => '',
7746 p_ATTRIBUTE7 => '',
7747 p_ATTRIBUTE8 => '',
7748 p_ATTRIBUTE9 => '',
7749 p_ATTRIBUTE10 => '',
7750 p_ATTRIBUTE11 => '',
7751 p_ATTRIBUTE12 => '',
7752 p_ATTRIBUTE13 => '',
7753 p_ATTRIBUTE14 => '',
7754 p_ATTRIBUTE15 => '',
7755 p_CONTEXT => '',
7756 p_OBJECT_VERSION_NUMBER => 1,
7757 P_REQ_HEADER_ID => DEL.req_header_id,
7758 P_REQ_LINE_ID => DEL.req_line_id,
7759 P_ORDER_HEADER_ID => DEL.header_id,
7760 P_ORDER_LINE_ID => DEL.line_id,
7761 P_PRD_TXN_QTY_RECEIVED => 0,
7762 P_PRD_TXN_QTY_SHIPPED => nvl(DEL.shipped_quantity,0),
7763 P_SOURCE_SERIAL_NUMBER => '',
7764 P_SOURCE_INSTANCE_ID => NULL,
7765 P_NON_SOURCE_SERIAL_NUMBER => '',
7766 P_NON_SOURCE_INSTANCE_ID => NULL,
7767 P_LOCATOR_ID => DEL.locator_id,
7768 P_SUB_INVENTORY_RCVD => '',
7769 P_LOT_NUMBER_RCVD => '',
7770 P_PICKING_RULE_ID => null,
7771 P_PROJECT_ID => null,
7772 P_TASK_ID => null,
7773 P_UNIT_NUMBER => '');
7774 Exception
7775 When Others then
7776 IF ( l_error_level >= G_debug_level) THEN
7777 fnd_message.set_name('CSD','CSD_PROD_TXN_INSERT_FAILED');
7778 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
7779 ELSE
7780 fnd_message.set_name('CSD','CSD_PROD_TXN_INSERT_FAILED');
7781 fnd_msg_pub.add;
7782 END IF;
7783 RAISE PROCESS_ERROR;
7784 END;
7785 END IF;
7786
7787 ELSE -- Serialized scenario
7788
7789 --Initialize the variables
7790 l_prod_txn_id := NULL;
7791
7792 -- Check if the product txn exists
7793 -- for the order line and header id
7794 BEGIN
7795 Select product_transaction_id,
7796 repair_line_id
7797 into l_prod_txn_id,
7798 l_rep_line_id
7799 from csd_product_transactions
7800 where order_header_id = DEL.header_id
7801 and order_line_id = DEL.line_id
7802 and action_type = l_action_type
7803 and action_code = l_action_code
7804 and rownum =1;
7805 Debug('Product txn exist',l_mod_name,1);
7806 l_prod_txn_exists := TRUE;
7807 EXCEPTION
7808 When NO_DATA_FOUND then
7809 Debug('Product txn does not exist',l_mod_name,1);
7810 l_prod_txn_exists := FALSE;
7811 END;
7812
7813 IF DEL.released_status in ('I','C') THEN
7814 l_qty_shipped := 1;
7815 ELSE
7816 l_qty_shipped := 0;
7817 END IF;
7818
7819 IF l_prod_txn_exists THEN
7820 UPDATE CSD_PRODUCT_TRANSACTIONS
7821 SET quantity_shipped = l_qty_shipped,
7822 release_sales_order_flag = l_release_so_flag,
7823 ship_sales_order_flag = l_ship_so_flag,
7824 prod_txn_status = l_prod_txn_status,
7825 sub_inventory = DEL.subinventory,
7826 lot_number = DEL.lot_number,
7827 locator_id = DEL.locator_id,
7828 object_version_number = object_version_number+1,
7829 last_update_date = sysdate,
7830 last_updated_by = fnd_global.user_id,
7831 last_update_login = fnd_global.login_id
7832 WHERE order_header_id = DEL.header_id
7833 and order_line_id = DEL.line_id
7834 and action_type = l_action_type
7835 and action_code = l_action_code
7836 and prod_txn_status in('BOOKED','RELEASED')
7837 and rownum <= nvl(DEL.requested_quantity,0) ;
7838 IF SQL%NOTFOUND THEN
7839 IF ( l_error_level >= G_debug_level) THEN
7840 fnd_message.set_name('CSD','CSD_INV_ORDER_LINE_ID');
7841 fnd_message.set_token('ORDER_LINE_ID',DEL.line_id);
7842 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
7843 ELSE
7844 fnd_message.set_name('CSD','CSD_INV_ORDER_LINE_ID');
7845 fnd_message.set_token('ORDER_LINE_ID',DEL.line_id);
7846 fnd_msg_pub.add;
7847 END IF;
7848 RAISE PROCESS_ERROR;
7849 END IF;
7850 ELSE
7851 UPDATE CSD_PRODUCT_TRANSACTIONS
7852 SET quantity_shipped = l_qty_shipped,
7853 order_line_id = DEL.line_id,
7854 release_sales_order_flag = l_release_so_flag,
7855 ship_sales_order_flag = l_ship_so_flag,
7856 prod_txn_status = l_prod_txn_status,
7857 sub_inventory = DEL.subinventory,
7858 lot_number = DEL.lot_number,
7859 locator_id = DEL.locator_id,
7860 object_version_number = object_version_number+1,
7861 last_update_date = sysdate,
7862 last_updated_by = fnd_global.user_id,
7863 last_update_login = fnd_global.login_id
7864 WHERE order_header_id = DEL.header_id
7865 and action_type = l_action_type
7866 and action_code = l_action_code
7867 and prod_txn_status in ('BOOKED','RELEASED')
7868 and rownum <= nvl(DEL.requested_quantity,0);
7869 IF SQL%NOTFOUND THEN
7870 IF ( l_error_level >= G_debug_level) THEN
7871 fnd_message.set_name('CSD','CSD_INV_ORDER_LINE_ID');
7872 fnd_message.set_token('ORDER_LINE_ID',DEL.line_id);
7873 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
7874 ELSE
7875 fnd_message.set_name('CSD','CSD_INV_ORDER_LINE_ID');
7876 fnd_message.set_token('ORDER_LINE_ID',DEL.line_id);
7877 fnd_msg_pub.add;
7878 END IF;
7879 RAISE PROCESS_ERROR;
7880 END IF;
7881 END IF;
7882
7883 END IF;
7884
7885 ELSE -- action_type = 'MOVE_OUT'
7886
7887 -- Move-out Lines
7888 Debug('Processing the move-out lines ',l_mod_name,1);
7889
7890 Select nvl(sum(quantity),0)
7891 into l_total_shipped_qty
7892 from csd_repair_history
7893 where event_code = 'PSI'
7894 and paramn1 = DEL.delivery_detail_id;
7895
7896 -- Debug messages
7897 Debug('l_total_shipped_qty= '||l_total_shipped_qty,l_mod_name,1);
7898 IF l_total_shipped_qty >= DEL.shipped_quantity THEN
7899 -- Debug messages
7900 Debug('Skipping the record ',l_mod_name,1);
7901 RAISE SKIP_RECORD;
7902 END IF;
7903
7904 -- Processing starts for item is pre-deined/serialized inv receipt
7905 -- In case of partial shipment against the move-out internal orders
7906 -- the order lines gets split. But the product txn exist only for the
7907 -- original order line id and header id. In such case the update program
7908 -- will create new product txn lines for the split order lines
7909 --
7910 --BEFORE SPLIT
7911 --
7912 -- Order Lines
7913 -- Line Id Header Id Qty Shipped Qty PO Line Id Split_From Line_id
7914 -- L1 H1 10 0 PL1
7915 --
7916 -- Delivery Lines
7917 -- Del Line Id Ord Line Id Shipped Qty Rel Status
7918 -- D1 L1 0 R/Y
7919 --
7920 -- Repair Order
7921 -- RO Number RO qty Shipped Qty
7922 -- R1 10 0
7923 --
7924 -- PRODUCT TXN
7925 -- Prod Txn Line Id Header Id PO Line Id Shipped Qty
7926 -- P1 L1 H1 PL1 0
7927 --
7928 --
7929 -- AFTER ORDER LINE SPLIT (Partial Shipping)
7930 -- Order Lines
7931 -- Line Id Header Id Qty Shipped Qty PO Line Id Split_From Line_id
7932 -- L1 H1 6 6 PL1
7933 -- L2 H1 1 1 PL1 L1
7934 -- L3 H1 3 3 PL1 L2
7935 --
7936 -- Delivery Lines
7937 -- Del Line Id Ord Line Id Shipped Qty
7938 -- D1 L1 6
7939 -- D2 L2 1
7940 -- D3 L3 3
7941 --
7942 -- Repair Order
7943 -- RO Number RO qty Shipped Qty
7944 -- R1 10 0
7945 --
7946 -- PRODUCT TXN
7947 -- Prod Txn Line Id Header Id PO Line Id Shipped Qty
7948 -- P1 L1 H1 PL1 6
7949 -- P2 L2 H1 PL1 1
7950 -- P3 L3 H1 PL1 3
7951 --
7952 --
7953 IF DEL.serial_number_control_code = 1 THEN
7954
7955 --Initialize the variables
7956 l_prod_txn_id := NULL;
7957
7958 -- Check if the product txn exists
7959 -- for the order line and header id
7960 BEGIN
7961 Select product_transaction_id,
7962 repair_line_id
7963 into l_prod_txn_id,
7964 l_rep_line_id
7965 from csd_product_transactions
7966 where order_header_id = DEL.header_id
7967 and order_line_id = DEL.line_id
7968 and action_type = l_action_type
7969 and action_code = l_action_code;
7970 Debug('Product txn exist',l_mod_name,1);
7971 l_prod_txn_exists := TRUE;
7972 EXCEPTION
7973 When NO_DATA_FOUND then
7974 Debug('Product txn does not exist',l_mod_name,1);
7975 l_prod_txn_exists := FALSE;
7976 END;
7977
7978 -- Non-Serialized case
7979 Debug('Item Is Non-Serialized ',l_mod_name,1);
7980
7981 IF l_prod_txn_exists THEN
7982 --If product txn exist then update the shipped qty and the status
7983 UPDATE CSD_PRODUCT_TRANSACTIONS
7984 SET quantity_shipped = nvl(quantity_shipped,0) + nvl(DEL.shipped_quantity,0),
7985 sub_inventory = DEL.subinventory,
7986 lot_number = DEL.lot_number,
7987 locator_id = DEL.locator_id,
7988 release_sales_order_flag = l_release_so_flag,
7989 ship_sales_order_flag = l_ship_so_flag,
7990 prod_txn_status = l_prod_txn_status,
7991 object_version_number = object_version_number+1,
7992 last_update_date = sysdate,
7993 last_updated_by = fnd_global.user_id,
7994 last_update_login = fnd_global.login_id
7995 WHERE product_transaction_id = l_prod_txn_id;
7996 IF SQL%NOTFOUND THEN
7997 IF ( l_error_level >= G_debug_level) THEN
7998 fnd_message.set_name('CSD','CSD_INV_PROD_TXN_ID');
7999 fnd_message.set_token('PROD_TXN_ID',l_prod_txn_id);
8000 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
8001 ELSE
8002 fnd_message.set_name('CSD','CSD_INV_PROD_TXN_ID');
8003 fnd_message.set_token('PROD_TXN_ID',l_prod_txn_id);
8004 fnd_msg_pub.add;
8005 END IF;
8006 RAISE PROCESS_ERROR;
8007 END IF;
8008
8009 ELSE -- product txn does not exist
8010 -- If product txn does not exist then insert a product txn for the
8011 -- split order line
8012 -- Get the repair line id for the order header id
8013 Begin
8014 Select repair_line_id
8015 into l_rep_line_id
8016 from csd_product_transactions
8017 where order_header_id = DEL.header_id
8018 and action_type = l_action_type
8019 and action_code = l_action_code
8020 and rownum = 1;
8021 Exception
8022 WHEN NO_DATA_FOUND THEN
8023 IF ( l_error_level >= G_debug_level) THEN
8024 fnd_message.set_name('CSD','CSD_INV_ORD_HEADER_ID');
8025 fnd_message.set_token('ORDER_HEADER_ID',DEL.header_id);
8026 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
8027 ELSE
8028 fnd_message.set_name('CSD','CSD_INV_ORD_HEADER_ID');
8029 fnd_message.set_token('ORDER_HEADER_ID',DEL.header_id);
8030 fnd_msg_pub.add;
8031 END IF;
8032 RAISE PROCESS_ERROR;
8033 End;
8034 Begin
8035 Debug('Calling CSD_PRODUCT_TRANSACTIONS_PKG.INSERT_ROW',l_mod_name,2);
8036 CSD_PRODUCT_TRANSACTIONS_PKG.INSERT_ROW
8037 (px_PRODUCT_TRANSACTION_ID => l_prod_txn_id,
8038 p_REPAIR_LINE_ID => l_rep_line_id,
8039 p_ESTIMATE_DETAIL_ID => NULL,
8040 p_ACTION_TYPE => l_action_type,
8041 p_ACTION_CODE => l_action_code,
8042 p_LOT_NUMBER => DEL.lot_number,
8043 p_SUB_INVENTORY => DEL.subinventory,
8044 p_INTERFACE_TO_OM_FLAG => 'Y',
8045 p_BOOK_SALES_ORDER_FLAG => 'Y',
8046 p_RELEASE_SALES_ORDER_FLAG => l_release_so_flag,
8047 p_SHIP_SALES_ORDER_FLAG => l_ship_so_flag,
8048 p_PROD_TXN_STATUS => l_prod_txn_status,
8049 p_PROD_TXN_CODE => '',
8050 p_LAST_UPDATE_DATE => sysdate,
8051 p_CREATION_DATE => sysdate,
8052 p_LAST_UPDATED_BY => fnd_global.user_id,
8053 p_CREATED_BY => fnd_global.user_id,
8054 p_LAST_UPDATE_LOGIN => null,
8055 p_ATTRIBUTE1 => '',
8056 p_ATTRIBUTE2 => '',
8057 p_ATTRIBUTE3 => '',
8058 p_ATTRIBUTE4 => '',
8059 p_ATTRIBUTE5 => '',
8060 p_ATTRIBUTE6 => '',
8061 p_ATTRIBUTE7 => '',
8062 p_ATTRIBUTE8 => '',
8063 p_ATTRIBUTE9 => '',
8064 p_ATTRIBUTE10 => '',
8065 p_ATTRIBUTE11 => '',
8066 p_ATTRIBUTE12 => '',
8067 p_ATTRIBUTE13 => '',
8068 p_ATTRIBUTE14 => '',
8069 p_ATTRIBUTE15 => '',
8070 p_CONTEXT => '',
8071 p_OBJECT_VERSION_NUMBER => 1,
8072 P_REQ_HEADER_ID => DEL.req_header_id,
8073 P_REQ_LINE_ID => DEL.req_line_id,
8074 P_ORDER_HEADER_ID => DEL.header_id,
8075 P_ORDER_LINE_ID => DEL.line_id,
8076 P_PRD_TXN_QTY_RECEIVED => 0,
8077 P_PRD_TXN_QTY_SHIPPED => nvl(DEL.shipped_quantity,0),
8078 P_SOURCE_SERIAL_NUMBER => '',
8079 P_SOURCE_INSTANCE_ID => NULL,
8080 P_NON_SOURCE_SERIAL_NUMBER => '',
8081 P_NON_SOURCE_INSTANCE_ID => NULL,
8082 P_LOCATOR_ID => DEL.locator_id,
8083 P_SUB_INVENTORY_RCVD => '',
8084 P_LOT_NUMBER_RCVD => '',
8085 P_PICKING_RULE_ID => null,
8086 P_PROJECT_ID => null,
8087 P_TASK_ID => null,
8088 P_UNIT_NUMBER => '');
8089
8090 Exception
8091 When Others then
8092 IF ( l_error_level >= G_debug_level) THEN
8093 fnd_message.set_name('CSD','CSD_PROD_TXN_INSERT_FAILED');
8094 FND_LOG.MESSAGE(l_error_level,l_mod_name, FALSE);
8095 ELSE
8096 fnd_message.set_name('CSD','CSD_PROD_TXN_INSERT_FAILED');
8097 fnd_msg_pub.add;
8098 END IF;
8099 RAISE PROCESS_ERROR;
8100 END;
8101 END IF; -- end if prod_txn_exists
8102
8103 IF DEL.released_status in ('C','I') THEN
8104
8105 -- Updating the repair order with shipped_qty
8106 Update csd_repairs
8107 set quantity_shipped = nvl(quantity_shipped,0) + DEL.shipped_quantity,
8108 object_version_number = object_version_number+1,
8109 last_update_date = sysdate,
8110 last_updated_by = fnd_global.user_id,
8111 last_update_login = fnd_global.login_id
8112 where repair_line_id = l_rep_line_id;
8113 IF SQL%NOTFOUND THEN
8114 IF ( l_error_level >= G_debug_level) THEN
8115 FND_MESSAGE.SET_NAME('CSD','CSD_RO_UPD_FAILED');
8116 FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',l_rep_line_id);
8117 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
8118 ELSE
8119 FND_MESSAGE.SET_NAME('CSD','CSD_RO_UPD_FAILED');
8120 FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',l_rep_line_id);
8121 FND_MSG_PUB.ADD;
8122 END IF;
8123 RAISE PROCESS_ERROR;
8124 END IF;
8125
8126 -- Initialize the activity rec
8127 l_activity_rec := INIT_ACTIVITY_REC ;
8128
8129 -- Assign the values for activity record
8130 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
8131 l_activity_rec.REPAIR_LINE_ID := l_rep_line_id;
8132 l_activity_rec.EVENT_CODE := 'PSI';
8133 l_activity_rec.ACTION_CODE := 0;
8134 l_activity_rec.EVENT_DATE := DEL.shipment_date;
8135 l_activity_rec.QUANTITY := DEL.shipped_quantity;
8136 l_activity_rec.PARAMN1 := DEL.delivery_detail_id;
8137 l_activity_rec.PARAMN2 := l_prod_txn_id;
8138 l_activity_rec.PARAMN3 := DEL.source_organization_id;
8139 l_activity_rec.PARAMN5 := DEL.destination_organization_id;
8140 l_activity_rec.PARAMC1 := DEL.order_number;
8141 l_activity_rec.PARAMC2 := DEL.requisition_number;
8142 l_activity_rec.PARAMC3 := DEL.source_org_name;
8143 l_activity_rec.PARAMC4 := DEL.source_subinventory;
8144 l_activity_rec.PARAMC5 := DEL.destination_org_name;
8145 l_activity_rec.PARAMC6 := DEL.destination_subinventory;
8146 l_activity_rec.OBJECT_VERSION_NUMBER := null;
8147
8148 -- Debug Messages
8149 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
8150
8151 -- Calling LOG_ACTIVITY for logging activity
8152 LOG_ACTIVITY
8153 ( p_api_version => p_api_version,
8154 p_commit => p_commit,
8155 p_init_msg_list => p_init_msg_list,
8156 p_validation_level => p_validation_level,
8157 x_return_status => x_return_status,
8158 x_msg_count => x_msg_count,
8159 x_msg_data => x_msg_data,
8160 p_activity_rec => l_activity_rec );
8161
8162 -- Debug Messages
8163 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
8164
8165 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
8166 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
8167 RAISE FND_API.G_EXC_ERROR;
8168 END IF;
8169
8170 END IF; -- end of del.released_status in ('c','i')
8171
8172 ELSE --DEL.serial_number_control_code <> 1 THEN
8173
8174 Debug('DEL.LOT_CONTROL_CODE ='||DEL.LOT_CONTROL_CODE ,l_mod_name,1);
8175
8176 -- In case of item serialized at sales order issue, the serial number is stored
8177 -- in the material unit transactions. Need to join the mtl_material_transactions
8178 -- with mtl_unit_transactions to get the serial numbers.
8179 -- Serial Number Control Code = 6 (Serialized at Sales order Issue)
8180 -- Delivery Lines
8181 -- Del Line Id Order Line Id Shipped Qty
8182 -- D1 L1 6
8183 -- D2 L2 3
8184 -- D3 L2 1
8185 --
8186 -- Unit Trxs
8187 -- Txn Id Del Line id Serial Num
8188 -- T1 D1 SN11
8189 -- T2 D1 SN12
8190 -- T3 D1 SN13
8191 -- T4 D1 SN14
8192 -- T5 D1 SN15
8193 -- T6 D1 SN16
8194 -- T7 D2 SN17
8195 -- T8 D2 SN18
8196 -- T9 D2 SN19
8197 -- T10 D3 SN20
8198 --
8199 IF DEL.LOT_CONTROL_CODE = 1 THEN
8200 Debug(' Item is not lot controlled',l_mod_name,1);
8201
8202 FOR UT in MTL_UNIT_TXN (DEL.delivery_detail_id, DEL.txn_source_id)
8203 LOOP
8204 BEGIN
8205 Begin
8206 -- saupadhy 3757519 07102004 Commented line Supercession_inv_item_id is null
8207 -- as this may not be true.
8208 -- Added line cpt.Order_Header_id = Del.Header_Id as this
8209 Select cpt.product_transaction_id,
8210 cpt.repair_line_id
8211 into l_prod_txn_id,
8212 l_rep_line_id
8213 from csd_product_transactions cpt,
8214 csd_repairs cra
8215 where cpt.order_header_id = DEL.Header_id
8216 and cpt.action_type = 'MOVE_OUT'
8217 and cpt.action_code = 'USABLES'
8218 and cpt.prod_txn_status in ('BOOKED', 'RELEASED')
8219 -- and cra.supercession_inv_item_id is null
8220 and cpt.source_serial_number is null
8221 and cpt.repair_line_id = cra.repair_line_id
8222 and cra.serial_number = UT.serial_number ;
8223
8224 Debug('Product txn line found',l_mod_name,1);
8225
8226 -- Updating the product txns with status,shipped_qty
8227 Update csd_product_transactions
8228 set prod_txn_status = 'SHIPPED',
8229 quantity_shipped = 1,
8230 sub_inventory = DEL.subinventory,
8231 locator_id = DEL.locator_id,
8232 lot_number = DEL.lot_number,
8233 release_sales_order_flag = 'Y',
8234 ship_sales_order_flag = 'Y',
8235 order_line_id = DEL.line_id,
8236 source_serial_number = UT.serial_number,
8237 object_version_number = object_version_number+1,
8238 last_update_date = sysdate,
8239 last_updated_by = fnd_global.user_id,
8240 last_update_login = fnd_global.login_id
8241 where product_transaction_id = l_prod_txn_id;
8242 IF SQL%NOTFOUND THEN
8243 IF ( l_error_level >= G_debug_level) THEN
8244 FND_MESSAGE.SET_NAME('CSD','CSD_INV_PROD_TXN_ID');
8245 FND_MESSAGE.SET_TOKEN('PROD_TXN_ID',l_prod_txn_id);
8246 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
8247 ELSE
8248 FND_MESSAGE.SET_NAME('CSD','CSD_INV_PROD_TXN_ID');
8249 FND_MESSAGE.SET_TOKEN('PROD_TXN_ID',l_prod_txn_id);
8250 FND_MSG_PUB.ADD;
8251 END IF;
8252 RAISE PROCESS_ERROR;
8253 END IF;
8254
8255 -- Updating the repair order with shipped_qty
8256 Update csd_repairs
8257 set quantity_shipped = 1,
8258 object_version_number = object_version_number+1,
8259 last_update_date = sysdate,
8260 last_updated_by = fnd_global.user_id,
8261 last_update_login = fnd_global.login_id
8262 where repair_line_id = l_rep_line_id;
8263 IF SQL%NOTFOUND THEN
8264 IF ( l_error_level >= G_debug_level) THEN
8265 FND_MESSAGE.SET_NAME('CSD','CSD_RO_UPD_FAILED');
8266 FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',l_rep_line_id);
8267 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
8268 ELSE
8269 FND_MESSAGE.SET_NAME('CSD','CSD_RO_UPD_FAILED');
8270 FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',l_rep_line_id);
8271 FND_MSG_PUB.ADD;
8272 END IF;
8273 RAISE PROCESS_ERROR;
8274 END IF;
8275 -- product txn exist
8276 l_prod_txn_exists := TRUE;
8277 Exception
8278 WHEN NO_DATA_FOUND THEN
8279 Debug('Product txn line not found',l_mod_name,1);
8280 -- product txn does not exist
8281 l_prod_txn_exists := FALSE;
8282 End;
8283
8284 --If the serial number on the unit transactions may not be in the
8285 -- same order as the product txn. In a delivery some serial numbers could find
8286 -- repair order/product txn combination. But some may not have a matching serial number
8287 -- So we do not want to take repair order/product txn which could have a matching serial
8288 -- number in the later unit transactions
8289 --
8290 -- Product Txn
8291 -- Prod Txn RO Num Qty RO Serial Num
8292 -- P1 R1 1 SN1
8293 -- P2 R2 1 SN2
8294 -- P3 R3 1 SN3
8295 -- P4 R4 1 SN4
8296 -- P5 R5 1 SN5
8297 --
8298 -- Delivery Lines
8299 -- Del Id Ship Qty Ord Line
8300 -- D1 2 L1
8301 -- D2 3 L2
8302 --
8303 -- Unit Transactions
8304 -- Txn Id Del Id Qty Serial Num
8305 -- M1 D1 1 SN5
8306 -- M2 D1 1 SN1
8307 -- M3 D2 1 SN9
8308 -- M4 D2 1 SN2
8309 -- M5 D2 1 SN3
8310 -- The serial number would finally matched as follows:
8311 -- Ro Num Prod Txn RO SN UTSerial Num
8312 -- R1 P1 SN1 SN1
8313 -- R2 P2 SN2 SN2
8314 -- R3 P3 SN3 SN3
8315 -- R4 P4 SN4 SN9
8316 -- R5 P5 SN5 SN5
8317 IF NOT(l_prod_txn_exists) THEN
8318 Begin
8319 Select cpt.product_transaction_id,
8320 cpt.repair_line_id
8321 into l_prod_txn_id,
8322 l_rep_line_id
8323 from csd_product_transactions cpt,
8324 csd_repairs cra
8325 where cpt.repair_line_id = cra.repair_line_id
8326 and cpt.order_header_id = DEL.header_id
8327 and cpt.source_serial_number is null
8328 and cpt.action_type = 'MOVE_OUT'
8329 and cpt.action_code = 'USABLES'
8330 and cpt.prod_txn_status in ('BOOKED','RELEASED')
8331 and cra.serial_number not in
8332 (select
8333 mut.serial_number
8334 from mtl_material_transactions mtl,
8335 mtl_unit_transactions mut,
8336 wsh_delivery_details wdd
8337 where mtl.transaction_id = mut.transaction_id
8338 and mtl.transaction_source_type_id = 8 -- Internal Order
8339 and mtl.transaction_type_id in ( 50,62,54,34)
8340 and mtl.transaction_source_id = DEL.txn_source_id
8341 and mtl.picking_line_id = wdd.delivery_detail_id
8342 and wdd.source_header_id = DEL.header_id)
8343 and rownum = 1;
8344
8345 -- Updating the product txns with status,shipped_qty
8346 Update csd_product_transactions
8347 set prod_txn_status = 'SHIPPED',
8348 quantity_shipped = 1,
8349 sub_inventory = DEL.subinventory,
8350 locator_id = DEL.locator_id,
8351 lot_number = DEL.lot_number,
8352 release_sales_order_flag = 'Y',
8353 ship_sales_order_flag = 'Y',
8354 order_line_id = DEL.line_id,
8355 source_serial_number = UT.serial_number,
8356 object_version_number = object_version_number+1,
8357 last_update_date = sysdate,
8358 last_updated_by = fnd_global.user_id,
8359 last_update_login = fnd_global.login_id
8360 where product_transaction_id = l_prod_txn_id;
8361 IF SQL%NOTFOUND THEN
8362 IF ( l_error_level >= G_debug_level) THEN
8363 FND_MESSAGE.SET_NAME('CSD','CSD_PROD_TXN_UPD_FAILED');
8364 FND_MESSAGE.SET_TOKEN('PROD_TXN_ID',l_prod_txn_id);
8365 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
8366 ELSE
8367 FND_MESSAGE.SET_NAME('CSD','CSD_PROD_TXN_UPD_FAILED');
8368 FND_MESSAGE.SET_TOKEN('PROD_TXN_ID',l_prod_txn_id);
8369 FND_MSG_PUB.ADD;
8370 END IF;
8371 RAISE PROCESS_ERROR;
8372 END IF;
8373
8374 -- Updating the repair order with shipped_qty
8375 Update csd_repairs
8376 set quantity_shipped = 1,
8377 object_version_number = object_version_number+1,
8378 last_update_date = sysdate,
8379 last_updated_by = fnd_global.user_id,
8380 last_update_login = fnd_global.login_id
8381 where repair_line_id = l_rep_line_id;
8382 IF SQL%NOTFOUND THEN
8383 IF ( l_error_level >= G_debug_level) THEN
8384 FND_MESSAGE.SET_NAME('CSD','CSD_RO_UPD_FAILED');
8385 FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',l_rep_line_id);
8386 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
8387 ELSE
8388 FND_MESSAGE.SET_NAME('CSD','CSD_RO_UPD_FAILED');
8389 FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',l_rep_line_id);
8390 FND_MSG_PUB.ADD;
8391 END IF;
8392 RAISE PROCESS_ERROR;
8393 END IF;
8394 Exception
8395 WHEN NO_DATA_FOUND THEN
8396 Debug('In NO_DATA_FOUND exception ',l_mod_name,4);
8397 RAISE PROCESS_ERROR;
8398 WHEN OTHERS THEN
8399 Debug('In Others exception ',l_mod_name,4);
8400 RAISE PROCESS_ERROR;
8401 End;
8402 End If; --not(l_prod_txn_exist)
8403
8404 -- Initialize the activity rec
8405 l_activity_rec := INIT_ACTIVITY_REC ;
8406
8407 -- Assign the values for activity record
8408 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
8409 l_activity_rec.REPAIR_LINE_ID := l_rep_line_id;
8410 l_activity_rec.EVENT_CODE := 'PSI';
8411 l_activity_rec.ACTION_CODE := 0;
8412 l_activity_rec.EVENT_DATE := DEL.shipment_date;
8413 l_activity_rec.QUANTITY := 1;
8414 l_activity_rec.PARAMN1 := DEL.delivery_detail_id;
8415 l_activity_rec.PARAMN2 := l_prod_txn_id;
8416 l_activity_rec.PARAMN3 := DEL.source_organization_id;
8417 l_activity_rec.PARAMN5 := DEL.destination_organization_id;
8418 l_activity_rec.PARAMC1 := DEL.order_number;
8419 l_activity_rec.PARAMC2 := DEL.requisition_number;
8420 l_activity_rec.PARAMC3 := DEL.source_org_name;
8421 l_activity_rec.PARAMC4 := DEL.source_subinventory;
8422 l_activity_rec.PARAMC5 := DEL.destination_org_name;
8423 l_activity_rec.PARAMC6 := DEL.destination_subinventory;
8424 l_activity_rec.OBJECT_VERSION_NUMBER := null;
8425
8426 -- Debug Messages
8427 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
8428
8429 -- Calling LOG_ACTIVITY for logging activity
8430 -- Shipment against internal sales order
8431 LOG_ACTIVITY
8432 ( p_api_version => p_api_version,
8433 p_commit => p_commit,
8434 p_init_msg_list => p_init_msg_list,
8435 p_validation_level => p_validation_level,
8436 x_return_status => x_return_status,
8437 x_msg_count => x_msg_count,
8438 x_msg_data => x_msg_data,
8439 p_activity_rec => l_activity_rec );
8440
8441 -- Debug Messages
8442 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
8443 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
8444 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
8445 RAISE FND_API.G_EXC_ERROR;
8446 END IF;
8447
8448 EXCEPTION
8449 WHEN PROCESS_ERROR THEN
8450 Debug('Encountered PROCESS_ERROR exception in UT cursor',l_mod_name,1);
8451 RAISE FND_API.G_EXC_ERROR;
8452 WHEN SKIP_RECORD THEN
8453 Debug('Skipping record in UT cursor',l_mod_name,1);
8454 NULL;
8455 END;
8456 END LOOP;
8457
8458 ELSE -- LOT CONTROLLED AND SERIAL CONTROLLED ITEM
8459
8460 Debug(' Item is lot controlled',l_mod_name,1);
8461
8462 FOR UT in MTL_UNIT_LOT_TXN (DEL.delivery_detail_id, DEL.txn_source_id )
8463 LOOP
8464 BEGIN
8465 Begin
8466 Select cpt.product_transaction_id,
8467 cpt.repair_line_id
8468 into l_prod_txn_id,
8469 l_rep_line_id
8470 from csd_product_transactions cpt,
8471 csd_repairs cra
8472 where cpt.repair_line_id = cra.repair_line_id
8473 and cra.supercession_inv_item_id is null
8474 and cpt.source_serial_number is null
8475 and cra.serial_number = UT.serial_number
8476 and cpt.action_type = 'MOVE_OUT'
8477 and cpt.action_code = 'USABLES'
8478 and cpt.prod_txn_status in ('BOOKED', 'RELEASED');
8479
8480 Debug('Product txn line found',l_mod_name,1);
8481
8482 -- Updating the product txns with status,shipped_qty
8483 Update csd_product_transactions
8484 set prod_txn_status = 'SHIPPED',
8485 quantity_shipped = 1,
8486 sub_inventory = DEL.subinventory,
8487 locator_id = DEL.locator_id,
8488 lot_number = DEL.lot_number,
8489 release_sales_order_flag = 'Y',
8490 ship_sales_order_flag = 'Y',
8491 order_line_id = DEL.line_id,
8492 source_serial_number = UT.serial_number,
8493 object_version_number = object_version_number+1,
8494 last_update_date = sysdate,
8495 last_updated_by = fnd_global.user_id,
8496 last_update_login = fnd_global.login_id
8497 where product_transaction_id = l_prod_txn_id;
8498 IF SQL%NOTFOUND THEN
8499 IF ( l_error_level >= G_debug_level) THEN
8500 FND_MESSAGE.SET_NAME('CSD','CSD_INV_PROD_TXN_ID');
8501 FND_MESSAGE.SET_TOKEN('PROD_TXN_ID',l_prod_txn_id);
8502 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
8503 ELSE
8504 FND_MESSAGE.SET_NAME('CSD','CSD_INV_PROD_TXN_ID');
8505 FND_MESSAGE.SET_TOKEN('PROD_TXN_ID',l_prod_txn_id);
8506 FND_MSG_PUB.ADD;
8507 END IF;
8508 RAISE PROCESS_ERROR;
8509 END IF;
8510
8511 -- Updating the repair order with shipped_qty
8512 Update csd_repairs
8513 set quantity_shipped = 1,
8514 object_version_number = object_version_number+1,
8515 last_update_date = sysdate,
8516 last_updated_by = fnd_global.user_id,
8517 last_update_login = fnd_global.login_id
8518 where repair_line_id = l_rep_line_id;
8519 IF SQL%NOTFOUND THEN
8520 IF ( l_error_level >= G_debug_level) THEN
8521 FND_MESSAGE.SET_NAME('CSD','CSD_RO_UPD_FAILED');
8522 FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',l_rep_line_id);
8523 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
8524 ELSE
8525 FND_MESSAGE.SET_NAME('CSD','CSD_RO_UPD_FAILED');
8526 FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',l_rep_line_id);
8527 FND_MSG_PUB.ADD;
8528 END IF;
8529 RAISE PROCESS_ERROR;
8530 END IF;
8531 -- product txn exist
8532 l_prod_txn_exists := TRUE;
8533 Exception
8534 WHEN NO_DATA_FOUND THEN
8535 Debug('Product txn line not found',l_mod_name,1);
8536 -- product txn does not exist
8537 l_prod_txn_exists := FALSE;
8538 End;
8539
8540 --If the serial number on the unit transactions may not be in the
8541 -- same order as the product txn. In a delivery some serial numbers could find
8542 -- repair order/product txn combination. But some may not have a matching serial number
8543 -- So we do not want to take repair order/product txn which could have a matching serial
8544 -- number in the later unit transactions
8545 --
8546 -- Product Txn
8547 -- Prod Txn RO Num Qty RO Serial Num
8548 -- P1 R1 1 SN1
8549 -- P2 R2 1 SN2
8550 -- P3 R3 1 SN3
8551 -- P4 R4 1 SN4
8552 -- P5 R5 1 SN5
8553 --
8554 -- Delivery Lines
8555 -- Del Id Ship Qty Ord Line
8556 -- D1 2 L1
8557 -- D2 3 L2
8558 --
8559 -- Unit Transactions
8560 -- Txn Id Del Id Qty Serial Num
8561 -- M1 D1 1 SN5
8562 -- M2 D1 1 SN1
8563 -- M3 D2 1 SN9
8564 -- M4 D2 1 SN2
8565 -- M5 D2 1 SN3
8566 -- The serial number would finally matched as follows:
8567 -- Ro Num Prod Txn RO SN UTSerial Num
8568 -- R1 P1 SN1 SN1
8569 -- R2 P2 SN2 SN2
8570 -- R3 P3 SN3 SN3
8571 -- R4 P4 SN4 SN9
8572 -- R5 P5 SN5 SN5
8573 IF NOT(l_prod_txn_exists) THEN
8574 Begin
8575 Select cpt.product_transaction_id,
8576 cpt.repair_line_id
8577 into l_prod_txn_id,
8578 l_rep_line_id
8579 from csd_product_transactions cpt,
8580 csd_repairs cra
8581 where cpt.repair_line_id = cra.repair_line_id
8582 and cpt.order_header_id = DEL.header_id
8583 and cpt.source_serial_number is null
8584 and cpt.action_type = 'MOVE_OUT'
8585 and cpt.action_code = 'USABLES'
8586 and cpt.prod_txn_status in ('BOOKED','RELEASED')
8587 and cra.serial_number not in
8588 (select
8589 mut.serial_number
8590 from mtl_material_transactions mtl,
8591 mtl_unit_transactions mut,
8592 wsh_delivery_details wdd
8593 where mtl.transaction_id = mut.transaction_id
8594 and mtl.transaction_source_type_id = 8 -- Internal Order
8595 and mtl.transaction_type_id in ( 50,62,54,34)
8596 and mtl.transaction_source_id = DEL.txn_source_id
8597 and mtl.picking_line_id = wdd.delivery_detail_id
8598 and wdd.source_header_id = DEL.header_id)
8599 and rownum = 1;
8600
8601 -- Updating the product txns with status,shipped_qty
8602 Update csd_product_transactions
8603 set prod_txn_status = 'SHIPPED',
8604 quantity_shipped = 1,
8605 sub_inventory = DEL.subinventory,
8606 locator_id = DEL.locator_id,
8607 lot_number = DEL.lot_number,
8608 release_sales_order_flag = 'Y',
8609 ship_sales_order_flag = 'Y',
8610 order_line_id = DEL.line_id,
8611 source_serial_number = UT.serial_number,
8612 object_version_number = object_version_number+1,
8613 last_update_date = sysdate,
8614 last_updated_by = fnd_global.user_id,
8615 last_update_login = fnd_global.login_id
8616 where product_transaction_id = l_prod_txn_id;
8617 IF SQL%NOTFOUND THEN
8618 IF ( l_error_level >= G_debug_level) THEN
8619 FND_MESSAGE.SET_NAME('CSD','CSD_PROD_TXN_UPD_FAILED');
8620 FND_MESSAGE.SET_TOKEN('PROD_TXN_ID',l_prod_txn_id);
8621 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
8622 ELSE
8623 FND_MESSAGE.SET_NAME('CSD','CSD_PROD_TXN_UPD_FAILED');
8624 FND_MESSAGE.SET_TOKEN('PROD_TXN_ID',l_prod_txn_id);
8625 FND_MSG_PUB.ADD;
8626 END IF;
8627 RAISE PROCESS_ERROR;
8628 END IF;
8629
8630 -- Updating the repair order with shipped_qty
8631 Update csd_repairs
8632 set quantity_shipped = 1,
8633 object_version_number = object_version_number+1,
8634 last_update_date = sysdate,
8635 last_updated_by = fnd_global.user_id,
8636 last_update_login = fnd_global.login_id
8637 where repair_line_id = l_rep_line_id;
8638 IF SQL%NOTFOUND THEN
8639 IF ( l_error_level >= G_debug_level) THEN
8640 FND_MESSAGE.SET_NAME('CSD','CSD_RO_UPD_FAILED');
8641 FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',l_rep_line_id);
8642 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
8643 ELSE
8644 FND_MESSAGE.SET_NAME('CSD','CSD_RO_UPD_FAILED');
8645 FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',l_rep_line_id);
8646 FND_MSG_PUB.ADD;
8647 END IF;
8648 RAISE PROCESS_ERROR;
8649 END IF;
8650 Exception
8651 WHEN NO_DATA_FOUND THEN
8652 Debug('In NO_DATA_FOUND exception ',l_mod_name,4);
8653 RAISE PROCESS_ERROR;
8654 WHEN OTHERS THEN
8655 Debug('In Others exception ',l_mod_name,4);
8656 RAISE PROCESS_ERROR;
8657 End;
8658 End If; --not(l_prod_txn_exist)
8659
8660 -- Initialize the activity rec
8661 l_activity_rec := INIT_ACTIVITY_REC ;
8662
8663 -- Assign the values for activity record
8664 l_activity_rec.REPAIR_HISTORY_ID := l_rep_hist_id;
8665 l_activity_rec.REPAIR_LINE_ID := l_rep_line_id;
8666 l_activity_rec.EVENT_CODE := 'PSI';
8667 l_activity_rec.ACTION_CODE := 0;
8668 l_activity_rec.EVENT_DATE := DEL.shipment_date;
8669 l_activity_rec.QUANTITY := 1;
8670 l_activity_rec.PARAMN1 := DEL.delivery_detail_id;
8671 l_activity_rec.PARAMN2 := l_prod_txn_id;
8672 l_activity_rec.PARAMN3 := DEL.source_organization_id;
8673 l_activity_rec.PARAMN5 := DEL.destination_organization_id;
8674 l_activity_rec.PARAMC1 := DEL.order_number;
8675 l_activity_rec.PARAMC2 := DEL.requisition_number;
8676 l_activity_rec.PARAMC3 := DEL.source_org_name;
8677 l_activity_rec.PARAMC4 := DEL.source_subinventory;
8678 l_activity_rec.PARAMC5 := DEL.destination_org_name;
8679 l_activity_rec.PARAMC6 := DEL.destination_subinventory;
8680 l_activity_rec.OBJECT_VERSION_NUMBER := null;
8681
8682 -- Debug Messages
8683 Debug('Calling LOG_ACTIVITY',l_mod_name,2);
8684
8685 -- Calling LOG_ACTIVITY for logging activity
8686 -- Shipment against internal sales order
8687 LOG_ACTIVITY
8688 ( p_api_version => p_api_version,
8689 p_commit => p_commit,
8690 p_init_msg_list => p_init_msg_list,
8691 p_validation_level => p_validation_level,
8692 x_return_status => x_return_status,
8693 x_msg_count => x_msg_count,
8694 x_msg_data => x_msg_data,
8695 p_activity_rec => l_activity_rec );
8696
8697 -- Debug Messages
8698 Debug('Return Status from LOG_ACTIVITY:'||x_return_status,l_mod_name,2);
8699 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
8700 Debug('LOG_ACTIVITY api failed ',l_mod_name,4);
8701 RAISE FND_API.G_EXC_ERROR;
8702 END IF;
8703
8704 EXCEPTION
8705 WHEN PROCESS_ERROR THEN
8706 Debug('Encountered PROCESS_ERROR exception in UT cursor',l_mod_name,1);
8707 RAISE FND_API.G_EXC_ERROR;
8708 WHEN SKIP_RECORD THEN
8709 Debug('Skipping record in UT cursor',l_mod_name,1);
8710 NULL;
8711 END;
8712 END LOOP;
8713
8714 END IF;
8715
8716 END IF; -- IF DEL.serial_number_control_code = 1
8717
8718 END IF; -- end if l_action_type = 'MOVE_IN'
8719
8720 EXCEPTION
8721 WHEN PROCESS_ERROR THEN
8722 Debug('Encountered PROCESS_ERROR exception in DELUT cursor',l_mod_name,1);
8723 RAISE FND_API.G_EXC_ERROR;
8724 WHEN SKIP_RECORD THEN
8725 NULL;
8726 WHEN OTHERS THEN
8727 Debug('Encountered OTHERS in DEL cursor',l_mod_name,1);
8728 RAISE FND_API.G_EXC_ERROR;
8729 END;
8730 END LOOP;
8731
8732 IF(DELIVERY_LINES_ALL%ISOPEN ) THEN
8733 CLOSE DELIVERY_LINES_ALL;
8734 END IF;
8735 IF(DELIVERY_LINES%ISOPEN ) THEN
8736 CLOSE DELIVERY_LINES;
8737 END IF;
8738
8739
8740 -- Standard check of p_commit.
8741 IF FND_API.To_Boolean( p_commit ) THEN
8742 COMMIT WORK;
8743 END IF;
8744
8745 -- Standard call to get message count and IF count is get message info.
8746 FND_MSG_PUB.Count_And_Get
8747 (p_count => x_msg_count,
8748 p_data => x_msg_data);
8749
8750 EXCEPTION
8751 WHEN FND_API.G_EXC_ERROR THEN
8752 ROLLBACK TO IO_SHIP_UPDATE;
8753 x_return_status := FND_API.G_RET_STS_ERROR ;
8754 FND_MSG_PUB.Count_And_Get
8755 (p_count => x_msg_count,
8756 p_data => x_msg_data );
8757 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8758 ROLLBACK TO IO_SHIP_UPDATE;
8759 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
8760 FND_MSG_PUB.Count_And_Get
8761 ( p_count => x_msg_count,
8762 p_data => x_msg_data );
8763 WHEN OTHERS THEN
8764 ROLLBACK TO IO_SHIP_UPDATE;
8765 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
8766 IF FND_MSG_PUB.Check_Msg_Level
8767 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
8768 THEN
8769 FND_MSG_PUB.Add_Exc_Msg
8770 (G_PKG_NAME ,
8771 l_api_name );
8772 END IF;
8773 FND_MSG_PUB.Count_And_Get
8774 (p_count => x_msg_count,
8775 p_data => x_msg_data );
8776
8777 END IO_SHIP_UPDATE;
8778
8779 /*-------------------------------------------------------------------------------------*/
8780 /* Procedure name: WIP_UPDATE */
8781 /* Description : Procedure called from the UI to update the depot tables */
8782 /* for the WIP Job creation/Completion */
8783 /* */
8784 /* Called from : Called from Depot Repair UI */
8785 /* STANDARD PARAMETERS */
8786 /* In Parameters : */
8787 /* p_api_version NUMBER Required Api Version number */
8788 /* p_init_msg_list VARCHAR2 Optional To Initialize message stack */
8789 /* p_commit VARCHAR2 Optional Commits in API */
8790 /* p_validation_level NUMBER Optional validation level */
8791 /* */
8792 /* Output Parameters: */
8793 /* x_return_status VARCHAR2 Return status of the API */
8794 /* x_msg_count NUMBER Number of messages in stack */
8795 /* x_msg_data VARCHAR2 Error Message from message stack */
8796 /* */
8797 /* NON-STANDARD PARAMETERS */
8798 /* In Parameters */
8799 /* p_upd_job_completion Required Order Type; Possible values -'Y','N' */
8800 /* p_repair_line_id NUMBER Optional Repair Order Line Id */
8801 /* Output Parm : */
8802 /* Change Hist : */
8803 /* 09/20/03 vlakaman Initial Creation. */
8804 /*-------------------------------------------------------------------------------------*/
8805
8806 Procedure WIP_UPDATE
8807 ( p_api_version IN NUMBER,
8808 p_commit IN VARCHAR2,
8809 p_init_msg_list IN VARCHAR2,
8810 p_validation_level IN NUMBER,
8811 x_return_status OUT NOCOPY VARCHAR2,
8812 x_msg_count OUT NOCOPY NUMBER,
8813 x_msg_data OUT NOCOPY VARCHAR2,
8814 p_upd_job_completion IN VARCHAR2,
8815 p_repair_line_id IN NUMBER
8816 ) IS
8817
8818 -- Standard Variables
8819 l_api_name CONSTANT VARCHAR2(30) := 'WIP_UPDATE';
8820 l_api_version CONSTANT NUMBER := 1.0;
8821
8822 -- Variables used in the program
8823 l_dummy varchar2(30);
8824
8825 -- Variables used for FND log
8826 l_error_level number := FND_LOG.LEVEL_ERROR;
8827 l_mod_name varchar2(2000) := 'csd.plsql.csd_update_programs_pvt.wip_update';
8828
8829 BEGIN
8830 -- Standard Start of API savepoint
8831 SAVEPOINT WIP_UPDATE;
8832
8833 -- Initialize API return status to success
8834 x_return_status := FND_API.G_RET_STS_SUCCESS;
8835
8836 -- Debug Messages
8837 Debug('At the Beginning of Wip_update ',l_mod_name,1);
8838 Debug('Repair Line Id ='||p_repair_line_id,l_mod_name,1);
8839
8840 -- Standard call to check for call compatibility.
8841 IF NOT FND_API.Compatible_API_Call (l_api_version,
8842 p_api_version,
8843 l_api_name ,
8844 G_PKG_NAME )
8845 THEN
8846 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8847 END IF;
8848
8849 -- Initialize message list if p_init_msg_list is set to TRUE.
8850 IF FND_API.to_Boolean( p_init_msg_list ) THEN
8851 FND_MSG_PUB.initialize;
8852 END IF;
8853
8854 -- Api body starts
8855
8856 -- Validate the repair line id
8857 IF p_repair_line_id is not null THEN
8858 IF NOT(csd_process_util.validate_rep_line_id(p_repair_line_id)) THEN
8859 Debug('Validate_rep_line_id failed',l_mod_name,1);
8860 RAISE FND_API.G_EXC_ERROR;
8861 END IF;
8862 END IF;
8863
8864 -- Debug messages
8865 Debug('Calling JOB_CREATION_UPDATE',l_mod_name,2);
8866
8867 JOB_CREATION_UPDATE
8868 ( p_api_version => p_api_version,
8869 p_commit => p_commit,
8870 p_init_msg_list => p_init_msg_list,
8871 p_validation_level => p_validation_level,
8872 x_return_status => x_return_status,
8873 x_msg_count => x_msg_count,
8874 x_msg_data => x_msg_data ,
8875 p_repair_line_id => p_repair_line_id);
8876
8877 -- Debug messages
8878 Debug('Return Status from JOB_CREATION_UPDATE :'||x_return_status,l_mod_name,2);
8879
8880 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
8881 -- Debug messages
8882 Debug(' JOB_CREATION_UPDATE failed ',l_mod_name,4);
8883 RAISE FND_API.G_EXC_ERROR;
8884 END IF;
8885
8886 IF NVL(p_upd_job_completion,'Y') = 'Y' THEN
8887 -- Only if the update_job_completion is 'Y', then
8888 -- call the completion update api
8889
8890 -- Debug messages
8891 Debug('Calling JOB_COMPLETION_UPDATE',l_mod_name,2);
8892
8893 JOB_COMPLETION_UPDATE
8894 ( p_api_version => p_api_version,
8895 p_commit => p_commit,
8896 p_init_msg_list => p_init_msg_list,
8897 p_validation_level => p_validation_level,
8898 x_return_status => x_return_status,
8899 x_msg_count => x_msg_count,
8900 x_msg_data => x_msg_data ,
8901 p_repair_line_id => p_repair_line_id);
8902
8903 -- Debug messages
8904 Debug('Return Status from JOB_COMPLETION_UPDATE :'||x_return_status,l_mod_name,2);
8905
8906 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
8907 -- Debug messages
8908 Debug(' JOB_COMPLETION_UPDATE failed ',l_mod_name,4);
8909 RAISE FND_API.G_EXC_ERROR;
8910 END IF;
8911 END IF;
8912
8913 -- Standard check of p_commit.
8914 IF FND_API.To_Boolean( p_commit ) THEN
8915 COMMIT WORK;
8916 END IF;
8917
8918 -- Standard call to get message count and IF count is get message info.
8919 FND_MSG_PUB.Count_And_Get
8920 (p_count => x_msg_count,
8921 p_data => x_msg_data);
8922 EXCEPTION
8923 WHEN FND_API.G_EXC_ERROR THEN
8924 Debug('In FND_API.G_EXC_ERROR Exception',l_mod_name,4);
8925 -- As we commit the processed records in the inner APIs
8926 -- so we rollback only if the p_commit = 'F'
8927 IF NOT(FND_API.To_Boolean( p_commit )) THEN
8928 ROLLBACK TO WIP_UPDATE;
8929 END IF;
8930 x_return_status := FND_API.G_RET_STS_ERROR ;
8931 FND_MSG_PUB.Count_And_Get
8932 (p_count => x_msg_count,
8933 p_data => x_msg_data );
8934 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8935 Debug('In FND_API.G_EXC_UNEXPECTED_ERROR Exception',l_mod_name,4);
8936 IF ( l_error_level >= G_debug_level) THEN
8937 fnd_message.set_name('CSD','CSD_SQL_ERROR');
8938 fnd_message.set_token('SQLERRM',SQLERRM);
8939 fnd_message.set_token('SQLCODE',SQLCODE);
8940 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
8941 END If;
8942 -- As we commit the processed records in the inner APIs
8943 -- so we rollback only if the p_commit = 'F'
8944 IF NOT(FND_API.To_Boolean( p_commit )) THEN
8945 ROLLBACK TO WIP_UPDATE;
8946 END IF;
8947 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
8948 FND_MSG_PUB.Count_And_Get
8949 ( p_count => x_msg_count,
8950 p_data => x_msg_data );
8951 WHEN OTHERS THEN
8952 Debug('In OTHERS Exception',l_mod_name,4);
8953 IF ( l_error_level >= G_debug_level) THEN
8954 fnd_message.set_name('CSD','CSD_SQL_ERROR');
8955 fnd_message.set_token('SQLERRM',SQLERRM);
8956 fnd_message.set_token('SQLCODE',SQLCODE);
8957 FND_LOG.MESSAGE(l_error_level,l_mod_name,FALSE);
8958 END If;
8959 -- As we commit the processed records in the inner APIs
8960 -- so we rollback only if the p_commit = 'F'
8961 IF NOT(FND_API.To_Boolean( p_commit )) THEN
8962 ROLLBACK TO WIP_UPDATE;
8963 END IF;
8964 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
8965 IF FND_MSG_PUB.Check_Msg_Level
8966 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
8967 THEN
8968 FND_MSG_PUB.Add_Exc_Msg
8969 (G_PKG_NAME ,
8970 l_api_name );
8971 END IF;
8972 FND_MSG_PUB.Count_And_Get
8973 (p_count => x_msg_count,
8974 p_data => x_msg_data );
8975 End WIP_UPDATE;
8976
8977 /*-------------------------------------------------------------------------------------*/
8978 /* Procedure name: RECEIPTS_UPDATE_CONC_PROG */
8979 /* Description : Procedure called by concurrent program to update the depot tables */
8980 /* for the receipts against RMA/Internal Requisitions */
8981 /* */
8982 /* Called from : Called from Receipt update concurrent program */
8983 /* STANDARD PARAMETERS */
8984 /* In Parameters : */
8985 /* */
8986 /* Output Parameters: */
8987 /* errbuf VARCHAR2 Error message */
8988 /* retcode VARCHAR2 Error Code */
8989 /* */
8990 /* NON-STANDARD PARAMETERS */
8991 /* In Parameters */
8992 /* p_order_type VARCHAR2 Required Order Type; Possible values- 'I','E' */
8993 /* p_order_header_id NUMBER Optional Internal sales Order Id */
8994 /* p_repair_line_id NUMBER Optional Repair Order Line Id */
8995 /* Output Parm : */
8996 /* Change Hist : */
8997 /* 09/20/03 vlakaman Initial Creation. */
8998 /*-------------------------------------------------------------------------------------*/
8999
9000 Procedure RECEIPTS_UPDATE_CONC_PROG
9001 (errbuf OUT NOCOPY varchar2,
9002 retcode OUT NOCOPY varchar2,
9003 p_order_type IN varchar2,
9004 p_order_header_id IN number,
9005 p_repair_line_id IN number,
9006 p_past_num_of_days IN NUMBER DEFAULT NULL) ----bug#6753684, 6742512
9007 IS
9008
9009 --Standard Variables
9010 l_api_name CONSTANT VARCHAR2(30) := 'RECEIPTS_UPDATE_CONC_PROG';
9011 l_api_version CONSTANT NUMBER := 1.0;
9012
9013 -- Variable used in the API
9014 l_internal_order_flag VARCHAR2(1);
9015
9016 -- Concurrent Program return status
9017 l_success_status CONSTANT VARCHAR2(1) := '0';
9018 l_warning_status CONSTANT VARCHAR2(1) := '1';
9019 l_error_status CONSTANT VARCHAR2(1) := '2';
9020
9021 -- Variables used in the program
9022 l_return_status VARCHAR2(30);
9023 l_msg_count NUMBER;
9024 l_msg_data VARCHAR2(30000); --bug#8261344
9025 l_msg_text VARCHAR2(2000); -- swai: bug 12547701
9026
9027 -- Variables for FND Log
9028 l_error_level number := FND_LOG.LEVEL_ERROR;
9029 l_mod_name varchar2(2000) := 'csd.plsql.csd_update_programs_pvt.receipts_update_conc_prog';
9030
9031 BEGIN
9032 -- Initialize API return status to success
9033 l_return_status := FND_API.G_RET_STS_SUCCESS;
9034
9035 -- Initialize the error code and error buffer
9036 retcode := l_success_status;
9037 errbuf := '';
9038
9039 -- Debug messages
9040 Debug('At the Beginning of receipts_update_conc_prog',l_mod_name,1);
9041
9042 IF NVL(p_order_type,'E') = 'I' THEN
9043 l_internal_order_flag := 'Y';
9044 Else
9045 l_internal_order_flag := 'N';
9046 End if;
9047
9048 -- Debug messages
9049 Debug('Calling RECEIPTS_UPDATE',l_mod_name,2);
9050
9051 -- Api body starts
9052 RECEIPTS_UPDATE
9053 ( p_api_version => l_api_version,
9054 p_commit => FND_API.G_TRUE,
9055 p_init_msg_list => FND_API.G_TRUE,
9056 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
9057 x_return_status => l_return_status,
9058 x_msg_count => l_msg_count,
9059 x_msg_data => l_msg_data,
9060 p_internal_order_flag => l_internal_order_flag,
9061 p_order_header_id => p_order_header_id,
9062 p_repair_line_id => p_repair_line_id,
9063 p_past_num_of_days => p_past_num_of_days);
9064
9065 -- Debug messages
9066 Debug('Return Status from RECEIPTS_UPDATE :'||l_return_status,l_mod_name,2);
9067
9068 Debug('p_repair_line_id :'||p_repair_line_id,l_mod_name,2);
9069 Debug('profile value :'||NVL(fnd_profile.value('CSD_LOGISTICS_PROGRAM_ERROR'), 'S'),l_mod_name,2);
9070
9071 -- swai: bug 12547701
9072 -- Regardless of success/warning/failure,
9073 -- Write the messages in the message stack to both log and output files
9074 -- Also concatenate the messages to l_msg_data
9075 IF l_msg_count > 1 then
9076 FOR i IN 1..l_msg_count LOOP
9077 l_msg_text := FND_MSG_PUB.Get(i,FND_API.G_FALSE);
9078 fnd_file.put_line(fnd_file.log,l_msg_text);
9079 fnd_file.put_line(fnd_file.output,l_msg_text);
9080 l_msg_data := l_msg_data||l_msg_text;
9081 END LOOP ;
9082 END IF ;
9083
9084 --bug#8261344
9085 -- swai: bug 12547701 added new if clause
9086 If ((l_return_status = G_CSD_RET_STS_WARNING) AND
9087 (NVL(fnd_profile.value('CSD_LOGISTICS_PROGRAM_ERROR'), 'S') = 'I')) THEN
9088 retcode := l_success_status; -- return success since we are ignoring warnings
9089 errbuf := l_msg_data; -- but show the messages in the log
9090 ELSIF ((l_return_status = G_CSD_RET_STS_WARNING) AND
9091 (NVL(fnd_profile.value('CSD_LOGISTICS_PROGRAM_ERROR'), 'S') = 'A')) THEN
9092 retcode := l_warning_status;
9093 errbuf := l_msg_data;
9094 ElSIF NOT(l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
9095 -- swai: bug 12547701 no need to concatenate here since it was already done
9096 /*
9097 -- Concatenate the message from the message stack
9098 IF l_msg_count > 1 then
9099 FOR i IN 1..l_msg_count LOOP
9100 l_msg_data := l_msg_data||FND_MSG_PUB.Get(i,FND_API.G_FALSE) ;
9101 END LOOP ;
9102 END IF ;
9103 */
9104
9105 Debug(l_msg_data,l_mod_name,4);
9106 RAISE FND_API.G_EXC_ERROR;
9107 END IF;
9108
9109 Exception
9110 WHEN FND_API.G_EXC_ERROR THEN
9111 retcode := l_error_status;
9112 errbuf := l_msg_data;
9113 WHEN Others then
9114 -- Handle others exception
9115 retcode := l_error_status;
9116 errbuf := l_msg_data;
9117 END RECEIPTS_UPDATE_CONC_PROG;
9118
9119 /*-------------------------------------------------------------------------------------*/
9120 /* Procedure name: WIP_UPDATE_CONC_PROG */
9121 /* Description : Procedure called by concurrent program to update the depot tables */
9122 /* for the WIP Job Creation/ Completion */
9123 /* */
9124 /* Called from : Called from Wip Update Concurrent Program */
9125 /* STANDARD PARAMETERS */
9126 /* In Parameters : */
9127 /* */
9128 /* Output Parameters: */
9129 /* errbuf VARCHAR2 Error message */
9130 /* retcode VARCHAR2 Error Code */
9131 /* */
9132 /* NON-STANDARD PARAMETERS */
9133 /* In Parameters */
9134 /* p_upd_job_completion Required Order Type; Possible values -'Y','N' */
9135 /* p_repair_line_id NUMBER Optional Repair Order Line Id */
9136 /* Output Parm : */
9137 /* Change Hist : */
9138 /* 09/20/03 vlakaman Initial Creation. */
9139 /*-------------------------------------------------------------------------------------*/
9140
9141 Procedure WIP_UPDATE_CONC_PROG
9142 (errbuf OUT NOCOPY varchar2,
9143 retcode OUT NOCOPY varchar2,
9144 p_repair_line_id IN number,
9145 p_upd_job_completion IN varchar2) IS
9146
9147 -- Standard variables
9148 l_api_name CONSTANT VARCHAR2(30) := 'WIP_UPDATE_CONC_PROG';
9149 l_api_version CONSTANT NUMBER := 1.0;
9150
9151 -- Variables used in the program
9152 l_return_status VARCHAR2(30);
9153 l_msg_count NUMBER;
9154 l_msg_data VARCHAR2(20000);
9155
9156 -- Concurrent Program return status
9157 l_success_status CONSTANT VARCHAR2(1) := '0';
9158 l_warning_status CONSTANT VARCHAR2(1) := '1';
9159 l_error_status CONSTANT VARCHAR2(1) := '2';
9160
9161 -- Variables for FND log
9162 l_error_level number := FND_LOG.LEVEL_ERROR;
9163 l_mod_name varchar2(2000) := 'csd.plsql.csd_update_programs_pvt.wip_update_conc_prog';
9164
9165 BEGIN
9166 -- Initialize API return status to success
9167 l_return_status := FND_API.G_RET_STS_SUCCESS;
9168
9169 -- Initialize the error buffer and error code
9170 retcode := l_success_status;
9171 errbuf := '';
9172
9173 -- Debug Statement
9174 Debug('At the Beginning of wip_update_conc_prog',l_mod_name,1);
9175 Debug('p_repair_line_id ='||p_repair_line_id,l_mod_name,1);
9176
9177 -- Api body starts
9178 -- Debug statement
9179 Debug('Calling WIP_UPDATE',l_mod_name,2);
9180
9181 -- Call wip update api. If repair line Id is passed,
9182 -- then send the repair line Id. Else it will take all the
9183 -- unprocessed repair orders
9184 WIP_UPDATE
9185 ( p_api_version => l_api_version,
9186 p_commit => FND_API.G_TRUE,
9187 p_init_msg_list => FND_API.G_TRUE,
9188 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
9189 x_return_status => l_return_status,
9190 x_msg_count => l_msg_count,
9191 x_msg_data => l_msg_data,
9192 p_upd_job_completion => p_upd_job_completion,
9193 p_repair_line_id => p_repair_line_id);
9194
9195 -- Debug statement
9196 Debug('Return Status from WIP_UPDATE :'||l_return_status,l_mod_name,2);
9197
9198 -- Raise error message if the API returns status <> 'S'
9199 IF NOT(l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
9200 IF l_msg_count > 1 then
9201 FOR i IN 1..l_msg_count LOOP
9202 l_msg_data := l_msg_data||FND_MSG_PUB.Get(i,FND_API.G_FALSE) ;
9203 END LOOP ;
9204 END IF ;
9205 Debug(l_msg_data,l_mod_name,4);
9206 RAISE FND_API.G_EXC_ERROR;
9207 END IF;
9208
9209 Exception
9210 WHEN FND_API.G_EXC_ERROR THEN
9211 retcode := l_error_status;
9212 errbuf := l_msg_data;
9213 WHEN Others then
9214 -- Handle others exception
9215 retcode := l_error_status;
9216 errbuf := l_msg_data;
9217 END WIP_UPDATE_CONC_PROG;
9218
9219 /*-------------------------------------------------------------------------------------*/
9220 /* Procedure name: SHIP_UPDATE_CONC_PROG */
9221 /* Description: Procedure called by concurrent program to update the depot tables */
9222 /* for the shipment against Sales order/Internal Sales Order */
9223 /* */
9224 /* Called from : Called from Receipt update concurrent program */
9225 /* STANDARD PARAMETERS */
9226 /* In Parameters : */
9227 /* */
9228 /* Output Parameters: */
9229 /* errbuf VARCHAR2 Error message */
9230 /* retcode VARCHAR2 Eeror Code */
9231 /* */
9232 /* NON-STANDARD PARAMETERS */
9233 /* In Parameters */
9234 /* p_order_type VARCHAR2 Required Order Type; Possible values- 'I','E' */
9235 /* p_order_header_id NUMBER Optional Internal sales Order Id */
9236 /* p_repair_line_id NUMBER Optional Repair Order Line Id */
9237 /* Output Parm : */
9238 /* Change Hist : */
9239 /* 09/20/03 vlakaman Initial Creation. */
9240 /*-------------------------------------------------------------------------------------*/
9241
9242 PROCEDURE SHIP_UPDATE_CONC_PROG
9243 (errbuf OUT NOCOPY VARCHAR2,
9244 retcode OUT NOCOPY VARCHAR2,
9245 p_order_type IN VARCHAR2,
9246 p_order_header_id IN NUMBER,
9247 p_repair_line_id IN NUMBER,
9248 p_past_num_of_days IN NUMBER DEFAULT NULL) ----bug#6753684, 6742512
9249 IS
9250
9251 -- Standard Variables
9252 l_api_version CONSTANT NUMBER := 1.0;
9253 l_return_status varchar2(1);
9254 l_msg_count number;
9255 l_msg_data varchar2(30000); --bug#8261344
9256 l_msg_text VARCHAR2(2000); -- swai: bug 12547701
9257
9258 -- Variables used in API
9259 l_internal_order_flag varchar2(1);
9260
9261 -- Concurrent Program return status
9262 l_success_status CONSTANT VARCHAR2(1) := '0';
9263 l_warning_status CONSTANT VARCHAR2(1) := '1';
9264 l_error_status CONSTANT VARCHAR2(1) := '2';
9265
9266 -- Variables for the FND Log
9267 l_error_level number := FND_LOG.LEVEL_ERROR;
9268 l_mod_name varchar2(2000) := 'csd.plsql.csd_update_programs_pvt.ship_update_conc_prog';
9269
9270 Begin
9271 -- Initialize API return status to success
9272 l_return_status := FND_API.G_RET_STS_SUCCESS;
9273
9274 -- Initialize the error message and error buffer
9275 retcode := l_success_status;
9276 errbuf := '';
9277
9278 -- Debug message
9279 Debug('Beginning of ship_update_conc_prog ',l_mod_name,1);
9280
9281 -- Api body starts
9282 IF NVL(p_order_type,'E') = 'I' THEN
9283 l_internal_order_flag := 'Y';
9284 Else
9285 l_internal_order_flag := 'N';
9286 End if;
9287
9288 -- Debug message
9289 Debug('Calling SHIP_UPDATE ',l_mod_name,2);
9290
9291 SHIP_UPDATE
9292 ( p_api_version => l_api_version,
9293 p_commit => FND_API.G_TRUE,
9294 p_init_msg_list => FND_API.G_TRUE,
9295 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
9296 x_return_status => l_return_status,
9297 x_msg_count => l_msg_count,
9298 x_msg_data => l_msg_data,
9299 p_internal_order_flag => l_internal_order_flag,
9300 p_order_header_id => p_order_header_id,
9301 p_repair_line_id => p_repair_line_id,
9302 p_past_num_of_days => p_past_num_of_days);
9303
9304 -- Debug message
9305 Debug('Return Status from SHIP_UPDATE :'||l_return_status,l_mod_name,2);
9306
9307 -- swai: bug 12547701
9308 -- Regardless of success/warning/failure,
9309 -- Write the messages in the message stack to both log and output files
9310 -- Also concatenate the messages to l_msg_data
9311 IF l_msg_count > 1 then
9312 FOR i IN 1..l_msg_count LOOP
9313 l_msg_text := FND_MSG_PUB.Get(i,FND_API.G_FALSE);
9314 fnd_file.put_line(fnd_file.log,l_msg_text);
9315 fnd_file.put_line(fnd_file.output,l_msg_text);
9316 l_msg_data := l_msg_data||l_msg_text;
9317 END LOOP ;
9318 END IF ;
9319
9320 --bug#8261344
9321 -- swai: bug 12547701 added new if clause
9322 If ((l_return_status = G_CSD_RET_STS_WARNING) AND
9323 (NVL(fnd_profile.value('CSD_LOGISTICS_PROGRAM_ERROR'), 'S') = 'I')) THEN
9324 retcode := l_success_status; -- return success since we are ignoring warnings
9325 errbuf := l_msg_data; -- but show the messages in the log
9326 ELSIF ((l_return_status = G_CSD_RET_STS_WARNING) AND
9327 (NVL(fnd_profile.value('CSD_LOGISTICS_PROGRAM_ERROR'), 'S') = 'A')) THEN
9328 retcode := l_warning_status;
9329 errbuf := l_msg_data;
9330 ELSIF NOT(l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
9331 -- swai: bug 12547701 no need to concatenate here since it was already done
9332 /*
9333 -- Concatenate the message from the message stack
9334 IF l_msg_count > 1 then
9335 FOR i IN 1..l_msg_count LOOP
9336 l_msg_data := l_msg_data||FND_MSG_PUB.Get(i,FND_API.G_FALSE) ;
9337 END LOOP ;
9338 END IF ;
9339 */
9340
9341 Debug(l_msg_data,l_mod_name,4);
9342 RAISE FND_API.G_EXC_ERROR ;
9343 END IF;
9344 Exception
9345 WHEN FND_API.G_EXC_ERROR THEN
9346 retcode := l_error_status;
9347 errbuf := l_msg_data;
9348 WHEN Others then
9349 -- Handle others exception
9350 retcode := l_error_status;
9351 errbuf := l_msg_data;
9352 End SHIP_UPDATE_CONC_PROG;
9353
9354
9355 /*-------------------------------------------------------------------------------------*/
9356 /* Procedure name: TASK_UPDATE_CONC_PROG */
9357 /* Description : Procedure called by concurrent program to update the depot tables */
9358 /* for the task creation and update */
9359 /* */
9360 /* */
9361 /* Called from : Called from Task Update concurrent program */
9362 /* STANDARD PARAMETERS */
9363 /* In Parameters : */
9364 /* */
9365 /* Output Parameters: */
9366 /* errbuf VARCHAR2 Error message */
9367 /* retcode VARCHAR2 Error Code */
9368 /* */
9369 /* NON-STANDARD PARAMETERS */
9370 /* In Parameters */
9371 /* p_repair_line_id NUMBER Optional Repair Order Line Id */
9372 /* Output Parm : */
9373 /* Change Hist : */
9374 /* 09/20/03 vlakaman Initial Creation. */
9375 /*-------------------------------------------------------------------------------------*/
9376
9377 PROCEDURE TASK_UPDATE_CONC_PROG
9378 ( errbuf OUT NOCOPY varchar2,
9379 retcode OUT NOCOPY varchar2,
9380 p_repair_line_id IN number ) is
9381
9382 CURSOR c_updated_tasks( p_repair_line_id in number ) is
9383 select tsk.task_id
9384 ,rep.repair_line_id
9385 --,max(hist.repair_history_id) repair_history_id
9386 from csd_repair_tasks_v tsk
9387 ,csd_repair_history hist
9388 ,csd_repairs rep
9389 where rep.repair_line_id = tsk.source_object_id
9390 and tsk.source_object_id = hist.repair_line_id
9391 and tsk.task_id = hist.paramn1
9392 and ( tsk.task_status_id <> hist.paramn5 or tsk.owner_id <> hist.paramn3)
9393 and rep.repair_line_id = nvl(p_repair_line_id, rep.repair_line_id) -- travi 181201 change
9394 group by tsk.task_id, rep.repair_line_id;
9395
9396 CURSOR c_tasks_to_updt(l_task_id number, l_repair_line_id in number, l_rep_hist_id in number) is
9397 Select tsk.task_id, -- hist.paramn1
9398 tsk.last_updated_by, -- hist.paramn2
9399 tsk.owner_id, -- hist.paramn3
9400 tsk.assigned_by_id, -- hist.paramn4
9401 tsk.task_status_id, -- hist.paramn5
9402 tsk.task_number, -- hist.paramc1
9403 tsk.owner_type, -- hist.paramc2
9404 tsk.owner, -- hist.paramc3
9405 null assignee_type, -- hist.paramc4
9406 null assignee_name, -- hist.paramc5
9407 tsk.task_status, -- hist.paramc6
9408 tsk.planned_start_date, -- hist.paramd1
9409 tsk.actual_start_date, -- hist.paramd2
9410 tsk.actual_end_date, -- hist.paramd3
9411 tsk.last_update_date, -- hist.paramd4
9412 hist.paramc3, -- tsk.owner
9413 hist.paramc6 -- tsk.task_status
9414 from CSD_REPAIR_TASKS_V tsk
9415 ,csd_repair_history hist
9416 where tsk.source_object_type_code = 'DR'
9417 and tsk.task_id = l_task_id
9418 and tsk.source_object_id = l_repair_line_id
9419 and hist.repair_history_id = l_rep_hist_id
9420 and hist.paramn1 = tsk.task_id
9421 and hist.repair_line_id = tsk.source_object_id
9422 and (tsk.task_status_id <> hist.paramn5 or tsk.owner_id <> hist.paramn3);
9423
9424 -- Standard Variables
9425 l_api_name CONSTANT VARCHAR2(30) := 'VALIDATE_AND_WRITE';
9426 l_api_version CONSTANT NUMBER := 1.0;
9427 l_msg_count NUMBER;
9428 l_msg_data VARCHAR2(2000);
9429 l_msg_index NUMBER;
9430 x_return_status VARCHAR2(1);
9431 x_msg_count NUMBER;
9432 x_msg_data VARCHAR2(2000);
9433
9434 -- Variables used in program
9435 l_return_status VARCHAR2(1);
9436 l_repair_history_id NUMBER;
9437 v_total_records number;
9438 l_event_code VARCHAR2(30) := '';
9439 l_task_id number;
9440 l_repair_line_id number;
9441 l_rep_hist_id number;
9442 l_paramn1 NUMBER;
9443 l_paramn2 NUMBER;
9444 l_paramn3 NUMBER;
9445 l_paramn4 NUMBER;
9446 l_paramn5 NUMBER;
9447 l_paramc1 VARCHAR2(240);
9448 l_paramc2 VARCHAR2(240);
9449 l_paramc3 VARCHAR2(240);
9450 l_paramc4 VARCHAR2(240);
9451 l_paramc5 VARCHAR2(240);
9452 l_paramc6 VARCHAR2(240);
9453 l_paramd1 DATE;
9454 l_paramd2 DATE;
9455 l_paramd3 DATE;
9456 l_paramd4 DATE;
9457 l_owner VARCHAR2(240);
9458 l_task_status VARCHAR2(240);
9459
9460 -- Variables for FND Log
9461 l_error_level number := FND_LOG.LEVEL_ERROR;
9462 l_mod_name varchar2(2000) := 'csd.plsql.csd_update_programs_pvt.task_update_conc_prog';
9463
9464 BEGIN
9465
9466 -- Initialize API return status to success
9467 x_return_status := FND_API.G_RET_STS_SUCCESS;
9468
9469 -- Initialize the error message and error buffer
9470 retcode := '0';
9471 errbuf := '';
9472
9473 v_total_records := 0;
9474
9475 -- travi added p_repair_line_id
9476 FOR R in c_updated_tasks( p_repair_line_id )
9477 loop
9478
9479 l_event_code := '';
9480 l_task_id := '';
9481 l_repair_line_id := '';
9482 l_rep_hist_id := '';
9483 l_paramn1 := ''; -- task id
9484 l_paramn2 := ''; -- last updated by
9485 l_paramn3 := ''; -- owner id
9486 l_paramn4 := ''; -- assigned by id
9487 l_paramn5 := ''; -- status id
9488 l_paramc1 := ''; -- task number
9489 l_paramc2 := ''; -- owner type
9490 l_paramc3 := ''; -- owner name
9491 l_paramc4 := ''; -- null assignee type
9492 l_paramc5 := ''; -- null assignee name
9493 l_paramc6 := ''; -- status
9494 l_paramd1 := ''; -- planned start date
9495 l_paramd2 := ''; -- actual start date
9496 l_paramd3 := ''; -- actual end date
9497 l_paramd4 := ''; -- last updated date
9498 l_owner := ''; -- tsk.owner
9499 l_task_status := ''; -- tsk.task_status
9500
9501 select max(hist2.repair_history_id)
9502 into l_rep_hist_id
9503 from CSD_REPAIR_HISTORY hist2
9504 where hist2.repair_line_id = R.repair_line_id
9505 and hist2.paramn1 = R.task_id;
9506
9507 l_task_id := R.task_id;
9508 l_repair_line_id := R.repair_line_id;
9509
9510 IF (l_rep_hist_id is not null) then
9511
9512 OPEN c_tasks_to_updt(l_task_id, l_repair_line_id, l_rep_hist_id);
9513 FETCH c_tasks_to_updt
9514 INTO l_paramn1, -- task id
9515 l_paramn2, -- last updated by
9516 l_paramn3, -- owner id
9517 l_paramn4, -- assigned by id
9518 l_paramn5, -- status id
9519 l_paramc1, -- task number
9520 l_paramc2, -- owner type
9521 l_paramc3, -- owner name
9522 l_paramc4, -- null assignee type
9523 l_paramc5, -- null assignee name
9524 l_paramc6, -- status
9525 l_paramd1, -- planned start date
9526 l_paramd2, -- actual start date
9527 l_paramd3, -- actual end date
9528 l_paramd4, -- last updated date
9529 l_owner, -- tsk.owner
9530 l_task_status; -- -- tsk.task_status
9531
9532 CLOSE c_tasks_to_updt;
9533
9534 if (l_task_status <> l_paramc6) then
9535 l_event_code := 'TSC';
9536 elsif (l_owner <> l_paramc3) then
9537 l_event_code := 'TOC';
9538 end if;
9539
9540 -- ---------------------------------------------------------
9541 -- Repair history row inserted for TOC or TSC only
9542 -- ---------------------------------------------------------
9543 IF (l_event_code in ('TOC', 'TSC')) then
9544
9545 -- --------------------------------
9546 -- Begin Update repair task history
9547 -- --------------------------------
9548 -- Standard Start of API savepoint
9549 SAVEPOINT Update_rep_task_hist;
9550
9551 -- ---------------
9552 -- Api body starts
9553 -- ---------------
9554 Debug('Calling Validate_And_Write ',l_mod_name,2);
9555
9556 CSD_TO_FORM_REPAIR_HISTORY.Validate_And_Write
9557 (p_Api_Version_Number => l_api_version ,
9558 p_init_msg_list => FND_API.G_FALSE,
9559 p_commit => FND_API.G_FALSE,
9560 p_validation_level => NULL,
9561 p_action_code => 0,
9562 px_REPAIR_HISTORY_ID => l_repair_history_id,
9563 p_OBJECT_VERSION_NUMBER => null, -- travi ovn validation
9564 p_REQUEST_ID => null,
9565 p_PROGRAM_ID => null,
9566 p_PROGRAM_APPLICATION_ID => null,
9567 p_PROGRAM_UPDATE_DATE => null,
9568 p_CREATED_BY => FND_GLOBAL.USER_ID,
9569 p_CREATION_DATE => sysdate,
9570 p_LAST_UPDATED_BY => FND_GLOBAL.USER_ID,
9571 p_LAST_UPDATE_DATE => sysdate,
9572 p_repair_line_id => l_repair_line_id,
9573 p_EVENT_CODE => l_event_code,
9574 p_EVENT_DATE => sysdate,
9575 p_QUANTITY => null,
9576 p_PARAMN1 => l_paramn1,
9577 p_PARAMN2 => l_paramn2,
9578 p_PARAMN3 => l_paramn3,
9579 p_PARAMN4 => l_paramn4,
9580 p_PARAMN5 => l_paramn5,
9581 p_PARAMN6 => null,
9582 p_PARAMN7 => null,
9583 p_PARAMN8 => null,
9584 p_PARAMN9 => null,
9585 p_PARAMN10 => FND_GLOBAL.USER_ID,
9586 p_PARAMC1 => l_paramc1,
9587 p_PARAMC2 => l_paramc2,
9588 p_PARAMC3 => l_paramc3,
9589 p_PARAMC4 => l_paramc4,
9590 p_PARAMC5 => l_paramc5,
9591 p_PARAMC6 => l_paramc6,
9592 p_PARAMC7 => null,
9593 p_PARAMC8 => null,
9594 p_PARAMC9 => null,
9595 p_PARAMC10 => null,
9596 p_PARAMD1 => l_paramd1,
9597 p_PARAMD2 => l_paramd1,
9598 p_PARAMD3 => l_paramd1,
9599 p_PARAMD4 => l_paramd1,
9600 p_PARAMD5 => null,
9601 p_PARAMD6 => null,
9602 p_PARAMD7 => null,
9603 p_PARAMD8 => null,
9604 p_PARAMD9 => null,
9605 p_PARAMD10 => null,
9606 p_ATTRIBUTE_CATEGORY => null,
9607 p_ATTRIBUTE1 => null,
9608 p_ATTRIBUTE2 => null,
9609 p_ATTRIBUTE3 => null,
9610 p_ATTRIBUTE4 => null,
9611 p_ATTRIBUTE5 => null,
9612 p_ATTRIBUTE6 => null,
9613 p_ATTRIBUTE7 => null,
9614 p_ATTRIBUTE8 => null,
9615 p_ATTRIBUTE9 => null,
9616 p_ATTRIBUTE10 => null,
9617 p_ATTRIBUTE11 => null,
9618 p_ATTRIBUTE12 => null,
9619 p_ATTRIBUTE13 => null,
9620 p_ATTRIBUTE14 => null,
9621 p_ATTRIBUTE15 => null,
9622 p_LAST_UPDATE_LOGIN => FND_GLOBAL.CONC_LOGIN_ID,
9623 X_Return_Status => x_return_status,
9624 X_Msg_Count => x_msg_count,
9625 X_Msg_Data => x_msg_data
9626 );
9627
9628 Debug('Return Status from Validate_And_Write :'||x_return_status,l_mod_name,2);
9629 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
9630 -- Debug messages
9631 Debug(' JOB_COMPLETION_UPDATE failed ',l_mod_name,4);
9632 RAISE FND_API.G_EXC_ERROR;
9633 END IF;
9634
9635 -- -------------------
9636 -- Api body ends here
9637 -- -------------------
9638 v_total_records := v_total_records + 1;
9639 end if; -- End of TOC/TSC check
9640
9641 end if; -- End of check for l_rep_hist_id
9642 end loop;
9643
9644 -- Standard check of p_commit.
9645 IF FND_API.To_Boolean( FND_API.G_FALSE ) THEN
9646 COMMIT WORK;
9647 END IF;
9648
9649 -- Standard call to get message count and IF count is get message info.
9650 FND_MSG_PUB.Count_And_Get
9651 (p_count => x_msg_count,
9652 p_data => x_msg_data );
9653
9654 EXCEPTION
9655 WHEN FND_API.G_EXC_ERROR THEN
9656 ROLLBACK TO Update_rep_task_hist;
9657 x_return_status := FND_API.G_RET_STS_ERROR ;
9658 FND_MSG_PUB.Count_And_Get
9659 (p_count => x_msg_count,
9660 p_data => x_msg_data );
9661 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
9662 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
9663 ROLLBACK TO Update_rep_task_hist;
9664 FND_MSG_PUB.Count_And_Get
9665 ( p_count => x_msg_count,
9666 p_data => x_msg_data );
9667 WHEN OTHERS THEN
9668 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
9669 ROLLBACK TO Update_rep_task_hist;
9670 IF FND_MSG_PUB.Check_Msg_Level
9671 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
9672 THEN
9673 FND_MSG_PUB.Add_Exc_Msg
9674 (G_PKG_NAME ,
9675 l_api_name );
9676 END IF;
9677 FND_MSG_PUB.Count_And_Get
9678 (p_count => x_msg_count,
9679 p_data => x_msg_data );
9680
9681 END TASK_UPDATE_CONC_PROG;
9682
9683
9684 /*-------------------------------------------------------------------------------------*/
9685 /* Procedure name: PROD_TXN_STATUS_UPD */
9686 /* Description : Procedure called to update all the logistics lines status to booked */
9687 /* */
9688 /* */
9689 /* Called from : csd_process_pvt and CSDREPLN.pld */
9690 /* STANDARD PARAMETERS */
9691 /* In Parameters : */
9692 /* */
9693 /* Output Parameters: */
9694 /* */
9695 /* NON-STANDARD PARAMETERS */
9696 /* In Parameters */
9697 /* p_repair_line_id NUMBER */
9698 /* p_commit VARCHAR2 */
9699 /* Output Parm : */
9700 /* Change Hist : */
9701 /* 12/20/04 mshirkol Initial Creation. Fix for bug#4020651 */
9702 /*-------------------------------------------------------------------------------------*/
9703 PROCEDURE PROD_TXN_STATUS_UPD(p_repair_line_id in number,
9704 p_commit in varchar2)
9705
9706 is
9707
9708
9709 CURSOR c_product_transaction_id(p_repair_line_id IN number) is
9710 SELECT c.product_transaction_id, a.booked_flag
9711 FROM oe_order_lines_all a,
9712 cs_estimate_details b,
9713 csd_product_transactions c
9714 WHERE a.line_id = b.order_line_id
9715 AND b.estimate_detail_id = c.estimate_detail_id
9716 and c.prod_txn_status = 'SUBMITTED'
9717 and a.booked_flag = 'Y'
9718 and c.book_sales_order_flag = 'N'
9719 and b.order_header_id in
9720 (
9721 select p.order_header_id
9722 from cs_estimate_details p, csd_product_transactions q
9723 where p.estimate_detail_id=q.estimate_detail_id
9724 and q.repair_line_id=p_repair_line_id
9725 );
9726
9727 begin
9728
9729 FOR C in c_product_transaction_id(p_repair_line_id)
9730 Loop
9731 IF C.booked_flag = 'Y' THEN
9732 UPDATE csd_product_transactions
9733 SET prod_txn_status = 'BOOKED', book_sales_order_flag = 'Y'
9734 WHERE product_transaction_id = C.product_transaction_id;
9735 END IF;
9736 end loop;
9737
9738 IF c_product_transaction_id%isopen then
9739 CLOSE c_product_transaction_id;
9740 END IF;
9741
9742 if(p_commit = FND_API.G_TRUE) THEN
9743 commit;
9744 END IF;
9745 End;
9746
9747
9748 /*-------------------------------------------------------------------------------------*/
9749 /* Procedure name: check_for_cancelled_order */
9750 /* Description : Procedure called to update all the logistics lines status to */
9751 /* cancelled if the corresponding order line is cancelled. */
9752 /* */
9753 /* */
9754 /* Called from : RMA_RCV_UPDATE, IO_RCV_UPDATE , SHIP_UPDATE, IO_SHIP_UPDATE */
9755 /* STANDARD PARAMETERS */
9756 /* In Parameters : */
9757 /* */
9758 /* Output Parameters: */
9759 /* */
9760 /* NON-STANDARD PARAMETERS */
9761 /* In Parameters */
9762 /* p_repair_line_id NUMBER */
9763 /* Output Parm : */
9764 /* Change Hist : */
9765 /* 30/June/2005 vparvath Initial Creation. */
9766 /*-------------------------------------------------------------------------------------*/
9767 PROCEDURE check_for_cancelled_order(p_repair_line_id NUMBER) IS
9768
9769 CURSOR CANCELLED_ORDER_LINES(p_repair_line_id NUMBER) IS
9770 SELECT DISTINCT cpt.product_transaction_id PRODUCT_TXN_ID
9771 FROM oe_order_headers_all oeh,
9772 oe_order_lines_all oel,
9773 cs_estimate_details ced,
9774 csd_product_transactions cpt
9775 WHERE cpt.repair_line_id = p_repair_line_id
9776 AND cpt.action_type in ('RMA', 'SHIP', 'RMA_THIRD_PTY', 'SHIP_THIRD_PTY')
9777 AND cpt.prod_txn_status in ( 'BOOKED', 'SUBMITTED')
9778 AND ced.order_header_id is not null
9779 AND ced.source_code = 'DR'
9780 AND ced.estimate_detail_id = cpt.estimate_detail_id
9781 AND oeh.header_id = ced.order_header_id
9782 AND oel.header_id = oeh.header_id
9783 and ced.order_line_id = oel.line_id
9784 /*fixed for bug#5846050 only cancelled line should be updated not all the lines */
9785 --AND oel.cancelled_flag = 'Y'
9786 AND oel.ordered_quantity = 0 -- indicates the order line is cancelled.
9787 ; -- skip partial ship/receive case, current behavour is
9788 -- if the original line is cancelled the product transaction
9789 -- will show as cancelled.
9790 /***
9791 AND ((ced.QUANTITY_REQUIRED < -1
9792 AND oel.line_id in ( Select line_id
9793 from oe_order_lines_all oel1
9794 start with oel1.line_id = ced.order_line_id
9795 connect by prior oel1.line_id = oel1.split_from_line_id
9796 and oel1.shipped_quantity is not null
9797 and oel1.header_id = oeh.header_id))
9798 OR (ced.QUANTITY_REQUIRED = -1
9799 AND ced.ORDER_LINE_ID = oel.LINE_ID));
9800 **********/
9801
9802 l_product_txn_id NUMBER;
9803 C_PRODTXN_CANCELLED VARCHAR2(30) := 'CANCELLED';
9804
9805 BEGIN
9806
9807 FOR ORD_LINES IN CANCELLED_ORDER_LINES( p_repair_line_id) LOOP
9808 l_product_txn_id := ORD_LINES.PRODUCT_TXN_ID;
9809 BEGIN
9810 UPDATE CSD_PRODUCT_TRANSACTIONS
9811 SET PROD_TXN_STATUS = C_PRODTXN_CANCELLED,
9812 LAST_UPDATE_DATE = SYSDATE,
9813 LAST_UPDATE_LOGIN = FND_GLOBAL.LOGIN_ID,
9814 LAST_UPDATED_BY = FND_GLOBAL.USER_ID
9815 WHERE PRODUCT_TRANSACTION_ID = l_product_txn_id;
9816 EXCEPTION
9817 WHEN OTHERS THEN
9818 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9819 END;
9820 END LOOP;
9821
9822 END check_for_cancelled_order;
9823
9824
9825 /*-------------------------------------------------------------------------------------*/
9826 /* Procedure name: UPDATE_LOGISTIC_STATUS_WF */
9827 /* Description : Procedure called from workflow process to update logistics */
9828 /* line status */
9829 /* */
9830 /* Called from : Workflow */
9831 /* PARAMETERS */
9832 /* IN */
9833 /* */
9834 /* itemtype - type of the current item */
9835 /* itemkey - key of the current item */
9836 /* actid - process activity instance id */
9837 /* funcmode - function execution mode ('RUN', 'CANCEL', 'TIMEOUT', ...) */
9838 /* OUT */
9839 /* result */
9840 /* - COMPLETE[:<result>] */
9841 /* activity has completed with the indicated result */
9842 /* - WAITING */
9843 /* activity is waiting for additional transitions */
9844 /* - DEFERED */
9845 /* execution should be defered to background */
9846 /* - NOTIFIED[:<notification_id>:<assigned_user>] */
9847 /* activity has notified an external entity that this */
9848 /* step must be performed. A call to wf_engine.CompleteActivty */
9849 /* will signal when this step is complete. Optional */
9850 /* return of notification ID and assigned user. */
9851 /* - ERROR[:<error_code>] */
9852 /* function encountered an error. */
9853 /* Change Hist : */
9854 /* 04/18/06 mshirkol Initial Creation. ( Fix for bug#5610891 ) */
9855 /*-------------------------------------------------------------------------------------*/
9856
9857 Procedure UPDATE_LOGISTIC_STATUS_WF
9858 (itemtype in varchar2,
9859 itemkey in varchar2,
9860 actid in number,
9861 funcmode in varchar2,
9862 resultout in out nocopy varchar2) IS
9863
9864 l_line_id number;
9865 l_orig_source_code varchar2(10);
9866 l_orig_source_id number;
9867 l_line_category_code varchar2(30);
9868 l_order_header_id number;
9869 l_return_status varchar2(3);
9870 l_msg_count number;
9871 l_msg_data varchar2(2000);
9872 l_msg_index_out number;
9873 l_module_name varchar2(30);
9874
9875
9876 Cursor get_est_line_details ( p_line_id in number ) is
9877 select
9878 est.original_source_code,
9879 est.original_source_id,
9880 est.line_category_code,
9881 est.order_header_id
9882 from
9883 cs_estimate_details est
9884 where
9885 est.order_line_id = p_line_id;
9886
9887 BEGIN
9888
9889 IF ( funcmode = 'RUN' ) THEN
9890
9891 l_line_id := to_number(itemkey);
9892
9893 --
9894 -- Derive the wf roles for the Contact id
9895 --
9896 Open get_est_line_details (l_line_id);
9897 Fetch get_est_line_details into l_orig_source_code,
9898 l_orig_source_id,l_line_category_code,l_order_header_id;
9899 Close get_est_line_details;
9900
9901 IF ( l_orig_source_code = 'DR' ) THEN
9902
9903 IF ( l_line_category_code = 'RETURN') THEN
9904
9905 l_module_name := 'LOGISTICS_RECEIPTS_UPDATE';
9906
9907 CSD_UPDATE_PROGRAMS_PVT.RECEIPTS_UPDATE
9908 ( p_api_version => 1.0,
9909 p_commit => 'T',
9910 p_init_msg_list => 'T',
9911 p_validation_level => CSD_PROCESS_UTIL.G_VALID_LEVEL_FULL,
9912 x_return_status => l_return_status,
9913 x_msg_count => l_msg_count,
9914 x_msg_data => l_msg_data,
9915 p_internal_order_flag => 'N',
9916 p_order_header_id => null,
9917 p_repair_line_id => l_orig_source_id);
9918
9919 IF NOT(l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
9920 resultout := 'COMPLETE:ERROR';
9921 ELSE
9922 resultout := 'COMPLETE:SUCCESS';
9923 END IF;
9924
9925 ELSIF ( l_line_category_code = 'ORDER') THEN
9926
9927 l_module_name := 'LOGISTICS_SHIP_UPDATE';
9928
9929 CSD_UPDATE_PROGRAMS_PVT.SHIP_UPDATE
9930 ( p_api_version => 1.0,
9931 p_commit => 'T',
9932 p_init_msg_list => 'T',
9933 p_validation_level => CSD_PROCESS_UTIL.G_VALID_LEVEL_FULL,
9934 x_return_status => l_return_status,
9935 x_msg_count => l_msg_count,
9936 x_msg_data => l_msg_data,
9937 p_internal_order_flag => 'N' ,
9938 p_order_header_id => null,
9939 p_repair_line_id => l_orig_source_id);
9940
9941 IF NOT(l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
9942 resultout := 'COMPLETE:ERROR';
9943 ELSE
9944 resultout := 'COMPLETE:SUCCESS';
9945 END IF;
9946
9947 END IF;
9948
9949 -- If the return status is error then raise
9950 -- the Business Event
9951 IF NOT(l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
9952
9953 CSD_REPAIRS_PVT.LAUNCH_WFEXCEPTION_BEVENT(
9954 p_return_status => l_return_status,
9955 p_msg_count => l_msg_count,
9956 p_msg_data => l_msg_data,
9957 p_repair_line_id => l_orig_source_id,
9958 p_module_name => l_module_name);
9959
9960 END IF;
9961
9962 END IF;
9963
9964 return;
9965
9966 END IF;
9967
9968
9969
9970 EXCEPTION
9971 WHEN OTHERS THEN
9972 WF_CORE.CONTEXT('CSD_UPDATE_PROGRAMS_PVT','UPDATE_LOGISTICS_WF',itemtype,
9973 itemkey,to_char(actid),funcmode);
9974 raise;
9975 END;
9976
9977 END CSD_UPDATE_PROGRAMS_PVT;