[Home] [Help]
PACKAGE BODY: APPS.POR_AMENDMENT_PKG
Source
1 PACKAGE BODY por_amendment_pkg AS
2 /* $Header: POR_AMENDMENT_PKG.plb 120.63.12020000.7 2013/06/04 06:39:38 bpulivar ship $ */
3
4
5 -- Logging Static Variables
6 G_CURRENT_RUNTIME_LEVEL NUMBER;
7 G_LEVEL_UNEXPECTED CONSTANT NUMBER := FND_LOG.LEVEL_UNEXPECTED;
8 G_LEVEL_ERROR CONSTANT NUMBER := FND_LOG.LEVEL_ERROR;
9 G_LEVEL_EXCEPTION CONSTANT NUMBER := FND_LOG.LEVEL_EXCEPTION;
10 G_LEVEL_EVENT CONSTANT NUMBER := FND_LOG.LEVEL_EVENT;
11 G_LEVEL_PROCEDURE CONSTANT NUMBER := FND_LOG.LEVEL_PROCEDURE;
12 G_LEVEL_STATEMENT CONSTANT NUMBER := FND_LOG.LEVEL_STATEMENT;
13 G_MODULE_NAME CONSTANT VARCHAR2(30) := 'ICX.PLSQL.POR_AMENDMENT_PKG';
14
15 g_po_wf_debug VARCHAR2(1) := NVL(FND_PROFILE.VALUE('PO_SET_DEBUG_WORKFLOW_ON'),'N');
16
17 TYPE g_line_id_map IS TABLE OF NUMBER INDEX BY VARCHAR2(20);
18
19 /* Forward Declartion */
20 PROCEDURE Clm_MergeReserve_Autonomous
21 (
22 itemtype IN VARCHAR2,
23 itemkey IN VARCHAR2,
24 p_doc_type IN VARCHAR2,
25 p_doc_subtype IN VARCHAR2,
26 p_doc_id IN NUMBER,
27 p_override_funds IN VARCHAR2 DEFAULT 'N',
28 p_employee_id IN NUMBER,
29 p_conformed_header_id IN NUMBER DEFAULT NULL,
30 P_revision_num IN NUMBER,
31 P_amendment_approval IN VARCHAR2 DEFAULT 'N',
32 x_po_return_code OUT NOCOPY VARCHAR2,
33 x_online_report_id OUT NOCOPY NUMBER,
34 x_return_status OUT NOCOPY VARCHAR2
35 );
36 /*********************************************************************
37 * NAME
38 * compare_table
39 *
40 * PURPOSE
41 * Checks for the changes in Header, Line and Distribution level and populates
42 * the temp table with field altered, old value and new value.
43 *
44 * ARGUMENTS
45 * p_table_name IN Table name, possible values:
46 * PO_REQUISITION_HEADERS_ALL
47 * PO_REQUISITION_LINES_ALL
48 * PO_REQ_DISTRIBUTIONS_ALL
49 * p_revision_num IN
50 * p_confirmed_id IN
51 * amend_num OUT
52 *
53 * NOTES
54 *
55 *
56 * HISTORY
57 * 11-07-09 Bisdas Created
58 ********************************************************************/
59
60 PROCEDURE compare_table(p_table_name VARCHAR2,
61 p_revision_num NUMBER,
62 p_confirmed_id NUMBER,
63 amend_num IN OUT NOCOPY varchar2)
64 AS
65
66 sql_stmt1 VARCHAR2(10000);
67 sql_stmt2 VARCHAR2(10000);
68
69 p_level VARCHAR2(50);
70
71 -- UDA Related Changes
72 x_database_view_name VARCHAR2(50);
73 l_select_cols VARCHAR2(1000) := 'C_EXT_ATTR39';
74
75 CURSOR col_list(x_addr_group_name EGO_ATTRS_V.attr_group_name%TYPE)
76 IS
77 SELECT attr.database_column
78 FROM ego_attrs_v attr
79 WHERE attr.attr_group_name = x_addr_group_name
80 AND attr.attr_group_type = 'PO_REQ_HEADER_EXT_ATTRS'
81 AND attr.display_code <> 'H'
82 AND read_only_flag = 'N';
83
84
85 --Debugging purpose
86 v_progress VARCHAR2(3);
87 l_procedure_name VARCHAR2(100) := 'compare_table';
88 l_log_msg VARCHAR2(2000);
89
90
91 BEGIN
92
93
94 v_progress:='000';
95 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
96 l_log_msg := 'Invoked '||l_procedure_name;
97 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
98 l_log_msg := 'p_confirmed_id : '||p_confirmed_id||', p_revision_num : '||p_revision_num||', p_table_name :'||p_table_name;
99 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
100 END IF;
101
102 -- SQL What: Querying the archive table for the given revision_num and previous revision_num
103 -- SQL Why: Need to compare the values for each column
104
105 IF p_table_name = 'PO_REQUISITION_HEADERS_ALL' then
106
107 sql_stmt1:='SELECT REQUISITION_HEADER_ID,
108 SEGMENT1,
109 nvl(CANCEL_FLAG,''N'') CANCEL_FLAG,
110 nvl(CLOSED_CODE,''OPEN'') CLOSED_CODE,
111 DESCRIPTION,
112 NOTE_TO_AUTHORIZER,
113 USSGL_TRANSACTION_CODE,
114 PCARD_ID,
115 REVISION_NUM,
116 CLM_MIPR_TYPE,
117 CLM_MIPR_PREPARED_DATE,
118 CLM_MIPR_REF_NUM
119 FROM po_requisition_headers_all
120 WHERE conformed_header_id='||p_confirmed_id||
121 ' AND revision_num='||(p_revision_num -1);
122
123
124 sql_stmt2:='SELECT REQUISITION_HEADER_ID,
125 SEGMENT1,
126 nvl(CANCEL_FLAG,''N'') CANCEL_FLAG,
127 nvl(CLOSED_CODE,''OPEN'') CLOSED_CODE,
128 DESCRIPTION,
129 NOTE_TO_AUTHORIZER,
130 USSGL_TRANSACTION_CODE,
131 PCARD_ID,
132 REVISION_NUM,
133 CLM_MIPR_TYPE,
134 CLM_MIPR_PREPARED_DATE,
135 CLM_MIPR_REF_NUM
136 FROM po_requisition_headers_all
137 WHERE conformed_header_id='||p_confirmed_id||
138 ' AND revision_num='||p_revision_num;
139
140
141 p_level:= 'HEADER';
142
143 ELSIF p_table_name = 'PO_REQUISITION_LINES_ALL' then
144
145 sql_stmt1:= 'SELECT REQUISITION_LINE_ID,LINE_NUM, LINE_NUM_DISPLAY,nvl(prl.CANCEL_FLAG,''N'') CANCEL_FLAG, nvl(prl.CLOSED_CODE,''OPEN'') CLOSED_CODE,ITEM_ID,ITEM_REVISION,
146 ITEM_DESCRIPTION, CATEGORY_ID, UNIT_MEAS_LOOKUP_CODE, UNIT_PRICE,QUANTITY,DELIVER_TO_LOCATION_ID,TO_PERSON_ID,
147 SUGGESTED_BUYER_ID,to_char(NEED_BY_DATE,''DD-MON-YYYY HH24:MI:SS'') NEED_BY_DATE,JUSTIFICATION,NOTE_TO_AGENT,NOTE_TO_RECEIVER,CURRENCY_CODE,RATE_TYPE,to_char(RATE_DATE,''DD-MON-YYYY HH24:MI:SS'') RATE_DATE,
148 RATE,CURRENCY_UNIT_PRICE,SUGGESTED_VENDOR_NAME,SUGGESTED_VENDOR_LOCATION,SUGGESTED_VENDOR_CONTACT,SUGGESTED_VENDOR_PHONE,
149 SUGGESTED_VENDOR_PRODUCT_CODE,HAZARD_CLASS_ID,DESTINATION_TYPE_CODE,DESTINATION_ORGANIZATION_ID, DESTINATION_SUBINVENTORY,
150 VENDOR_ID,VENDOR_SITE_ID, VENDOR_CONTACT_ID,prl.USSGL_TRANSACTION_CODE USSGL_TRANSACTION_CODE, MANUFACTURER_NAME,
151 MANUFACTURER_PART_NUMBER, REQUESTER_EMAIL,REQUESTER_FAX,REQUESTER_PHONE, UNSPSC_CODE, SUPPLIER_DUNS,AMOUNT,
152 CURRENCY_AMOUNT,JOB_LONG_DESCRIPTION,SUGGESTED_VENDOR_CONTACT_FAX,SUGGESTED_VENDOR_CONTACT_EMAIL,CANDIDATE_FIRST_NAME,
153 CANDIDATE_LAST_NAME,to_char(ASSIGNMENT_START_DATE,''DD-MON-YYYY HH24:MI:SS'') ASSIGNMENT_START_DATE,CONTRACT_TYPE,COST_CONSTRAINT,
154 to_char(CLM_PERIOD_PERF_START_DATE,''DD-MON-YYYY HH24:MI:SS'') CLM_PERIOD_PERF_START_DATE,to_char(CLM_PERIOD_PERF_END_DATE,''DD-MON-YYYY HH24:MI:SS'') CLM_PERIOD_PERF_END_DATE,
155 nvl(CLM_OPTION_EXERCISED,''N'') CLM_OPTION_EXERCISED, CLM_OPTION_FROM_DATE, CLM_OPTION_TO_DATE, FUND_SOURCE_NOT_KNOWN,CLM_OPTION_INDICATOR , CLM_BASE_LINE_NUM , CLM_MIPR_OBLIGATION_TYPE
156 FROM po_requisition_lines_all prl,
157 po_requisition_headers_all prh
158 WHERE prh.conformed_header_id='||p_confirmed_id||
159 'AND prh.requisition_header_id=prl.requisition_header_id
160 AND prh.revision_num='||(p_revision_num -1)||
161 'ORDER BY LINE_NUM';
162
163 sql_stmt2:='SELECT REQUISITION_LINE_ID,LINE_NUM, LINE_NUM_DISPLAY,nvl(prl.CANCEL_FLAG,''N'') CANCEL_FLAG, nvl(prl.CLOSED_CODE,''OPEN'') CLOSED_CODE,ITEM_ID,ITEM_REVISION,
164 ITEM_DESCRIPTION, CATEGORY_ID, UNIT_MEAS_LOOKUP_CODE, UNIT_PRICE,QUANTITY,DELIVER_TO_LOCATION_ID,TO_PERSON_ID,
165 SUGGESTED_BUYER_ID,to_char(NEED_BY_DATE,''DD-MON-YYYY HH24:MI:SS'') NEED_BY_DATE,JUSTIFICATION,NOTE_TO_AGENT,NOTE_TO_RECEIVER,CURRENCY_CODE,RATE_TYPE,to_char(RATE_DATE,''DD-MON-YYYY HH24:MI:SS'') RATE_DATE,
166 RATE,CURRENCY_UNIT_PRICE,SUGGESTED_VENDOR_NAME,SUGGESTED_VENDOR_LOCATION,SUGGESTED_VENDOR_CONTACT,SUGGESTED_VENDOR_PHONE,
167 SUGGESTED_VENDOR_PRODUCT_CODE,HAZARD_CLASS_ID,DESTINATION_TYPE_CODE,DESTINATION_ORGANIZATION_ID, DESTINATION_SUBINVENTORY,
168 VENDOR_ID,VENDOR_SITE_ID, VENDOR_CONTACT_ID,prl.USSGL_TRANSACTION_CODE USSGL_TRANSACTION_CODE, MANUFACTURER_NAME,
169 MANUFACTURER_PART_NUMBER, REQUESTER_EMAIL,REQUESTER_FAX,REQUESTER_PHONE, UNSPSC_CODE, SUPPLIER_DUNS,AMOUNT,
170 CURRENCY_AMOUNT,JOB_LONG_DESCRIPTION,SUGGESTED_VENDOR_CONTACT_FAX,SUGGESTED_VENDOR_CONTACT_EMAIL,CANDIDATE_FIRST_NAME,
171 CANDIDATE_LAST_NAME,to_char(ASSIGNMENT_START_DATE,''DD-MON-YYYY HH24:MI:SS'') ASSIGNMENT_START_DATE,CONTRACT_TYPE,COST_CONSTRAINT,
172 to_char(CLM_PERIOD_PERF_START_DATE,''DD-MON-YYYY HH24:MI:SS'') CLM_PERIOD_PERF_START_DATE,to_char(CLM_PERIOD_PERF_END_DATE,''DD-MON-YYYY HH24:MI:SS'') CLM_PERIOD_PERF_END_DATE,
173 nvl(CLM_OPTION_EXERCISED,''N'') CLM_OPTION_EXERCISED, CLM_OPTION_FROM_DATE, CLM_OPTION_TO_DATE, FUND_SOURCE_NOT_KNOWN,CLM_OPTION_INDICATOR , CLM_BASE_LINE_NUM , CLM_MIPR_OBLIGATION_TYPE
174 FROM po_requisition_lines_all prl,
175 po_requisition_headers_all prh
176 WHERE prh.conformed_header_id='||p_confirmed_id||
177 'AND prh.requisition_header_id=prl.requisition_header_id
178 AND prh.revision_num='||p_revision_num||
179 'ORDER BY LINE_NUM';
180
181 p_level:= 'LINES';
182
183 ELSIF p_table_name = 'PO_REQ_DISTRIBUTIONS_ALL' THEN
184
185 /* Added NVL around RECOVERABLE_TAX, NONRECOVERABLE_TAX, RECOVERY_RATE
186 to disregard the difference between NULL and 0.
187 */
188
189 /* <<CLM Partial Funding Changes>>
190 Added following partial funding attributes:
191 PARTIAL_FUNDED_FLAG, FUNDED_VALUE, QUANTITY_FUNDED, AMOUNT_FUNDED
192 */
193 sql_stmt1:='SELECT DISTRIBUTION_ID,
194 prl.LINE_NUM LINE_NUM,
195 prl.LINE_NUM_DISPLAY LINE_NUM_DISPLAY,
196 DISTRIBUTION_NUM,
197 nvl(prl.CANCEL_FLAG,''N'') LINE_CANCEL_FLAG,
198 prl.ITEM_ID LINE_ITEM_ID,
199 CODE_COMBINATION_ID,
200 REQ_LINE_QUANTITY,
201 to_char(GL_ENCUMBERED_DATE,''DD-MON-YYYY HH24:MI:SS'') GL_ENCUMBERED_DATE,
202 prd.USSGL_TRANSACTION_CODE USSGL_TRANSACTION_CODE,
203 PROJECT_ID,
204 TASK_ID,
205 EXPENDITURE_TYPE,
206 EXPENDITURE_ORGANIZATION_ID,
207 to_char(EXPENDITURE_ITEM_DATE,''DD-MON-YYYY HH24:MI:SS'') EXPENDITURE_ITEM_DATE,
208 nvl(RECOVERABLE_TAX,0) RECOVERABLE_TAX,
209 nvl(NONRECOVERABLE_TAX,0) NONRECOVERABLE_TAX,
210 nvl(RECOVERY_RATE,0) RECOVERY_RATE,
211 REQ_LINE_AMOUNT,
212 REQ_LINE_CURRENCY_AMOUNT,
213 PARTIAL_FUNDED_FLAG,
214 FUNDED_VALUE,
215 QUANTITY_FUNDED,
216 AMOUNT_FUNDED,
217 ACRN
218 FROM po_req_distributions_all prd,
219 po_requisition_lines_all prl,
220 po_requisition_headers_all prh
221 WHERE prh.conformed_header_id='||p_confirmed_id||
222 'AND prh.requisition_header_id=prl.requisition_header_id
223 AND prl.requisition_line_id=nvl(prd.info_line_id,prd.requisition_line_id)
224 AND revision_num='||(p_revision_num -1)||
225 'ORDER BY nvl(prd.info_line_id,prd.requisition_line_id),DISTRIBUTION_NUM' ;
226
227 /* Added NVL around RECOVERABLE_TAX, NONRECOVERABLE_TAX, RECOVERY_RATE
228 to disregard the difference between NULL and 0.
229 */
230
231 /* <<CLM Partial Funding Changes>>
232 Added following partial funding attributes:
233 PARTIAL_FUNDED_FLAG, FUNDED_VALUE, QUANTITY_FUNDED, AMOUNT_FUNDED
234 */
235 sql_stmt2:='SELECT DISTRIBUTION_ID,
236 prl.LINE_NUM LINE_NUM,
237 prl.LINE_NUM_DISPLAY LINE_NUM_DISPLAY,
238 DISTRIBUTION_NUM,
239 nvl(prl.CANCEL_FLAG,''N'') LINE_CANCEL_FLAG,
240 prl.ITEM_ID LINE_ITEM_ID,
241 CODE_COMBINATION_ID,
242 REQ_LINE_QUANTITY,
243 to_char(GL_ENCUMBERED_DATE,''DD-MON-YYYY HH24:MI:SS'') GL_ENCUMBERED_DATE,
244 prd.USSGL_TRANSACTION_CODE USSGL_TRANSACTION_CODE,
245 PROJECT_ID,
246 TASK_ID,
247 EXPENDITURE_TYPE,
248 EXPENDITURE_ORGANIZATION_ID,
249 to_char(EXPENDITURE_ITEM_DATE,''DD-MON-YYYY HH24:MI:SS'') EXPENDITURE_ITEM_DATE,
250 nvl(RECOVERABLE_TAX,0) RECOVERABLE_TAX,
251 nvl(NONRECOVERABLE_TAX,0) NONRECOVERABLE_TAX,
252 nvl(RECOVERY_RATE,0) RECOVERY_RATE,
253 REQ_LINE_AMOUNT,
254 REQ_LINE_CURRENCY_AMOUNT,
255 PARTIAL_FUNDED_FLAG,
256 FUNDED_VALUE,
257 QUANTITY_FUNDED,
258 AMOUNT_FUNDED,
259 ACRN
260 FROM po_req_distributions_all prd,
261 po_requisition_lines_all prl,
262 po_requisition_headers_all prh
263 WHERE prh.conformed_header_id='||p_confirmed_id||
264 'AND prh.requisition_header_id=prl.requisition_header_id
265 AND prl.requisition_line_id=nvl(prd.info_line_id,prd.requisition_line_id)
266 AND revision_num='||p_revision_num||
267 'ORDER BY nvl(prd.info_line_id,prd.requisition_line_id),DISTRIBUTION_NUM';
268
269 p_level:= 'DIST';
270
271 ELSIF p_table_name = 'PO_REQ_HEADERS_UDA_ADDR' THEN
272
273 SELECT u.attribute_group_id, ag.attr_group_name
274 INTO g_address_attr_group_id, g_address_group_name
275 FROM po_uda_ag_template_usages u,
276 po_requisition_headers_all h,
277 ego_attr_groups_v ag
278 WHERE h.uda_template_id = u.template_id
279 AND h.requisition_header_id = p_confirmed_id
280 AND ag.attr_group_type = 'PO_REQ_HEADER_EXT_ATTRS'
281 AND ag.attr_group_id = u.attribute_group_id
282 AND u.attribute_category = 'ADDRESS' ;
283
284
285 FOR rec IN col_list(g_address_group_name) LOOP
286 l_select_cols := l_select_cols ||' , '|| rec.database_column;
287 END LOOP;
288
289 sql_stmt1:= 'SELECT '|| l_select_cols ||'
290 FROM po_req_headers_ext_b
291 WHERE requisition_header_id = (SELECT prh.requisition_header_id
292 FROM po_requisition_headers_all prh
293 WHERE prh.conformed_header_id= '||p_confirmed_id||
294 'AND prh.revision_num='||(p_revision_num-1)||')
295 and attr_group_id = '|| g_address_attr_group_id ||'
296 ORDER BY C_EXT_ATTR39';
297
298
299 sql_stmt2:= 'SELECT '|| l_select_cols ||'
300 FROM po_req_headers_ext_b
301 WHERE requisition_header_id = (SELECT prh.requisition_header_id
302 FROM po_requisition_headers_all prh
303 WHERE prh.conformed_header_id= '||p_confirmed_id||
304 'AND prh.revision_num='||(p_revision_num)||')
305 and attr_group_id = '|| g_address_attr_group_id ||'
306 ORDER BY C_EXT_ATTR39';
307
308
309 p_level:= 'UDA_HEADER_ADDR';
310
311 ELSIF p_table_name = 'PO_REQ_HEADERS_UDA' THEN
312
313 SELECT database_view_name,
314 template_id
315 INTO x_database_view_name,
316 x_template_id
317 FROM po_uda_ag_templates
318 WHERE template_id = (SELECT prh.uda_template_id
319 FROM po_requisition_headers_all prh
320 WHERE prh.conformed_header_id= p_confirmed_id
321 AND prh.revision_num=p_revision_num);
322
323 -- bug 14248325 getting the org_id so that we can use the org_id as a context while deriving attribute_group_name for DOCUMENT_NUMBERING
324
325 select prh.org_id into g_org_id from po_requisition_headers_all prh WHERE prh.conformed_header_id= p_confirmed_id
326 AND prh.revision_num=p_revision_num ;
327
328 sql_stmt1:='SELECT temp.*
329 FROM '||x_database_view_name||' temp
330 WHERE temp.requisition_header_id IN (SELECT prh.requisition_header_id
331 FROM po_requisition_headers_all prh
332 WHERE prh.conformed_header_id= '||p_confirmed_id||
333 'AND prh.revision_num='||(p_revision_num-1)||')';
334
335 sql_stmt2:='SELECT temp.*
336 FROM '||x_database_view_name||' temp
337 WHERE temp.requisition_header_id IN (SELECT prh.requisition_header_id
338 FROM po_requisition_headers_all prh
339 WHERE prh.conformed_header_id= '||p_confirmed_id||
340 'AND prh.revision_num='||p_revision_num||')';
341
342 p_level:= 'UDA_HEADER';
343 ELSIF p_table_name = 'PO_REQ_LINES_UDA' THEN
344
345 SELECT database_view_name
346 INTO x_database_view_name
347 FROM po_uda_ag_templates
348 WHERE template_id = (SELECT Max(prl.uda_template_id)
349 FROM po_requisition_lines_all prl,
350 po_requisition_headers_all prh
351 WHERE prh.conformed_header_id= p_confirmed_id
352 AND prh.revision_num=p_revision_num
353 AND prh.requisition_header_id=prl.requisition_header_id);
354
355
356 sql_stmt1:='SELECT prla.line_num, prla.LINE_NUM_DISPLAY,
357 temp.*
358 FROM '||x_database_view_name||' temp,
359 po_requisition_lines_all prla
360 WHERE temp.requisition_line_id IN (SELECT prl.requisition_line_id
361 FROM po_requisition_lines_all prl,
362 po_requisition_headers_all prh
363 WHERE prh.conformed_header_id= '||p_confirmed_id||
364 'AND prh.revision_num='||(p_revision_num-1)||
365 'AND prh.requisition_header_id=prl.requisition_header_id)
366 AND prla.requisition_line_id = temp.requisition_line_id';
367
368 sql_stmt2:='SELECT prla.line_num, prla.LINE_NUM_DISPLAY,
369 temp.*
370 FROM '||x_database_view_name||' temp,
371 po_requisition_lines_all prla
372 WHERE temp.requisition_line_id IN (SELECT prl.requisition_line_id
373 FROM po_requisition_lines_all prl,
374 po_requisition_headers_all prh
375 WHERE prh.conformed_header_id= '||p_confirmed_id||
376 'AND prh.revision_num='||p_revision_num||
377 'AND prh.requisition_header_id=prl.requisition_header_id)
378 AND prla.requisition_line_id = temp.requisition_line_id';
379
380 p_level:= 'UDA_LINES';
381 END IF;
382
383 v_progress:='001';
384 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
385 l_log_msg := v_progress||' : After creating queries';
386 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
387 END IF;
388
389 -- Comparing the data between two revisions
390 compare(sql_stmt1, sql_stmt2, p_level, p_revision_num, amend_num);
391
392 v_progress:='006';
393 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
394 l_log_msg := v_progress||' : After comparing two revisions';
395 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
396 END IF;
397
398
399 EXCEPTION
400 WHEN others THEN
401
402 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
403 l_log_msg := v_progress||' : Exception : '|| SQLERRM;
404 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
405 END IF;
406 RAISE;
407
408 END compare_table;
409
410
411
412
413
414 /*********************************************************************
415 * NAME
416 * compare
417 *
418 *
419 * PURPOSE
420 * Compares two different records/rows and populates
421 * the temp table with field altered, old value and new value.
422 *
423 * ARGUMENTS
424 * sql_stmt1 IN Sql statement to fetch the first record
425 * sql_stmt2 IN Sql statement to fetch the second record
426 * p_level IN
427 * amend_num IN OUT
428 *
429 * NOTES
430 *
431 *
432 * HISTORY
433 * 23-09-09 Bisdas Created
434 *********************************************************************/
435
436
437
438 PROCEDURE compare(sql_stmt1 VARCHAR2,
439 sql_stmt2 VARCHAR2,
440 p_level VARCHAR2,
441 p_revision_num NUMBER,
442 amend_num IN OUT NOCOPY varchar2)
443 AS
444
445 x_xml1 CLOB;
446 x_xml2 CLOB;
447
448 -- XML parsing --
449 p xmlparser.parser;
450 doc1 xmldom.domdocument;
451 doc2 xmldom.domdocument;
452
453 root xmldom.domelement;
454 n_list_row1 xmldom.domnodelist;
455 n_list_row2 xmldom.domnodelist;
456 n_list1 xmldom.domnodelist;
457 n_list2 xmldom.domnodelist;
458 node1 xmldom.domnode;
459 node2 xmldom.domnode;
460 l_id VARCHAR2(50);
461 l_name VARCHAR2(50);
462 -- XML parsing --
463
464 node_val1 VARCHAR2(1000);
465 node_val2 VARCHAR2(1000);
466 node_name VARCHAR2(1000);
467
468
469 line_num VARCHAR2(100);
470 old_line_num VARCHAR2(100);
471 dist_num VARCHAR2(100);
472 item_id number;
473 line_num_disp VARCHAR2(100);
474 old_line_num_disp VARCHAR2(100);
475
476 --Debugging purpose
477 v_progress VARCHAR2(3);
478 l_procedure_name VARCHAR2(100) := 'compare';
479 l_log_msg VARCHAR2(2000);
480
481 i1 NUMBER := 0;
482 i2 NUMBER := 0;
483
484 -- UDA related changes
485 x_doc_number_attr_group_name VARCHAR2(100);
486 x_addr_field_altered VARCHAR2(100);
487 x_address_type VARCHAR2(100);
488 x_attr_display_name VARCHAR2(500);
489 x_lookup_code VARCHAR2(100);
490 x_database_column VARCHAR2(100);
491
492 BEGIN
493
494
495 v_progress:='000';
496
497 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
498 l_log_msg := 'Invoked '||l_procedure_name;
499 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
500 END IF;
501
502 -- UDA related changes
503
504 BEGIN
505
506 IF p_level = 'UDA_HEADER' THEN
507 SELECT ags.ATTR_GROUP_NAME
508 INTO x_doc_number_attr_group_name
509 FROM PO_UDA_AG_TEMPLATE_USAGES usages, ego_attr_groups_v ags
510 WHERE usages.template_id = x_template_id
511 AND usages.ATTRIBUTE1='Base Document'
512 AND usages.ATTRIBUTE2='NA'
513 -- bug 14248325 Attribute3 needs to be added here as there may be records that have org_id as well as DEFAULT values in Attribute3 column
514 AND usages.ATTRIBUTE3=To_Char(g_org_id)
515 AND usages.ATTRIBUTE_CATEGORY='DOCUMENT_NUMBERING'
516 AND usages.attribute_group_id = ags.attr_group_id;
517
518 END IF;
519
520 EXCEPTION
521
522 WHEN No_Data_Found THEN
523
524 --If there is no attribute group name fetched with the org_id from po_requisition_headers_all then go for DEFAULT
525
526 SELECT ags.ATTR_GROUP_NAME
527 INTO x_doc_number_attr_group_name
528 FROM PO_UDA_AG_TEMPLATE_USAGES usages, ego_attr_groups_v ags
529 WHERE usages.template_id = x_template_id
530 AND usages.ATTRIBUTE1='Base Document'
531 AND usages.ATTRIBUTE2='NA'
532 AND usages.ATTRIBUTE3='DEFAULT'
533 AND usages.ATTRIBUTE_CATEGORY='DOCUMENT_NUMBERING'
534 AND usages.attribute_group_id = ags.attr_group_id;
535
536 END;
537
538 -- Getting the XMLs based on the dynamic queries
539
540 x_xml1:= create_xml(sql_stmt1);
541 x_xml2:= create_xml(sql_stmt2);
542
543 v_progress:='002';
544 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
545 l_log_msg := v_progress||' : After creating XMLs';
546 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
547 END IF;
548
549
550 IF (x_xml2 IS NOT NULL) THEN
551
552 -- Parse XMLs to find out the differences
553
554 IF(x_xml1 IS NOT NULL) THEN
555
556 p := xmlparser.newparser();
557
558 xmlparser.parseclob(p, x_xml1);
559
560 doc1 := xmlparser.getdocument(p);
561
562 xmlparser.freeparser(p);
563
564 END IF;
565
566 v_progress:='003';
567
568 p := xmlparser.newparser();
569
570 xmlparser.parseclob(p, x_xml2);
571
572 doc2 := xmlparser.getdocument(p);
573
574 xmlparser.freeparser(p);
575
576 v_progress:='004';
577
578 IF(x_xml1 IS NOT NULL) THEN
579 n_list_row1 := xmldom.getChildNodes(xmldom.item(xmldom.getElementsByTagName(doc1,'ROWSET'),0));
580 END IF;
581 n_list_row2 := xmldom.getChildNodes(xmldom.item(xmldom.getElementsByTagName(doc2,'ROWSET'),0));
582
583 --FOR i IN 0 .. xmldom.getLength(n_list_row2)-1 LOOP
584
585 v_progress:='005';
586
587 LOOP
588 IF(x_xml1 IS NOT NULL) THEN
589 node1:= xmldom.item(n_list_row1,i1);
590 END IF;
591 node2:= xmldom.item(n_list_row2,i2);
592
593 IF xmldom.isNULL(node1) THEN
594 n_list2:=xmldom.getChildNodes(node2);
595
596 FOR j IN 0 .. xmldom.getLength(n_list2)-1 LOOP
597 node2 := xmldom.item(n_list2,j);
598
599 IF xmldom.getNodeName(node2) = 'LINE_NUM' THEN
600 line_num := xmldom.getNodeValue(xmldom.item(xmldom.getChildNodes(node2), 0));
601 END IF;
602
603 IF xmldom.getNodeName(node2) = 'LINE_NUM_DISPLAY' THEN
604 line_num_disp := xmldom.getNodeValue(xmldom.item(xmldom.getChildNodes(node2), 0));
605 END IF;
606
607 IF xmldom.getNodeName(node2) = 'DISTRIBUTION_NUM' THEN
608 dist_num := xmldom.getNodeValue(xmldom.item(xmldom.getChildNodes(node2), 0));
609 END IF;
610
611 IF xmldom.getNodeName(node2) in ('ITEM_ID','LINE_ITEM_ID') THEN
612 item_id := xmldom.getNodeValue(xmldom.item(xmldom.getChildNodes(node2), 0));
613 END IF;
614
615
616
617 END LOOP;
618
619 IF p_level = 'LINES' THEN
620
621
622 po_num_tab(rec_index) := amend_num;
623 revision_num_tab(rec_index) := p_revision_num;
624 line_num_tab(rec_index) := line_num;
625 distribution_num_tab(rec_index) := NULL;
626 level_altered_tab(rec_index) := p_level;
627 item_id_tab(rec_index) := item_id;
628 field_altered_tab(rec_index) := 'New';
629 changes_from_tab(rec_index) := NULL;
630 changes_to_tab(rec_index) := NULL;
631 line_num_disp_tab(rec_index) := line_num_disp;
632
633 rec_index := rec_index+1;
634
635 ELSIF p_level = 'DIST' THEN
636
637 po_num_tab(rec_index) := amend_num;
638 revision_num_tab(rec_index) := p_revision_num;
639 line_num_tab(rec_index) := line_num;
640 distribution_num_tab(rec_index) := dist_num;
641 level_altered_tab(rec_index) := p_level;
642 item_id_tab(rec_index) := item_id;
643 field_altered_tab(rec_index) := 'New';
644 changes_from_tab(rec_index) := NULL;
645 changes_to_tab(rec_index) := NULL;
646 line_num_disp_tab(rec_index) := line_num_disp;
647
648 rec_index := rec_index+1;
649
650 END IF;
651
652 ELSE
653
654 n_list1:=xmldom.getChildNodes(node1);
655 n_list2:=xmldom.getChildNodes(node2);
656
657 FOR j IN 0 .. xmldom.getLength(n_list1)-1 LOOP
658
659
660 node1 := xmldom.item(n_list1,j);
661 node2 := xmldom.item(n_list2,j);
662
663 node_val1 := xmldom.getNodeValue(xmldom.item(xmldom.getChildNodes(node1), 0));
664 node_val2 := xmldom.getNodeValue(xmldom.item(xmldom.getChildNodes(node2), 0));
665
666
667 IF xmldom.getNodeName(node2) = 'SEGMENT1' AND amend_num IS NULL THEN
668 amend_num := node_val2;
669 END IF;
670
671
672 IF xmldom.getNodeName(node2) = 'LINE_NUM' THEN
673 line_num := node_val2;
674 old_line_num := node_val1;
675 END IF;
676
677 IF xmldom.getNodeName(node2) = 'LINE_NUM_DISPLAY' THEN
678 line_num_disp := node_val2;
679 END IF;
680
681 IF xmldom.getNodeName(node2) = 'DISTRIBUTION_NUM' THEN
682 dist_num := node_val2;
683 END IF;
684
685 IF xmldom.getNodeName(node2) in ('ITEM_ID','LINE_ITEM_ID') THEN
686 item_id := node_val2;
687 END IF;
688
689
690 IF line_num <> old_line_num AND p_level = 'DIST' AND xmldom.getNodeName(node1) NOT IN ('DISTRIBUTION_ID','LINE_NUM','LINE_NUM_DISPLAY') THEN
691 i1:=i1-1;
692
693 po_num_tab(rec_index) := amend_num;
694 revision_num_tab(rec_index) := p_revision_num;
695 line_num_tab(rec_index) := line_num;
696 distribution_num_tab(rec_index) := dist_num;
697 level_altered_tab(rec_index) := p_level;
698 item_id_tab(rec_index) := item_id;
699 field_altered_tab(rec_index) := 'New';
700 changes_from_tab(rec_index) := NULL;
701 changes_to_tab(rec_index) := NULL;
702 line_num_disp_tab(rec_index) := line_num_disp;
703
704 rec_index := rec_index+1;
705
706 EXIT;
707 END IF;
708
709
710 IF xmldom.getNodeName(node1) in ('CANCEL_FLAG','LINE_CANCEL_FLAG') AND node_val1 <> node_val2 THEN
711
712 IF p_level = 'HEADER' THEN
713
714 po_num_tab(rec_index) := amend_num;
715 revision_num_tab(rec_index) := p_revision_num;
716 line_num_tab(rec_index) := NULL;
717 distribution_num_tab(rec_index) := NULL;
718 level_altered_tab(rec_index) := p_level;
719 item_id_tab(rec_index) := item_id;
720 field_altered_tab(rec_index) := 'Canceled';
721 changes_from_tab(rec_index) := NULL;
722 changes_to_tab(rec_index) := NULL;
723 line_num_disp_tab(rec_index) := NULL;
724
725 rec_index := rec_index+1;
726
727 ELSIF p_level = 'LINES' THEN
728 po_num_tab(rec_index) := amend_num;
729 revision_num_tab(rec_index) := p_revision_num;
730 line_num_tab(rec_index) := line_num;
731 distribution_num_tab(rec_index) := NULL;
732 level_altered_tab(rec_index) := p_level;
733 item_id_tab(rec_index) := item_id;
734 field_altered_tab(rec_index) := 'Canceled';
735 changes_from_tab(rec_index) := NULL;
736 changes_to_tab(rec_index) := NULL;
737 line_num_disp_tab(rec_index) := line_num_disp;
738
739 rec_index := rec_index+1;
740
741 ELSIF p_level = 'DIST' THEN
742 po_num_tab(rec_index) := amend_num;
743 revision_num_tab(rec_index) := p_revision_num;
744 line_num_tab(rec_index) := line_num;
745 distribution_num_tab(rec_index) := dist_num;
746 level_altered_tab(rec_index) := p_level;
747 item_id_tab(rec_index) := item_id;
748 field_altered_tab(rec_index) := 'Canceled';
749 changes_from_tab(rec_index) := NULL;
750 changes_to_tab(rec_index) := NULL;
751 line_num_disp_tab(rec_index) := line_num_disp;
752
753 rec_index := rec_index+1;
754
755 END IF;
756
757 EXIT; -- Exit from the loop if Canceled
758
759 END IF;
760
761 IF xmldom.getNodeName(node1) = 'CLOSED_CODE' AND node_val1 <> node_val2 THEN
762
763 IF p_level = 'HEADER' THEN
764
765 po_num_tab(rec_index) := amend_num;
766 revision_num_tab(rec_index) := p_revision_num;
767 line_num_tab(rec_index) := NULL;
768 distribution_num_tab(rec_index) := NULL;
769 level_altered_tab(rec_index) := p_level;
770 item_id_tab(rec_index) := item_id;
771 field_altered_tab(rec_index) := 'Closed';
772 changes_from_tab(rec_index) := NULL;
773 changes_to_tab(rec_index) := NULL;
774 line_num_disp_tab(rec_index) := NULL;
775
776 rec_index := rec_index+1;
777
778
779 ELSIF p_level = 'LINES' THEN
780
781 po_num_tab(rec_index) := amend_num;
782 revision_num_tab(rec_index) := p_revision_num;
783 line_num_tab(rec_index) := line_num;
784 distribution_num_tab(rec_index) := NULL;
785 level_altered_tab(rec_index) := p_level;
786 item_id_tab(rec_index) := item_id;
787 field_altered_tab(rec_index) := 'Closed';
788 changes_from_tab(rec_index) := NULL;
789 changes_to_tab(rec_index) := NULL;
790 line_num_disp_tab(rec_index) := line_num_disp;
791
792 rec_index := rec_index+1;
793
794
795 END IF;
796
797 EXIT; -- Exit from the loop if Closed
798
799 END IF;
800
801 IF p_level = 'UDA_HEADER_ADDR' AND xmldom.getNodeName(node1) = 'C_EXT_ATTR39' THEN
802
803 x_lookup_code := node_val1;
804
805 BEGIN
806
807 SELECT displayed_field
808 INTO x_address_type
809 FROM po_lookup_codes
810 WHERE lookup_code = x_lookup_code
811 AND lookup_type='PR_UDA_ADDRESS_TYPES';
812
813 EXCEPTION
814 WHEN No_Data_Found THEN
815 x_address_type := '';
816 END;
817 END IF;
818
819
820 IF Nvl(node_val1,-999) <> Nvl(node_val2,-999)
821 AND xmldom.getNodeName(node1) NOT IN ('REQUISITION_HEADER_ID',
822 'SEGMENT1',
823 'REVISION_NUM',
824 'REQUISITION_LINE_ID',
825 'DISTRIBUTION_ID',
826 'LINE_ITEM_ID',
827 'LINE_NUM',
828 'LINE_NUM_DISPLAY',
829 'DISTRIBUTION_NUM') THEN
830
831 IF p_level IN ('HEADER','UDA_HEADER','UDA_HEADER_ADDR') THEN
832
833 -- UDA Doc Numbering attribute group
834 IF Nvl(instr(xmldom.getNodeName(node1), x_doc_number_attr_group_name),0) = 0 THEN
835
836 po_num_tab(rec_index) := amend_num;
837 revision_num_tab(rec_index) := p_revision_num;
838 line_num_tab(rec_index) := NULL;
839 distribution_num_tab(rec_index) := NULL;
840 level_altered_tab(rec_index) := 'HEADER';
841 item_id_tab(rec_index) := item_id;
842 line_num_disp_tab(rec_index) := NULL;
843 IF p_level = 'UDA_HEADER' THEN
844 field_altered_tab(rec_index) := getUDAAttributeName(xmldom.getNodeName(node1));
845 changes_from_tab(rec_index) := getUDAAttributeValue(node_val1, xmldom.getNodeName(node1), p_level, amend_num, NULL);
846 changes_to_tab(rec_index) := getUDAAttributeValue(node_val2, xmldom.getNodeName(node1), p_level, amend_num, NULL);
847 ELSIF p_level = 'UDA_HEADER_ADDR' THEN
848
849
850 BEGIN
851
852 x_database_column := xmldom.getNodeName(node1);
853
854 SELECT attr_display_name
855 INTO x_attr_display_name
856 FROM ego_attrs_v
857 WHERE attr_group_type = 'PO_REQ_HEADER_EXT_ATTRS'
858 AND attr_group_name = g_address_group_name
859 AND database_column = x_database_column;
860
861 EXCEPTION
862 WHEN No_Data_Found THEN
863 x_attr_display_name := '';
864 WHEN OTHERS THEN
865 x_attr_display_name := '';
866 END;
867
868 x_addr_field_altered := x_address_type || ' ' || x_attr_display_name;
869
870 field_altered_tab(rec_index) := x_addr_field_altered;
871 changes_from_tab(rec_index) := getUDAAttributeValue(node_val1, xmldom.getNodeName(node1), p_level, amend_num, NULL);
872 changes_to_tab(rec_index) := getUDAAttributeValue(node_val2, xmldom.getNodeName(node1), p_level, amend_num, NULL);
873 ELSE
874 field_altered_tab(rec_index) := fnd_message.get_String('ICX','ICX_'||xmldom.getNodeName(node1));
875 changes_from_tab(rec_index) := map_id_to_num(node_val1,xmldom.getNodeName(node1));
876 changes_to_tab(rec_index) := map_id_to_num(node_val2,xmldom.getNodeName(node1));
877 END IF;
878
879 rec_index := rec_index+1;
880
881 END IF; -- UDA Doc Numbering attribute group
882
883 ELSIF p_level IN ('LINES','UDA_LINES') THEN
884
885 po_num_tab(rec_index) := amend_num;
886 revision_num_tab(rec_index) := p_revision_num;
887 line_num_tab(rec_index) := line_num;
888 distribution_num_tab(rec_index) := NULL;
889 level_altered_tab(rec_index) := 'LINES';
890 item_id_tab(rec_index) := item_id;
891 line_num_disp_tab(rec_index) := line_num_disp;
892 IF p_level = 'UDA_LINES' THEN
893 field_altered_tab(rec_index) := getUDAAttributeName(xmldom.getNodeName(node1));
894 changes_from_tab(rec_index) := getUDAAttributeValue(node_val1, xmldom.getNodeName(node1), p_level, amend_num, line_num);
895 changes_to_tab(rec_index) := getUDAAttributeValue(node_val2, xmldom.getNodeName(node1), p_level, amend_num, line_num);
896 ELSE
897 field_altered_tab(rec_index) := fnd_message.get_String('ICX','ICX_'||xmldom.getNodeName(node1));
898 changes_from_tab(rec_index) := map_id_to_num(node_val1,xmldom.getNodeName(node1));
899 changes_to_tab(rec_index) := map_id_to_num(node_val2,xmldom.getNodeName(node1));
900 END IF;
901
902 rec_index := rec_index+1;
903
904 ELSIF p_level = 'DIST' THEN
905
906 po_num_tab(rec_index) := amend_num;
907 revision_num_tab(rec_index) := p_revision_num;
908 line_num_tab(rec_index) := line_num;
909 distribution_num_tab(rec_index) := dist_num;
910 level_altered_tab(rec_index) := p_level;
911 item_id_tab(rec_index) := item_id;
912 line_num_disp_tab(rec_index) := line_num_disp;
913 field_altered_tab(rec_index) := fnd_message.get_String('ICX','ICX_'||xmldom.getNodeName(node1));
914 changes_from_tab(rec_index) := map_id_to_num(node_val1,xmldom.getNodeName(node1));
915 changes_to_tab(rec_index) := map_id_to_num(node_val2,xmldom.getNodeName(node1));
916
917 rec_index := rec_index+1;
918
919 END IF;
920 END IF;
921
922 END LOOP;
923
924 END IF;
925
926 -- IF old_line_num
927
928 i2 := i2+1;
929 i1:=i1+1;
930
931 EXIT WHEN i2=xmldom.getLength(n_list_row2);
932
933 END LOOP;
934 END IF; -- If x_xml1 is NOT NULL
935
936 v_progress:='006';
937 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
938 l_log_msg := v_progress||' : After comparing xmls';
939 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
940 END IF;
941
942
943 EXCEPTION
944 WHEN others THEN
945
946 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
947 l_log_msg := v_progress||' : Exception : '|| SQLERRM;
948 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
949 END IF;
950 RAISE;
951
952 END compare;
953
954
955
956
957
958 /*********************************************************************
959 * NAME
960 * change_history
961 *
962 * PURPOSE
963 * This is the wrapper for compare_req procedure to find out the changes in all the 3 level
964 * i.e; Header, Lines and Distributions.
965 *
966 * ARGUMENTS
967 * p_confirmed_id
968 * p_revision_num
969 * p_sequence_num
970 *
971 * NOTES
972 *
973 *
974 * HISTORY
975 * 13-07-09 Bisdas Created
976 ********************************************************************/
977
978
979
980 PROCEDURE change_history(p_confirmed_id NUMBER, p_revision_num NUMBER, p_sequence_num NUMBER)
981 AS
982
983
984 c_line_num NUMBER;
985 c_dist_num NUMBER;
986 amend_num VARCHAR2(100);
987
988 v_progress VARCHAR2(3);
989 l_procedure_name VARCHAR2(100) := 'change_history';
990 l_log_msg VARCHAR2(2000);
991
992 BEGIN
993 v_progress := '000';
994 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
995 l_log_msg := v_progress||': Inside procedure '||l_procedure_name;
996 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
997 l_log_msg := 'p_confirmed_id : '||p_confirmed_id||', p_revision_num : '||p_revision_num||', p_sequence_num : '||p_sequence_num;
998 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
999 END IF;
1000
1001 v_progress := '001';
1002 compare_table('PO_REQUISITION_HEADERS_ALL',p_revision_num,p_confirmed_id,amend_num);
1003 v_progress := '002';
1004 compare_table('PO_REQUISITION_LINES_ALL',p_revision_num,p_confirmed_id,amend_num);
1005 v_progress := '003';
1006 compare_table('PO_REQ_DISTRIBUTIONS_ALL',p_revision_num,p_confirmed_id,amend_num);
1007
1008 -- UDA related Changes
1009 -- Header
1010 v_progress := '004';
1011 compare_table('PO_REQ_HEADERS_UDA_ADDR',p_revision_num,p_confirmed_id,amend_num);
1012 compare_table('PO_REQ_HEADERS_UDA',p_revision_num,p_confirmed_id,amend_num);
1013
1014 -- Lines
1015 v_progress := '005';
1016 compare_table('PO_REQ_LINES_UDA',p_revision_num,p_confirmed_id,amend_num);
1017 -- UDA related Changes
1018
1019 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1020 l_log_msg := v_progress||': After comparing header, lines and distributions';
1021 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1022 END IF;
1023
1024 v_progress := '006';
1025
1026 insert_changes(p_sequence_num,p_confirmed_id);
1027
1028 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1029 l_log_msg := v_progress||': After inserting into temp tabl';
1030 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1031 END IF;
1032
1033 v_progress := '007';
1034 verify_no_differences(p_sequence_num,p_revision_num,amend_num);
1035
1036 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1037 l_log_msg := v_progress||': After verifying if there is no changes';
1038 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1039 END IF;
1040
1041
1042 EXCEPTION
1043 WHEN OTHERS THEN
1044 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1045 l_log_msg := v_progress||': Exception at procedure change_history';
1046 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1047 END IF;
1048 RAISE;
1049 END change_history;
1050
1051
1052
1053
1054
1055 FUNCTION create_xml(p_sql_stmt VARCHAR2) RETURN CLOB
1056 IS
1057 queryCtx dbms_xmlgen.ctxType;
1058 result CLOB;
1059 BEGIN
1060 -- set up the query context
1061 queryCtx := dbms_xmlgen.newContext(p_sql_stmt);
1062
1063 dbms_xmlgen.setRowTag(
1064 queryCtx
1065 , 'ROW'
1066 );
1067 dbms_xmlgen.setRowSetTag(
1068 queryCtx
1069 , 'ROWSET'
1070 );
1071
1072 dbms_xmlgen.setConvertSpecialChars(queryCtx,TRUE);
1073 dbms_xmlgen.setNULLHandling(queryCtx,2);
1074
1075 result := dbms_xmlgen.getXml(queryCtx);
1076 dbms_xmlgen.closeContext(queryCtx);
1077 RETURN result;
1078
1079 EXCEPTION
1080 WHEN OTHERS THEN
1081 RETURN NULL;
1082 END create_xml;
1083
1084
1085
1086
1087 /*********************************************************************
1088 * NAME
1089 * compare_req
1090 *
1091 * PURPOSE
1092 * Compare the PR Amendment with the previous or the original
1093 * revision---including all lines, shipments, and distributions.
1094 *
1095 * ARGUMENTS
1096 * p_confirmed_id
1097 * p_revision_num
1098 * p_comparison_flag Indicator to compare the PO with the previous
1099 * or original revision
1100 * p_sequence_num Sequence number to identify the comparison
1101 * results for a specific record in
1102 * ICX_PO_REVISIONS_TEMP table.
1103 *
1104 * NOTES
1105 *
1106 * HISTORY
1107 * 13-07-2009 bisdas Created
1108 ********************************************************************/
1109
1110 PROCEDURE compare_req(
1111 p_confirmed_id IN NUMBER,
1112 p_revision_num IN NUMBER,
1113 p_comparison_flag IN VARCHAR2,
1114 p_sequence_num OUT NOCOPY NUMBER
1115 ) AS
1116
1117 v_sequence_num NUMBER;
1118 v_revision_counter NUMBER := p_revision_num;
1119 v_comparison_flag VARCHAR2( 80 ) := p_comparison_flag;
1120 v_progress VARCHAR2(3);
1121 l_procedure_name VARCHAR2(100) := 'compare_req';
1122 l_log_msg VARCHAR2(2000);
1123
1124 retcount NUMBER;
1125 BEGIN
1126
1127 v_progress := '000';
1128
1129 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1130 l_log_msg := 'Inside procedure '||l_procedure_name;
1131 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1132 l_log_msg := 'p_confirmed_id: ' ||p_confirmed_id || ' p_revision_num: '||p_revision_num||' p_comparison_flag: '||p_comparison_flag;
1133 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1134 END IF;
1135
1136 rec_index := 1;
1137
1138 --p_sequence_num:=10001;
1139 v_progress := '001';
1140
1141 SELECT icx_po_history_details_s.nextval
1142 INTO p_sequence_num
1143 FROM DUAL;
1144
1145 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1146 l_log_msg := v_progress||' : Getting sequence number: '||p_sequence_num;
1147 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1148 END IF;
1149
1150
1151 v_sequence_num:=p_sequence_num;
1152
1153 IF v_comparison_flag = 'All' THEN
1154
1155 v_progress := '002';
1156 v_comparison_flag := 'Previous';
1157
1158 SELECT Max(revision_num)
1159 INTO v_revision_counter
1160 FROM po_requisition_headers_all
1161 WHERE conformed_header_id=p_confirmed_id;
1162
1163 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1164 l_log_msg := v_progress||' : Getting sequence number: '||p_sequence_num;
1165 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1166 END IF;
1167
1168
1169 END IF;
1170
1171 LOOP
1172 v_progress := '003';
1173
1174 change_history(
1175 p_confirmed_id,
1176 v_revision_counter,
1177 v_sequence_num
1178 );
1179
1180 v_progress := '004';
1181
1182 po_num_tab.delete(1,po_num_tab.Count);
1183 line_num_tab.delete(1,line_num_tab.Count);
1184 distribution_num_tab.delete(1,distribution_num_tab.Count);
1185 level_altered_tab.delete(1,level_altered_tab.Count);
1186 field_altered_tab.delete(1,field_altered_tab.Count);
1187 changes_from_tab.delete(1,changes_from_tab.Count);
1188 changes_to_tab.delete(1,changes_to_tab.Count);
1189 line_num_disp_tab.delete(1,line_num_disp_tab.Count);
1190
1191 rec_index := 1;
1192
1193
1194 v_progress := '005';
1195
1196
1197 v_revision_counter := v_revision_counter - 1;
1198 IF v_revision_counter < 1 OR p_comparison_flag <> 'All'
1199 THEN
1200 EXIT;
1201 END IF;
1202
1203 END LOOP;
1204
1205 v_progress := '006';
1206
1207 EXCEPTION
1208 WHEN others THEN
1209
1210 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1211 l_log_msg := v_progress||' : Exception : '|| SQLERRM;
1212 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1213 END IF;
1214 RAISE;
1215
1216 END compare_req;
1217
1218
1219
1220 /*********************************************************************
1221 * NAME
1222 * purge
1223 *
1224 * PURPOSE
1225 * Delete records from the temp table, ICX_PO_REVISIONS_TEMP, where
1226 * all the records for differences are stored.
1227 *
1228 * ARGUMENTS
1229 * sequenceNumber Sequence number to identify the comparison
1230 * results for a specific record in
1231 * ICX_PO_REVISIONS_TEMP table.
1232 *
1233 * NOTES
1234 *
1235 * HISTORY
1236 * 15 -07-2009 bisdas Created
1237 ********************************************************************/
1238
1239 PROCEDURE purge(sequenceNumber IN NUMBER)
1240 AS
1241 v_progress VARCHAR2(3);
1242
1243 BEGIN
1244
1245 v_progress := '000';
1246
1247
1248 DELETE FROM icx_po_revisions_temp
1249 WHERE line_seq = sequenceNumber;
1250
1251 v_progress := '001';
1252
1253 COMMIT;
1254
1255 v_progress := '002';
1256
1257 EXCEPTION
1258 WHEN others THEN
1259 PO_MESSAGE_S.SQL_ERROR(
1260 'PO_REQ_CHANGE_HISTORY.PURGE',
1261 v_progress,
1262 sqlcode );
1263 RAISE;
1264
1265 END purge;
1266
1267
1268 /*********************************************************************
1269 * NAME
1270 * insert_changes
1271 *
1272 * PURPOSE
1273 * Insert the comparison result into the temp table.
1274 *
1275 * ARGUMENTS
1276 * p_line_seq Sequence number to identify the comparison
1277 * results for a specific record.
1278 * p_confirmed_id Confirmed Id.
1279 *
1280 *
1281 * HISTORY
1282 * 13-07-2009 bisdas Created
1283 *
1284 ********************************************************************/
1285
1286 PROCEDURE insert_changes(p_line_seq NUMBER,p_confirmed_id NUMBER)
1287 AS
1288
1289 v_progress VARCHAR2(3);
1290 l_procedure_name VARCHAR2(100) := 'insert_changes';
1291 l_log_msg VARCHAR2(2000);
1292
1293 BEGIN
1294
1295 v_progress := '000';
1296 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1297 l_log_msg := v_progress||': Inside procedure '||l_procedure_name;
1298 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1299 l_log_msg := 'p_line_seq: ' ||p_line_seq || ' p_confirmed_id: '||p_confirmed_id;
1300 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1301 END IF;
1302
1303 FORALL i in po_num_tab.FIRST..po_num_tab.LAST
1304 INSERT INTO
1305 icx_po_revisions_temp(
1306 header_id,
1307 line_seq,
1308 creation_date,
1309 po_num,
1310 revision_num,
1311 line_num,
1312 distribution_num,
1313 level_altered,
1314 item_id,
1315 field_altered,
1316 changes_from,
1317 changes_to,
1318 line_num_display
1319 )
1320 VALUES
1321 (
1322 p_confirmed_id,
1323 p_line_seq,
1324 SYSDATE,
1325 po_num_tab(i),
1326 revision_num_tab(i),
1327 line_num_tab(i),
1328 distribution_num_tab(i),
1329 level_altered_tab(i),
1330 item_id_tab(i),
1331 field_altered_tab(i),
1332 changes_from_tab(i),
1333 changes_to_tab(i),
1334 line_num_disp_tab(i)
1335 );
1336
1337 v_progress := '001';
1338
1339 EXCEPTION
1340 WHEN others THEN
1341
1342 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1343 l_log_msg := v_progress||' : Exception at procedure insert_changes: '|| SQLERRM;
1344 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1345 END IF;
1346 RAISE;
1347
1348 END insert_changes;
1349
1350
1351 /*********************************************************************
1352 * NAME
1353 * map_id_to_num
1354 *
1355 * PURPOSE
1356 * Takes the id as input and returns the corresponding num or name.
1357 *
1358 * ARGUMENTS
1359 * p_id Id for which we need the num
1360 * label Column name for which the id to num mapping should be done.
1361 *
1362 *
1363 * HISTORY
1364 * 13-07-2009 bisdas Created
1365 *
1366 ********************************************************************/
1367
1368
1369 FUNCTION map_id_to_num(p_id VARCHAR2, label VARCHAR2)
1370 RETURN varchar2
1371 IS
1372
1373 v_progress VARCHAR2(3);
1374 l_procedure_name VARCHAR2(100) := 'map_id_to_num';
1375 l_log_msg VARCHAR2(2000);
1376
1377 id VARCHAR2(1000);
1378
1379 BEGIN
1380 v_progress:= '000';
1381 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1382 l_log_msg := v_progress||': Inside procedure '||l_procedure_name;
1383 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1384 l_log_msg := 'p_id: ' ||p_id || ' label: '||label;
1385 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1386 END IF;
1387
1388 IF label IN ('DELIVER_TO_LOCATION_ID') THEN
1389 id:= po_compare_revisions.get_location(p_id);
1390 ELSIF label IN ('ITEM_ID') THEN
1391
1392 SELECT msi.concatenated_segments
1393 INTO id
1394 FROM mtl_system_items_kfv msi,
1395 financials_system_parameters fsp
1396 WHERE p_id = msi.inventory_item_id (+)
1397 AND fsp.inventory_organization_id = NVL(msi.organization_id,fsp.inventory_organization_id );
1398
1399 ELSIF label IN ('TO_PERSON_ID','SUGGESTED_BUYER_ID') THEN
1400 id:= po_compare_revisions.get_buyer(p_id);
1401 ELSIF label IN ('HAZARD_CLASS_ID') THEN
1402 id:= po_compare_revisions.get_hazard_class(p_id);
1403 ELSIF label IN ('VENDOR_ID') THEN
1404
1405 SELECT vendor_name
1406 INTO id
1407 FROM po_vendors
1408 WHERE vendor_id = p_id;
1409
1410 ELSIF label IN ('VENDOR_SITE_ID') THEN
1411
1412 SELECT vendor_site_code
1413 INTO id
1414 FROM po_vendor_sites_all
1415 WHERE vendor_site_id = p_id;
1416
1417 ELSIF label IN ('VENDOR_CONTACT_ID') THEN
1418 id:= po_compare_revisions.get_vendor_contact(p_id);
1419 ELSIF label IN ('DESTINATION_TYPE_CODE') THEN
1420 id:= po_compare_revisions.get_po_lookup('RCV DESTINATION TYPE',p_id);
1421 ELSIF label IN ('CATEGORY_ID') THEN
1422
1423 SELECT description
1424 INTO id
1425 FROM mtl_categories_tl
1426 WHERE category_id=p_id
1427 AND source_lang=USERENV('LANG');
1428
1429 ELSIF label IN ('PROJECT_ID') THEN
1430
1431 SELECT name
1432 INTO id
1433 FROM pa_projects_all
1434 WHERE project_id=p_id;
1435
1436 ELSIF label IN ('TASK_ID') THEN
1437
1438 SELECT task_number
1439 INTO id
1440 FROM pa_tasks_expend_v
1441 WHERE task_id=p_id;
1442 ELSIF label IN ('CLM_BASE_LINE_NUM') THEN
1443
1444 SELECT line_num_display INTO id FROM po_requisition_lines_all WHERE requisition_line_id=p_id;
1445
1446 ELSE
1447 id:= p_id;
1448 END IF;
1449
1450 v_progress:= '001';
1451
1452 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1453 l_log_msg := v_progress||' : Function map_id_to_num returns: '||id;
1454 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1455 END IF;
1456
1457 RETURN id;
1458
1459 EXCEPTION
1460 WHEN others THEN
1461
1462 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1463 l_log_msg := v_progress||' : Exception at function map_id_to_num : '|| SQLERRM;
1464 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1465 END IF;
1466 RETURN NULL;
1467
1468 END map_id_to_num;
1469
1470
1471
1472 /*********************************************************************
1473 * NAME
1474 * verify_no_differences
1475 *
1476 * PURPOSE
1477 * Insert a line in the ICX_PO_REVISIONS_TEMP table indicating that
1478 * there are no differences between the compared records.
1479 *
1480 * ARGUMENTS
1481 * p_line_seq Sequence number to identify the comparison
1482 * results for a specific record.
1483 *
1484 * NOTES
1485 * Refer to bug#549414 for more details.
1486 *
1487 * This is used specifically to handle AK functionality. AK is
1488 * expecting a row in table with the PK. The initial table in this
1489 * case is actually a procedure, so AK fails. The procedure checks.
1490 * If there are no differences, insert a dummy row in the table that
1491 * say something like 'No differences.'
1492 *
1493 * HISTORY
1494 * 13-07-09 Bisdas Created
1495 ********************************************************************/
1496
1497
1498
1499 PROCEDURE verify_no_differences( p_line_seq IN NUMBER,p_revision_num NUMBER, amend_num VARCHAR2) AS
1500
1501 records_exist number;
1502 v_progress varchar2(3);
1503 l_procedure_name VARCHAR2(100) := 'verify_no_differences';
1504 l_log_msg VARCHAR2(2000);
1505
1506 BEGIN
1507
1508 v_progress := '000';
1509 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1510 l_log_msg := v_progress||': Inside procedure '||l_procedure_name;
1511 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1512 l_log_msg := 'p_line_seq: ' ||p_line_seq || ' p_revision_num: '||p_revision_num;
1513 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1514 END IF;
1515
1516 SELECT COUNT(*)
1517 INTO records_exist
1518 FROM icx_po_revisions_temp
1519 WHERE line_seq = p_line_seq;
1520
1521 v_progress := '001';
1522
1523 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1524 l_log_msg := v_progress||' : Number of records in temp table: '||records_exist;
1525 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1526 END IF;
1527
1528 IF records_exist = 0 THEN
1529
1530 v_progress := '002';
1531
1532 INSERT INTO
1533 icx_po_revisions_temp(
1534 header_id,
1535 line_seq,
1536 creation_date,
1537 po_num,
1538 revision_num,
1539 line_num,
1540 distribution_num,
1541 level_altered,
1542 field_altered,
1543 changes_from,
1544 changes_to,
1545 line_num_display
1546 )
1547 VALUES
1548 (
1549 -999,
1550 p_line_seq,
1551 SYSDATE,
1552 amend_num,
1553 p_revision_num,
1554 NULL,
1555 NULL,
1556 'HEADER',
1557 fnd_message.get_String('ICX','ICX_NO_DIFFERENCE'),
1558 NULL,
1559 NULL,
1560 NULL
1561 );
1562
1563 END IF;
1564
1565 v_progress := '003';
1566
1567 EXCEPTION
1568 WHEN others THEN
1569
1570 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1571 l_log_msg := v_progress||' : Exception at procedure verify_no_differences : '|| SQLERRM;
1572 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1573 END IF;
1574 RAISE;
1575
1576 END verify_no_differences;
1577
1578
1579 /* ---------------------------------------------- Amendment Status ----------------------------------------------- */
1580
1581 /*********************************************************************
1582 * NAME
1583 * set_amendment_status
1584 *
1585 * PURPOSE
1586 * Checks for the changes in Header, Line and Distribution level and sets
1587 * the amendment_status and amendment_type accordingly.
1588 *
1589 * ARGUMENTS
1590 * p_table_name Table name, possible values:
1591 * PO_REQUISITION_HEADERS_ALL
1592 * PO_REQUISITION_LINES_ALL
1593 * PO_REQ_DISTRIBUTIONS_ALL
1594 * p_revision_num
1595 * p_confirmed_id
1596 *
1597 * NOTES
1598 *
1599 *
1600 * HISTORY
1601 * 19-07-09 Bisdas Created
1602 ********************************************************************/
1603
1604
1605 PROCEDURE set_amendment_status(p_table_name VARCHAR2,
1606 p_revision_num NUMBER,
1607 p_confirmed_id NUMBER)
1608 AS
1609
1610 sql_stmt1 VARCHAR2(10000);
1611 sql_stmt2 VARCHAR2(10000);
1612
1613 x_xml1 CLOB;
1614 x_xml2 CLOB;
1615
1616 -- XML parsing --
1617 p xmlparser.parser;
1618 doc1 xmldom.domdocument;
1619 doc2 xmldom.domdocument;
1620
1621 root xmldom.domelement;
1622 n_list_row1 xmldom.domnodelist;
1623 n_list_row2 xmldom.domnodelist;
1624 n_list1 xmldom.domnodelist;
1625 n_list2 xmldom.domnodelist;
1626 node1 xmldom.domnode;
1627 node2 xmldom.domnode;
1628 l_id VARCHAR2(50);
1629 l_name VARCHAR2(50);
1630 -- XML parsing --
1631
1632 node_val1 VARCHAR2(1000);
1633 node_val2 VARCHAR2(1000);
1634
1635 p_level VARCHAR2(50);
1636
1637
1638 line_num VARCHAR2(100);
1639 old_line_num VARCHAR2(100);
1640 old_amend_type VARCHAR2(50);
1641 amend_type VARCHAR2(50);
1642
1643 header_id NUMBER;
1644 line_id NUMBER;
1645 dist_id NUMBER;
1646
1647 i1 NUMBER := 0;
1648 i2 NUMBER := 0;
1649
1650 change_flag BOOLEAN :=FALSE;
1651 cancel_flag BOOLEAN :=FALSE;
1652 header_change BOOLEAN:= FALSE;
1653 line_change BOOLEAN:= FALSE;
1654 dist_change BOOLEAN:= FALSE;
1655
1656 l_amendment_type po_requisition_lines_all.amendment_type%TYPE;
1657 l_amendment_status po_requisition_lines_all.amendment_status%TYPE;
1658 new_amendment_type po_requisition_lines_all.amendment_type%TYPE;
1659 new_amendment_status po_requisition_lines_all.amendment_status%TYPE;
1660
1661 --Debugging purpose
1662 v_progress VARCHAR2(3);
1663 l_procedure_name VARCHAR2(100) := 'set_amendment_status';
1664 l_log_msg VARCHAR2(2000);
1665
1666
1667 BEGIN
1668
1669
1670 v_progress:='000';
1671
1672 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1673 l_log_msg := v_progress||': Inside procedure '||l_procedure_name;
1674 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1675 l_log_msg := 'p_table_name: ' ||p_table_name ||' p_confirmed_id: '||p_confirmed_id|| ' p_revision_num: '||p_revision_num;
1676 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1677 END IF;
1678
1679 -- SQL What: Querying the archive table for the given revision_num and previous revision_num
1680 -- SQL Why: Need to compare the values for each column
1681
1682 IF p_table_name = 'PO_REQUISITION_HEADERS_ALL' then
1683
1684 sql_stmt1:='SELECT REQUISITION_HEADER_ID,
1685 SEGMENT1,
1686 nvl(CANCEL_FLAG,''N'') CANCEL_FLAG,
1687 nvl(CLOSED_CODE,''OPEN'') CLOSED_CODE,
1688 DESCRIPTION,
1689 NOTE_TO_AUTHORIZER,
1690 USSGL_TRANSACTION_CODE,
1691 PCARD_ID,
1692 REVISION_NUM,
1693 AMENDMENT_STATUS,
1694 AMENDMENT_TYPE
1695 FROM po_requisition_headers_all
1696 WHERE conformed_header_id='||p_confirmed_id||
1697 ' AND revision_num='||(p_revision_num -1);
1698
1699
1700 sql_stmt2:='SELECT REQUISITION_HEADER_ID,
1701 SEGMENT1,
1702 nvl(CANCEL_FLAG,''N'') CANCEL_FLAG,
1703 nvl(CLOSED_CODE,''OPEN'') CLOSED_CODE,
1704 DESCRIPTION,
1705 NOTE_TO_AUTHORIZER,
1706 USSGL_TRANSACTION_CODE,
1707 PCARD_ID,
1708 REVISION_NUM,
1709 AMENDMENT_STATUS,
1710 AMENDMENT_TYPE
1711 FROM po_requisition_headers_all
1712 WHERE conformed_header_id='||p_confirmed_id||
1713 ' AND revision_num='||p_revision_num;
1714
1715
1716 p_level:= 'HEADER';
1717
1718 ELSIF p_table_name = 'PO_REQUISITION_LINES_ALL' then
1719
1720 sql_stmt1:= 'SELECT REQUISITION_LINE_ID,LINE_NUM, LINE_NUM_DISPLAY,nvl(prl.CANCEL_FLAG,''N'') CANCEL_FLAG, nvl(prl.CLOSED_CODE,''OPEN'') CLOSED_CODE,ITEM_ID,ITEM_REVISION,
1721 ITEM_DESCRIPTION, CATEGORY_ID, UNIT_MEAS_LOOKUP_CODE, UNIT_PRICE,QUANTITY,DELIVER_TO_LOCATION_ID,TO_PERSON_ID,
1722 SUGGESTED_BUYER_ID,to_char(NEED_BY_DATE,''DD-MON-YYYY HH24:MI:SS'') NEED_BY_DATE,JUSTIFICATION,NOTE_TO_AGENT,NOTE_TO_RECEIVER,CURRENCY_CODE,RATE_TYPE,to_char(RATE_DATE,''DD-MON-YYYY HH24:MI:SS'') RATE_DATE,
1723 RATE,CURRENCY_UNIT_PRICE,SUGGESTED_VENDOR_NAME,SUGGESTED_VENDOR_LOCATION,SUGGESTED_VENDOR_CONTACT,SUGGESTED_VENDOR_PHONE,
1724 SUGGESTED_VENDOR_PRODUCT_CODE,HAZARD_CLASS_ID,DESTINATION_TYPE_CODE,DESTINATION_ORGANIZATION_ID, DESTINATION_SUBINVENTORY,
1725 VENDOR_ID,VENDOR_SITE_ID, VENDOR_CONTACT_ID,prl.USSGL_TRANSACTION_CODE USSGL_TRANSACTION_CODE, MANUFACTURER_NAME,
1726 MANUFACTURER_PART_NUMBER, REQUESTER_EMAIL,REQUESTER_FAX,REQUESTER_PHONE, UNSPSC_CODE, SUPPLIER_DUNS,AMOUNT,
1727 CURRENCY_AMOUNT,JOB_LONG_DESCRIPTION,SUGGESTED_VENDOR_CONTACT_FAX,SUGGESTED_VENDOR_CONTACT_EMAIL,CANDIDATE_FIRST_NAME,
1728 CANDIDATE_LAST_NAME,to_char(ASSIGNMENT_START_DATE,''DD-MON-YYYY HH24:MI:SS'') ASSIGNMENT_START_DATE,prl.AMENDMENT_STATUS,prl.AMENDMENT_TYPE,CONTRACT_TYPE,COST_CONSTRAINT,
1729 to_char(CLM_PERIOD_PERF_START_DATE,''DD-MON-YYYY HH24:MI:SS'') CLM_PERIOD_PERF_START_DATE,to_char(CLM_PERIOD_PERF_END_DATE,''DD-MON-YYYY HH24:MI:SS'') CLM_PERIOD_PERF_END_DATE,
1730 nvl(CLM_OPTION_EXERCISED,''N'') CLM_OPTION_EXERCISED, CLM_OPTION_FROM_DATE, CLM_OPTION_TO_DATE, FUND_SOURCE_NOT_KNOWN,CLM_OPTION_INDICATOR,CLM_BASE_LINE_NUM
1731 FROM po_requisition_lines_all prl,
1732 po_requisition_headers_all prh
1733 WHERE prh.conformed_header_id='||p_confirmed_id||
1734 'AND prh.requisition_header_id=prl.requisition_header_id
1735 AND prh.revision_num='||(p_revision_num -1)||
1736 'ORDER BY LINE_NUM';
1737
1738 sql_stmt2:='SELECT REQUISITION_LINE_ID,LINE_NUM, LINE_NUM_DISPLAY,nvl(prl.CANCEL_FLAG,''N'') CANCEL_FLAG, nvl(prl.CLOSED_CODE,''OPEN'') CLOSED_CODE,ITEM_ID,ITEM_REVISION,
1739 ITEM_DESCRIPTION, CATEGORY_ID, UNIT_MEAS_LOOKUP_CODE, UNIT_PRICE,QUANTITY,DELIVER_TO_LOCATION_ID,TO_PERSON_ID,
1740 SUGGESTED_BUYER_ID,to_char(NEED_BY_DATE,''DD-MON-YYYY HH24:MI:SS'') NEED_BY_DATE,JUSTIFICATION,NOTE_TO_AGENT,NOTE_TO_RECEIVER,CURRENCY_CODE,RATE_TYPE,to_char(RATE_DATE,''DD-MON-YYYY HH24:MI:SS'') RATE_DATE,
1741 RATE,CURRENCY_UNIT_PRICE,SUGGESTED_VENDOR_NAME,SUGGESTED_VENDOR_LOCATION,SUGGESTED_VENDOR_CONTACT,SUGGESTED_VENDOR_PHONE,
1742 SUGGESTED_VENDOR_PRODUCT_CODE,HAZARD_CLASS_ID,DESTINATION_TYPE_CODE,DESTINATION_ORGANIZATION_ID, DESTINATION_SUBINVENTORY,
1743 VENDOR_ID,VENDOR_SITE_ID, VENDOR_CONTACT_ID,prl.USSGL_TRANSACTION_CODE USSGL_TRANSACTION_CODE, MANUFACTURER_NAME,
1744 MANUFACTURER_PART_NUMBER, REQUESTER_EMAIL,REQUESTER_FAX,REQUESTER_PHONE, UNSPSC_CODE, SUPPLIER_DUNS,AMOUNT,
1745 CURRENCY_AMOUNT,JOB_LONG_DESCRIPTION,SUGGESTED_VENDOR_CONTACT_FAX,SUGGESTED_VENDOR_CONTACT_EMAIL,CANDIDATE_FIRST_NAME,
1746 CANDIDATE_LAST_NAME,to_char(ASSIGNMENT_START_DATE,''DD-MON-YYYY HH24:MI:SS'') ASSIGNMENT_START_DATE,prl.AMENDMENT_STATUS,prl.AMENDMENT_TYPE,CONTRACT_TYPE,COST_CONSTRAINT,
1747 to_char(CLM_PERIOD_PERF_START_DATE,''DD-MON-YYYY HH24:MI:SS'') CLM_PERIOD_PERF_START_DATE,to_char(CLM_PERIOD_PERF_END_DATE,''DD-MON-YYYY HH24:MI:SS'') CLM_PERIOD_PERF_END_DATE,
1748 nvl(CLM_OPTION_EXERCISED,''N'') CLM_OPTION_EXERCISED, CLM_OPTION_FROM_DATE, CLM_OPTION_TO_DATE, FUND_SOURCE_NOT_KNOWN,CLM_OPTION_INDICATOR,CLM_BASE_LINE_NUM
1749 FROM po_requisition_lines_all prl,
1750 po_requisition_headers_all prh
1751 WHERE prh.conformed_header_id='||p_confirmed_id||
1752 'AND prh.requisition_header_id=prl.requisition_header_id
1753 AND prh.revision_num='||p_revision_num||
1754 'ORDER BY LINE_NUM';
1755
1756 p_level:= 'LINES';
1757
1758 ELSIF p_table_name = 'PO_REQ_DISTRIBUTIONS_ALL' THEN
1759
1760 /* Added NVL around RECOVERABLE_TAX, NONRECOVERABLE_TAX, RECOVERY_RATE
1761 to disregard the difference between NULL and 0.
1762 */
1763
1764 /* <<CLM Partial Funding Changes>>
1765 Added following partial funding attributes:
1766 PARTIAL_FUNDED_FLAG, FUNDED_VALUE, QUANTITY_FUNDED, AMOUNT_FUNDED
1767 */
1768 sql_stmt1:='SELECT DISTRIBUTION_ID,
1769 prl.LINE_NUM LINE_NUM,
1770 prl.LINE_NUM_DISPLAY LINE_NUM_DISPLAY,
1771 DISTRIBUTION_NUM,
1772 nvl(prl.CANCEL_FLAG,''N'') LINE_CANCEL_FLAG,
1773 prl.ITEM_ID LINE_ITEM_ID,
1774 CODE_COMBINATION_ID,
1775 REQ_LINE_QUANTITY,
1776 to_char(GL_ENCUMBERED_DATE,''DD-MON-YYYY HH24:MI:SS'') GL_ENCUMBERED_DATE,
1777 prd.USSGL_TRANSACTION_CODE USSGL_TRANSACTION_CODE,
1778 PROJECT_ID,
1779 TASK_ID,
1780 EXPENDITURE_TYPE,
1781 EXPENDITURE_ORGANIZATION_ID,
1782 to_char(EXPENDITURE_ITEM_DATE,''DD-MON-YYYY HH24:MI:SS'') EXPENDITURE_ITEM_DATE,
1783 nvl(RECOVERABLE_TAX,0) RECOVERABLE_TAX,
1784 nvl(NONRECOVERABLE_TAX,0) NONRECOVERABLE_TAX,
1785 nvl(RECOVERY_RATE,0) RECOVERY_RATE,
1786 REQ_LINE_AMOUNT,
1787 REQ_LINE_CURRENCY_AMOUNT,
1788 prd.AMENDMENT_STATUS,
1789 prd.AMENDMENT_TYPE,
1790 PARTIAL_FUNDED_FLAG,
1791 FUNDED_VALUE,
1792 QUANTITY_FUNDED,
1793 AMOUNT_FUNDED
1794 FROM po_req_distributions_all prd,
1795 po_requisition_lines_all prl,
1796 po_requisition_headers_all prh
1797 WHERE prh.conformed_header_id='||p_confirmed_id||
1798 'AND prh.requisition_header_id=prl.requisition_header_id
1799 AND prl.requisition_line_id=nvl(prd.info_line_id,prd.requisition_line_id)
1800 AND revision_num='||(p_revision_num -1)||
1801 'ORDER BY nvl(prd.info_line_id,prd.requisition_line_id),DISTRIBUTION_NUM' ;
1802
1803 /* Added NVL around RECOVERABLE_TAX, NONRECOVERABLE_TAX, RECOVERY_RATE
1804 to disregard the difference between NULL and 0.
1805 */
1806
1807 /* <<CLM Partial Funding Changes>>
1808 Added following partial funding attributes:
1809 PARTIAL_FUNDED_FLAG, FUNDED_VALUE, QUANTITY_FUNDED, AMOUNT_FUNDED
1810 */
1811 sql_stmt2:='SELECT DISTRIBUTION_ID,
1812 prl.LINE_NUM LINE_NUM,
1813 prl.LINE_NUM_DISPLAY LINE_NUM_DISPLAY,
1814 DISTRIBUTION_NUM,
1815 nvl(prl.CANCEL_FLAG,''N'') LINE_CANCEL_FLAG,
1816 prl.ITEM_ID LINE_ITEM_ID,
1817 CODE_COMBINATION_ID,
1818 REQ_LINE_QUANTITY,
1819 to_char(GL_ENCUMBERED_DATE,''DD-MON-YYYY HH24:MI:SS'') GL_ENCUMBERED_DATE,
1820 prd.USSGL_TRANSACTION_CODE USSGL_TRANSACTION_CODE,
1821 PROJECT_ID,
1822 TASK_ID,
1823 EXPENDITURE_TYPE,
1824 EXPENDITURE_ORGANIZATION_ID,
1825 to_char(EXPENDITURE_ITEM_DATE,''DD-MON-YYYY HH24:MI:SS'') EXPENDITURE_ITEM_DATE,
1826 nvl(RECOVERABLE_TAX,0) RECOVERABLE_TAX,
1827 nvl(NONRECOVERABLE_TAX,0) NONRECOVERABLE_TAX,
1828 nvl(RECOVERY_RATE,0) RECOVERY_RATE,
1829 REQ_LINE_AMOUNT,
1830 REQ_LINE_CURRENCY_AMOUNT,
1831 prd.AMENDMENT_STATUS,
1832 prd.AMENDMENT_TYPE,
1833 PARTIAL_FUNDED_FLAG,
1834 FUNDED_VALUE,
1835 QUANTITY_FUNDED,
1836 AMOUNT_FUNDED
1837 FROM po_req_distributions_all prd,
1838 po_requisition_lines_all prl,
1839 po_requisition_headers_all prh
1840 WHERE prh.conformed_header_id='||p_confirmed_id||
1841 'AND prh.requisition_header_id=prl.requisition_header_id
1842 AND prl.requisition_line_id=nvl(prd.info_line_id,prd.requisition_line_id)
1843 AND revision_num='||p_revision_num||
1844 'ORDER BY nvl(prd.info_line_id,prd.requisition_line_id),DISTRIBUTION_NUM';
1845
1846 p_level:= 'DIST';
1847
1848 END IF;
1849
1850 v_progress:='001';
1851 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1852 l_log_msg := v_progress||' : After creating queries';
1853 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1854 END IF;
1855
1856
1857 -- Getting the XMLs based on the dynamic queries
1858
1859 x_xml1:= create_xml(sql_stmt1);
1860 x_xml2:= create_xml(sql_stmt2);
1861
1862 v_progress:='002';
1863 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
1864 l_log_msg := v_progress||' : After creating XMLs';
1865 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
1866 END IF;
1867
1868
1869 IF (x_xml1 IS NOT NULL AND x_xml2 IS NOT NULL) THEN
1870
1871 -- Parse XMLs to find out the differences
1872
1873 p := xmlparser.newparser();
1874
1875 xmlparser.parseclob(p, x_xml1);
1876
1877 doc1 := xmlparser.getdocument(p);
1878
1879 xmlparser.freeparser(p);
1880 v_progress:='003';
1881
1882 p := xmlparser.newparser();
1883
1884 xmlparser.parseclob(p, x_xml2);
1885
1886 doc2 := xmlparser.getdocument(p);
1887
1888 xmlparser.freeparser(p);
1889 v_progress:='004';
1890
1891 --n_list_row1 := xmldom.getElementsByTagName(doc1,'ROWSET');
1892 -- n_list_row2 := xmldom.getElementsByTagName(doc2,'ROWSET');
1893
1894 n_list_row1 := xmldom.getChildNodes(xmldom.item(xmldom.getElementsByTagName(doc1,'ROWSET'),0));
1895 n_list_row2 := xmldom.getChildNodes(xmldom.item(xmldom.getElementsByTagName(doc2,'ROWSET'),0));
1896
1897
1898 --FOR i IN 0 .. xmldom.getLength(n_list_row2)-1 LOOP
1899
1900 LOOP
1901
1902 node1:= xmldom.item(n_list_row1,i1);
1903 node2:= xmldom.item(n_list_row2,i2);
1904
1905 --header_change:=FALSE;
1906 --line_change:=FALSE;
1907 --dist_change:=FALSE;
1908
1909 change_flag:=FALSE;
1910 cancel_flag:=FALSE;
1911
1912
1913 IF xmldom.isNULL(node1) THEN
1914 n_list2:=xmldom.getChildNodes(node2);
1915
1916 FOR j IN 0 .. xmldom.getLength(n_list2)-1 LOOP
1917 node2 := xmldom.item(n_list2,j);
1918
1919 IF xmldom.getNodeName(node2) = 'REQUISITION_HEADER_ID' THEN
1920 header_id := xmldom.getNodeValue(xmldom.item(xmldom.getChildNodes(node2), 0));
1921 END IF;
1922
1923 IF xmldom.getNodeName(node2) = 'REQUISITION_LINE_ID' THEN
1924 line_id := xmldom.getNodeValue(xmldom.item(xmldom.getChildNodes(node2), 0));
1925 END IF;
1926
1927 IF xmldom.getNodeName(node2) = 'DISTRIBUTION_ID' THEN
1928 dist_id := xmldom.getNodeValue(xmldom.item(xmldom.getChildNodes(node2), 0));
1929 END IF;
1930
1931
1932
1933 END LOOP;
1934
1935 IF p_level = 'LINES' THEN
1936 change_flag:=TRUE;
1937 amend_type := 'ADDED';
1938 ELSIF p_level = 'DIST' THEN
1939 change_flag:=TRUE;
1940 amend_type := 'ADDED';
1941 END IF;
1942
1943 ELSE
1944
1945 n_list1:=xmldom.getChildNodes(node1);
1946 n_list2:=xmldom.getChildNodes(node2);
1947
1948 FOR j IN 0 .. xmldom.getLength(n_list1)-1 LOOP
1949
1950
1951 node1 := xmldom.item(n_list1,j);
1952 node2 := xmldom.item(n_list2,j);
1953
1954 node_val1 := xmldom.getNodeValue(xmldom.item(xmldom.getChildNodes(node1), 0));
1955 node_val2 := xmldom.getNodeValue(xmldom.item(xmldom.getChildNodes(node2), 0));
1956
1957
1958 IF xmldom.getNodeName(node2) = 'LINE_NUM' THEN
1959 line_num := node_val2;
1960 old_line_num := node_val1;
1961 END IF;
1962
1963 IF xmldom.getNodeName(node2) = 'REQUISITION_HEADER_ID' THEN
1964 header_id := xmldom.getNodeValue(xmldom.item(xmldom.getChildNodes(node2), 0));
1965 END IF;
1966
1967 IF xmldom.getNodeName(node2) = 'REQUISITION_LINE_ID' THEN
1968 line_id := node_val2;
1969 END IF;
1970
1971 IF xmldom.getNodeName(node2) = 'DISTRIBUTION_ID' THEN
1972 dist_id := node_val2;
1973 END IF;
1974
1975 IF xmldom.getNodeName(node1) = 'AMENDMENT_TYPE' THEN
1976 old_amend_type := node_val1;
1977
1978 IF node_val1 <> node_val2 AND node_val2 = 'CANCELLED' THEN
1979 cancel_flag:=TRUE;
1980 change_flag:=TRUE;
1981 EXIT; -- Exit from the loop if Canceled
1982 END IF;
1983 END IF;
1984
1985
1986 IF line_num <> old_line_num AND p_level = 'DIST' AND xmldom.getNodeName(node1) NOT IN ('DISTRIBUTION_ID','LINE_NUM') THEN
1987 i1:=i1-1;
1988 change_flag:=TRUE;
1989 amend_type:='ADDED';
1990 EXIT;
1991 END IF;
1992
1993
1994 IF xmldom.getNodeName(node1) in ('CANCEL_FLAG','LINE_CANCEL_FLAG') AND node_val1 <> node_val2 THEN
1995
1996 cancel_flag:=TRUE;
1997 change_flag:=TRUE;
1998
1999 EXIT; -- Exit from the loop if Canceled
2000
2001 END IF;
2002
2003 IF xmldom.getNodeName(node1) = 'CLOSED_CODE' AND node_val1 <> node_val2 THEN
2004
2005 change_flag:=TRUE;
2006 amend_type:='CHANGED';
2007
2008 EXIT; -- Exit from the loop if Closed
2009
2010 END IF;
2011
2012
2013 IF Nvl(node_val1,-999) <> Nvl(node_val2,-999)
2014 AND xmldom.getNodeName(node1) NOT IN ('REQUISITION_HEADER_ID',
2015 'SEGMENT1',
2016 'REVISION_NUM',
2017 'REQUISITION_LINE_ID',
2018 'DISTRIBUTION_ID',
2019 'LINE_ITEM_ID',
2020 'LINE_NUM',
2021 'DISTRIBUTION_NUM',
2022 'AMENDMENT_STATUS',
2023 'AMENDMENT_TYPE') THEN
2024
2025 change_flag:=TRUE;
2026 amend_type:='CHANGED';
2027
2028 EXIT;
2029 END IF;
2030
2031 END LOOP;
2032
2033 END IF;
2034
2035
2036 IF p_level = 'HEADER' THEN
2037 IF change_flag THEN
2038
2039 IF NOT cancel_flag THEN
2040
2041 UPDATE po_requisition_headers_all
2042 SET amendment_status = 'N',
2043 amendment_type = 'CHANGED'
2044 WHERE requisition_header_id=header_id;
2045
2046 END IF;
2047
2048 ELSE
2049 IF old_amend_type in ('CHANGED') THEN
2050
2051 UPDATE po_requisition_headers_all
2052 SET amendment_type=old_amend_type,
2053 amendment_status = 'P'
2054 WHERE requisition_header_id=header_id
2055 AND amendment_status NOT IN ('A','R');
2056
2057 END IF;
2058
2059 END IF;
2060
2061 ELSIF p_level = 'LINES' THEN
2062 IF change_flag THEN
2063
2064 IF NOT cancel_flag THEN
2065
2066 IF amend_type = 'CHANGED' THEN
2067
2068 UPDATE po_requisition_lines_all
2069 SET amendment_status = 'N',
2070 amendment_type = 'CHANGED'
2071 WHERE requisition_line_id=line_id;
2072
2073 ELSIF amend_type = 'ADDED' THEN
2074
2075 UPDATE po_requisition_lines_all
2076 SET amendment_status = 'N',
2077 amendment_type = 'ADDED'
2078 WHERE requisition_line_id=line_id;
2079
2080 END IF;
2081
2082 END IF;
2083
2084 ELSE
2085 IF old_amend_type in ('ADDED','CHANGED') THEN
2086 UPDATE po_requisition_lines_all
2087 SET amendment_type=old_amend_type,
2088 amendment_status = 'P'
2089 WHERE requisition_line_id=line_id
2090 AND amendment_status NOT IN ('A','R');
2091 END IF;
2092
2093 END IF;
2094
2095 ELSIF p_level = 'DIST' THEN
2096 IF change_flag THEN
2097
2098 IF NOT cancel_flag THEN
2099
2100 IF amend_type = 'CHANGED' THEN
2101
2102 UPDATE po_req_distributions_all
2103 SET amendment_status = 'N',
2104 amendment_type = 'CHANGED'
2105 WHERE distribution_id=dist_id;
2106
2107 UPDATE po_requisition_lines_all
2108 SET amendment_status = 'N',
2109 amendment_type = 'CHANGED'
2110 WHERE requisition_line_id=(SELECT Nvl(info_line_id,requisition_line_id)
2111 FROM po_req_distributions_all
2112 WHERE distribution_id=dist_id);
2113
2114
2115 ELSIF amend_type = 'ADDED' THEN
2116
2117 UPDATE po_req_distributions_all
2118 SET amendment_status = 'N',
2119 amendment_type = 'ADDED'
2120 WHERE distribution_id=dist_id;
2121
2122 --Get the amendment_type and amendment_status of the parent
2123 --line and then change its status accordingly
2124 SELECT amendment_type,amendment_status
2125 INTO l_amendment_type, l_amendment_status
2126 FROM po_requisition_lines_all
2127 WHERE requisition_line_id=(SELECT Nvl(info_line_id,requisition_line_id)
2128 FROM po_req_distributions_all
2129 WHERE distribution_id=dist_id);
2130
2131 new_amendment_type := 'CHANGED';
2132 new_amendment_status := 'N';
2133
2134 IF l_amendment_type = 'ADDED' THEN
2135 new_amendment_type := 'ADDED';
2136 END IF;
2137
2138 UPDATE po_requisition_lines_all
2139 SET amendment_status = new_amendment_status,
2140 amendment_type = new_amendment_type
2141 WHERE requisition_line_id=(SELECT Nvl(info_line_id,requisition_line_id)
2142 FROM po_req_distributions_all
2143 WHERE distribution_id=dist_id);
2144
2145 END IF;
2146
2147 END IF;
2148
2149 ELSE
2150 IF old_amend_type in ('ADDED','CHANGED') THEN
2151 UPDATE po_req_distributions_all
2152 SET amendment_type=old_amend_type,
2153 amendment_status = 'P'
2154 WHERE distribution_id=dist_id
2155 AND amendment_status NOT IN ('A','R');
2156 END IF;
2157
2158 END IF;
2159 END IF;
2160
2161
2162
2163
2164 i2 := i2+1;
2165 i1 := i1+1;
2166
2167 EXIT WHEN i2=xmldom.getLength(n_list_row2);
2168
2169 END LOOP;
2170
2171 END IF; -- If x_xml1 is NOT NULL
2172
2173 v_progress:='005';
2174 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2175 l_log_msg := v_progress||' : After comparing xmls';
2176 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2177 END IF;
2178
2179
2180 EXCEPTION
2181 WHEN others THEN
2182
2183 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2184 l_log_msg := v_progress||' : Exception at procedure set_amendment_status : '|| SQLERRM;
2185 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2186 END IF;
2187 RAISE;
2188
2189 END set_amendment_status;
2190
2191
2192 /*********************************************************************
2193 * NAME
2194 * update_amendment
2195 *
2196 * PURPOSE
2197 * This is the wrapper for set_amendment_status to update the amendment_status
2198 * and amendment_type.
2199 *
2200 * ARGUMENTS
2201 * p_confirmed_id
2202 * p_revision_num
2203 *
2204 * NOTES
2205 *
2206 *
2207 * HISTORY
2208 * 19-07-09 Bisdas Created
2209 ********************************************************************/
2210
2211
2212 PROCEDURE update_amendment(p_confirmed_id NUMBER, p_revision_num NUMBER)
2213 AS
2214
2215 amend_num VARCHAR2(100);
2216
2217 v_progress VARCHAR2(3);
2218 l_procedure_name VARCHAR2(100) := 'update_amendment';
2219 l_log_msg VARCHAR2(2000);
2220
2221 BEGIN
2222
2223 v_progress:='000';
2224
2225 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2226 l_log_msg := v_progress||': Inside procedure '||l_procedure_name;
2227 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2228 l_log_msg := 'p_confirmed_id: ' ||p_confirmed_id || ' p_revision_num: '||p_revision_num;
2229 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2230 END IF;
2231
2232 set_amendment_status('PO_REQUISITION_HEADERS_ALL',p_revision_num,p_confirmed_id);
2233 set_amendment_status('PO_REQUISITION_LINES_ALL',p_revision_num,p_confirmed_id);
2234 set_amendment_status('PO_REQ_DISTRIBUTIONS_ALL',p_revision_num,p_confirmed_id);
2235
2236 v_progress:='001';
2237
2238 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2239 l_log_msg := v_progress||' : Update completes';
2240 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2241 END IF;
2242
2243 COMMIT;
2244
2245 EXCEPTION
2246 WHEN OTHERS THEN
2247
2248 ROLLBACK;
2249
2250 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2251 l_log_msg := v_progress||' : Exception at procedure update_amendment : '|| SQLERRM;
2252 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2253 END IF;
2254 RAISE;
2255
2256 END update_amendment;
2257
2258
2259
2260 PROCEDURE getAmendmentAttributes(p_req_header_id IN NUMBER,
2261 p_req_number IN VARCHAR2,
2262 x_revision_num OUT NOCOPY NUMBER,
2263 x_segment1 OUT NOCOPY VARCHAR2)
2264 IS
2265 l_num NUMBER:=0;
2266 l_val VARCHAR2(3);
2267
2268 CURSOR C(l_header_id NUMBER) IS
2269 SELECT Max(Nvl(revision_num,0))+1 FROM po_requisition_headers_all
2270 WHERE conformed_header_id = l_header_id;
2271
2272 l_procedure_name VARCHAR2(100) := 'getAmendmentAttributes';
2273 l_log_msg VARCHAR2(2000);
2274
2275 BEGIN
2276
2277 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2278 l_log_msg := 'Inside procedure : '||l_procedure_name;
2279 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2280 l_log_msg := 'p_req_header_id : '||p_req_header_id||', p_req_number : '||p_req_number;
2281 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2282 END IF;
2283
2284
2285 BEGIN
2286 OPEN C(p_req_header_id);
2287 FETCH C INTO x_revision_num;
2288 CLOSE C;
2289
2290 IF x_revision_num IS NULL THEN
2291 x_revision_num := 1;
2292 END IF;
2293
2294 EXCEPTION
2295 WHEN No_Data_Found THEN
2296 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2297 l_log_msg := 'Inside No_DATA_FOUND';
2298 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2299 END IF;
2300
2301 x_revision_num := 1;
2302 END;
2303
2304 SELECT LPad(x_revision_num ,3,'0') INTO l_val FROM dual;
2305
2306 x_segment1 := p_req_number||'-'||l_val;
2307
2308 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2309 l_log_msg := 'Exiting with values x_revision_num : '||x_revision_num||', x_segment1: '||x_segment1;
2310 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2311 END IF;
2312
2313
2314 END getAmendmentAttributes;
2315
2316
2317
2318 FUNCTION is_req_amendable(l_req_header_id IN NUMBER)
2319 RETURN NUMBER
2320 IS
2321 l_Cnt NUMBER:=0;
2322 BEGIN
2323 SELECT Count(*) INTO l_Cnt
2324 FROM po_requisition_headers_all
2325 WHERE conformed_header_id = l_req_header_id
2326 AND AUTHORIZATION_STATUS NOT IN ('APPROVED','REJECTED','RETURNED','CANCELLED');
2327
2328 RETURN l_Cnt;
2329 END;
2330
2331
2332
2333 PROCEDURE merge_amendment_header(p_confirmed_id IN NUMBER, p_revision_num IN NUMBER)
2334 IS
2335
2336 sql_stmt VARCHAR2(2000);
2337 req_header_id NUMBER;
2338
2339 v_progress VARCHAR2(10);
2340 l_procedure_name VARCHAR2(100) := 'merge_amendment_header';
2341 l_log_msg VARCHAR2(2000);
2342
2343 BEGIN
2344
2345 v_progress := '000';
2346 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2347 l_log_msg := v_progress||': Inside procedure '||l_procedure_name;
2348 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2349 l_log_msg := 'p_confirmed_id : '||p_confirmed_id||', p_revision_num : '||p_revision_num;
2350 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2351 END IF;
2352
2353 -- Creating the sql statement
2354
2355 sql_stmt:='MERGE
2356 INTO po_requisition_headers_all target
2357 USING (SELECT *
2358 FROM po_requisition_headers_all
2359 WHERE conformed_header_id = '||p_confirmed_id||'
2360 AND revision_num = '||p_revision_num||') source
2361 ON (target.requisition_header_id = '||p_confirmed_id||'
2362 AND target.revision_num IS NULL
2363 AND target.requisition_header_id = source.conformed_header_id)
2364 WHEN MATCHED
2365 THEN
2366 UPDATE
2367 SET target.CLOSED_CODE = source.CLOSED_CODE,
2368 target.DESCRIPTION = source.DESCRIPTION,
2369 target.NOTE_TO_AUTHORIZER = source.NOTE_TO_AUTHORIZER,
2370 target.CANCEL_FLAG = source.CANCEL_FLAG,
2371 target.USSGL_TRANSACTION_CODE = source.USSGL_TRANSACTION_CODE,
2372 target.PCARD_ID = source.PCARD_ID,
2373 target.AMENDMENT_TYPE = source.AMENDMENT_TYPE,
2374 target.AMENDMENT_STATUS = source.AMENDMENT_STATUS,
2375 target.AMENDMENT_REASON = source.AMENDMENT_REASON';
2376
2377 v_progress := '001';
2378
2379 EXECUTE IMMEDIATE sql_stmt;
2380
2381
2382 /* Merging attachments - start */
2383 v_progress := '002';
2384
2385 SELECT requisition_header_id
2386 INTO req_header_id
2387 FROM po_requisition_headers_all
2388 WHERE conformed_header_id = p_confirmed_id
2389 AND revision_num = p_revision_num;
2390
2391
2392 v_progress := '003';
2393 fnd_attached_documents2_pkg.delete_attachments('REQ_HEADERS',
2394 ''||p_confirmed_id,
2395 '',
2396 '',
2397 '',
2398 '',
2399 'Y',
2400 '');
2401
2402 v_progress := '004';
2403 fnd_attached_documents2_pkg.copy_attachments('REQ_HEADERS',
2404 ''||req_header_id,
2405 '',
2406 '',
2407 '',
2408 '',
2409 'REQ_HEADERS',
2410 ''||p_confirmed_id,
2411 '',
2412 '',
2413 '',
2414 '',
2415 fnd_global.user_id,
2416 fnd_global.login_id,
2417 '',
2418 '',
2419 '');
2420 v_progress := '005';
2421 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2422 l_log_msg := v_progress||' : After merging attachments for Header';
2423 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2424 END IF;
2425 /* Merging attachments - end */
2426
2427
2428 EXCEPTION
2429 WHEN OTHERS THEN
2430
2431 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2432 l_log_msg := v_progress||' : Exception at merge_amendment_header : '|| SQLERRM;
2433 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2434 END IF;
2435 RAISE;
2436 END merge_amendment_header;
2437
2438
2439 PROCEDURE create_amd_dist_on_conf_copy (p_from_dist_id IN NUMBER,
2440 p_to_req_line_id IN NUMBER,
2441 p_info_line_id IN NUMBER,
2442 x_new_dist_id OUT NOCOPY number)
2443 IS
2444 l_procedure_name VARCHAR2(100) := 'create_amd_dist_on_conf_copy';
2445 l_log_msg VARCHAR2(2000);
2446
2447
2448 BEGIN
2449 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2450 l_log_msg := ': Inside procedure '||l_procedure_name;
2451 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2452 END IF;
2453
2454 SELECT po_req_distributions_s.NEXTVAL
2455 INTO x_new_dist_id
2456 FROM dual;
2457
2458 INSERT INTO po_req_distributions_all
2459 (distribution_id,
2460 last_update_date,
2461 last_updated_by,
2462 requisition_line_id,
2463 set_of_books_id,
2464 code_combination_id,
2465 req_line_quantity,
2466 last_update_login,
2467 creation_date,
2468 created_by,
2469 encumbered_flag,
2470 gl_encumbered_date,
2471 gl_encumbered_period_name,
2472 gl_cancelled_date,
2473 failed_funds_lookup_code,
2474 encumbered_amount,
2475 budget_account_id,
2476 accrual_account_id,
2477 variance_account_id,
2478 prevent_encumbrance_flag,
2479 attribute_category,
2480 attribute1,
2481 attribute2,
2482 attribute3,
2483 attribute4,
2484 attribute5,
2485 attribute6,
2486 attribute7,
2487 attribute8,
2488 attribute9,
2489 attribute10,
2490 attribute11,
2491 attribute12,
2492 attribute13,
2493 attribute14,
2494 attribute15,
2495 ussgl_transaction_code,
2496 government_context,
2497 request_id,
2498 program_application_id,
2499 program_id,
2500 program_update_date,
2501 project_id,
2502 task_id,
2503 expenditure_type,
2504 project_accounting_context,
2505 expenditure_organization_id,
2506 gl_closed_date,
2507 source_req_distribution_id,
2508 distribution_num,
2509 project_related_flag,
2510 expenditure_item_date,
2511 org_id,
2512 allocation_type,
2513 allocation_value,
2514 award_id,
2515 end_item_unit_number,
2516 recoverable_tax,
2517 nonrecoverable_tax,
2518 recovery_rate,
2519 tax_recovery_override_flag,
2520 oke_contract_line_id,
2521 oke_contract_deliverable_id,
2522 req_line_amount,
2523 req_line_currency_amount,
2524 req_award_id,
2525 event_id,
2526 amendment_type,
2527 amendment_status,
2528 info_line_id,
2529 partial_funded_flag,
2530 funded_value,
2531 quantity_funded,
2532 amount_funded,
2533 change_in_funded_value, -- <<CLM Partial Funding Code Changes>>
2534 clm_misc_loa,
2535 clm_defence_funding,
2536 clm_fms_case_number,
2537 clm_agency_acct_identifier,
2538 acrn)
2539 SELECT
2540 x_new_dist_id,
2541 source.last_update_date,
2542 source.last_updated_by,
2543 p_to_req_line_id,
2544 source.set_of_books_id,
2545 source.code_combination_id,
2546 source.req_line_quantity,
2547 source.last_update_login,
2548 source.creation_date,
2549 source.created_by,
2550 source.encumbered_flag,
2551 source.gl_encumbered_date,
2552 source.gl_encumbered_period_name,
2553 source.gl_cancelled_date,
2554 source.failed_funds_lookup_code,
2555 source.encumbered_amount,
2556 source.budget_account_id,
2557 source.accrual_account_id,
2558 source.variance_account_id,
2559 source.prevent_encumbrance_flag,
2560 source.attribute_category,
2561 source.attribute1,
2562 source.attribute2,
2563 source.attribute3,
2564 source.attribute4,
2565 source.attribute5,
2566 source.attribute6,
2567 source.attribute7,
2568 source.attribute8,
2569 source.attribute9,
2570 source.attribute10,
2571 source.attribute11,
2572 source.attribute12,
2573 source.attribute13,
2574 source.attribute14,
2575 source.attribute15,
2576 source.ussgl_transaction_code,
2577 source.government_context,
2578 source.request_id,
2579 source.program_application_id,
2580 source.program_id,
2581 source.program_update_date,
2582 source.project_id,
2583 source.task_id,
2584 source.expenditure_type,
2585 source.project_accounting_context,
2586 source.expenditure_organization_id,
2587 source.gl_closed_date,
2588 source.source_req_distribution_id,
2589 source.distribution_num,
2590 source.project_related_flag,
2591 source.expenditure_item_date,
2592 source.org_id,
2593 source.allocation_type,
2594 source.allocation_value,
2595 source.award_id,
2596 source.end_item_unit_number,
2597 source.recoverable_tax,
2598 source.nonrecoverable_tax,
2599 source.recovery_rate,
2600 source.tax_recovery_override_flag,
2601 source.oke_contract_line_id,
2602 source.oke_contract_deliverable_id,
2603 source.req_line_amount,
2604 source.req_line_currency_amount,
2605 source.req_award_id,
2606 source.event_id,
2607 source.amendment_type,
2608 source.amendment_status,
2609 p_info_line_id,
2610 source.partial_funded_flag,
2611 source.funded_value,
2612 source.quantity_funded,
2613 source.amount_funded,
2614 source.change_in_funded_value, -- <<CLM Partial Funding Code Changes>>
2615 source.clm_misc_loa,
2616 source.clm_defence_funding,
2617 source.clm_fms_case_number,
2618 source.clm_agency_acct_identifier,
2619 source.acrn
2620 FROM po_req_distributions_all source
2621 WHERE distribution_id = p_from_dist_id;
2622
2623 EXCEPTION
2624 WHEN OTHERS THEN
2625 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2626 l_log_msg := ' : Exception at create_amd_dist_on_conf_copy: '|| SQLERRM;
2627 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2628 END IF;
2629 RAISE;
2630
2631 END create_amd_dist_on_conf_copy;
2632
2633
2634
2635 PROCEDURE update_amd_dist_on_conf_copy (p_from_dist_id IN NUMBER,
2636 p_to_dist_id IN NUMBER)
2637 IS
2638 l_procedure_name VARCHAR2(100) := 'update_amd_dist_on_conf_copy';
2639 l_log_msg VARCHAR2(2000);
2640
2641 BEGIN
2642 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2643 l_log_msg := ': Inside procedure '||l_procedure_name;
2644 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2645 END IF;
2646
2647 MERGE
2648 INTO po_req_distributions_all target
2649 USING (SELECT * FROM po_req_distributions_all
2650 WHERE distribution_id = p_from_dist_id) source
2651 ON ( target.distribution_id = p_to_dist_id
2652 AND source.CONFORMED_DIST_ID = target.distribution_id
2653 )
2654 WHEN MATCHED
2655 THEN
2656 UPDATE
2657 SET target.CODE_COMBINATION_ID = source.CODE_COMBINATION_ID,
2658 target.REQ_LINE_QUANTITY = source.REQ_LINE_QUANTITY,
2659 target.GL_ENCUMBERED_DATE = source.GL_ENCUMBERED_DATE,
2660 target.USSGL_TRANSACTION_CODE = source.USSGL_TRANSACTION_CODE,
2661 target.PROJECT_ID = source.PROJECT_ID,
2662 target.TASK_ID = source.TASK_ID,
2663 target.EXPENDITURE_TYPE = source.EXPENDITURE_TYPE,
2664 target.EXPENDITURE_ORGANIZATION_ID = source.EXPENDITURE_ORGANIZATION_ID,
2665 target.EXPENDITURE_ITEM_DATE = source.EXPENDITURE_ITEM_DATE,
2666 target.RECOVERABLE_TAX = source.RECOVERABLE_TAX,
2667 target.NONRECOVERABLE_TAX = source.NONRECOVERABLE_TAX,
2668 target.RECOVERY_RATE = source.RECOVERY_RATE,
2669 target.REQ_LINE_AMOUNT = source.REQ_LINE_AMOUNT,
2670 target.REQ_LINE_CURRENCY_AMOUNT = source.REQ_LINE_CURRENCY_AMOUNT,
2671 target.AMENDMENT_TYPE = source.AMENDMENT_TYPE,
2672 target.AMENDMENT_STATUS = source.AMENDMENT_STATUS,
2673 target.ALLOCATION_VALUE = source.ALLOCATION_VALUE,
2674 -- <<CLM Partial Funding Code Changes>>
2675 target.partial_funded_flag = source.partial_funded_flag,
2676 target.funded_value = source.funded_value,
2677 target.quantity_funded = source.quantity_funded,
2678 target.amount_funded = source.amount_funded,
2679 target.change_in_funded_value = Nvl(source.change_in_funded_value,0) ;
2680 -- <<CLM Partial Funding Code Changes>>
2681 EXCEPTION
2682 WHEN OTHERS THEN
2683 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2684 l_log_msg := ' : Exception at update_amd_dist_on_conf_copy: '|| SQLERRM;
2685 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2686 END IF;
2687 RAISE;
2688 END update_amd_dist_on_conf_copy;
2689
2690
2691
2692 PROCEDURE merge_amendment_distribution(p_confirmed_id IN NUMBER, p_revision_num IN NUMBER,
2693 line_map g_line_id_map)
2694 IS
2695 v_progress VARCHAR2(10);
2696 l_procedure_name VARCHAR2(100) := 'merge_amendment_distribution';
2697 l_log_msg VARCHAR2(2000);
2698
2699 l_distribution_ids Dbms_Sql.number_table;
2700 l_conformed_dist_ids Dbms_Sql.number_table;
2701 l_req_line_id Dbms_Sql.number_table;
2702 l_info_line_id Dbms_Sql.number_table;
2703 l_new_dist_id NUMBER;
2704
2705 l_info_line_temp_id NUMBER;
2706
2707 BEGIN
2708 v_progress := '000';
2709 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2710 l_log_msg := v_progress||': Inside procedure '||l_procedure_name;
2711 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2712 l_log_msg := 'p_confirmed_id : '||p_confirmed_id||', p_revision_num : '||p_revision_num;
2713 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2714 END IF;
2715
2716 SELECT distribution_id, requisition_line_id, conformed_dist_id, info_line_id
2717 BULK COLLECT INTO l_distribution_ids, l_req_line_id, l_conformed_dist_ids, l_info_line_id
2718 FROM po_req_distributions_all
2719 WHERE requisition_line_id IN
2720 (SELECT requisition_line_id
2721 FROM po_requisition_lines_all prla,
2722 po_requisition_headers_all prha
2723 WHERE prha.conformed_header_id = p_confirmed_id
2724 AND prha.revision_num = p_revision_num
2725 AND prha.requisition_header_id = prla.requisition_header_id);
2726
2727 FOR i IN 1..l_distribution_ids.Count LOOP
2728 IF l_conformed_dist_ids(i) IS NOT NULL THEN
2729 --call the update statement
2730 update_amd_dist_on_conf_copy(l_distribution_ids(i), l_conformed_dist_ids(i));
2731 ELSE
2732 l_info_line_temp_id := l_info_line_id(i);
2733 IF l_info_line_temp_id IS NOT NULL THEN
2734 l_info_line_temp_id := line_map(l_info_line_id(i));
2735 END IF;
2736 create_amd_dist_on_conf_copy(l_distribution_ids(i), line_map(l_req_line_id(i)),
2737 l_info_line_temp_id,l_new_dist_id);
2738 END IF;
2739 END LOOP;
2740
2741
2742 EXCEPTION
2743 WHEN OTHERS THEN
2744 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2745 l_log_msg := v_progress||' : Exception at merge_amendment_distribution: '|| SQLERRM;
2746 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2747 END IF;
2748 RAISE;
2749 END merge_amendment_distribution;
2750
2751
2752
2753 PROCEDURE update_amd_line_on_conf_copy (p_from_line_id IN NUMBER,
2754 p_to_line_id IN NUMBER,
2755 p_clm_base_line_num IN NUMBER DEFAULT NULL)
2756 IS
2757 l_procedure_name VARCHAR2(100) := 'update_amd_line_on_conf_copy';
2758 l_log_msg VARCHAR2(2000);
2759
2760 BEGIN
2761 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2762 l_log_msg := ': Inside procedure '||l_procedure_name;
2763 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2764 END IF;
2765
2766 MERGE
2767 INTO po_requisition_lines_all target
2768 USING
2769 (SELECT * FROM po_requisition_lines_all
2770 WHERE requisition_line_id = p_from_line_id) source
2771 ON ( target.requisition_line_id = p_to_line_id
2772 AND source.conformed_line_id = target.requisition_line_id
2773 )
2774 WHEN MATCHED
2775 THEN
2776 UPDATE
2777 SET target.DELIVER_TO_LOCATION_ID = source.DELIVER_TO_LOCATION_ID,
2778 target.TO_PERSON_ID = source.TO_PERSON_ID,
2779 target.ITEM_DESCRIPTION = source.ITEM_DESCRIPTION,
2780 target.CATEGORY_ID = source.CATEGORY_ID,
2781 target.UNIT_MEAS_LOOKUP_CODE = source.UNIT_MEAS_LOOKUP_CODE,
2782 target.UNIT_PRICE = source.UNIT_PRICE,
2783 target.QUANTITY = source.QUANTITY,
2784 target.ITEM_ID = source.ITEM_ID,
2785 target.ITEM_REVISION = source.ITEM_REVISION,
2786 target.SUGGESTED_BUYER_ID = source.SUGGESTED_BUYER_ID,
2787 target.NEED_BY_DATE = source.NEED_BY_DATE,
2788 target.JUSTIFICATION = source.JUSTIFICATION,
2789 target.NOTE_TO_AGENT = source.NOTE_TO_AGENT,
2790 target.NOTE_TO_RECEIVER = source.NOTE_TO_RECEIVER,
2791 target.CURRENCY_CODE = source.CURRENCY_CODE,
2792 target.RATE_TYPE = source.RATE_TYPE,
2793 target.RATE_DATE = source.RATE_DATE,
2794 target.RATE = source.RATE,
2795 target.CURRENCY_UNIT_PRICE = source.CURRENCY_UNIT_PRICE,
2796 target.SUGGESTED_VENDOR_NAME = source.SUGGESTED_VENDOR_NAME,
2797 target.SUGGESTED_VENDOR_LOCATION = source.SUGGESTED_VENDOR_LOCATION,
2798 target.SUGGESTED_VENDOR_CONTACT = source.SUGGESTED_VENDOR_CONTACT,
2799 target.SUGGESTED_VENDOR_PHONE = source.SUGGESTED_VENDOR_PHONE,
2800 target.SUGGESTED_VENDOR_PRODUCT_CODE = source.SUGGESTED_VENDOR_PRODUCT_CODE,
2801 target.HAZARD_CLASS_ID = source.HAZARD_CLASS_ID,
2802 target.CANCEL_FLAG = source.CANCEL_FLAG,
2803 target.DESTINATION_TYPE_CODE = source.DESTINATION_TYPE_CODE,
2804 target.DESTINATION_ORGANIZATION_ID = source.DESTINATION_ORGANIZATION_ID,
2805 target.DESTINATION_SUBINVENTORY = source.DESTINATION_SUBINVENTORY,
2806 target.CLOSED_CODE = source.CLOSED_CODE,
2807 target.VENDOR_ID = source.VENDOR_ID,
2808 target.VENDOR_SITE_ID = source.VENDOR_SITE_ID,
2809 target.VENDOR_CONTACT_ID = source.VENDOR_CONTACT_ID,
2810 target.USSGL_TRANSACTION_CODE = source.USSGL_TRANSACTION_CODE,
2811 target.MANUFACTURER_NAME = source.MANUFACTURER_NAME,
2812 target.MANUFACTURER_PART_NUMBER = source.MANUFACTURER_PART_NUMBER,
2813 target.REQUESTER_EMAIL = source.REQUESTER_EMAIL,
2814 target.REQUESTER_FAX = source.REQUESTER_FAX,
2815 target.REQUESTER_PHONE = source.REQUESTER_PHONE,
2816 target.UNSPSC_CODE = source.UNSPSC_CODE,
2817 target.SUPPLIER_DUNS = source.SUPPLIER_DUNS,
2818 target.AMOUNT = source.AMOUNT,
2819 target.CURRENCY_AMOUNT = source.CURRENCY_AMOUNT,
2820 target.JOB_LONG_DESCRIPTION = source.JOB_LONG_DESCRIPTION,
2821 target.SUGGESTED_VENDOR_CONTACT_FAX = source.SUGGESTED_VENDOR_CONTACT_FAX,
2822 target.SUGGESTED_VENDOR_CONTACT_EMAIL = source.SUGGESTED_VENDOR_CONTACT_EMAIL,
2823 target.CANDIDATE_FIRST_NAME = source.CANDIDATE_FIRST_NAME,
2824 target.CANDIDATE_LAST_NAME = source.CANDIDATE_LAST_NAME,
2825 target.ASSIGNMENT_START_DATE = source.ASSIGNMENT_START_DATE,
2826 target.AMENDMENT_TYPE = source.AMENDMENT_TYPE,
2827 target.AMENDMENT_STATUS = source.AMENDMENT_STATUS,
2828 target.CONTRACT_TYPE = source.CONTRACT_TYPE,
2829 target.COST_CONSTRAINT = source.COST_CONSTRAINT,
2830 target.CLM_PERIOD_PERF_START_DATE = source.CLM_PERIOD_PERF_START_DATE,
2831 target.CLM_PERIOD_PERF_END_DATE = source.CLM_PERIOD_PERF_END_DATE,
2832 target.CLM_OPTION_EXERCISED = source.CLM_OPTION_EXERCISED,
2833 target.CLM_OPTION_FROM_DATE = source.CLM_OPTION_FROM_DATE,
2834 target.CLM_OPTION_TO_DATE = source.CLM_OPTION_TO_DATE,
2835 target.CLM_FUNDED_FLAG = source.CLM_FUNDED_FLAG,
2836 target.CLM_OPTION_INDICATOR = source.CLM_OPTION_INDICATOR,
2837 target.FUND_SOURCE_NOT_KNOWN = source.FUND_SOURCE_NOT_KNOWN,
2838 target.clm_base_line_num = p_clm_base_line_num,
2839 target.clm_option_num = source.clm_option_num,
2840 target.CLM_MIPR_OBLIGATION_TYPE = source.CLM_MIPR_OBLIGATION_TYPE;
2841
2842 EXCEPTION
2843 WHEN OTHERS THEN
2844 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2845 l_log_msg := ' : Exception at update_amd_line_on_conf_copy : '|| SQLERRM;
2846 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2847 END IF;
2848 RAISE;
2849
2850 END update_amd_line_on_conf_copy;
2851
2852
2853
2854 PROCEDURE create_amd_line_on_conf_copy (p_from_line_id IN NUMBER,
2855 p_to_req_hdr_id IN NUMBER,
2856 p_group_line_id IN NUMBER,
2857 p_clm_base_line_num IN NUMBER,
2858 x_new_line_id OUT NOCOPY number)
2859 IS
2860 l_procedure_name VARCHAR2(100) := 'create_amd_line_on_conf_copy';
2861 l_log_msg VARCHAR2(2000);
2862
2863
2864 BEGIN
2865 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
2866 l_log_msg := ': Inside procedure '||l_procedure_name;
2867 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
2868 END IF;
2869
2870 SELECT po_requisition_lines_s.NEXTVAL
2871 INTO x_new_line_id
2872 FROM dual;
2873
2874 INSERT INTO po_requisition_lines_all
2875 (requisition_line_id,
2876 requisition_header_id,
2877 line_num,
2878 line_type_id,
2879 category_id,
2880 item_description,
2881 unit_meas_lookup_code,
2882 unit_price,
2883 quantity,
2884 deliver_to_location_id,
2885 to_person_id,
2886 last_update_date,
2887 last_updated_by,
2888 source_type_code,
2889 last_update_login,
2890 creation_date,
2891 created_by,
2892 item_id,
2893 item_revision,
2894 quantity_delivered,
2895 suggested_buyer_id,
2896 encumbered_flag,
2897 rfq_required_flag,
2898 need_by_date,
2899 line_location_id,
2900 modified_by_agent_flag,
2901 parent_req_line_id,
2902 justification,
2903 note_to_agent,
2904 note_to_receiver,
2905 purchasing_agent_id,
2906 document_type_code,
2907 blanket_po_header_id,
2908 blanket_po_line_num,
2909 currency_code,
2910 rate_type,
2911 rate_date,
2912 rate,
2913 currency_unit_price,
2914 suggested_vendor_name,
2915 suggested_vendor_location,
2916 suggested_vendor_contact,
2917 suggested_vendor_phone,
2918 suggested_vendor_product_code,
2919 un_number_id,
2920 hazard_class_id,
2921 must_use_sugg_vendor_flag,
2922 reference_num,
2923 on_rfq_flag,
2924 urgent_flag,
2925 cancel_flag,
2926 source_organization_id,
2927 source_subinventory,
2928 destination_type_code,
2929 destination_organization_id,
2930 destination_subinventory,
2931 quantity_cancelled,
2932 cancel_date,
2933 cancel_reason,
2934 closed_code,
2935 agent_return_note,
2936 changed_after_research_flag,
2937 vendor_id,
2938 vendor_site_id,
2939 vendor_contact_id,
2940 research_agent_id,
2941 on_line_flag,
2942 wip_entity_id,
2943 wip_line_id,
2944 wip_repetitive_schedule_id,
2945 wip_operation_seq_num,
2946 wip_resource_seq_num,
2947 attribute_category,
2948 destination_context,
2949 inventory_source_context,
2950 vendor_source_context,
2951 attribute1,
2952 attribute2,
2953 attribute3,
2954 attribute4,
2955 attribute5,
2956 attribute6,
2957 attribute7,
2958 attribute8,
2959 attribute9,
2960 attribute10,
2961 attribute11,
2962 attribute12,
2963 attribute13,
2964 attribute14,
2965 attribute15,
2966 bom_resource_id,
2967 request_id,
2968 program_application_id,
2969 program_id,
2970 program_update_date,
2971 ussgl_transaction_code,
2972 government_context,
2973 closed_reason,
2974 closed_date,
2975 transaction_reason_code,
2976 quantity_received,
2977 source_req_line_id,
2978 org_id,
2979 global_attribute1,
2980 global_attribute2,
2981 global_attribute3,
2982 global_attribute4,
2983 global_attribute5,
2984 global_attribute6,
2985 global_attribute7,
2986 global_attribute8,
2987 global_attribute9,
2988 global_attribute10,
2989 global_attribute11,
2990 global_attribute12,
2991 global_attribute13,
2992 global_attribute14,
2993 global_attribute15,
2994 global_attribute16,
2995 global_attribute17,
2996 global_attribute18,
2997 global_attribute19,
2998 global_attribute20,
2999 global_attribute_category,
3000 kanban_card_id,
3001 catalog_type,
3002 catalog_source,
3003 manufacturer_id,
3004 manufacturer_name,
3005 manufacturer_part_number,
3006 requester_email,
3007 requester_fax,
3008 requester_phone,
3009 unspsc_code ,
3010 other_category_code,
3011 supplier_duns,
3012 tax_status_indicator,
3013 pcard_flag,
3014 new_supplier_flag,
3015 auto_receive_flag,
3016 tax_user_override_flag,
3017 tax_code_id,
3018 note_to_vendor,
3019 oke_contract_version_id,
3020 oke_contract_header_id,
3021 item_source_id,
3022 supplier_ref_number,
3023 secondary_unit_of_measure,
3024 secondary_quantity,
3025 preferred_grade,
3026 secondary_quantity_received,
3027 secondary_quantity_cancelled,
3028 vmi_flag,
3029 auction_header_id,
3030 auction_display_number,
3031 auction_line_number,
3032 reqs_in_pool_flag,
3033 bid_number,
3034 bid_line_number,
3035 noncat_template_id,
3036 suggested_vendor_contact_fax,
3037 suggested_vendor_contact_email,
3038 amount,
3039 currency_amount,
3040 labor_req_line_id,
3041 job_id,
3042 job_long_description,
3043 contractor_status,
3044 contact_information,
3045 suggested_supplier_flag,
3046 candidate_screening_reqd_flag,
3047 assignment_end_date,
3048 overtime_allowed_flag,
3049 contractor_requisition_flag,
3050 drop_ship_flag ,
3051 candidate_first_name,
3052 candidate_last_name,
3053 assignment_start_date,
3054 order_type_lookup_code,
3055 purchase_basis,
3056 matching_basis ,
3057 negotiated_by_preparer_flag,
3058 ship_method,
3059 estimated_pickup_date,
3060 supplier_notified_for_cancel,
3061 base_unit_price,
3062 at_sourcing_flag,
3063 tax_attribute_update_code,
3064 tax_name,
3065 line_num_display,
3066 group_line_id,
3067 clm_info_flag,
3068 clm_option_indicator,
3069 clm_option_num,
3070 clm_option_from_date,
3071 clm_option_to_date,
3072 clm_funded_flag,
3073 clm_base_line_num,
3074 uda_template_id,
3075 amendment_type,
3076 amendment_status,
3077 cost_constraint,
3078 contract_type,
3079 clm_period_perf_end_date,
3080 clm_period_perf_start_date,
3081 clm_extended_item_description,
3082 clm_option_exercised,
3083 is_line_num_display_modified,
3084 fund_source_not_known,
3085 clm_mipr_obligation_type )
3086 SELECT
3087 x_new_line_id,
3088 p_to_req_hdr_id,
3089 source.line_num,
3090 source.line_type_id,
3091 source.category_id,
3092 source.item_description,
3093 source.unit_meas_lookup_code,
3094 source.unit_price,
3095 source.quantity,
3096 source.deliver_to_location_id,
3097 source.to_person_id,
3098 source.last_update_date,
3099 source.last_updated_by,
3100 source.source_type_code,
3101 source.last_update_login,
3102 source.creation_date,
3103 source.created_by,
3104 source.item_id,
3105 source.item_revision,
3106 source.quantity_delivered,
3107 source.suggested_buyer_id,
3108 source.encumbered_flag,
3109 source.rfq_required_flag,
3110 source.need_by_date,
3111 source.line_location_id,
3112 source.modified_by_agent_flag,
3113 source.parent_req_line_id,
3114 source.justification,
3115 source.note_to_agent,
3116 source.note_to_receiver,
3117 source.purchasing_agent_id,
3118 source.document_type_code,
3119 source.blanket_po_header_id,
3120 source.blanket_po_line_num,
3121 source.currency_code,
3122 source.rate_type,
3123 source.rate_date,
3124 source.rate,
3125 source.currency_unit_price,
3126 source.suggested_vendor_name,
3127 source.suggested_vendor_location,
3128 source.suggested_vendor_contact,
3129 source.suggested_vendor_phone,
3130 source.suggested_vendor_product_code,
3131 source.un_number_id,
3132 source.hazard_class_id,
3133 source.must_use_sugg_vendor_flag,
3134 source.reference_num,
3135 source.on_rfq_flag,
3136 source.urgent_flag,
3137 source.cancel_flag,
3138 source.source_organization_id,
3139 source.source_subinventory,
3140 source.destination_type_code,
3141 source.destination_organization_id,
3142 source.destination_subinventory,
3143 source.quantity_cancelled,
3144 source.cancel_date,
3145 source.cancel_reason,
3146 source.closed_code,
3147 source.agent_return_note,
3148 source.changed_after_research_flag,
3149 source.vendor_id,
3150 source.vendor_site_id,
3151 source.vendor_contact_id,
3152 source.research_agent_id,
3153 source.on_line_flag,
3154 source.wip_entity_id,
3155 source.wip_line_id,
3156 source.wip_repetitive_schedule_id,
3157 source.wip_operation_seq_num,
3158 source.wip_resource_seq_num,
3159 source.attribute_category,
3160 source.destination_context,
3161 source.inventory_source_context,
3162 source.vendor_source_context,
3163 source.attribute1,
3164 source.attribute2,
3165 source.attribute3,
3166 source.attribute4,
3167 source.attribute5,
3168 source.attribute6,
3169 source.attribute7,
3170 source.attribute8,
3171 source.attribute9,
3172 source.attribute10,
3173 source.attribute11,
3174 source.attribute12,
3175 source.attribute13,
3176 source.attribute14,
3177 source.attribute15,
3178 source.bom_resource_id,
3179 source.request_id,
3180 source.program_application_id,
3181 source.program_id,
3182 source.program_update_date,
3183 source.ussgl_transaction_code,
3184 source.government_context,
3185 source.closed_reason,
3186 source.closed_date,
3187 source.transaction_reason_code,
3188 source.quantity_received,
3189 source.source_req_line_id,
3190 source.org_id,
3191 source.global_attribute1,
3192 source.global_attribute2,
3193 source.global_attribute3,
3194 source.global_attribute4,
3195 source.global_attribute5,
3196 source.global_attribute6,
3197 source.global_attribute7,
3198 source.global_attribute8,
3199 source.global_attribute9,
3200 source.global_attribute10,
3201 source.global_attribute11,
3202 source.global_attribute12,
3203 source.global_attribute13,
3204 source.global_attribute14,
3205 source.global_attribute15,
3206 source.global_attribute16,
3207 source.global_attribute17,
3208 source.global_attribute18,
3209 source.global_attribute19,
3210 source.global_attribute20,
3211 source.global_attribute_category,
3212 source.kanban_card_id,
3213 source.catalog_type,
3214 source.catalog_source,
3215 source.manufacturer_id,
3216 source.manufacturer_name,
3217 source.manufacturer_part_number,
3218 source.requester_email,
3219 source.requester_fax,
3220 source.requester_phone,
3221 source.unspsc_code ,
3222 source.other_category_code,
3223 source.supplier_duns,
3224 source.tax_status_indicator,
3225 source.pcard_flag,
3226 source.new_supplier_flag,
3227 source.auto_receive_flag,
3228 source.tax_user_override_flag,
3229 source.tax_code_id,
3230 source.note_to_vendor,
3231 source.oke_contract_version_id,
3232 source.oke_contract_header_id,
3233 source.item_source_id,
3234 source.supplier_ref_number,
3235 source.secondary_unit_of_measure,
3236 source.secondary_quantity,
3237 source.preferred_grade,
3238 source.secondary_quantity_received,
3239 source.secondary_quantity_cancelled,
3240 source.vmi_flag,
3241 source.auction_header_id,
3242 source.auction_display_number,
3243 source.auction_line_number,
3244 'Y',
3245 source.bid_number,
3246 source.bid_line_number,
3247 source.noncat_template_id,
3248 source.suggested_vendor_contact_fax,
3249 source.suggested_vendor_contact_email,
3250 source.amount,
3251 source.currency_amount,
3252 source.labor_req_line_id,
3253 source.job_id,
3254 source.job_long_description,
3255 source.contractor_status,
3256 source.contact_information,
3257 source.suggested_supplier_flag,
3258 source.candidate_screening_reqd_flag,
3259 source.assignment_end_date,
3260 source.overtime_allowed_flag,
3261 source.contractor_requisition_flag,
3262 source.drop_ship_flag ,
3263 source.candidate_first_name,
3264 source.candidate_last_name,
3265 source.assignment_start_date,
3266 source.order_type_lookup_code,
3267 source.purchase_basis,
3268 source.matching_basis ,
3269 source.negotiated_by_preparer_flag,
3270 source.ship_method,
3271 source.estimated_pickup_date,
3272 source.supplier_notified_for_cancel,
3273 source.base_unit_price,
3274 source.at_sourcing_flag,
3275 source.tax_attribute_update_code,
3276 source.tax_name,
3277 source.line_num_display,
3278 p_group_line_id,
3279 source.clm_info_flag,
3280 source.clm_option_indicator,
3281 source.clm_option_num,
3282 source.clm_option_from_date,
3283 source.clm_option_to_date,
3284 source.clm_funded_flag,
3285 p_clm_base_line_num,
3286 source.uda_template_id,
3287 source.amendment_type,
3288 source.amendment_status,
3289 source.cost_constraint,
3290 source.contract_type,
3291 source.clm_period_perf_end_date,
3292 source.clm_period_perf_start_date,
3293 source.clm_extended_item_description,
3294 source.clm_option_exercised,
3295 source.is_line_num_display_modified,
3296 source.fund_source_not_known,
3297 source.clm_mipr_obligation_type
3298 FROM po_requisition_lines_all source
3299 WHERE source.requisition_line_id = p_from_line_id;
3300
3301 EXCEPTION
3302 WHEN OTHERS THEN
3303 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3304 l_log_msg := ' : Exception at create_amd_line_on_conf_copy : '|| SQLERRM;
3305 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3306 END IF;
3307 RAISE;
3308
3309 END create_amd_line_on_conf_copy;
3310
3311
3312 PROCEDURE update_oneTimeL_and_Atchmnt(p_from_line_id IN NUMBER,
3313 p_to_line_id IN NUMBER,
3314 p_confirmed_id IN NUMBER)
3315 IS
3316 v_progress VARCHAR2(10);
3317 l_procedure_name VARCHAR2(100) := 'update_oneTimeL_and_Atchmnt';
3318 l_log_msg VARCHAR2(2000);
3319
3320 BEGIN
3321 v_progress := '000';
3322 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3323 l_log_msg := v_progress||': Inside procedure '||l_procedure_name;
3324 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3325 END IF;
3326
3327 /* Merging one time location - start */
3328
3329 DELETE FROM por_item_attribute_values
3330 WHERE requisition_line_id = p_to_line_id;
3331
3332 v_progress := '002';
3333
3334 INSERT INTO por_item_attribute_values(
3335 item_type,
3336 requisition_header_id,
3337 requisition_line_id,
3338 attribute1,
3339 attribute2,
3340 attribute3,
3341 attribute4,
3342 attribute5,
3343 attribute6,
3344 attribute7,
3345 attribute8,
3346 attribute9,
3347 attribute10,
3348 attribute11,
3349 attribute12,
3350 attribute13,
3351 attribute14,
3352 attribute15,
3353 org_id,
3354 created_by,
3355 creation_date,
3356 last_updated_by,
3357 last_update_date,
3358 last_update_login)
3359 SELECT piav.item_type,
3360 p_confirmed_id,
3361 p_to_line_id,
3362 piav.attribute1,
3363 piav.attribute2,
3364 piav.attribute3,
3365 piav.attribute4,
3366 piav.attribute5,
3367 piav.attribute6,
3368 piav.attribute7,
3369 piav.attribute8,
3370 piav.attribute9,
3371 piav.attribute10,
3372 piav.attribute11,
3373 piav.attribute12,
3374 piav.attribute13,
3375 piav.attribute14,
3376 piav.attribute15,
3377 piav.org_id,
3378 piav.created_by,
3379 piav.creation_date,
3380 piav.last_updated_by,
3381 piav.last_update_date,
3382 piav.last_update_login
3383 FROM por_item_attribute_values piav
3384 WHERE piav.requisition_line_id = p_from_line_id;
3385
3386 v_progress := '003';
3387
3388 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3389 l_log_msg := v_progress||' : After merging one time location for line';
3390 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3391 END IF;
3392
3393 /* Merging one time location - end */
3394
3395 /* Merging attachments - start */
3396 v_progress := '004';
3397
3398 v_progress := '005';
3399 fnd_attached_documents2_pkg.delete_attachments('REQ_LINES',
3400 ''||p_to_line_id,
3401 '',
3402 '',
3403 '',
3404 '',
3405 'Y',
3406 '');
3407
3408 v_progress := '006';
3409 fnd_attached_documents2_pkg.copy_attachments('REQ_LINES',
3410 ''||p_from_line_id,
3411 '',
3412 '',
3413 '',
3414 '',
3415 'REQ_LINES',
3416 ''||p_to_line_id,
3417 '',
3418 '',
3419 '',
3420 '',
3421 fnd_global.user_id,
3422 fnd_global.login_id,
3423 '',
3424 '',
3425 '');
3426
3427
3428 v_progress := '005';
3429 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3430 l_log_msg := v_progress||' : After merging attachments for Lines';
3431 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3432 END IF;
3433 /* Merging attachments - end */
3434
3435 EXCEPTION
3436 WHEN OTHERS THEN
3437 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3438 l_log_msg := ' : Exception at update_oneTimeL_and_Atchmnt : '|| SQLERRM;
3439 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3440 END IF;
3441
3442 END update_oneTimeL_and_Atchmnt;
3443
3444
3445 PROCEDURE merge_amendment_line(p_confirmed_id IN NUMBER, p_revision_num IN NUMBER)
3446 IS
3447 v_progress VARCHAR2(10);
3448 l_procedure_name VARCHAR2(100) := 'merge_amendment_line';
3449 l_log_msg VARCHAR2(2000);
3450
3451 line_map g_line_id_map;
3452
3453 l_line_ids Dbms_Sql.number_table;
3454 l_conformed_line_ids Dbms_Sql.number_table;
3455 l_clm_base_line_num Dbms_Sql.number_table;
3456 l_group_line_id Dbms_Sql.number_table;
3457 l_req_header_id po_requisition_headers_all.requisition_header_id%TYPE;
3458 l_new_line_id NUMBER;
3459
3460 BEGIN
3461
3462 v_progress := '000';
3463 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3464 l_log_msg := v_progress||': Inside procedure '||l_procedure_name;
3465 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3466 l_log_msg := 'p_confirmed_id : '||p_confirmed_id||', p_revision_num : '||p_revision_num;
3467 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3468 END IF;
3469
3470 SELECT requisition_header_id
3471 INTO l_req_header_id
3472 FROM po_requisition_headers_all
3473 WHERE conformed_header_id = p_confirmed_id
3474 AND revision_num = p_revision_num;
3475
3476 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3477 l_log_msg := v_progress||': req_header_id of the amendment record : '||l_req_header_id;
3478 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3479 END IF;
3480
3481 /*
3482 For merging lines, we have to do at line by line basis.
3483 1)Pick the lines which are CLIN and are not the option CLIN
3484 2)Pick the Option CLIN and carry out the merge task
3485 3)Pick the SLIN which are not the option SLIN.
3486 4)Last pick the Option SLIN
3487 */
3488
3489 SELECT requisition_line_id , conformed_line_id
3490 BULK COLLECT INTO l_line_ids , l_conformed_line_ids
3491 FROM po_requisition_lines_all
3492 WHERE requisition_header_id = l_req_header_id
3493 AND group_line_id IS NULL
3494 AND clm_base_line_num IS NULL;
3495
3496 FOR i IN 1..l_line_ids.Count LOOP
3497 IF l_conformed_line_ids(i) IS NOT NULL THEN
3498
3499 line_map(''||l_line_ids(i)) := l_conformed_line_ids(i);
3500 --call the api to update the corresponding record
3501 update_amd_line_on_conf_copy(l_line_ids(i),l_conformed_line_ids(i));
3502 update_oneTimeL_and_Atchmnt(l_line_ids(i),l_conformed_line_ids(i),p_confirmed_id);
3503
3504 ELSE
3505 --insert this new CLIN
3506 create_amd_line_on_conf_copy(l_line_ids(i),p_confirmed_id,NULL,NULL,l_new_line_id);
3507 line_map(''||l_line_ids(i)) := l_new_line_id;
3508 update_oneTimeL_and_Atchmnt(l_line_ids(i),l_new_line_id,p_confirmed_id);
3509
3510 END IF;
3511 END LOOP;
3512
3513 l_line_ids.DELETE;
3514 l_conformed_line_ids.DELETE;
3515
3516 v_progress := '001';
3517 --Now pick the Option CLINs
3518 SELECT requisition_line_id , conformed_line_id, clm_base_line_num
3519 BULK COLLECT INTO l_line_ids , l_conformed_line_ids, l_clm_base_line_num
3520 FROM po_requisition_lines_all
3521 WHERE requisition_header_id = l_req_header_id
3522 AND group_line_id IS NULL
3523 AND clm_base_line_num IS NOT NULL;
3524
3525 FOR i IN 1..l_line_ids.Count LOOP
3526 IF l_conformed_line_ids(i) IS NOT NULL THEN
3527
3528 line_map(''||l_line_ids(i)) := l_conformed_line_ids(i);
3529 --call the api to update the corresponding record
3530 update_amd_line_on_conf_copy(l_line_ids(i),l_conformed_line_ids(i), line_map(l_clm_base_line_num(i)));
3531 update_oneTimeL_and_Atchmnt(l_line_ids(i),l_conformed_line_ids(i),p_confirmed_id);
3532
3533 ELSE
3534 --insert this new CLIN
3535 create_amd_line_on_conf_copy(l_line_ids(i),p_confirmed_id,NULL,
3536 line_map(l_clm_base_line_num(i)),l_new_line_id);
3537 line_map(''||l_line_ids(i)) := l_new_line_id;
3538 update_oneTimeL_and_Atchmnt(l_line_ids(i),l_new_line_id,p_confirmed_id);
3539
3540 END IF;
3541 END LOOP;
3542
3543 l_line_ids.DELETE;
3544 l_conformed_line_ids.DELETE;
3545 l_clm_base_line_num.DELETE;
3546
3547 v_progress := '002';
3548 --Now pick the SLINs which are not option
3549 SELECT requisition_line_id , conformed_line_id, group_line_id
3550 BULK COLLECT INTO l_line_ids , l_conformed_line_ids, l_group_line_id
3551 FROM po_requisition_lines_all
3552 WHERE requisition_header_id = l_req_header_id
3553 AND group_line_id IS NOT NULL
3554 AND clm_base_line_num IS NULL;
3555
3556 FOR i IN 1..l_line_ids.Count LOOP
3557 IF l_conformed_line_ids(i) IS NOT NULL THEN
3558
3559 line_map(''||l_line_ids(i)) := l_conformed_line_ids(i);
3560 --call the api to update the corresponding record
3561 update_amd_line_on_conf_copy(l_line_ids(i),l_conformed_line_ids(i));
3562 update_oneTimeL_and_Atchmnt(l_line_ids(i),l_conformed_line_ids(i),p_confirmed_id);
3563
3564 ELSE
3565 --insert this new CLIN
3566 create_amd_line_on_conf_copy(l_line_ids(i),p_confirmed_id,
3567 line_map(l_group_line_id(i)),
3568 NULL ,l_new_line_id);
3569 line_map(''||l_line_ids(i)) := l_new_line_id;
3570 update_oneTimeL_and_Atchmnt(l_line_ids(i),l_new_line_id,p_confirmed_id);
3571
3572 END IF;
3573 END LOOP;
3574
3575
3576 l_line_ids.DELETE;
3577 l_conformed_line_ids.DELETE;
3578 l_group_line_id.DELETE;
3579
3580
3581 v_progress := '003';
3582 --Now pick the SLINs which are also option
3583 SELECT requisition_line_id , conformed_line_id, group_line_id, clm_base_line_num
3584 BULK COLLECT INTO l_line_ids , l_conformed_line_ids, l_group_line_id, l_clm_base_line_num
3585 FROM po_requisition_lines_all
3586 WHERE requisition_header_id = l_req_header_id
3587 AND group_line_id IS NOT NULL
3588 AND clm_base_line_num IS NOT NULL;
3589
3590
3591 FOR i IN 1..l_line_ids.Count LOOP
3592 IF l_conformed_line_ids(i) IS NOT NULL THEN
3593
3594 line_map(''||l_line_ids(i)) := l_conformed_line_ids(i);
3595 --call the api to update the corresponding record
3596 update_amd_line_on_conf_copy(l_line_ids(i),l_conformed_line_ids(i),line_map(l_clm_base_line_num(i)));
3597 update_oneTimeL_and_Atchmnt(l_line_ids(i),l_conformed_line_ids(i),p_confirmed_id);
3598
3599 ELSE
3600 --insert this new CLIN
3601 create_amd_line_on_conf_copy(l_line_ids(i),p_confirmed_id,
3602 line_map(l_group_line_id(i)),
3603 line_map(l_clm_base_line_num(i)),
3604 l_new_line_id);
3605 line_map(''||l_line_ids(i)) := l_new_line_id;
3606 update_oneTimeL_and_Atchmnt(l_line_ids(i),l_new_line_id,p_confirmed_id);
3607
3608 END IF;
3609 END LOOP;
3610
3611 merge_amendment_distribution(p_confirmed_id,p_revision_num, line_map);
3612
3613 EXCEPTION
3614 WHEN OTHERS THEN
3615 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3616 l_log_msg := v_progress||' : Exception at merge_amendment_line: '|| SQLERRM;
3617 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3618 END IF;
3619 RAISE;
3620 END merge_amendment_line;
3621
3622
3623 PROCEDURE merge_action_history(p_confirmed_id IN NUMBER, p_revision_num IN NUMBER)
3624 IS
3625
3626 v_progress VARCHAR2(10);
3627 l_procedure_name VARCHAR2(100) := 'merge_action_history';
3628 l_log_msg VARCHAR2(2000);
3629
3630 max_seq NUMBER;
3631 BEGIN
3632
3633 v_progress:='000';
3634 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3635 l_log_msg := v_progress||': Inside procedure '||l_procedure_name;
3636 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3637 l_log_msg := 'p_confirmed_id : '||p_confirmed_id||', p_revision_num : '||p_revision_num;
3638 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3639 END IF;
3640
3641 SELECT Max(sequence_num)
3642 INTO max_seq
3643 FROM po_action_history
3644 WHERE object_id = (SELECT requisition_header_id
3645 FROM po_requisition_headers_all
3646 WHERE conformed_header_id = p_confirmed_id
3647 AND revision_num =p_revision_num)
3648 AND object_type_code = 'REQUISITION';
3649
3650 v_progress:='001';
3651
3652 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3653 l_log_msg := v_progress||' At procedure merge_action_history: max_seq: '|| max_seq;
3654 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3655 END IF;
3656
3657 INSERT INTO po_action_history(
3658 object_id,
3659 object_type_code,
3660 object_sub_type_code,
3661 sequence_num,
3662 last_update_date,
3663 last_updated_by,
3664 creation_date,
3665 created_by,
3666 action_code,
3667 action_date,
3668 employee_id,
3669 approval_path_id,
3670 note,
3671 object_revision_num,
3672 offline_code,
3673 last_update_login,
3674 request_id,
3675 program_application_id,
3676 program_id,
3677 program_update_date,
3678 program_date,
3679 approval_group_id)
3680 SELECT p_confirmed_id,
3681 object_type_code,
3682 object_sub_type_code,
3683 max_seq+sequence_num+1,
3684 last_update_date,
3685 last_updated_by,
3686 creation_date,
3687 created_by,
3688 Decode(action_code,'SUBMIT','SUBMIT CHANGE',action_code),
3689 action_date,
3690 employee_id,
3691 approval_path_id,
3692 note,
3693 p_revision_num,
3694 offline_code,
3695 last_update_login,
3696 request_id,
3697 program_application_id,
3698 program_id,
3699 program_update_date,
3700 program_date,
3701 approval_group_id
3702 FROM po_action_history
3703 WHERE object_id = (SELECT requisition_header_id
3704 FROM po_requisition_headers_all
3705 WHERE conformed_header_id = p_confirmed_id
3706 AND revision_num =p_revision_num)
3707 AND object_type_code = 'REQUISITION';
3708
3709 v_progress:='002';
3710 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3711 l_log_msg := v_progress||' After merging requisition action history';
3712 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3713 END IF;
3714
3715
3716 EXCEPTION
3717 WHEN OTHERS THEN
3718 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3719 l_log_msg := v_progress||' : Exception at procedure merge_action_history '|| SQLERRM;
3720 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3721 END IF;
3722 RAISE;
3723 END merge_action_history;
3724
3725
3726
3727 PROCEDURE merge_amendment(p_confirmed_id IN NUMBER, p_revision_num IN NUMBER)
3728 IS
3729
3730 v_progress VARCHAR2(10);
3731 l_procedure_name VARCHAR2(100) := 'merge_amendment';
3732 l_log_msg VARCHAR2(2000);
3733 BEGIN
3734 -- Standard start of API savepoint
3735 SAVEPOINT MERGE_AMENDMENT;
3736
3737 v_progress:='000';
3738 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3739 l_log_msg := v_progress||': Inside procedure '||l_procedure_name;
3740 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3741 l_log_msg := 'p_confirmed_id : '||p_confirmed_id||', p_revision_num : '||p_revision_num;
3742 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3743 END IF;
3744
3745 merge_amendment_header(p_confirmed_id,p_revision_num);
3746 v_progress:='001';
3747 merge_amendment_line(p_confirmed_id,p_revision_num);
3748 v_progress:='002';
3749 --distribution merge is called after the line_merge
3750 v_progress:='003';
3751 merge_action_history(p_confirmed_id,p_revision_num);
3752
3753 --Merge UDA attributes for header and lines to confirmed copy.
3754 v_progress:='004';
3755 POR_UDA_PKG.merge_amendment_uda_header(p_confirmed_id, p_revision_num);
3756 v_progress:='005';
3757 POR_UDA_PKG.merge_amendment_uda_line(p_confirmed_id, p_revision_num);
3758
3759
3760 COMMIT;
3761
3762 EXCEPTION
3763 WHEN OTHERS THEN
3764 ROLLBACK TO SAVEPOINT MERGE_AMENDMENT;
3765 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3766 l_log_msg := v_progress||' : Exception : '|| SQLERRM;
3767 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3768 END IF;
3769 RAISE;
3770 END merge_amendment;
3771
3772
3773
3774 /* --------------------------------- Create Base Copy -------------------------------------------- */
3775
3776 procedure create_base_copy( p_from_req_header_id IN number,
3777 x_to_req_header_id OUT NOCOPY number,
3778 x_return_status OUT NOCOPY VARCHAR2,
3779 x_return_msg OUT NOCOPY varchar2)
3780 IS
3781
3782 v_progress VARCHAR2(10);
3783 l_procedure_name VARCHAR2(100) := 'create_base_copy';
3784 l_log_msg VARCHAR2(2000);
3785 BEGIN
3786
3787 v_progress := '000';
3788 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3789 l_log_msg := v_progress||': Inside procedure '||l_procedure_name;
3790 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3791 l_log_msg := 'p_from_req_header_id: ' ||p_from_req_header_id;
3792 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3793 END IF;
3794
3795 -- Standard start of API savepoint
3796 SAVEPOINT CREATE_BASE_COPY;
3797
3798 v_progress := '001';
3799 x_to_req_header_id := NULL;
3800 x_return_status := FND_API.g_ret_sts_success;
3801 x_return_msg := NULL;
3802
3803 v_progress := '002';
3804 /* Call the procedure to copy the header*/
3805 copy_header(p_from_req_header_id, 0, x_to_req_header_id, x_return_status, x_return_msg);
3806
3807 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3808 l_log_msg := v_progress||' : Procedure copy_header: x_return_status: '||x_return_status ||' x_to_req_header_id: '||x_to_req_header_id ||' x_return_msg: '||x_return_msg;
3809 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3810 END IF;
3811
3812 copy_lines(p_from_req_header_id, x_to_req_header_id, x_return_status, x_return_msg);
3813
3814 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3815 l_log_msg := v_progress||' : x_return_status: '||x_return_status ||' x_to_req_header_id: '||x_to_req_header_id||' x_return_msg: '||x_return_msg;
3816 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3817 END IF;
3818
3819 v_progress := '003';
3820 --Copy Uda lines into base version.
3821 POR_UDA_PKG.copy_uda_header(p_from_req_header_id, x_to_req_header_id, x_return_status, x_return_msg);
3822
3823 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3824 l_log_msg := v_progress||' : x_return_status: '||x_return_status ||' x_to_req_header_id: '||x_to_req_header_id||' x_return_msg: '||x_return_msg;
3825 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3826 END IF;
3827
3828 v_progress := '004';
3829 POR_UDA_PKG.copy_uda_line(p_from_req_header_id, x_to_req_header_id, x_return_status, x_return_msg);
3830
3831 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3832 l_log_msg := v_progress||' : x_return_status: '||x_return_status ||' x_to_req_header_id: '||x_to_req_header_id||' x_return_msg: '||x_return_msg;
3833 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3834 END IF;
3835
3836 v_progress := '005';
3837
3838 COMMIT;
3839
3840 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3841 l_log_msg := v_progress||' : After Commit';
3842 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3843 END IF;
3844
3845
3846 EXCEPTION
3847 WHEN OTHERS THEN
3848 ROLLBACK TO SAVEPOINT CREATE_BASE_COPY;
3849
3850 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3851 l_log_msg := v_progress||' : Exception at create_base_copy: '|| SQLERRM;
3852 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3853 END IF;
3854 RAISE;
3855 END create_base_copy;
3856
3857
3858 PROCEDURE copy_header(p_from_req_header_id IN number,
3859 p_to_revision_num in number,
3860 x_to_req_header_id OUT NOCOPY number,
3861 x_return_status OUT NOCOPY VARCHAR2,
3862 x_return_msg OUT NOCOPY varchar2)
3863 IS
3864
3865 v_progress VARCHAR2(10);
3866 l_procedure_name VARCHAR2(100) := 'copy_header';
3867 l_log_msg VARCHAR2(2000);
3868 BEGIN
3869
3870 v_progress := '000';
3871 x_return_status := FND_API.g_ret_sts_success;
3872 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3873 l_log_msg := v_progress||': Inside procedure '||l_procedure_name;
3874 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3875 l_log_msg := 'p_from_req_header_id: ' ||p_from_req_header_id;
3876 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3877 END IF;
3878
3879 x_return_msg := NULL;
3880
3881 SELECT po_requisition_headers_s.NEXTVAL
3882 INTO x_to_req_header_id
3883 FROM dual;
3884
3885 v_progress := '001';
3886 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
3887 l_log_msg := v_progress||' : x_to_req_header_id: ' ||x_to_req_header_id;
3888 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
3889 END IF;
3890
3891
3892 INSERT INTO po_requisition_headers_all (
3893 requisition_header_id,
3894 preparer_id,
3895 last_update_date,
3896 last_updated_by,
3897 segment1,
3898 summary_flag,
3899 enabled_flag,
3900 segment2,
3901 segment3,
3902 segment4,
3903 segment5,
3904 start_date_active,
3905 end_date_active,
3906 last_update_login,
3907 creation_date,
3908 created_by,
3909 description,
3910 authorization_status,
3911 note_to_authorizer,
3912 type_lookup_code,
3913 transferred_to_oe_flag,
3914 attribute_category,
3915 attribute1,
3916 attribute2,
3917 attribute3,
3918 attribute4,
3919 attribute5,
3920 on_line_flag,
3921 preliminary_research_flag,
3922 research_complete_flag,
3923 preparer_finished_flag,
3924 preparer_finished_date,
3925 agent_return_flag,
3926 agent_return_note,
3927 cancel_flag,
3928 attribute6,
3929 attribute7,
3930 attribute8,
3931 attribute9,
3932 attribute10,
3933 attribute11,
3934 attribute12,
3935 attribute13,
3936 attribute14,
3937 attribute15,
3938 ussgl_transaction_code,
3939 government_context,
3940 request_id,
3941 program_application_id,
3942 program_id,
3943 program_update_date,
3944 interface_source_code,
3945 interface_source_line_id,
3946 closed_code,
3947 org_id,
3948 wf_item_type,
3949 wf_item_key,
3950 emergency_po_num,
3951 pcard_id,
3952 apps_source_code,
3953 cbc_accounting_date,
3954 change_pending_flag,
3955 active_shopping_cart_flag,
3956 contractor_status,
3957 contractor_requisition_flag,
3958 supplier_notified_flag,
3959 emergency_po_org_id,
3960 approved_date,
3961 tax_attribute_update_code,
3962 first_approver_id,
3963 first_position_id,
3964 uda_template_id,
3965 conformed_header_id,
3966 revision_num,
3967 federal_flag,
3968 amendment_type,
3969 amendment_status,
3970 clm_issuing_office,
3971 clm_cotr_office,
3972 clm_cotr_contact,
3973 clm_priority_code,
3974 suggested_award_no,
3975 clm_assist_office,
3976 clm_mipr_prepared_date,
3977 clm_mipr_ref_num,
3978 clm_mipr_type,
3979 clm_req_office,
3980 clm_mipr_acknowledged_flag,
3981 clm_assist_contact,
3982 clm_req_contact)
3983 SELECT
3984 x_to_req_header_id,
3985 preparer_id,
3986 last_update_date,
3987 last_updated_by,
3988 decode(p_to_revision_num, 0, segment1, segment1 || '-' || lpad(p_to_revision_num,3,'0')),
3989 summary_flag,
3990 enabled_flag,
3991 segment2,
3992 segment3,
3993 segment4,
3994 segment5,
3995 start_date_active,
3996 end_date_active,
3997 last_update_login,
3998 creation_date,
3999 created_by,
4000 description,
4001 authorization_status,
4002 note_to_authorizer,
4003 type_lookup_code,
4004 transferred_to_oe_flag,
4005 attribute_category,
4006 attribute1,
4007 attribute2,
4008 attribute3,
4009 attribute4,
4010 attribute5,
4011 on_line_flag,
4012 preliminary_research_flag,
4013 research_complete_flag,
4014 preparer_finished_flag,
4015 preparer_finished_date,
4016 agent_return_flag,
4017 agent_return_note,
4018 cancel_flag,
4019 attribute6,
4020 attribute7,
4021 attribute8,
4022 attribute9,
4023 attribute10,
4024 attribute11,
4025 attribute12,
4026 attribute13,
4027 attribute14,
4028 attribute15,
4029 ussgl_transaction_code,
4030 government_context,
4031 request_id,
4032 program_application_id,
4033 program_id,
4034 program_update_date,
4035 interface_source_code,
4036 interface_source_line_id,
4037 closed_code,
4038 org_id,
4039 wf_item_type,
4040 wf_item_key,
4041 emergency_po_num,
4042 pcard_id,
4043 apps_source_code,
4044 cbc_accounting_date,
4045 change_pending_flag,
4046 active_shopping_cart_flag,
4047 contractor_status,
4048 contractor_requisition_flag,
4049 supplier_notified_flag,
4050 emergency_po_org_id,
4051 approved_date,
4052 tax_attribute_update_code,
4053 first_approver_id,
4054 first_position_id,
4055 uda_template_id,
4056 p_from_req_header_id,
4057 p_to_revision_num,
4058 federal_flag,
4059 amendment_type,
4060 amendment_status,
4061 clm_issuing_office,
4062 clm_cotr_office,
4063 clm_cotr_contact,
4064 clm_priority_code,
4065 suggested_award_no,
4066 clm_assist_office,
4067 clm_mipr_prepared_date,
4068 clm_mipr_ref_num,
4069 clm_mipr_type,
4070 clm_req_office,
4071 clm_mipr_acknowledged_flag,
4072 clm_assist_contact,
4073 clm_req_contact
4074 FROM po_requisition_headers_all
4075 WHERE requisition_header_id = p_from_req_header_id;
4076
4077 v_progress := '002';
4078 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
4079 l_log_msg := v_progress||' : After insert into po_requisition_headers_all';
4080 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
4081 END IF;
4082
4083
4084 /* Copying header level attachments */
4085
4086 fnd_attached_documents2_pkg.copy_attachments('REQ_HEADERS',
4087 ''||p_from_req_header_id,
4088 '',
4089 '',
4090 '',
4091 '',
4092 'REQ_HEADERS',
4093 ''||x_to_req_header_id,
4094 '',
4095 '',
4096 '',
4097 '',
4098 fnd_global.user_id,
4099 fnd_global.login_id,
4100 '',
4101 '',
4102 '');
4103
4104 v_progress := '003';
4105 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
4106 l_log_msg := v_progress||' : After copying header level attachments';
4107 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
4108 END IF;
4109
4110 /* Copying header level attachments - end */
4111
4112 EXCEPTION
4113 WHEN OTHERS THEN
4114
4115 x_return_msg := SQLERRM;
4116 x_return_status := FND_API.g_ret_sts_error;
4117
4118 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
4119 l_log_msg := v_progress||' : Exception at copy_header: '|| SQLERRM;
4120 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
4121 END IF;
4122
4123 RAISE;
4124 END copy_header;
4125
4126
4127
4128
4129
4130
4131 PROCEDURE copy_lines(p_from_req_header_id IN number,
4132 p_to_req_header_id IN number,
4133 x_return_status OUT NOCOPY VARCHAR2,
4134 x_return_msg OUT NOCOPY varchar2)
4135 IS
4136
4137 v_progress VARCHAR2(10);
4138 l_procedure_name VARCHAR2(100) := 'copy_lines';
4139 l_log_msg VARCHAR2(2000);
4140
4141 CURSOR line_cursor IS
4142 SELECT requisition_line_id
4143 FROM po_requisition_lines_all
4144 WHERE requisition_header_id = p_from_req_header_id;
4145
4146 from_req_line_id NUMBER;
4147 to_req_line_id NUMBER;
4148
4149 BEGIN
4150
4151 v_progress := '000';
4152
4153 x_return_status := fnd_api.G_RET_STS_SUCCESS;
4154
4155 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
4156 l_log_msg := v_progress||': Inside procedure '||l_procedure_name;
4157 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
4158 l_log_msg := 'p_from_req_header_id: ' ||p_from_req_header_id || ' p_to_req_header_id: '||p_to_req_header_id;
4159 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
4160 END IF;
4161
4162 x_return_msg := NULL;
4163
4164 OPEN line_cursor;
4165
4166 LOOP
4167 FETCH line_cursor INTO from_req_line_id;
4168 EXIT WHEN line_cursor%NOTFOUND;
4169
4170 SELECT po_requisition_lines_s.NEXTVAL
4171 INTO to_req_line_id
4172 FROM dual;
4173
4174
4175 INSERT INTO po_requisition_lines_all (
4176 requisition_line_id,
4177 requisition_header_id,
4178 line_num,
4179 line_type_id,
4180 category_id,
4181 item_description,
4182 unit_meas_lookup_code,
4183 unit_price,
4184 quantity,
4185 deliver_to_location_id,
4186 to_person_id,
4187 last_update_date,
4188 last_updated_by,
4189 source_type_code,
4190 last_update_login,
4191 creation_date,
4192 created_by,
4193 item_id,
4194 item_revision,
4195 quantity_delivered,
4196 suggested_buyer_id,
4197 encumbered_flag,
4198 rfq_required_flag,
4199 need_by_date,
4200 line_location_id,
4201 modified_by_agent_flag,
4202 parent_req_line_id,
4203 justification,
4204 note_to_agent,
4205 note_to_receiver,
4206 purchasing_agent_id,
4207 document_type_code,
4208 blanket_po_header_id,
4209 blanket_po_line_num,
4210 currency_code,
4211 rate_type,
4212 rate_date,
4213 rate,
4214 currency_unit_price,
4215 suggested_vendor_name,
4216 suggested_vendor_location,
4217 suggested_vendor_contact,
4218 suggested_vendor_phone,
4219 suggested_vendor_product_code,
4220 un_number_id,
4221 hazard_class_id,
4222 must_use_sugg_vendor_flag,
4223 reference_num,
4224 on_rfq_flag,
4225 urgent_flag,
4226 cancel_flag,
4227 source_organization_id,
4228 source_subinventory,
4229 destination_type_code,
4230 destination_organization_id,
4231 destination_subinventory,
4232 quantity_cancelled,
4233 cancel_date,
4234 cancel_reason,
4235 closed_code,
4236 agent_return_note,
4237 changed_after_research_flag,
4238 vendor_id,
4239 vendor_site_id,
4240 vendor_contact_id,
4241 research_agent_id,
4242 on_line_flag,
4243 wip_entity_id,
4244 wip_line_id,
4245 wip_repetitive_schedule_id,
4246 wip_operation_seq_num,
4247 wip_resource_seq_num,
4248 attribute_category,
4249 destination_context,
4250 inventory_source_context,
4251 vendor_source_context,
4252 attribute1,
4253 attribute2,
4254 attribute3,
4255 attribute4,
4256 attribute5,
4257 attribute6,
4258 attribute7,
4259 attribute8,
4260 attribute9,
4261 attribute10,
4262 attribute11,
4263 attribute12,
4264 attribute13,
4265 attribute14,
4266 attribute15,
4267 bom_resource_id,
4268 request_id,
4269 program_application_id,
4270 program_id,
4271 program_update_date,
4272 ussgl_transaction_code,
4273 government_context,
4274 closed_reason,
4275 closed_date,
4276 transaction_reason_code,
4277 quantity_received,
4278 source_req_line_id,
4279 org_id,
4280 global_attribute1,
4281 global_attribute2,
4282 global_attribute3,
4283 global_attribute4,
4284 global_attribute5,
4285 global_attribute6,
4286 global_attribute7,
4287 global_attribute8,
4288 global_attribute9,
4289 global_attribute10,
4290 global_attribute11,
4291 global_attribute12,
4292 global_attribute13,
4293 global_attribute14,
4294 global_attribute15,
4295 global_attribute16,
4296 global_attribute17,
4297 global_attribute18,
4298 global_attribute19,
4299 global_attribute20,
4300 global_attribute_category,
4301 kanban_card_id,
4302 catalog_type,
4303 catalog_source,
4304 manufacturer_id,
4305 manufacturer_name,
4306 manufacturer_part_number,
4307 requester_email,
4308 requester_fax,
4309 requester_phone,
4310 unspsc_code ,
4311 other_category_code,
4312 supplier_duns,
4313 tax_status_indicator,
4314 pcard_flag,
4315 new_supplier_flag,
4316 auto_receive_flag,
4317 tax_user_override_flag,
4318 tax_code_id,
4319 note_to_vendor,
4320 oke_contract_version_id,
4321 oke_contract_header_id,
4322 item_source_id,
4323 supplier_ref_number,
4324 secondary_unit_of_measure,
4325 secondary_quantity,
4326 preferred_grade,
4327 secondary_quantity_received,
4328 secondary_quantity_cancelled,
4329 vmi_flag,
4330 auction_header_id,
4331 auction_display_number,
4332 auction_line_number,
4333 reqs_in_pool_flag,
4334 bid_number,
4335 bid_line_number,
4336 noncat_template_id,
4337 suggested_vendor_contact_fax,
4338 suggested_vendor_contact_email,
4339 amount,
4340 currency_amount,
4341 labor_req_line_id,
4342 job_id,
4343 job_long_description,
4344 contractor_status,
4345 contact_information,
4346 suggested_supplier_flag,
4347 candidate_screening_reqd_flag,
4348 assignment_end_date,
4349 overtime_allowed_flag,
4350 contractor_requisition_flag,
4351 drop_ship_flag ,
4352 candidate_first_name,
4353 candidate_last_name,
4354 assignment_start_date,
4355 order_type_lookup_code,
4356 purchase_basis,
4357 matching_basis ,
4358 negotiated_by_preparer_flag,
4359 ship_method,
4360 estimated_pickup_date,
4361 supplier_notified_for_cancel,
4362 base_unit_price,
4363 at_sourcing_flag,
4364 tax_attribute_update_code,
4365 tax_name,
4366 line_num_display,
4367 group_line_id,
4368 clm_info_flag,
4369 clm_option_indicator,
4370 clm_option_num,
4371 clm_option_from_date,
4372 clm_option_to_date,
4373 clm_funded_flag,
4374 clm_base_line_num,
4375 conformed_line_id,
4376 amendment_type,
4377 amendment_status,
4378 cost_constraint,
4379 contract_type,
4380 clm_period_perf_end_date,
4381 clm_period_perf_start_date,
4382 clm_option_exercised,
4383 uda_template_id,
4384 fund_source_not_known,
4385 clm_mipr_obligation_type
4386 )
4387 SELECT to_req_line_id,
4388 p_to_req_header_id,
4389 prl.line_num,
4390 prl.line_type_id,
4391 prl.category_id,
4392 prl.item_description,
4393 prl.unit_meas_lookup_code,
4394 prl.unit_price,
4395 prl.quantity,
4396 prl.deliver_to_location_id,
4397 prl.to_person_id,
4398 prl.last_update_date,
4399 prl.last_updated_by,
4400 prl.source_type_code,
4401 prl.last_update_login,
4402 prl.creation_date,
4403 prl.created_by,
4404 prl.item_id,
4405 prl.item_revision,
4406 prl.quantity_delivered,
4407 prl.suggested_buyer_id,
4408 prl.encumbered_flag,
4409 prl.rfq_required_flag,
4410 prl.need_by_date,
4411 prl.line_location_id,
4412 prl.modified_by_agent_flag,
4413 prl.parent_req_line_id,
4414 prl.justification,
4415 prl.note_to_agent,
4416 prl.note_to_receiver,
4417 prl.purchasing_agent_id,
4418 prl.document_type_code,
4419 prl.blanket_po_header_id,
4420 prl.blanket_po_line_num,
4421 prl.currency_code,
4422 prl.rate_type,
4423 prl.rate_date,
4424 prl.rate,
4425 prl.currency_unit_price,
4426 prl.suggested_vendor_name,
4427 prl.suggested_vendor_location,
4428 prl.suggested_vendor_contact,
4429 prl.suggested_vendor_phone,
4430 prl.suggested_vendor_product_code,
4431 prl.un_number_id,
4432 prl.hazard_class_id,
4433 prl.must_use_sugg_vendor_flag,
4434 prl.reference_num,
4435 prl.on_rfq_flag,
4436 prl.urgent_flag,
4437 prl.cancel_flag,
4438 prl.source_organization_id,
4439 prl.source_subinventory,
4440 prl.destination_type_code,
4441 prl.destination_organization_id,
4442 prl.destination_subinventory,
4443 prl.quantity_cancelled,
4444 prl.cancel_date,
4445 prl.cancel_reason,
4446 prl.closed_code,
4447 prl.agent_return_note,
4448 prl.changed_after_research_flag,
4449 prl.vendor_id,
4450 prl.vendor_site_id,
4451 prl.vendor_contact_id,
4452 prl.research_agent_id,
4453 prl.on_line_flag,
4454 prl.wip_entity_id,
4455 prl.wip_line_id,
4456 prl.wip_repetitive_schedule_id,
4457 prl.wip_operation_seq_num,
4458 prl.wip_resource_seq_num,
4459 prl.attribute_category,
4460 prl.destination_context,
4461 prl.inventory_source_context,
4462 prl.vendor_source_context,
4463 prl.attribute1,
4464 prl.attribute2,
4465 prl.attribute3,
4466 prl.attribute4,
4467 prl.attribute5,
4468 prl.attribute6,
4469 prl.attribute7,
4470 prl.attribute8,
4471 prl.attribute9,
4472 prl.attribute10,
4473 prl.attribute11,
4474 prl.attribute12,
4475 prl.attribute13,
4476 prl.attribute14,
4477 prl.attribute15,
4478 prl.bom_resource_id,
4479 prl.request_id,
4480 prl.program_application_id,
4481 prl.program_id,
4482 prl.program_update_date,
4483 prl.ussgl_transaction_code,
4484 prl.government_context,
4485 prl.closed_reason,
4486 prl.closed_date,
4487 prl.transaction_reason_code,
4488 prl.quantity_received,
4489 prl.source_req_line_id,
4490 prl.org_id,
4491 prl.global_attribute1,
4492 prl.global_attribute2,
4493 prl.global_attribute3,
4494 prl.global_attribute4,
4495 prl.global_attribute5,
4496 prl.global_attribute6,
4497 prl.global_attribute7,
4498 prl.global_attribute8,
4499 prl.global_attribute9,
4500 prl.global_attribute10,
4501 prl.global_attribute11,
4502 prl.global_attribute12,
4503 prl.global_attribute13,
4504 prl.global_attribute14,
4505 prl.global_attribute15,
4506 prl.global_attribute16,
4507 prl.global_attribute17,
4508 prl.global_attribute18,
4509 prl.global_attribute19,
4510 prl.global_attribute20,
4511 prl.global_attribute_category,
4512 prl.kanban_card_id,
4513 prl.catalog_type,
4514 prl.catalog_source,
4515 prl.manufacturer_id,
4516 prl.manufacturer_name,
4517 prl.manufacturer_part_number,
4518 prl.requester_email,
4519 prl.requester_fax,
4520 prl.requester_phone,
4521 prl.unspsc_code ,
4522 prl.other_category_code,
4523 prl.supplier_duns,
4524 prl.tax_status_indicator,
4525 prl.pcard_flag,
4526 prl.new_supplier_flag,
4527 prl.auto_receive_flag,
4528 prl.tax_user_override_flag,
4529 prl.tax_code_id,
4530 prl.note_to_vendor,
4531 prl.oke_contract_version_id,
4532 prl.oke_contract_header_id,
4533 prl.item_source_id,
4534 prl.supplier_ref_number,
4535 prl.secondary_unit_of_measure,
4536 prl.secondary_quantity,
4537 prl.preferred_grade,
4538 prl.secondary_quantity_received,
4539 prl.secondary_quantity_cancelled,
4540 prl.vmi_flag,
4541 prl.auction_header_id,
4542 prl.auction_display_number,
4543 prl.auction_line_number,
4544 null,
4545 prl.bid_number,
4546 prl.bid_line_number,
4547 prl.noncat_template_id,
4548 prl.suggested_vendor_contact_fax,
4549 prl.suggested_vendor_contact_email,
4550 prl.amount,
4551 prl.currency_amount,
4552 prl.labor_req_line_id,
4553 prl.job_id,
4554 prl.job_long_description,
4555 prl.contractor_status,
4556 prl.contact_information,
4557 prl.suggested_supplier_flag,
4558 prl.candidate_screening_reqd_flag,
4559 prl.assignment_end_date,
4560 prl.overtime_allowed_flag,
4561 prl.contractor_requisition_flag,
4562 prl.drop_ship_flag ,
4563 prl.candidate_first_name,
4564 prl.candidate_last_name,
4565 prl.assignment_start_date,
4566 prl.order_type_lookup_code,
4567 prl.purchase_basis,
4568 prl.matching_basis ,
4569 prl.negotiated_by_preparer_flag,
4570 prl.ship_method,
4571 prl.estimated_pickup_date,
4572 prl.supplier_notified_for_cancel,
4573 prl.base_unit_price,
4574 prl.at_sourcing_flag,
4575 prl.tax_attribute_update_code,
4576 prl.tax_name,
4577 prl.line_num_display,
4578 prl.group_line_id,
4579 prl.clm_info_flag,
4580 prl.clm_option_indicator,
4581 prl.clm_option_num,
4582 prl.clm_option_from_date,
4583 prl.clm_option_to_date,
4584 prl.clm_funded_flag,
4585 prl.clm_base_line_num,
4586 from_req_line_id,
4587 prl.amendment_type,
4588 prl.amendment_status,
4589 prl.cost_constraint,
4590 prl.contract_type,
4591 prl.clm_period_perf_end_date,
4592 prl.clm_period_perf_start_date,
4593 prl.clm_option_exercised,
4594 prl.uda_template_id,
4595 prl.fund_source_not_known,
4596 clm_mipr_obligation_type
4597 FROM po_requisition_lines_all prl
4598 WHERE prl.requisition_line_id = from_req_line_id;
4599
4600 v_progress := '002';
4601
4602 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
4603 l_log_msg := v_progress||' : After inserting line: '||to_req_line_id;
4604 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
4605 END IF;
4606
4607 /* Copying header level attachments */
4608
4609 fnd_attached_documents2_pkg.copy_attachments('REQ_LINES',
4610 ''||from_req_line_id,
4611 '',
4612 '',
4613 '',
4614 '',
4615 'REQ_LINES',
4616 ''||to_req_line_id,
4617 '',
4618 '',
4619 '',
4620 '',
4621 fnd_global.user_id,
4622 fnd_global.login_id,
4623 '',
4624 '',
4625 '');
4626
4627 v_progress := '003';
4628 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
4629 l_log_msg := v_progress||' : After copying line level attachments';
4630 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
4631 END IF;
4632
4633 /* Copying header level attachments - end */
4634
4635 /* Copying One Time location */
4636 v_progress := '004';
4637
4638 INSERT INTO por_item_attribute_values (
4639 item_type,
4640 requisition_header_id,
4641 requisition_line_id,
4642 attribute1,
4643 attribute2,
4644 attribute3,
4645 attribute4,
4646 attribute5,
4647 attribute6,
4648 attribute7,
4649 attribute8,
4650 attribute9,
4651 attribute10,
4652 attribute11,
4653 attribute12,
4654 attribute13,
4655 attribute14,
4656 attribute15,
4657 org_id,
4658 created_by,
4659 creation_date,
4660 last_updated_by,
4661 last_update_date,
4662 last_update_login
4663 )
4664 SELECT item_type,
4665 p_to_req_header_id,
4666 to_req_line_id,
4667 attribute1,
4668 attribute2,
4669 attribute3,
4670 attribute4,
4671 attribute5,
4672 attribute6,
4673 attribute7,
4674 attribute8,
4675 attribute9,
4676 attribute10,
4677 attribute11,
4678 attribute12,
4679 attribute13,
4680 attribute14,
4681 attribute15,
4682 org_id,
4683 created_by,
4684 creation_date,
4685 last_updated_by,
4686 last_update_date,
4687 last_update_login
4688 FROM por_item_attribute_values
4689 WHERE requisition_header_id = p_from_req_header_id
4690 AND requisition_line_id = from_req_line_id
4691 AND item_type = 'AD_HOC_LOCATION';
4692
4693 v_progress := '005';
4694
4695 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
4696 l_log_msg := v_progress||' : After copying one time location for line: '||to_req_line_id;
4697 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
4698 END IF;
4699
4700 /* Copying One Time location - end */
4701
4702 copy_distributions(from_req_line_id,to_req_line_id,x_return_status,x_return_msg);
4703
4704 v_progress := '006';
4705
4706 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
4707 l_log_msg := v_progress||' : After inserting distributions for line: '||to_req_line_id;
4708 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
4709 END IF;
4710
4711 END LOOP;
4712
4713 v_progress := '007';
4714
4715 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
4716 l_log_msg := v_progress||' : After insert into po_requisition_lines_all and po_req_distributions_all';
4717 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
4718 END IF;
4719
4720 EXCEPTION
4721 WHEN OTHERS THEN
4722
4723 x_return_msg := SQLERRM;
4724 x_return_status := FND_API.g_ret_sts_error;
4725
4726 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
4727 l_log_msg := v_progress||' : Exception at copy_lines: '|| SQLERRM;
4728 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
4729 END IF;
4730 RAISE;
4731 END copy_lines;
4732
4733
4734
4735
4736 PROCEDURE copy_distributions(p_from_req_line_id IN number,
4737 p_to_req_line_id IN number,
4738 x_return_status OUT NOCOPY VARCHAR2,
4739 x_return_msg OUT NOCOPY varchar2)
4740 IS
4741
4742 v_progress VARCHAR2(10);
4743 l_procedure_name VARCHAR2(100) := 'copy_distributions';
4744 l_log_msg VARCHAR2(2000);
4745
4746 BEGIN
4747
4748 v_progress := '000';
4749 x_return_status := fnd_api.G_RET_STS_SUCCESS;
4750 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
4751 l_log_msg := v_progress||': Inside procedure '||l_procedure_name;
4752 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
4753 l_log_msg := 'p_from_req_line_id: ' ||p_from_req_line_id || ' p_to_req_line_id: '||p_to_req_line_id;
4754 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
4755 END IF;
4756
4757 x_return_msg := NULL;
4758
4759 INSERT INTO po_req_distributions_all (
4760 distribution_id,
4761 last_update_date,
4762 last_updated_by,
4763 requisition_line_id,
4764 set_of_books_id,
4765 code_combination_id,
4766 req_line_quantity,
4767 last_update_login,
4768 creation_date,
4769 created_by,
4770 encumbered_flag,
4771 gl_encumbered_date,
4772 gl_encumbered_period_name,
4773 gl_cancelled_date,
4774 failed_funds_lookup_code,
4775 encumbered_amount,
4776 budget_account_id,
4777 accrual_account_id,
4778 variance_account_id,
4779 prevent_encumbrance_flag,
4780 attribute_category,
4781 attribute1,
4782 attribute2,
4783 attribute3,
4784 attribute4,
4785 attribute5,
4786 attribute6,
4787 attribute7,
4788 attribute8,
4789 attribute9,
4790 attribute10,
4791 attribute11,
4792 attribute12,
4793 attribute13,
4794 attribute14,
4795 attribute15,
4796 ussgl_transaction_code,
4797 government_context,
4798 request_id,
4799 program_application_id,
4800 program_id,
4801 program_update_date,
4802 project_id,
4803 task_id,
4804 expenditure_type,
4805 project_accounting_context,
4806 expenditure_organization_id,
4807 gl_closed_date,
4808 source_req_distribution_id,
4809 distribution_num,
4810 project_related_flag,
4811 expenditure_item_date,
4812 org_id,
4813 allocation_type,
4814 allocation_value,
4815 award_id,
4816 end_item_unit_number,
4817 recoverable_tax,
4818 nonrecoverable_tax,
4819 recovery_rate,
4820 tax_recovery_override_flag,
4821 oke_contract_line_id,
4822 oke_contract_deliverable_id,
4823 req_line_amount,
4824 req_line_currency_amount,
4825 req_award_id,
4826 event_id,
4827 -- line_num_display,
4828 conformed_dist_id,
4829 amendment_type,
4830 amendment_status,
4831 partial_funded_flag,
4832 funded_value,
4833 quantity_funded,
4834 amount_funded,
4835 change_in_funded_value, --<<CLM Partial Funding Code Changes>>
4836 clm_misc_loa,
4837 clm_defence_funding,
4838 clm_fms_case_number,
4839 clm_agency_acct_identifier,
4840 info_line_id,
4841 acrn
4842 )
4843 SELECT po_req_distributions_s.NEXTVAL,
4844 last_update_date,
4845 last_updated_by,
4846 p_to_req_line_id,
4847 set_of_books_id,
4848 code_combination_id,
4849 req_line_quantity,
4850 last_update_login,
4851 creation_date,
4852 created_by,
4853 encumbered_flag,
4854 gl_encumbered_date,
4855 gl_encumbered_period_name,
4856 gl_cancelled_date,
4857 failed_funds_lookup_code,
4858 encumbered_amount,
4859 budget_account_id,
4860 accrual_account_id,
4861 variance_account_id,
4862 prevent_encumbrance_flag,
4863 attribute_category,
4864 attribute1,
4865 attribute2,
4866 attribute3,
4867 attribute4,
4868 attribute5,
4869 attribute6,
4870 attribute7,
4871 attribute8,
4872 attribute9,
4873 attribute10,
4874 attribute11,
4875 attribute12,
4876 attribute13,
4877 attribute14,
4878 attribute15,
4879 ussgl_transaction_code,
4880 government_context,
4881 request_id,
4882 program_application_id,
4883 program_id,
4884 program_update_date,
4885 project_id,
4886 task_id,
4887 expenditure_type,
4888 project_accounting_context,
4889 expenditure_organization_id,
4890 gl_closed_date,
4891 source_req_distribution_id,
4892 distribution_num,
4893 project_related_flag,
4894 expenditure_item_date,
4895 org_id,
4896 allocation_type,
4897 allocation_value,
4898 award_id,
4899 end_item_unit_number,
4900 recoverable_tax,
4901 nonrecoverable_tax,
4902 recovery_rate,
4903 tax_recovery_override_flag,
4904 oke_contract_line_id,
4905 oke_contract_deliverable_id,
4906 req_line_amount,
4907 req_line_currency_amount,
4908 req_award_id,
4909 event_id,
4910 -- line_num_display,
4911 distribution_id,
4912 amendment_type,
4913 amendment_status,
4914 partial_funded_flag,
4915 funded_value,
4916 quantity_funded,
4917 amount_funded,
4918 change_in_funded_value, -- <<CLM Partial Funding Code Changes>>
4919 clm_misc_loa,
4920 clm_defence_funding,
4921 clm_fms_case_number,
4922 clm_agency_acct_identifier,
4923 info_line_id,
4924 acrn
4925 FROM po_req_distributions_all
4926 WHERE requisition_line_id = p_from_req_line_id;
4927
4928 v_progress := '001';
4929
4930 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
4931 l_log_msg := v_progress||' : After inserting distribution';
4932 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
4933 END IF;
4934
4935 EXCEPTION
4936 WHEN OTHERS THEN
4937
4938 x_return_msg := SQLERRM;
4939 x_return_status := FND_API.g_ret_sts_error;
4940
4941 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
4942 l_log_msg := v_progress||' : Exception at copy_distributions: '|| SQLERRM;
4943 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
4944 END IF;
4945 RAISE;
4946 END copy_distributions;
4947
4948
4949 PROCEDURE carry_auto_aceept_and_reject (l_requisition_header_id IN NUMBER)
4950 IS
4951 x_progress varchar2(100);
4952 l_procedure_name VARCHAR2(100) := 'carry_auto_aceept_and_reject';
4953 l_log_msg VARCHAR2(2000);
4954 BEGIN
4955
4956 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
4957 l_log_msg := ' Begin ';
4958 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
4959 END IF;
4960
4961 --First update all those lines and distribution to accepted whose
4962 --conformed_ids are null and they are CLIN
4963 UPDATE po_requisition_lines_all SET amendment_status = 'A'
4964 WHERE conformed_line_id IS NULL AND
4965 group_line_id IS NULL AND
4966 requisition_header_id = l_requisition_header_id;
4967
4968 --Update it for slins whose clin is also new
4969 UPDATE po_requisition_lines_all prla SET prla.amendment_status = 'A'
4970 WHERE prla.requisition_header_id = l_requisition_header_id
4971 AND EXISTS (SELECT 1 FROM po_requisition_lines_all prla1
4972 WHERE prla1.requisition_line_id = prla.group_line_id
4973 AND prla1.conformed_line_id IS NULL
4974 AND prla1.amendment_status = 'A');
4975
4976 UPDATE po_req_distributions_all SET amendment_status = 'A'
4977 WHERE conformed_dist_id IS NULL AND
4978 requisition_line_id IN
4979 (SELECT requisition_line_id FROM po_requisition_lines_all
4980 WHERE conformed_line_id IS NULL AND
4981 requisition_header_id = l_requisition_header_id);
4982
4983 --Now update those lines and distributions whose
4984 --conformed_ids is not null but the corresponding
4985 --line_location_id is null
4986 UPDATE po_requisition_lines_all prla SET prla.amendment_status = 'A'
4987 WHERE prla.requisition_header_id = l_requisition_header_id
4988 AND EXISTS (SELECT 1 FROM po_requisition_lines_all prla1
4989 WHERE prla1.requisition_line_id = prla.conformed_line_id
4990 AND prla1.line_location_id IS NULL
4991 AND prla1.auction_header_id is NULL
4992 AND nvl(prla1.clm_info_flag,'N') = 'N')
4993 AND prla.group_line_id IS NULL;
4994
4995 --Update slins whose clins are not placed on PO and amendment_status='A'
4996 UPDATE po_requisition_lines_all prla SET prla.amendment_status = 'A'
4997 WHERE prla.requisition_header_id = l_requisition_header_id
4998 AND prla.group_line_id IS NOT NULL
4999 AND EXISTS (SELECT 1 FROM po_requisition_lines_all prla1,po_requisition_lines_all prla2
5000 WHERE prla1.requisition_line_id = prla.group_line_id
5001 AND prla2.requisition_line_id = prla1.conformed_line_id
5002 AND prla2.line_location_id IS NULL
5003 AND prla2.auction_header_id is NULL
5004 AND nvl(prla2.clm_info_flag,'N') = 'N');
5005
5006
5007 UPDATE po_req_distributions_all prda SET prda.amendment_status = 'A'
5008 WHERE prda.requisition_line_id IN
5009 (SELECT requisition_line_id FROM po_requisition_lines_all prla
5010 WHERE prla.requisition_header_id = l_requisition_header_id
5011 AND EXISTS (SELECT 1 FROM po_requisition_lines_all prla1
5012 WHERE prla1.requisition_line_id = prla.conformed_line_id
5013 AND prla1.line_location_id IS NULL
5014 AND prla1.auction_header_id is NULL));
5015
5016 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
5017 l_log_msg := ' Auto Accept completed';
5018 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
5019 END IF;
5020
5021
5022 END carry_auto_aceept_and_reject;
5023
5024
5025 procedure CREATE_BASE_VERSION(itemtype in varchar2,
5026 itemkey in varchar2,
5027 actid in number,
5028 funcmode in varchar2,
5029 resultout out NOCOPY varchar2) is
5030 x_progress varchar2(100);
5031 l_resultout varchar2(30);
5032 l_from_req_header_id number;
5033 l_to_req_header_id number;
5034 l_return_status varchar2(1);
5035 l_return_msg varchar2(2000);
5036 copy_doc_exception exception;
5037
5038 BEGIN
5039
5040 x_progress := 'POR_AMENDMENT_PKG.CREATE_BASE_VERSION: 01';
5041 IF (g_po_wf_debug = 'Y') THEN
5042 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5043 END IF;
5044
5045
5046 -- Do nothing in cancel or timeout mode
5047 --
5048 if (funcmode <> wf_engine.eng_run) then
5049
5050 resultout := wf_engine.eng_null;
5051 return;
5052
5053 end if;
5054
5055 l_from_req_header_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
5056 itemkey => itemkey,
5057 aname => 'DOCUMENT_ID');
5058
5059 x_progress := 'POR_AMENDMENT_PKG.CREATE_BASE_VERSION: 02 - l_from_req_header_id= ' || l_from_req_header_id;
5060
5061 create_base_copy( p_from_req_header_id => l_from_req_header_id,
5062 x_to_req_header_id => l_to_req_header_id,
5063 x_return_status => l_return_status,
5064 x_return_msg => l_return_msg);
5065
5066 if(l_return_status <> FND_API.G_RET_STS_SUCCESS) then
5067 x_progress := 'POR_AMENDMENT_PKG.CREATE_BASE_VERSION: 03 - Exception : l_return_msg';
5068 raise copy_doc_exception;
5069 end if;
5070
5071 EXCEPTION
5072
5073 WHEN OTHERS THEN
5074 wf_core.context('POR_AMENDMENT_PKG','CREATE_BASE_VERSION',x_progress);
5075 raise;
5076
5077 END CREATE_BASE_VERSION;
5078
5079
5080 procedure MERGE_INTO_CONFORM_VERSION(itemtype in varchar2,
5081 itemkey in varchar2,
5082 actid in number,
5083 funcmode in varchar2,
5084 resultout out NOCOPY varchar2) IS
5085
5086 x_progress varchar2(100);
5087 x_resultout varchar2(30);
5088 l_conformed_header_id number;
5089 l_revision_num number;
5090
5091 BEGIN
5092
5093 x_progress := 'POR_AMENDMENT_PKG.MERGE_INTO_CONFORM_VERSION: 01';
5094 IF (g_po_wf_debug = 'Y') THEN
5095 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5096 END IF;
5097
5098
5099 -- Do nothing in cancel or timeout mode
5100 --
5101 if (funcmode <> wf_engine.eng_run) then
5102
5103 resultout := wf_engine.eng_null;
5104 return;
5105
5106 end if;
5107
5108 l_conformed_header_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
5109 itemkey => itemkey,
5110 aname => 'CONFORMED_HEADER_ID');
5111
5112 l_revision_num := wf_engine.GetItemAttrNumber (itemtype => itemtype,
5113 itemkey => itemkey,
5114 aname => 'REVISION_NUM');
5115
5116
5117 merge_amendment(p_confirmed_id => l_conformed_header_id,
5118 p_revision_num => l_revision_num);
5119
5120 EXCEPTION
5121
5122 WHEN OTHERS THEN
5123 wf_core.context('POR_AMENDMENT_PKG','MERGE_INTO_CONFORM_VERSION',x_progress);
5124 raise;
5125
5126 END MERGE_INTO_CONFORM_VERSION;
5127
5128
5129 procedure AUTO_ACCEPT_AND_REJECT(itemtype in varchar2,
5130 itemkey in varchar2,
5131 actid in number,
5132 funcmode in varchar2,
5133 resultout out NOCOPY varchar2) IS
5134
5135 x_progress varchar2(100);
5136 x_resultout varchar2(30);
5137 l_requisition_header_id number;
5138
5139 BEGIN
5140 x_progress := 'POR_AMENDMENT_PKG.AUTO_ACCEPT_AND_REJECT: 01';
5141 IF (g_po_wf_debug = 'Y') THEN
5142 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5143 END IF;
5144
5145 -- Do nothing in cancel or timeout mode
5146 --
5147 if (funcmode <> wf_engine.eng_run) then
5148
5149 resultout := wf_engine.eng_null;
5150 return;
5151
5152 end if;
5153
5154 l_requisition_header_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
5155 itemkey => itemkey,
5156 aname => 'DOCUMENT_ID');
5157
5158 carry_auto_aceept_and_reject(l_requisition_header_id);
5159
5160
5161 END AUTO_ACCEPT_AND_REJECT;
5162
5163 procedure MORE_BUYER_TO_NOTIFY(itemtype in varchar2,
5164 itemkey in varchar2,
5165 actid in number,
5166 funcmode in varchar2,
5167 resultout out NOCOPY varchar2) IS
5168
5169 x_progress varchar2(100);
5170 x_resultout varchar2(30);
5171 l_document_id number;
5172 l_current_buyer_id NUMBER;
5173 l_buyer_id NUMBER := 0;
5174
5175 l_buyer_name VARCHAR2(100);
5176 l_buyer_display_name VARCHAR2(240);
5177
5178 BEGIN
5179
5180 x_progress := 'POR_AMENDMENT_PKG.MORE_BUYER_TO_NOTIFY: 01';
5181 IF (g_po_wf_debug = 'Y') THEN
5182 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5183 END IF;
5184
5185
5186 -- Do nothing in cancel or timeout mode
5187 --
5188 if (funcmode <> wf_engine.eng_run) then
5189
5190 resultout := wf_engine.eng_null;
5191 return;
5192
5193 end if;
5194
5195 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
5196 itemkey => itemkey,
5197 aname => 'DOCUMENT_ID');
5198
5199 l_current_buyer_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
5200 itemkey => itemkey,
5201 aname => 'CURRENT_BUYER_ID');
5202
5203 x_progress := 'POR_AMENDMENT_PKG.MORE_BUYER_TO_NOTIFY: 02 : l_document_id :'||l_document_id||' : l_current_buyer_id : '||l_current_buyer_id;
5204 IF (g_po_wf_debug = 'Y') THEN
5205 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5206 END IF;
5207
5208 SELECT Min(awdrefs.agent_id)
5209 INTO l_buyer_id
5210 FROM po_requisition_lines_all prl,
5211 PO_CLMREQ_LINE_AWD_REFS_V awdrefs
5212 -- po_line_locations_all pll,
5213 -- po_headers_all pha
5214 WHERE prl.requisition_header_id = (SELECT conformed_header_id
5215 FROM po_requisition_headers_all
5216 WHERE requisition_header_id = l_document_id)
5217 AND awdrefs.requisition_line_id = prl.requisition_line_id
5218 AND awdrefs.requisition_header_id=prl.requisition_header_id
5219 --AND prl.line_location_id = pll.line_location_id
5220 --AND pll.po_header_id = pha.po_header_id
5221 AND prl.AMENDMENT_TYPE = 'CHANGED'
5222 AND prl.AMENDMENT_STATUS IN ('N','P')
5223 AND awdrefs.agent_id > Nvl(l_current_buyer_id,0);
5224
5225
5226 IF l_buyer_id IS NOT NULL THEN
5227 wf_engine.SetItemAttrText ( itemtype => itemtype,
5228 itemkey => itemkey,
5229 aname => 'CURRENT_BUYER_ID',
5230 avalue => l_buyer_id);
5231
5232 PO_REQAPPROVAL_INIT1.get_user_name(l_buyer_id, l_buyer_name, l_buyer_display_name);
5233
5234 wf_engine.SetItemAttrText ( itemtype => itemtype,
5235 itemkey => itemkey,
5236 aname => 'CURRENT_BUYER_NAME',
5237 avalue => l_buyer_name);
5238
5239 resultout:='COMPLETE:'||'Y';
5240 RETURN;
5241 ELSE
5242 wf_engine.SetItemAttrText ( itemtype => itemtype,
5243 itemkey => itemkey,
5244 aname => 'CURRENT_BUYER_ID',
5245 avalue => l_buyer_id);
5246 wf_engine.SetItemAttrText ( itemtype => itemtype,
5247 itemkey => itemkey,
5248 aname => 'CURRENT_BUYER_NAME',
5249 avalue => null);
5250
5251 resultout:='COMPLETE:'||'N';
5252 RETURN;
5253 END IF;
5254 EXCEPTION
5255
5256 WHEN OTHERS THEN
5257 wf_core.context('POR_AMENDMENT_PKG','MORE_BUYER_TO_NOTIFY',x_progress);
5258 raise;
5259
5260 END MORE_BUYER_TO_NOTIFY;
5261
5262
5263
5264 procedure MORE_SOURCING_OWNER_TO_NOTIFY(itemtype in varchar2,
5265 itemkey in varchar2,
5266 actid in number,
5267 funcmode in varchar2,
5268 resultout out NOCOPY varchar2) IS
5269
5270 x_progress varchar2(100);
5271 x_resultout varchar2(30);
5272 l_document_id NUMBER;
5273 l_current_sourcing_owner_id NUMBER;
5274 l_sourcing_owner_id NUMBER := 0;
5275
5276 l_ourcing_owner_name VARCHAR2(100);
5277 l_ourcing_owner_display_name VARCHAR2(240);
5278
5279 BEGIN
5280
5281 x_progress := 'POR_AMENDMENT_PKG.MORE_SOURCING_OWNER_TO_NOTIFY: 01';
5282 IF (g_po_wf_debug = 'Y') THEN
5283 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5284 END IF;
5285
5286
5287 -- Do nothing in cancel or timeout mode
5288 --
5289 if (funcmode <> wf_engine.eng_run) then
5290
5291 resultout := wf_engine.eng_null;
5292 return;
5293
5294 end if;
5295
5296 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
5297 itemkey => itemkey,
5298 aname => 'DOCUMENT_ID');
5299
5300 l_current_sourcing_owner_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
5301 itemkey => itemkey,
5302 aname => 'CURRENT_SOURCING_OWNER_ID');
5303
5304
5305 SELECT Min(pah.trading_partner_contact_id)
5306 INTO l_sourcing_owner_id
5307 FROM pon_auction_headers_all pah,
5308 po_requisition_lines_all prl
5309 WHERE prl.requisition_header_id = (SELECT conformed_header_id
5310 FROM po_requisition_headers_all
5311 WHERE requisition_header_id = l_document_id)
5312 AND pah.auction_header_id = prl.auction_header_id
5313 AND prl.AMENDMENT_TYPE = 'CHANGED'
5314 AND prl.AMENDMENT_STATUS IN ('N','P')
5315 AND pah.trading_partner_contact_id > Nvl(l_current_sourcing_owner_id,0);
5316
5317 IF l_sourcing_owner_id IS NOT NULL THEN
5318 wf_engine.SetItemAttrText ( itemtype => itemtype,
5319 itemkey => itemkey,
5320 aname => 'CURRENT_SOURCING_OWNER_ID',
5321 avalue => l_sourcing_owner_id);
5322
5323 SELECT user_name
5324 INTO l_ourcing_owner_name
5325 FROM fnd_user
5326 WHERE person_party_id = l_sourcing_owner_id
5327 AND nvl(end_date, sysdate+1) > sysdate
5328 AND rownum=1;
5329
5330 wf_engine.SetItemAttrText ( itemtype => itemtype,
5331 itemkey => itemkey,
5332 aname => 'CURRENT_SOURCING_OWNER_NAME',
5333 avalue => l_ourcing_owner_name);
5334
5335 resultout:='COMPLETE:'||'Y';
5336 RETURN;
5337 ELSE
5338 wf_engine.SetItemAttrText ( itemtype => itemtype,
5339 itemkey => itemkey,
5340 aname => 'CURRENT_SOURCING_OWNER_ID',
5341 avalue => l_sourcing_owner_id);
5342 wf_engine.SetItemAttrText ( itemtype => itemtype,
5343 itemkey => itemkey,
5344 aname => 'CURRENT_SOURCING_OWNER_NAME',
5345 avalue => null);
5346
5347 resultout:='COMPLETE:'||'N';
5348 RETURN;
5349 END IF;
5350 EXCEPTION
5351
5352 WHEN OTHERS THEN
5353 wf_core.context('POR_AMENDMENT_PKG','MORE_SOURCING_OWNER_TO_NOTIFY',x_progress);
5354 raise;
5355
5356 END MORE_SOURCING_OWNER_TO_NOTIFY;
5357
5358
5359
5360 procedure SET_AMENDMENT_WF_ATTRIBUTES(itemtype in varchar2,
5361 itemkey in varchar2,
5362 actid in number,
5363 funcmode in varchar2,
5364 resultout out NOCOPY varchar2) IS
5365
5366 x_progress varchar2(100);
5367 x_resultout varchar2(30);
5368 l_document_id NUMBER;
5369 l_old_document_id NUMBER;
5370 l_req_amount NUMBER;
5371 l_req_amount_disp VARCHAR2(60);
5372 l_tax_amount NUMBER;
5373 l_tax_amount_disp VARCHAR2(60);
5374 l_total_amount NUMBER;
5375 l_total_amount_disp VARCHAR2(60);
5376
5377 l_conformed_header_id NUMBER;
5378 l_revision_num NUMBER;
5379
5380 l_precision NUMBER;
5381 l_ext_precision NUMBER;
5382 l_min_acct_unit NUMBER;
5383 g_currency_format_mask NUMBER := 60;
5384
5385 l_currency_code VARCHAR2(30);
5386
5387 CURSOR req_total_csr(p_doc_id NUMBER,l_precision NUMBER)
5388 IS
5389 SELECT NVL(SUM(ROUND(DECODE(order_type_lookup_code, 'RATE', amount, 'FIXED PRICE', amount, quantity * unit_price),l_precision)) ,0)
5390 FROM po_requisition_lines
5391 WHERE requisition_header_id = p_doc_id
5392 AND NVL(cancel_flag,'N') = 'N'
5393 AND NVL(modified_by_agent_flag, 'N') = 'N';
5394
5395 CURSOR req_tax_csr(p_doc_id NUMBER)
5396 IS
5397 SELECT NVL(SUM(nonrecoverable_tax), 0)
5398 FROM po_requisition_lines rl,
5399 po_req_distributions_all rd -- <R12 MOAC>
5400 WHERE rl.requisition_header_id = p_doc_id
5401 AND rd.requisition_line_id = rl.requisition_line_id
5402 AND NVL(rl.cancel_flag,'N') = 'N'
5403 AND NVL(rl.modified_by_agent_flag, 'N') = 'N';
5404
5405 BEGIN
5406
5407 x_progress := 'POR_AMENDMENT_PKG.SET_AMENDMENT_WF_ATTRIBUTES: 01';
5408 IF (g_po_wf_debug = 'Y') THEN
5409 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5410 END IF;
5411
5412
5413 -- Do nothing in cancel or timeout mode
5414 --
5415 if (funcmode <> wf_engine.eng_run) then
5416
5417 resultout := wf_engine.eng_null;
5418 return;
5419
5420 end if;
5421
5422 l_document_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
5423 itemkey => itemkey,
5424 aname => 'DOCUMENT_ID');
5425
5426 l_currency_code := PO_CORE_S2.get_base_currency;
5427 fnd_currency.get_info(l_currency_code, l_precision, l_ext_precision, l_min_acct_unit);
5428
5429 wf_engine.SetItemAttrText ( itemtype => itemtype,
5430 itemkey => itemkey,
5431 aname => 'FUNCTIONAL_CURRENCY',
5432 avalue => l_currency_code);
5433
5434
5435 OPEN req_total_csr(l_document_id,l_precision);
5436 FETCH req_total_csr INTO l_req_amount;
5437
5438 CLOSE req_total_csr;
5439
5440 OPEN req_tax_csr(l_document_id);
5441 FETCH req_tax_csr INTO l_tax_amount;
5442
5443 CLOSE req_tax_csr;
5444
5445 l_tax_amount_disp := TO_CHAR(l_tax_amount,FND_CURRENCY.GET_FORMAT_MASK( l_currency_code, g_currency_format_mask))||' '||l_currency_code;
5446
5447 wf_engine.SetItemAttrText ( itemtype => itemtype,
5448 itemkey => itemkey,
5449 aname => 'NEW_TAX_AMOUNT_CURRENCY_DSP',
5450 avalue => l_tax_amount_disp);
5451
5452 l_total_amount := l_req_amount + l_tax_amount;
5453 l_total_amount_disp := TO_CHAR(l_total_amount, FND_CURRENCY.GET_FORMAT_MASK( l_currency_code, g_currency_format_mask))||' '||l_currency_code;
5454
5455 wf_engine.SetItemAttrText ( itemtype => itemtype,
5456 itemkey => itemkey,
5457 aname => 'NEW_REQ_AMOUNT_CURRENCY_DSP',
5458 avalue => l_total_amount_disp);
5459
5460
5461
5462
5463 l_conformed_header_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
5464 itemkey => itemkey,
5465 aname => 'CONFORMED_HEADER_ID');
5466
5467 l_revision_num := wf_engine.GetItemAttrNumber (itemtype => itemtype,
5468 itemkey => itemkey,
5469 aname => 'REVISION_NUM');
5470
5471 SELECT requisition_header_id
5472 INTO l_old_document_id
5473 FROM po_requisition_headers_all
5474 WHERE conformed_header_id = l_conformed_header_id
5475 AND revision_num = l_revision_num -1;
5476
5477 OPEN req_total_csr(l_old_document_id,l_precision);
5478 FETCH req_total_csr INTO l_req_amount;
5479
5480 CLOSE req_total_csr;
5481
5482 OPEN req_tax_csr(l_old_document_id);
5483 FETCH req_tax_csr INTO l_tax_amount;
5484
5485 CLOSE req_tax_csr;
5486
5487 l_tax_amount_disp := TO_CHAR(l_tax_amount,FND_CURRENCY.GET_FORMAT_MASK( l_currency_code, g_currency_format_mask))||' '||l_currency_code;
5488
5489 wf_engine.SetItemAttrText ( itemtype => itemtype,
5490 itemkey => itemkey,
5491 aname => 'OLD_TAX_AMOUNT_CURRENCY_DSP',
5492 avalue => l_tax_amount_disp);
5493
5494 l_total_amount := l_req_amount + l_tax_amount;
5495 l_total_amount_disp := TO_CHAR(l_total_amount, FND_CURRENCY.GET_FORMAT_MASK( l_currency_code, g_currency_format_mask))||' '||l_currency_code;
5496
5497 wf_engine.SetItemAttrText ( itemtype => itemtype,
5498 itemkey => itemkey,
5499 aname => 'OLD_REQ_AMOUNT_CURRENCY_DSP',
5500 avalue => l_total_amount_disp);
5501
5502
5503
5504 EXCEPTION
5505
5506 WHEN OTHERS THEN
5507 wf_core.context('POR_AMENDMENT_PKG','SET_AMENDMENT_WF_ATTRIBUTES',x_progress);
5508 raise;
5509
5510 END SET_AMENDMENT_WF_ATTRIBUTES;
5511
5512
5513 FUNCTION isLinePlacedOnApprPO(reqLineId IN NUMBER) RETURN VARCHAR2
5514 IS
5515 isApprovedPOLine VARCHAR2(1):='N';
5516 l_line_location_id NUMBER;
5517 l_authorization_status po_headers_all.authorization_status%TYPE;
5518 BEGIN
5519 SELECT line_location_id
5520 INTO l_line_location_id
5521 FROM po_requisition_lines_all
5522 WHERE REQUISITION_line_ID = reqLineId;
5523
5524 IF l_line_location_id IS NOT NULL THEN
5525 IF l_line_location_id < 0 THEN
5526 BEGIN
5527 select 'Y' into isApprovedPOLine from PO_CLMREQ_LINE_AWD_REFS_V WHERE requisition_line_id= reqLineId
5528 AND nvl(authorization_status,'INCOMPLETE') ='APPROVED' AND ROWNUM=1;
5529 EXCEPTION
5530 WHEN No_Data_Found THEN
5531 isApprovedPOLine :='N';
5532 END;
5533
5534 ELSE
5535
5536 BEGIN
5537 SELECT Nvl(pra.authorization_status, 'INCOMPLETE')
5538 INTO l_authorization_status
5539 FROM po_releases_all pra,po_line_locations_all plla
5540 WHERE plla.line_location_id = l_line_location_id
5541 AND pra.po_release_id =plla.po_release_id ;
5542 EXCEPTION
5543 WHEN No_Data_Found THEN
5544 --This is not a release but a normal po
5545 l_authorization_status :=NULL;
5546 END;
5547
5548 IF l_authorization_status IS NULL THEN
5549 BEGIN
5550 SELECT pha.authorization_status
5551 INTO l_authorization_status
5552 FROM po_headers_all pha,
5553 po_line_locations_all plla
5554 WHERE
5555 pha.po_header_id = plla.po_header_id
5556 AND plla.line_location_id = l_line_location_id;
5557 EXCEPTION
5558 WHEN No_Data_Found THEN
5559 l_authorization_status :=NULL;
5560 END;
5561 END IF;
5562
5563 IF (Nvl(l_authorization_status,'INCOMPLETE') = 'APPROVED') THEN
5564 isApprovedPOLine :='Y';
5565 END IF;
5566 END IF;
5567 END IF;
5568 RETURN isApprovedPOLine;
5569 END isLinePlacedOnApprPO;
5570
5571 PROCEDURE amendment_post_merge_actions(itemtype in varchar2,
5572 itemkey in varchar2,
5573 actid in number,
5574 funcmode in varchar2,
5575 resultout out NOCOPY varchar2)
5576 IS
5577 l_api_name CONSTANT VARCHAR2(30) := 'amendment_post_merge_actions';
5578 x_progress varchar2(100);
5579 x_resultout varchar2(30);
5580
5581 l_conformed_id NUMBER;
5582 l_result BOOLEAN;
5583 l_log_msg VARCHAR2(2000);
5584
5585 BEGIN
5586 x_progress := 'POR_AMENDMENT_PKG.amendment_post_merge_actions: 01';
5587 IF (g_po_wf_debug = 'Y') THEN
5588 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5589 END IF;
5590
5591 -- Do nothing in cancel or timeout mode
5592 if (funcmode <> wf_engine.eng_run) then
5593 resultout := wf_engine.eng_null;
5594 return;
5595 end if;
5596
5597 l_conformed_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
5598 itemkey => itemkey,
5599 aname => 'CONFORMED_HEADER_ID');
5600
5601 --Since this is an amendment flow, so we have to create/modify the
5602 --supply table based on the conformed_id
5603 l_result := PO_SUPPLY.create_req(l_conformed_id, 'REQ HDR');
5604
5605 x_progress := 'POR_AMENDMENT_PKG.amendment_post_merge_actions: completed successfully';
5606 IF (g_po_wf_debug = 'Y') THEN
5607 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
5608 END IF;
5609
5610 EXCEPTION
5611 WHEN OTHERS THEN
5612 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
5613 l_log_msg := x_progress||'CException: '||SQLERRM;
5614 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_api_name, l_log_msg);
5615
5616 END IF;
5617 wf_core.context('POR_AMENDMENT_PKG','amendment_post_merge_actions',x_progress);
5618 raise;
5619
5620 END amendment_post_merge_actions;
5621
5622
5623 PROCEDURE create_cancel_amendment(p_from_req_header_id in number,
5624 p_cancel_Reason in varchar2,
5625 x_amendment_header_id out nocopy number,
5626 x_return_status OUT NOCOPY VARCHAR2) IS
5627
5628 v_progress VARCHAR2(10);
5629 l_procedure_name VARCHAR2(100) := 'create_cancel_amendment';
5630 l_log_msg VARCHAR2(2000);
5631 l_to_req_header_id number := NULL;
5632 l_return_status varchar2(1) := FND_API.g_ret_sts_success;
5633 l_return_msg varchar2(2000) := null;
5634 l_revision_num number :=0;
5635
5636 BEGIN
5637
5638 x_return_status := FND_API.g_ret_sts_success;
5639
5640 v_progress := '000';
5641 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
5642 l_log_msg := v_progress||': Inside procedure '||l_procedure_name;
5643 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
5644 l_log_msg := 'p_from_req_header_id: ' ||p_from_req_header_id;
5645 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
5646 END IF;
5647
5648 -- Standard start of API savepoint
5649 SAVEPOINT CREATE_CANCEL_AMENDMENT;
5650
5651 v_progress := '001';
5652
5653 select max(nvl(revision_num,0))
5654 into l_revision_num
5655 from po_requisition_headers_all
5656 where conformed_header_id = p_from_req_header_id;
5657
5658
5659 /* Call the procedure to copy the header*/
5660 copy_header(p_from_req_header_id, l_revision_num+1, l_to_req_header_id, l_return_status, l_return_msg);
5661
5662 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
5663 l_log_msg := v_progress||' : Procedure copy_header: l_return_status: '||l_return_status ||' l_to_req_header_id: '||l_to_req_header_id ||' l_return_msg: '||l_return_msg;
5664 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
5665 END IF;
5666
5667 update po_requisition_headers_all
5668 set amendment_reason = p_cancel_Reason
5669 where requisition_header_id = l_to_req_header_id;
5670
5671 v_progress := '002';
5672
5673 copy_lines(p_from_req_header_id, l_to_req_header_id, l_return_status, l_return_msg);
5674
5675 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
5676 l_log_msg := v_progress||' : l_return_status: '||l_return_status ||' l_to_req_header_id: '||l_to_req_header_id||' l_return_msg: '||l_return_msg;
5677 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
5678 END IF;
5679
5680 x_return_status := l_return_status;
5681 x_amendment_header_id := l_to_req_header_id;
5682
5683 EXCEPTION
5684 WHEN OTHERS THEN
5685 ROLLBACK TO SAVEPOINT CREATE_CANCEL_AMENDMENT;
5686
5687 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
5688 l_log_msg := v_progress||' : Exception at CREATE_CANCEL_AMENDMENT: '|| SQLERRM;
5689 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
5690 END IF;
5691 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5692
5693 END create_cancel_amendment;
5694
5695
5696 PROCEDURE set_amend_lines_cancel(p_req_header_id in number,
5697 p_line_id_list in po_tbl_number)
5698 IS
5699
5700 v_progress VARCHAR2(10);
5701 l_procedure_name VARCHAR2(100) := 'set_amend_lines_cancel';
5702 l_log_msg VARCHAR2(2000);
5703
5704 BEGIN
5705
5706 v_progress := '000';
5707 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
5708 l_log_msg := v_progress||': Inside procedure '||l_procedure_name;
5709 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
5710 END IF;
5711
5712
5713 v_progress := '001';
5714
5715 FORALL i in 1..p_line_id_list.count
5716 update po_requisition_lines_all
5717 set amendment_type='CANCELLED',
5718 amendment_status='A',
5719 cancel_flag='Y'
5720 where requisition_header_id = p_req_header_id
5721 and conformed_line_id = p_line_id_list(i);
5722
5723 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
5724 l_log_msg := v_progress||': Bulk set amendment type completed'||l_procedure_name;
5725 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
5726 END IF;
5727
5728 EXCEPTION
5729 WHEN OTHERS THEN
5730
5731 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
5732 l_log_msg := v_progress||' : Exception at set_amend_lines_cancel: '|| SQLERRM;
5733 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
5734 END IF;
5735 raise;
5736
5737 END set_amend_lines_cancel;
5738
5739
5740 ---------------------------------------------------------------------------------------------------------------------------
5741
5742
5743 PROCEDURE create_distributions(
5744 x_requisition_line_id IN number,
5745 x_requisition_dist_id IN number,
5746 x_line_location_id IN number,
5747 x_po_release_id IN NUMBER
5748 )
5749 IS
5750 x_distribution_num number;
5751 x_po_distribution_id number;
5752 x_gl_date_option varchar2(25);
5753 x_po_appl_id number;
5754 x_gl_appl_id number;
5755
5756 x_po_encumbrance_flag varchar2(1);
5757 x_req_encumbrance_flag varchar2(1);
5758 x_period_name gl_period_statuses.period_name%type;
5759 x_sob_id number;
5760 x_receiving_flag varchar2(1);
5761 X_expense_accrual_code po_system_parameters.price_type_lookup_code%type;
5762 x_date date;
5763 x_rate_for_req_fields number;
5764
5765
5766 /* obtain currency info to adjust precision */
5767 x_precision number := 2;
5768 x_ext_precision number := 5;
5769 x_min_unit number :='';
5770 x_order_type_lookup_code varchar2(15);
5771
5772 x_kanban_card_id number:='';
5773 x_accrued_flag varchar2(1);
5774 x_po_uom varchar2(25):=null;
5775 x_req_uom varchar2(25):=null;
5776 x_uom_convert varchar2(2) := fnd_profile.value('PO_REQ_BPA_UOM_CONVERT');
5777 x_conversion_rate number := 1;
5778 x_item_id PO_REQUISITION_LINES_ALL.item_id%TYPE;
5779
5780
5781 x_req_rate PO_REQUISITION_LINES_ALL.rate%TYPE;
5782 x_req_rate_date PO_REQUISITION_LINES_ALL.rate_date%TYPE;
5783 x_req_currency_code PO_REQUISITION_LINES_ALL.currency_code%TYPE;
5784 x_po_currency_code PO_HEADERS_ALL.currency_code%TYPE;
5785 x_pcard_id PO_HEADERS_ALL.pcard_id%TYPE;
5786 x_po_header_id PO_HEADERS_ALL.po_header_id%TYPE;
5787 x_rate PO_REQUISITION_LINES_ALL.rate%TYPE;
5788 x_req_quantity PO_REQUISITION_LINES_ALL.quantity%TYPE;
5789 x_req_unit_price PO_REQUISITION_LINES_ALL.unit_price%TYPE;
5790 x_req_base_unit_price PO_REQUISITION_LINES_ALL.base_unit_price%TYPE;
5791 x_req_amount PO_REQUISITION_LINES_ALL.amount%TYPE;
5792
5793 -- <SERVICES FPJ START>
5794
5795 x_deliver_to_location_id PO_REQUISITION_LINES_ALL.deliver_to_location_id%TYPE;
5796 x_deliver_to_person_id PO_REQUISITION_LINES_ALL.to_person_id%TYPE;
5797 x_destination_type_code PO_REQUISITION_LINES_ALL.destination_type_code%TYPE;
5798 x_destination_organization_id PO_REQUISITION_LINES_ALL.destination_organization_id%TYPE;
5799 x_destination_subinventory PO_REQUISITION_LINES_ALL.destination_subinventory%TYPE;
5800 x_wip_entity_id PO_REQUISITION_LINES_ALL.wip_entity_id%TYPE;
5801 x_wip_line_id PO_REQUISITION_LINES_ALL.wip_line_id%TYPE;
5802 x_wip_repetitive_schedule_id PO_REQUISITION_LINES_ALL.wip_repetitive_schedule_id%TYPE;
5803 x_wip_operation_seq_num PO_REQUISITION_LINES_ALL.wip_operation_seq_num%TYPE;
5804 x_wip_resource_seq_num PO_REQUISITION_LINES_ALL.wip_resource_seq_num%TYPE;
5805 x_bom_resource_id PO_REQUISITION_LINES_ALL.bom_resource_id%TYPE;
5806 x_destination_context PO_REQUISITION_LINES_ALL.destination_context%TYPE;
5807 x_vendor_id PO_REQUISITION_LINES_ALL.vendor_id%TYPE;
5808 x_requesting_ou_id PO_REQUISITION_HEADERS_ALL.org_id%TYPE;
5809
5810 l_req_ou_sob_id GL_SETS_OF_BOOKS.set_of_books_id%TYPE;
5811 l_po_ou_sob_id GL_SETS_OF_BOOKS.set_of_books_id%TYPE;
5812 l_display_rate NUMBER;
5813 l_rate_type PO_HEADERS_INTERFACE.rate_type%TYPE;
5814
5815
5816 --
5817 x_item_inspection_req_flag varchar2(1):=NULL;
5818 x_vendor_receipt_required_flag po_vendors.receipt_required_flag%type := NULL;
5819 x_transaction_flow_header_id PO_LINE_LOCATIONS_ALL.transaction_flow_header_id%TYPE;
5820 --
5821 l_uom_conversion_rate MTL_UOM_CONVERSIONS.conversion_rate%TYPE := 1;
5822 l_currency_conversion_rate PO_HEADERS_ALL.rate%TYPE := 1;
5823 --
5824 -- <SERVICES FPJ END>
5825
5826 g_purchasing_ou_id PO_HEADERS_ALL.org_id%TYPE;
5827 x_po_rate_type PO_HEADERS_ALL.rate_type%TYPE;
5828 x_po_rate_date PO_HEADERS_ALL.rate_date%TYPE;
5829 g_document_subtype varchar2(25);
5830 g_calculate_tax_flag VARCHAR2(1):= 'Y';
5831
5832 --<MRC FPJ Start>
5833 l_return_status VARCHAR2(1);
5834 l_msg_data VARCHAR2(2000);
5835 l_msg_count NUMBER;
5836 --<MRC FPJ End>
5837
5838 l_progress VARCHAR2(3) := '000';
5839 l_procedure_name VARCHAR2(100) := 'create_distributions';
5840 l_log_msg VARCHAR2(2000);
5841
5842
5843
5844 l_amount_ordered NUMBER; --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5845 l_drop_ship_flag po_line_locations.drop_ship_flag%type; --bug#3603067
5846 -- bug 5208159
5847 l_from_type_lookup_code po_headers_all.TYPE_LOOKUP_CODE%type;
5848
5849 --introduced to hold the value of drop_ship_flag for shipments
5850 BEGIN
5851
5852 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
5853 l_log_msg := l_progress||' Create_distributions: po_line_loc_id: '||x_line_location_id;
5854 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
5855
5856 l_log_msg := l_progress||' Create_distributions: po_release_id: '||x_po_release_id;
5857 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
5858
5859 END IF;
5860
5861 /*
5862 ** get previous max distribution number for this shipment
5863 */
5864 l_progress:='010';
5865 SELECT nvl(max(distribution_num), 0)
5866 INTO x_distribution_num
5867 FROM po_distributions_all --<Shared Proc FPJ>
5868 WHERE line_location_id = x_line_location_id;
5869
5870
5871 l_progress:='020';
5872 fnd_profile.get('PO_AUTOCREATE_DATE',x_gl_date_option);
5873
5874 /* Bug 482648 ecso 4/30/97
5875 * Move quantity conversion from setup_interface_tables
5876 * to create_distribution for consistency
5877 */
5878
5879 l_progress := '030';
5880
5881 SELECT order_type_lookup_code
5882 INTO x_order_type_lookup_code
5883 FROM po_line_types
5884 WHERE line_type_id =(SELECT line_type_id
5885 FROM po_requisition_lines_all
5886 WHERE requisition_line_id = x_requisition_line_id);
5887
5888
5889 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
5890 l_log_msg := l_progress||'Create_distributions: Order type: '||x_order_type_lookup_code;
5891 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
5892
5893 END IF;
5894
5895 SELECT PRH.org_id
5896 INTO x_requesting_ou_id
5897 FROM po_requisition_headers_all PRH,
5898 po_Requisition_lines_all PRL
5899 WHERE PRH.requisition_header_id=PRL.requisition_header_id
5900 AND PRL.requisition_line_id = x_requisition_line_id;
5901
5902
5903 l_progress := '040';
5904 SELECT nvl(fsp.purch_encumbrance_flag,'N'),
5905 nvl(fsp.req_encumbrance_flag,'N'),
5906 sob.set_of_books_id,
5907 psp.receiving_flag,
5908 psp.expense_accrual_code
5909 INTO x_po_encumbrance_flag,
5910 x_req_encumbrance_flag,
5911 x_sob_id,
5912 x_receiving_flag,
5913 x_expense_accrual_code
5914 FROM financials_system_parameters fsp,
5915 gl_sets_of_books sob,
5916 po_system_parameters psp,
5917 rcv_parameters rcv
5918 WHERE fsp.set_of_books_id = sob.set_of_books_id
5919 AND rcv.organization_id (+) = fsp.inventory_organization_id;
5920
5921
5922 IF(x_po_encumbrance_flag = 'Y') THEN
5923 po_core_s.get_period_name(x_sob_id,x_period_name,x_date);
5924 END IF;
5925
5926
5927 BEGIN
5928 SELECT PHA.currency_code,
5929 PHA.pcard_id,
5930 PHA.org_id,
5931 PHA.po_header_id,
5932 PHA.rate_type,
5933 PHA.rate_date,
5934 PLL.transaction_flow_header_id
5935 INTO x_po_currency_code,
5936 x_pcard_id,
5937 g_purchasing_ou_id,
5938 x_po_header_id,
5939 x_po_rate_type,
5940 x_po_rate_date,
5941 x_transaction_flow_header_id
5942 FROM po_line_locations_all PLL,
5943 po_headers_all PHA
5944 WHERE PLL.po_header_id = PHA.po_header_id
5945 AND PLL.line_location_id = x_line_location_id;
5946
5947 EXCEPTION
5948 WHEN OTHERS THEN
5949 NULL;
5950 END;
5951
5952
5953
5954 -- <BUG 3422146> Removed IF condition so that we will always get the
5955 -- the precision/extended precision information for the PO currency.
5956 --
5957 -- Bug 4471683: added not null check for currency
5958 IF x_po_currency_code IS NOT NULL THEN
5959 FND_CURRENCY.get_info ( currency_code => x_po_currency_code -- IN
5960 , precision => x_precision -- OUT
5961 , ext_precision => x_ext_precision -- OUT
5962 , min_acct_unit => x_min_unit -- OUT
5963 );
5964 END IF;
5965
5966 l_progress := '050';
5967
5968
5969 Begin
5970 SELECT KANBAN_CARD_ID
5971 INTO x_kanban_card_id
5972 FROM po_requisition_lines_all pol --<Shared Proc FPJ>
5973 WHERE pol.REQUISITION_LINE_ID = x_requisition_line_id;
5974 Exception
5975 WHEN NO_DATA_FOUND THEN
5976 /* Not all req has kanban id */
5977
5978 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
5979 l_log_msg := l_progress||'NO_DATA_FOUND: '||SQLERRM;
5980 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
5981
5982 END IF;
5983
5984 WHEN OTHERS THEN
5985 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
5986 l_log_msg := l_progress||'OTHER EXCEPTON: '||SQLERRM;
5987 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
5988
5989 END IF;
5990
5991 raise;
5992 End;
5993
5994
5995 if(x_pcard_id is not null) then
5996 x_accrued_flag := 'Y';
5997 else
5998 x_accrued_flag := 'N';
5999 end if;
6000
6001 l_progress:='060';
6002
6003
6004 /* also use fnd_application table to find the application_id */
6005 SELECT application_id
6006 INTO x_po_appl_id
6007 FROM fnd_application
6008 WHERE application_short_name = 'PO';
6009
6010 l_progress := '070';
6011 SELECT application_id
6012 INTO x_gl_appl_id
6013 FROM fnd_application
6014 WHERE application_short_name = 'SQLGL';
6015
6016
6017
6018 if ((x_po_encumbrance_flag = 'Y') and
6019 (x_gl_date_option <> 'REQ GL DATE') and
6020 (x_period_name IS NULL)) THEN
6021
6022 l_progress := '080';
6023 SELECT PS1.period_name
6024 INTO x_period_name
6025 FROM GL_PERIOD_STATUSES PS1
6026 , GL_PERIOD_STATUSES PS2
6027 , GL_SETS_OF_BOOKS GSOB
6028 WHERE PS1.application_id = x_gl_appl_id
6029 AND PS1.set_of_books_id = x_sob_id
6030 AND PS1.adjustment_period_flag = 'N'
6031 AND trunc(sysdate) BETWEEN trunc(PS1.start_date)
6032 AND trunc(PS1.end_date)
6033 AND ps1.period_year <= gsob.latest_encumbrance_year
6034 AND gsob.set_of_books_id = x_sob_id
6035 AND PS1.period_name = PS2.period_name
6036 AND PS2.application_id = x_po_appl_id
6037 AND PS2.adjustment_period_flag = 'N'
6038 AND PS2.set_of_books_id = x_sob_id;
6039
6040
6041 end if;
6042
6043
6044
6045 l_progress := '090';
6046
6047 SELECT pol.unit_meas_lookup_code
6048 INTO x_po_uom
6049 FROM po_lines_all pol , --<Shared Proc FPJ>
6050 po_line_locations_all pll --<Shared Proc FPJ>
6051 WHERE pol.po_line_id = pll.po_line_id
6052 AND pll.line_location_id = x_line_location_id;
6053
6054
6055 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
6056 l_log_msg := l_progress||'Create_distributions: PO UOM is: '||x_po_uom;
6057 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
6058
6059 END IF;
6060
6061
6062 l_progress := '100';
6063
6064 SELECT unit_meas_lookup_code,
6065 item_id
6066 INTO x_req_uom,
6067 x_item_id
6068 FROM po_requisition_lines_all prl
6069 WHERE prl.requisition_line_id = x_requisition_line_id;
6070
6071
6072
6073 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
6074 l_log_msg := l_progress||'Create_distributions: Req UOM is: '||x_req_uom;
6075 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
6076
6077 END IF;
6078
6079
6080 l_progress := '110';
6081 /* before inserting into the distributions table get the conversion rate to convert
6082 into the BPA uom if the uom's on the req and BPA are different .
6083 This conversion is done only if the Convert UOM profile option is set to Yes. */
6084
6085 if x_req_uom <> x_po_uom then
6086
6087 x_conversion_rate := po_uom_s.po_uom_convert(x_req_uom,
6088 x_po_uom,
6089 x_item_id);
6090 else
6091
6092 x_conversion_rate := 1;
6093
6094 end if;
6095
6096 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
6097 l_log_msg := l_progress||'Create_distributions: Conversion rate is: '||x_conversion_rate;
6098 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
6099
6100 END IF;
6101
6102
6103 l_progress := '120';
6104
6105 l_uom_conversion_rate := x_conversion_rate; -- <SERVICES FPJ>
6106 -- <ACHTML R12>
6107
6108 l_progress := '130';
6109
6110
6111
6112
6113 l_progress := '150';
6114
6115 --update_award_distributions;
6116
6117 --<GRANTS FPJ END>
6118
6119 l_progress := '170';
6120
6121
6122 --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6123
6124 begin
6125 select nvl(drop_ship_flag,'N') into l_drop_ship_flag
6126 from po_line_locations_all where
6127 line_location_id=x_line_location_id;
6128 exception
6129 when others then
6130 null;
6131 end;
6132
6133
6134 -- No conversion for same currency.
6135
6136 BEGIN
6137 SELECT PRL.currency_code,
6138 PRL.rate,
6139 PRL.quantity,
6140 PRL.unit_price,
6141 PRL.base_unit_price,
6142 PRL.amount,
6143 PRL.deliver_to_location_id,
6144 PRL.to_person_id,
6145 PRL.destination_type_code,
6146 PRL.destination_organization_id,
6147 PRL.destination_subinventory,
6148 PRL.wip_entity_id,
6149 PRL.wip_line_id,
6150 PRL.wip_repetitive_schedule_id,
6151 PRL.wip_operation_seq_num,
6152 PRL.wip_resource_seq_num,
6153 PRL.bom_resource_id,
6154 PRL.destination_context,
6155 PRL.vendor_id
6156 INTO x_req_currency_code,
6157 x_req_rate,
6158 x_req_quantity,
6159 x_req_unit_price,
6160 x_req_base_unit_price,
6161 x_req_amount,
6162 x_deliver_to_location_id,
6163 x_deliver_to_person_id,
6164 x_destination_type_code,
6165 x_destination_organization_id,
6166 x_destination_subinventory,
6167 x_wip_entity_id,
6168 x_wip_line_id,
6169 x_wip_repetitive_schedule_id,
6170 x_wip_operation_seq_num,
6171 x_wip_resource_seq_num,
6172 x_bom_resource_id,
6173 x_destination_context,
6174 x_vendor_id
6175 FROM po_requisition_lines_all PRL
6176 WHERE PRL.requisition_line_id = x_requisition_line_id;
6177
6178 EXCEPTION
6179 WHEN OTHERS THEN
6180 NULL;
6181 END;
6182
6183
6184 BEGIN
6185
6186 SELECT msi.inspection_required_flag
6187 INTO x_item_inspection_req_flag
6188 FROM mtl_system_items msi
6189 WHERE msi.inventory_item_id = x_item_id
6190 AND msi.organization_id = x_destination_organization_id;
6191
6192 EXCEPTION
6193 WHEN NO_DATA_FOUND THEN
6194 x_item_inspection_req_flag:= 'N';
6195 END;
6196
6197
6198 BEGIN
6199 SELECT v.receipt_required_flag
6200 INTO x_vendor_receipt_required_flag
6201 FROM po_vendors v
6202 WHERE v.vendor_id = x_vendor_id;
6203
6204
6205 EXCEPTION
6206 WHEN NO_DATA_FOUND THEN
6207 x_vendor_receipt_required_flag:= 'N';
6208 END;
6209
6210 IF g_purchasing_ou_id <> x_requesting_ou_id THEN
6211
6212 select req_fsp.set_of_books_id
6213 into l_req_ou_sob_id
6214 from financials_system_params_all req_fsp
6215 where req_fsp.org_id = x_requesting_ou_id; -- <ACHTML R12>
6216
6217 l_progress := '010';
6218 select po_fsp.set_of_books_id
6219 into l_po_ou_sob_id
6220 from financials_system_params_all po_fsp
6221 where po_fsp.org_id = g_purchasing_ou_id; -- <ACHTML R12>
6222
6223 IF l_req_ou_sob_id = l_po_ou_sob_id THEN
6224 x_rate_for_req_fields := NULL;
6225 ELSE
6226 IF x_po_rate_type is NULL THEN
6227
6228 select default_rate_type
6229 into l_rate_type
6230 from po_system_parameters_all psp
6231 where psp.org_id = g_purchasing_ou_id; -- <ACHTML R12>
6232 ELSE
6233 l_rate_type := x_po_rate_type;
6234 END IF;
6235
6236 po_currency_sv.get_rate(l_req_ou_sob_id,
6237 x_po_currency_code,
6238 x_po_rate_type,
6239 x_po_rate_date,
6240 'N',
6241 x_rate_for_req_fields,
6242 l_display_rate);
6243
6244 END IF;
6245
6246 END IF;
6247
6248 IF ( x_req_currency_code = x_po_currency_code ) THEN
6249 x_rate:=Nvl(x_req_rate,1);
6250 ELSE
6251 x_rate:=x_rate_for_req_fields;
6252 END IF;
6253
6254 l_currency_conversion_rate := x_rate_for_req_fields; -- <SERVICES FPJ>
6255
6256 --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6257
6258 INSERT INTO po_distributions_all --<Shared Proc FPJ>
6259 (po_distribution_id,
6260 last_update_date,
6261 last_updated_by,
6262 po_header_id,
6263 creation_date,
6264 created_by,
6265 last_update_login,
6266 po_line_id,
6267 line_location_id,
6268 po_release_id,
6269 req_distribution_id,
6270 set_of_books_id,
6271 code_combination_id,
6272 deliver_to_location_id,
6273 deliver_to_person_id,
6274 quantity_ordered,
6275 quantity_delivered,
6276 quantity_billed,
6277 quantity_cancelled,
6278 amount_ordered, -- <SERVICES FPJ>
6279 amount_delivered, -- <SERVICES FPJ>
6280 amount_cancelled, -- <SERVICES FPJ>
6281 amount_billed, -- <SERVICES FPJ>
6282 rate_date,
6283 rate,
6284 accrued_flag,
6285 encumbered_flag,
6286 gl_encumbered_date,
6287 gl_encumbered_period_name,
6288 distribution_num,
6289 destination_type_code,
6290 destination_organization_id,
6291 destination_subinventory,
6292 budget_account_id,
6293 accrual_account_id,
6294 variance_account_id,
6295
6296 --< Shared Proc FPJ Start >
6297 dest_charge_account_id,
6298 dest_variance_account_id,
6299 --< Shared Proc FPJ End >
6300
6301 wip_entity_id,
6302 wip_line_id,
6303 wip_repetitive_schedule_id,
6304 wip_operation_seq_num,
6305 wip_resource_seq_num,
6306 bom_resource_id,
6307 prevent_encumbrance_flag,
6308 project_id,
6309 task_id,
6310 end_item_unit_number,
6311 expenditure_type,
6312 project_accounting_context,
6313 destination_context,
6314 expenditure_organization_id,
6315 expenditure_item_date,
6316 accrue_on_receipt_flag,
6317 kanban_card_id,
6318 tax_recovery_override_flag, --<eTax Integration R12>
6319 recovery_rate,
6320 award_id,
6321 --togeorge 09/27/2000
6322 --added oke columns
6323 oke_contract_line_id,
6324 oke_contract_deliverable_id,
6325 org_id, --<Shared Proc FPJ>
6326 distribution_type, -- <Encumbrance FPJ>
6327 tax_attribute_update_code, --<eTax Integration R12>
6328 interface_distribution_ref --<ECO 5373370>
6329 -- <<CLM Partial Funding Code Changes>>
6330 ,partial_funded_flag,
6331 funded_value,
6332 quantity_funded,
6333 amount_funded,
6334 change_in_funded_value,
6335 -- <<CLM Partial Funding Code Changes>>
6336 acrn
6337 )
6338 SELECT po_distributions_s.NEXTVAL, --<GRANTS FPJ>
6339 sysdate,
6340 FND_GLOBAL.USER_ID,
6341 x_po_header_id,
6342 sysdate,
6343 FND_GLOBAL.USER_ID,
6344 FND_GLOBAL.LOGIN_ID,
6345 (SELECT po_line_id
6346 FROM po_line_locations_all
6347 WHERE line_location_id = x_line_location_id),
6348 x_line_location_id,
6349 nvl(x_po_release_id,''),
6350 x_requisition_dist_id,
6351 nvl(x_sob_id, prd.set_of_books_id), --<Bug 3692789>
6352 prd.code_combination_id,
6353 x_deliver_to_location_id,
6354 decode(l_drop_ship_flag,'Y',NULL,x_deliver_to_person_id),
6355 decode(
6356 x_order_type_lookup_code,
6357 'QUANTITY',
6358 round((req_line_quantity * x_conversion_rate), 15),
6359 'AMOUNT',
6360 round(
6361 (prd.req_line_quantity
6362 * x_conversion_rate
6363 / x_rate), -- <ACHTML R12>
6364 nvl(x_ext_precision, 15)
6365 ),
6366 NULL
6367 ),
6368 -- <SERVICES FPJ END>
6369
6370 0,
6371 0,
6372 0,
6373
6374 -- <SERVICES FPJ START>
6375 decode ( x_order_type_lookup_code -- amount_ordered
6376 , 'RATE' ,round ( ( req_line_quantity
6377 * l_uom_conversion_rate
6378 / l_currency_conversion_rate)
6379 , x_precision )
6380 , 'FIXED PRICE',round ( ( req_line_quantity
6381 / l_currency_conversion_rate)
6382 , x_precision )
6383 ,NULL
6384 ),
6385 0, -- amount_delivered
6386 0, -- amount_cancelled
6387 0, -- amount_billed
6388 -- <SERVICES FPJ END>
6389
6390 x_req_rate_date,
6391 x_req_rate,
6392 x_accrued_flag,
6393 'N'
6394
6395 --<Encumbrance FPJ>
6396 -- If Req encumbrance is on and the profile option requests
6397 -- that the Req's GL date be used, use the Req's GL date.
6398 -- Otherwise, if PO enc is on, use SYSDATE.
6399 -- if PO enc is not on, use NULL.
6400
6401 -- gl_encumbered_date =
6402 , NVL( DECODE( x_req_encumbrance_flag
6403 , 'Y', DECODE( x_gl_date_option
6404 , 'REQ GL DATE', prd.gl_encumbered_date
6405 , NULL
6406 )
6407 , NULL
6408 )
6409 , DECODE( x_po_encumbrance_flag
6410 , 'Y', TRUNC(SYSDATE)
6411 , NULL
6412 )
6413 )
6414
6415 -- gl_encumbered_period_name =
6416 , NVL( DECODE( x_req_encumbrance_flag
6417 , 'Y', DECODE(x_gl_date_option
6418 , 'REQ GL DATE', prd.gl_encumbered_period_name
6419 , NULL
6420 )
6421 , NULL
6422 )
6423 , DECODE( x_po_encumbrance_flag
6424 , 'Y', x_period_name
6425 , NULL
6426 )
6427 )
6428
6429 , x_distribution_num +1, --<GRANTS FPJ>
6430 x_destination_type_code,
6431 x_destination_organization_id,
6432 x_destination_subinventory,
6433 prd.budget_account_id,
6434 prd.accrual_account_id,
6435 prd.variance_account_id,
6436
6437 --< Shared Proc FPJ Start >
6438 -- Copy the receiving accounts from the interface table to
6439 -- the PO table.
6440 null, --pdi.dest_charge_account_id,
6441 null, --pdi.dest_variance_account_id,
6442 --< Shared Proc FPJ End >
6443
6444 x_wip_entity_id,
6445 x_wip_line_id,
6446 x_wip_repetitive_schedule_id,
6447 x_wip_operation_seq_num,
6448 x_wip_resource_seq_num,
6449 x_bom_resource_id
6450 --<ENCUMBRANCE FPJ>
6451 -- prevent_encumbrance_flag =
6452 , DECODE( x_destination_type_code
6453 , 'SHOP FLOOR', 'Y'
6454 , 'N'
6455 )
6456 , prd.project_id,
6457 prd.task_id,
6458 prd.end_item_unit_number,
6459 prd.expenditure_type,
6460 prd.project_accounting_context,
6461 x_destination_context,
6462 prd.expenditure_organization_id,
6463 prd.expenditure_item_date,
6464 decode(x_transaction_flow_header_id, NULL, --<Shared Proc FPJ>
6465 DECODE(x_destination_type_code,
6466 'EXPENSE',
6467 decode(nvl(x_item_inspection_req_flag,
6468 nvl(x_vendor_receipt_required_flag,
6469 nvl(x_receiving_flag,'N'))),
6470 'N', 'N',
6471 decode(x_expense_accrual_code,
6472 'PERIOD END', 'N', 'Y')),
6473 'INVENTORY', 'Y',
6474 'SHOP FLOOR', 'Y'),
6475 'Y'), --<Shared Proc FPJ>
6476 x_kanban_card_id,
6477 prd.tax_recovery_override_flag, --<eTax integration R12>
6478 decode(prd.tax_recovery_override_flag, 'Y', prd.recovery_rate, null), --<eTax integration R12>
6479 prd.award_id, -- OGM_0.0 changes..
6480 --togeorge 09/27/2000
6481 --added oke columns
6482 prd.oke_contract_line_id,
6483 prd.oke_contract_deliverable_id,
6484 g_purchasing_ou_id, --<Shared Proc FPJ>
6485 (SELECT shipment_type
6486 FROM po_line_locations_all
6487 WHERE line_location_id = x_line_location_id), --poll.shipment_type, -- <Encumbrance FPJ: join on poll.line_location_id added>
6488 nvl2(g_calculate_tax_flag, 'CREATE', null), --<eTax integration R12>
6489 null --pdi.interface_distribution_ref --<ECO 5373370>
6490 -- <<CLM Partial Funding Code Changes>>
6491 ,prd.partial_funded_flag,
6492 prd.funded_value,
6493 prd.quantity_funded,
6494 prd.amount_funded,
6495 prd.change_in_funded_value,
6496 -- <<CLM Partial Funding Code Changes>>
6497 prd.acrn
6498 FROM po_req_distributions_all prd
6499 WHERE prd.distribution_id = x_requisition_dist_id;
6500
6501
6502 --
6503 --PO_INTERFACE_S.calibrate_last_dist_amount(x_line_location_id);
6504
6505
6506 l_progress := '210';
6507 /* Bug 1030123: Since there may be more than a distribution, we need to
6508 loop thru all the distribution based on the line id */
6509
6510
6511
6512 EXCEPTION
6513 WHEN OTHERS THEN
6514
6515 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
6516 l_log_msg := l_progress||'CException: '||SQLERRM;
6517 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
6518
6519 END IF;
6520 po_message_s.sql_error('CREATE_DISTRIBUTIONS',l_progress,sqlcode);
6521 raise;
6522 END create_distributions;
6523
6524
6525
6526 /**************************************************************************************************
6527 *
6528 * NAME
6529 * implement_dist_auto
6530 *
6531 *
6532 *
6533 * HISTORY
6534 * 23-09-09 Bisdas Created
6535 **************************************************************************************************/
6536
6537 PROCEDURE implement_dist_auto(x_req_line_id IN NUMBER)
6538 IS
6539
6540
6541 l_progress VARCHAR2(3);
6542 l_procedure_name VARCHAR2(100) := 'implement_dist_auto';
6543 l_log_msg VARCHAR2(2000);
6544
6545 CURSOR valid_lines(req_line_id NUMBER) IS
6546 SELECT 1
6547 FROM po_requisition_lines_all prl,
6548 po_req_distributions_all prd
6549 WHERE prl.requisition_line_id = req_line_id
6550 AND prl.requisition_line_id = Nvl(prd.info_line_id,prd.requisition_line_id)
6551 AND
6552 ( (prl.amendment_type = 'ADDED' AND
6553 prl.clm_info_flag='Y' AND
6554 prl.amendment_status IN ('N','P')
6555 )
6556 OR
6557 (prl.amendment_type = 'CHANGED' AND
6558 prl.amendment_status IN ('N','P') AND
6559 prd.amendment_type IN ('ADDED') AND
6560 prd.amendment_status IN ('N','P')
6561 )
6562 );
6563
6564
6565 l_temp NUMBER;
6566
6567 BEGIN
6568
6569 l_progress :='000';
6570 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
6571 l_log_msg := 'Invoked '||l_procedure_name;
6572 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
6573 END IF;
6574
6575 OPEN valid_lines(x_req_line_id);
6576
6577 LOOP
6578 FETCH valid_lines INTO l_temp;
6579 EXIT WHEN valid_lines%NOTFOUND;
6580
6581 po_auto_implement_pvt.process(x_req_line_id);
6582
6583 END LOOP;
6584
6585 CLOSE valid_lines;
6586
6587
6588 EXCEPTION
6589 WHEN OTHERS THEN
6590
6591 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
6592 l_log_msg := l_progress||'Exception: '||SQLERRM;
6593 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
6594
6595 END IF;
6596 raise;
6597 END implement_dist_auto;
6598
6599 /**************************************************************************************************
6600 *
6601 * NAME
6602 * implement_slin_auto
6603 *
6604 *
6605 *
6606 * HISTORY
6607 * 18-05-10 Rohit Created
6608 **************************************************************************************************/
6609
6610 PROCEDURE implement_slin_auto(x_req_line_id IN NUMBER,dest_doc_id IN varchar2)
6611 IS
6612
6613
6614 l_progress VARCHAR2(3);
6615 l_procedure_name VARCHAR2(100) := 'implement_slin_auto';
6616 l_log_msg VARCHAR2(2000);
6617
6618 auction_id NUMBER;
6619 x_result NUMBER;
6620 x_error_code VARCHAR2(2000);
6621 x_error_message VARCHAR2 (2000) ;
6622
6623 BEGIN
6624
6625 l_progress :='000';
6626 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
6627 l_log_msg := 'Invoked '||l_procedure_name;
6628 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
6629 END IF;
6630
6631 IF dest_doc_id IS NOT NULL THEN
6632 auction_id := To_Number(dest_doc_id);
6633 ELSE
6634 SELECT clin.auction_header_id
6635 INTO auction_id
6636 FROM po_requisition_lines_all clin,
6637 po_requisition_lines_all slin
6638 WHERE slin.requisition_line_id = x_req_line_id
6639 AND slin.group_line_id = clin.requisition_line_id
6640 AND slin.amendment_type IN ('ADDED')
6641 AND slin.amendment_status IN ('N')
6642 AND slin.group_line_id IS NOT NULL ;
6643 END IF;
6644
6645 l_progress :='001';
6646 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
6647 l_log_msg := 'valid slin found in'||l_procedure_name;
6648 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
6649 END IF;
6650
6651 po_negotiations_sv1.add_line_to_negotiation(auction_id,x_req_line_id,x_result,x_error_code,x_error_message );
6652
6653
6654 l_progress :='002';
6655 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
6656 l_log_msg := 'sourcing API called in '||l_procedure_name;
6657 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
6658 END IF;
6659
6660
6661 EXCEPTION
6662 WHEN NO_DATA_FOUND THEN
6663 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
6664 l_log_msg := l_progress||'No Valid Slin Found '||SQLERRM;
6665 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
6666 l_log_msg := 'x_error_code:'|| x_error_code|| ' x_error_message:'||x_error_message;
6667 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
6668
6669 END IF;
6670
6671
6672 WHEN OTHERS THEN
6673
6674 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
6675 l_log_msg := l_progress||'Exception: '||SQLERRM;
6676 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
6677 l_log_msg := 'x_error_code:'|| x_error_code|| ' x_error_message:'||x_error_message;
6678 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
6679
6680
6681 END IF;
6682 raise;
6683 END implement_slin_auto;
6684
6685 /*********************************************************************
6686 * NAME
6687 * compare_for_implement
6688 *
6689 * PURPOSE
6690 * Compare the PR Amendment line with the accepted revision
6691 * ---including all lines and distributions.
6692 *
6693 * ARGUMENTS
6694 *
6695 * p_req_line_id Req line id of the line
6696 *
6697 * p_sequence_num Sequence number to identify the comparison
6698 * results for a specific record in
6699 * ICX_PO_REVISIONS_TEMP table.
6700 *
6701 * NOTES
6702 *
6703 * HISTORY
6704 * 25-09-2009 bisdas Created
6705 ********************************************************************/
6706
6707 PROCEDURE compare_for_implement(p_conformed_req_line_id IN NUMBER,
6708 p_sequence_num IN OUT NOCOPY NUMBER) AS
6709
6710 v_sequence_num NUMBER;
6711 v_progress VARCHAR2(3);
6712 l_procedure_name VARCHAR2(100) := 'compare_for_implement';
6713 l_log_msg VARCHAR2(2000);
6714
6715 x_line_id NUMBER;
6716 x_amendment_num VARCHAR2(25);
6717 p_level VARCHAR2(10):= 'LINES';
6718
6719 sql_stmt1 VARCHAR2(20000);
6720 sql_stmt2 VARCHAR2(20000);
6721
6722 l_revision_num NUMBER;
6723 l_line_num NUMBER;
6724 l_line_num_disp VARCHAR2(100);
6725 l_cnt NUMBER;
6726
6727 retcount NUMBER;
6728 BEGIN
6729
6730 v_progress := '000';
6731
6732 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
6733 l_log_msg := 'Inside procedure '||l_procedure_name;
6734 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
6735 END IF;
6736
6737 rec_index := 1;
6738
6739 --p_sequence_num:=10001;
6740 v_progress := '001';
6741
6742 IF p_sequence_num = 0 THEN
6743 SELECT icx_po_history_details_s.nextval
6744 INTO p_sequence_num
6745 FROM DUAL;
6746 END IF;
6747
6748 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
6749 l_log_msg := v_progress||' : Getting sequence number: '||p_sequence_num;
6750 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
6751 END IF;
6752
6753 SELECT getLatestAmendmentNum(prh.requisition_header_id)
6754 INTO x_amendment_num
6755 FROM po_requisition_headers_all prh
6756 WHERE prh.requisition_header_id = (SELECT requisition_header_id
6757 FROM po_requisition_lines_all
6758 WHERE requisition_line_id = p_conformed_req_line_id);
6759
6760 SELECT Max(requisition_line_id)
6761 INTO x_line_id
6762 FROM po_requisition_lines_all
6763 WHERE conformed_line_id = p_conformed_req_line_id
6764 AND amendment_type = 'CHANGED'
6765 AND amendment_status IN ('A','R');
6766
6767 IF x_line_id IS NULL THEN
6768 SELECT Min(requisition_line_id)
6769 INTO x_line_id
6770 FROM po_requisition_lines_all
6771 WHERE conformed_line_id = p_conformed_req_line_id;
6772 END IF;
6773
6774
6775 v_progress := '005';
6776
6777 IF x_line_id IS NOT NULL THEN
6778
6779 compare_table_for_implement('PO_REQUISITION_LINES_ALL',
6780 p_conformed_req_line_id,
6781 x_line_id,
6782 p_sequence_num,
6783 x_amendment_num);
6784
6785 compare_table_for_implement('PO_REQ_DISTRIBUTIONS_ALL',
6786 p_conformed_req_line_id,
6787 x_line_id,
6788 p_sequence_num,
6789 x_amendment_num);
6790 ELSE
6791 --this means this is a new line added during amendment.
6792 SELECT line_num,line_num_display
6793 INTO l_line_num,l_line_num_disp
6794 FROM po_requisition_lines_all
6795 WHERE requisition_line_id = p_conformed_req_line_id;
6796
6797 SELECT revision_num INTO l_revision_num
6798 FROM po_requisition_headers_all
6799 WHERE segment1=x_amendment_num;
6800
6801 INSERT INTO icx_po_revisions_temp(
6802 header_id,
6803 line_seq,
6804 creation_date,
6805 po_num,
6806 revision_num,
6807 line_num,
6808 distribution_num,
6809 level_altered,
6810 item_id,
6811 field_altered,
6812 changes_from,
6813 changes_to,
6814 line_num_display
6815 )
6816 VALUES
6817 (
6818 p_conformed_req_line_id,
6819 p_sequence_num,
6820 SYSDATE,
6821 x_amendment_num,
6822 l_revision_num,
6823 l_line_num,
6824 NULL,
6825 'LINES',
6826 NULL,
6827 'New',
6828 NULL,
6829 NULL,
6830 l_line_num_disp
6831 );
6832
6833 SELECT Count(*) INTO l_cnt
6834 FROM po_req_distributions_all
6835 WHERE info_line_id = p_conformed_req_line_id;
6836
6837 IF l_cnt > 0 THEN
6838 --New we need to insert the distribution value
6839 FOR i IN 1..l_cnt LOOP
6840 INSERT INTO icx_po_revisions_temp(
6841 header_id,
6842 line_seq,
6843 creation_date,
6844 po_num,
6845 revision_num,
6846 line_num,
6847 distribution_num,
6848 level_altered,
6849 item_id,
6850 field_altered,
6851 changes_from,
6852 changes_to,
6853 line_num_display
6854 )
6855 VALUES
6856 (
6857 p_conformed_req_line_id,
6858 p_sequence_num,
6859 SYSDATE,
6860 x_amendment_num,
6861 l_revision_num,
6862 l_line_num,
6863 i,
6864 'DIST',
6865 NULL,
6866 'New',
6867 NULL,
6868 NULL,
6869 l_line_num_disp
6870 );
6871 END LOOP;
6872 END IF;
6873
6874 END IF;
6875
6876 EXCEPTION
6877 WHEN others THEN
6878
6879 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
6880 l_log_msg := v_progress||' : Exception : '|| SQLERRM;
6881 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
6882 END IF;
6883 RAISE;
6884
6885 END compare_for_implement;
6886
6887
6888
6889 /*********************************************************************
6890 * NAME
6891 * compare_table
6892 *
6893 * PURPOSE
6894 * Checks for the changes in Header, Line and Distribution level and populates
6895 * the temp table with field altered, old value and new value.
6896 *
6897 * ARGUMENTS
6898 * p_table_name IN Table name, possible values:
6899 * PO_REQUISITION_HEADERS_ALL
6900 * PO_REQUISITION_LINES_ALL
6901 * PO_REQ_DISTRIBUTIONS_ALL
6902 * p_revision_num IN
6903 * p_confirmed_id IN
6904 * amend_num OUT
6905 *
6906 * NOTES
6907 *
6908 *
6909 * HISTORY
6910 * 11-07-09 Bisdas Created
6911 ********************************************************************/
6912
6913 PROCEDURE compare_table_for_implement(p_table_name VARCHAR2,
6914 p_from_req_line_id NUMBER,
6915 p_to_req_line_id NUMBER,
6916 p_sequence_num NUMBER,
6917 p_amend_num IN VARCHAR2)
6918 AS
6919
6920 sql_stmt1 VARCHAR2(20000);
6921 sql_stmt2 VARCHAR2(20000);
6922
6923 p_level VARCHAR2(50);
6924 x_amendment_num VARCHAR2(100) := p_amend_num;
6925
6926 --Debugging purpose
6927 v_progress VARCHAR2(3);
6928 l_procedure_name VARCHAR2(100) := 'compare_table_for_implement';
6929 l_log_msg VARCHAR2(2000);
6930
6931
6932 BEGIN
6933
6934 v_progress:='000';
6935 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
6936 l_log_msg := 'Invoked '||l_procedure_name;
6937 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
6938 END IF;
6939
6940 -- SQL What: Querying the archive table for the given revision_num and previous revision_num
6941 -- SQL Why: Need to compare the values for each column
6942
6943 po_num_tab.delete(1,po_num_tab.Count);
6944 line_num_tab.delete(1,line_num_tab.Count);
6945 distribution_num_tab.delete(1,distribution_num_tab.Count);
6946 level_altered_tab.delete(1,level_altered_tab.Count);
6947 field_altered_tab.delete(1,field_altered_tab.Count);
6948 changes_from_tab.delete(1,changes_from_tab.Count);
6949 changes_to_tab.delete(1,changes_to_tab.Count);
6950 line_num_disp_tab.delete(1,line_num_disp_tab.Count);
6951
6952 rec_index := 1;
6953
6954
6955 IF p_table_name = 'PO_REQUISITION_LINES_ALL' THEN
6956
6957
6958 sql_stmt1 := 'SELECT REQUISITION_LINE_ID,LINE_NUM, LINE_NUM_DISPLAY,nvl(prl.CANCEL_FLAG,''N'') CANCEL_FLAG, nvl(prl.CLOSED_CODE,''OPEN'') CLOSED_CODE,ITEM_ID,ITEM_REVISION,
6959 ITEM_DESCRIPTION, CATEGORY_ID, UNIT_MEAS_LOOKUP_CODE, UNIT_PRICE,QUANTITY,DELIVER_TO_LOCATION_ID,TO_PERSON_ID,
6960 SUGGESTED_BUYER_ID,to_char(NEED_BY_DATE,''DD-MON-YYYY HH24:MI:SS'') NEED_BY_DATE,JUSTIFICATION,NOTE_TO_AGENT,NOTE_TO_RECEIVER,CURRENCY_CODE,RATE_TYPE,to_char(RATE_DATE,''DD-MON-YYYY HH24:MI:SS'') RATE_DATE,
6961 RATE,CURRENCY_UNIT_PRICE,SUGGESTED_VENDOR_NAME,SUGGESTED_VENDOR_LOCATION,SUGGESTED_VENDOR_CONTACT,SUGGESTED_VENDOR_PHONE,
6962 SUGGESTED_VENDOR_PRODUCT_CODE,HAZARD_CLASS_ID,DESTINATION_TYPE_CODE,DESTINATION_ORGANIZATION_ID, DESTINATION_SUBINVENTORY,
6963 VENDOR_ID,VENDOR_SITE_ID, VENDOR_CONTACT_ID,prl.USSGL_TRANSACTION_CODE USSGL_TRANSACTION_CODE, MANUFACTURER_NAME,
6964 MANUFACTURER_PART_NUMBER, REQUESTER_EMAIL,REQUESTER_FAX,REQUESTER_PHONE, UNSPSC_CODE, SUPPLIER_DUNS,AMOUNT,
6965 CURRENCY_AMOUNT,JOB_LONG_DESCRIPTION,SUGGESTED_VENDOR_CONTACT_FAX,SUGGESTED_VENDOR_CONTACT_EMAIL,CANDIDATE_FIRST_NAME,
6966 CANDIDATE_LAST_NAME,to_char(ASSIGNMENT_START_DATE,''DD-MON-YYYY HH24:MI:SS'') ASSIGNMENT_START_DATE,CONTRACT_TYPE,COST_CONSTRAINT,
6967 to_char(CLM_PERIOD_PERF_START_DATE,''DD-MON-YYYY HH24:MI:SS'') CLM_PERIOD_PERF_START_DATE,to_char(CLM_PERIOD_PERF_END_DATE,''DD-MON-YYYY HH24:MI:SS'') CLM_PERIOD_PERF_END_DATE,
6968 nvl(CLM_OPTION_EXERCISED,''N'') CLM_OPTION_EXERCISED, CLM_OPTION_FROM_DATE, CLM_OPTION_TO_DATE,CLM_OPTION_INDICATOR , CLM_BASE_LINE_NUM , CLM_MIPR_OBLIGATION_TYPE
6969 FROM po_requisition_lines_all prl
6970 WHERE prl.requisition_line_id='||p_to_req_line_id||
6971 'ORDER BY LINE_NUM';
6972
6973 sql_stmt2 := 'SELECT REQUISITION_LINE_ID,LINE_NUM, LINE_NUM_DISPLAY,nvl(prl.CANCEL_FLAG,''N'') CANCEL_FLAG, nvl(prl.CLOSED_CODE,''OPEN'') CLOSED_CODE,ITEM_ID,ITEM_REVISION,
6974 ITEM_DESCRIPTION, CATEGORY_ID, UNIT_MEAS_LOOKUP_CODE, UNIT_PRICE,QUANTITY,DELIVER_TO_LOCATION_ID,TO_PERSON_ID,
6975 SUGGESTED_BUYER_ID,to_char(NEED_BY_DATE,''DD-MON-YYYY HH24:MI:SS'') NEED_BY_DATE,JUSTIFICATION,NOTE_TO_AGENT,NOTE_TO_RECEIVER,CURRENCY_CODE,RATE_TYPE,to_char(RATE_DATE,''DD-MON-YYYY HH24:MI:SS'') RATE_DATE,
6976 RATE,CURRENCY_UNIT_PRICE,SUGGESTED_VENDOR_NAME,SUGGESTED_VENDOR_LOCATION,SUGGESTED_VENDOR_CONTACT,SUGGESTED_VENDOR_PHONE,
6977 SUGGESTED_VENDOR_PRODUCT_CODE,HAZARD_CLASS_ID,DESTINATION_TYPE_CODE,DESTINATION_ORGANIZATION_ID, DESTINATION_SUBINVENTORY,
6978 VENDOR_ID,VENDOR_SITE_ID, VENDOR_CONTACT_ID,prl.USSGL_TRANSACTION_CODE USSGL_TRANSACTION_CODE, MANUFACTURER_NAME,
6979 MANUFACTURER_PART_NUMBER, REQUESTER_EMAIL,REQUESTER_FAX,REQUESTER_PHONE, UNSPSC_CODE, SUPPLIER_DUNS,AMOUNT,
6980 CURRENCY_AMOUNT,JOB_LONG_DESCRIPTION,SUGGESTED_VENDOR_CONTACT_FAX,SUGGESTED_VENDOR_CONTACT_EMAIL,CANDIDATE_FIRST_NAME,
6981 CANDIDATE_LAST_NAME,to_char(ASSIGNMENT_START_DATE,''DD-MON-YYYY HH24:MI:SS'') ASSIGNMENT_START_DATE,CONTRACT_TYPE,COST_CONSTRAINT,
6982 to_char(CLM_PERIOD_PERF_START_DATE,''DD-MON-YYYY HH24:MI:SS'') CLM_PERIOD_PERF_START_DATE,to_char(CLM_PERIOD_PERF_END_DATE,''DD-MON-YYYY HH24:MI:SS'') CLM_PERIOD_PERF_END_DATE,
6983 nvl(CLM_OPTION_EXERCISED,''N'') CLM_OPTION_EXERCISED, CLM_OPTION_FROM_DATE, CLM_OPTION_TO_DATE, CLM_OPTION_INDICATOR, CLM_BASE_LINE_NUM , CLM_MIPR_OBLIGATION_TYPE
6984 FROM po_requisition_lines_all prl
6985 WHERE prl.requisition_line_id='||p_from_req_line_id||
6986 'ORDER BY LINE_NUM';
6987
6988
6989 p_level:= 'LINES';
6990
6991 ELSIF p_table_name = 'PO_REQ_DISTRIBUTIONS_ALL' THEN
6992
6993 /* Added NVL around RECOVERABLE_TAX, NONRECOVERABLE_TAX, RECOVERY_RATE
6994 to disregard the difference between NULL and 0.
6995 */
6996
6997 /* <<CLM Partial Funding Changes>>
6998 Added following partial funding attributes:
6999 PARTIAL_FUNDED_FLAG, FUNDED_VALUE, QUANTITY_FUNDED, AMOUNT_FUNDED
7000 */
7001 sql_stmt1:='SELECT DISTRIBUTION_ID,
7002 prl.LINE_NUM LINE_NUM,
7003 prl.LINE_NUM_DISPLAY LINE_NUM_DISPLAY,
7004 DISTRIBUTION_NUM,
7005 nvl(prl.CANCEL_FLAG,''N'') LINE_CANCEL_FLAG,
7006 prl.ITEM_ID LINE_ITEM_ID,
7007 CODE_COMBINATION_ID,
7008 REQ_LINE_QUANTITY,
7009 to_char(GL_ENCUMBERED_DATE,''DD-MON-YYYY HH24:MI:SS'') GL_ENCUMBERED_DATE,
7010 prd.USSGL_TRANSACTION_CODE USSGL_TRANSACTION_CODE,
7011 PROJECT_ID,
7012 TASK_ID,
7013 EXPENDITURE_TYPE,
7014 EXPENDITURE_ORGANIZATION_ID,
7015 to_char(EXPENDITURE_ITEM_DATE,''DD-MON-YYYY HH24:MI:SS'') EXPENDITURE_ITEM_DATE,
7016 nvl(RECOVERABLE_TAX,0) RECOVERABLE_TAX,
7017 nvl(NONRECOVERABLE_TAX,0) NONRECOVERABLE_TAX,
7018 nvl(RECOVERY_RATE,0) RECOVERY_RATE,
7019 REQ_LINE_AMOUNT,
7020 REQ_LINE_CURRENCY_AMOUNT,
7021 PARTIAL_FUNDED_FLAG,
7022 FUNDED_VALUE,
7023 QUANTITY_FUNDED,
7024 AMOUNT_FUNDED
7025 FROM po_req_distributions_all prd,
7026 po_requisition_lines_all prl
7027 WHERE prl.requisition_line_id ='||p_to_req_line_id||
7028 'AND prl.requisition_line_id=nvl(prd.info_line_id,prd.requisition_line_id)
7029 ORDER BY nvl(prd.info_line_id,prd.requisition_line_id),DISTRIBUTION_NUM';
7030
7031 /* Added NVL around RECOVERABLE_TAX, NONRECOVERABLE_TAX, RECOVERY_RATE
7032 to disregard the difference between NULL and 0.
7033 */
7034
7035 /* <<CLM Partial Funding Changes>>
7036 Added following partial funding attributes:
7037 PARTIAL_FUNDED_FLAG, FUNDED_VALUE, QUANTITY_FUNDED, AMOUNT_FUNDED
7038 */
7039 sql_stmt2:='SELECT DISTRIBUTION_ID,
7040 prl.LINE_NUM LINE_NUM,
7041 prl.LINE_NUM_DISPLAY LINE_NUM_DISPLAY,
7042 DISTRIBUTION_NUM,
7043 nvl(prl.CANCEL_FLAG,''N'') LINE_CANCEL_FLAG,
7044 prl.ITEM_ID LINE_ITEM_ID,
7045 CODE_COMBINATION_ID,
7046 REQ_LINE_QUANTITY,
7047 to_char(GL_ENCUMBERED_DATE,''DD-MON-YYYY HH24:MI:SS'') GL_ENCUMBERED_DATE,
7048 prd.USSGL_TRANSACTION_CODE USSGL_TRANSACTION_CODE,
7049 PROJECT_ID,
7050 TASK_ID,
7051 EXPENDITURE_TYPE,
7052 EXPENDITURE_ORGANIZATION_ID,
7053 to_char(EXPENDITURE_ITEM_DATE,''DD-MON-YYYY HH24:MI:SS'') EXPENDITURE_ITEM_DATE,
7054 nvl(RECOVERABLE_TAX,0) RECOVERABLE_TAX,
7055 nvl(NONRECOVERABLE_TAX,0) NONRECOVERABLE_TAX,
7056 nvl(RECOVERY_RATE,0) RECOVERY_RATE,
7057 REQ_LINE_AMOUNT,
7058 REQ_LINE_CURRENCY_AMOUNT,
7059 PARTIAL_FUNDED_FLAG,
7060 FUNDED_VALUE,
7061 QUANTITY_FUNDED,
7062 AMOUNT_FUNDED
7063 FROM po_req_distributions_all prd,
7064 po_requisition_lines_all prl
7065 WHERE prl.requisition_line_id ='||p_from_req_line_id||
7066 'AND prl.requisition_line_id=nvl(prd.info_line_id,prd.requisition_line_id)
7067 ORDER BY nvl(prd.info_line_id,prd.requisition_line_id),DISTRIBUTION_NUM';
7068
7069 p_level:= 'DIST';
7070
7071 END IF;
7072
7073
7074 v_progress:='001';
7075 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
7076 l_log_msg := v_progress||' : After creating queries';
7077 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
7078 END IF;
7079
7080
7081 -- Comparing the data between two revisions
7082 compare(sql_stmt1, sql_stmt2, p_level, 0, x_amendment_num);
7083
7084
7085
7086 v_progress:='002';
7087 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
7088 l_log_msg := v_progress||' : After comparing two revisions';
7089 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
7090 END IF;
7091
7092
7093 -- Insert the comparison result into the temp table
7094 insert_changes(p_sequence_num,p_from_req_line_id);
7095
7096 v_progress:='003';
7097 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
7098 l_log_msg := v_progress||' : After cinserting into the temp table';
7099 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
7100 END IF;
7101
7102
7103 EXCEPTION
7104 WHEN others THEN
7105
7106 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
7107 l_log_msg := v_progress||' : Exception : '|| SQLERRM;
7108 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
7109 END IF;
7110 RAISE;
7111
7112 END compare_table_for_implement;
7113
7114
7115 /**************************************************************************************************
7116 *
7117 * NAME
7118 * implement_amendment_changes
7119 *
7120 * PURPOSE
7121 * Update amendment status of the implemented lines( Accepted or Rejected)
7122 *
7123 * ARGUMENTS
7124 * selected_lines IN variable of type REQ_LINE_TABLE_TYPE
7125 * stores requisition_line_id's of the selected lines
7126 *
7127 * reason IN Accept or Reject reason
7128 * implement_mode IN Accept or Reject
7129 * caller IN Specifies source document (possible values: BUYER or SOURCING_BUYER )
7130
7131 *
7132 * HISTORY
7133 * 05-10-09 Bisdas Created
7134 **************************************************************************************************/
7135 PROCEDURE implement_amendment_changes(selected_lines IN po_tbl_number,
7136 reason IN VARCHAR2,
7137 implement_mode IN VARCHAR2,
7138 caller IN VARCHAR2,
7139 dest_doc_id IN varchar2)
7140 IS
7141
7142 --Debugging purpose
7143 v_progress VARCHAR2(3);
7144 l_procedure_name VARCHAR2(100) := 'accept_amendment_changes';
7145 l_log_msg VARCHAR2(2000);
7146 l_latest_amendment_hdr_id number;
7147 l_line_num_display po_requisition_lines_all.line_num_display%type;
7148 l_amendment_line_id number;
7149
7150 BEGIN
7151
7152 v_progress:='000';
7153 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
7154 l_log_msg := 'Invoked '||l_procedure_name;
7155 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
7156 END IF;
7157
7158 IF implement_mode = 'ACCEPT' THEN
7159 FOR i IN 1..selected_lines.count
7160 LOOP
7161 /* Add the newly added distribution to PO */
7162 IF caller = 'BUYER' THEN
7163 /* Auto addition of newly added distribution */
7164 implement_dist_auto(selected_lines(i));
7165 END IF; -- If source document is PO
7166
7167 IF caller = 'SOURCING_BUYER' THEN
7168 /* Auto addition of newly added slin */
7169 implement_slin_auto(selected_lines(i),dest_doc_id);
7170 END IF;
7171
7172
7173 /* Update amendment status of the implemented lines/ distributions
7174 selected_lines is the list of line_id from conformed copy. When
7175 stamping the response, stamp it on the lastest amendment copy also */
7176 UPDATE po_requisition_lines_all
7177 SET amendment_status = 'A',
7178 amendment_response_reason = reason
7179 WHERE requisition_line_id = selected_lines(i)
7180 AND amendment_status IN ('N','P');
7181
7182 select prh.requisition_header_id
7183 into l_latest_amendment_hdr_id
7184 from po_requisition_headers_all prh,
7185 po_requisition_lines_all prl
7186 where prh.revision_num = (select max(prh2.revision_num)
7187 from po_requisition_headers_all prh2,
7188 po_requisition_lines_all prl2
7189 where prh2.conformed_header_id = prl2.requisition_header_id
7190 and prl2.requisition_line_id = selected_lines(i) )
7191 and prh.conformed_header_id = prl.requisition_header_id
7192 and prl.requisition_line_id = selected_lines(i);
7193
7194 select prl2.requisition_line_id, prl2.line_num_display
7195 into l_amendment_line_id, l_line_num_display
7196 from po_requisition_lines_all prl1,
7197 po_requisition_lines_all prl2
7198 where prl1.requisition_line_id = selected_lines(i)
7199 and prl2.requisition_header_id = l_latest_amendment_hdr_id
7200 and prl1.line_num_display = prl2.line_num_display;
7201
7202 UPDATE po_requisition_lines_all prl
7203 SET amendment_status = 'A',
7204 amendment_response_reason = reason
7205 WHERE requisition_line_id = l_amendment_line_id
7206 and amendment_status in ('N','P');
7207
7208 UPDATE po_req_distributions_all
7209 SET amendment_status = 'A'
7210 WHERE requisition_line_id = selected_lines(i)
7211 AND amendment_status IN ('N','P');
7212
7213 update po_req_distributions_all
7214 set amendment_status = 'A'
7215 where requisition_line_id = l_amendment_line_id
7216 and amendment_status in ('N', 'P');
7217
7218 END LOOP;
7219 ELSIF implement_mode = 'REJECT' THEN
7220 FOR i IN 1..selected_lines.count
7221 LOOP
7222 /* Update amendment status of the implemented lines/ distributions */
7223 UPDATE po_requisition_lines_all
7224 SET amendment_status = 'R',
7225 amendment_response_reason = reason
7226 WHERE requisition_line_id = selected_lines(i)
7227 AND amendment_status IN ('N','P');
7228
7229 select prh.requisition_header_id
7230 into l_latest_amendment_hdr_id
7231 from po_requisition_headers_all prh,
7232 po_requisition_lines_all prl
7233 where prh.revision_num = (select max(prh2.revision_num)
7234 from po_requisition_headers_all prh2,
7235 po_requisition_lines_all prl2
7236 where prh2.conformed_header_id = prl2.requisition_header_id
7237 and prl2.requisition_line_id = selected_lines(i) )
7238 and prh.conformed_header_id = prl.requisition_header_id
7239 and prl.requisition_line_id = selected_lines(i);
7240
7241 select prl2.requisition_line_id, prl2.line_num_display
7242 into l_amendment_line_id, l_line_num_display
7243 from po_requisition_lines_all prl1,
7244 po_requisition_lines_all prl2
7245 where prl1.requisition_line_id = selected_lines(i)
7246 and prl2.requisition_header_id = l_latest_amendment_hdr_id
7247 and prl1.line_num_display = prl2.line_num_display;
7248
7249 UPDATE po_requisition_lines_all prl
7250 SET amendment_status = 'R',
7251 amendment_response_reason = reason
7252 WHERE requisition_line_id = l_amendment_line_id
7253 and amendment_status in ('N','P');
7254
7255 UPDATE po_req_distributions_all
7256 SET amendment_status = 'R'
7257 WHERE requisition_line_id = selected_lines(i)
7258 AND amendment_status IN ('N','P');
7259
7260 UPDATE po_req_distributions_all
7261 SET amendment_status = 'R'
7262 WHERE requisition_line_id = l_amendment_line_id
7263 AND amendment_status IN ('N','P');
7264
7265 END LOOP;
7266 END IF;
7267
7268
7269 COMMIT;
7270
7271 EXCEPTION
7272 WHEN others THEN
7273
7274 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
7275 l_log_msg := v_progress||' : Exception : '|| SQLERRM;
7276 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
7277 END IF;
7278 RAISE;
7279
7280 END implement_amendment_changes;
7281
7282
7283 FUNCTION is_conformedline_on_po(p_conformed_line_id in number) return varchar2 is
7284 l_po_line_id number := null;
7285 ret_val VARCHAR2(1) := 'N';
7286 l_info_flag VARCHAR2(1);
7287 l_grp_line_id NUMBER;
7288 l_base_line_num NUMBER;
7289 l_cnt NUMBER;
7290
7291 begin
7292
7293
7294 IF p_conformed_line_id IS NULL then
7295 RETURN 'N';
7296 END IF;
7297
7298 select po_line_id
7299 into l_po_line_id
7300 from po_requisition_lines_all
7301 where requisition_line_id = p_conformed_line_id;
7302
7303 if(l_po_line_id IS NOT NULL) THEN --line is placed on PO irrespective of whether its priced/info/option
7304 ret_val := 'Y';
7305 else
7306 ret_val := 'N';
7307 end if;
7308
7309 RETURN ret_val;
7310 END is_conformedline_on_po;
7311
7312
7313 FUNCTION is_conformedline_on_sol(p_conformed_line_id in number) return varchar2
7314 is
7315 l_cnt NUMBER :=0;
7316 ret_val VARCHAR2(1) := 'N';
7317 begin
7318 select count(*)
7319 into l_cnt
7320 from po_requisition_lines_all
7321 where requisition_line_id = p_conformed_line_id
7322 and auction_header_id is not null;
7323
7324 if(l_cnt > 0) then
7325 ret_val := 'Y';
7326 end if;
7327
7328 return ret_val;
7329
7330 END is_conformedline_on_sol;
7331
7332 FUNCTION is_conformedline_exercised(p_conformed_line_id in number) return varchar2 is
7333 l_option_exercised varchar2(1) := 'N';
7334 begin
7335 select nvl(CLM_OPTION_EXERCISED,'N')
7336 into l_option_exercised
7337 from po_requisition_lines_all
7338 where requisition_line_id = p_conformed_line_id;
7339
7340 if(l_option_exercised = 'Y') then
7341 return 'Y';
7342 else
7343 return 'N';
7344 end if;
7345
7346 END is_conformedline_exercised;
7347
7348 PROCEDURE set_amendment_related_attrib(itemtype in varchar2,
7349 itemkey in varchar2,
7350 actid in number,
7351 funcmode in varchar2,
7352 resultout out NOCOPY varchar2)
7353 IS
7354 l_api_name CONSTANT VARCHAR2(30) := 'set_amendment_related_attrib';
7355 x_progress varchar2(100);
7356 x_resultout varchar2(30);
7357
7358 l_conformed_id NUMBER;
7359 l_revision_num NUMBER;
7360 l_result BOOLEAN;
7361 l_log_msg VARCHAR2(2000);
7362 l_amendment_flow VARCHAR2(1);
7363 l_amendment_approval VARCHAR2(1);
7364
7365 BEGIN
7366 x_progress := 'POR_AMENDMENT_PKG.set_amendment_related_attrib: 01';
7367 IF (g_po_wf_debug = 'Y') THEN
7368 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
7369 END IF;
7370
7371 -- Do nothing in cancel or timeout mode
7372 if (funcmode <> wf_engine.eng_run) then
7373 resultout := wf_engine.eng_null;
7374 return;
7375 end if;
7376
7377 l_amendment_approval := wf_engine.GetItemAttrText (itemtype => itemtype,
7378 itemkey => itemkey,
7379 aname => 'IS_AMENDMENT_APPROVAL');
7380
7381 x_progress := 'POR_AMENDMENT_PKG.set_amendment_related_attrib: 02';
7382 IF (g_po_wf_debug = 'Y') THEN
7383 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
7384 END IF;
7385
7386 IF (l_amendment_approval IS NULL OR l_amendment_approval = 'N') THEN
7387 x_progress := 'POR_AMENDMENT_PKG.set_amendment_related_attrib: l_amendment_approval is not Y, so return';
7388 IF (g_po_wf_debug = 'Y') THEN
7389 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
7390 END IF;
7391
7392 RETURN;
7393 END IF;
7394
7395
7396 l_conformed_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
7397 itemkey => itemkey,
7398 aname => 'CONFORMED_HEADER_ID');
7399
7400 l_revision_num := wf_engine.GetItemAttrNumber (itemtype => itemtype,
7401 itemkey => itemkey,
7402 aname => 'REVISION_NUM');
7403
7404 --Since this is an amendment flow, so we have to create/modify the
7405 --supply table based on the conformed_id
7406 update_amendment(l_conformed_id,l_revision_num);
7407
7408 x_progress := 'POR_AMENDMENT_PKG.set_amendment_related_attrib: completed successfully';
7409 IF (g_po_wf_debug = 'Y') THEN
7410 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
7411 END IF;
7412
7413 EXCEPTION
7414 WHEN OTHERS THEN
7415 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
7416 l_log_msg := x_progress||'CException: '||SQLERRM;
7417 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_api_name, l_log_msg);
7418
7419 END IF;
7420 wf_core.context('POR_AMENDMENT_PKG','set_amendment_related_attrib',x_progress);
7421 raise;
7422
7423 END set_amendment_related_attrib;
7424
7425 FUNCTION getLatestAmendmentNum (p_req_header_id IN NUMBER) RETURN VARCHAR2
7426 IS
7427 l_amendment_num po_requisition_headers_all.segment1%TYPE;
7428 BEGIN
7429 SELECT segment1 INTO l_amendment_num
7430 FROM
7431 (SELECT prha.segment1,rownum rnum
7432 FROM po_requisition_headers_all prha
7433 WHERE conformed_header_id = p_req_header_id
7434 AND authorization_status = 'APPROVED'
7435 ORDER BY revision_num DESC)
7436 WHERE RNUM =1;
7437
7438 RETURN l_amendment_num;
7439 END getLatestAmendmentNum;
7440
7441
7442 FUNCTION getLatestAmendmentHdrId (p_req_header_id IN NUMBER) RETURN NUMBER
7443 IS
7444 l_header_id po_requisition_headers_all.requisition_header_id%TYPE;
7445 BEGIN
7446 SELECT requisition_header_id INTO l_header_id
7447 FROM
7448 (SELECT prha.requisition_header_id,rownum rnum
7449 FROM po_requisition_headers_all prha
7450 WHERE conformed_header_id = p_req_header_id
7451 AND authorization_status = 'APPROVED'
7452 ORDER BY revision_num DESC)
7453 WHERE RNUM =1;
7454
7455 RETURN l_header_id;
7456 END getLatestAmendmentHdrId;
7457
7458
7459 PROCEDURE getDraftId(p_req_header_id IN NUMBER, p_draft_id OUT NOCOPY NUMBER)
7460 IS
7461
7462 l_api_name CONSTANT VARCHAR2(30) := 'getDraftId';
7463 x_progress varchar2(100);
7464
7465 BEGIN
7466
7467 SELECT draft_id
7468 INTO p_draft_id
7469 FROM po_drafts DFT
7470 WHERE DFT.document_id = p_req_header_id
7471 AND DFT.status in ('DRAFT')
7472 AND DFT.creation_date = (SELECT Max(creation_date)
7473 FROM po_drafts
7474 WHERE document_id = p_req_header_id
7475 AND status in ('DRAFT'));
7476
7477 EXCEPTION
7478 WHEN NO_DATA_FOUND THEN
7479 p_draft_id := null;
7480 WHEN OTHERS THEN
7481 p_draft_id := null;
7482 END getDraftId;
7483
7484 /* <<CLM Partial Funding Code Changes>> */
7485 FUNCTION getLastImplFundValue(p_distribution_id IN NUMBER) RETURN NUMBER
7486 IS
7487 L_FUNDED_VALUE NUMBER:= 0;
7488 l_dist_id NUMBER;
7489 BEGIN
7490
7491 SELECT Max(distribution_id)
7492 INTO l_dist_id
7493 FROM po_req_distributions_all
7494 WHERE ( conformed_dist_id = p_distribution_id AND amendment_status = 'A')
7495 ---Bug#14332568 : Added below condition to get the funded value for requistion line
7496 -- which is newly added after requisition1405has been autocreated.
7497 OR (distribution_id = p_distribution_id
7498 AND amendment_type = 'ADDED'
7499 AND amendment_type IS NOT NULL );
7500
7501 IF l_dist_id IS NULL THEN
7502
7503 SELECT prda.funded_value INTO L_FUNDED_VALUE
7504 FROM po_req_distributions_all prda,
7505 po_requisition_lines_all prla,
7506 po_requisition_headers_all prha
7507 WHERE
7508 prda.conformed_dist_id = p_distribution_id
7509 AND prda.requisition_line_id = prla.requisition_line_id
7510 AND prla.requisition_header_id = prha.requisition_header_id
7511 AND prha.revision_num=0;
7512 ELSE
7513 SELECT funded_value INTO L_FUNDED_VALUE
7514 FROM po_req_distributions_all WHERE
7515 distribution_id = l_dist_id;
7516 END IF;
7517
7518 RETURN L_FUNDED_VALUE;
7519
7520 END getLastImplFundValue;
7521
7522 PROCEDURE SET_CLM_FUNDS_OVERRIDE(itemtype in varchar2,
7523 itemkey in varchar2,
7524 actid in number,
7525 funcmode in varchar2,
7526 resultout out NOCOPY varchar2)
7527 IS
7528 x_progress VARCHAR2(100);
7529
7530 BEGIN
7531 x_progress := 'POR_AMENDMENT_PKG.SET_CLM_FUNDS_OVERRIDE: 01';
7532 IF (g_po_wf_debug = 'Y') THEN
7533 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
7534 END IF;
7535 -- Do nothing in cancel or timeout mode
7536 --
7537 if (funcmode <> wf_engine.eng_run) then
7538 resultout := wf_engine.eng_null;
7539 return;
7540 end if;
7541
7542 x_progress := 'POR_AMENDMENT_PKG.SET_CLM_FUNDS_OVERRIDE: Setting Funds Override as Y : 02';
7543 IF (g_po_wf_debug = 'Y') THEN
7544 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
7545 END IF;
7546 -- Bug 9667861.
7547 wf_engine.SetitemattrText( itemtype => itemtype,
7548 itemkey => itemkey,
7549 aname => 'CLM_FUNDS_OVERRIDE',
7550 avalue => 'Y');
7551
7552 x_progress := 'POR_AMENDMENT_PKG.SET_CLM_FUNDS_OVERRIDE: Successful: 03';
7553 IF (g_po_wf_debug = 'Y') THEN
7554 PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
7555 END IF;
7556 EXCEPTION
7557 WHEN Others THEN
7558 wf_core.context('POR_AMENDMENT_PKG','SET_CLM_FUNDS_OVERRIDE',x_progress || ', ' || sqlerrm);
7559 raise;
7560 END SET_CLM_FUNDS_OVERRIDE;
7561
7562 PROCEDURE Clm_req_merge_reserve
7563 (
7564 itemtype IN VARCHAR2,
7565 itemkey IN VARCHAR2,
7566 actid IN NUMBER,
7567 funcmode IN VARCHAR2,
7568 resultout OUT NOCOPY VARCHAR2
7569 )
7570 IS
7571 x_progress VARCHAR2(100);
7572 x_resultout VARCHAR2(30);
7573 l_override_funds VARCHAR2(3) := NULL;
7574 l_conformed_header_id NUMBER;
7575 l_revision_num NUMBER;
7576 l_amendment_approval VARCHAR2(1) := 'N';
7577 l_clm_funds_Override VARCHAR2(3) := 'N';
7578 l_document_id NUMBER;
7579 l_employee_id NUMBER;
7580 l_document_type po_document_types_all.document_type_code%TYPE;
7581 l_document_subtype po_document_types_all.document_subtype%TYPE;
7582 l_return_status VARCHAR2(1);
7583 l_po_return_code VARCHAR2(10);
7584 l_online_report_id NUMBER;
7585 l_warning_mesg VARCHAR2(2000) := NULL;
7586 l_req_encumbrance_on BOOLEAN;
7587 BEGIN
7588 x_progress := 'POR_AMENDMENT_PKG.CLM_REQ_MERGE_RESERVE: 01';
7589 IF (g_po_wf_debug = 'Y') THEN
7590 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,x_progress);
7591 END IF;
7592 -- Do nothing in cancel or timeout mode
7593 --
7594 IF (funcmode <> wf_engine.eng_run) THEN
7595 resultout := wf_engine.eng_null;
7596 RETURN;
7597 END IF;
7598 l_req_encumbrance_on := po_core_s.Is_encumbrance_on(p_doc_type => 'REQUISITION',p_org_id => NULL);
7599 l_conformed_header_id := po_wf_util_pkg.Getitemattrnumber(itemtype => itemtype,itemkey => itemkey,aname => 'CONFORMED_HEADER_ID');
7600 l_revision_num := po_wf_util_pkg.Getitemattrnumber(itemtype => itemtype,itemkey => itemkey,aname => 'REVISION_NUM');
7601 l_amendment_approval := po_wf_util_pkg.Getitemattrtext(itemtype => itemtype,itemkey => itemkey,aname => 'IS_AMENDMENT_APPROVAL');
7602 l_employee_id := po_wf_util_pkg.Getitemattrnumber(itemtype => itemtype,itemkey => itemkey,aname => 'APPROVER_EMPID');
7603 l_document_id := po_wf_util_pkg.Getitemattrnumber(itemtype => itemtype,itemkey => itemkey,aname => 'DOCUMENT_ID');
7604 l_document_type := po_wf_util_pkg.Getitemattrtext(itemtype => itemtype,itemkey => itemkey,aname => 'DOCUMENT_TYPE');
7605 l_document_subtype := po_wf_util_pkg.Getitemattrtext(itemtype => itemtype,itemkey => itemkey,aname => 'DOCUMENT_SUBTYPE');
7606 fnd_profile.Get('PO_REQAPPR_OVERRIDE_FUNDS',l_override_funds);
7607 l_clm_funds_Override := po_wf_util_pkg.Getitemattrtext(itemtype => itemtype,itemkey => itemkey,aname => 'CLM_FUNDS_OVERRIDE');
7608
7609
7610
7611 IF l_amendment_approval IS NULL THEN
7612 l_amendment_approval := 'N';
7613 END IF;
7614 IF (l_clm_funds_Override IS NOT NULL
7615 AND l_clm_funds_Override <> 'N') THEN
7616 l_override_funds := l_clm_funds_Override;
7617 wf_engine.SetitemattrText(itemtype => itemtype,itemkey => itemkey,aname => 'CLM_FUNDS_OVERRIDE', avalue => 'N');
7618 END IF;
7619 IF (g_po_wf_debug = 'Y') THEN
7620 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'is Amenement Approval '||l_amendment_approval);
7621 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'Conformed Header Id '||l_conformed_header_id);
7622 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'Revision Num '||l_revision_num);
7623 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'Document Id '||l_document_id);
7624 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'Document Type '||l_document_type);
7625 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'Approver EmpId '||l_employee_id);
7626 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'Funds Override '||l_override_funds);
7627 END IF;
7628
7629 IF l_amendment_approval = 'Y' THEN
7630 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'Calling process_cancel_amendments before mergeReserveAutonomous ');
7631 process_cancel_amendments(l_document_id, l_conformed_header_id);
7632 END IF;
7633
7634 -- Call MergeReserve only Either Req Encumbrance is On or If its an Amendment Aprpoval
7635 IF (l_req_encumbrance_on OR l_amendment_approval = 'Y') THEN
7636 IF (g_po_wf_debug = 'Y') THEN
7637 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'Calling MergeReserveAutonomous. ');
7638 END IF;
7639
7640 Clm_mergereserve_autonomous(itemtype => itemtype,itemkey => itemkey,p_doc_type => l_document_type,
7641 p_doc_subtype => l_document_subtype,p_doc_id => l_document_id,
7642 p_override_funds => l_override_funds,p_employee_id => l_employee_id,
7643 p_conformed_header_id => l_conformed_header_id,
7644 p_revision_num => l_revision_num,p_amendment_approval => l_amendment_approval,
7645 x_po_return_code => l_po_return_code,x_online_report_id => l_online_report_id,
7646 x_return_status => l_return_status);
7647
7648 IF (g_po_wf_debug = 'Y') THEN
7649 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'MergeReserveAutonomous - Return Status: '|| l_return_status );
7650 END IF;
7651 IF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
7652 OR l_return_status IS NULL) THEN
7653 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7654 ELSIF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
7655 IF (l_req_encumbrance_on)
7656 AND
7657 (
7658 l_po_return_code NOT IN ( po_document_funds_pvt.g_return_success,
7659 PO_DOCUMENT_FUNDS_PVT.g_return_WARNING)
7660 )
7661 THEN
7662 IF (g_po_wf_debug = 'Y') THEN
7663 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'MergeReserveAutonomous - Po Return Code: '|| l_po_return_code );
7664 END IF;
7665 resultout := 'COMPLETE:'|| 'N';
7666 RETURN;
7667 END IF;
7668 END IF;
7669 END IF;
7670
7671 IF (g_po_wf_debug = 'Y') THEN
7672 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'MergeReserve Completed Successfully.');
7673 END IF;
7674
7675 resultout := 'COMPLETE:'|| 'Y';
7676 RETURN;
7677
7678 EXCEPTION
7679 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7680 wf_core.Context('POR_AMENDMENT_PKG','CLM_REQ_MERGE_RESERVE', x_progress);
7681 RAISE;
7682 WHEN OTHERS THEN
7683 x_progress := 'POR_AMENDMENT_PKG.CLM_REQ_MERGE_RESERVE: Do Reserve. Return Status.'||l_return_status;
7684 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,x_progress);
7685 RAISE;
7686 END Clm_req_merge_reserve;
7687
7688
7689 PROCEDURE Clm_MergeReserve_Autonomous
7690 (
7691 itemtype IN VARCHAR2,
7692 itemkey IN VARCHAR2,
7693 p_doc_type IN VARCHAR2,
7694 p_doc_subtype IN VARCHAR2,
7695 p_doc_id IN NUMBER,
7696 p_override_funds IN VARCHAR2 DEFAULT 'N',
7697 p_employee_id IN NUMBER,
7698 p_conformed_header_id IN NUMBER DEFAULT NULL,
7699 P_revision_num IN NUMBER,
7700 P_amendment_approval IN VARCHAR2 DEFAULT 'N',
7701 x_po_return_code OUT NOCOPY VARCHAR2,
7702 x_online_report_id OUT NOCOPY NUMBER,
7703 x_return_status OUT NOCOPY VARCHAR2
7704 )
7705 IS
7706 pragma AUTONOMOUS_TRANSACTION;
7707 x_progress VARCHAR2(100);
7708 l_return_status VARCHAR2(1);
7709 l_po_return_code VARCHAR2(10);
7710 l_online_report_id NUMBER;
7711 l_document_id NUMBER;
7712 l_result BOOLEAN;
7713 BEGIN
7714 IF (g_po_wf_debug = 'Y') THEN
7715 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'MergeReserveAutonomous: Start');
7716 END IF;
7717
7718 SAVEPOINT Clm_MergeReserve_Autonomous_SP; -- Save point to Rollback in case of Errors
7719 IF (g_po_wf_debug = 'Y') THEN
7720 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'Savepoint: Clm_MergeReserve_Autonomous_SP');
7721 END IF;
7722
7723 IF p_amendment_approval = 'Y' THEN
7724
7725 IF (g_po_wf_debug = 'Y') THEN
7726 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'Calling Auto Accept for Amendment. Requisition Header Id: '||p_conformed_header_id);
7727 END IF;
7728
7729 Carry_auto_aceept_and_reject(p_doc_id);
7730
7731 IF (g_po_wf_debug = 'Y') THEN
7732 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'Auto Accept for Amendment Successful.');
7733 END IF;
7734
7735 IF (g_po_wf_debug = 'Y') THEN
7736 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'Calling Merge Amendment with ConfirmedId: '||p_conformed_header_id||' Revision Num: '||p_revision_num);
7737 END IF;
7738 Merge_amendment(p_confirmed_id => p_conformed_header_id,p_revision_num => p_revision_num);
7739 IF (g_po_wf_debug = 'Y') THEN
7740 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'Merge Amendment Successful');
7741 END IF;
7742 END IF; -- p_amendment_approval
7743
7744 IF (po_core_s.Is_encumbrance_on(p_doc_type => 'REQUISITION',p_org_id => NULL)) THEN
7745 IF (g_po_wf_debug = 'Y') THEN
7746 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'Requisition Encumbrance is On');
7747 END IF;
7748 IF p_amendment_approval = 'Y' THEN
7749 l_document_id := p_conformed_header_id;
7750 ELSE
7751 l_document_id := p_doc_id;
7752 END IF;
7753
7754 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'Calling do Reserve with doctype: '||p_doc_type||' - sub: '||p_doc_subtype||'- document id: '||l_document_id||' - Ovrride: '||p_override_funds||'- Emp: '||p_employee_id||'.');
7755
7756 po_document_funds_pvt.Do_reserve(x_return_status => l_return_status,p_doc_type => p_doc_type,
7757 p_doc_subtype => p_doc_subtype,p_doc_level => po_document_funds_pvt.g_doc_level_header,
7758 p_doc_level_id => l_document_id,
7759 p_use_enc_gt_flag => po_document_funds_pvt.g_parameter_no,
7760 p_prevent_partial_flag => po_document_funds_pvt.g_parameter_no,
7761 p_validate_document => po_document_funds_pvt.g_parameter_yes,
7762 p_override_funds => p_override_funds,p_employee_id => p_employee_id,
7763 x_po_return_code => x_po_return_code,x_online_report_id => l_online_report_id);
7764
7765 IF (g_po_wf_debug = 'Y') THEN
7766 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'Do Reserve Completed with Return Status: '||l_return_status);
7767 END IF;
7768 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
7769 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7770 END IF;
7771
7772 END IF;
7773 IF p_amendment_approval = 'Y' THEN
7774
7775 l_result := po_supply.Create_req(p_conformed_header_id,'REQ HDR');
7776 IF NOT l_result THEN
7777 po_wf_debug_pkg.Insert_debug(itemtype,itemkey,'Create Req Supply failed for Confirmed Header Id : '||p_conformed_header_id);
7778 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7779 END IF;
7780 END IF;
7781 x_return_status := FND_API.G_RET_STS_SUCCESS;
7782 COMMIT;
7783 EXCEPTION
7784 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7785 ROLLBACK TO Clm_MergeReserve_Autonomous_SP;
7786 wf_core.context('PO_REQAPPROVAL_ACTION','ReserveAutonomous', x_progress);
7787 RAISE;
7788 WHEN OTHERS THEN
7789 wf_core.Context('POR_AMENDMENT_PKG','MERGE_INTO_CONFORM_VERSION', x_progress);
7790 ROLLBACK TO Clm_MergeReserve_Autonomous_SP;
7791 RAISE;
7792 END Clm_MergeReserve_Autonomous;
7793
7794 /* <<CLM Partial Funding Code Changes>> */
7795
7796
7797 /* UDA related changes */
7798
7799 /*********************************************************************
7800 * NAME
7801 * getUDAAttributeName
7802 *
7803 * PURPOSE
7804 * Takes the UDA attribute name concatenated with attribute group name as
7805 * input and returns the corresponding display value.
7806 *
7807 * ARGUMENTS
7808 * p_node_name UDA attribute name concatenated with attribute group name
7809 *
7810 *
7811 * HISTORY
7812 * 07-05-2010 bisdas Created
7813 *
7814 ********************************************************************/
7815
7816 FUNCTION getUDAAttributeName(p_node_name VARCHAR2)
7817 RETURN VARCHAR2
7818 IS
7819
7820 l_progress VARCHAR2(3) := '000';
7821 l_procedure_name VARCHAR2(100) := 'getUDAAttributeName';
7822 l_log_msg VARCHAR2(2000);
7823
7824 x_attr_grp_name VARCHAR2(50);
7825 x_attr_name VARCHAR2(50);
7826 x_attr_disp_name VARCHAR2(5000);
7827
7828 BEGIN
7829
7830 -- x_attr_grp_name := SubStr(p_node_name,0,InStr(p_node_name,'$')-1);
7831 -- x_attr_name := SubStr(p_node_name,InStr(p_node_name,'$')+1,Length(p_node_name));
7832
7833
7834 SELECT attr_display_name
7835 INTO x_attr_disp_name
7836 FROM ego_attrs_v
7837 WHERE p_node_name = attr_group_name||PO_UDA_TEMPLATES_UTIL.g_delimiter||attr_name
7838 AND ATTR_GROUP_TYPE = 'PO_UDA_DUMMY_EXT_ATTRS'
7839 AND application_id = 201;
7840
7841
7842 RETURN x_attr_disp_name;
7843
7844 EXCEPTION
7845 WHEN others THEN
7846
7847 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
7848 l_log_msg := l_progress||' : Exception at function getUDAAttributeName : '|| SQLERRM;
7849 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
7850 END IF;
7851 RETURN p_node_name;
7852
7853 END getUDAAttributeName;
7854
7855
7856
7857
7858 /*********************************************************************
7859 * NAME
7860 * getUDAAttributeValue
7861 *
7862 * PURPOSE
7863 * Takes the UDA attribute value as input and returns the corresponding display value.
7864 *
7865 * ARGUMENTS
7866 * p_node_value UDA attribute value
7867 * p_node_name UDA attribute name concatenated with attribute group name
7868 * p_lavel level eg; UDA_HEADER or UDA_LINES
7869 * amend_num Amendment Number
7870 * line_num Line Number
7871 *
7872 * HISTORY
7873 * 07-05-2010 bisdas Created
7874 *
7875 ********************************************************************/
7876
7877 FUNCTION getUDAAttributeValue(p_node_value VARCHAR2,
7878 p_node_name VARCHAR2,
7879 p_lavel VARCHAR2,
7880 amend_num VARCHAR2,
7881 line_num VARCHAR2)
7882 RETURN VARCHAR2
7883 IS
7884
7885 l_progress VARCHAR2(3) := '000';
7886 l_procedure_name VARCHAR2(100) := 'getUDAAttributeValue';
7887 l_log_msg VARCHAR2(2000);
7888
7889 l_attr_disp_value VARCHAR2(500) := null;
7890 l_attr_name VARCHAR2(100);
7891 l_attr_group_Type VARCHAR2(50);
7892 l_attr_grp_name VARCHAR2(100);
7893 l_attr_id NUMBER;
7894 l_application_id NUMBER;
7895 l_db_object_name VARCHAR2(100);
7896 l_attr_grp_id NUMBER;
7897
7898 l_req_header_id VARCHAR2(100);
7899 l_pk1_col_name VARCHAR2(100);
7900 l_pk1_col_val VARCHAR2(100);
7901
7902
7903 BEGIN
7904
7905 IF p_lavel IN ('UDA_HEADER','UDA_LINES') THEN
7906
7907 SELECT attr_name,
7908 attr_group_type,
7909 attr_group_name,
7910 attr_id,
7911 application_id
7912 INTO l_attr_name,
7913 l_attr_group_Type,
7914 l_attr_grp_name,
7915 l_attr_id,
7916 l_application_id
7917 FROM ego_attrs_v
7918 WHERE p_node_name = attr_group_name||PO_UDA_TEMPLATES_UTIL.g_delimiter||attr_name
7919 AND ATTR_GROUP_TYPE = 'PO_UDA_DUMMY_EXT_ATTRS'
7920 AND application_id = 201;
7921
7922
7923 IF p_lavel = 'UDA_HEADER' THEN
7924 l_db_object_name := 'PO_REQUISITION_HEADERS_ALL';
7925 l_pk1_col_name := 'REQUISITION_HEADER_ID';
7926
7927 SELECT requisition_header_id
7928 INTO l_pk1_col_val
7929 FROM PO_REQUISITION_HEADERS_ALL
7930 WHERE segment1 = amend_num;
7931
7932 ELSIF p_lavel = 'UDA_LINES' THEN
7933
7934 l_db_object_name := 'PO_REQUISITION_LINES_ALL';
7935 l_pk1_col_name := 'REQUISITION_HEADER_ID';
7936
7937 SELECT requisition_header_id
7938 INTO l_req_header_id
7939 FROM PO_REQUISITION_HEADERS_ALL
7940 WHERE segment1 = amend_num;
7941
7942
7943 SELECT requisition_line_id
7944 INTO l_pk1_col_val
7945 FROM PO_REQUISITION_LINES_ALL
7946 WHERE requisition_header_id = l_req_header_id
7947 AND line_num = line_num;
7948
7949 END IF; -- ELSIF p_lavel = 'UDA_LINES' THEN
7950
7951
7952 l_attr_disp_value := EGO_USER_ATTRS_DATA_PVT.Get_Attr_Disp_Val_From_VSet (
7953 p_application_id => l_application_id
7954 ,p_attr_internal_str_value => p_node_value
7955 ,p_attr_internal_name => l_attr_name
7956 ,p_attr_group_type => l_attr_group_Type
7957 ,p_attr_group_int_name => l_attr_grp_name
7958 ,p_attr_id => l_attr_id
7959 ,p_object_name => l_db_object_name
7960 ,p_pk1_column_name => l_pk1_col_name
7961 ,p_pk1_value => l_pk1_col_val
7962 ,p_pk2_column_name => NULL
7963 ,p_pk2_value => NULL
7964 ,p_pk3_column_name => NULL
7965 ,p_pk3_value => NULL
7966 ,p_pk4_column_name => NULL
7967 ,p_pk4_value => NULL
7968 ,p_pk5_column_name => NULL
7969 ,p_pk5_value => NULL
7970 );
7971
7972
7973 ELSIF p_lavel = 'UDA_HEADER_ADDR' THEN -- p_lavel IN ('UDA_HEADER','UDA_LINES')
7974
7975 SELECT attr.attr_id,
7976 attr.attr_name,
7977 attr.application_id
7978 INTO l_attr_id,
7979 l_attr_name,
7980 l_application_id
7981 FROM ego_attrs_v attr
7982 WHERE attr.attr_group_name = 'addresses'
7983 AND attr.attr_group_type = 'PO_REQ_HEADER_EXT_ATTRS'
7984 AND attr.database_column = p_node_name
7985 AND attr.display_code <> 'H'
7986 AND application_id = 201;
7987
7988
7989 l_db_object_name := 'PO_REQUISITION_HEADERS_ALL';
7990 l_pk1_col_name := 'REQUISITION_HEADER_ID';
7991
7992 SELECT requisition_header_id
7993 INTO l_pk1_col_val
7994 FROM PO_REQUISITION_HEADERS_ALL
7995 WHERE segment1 = amend_num;
7996
7997
7998 l_attr_disp_value := EGO_USER_ATTRS_DATA_PVT.Get_Attr_Disp_Val_From_VSet (
7999 p_application_id => l_application_id
8000 ,p_attr_internal_str_value => p_node_value
8001 ,p_attr_internal_name => l_attr_name
8002 ,p_attr_group_type => 'PO_REQ_HEADER_EXT_ATTRS'
8003 ,p_attr_group_int_name => g_address_group_name
8004 ,p_attr_id => l_attr_id
8005 ,p_object_name => l_db_object_name
8006 ,p_pk1_column_name => l_pk1_col_name
8007 ,p_pk1_value => l_pk1_col_val
8008 ,p_pk2_column_name => NULL
8009 ,p_pk2_value => NULL
8010 ,p_pk3_column_name => NULL
8011 ,p_pk3_value => NULL
8012 ,p_pk4_column_name => NULL
8013 ,p_pk4_value => NULL
8014 ,p_pk5_column_name => NULL
8015 ,p_pk5_value => NULL
8016 );
8017
8018 END IF; -- p_lavel = 'UDA_HEADER_ADDR' THEN
8019
8020 l_attr_disp_value := Nvl(l_attr_disp_value, p_node_value);
8021
8022 RETURN l_attr_disp_value;
8023
8024 EXCEPTION
8025 WHEN others THEN
8026
8027 IF( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) THEN
8028 l_log_msg := l_progress||' : Exception at function getUDAAttributeValue : '|| SQLERRM;
8029 FND_LOG.STRING(G_LEVEL_STATEMENT, G_MODULE_NAME||l_procedure_name, l_log_msg);
8030 END IF;
8031 RETURN l_attr_disp_value;
8032
8033 END getUDAAttributeValue;
8034
8035 /* UDA related changes */
8036
8037 FUNCTION anySlinPlacedOnPO(l_clin_line_id IN NUMBER) RETURN NUMBER
8038 IS
8039 l_num NUMBER;
8040 BEGIN
8041 --First of all check whether this clin itself is placed on a PO
8042 --if yes then return 1 else check for the slins
8043 BEGIN
8044 SELECT 1 INTO l_num
8045 FROM po_requisition_lines_all
8046 WHERE requisition_line_id = l_clin_line_id
8047 AND line_location_id IS NOT NULL;
8048
8049 IF l_num IS NOT NULL THEN
8050 RETURN l_num;
8051 END IF;
8052 EXCEPTION
8053 WHEN No_Data_Found THEN
8054 NULL;
8055 END;
8056
8057 SELECT 1 INTO l_num
8058 FROM po_requisition_lines_all
8059 WHERE group_line_id = l_clin_line_id
8060 AND line_location_id IS NOT NULL
8061 AND ROWNUM=1;
8062
8063 RETURN l_num;
8064 EXCEPTION
8065 WHEN No_Data_Found THEN
8066 RETURN NULL;
8067 END;
8068
8069 PROCEDURE amendment_post_approval(itemtype in varchar2,
8070 itemkey in varchar2,
8071 actid in number,
8072 funcmode in varchar2,
8073 resultout out NOCOPY varchar2)
8074 IS
8075
8076 x_progress varchar2(100);
8077 l_req_header_id number;
8078 l_conf_hdr_id NUMBER;
8079 x_return_status VARCHAR2(100);
8080
8081 BEGIN
8082 x_progress := 'POR_AMENDMENT_PKG.amendment_post_approval: 01';
8083 IF (g_po_wf_debug = 'Y') THEN
8084 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
8085 END IF;
8086
8087
8088 -- Do nothing in cancel or timeout mode
8089 --
8090 if (funcmode <> wf_engine.eng_run) then
8091
8092 resultout := wf_engine.eng_null;
8093 return;
8094
8095 end if;
8096
8097 l_req_header_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
8098 itemkey => itemkey,
8099 aname => 'DOCUMENT_ID');
8100 l_conf_hdr_id := wf_engine.GetItemAttrNumber (itemtype => itemtype,
8101 itemkey => itemkey,
8102 aname => 'CONFORMED_HEADER_ID');
8103
8104 --update the approval status of the main requisition with the
8105 UPDATE po_requisition_headers_all h1 SET (h1.authorization_status,h1.approved_date) =
8106 (SELECT h2.authorization_status,h2.approved_date
8107 FROM po_requisition_headers_all h2
8108 WHERE h2.requisition_header_id = l_req_header_id)
8109 WHERE requisition_header_id = l_conf_hdr_id;
8110
8111 --Update reqs_in_pool_flag also
8112 po_req_lines_sv.update_reqs_in_pool_flag(NULL,l_conf_hdr_id,x_return_status);
8113
8114 x_progress := 'POR_AMENDMENT_PKG.amendment_post_approval: 02, finished';
8115 IF (g_po_wf_debug = 'Y') THEN
8116 /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
8117 END IF;
8118
8119 END amendment_post_approval;
8120
8121 PROCEDURE process_cancel_amendments(p_req_header_id IN NUMBER,
8122 p_conf_hdr_id IN NUMBER)
8123 IS
8124
8125 pragma AUTONOMOUS_TRANSACTION;
8126 l_use_gl_date VARCHAR2(1);
8127 x_amendment_reason PO_REQUISITION_HEADERS_ALL.AMENDMENT_REASON%TYPE;
8128 x_preparer_id PO_REQUISITION_HEADERS_ALL.PREPARER_ID%TYPE;
8129 x_req_line_id po_requisition_lines_all.REQUISITION_LINE_ID%TYPE;
8130 x_conf_line_id po_requisition_lines_all.CONFORMED_LINE_ID%TYPE;
8131 l_return_status VARCHAR2(1);
8132 l_po_return_code VARCHAR2(10);
8133 l_detailed_results po_fcout_type;
8134 X_req_control_error_rc VARCHAR2(1) := NULL;
8135 l_req_encumbrance_on VARCHAR2(1);
8136 l_valid_cancel_action VARCHAR2(1);
8137 x_po_line_id po_requisition_lines_all.po_line_id%TYPE;
8138 x_line_loc_id po_requisition_lines_all.line_location_id%TYPE;
8139 x_org_id NUMBER;
8140
8141 CURSOR get_cancel_lines(x_req_header_id NUMBER) IS
8142 SELECT REQUISITION_LINE_ID,CONFORMED_LINE_ID
8143 FROM po_requisition_lines_all
8144 WHERE requisition_header_id = x_req_header_id
8145 AND AMENDMENT_TYPE = 'CANCELLED'
8146 AND AMENDMENT_STATUS = 'N';
8147
8148 BEGIN
8149 fnd_profile.get('PO_GL_DATE',l_use_gl_date);
8150
8151 SELECT AMENDMENT_REASON, PREPARER_ID, ORG_ID
8152 INTO x_amendment_reason, x_preparer_id, x_org_id
8153 FROM PO_REQUISITION_HEADERS_ALL
8154 WHERE requisition_header_id = p_req_header_id;
8155
8156 l_req_encumbrance_on := POR_UTIL_PKG.BOOL_TO_VARCHAR(po_core_s.Is_encumbrance_on(p_doc_type => 'REQUISITION',p_org_id => x_org_id));
8157
8158 OPEN get_cancel_lines(p_req_header_id);
8159 LOOP
8160 FETCH get_cancel_lines INTO x_req_line_id, x_conf_line_id;
8161 EXIT WHEN get_cancel_lines%NOTFOUND;
8162
8163 SELECT po_line_id, line_location_id
8164 INTO x_po_line_id, x_line_loc_id
8165 FROM po_requisition_lines_all
8166 WHERE requisition_line_id = x_conf_line_id;
8167
8168 IF x_po_line_id IS NOT NULL OR x_line_loc_id IS NOT NULL THEN
8169 l_valid_cancel_action := 'N';
8170 ELSE
8171 l_valid_cancel_action := POR_UTIL_PKG.BOOL_TO_VARCHAR(PO_REQS_CONTROL_SV.val_reqs_action(
8172 p_conf_hdr_id, x_conf_line_id, x_preparer_id, 'REQUISITION', 'PURCHASE', 'CANCEL', '', sysdate, l_req_encumbrance_on,
8173 po_core_s.get_product_install_status('OE')));
8174
8175 IF l_valid_cancel_action = 'Y' THEN
8176
8177 IF l_req_encumbrance_on = 'Y' THEN
8178
8179 UPDATE po_requisition_lines_all set cancel_flag = 'I'
8180 WHERE requisition_line_id = x_conf_line_id and nvl(cancel_flag,'N') = 'N';
8181
8182 COMMIT;
8183
8184 PO_DOCUMENT_FUNDS_GRP.do_cancel(
8185 p_api_version => 1.0
8186 , p_commit => FND_API.G_TRUE
8187 , p_init_msg_list => FND_API.G_FALSE
8188 , p_validation_level => FND_API.G_VALID_LEVEL_FULL
8189 , x_return_status => l_return_status
8190 , p_doc_type => PO_DOCUMENT_FUNDS_GRP.g_doc_type_REQUISITION
8191 , p_doc_subtype => NULL
8192 , p_doc_level => 'LINE'
8193 , p_doc_level_id => x_conf_line_id
8194 , p_override_funds => PO_DOCUMENT_FUNDS_GRP.g_parameter_USE_PROFILE --use profile value
8195 , p_use_gl_date => l_use_gl_date
8196 , p_override_date => SYSDATE
8197 , p_report_successes => PO_DOCUMENT_FUNDS_GRP.g_parameter_NO
8198 , x_po_return_code => l_po_return_code
8199 , x_detailed_results => l_detailed_results
8200 );
8201
8202 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR OR l_return_status IS NULL THEN
8203
8204 UPDATE po_requisition_lines_all set amendment_response_reason = 'Cancel Funds failed. Contact Purchasing Administrator if necessary.',
8205 amendment_status = 'R',
8206 amendment_type = 'CANCELLED'
8207 WHERE requisition_line_id IN (x_conf_line_id, x_req_line_id);
8208
8209 update po_requisition_lines_all set cancel_flag = NULL
8210 where requisition_line_id = x_conf_line_id and nvl(cancel_flag,'N') = 'I';
8211
8212 CONTINUE;
8213 END IF;
8214
8215 IF l_po_return_code = 'WARNING' THEN
8216
8217 UPDATE po_requisition_lines_all set amendment_response_reason = 'Cancel Funds completed with warnings.',
8218 amendment_type = 'CANCELLED'
8219 WHERE requisition_line_id in (x_req_line_id, x_conf_line_id);
8220
8221 ELSE IF l_po_return_code = 'FAILURE' THEN
8222
8223 UPDATE po_requisition_lines_all set amendment_response_reason = 'Cancel Funds completed with errors.',
8224 amendment_status = 'R',
8225 amendment_type = 'CANCELLED'
8226 WHERE requisition_line_id in (x_req_line_id, x_conf_line_id);
8227
8228 update po_requisition_lines_all set cancel_flag = NULL
8229 where requisition_line_id = x_conf_line_id and nvl(cancel_flag,'N') = 'I';
8230
8231 CONTINUE;
8232
8233 END IF;
8234 END IF;
8235 COMMIT;
8236 END IF; -- end of l_req_encumbrance_on = Y
8237
8238 po_reqs_control_sv.update_reqs_status
8239 (p_conf_hdr_id,
8240 x_conf_line_id,
8241 x_preparer_id,
8242 'REQUISITION',
8243 'PURCHASE',
8244 'CANCEL',
8245 x_amendment_reason,
8246 SYSDATE,
8247 l_req_encumbrance_on,
8248 po_core_s.get_product_install_status('OE'),
8249 X_req_control_error_rc);
8250
8251 po_negotiation_req_notif.call_negotiation_wf('REQ HEADER', p_conf_hdr_id);
8252
8253 UPDATE po_requisition_lines_all SET amendment_status = 'A',
8254 amendment_type = 'CANCELLED'
8255 WHERE requisition_line_id in (x_req_line_id, x_conf_line_id);
8256
8257 ELSE
8258
8259 UPDATE po_requisition_lines_all SET amendment_status = 'R',
8260 amendment_type = 'CANCELLED'
8261 WHERE requisition_line_id in (x_req_line_id, x_conf_line_id);
8262
8263 END IF;
8264 END IF;
8265
8266 END LOOP;
8267 CLOSE get_cancel_lines;
8268 COMMIT;
8269 END process_cancel_amendments;
8270
8271 FUNCTION is_req_liquidatable(l_req_header_id IN NUMBER)
8272 RETURN NUMBER
8273 IS
8274
8275 l_status NUMBER :=0;
8276 l_req_cnt NUMBER:=0;
8277 l_po_cnt NUMBER :=0;
8278
8279 BEGIN
8280
8281 l_req_cnt := is_req_amendable(l_req_header_id);
8282
8283 IF(l_req_cnt = 0) THEN
8284
8285 SELECT Count(*)
8286 INTO l_po_cnt
8287 FROM po_clmreq_line_awd_refs_v
8288 WHERE requisition_header_id = l_req_header_id
8289 AND Nvl(authorization_status,'INCOMPLETE') NOT IN ('APPROVED','REJECTED','CANCELLED');
8290
8291 IF(l_po_cnt >0) THEN
8292 l_status :=20;
8293 ELSE
8294 l_status:=0;
8295 END IF;
8296 ELSE
8297 l_status :=10;
8298 END IF;
8299
8300 RETURN l_status;
8301
8302 END;
8303
8304
8305 PROCEDURE is_federal_req(p_req_header_id IN number,
8306 x_return_status OUT NOCOPY VARCHAR2)
8307 IS
8308
8309 BEGIN
8310
8311 x_return_status :='N';
8312
8313 if(p_req_header_id is not null) THEN
8314
8315 Select 'Y' into x_return_status from PO_REQUISITION_HEADERS_ALL where requisition_header_id=p_req_header_id and federal_flag='Y';
8316
8317 END IF;
8318
8319 EXCEPTION
8320
8321 WHEN NO_DATA_FOUND THEN
8322
8323 x_return_status :='N';
8324
8325 END is_federal_req;
8326
8327 END por_amendment_pkg;