[Home] [Help]
PACKAGE BODY: APPS.CSD_PROCESS_PVT
Source
1 Package BODY Csd_Process_Pvt AS
2 /* $Header: csdvintb.pls 120.52.12020000.6 2013/04/14 02:06:35 takwong ship $ */
3
4 -- ---------------------------------------------------------
5 -- Define global variables
6 -- ---------------------------------------------------------
7
8 G_PKG_NAME CONSTANT VARCHAR2(30) := 'CSD_PROCESS_PVT';
9 G_FILE_NAME CONSTANT VARCHAR2(12) := 'csdvintb.pls';
10 g_debug NUMBER := Csd_Gen_Utility_Pvt.g_debug_level;
11
12 /* R12 Srl reservation changes, begin */
13 C_RESERVABLE CONSTANT NUMBER := 1;
14 C_SERIAL_CONTROL_AT_RECEIPT CONSTANT NUMBER := 5;
15 C_SERIAL_CONTROL_PREDEFINED CONSTANT NUMBER := 2;
16 /* R12 Srl reservation changes, end */
17
18
19 -- Global variable for storing the debug level
20 G_debug_level NUMBER := Fnd_Log.G_CURRENT_RUNTIME_LEVEL;
21
22 /*-------------------------------------------------------------------------------------*/
23 /* Function name: DEBUG */
24 /* Description : Logs the debug message */
25 /* Called from : Called from Update API */
26 /* */
27 /* STANDARD PARAMETERS */
28 /* In Parameters : */
29 /* p_message Required Debug message that needs to be logged */
30 /* p_mod_name Required Module name */
31 /* p_severity_level Required Severity level */
32 /* Output Parameters: */
33 /* NON-STANDARD PARAMETERS */
34 /* In Parameters */
35 /* Out parameters */
36 /* Change Hist : */
37 /* 09/20/03 vlakaman Initial Creation. */
38 /*-------------------------------------------------------------------------------------*/
39
40 PROCEDURE DEBUG(p_message IN VARCHAR2,
41 p_mod_name IN VARCHAR2,
42 p_severity_level IN NUMBER) IS
43
44 -- Variables used in FND Log
45 l_stat_level NUMBER := Fnd_Log.LEVEL_STATEMENT;
46 l_proc_level NUMBER := Fnd_Log.LEVEL_PROCEDURE;
47 l_event_level NUMBER := Fnd_Log.LEVEL_EVENT;
48 l_excep_level NUMBER := Fnd_Log.LEVEL_EXCEPTION;
49 l_error_level NUMBER := Fnd_Log.LEVEL_ERROR;
50 l_unexp_level NUMBER := Fnd_Log.LEVEL_UNEXPECTED;
51
52 BEGIN
53
54 IF p_severity_level = 1
55 THEN
56 IF (l_stat_level >= G_debug_level)
57 THEN
58 Fnd_Log.STRING(l_stat_level, p_mod_name, p_message);
59 END IF;
60 ELSIF p_severity_level = 2
61 THEN
62 IF (l_proc_level >= G_debug_level)
63 THEN
64 Fnd_Log.STRING(l_proc_level, p_mod_name, p_message);
65 END IF;
66 ELSIF p_severity_level = 3
67 THEN
68 IF (l_event_level >= G_debug_level)
69 THEN
70 Fnd_Log.STRING(l_event_level, p_mod_name, p_message);
71 END IF;
72 ELSIF p_severity_level = 4
73 THEN
74 IF (l_excep_level >= G_debug_level)
75 THEN
76 Fnd_Log.STRING(l_excep_level, p_mod_name, p_message);
77 END IF;
78 ELSIF p_severity_level = 5
79 THEN
80 IF (l_error_level >= G_debug_level)
81 THEN
82 Fnd_Log.STRING(l_error_level, p_mod_name, p_message);
83 END IF;
84 ELSIF p_severity_level = 6
85 THEN
86 IF (l_unexp_level >= G_debug_level)
87 THEN
88 Fnd_Log.STRING(l_unexp_level, p_mod_name, p_message);
89 END IF;
90 END IF;
91
92 Csd_Gen_Utility_Pvt.add(p_message);
93
94 END DEBUG;
95 /*--------------------------------------------------*/
96 /* procedure name: process_service_request */
97 /* description : procedure used to create */
98 /* service requests */
99 /*--------------------------------------------------*/
100
101 PROCEDURE process_service_request(p_api_version IN NUMBER,
102 p_commit IN VARCHAR2 := Fnd_Api.g_false,
103 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_false,
104 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
105 p_action IN VARCHAR2,
106 p_incident_id IN NUMBER := NULL,
107 p_service_request_rec IN Csd_Process_Pvt.SERVICE_REQUEST_REC,
108 x_incident_id OUT NOCOPY NUMBER,
109 x_incident_number OUT NOCOPY VARCHAR2,
110 x_return_status OUT NOCOPY VARCHAR2,
111 x_msg_count OUT NOCOPY NUMBER,
112 x_msg_data OUT NOCOPY VARCHAR2) IS
113
114 l_notes_tbl Cs_Servicerequest_Pub.NOTES_TABLE;
115
116 BEGIN
117
118 process_service_request(p_api_version => p_api_version,
119 p_commit => p_commit,
120 p_init_msg_list => p_init_msg_list,
121 p_validation_level => p_validation_level,
122 p_action => p_action,
123 p_incident_id => p_incident_id,
124 p_service_request_rec => p_service_request_rec,
125 p_notes_tbl => l_notes_tbl,
126 x_incident_id => x_incident_id,
127 x_incident_number => x_incident_number,
128 x_return_status => x_return_status,
129 x_msg_count => x_msg_count,
130 x_msg_data => x_msg_data );
131
132 END process_Service_request;
133
134 /*--------------------------------------------------*/
135 /* procedure name: process_service_request */
136 /* description : procedure used to create */
137 /* service requests */
138 /*--------------------------------------------------*/
139
140 PROCEDURE process_service_request(p_api_version IN NUMBER,
141 p_commit IN VARCHAR2 := Fnd_Api.g_false,
142 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_false,
143 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
144 p_action IN VARCHAR2,
145 p_incident_id IN NUMBER := NULL,
146 p_service_request_rec IN Csd_Process_Pvt.SERVICE_REQUEST_REC,
147 p_notes_tbl IN Cs_Servicerequest_Pub.NOTES_TABLE,
148 x_incident_id OUT NOCOPY NUMBER,
149 x_incident_number OUT NOCOPY VARCHAR2,
150 x_return_status OUT NOCOPY VARCHAR2,
151 x_msg_count OUT NOCOPY NUMBER,
152 x_msg_data OUT NOCOPY VARCHAR2) IS
153
154 l_api_name CONSTANT VARCHAR2(30) := 'PROCESS_SERVICE_REQUEST';
155 l_api_version CONSTANT NUMBER := 1.0;
156 l_msg_count NUMBER;
157 l_msg_data VARCHAR2(2000);
158 l_msg_index NUMBER;
159 r_service_request_rec Cs_Servicerequest_Pub.service_request_rec_type;
160 t_contacts_table Cs_Servicerequest_Pub.contacts_table;
161 ln_interaction_id NUMBER;
162 ln_workflow_id NUMBER;
163 ln_individual_owner NUMBER;
164 ln_group_owner NUMBER;
165 ln_individual_type VARCHAR2(100);
166
167 CURSOR c_party_site_id(p_party_site_use_id IN NUMBER) IS
168 SELECT party_site_id
169 FROM hz_party_site_uses
170 WHERE party_site_use_id = p_party_site_use_id;
171
172 CURSOR c_party_id(p_party_site_id IN NUMBER) IS
173 SELECT party_id
174 FROM hz_party_sites
175 WHERE party_site_id = p_party_site_id;
176
177 BEGIN
178 -- Standard Start of API savepoint
179 SAVEPOINT process_service_request;
180
181 -- Standard call to check for call compatibility.
182 IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
183 p_api_version,
184 l_api_name,
185 G_PKG_NAME)
186 THEN
187 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
188 END IF;
189
190 -- Initialize message list if p_init_msg_list is set to TRUE.
191 IF Fnd_Api.to_Boolean(p_init_msg_list)
192 THEN
193 Fnd_Msg_Pub.initialize;
194 END IF;
195
196 -- Initialize API return status to success
197 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
198
199 IF (g_debug > 5)
200 THEN
201 Csd_Gen_Utility_Pvt.ADD('dump_sr_rec');
202 Csd_Gen_Utility_Pvt.dump_sr_rec(p_sr_rec => p_service_request_rec);
203 END IF;
204
205 -- Assign the SR rec values
206 Cs_Servicerequest_Pub.initialize_rec(r_service_request_rec);
207 r_service_request_rec.request_date := p_service_request_rec.request_date;
208 r_service_request_rec.type_id := p_service_request_rec.type_id;
209 r_service_request_rec.type_name := p_service_request_rec.type_name;
210 r_service_request_rec.status_id := p_service_request_rec.status_id;
211 r_service_request_rec.status_name := p_service_request_rec.status_name;
212 r_service_request_rec.severity_id := p_service_request_rec.severity_id;
213 r_service_request_rec.severity_name := p_service_request_rec.severity_name;
214 r_service_request_rec.urgency_id := p_service_request_rec.urgency_id;
215 r_service_request_rec.urgency_name := p_service_request_rec.urgency_name;
216 r_service_request_rec.closed_date := p_service_request_rec.closed_date;
217 r_service_request_rec.owner_id := p_service_request_rec.owner_id;
218
219 -- swai: 02-07-03
220 -- do not pass owner_group_id since group_type is not available
221 -- passing owner_group_id without group_type may cause SR validation
222 -- errors
223 -- r_service_request_rec.owner_group_id := p_service_request_rec.owner_group_id;
224 r_service_request_rec.publish_flag := p_service_request_rec.publish_flag;
225 r_service_request_rec.summary := p_service_request_rec.summary;
226 r_service_request_rec.caller_type := p_service_request_rec.caller_type;
227 r_service_request_rec.customer_id := p_service_request_rec.customer_id;
228 r_service_request_rec.customer_number := p_service_request_rec.customer_number;
229 r_service_request_rec.employee_id := p_service_request_rec.employee_id;
230 r_service_request_rec.employee_number := p_service_request_rec.employee_number;
231 r_service_request_rec.customer_product_id := p_service_request_rec.customer_product_id;
232 r_service_request_rec.cp_ref_number := p_service_request_rec.cp_ref_number;
233 r_service_request_rec.inventory_item_id := p_service_request_rec.inventory_item_id;
234 r_service_request_rec.inventory_org_id := p_service_request_rec.inventory_org_id;
235 r_service_request_rec.current_serial_number := p_service_request_rec.current_serial_number;
236 r_service_request_rec.original_order_number := p_service_request_rec.original_order_number;
237 r_service_request_rec.purchase_order_num := p_service_request_rec.purchase_order_num;
238 r_service_request_rec.problem_code := p_service_request_rec.problem_code;
239 r_service_request_rec.exp_resolution_date := p_service_request_rec.exp_resolution_date;
240 r_service_request_rec.bill_to_site_use_id := p_service_request_rec.bill_to_site_use_id;
241 r_service_request_rec.ship_to_site_use_id := p_service_request_rec.ship_to_site_use_id;
242 r_service_request_rec.contract_id := p_service_request_rec.contract_id;
243 r_service_request_rec.account_id := p_service_request_rec.account_id;
244 r_service_request_rec.resource_type := p_service_request_rec.resource_type;
245 r_service_request_rec.cust_po_number := p_service_request_rec.cust_po_number;
246 r_service_request_rec.cp_revision_id := p_service_request_rec.cp_revision_id;
247 r_service_request_rec.inv_item_revision := p_service_request_rec.inv_item_revision;
248 r_service_request_rec.sr_creation_channel := p_service_request_rec.sr_creation_channel;
249 r_service_request_rec.creation_program_code := 'CSD_REPAIR_ORDER_FORM';
250 r_service_request_rec.last_update_program_code := 'CSD_REPAIR_ORDER_FORM';
251 r_service_request_rec.group_type := 'RS_GROUP';
252
253 /*Fixed for bug#5589395
254 Pass the DFF value to Service API.
255 */
256 r_service_request_rec.external_context := p_service_request_rec.external_context;
257 r_service_request_rec.external_attribute_1 := p_service_request_rec.external_attribute_1;
258 r_service_request_rec.external_attribute_2 := p_service_request_rec.external_attribute_2;
259 r_service_request_rec.external_attribute_3 := p_service_request_rec.external_attribute_3;
260 r_service_request_rec.external_attribute_4 := p_service_request_rec.external_attribute_4;
261 r_service_request_rec.external_attribute_5 := p_service_request_rec.external_attribute_5;
262 r_service_request_rec.external_attribute_6 := p_service_request_rec.external_attribute_6;
263 r_service_request_rec.external_attribute_7 := p_service_request_rec.external_attribute_7;
264 r_service_request_rec.external_attribute_8 := p_service_request_rec.external_attribute_8;
265 r_service_request_rec.external_attribute_9 := p_service_request_rec.external_attribute_9;
266 r_service_request_rec.external_attribute_10 := p_service_request_rec.external_attribute_10;
267 r_service_request_rec.external_attribute_11 := p_service_request_rec.external_attribute_11;
268 r_service_request_rec.external_attribute_12 := p_service_request_rec.external_attribute_12;
269 r_service_request_rec.external_attribute_13 := p_service_request_rec.external_attribute_13;
270 r_service_request_rec.external_attribute_14 := p_service_request_rec.external_attribute_14;
271 r_service_request_rec.external_attribute_15 := p_service_request_rec.external_attribute_15;
272
273
274 -- Contacts
275 -- swai - forward port bug 2767101
276 -- Do not set the contact record if no contact was specified.
277 -- setting these fields to null may cause SR API to fail
278 IF (p_service_request_rec.party_id IS NOT NULL)
279 THEN
280 t_contacts_table(1).sr_contact_point_id := p_service_request_rec.sr_contact_point_id;
281 t_contacts_table(1).party_id := p_service_request_rec.party_id;
282 t_contacts_table(1).contact_type := p_service_request_rec.contact_type;
283 t_contacts_table(1).contact_point_id := p_service_request_rec.contact_point_id;
284 t_contacts_table(1).contact_point_type := p_service_request_rec.contact_point_type;
285 t_contacts_table(1).primary_flag := p_service_request_rec.primary_flag;
286 END IF;
287
288 Csd_Gen_Utility_Pvt.ADD('GETTING BILL-TO FIELDS');
289 -- Bill-To fields
290 IF (NVL(p_service_request_rec.bill_to_site_use_id,
291 Fnd_Api.G_MISS_NUM) <> Fnd_Api.G_MISS_NUM)
292 THEN
293 OPEN c_party_site_id(p_service_request_rec.bill_to_site_use_id);
294 FETCH c_party_site_id
295 INTO r_service_request_rec.bill_to_site_id;
296 CLOSE c_party_site_id;
297 Csd_Gen_Utility_Pvt.ADD('r_service_request_rec.bill_to_site_id ' ||
298 r_service_request_rec.bill_to_site_id);
299 IF (NVL(r_service_request_rec.bill_to_site_id,
300 Fnd_Api.G_MISS_NUM) <> Fnd_Api.G_MISS_NUM)
301 THEN
302 OPEN c_party_id(r_service_request_rec.bill_to_site_id);
303 FETCH c_party_id
304 INTO r_service_request_rec.bill_to_party_id;
305 CLOSE c_party_id;
306 Csd_Gen_Utility_Pvt.ADD('r_service_request_rec.bill_to_party_id ' ||
307 r_service_request_rec.bill_to_party_id);
308 END IF;
309 END IF;
310
311 -- Ship-To fields
312 Csd_Gen_Utility_Pvt.ADD('GETTING SHIP-TO FIELDS');
313 IF (NVL(p_service_request_rec.ship_to_site_use_id,
314 Fnd_Api.G_MISS_NUM) <> Fnd_Api.G_MISS_NUM)
315 THEN
316 OPEN c_party_site_id(p_service_request_rec.ship_to_site_use_id);
317 FETCH c_party_site_id
318 INTO r_service_request_rec.ship_to_site_id;
319 CLOSE c_party_site_id;
320 Csd_Gen_Utility_Pvt.ADD('r_service_request_rec.ship_to_site_id ' ||
321 r_service_request_rec.ship_to_site_id);
322 IF (NVL(r_service_request_rec.ship_to_site_id,
323 Fnd_Api.G_MISS_NUM) <> Fnd_Api.G_MISS_NUM)
324 THEN
325 OPEN c_party_id(r_service_request_rec.ship_to_site_id);
326 FETCH c_party_id
327 INTO r_service_request_rec.ship_to_party_id;
328 CLOSE c_party_id;
329 Csd_Gen_Utility_Pvt.ADD('r_service_request_rec.ship_to_party_id ' ||
330 r_service_request_rec.ship_to_party_id);
331 END IF;
332 END IF;
333
334 -- Call to Service Request API
335 IF (UPPER(p_action) = 'CREATE')
336 THEN
337 Cs_Servicerequest_Pub.Create_ServiceRequest(p_api_version => 3.0,
338 p_init_msg_list => Fnd_Api.G_FALSE,
339 p_commit => Fnd_Api.G_FALSE,
340 x_return_status => x_return_status,
341 x_msg_count => x_msg_count,
342 x_msg_data => x_msg_data,
343 p_resp_appl_id => NULL,
344 p_resp_id => NULL,
345 p_user_id => Fnd_Global.user_id,
346 p_login_id => Fnd_Global.conc_login_id,
347 p_org_id => NULL,
348 p_request_id => p_incident_id,
349 p_request_number => p_service_request_rec.incident_number, -- swai: FP 5157216,
350 p_service_request_rec => r_service_request_rec,
351 p_notes => p_notes_tbl,
352 p_contacts => t_contacts_table,
353 x_request_id => x_incident_id,
354 x_request_number => x_incident_number,
355 x_interaction_id => ln_interaction_id,
356 x_workflow_process_id => ln_workflow_id,
357 x_individual_owner => ln_individual_owner,
358 x_group_owner => ln_group_owner,
359 x_individual_type => ln_individual_type);
360
361 END IF;
362
363 -- Api body ends here
364
365 -- Standard check of p_commit.
366 IF Fnd_Api.To_Boolean(p_commit)
367 THEN
368 COMMIT WORK;
369 END IF;
370
371 -- Standard call to get message count and IF count is get message info.
372 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
373 p_data => x_msg_data);
374 EXCEPTION
375 WHEN Fnd_Api.G_EXC_ERROR THEN
376 ROLLBACK TO process_service_request;
377 x_return_status := Fnd_Api.G_RET_STS_ERROR;
378 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
379 p_data => x_msg_data);
380 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
381 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
382 ROLLBACK TO process_service_request;
383 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
384 p_data => x_msg_data);
385 WHEN OTHERS THEN
386 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
387 ROLLBACK TO process_service_request;
388 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
389 THEN
390 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
391 END IF;
392 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
393 p_data => x_msg_data);
394 END process_service_request;
395
396 /*--------------------------------------------------*/
397 /* procedure name: process_charge_lines */
398 /* description : procedure used to create/update */
399 /* delete charge lines */
400 /* */
401 /*--------------------------------------------------*/
402
403 PROCEDURE process_charge_lines(p_api_version IN NUMBER,
404 p_commit IN VARCHAR2 := Fnd_Api.g_false,
405 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_false,
406 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
407 p_action IN VARCHAR2,
408 p_Charges_Rec IN Cs_Charge_Details_Pub.Charges_Rec_Type,
409 x_estimate_detail_id OUT NOCOPY NUMBER,
410 x_return_status OUT NOCOPY VARCHAR2,
411 x_msg_count OUT NOCOPY NUMBER,
412 x_msg_data OUT NOCOPY VARCHAR2) IS
413 l_api_name CONSTANT VARCHAR2(30) := 'PROCESS_CHARGE_LINES';
414 l_api_version CONSTANT NUMBER := 1.0;
415 l_msg_count NUMBER;
416 l_msg_data VARCHAR2(2000);
417 l_msg_index NUMBER;
418 l_estimate_detail_id NUMBER;
419 l_charges_rec Cs_Charge_Details_Pub.Charges_Rec_Type;
420 x_object_version_number NUMBER;
421 x_line_number NUMBER;
422 l_invoice_to_org_id NUMBER; -- nnadig: bug 9395568
423 l_ship_to_org_id NUMBER; -- nnadig: bug 9395568
424
425
426 -- Variables used in FND Log
427 l_error_level NUMBER := Fnd_Log.LEVEL_ERROR;
428 l_mod_name VARCHAR2(2000) := 'csd.plsql.csd_process_pvt.process_charge_lines';
429
430 BEGIN
431 Debug('At the Beginning of process_charge_lines', l_mod_name, 1);
432
433 -- Standard Start of API savepoint
434 SAVEPOINT process_charge_lines;
435
436 -- Standard call to check for call compatibility.
437 IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
438 p_api_version,
439 l_api_name,
440 G_PKG_NAME)
441 THEN
442 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
443 END IF;
444
445 -- Initialize message list if p_init_msg_list is set to TRUE.
446 IF Fnd_Api.to_Boolean(p_init_msg_list)
447 THEN
448 Fnd_Msg_Pub.initialize;
449 END IF;
450
451 -- Initialize API return status to success
452 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
453
454 -- Api body starts
455
456 Debug('Validate the action', l_mod_name, 1);
457
458 -- Validate the action code
459 IF NOT (Csd_Process_Util.VALIDATE_ACTION(p_action, l_api_name))
460 THEN
461 RAISE Fnd_Api.G_EXC_ERROR;
462 END IF;
463
464 l_charges_rec := p_charges_rec;
465
466 -- nnadig: bug 9395568
467 -- If this is an existing charge line, get the current
468 -- bill-to and ship-to site information so that
469 -- we can compare them with what is being passed in.
470 if (l_Charges_Rec.estimate_detail_id is not null and
471 l_Charges_Rec.estimate_detail_id <> FND_API.G_MISS_NUM) then
472 BEGIN
473 select invoice_to_org_id, ship_to_org_id
474 into l_invoice_to_org_id, l_ship_to_org_id
475 from cs_estimate_details
476 where estimate_detail_id = l_Charges_Rec.estimate_detail_id;
477 EXCEPTION
478 WHEN NO_DATA_FOUND THEN
479 debug('No existing Charges record',l_mod_name,1);
480 RAISE FND_API.G_EXC_ERROR;
481 END;
482 if (l_invoice_to_org_id <> l_Charges_Rec.invoice_to_org_id) then
483 l_Charges_Rec.bill_to_account_id := NULL;
484 end if;
485 if (l_ship_to_org_id <> l_Charges_Rec.ship_to_org_id) then
486 l_Charges_Rec.ship_to_account_id := NULL;
487 end if;
488 end if;
489 -- end nnadig: bug 9395568
490
491 /* Fixed for forward port bug#4214359.
492 Whenever we pass the invoice_to_org_id corresponding bill_to_party_id should be passed
493 otherwise charges API will validate the bill_to_org_id against the party_id at
494 Service Request level and it would error out if the bill to address selected at product
495 line level is of related party.
496 */
497 IF (l_Charges_Rec.invoice_to_org_id IS NOT NULL AND
498 l_Charges_Rec.invoice_to_org_id <> Fnd_Api.G_MISS_NUM)
499 THEN
500 BEGIN
501 SELECT party_id
502 INTO l_Charges_Rec.bill_to_party_id
503 FROM hz_party_sites
504 WHERE party_site_id = l_Charges_Rec.invoice_to_org_id;
505 EXCEPTION
506 WHEN NO_DATA_FOUND THEN
507 debug('No Bill to Party Id', l_mod_name, 1);
508 RAISE Fnd_Api.G_EXC_ERROR;
509 WHEN TOO_MANY_ROWS THEN
510 debug('Too many Bill to Party Id', l_mod_name, 1);
511 RAISE Fnd_Api.G_EXC_ERROR;
512 END;
513 END IF;
514
515 /* Fixed for forward port bug#4214359.
516 Whenever we pass the ship_to_org_id corresponding ship_to_party_id should be passed
517 otherwise charges API will validate the ship_to_org_id against the party_id at
518 Service Request level and it would error out if the ship to address selected at product
519 line level is of related party.
520 */
521 IF (l_Charges_Rec.ship_to_org_id IS NOT NULL AND
522 l_Charges_Rec.ship_to_org_id <> Fnd_Api.G_MISS_NUM)
523 THEN
524 BEGIN
525 SELECT party_id
526 INTO l_Charges_Rec.ship_to_party_id
527 FROM hz_party_sites
528 WHERE party_site_id = l_Charges_Rec.ship_to_org_id;
529 EXCEPTION
530 WHEN NO_DATA_FOUND THEN
531 debug('No Ship to Party Id', l_mod_name, 1);
532 RAISE Fnd_Api.G_EXC_ERROR;
533 WHEN TOO_MANY_ROWS THEN
534 debug('Too many Ship to Party Id', l_mod_name, 1);
535 RAISE Fnd_Api.G_EXC_ERROR;
536 END;
537 END IF;
538
539 -- Based on the action, call the respective charges public api to
540 -- to create/update/delete the charge lines.
541 IF p_action = 'CREATE'
542 THEN
543
544 Debug('Creating the charge lines ', l_mod_name, 1);
545 Debug('l_charges_rec.transaction_type_id :' ||
546 TO_CHAR(l_charges_rec.transaction_type_id),
547 l_mod_name,
548 1);
549
550 Cs_Charge_Details_Pub.Create_Charge_Details(p_api_version => p_api_version,
551 p_init_msg_list => p_init_msg_list,
552 p_commit => p_commit,
553 p_validation_level => p_validation_level,
554 p_transaction_control => Fnd_Api.G_TRUE,
555 p_Charges_Rec => l_charges_rec,
556 x_object_version_number => x_object_version_number,
557 x_estimate_detail_id => x_estimate_detail_id,
558 x_line_number => x_line_number,
559 x_return_status => x_return_status,
560 x_msg_count => x_msg_count,
561 x_msg_data => x_msg_data);
562
563 Debug('Return Status from Create_Charge_Details' ||
564 x_return_status,
565 l_mod_name,
566 1);
567
568 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
569 THEN
570 Debug('Create_Charge_Details failed ', l_mod_name, 1);
571 RAISE Fnd_Api.G_EXC_ERROR;
572 END IF;
573
574 ELSIF p_action = 'UPDATE'
575 THEN
576
577 Debug('Creating the charge lines ', l_mod_name, 1);
578 Debug('Estimate Detail Id = ' ||
579 l_Charges_Rec.estimate_detail_id,
580 l_mod_name,
581 1);
582 Debug('l_Charges_Rec.business_process_id=' ||
583 l_Charges_Rec.business_process_id,
584 l_mod_name,
585 1);
586
587 IF ((NVL(l_Charges_Rec.business_process_id, Fnd_Api.G_MISS_NUM) =
588 Fnd_Api.G_MISS_NUM) AND
589 l_Charges_Rec.estimate_detail_id IS NOT NULL)
590 THEN
591 BEGIN
592 SELECT business_process_id
593 INTO l_Charges_Rec.business_process_id
594 FROM cs_estimate_details
595 WHERE estimate_detail_id =
596 l_Charges_Rec.estimate_detail_id;
597 EXCEPTION
598 WHEN NO_DATA_FOUND THEN
599 Debug('No Business business_process_id',
600 l_mod_name,
601 1);
602 RAISE Fnd_Api.G_EXC_ERROR;
603 WHEN TOO_MANY_ROWS THEN
604 Debug('Too many business_process_id',
605 l_mod_name,
606 1);
607 RAISE Fnd_Api.G_EXC_ERROR;
608 END;
609 END IF;
610
611 Debug('l_Charges_Rec.business_process_id=' ||
612 l_Charges_Rec.business_process_id,
613 l_mod_name,
614 1);
615
616 Cs_Charge_Details_Pub.Update_Charge_Details(p_api_version => p_api_version,
617 p_init_msg_list => p_init_msg_list,
618 p_commit => p_commit,
619 p_validation_level => p_validation_level,
620 p_transaction_control => Fnd_Api.G_TRUE,
621 p_Charges_Rec => l_Charges_Rec,
622 x_object_version_number => x_object_version_number,
623 x_return_status => x_return_status,
624 x_msg_count => x_msg_count,
625 x_msg_data => x_msg_data);
626
627 Debug('Return Status from Update_Charge_Details' ||
628 x_return_status,
629 l_mod_name,
630 1);
631
632 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
633 THEN
634 Debug('update_charge_details failed', l_mod_name, 1);
635 RAISE Fnd_Api.G_EXC_ERROR;
636 END IF;
637
638 ELSIF p_action = 'DELETE'
639 THEN
640
641 Debug('l_estimate_detail_id =' || l_estimate_detail_id,
642 l_mod_name,
643 1);
644 Debug('Deleting the charge lines ', l_mod_name, 1);
645
646 l_estimate_detail_id := l_charges_rec.estimate_detail_id;
647
648 Cs_Charge_Details_Pub.Delete_Charge_Details(p_api_version => p_api_version,
649 p_init_msg_list => p_init_msg_list,
650 p_commit => p_commit,
651 p_validation_level => p_validation_level,
652 p_transaction_control => Fnd_Api.G_TRUE,
653 p_estimate_detail_id => l_estimate_detail_id,
654 x_return_status => x_return_status,
655 x_msg_count => x_msg_count,
656 x_msg_data => x_msg_data);
657
658 Debug('Return Status from Delete_Charge_Details' ||
659 x_return_status,
660 l_mod_name,
661 1);
662
663 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
664 THEN
665 Debug('Delete_Charge_Details failed ', l_mod_name, 1);
666 RAISE Fnd_Api.G_EXC_ERROR;
667 END IF;
668 END IF;
669
670 -- Api body ends here
671
672 -- Standard check of p_commit.
673 IF Fnd_Api.To_Boolean(p_commit)
674 THEN
675 COMMIT WORK;
676 END IF;
677
678 -- Standard call to get message count and IF count is get message info.
679 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
680 p_data => x_msg_data);
681 EXCEPTION
682 WHEN Fnd_Api.G_EXC_ERROR THEN
683 ROLLBACK TO process_charge_lines;
684 x_return_status := Fnd_Api.G_RET_STS_ERROR;
685 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
686 p_data => x_msg_data);
687 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
688 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
689 ROLLBACK TO process_charge_lines;
690 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
691 p_data => x_msg_data);
692 WHEN OTHERS THEN
693 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
694 ROLLBACK TO process_charge_lines;
695 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
696 THEN
697 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
698 END IF;
699 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
700 p_data => x_msg_data);
701 END process_charge_lines;
702
703 /*--------------------------------------------------*/
704 /* procedure name: apply_contract */
705 /* description : procedure used to apply contract */
706 /* */
707 /*--------------------------------------------------*/
708
709 PROCEDURE apply_contract(p_api_version IN NUMBER,
710 p_commit IN VARCHAR2 := Fnd_Api.g_false,
711 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_false,
712 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
713 p_incident_id IN NUMBER,
714 x_return_status OUT NOCOPY VARCHAR2,
715 x_msg_count OUT NOCOPY NUMBER,
716 x_msg_data OUT NOCOPY VARCHAR2) IS
717
718 l_api_name CONSTANT VARCHAR2(30) := 'APPLY_CONTRACT';
719 l_api_version CONSTANT NUMBER := 1.0;
720 l_msg_count NUMBER;
721 l_msg_data VARCHAR2(2000);
722 l_msg_index NUMBER;
723
724 BEGIN
725 -- Standard Start of API savepoint
726 SAVEPOINT apply_contract;
727
728 -- Standard call to check for call compatibility.
729 IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
730 p_api_version,
731 l_api_name,
732 G_PKG_NAME)
733 THEN
734 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
735 END IF;
736
737 -- Initialize message list if p_init_msg_list is set to TRUE.
738 IF Fnd_Api.to_Boolean(p_init_msg_list)
739 THEN
740 Fnd_Msg_Pub.initialize;
741 END IF;
742
743 -- Initialize API return status to success
744 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
745
746 -- Api body starts
747 IF (g_debug > 0)
748 THEN
749 Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
750 p_api_name => l_api_name);
751 END IF;
752
753 IF (g_debug > 0)
754 THEN
755 Csd_Gen_Utility_Pvt.ADD('Validate the incident id');
756 Csd_Gen_Utility_Pvt.ADD('p_incident_id =' || p_incident_id);
757 END IF;
758
759 IF NOT (Csd_Process_Util.VALIDATE_INCIDENT_ID(p_incident_id))
760 THEN
761 RAISE Fnd_Api.G_EXC_ERROR;
762 END IF;
763
764 IF (g_debug > 0)
765 THEN
766 Csd_Gen_Utility_Pvt.ADD('Applying contract on charge lines');
767 END IF;
768
769 -- Commented
770 -- signature change to be discussed.
771 -- CS_EST_APPLY_CONTRACT_PKG.APPLY_CONTRACT
772 -- (p_incident_id => p_incident_id ) ;
773
774 -- Api body ends here
775
776 -- Standard check of p_commit.
777 IF Fnd_Api.To_Boolean(p_commit)
778 THEN
779 COMMIT WORK;
780 END IF;
781
782 -- Standard call to get message count and IF count is get message info.
783 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
784 p_data => x_msg_data);
785 EXCEPTION
786 WHEN Fnd_Api.G_EXC_ERROR THEN
787 ROLLBACK TO apply_contract;
788 x_return_status := Fnd_Api.G_RET_STS_ERROR;
789 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
790 p_data => x_msg_data);
791 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
792 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
793 ROLLBACK TO apply_contract;
794 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
795 p_data => x_msg_data);
796 WHEN OTHERS THEN
797 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
798 ROLLBACK TO apply_contract;
799 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
800 THEN
801 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
802 END IF;
803 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
804 p_data => x_msg_data);
805 END apply_contract;
806
807 /*--------------------------------------------------*/
808 /* procedure name: ship_sales_order */
809 /* description : procedure used to ship */
810 /* sales Order */
811 /* */
812 /*--------------------------------------------------*/
813
814 PROCEDURE ship_sales_order(p_api_version IN NUMBER,
815 p_commit IN VARCHAR2 := Fnd_Api.g_false,
816 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_false,
817 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
818 p_delivery_id IN OUT NOCOPY NUMBER,
819 x_return_status OUT NOCOPY VARCHAR2,
820 x_msg_count OUT NOCOPY NUMBER,
821 x_msg_data OUT NOCOPY VARCHAR2) IS
822 l_api_name CONSTANT VARCHAR2(30) := 'SHIP_SALES_ORDER';
823 l_api_version CONSTANT NUMBER := 1.0;
824 l_msg_count NUMBER;
825 l_msg_data VARCHAR2(2000);
826 l_msg_index NUMBER;
827 l_dummy VARCHAR2(1);
828 l_header_rec Aso_Quote_Pub.Qte_Header_Rec_Type;
829 l_line_tbl Aso_Quote_Pub.Qte_Line_Tbl_Type;
830 l_Line_dtl_tbl Aso_Quote_Pub.Qte_Line_Dtl_Tbl_Type;
831 l_hd_shipment_rec Aso_Quote_Pub.Shipment_rec_Type;
832 l_hd_shipment_tbl Aso_Quote_Pub.Shipment_tbl_Type;
833 l_ln_shipment_tbl Aso_Quote_Pub.Shipment_Tbl_Type;
834 l_hd_payment_tbl Aso_Quote_Pub.Payment_Tbl_Type; -- added by cnemalik
835 l_line_price_adj_tbl Aso_Quote_Pub.Price_Adj_Tbl_Type;
836 x_order_header_rec Aso_Order_Int.Order_Header_rec_type;
837 x_order_line_tbl Aso_Order_Int.Order_Line_tbl_type;
838 x_order_header_id NUMBER;
839 l_control_rec Aso_Order_Int.control_rec_type;
840 -- Following two variables are defined to fix bug 3437177
841 l_Serial_number_control_code NUMBER;
842 C_SRL_NUM_Cnt_Code_SO_ISSUE CONSTANT NUMBER := 6;
843
844 -- Parameters for WSH_DELIVERIES_PUB.Delivery_Action.
845 --p_delivery_id NUMBER;
846 p_action_code VARCHAR2(15);
847 p_delivery_name VARCHAR2(30);
848 p_asg_trip_id NUMBER;
849 p_asg_trip_name VARCHAR2(30);
850 p_asg_pickup_stop_id NUMBER;
851 p_asg_pickup_loc_id NUMBER;
852 p_asg_pickup_loc_code VARCHAR2(30);
853 p_asg_pickup_arr_date DATE;
854 p_asg_pickup_dep_date DATE;
855 p_asg_dropoff_stop_id NUMBER;
856 p_asg_dropoff_loc_id NUMBER;
857 p_asg_dropoff_loc_code VARCHAR2(30);
858 p_asg_dropoff_arr_date DATE;
859 p_asg_dropoff_dep_date DATE;
860 p_sc_action_flag VARCHAR2(10);
861 p_sc_intransit_flag VARCHAR2(10);
862 p_sc_close_trip_flag VARCHAR2(10);
863 p_sc_create_bol_flag VARCHAR2(10);
864 p_sc_stage_del_flag VARCHAR2(10);
865 p_sc_trip_ship_method VARCHAR2(30);
866 p_sc_actual_dep_date VARCHAR2(30);
867 p_sc_defer_interface_flag VARCHAR2(1);
868 p_sc_report_set_id NUMBER;
869 p_sc_report_set_name VARCHAR2(60);
870 p_wv_override_flag VARCHAR2(10);
871 x_trip_id VARCHAR2(30);
872 x_trip_name VARCHAR2(30);
873 x_msg_details VARCHAR2(3000);
874 x_msg_summary VARCHAR2(3000);
875 l_customer_id NUMBER := NULL;
876 l_order_type_id NUMBER := NULL;
877 l_document_set_id NUMBER := NULL;
878 l_sub_inventory VARCHAR2(30) := '';
879
880 --Parameters for WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes.
881 source_code VARCHAR2(15);
882 changed_attributes Wsh_Delivery_Details_Pub.ChangedAttributeTabType;
883
884 /* Handle exceptions */
885 fail_api EXCEPTION;
886 -- Added Mtl_Sytem_items_B to get serial_number_control_Code for the item that is being
887 -- shipped. This is to fix bug 3437177 saupadhy
888 -- Added condition that release status should be 'Y' which 'Staged/Pick Confirmed'
889
890 CURSOR delivery(p_del_id IN NUMBER) IS
891 SELECT cr.serial_number,
892 wdd.delivery_detail_id,
893 wdd.requested_quantity,
894 mtl.serial_number_control_code
895 FROM csd_repairs cr,
896 mtl_system_items_b mtl,
897 cs_estimate_details ced,
898 wsh_delivery_details wdd,
899 --Changed to view from table, bug: 4341784
900 wsh_delivery_assignments_v wda
901 WHERE cr.repair_line_id = ced.original_source_id
902 AND ced.original_source_code = 'DR'
903 AND ced.order_line_id = wdd.source_line_id
904 AND wdd.SOURCE_CODE = 'OE' /*Fixed for bug#5846054*/
905 AND wdd.delivery_detail_id = wda.delivery_detail_id
906 AND wdd.released_status = 'Y'
907 AND wda.delivery_id = p_del_id
908 AND wdd.inventory_item_id = mtl.inventory_item_id
909 AND wdd.ship_from_location_id = mtl.organization_id;
910
911 BEGIN
912 -- Standard Start of API savepoint
913 SAVEPOINT ship_sales_order;
914
915 -- Standard call to check for call compatibility.
916 IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
917 p_api_version,
918 l_api_name,
919 G_PKG_NAME)
920 THEN
921 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
922 END IF;
923
924 -- Initialize message list if p_init_msg_list is set to TRUE.
925 IF Fnd_Api.to_Boolean(p_init_msg_list)
926 THEN
927 Fnd_Msg_Pub.initialize;
928 END IF;
929
930 -- Initialize API return status to success
931 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
932
933 -- Api body starts
934
935 -- dbms_application_info.set_client_info('204');
936 -- fnd_global.apps_initialize(1000200,52284,512,0);
937
938 IF (g_debug > 0)
939 THEN
940 Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
941 p_api_name => l_api_name);
942 END IF;
943 -- If action is SHIP, then call shipping api to
944 -- ship the sales order
945 IF (g_debug > 0)
946 THEN
947 Csd_Gen_Utility_Pvt.ADD('Shipping the Sales Order');
948 Csd_Gen_Utility_Pvt.ADD('p_delivery_id =' || p_delivery_id);
949 END IF;
950
951 IF NVL(p_delivery_id, Fnd_Api.G_MISS_NUM) = Fnd_Api.G_MISS_NUM
952 THEN
953 Fnd_Message.SET_NAME('CSD', 'CSD_INV_DELIVERY_ID');
954 Fnd_Message.SET_TOKEN('DELIVERY_ID', p_delivery_id);
955 Fnd_Msg_Pub.ADD;
956 IF (g_debug > 0)
957 THEN
958 Csd_Gen_Utility_Pvt.ADD('Delivery_id is invalid');
959 END IF;
960 RAISE Fnd_Api.G_EXC_ERROR;
961 ELSE
962
963 BEGIN
964 SELECT '*'
965 INTO l_dummy
966 FROM wsh_new_deliveries
967 WHERE delivery_id = p_delivery_id;
968 EXCEPTION
969 WHEN NO_DATA_FOUND THEN
970 Fnd_Message.SET_NAME('CSD', 'CSD_INV_DELIVERY_ID');
971 Fnd_Message.SET_TOKEN('DELIVERY_ID', p_delivery_id);
972 Fnd_Msg_Pub.ADD;
973 IF (g_debug > 0)
974 THEN
975 Csd_Gen_Utility_Pvt.ADD('Delivery_id is invalid');
976 END IF;
977 RAISE Fnd_Api.G_EXC_ERROR;
978 END;
979 END IF;
980
981 FOR i IN delivery(p_delivery_id)
982 LOOP
983
984 -- In case of serial controlled at SO issue item, update the serial number on the
985 -- delivery line details
986 -- This change was made to fix bug 3437177
987
988 -- IF NVL(i.serial_number, FND_API.G_MISS_CHAR) <> FND_API.G_MISS_CHAR THEN
989 IF i.Serial_number_control_code = C_SRL_NUM_Cnt_Code_SO_ISSUE AND
990 NVL(i.serial_number, Fnd_Api.G_MISS_CHAR) <>
991 Fnd_Api.G_MISS_CHAR
992 THEN
993 BEGIN
994 source_code := 'OE'; -- The only source code that should be used by the API
995 changed_attributes(1).delivery_detail_id := i.delivery_detail_id;
996 changed_attributes(1).serial_number := i.serial_number;
997 changed_attributes(1).shipped_quantity := i.requested_quantity;
998 IF (g_debug > 0)
999 THEN
1000 Csd_Gen_Utility_Pvt.ADD('delivery_detail_id =' ||
1001 changed_attributes(1)
1002 .delivery_detail_id);
1003 Csd_Gen_Utility_Pvt.ADD('serial_number =' ||
1004 changed_attributes(1)
1005 .serial_number);
1006 Csd_Gen_Utility_Pvt.ADD('shipped_quantity =' ||
1007 changed_attributes(1)
1008 .shipped_quantity);
1009 Csd_Gen_Utility_Pvt.ADD('Calling Update_Shipping_Attributes');
1010 END IF;
1011 --Call to WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes.
1012 Wsh_Delivery_Details_Pub.Update_Shipping_Attributes(p_api_version_number => 1.0,
1013 p_init_msg_list => p_init_msg_list,
1014 p_commit => p_commit,
1015 x_return_status => x_return_status,
1016 x_msg_count => x_msg_count,
1017 x_msg_data => x_msg_data,
1018 p_changed_attributes => changed_attributes,
1019 p_source_code => source_code);
1020 IF (g_debug > 0)
1021 THEN
1022 Csd_Gen_Utility_Pvt.ADD('x_return_status(Update_Shipping_Attributes )=' ||
1023 x_return_status);
1024 END IF;
1025 IF (x_return_status <> Wsh_Util_Core.G_RET_STS_SUCCESS)
1026 THEN
1027 IF (g_debug > 0)
1028 THEN
1029 Csd_Gen_Utility_Pvt.ADD('Update_Shipping_Attributes failed');
1030 END IF;
1031 RAISE fail_api;
1032 END IF;
1033 EXCEPTION
1034 WHEN fail_api THEN
1035 Wsh_Util_Core.get_messages('Y',
1036 x_msg_summary,
1037 x_msg_details,
1038 x_msg_count);
1039 IF x_msg_count > 1
1040 THEN
1041 x_msg_data := x_msg_summary || x_msg_details;
1042 ELSE
1043 x_msg_data := x_msg_summary;
1044 END IF;
1045 IF (g_debug > 0)
1046 THEN
1047 Csd_Gen_Utility_Pvt.ADD('Error Msg from Update_Shipping_Attributes');
1048 Csd_Gen_Utility_Pvt.ADD('x_msg_data = ' ||
1049 x_msg_data);
1050 END IF;
1051 Fnd_Message.SET_NAME('CSD',
1052 'CSD_UPDATE_SHIPPING_FAILED');
1053 Fnd_Message.SET_TOKEN('ERR_MSG', x_msg_data);
1054 Fnd_Msg_Pub.ADD;
1055 RAISE Fnd_Api.G_EXC_ERROR;
1056 END;
1057
1058 END IF; --end of update_shipping_attributes
1059
1060 END LOOP;
1061
1062 BEGIN
1063
1064 IF (g_debug > 0)
1065 THEN
1066 Csd_Gen_Utility_Pvt.ADD('p_delivery_id=' || p_delivery_id);
1067 END IF;
1068
1069 -- Values for Ship Confirming the delivery.
1070 p_action_code := 'CONFIRM'; -- The action code for ship confirm
1071 p_delivery_id := p_delivery_id; -- The delivery that needs to be confirmed
1072 p_delivery_name := TO_CHAR(p_delivery_id); -- The delivery name,
1073 p_sc_action_flag := 'S'; -- Ship entered quantity.
1074 -- p_Sc_Intransit_flag needs to be set to 'Y' this as per bug 3676488 (Shipping)
1075 -- This fix for bug# 3665544
1076 p_sc_intransit_flag := 'Y'; -- In transit flag is set to 'Y' closes the
1077 -- pickup stop and sets the delivery in transit.
1078 p_sc_close_trip_flag := 'Y'; -- Close the trip after ship confirm
1079 -- p_sc_trip_ship_method := ''; -- The ship method code
1080 p_sc_defer_interface_flag := 'N'; -- defer interface
1081 -- p_sc_report_set_id := 6; -- check if it is seeded
1082
1083 IF (g_debug > 0)
1084 THEN
1085 Csd_Gen_Utility_Pvt.ADD('Calling Delivery_Action ');
1086 END IF;
1087
1088 -- Call to WSH_DELIVERIES_PUB.Delivery_Action.
1089 Wsh_Deliveries_Pub.Delivery_Action(p_api_version_number => 1.0,
1090 p_init_msg_list => p_init_msg_list,
1091 x_return_status => x_return_status,
1092 x_msg_count => x_msg_count,
1093 x_msg_data => x_msg_data,
1094 p_action_code => p_action_code,
1095 p_delivery_id => p_delivery_id,
1096 p_delivery_name => p_delivery_name,
1097 p_asg_trip_id => p_asg_trip_id,
1098 p_asg_trip_name => p_asg_trip_name,
1099 p_asg_pickup_stop_id => p_asg_pickup_stop_id,
1100 p_asg_pickup_loc_id => p_asg_pickup_loc_id,
1101 p_asg_pickup_loc_code => p_asg_pickup_loc_code,
1102 p_asg_pickup_arr_date => p_asg_pickup_arr_date,
1103 p_asg_pickup_dep_date => p_asg_pickup_dep_date,
1104 p_asg_dropoff_stop_id => p_asg_dropoff_stop_id,
1105 p_asg_dropoff_loc_id => p_asg_dropoff_loc_id,
1106 p_asg_dropoff_loc_code => p_asg_dropoff_loc_code,
1107 p_asg_dropoff_arr_date => p_asg_dropoff_arr_date,
1108 p_asg_dropoff_dep_date => p_asg_dropoff_dep_date,
1109 p_sc_action_flag => p_sc_action_flag,
1110 p_sc_intransit_flag => p_sc_intransit_flag,
1111 p_sc_close_trip_flag => p_sc_close_trip_flag,
1112 p_sc_create_bol_flag => p_sc_create_bol_flag,
1113 p_sc_stage_del_flag => p_sc_stage_del_flag,
1114 p_sc_trip_ship_method => p_sc_trip_ship_method,
1115 p_sc_actual_dep_date => p_sc_actual_dep_date,
1116 p_sc_report_set_id => p_sc_report_set_id,
1117 p_sc_report_set_name => p_sc_report_set_name,
1118 p_sc_defer_interface_flag => p_sc_defer_interface_flag,
1119 p_wv_override_flag => p_wv_override_flag,
1120 x_trip_id => x_trip_id,
1121 x_trip_name => x_trip_name);
1122
1123 IF (g_debug > 0)
1124 THEN
1125 Csd_Gen_Utility_Pvt.ADD('x_return_status(Delivery_Action )=' ||
1126 x_return_status);
1127 END IF;
1128
1129 IF (x_return_status <> Wsh_Util_Core.G_RET_STS_SUCCESS)
1130 THEN
1131 IF (g_debug > 0)
1132 THEN
1133 Csd_Gen_Utility_Pvt.ADD('Delivery_Action failed');
1134 END IF;
1135 RAISE fail_api;
1136 END IF;
1137 EXCEPTION
1138 WHEN fail_api THEN
1139 Wsh_Util_Core.get_messages('Y',
1140 x_msg_summary,
1141 x_msg_details,
1142 x_msg_count);
1143 IF x_msg_count > 1
1144 THEN
1145 x_msg_data := x_msg_summary || x_msg_details;
1146 ELSE
1147 x_msg_data := x_msg_summary;
1148 END IF;
1149 IF (g_debug > 0)
1150 THEN
1151 Csd_Gen_Utility_Pvt.ADD('Error Msg from Delivery_Action');
1152 Csd_Gen_Utility_Pvt.ADD('x_msg_data = ' || x_msg_data);
1153 END IF;
1154
1155 -- Ignore if it is a warning
1156 IF (x_return_status <> Wsh_Util_Core.G_RET_STS_WARNING)
1157 THEN
1158 Fnd_Message.SET_NAME('CSD', 'CSD_SHIP_CONFIRM_FAILED');
1159 Fnd_Message.SET_TOKEN('ERR_MSG', x_msg_data);
1160 Fnd_Msg_Pub.ADD;
1161 RAISE Fnd_Api.G_EXC_ERROR;
1162 END IF;
1163
1164 END; -- end of delivery action
1165
1166 -- Api body ends here
1167
1168 -- Standard check of p_commit.
1169 IF Fnd_Api.To_Boolean(p_commit)
1170 THEN
1171 COMMIT WORK;
1172 END IF;
1173
1174 -- Standard call to get message count and IF count is get message info.
1175 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1176 p_data => x_msg_data);
1177
1178 EXCEPTION
1179 WHEN Fnd_Api.G_EXC_ERROR THEN
1180 ROLLBACK TO ship_sales_order;
1181 x_return_status := Fnd_Api.G_RET_STS_ERROR;
1182 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1183 p_data => x_msg_data);
1184 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
1185 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
1186 ROLLBACK TO ship_sales_order;
1187 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1188 p_data => x_msg_data);
1189 WHEN OTHERS THEN
1190 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
1191 ROLLBACK TO ship_sales_order;
1192 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
1193 THEN
1194 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
1195 END IF;
1196 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1197 p_data => x_msg_data);
1198 END ship_sales_order;
1199
1200
1201 /********************************************************
1202 procedure dbg_print_stack(p_msg_count number, p_mod_name varchar2) is
1203 l_msg varchar2(2000);
1204 l_stat_level NUMBER := Fnd_Log.LEVEL_STATEMENT;
1205
1206 begin
1207 IF p_MSG_COUNT > 1 THEN
1208 FOR i IN 1..p_MSG_COUNT LOOP
1209 l_msg := apps.FND_MSG_PUB.Get(i,apps.FND_API.G_FALSE) ;
1210 Fnd_Log.STRING(l_stat_level, p_mod_name, l_msg);
1211 END LOOP ;
1212 ELSE
1213 l_msg := apps.FND_MSG_PUB.Get(1,apps.FND_API.G_FALSE) ;
1214 Fnd_Log.STRING(l_stat_level, p_mod_name, l_msg);
1215 END IF ;
1216
1217 end dbg_print_stack;
1218 ************************************************************/
1219
1220 /*--------------------------------------------------*/
1221 /* procedure name: process_sales_order */
1222 /* description : procedure used to create/book */
1223 /* release and ship sales Order */
1224 /* */
1225 /*--------------------------------------------------*/
1226
1227 PROCEDURE process_sales_order(p_api_version IN NUMBER,
1228 p_commit IN VARCHAR2 := Fnd_Api.g_false,
1229 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_false,
1230 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
1231 p_action IN VARCHAR2,
1232 /*Fixed for bug#4433942 added product
1233 txn record as in parameter
1234 */
1235 p_product_txn_rec IN PRODUCT_TXN_REC default null,
1236 p_order_rec IN OUT NOCOPY OM_INTERFACE_REC,
1237 x_return_status OUT NOCOPY VARCHAR2,
1238 x_msg_count OUT NOCOPY NUMBER,
1239 x_msg_data OUT NOCOPY VARCHAR2) IS
1240 l_api_name CONSTANT VARCHAR2(30) := 'PROCESS_SALES_ORDER';
1241 l_api_version CONSTANT NUMBER := 1.0;
1242 l_msg_count NUMBER;
1243 l_msg_data VARCHAR2(2000);
1244 l_msg_index NUMBER;
1245 p_rule_id NUMBER := p_order_rec.picking_rule_id;
1246 l_batch_name VARCHAR2(30);
1247 l_batch_id NUMBER;
1248 l_temp NUMBER;
1249 l_user_id NUMBER;
1250 l_login_id NUMBER;
1251 l_dummy1 VARCHAR2(2000);
1252 l_dummy2 VARCHAR2(10);
1253 l_ret_code BOOLEAN;
1254 p_batch_prefix VARCHAR2(10) := 'DR';
1255 x_order_header_id NUMBER;
1256
1257 l_header_rec Aso_Quote_Pub.Qte_Header_Rec_Type;
1258 l_line_tbl Aso_Quote_Pub.Qte_Line_Tbl_Type;
1259 l_Line_dtl_tbl Aso_Quote_Pub.Qte_Line_Dtl_Tbl_Type;
1260 l_hd_shipment_rec Aso_Quote_Pub.Shipment_rec_Type;
1261 l_hd_shipment_tbl Aso_Quote_Pub.Shipment_tbl_Type;
1262 l_ln_shipment_tbl Aso_Quote_Pub.Shipment_Tbl_Type;
1263 l_hd_payment_tbl Aso_Quote_Pub.Payment_Tbl_Type;
1264 l_line_price_adj_tbl Aso_Quote_Pub.Price_Adj_Tbl_Type;
1265 x_order_header_rec Aso_Order_Int.Order_Header_rec_type;
1266 x_order_line_tbl Aso_Order_Int.Order_Line_tbl_type;
1267 l_control_rec Aso_Order_Int.control_rec_type;
1268
1269 -- Parameters for WSH_DELIVERIES_PUB.Delivery_Action.
1270 p_delivery_id NUMBER;
1271 p_action_code VARCHAR2(15);
1272 p_delivery_name VARCHAR2(30);
1273 p_asg_trip_id NUMBER;
1274 p_asg_trip_name VARCHAR2(30);
1275 p_asg_pickup_stop_id NUMBER;
1276 p_asg_pickup_loc_id NUMBER;
1277 p_asg_pickup_loc_code VARCHAR2(30);
1278 p_asg_pickup_arr_date DATE;
1279 p_asg_pickup_dep_date DATE;
1280 p_asg_dropoff_stop_id NUMBER;
1281 p_asg_dropoff_loc_id NUMBER;
1282 p_asg_dropoff_loc_code VARCHAR2(30);
1283 p_asg_dropoff_arr_date DATE;
1284 p_asg_dropoff_dep_date DATE;
1285 p_sc_action_flag VARCHAR2(10);
1286 p_sc_intransit_flag VARCHAR2(10);
1287 p_sc_close_trip_flag VARCHAR2(10);
1288 p_sc_create_bol_flag VARCHAR2(10);
1289 p_sc_stage_del_flag VARCHAR2(10);
1290 p_sc_trip_ship_method VARCHAR2(30);
1291 p_sc_actual_dep_date VARCHAR2(30);
1292 p_sc_defer_interface_flag VARCHAR2(1);
1293 p_sc_report_set_id NUMBER;
1294 p_sc_report_set_name VARCHAR2(60);
1295 p_wv_override_flag VARCHAR2(10);
1296 x_trip_id VARCHAR2(30);
1297 x_trip_name VARCHAR2(30);
1298 x_msg_details VARCHAR2(3000);
1299 x_msg_summary VARCHAR2(3000);
1300 l_customer_id NUMBER := NULL;
1301 l_order_type_id NUMBER := NULL;
1302 l_document_set_id NUMBER := NULL;
1303 l_sub_inventory VARCHAR2(30) := '';
1304 l_Organization_Id NUMBER := NULL;
1305 l_org_id NUMBER;
1306 l_locator_id NUMBER;
1307 lx_Request_ID Number ; -- R12 : SU
1308
1309 --bug#6071005
1310 l_delivery_detail_id NUMBER := NULL;
1311
1312 /*Fixed bug#4433942 following variable has been defined */
1313 C_SRL_NUM_Cnt_Code_SO_ISSUE Constant Number := 6 ;
1314 l_revision VARCHAR2(10);
1315 l_shipped_serial_number VARCHAR2(30);
1316 l_lot_number VARCHAR2(80); -- fix for bug#4625226
1317 l_SN_at_SO_new_SN_number BOOLEAN; /*This flag is true when user provide new SN for serialized item at SO */
1318
1319 --Parameters for WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes.
1320 source_code VARCHAR2(15);
1321 changed_attributes Wsh_Delivery_Details_Pub.ChangedAttributeTabType;
1322
1323
1324 --bug#7675562
1325 l_ship_param_info WSH_SHIPPING_PARAMS_GRP.Shipping_Params_Rec;
1326
1327
1328 /*Handle exceptions*/
1329 fail_api EXCEPTION;
1330
1331 -- bug#8269688, FP of bug#7659800, subhat
1332 l_shipped_flag varchar2(1);
1333 -- end bug#8269688, FP of bug#7659800, subhat
1334
1335 CURSOR pick_rule(x_rule_id IN NUMBER) IS
1336 SELECT PICKING_RULE_ID
1337 FROM WSH_PICKING_RULES
1338 WHERE PICKING_RULE_ID = x_rule_id
1339 AND SYSDATE BETWEEN NVL(START_DATE_ACTIVE, SYSDATE) AND
1340 NVL(END_DATE_ACTIVE, SYSDATE + 1);
1341
1342 CURSOR batch(x_batch_name IN VARCHAR2) IS
1343 SELECT batch_id
1344 FROM WSH_PICKING_BATCHES
1345 WHERE NAME = x_batch_name;
1346
1347 CURSOR move_order(x_batch_name IN VARCHAR2) IS
1348 SELECT header_id
1349 FROM MTL_TXN_REQUEST_HEADERS
1350 WHERE request_number = x_batch_name;
1351
1352 CURSOR customer(p_ord_header_id IN NUMBER) IS
1353 SELECT a.sold_to_org_id,
1354 a.order_type_id,
1355 a.source_document_type_id
1356 FROM oe_order_headers_all a
1357 WHERE a.header_id = p_ord_header_id;
1358
1359 CURSOR delivery(p_ord_header_id IN NUMBER, p_ord_line_id IN NUMBER) IS
1360 SELECT b.delivery_id,
1361 a.delivery_detail_id,
1362 c.serial_number_control_code,
1363 /* Fix for bug# 4433942 */
1364 c.lot_control_code,
1365 c.revision_qty_control_code,
1366 c.reservable_type,
1367 a.organization_id,
1368 a.inventory_item_id,
1369 c.segment1 item_name,
1370 p.organization_code
1371 FROM wsh_delivery_details a,
1372 --Changed to view from table, bug: 4341784
1373 wsh_delivery_assignments_v b,
1374 mtl_system_items c,
1375 mtl_parameters p
1376 WHERE a.delivery_detail_id = b.delivery_detail_id
1377 AND a.inventory_item_id = c.inventory_item_id
1378 AND a.organization_id = c.organization_id
1379 AND a.released_status = 'Y'
1380 AND a.SOURCE_CODE = 'OE' /*Fixed for bug#5846054*/
1381 AND a.source_header_id = p_ord_header_id
1382 AND a.source_line_id = p_ord_line_id
1383 AND a.organization_id = p.organization_id;
1384
1385 CURSOR c_get_org_id (p_header_id IN NUMBER) IS
1386 SELECT org_id
1387 FROM oe_order_headers_all
1388 WHERE header_id = p_header_id;
1389
1390 -- Variables used in FND Log
1391 l_error_level NUMBER := Fnd_Log.LEVEL_ERROR;
1392 l_mod_name VARCHAR2(2000) := 'csd.plsql.csd_process_pvt.process_sales_order';
1393
1394 /* pick release rule api changes/srl reservations changes *
1395 */
1396 l_batch_rec WSH_PICKING_BATCHES_PUB.Batch_Info_Rec ;
1397 l_ret_status varchar2(1);
1398 l_reservation_id number;
1399
1400 cursor c_srl_reservation(p_srl_num varchar2, p_item_id number) is
1401 select reservation_id from mtl_Serial_numbers
1402 where serial_number = p_srl_num
1403 and inventory_item_Id = p_item_id;
1404
1405 --bug#6071005
1406 cursor get_delivery_detail_id(p_order_header_id IN NUMBER, p_order_line_id IN NUMBER) IS
1407 select delivery_detail_id
1408 from wsh_Delivery_Details
1409 where source_header_id = p_order_header_id and source_line_id = p_order_line_id;
1410
1411
1412 BEGIN
1413 -- Debug message
1414 Debug('At the Beginning of process_sales_order', l_mod_name, 1);
1415
1416 -- Standard Start of API savepoint
1417 SAVEPOINT process_sales_order;
1418
1419 -- Standard call to check for call compatibility.
1420 IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
1421 p_api_version,
1422 l_api_name,
1423 G_PKG_NAME)
1424 THEN
1425 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
1426 END IF;
1427
1428 -- Initialize message list if p_init_msg_list is set to TRUE.
1429 IF Fnd_Api.to_Boolean(p_init_msg_list)
1430 THEN
1431 Fnd_Msg_Pub.initialize;
1432 END IF;
1433
1434 -- Initialize API return status to success
1435 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
1436
1437 -- Api body starts
1438
1439 -- dbms_application_info.set_client_info('204');
1440 -- fnd_global.apps_initialize(1000200,52284,512,0);
1441
1442 Debug('Validate the action code', l_mod_name, 1);
1443
1444 -- Validate the action code
1445 IF NOT (Csd_Process_Util.VALIDATE_ACTION(p_action, l_api_name))
1446 THEN
1447 RAISE Fnd_Api.G_EXC_ERROR;
1448 END IF;
1449
1450 IF p_action = 'CREATE'
1451 THEN
1452
1453 -- If action is CREATE, then call charges private api to
1454 -- create sales order
1455 Debug('Creating the Sales Order', l_mod_name, 1);
1456 Debug('p_order_rec.incident_id =' || p_order_rec.incident_id,
1457 l_mod_name,
1458 1);
1459 Debug('p_order_rec.party_id =' || p_order_rec.party_id,
1460 l_mod_name,
1461 1);
1462 Debug('p_order_rec.account_id =' || p_order_rec.account_id,
1463 l_mod_name,
1464 1);
1465
1466 Cs_Charge_Create_Order_Pub.Submit_Order(p_api_version => 1.0,
1467 p_init_msg_list => p_init_msg_list,
1468 p_commit => p_commit,
1469 p_validation_level => p_validation_level,
1470 p_incident_id => p_order_rec.incident_id,
1471 p_party_id => p_order_rec.party_id,
1472 p_account_id => p_order_rec.account_id,
1473 p_book_order_flag => 'N',
1474 x_return_status => x_return_status,
1475 x_msg_count => x_msg_count,
1476 x_msg_data => x_msg_data);
1477
1478 Debug('Return Status from Submit_Order' || x_return_status,
1479 l_mod_name,
1480 1);
1481
1482 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
1483 THEN
1484 Debug('Submit_Order API failed ', l_mod_name, 1);
1485 RAISE Fnd_Api.G_EXC_ERROR;
1486 END IF;
1487
1488 ELSIF p_action = 'BOOK'
1489 THEN
1490
1491 -- If action is BOOK, then call charges private api to
1492 -- book the sales order
1493 Debug('Booking the Sales Order', l_mod_name, 1);
1494 Debug('p_order_rec.order_header_id =' ||
1495 p_order_rec.order_header_id,
1496 l_mod_name,
1497 1);
1498 Debug('p_order_rec.org_id =' || p_order_rec.org_id,
1499 l_mod_name,
1500 1);
1501
1502 l_header_rec.org_id := p_order_rec.org_id;
1503 l_header_rec.order_id := p_order_rec.order_header_id;
1504 l_control_rec.book_flag := Fnd_Api.G_TRUE;
1505 l_control_rec.calculate_price := Fnd_Api.G_FALSE;
1506
1507 open c_get_org_id(p_order_rec.order_header_id);
1508 fetch c_get_org_id into l_org_id;
1509 close c_get_org_id;
1510
1511
1512 -- Set the Policy context as required for MOAC Uptake, Bug#4421242
1513 mo_global.set_policy_context('S',l_org_id);
1514
1515
1516 Aso_Order_Int.Update_order(P_Api_Version_Number => 1.0,
1517 P_Init_Msg_List => Fnd_Api.G_TRUE,
1518 P_Commit => Fnd_Api.G_FALSE,
1519 P_Qte_Rec => l_header_rec,
1520 P_Qte_Line_Tbl => l_line_tbl,
1521 P_Qte_Line_Dtl_Tbl => l_line_dtl_tbl,
1522 P_Line_Shipment_Tbl => l_ln_shipment_tbl,
1523 P_Header_Payment_Tbl => l_hd_payment_tbl,
1524 P_Line_Price_Adj_Tbl => l_line_price_adj_tbl,
1525 P_Control_Rec => l_control_rec,
1526 X_Order_Header_Rec => x_order_header_rec,
1527 X_Order_Line_Tbl => x_order_line_tbl,
1528 X_Return_Status => x_return_status,
1529 X_Msg_Count => x_msg_count,
1530 X_Msg_Data => x_msg_data);
1531
1532 -- Change the Policy context back to multiple
1533 mo_global.set_policy_context('M',null);
1534
1535 Debug('Return Status from Update_order' || x_return_status,
1536 l_mod_name,
1537 1);
1538
1539 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
1540 THEN
1541 Debug('ASO_ORDER_INT.UPDATE_ORDER failed', l_mod_name, 1);
1542 RAISE Fnd_Api.G_EXC_ERROR;
1543 END IF;
1544
1545 ELSIF p_action = 'PICK-RELEASE'
1546 THEN
1547
1548 Debug('Releasing Sales Order', l_mod_name, 1);
1549 Debug('p_order_rec.order_header_id =' ||
1550 p_order_rec.order_header_id,
1551 l_mod_name,
1552 1);
1553
1554 -- If action is BOOK, then call charges private api to
1555 -- book the sales order
1556
1557 IF NVL(p_order_rec.order_header_id, Fnd_Api.G_MISS_NUM) =
1558 Fnd_Api.G_MISS_NUM
1559 THEN
1560 Fnd_Message.SET_NAME('CSD', 'CSD_INV_ORDER_HEADER_ID');
1561 Fnd_Message.SET_TOKEN('ORDER_HEADER_ID',
1562 p_order_rec.order_header_id);
1563 Fnd_Msg_Pub.ADD;
1564 Debug('Invalid Order header Id is passed ', l_mod_name, 1);
1565 RAISE Fnd_Api.G_EXC_ERROR;
1566 END IF;
1567
1568 IF NVL(p_order_rec.PICKING_RULE_ID, Fnd_Api.G_MISS_NUM) =
1569 Fnd_Api.G_MISS_NUM
1570 THEN
1571 Fnd_Message.SET_NAME('CSD', 'CSD_INV_PICKING_RULE_ID');
1572 Fnd_Message.SET_TOKEN('PICKING_RULE_ID',
1573 p_order_rec.PICKING_RULE_ID);
1574 Fnd_Msg_Pub.ADD;
1575 Debug('Invalid Picking rule Id is passed ', l_mod_name, 1);
1576 RAISE Fnd_Api.G_EXC_ERROR;
1577 END IF;
1578
1579 -- Fetch user and login information
1580 l_user_id := Fnd_Global.USER_ID;
1581 l_login_id := Fnd_Global.CONC_LOGIN_ID;
1582
1583 -- Validate Picking Rule
1584 OPEN pick_rule(p_order_rec.PICKING_RULE_ID);
1585 FETCH pick_rule
1586 INTO l_temp;
1587 IF pick_rule%NOTFOUND
1588 THEN
1589 Debug('The picking rule ' || p_order_rec.PICKING_RULE_ID ||
1590 'does not exist or has expired',
1591 l_mod_name,
1592 1);
1593 CLOSE pick_rule;
1594 RAISE Fnd_Api.G_EXC_ERROR;
1595 END IF;
1596 IF pick_rule%ISOPEN
1597 THEN
1598 CLOSE pick_rule;
1599 END IF;
1600
1601 -- Get the customer/order details
1602 OPEN customer(p_order_rec.order_header_id);
1603 FETCH customer
1604 INTO l_customer_id, l_order_type_id, l_document_set_id;
1605
1606 IF customer%NOTFOUND
1607 THEN
1608 Debug('invalid order header id ', l_mod_name, 1);
1609 CLOSE customer;
1610 RAISE Fnd_Api.G_EXC_ERROR;
1611 END IF;
1612
1613 IF customer%ISOPEN
1614 THEN
1615 CLOSE customer;
1616 END IF;
1617
1618 IF NVL(p_order_rec.org_id, Fnd_Api.G_MISS_NUM) =
1619 Fnd_Api.G_MISS_NUM
1620 THEN
1621 l_Organization_Id := NULL;
1622 ELSIF p_Order_Rec.Org_Id IS NULL
1623 THEN
1624 l_Organization_Id := NULL;
1625 ELSE
1626 l_Organization_Id := p_order_rec.org_id;
1627 END IF;
1628
1629 IF NVL(p_order_rec.pick_from_subinventory, Fnd_Api.G_MISS_CHAR) =
1630 Fnd_Api.G_MISS_CHAR
1631 THEN
1632 l_sub_inventory := '';
1633 ELSIF p_Order_Rec.Pick_From_Subinventory IS NULL
1634 THEN
1635 l_Sub_Inventory := '';
1636 ELSE
1637 l_sub_inventory := p_order_rec.pick_from_subinventory;
1638 END IF;
1639
1640 -- Fix for Enh Req#3948563
1641 IF ((p_order_rec.locator_id is null) or (p_order_rec.locator_id = FND_API.G_MISS_NUM)) THEN
1642 l_locator_id := null;
1643 ELSE
1644 l_locator_id := p_order_rec.locator_id;
1645 END IF;
1646
1647 --bug#6071005
1648 --'A' means "All ship lines in an order",
1649 --'S' menas "Selected ship line only"
1650 --if the profile value set to "Selected ship line only", then pass the delivery_detail_id
1651 --else it will pass null value to delivery_detail_id.
1652 If (fnd_profile.value('CSD_PROCESS_AUTO_PICK_RELEASE') = 'S') then
1653 open get_delivery_detail_id(p_order_rec.order_header_id, p_order_rec.order_line_id);
1654 fetch get_delivery_detail_id into l_delivery_detail_id;
1655 close get_delivery_detail_id;
1656 End if;
1657
1658 --R12 : SU Putting Insert statement in Begin and End Block
1659
1660 Begin
1661 SELECT NVL(DOCUMENT_SET_ID, l_document_set_id),
1662 'I', -- Include backorders also 11.5.10 saupadhy: BACKORDERS_ONLY_FLAG,
1663 NVL(EXISTING_RSVS_ONLY_FLAG, 'N'),
1664 SHIPMENT_PRIORITY_CODE,
1665 p_order_rec.order_header_id,
1666 l_delivery_detail_id, --bug#6071005
1667 l_order_type_id,
1668 NULL, --SHIP_FROM_LOCATION_ID,
1669 l_customer_id,
1670 NULL, --SHIP_TO_LOCATION_ID,
1671 SHIP_METHOD_CODE,
1672 NVL(l_Sub_Inventory, PICK_FROM_SUBINVENTORY),
1673 NVL(l_locator_id,PICK_FROM_LOCATOR_ID), -- Fix for Enh Req#3948563 NULL, --PICK_FROM_LOCATOR_ID,
1674 DEFAULT_STAGE_SUBINVENTORY,
1675 DEFAULT_STAGE_LOCATOR_ID,
1676 AUTODETAIL_PR_FLAG,
1677 AUTO_PICK_CONFIRM_FLAG,
1678 SHIP_SET_NUMBER,
1679 NULL, --INVENTORY_ITEM_ID,
1680 NULL,
1681 NULL,
1682 NULL,
1683 NULL,
1684 PICK_GROUPING_RULE_ID,
1685 PICK_SEQUENCE_RULE_ID,
1686 NVL(l_Organization_Id, ORGANIZATION_ID),
1687 PROJECT_ID,
1688 TASK_ID,
1689 INCLUDE_PLANNED_LINES,
1690 AUTOCREATE_DELIVERY_FLAG
1691 INTO
1692 l_batch_rec.Document_set_id,
1693 l_batch_Rec.Backorders_only_flag,
1694 l_batch_rec.Existing_Rsvs_Only_Flag,
1695 l_batch_rec.Shipment_Priority_Code,
1696 l_batch_rec.order_header_id,
1697 l_batch_rec.delivery_detail_id, --bug#6071005
1698 l_batch_rec.order_type_id,
1699 l_batch_rec.ship_from_location_id,
1700 l_batch_rec.customer_id,
1701 l_batch_rec.ship_to_location_id,
1702 l_batch_rec.ship_method_code,
1703 l_batch_rec.pick_from_subinventory,
1704 l_batch_rec.pick_from_locator_id,
1705 l_batch_rec.default_stage_subinventory,
1706 l_batch_rec.default_stage_locator_id,
1707 l_batch_rec.autodetail_pr_flag,
1708 l_batch_rec.auto_pick_confirm_flag,
1709 l_batch_rec.ship_set_number,
1710 l_batch_rec.inventory_item_id,
1711 l_batch_rec.From_requested_date,
1712 l_batch_rec.to_Requested_date,
1713 l_batch_rec.from_scheduled_ship_date,
1714 l_batch_Rec.to_scheduled_ship_date,
1715 l_batch_Rec.pick_grouping_rule_id,
1716 l_batch_rec.pick_sequence_rule_id,
1717 l_batch_rec.organization_id,
1718 l_batch_rec.project_id,
1719 l_batch_rec.task_id,
1720 l_batch_rec.Include_Planned_Lines,
1721 l_batch_rec.Autocreate_Delivery_Flag
1722 FROM WSH_PICKING_RULES
1723 WHERE PICKING_RULE_ID = p_order_rec.PICKING_RULE_ID;
1724
1725
1726 Exception
1727 WHEN OTHERS THEN
1728 Fnd_Message.SET_NAME('CSD', 'CSD_PICK_RELEASE_FAIL');
1729 Fnd_Message.SET_TOKEN('BATCH_NAME', l_batch_name);
1730 Fnd_Msg_Pub.ADD;
1731 Debug(' Picking rules insert failed ',l_mod_name, 1);
1732 RAISE Fnd_Api.G_EXC_ERROR;
1733 End ;
1734
1735 /* override the auto pick confirm flag if the serial_number is reserved. */
1736 Debug(' serial_number['||p_product_txn_rec.source_serial_number||']',l_mod_name, 1);
1737 Debug(' item['||to_char(p_product_txn_rec.inventory_item_id)||']',l_mod_name, 1);
1738 if(nvl(p_product_txn_rec.source_serial_number,FND_API.G_MISS_CHAR) <> FND_API.G_MISS_CHAR) then
1739 Open c_srl_reservation(p_product_txn_rec.source_serial_number, p_product_txn_rec.inventory_item_Id);
1740 FETCH c_Srl_reservation into l_reservation_Id;
1741 if(c_Srl_reservation%notfound)then
1742 l_reservation_id := null;
1743 end if;
1744 Close c_srl_reservation;
1745 Debug(' rsv_id['||to_char(nvl(l_reservation_id,0))||']',l_mod_name, 1);
1746 if(l_reservation_Id is not null) then
1747 l_batch_rec.auto_pick_confirm_flag := 'Y';
1748 end if;
1749 end if;
1750 Debug(' pick_confirm_flag['||l_batch_Rec.auto_pick_confirm_flag||']',l_mod_name, 1);
1751
1752 WSH_PICKING_BATCHES_GRP.Create_Batch(
1753 p_api_version_number => 1.0,
1754 p_init_msg_list => FND_API.G_FALSE,
1755 p_commit => FND_API.G_FALSE,
1756 x_return_status => l_ret_status,
1757 x_msg_count => l_msg_count,
1758 x_msg_data => l_msg_data,
1759 p_rule_id => p_order_rec.PICKING_RULE_ID,
1760 p_rule_name => null,
1761 p_batch_rec => l_batch_rec,
1762 p_batch_prefix => p_batch_prefix,
1763 x_batch_id => l_batch_id);
1764
1765 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
1766 THEN
1767 Debug('WSH_PICKINGBATCHES_GRP.Create_batch failed', l_mod_name, 1);
1768 RAISE Fnd_Api.G_EXC_ERROR;
1769 END IF;
1770 Debug('Batch created batch_id=['||l_batch_id||']',l_mod_name,1);
1771
1772 wsh_picking_batches_pub.Release_Batch (
1773 -- Standard parameters
1774 p_api_version => 1.0,
1775 p_init_msg_list => Fnd_API.G_False,
1776 p_commit => Fnd_API.G_False,
1777 x_return_status => x_Return_Status,
1778 x_msg_count => x_Msg_Count,
1779 x_msg_data => x_Msg_Data,
1780 -- program specific paramters.
1781 p_batch_id => l_Batch_ID,
1782 p_batch_name => l_Batch_Name,
1783 p_log_level => NULL,
1784 p_release_mode => 'ONLINE',
1785 x_request_id => lx_Request_ID ) ;
1786
1787 Debug('After release Batch, msg_data['||x_msg_data||']' ||
1788 'x_return_status=['||x_return_status||']', l_mod_name,1);
1789 --dbg_print_stack(x_msg_count, l_mod_name);
1790
1791 -- begin bug#9369021 , nnadig
1792 IF x_return_status = wsh_util_core.g_ret_sts_warning THEN
1793 Debug('release batch returning warning - interpreting that as success!', l_mod_name,1);
1794 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
1795 END IF;
1796 -- end bug#9369021
1797
1798
1799 IF (x_return_status = Fnd_Api.G_RET_STS_ERROR)
1800 THEN
1801 Fnd_Message.SET_NAME('CSD', 'CSD_PICK_RELEASE_FAIL');
1802 Fnd_Message.SET_TOKEN('BATCH_NAME', l_batch_name);
1803 Fnd_Msg_Pub.ADD;
1804 Debug('WSH_PICK_LIST.RELEASE_BATCH failed for batch : ' ||
1805 l_batch_name,
1806 l_mod_name,1) ;
1807 RAISE Fnd_Api.G_EXC_ERROR;
1808 END IF;
1809 Debug('Batch processed, req_id=['||lx_request_id||']',l_mod_name,1);
1810
1811 ELSIF p_action = 'SHIP'
1812 THEN
1813
1814 -- If action is SHIP, then call shipping api to ship the sales order
1815 Debug('Shipping the Sales Order', l_mod_name, 1);
1816 Debug('p_order_rec.order_header_id =' ||
1817 p_order_rec.order_header_id,
1818 l_mod_name,
1819 1);
1820
1821 IF NVL(p_order_rec.order_header_id, Fnd_Api.G_MISS_NUM) =
1822 Fnd_Api.G_MISS_NUM
1823 THEN
1824 Fnd_Message.SET_NAME('CSD', 'CSD_INV_ORDER_HEADER_ID');
1825 Fnd_Message.SET_TOKEN('ORDER_HEADER_ID',
1826 p_order_rec.order_header_id);
1827 Fnd_Msg_Pub.ADD;
1828 Debug('Order_header_id is invalid', l_mod_name, 1);
1829 RAISE Fnd_Api.G_EXC_ERROR;
1830 END IF;
1831
1832 FOR i IN delivery(p_order_rec.order_header_id,
1833 p_order_rec.order_line_id)
1834 LOOP
1835
1836 /* Fix for bug#4433942 -- Code Commented
1837 -- In case of serialized item, update the serial number on the
1838 -- delivery line details
1839 -- Update the serial number on the delivery lines only if the item
1840 -- is serialized at SO issue
1841 IF i.serial_number_control_code = 6 AND
1842 NVL(p_order_rec.serial_number, Fnd_Api.G_MISS_CHAR) <>
1843 Fnd_Api.G_MISS_CHAR
1844 THEN
1845
1846 BEGIN
1847 source_code := 'OE'; -- The only source code that should be used by the API
1848 changed_attributes(1).delivery_detail_id := i.delivery_detail_id;
1849 changed_attributes(1).serial_number := p_order_rec.serial_number;
1850 changed_attributes(1).shipped_quantity := p_order_rec.shipped_quantity;
1851
1852 Debug('delivery_detail_id =' ||
1853 changed_attributes(1).delivery_detail_id,
1854 l_mod_name,
1855 1);
1856 Debug('serial_number =' ||
1857 changed_attributes(1).serial_number,
1858 l_mod_name,
1859 1);
1860 Debug('shipped_quantity =' ||
1861 changed_attributes(1).shipped_quantity,
1862 l_mod_name,
1863 1);
1864 Debug('Calling Update_Shipping_Attributes',
1865 l_mod_name,
1866 1);
1867
1868 --Call to WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes.
1869 Wsh_Delivery_Details_Pub.Update_Shipping_Attributes(p_api_version_number => 1.0,
1870 p_init_msg_list => p_init_msg_list,
1871 p_commit => p_commit,
1872 x_return_status => x_return_status,
1873 x_msg_count => x_msg_count,
1874 x_msg_data => x_msg_data,
1875 p_changed_attributes => changed_attributes,
1876 p_source_code => source_code);
1877
1878 Debug('x_return_status(Update_Shipping_Attributes )=' ||
1879 x_return_status,
1880 l_mod_name,
1881 1);
1882
1883 IF (x_return_status <>
1884 Wsh_Util_Core.G_RET_STS_SUCCESS)
1885 THEN
1886 Debug('Update_Shipping_Attributes failed',
1887 l_mod_name,
1888 1);
1889 RAISE fail_api;
1890 END IF; */
1891
1892 /*Fixed for bug#4433942
1893 Psuedo code for new solution is as follows:
1894 If Item is Reservable then
1895 Check if item is Serial Controlled @ SO Issue
1896 ( This is existing solution and it will continue to stay
1897 If item is serial controlled at Sales Order issue then
1898 Call API WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes
1899 and update with serial_number and quantity.
1900 End If;
1901 Else If Item is Non-Reservable
1902 If Item is serial Controlled then
1903 Get Lot_Number, Revision, Sub Inventory Information from
1904 Mtl_Serial_numbers for a given serial_number, item_id,organization_id
1905
1906 Call API WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes and
1907 Update Serial_Number, Quantity ( will be 1 for serial controlled
1908 items), lot_number, Revision and subinventory
1909 Else if item is non serial controlled then
1910 Call API WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes
1911 Values for Quantity, Lot_Number, Revision and Sub Inventory
1912 should be pulled from UI.
1913 Update Quantity, Lot_Number, Revision and Sub-Inventory
1914 End If ;
1915 End If;
1916 */
1917 /* Fixed for bug#3438685
1918 In case of serial controlled at SO issue item, update the serial number on the
1919 delivery line details
1920 */
1921
1922 BEGIN
1923
1924 IF( i.RESERVABLE_TYPE = 1) Then /*Item is reservable */
1925 IF i.serial_number_control_code = C_SRL_NUM_Cnt_Code_SO_Issue Then
1926
1927 source_code := 'OE'; -- The only source code that should be used by the API
1928 changed_attributes(1).delivery_detail_id := i.delivery_detail_id;
1929 changed_attributes(1).serial_number := p_order_rec.serial_number;
1930 changed_attributes(1).shipped_quantity := p_order_rec.shipped_quantity;
1931
1932 IF (g_debug > 0 ) THEN
1933 csd_gen_utility_pvt.ADD('delivery_detail_id ='||changed_attributes(1).delivery_detail_id);
1934 csd_gen_utility_pvt.ADD('serial_number ='||changed_attributes(1).serial_number );
1935 csd_gen_utility_pvt.ADD('shipped_quantity ='||changed_attributes(1).shipped_quantity );
1936 csd_gen_utility_pvt.ADD('Calling Update_Shipping_Attributes');
1937 END IF;
1938
1939
1940 --Call to WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes.
1941 WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes(
1942 p_api_version_number => 1.0,
1943 p_init_msg_list => p_init_msg_list,
1944 p_commit => p_commit,
1945 x_return_status => x_return_status,
1946 x_msg_count => x_msg_count,
1947 x_msg_data => x_msg_data,
1948 p_changed_attributes => changed_attributes,
1949 p_source_code => source_code);
1950
1951 IF (g_debug > 0 ) THEN
1952 csd_gen_utility_pvt.ADD('x_return_status(Update_Shipping_Attributes )='||x_return_status);
1953 END IF;
1954
1955 IF (x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
1956 IF (g_debug > 0 ) THEN
1957 csd_gen_utility_pvt.ADD('Update_Shipping_Attributes failed');
1958 END IF;
1959 RAISE fail_api;
1960 END IF;
1961 END IF; /* end if of Serial control at sales order and reservable item */
1962
1963 Elsif (i.RESERVABLE_TYPE = 2 ) then /* else of reservable type */
1964
1965 /*Bug#4433942 Validations for non reservable item
1966 1) If item is serialized make sure that Serial Number resides in the warehouse specified on
1967 Ship line,if not raise error. for serial control at receipt/pre-defined.
1968 2) If item is non-serialized make sure that sub inventory entered on DWB belongs to warehouse
1969 specified on ship line, if not raise error.
1970 3) If item is serialized make sure that user passes serial number information,
1971 if not raise error.
1972 4) If item is non-serialized make sure that user passes Sub inventory information
1973 else raise error.
1974 5) If item is non-serialized and lot controlled make sure user passes
1975 lot_number information else raise error.
1976 6) If item is non-serialized and revision controlled make sure user passes revision
1977 information else raise error.
1978 */
1979 l_revision:=null;
1980 l_shipped_serial_number :=NULL;
1981 l_lot_number :=NULL;
1982 l_sub_inventory :=NULL;
1983 l_SN_at_SO_new_SN_number :=FALSE;
1984
1985 if i.serial_number_control_code in (2,5,6) then
1986
1987 if nvl(p_product_txn_rec.source_serial_number,FND_API.G_MISS_CHAR)=FND_API.G_MISS_CHAR then
1988 /* Validation 3 */
1989 FND_MESSAGE.SET_NAME('CSD','CSD_API_SERIAL_NUM_REQD');
1990 FND_MSG_PUB.ADD;
1991 RAISE FND_API.G_EXC_ERROR;
1992 else
1993 l_shipped_serial_number := p_product_txn_rec.source_serial_number;
1994 end if;
1995
1996 begin
1997 select Lot_Number, Revision, current_SubInventory_code
1998 into l_lot_number ,l_revision ,l_sub_inventory
1999 from mtl_serial_numbers
2000 where serial_number = l_shipped_serial_number
2001 AND inventory_item_id = i.inventory_item_id
2002 AND current_organization_id = i.organization_id;
2003 exception
2004 when no_data_found then
2005 if (i.serial_number_control_code in (2,5)) then
2006 /*Validation 1 */
2007 FND_MESSAGE.SET_NAME('CSD','CSD_SERIAL_NUM_NOT_IN_INVORG');
2008 FND_MESSAGE.SET_TOKEN('SERIAL_NUMBER',l_shipped_serial_number);
2009 FND_MESSAGE.SET_TOKEN('INV_ORG',i.organization_code);
2010 FND_MSG_PUB.ADD;
2011 RAISE FND_API.G_EXC_ERROR;
2012 else /*if Item is Serialied at SO then user may pass SN that does not resides in any warehouse */
2013 l_SN_at_SO_new_SN_number :=TRUE;
2014 end if;
2015 end;
2016 end if; /*end if of serialized item */
2017
2018 if ( i.serial_number_control_code =1 or (i.serial_number_control_code=6 and l_SN_at_SO_new_SN_number=TRUE ) ) then
2019 if nvl(p_product_txn_rec.sub_inventory ,FND_API.G_MISS_CHAR)=FND_API.G_MISS_CHAR then
2020 /*Validation 4 */
2021 FND_MESSAGE.SET_NAME('CSD','CSD_SUBINV_IS_REQD');
2022 FND_MSG_PUB.ADD;
2023 RAISE FND_API.G_EXC_ERROR;
2024 end if;
2025
2026 begin
2027 SELECT msi.secondary_inventory_name
2028 into l_sub_inventory
2029 FROM mtl_secondary_inventories msi
2030 where msi.organization_id = i.organization_id
2031 AND msi.secondary_inventory_name = p_product_txn_rec.sub_inventory
2032 AND NVL(msi.DISABLE_DATE,SYSDATE+1) > SYSDATE
2033 AND msi.QUANTITY_TRACKED = 1;
2034
2035 exception
2036 When no_data_found then
2037 /*Validation 2 */
2038 FND_MESSAGE.SET_NAME('CSD','CSD_SUBINV_NOT_IN_INVORG');
2039 FND_MESSAGE.SET_TOKEN('SUB_INV',p_product_txn_rec.sub_inventory);
2040 FND_MESSAGE.SET_TOKEN('INV_ORG',i.organization_code);
2041 FND_MSG_PUB.ADD;
2042 RAISE FND_API.G_EXC_ERROR;
2043 end;
2044
2045 if i.LOT_CONTROL_CODE =2 then
2046 if nvl(p_product_txn_rec.lot_number,FND_API.G_MISS_CHAR)=FND_API.G_MISS_CHAR then
2047 /*Validation 5 */
2048 FND_MESSAGE.SET_NAME('CSD','CSD_LOT_NUMBER_REQD');
2049 FND_MESSAGE.SET_TOKEN('ITEM',i.item_name);
2050 FND_MSG_PUB.ADD;
2051 RAISE FND_API.G_EXC_ERROR;
2052 else
2053 l_lot_number:= p_product_txn_rec.lot_number;
2054 end if;
2055 end if;
2056
2057 if i.REVISION_QTY_CONTROL_CODE =2 then
2058 if nvl(p_product_txn_rec.revision,FND_API.G_MISS_CHAR)=FND_API.G_MISS_CHAR then
2059 FND_MESSAGE.SET_NAME('CSD','CSD_ITEM_REVISION_REQD');
2060 FND_MESSAGE.SET_TOKEN('ITEM',i.item_name);
2061 FND_MSG_PUB.ADD;
2062 RAISE FND_API.G_EXC_ERROR;
2063 else
2064 l_revision:=p_product_txn_rec.revision;
2065 end if;
2066 end if;
2067 end if; /* end of non serialized item */
2068
2069 /* Till here all the validations are done now we can call update attribute API */
2070 source_code := 'OE'; /*The only source code that should be used by the API */
2071 changed_attributes(1).delivery_detail_id := i.delivery_detail_id;
2072 changed_attributes(1).serial_number := l_shipped_serial_number;
2073 changed_attributes(1).revision := l_revision ;
2074 changed_attributes(1).lot_number := l_lot_number;
2075 changed_attributes(1).subinventory := l_sub_inventory;
2076 changed_attributes(1).shipped_quantity := p_order_rec.shipped_quantity;
2077
2078 --- bug#16167687
2079 changed_attributes(1).locator_id := p_product_txn_rec.locator_id;
2080 --- bug#16167687
2081
2082 IF (g_debug > 0 ) THEN
2083 csd_gen_utility_pvt.ADD('delivery_detail_id ='||changed_attributes(1).delivery_detail_id);
2084 csd_gen_utility_pvt.ADD('serial_number ='||changed_attributes(1).serial_number );
2085 csd_gen_utility_pvt.ADD('Revision ='||changed_attributes(1).revision );
2086 csd_gen_utility_pvt.ADD('Lot number ='||changed_attributes(1).lot_number );
2087 csd_gen_utility_pvt.ADD('sub_inventory ='||changed_attributes(1).subinventory );
2088 csd_gen_utility_pvt.ADD('shipped_quantity ='||changed_attributes(1).shipped_quantity );
2089 csd_gen_utility_pvt.ADD('Calling Update_Shipping_Attributes');
2090 END IF;
2091
2092 WSH_DELIVERY_DETAILS_PUB.Update_Shipping_Attributes(
2093 p_api_version_number => 1.0,
2094 p_init_msg_list => p_init_msg_list,
2095 p_commit => p_commit,
2096 x_return_status => x_return_status,
2097 x_msg_count => x_msg_count,
2098 x_msg_data => x_msg_data,
2099 p_changed_attributes => changed_attributes,
2100 p_source_code => source_code);
2101
2102 IF (g_debug > 0 ) THEN
2103 csd_gen_utility_pvt.ADD('x_return_status(Update_Shipping_Attributes )='||x_return_status);
2104 END IF;
2105
2106 IF (x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
2107 IF (g_debug > 0 ) THEN
2108 csd_gen_utility_pvt.ADD('Update_Shipping_Attributes failed');
2109 END IF;
2110 RAISE fail_api;
2111 END IF;
2112
2113 END IF; /* end if of reservable type */
2114
2115 EXCEPTION
2116 WHEN fail_api THEN
2117 Wsh_Util_Core.get_messages('Y',
2118 x_msg_summary,
2119 x_msg_details,
2120 x_msg_count);
2121 IF x_msg_count > 1 THEN
2122 x_msg_data := x_msg_summary ||
2123 x_msg_details;
2124 ELSE
2125 x_msg_data := x_msg_summary;
2126 END IF;
2127
2128 Debug('Error Msg from Update_Shipping_Attributes',
2129 l_mod_name,
2130 1);
2131 Debug('x_msg_data = ' || x_msg_data,
2132 l_mod_name,
2133 1);
2134 Fnd_Message.SET_NAME('CSD','CSD_UPDATE_SHIPPING_FAILED');
2135 Fnd_Message.SET_TOKEN('ERR_MSG', x_msg_data);
2136 Fnd_Msg_Pub.ADD;
2137 RAISE Fnd_Api.G_EXC_ERROR;
2138 END;
2139
2140 -- END IF; --end of update_shipping_attributes
2141
2142 BEGIN
2143 Debug('i.delivery_id=' || i.delivery_id, l_mod_name, 1);
2144
2145 -- Values for Ship Confirming the delivery.
2146 p_action_code := 'CONFIRM'; -- The action code for ship confirm
2147 p_delivery_id := i.delivery_id; -- The delivery that needs to be confirmed
2148 p_delivery_name := TO_CHAR(i.delivery_id); -- The delivery name,
2149 p_sc_action_flag := 'S'; -- Ship entered quantity.
2150
2151 -- p_Sc_Intransit_flag needs to be set to 'Y' this as per bug 3676488 (Shipping)
2152 -- This fix for bug# 3665544
2153 p_sc_intransit_flag := 'Y'; -- In transit flag is set to 'Y' closes the
2154
2155 -- pickup stop and sets the delivery in transit.
2156 p_sc_close_trip_flag := 'Y'; -- Close the trip after ship confirm
2157
2158 -- p_sc_trip_ship_method := ''; -- The ship method code
2159 p_sc_defer_interface_flag := 'N'; -- defer interface
2160
2161 -- p_sc_report_set_id := 6; -- check if it is seeded
2162
2163
2164 --bug#7675562
2165 Debug('organization_id = '||i.organization_id,l_mod_name,1);
2166
2167 WSH_SHIPPING_PARAMS_GRP.Get_Shipping_Parameters(
2168 i.organization_id,
2169 l_ship_param_info,
2170 x_return_status);
2171
2172 Debug('x_return_status(Get_Shipping_Parameters)='||x_return_status,l_mod_name,1);
2173 Debug('DELIVERY_REPORT_SET_ID = '||l_ship_param_info.DELIVERY_REPORT_SET_ID,l_mod_name,1);
2174
2175 p_sc_report_set_id := l_ship_param_info.DELIVERY_REPORT_SET_ID; -- check if it is seeded
2176
2177 IF (x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
2178 Debug('Get_Shipping_Parameters failed',l_mod_name,1);
2179 RAISE fail_api;
2180 END IF;
2181
2182
2183 Debug('Calling Delivery_Action ', l_mod_name, 1);
2184
2185 -- Call to WSH_DELIVERIES_PUB.Delivery_Action.
2186 Wsh_Deliveries_Pub.Delivery_Action(p_api_version_number => 1.0,
2187 p_init_msg_list => p_init_msg_list,
2188 x_return_status => x_return_status,
2189 x_msg_count => x_msg_count,
2190 x_msg_data => x_msg_data,
2191 p_action_code => p_action_code,
2192 p_delivery_id => p_delivery_id,
2193 p_delivery_name => p_delivery_name,
2194 p_asg_trip_id => p_asg_trip_id,
2195 p_asg_trip_name => p_asg_trip_name,
2196 p_asg_pickup_stop_id => p_asg_pickup_stop_id,
2197 p_asg_pickup_loc_id => p_asg_pickup_loc_id,
2198 p_asg_pickup_loc_code => p_asg_pickup_loc_code,
2199 p_asg_pickup_arr_date => p_asg_pickup_arr_date,
2200 p_asg_pickup_dep_date => p_asg_pickup_dep_date,
2201 p_asg_dropoff_stop_id => p_asg_dropoff_stop_id,
2202 p_asg_dropoff_loc_id => p_asg_dropoff_loc_id,
2203 p_asg_dropoff_loc_code => p_asg_dropoff_loc_code,
2204 p_asg_dropoff_arr_date => p_asg_dropoff_arr_date,
2205 p_asg_dropoff_dep_date => p_asg_dropoff_dep_date,
2206 p_sc_action_flag => p_sc_action_flag,
2207 p_sc_intransit_flag => p_sc_intransit_flag,
2208 p_sc_close_trip_flag => p_sc_close_trip_flag,
2209 p_sc_create_bol_flag => p_sc_create_bol_flag,
2210 p_sc_stage_del_flag => p_sc_stage_del_flag,
2211 p_sc_trip_ship_method => p_sc_trip_ship_method,
2212 p_sc_actual_dep_date => p_sc_actual_dep_date,
2213 p_sc_report_set_id => p_sc_report_set_id,
2214 p_sc_report_set_name => p_sc_report_set_name,
2215 p_sc_defer_interface_flag => p_sc_defer_interface_flag,
2216 p_wv_override_flag => p_wv_override_flag,
2217 x_trip_id => x_trip_id,
2218 x_trip_name => x_trip_name);
2219
2220 Debug('x_return_status(Delivery_Action )=' ||
2221 x_return_status,
2222 l_mod_name,
2223 1);
2224
2225 IF (x_return_status <> Wsh_Util_Core.G_RET_STS_SUCCESS)
2226 THEN
2227 Debug('Delivery_Action failed', l_mod_name, 1);
2228 RAISE fail_api;
2229 END IF;
2230 EXCEPTION
2231 WHEN fail_api THEN
2232 Wsh_Util_Core.get_messages('Y',
2233 x_msg_summary,
2234 x_msg_details,
2235 x_msg_count);
2236 IF x_msg_count > 1
2237 THEN
2238 x_msg_data := x_msg_summary || x_msg_details;
2239 ELSE
2240 x_msg_data := x_msg_summary;
2241 END IF;
2242 Debug('Error Msg from Delivery_Action',
2243 l_mod_name,
2244 1);
2245 Debug('x_msg_data = ' || x_msg_data, l_mod_name, 1);
2246 -- Ignore if it is a warning
2247 -- bug#8269688, FP of bug#7659800, subhat
2248 --IF (x_return_status <>
2249 -- Wsh_Util_Core.G_RET_STS_WARNING)
2250 IF (x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS)
2251 THEN
2252 begin
2253 select 'N'
2254 into l_shipped_flag
2255 from wsh_delivery_details wdd
2256 where wdd.delivery_detail_id = i.delivery_detail_id
2257 and wdd.released_status <> 'C';
2258 exception
2259 when no_data_found then
2260 l_shipped_flag :='Y';
2261 end;
2262 if l_shipped_flag = 'N' then
2263 FND_MESSAGE.SET_NAME('CSD','CSD_SHIP_CONFIRM_FAILED');
2264 FND_MESSAGE.SET_TOKEN('ERR_MSG',x_msg_data);
2265 FND_MSG_PUB.ADD;
2266 RAISE FND_API.G_EXC_ERROR;
2267 end if;
2268 END IF;
2269 -- end bug#8269688, FP of bug#7659800, subhat
2270 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
2271 END; -- end of delivery action
2272
2273 END LOOP; -- At the end of processing all the delivery id for an Order
2274 END IF; -- end of all actions
2275
2276 -- Api body ends here
2277
2278 -- Standard check of p_commit.
2279 IF Fnd_Api.To_Boolean(p_commit)
2280 THEN
2281 COMMIT WORK;
2282 END IF;
2283
2284 -- Standard call to get message count and IF count is get message info.
2285 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2286 p_data => x_msg_data);
2287
2288 EXCEPTION
2289 WHEN Fnd_Api.G_EXC_ERROR THEN
2290 Debug('In EXC_ERROR in process_sales_order', l_mod_name, 1);
2291 ROLLBACK TO process_sales_order;
2292
2293 x_return_status := Fnd_Api.G_RET_STS_ERROR;
2294 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2295 p_data => x_msg_data);
2296
2297 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
2298 Debug('In EXC_UNEXP_ERROR in process_sales_order', l_mod_name, 1);
2299 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
2300 ROLLBACK TO process_sales_order;
2301 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2302 p_data => x_msg_data);
2303 WHEN OTHERS THEN
2304 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
2305 Debug('In OTHERS in process_sales_order' || sqlerrm, l_mod_name, 1);
2306 ROLLBACK TO process_sales_order;
2307 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
2308 THEN
2309 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
2310 END IF;
2311 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2312 p_data => x_msg_data);
2313 END process_sales_order;
2314
2315 /*------------------------------------------------------------------*/
2316 /* Procedure name: Create_product_txn */
2317 /* Description : Procedure to create product transaction lines */
2318 /* 1. It may from the ON-INSERT trigger in repair */
2319 /* order form for creating ptoduct txn manually. */
2320 /* 2. It may be also called from create_default_txn */
2321 /* API to create product txn at the time creating */
2322 /* repair orders */
2323 /*------------------------------------------------------------------*/
2324
2325 PROCEDURE create_product_txn(p_api_version IN NUMBER,
2326 p_commit IN VARCHAR2 := Fnd_Api.g_false,
2327 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_false,
2328 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
2329 x_product_txn_rec IN OUT NOCOPY PRODUCT_TXN_REC,
2330 x_return_status OUT NOCOPY VARCHAR2,
2331 x_msg_count OUT NOCOPY NUMBER,
2332 x_msg_data OUT NOCOPY VARCHAR2) IS
2333
2334 l_api_name CONSTANT VARCHAR2(30) := 'CREATE_PRODUCT_TXN';
2335 l_api_version CONSTANT NUMBER := 1.0;
2336 l_msg_count NUMBER;
2337 l_msg_data VARCHAR2(2000);
2338 l_msg_index NUMBER;
2339 l_product_transaction_id NUMBER := NULL;
2340 l_serial_flag BOOLEAN := FALSE;
2341 l_dummy VARCHAR2(1);
2342 l_check VARCHAR2(1);
2343 l_Charges_Rec Cs_Charge_Details_Pub.Charges_Rec_type;
2344 l_estimate_Rec Cs_Charge_Details_Pub.Charges_Rec_type;
2345 l_estimate_detail_id NUMBER := NULL;
2346 x_estimate_detail_id NUMBER := NULL;
2347 l_incident_id NUMBER := NULL;
2348 l_order_rec OM_INTERFACE_REC;
2349 l_reference_number VARCHAR2(30) := '';
2350 l_contract_number VARCHAR2(120) := '';
2351 l_bus_process_id NUMBER := NULL;
2352 l_repair_type_ref VARCHAR2(3) := '';
2353 l_line_type_id NUMBER := NULL;
2354 l_txn_billing_type_id NUMBER := NULL;
2355 l_party_id NUMBER := NULL;
2356 l_account_id NUMBER := NULL;
2357 l_order_header_id NUMBER := NULL;
2358 l_release_status VARCHAR2(10) := '';
2359 l_curr_code VARCHAR2(10) := '';
2360 l_picking_rule_id NUMBER := NULL;
2361 l_ship_qty NUMBER := NULL;
2362 l_line_category_code VARCHAR2(30) := '';
2363 l_ship_from_org_id NUMBER := NULL;
2364 l_order_line_id NUMBER := NULL;
2365 l_coverage_id NUMBER := NULL;
2366 -- Bugfix 3617932, vkjain.
2367 -- Increasing the column length to 150
2368 -- l_coverage_name VARCHAR2(150) := ''; -- Commented for bugfix 3617932
2369 l_txn_group_id NUMBER := NULL;
2370 l_unit_selling_price NUMBER := NULL;
2371 l_transaction_type_id NUMBER := NULL;
2372 l_order_category_code VARCHAR2(30);
2373 l_add_to_same_order BOOLEAN;
2374 l_orig_src_reference VARCHAR2(30);
2375 l_orig_src_header_id NUMBER;
2376 l_orig_src_line_id NUMBER;
2377 l_orig_po_num VARCHAR2(50);
2378 l_rev_ctl_code mtl_system_items.revision_qty_control_code%TYPE;
2379 l_booked_flag oe_order_headers_all.booked_flag%TYPE;
2380
2381 --taklam
2382 l_Line_Tbl_Type OE_ORDER_PUB.Line_Tbl_Type;
2383 x_Line_Tbl_Type OE_ORDER_PUB.Line_Tbl_Type;
2384 l_p_ship_from_org_id NUMBER;
2385 l_project_count NUMBER;
2386
2387 l_sr_account_id NUMBER; -- swai: bug 6001057
2388
2389 create_order EXCEPTION;
2390 book_order EXCEPTION;
2391 release_order EXCEPTION;
2392 ship_order EXCEPTION;
2393
2394 --Bug fix for 3399883 [
2395 l_no_contract_bp_vldn VARCHAR2(10);
2396 --]
2397
2398 CURSOR order_rec(p_incident_id IN NUMBER) IS
2399 SELECT customer_id, account_id
2400 FROM cs_incidents_all_b
2401 WHERE incident_id = p_incident_id;
2402
2403 CURSOR estimate(p_rep_line_id IN NUMBER) IS
2404 SELECT estimate_detail_id, object_version_number
2405 FROM cs_estimate_details
2406 WHERE source_id = p_rep_line_id
2407 AND source_code = 'DR'
2408 AND interface_to_oe_flag = 'N'
2409 AND order_header_id IS NULL
2410 AND order_line_id IS NULL;
2411
2412 --taklam
2413 CURSOR project_cu(l_project_id NUMBER, l_p_ship_from_org_id NUMBER) IS
2414 SELECT COUNT(*) p_count
2415 FROM PJM_PROJECTS_ORG_OU_SECURE_V --bug#13472453 PJM_PROJECTS_ORG_V
2416 WHERE project_id = l_project_id and inventory_organization_id = l_p_ship_from_org_id;
2417
2418 CURSOR order_line_cu(l_est_detail_id NUMBER) is
2419 SELECT b.order_line_id, a.ship_from_org_id
2420 FROM oe_order_lines_all a, cs_estimate_details b
2421 WHERE a.line_id = b.order_line_id
2422 AND b.estimate_detail_id = l_est_detail_id;
2423
2424 -- swai: bug 6001057
2425 CURSOR sr_account_cu (l_repair_line_id NUMBER) is
2426 SELECT account_id
2427 FROM cs_incidents_all_b cs, csd_repairs csd
2428 WHERE cs.incident_id = csd.incident_id
2429 AND repair_line_id = l_repair_line_id;
2430
2431 --R12 Development Changes Begin
2432 CURSOR cur_pick_rules(p_pick_rule_id NUMBER) IS
2433 SELECT 'x'
2434 FROM wsh_picking_rules
2435 WHERE picking_rule_id = p_pick_rule_id
2436 AND SYSDATE BETWEEN NVL(start_Date_Active, SYSDATE) AND
2437 NVL(end_Date_active, SYSDATE + 1);
2438 --R12 Development Changes End
2439
2440 -- Variables used in FND Log
2441 l_error_level NUMBER := Fnd_Log.LEVEL_ERROR;
2442 l_mod_name VARCHAR2(2000) := 'csd.plsql.csd_process_pvt.create_product_txn';
2443 l_tmp_char VARCHAR2(1); --R12 Development Changes
2444 /* R12 SN reservations integration change Begin */
2445 l_ItemAttributes Csd_Logistics_Util.ItemAttributes_Rec_Type;
2446 l_auto_reserve_profile VARCHAR2(10);
2447 l_srl_reservation_id NUMBER;
2448 l_serial_rsv_rec CSD_LOGISTICS_UTIL.CSD_SERIAL_RESERVE_REC_TYPE ;
2449 /* R12 SN reservations integration change End */
2450
2451 -- swai bug 7572247/7628204: cursor to default account address for SR account
2452 CURSOR c_sr_primary_account_address(p_incident_id NUMBER, p_site_use_type VARCHAR2)
2453 IS
2454 select distinct
2455 hp.party_site_id
2456 from hz_party_sites_v hp,
2457 hz_parties hz,
2458 hz_cust_acct_sites_all hca,
2459 hz_cust_site_uses_all hcsu,
2460 cs_incidents_all_b cs
2461 where hcsu.site_use_code = p_site_use_type
2462 and cs.incident_id = p_incident_id
2463 and hp.status = 'A'
2464 and hcsu.status = 'A'
2465 and hp.party_id = hz.party_id
2466 and hca.party_site_id = hp.party_site_id
2467 and hca.cust_account_id = cs.account_id
2468 and hcsu.cust_acct_site_id = hca.cust_acct_site_id
2469 and hca.org_id = cs.org_id
2470 and hcsu.primary_flag = 'Y'
2471 and rownum = 1;
2472
2473 BEGIN
2474 -- Debug message
2475 Debug('At the Beginning of create_product_txn', l_mod_name, 1);
2476
2477 -- Standard Start of API savepoint
2478 SAVEPOINT create_product_txn;
2479
2480 -- Initialize API return status to success
2481 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
2482
2483 -- Standard call to check for call compatibility.
2484 IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
2485 p_api_version,
2486 l_api_name,
2487 G_PKG_NAME)
2488 THEN
2489 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
2490 END IF;
2491
2492 -- Initialize message list if p_init_msg_list is set to TRUE.
2493 IF Fnd_Api.to_Boolean(p_init_msg_list)
2494 THEN
2495 Fnd_Msg_Pub.initialize;
2496 END IF;
2497
2498 -- Api body starts
2499
2500 -- Dump the IN parameters in the log file
2501 -- if the debug level > 5
2502 IF (g_debug > 5)
2503 THEN
2504 Csd_Gen_Utility_Pvt.dump_prod_txn_rec(p_prod_txn_rec => x_product_txn_rec);
2505 END IF;
2506
2507 Debug('********* Check reqd parameter ***************',
2508 l_mod_name,
2509 1);
2510 Debug('Repair Line ID =' || x_product_txn_rec.repair_line_id,
2511 l_mod_name,
2512 1);
2513 Debug('Action Code =' || x_product_txn_rec.action_code,
2514 l_mod_name,
2515 1);
2516 Debug('Action Type =' || x_product_txn_rec.action_type,
2517 l_mod_name,
2518 1);
2519 Debug('Txn_billing_type_id =' ||
2520 x_product_txn_rec.txn_billing_type_id,
2521 l_mod_name,
2522 1);
2523
2524 -- Check the required parameter(txn_billing_type_id)
2525 Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.txn_billing_type_id,
2526 p_param_name => 'TXN_BILLING_TYPE_ID',
2527 p_api_name => l_api_name);
2528
2529 -- Check the required parameter(inventory_item_id)
2530 Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.inventory_item_id,
2531 p_param_name => 'INVENTORY_ITEM_ID',
2532 p_api_name => l_api_name);
2533
2534 -- Check the required parameter(unit_of_measure_code)
2535 Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.unit_of_measure_code,
2536 p_param_name => 'UNIT_OF_MEASURE_CODE',
2537 p_api_name => l_api_name);
2538
2539 -- Check the required parameter(quantity)
2540 Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.quantity,
2541 p_param_name => 'QUANTITY',
2542 p_api_name => l_api_name);
2543
2544 -- Check the required parameter(price_list_id)
2545 Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.price_list_id,
2546 p_param_name => 'PRICE_LIST_ID',
2547 p_api_name => l_api_name);
2548
2549 Debug('Validate repair line id', l_mod_name, 1);
2550
2551 -- Validate the repair line ID if it exists in csd_repairs
2552 IF NOT
2553 (Csd_Process_Util.Validate_rep_line_id(p_repair_line_id => x_product_txn_rec.repair_line_id))
2554 THEN
2555 RAISE Fnd_Api.G_EXC_ERROR;
2556 END IF;
2557
2558 Debug('Validate action type', l_mod_name, 1);
2559
2560 -- Validate the Action Type if it exists in fnd_lookups
2561 IF NOT
2562 (Csd_Process_Util.Validate_action_type(p_action_type => x_product_txn_rec.action_type))
2563 THEN
2564 RAISE Fnd_Api.G_EXC_ERROR;
2565 END IF;
2566
2567 Debug('Validate action code', l_mod_name, 1);
2568
2569 -- Validate the repair line ID if it exists in fnd_lookups
2570 IF NOT
2571 (Csd_Process_Util.Validate_action_code(p_action_code => x_product_txn_rec.action_code))
2572 THEN
2573 RAISE Fnd_Api.G_EXC_ERROR;
2574 END IF;
2575
2576 --R12 Development changes begin
2577 Debug('Validating picking rule if passed[' ||
2578 x_producT_txn_rec.picking_rule_id || ']',
2579 l_mod_name,
2580 1);
2581 IF (x_producT_txn_rec.picking_rule_id <> NULL)
2582 THEN
2583 OPEN cur_pick_rules(x_producT_txn_rec.picking_rule_id);
2584 FETCH cur_pick_rules
2585 INTO l_tmp_char;
2586 IF (cur_pick_rules%NOTFOUND)
2587 THEN
2588 Fnd_Message.SET_NAME('CSD', 'CSD_INV_PICK_RULE');
2589 Fnd_Msg_Pub.ADD;
2590 RAISE Fnd_Api.G_EXC_ERROR;
2591 END IF;
2592 END IF;
2593 --R12 Development changes End
2594 Debug('Validate product txn qty', l_mod_name, 1);
2595 Debug('x_product_txn_rec.quantity =' || x_product_txn_rec.quantity,
2596 l_mod_name,
2597 1);
2598
2599 -- Validate if the product txn quantity (customer product only)
2600 -- is not exceeding the repair order quantity
2601 -- swai: bug 5931926 - 12.0.2 do not validate quantity for third party lines
2602 -- since multiple parts can be shipped out.
2603 IF x_product_txn_rec.action_code = 'CUST_PROD' AND
2604 x_product_txn_rec.action_type not in ('RMA_THIRD_PTY', 'SHIP_THIRD_PTY')
2605 THEN
2606 Csd_Process_Util.Validate_quantity(p_action_type => x_product_txn_rec.action_type,
2607 p_repair_line_id => x_product_txn_rec.repair_line_id,
2608 p_prod_txn_qty => x_product_txn_rec.quantity,
2609 x_return_status => x_return_status);
2610 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
2611 THEN
2612 Debug('Validate_Quantity failed ', l_mod_name, 1);
2613 RAISE Fnd_Api.G_EXC_ERROR;
2614 END IF;
2615 END IF;
2616
2617 Debug('Validate product txn status', l_mod_name, 1);
2618 Debug('x_product_txn_rec.PROD_TXN_STATUS =' ||
2619 x_product_txn_rec.PROD_TXN_STATUS,
2620 l_mod_name,
2621 1);
2622
2623 -- Validate the PROD_TXN_STATUS if it exists in fnd_lookups
2624 IF (x_product_txn_rec.PROD_TXN_STATUS IS NOT NULL) AND
2625 (x_product_txn_rec.PROD_TXN_STATUS <> Fnd_Api.G_MISS_CHAR)
2626 THEN
2627 BEGIN
2628 SELECT 'X'
2629 INTO l_check
2630 FROM fnd_lookups
2631 WHERE lookup_type = 'CSD_PRODUCT_TXN_STATUS'
2632 AND lookup_code = x_product_txn_rec.PROD_TXN_STATUS;
2633 EXCEPTION
2634 WHEN OTHERS THEN
2635 Fnd_Message.SET_NAME('CSD', 'CSD_ERR_PROD_TXN_STATUS');
2636 Fnd_Msg_Pub.ADD;
2637 RAISE Fnd_Api.G_EXC_ERROR;
2638 END;
2639 END IF;
2640
2641 -- Get service request from csd_repairs table
2642 -- using repair order
2643 BEGIN
2644 SELECT incident_id,
2645 original_source_reference,
2646 original_source_header_id,
2647 original_source_line_id
2648 INTO l_incident_id,
2649 l_orig_src_reference,
2650 l_orig_src_header_id,
2651 l_orig_src_line_id
2652 FROM csd_repairs
2653 WHERE repair_line_id = x_product_txn_rec.repair_line_id;
2654 EXCEPTION
2655 WHEN OTHERS THEN
2656 Fnd_Message.SET_NAME('CSD', 'CSD_API_INV_REP_LINE_ID');
2657 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
2658 x_product_txn_rec.repair_line_id);
2659 Fnd_Msg_Pub.ADD;
2660 RAISE Fnd_Api.G_EXC_ERROR;
2661 END;
2662
2663 Debug('l_incident_id =' || l_incident_id, l_mod_name, 1);
2664
2665 -- Get the business process id
2666 -- Forward bug fix # 2756313
2667 -- l_bus_process_id := CSD_PROCESS_UTIL.GET_BUS_PROCESS(l_incident_id);
2668
2669 l_bus_process_id := Csd_Process_Util.GET_BUS_PROCESS(x_product_txn_rec.repair_line_id);
2670
2671 Debug('l_bus_process_id =' || l_bus_process_id, l_mod_name, 1);
2672
2673 IF l_bus_process_id < 0
2674 THEN
2675 IF NVL(x_product_txn_rec.business_process_id,
2676 Fnd_Api.G_MISS_NUM) <> Fnd_Api.G_MISS_NUM
2677 THEN
2678 l_bus_process_id := x_product_txn_rec.business_process_id;
2679 ELSE
2680 Debug('Business process Id does not exist ', l_mod_name, 1);
2681 RAISE Fnd_Api.G_EXC_ERROR;
2682 END IF;
2683 END IF;
2684
2685 Debug('Getting the Coverage and txn Group Id', l_mod_name, 1);
2686 Debug('contract_line_id =' || x_product_txn_rec.contract_id,
2687 l_mod_name,
2688 1);
2689
2690 IF (x_product_txn_rec.transaction_type_id IS NULL) OR
2691 (x_product_txn_rec.transaction_type_id = Fnd_Api.G_MISS_NUM)
2692 THEN
2693 BEGIN
2694 SELECT transaction_type_id
2695 INTO l_transaction_type_id
2696 FROM cs_txn_billing_types
2697 WHERE txn_billing_type_id =
2698 x_product_txn_rec.txn_billing_type_id;
2699 EXCEPTION
2700 WHEN NO_DATA_FOUND THEN
2701 Debug('No Row found for the txn_billing_type_id=' ||
2702 TO_CHAR(l_txn_billing_type_id),
2703 l_mod_name,
2704 1);
2705 WHEN OTHERS THEN
2706 Debug('When others exception at - Transaction type id',
2707 l_mod_name,
2708 1);
2709 END;
2710 x_product_txn_rec.transaction_type_id := l_transaction_type_id;
2711 Debug('x_product_txn_rec.transaction_type_id :' ||
2712 TO_CHAR(x_product_txn_rec.transaction_type_id),
2713 l_mod_name,
2714 1);
2715 END IF;
2716
2717 -- Get the coverage details from the contract
2718 /******************************contract changes
2719 IF NVL(x_product_txn_rec.contract_id, Fnd_Api.G_MISS_NUM) <>
2720 Fnd_Api.G_MISS_NUM
2721 THEN
2722 BEGIN
2723 --Bug fix for 3399883 [
2724 l_no_contract_bp_vldn := NVL(Fnd_Profile.value('CSD_NO_CONTRACT_BP_VLDN'),
2725 'N');
2726
2727 IF (l_no_contract_bp_vldn = 'Y')
2728 THEN
2729
2730 SELECT cov.actual_coverage_id,
2731 -- cov.coverage_name, -- Commented for bugfix 3617932
2732 ent.txn_group_id
2733 INTO l_coverage_id,
2734 -- l_coverage_name, -- Commented for bugfix 3617932
2735 l_txn_group_id
2736 FROM oks_ent_coverages_v cov,
2737 oks_ent_txn_groups_v ent
2738 WHERE cov.contract_line_id =
2739 x_product_txn_rec.contract_id
2740 AND cov.actual_coverage_id = ent.coverage_id;
2741 ELSE
2742 --]
2743
2744 SELECT cov.actual_coverage_id,
2745 -- cov.coverage_name, -- Commented for bugfix 3617932
2746 ent.txn_group_id
2747 INTO l_coverage_id,
2748 -- l_coverage_name, -- Commented for bugfix 3617932
2749 l_txn_group_id
2750 FROM oks_ent_coverages_v cov,
2751 oks_ent_txn_groups_v ent
2752 WHERE cov.contract_line_id =
2753 x_product_txn_rec.contract_id
2754 AND cov.actual_coverage_id = ent.coverage_id
2755 AND ent.business_process_id = l_bus_process_id;
2756 --Bug fix for 3399883 [
2757 END IF;
2758 --]
2759 EXCEPTION
2760 WHEN NO_DATA_FOUND THEN
2761 Fnd_Message.SET_NAME('CSD', 'CSD_API_CONTRACT_MISSING');
2762 Fnd_Message.SET_TOKEN('CONTRACT_LINE_ID',
2763 x_product_txn_rec.contract_id);
2764 Fnd_Msg_Pub.ADD;
2765 Debug('Contract Line Id missing', l_mod_name, 1);
2766 RAISE Fnd_Api.G_EXC_ERROR;
2767 WHEN TOO_MANY_ROWS THEN
2768 Debug('Too many Contract Line', l_mod_name, 1);
2769 END;
2770 x_product_txn_rec.coverage_id := l_coverage_id;
2771 x_product_txn_rec.coverage_txn_group_id := l_txn_group_id;
2772
2773 Debug('l_coverage_id =' || l_coverage_id, l_mod_name, 1);
2774 Debug('l_txn_group_id =' || l_txn_group_id, l_mod_name, 1);
2775 END IF;
2776 *******************************/
2777
2778 IF l_incident_id IS NOT NULL
2779 THEN
2780 -- swai: bug 5931926 - 12.0.2 3rd party logistics
2781 -- only set order header info to SR party and account
2782 -- if it is not specified on the bill-to for the txn line.
2783 IF (nvl(l_Charges_Rec.bill_to_account_id, FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM) OR
2784 (nvl(l_Charges_Rec.bill_to_party_id, FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM) THEN
2785 OPEN order_rec(l_incident_id);
2786 FETCH order_rec
2787 INTO l_party_id, l_account_id;
2788 IF (order_rec%NOTFOUND OR l_party_id IS NULL)
2789 THEN
2790 Fnd_Message.SET_NAME('CSD', 'CSD_API_PARTY_MISSING');
2791 Fnd_Message.SET_TOKEN('INCIDENT_ID', l_incident_id);
2792 Fnd_Msg_Pub.ADD;
2793 RAISE Fnd_Api.G_EXC_ERROR;
2794 END IF;
2795 IF order_rec%ISOPEN
2796 THEN
2797 CLOSE order_rec;
2798 END IF;
2799 ELSE
2800 l_party_id := l_Charges_Rec.bill_to_party_id;
2801 l_account_id := l_Charges_Rec.bill_to_account_id;
2802 END IF;
2803 END IF;
2804
2805 Debug('l_party_id =' || l_party_id,
2806 l_mod_name,
2807 1);
2808 Debug('l_account_id =' || l_account_id,
2809 l_mod_name,
2810 1);
2811 Debug('x_product_txn_rec.txn_billing_type_id =' ||
2812 x_product_txn_rec.txn_billing_type_id,
2813 l_mod_name,
2814 1);
2815 Debug('x_product_txn_rec.organization_id =' ||
2816 x_product_txn_rec.organization_id,
2817 l_mod_name,
2818 1);
2819
2820 -- Derive the line type and line category code
2821 -- from the transaction billing type
2822 Csd_Process_Util.GET_LINE_TYPE(p_txn_billing_type_id => x_product_txn_rec.txn_billing_type_id,
2823 p_org_id => x_product_txn_rec.organization_id,
2824 x_line_type_id => l_line_type_id,
2825 x_line_category_code => l_line_category_code,
2826 x_return_status => x_return_status);
2827
2828 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
2829 THEN
2830 RAISE Fnd_Api.G_EXC_ERROR;
2831 END IF;
2832
2833 Debug('l_line_type_id =' || l_line_type_id,
2834 l_mod_name,
2835 1);
2836 Debug('l_line_category_code =' || l_line_category_code,
2837 l_mod_name,
2838 1);
2839 Debug('x_product_txn_rec.price_list_id =' ||
2840 x_product_txn_rec.price_list_id,
2841 l_mod_name,
2842 1);
2843
2844 -- If line_type_id Or line_category_code is null
2845 -- then raise error
2846 IF (l_line_type_id IS NULL OR l_line_category_code IS NULL)
2847 THEN
2848 Fnd_Message.SET_NAME('CSD', 'CSD_API_LINE_TYPE_MISSING');
2849 Fnd_Message.SET_TOKEN('TXN_BILLING_TYPE_ID',
2850 x_product_txn_rec.txn_billing_type_id);
2851 Fnd_Msg_Pub.ADD;
2852 RAISE Fnd_Api.G_EXC_ERROR;
2853 END IF;
2854
2855 -- Get the currency code from the price list if it is null or g_miss
2856 IF NVL(x_product_txn_rec.price_list_id, Fnd_Api.G_MISS_NUM) <>
2857 Fnd_Api.G_MISS_NUM
2858 THEN
2859 BEGIN
2860 SELECT currency_code
2861 INTO l_curr_code
2862 FROM oe_price_lists
2863 WHERE price_list_id = x_product_txn_rec.price_list_id;
2864 EXCEPTION
2865 WHEN NO_DATA_FOUND THEN
2866 Fnd_Message.SET_NAME('CSD',
2867 'CSD_API_INV_PRICE_LIST_ID');
2868 Fnd_Message.SET_TOKEN('PRICE_LIST_ID',
2869 x_product_txn_rec.price_list_id);
2870 Fnd_Msg_Pub.ADD;
2871 RAISE Fnd_Api.G_EXC_ERROR;
2872 WHEN TOO_MANY_ROWS THEN
2873 Debug('Too many currency_codes', l_mod_name, 1);
2874 END;
2875 END IF;
2876
2877 Debug('l_curr_code =' || l_curr_code, l_mod_name, 1);
2878
2879 -- If l_curr_code is null then raise error
2880 IF l_curr_code IS NULL
2881 THEN
2882 Fnd_Message.SET_NAME('CSD', 'CSD_API_INV_CURR_CODE');
2883 Fnd_Message.SET_TOKEN('PRICE_LIST_ID',
2884 x_product_txn_rec.price_list_id);
2885 Fnd_Msg_Pub.ADD;
2886 RAISE Fnd_Api.G_EXC_ERROR;
2887 END IF;
2888
2889 l_serial_flag := Csd_Process_Util.Is_item_serialized(x_product_txn_rec.inventory_item_id);
2890
2891 -- swai: bug 5931926 - 12.0.2 3rd party logistics
2892 -- Instead of adding 3rd party action types to if-then statement,
2893 -- we are commenting the code out altogether. Currently,
2894 -- if conditions do not allow any product transaction lines
2895 -- through except walk-in-receipt which is no longer supported.
2896 -- We should allow RMA line creation without Serial number for
2897 -- all action types.
2898 /*****
2899 -- Serial Number required if the item is serialized
2900 IF l_serial_flag AND
2901 -- changing from serial_number to source_serial_number 11.5.10
2902 NVL(x_product_txn_rec.source_serial_number, Fnd_Api.G_MISS_CHAR) =
2903 Fnd_Api.G_MISS_CHAR AND
2904 x_product_txn_rec.action_type NOT IN ('SHIP', 'WALK_IN_ISSUE') AND
2905 (x_product_txn_rec.action_code <> 'LOANER' AND
2906 x_product_txn_rec.action_type <> 'RMA')
2907 THEN
2908 Fnd_Message.SET_NAME('CSD', 'CSD_API_SERIAL_NUM_MISSING');
2909 Fnd_Message.SET_TOKEN('INVENTORY_ITEM_ID',
2910 x_product_txn_rec.inventory_item_id);
2911 Fnd_Msg_Pub.ADD;
2912 Debug('Serial Number missing for inventory_item_id =' ||
2913 x_product_txn_rec.inventory_item_id,
2914 l_mod_name,
2915 1);
2916 RAISE Fnd_Api.G_EXC_ERROR;
2917 END IF;
2918 *****/
2919
2920 IF (x_product_txn_rec.new_order_flag = 'N')
2921 THEN
2922 -- Fix for bug# 4913791
2923 IF ( x_product_txn_rec.interface_to_om_flag = 'Y' ) THEN
2924 x_product_txn_rec.add_to_order_flag := 'Y';
2925 x_product_txn_rec.order_header_id := x_product_txn_rec.add_to_order_id;
2926 ELSE
2927 x_product_txn_rec.add_to_order_flag := 'F';
2928 x_product_txn_rec.order_header_id := FND_API.G_MISS_NUM;
2929 END IF;
2930
2931 ELSIF (x_product_txn_rec.new_order_flag = 'Y')
2932 THEN
2933 x_product_txn_rec.add_to_order_flag := 'F';
2934 x_product_txn_rec.order_header_id := Fnd_Api.G_MISS_NUM;
2935 END IF;
2936
2937 Debug('x_product_txn_rec.new_order_flag =' ||
2938 x_product_txn_rec.new_order_flag,
2939 l_mod_name,
2940 1);
2941 Debug('x_product_txn_rec.add_to_order_flag =' ||
2942 x_product_txn_rec.add_to_order_flag,
2943 l_mod_name,
2944 1);
2945 Debug('x_product_txn_rec.order_header_id =' ||
2946 x_product_txn_rec.order_header_id,
2947 l_mod_name,
2948 1);
2949
2950 -- assigning values for the charge record
2951 x_product_txn_rec.incident_id := l_incident_id;
2952 x_product_txn_rec.business_process_id := l_bus_process_id;
2953 x_product_txn_rec.line_type_id := l_line_type_id;
2954 x_product_txn_rec.currency_code := l_curr_code;
2955 x_product_txn_rec.line_category_code := l_line_category_code;
2956
2957 -- swai bug 7572247/7628204: default account primary bill-to and ship to
2958 IF ((l_incident_id is not NULL) AND
2959 (nvl(fnd_profile.value('CSD_DEFAULT_SR_ACCT_ADDR_FOR_LOGISTICS'), 'N') = 'Y'))
2960 THEN
2961
2962 IF ((nvl(x_product_txn_rec.bill_to_account_id, FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM) AND
2963 (nvl(x_product_txn_rec.invoice_to_org_id, FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM))
2964 THEN
2965 OPEN c_sr_primary_account_address (l_incident_id, 'BILL_TO');
2966 FETCH c_sr_primary_account_address INTO x_product_txn_rec.invoice_to_org_id;
2967 IF c_sr_primary_account_address%ISOPEN THEN
2968 CLOSE c_sr_primary_account_address;
2969 END IF;
2970 END IF;
2971
2972 IF ((nvl(x_product_txn_rec.ship_to_account_id, FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM) AND
2973 (nvl(x_product_txn_rec.ship_to_org_id, FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM))
2974 THEN
2975 OPEN c_sr_primary_account_address (l_incident_id, 'SHIP_TO');
2976 FETCH c_sr_primary_account_address INTO x_product_txn_rec.ship_to_org_id;
2977 IF c_sr_primary_account_address%ISOPEN THEN
2978 CLOSE c_sr_primary_account_address;
2979 END IF;
2980 END IF;
2981 END IF;
2982 -- end swai: bug 7572247/7628204
2983
2984 Debug('Convert product txn rec to charges rec', l_mod_name, 1);
2985
2986 -- Convert the product txn record to
2987 -- charge record
2988 Csd_Process_Util.CONVERT_TO_CHG_REC(p_prod_txn_rec => x_product_txn_rec,
2989 x_charges_rec => l_Charges_Rec,
2990 x_return_status => x_return_status);
2991
2992 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
2993 THEN
2994 RAISE Fnd_Api.G_EXC_ERROR;
2995 END IF;
2996
2997 Debug('Call process_charge_lines to create charge lines ',
2998 l_mod_name,
2999 1);
3000 Debug('x_product_txn_rec.transaction_type_id :' ||
3001 TO_CHAR(x_product_txn_rec.transaction_type_id),
3002 l_mod_name,
3003 1);
3004 Debug('l_Charges_Rec.transaction_type_id :' ||
3005 TO_CHAR(l_Charges_Rec.transaction_type_id),
3006 l_mod_name,
3007 1);
3008
3009 PROCESS_CHARGE_LINES(p_api_version => 1.0,
3010 p_commit => Fnd_Api.g_false,
3011 p_init_msg_list => Fnd_Api.g_true,
3012 p_validation_level => Fnd_Api.g_valid_level_full,
3013 p_action => 'CREATE',
3014 p_Charges_Rec => l_Charges_Rec,
3015 x_estimate_detail_id => x_estimate_detail_id,
3016 x_return_status => x_return_status,
3017 x_msg_count => x_msg_count,
3018 x_msg_data => x_msg_data);
3019
3020 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
3021 THEN
3022 RAISE Fnd_Api.G_EXC_ERROR;
3023 END IF;
3024
3025 Debug('NEW ESTIMATE DETAIL ID =' || x_estimate_detail_id,
3026 l_mod_name,
3027 1);
3028 Debug('Call csd_product_transactions_pkg.insert_row to insert prod txns',
3029 l_mod_name,
3030 1);
3031
3032 -- Note (TTRV) at this point I would like to derive values for the new columns, every column is not
3033 -- use full for regular repair orders, some of the columns are used by regurlar repair orders but
3034 -- they need not be filled at the time of creation of product transaction record. Some of the columns
3035 -- are updated by update programs.
3036 -- Please come back and verify that for repair types, Exchange, Advance Exchange, Replacement
3037 -- non-source columns are picked from UI. These comments are added by saupadhy TTRV
3038 Csd_Product_Transactions_Pkg.INSERT_ROW(px_PRODUCT_TRANSACTION_ID => x_product_txn_rec.PRODUCT_TRANSACTION_ID,
3039 p_REPAIR_LINE_ID => x_product_txn_rec.REPAIR_LINE_ID,
3040 p_ESTIMATE_DETAIL_ID => x_estimate_detail_id,
3041 p_ACTION_TYPE => x_product_txn_rec.ACTION_TYPE,
3042 p_ACTION_CODE => x_product_txn_rec.ACTION_CODE,
3043 p_LOT_NUMBER => x_product_txn_rec.LOT_NUMBER,
3044 p_SUB_INVENTORY => x_product_txn_rec.SUB_INVENTORY,
3045 p_INTERFACE_TO_OM_FLAG => 'N',
3046 p_BOOK_SALES_ORDER_FLAG => 'N',
3047 p_RELEASE_SALES_ORDER_FLAG => 'N',
3048 p_SHIP_SALES_ORDER_FLAG => 'N',
3049 p_PROD_TXN_STATUS => 'ENTERED',
3050 p_PROD_TXN_CODE => x_product_txn_rec.PROD_TXN_CODE,
3051 p_LAST_UPDATE_DATE => SYSDATE,
3052 p_CREATION_DATE => SYSDATE,
3053 p_LAST_UPDATED_BY => Fnd_Global.USER_ID,
3054 p_CREATED_BY => Fnd_Global.USER_ID,
3055 p_LAST_UPDATE_LOGIN => Fnd_Global.USER_ID,
3056 p_ATTRIBUTE1 => x_product_txn_rec.ATTRIBUTE1,
3057 p_ATTRIBUTE2 => x_product_txn_rec.ATTRIBUTE2,
3058 p_ATTRIBUTE3 => x_product_txn_rec.ATTRIBUTE3,
3059 p_ATTRIBUTE4 => x_product_txn_rec.ATTRIBUTE4,
3060 p_ATTRIBUTE5 => x_product_txn_rec.ATTRIBUTE5,
3061 p_ATTRIBUTE6 => x_product_txn_rec.ATTRIBUTE6,
3062 p_ATTRIBUTE7 => x_product_txn_rec.ATTRIBUTE7,
3063 p_ATTRIBUTE8 => x_product_txn_rec.ATTRIBUTE8,
3064 p_ATTRIBUTE9 => x_product_txn_rec.ATTRIBUTE9,
3065 p_ATTRIBUTE10 => x_product_txn_rec.ATTRIBUTE10,
3066 p_ATTRIBUTE11 => x_product_txn_rec.ATTRIBUTE11,
3067 p_ATTRIBUTE12 => x_product_txn_rec.ATTRIBUTE12,
3068 p_ATTRIBUTE13 => x_product_txn_rec.ATTRIBUTE13,
3069 p_ATTRIBUTE14 => x_product_txn_rec.ATTRIBUTE14,
3070 p_ATTRIBUTE15 => x_product_txn_rec.ATTRIBUTE15,
3071 p_CONTEXT => x_product_txn_rec.CONTEXT,
3072 p_OBJECT_VERSION_NUMBER => 1,
3073 P_SOURCE_SERIAL_NUMBER => x_product_txn_rec.source_serial_number,
3074 P_SOURCE_INSTANCE_ID => x_product_txn_rec.source_instance_Id,
3075 P_NON_SOURCE_SERIAL_NUMBER => x_product_txn_rec.non_source_serial_number,
3076 P_NON_SOURCE_INSTANCE_ID => x_product_txn_rec.non_source_instance_id,
3077 P_REQ_HEADER_ID => x_product_txn_rec.Req_Header_Id,
3078 P_REQ_LINE_ID => x_product_txn_rec.Req_Line_Id,
3079 P_ORDER_HEADER_ID => x_Product_Txn_Rec.Order_Header_Id,
3080 P_ORDER_LINE_ID => x_Product_Txn_Rec.Order_Line_Id,
3081 P_PRD_TXN_QTY_RECEIVED => x_product_txn_rec.Prd_Txn_Qty_Received,
3082 P_PRD_TXN_QTY_SHIPPED => x_product_txn_rec.Prd_Txn_Qty_Shipped,
3083 P_SUB_INVENTORY_RCVD => x_product_txn_rec.Sub_Inventory_Rcvd,
3084 P_LOT_NUMBER_RCVD => x_product_txn_rec.Lot_Number_Rcvd,
3085 P_LOCATOR_ID => x_product_txn_rec.Locator_Id,
3086 --R12 Development Changes
3087 p_picking_rule_id => x_product_txn_rec.picking_rule_id,
3088 P_PROJECT_ID => x_product_txn_rec.project_id,
3089 P_TASK_ID => x_product_txn_rec.task_id,
3090 P_UNIT_NUMBER => x_product_txn_rec.unit_number,
3091 P_INTERNAL_PO_HEADER_ID => x_product_txn_rec.internal_po_header_id); -- swai: bug 6148019
3092
3093
3094 Debug('NEW PRODUCT TXN ID = ' ||
3095 x_product_txn_rec.PRODUCT_TRANSACTION_ID,
3096 l_mod_name,
3097 1);
3098
3099 UPDATE csd_repairs
3100 SET ro_txn_status = 'CHARGE_ENTERED'
3101 WHERE repair_line_id = x_product_txn_rec.REPAIR_LINE_ID;
3102 IF SQL%NOTFOUND
3103 THEN
3104 Fnd_Message.SET_NAME('CSD', 'CSD_ERR_REPAIRS_UPDATE');
3105 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
3106 x_product_txn_rec.repair_line_id);
3107 Fnd_Msg_Pub.ADD;
3108 RAISE Fnd_Api.G_EXC_ERROR;
3109 END IF;
3110
3111 -- Process the product txn only if the process_flag = 'Y'
3112 -- Else skip to the end and return the control to calling program
3113 IF x_product_txn_rec.process_txn_flag = 'Y'
3114 THEN
3115
3116 -- Assigning values for the order record
3117 l_order_rec.incident_id := l_incident_id;
3118 l_order_rec.party_id := l_party_id;
3119 l_order_rec.account_id := l_account_id;
3120 l_order_rec.org_id := Cs_Std.get_item_valdn_orgzn_id;
3121
3122 -- Interface the charge line to OM if the flag is checked
3123 IF x_product_txn_rec.interface_to_om_flag = 'Y'
3124 THEN
3125
3126 BEGIN
3127
3128 -- Define savepoint
3129 SAVEPOINT create_sales_order;
3130
3131 BEGIN
3132 SELECT revision_qty_control_code
3133 INTO l_rev_ctl_code
3134 FROM mtl_system_items
3135 WHERE organization_id =
3136 Cs_Std.get_item_valdn_orgzn_id
3137 AND inventory_item_id =
3138 x_product_txn_rec.inventory_item_id;
3139 EXCEPTION
3140 WHEN NO_DATA_FOUND THEN
3141 Fnd_Message.SET_NAME('CSD',
3142 'CSD_INVALID_INVENTORY_ITEM');
3143 Fnd_Msg_Pub.ADD;
3144 RAISE CREATE_ORDER;
3145 END;
3146
3147 IF l_rev_ctl_code = 2
3148 THEN
3149 BEGIN
3150 SELECT 'x'
3151 INTO l_dummy
3152 FROM mtl_item_revisions
3153 WHERE inventory_item_id =
3154 x_product_txn_rec.inventory_item_id
3155 AND organization_id =
3156 Cs_Std.get_item_valdn_orgzn_id
3157 AND revision = x_product_txn_rec.revision;
3158 EXCEPTION
3159 WHEN NO_DATA_FOUND THEN
3160 Fnd_Message.SET_NAME('CSD',
3161 'CSD_INVALID_REVISION');
3162 Fnd_Msg_Pub.ADD;
3163 RAISE CREATE_ORDER;
3164 END;
3165 END IF;
3166
3167 Debug('Call process_sales_order to create SO',
3168 l_mod_name,
3169 1);
3170 Debug('l_order_rec.incident_id =' ||
3171 l_order_rec.incident_id,
3172 l_mod_name,
3173 1);
3174 Debug('l_order_rec.party_id =' ||
3175 l_order_rec.party_id,
3176 l_mod_name,
3177 1);
3178 Debug('l_order_rec.account_id =' ||
3179 l_order_rec.account_id,
3180 l_mod_name,
3181 1);
3182
3183 --taklam
3184 if (x_product_txn_rec.unit_number) is not null then
3185 FND_PROFILE.PUT('CSD_UNIT_NUMBER', x_product_txn_rec.unit_number);
3186 end if;
3187
3188 PROCESS_SALES_ORDER(p_api_version => 1.0,
3189 p_commit => Fnd_Api.g_false,
3190 p_init_msg_list => Fnd_Api.g_true,
3191 p_validation_level => Fnd_Api.g_valid_level_full,
3192 p_action => 'CREATE',
3193 p_order_rec => l_order_rec,
3194 x_return_status => x_return_status,
3195 x_msg_count => x_msg_count,
3196 x_msg_data => x_msg_data);
3197
3198 if (x_product_txn_rec.unit_number) is not null then
3199 FND_PROFILE.PUT('CSD_UNIT_NUMBER', null);
3200 end if;
3201
3202 Debug('x_return_status from process_sales_order =' ||
3203 x_return_status,
3204 l_mod_name,
3205 1);
3206
3207 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
3208 THEN
3209 Debug('process_sales_order failed', l_mod_name, 1);
3210 RAISE CREATE_ORDER;
3211 END IF;
3212
3213 UPDATE csd_product_transactions
3214 SET prod_txn_status = 'SUBMITTED',
3215 interface_to_om_flag = 'Y'
3216 WHERE product_transaction_id =
3217 x_product_txn_rec.PRODUCT_TRANSACTION_ID;
3218 IF SQL%NOTFOUND
3219 THEN
3220 Fnd_Message.SET_NAME('CSD',
3221 'CSD_ERR_PRD_TXN_UPDATE');
3222 Fnd_Message.SET_TOKEN('PRODUCT_TRANSACTION_ID',
3223 x_product_txn_rec.PRODUCT_TRANSACTION_ID);
3224 Fnd_Msg_Pub.ADD;
3225 RAISE CREATE_ORDER;
3226 END IF;
3227
3228 UPDATE csd_repairs
3229 SET ro_txn_status = 'OM_SUBMITTED'
3230 WHERE repair_line_id =
3231 x_product_txn_rec.REPAIR_LINE_ID;
3232 IF SQL%NOTFOUND
3233 THEN
3234 Fnd_Message.SET_NAME('CSD',
3235 'CSD_ERR_REPAIRS_UPDATE');
3236 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
3237 x_product_txn_rec.repair_line_id);
3238 Fnd_Msg_Pub.ADD;
3239 RAISE CREATE_ORDER;
3240 END IF;
3241
3242 -- swai: bug 6001057
3243 -- rearranged code so that call to OM API can be used to update
3244 -- project, unit number, or 3rd party end_customer
3245 if (((x_product_txn_rec.project_id is not null)
3246 OR (x_product_txn_rec.unit_number is not null)
3247 OR (x_product_txn_rec.sub_inventory is not null) ----bug#9955988
3248 OR (x_product_txn_rec.action_type in ('RMA_THIRD_PTY', 'SHIP_THIRD_PTY')))
3249 and ((NVL(x_product_txn_rec.project_id,-1)) <> FND_API.G_MISS_NUM)) then --bug#6075825
3250
3251 OPEN order_line_cu(x_estimate_detail_id);
3252 FETCH order_line_cu into l_order_line_id, l_p_ship_from_org_id;
3253 CLOSE order_line_cu;
3254
3255 if (l_order_line_id) is not null then
3256 l_Line_Tbl_Type(1) := OE_Order_PUB.G_MISS_LINE_REC;
3257 l_Line_Tbl_Type(1).line_id := l_order_line_id;
3258 l_Line_Tbl_Type(1).operation := OE_GLOBALS.G_OPR_UPDATE;
3259
3260 -- taklam: update project and unit number fields
3261 if ((x_product_txn_rec.project_id is not null) or (x_product_txn_rec.unit_number is not null)) then
3262
3263 l_Line_Tbl_Type(1).end_item_unit_number := x_product_txn_rec.unit_number;
3264
3265 if (x_product_txn_rec.project_id is not null) then
3266 OPEN project_cu(x_product_txn_rec.project_id,l_p_ship_from_org_id);
3267 FETCH project_cu into l_project_count;
3268 CLOSE project_cu;
3269
3270 if (l_project_count >= 1) then
3271 l_Line_Tbl_Type(1).project_id := x_product_txn_rec.project_id;
3272 l_Line_Tbl_Type(1).task_id := x_product_txn_rec.task_id;
3273 else
3274 FND_MESSAGE.SET_NAME('CSD','CSD_ERR_PROJECT_UPDATE');
3275 FND_MESSAGE.SET_TOKEN('project_id',x_product_txn_rec.project_id);
3276 FND_MESSAGE.SET_TOKEN('ship_from_org_id',l_p_ship_from_org_id);
3277 FND_MSG_PUB.ADD;
3278 RAISE CREATE_ORDER;
3279 end if;
3280 end if;
3281 end if; -- end update project and unit number fields
3282
3283 --bug#9955988
3284 if (x_product_txn_rec.sub_inventory is not null) then
3285 l_Line_Tbl_Type(1).subinventory := x_product_txn_rec.sub_inventory ;
3286 end if;
3287 --bug#9955988
3288
3289 -- swai: update 3rd party fields.
3290 -- IB Owner must be set to END_CUSTOMER and end_custoemr_id mustbe
3291 -- set to the SR customer account id in order for 3rd party lines to
3292 -- avoid changing IB ownership during material transactions.
3293 if (x_product_txn_rec.action_type in ('RMA_THIRD_PTY', 'SHIP_THIRD_PTY')) then
3294 -- get SR customer account
3295 OPEN sr_account_cu (x_product_txn_rec.repair_line_id);
3296 FETCH sr_account_cu into l_sr_account_id;
3297 CLOSE sr_account_cu;
3298 if (l_sr_account_id) is not null then
3299 l_Line_Tbl_Type(1).ib_owner := 'END_CUSTOMER';
3300 l_Line_Tbl_Type(1).end_customer_id := l_sr_account_id;
3301 end if;
3302 end if; -- end update 3rd party fields
3303
3304 OE_ORDER_PUB.Process_Line(
3305 p_line_tbl => l_Line_Tbl_Type,
3306 x_line_out_tbl => x_Line_Tbl_Type,
3307 x_return_status => x_return_status,
3308 x_msg_count => x_msg_count,
3309 x_msg_data => x_msg_data
3310 );
3311
3312 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
3313 FND_MESSAGE.SET_NAME('CSD','CSD_ERR_OM_PROCESS_LINE');
3314 FND_MSG_PUB.ADD;
3315 RAISE CREATE_ORDER;
3316 END IF;
3317 end if; -- order line is not null
3318 end if;
3319 -- end swai: bug 6001057
3320
3321
3322 EXCEPTION
3323 WHEN CREATE_ORDER THEN
3324 Debug('In CREATE_ORDER exception', l_mod_name, 1);
3325 RAISE CREATE_ORDER;
3326 WHEN OTHERS THEN
3327 Debug('In OTHERS exception', l_mod_name, 1);
3328 RAISE CREATE_ORDER;
3329 END;
3330 END IF; -- end of create sales order
3331
3332 -- Book the Sales Order if the book_sales_order_flag is checked
3333 IF x_product_txn_rec.book_sales_order_flag = 'Y'
3334 THEN
3335
3336 BEGIN
3337
3338 -- Define Savepoint
3339 SAVEPOINT book_sales_order;
3340
3341 Debug('x_estimate_detail_id =' || x_estimate_detail_id,
3342 l_mod_name,
3343 1);
3344
3345 BEGIN
3346 -- Get the order header id from the charge line
3347 SELECT a.order_header_id, a.order_line_id
3348 INTO l_order_header_id, l_order_line_id
3349 FROM cs_estimate_details a
3350 WHERE a.estimate_detail_id = x_estimate_detail_id
3351 AND a.order_header_id IS NOT NULL
3352 AND a.order_line_id IS NOT NULL;
3353
3354 --assign the order header id
3355 l_order_rec.order_header_id := l_order_header_id;
3356 l_order_rec.order_line_id := l_order_line_id;
3357
3358 EXCEPTION
3359 WHEN NO_DATA_FOUND THEN
3360 FND_MESSAGE.SET_NAME('CSD','CSD_API_BOOKING_FAILED'); /*FP Fixed for bug#5147030 message changed*/
3361 /*
3362 Fnd_Message.SET_NAME('CSD',
3363 'CSD_API_INV_EST_DETAIL_ID');
3364 Fnd_Message.SET_TOKEN('ESTIMATE_DETAIL_ID',
3365 x_estimate_detail_id); */
3366 Fnd_Msg_Pub.ADD;
3367 Debug('Sales Order missing for estimate_detail_id =' ||
3368 x_estimate_detail_id,
3369 l_mod_name,
3370 1);
3371 RAISE BOOK_ORDER;
3372 WHEN TOO_MANY_ROWS THEN
3373 Debug('Too many order header id',
3374 l_mod_name,
3375 1);
3376 RAISE BOOK_ORDER;
3377 END;
3378
3379 BEGIN
3380 -- To Book an Order Sales Rep and ship_from_org_id is reqd
3381 -- so check if the Order header has it
3382 SELECT ship_from_org_id, unit_selling_price, org_id
3383 INTO l_ship_from_org_id,
3384 l_unit_selling_price,
3385 l_order_rec.org_id
3386 FROM oe_order_lines_all
3387 WHERE line_id = l_order_line_id;
3388 /*Fixed for bug#5368306
3389 OM does not require sales rep at line to book it.
3390 Depot should not check sales rep at line since oe
3391 allows to book an order without a sales rep at
3392 the line.
3393 Following condition which checks sales rep at
3394 order line has been commented.
3395 */
3396 /* AND salesrep_id IS NOT NULL; */
3397 EXCEPTION
3398 WHEN NO_DATA_FOUND THEN
3399 Fnd_Message.SET_NAME('CSD',
3400 'CSD_API_SALES_REP_MISSING');
3401 Fnd_Message.SET_TOKEN('ORDER_LINE_ID',
3402 l_order_line_id);
3403 Fnd_Msg_Pub.ADD;
3404 Debug('Sales rep missing for Line_id=' ||
3405 l_order_line_id,
3406 l_mod_name,
3407 1);
3408 RAISE BOOK_ORDER;
3409 WHEN TOO_MANY_ROWS THEN
3410 Debug('Too many order ship_from_org_id',
3411 l_mod_name,
3412 1);
3413 END;
3414
3415 IF l_ship_from_org_id IS NULL
3416 THEN
3417 Fnd_Message.SET_NAME('CSD',
3418 'CSD_API_SHIP_FROM_ORG_MISSING');
3419 Fnd_Message.SET_TOKEN('ORDER_LINE_ID',
3420 l_order_line_id);
3421 Fnd_Msg_Pub.ADD;
3422 Debug('Ship from Org Id missing for Line_id=' ||
3423 l_order_line_id,
3424 l_mod_name,
3425 1);
3426 RAISE BOOK_ORDER;
3427 END IF;
3428
3429 IF l_unit_selling_price IS NULL
3430 THEN
3431 Fnd_Message.SET_NAME('CSD',
3432 'CSD_API_PRICE_MISSING');
3433 Fnd_Message.SET_TOKEN('ORDER_LINE_ID',
3434 l_order_line_id);
3435 Fnd_Msg_Pub.ADD;
3436 Debug('Unit Selling price missing for Line_id=' ||
3437 l_order_line_id,
3438 l_mod_name,
3439 1);
3440 RAISE BOOK_ORDER;
3441 END IF;
3442
3443 Debug('l_order_rec.order_header_id =' ||
3444 l_order_rec.order_header_id,
3445 l_mod_name,
3446 1);
3447
3448 BEGIN
3449 SELECT booked_flag
3450 INTO l_booked_flag
3451 FROM oe_order_headers_all
3452 WHERE header_id = l_order_rec.order_header_id;
3453 EXCEPTION
3454 WHEN NO_DATA_FOUND THEN
3455 Debug('The Sales Order is booked OR does not exist',
3456 l_mod_name,
3457 1);
3458 RAISE BOOK_ORDER;
3459 END;
3460
3461 Debug('l_order_rec.org_id' || l_order_rec.org_id,
3462 l_mod_name,
3463 1);
3464
3465 IF NVL(l_booked_flag, 'N') = 'N'
3466 THEN
3467 -- swai: bug 6001057
3468 -- rearranged code so that call to OM API can be used to update
3469 -- project, unit number, or 3rd party end_customer
3470 if (((x_product_txn_rec.project_id is not null)
3471 OR (x_product_txn_rec.unit_number is not null)
3472 OR (x_product_txn_rec.sub_inventory is not null) ----bug#9955988
3473 OR (x_product_txn_rec.action_type in ('RMA_THIRD_PTY', 'SHIP_THIRD_PTY')))
3474 and ((NVL(x_product_txn_rec.project_id,-1)) <> FND_API.G_MISS_NUM)) then --bug#6075825
3475
3476 if (l_order_line_id) is not null then
3477 l_Line_Tbl_Type(1) := OE_Order_PUB.G_MISS_LINE_REC;
3478 l_Line_Tbl_Type(1).line_id := l_order_line_id;
3479 l_Line_Tbl_Type(1).operation := OE_GLOBALS.G_OPR_UPDATE;
3480
3481 -- taklam: update project and unit number fields
3482 if ((x_product_txn_rec.project_id is not null) or (x_product_txn_rec.unit_number is not null)) then
3483
3484 l_Line_Tbl_Type(1).end_item_unit_number := x_product_txn_rec.unit_number;
3485
3486 if (x_product_txn_rec.project_id is not null) then
3487 OPEN project_cu(x_product_txn_rec.project_id,l_ship_from_org_id);
3488 FETCH project_cu into l_project_count;
3489 CLOSE project_cu;
3490
3491 if (l_project_count >= 1) then
3492 l_Line_Tbl_Type(1).project_id := x_product_txn_rec.project_id;
3493 l_Line_Tbl_Type(1).task_id := x_product_txn_rec.task_id;
3494 else
3495 FND_MESSAGE.SET_NAME('CSD','CSD_ERR_PROJECT_UPDATE');
3496 FND_MESSAGE.SET_TOKEN('project_id',x_product_txn_rec.project_id);
3497 FND_MESSAGE.SET_TOKEN('ship_from_org_id',l_ship_from_org_id);
3498 FND_MSG_PUB.ADD;
3499 RAISE BOOK_ORDER;
3500 end if;
3501 end if;
3502 end if;
3503
3504 --bug#9955988
3505 if (x_product_txn_rec.sub_inventory is not null) then
3506 l_Line_Tbl_Type(1).subinventory := x_product_txn_rec.sub_inventory ;
3507 end if;
3508 --bug#9955988
3509
3510 -- swai: update 3rd party fields.
3511 -- IB Owner must be set to END_CUSTOMER and end_custoemr_id mustbe
3512 -- set to the SR customer account id in order for 3rd party lines to
3513 -- avoid changing IB ownership during material transactions.
3514 if (x_product_txn_rec.action_type in ('RMA_THIRD_PTY', 'SHIP_THIRD_PTY')) then
3515 -- get SR customer account
3516 OPEN sr_account_cu (x_product_txn_rec.repair_line_id);
3517 FETCH sr_account_cu into l_sr_account_id;
3518 CLOSE sr_account_cu;
3519 if (l_sr_account_id) is not null then
3520 l_Line_Tbl_Type(1).ib_owner := 'END_CUSTOMER';
3521 l_Line_Tbl_Type(1).end_customer_id := l_sr_account_id;
3522 end if;
3523 end if; -- end update 3rd party fields
3524
3525 OE_ORDER_PUB.Process_Line(
3526 p_line_tbl => l_Line_Tbl_Type,
3527 x_line_out_tbl => x_Line_Tbl_Type,
3528 x_return_status => x_return_status,
3529 x_msg_count => x_msg_count,
3530 x_msg_data => x_msg_data
3531 );
3532
3533 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
3534 FND_MESSAGE.SET_NAME('CSD','CSD_ERR_OM_PROCESS_LINE');
3535 FND_MSG_PUB.ADD;
3536 RAISE BOOK_ORDER;
3537 END IF;
3538 end if; -- order line is not null
3539 end if;
3540 -- end swai: bug 6001057
3541
3542 Debug('Call process_sales_order to book SO',
3543 l_mod_name,
3544 1);
3545 PROCESS_SALES_ORDER(p_api_version => 1.0,
3546 p_commit => Fnd_Api.g_false,
3547 p_init_msg_list => Fnd_Api.g_true,
3548 p_validation_level => Fnd_Api.g_valid_level_full,
3549 p_action => 'BOOK',
3550 p_order_rec => l_order_rec,
3551 x_return_status => x_return_status,
3552 x_msg_count => x_msg_count,
3553 x_msg_data => x_msg_data);
3554
3555 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
3556 THEN
3557 Debug('process_sales_order failed to book Sales order',
3558 l_mod_name,
3559 1);
3560 RAISE BOOK_ORDER;
3561 END IF;
3562 END IF;
3563
3564 -- -- Update product txn with the status
3565 -- UPDATE csd_product_transactions
3566 -- SET prod_txn_status = 'BOOKED',
3567 -- book_sales_order_flag = 'Y'
3568 -- WHERE product_transaction_id = x_product_txn_rec.PRODUCT_TRANSACTION_ID;
3569 -- IF SQL%NOTFOUND then
3570 -- FND_MESSAGE.SET_NAME('CSD','CSD_ERR_PRD_TXN_UPDATE');
3571 -- FND_MESSAGE.SET_TOKEN('PRODUCT_TRANSACTION_ID',x_product_txn_rec.PRODUCT_TRANSACTION_ID);
3572 -- FND_MSG_PUB.ADD;
3573 -- RAISE BOOK_ORDER;
3574 -- END IF;
3575
3576 -- Fix for bug#4020651
3577 Csd_Update_Programs_Pvt.prod_txn_status_upd(p_repair_line_id => x_product_txn_rec.repair_line_id,
3578 p_commit => Fnd_Api.g_false);
3579
3580 --Update csd_repairs with status
3581 UPDATE csd_repairs
3582 SET ro_txn_status = 'OM_BOOKED'
3583 WHERE repair_line_id =
3584 x_product_txn_rec.REPAIR_LINE_ID;
3585 IF SQL%NOTFOUND
3586 THEN
3587 Fnd_Message.SET_NAME('CSD',
3588 'CSD_ERR_REPAIRS_UPDATE');
3589 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
3590 x_product_txn_rec.repair_line_id);
3591 Fnd_Msg_Pub.ADD;
3592 RAISE BOOK_ORDER;
3593 END IF;
3594
3595 EXCEPTION
3596 WHEN BOOK_ORDER THEN
3597 Debug('In BOOK_ORDER Exception while booking SO',
3598 l_mod_name,
3599 1);
3600 RAISE BOOK_ORDER;
3601 WHEN OTHERS THEN
3602 Debug('In OTHERS Exception while booking SO',
3603 l_mod_name,
3604 1);
3605 RAISE BOOK_ORDER;
3606 END;
3607 END IF; --end of Book Sales Order
3608
3609 -- Release Sales Order if the flag is checked
3610 IF x_product_txn_rec.release_sales_order_flag = 'Y'
3611 THEN
3612 BEGIN
3613
3614 -- Define savepoint
3615 SAVEPOINT release_sales_order;
3616
3617 Debug('x_product_txn_rec.sub_inventory =' ||
3618 x_product_txn_rec.sub_inventory,
3619 l_mod_name,
3620 1);
3621
3622 IF NVL(x_product_txn_rec.sub_inventory,
3623 Fnd_Api.G_MISS_CHAR) <> Fnd_Api.G_MISS_CHAR
3624 THEN
3625 BEGIN
3626 SELECT 'x'
3627 INTO l_dummy
3628 FROM mtl_secondary_inventories
3629 WHERE secondary_inventory_name =
3630 x_product_txn_rec.sub_inventory
3631 AND organization_id = l_ship_from_org_id;
3632 EXCEPTION
3633 WHEN NO_DATA_FOUND THEN
3634 Fnd_Message.SET_NAME('CSD',
3635 'CSD_API_SUB_INV_MISSING');
3636 Fnd_Message.SET_TOKEN('SUB_INVENTORY',
3637 x_product_txn_rec.sub_inventory);
3638 Fnd_Msg_Pub.ADD;
3639 Debug(x_product_txn_rec.sub_inventory ||
3640 ':Subinventory does not exist',
3641 l_mod_name,
3642 1);
3643 RAISE RELEASE_ORDER;
3644 WHEN OTHERS THEN
3645 Debug('More than one Subinventory does exist with same name',
3646 l_mod_name,
3647 1);
3648 RAISE RELEASE_ORDER;
3649 END;
3650 l_order_rec.PICK_FROM_SUBINVENTORY := x_product_txn_rec.sub_inventory;
3651 END IF;
3652 /* R12 SN reservations change Begin */
3653 -- Get Item attributes in local variable
3654 CSD_LOGISTICS_UTIL.Get_ItemAttributes(p_Inventory_Item_Id => x_Product_Txn_Rec.Inventory_Item_Id,
3655 p_inv_org_id => x_Product_Txn_Rec.inventory_org_id,
3656 x_ItemAttributes => l_ItemAttributes);
3657 -- Get the default pick rule id
3658 Fnd_Profile.Get('CSD_AUTO_SRL_RESERVE', l_auto_reserve_profile);
3659 if(l_auto_reserve_profile is null) then
3660 l_auto_reserve_profile := 'N';
3661 end if;
3662
3663 Debug('Going to process reservation..', l_mod_name, 1);
3664 Debug(l_auto_reserve_profile, l_mod_name,1);
3665 Debug(x_Product_Txn_Rec.source_Serial_number, l_mod_name,1);
3666 Debug(x_Product_Txn_Rec.sub_inventory, l_mod_name,1);
3667 Debug(x_Product_Txn_Rec.action_type, l_mod_name,1);
3668 Debug(to_char(l_itemAttributes.reservable_type), l_mod_name,1);
3669 Debug(to_char(l_itemAttributes.serial_Code), l_mod_name,1);
3670
3671
3672 -- swai: bug 5931926 - 12.0.2 added 3rd party action type
3673 IF( l_auto_reserve_profile = 'Y'
3674 AND x_Product_Txn_Rec.source_Serial_number is not null
3675 AND x_Product_Txn_Rec.sub_inventory is not null
3676 AND x_product_txn_rec.action_type IN ('SHIP', 'WALK_IN_ISSUE', 'SHIP_THIRD_PTY')
3677 AND l_ItemAttributes.reservable_type = C_RESERVABLE
3678 AND (l_ItemAttributes.serial_code = C_SERIAL_CONTROL_AT_RECEIPT
3679 OR
3680 l_ItemAttributes.serial_code = C_SERIAL_CONTROL_PREDEFINED) ) THEN
3681
3682 Debug('Checking reservation id for serial number..['
3683 ||x_Product_Txn_Rec.source_Serial_number||']', l_mod_name, 1);
3684
3685 l_serial_rsv_rec.inventory_item_id := x_Product_Txn_Rec.inventory_item_id;
3686 l_serial_rsv_rec.inv_organization_id := x_Product_Txn_Rec.inventory_org_id;
3687 l_serial_rsv_rec.order_header_id := l_order_header_id;
3688 l_serial_rsv_rec.order_line_id := l_order_line_Id;
3689 l_serial_rsv_rec.order_schedule_date := sysdate;
3690 l_serial_rsv_rec.serial_number := x_Product_Txn_Rec.source_serial_number;
3691 l_serial_rsv_rec.locator_id := x_Product_Txn_Rec.locator_id;
3692 l_serial_rsv_rec.revision := x_Product_Txn_Rec.revision;
3693 l_serial_rsv_rec.lot_number := x_Product_Txn_Rec.lot_number;
3694 l_serial_rsv_rec.subinventory_code := x_Product_Txn_Rec.sub_inventory;
3695 l_serial_rsv_rec.reservation_uom_code := x_Product_Txn_Rec.Unit_Of_Measure_Code;
3696
3697 Debug('Calling reserve serial..', l_mod_name, 1);
3698 CSD_LOGISTICS_UTIL.Reserve_serial_number(l_serial_rsv_rec, x_return_status);
3699
3700 if(x_return_status = FND_API.G_RET_STS_ERROR) THEN
3701 Fnd_Message.SET_NAME('CSD', 'CSD_SRL_RESERVE_FAILED');
3702 Fnd_Msg_Pub.ADD;
3703 RAISE RELEASE_ORDER;
3704 END IF;
3705
3706 END IF;
3707
3708 /* R12 SN reservations change End */
3709
3710
3711
3712 -- R12 development changes
3713 -- Added the code to get the picking rule from profile only if the product_txn_rec does
3714 -- not have it.
3715 IF (x_product_txn_rec.picking_rule_id IS NULL)
3716 THEN
3717 -- Get the default pick rule id
3718 Fnd_Profile.Get('CSD_DEF_PICK_RELEASE_RULE',
3719 l_picking_rule_id);
3720
3721 ELSE
3722
3723 l_picking_rule_id := x_product_txn_rec.picking_rule_id;
3724
3725 END IF; -- End of if for input pick_rule_id check.
3726
3727 -- Get the Picking Rule Id
3728 BEGIN
3729 SELECT picking_rule_id
3730 INTO l_picking_rule_id
3731 FROM wsh_picking_rules
3732 WHERE picking_rule_id = l_picking_rule_id;
3733 EXCEPTION
3734 WHEN NO_DATA_FOUND THEN
3735 Fnd_Message.SET_NAME('CSD',
3736 'CSD_API_INV_PICKING_RULE_ID');
3737 Fnd_Message.SET_TOKEN('PICKING_RULE_ID',
3738 l_picking_rule_id);
3739 Fnd_Msg_Pub.ADD;
3740 Debug(l_picking_rule_id ||
3741 ':Picking Rule does not exist ',
3742 l_mod_name,
3743 1);
3744 RAISE RELEASE_ORDER;
3745 WHEN OTHERS THEN
3746 Debug('More than one Picking Rule exist with same name',
3747 l_mod_name,
3748 1);
3749 RAISE RELEASE_ORDER;
3750 END;
3751
3752 l_order_rec.picking_rule_id := l_picking_rule_id;
3753 l_order_rec.org_id := l_ship_from_org_id;
3754
3755 BEGIN
3756 SELECT released_status
3757 INTO l_release_status
3758 FROM wsh_delivery_details
3759 WHERE source_line_id = l_order_line_id
3760 AND SOURCE_CODE = 'OE'; /*Fixed for bug#5846054 */
3761 EXCEPTION
3762 WHEN NO_DATA_FOUND THEN
3763 Debug('No Delivery lines found', l_mod_name, 1);
3764 RAISE RELEASE_ORDER;
3765 WHEN TOO_MANY_ROWS THEN
3766 Debug('Too Delivery lines found for the order line',
3767 l_mod_name,
3768 1);
3769 RAISE RELEASE_ORDER;
3770 END;
3771
3772 IF l_release_status IN ('R', 'B')
3773 THEN
3774 Debug('Call process_sales_order to pick release sales order',
3775 l_mod_name,
3776 1);
3777 PROCESS_SALES_ORDER(p_api_version => 1.0,
3778 p_commit => Fnd_Api.g_false,
3779 p_init_msg_list => Fnd_Api.g_true,
3780 p_validation_level => Fnd_Api.g_valid_level_full,
3781 p_action => 'PICK-RELEASE',
3782 p_order_rec => l_order_rec,
3783 x_return_status => x_return_status,
3784 x_msg_count => x_msg_count,
3785 x_msg_data => x_msg_data);
3786
3787 IF (x_return_status = Fnd_Api.G_RET_STS_ERROR)
3788 THEN
3789 Debug('process_sales_order failed',
3790 l_mod_name,
3791 1);
3792 RAISE RELEASE_ORDER;
3793 END IF;
3794 END IF;
3795
3796 BEGIN
3797 SELECT released_status
3798 INTO l_release_status
3799 FROM wsh_delivery_details
3800 WHERE source_line_id = l_order_line_id
3801 AND SOURCE_CODE = 'OE'; /*Fixed for bug#5846054 */
3802 EXCEPTION
3803 WHEN NO_DATA_FOUND THEN
3804 Debug('No Delivery lines found', l_mod_name, 1);
3805 RAISE RELEASE_ORDER;
3806 WHEN TOO_MANY_ROWS THEN
3807 Debug('Too Delivery lines found for the order line',
3808 l_mod_name,
3809 1);
3810 RAISE RELEASE_ORDER;
3811 END;
3812
3813 IF l_release_status = 'Y'
3814 THEN
3815 -- swai: bug 5931926 - 12.0.2 added 3rd party action type
3816 IF (x_product_txn_rec.ACTION_TYPE IN
3817 ('SHIP', 'WALK_IN_ISSUE', 'SHIP_THIRD_PTY'))
3818 THEN
3819 UPDATE csd_product_transactions
3820 SET prod_txn_status = 'RELEASED',
3821 release_sales_order_flag = 'Y'
3822 WHERE product_transaction_id =
3823 x_product_txn_rec.PRODUCT_TRANSACTION_ID;
3824 IF SQL%NOTFOUND
3825 THEN
3826 Fnd_Message.SET_NAME('CSD',
3827 'CSD_ERR_PRD_TXN_UPDATE');
3828 Fnd_Message.SET_TOKEN('PRODUCT_TRANSACTION_ID',
3829 x_product_txn_rec.PRODUCT_TRANSACTION_ID);
3830 Fnd_Msg_Pub.ADD;
3831 RAISE RELEASE_ORDER;
3832 END IF;
3833 END IF;
3834
3835 UPDATE csd_repairs
3836 SET ro_txn_status = 'OM_RELEASED'
3837 WHERE repair_line_id =
3838 x_product_txn_rec.REPAIR_LINE_ID;
3839 IF SQL%NOTFOUND
3840 THEN
3841 Fnd_Message.SET_NAME('CSD',
3842 'CSD_ERR_REPAIRS_UPDATE');
3843 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
3844 x_product_txn_rec.repair_line_id);
3845 Fnd_Msg_Pub.ADD;
3846 RAISE RELEASE_ORDER;
3847 END IF;
3848
3849 ELSIF l_release_status IN ('S', 'B')
3850 THEN
3851 -- swai: bug 5931926 - 12.0.2 added 3rd party action type
3852 IF (x_product_txn_rec.ACTION_TYPE IN
3853 ('SHIP', 'WALK_IN_ISSUE', 'SHIP_THIRD_PTY'))
3854 THEN
3855 UPDATE csd_product_transactions
3856 SET prod_txn_status = 'BOOKED'
3857 WHERE product_transaction_id =
3858 x_product_txn_rec.PRODUCT_TRANSACTION_ID;
3859 IF SQL%NOTFOUND
3860 THEN
3861 Fnd_Message.SET_NAME('CSD',
3862 'CSD_ERR_PRD_TXN_UPDATE');
3863 Fnd_Message.SET_TOKEN('PRODUCT_TRANSACTION_ID',
3864 x_product_txn_rec.PRODUCT_TRANSACTION_ID);
3865 Fnd_Msg_Pub.ADD;
3866 RAISE RELEASE_ORDER;
3867 END IF;
3868 END IF;
3869
3870 UPDATE csd_repairs
3871 SET ro_txn_status = 'OM_BOOKED'
3872 WHERE repair_line_id =
3873 x_product_txn_rec.REPAIR_LINE_ID;
3874 IF SQL%NOTFOUND
3875 THEN
3876 Fnd_Message.SET_NAME('CSD',
3877 'CSD_ERR_REPAIRS_UPDATE');
3878 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
3879 x_product_txn_rec.repair_line_id);
3880 Fnd_Msg_Pub.ADD;
3881 RAISE RELEASE_ORDER;
3882 END IF;
3883
3884 END IF;
3885
3886 EXCEPTION
3887 WHEN RELEASE_ORDER THEN
3888 Debug('In RELEASE_ORDER Exception while releasing SO',
3889 l_mod_name,
3890 1);
3891 RAISE RELEASE_ORDER;
3892 WHEN OTHERS THEN
3893 Debug('In OTHERS Exception while releasing SO',
3894 l_mod_name,
3895 1);
3896 RAISE RELEASE_ORDER;
3897 END;
3898 END IF; -- end of Release Sales Order
3899
3900 -- Ship the sales order if the flag is checked
3901 IF x_product_txn_rec.ship_sales_order_flag = 'Y'
3902 THEN
3903
3904 BEGIN
3905
3906 -- Define savepoint
3907 SAVEPOINT ship_sales_order;
3908
3909 BEGIN
3910 SELECT requested_quantity, released_status
3911 INTO l_ship_qty, l_release_status
3912 FROM wsh_delivery_details
3913 WHERE source_header_id =
3914 l_order_rec.order_header_id
3915 AND source_line_id = l_order_rec.order_line_id
3916 AND SOURCE_CODE = 'OE'; /*Fixed for bug#5685341*/
3917 EXCEPTION
3918 WHEN NO_DATA_FOUND THEN
3919 Debug('No Delivery Lines found', l_mod_name, 1);
3920 RAISE SHIP_ORDER;
3921 WHEN TOO_MANY_ROWS THEN
3922 Debug('Many Delivery lines found',
3923 l_mod_name,
3924 1);
3925 RAISE SHIP_ORDER;
3926 END;
3927
3928 l_order_rec.shipped_quantity := l_ship_qty;
3929 l_order_rec.serial_number := x_product_txn_rec.source_serial_number;
3930
3931 IF l_release_status = 'Y'
3932 THEN
3933 Debug('Call process_sales_order to ship SO',
3934 l_mod_name,
3935 1);
3936 PROCESS_SALES_ORDER(p_api_version => 1.0,
3937 p_commit => Fnd_Api.g_false,
3938 p_init_msg_list => Fnd_Api.g_true,
3939 p_validation_level => Fnd_Api.g_valid_level_full,
3940 p_action => 'SHIP',
3941 /*Fixed for bug#4433942 passing product
3942 txn record as in parameter*/
3943 p_product_txn_rec => x_product_txn_rec,
3944 p_order_rec => l_order_rec,
3945 x_return_status => x_return_status,
3946 x_msg_count => x_msg_count,
3947 x_msg_data => x_msg_data);
3948
3949 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
3950 THEN
3951 Debug('process_sales_order failed to ship sales order',
3952 l_mod_name,
3953 1);
3954 RAISE SHIP_ORDER;
3955 END IF;
3956 -- swai: bug 5931926 - 12.0.2 added 3rd party action type
3957 IF (x_product_txn_rec.ACTION_TYPE IN
3958 ('SHIP', 'WALK_IN_ISSUE', 'SHIP_THIRD_PTY'))
3959 THEN
3960 UPDATE csd_product_transactions
3961 SET prod_txn_status = 'SHIPPED',
3962 ship_sales_order_flag = 'Y'
3963 WHERE product_transaction_id =
3964 x_product_txn_rec.PRODUCT_TRANSACTION_ID;
3965 IF SQL%NOTFOUND
3966 THEN
3967 Fnd_Message.SET_NAME('CSD',
3968 'CSD_ERR_PRD_TXN_UPDATE');
3969 Fnd_Message.SET_TOKEN('PRODUCT_TRANSACTION_ID',
3970 x_product_txn_rec.PRODUCT_TRANSACTION_ID);
3971 Fnd_Msg_Pub.ADD;
3972 RAISE SHIP_ORDER;
3973 END IF;
3974 END IF;
3975
3976 UPDATE csd_repairs
3977 SET ro_txn_status = 'OM_SHIPPED'
3978 WHERE repair_line_id =
3979 x_product_txn_rec.REPAIR_LINE_ID;
3980 IF SQL%NOTFOUND
3981 THEN
3982 Fnd_Message.SET_NAME('CSD',
3983 'CSD_ERR_REPAIRS_UPDATE');
3984 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
3985 x_product_txn_rec.repair_line_id);
3986 Fnd_Msg_Pub.ADD;
3987 RAISE SHIP_ORDER;
3988 END IF;
3989
3990 END IF;
3991
3992 EXCEPTION
3993 WHEN SHIP_ORDER THEN
3994 Debug('In SHIP_ORDER Exception', l_mod_name, 1);
3995 RAISE SHIP_ORDER;
3996 WHEN OTHERS THEN
3997 Debug('In OTHERS Exception', l_mod_name, 1);
3998 RAISE SHIP_ORDER;
3999 END;
4000 END IF; -- end of ship sales order
4001
4002 END IF; --end of all process
4003
4004 -- Api body ends here
4005
4006 -- Standard check of p_commit.
4007 IF Fnd_Api.To_Boolean(p_commit)
4008 THEN
4009 COMMIT WORK;
4010 END IF;
4011
4012 -- Standard call to get message count and IF count is get message info.
4013 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4014 p_data => x_msg_data);
4015 EXCEPTION
4016 WHEN CREATE_ORDER THEN
4017 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4018 ROLLBACK TO create_sales_order;
4019 -- update the prod txn as the charge
4020 -- line was not interfaced
4021 UPDATE csd_product_transactions
4022 SET interface_to_om_flag = 'N',
4023 book_sales_order_flag = 'N',
4024 release_sales_order_flag = 'N',
4025 ship_sales_order_flag = 'N'
4026 WHERE product_transaction_id =
4027 x_product_txn_rec.PRODUCT_TRANSACTION_ID;
4028 -- Update auto_process_rma if OM fails
4029 -- swai: bug 5931926 - 12.0.2 added 3rd party action type
4030 IF (x_product_txn_rec.action_type IN ('RMA', 'WALK_IN_RECEIPT', 'RMA_THIRD_PTY')) AND
4031 (x_product_txn_rec.action_code = 'CUST_PROD')
4032 THEN
4033 UPDATE csd_repairs
4034 SET auto_process_rma = 'N'
4035 WHERE repair_line_id = x_product_txn_rec.repair_line_id;
4036 END IF;
4037 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4038 p_data => x_msg_data);
4039 WHEN BOOK_ORDER THEN
4040 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4041 ROLLBACK TO book_sales_order;
4042 -- update the prod txn as the order
4043 -- line was not booked
4044 UPDATE csd_product_transactions
4045 SET book_sales_order_flag = 'N',
4046 release_sales_order_flag = 'N',
4047 ship_sales_order_flag = 'N'
4048 WHERE product_transaction_id =
4049 x_product_txn_rec.PRODUCT_TRANSACTION_ID;
4050 -- Update auto_process_rma if OM fails
4051 -- swai: bug 5931926 - 12.0.2 added 3rd party action type
4052 IF (x_product_txn_rec.action_type IN ('RMA', 'WALK_IN_RECEIPT', 'RMA_THIRD_PTY')) AND
4053 (x_product_txn_rec.action_code = 'CUST_PROD')
4054 THEN
4055 UPDATE csd_repairs
4056 SET auto_process_rma = 'N'
4057 WHERE repair_line_id = x_product_txn_rec.repair_line_id;
4058 END IF;
4059 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4060 p_data => x_msg_data);
4061 WHEN RELEASE_ORDER THEN
4062 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4063 ROLLBACK TO release_sales_order;
4064 -- update the prod txn as the order
4065 -- line was not booked
4066 UPDATE csd_product_transactions
4067 SET release_sales_order_flag = 'N',
4068 ship_sales_order_flag = 'N'
4069 WHERE product_transaction_id =
4070 x_product_txn_rec.PRODUCT_TRANSACTION_ID;
4071 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4072 p_data => x_msg_data);
4073 WHEN SHIP_ORDER THEN
4074 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4075 ROLLBACK TO ship_sales_order;
4076 -- update the prod txn as the order
4077 -- line was not booked
4078 UPDATE csd_product_transactions
4079 SET ship_sales_order_flag = 'N'
4080 WHERE product_transaction_id =
4081 x_product_txn_rec.PRODUCT_TRANSACTION_ID;
4082 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4083 p_data => x_msg_data);
4084 WHEN Fnd_Api.G_EXC_ERROR THEN
4085 x_return_status := Fnd_Api.G_RET_STS_ERROR;
4086 ROLLBACK TO create_product_txn;
4087 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4088 p_data => x_msg_data);
4089 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
4090 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
4091 ROLLBACK TO create_product_txn;
4092 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4093 p_data => x_msg_data);
4094 WHEN OTHERS THEN
4095 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
4096 ROLLBACK TO create_product_txn;
4097 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
4098 THEN
4099 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
4100 END IF;
4101 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4102 p_data => x_msg_data);
4103 END create_product_txn;
4104
4105 /*-----------------------------------------------------------------*/
4106 /* Procedure Name: Create_ext_prod_txn */
4107 /* description : This procedure will create a product transaction */
4108 /* without creating charge line */
4109 /*-----------------------------------------------------------------*/
4110 PROCEDURE CREATE_EXT_PROD_TXN(p_api_version IN NUMBER,
4111 p_commit IN VARCHAR2,
4112 p_init_msg_list IN VARCHAR2,
4113 p_validation_level IN NUMBER,
4114 p_create_charge_lines IN VARCHAR2,
4115 x_product_txn_rec IN OUT NOCOPY PRODUCT_TXN_REC,
4116 x_return_status OUT NOCOPY VARCHAR2,
4117 x_msg_count OUT NOCOPY NUMBER,
4118 x_msg_data OUT NOCOPY VARCHAR2
4119
4120 ) IS
4121 l_api_name CONSTANT VARCHAR2(30) := 'CREATE_EXT_PRODUCT_TXN';
4122 l_api_version CONSTANT NUMBER := 1.0;
4123 l_msg_count NUMBER;
4124 l_msg_data VARCHAR2(2000);
4125 l_msg_index NUMBER;
4126 l_product_transaction_id NUMBER := NULL;
4127 l_serial_flag BOOLEAN := FALSE;
4128 l_dummy VARCHAR2(1);
4129 l_check VARCHAR2(1);
4130 l_Charges_Rec Cs_Charge_Details_Pub.Charges_Rec_type;
4131 l_estimate_Rec Cs_Charge_Details_Pub.Charges_Rec_type;
4132 l_estimate_detail_id NUMBER := NULL;
4133 x_estimate_detail_id NUMBER := NULL;
4134 l_incident_id NUMBER := NULL;
4135 l_order_rec OM_INTERFACE_REC;
4136 l_reference_number VARCHAR2(30) := '';
4137 l_contract_number VARCHAR2(120) := '';
4138 l_bus_process_id NUMBER := NULL;
4139 l_repair_type_ref VARCHAR2(3) := '';
4140 l_line_type_id NUMBER := NULL;
4141 l_txn_billing_type_id NUMBER := NULL;
4142 l_party_id NUMBER := NULL;
4143 l_account_id NUMBER := NULL;
4144 l_order_header_id NUMBER := NULL;
4145 l_release_status VARCHAR2(10) := '';
4146 l_curr_code VARCHAR2(10) := '';
4147 l_picking_rule_id NUMBER := NULL;
4148 l_ship_qty NUMBER := NULL;
4149 l_line_category_code VARCHAR2(30) := '';
4150 l_ship_from_org_id NUMBER := NULL;
4151 l_order_line_id NUMBER := NULL;
4152 l_coverage_id NUMBER := NULL;
4153 -- Bugfix 3617932, vkjain.
4154 -- Increasing the column length to 150
4155 -- l_coverage_name VARCHAR2(150) := ''; -- Commented for bugfix 3617932
4156 l_txn_group_id NUMBER := NULL;
4157 l_unit_selling_price NUMBER := NULL;
4158
4159 create_order EXCEPTION;
4160 book_order EXCEPTION;
4161 release_order EXCEPTION;
4162 ship_order EXCEPTION;
4163
4164 CURSOR get_account_details(p_incident_id IN NUMBER) IS
4165 SELECT customer_id, account_id
4166 FROM cs_incidents_all_b
4167 WHERE incident_id = p_incident_id;
4168
4169 CURSOR estimate(p_rep_line_id IN NUMBER) IS
4170 SELECT estimate_detail_id, object_version_number
4171 FROM cs_estimate_details
4172 WHERE source_id = p_rep_line_id
4173 AND source_code = 'DR'
4174 AND interface_to_oe_flag = 'N'
4175 AND order_header_id IS NULL
4176 AND order_line_id IS NULL
4177 AND line_category_code = 'ORDER';
4178
4179 BEGIN
4180 -- Standard Start of API savepoint
4181 SAVEPOINT create_product_txn;
4182
4183 -- Standard call to check for call compatibility.
4184 IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
4185 p_api_version,
4186 l_api_name,
4187 G_PKG_NAME)
4188 THEN
4189 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
4190 END IF;
4191
4192 -- Initialize message list if p_init_msg_list is set to TRUE.
4193 IF Fnd_Api.to_Boolean(p_init_msg_list)
4194 THEN
4195 Fnd_Msg_Pub.initialize;
4196 END IF;
4197
4198 -- Initialize API return status to success
4199 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4200
4201 -- Api body starts
4202
4203 -- Dump the API in the log file
4204 Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
4205 p_api_name => l_api_name);
4206
4207 -- Dump the IN parameters in the log file
4208 -- if the debug level > 5
4209 IF Fnd_Profile.value('CSD_DEBUG_LEVEL') > 5
4210 THEN
4211 Csd_Gen_Utility_Pvt.dump_prod_txn_rec(p_prod_txn_rec => x_product_txn_rec);
4212 END IF;
4213
4214 IF (g_debug > 0)
4215 THEN
4216 Csd_Gen_Utility_Pvt.ADD('********* Check reqd parameter ***************');
4217 Csd_Gen_Utility_Pvt.ADD('Repair Line ID =' ||
4218 x_product_txn_rec.repair_line_id);
4219 Csd_Gen_Utility_Pvt.ADD('Action Code =' ||
4220 x_product_txn_rec.action_code);
4221 Csd_Gen_Utility_Pvt.ADD('Action Type =' ||
4222 x_product_txn_rec.action_type);
4223 Csd_Gen_Utility_Pvt.ADD('Txn_billing_type_id =' ||
4224 x_product_txn_rec.txn_billing_type_id);
4225 END IF;
4226
4227 -- Check the required parameter(txn_billing_type_id)
4228 Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.txn_billing_type_id,
4229 p_param_name => 'TXN_BILLING_TYPE_ID',
4230 p_api_name => l_api_name);
4231
4232 -- Check the required parameter(inventory_item_id)
4233 Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.inventory_item_id,
4234 p_param_name => 'INVENTORY_ITEM_ID',
4235 p_api_name => l_api_name);
4236
4237 -- Check the required parameter(unit_of_measure_code)
4238 Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.unit_of_measure_code,
4239 p_param_name => 'UNIT_OF_MEASURE_CODE',
4240 p_api_name => l_api_name);
4241
4242 -- Check the required parameter(quantity)
4243 Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.quantity,
4244 p_param_name => 'QUANTITY',
4245 p_api_name => l_api_name);
4246
4247 -- Check the required parameter(price_list_id)
4248 Csd_Process_Util.Check_Reqd_Param(p_param_value => x_product_txn_rec.price_list_id,
4249 p_param_name => 'PRICE_LIST_ID',
4250 p_api_name => l_api_name);
4251
4252 IF (g_debug > 0)
4253 THEN
4254 Csd_Gen_Utility_Pvt.ADD('Validate repair line id');
4255 END IF;
4256
4257 -- Validate the repair line ID if it exists in csd_repairs
4258 IF NOT
4259 (Csd_Process_Util.Validate_rep_line_id(p_repair_line_id => x_product_txn_rec.repair_line_id))
4260 THEN
4261 RAISE Fnd_Api.G_EXC_ERROR;
4262 END IF;
4263
4264 IF (g_debug > 0)
4265 THEN
4266 Csd_Gen_Utility_Pvt.ADD('Validate action type');
4267 END IF;
4268
4269 -- Validate the Action Type if it exists in fnd_lookups
4270 IF NOT
4271 (Csd_Process_Util.Validate_action_type(p_action_type => x_product_txn_rec.action_type))
4272 THEN
4273 RAISE Fnd_Api.G_EXC_ERROR;
4274 END IF;
4275
4276 IF (g_debug > 0)
4277 THEN
4278 Csd_Gen_Utility_Pvt.ADD('Validate action code');
4279 END IF;
4280
4281 -- Validate the repair line ID if it exists in fnd_lookups
4282 IF NOT
4283 (Csd_Process_Util.Validate_action_code(p_action_code => x_product_txn_rec.action_code))
4284 THEN
4285 RAISE Fnd_Api.G_EXC_ERROR;
4286 END IF;
4287
4288 IF (g_debug > 0)
4289 THEN
4290 Csd_Gen_Utility_Pvt.ADD('Validate product txn qty');
4291 Csd_Gen_Utility_Pvt.ADD('x_product_txn_rec.quantity =' ||
4292 x_product_txn_rec.quantity);
4293 END IF;
4294
4295 -- Validate if the product txn quantity (customer product only)
4296 -- is not exceeding the repair order quantity
4297 -- swai: bug 5931926 - 12.0.2 do not validate quantity for third party lines
4298 -- since multiple parts can be shipped out.
4299 IF x_product_txn_rec.action_code = 'CUST_PROD' AND
4300 x_product_txn_rec.action_type not in ('RMA_THIRD_PTY', 'SHIP_THIRD_PTY')
4301 THEN
4302 Csd_Process_Util.Validate_quantity(p_action_type => x_product_txn_rec.action_type,
4303 p_repair_line_id => x_product_txn_rec.repair_line_id,
4304 p_prod_txn_qty => x_product_txn_rec.quantity,
4305 x_return_status => x_return_status);
4306
4307 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
4308 THEN
4309 IF (g_debug > 0)
4310 THEN
4311 Csd_Gen_Utility_Pvt.ADD('Validate_Quantity failed ');
4312 END IF;
4313 RAISE Fnd_Api.G_EXC_ERROR;
4314 END IF;
4315 END IF;
4316
4317 IF (g_debug > 0)
4318 THEN
4319 Csd_Gen_Utility_Pvt.ADD('Validate product txn status');
4320 Csd_Gen_Utility_Pvt.ADD('x_product_txn_rec.PROD_TXN_STATUS =' ||
4321 x_product_txn_rec.PROD_TXN_STATUS);
4322 END IF;
4323
4324 -- Validate the PROD_TXN_STATUS if it exists in fnd_lookups
4325 IF (x_product_txn_rec.PROD_TXN_STATUS IS NOT NULL) AND
4326 (x_product_txn_rec.PROD_TXN_STATUS <> Fnd_Api.G_MISS_CHAR)
4327 THEN
4328 BEGIN
4329 SELECT 'X'
4330 INTO l_check
4331 FROM fnd_lookups
4332 WHERE lookup_type = 'CSD_PRODUCT_TXN_STATUS'
4333 AND lookup_code = x_product_txn_rec.PROD_TXN_STATUS;
4334 EXCEPTION
4335 WHEN OTHERS THEN
4336 Fnd_Message.SET_NAME('CSD', 'CSD_ERR_PROD_TXN_STATUS');
4337 Fnd_Msg_Pub.ADD;
4338 RAISE Fnd_Api.G_EXC_ERROR;
4339 END;
4340 END IF;
4341
4342 -- Get service request id from csd_repairs table
4343 -- using repair order
4344 BEGIN
4345 SELECT incident_id
4346 INTO l_incident_id
4347 FROM csd_repairs
4348 WHERE repair_line_id = x_product_txn_rec.repair_line_id;
4349 EXCEPTION
4350 WHEN OTHERS THEN
4351 Fnd_Message.SET_NAME('CSD', 'CSD_API_INV_REP_LINE_ID');
4352 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
4353 x_product_txn_rec.repair_line_id);
4354 Fnd_Msg_Pub.ADD;
4355 RAISE Fnd_Api.G_EXC_ERROR;
4356 END;
4357
4358 IF (g_debug > 0)
4359 THEN
4360 Csd_Gen_Utility_Pvt.ADD('l_incident_id =' || l_incident_id);
4361 END IF;
4362
4363 -- Get the business process id
4364 -- Forward port bug fix# 2756313
4365 --l_bus_process_id := CSD_PROCESS_UTIL.GET_BUS_PROCESS(l_incident_id);
4366
4367 l_bus_process_id := Csd_Process_Util.GET_BUS_PROCESS(x_product_txn_rec.repair_line_id);
4368
4369 IF (g_debug > 0)
4370 THEN
4371 Csd_Gen_Utility_Pvt.ADD('l_bus_process_id =' ||
4372 l_bus_process_id);
4373 END IF;
4374
4375 IF l_bus_process_id < 0
4376 THEN
4377 IF NVL(x_product_txn_rec.business_process_id,
4378 Fnd_Api.G_MISS_NUM) <> Fnd_Api.G_MISS_NUM
4379 THEN
4380 l_bus_process_id := x_product_txn_rec.business_process_id;
4381 ELSE
4382 IF (g_debug > 0)
4383 THEN
4384 Csd_Gen_Utility_Pvt.ADD('Business process Id does not exist ');
4385 END IF;
4386 RAISE Fnd_Api.G_EXC_ERROR;
4387 END IF;
4388 END IF;
4389
4390 IF (g_debug > 0)
4391 THEN
4392 Csd_Gen_Utility_Pvt.ADD('Getting the Coverage and txn Group Id');
4393 Csd_Gen_Utility_Pvt.ADD('contract_line_id =' ||
4394 x_product_txn_rec.contract_id);
4395 END IF;
4396
4397 IF l_incident_id IS NOT NULL
4398 THEN
4399 OPEN get_account_details(l_incident_id);
4400 FETCH get_account_details
4401 INTO l_party_id, l_account_id;
4402 IF (get_account_details%NOTFOUND OR l_party_id IS NULL)
4403 THEN
4404 Fnd_Message.SET_NAME('CSD', 'CSD_API_PARTY_MISSING');
4405 Fnd_Message.SET_TOKEN('INCIDENT_ID', l_incident_id);
4406 Fnd_Msg_Pub.ADD;
4407 RAISE Fnd_Api.G_EXC_ERROR;
4408 END IF;
4409 IF get_account_details%ISOPEN
4410 THEN
4411 CLOSE get_account_details;
4412 END IF;
4413 END IF;
4414
4415 IF (g_debug > 0)
4416 THEN
4417 Csd_Gen_Utility_Pvt.ADD('l_party_id =' ||
4418 l_party_id);
4419 Csd_Gen_Utility_Pvt.ADD('l_account_id =' ||
4420 l_account_id);
4421 Csd_Gen_Utility_Pvt.ADD('x_product_txn_rec.txn_billing_type_id =' ||
4422 x_product_txn_rec.txn_billing_type_id);
4423 Csd_Gen_Utility_Pvt.ADD('x_product_txn_rec.organization_id =' ||
4424 x_product_txn_rec.organization_id);
4425 END IF;
4426
4427 -- Derive the line type and line category code
4428 -- from the transaction billing type
4429 Csd_Process_Util.GET_LINE_TYPE(p_txn_billing_type_id => x_product_txn_rec.txn_billing_type_id,
4430 p_org_id => x_product_txn_rec.organization_id,
4431 x_line_type_id => l_line_type_id,
4432 x_line_category_code => l_line_category_code,
4433 x_return_status => x_return_status);
4434
4435 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
4436 THEN
4437 RAISE Fnd_Api.G_EXC_ERROR;
4438 END IF;
4439
4440 IF (g_debug > 0)
4441 THEN
4442 Csd_Gen_Utility_Pvt.ADD('l_line_type_id =' ||
4443 l_line_type_id);
4444 Csd_Gen_Utility_Pvt.ADD('l_line_category_code =' ||
4445 l_line_category_code);
4446 Csd_Gen_Utility_Pvt.ADD('x_product_txn_rec.price_list_id =' ||
4447 x_product_txn_rec.price_list_id);
4448 END IF;
4449
4450 -- If line_type_id Or line_category_code is null
4451 -- then raise error
4452 IF (l_line_type_id IS NULL OR l_line_category_code IS NULL)
4453 THEN
4454 Fnd_Message.SET_NAME('CSD', 'CSD_API_LINE_TYPE_MISSING');
4455 Fnd_Message.SET_TOKEN('TXN_BILLING_TYPE_ID',
4456 x_product_txn_rec.txn_billing_type_id);
4457 Fnd_Msg_Pub.ADD;
4458 RAISE Fnd_Api.G_EXC_ERROR;
4459 END IF;
4460
4461 -- Get the currency code from the price list if it is null or g_miss
4462 IF NVL(x_product_txn_rec.price_list_id, Fnd_Api.G_MISS_NUM) <>
4463 Fnd_Api.G_MISS_NUM
4464 THEN
4465 BEGIN
4466 SELECT currency_code
4467 INTO l_curr_code
4468 FROM oe_price_lists
4469 WHERE price_list_id = x_product_txn_rec.price_list_id;
4470 EXCEPTION
4471 WHEN NO_DATA_FOUND THEN
4472 Fnd_Message.SET_NAME('CSD',
4473 'CSD_API_INV_PRICE_LIST_ID');
4474 Fnd_Message.SET_TOKEN('PRICE_LIST_ID',
4475 x_product_txn_rec.price_list_id);
4476 Fnd_Msg_Pub.ADD;
4477 RAISE Fnd_Api.G_EXC_ERROR;
4478 WHEN TOO_MANY_ROWS THEN
4479 IF (g_debug > 0)
4480 THEN
4481 Csd_Gen_Utility_Pvt.ADD('Too many currency_codes');
4482 END IF;
4483 END;
4484 END IF;
4485
4486 IF (g_debug > 0)
4487 THEN
4488 Csd_Gen_Utility_Pvt.ADD('l_curr_code =' ||
4489 l_curr_code);
4490 END IF;
4491
4492 -- If l_curr_code is null then raise error
4493 IF l_curr_code IS NULL
4494 THEN
4495 Fnd_Message.SET_NAME('CSD', 'CSD_API_INV_CURR_CODE');
4496 Fnd_Message.SET_TOKEN('PRICE_LIST_ID',
4497 x_product_txn_rec.price_list_id);
4498 Fnd_Msg_Pub.ADD;
4499 RAISE Fnd_Api.G_EXC_ERROR;
4500 END IF;
4501
4502 l_serial_flag := Csd_Process_Util.Is_item_serialized(x_product_txn_rec.inventory_item_id);
4503
4504
4505 -- swai: bug 5931926 - 12.0.2 3rd party logistics
4506 -- Instead of adding 3rd party action types to if-then statement,
4507 -- we are commenting the code out altogether. Currently, the
4508 -- if conditions do not allow any product transaction lines
4509 -- through except walk-in-receipt, which is no longer supported.
4510 -- We should allow RMA line creation without Serial number for
4511 -- all action types.
4512 /*****
4513 -- Serial Number required if the item is serialized
4514 -- changing it from serial_number to source_serial_number 11.5.10
4515 IF l_serial_flag AND x_product_txn_rec.source_serial_number IS NULL AND
4516 x_product_txn_rec.action_type NOT IN ('SHIP') AND
4517 (x_product_txn_rec.action_code <> 'LOANER' AND
4518 x_product_txn_rec.action_type <>'RMA')
4519 THEN
4520 Fnd_Message.SET_NAME('CSD', 'CSD_API_SERIAL_NUM_MISSING');
4521 Fnd_Message.SET_TOKEN('INVENTORY_ITEM_ID',
4522 x_product_txn_rec.inventory_item_id);
4523 Fnd_Msg_Pub.ADD;
4524 IF (g_debug > 0)
4525 THEN
4526 Csd_Gen_Utility_Pvt.ADD('Serial Number missing for inventory_item_id =' ||
4527 x_product_txn_rec.inventory_item_id);
4528 END IF;
4529 RAISE Fnd_Api.G_EXC_ERROR;
4530 END IF;
4531 *****/
4532
4533 -- assigning values for the charge record
4534 x_product_txn_rec.incident_id := l_incident_id;
4535 x_product_txn_rec.business_process_id := l_bus_process_id;
4536 x_product_txn_rec.line_type_id := l_line_type_id;
4537 x_product_txn_rec.currency_code := l_curr_code;
4538 x_product_txn_rec.line_category_code := l_line_category_code;
4539 x_estimate_detail_id := x_product_txn_rec.estimate_detail_id;
4540
4541 Csd_Gen_Utility_Pvt.ADD('Call csd_product_transactions_pkg.insert_row to insert prod txns');
4542
4543 Csd_Product_Transactions_Pkg.INSERT_ROW(px_PRODUCT_TRANSACTION_ID => x_product_txn_rec.PRODUCT_TRANSACTION_ID,
4544 p_REPAIR_LINE_ID => x_product_txn_rec.REPAIR_LINE_ID,
4545 p_ESTIMATE_DETAIL_ID => x_estimate_detail_id,
4546 p_ACTION_TYPE => x_product_txn_rec.ACTION_TYPE,
4547 p_ACTION_CODE => x_product_txn_rec.ACTION_CODE,
4548 p_LOT_NUMBER => x_product_txn_rec.LOT_NUMBER,
4549 p_SUB_INVENTORY => x_product_txn_rec.SUB_INVENTORY,
4550 p_INTERFACE_TO_OM_FLAG => x_product_txn_rec.INTERFACE_TO_OM_FLAG,
4551 p_BOOK_SALES_ORDER_FLAG => x_product_txn_rec.BOOK_SALES_ORDER_FLAG,
4552 p_RELEASE_SALES_ORDER_FLAG => x_product_txn_rec.RELEASE_SALES_ORDER_FLAG,
4553 p_SHIP_SALES_ORDER_FLAG => x_product_txn_rec.SHIP_SALES_ORDER_FLAG,
4554 p_PROD_TXN_STATUS => 'SUBMITTED',
4555 p_PROD_TXN_CODE => x_product_txn_rec.PROD_TXN_CODE,
4556 p_LAST_UPDATE_DATE => SYSDATE,
4557 p_CREATION_DATE => SYSDATE,
4558 p_LAST_UPDATED_BY => Fnd_Global.USER_ID,
4559 p_CREATED_BY => Fnd_Global.USER_ID,
4560 p_LAST_UPDATE_LOGIN => Fnd_Global.USER_ID,
4561 p_ATTRIBUTE1 => x_product_txn_rec.ATTRIBUTE1,
4562 p_ATTRIBUTE2 => x_product_txn_rec.ATTRIBUTE2,
4563 p_ATTRIBUTE3 => x_product_txn_rec.ATTRIBUTE3,
4564 p_ATTRIBUTE4 => x_product_txn_rec.ATTRIBUTE4,
4565 p_ATTRIBUTE5 => x_product_txn_rec.ATTRIBUTE5,
4566 p_ATTRIBUTE6 => x_product_txn_rec.ATTRIBUTE6,
4567 p_ATTRIBUTE7 => x_product_txn_rec.ATTRIBUTE7,
4568 p_ATTRIBUTE8 => x_product_txn_rec.ATTRIBUTE8,
4569 p_ATTRIBUTE9 => x_product_txn_rec.ATTRIBUTE9,
4570 p_ATTRIBUTE10 => x_product_txn_rec.ATTRIBUTE10,
4571 p_ATTRIBUTE11 => x_product_txn_rec.ATTRIBUTE11,
4572 p_ATTRIBUTE12 => x_product_txn_rec.ATTRIBUTE12,
4573 p_ATTRIBUTE13 => x_product_txn_rec.ATTRIBUTE13,
4574 p_ATTRIBUTE14 => x_product_txn_rec.ATTRIBUTE14,
4575 p_ATTRIBUTE15 => x_product_txn_rec.ATTRIBUTE15,
4576 p_CONTEXT => x_product_txn_rec.CONTEXT,
4577 p_OBJECT_VERSION_NUMBER => 1,
4578 P_SOURCE_SERIAL_NUMBER => x_product_txn_rec.source_serial_number,
4579 P_SOURCE_INSTANCE_ID => x_product_txn_rec.source_instance_Id,
4580 P_NON_SOURCE_SERIAL_NUMBER => x_product_txn_rec.non_source_serial_number,
4581 P_NON_SOURCE_INSTANCE_ID => x_product_txn_rec.non_source_instance_id,
4582 P_REQ_HEADER_ID => x_product_txn_rec.Req_Header_Id,
4583 P_REQ_LINE_ID => x_product_txn_rec.Req_Line_Id,
4584 P_ORDER_HEADER_ID => x_Product_Txn_Rec.Order_Header_Id,
4585 P_ORDER_LINE_ID => x_Product_Txn_Rec.Order_Line_Id,
4586 P_PRD_TXN_QTY_RECEIVED => x_product_txn_rec.Prd_Txn_Qty_Received,
4587 P_PRD_TXN_QTY_SHIPPED => x_product_txn_rec.Prd_Txn_Qty_Shipped,
4588 P_SUB_INVENTORY_RCVD => x_product_txn_rec.Sub_Inventory_Rcvd,
4589 P_LOT_NUMBER_RCVD => x_product_txn_rec.Lot_Number_Rcvd,
4590 P_LOCATOR_ID => x_product_txn_rec.Locator_Id,
4591 p_picking_rule_id => x_product_txn_rec.picking_rule_id, --R12 development changes
4592 P_PROJECT_ID => x_product_txn_rec.project_id,
4593 P_TASK_ID => x_product_txn_rec.task_id,
4594 P_UNIT_NUMBER => x_product_txn_rec.unit_number,
4595 P_INTERNAL_PO_HEADER_ID => x_product_txn_rec.internal_po_header_id); -- swai: bug 6148019
4596
4597
4598 Csd_Gen_Utility_Pvt.ADD('PRODUCT_TRANSACTION_ID =' ||
4599 x_product_txn_rec.PRODUCT_TRANSACTION_ID);
4600 Csd_Gen_Utility_Pvt.ADD('REPAIR_ORDER_ID =' ||
4601 x_product_txn_rec.repair_line_id);
4602
4603 UPDATE csd_repairs
4604 SET ro_txn_status = 'OM_SUBMITTED'
4605 WHERE repair_line_id = x_product_txn_rec.REPAIR_LINE_ID;
4606 IF SQL%NOTFOUND
4607 THEN
4608 Fnd_Message.SET_NAME('CSD', 'CSD_ERR_REPAIRS_UPDATE');
4609 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
4610 x_product_txn_rec.repair_line_id);
4611 Fnd_Msg_Pub.ADD;
4612 RAISE Fnd_Api.G_EXC_ERROR;
4613 END IF;
4614
4615 -- Api body ends here
4616
4617 -- Standard check of p_commit.
4618 IF Fnd_Api.To_Boolean(p_commit)
4619 THEN
4620 COMMIT WORK;
4621 END IF;
4622
4623 -- Standard call to get message count and IF count is get message info.
4624 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4625 p_data => x_msg_data);
4626 EXCEPTION
4627 WHEN Fnd_Api.G_EXC_ERROR THEN
4628 x_return_status := Fnd_Api.G_RET_STS_ERROR;
4629 ROLLBACK TO create_product_txn;
4630 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4631 p_data => x_msg_data);
4632 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
4633 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
4634 ROLLBACK TO create_product_txn;
4635 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4636 p_data => x_msg_data);
4637 WHEN OTHERS THEN
4638 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
4639 ROLLBACK TO create_product_txn;
4640 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
4641 THEN
4642 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
4643 END IF;
4644 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4645 p_data => x_msg_data);
4646 END create_ext_prod_txn;
4647
4648 /*----------------------------------------------------------------*/
4649 /* procedure name: update_product_txn */
4650 /* description : procedure to update product txn lines.It is */
4651 /* called from ON-UPDATE trigger in the repair */
4652 /* order form */
4653 /*----------------------------------------------------------------*/
4654
4655 PROCEDURE update_product_txn(p_api_version IN NUMBER,
4656 p_commit IN VARCHAR2 := Fnd_Api.g_false,
4657 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_false,
4658 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
4659 x_product_txn_rec IN OUT NOCOPY PRODUCT_TXN_REC,
4660 x_return_status OUT NOCOPY VARCHAR2,
4661 x_msg_count OUT NOCOPY NUMBER,
4662 x_msg_data OUT NOCOPY VARCHAR2) IS
4663
4664 l_api_name CONSTANT VARCHAR2(30) := 'UPDATE_PRODUCT_TXN';
4665 l_api_version CONSTANT NUMBER := 1.0;
4666 l_msg_count NUMBER;
4667 l_msg_data VARCHAR2(2000);
4668 l_msg_index NUMBER;
4669 l_return_status VARCHAR2(1);
4670 l_estimate_Rec Cs_Charge_Details_Pub.charges_rec_type;
4671 l_prodtxn_db_attr Csd_Logistics_Util.PRODTXN_DB_ATTR_REC;
4672 l_order_Rec Csd_Process_Pvt.om_interface_rec;
4673 l_est_detail_id NUMBER;
4674 l_add_to_order_id NUMBER;
4675 l_add_to_order_flag VARCHAR2(1);
4676 l_transaction_type_id NUMBER;
4677 l_repair_line_id NUMBER;
4678 l_order_header_id NUMBER; --bug 7355526
4679 l_ship_from_org_id NUMBER; --bug 7355526
4680
4681 create_order EXCEPTION;
4682 book_order EXCEPTION;
4683 release_order EXCEPTION;
4684 ship_order EXCEPTION;
4685
4686
4687 CURSOR estimate(p_rep_line_id IN NUMBER) IS
4688 SELECT estimate_detail_id, object_version_number
4689 FROM cs_estimate_details
4690 WHERE source_id = p_rep_line_id
4691 AND source_code = 'DR'
4692 AND interface_to_oe_flag = 'N'
4693 AND order_header_id IS NULL
4694 AND order_line_id IS NULL;
4695
4696
4697 -- Variables used in FND Log
4698 l_error_level NUMBER := Fnd_Log.LEVEL_ERROR;
4699 l_excep_level NUMBER := Fnd_Log.LEVEL_EXCEPTION;
4700 l_statement_level NUMBER := Fnd_Log.LEVEL_STATEMENT;
4701
4702 l_mod_name VARCHAR2(2000) := 'csd.plsql.csd_process_pvt.update_product_txn';
4703
4704 BEGIN
4705
4706
4707 SAVEPOINT UPDATE_PRODUCT_TXN_PVT;
4708
4709 -- Initialize API return status to success
4710 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4711
4712 -- Fix for bug#6210765
4713 -- Initialize message list if p_init_msg_list is set to TRUE.
4714 IF Fnd_Api.to_Boolean(p_init_msg_list)
4715 THEN
4716 Fnd_Msg_Pub.initialize;
4717 END IF;
4718
4719
4720 l_prodtxn_db_attr := Csd_Logistics_Util.get_prodtxn_db_attr(x_product_txn_rec.product_transaction_id);
4721
4722 -----------------------------------------------------------------------------
4723 /*********************************************************************
4724 /* Code here got moved to CSD_LOGISTICS_UTIL.upd_prodtxn_n_chrgline
4725 **********************************************************************/
4726 -----------------------------------------------------------------------------
4727 Csd_Logistics_Util.upd_prodtxn_n_chrgline(x_product_txn_rec ,
4728 l_prodtxn_db_attr,
4729 l_est_detail_id,
4730 l_repair_line_id,
4731 l_add_to_order_flag,
4732 l_add_to_order_id,
4733 l_transaction_type_id);
4734
4735 x_product_txn_Rec.estimate_detail_id := l_est_detail_id;
4736 x_product_txn_Rec.repair_line_id := l_repair_line_id;
4737 x_product_txn_Rec.add_to_order_flag := l_add_to_order_flag;
4738 x_product_txn_Rec.order_header_id := l_add_to_order_id;
4739 x_product_txn_rec.transaction_type_id := l_transaction_type_id;
4740
4741 Debug('process_txn_flag =' ||
4742 x_product_txn_rec.process_txn_flag,
4743 l_mod_name,
4744 l_statement_level);
4745 Debug('interface_to_om_flag =' ||
4746 x_product_txn_rec.interface_to_om_flag,
4747 l_mod_name,
4748 l_statement_level);
4749 Debug('book_sales_order_flag =' ||
4750 x_product_txn_rec.book_sales_order_flag,
4751 l_mod_name,
4752 l_statement_level);
4753 Debug('release_sales_order_flag =' ||
4754 x_product_txn_rec.release_sales_order_flag,
4755 l_mod_name,
4756 l_statement_level);
4757 Debug('ship_sales_order_flag =' ||
4758 x_product_txn_rec.ship_sales_order_flag,
4759 l_mod_name,
4760 l_statement_level);
4761
4762
4763 IF x_product_txn_rec.process_txn_flag = 'Y'
4764 THEN
4765
4766 -- Define savepoint
4767 SAVEPOINT create_sales_order;
4768
4769 /*******************************************************************
4770 Code here has been moved to CSD_LOGISTICS_UTIL.interface_prodtxn
4771 ********************************************************************/
4772
4773 l_order_Rec := Csd_Logistics_Util.get_order_rec(x_product_txn_rec.repair_line_id);
4774
4775 --bug#6071005
4776 if (x_product_txn_rec.order_line_id is not null) THEN
4777 l_order_Rec.order_line_id := x_product_txn_rec.order_line_id;
4778 End If;
4779
4780 -- swai: bug 5931926 - 12.0.2 3rd party logistics. If the bill to party
4781 -- and account have been specified, then this is a 3rd party logistics line,
4782 -- and we need to override the SR party and account from get_order_rec with
4783 -- the thrid party info
4784 /*IF (nvl(x_product_txn_rec.bill_to_account_id, FND_API.GMISS_NUM) <> FND_API.GMISS_NUM) AND
4785 (nvl(x_product_txn_rec.bill_to_party_id, FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM) THEN */
4786 -- nnadig: bug 9187830 - ensure bill-to info is only set for 3rd party lines
4787 IF (x_product_txn_rec.action_type in ('RMA_THIRD_PTY', 'SHIP_THIRD_PTY')) and
4788 (x_product_txn_rec.bill_to_party_id is not null) and
4789 (x_product_txn_rec.bill_to_account_id is not null) THEN
4790 l_order_Rec.party_id := x_product_txn_rec.bill_to_party_id;
4791 l_order_Rec.account_id := x_product_txn_rec.bill_to_account_id;
4792 END IF;
4793
4794 Csd_Logistics_Util.interface_prodtxn( x_return_status => l_return_status,
4795 p_product_txn_rec => x_product_txn_rec,
4796 p_prodtxn_db_attr => l_prodtxn_db_attr,
4797 px_order_rec => l_order_rec);
4798
4799 IF NOT (l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
4800 RAISE Create_ORDER;
4801 END IF;
4802 IF l_prodtxn_db_attr.curr_book_order_flag <>
4803 x_product_txn_rec.book_sales_order_flag AND
4804 x_product_txn_rec.book_sales_order_flag = 'Y'
4805 THEN
4806 -- Define savepoint
4807 SAVEPOINT book_sales_order;
4808 /***************************************************
4809 Code here has been moved to the api book_prodtxn
4810 ****************************************************/
4811 Csd_Logistics_Util.book_prodtxn( x_return_status => l_return_status,
4812 p_product_txn_rec => x_product_txn_rec,
4813 p_prodtxn_db_attr => l_prodtxn_db_attr,
4814 px_order_rec => l_order_rec);
4815 IF NOT (l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
4816 RAISE BOOK_ORDER;
4817 END IF;
4818
4819
4820 END IF; -- end of book order
4821
4822 --IF l_prodtxn_db_attr.curr_release_order_flag <> --bug#13503428
4823 IF nvl(l_prodtxn_db_attr.curr_release_order_flag,'N') <>
4824 x_product_txn_rec.release_sales_order_flag AND
4825 x_product_txn_rec.release_sales_order_flag = 'Y'
4826 THEN
4827 -- Define savepoint
4828 SAVEPOINT release_sales_order;
4829
4830
4831 -- begin bug fix #7355526, nnadig
4832 -- FP for bug fix#9198116: validate the subinventory information
4833 Begin
4834 Select ship_from_org_id, header_id
4835 into l_ship_from_org_id, l_order_header_id
4836 from oe_order_lines_all oel,
4837 cs_estimate_details ced
4838 where oel.line_id = ced.order_line_id
4839 and ced.estimate_detail_id = x_product_txn_rec.estimate_detail_id;
4840 Exception
4841 When no_data_found then
4842 Debug('Order Line not found ',l_mod_name,1);
4843 RAISE RELEASE_ORDER;
4844 End;
4845
4846 -- If wrong sub-inventory is entered, throw explanatory error message
4847 if x_product_txn_rec.sub_inventory is not null then
4848 if NOT csd_process_util.validate_subinventory_ship(
4849 --p_org_id => cs_std.get_item_valdn_orgzn_id, -- FP for bug fix 9198116
4850 p_org_id => l_ship_from_org_id,
4851 p_sub_inv => x_product_txn_rec.sub_inventory,
4852 p_inventory_item_id => x_product_txn_rec.inventory_item_id,
4853 p_serial_number => x_product_txn_rec.source_serial_number ) then
4854 fnd_message.set_name('CSD','CSD_NEG_INV_IN_SHIP');
4855 fnd_message.set_token('SUBINV',x_product_txn_rec.sub_inventory);
4856 fnd_msg_pub.add;
4857 RAISE RELEASE_ORDER;
4858 end if;
4859 end if;
4860
4861 -- validate if the line/header is on hold. If so, throw explanatory error message
4862 if CSD_PROCESS_UTIL.validate_order_for_holds
4863 ( p_action_type => 'SHIP',
4864 p_order_header_id => l_order_header_id,
4865 p_order_line_id => x_product_txn_rec.order_line_id ) then
4866 fnd_message.set_name('CSD','CSD_OM_ORDER_ON_HOLD');
4867 fnd_message.set_token('ACTION','Shipping');
4868 fnd_message.set_token('ORDER_NUM',x_product_txn_rec.order_number);
4869 fnd_msg_pub.add;
4870 RAISE RELEASE_ORDER;
4871 end if;
4872 -- end bug fix #7355526, nnadig
4873 /*******************************************************************
4874 Code here has been moved to CSD_LOGISTICS_UTIL.pickrelease_prodtxn
4875 ********************************************************************/
4876 Csd_Logistics_Util.pickrelease_prodtxn(x_return_status => l_return_status,
4877 p_product_txn_rec => x_product_txn_rec,
4878 p_prodtxn_db_attr => l_prodtxn_db_attr,
4879 px_order_rec => l_order_rec);
4880 IF NOT (l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
4881 RAISE RELEASE_ORDER;
4882 END IF;
4883 END IF; --end of pick-release sales order
4884
4885 --IF l_prodtxn_db_attr.curr_ship_order_flag <> --bug#13503428
4886 IF nvl(l_prodtxn_db_attr.curr_ship_order_flag,'N') <>
4887 x_product_txn_rec.ship_sales_order_flag AND
4888 x_product_txn_rec.ship_sales_order_flag = 'Y'
4889 THEN
4890 -- Define savepoint
4891 SAVEPOINT ship_sales_order;
4892 /*******************************************************************
4893 Code here has been moved to CSD_LOGISTICS_UTIL.ship_prodtxn
4894 ********************************************************************/
4895 Csd_Logistics_Util.ship_prodtxn( x_return_status => l_return_status,
4896 p_product_txn_rec => x_product_txn_rec,
4897 p_prodtxn_db_attr => l_prodtxn_db_attr,
4898 px_order_rec => l_order_rec);
4899
4900 IF NOT (l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
4901 RAISE SHIP_ORDER;
4902 END IF;
4903
4904 END IF; -- end of ship sales order
4905
4906 END IF; --end of process txn
4907
4908 -- Api body ends here
4909
4910 -- Standard check of p_commit.
4911 IF Fnd_Api.To_Boolean(p_commit)
4912 THEN
4913 COMMIT WORK;
4914 END IF;
4915
4916 -- Standard call to get message count and IF count is get message info.
4917 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4918 p_data => x_msg_data);
4919 EXCEPTION
4920 WHEN CREATE_ORDER THEN
4921 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4922
4923 /*FP Fixed for bug#4526773
4924 When error occurred then complete rollback should be
4925 done so that sanity of charge line and product line
4926 remain intact.
4927 */
4928 --ROLLBACK TO create_sales_order;
4929
4930 ROLLBACK TO UPDATE_PRODUCT_TXN_PVT;
4931
4932 -- update the prod txn as the charge
4933 -- line was not interfaced
4934 UPDATE csd_product_transactions
4935 SET interface_to_om_flag = 'N',
4936 book_sales_order_flag = 'N',
4937 release_sales_order_flag = 'N',
4938 ship_sales_order_flag = 'N'
4939 WHERE product_transaction_id =
4940 x_product_txn_rec.PRODUCT_TRANSACTION_ID;
4941 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4942 p_data => x_msg_data);
4943 WHEN BOOK_ORDER THEN
4944 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4945 ROLLBACK TO book_sales_order;
4946 -- update the prod txn as the order
4947 -- line was not booked
4948 UPDATE csd_product_transactions
4949 SET book_sales_order_flag = 'N',
4950 release_sales_order_flag = 'N',
4951 ship_sales_order_flag = 'N'
4952 WHERE product_transaction_id =
4953 x_product_txn_rec.PRODUCT_TRANSACTION_ID;
4954 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4955 p_data => x_msg_data);
4956 WHEN RELEASE_ORDER THEN
4957 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4958 ROLLBACK TO release_sales_order;
4959 -- update the prod txn as the order
4960 -- line was not booked
4961 UPDATE csd_product_transactions
4962 SET release_sales_order_flag = 'N',
4963 ship_sales_order_flag = 'N'
4964 WHERE product_transaction_id =
4965 x_product_txn_rec.PRODUCT_TRANSACTION_ID;
4966 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4967 p_data => x_msg_data);
4968 WHEN SHIP_ORDER THEN
4969 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4970 ROLLBACK TO ship_sales_order;
4971 -- update the prod txn as the order
4972 -- line was not booked
4973 UPDATE csd_product_transactions
4974 SET ship_sales_order_flag = 'N'
4975 WHERE product_transaction_id =
4976 x_product_txn_rec.PRODUCT_TRANSACTION_ID;
4977 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4978 p_data => x_msg_data);
4979 WHEN Fnd_Api.G_EXC_ERROR THEN
4980 x_return_status := Fnd_Api.G_RET_STS_ERROR;
4981 ROLLBACK TO UPDATE_PRODUCT_TXN_PVT;
4982 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4983 p_data => x_msg_data);
4984 Debug('in exc_error, x_msg_data,count[' || x_msg_data|| ','||to_char(x_msg_count)||']',
4985 l_mod_name,
4986 l_statement_level);
4987 IF x_msg_count > 1 THEN
4988 FOR i IN 1..x_msg_count LOOP
4989 l_msg_data := apps.FND_MSG_PUB.Get(i,FND_API.G_TRUE) ;
4990 Debug('in exc_error, l_msg_data[' || l_msg_data||']',
4991 l_mod_name,
4992 l_statement_level);
4993 END LOOP ;
4994 END IF ;
4995 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
4996 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
4997 ROLLBACK TO UPDATE_PRODUCT_TXN_PVT;
4998 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4999 p_data => x_msg_data);
5000 Debug('in unexp_Error, x_msg_data[' || x_msg_data||']',
5001 l_mod_name,
5002 l_statement_level);
5003 IF x_msg_count > 1 THEN
5004 FOR i IN 1..x_msg_count LOOP
5005 l_msg_data := apps.FND_MSG_PUB.Get(i,apps.FND_API.G_FALSE) ;
5006 Debug('in exc_error, l_msg_data[' || l_msg_data||']',
5007 l_mod_name,
5008 l_statement_level);
5009 END LOOP ;
5010 END IF ;
5011 WHEN OTHERS THEN
5012 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5013 ROLLBACK TO UPDATE_PRODUCT_TXN_PVT;
5014 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
5015 THEN
5016 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
5017 END IF;
5018 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5019 p_data => x_msg_data);
5020 Debug('in others, x_msg_data[' || x_msg_data||']',
5021 l_mod_name,
5022 l_statement_level);
5023 IF x_msg_count > 1 THEN
5024 FOR i IN 1..x_msg_count LOOP
5025 l_msg_data := apps.FND_MSG_PUB.Get(i,apps.FND_API.G_FALSE) ;
5026 Debug('in exc_error, l_msg_data[' || l_msg_data||']',
5027 l_mod_name,
5028 l_statement_level);
5029 END LOOP ;
5030 END IF ;
5031 END update_product_txn;
5032
5033 /*--------------------------------------------------*/
5034 /* procedure name: delete_product_txn */
5035 /* description : procedure used to delete */
5036 /* product transaction lines */
5037 /* */
5038 /*--------------------------------------------------*/
5039
5040 PROCEDURE delete_product_txn(p_api_version IN NUMBER,
5041 p_commit IN VARCHAR2 := Fnd_Api.g_false,
5042 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_false,
5043 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
5044 p_product_txn_id IN NUMBER,
5045 x_return_status OUT NOCOPY VARCHAR2,
5046 x_msg_count OUT NOCOPY NUMBER,
5047 x_msg_data OUT NOCOPY VARCHAR2) IS
5048 l_api_name CONSTANT VARCHAR2(30) := 'DELETE_PRODUCT_TXN';
5049 l_api_version CONSTANT NUMBER := 1.0;
5050 l_msg_count NUMBER;
5051 l_msg_data VARCHAR2(2000);
5052 l_msg_index NUMBER;
5053 l_Charges_Rec Cs_Charge_Details_Pub.charges_rec_type;
5054 x_estimate_detail_id NUMBER;
5055 l_est_detail_id NUMBER;
5056 l_delete_allow VARCHAR2(1);
5057
5058 BEGIN
5059 -- Standard Start of API savepoint
5060 SAVEPOINT delete_product_txn;
5061
5062 -- Standard call to check for call compatibility.
5063 IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
5064 p_api_version,
5065 l_api_name,
5066 G_PKG_NAME)
5067 THEN
5068 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
5069 END IF;
5070
5071 -- Initialize message list if p_init_msg_list is set to TRUE.
5072 IF Fnd_Api.to_Boolean(p_init_msg_list)
5073 THEN
5074 Fnd_Msg_Pub.initialize;
5075 END IF;
5076
5077 -- Initialize API return status to success
5078 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
5079
5080 -- Api body starts
5081 IF (g_debug > 0)
5082 THEN
5083 Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
5084 p_api_name => l_api_name);
5085 END IF;
5086 IF (g_debug > 0)
5087 THEN
5088 Csd_Gen_Utility_Pvt.ADD('Check reqd parameter :prod txn Id ');
5089 Csd_Gen_Utility_Pvt.ADD('product txn Id = ' ||
5090 p_product_txn_id);
5091 END IF;
5092
5093 -- Check the required parameter
5094 Csd_Process_Util.Check_Reqd_Param(p_param_value => p_product_txn_id,
5095 p_param_name => 'PRODUCT_TRANSACTION_ID',
5096 p_api_name => l_api_name);
5097
5098 IF (g_debug > 0)
5099 THEN
5100 Csd_Gen_Utility_Pvt.ADD('Validate product txn id');
5101 END IF;
5102
5103 -- Validate the repair line ID
5104 IF NOT
5105 (Csd_Process_Util.Validate_prod_txn_id(p_prod_txn_id => p_product_txn_id))
5106 THEN
5107 RAISE Fnd_Api.G_EXC_ERROR;
5108 END IF;
5109
5110 -- The Product txn line is allowed to delete
5111 -- only if it is not interfaced
5112 BEGIN
5113 SELECT a.estimate_detail_id
5114 INTO l_est_detail_id
5115 FROM csd_product_transactions a, cs_estimate_details b
5116 WHERE a.estimate_detail_id = b.estimate_detail_id
5117 AND a.product_transaction_id = p_product_txn_id
5118 AND b.order_header_id IS NULL;
5119
5120 l_delete_allow := 'Y';
5121 EXCEPTION
5122 WHEN NO_DATA_FOUND THEN
5123 l_delete_allow := 'N';
5124 Fnd_Message.SET_NAME('CSD', 'CSD_API_DELETE_NOT_ALLOWED');
5125 --FND_MESSAGE.SET_TOKEN('PRODUCT_TXN_ID',p_product_txn_id);
5126 Fnd_Msg_Pub.ADD;
5127 IF (g_debug > 0)
5128 THEN
5129 Csd_Gen_Utility_Pvt.ADD('Product txn is interfaced,so it cannot be deleted');
5130 END IF;
5131 RAISE Fnd_Api.G_EXC_ERROR;
5132 WHEN TOO_MANY_ROWS THEN
5133 IF (g_debug > 0)
5134 THEN
5135 Csd_Gen_Utility_Pvt.ADD('Too many from Product txn line is allowed to delete');
5136 END IF;
5137 END;
5138
5139 IF (g_debug > 0)
5140 THEN
5141 Csd_Gen_Utility_Pvt.ADD('l_delete_allow =' ||
5142 l_delete_allow);
5143 Csd_Gen_Utility_Pvt.ADD('Estimate Detail Id =' ||
5144 l_est_detail_id);
5145 END IF;
5146
5147 IF l_delete_allow = 'Y'
5148 THEN
5149 l_Charges_Rec.estimate_detail_id := l_est_detail_id;
5150 IF (g_debug > 0)
5151 THEN
5152 Csd_Gen_Utility_Pvt.ADD('Call process_charge_lines to delete');
5153 END IF;
5154
5155 PROCESS_CHARGE_LINES(p_api_version => 1.0,
5156 p_commit => Fnd_Api.g_false,
5157 p_init_msg_list => Fnd_Api.g_true,
5158 p_validation_level => Fnd_Api.g_valid_level_full,
5159 p_action => 'DELETE',
5160 p_Charges_Rec => l_Charges_Rec,
5161 x_estimate_detail_id => x_estimate_detail_id,
5162 x_return_status => x_return_status,
5163 x_msg_count => x_msg_count,
5164 x_msg_data => x_msg_data);
5165
5166 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
5167 THEN
5168 RAISE Fnd_Api.G_EXC_ERROR;
5169 END IF;
5170
5171 IF (g_debug > 0)
5172 THEN
5173 Csd_Gen_Utility_Pvt.ADD('Call csd_product_transactions_pkg.Delete_Row');
5174 END IF;
5175
5176 Csd_Product_Transactions_Pkg.Delete_Row(p_PRODUCT_TRANSACTION_ID => p_product_txn_id);
5177 END IF; --end of delete
5178
5179 -- Api body ends here
5180
5181 -- Standard check of p_commit.
5182 IF Fnd_Api.To_Boolean(p_commit)
5183 THEN
5184 COMMIT WORK;
5185 END IF;
5186
5187 -- Standard call to get message count and IF count is get message info.
5188 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5189 p_data => x_msg_data);
5190 EXCEPTION
5191 WHEN Fnd_Api.G_EXC_ERROR THEN
5192 x_return_status := Fnd_Api.G_RET_STS_ERROR;
5193 ROLLBACK TO delete_product_txn;
5194 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5195 p_data => x_msg_data);
5196 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
5197 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5198 ROLLBACK TO delete_product_txn;
5199 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5200 p_data => x_msg_data);
5201 WHEN OTHERS THEN
5202 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5203 ROLLBACK TO delete_product_txn;
5204 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
5205 THEN
5206 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
5207 END IF;
5208 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5209 p_data => x_msg_data);
5210 END delete_product_txn;
5211
5212 /*--------------------------------------------------*/
5213 /* procedure name: create_default_prod_txn */
5214 /* description : procedure used to create */
5215 /* default product transaction lines */
5216 /* */
5217 /*--------------------------------------------------*/
5218
5219 PROCEDURE create_default_prod_txn(p_api_version IN NUMBER,
5220 p_commit IN VARCHAR2 := Fnd_Api.g_false,
5221 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_false,
5222 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
5223 p_repair_line_id IN NUMBER,
5224 p_create_thirdpty_line IN VARCHAR2 := Fnd_Api.g_false,
5225 p_return_reason_code IN VARCHAR2 := NULL,
5226 p_invoice_to_org_id IN NUMBER := NULL,
5227 p_ship_to_org_id IN NUMBER := NULL,
5228 x_return_status OUT NOCOPY VARCHAR2,
5229 x_msg_count OUT NOCOPY NUMBER,
5230 x_msg_data OUT NOCOPY VARCHAR2) IS
5231
5232 l_api_name CONSTANT VARCHAR2(30) := 'CREATE_DEFAULT_PROD_TXN';
5233 l_api_version CONSTANT NUMBER := 1.0;
5234 l_msg_count NUMBER;
5235 l_msg_data VARCHAR2(2000);
5236 l_msg_index NUMBER;
5237 l_product_txn_rec product_txn_rec;
5238 x_prod_txn_tbl product_txn_tbl;
5239 x_msg_index_out NUMBER;
5240 l_msg_text VARCHAR2(2000) := '';
5241
5242 l_sr_add_to_order_flag VARCHAR2(10);
5243 l_ro_add_to_order_flag VARCHAR2(10);
5244 l_add_rma_to_id NUMBER;
5245 l_add_ship_to_id NUMBER;
5246
5247
5248 BEGIN
5249 -- Standard Start of API savepoint
5250 SAVEPOINT create_default_prod_txn;
5251
5252 --
5253 -- MOAC initialization
5254 --
5255 MO_GLOBAL.init('CS_CHARGES');
5256
5257 -- Standard call to check for call compatibility.
5258 IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
5259 p_api_version,
5260 l_api_name,
5261 G_PKG_NAME)
5262 THEN
5263 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
5264 END IF;
5265
5266 -- Initialize message list if p_init_msg_list is set to TRUE.
5267 IF Fnd_Api.to_Boolean(p_init_msg_list)
5268 THEN
5269 Fnd_Msg_Pub.initialize;
5270 END IF;
5271
5272 -- Initialize API return status to success
5273 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
5274
5275 -- Api body starts
5276 IF (g_debug > 0)
5277 THEN
5278 Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
5279 p_api_name => l_api_name);
5280 END IF;
5281 IF (g_debug > 0)
5282 THEN
5283 Csd_Gen_Utility_Pvt.ADD('Check the required parameter:(repair_line_id)');
5284 Csd_Gen_Utility_Pvt.ADD('Repair line id =' || p_repair_line_id);
5285 END IF;
5286
5287 -- Check the required parameter
5288 Csd_Process_Util.Check_Reqd_Param(p_param_value => p_repair_line_id,
5289 p_param_name => 'REPAIR_LINE_ID',
5290 p_api_name => l_api_name);
5291
5292 IF (g_debug > 0)
5293 THEN
5294 Csd_Gen_Utility_Pvt.ADD('Validate repair line id');
5295 END IF;
5296
5297 -- Validate the repair line ID
5298 IF NOT
5299 (Csd_Process_Util.Validate_rep_line_id(p_repair_line_id => p_repair_line_id))
5300 THEN
5301 RAISE Fnd_Api.G_EXC_ERROR;
5302 END IF;
5303
5304 IF (g_debug > 0)
5305 THEN
5306 Csd_Gen_Utility_Pvt.ADD('Build the product txn table');
5307 END IF;
5308
5309 l_sr_add_to_order_flag := fnd_profile.value('CSD_ADD_TO_SO_WITHIN_SR');
5310 l_sr_add_to_order_flag := nvl(l_sr_Add_to_order_flag, 'N');
5311
5312 l_ro_add_to_order_flag := fnd_profile.value('CSD_ADD_TO_SO_WITHIN_RO');
5313 l_ro_add_to_order_flag := nvl(l_ro_add_to_order_flag, 'N');
5314 -- subhat 12.2 changes.
5315 Csd_Process_Util.BUILD_PROD_TXN_TBL(p_repair_line_id => p_repair_line_id,
5316 p_create_thirdpty_line => p_create_thirdpty_line,
5317 x_prod_txn_tbl => x_prod_txn_tbl,
5318 x_return_status => x_return_status,
5319 p_return_reason_code => p_return_reason_code,
5320 p_invoice_to_org_id => p_invoice_to_org_id,
5321 p_ship_to_org_id => p_ship_to_org_id);
5322
5323 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
5324 THEN
5325 RAISE Fnd_Api.G_EXC_ERROR;
5326 END IF;
5327
5328 IF (g_debug > 0)
5329 THEN
5330 Csd_Gen_Utility_Pvt.ADD('x_prod_txn_tbl.count =' ||
5331 x_prod_txn_tbl.COUNT);
5332 END IF;
5333
5334 IF x_prod_txn_tbl.COUNT > 0 THEN
5335 FOR i IN x_prod_txn_tbl.first..1
5336 LOOP
5337
5338 IF (g_debug > 0 ) THEN
5339 csd_gen_utility_pvt.ADD('Call create_product_txn in a loop');
5340 END IF;
5341 CREATE_PRODUCT_TXN
5342 (p_api_version => 1.0 ,
5343 p_commit => fnd_api.g_false,
5344 p_init_msg_list => 'F',
5345 p_validation_level => fnd_api.g_valid_level_full,
5346 x_product_txn_rec => x_prod_txn_tbl(i),
5347 x_return_status => x_return_status,
5348 x_msg_count => x_msg_count,
5349 x_msg_data => x_msg_data );
5350
5351 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
5352 RAISE FND_API.G_EXC_ERROR;
5353 END IF;
5354 -- Log the message after processing
5355 -- each prod txn
5356 FOR i in 1..x_msg_Count LOOP
5357 FND_MSG_PUB.Get
5358 (p_msg_index => i,
5359 p_encoded => 'F',
5360 p_data => x_msg_data,
5361 p_msg_index_out => x_msg_index_out );
5362 l_msg_text := x_msg_data;
5363 IF (g_debug > 0 ) THEN
5364 csd_gen_utility_pvt.ADD('message data after create_prod_txn ='||x_msg_data);
5365 END IF;
5366 End LOOP;
5367 END LOOP;
5368
5369 FOR i IN 2..x_prod_txn_tbl.last
5370 LOOP
5371
5372 IF (g_debug > 0 ) THEN
5373 csd_gen_utility_pvt.ADD('Call create_product_txn in a loop 2');
5374 END IF;
5375
5376 If ((i = 2) and (x_prod_txn_tbl(i).interface_to_om_flag = 'Y') and
5377 (x_prod_txn_tbl(i).new_order_flag = 'Y' or x_prod_txn_tbl(i).new_order_flag is null) and
5378 ((l_sr_add_to_order_flag = 'Y') or (l_ro_add_to_order_flag = 'Y'))) Then
5379
5380 l_add_rma_to_id := CSD_PROCESS_UTIL.get_sr_add_to_order(p_repair_line_Id, 'RMA');
5381 l_add_ship_to_id := CSD_PROCESS_UTIL.get_sr_add_to_order(p_repair_line_Id, 'SHIP');
5382 If (x_prod_txn_tbl(i).action_type = 'SHIP' and (l_add_ship_to_id is not null)) Then
5383 x_prod_txn_tbl(i).new_order_flag := 'N';
5384 x_prod_txn_tbl(i).add_to_order_flag := 'Y';
5385 x_prod_txn_tbl(i).add_to_order_id := l_add_ship_to_id;
5386 elsif (x_prod_txn_tbl(i).action_type = 'RMA' and (l_add_rma_to_id is not null)) Then
5387 x_prod_txn_tbl(i).new_order_flag := 'N';
5388 x_prod_txn_tbl(i).add_to_order_flag := 'Y';
5389 x_prod_txn_tbl(i).add_to_order_id := l_add_rma_to_id;
5390 End If;
5391
5392 --special case
5393 If ((NVL(x_prod_txn_tbl(1).interface_to_om_flag, 'N') = 'N') and (l_sr_add_to_order_flag = 'N')
5394 and (l_ro_add_to_order_flag = 'Y')) Then
5395 x_prod_txn_tbl(i).new_order_flag := 'Y';
5396 x_prod_txn_tbl(i).add_to_order_flag := 'N';
5397 x_prod_txn_tbl(i).add_to_order_id := null;
5398 End if;
5399
5400 END IF;
5401
5402 CREATE_PRODUCT_TXN
5403 (p_api_version => 1.0 ,
5404 p_commit => fnd_api.g_false,
5405 p_init_msg_list => 'F',
5406 p_validation_level => fnd_api.g_valid_level_full,
5407 x_product_txn_rec => x_prod_txn_tbl(i),
5408 x_return_status => x_return_status,
5409 x_msg_count => x_msg_count,
5410 x_msg_data => x_msg_data );
5411
5412 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
5413 RAISE FND_API.G_EXC_ERROR;
5414 END IF;
5415 -- Log the message after processing
5416 -- each prod txn
5417 FOR i in 1..x_msg_Count LOOP
5418 FND_MSG_PUB.Get
5419 (p_msg_index => i,
5420 p_encoded => 'F',
5421 p_data => x_msg_data,
5422 p_msg_index_out => x_msg_index_out );
5423 l_msg_text := x_msg_data;
5424 IF (g_debug > 0 ) THEN
5425 csd_gen_utility_pvt.ADD('message data after create_prod_txn ='||x_msg_data);
5426 END IF;
5427 End LOOP;
5428 END LOOP;
5429 END IF;
5430
5431 -- Api body ends here
5432 IF l_msg_text IS NOT NULL
5433 THEN
5434 Fnd_Message.SET_NAME('CSD', 'CSD_API_OM_ERR_MSG');
5435 Fnd_Message.SET_TOKEN('MSG_DATA', l_msg_text);
5436 Fnd_Msg_Pub.ADD;
5437 END IF;
5438
5439 -- Standard check of p_commit.
5440 IF Fnd_Api.To_Boolean(p_commit)
5441 THEN
5442 COMMIT WORK;
5443 END IF;
5444
5445 -- Standard call to get message count and IF count is get message info.
5446 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5447 p_data => x_msg_data);
5448
5449 EXCEPTION
5450 WHEN Fnd_Api.G_EXC_ERROR THEN
5451 ROLLBACK TO create_default_prod_txn;
5452 x_return_status := Fnd_Api.G_RET_STS_ERROR;
5453 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5454 p_data => x_msg_data);
5455 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
5456 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5457 ROLLBACK TO create_default_prod_txn;
5458 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5459 p_data => x_msg_data);
5460 WHEN OTHERS THEN
5461 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5462 ROLLBACK TO create_default_prod_txn;
5463 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
5464 THEN
5465 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
5466 END IF;
5467 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5468 p_data => x_msg_data);
5469 END create_default_prod_txn;
5470
5471 --------------------- travi changes---------------
5472
5473 FUNCTION GET_ORG_REC_TYPE RETURN HZ_PARTY_V2PUB.ORGANIZATION_REC_TYPE IS
5474 TMP_ORG_REC_TYPE HZ_PARTY_V2PUB.ORGANIZATION_REC_TYPE;
5475 BEGIN
5476 RETURN TMP_ORG_REC_TYPE;
5477 END GET_ORG_REC_TYPE;
5478 FUNCTION GET_GROUP_REC_TYPE RETURN HZ_PARTY_V2PUB.GROUP_REC_TYPE IS
5479 TMP_GROUP_REC_TYPE HZ_PARTY_V2PUB.GROUP_REC_TYPE;
5480 BEGIN
5481 RETURN TMP_GROUP_REC_TYPE;
5482 END GET_GROUP_REC_TYPE;
5483 FUNCTION GET_PARTY_REC_TYPE RETURN HZ_PARTY_V2PUB.PARTY_REC_TYPE IS
5484 TMP_PARTY_REC_TYPE HZ_PARTY_V2PUB.PARTY_REC_TYPE;
5485 BEGIN
5486 RETURN TMP_PARTY_REC_TYPE;
5487 END GET_PARTY_REC_TYPE;
5488 FUNCTION GET_PERSON_REC_TYPE RETURN HZ_PARTY_V2PUB.PERSON_REC_TYPE IS
5489 TMP_PERSON_REC_TYPE HZ_PARTY_V2PUB.PERSON_REC_TYPE;
5490 BEGIN
5491 RETURN TMP_PERSON_REC_TYPE;
5492 END GET_PERSON_REC_TYPE;
5493 FUNCTION GET_CONTACT_POINTS_REC_TYPE
5494 RETURN HZ_CONTACT_POINT_V2PUB.CONTACT_POINT_REC_TYPE IS
5495 TMP_CONTACT_POINTS_REC_TYPE HZ_CONTACT_POINT_V2PUB.CONTACT_POINT_REC_TYPE;
5496 BEGIN
5497 RETURN TMP_CONTACT_POINTS_REC_TYPE;
5498 END GET_CONTACT_POINTS_REC_TYPE;
5499 FUNCTION GET_EDI_REC_TYPE RETURN HZ_CONTACT_POINT_V2PUB.EDI_REC_TYPE IS
5500 TMP_EDI_REC_TYPE HZ_CONTACT_POINT_V2PUB.EDI_REC_TYPE;
5501 BEGIN
5502 RETURN TMP_EDI_REC_TYPE;
5503 END GET_EDI_REC_TYPE;
5504 FUNCTION GET_PHONE_REC_TYPE RETURN HZ_CONTACT_POINT_V2PUB.PHONE_REC_TYPE IS
5505 TMP_PHONE_REC_TYPE HZ_CONTACT_POINT_V2PUB.PHONE_REC_TYPE;
5506 BEGIN
5507 RETURN TMP_PHONE_REC_TYPE;
5508 END GET_PHONE_REC_TYPE;
5509 FUNCTION GET_EMAIL_REC_TYPE RETURN HZ_CONTACT_POINT_V2PUB.EMAIL_REC_TYPE IS
5510 TMP_EMAIL_REC_TYPE HZ_CONTACT_POINT_V2PUB.EMAIL_REC_TYPE;
5511 BEGIN
5512 RETURN TMP_EMAIL_REC_TYPE;
5513 END GET_EMAIL_REC_TYPE;
5514 FUNCTION GET_TELEX_REC_TYPE RETURN HZ_CONTACT_POINT_V2PUB.TELEX_REC_TYPE IS
5515 TMP_TELEX_REC_TYPE HZ_CONTACT_POINT_V2PUB.TELEX_REC_TYPE;
5516 BEGIN
5517 RETURN TMP_TELEX_REC_TYPE;
5518 END GET_TELEX_REC_TYPE;
5519 FUNCTION GET_WEB_REC_TYPE RETURN HZ_CONTACT_POINT_V2PUB.WEB_REC_TYPE IS
5520 TMP_WEB_REC_TYPE HZ_CONTACT_POINT_V2PUB.WEB_REC_TYPE;
5521 BEGIN
5522 RETURN TMP_WEB_REC_TYPE;
5523 END GET_WEB_REC_TYPE;
5524 FUNCTION GET_ACCOUNT_REC_TYPE
5525 RETURN HZ_CUST_ACCOUNT_V2PUB.CUST_ACCOUNT_REC_TYPE IS
5526 TMP_ACCOUNT_REC_TYPE HZ_CUST_ACCOUNT_V2PUB.CUST_ACCOUNT_REC_TYPE;
5527 BEGIN
5528 RETURN TMP_ACCOUNT_REC_TYPE;
5529 END GET_ACCOUNT_REC_TYPE;
5530 FUNCTION GET_PARTY_REL_REC_TYPE RETURN HZ_RELATIONSHIP_V2PUB.RELATIONSHIP_REC_TYPE IS
5531 TMP_PARTY_REL_REC_TYPE HZ_RELATIONSHIP_V2PUB.RELATIONSHIP_REC_TYPE;
5532 BEGIN
5533 RETURN TMP_PARTY_REL_REC_TYPE;
5534 END GET_PARTY_REL_REC_TYPE;
5535 FUNCTION GET_ORG_CONTACT_REC_TYPE RETURN HZ_PARTY_CONTACT_V2PUB.ORG_CONTACT_REC_TYPE IS
5536 TMP_ORG_CONTACT_REC_TYPE HZ_PARTY_CONTACT_V2PUB.ORG_CONTACT_REC_TYPE;
5537 BEGIN
5538 RETURN TMP_ORG_CONTACT_REC_TYPE;
5539 END GET_ORG_CONTACT_REC_TYPE;
5540 FUNCTION GET_PARTY_SITE_REC_TYPE RETURN HZ_PARTY_SITE_V2PUB.PARTY_SITE_REC_TYPE IS
5541 TMP_PARTY_SITE_REC_TYPE HZ_PARTY_SITE_V2PUB.PARTY_SITE_REC_TYPE;
5542 BEGIN
5543 RETURN TMP_PARTY_SITE_REC_TYPE;
5544 END GET_PARTY_SITE_REC_TYPE;
5545 FUNCTION GET_PARTY_SITE_USE_REC_TYPE
5546 RETURN HZ_PARTY_SITE_V2PUB.PARTY_SITE_USE_REC_TYPE IS
5547 TMP_PARTY_SITE_USE_REC_TYPE HZ_PARTY_SITE_V2PUB.PARTY_SITE_USE_REC_TYPE;
5548 BEGIN
5549 RETURN TMP_PARTY_SITE_USE_REC_TYPE;
5550 END GET_PARTY_SITE_USE_REC_TYPE;
5551 FUNCTION GET_CUST_PROFILE_REC_TYPE
5552 RETURN HZ_CUSTOMER_PROFILE_V2PUB.CUSTOMER_PROFILE_REC_TYPE IS
5553 TMP_CUST_PROFILE_REC_TYPE HZ_CUSTOMER_PROFILE_V2PUB.CUSTOMER_PROFILE_REC_TYPE;
5554 BEGIN
5555 RETURN TMP_CUST_PROFILE_REC_TYPE;
5556 END GET_CUST_PROFILE_REC_TYPE;
5557 FUNCTION GET_CREATE_TASK_REC_TYPE
5558 RETURN Csd_Process_Pvt.CREATE_TASK_REC_TYPE IS
5559 TMP_CREATE_TASK_REC_TYPE Csd_Process_Pvt.CREATE_TASK_REC_TYPE;
5560 BEGIN
5561 RETURN TMP_CREATE_TASK_REC_TYPE;
5562 END GET_CREATE_TASK_REC_TYPE;
5563
5564 /*-----------------------------------------------------------------------------------------------------------*/
5565 /* procedure name: create_task */
5566 /* description : procedure used to create task */
5567 /* Called from : Depot Repair Form to Create Task */
5568 /* Input Parm : p_api_version NUMBER Required Api Version number */
5569 /* p_init_msg_list VARCHAR2 Optional Initializes message stack if fnd_api.g_true, */
5570 /* default value is fnd_api.g_false */
5571 /* p_commit VARCHAR2 Optional Commits in API if fnd_api.g_true, default */
5572 /* fnd_api.g_false */
5573 /* p_validation_level NUMBER Optional API uses this parameter to determine which */
5574 /* validation steps must be done and which steps */
5575 /* should be skipped. */
5576 /* CREATE_TASK_REC_TYPE RECORD Required Columns are in the Record CREATE_TASK_REC_TYPE */
5577 /* Output Parm : x_return_status VARCHAR2 Return status after the call. The status can be*/
5578 /* fnd_api.g_ret_sts_success (success) */
5579 /* fnd_api.g_ret_sts_error (error) */
5580 /* fnd_api.g_ret_sts_unexp_error (unexpected) */
5581 /* x_msg_count NUMBER Number of messages in the message stack */
5582 /* x_msg_data VARCHAR2 Message text if x_msg_count >= 1 */
5583 /* x_task_id NUMBER Task Id of the created Task */
5584 /*-----------------------------------------------------------------------------------------------------------*/
5585
5586 PROCEDURE create_task(p_api_version IN NUMBER,
5587 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_false,
5588 p_commit IN VARCHAR2 := Fnd_Api.g_false,
5589 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
5590 p_create_task_rec IN CREATE_TASK_REC_TYPE,
5591 x_return_status OUT NOCOPY VARCHAR2,
5592 x_msg_count OUT NOCOPY NUMBER,
5593 x_msg_data OUT NOCOPY VARCHAR2,
5594 x_task_id OUT NOCOPY NUMBER) IS
5595 l_api_name CONSTANT VARCHAR2(30) := 'CREATE_TASK';
5596 l_api_version CONSTANT NUMBER := 1.0;
5597 l_msg_count NUMBER;
5598 l_msg_data VARCHAR2(2000);
5599 l_msg_index NUMBER;
5600 l_return_status VARCHAR2(1);
5601 l_task_id NUMBER;
5602 -- Task record
5603 l_create_task_rec Csd_Process_Pvt.CREATE_TASK_REC_TYPE := p_create_task_rec;
5604 BEGIN
5605 -- -----------------
5606 -- Begin create task
5607 -- -----------------
5608 -- Standard Start of API savepoint
5609 SAVEPOINT create_task;
5610 -- Standard call to check for call compatibility.
5611 IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
5612 p_api_version,
5613 l_api_name,
5614 G_PKG_NAME)
5615 THEN
5616 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
5617 END IF;
5618 -- Initialize message list if p_init_msg_list is set to TRUE.
5619 IF Fnd_Api.to_Boolean(p_init_msg_list)
5620 THEN
5621 Fnd_Msg_Pub.initialize;
5622 END IF;
5623 -- Initialize API return status to success
5624 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
5625 -- ---------------
5626 -- Api body starts
5627 -- ---------------
5628 IF (g_debug > 0)
5629 THEN
5630 Csd_Gen_Utility_Pvt.ADD('CSD_PROCESS_PVT.create_task before jtf_tasks_pub.CREATE_TASK');
5631 END IF;
5632
5633 -- ----------------------------------------
5634 -- Calling Public JTF API to create a Task
5635 -- ----------------------------------------
5636 Jtf_Tasks_Pub.CREATE_TASK(P_API_VERSION => 1.0,
5637 P_INIT_MSG_LIST => Fnd_Api.g_true,
5638 P_COMMIT => Fnd_Api.g_false,
5639 P_TASK_ID => l_create_task_rec.task_id,
5640 P_TASK_NAME => l_create_task_rec.TASK_NAME,
5641 P_TASK_TYPE_ID => l_create_task_rec.TASK_TYPE_ID,
5642 P_DESCRIPTION => l_create_task_rec.DESCRIPTION,
5643 P_TASK_STATUS_ID => l_create_task_rec.TASK_STATUS_ID,
5644 P_TASK_PRIORITY_ID => l_create_task_rec.TASK_PRIORITY_ID,
5645 P_OWNER_TYPE_CODE => l_create_task_rec.OWNER_TYPE_CODE,
5646 P_OWNER_ID => l_create_task_rec.OWNER_ID,
5647 P_OWNER_TERRITORY_ID => l_create_task_rec.OWNER_TERRITORY_ID,
5648 P_ASSIGNED_BY_ID => l_create_task_rec.ASSIGNED_BY_ID,
5649 P_CUSTOMER_ID => l_create_task_rec.CUSTOMER_ID,
5650 P_CUST_ACCOUNT_ID => l_create_task_rec.CUST_ACCOUNT_ID,
5651 P_ADDRESS_ID => l_create_task_rec.ADDRESS_ID,
5652 P_PLANNED_START_DATE => l_create_task_rec.planned_start_date,
5653 P_PLANNED_END_DATE => l_create_task_rec.planned_end_date,
5654 P_SCHEDULED_START_DATE => l_create_task_rec.scheduled_start_date,
5655 P_SCHEDULED_END_DATE => l_create_task_rec.scheduled_end_date,
5656 P_ACTUAL_START_DATE => l_create_task_rec.actual_start_date,
5657 P_ACTUAL_END_DATE => l_create_task_rec.actual_end_date,
5658 P_TIMEZONE_ID => l_create_task_rec.TIMEZONE_ID,
5659 P_SOURCE_OBJECT_TYPE_CODE => l_create_task_rec.SOURCE_OBJECT_TYPE_CODE,
5660 P_SOURCE_OBJECT_ID => l_create_task_rec.SOURCE_OBJECT_ID,
5661 P_SOURCE_OBJECT_NAME => l_create_task_rec.SOURCE_OBJECT_NAME,
5662 P_DURATION => l_create_task_rec.DURATION,
5663 P_DURATION_UOM => l_create_task_rec.DURATION_UOM,
5664 P_PLANNED_EFFORT => l_create_task_rec.PLANNED_EFFORT,
5665 P_PLANNED_EFFORT_UOM => l_create_task_rec.PLANNED_EFFORT_UOM,
5666 P_ACTUAL_EFFORT => l_create_task_rec.ACTUAL_EFFORT,
5667 P_ACTUAL_EFFORT_UOM => l_create_task_rec.ACTUAL_EFFORT_UOM,
5668 P_PRIVATE_FLAG => l_create_task_rec.PRIVATE_FLAG,
5669 P_PUBLISH_FLAG => l_create_task_rec.PUBLISH_FLAG,
5670 P_RESTRICT_CLOSURE_FLAG => l_create_task_rec.RESTRICT_CLOSURE_FLAG,
5671 P_ATTRIBUTE1 => l_create_task_rec.ATTRIBUTE1,
5672 P_ATTRIBUTE2 => l_create_task_rec.ATTRIBUTE2,
5673 P_ATTRIBUTE3 => l_create_task_rec.ATTRIBUTE3,
5674 P_ATTRIBUTE4 => l_create_task_rec.ATTRIBUTE4,
5675 P_ATTRIBUTE5 => l_create_task_rec.ATTRIBUTE5,
5676 P_ATTRIBUTE6 => l_create_task_rec.ATTRIBUTE6,
5677 P_ATTRIBUTE7 => l_create_task_rec.ATTRIBUTE7,
5678 P_ATTRIBUTE8 => l_create_task_rec.ATTRIBUTE8,
5679 P_ATTRIBUTE9 => l_create_task_rec.ATTRIBUTE9,
5680 P_ATTRIBUTE10 => l_create_task_rec.ATTRIBUTE10,
5681 P_ATTRIBUTE11 => l_create_task_rec.ATTRIBUTE11,
5682 P_ATTRIBUTE12 => l_create_task_rec.ATTRIBUTE12,
5683 P_ATTRIBUTE13 => l_create_task_rec.ATTRIBUTE13,
5684 P_ATTRIBUTE14 => l_create_task_rec.ATTRIBUTE14,
5685 P_ATTRIBUTE15 => l_create_task_rec.ATTRIBUTE15,
5686 P_ATTRIBUTE_CATEGORY => l_create_task_rec.ATTRIBUTE_CATEGORY,
5687 P_BOUND_MODE_CODE => l_create_task_rec.bound_mode_code,
5688 P_SOFT_BOUND_FLAG => l_create_task_rec.soft_bound_flag,
5689 P_PARENT_TASK_ID => l_create_task_rec.PARENT_TASK_ID,
5690 P_ESCALATION_LEVEL => l_create_task_rec.ESCALATION_LEVEL,
5691 X_RETURN_STATUS => x_return_status,
5692 X_MSG_COUNT => x_msg_count,
5693 X_MSG_DATA => x_msg_data,
5694 X_TASK_ID => x_task_id);
5695
5696 IF (g_debug > 0)
5697 THEN
5698 Csd_Gen_Utility_Pvt.ADD('CSD_PROCESS_PVT.create_task after jtf_tasks_pub.CREATE_TASK x_return_status' ||
5699 x_return_status);
5700 END IF;
5701
5702 -- -------------------
5703 -- Api body ends here
5704 -- -------------------
5705 -- Standard check of p_commit.
5706 IF Fnd_Api.To_Boolean(p_commit)
5707 THEN
5708 COMMIT WORK;
5709 END IF;
5710 -- Standard call to get message count and IF count is get message info.
5711 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5712 p_data => x_msg_data);
5713 EXCEPTION
5714 WHEN Fnd_Api.G_EXC_ERROR THEN
5715 ROLLBACK TO create_task;
5716 x_return_status := Fnd_Api.G_RET_STS_ERROR;
5717 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5718 p_data => x_msg_data);
5719 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
5720 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5721 ROLLBACK TO create_task;
5722 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5723 p_data => x_msg_data);
5724 WHEN OTHERS THEN
5725 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5726 ROLLBACK TO create_task;
5727 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
5728 THEN
5729 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
5730 END IF;
5731 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5732 p_data => x_msg_data);
5733 END create_task;
5734
5735 /*-----------------------------------------------------------------------------------------------------------*/
5736 /* procedure name: update_task */
5737 /* description : procedure used to update task */
5738 /* Called from : Depot Repair Form to Create Task */
5739 /* Input Parm : p_api_version NUMBER Required Api Version number */
5740 /* p_init_msg_list VARCHAR2 Optional Initializes message stack if fnd_api.g_true, */
5741 /* default value is fnd_api.g_false */
5742 /* p_commit VARCHAR2 Optional Commits in API if fnd_api.g_true, default */
5743 /* fnd_api.g_false */
5744 /* p_validation_level NUMBER Optional API uses this parameter to determine which */
5745 /* validation steps must be done and which steps */
5746 /* should be skipped. */
5747 /* CREATE_TASK_REC_TYPE RECORD Required Columns are in the Record CREATE_TASK_REC_TYPE */
5748 /* Output Parm : x_return_status VARCHAR2 Return status after the call. The status can be*/
5749 /* fnd_api.g_ret_sts_success (success) */
5750 /* fnd_api.g_ret_sts_error (error) */
5751 /* fnd_api.g_ret_sts_unexp_error (unexpected) */
5752 /* x_msg_count NUMBER Number of messages in the message stack */
5753 /* x_msg_data VARCHAR2 Message text if x_msg_count >= 1 */
5754 /*-----------------------------------------------------------------------------------------------------------*/
5755
5756 PROCEDURE update_task(p_api_version IN NUMBER,
5757 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_false,
5758 p_commit IN VARCHAR2 := Fnd_Api.g_false,
5759 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
5760 p_create_task_rec IN CREATE_TASK_REC_TYPE,
5761 x_return_status OUT NOCOPY VARCHAR2,
5762 x_msg_count OUT NOCOPY NUMBER,
5763 x_msg_data OUT NOCOPY VARCHAR2) IS
5764 l_api_name CONSTANT VARCHAR2(30) := 'UPDATE_TASK';
5765 l_api_version CONSTANT NUMBER := 1.0;
5766 l_msg_count NUMBER;
5767 l_msg_data VARCHAR2(2000);
5768 l_msg_index NUMBER;
5769 l_return_status VARCHAR2(1);
5770 l_task_id NUMBER;
5771 -- Task record
5772 l_create_task_rec Csd_Process_Pvt.CREATE_TASK_REC_TYPE := p_create_task_rec;
5773 BEGIN
5774 -- -----------------
5775 -- Begin update task
5776 -- -----------------
5777 -- Standard Start of API savepoint
5778 SAVEPOINT update_task;
5779 -- Standard call to check for call compatibility.
5780 IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
5781 p_api_version,
5782 l_api_name,
5783 G_PKG_NAME)
5784 THEN
5785 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
5786 END IF;
5787 -- Initialize message list if p_init_msg_list is set to TRUE.
5788 IF Fnd_Api.to_Boolean(p_init_msg_list)
5789 THEN
5790 Fnd_Msg_Pub.initialize;
5791 END IF;
5792 -- Initialize API return status to success
5793 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
5794 -- ---------------
5795 -- Api body starts
5796 -- ---------------
5797 IF (g_debug > 0)
5798 THEN
5799 Csd_Gen_Utility_Pvt.ADD('CSD_PROCESS_PVT.update_task before jtf_tasks_pub.UPDATE_TASK');
5800 END IF;
5801
5802 -- ----------------------------------------
5803 -- Calling Public JTF API to Update a Task
5804 -- ----------------------------------------
5805 Jtf_Tasks_Pub.UPDATE_TASK(P_API_VERSION => 1.0,
5806 P_INIT_MSG_LIST => Fnd_Api.g_true,
5807 P_COMMIT => Fnd_Api.g_false,
5808 P_TASK_ID => l_create_task_rec.task_id,
5809 P_TASK_NAME => l_create_task_rec.TASK_NAME,
5810 P_TASK_TYPE_ID => l_create_task_rec.TASK_TYPE_ID,
5811 P_DESCRIPTION => l_create_task_rec.DESCRIPTION,
5812 P_TASK_STATUS_ID => l_create_task_rec.TASK_STATUS_ID,
5813 P_TASK_PRIORITY_NAME => l_create_task_rec.TASK_PRIORITY_NAME,
5814 P_TASK_PRIORITY_ID => l_create_task_rec.TASK_PRIORITY_ID,
5815 P_OWNER_TYPE_CODE => l_create_task_rec.OWNER_TYPE_CODE,
5816 P_OWNER_ID => l_create_task_rec.OWNER_ID,
5817 P_OWNER_TERRITORY_ID => l_create_task_rec.OWNER_TERRITORY_ID,
5818 P_ASSIGNED_BY_ID => l_create_task_rec.ASSIGNED_BY_ID,
5819 P_CUSTOMER_ID => l_create_task_rec.CUSTOMER_ID,
5820 P_CUST_ACCOUNT_ID => l_create_task_rec.CUST_ACCOUNT_ID,
5821 P_ADDRESS_ID => l_create_task_rec.ADDRESS_ID,
5822 P_PLANNED_START_DATE => l_create_task_rec.planned_start_date,
5823 P_PLANNED_END_DATE => l_create_task_rec.planned_end_date,
5824 P_SCHEDULED_START_DATE => l_create_task_rec.scheduled_start_date,
5825 P_SCHEDULED_END_DATE => l_create_task_rec.scheduled_end_date,
5826 P_ACTUAL_START_DATE => l_create_task_rec.actual_start_date,
5827 P_ACTUAL_END_DATE => l_create_task_rec.actual_end_date,
5828 P_TIMEZONE_ID => l_create_task_rec.TIMEZONE_ID,
5829 P_SOURCE_OBJECT_TYPE_CODE => l_create_task_rec.SOURCE_OBJECT_TYPE_CODE,
5830 P_SOURCE_OBJECT_ID => l_create_task_rec.SOURCE_OBJECT_ID,
5831 P_SOURCE_OBJECT_NAME => l_create_task_rec.SOURCE_OBJECT_NAME,
5832 P_DURATION => l_create_task_rec.DURATION,
5833 P_DURATION_UOM => l_create_task_rec.DURATION_UOM,
5834 P_PLANNED_EFFORT => l_create_task_rec.PLANNED_EFFORT,
5835 P_PLANNED_EFFORT_UOM => l_create_task_rec.PLANNED_EFFORT_UOM,
5836 P_ACTUAL_EFFORT => l_create_task_rec.ACTUAL_EFFORT,
5837 P_ACTUAL_EFFORT_UOM => l_create_task_rec.ACTUAL_EFFORT_UOM,
5838 P_PRIVATE_FLAG => l_create_task_rec.PRIVATE_FLAG,
5839 P_PUBLISH_FLAG => l_create_task_rec.PUBLISH_FLAG,
5840 P_RESTRICT_CLOSURE_FLAG => l_create_task_rec.RESTRICT_CLOSURE_FLAG,
5841 P_ATTRIBUTE1 => l_create_task_rec.ATTRIBUTE1,
5842 P_ATTRIBUTE2 => l_create_task_rec.ATTRIBUTE2,
5843 P_ATTRIBUTE3 => l_create_task_rec.ATTRIBUTE3,
5844 P_ATTRIBUTE4 => l_create_task_rec.ATTRIBUTE4,
5845 P_ATTRIBUTE5 => l_create_task_rec.ATTRIBUTE5,
5846 P_ATTRIBUTE6 => l_create_task_rec.ATTRIBUTE6,
5847 P_ATTRIBUTE7 => l_create_task_rec.ATTRIBUTE7,
5848 P_ATTRIBUTE8 => l_create_task_rec.ATTRIBUTE8,
5849 P_ATTRIBUTE9 => l_create_task_rec.ATTRIBUTE9,
5850 P_ATTRIBUTE10 => l_create_task_rec.ATTRIBUTE10,
5851 P_ATTRIBUTE11 => l_create_task_rec.ATTRIBUTE11,
5852 P_ATTRIBUTE12 => l_create_task_rec.ATTRIBUTE12,
5853 P_ATTRIBUTE13 => l_create_task_rec.ATTRIBUTE13,
5854 P_ATTRIBUTE14 => l_create_task_rec.ATTRIBUTE14,
5855 P_ATTRIBUTE15 => l_create_task_rec.ATTRIBUTE15,
5856 P_ATTRIBUTE_CATEGORY => l_create_task_rec.ATTRIBUTE_CATEGORY,
5857 P_BOUND_MODE_CODE => l_create_task_rec.bound_mode_code,
5858 P_SOFT_BOUND_FLAG => l_create_task_rec.soft_bound_flag,
5859 P_PARENT_TASK_ID => l_create_task_rec.PARENT_TASK_ID,
5860 P_ESCALATION_LEVEL => l_create_task_rec.ESCALATION_LEVEL,
5861 P_OBJECT_VERSION_NUMBER => l_create_task_rec.OBJECT_VERSION_NUMBER,
5862 X_RETURN_STATUS => x_return_status,
5863 X_MSG_COUNT => x_msg_count,
5864 X_MSG_DATA => x_msg_data);
5865
5866 IF (g_debug > 0)
5867 THEN
5868 Csd_Gen_Utility_Pvt.ADD('CSD_PROCESS_PVT.update_task after jtf_tasks_pub.UPDATE_TASK x_return_status' ||
5869 x_return_status);
5870 END IF;
5871
5872 -- -------------------
5873 -- Api body ends here
5874 -- -------------------
5875 -- Standard check of p_commit.
5876 IF Fnd_Api.To_Boolean(p_commit)
5877 THEN
5878 COMMIT WORK;
5879 END IF;
5880 -- Standard call to get message count and IF count is get message info.
5881 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5882 p_data => x_msg_data);
5883 EXCEPTION
5884 WHEN Fnd_Api.G_EXC_ERROR THEN
5885 ROLLBACK TO update_task;
5886 x_return_status := Fnd_Api.G_RET_STS_ERROR;
5887 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5888 p_data => x_msg_data);
5889 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
5890 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5891 ROLLBACK TO update_task;
5892 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5893 p_data => x_msg_data);
5894 WHEN OTHERS THEN
5895 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5896 ROLLBACK TO update_task;
5897 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
5898 THEN
5899 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
5900 END IF;
5901 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5902 p_data => x_msg_data);
5903 END update_task;
5904 FUNCTION GET_ADDRESS_REC_TYPE RETURN Csd_Process_Pvt.ADDRESS_REC_TYPE IS
5905 TMP_ADDRESS_REC_TYPE Csd_Process_Pvt.ADDRESS_REC_TYPE;
5906 BEGIN
5907 RETURN TMP_ADDRESS_REC_TYPE;
5908 END GET_ADDRESS_REC_TYPE;
5909
5910 /*-----------------------------------------------------------------------------------------------------------*/
5911 /* procedure name: create_address */
5912 /* description : procedure to create Address for the Contact */
5913 /* Called from : Depot Repair Form to Create Address */
5914 /* Input Parm : p_address_rec RECORD Required Record ADDRESS_REC_TYPE */
5915 /* Output Parm : x_return_status VARCHAR2 Return status after the call. The status can be*/
5916 /* fnd_api.g_ret_sts_success (success) */
5917 /* fnd_api.g_ret_sts_error (error) */
5918 /* fnd_api.g_ret_sts_unexp_error (unexpected) */
5919 /* x_msg_count NUMBER Number of messages in the message stack */
5920 /* x_msg_data VARCHAR2 Message text if x_msg_count >= 1 */
5921 /* x_location_id NUMBER Location ID of the Contacts address created */
5922 /*-----------------------------------------------------------------------------------------------------------*/
5923
5924 PROCEDURE Create_Address(p_address_rec IN ADDRESS_REC_TYPE,
5925 x_msg_count OUT NOCOPY NUMBER,
5926 x_msg_data OUT NOCOPY VARCHAR2,
5927 x_return_status OUT NOCOPY VARCHAR2,
5928 x_location_id OUT NOCOPY NUMBER) IS
5929 l_location_rec HZ_LOCATION_V2PUB.LOCATION_REC_TYPE;
5930 l_return_status VARCHAR2(1);
5931 l_msg_count NUMBER;
5932 l_msg_data VARCHAR2(2000);
5933 l_location_id NUMBER;
5934 BEGIN
5935 l_location_rec.address1 := p_address_rec.address1;
5936 l_location_rec.address2 := p_address_rec.address2;
5937 l_location_rec.address3 := p_address_rec.address3;
5938 l_location_rec.address4 := p_address_rec.address4;
5939 l_location_rec.city := p_address_rec.city;
5940 l_location_rec.state := p_address_rec.state;
5941 l_location_rec.county := p_address_rec.county;
5942 l_location_rec.country := p_address_rec.country;
5943 l_location_rec.postal_code := p_address_rec.postal_code;
5944 l_location_rec.province := p_address_rec.province;
5945 l_location_rec.county := p_address_rec.county;
5946 l_location_rec.LANGUAGE := p_address_rec.LANGUAGE;
5947 l_location_rec.position := p_address_rec.position;
5948 l_location_rec.address_key := p_address_rec.address_key;
5949 l_location_rec.postal_plus4_code := p_address_rec.postal_plus4_code;
5950 l_location_rec.position := p_address_rec.position;
5951 l_location_rec.delivery_point_code := p_address_rec.delivery_point_code;
5952 l_location_rec.location_directions := p_address_rec.location_directions;
5953 -- l_location_rec.address_error_code := p_address_rec.address_error_code;
5954 l_location_rec.clli_code := p_address_rec.clli_code;
5955 l_location_rec.short_description := p_address_rec.short_description;
5956 l_location_rec.description := p_address_rec.description;
5957 l_location_rec.sales_tax_geocode := p_address_rec.sales_tax_geocode;
5958 l_location_rec.sales_tax_inside_city_limits := p_address_rec.sales_tax_inside_city_limits;
5959 -- swai: new TCA v2 fields
5960 l_location_rec.timezone_id := p_address_rec.timezone_id;
5961 l_location_rec.created_by_module := p_address_rec.created_by_module;
5962 l_location_rec.application_id := p_address_rec.application_id;
5963 l_location_rec.actual_content_source := p_address_rec.actual_content_source;
5964 -- swai: unused fields in TCA, but still avail in v2 (per bug #2863096)
5965 l_location_rec.po_box_number := p_address_rec.po_box_number;
5966 l_location_rec.street := p_address_rec.street;
5967 l_location_rec.house_number := p_address_rec.house_number;
5968 l_location_rec.street_suffix := p_address_rec.street_suffix;
5969 l_location_rec.street_number := p_address_rec.street_number;
5970 l_location_rec.floor := p_address_rec.floor;
5971 l_location_rec.suite := p_address_rec.suite;
5972 -- swai: obsoleted v1 fields
5973 -- l_location_rec.apartment_number := p_address_rec.apartment_number;
5974 -- l_location_rec.building := p_address_rec.building;
5975 -- l_location_rec.apartment_flag := p_address_rec.apartment_flag;
5976 -- l_location_rec.secondary_suffix_element := p_address_rec.secondary_suffix_element;
5977 -- l_location_rec.rural_route_type := p_address_rec.rural_route_type;
5978 -- l_location_rec.rural_route_number := p_address_rec.rural_route_number;
5979 -- l_location_rec.room := p_address_rec.room;
5980 -- l_location_rec.time_zone := p_address_rec.time_zone;
5981 -- l_location_rec.post_office := p_address_rec.post_office;
5982 -- l_location_rec.dodaac := p_address_rec.dodaac;
5983 -- l_location_rec.trailing_directory_code := p_address_rec.trailing_directory_code;
5984 -- l_location_rec.life_cycle_status := p_address_rec.life_cycle_status;
5985 -- l_location_rec.wh_update_date := p_address_rec.wh_update_date;
5986
5987
5988 /*-----------------------------------------------------------------------------------------------------------*/
5989 /* Calling HZ Public API to create location */
5990 /* Description : Creates location. */
5991 /* Input Parm : */
5992 /* p_api_version */
5993 /* p_init_msg_list */
5994 /* p_commit */
5995 /* p_location_rec */
5996 /* p_validation_level */
5997 /* Output Parm : */
5998 /* x_return_status */
5999 /* x_msg_count */
6000 /* x_msg_data */
6001 /* x_location_id */
6002 /*-----------------------------------------------------------------------------------------------------------*/
6003 HZ_LOCATION_V2PUB.create_location(p_init_msg_list => Fnd_Api.G_FALSE,
6004 p_location_rec => l_location_rec,
6005 x_location_id => l_location_id,
6006 x_return_status => l_return_status,
6007 x_msg_count => l_msg_count,
6008 x_msg_data => l_msg_data
6009 );
6010 x_return_status := l_return_status;
6011 x_msg_count := l_msg_count;
6012 x_msg_data := l_msg_data;
6013 IF x_return_status = Csc_Core_Utils_Pvt.G_RET_STS_SUCCESS
6014 THEN
6015 x_location_id := l_location_id;
6016 END IF;
6017 END Create_Address;
6018
6019 /*-----------------------------------------------------------------------------------------------------------*/
6020 /* procedure name: Create_repair_task_hist */
6021 /* description : procedure used to create Repair Order history for task creation */
6022 /* Called from : Depot Repair Form to Create Address */
6023 /* Input Parm : p_api_version NUMBER Required Api Version number */
6024 /* p_init_msg_list VARCHAR2 Optional Initializes message stack if fnd_api.g_true, */
6025 /* default value is fnd_api.g_false */
6026 /* p_commit VARCHAR2 Optional Commits in API if fnd_api.g_true, default */
6027 /* fnd_api.g_false */
6028 /* p_validation_level NUMBER Optional API uses this parameter to determine which */
6029 /* validation steps must be done and which steps */
6030 /* should be skipped. */
6031 /* p_task_id NUMBER Required Task Id */
6032 /* p_repair_line_id NUMBER Required Repair_line_id */
6033 /* Output Parm : x_return_status VARCHAR2 Return status after the call. The status can be*/
6034 /* fnd_api.g_ret_sts_success (success) */
6035 /* fnd_api.g_ret_sts_error (error) */
6036 /* fnd_api.g_ret_sts_unexp_error (unexpected) */
6037 /* x_msg_count NUMBER Number of messages in the message stack */
6038 /* x_msg_data VARCHAR2 Message text if x_msg_count >= 1 */
6039 /*-----------------------------------------------------------------------------------------------------------*/
6040
6041 PROCEDURE Create_repair_task_hist(p_api_version IN NUMBER,
6042 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_false,
6043 p_commit IN VARCHAR2 := Fnd_Api.g_false,
6044 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
6045 p_task_id IN NUMBER,
6046 p_repair_line_id IN NUMBER,
6047 x_return_status OUT NOCOPY VARCHAR2,
6048 x_msg_count OUT NOCOPY NUMBER,
6049 x_msg_data OUT NOCOPY VARCHAR2) IS
6050 l_api_name CONSTANT VARCHAR2(30) := 'VALIDATE_AND_WRITE';
6051 l_api_version CONSTANT NUMBER := 1.0;
6052 l_msg_count NUMBER;
6053 l_msg_data VARCHAR2(2000);
6054 l_msg_index NUMBER;
6055 l_return_status VARCHAR2(1);
6056 l_repair_history_id NUMBER;
6057 l_paramn1 NUMBER;
6058 l_paramn2 NUMBER;
6059 l_paramn3 NUMBER;
6060 l_paramn4 NUMBER;
6061 l_paramn5 NUMBER;
6062 l_paramc1 VARCHAR2(240);
6063 l_paramc2 VARCHAR2(240);
6064 l_paramc3 VARCHAR2(240);
6065 l_paramc4 VARCHAR2(240);
6066 l_paramc5 VARCHAR2(240);
6067 l_paramc6 VARCHAR2(240);
6068 l_paramd1 DATE;
6069 l_paramd2 DATE;
6070 l_paramd3 DATE;
6071 l_paramd4 DATE;
6072 l_event_code VARCHAR2(30) := 'TC'; -- Task Created
6073 l_check_task NUMBER;
6074 CURSOR c_task(p_task_id NUMBER, p_repair_line_id NUMBER) IS
6075 SELECT tsk.task_id, -- hist.paramn1
6076 tsk.last_updated_by, -- hist.paramn2
6077 tsk.owner_id, -- hist.paramn3
6078 tsk.assigned_by_id, -- hist.paramn4
6079 tsk.task_status_id, -- hist.paramn5
6080 tsk.task_number, -- hist.paramc1
6081 tsk.owner_type, -- hist.paramc2
6082 tsk.owner, -- hist.paramc3
6083 NULL assignee_type, -- hist.paramc4
6084 NULL assignee_name, -- hist.paramc5
6085 tsk.task_status, -- hist.paramc6
6086 tsk.planned_start_date, -- hist.paramd1
6087 tsk.actual_start_date, -- hist.paramd2
6088 tsk.actual_end_date, -- hist.paramd3
6089 tsk.last_update_date -- hist.paramd4
6090 FROM CSD_REPAIR_TASKS_V tsk
6091 WHERE tsk.source_object_type_code = 'DR'
6092 AND tsk.source_object_id = p_repair_line_id
6093 AND tsk.task_id = p_task_id;
6094 BEGIN
6095
6096 -- check if this task is saved in the repair history
6097 SELECT COUNT(*)
6098 INTO l_check_task
6099 FROM CSD_REPAIR_TASKS_V tsk, CSD_REPAIR_HISTORY hist
6100 WHERE tsk.source_object_id = hist.repair_line_id
6101 AND hist.paramn1 = p_task_id
6102 AND tsk.source_object_type_code = 'DR'
6103 AND hist.event_code = 'TC';
6104
6105 IF (l_check_task > 0)
6106 THEN
6107 IF (g_debug > 0)
6108 THEN
6109 Csd_Gen_Utility_Pvt.ADD('Task Exists in Repair History');
6110 END IF;
6111
6112 ELSE
6113 -- call the pub after assigning the required variable values
6114 OPEN c_task(p_task_id, p_repair_line_id);
6115
6116 -- dbms_output.put_line('Task Cursor fetches data');
6117 FETCH c_task
6118 INTO l_paramn1, -- task id
6119 l_paramn2, -- last updated by
6120 l_paramn3, -- owner id
6121 l_paramn4, -- assigned by id
6122 l_paramn5, -- status id
6123 l_paramc1, -- task number
6124 l_paramc2, -- owner type
6125 l_paramc3, -- owner name
6126 l_paramc4, -- null assignee type
6127 l_paramc5, -- null assignee name
6128 l_paramc6, -- status
6129 l_paramd1, -- planned start date
6130 l_paramd2, -- actual start date
6131 l_paramd3, -- actual end date
6132 l_paramd4; -- last updated date
6133 -- dbms_output.put_line('Task Cursor has no data');
6134
6135 CLOSE c_task;
6136 -- --------------------------------
6137 -- Begin create repair task history
6138 -- --------------------------------
6139 -- History : assignee_id --> assigned_by_id
6140 -- assignee_type --> null
6141 -- assignee_name --> null
6142
6143 -- Standard Start of API savepoint
6144 SAVEPOINT Create_repair_task_hist;
6145 -- Standard call to check for call compatibility.
6146 IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
6147 p_api_version,
6148 l_api_name,
6149 G_PKG_NAME)
6150 THEN
6151 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
6152 END IF;
6153 -- Initialize message list if p_init_msg_list is set to TRUE.
6154 IF Fnd_Api.to_Boolean(p_init_msg_list)
6155 THEN
6156 Fnd_Msg_Pub.initialize;
6157 END IF;
6158 -- Initialize API return status to success
6159 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
6160 -- ---------------
6161 -- Api body starts
6162 -- ---------------
6163 IF (g_debug > 0)
6164 THEN
6165 Csd_Gen_Utility_Pvt.ADD('Before Task to Repair History API call');
6166 END IF;
6167
6168 -- travi 020502 OBJECT_VERSION_NUMBER validation
6169
6170 -- ------------------------------------------------------
6171 -- Internal Private API call to write to Repair History
6172 -- ------------------------------------------------------
6173 Csd_To_Form_Repair_History.Validate_And_Write(p_Api_Version_Number => 1.0,
6174 p_init_msg_list => 'F',
6175 p_commit => 'F',
6176 p_validation_level => NULL,
6177 p_action_code => 0,
6178 px_REPAIR_HISTORY_ID => l_repair_history_id,
6179 p_OBJECT_VERSION_NUMBER => NULL,
6180 p_REQUEST_ID => NULL,
6181 p_PROGRAM_ID => NULL,
6182 p_PROGRAM_APPLICATION_ID => NULL,
6183 p_PROGRAM_UPDATE_DATE => NULL,
6184 p_CREATED_BY => Fnd_Global.USER_ID,
6185 p_CREATION_DATE => SYSDATE,
6186 p_LAST_UPDATED_BY => Fnd_Global.USER_ID,
6187 p_LAST_UPDATE_DATE => SYSDATE,
6188 p_repair_line_id => p_repair_line_id,
6189 p_EVENT_CODE => l_event_code,
6190 p_EVENT_DATE => SYSDATE,
6191 p_QUANTITY => NULL,
6192 p_PARAMN1 => l_paramn1,
6193 p_PARAMN2 => l_paramn2,
6194 p_PARAMN3 => l_paramn3,
6195 p_PARAMN4 => l_paramn4,
6196 p_PARAMN5 => l_paramn5,
6197 p_PARAMN6 => NULL,
6198 p_PARAMN7 => NULL,
6199 p_PARAMN8 => NULL,
6200 p_PARAMN9 => NULL,
6201 p_PARAMN10 => Fnd_Global.USER_ID,
6202 p_PARAMC1 => l_paramc1,
6203 p_PARAMC2 => l_paramc2,
6204 p_PARAMC3 => l_paramc3,
6205 p_PARAMC4 => l_paramc4,
6206 p_PARAMC5 => l_paramc5,
6207 p_PARAMC6 => l_paramc6,
6208 p_PARAMC7 => NULL,
6209 p_PARAMC8 => NULL,
6210 p_PARAMC9 => NULL,
6211 p_PARAMC10 => NULL,
6212 p_PARAMD1 => l_paramd1,
6213 p_PARAMD2 => l_paramd1,
6214 p_PARAMD3 => l_paramd1,
6215 p_PARAMD4 => l_paramd1,
6216 p_PARAMD5 => NULL,
6217 p_PARAMD6 => NULL,
6218 p_PARAMD7 => NULL,
6219 p_PARAMD8 => NULL,
6220 p_PARAMD9 => NULL,
6221 p_PARAMD10 => NULL,
6222 p_ATTRIBUTE_CATEGORY => NULL,
6223 p_ATTRIBUTE1 => NULL,
6224 p_ATTRIBUTE2 => NULL,
6225 p_ATTRIBUTE3 => NULL,
6226 p_ATTRIBUTE4 => NULL,
6227 p_ATTRIBUTE5 => NULL,
6228 p_ATTRIBUTE6 => NULL,
6229 p_ATTRIBUTE7 => NULL,
6230 p_ATTRIBUTE8 => NULL,
6231 p_ATTRIBUTE9 => NULL,
6232 p_ATTRIBUTE10 => NULL,
6233 p_ATTRIBUTE11 => NULL,
6234 p_ATTRIBUTE12 => NULL,
6235 p_ATTRIBUTE13 => NULL,
6236 p_ATTRIBUTE14 => NULL,
6237 p_ATTRIBUTE15 => NULL,
6238 p_LAST_UPDATE_LOGIN => Fnd_Global.CONC_LOGIN_ID,
6239 X_Return_Status => x_return_status,
6240 X_Msg_Count => x_msg_count,
6241 X_Msg_Data => x_msg_data);
6242 --
6243 IF (g_debug > 0)
6244 THEN
6245 Csd_Gen_Utility_Pvt.ADD('After Task to Repair History : ' ||
6246 x_return_status);
6247 END IF;
6248
6249 -- -------------------
6250 -- Api body ends here
6251 -- -------------------
6252 -- Standard check of p_commit.
6253 IF Fnd_Api.To_Boolean(p_commit)
6254 THEN
6255 COMMIT WORK;
6256 END IF;
6257
6258 -- Standard call to get message count and IF count is get message info.
6259 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6260 p_data => x_msg_data);
6261 END IF;
6262 EXCEPTION
6263 WHEN Fnd_Api.G_EXC_ERROR THEN
6264 ROLLBACK TO Create_repair_task_hist;
6265 x_return_status := Fnd_Api.G_RET_STS_ERROR;
6266 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6267 p_data => x_msg_data);
6268 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
6269 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
6270 ROLLBACK TO Create_repair_task_hist;
6271 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6272 p_data => x_msg_data);
6273 WHEN OTHERS THEN
6274 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
6275 ROLLBACK TO Create_repair_task_hist;
6276 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
6277 THEN
6278 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
6279 END IF;
6280 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6281 p_data => x_msg_data);
6282 END Create_repair_task_hist;
6283
6284 /*-----------------------------------------------------------------------------------------------------------*/
6285 /* procedure name: Update_repair_task_hist */
6286 /* description : procedure used to Update Repair Order history */
6287 /* for task creation */
6288 /* Called from : Depot Repair Form to update to Repair history */
6289 /* Input Parm : p_api_version NUMBER Required Api Version number */
6290 /* p_init_msg_list VARCHAR2 Optional Initializes message stack if fnd_api.g_true, */
6291 /* default value is fnd_api.g_false */
6292 /* p_commit VARCHAR2 Optional Commits in API if fnd_api.g_true, default */
6293 /* fnd_api.g_false */
6294 /* p_validation_level NUMBER Optional API uses this parameter to determine which */
6295 /* validation steps must be done and which steps */
6296 /* should be skipped. */
6297 /* p_task_id NUMBER Required Task Id */
6298 /* p_repair_line_id NUMBER Required Repair_line_id */
6299 /* Output Parm : x_return_status VARCHAR2 Return status after the call. The status can be*/
6300 /* fnd_api.g_ret_sts_success (success) */
6301 /* fnd_api.g_ret_sts_error (error) */
6302 /* fnd_api.g_ret_sts_unexp_error (unexpected) */
6303 /* x_msg_count NUMBER Number of messages in the message stack */
6304 /* x_msg_data VARCHAR2 Message text if x_msg_count >= 1 */
6305 /*-----------------------------------------------------------------------------------------------------------*/
6306 /*
6307 PROCEDURE Update_repair_task_hist
6308 ( p_api_version IN NUMBER,
6309 p_init_msg_list IN VARCHAR2 := fnd_api.g_true,
6310 p_commit IN VARCHAR2 := fnd_api.g_false,
6311 p_validation_level IN NUMBER := fnd_api.g_valid_level_full,
6312 p_task_id IN NUMBER,
6313 p_repair_line_id IN NUMBER,
6314 x_return_status OUT NOCOPY VARCHAR2,
6315 x_msg_count OUT NOCOPY NUMBER,
6316 x_msg_data OUT NOCOPY VARCHAR2
6317 )
6318 IS
6319 l_api_name CONSTANT VARCHAR2(30) := 'VALIDATE_AND_WRITE';
6320 l_api_version CONSTANT NUMBER := 1.0;
6321 l_msg_count NUMBER;
6322 l_msg_data VARCHAR2(2000);
6323 l_msg_index NUMBER;
6324 l_return_status VARCHAR2(1);
6325 l_repair_history_id NUMBER;
6326 l_paramn1 NUMBER;
6327 l_paramn2 NUMBER;
6328 l_paramn3 NUMBER;
6329 l_paramn4 NUMBER;
6330 l_paramn5 NUMBER;
6331 l_paramc1 VARCHAR2(240);
6332 l_paramc2 VARCHAR2(240);
6333 l_paramc3 VARCHAR2(240);
6334 l_paramc4 VARCHAR2(240);
6335 l_paramc5 VARCHAR2(240);
6336 l_paramc6 VARCHAR2(240);
6337 l_paramd1 DATE;
6338 l_paramd2 DATE;
6339 l_paramd3 DATE;
6340 l_paramd4 DATE;
6341 l_event_code VARCHAR2(30) := '';
6342 l_hist_ec VARCHAR2(30);
6343 l_owner_type VARCHAR2(240);
6344 l_owner VARCHAR2(240);
6345 l_assignee_type VARCHAR2(240);
6346 l_assignee_name VARCHAR2(240);
6347 l_task_status VARCHAR2(240);
6348 l_check_id NUMBER;
6349 l_check_code VARCHAR2(30);
6350
6351 CURSOR c_task_hist(p_task_id NUMBER, p_repair_line_id NUMBER) IS
6352 SELECT hist.event_code,
6353 hist.paramc2, -- tsk.owner_type
6354 hist.paramc3, -- tsk.owner
6355 null paramc4, -- tsk.assignee_type
6356 null paramc5, -- tsk.assignee_name
6357 hist.paramc6 -- tsk.task_status
6358 FROM CSD_REPAIR_HISTORY hist
6359 WHERE hist.paramn1 = p_task_id
6360 AND hist.repair_line_id = p_repair_line_id
6361 --and hist.event_code = 'TC'
6362 ORDER BY hist.repair_history_id DESC;
6363
6364 CURSOR c_task(p_task_id NUMBER, p_repair_line_id NUMBER) IS
6365 SELECT tsk.task_id, -- hist.paramn1
6366 tsk.last_updated_by, -- hist.paramn2
6367 tsk.owner_id, -- hist.paramn3
6368 tsk.assigned_by_id, -- hist.paramn4
6369 tsk.task_status_id, -- hist.paramn5
6370 tsk.task_number, -- hist.paramc1
6371 tsk.owner_type, -- hist.paramc2
6372 tsk.owner, -- hist.paramc3
6373 null assignee_type, -- hist.paramc4
6374 null assignee_name, -- hist.paramc5
6375 tsk.task_status, -- hist.paramc6
6376 tsk.planned_start_date, -- hist.paramd1
6377 tsk.actual_start_date, -- hist.paramd2
6378 tsk.actual_end_date, -- hist.paramd3
6379 tsk.last_update_date -- hist.paramd4
6380 FROM CSD_REPAIR_TASKS_V tsk
6381 WHERE tsk.source_object_type_code = 'DR'
6382 AND tsk.source_object_id = p_repair_line_id
6383 AND tsk.task_id = p_task_id;
6384
6385 BEGIN
6386 -- History : assignee_id --> assigned_by_id
6387 -- assignee_type --> null
6388 -- assignee_name --> null
6389 -- check if this task creation / update is saved in the repair history
6390 SELECT COUNT(*)
6391 INTO l_check_id
6392 FROM CSD_REPAIR_TASKS_V tsk,
6393 CSD_REPAIR_HISTORY hist
6394 WHERE tsk.source_object_id = p_repair_line_id
6395 AND hist.paramn1 = p_task_id
6396 AND tsk.task_id = hist.paramn1
6397 AND tsk.source_object_id = hist.repair_line_id
6398 AND tsk.source_object_type_code = 'DR';
6399
6400 OPEN c_task(p_task_id, p_repair_line_id);
6401
6402 FETCH c_task
6403 INTO l_paramn1, -- task id
6404 l_paramn2, -- last updated by
6405 l_paramn3, -- owner id
6406 l_paramn4, -- assigned by id
6407 l_paramn5, -- status id
6408 l_paramc1, -- task number
6409 l_paramc2, -- owner type
6410 l_paramc3, -- owner name
6411 l_paramc4, -- null assignee type
6412 l_paramc5, -- null assignee name
6413 l_paramc6, -- status
6414 l_paramd1, -- planned start date
6415 l_paramd2, -- actual start date
6416 l_paramd3, -- actual end date
6417 l_paramd4; -- last updated date
6418 CLOSE c_task;
6419 -- TC Exists in Repair History
6420 -- add the update TOC/TSC line to Repair history
6421 -- ----------------------------------------------
6422 IF (l_check_id >= 1) THEN
6423 IF (g_debug > 0 ) THEN
6424 csd_gen_utility_pvt.ADD('TC and/or TOC/TSC Exists in Repair History');
6425 END IF;
6426
6427 -- pick latest row from Repair history
6428 OPEN c_task_hist(p_task_id, p_repair_line_id);
6429
6430 FETCH c_task_hist
6431 INTO l_hist_ec,
6432 l_owner_type,
6433 l_owner,
6434 l_assignee_type,
6435 l_assignee_name,
6436 l_task_status;
6437
6438 CLOSE c_task_hist;
6439 -- check the row in history against the row in tasks
6440 -- for updates to Owner or Status
6441 -- check if Status has changed
6442 IF (l_task_status <> l_paramc6) THEN
6443 -- insert Status change into Repair history
6444 l_event_code := 'TSC';
6445 -- check if Owner has changed
6446 ELSIF (l_owner <> l_paramc3) THEN
6447 -- insert Owner change into Repair history
6448 l_event_code := 'TOC';
6449 ELSE
6450 -- NO insert for this change into Repair history
6451 l_event_code := '';
6452 END IF;
6453 END IF; -- check for l_check_id
6454 -- ----------------------------------------------
6455 -- ---------------------------------------------------------
6456 -- Repair history row inserted for TOC or TSC only
6457 -- ---------------------------------------------------------
6458 IF (l_event_code IN ('TOC', 'TSC')) THEN
6459 -- --------------------------------
6460 -- Begin create repair task history
6461 -- --------------------------------
6462 -- Standard Start of API savepoint
6463 SAVEPOINT Update_repair_task_hist;
6464 -- Standard call to check for call compatibility.
6465 IF NOT FND_API.Compatible_API_Call (l_api_version,
6466 p_api_version,
6467 l_api_name ,
6468 G_PKG_NAME )
6469 THEN
6470 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6471 END IF;
6472 -- Initialize message list if p_init_msg_list is set to TRUE.
6473 IF FND_API.to_Boolean( p_init_msg_list ) THEN
6474 FND_MSG_PUB.initialize;
6475 END IF;
6476 -- Initialize API return status to success
6477 x_return_status := FND_API.G_RET_STS_SUCCESS;
6478 -- ---------------
6479 -- Api body starts
6480 -- ---------------
6481 IF (g_debug > 0 ) THEN
6482 csd_gen_utility_pvt.ADD('Before Task to Update Repair History');
6483 END IF;
6484
6485
6486 -- travi 020502 OBJECT_VERSION_NUMBER validation
6487
6488 -- ------------------------------------------------------
6489 -- Internal Private API call to write to Repair History
6490 -- ------------------------------------------------------
6491 CSD_TO_FORM_REPAIR_HISTORY.Validate_And_Write
6492 (p_Api_Version_Number => 1.0 ,
6493 p_init_msg_list => 'F',
6494 p_commit => 'F',
6495 p_validation_level => NULL,
6496 p_action_code => 0,
6497 px_REPAIR_HISTORY_ID => l_repair_history_id,
6498 p_OBJECT_VERSION_NUMBER => NULL,
6499 p_REQUEST_ID => NULL,
6500 p_PROGRAM_ID => NULL,
6501 p_PROGRAM_APPLICATION_ID => NULL,
6502 p_PROGRAM_UPDATE_DATE => NULL,
6503 p_CREATED_BY => FND_GLOBAL.USER_ID,
6504 p_CREATION_DATE => SYSDATE,
6505 p_LAST_UPDATED_BY => FND_GLOBAL.USER_ID,
6506 p_LAST_UPDATE_DATE => SYSDATE,
6507 p_repair_line_id => p_repair_line_id,
6508 p_EVENT_CODE => l_event_code,
6509 p_EVENT_DATE => SYSDATE,
6510 p_QUANTITY => NULL,
6511 p_PARAMN1 => l_paramn1,
6512 p_PARAMN2 => l_paramn2,
6513 p_PARAMN3 => l_paramn3,
6514 p_PARAMN4 => l_paramn4,
6515 p_PARAMN5 => l_paramn5,
6516 p_PARAMN6 => NULL,
6517 p_PARAMN7 => NULL,
6518 p_PARAMN8 => NULL,
6519 p_PARAMN9 => NULL,
6520 p_PARAMN10 => FND_GLOBAL.USER_ID,
6521 p_PARAMC1 => l_paramc1,
6522 p_PARAMC2 => l_paramc2,
6523 p_PARAMC3 => l_paramc3,
6524 p_PARAMC4 => l_paramc4,
6525 p_PARAMC5 => l_paramc5,
6526 p_PARAMC6 => l_paramc6,
6527 p_PARAMC7 => NULL,
6528 p_PARAMC8 => NULL,
6529 p_PARAMC9 => NULL,
6530 p_PARAMC10 => NULL,
6531 p_PARAMD1 => l_paramd1,
6532 p_PARAMD2 => l_paramd1,
6533 p_PARAMD3 => l_paramd1,
6534 p_PARAMD4 => l_paramd1,
6535 p_PARAMD5 => NULL,
6536 p_PARAMD6 => NULL,
6537 p_PARAMD7 => NULL,
6538 p_PARAMD8 => NULL,
6539 p_PARAMD9 => NULL,
6540 p_PARAMD10 => NULL,
6541 p_ATTRIBUTE_CATEGORY => NULL,
6542 p_ATTRIBUTE1 => NULL,
6543 p_ATTRIBUTE2 => NULL,
6544 p_ATTRIBUTE3 => NULL,
6545 p_ATTRIBUTE4 => NULL,
6546 p_ATTRIBUTE5 => NULL,
6547 p_ATTRIBUTE6 => NULL,
6548 p_ATTRIBUTE7 => NULL,
6549 p_ATTRIBUTE8 => NULL,
6550 p_ATTRIBUTE9 => NULL,
6551 p_ATTRIBUTE10 => NULL,
6552 p_ATTRIBUTE11 => NULL,
6553 p_ATTRIBUTE12 => NULL,
6554 p_ATTRIBUTE13 => NULL,
6555 p_ATTRIBUTE14 => NULL,
6556 p_ATTRIBUTE15 => NULL,
6557 p_LAST_UPDATE_LOGIN => FND_GLOBAL.CONC_LOGIN_ID,
6558 X_Return_Status => x_return_status,
6559 X_Msg_Count => x_msg_count,
6560 X_Msg_Data => x_msg_data
6561 );
6562 --
6563 IF (g_debug > 0 ) THEN
6564 csd_gen_utility_pvt.ADD('After Task to Update Repair History : '||x_return_status);
6565 END IF;
6566
6567 -- -------------------
6568 -- Api body ends here
6569 -- -------------------
6570 -- Standard check of p_commit.
6571 IF FND_API.To_Boolean( p_commit ) THEN
6572 COMMIT WORK;
6573 END IF;
6574 -- Standard call to get message count and IF count is get message info.
6575 FND_MSG_PUB.Count_And_Get
6576 (p_count => x_msg_count,
6577 p_data => x_msg_data );
6578 END IF;
6579 -- ---------------------------------------------------------
6580 EXCEPTION
6581 WHEN FND_API.G_EXC_ERROR THEN
6582 ROLLBACK TO Update_repair_task_hist;
6583 x_return_status := FND_API.G_RET_STS_ERROR ;
6584 FND_MSG_PUB.Count_And_Get
6585 (p_count => x_msg_count,
6586 p_data => x_msg_data
6587 );
6588 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6589 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6590 ROLLBACK TO Update_repair_task_hist;
6591 FND_MSG_PUB.Count_And_Get
6592 ( p_count => x_msg_count,
6593 p_data => x_msg_data
6594 );
6595 WHEN OTHERS THEN
6596 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6597 ROLLBACK TO Update_repair_task_hist;
6598 IF FND_MSG_PUB.Check_Msg_Level
6599 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6600 THEN
6601 FND_MSG_PUB.Add_Exc_Msg
6602 (G_PKG_NAME ,
6603 l_api_name );
6604 END IF;
6605 FND_MSG_PUB.Count_And_Get
6606 (p_count => x_msg_count,
6607 p_data => x_msg_data );
6608 END Update_repair_task_hist;
6609 */
6610 -------------------- travi changes-------------
6611
6612 PROCEDURE Create_repair_task_hist(p_api_version IN NUMBER,
6613 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_true,
6614 p_commit IN VARCHAR2 := Fnd_Api.g_false,
6615 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
6616 p_task_activity_rec IN Csd_Process_Pvt.TASK_ACTIVITY_REC,
6617 x_return_status OUT NOCOPY VARCHAR2,
6618 x_msg_count OUT NOCOPY NUMBER,
6619 x_msg_data OUT NOCOPY VARCHAR2)
6620
6621 IS
6622 l_api_name CONSTANT VARCHAR2(30) := 'VALIDATE_AND_WRITE';
6623 l_api_version CONSTANT NUMBER := 1.0;
6624 l_msg_count NUMBER;
6625 l_msg_data VARCHAR2(2000);
6626 l_msg_index NUMBER;
6627 l_return_status VARCHAR2(1);
6628 l_repair_history_id NUMBER;
6629 l_owner_type VARCHAR2(240);
6630 l_owner VARCHAR2(240);
6631 l_assignee_type VARCHAR2(240);
6632 l_assignee_name VARCHAR2(240);
6633 l_task_status VARCHAR2(240);
6634 l_last_updated_by NUMBER;
6635 l_assigned_by_id NUMBER;
6636 l_task_number VARCHAR2(240);
6637 l_task_name VARCHAR2(240);
6638 l_planned_start_Date DATE;
6639 l_actual_start_Date DATE;
6640 l_actual_end_Date DATE;
6641 l_last_update_date DATE;
6642 l_event_code VARCHAR2(30) := 'TC'; -- Task Created
6643 l_check_task NUMBER;
6644
6645 /*CURSOR c_task(p_task_id NUMBER, p_repair_line_id NUMBER) IS
6646 SELECT tsk.task_id, -- hist.paramn1
6647 tsk.last_updated_by, -- hist.paramn2
6648 tsk.owner_id, -- hist.paramn3
6649 tsk.assigned_by_id, -- hist.paramn4
6650 tsk.task_status_id, -- hist.paramn5
6651 tsk.task_number, -- hist.paramc1
6652 tsk.owner_type, -- hist.paramc2
6653 tsk.owner, -- hist.paramc3
6654 --null assignee_type, -- hist.paramc4
6655 --null assignee_name, -- hist.paramc5
6656 tsk.task_status, -- hist.paramc6
6657 tsk.task_name, -- hist.paramc7
6658 tsk.planned_start_date, -- hist.paramd1
6659 tsk.actual_start_date, -- hist.paramd2
6660 tsk.actual_end_date, -- hist.paramd3
6661 tsk.last_update_date -- hist.paramd4
6662
6663 FROM CSD_REPAIR_TASKS_V tsk
6664 WHERE tsk.source_object_type_code = 'DR'
6665 AND tsk.source_object_id = p_repair_line_id
6666 AND tsk.task_id = p_task_id;*/
6667
6668 CURSOR c_task(p_task_id NUMBER, p_repair_line_id NUMBER) IS
6669 SELECT
6670
6671 tsk.last_updated_by, -- hist.paramn2
6672
6673 tsk.assigned_by_id, -- hist.paramn4
6674
6675 tsk.task_number, -- hist.paramc1
6676 tsk.task_name,
6677
6678 tsk.planned_start_date, -- hist.paramd1
6679 tsk.actual_start_date, -- hist.paramd2
6680 tsk.actual_end_date, -- hist.paramd3
6681 tsk.last_update_date -- hist.paramd4
6682 FROM CSD_REPAIR_TASKS_V tsk
6683 WHERE tsk.source_object_type_code = 'DR'
6684 AND tsk.source_object_id = p_repair_line_id
6685 AND tsk.task_id = p_task_id;
6686
6687 BEGIN
6688
6689 -- check if this task is saved in the repair history
6690 SELECT COUNT(*)
6691 INTO l_check_task
6692 FROM CSD_REPAIR_TASKS_V tsk, CSD_REPAIR_HISTORY hist
6693 WHERE tsk.source_object_id = hist.repair_line_id
6694 AND hist.paramn1 = p_task_activity_rec.task_id
6695 AND tsk.source_object_type_code = 'DR'
6696 AND hist.event_code = 'TC';
6697
6698 IF (l_check_task > 0)
6699 THEN
6700 IF (g_debug > 0)
6701 THEN
6702 Csd_Gen_Utility_Pvt.ADD('Task Exists in Repair History');
6703 END IF;
6704
6705 ELSE
6706 -- call the pub after assigning the required variable values
6707 OPEN c_task(p_task_activity_rec.task_id,
6708 p_task_activity_rec.repair_line_id);
6709
6710 -- dbms_output.put_line('Task Cursor fetches data');
6711 FETCH c_task
6712 INTO
6713
6714 l_last_updated_by, -- last updated by
6715 l_assigned_by_id, -- assigned by id
6716 l_task_number, -- task number
6717 l_task_name, -- task name
6718 l_planned_start_Date, -- planned start date
6719 l_actual_start_Date, -- actual start date
6720 l_actual_end_Date, -- actual end date
6721 l_last_update_date; -- last updated date
6722
6723 /* l_paramn1, -- task id
6724 l_paramn2, -- last updated by
6725 l_paramn3, -- owner id
6726 l_paramn4, -- assigned by id
6727 l_paramn5, -- status id
6728 l_paramc1, -- task number
6729 l_paramc2, -- owner type sangiguptask
6730 l_paramc3, -- owner name
6731 --l_paramc4, -- null assignee type
6732 -- l_paramc5, -- null assignee name
6733 l_paramc6, -- status
6734 l_paramc7, -- task name
6735 l_paramd1, -- planned start date
6736 l_paramd2, -- actual start date
6737 l_paramd3, -- actual end date
6738 l_paramd4-- last updated date;*/
6739
6740 -- dbms_output.put_line('Task Cursor has no data');
6741
6742 CLOSE c_task;
6743
6744 -- --------------------------------
6745 -- Begin create repair task history
6746 -- --------------------------------
6747
6748 -- Standard Start of API savepoint
6749 SAVEPOINT Create_repair_task_hist;
6750 -- Standard call to check for call compatibility.
6751 IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
6752 p_api_version,
6753 l_api_name,
6754 G_PKG_NAME)
6755 THEN
6756 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
6757 END IF;
6758 -- Initialize message list if p_init_msg_list is set to TRUE.
6759 IF Fnd_Api.to_Boolean(p_init_msg_list)
6760 THEN
6761 Fnd_Msg_Pub.initialize;
6762 END IF;
6763 -- Initialize API return status to success
6764 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
6765 -- ---------------
6766 -- Api body starts
6767 -- ---------------
6768 IF (g_debug > 0)
6769 THEN
6770 Csd_Gen_Utility_Pvt.ADD('Before Task to Repair History API call');
6771 END IF;
6772
6773 -- travi 020502 OBJECT_VERSION_NUMBER validation
6774
6775 -- ------------------------------------------------------
6776 -- Internal Private API call to write to Repair History
6777 -- ------------------------------------------------------
6778 Csd_To_Form_Repair_History.Validate_And_Write(p_Api_Version_Number => 1.0,
6779 p_init_msg_list => 'F',
6780 p_commit => 'F',
6781 p_validation_level => NULL,
6782 p_action_code => 0,
6783 px_REPAIR_HISTORY_ID => l_repair_history_id,
6784 p_OBJECT_VERSION_NUMBER => NULL,
6785 p_REQUEST_ID => NULL,
6786 p_PROGRAM_ID => NULL,
6787 p_PROGRAM_APPLICATION_ID => NULL,
6788 p_PROGRAM_UPDATE_DATE => NULL,
6789 p_CREATED_BY => Fnd_Global.USER_ID,
6790 p_CREATION_DATE => SYSDATE,
6791 p_LAST_UPDATED_BY => Fnd_Global.USER_ID,
6792 p_LAST_UPDATE_DATE => SYSDATE,
6793 p_repair_line_id => p_task_activity_rec.repair_line_id,
6794 p_EVENT_CODE => l_event_code,
6795 p_EVENT_DATE => SYSDATE,
6796 p_QUANTITY => NULL,
6797 p_PARAMN1 => p_task_activity_rec.task_id, --task id,
6798 p_PARAMN2 => l_last_updated_by, --l_paramn2,
6799 p_PARAMN3 => p_task_activity_rec.new_owner_id, --l_paramn3,
6800 p_PARAMN4 => l_assigned_by_id, --l_paramn4,
6801 p_PARAMN5 => p_task_activity_rec.new_status_id, --l_paramn5,
6802 p_PARAMN6 => p_task_activity_rec.new_resource_id, --l_paramn6,--assignee_id
6803 p_PARAMN7 => NULL,
6804 p_PARAMN8 => NULL,
6805 p_PARAMN9 => NULL,
6806 p_PARAMN10 => Fnd_Global.USER_ID,
6807 p_PARAMC1 => l_task_number,
6808 p_PARAMC2 => p_task_activity_rec.new_owner_type_code,
6809 p_PARAMC3 => p_task_activity_rec.new_owner_name,
6810 p_PARAMC4 => p_task_activity_rec.new_resource_type_code, --resource_type_code sangiguptask
6811 p_PARAMC5 => p_task_activity_rec.new_resource_name, --assignee_name sangiguptask
6812 p_PARAMC6 => p_task_activity_rec.new_status, --task status
6813 p_PARAMC7 => l_task_name, --task name sangiguptask
6814 p_PARAMC8 => NULL,
6815 p_PARAMC9 => NULL,
6816 p_PARAMC10 => NULL, -- split from rep line number sangiguptask
6817 p_PARAMD1 => l_planned_start_Date, -- planned start date
6818 p_PARAMD2 => l_actual_start_Date,
6819 p_PARAMD3 => l_actual_end_Date,
6820 p_PARAMD4 => l_last_update_date,
6821 p_PARAMD5 => NULL,
6822 p_PARAMD6 => NULL,
6823 p_PARAMD7 => NULL,
6824 p_PARAMD8 => NULL,
6825 p_PARAMD9 => NULL,
6826 p_PARAMD10 => NULL,
6827 p_ATTRIBUTE_CATEGORY => NULL,
6828 p_ATTRIBUTE1 => NULL,
6829 p_ATTRIBUTE2 => NULL,
6830 p_ATTRIBUTE3 => NULL,
6831 p_ATTRIBUTE4 => NULL,
6832 p_ATTRIBUTE5 => NULL,
6833 p_ATTRIBUTE6 => NULL,
6834 p_ATTRIBUTE7 => NULL,
6835 p_ATTRIBUTE8 => NULL,
6836 p_ATTRIBUTE9 => NULL,
6837 p_ATTRIBUTE10 => NULL,
6838 p_ATTRIBUTE11 => NULL,
6839 p_ATTRIBUTE12 => NULL,
6840 p_ATTRIBUTE13 => NULL,
6841 p_ATTRIBUTE14 => NULL,
6842 p_ATTRIBUTE15 => NULL,
6843 p_LAST_UPDATE_LOGIN => Fnd_Global.CONC_LOGIN_ID,
6844 X_Return_Status => x_return_status,
6845 X_Msg_Count => x_msg_count,
6846 X_Msg_Data => x_msg_data);
6847 --
6848 IF (g_debug > 0)
6849 THEN
6850 Csd_Gen_Utility_Pvt.ADD('After Task to Repair History : ' ||
6851 x_return_status);
6852 END IF;
6853
6854 -- -------------------
6855 -- Api body ends here
6856 -- -------------------
6857 -- Standard check of p_commit.
6858 IF Fnd_Api.To_Boolean(p_commit)
6859 THEN
6860 COMMIT WORK;
6861 END IF;
6862
6863 -- Standard call to get message count and IF count is get message info.
6864 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6865 p_data => x_msg_data);
6866 END IF;
6867 EXCEPTION
6868 WHEN Fnd_Api.G_EXC_ERROR THEN
6869 ROLLBACK TO Create_repair_task_hist;
6870 x_return_status := Fnd_Api.G_RET_STS_ERROR;
6871 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6872 p_data => x_msg_data);
6873 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
6874 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
6875 ROLLBACK TO Create_repair_task_hist;
6876 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6877 p_data => x_msg_data);
6878 WHEN OTHERS THEN
6879 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
6880 ROLLBACK TO Create_repair_task_hist;
6881 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
6882 THEN
6883 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
6884 END IF;
6885 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6886 p_data => x_msg_data);
6887 END Create_repair_task_hist;
6888
6889 /*-----------------------------------------------------------------------------------------------------------*/
6890 /* procedure name: Update_repair_task_hist */
6891 /* description : procedure used to Update Repair Order history */
6892 /* for task creation */
6893 /* Called from : Depot Repair Form to update to Repair history */
6894 /* Input Parm : p_api_version NUMBER Required Api Version number */
6895 /* p_init_msg_list VARCHAR2 Optional Initializes message stack if fnd_api.g_true, */
6896 /* default value is fnd_api.g_false */
6897 /* p_commit VARCHAR2 Optional Commits in API if fnd_api.g_true, default */
6898 /* fnd_api.g_false */
6899 /* p_validation_level NUMBER Optional API uses this parameter to determine which */
6900 /* validation steps must be done and which steps */
6901 /* should be skipped. */
6902 /* p_task_id NUMBER Required Task Id */
6903 /* p_repair_line_id NUMBER Required Repair_line_id */
6904 /* Output Parm : x_return_status VARCHAR2 Return status after the call. The status can be*/
6905 /* fnd_api.g_ret_sts_success (success) */
6906 /* fnd_api.g_ret_sts_error (error) */
6907 /* fnd_api.g_ret_sts_unexp_error (unexpected) */
6908 /* x_msg_count NUMBER Number of messages in the message stack */
6909 /* x_msg_data VARCHAR2 Message text if x_msg_count >= 1 */
6910 /*-----------------------------------------------------------------------------------------------------------*/
6911
6912 PROCEDURE Update_repair_task_hist(p_api_version IN NUMBER,
6913 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_true,
6914 p_commit IN VARCHAR2 := Fnd_Api.g_false,
6915 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
6916 p_task_activity_rec IN Csd_Process_Pvt.TASK_ACTIVITY_REC,
6917 x_return_status OUT NOCOPY VARCHAR2,
6918 x_msg_count OUT NOCOPY NUMBER,
6919 x_msg_data OUT NOCOPY VARCHAR2) IS
6920 l_api_name CONSTANT VARCHAR2(30) := 'VALIDATE_AND_WRITE';
6921 l_api_version CONSTANT NUMBER := 1.0;
6922 l_msg_count NUMBER;
6923 l_msg_data VARCHAR2(2000);
6924 l_msg_index NUMBER;
6925 l_return_status VARCHAR2(1);
6926 l_repair_history_id NUMBER;
6927 l_event_code VARCHAR2(30);
6928 l_hist_ec VARCHAR2(30);
6929 l_owner_type VARCHAR2(240);
6930 l_owner VARCHAR2(240);
6931 l_assignee_type VARCHAR2(240);
6932 l_assignee_name VARCHAR2(240);
6933 l_task_status VARCHAR2(240);
6934 l_last_updated_by NUMBER;
6935 l_assigned_by_id NUMBER;
6936 l_task_number VARCHAR2(240);
6937 l_task_name VARCHAR2(240);
6938 l_planned_start_Date DATE;
6939 l_actual_start_Date DATE;
6940 l_actual_end_Date DATE;
6941 l_last_update_date DATE;
6942
6943 CURSOR c_task_hist(p_task_id NUMBER, p_repair_line_id NUMBER) IS
6944 SELECT hist.event_code,
6945 hist.paramc2, -- owner type/assignee type(TAC)
6946 hist.paramc3, -- tsk.owner name/assignee name (TAC)
6947 hist.paramc4, -- assignee_type/previous assignee type (TAC)
6948 hist.paramc5, -- tsk.assignee_name/prev task assignee name (TAC)
6949 hist.paramc6, -- task status/null (TAC)
6950 hist.paramn3, -- task owner id/assignee isd (TAC)
6951 hist.paramn5, --status id/null (TAC)
6952 hist.paramn6 -- tsk.assignee_id (TAC)
6953 FROM CSD_REPAIR_HISTORY hist
6954 WHERE hist.paramn1 = p_task_id
6955 AND hist.repair_line_id = p_repair_line_id
6956 --and hist.event_code = 'TC'
6957 ORDER BY hist.repair_history_id DESC;
6958
6959 CURSOR c_task(p_task_id NUMBER, p_repair_line_id NUMBER) IS
6960 SELECT
6961
6962 tsk.last_updated_by, -- hist.paramn2
6963
6964 tsk.assigned_by_id, -- hist.paramn4
6965
6966 tsk.task_number, -- hist.paramc1
6967 tsk.task_name,
6968
6969 tsk.planned_start_date, -- hist.paramd1
6970 tsk.actual_start_date, -- hist.paramd2
6971 tsk.actual_end_date, -- hist.paramd3
6972 tsk.last_update_date -- hist.paramd4
6973 FROM CSD_REPAIR_TASKS_V tsk
6974 WHERE tsk.source_object_type_code = 'DR'
6975 AND tsk.source_object_id = p_repair_line_id
6976 AND tsk.task_id = p_task_id;
6977
6978 BEGIN
6979 -- --------------------------------
6980 -- Begin create repair task history
6981 -- --------------------------------
6982 -- Standard Start of API savepoint
6983 SAVEPOINT Update_repair_task_hist;
6984 -- Standard call to check for call compatibility.
6985 IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
6986 p_api_version,
6987 l_api_name,
6988 G_PKG_NAME)
6989 THEN
6990 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
6991 END IF;
6992 -- Initialize message list if p_init_msg_list is set to TRUE.
6993 IF Fnd_Api.to_Boolean(p_init_msg_list)
6994 THEN
6995 Fnd_Msg_Pub.initialize;
6996 END IF;
6997 -- Initialize API return status to success
6998 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
6999 -- ---------------
7000 -- Api body starts
7001 -- ---------------
7002 -- if any of the values (Assignee, owner,status) have chnaged then proceed else get out
7003 IF (p_task_activity_rec.old_status_id <>
7004 p_task_activity_rec.new_status_id OR
7005 p_task_activity_rec.old_resource_id <>
7006 p_task_activity_rec.new_resource_id OR
7007 p_task_activity_rec.old_owner_id <>
7008 p_task_activity_rec.new_owner_id)
7009 THEN
7010 --fetch the cursor in local variables
7011 OPEN c_task(p_task_activity_rec.task_id,
7012 p_task_activity_rec.repair_line_id);
7013
7014 FETCH c_task
7015 INTO l_last_updated_by, -- last updated by
7016 l_assigned_by_id, -- assigned by id
7017 l_task_number, -- task number
7018 l_task_name, -- task name
7019 l_planned_start_Date, -- planned start date
7020 l_actual_start_Date, -- actual start date
7021 l_actual_end_Date, -- actual end date
7022 l_last_update_date; -- last updated date
7023 CLOSE c_task;
7024 -- find out the events that need to be logged.
7025 --If old owner name is not the same as the new owner name, log the event TOC
7026 IF (p_task_activity_rec.new_owner_id <>
7027 p_task_activity_rec.old_owner_id)
7028 THEN
7029 l_event_Code := 'TOC';
7030 --log the activity
7031 -- ------------------------------------------------------
7032 -- Internal Private API call to write to Repair History
7033 -- ------------------------------------------------------
7034 Csd_To_Form_Repair_History.Validate_And_Write(p_Api_Version_Number => 1.0,
7035 p_init_msg_list => 'F',
7036 p_commit => 'F',
7037 p_validation_level => NULL,
7038 p_action_code => 0,
7039 px_REPAIR_HISTORY_ID => l_repair_history_id,
7040 p_OBJECT_VERSION_NUMBER => NULL,
7041 p_REQUEST_ID => NULL,
7042 p_PROGRAM_ID => NULL,
7043 p_PROGRAM_APPLICATION_ID => NULL,
7044 p_PROGRAM_UPDATE_DATE => NULL,
7045 p_CREATED_BY => Fnd_Global.USER_ID,
7046 p_CREATION_DATE => SYSDATE,
7047 p_LAST_UPDATED_BY => Fnd_Global.USER_ID,
7048 p_LAST_UPDATE_DATE => SYSDATE,
7049 p_repair_line_id => p_task_activity_rec.repair_line_id,
7050 p_EVENT_CODE => l_event_code,
7051 p_EVENT_DATE => SYSDATE,
7052 p_QUANTITY => NULL,
7053 p_PARAMN1 => p_task_activity_rec.task_id, -- task_id
7054 p_PARAMN2 => l_last_updated_by, -- last_updated_by
7055 p_PARAMN3 => p_task_Activity_rec.new_owner_id, -- owner_id
7056 p_PARAMN4 => l_assigned_by_id, -- assigned_by_id
7057 p_PARAMN5 => p_task_Activity_rec.new_status_id, --l_paramn5, -- status_id
7058 p_PARAMN6 => p_task_activity_rec.old_owner_id, -- assignee_id sangiguptask
7059 p_PARAMN7 => NULL,
7060 p_PARAMN8 => NULL,
7061 p_PARAMN9 => NULL,
7062 p_PARAMN10 => Fnd_Global.USER_ID,
7063 p_PARAMC1 => l_task_number, -- l_paramc1,-- task number
7064 p_PARAMC2 => p_task_activity_rec.new_owner_type_code, -- new owner type code
7065 p_PARAMC3 => p_task_activity_rec.new_owner_name, -- task owner name
7066 p_PARAMC4 => NULL, -- l_paramc4,-- asisgnee type
7067 p_PARAMC5 => NULL, -- assignee name
7068 p_PARAMC6 => p_task_activity_rec.new_status, -- task status
7069 p_PARAMC7 => l_task_name,
7070 p_PARAMC8 => p_task_activity_rec.old_owner_type_code, --prev owner type code
7071 p_PARAMC9 => p_task_activity_Rec.old_owner_name, -- prev task owner name
7072 p_PARAMC10 => NULL,
7073 p_PARAMD1 => l_planned_start_Date,
7074 p_PARAMD2 => l_actual_start_date,
7075 p_PARAMD3 => l_actual_end_date,
7076 p_PARAMD4 => l_last_update_Date,
7077 p_PARAMD5 => NULL,
7078 p_PARAMD6 => NULL,
7079 p_PARAMD7 => NULL,
7080 p_PARAMD8 => NULL,
7081 p_PARAMD9 => NULL,
7082 p_PARAMD10 => NULL,
7083 p_ATTRIBUTE_CATEGORY => NULL,
7084 p_ATTRIBUTE1 => NULL,
7085 p_ATTRIBUTE2 => NULL,
7086 p_ATTRIBUTE3 => NULL,
7087 p_ATTRIBUTE4 => NULL,
7088 p_ATTRIBUTE5 => NULL,
7089 p_ATTRIBUTE6 => NULL,
7090 p_ATTRIBUTE7 => NULL,
7091 p_ATTRIBUTE8 => NULL,
7092 p_ATTRIBUTE9 => NULL,
7093 p_ATTRIBUTE10 => NULL,
7094 p_ATTRIBUTE11 => NULL,
7095 p_ATTRIBUTE12 => NULL,
7096 p_ATTRIBUTE13 => NULL,
7097 p_ATTRIBUTE14 => NULL,
7098 p_ATTRIBUTE15 => NULL,
7099 p_LAST_UPDATE_LOGIN => Fnd_Global.CONC_LOGIN_ID,
7100 X_Return_Status => x_return_status,
7101 X_Msg_Count => x_msg_count,
7102 X_Msg_Data => x_msg_data);
7103
7104 END IF;
7105 --If old task status is not the same as the new task status , log the event TSC
7106 IF (p_task_activity_rec.new_status_id <>
7107 p_task_activity_rec.old_status_id)
7108 THEN
7109 l_event_Code := 'TSC';
7110 --log the activity
7111 -- ------------------------------------------------------
7112 -- Internal Private API call to write to Repair History
7113 -- ------------------------------------------------------
7114 Csd_To_Form_Repair_History.Validate_And_Write(p_Api_Version_Number => 1.0,
7115 p_init_msg_list => 'F',
7116 p_commit => 'F',
7117 p_validation_level => NULL,
7118 p_action_code => 0,
7119 px_REPAIR_HISTORY_ID => l_repair_history_id,
7120 p_OBJECT_VERSION_NUMBER => NULL,
7121 p_REQUEST_ID => NULL,
7122 p_PROGRAM_ID => NULL,
7123 p_PROGRAM_APPLICATION_ID => NULL,
7124 p_PROGRAM_UPDATE_DATE => NULL,
7125 p_CREATED_BY => Fnd_Global.USER_ID,
7126 p_CREATION_DATE => SYSDATE,
7127 p_LAST_UPDATED_BY => Fnd_Global.USER_ID,
7128 p_LAST_UPDATE_DATE => SYSDATE,
7129 p_repair_line_id => p_task_activity_rec.repair_line_id,
7130 p_EVENT_CODE => l_event_code,
7131 p_EVENT_DATE => SYSDATE,
7132 p_QUANTITY => NULL,
7133 p_PARAMN1 => p_task_activity_rec.task_id, -- task_id
7134 p_PARAMN2 => l_last_updated_by, -- last_updated_by
7135 p_PARAMN3 => p_task_Activity_rec.new_owner_id, -- owner_id
7136 p_PARAMN4 => l_assigned_by_id, -- assigned_by_id
7137 p_PARAMN5 => p_task_Activity_rec.new_status_id, --l_paramn5, -- status_id
7138 p_PARAMN6 => p_task_activity_rec.old_status_id,
7139 p_PARAMN7 => NULL,
7140 p_PARAMN8 => NULL,
7141 p_PARAMN9 => NULL,
7142 p_PARAMN10 => Fnd_Global.USER_ID,
7143 p_PARAMC1 => l_task_number, -- task number
7144 p_PARAMC2 => p_task_activity_rec.new_owner_type_code, -- new owner type code
7145 p_PARAMC3 => p_task_activity_rec.new_owner_name, -- task owner name
7146 p_PARAMC4 => NULL, -- asisgnee type
7147 p_PARAMC5 => NULL, -- assignee name
7148 p_PARAMC6 => p_task_activity_rec.new_status, -- task status
7149 p_PARAMC7 => l_task_name,
7150 p_PARAMC8 => p_task_activity_rec.old_status, -- prev task status
7151 p_PARAMC9 => NULL,
7152 p_PARAMC10 => NULL,
7153 p_PARAMD1 => l_planned_start_Date,
7154 p_PARAMD2 => l_actual_start_date,
7155 p_PARAMD3 => l_actual_end_date,
7156 p_PARAMD4 => l_last_update_Date,
7157 p_PARAMD5 => NULL,
7158 p_PARAMD6 => NULL,
7159 p_PARAMD7 => NULL,
7160 p_PARAMD8 => NULL,
7161 p_PARAMD9 => NULL,
7162 p_PARAMD10 => NULL,
7163 p_ATTRIBUTE_CATEGORY => NULL,
7164 p_ATTRIBUTE1 => NULL,
7165 p_ATTRIBUTE2 => NULL,
7166 p_ATTRIBUTE3 => NULL,
7167 p_ATTRIBUTE4 => NULL,
7168 p_ATTRIBUTE5 => NULL,
7169 p_ATTRIBUTE6 => NULL,
7170 p_ATTRIBUTE7 => NULL,
7171 p_ATTRIBUTE8 => NULL,
7172 p_ATTRIBUTE9 => NULL,
7173 p_ATTRIBUTE10 => NULL,
7174 p_ATTRIBUTE11 => NULL,
7175 p_ATTRIBUTE12 => NULL,
7176 p_ATTRIBUTE13 => NULL,
7177 p_ATTRIBUTE14 => NULL,
7178 p_ATTRIBUTE15 => NULL,
7179 p_LAST_UPDATE_LOGIN => Fnd_Global.CONC_LOGIN_ID,
7180 X_Return_Status => x_return_status,
7181 X_Msg_Count => x_msg_count,
7182 X_Msg_Data => x_msg_data);
7183
7184 END IF;
7185 --If old task assignee id is not the same as the new task assignee id,log the event TSC
7186 IF (p_task_activity_rec.new_resource_id <>
7187 p_task_activity_rec.old_resource_id)
7188 THEN
7189 l_event_Code := 'TAC';
7190 --log the activity
7191 -- ------------------------------------------------------
7192 -- Internal Private API call to write to Repair History
7193 -- ------------------------------------------------------
7194 Csd_To_Form_Repair_History.Validate_And_Write(p_Api_Version_Number => 1.0,
7195 p_init_msg_list => 'F',
7196 p_commit => 'F',
7197 p_validation_level => NULL,
7198 p_action_code => 0,
7199 px_REPAIR_HISTORY_ID => l_repair_history_id,
7200 p_OBJECT_VERSION_NUMBER => NULL,
7201 p_REQUEST_ID => NULL,
7202 p_PROGRAM_ID => NULL,
7203 p_PROGRAM_APPLICATION_ID => NULL,
7204 p_PROGRAM_UPDATE_DATE => NULL,
7205 p_CREATED_BY => Fnd_Global.USER_ID,
7206 p_CREATION_DATE => SYSDATE,
7207 p_LAST_UPDATED_BY => Fnd_Global.USER_ID,
7208 p_LAST_UPDATE_DATE => SYSDATE,
7209 p_repair_line_id => p_task_activity_rec.repair_line_id,
7210 p_EVENT_CODE => l_event_code,
7211 p_EVENT_DATE => SYSDATE,
7212 p_QUANTITY => NULL,
7213 p_PARAMN1 => p_task_activity_rec.task_id, -- task_id
7214 p_PARAMN2 => l_last_updated_by, -- last_updated_by
7215 p_PARAMN3 => p_task_Activity_rec.new_resource_id, -- new assignee id
7216 p_PARAMN4 => p_task_Activity_rec.old_resource_id, -- prev assignee id
7217 p_PARAMN5 => NULL,
7218 p_PARAMN6 => NULL,
7219 p_PARAMN7 => NULL,
7220 p_PARAMN8 => NULL,
7221 p_PARAMN9 => NULL,
7222 p_PARAMN10 => Fnd_Global.USER_ID,
7223 p_PARAMC1 => l_task_number, -- task number
7224 p_PARAMC2 => NULL,
7225 p_PARAMC3 => NULL,
7226 p_PARAMC4 => p_task_activity_rec.new_resource_type_code, -- new assignee type code
7227 p_PARAMC5 => p_task_activity_rec.new_resource_name, -- new task assignee name
7228 p_PARAMC6 => NULL,
7229 p_PARAMC7 => l_task_name,
7230 p_PARAMC8 => p_task_activity_rec.old_resource_type_code, -- old assignee type code
7231 p_PARAMC9 => p_task_activity_rec.old_resource_name, -- old task assignee name
7232 p_PARAMC10 => NULL,
7233 p_PARAMD1 => NULL,
7234 p_PARAMD2 => NULL,
7235 p_PARAMD3 => NULL,
7236 p_PARAMD4 => NULL,
7237 p_PARAMD5 => NULL,
7238 p_PARAMD6 => NULL,
7239 p_PARAMD7 => NULL,
7240 p_PARAMD8 => NULL,
7241 p_PARAMD9 => NULL,
7242 p_PARAMD10 => NULL,
7243 p_ATTRIBUTE_CATEGORY => NULL,
7244 p_ATTRIBUTE1 => NULL,
7245 p_ATTRIBUTE2 => NULL,
7246 p_ATTRIBUTE3 => NULL,
7247 p_ATTRIBUTE4 => NULL,
7248 p_ATTRIBUTE5 => NULL,
7249 p_ATTRIBUTE6 => NULL,
7250 p_ATTRIBUTE7 => NULL,
7251 p_ATTRIBUTE8 => NULL,
7252 p_ATTRIBUTE9 => NULL,
7253 p_ATTRIBUTE10 => NULL,
7254 p_ATTRIBUTE11 => NULL,
7255 p_ATTRIBUTE12 => NULL,
7256 p_ATTRIBUTE13 => NULL,
7257 p_ATTRIBUTE14 => NULL,
7258 p_ATTRIBUTE15 => NULL,
7259 p_LAST_UPDATE_LOGIN => Fnd_Global.CONC_LOGIN_ID,
7260 X_Return_Status => x_return_status,
7261 X_Msg_Count => x_msg_count,
7262 X_Msg_Data => x_msg_data);
7263
7264 END IF;
7265
7266 END IF; -- most outer if
7267 --
7268 IF (g_debug > 0)
7269 THEN
7270 Csd_Gen_Utility_Pvt.ADD('After Task to Update Repair History : ' ||
7271 x_return_status);
7272 END IF;
7273
7274 -- -------------------
7275 -- Api body ends here
7276 -- -------------------
7277 -- Standard check of p_commit.
7278 IF Fnd_Api.To_Boolean(p_commit)
7279 THEN
7280 COMMIT WORK;
7281 END IF;
7282 -- Standard call to get message count and IF count is get message info.
7283 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7284 p_data => x_msg_data);
7285 --END IF;
7286 -- ---------------------------------------------------------
7287 EXCEPTION
7288 WHEN Fnd_Api.G_EXC_ERROR THEN
7289 ROLLBACK TO Update_repair_task_hist;
7290 x_return_status := Fnd_Api.G_RET_STS_ERROR;
7291 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7292 p_data => x_msg_data);
7293 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
7294 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
7295 ROLLBACK TO Update_repair_task_hist;
7296 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7297 p_data => x_msg_data);
7298 WHEN OTHERS THEN
7299 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
7300 ROLLBACK TO Update_repair_task_hist;
7301 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
7302 THEN
7303 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
7304 END IF;
7305 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7306 p_data => x_msg_data);
7307 END Update_repair_task_hist;
7308
7309 /*----------------------------------------------------------------*/
7310 /* procedure name: Close_Status */
7311 /* description : procedure used to Close RO / Group RO and then */
7312 /* Close Service Request */
7313 /*----------------------------------------------------------------*/
7314
7315 PROCEDURE Close_status(p_api_version IN NUMBER,
7316 p_commit IN VARCHAR2 := Fnd_Api.g_false,
7317 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_false,
7318 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
7319 p_incident_id IN NUMBER,
7320 p_repair_line_id IN NUMBER,
7321 x_return_status OUT NOCOPY VARCHAR2,
7322 x_msg_count OUT NOCOPY NUMBER,
7323 x_msg_data OUT NOCOPY VARCHAR2) IS
7324
7325 l_api_name CONSTANT VARCHAR2(30) := 'Status_Close';
7326 l_api_version CONSTANT NUMBER := 1.0;
7327 l_msg_count NUMBER;
7328 l_msg_data VARCHAR2(2000);
7329 l_msg_index NUMBER;
7330 l_return_status VARCHAR2(3);
7331 l_validate_flag BOOLEAN;
7332 l_grp_rec Csd_Repair_Groups_Pvt.REPAIR_ORDER_GROUP_REC;
7333 l_ro_rec Csd_Repairs_Pub.REPLN_Rec_Type;
7334 l_open_ro_cnt NUMBER;
7335 l_repair_group_id NUMBER;
7336 l_grp_count NUMBER;
7337 l_status VARCHAR2(10) := 'CLOSED';
7338 l_ro_obj_version_number NUMBER;
7339 l_grp_obj_version_number NUMBER;
7340 l_interaction_id NUMBER;
7341 l_incident_id NUMBER;
7342 l_inc_obj_version_number NUMBER;
7343 l_prof_value VARCHAR2(1) := '';
7344
7345 /* Fixed for bug#3416001
7346 Variable l_sr_status has been declared to get the
7347 status of service request which is equivalent of
7348 status 'Close' in local language.
7349 */
7350 l_sr_status VARCHAR2(30);
7351
7352 CURSOR get_rep_group(p_incident_id IN NUMBER) IS
7353 SELECT crog.repair_group_id,
7354 crt.repair_type_ref,
7355 crog.group_txn_status
7356 FROM csd_repair_order_groups crog, csd_repair_types_vl crt
7357 WHERE crog.repair_type_id = crt.repair_type_id
7358 AND crog.incident_id = p_incident_id;
7359
7360 CURSOR get_ro_order(p_repair_group_id IN NUMBER) IS
7361 SELECT repair_line_id
7362 FROM csd_repairs
7363 WHERE repair_group_id = p_repair_group_id;
7364
7365 BEGIN
7366 --------------------------------------
7367 -- Standard Start of API savepoint
7368 --------------------------------------
7369 SAVEPOINT Close_Status;
7370
7371 -- Standard call to check for call compatibility.
7372 IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
7373 p_api_version,
7374 l_api_name,
7375 G_PKG_NAME)
7376 THEN
7377 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
7378 END IF;
7379 ------------------------------------------------------------
7380 -- Initialize message list if p_init_msg_list is set to TRUE.
7381 ------------------------------------------------------------
7382 IF Fnd_Api.to_Boolean(p_init_msg_list)
7383 THEN
7384 Fnd_Msg_Pub.initialize;
7385 END IF;
7386
7387 ---------------------------------------------
7388 -- Initialize API return status to success
7389 ---------------------------------------------
7390 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
7391
7392 --------------------
7393 -- Api body starts
7394 --------------------
7395 IF (g_debug > 0)
7396 THEN
7397 Csd_Gen_Utility_Pvt.dump_api_info
7398
7399 (p_pkg_name => G_PKG_NAME, p_api_name => l_api_name);
7400 END IF;
7401
7402 l_prof_value := NVL(Fnd_Profile.value('CSD_CLOSE_SR'), 'N');
7403 --------------------------------------------
7404 -- Check whether status has to updated for
7405 -- a group / Repair Order
7406 --------------------------------------------
7407
7408 IF (p_incident_id IS NOT NULL)
7409 THEN
7410
7411 -- Validate the incident_id
7412
7413 IF (g_debug > 0)
7414 THEN
7415 Csd_Gen_Utility_Pvt.ADD('Incident Id =' || p_incident_id);
7416 END IF;
7417
7418 l_validate_flag := Csd_Process_Util.validate_incident_id(p_incident_id);
7419
7420 IF NOT (l_validate_flag)
7421 THEN
7422 IF (g_debug > 0)
7423 THEN
7424 Csd_Gen_Utility_Pvt.ADD('The Incident Id is invalid ');
7425 END IF;
7426
7427 RAISE Fnd_Api.G_EXC_ERROR;
7428 END IF;
7429
7430 -- For all the groups within SR
7431
7432 FOR grp IN get_rep_group(p_incident_id)
7433 LOOP
7434
7435 IF (g_debug > 0)
7436 THEN
7437 Csd_Gen_Utility_Pvt.ADD('grp.repair_type_ref =' ||
7438 grp.repair_type_ref);
7439 END IF;
7440
7441 IF grp.repair_type_ref IN ('AE', 'AL')
7442 THEN
7443
7444 IF grp.group_txn_status = 'OM_RECEIVED'
7445 THEN
7446
7447 -- Update for all the Repair Orders within Group
7448 FOR ro IN get_ro_order(grp.repair_group_id)
7449 LOOP
7450
7451 BEGIN
7452 SELECT object_version_number
7453 INTO l_ro_obj_version_number
7454 FROM csd_repairs
7455 WHERE repair_line_id = ro.repair_line_id;
7456 EXCEPTION
7457 WHEN OTHERS THEN
7458 RAISE Fnd_Api.G_EXC_ERROR;
7459 END;
7460
7461 l_ro_rec.object_version_number := l_ro_obj_version_number;
7462 l_ro_rec.status := 'C';
7463
7464 IF (g_debug > 0)
7465 THEN
7466 Csd_Gen_Utility_Pvt.ADD('Update Repair Line Id =' ||
7467 ro.repair_line_id);
7468 END IF;
7469
7470 Csd_Repairs_Pub.Update_Repair_Order(P_Api_Version_Number => 1.0,
7471 P_Init_Msg_List => 'T',
7472 P_Commit => 'F',
7473 p_validation_level => 0,
7474 p_REPAIR_LINE_ID => ro.repair_line_id,
7475 P_REPLN_Rec => l_ro_rec,
7476 X_Return_Status => l_return_status,
7477 X_Msg_Count => l_msg_count,
7478 X_Msg_Data => l_msg_data);
7479
7480 IF (l_return_status <> 'S')
7481 THEN
7482 Fnd_Message.SET_NAME('CSD',
7483 'CSD_API_RO_STAT_UPD_FAIL');
7484 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
7485 ro.repair_line_id);
7486 Fnd_Msg_Pub.ADD;
7487 RAISE Fnd_Api.G_EXC_ERROR;
7488 END IF;
7489
7490 END LOOP;
7491
7492 BEGIN
7493 SELECT object_version_number
7494 INTO l_grp_obj_version_number
7495 FROM csd_repair_order_groups
7496 WHERE repair_group_id = grp.repair_group_id;
7497 EXCEPTION
7498 WHEN OTHERS THEN
7499 RAISE Fnd_Api.G_EXC_ERROR;
7500 END;
7501
7502 l_grp_rec.object_version_number := l_grp_obj_version_number;
7503 l_grp_rec.group_txn_status := 'CLOSED';
7504 l_grp_rec.repair_group_id := grp.repair_group_id;
7505
7506 IF (g_debug > 0)
7507 THEN
7508 Csd_Gen_Utility_Pvt.ADD('Update Repair Group Id =' ||
7509 grp.repair_group_id);
7510 END IF;
7511
7512 -- Update Group
7513 Csd_Repair_Groups_Pvt.UPDATE_REPAIR_GROUPS(p_api_version => 1.0,
7514 p_commit => 'F',
7515 p_init_msg_list => 'T',
7516 p_validation_level => 0,
7517 x_repair_order_group_rec => l_grp_rec,
7518 x_return_status => l_return_status,
7519 x_msg_count => l_msg_count,
7520 x_msg_data => l_msg_data);
7521
7522 IF (l_return_status <> 'S')
7523 THEN
7524 Fnd_Message.SET_NAME('CSD',
7525 'CSD_API_GRP_STAT_UPD_FAIL');
7526 Fnd_Message.SET_TOKEN('REPAIR_GROUP_ID',
7527 grp.repair_group_id);
7528 Fnd_Msg_Pub.ADD;
7529 RAISE Fnd_Api.G_EXC_ERROR;
7530 END IF;
7531
7532 END IF;
7533
7534 ELSIF grp.repair_type_ref IN ('RR', 'E', 'WR')
7535 THEN
7536
7537 IF grp.group_txn_status = 'OM_SHIPPED'
7538 THEN
7539
7540 -- Update all the repair orders within group
7541
7542 FOR ro IN get_ro_order(grp.repair_group_id)
7543 LOOP
7544
7545 BEGIN
7546 SELECT object_version_number
7547 INTO l_ro_obj_version_number
7548 FROM csd_repairs
7549 WHERE repair_line_id = ro.repair_line_id;
7550 EXCEPTION
7551 WHEN OTHERS THEN
7552 RAISE Fnd_Api.G_EXC_ERROR;
7553 END;
7554
7555 l_ro_rec.object_version_number := l_ro_obj_version_number;
7556 l_ro_rec.status := 'C';
7557
7558 IF (g_debug > 0)
7559 THEN
7560 Csd_Gen_Utility_Pvt.ADD('Update Repair Line Id =' ||
7561 ro.repair_line_id);
7562 END IF;
7563
7564 Csd_Repairs_Pub.Update_Repair_Order(P_Api_Version_Number => 1.0,
7565 P_Init_Msg_List => 'T',
7566 P_Commit => 'F',
7567 p_validation_level => 0,
7568 p_REPAIR_LINE_ID => ro.repair_line_id,
7569 P_REPLN_Rec => l_ro_rec,
7570 X_Return_Status => l_return_status,
7571 X_Msg_Count => l_msg_count,
7572 X_Msg_Data => l_msg_data);
7573
7574 IF (l_return_status <> 'S')
7575 THEN
7576 Fnd_Message.SET_NAME('CSD',
7577 'CSD_API_RO_STAT_UPD_FAIL');
7578 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
7579 ro.repair_line_id);
7580 Fnd_Msg_Pub.ADD;
7581 RAISE Fnd_Api.G_EXC_ERROR;
7582 END IF;
7583
7584 END LOOP;
7585
7586 BEGIN
7587 SELECT object_version_number
7588 INTO l_grp_obj_version_number
7589 FROM csd_repair_order_groups
7590 WHERE repair_group_id = grp.repair_group_id;
7591 EXCEPTION
7592 WHEN OTHERS THEN
7593 RAISE Fnd_Api.G_EXC_ERROR;
7594 END;
7595
7596 l_grp_rec.object_version_number := l_grp_obj_version_number;
7597 l_grp_rec.group_txn_status := 'CLOSED';
7598 l_grp_rec.repair_group_id := grp.repair_group_id;
7599
7600 IF (g_debug > 0)
7601 THEN
7602 Csd_Gen_Utility_Pvt.ADD('Update Repair Group Id =' ||
7603 grp.repair_group_id);
7604 END IF;
7605
7606 -- Update the Group
7607
7608 Csd_Repair_Groups_Pvt.UPDATE_REPAIR_GROUPS(p_api_version => 1.0,
7609 p_commit => 'F',
7610 p_init_msg_list => 'T',
7611 p_validation_level => 0,
7612 x_repair_order_group_rec => l_grp_rec,
7613 x_return_status => l_return_status,
7614 x_msg_count => l_msg_count,
7615 x_msg_data => l_msg_data);
7616
7617 IF (l_return_status <> 'S')
7618 THEN
7619 Fnd_Message.SET_NAME('CSD',
7620 'CSD_API_GRP_STAT_UPD_FAIL');
7621 Fnd_Message.SET_TOKEN('REPAIR_GROUP_ID',
7622 grp.repair_group_id);
7623 Fnd_Msg_Pub.ADD;
7624 RAISE Fnd_Api.G_EXC_ERROR;
7625 END IF;
7626
7627 END IF; -- grp_txn_status
7628
7629 END IF; -- rep_typ_ref
7630
7631 END LOOP; -- end of all groups
7632
7633 BEGIN
7634
7635 SELECT COUNT(*)
7636 INTO l_open_ro_cnt
7637 FROM csd_repairs
7638 WHERE incident_id = p_incident_id
7639 AND status <> 'C';
7640
7641 EXCEPTION
7642 WHEN OTHERS THEN
7643 l_open_ro_cnt := -1;
7644 END;
7645
7646 IF l_open_ro_cnt = 0
7647 THEN
7648
7649 IF (g_debug > 0)
7650 THEN
7651 Csd_Gen_Utility_Pvt.ADD('Update Incident Id =' ||
7652 p_incident_id);
7653 END IF;
7654
7655 BEGIN
7656 SELECT object_version_number
7657 INTO l_inc_obj_version_number
7658 FROM cs_incidents_all_b
7659 WHERE incident_id = p_incident_id;
7660 EXCEPTION
7661 WHEN OTHERS THEN
7662 l_inc_obj_version_number := -1;
7663 END;
7664
7665 -- swai bug fix 3376564
7666 -- (1) Close the SR using the seeded 'Closed' status if it is valid
7667 -- (2) If the seeded status is not valid, then close the SR using the
7668 -- first valid closed status.
7669 BEGIN
7670 SELECT name
7671 INTO l_sr_status
7672 FROM cs_incident_statuses_vl
7673 WHERE incident_subtype = 'INC'
7674 AND CLOSE_FLAG = 'Y'
7675 AND TRUNC(SYSDATE) BETWEEN
7676 TRUNC(NVL(start_date_active, SYSDATE)) AND
7677 TRUNC(NVL(end_date_active, SYSDATE))
7678 AND status_code = 'CLOSED';
7679 EXCEPTION
7680 WHEN OTHERS THEN
7681 l_sr_status := NULL;
7682 END;
7683
7684 IF (l_sr_status IS NULL)
7685 THEN
7686 /* Fixed for bug#3416001
7687 Following query has been added to get the
7688 status of service request which is equivalent of
7689 status 'Close' in local language.
7690 */
7691 SELECT name
7692 INTO l_sr_status
7693 FROM cs_incident_statuses_vl
7694 WHERE incident_subtype = 'INC'
7695 AND CLOSE_FLAG = 'Y'
7696 AND TRUNC(SYSDATE) BETWEEN
7697 TRUNC(NVL(start_date_active, SYSDATE)) AND
7698 TRUNC(NVL(end_date_active, SYSDATE))
7699 AND ROWNUM < 2;
7700 END IF;
7701
7702 IF l_prof_value = 'Y'
7703 THEN
7704 -- Update the Service Request
7705 Cs_Servicerequest_Pub.Update_Status(p_api_version => 2.0,
7706 p_init_msg_list => 'T',
7707 p_commit => 'F',
7708 x_return_status => l_return_status,
7709 x_msg_count => l_msg_count,
7710 x_msg_data => l_msg_data,
7711 p_resp_appl_id => Fnd_Global.RESP_APPL_ID,
7712 p_resp_id => Fnd_Global.RESP_ID,
7713 p_user_id => Fnd_Global.USER_ID,
7714 p_login_id => Fnd_Global.LOGIN_ID,
7715 p_request_id => p_incident_id,
7716 p_request_number => NULL,
7717 p_object_version_number => l_inc_obj_version_number,
7718 p_status_id => NULL,
7719 -- p_status => 'CLOSED',
7720 /* Fixed for bug#3416001
7721 Hardcoding for parameter p_status has been removed.
7722 */
7723 p_status => l_sr_status,
7724 p_closed_date => SYSDATE,
7725 p_audit_comments => NULL,
7726 p_called_by_workflow => 'F',
7727 p_workflow_process_id => NULL,
7728 p_comments => NULL,
7729 p_public_comment_flag => 'F',
7730 x_interaction_id => l_interaction_id);
7731
7732 IF (l_return_status <> 'S')
7733 THEN
7734 Fnd_Message.SET_NAME('CSD',
7735 'CSD_API_SR_STAT_UPD_FAIL');
7736 Fnd_Message.SET_TOKEN('INCIDENT_ID', p_incident_id);
7737 Fnd_Msg_Pub.ADD;
7738 RAISE Fnd_Api.G_EXC_ERROR;
7739 END IF;
7740
7741 END IF;
7742
7743 END IF;
7744
7745 ELSIF (p_repair_line_id IS NOT NULL)
7746 THEN
7747
7748 -- Validate the repair_line_id
7749
7750 IF (g_debug > 0)
7751 THEN
7752 Csd_Gen_Utility_Pvt.ADD('Update Repair Line ID =' ||
7753 p_repair_line_id);
7754 END IF;
7755
7756 l_validate_flag := Csd_Process_Util.validate_rep_line_id(p_repair_line_id);
7757
7758 IF NOT (l_validate_flag)
7759 THEN
7760 IF (g_debug > 0)
7761 THEN
7762 Csd_Gen_Utility_Pvt.ADD('Repair Line Id is invalid ');
7763 END IF;
7764
7765 RAISE Fnd_Api.G_EXC_ERROR;
7766 END IF;
7767
7768 BEGIN
7769 SELECT object_version_number
7770 INTO l_ro_obj_version_number
7771 FROM csd_repairs
7772 WHERE repair_line_id = p_repair_line_id;
7773 EXCEPTION
7774 WHEN OTHERS THEN
7775 RAISE Fnd_Api.G_EXC_ERROR;
7776 END;
7777
7778 l_ro_rec.object_version_number := l_ro_obj_version_number;
7779 l_ro_rec.status := 'C';
7780
7781 -- Update the Repair Order
7782 Csd_Repairs_Pub.Update_Repair_Order(P_Api_Version_Number => 1.0,
7783 P_Init_Msg_List => 'T',
7784 P_Commit => 'F',
7785 p_validation_level => 0,
7786 p_REPAIR_LINE_ID => p_repair_line_id,
7787 P_REPLN_Rec => l_ro_rec,
7788 X_Return_Status => l_return_status,
7789 X_Msg_Count => l_msg_count,
7790 X_Msg_Data => l_msg_data);
7791
7792 IF (l_return_status <> 'S')
7793 THEN
7794 Fnd_Message.SET_NAME('CSD', 'CSD_API_RO_STAT_UPD_FAIL');
7795 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID', p_repair_line_id);
7796 Fnd_Msg_Pub.ADD;
7797 RAISE Fnd_Api.G_EXC_ERROR;
7798 END IF;
7799
7800 BEGIN
7801
7802 SELECT repair_group_id, incident_id
7803 INTO l_repair_group_id, l_incident_id
7804 FROM csd_repairs
7805 WHERE repair_line_id = p_repair_line_id;
7806
7807 IF (l_repair_group_id IS NOT NULL)
7808 THEN
7809 SELECT COUNT(*)
7810 INTO l_grp_count
7811 FROM csd_repairs
7812 WHERE status = 'C'
7813 AND repair_group_id = l_repair_group_id;
7814 END IF;
7815
7816 EXCEPTION
7817 WHEN NO_DATA_FOUND THEN
7818 l_grp_count := -1;
7819 END;
7820
7821 -- Update the Group only if its exists
7822
7823 IF (l_grp_count = 0 AND l_repair_group_id IS NOT NULL)
7824 THEN
7825
7826 IF (g_debug > 0)
7827 THEN
7828 Csd_Gen_Utility_Pvt.ADD('Update Repair Group Id =' ||
7829 l_repair_group_id);
7830 END IF;
7831
7832 BEGIN
7833 SELECT object_version_number
7834 INTO l_grp_obj_version_number
7835 FROM csd_repair_order_groups
7836 WHERE repair_group_id = l_repair_group_id;
7837 EXCEPTION
7838 WHEN OTHERS THEN
7839 RAISE Fnd_Api.G_EXC_ERROR;
7840 END;
7841
7842 l_grp_rec.object_version_number := l_grp_obj_version_number;
7843 l_grp_rec.group_txn_status := 'CLOSED';
7844 l_grp_rec.repair_group_id := l_repair_group_id;
7845
7846 Csd_Repair_Groups_Pvt.UPDATE_REPAIR_GROUPS(p_api_version => 1.0,
7847 p_commit => 'F',
7848 p_init_msg_list => 'T',
7849 p_validation_level => 0,
7850 x_repair_order_group_rec => l_grp_rec,
7851 x_return_status => l_return_status,
7852 x_msg_count => l_msg_count,
7853 x_msg_data => l_msg_data);
7854
7855 IF (l_return_status <> 'S')
7856 THEN
7857 Fnd_Message.SET_NAME('CSD',
7858 'CSD_API_GRP_STAT_UPD_FAIL');
7859 Fnd_Message.SET_TOKEN('REPAIR_GROUP_ID',
7860 l_repair_group_id);
7861 Fnd_Msg_Pub.ADD;
7862 RAISE Fnd_Api.G_EXC_ERROR;
7863 END IF;
7864
7865 END IF;
7866
7867 BEGIN
7868
7869 SELECT COUNT(*)
7870 INTO l_open_ro_cnt
7871 FROM csd_repairs
7872 WHERE incident_id = l_incident_id
7873 AND status <> 'C';
7874
7875 EXCEPTION
7876 WHEN OTHERS THEN
7877 l_open_ro_cnt := -1;
7878 END;
7879
7880 IF l_open_ro_cnt = 0
7881 THEN
7882
7883 IF (g_debug > 0)
7884 THEN
7885 Csd_Gen_Utility_Pvt.ADD('Update Service Request = ' ||
7886 l_incident_id);
7887 END IF;
7888
7889 -- Update the Service Request
7890
7891 BEGIN
7892 SELECT object_version_number
7893 INTO l_inc_obj_version_number
7894 FROM cs_incidents_all_b
7895 WHERE incident_id = l_incident_id;
7896 EXCEPTION
7897 WHEN OTHERS THEN
7898 l_inc_obj_version_number := -1;
7899 END;
7900
7901 -- swai bug fix 3376564
7902 -- (1) Close the SR using the seeded 'Closed' status if it is valid
7903 -- (2) If the seeded status is not valid, then close the SR using the
7904 -- first valid closed status.
7905 BEGIN
7906 SELECT name
7907 INTO l_sr_status
7908 FROM cs_incident_statuses_vl
7909 WHERE incident_subtype = 'INC'
7910 AND CLOSE_FLAG = 'Y'
7911 AND TRUNC(SYSDATE) BETWEEN
7912 TRUNC(NVL(start_date_active, SYSDATE)) AND
7913 TRUNC(NVL(end_date_active, SYSDATE))
7914 AND status_code = 'CLOSED';
7915 EXCEPTION
7916 WHEN OTHERS THEN
7917 l_sr_status := NULL;
7918 END;
7919
7920 IF (l_sr_status IS NULL)
7921 THEN
7922 /* Fixed for bug#3416001
7923 Following query has been added to get the
7924 status of service request which is equivalent of
7925 status 'Close' in local language.
7926 */
7927 SELECT name
7928 INTO l_sr_status
7929 FROM cs_incident_statuses_vl
7930 WHERE incident_subtype = 'INC'
7931 AND CLOSE_FLAG = 'Y'
7932 AND TRUNC(SYSDATE) BETWEEN
7933 TRUNC(NVL(start_date_active, SYSDATE)) AND
7934 TRUNC(NVL(end_date_active, SYSDATE))
7935 AND ROWNUM < 2;
7936 END IF;
7937
7938 IF l_prof_value = 'Y'
7939 THEN
7940 -- Update the Service Request
7941 Cs_Servicerequest_Pub.Update_Status(p_api_version => 2.0,
7942 p_init_msg_list => 'T',
7943 p_commit => 'F',
7944 x_return_status => l_return_status,
7945 x_msg_count => l_msg_count,
7946 x_msg_data => l_msg_data,
7947 p_resp_appl_id => Fnd_Global.RESP_APPL_ID,
7948 p_resp_id => Fnd_Global.RESP_ID,
7949 p_user_id => Fnd_Global.USER_ID,
7950 p_login_id => Fnd_Global.LOGIN_ID,
7951 p_request_id => l_incident_id,
7952 p_request_number => NULL,
7953 p_object_version_number => l_inc_obj_version_number,
7954 p_status_id => NULL,
7955 -- p_status => 'CLOSED',
7956 /* Fixed for bug#3416001
7957 Hardcoding for parameter p_status has been removed.
7958 */
7959 p_status => l_sr_status,
7960 p_closed_date => SYSDATE,
7961 p_audit_comments => NULL,
7962 p_called_by_workflow => 'F',
7963 p_workflow_process_id => NULL,
7964 p_comments => NULL,
7965 p_public_comment_flag => 'F',
7966 x_interaction_id => l_interaction_id);
7967
7968 IF (l_return_status <> 'S')
7969 THEN
7970 Fnd_Message.SET_NAME('CSD',
7971 'CSD_API_SR_STAT_UPD_FAIL');
7972 Fnd_Message.SET_TOKEN('INCIDENT_ID', l_incident_id);
7973 Fnd_Msg_Pub.ADD;
7974 --Bug fix for 3555256 Begin
7975 --RAISE FND_API.G_EXC_ERROR;
7976 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7977 p_data => x_msg_data);
7978 --Bug fix for 3555256 End
7979
7980 END IF;
7981 END IF;
7982 END IF;
7983
7984 END IF;
7985
7986 EXCEPTION
7987 WHEN Fnd_Api.G_EXC_ERROR THEN
7988 ROLLBACK TO Close_Status;
7989 x_return_status := Fnd_Api.G_RET_STS_ERROR;
7990 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7991 p_data => x_msg_data);
7992 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
7993 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
7994 ROLLBACK TO status_close;
7995 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7996 p_data => x_msg_data);
7997 WHEN OTHERS THEN
7998 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
7999 ROLLBACK TO status_close;
8000 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
8001 THEN
8002 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
8003 END IF;
8004 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
8005 p_data => x_msg_data);
8006 END Close_Status;
8007
8008 /*---------------------------------------------------------------*/
8009 /* procedure name: Check_Service_Request */
8010 /* Description: procedure used to find if there are unasigned */
8011 /* RMA/SO lines for the given service request */
8012 /* Parameters x_link_mode determines the way the screen flow */
8013 /* will happen. The valid values are */
8014 /* 1: Only unlinked RMA's exist */
8015 /* 2: Both unlinked RMA's and unlinked SO's exist */
8016 /* 3: Only unlinked SO's with atleast 1 repair */
8017 /* for the service request */
8018 /* 4: Only unlinked SO without any repair order */
8019 /* for the service request */
8020 /* 5: No unlinked RMA or SO */
8021 /*---------------------------------------------------------------*/
8022
8023 PROCEDURE Check_Service_Request(p_api_version IN NUMBER,
8024 p_commit IN VARCHAR2 := Fnd_Api.g_false,
8025 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_false,
8026 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
8027 p_incident_id IN NUMBER,
8028 x_link_mode OUT NOCOPY NUMBER,
8029 x_return_status OUT NOCOPY VARCHAR2,
8030 x_msg_count OUT NOCOPY NUMBER,
8031 x_msg_data OUT NOCOPY VARCHAR2) IS
8032 l_api_name CONSTANT VARCHAR2(30) := 'Check_Service_Request';
8033 l_rma_count NUMBER;
8034 l_so_count NUMBER;
8035 l_ro_count NUMBER;
8036
8037 --Cursor for selecting count of RMA/SO
8038 CURSOR RMA_SO_CUR(p_incident_Id NUMBER) IS
8039 SELECT Line_Category_code, COUNT(*) line_count
8040 FROM CSD_ESTIMATE_DETAILS_EXT_V
8041 WHERE INCIDENT_ID = p_incident_Id
8042 AND Line_Category_Code IN ('RETURN', 'ORDER')
8043 GROUP BY Line_Category_Code;
8044
8045 --Cursor to get the count of repair orders for the given SR
8046 CURSOR RO_CUR(p_incident_Id NUMBER) IS
8047 SELECT COUNT(*) ro_count
8048 FROM CSD_REPAIRS
8049 WHERE INCIDENT_ID = p_incident_Id;
8050
8051 BEGIN
8052
8053 IF (g_debug > 0)
8054 THEN
8055 Csd_Gen_Utility_Pvt.ADD('In Check_Service_Request API');
8056 END IF;
8057
8058 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
8059
8060 -- Initialize the count vars
8061 l_rma_count := 0;
8062 l_so_count := 0;
8063 --Get the count for RMA and SO
8064 FOR rma_so_rec IN RMA_SO_CUR(p_incident_Id)
8065 LOOP
8066 IF (g_debug > 0)
8067 THEN
8068 Csd_Gen_Utility_Pvt.ADD('Unlinked RMA/SO found ');
8069 Csd_Gen_Utility_Pvt.ADD('Category[' ||
8070 rma_so_Rec.Line_Category_Code || ']');
8071 Csd_Gen_Utility_Pvt.ADD('count[' || rma_so_Rec.line_Count || ']');
8072 END IF;
8073
8074 IF (rma_so_Rec.Line_Category_Code = 'RETURN')
8075 THEN
8076 l_rma_Count := rma_so_Rec.line_Count;
8077 END IF;
8078 IF (rma_so_Rec.Line_Category_Code = 'ORDER')
8079 THEN
8080 l_so_Count := rma_so_Rec.line_Count;
8081 END IF;
8082 END LOOP;
8083
8084 --Determine the mode
8085 IF (l_rma_count > 0 AND l_so_Count > 0)
8086 THEN
8087 x_link_mode := 2;
8088 ELSIF (l_rma_count = 0 AND l_so_count = 0)
8089 THEN
8090 x_link_mode := 5;
8091 ELSIF (l_so_count = 0 AND l_rma_count > 0)
8092 THEN
8093 x_link_mode := 1;
8094 ELSIF (l_rma_count = 0 AND l_so_count > 0)
8095 THEN
8096 -- get the count of repair orders and
8097 -- set the mode to 3 if there are repair orders
8098 -- or to 4 if there are no reapair orders.
8099 l_ro_count := 0;
8100 OPEN RO_CUR(p_incident_Id);
8101 FETCH RO_CUR
8102 INTO l_ro_count;
8103 CLOSE RO_CUR;
8104
8105 IF (l_ro_Count > 0)
8106 THEN
8107 x_link_mode := 3;
8108 ELSE
8109 x_link_mode := 4;
8110 END IF;
8111
8112 END IF;
8113
8114 IF (g_debug > 0)
8115 THEN
8116 Csd_Gen_Utility_Pvt.ADD('Leaving checkService_Request link mode[' ||
8117 TO_CHAR(x_link_mode) || ']');
8118 END IF;
8119
8120 EXCEPTION
8121 WHEN OTHERS THEN
8122 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
8123 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
8124 THEN
8125 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
8126 END IF;
8127 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
8128 p_data => x_msg_data);
8129
8130 END Check_Service_Request;
8131
8132 /*---------------------------------------------------------------*/
8133 /* procedure name: Update_Line_Txn_Source */
8134 /* Description: procedure used to update the source_code and */
8135 /* source_id of the line transaction */
8136 /*---------------------------------------------------------------*/
8137 PROCEDURE Update_Line_Txn_Source(p_api_version IN NUMBER,
8138 p_commit IN VARCHAR2,
8139 p_init_msg_list IN VARCHAR2,
8140 p_validation_level IN NUMBER,
8141 p_incident_id IN NUMBER,
8142 p_estimate_detail_line_id IN NUMBER,
8143 p_repair_line_id IN NUMBER,
8144 x_return_status OUT NOCOPY VARCHAR2,
8145 x_msg_count OUT NOCOPY NUMBER,
8146 x_msg_data OUT NOCOPY VARCHAR2) IS
8147 BEGIN
8148
8149 UPDATE CS_ESTIMATE_DETAILS
8150 SET SOURCE_CODE = 'DR', SOURCE_ID = p_repair_line_id
8151 WHERE INCIDENT_ID = p_incident_id
8152 AND ESTIMATE_DETAIL_ID = p_estimate_detail_line_id;
8153
8154 END Update_Line_Txn_Source;
8155
8156 /*---------------------------------------------------------------------------------*/
8157 /* procedure name: Update_iro_product_txn */
8158 /* Description: procedure used to update the product transaction */
8159 /* table and process pick release and shipping */
8160 /* transactions for internal ROs. */
8161 /* p_api_version Standard in parameter */
8162 /* p_commit Standard in parameter */
8163 /* p_init_msg_list Standard in parameter */
8164 /* p_validation_level Standard in parameter */
8165 /* x_return_status Standard Out parameter */
8166 /* x_msg_count Standard in parameter */
8167 /* x_msg_data Standard in parameter , */
8168 /* x_product_txn_rec in out record variable of type */
8169 /* csd_process_pvt.product_txn_rec ) ; */
8170 /*---------------------------------------------------------------------------------*/
8171 PROCEDURE update_iro_product_txn(p_api_version IN NUMBER,
8172 p_commit IN VARCHAR2,
8173 p_init_msg_list IN VARCHAR2,
8174 p_validation_level IN NUMBER,
8175 x_product_txn_rec IN OUT nocopy Csd_Process_Pvt.product_txn_rec,
8176 x_return_status OUT nocopy VARCHAR2,
8177 x_msg_count OUT nocopy NUMBER,
8178 x_msg_data OUT nocopy VARCHAR2) IS
8179
8180 l_api_name CONSTANT VARCHAR2(30) := 'update_iro_product_txn';
8181 l_api_version CONSTANT NUMBER := 1.0;
8182 l_msg_count NUMBER;
8183 l_msg_data VARCHAR2(2000);
8184 l_msg_index NUMBER;
8185 l_check VARCHAR2(1);
8186 l_order_rec Csd_Process_Pvt.om_interface_rec;
8187 l_est_detail_id NUMBER := NULL;
8188 l_incident_id NUMBER := NULL;
8189 l_party_id NUMBER := NULL;
8190 l_account_id NUMBER := NULL;
8191 l_order_header_id NUMBER := NULL;
8192 l_released_status VARCHAR2(1) := '';
8193 l_picking_rule_id NUMBER := NULL;
8194 l_repair_line_id NUMBER := NULL;
8195 l_curr_submit_order_flag VARCHAR2(1) := '';
8196 l_curr_book_order_flag VARCHAR2(1) := '';
8197 l_curr_release_order_flag VARCHAR2(1) := '';
8198 l_curr_ship_order_flag VARCHAR2(1) := '';
8199 l_booked_flag VARCHAR2(1) := '';
8200 l_allow_ship VARCHAR2(1) := '';
8201 l_object_version_num NUMBER := NULL;
8202 l_ship_from_org_id NUMBER := NULL;
8203 l_order_line_id NUMBER := NULL;
8204 l_bus_process_id NUMBER := NULL;
8205 l_unit_selling_price NUMBER := NULL;
8206 l_serial_flag BOOLEAN := FALSE;
8207 l_order_category_code VARCHAR2(30);
8208 l_orig_src_reference VARCHAR2(30);
8209 l_orig_src_header_id NUMBER;
8210 l_orig_src_line_id NUMBER;
8211 l_orig_po_num VARCHAR2(50);
8212
8213 -- travi fix
8214 l_repair_mode VARCHAR2(30) := NULL;
8215 l_count_est NUMBER := 0;
8216 l_count_iface_est NUMBER := 0;
8217 l_count_task NUMBER := 0;
8218 l_count_wip NUMBER := 0;
8219
8220 C_Yes CONSTANT VARCHAR2(1) := 'Y';
8221 C_No CONSTANT VARCHAR2(1) := 'N';
8222 C_Zero CONSTANT NUMBER := 0;
8223
8224 -- define variables to define fnd_log debug levels
8225 l_debug_level NUMBER := Fnd_Log.g_current_runtime_level;
8226 -- examples : 1- copying buffer x to y : low level detailed messages
8227 l_statement_level NUMBER := Fnd_Log.level_statement;
8228 -- examples : 2- key progress events : starting business transactions
8229 l_procedure_level NUMBER := Fnd_Log.level_procedure;
8230 -- examples : 3- event : calling an api, key progress events
8231 l_event_level NUMBER := Fnd_Log.level_event;
8232 -- examples : 4- exception internal software failure condition
8233 l_exception_level NUMBER := Fnd_Log.level_exception;
8234 -- examples : 5- error end user erros
8235 l_error_level NUMBER := Fnd_Log.level_error;
8236 l_module_name VARCHAR2(240) := 'csd.plsql.csd_process_pvt.update_iro_product_txn';
8237
8238 -- a variable whose value tells us whether order header can be pick released or not.
8239 l_order_to_be_pickreleased VARCHAR2(1) := C_NO;
8240 -- a variable whose value tells us whether order header can be shipped or not.
8241 l_order_to_be_shipped VARCHAR2(1) := C_No;
8242
8243 -- constants to define delivery line release statuses
8244 c_ready_for_release CONSTANT VARCHAR2(1) := 'R';
8245 c_backordered CONSTANT VARCHAR2(1) := 'B';
8246 c_staged_pickconfirmed CONSTANT VARCHAR2(1) := 'Y';
8247 c_shipped CONSTANT VARCHAR2(1) := 'C';
8248 c_cancelled CONSTANT VARCHAR2(1) := 'D';
8249 c_release_to_warehouse CONSTANT VARCHAR2(1) := 'S';
8250 ----- End of definition of release statuses
8251
8252 -- Define variable for action type values
8253 C_Action_Type_Move_Out CONSTANT VARCHAR2(30) := 'MOVE_OUT';
8254 C_Action_Type_Move_In CONSTANT VARCHAR2(30) := 'MOVE_IN';
8255
8256 -- Define varialbes for Action variable in process_sales_order API
8257 C_Action_Pick_Release CONSTANT VARCHAR2(30) := 'PICK-RELEASE';
8258 C_Action_Ship CONSTANT VARCHAR2(30) := 'SHIP';
8259
8260 -- Define constants to hold product txn status values
8261 C_Status_Released CONSTANT VARCHAR2(30) := 'RELEASED';
8262 C_Status_Shipped CONSTANT VARCHAR2(30) := 'SHIPPED';
8263
8264 release_order_excep EXCEPTION;
8265 ship_order_excep EXCEPTION;
8266
8267 CURSOR sr_rec(p_incident_id IN NUMBER) IS
8268 SELECT customer_id, account_id
8269 FROM cs_incidents_all_b
8270 WHERE incident_id = p_incident_id;
8271
8272 CURSOR prod_txn(p_prod_txn_id IN NUMBER) IS
8273 SELECT estimate_detail_id,
8274 repair_line_id,
8275 interface_to_om_flag,
8276 book_sales_order_flag,
8277 release_sales_order_flag,
8278 ship_sales_order_flag,
8279 object_version_number
8280 FROM csd_product_transactions
8281 WHERE product_transaction_id = p_prod_txn_id;
8282
8283 CURSOR released_lines_cur(p_order_header_id IN NUMBER, p_Order_Line_id IN NUMBER) IS
8284 SELECT source_header_id, source_line_id, released_status
8285 FROM wsh_delivery_details
8286 WHERE source_header_id = p_order_header_id
8287 AND Source_line_id = p_Order_line_id
8288 AND SOURCE_CODE = 'OE' /*Fixed for bug#5846054*/
8289 AND released_status = C_Staged_PickConfirmed;
8290
8291 CURSOR shipped_lines_cur(p_order_header_id IN NUMBER, p_Order_Line_Id IN NUMBER) IS
8292 SELECT source_header_id, source_line_id, released_status
8293 FROM wsh_delivery_details
8294 WHERE source_header_id = p_order_header_id
8295 AND Source_line_id = p_Order_line_id
8296 AND SOURCE_CODE = 'OE' /*Fixed for bug#5846054*/
8297 AND released_status = C_Shipped;
8298
8299 BEGIN
8300 IF l_statement_level >= l_debug_level
8301 THEN
8302 Fnd_Log.string(l_statement_level, l_module_name, 'begin');
8303 END IF;
8304 -- standard start of api savepoint
8305 SAVEPOINT update_iro_product_txn;
8306 IF l_statement_level >= l_debug_level
8307 THEN
8308 Fnd_Log.string(l_statement_level,
8309 l_module_name,
8310 'checking api compatibility');
8311 END IF;
8312 -- standard call to check for call compatibility.
8313 IF NOT Fnd_Api.compatible_api_call(l_api_version,
8314 p_api_version,
8315 l_api_name,
8316 g_pkg_name)
8317 THEN
8318 IF l_exception_level >= l_debug_level
8319 THEN
8320 Fnd_Log.string(l_exception_level,
8321 l_module_name,
8322 'checking api compatibility, was unsuccessful');
8323 END IF;
8324 RAISE Fnd_Api.g_exc_unexpected_error;
8325 END IF;
8326 IF l_statement_level >= l_debug_level
8327 THEN
8328 Fnd_Log.string(l_statement_level,
8329 l_module_name,
8330 'checking api compatibility, was successful');
8331 END IF;
8332
8333 -- initialize message list if p_init_msg_list is set to true.
8334 IF Fnd_Api.to_boolean(p_init_msg_list)
8335 THEN
8336 Fnd_Msg_Pub.initialize;
8337 END IF;
8338
8339 -- initialize api return status to success
8340 x_return_status := Fnd_Api.g_ret_sts_success;
8341
8342 IF l_statement_level >= l_debug_level
8343 THEN
8344 Fnd_Log.String(l_Statement_Level,
8345 l_Module_Name,
8346 'Product Transaction Record Values:');
8347 Fnd_Log.String(l_Statement_Level,
8348 l_Module_Name,
8349 'Product Transaction Id :' ||
8350 x_product_txn_rec.Product_Transaction_Id);
8351 Fnd_Log.String(l_Statement_Level,
8352 l_Module_Name,
8353 'Repair_line_id :' ||
8354 x_product_txn_rec.repair_line_id);
8355 Fnd_Log.String(l_Statement_Level,
8356 l_Module_Name,
8357 'Action_type :' ||
8358 x_product_txn_rec.action_type);
8359 Fnd_Log.String(l_Statement_Level,
8360 l_Module_Name,
8361 'Action_code :' ||
8362 x_product_txn_rec.action_code);
8363 Fnd_Log.String(l_Statement_Level,
8364 l_Module_Name,
8365 'Incident_id :' ||
8366 x_product_txn_rec.incident_id);
8367 Fnd_Log.String(l_Statement_Level,
8368 l_Module_Name,
8369 'line_type_id :' ||
8370 x_product_txn_rec.line_type_id);
8371 Fnd_Log.String(l_Statement_Level,
8372 l_Module_Name,
8373 'Order_number :' ||
8374 x_product_txn_rec.order_number);
8375 Fnd_Log.String(l_Statement_Level,
8376 l_Module_Name,
8377 'Status :' ||
8378 x_product_txn_rec.status);
8379 Fnd_Log.String(l_Statement_Level,
8380 l_Module_Name,
8381 'Currency_code :' ||
8382 x_product_txn_rec.currency_code);
8383 Fnd_Log.String(l_Statement_Level,
8384 l_Module_Name,
8385 'Unit_of_measure_code :' ||
8386 x_product_txn_rec.unit_of_measure_code);
8387 Fnd_Log.String(l_Statement_Level,
8388 l_Module_Name,
8389 'Inventory_item_id :' ||
8390 x_product_txn_rec.inventory_item_id);
8391 Fnd_Log.String(l_Statement_Level,
8392 l_Module_Name,
8393 'Revision :' ||
8394 x_product_txn_rec.revision);
8395 Fnd_Log.String(l_Statement_Level,
8396 l_Module_Name,
8397 'Quantity :' ||
8398 x_product_txn_rec.quantity);
8399 Fnd_Log.String(l_Statement_Level,
8400 l_Module_Name,
8401 'Price_list_id :' ||
8402 x_product_txn_rec.price_list_id);
8403 Fnd_Log.String(l_Statement_Level,
8404 l_Module_Name,
8405 'Source Organization_id :' ||
8406 x_product_txn_rec.organization_id);
8407 Fnd_Log.String(l_Statement_Level,
8408 l_Module_Name,
8409 'Interface_to_om_flag :' ||
8410 x_product_txn_rec.interface_to_om_flag);
8411 Fnd_Log.String(l_Statement_Level,
8412 l_Module_Name,
8413 'Book_sales_order_flag :' ||
8414 x_product_txn_rec.book_sales_order_flag);
8415 Fnd_Log.String(l_Statement_Level,
8416 l_Module_Name,
8417 'Release_sales_order_flag :' ||
8418 x_product_txn_rec.release_sales_order_flag);
8419 Fnd_Log.String(l_Statement_Level,
8420 l_Module_Name,
8421 'Ship_sales_order_flag :' ||
8422 x_product_txn_rec.ship_sales_order_flag);
8423 Fnd_Log.String(l_Statement_Level,
8424 l_Module_Name,
8425 'Process_txn_flag :' ||
8426 x_product_txn_rec.process_txn_flag);
8427 Fnd_Log.String(l_Statement_Level,
8428 l_Module_Name,
8429 'Object_version_number :' ||
8430 x_product_txn_rec.object_version_number);
8431 END IF;
8432
8433 IF l_statement_level >= l_debug_level
8434 THEN
8435 Fnd_Log.string(l_statement_level,
8436 l_module_name || '.check_in_parameters',
8437 'product txn id is:' ||
8438 x_product_txn_rec.product_transaction_id);
8439 END IF;
8440
8441 -- check the required parameter
8442 Csd_Process_Util.check_reqd_param(p_param_value => x_product_txn_rec.product_transaction_id,
8443 p_param_name => 'product_transaction_id',
8444 p_api_name => l_api_name);
8445
8446 IF l_statement_level >= l_debug_level
8447 THEN
8448 Fnd_Log.string(l_statement_level,
8449 l_module_name || '.check_in_parameters',
8450 'product txn id is valid');
8451 END IF;
8452
8453 -- validate the prod_txn_id if it exists in csd_product_transactions
8454 IF NOT
8455 (Csd_Process_Util.validate_prod_txn_id(p_prod_txn_id => x_product_txn_rec.product_transaction_id))
8456 THEN
8457 IF l_exception_level >= l_debug_level
8458 THEN
8459 Fnd_Log.string(l_exception_level,
8460 l_module_name || '.check_in_parameters',
8461 'product txn id is not valid ');
8462 END IF;
8463 RAISE Fnd_Api.g_exc_error;
8464 END IF;
8465 IF l_statement_level >= l_debug_level
8466 THEN
8467 Fnd_Log.string(l_statement_level,
8468 l_module_name || '.check_in_parameters',
8469 'product txn id is valid ');
8470 END IF;
8471
8472 -- validate the prod_txn_status
8473 IF NVL(x_product_txn_rec.prod_txn_status, Fnd_Api.g_miss_char) <>
8474 Fnd_Api.g_miss_char
8475 THEN
8476 BEGIN
8477 SELECT 'x'
8478 INTO l_check
8479 FROM fnd_lookups
8480 WHERE lookup_type = 'CSD_PRODUCT_TXN_STATUS'
8481 AND lookup_code = x_product_txn_rec.prod_txn_status;
8482 IF l_statement_level >= l_debug_level
8483 THEN
8484 Fnd_Log.string(l_statement_level,
8485 l_module_name || '.check_in_parameters',
8486 'Product txn status is valid : ' ||
8487 x_product_txn_rec.prod_txn_status);
8488 END IF;
8489 EXCEPTION
8490 WHEN NO_DATA_FOUND THEN
8491 Fnd_Message.set_name('CSD', 'CSD_ERR_PROD_TXN_STATUS');
8492 IF l_exception_level >= l_debug_level
8493 THEN
8494 Fnd_Log.string(l_exception_level,
8495 l_module_name ||
8496 '.check_in_parameters',
8497 'Product txn status is invalid : ' ||
8498 x_product_txn_rec.prod_txn_status);
8499 END IF;
8500 Fnd_Msg_Pub.ADD;
8501 RAISE Fnd_Api.g_exc_error;
8502 END;
8503 END IF;
8504
8505 IF NVL(x_product_txn_rec.action_type, Fnd_Api.g_miss_char) <>
8506 Fnd_Api.g_miss_char
8507 THEN
8508 -- validate the action type
8509 IF NOT
8510 (Csd_Process_Util.validate_action_type(p_action_type => x_product_txn_rec.action_type))
8511 THEN
8512 IF l_exception_level >= l_debug_level
8513 THEN
8514 Fnd_Log.string(l_exception_level,
8515 l_module_name || '.check_in_parameters',
8516 'Action Type s invalid : ' ||
8517 x_product_txn_rec.Action_Type);
8518 END IF;
8519 RAISE Fnd_Api.g_exc_error;
8520 END IF;
8521 END IF;
8522
8523 IF NVL(x_product_txn_rec.action_code, Fnd_Api.g_miss_char) <>
8524 Fnd_Api.g_miss_char
8525 THEN
8526 -- validate the action code
8527 IF NOT
8528 (Csd_Process_Util.validate_action_code(p_action_code => x_product_txn_rec.action_code))
8529 THEN
8530 IF l_exception_level >= l_debug_level
8531 THEN
8532 Fnd_Log.string(l_exception_level,
8533 l_module_name || '.check_in_parameters',
8534 'Action Code is invalid : ' ||
8535 x_product_txn_rec.Action_Code);
8536 END IF;
8537 RAISE Fnd_Api.g_exc_error;
8538 END IF;
8539 END IF;
8540 -- Get Current submit_order_flag, book_order_flag, release_order_flag and Ship_Order_Flag
8541 -- statuses and Object_Version_Number values from database
8542 IF NVL(x_product_txn_rec.product_transaction_id, Fnd_Api.g_miss_num) <>
8543 Fnd_Api.g_miss_num
8544 THEN
8545 OPEN prod_txn(x_product_txn_rec.product_transaction_id);
8546 FETCH prod_txn
8547 INTO l_est_detail_id, l_repair_line_id, l_curr_submit_order_flag, l_curr_book_order_flag, l_curr_release_order_flag, l_curr_ship_order_flag, l_object_version_num;
8548 CLOSE prod_txn;
8549 END IF;
8550
8551 IF NVL(x_product_txn_rec.repair_line_id, Fnd_Api.g_miss_num) <>
8552 Fnd_Api.g_miss_num
8553 THEN
8554 IF x_product_txn_rec.repair_line_id <> l_repair_line_id
8555 THEN
8556 IF l_exception_level >= l_debug_level
8557 THEN
8558 Fnd_Log.string(l_exception_level,
8559 l_module_name || '.check_in_parameters',
8560 'Repair Line id can not be changed');
8561 END IF;
8562 RAISE Fnd_Api.g_exc_error;
8563 END IF;
8564 ELSE
8565 x_product_txn_rec.repair_line_id := l_repair_line_id;
8566 END IF;
8567
8568 IF x_product_txn_rec.action_type IN
8569 (C_Action_Type_Move_Out, C_Action_Type_Move_In)
8570 THEN
8571 -- get the incident id for the repair line
8572 BEGIN
8573 SELECT incident_id
8574 INTO l_incident_id
8575 FROM csd_repairs
8576 WHERE repair_line_id = l_repair_line_id;
8577 EXCEPTION
8578 WHEN NO_DATA_FOUND THEN
8579 Fnd_Message.set_name('CSD', 'CSD_API_INV_REP_LINE_ID');
8580 Fnd_Message.set_token('REPAIR_LINE_ID',
8581 l_repair_line_id);
8582 Fnd_Msg_Pub.ADD;
8583 IF l_statement_level >= l_debug_level
8584 THEN
8585 Fnd_Log.string(l_statement_level,
8586 l_module_name ||
8587 '.check_in_parameters',
8588 'Invalid repair line id ' ||
8589 x_product_txn_rec.repair_line_id);
8590 END IF;
8591 RAISE Fnd_Api.g_exc_error;
8592 END;
8593 IF l_incident_id IS NOT NULL
8594 THEN
8595 OPEN sr_rec(l_incident_id);
8596 FETCH sr_rec
8597 INTO l_party_id, l_account_id;
8598 CLOSE sr_rec;
8599 ELSE
8600 Fnd_Message.set_name('CSD', 'CSD_API_INV_SR_ID');
8601 Fnd_Message.set_token('INCIDENT_ID', l_incident_id);
8602 Fnd_Msg_Pub.ADD;
8603 IF (g_debug > 0)
8604 THEN
8605 Csd_Gen_Utility_Pvt.ADD('incident id missing ');
8606 END IF;
8607 RAISE Fnd_Api.g_exc_error;
8608 END IF;
8609
8610 -- assigning values for the order record
8611 l_order_rec.incident_id := l_incident_id;
8612 l_order_rec.party_id := l_party_id;
8613 l_order_rec.account_id := l_account_id;
8614 l_order_rec.org_id := x_Product_Txn_Rec.Organization_Id;
8615 -- Do further processing only when process transaction flag is 'Y'
8616 IF x_product_txn_rec.process_txn_flag = C_Yes
8617 THEN
8618 SAVEPOINT release_sales_order;
8619 -- Do further processing only when process transaction flag values for UI and database
8620 -- are different and release sales order flag at UI should be checked.
8621 IF NVL(l_curr_release_order_flag, 'N') <>
8622 x_product_txn_rec.release_sales_order_flag AND
8623 x_product_txn_rec.release_sales_order_flag = C_Yes
8624 THEN
8625 -- Sub Inventory column will have value if internal requisition has source sub inventory
8626 -- value else it will have null values.
8627 IF NVL(x_product_txn_rec.sub_inventory,
8628 Fnd_Api.g_miss_char) <> Fnd_Api.g_miss_char
8629 THEN
8630 l_order_rec.pick_from_subinventory := x_product_txn_rec.sub_inventory;
8631 l_order_rec.def_staging_subinventory := x_product_txn_rec.sub_inventory;
8632 END IF;
8633 -- get the default pick rule id
8634 -- Check Action Type and get appropriate picking rule definition
8635 --R12 Development Changes
8636 -- Changed code to take the profile value onlyif the input record
8637 -- picking_rule is null
8638 IF (x_product_txn_rec.picking_rule_id IS NULL)
8639 THEN
8640 IF x_product_txn_rec.Action_Type =
8641 C_ACTION_TYPE_MOVE_IN
8642 THEN
8643 Fnd_Profile.get('csd_pick_release_rule_defect_subinv',
8644 l_picking_rule_id);
8645 ELSIF x_product_txn_rec.Action_Type =
8646 C_ACTION_TYPE_MOVE_OUT
8647 THEN
8648 Fnd_Profile.get('csd_pick_release_rule_usable_subinv',
8649 l_picking_rule_id);
8650 END IF;
8651 ELSE
8652 l_picking_rule_id := x_product_txn_rec.picking_rule_id;
8653 END IF;
8654 -- fnd_profile.get('csd_def_pick_release_rule',l_picking_rule_id);
8655 IF l_Statement_level >= l_debug_level
8656 THEN
8657 Fnd_Log.string(l_Statement_level,
8658 l_module_name,
8659 'Default picking rule id :' ||
8660 l_Picking_Rule_Id);
8661 END IF;
8662 BEGIN
8663 SELECT picking_rule_id
8664 INTO l_picking_rule_id
8665 FROM wsh_picking_rules
8666 WHERE picking_rule_id = l_picking_rule_id
8667 AND SYSDATE BETWEEN
8668 NVL(start_date_active, SYSDATE) AND
8669 NVL(end_date_active, SYSDATE + 1);
8670 l_order_rec.picking_rule_id := l_picking_rule_id;
8671 EXCEPTION
8672 WHEN NO_DATA_FOUND THEN
8673 Fnd_Message.set_name('CSD',
8674 'CSD_API_INV_PICKING_RULE_ID');
8675 Fnd_Message.set_token('PICKING_RULE_ID',
8676 l_picking_rule_id);
8677 Fnd_Msg_Pub.ADD;
8678 IF l_exception_level >= l_debug_level
8679 THEN
8680 Fnd_Log.string(l_exception_level,
8681 l_module_name,
8682 ' Default picking rule id not found');
8683 END IF;
8684 RAISE release_order_excep;
8685 END;
8686 BEGIN
8687 -- check released_status column value for the delivery line, if even one record is found
8688 -- with status ready_for_release or backordered then whole order header needs to be pick released
8689 SELECT 'Y'
8690 INTO l_order_to_be_pickreleased
8691 FROM wsh_delivery_details a
8692 WHERE a.source_header_id =
8693 x_product_txn_rec.order_header_id
8694 AND a.source_line_id =
8695 x_product_txn_rec.order_line_id
8696 AND a.released_status IN
8697 (c_ready_for_release, c_backordered)
8698 AND ROWNUM < 2;
8699 IF l_statement_level >= l_debug_level
8700 THEN
8701 Fnd_Log.string(l_statement_level,
8702 l_module_name,
8703 'There are lines eligible for pick release');
8704 END IF;
8705 EXCEPTION
8706 WHEN NO_DATA_FOUND THEN
8707 -- there are no records to be pick released using public api
8708 l_order_to_be_pickreleased := C_No;
8709 IF l_statement_level >= l_debug_level
8710 THEN
8711 Fnd_Log.string(l_statement_level,
8712 l_module_name,
8713 'There are no lines eligible for pick releas');
8714 END IF;
8715 END;
8716 l_order_rec.order_header_id := x_product_txn_rec.order_header_id;
8717 IF l_order_to_be_pickreleased = C_Yes
8718 THEN
8719 IF l_statement_level >= l_debug_level
8720 THEN
8721 Fnd_Log.string(l_statement_level,
8722 l_module_name,
8723 'Calling process_sales_order to release so');
8724 END IF;
8725 Csd_Process_Pvt.process_sales_order(p_api_version => 1.0,
8726 p_commit => Fnd_Api.g_false,
8727 p_init_msg_list => Fnd_Api.g_true,
8728 p_validation_level => Fnd_Api.g_valid_level_full,
8729 p_action => C_Action_Pick_Release,
8730 p_order_rec => l_order_rec,
8731 x_return_status => x_return_status,
8732 x_msg_count => x_msg_count,
8733 x_msg_data => x_msg_data);
8734 IF (x_return_status = Fnd_Api.g_ret_sts_error)
8735 THEN
8736 IF l_exception_level >= l_debug_level
8737 THEN
8738 Fnd_Log.string(l_exception_level,
8739 l_module_name,
8740 'csd_process_pvt.process_sales_order failed');
8741 END IF;
8742 RAISE release_order_excep;
8743 ELSE
8744 IF l_statement_level >= l_debug_level
8745 THEN
8746 Fnd_Log.string(l_statement_level,
8747 l_module_name,
8748 'process_sales_order was successful');
8749 END IF;
8750 END IF; -- X_Return_Status is Error
8751 END IF; --l_order_to_be_pickreleased = 'y' then
8752 -- Check if there are any delivery lines in status in 'Ready To Releas',
8753 -- Released To WareHouse', 'Back ORdered' for a given order header id and
8754 -- order line id, if so line is not eligible to stamp for 'Released' status.
8755 BEGIN
8756 SELECT 'Y'
8757 INTO l_order_to_Be_PickReleased
8758 FROM wsh_Delivery_Details
8759 WHERE source_header_id =
8760 x_product_txn_rec.order_header_id
8761 AND source_line_id =
8762 x_product_txn_Rec.Order_line_id
8763 AND SOURCE_CODE = 'OE' /*Fixed for bug#5846054*/
8764 AND released_Status IN
8765 (c_ready_for_release, c_backordered,
8766 c_release_to_warehouse);
8767 IF l_statement_level >= l_debug_level
8768 THEN
8769 Fnd_Log.string(l_statement_level,
8770 l_module_name,
8771 'Still there are some lines to be pick released');
8772 END IF;
8773 EXCEPTION
8774 WHEN NO_DATA_FOUND THEN
8775 l_order_to_Be_PickReleased := 'N';
8776 IF l_statement_level >= l_debug_level
8777 THEN
8778 Fnd_Log.string(l_statement_level,
8779 l_module_name,
8780 'There are no lines to be pick released');
8781 END IF;
8782 WHEN TOO_MANY_ROWS THEN
8783 IF l_statement_level >= l_debug_level
8784 THEN
8785 Fnd_Log.string(l_statement_level,
8786 l_module_name,
8787 'More then one line to be pick released');
8788 END IF;
8789 l_order_to_Be_PickReleased := 'Y';
8790 END;
8791 IF l_order_TO_Be_PickReleased = 'N'
8792 THEN
8793 -- since pick release process is complete update product transaction lines
8794 FOR released_line_rec IN released_lines_cur(x_product_txn_rec.order_header_id,
8795 x_product_txn_rec.order_line_id)
8796 LOOP
8797 -- update product transaction tables
8798 UPDATE csd_product_transactions
8799 SET prod_txn_status = C_Status_Released,
8800 release_sales_order_flag = C_Yes,
8801 object_version_number = Object_Version_Number + 1,
8802 Last_Update_Date = SYSDATE,
8803 Last_Updated_By = Fnd_Global.User_Id,
8804 Last_Update_login = Fnd_Global.Login_Id
8805 WHERE order_header_id =
8806 released_line_rec.source_header_id
8807 AND order_line_id =
8808 released_line_rec.source_line_id
8809 AND NVL(release_sales_order_flag, C_No) = C_No;
8810 --
8811 IF SQL%FOUND
8812 THEN
8813 -- Product Transaction records are updated.
8814 IF l_statement_level >= l_debug_level
8815 THEN
8816 Fnd_Log.string(l_statement_level,
8817 l_module_name,
8818 'Product transaction records are updated with Released Status');
8819 Fnd_Log.string(l_statement_level,
8820 l_module_name,
8821 'Internal Order header id :' ||
8822 x_product_txn_rec.order_header_id);
8823 Fnd_Log.string(l_statement_level,
8824 l_module_name,
8825 'Internal Order Line id :' ||
8826 x_product_txn_rec.order_Line_id);
8827 END IF;
8828 /****************************
8829 RO is not udpated as it is does not make sense to update RO record
8830 when ever its product transactions are released. Not applicable to internal ROs.
8831 update csd_repairs
8832 set ro_txn_status = 'OM_RELEASED' ,
8833 object_version_number = Object_Version_Number + 1,
8834 Last_Update_Date = Sysdate,
8835 Last_Updated_By = Fnd_Global.User_Id,
8836 Last_Update_login = Fnd_Global.Login_Id
8837 where repair_line_id = x_product_txn_rec.repair_line_id;
8838 if sql%notfound then
8839 fnd_message.set_name('CSD','CSD_ERR_REPAIRS_UPDATE');
8840 fnd_message.set_token('REPAIR_LINE_ID',x_product_txn_rec.repair_line_id);
8841 fnd_msg_pub.add;
8842 raise release_order_excep;
8843 end if;
8844 ********************************/
8845 ELSE
8846 -- No Product Transaction records are updated.
8847 IF l_statement_level >= l_debug_level
8848 THEN
8849 Fnd_Log.string(l_statement_level,
8850 l_module_name,
8851 'No valid product transaction record found to update release status');
8852 Fnd_Log.string(l_statement_level,
8853 l_module_name,
8854 'Internal Order header id :' ||
8855 x_product_txn_rec.order_header_id);
8856 Fnd_Log.string(l_statement_level,
8857 l_module_name,
8858 'Internal Order Line id :' ||
8859 x_product_txn_rec.order_Line_id);
8860 END IF;
8861 END IF; --if sql%found then
8862 END LOOP; --released_line_rec in
8863 END IF; -- l_order_to_be_PickReleased
8864 END IF; --end of pick-release sales order
8865
8866 -- Allow auto shipping only when ship_order_flag has different values for UI and database values.
8867 -- and ship_sales_order_flag is checked in UI.
8868 -- Ship-Confirm radio button in UI is disabled for items that are serial controlled at SO issue.
8869 -- Ship-Confirm radio button is disabled in UIwhen more then one delivery lines exist for a
8870 -- given order line.
8871 IF NVL(l_curr_ship_order_flag, 'N') <>
8872 x_product_txn_rec.ship_sales_order_flag AND
8873 x_product_txn_rec.ship_sales_order_flag = C_Yes
8874 THEN
8875 SAVEPOINT ship_sales_order;
8876 l_order_rec.order_header_id := x_product_txn_rec.order_header_id;
8877 l_order_rec.order_line_id := x_product_txn_rec.order_line_id;
8878 l_order_rec.serial_number := x_product_txn_rec.source_serial_number; -- from 11.5.10 release
8879 -- Check if there is a delivery line eligible for shipping for a given order line id
8880 --Initialize l_Released_Status to NULL
8881 l_Released_Status := NULL;
8882 BEGIN
8883 -- select C_Yes
8884 -- into l_allow_ship
8885 SELECT Released_Status
8886 INTO l_Released_Status
8887 FROM wsh_delivery_details
8888 WHERE source_header_id =
8889 l_order_rec.order_header_id
8890 AND source_line_id = l_order_rec.order_line_id
8891 AND released_status IN (C_Staged_PickConfirmed,
8892 C_Release_to_warehouse)
8893 AND SOURCE_CODE = 'OE'; /*Fixed for bug#5840654 */
8894 EXCEPTION
8895 WHEN NO_DATA_FOUND THEN
8896 l_allow_ship := C_No;
8897 -- fnd_message.set_name('csd','csd_release_failed');
8898 Fnd_Message.set_name('CSD',
8899 'CSD_ORDER_LINE_NOT_SHIPABLE');
8900 Fnd_Message.set_token('ORDER_LINE_ID',
8901 l_order_rec.order_line_id);
8902 Fnd_Msg_Pub.ADD;
8903 IF l_statement_level >= l_debug_level
8904 THEN
8905 Fnd_Log.string(l_statement_level,
8906 l_module_name,
8907 'Order line id ' ||
8908 l_Order_rec.Order_Line_id ||
8909 ' is not eligible for shipping.');
8910 END IF;
8911 RAISE ship_order_excep;
8912 WHEN TOO_MANY_ROWS THEN
8913 Fnd_Message.set_name('CSD',
8914 'CSD_TOO_MANY_ROWS_SHIPABLE');
8915 Fnd_Message.set_token('ORDER_LINE_ID',
8916 l_order_rec.order_line_id);
8917 Fnd_Msg_Pub.ADD;
8918 IF l_statement_level >= l_debug_level
8919 THEN
8920 Fnd_Log.string(l_statement_level,
8921 l_module_name,
8922 'Order line id ' ||
8923 l_Order_rec.Order_Line_id ||
8924 ' has more then one delivery lines.');
8925 END IF;
8926 END;
8927 -- if l_allow_ship = C_Yes then
8928 IF l_Released_Status = C_Staged_PickConfirmed
8929 THEN
8930 IF l_statement_level >= l_debug_level
8931 THEN
8932 Fnd_Log.string(l_statement_level,
8933 l_module_name,
8934 'Calling Process Sales Order API');
8935 END IF;
8936 Csd_Process_Pvt.process_sales_order(p_api_version => 1.0,
8937 p_commit => Fnd_Api.g_false,
8938 p_init_msg_list => Fnd_Api.g_true,
8939 p_validation_level => Fnd_Api.g_valid_level_full,
8940 p_action => C_Action_Ship,
8941 p_order_rec => l_order_rec,
8942 x_return_status => x_return_status,
8943 x_msg_count => x_msg_count,
8944 x_msg_data => x_msg_data);
8945 IF NOT (x_return_status = Fnd_Api.g_ret_sts_success)
8946 THEN
8947 IF l_statement_level >= l_debug_level
8948 THEN
8949 Fnd_Log.string(l_statement_level,
8950 l_module_name,
8951 ' process sales order failed');
8952 END IF;
8953 RAISE ship_order_excep;
8954 END IF; -- If x_return_status <> fnd_api.g_ret_sts_success
8955 END IF; -- l_allow_ship = C_Yes
8956 -- Check if any of the delivery lines status are less then 'Shipped'
8957 -- for a given order header id and order line id , if so do not update
8958 -- product txn lines with Shipped status, if not then update product txn table
8959 BEGIN
8960 SELECT 'Y'
8961 INTO l_order_to_Be_Shipped
8962 FROM wsh_Delivery_Details
8963 WHERE source_header_id =
8964 x_product_txn_rec.order_header_id
8965 AND source_line_id =
8966 x_product_txn_Rec.Order_line_id
8967 AND SOURCE_CODE = 'OE' /*Fixed for bug#5846054*/
8968 AND released_Status IN
8969 (c_ready_for_release, c_backordered,
8970 c_release_to_warehouse,
8971 c_staged_pickconfirmed);
8972 EXCEPTION
8973 WHEN NO_DATA_FOUND THEN
8974 l_order_to_Be_shipped := 'N';
8975 END;
8976
8977 IF l_order_to_Be_Shipped = 'N'
8978 THEN
8979 -- since there are no records to be shipped
8980 -- shipping process is complete update product transaction lines
8981 FOR Shipped_line_rec IN Shipped_lines_cur(x_product_txn_rec.order_header_id,
8982 x_product_txn_rec.Order_line_id)
8983 LOOP
8984 -- update product transaction tables
8985 UPDATE csd_product_transactions
8986 SET -- prod_txn_status = C_Status_Shipped ,
8987 release_sales_order_flag = C_Yes,
8988 ship_sales_order_flag = C_Yes,
8989 object_version_number = Object_Version_Number + 1,
8990 Last_Update_Date = SYSDATE,
8991 Last_Updated_By = Fnd_Global.User_Id,
8992 Last_Update_login = Fnd_Global.Login_Id
8993 WHERE order_header_id =
8994 shipped_line_rec.source_header_id
8995 AND order_line_id =
8996 shipped_line_rec.source_line_id
8997 AND NVL(ship_sales_order_flag, C_No) = C_No;
8998 --
8999 IF SQL%FOUND
9000 THEN
9001 -- Product Transaction records are updated.
9002 IF l_statement_level >= l_debug_level
9003 THEN
9004 Fnd_Log.string(l_statement_level,
9005 l_module_name,
9006 'Product transaction records are updated with Shipped Status');
9007 Fnd_Log.string(l_statement_level,
9008 l_module_name,
9009 'Internal Order header id :' ||
9010 x_product_txn_rec.order_header_id);
9011 Fnd_Log.string(l_statement_level,
9012 l_module_name,
9013 'Internal Order Line id :' ||
9014 x_product_txn_rec.order_Line_id);
9015 END IF;
9016 /*****************
9017 No need to update repairs block when ever its product transaction
9018 line is shipped. One repair order line can have more then one product
9019 transaction line and if we update RO when ever it is released or
9020 shipped then ro_txn_Status will not be of much use.
9021 Update csd_repairs
9022 Set ro_txn_status = 'OM_SHIPPED' ,
9023 object_version_number = Object_Version_Number + 1,
9024 Last_Update_Date = Sysdate,
9025 Last_Updated_By = Fnd_Global.User_Id,
9026 Last_Update_login = Fnd_Global.Login_Id
9027 Where repair_line_id = x_product_txn_rec.repair_line_id;
9028 If sql%notfound then
9029 fnd_message.set_name('CSD','CSD_ERR_REPAIRS_UPDATE');
9030 fnd_message.set_token('REPAIR_LINE_ID',x_product_txn_rec.repair_line_id);
9031 fnd_msg_pub.add;
9032 Raise release_order_excep;
9033 End if;
9034 *****************/
9035 ELSE
9036 -- No Product Transaction records are updated.
9037 IF l_statement_level >= l_debug_level
9038 THEN
9039 Fnd_Log.string(l_statement_level,
9040 l_module_name,
9041 'No valid product transaction record found to update to shipped status');
9042 Fnd_Log.string(l_statement_level,
9043 l_module_name,
9044 'Internal Order header id :' ||
9045 x_product_txn_rec.order_header_id);
9046 Fnd_Log.string(l_statement_level,
9047 l_module_name,
9048 'Internal Order Line id :' ||
9049 x_product_txn_rec.order_Line_id);
9050 END IF;
9051 END IF; --if sql%found then
9052 END LOOP; --shipped_line_rec in
9053 END IF; -- if l_order_to_be_shipped
9054 END IF; -- end of ship sales order
9055 END IF; --end of process txn
9056 END IF; -- Action Type = MOVE_OUt
9057 -- standard check of p_commit.
9058 IF Fnd_Api.to_boolean(p_commit)
9059 THEN
9060 COMMIT WORK;
9061 END IF;
9062 EXCEPTION
9063 WHEN release_order_excep THEN
9064 -- Set return status to unexpected error
9065 x_return_status := Fnd_Api.g_ret_sts_success;
9066 -- If there is any error then rollback
9067 ROLLBACK TO release_sales_order;
9068 -- Standard procedure to get error message count and error message is also returned
9069 -- if error message count is 1
9070 Fnd_Msg_Pub.count_and_get(p_count => x_msg_count,
9071 p_data => x_msg_data);
9072 WHEN ship_order_excep THEN
9073 -- Set return status to unexpected error
9074 x_return_status := Fnd_Api.g_ret_sts_success;
9075 -- If there is any error then rollback
9076 ROLLBACK TO ship_sales_order;
9077 -- Standard procedure to get error message count and error message is also returned
9078 -- if error message count is 1
9079 Fnd_Msg_Pub.count_and_get(p_count => x_msg_count,
9080 p_data => x_msg_data);
9081 WHEN Fnd_Api.g_exc_error THEN
9082 -- Set return status to unexpected error
9083 x_return_status := Fnd_Api.g_ret_sts_error;
9084 -- If there is any error then rollback
9085 ROLLBACK TO update_iro_product_txn;
9086 -- Standard procedure to get error message count and error message is also returned
9087 -- if error message count is 1
9088 Fnd_Msg_Pub.count_and_get(p_count => x_msg_count,
9089 p_data => x_msg_data);
9090 WHEN Fnd_Api.g_exc_unexpected_error THEN
9091 -- Set return status to unexpected error
9092 x_return_status := Fnd_Api.g_ret_sts_unexp_error;
9093 -- If there is any error then rollback
9094 ROLLBACK TO update_iro_product_txn;
9095 -- Standard procedure to get error message count and error message is also returned
9096 -- if error message count is 1
9097 Fnd_Msg_Pub.count_and_get(p_count => x_msg_count,
9098 p_data => x_msg_data);
9099 WHEN OTHERS THEN
9100 -- Set return status to unexpected error
9101 x_return_status := Fnd_Api.g_ret_sts_unexp_error;
9102 -- If there is any error then rollback
9103 ROLLBACK TO update_iro_product_txn;
9104 IF Fnd_Msg_Pub.check_msg_level(Fnd_Msg_Pub.g_msg_lvl_unexp_error)
9105 THEN
9106 -- Standard way to add sql error message to stack
9107 Fnd_Msg_Pub.add_exc_msg(g_pkg_name, l_api_name);
9108 END IF;
9109 -- Standard procedure to get error message count and error message is also returned
9110 -- if error message count is 1
9111 Fnd_Msg_Pub.count_and_get(p_count => x_msg_count,
9112 p_data => x_msg_data);
9113 END update_iro_product_txn;
9114
9115
9116 /*----------------------------------------------------------------------*/
9117 /*** Forward porting bug# 3877328 */
9118 /*----------------------------------------------------------------------*/
9119 /* procedure name: create_default_prod_txn_wrapr */
9120 /* description : Is a wrapper procedure which does validations before */
9121 /* calling procedure create_default_prod_txn. */
9122 /* This API will have same parameters as procedure */
9123 /* create_default_prod_txn. After successful validation */
9124 /* wrapper API will pass same input parameters. */
9125 /*----------------------------------------------------------------------*/
9126
9127 PROCEDURE Create_Default_Prod_Txn_wrapr(p_api_version IN NUMBER,
9128 p_commit IN VARCHAR2,
9129 p_init_msg_list IN VARCHAR2,
9130 p_validation_level IN NUMBER,
9131 p_repair_line_id IN NUMBER,
9132 x_return_status OUT NOCOPY VARCHAR2,
9133 x_msg_count OUT NOCOPY NUMBER,
9134 x_msg_data OUT NOCOPY VARCHAR2,
9135 x_Logistics_KeyAttr_Tbl OUT NOCOPY Csd_Process_Pvt.Logistics_KeyAttr_Tbl_Type) IS
9136 l_api_name CONSTANT VARCHAR2(30) := 'Create_Default_Prod_Txn_Wrapr';
9137 l_api_version CONSTANT NUMBER := 1.0;
9138 l_msg_count NUMBER;
9139 l_msg_data VARCHAR2(2000);
9140 l_Serial_num_Control_Code NUMBER;
9141 l_RO_Status VARCHAR2(30);
9142 l_RO_Status_Meaning VARCHAR2(80);
9143 l_RO_Quantity NUMBER;
9144 l_Inventory_Item_id NUMBER;
9145 l_RO_Repair_Type_Ref VARCHAR2(30);
9146 l_Prod_Txn_Lines_Count NUMBER;
9147 l_RO_Number NUMBER;
9148 l_Service_Valdn_Org_Name VARCHAR2(240);
9149 l_Item_Name VARCHAR2(240);
9150 -- Define Constants here
9151 C_RO_Status_Open VARCHAR2(30) := 'O';
9152 C_Repair_Type_Ref_Standard VARCHAR2(10) := 'SR';
9153
9154 i BINARY_INTEGER; -- loop variable
9155
9156 -- Define Cursor to get all product transaction lines rec information for a repair order
9157 CURSOR Logistic_KeyAttr_Cur_Type(p_Repair_Line_Id IN NUMBER) IS
9158 SELECT cpt.product_Transaction_Id,
9159 ced.Estimate_Detail_Id,
9160 ced.order_header_Id,
9161 ced.order_Line_Id
9162 FROM csd_product_Transactions cpt, cs_estimate_Details ced
9163 WHERE cpt.repair_line_id = p_Repair_Line_Id
9164 AND cpt.estimate_detail_id = ced.estimate_detail_id;
9165 BEGIN
9166 -- Standard call to check for call compatibility.
9167 IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
9168 p_api_version,
9169 l_api_name,
9170 G_PKG_NAME)
9171 THEN
9172 RAISE Fnd_Api.G_Exc_UnExpected_Error;
9173 END IF;
9174
9175 -- Initialize message list if p_init_msg_list is set to TRUE.
9176 IF Fnd_Api.to_Boolean(p_init_msg_list)
9177 THEN
9178 Fnd_Msg_Pub.initialize;
9179 END IF;
9180
9181 -- Initialize API return status to success
9182 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
9183
9184 -- Api body starts
9185 IF (g_debug > 0)
9186 THEN
9187 Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
9188 p_api_name => l_api_name);
9189 END IF;
9190 IF (g_debug > 0)
9191 THEN
9192 Csd_Gen_Utility_Pvt.ADD('Checking required parameter:(repair_line_id)');
9193 END IF;
9194 -- Check the required parameter
9195 Csd_Process_Util.Check_Reqd_Param(p_param_value => p_Repair_Line_id,
9196 p_param_name => 'Repair_Line_Id',
9197 p_api_name => l_api_name);
9198 -- Validate Repair_Line_id and check RO status
9199 IF (g_debug > 0)
9200 THEN
9201 Csd_Gen_Utility_Pvt.ADD('Required parameter:(repair_line_id) has value' ||
9202 p_Repair_Line_id);
9203 END IF;
9204 BEGIN
9205 IF (g_debug > 0)
9206 THEN
9207 Csd_Gen_Utility_Pvt.ADD('Querying csd_repairs_v view');
9208 END IF;
9209 SELECT dra.status,
9210 dra.Quantity,
9211 dra.Inventory_Item_Id,
9212 drtvl.Repair_Type_Ref,
9213 dra.Repair_Number,
9214 fndl2.meaning
9215 INTO l_RO_Status,
9216 l_RO_Quantity,
9217 l_Inventory_Item_id,
9218 l_RO_Repair_Type_Ref,
9219 l_RO_Number,
9220 l_RO_Status_Meaning
9221 FROM csd_repairs dra, fnd_lookups fndl2, csd_repair_types_vl drtvl
9222 WHERE repair_line_id = p_Repair_line_id
9223 and dra.repair_type_id = drtvl.repair_type_id
9224 and dra.status = fndl2.lookup_code
9225 and fndl2.lookup_type = 'CSD_REPAIR_STATUS';
9226 -- If Repair Number is Null then Repair_line_id is invalid
9227 -- Now Check RO_Status , if RO_Status is not Open then raise error
9228 IF l_RO_Status <> C_RO_Status_Open
9229 THEN
9230 -- Display message: Repair Order is in status || l_RO_Status. Default product transaction lines are
9231 -- not created.
9232 -- Message Code CSD_RO_NOT_OPEN_NO_PRODTXN_LINES
9233 -- Raise Error message
9234 Fnd_Message.SET_NAME('CSD',
9235 'CSD_RO_NOT_OPEN_NO_PRODTXN_LNS');
9236 Fnd_Message.SET_TOKEN('RO_NUMBER', l_RO_Number);
9237 Fnd_Message.SET_TOKEN('RO_STATUS', l_RO_Status_Meaning);
9238 Fnd_Msg_Pub.ADD;
9239 RAISE Fnd_Api.G_EXC_ERROR;
9240 END IF;
9241 -- Check if repair Type Ref is Standard
9242 IF l_RO_Repair_Type_Ref = C_Repair_TYpe_Ref_Standard
9243 THEN
9244 -- Display message: Default product transaction lines are not created for standard repair type ref
9245 -- CSD_STD_REP_TYPE_NO_PRODUCTXN_LINES
9246 Fnd_Message.SET_NAME('CSD',
9247 'CSD_STD_REPTYPE_NO_PRODTXN_LNS');
9248 Fnd_Message.SET_TOKEN('RO_NUMBER', l_RO_Number);
9249 Fnd_Msg_Pub.ADD;
9250 RAISE Fnd_Api.G_EXC_ERROR;
9251 END IF;
9252 -- Check Serial control code if quantity is greater then 1
9253 IF l_RO_Quantity > 1
9254 THEN
9255 BEGIN
9256 SELECT Serial_Number_Control_COde
9257 INTO l_Serial_num_COntrol_Code
9258 FROM Mtl_System_Items_B
9259 WHERE Inventory_Item_Id = l_Inventory_Item_Id
9260 AND Organization_id = Cs_Std.Get_Item_Valdn_Orgzn_Id;
9261 -- If item is serial controlled then raise error
9262 IF l_Serial_num_COntrol_Code > 1
9263 THEN
9264 -- Display Message: RO quantity can not be greater then for serial controlled items.
9265 -- CSD_RO_QTY_MORE_FOR_SERIAL_ITEM
9266 -- Raise G_Exc_Error,
9267 Fnd_Message.SET_NAME('CSD',
9268 'CSD_RO_QTY_MORE_FOR_SRLCT_ITEM');
9269 Fnd_Msg_Pub.ADD;
9270 RAISE Fnd_Api.G_EXC_ERROR;
9271 END IF;
9272 EXCEPTION
9273 WHEN NO_DATA_FOUND THEN
9274 -- Get Item Name
9275 SELECT items.concatenated_segments
9276 INTO l_Item_Name
9277 FROM mtl_system_items_vl items, csd_repairs dra
9278 WHERE dra.repair_line_id = p_Repair_Line_Id
9279 and dra.inventory_item_id = items.inventory_item_id
9280 and items.organization_id = cs_std.get_item_valdn_orgzn_id;
9281
9282 -- Get Service Validation Org name
9283 SELECT Name
9284 INTO l_Service_Valdn_Org_Name
9285 FROM Hr_Organization_Units
9286 WHERE Organization_id =
9287 Cs_Std.Get_Item_Valdn_Orgzn_Id;
9288
9289 Fnd_Message.SET_NAME('CSD',
9290 'CSD_NO_ITEM_FOR_SRV_VALDN_ORG');
9291 Fnd_Message.Set_Token('ITEM', l_Item_Name);
9292 Fnd_Message.Set_Token('ORG_NAME',
9293 l_Service_Valdn_Org_Name);
9294 Fnd_Msg_Pub.ADD;
9295 RAISE Fnd_Api.G_EXC_ERROR;
9296
9297 END;
9298 END IF;
9299 -- CHeck if there are any product txn lines for a given repair line id
9300 BEGIN
9301 SELECT COUNT(Product_Transaction_Id)
9302 INTO l_Prod_Txn_Lines_Count
9303 FROM csd_product_Transactions
9304 WHERE Repair_Line_id = p_Repair_Line_Id;
9305 IF l_Prod_Txn_Lines_Count > 0
9306 THEN
9307 -- Default product transaction lines are not created as product transaction lines exist
9308 -- for Repair Order : l_RO_number
9309 -- CSD_RO_HAS_PRODTXN_LINES
9310 -- RAise G_Exc_Error
9311 Fnd_Message.SET_NAME('CSD',
9312 'CSD_RO_HAS_PRODUCT_TXN_LINES');
9313 Fnd_Message.SET_TOKEN('RO_NUMBER', l_RO_Number);
9314 Fnd_Msg_Pub.ADD;
9315 RAISE Fnd_Api.G_EXC_ERROR;
9316 END IF;
9317 END;
9318 EXCEPTION
9319 WHEN NO_DATA_FOUND THEN
9320 -- Message Code CSD_REPAIR_LINE_ID_INVALID
9321 -- Display message; Invalid repair line id is passed
9322 Fnd_Message.SET_NAME('CSD', 'CSD_API_INV_REP_LINE_ID');
9323 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID', P_Repair_Line_ID);
9324 Fnd_Msg_Pub.ADD;
9325 RAISE Fnd_Api.G_EXC_ERROR;
9326 END;
9327 -- Now call Default Product Txn lines API
9328
9329 create_default_prod_txn(p_api_version,
9330 p_commit,
9331 p_init_msg_list,
9332 p_validation_level,
9333 p_repair_line_id,
9334 NULL,
9335 NULL,
9336 NULL,
9337 Fnd_Api.g_false,
9338 x_return_status,
9339 x_msg_count,
9340 x_msg_Data);
9341
9342 -- Once default product transaction lines are created successfully,
9343 -- assign new entities to new out variable x_Logistics_KeyAttr_Tbl.
9344 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
9345 THEN
9346 RAISE Fnd_Api.G_EXC_ERROR;
9347 ELSE
9348 -- New code added here
9349 i := 0; -- Initialize loop variable to zero
9350 FOR Logistic_KeyAttr_Rec IN Logistic_KeyAttr_Cur_Type(p_Repair_line_id)
9351 LOOP
9352 i := i + 1;
9353 x_Logistics_KeyAttr_Tbl(i).Product_Transaction_Id := Logistic_KeyAttr_Rec.Product_Transaction_Id;
9354 x_Logistics_KeyAttr_Tbl(i).Estimate_Detail_Id := Logistic_KeyAttr_Rec.Estimate_Detail_Id;
9355 x_Logistics_KeyAttr_Tbl(i).Order_Header_Id := Logistic_KeyAttr_Rec.Order_Header_Id;
9356 x_Logistics_KeyAttr_Tbl(i).Order_Line_Id := Logistic_KeyAttr_Rec.Order_Line_Id;
9357 END LOOP;
9358 END IF;
9359
9360 EXCEPTION
9361 WHEN Fnd_Api.G_EXC_ERROR THEN
9362 x_return_status := Fnd_Api.G_RET_STS_ERROR;
9363 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9364 p_data => x_msg_data);
9365 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
9366 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
9367 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9368 p_data => x_msg_data);
9369 WHEN OTHERS THEN
9370 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
9371 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
9372 THEN
9373 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
9374 END IF;
9375 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9376 p_data => x_msg_data);
9377 END Create_Default_Prod_Txn_Wrapr;
9378
9379 /*-----------------------------------------------------------------------------------------------------------*/
9380 /* R12 Quality Integration */
9381 /* procedure name: create_repair_task */
9382 /* description : procedure used to create DR specific tasks in Depot tables */
9383 /* Called from : Depot Repair Form to Create Task */
9384 /* Input Parm : p_api_version NUMBER Required Api Version number */
9385 /* p_init_msg_list VARCHAR2 Optional Initializes message stack if fnd_api.g_true, */
9386 /* default value is fnd_api.g_false */
9387 /* p_commit VARCHAR2 Optional Commits in API if fnd_api.g_true, default */
9388 /* fnd_api.g_false */
9389 /* p_validation_level NUMBER Optional API uses this parameter to determine which */
9390 /* validation steps must be done and which steps */
9391 /* should be skipped. */
9392 /* p_CREATE_REPAIR_TASK_REC RECORD Required Columns are in the Record REPAIR_TASK_REC_TYPE */
9393 /* Output Parm : x_return_status VARCHAR2 Return status after the call. The status can be*/
9394 /* fnd_api.g_ret_sts_success (success) */
9395 /* fnd_api.g_ret_sts_error (error) */
9396 /* fnd_api.g_ret_sts_unexp_error (unexpected) */
9397 /* x_msg_count NUMBER Number of messages in the message stack */
9398 /* x_msg_data VARCHAR2 Message text if x_msg_count >= 1 */
9399 /* x_task_id NUMBER Task Id of the created Task */
9400 /*-----------------------------------------------------------------------------------------------------------*/
9401 PROCEDURE CREATE_REPAIR_TASK(p_api_version IN NUMBER,
9402 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_false,
9403 p_commit IN VARCHAR2 := Fnd_Api.g_false,
9404 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
9405 p_create_repair_task_rec IN REPAIR_TASK_REC,
9406 x_return_status OUT NOCOPY VARCHAR2,
9407 x_msg_count OUT NOCOPY NUMBER,
9408 x_msg_data OUT NOCOPY VARCHAR2,
9409 x_repair_task_id OUT NOCOPY NUMBER) IS
9410
9411 l_api_name CONSTANT VARCHAR2(30) := 'CREATE_REPAIR_TASK';
9412 l_api_version CONSTANT NUMBER := 1.0;
9413 l_msg_count NUMBER;
9414 l_msg_data VARCHAR2(2000);
9415 l_msg_index NUMBER;
9416 l_return_status VARCHAR2(1);
9417
9418 -- Task record
9419 l_create_task_rec Csd_Process_Pvt.REPAIR_TASK_REC := p_create_repair_task_rec;
9420 l_applicable_qa_plans VARCHAR2(1);
9421 l_plan_txn_ids VARCHAR2(5000);
9422 l_dummy_char VARCHAR2(32000);
9423
9424 -- define variables to define fnd_log debug levels
9425 l_debug_level NUMBER := Fnd_Log.g_current_runtime_level;
9426 -- examples : 1- copying buffer x to y : low level detailed messages
9427 l_statement_level NUMBER := Fnd_Log.level_statement;
9428 -- examples : 2- key progress events : starting business transactions
9429 l_procedure_level NUMBER := Fnd_Log.level_procedure;
9430 -- examples : 3- event : calling an api, key progress events
9431 l_event_level NUMBER := Fnd_Log.level_event;
9432 -- examples : 4- exception internal software failure condition
9433 l_exception_level NUMBER := Fnd_Log.level_exception;
9434 -- examples : 5- error end user erros
9435 l_error_level NUMBER := Fnd_Log.level_error;
9436 l_module_name VARCHAR2(240) := 'csd.plsql.csd_process_pvt.create_repair_task';
9437
9438 BEGIN
9439 -- -----------------
9440 -- Begin create repair task
9441 -- -----------------
9442
9443 -- Standard Start of API savepoint
9444 IF l_statement_level >= l_debug_level
9445 THEN
9446 Fnd_Log.string(l_statement_level, l_module_name, 'begin');
9447 END IF;
9448 SAVEPOINT create_repair_task;
9449
9450 -- Standard call to check for call compatibility.
9451 IF l_statement_level >= l_debug_level
9452 THEN
9453 Fnd_Log.string(l_statement_level,
9454 l_module_name,
9455 'checking api compatibility');
9456 END IF;
9457 IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
9458 p_api_version,
9459 l_api_name,
9460 G_PKG_NAME)
9461 THEN
9462 IF l_exception_level >= l_debug_level
9463 THEN
9464 Fnd_Log.string(l_exception_level,
9465 l_module_name,
9466 'checking api compatibility, was unsuccessful');
9467 END IF;
9468 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
9469 END IF;
9470
9471 IF l_statement_level >= l_debug_level
9472 THEN
9473 Fnd_Log.string(l_statement_level,
9474 l_module_name,
9475 'checking api compatibility, was successful');
9476 END IF;
9477
9478 -- Initialize message list if p_init_msg_list is set to TRUE.
9479 IF Fnd_Api.to_Boolean(p_init_msg_list)
9480 THEN
9481 Fnd_Msg_Pub.initialize;
9482 END IF;
9483 -- Initialize API return status to success
9484 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
9485 -- ---------------
9486 -- Api body starts
9487 -- ---------------
9488 IF l_statement_level >= l_debug_level
9489 THEN
9490 Fnd_Log.String(l_Statement_Level,
9491 l_Module_Name,
9492 'Task Record Values:');
9493 Fnd_Log.String(l_Statement_Level,
9494 l_Module_Name,
9495 'Task Id :' ||
9496 p_create_repair_task_rec.task_Id);
9497 Fnd_Log.String(l_Statement_Level,
9498 l_Module_Name,
9499 'Repair_line_id :' ||
9500 p_create_repair_task_rec.repair_line_id);
9501 Fnd_Log.String(l_Statement_Level,
9502 l_Module_Name,
9503 'context values :' ||
9504 p_create_repair_task_rec.context_values);
9505 END IF;
9506
9507 -- check the required parameter
9508
9509 Csd_Process_Util.check_reqd_param(p_param_value => p_create_repair_task_rec.task_Id,
9510 p_param_name => 'Task Id',
9511 p_api_name => l_api_name);
9512
9513 IF l_statement_level >= l_debug_level
9514 THEN
9515 Fnd_Log.string(l_statement_level,
9516 l_module_name || '.check_in_parameters',
9517 'Task id is valid');
9518 END IF;
9519
9520 Csd_Process_Util.check_reqd_param(p_param_value => p_create_repair_task_rec.repair_line_Id,
9521 p_param_name => 'Repair Line Id',
9522 p_api_name => l_api_name);
9523
9524 IF l_statement_level >= l_debug_level
9525 THEN
9526 Fnd_Log.string(l_statement_level,
9527 l_module_name || '.check_in_parameters',
9528 'Repair Line id is valid');
9529 END IF;
9530
9531 -- Determine if any plans are applicable for this task.
9532 l_dummy_char := Qa_Txn_Grp.evaluate_triggers(p_txn_number => G_DEPOT_REPAIR_TXN_NUMBER,
9533 p_org_id => p_create_repair_task_rec.org_id,
9534 p_context_values => p_create_repair_task_rec.context_values,
9535 x_plan_txn_ids => l_plan_txn_ids);
9536
9537 IF l_plan_txn_ids IS NOT NULL
9538 THEN
9539 l_applicable_qa_plans := 'Y';
9540 ELSE
9541 l_applicable_qa_plans := 'N';
9542 END IF;
9543
9544 -- Insert into CSD_TASKS table
9545 Csd_Tasks_Pkg.INSERT_ROW(px_repair_task_id => x_repair_task_id,
9546 p_TASK_ID => p_create_repair_task_rec.task_id,
9547 p_OBJECT_VERSION_NUMBER => 1,
9548 p_REPAIR_LINE_ID => p_create_repair_task_rec.repair_line_id,
9549 p_APPLICABLE_QA_PLANS => l_applicable_qa_plans,
9550 p_CREATED_BY => Fnd_Global.USER_ID,
9551 p_CREATION_DATE => SYSDATE,
9552 p_LAST_UPDATED_BY => Fnd_Global.USER_ID,
9553 p_LAST_UPDATE_DATE => SYSDATE,
9554 p_LAST_UPDATE_LOGIN => Fnd_Global.USER_ID);
9555
9556 -- -------------------
9557 -- Api body ends here
9558 -- -------------------
9559 -- Standard check of p_commit.
9560 IF Fnd_Api.To_Boolean(p_commit)
9561 THEN
9562 COMMIT WORK;
9563 END IF;
9564 -- Standard call to get message count and IF count is get message info.
9565 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9566 p_data => x_msg_data);
9567 EXCEPTION
9568 WHEN Fnd_Api.G_EXC_ERROR THEN
9569 ROLLBACK TO create_task;
9570 x_return_status := Fnd_Api.G_RET_STS_ERROR;
9571 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9572 p_data => x_msg_data);
9573 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
9574 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
9575 ROLLBACK TO create_task;
9576 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9577 p_data => x_msg_data);
9578 WHEN OTHERS THEN
9579 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
9580 ROLLBACK TO create_task;
9581 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
9582 THEN
9583 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
9584 END IF;
9585 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9586 p_data => x_msg_data);
9587
9588 END CREATE_REPAIR_TASK;
9589
9590 /*-----------------------------------------------------------------------------------------------------------*/
9591 /* R12 Quality Integration */
9592 /* procedure name: update_repair_task */
9593 /* description : procedure used to update DR specifc task in Depot tables */
9594 /* Called from : Depot Repair Form to Update DR specifc Task */
9595 /* Input Parm : p_api_version NUMBER Required Api Version number */
9596 /* p_init_msg_list VARCHAR2 Optional Initializes message stack if fnd_api.g_true, */
9597 /* default value is fnd_api.g_false */
9598 /* p_commit VARCHAR2 Optional Commits in API if fnd_api.g_true, default */
9599 /* fnd_api.g_false */
9600 /* p_validation_level NUMBER Optional API uses this parameter to determine which */
9601 /* validation steps must be done and which steps */
9602 /* should be skipped. */
9603 /* CREATE_REPAIR_TASK_REC RECORD Required Columns are in the Record CREATE_REPAIR_TASK_REC_TYPE */
9604 /* Output Parm : x_return_status VARCHAR2 Return status after the call. The status can be*/
9605 /* fnd_api.g_ret_sts_success (success) */
9606 /* fnd_api.g_ret_sts_error (error) */
9607 /* fnd_api.g_ret_sts_unexp_error (unexpected) */
9608 /* x_msg_count NUMBER Number of messages in the message stack */
9609 /* x_msg_data VARCHAR2 Message text if x_msg_count >= 1 */
9610 /*-----------------------------------------------------------------------------------------------------------*/
9611
9612 PROCEDURE UPDATE_REPAIR_TASK(p_api_version IN NUMBER,
9613 p_init_msg_list IN VARCHAR2 := Fnd_Api.g_false,
9614 p_commit IN VARCHAR2 := Fnd_Api.g_false,
9615 p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
9616 p_update_repair_task_rec IN REPAIR_TASK_REC,
9617 x_return_status OUT NOCOPY VARCHAR2,
9618 x_msg_count OUT NOCOPY NUMBER,
9619 x_msg_data OUT NOCOPY VARCHAR2) IS
9620
9621 l_api_name CONSTANT VARCHAR2(30) := 'update_REPAIR_TASK';
9622 l_api_version CONSTANT NUMBER := 1.0;
9623 l_msg_count NUMBER;
9624 l_msg_data VARCHAR2(2000);
9625 l_msg_index NUMBER;
9626 l_return_status VARCHAR2(1);
9627
9628 -- Task record
9629 l_update_task_rec Csd_Process_Pvt.REPAIR_TASK_REC := p_update_repair_task_rec;
9630 l_applicable_qa_plans VARCHAR2(1);
9631 l_dummy_char VARCHAR2(32000);
9632 l_plan_txn_ids VARCHAR2(5000);
9633
9634 -- define variables to define fnd_log debug levels
9635 l_debug_level NUMBER := Fnd_Log.g_current_runtime_level;
9636 -- examples : 1- copying buffer x to y : low level detailed messages
9637 l_statement_level NUMBER := Fnd_Log.level_statement;
9638 -- examples : 2- key progress events : starting business transactions
9639 l_procedure_level NUMBER := Fnd_Log.level_procedure;
9640 -- examples : 3- event : calling an api, key progress events
9641 l_event_level NUMBER := Fnd_Log.level_event;
9642 -- examples : 4- exception internal software failure condition
9643 l_exception_level NUMBER := Fnd_Log.level_exception;
9644 -- examples : 5- error end user erros
9645 l_error_level NUMBER := Fnd_Log.level_error;
9646 l_module_name VARCHAR2(240) := 'csd.plsql.csd_process_pvt.update_repair_task';
9647
9648 BEGIN
9649 -- -----------------
9650 -- Begin update repair task
9651 -- -----------------
9652
9653 -- Standard Start of API savepoint
9654 IF l_statement_level >= l_debug_level
9655 THEN
9656 Fnd_Log.string(l_statement_level, l_module_name, 'begin');
9657 END IF;
9658 SAVEPOINT update_repair_task;
9659
9660 -- Standard call to check for call compatibility.
9661 IF l_statement_level >= l_debug_level
9662 THEN
9663 Fnd_Log.string(l_statement_level,
9664 l_module_name,
9665 'checking api compatibility');
9666 END IF;
9667 IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
9668 p_api_version,
9669 l_api_name,
9670 G_PKG_NAME)
9671 THEN
9672 IF l_exception_level >= l_debug_level
9673 THEN
9674 Fnd_Log.string(l_exception_level,
9675 l_module_name,
9676 'checking api compatibility, was unsuccessful');
9677 END IF;
9678 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
9679 END IF;
9680
9681 IF l_statement_level >= l_debug_level
9682 THEN
9683 Fnd_Log.string(l_statement_level,
9684 l_module_name,
9685 'checking api compatibility, was successful');
9686 END IF;
9687
9688 -- Initialize message list if p_init_msg_list is set to TRUE.
9689 IF Fnd_Api.to_Boolean(p_init_msg_list)
9690 THEN
9691 Fnd_Msg_Pub.initialize;
9692 END IF;
9693 -- Initialize API return status to success
9694 x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
9695 -- ---------------
9696 -- Api body starts
9697 -- ---------------
9698 IF l_statement_level >= l_debug_level
9699 THEN
9700 Fnd_Log.String(l_Statement_Level,
9701 l_Module_Name,
9702 'Task Record Values:');
9703 Fnd_Log.String(l_Statement_Level,
9704 l_Module_Name,
9705 'Task Id :' ||
9706 p_update_repair_task_rec.task_Id);
9707 Fnd_Log.String(l_Statement_Level,
9708 l_Module_Name,
9709 'Repair_line_id :' ||
9710 p_update_repair_task_rec.repair_line_id);
9711 -- fnd_log.String(l_Statement_Level,l_Module_Name,'Applicable QA Plans :'|| p_update_repair_task_rec.applicable_qa_plans );
9712 END IF;
9713
9714 -- check the required parameter
9715 Csd_Process_Util.check_reqd_param(p_param_value => p_update_repair_task_rec.repair_task_Id,
9716 p_param_name => 'Task Id',
9717 p_api_name => l_api_name);
9718
9719 IF l_statement_level >= l_debug_level
9720 THEN
9721 Fnd_Log.string(l_statement_level,
9722 l_module_name || '.check_in_parameters',
9723 'Repair Task id is valid');
9724 END IF;
9725
9726 Csd_Process_Util.check_reqd_param(p_param_value => p_update_repair_task_rec.task_Id,
9727 p_param_name => 'Task Id',
9728 p_api_name => l_api_name);
9729
9730 IF l_statement_level >= l_debug_level
9731 THEN
9732 Fnd_Log.string(l_statement_level,
9733 l_module_name || '.check_in_parameters',
9734 'Task id is valid');
9735 END IF;
9736
9737 Csd_Process_Util.check_reqd_param(p_param_value => p_update_repair_task_rec.repair_line_Id,
9738 p_param_name => 'Repair Line Id',
9739 p_api_name => l_api_name);
9740
9741 IF l_statement_level >= l_debug_level
9742 THEN
9743 Fnd_Log.string(l_statement_level,
9744 l_module_name || '.check_in_parameters',
9745 'Repair Line id is valid');
9746 END IF;
9747
9748 -- Determine if any plans are applicable for this task.
9749 l_dummy_char := Qa_Txn_Grp.evaluate_triggers(p_txn_number => G_DEPOT_REPAIR_TXN_NUMBER,
9750 p_org_id => p_update_repair_task_rec.org_id,
9751 p_context_values => p_update_repair_task_rec.context_values,
9752 x_plan_txn_ids => l_plan_txn_ids);
9753
9754 IF l_plan_txn_ids IS NOT NULL
9755 THEN
9756 l_applicable_qa_plans := 'Y';
9757 ELSE
9758 l_applicable_qa_plans := 'N';
9759 END IF;
9760
9761 -- Update CSD_TASKS table
9762 Csd_Tasks_Pkg.UPDATE_ROW(px_REPAIR_TASK_ID => p_update_repair_task_rec.repair_task_id,
9763 p_task_id => p_update_repair_task_rec.task_id,
9764 p_OBJECT_VERSION_NUMBER => p_update_repair_task_rec.object_version_number,
9765 p_REPAIR_LINE_ID => p_update_repair_task_rec.repair_line_id,
9766 p_APPLICABLE_QA_PLANS => l_applicable_qa_plans,
9767 p_CREATED_BY => Fnd_Global.USER_ID,
9768 p_CREATION_DATE => SYSDATE,
9769 p_LAST_UPDATED_BY => Fnd_Global.USER_ID,
9770 p_LAST_UPDATE_DATE => SYSDATE,
9771 p_LAST_UPDATE_LOGIN => Fnd_Global.USER_ID);
9772
9773 -- -------------------
9774 -- Api body ends here
9775 -- -------------------
9776 -- Standard check of p_commit.
9777 IF Fnd_Api.To_Boolean(p_commit)
9778 THEN
9779 COMMIT WORK;
9780 END IF;
9781 -- Standard call to get message count and IF count is get message info.
9782 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9783 p_data => x_msg_data);
9784 EXCEPTION
9785 WHEN Fnd_Api.G_EXC_ERROR THEN
9786 ROLLBACK TO update_repair_task;
9787 x_return_status := Fnd_Api.G_RET_STS_ERROR;
9788 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9789 p_data => x_msg_data);
9790 WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
9791 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
9792 ROLLBACK TO update_repair_task;
9793 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9794 p_data => x_msg_data);
9795 WHEN OTHERS THEN
9796 x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
9797 ROLLBACK TO update_repair_task;
9798 IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
9799 THEN
9800 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
9801 END IF;
9802 Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
9803 p_data => x_msg_data);
9804
9805 END UPDATE_REPAIR_TASK;
9806
9807 FUNCTION GET_REPAIR_TASK_REC RETURN Csd_Process_Pvt.REPAIR_TASK_REC IS
9808 TMP_REPAIR_TASK_REC Csd_Process_Pvt.REPAIR_TASK_REC;
9809 BEGIN
9810 RETURN TMP_REPAIR_TASK_REC;
9811 END GET_REPAIR_TASK_REC;
9812 END Csd_Process_Pvt;