1 PACKAGE BODY AHL_OSP_ORDERS_PVT AS
2 /* $Header: AHLVOSPB.pls 120.24 2008/03/14 14:41:52 mpothuku ship $ */
3
4 --G_DEBUG varchar2(1) := FND_PROFILE.VALUE('AHL_API_FILE_DEBUG_ON');
5 G_DEBUG VARCHAR2(1) := AHL_DEBUG_PUB.is_log_enabled;
6 G_PKG_NAME CONSTANT VARCHAR2(30) := 'AHL_OSP_ORDERS_PVT';
7 G_APP_NAME CONSTANT VARCHAR2(3) := 'AHL';
8 G_LOG_PREFIX CONSTANT VARCHAR2(100) := 'ahl.plsql.'||G_PKG_NAME||'.';
9 G_OAF_MODULE CONSTANT VARCHAR2(3) := 'OAF';
10
11 g_module_type VARCHAR2(30) := NULL;
12 --Mainly used for whether to default unchanged attributes.For OAF, we don't.
13 g_old_status_code VARCHAR2(30) := NULL;
14 /*
15 -- Commented out by jaramana on January 7, 2008 for the Requisition ER 6034236
16 g_order_status_for_update VARCHAR2(30) := NULL;
17 --For OSP status change
18 g_order_conversion_flag VARCHAR2(1) := 'N';
19 -- jaramana End
20 */
21
22 --Indicates whether update order involves converting between 'SERVICE' and 'EXCHANGE'
23 g_old_type_code VARCHAR2(30) := NULL;
24 g_new_type_code VARCHAR2(30) := NULL;
25 --For OSP order type conversion
26
27 --***** The following lines were added by Jerry for Inventory Service Orders *****--
28 g_dummy_char VARCHAR2(1);
29 g_dummy_num NUMBER;
30
31 TYPE item_service_rel_rec_type IS RECORD (
32 inv_org_id NUMBER,
33 inv_item_id NUMBER,
34 service_item_id NUMBER);
35 TYPE item_service_rels_tbl_type IS TABLE OF item_service_rel_rec_type INDEX BY BINARY_INTEGER;
36
37 TYPE Vendor_Id_Rec_Type IS RECORD (
38 vendor_id NUMBER,
39 vendor_site_id NUMBER
40 );
41 TYPE Vendor_id_tbl_type IS TABLE OF Vendor_Id_Rec_Type INDEX BY BINARY_INTEGER;
42
43 --Given a series of physical item, service item combinations to get the common
44 --vendor attributes.
45 PROCEDURE derive_default_vendor(
46 p_item_service_rels_tbl IN item_service_rels_tbl_type,
47 x_vendor_id OUT NOCOPY NUMBER,
48 x_vendor_site_id OUT NOCOPY NUMBER,
49 x_vendor_contact_id OUT NOCOPY NUMBER,
50 x_valid_vendors_tbl OUT NOCOPY vendor_id_tbl_type);
51
52 --This procedure tries to derive the common vendors for an OSP Order based on its Lines.
53 --If the x_any_vendor_flag is 'Y', it means that any vendor can be used for this Order.
54 --Else, only the vendors whose ids are returned in the table x_valid_vendors_tbl
55 --are valid. It uses the derive_default_vendor method.
56 PROCEDURE Derive_Common_Vendors(p_osp_order_id IN NUMBER,
57 x_valid_vendors_tbl OUT NOCOPY Vendor_id_tbl_type,
58 x_any_vendor_flag OUT NOCOPY VARCHAR2);
59
60 --Newly created for validating vendor_id, vendor_site_id and
61 --vendor_contact_id together
62 PROCEDURE validate_vendor_site_contact(p_vendor_id IN NUMBER,
63 p_vendor_site_id IN NUMBER,
64 p_vendor_contact_id IN NUMBER);
65
66 --yazhou 07-Aug-2006 starts
67 -- bug fix#5448191
68
69 --Create shipment header/lines for osp line
70 PROCEDURE create_shipment(
71 p_osp_order_lines_tbl IN OUT NOCOPY osp_order_lines_tbl_type);
72
73 --yazhou 07-Aug-2006 ends
74
75 --Contains OSP order header record default, validation and creation
76 PROCEDURE create_osp_order_header(
77 p_x_osp_order_rec IN OUT NOCOPY osp_order_rec_type,
78 p_x_osp_order_lines_tbl IN OUT NOCOPY osp_order_lines_tbl_type);
79
80 --Contains OSP order header record default, validation and update, including
81 --Status change and type conversion
82 PROCEDURE update_osp_order_header(
83 p_x_osp_order_rec IN OUT NOCOPY osp_order_rec_type);
84
85 --Contains OSP order line record default and creation
86 PROCEDURE create_osp_order_line(
87 p_x_osp_order_line_rec IN OUT NOCOPY osp_order_line_rec_type);
88
89 --validate osp line for creation
90 PROCEDURE validate_order_line_creation(
91 p_x_osp_order_line_rec IN OUT NOCOPY osp_order_line_rec_type);
92
93 --update osp order line record
94 PROCEDURE update_osp_order_line(
95 p_x_osp_order_line_rec IN OUT NOCOPY osp_order_line_rec_type);
96
97 --validate osp line for update
98 PROCEDURE validate_order_line_update(
99 p_x_osp_order_line_rec IN OUT NOCOPY osp_order_line_rec_type);
100
101 --do the G_MISS to NULL and NULL to old value conversion for order
102 --line record
103 PROCEDURE default_unchanged_order_line(
104 p_x_osp_order_line_rec IN OUT NOCOPY osp_order_line_rec_type);
105
106 --Convert values to Ids for OSP order line record
107 PROCEDURE convert_order_line_val_to_id(
108 p_x_osp_order_line_rec IN OUT NOCOPY osp_order_line_rec_type);
109
110 --Validate the physical/service item combination with the vendor
111 PROCEDURE validate_vendor_service_item(
112 p_osp_order_line_rec IN osp_order_line_rec_type);
113
114 --Validate service_item_id (simplified the original one)
115 PROCEDURE validate_service_item_id(
116 p_service_item_id IN NUMBER,
117 p_organization_id IN NUMBER);
118
119 --Handle the order type change (new procedure but copied the old logic)
120 PROCEDURE process_order_type_change(
121 p_osp_order_rec IN osp_order_rec_type);
122
123 -----------------------------------------------
124 -- Declare Local TYPE, FUNCTION and PROCEDURE--
125 -----------------------------------------------
126 TYPE del_cancel_so_line_rec IS RECORD(
127 osp_order_id NUMBER,
128 oe_ship_line_id NUMBER,
129 oe_return_line_id NUMBER
130 );
131 TYPE del_cancel_so_lines_tbl_type IS TABLE OF del_cancel_so_line_rec INDEX BY BINARY_INTEGER;
132 PROCEDURE delete_cancel_so(
133 p_oe_header_id IN NUMBER,
134 p_del_cancel_so_lines_tbl IN del_cancel_so_lines_tbl_type,
135 p_cancel_flag IN VARCHAR2 := FND_API.G_FALSE
136 );
137 PROCEDURE process_order_status_change(
138 p_x_osp_order_rec IN OUT NOCOPY osp_order_rec_type
139 );
140 FUNCTION can_convert_order(
141 p_osp_order_id IN NUMBER,
142 p_old_type_code IN VARCHAR2,
143 p_new_type_code IN VARCHAR2
144 --p_new_order_rec IN AHL_OSP_ORDERS_PVT.osp_order_rec_type,
145 --p_old_order_rec IN AHL_OSP_ORDERS_PVT.osp_order_rec_type
146 ) RETURN BOOLEAN;
147 FUNCTION vendor_id_exist_in_PO(
148 p_po_header_id IN NUMBER,
149 p_vendor_id IN NUMBER
150 ) RETURN BOOLEAN;
151 FUNCTION vendor_site_id_exist_in_PO(
152 p_po_header_id IN NUMBER,
153 p_vendor_site_id IN NUMBER
154 ) RETURN BOOLEAN;
155
156 PROCEDURE validate_order_header(
157 p_x_osp_order_rec IN OUT NOCOPY osp_order_rec_type
158 );
159 PROCEDURE validate_vendor(
160 p_vendor_id IN NUMBER
161 );
162 PROCEDURE validate_vendor_site(
163 p_vendor_id IN NUMBER,
164 p_vendor_site_id IN NUMBER
165 );
166 PROCEDURE validate_customer(
167 p_customer_id IN NUMBER
168 );
169 PROCEDURE validate_buyer(
170 p_po_agent_id IN NUMBER
171 );
172 PROCEDURE validate_contract(
173 p_order_type_code IN VARCHAR2,
174 p_contract_id IN VARCHAR2,
175 p_party_vendor_id IN VARCHAR2,
176 p_authoring_org_id IN VARCHAR2
177 );
178 PROCEDURE validate_po_header(
179 p_osp_order_id IN NUMBER,
180 p_po_header_id IN NUMBER
181 );
182 PROCEDURE default_unchanged_order_header(
183 p_x_osp_order_rec IN OUT NOCOPY osp_order_rec_type
184 );
185 PROCEDURE validate_workorder(
186 p_workorder_id IN NUMBER
187 );
188
189 --Commented by mpothuku on 27-Feb-06 as the following procs. are not being used anymore and the Perf Bug #4919164 --has been logged for some of the cursors in the procedures below
190 /*
191 PROCEDURE validate_service_item(
192 p_workorder_id IN NUMBER,
193 p_service_item_id IN NUMBER,
194 p_order_type_code IN VARCHAR2
195 );
196 PROCEDURE validate_service_item_desc(
197 p_service_item_id IN NUMBER,
198 p_service_item_description IN VARCHAR2
199 );
200 */
201
202 -- Added by jaramana on January 7, 2008 for the Requisition ER 6034236
203 PROCEDURE val_svc_item_vs_wo_svc_item(
204 p_workorder_id IN NUMBER,
205 p_service_item_id IN NUMBER
206 );
207 -- jaramana End
208
209 --p_org_id added by mpothuku to fix the Perf Bug #4919164
210 PROCEDURE validate_service_item_uom(
211 p_service_item_id IN NUMBER,
212 p_service_item_uom_code IN VARCHAR2,
213 p_org_id IN NUMBER
214 );
215 PROCEDURE validate_po_line_type(
216 p_po_line_type_id IN NUMBER
217 );
218 PROCEDURE validate_po_line(
219 p_po_line_id IN NUMBER,
220 p_osp_order_id IN NUMBER
221 );
222 PROCEDURE validate_exchange_instance_id(
223 p_exchange_instance_id IN NUMBER
224 );
225 -- Commented out by jaramana on January 7, 2008 for the Requisition ER 6034236 (We are not using this procedure anymore)
226 /*
227 PROCEDURE nullify_exchange_instance(
228 p_osp_order_id IN NUMBER,
229 p_x_osp_order_lines_tbl IN OUT NOCOPY osp_order_lines_tbl_type
230 );
231 */
232 -- jaramana End
233
234 ------------------------------
235 -- Declare Local Procedures --
236 ------------------------------
237 /*
238 PROCEDURE process_order_header(
239 p_validation_level IN NUMBER := FND_API.G_VALID_LEVEL_FULL,
240 p_x_osp_order_rec IN OUT NOCOPY osp_order_rec_type
241 );
242 PROCEDURE process_order_lines(
243 p_validation_level IN NUMBER := FND_API.G_VALID_LEVEL_FULL,
244 p_osp_order_rec IN osp_order_rec_type,
245 p_x_osp_order_lines_tbl IN OUT NOCOPY osp_order_lines_tbl_type
246 );
247 PROCEDURE convert_order_lines_val_to_id(
248 p_x_osp_order_lines_tbl IN OUT NOCOPY osp_order_lines_tbl_type
249 );
250 PROCEDURE convert_order_header_val_to_id(
251 p_x_osp_order_rec IN OUT NOCOPY osp_order_rec_type
252 );
253 PROCEDURE validate_order_lines(
254 p_osp_order_rec IN osp_order_rec_type,
255 p_x_osp_order_lines_tbl IN OUT NOCOPY osp_order_lines_tbl_type,
256 x_del_cancel_so_lines_tbl OUT NOCOPY del_cancel_so_lines_tbl_type
257 );
258 PROCEDURE default_unchanged_order_lines(
259 p_x_osp_order_lines_tbl IN OUT NOCOPY osp_order_lines_tbl_type
260 );
261 PROCEDURE validate_osp_updates(
262 p_osp_order_rec IN osp_order_rec_type
263 );
264 */
265
266 -- *****Procedure definitions start here *****--
267 -- When DML operation is not INSERT and osp_order_id is not available, populates osp_order_id from othe unique keys.
268 -- other unique keys are -- osp_order_number, po_header_id, oe_header_id
269 --------------------------------------------------------------------------------------------------------------
270 --(?)Jerry on 04/17/2005, may need to add vendor_contact value to id conversion in this procedure
271 PROCEDURE convert_order_header_val_to_id(
272 p_x_osp_order_rec IN OUT NOCOPY osp_order_rec_type
273 ) IS
274 CURSOR vendor_id_csr(p_vendor_name IN VARCHAR2) IS
275 SELECT vendor_id FROM po_vendors_view
276 WHERE vendor_name = p_vendor_name
277 AND enabled_flag = G_YES_FLAG
278 AND NVL(vendor_start_date_active, SYSDATE - 1) <= SYSDATE
279 AND NVL(vendor_end_date_active, SYSDATE + 1) > SYSDATE;
280 l_vendor_id NUMBER;
281 CURSOR vendor_site_id_csr(p_vendor_site_code IN VARCHAR2) IS
282 SELECT vendor_site_id FROM po_vendor_sites
283 WHERE vendor_site_code = p_vendor_site_code
284 AND NVL(inactive_date, SYSDATE + 1) > SYSDATE
285 AND purchasing_site_flag = G_YES_FLAG;
286 l_vendor_site_id NUMBER;
287
288 CURSOR po_agent_id_csr(p_buyer_name IN VARCHAR2) IS
289 SELECT buyer_id FROM po_agents_name_v
290 WHERE full_name = p_buyer_name;
291 l_po_agent_id NUMBER;
292 CURSOR customer_id_csr(p_customer_name IN VARCHAR2) IS
293 SELECT party_id from hz_parties
294 where party_name = p_customer_name and party_type = 'ORGANIZATION';
295 l_customer_id NUMBER;
296 CURSOR contract_id_csr(p_contract_number IN VARCHAR2) IS
297 SELECT chr.id FROM okc_k_headers_b chr, okc_statuses_b sts
298 WHERE chr.contract_number = p_contract_number
299 AND chr.sts_code = sts.code AND sts.ste_code in ('ACTIVE', 'SIGNED');
300 l_contract_id NUMBER;
301 CURSOR osp_order_on_csr(p_osp_order_number IN NUMBER) IS
302 SELECT osp_order_id, object_version_number from ahl_osp_orders_b
303 WHERE osp_order_number = p_osp_order_number;
304 -- Commented out by jaramana on January 8, 2008 for the Requisition ER 6034236
305 /*
306 CURSOR osp_order_po_csr(p_po_header_id IN NUMBER) IS
307 SELECT osp_order_id, object_version_number from ahl_osp_orders_b
308 WHERE po_header_id = p_po_header_id;
309 CURSOR osp_order_oe_csr(p_oe_header_id IN NUMBER) IS
310 SELECT osp_order_id, object_version_number from ahl_osp_orders_b
311 WHERE oe_header_id = p_oe_header_id;
312 */
313 -- jaramana End
314 l_osp_order_id NUMBER;
315 l_object_version_number NUMBER;
316 l_count NUMBER;
317 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.convert_order_header_val_to_id';
318 BEGIN
319 --dbms_output.put_line('Entering : convert_order_header_val_to_id');
320 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
321 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
322 END IF;
323 IF (p_x_osp_order_rec.operation_flag IS NOT NULL AND p_x_osp_order_rec.operation_flag NOT IN(G_OP_CREATE, G_OP_UPDATE, G_OP_DELETE)) THEN
324 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INVOP');
325 FND_MSG_PUB.ADD;
326 END IF;
327 IF FND_MSG_PUB.count_msg > 0 THEN
328 RAISE FND_API.G_EXC_ERROR;
329 -- RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
330 END IF;
331 IF(g_module_type = 'JSP')THEN
332 -- conversion of value to id for Vendor name
333 IF(p_x_osp_order_rec.vendor_name IS NULL) THEN
334 p_x_osp_order_rec.vendor_id := NULL;
335 ELSIF (p_x_osp_order_rec.vendor_name = FND_API.G_MISS_CHAR) THEN
336 IF(p_x_osp_order_rec.operation_flag <> G_OP_CREATE) THEN
337 p_x_osp_order_rec.vendor_id := FND_API.G_MISS_NUM;
338 ELSE
339 p_x_osp_order_rec.vendor_id := NULL;
340 END IF;
341 END IF;
342 IF(p_x_osp_order_rec.vendor_site_code IS NULL) THEN
343 p_x_osp_order_rec.vendor_site_id := NULL;
344 ELSIF (p_x_osp_order_rec.vendor_site_code = FND_API.G_MISS_CHAR) THEN
345 IF(p_x_osp_order_rec.operation_flag <> G_OP_CREATE) THEN
346 p_x_osp_order_rec.vendor_site_id := FND_API.G_MISS_NUM;
347 ELSE
348 p_x_osp_order_rec.vendor_site_id := NULL;
349 END IF;
350 END IF;
351 IF(p_x_osp_order_rec.buyer_name IS NULL) THEN
352 p_x_osp_order_rec.po_agent_id := NULL;
353 ELSIF (p_x_osp_order_rec.buyer_name = FND_API.G_MISS_CHAR) THEN
354 IF(p_x_osp_order_rec.operation_flag <> G_OP_CREATE) THEN
355 p_x_osp_order_rec.po_agent_id := FND_API.G_MISS_NUM;
356 ELSE
357 p_x_osp_order_rec.po_agent_id := NULL;
358 END IF;
359 END IF;
360 IF(p_x_osp_order_rec.customer_name IS NULL) THEN
361 p_x_osp_order_rec.customer_id := NULL;
362 ELSIF (p_x_osp_order_rec.customer_name = FND_API.G_MISS_CHAR) THEN
363 IF(p_x_osp_order_rec.operation_flag <> G_OP_CREATE) THEN
364 p_x_osp_order_rec.customer_id := FND_API.G_MISS_NUM;
365 ELSE
366 p_x_osp_order_rec.customer_id := NULL;
367 END IF;
368 END IF;
369 IF(p_x_osp_order_rec.contract_number IS NULL) THEN
370 p_x_osp_order_rec.contract_id := NULL;
371 ELSIF (p_x_osp_order_rec.contract_number = FND_API.G_MISS_CHAR) THEN
372 IF(p_x_osp_order_rec.operation_flag <> G_OP_CREATE) THEN
373 p_x_osp_order_rec.contract_id := FND_API.G_MISS_NUM;
374 ELSE
375 p_x_osp_order_rec.contract_id := NULL;
376 END IF;
377 END IF;
378 --dbms_output.put_line('Done nulling out order header ids');
379 END IF;
380 -- conversion of value to id for Vendor name
381 IF (p_x_osp_order_rec.vendor_name IS NOT NULL AND p_x_osp_order_rec.vendor_name <> FND_API.G_MISS_CHAR) THEN
382 l_count := 0;
383 --dbms_output.put_line('converting vendor_name to id');
384 OPEN vendor_id_csr(p_x_osp_order_rec.vendor_name);
385 LOOP
386 FETCH vendor_id_csr INTO l_vendor_id;
387 IF(vendor_id_csr%NOTFOUND) THEN
388 EXIT;
389 ELSIF (p_x_osp_order_rec.vendor_id IS NOT NULL AND p_x_osp_order_rec.vendor_id = l_vendor_id) THEN
390 l_count := 1;
391 EXIT;
392 ELSE
393 l_count := l_count + 1;
394 END IF;
395 END LOOP;
396 CLOSE vendor_id_csr;
397 IF(l_count = 0 ) THEN
398 --dbms_output.put_line('checkpoint 1');
399 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENDOR_NAME_INV');
400 FND_MESSAGE.Set_Token('VENDOR_NAME', p_x_osp_order_rec.vendor_name);
401 FND_MSG_PUB.ADD;
402 ELSIF (l_count > 1) THEN
403 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENDOR_INV_NON_UNQ');
404 FND_MESSAGE.Set_Token('VENDOR_NAME', p_x_osp_order_rec.vendor_name);
405 FND_MSG_PUB.ADD;
406 ELSE
407 p_x_osp_order_rec.vendor_id := l_vendor_id;
408 END IF;
409 --dbms_output.put_line('done converting vendor_name to id');
410 END IF;
411 -- conversion of value to id for vendor site code
412 IF (p_x_osp_order_rec.vendor_site_code IS NOT NULL AND p_x_osp_order_rec.vendor_site_code <> FND_API.G_MISS_CHAR) THEN
413 l_count := 0;
414 OPEN vendor_site_id_csr(p_x_osp_order_rec.vendor_site_code);
415 LOOP
416 FETCH vendor_site_id_csr INTO l_vendor_site_id;
417 IF(vendor_site_id_csr%NOTFOUND) THEN
418 EXIT;
419 ELSIF (p_x_osp_order_rec.vendor_site_id IS NOT NULL AND p_x_osp_order_rec.vendor_site_id = l_vendor_site_id) THEN
420 l_count := 1;
421 EXIT;
422 ELSE
423 l_count := l_count + 1;
424 END IF;
425 END LOOP;
426 CLOSE vendor_site_id_csr;
427 IF(l_count = 0 ) THEN
428 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENSITE_INV');
429 FND_MESSAGE.Set_Token('VENDOR_SITE', p_x_osp_order_rec.vendor_site_code);
430 FND_MSG_PUB.ADD;
431 ELSIF (l_count > 1) THEN
432 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENSITE_INV_NON_UNQ');
433 FND_MESSAGE.Set_Token('VENDOR_SITE', p_x_osp_order_rec.vendor_site_code);
434 FND_MSG_PUB.ADD;
435 ELSE
436 p_x_osp_order_rec.vendor_site_id := l_vendor_site_id;
437 END IF;
438 END IF;
439 -- conversion of value to id for buyer name
440 IF (p_x_osp_order_rec.buyer_name IS NOT NULL AND p_x_osp_order_rec.buyer_name <> FND_API.G_MISS_CHAR) THEN
441 l_count := 0;
442 OPEN po_agent_id_csr(p_x_osp_order_rec.buyer_name);
443 LOOP
444 FETCH po_agent_id_csr INTO l_po_agent_id;
445 IF(po_agent_id_csr%NOTFOUND) THEN
446 EXIT;
447 ELSIF (p_x_osp_order_rec.po_agent_id IS NOT NULL AND p_x_osp_order_rec.po_agent_id = l_po_agent_id) THEN
448 l_count := 1;
449 EXIT;
450 ELSE
451 l_count := l_count + 1;
452 END IF;
453 END LOOP;
454 CLOSE po_agent_id_csr;
455 IF(l_count = 0 ) THEN
456 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_BUYER_INV');
457 FND_MESSAGE.Set_Token('BUYER_NAME', p_x_osp_order_rec.buyer_name);
458 FND_MSG_PUB.ADD;
459 ELSIF (l_count > 1) THEN
460 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_BUYER_INV_NON_UNQ');
461 FND_MESSAGE.Set_Token('BUYER_NAME', p_x_osp_order_rec.buyer_name);
462 FND_MSG_PUB.ADD;
463 ELSE
464 p_x_osp_order_rec.po_agent_id := l_po_agent_id;
465 END IF;
466 END IF;
467 -- conversion of value to id for customer name
468 IF (p_x_osp_order_rec.customer_name IS NOT NULL AND p_x_osp_order_rec.customer_name <> FND_API.G_MISS_CHAR) THEN
469 --dbms_output.put_line('converting customer_name to id');
470 l_count := 0;
471 OPEN customer_id_csr(p_x_osp_order_rec.customer_name);
472 LOOP
473 FETCH customer_id_csr INTO l_customer_id;
474 IF(customer_id_csr%NOTFOUND) THEN
475 EXIT;
476 ELSIF (p_x_osp_order_rec.customer_id IS NOT NULL AND p_x_osp_order_rec.customer_id = l_customer_id) THEN
477 l_count := 1;
478 EXIT;
479 ELSE
480 l_count := l_count + 1;
481 END IF;
482 END LOOP;
483 CLOSE customer_id_csr;
484 IF(l_count = 0 ) THEN
485 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_CUST_INV');
486 FND_MESSAGE.Set_Token('CUST_NAME', p_x_osp_order_rec.customer_name);
487 FND_MSG_PUB.ADD;
488 ELSIF (l_count > 1) THEN
489 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_CUST_INV_NON_UNQ');
490 FND_MESSAGE.Set_Token('CUST_NAME', p_x_osp_order_rec.customer_name);
491 FND_MSG_PUB.ADD;
492 ELSE
493 p_x_osp_order_rec.customer_id := l_customer_id;
494 END IF;
495 END IF;
496 -- conversion of value to id for contract number
497 IF (p_x_osp_order_rec.contract_number IS NOT NULL AND p_x_osp_order_rec.contract_number <> FND_API.G_MISS_CHAR) THEN
498 --dbms_output.put_line('converting contract_number to id');
499 OPEN contract_id_csr(p_x_osp_order_rec.contract_number);
500 FETCH contract_id_csr INTO l_contract_id;
501 IF(contract_id_csr%NOTFOUND) THEN
502 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_CONTRACT_INV');
503 FND_MESSAGE.Set_Token('CONTRACT_NUM', p_x_osp_order_rec.contract_number);
504 FND_MSG_PUB.ADD;
505 ELSE
506 p_x_osp_order_rec.contract_id := l_contract_id;
507 END IF;
508 CLOSE contract_id_csr;
509 END IF;
510 IF FND_MSG_PUB.count_msg > 0 THEN
511 RAISE FND_API.G_EXC_ERROR;
512 -- RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
513 END IF;
514 -- finding unique key osp_order_id when operation flag is not 'C'
515 IF (p_x_osp_order_rec.osp_order_id IS NULL) THEN
516 --dbms_output.put_line('finding osp_order_id');
517 IF p_x_osp_order_rec.operation_flag <> G_OP_CREATE THEN
518 IF (p_x_osp_order_rec.osp_order_number IS NOT NULL) THEN
519 OPEN osp_order_on_csr(p_x_osp_order_rec.osp_order_number);
520 FETCH osp_order_on_csr INTO l_osp_order_id,l_object_version_number;
521 IF(osp_order_on_csr%NOTFOUND) THEN
522 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_NUM_INV');
523 FND_MESSAGE.Set_Token('ORDER_NUMBER', p_x_osp_order_rec.osp_order_number);
524 FND_MSG_PUB.ADD;
525 ELSE
526 p_x_osp_order_rec.osp_order_id := l_osp_order_id;
527 p_x_osp_order_rec.object_version_number := l_object_version_number;
528 END IF;
529 CLOSE osp_order_on_csr;
530 -- Commented out by jaramana on January 8, 2008 for the Requisition ER 6034236
531 /*
532 ELSIF (p_x_osp_order_rec.po_header_id IS NOT NULL AND p_x_osp_order_rec.po_header_id <> FND_API.G_MISS_NUM) THEN
533 OPEN osp_order_po_csr(p_x_osp_order_rec.po_header_id);
534 FETCH osp_order_po_csr INTO l_osp_order_id,l_object_version_number;
535 IF(osp_order_po_csr%NOTFOUND) THEN
536 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_PO_HEADER_INV');
537 FND_MESSAGE.Set_Token('PO_HEADER_ID', p_x_osp_order_rec.po_header_id);
538 FND_MSG_PUB.ADD;
539 ELSE
540 p_x_osp_order_rec.osp_order_id := l_osp_order_id;
541 p_x_osp_order_rec.object_version_number := l_object_version_number;
542 END IF;
543 CLOSE osp_order_po_csr;
544 ELSIF (p_x_osp_order_rec.oe_header_id IS NOT NULL AND p_x_osp_order_rec.oe_header_id <> FND_API.G_MISS_NUM) THEN
545 OPEN osp_order_oe_csr(p_x_osp_order_rec.oe_header_id);
546 FETCH osp_order_oe_csr INTO l_osp_order_id,l_object_version_number;
547 IF(osp_order_oe_csr%NOTFOUND) THEN
548 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_OE_HEADER_INV');
549 FND_MESSAGE.Set_Token('OE_HEADER_ID', p_x_osp_order_rec.oe_header_id);
550 FND_MSG_PUB.ADD;
551 ELSE
552 p_x_osp_order_rec.osp_order_id := l_osp_order_id;
553 p_x_osp_order_rec.object_version_number := l_object_version_number;
554 END IF;
555 CLOSE osp_order_oe_csr;
556 */
557 -- jaramana End
558 ELSE
559 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_HEADER_INV');
560 FND_MSG_PUB.ADD;
561 END IF;
562 END IF;
563 END IF;
564 IF FND_MSG_PUB.count_msg > 0 THEN
565 RAISE FND_API.G_EXC_ERROR;
566 -- RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
567 END IF;
568 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
569 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
570 END IF;
571 --dbms_output.put_line('Exiting : convert_order_header_val_to_id');
572 END convert_order_header_val_to_id;
573
574 -------------------------------------------------------------------------------------------------------------
575 PROCEDURE validate_vendor(p_vendor_id IN NUMBER) IS
576 CURSOR val_vendor_id_csr(p_vendor_id IN NUMBER) IS
577 SELECT 'X'
578 FROM po_vendors_view
579 WHERE vendor_id = p_vendor_id
580 AND enabled_flag = G_YES_FLAG
581 AND NVL(vendor_start_date_active, SYSDATE - 1) <= SYSDATE
582 AND NVL(vendor_end_date_active, SYSDATE + 1) > SYSDATE;
583 CURSOR get_vendor_cert IS
584 SELECT 'X'
585 FROM ahl_vendor_certifications_v
586 WHERE vendor_id = p_vendor_id
587 AND TRUNC(active_start_date) <= TRUNC(SYSDATE)
588 AND TRUNC(nvl(active_end_date, SYSDATE+1)) > TRUNC(SYSDATE);
589 l_exist VARCHAR2(1);
590 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.validate_vendor';
591 BEGIN
592 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
593 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
594 END IF;
595 IF(p_vendor_id IS NOT NULL AND p_vendor_id <> FND_API.G_MISS_NUM) THEN
596 OPEN val_vendor_id_csr(p_vendor_id);
597 FETCH val_vendor_id_csr INTO l_exist;
598 IF(val_vendor_id_csr%NOTFOUND) THEN
599 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENDOR_ID_INV');
600 FND_MESSAGE.Set_Token('VENDOR_ID', p_vendor_id);
601 FND_MSG_PUB.ADD;
602 END IF;
603 CLOSE val_vendor_id_csr;
604 OPEN get_vendor_cert;
605 FETCH get_vendor_cert INTO l_exist;
606 IF(get_vendor_cert%NOTFOUND) THEN
607 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENDOR_ID_INV');
608 FND_MESSAGE.Set_Token('VENDOR_ID', p_vendor_id);
609 FND_MSG_PUB.ADD;
610 END IF;
611 CLOSE get_vendor_cert;
612 END IF;
613 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
614 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
615 END IF;
616 END validate_vendor;
617
618 -------------------------------------------------------------------------------------------------------------
619 PROCEDURE validate_vendor_site(p_vendor_id IN NUMBER, p_vendor_site_id IN NUMBER) IS
620 CURSOR val_vendor_site_id_csr(p_vendor_id IN NUMBER, p_vendor_site_id IN NUMBER) IS
621 SELECT 'x' FROM po_vendor_sites
622 WHERE vendor_site_id = p_vendor_site_id
623 AND vendor_id = p_vendor_id
624 AND NVL(inactive_date, SYSDATE + 1) > SYSDATE
625 AND purchasing_site_flag = G_YES_FLAG
626 AND NVL(RFQ_ONLY_SITE_FLAG, G_NO_FLAG) = G_NO_FLAG;
627 CURSOR get_vendor_cert IS
628 SELECT 'X'
629 FROM ahl_vendor_certifications_v
630 WHERE vendor_id = p_vendor_id
631 AND vendor_site_id = p_vendor_site_id
632 AND TRUNC(active_start_date) <= TRUNC(SYSDATE)
633 AND TRUNC(nvl(active_end_date, SYSDATE+1)) > TRUNC(SYSDATE);
634 l_exist VARCHAR2(1);
635 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.validate_vendor_site';
636 BEGIN
637 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
638 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
639 END IF;
640 IF (p_vendor_id IS NULL OR p_vendor_id = FND_API.G_MISS_NUM) THEN
641 IF(p_vendor_site_id IS NOT NULL AND p_vendor_site_id <> FND_API.G_MISS_NUM) THEN
642 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VEND_ID_NLL');
643 FND_MESSAGE.Set_Token('VENDOR_SITE_ID', p_vendor_site_id);
644 FND_MSG_PUB.ADD;
645 END IF;
646 ELSE
647 IF(p_vendor_site_id IS NOT NULL AND p_vendor_site_id <> FND_API.G_MISS_NUM)THEN
648 OPEN val_vendor_site_id_csr(p_vendor_id, p_vendor_site_id);
649 FETCH val_vendor_site_id_csr INTO l_exist;
650 IF(val_vendor_site_id_csr%NOTFOUND) THEN
651 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENSITE_ID_INV');
652 FND_MESSAGE.Set_Token('VENDOR_SITE_ID', p_vendor_site_id);
653 FND_MSG_PUB.ADD;
654 END IF;
655 CLOSE val_vendor_site_id_csr;
656 OPEN get_vendor_cert;
657 FETCH get_vendor_cert INTO l_exist;
658 IF(get_vendor_cert%NOTFOUND) THEN
659 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENSITE_ID_INV');
660 FND_MESSAGE.Set_Token('VENDOR_SITE_ID', p_vendor_site_id);
661 FND_MSG_PUB.ADD;
662 END IF;
663 CLOSE get_vendor_cert;
664 END IF;
665 END IF;
666 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
667 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
668 END IF;
669 END validate_vendor_site;
670
671 -------------------------------------------------------------------------------------------------------------
672 PROCEDURE validate_customer(
673 p_customer_id IN NUMBER
674 )IS
675 CURSOR val_customer_id_csr(p_customer_id IN NUMBER) IS
676 SELECT 'x' from hz_parties
677 where party_id = p_customer_id and party_type = 'ORGANIZATION';
678 l_exist VARCHAR2(1);
679 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.validate_customer';
680 BEGIN
681 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
682 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
683 END IF;
684 IF(p_customer_id IS NOT NULL AND p_customer_id <> FND_API.G_MISS_NUM) THEN
685 OPEN val_customer_id_csr(p_customer_id);
686 FETCH val_customer_id_csr INTO l_exist;
687 IF(val_customer_id_csr%NOTFOUND) THEN
688 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_CUST_ID_INV');
689 FND_MESSAGE.Set_Token('CUSTOMER_ID', p_customer_id);
690 FND_MSG_PUB.ADD;
691 END IF;
692 CLOSE val_customer_id_csr;
693 END IF;
694 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
695 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
696 END IF;
697 END validate_customer;
698
699 -------------------------------------------------------------------------------------------------------------
700 PROCEDURE validate_buyer(
701 p_po_agent_id IN NUMBER
702 )IS
703 CURSOR val_po_agent_id_csr(p_po_agent_id IN NUMBER) IS
704 SELECT 'x' FROM po_agents_name_v
705 WHERE buyer_id = p_po_agent_id;
706 l_exist VARCHAR2(1);
707 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.validate_buyer';
708 BEGIN
709 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
710 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
711 END IF;
712 IF(p_po_agent_id IS NOT NULL AND p_po_agent_id <> FND_API.G_MISS_NUM) THEN
713 OPEN val_po_agent_id_csr(p_po_agent_id);
714 FETCH val_po_agent_id_csr INTO l_exist;
715 IF(val_po_agent_id_csr%NOTFOUND) THEN
716 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_BUYER_ID_INV');
717 FND_MESSAGE.Set_Token('BUYER_ID', p_po_agent_id);
718 FND_MSG_PUB.ADD;
719 END IF;
720 CLOSE val_po_agent_id_csr;
721 END IF;
722 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
723 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
724 END IF;
725 END validate_buyer;
726
727 -------------------------------------------------------------------------------------------------------------
728 PROCEDURE validate_contract(
729 p_order_type_code IN VARCHAR2,
730 p_contract_id IN VARCHAR2,
731 p_party_vendor_id IN VARCHAR2,
732 p_authoring_org_id IN VARCHAR2
733 )IS
734 CURSOR val_contract_id_csr(p_contract_id IN NUMBER,p_party_vendor_id in NUMBER,
735 p_buy_or_sell IN VARCHAR2, p_authoring_org_id IN NUMBER, p_object_code IN VARCHAR2) IS
736 SELECT 'x' FROM okc_k_headers_b chr, okc_k_party_roles_b cpl, okc_statuses_b sts
737 WHERE chr.id = p_contract_id
738 AND cpl.object1_id1 = p_party_vendor_id
739 AND chr.authoring_org_id = p_authoring_org_id
740 AND chr.id = cpl.chr_id AND chr.buy_or_sell = p_buy_or_sell AND chr.sts_code = sts.code AND sts.ste_code in ('ACTIVE', 'SIGNED')
741 AND cpl.jtot_object1_code = p_object_code;
742 l_exist VARCHAR2(1);
743 l_buy_or_sell VARCHAR2(1);
744 l_object_code VARCHAR2(30);
745 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.validate_contract';
746 BEGIN
747 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
748 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
749 END IF;
750 IF(p_order_type_code = G_OSP_ORDER_TYPE_BORROW) THEN
751 l_buy_or_sell := 'B';
752 l_object_code := 'OKX_VENDOR';
753 ELSIF (p_order_type_code = G_OSP_ORDER_TYPE_LOAN) THEN
754 l_buy_or_sell := 'S';
755 l_object_code := 'OKX_PARTY';
756 ELSE
757 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_CTRCT');
758 FND_MSG_PUB.ADD;
759 RETURN;
760 END IF;
761 IF(p_party_vendor_id IS NULL OR p_party_vendor_id = FND_API.G_MISS_NUM) THEN
762 IF(p_contract_id IS NOT NULL AND p_contract_id <> FND_API.G_MISS_NUM) THEN
763 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VEND_PTY_ID_NLL');
764 FND_MESSAGE.Set_Token('CONTRACT_ID', p_contract_id);
765 FND_MSG_PUB.ADD;
766 END IF;
767 ELSE
768 IF(p_contract_id IS NOT NULL AND p_contract_id <> FND_API.G_MISS_NUM) THEN
769 OPEN val_contract_id_csr(p_contract_id, p_party_vendor_id, l_buy_or_sell, p_authoring_org_id, l_object_code);
770 FETCH val_contract_id_csr INTO l_exist;
771 IF(val_contract_id_csr%NOTFOUND) THEN
772 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_CTRCT');
773 FND_MESSAGE.Set_Token('CONTRACT_ID', p_contract_id);
774 FND_MSG_PUB.ADD;
775 END IF;
776 CLOSE val_contract_id_csr;
777 END IF;
778 END IF;
779 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
780 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
781 END IF;
782 END validate_contract;
783
784 -------------------------------------------------------------------------------------------------------------
785 PROCEDURE validate_po_header(
786 p_osp_order_id IN NUMBER,
787 p_po_header_id IN NUMBER
788 )IS
789 CURSOR val_po_header_id_csr(p_po_header_id IN NUMBER,p_osp_order_id IN NUMBER) IS
790 SELECT 'x' FROM po_headers_all
791 WHERE po_header_id = p_po_header_id
792 AND reference_num = p_osp_order_id
793 AND interface_source_code = G_APP_NAME;
794 l_exist VARCHAR2(1);
795 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.validate_po_header';
796 BEGIN
797 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
798 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
799 END IF;
800 IF(p_osp_order_id IS NULL OR p_osp_order_id = FND_API.G_MISS_NUM) THEN
801 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_HEADER_INV');
802 FND_MSG_PUB.ADD;
803 RETURN;
804 END IF;
805 IF(p_po_header_id IS NOT NULL AND p_po_header_id <> FND_API.G_MISS_NUM) THEN
806 OPEN val_po_header_id_csr(p_po_header_id, p_osp_order_id);
807 FETCH val_po_header_id_csr INTO l_exist;
808 IF(val_po_header_id_csr%NOTFOUND) THEN
809 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_PO_HEADER_INV');
810 FND_MESSAGE.Set_Token('PO_HEADER_ID', p_po_header_id);
811 FND_MSG_PUB.ADD;
812 END IF;
813 CLOSE val_po_header_id_csr;
814 END IF;
815 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
816 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
817 END IF;
818 END validate_po_header;
819
820 --------------------------------------------------------------------------------------------------------------
821 -- validates osp header information for different order types and DML operations.
822 -- Steps :
823 -- Order Type Code can be Service, Loan , Borrow
824 -- Opreation Flag can be 'C', 'U', 'D' or null
825 -- IF not 'C', record should exist and osp_order_id and object version number should match in AHL_OSP_ORDERS_B table.
826 -- IF 'C', osp_order_id and object version number should be null.
827 -- IMPORTANT NOTE: This procedure is NOT being called for Order Header Creation any more.
828 -- Added by jaramana on January 8, 2008 for the Requisition ER 6034236
829 -- Also Note that operation_flag will never be NULL in the call to this API, as if it is null, then there is no updation
830 -- that needs to be performed on the Order Header, hence no validation is necessary.
831 --------------------------------------------------------------------------------------------------------------
832 PROCEDURE validate_order_header(
833 p_x_osp_order_rec IN OUT NOCOPY osp_order_rec_type)
834 IS
835 CURSOR osp_order_csr(p_osp_order_id IN NUMBER, p_object_version_number IN NUMBER) IS
836 -- po_req_header_id added by jaramana on January 8, 2008 for the Requisition ER 6034236
837 SELECT osp_order_number, order_type_code, single_instance_flag, po_header_id, oe_header_id,vendor_id, vendor_site_id,
838 customer_id,order_date,contract_id,contract_terms,operating_unit_id, po_synch_flag, status_code,
839 po_batch_id, po_request_id,po_agent_id, po_interface_header_id, po_req_header_id , description, vendor_contact_id
840 -- jaramana End
841 FROM ahl_osp_orders_vl
842 WHERE osp_order_id = p_osp_order_id
843 AND object_version_number = p_object_version_number;
844
845 -- Added by jaramana on January 8, 2008 for the Requisition ER 6034236
846 CURSOR chk_requisition_exists_csr(c_osp_order_id IN NUMBER) IS
847 SELECT POREQ.SEGMENT1
848 FROM PO_REQUISITION_HEADERS_ALL POREQ, AHL_OSP_ORDERS_B OSP
849 WHERE POREQ.INTERFACE_SOURCE_LINE_ID = c_osp_order_id
850 AND OSP.OSP_ORDER_ID = c_osp_order_id
851 AND OSP.OPERATING_UNIT_ID = POREQ.ORG_ID
852 AND POREQ.INTERFACE_SOURCE_CODE = AHL_GLOBAL.AHL_APP_SHORT_NAME
853 AND NVL(POREQ.CLOSED_CODE, 'X') NOT IN ('CANCELLED', 'CLOSED', 'CLOSED FOR INVOICE', 'CLOSED FOR RECEIVING',
854 'FINALLY CLOSED', 'REJECTED', 'RETURNED');
855
856 l_req_num VARCHAR2(20);
857
858 l_osp_order_rec osp_order_rec_type;
859 l_operating_unit_id NUMBER;
860 l_new_order_number NUMBER;
861 l_del_cancel_so_lines_tbl del_cancel_so_lines_tbl_type;
862 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.validate_order_header';
863 BEGIN
864 --dbms_output.put_line('Entering : validate_order_header');
865 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
866 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
867 END IF;
868 l_operating_unit_id := mo_global.get_current_org_id();
869 IF (l_operating_unit_id IS NULL) THEN
870 FND_MESSAGE.Set_Name('AHL', 'AHL_OSP_ORG_NOT_SET');
871 FND_MSG_PUB.ADD;
872 END IF;
873 IF FND_MSG_PUB.count_msg > 0 THEN
874 RAISE FND_API.G_EXC_ERROR;
875 -- RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
876 END IF;
877 -- Note added by jaramana on January 8, 2008 for the Requisition ER 6034236
878 -- Note that p_x_osp_order_rec.operation_flag will never be NULL in the call to this API. As an operation_flag of NULL
879 -- means, there need to be no change in the osp_order_header, hence no validation is necessary.
880 IF(p_x_osp_order_rec.operation_flag IS NULL OR p_x_osp_order_rec.operation_flag <> G_OP_CREATE) THEN
881 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
882 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY || '.notCreate', 'operation is not create, it is:'||p_x_osp_order_rec.operation_flag);
883 END IF;
884 IF(p_x_osp_order_rec.osp_order_id IS NULL OR p_x_osp_order_rec.object_version_number IS NULL) THEN
885 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_ID_OBJ_MISS');
886 FND_MSG_PUB.ADD;
887 ELSE
888 -- fetch record and verify the latest record is being dealt with.
889 OPEN osp_order_csr(p_x_osp_order_rec.osp_order_id, p_x_osp_order_rec.object_version_number);
890 -- jaramana modified on January 8, 2008 for the Requisition ER 6034236 (Added po_req_header_id)
891 FETCH osp_order_csr INTO l_osp_order_rec.osp_order_number, l_osp_order_rec.order_type_code,l_osp_order_rec.single_instance_flag,
892 l_osp_order_rec.po_header_id, l_osp_order_rec.oe_header_id,l_osp_order_rec.vendor_id,
893 l_osp_order_rec.vendor_site_id, l_osp_order_rec.customer_id, l_osp_order_rec.order_date,
894 l_osp_order_rec.contract_id, l_osp_order_rec.contract_terms, l_osp_order_rec.operating_unit_id,
895 l_osp_order_rec.po_synch_flag, l_osp_order_rec.status_code, l_osp_order_rec.po_batch_id, l_osp_order_rec.po_request_id,
896 l_osp_order_rec.po_agent_id, l_osp_order_rec.po_interface_header_id, l_osp_order_rec.po_req_header_id, l_osp_order_rec.description, l_osp_order_rec.vendor_contact_id;
897 -- jaramana End
898 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
899 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'osp_order_id='||p_x_osp_order_rec.osp_order_id|| 'ovn='||p_x_osp_order_rec.object_version_number);
900 END IF;
901 -- if record not found, raise error and declare that record has been modified.
902 IF (osp_order_csr%NOTFOUND) THEN
903 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INVOP_OSP_NFOUND');
904 FND_MSG_PUB.ADD;
905 END IF;
906 CLOSE osp_order_csr;
907 -- check existing status. If closed, raise error.
908 IF(l_osp_order_rec.status_code = G_OSP_CLOSED_STATUS) THEN
909 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_STATUS');
910 FND_MSG_PUB.ADD;
911 ELSE
912 g_old_status_code := l_osp_order_rec.status_code;
913 --g_order_status_for_update := l_osp_order_rec.status_code;
914 g_old_type_code := l_osp_order_rec.order_type_code;
915 END IF;
916
917 -- Added by jaramana on January 8, 2008 for the Requisition ER 6034236
918 -- User should not pass G_OSP_REQ_SUBMITTED_STATUS directly. User need to pass G_OSP_SUBMITTED_STATUS and
919 -- depening on the 'Initialize Purchase Requisition' profile we deduce whether Requisition needs to be created
920 IF(p_x_osp_order_rec.status_code is not null AND l_osp_order_rec.status_code <> G_OSP_REQ_SUBMITTED_STATUS AND p_x_osp_order_rec.status_code = G_OSP_REQ_SUBMITTED_STATUS) THEN
921 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_STATUS');
922 FND_MSG_PUB.ADD;
923 END IF;
924
925 --If the Profile 'Initialize Purchase Requisition' is set, then set the status to G_OSP_REQ_SUBMITTED_STATUS
926 --if the passed status is G_OSP_SUBMITTED_STATUS and the old status is not G_OSP_SUBMITTED_STATUS
927 IF (NVL(FND_PROFILE.VALUE('AHL_OSP_INIT_PO_REQ'), 'N') = 'Y') THEN
928 IF(p_x_osp_order_rec.order_type_code IN (G_OSP_ORDER_TYPE_SERVICE, G_OSP_ORDER_TYPE_EXCHANGE) AND
929 (p_x_osp_order_rec.status_code is not null and p_x_osp_order_rec.status_code = G_OSP_SUBMITTED_STATUS and
930 l_osp_order_rec.status_code <> G_OSP_SUBMITTED_STATUS)) THEN
931 p_x_osp_order_rec.status_code := G_OSP_REQ_SUBMITTED_STATUS;
932 END IF;
933 END IF;
934 -- jaramana End
935
936 -- check whether order_type_code is same -- . IF null, default it.
937 IF(p_x_osp_order_rec.order_type_code IS NOT NULL AND p_x_osp_order_rec.order_type_code <> l_osp_order_rec.order_type_code) THEN
938 --item exchange enhancement
939 --only service/exchange ordertype conversion are allowed
940 IF(p_x_osp_order_rec.order_type_code IN ( G_OSP_ORDER_TYPE_SERVICE, G_OSP_ORDER_TYPE_EXCHANGE)
941 AND l_osp_order_rec.order_type_code IN ( G_OSP_ORDER_TYPE_SERVICE, G_OSP_ORDER_TYPE_EXCHANGE)) THEN
942 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
943 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY || '.notCreate', 'Set conversion Flag to Yes');
944 END IF;
945 -- Commented out by jaramana on January 8, 2008 for the Requisition ER 6034236
946 -- g_order_conversion_flag := G_YES_FLAG;
947 -- jaramana End
948 g_old_type_code := l_osp_order_rec.order_type_code;
949 g_new_type_code := p_x_osp_order_rec.order_type_code;
950 ELSE
951 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_TYPE');
952 FND_MSG_PUB.ADD;
953 END IF;
954 ELSE
955 p_x_osp_order_rec.order_type_code := l_osp_order_rec.order_type_code;
956 END IF;
957 -- osp order number can not be changed.
958 IF(p_x_osp_order_rec.osp_order_number IS NOT NULL AND p_x_osp_order_rec.osp_order_number <> l_osp_order_rec.osp_order_number) THEN
959 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_NUM_INV');
960 FND_MESSAGE.Set_Token('ORDER_NUMBER', p_x_osp_order_rec.osp_order_number);
961 FND_MSG_PUB.ADD;
962 END IF;
963 -- order date can not be changed.
964 IF(p_x_osp_order_rec.order_date IS NOT NULL AND TRUNC(p_x_osp_order_rec.order_date) <> TRUNC(l_osp_order_rec.order_date)) THEN
965 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_ORD_DT');
966 FND_MSG_PUB.ADD;
967 END IF;
968 -- operating_unit_id can not change
969 IF(p_x_osp_order_rec.operating_unit_id IS NOT NULL AND p_x_osp_order_rec.operating_unit_id <> l_osp_order_rec.operating_unit_id) THEN
970 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_OPUNIT');
971 FND_MSG_PUB.ADD;
972 END IF;
973
974
975 -- Commented out by jaramana on January 8, 2008 for the Requisition ER 6034236
976 /*
977 Note that p_x_osp_order_rec.operation_flag will never be NULL in the call to this API. As an operation_flag of NULL
978 means, there need to be no change in the osp_order_header, hence no validation is necessary.
979 Hence commenting out the following code
980 */
981 -- if operation_flag is NULL , default po_header_id, oe_header_id (needed for lines)
982 /*
983 IF(p_x_osp_order_rec.operation_flag IS NULL) THEN
984 p_x_osp_order_rec.po_header_id := l_osp_order_rec.po_header_id;
985 p_x_osp_order_rec.oe_header_id := l_osp_order_rec.oe_header_id;
986 p_x_osp_order_rec.operating_unit_id := l_osp_order_rec.operating_unit_id;
987 p_x_osp_order_rec.single_instance_flag := l_osp_order_rec.single_instance_flag;
988 END IF;
989 */
990 -- contract terms should be null.
991 IF(p_x_osp_order_rec.contract_terms IS NOT NULL AND p_x_osp_order_rec.contract_terms <> FND_API.G_MISS_NUM) THEN
992 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_CO');
993 FND_MSG_PUB.ADD;
994 END IF;
995 -- shipping info is not allowed to update in this API
996 IF(p_x_osp_order_rec.oe_header_id IS NOT NULL ) THEN
997 IF(l_osp_order_rec.oe_header_id IS NULL AND p_x_osp_order_rec.oe_header_id <> FND_API.G_MISS_NUM) THEN
998 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_OE'); FND_MSG_PUB.ADD;
999 ELSIF(p_x_osp_order_rec.oe_header_id <> l_osp_order_rec.oe_header_id) THEN
1000 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_OE');
1001 FND_MSG_PUB.ADD;
1002 END IF;
1003 END IF;
1004 END IF;
1005 -- Commented out by jaramana on January 8, 2008 for the Requisition ER 6034236
1006 --This API is not being called during the create mode any more. Hence commenting out the following
1007 --validations. Some of the fields like PO related fields are defaulted to Null ignoring the user passed inputs
1008 --and the rest of them are being validated in the create_osp_order_header API
1009 /*
1010 ELSE -- mode is create and following processing is same for all type of orders
1011
1012 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
1013 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY || '.create', 'operation is create');
1014 END IF;
1015 IF(p_x_osp_order_rec.osp_order_id IS NOT NULL AND p_x_osp_order_rec.osp_order_id <> FND_API.G_MISS_NUM) THEN
1016 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_ID_NNLL');
1017 FND_MSG_PUB.ADD;
1018 END IF;
1019 IF(p_x_osp_order_rec.object_version_number IS NOT NULL AND p_x_osp_order_rec.object_version_number <> FND_API.G_MISS_NUM) THEN
1020 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_OBJV_NNLL');
1021 FND_MSG_PUB.ADD;
1022 END IF;
1023 -- populate order number
1024 IF(p_x_osp_order_rec.osp_order_number IS NOT NULL AND p_x_osp_order_rec.osp_order_number <> FND_API.G_MISS_NUM) THEN
1025 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_NUM_INV');
1026 FND_MESSAGE.Set_Token('ORDER_NUMBER', p_x_osp_order_rec.osp_order_number);
1027 FND_MSG_PUB.ADD;
1028 END IF;
1029 -- populate order_date
1030 IF(p_x_osp_order_rec.order_date IS NOT NULL AND p_x_osp_order_rec.order_date <> FND_API.G_MISS_DATE) THEN
1031 IF(TRUNC(p_x_osp_order_rec.order_date) <> TRUNC(SYSDATE)) THEN
1032 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_ORD_DAT');
1033 FND_MESSAGE.Set_Token('ORDER_DATE', p_x_osp_order_rec.order_date);
1034 FND_MSG_PUB.ADD;
1035 END IF;
1036 ELSE
1037 p_x_osp_order_rec.order_date := TRUNC(SYSDATE);
1038 END IF;
1039 -- populate operating_unit_id
1040 IF(p_x_osp_order_rec.operating_unit_id IS NOT NULL AND p_x_osp_order_rec.operating_unit_id <> FND_API.G_MISS_NUM) THEN
1041 IF(p_x_osp_order_rec.operating_unit_id <> l_operating_unit_id) THEN
1042 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_OP_UNIT');
1043 FND_MSG_PUB.ADD;
1044 END IF;
1045 ELSE
1046 p_x_osp_order_rec.operating_unit_id := l_operating_unit_id;
1047 END IF;
1048 -- po_header_id, oe_header_id, po_batch_id, po_request_id, po_interface_header_id, contract_terms should be null for CREATE.
1049 IF(p_x_osp_order_rec.po_header_id IS NOT NULL AND p_x_osp_order_rec.po_header_id <> FND_API.G_MISS_NUM) THEN
1050 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_PO_NNLL');
1051 FND_MSG_PUB.ADD;
1052 END IF;
1053 IF(p_x_osp_order_rec.oe_header_id IS NOT NULL AND p_x_osp_order_rec.oe_header_id <> FND_API.G_MISS_NUM) THEN
1054 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_OE_NNLL');
1055 FND_MSG_PUB.ADD;
1056 END IF;
1057 IF(p_x_osp_order_rec.po_batch_id IS NOT NULL AND p_x_osp_order_rec.po_batch_id <> FND_API.G_MISS_NUM) THEN
1058 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_PO_NNLL');
1059 FND_MSG_PUB.ADD;
1060 END IF;
1061 IF(p_x_osp_order_rec.po_request_id IS NOT NULL AND p_x_osp_order_rec.po_request_id <> FND_API.G_MISS_NUM) THEN
1062 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_PO_NNLL');
1063 FND_MSG_PUB.ADD;
1064 END IF;
1065 IF(p_x_osp_order_rec.po_interface_header_id IS NOT NULL AND p_x_osp_order_rec.po_interface_header_id <> FND_API.G_MISS_NUM) THEN
1066 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_PO_NNLL');
1067 FND_MSG_PUB.ADD;
1068 END IF;
1069 -- status_code should be null or 'ENTERED'. IF null, default to 'ENTERED'
1070 IF(p_x_osp_order_rec.status_code IS NOT NULL AND p_x_osp_order_rec.status_code <> FND_API.G_MISS_CHAR
1071 AND p_x_osp_order_rec.status_code <> G_OSP_ENTERED_STATUS) THEN
1072 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_STATUS');
1073 FND_MSG_PUB.ADD;
1074 ELSE
1075 p_x_osp_order_rec.status_code := G_OSP_ENTERED_STATUS;
1076 g_old_status_code := G_OSP_ENTERED_STATUS;
1077 --g_order_status_for_update := G_OSP_ENTERED_STATUS;
1078 END IF;
1079 --dbms_output.put_line('Create mode defaulting done');
1080 */
1081 END IF;
1082 IF FND_MSG_PUB.count_msg > 0 THEN
1083 RAISE FND_API.G_EXC_ERROR;
1084 -- RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1085 END IF;
1086 ----------------------------
1087 -- forcing null column rules
1088 ----------------------------
1089 -- add item exchange enhancement to if condition
1090 IF (p_x_osp_order_rec.order_type_code IN ( G_OSP_ORDER_TYPE_SERVICE, G_OSP_ORDER_TYPE_EXCHANGE))THEN
1091 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
1092 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY || '.type', 'Update Order type is Service or Exchange');
1093 END IF;
1094 -- contract_id and customer_id must be null for SERVICE or EXCHANGE
1095 IF(p_x_osp_order_rec.contract_id IS NOT NULL AND p_x_osp_order_rec.contract_id <> FND_API.G_MISS_NUM) THEN
1096 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_CTRCT');
1097 FND_MESSAGE.Set_Token('CONTRACT_ID', p_x_osp_order_rec.contract_id);
1098 FND_MSG_PUB.ADD;
1099 END IF;
1100 IF(p_x_osp_order_rec.customer_id IS NOT NULL AND p_x_osp_order_rec.customer_id <> FND_API.G_MISS_NUM) THEN
1101 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_CUST_ID_INV');
1102 FND_MESSAGE.Set_Token('CUSTOMER_ID', p_x_osp_order_rec.customer_id);
1103 FND_MSG_PUB.ADD;
1104 END IF;
1105 IF(p_x_osp_order_rec.contract_terms IS NOT NULL AND p_x_osp_order_rec.contract_terms <> FND_API.G_MISS_NUM) THEN
1106 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_CO');
1107 FND_MSG_PUB.ADD;
1108 END IF;
1109 ELSIF (p_x_osp_order_rec.order_type_code IN( G_OSP_ORDER_TYPE_LOAN,G_OSP_ORDER_TYPE_BORROW) ) THEN
1110 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
1111 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY || '.type', 'Update Order type is Loan or Borrow');
1112 END IF;
1113 -- po_agent_id,vendor_id(FOR LOAN only) and vendor_site_id must be null.
1114 IF(p_x_osp_order_rec.po_agent_id IS NOT NULL AND p_x_osp_order_rec.po_agent_id <> FND_API.G_MISS_NUM) THEN
1115 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_BUYER_ID_INV');
1116 FND_MESSAGE.Set_Token('BUYER_ID', p_x_osp_order_rec.po_agent_id);
1117 FND_MSG_PUB.ADD;
1118 END IF;
1119 IF(p_x_osp_order_rec.vendor_site_id IS NOT NULL AND p_x_osp_order_rec.vendor_site_id <> FND_API.G_MISS_NUM) THEN
1120 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENSITE_ID_INV');
1121 FND_MESSAGE.Set_Token('VENDOR_SITE_ID', p_x_osp_order_rec.vendor_site_id);
1122 FND_MSG_PUB.ADD;
1123 END IF;
1124 IF(p_x_osp_order_rec.order_type_code = G_OSP_ORDER_TYPE_LOAN) THEN
1125 IF(p_x_osp_order_rec.vendor_id IS NOT NULL AND p_x_osp_order_rec.vendor_id <> FND_API.G_MISS_NUM) THEN
1126 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENDOR_ID_INV');
1127 FND_MESSAGE.Set_Token('VENDOR_ID', p_x_osp_order_rec.vendor_id);
1128 FND_MSG_PUB.ADD;
1129 END IF;
1130 END IF;
1131 -- po_header_id, po_batch_id, po_request_id, po_interface_header_id, contract_terms should be null
1132 IF(p_x_osp_order_rec.po_header_id IS NOT NULL AND p_x_osp_order_rec.po_header_id <> FND_API.G_MISS_NUM) THEN
1133 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_PO_NNLL');
1134 FND_MSG_PUB.ADD;
1135 END IF;
1136 IF(p_x_osp_order_rec.po_batch_id IS NOT NULL AND p_x_osp_order_rec.po_batch_id <> FND_API.G_MISS_NUM) THEN
1137 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_PO_NNLL');
1138 FND_MSG_PUB.ADD;
1139 END IF;
1140 IF(p_x_osp_order_rec.po_request_id IS NOT NULL AND p_x_osp_order_rec.po_request_id <> FND_API.G_MISS_NUM) THEN
1141 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_PO_NNLL');
1142 FND_MSG_PUB.ADD;
1143 END IF;
1144 IF(p_x_osp_order_rec.po_interface_header_id IS NOT NULL AND p_x_osp_order_rec.po_interface_header_id <> FND_API.G_MISS_NUM) THEN
1145 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_PO_NNLL');
1146 FND_MSG_PUB.ADD;
1147 END IF;
1148
1149 -- Added by jaramana on January 8, 2008 for the Requisition ER 6034236
1150 IF(p_x_osp_order_rec.po_req_header_id IS NOT NULL AND p_x_osp_order_rec.po_req_header_id <> FND_API.G_MISS_NUM) THEN
1151 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_REQ_NNLL');
1152 FND_MSG_PUB.ADD;
1153 END IF;
1154 -- jaramana End
1155
1156 IF(p_x_osp_order_rec.contract_terms IS NOT NULL AND p_x_osp_order_rec.contract_terms <> FND_API.G_MISS_NUM) THEN
1157 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_CO');
1158 FND_MSG_PUB.ADD;
1159 END IF;
1160
1161 END IF;
1162 --dbms_output.put_line('ensured null columns');
1163 IF FND_MSG_PUB.count_msg > 0 THEN
1164 RAISE FND_API.G_EXC_ERROR;
1165 -- RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1166 END IF;
1167 IF (p_x_osp_order_rec.order_type_code IN ( G_OSP_ORDER_TYPE_SERVICE, G_OSP_ORDER_TYPE_EXCHANGE)) THEN --item exchange enhancement add G_OSP_ORDER_TYPE_EXCHANGE condition
1168 -- Commented out by jaramana on January 8, 2008 for the Requisition ER 6034236
1169 -- This API is not being called during the create mode any more.
1170 -- Hence commenting out the following validations.
1171
1172 /*
1173 IF(p_x_osp_order_rec.operation_flag = G_OP_CREATE) THEN
1174 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
1175 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY || '.type.oper', 'Update Order type is Service or Exchange Operation is Create');
1176 END IF;
1177 --dbms_output.put_line('validate single_instance_flag');
1178 --set single_instance_flag
1179 IF(p_x_osp_order_rec.single_instance_flag IS NULL OR p_x_osp_order_rec.single_instance_flag = FND_API.G_MISS_CHAR)THEN
1180 p_x_osp_order_rec.single_instance_flag := G_NO_FLAG;
1181 ELSIF (p_x_osp_order_rec.single_instance_flag NOT IN(G_NO_FLAG,G_YES_FLAG))THEN
1182 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_INST_FLG');
1183 FND_MESSAGE.Set_Token('INST_FLG', p_x_osp_order_rec.single_instance_flag);
1184 FND_MSG_PUB.ADD;
1185 END IF;
1186 --dbms_output.put_line('validate vendor');
1187
1188 -- validate vendor_id.
1189 IF(p_x_osp_order_rec.vendor_id IS NULL OR p_x_osp_order_rec.vendor_id = FND_API.G_MISS_NUM) THEN
1190 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENDOR_ID_NLL');
1191 FND_MSG_PUB.ADD;
1192 ELSE
1193 validate_vendor(p_x_osp_order_rec.vendor_id);
1194 END IF;
1195 --dbms_output.put_line('validate vendor site');
1196 -- validate vendor_site_id.
1197 IF(p_x_osp_order_rec.vendor_site_id IS NULL OR p_x_osp_order_rec.vendor_site_id = FND_API.G_MISS_NUM) THEN
1198 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENSITE_ID_NLL');
1199 FND_MSG_PUB.ADD;
1200 ELSE
1201 validate_vendor_site(p_x_osp_order_rec.vendor_id, p_x_osp_order_rec.vendor_site_id);
1202 END IF;
1203
1204 validate_vendor_site_contact(p_x_osp_order_rec.vendor_id,
1205 p_x_osp_order_rec.vendor_site_id,
1206 p_x_osp_order_rec.vendor_contact_id);
1207 -- validate po_agent_id.
1208 --dbms_output.put_line('validate buyer');
1209 IF(p_x_osp_order_rec.po_agent_id IS NULL OR p_x_osp_order_rec.po_agent_id = FND_API.G_MISS_NUM) THEN
1210 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_BUYER_ID_NLL');
1211 FND_MSG_PUB.ADD;
1212 ELSE
1213 validate_buyer(p_x_osp_order_rec.po_agent_id);
1214 END IF;
1215 */
1216 -- jaramana End
1217 IF(p_x_osp_order_rec.operation_flag = G_OP_UPDATE) THEN
1218 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
1219 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY || '.srvExch.update', 'Update Order type is Service or Exchange Operation is Update ');
1220 END IF;
1221 -- Modified by jaramana on January 9, 2008 for the Requisition ER 6034236 (Added G_OSP_REQ_SUB_FAILED_STATUS)
1222 IF(g_old_status_code IN (G_OSP_ENTERED_STATUS, G_OSP_SUB_FAILED_STATUS, G_OSP_REQ_SUB_FAILED_STATUS)) THEN
1223 -- jaramana End
1224 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
1225 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY || '.srvExch.update.', 'Update Order type is Service or Exchange Operation is Update'
1226 || 'g_old_status_code' || g_old_status_code);
1227 END IF;
1228 -- po_header_id should be null.
1229 IF(p_x_osp_order_rec.po_header_id IS NOT NULL AND p_x_osp_order_rec.po_header_id <> FND_API.G_MISS_NUM) THEN
1230 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_PO_NNLL');
1231 FND_MSG_PUB.ADD;
1232 END IF;
1233 -- Modified by jaramana on January 9, 2008 for the Requisition ER 6034236
1234 -- req_header_id should be null.
1235 IF(p_x_osp_order_rec.po_req_header_id IS NOT NULL AND p_x_osp_order_rec.po_req_header_id <> FND_API.G_MISS_NUM) THEN
1236 FND_MESSAGE.Set_Name(G_APP_NAME, 'AHL_OSP_ORD_REQ_NNLL');
1237 FND_MSG_PUB.ADD;
1238 END IF;
1239 -- jaramana End
1240
1241 -- Modified by jaramana on January 9, 2008 for the Requisition ER 6034236
1242 -- status_code should be null,'ENTERED', 'SUBMISSION_FAILED' or 'SUBMITTED'
1243 /*
1244 IF(p_x_osp_order_rec.status_code IS NOT NULL AND
1245 p_x_osp_order_rec.status_code NOT IN(G_OSP_ENTERED_STATUS, G_OSP_SUB_FAILED_STATUS, G_OSP_SUBMITTED_STATUS)) THEN
1246 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_STATUS');
1247 FND_MSG_PUB.ADD;
1248 ELSIF (g_old_status_code = G_OSP_ENTERED_STATUS AND p_x_osp_order_rec.status_code = G_OSP_SUB_FAILED_STATUS) THEN
1249 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_STATUS');
1250 FND_MSG_PUB.ADD;
1251 ELSIF (g_old_status_code = G_OSP_SUB_FAILED_STATUS AND p_x_osp_order_rec.status_code = G_OSP_ENTERED_STATUS) THEN
1252 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_STATUS');
1253 FND_MSG_PUB.ADD;
1254 END IF;
1255 */
1256 /*
1257 1. If the current status is G_OSP_ENTERED_STATUS, the status cannot be changed to G_OSP_SUB_FAILED_STATUS or
1258 G_OSP_REQ_SUB_FAILED_STATUS. It can only be changed to G_OSP_SUBMITTED_STATUS or G_OSP_REQ_SUBMITTED_STATUS or
1259 it can be changed to G_OSP_ENTERED_STATUS (No update)
1260
1261 2. If the current status is G_OSP_SUB_FAILED_STATUS, the status cannot be changed to G_OSP_ENTERED_STATUS or
1262 G_OSP_REQ_SUB_FAILED_STATUS. It can only be changed to G_OSP_SUBMITTED_STATUS or G_OSP_REQ_SUBMITTED_STATUS or
1263 it can be changed to G_OSP_SUB_FAILED_STATUS (No update)
1264
1265 3. If the current status is G_OSP_REQ_SUB_FAILED_STATUS, the status cannot be changed to G_OSP_ENTERED_STATUS or
1266 G_OSP_SUB_FAILED_STATUS. It can only be changed to G_OSP_SUBMITTED_STATUS or G_OSP_REQ_SUBMITTED_STATUS or
1267 it can be changed to G_OSP_REQ_SUB_FAILED_STATUS (No update)
1268
1269 In all the above the changes status is either itself or G_OSP_SUBMITTED_STATUS or G_OSP_REQ_SUBMITTED_STATUS
1270 */
1271
1272 IF(p_x_osp_order_rec.status_code IS NOT NULL AND p_x_osp_order_rec.status_code <> g_old_status_code AND p_x_osp_order_rec.status_code NOT IN (G_OSP_SUBMITTED_STATUS,G_OSP_REQ_SUBMITTED_STATUS )) THEN
1273 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_STATUS');
1274 FND_MSG_PUB.ADD;
1275 END IF;
1276
1277 --
1278 --set single_instance_flag
1279 IF(p_x_osp_order_rec.single_instance_flag = FND_API.G_MISS_CHAR)THEN
1280 p_x_osp_order_rec.single_instance_flag := G_NO_FLAG;
1281 ELSIF (p_x_osp_order_rec.single_instance_flag IS NOT NULL AND p_x_osp_order_rec.single_instance_flag NOT IN(G_NO_FLAG,G_YES_FLAG))THEN
1282 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_INST_FLG');
1283 FND_MESSAGE.Set_Token('INST_FLG', p_x_osp_order_rec.single_instance_flag);
1284 FND_MSG_PUB.ADD;
1285 END IF;
1286 /*
1287 -- validate vendor_id
1288 IF(p_x_osp_order_rec.vendor_id IS NOT NULL AND p_x_osp_order_rec.vendor_id = FND_API.G_MISS_NUM) THEN
1289 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENDOR_ID_NLL');
1290 FND_MSG_PUB.ADD;
1291 ELSIF (p_x_osp_order_rec.vendor_id IS NOT NULL) THEN
1292 validate_vendor(p_x_osp_order_rec.vendor_id);
1293 END IF;
1294 -- validate vendor_site_id.
1295 IF(p_x_osp_order_rec.vendor_site_id IS NOT NULL AND p_x_osp_order_rec.vendor_site_id = FND_API.G_MISS_NUM) THEN
1296 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENSITE_ID_NLL');
1297 FND_MSG_PUB.ADD;
1298 ELSE
1299 p_x_osp_order_rec.vendor_site_id := NVL(p_x_osp_order_rec.vendor_site_id,l_osp_order_rec.vendor_site_id);
1300 p_x_osp_order_rec.vendor_id := NVL(p_x_osp_order_rec.vendor_id, l_osp_order_rec.vendor_id);
1301 validate_vendor_site(p_x_osp_order_rec.vendor_id, p_x_osp_order_rec.vendor_site_id);
1302 END IF;
1303 */
1304 --When updating OSP order header, vendor_id is required
1305 --G_MISS/Null conversion has already been made in default_unchanged_order_header
1306 IF(p_x_osp_order_rec.vendor_id IS NULL) THEN
1307 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENSITE_ID_NLL');
1308 FND_MSG_PUB.ADD;
1309 END IF;
1310
1311 --When updating OSP order header, vendor_site_id is required
1312 --G_MISS/Null conversion has already been made in default_unchanged_order_header
1313 IF(p_x_osp_order_rec.vendor_site_id IS NULL) THEN
1314 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENDOR_ID_NLL');
1315 FND_MSG_PUB.ADD;
1316 END IF;
1317
1318 validate_vendor_site_contact(p_x_osp_order_rec.vendor_id,
1319 p_x_osp_order_rec.vendor_site_id,
1320 p_x_osp_order_rec.vendor_contact_id);
1321 -- validate po_agent_id.
1322 --dbms_output.put_line('validate buyer in update');
1323 --IF(p_x_osp_order_rec.po_agent_id IS NOT NULL AND p_x_osp_order_rec.po_agent_id = FND_API.G_MISS_NUM) THEN
1324 --G_MISS/Null conversion has already been made in default_unchanged_order_header
1325 IF(p_x_osp_order_rec.po_agent_id IS NULL) THEN
1326 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_BUYER_ID_NLL');
1327 FND_MSG_PUB.ADD;
1328 ELSIF (p_x_osp_order_rec.po_agent_id IS NOT NULL) THEN
1329 validate_buyer(p_x_osp_order_rec.po_agent_id);
1330 END IF;
1331 -- Added by jaramana on January 9, 2008 for the Requisition ER 6034236
1332 -- Prevent Resubmission if the old status is G_OSP_REQ_SUB_FAILED_STATUS
1333 -- and new status is (G_OSP_SUBMITTED_STATUS or G_OSP_REQ_SUBMITTED_STATUS)
1334 -- and if the requisition header is not yet deleted by the user.
1335 -- This is the case where the Requisition was created only for some OSP lines
1336 -- and failed for the remaining - user has to manually delete the Requisition before resubmitting.
1337 IF(g_old_status_code = G_OSP_REQ_SUB_FAILED_STATUS AND
1338 p_x_osp_order_rec.status_code IS NOT NULL AND
1339 p_x_osp_order_rec.status_code IN (G_OSP_SUBMITTED_STATUS,G_OSP_REQ_SUBMITTED_STATUS)) THEN
1340 OPEN chk_requisition_exists_csr(p_x_osp_order_rec.osp_order_id);
1341 FETCH chk_requisition_exists_csr INTO l_req_num;
1342 IF (chk_requisition_exists_csr%FOUND) THEN
1343 FND_MESSAGE.Set_Name(G_APP_NAME, 'AHL_OSP_REQ_NOT_DELETED');
1344 FND_MESSAGE.Set_Token('REQ_NUM', l_req_num);
1345 FND_MSG_PUB.ADD;
1346 END IF;
1347 CLOSE chk_requisition_exists_csr;
1348 END IF;
1349 -- End addition by jaramana on January 9, 2008
1350 ELSIF (g_old_status_code = G_OSP_SUBMITTED_STATUS) THEN
1351 -- status_code should be null,'SUBMITTED', 'SUBMISSION_FAILED' or 'PO_CREATED'
1352 IF(p_x_osp_order_rec.status_code IS NULL OR p_x_osp_order_rec.status_code = G_OSP_SUBMITTED_STATUS) THEN
1353 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
1354 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY || '.srvExch.update.', 'Update Order type is Service or Exchange Operation is Update'
1355 || 'g_old_status_code: ' || g_old_status_code || 'new status: ' || p_x_osp_order_rec.status_code );
1356 END IF;
1357 -- po_header_id should be null.
1358 IF(p_x_osp_order_rec.po_header_id IS NOT NULL AND p_x_osp_order_rec.po_header_id <> FND_API.G_MISS_NUM) THEN
1359 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_PO_NNLL');
1360 FND_MSG_PUB.ADD;
1361 END IF;
1362
1363 -- Added by jaramana on January 9, 2008 for the Requisition ER 6034236
1364 -- req_header_id should be null.
1365 IF(p_x_osp_order_rec.po_req_header_id IS NOT NULL AND p_x_osp_order_rec.po_req_header_id <> FND_API.G_MISS_NUM) THEN
1366 FND_MESSAGE.Set_Name(G_APP_NAME, 'AHL_OSP_ORD_REQ_NNLL');
1367 FND_MSG_PUB.ADD;
1368 END IF;
1369 -- jaramana End
1370
1371 -- single_instance_flag cant change
1372 IF(p_x_osp_order_rec.single_instance_flag IS NOT NULL AND p_x_osp_order_rec.single_instance_flag <> l_osp_order_rec.single_instance_flag) THEN
1373 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_INST_FLG_CHG');
1374 FND_MSG_PUB.ADD;
1375 END IF;
1376 -- vendor_id cant change
1377 IF(p_x_osp_order_rec.vendor_id IS NOT NULL AND p_x_osp_order_rec.vendor_id <> l_osp_order_rec.vendor_id) THEN
1378 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_VEN_CHG');
1379 FND_MSG_PUB.ADD;
1380 END IF;
1381 -- vendor_site_id cant change
1382 IF(p_x_osp_order_rec.vendor_site_id IS NOT NULL AND p_x_osp_order_rec.vendor_site_id <> l_osp_order_rec.vendor_site_id) THEN
1383 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_VEN_STE_CHG');
1384 FND_MSG_PUB.ADD;
1385 END IF;
1386
1387 -- Added by jaramana on January 9, 2008 for the Requisition ER 6034236
1388 -- This should have been present with ISO changes. Adding now.
1389 -- vendor_contact_id cant change
1390 IF(p_x_osp_order_rec.vendor_contact_id IS NOT NULL AND p_x_osp_order_rec.vendor_contact_id <> l_osp_order_rec.vendor_contact_id) THEN
1391 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_VEN_CTCT_CHG ');
1392 FND_MSG_PUB.ADD;
1393 END IF;
1394 -- jaramana End
1395
1396 -- Buyer cant change
1397 IF(p_x_osp_order_rec.po_agent_id IS NOT NULL AND p_x_osp_order_rec.po_agent_id <> l_osp_order_rec.po_agent_id) THEN
1398 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_BUYER_CHG');
1399 FND_MSG_PUB.ADD;
1400 END IF;
1401 -- jaramana modified on January 9, 2008 for the Requisition ER 6034236
1402 --The transitions from G_OSP_SUBMITTED_STATUS -> G_OSP_SUB_FAILED_STATUS and
1403 --G_OSP_SUBMITTED_STATUS -> G_OSP_PO_CREATED_STATUS are not done from this API and are handled by the PO Synch
1404 --API. Hence removing these tranisitions from here. If at all these transitions take place, we are throwing a
1405 --validation error.
1406 /*
1407 ELSIF (p_x_osp_order_rec.status_code = G_OSP_SUB_FAILED_STATUS) THEN
1408 -- po_header_id should be null.
1409 IF(p_x_osp_order_rec.po_header_id IS NOT NULL AND p_x_osp_order_rec.po_header_id <> FND_API.G_MISS_NUM) THEN
1410 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_PO_NNLL');
1411 FND_MSG_PUB.ADD;
1412 END IF;
1413 --set single_instance_flag
1414 IF(p_x_osp_order_rec.single_instance_flag = FND_API.G_MISS_CHAR)THEN
1415 p_x_osp_order_rec.single_instance_flag := G_NO_FLAG;
1416 ELSIF (p_x_osp_order_rec.single_instance_flag IS NOT NULL AND p_x_osp_order_rec.single_instance_flag NOT IN(G_NO_FLAG,G_YES_FLAG))THEN
1417 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_INST_FLG');
1418 FND_MESSAGE.Set_Token('INST_FLG', p_x_osp_order_rec.single_instance_flag);
1419 FND_MSG_PUB.ADD;
1420 END IF;
1421 */
1422 /*
1423 -- validate vendor_id.
1424 IF(p_x_osp_order_rec.vendor_id IS NOT NULL AND p_x_osp_order_rec.vendor_id = FND_API.G_MISS_NUM) THEN
1425 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENDOR_ID_NLL');
1426 FND_MSG_PUB.ADD;
1427 ELSIF (p_x_osp_order_rec.vendor_id IS NOT NULL) THEN
1428 validate_vendor(p_x_osp_order_rec.vendor_id);
1429 END IF;
1430 -- validate vendor_site_id.
1431 IF(p_x_osp_order_rec.vendor_site_id IS NOT NULL AND p_x_osp_order_rec.vendor_site_id = FND_API.G_MISS_NUM) THEN
1432 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENSITE_ID_NLL');
1433 FND_MSG_PUB.ADD;
1434 ELSE
1435 p_x_osp_order_rec.vendor_site_id := NVL(p_x_osp_order_rec.vendor_site_id,l_osp_order_rec.vendor_site_id);
1436 p_x_osp_order_rec.vendor_id := NVL(p_x_osp_order_rec.vendor_id, l_osp_order_rec.vendor_id);
1437 validate_vendor_site(p_x_osp_order_rec.vendor_id, p_x_osp_order_rec.vendor_site_id);
1438 END IF;
1439 */
1440 /*
1441 validate_vendor_site_contact(p_x_osp_order_rec.vendor_id,
1442 p_x_osp_order_rec.vendor_site_id,
1443 p_x_osp_order_rec.vendor_contact_id);
1444 -- validate po_agent_id.
1445 --dbms_output.put_line('validate buyer in update');
1446 IF(p_x_osp_order_rec.po_agent_id IS NOT NULL AND p_x_osp_order_rec.po_agent_id = FND_API.G_MISS_NUM) THEN
1447 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_BUYER_ID_NLL');
1448 FND_MSG_PUB.ADD;
1449 ELSIF (p_x_osp_order_rec.po_agent_id IS NOT NULL) THEN
1450 validate_buyer(p_x_osp_order_rec.po_agent_id);
1451 END IF;
1452 -- set status_code for lines
1453 g_order_status_for_update := G_OSP_SUB_FAILED_STATUS;
1454 ELSIF (p_x_osp_order_rec.status_code = G_OSP_PO_CREATED_STATUS) THEN
1455 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
1456 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY || '.srvExch.update.', 'Update Order type is Service or Exchange Operation is Update'
1457 || 'g_old_status_code: ' || g_old_status_code || 'new status: ' || p_x_osp_order_rec.status_code );
1458 END IF;
1459 -- po_header_id should be not be null.
1460 IF(p_x_osp_order_rec.po_header_id IS NULL OR p_x_osp_order_rec.po_header_id = FND_API.G_MISS_NUM) THEN
1461 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_PO_NLL');
1462 FND_MSG_PUB.ADD;
1463 ELSE
1464 validate_po_header(p_x_osp_order_rec.osp_order_id,p_x_osp_order_rec.po_header_id);
1465 END IF;
1466 -- single_instance_flag cant change
1467 IF(p_x_osp_order_rec.single_instance_flag IS NOT NULL AND p_x_osp_order_rec.single_instance_flag <> l_osp_order_rec.single_instance_flag) THEN
1468 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_INST_FLG_CHG');
1469 FND_MSG_PUB.ADD;
1470 END IF;
1471 --PO Synch enhancement vendor id and vendor sitecode can change if the change come from PO
1472 -- vendor_id cannot change unless it was change in PO
1473 IF(p_x_osp_order_rec.vendor_id IS NOT NULL AND p_x_osp_order_rec.vendor_id <> l_osp_order_rec.vendor_id) THEN
1474 IF( vendor_id_exist_in_PO(l_osp_order_rec.po_header_id, p_x_osp_order_rec.vendor_id) = false) THEN
1475 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_VEN_CHG');
1476 FND_MSG_PUB.ADD;
1477 END IF;
1478 END IF;
1479 -- vendor_site_id cannot change unless it was changed in PO
1480 IF(p_x_osp_order_rec.vendor_site_id IS NOT NULL AND p_x_osp_order_rec.vendor_site_id <> l_osp_order_rec.vendor_site_id) THEN
1481 IF( vendor_site_id_exist_in_PO(l_osp_order_rec.po_header_id, p_x_osp_order_rec.vendor_site_id) = false) THEN
1482 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_VEN_STE_CHG');
1483 FND_MSG_PUB.ADD;
1484 END IF;
1485 END IF;
1486 -- Buyer cant change
1487 IF(p_x_osp_order_rec.po_agent_id IS NOT NULL AND p_x_osp_order_rec.po_agent_id <> l_osp_order_rec.po_agent_id) THEN
1488 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_BUYER_CHG');
1489 FND_MSG_PUB.ADD;
1490 END IF;
1491 -- set status_code for lines
1492 g_order_status_for_update := G_OSP_PO_CREATED_STATUS;
1493 */
1494 -- jaramana End
1495 ELSE
1496 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_STATUS');
1497 FND_MSG_PUB.ADD;
1498 END IF;
1499
1500 ELSIF (g_old_status_code = G_OSP_PO_CREATED_STATUS) THEN
1501 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
1502 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY || '.srvExch.update.', 'Update Order type is Service or Exchange Operation is Update'
1503 || 'g_old_status_code: ' || g_old_status_code);
1504 END IF;
1505 -- status_code should be null, 'PO_CREATED' or 'CLOSED'
1506 IF(p_x_osp_order_rec.status_code IS NULL OR p_x_osp_order_rec.status_code IN( G_OSP_PO_CREATED_STATUS,G_OSP_CLOSED_STATUS)) THEN
1507 -- po_header_id cant change
1508 IF(p_x_osp_order_rec.po_header_id IS NOT NULL AND p_x_osp_order_rec.po_header_id <> l_osp_order_rec.po_header_id) THEN
1509 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_PO_CHG');
1510 FND_MSG_PUB.ADD;
1511 END IF;
1512
1513 -- jaramana modified on January 9, 2008 for the Requisition ER 6034236
1514 -- req_header_id should be null.
1515 IF(p_x_osp_order_rec.po_req_header_id IS NOT NULL AND p_x_osp_order_rec.po_req_header_id <> FND_API.G_MISS_NUM) THEN
1516 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_REQ_NNLL');
1517 FND_MSG_PUB.ADD;
1518 END IF;
1519 -- jaramana End
1520
1521 -- single_instance_flag cant change
1522 IF(p_x_osp_order_rec.single_instance_flag IS NOT NULL AND p_x_osp_order_rec.single_instance_flag <> l_osp_order_rec.single_instance_flag) THEN
1523 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_INST_FLG_CHG');
1524 FND_MSG_PUB.ADD;
1525 END IF;
1526 /*
1527 --PO Synch enhancement vendor id and vendor sitecode can change if the change come from PO
1528 -- vendor_id cant change
1529 IF(p_x_osp_order_rec.vendor_id IS NOT NULL AND p_x_osp_order_rec.vendor_id <> l_osp_order_rec.vendor_id) THEN
1530 IF( vendor_id_exist_in_PO(l_osp_order_rec.po_header_id, p_x_osp_order_rec.vendor_id) = false) THEN
1531 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_VEN_CHG');
1532 FND_MSG_PUB.ADD;
1533 END IF;
1534 END IF;
1535 -- vendor_site_id cant change
1536 IF(p_x_osp_order_rec.vendor_site_id IS NOT NULL AND p_x_osp_order_rec.vendor_site_id <> l_osp_order_rec.vendor_site_id) THEN
1537 IF( vendor_site_id_exist_in_PO(l_osp_order_rec.po_header_id, p_x_osp_order_rec.vendor_site_id) = false) THEN
1538 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_VEN_STE_CHG');
1539 FND_MSG_PUB.ADD;
1540 END IF;
1541 END IF;
1542 */
1543 -- Changes by jaramana on January 9, 2008 for the Requisition ER 6034236
1544 -- We are not planning to support this PO attribute continuous synch anymore.
1545
1546 -- vendor_id cant change
1547 IF(p_x_osp_order_rec.vendor_id IS NOT NULL AND p_x_osp_order_rec.vendor_id <> l_osp_order_rec.vendor_id) THEN
1548 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_VEN_CHG');
1549 FND_MSG_PUB.ADD;
1550 END IF;
1551 -- vendor_site_id cant change
1552 IF(p_x_osp_order_rec.vendor_site_id IS NOT NULL AND p_x_osp_order_rec.vendor_site_id <> l_osp_order_rec.vendor_site_id) THEN
1553 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_VEN_STE_CHG');
1554 FND_MSG_PUB.ADD;
1555 END IF;
1556 -- vendor_contact_id cant change
1557 IF(p_x_osp_order_rec.vendor_contact_id IS NOT NULL AND p_x_osp_order_rec.vendor_contact_id <> l_osp_order_rec.vendor_contact_id) THEN
1558 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_VEN_CTCT_CHG ');
1559 FND_MSG_PUB.ADD;
1560 END IF;
1561 -- jaramana End
1562
1563 -- Buyer cant change
1564 IF(p_x_osp_order_rec.po_agent_id IS NOT NULL AND p_x_osp_order_rec.po_agent_id <> l_osp_order_rec.po_agent_id) THEN
1565 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_BUYER_CHG');
1566 FND_MSG_PUB.ADD;
1567 END IF;
1568 -- set status_code for lines
1569 --g_order_status_for_update := G_OSP_PO_CREATED_STATUS;
1570 ELSE
1571 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_STATUS');
1572 FND_MSG_PUB.ADD;
1573 END IF;
1574 -- Added by jaramana on January 9, 2008 for the Requisition ER 6034236
1575 ELSIF (g_old_status_code = G_OSP_REQ_SUBMITTED_STATUS) THEN
1576 IF(p_x_osp_order_rec.status_code IS NULL OR p_x_osp_order_rec.status_code = G_OSP_REQ_SUBMITTED_STATUS) THEN
1577 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
1578 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY || '.srvExch.update.', 'Update Order type is Service or Exchange Operation is Update'||
1579 'g_old_status_code: ' || g_old_status_code || 'new status: ' || p_x_osp_order_rec.status_code );
1580 END IF;
1581 -- po_header_id should be null.
1582 IF(p_x_osp_order_rec.po_header_id IS NOT NULL AND p_x_osp_order_rec.po_header_id <> FND_API.G_MISS_NUM) THEN
1583 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_PO_NNLL');
1584 FND_MSG_PUB.ADD;
1585 END IF;
1586
1587 -- req_header_id should be null.
1588 IF(p_x_osp_order_rec.po_req_header_id IS NOT NULL AND p_x_osp_order_rec.po_req_header_id <> FND_API.G_MISS_NUM) THEN
1589 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_REQ_NNLL');
1590 FND_MSG_PUB.ADD;
1591 END IF;
1592
1593 -- single_instance_flag cant change
1594 IF(p_x_osp_order_rec.single_instance_flag IS NOT NULL AND p_x_osp_order_rec.single_instance_flag <> l_osp_order_rec.single_instance_flag) THEN
1595 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_INST_FLG_CHG');
1596 FND_MSG_PUB.ADD;
1597 END IF;
1598 -- vendor_id cant change
1599 IF(p_x_osp_order_rec.vendor_id IS NOT NULL AND p_x_osp_order_rec.vendor_id <> l_osp_order_rec.vendor_id) THEN
1600 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_VEN_CHG');
1601 FND_MSG_PUB.ADD;
1602 END IF;
1603 -- vendor_site_id cant change
1604 IF(p_x_osp_order_rec.vendor_site_id IS NOT NULL AND p_x_osp_order_rec.vendor_site_id <> l_osp_order_rec.vendor_site_id) THEN
1605 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_VEN_STE_CHG');
1606 FND_MSG_PUB.ADD;
1607 END IF;
1608 -- vendor_contact_id cant change
1609 IF(p_x_osp_order_rec.vendor_contact_id IS NOT NULL AND p_x_osp_order_rec.vendor_contact_id <> l_osp_order_rec.vendor_contact_id) THEN
1610 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_VEN_CTCT_CHG ');
1611 FND_MSG_PUB.ADD;
1612 END IF;
1613 -- Buyer cant change
1614 IF(p_x_osp_order_rec.po_agent_id IS NOT NULL AND p_x_osp_order_rec.po_agent_id <> l_osp_order_rec.po_agent_id) THEN
1615 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_BUYER_CHG');
1616 FND_MSG_PUB.ADD;
1617 END IF;
1618 ELSE
1619 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_STATUS');
1620 FND_MSG_PUB.ADD;
1621 END IF;
1622
1623 ELSIF (g_old_status_code = G_OSP_REQ_CREATED_STATUS) THEN
1624 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
1625 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY || '.srvExch.update.', 'Update Order type is Service or Exchange Operation is Update'
1626 || 'g_old_status_code: ' || g_old_status_code);
1627 END IF;
1628 -- status_code should be null, 'REQ_CREATED' or 'CLOSED'
1629 IF(p_x_osp_order_rec.status_code IS NULL OR p_x_osp_order_rec.status_code IN( G_OSP_REQ_CREATED_STATUS,G_OSP_CLOSED_STATUS)) THEN
1630 -- req_header_id cant change
1631 IF(p_x_osp_order_rec.po_req_header_id IS NOT NULL AND p_x_osp_order_rec.po_req_header_id <> l_osp_order_rec.po_req_header_id) THEN
1632 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_REQ_CHG');
1633 FND_MSG_PUB.ADD;
1634 END IF;
1635
1636 --po_header_id should be null
1637 IF(p_x_osp_order_rec.po_header_id IS NOT NULL AND p_x_osp_order_rec.po_header_id <> FND_API.G_MISS_NUM) THEN
1638 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_PO_NNLL');
1639 FND_MSG_PUB.ADD;
1640 END IF;
1641
1642 -- single_instance_flag cant change
1643 IF(p_x_osp_order_rec.single_instance_flag IS NOT NULL AND p_x_osp_order_rec.single_instance_flag <> l_osp_order_rec.single_instance_flag) THEN
1644 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_INST_FLG_CHG');
1645 FND_MSG_PUB.ADD;
1646 END IF;
1647
1648 -- vendor_id cant change
1649 IF(p_x_osp_order_rec.vendor_id IS NOT NULL AND p_x_osp_order_rec.vendor_id <> l_osp_order_rec.vendor_id) THEN
1650 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_VEN_CHG');
1651 FND_MSG_PUB.ADD;
1652 END IF;
1653 -- vendor_site_id cant change
1654 IF(p_x_osp_order_rec.vendor_site_id IS NOT NULL AND p_x_osp_order_rec.vendor_site_id <> l_osp_order_rec.vendor_site_id) THEN
1655 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_VEN_STE_CHG');
1656 FND_MSG_PUB.ADD;
1657 END IF;
1658
1659 -- vendor_contact_id cant change
1660 IF(p_x_osp_order_rec.vendor_contact_id IS NOT NULL AND p_x_osp_order_rec.vendor_contact_id <> l_osp_order_rec.vendor_contact_id) THEN
1661 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_VEN_CTCT_CHG ');
1662 FND_MSG_PUB.ADD;
1663 END IF;
1664
1665 -- Buyer cant change
1666 IF(p_x_osp_order_rec.po_agent_id IS NOT NULL AND p_x_osp_order_rec.po_agent_id <> l_osp_order_rec.po_agent_id) THEN
1667 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_BUYER_CHG');
1668 FND_MSG_PUB.ADD;
1669 END IF;
1670 -- set status_code for lines
1671 --g_order_status_for_update := G_OSP_PO_CREATED_STATUS;
1672 ELSE
1673 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_STATUS');
1674 FND_MSG_PUB.ADD;
1675 END IF;
1676 --mpothuku End
1677 END IF; --IF(p_x_osp_order_rec.operation_flag = G_OP_UPDATE) THEN
1678 END IF; --IF (p_x_osp_order_rec.order_type_code IN ( G_OSP_ORDER_TYPE_SERVICE, G_OSP_ORDER_TYPE_EXCHANGE)) THEN
1679 -- validate Loan order header
1680 ELSIF (p_x_osp_order_rec.order_type_code = G_OSP_ORDER_TYPE_LOAN) THEN
1681 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
1682 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY || '.loan', 'Update order type is Loan');
1683 END IF;
1684 -- single_instance_flag can not be other than null, GMISS or G_NO_FLAG.
1685 IF(p_x_osp_order_rec.single_instance_flag IS NULL OR p_x_osp_order_rec.single_instance_flag = FND_API.G_MISS_CHAR
1686 OR p_x_osp_order_rec.single_instance_flag = G_NO_FLAG )THEN
1687 p_x_osp_order_rec.single_instance_flag := G_NO_FLAG;
1688 ELSE
1689 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_INST_FLG');
1690 FND_MESSAGE.Set_Token('INST_FLG', p_x_osp_order_rec.single_instance_flag);
1691 FND_MSG_PUB.ADD;
1692 END IF;
1693 IF(p_x_osp_order_rec.operation_flag = G_OP_CREATE) THEN
1694 -- validate customer_id.
1695 IF(p_x_osp_order_rec.customer_id IS NULL OR p_x_osp_order_rec.customer_id = FND_API.G_MISS_NUM) THEN
1696 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_CUSTOMER_ID_NLL');
1697 FND_MSG_PUB.ADD;
1698 ELSE
1699 validate_customer(p_x_osp_order_rec.customer_id);
1700 END IF;
1701 -- validate contract_id
1702 /* Change made by mpothuku to make the contract_id optional on 12/16/04
1703 This is a work around and has to be revoked after PM comes up with the Service Contract Integration
1704 */
1705 -- Changes begin
1706 /*
1707 IF (p_x_osp_order_rec.contract_id IS NULL OR p_x_osp_order_rec.contract_id = FND_API.G_MISS_NUM) THEN
1708 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_CONTRACT_ID_NLL');
1709 FND_MSG_PUB.ADD;
1710 ELSE
1711 validate_contract(G_OSP_ORDER_TYPE_LOAN, p_x_osp_order_rec.contract_id , p_x_osp_order_rec.customer_id , l_operating_unit_id);
1712 */
1713 IF (p_x_osp_order_rec.contract_id IS NOT NULL AND p_x_osp_order_rec.contract_id <> FND_API.G_MISS_NUM) THEN
1714 validate_contract(G_OSP_ORDER_TYPE_LOAN, p_x_osp_order_rec.contract_id , p_x_osp_order_rec.customer_id , l_operating_unit_id);
1715 END IF;
1716 --Changes by mpothuku End
1717 ELSIF(p_x_osp_order_rec.operation_flag = G_OP_UPDATE) THEN
1718 IF(g_old_status_code = G_OSP_ENTERED_STATUS) THEN
1719 -- Changed by jaramana on January 9, 2008 for the Requisition ER 6034236
1720 -- status_code should be null,'ENTERED', or 'SUBMITTED' or 'REQ_SUBMITTED'
1721 IF(p_x_osp_order_rec.status_code IS NOT NULL AND
1722 p_x_osp_order_rec.status_code NOT IN(G_OSP_ENTERED_STATUS, G_OSP_SUBMITTED_STATUS, G_OSP_REQ_SUBMITTED_STATUS)) THEN
1723 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_STATUS');
1724 FND_MSG_PUB.ADD;
1725 END IF;
1726 -- jaramana End
1727 -- validate customer_id.
1728 IF(p_x_osp_order_rec.customer_id IS NOT NULL AND p_x_osp_order_rec.customer_id = FND_API.G_MISS_NUM) THEN
1729 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_CUSTOMER_ID_NLL');
1730 FND_MSG_PUB.ADD;
1731 ELSIF(p_x_osp_order_rec.customer_id IS NOT NULL) THEN
1732 validate_customer(p_x_osp_order_rec.customer_id);
1733 END IF;
1734 -- validate contract_id
1735 /* Change made by mpothuku to make the contract_id optional on 12/16/04
1736 This is a work around and has to be revoked after PM comes up with the Service Contract Integration
1737 */
1738 -- Changes begin
1739 /*
1740 IF(p_x_osp_order_rec.contract_id IS NOT NULL AND p_x_osp_order_rec.contract_id = FND_API.G_MISS_NUM) THEN
1741 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_CONTRACT_ID_NLL');
1742 FND_MSG_PUB.ADD;
1743 ELSIF ( p_x_osp_order_rec.contract_id IS NOT NULL) THEN
1744 validate_contract(G_OSP_ORDER_TYPE_LOAN, p_x_osp_order_rec.contract_id , p_x_osp_order_rec.customer_id , l_operating_unit_id);
1745 */
1746 IF ( p_x_osp_order_rec.contract_id IS NOT NULL AND p_x_osp_order_rec.contract_id <> FND_API.G_MISS_NUM) THEN
1747 validate_contract(G_OSP_ORDER_TYPE_LOAN, p_x_osp_order_rec.contract_id , p_x_osp_order_rec.customer_id , l_operating_unit_id);
1748 END IF;
1749 --Changes by mpothuku End
1750 -- set status
1751 --g_order_status_for_update := G_OSP_ENTERED_STATUS;
1752 ELSIF(g_old_status_code = G_OSP_SUBMITTED_STATUS) THEN
1753 -- status_code should be null,'ENTERED', or 'SUBMITTED'
1754 IF(p_x_osp_order_rec.status_code IS NOT NULL AND
1755 p_x_osp_order_rec.status_code NOT IN(G_OSP_SUBMITTED_STATUS, G_OSP_CLOSED_STATUS)) THEN
1756 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_STATUS');
1757 FND_MSG_PUB.ADD;
1758 END IF;
1759 -- CUSTOMER_ID cant change
1760 IF(p_x_osp_order_rec.customer_id IS NOT NULL AND p_x_osp_order_rec.customer_id <> l_osp_order_rec.customer_id) THEN
1761 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_CUST_CHG');
1762 FND_MSG_PUB.ADD;
1763 END IF;
1764 -- contract_id cant change
1765 IF(p_x_osp_order_rec.contract_id IS NOT NULL AND p_x_osp_order_rec.contract_id <> l_osp_order_rec.contract_id) THEN
1766 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_CTRCT_CHG');
1767 FND_MSG_PUB.ADD;
1768 END IF;
1769 --g_order_status_for_update := G_OSP_SUBMITTED_STATUS;
1770 ELSE
1771 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_STATUS');
1772 FND_MSG_PUB.ADD;
1773 END IF;
1774 END IF;
1775 -- validate BORROW order header
1776 ELSIF (p_x_osp_order_rec.order_type_code = G_OSP_ORDER_TYPE_BORROW) THEN
1777 -- single_instance_flag can not be other than null, GMISS or G_NO_FLAG.
1778 IF(p_x_osp_order_rec.single_instance_flag IS NULL OR p_x_osp_order_rec.single_instance_flag = FND_API.G_MISS_CHAR
1779 OR p_x_osp_order_rec.single_instance_flag = G_NO_FLAG )THEN
1780 p_x_osp_order_rec.single_instance_flag := G_NO_FLAG;
1781 ELSE
1782 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_INST_FLG');
1783 FND_MESSAGE.Set_Token('INST_FLG', p_x_osp_order_rec.single_instance_flag);
1784 FND_MSG_PUB.ADD;
1785 END IF;
1786 IF(p_x_osp_order_rec.operation_flag = G_OP_CREATE) THEN
1787 -- validate customer_id.
1788 IF(p_x_osp_order_rec.customer_id IS NOT NULL) THEN
1789 validate_customer(p_x_osp_order_rec.customer_id);
1790 END IF;
1791 /*
1792 -- validate vendor_id.
1793 IF(p_x_osp_order_rec.vendor_id IS NULL OR p_x_osp_order_rec.vendor_id = FND_API.G_MISS_NUM) THEN
1794 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENDOR_ID_NLL');
1795 FND_MSG_PUB.ADD;
1796 ELSE
1797 validate_vendor(p_x_osp_order_rec.vendor_id);
1798 END IF;
1799 */
1800 validate_vendor_site_contact(p_x_osp_order_rec.vendor_id,
1801 p_x_osp_order_rec.vendor_site_id,
1802 p_x_osp_order_rec.vendor_contact_id);
1803 -- validate contract_id
1804 /* Change made by mpothuku to make the contract_id optional on 12/16/04
1805 This is a work around and has to be revoked after PM comes up with the Service Contract Integration
1806 */
1807 -- Changes begin
1808 /*
1809 IF (p_x_osp_order_rec.contract_id IS NULL OR p_x_osp_order_rec.contract_id = FND_API.G_MISS_NUM) THEN
1810 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_CONTRACT_ID_NLL');
1811 FND_MSG_PUB.ADD;
1812 ELSE
1813 validate_contract(G_OSP_ORDER_TYPE_BORROW, p_x_osp_order_rec.contract_id , p_x_osp_order_rec.vendor_id , l_operating_unit_id);
1814 END IF;
1815 */
1816 IF (p_x_osp_order_rec.contract_id IS NOT NULL AND p_x_osp_order_rec.contract_id <> FND_API.G_MISS_NUM) THEN
1817 validate_contract(G_OSP_ORDER_TYPE_BORROW, p_x_osp_order_rec.contract_id , p_x_osp_order_rec.vendor_id , l_operating_unit_id);
1818 END IF;
1819 --Changes by mpothuku End
1820 ELSIF(p_x_osp_order_rec.operation_flag = G_OP_UPDATE) THEN
1821 IF(g_old_status_code = G_OSP_ENTERED_STATUS) THEN
1822 -- status_code should be null,'ENTERED', or 'SUBMITTED'
1823 IF(p_x_osp_order_rec.status_code IS NOT NULL AND
1824 p_x_osp_order_rec.status_code NOT IN(G_OSP_ENTERED_STATUS, G_OSP_SUBMITTED_STATUS)) THEN
1825 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_STATUS');
1826 FND_MSG_PUB.ADD;
1827 END IF;
1828 -- validate customer_id.
1829 IF(p_x_osp_order_rec.customer_id IS NOT NULL AND p_x_osp_order_rec.customer_id <> FND_API.G_MISS_NUM) THEN
1830 validate_customer(p_x_osp_order_rec.customer_id);
1831 END IF;
1832 /* Change made by mpothuku to make the contract_id optional on 12/16/04
1833 This is a work around and has to be revoked after PM comes up with the Service Contract Integration
1834 */
1835 -- Changes begin
1836 /*
1837 IF (p_x_osp_order_rec.contract_id IS NOT NULL AND p_x_osp_order_rec.contract_id = FND_API.G_MISS_NUM) THEN
1838 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_CONTRACT_ID_NLL');
1839 FND_MSG_PUB.ADD;
1840 ELSIF(p_x_osp_order_rec.contract_id IS NOT NULL AND (p_x_osp_order_rec.vendor_id IS NULL OR p_x_osp_order_rec.vendor_id = FND_API.G_MISS_NUM)) THEN
1841 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENDOR_ID_NLL');
1842 FND_MSG_PUB.ADD;
1843 ELSIF(p_x_osp_order_rec.vendor_id IS NOT NULL OR p_x_osp_order_rec.contract_id IS NOT NULL) THEN
1844 -- validate vendor_id.
1845 validate_vendor(p_x_osp_order_rec.vendor_id);
1846 p_x_osp_order_rec.contract_id := NVL(p_x_osp_order_rec.contract_id, l_osp_order_rec.contract_id);
1847 -- validate contract_id
1848 validate_contract(G_OSP_ORDER_TYPE_BORROW, p_x_osp_order_rec.contract_id , p_x_osp_order_rec.vendor_id , l_operating_unit_id);
1849 END IF;
1850 */
1851 /*
1852 -- validate vendor_id.
1853 IF(p_x_osp_order_rec.vendor_id IS NULL OR p_x_osp_order_rec.vendor_id = FND_API.G_MISS_NUM) THEN
1854 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENDOR_ID_NLL');
1855 FND_MSG_PUB.ADD;
1856 ELSE
1857 validate_vendor(p_x_osp_order_rec.vendor_id);
1858 END IF;
1859 */
1860 validate_vendor_site_contact(p_x_osp_order_rec.vendor_id,
1861 p_x_osp_order_rec.vendor_site_id,
1862 p_x_osp_order_rec.vendor_contact_id);
1863
1864 p_x_osp_order_rec.contract_id := NVL(p_x_osp_order_rec.contract_id, l_osp_order_rec.contract_id);
1865 --validate contract_id only if it is not null.
1866 IF (p_x_osp_order_rec.contract_id IS NOT NULL AND p_x_osp_order_rec.contract_id <> FND_API.G_MISS_NUM) THEN
1867 validate_contract(G_OSP_ORDER_TYPE_BORROW, p_x_osp_order_rec.contract_id , p_x_osp_order_rec.vendor_id , l_operating_unit_id);
1868 END IF;
1869 --Changes by mpothuku End
1870 -- set status
1871 --g_order_status_for_update := G_OSP_ENTERED_STATUS;
1872 ELSIF(g_old_status_code = G_OSP_SUBMITTED_STATUS) THEN
1873 -- status_code should be null,'ENTERED', or 'SUBMITTED'
1874 IF(p_x_osp_order_rec.status_code IS NOT NULL AND
1875 p_x_osp_order_rec.status_code NOT IN(G_OSP_SUBMITTED_STATUS, G_OSP_CLOSED_STATUS)) THEN
1876 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_STATUS');
1877 FND_MSG_PUB.ADD;
1878 END IF;
1879 -- CUSTOMER_ID cant change
1880 IF(p_x_osp_order_rec.customer_id IS NOT NULL AND p_x_osp_order_rec.customer_id <> l_osp_order_rec.customer_id) THEN
1881 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_CUST_CHG');
1882 FND_MSG_PUB.ADD;
1883 END IF;
1884 -- vendor_id cant change
1885 IF(p_x_osp_order_rec.vendor_id IS NOT NULL AND p_x_osp_order_rec.vendor_id <> l_osp_order_rec.vendor_id) THEN
1886 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_VEND_CHG');
1887 FND_MSG_PUB.ADD;
1888 END IF;
1889 -- contract_id cant change
1890 IF(p_x_osp_order_rec.contract_id IS NOT NULL AND p_x_osp_order_rec.contract_id <> l_osp_order_rec.contract_id) THEN
1891 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_CTRCT_CHG');
1892 FND_MSG_PUB.ADD;
1893 END IF;
1894 -- set status
1895 --g_order_status_for_update := G_OSP_SUBMITTED_STATUS;
1896 ELSE
1897 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_STATUS');
1898 FND_MSG_PUB.ADD;
1899 END IF;
1900 END IF;
1901 ELSE
1902 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INV_TYPE');
1903 FND_MSG_PUB.ADD;
1904 END IF;
1905 -- delete header
1906 IF(p_x_osp_order_rec.operation_flag = G_OP_DELETE) THEN
1907 -- Changed by jaramana on January 9, 2008 for the Requisition ER 6034236 (Added G_OSP_REQ_SUB_FAILED_STATUS)
1908 IF(g_old_status_code NOT IN( G_OSP_ENTERED_STATUS, G_OSP_SUB_FAILED_STATUS, G_OSP_REQ_SUB_FAILED_STATUS ))THEN
1909 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INVOP');
1910 FND_MSG_PUB.ADD;
1911 ELSE
1912 --g_order_status_for_update := G_OSP_DELETED_STATUS;
1913 IF(l_osp_order_rec.oe_header_id IS NOT NULL) THEN
1914 -- calling to delete SO HEADER
1915 delete_cancel_so(
1916 p_oe_header_id => l_osp_order_rec.oe_header_id,
1917 p_del_cancel_so_lines_tbl =>l_del_cancel_so_lines_tbl
1918 );
1919 END IF;
1920 END IF;
1921 -- jaramana End
1922 END IF;
1923 IF FND_MSG_PUB.count_msg > 0 THEN
1924 RAISE FND_API.G_EXC_ERROR;
1925 -- RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1926 END IF;
1927 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
1928 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
1929 END IF;
1930 --dbms_output.put_line('Exiting : validate_order_header');
1931 END validate_order_header;
1932
1933 --------------------------------------------------------------------------------------------------------------
1934 -- defaults values and populates unchanged fields in header record.
1935 --------------------------------------------------------------------------------------------------------------
1936 --Added the handling for vendor_contact_id, (?)Jerry 04/17/2005
1937 --This procedure should be called after value to id conversion
1938 PROCEDURE default_unchanged_order_header(
1939 p_x_osp_order_rec IN OUT NOCOPY osp_order_rec_type
1940 ) IS
1941
1942 -- Changed by jaramana on January 9, 2008 for the Requisition ER 6034236 (Added the PO_REQ_HEADER_ID in the cursor below)
1943 CURSOR osp_order_csr(p_osp_order_id IN NUMBER, p_object_version_number IN NUMBER) IS
1944 SELECT osp_order_number, order_type_code, single_instance_flag, po_header_id, oe_header_id,vendor_id, vendor_site_id,
1945 customer_id,order_date,contract_id,contract_terms,operating_unit_id, po_synch_flag, status_code,
1946 po_batch_id, po_request_id,po_agent_id, po_interface_header_id, po_req_header_id, description,attribute_category,
1947 attribute1,attribute2, attribute3, attribute4, attribute5, attribute6, attribute7, attribute8, attribute9,
1948 attribute10, attribute11, attribute12, attribute13, attribute14, attribute15, vendor_contact_id
1949 -- jaramana End
1950 FROM ahl_osp_orders_vl
1951 WHERE osp_order_id = p_osp_order_id
1952 AND object_version_number= p_object_version_number;
1953 l_osp_order_rec osp_order_rec_type;
1954 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.default_unchanged_order_header';
1955 BEGIN
1956 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
1957 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
1958 END IF;
1959 IF(p_x_osp_order_rec.operation_flag = G_OP_UPDATE) THEN
1960 OPEN osp_order_csr(p_x_osp_order_rec.osp_order_id, p_x_osp_order_rec.object_version_number);
1961 -- Added by jaramana on January 9, 2008 for the Requisition ER 6034236 (Added the PO_REQ_HEADER_ID in the rec below)
1962 FETCH osp_order_csr INTO l_osp_order_rec.osp_order_number, l_osp_order_rec.order_type_code,l_osp_order_rec.single_instance_flag,
1963 l_osp_order_rec.po_header_id, l_osp_order_rec.oe_header_id,l_osp_order_rec.vendor_id,
1964 l_osp_order_rec.vendor_site_id, l_osp_order_rec.customer_id, l_osp_order_rec.order_date,
1965 l_osp_order_rec.contract_id, l_osp_order_rec.contract_terms, l_osp_order_rec.operating_unit_id,
1966 l_osp_order_rec.po_synch_flag, l_osp_order_rec.status_code, l_osp_order_rec.po_batch_id, l_osp_order_rec.po_request_id,
1967 l_osp_order_rec.po_agent_id, l_osp_order_rec.po_interface_header_id, l_osp_order_rec.po_req_header_id, l_osp_order_rec.description,
1968 l_osp_order_rec.attribute_category,l_osp_order_rec.attribute1,l_osp_order_rec.attribute2,
1969 l_osp_order_rec.attribute3, l_osp_order_rec.attribute4, l_osp_order_rec.attribute5,
1970 l_osp_order_rec.attribute6, l_osp_order_rec.attribute7, l_osp_order_rec.attribute8,
1971 l_osp_order_rec.attribute9, l_osp_order_rec.attribute10, l_osp_order_rec.attribute11,
1972 l_osp_order_rec.attribute12, l_osp_order_rec.attribute13, l_osp_order_rec.attribute14,
1973 l_osp_order_rec.attribute15, l_osp_order_rec.vendor_contact_id;
1974 -- jaramana End
1975 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
1976 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'osp_order_id='||p_x_osp_order_rec.osp_order_id|| 'ovn='||p_x_osp_order_rec.object_version_number);
1977 END IF;
1978 IF (osp_order_csr%NOTFOUND) THEN
1979 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INVOP_OSP_NFOUND');
1980 FND_MSG_PUB.ADD;
1981 ELSE
1982 --dbms_output.put_line('l_osp_order_rec.osp_order_number ' || l_osp_order_rec.osp_order_number);
1983 IF (p_x_osp_order_rec.osp_order_number IS NULL) THEN
1984 p_x_osp_order_rec.osp_order_number := l_osp_order_rec.osp_order_number;
1985 ELSIF(p_x_osp_order_rec.osp_order_number = FND_API.G_MISS_NUM) THEN
1986 p_x_osp_order_rec.osp_order_number := null;
1987 END IF;
1988 IF (p_x_osp_order_rec.order_type_code IS NULL) THEN
1989 p_x_osp_order_rec.order_type_code := l_osp_order_rec.order_type_code;
1990 ELSIF(p_x_osp_order_rec.order_type_code = FND_API.G_MISS_CHAR) THEN
1991 p_x_osp_order_rec.order_type_code := null;
1992 END IF;
1993 IF (p_x_osp_order_rec.single_instance_flag IS NULL) THEN
1994 p_x_osp_order_rec.single_instance_flag := l_osp_order_rec.single_instance_flag;
1995 ELSIF(p_x_osp_order_rec.single_instance_flag = FND_API.G_MISS_CHAR) THEN
1996 p_x_osp_order_rec.single_instance_flag := null;
1997 END IF;
1998 IF (p_x_osp_order_rec.po_header_id IS NULL) THEN
1999 p_x_osp_order_rec.po_header_id := l_osp_order_rec.po_header_id;
2000 ELSIF(p_x_osp_order_rec.po_header_id = FND_API.G_MISS_NUM) THEN
2001 p_x_osp_order_rec.po_header_id := null;
2002 END IF;
2003 IF (p_x_osp_order_rec.oe_header_id IS NULL) THEN
2004 p_x_osp_order_rec.oe_header_id := l_osp_order_rec.oe_header_id;
2005 ELSIF(p_x_osp_order_rec.oe_header_id = FND_API.G_MISS_NUM) THEN
2006 p_x_osp_order_rec.oe_header_id := null;
2007 END IF;
2008 IF (p_x_osp_order_rec.vendor_id IS NULL) THEN
2009 p_x_osp_order_rec.vendor_id := l_osp_order_rec.vendor_id;
2010 ELSIF(p_x_osp_order_rec.vendor_id = FND_API.G_MISS_NUM) THEN
2011 p_x_osp_order_rec.vendor_id := null;
2012 END IF;
2013 IF (p_x_osp_order_rec.vendor_site_id IS NULL) THEN
2014 p_x_osp_order_rec.vendor_site_id := l_osp_order_rec.vendor_site_id;
2015 ELSIF(p_x_osp_order_rec.vendor_site_id = FND_API.G_MISS_NUM) THEN
2016 p_x_osp_order_rec.vendor_site_id := null;
2017 END IF;
2018 IF (p_x_osp_order_rec.customer_id IS NULL) THEN
2019 p_x_osp_order_rec.customer_id := l_osp_order_rec.customer_id;
2020 ELSIF(p_x_osp_order_rec.customer_id = FND_API.G_MISS_NUM) THEN
2021 p_x_osp_order_rec.customer_id := null;
2022 END IF;
2023 IF (p_x_osp_order_rec.order_date IS NULL) THEN
2024 p_x_osp_order_rec.order_date := l_osp_order_rec.order_date;
2025 ELSIF(p_x_osp_order_rec.order_date = FND_API.G_MISS_DATE) THEN
2026 p_x_osp_order_rec.order_date := null;
2027 END IF;
2028 IF (p_x_osp_order_rec.contract_id IS NULL) THEN
2029 p_x_osp_order_rec.contract_id := l_osp_order_rec.contract_id;
2030 ELSIF(p_x_osp_order_rec.contract_id = FND_API.G_MISS_NUM) THEN
2031 p_x_osp_order_rec.contract_id := null;
2032 END IF;
2033 IF (p_x_osp_order_rec.contract_terms IS NULL) THEN
2034 p_x_osp_order_rec.contract_terms := l_osp_order_rec.contract_terms;
2035 ELSIF(p_x_osp_order_rec.contract_terms = FND_API.G_MISS_CHAR) THEN
2036 p_x_osp_order_rec.contract_terms := null;
2037 END IF;
2038 IF (p_x_osp_order_rec.operating_unit_id IS NULL) THEN
2039 p_x_osp_order_rec.operating_unit_id := l_osp_order_rec.operating_unit_id;
2040 ELSIF(p_x_osp_order_rec.operating_unit_id = FND_API.G_MISS_NUM) THEN
2041 p_x_osp_order_rec.operating_unit_id := null;
2042 END IF;
2043 IF (p_x_osp_order_rec.po_synch_flag IS NULL) THEN
2044 p_x_osp_order_rec.po_synch_flag := l_osp_order_rec.po_synch_flag;
2045 ELSIF(p_x_osp_order_rec.po_synch_flag = FND_API.G_MISS_CHAR) THEN
2046 p_x_osp_order_rec.po_synch_flag := null;
2047 END IF;
2048 IF (p_x_osp_order_rec.status_code IS NULL) THEN
2049 p_x_osp_order_rec.status_code := l_osp_order_rec.status_code;
2050 ELSIF(p_x_osp_order_rec.status_code = FND_API.G_MISS_CHAR) THEN
2051 p_x_osp_order_rec.status_code := null;
2052 END IF;
2053 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2054 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin',
2055 'batch_id='||p_x_osp_order_rec.po_batch_id||
2056 'request_id='||p_x_osp_order_rec.po_request_id||
2057 'interface_id='||p_x_osp_order_rec.po_interface_header_id);
2058 END IF;
2059 IF (p_x_osp_order_rec.po_batch_id IS NULL) THEN
2060 p_x_osp_order_rec.po_batch_id := l_osp_order_rec.po_batch_id;
2061 ELSIF(p_x_osp_order_rec.po_batch_id = FND_API.G_MISS_NUM) THEN
2062 p_x_osp_order_rec.po_batch_id := null;
2063 END IF;
2064 IF (p_x_osp_order_rec.po_request_id IS NULL) THEN
2065 p_x_osp_order_rec.po_request_id := l_osp_order_rec.po_request_id;
2066 ELSIF(p_x_osp_order_rec.po_request_id = FND_API.G_MISS_NUM) THEN
2067 p_x_osp_order_rec.po_request_id := null;
2068 END IF;
2069 IF (p_x_osp_order_rec.po_agent_id IS NULL) THEN
2070 p_x_osp_order_rec.po_agent_id := l_osp_order_rec.po_agent_id;
2071 ELSIF(p_x_osp_order_rec.po_agent_id = FND_API.G_MISS_NUM) THEN
2072 p_x_osp_order_rec.po_agent_id := null;
2073 END IF;
2074 IF (p_x_osp_order_rec.po_interface_header_id IS NULL) THEN
2075 p_x_osp_order_rec.po_interface_header_id := l_osp_order_rec.po_interface_header_id;
2076 ELSIF(p_x_osp_order_rec.po_interface_header_id = FND_API.G_MISS_NUM) THEN
2077 p_x_osp_order_rec.po_interface_header_id := null;
2078 END IF;
2079 -- Added by jaramana on January 9, 2008 for the Requisition ER 6034236
2080 IF (p_x_osp_order_rec.po_req_header_id IS NULL) THEN
2081 p_x_osp_order_rec.po_req_header_id := l_osp_order_rec.po_req_header_id;
2082 ELSIF(p_x_osp_order_rec.po_req_header_id = FND_API.G_MISS_NUM) THEN
2083 p_x_osp_order_rec.po_req_header_id := null;
2084 END IF;
2085 -- jaramana End
2086 IF (p_x_osp_order_rec.description IS NULL) THEN
2087 p_x_osp_order_rec.description := l_osp_order_rec.description;
2088 ELSIF(p_x_osp_order_rec.description = FND_API.G_MISS_CHAR) THEN
2089 p_x_osp_order_rec.description := null;
2090 END IF;
2091 IF (p_x_osp_order_rec.attribute_category IS NULL) THEN
2092 p_x_osp_order_rec.attribute_category := l_osp_order_rec.attribute_category;
2093 ELSIF(p_x_osp_order_rec.attribute_category = FND_API.G_MISS_CHAR) THEN
2094 p_x_osp_order_rec.attribute_category := null;
2095 END IF;
2096 IF (p_x_osp_order_rec.attribute1 IS NULL) THEN
2097 p_x_osp_order_rec.attribute1 := l_osp_order_rec.attribute1;
2098 ELSIF(p_x_osp_order_rec.attribute1 = FND_API.G_MISS_CHAR) THEN
2099 p_x_osp_order_rec.attribute1 := null;
2100 END IF;
2101 IF (p_x_osp_order_rec.attribute2 IS NULL) THEN
2102 p_x_osp_order_rec.attribute2 := l_osp_order_rec.attribute2;
2103 ELSIF(p_x_osp_order_rec.attribute2 = FND_API.G_MISS_CHAR) THEN
2104 p_x_osp_order_rec.attribute2 := null;
2105 END IF;
2106 IF (p_x_osp_order_rec.attribute3 IS NULL) THEN
2107 p_x_osp_order_rec.attribute3 := l_osp_order_rec.attribute3;
2108 ELSIF(p_x_osp_order_rec.attribute3 = FND_API.G_MISS_CHAR) THEN
2109 p_x_osp_order_rec.attribute3 := null;
2110 END IF;
2111 IF (p_x_osp_order_rec.attribute4 IS NULL) THEN
2112 p_x_osp_order_rec.attribute4 := l_osp_order_rec.attribute4;
2113 ELSIF(p_x_osp_order_rec.attribute4 = FND_API.G_MISS_CHAR) THEN
2114 p_x_osp_order_rec.attribute4 := null;
2115 END IF;
2116 IF (p_x_osp_order_rec.attribute5 IS NULL) THEN
2117 p_x_osp_order_rec.attribute5 := l_osp_order_rec.attribute5;
2118 ELSIF(p_x_osp_order_rec.attribute5 = FND_API.G_MISS_CHAR) THEN
2119 p_x_osp_order_rec.attribute5 := null;
2120 END IF;
2121 IF (p_x_osp_order_rec.attribute6 IS NULL) THEN
2122 p_x_osp_order_rec.attribute6 := l_osp_order_rec.attribute6;
2123 ELSIF(p_x_osp_order_rec.attribute6 = FND_API.G_MISS_CHAR) THEN
2124 p_x_osp_order_rec.attribute6 := null;
2125 END IF;
2126 IF (p_x_osp_order_rec.attribute7 IS NULL) THEN
2127 p_x_osp_order_rec.attribute7 := l_osp_order_rec.attribute7;
2128 ELSIF(p_x_osp_order_rec.attribute7 = FND_API.G_MISS_CHAR) THEN
2129 p_x_osp_order_rec.attribute7 := null;
2130 END IF;
2131 IF (p_x_osp_order_rec.attribute8 IS NULL) THEN
2132 p_x_osp_order_rec.attribute8 := l_osp_order_rec.attribute8;
2133 ELSIF(p_x_osp_order_rec.attribute8 = FND_API.G_MISS_CHAR) THEN
2134 p_x_osp_order_rec.attribute8 := null;
2135 END IF;
2136 IF (p_x_osp_order_rec.attribute9 IS NULL) THEN
2137 p_x_osp_order_rec.attribute9 := l_osp_order_rec.attribute9;
2138 ELSIF(p_x_osp_order_rec.attribute9 = FND_API.G_MISS_CHAR) THEN
2139 p_x_osp_order_rec.attribute9 := null;
2140 END IF;
2141 IF (p_x_osp_order_rec.attribute10 IS NULL) THEN
2142 p_x_osp_order_rec.attribute10 := l_osp_order_rec.attribute10;
2143 ELSIF(p_x_osp_order_rec.attribute10 = FND_API.G_MISS_CHAR) THEN
2144 p_x_osp_order_rec.attribute10 := null;
2145 END IF;
2146 IF (p_x_osp_order_rec.attribute11 IS NULL) THEN
2147 p_x_osp_order_rec.attribute11 := l_osp_order_rec.attribute11;
2148 ELSIF(p_x_osp_order_rec.attribute11 = FND_API.G_MISS_CHAR) THEN
2149 p_x_osp_order_rec.attribute11 := null;
2150 END IF;
2151 IF (p_x_osp_order_rec.attribute12 IS NULL) THEN
2152 p_x_osp_order_rec.attribute12 := l_osp_order_rec.attribute12;
2153 ELSIF(p_x_osp_order_rec.attribute12 = FND_API.G_MISS_CHAR) THEN
2154 p_x_osp_order_rec.attribute12 := null;
2155 END IF;
2156 IF (p_x_osp_order_rec.attribute13 IS NULL) THEN
2157 p_x_osp_order_rec.attribute13 := l_osp_order_rec.attribute13;
2158 ELSIF(p_x_osp_order_rec.attribute13 = FND_API.G_MISS_CHAR) THEN
2159 p_x_osp_order_rec.attribute13 := null;
2160 END IF;
2161 IF (p_x_osp_order_rec.attribute14 IS NULL) THEN
2162 p_x_osp_order_rec.attribute14 := l_osp_order_rec.attribute14;
2163 ELSIF(p_x_osp_order_rec.attribute14 = FND_API.G_MISS_CHAR) THEN
2164 p_x_osp_order_rec.attribute14 := null;
2165 END IF;
2166 IF (p_x_osp_order_rec.attribute15 IS NULL) THEN
2167 p_x_osp_order_rec.attribute15 := l_osp_order_rec.attribute15;
2168 ELSIF(p_x_osp_order_rec.attribute15 = FND_API.G_MISS_CHAR) THEN
2169 p_x_osp_order_rec.attribute15 := null;
2170 END IF;
2171 IF (p_x_osp_order_rec.vendor_contact_id IS NULL) THEN
2172 p_x_osp_order_rec.vendor_contact_id := l_osp_order_rec.vendor_contact_id;
2173 ELSIF(p_x_osp_order_rec.vendor_contact_id = FND_API.G_MISS_NUM) THEN
2174 p_x_osp_order_rec.vendor_contact_id := null;
2175 END IF;
2176 END IF;
2177 CLOSE osp_order_csr;
2178 ELSIF (p_x_osp_order_rec.operation_flag = G_OP_CREATE) THEN
2179 IF(p_x_osp_order_rec.osp_order_number = FND_API.G_MISS_NUM) THEN
2180 p_x_osp_order_rec.osp_order_number := null;
2181 END IF;
2182 IF(p_x_osp_order_rec.order_type_code = FND_API.G_MISS_CHAR) THEN
2183 p_x_osp_order_rec.order_type_code := null;
2184 END IF;
2185 IF(p_x_osp_order_rec.single_instance_flag = FND_API.G_MISS_CHAR) THEN
2186 p_x_osp_order_rec.single_instance_flag := null;
2187 END IF;
2188 IF(p_x_osp_order_rec.po_header_id = FND_API.G_MISS_NUM) THEN
2189 p_x_osp_order_rec.po_header_id := null;
2190 END IF;
2191 IF(p_x_osp_order_rec.oe_header_id = FND_API.G_MISS_NUM) THEN
2192 p_x_osp_order_rec.oe_header_id := null;
2193 END IF;
2194 IF(p_x_osp_order_rec.vendor_id = FND_API.G_MISS_NUM) THEN
2195 p_x_osp_order_rec.vendor_id := null;
2196 END IF;
2197 IF(p_x_osp_order_rec.vendor_site_id = FND_API.G_MISS_NUM) THEN
2198 p_x_osp_order_rec.vendor_site_id := null;
2199 END IF;
2200 IF(p_x_osp_order_rec.customer_id = FND_API.G_MISS_NUM) THEN
2201 p_x_osp_order_rec.customer_id := null;
2202 END IF;
2203 IF(p_x_osp_order_rec.order_date = FND_API.G_MISS_DATE) THEN
2204 p_x_osp_order_rec.order_date := null;
2205 END IF;
2206 IF(p_x_osp_order_rec.contract_id = FND_API.G_MISS_NUM) THEN
2207 p_x_osp_order_rec.contract_id := null;
2208 END IF;
2209 IF(p_x_osp_order_rec.contract_terms = FND_API.G_MISS_CHAR) THEN
2210 p_x_osp_order_rec.contract_terms := null;
2211 END IF;
2212 IF(p_x_osp_order_rec.operating_unit_id = FND_API.G_MISS_NUM) THEN
2213 p_x_osp_order_rec.operating_unit_id := null;
2214 END IF;
2215 IF(p_x_osp_order_rec.po_synch_flag = FND_API.G_MISS_CHAR) THEN
2216 p_x_osp_order_rec.po_synch_flag := null;
2217 END IF;
2218 IF(p_x_osp_order_rec.status_code = FND_API.G_MISS_CHAR) THEN
2219 p_x_osp_order_rec.status_code := null;
2220 END IF;
2221 IF(p_x_osp_order_rec.po_batch_id = FND_API.G_MISS_NUM) THEN
2222 p_x_osp_order_rec.po_batch_id := null;
2223 END IF;
2224 IF(p_x_osp_order_rec.po_request_id = FND_API.G_MISS_NUM) THEN
2225 p_x_osp_order_rec.po_request_id := null;
2226 END IF;
2227 IF(p_x_osp_order_rec.po_agent_id = FND_API.G_MISS_NUM) THEN
2228 p_x_osp_order_rec.po_agent_id := null;
2229 END IF;
2230 IF(p_x_osp_order_rec.po_interface_header_id = FND_API.G_MISS_NUM) THEN
2231 p_x_osp_order_rec.po_interface_header_id := null;
2232 END IF;
2233 -- Added by jaramana on January 9, 2008 for the Requisition ER 6034236
2234 IF(p_x_osp_order_rec.po_req_header_id = FND_API.G_MISS_NUM) THEN
2235 p_x_osp_order_rec.po_req_header_id := null;
2236 END IF;
2237 -- jaramana End
2238 IF(p_x_osp_order_rec.description = FND_API.G_MISS_CHAR) THEN
2239 p_x_osp_order_rec.description := null;
2240 END IF;
2241 IF(p_x_osp_order_rec.attribute_category = FND_API.G_MISS_CHAR) THEN
2242 p_x_osp_order_rec.attribute_category := null;
2243 END IF;
2244 IF(p_x_osp_order_rec.attribute1 = FND_API.G_MISS_CHAR) THEN
2245 p_x_osp_order_rec.attribute1 := null;
2246 END IF;
2247 IF(p_x_osp_order_rec.attribute2 = FND_API.G_MISS_CHAR) THEN
2248 p_x_osp_order_rec.attribute2 := null;
2249 END IF;
2250 IF(p_x_osp_order_rec.attribute3 = FND_API.G_MISS_CHAR) THEN
2251 p_x_osp_order_rec.attribute3 := null;
2252 END IF;
2253 IF(p_x_osp_order_rec.attribute4 = FND_API.G_MISS_CHAR) THEN
2254 p_x_osp_order_rec.attribute4 := null;
2255 END IF;
2256 IF(p_x_osp_order_rec.attribute5 = FND_API.G_MISS_CHAR) THEN
2257 p_x_osp_order_rec.attribute5 := null;
2258 END IF;
2259 IF(p_x_osp_order_rec.attribute6 = FND_API.G_MISS_CHAR) THEN
2260 p_x_osp_order_rec.attribute6 := null;
2261 END IF;
2262 IF(p_x_osp_order_rec.attribute7 = FND_API.G_MISS_CHAR) THEN
2263 p_x_osp_order_rec.attribute7 := null;
2264 END IF;
2265 IF(p_x_osp_order_rec.attribute8 = FND_API.G_MISS_CHAR) THEN
2266 p_x_osp_order_rec.attribute8 := null;
2267 END IF;
2268 IF(p_x_osp_order_rec.attribute9 = FND_API.G_MISS_CHAR) THEN
2269 p_x_osp_order_rec.attribute9 := null;
2270 END IF;
2271 IF(p_x_osp_order_rec.attribute10 = FND_API.G_MISS_CHAR) THEN
2272 p_x_osp_order_rec.attribute10 := null;
2273 END IF;
2274 IF(p_x_osp_order_rec.attribute11 = FND_API.G_MISS_CHAR) THEN
2275 p_x_osp_order_rec.attribute11 := null;
2276 END IF;
2277 IF(p_x_osp_order_rec.attribute12 = FND_API.G_MISS_CHAR) THEN
2278 p_x_osp_order_rec.attribute12 := null;
2279 END IF;
2280 IF(p_x_osp_order_rec.attribute13 = FND_API.G_MISS_CHAR) THEN
2281 p_x_osp_order_rec.attribute13 := null;
2282 END IF;
2283 IF(p_x_osp_order_rec.attribute14 = FND_API.G_MISS_CHAR) THEN
2284 p_x_osp_order_rec.attribute14 := null;
2285 END IF;
2286 IF(p_x_osp_order_rec.attribute15 = FND_API.G_MISS_CHAR) THEN
2287 p_x_osp_order_rec.attribute15 := null;
2288 END IF;
2289 IF(p_x_osp_order_rec.vendor_contact_id = FND_API.G_MISS_NUM) THEN
2290 p_x_osp_order_rec.vendor_contact_id := null;
2291 END IF;
2292 END IF;
2293 IF FND_MSG_PUB.count_msg > 0 THEN
2294 RAISE FND_API.G_EXC_ERROR;
2295 -- RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2296 END IF;
2297 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2298 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
2299 END IF;
2300 --dbms_output.put_line('Exiting : default_unchanged_order_header');
2301 END default_unchanged_order_header;
2302
2303 -------------------------------------------------------------------------
2304 PROCEDURE validate_workorder(
2305 p_workorder_id IN NUMBER
2306 )IS
2307 CURSOR val_workorder_id_csr(p_workorder_id IN NUMBER) IS
2308 --Modified by mpothuku on 27-Feb-06 to fix the Perf Bug #4919164
2309 /*
2310 SELECT 'x' FROM ahl_workorders_osp_v
2311 WHERE workorder_id = p_workorder_id
2312 AND upper(department_class_code) = 'VENDOR'
2313 AND job_status_code = G_OSP_WO_RELEASED;
2314 */
2315 SELECT 'x'
2316 FROM ahl_workorders wo,
2317 wip_discrete_jobs wdj,
2318 bom_departments bmd,
2319 ahl_visits_b vst,
2320 ahl_visit_tasks_b vts,
2321 inv_organization_info_v org
2322 WHERE wo.workorder_id = p_workorder_id
2323 AND wo.master_workorder_flag = 'N'
2324 AND wo.visit_task_id = vts.visit_task_id
2325 AND vst.visit_id = vts.visit_id
2326 AND wdj.organization_id = vst.organization_id
2327 AND wdj.wip_entity_id = wo.wip_entity_id
2328 AND wdj.owning_department = bmd.department_id
2329 AND upper(bmd.department_class_code) = 'VENDOR'
2330 AND org.organization_id = vst.organization_id
2331 AND NVL (org.operating_unit, mo_global.get_current_org_id ()) = mo_global.get_current_org_id()
2332 AND wo.status_code = G_OSP_WO_RELEASED;
2333
2334 l_exist VARCHAR2(1);
2335 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.validate_workorder';
2336 BEGIN
2337 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2338 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
2339 END IF;
2340 IF(p_workorder_id IS NOT NULL) THEN
2341 OPEN val_workorder_id_csr(p_workorder_id);
2342 FETCH val_workorder_id_csr INTO l_exist;
2343 IF(val_workorder_id_csr%NOTFOUND) THEN
2344 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_WO');
2345 FND_MESSAGE.Set_Token('WORKORDER_ID', p_workorder_id);
2346 FND_MSG_PUB.ADD;
2347 END IF;
2348 CLOSE val_workorder_id_csr;
2349 END IF;
2350 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2351 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
2352 END IF;
2353 END validate_workorder;
2354
2355 /*
2356 --Commented by mpothuku on 27-Feb-06 as the following procs. are not being used anymore and the Perf Bug #4919164 --has been logged for some of the cursors in the procedures below
2357
2358 --------------------------------------------------------------------------------------------------------------
2359 PROCEDURE validate_service_item(
2360 p_workorder_id IN NUMBER,
2361 p_service_item_id IN NUMBER,
2362 p_order_type_code IN VARCHAR2
2363 )IS
2364 CURSOR val_service_item_id_inv_csr(p_service_item_id IN VARCHAR2, p_workorder_id IN NUMBER) IS
2365 SELECT 'x' FROM mtl_system_items_kfv MTL, ahl_workorders_osp_v WO
2366 WHERE MTL.inventory_item_id = p_service_item_id
2367 AND MTL.enabled_flag = G_YES_FLAG
2368 AND MTL.inventory_item_flag = G_NO_FLAG
2369 AND MTL.stock_enabled_flag = G_NO_FLAG
2370 AND NVL(MTL.start_date_active, SYSDATE - 1) <= SYSDATE
2371 AND NVL(MTL.end_date_active, SYSDATE + 1) > SYSDATE
2372 AND MTL.purchasing_enabled_flag = G_YES_FLAG
2373 AND NVL(outside_operation_flag, G_NO_FLAG) = G_NO_FLAG
2374 AND MTL.organization_id = WO.organization_id
2375 AND WO.workorder_id = p_workorder_id;
2376 CURSOR val_service_item_id_wo_csr(p_workorder_id IN NUMBER, p_service_item_id IN NUMBER) IS
2377 SELECT 'x' from ahl_workorders_osp_v
2378 WHERE workorder_id = p_workorder_id
2379 AND NVL(service_item_id,p_service_item_id) = p_service_item_id;
2380 CURSOR val_service_item_id_nll_csr(p_workorder_id IN NUMBER) IS
2381 SELECT 'x' from ahl_workorders_osp_v
2382 WHERE workorder_id = p_workorder_id
2383 AND service_item_id IS NULL;
2384
2385 CURSOR item_exists_in_wo_org_csr(p_workorder_id IN NUMBER) IS
2386 SELECT 'x'
2387 from ahl_workorders_osp_v wo, ahl_mtl_items_ou_v mtl
2388 where wo.workorder_id = p_workorder_id and
2389 wo.service_item_id = mtl.inventory_item_id and
2390 mtl.inventory_org_id = wo.organization_id;
2391 l_exist VARCHAR2(1);
2392 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.validate_service_item';
2393 BEGIN
2394 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2395 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
2396 END IF;
2397 IF(p_service_item_id IS NOT NULL AND p_service_item_id <> FND_API.G_MISS_NUM) THEN
2398 OPEN val_service_item_id_inv_csr(p_service_item_id, p_workorder_id);
2399 FETCH val_service_item_id_inv_csr INTO l_exist;
2400 IF(val_service_item_id_inv_csr%NOTFOUND) THEN
2401 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_SVC_ITEM');
2402 FND_MESSAGE.Set_Token('SERVICE_ITEM_ID', p_service_item_id);
2403 FND_MSG_PUB.ADD;
2404 --dbms_output.put_line('Invalid service item not in inventory');
2405 ELSE
2406 -- Valid service item, exists in WO Org
2407 IF ( p_order_type_code = G_OSP_ORDER_TYPE_SERVICE) THEN -- item exchange enhancement
2408 OPEN val_service_item_id_wo_csr(p_workorder_id, p_service_item_id);
2409 FETCH val_service_item_id_wo_csr INTO l_exist;
2410 IF(val_service_item_id_wo_csr%NOTFOUND) THEN
2411 -- Service Item does not match that in WO
2412 OPEN item_exists_in_wo_org_csr(p_workorder_id);
2413 FETCH item_exists_in_wo_org_csr INTO l_exist;
2414 IF (item_exists_in_wo_org_csr%FOUND) THEN
2415 -- WO Service Item does exist in WO Org. So, should have matched!
2416 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_SVC_ITEM_MISWO');
2417 FND_MESSAGE.Set_Token('SERVICE_ITEM_ID', p_service_item_id);
2418 FND_MSG_PUB.ADD;
2419 --dbms_output.put_line('Invalid service item , does not match in wo');
2420 ELSE
2421 -- WO Service Item does not exist in WO Org.
2422 -- So, a mismatch is OK
2423 null;
2424 END IF;
2425 CLOSE item_exists_in_wo_org_csr;
2426 END IF;
2427 CLOSE val_service_item_id_wo_csr;
2428 END IF;
2429 END IF;
2430 CLOSE val_service_item_id_inv_csr;
2431 ELSE
2432 -- Service item is null
2433 IF ( p_order_type_code = G_OSP_ORDER_TYPE_SERVICE) THEN --item exchange enhancement
2434 OPEN val_service_item_id_nll_csr(p_workorder_id);
2435 FETCH val_service_item_id_nll_csr INTO l_exist;
2436 IF(val_service_item_id_nll_csr%NOTFOUND) THEN
2437 -- Work order has a not null service item
2438 OPEN item_exists_in_wo_org_csr(p_workorder_id);
2439 FETCH item_exists_in_wo_org_csr INTO l_exist;
2440 IF (item_exists_in_wo_org_csr%FOUND) THEN
2441 -- WO Service Item does exist in WO Org. So, should not have been null
2442 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_SVC_ITEM_NLL');
2443 FND_MSG_PUB.ADD;
2444 --dbms_output.put_line('Passed service item is null, in wo its not null');
2445 ELSE
2446 -- WO Service Item does not exist in WO Org.
2447 -- So, user entered value can be null
2448 null;
2449 END IF;
2450 CLOSE item_exists_in_wo_org_csr;
2451 END IF;
2452 CLOSE val_service_item_id_nll_csr;
2453 END IF;
2454 END IF;
2455 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2456 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
2457 END IF;
2458 END validate_service_item;
2459
2460 --------------------------------------------------------------------------------------------------------------
2461 PROCEDURE validate_service_item_desc(
2462 p_service_item_id IN NUMBER,
2463 p_service_item_description IN VARCHAR2
2464 ) IS
2465 CURSOR val_service_item_desc_csr(p_service_item_id IN VARCHAR2, p_service_item_description IN VARCHAR2) IS
2466 SELECT 'x' FROM mtl_system_items_kfv MTL
2467 WHERE MTL.inventory_item_id = p_service_item_id
2468 AND MTL.DESCRIPTION = p_service_item_description;
2469 l_exist VARCHAR2(1);
2470 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.validate_service_item_desc';
2471 BEGIN
2472 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2473 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
2474 END IF;
2475 IF(p_service_item_id IS NOT NULL AND p_service_item_id <> FND_API.G_MISS_NUM) THEN
2476 OPEN val_service_item_desc_csr(p_service_item_id , p_service_item_description);
2477 FETCH val_service_item_desc_csr INTO l_exist;
2478 IF(val_service_item_desc_csr%NOTFOUND) THEN
2479 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_SVC_ITEM_DESC');
2480 FND_MESSAGE.Set_Token('SERVICE_ITEM_ID', p_service_item_id);
2481 FND_MESSAGE.Set_Token('SERVICE_ITEM_DESC', p_service_item_description);
2482 FND_MSG_PUB.ADD;
2483 --dbms_output.put_line('Invalid service item description');
2484 END IF;
2485 CLOSE val_service_item_desc_csr;
2486 END IF;
2487 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2488 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
2489 END IF;
2490 END validate_service_item_desc;
2491
2492 --------------------------------------------------------------------------------------------------------------
2493 */
2494 -- Added by jaramana on January 9, 2008 for the Requisition ER 6034236
2495 PROCEDURE val_svc_item_vs_wo_svc_item(
2496 p_workorder_id IN NUMBER,
2497 p_service_item_id IN NUMBER
2498 )IS
2499 CURSOR val_service_item_id_inv_csr(p_service_item_id IN VARCHAR2, p_workorder_id IN NUMBER) IS
2500 SELECT 'x' FROM mtl_system_items_kfv MTL, ahl_workorders WO, AHL_VISITS_B VST
2501 WHERE MTL.inventory_item_id = p_service_item_id
2502 AND MTL.enabled_flag = G_YES_FLAG
2503 AND MTL.inventory_item_flag = G_NO_FLAG
2504 AND MTL.stock_enabled_flag = G_NO_FLAG
2505 AND NVL(MTL.start_date_active, SYSDATE - 1) <= SYSDATE
2506 AND NVL(MTL.end_date_active, SYSDATE + 1) > SYSDATE
2507 AND MTL.purchasing_enabled_flag = G_YES_FLAG
2508 AND NVL(outside_operation_flag, G_NO_FLAG) = G_NO_FLAG
2509 AND MTL.organization_id = VST.organization_id
2510 AND VST.visit_id = WO.visit_id
2511 AND WO.workorder_id = p_workorder_id;
2512
2513 CURSOR val_service_item_id_wo_csr(p_workorder_id IN NUMBER, p_service_item_id IN NUMBER) IS
2514 SELECT 'x' from ahl_workorders WO, AHL_ROUTES_B ARB
2515 WHERE WO.workorder_id = p_workorder_id
2516 AND WO.ROUTE_ID = ARB.ROUTE_ID (+)
2517 AND NVL(ARB.service_item_id, p_service_item_id) = p_service_item_id;
2518
2519 CURSOR val_service_item_id_nll_csr(p_workorder_id IN NUMBER) IS
2520 SELECT 'x' from ahl_workorders WO, AHL_ROUTES_B ARB
2521 WHERE WO.workorder_id = p_workorder_id
2522 AND WO.ROUTE_ID = ARB.ROUTE_ID (+)
2523 AND ARB.service_item_id IS NULL;
2524
2525 CURSOR item_exists_in_wo_org_csr(p_workorder_id IN NUMBER) IS
2526 SELECT 'x'
2527 from ahl_workorders WO, AHL_ROUTES_B ARB, AHL_VISITS_B VST, ahl_mtl_items_ou_v mtl
2528 where wo.workorder_id = p_workorder_id and
2529 WO.ROUTE_ID = ARB.ROUTE_ID (+) and
2530 ARB.service_item_id = mtl.inventory_item_id and
2531 VST.visit_id = WO.visit_id and
2532 mtl.inventory_org_id = VST.organization_id;
2533
2534 l_exist VARCHAR2(1);
2535 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.val_svc_item_vs_wo_svc_item';
2536
2537 BEGIN
2538 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2539 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
2540 END IF;
2541 IF(p_service_item_id IS NOT NULL AND p_service_item_id <> FND_API.G_MISS_NUM) THEN
2542
2543 OPEN val_service_item_id_inv_csr(p_service_item_id, p_workorder_id);
2544 FETCH val_service_item_id_inv_csr INTO l_exist;
2545 IF(val_service_item_id_inv_csr%NOTFOUND) THEN
2546 FND_MESSAGE.Set_Name(G_APP_NAME, 'AHL_OSP_LN_INV_SVC_ITEM');
2547 FND_MESSAGE.Set_Token('SERVICE_ITEM_ID', p_service_item_id);
2548 FND_MSG_PUB.ADD;
2549 --dbms_output.put_line('Invalid service item not in inventory');
2550 ELSE
2551 -- Valid service item, exists in WO Org
2552 OPEN val_service_item_id_wo_csr(p_workorder_id, p_service_item_id);
2553 FETCH val_service_item_id_wo_csr INTO l_exist;
2554 IF(val_service_item_id_wo_csr%NOTFOUND) THEN
2555 -- Service Item does not match that in WO
2556 OPEN item_exists_in_wo_org_csr(p_workorder_id);
2557 FETCH item_exists_in_wo_org_csr INTO l_exist;
2558 IF (item_exists_in_wo_org_csr%FOUND) THEN
2559 -- WO Service Item does exist in WO Org. So, should have matched!
2560 FND_MESSAGE.Set_Name(G_APP_NAME, 'AHL_OSP_LN_INV_SVC_ITEM_MISWO');
2561 FND_MESSAGE.Set_Token('SERVICE_ITEM_ID', p_service_item_id);
2562 FND_MSG_PUB.ADD;
2563 --dbms_output.put_line('Invalid service item , does not match in wo');
2564 ELSE
2565 -- WO Service Item does not exist in WO Org.
2566 -- So, a mismatch is OK
2567 null;
2568 END IF;
2569 CLOSE item_exists_in_wo_org_csr;
2570 END IF;
2571 CLOSE val_service_item_id_wo_csr;
2572 END IF;
2573 CLOSE val_service_item_id_inv_csr;
2574
2575 ELSE
2576 -- Service item is null
2577 OPEN val_service_item_id_nll_csr(p_workorder_id);
2578 FETCH val_service_item_id_nll_csr INTO l_exist;
2579 IF(val_service_item_id_nll_csr%NOTFOUND) THEN
2580 -- Work order has a not null service item
2581 OPEN item_exists_in_wo_org_csr(p_workorder_id);
2582 FETCH item_exists_in_wo_org_csr INTO l_exist;
2583 IF (item_exists_in_wo_org_csr%FOUND) THEN
2584 -- WO Service Item does exist in WO Org. So, should not have been null
2585 FND_MESSAGE.Set_Name(G_APP_NAME, 'AHL_OSP_LN_INV_SVC_ITEM_NLL');
2586 FND_MSG_PUB.ADD;
2587 --dbms_output.put_line('Passed service item is null, in wo its not null');
2588 ELSE
2589 -- WO Service Item does not exist in WO Org.
2590 -- So, user entered value can be null
2591 null;
2592 END IF;
2593 CLOSE item_exists_in_wo_org_csr;
2594 END IF;
2595 CLOSE val_service_item_id_nll_csr;
2596 END IF;
2597
2598 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2599 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
2600 END IF;
2601 END val_svc_item_vs_wo_svc_item;
2602
2603 --------------------------------------------------------------------------------------------------------------
2604
2605 --p_org_id added by mpothuku to fix the Perf Bug #4919164
2606 PROCEDURE validate_service_item_uom(
2607 p_service_item_id IN NUMBER,
2608 p_service_item_uom_code IN VARCHAR2,
2609 p_org_id IN NUMBER
2610 )IS
2611 CURSOR val_service_item_uom_csr(p_service_item_id IN NUMBER,p_service_item_uom_code IN VARCHAR2, p_org_id IN NUMBER ) IS
2612 SELECT 'x' FROM ahl_item_class_uom_v
2613 WHERE inventory_item_id = p_service_item_id
2614 AND uom_code = p_service_item_uom_code
2615 AND inventory_org_id = p_org_id;
2616 CURSOR val_uom_code_csr(p_service_item_uom_code IN VARCHAR2) IS
2617 SELECT 'x' from mtl_units_of_measure_vl
2618 WHERE uom_code = p_service_item_uom_code;
2619 l_exist VARCHAR2(1);
2620 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.validate_service_item_uom';
2621 BEGIN
2622 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2623 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure'
2624 || '- Service Item Id: ' || p_service_item_id || 'uom_code' || p_service_item_uom_code );
2625 END IF;
2626 IF(p_service_item_id IS NOT NULL AND p_service_item_id <> FND_API.G_MISS_NUM) THEN
2627 IF(p_service_item_uom_code IS NOT NULL AND p_service_item_uom_code <> FND_API.G_MISS_CHAR) THEN
2628 OPEN val_service_item_uom_csr(p_service_item_id,p_service_item_uom_code,p_org_id);
2629 FETCH val_service_item_uom_csr INTO l_exist;
2630 IF(val_service_item_uom_csr%NOTFOUND) THEN
2631 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_UOM');
2632 FND_MESSAGE.Set_Token('UOM_CODE', p_service_item_uom_code);
2633 -- FND_MESSAGE.Set_Token('SERVICE_ITEM_ID', p_service_item_id);
2634 FND_MSG_PUB.ADD;
2635 END IF;
2636 CLOSE val_service_item_uom_csr;
2637 END IF;
2638 ELSE
2639 IF(p_service_item_uom_code IS NOT NULL AND p_service_item_uom_code <> FND_API.G_MISS_CHAR) THEN
2640 OPEN val_uom_code_csr(p_service_item_uom_code);
2641 FETCH val_uom_code_csr INTO l_exist;
2642 IF(val_uom_code_csr%NOTFOUND) THEN
2643 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_UOM');
2644 FND_MESSAGE.Set_Token('UOM_CODE', p_service_item_uom_code);
2645 -- FND_MESSAGE.Set_Token('SERVICE_ITEM_ID', p_service_item_id);
2646 FND_MSG_PUB.ADD;
2647 END IF;
2648 CLOSE val_uom_code_csr;
2649 END IF;
2650 END IF;
2651 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2652 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
2653 END IF;
2654 END validate_service_item_uom;
2655
2656 --------------------------------------------------------------------------------------------------------------
2657 PROCEDURE validate_po_line_type(
2658 p_po_line_type_id IN NUMBER
2659 )IS
2660 CURSOR val_po_line_type_id_csr(p_po_line_type_id IN NUMBER) IS
2661 SELECT 'x' FROM po_line_types
2662 WHERE line_type_id = p_po_line_type_id and
2663 ORDER_TYPE_LOOKUP_CODE = 'QUANTITY' and
2664 NVL(OUTSIDE_OPERATION_FLAG, G_NO_FLAG) = G_NO_FLAG;
2665 l_exist VARCHAR2(1);
2666 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.validate_po_line_type';
2667 BEGIN
2668 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2669 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
2670 END IF;
2671 IF(p_po_line_type_id IS NOT NULL AND p_po_line_type_id <> FND_API.G_MISS_NUM) THEN
2672 OPEN val_po_line_type_id_csr(p_po_line_type_id);
2673 FETCH val_po_line_type_id_csr INTO l_exist;
2674 IF(val_po_line_type_id_csr%NOTFOUND) THEN
2675 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_LNTYP_ID');
2676 FND_MESSAGE.Set_Token('LINE_TYPE_ID', p_po_line_type_id);
2677 FND_MSG_PUB.ADD;
2678 END IF;
2679 CLOSE val_po_line_type_id_csr;
2680 END IF;
2681 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2682 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
2683 END IF;
2684 END validate_po_line_type;
2685
2686 --------------------------------------------------------------------------------------------------------------
2687 PROCEDURE validate_po_line(
2688 p_po_line_id IN NUMBER,
2689 p_osp_order_id IN NUMBER
2690 )IS
2691 CURSOR val_po_line_id_csr(p_po_line_id IN NUMBER, p_osp_order_id IN NUMBER) IS
2692 SELECT 'x' FROM po_lines_all POL, ahl_osp_orders_b OO
2693 WHERE POL.po_line_id = p_po_line_id
2694 AND OO.osp_order_id = p_osp_order_id
2695 AND POL.PO_HEADER_ID = OO.po_header_id
2696 -- Added by jaramana on January 9, 2008 to fix the Bug 5358438/5967633
2697 AND NVL(POL.CANCEL_FLAG, 'N') <> 'Y'
2698 --the line_id should not have already been associated to the same osp order
2699 AND NOT EXISTS (select 1 from ahl_osp_order_lines
2700 where osp_order_id = p_osp_order_id
2701 and po_line_id = p_po_line_id );
2702 -- jaramana End
2703 l_exist VARCHAR2(1);
2704 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.validate_po_line';
2705 BEGIN
2706 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2707 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
2708 END IF;
2709 IF(p_po_line_id IS NOT NULL AND p_po_line_id <> FND_API.G_MISS_NUM) THEN
2710 OPEN val_po_line_id_csr(p_po_line_id, p_osp_order_id);
2711 FETCH val_po_line_id_csr INTO l_exist;
2712 IF(val_po_line_id_csr%NOTFOUND) THEN
2713 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_PO_LINE_INV');
2714 FND_MESSAGE.Set_Token('PO_LINE_ID', p_po_line_id);
2715 FND_MSG_PUB.ADD;
2716 END IF;
2717 CLOSE val_po_line_id_csr;
2718 END IF;
2719 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2720 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
2721 END IF;
2722 END validate_po_line;
2723
2724 -------------------------------------------------------------------------------------------------------------
2725 PROCEDURE validate_exchange_instance_id(p_exchange_instance_id IN NUMBER) IS
2726 CURSOR val_instance_id_csr(p_instance_id IN NUMBER) IS
2727 SELECT 'x' FROM csi_item_instances csi
2728 WHERE instance_id = p_instance_id
2729 AND trunc(sysdate) < trunc(nvl(active_end_date, sysdate+1))
2730 AND NOT EXISTS (select subject_id from csi_ii_relationships where
2731 subject_id = p_instance_id and
2732 relationship_type_code = 'COMPONENT-OF' and
2733 trunc(sysdate) >= trunc(nvl(active_start_date,sysdate)) and
2734 trunc(sysdate) < trunc(nvl(active_end_date, sysdate+1))
2735 ) ;
2736 l_exist VARCHAR2(1);
2737 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.validate_exchange_instance_id';
2738 BEGIN
2739 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2740 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
2741 END IF;
2742 IF(p_exchange_instance_id IS NOT NULL AND p_exchange_instance_id <> FND_API.G_MISS_NUM) THEN
2743 OPEN val_instance_id_csr(p_exchange_instance_id);
2744 FETCH val_instance_id_csr INTO l_exist;
2745 IF (val_instance_id_csr %NOTFOUND) THEN
2746 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INSTANCE_ID_INV');
2747 FND_MESSAGE.Set_Token('EXCHANGE_INSTANCE_ID', p_exchange_instance_id);
2748 FND_MSG_PUB.ADD;
2749 END IF;
2750 END IF;
2751 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2752 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
2753 END IF;
2754 END validate_exchange_instance_id;
2755
2756
2757 /*
2758 - Changed by jaramana on January 9, 2008 for the Requisition ER 6034236 (We are not using this procedure anymore):
2759 Commented the nullify_exchange_instance procedure and placed it at the end of package. Please note that instead of using this
2760 heavy weight procedure we are directly updating the AHL_OSP_ORDER_LINES table
2761 */
2762
2763 --------------------------------------------------------------------------------------------------------------
2764 -- Jerry made minor changes to this procedure for ISO in May 27, 2005
2765 -- Basically, just replace g_old_status_code with l_old_status_code which
2766 -- is queried on the fly
2767 --------------------------------------------------------------------------------------------------------------
2768 PROCEDURE process_order_status_change(
2769 p_x_osp_order_rec IN OUT NOCOPY osp_order_rec_type)
2770 IS
2771 CURSOR val_order_has_lines(p_osp_order_id IN NUMBER)IS
2772 SELECT 'x' FROM ahl_osp_order_lines
2773 WHERE osp_order_id = p_osp_order_id;
2774 l_exist VARCHAR2(1);
2775 CURSOR val_order_has_ship_lines(p_osp_order_id IN NUMBER)IS
2776 SELECT oe_ship_line_id, oe_return_line_id, osp_line_number FROM ahl_osp_order_lines
2777 WHERE osp_order_id = p_osp_order_id;
2778 l_oe_ship_line_id NUMBER;
2779 l_oe_return_line_id NUMBER;
2780 l_line_number NUMBER;
2781 l_count NUMBER;
2782 l_batch_id NUMBER;
2783 l_request_id NUMBER;
2784 l_interface_header_id NUMBER;
2785 l_return_status VARCHAR2(1);
2786 l_msg_count NUMBER;
2787 l_msg_data VARCHAR2(1000);
2788 l_shipment_IDs_Tbl AHL_OSP_SHIPMENT_PUB.Ship_ID_Tbl_Type;
2789 CURSOR val_all_wo_closed(p_osp_order_id IN NUMBER) IS
2790 --Modified by mpothuku on 27-Feb-06 to use ahl_workorders instead of ahl_workorders_osp_v
2791 --to fix the Perf Bug #4919164
2792 SELECT 'x' from ahl_osp_order_lines OL, ahl_workorders WO
2793 WHERE OL.osp_order_id = p_osp_order_id
2794 AND OL.workorder_id = WO.workorder_id
2795 AND OL.status_code IS NULL
2796 AND WO.status_code NOT IN(G_OSP_WO_CANCELLED,G_OSP_WO_CLOSED);
2797 CURSOR val_order_lines_csr(p_osp_order_id IN NUMBER) IS
2798 SELECT osp_line_number, service_item_id, service_item_description, service_item_uom_code, quantity, need_by_date, po_line_type_id
2799 FROM AHL_OSP_ORDER_LINES
2800 WHERE osp_order_id = p_osp_order_id
2801 ORDER BY osp_line_number;
2802 CURSOR get_old_status IS
2803 SELECT status_code, object_version_number
2804 FROM ahl_osp_orders_b
2805 WHERE osp_order_id = p_x_osp_order_rec.osp_order_id;
2806
2807 l_osp_line_number NUMBER;
2808 l_service_item_id NUMBER;
2809 l_service_item_description VARCHAR(2000);
2810 l_service_item_uom_code VARCHAR(30);
2811 l_quantity NUMBER;
2812 l_need_by_date DATE;
2813 l_po_line_type_id NUMBER;
2814 l_old_status_code VARCHAR2(30);
2815 l_temp_status_code VARCHAR2(30);
2816 l_new_ovn NUMBER;
2817 l_old_ovn NUMBER;
2818 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || 'process_order_status_change';
2819 BEGIN
2820 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2821 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin',
2822 'osp_order_id='||p_x_osp_order_rec.osp_order_id||
2823 'status='||p_x_osp_order_rec.status_code||
2824 'ovn='||p_x_osp_order_rec.object_version_number);
2825 END IF;
2826 OPEN get_old_status;
2827 FETCH get_old_status INTO l_old_status_code, l_old_ovn;
2828 CLOSE get_old_status;
2829 IF(p_x_osp_order_rec.order_type_code IN (G_OSP_ORDER_TYPE_SERVICE, G_OSP_ORDER_TYPE_EXCHANGE) AND p_x_osp_order_rec.operation_flag = G_OP_UPDATE) THEN
2830 --IF(g_old_status_code IN (G_OSP_ENTERED_STATUS, G_OSP_SUB_FAILED_STATUS) AND
2831 -- Added by jaramana on January 9, 2008 for the Requisition ER 6034236
2832 IF(l_old_status_code IN (G_OSP_ENTERED_STATUS, G_OSP_SUB_FAILED_STATUS, G_OSP_REQ_SUB_FAILED_STATUS) AND
2833 p_x_osp_order_rec.status_code IN (G_OSP_SUBMITTED_STATUS, G_OSP_REQ_SUBMITTED_STATUS)) THEN
2834 -- jaramana End
2835 -- validate fields and submit for PO creation
2836 IF(p_x_osp_order_rec.vendor_id IS NULL) THEN
2837 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_VEN_NLL');
2838 FND_MSG_PUB.ADD;
2839 END IF;
2840 IF (p_x_osp_order_rec.vendor_site_id IS NULL) THEN
2841 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_VENST_NLL');
2842 FND_MSG_PUB.ADD;
2843 END IF;
2844 IF (p_x_osp_order_rec.po_agent_id IS NULL) THEN
2845 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_BUYER_NLL');
2846 FND_MSG_PUB.ADD;
2847 END IF;
2848 IF (p_x_osp_order_rec.po_header_id IS NOT NULL) THEN
2849 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_PO_NNLL');
2850 FND_MSG_PUB.ADD;
2851 END IF;
2852
2853 -- Added by jaramana on January 9, 2008 for the Requisition ER 6034236
2854 IF (p_x_osp_order_rec.po_req_header_id IS NOT NULL) THEN
2855 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_REQ_NNLL');
2856 FND_MSG_PUB.ADD;
2857 END IF;
2858 -- jaramana End
2859
2860 -- check whether order has lines
2861 OPEN val_order_has_lines(p_x_osp_order_rec.osp_order_id);
2862 FETCH val_order_has_lines INTO l_exist;
2863 IF(val_order_has_lines%NOTFOUND) THEN
2864 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_NO_LNS');
2865 FND_MSG_PUB.ADD;
2866 END IF;
2867 CLOSE val_order_has_lines;
2868 -- check null values in order lines
2869 OPEN val_order_lines_csr(p_x_osp_order_rec.osp_order_id);
2870 LOOP
2871 FETCH val_order_lines_csr INTO l_osp_line_number, l_service_item_id, l_service_item_description,
2872 l_service_item_uom_code, l_quantity, l_need_by_date, l_po_line_type_id;
2873 EXIT WHEN val_order_lines_csr%NOTFOUND;
2874 --service item id and service item description cannot be both null
2875 IF(l_service_item_description IS NULL AND l_service_item_id IS NULL) THEN
2876 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_ITMID_NL');
2877 FND_MESSAGE.Set_Token('LINE_NUM', l_osp_line_number);
2878 FND_MSG_PUB.ADD;
2879 END IF;
2880 --l_service_item_uom_code cannot be null
2881 IF(l_service_item_uom_code IS NULL) THEN
2882 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_UOM_NL');
2883 FND_MESSAGE.Set_Token('LINE_NUM', l_osp_line_number);
2884 FND_MSG_PUB.ADD;
2885 END IF;
2886 --quantity cannot be null
2887 IF(l_quantity IS NULL) THEN
2888 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_QTY_NL');
2889 FND_MESSAGE.Set_Token('LINE_NUM', l_osp_line_number);
2890 FND_MSG_PUB.ADD;
2891 END IF;
2892 --need_by_date cannot be null
2893 IF(l_need_by_date IS NULL) THEN
2894 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_NBD_NL');
2895 FND_MESSAGE.Set_Token('LINE_NUM', l_osp_line_number);
2896 FND_MSG_PUB.ADD;
2897 END IF;
2898 --po_line_type_id cannot be null
2899 IF(l_po_line_type_id IS NULL) THEN
2900 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_PO_LNTYP_NL');
2901 FND_MESSAGE.Set_Token('LINE_NUM', l_osp_line_number);
2902 FND_MSG_PUB.ADD;
2903 END IF;
2904 END LOOP;
2905 CLOSE val_order_lines_csr;
2906 IF FND_MSG_PUB.count_msg > 0 THEN
2907 RAISE FND_API.G_EXC_ERROR;
2908 -- Changed by jaramana on January 9, 2008 for the Requisition ER 6034236
2909 ELSIF(p_x_osp_order_rec.status_code = G_OSP_SUBMITTED_STATUS) THEN
2910 -- jaramana End
2911 -- submit for PO creation
2912 AHL_OSP_PO_PVT.Create_Purchase_Order
2913 (
2914 p_api_version => 1.0 ,
2915 p_osp_order_id => p_x_osp_order_rec.osp_order_id,
2916 x_batch_id => l_batch_id,
2917 x_request_id => l_request_id,
2918 x_interface_header_id =>l_interface_header_id,
2919 x_return_status => l_return_status,
2920 x_msg_count => l_msg_count,
2921 x_msg_data => l_msg_data
2922 );
2923 OPEN get_old_status;
2924 FETCH get_old_status INTO l_temp_status_code, l_new_ovn;
2925 CLOSE get_old_status;
2926 IF (l_return_status <> FND_API.G_RET_STS_SUCCESS OR
2927 l_new_ovn <> l_old_ovn+1) THEN
2928 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_PO_FLD');
2929 FND_MSG_PUB.ADD;
2930 ELSE
2931 p_x_osp_order_rec.object_version_number := l_new_ovn;
2932 p_x_osp_order_rec.po_request_id := l_request_id;
2933 p_x_osp_order_rec.po_interface_header_id := l_interface_header_id;
2934 p_x_osp_order_rec.po_batch_id := l_batch_id;
2935 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2936 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin',
2937 'batch_id='||p_x_osp_order_rec.po_batch_id||
2938 'request_id='||p_x_osp_order_rec.po_request_id||
2939 'interface_id='||p_x_osp_order_rec.po_interface_header_id);
2940 END IF;
2941 END IF;
2942 -- Added by jaramana on January 9, 2008 for the Requisition ER 6034236
2943 ELSIF(p_x_osp_order_rec.status_code = G_OSP_REQ_SUBMITTED_STATUS) THEN
2944 -- submit for PO creation
2945 AHL_OSP_PO_REQ_PVT.Create_PO_Requisition
2946 (
2947 p_api_version => 1.0 ,
2948 p_osp_order_id => p_x_osp_order_rec.osp_order_id,
2949 x_batch_id => l_batch_id,
2950 x_request_id => l_request_id,
2951 x_return_status => l_return_status,
2952 x_msg_count => l_msg_count,
2953 x_msg_data => l_msg_data
2954 );
2955 OPEN get_old_status;
2956 FETCH get_old_status INTO l_temp_status_code, l_new_ovn;
2957 CLOSE get_old_status;
2958 IF (l_return_status <> FND_API.G_RET_STS_SUCCESS OR
2959 l_new_ovn <> l_old_ovn+1) THEN
2960 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_REQ_FLD');
2961 FND_MSG_PUB.ADD;
2962 ELSE
2963 p_x_osp_order_rec.object_version_number := l_new_ovn;
2964 p_x_osp_order_rec.po_request_id := l_request_id;
2965 p_x_osp_order_rec.po_batch_id := l_batch_id;
2966 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
2967 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin',
2968 'batch_id='||p_x_osp_order_rec.po_batch_id||
2969 'request_id='||p_x_osp_order_rec.po_request_id);
2970 END IF;
2971 END IF;
2972 -- jaramana End
2973
2974 END IF;
2975 --ELSIF(g_old_status_code = G_OSP_PO_CREATED_STATUS AND p_x_osp_order_rec.status_code = G_OSP_CLOSED_STATUS) THEN
2976 -- Changed by jaramana on January 9, 2008 for the Requisition ER 6034236
2977 --ELSIF(l_old_status_code = G_OSP_PO_CREATED_STATUS AND p_x_osp_order_rec.status_code = G_OSP_CLOSED_STATUS) THEN
2978 ELSIF(l_old_status_code IN (G_OSP_PO_CREATED_STATUS,G_OSP_REQ_CREATED_STATUS) AND p_x_osp_order_rec.status_code = G_OSP_CLOSED_STATUS) THEN
2979
2980 -- validate fields and ask whether PO and SO is closed.
2981 IF(l_old_status_code = G_OSP_PO_CREATED_STATUS AND p_x_osp_order_rec.po_header_id IS NULL) THEN
2982 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_CL_PO_NLL');
2983 FND_MSG_PUB.ADD;
2984 ELSIF(l_old_status_code = G_OSP_REQ_CREATED_STATUS AND p_x_osp_order_rec.po_req_header_id IS NULL) THEN
2985 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_CL_REQ_NLL');
2986 FND_MSG_PUB.ADD;
2987 ELSE --This would mean either po_header_id is not null OR po_req_header_id is not NULL
2988 -- If the status is PO_CREATED, ask PO whether it is closed/cancelled.
2989 IF (l_old_status_code = G_OSP_PO_CREATED_STATUS AND
2990 AHL_OSP_PO_PVT.Is_PO_Closed(p_x_osp_order_rec.po_header_id) = G_NO_FLAG ) THEN
2991 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_CL_PO_OPEN');
2992 FND_MSG_PUB.ADD;
2993 END IF;
2994 -- If the status is REQ_CREATED, ask Requisition whether the order can be closed.
2995 IF(l_old_status_code = G_OSP_REQ_CREATED_STATUS AND
2996 AHL_OSP_PO_REQ_PVT.Is_PO_Req_Closed(p_x_osp_order_rec.po_req_header_id) = G_NO_FLAG ) THEN
2997 FND_MESSAGE.Set_Name('AHL', 'AHL_OSP_INV_CL_REQ_OPEN');
2998 FND_MSG_PUB.ADD;
2999 END IF;
3000
3001 -- ask SO whether can close
3002 IF(p_x_osp_order_rec.oe_header_id IS NOT NULL) THEN
3003 IF NOT(FND_API.TO_BOOLEAN(AHL_OSP_SHIPMENT_PUB.Is_Order_Header_Closed( p_x_osp_order_rec.oe_header_id))) THEN
3004 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_CL_SO_OPEN');
3005 FND_MSG_PUB.ADD;
3006 END IF;
3007 END IF;
3008 -- check whether all the workorders are closed.
3009 OPEN val_all_wo_closed(p_x_osp_order_rec.osp_order_id);
3010 FETCH val_all_wo_closed INTO l_exist;
3011 IF(val_all_wo_closed%FOUND) THEN
3012 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_CL_WO_OPEN');
3013 FND_MSG_PUB.ADD;
3014 END IF;
3015 CLOSE val_all_wo_closed;
3016 END IF;
3017 END IF;
3018 ELSIF(p_x_osp_order_rec.order_type_code IN(G_OSP_ORDER_TYPE_LOAN, G_OSP_ORDER_TYPE_BORROW) AND p_x_osp_order_rec.operation_flag = G_OP_UPDATE)THEN
3019 --IF(g_old_status_code = G_OSP_ENTERED_STATUS AND
3020 IF(l_old_status_code = G_OSP_ENTERED_STATUS AND
3021 p_x_osp_order_rec.status_code = G_OSP_SUBMITTED_STATUS) THEN
3022 IF(p_x_osp_order_rec.customer_id IS NULL AND p_x_osp_order_rec.order_type_code = G_OSP_ORDER_TYPE_LOAN) THEN
3023 --only loan type requires customer id for borrow it's optional (bug fix).
3024 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_CUST_NLL');
3025 FND_MSG_PUB.ADD;
3026 END IF;
3027 /* Change made by mpothuku to make the contract_id optional on 12/16/04
3028 This is a work around and has to be revoked after PM comes up with the Service Contract Integration
3029 */
3030 -- Changes start
3031 /*
3032 IF(p_x_osp_order_rec.contract_id IS NULL) THEN
3033 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_CTRCT_NLL');
3034 FND_MSG_PUB.ADD;
3035 END IF;
3036 */
3037 -- Changes by mpothuku End
3038 IF(p_x_osp_order_rec.oe_header_id IS NULL) THEN
3039 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_OE_NLL');
3040 FND_MSG_PUB.ADD;
3041 END IF;
3042 -- check whether order has lines and all lines have shipping information
3043 OPEN val_order_has_ship_lines(p_x_osp_order_rec.osp_order_id);
3044 l_count := 0;
3045 LOOP
3046 FETCH val_order_has_ship_lines INTO l_oe_ship_line_id, l_oe_return_line_id, l_line_number;
3047 IF(val_order_has_ship_lines%NOTFOUND) THEN
3048 EXIT;
3049 ELSIF (l_oe_ship_line_id IS NULL AND l_oe_return_line_id IS NULL) THEN
3050 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_NO_SHIP_LN');
3051 FND_MESSAGE.Set_Token('LINE_NUMBER', l_line_number);
3052 FND_MSG_PUB.ADD;
3053 l_count := l_count + 1;
3054 ELSE
3055 l_count := l_count + 1;
3056 END IF;
3057 END LOOP;
3058 IF(l_count < 1) THEN
3059 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_NO_LNS');
3060 FND_MSG_PUB.ADD;
3061 END IF;
3062 CLOSE val_order_has_ship_lines;
3063 IF FND_MSG_PUB.count_msg > 0 THEN
3064 RAISE FND_API.G_EXC_ERROR;
3065 ELSE
3066 l_shipment_IDs_Tbl(1) := p_x_osp_order_rec.oe_header_id;
3067 AHL_OSP_SHIPMENT_PUB.Book_Order(
3068 p_api_version => 1.0,
3069 p_init_msg_list => FND_API.G_FALSE,
3070 p_commit => FND_API.G_FALSE,
3071 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
3072 p_oe_header_tbl => l_shipment_IDs_Tbl,
3073 x_return_status => l_return_status,
3074 x_msg_count => l_msg_count,
3075 x_msg_data => l_msg_data
3076 );
3077 IF (l_return_status <> FND_API.G_RET_STS_SUCCESS)THEN
3078 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SUB_SO_FLD');
3079 FND_MSG_PUB.ADD;
3080 END IF;
3081 END IF;
3082 --ELSIF(g_old_status_code = G_OSP_SUBMITTED_STATUS AND p_x_osp_order_rec.status_code = G_OSP_CLOSED_STATUS) THEN
3083 ELSIF(l_old_status_code = G_OSP_SUBMITTED_STATUS AND p_x_osp_order_rec.status_code = G_OSP_CLOSED_STATUS) THEN
3084 -- validate fields and ask SO whether order can be closed.
3085 --dbms_output.put_line('Sales order closed ');
3086 IF(p_x_osp_order_rec.oe_header_id IS NULL) THEN
3087 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_CL_OE_NLL');
3088 FND_MSG_PUB.ADD;
3089 ELSE
3090 --dbms_output.put_line('Sales order closed ' || AHL_OSP_SHIPMENT_PUB.Is_Order_Header_Closed( p_x_osp_order_rec.oe_header_id));
3091 IF NOT(FND_API.TO_BOOLEAN(AHL_OSP_SHIPMENT_PUB.Is_Order_Header_Closed( p_x_osp_order_rec.oe_header_id))) THEN
3092 --dbms_output.put_line('Sales order is not closed');
3093 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_CL_SO_OPEN');
3094 FND_MSG_PUB.ADD;
3095 END IF;
3096 -- check whether all the workorders are closed.
3097 OPEN val_all_wo_closed(p_x_osp_order_rec.osp_order_id);
3098 FETCH val_all_wo_closed INTO l_exist;
3099 IF(val_all_wo_closed%FOUND) THEN
3100 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_CL_WO_OPEN');
3101 FND_MSG_PUB.ADD;
3102 END IF;
3103 CLOSE val_all_wo_closed;
3104 END IF;
3105 END IF;
3106 END IF;
3107 IF FND_MSG_PUB.count_msg > 0 THEN
3108 RAISE FND_API.G_EXC_ERROR;
3109 END IF;
3110 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3111 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
3112 END IF;
3113 END process_order_status_change;
3114
3115 --------------------------------------------------------------------------------------------------------------
3116 PROCEDURE delete_cancel_so(
3117 p_oe_header_id IN NUMBER,
3118 p_del_cancel_so_lines_tbl IN del_cancel_so_lines_tbl_type,
3119 p_cancel_flag IN VARCHAR2 := FND_API.G_FALSE
3120 ) IS
3121 l_Ship_ID_Tbl AHL_OSP_SHIPMENT_PUB.Ship_ID_Tbl_Type;
3122 l_return_status VARCHAR2(1);
3123 l_msg_count NUMBER;
3124 l_msg_data VARCHAR2(1000);
3125 CURSOR can_del_ship_line_csr(p_osp_order_id IN NUMBER, p_oe_ship_line_id IN NUMBER) IS
3126 SELECT 'x' FROM ahl_osp_order_lines
3127 WHERE osp_order_id = p_osp_order_id
3128 AND oe_ship_line_id = p_oe_ship_line_id
3129 AND status_code IS NULL;
3130 CURSOR can_del_return_line_csr(p_osp_order_id IN NUMBER, p_oe_return_line_id IN NUMBER) IS
3131 SELECT 'x' FROM ahl_osp_order_lines
3132 WHERE osp_order_id = p_osp_order_id
3133 AND oe_return_line_id = p_oe_return_line_id
3134 AND status_code IS NULL;
3135 CURSOR line_already_shipped_csr(p_oe_line_id IN NUMBER) IS
3136 SELECT 'x' from oe_order_lines_all
3137 where line_id = p_oe_line_id AND
3138 shipped_quantity > 0;
3139 l_exist VARCHAR2(1);
3140 l_index NUMBER := 1;
3141 l_unique_flag BOOLEAN := TRUE;
3142 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.delete_cancel_so';
3143 BEGIN
3144 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3145 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
3146 END IF;
3147 IF(p_oe_header_id IS NOT NULL) THEN
3148 -- CALL SO to delete/cancel SO
3149 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3150 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'Calling AHL_OSP_SHIPMENT_PUB.Delete_Cancel_Order with p_oe_header_id = ' || p_oe_header_id);
3151 END IF;
3152 AHL_OSP_SHIPMENT_PUB.Delete_Cancel_Order (
3153 p_api_version => 1.0,
3154 p_oe_header_id => p_oe_header_id,
3155 p_oe_lines_tbl => l_Ship_ID_Tbl,
3156 p_cancel_flag => p_cancel_flag,
3157 x_return_status => l_return_status ,
3158 x_msg_count => l_msg_count ,
3159 x_msg_data => l_msg_data
3160 );
3161 IF(l_return_status <> FND_API.G_RET_STS_SUCCESS)THEN
3162 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SO_CAN_FLD');
3163 FND_MSG_PUB.ADD;
3164 END IF;
3165 ELSIF ( p_del_cancel_so_lines_tbl IS NOT NULL) THEN
3166 IF NOT(p_del_cancel_so_lines_tbl.COUNT > 0) THEN
3167 RETURN;
3168 END IF;
3169 FOR i IN p_del_cancel_so_lines_tbl.FIRST..p_del_cancel_so_lines_tbl.LAST LOOP
3170 IF(p_del_cancel_so_lines_tbl(i).oe_ship_line_id IS NOT NULL) THEN
3171 IF(l_Ship_ID_Tbl.COUNT > 0) THEN
3172 l_unique_flag := TRUE;
3173 -- Check if this shipment line has already been included for deletion
3174 -- If so, set the l_unique_flag to false to prevent duplicates
3175 FOR j IN l_Ship_ID_Tbl.FIRST..l_Ship_ID_Tbl.LAST LOOP
3176 IF(l_Ship_ID_Tbl(j) = p_del_cancel_so_lines_tbl(i).oe_ship_line_id) THEN
3177 l_unique_flag := FALSE;
3178 EXIT;
3179 END IF;
3180 END LOOP;
3181 END IF;
3182 IF(l_unique_flag) THEN
3183 -- Not a duplicate
3184 -- Check if there are any active OSP Lines for this Shipment
3185 OPEN can_del_ship_line_csr(p_del_cancel_so_lines_tbl(i).osp_order_id, p_del_cancel_so_lines_tbl(i).oe_ship_line_id);
3186 FETCH can_del_ship_line_csr INTO l_exist;
3187 IF(can_del_ship_line_csr%NOTFOUND) THEN
3188 -- No other active OSP Line for this shipment
3189 -- Check if the shipment has already occured
3190 OPEN line_already_shipped_csr(p_del_cancel_so_lines_tbl(i).oe_ship_line_id);
3191 FETCH line_already_shipped_csr INTO l_exist;
3192 IF (line_already_shipped_csr%NOTFOUND) THEN
3193 -- Line not yet shipped: Include for deletion
3194 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3195 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'Shipment line with id ' || p_del_cancel_so_lines_tbl(i).oe_ship_line_id || ' included for deletion/cancellation.');
3196 END IF;
3197 l_Ship_ID_Tbl(l_index) := p_del_cancel_so_lines_tbl(i).oe_ship_line_id;
3198 l_index := l_index + 1;
3199 END IF;
3200 CLOSE line_already_shipped_csr;
3201 END IF;
3202 CLOSE can_del_ship_line_csr;
3203 END IF;
3204 END IF;
3205 IF(p_del_cancel_so_lines_tbl(i).oe_return_line_id IS NOT NULL) THEN
3206 IF(l_Ship_ID_Tbl.COUNT > 0) THEN
3207 l_unique_flag := TRUE;
3208 -- Check if this shipment line has already been included for deletion
3209 -- If so, set the l_unique_flag to false to prevent duplicates
3210 FOR j IN l_Ship_ID_Tbl.FIRST..l_Ship_ID_Tbl.LAST LOOP
3211 IF(l_Ship_ID_Tbl(j) = p_del_cancel_so_lines_tbl(i).oe_return_line_id) THEN
3212 l_unique_flag := FALSE;
3213 EXIT;
3214 END IF;
3215 END LOOP;
3216 END IF;
3217 IF(l_unique_flag) THEN
3218 -- Not a duplicate
3219 -- Check if there are any active OSP Lines for this Return Shipment
3220 OPEN can_del_return_line_csr(p_del_cancel_so_lines_tbl(i).osp_order_id,p_del_cancel_so_lines_tbl(i).oe_return_line_id);
3221 FETCH can_del_return_line_csr INTO l_exist;
3222 IF(can_del_return_line_csr%NOTFOUND) THEN
3223 -- No other active OSP Line for this Return shipment
3224 -- Check if the shipment has already occured
3225 OPEN line_already_shipped_csr(p_del_cancel_so_lines_tbl(i).oe_return_line_id);
3226 FETCH line_already_shipped_csr INTO l_exist;
3227 IF (line_already_shipped_csr%NOTFOUND) THEN
3228 -- Line not yet shipped: Include for deletion
3229 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3230 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'Return Shipment line with id ' || p_del_cancel_so_lines_tbl(i).oe_return_line_id || ' included for deletion/cancellation.');
3231 END IF;
3232 l_Ship_ID_Tbl(l_index) := p_del_cancel_so_lines_tbl(i).oe_return_line_id;
3233 l_index := l_index + 1;
3234 END IF;
3235 CLOSE line_already_shipped_csr;
3236 END IF;
3237 CLOSE can_del_return_line_csr;
3238 END IF;
3239 END IF;
3240 END LOOP;
3241 -- CALL SO API with consolidated list of line IDs
3242 IF(l_Ship_ID_Tbl.COUNT > 0) THEN
3243 -- CALL SO to delete/cancel SO
3244 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3245 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'Calling AHL_OSP_SHIPMENT_PUB.Delete_Cancel_Order with l_Ship_ID_Tbl.COUNT = ' || l_Ship_ID_Tbl.COUNT);
3246 END IF;
3247 AHL_OSP_SHIPMENT_PUB.Delete_Cancel_Order (
3248 p_api_version => 1.0,
3249 p_oe_header_id => NULL,
3250 p_oe_lines_tbl => l_Ship_ID_Tbl,
3251 p_cancel_flag => p_cancel_flag,
3252 x_return_status => l_return_status ,
3253 x_msg_count => l_msg_count ,
3254 x_msg_data => l_msg_data
3255 );
3256 IF(l_return_status <> FND_API.G_RET_STS_SUCCESS)THEN
3257 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_SO_LN_CAN_FLD');
3258 FND_MSG_PUB.ADD;
3259 END IF;
3260 END IF;
3261 END IF;
3262 IF FND_MSG_PUB.count_msg > 0 THEN
3263 RAISE FND_API.G_EXC_ERROR;
3264 -- RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3265 END IF;
3266 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3267 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
3268 END IF;
3269 END delete_cancel_so;
3270
3271 -----------------------------------------------------------------------------------------------------
3272 FUNCTION can_convert_order(p_osp_order_id IN NUMBER,
3273 p_old_type_code IN VARCHAR2,
3274 p_new_type_code IN VARCHAR2
3275 --p_new_order_rec IN AHL_OSP_ORDERS_PVT.osp_order_rec_type,
3276 --p_old_order_rec IN AHL_OSP_ORDERS_PVT.osp_order_rec_type
3277 ) RETURN BOOLEAN IS
3278 CURSOR order_has_ship_return_csr(p_osp_order_id IN NUMBER) IS
3279 SELECT 'x' FROM ahl_osp_order_lines ol --, oe_order_lines_all oel
3280 WHERE ol.osp_order_id = p_osp_order_id
3281 AND ol.oe_return_line_id IS NOT NULL; --= oel.line_id;
3282 CURSOR order_header_status_csr(p_osp_order_id IN NUMBER) IS
3283 SELECT status_code FROM ahl_osp_orders_b
3284 WHERE osp_order_id = p_osp_order_id;
3285 l_exist VARCHAR(1);
3286 l_status_code VARCHAR(30);
3287 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.CAN_CONVERT_ORDER';
3288 BEGIN
3289 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3290 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Function');
3291 END IF;
3292 IF(p_old_type_code NOT IN (G_OSP_ORDER_TYPE_SERVICE, G_OSP_ORDER_TYPE_EXCHANGE)) THEN
3293 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_CONV_FR_TYPE');
3294 FND_MSG_PUB.ADD;
3295 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3296 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY ||'.error', 'Cannot Convert from Order Type is not Service or Exchange');
3297 END IF;
3298 return false;
3299 END IF;
3300 IF(p_new_type_code NOT IN (G_OSP_ORDER_TYPE_SERVICE, G_OSP_ORDER_TYPE_EXCHANGE)) THEN
3301 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_CONV_TO_TYPE');
3302 FND_MSG_PUB.ADD;
3303 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3304 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY ||'.error', 'Cannot Convert to an order that is not of type Service or Exchange');
3305 END IF;
3306 return false;
3307 END IF;
3308 -- check if the order is closed
3309 OPEN order_header_status_csr(p_osp_order_id);
3310 FETCH order_header_status_csr INTO l_status_code;
3311 IF(l_status_code = G_OSP_CLOSED_STATUS) THEN
3312 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_CONV_CLOSED');
3313 FND_MSG_PUB.ADD;
3314 CLOSE order_header_status_csr;
3315 return false;
3316 END IF;
3317 CLOSE order_header_status_csr;
3318 --mpothuku commented on 10-Feb-2007 to implment the Osp Receiving ER. Conversion is enhanced to cancel the return lines in the back ground.
3319 --We do not need this check any more.
3320 /*
3321 OPEN order_has_ship_return_csr(p_osp_order_id);
3322 FETCH order_has_ship_return_csr INTO l_exist;
3323 IF( order_has_ship_return_csr %FOUND) THEN
3324 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INV_CONV_HAS_RET_LINE');
3325 FND_MSG_PUB.ADD;
3326 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3327 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY ||'.error', 'can_convert: Cannot Convert. Order has shipment return line');
3328 END IF;
3329 CLOSE order_has_ship_return_csr;
3330 return false;
3331 END IF;
3332 CLOSE order_has_ship_return_csr;
3333 */
3334 --mpothuku End
3335 RETURN true;
3336 END can_convert_order;
3337
3338 ------------------------------------------------------------------------------------------------------
3339 FUNCTION vendor_id_exist_in_PO( p_po_header_id IN NUMBER,
3340 p_vendor_id IN NUMBER
3341 ) RETURN BOOLEAN IS
3342 CURSOR vendor_id_csr(p_po_header_id IN NUMBER, p_vendor_id IN NUMBER) IS
3343 SELECT 'x' FROM po_headers_all
3344 WHERE po_header_id = p_po_header_id
3345 AND vendor_id = p_vendor_id;
3346 l_exist VARCHAR(1);
3347 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.vendor_id_exist_in_PO';
3348 BEGIN
3349 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3350 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Function - '
3351 || 'p_po_header_id: ' || p_po_header_id || ' p_vendor_id: ' || p_vendor_id);
3352 END IF;
3353 IF(p_po_header_id IS NOT NULL AND p_po_header_id <> FND_API.G_MISS_NUM
3354 AND p_vendor_id IS NOT NULL AND p_vendor_id <> FND_API.G_MISS_NUM) THEN
3355 OPEN vendor_id_csr(p_po_header_id, p_vendor_id);
3356 FETCH vendor_id_csr INTO l_exist;
3357 IF(vendor_id_csr %FOUND) THEN
3358 CLOSE vendor_id_csr;
3359 RETURN true;
3360 END IF;
3361 CLOSE vendor_id_csr;
3362 END IF;
3363 RETURN false;
3364 END vendor_id_exist_in_PO;
3365
3366 --------------------------------------------------------------------------------------------------------------
3367 FUNCTION vendor_site_id_exist_in_PO( p_po_header_id IN NUMBER,
3368 p_vendor_site_id IN NUMBER
3369 ) RETURN BOOLEAN IS
3370 CURSOR vendor_site_id_csr(p_po_header_id IN NUMBER, p_vendor_site_id IN NUMBER) IS
3371 SELECT 'x' FROM po_headers_all
3372 WHERE po_header_id = p_po_header_id
3373 AND vendor_site_id = p_vendor_site_id;
3374 l_exist VARCHAR(1);
3375 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.vendor_site_id_exist_in_PO';
3376 BEGIN
3377 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3378 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Function - '
3379 || 'p_po_header_id: ' || p_po_header_id || ' p_vendor_site_id: ' || p_vendor_site_id);
3380 END IF;
3381 IF(p_po_header_id IS NOT NULL AND p_po_header_id <> FND_API.G_MISS_NUM
3382 AND p_vendor_site_id IS NOT NULL AND p_vendor_site_id <> FND_API.G_MISS_NUM) THEN
3383 OPEN vendor_site_id_csr(p_po_header_id, p_vendor_site_id);
3384 FETCH vendor_site_id_csr INTO l_exist;
3385 IF(vendor_site_id_csr %FOUND) THEN
3386 CLOSE vendor_site_id_csr;
3387 RETURN true;
3388 END IF;
3389 CLOSE vendor_site_id_csr;
3390 END IF;
3391 RETURN false;
3392 END vendor_site_id_exist_in_PO;
3393
3394 ---------------------------------------------------------------------------
3395 --This is the main API for processing Inventory Service Orders including work order based.
3396 --It handles OSP order header Creation, Update, and Deletion, order lines Creation, Update
3397 --and Deletion.
3398 PROCEDURE process_osp_order(
3399 p_api_version IN NUMBER := 1.0,
3400 p_init_msg_list IN VARCHAR2 := FND_API.G_TRUE,
3401 p_commit IN VARCHAR2 := FND_API.G_FALSE,
3402 p_validation_level IN NUMBER := FND_API.G_VALID_LEVEL_FULL,
3403 p_module_type IN VARCHAR2 := NULL,
3404 p_x_osp_order_rec IN OUT NOCOPY osp_order_rec_type,
3405 p_x_osp_order_lines_tbl IN OUT NOCOPY osp_order_lines_tbl_type,
3406 x_return_status OUT NOCOPY VARCHAR2,
3407 x_msg_count OUT NOCOPY NUMBER,
3408 x_msg_data OUT NOCOPY VARCHAR2)
3409 IS
3410 l_api_name CONSTANT VARCHAR2(30) := 'process_osp_order';
3411 l_api_version CONSTANT NUMBER := 1.0;
3412 l_return_status VARCHAR2(1);
3413 l_msg_count NUMBER;
3414 l_msg_data VARCHAR2(2000);
3415 l_del_cancel_so_lines_tbl del_cancel_so_lines_tbl_type;
3416 l_dummy_dc_so_lines_tbl del_cancel_so_lines_tbl_type;
3417 l_osp_order_id NUMBER;
3418 l_oe_ship_line_id NUMBER;
3419 l_oe_return_line_id NUMBER;
3420 l_oe_header_id NUMBER;
3421 l_status_code VARCHAR2(30);
3422 l_vendor_validate_flag BOOLEAN := FALSE;
3423 l_validate_pass_flag BOOLEAN := FALSE;
3424 l_first_index NUMBER;
3425 l_valid_vendors_tbl vendor_id_tbl_type;
3426 l_any_vendor_flag VARCHAR2(1);
3427 l_header_vendor_id NUMBER;
3428 l_header_site_id NUMBER;
3429 i NUMBER;
3430 CURSOR get_order_lines(c_osp_order_id NUMBER) IS
3431 SELECT osp_order_line_id
3432 FROM ahl_osp_order_lines
3433 WHERE osp_order_id = c_osp_order_id;
3434 BEGIN
3435 --Initialize API return status to success
3436 x_return_status := FND_API.G_RET_STS_SUCCESS;
3437
3438 --Standard Start of API savepoint
3439 SAVEPOINT process_osp_order;
3440
3441 --Standard call to check for call compatibility.
3442 IF NOT FND_API.compatible_api_call(
3443 l_api_version,
3444 p_api_version,
3445 l_api_name,
3446 G_PKG_NAME)
3447 THEN
3448 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3449 END IF;
3450
3451 --Initialize message list if p_init_msg_list is set to TRUE.
3452 IF FND_API.to_boolean(p_init_msg_list) THEN
3453 FND_MSG_PUB.initialize;
3454 END IF;
3455
3456 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3457 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
3458 G_LOG_PREFIX||l_api_name, --module
3459 'The main API Begin: and header operation_flag='||p_x_osp_order_rec.operation_flag); --message_text
3460 END IF;
3461
3462 --Validate the operation_flag of the header record, and it could be NULL which
3463 --means no change to the header record
3464 IF (p_x_osp_order_rec.operation_flag IS NOT NULL AND
3465 p_x_osp_order_rec.operation_flag NOT IN (G_OP_CREATE, G_OP_UPDATE, G_OP_DELETE)) THEN
3466 FND_MESSAGE.set_name('AHL', 'AHL_OSP_ORD_INVOP');
3467 FND_MSG_PUB.add;
3468 RAISE FND_API.G_EXC_ERROR;
3469 END IF;
3470 --Validate the operation_flag of the line records and it couldn't be NULL
3471 --In case only header record is to be processed, then NULL is supposed to be passed
3472 --to the lines table
3473 IF (p_x_osp_order_lines_tbl.COUNT > 0) THEN
3474 FOR i IN p_x_osp_order_lines_tbl.FIRST..p_x_osp_order_lines_tbl.LAST LOOP
3475 IF (p_x_osp_order_lines_tbl(i).operation_flag NOT IN (G_OP_CREATE, G_OP_UPDATE, G_OP_DELETE)) THEN
3476 FND_MESSAGE.set_name('AHL', 'AHL_OSP_ORD_INVOP');
3477 FND_MSG_PUB.add;
3478 RAISE FND_API.G_EXC_ERROR;
3479 END IF;
3480 END LOOP;
3481 END IF;
3482
3483 --Set the global variable g_module_type
3484 g_module_type := p_module_type;
3485
3486 /* Customer pre-processing section, Mandatory */
3487
3488 IF (JTF_USR_HKS.Ok_to_execute('AHL_OSP_ORDERS_PVT', 'PROCESS_OSP_ORDER', 'B', 'C' )) then
3489 ahl_osp_orders_CUHK.process_osp_order_pre(
3490 p_osp_order_rec => p_x_osp_order_rec,
3491 p_osp_order_lines_tbl => p_x_osp_order_lines_tbl,
3492 x_msg_count => l_msg_count,
3493 x_msg_data => l_msg_data,
3494 x_return_status => l_return_status);
3495 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
3496 RAISE FND_API.G_EXC_ERROR;
3497 ELSIF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
3498 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3499 END IF;
3500 END IF;
3501
3502 IF (p_x_osp_order_rec.operation_flag IS NULL) THEN
3503 IF (FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3504 FND_LOG.STRING(FND_LOG.LEVEL_EVENT,
3505 G_LOG_PREFIX||l_api_name, --module
3506 'Within API: No change to OSP header, just for lines');
3507 END IF;
3508 --No change to the header record and only to the line records
3509 IF (p_x_osp_order_lines_tbl.COUNT > 0) THEN
3510 FOR i IN p_x_osp_order_lines_tbl.FIRST..p_x_osp_order_lines_tbl.LAST LOOP
3511 IF (p_x_osp_order_lines_tbl(i).operation_flag = G_OP_DELETE) THEN
3512 --Front end just passes osp_order_line_id and operation_flag
3513 BEGIN
3514 SELECT osp_order_id, oe_ship_line_id, oe_return_line_id
3515 INTO l_osp_order_id, l_oe_ship_line_id, l_oe_return_line_id
3516 FROM ahl_osp_order_lines
3517 WHERE osp_order_line_id = p_x_osp_order_lines_tbl(i).osp_order_line_id;
3518
3519 SELECT status_code, oe_header_id INTO l_status_code, l_oe_header_id
3520 FROM ahl_osp_orders_b
3521 WHERE osp_order_id = l_osp_order_id;
3522 EXCEPTION
3523 WHEN NO_DATA_FOUND THEN
3524 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_ID_LN_INV');
3525 FND_MESSAGE.Set_Token('OSP_LINE_ID',p_x_osp_order_lines_tbl(i).osp_order_line_id);
3526 FND_MSG_PUB.ADD;
3527 RAISE FND_API.G_EXC_ERROR;
3528 END;
3529 -- Added by jaramana on January 9, 2008 for the Requisition ER 6034236
3530 IF (l_status_code IN (G_OSP_ENTERED_STATUS, G_OSP_SUB_FAILED_STATUS, G_OSP_REQ_SUB_FAILED_STATUS)) THEN
3531 -- jaramana End
3532 IF (l_oe_ship_line_id IS NOT NULL OR l_oe_return_line_id IS NOT NULL) THEN
3533 l_del_cancel_so_lines_tbl(1).osp_order_id := l_osp_order_id;
3534 l_del_cancel_so_lines_tbl(1).oe_ship_line_id := l_oe_ship_line_id;
3535 l_del_cancel_so_lines_tbl(1).oe_return_line_id := l_oe_return_line_id;
3536 END IF;
3537
3538 --Delete OSP line record first (it makes more sense to delete shipment lines first, but
3539 --here just keep it the same as the old logic).
3540 AHL_OSP_ORDER_LINES_PKG.delete_row(p_x_osp_order_lines_tbl(i).osp_order_line_id);
3541
3542 --Delete or cancel shipment lines
3543 delete_cancel_so(
3544 p_oe_header_id => NULL,
3545 p_del_cancel_so_lines_tbl => l_del_cancel_so_lines_tbl);
3546 ELSE
3547 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INVOP');
3548 FND_MSG_PUB.ADD;
3549 RAISE FND_API.G_EXC_ERROR;
3550 END IF;
3551 ELSIF (p_x_osp_order_lines_tbl(i).operation_flag = G_OP_CREATE) THEN
3552 --Create(Add) new line record
3553 create_osp_order_line(p_x_osp_order_lines_tbl(i));
3554 --Create shipment at the same time if the flag is checked
3555 --Removed to the out loop for performance gain
3556 --IF (p_x_osp_order_lines_tbl(i).shipment_creation_flag = 'Y') THEN
3557 --create_shipment(p_x_osp_order_lines_tbl(i));
3558 --END IF;
3559 ELSIF (p_x_osp_order_lines_tbl(i).operation_flag = G_OP_UPDATE) THEN
3560 --Update line record
3561 update_osp_order_line(p_x_osp_order_lines_tbl(i));
3562 END IF;
3563 END LOOP;
3564
3565 --To check whether it is necessary to do a post vendor/items combination validation
3566 --after the records were inserted into or updated from the database
3567 FOR i IN p_x_osp_order_lines_tbl.FIRST..p_x_osp_order_lines_tbl.LAST LOOP
3568 -- Modified by jaramana on January 9, 2008 to not do this Vendor check if the line is PO Cancelled or PO Deleted
3569 IF p_x_osp_order_lines_tbl(i).operation_flag <> G_OP_DELETE AND
3570 (NVL(p_x_osp_order_lines_tbl(i).status_code, 'ENTERED') NOT IN (G_OL_PO_CANCELLED_STATUS, G_OL_PO_DELETED_STATUS)) THEN
3571 l_vendor_validate_flag := TRUE;
3572 EXIT;
3573 END IF;
3574 END LOOP;
3575 IF l_vendor_validate_flag THEN
3576 --Needs to do the post vendor/items combination validation
3577 l_first_index := p_x_osp_order_lines_tbl.FIRST;
3578 derive_common_vendors(p_x_osp_order_lines_tbl(l_first_index).osp_order_id,
3579 l_valid_vendors_tbl,
3580 l_any_vendor_flag);
3581 IF l_any_vendor_flag <> 'Y' THEN
3582 BEGIN
3583 SELECT vendor_id, vendor_site_id INTO l_header_vendor_id, l_header_site_id
3584 FROM ahl_osp_orders_b
3585 WHERE osp_order_id = p_x_osp_order_lines_tbl(l_first_index).osp_order_id;
3586 EXCEPTION
3587 WHEN NO_DATA_FOUND THEN
3588 FND_MESSAGE.set_name('AHL', 'AHL_OSP_ORD_INVALID');
3589 FND_MSG_PUB.add;
3590 RAISE FND_API.G_EXC_ERROR;
3591 END;
3592
3593 IF l_valid_vendors_tbl.count > 0 THEN
3594 IF (l_header_vendor_id IS NULL OR l_header_site_id IS NULL) THEN
3595 l_validate_pass_flag := TRUE;
3596 ELSE
3597 FOR i IN l_valid_vendors_tbl.FIRST..l_valid_vendors_tbl.LAST LOOP
3598 IF (l_header_vendor_id = l_valid_vendors_tbl(i).vendor_id AND
3599 l_header_site_id = l_valid_vendors_tbl(i).vendor_site_id) THEN
3600 l_validate_pass_flag := TRUE;
3601 EXIT;
3602 END IF;
3603 END LOOP;
3604 END IF;
3605 IF NOT l_validate_pass_flag THEN
3606 FND_MESSAGE.set_name('AHL', 'AHL_OSP_ITEM_VENDOR_MISMATCH');
3607 FND_MSG_PUB.add;
3608 RAISE FND_API.G_EXC_ERROR;
3609 END IF;
3610 ELSE
3611 FND_MESSAGE.set_name('AHL', 'AHL_OSP_ITEM_VENDOR_MISMATCH');
3612 FND_MSG_PUB.add;
3613 RAISE FND_API.G_EXC_ERROR;
3614 END IF;
3615 END IF;
3616 END IF;
3617 --Call create_shipment. Create_shipment will check whether it will create
3618 --shipment or not(if the operation is not Create and no shipment_creation_flag
3619 --is checked, it will do nothing)
3620 create_shipment(p_x_osp_order_lines_tbl);
3621 END IF;
3622 ELSIF (p_x_osp_order_rec.operation_flag = G_OP_DELETE) THEN
3623 IF (FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3624 FND_LOG.STRING(FND_LOG.LEVEL_EVENT,
3625 G_LOG_PREFIX||l_api_name, --module
3626 'Within API: Delete OSP Header/Lines');
3627 END IF;
3628 --Front end just passes the osp_order_id
3629 BEGIN
3630 SELECT status_code, oe_header_id INTO l_status_code, l_oe_header_id
3631 FROM ahl_osp_orders_b
3632 WHERE osp_order_id = p_x_osp_order_rec.osp_order_id;
3633 EXCEPTION
3634 WHEN NO_DATA_FOUND THEN
3635 FND_MESSAGE.set_name('AHL', 'AHL_OSP_ORD_INVALID');
3636 FND_MSG_PUB.add;
3637 RAISE FND_API.G_EXC_ERROR;
3638 END;
3639 --check the osp order could be deleted, if Yes then
3640 --Delete OSP order Header/Line records
3641 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3642 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
3643 G_LOG_PREFIX||l_api_name,
3644 'Before deletion and status='||l_status_code||' oe_header='||l_oe_header_id);
3645 END IF;
3646 -- Added by jaramana on January 9, 2008 for the Requisition ER 6034236
3647 IF(l_status_code IN (G_OSP_ENTERED_STATUS, G_OSP_SUB_FAILED_STATUS, G_OSP_REQ_SUB_FAILED_STATUS)) THEN
3648 -- jaramana End
3649 IF (l_oe_header_id IS NOT NULL) THEN
3650 -- calling to delete SO HEADER
3651 -- Here needs to populate the l_del_cancel_so_lines_tbl
3652 i := 1;
3653 FOR l_get_order_lines IN get_order_lines(p_x_osp_order_rec.osp_order_id) LOOP
3654 BEGIN
3655 SELECT oe_ship_line_id, oe_return_line_id
3656 INTO l_oe_ship_line_id, l_oe_return_line_id
3657 FROM ahl_osp_order_lines
3658 WHERE osp_order_line_id = l_get_order_lines.osp_order_line_id;
3659 EXCEPTION
3660 WHEN NO_DATA_FOUND THEN
3661 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_ID_LN_INV');
3662 FND_MESSAGE.Set_Token('OSP_LINE_ID',l_get_order_lines.osp_order_line_id);
3663 FND_MSG_PUB.ADD;
3664 RAISE FND_API.G_EXC_ERROR;
3665 END;
3666 IF (l_oe_ship_line_id IS NOT NULL OR l_oe_return_line_id IS NOT NULL) THEN
3667 l_del_cancel_so_lines_tbl(i).osp_order_id := p_x_osp_order_rec.osp_order_id;
3668 l_del_cancel_so_lines_tbl(i).oe_ship_line_id := l_oe_ship_line_id;
3669 l_del_cancel_so_lines_tbl(i).oe_return_line_id := l_oe_return_line_id;
3670 i := i+1;
3671 END IF;
3672 END LOOP;
3673 IF (FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3674 FND_LOG.STRING(FND_LOG.LEVEL_EVENT,
3675 G_LOG_PREFIX||l_api_name,
3676 'Before calling: delete_cancel_so and table_count='||to_char(i-1));
3677 END IF;
3678 --Delete Shipment header/lines
3679 delete_cancel_so(
3680 p_oe_header_id => l_oe_header_id,
3681 p_del_cancel_so_lines_tbl => l_dummy_dc_so_lines_tbl);
3682 END IF;
3683
3684 --Delete OSP order lines
3685 FOR l_get_order_lines IN get_order_lines(p_x_osp_order_rec.osp_order_id) LOOP
3686 AHL_OSP_ORDER_LINES_PKG.delete_row(l_get_order_lines.osp_order_line_id);
3687 END LOOP;
3688
3689 --Delete OSP order header record
3690 AHL_OSP_ORDERS_PKG.delete_row(x_osp_order_id => p_x_osp_order_rec.osp_order_id);
3691 IF (FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3692 FND_LOG.STRING(FND_LOG.LEVEL_EVENT,
3693 G_LOG_PREFIX||l_api_name,
3694 'After deleting header.');
3695 END IF;
3696 ELSE
3697 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INVOP');
3698 FND_MSG_PUB.ADD;
3699 RAISE FND_API.G_EXC_ERROR;
3700 END IF;
3701 ELSIF (p_x_osp_order_rec.operation_flag = G_OP_UPDATE) THEN
3702 IF (FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3703 FND_LOG.STRING(FND_LOG.LEVEL_EVENT,
3704 G_LOG_PREFIX||l_api_name, --module
3705 'Within API: Update OSP Header/Lines');
3706 END IF;
3707 -- Validate and update header record
3708 -- Handling if order status is to be changed
3709 --process_order_status_change(p_x_osp_order_rec);
3710 -- Handling if order type is to be changed
3711 --process_order_type_change(p_x_osp_order_rec);
3712 --Just update the Header record first
3713 update_osp_order_header(p_x_osp_order_rec);
3714 IF (p_x_osp_order_lines_tbl IS NOT NULL AND p_x_osp_order_lines_tbl.COUNT > 0) THEN
3715 FOR i IN p_x_osp_order_lines_tbl.FIRST..p_x_osp_order_lines_tbl.LAST LOOP
3716 IF (p_x_osp_order_lines_tbl(i).operation_flag = G_OP_DELETE) THEN
3717 --Front end just passes osp_order_line_id and operation_flag
3718 BEGIN
3719 SELECT osp_order_id, oe_ship_line_id, oe_return_line_id
3720 INTO l_osp_order_id, l_oe_ship_line_id, l_oe_return_line_id
3721 FROM ahl_osp_order_lines
3722 WHERE osp_order_line_id = p_x_osp_order_lines_tbl(i).osp_order_line_id;
3723
3724 SELECT status_code, oe_header_id INTO l_status_code, l_oe_header_id
3725 FROM ahl_osp_orders_b
3726 WHERE osp_order_id = l_osp_order_id;
3727 EXCEPTION
3728 WHEN NO_DATA_FOUND THEN
3729 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_ID_LN_INV');
3730 FND_MESSAGE.Set_Token('OSP_LINE_ID',p_x_osp_order_lines_tbl(i).osp_order_line_id);
3731 FND_MSG_PUB.ADD;
3732 RAISE FND_API.G_EXC_ERROR;
3733 END;
3734 -- Added by jaramana on January 9, 2008 for the Requisition ER 6034236
3735 IF (l_status_code IN (G_OSP_ENTERED_STATUS, G_OSP_SUB_FAILED_STATUS, G_OSP_REQ_SUB_FAILED_STATUS)) THEN
3736 -- jaramana End
3737 IF (p_x_osp_order_lines_tbl(i).oe_ship_line_id IS NOT NULL OR
3738 p_x_osp_order_lines_tbl(i).oe_return_line_id IS NOT NULL) THEN
3739 l_del_cancel_so_lines_tbl(1).osp_order_id := l_osp_order_id;
3740 l_del_cancel_so_lines_tbl(1).oe_ship_line_id := l_oe_ship_line_id;
3741 l_del_cancel_so_lines_tbl(1).oe_return_line_id := l_oe_return_line_id;
3742 END IF;
3743
3744 --Delete line record first (it makes more sense to delete shipment lines first, but
3745 --here just keep it the same as the old logic.
3746 AHL_OSP_ORDER_LINES_PKG.delete_row(p_x_osp_order_lines_tbl(i).osp_order_line_id);
3747 --Delete or cancel Shipment lines
3748 delete_cancel_so(
3749 p_oe_header_id => NULL,
3750 p_del_cancel_so_lines_tbl => l_del_cancel_so_lines_tbl);
3751 ELSE
3752 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INVOP');
3753 FND_MSG_PUB.ADD;
3754 RAISE FND_API.G_EXC_ERROR;
3755 END IF;
3756 --AHL_OSP_ORDER_LINES_PKG.delete_row(p_x_osp_order_lines_tbl(i).osp_order_line_id);
3757 ELSIF (p_x_osp_order_lines_tbl(i).operation_flag = G_OP_UPDATE) THEN
3758 --update osp order line
3759 update_osp_order_line(p_x_osp_order_lines_tbl(i));
3760 ELSIF (p_x_osp_order_lines_tbl(i).operation_flag = G_OP_CREATE) THEN
3761 --Add new osp order line
3762 create_osp_order_line(p_x_osp_order_lines_tbl(i));
3763 -- Moved out of the loop for performance gain
3764 --IF (p_x_osp_order_lines_tbl(i).shipment_creation_flag = 'Y') THEN
3765 --create_shipment(p_x_osp_order_lines_tbl(i));
3766 --END IF;
3767 END IF;
3768 END LOOP;
3769
3770 --Call create_shipment. Create_shipment will check whether it will create
3771 --shipment or not(if the operation is not Create and no shipment_creation_flag
3772 --is checked, it will do nothing)
3773 create_shipment(p_x_osp_order_lines_tbl);
3774 END IF;
3775
3776 --To check whether it is necessary to do a post vendor/items combination validation
3777 --after the records were inserted into or updated from the database
3778 derive_common_vendors(p_x_osp_order_rec.osp_order_id,
3779 l_valid_vendors_tbl,
3780 l_any_vendor_flag);
3781 BEGIN
3782 SELECT vendor_id, vendor_site_id INTO l_header_vendor_id, l_header_site_id
3783 FROM ahl_osp_orders_b
3784 WHERE osp_order_id = p_x_osp_order_rec.osp_order_id;
3785 EXCEPTION
3786 WHEN NO_DATA_FOUND THEN
3787 FND_MESSAGE.set_name('AHL', 'AHL_OSP_ORD_INVALID');
3788 FND_MSG_PUB.add;
3789 RAISE FND_API.G_EXC_ERROR;
3790 END;
3791 IF l_any_vendor_flag <> 'Y' THEN
3792 IF l_valid_vendors_tbl.count > 0 THEN
3793 IF (l_header_vendor_id IS NULL OR l_header_site_id IS NULL) THEN
3794 l_validate_pass_flag := TRUE;
3795 ELSE
3796 FOR i IN l_valid_vendors_tbl.FIRST..l_valid_vendors_tbl.LAST LOOP
3797 IF (l_header_vendor_id = l_valid_vendors_tbl(i).vendor_id AND
3798 l_header_site_id = l_valid_vendors_tbl(i).vendor_site_id) THEN
3799 l_validate_pass_flag := TRUE;
3800 EXIT;
3801 END IF;
3802 END LOOP;
3803 END IF;
3804 IF NOT l_validate_pass_flag THEN
3805 FND_MESSAGE.set_name('AHL', 'AHL_OSP_ITEM_VENDOR_MISMATCH');
3806 FND_MSG_PUB.add;
3807 RAISE FND_API.G_EXC_ERROR;
3808 END IF;
3809 ELSE
3810 FND_MESSAGE.set_name('AHL', 'AHL_OSP_ITEM_VENDOR_MISMATCH');
3811 FND_MSG_PUB.add;
3812 RAISE FND_API.G_EXC_ERROR;
3813 END IF;
3814 END IF;
3815 ELSIF (p_x_osp_order_rec.operation_flag = G_OP_CREATE) THEN
3816 --Validate new line records first because in header record only one attribute needs validation
3817 --but it needs line records to derive vendor attributes.
3818 --
3819 --Default the attributes of header record and create OSP order header record
3820 IF (FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3821 FND_LOG.STRING(FND_LOG.LEVEL_EVENT,
3822 G_LOG_PREFIX||l_api_name,
3823 'OSP order header/Lines creation and lines count='||p_x_osp_order_lines_tbl.Count||
3824 'osp_order_id='||p_x_osp_order_rec.osp_order_id);
3825 END IF;
3826 create_osp_order_header(p_x_osp_order_rec, p_x_osp_order_lines_tbl);
3827 IF (p_x_osp_order_lines_tbl IS NOT NULL AND p_x_osp_order_lines_tbl.COUNT > 0) THEN
3828 FOR i IN p_x_osp_order_lines_tbl.FIRST..p_x_osp_order_lines_tbl.LAST LOOP
3829 --Create OSP order line records
3830 --p_x_osp_order_lines_tbl(i).osp_order_id := p_x_osp_order_rec.osp_order_id;
3831 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3832 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
3833 G_LOG_PREFIX||l_api_name,
3834 'Within the API and i='||i||'workorder_id='||p_x_osp_order_lines_tbl(i).workorder_id||
3835 'First='||p_x_osp_order_lines_tbl.FIRST||'Last='||p_x_osp_order_lines_tbl.LAST||
3836 'Count='||p_x_osp_order_lines_tbl.Count);
3837 END IF;
3838 p_x_osp_order_lines_tbl(i).osp_order_id := p_x_osp_order_rec.osp_order_id;
3839 create_osp_order_line(p_x_osp_order_lines_tbl(i));
3840 -- Moved out of the loop for performance gain
3841 --IF (p_x_osp_order_lines_tbl(i).shipment_creation_flag = 'Y') THEN
3842 --create_shipment(p_x_osp_order_lines_tbl(i));
3843 --END IF;
3844 END LOOP;
3845 --Call create_shipment. Create_shipment will check whether it will create
3846 --shipment or not(if the operation is not Create and no shipment_creation_flag
3847 --is checked, it will do nothing)
3848 create_shipment(p_x_osp_order_lines_tbl);
3849 END IF;
3850 END IF;
3851
3852 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3853 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
3854 G_LOG_PREFIX||l_api_name,
3855 'API End: at the end of the procedure');
3856 END IF;
3857
3858 /* Customer Post Processing section - mandatory */
3859 IF (JTF_USR_HKS.Ok_to_execute('AHL_OSP_ORDERS_PVT', 'PROCESS_OSP_ORDER', 'A', 'C' )) then
3860 ahl_osp_orders_CUHK. process_osp_order_Post(
3861 p_osp_order_rec => p_x_osp_order_rec,
3862 p_osp_order_lines_tbl => p_x_osp_order_lines_tbl,
3863 x_msg_count => l_msg_count,
3864 x_msg_data => l_msg_data,
3865 x_return_status => l_return_status);
3866 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
3867 RAISE FND_API.G_EXC_ERROR;
3868 ELSIF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
3869 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3870 END IF;
3871 END IF;
3872
3873 -- Get all the error messages from the previous steps (if any) and raise the appropriate Exception
3874 l_msg_count := FND_MSG_PUB.count_msg;
3875 IF l_msg_count > 0 THEN
3876 x_msg_count := l_msg_count;
3877 RAISE FND_API.G_EXC_ERROR;
3878 END IF;
3879
3880 -- Perform the Commit (if requested)
3881 IF FND_API.to_boolean(p_commit) THEN
3882 COMMIT;
3883 END IF;
3884
3885 -- Count and Get messages (optional)
3886 FND_MSG_PUB.count_and_get(
3887 p_encoded => FND_API.G_FALSE,
3888 p_count => x_msg_count,
3889 p_data => x_msg_data);
3890
3891 EXCEPTION
3892 WHEN FND_API.G_EXC_ERROR THEN
3893 ROLLBACK TO process_osp_order;
3894 x_return_status := FND_API.G_RET_STS_ERROR;
3895 FND_MSG_PUB.count_and_get(
3896 p_encoded => FND_API.G_FALSE,
3897 p_count => x_msg_count,
3898 p_data => x_msg_data);
3899
3900 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3901 ROLLBACK TO process_osp_order;
3902 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3903 FND_MSG_PUB.count_and_get(
3904 p_encoded => FND_API.G_FALSE,
3905 p_count => x_msg_count,
3906 p_data => x_msg_data);
3907
3908 WHEN OTHERS THEN
3909 ROLLBACK TO process_osp_order;
3910 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3911 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3912 THEN
3913 FND_MSG_PUB.add_exc_msg(
3914 p_pkg_name => G_PKG_NAME,
3915 p_procedure_name => l_api_name,
3916 p_error_text => SUBSTRB(SQLERRM,1,240));
3917 END IF;
3918 FND_MSG_PUB.count_and_get(
3919 p_encoded => FND_API.G_FALSE,
3920 p_count => x_msg_count,
3921 p_data => x_msg_data);
3922 END process_osp_order;
3923
3924 -- create_osp_order_header Procedure revamped by jaramana on May 9, 2006 for Bug 5215894
3925 -- to make the process_osp_order API conform to Oracle Apps Public API Standards
3926 -- in the create mode also.
3927 -- 1. Perform Value to Id conversions
3928 -- 2. Honor the input values/Ids passed
3929 -- 3. Validate the Ids passed or derived
3930 PROCEDURE create_osp_order_header(p_x_osp_order_rec IN OUT NOCOPY osp_order_rec_type,
3931 p_x_osp_order_lines_tbl IN OUT NOCOPY osp_order_lines_tbl_type)
3932 IS
3933 l_operating_unit_id NUMBER;
3934 l_osp_order_id NUMBER;
3935 l_osp_order_number NUMBER;
3936 l_item_service_rels_tbl item_service_rels_tbl_type;
3937 l_vendor_id NUMBER;
3938 l_vendor_site_id NUMBER;
3939 l_vendor_contact_id NUMBER;
3940 l_return_status VARCHAR2(1);
3941 l_organization_id NUMBER;
3942 l_inventory_item_id NUMBER;
3943 l_service_item_id NUMBER;
3944 l_rowid_dummy VARCHAR2(100);
3945 l_buyer_id NUMBER;
3946 l_valid_vendors_tbl vendor_id_tbl_type;
3947 l_temp_num NUMBER;
3948 l_vendor_valid_flag BOOLEAN := FALSE;
3949
3950 CURSOR get_buyer_id IS
3951 SELECT PA.buyer_id
3952 FROM po_agents_name_v PA,
3953 fnd_user FU
3954 WHERE FU.user_id = fnd_global.user_id
3955 AND PA.buyer_id = FU.employee_id;
3956 BEGIN
3957 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
3958 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
3959 G_LOG_PREFIX || 'create_osp_order_header',
3960 'Procedure begins...');
3961 END IF;
3962
3963 --Generate the primary key
3964 SELECT ahl_osp_orders_b_s.NEXTVAL
3965 INTO l_osp_order_id
3966 FROM sys.dual;
3967 --If there is no records in the table, then max(osp_order_number) IS null
3968 --SELECT NVL(MAX(osp_order_number), l_osp_order_id-1)+1
3969 -- INTO l_osp_order_number
3970 -- FROM ahl_osp_orders_b;
3971 --Finally decided to change back because the above logic will probably violate the unique
3972 --index defined on osp_order_number if two concurrent users submit the OSP Order creation at
3973 --the same time
3974 l_osp_order_number := l_osp_order_id;
3975 --Derive operating_unit_id
3976 l_operating_unit_id :=mo_global.get_current_org_id();
3977 IF (l_operating_unit_id IS NULL) THEN
3978 FND_MESSAGE.Set_Name('AHL', 'AHL_OSP_ORG_NOT_SET');
3979 FND_MSG_PUB.ADD;
3980 RAISE FND_API.G_EXC_ERROR;
3981 END IF;
3982 --Validate the only user passed parameter order_type_code
3983 IF (p_x_osp_order_rec.order_type_code IS NULL OR
3984 p_x_osp_order_rec.order_type_code NOT IN (G_OSP_ORDER_TYPE_SERVICE,
3985 G_OSP_ORDER_TYPE_EXCHANGE,
3986 G_OSP_ORDER_TYPE_BORROW)) THEN
3987 FND_MESSAGE.set_name('AHL', 'AHL_OSP_ORDER_TYPE_INVALID');
3988 FND_MSG_PUB.add;
3989 RAISE FND_API.G_EXC_ERROR;
3990 END IF;
3991
3992 -- Added by jaramana on January 10, 2008 for the Requisition ER 6034236
3993 --This API nulls out the G_MISS info, if passed by the user in the create mode.
3994 IF nvl(g_module_type, 'NULL') <> G_OAF_MODULE THEN
3995 default_unchanged_order_header(p_x_osp_order_rec);
3996 END IF;
3997 -- jaramana End
3998
3999 -- Added by jaramana on May 9, 2006 for Bug 5215894
4000 convert_order_header_val_to_id(p_x_osp_order_rec);
4001
4002 --Derive vendor related attributes
4003 IF (p_x_osp_order_lines_tbl IS NULL OR p_x_osp_order_lines_tbl.COUNT = 0) THEN
4004 l_vendor_id := NULL;
4005 l_vendor_site_id := NULL;
4006 l_vendor_contact_id := NULL;
4007 /** Added by jaramana on May 9, 2006 for Bug 5215894 **/
4008 IF (p_x_osp_order_rec.vendor_id IS NOT NULL) THEN
4009 IF (p_x_osp_order_rec.vendor_site_id IS NOT NULL) THEN
4010 IF (p_x_osp_order_rec.vendor_contact_id IS NOT NULL) THEN
4011 -- Validate the combination of vendor/site/contact
4012 validate_vendor_site_contact(p_x_osp_order_rec.vendor_id,
4013 p_x_osp_order_rec.vendor_site_id,
4014 p_x_osp_order_rec.vendor_contact_id);
4015 IF FND_MSG_PUB.count_msg > 0 THEN
4016 -- Vendor/Vendor Site/Vendor Contact is Invalid
4017 RAISE FND_API.G_EXC_ERROR;
4018 END IF;
4019 -- If valid, use the input values
4020 l_vendor_id := p_x_osp_order_rec.vendor_id;
4021 l_vendor_site_id := p_x_osp_order_rec.vendor_site_id;
4022 l_vendor_contact_id := p_x_osp_order_rec.vendor_contact_id;
4023 ELSE
4024 -- Validate the vendor and vendor site
4025 validate_vendor_site(p_x_osp_order_rec.vendor_id,
4026 p_x_osp_order_rec.vendor_site_id);
4027 IF FND_MSG_PUB.count_msg > 0 THEN
4028 -- Vendor/Vendor Site/Vendor Contact is Invalid
4029 RAISE FND_API.G_EXC_ERROR;
4030 END IF;
4031 -- If valid, use the input values
4032 l_vendor_id := p_x_osp_order_rec.vendor_id;
4033 l_vendor_site_id := p_x_osp_order_rec.vendor_site_id;
4034 END IF;
4035 ELSE
4036 -- Validate the Vendor
4037 validate_vendor(p_x_osp_order_rec.vendor_id);
4038 IF FND_MSG_PUB.count_msg > 0 THEN
4039 -- Vendor/Vendor Site/Vendor Contact is Invalid
4040 RAISE FND_API.G_EXC_ERROR;
4041 END IF;
4042 -- If valid, use the input values
4043 l_vendor_id := p_x_osp_order_rec.vendor_id;
4044 END IF;
4045 END IF;
4046 /** End addition by jaramana on May 9, 2006 for Bug 5215894 **/
4047 ELSIF (p_x_osp_order_lines_tbl.COUNT > 0) THEN
4048 IF (p_x_osp_order_lines_tbl(p_x_osp_order_lines_tbl.FIRST).workorder_id IS NULL) THEN
4049 --Only need to check the the first record, either all work order lines or inventory
4050 --service order lines. All service order lines
4051 FOR i IN p_x_osp_order_lines_tbl.FIRST..p_x_osp_order_lines_tbl.LAST LOOP
4052 l_item_service_rels_tbl(i).inv_org_id := p_x_osp_order_lines_tbl(i).inventory_org_id;
4053 l_item_service_rels_tbl(i).inv_item_id := p_x_osp_order_lines_tbl(i).inventory_item_id;
4054 l_item_service_rels_tbl(i).service_item_id := p_x_osp_order_lines_tbl(i).service_item_id;
4055 END LOOP;
4056 ELSE
4057 --All work order lines
4058 FOR i IN p_x_osp_order_lines_tbl.FIRST..p_x_osp_order_lines_tbl.LAST LOOP
4059 BEGIN
4060 --Modified by mpothuku on 27-Feb-06 to fix the Perf Bug #4919164
4061 /*
4062 SELECT organization_id, inventory_item_id, service_item_id
4063 INTO l_organization_id, l_inventory_item_id, l_service_item_id
4064 FROM ahl_workorders_osp_v
4065 WHERE workorder_id = p_x_osp_order_lines_tbl(i).workorder_id;
4066 */
4067 SELECT vst.organization_id, vts.inventory_item_id, arb.service_item_id
4068 INTO l_organization_id, l_inventory_item_id, l_service_item_id
4069 FROM ahl_workorders wo,
4070 ahl_visits_b vst,
4071 ahl_visit_tasks_b vts,
4072 ahl_routes_b arb,
4073 inv_organization_info_v org
4074 WHERE wo.workorder_id = p_x_osp_order_lines_tbl (i).workorder_id
4075 AND wo.route_id = arb.route_id(+)
4076 AND wo.master_workorder_flag = 'N'
4077 AND wo.visit_id = vst.visit_id
4078 AND wo.visit_task_id = vts.visit_task_id
4079 AND vst.visit_id = vts.visit_id
4080 AND vst.organization_id = org.organization_id
4081 AND NVL (org.operating_unit, mo_global.get_current_org_id ())= mo_global.get_current_org_id();
4082
4083 l_item_service_rels_tbl(i).inv_org_id := l_organization_id;
4084 l_item_service_rels_tbl(i).inv_item_id := l_inventory_item_id;
4085 l_item_service_rels_tbl(i).service_item_id := l_service_item_id;
4086 EXCEPTION
4087 WHEN NO_DATA_FOUND THEN
4088 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_WO');
4089 FND_MESSAGE.Set_Token('WORKORDER_ID', p_x_osp_order_lines_tbl(i).workorder_id);
4090 FND_MSG_PUB.ADD;
4091 RAISE FND_API.G_EXC_ERROR;
4092 END;
4093 END LOOP;
4094 END IF;
4095 derive_default_vendor(l_item_service_rels_tbl,
4096 l_vendor_id,
4097 l_vendor_site_id,
4098 l_vendor_contact_id,
4099 l_valid_vendors_tbl);
4100 /** Added by jaramana on May 9, 2006 for Bug 5215894 **/
4101 -- If the user has passed a Vendor or Vendor + Vendor Site, validate and use these instead of the default
4102 -- If only Vendor Site is passed (without the Vendor), ignore and use default
4103 IF (p_x_osp_order_rec.vendor_id IS NOT NULL) THEN
4104 IF (l_valid_vendors_tbl.count > 0) THEN
4105 FOR l_temp_num in l_valid_vendors_tbl.FIRST..l_valid_vendors_tbl.LAST LOOP
4106 IF (l_valid_vendors_tbl(l_temp_num).vendor_id = p_x_osp_order_rec.vendor_id AND
4107 l_valid_vendors_tbl(l_temp_num).vendor_site_id = NVL(p_x_osp_order_rec.vendor_site_id, l_valid_vendors_tbl(l_temp_num).vendor_site_id)) THEN
4108 l_vendor_id := p_x_osp_order_rec.vendor_id;
4109 l_vendor_site_id := NVL(p_x_osp_order_rec.vendor_site_id, l_valid_vendors_tbl(l_temp_num).vendor_site_id);
4110 l_vendor_valid_flag := TRUE;
4111 EXIT;
4112 END IF;
4113 END LOOP;
4114 END IF;
4115 IF (l_vendor_valid_flag = FALSE) THEN
4116 -- The vendor or vendor + vendor site passed in is not a valid: Throw Error
4117 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENDOR_ID_INV');
4118 FND_MESSAGE.Set_Token('VENDOR_ID', p_x_osp_order_rec.vendor_id);
4119 FND_MSG_PUB.ADD;
4120 RAISE FND_API.G_EXC_ERROR;
4121 END IF;
4122 IF (p_x_osp_order_rec.vendor_site_id IS NOT NULL) THEN
4123 IF (p_x_osp_order_rec.vendor_contact_id IS NOT NULL) THEN
4124 -- Check if p_x_osp_order_rec.vendor_contact_id is valid
4125 validate_vendor_site_contact(p_x_osp_order_rec.vendor_id,
4126 p_x_osp_order_rec.vendor_site_id,
4127 p_x_osp_order_rec.vendor_contact_id);
4128 IF FND_MSG_PUB.count_msg > 0 THEN
4129 -- Vendor/Vendor Site/Vendor Contact is Invalid
4130 RAISE FND_API.G_EXC_ERROR;
4131 END IF;
4132 -- Vendor Contact is valid: Use it
4133 l_vendor_contact_id := p_x_osp_order_rec.vendor_contact_id;
4134 ELSE
4135 -- User has passed Vendor and Vendor Site, but not Vendor Contact: Leave Contact as null
4136 l_vendor_contact_id := null;
4137 END IF;
4138 ELSE
4139 -- User has passed Vendor, but not Vendor Site: Set Contact as null even if passed
4140 l_vendor_contact_id := null;
4141 END IF;
4142 END IF;
4143 END IF;
4144
4145 IF (p_x_osp_order_rec.po_agent_id IS NOT NULL) THEN
4146 -- Validate the buyer
4147 validate_buyer(p_x_osp_order_rec.po_agent_id);
4148 IF FND_MSG_PUB.count_msg > 0 THEN
4149 -- Buyer is Invalid
4150 RAISE FND_API.G_EXC_ERROR;
4151 END IF;
4152 -- Buyer is valid: Use it
4153 l_buyer_id := p_x_osp_order_rec.po_agent_id;
4154 ELSE
4155 --Derive the default po_agent_id
4156 l_buyer_id := fnd_global.user_id;
4157 OPEN get_buyer_id;
4158 FETCH get_buyer_id INTO l_buyer_id;
4159 CLOSE get_buyer_id;
4160 END IF;
4161 /** End addition by jaramana on May 9, 2006 for Bug 5215894 **/
4162
4163 --In Create mode, assume that UI will never pass G_MISS value(if it is null in UI, then just pass
4164 --Null to the API). Thus in this Create procedure, there are only three attributes probably need
4165 --validation: customer_id, contract_id and contract_terms
4166 AHL_OSP_ORDERS_PKG.insert_row(
4167 x_rowid => l_rowid_dummy,
4168 x_osp_order_id => l_osp_order_id,
4169 x_object_version_number => 1,
4170 x_created_by => FND_GLOBAL.user_id,
4171 x_creation_date => SYSDATE,
4172 x_last_updated_by => FND_GLOBAL.user_id,
4173 x_last_update_date => SYSDATE,
4174 x_last_update_login => FND_GLOBAL.login_id,
4175 x_osp_order_number => l_osp_order_number,
4176 x_order_type_code => p_x_osp_order_rec.order_type_code, --User entered
4177 x_single_instance_flag => G_NO_FLAG,
4178 x_po_header_id => NULL, --p_x_osp_order_rec.po_header_id,
4179 x_oe_header_id => NULL, --p_x_osp_order_rec.oe_header_id,
4180 x_vendor_id => l_vendor_id,
4181 x_vendor_site_id => l_vendor_site_id,
4182 x_vendor_contact_id => l_vendor_contact_id,
4183 x_customer_id => p_x_osp_order_rec.customer_id,
4184 x_order_date => TRUNC(SYSDATE),
4185 x_contract_id => p_x_osp_order_rec.contract_id,
4186 x_contract_terms => p_x_osp_order_rec.contract_terms,
4187 x_operating_unit_id => l_operating_unit_id,
4188 x_po_synch_flag => NULL, --p_x_osp_order_rec.po_synch_flag,
4189 x_status_code => G_OSP_ENTERED_STATUS,
4190 x_po_batch_id => NULL, --p_x_osp_order_rec.po_batch_id,
4191 x_po_request_id => NULL, --p_x_osp_order_rec.po_request_id,
4192 x_po_agent_id => l_buyer_id,
4193 x_po_interface_header_id => NULL, --p_x_osp_order_rec.po_interface_header_id,
4194 -- Added by jaramana on January 10, 2008 for the Requisition ER 6034236
4195 x_po_req_header_id => NULL,
4196 -- jaramana End
4197 x_description => p_x_osp_order_rec.description,
4198 x_attribute_category => p_x_osp_order_rec.attribute_category,
4199 x_attribute1 => p_x_osp_order_rec.attribute1,
4200 x_attribute2 => p_x_osp_order_rec.attribute2,
4201 x_attribute3 => p_x_osp_order_rec.attribute3,
4202 x_attribute4 => p_x_osp_order_rec.attribute4,
4203 x_attribute5 => p_x_osp_order_rec.attribute5,
4204 x_attribute6 => p_x_osp_order_rec.attribute6,
4205 x_attribute7 => p_x_osp_order_rec.attribute7,
4206 x_attribute8 => p_x_osp_order_rec.attribute8,
4207 x_attribute9 => p_x_osp_order_rec.attribute9,
4208 x_attribute10 => p_x_osp_order_rec.attribute10,
4209 x_attribute11 => p_x_osp_order_rec.attribute11,
4210 x_attribute12 => p_x_osp_order_rec.attribute12,
4211 x_attribute13 => p_x_osp_order_rec.attribute13,
4212 x_attribute14 => p_x_osp_order_rec.attribute14,
4213 x_attribute15 => p_x_osp_order_rec.attribute15);
4214 --Return the generated order header id to the output record structure
4215 p_x_osp_order_rec.osp_order_id := l_osp_order_id;
4216 IF (p_x_osp_order_lines_tbl IS NOT NULL AND p_x_osp_order_lines_tbl.COUNT > 0) THEN
4217 FOR i IN p_x_osp_order_lines_tbl.FIRST..p_x_osp_order_lines_tbl.LAST LOOP
4218 p_x_osp_order_lines_tbl(i).osp_order_id := l_osp_order_id;
4219 END LOOP;
4220 END IF;
4221 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
4222 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
4223 G_LOG_PREFIX || '.create_osp_order_header',
4224 'Procedure exits normally');
4225 END IF;
4226 END create_osp_order_header;
4227
4228 PROCEDURE update_osp_order_header(p_x_osp_order_rec IN OUT NOCOPY osp_order_rec_type)
4229 IS
4230 l_operating_unit_id NUMBER;
4231 l_osp_order_id NUMBER;
4232 l_osp_order_number NUMBER;
4233 l_item_service_rels_tbl item_service_rels_tbl_type;
4234 l_vendor_id NUMBER;
4235 l_vendor_site_id NUMBER;
4236 l_vendor_contact_id NUMBER;
4237 l_return_status VARCHAR2(1);
4238 l_msg_count NUMBER;
4239 l_msg_data VARCHAR2(2000);
4240 l_organization_id NUMBER;
4241 l_inventory_item_id NUMBER;
4242 l_service_item_id NUMBER;
4243 l_dummy_num NUMBER;
4244 l_osp_order_line_rec osp_order_line_rec_type;
4245 l_oe_header_id NUMBER;
4246 CURSOR get_all_lines(c_osp_order_id NUMBER) IS
4247 SELECT osp_order_line_id, inventory_item_id,
4248 inventory_org_id, service_item_id, workorder_id
4249 FROM ahl_osp_order_lines
4250 WHERE osp_order_id = c_osp_order_id;
4251 CURSOR get_old_vendor_attrs(c_osp_order_id NUMBER) IS
4252 SELECT vendor_id, vendor_site_id, oe_header_id
4253 FROM ahl_osp_orders_b
4254 WHERE osp_order_id = c_osp_order_id;
4255
4256 BEGIN
4257 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
4258 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
4259 G_LOG_PREFIX || '.update_osp_order_header',
4260 'Procedure begins and osp_order_id='||p_x_osp_order_rec.osp_order_id);
4261 END IF;
4262 --This three procedures are borrowed from the original ones
4263 --For OAF, the default procedure may not be necessary.
4264 --we decided to pass null when you want to change it to null, the old value if there is no change.
4265 IF nvl(g_module_type, 'NULL') <> G_OAF_MODULE THEN
4266 default_unchanged_order_header(p_x_osp_order_rec);
4267 END IF;
4268 convert_order_header_val_to_id(p_x_osp_order_rec);
4269 validate_order_header(p_x_osp_order_rec);
4270
4271 --Handling if order status is to be changed
4272 process_order_status_change(p_x_osp_order_rec);
4273 --Handling if order type is to be changed
4274 process_order_type_change(p_x_osp_order_rec);
4275
4276 OPEN get_old_vendor_attrs(p_x_osp_order_rec.osp_order_id);
4277 FETCH get_old_vendor_attrs INTO l_vendor_id, l_vendor_site_id, l_oe_header_id;
4278 CLOSE get_old_vendor_attrs;
4279
4280 --Call table handler to update
4281 AHL_OSP_ORDERS_PKG.update_row(
4282 x_osp_order_id => p_x_osp_order_rec.osp_order_id,
4283 x_object_version_number => p_x_osp_order_rec.object_version_number + 1,
4284 x_osp_order_number => p_x_osp_order_rec.osp_order_number,
4285 x_order_type_code => p_x_osp_order_rec.order_type_code,
4286 x_single_instance_flag => p_x_osp_order_rec.single_instance_flag,
4287 x_po_header_id => p_x_osp_order_rec.po_header_id,
4288 x_oe_header_id => p_x_osp_order_rec.oe_header_id,
4289 x_vendor_id => p_x_osp_order_rec.vendor_id,
4290 x_vendor_site_id => p_x_osp_order_rec.vendor_site_id,
4291 x_vendor_contact_id => p_x_osp_order_rec.vendor_contact_id,
4292 x_customer_id => p_x_osp_order_rec.customer_id,
4293 x_order_date => TRUNC(p_x_osp_order_rec.order_date),
4294 x_contract_id => p_x_osp_order_rec.contract_id,
4295 x_contract_terms => p_x_osp_order_rec.contract_terms,
4296 x_operating_unit_id => p_x_osp_order_rec.operating_unit_id,
4297 x_po_synch_flag => p_x_osp_order_rec.po_synch_flag,
4298 x_status_code => p_x_osp_order_rec.status_code,
4299 x_po_batch_id => p_x_osp_order_rec.po_batch_id,
4300 x_po_request_id => p_x_osp_order_rec.po_request_id,
4301 x_po_agent_id => p_x_osp_order_rec.po_agent_id,
4302 x_po_interface_header_id => p_x_osp_order_rec.po_interface_header_id,
4303 -- Added by jaramana on January 10, 2008 for the Requisition ER 6034236
4304 x_po_req_header_id => p_x_osp_order_rec.po_req_header_id,
4305 -- jaramana End
4306 x_description => p_x_osp_order_rec.description,
4307 x_attribute_category => p_x_osp_order_rec.attribute_category,
4308 x_attribute1 => p_x_osp_order_rec.attribute1,
4309 x_attribute2 => p_x_osp_order_rec.attribute2,
4310 x_attribute3 => p_x_osp_order_rec.attribute3,
4311 x_attribute4 => p_x_osp_order_rec.attribute4,
4312 x_attribute5 => p_x_osp_order_rec.attribute5,
4313 x_attribute6 => p_x_osp_order_rec.attribute6,
4314 x_attribute7 => p_x_osp_order_rec.attribute7,
4315 x_attribute8 => p_x_osp_order_rec.attribute8,
4316 x_attribute9 => p_x_osp_order_rec.attribute9,
4317 x_attribute10 => p_x_osp_order_rec.attribute10,
4318 x_attribute11 => p_x_osp_order_rec.attribute11,
4319 x_attribute12 => p_x_osp_order_rec.attribute12,
4320 x_attribute13 => p_x_osp_order_rec.attribute13,
4321 x_attribute14 => p_x_osp_order_rec.attribute14,
4322 x_attribute15 => p_x_osp_order_rec.attribute15,
4323 x_last_updated_by => fnd_global.user_id,
4324 x_last_update_date => SYSDATE,
4325 x_last_update_login => fnd_global.login_id
4326 );
4327 --After the header vendor gets changed then calling validate_vendor_service_item.
4328 --If it is not for calling validate_vendor_service_item, then it is better to put
4329 --this validation ahead of table_handler calling
4330 --Validate the header vendor with physical/Service item combinations in lines
4331 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
4332 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4333 G_LOG_PREFIX || '.update_osp_order_header',
4334 'new_vendor='||p_x_osp_order_rec.vendor_id||
4335 'old_vendor='||l_vendor_id);
4336 END IF;
4337 --The following validation was moved to process_osp_order and acting like
4338 --a post database operation validation (Jerry) 06/15/2005
4339 --IF ((p_x_osp_order_rec.vendor_id <> l_vendor_id) OR
4340 --(p_x_osp_order_rec.vendor_id IS NOT NULL AND l_vendor_id IS NULL) OR
4341 --(p_x_osp_order_rec.vendor_site_id <> l_vendor_site_id) OR
4342 --(p_x_osp_order_rec.vendor_site_id IS NOT NULL AND l_vendor_site_id IS NULL)) THEN
4343 -- Both new vendor_id and vendor_site_id can't be null. Already validated in
4344 -- validate_order_header
4345 --FOR l_get_all_lines IN get_all_lines(p_x_osp_order_rec.osp_order_id) LOOP
4346 --l_osp_order_line_rec.osp_order_id := p_x_osp_order_rec.osp_order_id;
4347 --l_osp_order_line_rec.osp_order_line_id := l_get_all_lines.osp_order_line_id;
4348 --l_osp_order_line_rec.inventory_item_id := l_get_all_lines.inventory_item_id;
4349 --l_osp_order_line_rec.inventory_org_id := l_get_all_lines.inventory_org_id;
4350 --l_osp_order_line_rec.service_item_id := l_get_all_lines.service_item_id;
4351 --IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
4352 --FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4353 --G_LOG_PREFIX || '.update_osp_order_header',
4354 --'before calling validate_vendor_service_item'||
4355 --'line_id='||l_get_all_lines.osp_order_line_id||
4356 --'inventory_item_id ='||l_osp_order_line_rec.inventory_item_id||
4357 --'org_id = '||l_osp_order_line_rec.inventory_org_id||
4358 --'service_id = '||l_osp_order_line_rec.service_item_id);
4359 --END IF;
4360 -- validate_vendor_service_item(l_osp_order_line_rec);
4361 --END LOOP;
4362 --END IF;
4363 IF (FND_LOG.LEVEL_EVENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
4364 FND_LOG.STRING(FND_LOG.LEVEL_EVENT,
4365 G_LOG_PREFIX || '.update_osp_order_header',
4366 'Before calling AHL_OSP_SHIPMENT_PUB.handle_vendor_change');
4367 END IF;
4368 IF ((l_oe_header_id IS NOT NULL) AND
4369 ((p_x_osp_order_rec.vendor_id IS NOT NULL AND l_vendor_id IS NULL) OR
4370 (p_x_osp_order_rec.vendor_id <> l_vendor_id) OR
4371 -- Added by jaramana on January 10, 2008 to fix the issue with the SO Customer change if the Vendor Site is Changed, Bug 6521712.
4372 (p_x_osp_order_rec.vendor_site_id IS NOT NULL AND l_vendor_site_id IS NULL) OR
4373 (p_x_osp_order_rec.vendor_site_id <> l_vendor_site_id ))) THEN
4374 --Only if vendor gets changed, then call the shipment API to handle the change
4375 AHL_OSP_SHIPMENT_PUB.handle_vendor_change(
4376 p_osp_order_id => p_x_osp_order_rec.osp_order_id,
4377 p_vendor_id => p_x_osp_order_rec.vendor_id,
4378 p_vendor_loc_id => p_x_osp_order_rec.vendor_site_id,
4379 x_return_status => l_return_status,
4380 x_msg_count => l_msg_count,
4381 x_msg_data => l_msg_data);
4382 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
4383 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
4384 G_LOG_PREFIX || '.update_osp_order_header',
4385 'Normally exit after calling AHL_OSP_SHIPMENT_PUB.handle_vendor_change'||
4386 'x_return_status='||l_return_status);
4387 END IF;
4388 END IF;
4389 END update_osp_order_header;
4390
4391 PROCEDURE create_osp_order_line(p_x_osp_order_line_rec IN OUT NOCOPY osp_order_line_rec_type)
4392 IS
4393 l_osp_line_id NUMBER;
4394 l_osp_line_number NUMBER;
4395 l_return_status VARCHAR2(1);
4396 l_organization_id NUMBER;
4397 l_inventory_item_id NUMBER;
4398 l_service_item_id NUMBER;
4399 l_service_duration NUMBER;
4400 l_quantity NUMBER;
4401 l_service_item_uom_code VARCHAR2(3);
4402 l_temp_uom_code VARCHAR2(3);
4403 l_item_description VARCHAR2(240);
4404 l_vendor_id NUMBER;
4405 l_vendor_site_id NUMBER;
4406 --Added by mpothuku on 24-Mar-06 for ER: 4544654
4407 l_owrite_svc_desc_prf VARCHAR2(1);
4408 l_item_prefix VARCHAR2(240);
4409 l_serial_prefix VARCHAR2(240);
4410 l_inv_item_number VARCHAR2(40);
4411 l_svc_item_number VARCHAR2(40);
4412 l_desc_update_flag VARCHAR2(1);
4413 --mpothuku end
4414 CURSOR get_wo_item_attrs(c_workorder_id NUMBER) IS
4415 --Modified by mpothuku on 27-Feb-06 to fix the Perf Bug #4919164
4416 /*
4417 SELECT inventory_item_id,
4418 organization_id,
4419 lot_number,
4420 serial_number,
4421 quantity, --This quantity is from csi, so it means instance quantity
4422 item_instance_uom,
4423 service_item_id,
4424 service_item_description,
4425 service_item_uom
4426 FROM ahl_workorders_osp_v
4427 WHERE workorder_id = c_workorder_id;
4428 */
4429 SELECT vts.inventory_item_id,
4430 vst.organization_id,
4431 csii.lot_number,
4432 csii.serial_number,
4433 csii.quantity, --This quantity is from csi, so it means instance quantity
4434 csii.unit_of_measure item_instance_uom,
4435 arb.service_item_id,
4436 mtls.description service_item_description,
4437 mtls.primary_uom_code service_item_uom
4438 FROM ahl_workorders wo,
4439 ahl_visits_b vst,
4440 ahl_visit_tasks_b vts,
4441 csi_item_instances csii,
4442 mtl_system_items_kfv mtls,
4443 ahl_routes_b arb
4444 WHERE wo.workorder_id = c_workorder_id
4445 AND wo.visit_task_id = vts.visit_task_id
4446 AND vst.visit_id = vts.visit_id
4447 AND wo.route_id = arb.route_id(+)
4448 AND arb.service_item_org_id = mtls.organization_id(+)
4449 AND arb.service_item_id = mtls.inventory_item_id(+)
4450 AND vts.instance_id = csii.instance_id;
4451 BEGIN
4452 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
4453 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, G_LOG_PREFIX || '.create_osp_order_line',
4454 'Before line validation:'||
4455 'osp_order_id='||p_x_osp_order_line_rec.osp_order_id);
4456 END IF;
4457 --Validate the order line
4458 validate_order_line_creation(p_x_osp_order_line_rec);
4459
4460 --yazhou 22-Aug-2006 starts
4461 -- Bug fix#5479266
4462
4463 IF FND_MSG_PUB.count_msg > 0 THEN
4464 RAISE FND_API.G_EXC_ERROR;
4465 END IF;
4466
4467 --yazhou 22-Aug-2006 ends
4468
4469 --Generate the primary key
4470 SELECT ahl_osp_order_lines_s.NEXTVAL
4471 INTO l_osp_line_id
4472 FROM sys.dual;
4473
4474 --Generate the line number
4475 --NOTE: This logic to generate osp_line number will probably violate the unique
4476 --index defined on osp_line_number if two concurrent users try to add osp order line
4477 --to the same OSP Order headet at the same time.
4478 SELECT NVL(MAX(osp_line_number), 0)+1
4479 INTO l_osp_line_number
4480 FROM ahl_osp_order_lines
4481 WHERE osp_order_id = p_x_osp_order_line_rec.osp_order_id;
4482
4483 /*
4484 Changed by jaramana on January 10, 2008
4485 Fix for the Bug 5358438/5967633/5417460
4486 Its better not to change the existing flow if the po_line_id is passed. The attribute defaulting as well as validation
4487 happens in the validate_order_creation, we only need to call the insert_row method here.
4488 */
4489 IF(p_x_osp_order_line_rec.po_line_id is null) THEN
4490
4491 --For work order based lines, it is better to populate the physical item/service item related attributes
4492 --And these attributes don't have to be validated.
4493 IF (p_x_osp_order_line_rec.workorder_id IS NOT NULL) THEN
4494 OPEN get_wo_item_attrs(p_x_osp_order_line_rec.workorder_id);
4495 FETCH get_wo_item_attrs INTO p_x_osp_order_line_rec.inventory_item_id,
4496 p_x_osp_order_line_rec.inventory_org_id,
4497 p_x_osp_order_line_rec.lot_number,
4498 p_x_osp_order_line_rec.serial_number,
4499 p_x_osp_order_line_rec.inventory_item_quantity,
4500 p_x_osp_order_line_rec.inventory_item_uom,
4501 p_x_osp_order_line_rec.service_item_id,
4502 p_x_osp_order_line_rec.service_item_description,
4503 p_x_osp_order_line_rec.service_item_uom_code;
4504 --leave p_x_osp_order_line_rec.sub_inventory blank
4505 CLOSE get_wo_item_attrs;
4506 END IF;
4507
4508 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
4509 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, G_LOG_PREFIX || 'create_osp_order_line',
4510 'After line validation and before insert operation:'||
4511 'inv_item_id='||p_x_osp_order_line_rec.inventory_item_id||' service_item_id='||p_x_osp_order_line_rec.service_item_id);
4512 END IF;
4513
4514 --Default service item quantity and uom if there are null and service item not null, derive
4515 --service item description always as long as service_item_id is not null regardless what being passed (means
4516 --it could be overwrite if a non null value passed to service_item_description if service_item_id is not null)
4517
4518 -- yazhou 06-Jul-2006 starts
4519 -- bug fix#5376907
4520 -- l_quantity := p_x_osp_order_line_rec.quantity; --here it means service_item quantity
4521 -- yazhou 06-Jul-2006 ends
4522
4523 l_service_item_uom_code := p_x_osp_order_line_rec.service_item_uom_code;
4524 l_item_description := p_x_osp_order_line_rec.service_item_description;
4525 IF (p_x_osp_order_line_rec.service_item_id IS NOT NULL) THEN
4526 BEGIN
4527 --Assuming the org of service_item_id is the same as that of physical item
4528 --Alwasy set service_item_description to be derived from service_item_id if service_item_id is not null
4529 SELECT primary_uom_code, description,concatenated_segments, allow_item_desc_update_flag INTO
4530 l_temp_uom_code, l_item_description, l_svc_item_number, l_desc_update_flag
4531 FROM mtl_system_items_kfv
4532 WHERE inventory_item_id = p_x_osp_order_line_rec.service_item_id
4533 AND organization_id = p_x_osp_order_line_rec.inventory_org_id;
4534 EXCEPTION
4535 WHEN NO_DATA_FOUND THEN
4536 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_SVC_ITEM');
4537 FND_MESSAGE.Set_Token('SERVICE_ITEM_ID', p_x_osp_order_line_rec.service_item_id);
4538 FND_MSG_PUB.ADD;
4539 END;
4540
4541 -- yazhou 06-Jul-2006 starts
4542 -- bug fix#5376907
4543
4544 -- IF (p_x_osp_order_line_rec.quantity IS NULL) THEN
4545 -- l_quantity := 1;
4546 -- END IF;
4547 -- yazhou 06-Jul-2006 ends
4548
4549 IF (p_x_osp_order_line_rec.service_item_uom_code IS NULL) THEN
4550 l_service_item_uom_code := l_temp_uom_code;
4551 END IF;
4552 --Added by mpothuku on 24-Mar-06 for ER: 4544654
4553 /*IF Overwrite Svc Description profile set to No l_item_description would have been
4554 defaulted as the service item desc from inventory above, if the profile is Yes, we proceed below
4555 to override the value set from the inventory */
4556
4557 l_owrite_svc_desc_prf := NVL(FND_PROFILE.VALUE('AHL_OSP_OWRITE_SVC_DESC'), 'N');
4558 l_item_prefix := FND_PROFILE.VALUE('AHL_OSP_POL_ITEM_PREFIX');
4559 l_serial_prefix := FND_PROFILE.VALUE('AHL_OSP_POL_SER_PREFIX');
4560
4561 IF(l_owrite_svc_desc_prf = 'Y') THEN --Overwrite Svc Description profile set to Yes
4562 IF(NVL(l_desc_update_flag, 'N') = 'N') THEN --Allow Description update set to No
4563 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_SVC_DESC_NOCHNG');
4564 FND_MESSAGE.Set_Token('SERVICE_ITEM_NUMBER', l_svc_item_number);
4565 FND_MSG_PUB.ADD;
4566 ELSE
4567 BEGIN
4568 SELECT concatenated_segments INTO l_inv_item_number
4569 FROM mtl_system_items_kfv
4570 WHERE inventory_item_id = p_x_osp_order_line_rec.inventory_item_id
4571 AND organization_id = p_x_osp_order_line_rec.inventory_org_id;
4572 EXCEPTION
4573 WHEN NO_DATA_FOUND THEN
4574 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_PHY_ITEM_INVALID');
4575 FND_MSG_PUB.ADD;
4576 END;
4577 l_item_description :=
4578 SUBSTR(l_item_prefix||l_inv_item_number||' '||l_serial_prefix||p_x_osp_order_line_rec.serial_number,1,240);
4579 END IF;
4580 END IF;
4581 --mpothuku End
4582 END IF;
4583
4584 --This is for deriving need_by_date from the profile option value and service_duration defined
4585 --at association between vendor and items combination
4586 BEGIN
4587 SELECT vendor_id, vendor_site_id
4588 INTO l_vendor_id, l_vendor_site_id
4589 FROM ahl_osp_orders_b
4590 WHERE osp_order_id = p_x_osp_order_line_rec.osp_order_id;
4591 IF (l_vendor_id IS NOT NULL AND l_vendor_site_id IS NOT NULL) THEN
4592 SELECT IV.service_duration INTO l_service_duration
4593 FROM ahl_inv_service_item_rels SI,
4594 ahl_item_vendor_rels IV,
4595 ahl_vendor_certifications_v VC
4596 WHERE SI.inv_item_id = p_x_osp_order_line_rec.inventory_item_id
4597 AND SI.inv_org_id = p_x_osp_order_line_rec.inventory_org_id
4598 AND SI.service_item_id = p_x_osp_order_line_rec.service_item_id
4599 AND VC.vendor_id = l_vendor_id
4600 AND VC.vendor_site_id = l_vendor_site_id
4601 AND SI.inv_service_item_rel_id = IV.inv_service_item_rel_id
4602 AND IV.vendor_certification_id = VC.vendor_certification_id
4603 AND trunc(SI.active_start_date) <= trunc(SYSDATE)
4604 AND trunc(nvl(SI.active_end_date, SYSDATE+1)) > trunc(SYSDATE)
4605 AND trunc(IV.active_start_date) <= trunc(SYSDATE)
4606 AND trunc(nvl(IV.active_end_date, SYSDATE+1)) > trunc(SYSDATE)
4607 AND trunc(VC.active_start_date) <= trunc(SYSDATE)
4608 AND trunc(nvl(VC.active_end_date, SYSDATE+1)) > trunc(SYSDATE);
4609 ELSE
4610 l_service_duration := FND_PROFILE.value('AHL_VENDOR_SERVICE_DURATION');
4611 END IF;
4612 EXCEPTION
4613 WHEN OTHERS THEN
4614 l_service_duration := FND_PROFILE.value('AHL_VENDOR_SERVICE_DURATION');
4615 END;
4616 --In case service_duration returned from the above query is null
4617 IF l_service_duration IS NULL THEN
4618 l_service_duration := FND_PROFILE.value('AHL_VENDOR_SERVICE_DURATION');
4619 END IF;
4620
4621 -- yazhou 06-Jul-2006 starts
4622 -- bug fix#5376907
4623 -- Service item qty should be the same as physical item qty at the time of creation
4624
4625 --Call table handler to insert the line
4626 AHL_OSP_ORDER_LINES_PKG.insert_row(
4627 p_x_osp_order_line_id => l_osp_line_id,
4628 p_object_version_number => 1,
4629 p_created_by => fnd_global.user_id,
4630 p_creation_date => SYSDATE,
4631 p_last_updated_by => fnd_global.user_id,
4632 p_last_update_date => SYSDATE,
4633 p_last_update_login => fnd_global.login_id,
4634 p_osp_order_id => p_x_osp_order_line_rec.osp_order_id,
4635 p_osp_line_number => l_osp_line_number,
4636 p_status_code => NULL, --Derived from header status when displaying
4637 p_po_line_type_id => to_number(FND_PROFILE.VALUE('AHL_OSP_PO_LINE_TYPE_ID')),
4638 p_service_item_id => p_x_osp_order_line_rec.service_item_id,
4639 p_service_item_description => l_item_description,
4640 p_service_item_uom_code => l_service_item_uom_code,
4641 p_need_by_date => TRUNC(SYSDATE+l_service_duration),
4642 p_ship_by_date => TRUNC(nvl(p_x_osp_order_line_rec.ship_by_date, SYSDATE)),
4643 p_po_line_id => NULL,
4644 -- by jaramana on January 10, 2008 to fix the Bug 5358438/5967633/5417460
4645 --p_po_line_id => p_x_osp_order_line_rec.po_line_id, --yazhou 28-jul-2006 bug#5417460
4646 p_oe_ship_line_id => NULL,
4647 p_oe_return_line_id => NULL,
4648 p_workorder_id => p_x_osp_order_line_rec.workorder_id,
4649 p_operation_id => NULL,
4650 -- p_quantity => l_quantity,
4651 p_quantity => p_x_osp_order_line_rec.inventory_item_quantity,
4652 p_exchange_instance_id => NULL,
4653 p_inventory_item_id => p_x_osp_order_line_rec.inventory_item_id,
4654 p_inventory_org_id => p_x_osp_order_line_rec.inventory_org_id,
4655 p_sub_inventory => p_x_osp_order_line_rec.sub_inventory,
4656 p_lot_number => p_x_osp_order_line_rec.lot_number,
4657 p_serial_number => p_x_osp_order_line_rec.serial_number,
4658 p_inventory_item_uom => p_x_osp_order_line_rec.inventory_item_uom,
4659 p_inventory_item_quantity => p_x_osp_order_line_rec.inventory_item_quantity,
4660 -- Added by jaramana on January 10, 2008 for the Requisition ER 6034236
4661 p_po_req_line_id => NULL,
4662 -- jaramana End
4663 p_attribute_category => p_x_osp_order_line_rec.attribute_category,
4664 p_attribute1 => p_x_osp_order_line_rec.attribute1,
4665 p_attribute2 => p_x_osp_order_line_rec.attribute2,
4666 p_attribute3 => p_x_osp_order_line_rec.attribute3,
4667 p_attribute4 => p_x_osp_order_line_rec.attribute4,
4668 p_attribute5 => p_x_osp_order_line_rec.attribute5,
4669 p_attribute6 => p_x_osp_order_line_rec.attribute6,
4670 p_attribute7 => p_x_osp_order_line_rec.attribute7,
4671 p_attribute8 => p_x_osp_order_line_rec.attribute8,
4672 p_attribute9 => p_x_osp_order_line_rec.attribute9,
4673 p_attribute10 => p_x_osp_order_line_rec.attribute10,
4674 p_attribute11 => p_x_osp_order_line_rec.attribute11,
4675 p_attribute12 => p_x_osp_order_line_rec.attribute12,
4676 p_attribute13 => p_x_osp_order_line_rec.attribute13,
4677 p_attribute14 => p_x_osp_order_line_rec.attribute14,
4678 p_attribute15 => p_x_osp_order_line_rec.attribute15
4679 );
4680 -- yazhou 06-Jul-2006 ends
4681 ELSE --IF(p_x_osp_order_line_rec.po_line_id is null) THEN, which would mean po_line_id is passed
4682
4683 --Purchasing allows past need_by_date as well, if so defaulting ship_by_date to the need_by_date
4684 --else initializing it to the sysdate
4685 --this field does not have much significance
4686 IF(trunc(p_x_osp_order_line_rec.need_by_date) <= trunc(sysdate)) THEN
4687 p_x_osp_order_line_rec.ship_by_date := p_x_osp_order_line_rec.need_by_date;
4688 ELSE
4689 p_x_osp_order_line_rec.ship_by_date := SYSDATE;
4690 END IF;
4691
4692 --Call table handler to insert the line
4693 AHL_OSP_ORDER_LINES_PKG.insert_row(
4694 p_x_osp_order_line_id => l_osp_line_id,
4695 p_object_version_number => 1,
4696 p_created_by => fnd_global.user_id,
4697 p_creation_date => SYSDATE,
4698 p_last_updated_by => fnd_global.user_id,
4699 p_last_update_date => SYSDATE,
4700 p_last_update_login => fnd_global.login_id,
4701 p_osp_order_id => p_x_osp_order_line_rec.osp_order_id,
4702 p_osp_line_number => l_osp_line_number,
4703 p_status_code => NULL, --Derived from header status when displaying
4704 p_po_line_type_id => p_x_osp_order_line_rec.po_line_type_id, --derived from PO Line
4705 p_service_item_id => p_x_osp_order_line_rec.service_item_id, --derived from PO Line
4706 p_service_item_description => p_x_osp_order_line_rec.service_item_description, --derived from PO Line
4707 p_service_item_uom_code => p_x_osp_order_line_rec.service_item_uom_code, --derived from PO Line
4708 p_need_by_date => p_x_osp_order_line_rec.need_by_date, --derived from PO Line
4709 p_ship_by_date => p_x_osp_order_line_rec.ship_by_date,
4710 p_po_line_id => p_x_osp_order_line_rec.po_line_id,
4711 p_oe_ship_line_id => NULL,
4712 p_oe_return_line_id => NULL,
4713 p_workorder_id => p_x_osp_order_line_rec.workorder_id,
4714 p_operation_id => NULL,
4715 p_quantity => p_x_osp_order_line_rec.quantity, --derived from PO Line
4716 p_exchange_instance_id => NULL,
4717 p_inventory_item_id => p_x_osp_order_line_rec.inventory_item_id,
4718 p_inventory_org_id => p_x_osp_order_line_rec.inventory_org_id,
4719 p_sub_inventory => p_x_osp_order_line_rec.sub_inventory,
4720 p_lot_number => p_x_osp_order_line_rec.lot_number,
4721 p_serial_number => p_x_osp_order_line_rec.serial_number,
4722 p_inventory_item_uom => p_x_osp_order_line_rec.inventory_item_uom,
4723 p_inventory_item_quantity => p_x_osp_order_line_rec.inventory_item_quantity,
4724 p_po_req_line_id => NULL,
4725 p_attribute_category => p_x_osp_order_line_rec.attribute_category,
4726 p_attribute1 => p_x_osp_order_line_rec.attribute1,
4727 p_attribute2 => p_x_osp_order_line_rec.attribute2,
4728 p_attribute3 => p_x_osp_order_line_rec.attribute3,
4729 p_attribute4 => p_x_osp_order_line_rec.attribute4,
4730 p_attribute5 => p_x_osp_order_line_rec.attribute5,
4731 p_attribute6 => p_x_osp_order_line_rec.attribute6,
4732 p_attribute7 => p_x_osp_order_line_rec.attribute7,
4733 p_attribute8 => p_x_osp_order_line_rec.attribute8,
4734 p_attribute9 => p_x_osp_order_line_rec.attribute9,
4735 p_attribute10 => p_x_osp_order_line_rec.attribute10,
4736 p_attribute11 => p_x_osp_order_line_rec.attribute11,
4737 p_attribute12 => p_x_osp_order_line_rec.attribute12,
4738 p_attribute13 => p_x_osp_order_line_rec.attribute13,
4739 p_attribute14 => p_x_osp_order_line_rec.attribute14,
4740 p_attribute15 => p_x_osp_order_line_rec.attribute15
4741 );
4742
4743 END IF; --IF(p_x_osp_order_line_rec.po_line_id is null) THEN
4744 -- jaramana January 10, 2008 Bug 5358438/5967633/5417460 ends
4745
4746 --Remember to return the line id created
4747 p_x_osp_order_line_rec.osp_order_line_id := l_osp_line_id;
4748 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
4749 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, G_LOG_PREFIX || '.create_osp_order_line', 'After insert operation:');
4750 END IF;
4751
4752 END create_osp_order_line;
4753
4754 --yazhou 07-Aug-2006 starts
4755 -- bug fix#5448191
4756
4757 PROCEDURE create_shipment(p_osp_order_lines_tbl IN OUT NOCOPY osp_order_lines_tbl_type)
4758 --yazhou 07-Aug-2006 ends
4759
4760 IS
4761 l_oe_header_id NUMBER;
4762 l_oe_header_rec AHL_OSP_SHIPMENT_PUB.ship_header_rec_type;
4763 l_oe_lines_tbl AHL_OSP_SHIPMENT_PUB.ship_line_tbl_type;
4764 l_return_status VARCHAR2(1);
4765 l_msg_count NUMBER;
4766 l_msg_data VARCHAR2(2000);
4767 l_create_shipment BOOLEAN;
4768 l_osp_order_id NUMBER;
4769 i NUMBER;
4770 j NUMBER;
4771 k NUMBER;
4772 l_create_ship_line BOOLEAN;
4773 CURSOR check_ship_line_exists(c_inventory_item_id NUMBER,
4774 c_inventory_org_id NUMBER,
4775 c_serial_number VARCHAR2,
4776 c_osp_order_id NUMBER) IS
4777 SELECT 'X'
4778 FROM ahl_osp_order_lines
4779 WHERE inventory_item_id = c_inventory_item_id
4780 AND inventory_org_id = c_inventory_org_id
4781 AND serial_number = c_serial_number
4782 AND osp_order_id = c_osp_order_id
4783 AND (oe_ship_line_id IS NOT NULL OR oe_return_line_id IS NOT NULL);
4784
4785 BEGIN
4786 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
4787 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
4788 G_LOG_PREFIX||'create_shipment','Begin');
4789 END IF;
4790 l_create_shipment := FALSE;
4791 IF p_osp_order_lines_tbl.count > 0 THEN
4792 FOR i IN p_osp_order_lines_tbl.FIRST..p_osp_order_lines_tbl.LAST LOOP
4793
4794 -- yazhou 07-Aug-2006 starts
4795 -- bug fix#5448191
4796 IF p_osp_order_lines_tbl(i).operation_flag = G_OP_CREATE THEN
4797
4798 IF p_osp_order_lines_tbl(i).shipment_creation_flag = G_YES_FLAG THEN
4799 IF NOT l_create_shipment THEN
4800 l_create_shipment := TRUE;
4801 l_osp_order_id := p_osp_order_lines_tbl(i).osp_order_id;
4802 END IF;
4803 ELSE
4804 -- turn on create shipment flag if shipments for the same physical item
4805 -- already exist, so that shipment can be associated to new OSP order line
4806 -- in AHL_OSP_SHIPMENT_PUB.process_order
4807 OPEN check_ship_line_exists(p_osp_order_lines_tbl(i).inventory_item_id,
4808 p_osp_order_lines_tbl(i).inventory_org_id,
4809 p_osp_order_lines_tbl(i).serial_number,
4810 p_osp_order_lines_tbl(i).osp_order_id);
4811 FETCH check_ship_line_exists INTO g_dummy_char;
4812 IF check_ship_line_exists%FOUND THEN
4813 p_osp_order_lines_tbl(i).shipment_creation_flag := G_YES_FLAG;
4814 IF NOT l_create_shipment THEN
4815 l_create_shipment := TRUE;
4816 l_osp_order_id := p_osp_order_lines_tbl(i).osp_order_id;
4817 END IF;
4818 END IF;
4819
4820 CLOSE check_ship_line_exists;
4821
4822 END IF;
4823
4824 --EXIT;
4825 END IF;
4826
4827 -- yazhou 07-Aug-2006 ends
4828
4829 END LOOP;
4830 --For safety purpose, just check whether shipment header already exists
4831 --This is probably not necessary
4832 IF l_create_shipment THEN
4833 BEGIN
4834 SELECT oe_header_id INTO l_oe_header_id
4835 FROM ahl_osp_orders_b
4836 WHERE osp_order_id = l_osp_order_id;
4837 EXCEPTION
4838 WHEN NO_DATA_FOUND THEN
4839 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_INVALID');
4840 FND_MSG_PUB.ADD;
4841 RAISE FND_API.G_EXC_ERROR;
4842 END;
4843 l_oe_header_rec.header_id := l_oe_header_id;
4844 l_oe_header_rec.osp_order_id := l_osp_order_id;
4845 IF l_oe_header_id IS NULL THEN
4846 --No shipment header/lines exist yet
4847 l_oe_header_rec.operation := G_OP_CREATE;
4848 ELSE
4849 --Already has shipment header, but no change to shipment header itself and
4850 --just adding new shipment lines to the existing shipment header
4851 --And try to make it the same as front end calling Shipment API for which
4852 --Shipment header as a whole is passed as null
4853 l_oe_header_rec.operation := NULL;
4854 l_oe_header_rec.header_id := NULL;
4855
4856 --yazhou 03-Aug-2006 starts
4857 -- bug fix#5442904
4858 -- osp_order_id is used in AHL_OSP_SHIPMENT_PUB.Process_Line_Tbl to fetch vendor info
4859
4860 -- l_oe_header_rec.osp_order_id := NULL;
4861
4862 --yazhou 03-Aug-2006 ends
4863
4864 END IF;
4865 k := 1;
4866 FOR i IN p_osp_order_lines_tbl.FIRST..p_osp_order_lines_tbl.LAST LOOP
4867 IF (p_osp_order_lines_tbl(i).operation_flag = G_OP_CREATE AND
4868 p_osp_order_lines_tbl(i).shipment_creation_flag = G_YES_FLAG) THEN
4869 --Jerry added on 10/19/2005
4870 --Adding the following logic to check whether really needs to create shipment
4871 --line because for the same tracked item instance with different service time
4872 --combination, we still need to create one set of shipment lines. This is
4873 --feature is added for fixing bug 4571305
4874
4875 l_create_ship_line := TRUE;
4876 IF l_oe_header_id IS NOT NULL THEN
4877 OPEN check_ship_line_exists(p_osp_order_lines_tbl(i).inventory_item_id,
4878 p_osp_order_lines_tbl(i).inventory_org_id,
4879 p_osp_order_lines_tbl(i).serial_number,
4880 p_osp_order_lines_tbl(i).osp_order_id);
4881 FETCH check_ship_line_exists INTO g_dummy_char;
4882 IF check_ship_line_exists%FOUND THEN
4883 l_create_ship_line := FALSE;
4884 ELSIF i > p_osp_order_lines_tbl.FIRST THEN
4885 FOR j IN p_osp_order_lines_tbl.FIRST .. i-1 LOOP
4886 IF (p_osp_order_lines_tbl(i).inventory_item_id = p_osp_order_lines_tbl(j).inventory_item_id AND
4887 p_osp_order_lines_tbl(i).inventory_org_id = p_osp_order_lines_tbl(j).inventory_org_id AND
4888 p_osp_order_lines_tbl(i).serial_number = p_osp_order_lines_tbl(j).serial_number AND
4889 p_osp_order_lines_tbl(i).osp_order_id = p_osp_order_lines_tbl(j).osp_order_id) THEN
4890 l_create_ship_line := FALSE;
4891 EXIT;
4892 END IF;
4893 END LOOP;
4894 END IF;
4895 CLOSE check_ship_line_exists;
4896 ELSIF (l_oe_header_id IS NULL AND i > p_osp_order_lines_tbl.FIRST) THEN
4897 FOR j IN p_osp_order_lines_tbl.FIRST .. i-1 LOOP
4898 IF (p_osp_order_lines_tbl(i).inventory_item_id = p_osp_order_lines_tbl(j).inventory_item_id AND
4899 p_osp_order_lines_tbl(i).inventory_org_id = p_osp_order_lines_tbl(j).inventory_org_id AND
4900 p_osp_order_lines_tbl(i).serial_number = p_osp_order_lines_tbl(j).serial_number AND
4901 p_osp_order_lines_tbl(i).osp_order_id = p_osp_order_lines_tbl(j).osp_order_id) THEN
4902 l_create_ship_line := FALSE;
4903 EXIT;
4904 END IF;
4905 END LOOP;
4906 END IF;
4907
4908 IF l_create_ship_line THEN
4909 l_oe_lines_tbl(k).header_id := l_oe_header_id;
4910 l_oe_lines_tbl(k).line_type_id := FND_PROFILE.VALUE('AHL_OSP_OE_SHIP_ONLY_ID');
4911 l_oe_lines_tbl(k).osp_order_id := p_osp_order_lines_tbl(i).osp_order_id;
4912 l_oe_lines_tbl(k).osp_line_id := p_osp_order_lines_tbl(i).osp_order_line_id;
4913 l_oe_lines_tbl(k).ship_from_org_id := p_osp_order_lines_tbl(i).inventory_org_id;
4914 /* The following will be derived from Shipment API
4915 l_oe_lines_tbl(k).inventory_item_id := p_osp_order_lines_tbl(i).inventory_item_id;
4916 l_oe_lines_tbl(k).inventory_org_id := p_osp_order_lines_tbl(i).inventory_org_id;
4917 l_oe_lines_tbl(k).subinventory := p_osp_order_lines_tbl(i).sub_inventory;
4918 l_oe_lines_tbl(k).serial_number := p_osp_order_lines_tbl(i).serial_number;
4919 l_oe_lines_tbl(k).lot_number := p_osp_order_lines_tbl(i).lot_number;
4920 */
4921 l_oe_lines_tbl(k).osp_line_flag := G_YES_FLAG;
4922 l_oe_lines_tbl(k).operation := G_OP_CREATE;
4923
4924 l_oe_lines_tbl(k+1).header_id := l_oe_header_id;
4925 l_oe_lines_tbl(k+1).line_type_id := FND_PROFILE.VALUE('AHL_OSP_OE_RETURN_ID');
4926 l_oe_lines_tbl(k+1).osp_order_id := p_osp_order_lines_tbl(i).osp_order_id;
4927 l_oe_lines_tbl(k+1).osp_line_id := p_osp_order_lines_tbl(i).osp_order_line_id;
4928 l_oe_lines_tbl(k+1).ship_from_org_id := p_osp_order_lines_tbl(i).inventory_org_id;
4929 /* The following will be derived from Shipment API
4930 l_oe_lines_tbl(k+1).inventory_item_id := p_osp_order_lines_tbl(i).inventory_item_id;
4931 l_oe_lines_tbl(k+1).inventory_org_id := p_osp_order_lines_tbl(i).inventory_org_id;
4932 l_oe_lines_tbl(k+1).subinventory := p_osp_order_lines_tbl(i).sub_inventory;
4933 l_oe_lines_tbl(k+1).serial_number := p_osp_order_lines_tbl(i).serial_number;
4934 l_oe_lines_tbl(k+1).lot_number := p_osp_order_lines_tbl(i).lot_number;
4935 */
4936 l_oe_lines_tbl(k+1).osp_line_flag := G_YES_FLAG;
4937 l_oe_lines_tbl(k+1).operation := G_OP_CREATE;
4938 --other attributes to populate
4939 k := k+2;
4940 END IF;
4941 END IF;
4942 END LOOP;
4943 IF (l_oe_lines_tbl.COUNT > 0 AND FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
4944 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
4945 G_LOG_PREFIX||'create_shipment','Before calling Shipment API: process_order and the parameters are'||
4946 'oe_header='||l_oe_header_rec.header_id||' header_oper_flag='||l_oe_header_rec.operation||
4947 'oe_line1_osp_order_id='||l_oe_lines_tbl(1).osp_order_id||'oe_line2_osp_line_id='||l_oe_lines_tbl(1).osp_line_id||
4948 'oe_line_operation='||l_oe_lines_tbl(1).operation);
4949 END IF;
4950 AHL_OSP_SHIPMENT_PUB.process_order(
4951 p_api_version => 1.0,
4952 p_init_msg_list => FND_API.G_FALSE,
4953 p_commit => FND_API.G_FALSE,
4954 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
4955 --Changed by mpothuku on 14-Dec-05 to differentiate the call from here and from
4956 --Shipment Line Details UI. Note that Shipment Line Details will be using OAF as the p_module_type
4957 p_module_type => NULL,--G_OAF_MODULE,
4958 p_x_header_rec => l_oe_header_rec,
4959 p_x_lines_tbl => l_oe_lines_tbl,
4960 x_return_status => l_return_status,
4961 x_msg_count => l_msg_count,
4962 x_msg_data => l_msg_data);
4963 END IF;
4964 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
4965 RAISE FND_API.G_EXC_ERROR;
4966 ELSIF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
4967 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4968 END IF;
4969 END IF;
4970
4971 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
4972 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
4973 G_LOG_PREFIX||'create_shipment',
4974 'End: after calling shipment creation API and x_return_status='||l_return_status);
4975 END IF;
4976 END create_shipment;
4977
4978 PROCEDURE validate_order_line_creation(p_x_osp_order_line_rec IN OUT NOCOPY osp_order_line_rec_type)
4979 IS
4980 CURSOR check_physical_item(c_inventory_item_id NUMBER, c_inventory_org_id NUMBER) IS
4981 SELECT organization_id,
4982 inventory_item_id,
4983 concatenated_segments,
4984 primary_uom_code,
4985 serial_number_control_code,
4986 lot_control_code,
4987 comms_nl_trackable_flag
4988 FROM mtl_system_items_kfv
4989 WHERE inventory_item_id = c_inventory_item_id
4990 AND organization_id = c_inventory_org_id;
4991 l_check_physical_item check_physical_item%ROWTYPE;
4992 CURSOR check_sub_inventory(c_organization_id NUMBER, c_sub_inventory VARCHAR2) IS
4993 SELECT 'X'
4994 FROM mtl_secondary_inventories
4995 WHERE organization_id = c_organization_id
4996 AND secondary_inventory_name = c_sub_inventory;
4997 CURSOR check_serial_number (c_inv_item_id NUMBER, c_serial_number VARCHAR2) IS
4998 SELECT 'X'
4999 FROM mtl_serial_numbers
5000 WHERE inventory_item_id = c_inv_item_id
5001 AND serial_number = c_serial_number;
5002 CURSOR check_lot_number (c_inv_item_id NUMBER, c_org_id NUMBER, c_lot_number VARCHAR2) IS
5003 SELECT 'X'
5004 FROM mtl_lot_numbers
5005 WHERE inventory_item_id = c_inv_item_id
5006 AND organization_id = c_org_id
5007 AND lot_number = c_lot_number;
5008
5009 -- Modified by mpothuku on 27-Feb-06 to fix the Perf Bug #4919164 and also added subinventory to
5010 --calculate the onhand quantity correctly.
5011 CURSOR get_onhand_quantity(c_inv_item_id NUMBER, c_inv_org_id NUMBER, c_subinv VARCHAR2, c_lot_number VARCHAR2) IS
5012 --Added by mpothuku on 23rd Aug, 06 to fix the Bug 5252627
5013 SELECT ahl_osp_queries_pvt.get_onhand_quantity(c_inv_org_id, c_subinv, c_inv_item_id, c_lot_number) onhand_quantity, primary_uom_code uom_code
5014 FROM mtl_system_items_b
5015 WHERE inventory_item_id = c_inv_item_id
5016 AND organization_id = c_inv_org_id;
5017 CURSOR check_phy_ser_item_unique(c_osp_order_id NUMBER,
5018 c_service_item_id NUMBER,
5019 c_inv_item_id NUMBER,
5020 c_inv_org_id NUMBER,
5021 c_lot_number VARCHAR2,
5022 c_serial_number VARCHAR2) IS
5023 SELECT 'X'
5024 FROM ahl_osp_order_lines
5025 WHERE osp_order_id = c_osp_order_id
5026 AND ((service_item_id = c_service_item_id) OR
5027 (service_item_id IS NULL AND c_service_item_id IS NULL))
5028 AND inventory_item_id = c_inv_item_id
5029 AND inventory_org_id = c_inv_org_id
5030 AND ((lot_number IS NULL AND c_lot_number IS NULL) OR (lot_number = c_lot_number))
5031 AND ((serial_number IS NULL AND c_serial_number IS NULL) OR (serial_number = c_serial_number));
5032 CURSOR check_phy_item_unique(c_osp_order_id NUMBER, c_inv_item_id NUMBER) IS
5033 SELECT 'X'
5034 FROM ahl_osp_order_lines
5035 WHERE inventory_item_id = c_inv_item_id
5036 AND osp_order_id = c_osp_order_id;
5037
5038 --yazhou 22-Aug-2006 starts
5039 -- Bug fix#5479266
5040
5041 /*
5042 CURSOR check_osp_order_unique(c_osp_order_id NUMBER, c_inventory_item_id NUMBER,
5043 c_inventory_org_id NUMBER, c_serial_number VARCHAR2) IS
5044 SELECT 'X'
5045 FROM ahl_osp_order_lines ospl, ahl_osp_orders_b osp
5046 WHERE ospl.osp_order_id = osp.osp_order_id
5047 AND osp.status_code <> 'CLOSED'
5048 AND ospl.status_code is null
5049 AND ospl.inventory_item_id = c_inventory_item_id
5050 AND ospl.inventory_org_id = c_inventory_org_id
5051 AND NVL (ospl.serial_number, 'XXX') = NVL (c_serial_number, 'XXX')
5052 AND osp.osp_order_id <> c_osp_order_id;
5053 */
5054 -- Added by jaramana on January 10, 2008 for the Bug 5547870/5673279
5055 CURSOR check_osp_order_unique(c_osp_order_id NUMBER, c_inventory_item_id NUMBER,
5056 c_inventory_org_id NUMBER, c_serial_number VARCHAR2) IS
5057 SELECT 'X'
5058 FROM ahl_osp_order_lines ospl, ahl_osp_orders_b osp, oe_order_lines_all oelship
5059 WHERE ospl.osp_order_id = osp.osp_order_id
5060 AND osp.status_code <> 'CLOSED'
5061 AND oelship.LINE_ID = ospl.OE_SHIP_LINE_ID
5062 --The order line should not be closed and should not be cancelled to be considered in the uniqueness check
5063 AND (nvl(oelship.cancelled_flag, 'N') <> 'Y' OR nvl(oelship.flow_status_code, 'XXX') <> 'CANCELLED')
5064 AND (oelship.open_flag <> 'N' OR nvl(oelship.flow_status_code, 'XXX') <> 'CLOSED')
5065 AND ospl.inventory_item_id = c_inventory_item_id
5066 AND ospl.inventory_org_id = c_inventory_org_id
5067 AND NVL (ospl.serial_number, 'XXX') = NVL (c_serial_number, 'XXX')
5068 AND osp.osp_order_id <> c_osp_order_id;
5069
5070 -- Added by jaramana on January 10, 2008 for the Bug 5358438/5967633/5417460
5071 CURSOR get_wo_item_attrs(c_workorder_id NUMBER) IS
5072 SELECT vts.inventory_item_id,
5073 vst.organization_id,
5074 csii.lot_number,
5075 csii.serial_number,
5076 csii.quantity,
5077 csii.unit_of_measure item_instance_uom,
5078 arb.service_item_id,
5079 mtls.description service_item_description,
5080 mtls.primary_uom_code service_item_uom
5081 FROM ahl_workorders wo,
5082 ahl_visits_b vst,
5083 ahl_visit_tasks_b vts,
5084 csi_item_instances csii,
5085 mtl_system_items_kfv mtls,
5086 ahl_routes_b arb
5087 WHERE workorder_id = c_workorder_id
5088 AND wo.visit_task_id = vts.visit_task_id
5089 AND vst.visit_id = vts.visit_id
5090 AND wo.route_id = arb.route_id(+)
5091 AND arb.service_item_org_id = mtls.organization_id(+)
5092 AND arb.service_item_id = mtls.inventory_item_id(+)
5093 AND vts.instance_id = csii.instance_id;
5094
5095 -- Added by jaramana on January 10, 2008 for the Bug 5358438/5967633/5417460
5096 --Get the PO Line attributes and the need_by_date from the first record of po_line_locations_all
5097 CURSOR get_po_line_attrs(c_po_line_id NUMBER) IS
5098 SELECT pol.line_num,
5099 pol.item_id,
5100 pol.item_description,
5101 pol.line_type_id,
5102 uom.uom_code,
5103 pol.quantity,
5104 (select min(need_by_date)
5105 from po_line_locations_all
5106 where po_line_id = pol.po_line_id
5107 and po_header_id = pol.po_header_id) need_by_date
5108 FROM po_lines_all pol,
5109 mtl_units_of_measure_vl uom
5110 WHERE pol.po_line_id = c_po_line_id
5111 AND uom.unit_of_measure = pol.unit_meas_lookup_code;
5112 -- jaramana January 10, 2008 Ends
5113 --yazhou 22-Aug-2006 ends
5114
5115 l_vendor_id NUMBER;
5116 l_vendor_site_id NUMBER;
5117 l_vendor_contact_id NUMBER;
5118 l_quantity NUMBER;
5119 l_onhand_quantity NUMBER;
5120 l_uom_code VARCHAR2(3);
5121 l_po_line_attrs get_po_line_attrs%ROWTYPE;
5122 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.validate_order_line_creation';
5123
5124 BEGIN
5125 --Suppose all value id conversion has been done.
5126 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
5127 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, G_LOG_PREFIX || '.validate_order_line_creation', 'Begin:');
5128 END IF;
5129 --For OAF, we decided to pass null when you want to change it to null, the old value if there is no
5130 --change.
5131 IF nvl(g_module_type, 'NULL') <> G_OAF_MODULE THEN
5132 default_unchanged_order_line(p_x_osp_order_line_rec);
5133 END IF;
5134
5135 --And need to adde value to id conversion here
5136 convert_order_line_val_to_id(p_x_osp_order_line_rec);
5137 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
5138 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, G_LOG_PREFIX || 'create_osp_order_line',
5139 'osp_order_id='||p_x_osp_order_line_rec.osp_order_id);
5140 END IF;
5141 --Validate osp_order_id
5142 BEGIN
5143
5144 -- yazhou 28-jul-2006 starts
5145 -- bug#5417460
5146 IF p_x_osp_order_line_rec.po_line_id is not null and p_x_osp_order_line_rec.workorder_id is not null then
5147 SELECT osp_order_id INTO g_dummy_num
5148 FROM ahl_osp_orders_b
5149 WHERE osp_order_id = p_x_osp_order_line_rec.osp_order_id
5150 AND status_code = G_OSP_PO_CREATED_STATUS
5151 -- Added by jaramana on January 10, 2008 for the Bug 5358438/5967633/5417460
5152 --Pos are not applying to the other order types.
5153 AND order_type_code IN (G_OSP_ORDER_TYPE_SERVICE, G_OSP_ORDER_TYPE_EXCHANGE)
5154 -- Added by jaramana on January 10, 2008 for the Requisition ER 6034236
5155 --If we are creating an osp order line based on PO line that is created from the Purchasing forms, then
5156 --the work order selected for the order Line, should not be associated with any open order lines
5157 --Note that instead of status_code not in, we could have use status_code is null as well.
5158 AND not exists (select 1
5159 from ahl_osp_order_lines
5160 where workorder_id =p_x_osp_order_line_rec.workorder_id
5161 and nvl(status_code, 'X') not in (G_OL_PO_CANCELLED_STATUS, G_OL_PO_DELETED_STATUS, G_OL_REQ_CANCELLED_STATUS, G_OL_REQ_DELETED_STATUS));
5162 -- jaramana End
5163 ELSE
5164 SELECT osp_order_id INTO g_dummy_num
5165 FROM ahl_osp_orders_b
5166 WHERE osp_order_id = p_x_osp_order_line_rec.osp_order_id
5167 -- jaramana modified on January 10, 2008 for the Requisition ER 6034236 (Added G_OSP_REQ_SUB_FAILED_STATUS)
5168 AND status_code IN (G_OSP_ENTERED_STATUS, G_OSP_SUB_FAILED_STATUS, G_OSP_REQ_SUB_FAILED_STATUS);
5169 -- jaramana End
5170 END IF;
5171 -- yazhou 28-jul-2006 ends
5172
5173 EXCEPTION
5174 WHEN NO_DATA_FOUND THEN
5175 FND_MESSAGE.set_name('AHL', 'AHL_OSP_ORD_INVALID');
5176 FND_MSG_PUB.add;
5177 END;
5178
5179 -- Added by jaramana on January 10, 2008 for the Requisition ER 6034236 (partial fix for the Bug 5358438/5967633/5417460)
5180 --po_line_id should be passed only along with the work_order_id
5181 --value to id conversion should already have taken place, so even if the user passes job_number,
5182 --we would have derived the workorder_id
5183 IF p_x_osp_order_line_rec.po_line_id is not null and p_x_osp_order_line_rec.workorder_id is not null THEN
5184 validate_po_line(p_x_osp_order_line_rec.po_line_id, p_x_osp_order_line_rec.osp_order_id);
5185 ELSIF (p_x_osp_order_line_rec.po_line_id is not null and p_x_osp_order_line_rec.workorder_id is null) THEN
5186 FND_MESSAGE.set_name('AHL', 'AHL_OSP_WO_NLL_CR_POL');
5187 FND_MSG_PUB.add;
5188 END IF;
5189 -- jaramna End
5190
5191 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
5192 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, G_LOG_PREFIX || '.validate_order_line_creation', 'item='||p_x_osp_order_line_rec.inventory_item_id||'org='||p_x_osp_order_line_rec.inventory_org_id);
5193 END IF;
5194 IF (p_x_osp_order_line_rec.workorder_id IS NULL AND p_x_osp_order_line_rec.inventory_item_id IS NULL) THEN
5195 FND_MESSAGE.set_name('AHL', 'AHL_OSP_WO_ITEM_ALL_NULL');
5196 FND_MSG_PUB.add;
5197 --Validate workorder_id (borrow the old code)
5198 ELSIF(p_x_osp_order_line_rec.workorder_id IS NOT NULL) THEN
5199 validate_workorder(p_x_osp_order_line_rec.workorder_id);
5200 --Validate physical item
5201 ELSIF (p_x_osp_order_line_rec.inventory_item_id IS NOT NULL) THEN
5202 IF (p_x_osp_order_line_rec.inventory_org_id IS NULL) THEN
5203 FND_MESSAGE.set_name('AHL', 'AHL_OSP_ITEM_ORG_NULL');
5204 FND_MSG_PUB.add;
5205 END IF;
5206 OPEN check_physical_item(p_x_osp_order_line_rec.inventory_item_id,
5207 p_x_osp_order_line_rec.inventory_org_id);
5208 FETCH check_physical_item INTO l_check_physical_item;
5209 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
5210 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, G_LOG_PREFIX || '.validate_order_line_creation', 'track_flag='||l_check_physical_item.comms_nl_trackable_flag);
5211 END IF;
5212 IF check_physical_item%NOTFOUND THEN
5213 FND_MESSAGE.set_name('AHL', 'AHL_OSP_PHY_ITEM_INVALID');
5214 FND_MSG_PUB.add;
5215 ELSE
5216 IF (p_x_osp_order_line_rec.sub_inventory IS NOT NULL) THEN
5217 OPEN check_sub_inventory(p_x_osp_order_line_rec.inventory_org_id,
5218 p_x_osp_order_line_rec.sub_inventory);
5219 FETCH check_sub_inventory INTO g_dummy_char;
5220 IF check_sub_inventory%NOTFOUND THEN
5221 FND_MESSAGE.set_name('AHL', 'AHL_OSP_SUB_INV_INVALID');
5222 FND_MSG_PUB.add;
5223 END IF;
5224 CLOSE check_sub_inventory;
5225 END IF;
5226
5227 --Non tracked physical item's quantity (to be serviced) is manadatory
5228 IF (nvl(l_check_physical_item.comms_nl_trackable_flag, 'N')='N' AND
5229 (p_x_osp_order_line_rec.inventory_item_quantity IS NULL)) THEN
5230 FND_MESSAGE.set_name('AHL', 'AHL_OSP_PHY_ITEM_QTY_REQUIRED');
5231 FND_MSG_PUB.add;
5232 END IF;
5233
5234 /*
5235 Comment Added by mpothuku on 27-Feb-06: May need to revise this logic
5236 as the checks below will not cater to serial and lot controlled items
5237 */
5238 IF l_check_physical_item.serial_number_control_code IN (2, 5, 6) THEN
5239 OPEN check_serial_number(p_x_osp_order_line_rec.inventory_item_id,
5240 p_x_osp_order_line_rec.serial_number);
5241 FETCH check_serial_number INTO g_dummy_char;
5242 IF check_serial_number%NOTFOUND THEN
5243 FND_MESSAGE.set_name('AHL', 'AHL_OSP_PHY_ITEM_SN_INVALID');
5244 FND_MSG_PUB.add;
5245 ELSIF p_x_osp_order_line_rec.inventory_item_quantity <> 1 THEN
5246 FND_MESSAGE.set_name('AHL', 'AHL_OSP_PHY_ITEM_QT_INVALID');
5247 FND_MSG_PUB.add;
5248 END IF;
5249 CLOSE check_serial_number;
5250 ELSIF l_check_physical_item.lot_control_code = 2 THEN
5251 OPEN check_lot_number(p_x_osp_order_line_rec.inventory_item_id,
5252 p_x_osp_order_line_rec.inventory_org_id,
5253 p_x_osp_order_line_rec.lot_number);
5254 FETCH check_lot_number INTO g_dummy_char;
5255 IF check_lot_number%NOTFOUND THEN
5256 FND_MESSAGE.set_name('AHL', 'AHL_OSP_PHY_ITEM_LOT_INVALID');
5257 FND_MSG_PUB.add;
5258 END IF;
5259 CLOSE check_lot_number;
5260 --Validate the onhand quantity with the quantity to be serviced
5261 --Subinventory_code added by mpothuku on 27-Feb-06 to fix the Perf bug #4919164
5262 ELSIF nvl(l_check_physical_item.comms_nl_trackable_flag, 'N')='N' THEN
5263 OPEN get_onhand_quantity(p_x_osp_order_line_rec.inventory_item_id,
5264 p_x_osp_order_line_rec.inventory_org_id,
5265 p_x_osp_order_line_rec.sub_inventory,
5266 --Added by mpothuku on 23rd Aug, 06 to fix the Bug 5252627
5267 p_x_osp_order_line_rec.lot_number);
5268 FETCH get_onhand_quantity INTO l_onhand_quantity, l_uom_code;
5269 IF get_onhand_quantity%NOTFOUND THEN
5270 FND_MESSAGE.set_name('AHL', 'AHL_OSP_PHY_ITEM_INVALID');
5271 FND_MSG_PUB.add;
5272 END IF;
5273 CLOSE get_onhand_quantity;
5274 IF (l_onhand_quantity IS NOT NULL AND l_uom_code IS NOT NULL) THEN
5275 --l_uom_code is primary_uom_code
5276 --convert the inventory_item_uom to l_uom_code
5277 IF (p_x_osp_order_line_rec.inventory_item_quantity IS NOT NULL AND
5278 p_x_osp_order_line_rec.inventory_item_uom IS NOT NULL) THEN
5279 l_quantity := inv_convert.inv_um_convert(
5280 item_id => p_x_osp_order_line_rec.inventory_item_id,
5281 precision => 6,
5282 from_quantity => p_x_osp_order_line_rec.inventory_item_quantity,
5283 from_unit => p_x_osp_order_line_rec.inventory_item_uom,
5284 to_unit => l_uom_code,
5285 from_name => NULL,
5286 to_name => NULL);
5287 IF (l_quantity > l_onhand_quantity) THEN
5288 FND_MESSAGE.set_name('AHL', 'AHL_OSP_ITEM_ONHAND_LESS_SERV');
5289 FND_MSG_PUB.add;
5290 END IF;
5291 END IF;
5292 END IF;
5293 END IF;
5294 END IF;
5295 CLOSE check_physical_item;
5296 END IF;
5297
5298 -- Added by jaramana on January 10, 2008 for the Bug 5358438/5967633/5417460
5299 /*
5300 1. Retrieve the ITEM_ID, ITEM_DESCRIPTION, UNIT_MEAS_LOOKUP_CODE, QUANTITY, LINE_TYPE_ID
5301 from PO_LINES_All corresponding to the PO_LINE_ID passed
5302 2. ITEM_ID and ITEM_DESCRIPTION cannot both be null
5303 3. If ITEM_ID is not null, validate it agains the work order's service_item_id
5304 6. UNIT_MEAS_LOOKUP_CODE, QUANTITY, LINE_TYPE_ID, NEED_BY_DATE are mandatory
5305 */
5306
5307 --We already added the check that if the po_line_id is not null, the workorder_id also should not be null
5308 IF(p_x_osp_order_line_rec.po_line_id is NOT NULL) THEN
5309 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
5310 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'p_x_osp_order_line_rec.po_line_id='||p_x_osp_order_line_rec.po_line_id);
5311 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'p_x_osp_order_line_rec.workorder_id='||p_x_osp_order_line_rec.workorder_id);
5312 END IF;
5313
5314 OPEN get_wo_item_attrs(p_x_osp_order_line_rec.workorder_id);
5315 FETCH get_wo_item_attrs INTO p_x_osp_order_line_rec.inventory_item_id,
5316 p_x_osp_order_line_rec.inventory_org_id,
5317 p_x_osp_order_line_rec.lot_number,
5318 p_x_osp_order_line_rec.serial_number,
5319 p_x_osp_order_line_rec.inventory_item_quantity,
5320 p_x_osp_order_line_rec.inventory_item_uom,
5321 p_x_osp_order_line_rec.service_item_id,
5322 p_x_osp_order_line_rec.service_item_description,
5323 p_x_osp_order_line_rec.service_item_uom_code;
5324
5325 CLOSE get_wo_item_attrs;
5326
5327
5328 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
5329 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'p_x_osp_order_line_rec.service_item_id ='||p_x_osp_order_line_rec.service_item_id);
5330 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'p_x_osp_order_line_rec.service_item_description ='||p_x_osp_order_line_rec.service_item_description);
5331 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'p_x_osp_order_line_rec.service_item_uom_code ='||p_x_osp_order_line_rec.service_item_uom_code);
5332 END IF;
5333
5334 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
5335 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'p_x_osp_order_line_rec.po_line_id='||p_x_osp_order_line_rec.po_line_id);
5336 END IF;
5337
5338 OPEN get_po_line_attrs(p_x_osp_order_line_rec.po_line_id);
5339 FETCH get_po_line_attrs INTO l_po_line_attrs.line_num,
5340 l_po_line_attrs.item_id,
5341 l_po_line_attrs.item_description,
5342 l_po_line_attrs.line_type_id,
5343 l_po_line_attrs.uom_code,
5344 l_po_line_attrs.quantity,
5345 l_po_line_attrs.need_by_date;
5346 CLOSE get_po_line_attrs;
5347
5348 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
5349 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'l_po_line_attrs.line_num ='||l_po_line_attrs.line_num);
5350 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'l_po_line_attrs.item_id ='||l_po_line_attrs.item_id);
5351 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'l_po_line_attrs.item_description ='||l_po_line_attrs.item_description);
5352 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'l_po_line_attrs.line_type_id ='||l_po_line_attrs.line_type_id);
5353 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'l_po_line_attrs.uom_code ='||l_po_line_attrs.uom_code);
5354 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'l_po_line_attrs.quantity ='||l_po_line_attrs.quantity);
5355 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'l_po_line_attrs.need_by_date ='||l_po_line_attrs.need_by_date);
5356 END IF;
5357
5358
5359 IF (l_po_line_attrs.item_id is null and l_po_line_attrs.item_description is null) THEN
5360 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_POL_ITEM_ID_DESC_NLL');
5361 FND_MESSAGE.Set_Token('LINE_NUM', l_po_line_attrs.line_num);
5362 FND_MSG_PUB.ADD;
5363 END IF;
5364
5365 IF (l_po_line_attrs.line_type_id is null) THEN
5366 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_POL_TYPE_NLL');
5367 FND_MESSAGE.Set_Token('LINE_NUM', l_po_line_attrs.line_num);
5368 FND_MSG_PUB.ADD;
5369 END IF;
5370
5371 IF (l_po_line_attrs.uom_code is null) THEN
5372 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_POL_UOM_NLL');
5373 FND_MESSAGE.Set_Token('LINE_NUM', l_po_line_attrs.line_num);
5374 FND_MSG_PUB.ADD;
5375 END IF;
5376
5377 IF (l_po_line_attrs.quantity is null) THEN
5378 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_POL_QUANT_NLL');
5379 FND_MESSAGE.Set_Token('LINE_NUM', l_po_line_attrs.line_num);
5380 FND_MSG_PUB.ADD;
5381 END IF;
5382
5383 IF (l_po_line_attrs.need_by_date is null) THEN
5384 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_POL_NBDATE_NLL');
5385 FND_MESSAGE.Set_Token('LINE_NUM', l_po_line_attrs.line_num);
5386 FND_MSG_PUB.ADD;
5387 END IF;
5388
5389 END IF;
5390
5391 --If the po_line_id is passed validate the attributes got from the PO Line
5392 IF(p_x_osp_order_line_rec.po_line_id is NOT NULL) THEN
5393 /*
5394 Note that the messages below will not have PO line numbers associated. They will not ideally occur from
5395 front end as the front LOV already will filter records according to the conditions below
5396 and moreover the data from po_lines_all should not have the below errors unless manually changed in the tables
5397 */
5398 val_svc_item_vs_wo_svc_item (p_x_osp_order_line_rec.workorder_id, l_po_line_attrs.item_id);
5399 validate_service_item_uom(l_po_line_attrs.item_id, p_x_osp_order_line_rec.service_item_uom_code, p_x_osp_order_line_rec.inventory_org_id);
5400 IF(l_po_line_attrs.quantity <=0) THEN
5401 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_QUANT_VAL');
5402 FND_MESSAGE.Set_Token('QUANTITY', p_x_osp_order_line_rec.quantity);
5403 FND_MSG_PUB.ADD;
5404 END IF;
5405 validate_po_line_type(l_po_line_attrs.line_type_id);
5406 --Assign the attributes from the po line to the osp line
5407 --over-write the ones defined at the workorder route level
5408 p_x_osp_order_line_rec.service_item_id := l_po_line_attrs.item_id;
5409 p_x_osp_order_line_rec.service_item_description := l_po_line_attrs.item_description;
5410 p_x_osp_order_line_rec.service_item_uom_code := l_po_line_attrs.uom_code;
5411
5412 p_x_osp_order_line_rec.po_line_type_id := l_po_line_attrs.line_type_id;
5413 p_x_osp_order_line_rec.quantity := l_po_line_attrs.quantity;
5414 p_x_osp_order_line_rec.need_by_date := l_po_line_attrs.need_by_date;
5415
5416 ELSE --retain the existing logic
5417
5418 --validate service_item_id (simplfied the original one)
5419 --All the service item related attributes validations are applicable only
5420 --when the service item is provided
5421 /* Comment Added by mpothuku on 28-Feb-06: Note that for workorder based lines, the service item defined
5422 at the route level is not yet defaulted, so for such lines both the service_item_id and service_item_uom are null and also there is no need to validate these for the workorder based lines */
5423 IF (p_x_osp_order_line_rec.service_item_id IS NOT NULL) THEN
5424 validate_service_item_id(p_x_osp_order_line_rec.service_item_id, p_x_osp_order_line_rec.inventory_org_id);
5425 --validate service_item_description
5426 --it is not necessary to add the original one here.
5427 --validate sercice_item_uom (just borrowed the old one)
5428 validate_service_item_uom(p_x_osp_order_line_rec.service_item_id, p_x_osp_order_line_rec.service_item_uom_code, p_x_osp_order_line_rec.inventory_org_id);
5429 --validate sercice_item_quantity(quantity)
5430 IF (p_x_osp_order_line_rec.quantity IS NOT NULL AND p_x_osp_order_line_rec.quantity <> FND_API.G_MISS_NUM) THEN
5431 IF(p_x_osp_order_line_rec.quantity <=0) THEN
5432 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_QUANT_VAL');
5433 FND_MESSAGE.Set_Token('QUANTITY', p_x_osp_order_line_rec.quantity);
5434 FND_MSG_PUB.ADD;
5435 END IF;
5436 --quantity cannot be null when UOM is not null
5437 ELSIF (p_x_osp_order_line_rec.service_item_uom_code IS NOT NULL AND p_x_osp_order_line_rec.service_item_uom_code <> FND_API.G_MISS_CHAR) THEN
5438 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_QUANT_NLL');
5439 FND_MSG_PUB.ADD;
5440 END IF;
5441
5442 --Validate header vendor with physical, service item combination in line
5443 --validate_vendor_service_item(p_x_osp_order_line_rec);
5444 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
5445 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, G_LOG_PREFIX || '.validate_order_line_creation', 'Normal End.');
5446 END IF;
5447 END IF;
5448
5449 --yazhou 22-Aug-2006 starts
5450 -- Bug fix#5479266
5451 -- For serial controlled items, check whether another OSP order
5452 -- has already been created for the same item.
5453
5454 IF l_check_physical_item.serial_number_control_code IN (2, 5, 6) THEN
5455
5456 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
5457 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, G_LOG_PREFIX || '.validate_order_line_creation', 'osp_order_id='||p_x_osp_order_line_rec.osp_order_id||'lot_number='||p_x_osp_order_line_rec.lot_number);
5458 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, G_LOG_PREFIX || '.validate_order_line_creation', 'serial_number='||p_x_osp_order_line_rec.serial_number);
5459 END IF;
5460
5461 OPEN check_osp_order_unique(p_x_osp_order_line_rec.osp_order_id,
5462 p_x_osp_order_line_rec.inventory_item_id,
5463 p_x_osp_order_line_rec.inventory_org_id,
5464 p_x_osp_order_line_rec.serial_number);
5465
5466 FETCH check_osp_order_unique INTO g_dummy_char;
5467
5468 IF check_osp_order_unique%FOUND THEN
5469 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_PHY_ITEM_UNIUE');
5470 FND_MSG_PUB.ADD;
5471 END IF;
5472 CLOSE check_osp_order_unique;
5473 END IF;
5474 --yazhou 22-Aug-2006 ends
5475
5476 --For tracked item, same physical item and service item combination can only appear once in a given OSP order header
5477 --While for non tracked item, same physical item can only appear once in a given OSP order header
5478 IF (p_x_osp_order_line_rec.workorder_id IS NULL) THEN
5479 IF (nvl(l_check_physical_item.comms_nl_trackable_flag, 'N')='N') THEN
5480 OPEN check_phy_item_unique(p_x_osp_order_line_rec.osp_order_id,
5481 p_x_osp_order_line_rec.inventory_item_id);
5482 FETCH check_phy_item_unique INTO g_dummy_char;
5483 IF check_phy_item_unique%FOUND THEN
5484 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_PHY_ITEM_UNIUE');
5485 FND_MSG_PUB.ADD;
5486 END IF;
5487 CLOSE check_phy_item_unique;
5488 --ELSIF (p_x_osp_order_line_rec.service_item_id IS NOT NULL) THEN
5489 --The cursor query contains the case which service_item_id is null
5490 ELSE
5491 OPEN check_phy_ser_item_unique(p_x_osp_order_line_rec.osp_order_id,
5492 p_x_osp_order_line_rec.service_item_id,
5493 p_x_osp_order_line_rec.inventory_item_id,
5494 p_x_osp_order_line_rec.inventory_org_id,
5495 p_x_osp_order_line_rec.lot_number,
5496 p_x_osp_order_line_rec.serial_number);
5497 FETCH check_phy_ser_item_unique INTO g_dummy_char;
5498 IF check_phy_ser_item_unique%FOUND THEN
5499 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_PHY_SER_ITEM_UNIUE');
5500 FND_MSG_PUB.ADD;
5501 END IF;
5502 CLOSE check_phy_ser_item_unique;
5503 END IF;
5504 END IF;
5505
5506 END IF;--IF(p_x_osp_order_line_rec.po_line_id is NOT NULL)
5507 -- jaramana January 10, 2008 Bug 5358438/5967633/5417460 Ends
5508
5509 END validate_order_line_creation;
5510
5511 PROCEDURE update_osp_order_line(p_x_osp_order_line_rec IN OUT NOCOPY osp_order_line_rec_type)
5512 IS
5513 l_osp_line_id NUMBER;
5514 l_osp_line_number NUMBER;
5515 l_return_status VARCHAR2(1);
5516 l_organization_id NUMBER;
5517 l_inventory_item_id NUMBER;
5518 l_service_item_id NUMBER;
5519 l_service_duration NUMBER;
5520 BEGIN
5521 validate_order_line_update(p_x_osp_order_line_rec);
5522 --call table handler to update the record
5523 AHL_OSP_ORDER_LINES_PKG.update_row(
5524 p_osp_order_line_id => p_x_osp_order_line_rec.osp_order_line_id,
5525 p_object_version_number => p_x_osp_order_line_rec.object_version_number +1,
5526 p_osp_order_id => p_x_osp_order_line_rec.osp_order_id,
5527 p_osp_line_number => p_x_osp_order_line_rec.osp_line_number,
5528 p_status_code => p_x_osp_order_line_rec.status_code,
5529 p_po_line_type_id => p_x_osp_order_line_rec.po_line_type_id,
5530 p_service_item_id => p_x_osp_order_line_rec.service_item_id,
5531 p_service_item_description => p_x_osp_order_line_rec.service_item_description,
5532 p_service_item_uom_code => p_x_osp_order_line_rec.service_item_uom_code,
5533 p_need_by_date => TRUNC(p_x_osp_order_line_rec.need_by_date),
5534 p_ship_by_date => TRUNC(p_x_osp_order_line_rec.ship_by_date),
5535 p_po_line_id => p_x_osp_order_line_rec.po_line_id,
5536 p_oe_ship_line_id => p_x_osp_order_line_rec.oe_ship_line_id,
5537 p_oe_return_line_id => p_x_osp_order_line_rec.oe_return_line_id,
5538 p_workorder_id => p_x_osp_order_line_rec.workorder_id,
5539 p_operation_id => p_x_osp_order_line_rec.operation_id,
5540 p_quantity => p_x_osp_order_line_rec.quantity,
5541 p_exchange_instance_id => p_x_osp_order_line_rec.exchange_instance_id,
5542 p_inventory_item_id => p_x_osp_order_line_rec.inventory_item_id,
5543 p_inventory_org_id => p_x_osp_order_line_rec.inventory_org_id,
5544 p_inventory_item_uom => p_x_osp_order_line_rec.inventory_item_uom,
5545 p_inventory_item_quantity => p_x_osp_order_line_rec.inventory_item_quantity,
5546 p_sub_inventory => p_x_osp_order_line_rec.sub_inventory,
5547 p_lot_number => p_x_osp_order_line_rec.lot_number,
5548 p_serial_number => p_x_osp_order_line_rec.serial_number,
5549 -- Added by jaramana on January 10, 2008 for the Requisition ER 6034236
5550 p_po_req_line_id => p_x_osp_order_line_rec.po_req_line_id,
5551 -- jaramana End
5552 p_attribute_category => p_x_osp_order_line_rec.attribute_category,
5553 p_attribute1 => p_x_osp_order_line_rec.attribute1,
5554 p_attribute2 => p_x_osp_order_line_rec.attribute2,
5555 p_attribute3 => p_x_osp_order_line_rec.attribute3,
5556 p_attribute4 => p_x_osp_order_line_rec.attribute4,
5557 p_attribute5 => p_x_osp_order_line_rec.attribute5,
5558 p_attribute6 => p_x_osp_order_line_rec.attribute6,
5559 p_attribute7 => p_x_osp_order_line_rec.attribute7,
5560 p_attribute8 => p_x_osp_order_line_rec.attribute8,
5561 p_attribute9 => p_x_osp_order_line_rec.attribute9,
5562 p_attribute10 => p_x_osp_order_line_rec.attribute10,
5563 p_attribute11 => p_x_osp_order_line_rec.attribute11,
5564 p_attribute12 => p_x_osp_order_line_rec.attribute12,
5565 p_attribute13 => p_x_osp_order_line_rec.attribute13,
5566 p_attribute14 => p_x_osp_order_line_rec.attribute14,
5567 p_attribute15 => p_x_osp_order_line_rec.attribute15,
5568 p_last_updated_by => FND_GLOBAL.user_id,
5569 p_last_update_date => SYSDATE,
5570 p_last_update_login => FND_GLOBAL.login_id
5571 );
5572 END update_osp_order_line;
5573
5574 PROCEDURE validate_order_line_update(p_x_osp_order_line_rec IN OUT NOCOPY osp_order_line_rec_type)
5575 IS
5576 l_osp_line_id NUMBER;
5577 l_osp_line_number NUMBER;
5578 l_return_status VARCHAR2(1);
5579 l_organization_id NUMBER;
5580 l_inventory_item_id NUMBER;
5581 l_service_item_id NUMBER;
5582 l_service_duration NUMBER;
5583 l_trackable_flag VARCHAR2(1);
5584 l_header_status_code VARCHAR2(30);
5585 l_item_description VARCHAR2(240);
5586 l_desc_update_flag VARCHAR2(1);
5587 CURSOR osp_order_line_csr IS
5588 SELECT *
5589 FROM ahl_osp_order_lines
5590 WHERE osp_order_line_id = p_x_osp_order_line_rec.osp_order_line_id
5591 AND object_version_number= p_x_osp_order_line_rec.object_version_number;
5592 l_osp_order_line_rec osp_order_line_csr%ROWTYPE;
5593 CURSOR check_phy_ser_item_unique(c_osp_order_id NUMBER,
5594 c_service_item_id NUMBER,
5595 c_inv_item_id NUMBER,
5596 c_inv_org_id NUMBER,
5597 c_lot_number VARCHAR2,
5598 c_serial_number VARCHAR2) IS
5599 SELECT 'X'
5600 FROM ahl_osp_order_lines
5601 WHERE osp_order_id = c_osp_order_id
5602 AND ((service_item_id = c_service_item_id) OR
5603 (service_item_id IS NULL AND c_service_item_id IS NULL))
5604 AND inventory_item_id = c_inv_item_id
5605 AND inventory_org_id = c_inv_org_id
5606 AND ((lot_number IS NULL AND c_lot_number IS NULL) OR (lot_number = c_lot_number))
5607 AND ((serial_number IS NULL AND c_serial_number IS NULL) OR (serial_number = c_serial_number));
5608 CURSOR check_phy_item_unique(c_osp_order_id NUMBER, c_inv_item_id NUMBER) IS
5609 SELECT 'X'
5610 FROM ahl_osp_order_lines
5611 WHERE inventory_item_id = c_inv_item_id
5612 AND osp_order_id = c_osp_order_id;
5613 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.validate_order_line_update';
5614 --Added by mpothuku on 24-Mar-06 for ER: 4544654
5615 l_owrite_svc_desc_prf VARCHAR2(1);
5616 l_item_prefix VARCHAR2(240);
5617 l_serial_prefix VARCHAR2(240);
5618 l_inv_item_number VARCHAR2(40);
5619 l_svc_item_number VARCHAR2(40);
5620 --mpothuku end
5621 BEGIN
5622 --For OAF, the default logic may not be necessary
5623 --we decided to pass null when you want to change it to null, the old value if there is no change.
5624 IF nvl(g_module_type, 'NULL') <> G_OAF_MODULE THEN
5625 default_unchanged_order_line(p_x_osp_order_line_rec);
5626 END IF;
5627 convert_order_line_val_to_id(p_x_osp_order_line_rec);
5628 --Add the other validations here
5629 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
5630 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
5631 END IF;
5632 IF(p_x_osp_order_line_rec.osp_order_line_id IS NULL OR p_x_osp_order_line_rec.object_version_number IS NULL) THEN
5633 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_ID_OBJ_MISS');
5634 FND_MSG_PUB.ADD;
5635 ELSE
5636 OPEN osp_order_line_csr;
5637 FETCH osp_order_line_csr INTO l_osp_order_line_rec;
5638 IF (osp_order_line_csr%NOTFOUND) THEN
5639 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INVOP_OSP_LN_NFOUND');
5640 FND_MSG_PUB.ADD;
5641 ELSE
5642 --The following attributes can't be changed once created
5643 --osp_order_id can't be changed, and osp_order_id is required
5644 IF(p_x_osp_order_line_rec.osp_order_id IS NULL OR
5645 p_x_osp_order_line_rec.osp_order_id <> l_osp_order_line_rec.osp_order_id) THEN
5646 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_ORD_ID_CHG');
5647 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5648 FND_MSG_PUB.ADD;
5649 END IF;
5650 --osp_order_number can't be changed and osp_order_number is required
5651 IF(p_x_osp_order_line_rec.osp_line_number IS NULL OR
5652 p_x_osp_order_line_rec.osp_line_number <> l_osp_order_line_rec.osp_line_number) THEN
5653 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_LN_NUM_CHG');
5654 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5655 FND_MSG_PUB.ADD;
5656 END IF;
5657 --workorder_id can't be changed but workorder can be null
5658 IF((p_x_osp_order_line_rec.workorder_id <> l_osp_order_line_rec.workorder_id) OR
5659 (p_x_osp_order_line_rec.workorder_id IS NOT NULL AND l_osp_order_line_rec.workorder_id IS NULL) OR
5660 (p_x_osp_order_line_rec.workorder_id IS NULL AND l_osp_order_line_rec.workorder_id IS NOT NULL)) THEN
5661 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_WO_CHG');
5662 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5663 FND_MSG_PUB.ADD;
5664 END IF;
5665 --inventory_item_id can't be changed and inventory_item_id is always populated
5666 IF(p_x_osp_order_line_rec.inventory_item_id IS NULL OR
5667 p_x_osp_order_line_rec.inventory_item_id <> l_osp_order_line_rec.inventory_item_id) THEN
5668 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_ITEM_CHG');
5669 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5670 FND_MSG_PUB.ADD;
5671 END IF;
5672 --inventory_org_id can't be changed and inventory_org_id is always popluated
5673 IF(p_x_osp_order_line_rec.inventory_org_id IS NULL OR
5674 p_x_osp_order_line_rec.inventory_org_id <> l_osp_order_line_rec.inventory_org_id) THEN
5675 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_ORG_CHG');
5676 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5677 FND_MSG_PUB.ADD;
5678 END IF;
5679 --inventory_item_uom can't be changed and inventory_item_uom is always populated
5680 IF(p_x_osp_order_line_rec.inventory_item_uom IS NULL OR
5681 p_x_osp_order_line_rec.inventory_item_uom <> l_osp_order_line_rec.inventory_item_uom) THEN
5682 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_UOM_CHG');
5683 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5684 FND_MSG_PUB.ADD;
5685 END IF;
5686 --inventory_item_quantity can't be changed and inventory_item_quantity is always populated
5687 IF(p_x_osp_order_line_rec.inventory_item_quantity IS NULL OR
5688 p_x_osp_order_line_rec.inventory_item_quantity <> l_osp_order_line_rec.inventory_item_quantity) THEN
5689 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_QTY_CHG');
5690 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5691 FND_MSG_PUB.ADD;
5692 END IF;
5693 --sub_inventory can't be changed but sub_inventory can be null
5694 IF((p_x_osp_order_line_rec.sub_inventory <> l_osp_order_line_rec.sub_inventory) OR
5695 (p_x_osp_order_line_rec.sub_inventory IS NOT NULL AND l_osp_order_line_rec.sub_inventory IS NULL) OR
5696 (p_x_osp_order_line_rec.sub_inventory IS NULL AND l_osp_order_line_rec.sub_inventory IS NOT NULL)) THEN
5697 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_SUB_CHG');
5698 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5699 FND_MSG_PUB.ADD;
5700 END IF;
5701 --lot_number can't be changed but lot_number can be null
5702 IF((p_x_osp_order_line_rec.lot_number <> l_osp_order_line_rec.lot_number) OR
5703 (p_x_osp_order_line_rec.lot_number IS NOT NULL AND l_osp_order_line_rec.lot_number IS NULL) OR
5704 (p_x_osp_order_line_rec.lot_number IS NULL AND l_osp_order_line_rec.lot_number IS NOT NULL)) THEN
5705 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_LOT_CHG');
5706 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5707 FND_MSG_PUB.ADD;
5708 END IF;
5709 --serial_number can't be changed but serial_number can be null
5710 IF((p_x_osp_order_line_rec.serial_number <> l_osp_order_line_rec.serial_number) OR
5711 (p_x_osp_order_line_rec.serial_number IS NOT NULL AND l_osp_order_line_rec.serial_number IS NULL) OR
5712 (p_x_osp_order_line_rec.serial_number IS NULL AND l_osp_order_line_rec.serial_number IS NOT NULL)) THEN
5713 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_SERIAL_CHG');
5714 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5715 FND_MSG_PUB.ADD;
5716 END IF;
5717 -- this API does not allow to update SO line information, Shipment API needs to update
5718 -- OSP tables directly (is this the best approach?)
5719 --oe_ship_line_id can't be changed from this API, and it could be null.
5720 IF((p_x_osp_order_line_rec.oe_ship_line_id <> l_osp_order_line_rec.oe_ship_line_id) OR
5721 (p_x_osp_order_line_rec.oe_ship_line_id IS NOT NULL AND l_osp_order_line_rec.oe_ship_line_id IS NULL) OR
5722 (p_x_osp_order_line_rec.oe_ship_line_id IS NULL AND l_osp_order_line_rec.oe_ship_line_id IS NOT NULL)) THEN
5723 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_SHIP_ID_CHG');
5724 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5725 FND_MSG_PUB.ADD;
5726 END IF;
5727 --oe_return_line_id can't be changed from this API, and it could be null.
5728 IF((p_x_osp_order_line_rec.oe_return_line_id <> l_osp_order_line_rec.oe_return_line_id) OR
5729 (p_x_osp_order_line_rec.oe_return_line_id IS NOT NULL AND l_osp_order_line_rec.oe_return_line_id IS NULL) OR
5730 (p_x_osp_order_line_rec.oe_return_line_id IS NULL AND l_osp_order_line_rec.oe_return_line_id IS NOT NULL)) THEN
5731 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_RET_ID_CHG');
5732 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5733 FND_MSG_PUB.ADD;
5734 END IF;
5735 -- this API does not allow to update PO line information, PO API needs to update
5736 -- OSP tables directly (is this the best approach?)
5737 --po_line_id can't be changed from this API, and it could be null.
5738 IF((p_x_osp_order_line_rec.po_line_id <> l_osp_order_line_rec.po_line_id) OR
5739 (p_x_osp_order_line_rec.po_line_id IS NOT NULL AND l_osp_order_line_rec.po_line_id IS NULL) OR
5740 (p_x_osp_order_line_rec.po_line_id IS NULL AND l_osp_order_line_rec.po_line_id IS NOT NULL)) THEN
5741 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_POLINE_ID_CHG');
5742 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5743 FND_MSG_PUB.ADD;
5744 END IF;
5745
5746 -- Added by jaramana on January 10, 2008 for the Requisition ER 6034236
5747 -- this API does not allow to update PO line information, PO API needs to update OSP tables directly
5748 --po_req_line_id can't be changed from this API, and it could be null.
5749 IF((p_x_osp_order_line_rec.po_req_line_id <> l_osp_order_line_rec.po_req_line_id) OR
5750 (p_x_osp_order_line_rec.po_req_line_id IS NOT NULL AND l_osp_order_line_rec.po_req_line_id IS NULL) OR
5751 (p_x_osp_order_line_rec.po_req_line_id IS NULL AND l_osp_order_line_rec.po_req_line_id IS NOT NULL)) THEN
5752 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_REQLINE_ID_CHG');
5753 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5754 FND_MSG_PUB.ADD;
5755 END IF;
5756
5757 --po_line_type_id can't be changed from this API, and it could be null.
5758 IF((p_x_osp_order_line_rec.po_line_type_id <> l_osp_order_line_rec.po_line_type_id) OR
5759 (p_x_osp_order_line_rec.po_line_type_id IS NOT NULL AND l_osp_order_line_rec.po_line_type_id IS NULL) OR
5760 (p_x_osp_order_line_rec.po_line_type_id IS NULL AND l_osp_order_line_rec.po_line_type_id IS NOT NULL)) THEN
5761 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_POTYPE_ID_CHG');
5762 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5763 FND_MSG_PUB.ADD;
5764 END IF;
5765
5766 -- Added by jaramana on January 10, 2008 for the Requisition ER 6034236
5767 --If the status is other than 'ENTERED', 'SUBMISSION_FAILED', 'REQ_SUBMISSION_FAILED' we should not allow updates of
5768 --service_item_id, service_item_uom_code, quantity and need_by_date
5769 SELECT status_code INTO l_header_status_code
5770 FROM ahl_osp_orders_b
5771 WHERE osp_order_id = p_x_osp_order_line_rec.osp_order_id;
5772
5773 IF(l_header_status_code NOT IN (G_OSP_ENTERED_STATUS, G_OSP_SUB_FAILED_STATUS, G_OSP_REQ_SUB_FAILED_STATUS)) THEN
5774 --service_item_id can't be changed from this API, and it could be null.
5775 IF((p_x_osp_order_line_rec.service_item_id <> l_osp_order_line_rec.service_item_id) OR
5776 (p_x_osp_order_line_rec.service_item_id IS NOT NULL AND l_osp_order_line_rec.service_item_id IS NULL) OR
5777 (p_x_osp_order_line_rec.service_item_id IS NULL AND l_osp_order_line_rec.service_item_id IS NOT NULL)) THEN
5778 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_SER_ID_CHG');
5779 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5780 FND_MSG_PUB.ADD;
5781 END IF;
5782
5783 --service_item_description can't be changed from this API, and it could be null.
5784 IF((p_x_osp_order_line_rec.service_item_description <> l_osp_order_line_rec.service_item_description) OR
5785 (p_x_osp_order_line_rec.service_item_description IS NOT NULL AND l_osp_order_line_rec.service_item_description IS NULL) OR
5786 (p_x_osp_order_line_rec.service_item_description IS NULL AND l_osp_order_line_rec.service_item_description IS NOT NULL)) THEN
5787 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_SER_DESC_CHG');
5788 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5789 FND_MSG_PUB.ADD;
5790 END IF;
5791
5792 /*
5793 --exchange_instance_id can't be changed from this API, and it could be null.
5794 IF((p_x_osp_order_line_rec.exchange_instance_id <> l_osp_order_line_rec.exchange_instance_id) OR
5795 (p_x_osp_order_line_rec.exchange_instance_id IS NOT NULL AND l_osp_order_line_rec.exchange_instance_id IS NULL) OR
5796 (p_x_osp_order_line_rec.exchange_instance_id IS NULL AND l_osp_order_line_rec.exchange_instance_id IS NOT NULL)) THEN
5797 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_EXCH_ID_CHG');
5798 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5799 FND_MSG_PUB.ADD;
5800 END IF;
5801 */
5802
5803 --service_item_uom cannot change and cannot be null
5804 IF(p_x_osp_order_line_rec.service_item_uom_code IS NULL OR
5805 (p_x_osp_order_line_rec.service_item_uom_code <> l_osp_order_line_rec.service_item_uom_code) ) THEN
5806 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_SER_UOM_CHG');
5807 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5808 FND_MSG_PUB.ADD;
5809 END IF;
5810
5811 --service_item_quantity cannot change and cannot be null
5812 IF(p_x_osp_order_line_rec.quantity IS NULL OR
5813 (p_x_osp_order_line_rec.quantity <> l_osp_order_line_rec.quantity) ) THEN
5814 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_SER_QTY_CHG');
5815 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5816 FND_MSG_PUB.ADD;
5817 END IF;
5818
5819 --Neeed By Date cannot change and cannot be null
5820 IF(p_x_osp_order_line_rec.need_by_date IS NULL OR
5821 (trunc(p_x_osp_order_line_rec.need_by_date) <> trunc(l_osp_order_line_rec.need_by_date) )) THEN
5822 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_NBD_CHG');
5823 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5824 FND_MSG_PUB.ADD;
5825 END IF;
5826 END IF;
5827 -- jaramana End
5828
5829 --Service_item_description is updatable only if service_item_id is NULL, and serive_item_description can be null
5830 --Here we use the item description derived from service_item_id instead of l_service_item_description which is from
5831 --database table and could be derived from service_item_id and could be just
5832 --the identifier of one-time service item
5833
5834 --Jerry changed on 10/04/05 for AE enhancement 4544654 to allow the service item description to be changed in AHL
5835 --side.
5836
5837 IF (p_x_osp_order_line_rec.service_item_id IS NOT NULL) THEN
5838 BEGIN
5839 --Assuming service_item_id is always in mtl_system_items_kfv and its organization equals that of physical item
5840 --Alwasy set service_item_description to be derived from service_item_id if service_item_id is not null
5841 --Changes made by mpothuku on 27-Mar-06 to fix the ER 4544654 and Bug 5013047
5842 SELECT description, allow_item_desc_update_flag, concatenated_segments INTO l_item_description, l_desc_update_flag, l_svc_item_number
5843 FROM mtl_system_items_kfv
5844 WHERE inventory_item_id = p_x_osp_order_line_rec.service_item_id
5845 AND organization_id = p_x_osp_order_line_rec.inventory_org_id;
5846 EXCEPTION
5847 WHEN NO_DATA_FOUND THEN
5848 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_SVC_ITEM');
5849 FND_MESSAGE.Set_Token('SERVICE_ITEM_ID', p_x_osp_order_line_rec.service_item_id);
5850 FND_MSG_PUB.ADD;
5851 END;
5852 l_owrite_svc_desc_prf := NVL(FND_PROFILE.VALUE('AHL_OSP_OWRITE_SVC_DESC'), 'N');
5853 l_item_prefix := FND_PROFILE.VALUE('AHL_OSP_POL_ITEM_PREFIX');
5854 l_serial_prefix := FND_PROFILE.VALUE('AHL_OSP_POL_SER_PREFIX');
5855
5856 --Fix for the bug 5013047
5857 /*
5858 IF(l_desc_update_flag <> 'Y' AND
5859 ((p_x_osp_order_line_rec.service_item_description <> l_item_description) OR
5860 (p_x_osp_order_line_rec.service_item_description IS NOT NULL AND l_item_description IS NULL) OR
5861 (p_x_osp_order_line_rec.service_item_description IS NULL AND l_item_description IS NOT NULL))) THEN
5862 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_SVCITMDSC_CHG');
5863 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5864 FND_MSG_PUB.ADD;
5865 END IF;
5866 */
5867 /*
5868 IF Overwrite Svc Description profile set to No l_item_description would have been
5869 defaulted as the service item desc from inventory above, if the profile is Yes, we proceed below
5870 to override the value set from the inventory
5871 */
5872
5873 IF(l_owrite_svc_desc_prf = 'Y') THEN --Overwrite Svc Description profile set to Yes
5874 IF(NVL(l_desc_update_flag, 'N') = 'N') THEN --Allow Description update set to No
5875 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_SVCITMDSC_CHG');
5876 FND_MESSAGE.Set_Token('SERVICE_ITEM_NUMBER', l_svc_item_number);
5877 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5878 FND_MSG_PUB.ADD;
5879 ELSE
5880 BEGIN
5881 SELECT concatenated_segments INTO l_inv_item_number
5882 FROM mtl_system_items_kfv
5883 WHERE inventory_item_id = p_x_osp_order_line_rec.inventory_item_id
5884 AND organization_id = p_x_osp_order_line_rec.inventory_org_id;
5885 EXCEPTION
5886 WHEN NO_DATA_FOUND THEN
5887 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_PHY_ITEM_INVALID');
5888 FND_MSG_PUB.ADD;
5889 END;
5890 l_item_description :=
5891 SUBSTR(l_item_prefix||l_inv_item_number||' '||l_serial_prefix||p_x_osp_order_line_rec.serial_number,1,240);
5892 END IF;
5893 END IF;
5894 p_x_osp_order_line_rec.service_item_description := l_item_description;
5895 END IF;
5896 --mpothuku End
5897
5898 --Enforcing that either service_item_id and description should be not null
5899 --This is only enforced during update. Maybe it is better if delaying this validation
5900 --until submitting the OSP order?
5901 IF (p_x_osp_order_line_rec.service_item_id IS NULL AND p_x_osp_order_line_rec.service_item_description IS NULL) THEN
5902 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_SVCITMDSC_BOTH_NLL');
5903 FND_MESSAGE.Set_Token('LINE_NUMBER', l_osp_order_line_rec.osp_line_number);
5904 FND_MSG_PUB.ADD;
5905 END IF;
5906 --validate status_code change
5907 --it looks like only changing to 'CLOSED' occurs in this API, other statuses will be
5908 --changed in PO API?
5909 --NULL;
5910 --validate need_by_date
5911 -- Modified by jaramana on August 11, 2006 to not do this Date check if the line is PO Cancelled or PO Deleted (Bug 5478764)
5912 -- Added by jaramana on January 10, 2008 for the Requisition ER 6034236 (Added the Requisition related statuses)
5913 IF(TRUNC(p_x_osp_order_line_rec.need_by_date) < TRUNC(SYSDATE) AND
5914 (NVL(p_x_osp_order_line_rec.status_code, 'ENTERED') NOT IN (G_OL_PO_CANCELLED_STATUS, G_OL_PO_DELETED_STATUS,G_OL_REQ_CANCELLED_STATUS, G_OL_REQ_DELETED_STATUS))) THEN
5915 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_NEED_DT');
5916 FND_MESSAGE.Set_Token('NEED_BY_DATE', p_x_osp_order_line_rec.need_by_date);
5917 FND_MSG_PUB.ADD;
5918 END IF;
5919 -- jaramana End
5920 --validate ship_by_date (is this necessary?)
5921 /* Commented out on 05/31/2005 by Jerry
5922 IF(TRUNC(p_x_osp_order_line_rec.ship_by_date) < TRUNC(SYSDATE))THEN
5923 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_SHIP_DT');
5924 FND_MESSAGE.Set_Token('SHIP_BY_DATE', p_x_osp_order_line_rec.ship_by_date);
5925 FND_MSG_PUB.ADD;
5926 END IF;
5927 */
5928 --validate service_item_id (simplfied the original one)
5929
5930 /* p_org_id added to validate_service_item_uom to fix the Perf Bug #4919164 by mpothuku on 28-Feb-06
5931 default_unchanged_order_line would have defaulted the inventory_org_id by now, hence even for workorder based lines inventory_org_id will be populated with the visit's org */
5932
5933 validate_service_item_id(p_x_osp_order_line_rec.service_item_id, p_x_osp_order_line_rec.inventory_org_id);
5934 --validate service_item_description
5935 --it is not necessary to add the original one here.
5936 --validate sercice_item_uom (just borrowed the old one)
5937 validate_service_item_uom(p_x_osp_order_line_rec.service_item_id, p_x_osp_order_line_rec.service_item_uom_code, p_x_osp_order_line_rec.inventory_org_id);
5938 --validate sercice_item_quantity(quantity)
5939 --Service item quantity could be from the quantity of PO lines and not necessary to be the same as
5940 --as the value in ahl_osp_order_lines when PO has ever been created
5941 --created
5942 -- Added by jaramana on January 10, 2008 for the Requisition ER 6034236
5943 --Moved the logic below, to above
5944 /*
5945 SELECT status_code INTO l_header_status_code
5946 FROM ahl_osp_orders_b
5947 WHERE osp_order_id = p_x_osp_order_line_rec.osp_order_id;
5948 */
5949 -- jaramana End
5950 IF (p_x_osp_order_line_rec.quantity IS NOT NULL AND p_x_osp_order_line_rec.quantity <> FND_API.G_MISS_NUM) THEN
5951 IF(p_x_osp_order_line_rec.quantity <= 0) THEN
5952 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_QUANT_VAL');
5953 FND_MESSAGE.Set_Token('QUANTITY', p_x_osp_order_line_rec.quantity);
5954 FND_MSG_PUB.ADD;
5955 END IF;
5956 -- Added by jaramana on January 10, 2008 for the Requisition ER 6034236
5957 --Included the equal to zero clause above. Since we are modifying the OSP Line Views and are refraining from
5958 --synching up the quantity from PO Lines, the equal to clause can be imposed on all the OSP line statuses
5959 /*
5960 IF (p_x_osp_order_line_rec.quantity = 0 AND
5961 l_header_status_code NOT IN (G_OSP_PO_CREATED_STATUS, G_OSP_CLOSED_STATUS)) THEN
5962 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_QUANT_VAL');
5963 FND_MESSAGE.Set_Token('QUANTITY', p_x_osp_order_line_rec.quantity);
5964 FND_MSG_PUB.ADD;
5965 END IF;
5966 */
5967 -- jaramana End
5968 --quantity cannot be null when UOM is not null
5969 ELSIF (p_x_osp_order_line_rec.service_item_uom_code IS NOT NULL AND p_x_osp_order_line_rec.service_item_uom_code <> FND_API.G_MISS_CHAR) THEN
5970 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_QUANT_NLL');
5971 FND_MSG_PUB.ADD;
5972 END IF;
5973
5974 -- validate service/physical item combination with vendor
5975 --validate_vendor_service_item(p_x_osp_order_line_rec);
5976 -- validate physical/service item combination unique for a given OSP order
5977 -- For tracked item, same physical item and service item combination can only appear once in a given OSP order header
5978 -- While for non tracked item, same physical item can only appear once in a given OSP order header
5979 IF (p_x_osp_order_line_rec.workorder_id IS NULL AND
5980 p_x_osp_order_line_rec.service_item_id <> l_osp_order_line_rec.service_item_id) THEN
5981 SELECT comms_nl_trackable_flag INTO l_trackable_flag
5982 FROM mtl_system_items_kfv
5983 WHERE inventory_item_id = p_x_osp_order_line_rec.inventory_item_id
5984 AND organization_id = p_x_osp_order_line_rec.inventory_org_id;
5985 /* Commented out by Jerry on 10/11/05 due to an issue found by Pavan
5986 IF (nvl(l_trackable_flag, 'N')='N') THEN
5987 OPEN check_phy_item_unique(p_x_osp_order_line_rec.osp_order_id,
5988 p_x_osp_order_line_rec.inventory_item_id);
5989 FETCH check_phy_item_unique INTO g_dummy_char;
5990 IF check_phy_item_unique%FOUND THEN
5991 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_PHY_ITEM_UNIUE');
5992 FND_MSG_PUB.ADD;
5993 END IF;
5994 CLOSE check_phy_item_unique;
5995 ELSE
5996 */
5997 IF (nvl(l_trackable_flag, 'N')='Y') THEN
5998 OPEN check_phy_ser_item_unique(p_x_osp_order_line_rec.osp_order_id,
5999 p_x_osp_order_line_rec.service_item_id,
6000 p_x_osp_order_line_rec.inventory_item_id,
6001 p_x_osp_order_line_rec.inventory_org_id,
6002 p_x_osp_order_line_rec.lot_number,
6003 p_x_osp_order_line_rec.serial_number);
6004 FETCH check_phy_ser_item_unique INTO g_dummy_char;
6005 IF check_phy_ser_item_unique%FOUND THEN
6006 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_PHY_SER_ITEM_UNIUE');
6007 FND_MSG_PUB.ADD;
6008 END IF;
6009 CLOSE check_phy_ser_item_unique;
6010 END IF;
6011 END IF;
6012 END IF;
6013 CLOSE osp_order_line_csr;
6014 END IF;
6015 END validate_order_line_update;
6016
6017 PROCEDURE derive_default_vendor(
6018 p_item_service_rels_tbl IN item_service_rels_tbl_type,
6019 x_vendor_id OUT NOCOPY NUMBER,
6020 x_vendor_site_id OUT NOCOPY NUMBER,
6021 x_vendor_contact_id OUT NOCOPY NUMBER,
6022 x_valid_vendors_tbl OUT NOCOPY Vendor_id_tbl_type)
6023 IS
6024 CURSOR get_vendor_cert(c_inv_item_id NUMBER,
6025 c_inv_org_id NUMBER,
6026 c_service_item_id NUMBER) IS
6027
6028 /* mpothuku modified ahl_vendor_certifications to _v to fix the OU related Bug 5350882 on 21-Jul-06
6029 Also added the inv_org_id related OU filter */
6030
6031 SELECT IV.vendor_certification_id,
6032 IV.rank
6033 FROM ahl_inv_service_item_rels SI,
6034 ahl_item_vendor_rels IV,
6035 ahl_vendor_certifications_v VC
6036 WHERE SI.inv_service_item_rel_id = IV.inv_service_item_rel_id
6037 AND IV.vendor_certification_id = VC.vendor_certification_id
6038 AND SI.inv_item_id = c_inv_item_id
6039 AND SI.inv_org_id = c_inv_org_id
6040 AND SI.service_item_id = c_service_item_id
6041 AND trunc(SI.active_start_date) <= trunc(SYSDATE)
6042 AND trunc(nvl(SI.active_end_date, SYSDATE+1)) > trunc(SYSDATE)
6043 AND trunc(IV.active_start_date) <= trunc(SYSDATE)
6044 AND trunc(nvl(IV.active_end_date, SYSDATE+1)) > trunc(SYSDATE)
6045 AND trunc(VC.active_start_date) <= trunc(SYSDATE)
6046 AND trunc(nvl(VC.active_end_date, SYSDATE+1)) > trunc(SYSDATE);
6047
6048 CURSOR get_vendor_ids(c_vendor_cert_id NUMBER) IS
6049 SELECT vendor_id,
6050 vendor_site_id,
6051 vendor_contact_id
6052 FROM ahl_vendor_certifications_v
6053 WHERE vendor_certification_id = c_vendor_cert_id
6054 AND trunc(active_start_date) <= trunc(SYSDATE)
6055 AND trunc(nvl(active_end_date, SYSDATE+1)) > trunc(SYSDATE);
6056 TYPE vendor_rank_count_rec_type IS RECORD (
6057 rank_sum NUMBER, --the summary of ranks for all the vendor_certification_ids
6058 count_num NUMBER);--if count_num = p_item_service_rels_tbl.count then the vendor_cert_id is common
6059 --The index of the record type is vendor_certification_id
6060 TYPE vendor_rank_count_tbl_type IS TABLE OF vendor_rank_count_rec_type INDEX BY BINARY_INTEGER;
6061 l_vendor_rank_count_tbl vendor_rank_count_tbl_type;
6062 i NUMBER;
6063 l_first_index NUMBER;
6064 l_tbl_index NUMBER;
6065 l_vendor_index NUMBER;
6066 l_temp_index NUMBER;
6067 l_temp_vendor_cert_id NUMBER;
6068 l_temp_rank NUMBER;
6069 l_temp_rank_sum NUMBER;
6070 l_vendor_cert_id NUMBER;
6071 l_common_exists_flag BOOLEAN;
6072
6073 l_temp_vendor_index NUMBER := 0;
6074 l_dummy_contact_id NUMBER;
6075 BEGIN
6076 --This whole logic depends on the assumption that rank is mandatory in table
6077 --ahl_item_vendor_rels
6078 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
6079 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
6080 G_LOG_PREFIX || 'derive_default_vendor',
6081 'Procedure begins and count='||p_item_service_rels_tbl.count);
6082 END IF;
6083 x_vendor_id := NULL;
6084 x_vendor_site_id := NULL;
6085 x_vendor_contact_id := NULL;
6086 IF (p_item_service_rels_tbl.count > 0) THEN
6087 --get the vendor_cert_id set for the first physical/service item combination record
6088 --and take it as the base for comparing with other sets to seek the common vendor_cert_id
6089 l_tbl_index := p_item_service_rels_tbl.FIRST;
6090 FOR l_get_vendor_cert IN get_vendor_cert(p_item_service_rels_tbl(l_tbl_index).inv_item_id,
6091 p_item_service_rels_tbl(l_tbl_index).inv_org_id,
6092 p_item_service_rels_tbl(l_tbl_index).service_item_id) LOOP
6093 l_first_index := l_get_vendor_cert.vendor_certification_id;
6094 l_vendor_rank_count_tbl(l_first_index).rank_sum := l_get_vendor_cert.rank;
6095 l_vendor_rank_count_tbl(l_first_index).count_num := 1;
6096 END LOOP;
6097 --Loop through other vendor_cert_id sets of all the other physical/service item combination records
6098 --Counting the appearing times and suming their ranks in all the vendor_cert_id sets of each
6099 --vendor_cert_id in the base set. By this rule we could find the common vendor_cert_id
6100 --with the highest rank.
6101 IF (l_vendor_rank_count_tbl.count > 0) THEN
6102 FOR i IN (l_tbl_index+1)..p_item_service_rels_tbl.LAST LOOP
6103 l_common_exists_flag := FALSE;
6104 FOR l_get_vendor_cert IN get_vendor_cert(p_item_service_rels_tbl(i).inv_item_id,
6105 p_item_service_rels_tbl(i).inv_org_id,
6106 p_item_service_rels_tbl(i).service_item_id) LOOP
6107 l_temp_index := l_get_vendor_cert.vendor_certification_id;
6108 l_temp_rank := l_get_vendor_cert.rank;
6109 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
6110 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
6111 G_LOG_PREFIX || 'derive_default_vendor',
6112 'l_temp_index='||l_temp_index||
6113 'l_temp_rank='||l_temp_rank);
6114 END IF;
6115 IF l_vendor_rank_count_tbl.EXISTS(l_temp_index) THEN
6116 l_common_exists_flag := TRUE;
6117 l_vendor_rank_count_tbl(l_temp_index).rank_sum := l_vendor_rank_count_tbl(l_temp_index).rank_sum + l_temp_rank;
6118 l_vendor_rank_count_tbl(l_temp_index).count_num := l_vendor_rank_count_tbl(l_temp_index).count_num + 1;
6119 END IF;
6120 END LOOP;
6121 IF NOT l_common_exists_flag THEN
6122 RETURN;
6123 END IF;
6124 END LOOP;
6125 --Pick up the common vendor_cert_id (exists in all the sets) with
6126 --the highest(least) summary rank
6127 l_vendor_cert_id := NULL;
6128 l_temp_rank_sum := FND_API.G_MISS_NUM; --Just want to use a big positive number
6129 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
6130 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
6131 G_LOG_PREFIX || 'derive_default_vendor',
6132 'Procedure begins and count2='||l_vendor_rank_count_tbl.count||
6133 'first='||l_vendor_rank_count_tbl.first||'last='||l_vendor_rank_count_tbl.last);
6134 END IF;
6135 l_vendor_index := l_vendor_rank_count_tbl.FIRST; -- get subscript of first element
6136 --You can't use FOR l_vendor_index IN l_vendor_rank_count_tbl.FIRST..l_vendor_rank_count_tbl.LAST here
6137 WHILE l_vendor_index IS NOT NULL LOOP
6138 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
6139 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
6140 G_LOG_PREFIX || 'derive_default_vendor',
6141 'l_vendor_index='||l_vendor_index);
6142 END IF;
6143 IF (l_vendor_rank_count_tbl(l_vendor_index).count_num = p_item_service_rels_tbl.count) THEN
6144 -- Make a note of this common vendor
6145 l_temp_vendor_index := l_temp_vendor_index + 1;
6146 x_valid_vendors_tbl(l_temp_vendor_index).vendor_id := l_vendor_index;
6147 IF (l_vendor_rank_count_tbl(l_vendor_index).rank_sum < l_temp_rank_sum) THEN
6148 -- Current Best Rank
6149 l_vendor_cert_id := l_vendor_index;
6150 l_temp_rank_sum := l_vendor_rank_count_tbl(l_vendor_index).rank_sum;
6151 END IF;
6152 END IF;
6153 l_vendor_index := l_vendor_rank_count_tbl.NEXT(l_vendor_index); -- get subscript of next element
6154 END LOOP;
6155
6156 OPEN get_vendor_ids(l_vendor_cert_id);
6157 FETCH get_vendor_ids INTO x_vendor_id, x_vendor_site_id, x_vendor_contact_id;
6158 CLOSE get_vendor_ids;
6159
6160 -- Convert All Certification Ids to Vendor/Vendor Location Ids
6161 IF x_valid_vendors_tbl.count > 0 THEN
6162 FOR i IN x_valid_vendors_tbl.FIRST..x_valid_vendors_tbl.LAST LOOP
6163 OPEN get_vendor_ids(x_valid_vendors_tbl(i).vendor_id);
6164 FETCH get_vendor_ids INTO x_valid_vendors_tbl(i).vendor_id, x_valid_vendors_tbl(i).vendor_site_id, l_dummy_contact_id;
6165 CLOSE get_vendor_ids;
6166 END LOOP;
6167 END IF;
6168 END IF;
6169 END IF;
6170 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
6171 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
6172 G_LOG_PREFIX || 'derive_default_vendor',
6173 'Procedure exits normallly');
6174 END IF;
6175 END derive_default_vendor;
6176
6177 --This procedure tries to derive the common vendors for an OSP Order based on its Lines.
6178 --If the x_any_vendor_flag is 'Y', it means that any vendor can be used for this Order.
6179 --Else, only the vendors whose ids are returned in the table x_valid_vendors_tbl
6180 --are valid. It uses the derive_default_vendor method.
6181 PROCEDURE derive_common_vendors(p_osp_order_id IN NUMBER,
6182 x_valid_vendors_tbl OUT NOCOPY Vendor_id_tbl_type,
6183 x_any_vendor_flag OUT NOCOPY VARCHAR2) IS
6184
6185 CURSOR item_service_dtls_csr IS
6186 SELECT INVENTORY_ORG_ID, INVENTORY_ITEM_ID, SERVICE_ITEM_ID FROM ahl_osp_order_lines
6187 WHERE osp_order_id = p_osp_order_id AND
6188 service_item_id IS NOT NULL;
6189
6190 CURSOR is_vendor_defined_csr (c_inventory_item_id IN NUMBER,
6191 c_service_item_id IN NUMBER) IS
6192 SELECT 1
6193 FROM ahl_inv_service_item_rels isr,
6194 ahl_item_vendor_rels ivr
6195 WHERE isr.inv_item_id = c_inventory_item_id AND
6196 isr.service_item_id = c_service_item_id AND
6197 isr.inv_service_item_rel_id = ivr.inv_service_item_rel_id;
6198
6199 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.Derive_Common_Vendors';
6200 l_temp_number NUMBER;
6201 l_item_dtls_tbl item_service_rels_tbl_type;
6202 l_item_dtls_rec item_service_rel_rec_type;
6203 l_temp_index NUMBER := 0;
6204 l_dummy_vendor_id NUMBER;
6205 l_dummy_site_id NUMBER;
6206 l_dummy_contact_id NUMBER;
6207
6208 BEGIN
6209
6210 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
6211 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Entering Procedure. p_osp_order_id = ' || p_osp_order_id);
6212 END IF;
6213
6214 x_any_vendor_flag := 'N';
6215
6216 OPEN item_service_dtls_csr;
6217 LOOP
6218 FETCH item_service_dtls_csr INTO l_item_dtls_rec;
6219 EXIT WHEN item_service_dtls_csr%NOTFOUND;
6220 -- Check if a Vendor exists for this item/service
6221 OPEN is_vendor_defined_csr(l_item_dtls_rec.inv_item_id, l_item_dtls_rec.service_item_id);
6222 FETCH is_vendor_defined_csr INTO l_temp_number;
6223 IF (is_vendor_defined_csr%FOUND) THEN
6224 -- There is a vendor defined for this item/svc association
6225 l_temp_index := l_temp_index + 1; -- One based index
6226 -- Populate the table with this Item Association Details
6227 l_item_dtls_tbl(l_temp_index) := l_item_dtls_rec;
6228 END IF;
6229 CLOSE is_vendor_defined_csr;
6230 END LOOP;
6231 CLOSE item_service_dtls_csr;
6232
6233 IF (l_temp_index = 0) THEN
6234 -- All OSP lines have only one-time items or no vendor is defined for any item/svc combination
6235 -- In such a case, Can use any Vendor
6236 x_any_vendor_flag := 'Y';
6237 RETURN;
6238 END IF;
6239
6240 -- Now try to get the common Vendor(s) for the associations in l_item_dtls_tbl
6241
6242 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
6243 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'Trying to get the common vendors for ' || l_item_dtls_tbl.COUNT || ' associations.');
6244 END IF;
6245
6246 derive_default_vendor(p_item_service_rels_tbl => l_item_dtls_tbl,
6247 x_vendor_id => l_dummy_vendor_id,
6248 x_vendor_site_id => l_dummy_site_id,
6249 x_vendor_contact_id => l_dummy_contact_id,
6250 x_valid_vendors_tbl => x_valid_vendors_tbl);
6251
6252 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
6253 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'Total number of common vendors: ' || x_valid_vendors_tbl.COUNT);
6254 END IF;
6255
6256
6257 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
6258 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'Exiting Procedure');
6259 END IF;
6260
6261 END derive_common_vendors;
6262
6263 --Newly created to validate vendor_id, vendor_site_id and
6264 --vendor_contact_id together(crosss attribute validation)
6265 PROCEDURE validate_vendor_site_contact(p_vendor_id IN NUMBER,
6266 p_vendor_site_id IN NUMBER,
6267 p_vendor_contact_id IN NUMBER)
6268 IS
6269 CURSOR val_vendor_id_csr IS
6270 SELECT 'X'
6271 FROM po_vendors_view
6272 WHERE vendor_id = p_vendor_id
6273 AND enabled_flag = G_YES_FLAG
6274 AND TRUNC(NVL(vendor_start_date_active, SYSDATE - 1)) <= TRUNC(SYSDATE)
6275 AND TRUNC(NVL(vendor_end_date_active, SYSDATE + 1)) > TRUNC(SYSDATE);
6276 CURSOR get_vendor_cert IS
6277 SELECT 'X'
6278 FROM ahl_vendor_certifications_v
6279 WHERE vendor_id = p_vendor_id
6280 AND TRUNC(active_start_date) <= TRUNC(SYSDATE)
6281 AND TRUNC(nvl(active_end_date, SYSDATE+1)) > TRUNC(SYSDATE);
6282 CURSOR val_vendor_site_id_csr IS
6283 SELECT 'X'
6284 FROM po_vendor_sites
6285 WHERE vendor_site_id = p_vendor_site_id
6286 AND vendor_id = p_vendor_id
6287 AND TRUNC(NVL(inactive_date, SYSDATE + 1)) > TRUNC(SYSDATE)
6288 AND purchasing_site_flag = G_YES_FLAG
6289 AND NVL(RFQ_ONLY_SITE_FLAG, G_NO_FLAG) =G_NO_FLAG ;
6290 CURSOR get_site_cert IS
6291 SELECT 'X'
6292 FROM ahl_vendor_certifications_v
6293 WHERE vendor_id = p_vendor_id
6294 AND vendor_site_id = p_vendor_site_id
6295 AND TRUNC(active_start_date) <= TRUNC(SYSDATE)
6296 AND TRUNC(nvl(active_end_date, SYSDATE+1)) > TRUNC(SYSDATE);
6297 CURSOR val_vendor_contact_id_csr IS
6298 SELECT 'X'
6299 FROM po_vendor_contacts
6300 WHERE vendor_site_id = p_vendor_site_id
6301 AND vendor_contact_id = p_vendor_contact_id
6302 AND TRUNC(NVL(inactive_date, SYSDATE+1)) > TRUNC(SYSDATE);
6303 CURSOR get_contact_cert IS
6304 SELECT 'X'
6305 FROM ahl_vendor_certifications
6306 WHERE vendor_contact_id = p_vendor_contact_id
6307 AND TRUNC(active_start_date) <= TRUNC(SYSDATE)
6308 AND TRUNC(NVL(active_end_date, SYSDATE+1)) > TRUNC(SYSDATE);
6309 l_exist VARCHAR2(1);
6310 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.validate_vendor_site_contact';
6311 BEGIN
6312 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
6313 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
6314 END IF;
6315 IF (p_vendor_id IS NULL) THEN
6316 IF (p_vendor_site_id IS NOT NULL OR p_vendor_contact_id IS NOT NULL) THEN
6317 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENDOR_ID_INV');
6318 FND_MESSAGE.Set_Token('VENDOR_ID', p_vendor_id);
6319 FND_MSG_PUB.ADD;
6320 END IF;
6321 ELSE
6322 OPEN val_vendor_id_csr;
6323 FETCH val_vendor_id_csr INTO l_exist;
6324 IF(val_vendor_id_csr%NOTFOUND) THEN
6325 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENDOR_ID_INV');
6326 FND_MESSAGE.Set_Token('VENDOR_ID', p_vendor_id);
6327 FND_MSG_PUB.ADD;
6328 END IF;
6329 CLOSE val_vendor_id_csr;
6330 OPEN get_vendor_cert;
6331 FETCH get_vendor_cert INTO l_exist;
6332 IF(get_vendor_cert%NOTFOUND) THEN
6333 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENDOR_ID_INV');
6334 FND_MESSAGE.Set_Token('VENDOR_ID', p_vendor_id);
6335 FND_MSG_PUB.ADD;
6336 END IF;
6337 CLOSE get_vendor_cert;
6338 IF (p_vendor_site_id IS NULL AND p_vendor_contact_id IS NOT NULL) THEN
6339 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENSITE_ID_INV');
6340 FND_MESSAGE.Set_Token('VENDOR_SITE_ID', p_vendor_site_id);
6341 FND_MSG_PUB.ADD;
6342 ELSIF (p_vendor_site_id IS NOT NULL) THEN
6343 OPEN val_vendor_site_id_csr;
6344 FETCH val_vendor_site_id_csr INTO l_exist;
6345 IF(val_vendor_site_id_csr%NOTFOUND) THEN
6346 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENSITE_ID_INV');
6347 FND_MESSAGE.Set_Token('VENDOR_SITE_ID', p_vendor_site_id);
6348 FND_MSG_PUB.ADD;
6349 END IF;
6350 CLOSE val_vendor_site_id_csr;
6351 OPEN get_site_cert;
6352 FETCH get_site_cert INTO l_exist;
6353 IF(get_site_cert%NOTFOUND) THEN
6354 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENSITE_ID_INV');
6355 FND_MESSAGE.Set_Token('VENDOR_SITE_ID', p_vendor_site_id);
6356 FND_MSG_PUB.ADD;
6357 END IF;
6358 CLOSE get_site_cert;
6359 IF (p_vendor_contact_id IS NOT NULL) THEN
6360 OPEN val_vendor_contact_id_csr;
6361 FETCH val_vendor_contact_id_csr INTO l_exist;
6362 IF(val_vendor_contact_id_csr%NOTFOUND) THEN
6363 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VEN_CONTACT_ID_INV');
6364 FND_MESSAGE.Set_Token('VENDOR_CONTACT_ID', p_vendor_contact_id);
6365 FND_MSG_PUB.ADD;
6366 END IF;
6367 CLOSE val_vendor_contact_id_csr;
6368 OPEN get_contact_cert;
6369 FETCH get_contact_cert INTO l_exist;
6370 IF(get_contact_cert%NOTFOUND) THEN
6371 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VEN_CONTACT_ID_INV');
6372 FND_MESSAGE.Set_Token('VENDOR_CONTACT_ID', p_vendor_contact_id);
6373 FND_MSG_PUB.ADD;
6374 END IF;
6375 CLOSE get_contact_cert;
6376 END IF;
6377 END IF;
6378 END IF;
6379
6380 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
6381 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
6382 END IF;
6383 END validate_vendor_site_contact;
6384
6385 --Copied from original default_unchanged_order_lines, so some inherited logic
6386 --may not be necessary. It is applicable to both Update and Create
6387 PROCEDURE default_unchanged_order_line(p_x_osp_order_line_rec IN OUT NOCOPY osp_order_line_rec_type)
6388 IS
6389 CURSOR osp_order_lines_csr IS
6390 --Updated by mpothuku on 27-Feb-06 to fix the Perf Bug #4919164
6391 /*
6392 SELECT osp_order_id,
6393 osp_line_number,
6394 status_code, --status is not defined in the record because user can't directly change the status
6395 po_line_type_id, --no po_line_type here because it is not changeable once it is created(from a profile option)
6396 service_item_id,
6397 service_item_number,
6398 service_item_description,
6399 service_item_uom_code,
6400 quantity,
6401 need_by_date,
6402 ship_by_date,
6403 po_line_id,
6404 oe_ship_line_id,
6405 oe_return_line_id,
6406 workorder_id,
6407 job_number,
6408 operation_id, --this attribute should be deleted from the table, so ignore it
6409 exchange_instance_id,
6410 exchange_instance_number,
6411 inventory_item_id,
6412 inventory_org_id,
6413 item_number,
6414 inventory_item_uom,
6415 inventory_item_quantity,
6416 sub_inventory,
6417 lot_number,
6418 serial_number,
6419 attribute_category,
6420 attribute1,
6421 attribute2,
6422 attribute3,
6423 attribute4,
6424 attribute5,
6425 attribute6,
6426 attribute7,
6427 attribute8,
6428 attribute9,
6429 attribute10,
6430 attribute11,
6431 attribute12,
6432 attribute13,
6433 attribute14,
6434 attribute15
6435 FROM ahl_osp_order_lines_v
6436 WHERE osp_order_line_id = p_x_osp_order_line_rec.osp_order_line_id
6437 AND object_version_number= p_x_osp_order_line_rec.object_version_number;
6438 */
6439 SELECT ospl.osp_order_id,
6440 ospl.osp_line_number,
6441 ospl.status_code, --status is not defined in the record because user can't directly change the status
6442 ospl.po_line_type_id, --no po_line_type here because it is not changeable once it is created(from a profile option)
6443 ospl.service_item_id,
6444 (select mtlsvc.concatenated_segments
6445 from mtl_system_items_kfv mtlsvc
6446 where mtlsvc.inventory_item_id = ospl.service_item_id
6447 and mtlsvc.organization_id = decode(ospl.workorder_id, null, ospl.inventory_org_id, vst.organization_id)
6448 )service_item_number,
6449 ospl.service_item_description,
6450 --modified by mpothuku on 14-mar-2008 to fix the Bug 6885513
6451 /*
6452 decode(ospl.po_line_id, null, ospl.service_item_uom_code, mtluom.uom_code )service_item_uom_code,
6453 decode(ospl.po_line_id, null, ospl.quantity, pl.quantity )quantity,
6454 */
6455 ospl.service_item_uom_code,
6456 ospl.quantity,
6457 --mpothuku End
6458 ospl.need_by_date,
6459 ospl.ship_by_date,
6460 ospl.po_line_id,
6461 ospl.oe_ship_line_id,
6462 ospl.oe_return_line_id,
6463 ospl.workorder_id,
6464 wo.workorder_name job_number,
6465 ospl.operation_id, --this attribute should be deleted from the table, so ignore it
6466 ospl.exchange_instance_id,
6467 csiex.instance_number exchange_instance_number,
6468 decode(ospl.workorder_id, null, ospl.inventory_item_id, vts.inventory_item_id)inventory_item_id,
6469 --Fix for the regression issue by mpothuku on 28th August 2006, changed the item_id to org_id in decode below
6470 decode(ospl.workorder_id, null, ospl.inventory_org_id, vst.organization_id) inventory_org_id,
6471 (select mtli.concatenated_segments
6472 from mtl_system_items_kfv mtli
6473 where mtli.inventory_item_id = ospl.inventory_item_id
6474 and mtli.organization_id = decode(ospl.workorder_id, null, ospl.inventory_org_id, vst.organization_id)
6475 )item_number,
6476 decode(ospl.workorder_id, null, ospl.inventory_item_uom, csiwo.unit_of_measure)inventory_item_uom,
6477 decode(ospl.workorder_id, null, ospl.inventory_item_quantity, csiwo.quantity)inventory_item_quantity,
6478 decode(ospl.workorder_id, null, ospl.sub_inventory, null)sub_inventory,
6479 decode(ospl.workorder_id, null, ospl.lot_number, csiwo.lot_number)lot_number,
6480 decode(ospl.workorder_id, null, ospl.serial_number, csiwo.serial_number)serial_number,
6481 -- Added by jaramana on January 10, 2008 for the Requisition ER 6034236
6482 po_req_line_id,
6483 -- jaramana End
6484 ospl.attribute_category,
6485 ospl.attribute1,
6486 ospl.attribute2,
6487 ospl.attribute3,
6488 ospl.attribute4,
6489 ospl.attribute5,
6490 ospl.attribute6,
6491 ospl.attribute7,
6492 ospl.attribute8,
6493 ospl.attribute9,
6494 ospl.attribute10,
6495 ospl.attribute11,
6496 ospl.attribute12,
6497 ospl.attribute13,
6498 ospl.attribute14,
6499 ospl.attribute15
6500 FROM ahl_osp_order_lines ospl,
6501 ahl_workorders wo,
6502 ahl_visits_b vst,
6503 ahl_visit_tasks_b vts,
6504 csi_item_instances csiwo,
6505 csi_item_instances csiex,
6506 --po_lines_all pl,
6507 mtl_units_of_measure_tl mtluom
6508 WHERE ospl.osp_order_line_id = p_x_osp_order_line_rec.osp_order_line_id
6509 AND ospl.object_version_number= p_x_osp_order_line_rec.object_version_number
6510 AND ospl.workorder_id = wo.workorder_id(+)
6511 AND wo.visit_task_id = vts.visit_task_id(+)
6512 AND vts.visit_id = vst.visit_id(+)
6513 AND vts.instance_id = csiwo.instance_id(+)
6514 AND NVL (ospl.status_code, 'ENTERED') <> 'PO_DELETED'
6515 --modified by mpothuku on 14-mar-2008 to fix the Bug 6885513
6516 /*
6517 AND ospl.po_line_id = pl.po_line_id(+)
6518 AND pl.unit_meas_lookup_code = mtluom.unit_of_measure(+)
6519 AND mtluom.language(+) = USERENV('LANG')
6520 */
6521 --mpothuku End
6522 AND csiex.instance_id(+) = ospl.exchange_instance_id;
6523
6524 l_osp_order_line_rec osp_order_lines_csr%ROWTYPE;
6525 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.default_unchanged_order_lines';
6526 BEGIN
6527 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
6528 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
6529 END IF;
6530 IF(p_x_osp_order_line_rec.operation_flag = G_OP_UPDATE) THEN
6531 OPEN osp_order_lines_csr;
6532 FETCH osp_order_lines_csr INTO l_osp_order_line_rec;
6533 IF (osp_order_lines_csr%NOTFOUND) THEN
6534 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_INVOP_OSP_LN_NFOUND');
6535 FND_MSG_PUB.ADD;
6536 ELSE
6537 IF (p_x_osp_order_line_rec.osp_order_id IS NULL) THEN
6538 p_x_osp_order_line_rec.osp_order_id := l_osp_order_line_rec.osp_order_id;
6539 ELSIF(p_x_osp_order_line_rec.osp_order_id = FND_API.G_MISS_NUM) THEN
6540 p_x_osp_order_line_rec.osp_order_id := null;
6541 END IF;
6542 IF (p_x_osp_order_line_rec.osp_line_number IS NULL) THEN
6543 p_x_osp_order_line_rec.osp_line_number := l_osp_order_line_rec.osp_line_number;
6544 ELSIF(p_x_osp_order_line_rec.osp_line_number = FND_API.G_MISS_NUM) THEN
6545 p_x_osp_order_line_rec.osp_line_number := null;
6546 END IF;
6547 IF (p_x_osp_order_line_rec.status_code IS NULL) THEN
6548 p_x_osp_order_line_rec.status_code := l_osp_order_line_rec.status_code;
6549 ELSIF(p_x_osp_order_line_rec.status_code = FND_API.G_MISS_CHAR) THEN
6550 p_x_osp_order_line_rec.status_code := null;
6551 END IF;
6552 IF (p_x_osp_order_line_rec.need_by_date IS NULL) THEN
6553 p_x_osp_order_line_rec.need_by_date := l_osp_order_line_rec.need_by_date;
6554 ELSIF(p_x_osp_order_line_rec.need_by_date = FND_API.G_MISS_DATE) THEN
6555 p_x_osp_order_line_rec.need_by_date := null;
6556 END IF;
6557 IF (p_x_osp_order_line_rec.ship_by_date IS NULL) THEN
6558 p_x_osp_order_line_rec.ship_by_date := l_osp_order_line_rec.ship_by_date;
6559 ELSIF(p_x_osp_order_line_rec.ship_by_date = FND_API.G_MISS_DATE) THEN
6560 p_x_osp_order_line_rec.ship_by_date := null;
6561 END IF;
6562 IF (p_x_osp_order_line_rec.service_item_id IS NULL) THEN
6563 p_x_osp_order_line_rec.service_item_id := l_osp_order_line_rec.service_item_id;
6564 ELSIF(p_x_osp_order_line_rec.service_item_id = FND_API.G_MISS_NUM) THEN
6565 p_x_osp_order_line_rec.service_item_id := null;
6566 END IF;
6567 IF (p_x_osp_order_line_rec.service_item_number IS NULL) THEN
6568 p_x_osp_order_line_rec.service_item_number := l_osp_order_line_rec.service_item_number;
6569 ELSIF(p_x_osp_order_line_rec.service_item_number = FND_API.G_MISS_CHAR) THEN
6570 p_x_osp_order_line_rec.service_item_number := null;
6571 END IF;
6572 IF (p_x_osp_order_line_rec.service_item_description IS NULL) THEN
6573 p_x_osp_order_line_rec.service_item_description := l_osp_order_line_rec.service_item_description;
6574 ELSIF(p_x_osp_order_line_rec.service_item_description = FND_API.G_MISS_CHAR) THEN
6575 p_x_osp_order_line_rec.service_item_description := null;
6576 END IF;
6577 IF (p_x_osp_order_line_rec.service_item_uom_code IS NULL) THEN
6578 p_x_osp_order_line_rec.service_item_uom_code := l_osp_order_line_rec.service_item_uom_code;
6579 ELSIF(p_x_osp_order_line_rec.service_item_uom_code = FND_API.G_MISS_CHAR) THEN
6580 p_x_osp_order_line_rec.service_item_uom_code := null;
6581 END IF;
6582 IF (p_x_osp_order_line_rec.quantity IS NULL) THEN
6583 p_x_osp_order_line_rec.quantity := l_osp_order_line_rec.quantity;
6584 ELSIF(p_x_osp_order_line_rec.quantity = FND_API.G_MISS_NUM) THEN
6585 p_x_osp_order_line_rec.quantity := null;
6586 END IF;
6587 IF (p_x_osp_order_line_rec.po_line_type_id IS NULL) THEN
6588 p_x_osp_order_line_rec.po_line_type_id := l_osp_order_line_rec.po_line_type_id;
6589 ELSIF(p_x_osp_order_line_rec.po_line_type_id = FND_API.G_MISS_NUM) THEN
6590 p_x_osp_order_line_rec.po_line_type_id := null;
6591 END IF;
6592 IF (p_x_osp_order_line_rec.po_line_id IS NULL) THEN
6593 p_x_osp_order_line_rec.po_line_id := l_osp_order_line_rec.po_line_id;
6594 ELSIF(p_x_osp_order_line_rec.po_line_id = FND_API.G_MISS_NUM) THEN
6595 p_x_osp_order_line_rec.po_line_id := null;
6596 END IF;
6597 IF (p_x_osp_order_line_rec.oe_ship_line_id IS NULL) THEN
6598 p_x_osp_order_line_rec.oe_ship_line_id := l_osp_order_line_rec.oe_ship_line_id;
6599 ELSIF(p_x_osp_order_line_rec.oe_ship_line_id = FND_API.G_MISS_NUM) THEN
6600 p_x_osp_order_line_rec.oe_ship_line_id := null;
6601 END IF;
6602 IF (p_x_osp_order_line_rec.oe_return_line_id IS NULL) THEN
6603 p_x_osp_order_line_rec.oe_return_line_id := l_osp_order_line_rec.oe_return_line_id;
6604 ELSIF(p_x_osp_order_line_rec.oe_return_line_id = FND_API.G_MISS_NUM) THEN
6605 p_x_osp_order_line_rec.oe_return_line_id := null;
6606 END IF;
6607 IF (p_x_osp_order_line_rec.workorder_id IS NULL) THEN
6608 p_x_osp_order_line_rec.workorder_id := l_osp_order_line_rec.workorder_id;
6609 ELSIF(p_x_osp_order_line_rec.workorder_id = FND_API.G_MISS_NUM) THEN
6610 p_x_osp_order_line_rec.workorder_id := null;
6611 END IF;
6612 IF (p_x_osp_order_line_rec.job_number IS NULL) THEN
6613 p_x_osp_order_line_rec.job_number := l_osp_order_line_rec.job_number;
6614 ELSIF(p_x_osp_order_line_rec.job_number = FND_API.G_MISS_CHAR) THEN
6615 p_x_osp_order_line_rec.job_number := null;
6616 END IF;
6617 IF (p_x_osp_order_line_rec.exchange_instance_id IS NULL) THEN
6618 p_x_osp_order_line_rec.exchange_instance_id := l_osp_order_line_rec.exchange_instance_id;
6619 ELSIF(p_x_osp_order_line_rec.exchange_instance_id = FND_API.G_MISS_NUM) THEN
6620 p_x_osp_order_line_rec.exchange_instance_id := null;
6621 END IF;
6622 IF (p_x_osp_order_line_rec.exchange_instance_number IS NULL) THEN
6623 p_x_osp_order_line_rec.exchange_instance_number := l_osp_order_line_rec.exchange_instance_number;
6624 ELSIF(p_x_osp_order_line_rec.exchange_instance_number = FND_API.G_MISS_CHAR) THEN
6625 p_x_osp_order_line_rec.exchange_instance_number := null;
6626 END IF;
6627 IF (p_x_osp_order_line_rec.inventory_item_id IS NULL) THEN
6628 p_x_osp_order_line_rec.inventory_item_id := l_osp_order_line_rec.inventory_item_id;
6629 ELSIF(p_x_osp_order_line_rec.inventory_item_id = FND_API.G_MISS_NUM) THEN
6630 p_x_osp_order_line_rec.inventory_item_id := null;
6631 END IF;
6632 IF (p_x_osp_order_line_rec.inventory_org_id IS NULL) THEN
6633 p_x_osp_order_line_rec.inventory_org_id := l_osp_order_line_rec.inventory_org_id;
6634 ELSIF(p_x_osp_order_line_rec.inventory_org_id = FND_API.G_MISS_NUM) THEN
6635 p_x_osp_order_line_rec.inventory_org_id := null;
6636 END IF;
6637 IF (p_x_osp_order_line_rec.item_number IS NULL) THEN
6638 p_x_osp_order_line_rec.item_number := l_osp_order_line_rec.item_number;
6639 ELSIF(p_x_osp_order_line_rec.item_number = FND_API.G_MISS_CHAR) THEN
6640 p_x_osp_order_line_rec.item_number := null;
6641 END IF;
6642 IF (p_x_osp_order_line_rec.inventory_item_uom IS NULL) THEN
6643 p_x_osp_order_line_rec.inventory_item_uom := l_osp_order_line_rec.inventory_item_uom;
6644 ELSIF(p_x_osp_order_line_rec.inventory_item_uom = FND_API.G_MISS_CHAR) THEN
6645 p_x_osp_order_line_rec.inventory_item_uom := null;
6646 END IF;
6647 IF (p_x_osp_order_line_rec.inventory_item_quantity IS NULL) THEN
6648 p_x_osp_order_line_rec.inventory_item_quantity := l_osp_order_line_rec.inventory_item_quantity;
6649 ELSIF(p_x_osp_order_line_rec.inventory_item_quantity = FND_API.G_MISS_NUM) THEN
6650 p_x_osp_order_line_rec.inventory_item_quantity := null;
6651 END IF;
6652 IF (p_x_osp_order_line_rec.sub_inventory IS NULL) THEN
6653 p_x_osp_order_line_rec.sub_inventory := l_osp_order_line_rec.sub_inventory;
6654 ELSIF(p_x_osp_order_line_rec.sub_inventory = FND_API.G_MISS_CHAR) THEN
6655 p_x_osp_order_line_rec.sub_inventory := null;
6656 END IF;
6657 IF (p_x_osp_order_line_rec.lot_number IS NULL) THEN
6658 p_x_osp_order_line_rec.lot_number := l_osp_order_line_rec.lot_number;
6659 ELSIF(p_x_osp_order_line_rec.lot_number = FND_API.G_MISS_CHAR) THEN
6660 p_x_osp_order_line_rec.lot_number := null;
6661 END IF;
6662 IF (p_x_osp_order_line_rec.serial_number IS NULL) THEN
6663 p_x_osp_order_line_rec.serial_number := l_osp_order_line_rec.serial_number;
6664 ELSIF(p_x_osp_order_line_rec.serial_number = FND_API.G_MISS_CHAR) THEN
6665 p_x_osp_order_line_rec.serial_number := null;
6666 END IF;
6667
6668 -- Added by jaramana on January 10, 2008 for the Requisition ER 6034236
6669 IF (p_x_osp_order_line_rec.po_req_line_id IS NULL) THEN
6670 p_x_osp_order_line_rec.po_req_line_id := l_osp_order_line_rec.po_req_line_id;
6671 ELSIF(p_x_osp_order_line_rec.po_req_line_id = FND_API.G_MISS_NUM) THEN
6672 p_x_osp_order_line_rec.po_req_line_id := null;
6673 END IF;
6674 -- jaramana End
6675
6676 IF (p_x_osp_order_line_rec.attribute_category IS NULL) THEN
6677 p_x_osp_order_line_rec.attribute_category := l_osp_order_line_rec.attribute_category;
6678 ELSIF(p_x_osp_order_line_rec.attribute_category = FND_API.G_MISS_CHAR) THEN
6679 p_x_osp_order_line_rec.attribute_category := null;
6680 END IF;
6681 IF (p_x_osp_order_line_rec.attribute1 IS NULL) THEN
6682 p_x_osp_order_line_rec.attribute1 := l_osp_order_line_rec.attribute1;
6683 ELSIF(p_x_osp_order_line_rec.attribute1 = FND_API.G_MISS_CHAR) THEN
6684 p_x_osp_order_line_rec.attribute1 := null;
6685 END IF;
6686 IF (p_x_osp_order_line_rec.attribute2 IS NULL) THEN
6687 p_x_osp_order_line_rec.attribute2 := l_osp_order_line_rec.attribute2;
6688 ELSIF(p_x_osp_order_line_rec.attribute2 = FND_API.G_MISS_CHAR) THEN
6689 p_x_osp_order_line_rec.attribute2 := null;
6690 END IF;
6691 IF (p_x_osp_order_line_rec.attribute3 IS NULL) THEN
6692 p_x_osp_order_line_rec.attribute3 := l_osp_order_line_rec.attribute3;
6693 ELSIF(p_x_osp_order_line_rec.attribute3 = FND_API.G_MISS_CHAR) THEN
6694 p_x_osp_order_line_rec.attribute3 := null;
6695 END IF;
6696 IF (p_x_osp_order_line_rec.attribute4 IS NULL) THEN
6697 p_x_osp_order_line_rec.attribute4 := l_osp_order_line_rec.attribute4;
6698 ELSIF(p_x_osp_order_line_rec.attribute4 = FND_API.G_MISS_CHAR) THEN
6699 p_x_osp_order_line_rec.attribute4 := null;
6700 END IF;
6701 IF (p_x_osp_order_line_rec.attribute5 IS NULL) THEN
6702 p_x_osp_order_line_rec.attribute5 := l_osp_order_line_rec.attribute5;
6703 ELSIF(p_x_osp_order_line_rec.attribute5 = FND_API.G_MISS_CHAR) THEN
6704 p_x_osp_order_line_rec.attribute5 := null;
6705 END IF;
6706 IF (p_x_osp_order_line_rec.attribute6 IS NULL) THEN
6707 p_x_osp_order_line_rec.attribute6 := l_osp_order_line_rec.attribute6;
6708 ELSIF(p_x_osp_order_line_rec.attribute6 = FND_API.G_MISS_CHAR) THEN
6709 p_x_osp_order_line_rec.attribute6 := null;
6710 END IF;
6711 IF (p_x_osp_order_line_rec.attribute7 IS NULL) THEN
6712 p_x_osp_order_line_rec.attribute7 := l_osp_order_line_rec.attribute7;
6713 ELSIF(p_x_osp_order_line_rec.attribute7 = FND_API.G_MISS_CHAR) THEN
6714 p_x_osp_order_line_rec.attribute7 := null;
6715 END IF;
6716 IF (p_x_osp_order_line_rec.attribute8 IS NULL) THEN
6717 p_x_osp_order_line_rec.attribute8 := l_osp_order_line_rec.attribute8;
6718 ELSIF(p_x_osp_order_line_rec.attribute8 = FND_API.G_MISS_CHAR) THEN
6719 p_x_osp_order_line_rec.attribute8 := null;
6720 END IF;
6721 IF (p_x_osp_order_line_rec.attribute9 IS NULL) THEN
6722 p_x_osp_order_line_rec.attribute9 := l_osp_order_line_rec.attribute9;
6723 ELSIF(p_x_osp_order_line_rec.attribute9 = FND_API.G_MISS_CHAR) THEN
6724 p_x_osp_order_line_rec.attribute9 := null;
6725 END IF;
6726 IF (p_x_osp_order_line_rec.attribute10 IS NULL) THEN
6727 p_x_osp_order_line_rec.attribute10 := l_osp_order_line_rec.attribute10;
6728 ELSIF(p_x_osp_order_line_rec.attribute10 = FND_API.G_MISS_CHAR) THEN
6729 p_x_osp_order_line_rec.attribute10 := null;
6730 END IF;
6731 IF (p_x_osp_order_line_rec.attribute11 IS NULL) THEN
6732 p_x_osp_order_line_rec.attribute11 := l_osp_order_line_rec.attribute11;
6733 ELSIF(p_x_osp_order_line_rec.attribute11 = FND_API.G_MISS_CHAR) THEN
6734 p_x_osp_order_line_rec.attribute11 := null;
6735 END IF;
6736 IF (p_x_osp_order_line_rec.attribute12 IS NULL) THEN
6737 p_x_osp_order_line_rec.attribute12 := l_osp_order_line_rec.attribute12;
6738 ELSIF(p_x_osp_order_line_rec.attribute12 = FND_API.G_MISS_CHAR) THEN
6739 p_x_osp_order_line_rec.attribute12 := null;
6740 END IF;
6741 IF (p_x_osp_order_line_rec.attribute13 IS NULL) THEN
6742 p_x_osp_order_line_rec.attribute13 := l_osp_order_line_rec.attribute13;
6743 ELSIF(p_x_osp_order_line_rec.attribute13 = FND_API.G_MISS_CHAR) THEN
6744 p_x_osp_order_line_rec.attribute13 := null;
6745 END IF;
6746 IF (p_x_osp_order_line_rec.attribute14 IS NULL) THEN
6747 p_x_osp_order_line_rec.attribute14 := l_osp_order_line_rec.attribute14;
6748 ELSIF(p_x_osp_order_line_rec.attribute14 = FND_API.G_MISS_CHAR) THEN
6749 p_x_osp_order_line_rec.attribute14 := null;
6750 END IF;
6751 IF (p_x_osp_order_line_rec.attribute15 IS NULL) THEN
6752 p_x_osp_order_line_rec.attribute15 := l_osp_order_line_rec.attribute15;
6753 ELSIF(p_x_osp_order_line_rec.attribute15 = FND_API.G_MISS_CHAR) THEN
6754 p_x_osp_order_line_rec.attribute15 := null;
6755 END IF;
6756 END IF;
6757 CLOSE osp_order_lines_csr;
6758 ELSIF (p_x_osp_order_line_rec.operation_flag = G_OP_CREATE) THEN
6759 IF(p_x_osp_order_line_rec.osp_order_id = FND_API.G_MISS_NUM) THEN
6760 p_x_osp_order_line_rec.osp_order_id := null;
6761 END IF;
6762 IF(p_x_osp_order_line_rec.osp_line_number = FND_API.G_MISS_NUM) THEN
6763 p_x_osp_order_line_rec.osp_line_number := null;
6764 END IF;
6765 IF(p_x_osp_order_line_rec.status_code = FND_API.G_MISS_CHAR) THEN
6766 p_x_osp_order_line_rec.status_code := null;
6767 END IF;
6768 IF(p_x_osp_order_line_rec.need_by_date = FND_API.G_MISS_DATE) THEN
6769 p_x_osp_order_line_rec.need_by_date := null;
6770 END IF;
6771 IF(p_x_osp_order_line_rec.ship_by_date = FND_API.G_MISS_DATE) THEN
6772 p_x_osp_order_line_rec.ship_by_date := null;
6773 END IF;
6774 IF(p_x_osp_order_line_rec.service_item_id = FND_API.G_MISS_NUM) THEN
6775 p_x_osp_order_line_rec.service_item_id := null;
6776 END IF;
6777 IF(p_x_osp_order_line_rec.service_item_number = FND_API.G_MISS_CHAR) THEN
6778 p_x_osp_order_line_rec.service_item_number := null;
6779 END IF;
6780 IF(p_x_osp_order_line_rec.service_item_description = FND_API.G_MISS_CHAR) THEN
6781 p_x_osp_order_line_rec.service_item_description := null;
6782 END IF;
6783 IF(p_x_osp_order_line_rec.service_item_uom_code = FND_API.G_MISS_CHAR) THEN
6784 p_x_osp_order_line_rec.service_item_uom_code := null;
6785 END IF;
6786 IF(p_x_osp_order_line_rec.quantity = FND_API.G_MISS_NUM) THEN
6787 p_x_osp_order_line_rec.quantity := null;
6788 END IF;
6789 IF(p_x_osp_order_line_rec.po_line_type_id = FND_API.G_MISS_NUM) THEN
6790 p_x_osp_order_line_rec.po_line_type_id := null;
6791 END IF;
6792 IF(p_x_osp_order_line_rec.po_line_id = FND_API.G_MISS_NUM) THEN
6793 p_x_osp_order_line_rec.po_line_id := null;
6794 END IF;
6795 IF(p_x_osp_order_line_rec.oe_ship_line_id = FND_API.G_MISS_NUM) THEN
6796 p_x_osp_order_line_rec.oe_ship_line_id := null;
6797 END IF;
6798 IF(p_x_osp_order_line_rec.oe_return_line_id = FND_API.G_MISS_NUM) THEN
6799 p_x_osp_order_line_rec.oe_return_line_id := null;
6800 END IF;
6801 IF(p_x_osp_order_line_rec.workorder_id = FND_API.G_MISS_NUM) THEN
6802 p_x_osp_order_line_rec.workorder_id := null;
6803 END IF;
6804 IF(p_x_osp_order_line_rec.job_number = FND_API.G_MISS_CHAR) THEN
6805 p_x_osp_order_line_rec.job_number := null;
6806 END IF;
6807 IF(p_x_osp_order_line_rec.exchange_instance_id = FND_API.G_MISS_NUM) THEN
6808 p_x_osp_order_line_rec.exchange_instance_id := null;
6809 END IF;
6810 IF(p_x_osp_order_line_rec.exchange_instance_number = FND_API.G_MISS_CHAR) THEN
6811 p_x_osp_order_line_rec.exchange_instance_number := null;
6812 END IF;
6813 IF (p_x_osp_order_line_rec.inventory_item_id = FND_API.G_MISS_NUM) THEN
6814 p_x_osp_order_line_rec.inventory_item_id := null;
6815 END IF;
6816 IF (p_x_osp_order_line_rec.inventory_org_id = FND_API.G_MISS_NUM) THEN
6817 p_x_osp_order_line_rec.inventory_org_id := null;
6818 END IF;
6819 IF (p_x_osp_order_line_rec.item_number = FND_API.G_MISS_CHAR) THEN
6820 p_x_osp_order_line_rec.item_number := null;
6821 END IF;
6822 IF (p_x_osp_order_line_rec.inventory_item_uom = FND_API.G_MISS_CHAR) THEN
6823 p_x_osp_order_line_rec.inventory_item_uom := null;
6824 END IF;
6825 IF (p_x_osp_order_line_rec.inventory_item_quantity = FND_API.G_MISS_NUM) THEN
6826 p_x_osp_order_line_rec.inventory_item_quantity := null;
6827 END IF;
6828 IF (p_x_osp_order_line_rec.sub_inventory = FND_API.G_MISS_CHAR) THEN
6829 p_x_osp_order_line_rec.sub_inventory := null;
6830 END IF;
6831 IF (p_x_osp_order_line_rec.lot_number = FND_API.G_MISS_CHAR) THEN
6832 p_x_osp_order_line_rec.lot_number := null;
6833 END IF;
6834 IF (p_x_osp_order_line_rec.serial_number = FND_API.G_MISS_CHAR) THEN
6835 p_x_osp_order_line_rec.serial_number := null;
6836 END IF;
6837 -- Added by jaramana on January 10, 2008 for the Requisition ER 6034236
6838 IF (p_x_osp_order_line_rec.po_req_line_id = FND_API.G_MISS_NUM) THEN
6839 p_x_osp_order_line_rec.po_req_line_id := null;
6840 END IF;
6841 -- jaramana End
6842 IF (p_x_osp_order_line_rec.attribute_category = FND_API.G_MISS_CHAR) THEN
6843 p_x_osp_order_line_rec.attribute_category := null;
6844 END IF;
6845 IF (p_x_osp_order_line_rec.attribute1 = FND_API.G_MISS_CHAR) THEN
6846 p_x_osp_order_line_rec.attribute1 := null;
6847 END IF;
6848 IF (p_x_osp_order_line_rec.attribute2 = FND_API.G_MISS_CHAR) THEN
6849 p_x_osp_order_line_rec.attribute2 := null;
6850 END IF;
6851 IF (p_x_osp_order_line_rec.attribute3 = FND_API.G_MISS_CHAR) THEN
6852 p_x_osp_order_line_rec.attribute3 := null;
6853 END IF;
6854 IF (p_x_osp_order_line_rec.attribute4 = FND_API.G_MISS_CHAR) THEN
6855 p_x_osp_order_line_rec.attribute4 := null;
6856 END IF;
6857 IF (p_x_osp_order_line_rec.attribute5 = FND_API.G_MISS_CHAR) THEN
6858 p_x_osp_order_line_rec.attribute5 := null;
6859 END IF;
6860 IF (p_x_osp_order_line_rec.attribute6 = FND_API.G_MISS_CHAR) THEN
6861 p_x_osp_order_line_rec.attribute6 := null;
6862 END IF;
6863 IF (p_x_osp_order_line_rec.attribute7 = FND_API.G_MISS_CHAR) THEN
6864 p_x_osp_order_line_rec.attribute7 := null;
6865 END IF;
6866 IF (p_x_osp_order_line_rec.attribute8 = FND_API.G_MISS_CHAR) THEN
6867 p_x_osp_order_line_rec.attribute8 := null;
6868 END IF;
6869 IF (p_x_osp_order_line_rec.attribute9 = FND_API.G_MISS_CHAR) THEN
6870 p_x_osp_order_line_rec.attribute9 := null;
6871 END IF;
6872 IF (p_x_osp_order_line_rec.attribute10 = FND_API.G_MISS_CHAR) THEN
6873 p_x_osp_order_line_rec.attribute10 := null;
6874 END IF;
6875 IF (p_x_osp_order_line_rec.attribute11 = FND_API.G_MISS_CHAR) THEN
6876 p_x_osp_order_line_rec.attribute11 := null;
6877 END IF;
6878 IF (p_x_osp_order_line_rec.attribute12 = FND_API.G_MISS_CHAR) THEN
6879 p_x_osp_order_line_rec.attribute12 := null;
6880 END IF;
6881 IF (p_x_osp_order_line_rec.attribute13 = FND_API.G_MISS_CHAR) THEN
6882 p_x_osp_order_line_rec.attribute13 := null;
6883 END IF;
6884 IF (p_x_osp_order_line_rec.attribute14 = FND_API.G_MISS_CHAR) THEN
6885 p_x_osp_order_line_rec.attribute14 := null;
6886 END IF;
6887 IF (p_x_osp_order_line_rec.attribute15 = FND_API.G_MISS_CHAR) THEN
6888 p_x_osp_order_line_rec.attribute15 := null;
6889 END IF;
6890 END IF;
6891 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
6892 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
6893 END IF;
6894 END default_unchanged_order_line;
6895
6896 --Copied from original convert_order_lines_val_to_id, so some inherited logic
6897 --may not be necessary
6898 PROCEDURE convert_order_line_val_to_id(p_x_osp_order_line_rec IN OUT NOCOPY osp_order_line_rec_type)
6899 IS
6900 CURSOR workorder_id_csr(p_job_number IN VARCHAR2) IS
6901 --Modified by mpothuku on 27-Feb-06 to fix the Perf Bug #4919164
6902 /*
6903 SELECT workorder_id
6904 FROM ahl_workorders_osp_v
6905 WHERE job_number = p_job_number;
6906 */
6907 SELECT workorder_id from ahl_workorders
6908 WHERE workorder_name = p_job_number;
6909
6910 l_workorder_id NUMBER;
6911 CURSOR service_item_id_csr(p_service_item_number IN VARCHAR2, p_inventory_org_id NUMBER) IS
6912 SELECT MTL.inventory_item_id
6913 FROM mtl_system_items_kfv MTL
6914 WHERE MTL.concatenated_segments = p_service_item_number
6915 AND MTL.organization_id = p_inventory_org_id;
6916 l_service_item_id NUMBER;
6917 l_organization_id NUMBER;
6918 CURSOR po_line_type_id_csr(p_po_line_type IN VARCHAR2) IS
6919 SELECT line_type_id
6920 FROM po_line_types
6921 WHERE line_type = p_po_line_type
6922 AND order_type_lookup_code = 'QUANTITY'
6923 AND NVL(outside_operation_flag, G_NO_FLAG) = G_NO_FLAG;
6924 l_po_line_type_id NUMBER;
6925 CURSOR osp_order_line_on_csr(p_osp_order_id IN NUMBER, p_osp_line_number IN NUMBER) IS
6926 SELECT osp_order_line_id
6927 FROM ahl_osp_order_lines
6928 WHERE osp_order_id = p_osp_order_id
6929 and osp_line_number = p_osp_line_number;
6930 -- Added by jaramana on January 10, 2008 for the Requisition ER 6034236
6931 -- We are not planning to derive the OSP_ORDER_LINE_ID from PO_LINE_ID
6932 /*
6933 CURSOR osp_order_line_po_csr(p_po_line_id IN NUMBER) IS
6934 SELECT osp_order_line_id
6935 FROM ahl_osp_order_lines
6936 WHERE po_line_id = p_po_line_id;
6937 */
6938 -- jaramana End
6939 l_osp_order_line_id NUMBER;
6940 CURSOR exchange_instance_id_csr(p_exchange_instance_number IN VARCHAR2) IS
6941 SELECT instance_id
6942 FROM csi_item_instances
6943 WHERE instance_number = p_exchange_instance_number;
6944 l_exchange_instance_id NUMBER;
6945 CURSOR physical_item_id_csr(p_item_number IN VARCHAR2, p_inventory_org_id NUMBER) IS
6946 SELECT MTL.inventory_item_id
6947 FROM mtl_system_items_kfv MTL
6948 WHERE MTL.concatenated_segments = p_item_number
6949 AND MTL.organization_id = p_inventory_org_id;
6950 l_physical_item_id NUMBER;
6951 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.convert_order_lines_val_to_id';
6952 BEGIN
6953 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
6954 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
6955 END IF;
6956 -- nulling out ids if module type is JSP
6957 --Jerry 04/18/2005, this 'JSP' consideration may not be necessary for
6958 --newly added physical item, so it is not added here
6959 IF(g_module_type = 'JSP') THEN
6960 -- service item number
6961 IF(p_x_osp_order_line_rec.service_item_number IS NULL) THEN
6962 p_x_osp_order_line_rec.service_item_id := NULL;
6963 ELSIF (p_x_osp_order_line_rec.service_item_number = FND_API.G_MISS_CHAR) THEN
6964 IF(p_x_osp_order_line_rec.operation_flag <> G_OP_CREATE) THEN
6965 p_x_osp_order_line_rec.service_item_id := FND_API.G_MISS_NUM;
6966 ELSE
6967 p_x_osp_order_line_rec.service_item_id := NULL;
6968 END IF;
6969 END IF;
6970 -- job number and workorder_id
6971 IF(p_x_osp_order_line_rec.job_number IS NULL) THEN
6972 p_x_osp_order_line_rec.workorder_id := NULL;
6973 ELSIF (p_x_osp_order_line_rec.job_number = FND_API.G_MISS_CHAR) THEN
6974 IF(p_x_osp_order_line_rec.operation_flag <> G_OP_CREATE) THEN
6975 p_x_osp_order_line_rec.workorder_id := FND_API.G_MISS_NUM;
6976 ELSE
6977 p_x_osp_order_line_rec.workorder_id := NULL;
6978 END IF;
6979 END IF;
6980 -- po_line_type_id
6981 IF(p_x_osp_order_line_rec.po_line_type IS NULL) THEN
6982 p_x_osp_order_line_rec.po_line_type_id := NULL;
6983 ELSIF (p_x_osp_order_line_rec.po_line_type = FND_API.G_MISS_CHAR) THEN
6984 IF(p_x_osp_order_line_rec.operation_flag <> G_OP_CREATE) THEN
6985 p_x_osp_order_line_rec.po_line_type_id := FND_API.G_MISS_NUM;
6986 ELSE
6987 p_x_osp_order_line_rec.po_line_type_id := NULL;
6988 END IF;
6989 END IF;
6990 END IF;
6991 -- conversion of value to id for job number (to workorder_id)
6992 IF (p_x_osp_order_line_rec.job_number IS NOT NULL AND p_x_osp_order_line_rec.job_number <> FND_API.G_MISS_CHAR) THEN
6993 OPEN workorder_id_csr(p_x_osp_order_line_rec.job_number);
6994 FETCH workorder_id_csr INTO l_workorder_id;
6995 IF(workorder_id_csr%NOTFOUND) THEN
6996 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_JOB_NUM_INV');
6997 FND_MESSAGE.Set_Token('JOB_NUMBER', p_x_osp_order_line_rec.job_number);
6998 FND_MSG_PUB.ADD;
6999 ELSE
7000 p_x_osp_order_line_rec.workorder_id := l_workorder_id;
7001 END IF;
7002 CLOSE workorder_id_csr;
7003 END IF;
7004 -- conversion of value to id for service item number
7005 IF (p_x_osp_order_line_rec.service_item_number IS NOT NULL AND p_x_osp_order_line_rec.service_item_number <> FND_API.G_MISS_CHAR) THEN
7006 OPEN service_item_id_csr(p_x_osp_order_line_rec.service_item_number, p_x_osp_order_line_rec.inventory_org_id);
7007 FETCH service_item_id_csr INTO l_service_item_id;
7008 IF(service_item_id_csr%NOTFOUND) THEN
7009 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_SVC_ITEM_INV');
7010 FND_MESSAGE.Set_Token('SERVICE_ITEM', p_x_osp_order_line_rec.service_item_number);
7011 FND_MSG_PUB.ADD;
7012 ELSE
7013 p_x_osp_order_line_rec.service_item_id := l_service_item_id;
7014 END IF;
7015 CLOSE service_item_id_csr;
7016 END IF;
7017 -- conversion of value to id for po_line_type (to po_line_type_id)
7018 IF (p_x_osp_order_line_rec.po_line_type IS NOT NULL AND p_x_osp_order_line_rec.po_line_type <> FND_API.G_MISS_CHAR) THEN
7019 OPEN po_line_type_id_csr(p_x_osp_order_line_rec.po_line_type);
7020 FETCH po_line_type_id_csr INTO l_po_line_type_id;
7021 IF(po_line_type_id_csr%NOTFOUND) THEN
7022 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_PO_LN_TYPE_INV');
7023 FND_MESSAGE.Set_Token('PO_LINE_TYPE', p_x_osp_order_line_rec.po_line_type);
7024 FND_MSG_PUB.ADD;
7025 ELSE
7026 p_x_osp_order_line_rec.po_line_type_id := l_po_line_type_id;
7027 END IF;
7028 CLOSE po_line_type_id_csr;
7029 END IF;
7030 -- conversion of value to id for exchange_instance_number (to exchange_instance_id)
7031 IF (p_x_osp_order_line_rec.exchange_instance_number IS NOT NULL AND p_x_osp_order_line_rec.exchange_instance_number <> FND_API.G_MISS_CHAR) THEN
7032 OPEN exchange_instance_id_csr(p_x_osp_order_line_rec.exchange_instance_number);
7033 FETCH exchange_instance_id_csr INTO l_exchange_instance_id;
7034 IF(exchange_instance_id_csr%NOTFOUND) THEN
7035 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_X_INST_NUM_INV');
7036 FND_MESSAGE.Set_Token('INTANCE_NUMBER', p_x_osp_order_line_rec.exchange_instance_number);
7037 FND_MSG_PUB.ADD;
7038 ELSE
7039 p_x_osp_order_line_rec.exchange_instance_id := l_exchange_instance_id;
7040 END IF;
7041 CLOSE exchange_instance_id_csr;
7042 END IF;
7043 -- conversion of value to id for physical item number
7044 IF (p_x_osp_order_line_rec.item_number IS NOT NULL AND p_x_osp_order_line_rec.inventory_item_id IS NULL) THEN
7045 OPEN physical_item_id_csr(p_x_osp_order_line_rec.item_number, p_x_osp_order_line_rec.inventory_org_id);
7046 FETCH physical_item_id_csr INTO l_physical_item_id;
7047 IF(physical_item_id_csr%NOTFOUND) THEN
7048 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_PHY_ITEM_INV');
7049 FND_MESSAGE.Set_Token('PHSICAL_ITEM', p_x_osp_order_line_rec.item_number);
7050 FND_MSG_PUB.ADD;
7051 ELSE
7052 p_x_osp_order_line_rec.inventory_item_id := l_physical_item_id;
7053 END IF;
7054 CLOSE physical_item_id_csr;
7055 END IF;
7056 -- fetching the unique key osp_order_line_id based on other unique keys
7057 IF (p_x_osp_order_line_rec.osp_order_line_id IS NULL) THEN
7058 IF p_x_osp_order_line_rec.operation_flag <> G_OP_CREATE THEN
7059 IF (p_x_osp_order_line_rec.osp_order_id IS NOT NULL AND p_x_osp_order_line_rec.osp_line_number IS NOT NULL) THEN
7060 OPEN osp_order_line_on_csr(p_x_osp_order_line_rec.osp_order_id , p_x_osp_order_line_rec.osp_line_number);
7061 FETCH osp_order_line_on_csr INTO l_osp_order_line_id;
7062 IF(osp_order_line_on_csr%NOTFOUND) THEN
7063 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_ORD_ID_LN_INV');
7064 FND_MESSAGE.Set_Token('OSP_LINE_NUMBER', p_x_osp_order_line_rec.osp_line_number);
7065 FND_MSG_PUB.ADD;
7066 ELSE
7067 p_x_osp_order_line_rec.osp_order_line_id := l_osp_order_line_id;
7068 END IF;
7069 CLOSE osp_order_line_on_csr;
7070 -- Added by jaramana on January 10, 2008 for the Requisition ER 6034236
7071 -- We are not planning to derive the OSP_ORDER_LINE_ID from PO_LINE_ID
7072 /*
7073 ELSIF (p_x_osp_order_line_rec.po_line_id IS NOT NULL AND p_x_osp_order_line_rec.po_line_id <> FND_API.G_MISS_NUM) THEN
7074 OPEN osp_order_line_po_csr(p_x_osp_order_line_rec.po_line_id );
7075 FETCH osp_order_line_po_csr INTO l_osp_order_line_id;
7076 IF(osp_order_line_po_csr%NOTFOUND) THEN
7077 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_PO_LINE_INV');
7078 FND_MESSAGE.Set_Token('PO_LINE_ID', p_x_osp_order_line_rec.po_line_id);
7079 FND_MSG_PUB.ADD;
7080 ELSE
7081 p_x_osp_order_line_rec.osp_order_line_id := l_osp_order_line_id;
7082 END IF;
7083 CLOSE osp_order_line_po_csr;
7084 */
7085 -- jaramana End
7086 ELSE
7087 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV');
7088 FND_MESSAGE.Set_Token('OSP_LINE_NUMBER', p_x_osp_order_line_rec.osp_line_number); FND_MSG_PUB.ADD;
7089 END IF;
7090 END IF;
7091 END IF;
7092 IF FND_MSG_PUB.count_msg > 0 THEN
7093 RAISE FND_API.G_EXC_ERROR;
7094 -- RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7095 END IF;
7096 --dbms_output.put_line('Exiting : convert_order_lines_val_to_id');
7097 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
7098 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
7099 END IF;
7100 END convert_order_line_val_to_id;
7101
7102 --validate service_item_id (simplified the original one)
7103 PROCEDURE validate_service_item_id(
7104 p_service_item_id IN NUMBER,
7105 p_organization_id IN NUMBER)
7106 IS
7107 CURSOR val_service_item_id_csr IS
7108 SELECT 'X'
7109 FROM mtl_system_items_kfv MTL
7110 WHERE MTL.inventory_item_id = p_service_item_id
7111 AND MTL.enabled_flag = G_YES_FLAG
7112 AND MTL.inventory_item_flag = G_NO_FLAG
7113 AND MTL.stock_enabled_flag = G_NO_FLAG
7114 AND NVL(MTL.start_date_active, SYSDATE - 1) <= SYSDATE
7115 AND NVL(MTL.end_date_active, SYSDATE + 1) > SYSDATE
7116 AND MTL.purchasing_enabled_flag = G_YES_FLAG
7117 AND NVL(MTL.outside_operation_flag, G_NO_FLAG) = G_NO_FLAG
7118 AND MTL.organization_id = p_organization_id;
7119 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.validate_service_item_id';
7120 BEGIN
7121 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
7122 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
7123 END IF;
7124
7125 IF(p_service_item_id IS NOT NULL AND p_service_item_id <> FND_API.G_MISS_NUM) THEN
7126 OPEN val_service_item_id_csr;
7127 FETCH val_service_item_id_csr INTO g_dummy_char;
7128 IF(val_service_item_id_csr%NOTFOUND) THEN
7129 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_LN_INV_SVC_ITEM');
7130 FND_MESSAGE.Set_Token('SERVICE_ITEM_ID', p_service_item_id);
7131 FND_MSG_PUB.ADD;
7132 END IF;
7133 CLOSE val_service_item_id_csr;
7134 END IF;
7135
7136 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
7137 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
7138 END IF;
7139 END validate_service_item_id;
7140
7141 --Validate header vendor with physical, service item combination in line
7142 PROCEDURE validate_vendor_service_item(p_osp_order_line_rec IN osp_order_line_rec_type)
7143 IS
7144 l_vendor_id NUMBER;
7145 l_vendor_site_id NUMBER;
7146 l_vendor_contact_id NUMBER;
7147 l_msg_count NUMBER;
7148 l_msg_data VARCHAR2(2000);
7149 CURSOR verify_vendor(c_vendor_id NUMBER, c_vendor_site_id NUMBER) IS
7150 SELECT A.inv_service_item_rel_id
7151 FROM ahl_inv_service_item_rels A,
7152 ahl_item_vendor_rels_v B
7153 WHERE A.inv_service_item_rel_id = B.inv_service_item_rel_id
7154 AND A.inv_item_id = p_osp_order_line_rec.inventory_item_id
7155 AND A.inv_org_id = p_osp_order_line_rec.inventory_org_id
7156 AND A.service_item_id = p_osp_order_line_rec.service_item_id
7157 AND TRUNC(A.active_start_date) <= TRUNC(SYSDATE)
7158 AND TRUNC(NVL(A.active_end_date, SYSDATE+1)) > TRUNC(SYSDATE)
7159 AND TRUNC(B.active_start_date) <= TRUNC(SYSDATE)
7160 AND TRUNC(NVL(B.active_end_date, SYSDATE+1)) > TRUNC(SYSDATE)
7161 AND B.vendor_id = c_vendor_id
7162 AND B.vendor_site_id = c_vendor_site_id;
7163 --AND B.vendor_contact_id = l_vendor_contact_id;
7164 BEGIN
7165 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
7166 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
7167 G_LOG_PREFIX || '.validate_vendor_service_item',
7168 'osp_order_id='||p_osp_order_line_rec.osp_order_id );
7169 END IF;
7170 --IF (p_osp_order_line_rec.workorder_id IS NULL) THEN --commented out on 06/10/2006
7171 /*(From Jay said on 06/07/2005) service_item_id is not mandatory even for update
7172 IF p_osp_order_line_rec.service_item_id IS NULL THEN
7173 FND_MESSAGE.set_name('AHL', 'AHL_OSP_SERVICE_ITEM_NULL');
7174 FND_MSG_PUB.add;
7175 END IF;
7176 */
7177 --(Note: 05/31/2005 Jerry)It is not good to use ahl_osp_orders_v here but
7178 --there exists a special case where vendor_contact_id is null in
7179 --ahl_osp_orders_b but populated in ahl_osp_orders_v. After discussion with
7180 --Jay and found we have to use _v here because the vendor_id and vendor_site_id
7181 --could be changed from PO side
7182 BEGIN
7183 --Modified by mpothuku on 27-Feb-06 to fix the Perf Bug #4919164
7184 /*
7185 SELECT decode(osp.po_header_id, null, osp.vendor_id, po.vendor_id) vendor_id,
7186 decode(osp.po_header_id, null, osp.vendor_site_id, po.vendor_site_id) vendor_site_id --, vendor_contact_id
7187 INTO l_vendor_id, l_vendor_site_id --, l_vendor_contact_id
7188 FROM ahl_osp_orders_b osp,
7189 po_headers_all po
7190 WHERE osp.osp_order_id = p_osp_order_line_rec.osp_order_id
7191 AND osp.po_header_id = po.po_header_id(+);
7192 */
7193 --modified by mpothuku on 14-mar-2008 to fix the Bug 6885513
7194 SELECT vendor_id,
7195 vendor_site_id
7196 INTO l_vendor_id, l_vendor_site_id --, l_vendor_contact_id
7197 FROM ahl_osp_orders_b osp
7198 WHERE osp.osp_order_id = p_osp_order_line_rec.osp_order_id;
7199 --mpothuku End
7200 EXCEPTION
7201 WHEN NO_DATA_FOUND THEN
7202 FND_MESSAGE.set_name('AHL', 'AHL_OSP_ORDER_INVALID');
7203 FND_MSG_PUB.add;
7204 END;
7205
7206 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
7207 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT,
7208 G_LOG_PREFIX || '.validate_vendor_service_item',
7209 'vendor_id='||l_vendor_id||
7210 'item_id='||p_osp_order_line_rec.inventory_item_id||
7211 'org_id='||p_osp_order_line_rec.inventory_org_id||
7212 'service_id='||p_osp_order_line_rec.service_item_id);
7213 END IF;
7214
7215 IF (l_vendor_id IS NOT NULL AND l_vendor_site_id IS NOT NULL AND
7216 p_osp_order_line_rec.service_item_id IS NOT NULL) THEN
7217 --If the service_item_id in OSP Order Line is null then we don't have to
7218 --validate it against OSP header vendor attributes
7219 --Check the vendor itself is valid
7220 BEGIN
7221 SELECT 'X' INTO g_dummy_char
7222 FROM ahl_vendor_certifications_v
7223 WHERE vendor_id = l_vendor_id
7224 AND vendor_site_id = l_vendor_site_id
7225 AND trunc(active_start_date) <= trunc(SYSDATE)
7226 AND trunc(nvl(active_end_date, SYSDATE+1)) > trunc(SYSDATE);
7227 EXCEPTION
7228 WHEN NO_DATA_FOUND THEN
7229 FND_MESSAGE.Set_Name(G_APP_NAME,'AHL_OSP_VENDOR_ID_INV');
7230 FND_MESSAGE.Set_Token('VENDOR_ID', l_vendor_id);
7231 FND_MSG_PUB.ADD;
7232 END;
7233
7234 OPEN verify_vendor(l_vendor_id, l_vendor_site_id);
7235 FETCH verify_vendor INTO g_dummy_num;
7236 IF verify_vendor%NOTFOUND THEN
7237 FND_MESSAGE.set_name('AHL', 'AHL_OSP_ITEM_VENDOR_MISMATCH');
7238 FND_MESSAGE.set_token('ITEM_ID', p_osp_order_line_rec.inventory_item_id);
7239 FND_MSG_PUB.add;
7240 RAISE FND_API.G_EXC_ERROR;
7241 --FND_MSG_PUB.count_and_get(
7242 --p_encoded => FND_API.G_FALSE,
7243 --p_count => l_msg_count,
7244 --p_data => l_msg_data);
7245 END IF;
7246 CLOSE verify_vendor;
7247 END IF;
7248 --END IF;
7249 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
7250 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
7251 G_LOG_PREFIX || '.validate_vendor_service_item',
7252 'Normal end and msg_count='||l_msg_count||
7253 'msg='||l_msg_data);
7254 END IF;
7255 END validate_vendor_service_item;
7256
7257 PROCEDURE process_order_type_change(
7258 p_osp_order_rec IN osp_order_rec_type) IS
7259 l_old_type_code VARCHAR2(30);
7260 l_return_status VARCHAR2(30);
7261 l_msg_count NUMBER;
7262 l_msg_data VARCHAR2(2000);
7263 BEGIN
7264 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
7265 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, G_LOG_PREFIX||'process_order_type_change', 'Begin');
7266 END IF;
7267 SELECT order_type_code INTO l_old_type_code
7268 FROM ahl_osp_orders_b
7269 WHERE osp_order_id = p_osp_order_rec.osp_order_id;
7270 IF l_old_type_code <> p_osp_order_rec.order_type_code THEN
7271 IF(can_convert_order(p_osp_order_rec.osp_order_id, l_old_type_code, p_osp_order_rec.order_type_code)) THEN
7272 IF(p_osp_order_rec.order_type_code = G_OSP_ORDER_TYPE_SERVICE) THEN
7273 UPDATE ahl_osp_order_lines
7274 SET exchange_instance_id = NULL,
7275 last_update_date = SYSDATE,
7276 last_updated_by = fnd_global.user_id,
7277 last_update_login = fnd_global.login_id,
7278 object_version_number = object_version_number+1
7279 WHERE osp_order_id = p_osp_order_rec.osp_order_id;
7280 --set exchange instance id to null and update object_version_number in p_x_osp_order_lines_tbl
7281 --nullify_exchange_instance(p_osp_order_rec.osp_order_id, p_x_osp_order_lines_tbl);
7282 END IF;
7283 AHL_OSP_SHIPMENT_PUB.convert_subtxn_type(
7284 p_api_version => 1.0,
7285 p_init_msg_list => FND_API.G_FALSE,
7286 p_commit => FND_API.G_FALSE,
7287 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
7288 p_default => FND_API.G_TRUE,
7289 p_module_type => NULL,
7290 p_osp_order_id => p_osp_order_rec.osp_order_id ,
7291 p_old_order_type_code => l_old_type_code,
7292 p_new_order_type_code => p_osp_order_rec.order_type_code,
7293 x_return_status => l_return_status,
7294 x_msg_count => l_msg_count,
7295 x_msg_data => l_msg_data);
7296 END IF;
7297 END IF;
7298 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
7299 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, G_LOG_PREFIX||'process_order_type_change', 'End');
7300 END IF;
7301 END process_order_type_change;
7302
7303 END ahl_osp_orders_pvt;
7304
7305 /*
7306 PROCEDURE nullify_exchange_instance(
7307 p_osp_order_id IN NUMBER,
7308 p_x_osp_order_lines_tbl IN OUT NOCOPY osp_order_lines_tbl_type
7309 ) IS
7310 CURSOR l_order_lines_csr(p_osp_order_id IN NUMBER) IS
7311 SELECT osp_order_line_id, object_version_number, last_update_date, last_updated_by , last_update_login,
7312 osp_order_id, osp_line_number, status_code , po_line_type_id, service_item_id, service_item_description , service_item_uom_code,
7313 need_by_date, ship_by_date, po_line_id, oe_ship_line_id , oe_return_line_id , workorder_id, operation_id,
7314 quantity, exchange_instance_id, attribute_category, attribute1, attribute2, attribute3, attribute4, attribute5, attribute6,
7315 attribute7, attribute8, attribute9, attribute10, attribute11, attribute12, attribute13, attribute14, attribute15
7316 FROM ahl_osp_order_lines
7317 WHERE osp_order_id = p_osp_order_id;
7318 l_osp_order_lines_rec osp_order_line_rec_type;
7319 CURSOR l_order_line_obj_ver_csr(p_osp_order_line_id IN NUMBER) IS
7320 SELECT object_version_number FROM ahl_osp_order_lines
7321 WHERE osp_order_line_id = p_osp_order_line_id;
7322 i NUMBER; --index for looping
7323 L_DEBUG_KEY CONSTANT VARCHAR2(150) := G_LOG_PREFIX || '.nullify_exchange_instance';
7324 BEGIN
7325 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
7326 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.begin', 'Begin Procedure');
7327 END IF;
7328 OPEN l_order_lines_csr(p_osp_order_id);
7329 LOOP
7330 FETCH l_order_lines_csr INTO l_osp_order_lines_rec.osp_order_line_id ,
7331 l_osp_order_lines_rec.object_version_number ,
7332 l_osp_order_lines_rec.last_update_date ,
7333 l_osp_order_lines_rec.last_updated_by ,
7334 l_osp_order_lines_rec.last_update_login ,
7335 l_osp_order_lines_rec.osp_order_id ,
7336 l_osp_order_lines_rec.osp_line_number ,
7337 l_osp_order_lines_rec.status_code ,
7338 l_osp_order_lines_rec.po_line_type_id ,
7339 l_osp_order_lines_rec.service_item_id ,
7340 l_osp_order_lines_rec.service_item_description ,
7341 l_osp_order_lines_rec.service_item_uom_code ,
7342 l_osp_order_lines_rec.need_by_date ,
7343 l_osp_order_lines_rec.ship_by_date ,
7344 l_osp_order_lines_rec.po_line_id ,
7345 l_osp_order_lines_rec.oe_ship_line_id ,
7346 l_osp_order_lines_rec.oe_return_line_id ,
7347 l_osp_order_lines_rec.workorder_id ,
7348 l_osp_order_lines_rec.operation_id ,
7349 l_osp_order_lines_rec.quantity ,
7350 l_osp_order_lines_rec.exchange_instance_id ,
7351 l_osp_order_lines_rec.attribute_category ,
7352 l_osp_order_lines_rec.attribute1 ,
7353 l_osp_order_lines_rec.attribute2 ,
7354 l_osp_order_lines_rec.attribute3 ,
7355 l_osp_order_lines_rec.attribute4 ,
7356 l_osp_order_lines_rec.attribute5 ,
7357 l_osp_order_lines_rec.attribute6 ,
7358 l_osp_order_lines_rec.attribute7 ,
7359 l_osp_order_lines_rec.attribute8 ,
7360 l_osp_order_lines_rec.attribute9 ,
7361 l_osp_order_lines_rec.attribute10 ,
7362 l_osp_order_lines_rec.attribute11 ,
7363 l_osp_order_lines_rec.attribute12 ,
7364 l_osp_order_lines_rec.attribute13 ,
7365 l_osp_order_lines_rec.attribute14 ,
7366 l_osp_order_lines_rec.attribute15 ;
7367 IF(l_order_lines_csr %NOTFOUND) THEN
7368 EXIT;
7369 END IF;
7370 AHL_OSP_ORDER_LINES_PKG.update_row(
7371 p_osp_order_line_id => l_osp_order_lines_rec.osp_order_line_id,
7372 p_object_version_number => l_osp_order_lines_rec.object_version_number + 1,
7373 p_last_update_date => l_osp_order_lines_rec.last_update_date,
7374 p_last_updated_by => l_osp_order_lines_rec.last_updated_by,
7375 p_last_update_login => l_osp_order_lines_rec.last_update_login,
7376 p_osp_order_id => l_osp_order_lines_rec.osp_order_id,
7377 p_osp_line_number => l_osp_order_lines_rec.osp_line_number,
7378 p_status_code => l_osp_order_lines_rec.status_code,
7379 p_po_line_type_id => l_osp_order_lines_rec.po_line_type_id,
7380 p_service_item_id => l_osp_order_lines_rec.service_item_id,
7381 p_service_item_description => l_osp_order_lines_rec.service_item_description,
7382 p_service_item_uom_code => l_osp_order_lines_rec.service_item_uom_code,
7383 p_need_by_date => l_osp_order_lines_rec.need_by_date,
7384 p_ship_by_date => l_osp_order_lines_rec.ship_by_date,
7385 p_po_line_id => l_osp_order_lines_rec.po_line_id,
7386 p_oe_ship_line_id => l_osp_order_lines_rec.oe_ship_line_id,
7387 p_oe_return_line_id => l_osp_order_lines_rec.oe_return_line_id,
7388 p_workorder_id => l_osp_order_lines_rec.workorder_id,
7389 p_operation_id => l_osp_order_lines_rec.operation_id,
7390 p_quantity => l_osp_order_lines_rec.quantity,
7391 p_exchange_instance_id => NULL,
7392 p_inventory_item_id => l_osp_order_lines_rec.inventory_item_id,
7393 p_inventory_org_id => l_osp_order_lines_rec.inventory_org_id,
7394 p_inventory_item_uom => l_osp_order_lines_rec.inventory_item_uom,
7395 p_inventory_item_quantity => l_osp_order_lines_rec.inventory_item_quantity,
7396 p_sub_inventory => l_osp_order_lines_rec.sub_inventory,
7397 p_lot_number => l_osp_order_lines_rec.lot_number,
7398 p_serial_number => l_osp_order_lines_rec.serial_number,
7399
7400 p_attribute_category => l_osp_order_lines_rec.attribute_category,
7401 p_attribute1 => l_osp_order_lines_rec.attribute1,
7402 p_attribute2 => l_osp_order_lines_rec.attribute2,
7403 p_attribute3 => l_osp_order_lines_rec.attribute3,
7404 p_attribute4 => l_osp_order_lines_rec.attribute4,
7405 p_attribute5 => l_osp_order_lines_rec.attribute5,
7406 p_attribute6 => l_osp_order_lines_rec.attribute6,
7407 p_attribute7 => l_osp_order_lines_rec.attribute7,
7408 p_attribute8 => l_osp_order_lines_rec.attribute8,
7409 p_attribute9 => l_osp_order_lines_rec.attribute9,
7410 p_attribute10 => l_osp_order_lines_rec.attribute10,
7411 p_attribute11 => l_osp_order_lines_rec.attribute11,
7412 p_attribute12 => l_osp_order_lines_rec.attribute12,
7413 p_attribute13 => l_osp_order_lines_rec.attribute13,
7414 p_attribute14 => l_osp_order_lines_rec.attribute14,
7415 p_attribute15 => l_osp_order_lines_rec.attribute15
7416 );
7417 END LOOP;
7418 --get the newest object_version_number for p_x_osp_order_lines_tbl
7419 IF(p_x_osp_order_lines_tbl IS NOT NULL AND p_x_osp_order_lines_tbl.COUNT > 0) THEN
7420 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
7421 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, ' p_x_osp_order_lines_tbl not null' ||
7422 'p_x_osp_order_lines_tbl.FIRST: ' || p_x_osp_order_lines_tbl.FIRST ||
7423 'p_x_osp_order_lines_tbl.LAST: ' || p_x_osp_order_lines_tbl.LAST);
7424 END IF;
7425 FOR i IN p_x_osp_order_lines_tbl.FIRST..p_x_osp_order_lines_tbl.LAST LOOP
7426 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
7427 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'loop inside table p_x_osp_order_lines_tbl');
7428 END IF;
7429 IF(p_x_osp_order_lines_tbl(i).osp_order_line_id IS NOT NULL) THEN
7430 IF (FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
7431 FND_LOG.STRING(FND_LOG.LEVEL_STATEMENT, L_DEBUG_KEY, 'loop inside table p_x_osp_order_lines_tbl.osp_order_line_id');
7432 END IF;
7433 OPEN l_order_line_obj_ver_csr(p_x_osp_order_lines_tbl(i).osp_order_line_id);
7434 FETCH l_order_line_obj_ver_csr INTO p_x_osp_order_lines_tbl(i).object_version_number;
7435 CLOSE l_order_line_obj_ver_csr;
7436 END IF;
7437 END LOOP;
7438 END IF;
7439 IF (FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
7440 FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE, L_DEBUG_KEY || '.end', 'End Procedure');
7441 END IF;
7442 END nullify_exchange_instance;
7443 */