[Home] [Help]
PACKAGE BODY: APPS.PO_CORE_S
Source
1 PACKAGE BODY PO_CORE_S AS
2 -- $Header: POXCOC1B.pls 120.42.12020000.5 2013/03/24 05:43:36 zexie ship $
3
4
5 -----------------------------------------------------------------------------
6 -- Declare private package variables.
7 -----------------------------------------------------------------------------
8
9 -- Debugging
10
11 g_pkg_name CONSTANT
12 VARCHAR2(30)
13 := 'PO_CORE_S'
14 ;
15 g_log_head CONSTANT
16 VARCHAR2(50)
17 := 'po.plsql.' || g_pkg_name || '.'
18 ;
19
20 g_debug_stmt CONSTANT
21 BOOLEAN
22 := PO_DEBUG.is_debug_stmt_on
23 ;
24 g_debug_unexp CONSTANT
25 BOOLEAN
26 := PO_DEBUG.is_debug_unexp_on
27 ;
28
29
30 D_PACKAGE_BASE CONSTANT VARCHAR2(100) := PO_LOG.get_package_base(g_pkg_name);
31 -----------------------------------------------------------------------------
32 -- Declare private package types.
33 -----------------------------------------------------------------------------
34
35
36 -- Bug 3292870
37 TYPE g_rowid_char_tbl IS TABLE OF VARCHAR2(18);
38
39
40
41 -----------------------------------------------------------------------------
42 -- Define procedures.
43 -----------------------------------------------------------------------------
44
45 PROCEDURE get_open_encumbrance_stats(
46 p_doc_type IN VARCHAR2
47 , p_doc_level IN VARCHAR2
48 , p_doc_level_id IN NUMBER
49 , x_reserved_count OUT NOCOPY NUMBER
50 , x_unreserved_count OUT NOCOPY NUMBER
51 , x_prevented_count OUT NOCOPY NUMBER
52 );
53
54 -- <GC FPJ START>
55 -- Prototype of get_gc_amount_released
56
57 FUNCTION get_gc_amount_released
58 (
59 p_po_header_id IN NUMBER,
60 p_convert_to_base IN BOOLEAN := FALSE
61 ) RETURN NUMBER;
62
63 -- <GC FPJ END>
64
65
66 /* ===========================================================================
67
68 FUNCTION NAME : get_ussgl_option
69
70 DESCRIPTION :
71
72 CLIENT/SERVER : SERVER
73
74 LIBRARY NAME :
75
76 OWNER : SUBHAJIT PURKAYASTHA
77
78 PARAMETERS :
79
80 ALGORITHM : Use fnd_profile.get function to retreive the value
81
82 NOTES : Add sqlcode param in the call to po_message_c.sql_error
83 - SI 04/08
84
85 =========================================================================== */
86 FUNCTION get_ussgl_option RETURN VARCHAR2 is
87
88 x_progress VARCHAR2(3) := NULL;
89 x_option_value VARCHAR2(1);
90 begin
91 x_progress := 10;
92
93 fnd_profile.get('USSGL_OPTION',x_option_value);
94
95 RETURN(x_option_value);
96
97 EXCEPTION
98 WHEN OTHERS THEN
99 po_message_s.sql_error('get_ussgl_option', x_progress, sqlcode);
100 RAISE;
101
102 end get_ussgl_option;
103
104 /* ===========================================================================
105
106 FUNCTION NAME : get_gl_set_of_bks_id
107
108 DESCRIPTION :
109
110 CLIENT/SERVER : SERVER
111
112 LIBRARY NAME :
113
114 OWNER : SUBHAJIT PURKAYASTHA
115
116 PARAMETERS :
117
118 ALGORITHM : Use fnd_profile.get function to retreive the value
119
120 NOTES :
121
122 =========================================================================== */
123 FUNCTION get_gl_set_of_bks_id RETURN VARCHAR2 is
124
125 x_progress VARCHAR2(3) := NULL;
126 x_option_value VARCHAR2(3);
127 begin
128 x_progress := 10;
129
130 /* Replaced the profile option name from 'GL_SET_OF_BKS_ID' to GL_ACCESS_SET_ID'*/
131
132 fnd_profile.get('GL_ACCESS_SET_ID',x_option_value); --<R12 Ledger Architecture>
133
134 RETURN(x_option_value);
135
136 EXCEPTION
137 WHEN OTHERS THEN
138 po_message_s.sql_error('get_gl_set_of_bks_id', x_progress, sqlcode);
139 RAISE;
140
141 end get_gl_set_of_bks_id;
142
143 /* ===========================================================================
144 FUNCTION get_conversion_rate (
145 x_set_of_books_id NUMBER,
146 x_from_currency VARCHAR2,
147 x_conversion_date DATE,
148 x_conversion_type VARCHAR2 DEFAULT NULL ) RETURN NUMBER;
149
150 DESCRIPTION : Returns the rate between the two currencies for a
151 given conversion date and conversion type.
152 CLIENT/SERVER : SERVER
153
154 LIBRARY NAME :
155
156 OWNER : GKELLNER
157
158 PARAMETERS : x_set_of_books_id Set of Books you are in
159 x_from_currency From currency
160 x_conversion_date Conversion date
161 x_conversion_type Conversion type
162
163 RETURN : Rate The conversion rate between
164 the two currencies
165
166 NOTES : We need this cover on top of gl_currency_api.get_rate
167 so that we can handle the gl_currency_api.no_rate and
168 no_data_found exception properly
169
170 =========================================================================== */
171 FUNCTION get_conversion_rate (
172 x_set_of_books_id NUMBER,
173 x_from_currency VARCHAR2,
174 x_conversion_date DATE,
175 x_conversion_type VARCHAR2 DEFAULT NULL )
176
177 RETURN NUMBER IS
178
179 x_conversion_rate NUMBER := 0;
180 x_progress VARCHAR2(3) := '000';
181
182 BEGIN
183
184 x_conversion_rate := gl_currency_api.get_rate (
185 x_set_of_books_id,
186 x_from_currency ,
187 x_conversion_date,
188 x_conversion_type);
189
190 -- <2694908>: Truncate rate value (as done in PO_CURRENCY_SV.get_rate( ))
191 x_conversion_rate := round(x_conversion_rate, 15);
192
193 return (x_conversion_rate);
194
195 EXCEPTION
196 WHEN gl_currency_api.no_rate THEN
197 return(NULL);
198 WHEN no_data_found THEN
199 return(NULL);
200 WHEN OTHERS THEN
201 RAISE;
202
203 END get_conversion_rate;
204
205 /* ===========================================================================
206 PROCEDURE NAME : get_org_sob (x_org_id OUT NOCOPY NUMBER,
207 x_org_name OUT NOCOPY VARCHAR2,
208 x_sob_id OUT NOCOPY NUMBER)
209
210 DESCRIPTION :
211
212 CLIENT/SERVER : SERVER
213
214 LIBRARY NAME :
215
216 OWNER : SUBHAJIT PURKAYASTHA
217
218 PARAMETERS : x_org_id - Return's the Id of the organization
219 x_org_name - Return's the name of the organization
220 x_sob_id - Return's the SOB id
221
222 ALGORITHM : AOL function fnd_profile.get('MFG_ORGANIZATION_ID') returns
223 the default id of the org.
224 If id <> 0 then
225 retreive organization name and sob id from
226 org_organization_definitions table based on org_id
227 else
228 retreive purchasing organization from
229 financials_system_parameters and gl_sets_of_books table
230
231 NOTES :
232
233 =========================================================================== */
234
235 PROCEDURE get_org_sob (x_org_id OUT NOCOPY NUMBER,
236 x_org_name OUT NOCOPY VARCHAR2,
237 x_sob_id OUT NOCOPY NUMBER) is
238 x_progress VARCHAR2(3) := NULL;
239 org_id NUMBER;
240
241 /** <UTF8 FPI> **/
242 /** tpoon 9/27/2002 **/
243 /** Changed org_name to use %TYPE **/
244 -- org_name VARCHAR2(60);
245 org_name hr_all_organization_units.name%TYPE;
246
247 sob_id NUMBER;
248 begin
249 x_progress := 10;
250 fnd_profile.get('MFG_ORGANIZATION_ID',org_id);
251 if org_id <> 0 then
252
253 x_progress := 20;
254 select organization_name,
255 set_of_books_id
256 into org_name,
257 sob_id
258 FROM org_organization_definitions
259 WHERE organization_id = org_id ;
260
261 else
262 --Get purchasing organization
263 x_progress := 30;
264 SELECT fsp.inventory_organization_id,
265 fsp.set_of_books_id,
266 sob.name
267 INTO org_id,
268 sob_id,
269 org_name
270 FROM financials_system_parameters fsp,
271 gl_sets_of_books sob
272 WHERE fsp.set_of_books_id = sob.set_of_books_id;
273
274 end if;
275 x_progress := 40;
276 --Associate each of the OUT NOCOPY variable with local variable
277
278 x_org_id := org_id;
279 x_org_name := org_name;
280 x_sob_id := sob_id;
281
282 EXCEPTION
283 WHEN OTHERS THEN
284 po_message_s.sql_error('get_org_sob', x_progress, sqlcode);
285 RAISE;
286 end get_org_sob;
287
288 /* ===========================================================================
289 PROCEDURE NAME: get_po_parameters
290
291 DESCRIPTION :
292
293 CLIENT/SERVER : SERVER
294
295 LIBRARY NAME :
296
297 OWNER : SUBHAJIT PURKAYASTHA
298
299 PARAMETERS : x_currency_code
300 x_coa_id
301 x_po_encumberance_flag
302 x_req_encumberance_flag
303 x_sob_id
304 x_ship_to_location_id
305 x_bill_to_location_id
306 x_fob_lookup_code
307 x_freight_terms_lookup_code
308 x_terms_id
309 x_default_rate_type
310 x_taxable_flag
311 x_receiving_flag
312 x_enforce_buyer_name_flag
313 x_enforce_buyer_auth_flag
314 x_line_type_id
315 x_manual_po_num_type
316 x_po_num_code
317 x_price_lookup_code
318 x_invoice_close_tolerance
319 x_receive_close_tolerance
320 x_security_structure_id
321 x_expense_accrual_code
322 x_inv_org_id
323 x_rev_sort_ordering
324 x_min_rel_amount
325 x_notify_blanket_flag
326 x_budgetary_control_flag
327 x_user_defined_req_num_code
328 x_rfq_required_flag
329 x_manual_req_num_type
330 x_enforce_full_lot_qty
331 x_disposition_warning_flag
332 x_reserve_at_completion_flag
333 x_user_defined_rcpt_num_code
334 x_manual_rcpt_num_type
335 x_use_positions_flag
336 x_default_quote_warning_delay
337 x_inspection_required_flag
338 x_user_defined_quote_num_code
339 x_manual_quote_num_type
340 x_user_defined_rfq_num_code
341 x_manual_rfq_num_type
342 x_ship_via_lookup_code
343 x_qty_rcv_tolerance
344
345
346 ALGORITHM : Retreive po parameters from
347 financials_system_parameters,gl_sets_of_books,
348 po_system_parameters and rcv_parameters tables.
349
350 NOTES :
351
352 =========================================================================== */
356 x_req_encumberance_flag OUT NOCOPY VARCHAR2,
353 PROCEDURE get_po_parameters ( x_currency_code OUT NOCOPY VARCHAR2,
354 x_coa_id OUT NOCOPY NUMBER,
355 x_po_encumberance_flag OUT NOCOPY VARCHAR2,
357 x_sob_id OUT NOCOPY NUMBER,
358 x_ship_to_location_id OUT NOCOPY NUMBER,
359 x_bill_to_location_id OUT NOCOPY NUMBER,
360 x_fob_lookup_code OUT NOCOPY VARCHAR2,
361 x_freight_terms_lookup_code OUT NOCOPY VARCHAR2,
362 x_terms_id OUT NOCOPY NUMBER,
363 x_default_rate_type OUT NOCOPY VARCHAR2,
364 x_taxable_flag OUT NOCOPY VARCHAR2,
365 x_receiving_flag OUT NOCOPY VARCHAR2,
366 x_enforce_buyer_name_flag OUT NOCOPY VARCHAR2,
367 x_enforce_buyer_auth_flag OUT NOCOPY VARCHAR2,
368 x_line_type_id OUT NOCOPY NUMBER,
369 x_manual_po_num_type OUT NOCOPY VARCHAR2,
370 x_po_num_code OUT NOCOPY VARCHAR2,
371 x_price_lookup_code OUT NOCOPY VARCHAR2,
372 x_invoice_close_tolerance OUT NOCOPY NUMBER,
373 x_receive_close_tolerance OUT NOCOPY NUMBER,
374 x_security_structure_id OUT NOCOPY NUMBER,
375 x_expense_accrual_code OUT NOCOPY VARCHAR2,
376 x_inv_org_id OUT NOCOPY NUMBER,
377 x_rev_sort_ordering OUT NOCOPY NUMBER,
378 x_min_rel_amount OUT NOCOPY NUMBER,
379 x_notify_blanket_flag OUT NOCOPY VARCHAR2,
380 x_budgetary_control_flag OUT NOCOPY VARCHAR2,
381 x_user_defined_req_num_code OUT NOCOPY VARCHAR2,
382 x_rfq_required_flag OUT NOCOPY VARCHAR2,
383 x_manual_req_num_type OUT NOCOPY VARCHAR2,
384 x_enforce_full_lot_qty OUT NOCOPY VARCHAR2,
385 x_disposition_warning_flag OUT NOCOPY VARCHAR2,
386 x_reserve_at_completion_flag OUT NOCOPY VARCHAR2,
387 x_user_defined_rcpt_num_code OUT NOCOPY VARCHAR2,
388 x_manual_rcpt_num_type OUT NOCOPY VARCHAR2,
389 x_use_positions_flag OUT NOCOPY VARCHAR2,
390 x_default_quote_warning_delay OUT NOCOPY NUMBER,
391 x_inspection_required_flag OUT NOCOPY VARCHAR2,
392 x_user_defined_quote_num_code OUT NOCOPY VARCHAR2,
393 x_manual_quote_num_type OUT NOCOPY VARCHAR2,
394 x_user_defined_rfq_num_code OUT NOCOPY VARCHAR2,
395 x_manual_rfq_num_type OUT NOCOPY VARCHAR2,
396 x_ship_via_lookup_code OUT NOCOPY VARCHAR2,
397 x_qty_rcv_tolerance OUT NOCOPY NUMBER
398 ) is
399
400 x_progress VARCHAR2(3) := NULL;
401 x_acceptance_required_flag VARCHAR2(1) := NULL;
402 begin
403 x_progress := 10;
404
405
406 get_po_parameters ( x_currency_code => x_currency_code
407 ,x_coa_id => x_coa_id
408 ,x_po_encumberance_flag => x_po_encumberance_flag
409 ,x_req_encumberance_flag => x_req_encumberance_flag
410 ,x_sob_id => x_sob_id
411 ,x_ship_to_location_id => x_ship_to_location_id
412 ,x_bill_to_location_id => x_bill_to_location_id
413 ,x_fob_lookup_code => x_fob_lookup_code
414 ,x_freight_terms_lookup_code => x_freight_terms_lookup_code
415 ,x_terms_id => x_terms_id
416 ,x_default_rate_type => x_default_rate_type
417 ,x_taxable_flag => x_taxable_flag
418 ,x_receiving_flag => x_receiving_flag
419 ,x_enforce_buyer_name_flag => x_enforce_buyer_name_flag
420 ,x_enforce_buyer_auth_flag => x_enforce_buyer_auth_flag
421 ,x_line_type_id => x_line_type_id
422 ,x_manual_po_num_type => x_manual_po_num_type
423 ,x_po_num_code => x_po_num_code
424 ,x_price_lookup_code => x_price_lookup_code
425 ,x_invoice_close_tolerance => x_invoice_close_tolerance
426 ,x_receive_close_tolerance => x_receive_close_tolerance
427 ,x_security_structure_id => x_security_structure_id
428 ,x_expense_accrual_code => x_expense_accrual_code
429 ,x_inv_org_id => x_inv_org_id
430 ,x_rev_sort_ordering => x_rev_sort_ordering
431 ,x_min_rel_amount => x_min_rel_amount
432 ,x_notify_blanket_flag => x_notify_blanket_flag
436 ,x_manual_req_num_type => x_manual_req_num_type
433 ,x_budgetary_control_flag => x_budgetary_control_flag
434 ,x_user_defined_req_num_code => x_user_defined_req_num_code
435 ,x_rfq_required_flag => x_rfq_required_flag
437 ,x_enforce_full_lot_qty => x_enforce_full_lot_qty
438 ,x_disposition_warning_flag => x_disposition_warning_flag
439 ,x_reserve_at_completion_flag => x_reserve_at_completion_flag
440 ,x_user_defined_rcpt_num_code => x_user_defined_rcpt_num_code
441 ,x_manual_rcpt_num_type => x_manual_rcpt_num_type
442 ,x_use_positions_flag => x_use_positions_flag
443 ,x_default_quote_warning_delay => x_default_quote_warning_delay
444 ,x_inspection_required_flag => x_inspection_required_flag
445 ,x_user_defined_quote_num_code => x_user_defined_quote_num_code
446 ,x_manual_quote_num_type => x_manual_quote_num_type
447 ,x_user_defined_rfq_num_code => x_user_defined_rfq_num_code
448 ,x_manual_rfq_num_type => x_manual_rfq_num_type
449 ,x_ship_via_lookup_code => x_ship_via_lookup_code
450 ,x_qty_rcv_tolerance => x_qty_rcv_tolerance
451 ,x_acceptance_required_flag => x_acceptance_required_flag
452 );
453
454 EXCEPTION
455 WHEN OTHERS THEN
456 po_message_s.sql_error('get_po_parameters', x_progress, sqlcode);
457 RAISE;
458
459 end get_po_parameters;
460
461 /* Bug 7518967: ER Default Acceptance Required Check : Overloading the procedure
462 get_po_parameters to get the default acceptance_required_flag from
463 PO_SYSTEM_PARAMETERS_ALL */
464
465 /* ===========================================================================
466 PROCEDURE NAME: get_po_parameters
467
468 DESCRIPTION :
469
470 CLIENT/SERVER : SERVER
471
472 LIBRARY NAME :
473
474 OWNER : SUBHAJIT PURKAYASTHA
475
476 PARAMETERS : x_currency_code
477 x_coa_id
478 x_po_encumberance_flag
479 x_req_encumberance_flag
480 x_sob_id
481 x_ship_to_location_id
482 x_bill_to_location_id
483 x_fob_lookup_code
484 x_freight_terms_lookup_code
485 x_terms_id
486 x_default_rate_type
487 x_taxable_flag
488 x_receiving_flag
489 x_enforce_buyer_name_flag
490 x_enforce_buyer_auth_flag
491 x_line_type_id
492 x_manual_po_num_type
493 x_po_num_code
494 x_price_lookup_code
495 x_invoice_close_tolerance
496 x_receive_close_tolerance
497 x_security_structure_id
498 x_expense_accrual_code
499 x_inv_org_id
500 x_rev_sort_ordering
501 x_min_rel_amount
502 x_notify_blanket_flag
503 x_budgetary_control_flag
504 x_user_defined_req_num_code
505 x_rfq_required_flag
506 x_manual_req_num_type
507 x_enforce_full_lot_qty
508 x_disposition_warning_flag
509 x_reserve_at_completion_flag
510 x_user_defined_rcpt_num_code
511 x_manual_rcpt_num_type
512 x_use_positions_flag
513 x_default_quote_warning_delay
514 x_inspection_required_flag
515 x_user_defined_quote_num_code
516 x_manual_quote_num_type
517 x_user_defined_rfq_num_code
518 x_manual_rfq_num_type
519 x_ship_via_lookup_code
520 x_qty_rcv_tolerance
521 x_acceptance_required_flag
522
523
524 ALGORITHM : Retreive po parameters from
525 financials_system_parameters,gl_sets_of_books,
526 po_system_parameters and rcv_parameters tables.
527
528 NOTES :
529
530 =========================================================================== */
531 PROCEDURE get_po_parameters ( x_currency_code OUT NOCOPY VARCHAR2,
532 x_coa_id OUT NOCOPY NUMBER,
533 x_po_encumberance_flag OUT NOCOPY VARCHAR2,
534 x_req_encumberance_flag OUT NOCOPY VARCHAR2,
535 x_sob_id OUT NOCOPY NUMBER,
536 x_ship_to_location_id OUT NOCOPY NUMBER,
537 x_bill_to_location_id OUT NOCOPY NUMBER,
538 x_fob_lookup_code OUT NOCOPY VARCHAR2,
539 x_freight_terms_lookup_code OUT NOCOPY VARCHAR2,
540 x_terms_id OUT NOCOPY NUMBER,
541 x_default_rate_type OUT NOCOPY VARCHAR2,
542 x_taxable_flag OUT NOCOPY VARCHAR2,
543 x_receiving_flag OUT NOCOPY VARCHAR2,
544 x_enforce_buyer_name_flag OUT NOCOPY VARCHAR2,
545 x_enforce_buyer_auth_flag OUT NOCOPY VARCHAR2,
546 x_line_type_id OUT NOCOPY NUMBER,
547 x_manual_po_num_type OUT NOCOPY VARCHAR2,
551 x_receive_close_tolerance OUT NOCOPY NUMBER,
548 x_po_num_code OUT NOCOPY VARCHAR2,
549 x_price_lookup_code OUT NOCOPY VARCHAR2,
550 x_invoice_close_tolerance OUT NOCOPY NUMBER,
552 x_security_structure_id OUT NOCOPY NUMBER,
553 x_expense_accrual_code OUT NOCOPY VARCHAR2,
554 x_inv_org_id OUT NOCOPY NUMBER,
555 x_rev_sort_ordering OUT NOCOPY NUMBER,
556 x_min_rel_amount OUT NOCOPY NUMBER,
557 x_notify_blanket_flag OUT NOCOPY VARCHAR2,
558 x_budgetary_control_flag OUT NOCOPY VARCHAR2,
559 x_user_defined_req_num_code OUT NOCOPY VARCHAR2,
560 x_rfq_required_flag OUT NOCOPY VARCHAR2,
561 x_manual_req_num_type OUT NOCOPY VARCHAR2,
562 x_enforce_full_lot_qty OUT NOCOPY VARCHAR2,
563 x_disposition_warning_flag OUT NOCOPY VARCHAR2,
564 x_reserve_at_completion_flag OUT NOCOPY VARCHAR2,
565 x_user_defined_rcpt_num_code OUT NOCOPY VARCHAR2,
566 x_manual_rcpt_num_type OUT NOCOPY VARCHAR2,
567 x_use_positions_flag OUT NOCOPY VARCHAR2,
568 x_default_quote_warning_delay OUT NOCOPY NUMBER,
569 x_inspection_required_flag OUT NOCOPY VARCHAR2,
570 x_user_defined_quote_num_code OUT NOCOPY VARCHAR2,
571 x_manual_quote_num_type OUT NOCOPY VARCHAR2,
572 x_user_defined_rfq_num_code OUT NOCOPY VARCHAR2,
573 x_manual_rfq_num_type OUT NOCOPY VARCHAR2,
574 x_ship_via_lookup_code OUT NOCOPY VARCHAR2,
575 x_qty_rcv_tolerance OUT NOCOPY NUMBER,
576 x_acceptance_required_flag OUT NOCOPY VARCHAR2
577 ) is
578
579 x_progress VARCHAR2(3) := NULL;
580 begin
581 x_progress := 10;
582
583 SELECT sob.currency_code,
584 sob.chart_of_accounts_id,
585 nvl(fsp.purch_encumbrance_flag,'N'),
586 nvl(fsp.req_encumbrance_flag,'N'),
587 sob.set_of_books_id,
588 fsp.ship_to_location_id,
589 fsp.bill_to_location_id,
590 fsp.fob_lookup_code,
591 fsp.freight_terms_lookup_code,
592 aps.terms_id, -- bug5701539
593 psp.default_rate_type,
594 --togeorge 07/03/2001
595 --Bug# 1839659
596 --We are no more using this flag from psp.
597 --psp.taxable_flag,
598 null,
599 --
600 psp.receiving_flag,
601 nvl(psp.enforce_buyer_name_flag, 'N'),
602 nvl(psp.enforce_buyer_authority_flag,'N'),
603 psp.line_type_id,
604 psp.manual_po_num_type,
605 psp.user_defined_po_num_code,
606 psp.price_type_lookup_code,
607 psp.invoice_close_tolerance,
608 psp.receive_close_tolerance,
609 psp.security_position_structure_id,
610 psp.expense_accrual_code,
611 fsp.inventory_organization_id,
612 fsp.revision_sort_ordering,
613 psp.min_release_amount,
614 nvl(psp.notify_if_blanket_flag,'N'),
615 nvl(sob.enable_budgetary_control_flag,'N'),
616 psp.user_defined_req_num_code,
617 nvl(psp.rfq_required_flag,'N'),
618 psp.manual_req_num_type,
619 psp.enforce_full_lot_quantities,
620 psp.disposition_warning_flag,
621 nvl(fsp.reserve_at_completion_flag,'N'),
622 psp.user_defined_receipt_num_code,
623 psp.manual_receipt_num_type,
624 fsp.use_positions_flag,
625 psp.default_quote_warning_delay,
626 psp.inspection_required_flag,
627 psp.user_defined_quote_num_code,
628 psp.manual_quote_num_type,
629 psp.user_defined_rfq_num_code,
630 psp.manual_rfq_num_type,
631 fsp.ship_via_lookup_code,
632 rcv.qty_rcv_tolerance,
633 psp.acceptance_required_flag
634 INTO x_currency_code ,
635 x_coa_id ,
636 x_po_encumberance_flag ,
637 x_req_encumberance_flag ,
638 x_sob_id ,
639 x_ship_to_location_id ,
640 x_bill_to_location_id ,
641 x_fob_lookup_code ,
642 x_freight_terms_lookup_code,
643 x_terms_id ,
644 x_default_rate_type ,
645 x_taxable_flag ,
646 x_receiving_flag ,
647 x_enforce_buyer_name_flag,
648 x_enforce_buyer_auth_flag,
649 x_line_type_id ,
650 x_manual_po_num_type ,
651 x_po_num_code ,
652 x_price_lookup_code ,
653 x_invoice_close_tolerance,
654 x_receive_close_tolerance,
655 x_security_structure_id,
656 x_expense_accrual_code,
657 x_inv_org_id ,
658 x_rev_sort_ordering,
659 x_min_rel_amount ,
660 x_notify_blanket_flag,
661 x_budgetary_control_flag,
662 x_user_defined_req_num_code,
663 x_rfq_required_flag,
664 x_manual_req_num_type,
665 x_enforce_full_lot_qty,
666 x_disposition_warning_flag,
667 x_reserve_at_completion_flag,
671 x_default_quote_warning_delay,
668 x_user_defined_rcpt_num_code,
669 x_manual_rcpt_num_type,
670 x_use_positions_flag,
672 x_inspection_required_flag,
673 x_user_defined_quote_num_code,
674 x_manual_quote_num_type,
675 x_user_defined_rfq_num_code,
676 x_manual_rfq_num_type,
677 x_ship_via_lookup_code,
678 x_qty_rcv_tolerance,
679 x_acceptance_required_flag
680 FROM financials_system_parameters fsp,
681 gl_sets_of_books sob,
682 po_system_parameters psp,
683 rcv_parameters rcv,
684 ap_product_setup aps
685 WHERE fsp.set_of_books_id = sob.set_of_books_id
686 AND rcv.organization_id (+) = fsp.inventory_organization_id;
687
688
689 EXCEPTION
690 WHEN OTHERS THEN
691 po_message_s.sql_error('get_po_parameters', x_progress, sqlcode);
692 RAISE;
693
694 end get_po_parameters;
695
696 /* ===========================================================================
697 PROCEDURE NAME: get_item_category_structure(x_category_set_id OUT NOCOPY NUMBER,
698 x_structure_id OUT NOCOPY NUMBER)
699
700 DESCRIPTION :
701
702 CLIENT/SERVER : SERVER
703
704 LIBRARY NAME :
705
706 OWNER : SUBHAJIT PURKAYASTHA
707
708 PARAMETERS : Category_set_id NUMBER
709 structure_id NUMBER
710
711 ALGORITHM : Retreive category_set_id and structure_id from
712 mtl_default_sets_view for functional_area_id = 2
713
714 NOTES :
715
716 =========================================================================== */
717 PROCEDURE get_item_category_structure ( x_category_set_id OUT NOCOPY NUMBER,
718 x_structure_id OUT NOCOPY NUMBER ) is
719 x_progress VARCHAR2(3) := NULL;
720 begin
721 x_progress := 10;
722 SELECT mdsv.category_set_id,
723 mdsv.structure_id
724 INTO x_category_set_id,
725 x_structure_id
726 FROM mtl_default_sets_view mdsv
727 WHERE mdsv.functional_area_id = 2;
728
729 EXCEPTION
730 WHEN OTHERS THEN
731 po_message_s.sql_error('get_item_category_structure', x_progress, sqlcode);
732 RAISE;
733
734 end get_item_category_structure;
735
736 /* ===========================================================================
737 FUNCTION NAME : get_product_install_status (x_product_name IN VARCHAR2)
738 RETURN VARCHAR2
739
740 DESCRIPTION : Returns the product's installation status
741
742 CLIENT/SERVER : SERVER
743
744 LIBRARY NAME :
745
746 OWNER : SUBHAJIT PURKAYASTHA
747
748 PARAMETERS : x_product_name - Name of the product
749 For eg - 'INV','PO','ENG'
750
751 ALGORITHM : Use fnd_installation.get function to retreive
752 the status of product installation.
753 Function expects product id to be passed
754 Product Id will be derived from FND_APPLICATION table
755 Product Product Id
756 -------- -----------
757 INV 401
758 PO 201
759
760 NOTES : valid installation status:
761 I - Product is installed
762 S - Product is partially installed
763 N - Product is not installed
764 L - Product is a local (custom) application
765
766
767 =========================================================================== */
768
769 FUNCTION get_product_install_status ( x_product_name IN VARCHAR2) RETURN VARCHAR2 IS
770 x_progress VARCHAR2(3) := NULL;
771 x_app_id NUMBER;
772 x_install BOOLEAN;
773 x_status VARCHAR2(1);
774 x_org VARCHAR2(1);
775 x_temp_product_name varchar2(10);
776 begin
777 --Retreive product id from fnd_application based on product name
778 x_progress := 10;
779
780 select application_id
781 into x_app_id
782 from fnd_application
783 where application_short_name = x_product_name ;
784
785 --get product installation status
786 x_progress := 20;
787 x_install := fnd_installation.get(x_app_id,x_app_id,x_status,x_org);
788
789 /* Bug 16240413 : FND_INSTALLATION.get will verify for ONT product as well. No
790 * need to call Oe_install.get_active_product because OE product has been
791 * decommissioned */
792
793 /* if x_product_name in ('OE', 'ONT') then
794
795 if Oe_install.get_active_product() in ('OE', 'ONT') then
796 x_status := 'I';
797 else
798 x_status := 'N';
799 end if;
800 end if;
801 */
802
803 RETURN(x_status);
804
805 EXCEPTION
806 WHEN NO_DATA_FOUND then
807 null;
808 RETURN(null);
809 WHEN OTHERS THEN
810 po_message_s.sql_error('get_product_install_status', x_progress, sqlcode);
811 RAISE;
812
813 end get_product_install_status;
814
815 /* ===========================================================================
816 PROCEDURE NAME: get_global_values(x_userid OUT NOCOPY number,
817 x_logonid OUT NOCOPY number,
818 x_last_upd_date OUT NOCOPY date,
819 x_current_date OUT NOCOPY date )
820
824
821 DESCRIPTION :
822
823 CLIENT/SERVER : SERVER
825 LIBRARY NAME :
826
827 OWNER : SUBHAJIT PURKAYASTHA
828
829 PARAMETERS : x_userid - Returns fnd user_id
830 x_logonid - Return fnd logon id
831 x_last_upd_date - Returns sysdate
832 x_current_date - Returns sysdate
833
834 ALGORITHM :
835
836 NOTES :
837
838 =========================================================================== */
839
840 PROCEDURE get_global_values(x_userid OUT NOCOPY number,
841 x_logonid OUT NOCOPY number,
842 x_last_upd_date OUT NOCOPY date,
843 x_current_date OUT NOCOPY date ) is
844 x_progress VARCHAR2(3) := NULL;
845 begin
846 x_progress := 10;
847 x_userid := fnd_global.user_id;
848
849 x_progress := 20;
850 x_logonid := fnd_global.login_id;
851
852 x_progress := 30;
853 x_last_upd_date := sysdate;
854
855 x_progress := 40;
856 x_current_date := sysdate;
857
858 EXCEPTION
859 WHEN OTHERS THEN
860 po_message_s.sql_error('get_global_values', x_progress, sqlcode);
861 RAISE;
862
863 end get_global_values;
864
865 /*===========================================================================
866
867 PROCEDURE NAME : GET_PERIOD_NAME
868
869 DESCRIPTION : Based on system date, function returns appropriate period
870 and gl_date
871
872 CLIENT/SERVER : SERVER
873
874 LIBRARY NAME :
875
876 OWNER : SUBHAJIT PURKAYASTHA
877
878 PARAMETERS : sob_id - Set_of_books_id
879 period_name - Period Name
880 gl_date - GL Date
881 ALGORITHM :
882
883 NOTES :
884
885 ===========================================================================*/
886 -------------------------------------------------------------------------------
887 --Start of Comments
888 --Name: get_period_name
889 --Pre-reqs:
890 -- None.
891 --Modifies:
892 -- None.
893 --Locks:
894 -- None.
895 --Function:
896 -- Retrieves the GL period name and date for SYSDATE,
897 -- if the date is in a usable period (valid for GL and PO).
898 --Parameters:
899 --IN:
900 --x_sob_id
901 -- Set of books.
902 --OUT:
903 --x_gl_period
904 -- The period name corresponding to SYSDATE.
905 --x_gl_date
906 -- SYSDATE.
907 --Notes:
908 -- This procedure was refactored in FPJ to call the more generalized
909 -- procedure get_period_info. However, the parameter names were
910 -- not changed to meet standards, as that may have impacted calling code.
911 --Testing:
912 --
913 --End of Comments
914 -------------------------------------------------------------------------------
915 PROCEDURE get_period_name (
916 x_sob_id IN NUMBER
917 , x_period OUT NOCOPY VARCHAR2
918 , x_gl_date OUT NOCOPY DATE
919 )
920 IS
921
922
923 l_log_head CONSTANT VARCHAR2(100) := g_log_head||'GET_PERIOD_NAME';
924 l_progress VARCHAR2(3) := '000';
925
926 l_period_name_tbl po_tbl_varchar30;
927 l_period_year_tbl po_tbl_number;
928 l_period_num_tbl po_tbl_number;
929 l_quarter_num_tbl po_tbl_number;
930 l_invalid_period_flag VARCHAR2(1);
931
932 BEGIN
933
934 IF g_debug_stmt THEN
935 PO_DEBUG.debug_begin(l_log_head);
936 PO_DEBUG.debug_var(l_log_head,l_progress,'x_sob_id',x_sob_id);
937 END IF;
938
939 l_progress := '010';
940
941 PO_PERIODS_SV.get_period_info(
942 p_roll_logic => NULL
943 , p_set_of_books_id => x_sob_id
944 , p_date_tbl => po_tbl_date( SYSDATE )
945 , x_period_name_tbl => l_period_name_tbl
946 , x_period_year_tbl => l_period_year_tbl
947 , x_period_num_tbl => l_period_num_tbl
948 , x_quarter_num_tbl => l_quarter_num_tbl
949 , x_invalid_period_flag => l_invalid_period_flag
950 );
951
952 l_progress := '020';
953
954 x_period := l_period_name_tbl(1);
955
956 IF (l_invalid_period_flag = FND_API.G_FALSE) THEN
957
958 l_progress := '030';
959 IF g_debug_stmt THEN
960 PO_DEBUG.debug_stmt(l_log_head,l_progress,'valid period');
961 END IF;
962
963 x_gl_date := TRUNC(SYSDATE);
964
965 END IF;
966
967 l_progress := '900';
968
969 IF g_debug_stmt THEN
970 PO_DEBUG.debug_var(l_log_head,l_progress,'x_period',x_period);
971 PO_DEBUG.debug_var(l_log_head,l_progress,'x_gl_date',x_gl_date);
972 PO_DEBUG.debug_end(l_log_head);
973 END IF;
974
975 EXCEPTION
976 WHEN OTHERS THEN
977 IF g_debug_unexp THEN
978 PO_DEBUG.debug_exc(l_log_head,l_progress);
979 END IF;
980 RAISE;
981
982 END get_period_name;
983
984
985
986
987 /* ===========================================================================
988 PROCEDURE NAME: get_displayed_value(x_lookup_type IN VARCHAR2,
989 x_lookup_code IN VARCHAR2,
993
990 x_disp_value OUT NOCOPY VARCHAR2,
991 x_description OUT NOCOPY VARCHAR2,
992 x_validate IN BOOLEAN)
994 DESCRIPTION : Obtain the displayed field and description. This procedure
995 also performs active date validation.
996
997 CLIENT/SERVER : SERVER
998
999 LIBRARY NAME :
1000
1001 OWNER : Ramana Mulpury
1002
1003 PARAMETERS : lookup_type VARCHAR2
1004 lookup_type VARCHAR2
1005 displayed_field VARCHAR2
1006 descriptioni VARCHAR2
1007 validate BOOLEAN
1008
1009 ALGORITHM : Get the displayed field and description from the
1010 table po_lookup_codes. These values are validated
1011 against the inactive date if x_validate is set to TRUE
1012 No validation is performed if x_validate is set to
1013 FALSE.
1014 NOTES :
1015
1016 =========================================================================== */
1017 PROCEDURE get_displayed_value (x_lookup_type IN VARCHAR2,
1018 x_lookup_code IN VARCHAR2,
1019 x_disp_value OUT NOCOPY VARCHAR2,
1020 x_description OUT NOCOPY VARCHAR2,
1021 x_validate IN BOOLEAN) IS
1022 x_progress VARCHAR2(3) := NULL;
1023 begin
1024
1025 x_progress := 10;
1026
1027 IF (x_validate = TRUE) THEN
1028
1029 SELECT plc.displayed_field,
1030 plc.description
1031 INTO x_disp_value,
1032 x_description
1033 FROM po_lookup_codes plc
1034 WHERE plc.lookup_code = x_lookup_code
1035 AND plc.lookup_type = x_lookup_type
1036 AND sysdate < nvl(plc.inactive_date,sysdate + 1);
1037
1038 ELSE
1039 get_displayed_value(x_lookup_type, x_lookup_code, x_disp_value, x_description);
1040
1041 END IF;
1042
1043 EXCEPTION
1044 WHEN NO_DATA_FOUND THEN
1045 x_disp_value := NULL;
1046 x_description := NULL;
1047
1048 WHEN OTHERS THEN
1049 po_message_s.sql_error('get_displayed_value', x_progress, sqlcode);
1050 RAISE;
1051
1052 end get_displayed_value;
1053
1054
1055
1056 /* ===========================================================================
1057 PROCEDURE NAME: get_displayed_value(x_lookup_type IN VARCHAR2,
1058 x_lookup_code IN VARCHAR2,
1059 x_disp_value OUT NOCOPY VARCHAR2,
1060 x_description OUT NOCOPY VARCHAR2)
1061
1062 DESCRIPTION : Obtain the displayed field and description
1063
1064 CLIENT/SERVER : SERVER
1065
1066 LIBRARY NAME :
1067
1068 OWNER : Ramana Mulpury
1069
1070 PARAMETERS : lookup_type VARCHAR2
1071 lookup_type VARCHAR2
1072 displayed_field VARCHAR2
1073 descriptioni VARCHAR2
1074
1075 ALGORITHM : Get the displayed field and description from the
1076 table po_lookup_codes.
1077
1078 NOTES :
1079
1080 =========================================================================== */
1081 PROCEDURE get_displayed_value (x_lookup_type IN VARCHAR2,
1082 x_lookup_code IN VARCHAR2,
1083 x_disp_value OUT NOCOPY VARCHAR2,
1084 x_description OUT NOCOPY VARCHAR2) IS
1085 x_progress VARCHAR2(3) := NULL;
1086 begin
1087
1088 x_progress := 10;
1089
1090 SELECT plc.displayed_field,
1091 plc.description
1092 INTO x_disp_value,
1093 x_description
1094 FROM po_lookup_codes plc
1095 WHERE plc.lookup_code = x_lookup_code
1096 AND plc.lookup_type = x_lookup_type;
1097
1098 EXCEPTION
1099 WHEN NO_DATA_FOUND THEN
1100 x_disp_value := NULL;
1101 x_description := NULL;
1102
1103 WHEN OTHERS THEN
1104 po_message_s.sql_error('get_displayed_value', x_progress, sqlcode);
1105 RAISE;
1106
1107 end get_displayed_value;
1108
1109
1110 /* ===========================================================================
1111 PROCEDURE NAME: get_displayed_value(x_lookup_type IN VARCHAR2,
1112 x_lookup_code IN VARCHAR2,
1113 x_disp_value OUT NOCOPY VARCHAR2)
1114
1115 DESCRIPTION : Obtain the displayed field . This is an overloaded
1116 procedure
1117
1118 CLIENT/SERVER : SERVER
1119
1120 LIBRARY NAME :
1121
1122 OWNER : Ramana Mulpury
1123
1124 PARAMETERS : lookup_type VARCHAR2
1125 lookup_code VARCHAR2
1126 displayed_field VARCHAR2
1127
1128
1129 ALGORITHM : Get the displayed field from the table po_lookup_codes.
1130
1131 NOTES :
1132
1133 =========================================================================== */
1134 PROCEDURE get_displayed_value (x_lookup_type IN VARCHAR2,
1135 x_lookup_code IN VARCHAR2,
1136 x_disp_value OUT NOCOPY VARCHAR2) IS
1137
1138 x_progress VARCHAR2(3) := NULL;
1139
1140 begin
1141
1142 x_progress := 10;
1143
1144 SELECT plc.displayed_field
1145 INTO x_disp_value
1146 FROM po_lookup_codes plc
1147 WHERE plc.lookup_code = x_lookup_code
1148 AND plc.lookup_type = x_lookup_type;
1149
1150 EXCEPTION
1151 WHEN NO_DATA_FOUND THEN
1152 x_disp_value := NULL;
1156 RAISE;
1153
1154 WHEN OTHERS THEN
1155 po_message_s.sql_error('get_displayed_value', x_progress, sqlcode);
1157
1158 end get_displayed_value;
1159
1160 /*===========================================================================
1161 FUNCTION NAME: get_total
1162
1163 ===========================================================================*/
1164 FUNCTION get_total (x_object_type IN VARCHAR2,
1165 x_object_id IN NUMBER) RETURN NUMBER IS
1166 x_total NUMBER;
1167 BEGIN
1168 x_total := get_total(x_object_type,
1169 x_object_id,
1170 NULL);
1171 return(x_total);
1172 END;
1173
1174
1175 -- Bug 5124868: as part of refactoring for this bug, the get_entity_org_id
1176 -- method was removed from this package and moved to PO_MOAC_UTILS_PVT.
1177 -- get_entity_org_id was originally created for bug 5092574
1178
1179
1180 /*===========================================================================
1181 FUNCTION NAME: get_total
1182
1183 ===========================================================================*/
1184 --<CONTERMS FPJ START>
1185 -- When making any change to this function please check if get_archive_total/get_archive_total_for_any_rev
1186 -- also needs to be change correspondigly
1187 --<CONTERMS FPJ END>
1188 FUNCTION get_total (x_object_type IN VARCHAR2,
1189 x_object_id IN NUMBER,
1190 x_base_cur_result IN BOOLEAN) RETURN NUMBER IS
1191 x_progress VARCHAR2(3) := NULL;
1192 x_base_currency VARCHAR2(16);
1193 x_po_currency VARCHAR2(16);
1194 x_min_unit NUMBER;
1195 x_base_min_unit NUMBER;
1196 x_precision INTEGER;
1197 x_base_precision INTEGER;
1198 x_result_fld NUMBER;
1199 l_org_id HR_ALL_ORGANIZATION_UNITS.organization_id%type;
1200
1201 --bug 12723347
1202 l_rel_amt_same_curr NUMBER;
1203 l_rel_amt_diff_curr NUMBER;
1204
1205 BEGIN
1206 if (x_object_type in ('H','B') ) then
1207
1208 if x_base_cur_result then
1209 /* Result should be returned in base currency. Get the currency code
1210 of the PO and the base currency code
1211 */
1212 x_progress := 10;
1213 po_core_s2.get_po_currency (x_object_id,
1214 x_base_currency,
1215 x_po_currency );
1216
1217 /* Chk if base_currency = po_currency */
1218 if x_base_currency <> x_po_currency then
1219 /* Get precision and minimum accountable unit of the PO CURRENCY */
1220 x_progress := 20;
1221 po_core_s2.get_currency_info (x_po_currency,
1222 x_precision,
1223 x_min_unit );
1224
1225 /* Get precision and minimum accountable unit of the base CURRENCY */
1226 x_progress := 30;
1227 po_core_s2.get_currency_info (x_base_currency,
1228 x_base_precision,
1229 x_base_min_unit );
1230
1231
1232
1233 if X_base_min_unit is null then
1234
1235 if X_min_unit is null then
1236
1237 x_progress := 40;
1238
1239 /* 958792 kbenjami 8/25/99. Proprogated fix from R11.
1240 849493 - SVAIDYAN: Do a sum(round()) instead of round(sum()) since what
1241 we pass to GL is the round of individual dist. amounts
1242 and the sum of these rounded values is what should be
1243 displayed as the header total.
1244 */
1245 -- <SERVICES FPJ>
1246 -- For the new Services lines, quantity will be null.
1247 -- Hence, added a decode statement to use amount directly
1248 -- in the total amount calculation when quantity is null.
1249 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1250 --<BUG 10196605 Modified below sql to reduce performance issues>
1251 SELECT nvl(sum(round(
1252 round(
1253 (decode(PLL.quantity,
1254 null,
1255 (nvl(PLL.amount, 0) -
1256 nvl(PLL.amount_cancelled, 0)),
1257 ((nvl(PLL.quantity, 0) -
1258 nvl(PLL.quantity_cancelled, 0)) *
1259 nvl(PLL.price_override, 0))
1260 )
1261 * POD.rate
1262 )
1263 , X_precision) ,
1264 X_base_precision)),0)
1265 INTO X_result_fld
1266 FROM PO_DISTRIBUTIONS_ALL POD, PO_LINE_LOCATIONS_ALL PLL
1267 WHERE PLL.po_header_id = X_object_id
1268 AND PLL.shipment_type in ('STANDARD','PLANNED','BLANKET')
1269 AND PLL.line_location_id = POD.line_location_id;
1270
1271 else
1272 x_progress := 42;
1273
1274 -- <SERVICES FPJ>
1275 -- For the new Services lines, quantity will be null.
1276 -- Hence, added a decode statement to use amount directly
1277 -- in the total amount calculation when quantity is null.
1278 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1279 --<BUG 10196605 Modified below sql to reduce performance issues>
1280 SELECT nvl(sum(round(
1281 round(
1282 decode(PLL.quantity,
1283 null,
1284 (nvl(PLL.amount, 0) -
1285 nvl(PLL.amount_cancelled, 0)),
1286 ((nvl(PLL.quantity, 0) -
1290 * POD.rate / X_min_unit
1287 nvl(PLL.quantity_cancelled, 0)) *
1288 nvl(PLL.price_override, 0))
1289 )
1291 )
1292 * X_min_unit , X_base_precision)),0)
1293 INTO X_result_fld
1294 FROM PO_DISTRIBUTIONS_ALL POD, PO_LINE_LOCATIONS_ALL PLL
1295 WHERE PLL.po_header_id = X_object_id
1296 AND PLL.shipment_type in ('STANDARD','PLANNED','BLANKET')
1297 AND PLL.line_location_id = POD.line_location_id;
1298
1299 end if;
1300
1301 else /* base_min_unit is NOT null */
1302
1303 if X_min_unit is null then
1304 x_progress := 44;
1305
1306 -- <SERVICES FPJ>
1307 -- For the new Services lines, quantity will be null.
1308 -- Hence, added a decode statement to use amount directly
1309 -- in the total amount calculation when quantity is null.
1310 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1311 --<BUG 10196605 Modified below sql to reduce performance issues>
1312 SELECT nvl(sum(round( round(
1313 decode(PLL.quantity,
1314 null,
1315 (nvl(PLL.amount, 0) -
1316 nvl(PLL.amount_cancelled, 0)),
1317 (nvl(PLL.quantity, 0) -
1318 nvl(PLL.quantity_cancelled, 0))
1319 * nvl(PLL.price_override, 0)
1320 )
1321 * POD.rate , X_precision)
1322 / X_base_min_unit ) * X_base_min_unit) ,0)
1323 INTO X_result_fld
1324 FROM PO_DISTRIBUTIONS_ALL POD, PO_LINE_LOCATIONS_ALL PLL
1325 WHERE PLL.po_header_id = X_object_id
1326 AND PLL.shipment_type in ('STANDARD','PLANNED','BLANKET')
1327 AND PLL.line_location_id = POD.line_location_id;
1328
1329 else
1330 x_progress := 46;
1331
1332 -- <SERVICES FPJ>
1333 -- For the new Services lines, quantity will be null.
1334 -- Hence, added a decode statement to use amount directly
1335 -- in the total amount calculation when quantity is null.
1336 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1337 --<BUG 10196605 Modified below sql to reduce performance issues>
1338 SELECT nvl(sum(round( round(
1339 decode(PLL.quantity,
1340 null,
1341 (nvl(PLL.amount, 0) -
1342 nvl(PLL.amount_cancelled, 0)),
1343 (nvl(PLL.quantity, 0) -
1344 nvl(PLL.quantity_cancelled, 0))
1345 * nvl(PLL.price_override, 0)
1346 )
1347 * POD.rate /
1348 X_min_unit) * X_min_unit / X_base_min_unit)
1349 * X_base_min_unit) , 0)
1350 INTO X_result_fld
1351 FROM PO_DISTRIBUTIONS_ALL POD, PO_LINE_LOCATIONS_ALL PLL
1352 WHERE PLL.po_header_id = X_object_id
1353 AND PLL.shipment_type in ('STANDARD','PLANNED','BLANKET')
1354 AND PLL.line_location_id = POD.line_location_id;
1355
1356
1357 end if;
1358
1359 end if;
1360
1361 end if; /* x_base_currency <> x_po_currency */
1362
1363 else
1364
1365 /* if we donot want result converted to base currency or if
1366 the currencies are the same then do the check without
1367 rate conversion */
1368
1369 /* 958792 kbenjami 8/25/99. Proprogated fix from R11.
1370 849493 - SVAIDYAN: Do a sum(round()) instead of round(sum()) since what
1371 we pass to GL is the round of individual dist. amounts
1372 and the sum of these rounded values is what should be
1373 displayed as the header total.
1374 */
1375
1376 x_progress := 50;
1377
1378 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1379 SELECT c.minimum_accountable_unit,
1380 c.precision
1381 INTO x_min_unit,
1382 x_precision
1383 FROM FND_CURRENCIES C,
1384 PO_HEADERS_ALL PH
1385 WHERE PH.po_header_id = x_object_id
1386 AND C.currency_code = PH.CURRENCY_CODE;
1387
1388 if x_min_unit is null then
1389 x_progress := 53;
1390
1391 -- <SERVICES FPJ>
1392 -- For the new Services lines, quantity will be null.
1393 -- Hence, added a decode statement to use amount directly
1394 -- in the total amount calculation when quantity is null.
1395 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1396 select sum(round(
1397 decode(pll.quantity,
1398 null,
1399 (pll.amount - nvl(pll.amount_cancelled,0)),
1400 (pll.quantity - nvl(pll.quantity_cancelled,0))
1401 * nvl(pll.price_override,0)
1402 )
1403 ,x_precision))
1404 INTO x_result_fld
1405 FROM PO_LINE_LOCATIONS_ALL PLL
1406 WHERE PLL.po_header_id = x_object_id
1407 AND PLL.shipment_type in ('STANDARD','PLANNED','BLANKET');
1408
1409 else
1410 /* Bug 1111926: GMudgal 2/18/2000
1411 ** Incorrect placement of brackets caused incorrect rounding
1412 ** and consequently incorrect PO header totals
1413 */
1414 x_progress := 56;
1415
1416 -- <SERVICES FPJ>
1420 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1417 -- For the new Services lines, quantity will be null.
1418 -- Hence, added a decode statement to use amount directly
1419 -- in the total amount calculation when quantity is null.
1421 select sum(round(
1422 decode(pll.quantity,
1423 null,
1424 (pll.amount - nvl(pll.amount_cancelled, 0)),
1425 (pll.quantity - nvl(pll.quantity_cancelled, 0))
1426 * nvl(pll.price_override,0)
1427 )
1428 / x_min_unit)
1429 * x_min_unit)
1430 INTO x_result_fld
1431 FROM PO_LINE_LOCATIONS_ALL PLL
1432 WHERE PLL.po_header_id = x_object_id
1433 AND PLL.shipment_type in ('STANDARD','PLANNED','BLANKET');
1434
1435 end if;
1436
1437 end if;
1438
1439 -- <GA FPI START>
1440 --
1441
1442 -- <GC FPJ>
1443 -- Change x_object_type for GA from 'G' to 'GA'
1444
1445 ELSIF ( x_object_type = 'GA' ) THEN -- Global Agreement
1446
1447 x_result_fld := get_ga_amount_released( x_object_id, x_base_cur_result );
1448 --
1449 -- <GA FPI END>
1450
1451 -- <GC FPJ START>
1452 ELSIF (x_object_type = 'GC') THEN -- Global Contract
1453 x_result_fld := get_gc_amount_released
1454 (
1455 p_po_header_id => x_object_id,
1456 p_convert_to_base => x_base_cur_result
1457 );
1458
1459 -- <GC FPJ END>
1460
1461 elsif (x_object_type = 'P') then /* For PO Planned */
1462
1463 if x_base_cur_result then
1464
1465 /* Result should be returned in base currency. Get the currency code
1466 of the PO and the base currency code */
1467
1468 x_progress := 60;
1469 po_core_s2.get_po_currency (x_object_id,
1470 x_base_currency,
1471 x_po_currency );
1472
1473 /* Chk if base_currency = po_currency */
1474 if x_base_currency <> x_po_currency then
1475 /* Get precision and minimum accountable unit of the PO CURRENCY */
1476 x_progress := 70;
1477 po_core_s2.get_currency_info (x_po_currency,
1478 x_precision,
1479 x_min_unit );
1480
1481 /* Get precision and minimum accountable unit of the base CURRENCY */
1482 x_progress := 80;
1483 po_core_s2.get_currency_info (x_base_currency,
1484 x_base_precision,
1485 x_base_min_unit );
1486
1487 /* iali - Bug 482497 - 05/09/97
1488 For Planned PO the PLL.shipment_type should be 'PLANNED' and not
1489 'SCHEDULED' as it was before. Adding both in the where clause by replacing
1490 eqality check with in clause.
1491 */
1492 -- Bugs 482497 and 602664, lpo, 12/22/97
1493 -- Actually, for planned PO, the shipment_type should remain to be 'SCHEDULED'.
1494 -- This will calculate the total released amount. (a shipment type of 'PLANNED'
1495 -- indicates the lines in the planned PO, therefore using IN ('PLANNED',
1496 -- 'SCHEDULED') will calculate the total released amount plus the amount
1497 -- agreed, which is not what we want.
1498 -- Refer to POXBWN3B.pls for fix to bug 482497.
1499
1500 if X_base_min_unit is null then
1501
1502 if X_min_unit is null then
1503
1504 x_progress := 90;
1505
1506 /* 958792 kbenjami 8/25/99. Proprogated fix from R11.
1507 849493 - SVAIDYAN: Do a sum(round()) instead of round(sum()) since what
1508 we pass to GL is the round of individual dist. amounts
1509 and the sum of these rounded values is what should be
1510 displayed as the header total.
1511 */
1512 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1513 SELECT nvl(sum(round( round((nvl(POD.quantity_ordered, 0) -
1514 nvl(POD.quantity_cancelled, 0)) *
1515 nvl(PLL.price_override, 0) * POD.rate, X_precision) ,
1516 X_base_precision)),0)
1517 INTO X_result_fld
1518 FROM PO_DISTRIBUTIONS_ALL POD, PO_LINE_LOCATIONS_ALL PLL
1519 WHERE PLL.po_header_id = X_object_id
1520 -- Bugs 482497 and 602664, lpo, 12/22/97
1521 AND PLL.shipment_type = 'SCHEDULED'
1522 -- End of fix. Bugs 482497 and 602664, lpo, 12/22/97
1523 AND PLL.line_location_id = POD.line_location_id;
1524
1525 else
1526 x_progress := 92;
1527 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1528 SELECT nvl(sum(round( round((nvl(POD.quantity_ordered, 0) -
1529 nvl(POD.quantity_cancelled, 0)) *
1530 nvl(PLL.price_override, 0) * POD.rate /
1531 X_min_unit) * X_min_unit , X_base_precision)),0)
1532 INTO X_result_fld
1533 FROM PO_DISTRIBUTIONS_ALL POD, PO_LINE_LOCATIONS_ALL PLL
1534 WHERE PLL.po_header_id = X_object_id
1535 -- Bugs 482497 and 602664, lpo, 12/22/97
1536 AND PLL.shipment_type = 'SCHEDULED'
1537 -- End of fix. Bugs 482497 and 602664, lpo, 12/22/97
1538 AND PLL.line_location_id = POD.line_location_id;
1539 end if;
1540
1541 else /* base_min_unit is NOT null */
1542
1543 if X_min_unit is null then
1547 nvl(POD.quantity_cancelled, 0)) *
1544 x_progress := 94;
1545 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1546 SELECT nvl(sum(round( round((nvl(POD.quantity_ordered, 0) -
1548 nvl(PLL.price_override, 0) * POD.rate , X_precision)
1549 / X_base_min_unit ) * X_base_min_unit) ,0)
1550 INTO X_result_fld
1551 FROM PO_DISTRIBUTIONS_ALL POD, PO_LINE_LOCATIONS_ALL PLL
1552 WHERE PLL.po_header_id = X_object_id
1553 -- Bugs 482497 and 602664, lpo, 12/22/97
1554 AND PLL.shipment_type = 'SCHEDULED'
1555 -- End of fix. Bugs 482497 and 602664, lpo, 12/22/97
1556 AND PLL.line_location_id = POD.line_location_id;
1557
1558 else
1559 x_progress := 96;
1560 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1561 SELECT nvl(sum(round( round((nvl(POD.quantity_ordered, 0) -
1562 nvl(POD.quantity_cancelled, 0)) *
1563 nvl(PLL.price_override, 0) * POD.rate /
1564 X_min_unit) * X_min_unit / X_base_min_unit)
1565 * X_base_min_unit) , 0)
1566 INTO X_result_fld
1567 FROM PO_DISTRIBUTIONS_ALL POD, PO_LINE_LOCATIONS_ALL PLL
1568 WHERE PLL.po_header_id = X_object_id
1569 -- Bugs 482497 and 602664, lpo, 12/22/97
1570 AND PLL.shipment_type = 'SCHEDULED'
1571 -- End of fix. Bugs 482497 and 602664, lpo, 12/22/97
1572 AND PLL.line_location_id = POD.line_location_id;
1573 end if;
1574
1575 end if;
1576
1577 end if; /* x_base_currency <> x_po_currency */
1578
1579 else
1580
1581 /* if we donot want result converted to base currency or if
1582 the currencies are the same then do the check without
1583 rate conversion */
1584 x_progress := 100;
1585 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1586 SELECT c.minimum_accountable_unit,
1587 c.precision
1588 INTO x_min_unit,
1589 x_precision
1590 FROM FND_CURRENCIES C,
1591 PO_HEADERS_ALL PH
1592 WHERE PH.po_header_id = x_object_id
1593 AND C.currency_code = PH.CURRENCY_CODE;
1594
1595 /* 958792 kbenjami 8/25/99. Proprogated fix from R11.
1596 849493 - SVAIDYAN: Do a sum(round()) instead of round(sum()) since what
1597 we pass to GL is the round of individual dist. amounts
1598 and the sum of these rounded values is what should be
1599 displayed as the header total.
1600 */
1601 if x_min_unit is null then
1602 x_progress := 103;
1603 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1604 select sum(round((pll.quantity - nvl(pll.quantity_cancelled,0))*
1605 nvl(pll.price_override,0),x_precision))
1606 INTO x_result_fld
1607 FROM PO_LINE_LOCATIONS_ALL PLL
1608 WHERE PLL.po_header_id = x_object_id
1609 -- Bugs 482497 and 602664, lpo, 12/22/97
1610 AND PLL.shipment_type = 'SCHEDULED';
1611 -- Bugs 482497 and 602664, lpo, 12/22/97
1612 else
1613 /* Bug 1111926: GMudgal 2/18/2000
1614 ** Incorrect placement of brackets caused incorrect rounding
1615 ** and consequently incorrect PO header totals
1616 */
1617 x_progress := 106;
1618 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1619 select sum(round((pll.quantity -
1620 nvl(pll.quantity_cancelled,0)) *
1621 nvl(pll.price_override,0)/x_min_unit)*
1622 x_min_unit)
1623 INTO x_result_fld
1624 FROM PO_LINE_LOCATIONS_ALL PLL
1625 WHERE PLL.po_header_id = x_object_id
1626 -- Bugs 482497 and 602664, lpo, 12/22/97
1627 AND PLL.shipment_type = 'SCHEDULED';
1628 -- End of fix. Bugs 482497 and 602664, lpo, 12/22/97
1629 end if;
1630
1631 end if;
1632
1633 elsif (x_object_type = 'E' ) then /* Requisition Header */
1634 x_progress := 110;
1635 --bug#5092574 Retrieve the doc org id and pass this to retrieve
1636 --the document currency. Bug 5124868: refactored this call
1637 l_org_id := PO_MOAC_UTILS_PVT.get_entity_org_id(
1638 PO_MOAC_UTILS_PVT.g_doc_type_REQUISITION
1639 , PO_MOAC_UTILS_PVT.g_doc_level_HEADER
1640 , x_object_id);--bug#5092574
1641
1642 po_core_s2.get_req_currency (x_object_id,
1643 x_base_currency,
1644 l_org_id);--bug#5092574
1645
1646 x_progress := 120;
1647 po_core_s2.get_currency_info (x_base_currency,
1648 x_base_precision,
1649 x_base_min_unit );
1650
1651 if x_base_min_unit is null then
1652 x_progress := 130;
1653
1654 /* Bug No. 1431811 Changing the round of sum to sum of rounded totals
1655
1656 round(sum((nvl(quantity,0) * nvl(unit_price,0))), x_base_precision)
1657 */
1658 -- <SERVICES FPJ>
1659 -- For the new Services lines, quantity will be null.
1660 -- Hence, added a decode statement to use amount directly
1661 -- in the total amount calculation when quantity is null.
1662 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1663 -- <Bug 4036549, include cancelled lines with with delivered quantity>
1664
1665 select sum(round(
1666 decode(quantity,
1667 null,
1668 nvl(amount, 0),
1672 )
1669 (
1670 (nvl(quantity,0) - nvl(quantity_cancelled,0))* nvl(unit_price,0)
1671 )
1673 , x_base_precision))
1674 INTO x_result_fld
1675 FROM PO_REQUISITION_LINES_ALL
1676 WHERE requisition_header_id = x_object_id
1677 AND nvl(modified_by_agent_flag, 'N') = 'N';
1678
1679 else
1680 x_progress := 135;
1681
1682 /* Bug No. 1431811 Changing the round of sum to sum of rounded totals
1683 select
1684 round(sum((nvl(quantity,0) * nvl(unit_price,0)/x_base_min_unit)*
1685 x_base_min_unit))
1686 */
1687 -- <SERVICES FPJ>
1688 -- For the new Services lines, quantity will be null.
1689 -- Hence, added a decode statement to use amount directly
1690 -- in the total amount calculation when quantity is null.
1691 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1692 -- <Bug 4036549, include cancelled lines with with delivered quantity>
1693 select sum(round(
1694 decode(quantity,
1695 null,
1696 nvl(amount, 0),
1697 (
1698 (nvl(quantity,0) - nvl(quantity_cancelled,0))* nvl(unit_price,0)
1699 )
1700 )
1701 /x_base_min_unit)*
1702 x_base_min_unit)
1703 INTO x_result_fld
1704 FROM PO_REQUISITION_LINES_ALL
1705 WHERE requisition_header_id = x_object_id
1706 AND nvl(modified_by_agent_flag, 'N') = 'N';
1707
1708 end if;
1709
1710 elsif (x_object_type = 'I' ) then /* Requisition Line */
1711
1712 x_progress := 140;
1713 --bug#5092574 Retrieve the doc org id and pass this to retrieve
1714 --the document currency. Bug 5124868: refactored this call
1715 l_org_id := PO_MOAC_UTILS_PVT.get_entity_org_id(
1716 PO_MOAC_UTILS_PVT.g_doc_type_REQUISITION
1717 , PO_MOAC_UTILS_PVT.g_doc_level_LINE
1718 , x_object_id);--bug#5092574
1719
1720 po_core_s2.get_req_currency (x_object_id,
1721 x_base_currency,
1722 l_org_id);--bug#5092574
1723
1724 x_progress := 150;
1725 po_core_s2.get_currency_info (x_base_currency,
1726 x_base_precision,
1727 x_base_min_unit );
1728
1729 if x_base_min_unit is null then
1730 x_progress := 160;
1731
1732 /* Bug No. 1431811 Changing the round of sum to sum of rounded totals
1733
1734 select
1735 round(sum((nvl(quantity,0) * nvl(unit_price,0))), x_base_precision)
1736 */
1737 -- <SERVICES FPJ>
1738 -- For the new Services lines, quantity will be null.
1739 -- Hence, added a decode statement to use amount directly
1740 -- in the total amount calculation when quantity is null.
1741 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1742 -- <Bug 4036549, include cancelled lines with with delivered quantity>
1743 select sum(round(
1744 decode(quantity,
1745 null,
1746 nvl(amount, 0),
1747 (
1748 (nvl(quantity,0) - nvl(quantity_cancelled,0))* nvl(unit_price,0)
1749 )
1750 )
1751 , x_base_precision))
1752 INTO x_result_fld
1753 FROM PO_REQUISITION_LINES_ALL
1754 WHERE requisition_line_id = x_object_id
1755 AND nvl(modified_by_agent_flag, 'N') = 'N';
1756
1757 else
1758 x_progress := 165;
1759 -- <SERVICES FPJ>
1760 -- For the new Services lines, quantity will be null.
1761 -- Hence, added a decode statement to use amount directly
1762 -- in the total amount calculation when quantity is null.
1763 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1764 -- <Bug 4036549, include cancelled lines with with delivered quantity>
1765 select round(sum((
1766 decode(quantity,
1767 null,
1768 nvl(amount, 0),
1769 (
1770 (nvl(quantity,0) - nvl(quantity_cancelled,0))* nvl(unit_price,0)
1771 )
1772 )
1773 /x_base_min_unit)*
1774 x_base_min_unit))
1775 INTO x_result_fld
1776 FROM PO_REQUISITION_LINES_ALL
1777 WHERE requisition_line_id = x_object_id
1778 AND nvl(modified_by_agent_flag, 'N') = 'N';
1779
1780 end if;
1781 x_progress := 160;
1782
1783 elsif (x_object_type = 'J' ) then /* Requisition Distribution */
1784
1785 x_progress := 162;
1786 --bug#5092574 Retrieve the doc org id and pass this to retrieve
1787 --the document currency. Bug 5124868: refactored this call
1788 l_org_id := PO_MOAC_UTILS_PVT.get_entity_org_id(
1789 PO_MOAC_UTILS_PVT.g_doc_type_REQUISITION
1790 , PO_MOAC_UTILS_PVT.g_doc_level_DISTRIBUTION
1791 , x_object_id);--bug#5092574
1792
1793 po_core_s2.get_req_currency (x_object_id,
1794 x_base_currency,
1795 l_org_id);--bug#5092574
1796 x_progress := 164;
1797 po_core_s2.get_currency_info (x_base_currency,
1798 x_base_precision,
1799 x_base_min_unit );
1800
1801 x_progress := 166;
1802
1803 -- <SERVICES FPJ>
1804 -- Modified the SELECT statement to take account into Services
1808 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1805 -- lines. For the new Services lines, quantity will be null.
1806 -- Hence, added decode statements to use amount directly
1807 -- in the total amount calculation when quantity is null.
1809 /* Fp of bug 12584086 : Added condition to not calculate amount for distribution for
1810 which line is modified or not valid. */
1811 SELECT
1812 sum( decode
1813 ( x_base_min_unit, NULL,
1814 decode(quantity, NULL,
1815 round( nvl(PORD.req_line_amount, 0),
1816 x_base_precision),
1817 round( nvl(PORD.req_line_quantity, 0) *
1818 nvl(PORL.unit_price, 0),
1819 x_base_precision)
1820 ),
1821 decode(quantity, NULL,
1822 round((nvl(PORD.req_line_amount, 0) /
1823 x_base_min_unit) *
1824 x_base_min_unit),
1825 round((nvl(PORD.req_line_quantity, 0) *
1826 nvl(PORL.unit_price, 0) /
1827 x_base_min_unit) *
1828 x_base_min_unit)
1829 )))
1830 INTO x_result_fld
1831 FROM PO_REQ_DISTRIBUTIONS_ALL PORD,
1832 PO_REQUISITION_LINES_ALL PORL
1833 WHERE PORD.distribution_id = x_object_id
1834 AND PORD.requisition_line_id = PORL.requisition_line_id
1835 AND nvl(PORL.modified_by_agent_flag, 'N') = 'N'; -- Fp of bug 12584086;
1836
1837 elsif (x_object_type = 'C' ) then /* Contract */
1838
1839 x_progress := 170;
1840 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1841 SELECT c.minimum_accountable_unit,
1842 c.precision
1843 INTO x_min_unit,
1844 x_precision
1845 FROM FND_CURRENCIES C,
1846 PO_HEADERS_ALL PH
1847 WHERE PH.po_header_id = x_object_id
1848 AND C.currency_code = PH.CURRENCY_CODE;
1849
1850 /* 716188 - SVAIDYAN : Changed the sql stmt to select only Standard and Planned
1851 POs that reference this contract and also to convert the amount into the
1852 Contract's currency. This is achieved by converting the PO amt first to the
1853 functional currency and then changing this to the Contract currency */
1854
1855 /* 716188 - Added an outer join on PO_DISTRIBUTIONS */
1856 /* 866358 - BPESCHAN: Changed the sql stmt to select quantity_ordered and
1857 quantity_cancelled from PO_DISTRIBUTIONS instead of PO_LINE_LOCATIONS.
1858 This fix prevents incorrect calculation for amount release when more then
1859 one distribution exists. */
1860
1861 /* 958792 kbenjami 8/25/99. Proprogated fix from R11.
1862 849493 - SVAIDYAN: Do a sum(round()) instead of round(sum()) since what
1863 we pass to GL is the round of individual dist. amounts
1864 and the sum of these rounded values is what should be
1865 displayed as the header total.
1866 */
1867 /*Bug3760487:Purchase Order form was displaying incorrect released
1868 amount for foreign currency contract when the PO currency is same
1869 as the contract currency and the rates were different.Added the decode
1870 to perform the currency conversion only when the currency code of
1871 PO and contract are different.
1872 Also removed the join to FND_CURRENCIES
1873 */
1874
1875 /*Bug 12723347
1876 1)For execution documents with same currency as the Contract, get
1877 quantity/amount from po_line_locations_all;
1878 2)For execution documents with different currency as the Contract, get
1879 quantity/amount from po_distributions_all;
1880
1881 Assume most execution documents have same currency as the contract, so the
1882 performance impact as described in bug 7518629 by reverting back to POD
1883 (second case) will be limited.*/
1884
1885
1886 if x_min_unit is null then
1887 x_progress := 172;
1888 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1889 --<Bug 10196605 Modifed the following sql to increase the performance
1890 -- when the contract PO is queried through the PO summary form.
1891 /* SELECT nvl ( sum (decode ( PH.currency_code, PH1.currency_code,
1892 round (
1893 decode ( PLL.quantity,
1894 null,
1895 ( nvl ( PLL.amount,0) -
1896 nvl(PLL.amount_cancelled, 0) ),
1897 ( nvl ( PLL.quantity,0) -
1898 nvl ( PLL.quantity_cancelled,0 ) )
1899 * nvl(pll.price_override,0) ) ,x_precision ),
1900 round (
1901 decode ( PLL.quantity,
1902 null,
1903 ( nvl ( PLL.amount, 0) -
1904 nvl ( PLL.amount_cancelled, 0 ) ),
1905 ( nvl ( PLL.quantity,0) -
1906 nvl ( PLL.quantity_cancelled,0 ) )
1907 * nvl(pll.price_override,0) ) * nvl(POD.rate,nvl(PH1.rate,1)) / nvl (PH.rate,1),x_precision)
1908 ) ) , 0 )
1909 INTO x_result_fld
1910 FROM PO_LINE_LOCATIONS_ALL PLL,
1911 PO_DISTRIBUTIONS_ALL POD,
1912 PO_LINES_ALL PL,
1913 PO_HEADERS_ALL PH,
1914 PO_HEADERS_ALL PH1
1915 WHERE PH.po_header_id = x_object_id
1916 AND PH.po_header_id = PL.contract_id
1917 AND PL.po_line_id = PLL.po_line_id
1918 AND PLL.shipment_type IN ('STANDARD','PLANNED')
1919 AND POD.line_location_id(+) = PLL.line_location_id
1920 AND PH1.po_header_id = PL.po_header_id;*/
1921
1925 ( nvl ( PLL.quantity,0) - nvl ( PLL.quantity_cancelled,0 ) )
1922 --Get release amount for documents with same currency
1923 SELECT nvl ( sum (round (decode ( PLL.quantity,null,
1924 ( nvl ( PLL.amount,0) -nvl(PLL.amount_cancelled, 0) ),
1926 * nvl(pll.price_override,0) ) , x_precision)), 0)
1927 INTO l_rel_amt_same_curr
1928 FROM PO_LINE_LOCATIONS_ALL PLL,
1929 PO_LINES_ALL PL,
1930 PO_HEADERS_ALL PH,
1931 PO_HEADERS_ALL PH1
1932 WHERE PH.po_header_id = x_object_id
1933 AND PH.po_header_id = PL.contract_id
1934 AND PL.po_line_id = PLL.po_line_id
1935 AND PLL.shipment_type IN ('STANDARD','PLANNED')
1936 AND PH1.po_header_id = PL.po_header_id
1937 and PH.currency_code = PH1.currency_code;
1938
1939 --Get release amount for documents with different currency
1940 SELECT nvl (sum(round(decode(POD.quantity_ordered, null,
1941 (nvl(POD.amount_ordered, 0) - nvl(POD.amount_cancelled, 0)),
1942 (nvl(POD.quantity_ordered,0) - nvl(POD.quantity_cancelled,0))
1943 * nvl(pll.price_override,0) * nvl(POD.rate, nvl(PH1.rate,1))
1944 /nvl(PH.rate,1)), x_precision)
1945 ),0)
1946 INTO l_rel_amt_diff_curr
1947 FROM PO_LINE_LOCATIONS_ALL PLL,
1948 PO_DISTRIBUTIONS_ALL POD,
1949 PO_LINES_ALL PL,
1950 PO_HEADERS_ALL PH,
1951 PO_HEADERS_ALL PH1
1952 WHERE PH.po_header_id = x_object_id
1953 AND PH.po_header_id = PL.contract_id
1954 AND PL.po_line_id = PLL.po_line_id
1955 AND PLL.shipment_type IN ('STANDARD','PLANNED')
1956 AND POD.line_location_id(+) = PLL.line_location_id
1957 AND PH1.po_header_id = PL.po_header_id
1958 and PH.currency_code <> PH1.currency_code;
1959
1960 x_result_fld := l_rel_amt_same_curr + l_rel_amt_diff_curr;
1961
1962 else
1963
1964 /* 958792 kbenjami 8/25/99. Proprogated fix from R11.
1965 849493 - SVAIDYAN: Do a sum(round()) instead of round(sum()) since what
1966 we pass to GL is the round of individual dist. amounts
1967 and the sum of these rounded values is what should be
1968 displayed as the header total.
1969 */
1970 x_progress := 174;
1971 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
1972 --<Bug 10196605 Modifed the following sql to increase the performance
1973 -- when the contract PO is queried through the PO summary form.
1974 /* SELECT
1975 nvl(sum(decode(PH.currency_code, PH1.currency_code,
1976 round(
1977 decode(PLL.quantity, --Bug# 5238463
1978 null,
1979 (nvl(PLL.amount, 0) -
1980 nvl(PLL.amount_cancelled, 0)),
1981 ((nvl(PLL.quantity,0) -
1982 nvl(PLL.quantity_cancelled,0))
1983 * nvl(pll.price_override,0)))/x_min_unit),
1984 round(
1985 decode(PLL.quantity,
1986 null,
1987 (nvl(PLL.amount, 0) -
1988 nvl(PLL.amount_cancelled, 0)),
1989 ((nvl(PLL.quantity,0) -
1990 nvl(PLL.quantity_cancelled,0))
1991 * nvl(pll.price_override,0)))
1992 * nvl(POD.rate, nvl(PH1.rate,1))/nvl(PH.rate,1)/x_min_unit))
1993 * x_min_unit),0)
1994 INTO x_result_fld
1995 FROM PO_DISTRIBUTIONS_ALL POD,
1996 PO_LINE_LOCATIONS_ALL PLL,
1997 PO_LINES_ALL PL,
1998 PO_HEADERS_ALL PH,
1999 PO_HEADERS_ALL PH1
2000 --,FND_CURRENCIES C
2001 WHERE PH.po_header_id = x_object_id
2002 AND PH.po_header_id = PL.contract_id -- <GC FPJ>
2003 --AND PH.currency_code = C.currency_code
2004 AND PL.po_line_id = PLL.po_line_id
2005 AND PLL.shipment_type in ('STANDARD','PLANNED')
2006 AND POD.line_location_id(+) = PLL.line_location_id
2007 AND PH1.po_header_id = PL.po_header_id;*/
2008
2009 --Get release amount for documents with same currency
2010 SELECT nvl ( sum (round (decode ( PLL.quantity,null,
2011 ( nvl ( PLL.amount,0) -nvl(PLL.amount_cancelled, 0) ),
2012 ( nvl ( PLL.quantity,0) - nvl ( PLL.quantity_cancelled,0 ) )
2013 * nvl(pll.price_override,0) )/x_min_unit) * x_min_unit), 0)
2014 INTO l_rel_amt_same_curr
2015 FROM PO_LINE_LOCATIONS_ALL PLL,
2016 PO_LINES_ALL PL,
2017 PO_HEADERS_ALL PH,
2018 PO_HEADERS_ALL PH1
2019 WHERE PH.po_header_id = x_object_id
2020 AND PH.po_header_id = PL.contract_id
2021 AND PL.po_line_id = PLL.po_line_id
2022 AND PLL.shipment_type IN ('STANDARD','PLANNED')
2023 AND PH1.po_header_id = PL.po_header_id
2024 and PH.currency_code = PH1.currency_code;
2025
2026 --Get release amount for documents with different currency
2027 SELECT nvl (sum(round(decode(POD.quantity_ordered, null,
2028 (nvl(POD.amount_ordered, 0) - nvl(POD.amount_cancelled, 0)),
2029 (nvl(POD.quantity_ordered,0) - nvl(POD.quantity_cancelled,0))
2030 * nvl(pll.price_override,0) * nvl(POD.rate, nvl(PH1.rate,1))
2031 /nvl(PH.rate,1))/x_min_unit)
2035 PO_DISTRIBUTIONS_ALL POD,
2032 * x_min_unit),0)
2033 INTO l_rel_amt_diff_curr
2034 FROM PO_LINE_LOCATIONS_ALL PLL,
2036 PO_LINES_ALL PL,
2037 PO_HEADERS_ALL PH,
2038 PO_HEADERS_ALL PH1
2039 WHERE PH.po_header_id = x_object_id
2040 AND PH.po_header_id = PL.contract_id
2041 AND PL.po_line_id = PLL.po_line_id
2042 AND PLL.shipment_type IN ('STANDARD','PLANNED')
2043 AND POD.line_location_id(+) = PLL.line_location_id
2044 AND PH1.po_header_id = PL.po_header_id
2045 and PH.currency_code <> PH1.currency_code;
2046
2047 x_result_fld := l_rel_amt_same_curr + l_rel_amt_diff_curr;
2048
2049 end if;
2050
2051
2052 elsif (x_object_type = 'R' ) then /* Release */
2053
2054 if x_base_cur_result then
2055 x_progress := 180;
2056 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
2057 SELECT GSB.currency_code,
2058 POH.currency_code
2059 INTO x_base_currency,
2060 x_po_currency
2061 FROM PO_HEADERS_ALL POH,
2062 FINANCIALS_SYSTEM_PARAMS_ALL FSP,
2063 GL_SETS_OF_BOOKS GSB,
2064 PO_RELEASES_ALL POR
2065 WHERE POR.po_release_id = x_object_id
2066 AND POH.po_header_id = POR.po_header_id
2067 AND NVL(POR.org_id,-99) = NVL(FSP.org_id,-99) --< Bug 3549096 >
2068 AND FSP.set_of_books_id = GSB.set_of_books_id;
2069
2070 if (x_base_currency <> x_po_currency) then
2071 /* Get precision and minimum accountable unit of the PO CURRENCY */
2072 x_progress := 190;
2073 po_core_s2.get_currency_info (x_po_currency,
2074 x_precision,
2075 x_min_unit );
2076
2077 /* Get precision and minimum accountable unit of the base CURRENCY */
2078 x_progress := 200;
2079 po_core_s2.get_currency_info (x_base_currency,
2080 x_base_precision,
2081 x_base_min_unit );
2082
2083 if x_base_min_unit is null then
2084 if x_min_unit is null then
2085 x_progress := 210;
2086
2087 /* 958792 kbenjami 8/25/99. Proprogated fix from R11.
2088 849493 - SVAIDYAN: Do a sum(round()) instead of round(sum()) since what
2089 we pass to GL is the round of individual dist. amounts
2090 and the sum of these rounded values is what should be
2091 displayed as the header total.
2092 */
2093 -- <SERVICES FPJ>
2094 -- For the new Services lines, quantity will be null.
2095 -- Hence, added a decode statement to use amount directly
2096 -- in the total amount calculation when quantity is null.
2097 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
2098 select nvl(sum(round(round(
2099 decode(POD.quantity_ordered,
2100 null,
2101 nvl(POD.amount_ordered, 0),
2102 (nvl(POD.quantity_ordered,0) *
2103 nvl(PLL.price_override,0))
2104 )
2105 * POD.rate
2106 ,x_precision),x_base_precision)),0)
2107 INTO x_result_fld
2108 FROM PO_DISTRIBUTIONS_ALL POD, PO_LINE_LOCATIONS_ALL PLL
2109 WHERE PLL.po_release_id = x_object_id
2110 AND PLL.line_location_id = POD.line_location_id
2111 AND PLL.shipment_type in ('SCHEDULED','BLANKET');
2112
2113 else
2114 x_progress := 212;
2115 -- <SERVICES FPJ>
2116 -- For the new Services lines, quantity will be null.
2117 -- Hence, added a decode statement to use amount directly
2118 -- in the total amount calculation when quantity is null.
2119 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
2120 SELECT nvl(sum(round( round(
2121 decode(POD.quantity_ordered,
2122 null,
2123 nvl(POD.amount_ordered, 0),
2124 (nvl(POD.quantity_ordered, 0) *
2125 nvl(PLL.price_override, 0))
2126 )
2127 * POD.rate /
2128 X_min_unit) * X_min_unit , X_base_precision)),0)
2129 INTO x_result_fld
2130 FROM PO_DISTRIBUTIONS_ALL POD, PO_LINE_LOCATIONS_ALL PLL
2131 WHERE PLL.po_release_id = x_object_id
2132 AND PLL.line_location_id = POD.line_location_id
2133 AND PLL.shipment_type in ('SCHEDULED','BLANKET');
2134
2135 end if;
2136 else
2137 if X_min_unit is null then
2138 x_progress := 214;
2139 -- <SERVICES FPJ>
2140 -- For the new Services lines, quantity will be null.
2141 -- Hence, added a decode statement to use amount directly
2142 -- in the total amount calculation when quantity is null.
2143 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
2144 SELECT nvl(sum(round( round(
2145 decode(POD.quantity_ordered,
2146 null,
2147 nvl(POD.amount_ordered, 0),
2148 (nvl(POD.quantity_ordered, 0) *
2149 nvl(PLL.price_override, 0))
2150 )
2151 * POD.rate
2152 , X_precision)
2153 / X_base_min_unit ) * X_base_min_unit) ,0)
2154 INTO X_result_fld
2158 AND PLL.shipment_type in ('SCHEDULED','BLANKET');
2155 FROM PO_DISTRIBUTIONS_ALL POD, PO_LINE_LOCATIONS_ALL PLL
2156 WHERE PLL.po_release_id = x_object_id
2157 AND PLL.line_location_id = POD.line_location_id
2159
2160 else
2161 x_progress := 216;
2162 -- <SERVICES FPJ>
2163 -- For the new Services lines, quantity will be null.
2164 -- Hence, added a decode statement to use amount directly
2165 -- in the total amount calculation when quantity is null.
2166 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
2167 SELECT nvl(sum(round( round(
2168 decode(POD.quantity_ordered,
2169 null,
2170 nvl(POD.amount_ordered, 0),
2171 (nvl(POD.quantity_ordered, 0) *
2172 nvl(PLL.price_override, 0))
2173 )
2174 * POD.rate /
2175 X_min_unit) * X_min_unit / X_base_min_unit)
2176 * X_base_min_unit) , 0)
2177 INTO X_result_fld
2178 FROM PO_DISTRIBUTIONS_ALL POD, PO_LINE_LOCATIONS_ALL PLL
2179 WHERE PLL.po_release_id = x_object_id
2180 AND PLL.line_location_id = POD.line_location_id
2181 AND PLL.shipment_type in ('SCHEDULED','BLANKET');
2182
2183 end if;
2184 end if;
2185
2186 end if;
2187 else
2188 x_progress := 220;
2189 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
2190 SELECT c.minimum_accountable_unit,
2191 c.precision
2192 INTO x_min_unit,
2193 x_precision
2194 FROM FND_CURRENCIES C,
2195 PO_RELEASES_ALL POR,
2196 PO_HEADERS_ALL PH
2197 WHERE POR.po_release_id = x_object_id
2198 AND PH.po_header_id = POR.PO_HEADER_ID
2199 AND C.currency_code = PH.CURRENCY_CODE;
2200
2201 if x_min_unit is null then
2202
2203 /* 958792 kbenjami 8/25/99. Proprogated fix from R11.
2204 849493 - SVAIDYAN: Do a sum(round()) instead of round(sum()) since what
2205 we pass to GL is the round of individual dist. amounts
2206 and the sum of these rounded values is what should be
2207 displayed as the header total.
2208 */
2209 x_progress := 222;
2210 -- <SERVICES FPJ>
2211 -- For the new Services lines, quantity will be null.
2212 -- Hence, added a decode statement to use amount directly
2213 -- in the total amount calculation when quantity is null.
2214 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
2215 select sum(round(
2216 decode(pll.quantity,
2217 null,
2218 (pll.amount - nvl(pll.amount_cancelled,0)),
2219 ((pll.quantity - nvl(pll.quantity_cancelled,0)) *
2220 nvl(pll.price_override,0))
2221 )
2222 ,x_precision))
2223 INTO x_result_fld
2224 FROM PO_LINE_LOCATIONS_ALL PLL
2225 WHERE PLL.po_release_id = x_object_id
2226 AND PLL.shipment_type in ( 'SCHEDULED','BLANKET');
2227
2228 else
2229 /* Bug 1111926: GMudgal 2/18/2000
2230 ** Incorrect placement of brackets caused incorrect rounding
2231 ** and consequently incorrect PO header totals
2232 */
2233 x_progress := 224;
2234
2235 -- <SERVICES FPJ>
2236 -- For the new Services lines, quantity will be null.
2237 -- Hence, added a decode statement to use amount directly
2238 -- in the total amount calculation when quantity is null.
2239 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
2240 select sum(round(
2241 decode(pll.quantity,
2242 null,
2243 (pll.amount - nvl(pll.amount_cancelled,0)),
2244 ((pll.quantity - nvl(pll.quantity_cancelled,0)) *
2245 nvl(pll.price_override,0))
2246 )
2247 /x_min_unit) *
2248 x_min_unit)
2249 INTO x_result_fld
2250 FROM PO_LINE_LOCATIONS_ALL PLL
2251 WHERE PLL.po_release_id = x_object_id
2252 AND PLL.shipment_type in ( 'SCHEDULED','BLANKET');
2253
2254 end if;
2255
2256 end if;
2257
2258 elsif (x_object_type = 'L' ) then /* Po Line */
2259 x_progress := 230;
2260 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
2261 SELECT sum(c.minimum_accountable_unit),
2262 sum(c.precision)
2263 INTO x_min_unit,
2264 x_precision
2265 FROM FND_CURRENCIES C,
2266 PO_HEADERS_ALL PH,
2267 PO_LINES_ALL POL
2268 WHERE POL.po_line_id = x_object_id
2269 AND PH.po_header_id = POL.po_header_id
2270 AND C.currency_code = PH.CURRENCY_CODE;
2271
2272 if x_min_unit is null then
2273 x_progress := 232;
2274
2275 /* Bug No. 1431811 Changing the round of sum to sum of rounded totals
2276 select round(sum((pll.quantity - nvl(pll.quantity_cancelled,0))*
2277 nvl(pll.price_override,0)),x_precision)
2278 */
2279 /* Bug No. 1849112 In the previous fix of 143811 by mistake x_precision
2280 was not used.
2281 */
2282 -- <SERVICES FPJ>
2283 -- For the new Services lines, quantity will be null.
2284 -- Hence, added a decode statement to use amount directly
2285 -- in the total amount calculation when quantity is null.
2289 null,
2286 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
2287 select sum(round((
2288 decode(pll.quantity,
2290 (pll.amount - nvl(pll.amount_cancelled, 0)),
2291 (pll.quantity - nvl(pll.quantity_cancelled,0))
2292 * nvl(pll.price_override,0)
2293 )
2294 ),x_precision))
2295 INTO x_result_fld
2296 FROM PO_LINE_LOCATIONS_ALL PLL
2297 WHERE PLL.po_line_id = x_object_id
2298 AND PLL.shipment_type in ( 'STANDARD','BLANKET','PLANNED');
2299
2300 else
2301 x_progress := 234;
2302
2303 /* Bug No. 1431811 Changing the round of sum to sum of rounded totals
2304 */
2305 -- <SERVICES FPJ>
2306 -- For the new Services lines, quantity will be null.
2307 -- Hence, added a decode statement to use amount directly
2308 -- in the total amount calculation when quantity is null.
2309 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
2310 select sum(round((
2311 decode(pll.quantity,
2312 null,
2313 (pll.amount - nvl(pll.amount_cancelled,0)),
2314 (pll.quantity - nvl(pll.quantity_cancelled,0))
2315 * nvl(pll.price_override,0)
2316 )
2317 / x_min_unit) * x_min_unit))
2318 INTO x_result_fld
2319 FROM PO_LINE_LOCATIONS_ALL PLL
2320 WHERE PLL.po_line_id = x_object_id
2321 AND PLL.shipment_type in ( 'STANDARD','BLANKET','PLANNED');
2322
2323 end if;
2324
2325 elsif (x_object_type = 'S' ) then /* PO Shipment */
2326 x_progress := 240;
2327 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
2328 SELECT c.minimum_accountable_unit,
2329 c.precision
2330 INTO x_min_unit,
2331 x_precision
2332 FROM FND_CURRENCIES C,
2333 PO_HEADERS_ALL PH,
2334 PO_LINE_LOCATIONS_ALL PLL
2335 WHERE PLL.line_location_id = x_object_id
2336 AND PH.po_header_id = PLL.po_header_id
2337 AND C.currency_code = PH.CURRENCY_CODE;
2338
2339 if x_min_unit is null then
2340 x_progress := 242;
2341
2342 /* Bug No. 1431811 Changing the round of sum to sum of rounded totals
2343 select round(sum((pll.quantity - nvl(pll.quantity_cancelled,0))*
2344 nvl(pll.price_override,0)),x_precision)
2345 */
2346 -- <SERVICES FPJ>
2347 -- For the new Services lines, quantity will be null.
2348 -- Hence, added a decode statement to use amount directly
2349 -- in the total amount calculation when quantity is null.
2350 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
2351 select sum(round((
2352 decode(pll.quantity,
2353 null,
2354 (pll.amount - nvl(pll.amount_cancelled,0)),
2355 (pll.quantity - nvl(pll.quantity_cancelled,0))
2356 * nvl(pll.price_override,0)
2357 )
2358 ),x_precision))
2359 INTO x_result_fld
2360 FROM PO_LINE_LOCATIONS_ALL PLL
2361 WHERE PLL.line_location_id = x_object_id;
2362
2363 else
2364 x_progress := 244;
2365 -- <SERVICES FPJ>
2366 -- For the new Services lines, quantity will be null.
2367 -- Hence, added a decode statement to use amount directly
2368 -- in the total amount calculation when quantity is null.
2369 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
2370 select round(sum((
2371 decode(pll.quantity,
2372 null,
2373 (pll.amount - nvl(pll.amount_cancelled,0)),
2374 (pll.quantity - nvl(pll.quantity_cancelled,0))
2375 * nvl(pll.price_override,0)
2376 )
2377 /x_min_unit) * x_min_unit))
2378 INTO x_result_fld
2379 FROM PO_LINE_LOCATIONS_ALL PLL
2380 WHERE PLL.line_location_id = x_object_id;
2381
2382 end if;
2383
2384 end if; /* x_object_type */
2385
2386 /* If x_result_fld has a null value, return 0 as the total. */
2387 IF x_result_fld IS NULL THEN
2388 x_result_fld := 0;
2389 END IF;
2390
2391 RETURN(x_result_fld);
2392
2393 EXCEPTION
2394 WHEN OTHERS THEN
2395 RETURN(0);
2396 RAISE;
2397
2398 END get_total;
2399
2400 --<CONTERMS FPJ START>
2401 -------------------------------------------------------------------------------
2402 --Start of Comments
2403 --Name: GET_ARCHIVE_TOTAL
2404 --Pre-reqs:
2405 -- None
2406 --Modifies:
2407 -- None.
2408 --Locks:
2409 -- None.
2410 --Function:
2411 -- Returns total amount for latest archived revision for Standard Purchase order
2412 --Parameters:
2413 --IN:
2414 -- p_object_id
2415 -- PO header id
2416 -- p_doc_type
2417 -- The main doc type for PO. Valid values are 'PO'
2418 -- p_doc_subtype
2419 -- The lookup code of the document. Valid values are 'STANDARD'
2420 -- p_base_cur_result
2421 -- Whether result should be returned in base currency or transaction currency
2422 -- Valid Values are
2423 -- 'Y'- Return result in Base/Functional Currency for the org
2424 -- 'N'- Return result in Transaction currency in po
2425 -- Default 'N'
2426 --Testing:
2427 -- None
2428 --End of Comments
2429 ---------------------------------------------------------------------------
2430 FUNCTION get_archive_total (p_object_id IN NUMBER,
2434
2431 p_doc_type IN VARCHAR2,
2432 p_doc_subtype IN VARCHAR2,
2433 p_base_cur_result IN VARCHAR2) RETURN NUMBER IS
2435 l_base_currency PO_HEADERS_ALL.CURRENCY_CODE%TYPE;
2436 l_po_currency PO_HEADERS_ALL.CURRENCY_CODE%TYPE;
2437 l_min_unit FND_CURRENCIES.MINIMUM_ACCOUNTABLE_UNIT%TYPE;
2438 l_base_min_unit FND_CURRENCIES.MINIMUM_ACCOUNTABLE_UNIT%TYPE;
2439 l_precision FND_CURRENCIES.PRECISION%TYPE;
2440 l_base_precision FND_CURRENCIES.PRECISION%TYPE;
2441 l_archive_total_amt NUMBER;
2442 l_progress VARCHAR2(3):='000';
2443 BEGIN
2444 l_progress := '010';
2445 IF (p_doc_type = 'PO') AND (p_doc_subtype = 'STANDARD') then
2446
2447 --Get the currency code of the PO and the base currency code
2448
2449 po_core_s2.get_po_currency (x_object_id=>p_object_id,
2450 x_base_currency =>l_base_currency,
2451 x_po_currency =>l_po_currency );
2452 l_progress := '020';
2453 --Get precision and minimum accountable unit of the PO CURRENCY
2454 po_core_s2.get_currency_info (x_currency_code => l_po_currency,
2455 x_precision=>l_precision,
2456 x_min_unit=>l_min_unit );
2457 l_progress := '030';
2458 -- Chk if base_currency = po_currency
2459 IF (p_base_cur_result = 'Y') AND (l_base_currency <> l_po_currency) then
2460
2461 l_progress := '040';
2462 --Get precision and minimum accountable unit of the base CURRENCY
2463
2464 po_core_s2.get_currency_info (x_currency_code => l_base_currency,
2465 x_precision=>l_base_precision,
2466 x_min_unit=>l_base_min_unit );
2467
2468
2469 ELSE -- if l_base_currency <> l_po_currency
2470 l_base_precision := l_precision;
2471 l_base_min_unit := l_min_unit;
2472 END IF; -- if l_base_currency <> l_po_currency
2473 l_progress := '050';
2474 --SQL WHAT- This query returns the total amount for an archived SPO
2475 --SQL WHY- To check if archived amount different from working copy amt. for a po in contract terms
2476 --SQL JOIN- Location id in PO_LINE_LOCATIONS_ARCHIVE_ALL and PO_DISTRIBUTIONS_ARCHIVE_ALL
2477 SELECT nvl(sum(round( ( (round( ( ( decode(POD.quantity_ordered, NULL,
2478 (nvl(POD.amount_ordered,0) -
2479 nvl(POD.amount_cancelled,0)
2480 ),
2481 ( (nvl(POD.quantity_ordered,0) -
2482 nvl(POD.quantity_cancelled,0)
2483 )*
2484 nvl(PLL.price_override, 0)
2485 )
2486 ) *
2487 decode(p_base_cur_result,'Y',nvl(POD.rate,1),1)
2488 )/
2489 nvl(l_min_unit,1)
2490 ),decode(l_min_unit,null,l_precision,0)
2491 )*
2492 nvl(l_min_unit,1)
2493 )/
2494 nvl(l_base_min_unit,1)
2495 )
2496 ,decode(l_base_min_unit,null,l_base_precision,0)
2497 )*
2498 nvl(l_base_min_unit,1)
2499 ), 0
2500 )
2501 INTO l_archive_total_amt
2502 FROM PO_DISTRIBUTIONS_ARCHIVE_ALL POD, PO_LINE_LOCATIONS_ARCHIVE_ALL PLL
2503 WHERE PLL.po_header_id = p_object_id
2504 AND PLL.shipment_type in ('STANDARD')
2505 AND PLL.line_location_id = POD.line_location_id
2506 AND PLL.LATEST_EXTERNAL_FLAG = 'Y'
2507 AND POD.LATEST_EXTERNAL_FLAG = 'Y';
2508
2509 l_progress := '060';
2510 END if;-- (p_doc_type = 'PO') AND (p_doc_subtype = 'STANDARD')
2511 l_progress := '070';
2512 --If l_archive_total_amt has a null value, return 0 as the total.
2513 IF l_archive_total_amt IS NULL THEN
2514 l_archive_total_amt := 0;
2515 END IF;
2516 l_progress := '080';
2517 RETURN(l_archive_total_amt);
2518
2519 EXCEPTION
2520 WHEN OTHERS THEN
2524 SUBSTRB (SQLERRM , 1 , 200) || ' at location ' || l_progress);
2521 IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error)
2522 THEN
2523 fnd_msg_pub.add_exc_msg (g_pkg_name, 'GET_ARCHIVE_TOTAL',
2525 END IF;
2526 RETURN(0);
2527 END get_archive_total;
2528 --<CONTERMS FPJ END>
2529
2530
2531
2532 --<POC FPJ START>
2533
2534
2535 FUNCTION get_archive_total_for_any_rev (p_object_id IN NUMBER,
2536 p_object_type in varchar2,
2537 p_doc_type IN VARCHAR2,
2538 p_doc_subtype IN VARCHAR2,
2539 p_doc_revision IN NUMBER,
2540 p_base_cur_result IN VARCHAR2) RETURN NUMBER IS
2541
2542 l_base_currency PO_HEADERS_ALL.CURRENCY_CODE%TYPE;
2543 l_po_currency PO_HEADERS_ALL.CURRENCY_CODE%TYPE;
2544 l_min_unit FND_CURRENCIES.MINIMUM_ACCOUNTABLE_UNIT%TYPE;
2545 l_base_min_unit FND_CURRENCIES.MINIMUM_ACCOUNTABLE_UNIT%TYPE;
2546 l_precision FND_CURRENCIES.PRECISION%TYPE;
2547 l_base_precision FND_CURRENCIES.PRECISION%TYPE;
2548 l_archive_total_amt NUMBER;
2549 l_progress VARCHAR2(3):='000';
2550
2551 BEGIN
2552 l_progress := '010';
2553 IF (p_doc_type = 'PO') AND (p_doc_subtype = 'STANDARD') then
2554
2555 IF p_object_type = 'H' then
2556
2557 --Get the currency code of the PO and the base currency code
2558
2559 po_core_s2.get_po_currency (x_object_id=>p_object_id,
2560 x_base_currency =>l_base_currency,
2561 x_po_currency =>l_po_currency );
2562 l_progress := '020';
2563 --Get precision and minimum accountable unit of the PO CURRENCY
2564 po_core_s2.get_currency_info (x_currency_code => l_po_currency,
2565 x_precision=>l_precision,
2566 x_min_unit=>l_min_unit );
2567 l_progress := '030';
2568 -- Chk if base_currency = po_currency
2569 IF (p_base_cur_result = 'Y') AND (l_base_currency <> l_po_currency) then
2570
2571 l_progress := '040';
2572 --Get precision and minimum accountable unit of the base CURRENCY
2573
2574 po_core_s2.get_currency_info (x_currency_code => l_base_currency,
2575 x_precision=>l_base_precision,
2576 x_min_unit=>l_base_min_unit );
2577
2578
2579 ELSE -- if l_base_currency <> l_po_currency
2580 l_base_precision := l_precision;
2581 l_base_min_unit := l_min_unit;
2582 END IF; -- if l_base_currency <> l_po_currency
2583 l_progress := '050';
2584 --SQL WHAT- This query returns the total amount for an archived SPO
2585 --SQL WHY- To derive the total amount for an archived PO revision
2586 --SQL JOIN- Location id in PO_LINE_LOCATIONS_ARCHIVE_ALL and PO_DISTRIBUTIONS_ARCHIVE_ALL
2587 SELECT nvl(sum(round( ( (round( ( ( decode(POD.quantity_ordered, NULL,
2588 (nvl(POD.amount_ordered,0) -
2589 nvl(POD.amount_cancelled,0)
2590 ),
2591 ( (nvl(POD.quantity_ordered,0) -
2592 nvl(POD.quantity_cancelled,0)
2593 )*
2594 nvl(PLL.price_override, 0)
2595 )
2596 ) *
2597 decode(p_base_cur_result,'Y',nvl(POD.rate,1),1)
2598 )/
2599 nvl(l_min_unit,1)
2600 ),decode(l_min_unit,null,l_precision,0)
2601 )*
2602 nvl(l_min_unit,1)
2603 )/
2604 nvl(l_base_min_unit,1)
2605 )
2606 ,decode(l_base_min_unit,null,l_base_precision,0)
2607 )*
2608 nvl(l_base_min_unit,1)
2609 ), 0
2610 )
2611 INTO l_archive_total_amt
2612 FROM PO_DISTRIBUTIONS_ARCHIVE_ALL POD, PO_LINE_LOCATIONS_ARCHIVE_ALL PLL
2613 WHERE PLL.po_header_id = p_object_id
2614 AND PLL.shipment_type in ('STANDARD')
2615 AND PLL.line_location_id = POD.line_location_id
2616 AND PLL.REVISION_NUM = (SELECT MAX(pll1.revision_num) FROM PO_LINE_LOCATIONS_ARCHIVE_ALL PLL1
2617 WHERE pll1.line_location_id = pll.line_location_id AND
2618 pll1.revision_num <= p_doc_revision)
2619 AND POD.REVISION_NUM = (SELECT MAX(pdd1.revision_num) FROM PO_DISTRIBUTIONS_ARCHIVE_ALL PDD1
2620 WHERE pdd1.po_distribution_id = pod.po_distribution_id AND
2621 pdd1.revision_num <= p_doc_revision);
2622
2623 l_progress := '060';
2624
2625
2626 elsif (p_object_type = 'S' ) then /* PO Shipment */
2630 c.precision
2627 l_progress := '070';
2628 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
2629 SELECT c.minimum_accountable_unit,
2631 INTO l_min_unit,
2632 l_precision
2633 FROM FND_CURRENCIES C,
2634 PO_HEADERS_ALL PH,
2635 PO_LINE_LOCATIONS_ALL PLL
2636 WHERE PLL.line_location_id = p_object_id
2637 AND PH.po_header_id = PLL.po_header_id
2638 AND C.currency_code = PH.CURRENCY_CODE;
2639
2640 if l_min_unit is null then
2641 l_progress := '80';
2642
2643 --SQL WHAT- This query returns the amount for the appropriate revision of a line_location
2644 --SQL WHY- To return the amount for line location
2645 --SQL JOIN- Use MAX to derive the appropriate revision of a line location
2646 -- <SERVICES FPJ>
2647 -- For the new Services lines, quantity will be null.
2648 -- Hence, added a decode statement to use amount directly
2649 -- in the total amount calculation when quantity is null.
2650 SELECT sum(round((
2651 decode(pll.quantity,
2652 null,
2653 (pll.amount - nvl(pll.amount_cancelled,0)),
2654 (pll.quantity - nvl(pll.quantity_cancelled,0))
2655 * nvl(pll.price_override,0)
2656 )
2657 ),l_precision))
2658 INTO l_archive_total_amt
2659 FROM PO_LINE_LOCATIONS_ARCHIVE_ALL PLL
2660 WHERE PLL.line_location_id = p_object_id AND
2661 PLL.revision_num = (SELECT MAX(pll1.revision_num) FROM PO_LINE_LOCATIONS_ARCHIVE_ALL PLL1 WHERE
2662 pll1.line_location_id = pll.line_location_id AND
2663 pll1.revision_num <= p_doc_revision) ;
2664
2665 else
2666 l_progress := '90';
2667 -- <SERVICES FPJ>
2668 -- For the new Services lines, quantity will be null.
2669 -- Hence, added a decode statement to use amount directly
2670 -- in the total amount calculation when quantity is null.
2671 select round(sum((
2672 decode(pll.quantity,
2673 null,
2674 (pll.amount - nvl(pll.amount_cancelled,0)),
2675 (pll.quantity - nvl(pll.quantity_cancelled,0))
2676 * nvl(pll.price_override,0)
2677 )
2678 /l_min_unit) * l_min_unit))
2679 INTO l_archive_total_amt
2680 FROM PO_LINE_LOCATIONS_ARCHIVE_ALL PLL
2681 WHERE PLL.line_location_id = p_object_id AND
2682 PLL.revision_num = (SELECT MAX(pll1.revision_num) FROM PO_LINE_LOCATIONS_ARCHIVE_ALL PLL1 WHERE
2683 pll1.line_location_id = pll.line_location_id AND
2684 pll1.revision_num <= p_doc_revision) ;
2685
2686 end if;
2687
2688 elsif (p_object_type = 'L' ) then /* Po Line */
2689 l_progress := '100';
2690 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
2691 SELECT sum(c.minimum_accountable_unit),
2692 sum(c.precision)
2693 INTO l_min_unit,
2694 l_precision
2695 FROM FND_CURRENCIES C,
2696 PO_HEADERS_ALL PH,
2697 PO_LINES_ALL POL
2698 WHERE POL.po_line_id = p_object_id
2699 AND PH.po_header_id = POL.po_header_id
2700 AND C.currency_code = PH.CURRENCY_CODE;
2701
2702 if l_min_unit is null then
2703 l_progress := '105';
2704
2705 -- <SERVICES FPJ>
2706 -- For the new Services lines, quantity will be null.
2707 -- Hence, added a decode statement to use amount directly
2708 -- in the total amount calculation when quantity is null.
2709 select sum(round((
2710 decode(pll.quantity,
2711 null,
2712 (pll.amount - nvl(pll.amount_cancelled, 0)),
2713 (pll.quantity - nvl(pll.quantity_cancelled,0))
2714 * nvl(pll.price_override,0)
2715 )
2716 ),l_precision))
2717 INTO l_archive_total_amt
2718 FROM PO_LINE_LOCATIONS_ARCHIVE_ALL PLL
2719 WHERE PLL.po_line_id = p_object_id
2720 AND PLL.shipment_type in ( 'STANDARD','BLANKET','PLANNED')
2721 AND PLL.revision_num = (SELECT MAX(pll1.revision_num) FROM PO_LINE_LOCATIONS_ARCHIVE_ALL PLL1 WHERE
2722 pll1.line_location_id = pll.line_location_id AND
2723 pll1.revision_num <= p_doc_revision) ;
2724
2725 else
2726 l_progress := '110';
2727
2728 -- <SERVICES FPJ>
2729 -- For the new Services lines, quantity will be null.
2730 -- Hence, added a decode statement to use amount directly
2731 -- in the total amount calculation when quantity is null.
2732 select sum(round((
2733 decode(pll.quantity,
2734 null,
2735 (pll.amount - nvl(pll.amount_cancelled,0)),
2736 (pll.quantity - nvl(pll.quantity_cancelled,0))
2737 * nvl(pll.price_override,0)
2738 )
2742 WHERE PLL.po_line_id = p_object_id
2739 / l_min_unit) * l_min_unit))
2740 INTO l_archive_total_amt
2741 FROM PO_LINE_LOCATIONS_ARCHIVE_ALL PLL
2743 AND PLL.shipment_type in ( 'STANDARD','BLANKET','PLANNED')
2744 AND PLL.revision_num = (SELECT MAX(pll1.revision_num) FROM PO_LINE_LOCATIONS_ARCHIVE_ALL PLL1 WHERE
2745 pll1.line_location_id = pll.line_location_id AND
2746 pll1.revision_num <= p_doc_revision) ;
2747
2748
2749 end if;
2750 end if; /* p_object_type */
2751
2752 elsif (p_doc_type = 'RELEASE') AND (p_doc_subtype = 'BLANKET') then
2753
2754
2755 if (p_object_type = 'R' ) then /* Release */
2756
2757 if p_base_cur_result = 'Y' then
2758 l_progress := '180';
2759 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
2760 SELECT GSB.currency_code,
2761 POH.currency_code
2762 INTO l_base_currency,
2763 l_po_currency
2764 FROM PO_HEADERS_ALL POH,
2765 FINANCIALS_SYSTEM_PARAMS_ALL FSP,
2766 GL_SETS_OF_BOOKS GSB,
2767 PO_RELEASES_ALL POR
2768 WHERE POR.po_release_id = p_object_id
2769 AND POH.po_header_id = POR.po_header_id
2770 AND NVL(POR.org_id,-99) = NVL(FSP.org_id,-99) --< Bug 3549096 >
2771 AND FSP.set_of_books_id = GSB.set_of_books_id;
2772
2773 if (l_base_currency <> l_po_currency) then
2774 /* Get precision and minimum accountable unit of the PO CURRENCY */
2775 l_progress := '190';
2776 po_core_s2.get_currency_info (l_po_currency,
2777 l_precision,
2778 l_min_unit );
2779
2780 /* Get precision and minimum accountable unit of the base CURRENCY */
2781 l_progress := '200';
2782 po_core_s2.get_currency_info (l_base_currency,
2783 l_base_precision,
2784 l_base_min_unit );
2785
2786 if l_base_min_unit is null then
2787 if l_min_unit is null then
2788 l_progress := '210';
2789
2790 -- <SERVICES FPJ>
2791 -- For the new Services lines, quantity will be null.
2792 -- Hence, added a decode statement to use amount directly
2793 -- in the total amount calculation when quantity is null.
2794 select nvl(sum(round(round(
2795 decode(POD.quantity_ordered,
2796 null,
2797 nvl(POD.amount_ordered, 0),
2798 (nvl(POD.quantity_ordered,0) *
2799 nvl(PLL.price_override,0))
2800 )
2801 * POD.rate
2802 ,l_precision),l_base_precision)),0)
2803 INTO l_archive_total_amt
2804 FROM PO_DISTRIBUTIONS_ARCHIVE_ALL POD, PO_LINE_LOCATIONS_ARCHIVE_ALL PLL
2805 WHERE PLL.po_release_id = p_object_id
2806 AND PLL.line_location_id = POD.line_location_id
2807 AND PLL.shipment_type in ('SCHEDULED','BLANKET')
2808 AND PLL.REVISION_NUM = (SELECT MAX(pll1.revision_num) FROM PO_LINE_LOCATIONS_ARCHIVE_ALL PLL1
2809 WHERE pll1.line_location_id = pll.line_location_id AND
2810 pll1.revision_num <= p_doc_revision)
2811 AND POD.REVISION_NUM = (SELECT MAX(pdd1.revision_num) FROM PO_DISTRIBUTIONS_ARCHIVE_ALL PDD1
2812 WHERE pdd1.po_distribution_id = pod.po_distribution_id AND
2813 pdd1.revision_num <= p_doc_revision);
2814
2815
2816 else
2817 l_progress := '212';
2818 -- <SERVICES FPJ>
2819 -- For the new Services lines, quantity will be null.
2820 -- Hence, added a decode statement to use amount directly
2821 -- in the total amount calculation when quantity is null.
2822 SELECT nvl(sum(round( round(
2823 decode(POD.quantity_ordered,
2824 null,
2825 nvl(POD.amount_ordered, 0),
2826 (nvl(POD.quantity_ordered, 0) *
2827 nvl(PLL.price_override, 0))
2828 )
2829 * POD.rate /
2830 l_min_unit) * l_min_unit , l_base_precision)),0)
2831 INTO l_archive_total_amt
2832 FROM PO_DISTRIBUTIONS_ARCHIVE_ALL POD, PO_LINE_LOCATIONS_ARCHIVE_ALL PLL
2833 WHERE PLL.po_release_id = p_object_id
2834 AND PLL.line_location_id = POD.line_location_id
2835 AND PLL.shipment_type in ('SCHEDULED','BLANKET')
2836 AND PLL.REVISION_NUM = (SELECT MAX(pll1.revision_num) FROM PO_LINE_LOCATIONS_ARCHIVE_ALL PLL1
2837 WHERE pll1.line_location_id = pll.line_location_id AND
2838 pll1.revision_num <= p_doc_revision)
2839 AND POD.REVISION_NUM = (SELECT MAX(pdd1.revision_num) FROM PO_DISTRIBUTIONS_ARCHIVE_ALL PDD1
2840 WHERE pdd1.po_distribution_id = pod.po_distribution_id AND
2841 pdd1.revision_num <= p_doc_revision);
2842
2843 end if;
2844 else
2845 if l_min_unit is null then
2846 l_progress := '214';
2847 -- <SERVICES FPJ>
2848 -- For the new Services lines, quantity will be null.
2852 decode(POD.quantity_ordered,
2849 -- Hence, added a decode statement to use amount directly
2850 -- in the total amount calculation when quantity is null.
2851 SELECT nvl(sum(round( round(
2853 null,
2854 nvl(POD.amount_ordered, 0),
2855 (nvl(POD.quantity_ordered, 0) *
2856 nvl(PLL.price_override, 0))
2857 )
2858 * POD.rate
2859 , l_precision)
2860 / l_base_min_unit ) * l_base_min_unit) ,0)
2861 INTO l_archive_total_amt
2862 FROM PO_DISTRIBUTIONS_ARCHIVE_ALL POD, PO_LINE_LOCATIONS_ARCHIVE_ALL PLL
2863 WHERE PLL.po_release_id = p_object_id
2864 AND PLL.line_location_id = POD.line_location_id
2865 AND PLL.shipment_type in ('SCHEDULED','BLANKET')
2866 AND PLL.REVISION_NUM = (SELECT MAX(pll1.revision_num) FROM PO_LINE_LOCATIONS_ARCHIVE_ALL PLL1
2867 WHERE pll1.line_location_id = pll.line_location_id AND
2868 pll1.revision_num <= p_doc_revision)
2869 AND POD.REVISION_NUM = (SELECT MAX(pdd1.revision_num) FROM PO_DISTRIBUTIONS_ARCHIVE_ALL PDD1
2870 WHERE pdd1.po_distribution_id = pod.po_distribution_id AND
2871 pdd1.revision_num <= p_doc_revision);
2872
2873 else
2874 l_progress := '216';
2875 -- <SERVICES FPJ>
2876 -- For the new Services lines, quantity will be null.
2877 -- Hence, added a decode statement to use amount directly
2878 -- in the total amount calculation when quantity is null.
2879 SELECT nvl(sum(round( round(
2880 decode(POD.quantity_ordered,
2881 null,
2882 nvl(POD.amount_ordered, 0),
2883 (nvl(POD.quantity_ordered, 0) *
2884 nvl(PLL.price_override, 0))
2885 )
2886 * POD.rate /
2887 l_min_unit) * l_min_unit / l_base_min_unit)
2888 * l_base_min_unit) , 0)
2889 INTO l_archive_total_amt
2890 FROM PO_DISTRIBUTIONS_ARCHIVE_ALL POD, PO_LINE_LOCATIONS_ARCHIVE_ALL PLL
2891 WHERE PLL.po_release_id = p_object_id
2892 AND PLL.line_location_id = POD.line_location_id
2893 AND PLL.shipment_type in ('SCHEDULED','BLANKET')
2894 AND PLL.REVISION_NUM = (SELECT MAX(pll1.revision_num) FROM PO_LINE_LOCATIONS_ARCHIVE_ALL PLL1
2895 WHERE pll1.line_location_id = pll.line_location_id AND
2896 pll1.revision_num <= p_doc_revision)
2897 AND POD.REVISION_NUM = (SELECT MAX(pdd1.revision_num) FROM PO_DISTRIBUTIONS_ARCHIVE_ALL PDD1
2898 WHERE pdd1.po_distribution_id = pod.po_distribution_id AND
2899 pdd1.revision_num <= p_doc_revision);
2900
2901 end if;
2902 end if;
2903
2904 end if;
2905 else
2906 l_progress := '220';
2907 --< Bug 3549096 > Use _ALL tables instead of org-striped views.
2908 SELECT c.minimum_accountable_unit,
2909 c.precision
2910 INTO l_min_unit,
2911 l_precision
2912 FROM FND_CURRENCIES C,
2913 PO_RELEASES_ALL POR,
2914 PO_HEADERS_ALL PH
2915 WHERE POR.po_release_id = p_object_id
2916 AND PH.po_header_id = POR.PO_HEADER_ID
2917 AND C.currency_code = PH.CURRENCY_CODE;
2918
2919 if l_min_unit is null then
2920
2921 /* 958792 kbenjami 8/25/99. Proprogated fix from R11.
2922 849493 - SVAIDYAN: Do a sum(round()) instead of round(sum()) since what
2923 we pass to GL is the round of individual dist. amounts
2924 and the sum of these rounded values is what should be
2925 displayed as the header total.
2926 */
2927 l_progress := '222';
2928 -- <SERVICES FPJ>
2929 -- For the new Services lines, quantity will be null.
2930 -- Hence, added a decode statement to use amount directly
2931 -- in the total amount calculation when quantity is null.
2932 select sum(round(
2933 decode(pll.quantity,
2934 null,
2935 (pll.amount - nvl(pll.amount_cancelled,0)),
2936 ((pll.quantity - nvl(pll.quantity_cancelled,0)) *
2937 nvl(pll.price_override,0))
2938 )
2939 ,l_precision))
2940 INTO l_archive_total_amt
2941 FROM PO_LINE_LOCATIONS_ARCHIVE_ALL PLL
2942 WHERE PLL.po_release_id = p_object_id
2943 AND PLL.shipment_type in ( 'SCHEDULED','BLANKET')
2944 AND PLL.REVISION_NUM = (SELECT MAX(pll1.revision_num) FROM PO_LINE_LOCATIONS_ARCHIVE_ALL PLL1
2945 WHERE pll1.line_location_id = pll.line_location_id AND
2946 pll1.revision_num <= p_doc_revision);
2947
2948 else
2949 /* Bug 1111926: GMudgal 2/18/2000
2950 ** Incorrect placement of brackets caused incorrect rounding
2951 ** and consequently incorrect PO header totals
2952 */
2953 l_progress := '224';
2954
2955 -- <SERVICES FPJ>
2959 select sum(round(
2956 -- For the new Services lines, quantity will be null.
2957 -- Hence, added a decode statement to use amount directly
2958 -- in the total amount calculation when quantity is null.
2960 decode(pll.quantity,
2961 null,
2962 (pll.amount - nvl(pll.amount_cancelled,0)),
2963 ((pll.quantity - nvl(pll.quantity_cancelled,0)) *
2964 nvl(pll.price_override,0))
2965 )
2966 /l_min_unit) *
2967 l_min_unit)
2968 INTO l_archive_total_amt
2969 FROM PO_LINE_LOCATIONS_ARCHIVE_ALL PLL
2970 WHERE PLL.po_release_id = p_object_id
2971 AND PLL.shipment_type in ( 'SCHEDULED','BLANKET')
2972 AND PLL.REVISION_NUM = (SELECT MAX(pll1.revision_num) FROM PO_LINE_LOCATIONS_ARCHIVE_ALL PLL1
2973 WHERE pll1.line_location_id = pll.line_location_id AND
2974 pll1.revision_num <= p_doc_revision);
2975
2976 end if;
2977
2978 end if;
2979
2980
2981 end if;
2982 END IF;-- (p_doc_type = 'PO') AND (p_doc_subtype = 'STANDARD')
2983
2984
2985 l_progress := '250';
2986 --If l_archive_total_amt has a null value, return 0 as the total.
2987 IF l_archive_total_amt IS NULL THEN
2988 l_archive_total_amt := 0;
2989 END IF;
2990 l_progress := '260';
2991 RETURN(l_archive_total_amt);
2992
2993 EXCEPTION
2994 WHEN OTHERS THEN
2995 IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error)
2996 THEN
2997 fnd_msg_pub.add_exc_msg (g_pkg_name, 'GET_ARCHIVE_TOTAL_FOR_ANY_REV',
2998 SUBSTRB (SQLERRM , 1 , 200) || ' at location ' || l_progress);
2999 END IF;
3000 RETURN(0);
3001 END get_archive_total_for_any_rev;
3002
3003 --<POC FPJ END>
3004 /*===================================================================================
3005
3006 FUNCTION: GET_RELEASE_LINE_TOTAL Bug#3771735
3007
3008 DESCRIPTION: Function is being added to get the correct cumulative Amount of all
3009 shipments of a Release which correspond to the same line of a BPA.
3010 The function will be used during the PDF generation of a Incomplete
3011 Blanket Release.
3012
3013 ===================================================================================*/
3014 FUNCTION GET_RELEASE_LINE_TOTAL
3015 (
3016 p_line_id IN PO_LINES_ALL.PO_LINE_ID%TYPE ,
3017 p_release_id IN PO_RELEASES_ALL.PO_RELEASE_ID%TYPE
3018 )
3019 RETURN NUMBER
3020 IS
3021 x_min_unit NUMBER;
3022 x_precision INTEGER;
3023 x_result_fld NUMBER;
3024
3025 BEGIN
3026
3027 SELECT sum(c.minimum_accountable_unit),
3028 sum(c.precision)
3029 INTO x_min_unit,
3030 x_precision
3031 FROM FND_CURRENCIES C,
3032 PO_HEADERS_ALL PH,
3033 PO_LINES_ALL POL
3034 WHERE POL.po_line_id = p_line_id
3035 AND PH.po_header_id = POL.po_header_id
3036 AND C.currency_code = PH.CURRENCY_CODE;
3037
3038 if x_min_unit is null then
3039 -- <SERVICES FPJ>
3040 -- For the new Services lines, quantity will be null.
3041 -- Hence, added a decode statement to use amount directly
3042 -- in the total amount calculation when quantity is null.
3043 --Use _ALL tables instead of org-striped views.
3044 select sum(round((
3045 decode(pll.quantity,
3046 null,
3047 (pll.amount - nvl(pll.amount_cancelled, 0)),
3048 (pll.quantity - nvl(pll.quantity_cancelled,0))
3049 * nvl(pll.price_override,0)
3050 )
3051 ),x_precision))
3052 INTO x_result_fld
3053 FROM PO_LINE_LOCATIONS_ALL PLL
3054 WHERE PLL.po_line_id = p_line_id
3055 AND PLL.po_release_id = p_release_id
3056 AND PLL.shipment_type in ( 'STANDARD','BLANKET','PLANNED');
3057
3058 else
3059 -- <SERVICES FPJ>
3060 -- For the new Services lines, quantity will be null.
3061 -- Hence, added a decode statement to use amount directly
3062 -- in the total amount calculation when quantity is null.
3063 -- Use _ALL tables instead of org-striped views.
3064 select sum(round((
3065 decode(pll.quantity,
3066 null,
3067 (pll.amount - nvl(pll.amount_cancelled,0)),
3068 (pll.quantity - nvl(pll.quantity_cancelled,0))
3069 * nvl(pll.price_override,0)
3070 )
3071 / x_min_unit) * x_min_unit))
3072 INTO x_result_fld
3073 FROM PO_LINE_LOCATIONS_ALL PLL
3074 WHERE PLL.po_line_id = p_line_id
3075 AND PLL.po_release_id = p_release_id
3076 AND PLL.shipment_type in ( 'STANDARD','BLANKET','PLANNED');
3077
3078 end if;
3079 return(x_result_fld);
3080 END GET_RELEASE_LINE_TOTAL;
3081
3082 /*===================================================================================
3083
3084 FUNCTION: get_ga_amount_released <GA FPI>
3085
3086 DESCRIPTION: Gets the total Amount Released for a particular Global Agreement.
3087 That is, sum up the total for all uncancelled Standard PO lines
3088 which reference that Global Agreement.
3089
3090 ===================================================================================*/
3091 FUNCTION get_ga_amount_released
3095 )
3092 (
3093 p_po_header_id PO_HEADERS_ALL.po_header_id%TYPE,
3094 p_convert_to_base BOOLEAN := FALSE
3096 RETURN NUMBER
3097 IS
3098 l_base_currency FND_CURRENCIES.currency_code%TYPE;
3099 l_base_precision FND_CURRENCIES.precision%TYPE;
3100 l_base_ext_precision FND_CURRENCIES.extended_precision%TYPE;
3101 l_base_min_unit FND_CURRENCIES.minimum_accountable_unit%TYPE;
3102
3103 l_po_currency FND_CURRENCIES.currency_code%TYPE;
3104 l_po_precision FND_CURRENCIES.precision%TYPE;
3105 l_po_ext_precision FND_CURRENCIES.extended_precision%TYPE;
3106 l_po_min_unit FND_CURRENCIES.minimum_accountable_unit%TYPE;
3107
3108 l_rate PO_HEADERS_ALL.rate%TYPE;
3109
3110 x_total NUMBER;
3111
3112 BEGIN
3113
3114 -- Get the functional currency code for the current org's Set of Books
3115 -- and the currency code defined for the PO
3116 PO_CORE_S2.get_po_currency( p_po_header_id, -- IN
3117 l_base_currency, --OUT
3118 l_po_currency ); --OUT
3119
3120 -- Get the Precision (never NULL), Extended Precision, Minimum Accountable Unit
3121 -- for the Set of Books' currency code...
3122 FND_CURRENCY.get_info( l_base_currency, -- IN
3123 l_base_precision, --OUT
3124 l_base_ext_precision, --OUT
3125 l_base_min_unit ); --OUT
3126
3127 -- and for the PO's currency code...
3128 FND_CURRENCY.get_info( l_po_currency, -- IN
3129 l_po_precision, --OUT
3130 l_po_ext_precision, --OUT
3131 l_po_min_unit ); --OUT
3132
3133 -- NOTE: All Standard PO's must have the same currency code as the
3134 -- Global Agreement that they reference. The currency conversion rate used
3135 -- will be the rate between the Global Agreement's currency and the owning
3136 -- org's currency.
3137
3138 IF ( ( p_convert_to_base ) -- convert back to base currency
3139 AND ( l_base_currency <> l_po_currency ) ) THEN
3140
3141 -- Get the rate from PO_HEADERS_ALL for the Global Agreement.
3142 SELECT rate
3143 INTO l_rate
3144 FROM po_headers_all
3145 WHERE po_header_id = p_po_header_id;
3146
3147 IF ( l_base_min_unit IS NOT NULL ) THEN
3148
3149 IF ( l_po_min_unit IS NOT NULL ) THEN
3150
3151 -- <SERVICES FPJ>
3152 -- For the new Services lines, quantity will be null.
3153 -- Hence, added a decode statement to use amount directly
3154 -- in the total amount calculation when quantity is null.
3155 --<BUG 10196605 Modified below sql to reduce performance issues>
3156 SELECT sum ( round ( ( round ( ( ( decode(poll.quantity, null,
3157 (poll.amount -
3158 poll.amount_cancelled),
3159 (( poll.quantity
3160 - poll.quantity_cancelled )
3161 * nvl(poll.price_override,0))
3162 )
3163 )
3164 * l_rate )
3165 / l_po_min_unit )
3166 * l_po_min_unit )
3167 / l_base_min_unit )
3168 * l_base_min_unit )
3169 INTO x_total
3170 FROM po_line_locations_all poll,
3171 po_lines_all pol
3172 WHERE poll.po_line_id = pol.po_line_id
3173 AND pol.from_header_id = p_po_header_id
3174 AND Nvl(poll.consigned_flag,'N') <> 'Y';
3175 ELSE -- ( l_po_min_unit IS NULL )
3176
3177 -- <SERVICES FPJ>
3178 -- For the new Services lines, quantity will be null.
3179 -- Hence, added a decode statement to use amount directly
3180 -- in the total amount calculation when quantity is null.
3181 --<BUG 10196605 Modified below sql to reduce performance issues>
3182 SELECT sum ( round ( ( (decode(poll.quantity, null,
3183 (poll.amount -
3184 poll.amount_cancelled),
3185 (( poll.quantity
3186 - poll.quantity_cancelled )
3187 * nvl(poll.price_override,0))
3188 )
3189 )
3190 * l_rate )
3191 / l_base_min_unit )
3192 * l_base_min_unit )
3193 INTO x_total
3194 FROM po_line_locations_all poll,
3195 po_lines_all pol
3196 WHERE poll.po_line_id = pol.po_line_id
3197 AND pol.from_header_id = p_po_header_id
3198 AND Nvl(poll.consigned_flag,'N') <> 'Y';
3199
3200 END IF;
3201
3202 ELSE -- ( l_base_min_unit IS NULL )
3203
3204 IF ( l_po_min_unit IS NOT NULL ) THEN
3205
3206 -- <SERVICES FPJ>
3207 -- For the new Services lines, quantity will be null.
3211 SELECT sum ( round ( ( (decode(poll.quantity, null,
3208 -- Hence, added a decode statement to use amount directly
3209 -- in the total amount calculation when quantity is null.
3210 --<BUG 10196605 Modified below sql to reduce performance issues>
3212 (poll.amount -
3213 poll.amount_cancelled),
3214 (( poll.quantity
3215 - poll.quantity_cancelled )
3216 * nvl(poll.price_override,0))
3217 )
3218 )
3219 * l_rate )
3220 / l_po_min_unit )
3221 * l_po_min_unit )
3222 INTO x_total
3223 FROM po_line_locations_all poll,
3224 po_lines_all pol
3225 WHERE poll.po_line_id = pol.po_line_id
3226 AND pol.from_header_id = p_po_header_id
3227 AND Nvl(poll.consigned_flag,'N') <> 'Y';
3228 ELSE -- ( l_po_min_unit IS NULL )
3229
3230 -- <SERVICES FPJ>
3231 -- For the new Services lines, quantity will be null.
3232 -- Hence, added a decode statement to use amount directly
3233 -- in the total amount calculation when quantity is null.
3234 --<BUG 10196605 Modified below sql to reduce performance issues>
3235 SELECT sum ( (decode(poll.quantity, null,
3236 (poll.amount -
3237 poll.amount_cancelled),
3238 (( poll.quantity
3239 - poll.quantity_cancelled )
3240 * nvl(poll.price_override,0))
3241 )
3242 )
3243 * l_rate )
3244 INTO x_total
3245 FROM po_line_locations_all poll,
3246 po_lines_all pol
3247 WHERE poll.po_line_id = pol.po_line_id
3248 AND pol.from_header_id = p_po_header_id
3249 AND Nvl(poll.consigned_flag,'N') <> 'Y';
3250 END IF;
3251
3252 END IF;
3253
3254 ELSE -- just get po_currency (no conversion necessary)
3255
3256 IF ( l_po_min_unit IS NOT NULL ) THEN
3257
3258 -- <SERVICES FPJ>
3259 -- For the new Services lines, quantity will be null.
3260 -- Hence, added a decode statement to use amount directly
3261 -- in the total amount calculation when quantity is null.
3262 --<BUG 10196605 Modified below sql to reduce performance issues>
3263 SELECT sum ( round ( (decode(poll.quantity, null,
3264 (poll.amount -
3265 poll.amount_cancelled),
3266 (( poll.quantity
3267 - poll.quantity_cancelled )
3268 * nvl(poll.price_override,0))
3269 )
3270 )
3271 / l_po_min_unit )
3272 * l_po_min_unit )
3273 INTO x_total
3274 FROM po_line_locations_all poll,
3275 po_lines_all pol
3276 WHERE poll.po_line_id = pol.po_line_id
3277 AND pol.from_header_id = p_po_header_id
3278 AND Nvl(poll.consigned_flag,'N') <> 'Y';
3279
3280 ELSE -- ( l_po_min_unit IS NULL )
3281
3282 -- <SERVICES FPJ>
3283 -- For the new Services lines, quantity will be null.
3284 -- Hence, added a decode statement to use amount directly
3285 -- in the total amount calculation when quantity is null.
3286 --<BUG 10196605 Modified below sql to reduce performance issues>
3287 SELECT sum (decode(poll.quantity, null,
3288 (poll.amount -
3289 poll.amount_cancelled),
3290 (( poll.quantity
3291 - poll.quantity_cancelled )
3292 * nvl(poll.price_override,0))
3293 )
3294 )
3295 INTO x_total
3296 FROM po_line_locations_all poll,
3297 po_lines_all pol
3298 WHERE poll.po_line_id = pol.po_line_id
3299 AND pol.from_header_id = p_po_header_id
3300 AND Nvl(poll.consigned_flag,'N') <> 'Y';
3301
3302 END IF;
3303
3304 END IF;
3305
3306 return(x_total);
3307
3308 EXCEPTION
3309 WHEN OTHERS THEN
3310 return(0);
3311
3312 END get_ga_amount_released;
3313
3314
3315 /*===================================================================================
3316
3317 FUNCTION: get_ga_line_amount_released <GA FPI>
3318
3319 DESCRIPTION: Gets the total Amount Released for a Global Agreement line.
3320 That is, sum up the total for all uncancelled Standard PO lines
3321 which reference that Global Agreement line.
3322
3323 ===================================================================================*/
3324 PROCEDURE get_ga_line_amount_released
3325 (
3326 p_po_line_id IN PO_LINES_ALL.po_line_id%TYPE,
3327 p_po_header_id IN PO_HEADERS_ALL.po_header_id%TYPE,
3328 x_quantity_released OUT NOCOPY NUMBER,
3332 l_base_currency FND_CURRENCIES.currency_code%TYPE;
3329 x_amount_released OUT NOCOPY NUMBER
3330 )
3331 IS
3333
3334 l_po_currency FND_CURRENCIES.currency_code%TYPE;
3335 l_po_precision FND_CURRENCIES.precision%TYPE;
3336 l_po_ext_precision FND_CURRENCIES.extended_precision%TYPE;
3337 l_po_min_unit FND_CURRENCIES.minimum_accountable_unit%TYPE;
3338
3339 l_rate PO_HEADERS_ALL.rate%TYPE;
3340
3341 BEGIN
3342 /*Bug11802312 - Exclude the records with consigned flag Y while calculating the amount released
3343 After this fix, document reference is retained and hence from header id and from line id will
3344 be populated.Added AND Nvl(poll.consigned_flag,'N') <> 'Y'; to exclude the consigned shipments*/
3345
3346 -- Get the currency code defined for the PO
3347 PO_CORE_S2.get_po_currency( p_po_header_id, -- IN
3348 l_base_currency, --OUT
3349 l_po_currency ); --OUT
3350
3351 -- Get the Precision (never NULL), Extended Precision, Minimum Accountable Unit
3352 -- for the PO's currency code...
3353 FND_CURRENCY.get_info( l_po_currency, -- IN
3354 l_po_precision, --OUT
3355 l_po_ext_precision, --OUT
3356 l_po_min_unit ); --OUT
3357
3358 IF ( l_po_min_unit IS NOT NULL ) THEN
3359
3360 -- <SERVICES FPJ>
3361 -- For the new Services lines, quantity will be null.
3362 -- Hence, added a decode statement to use amount directly
3363 -- in the total amount calculation when quantity is null.
3364 SELECT sum ( round ( (decode(pol.quantity, null,
3365 (pod.amount_ordered -
3366 pod.amount_cancelled),
3367 (( pod.quantity_ordered
3368 - pod.quantity_cancelled )
3369 * poll.price_override))
3370 )
3371 / l_po_min_unit )
3372 * l_po_min_unit ),
3373 sum ( pod.quantity_ordered - pod.quantity_cancelled )
3374 INTO x_amount_released,
3375 x_quantity_released
3376 FROM po_distributions_all pod,
3377 po_line_locations_all poll,
3378 po_lines_all pol
3379 WHERE pod.line_location_id = poll.line_location_id
3380 AND poll.po_line_id = pol.po_line_id
3381 AND pol.from_line_id = p_po_line_id
3382 AND Nvl(poll.consigned_flag,'N') <> 'Y';
3383
3384 ELSE -- ( l_po_min_unit IS NULL )
3385
3386 -- <SERVICES FPJ>
3387 -- For the new Services lines, quantity will be null.
3388 -- Hence, added a decode statement to use amount directly
3389 -- in the total amount calculation when quantity is null.
3390 SELECT sum (decode(pol.quantity, null,
3391 (pod.amount_ordered -
3392 pod.amount_cancelled),
3393 (( pod.quantity_ordered
3394 - pod.quantity_cancelled )
3395 * poll.price_override)
3396 )
3397 ),
3398 sum ( pod.quantity_ordered - pod.quantity_cancelled )
3399 INTO x_amount_released,
3400 x_quantity_released
3401 FROM po_distributions_all pod,
3402 po_line_locations_all poll,
3403 po_lines_all pol
3404 WHERE pod.line_location_id = poll.line_location_id
3405 AND poll.po_line_id = pol.po_line_id
3406 AND pol.from_line_id = p_po_line_id
3407 AND Nvl(poll.consigned_flag,'N') <> 'Y';
3408
3409 END IF;
3410
3411 END get_ga_line_amount_released;
3412
3413
3414 -- <GC FPJ START>
3415 /**=========================================================================
3416 * Function: get_gc_amount_released
3417 * Effects: Calculate amount released given a global contract
3418 * Requires: None
3419 * Modifies: None
3420 * Return: amount released. Whether the amount is converted to base currency
3421 * is determined by p_convert_to_base
3422 =========================================================================**/
3423
3424 FUNCTION get_gc_amount_released
3425 (
3426 p_po_header_id IN NUMBER,
3427 p_convert_to_base IN BOOLEAN := FALSE
3428 ) RETURN NUMBER
3429 IS
3430
3431 l_base_currency FND_CURRENCIES.currency_code%TYPE;
3432 l_base_precision FND_CURRENCIES.precision%TYPE;
3433 l_base_min_unit FND_CURRENCIES.minimum_accountable_unit%TYPE;
3434
3435 l_po_currency FND_CURRENCIES.currency_code%TYPE;
3436 l_po_precision FND_CURRENCIES.precision%TYPE;
3437 l_po_min_unit FND_CURRENCIES.minimum_accountable_unit%TYPE;
3438
3439 l_rate PO_HEADERS_ALL.rate%TYPE;
3440 l_total NUMBER;
3441
3442 l_log_head CONSTANT VARCHAR2(100) := g_log_head||'GET_GC_AMOUNT_RELEASED';
3443 l_progress VARCHAR2(3) := '000';
3444
3445 BEGIN
3446 IF g_debug_stmt THEN
3447 PO_DEBUG.debug_begin(l_log_head);
3448 END IF;
3449
3450 l_progress := '010';
3451
3452 PO_CORE_S2.get_po_currency ( x_object_id => p_po_header_id,
3453 x_base_currency => l_base_currency,
3454 x_po_currency => l_po_currency );
3455
3456 PO_CORE_S2.get_currency_info ( x_currency_code => l_base_currency,
3460 PO_CORE_S2.get_currency_info ( x_currency_code => l_po_currency,
3457 x_precision => l_base_precision,
3458 x_min_unit => l_base_min_unit );
3459
3461 x_precision => l_po_precision,
3462 x_min_unit => l_po_min_unit );
3463
3464 --Bug# 5391346 START:
3465 --Added the following to queries below as was coded in the local contract case (refer bug# 716188)
3466 --1. Where clause POLL.shipment_type in ('STANDARD','PLANNED')
3467 --2. Outer Join POD.line_location_id(+) = POLL.line_location_id instead of simple join
3468 --3. Proper rate conversions taking into account different currencies of GCPA and SPOs sourced to it.
3469
3470
3471
3472 IF ( p_convert_to_base AND
3473 l_base_currency <> l_po_currency ) THEN
3474
3475 --Bug# 5391346: Removed the query to get l_rate from GCPA header
3476 --as we now use rate on the PO header to convert it to base currency.
3477
3478 l_progress := '020';
3479
3480 IF (l_base_min_unit IS NOT NULL) THEN
3481
3482 l_progress := '030';
3483
3484 IF (l_po_min_unit IS NOT NULL) THEN
3485 /*Bug11802312 - Exclude the records with consigned flag Y while calculating the amount released
3486 After this fix, document reference is retained and hence from header id and from line id will
3487 be populated.Added AND Nvl(poll.consigned_flag,'N') <> 'Y'; to exclude the consigned shipments*/
3488
3489 -- SQL What: calculate amount released from all lines across OU
3490 -- referencing this GC, with the amount being
3491 -- converted to base currency
3492 -- SQL Why: This is the return value
3493 --<Complex Work R12>: added decode on value basis
3494
3495 --Bug# 5391346: Added Decode for currency match condition
3496 --Also added a join with PO_HEADERS_ALL for rate in header of execution document
3497 --<BUG 10196605 Modified below sql to reduce performance issues>
3498 l_progress := '040';
3499
3500 SELECT NVL(
3501 SUM(
3502 DECODE(l_base_currency, PH1.currency_code,
3503 ROUND(
3504 ROUND(
3505 DECODE(POLL.value_basis
3506 ,'FIXED PRICE',
3507 NVL(POD.amount_ordered, 0) -
3508 NVL(POD.amount_cancelled, 0)
3509 , 'RATE',
3510 NVL(POD.amount_ordered, 0)-
3511 NVL(POD.amount_cancelled, 0)
3512 , --Qty based
3513 (NVL(POD.quantity_ordered, 0) -
3514 NVL(POD.quantity_cancelled,0)
3515 ) * NVL(POLL.price_override, 0)
3516 )
3517 /l_po_min_unit)*l_po_min_unit
3518 /l_base_min_unit)*l_base_min_unit
3519 ,
3520
3521
3522 ROUND(
3523 ROUND(
3524 DECODE(POLL.value_basis
3525 ,'FIXED PRICE',
3526 NVL(POD.amount_ordered, 0) -
3527 NVL(POD.amount_cancelled, 0)
3528 , 'RATE',
3529 NVL(POD.amount_ordered, 0)-
3530 NVL(POD.amount_cancelled, 0)
3531 , --Qty based
3532 (NVL(POD.quantity_ordered, 0) -
3533 NVL(POD.quantity_cancelled,0)
3534 ) * NVL(POLL.price_override, 0)
3535 )
3536 /l_po_min_unit)*l_po_min_unit
3537 * NVL(POD.rate, NVL(PH1.rate,1))
3538 /l_base_min_unit) * l_base_min_unit
3539 )
3540 )
3541 ,0)
3542 INTO l_total
3543 FROM PO_DISTRIBUTIONS_ALL POD,
3544 PO_LINE_LOCATIONS_ALL POLL,
3545 PO_LINES_ALL POL,
3546 PO_HEADERS_ALL PH1
3547 WHERE POL.contract_id = p_po_header_id
3548 AND POL.po_line_id = POLL.po_line_id
3549 AND POLL.shipment_type in ('STANDARD','PLANNED')
3550 AND POD.line_location_id = POLL.line_location_id --bug 12572504
3551 AND PH1.po_header_id = POL.po_header_id
3552 AND POD.po_line_id = POLL.po_line_id
3553 AND Nvl(poll.consigned_flag,'N') <> 'Y';
3554
3555 ELSE -- (l_po_min_unit is null)
3556
3557 -- SQL What: calculate amount released from all lines across OU
3558 -- referencing this GC, with the amount being
3559 -- converted to base currency
3560 -- SQL Why: This is the return value
3561 --<Complex Work R12>: added decode on value basis
3562
3563 --Bug# 5391346: Added Decode for currency match condition
3564 --Use PO precision (ie Contract currency precision) when l_po_min_unit is null (PO implies the Contract here)
3565 --Also added a join with PO_HEADERS_ALL for rate in header of execution document
3566 --<BUG 10196605 Modified below sql to reduce performance issues>
3567 l_progress := '050';
3568
3569 SELECT NVL(
3570 SUM(
3571 DECODE(l_base_currency, PH1.currency_code,
3572 ROUND(
3573 ROUND(
3574 DECODE(POLL.value_basis
3575 ,'FIXED PRICE',
3576 NVL(POD.amount_ordered, 0) -
3577 NVL(POD.amount_cancelled, 0)
3578 , 'RATE',
3579 NVL(POD.amount_ordered, 0)-
3580 NVL(POD.amount_cancelled, 0)
3581 , --Qty based
3582 (NVL(POD.quantity_ordered, 0) -
3583 NVL(POD.quantity_cancelled,0)
3584 ) * NVL(POLL.price_override, 0)
3585 )
3586 ,l_po_precision)
3587 /l_base_min_unit)*l_base_min_unit
3588 ,
3589
3590
3591 ROUND(
3592 ROUND(
3593 DECODE(POLL.value_basis
3594 ,'FIXED PRICE',
3595 NVL(POD.amount_ordered, 0) -
3596 NVL(POD.amount_cancelled, 0)
3597 , 'RATE',
3598 NVL(POD.amount_ordered, 0)-
3599 NVL(POD.amount_cancelled, 0)
3600 , --Qty based
3601 (NVL(POD.quantity_ordered, 0) -
3602 NVL(POD.quantity_cancelled,0)
3603 ) * NVL(POLL.price_override, 0)
3604 ) * NVL(POD.rate, NVL(PH1.rate,1))
3605 ,l_po_precision)
3606 /l_base_min_unit) * l_base_min_unit
3607 )
3608 )
3609 ,0)
3610 INTO l_total
3611 FROM PO_DISTRIBUTIONS_ALL POD,
3612 PO_LINE_LOCATIONS_ALL POLL,
3613 PO_LINES_ALL POL,
3614 PO_HEADERS_ALL PH1
3615 WHERE POL.contract_id = p_po_header_id
3616 AND POL.po_line_id = POLL.po_line_id
3617 AND POLL.shipment_type in ('STANDARD','PLANNED')
3618 AND POD.line_location_id = POLL.line_location_id --bug 12572504
3619 AND PH1.po_header_id = POL.po_header_id
3620 AND POD.po_line_id = POLL.po_line_id
3621 AND Nvl(poll.consigned_flag,'N') <> 'Y';
3622 END IF;
3623
3624 ELSE -- (l_base_min_unit IS NULL)
3625 l_progress := '060';
3626
3627 IF (l_po_min_unit IS NOT NULL) THEN
3628
3629 -- SQL What: calculate amount released from all lines across OU
3630 -- referencing this GC, with the amount being
3631 -- converted to base currency
3632 -- SQL Why: This is the return value
3633 --<Complex Work R12>: added decode on value basis
3634
3635 --Bug# 5391346: Added Decode for currency match condition
3636 --use only PO min unit and not PO precision when l_po_min_unit is not null (PO implies the Contract here)
3637 --Also added a join with PO_HEADERS_ALL for rate in header of execution document
3638 --<BUG 10196605 Modified below sql to reduce performance issues>
3639 l_progress := '070';
3640
3641 SELECT NVL(
3642 SUM(
3643 DECODE(l_base_currency, PH1.currency_code,
3644 ROUND(
3645 ROUND(
3646 DECODE(POLL.value_basis
3647 ,'FIXED PRICE',
3648 NVL(POD.amount_ordered, 0) -
3649 NVL(POD.amount_cancelled, 0)
3650 , 'RATE',
3651 NVL(POD.amount_ordered, 0)-
3652 NVL(POD.amount_cancelled, 0)
3653 , --Qty based
3654 (NVL(POD.quantity_ordered, 0) -
3655 NVL(POD.quantity_cancelled,0)
3656 ) * NVL(POLL.price_override, 0)
3657 )
3658 /l_po_min_unit) * l_po_min_unit
3659 , l_base_precision),
3660 ROUND(
3661 ROUND(
3662 DECODE(POLL.value_basis
3663 ,'FIXED PRICE',
3664 NVL(POD.amount_ordered, 0) -
3665 NVL(POD.amount_cancelled, 0)
3666 , 'RATE',
3667 NVL(POD.amount_ordered, 0)-
3668 NVL(POD.amount_cancelled, 0)
3669 , --Qty based
3670 (NVL(POD.quantity_ordered, 0) -
3671 NVL(POD.quantity_cancelled,0)
3672 ) * NVL(POLL.price_override, 0)
3673 )* NVL(POD.rate, NVL(PH1.rate,1)
3674 )
3675 /l_po_min_unit) * l_po_min_unit
3676 , l_base_precision)
3677 )
3678 ),0)
3679 INTO l_total
3680 FROM PO_DISTRIBUTIONS_ALL POD,
3681 PO_LINE_LOCATIONS_ALL POLL,
3682 PO_LINES_ALL PoL,
3683 PO_HEADERS_ALL PH1
3684 WHERE POL.contract_id = p_po_header_id
3685 AND POL.po_line_id = POLL.po_line_id
3686 AND POLL.shipment_type in ('STANDARD','PLANNED')
3687 AND POD.line_location_id = POLL.line_location_id --bug 12572504
3688 AND PH1.po_header_id = POL.po_header_id
3689 AND POD.po_line_id = POLL.po_line_id
3690 AND Nvl(poll.consigned_flag,'N') <> 'Y';
3691
3692 ELSE -- (l_po_min_unit IS NULL)
3693
3694 -- SQL What: calculate amount released from all lines across OU
3695 -- referencing this GC, with the amount being
3696 -- converted to base currency
3697 -- SQL Why: This is the return value
3698 --<Complex Work R12>: added decode on value basis
3699
3700 --Bug# 5391346: Added Decode for currency match condition
3701 --use PO precision when PO currency min unit is null
3702 --Also added a join with PO_HEADERS_ALL for rate in header of execution document
3703 --<BUG 10196605 Modified below sql to reduce performance issues>
3704 l_progress := '080';
3705
3706 SELECT NVL(
3707 SUM(
3708 DECODE(l_base_currency, PH1.currency_code,
3709 ROUND(
3710 ROUND(
3711 DECODE(POLL.value_basis
3712 ,'FIXED PRICE',
3713 NVL(POD.amount_ordered, 0) -
3714 NVL(POD.amount_cancelled, 0)
3715 , 'RATE',
3716 NVL(POD.amount_ordered, 0)-
3717 NVL(POD.amount_cancelled, 0)
3718 , --Qty based
3719 (NVL(POD.quantity_ordered, 0) -
3720 NVL(POD.quantity_cancelled,0)
3721 ) * NVL(POLL.price_override, 0)
3722 )
3723 ,l_po_precision)
3724 , l_base_precision),
3725 ROUND(
3726 ROUND(
3727 DECODE(POLL.value_basis
3728 ,'FIXED PRICE',
3729 NVL(POD.amount_ordered, 0) -
3730 NVL(POD.amount_cancelled, 0)
3734 , --Qty based
3731 , 'RATE',
3732 NVL(POD.amount_ordered, 0)-
3733 NVL(POD.amount_cancelled, 0)
3735 (NVL(POD.quantity_ordered, 0) -
3736 NVL(POD.quantity_cancelled,0)
3737 ) * NVL(POLL.price_override, 0)
3738 )* NVL(POD.rate, NVL(PH1.rate,1)
3739 )
3740 ,l_po_precision)
3741 , l_base_precision)
3742 )
3743 ),0)
3744 INTO l_total
3745 FROM PO_DISTRIBUTIONS_ALL POD,
3746 PO_LINE_LOCATIONS_ALL POLL,
3747 PO_LINES_ALL POL,
3748 PO_HEADERS_ALL PH1
3749 WHERE POL.contract_id = p_po_header_id
3750 AND POL.po_line_id = POLL.po_line_id
3751 AND POLL.shipment_type in ('STANDARD','PLANNED')
3752 AND POD.line_location_id = POLL.line_location_id --bug 12572504
3753 AND PH1.po_header_id = POL.po_header_id
3754 AND POD.po_line_id = POLL.po_line_id
3755 AND Nvl(poll.consigned_flag,'N') <> 'Y';
3756
3757 END IF;
3758
3759 END IF;
3760
3761 ELSE -- (no base currency conversion)
3762
3763 l_progress := '090';
3764
3765 IF (l_po_min_unit IS NOT NULL) THEN
3766
3767 -- SQL What: calculate amount released from all lines across OU
3768 -- referencing this GC in GC currency
3769 -- SQL Why: This is the return value
3770 --<Complex Work R12>: added decode on value basis
3771
3772 --Bug# 5391346: Added Decode for currency match condition
3773 --Also added a join with PO_HEADERS_ALL for rate in header of execution document
3774 --<BUG 10196605 Modified below sql to reduce performance issues>
3775 l_progress := '100';
3776 -- Bug# 13536418: Added hint to improve performance.
3777 SELECT /*+ use_nl(POLL,POD,PH1) index(POLL PO_LINE_LOCATIONS_N1) index(PH1 PO_HEADERS_U1) */ NVL(
3778 SUM(
3779 DECODE(PH.currency_code, PH1.currency_code,
3780 ROUND (
3781 DECODE(POLL.value_basis
3782 ,'FIXED PRICE',
3783 NVL(POD.amount_ordered, 0) -
3784 NVL(POD.amount_cancelled, 0)
3785 , 'RATE',
3786 NVL(POD.amount_ordered, 0)-
3787 NVL(POD.amount_cancelled, 0)
3788 , --Qty based
3789 (NVL(POD.quantity_ordered, 0) -
3790 NVL(POD.quantity_cancelled,0)
3791 ) * NVL(POLL.price_override, 0)
3792 )
3793 /l_po_min_unit)* l_po_min_unit
3794 ,
3795
3796 ROUND(
3797 DECODE(POLL.value_basis
3798 ,'FIXED PRICE',
3799 NVL(POD.amount_ordered, 0) -
3800 NVL(POD.amount_cancelled, 0)
3801 , 'RATE',
3802 NVL(POD.amount_ordered, 0)-
3803 NVL(POD.amount_cancelled, 0)
3804 , --Qty based
3805 (NVL(POD.quantity_ordered, 0) -
3806 NVL(POD.quantity_cancelled,0)
3807 ) * NVL(POLL.price_override, 0)
3808 )* NVL(POD.rate, NVL(PH1.rate,1))
3809 /NVL(PH.rate,1)
3810 /l_po_min_unit)* l_po_min_unit
3811
3812 )
3813 )
3814 ,0)
3815 INTO l_total
3816 FROM PO_DISTRIBUTIONS_ALL POD,
3817 PO_LINE_LOCATIONS_ALL POLL,
3818 PO_LINES_ALL POL,
3819 PO_HEADERS_ALL PH,
3820 PO_HEADERS_ALL PH1
3821 WHERE PH.po_header_id = p_po_header_id
3822 AND PH.po_header_id = POL.contract_id
3823 AND POL.po_line_id = POLL.po_line_id
3824 AND POLL.shipment_type in ('STANDARD','PLANNED')
3825 AND POD.line_location_id = POLL.line_location_id --bug 12572504
3826 AND PH1.po_header_id = POL.po_header_id
3827 AND POD.po_line_id = POLL.po_line_id
3828 AND Nvl(poll.consigned_flag,'N') <> 'Y';
3829
3830 ELSE -- (l_po_min unit IS NULL)
3831
3832 -- SQL What: calculate amount released from all lines across OU
3833 -- referencing this GC in GC currency
3834 -- SQL Why: This is the return value
3835 --<Complex Work R12>: added decode on value basis
3836
3837 --Bug# 5391346: Added Decode for currency match condition
3841 -- Bug# 13536418: Added hint to improve performance.
3838 --Also added a join with PO_HEADERS_ALL for rate in header of execution document
3839 --<BUG 10196605 Modified below sql to reduce performance issues>
3840 l_progress := '110';
3842 SELECT /*+ use_nl(POLL,POD,PH1) index(POLL PO_LINE_LOCATIONS_N1) index(PH1 PO_HEADERS_U1) */ NVL(
3843 SUM(
3844
3845 DECODE(PH.currency_code, PH1.currency_code,
3846 ROUND(
3847 DECODE(POLL.value_basis
3848 ,'FIXED PRICE',
3849 NVL(POD.amount_ordered, 0) -
3850 NVL(POD.amount_cancelled, 0)
3851 , 'RATE',
3852 NVL(POD.amount_ordered, 0)-
3853 NVL(POD.amount_cancelled, 0)
3854 , --Qty based
3855 (NVL(POD.quantity_ordered, 0) -
3856 NVL(POD.quantity_cancelled,0)
3857 ) * NVL(POLL.price_override, 0)
3858 )
3859
3860
3861 , l_po_precision ) ,
3862
3863 ROUND(
3864 DECODE(POLL.value_basis
3865 ,'FIXED PRICE',
3866 NVL(POD.amount_ordered, 0) -
3867 NVL(POD.amount_cancelled, 0)
3868 , 'RATE',
3869 NVL(POD.amount_ordered, 0)-
3870 NVL(POD.amount_cancelled, 0)
3871 , --Qty based
3872 (NVL(POD.quantity_ordered, 0) -
3873 NVL(POD.quantity_cancelled,0)
3874 ) * NVL(POLL.price_override, 0)
3875 )
3876
3877 * NVL(POD.rate, NVL(PH1.rate,1))
3878 /NVL(PH.rate,1)
3879
3880 , l_po_precision)
3881 )
3882 )
3883 ,0)
3884 INTO l_total
3885 FROM PO_DISTRIBUTIONS_ALL POD,
3886 PO_LINE_LOCATIONS_ALL POLL,
3887 PO_LINES_ALL POL,
3888 PO_HEADERS_ALL PH,
3889 PO_HEADERS_ALL PH1
3890 WHERE PH.po_header_id = p_po_header_id
3891 AND PH.po_header_id = POL.contract_id -- <GC FPJ>
3892 AND POL.po_line_id = POLL.po_line_id
3893 AND POLL.shipment_type in ('STANDARD','PLANNED')
3894 AND POD.line_location_id = POLL.line_location_id --bug 12572504
3895 AND PH1.po_header_id = POL.po_header_id
3896 AND POD.po_line_id = POLL.po_line_id
3897 AND Nvl(poll.consigned_flag,'N') <> 'Y';
3898
3899 END IF;
3900
3901 END IF;
3902
3903 IF g_debug_stmt THEN
3904 PO_DEBUG.debug_end(l_log_head);
3905 END IF;
3906
3907 --Bug# 5391346 END
3908
3909 RETURN l_total;
3910
3911 EXCEPTION
3912 WHEN OTHERS THEN
3913 PO_DEBUG.debug_exc(l_log_head,l_progress);
3914 RETURN 0;
3915 END get_gc_amount_released;
3916
3917 -- <GC FPJ END>
3918
3919 /* ===========================================================================
3920 PROCEDURE NAME : validate_lookup_info (
3921 p_lookup_rec IN OUT NOCOPY RCV_SHIPMENT_HEADER_SV.LookupRecType)
3922
3923 DESCRIPTION :
3924
3925 CLIENT/SERVER : SERVER
3926
3927 LIBRARY NAME :
3928
3929 OWNER : Raj Bhakta
3930
3931 PARAMETERS : p_lookup_rec IN OUT NOCOPY RCV_SHIPMENT_HEADER_SV.LookupRecType
3932
3933 ALGORITHM :
3934
3935 NOTES : Generic procedure which accepts the lookup record and
3936 returns error status and error message depending on
3937 business rules. The lookup record has type and code as
3938 components.
3939
3940 CHANGE HISTORY : Raj Bhakta 10/30/96 created
3941
3942 =========================================================================== */
3943
3944 PROCEDURE validate_lookup_info(
3945 p_lookup_rec IN OUT NOCOPY RCV_SHIPMENT_HEADER_SV.LookupRecType) IS
3946
3947
3948 cursor C is
3949 SELECT inactive_date
3950 FROM po_lookup_codes
3951 WHERE
3952 lookup_type = p_lookup_rec.lookup_type and
3953 lookup_code = p_lookup_rec.lookup_code;
3954
3955 X_sysdate Date := sysdate;
3956
3957 X_inactive_date po_lookup_codes.INACTIVE_DATE%TYPE;
3958
3959 BEGIN
3960
3961 OPEN C;
3962 FETCH C INTO X_inactive_date;
3963
3964 IF C%ROWCOUNT = 0 then
3965 CLOSE C;
3966 p_lookup_rec.error_record.error_status := 'E';
3967 p_lookup_rec.error_record.error_message := 'INVALID_LOOKUP';
3968 RETURN;
3969
3970 ELSE
3971
3972 IF X_sysdate > nvl(X_inactive_date,X_sysdate + 1) THEN
3973
3974 CLOSE C;
3975 p_lookup_rec.error_record.error_status := 'E';
3976 p_lookup_rec.error_record.error_message := 'INACTIVE_LOOKUP';
3977 RETURN;
3978 END IF;
3979
3980 LOOP
3981 FETCH C INTO X_inactive_date;
3982 IF C%NOTFOUND THEN
3983
3984 p_lookup_rec.error_record.error_status := 'S';
3985 p_lookup_rec.error_record.error_message := NULL;
3986 EXIT;
3987
3988 END IF;
3989 IF C%FOUND THEN
3990
3991 p_lookup_rec.error_record.error_status := 'E';
3992 p_lookup_rec.error_record.error_message := 'TOOMANYROWS';
3993 CLOSE C;
3994 EXIT;
3995
3996 END IF;
3997
3998 END LOOP;
3999
4000 END IF;
4001
4002 EXCEPTION
4003 WHEN others THEN
4004 p_lookup_rec.error_record.error_status := 'U';
4005 p_lookup_rec.error_record.error_message := sqlerrm;
4006
4007 END validate_lookup_info;
4008
4009
4010
4011
4012
4013 -------------------------------------------
4014 -- Document id helper procedures
4015 -------------------------------------------
4016
4017
4018
4019
4020 -------------------------------------------------------------------------------
4021 --Start of Comments
4022 --Name: get_document_ids
4023 --Pre-reqs:
4024 -- None.
4025 --Modifies:
4026 -- None.
4027 --Locks:
4028 -- None.
4029 --Function:
4030 -- Returns the header-level document id for the given ids.
4031 --Parameters:
4032 --IN:
4033 --p_doc_type
4034 -- Document type. Use the g_doc_type_<> variables, where <> is:
4035 -- REQUISITION
4036 -- PA
4037 -- PO
4038 -- RELEASE
4039 --p_doc_level
4040 -- The type of ids that are being passed. Use g_doc_level_<>
4041 -- HEADER
4042 -- LINE
4043 -- SHIPMENT
4044 -- DISTRIBUTION
4045 --p_doc_level_id_tbl
4046 -- Ids of the doc level type of which to derive the document header id.
4047 --OUT:
4048 --x_doc_id_tbl
4049 -- Header-level ids of the input ids.
4053 -------------------------------------------------------------------------------
4050 --Testing:
4051 --
4052 --End of Comments
4054 PROCEDURE get_document_ids(
4055 p_doc_type IN VARCHAR2
4056 , p_doc_level IN VARCHAR2
4057 , p_doc_level_id_tbl IN po_tbl_number
4058 , x_doc_id_tbl OUT NOCOPY po_tbl_number
4059 )
4060 IS
4061
4062 l_log_head CONSTANT VARCHAR2(100) := g_log_head||'GET_DOCUMENT_IDS';
4063 l_progress VARCHAR2(3) := '000';
4064
4065 l_id_key NUMBER;
4066
4067 -- Bug 3292870
4068 l_rowid_char_tbl g_rowid_char_tbl;
4069
4070 BEGIN
4071
4072 IF g_debug_stmt THEN
4073 PO_DEBUG.debug_begin(l_log_head);
4074 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_type', p_doc_type);
4075 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_level', p_doc_level);
4076 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_level_id_tbl', p_doc_level_id_tbl);
4077 END IF;
4078
4079 l_progress := '010';
4080
4081 IF (p_doc_level = g_doc_level_HEADER) THEN
4082
4083 l_progress := '020';
4084 IF g_debug_stmt THEN
4085 PO_DEBUG.debug_stmt(l_log_head,l_progress,'headers');
4086 END IF;
4087
4088 x_doc_id_tbl := p_doc_level_id_tbl;
4089
4090 ELSE
4091
4092 l_progress := '100';
4093 IF g_debug_stmt THEN
4094 PO_DEBUG.debug_stmt(l_log_head,l_progress,'not headers');
4095 END IF;
4096
4097 -- We need to get outthe header ids in the same ordering as the
4098 -- input id table.
4099 -- We can't do a FORALL ... SELECT (PL/SQL limitation),
4100 -- but we can to a FORALL ... INSERT ... RETURNING.
4101
4102 ----------------------------------------------------------------
4103 -- PO_SESSION_GT column mapping
4104 --
4105 -- num1 doc level id
4106 -- num2 header id of num1
4107 ----------------------------------------------------------------
4108
4109 l_id_key := get_session_gt_nextval();
4110
4111 l_progress := '110';
4112
4113 IF (p_doc_type = g_doc_type_REQUISITION) THEN
4114
4115 l_progress := '120';
4116 IF g_debug_stmt THEN
4117 PO_DEBUG.debug_stmt(l_log_head,l_progress,'requisition');
4118 END IF;
4119
4120 IF (p_doc_level = g_doc_level_LINE) THEN
4121
4122 l_progress := '130';
4123 IF g_debug_stmt THEN
4124 PO_DEBUG.debug_stmt(l_log_head,l_progress,'line');
4125 END IF;
4126
4127 /* Start Bug 3292870: Split query to make it compatible with 8i db. */
4128
4129 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4130 INSERT INTO PO_SESSION_GT ( key, num1 )
4131 VALUES
4132 ( l_id_key
4133 , p_doc_level_id_tbl(i)
4134 )
4135 RETURNING ROWIDTOCHAR(rowid)
4136 BULK COLLECT INTO l_rowid_char_tbl
4137 ;
4138
4139 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4140 UPDATE PO_SESSION_GT
4141 SET num2 =
4142 (
4143 SELECT PRL.requisition_header_id
4144 FROM PO_REQUISITION_LINES_ALL PRL
4145 WHERE PRL.requisition_line_id = p_doc_level_id_tbl(i)
4146 )
4147 WHERE rowid = CHARTOROWID(l_rowid_char_tbl(i))
4148 RETURNING num2
4149 BULK COLLECT INTO x_doc_id_tbl
4150 ;
4151
4152 /* End Bug 3292870 */
4153
4154 l_progress := '140';
4155
4156 ELSIF (p_doc_level = g_doc_level_DISTRIBUTION) THEN
4157
4158 l_progress := '150';
4159 IF g_debug_stmt THEN
4160 PO_DEBUG.debug_stmt(l_log_head,l_progress,'distribution');
4161 END IF;
4162
4163 /* Start Bug 3292870: Split query to make it compatible with 8i db. */
4164
4165 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4166 INSERT INTO PO_SESSION_GT ( key, num1 )
4167 VALUES
4168 ( l_id_key
4169 , p_doc_level_id_tbl(i)
4170 )
4171 RETURNING ROWIDTOCHAR(rowid)
4172 BULK COLLECT INTO l_rowid_char_tbl
4173 ;
4174
4175 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4176 UPDATE PO_SESSION_GT
4177 SET num2 =
4178 (
4179 SELECT PRL.requisition_header_id
4180 FROM
4181 PO_REQUISITION_LINES_ALL PRL
4182 , PO_REQ_DISTRIBUTIONS_ALL PRD
4183 WHERE PRL.requisition_line_id = PRD.requisition_line_id
4184 AND PRD.distribution_id = p_doc_level_id_tbl(i)
4185 )
4186 WHERE rowid = CHARTOROWID(l_rowid_char_tbl(i))
4187 RETURNING num2
4188 BULK COLLECT INTO x_doc_id_tbl
4189 ;
4190
4191 /* End Bug 3292870 */
4192
4193 l_progress := '160';
4194
4195 ELSE
4196 l_progress := '170';
4197 RAISE g_INVALID_CALL_EXC;
4198 END IF;
4199
4200 l_progress := '190';
4201
4202 ELSE -- PO, PA, RELEASE
4203
4204 l_progress := '200';
4205 IF g_debug_stmt THEN
4206 PO_DEBUG.debug_stmt(l_log_head,l_progress,'not req');
4207 END IF;
4208
4209 IF (p_doc_level = g_doc_level_LINE) THEN
4210
4214 END IF;
4211 l_progress := '210';
4212 IF g_debug_stmt THEN
4213 PO_DEBUG.debug_stmt(l_log_head,l_progress,'line');
4215
4216 /* Start Bug 3292870: Split query to make it compatible with 8i db. */
4217
4218 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4219 INSERT INTO PO_SESSION_GT ( key, num1 )
4220 VALUES
4221 ( l_id_key
4222 , p_doc_level_id_tbl(i)
4223 )
4224 RETURNING ROWIDTOCHAR(rowid)
4225 BULK COLLECT INTO l_rowid_char_tbl
4226 ;
4227
4228 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4229 UPDATE PO_SESSION_GT
4230 SET num2 =
4231 (
4232 SELECT POL.po_header_id
4233 FROM PO_LINES_ALL POL
4234 WHERE POL.po_line_id = p_doc_level_id_tbl(i)
4235 )
4236 WHERE rowid = CHARTOROWID(l_rowid_char_tbl(i))
4237 RETURNING num2
4238 BULK COLLECT INTO x_doc_id_tbl
4239 ;
4240
4241 /* End Bug 3292870 */
4242
4243 l_progress := '220';
4244
4245 ELSIF (p_doc_level = g_doc_level_SHIPMENT) THEN
4246
4247 l_progress := '230';
4248 IF g_debug_stmt THEN
4249 PO_DEBUG.debug_stmt(l_log_head,l_progress,'shipment');
4250 END IF;
4251
4252 /* Start Bug 3292870: Split query to make it compatible with 8i db. */
4253
4254 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4255 INSERT INTO PO_SESSION_GT ( key, num1 )
4256 VALUES
4257 ( l_id_key
4258 , p_doc_level_id_tbl(i)
4259 )
4260 RETURNING ROWIDTOCHAR(rowid)
4261 BULK COLLECT INTO l_rowid_char_tbl
4262 ;
4263
4264 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4265 UPDATE PO_SESSION_GT
4266 SET num2 =
4267 (
4268 SELECT DECODE( p_doc_type
4269 , g_doc_type_RELEASE, POLL.po_release_id
4270 , POLL.po_header_id
4271 )
4272 FROM PO_LINE_LOCATIONS_ALL POLL
4273 WHERE POLL.line_location_id = p_doc_level_id_tbl(i)
4274 )
4275 WHERE rowid = CHARTOROWID(l_rowid_char_tbl(i))
4276 RETURNING num2
4277 BULK COLLECT INTO x_doc_id_tbl
4278 ;
4279
4280 /* End Bug 3292870 */
4281
4282 l_progress := '240';
4283
4284 ELSIF (p_doc_level = g_doc_level_DISTRIBUTION) THEN
4285
4286 l_progress := '250';
4287 IF g_debug_stmt THEN
4288 PO_DEBUG.debug_stmt(l_log_head,l_progress,'distribution');
4289 END IF;
4290
4291 /* Start Bug 3292870: Split query to make it compatible with 8i db. */
4292
4293 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4294 INSERT INTO PO_SESSION_GT ( key, num1 )
4295 VALUES
4296 ( l_id_key
4297 , p_doc_level_id_tbl(i)
4298 )
4299 RETURNING ROWIDTOCHAR(rowid)
4300 BULK COLLECT INTO l_rowid_char_tbl
4301 ;
4302
4303 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4304 UPDATE PO_SESSION_GT
4305 SET num2 =
4306 (
4307 SELECT DECODE( p_doc_type
4308 , g_doc_type_RELEASE, POD.po_release_id
4309 , POD.po_header_id
4310 )
4311 FROM PO_DISTRIBUTIONS_ALL POD
4312 WHERE POD.po_distribution_id = p_doc_level_id_tbl(i)
4313 )
4314 WHERE rowid = CHARTOROWID(l_rowid_char_tbl(i))
4315 RETURNING num2
4316 BULK COLLECT INTO x_doc_id_tbl
4317 ;
4318
4319 /* End Bug 3292870 */
4320
4321 l_progress := '260';
4322
4323 ELSE
4324 l_progress := '270';
4325 RAISE g_INVALID_CALL_EXC;
4326 END IF;
4327
4328 l_progress := '280';
4329
4330 END IF;
4331
4332 l_progress := '290';
4333
4334 END IF;
4335
4336 l_progress := '900';
4337
4338 IF g_debug_stmt THEN
4339 PO_DEBUG.debug_var(l_log_head,l_progress,'x_doc_id_tbl',x_doc_id_tbl);
4340 PO_DEBUG.debug_end(l_log_head);
4341 END IF;
4342
4343 EXCEPTION
4344 WHEN OTHERS THEN
4345 IF g_debug_unexp THEN
4346 PO_DEBUG.debug_exc(l_log_head,l_progress);
4347 END IF;
4348 RAISE;
4349
4350 END get_document_ids;
4351
4352 -- <Bug 9909408> Overloaded procedure
4353 PROCEDURE get_line_ids(
4354 p_doc_type IN VARCHAR2
4355 , p_doc_level IN VARCHAR2
4356 , p_doc_level_id_tbl IN po_tbl_number
4357 , x_line_id_tbl OUT NOCOPY po_tbl_number
4358 )
4359 IS
4360 BEGIN
4361 get_line_ids(
4362 p_doc_type => p_doc_type,
4363 p_doc_level => p_doc_level,
4364 p_doc_level_id_tbl => p_doc_level_id_tbl,
4365 p_draft_id => -1,
4366 x_line_id_tbl => x_line_id_tbl
4367 );
4368 END get_line_ids;
4369
4370 -------------------------------------------------------------------------------
4374 -- None.
4371 --Start of Comments
4372 --Name: get_line_ids
4373 --Pre-reqs:
4375 --Modifies:
4376 -- None.
4377 --Locks:
4378 -- None.
4379 --Function:
4380 -- Returns the line-level ids for the given ids.
4381 --Parameters:
4382 --IN:
4383 --p_doc_type
4384 -- Document type. Use the g_doc_type_<> variables, where <> is:
4385 -- REQUISITION
4386 -- PA
4387 -- PO
4388 -- RELEASE
4389 --p_doc_level
4390 -- The type of ids that are being passed. Use g_doc_level_<>
4391 -- HEADER
4392 -- LINE
4393 -- SHIPMENT
4394 -- DISTRIBUTION
4395 --p_doc_level_id_tbl
4396 -- Ids of the doc level type of which to derive the document header id.
4397 --OUT:
4398 --x_line_id_tbl
4399 -- Line-level ids of the input ids.
4400 --Testing:
4401 --
4402 --End of Comments
4403 -------------------------------------------------------------------------------
4404 PROCEDURE get_line_ids(
4405 p_doc_type IN VARCHAR2
4406 , p_doc_level IN VARCHAR2
4407 , p_doc_level_id_tbl IN po_tbl_number
4408 , p_draft_id IN NUMBER -- <Bug 9909408>
4409 , x_line_id_tbl OUT NOCOPY po_tbl_number
4410 )
4411 IS
4412
4413 l_log_head CONSTANT VARCHAR2(100) := g_log_head||'GET_LINE_IDS';
4414 l_progress VARCHAR2(3) := '000';
4415
4416 l_id_key NUMBER;
4417
4418 --Bug 3292870
4419 l_rowid_char_tbl g_rowid_char_tbl;
4420
4421 BEGIN
4422
4423 IF g_debug_stmt THEN
4424 PO_DEBUG.debug_begin(l_log_head);
4425 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_type', p_doc_type);
4426 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_level', p_doc_level);
4427 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_level_id_tbl', p_doc_level_id_tbl);
4428 END IF;
4429
4430 l_progress := '010';
4431
4432 IF (p_doc_level = g_doc_level_LINE) THEN
4433
4434 l_progress := '020';
4435 IF g_debug_stmt THEN
4436 PO_DEBUG.debug_stmt(l_log_head,l_progress,'lines');
4437 END IF;
4438
4439 x_line_id_tbl := p_doc_level_id_tbl;
4440
4441 ELSIF (p_doc_level = g_doc_level_HEADER) THEN
4442
4443 l_progress := '100';
4444 IF g_debug_stmt THEN
4445 PO_DEBUG.debug_stmt(l_log_head,l_progress,'headers');
4446 END IF;
4447
4448 ----------------------------------------------------
4449 --Algorithm:
4450 --
4451 -- 1. Load the ids into the scratchpad.
4452 -- 2. Join to the appropriate tables to bulk collect the line ids.
4453 ----------------------------------------------------
4454
4455 ---------------------------------------
4456 -- PO_SESSION_GT column mapping
4457 --
4458 -- num1 doc_level_id
4459 ---------------------------------------
4460
4461 l_id_key := get_session_gt_nextval();
4462
4463 l_progress := '110';
4464
4465 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4466 INSERT INTO PO_SESSION_GT ( key, num1 )
4467 VALUES ( l_id_key, p_doc_level_id_tbl(i) )
4468 ;
4469
4470 l_progress := '120';
4471
4472 IF (p_doc_type = g_doc_type_REQUISITION) THEN
4473
4474 l_progress := '130';
4475 IF g_debug_stmt THEN
4476 PO_DEBUG.debug_stmt(l_log_head,l_progress,'req headers');
4477 END IF;
4478
4479 -- Gather all of the req line ids below this entity level.
4480
4481 SELECT PRL.requisition_line_id
4482 BULK COLLECT INTO x_line_id_tbl
4483 FROM
4484 PO_REQUISITION_LINES_ALL PRL
4485 , PO_SESSION_GT IDS
4486 WHERE PRL.requisition_header_id = IDS.num1
4487 AND IDS.key = l_id_key
4488 ;
4489
4490 l_progress := '140';
4491
4492 ELSIF (p_doc_type IN (g_doc_type_PO, g_doc_type_PA)) THEN
4493
4494 l_progress := '150';
4495 IF g_debug_stmt THEN
4496 PO_DEBUG.debug_stmt(l_log_head,l_progress,'po/pa headers');
4497 END IF;
4498
4499 -- Gather all of the line ids below this entity level.
4500
4501 SELECT POL.po_line_id
4502 BULK COLLECT INTO x_line_id_tbl
4503 FROM
4504 PO_LINES_MERGE_V POL -- <Bug 9909408> replaced PO_LINES_ALL
4505 , PO_SESSION_GT IDS
4506 WHERE POL.po_header_id = IDS.num1
4507 AND POL.draft_id = p_draft_id
4508 AND IDS.key = l_id_key
4509 ;
4510
4511 l_progress := '160';
4512
4513 ELSE
4514 l_progress := '180';
4515 RAISE g_INVALID_CALL_EXC;
4516 END IF;
4517
4518 l_progress := '190';
4519
4520 ELSIF (p_doc_level = g_doc_level_SHIPMENT
4521 AND p_doc_type IN (g_doc_type_PO, g_doc_type_PA, g_doc_type_RELEASE))
4522 THEN
4523
4524 l_progress := '200';
4525 IF g_debug_stmt THEN
4526 PO_DEBUG.debug_stmt(l_log_head,l_progress,'shipments');
4527 END IF;
4528
4529 -- We need to get out the line ids in the same ordering as the
4530 -- input id table.
4531 -- We can't do a FORALL ... SELECT (PL/SQL limitation),
4532 -- but we can to a FORALL ... INSERT ... RETURNING.
4533
4534 ----------------------------------------------------------------
4535 -- PO_SESSION_GT column mapping
4536 --
4537 -- num1 doc level id
4538 -- num2 line id of num1
4539 ----------------------------------------------------------------
4540
4541 l_id_key := get_session_gt_nextval();
4542
4546
4543 l_progress := '210';
4544
4545 /* Start Bug 3292870: Split query to make it compatible with 8i db. */
4547 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4548 INSERT INTO PO_SESSION_GT ( key, num1 )
4549 VALUES
4550 ( l_id_key
4551 , p_doc_level_id_tbl(i)
4552 )
4553 RETURNING ROWIDTOCHAR(rowid)
4554 BULK COLLECT INTO l_rowid_char_tbl
4555 ;
4556
4557 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4558 UPDATE PO_SESSION_GT
4559 SET num2 =
4560 (
4561 SELECT POLL.po_line_id
4562 FROM PO_LINE_LOCATIONS_MERGE_V POLL -- <Bug 9909408> replaced PO_LINE_LOCATIONS_ALL
4563 WHERE POLL.line_location_id = p_doc_level_id_tbl(i)
4564 AND POLL.draft_id = p_draft_id
4565 )
4566 WHERE rowid = CHARTOROWID(l_rowid_char_tbl(i))
4567 RETURNING num2
4568 BULK COLLECT INTO x_line_id_tbl
4569 ;
4570
4571 /* End Bug 3292870 */
4572
4573 l_progress := '220';
4574
4575 ELSIF (p_doc_level = g_doc_level_DISTRIBUTION) THEN
4576
4577 l_progress := '300';
4578 IF g_debug_stmt THEN
4579 PO_DEBUG.debug_stmt(l_log_head,l_progress,'distributions');
4580 END IF;
4581
4582 -- We need to get out the line ids in the same ordering as the
4583 -- input id table.
4584 -- We can't do a FORALL ... SELECT (PL/SQL limitation),
4585 -- but we can to a FORALL ... INSERT ... RETURNING.
4586
4587 ----------------------------------------------------------------
4588 -- PO_SESSION_GT column mapping
4589 --
4590 -- num1 doc level id
4591 -- num2 line id of num1
4592 ----------------------------------------------------------------
4593
4594 l_id_key := get_session_gt_nextval();
4595
4596 l_progress := '310';
4597
4598 IF (p_doc_type = g_doc_type_REQUISITION) THEN
4599
4600 l_progress := '320';
4601 IF g_debug_stmt THEN
4602 PO_DEBUG.debug_stmt(l_log_head,l_progress,'req');
4603 END IF;
4604
4605 /* Start Bug 3292870: Split query to make it compatible with 8i db. */
4606
4607 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4608 INSERT INTO PO_SESSION_GT ( key, num1 )
4609 VALUES
4610 ( l_id_key
4611 , p_doc_level_id_tbl(i)
4612 )
4613 RETURNING ROWIDTOCHAR(rowid)
4614 BULK COLLECT INTO l_rowid_char_tbl
4615 ;
4616
4617 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4618 UPDATE PO_SESSION_GT
4619 SET num2 =
4620 (
4621 SELECT PRD.requisition_line_id
4622 FROM PO_REQ_DISTRIBUTIONS_ALL PRD
4623 WHERE PRD.distribution_id = p_doc_level_id_tbl(i)
4624 )
4625 WHERE rowid = CHARTOROWID(l_rowid_char_tbl(i))
4626 RETURNING num2
4627 BULK COLLECT INTO x_line_id_tbl
4628 ;
4629
4630 /* End Bug 3292870 */
4631
4632 l_progress := '330';
4633
4634 ELSE
4635
4636 l_progress := '340';
4637 IF g_debug_stmt THEN
4638 PO_DEBUG.debug_stmt(l_log_head,l_progress,'not req');
4639 END IF;
4640
4641 /* Start Bug 3292870: Split query to make it compatible with 8i db. */
4642
4643 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4644 INSERT INTO PO_SESSION_GT ( key, num1 )
4645 VALUES
4646 ( l_id_key
4647 , p_doc_level_id_tbl(i)
4648 )
4649 RETURNING ROWIDTOCHAR(rowid)
4650 BULK COLLECT INTO l_rowid_char_tbl
4651 ;
4652
4653 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4654 UPDATE PO_SESSION_GT
4655 SET num2 =
4656 (
4657 SELECT POD.po_line_id
4658 FROM PO_DISTRIBUTIONS_MERGE_V POD -- <Bug 9909408> replaced PO_DISTRIBUTIONS_ALL
4659 WHERE POD.po_distribution_id = p_doc_level_id_tbl(i)
4660 AND POD.draft_id = p_draft_id
4661 )
4662 WHERE rowid = CHARTOROWID(l_rowid_char_tbl(i))
4663 RETURNING num2
4664 BULK COLLECT INTO x_line_id_tbl
4665 ;
4666
4667 /* End Bug 3292870 */
4668
4669 l_progress := '350';
4670
4671 END IF;
4672
4673 l_progress := '370';
4674
4675 ELSE
4676 l_progress := '390';
4677 RAISE g_INVALID_CALL_EXC;
4678 END IF;
4679
4680 l_progress := '900';
4681
4682 IF g_debug_stmt THEN
4683 PO_DEBUG.debug_var(l_log_head,l_progress,'x_line_id_tbl',x_line_id_tbl);
4684 PO_DEBUG.debug_end(l_log_head);
4685 END IF;
4686
4687 EXCEPTION
4688 WHEN OTHERS THEN
4689 IF g_debug_unexp THEN
4690 PO_DEBUG.debug_exc(l_log_head,l_progress);
4691 END IF;
4692 RAISE;
4693
4694 END get_line_ids;
4695
4696
4697 -- <Bug 9909408> Overloaded procedure
4698 PROCEDURE get_line_location_ids(
4699 p_doc_type IN VARCHAR2
4700 , p_doc_level IN VARCHAR2
4701 , p_doc_level_id_tbl IN po_tbl_number
4702 , x_line_location_id_tbl OUT NOCOPY po_tbl_number
4703 )
4704 IS
4705 BEGIN
4706 get_line_location_ids(
4707 p_doc_type => p_doc_type,
4708 p_doc_level => p_doc_level,
4709 p_doc_level_id_tbl => p_doc_level_id_tbl,
4710 p_draft_id => -1,
4711 x_line_location_id_tbl => x_line_location_id_tbl
4712 );
4713 END get_line_location_ids;
4714
4718 --Pre-reqs:
4715 -------------------------------------------------------------------------------
4716 --Start of Comments
4717 --Name: get_line_location_ids
4719 -- None.
4720 --Modifies:
4721 -- None.
4722 --Locks:
4723 -- None.
4724 --Function:
4725 -- Retrieves the ids of shipments corresponding to the given doc level.
4726 --Parameters:
4727 --IN:
4728 --p_doc_type
4729 -- Document type. Use the g_doc_type_<> variables, where <> is:
4730 -- PO
4731 -- PA
4732 -- RELEASE
4733 -- - REQUISITION not currently supported.
4734 --p_doc_level
4735 -- The type of ids that are being passed. Use g_doc_level_<>
4736 -- HEADER
4737 -- LINE
4738 -- SHIPMENT
4739 -- DISTRIBUTION
4740 --p_doc_level_id_tbl
4741 -- Ids of the doc level type with which to find related shipments.
4742 --OUT:
4743 --x_line_location_id_tbl
4744 -- The ids of the related shipments that were found.
4745 -- If p_doc_level is DISTRIBUTION, the entries in this table
4746 -- will map one-to-one to the input id table.
4747 --Testing:
4748 --
4749 --End of Comments
4750 -------------------------------------------------------------------------------
4751 PROCEDURE get_line_location_ids(
4752 p_doc_type IN VARCHAR2
4753 , p_doc_level IN VARCHAR2
4754 , p_doc_level_id_tbl IN po_tbl_number
4755 , p_draft_id IN NUMBER -- <Bug 9909408>
4756 , x_line_location_id_tbl OUT NOCOPY po_tbl_number
4757 )
4758 IS
4759
4760 l_log_head CONSTANT VARCHAR2(100) := g_log_head||'GET_LINE_LOCATION_IDS';
4761 l_progress VARCHAR2(3) := '000';
4762
4763 l_doc_level_id_key NUMBER;
4764
4765 -- Bug 3292870
4766 l_rowid_char_tbl g_rowid_char_tbl;
4767
4768 BEGIN
4769
4770 IF g_debug_stmt THEN
4771 PO_DEBUG.debug_begin(l_log_head);
4772 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_type', p_doc_type);
4773 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_level', p_doc_level);
4774 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_level_id_tbl', p_doc_level_id_tbl);
4775 END IF;
4776
4777 l_progress := '010';
4778
4779 -----------------------------------------------------------------
4780 --Algorithm:
4781 --
4782 -- - Insert the doc level ids into the scratchpad table.
4783 -- - Join to the main doc tables against these doc level ids
4784 -- to retrieve the linked line location ids.
4785 -----------------------------------------------------------------
4786
4787 IF (p_doc_level = g_doc_level_SHIPMENT) THEN
4788
4789 l_progress := '100';
4790 IF g_debug_stmt THEN
4791 PO_DEBUG.debug_stmt(l_log_head,l_progress,'shipments');
4792 END IF;
4793
4794 x_line_location_id_tbl := p_doc_level_id_tbl;
4795
4796 ELSE
4797
4798 l_progress := '200';
4799 IF g_debug_stmt THEN
4800 PO_DEBUG.debug_stmt(l_log_head,l_progress,'not shipments');
4801 END IF;
4802
4803 -- Load the entity ids into the scratchpad.
4804
4805 ---------------------------------------
4806 -- PO_SESSION_GT column mapping
4807 --
4808 -- num1 document_level_id
4809 ---------------------------------------
4810
4811 l_doc_level_id_key := get_session_gt_nextval();
4812
4813 l_progress := '210';
4814
4815 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4816 INSERT INTO PO_SESSION_GT ( key, num1 )
4817 VALUES ( l_doc_level_id_key, p_doc_level_id_tbl(i) )
4818 ;
4819
4820 l_progress := '220';
4821
4822 -- We need to derive the appropriate line location ids for the given
4823 -- entity id and entity level.
4824
4825 -- NOT SUPPORTED FOR REQUISITIONS
4826
4827 IF ( p_doc_type = g_doc_type_RELEASE
4828 AND p_doc_level = g_doc_level_HEADER)
4829 THEN
4830
4831 l_progress := '410';
4832 IF g_debug_stmt THEN
4833 PO_DEBUG.debug_stmt(l_log_head,l_progress,'release');
4834 END IF;
4835
4836 SELECT POLL.line_location_id
4837 BULK COLLECT INTO x_line_location_id_tbl
4838 FROM
4839 PO_LINE_LOCATIONS_ALL POLL
4840 , PO_SESSION_GT IDS
4841 WHERE POLL.po_release_id = IDS.num1
4842 AND IDS.key = l_doc_level_id_key
4843 ;
4844
4845 l_progress := '420';
4846
4847 ELSIF (p_doc_level = g_doc_level_HEADER) THEN
4848
4849 l_progress := '430';
4850 IF g_debug_stmt THEN
4851 PO_DEBUG.debug_stmt(l_log_head,l_progress,'headers');
4852 END IF;
4853
4854 SELECT POLL.line_location_id
4855 BULK COLLECT INTO x_line_location_id_tbl
4856 FROM
4857 PO_LINE_LOCATIONS_MERGE_V POLL -- <Bug 9909408> replaced PO_LINE_LOCATIONS_ALL
4858 , PO_SESSION_GT IDS
4859 WHERE POLL.po_header_id = IDS.num1
4860 and POLL.draft_id = p_draft_id
4861 AND POLL.shipment_type <> g_ship_type_SCHEDULED
4862 AND POLL.shipment_type <> g_ship_type_BLANKET
4863 -- don't pick up release shipments for POs/PAs
4864 AND IDS.key = l_doc_level_id_key
4865 ;
4866
4867 l_progress := '440';
4868
4869 ELSIF (p_doc_level = g_doc_level_LINE) THEN
4870
4871 l_progress := '450';
4872 IF g_debug_stmt THEN
4873 PO_DEBUG.debug_stmt(l_log_head,l_progress,'lines');
4874 END IF;
4875
4876 SELECT POLL.line_location_id
4877 BULK COLLECT INTO x_line_location_id_tbl
4878 FROM
4879 PO_LINE_LOCATIONS_MERGE_V POLL -- <Bug 9909408> replaced PO_LINE_LOCATIONS_ALL
4880 , PO_SESSION_GT IDS
4881 WHERE POLL.po_line_id = IDS.num1
4882 and POLL.draft_id = p_draft_id
4883 AND POLL.shipment_type <> g_ship_type_SCHEDULED
4884 AND POLL.shipment_type <> g_ship_type_BLANKET
4885 -- don't pick up release shipments for POs/PAs
4886 AND IDS.key = l_doc_level_id_key
4887 ;
4888
4889 l_progress := '460';
4890
4891 ELSIF (p_doc_level = g_doc_level_DISTRIBUTION) THEN
4892
4893 -- We need to get out the header ids in the same ordering as the
4894 -- input id table.
4895 -- We can't do a FORALL ... SELECT (PL/SQL limitation),
4896 -- but we can to a FORALL ... INSERT ... RETURNING.
4897
4898 ----------------------------------------------------------------
4899 -- PO_SESSION_GT column mapping
4900 --
4901 -- num1 doc level id
4902 -- num2 line location id of num1
4903 ----------------------------------------------------------------
4904
4905 l_progress := '470';
4906 IF g_debug_stmt THEN
4907 PO_DEBUG.debug_stmt(l_log_head,l_progress,'distributions');
4908 END IF;
4909
4910 /* Start Bug 3292870: Split query to make it compatible with 8i db. */
4911
4912 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4913 INSERT INTO PO_SESSION_GT ( key, num1 )
4914 VALUES
4915 ( l_doc_level_id_key
4916 , p_doc_level_id_tbl(i)
4917 )
4918 RETURNING ROWIDTOCHAR(rowid)
4919 BULK COLLECT INTO l_rowid_char_tbl
4920 ;
4921
4922 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
4923 UPDATE PO_SESSION_GT
4924 SET num2 =
4925 (
4926 SELECT POD.line_location_id
4927 FROM PO_DISTRIBUTIONS_MERGE_V POD -- <Bug 9909408> replaced PO_DISTRIBUTIONS_ALL
4928 WHERE POD.po_distribution_id = p_doc_level_id_tbl(i)
4929 AND POD.draft_id = p_draft_id
4930 )
4931 WHERE rowid = CHARTOROWID(l_rowid_char_tbl(i))
4932 RETURNING num2
4933 BULK COLLECT INTO x_line_location_id_tbl
4934 ;
4935
4936 /* End Bug 3292870 */
4937
4938 l_progress := '480';
4939
4940 ELSE
4941 l_progress := '490';
4942 RAISE g_INVALID_CALL_EXC;
4943 END IF;
4944
4945 l_progress := '500';
4946
4947 END IF;
4948
4949 l_progress := '900';
4950
4951 IF g_debug_stmt THEN
4952 PO_DEBUG.debug_var(l_log_head,l_progress,'x_line_location_id_tbl',x_line_location_id_tbl);
4953 PO_DEBUG.debug_end(l_log_head);
4954 END IF;
4955
4956 EXCEPTION
4957 WHEN OTHERS THEN
4958 IF g_debug_unexp THEN
4959 PO_DEBUG.debug_exc(l_log_head,l_progress);
4960 END IF;
4961 RAISE;
4962
4963 END get_line_location_ids;
4964
4965
4966 PROCEDURE get_distribution_ids(
4967 p_doc_type IN VARCHAR2
4968 , p_doc_level IN VARCHAR2
4969 , p_doc_level_id_tbl IN po_tbl_number
4970 , x_distribution_id_tbl OUT NOCOPY po_tbl_number
4971 )
4972 IS
4973 BEGIN
4974 get_distribution_ids(
4975 p_doc_type => p_doc_type,
4976 p_doc_level => p_doc_level,
4977 p_doc_level_id_tbl => p_doc_level_id_tbl,
4978 p_draft_id => -1,
4979 x_distribution_id_tbl => x_distribution_id_tbl
4980 );
4981 END get_distribution_ids;
4982
4983 -------------------------------------------------------------------------------
4984 --Start of Comments
4985 --Name: get_distribution_ids
4986 --Pre-reqs:
4987 -- None.
4988 --Modifies:
4989 -- None.
4990 --Locks:
4991 -- None.
4992 --Function:
4993 -- Retrieves the ids of distributions below the given doc level.
4994 --Parameters:
4995 --IN:
4996 --p_doc_type
4997 -- Document type. Use the g_doc_type_<> variables, where <> is:
4998 -- REQUISITION
4999 -- PA
5000 -- PO
5001 -- RELEASE
5002 --p_doc_level
5003 -- The type of ids that are being passed. Use g_doc_level_<>
5004 -- HEADER
5005 -- LINE
5006 -- SHIPMENT
5007 -- DISTRIBUTION
5008 --p_doc_level_id_tbl
5009 -- Ids of the doc level type with which to find related distributions.
5010 --OUT:
5011 --x_dist_id_tbl
5012 -- The ids of the related distributions that were found.
5013 --Testing:
5014 --
5015 --End of Comments
5016 -------------------------------------------------------------------------------
5017 PROCEDURE get_distribution_ids(
5018 p_doc_type IN VARCHAR2
5019 , p_doc_level IN VARCHAR2
5020 , p_doc_level_id_tbl IN po_tbl_number
5021 , p_draft_id IN NUMBER -- <Bug 9909408>
5022 , x_distribution_id_tbl OUT NOCOPY po_tbl_number
5023 )
5024 IS
5025
5026 l_log_head CONSTANT VARCHAR2(100) := g_log_head||'GET_DISTRIBUTION_IDS';
5027 l_progress VARCHAR2(3) := '000';
5028
5029 l_doc_level_id_key NUMBER;
5030
5031 BEGIN
5032
5033 IF g_debug_stmt THEN
5034 PO_DEBUG.debug_begin(l_log_head);
5035 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_type', p_doc_type);
5036 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_level', p_doc_level);
5037 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_level_id_tbl', p_doc_level_id_tbl);
5038 END IF;
5039
5040 l_progress := '010';
5041
5042 -----------------------------------------------------------------
5043 --Algorithm:
5044 --
5045 -- - Insert the doc level ids into the scratchpad table.
5046 -- - Join to the main doc tables against these doc level ids
5047 -- to retrieve the linked distribution ids.
5048 -----------------------------------------------------------------
5049
5050 IF (p_doc_level = g_doc_level_DISTRIBUTION) THEN
5051
5052 l_progress := '100';
5053 IF g_debug_stmt THEN
5054 PO_DEBUG.debug_stmt(l_log_head,l_progress,'distributions');
5055 END IF;
5056
5057 x_distribution_id_tbl := p_doc_level_id_tbl;
5058
5059 ELSE
5060
5061 l_progress := '200';
5062 IF g_debug_stmt THEN
5063 PO_DEBUG.debug_stmt(l_log_head,l_progress,'not dists');
5064 END IF;
5065
5066 -- Load the entity ids into the scratchpad.
5067
5068 ---------------------------------------
5069 -- PO_SESSION_GT column mapping
5073
5070 --
5071 -- num1 document_level_id
5072 ---------------------------------------
5074 l_doc_level_id_key := get_session_gt_nextval();
5075
5076 l_progress := '210';
5077
5078 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
5079 INSERT INTO PO_SESSION_GT ( key, num1 )
5080 VALUES ( l_doc_level_id_key, p_doc_level_id_tbl(i) )
5081 ;
5082
5083 l_progress := '220';
5084
5085 -- We need to derive the appropriate distribution ids for the given
5086 -- entity id and entity level.
5087
5088 IF (p_doc_type = g_doc_type_REQUISITION) THEN
5089
5090 l_progress := '300';
5091 IF g_debug_stmt THEN
5092 PO_DEBUG.debug_stmt(l_log_head,l_progress,'requisition');
5093 END IF;
5094
5095 -- Gather all of the req distribution ids below this entity level.
5096
5097 IF (p_doc_level = g_doc_level_HEADER) THEN
5098
5099 l_progress := '310';
5100 IF g_debug_stmt THEN
5101 PO_DEBUG.debug_stmt(l_log_head,l_progress,'headers');
5102 END IF;
5103
5104 SELECT PRD.distribution_id
5105 BULK COLLECT INTO x_distribution_id_tbl
5106 FROM
5107 PO_REQUISITION_LINES_ALL PRL
5108 , PO_REQ_DISTRIBUTIONS_ALL PRD
5109 , PO_SESSION_GT IDS
5110 WHERE PRL.requisition_header_id = IDS.num1
5111 AND PRD.requisition_line_id = PRL.requisition_line_id
5112 AND IDS.key = l_doc_level_id_key
5113 ;
5114
5115 l_progress := '320';
5116
5117 ELSIF (p_doc_level = g_doc_level_LINE) THEN
5118
5119 l_progress := '330';
5120 IF g_debug_stmt THEN
5121 PO_DEBUG.debug_stmt(l_log_head,l_progress,'lines');
5122 END IF;
5123
5124 SELECT PRD.distribution_id
5125 BULK COLLECT INTO x_distribution_id_tbl
5126 FROM
5127 PO_REQ_DISTRIBUTIONS_ALL PRD
5128 , PO_SESSION_GT IDS
5129 WHERE PRD.requisition_line_id = IDS.num1
5130 AND IDS.key = l_doc_level_id_key
5131 ;
5132
5133 l_progress := '340';
5134
5135 ELSE
5136 l_progress := '370';
5137 RAISE g_INVALID_CALL_EXC;
5138 END IF;
5139
5140 l_progress := '390';
5141
5142 ELSE -- PO, PA, Release, etc.
5143
5144 l_progress := '400';
5145 IF g_debug_stmt THEN
5146 PO_DEBUG.debug_stmt(l_log_head,l_progress,'not req');
5147 END IF;
5148
5149 -- Gather all of the distribution ids below this entity level.
5150
5151 IF ( p_doc_type = g_doc_type_RELEASE
5152 AND p_doc_level = g_doc_level_HEADER
5153 )
5154 THEN
5155
5156 l_progress := '410';
5157 IF g_debug_stmt THEN
5158 PO_DEBUG.debug_stmt(l_log_head,l_progress,'release');
5159 END IF;
5160
5161 SELECT POD.po_distribution_id
5162 BULK COLLECT INTO x_distribution_id_tbl
5163 FROM
5164 PO_DISTRIBUTIONS_ALL POD
5165 , PO_SESSION_GT IDS
5166 WHERE POD.po_release_id = IDS.num1
5167 AND IDS.key = l_doc_level_id_key
5168 ;
5169
5170 l_progress := '420';
5171
5172 ELSIF (p_doc_level = g_doc_level_HEADER) THEN
5173
5174 l_progress := '430';
5175 IF g_debug_stmt THEN
5176 PO_DEBUG.debug_stmt(l_log_head,l_progress,'headers');
5177 END IF;
5178
5179 SELECT POD.po_distribution_id
5180 BULK COLLECT INTO x_distribution_id_tbl
5181 FROM
5182 PO_DISTRIBUTIONS_MERGE_V POD -- <Bug 9909408> replaced PO_DISTRIBUTIONS_ALL
5183 , PO_SESSION_GT IDS
5184 WHERE POD.po_header_id = IDS.num1
5185 AND POD.draft_id = p_draft_id
5186 AND POD.po_release_id IS NULL
5187 -- Don't pick up Release distributions when acting on a PPO/BPA/GA.
5188 -- Not using distribution_type due to dependency issues.
5189 AND IDS.key = l_doc_level_id_key
5190 ;
5191
5192 l_progress := '440';
5193
5194 ELSIF (p_doc_level = g_doc_level_LINE) THEN
5195
5196 l_progress := '450';
5197 IF g_debug_stmt THEN
5198 PO_DEBUG.debug_stmt(l_log_head,l_progress,'lines');
5199 END IF;
5200
5201 SELECT POD.po_distribution_id
5202 BULK COLLECT INTO x_distribution_id_tbl
5203 FROM
5204 PO_DISTRIBUTIONS_MERGE_V POD -- <Bug 9909408> replaced PO_DISTRIBUTIONS_ALL
5205 , PO_SESSION_GT IDS
5206 WHERE POD.po_line_id = IDS.num1
5207 AND POD.draft_id = p_draft_id
5208 AND POD.po_release_id IS NULL
5209 -- Don't pick up SR distributions when acting on a PPO.
5210 -- Not using distribution_type due to dependency issues.
5211 AND IDS.key = l_doc_level_id_key
5212 ;
5213
5214 l_progress := '460';
5215
5216 ELSIF (p_doc_level = g_doc_level_SHIPMENT) THEN
5217
5218 l_progress := '470';
5219 IF g_debug_stmt THEN
5220 PO_DEBUG.debug_stmt(l_log_head,l_progress,'shipments');
5221 END IF;
5222
5223 SELECT POD.po_distribution_id
5224 BULK COLLECT INTO x_distribution_id_tbl
5225 FROM
5226 PO_DISTRIBUTIONS_MERGE_V POD -- <Bug 9909408> replaced PO_DISTRIBUTIONS_ALL
5227 , PO_SESSION_GT IDS
5228 WHERE POD.line_location_id = IDS.num1
5232
5229 AND POD.draft_id = p_draft_id
5230 AND IDS.key = l_doc_level_id_key
5231 ;
5233 l_progress := '480';
5234
5235 ELSE
5236 l_progress := '490';
5237 RAISE g_INVALID_CALL_EXC;
5238 END IF;
5239
5240 l_progress := '500';
5241
5242 END IF; -- Req vs. PO/PA/Release
5243
5244 l_progress := '600';
5245
5246 END IF; -- entity type <> DISTRIBUTION
5247
5248 l_progress := '900';
5249
5250 IF g_debug_stmt THEN
5251 PO_DEBUG.debug_var(l_log_head,l_progress,'x_distribution_id_tbl',x_distribution_id_tbl);
5252 PO_DEBUG.debug_end(l_log_head);
5253 END IF;
5254
5255 EXCEPTION
5256 WHEN OTHERS THEN
5257 IF g_debug_unexp THEN
5258 PO_DEBUG.debug_exc(l_log_head,l_progress);
5259 END IF;
5260 RAISE;
5261
5262 END get_distribution_ids;
5263
5264
5265 --<Complex Work R12 START>
5266 -------------------------------------------------------------------------------
5267 --Start of Comments
5268 --Name: get_dist_ids_from_archive
5269 --Pre-reqs:
5270 -- None.
5271 --Modifies:
5272 -- None.
5273 --Locks:
5274 -- None.
5275 --Function:
5276 -- Retrieves the ids of distributions below the given doc level for a
5277 -- particular revision of the document from the archive tables
5278 --Parameters:
5279 --IN:
5280 --p_doc_type
5281 -- Document type. Use the g_doc_type_<> variables, where <> is:
5282 -- PO
5283 -- RELEASE
5284 --p_doc_level
5285 -- The type of ids that are being passed. Use g_doc_level_<>
5286 -- HEADER
5287 -- LINE
5288 -- SHIPMENT
5289 -- DISTRIBUTION
5290 --p_doc_level_id_tbl
5291 -- Ids of the doc level type with which to find related distributions.
5292 --p_doc_revision_num
5293 -- The revision number of the header in the archive table.
5294 -- If this parameter is passed as null, the latest version in the table
5295 -- is assumed
5296 --OUT:
5297 --x_distribution_id_tbl
5298 -- The ids of the related distributions that were found.
5299 --x_distribution_rev_num_tbl
5300 -- The revision number of the distribution rows in the archive table
5301 --Testing:
5302 --
5303 --End of Comments
5304 -------------------------------------------------------------------------------
5305 PROCEDURE get_dist_ids_from_archive(
5306 p_doc_type IN VARCHAR2
5307 , p_doc_level IN VARCHAR2
5308 , p_doc_level_id_tbl IN po_tbl_number
5309 , p_doc_revision_num IN NUMBER
5310 , x_distribution_id_tbl OUT NOCOPY po_tbl_number
5311 , x_distribution_rev_num_tbl OUT NOCOPY po_tbl_number
5312 )
5313 IS
5314
5315 l_log_head CONSTANT VARCHAR2(100) := g_log_head||'GET_DIST_IDS_FROM_ARCHIVE';
5316 l_progress VARCHAR2(3) := '000';
5317
5318 l_doc_level_id_key NUMBER;
5319 l_revision_specified_flag VARCHAR2(1);
5320
5321 BEGIN
5322
5323 IF g_debug_stmt THEN
5324 PO_DEBUG.debug_begin(l_log_head);
5325 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_type', p_doc_type);
5326 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_level', p_doc_level);
5327 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_level_id_tbl', p_doc_level_id_tbl);
5328 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_revision_num', p_doc_revision_num);
5329 END IF;
5330
5331 l_progress := '010';
5332
5333 -----------------------------------------------------------------
5334 --Algorithm:
5335 --
5336 -- - Insert the doc level ids into the scratchpad table.
5337 -- - Join to the main doc tables against these doc level ids
5338 -- to retrieve the linked distribution ids.
5339 -----------------------------------------------------------------
5340
5341 l_progress := '200';
5342 IF g_debug_stmt THEN
5343 PO_DEBUG.debug_stmt(l_log_head,l_progress,'not dists');
5344 END IF;
5345
5346 -- Load the entity ids into the scratchpad.
5347
5348 ---------------------------------------
5349 -- PO_SESSION_GT column mapping
5350 --
5351 -- num1 document_level_id
5352 ---------------------------------------
5353
5354 l_doc_level_id_key := get_session_gt_nextval();
5355
5356 l_progress := '210';
5357
5358 FORALL i IN 1 .. p_doc_level_id_tbl.COUNT
5359 INSERT INTO PO_SESSION_GT ( key, num1 )
5360 VALUES ( l_doc_level_id_key, p_doc_level_id_tbl(i) )
5361 ;
5362
5363 l_progress := '220';
5364
5365 -- If a specific revision num is not passed in, set a flag to
5366 -- indicate we should use the latest revision in the archive table
5367 IF (p_doc_revision_num IS NULL) THEN
5368 l_revision_specified_flag := 'Y';
5369 ELSE
5370 l_revision_specified_flag := 'N';
5371 END IF;
5372
5373
5374 -- We need to derive the appropriate distribution ids for the given
5375 -- entity id and entity level.
5376
5377 IF (p_doc_type = g_doc_type_REQUISITION) THEN
5378
5379 l_progress := '300';
5380 IF g_debug_stmt THEN
5381 PO_DEBUG.debug_stmt(l_log_head,l_progress,'requisition');
5382 END IF;
5383
5384 -- Requisitions are not archived, hence this doc type is not
5385 -- supported by this API
5386 RAISE g_INVALID_CALL_EXC;
5387
5388 ELSE -- PO, Release
5389
5390 l_progress := '400';
5394
5391 IF g_debug_stmt THEN
5392 PO_DEBUG.debug_stmt(l_log_head,l_progress,'not req');
5393 END IF;
5395 -- Gather all of the distribution ids below this entity level.
5396
5397 IF ( p_doc_type = g_doc_type_RELEASE
5398 AND p_doc_level = g_doc_level_HEADER
5399 )
5400 THEN
5401
5402 l_progress := '410';
5403 IF g_debug_stmt THEN
5404 PO_DEBUG.debug_stmt(l_log_head,l_progress,'release');
5405 END IF;
5406
5407 SELECT POD.po_distribution_id
5408 , POD.revision_num
5409 BULK COLLECT INTO
5410 x_distribution_id_tbl
5411 , x_distribution_rev_num_tbl
5412 FROM
5413 PO_DISTRIBUTIONS_ARCHIVE_ALL POD
5414 , PO_SESSION_GT IDS
5415 WHERE POD.po_release_id = IDS.num1
5416 AND IDS.key = l_doc_level_id_key
5417 AND ( (l_revision_specified_flag = 'Y'
5418 AND POD.latest_external_flag = 'Y')
5419 OR
5420 (l_revision_specified_flag = 'N'
5421 AND POD.revision_num =
5422 (SELECT max(POD2.revision_num)
5423 FROM PO_DISTRIBUTIONS_ARCHIVE_ALL POD2
5424 WHERE POD2.po_distribution_id = POD.po_distribution_id
5425 AND POD2.revision_num <= p_doc_revision_num) )
5426 )
5427 ;
5428
5429 l_progress := '420';
5430
5431 ELSIF (p_doc_level = g_doc_level_HEADER) THEN
5432
5433 l_progress := '430';
5434 IF g_debug_stmt THEN
5435 PO_DEBUG.debug_stmt(l_log_head,l_progress,'headers');
5436 END IF;
5437
5438 SELECT POD.po_distribution_id
5439 , POD.revision_num
5440 BULK COLLECT INTO
5441 x_distribution_id_tbl
5442 , x_distribution_rev_num_tbl
5443 FROM
5444 PO_DISTRIBUTIONS_ARCHIVE_ALL POD
5445 , PO_SESSION_GT IDS
5446 WHERE POD.po_header_id = IDS.num1
5447 AND POD.po_release_id IS NULL
5448 -- Don't pick up Release distributions when acting on a PPO/BPA/GA.
5449 -- Not using distribution_type due to dependency issues.
5450 AND IDS.key = l_doc_level_id_key
5451 AND ( (l_revision_specified_flag = 'Y'
5452 AND POD.latest_external_flag = 'Y')
5453 OR
5454 (l_revision_specified_flag = 'N'
5455 AND POD.revision_num =
5456 (SELECT max(POD2.revision_num)
5457 FROM PO_DISTRIBUTIONS_ARCHIVE_ALL POD2
5458 WHERE POD2.po_distribution_id = POD.po_distribution_id
5459 AND POD2.revision_num <= p_doc_revision_num) )
5460 )
5461 ;
5462
5463 l_progress := '440';
5464
5465 ELSIF (p_doc_level = g_doc_level_LINE) THEN
5466
5467 l_progress := '450';
5468 IF g_debug_stmt THEN
5469 PO_DEBUG.debug_stmt(l_log_head,l_progress,'lines');
5470 END IF;
5471
5472 SELECT POD.po_distribution_id
5473 , POD.revision_num
5474 BULK COLLECT INTO
5475 x_distribution_id_tbl
5476 , x_distribution_rev_num_tbl
5477 FROM
5478 PO_DISTRIBUTIONS_ARCHIVE_ALL POD
5479 , PO_SESSION_GT IDS
5480 WHERE POD.po_line_id = IDS.num1
5481 AND POD.po_release_id IS NULL
5482 -- Don't pick up SR distributions when acting on a PPO.
5483 -- Not using distribution_type due to dependency issues.
5484 AND IDS.key = l_doc_level_id_key
5485 AND ( (l_revision_specified_flag = 'Y'
5486 AND POD.latest_external_flag = 'Y')
5487 OR
5488 (l_revision_specified_flag = 'N'
5489 AND POD.revision_num =
5490 (SELECT max(POD2.revision_num)
5491 FROM PO_DISTRIBUTIONS_ARCHIVE_ALL POD2
5492 WHERE POD2.po_distribution_id = POD.po_distribution_id
5493 AND POD2.revision_num <= p_doc_revision_num) )
5494 )
5495 ;
5496
5497 l_progress := '460';
5498
5499 ELSIF (p_doc_level = g_doc_level_SHIPMENT) THEN
5500
5501 l_progress := '470';
5502 IF g_debug_stmt THEN
5503 PO_DEBUG.debug_stmt(l_log_head,l_progress,'shipments');
5504 END IF;
5505
5506 SELECT POD.po_distribution_id
5507 , POD.revision_num
5508 BULK COLLECT INTO
5509 x_distribution_id_tbl
5510 , x_distribution_rev_num_tbl
5511 FROM
5512 PO_DISTRIBUTIONS_ARCHIVE_ALL POD
5513 , PO_SESSION_GT IDS
5514 WHERE POD.line_location_id = IDS.num1
5515 AND IDS.key = l_doc_level_id_key
5516 AND ( (l_revision_specified_flag = 'Y'
5517 AND POD.latest_external_flag = 'Y')
5518 OR
5519 (l_revision_specified_flag = 'N'
5520 AND POD.revision_num =
5521 (SELECT max(POD2.revision_num)
5522 FROM PO_DISTRIBUTIONS_ARCHIVE_ALL POD2
5523 WHERE POD2.po_distribution_id = POD.po_distribution_id
5524 AND POD2.revision_num <= p_doc_revision_num) )
5525 )
5526 ;
5530 ELSIF (p_doc_level = g_doc_level_DISTRIBUTION) THEN
5527
5528 l_progress := '480';
5529
5531
5532 l_progress := '490';
5533 IF g_debug_stmt THEN
5534 PO_DEBUG.debug_stmt(l_log_head,l_progress,'distributions');
5535 END IF;
5536
5537 SELECT POD.po_distribution_id
5538 , POD.revision_num
5539 BULK COLLECT INTO
5540 x_distribution_id_tbl
5541 , x_distribution_rev_num_tbl
5542 FROM
5543 PO_DISTRIBUTIONS_ARCHIVE_ALL POD
5544 , PO_SESSION_GT IDS
5545 WHERE POD.po_distribution_id = IDS.num1
5546 AND IDS.key = l_doc_level_id_key
5547 AND ( (l_revision_specified_flag = 'Y'
5548 AND POD.latest_external_flag = 'Y')
5549 OR
5550 (l_revision_specified_flag = 'N'
5551 AND POD.revision_num =
5552 (SELECT max(POD2.revision_num)
5553 FROM PO_DISTRIBUTIONS_ARCHIVE_ALL POD2
5554 WHERE POD2.po_distribution_id = POD.po_distribution_id
5555 AND POD2.revision_num <= p_doc_revision_num) )
5556 )
5557 ;
5558
5559 l_progress := '500';
5560
5561 ELSE
5562 l_progress := '510';
5563 RAISE g_INVALID_CALL_EXC;
5564 END IF;
5565
5566 l_progress := '520';
5567
5568 END IF; -- Req vs. PO/Release
5569
5570 l_progress := '600';
5571
5572
5573 IF g_debug_stmt THEN
5574 PO_DEBUG.debug_var(l_log_head,l_progress,'x_distribution_id_tbl',x_distribution_id_tbl);
5575 PO_DEBUG.debug_var(l_log_head,l_progress,'x_distribution_rev_num_tbl',x_distribution_rev_num_tbl);
5576 PO_DEBUG.debug_end(l_log_head);
5577 END IF;
5578
5579 EXCEPTION
5580 WHEN OTHERS THEN
5581 IF g_debug_unexp THEN
5582 PO_DEBUG.debug_exc(l_log_head,l_progress);
5583 END IF;
5584 RAISE;
5585
5586 END get_dist_ids_from_archive;
5587 --<Complex Work R12 END>
5588
5589
5590 ------------------------------------------------------------------------------
5591 --Start of Comments
5592 --Name: is_encumbrance_on
5593 --Pre-reqs:
5594 -- Org context may need to be set prior to calling.
5595 --Modifies:
5596 -- None.
5597 --Locks:
5598 -- None.
5599 --Function:
5600 -- This procedure checks if encumbrance is ON for a document type in a
5601 -- specified org.
5602 --Parameters:
5603 --IN:
5604 --p_doc_type
5605 -- The type of doc to check. Use g_doc_type_<> where <> is:
5606 -- REQUISITION - req enc
5607 -- PO - purch enc
5608 -- RELEASE - purch enc
5609 -- PA - both req and purch enc are on
5610 -- ANY - either req or purch enc or both are on
5611 --p_org_id
5612 -- The org id to check the encumbrance status in.
5613 -- If NULL is passed, the org context is assumed to have been set
5614 -- by the caller.
5615 --Returns:
5616 -- FALSE the encumbrance for p_doc_type is NOT on
5617 -- TRUE the encumbrance for p_doc_type is on
5618 --Testing:
5619 --
5620 --End of Comments
5621 -------------------------------------------------------------------------------
5622 FUNCTION is_encumbrance_on(
5623 p_doc_type IN VARCHAR2
5624 , p_org_id IN NUMBER
5625 ) RETURN BOOLEAN
5626 IS
5627
5628 l_log_head CONSTANT VARCHAR2(100) := g_log_head||'IS_ENCUMBRANCE_ON';
5629 l_progress VARCHAR2(3) := '000';
5630
5631 l_req_enc_flag FINANCIALS_SYSTEM_PARAMS_ALL.req_encumbrance_flag%TYPE;
5632 l_purch_enc_flag FINANCIALS_SYSTEM_PARAMS_ALL.purch_encumbrance_flag%TYPE;
5633
5634 l_req_encumbrance_on BOOLEAN;
5635 l_po_encumbrance_on BOOLEAN;
5636
5637 l_enc_on BOOLEAN;
5638
5639 BEGIN
5640
5641 IF g_debug_stmt THEN
5642 PO_DEBUG.debug_begin(l_log_head);
5643 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_type', p_doc_type);
5644 PO_DEBUG.debug_var(l_log_head,l_progress,'p_org_id', p_org_id);
5645 END IF;
5646
5647 l_progress := '010';
5648
5649 -- Get the FSP encumbrance status values.
5650 -- If org id is not passed in, use the org-striped table,
5651 -- otherwise use the _ALL table.
5652
5653 IF (p_org_id IS NULL) THEN
5654
5655 l_progress := '020';
5656 IF g_debug_stmt THEN
5657 PO_DEBUG.debug_stmt(l_log_head,l_progress,'using FINANCIALS_SYSTEM_PARAMETERS');
5658 END IF;
5659
5660 SELECT FSP.req_encumbrance_flag, FSP.purch_encumbrance_flag
5661 INTO l_req_enc_flag, l_purch_enc_flag
5662 FROM FINANCIALS_SYSTEM_PARAMETERS FSP
5663 ;
5664
5665 l_progress := '030';
5666
5667 ELSE
5668
5669 l_progress := '040';
5670 IF g_debug_stmt THEN
5671 PO_DEBUG.debug_stmt(l_log_head,l_progress,'using FINANCIALS_SYSTEM_PARAMS_ALL');
5672 END IF;
5673
5674 SELECT FSP.req_encumbrance_flag, FSP.purch_encumbrance_flag
5675 INTO l_req_enc_flag, l_purch_enc_flag
5676 FROM FINANCIALS_SYSTEM_PARAMS_ALL FSP
5677 WHERE FSP.org_id = p_org_id
5678 ;
5679
5680 l_progress := '050';
5681
5682 END IF;
5683
5684 l_progress := '060';
5685
5686 IF g_debug_stmt THEN
5687 PO_DEBUG.debug_var(l_log_head,l_progress,'l_req_enc_flag',l_req_enc_flag);
5688 PO_DEBUG.debug_var(l_log_head,l_progress,'l_purch_enc_flag',l_purch_enc_flag);
5689 END IF;
5690
5691 -- Set the vars for encumbrance checking.
5692
5693 IF (l_req_enc_flag = 'Y') THEN
5694 l_req_encumbrance_on := TRUE;
5695 ELSE
5696 l_req_encumbrance_on := FALSE;
5697 END IF;
5698
5699 l_progress := '070';
5700
5701 IF (l_purch_enc_flag = 'Y') THEN
5702 l_po_encumbrance_on := TRUE;
5703 ELSE
5704 l_po_encumbrance_on := FALSE;
5705 END IF;
5706
5707 l_progress := '080';
5708
5709 IF g_debug_stmt THEN
5710 PO_DEBUG.debug_var(l_log_head,l_progress,'l_req_encumbrance_on',l_req_encumbrance_on);
5711 PO_DEBUG.debug_var(l_log_head,l_progress,'l_po_encumbrance_on',l_po_encumbrance_on);
5712 END IF;
5713
5714 -- Set the return value for the appropriate doc type.
5715
5716 IF (p_doc_type = g_doc_type_REQUISITION) THEN
5717
5718 l_progress := '100';
5719
5720 l_enc_on := l_req_encumbrance_on;
5721
5722 ELSIF (p_doc_type IN (g_doc_type_PO, g_doc_type_RELEASE)) THEN
5723
5724 l_progress := '110';
5725
5726 l_enc_on := l_po_encumbrance_on;
5727
5728 ELSIF (p_doc_type = g_doc_type_PA) THEN
5729
5730 l_progress := '120';
5731
5732 l_enc_on := (l_req_encumbrance_on AND l_po_encumbrance_on);
5733
5734 ELSIF (p_doc_type = g_doc_type_ANY) THEN
5735
5736 l_progress := '130';
5737
5738 l_enc_on := (l_req_encumbrance_on OR l_po_encumbrance_on);
5739
5740 ELSE
5741 l_progress := '170';
5742 RAISE g_INVALID_CALL_EXC;
5743 END IF;
5744
5745 l_progress := '900';
5746
5747 IF g_debug_stmt THEN
5748 PO_DEBUG.debug_var(l_log_head,l_progress,'l_enc_on',l_enc_on);
5749 PO_DEBUG.debug_end(l_log_head);
5750 END IF;
5751
5752 RETURN(l_enc_on);
5753
5754 EXCEPTION
5755 WHEN OTHERS THEN
5756 IF g_debug_unexp THEN
5757 PO_DEBUG.debug_var(l_log_head,l_progress,'l_enc_on',l_enc_on);
5758 PO_DEBUG.debug_exc(l_log_head,l_progress);
5759 END IF;
5760 RAISE;
5761
5762 END is_encumbrance_on;
5763
5764
5765 -----------------------------------------------------------------<SERVICES FPJ>
5766 -------------------------------------------------------------------------------
5767 --Start of Comments
5768 --Name: get_translated_text
5769 --Pre-reqs:
5770 -- None.
5771 --Modifies:
5772 -- None.
5773 --Locks:
5774 -- None.
5775 --Function:
5776 -- This function takes in a message name and token-value pairs and returns
5777 -- the translated text as a VARCHAR2 String.
5778 --Parameters:
5779 --IN:
5780 --p_message_name
5781 -- Name of message in Message Dictionary.
5782 --p_token1
5783 -- Name of token variable in the message (only applies if a token exists).
5784 --p_value1
5785 -- Value to subsitute for token (only applies if a token exists).
5786 --Returns:
5787 -- VARCHAR2 - The translated and token-substituted message.
5788 --Testing:
5789 -- None.
5790 --End of Comments
5791 -------------------------------------------------------------------------------
5792 -------------------------------------------------------------------------------
5793 FUNCTION get_translated_text
5794 ( p_message_name IN VARCHAR2
5795 , p_token1 IN VARCHAR2 -- := NULL
5796 , p_value1 IN VARCHAR2 -- := NULL
5797 , p_token2 IN VARCHAR2 -- := NULL
5798 , p_value2 IN VARCHAR2 -- := NULL
5799 , p_token3 IN VARCHAR2 -- := NULL
5800 , p_value3 IN VARCHAR2 -- := NULL
5801 , p_token4 IN VARCHAR2 -- := NULL
5802 , p_value4 IN VARCHAR2 -- := NULL
5803 , p_token5 IN VARCHAR2 -- := NULL
5804 , p_value5 IN VARCHAR2 -- := NULL
5805 ) RETURN VARCHAR2
5806 IS
5807 l_application_name VARCHAR2(3) := 'PO';
5808
5809 BEGIN
5810
5811 ---------------------------------------------------------------------------
5812 -- Set Message on Stack ---------------------------------------------------
5813 ---------------------------------------------------------------------------
5814
5815 FND_MESSAGE.set_name(l_application_name, p_message_name);
5816
5817 ---------------------------------------------------------------------------
5818 -- Substitute Tokens ------------------------------------------------------
5819 ---------------------------------------------------------------------------
5820
5821 IF ( p_token1 IS NOT NULL ) THEN
5822 FND_MESSAGE.set_token(p_token1, p_value1);
5823 END IF;
5824
5825 IF ( p_token2 IS NOT NULL ) THEN
5826 FND_MESSAGE.set_token(p_token2, p_value2);
5827 END IF;
5828
5829 IF ( p_token3 IS NOT NULL ) THEN
5830 FND_MESSAGE.set_token(p_token3, p_value3);
5831 END IF;
5832
5833 IF ( p_token4 IS NOT NULL ) THEN
5834 FND_MESSAGE.set_token(p_token4, p_value4);
5835 END IF;
5836
5837 IF ( p_token5 IS NOT NULL ) THEN
5838 FND_MESSAGE.set_token(p_token5, p_value5);
5839 END IF;
5840
5841 ---------------------------------------------------------------------------
5842 -- Return Translated Message ----------------------------------------------
5843 ---------------------------------------------------------------------------
5844
5845 return (FND_MESSAGE.get);
5846
5847 ---------------------------------------------------------------------------
5848
5849 END get_translated_text;
5850
5851 --<Shared Proc FPJ START>
5852 -------------------------------------------------------------------------------
5853 --Start of Comments
5854 --Name: CHECK_DOC_NUMBER_UNIQUE
5855 --Pre-reqs:
5856 -- None
5857 --Modifies:
5858 -- None.
5859 --Locks:
5860 -- None.
5861 --Function:
5862 -- Returns boolean indicating whether a segment1 value with given type lookup
5863 -- code passed in is unique in given operating unit. The uniqueness test is
5864 -- done in PO trasaction and history tables. The uniqueness test spans Sourcing's
5865 -- transaction tables also.
5866 --Parameters:
5867 --IN:
5868 -- p_segment1
5869 -- The doc number whose uniqueness needs to be tested
5870 -- p_org_id
5871 -- The operating unit where the uniqueness needs to be tested
5872 -- p_type_lookup_code
5873 -- The lookup code of the document. Valid values are 'STANDARD', 'PLANNED',
5874 -- 'CONTRACT','BLANKET', 'RFQ', 'QUOTATION'
5875 --Testing:
5876 -- None
5877 --End of Comments
5878 ---------------------------------------------------------------------------
5879 FUNCTION Check_Doc_Number_Unique(p_Segment1 In VARCHAR2,
5880 p_org_id IN VARCHAR2,
5881 p_Type_lookup_code IN VARCHAR2)
5882 RETURN boolean is
5883
5884 l_Unique boolean;
5885 l_non_unique_seg1 Varchar2(20);
5886 l_api_name CONSTANT VARCHAR2(30) := 'Check_Doc_Number_Unique';
5887 l_progress varchar2(3) := '000';
5888 l_duplicate_exists varchar2(1);
5889 l_pon_install_status varchar2(1);
5890 l_status varchar2(10);
5891 BEGIN
5892
5893 IF p_Type_lookup_code NOT IN ('RFQ', 'QUOTATION') THEN
5894
5895 l_progress := '010';
5896
5897 SELECT 'N'
5898 into l_duplicate_exists
5899 from sys.dual
5900 where not exists
5901 (SELECT 'po number is not unique'
5902 FROM po_headers_all ph
5903 WHERE ph.segment1 = p_segment1
5904 AND ph.type_lookup_code IN
5905 ('STANDARD','CONTRACT','BLANKET','PLANNED')
5906 AND nvl(ph.org_id, -99) = nvl(p_org_id, -99));
5907
5908 l_Progress := '020';
5909
5910 SELECT 'N'
5911 into l_duplicate_exists
5912 from sys.dual
5913 where not exists
5914 (SELECT 'po number is not unique'
5915 FROM po_history_pos_all ph
5916 WHERE ph.segment1 = p_segment1
5917 AND ph.type_lookup_code IN
5918 ('STANDARD','CONTRACT','BLANKET','PLANNED')
5919 AND nvl(ph.org_id, -99) = nvl(p_org_id, -99));
5920
5921 --Get the install status of Sourcing
5922 po_setup_s1.get_sourcing_startup(l_pon_install_status);
5923
5924 if nvl(l_pon_install_status,'N') ='I' then
5925 if p_Type_lookup_code in ('STANDARD','BLANKET') then
5926 pon_auction_po_pkg.check_unique(p_org_id,p_segment1,l_status);
5927 if l_status = 'SUCCESS' then
5928 l_Unique :=TRUE;
5929 else
5930 raise no_data_found;
5931 end if;
5932 end if;
5933 end if;
5934
5935 l_Unique:= TRUE;
5936
5937 return(l_Unique);
5938
5939 ELSIF (p_Type_lookup_code = 'RFQ') THEN
5940
5941 -- RFQ specific processing
5942
5943 l_progress := '030';
5944
5945 SELECT 'N'
5946 into l_duplicate_exists
5947 from sys.dual
5948 where not exists
5949 (SELECT 'rfq number is not unique'
5950 FROM po_headers_all ph
5951 WHERE ph.segment1 = p_segment1
5952 AND ph.type_lookup_code = 'RFQ'
5953 AND nvl(ph.org_id, -99) = nvl(p_org_id, -99));
5954
5955 l_Progress := '040';
5956
5957 SELECT 'N'
5958 into l_duplicate_exists
5959 from sys.dual
5960 where not exists
5961 (SELECT 'rfq number is not unique'
5962 FROM po_history_pos_all ph
5963 WHERE ph.segment1 = p_segment1
5964 AND ph.type_lookup_code = 'RFQ'
5965 AND nvl(ph.org_id, -99) = nvl(p_org_id, -99));
5966
5967 l_Unique:= TRUE;
5968
5969 return(l_Unique);
5970
5971 ELSIF (p_Type_lookup_code = 'QUOTATION') THEN
5972
5973 -- Quotation specific processing
5974
5975 l_progress := '050';
5976
5977 SELECT 'N'
5978 into l_duplicate_exists
5979 from sys.dual
5980 where not exists
5981 (SELECT 'quote number is not unique'
5982 FROM po_headers_all ph
5983 WHERE ph.segment1 = p_segment1
5984 AND ph.type_lookup_code = 'QUOTATION'
5985 AND nvl(ph.org_id, -99) = nvl(p_org_id, -99));
5986
5987 l_Progress := '060';
5988
5989 SELECT 'N'
5990 into l_duplicate_exists
5991 from sys.dual
5992 where not exists
5993 (SELECT 'quote number is not unique'
5994 FROM po_history_pos_all ph
5995 WHERE ph.segment1 = p_segment1
5996 AND ph.type_lookup_code = 'QUOTATION'
5997 AND nvl(ph.org_id, -99) = nvl(p_org_id, -99));
5998
5999 l_Unique:= TRUE;
6000
6001 return(l_Unique);
6002
6003 END IF;
6004
6005 EXCEPTION
6006 WHEN NO_DATA_FOUND THEN
6007 --Bug 3417966 No need to set the message here
6008 --fnd_message.set_name('PO', 'PO_ALL_ENTER_UNIQUE_VAL');
6009 l_Unique:= FALSE;
6010 RETURN(l_Unique);
6011 WHEN OTHERS THEN
6012 l_unique := FALSE;
6013 IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error)
6014 THEN
6015 fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name,
6016 SUBSTRB (SQLERRM , 1 , 200) || ' at location ' || l_progress);
6017 END IF;
6018 RETURN(l_Unique);
6019 END Check_doc_number_Unique;
6020
6021 --------------------------------------------------------------------------------
6022 --Start of Comments
6023 --Name: check_inv_org_in_sob
6024 --Pre-reqs:
6025 -- None.
6026 --Modifies:
6027 -- FND_LOG
6028 -- FND_MSG_PUB
6029 --Locks:
6030 -- None.
6031 --Function:
6032 -- Checks if p_inv_org_id is in the Set of Books p_sob_id. If p_sob_id
6033 -- is NULL, then defaults p_sob_id to be the current OU's SOB. Appends to the
6034 -- API message list upon error.
6035 --Parameters:
6036 --IN:
6037 --p_inv_org_id
6038 -- The inventory organization ID.
6039 --p_sob_id
6040 -- The set of books ID, or NULL to default the current OU's SOB.
6041 --OUT:
6042 --x_return_status
6043 -- FND_API.g_ret_sts_success - if the procedure completed successfully
6044 -- FND_API.g_ret_sts_unexp_error - unexpected error occurred
6045 --x_in_sob
6046 -- TRUE if p_inv_org_id is within the set of books p_sob_id.
6047 -- FALSE otherwise.
6048 --End of Comments
6049 --------------------------------------------------------------------------------
6050 PROCEDURE check_inv_org_in_sob
6051 (
6052 x_return_status OUT NOCOPY VARCHAR2,
6053 p_inv_org_id IN NUMBER,
6054 p_sob_id IN NUMBER,
6055 x_in_sob OUT NOCOPY BOOLEAN
6056 )
6057 IS
6058 l_progress VARCHAR2(3);
6059 l_in_sob VARCHAR2(1);
6060 BEGIN
6061 l_progress := '000';
6062 x_return_status := FND_API.g_ret_sts_success;
6063
6064 IF g_debug_stmt THEN
6065 PO_DEBUG.debug_stmt
6066 (p_log_head => g_log_head||'check_inv_org_in_sob',
6067 p_token => 'invoked',
6068 p_message => 'inv org ID: '||p_inv_org_id||' sob ID: '||p_sob_id);
6069 END IF;
6070
6071 BEGIN
6072
6073 IF (p_sob_id IS NULL) THEN
6074 l_progress := '010';
6075
6076 --SQL What: Check if inv org p_inv_org_id is in current set of books
6077 --SQL Why: Outcome determines output parameter x_in_sob
6078 SELECT 'Y'
6079 INTO l_in_sob
6080 FROM financials_system_parameters fsp,
6081 hr_organization_information hoi,
6082 mtl_parameters mp
6083 WHERE mp.organization_id = p_inv_org_id
6084 AND mp.organization_id = hoi.organization_id
6085 AND hoi.org_information_context = 'Accounting Information'
6086 AND hoi.org_information1 = TO_CHAR(fsp.set_of_books_id);
6087 ELSE
6088 l_progress := '020';
6089
6090 --SQL What: Check if inv org p_inv_org_id is in SOB p_sob_id
6091 --SQL Why: Outcome determines output parameter x_in_sob
6092 SELECT 'Y'
6093 INTO l_in_sob
6094 FROM hr_organization_information hoi,
6095 mtl_parameters mp
6096 WHERE mp.organization_id = p_inv_org_id
6097 AND mp.organization_id = hoi.organization_id
6098 AND hoi.org_information_context = 'Accounting Information'
6099 AND hoi.org_information1 = TO_CHAR(p_sob_id);
6100 END IF;
6101
6102 -- Successful select means inv org is in the SOB.
6103 x_in_sob := TRUE;
6104
6105 EXCEPTION
6106 WHEN NO_DATA_FOUND THEN
6107 l_progress := '030';
6108 x_in_sob := FALSE;
6109 END;
6110
6111 IF g_debug_stmt THEN
6112 PO_DEBUG.debug_var
6113 (p_log_head => g_log_head||'check_inv_org_in_sob',
6114 p_progress => l_progress,
6115 p_name => 'x_in_sob',
6116 p_value => x_in_sob);
6117 END IF;
6118
6119 EXCEPTION
6120 WHEN OTHERS THEN
6121 x_return_status := FND_API.g_ret_sts_unexp_error;
6122 x_in_sob := FALSE;
6123 FND_MSG_PUB.add_exc_msg(p_pkg_name => g_pkg_name,
6124 p_procedure_name => 'check_inv_org_in_sob',
6125 p_error_text => 'Progress: '||l_progress||
6126 ' Error: '||SUBSTRB(SQLERRM,1,215));
6127 IF g_debug_unexp THEN
6128 PO_DEBUG.debug_exc
6129 (p_log_head => g_log_head||'check_inv_org_in_sob',
6130 p_progress => l_progress);
6131 END IF;
6132 END check_inv_org_in_sob;
6133
6134 --------------------------------------------------------------------------------
6135 --Start of Comments
6136 --Name: get_inv_org_ou_id
6137 --Pre-reqs:
6138 -- None.
6139 --Modifies:
6140 -- FND_LOG
6141 -- FND_MSG_PUB
6142 --Locks:
6143 -- None.
6144 --Function:
6145 -- Gets the operating unit associated with p_inv_org_id. If p_inv_org_id is
6146 -- NULL, then just return a NULL x_ou_id. Appends to the API message list upon
6147 -- error.
6148 --Parameters:
6149 --IN:
6150 --p_inv_org_id
6151 -- The inventory organization ID.
6152 --OUT:
6153 --x_return_status
6154 -- FND_API.g_ret_sts_success - if the procedure completed successfully
6155 -- FND_API.g_ret_sts_unexp_error - unexpected error occurred
6156 --x_ou_id
6157 -- The operating unit ID associated with the inventory org p_inv_org_id. This
6158 -- will be NULL if p_inv_org_id is passed in as NULL.
6159 --End of Comments
6160 --------------------------------------------------------------------------------
6161 PROCEDURE get_inv_org_ou_id
6162 (
6163 x_return_status OUT NOCOPY VARCHAR2,
6164 p_inv_org_id IN NUMBER,
6165 x_ou_id OUT NOCOPY NUMBER
6166 )
6167 IS
6168 l_progress VARCHAR2(3);
6169 BEGIN
6170 l_progress := '000';
6171 x_return_status := FND_API.g_ret_sts_success;
6172
6173 IF g_debug_stmt THEN
6174 PO_DEBUG.debug_stmt
6175 (p_log_head => g_log_head||'get_inv_org_ou_id',
6176 p_token => 'invoked',
6177 p_message => 'inv org ID: '||p_inv_org_id);
6178 END IF;
6179
6180 --< Bug 3370735 Start >
6181 IF (p_inv_org_id IS NULL) THEN
6182 -- Null out x_ou_id and return when the inv org ID is NULL
6183 x_ou_id := NULL;
6184 RETURN;
6185 END IF;
6186 --< Bug 3370735 Start >
6187
6188 l_progress := '010';
6189
6190 --SQL What: Get the operating unit associated with p_inv_org_id
6191 --SQL Why: Return value as output parameter x_ou_id
6192 SELECT TO_NUMBER(hoi.org_information3)
6193 INTO x_ou_id
6194 FROM hr_organization_information hoi,
6195 mtl_parameters mp
6196 WHERE mp.organization_id = p_inv_org_id
6197 AND mp.organization_id = hoi.organization_id
6198 AND hoi.org_information_context = 'Accounting Information';
6199
6200 l_progress := '020';
6201
6202 IF g_debug_stmt THEN
6203 PO_DEBUG.debug_var
6204 (p_log_head => g_log_head||'get_inv_org_ou_id',
6205 p_progress => l_progress,
6206 p_name => 'x_ou_id',
6207 p_value => x_ou_id);
6208 END IF;
6209
6210 EXCEPTION
6211 WHEN OTHERS THEN
6212 x_return_status := FND_API.g_ret_sts_unexp_error;
6213 FND_MSG_PUB.add_exc_msg(p_pkg_name => g_pkg_name,
6214 p_procedure_name => 'get_inv_org_ou_id',
6215 p_error_text => 'Progress: '||l_progress||
6216 ' Error: '||SUBSTRB(SQLERRM,1,215));
6217 IF g_debug_unexp THEN
6218 PO_DEBUG.debug_exc
6219 (p_log_head => g_log_head||'get_inv_org_ou_id',
6220 p_progress => l_progress);
6221 END IF;
6222 END get_inv_org_ou_id;
6223
6224 --------------------------------------------------------------------------------
6225 --Start of Comments
6226 --Name: get_inv_org_sob_id
6227 --Pre-reqs:
6228 -- None.
6229 --Modifies:
6230 -- FND_LOG
6231 -- FND_MSG_PUB
6232 --Locks:
6233 -- None.
6234 --Function:
6235 -- Gets the set of books ID associated with p_inv_org_id. Appends to the
6236 -- API message list upon error.
6237 --Parameters:
6238 --IN:
6239 --p_inv_org_id
6240 -- The inventory organization ID.
6241 --OUT:
6242 --x_return_status
6243 -- FND_API.g_ret_sts_success - if the procedure completed successfully
6244 -- FND_API.g_ret_sts_unexp_error - unexpected error occurred
6245 --x_sob_id
6246 -- The set of books ID associated with the inventory org p_inv_org_id.
6247 --End of Comments
6248 --------------------------------------------------------------------------------
6249 PROCEDURE get_inv_org_sob_id
6250 (
6251 x_return_status OUT NOCOPY VARCHAR2,
6252 p_inv_org_id IN NUMBER,
6253 x_sob_id OUT NOCOPY NUMBER
6254 )
6255 IS
6256 l_progress VARCHAR2(3);
6257 BEGIN
6258 l_progress := '000';
6259 x_return_status := FND_API.g_ret_sts_success;
6260
6261 IF g_debug_stmt THEN
6262 PO_DEBUG.debug_stmt
6263 (p_log_head => g_log_head||'get_inv_org_sob_id',
6264 p_token => 'invoked',
6265 p_message => 'inv org ID: '||p_inv_org_id);
6266 END IF;
6267
6268 l_progress := '010';
6269
6270 --SQL What: Get the set of books ID associated with p_inv_org_id
6271 --SQL Why: Return value as output parameter x_sob_id
6272 SELECT TO_NUMBER(hoi.org_information1)
6273 INTO x_sob_id
6274 FROM hr_organization_information hoi,
6275 mtl_parameters mp
6276 WHERE mp.organization_id = p_inv_org_id
6277 AND mp.organization_id = hoi.organization_id
6278 AND hoi.org_information_context = 'Accounting Information';
6279
6280 l_progress := '020';
6281
6282 IF g_debug_stmt THEN
6283 PO_DEBUG.debug_var
6284 (p_log_head => g_log_head||'get_inv_org_sob_id',
6285 p_progress => l_progress,
6286 p_name => 'x_sob_id',
6287 p_value => x_sob_id);
6288 END IF;
6289
6290 EXCEPTION
6291 WHEN OTHERS THEN
6292 x_return_status := FND_API.g_ret_sts_unexp_error;
6293 FND_MSG_PUB.add_exc_msg(p_pkg_name => g_pkg_name,
6294 p_procedure_name => 'get_inv_org_sob_id',
6295 p_error_text => 'Progress: '||l_progress||
6296 ' Error: '||SUBSTRB(SQLERRM,1,215));
6297 IF g_debug_unexp THEN
6298 PO_DEBUG.debug_exc
6299 (p_log_head => g_log_head||'get_inv_org_sob_id',
6300 p_progress => l_progress);
6301 END IF;
6302 END get_inv_org_sob_id;
6303
6304 --------------------------------------------------------------------------------
6305 --Start of Comments
6306 --Name: get_inv_org_info
6307 --Pre-reqs:
6308 -- None.
6309 --Modifies:
6310 -- FND_LOG
6311 -- FND_MSG_PUB
6312 --Locks:
6313 -- None.
6314 --Function:
6315 -- Gets the following information associated with p_inv_org_id:
6316 -- business group ID
6317 -- set of books ID
6318 -- chart of accounts ID
6319 -- operating unit ID
6320 -- legal entity ID
6321 -- Appends to the API message list upon error.
6322 --Parameters:
6323 --IN:
6324 --p_inv_org_id
6325 -- The inventory organization ID.
6326 --OUT:
6327 --x_return_status
6328 -- FND_API.g_ret_sts_success - if the procedure completed successfully
6329 -- FND_API.g_ret_sts_unexp_error - unexpected error occurred
6330 --x_business_group_id
6331 -- The business group ID associated with the inventory org p_inv_org_id.
6332 --x_set_of_books_id
6333 -- The set of books ID associated with the inventory org p_inv_org_id.
6334 --x_chart_of_accounts_id
6335 -- The chart of accounts ID associated with the inventory org p_inv_org_id.
6336 --x_operating_unit_id
6337 -- The operating unit ID associated with the inventory org p_inv_org_id.
6338 --x_legal_entity_id
6339 -- The legal entity ID associated with the inventory org p_inv_org_id.
6340 --End of Comments
6341 --------------------------------------------------------------------------------
6342 PROCEDURE get_inv_org_info
6343 (
6344 x_return_status OUT NOCOPY VARCHAR2,
6345 p_inv_org_id IN NUMBER,
6346 x_business_group_id OUT NOCOPY NUMBER,
6347 x_set_of_books_id OUT NOCOPY NUMBER,
6348 x_chart_of_accounts_id OUT NOCOPY NUMBER,
6349 x_operating_unit_id OUT NOCOPY NUMBER,
6350 x_legal_entity_id OUT NOCOPY NUMBER
6351 )
6352 IS
6353 l_progress VARCHAR2(3);
6354 BEGIN
6355 l_progress := '000';
6356 x_return_status := FND_API.g_ret_sts_success;
6357
6358 IF g_debug_stmt THEN
6359 PO_DEBUG.debug_stmt
6360 (p_log_head => g_log_head||'get_inv_org_info',
6361 p_token => 'invoked',
6362 p_message => 'inv org ID: '||p_inv_org_id);
6363 END IF;
6364
6365 l_progress := '010';
6366
6367 --SQL What: Get the important ID's associated with p_inv_org_id. These ID's
6368 -- are the same as those returned by ORG_ORGANIZATION_DEFINITIONS.
6369 --SQL Why: Return value of ID's as output parameters to procedure.
6370 SELECT haou.business_group_id,
6371 gsob.set_of_books_id,
6372 gsob.chart_of_accounts_id,
6373 TO_NUMBER(hoi.org_information3),
6374 TO_NUMBER(hoi.org_information2)
6375 INTO x_business_group_id,
6376 x_set_of_books_id,
6377 x_chart_of_accounts_id,
6378 x_operating_unit_id,
6379 x_legal_entity_id
6380 FROM hr_organization_information hoi,
6381 hr_all_organization_units haou,
6382 mtl_parameters mp,
6383 gl_sets_of_books gsob
6384 WHERE mp.organization_id = p_inv_org_id
6385 AND mp.organization_id = haou.organization_id
6386 AND haou.organization_id = hoi.organization_id
6387 AND hoi.org_information_context = 'Accounting Information'
6388 AND TO_NUMBER(hoi.org_information1) = gsob.set_of_books_id;
6389
6390 l_progress := '020';
6391
6392 IF g_debug_stmt THEN
6393 PO_DEBUG.debug_stmt
6394 (p_log_head => g_log_head||'get_inv_org_info',
6395 p_token => 'output',
6396 p_message => 'bg ID: '||x_business_group_id||' sob ID: '||
6397 x_set_of_books_id||' coa ID: '||x_chart_of_accounts_id||
6398 ' ou ID: '||x_operating_unit_id||' le ID: '||
6399 x_legal_entity_id);
6400 END IF;
6401
6402 EXCEPTION
6403 WHEN OTHERS THEN
6404 x_return_status := FND_API.g_ret_sts_unexp_error;
6405 FND_MSG_PUB.add_exc_msg(p_pkg_name => g_pkg_name,
6406 p_procedure_name => 'get_inv_org_info',
6407 p_error_text => 'Progress: '||l_progress||
6408 ' Error: '||SUBSTRB(SQLERRM,1,215));
6409 IF g_debug_unexp THEN
6410 PO_DEBUG.debug_exc
6411 (p_log_head => g_log_head||'get_inv_org_info',
6412 p_progress => l_progress);
6413 END IF;
6414 END get_inv_org_info;
6415
6416 --<Shared Proc FPJ END>
6417
6418
6419
6420 --------------------------------------------------------------------------------
6421 --Start of Comments
6422 --Name: get_open_encumbrance_stats
6423 --Pre-reqs:
6424 -- None.
6425 --Modifies:
6426 -- None.
6427 --Locks:
6428 -- None.
6429 --Function:
6430 -- Classifies the distributions below the given entity that are not
6431 -- cancelled or finally closed.
6432 -- This procedure is being used by functions that are embedded in SQL
6433 -- statements in other products (views, etc.), so it is not allowed
6434 -- to modify anything (except in an autonomous transaction).
6435 -- Because of this restriction, the utility procedures that use
6436 -- global temp tables cannot be leveraged.
6437 --Parameters:
6438 --IN:
6439 --p_doc_type
6440 -- Document type. Use the g_doc_type_<> variables, where <> is:
6441 -- REQUISITION
6442 -- PA
6443 -- PO
6444 -- RELEASE
6445 --p_doc_level
6446 -- The type of ids that are being passed. Use g_doc_level_<>
6447 -- HEADER
6448 -- LINE
6449 -- SHIPMENT
6450 -- DISTRIBUTION
6451 --p_doc_level_id
6452 -- Id of the doc level type on which the action is being taken.
6453 --OUT:
6454 --x_reserved_count
6455 -- The number of (non-prevent) distributions that are reserved.
6456 --x_unreserved_count
6457 -- The number of non-prevent distributions that are unreserved.
6458 --x_prevented_count
6459 -- The number of distributions that have prevent_encumbrance_flag set to 'Y'.
6460 --End of Comments
6461 --------------------------------------------------------------------------------
6462 PROCEDURE get_open_encumbrance_stats(
6463 p_doc_type IN VARCHAR2
6464 , p_doc_level IN VARCHAR2
6465 , p_doc_level_id IN NUMBER
6466 , x_reserved_count OUT NOCOPY NUMBER
6467 , x_unreserved_count OUT NOCOPY NUMBER
6468 , x_prevented_count OUT NOCOPY NUMBER
6469 )
6470 IS
6471
6472 l_proc_name CONSTANT VARCHAR2(30) := 'GET_OPEN_ENCUMBRANCE_STATS';
6473 l_log_head CONSTANT VARCHAR2(100) := g_log_head || l_proc_name;
6474 l_progress VARCHAR2(3) := '000';
6475
6476 BEGIN
6477
6478 IF g_debug_stmt THEN
6479 PO_DEBUG.debug_begin(l_log_head);
6480 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_type',p_doc_type);
6481 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_level',p_doc_level);
6482 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_level_id',p_doc_level_id);
6483 END IF;
6484
6485 l_progress := '010';
6486
6487 IF (p_doc_type = g_doc_type_REQUISITION) THEN
6488
6489 l_progress := '100';
6490
6491 --SQL What:
6492 -- Count the distributions that fall into different categories.
6493 --SQL Where:
6494 -- Not Cancelled, not Finally Closed.
6495 -- The id passed in can be header, line, or dist. id.
6496 -- An inner query is used in the FROM clause to avoid duplicating
6497 -- any logic, while maintaining a decent SQL plan.
6498
6499 SELECT
6500
6501 -- reserved rows that are not prevent_encumbrance
6502 -- i.e., prevent_encumbrance_flag <> Y and encumbered_flag = Y
6503 COUNT( DECODE( PRD.prevent_encumbrance_flag
6504 , 'Y', NULL
6505 , DECODE( PRD.encumbered_flag
6506 , 'Y', 'Y'
6507 , NULL
6508 )
6509 )
6510 )
6511
6512 -- unreserved rows that are not prevent_encumbrance
6513 -- i.e., prevent_encumbrance_flag <> Y and encumbered_flag <> Y
6514 , COUNT( DECODE( PRD.prevent_encumbrance_flag
6515 , 'Y', NULL
6516 , DECODE( PRD.encumbered_flag
6517 , 'Y', NULL
6518 , 'N'
6519 )
6520 )
6521 )
6522
6523 -- prevent_encumbrance rows
6524 -- i.e., prevent_encumbrance_flag = Y
6525 , COUNT( DECODE( PRD.prevent_encumbrance_flag
6526 , 'Y', 'Y'
6527 , NULL
6528 )
6529 )
6530
6531 INTO
6532 x_reserved_count
6533 , x_unreserved_count
6534 , x_prevented_count
6535
6536 FROM
6537 PO_REQ_DISTRIBUTIONS_ALL PRD
6538 , PO_REQUISITION_LINES_ALL PRL
6539 , (
6540 SELECT
6541 p_doc_level_id dist_id
6542 FROM DUAL
6543 WHERE p_doc_level = g_doc_level_DISTRIBUTION
6544 UNION ALL
6545 SELECT
6546 PRD1.distribution_id dist_id
6547 FROM PO_REQ_DISTRIBUTIONS_ALL PRD1
6548 WHERE p_doc_level = g_doc_level_LINE
6549 AND PRD1.requisition_line_id = p_doc_level_id
6550 UNION ALL
6551 SELECT
6552 PRD2.distribution_id dist_id
6553 FROM
6554 PO_REQ_DISTRIBUTIONS_ALL PRD2
6555 , PO_REQUISITION_LINES_ALL PRL2
6556 WHERE p_doc_level = g_doc_level_HEADER
6557 AND PRD2.requisition_line_id = PRL2.requisition_line_id
6558 AND PRL2.requisition_header_id = p_doc_level_id
6559 ) DIST_IDS
6560
6561 WHERE PRL.requisition_line_id = PRD.requisition_line_id
6562 AND NVL(PRL.cancel_flag,'N') <> 'Y'
6563 AND NVL(PRL.closed_code,g_clsd_OPEN) <> g_clsd_FINALLY_CLOSED
6564 AND PRD.distribution_id = DIST_IDS.dist_id
6565 ;
6566
6567 l_progress := '190';
6568
6569 ELSE -- not a requisition
6570
6571 l_progress := '200';
6572
6573 --SQL What:
6574 -- Count the distributions that fall into different categories.
6575 --SQL Where:
6576 -- Not Cancelled, not Finally Closed.
6577 -- The id passed in can be header, line, shipment, dist., or release id.
6578
6579 SELECT
6580
6581 -- reserved rows that are not prevent_encumbrance
6582 -- i.e., prevent_encumbrance_flag <> Y and encumbered_flag = Y
6583 COUNT( DECODE( POD.prevent_encumbrance_flag
6584 , 'Y', NULL
6585 , DECODE( POD.encumbered_flag
6586 , 'Y', 'Y'
6587 , NULL
6588 )
6589 )
6590 )
6591
6592 -- unreserved rows that are not prevent_encumbrance
6593 -- i.e., prevent_encumbrance_flag <> Y and encumbered_flag <> Y
6594 , COUNT( DECODE( POD.prevent_encumbrance_flag
6595 , 'Y', NULL
6596 , DECODE( POD.encumbered_flag
6597 , 'Y', NULL
6598 , 'N'
6599 )
6600 )
6601 )
6602
6603 -- prevent_encumbrance rows
6604 -- i.e., prevent_encumbrance_flag = Y
6605 , COUNT( DECODE( POD.prevent_encumbrance_flag
6606 , 'Y', 'Y'
6607 , NULL
6608 )
6609 )
6610
6611 INTO
6612 x_reserved_count
6613 , x_unreserved_count
6614 , x_prevented_count
6615
6616 FROM
6617 PO_DISTRIBUTIONS_ALL POD
6618 , PO_LINE_LOCATIONS_ALL POLL
6619 , PO_HEADERS_ALL POH
6620
6621 WHERE POLL.line_location_id(+) = POD.line_location_id
6622 AND POH.po_header_id = POD.po_header_id
6623 AND
6624 ( (p_doc_type <> g_doc_type_PA AND NVL(POLL.cancel_flag,'N') <> 'Y')
6625 OR (p_doc_type = g_doc_type_PA AND NVL(POH.cancel_flag,'N') <> 'Y')
6626 )
6627 AND
6628 (
6629 ( p_doc_type <> g_doc_type_PA
6630 AND NVL(POLL.closed_code,g_clsd_OPEN) <> g_clsd_FINALLY_CLOSED
6631 )
6632 OR
6633 ( p_doc_type = g_doc_type_PA
6634 AND NVL(POH.closed_code,g_clsd_OPEN) <> g_clsd_FINALLY_CLOSED
6635 )
6636 )
6637 AND
6638 (
6639 ( p_doc_level = g_doc_level_DISTRIBUTION
6640 AND POD.po_distribution_id = p_doc_level_id
6641 )
6642 OR
6643 ( p_doc_level = g_doc_level_SHIPMENT
6644 AND POD.line_location_id = p_doc_level_id
6645 )
6646 OR
6647 ( p_doc_level = g_doc_level_LINE
6648 AND POD.po_line_id = p_doc_level_id
6649 )
6650 OR
6651 ( p_doc_level = g_doc_level_HEADER
6652 AND p_doc_type = g_doc_type_RELEASE
6653 AND POD.po_release_id = p_doc_level_id
6654 )
6655 OR
6656 ( p_doc_level = g_doc_level_HEADER
6657 AND p_doc_type <> g_doc_type_RELEASE
6658 AND POD.po_header_id = p_doc_level_id
6659 )
6660 )
6661 -- Make sure that release dists are not picked up for BPAs, PPOs.
6662 AND
6663 (
6664 ( p_doc_type <> g_doc_type_RELEASE
6665 AND POD.po_release_id IS NULL
6666 )
6667 OR
6668 ( p_doc_type = g_doc_type_RELEASE
6669 AND POD.po_release_id IS NOT NULL
6670 )
6671 )
6672 ;
6673
6674 l_progress := '290';
6675
6676 END IF;
6677
6678 IF g_debug_stmt THEN
6679 PO_DEBUG.debug_stmt(l_log_head,l_progress,'got encumbrance counts');
6680 END IF;
6681
6682 l_progress := '900';
6683 IF g_debug_stmt THEN
6684 PO_DEBUG.debug_var(l_log_head,l_progress,'x_reserved_count',x_reserved_count);
6685 PO_DEBUG.debug_var(l_log_head,l_progress,'x_unreserved_count',x_unreserved_count);
6686 PO_DEBUG.debug_var(l_log_head,l_progress,'x_prevented_count',x_prevented_count);
6687 PO_DEBUG.debug_end(l_log_head);
6688 END IF;
6689
6690 EXCEPTION
6691 WHEN OTHERS THEN
6692 IF g_debug_unexp THEN
6693 PO_DEBUG.debug_var(l_log_head,l_progress,'x_reserved_count',x_reserved_count);
6694 PO_DEBUG.debug_var(l_log_head,l_progress,'x_unreserved_count',x_unreserved_count);
6695 PO_DEBUG.debug_var(l_log_head,l_progress,'x_prevented_count',x_prevented_count);
6696 PO_DEBUG.debug_exc(l_log_head,l_progress);
6697 END IF;
6698 RAISE;
6699
6700 END get_open_encumbrance_stats;
6701
6702
6703
6704
6705 --------------------------------------------------------------------------------
6706 --Start of Comments
6707 --Name: should_display_reserved
6708 --Pre-reqs:
6709 -- None.
6710 --Modifies:
6711 -- None.
6712 --Locks:
6713 -- None.
6714 --Function:
6715 -- Determines whether or not the status of the given entity should display
6716 -- as "Reserved".
6717 -- This procedure is being used by functions that are embedded in SQL
6718 -- statements in other products (views, etc.), so it is not allowed
6719 -- to modify anything (except in an autonomous transaction).
6720 --Parameters:
6721 --IN:
6722 --p_doc_type
6723 -- Document type. Use the g_doc_type_<> variables, where <> is:
6724 -- REQUISITION
6725 -- PA
6726 -- PO
6727 -- RELEASE
6728 --p_doc_level
6729 -- The type of ids that are being passed. Use g_doc_level_<>
6730 -- HEADER
6731 -- LINE
6732 -- SHIPMENT
6733 -- DISTRIBUTION
6734 --p_doc_level_id
6735 -- Id of the doc level type on which the action is being taken.
6736 --OUT:
6737 --x_display_reserved_flag
6738 -- VARCHAR2(1)
6739 -- 'Y' - "Reserved" should be displayed
6740 -- 'N' - don't display "Reserved"
6741 --End of Comments
6742 --------------------------------------------------------------------------------
6743 PROCEDURE should_display_reserved(
6744 p_doc_type IN VARCHAR2
6745 , p_doc_level IN VARCHAR2
6746 , p_doc_level_id IN NUMBER
6747 , x_display_reserved_flag OUT NOCOPY VARCHAR2
6748 )
6749 IS
6750
6751 l_proc_name CONSTANT VARCHAR2(30) := 'SHOULD_DISPLAY_RESERVED';
6752 l_log_head CONSTANT VARCHAR2(100) := g_log_head || l_proc_name;
6753 l_progress VARCHAR2(3) := '000';
6754
6755 l_reserved_count NUMBER;
6756 l_unreserved_count NUMBER;
6757 l_prevented_count NUMBER;
6758
6759 BEGIN
6760
6761 IF g_debug_stmt THEN
6762 PO_DEBUG.debug_begin(l_log_head);
6763 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_type',p_doc_type);
6764 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_level',p_doc_level);
6765 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_level_id',p_doc_level_id);
6766 END IF;
6767
6768 l_progress := '010';
6769
6770 get_open_encumbrance_stats(
6771 p_doc_type => p_doc_type
6772 , p_doc_level => p_doc_level
6773 , p_doc_level_id => p_doc_level_id
6774 , x_reserved_count => l_reserved_count
6775 , x_unreserved_count => l_unreserved_count
6776 , x_prevented_count => l_prevented_count
6777 );
6778
6779 l_progress := '020';
6780
6781 IF (l_unreserved_count = 0 AND l_reserved_count > 0) THEN
6782 x_display_reserved_flag := 'Y';
6783 ELSE
6784 x_display_reserved_flag := 'N';
6785 END IF;
6786
6787 l_progress := '900';
6788 IF g_debug_stmt THEN
6789 PO_DEBUG.debug_var(l_log_head,l_progress,'x_display_reserved_flag',x_display_reserved_flag);
6790 PO_DEBUG.debug_end(l_log_head);
6791 END IF;
6792
6793 EXCEPTION
6794 WHEN OTHERS THEN
6795 IF g_debug_unexp THEN
6796 PO_DEBUG.debug_var(l_log_head,l_progress,'x_display_reserved_flag',x_display_reserved_flag);
6797 PO_DEBUG.debug_exc(l_log_head,l_progress);
6798 END IF;
6799 RAISE;
6800
6801 END should_display_reserved;
6802
6803
6804
6805
6806 --------------------------------------------------------------------------------
6807 --Start of Comments
6808 --Name: is_fully_reserved
6809 --Pre-reqs:
6810 -- None.
6811 --Modifies:
6812 -- None.
6813 --Locks:
6814 -- None.
6815 --Function:
6816 -- Determines whether or not all of the distributions below the given entity that
6817 -- can be reserved are reserved.
6818 --Parameters:
6819 --IN:
6820 --p_doc_type
6821 -- Document type. Use the g_doc_type_<> variables, where <> is:
6822 -- REQUISITION
6823 -- PA
6824 -- PO
6825 -- RELEASE
6826 --p_doc_level
6827 -- The type of ids that are being passed. Use g_doc_level_<>
6828 -- HEADER
6829 -- LINE
6830 -- SHIPMENT
6831 -- DISTRIBUTION
6832 --p_doc_level_id
6833 -- Id of the doc level type on which the action is being taken.
6834 --OUT:
6835 --x_fully_reserved_flag
6836 -- VARCHAR2(1)
6837 -- 'Y' - all of the dists that can be reserved are reserved
6838 -- 'N' - there is at least one non-prevent dist that is not reserved
6839 --End of Comments
6840 --------------------------------------------------------------------------------
6841 PROCEDURE is_fully_reserved(
6842 p_doc_type IN VARCHAR2
6843 , p_doc_level IN VARCHAR2
6844 , p_doc_level_id IN NUMBER
6845 , x_fully_reserved_flag OUT NOCOPY VARCHAR2
6846 )
6847 IS
6848
6849 l_proc_name CONSTANT VARCHAR2(30) := 'IS_FULLY_RESERVED';
6850 l_log_head CONSTANT VARCHAR2(100) := g_log_head || l_proc_name;
6851 l_progress VARCHAR2(3) := '000';
6852
6853 l_reserved_count NUMBER;
6854 l_unreserved_count NUMBER;
6855 l_prevented_count NUMBER;
6856
6857 BEGIN
6858
6859 IF g_debug_stmt THEN
6860 PO_DEBUG.debug_begin(l_log_head);
6861 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_type',p_doc_type);
6862 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_level',p_doc_level);
6863 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_level_id',p_doc_level_id);
6864 END IF;
6865
6866 l_progress := '010';
6867
6868 get_open_encumbrance_stats(
6869 p_doc_type => p_doc_type
6870 , p_doc_level => p_doc_level
6871 , p_doc_level_id => p_doc_level_id
6872 , x_reserved_count => l_reserved_count
6873 , x_unreserved_count => l_unreserved_count
6874 , x_prevented_count => l_prevented_count
6875 );
6876
6877 l_progress := '020';
6878
6879 IF (l_unreserved_count > 0) THEN
6880 x_fully_reserved_flag := 'N';
6881 ELSE
6882 x_fully_reserved_flag := 'Y';
6883 END IF;
6884
6885 l_progress := '900';
6886 IF g_debug_stmt THEN
6887 PO_DEBUG.debug_var(l_log_head,l_progress,'x_fully_reserved_flag',x_fully_reserved_flag);
6888 PO_DEBUG.debug_end(l_log_head);
6889 END IF;
6890
6891 EXCEPTION
6892 WHEN OTHERS THEN
6893 IF g_debug_unexp THEN
6894 PO_DEBUG.debug_var(l_log_head,l_progress,'x_fully_reserved_flag',x_fully_reserved_flag);
6895 PO_DEBUG.debug_exc(l_log_head,l_progress);
6896 END IF;
6897 RAISE;
6898
6899 END is_fully_reserved;
6900
6901
6902
6903
6904 --------------------------------------------------------------------------------
6905 --Start of Comments
6906 --Name: are_any_dists_reserved
6907 --Pre-reqs:
6908 -- None.
6909 --Modifies:
6910 -- None.
6911 --Locks:
6912 -- None.
6913 --Function:
6914 -- Determines if any of the distributions below the given entity are reserved.
6915 --Parameters:
6916 --IN:
6917 --p_doc_type
6918 -- Document type. Use the g_doc_type_<> variables, where <> is:
6919 -- REQUISITION
6920 -- PA
6921 -- PO
6922 -- RELEASE
6923 --p_doc_level
6924 -- The type of ids that are being passed. Use g_doc_level_<>
6925 -- HEADER
6926 -- LINE
6927 -- SHIPMENT
6928 -- DISTRIBUTION
6929 --p_doc_level_id
6930 -- Id of the doc level type on which the action is being taken.
6931 --OUT:
6932 --x_some_dists_reserved_flag
6933 -- VARCHAR2(1)
6934 -- 'Y' - at least one distribution is reserved
6935 -- 'N' - no distributions are reserved
6936 --End of Comments
6937 --------------------------------------------------------------------------------
6938 PROCEDURE are_any_dists_reserved(
6939 p_doc_type IN VARCHAR2
6940 , p_doc_level IN VARCHAR2
6941 , p_doc_level_id IN NUMBER
6942 , x_some_dists_reserved_flag OUT NOCOPY VARCHAR2
6943 )
6944 IS
6945
6946 l_proc_name CONSTANT VARCHAR2(30) := 'ARE_ANY_DISTS_RESERVED';
6947 l_log_head CONSTANT VARCHAR2(100) := g_log_head || l_proc_name;
6948 l_progress VARCHAR2(3) := '000';
6949
6950 l_reserved_count NUMBER;
6951 l_unreserved_count NUMBER;
6952 l_prevented_count NUMBER;
6953
6954 BEGIN
6955
6956 IF g_debug_stmt THEN
6957 PO_DEBUG.debug_begin(l_log_head);
6958 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_type',p_doc_type);
6959 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_level',p_doc_level);
6960 PO_DEBUG.debug_var(l_log_head,l_progress,'p_doc_level_id',p_doc_level_id);
6961 END IF;
6962
6963 l_progress := '010';
6964
6965 get_open_encumbrance_stats(
6966 p_doc_type => p_doc_type
6967 , p_doc_level => p_doc_level
6968 , p_doc_level_id => p_doc_level_id
6969 , x_reserved_count => l_reserved_count
6970 , x_unreserved_count => l_unreserved_count
6971 , x_prevented_count => l_prevented_count
6972 );
6973
6974 l_progress := '020';
6975
6976 IF (l_reserved_count > 0) THEN
6977 x_some_dists_reserved_flag := 'Y';
6978 ELSE
6979 x_some_dists_reserved_flag := 'N';
6980 END IF;
6981
6982 l_progress := '900';
6983 IF g_debug_stmt THEN
6984 PO_DEBUG.debug_var(l_log_head,l_progress,'x_some_dists_reserved_flag',x_some_dists_reserved_flag);
6985 PO_DEBUG.debug_end(l_log_head);
6986 END IF;
6987
6988 EXCEPTION
6989 WHEN OTHERS THEN
6990 IF g_debug_unexp THEN
6991 PO_DEBUG.debug_var(l_log_head,l_progress,'x_some_dists_reserved_flag',x_some_dists_reserved_flag);
6992 PO_DEBUG.debug_exc(l_log_head,l_progress);
6993 END IF;
6994 RAISE;
6995
6996 END are_any_dists_reserved;
6997
6998
6999
7000
7001 --------------------------------------------------------------------------------
7002 --Start of Comments
7003 --Name: get_reserved_lookup
7004 --Pre-reqs:
7005 -- None.
7006 --Modifies:
7007 -- None.
7008 --Locks:
7009 -- None.
7010 --Function:
7011 -- Gets the text to display for the "Reserved" keyword.
7012 --Parameters:
7013 --OUT:
7014 --x_displayed_field
7015 -- PO_LOOKUP_CODES.displayed_field%TYPE
7016 -- The text corresponding to the 'RESERVED' code.
7017 --End of Comments
7018 --------------------------------------------------------------------------------
7019 PROCEDURE get_reserved_lookup(
7023
7020 x_displayed_field OUT NOCOPY VARCHAR2
7021 )
7022 IS
7024 l_proc_name CONSTANT VARCHAR2(30) := 'GET_RESERVED_LOOKUP';
7025 l_log_head CONSTANT VARCHAR2(100) := g_log_head || l_proc_name;
7026 l_progress VARCHAR2(3) := '000';
7027
7028 BEGIN
7029
7030 IF g_debug_stmt THEN
7031 PO_DEBUG.debug_begin(l_log_head);
7032 END IF;
7033
7034 l_progress := '010';
7035
7036 SELECT POLC.displayed_field
7037 INTO x_displayed_field
7038 FROM PO_LOOKUP_CODES POLC
7039 WHERE POLC.lookup_type = 'DOCUMENT STATE'
7040 AND POLC.lookup_code = 'RESERVED'
7041 ;
7042
7043 l_progress := '900';
7044 IF g_debug_stmt THEN
7045 PO_DEBUG.debug_var(l_log_head,l_progress,'x_displayed_field',x_displayed_field);
7046 PO_DEBUG.debug_end(l_log_head);
7047 END IF;
7048
7049 EXCEPTION
7050 WHEN OTHERS THEN
7051 IF g_debug_unexp THEN
7052 PO_DEBUG.debug_var(l_log_head,l_progress,'x_displayed_field',x_displayed_field);
7053 PO_DEBUG.debug_exc(l_log_head,l_progress);
7054 END IF;
7055
7056 END get_reserved_lookup;
7057
7058
7059
7060
7061 -- Bug 3373453 START
7062 -------------------------------------------------------------------------------
7063 --Start of Comments
7064 --Name: validate_yes_no_param
7065 --Pre-reqs:
7066 -- None.
7067 --Modifies:
7068 -- None.
7069 --Locks:
7070 -- None.
7071 --Function:
7072 -- Validates that the given parameter value is one of the following:
7073 -- null, G_PARAMETER_YES, or G_PARAMETER_NO
7074 -- Returns an error for any other value.
7075 --Parameters:
7076 --IN:
7077 --p_parameter_name
7078 -- Name of the parameter; used in the error message
7079 --p_parameter_value
7080 -- Parameter value to be validated
7081 --OUT:
7082 --x_return_status
7083 -- FND_API.G_RET_STS_SUCCESS if the parameter value is valid.
7084 -- FND_API.G_RET_STS_ERROR if the parameter value is not valid.
7085 -- FND_API.G_RET_STS_UNEXP_ERROR if an unexpected error occurred.
7086 --End of Comments
7087 -------------------------------------------------------------------------------
7088 PROCEDURE validate_yes_no_param (
7089 x_return_status OUT NOCOPY VARCHAR2,
7090 p_parameter_name IN VARCHAR2,
7091 p_parameter_value IN VARCHAR2
7092 ) IS
7093 l_proc_name CONSTANT VARCHAR2(30) := 'VALIDATE_YES_NO_PARAM';
7094 BEGIN
7095 x_return_status := FND_API.G_RET_STS_SUCCESS;
7096
7097 IF (p_parameter_value IS NOT NULL)
7098 AND (p_parameter_value NOT IN (G_PARAMETER_YES, G_PARAMETER_NO)) THEN
7099
7100 FND_MESSAGE.set_name('PO', 'PO_INVALID_YES_NO_PARAM');
7101 FND_MESSAGE.set_token('PARAMETER_NAME', p_parameter_name);
7102 FND_MESSAGE.set_token('PARAMETER_VALUE', p_parameter_value);
7103 FND_MSG_PUB.add;
7104
7105 x_return_status := FND_API.G_RET_STS_ERROR;
7106 RETURN;
7107 END IF;
7108
7109 EXCEPTION
7110 WHEN OTHERS THEN
7111 PO_DEBUG.handle_unexp_error(p_pkg_name => g_pkg_name,
7112 p_proc_name => l_proc_name );
7113 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7114 END validate_yes_no_param;
7115 -- Bug 3373453 END
7116
7117
7118
7119
7120 --------------------------------------------------------------------------------
7121 --Start of Comments
7122 --Name: get_session_gt_nextval
7123 --Pre-reqs:
7124 -- None.
7125 --Modifies:
7126 -- PO_SESSION_GT_S
7127 --Locks:
7128 -- None.
7129 --Function:
7130 -- Retrieves the next sequence number from the PO_SESSION_GT_S sequence.
7131 --Returns:
7132 -- PO_SESSION_GT_S.nextval
7133 --End of Comments
7134 --------------------------------------------------------------------------------
7135 FUNCTION get_session_gt_nextval
7136 RETURN NUMBER
7137 IS
7138
7139 l_proc_name CONSTANT VARCHAR2(30) := 'GET_SESSION_GT_NEXTVAL';
7140 l_log_head CONSTANT VARCHAR2(100) := g_log_head || l_proc_name;
7141 l_progress VARCHAR2(3) := '000';
7142
7143 x_nextval NUMBER;
7144
7145 BEGIN
7146
7147 IF g_debug_stmt THEN
7148 PO_DEBUG.debug_begin(l_log_head);
7149 END IF;
7150
7151 l_progress := '010';
7152
7153 SELECT PO_SESSION_GT_S.nextval
7154 INTO x_nextval
7155 FROM DUAL
7156 ;
7157
7158 l_progress := '900';
7159
7160 IF g_debug_stmt THEN
7161 PO_DEBUG.debug_var(l_log_head,l_progress,'x_nextval',x_nextval);
7162 PO_DEBUG.debug_end(l_log_head);
7163 END IF;
7164
7165 RETURN(x_nextval);
7166
7167 EXCEPTION
7168 WHEN OTHERS THEN
7169 PO_MESSAGE_S.sql_error(g_pkg_name,l_proc_name,l_progress,SQLCODE,SQLERRM);
7170 IF g_debug_stmt THEN
7171 PO_DEBUG.debug_var(l_log_head,l_progress,'x_nextval',x_nextval);
7172 END IF;
7173 RAISE;
7174
7175 END get_session_gt_nextval;
7176
7177
7178 -- <Doc Manager Rewrite 11.5.11 Start>
7179 -- port of deprecated user exit "REQUEST_INFO" for request code DOCUMENT_STATUS
7180 -- org_context should be set
7181 PROCEDURE get_document_status(
7182 p_document_id IN VARCHAR2
7183 , p_document_type IN VARCHAR2
7184 , p_document_subtype IN VARCHAR2
7185 , x_return_status OUT NOCOPY VARCHAR2
7186 , x_document_status OUT NOCOPY VARCHAR2
7187 )
7188 IS
7189
7193
7190 d_msg VARCHAR2(200);
7191 d_progress NUMBER;
7192 d_module VARCHAR2(70) := 'po.plsql.PO_CORE_S.get_document_status';
7194 l_sep VARCHAR2(8) := ', ';
7195 l_ret_sts VARCHAR2(1);
7196
7197 l_status_code PO_LOOKUP_CODES.displayed_field%TYPE;
7198 l_cancel_status PO_LOOKUP_CODES.displayed_field%TYPE;
7199 l_closed_status PO_LOOKUP_CODES.displayed_field%TYPE;
7200 l_frozen_status PO_LOOKUP_CODES.displayed_field%TYPE;
7201 l_hold_status PO_LOOKUP_CODES.displayed_field%TYPE;
7202 l_auth_status PO_HEADERS.authorization_status%TYPE;
7203 l_offline_status PO_LOOKUP_CODES.displayed_field%TYPE;
7204 l_reserved_status PO_LOOKUP_CODES.displayed_field%TYPE;
7205
7206 l_cancel_flag PO_HEADERS.cancel_flag%TYPE;
7207 l_closed_code PO_HEADERS.closed_code%TYPE;
7208 l_frozen_flag PO_HEADERS.frozen_flag%TYPE;
7209 l_user_hold_flag PO_HEADERS.user_hold_flag%TYPE;
7210 l_offline_flag PO_ACTION_HISTORY.offline_code%TYPE;
7211 l_reserved_flag VARCHAR2(1);
7212
7213 l_display_reserved VARCHAR2(1);
7214
7215 BEGIN
7216
7217 d_progress := 0;
7218 IF (PO_LOG.d_proc) THEN
7219 PO_LOG.proc_begin(d_module);
7220 PO_LOG.proc_begin(d_module, 'p_document_id', p_document_id);
7221 PO_LOG.proc_begin(d_module, 'p_document_type', p_document_type);
7222 PO_LOG.proc_begin(d_module, 'p_document_subtype', p_document_subtype);
7223 END IF;
7224
7225 BEGIN
7226
7227 IF (p_document_type = 'REQUISITION')
7228 THEN
7229
7230 d_progress := 20;
7231
7232 SELECT plc_sta.displayed_field
7233 , prh.authorization_status
7234 , DECODE(nvl(prh.closed_code,'OPEN'), 'OPEN', NULL, plc_clo.displayed_field)
7235 INTO l_status_code, l_auth_status, l_closed_status
7236 FROM po_requisition_headers prh, po_lookup_codes plc_sta, po_lookup_codes plc_clo
7237 WHERE plc_sta.lookup_code = DECODE(prh.authorization_status,
7238 'SYSTEM_SAVED', 'INCOMPLETE',
7239 nvl(prh.authorization_status, 'INCOMPLETE')
7240 )
7241 AND plc_clo.lookup_code = nvl(prh.closed_code, 'OPEN')
7242 AND plc_clo.lookup_type = 'DOCUMENT STATE'
7243 AND plc_sta.lookup_type = 'AUTHORIZATION STATUS'
7244 AND prh.requisition_header_id = p_document_id;
7245
7246 d_progress := 30;
7247
7248 BEGIN
7249
7250 SELECT polc.displayed_field, nvl(poah.offline_code, 'N')
7251 INTO l_offline_status, l_offline_flag
7252 FROM po_lookup_codes polc, po_action_history poah
7253 WHERE polc.lookup_type = 'DOCUMENT STATE'
7254 AND polc.lookup_code = poah.offline_code
7255 AND poah.object_id = p_document_id
7256 AND poah.object_type_code = 'REQUISITION'
7257 AND poah.action_code IS NULL;
7258
7259 EXCEPTION
7260 WHEN no_data_found THEN
7261 IF (PO_LOG.d_stmt) THEN
7262 PO_LOG.stmt(d_module, d_progress, 'No data found');
7263 END IF;
7264 END;
7265
7266 ELSIF (p_document_type IN ('PO', 'PA'))
7267 THEN
7268
7269 d_progress := 40;
7270
7271 SELECT plc_sta.displayed_field
7272 , DECODE(poh.cancel_flag, 'Y', plc_can.displayed_field, NULL)
7273 , DECODE(nvl(poh.closed_code,'OPEN'), 'OPEN', NULL, plc_clo.displayed_field)
7274 , DECODE(poh.frozen_flag, 'Y', plc_fro.displayed_field, NULL)
7275 , DECODE(poh.user_hold_flag, 'Y', plc_hld.displayed_field, NULL)
7276 , poh.authorization_status
7277 , nvl(poh.cancel_flag, 'N')
7278 , poh.closed_code
7279 , nvl(poh.frozen_flag, 'N')
7280 , nvl(poh.user_hold_flag,'N')
7281 INTO l_status_code
7282 , l_cancel_status
7283 , l_closed_status
7284 , l_frozen_status
7285 , l_hold_status
7286 , l_auth_status
7287 , l_cancel_flag
7288 , l_closed_code
7289 , l_frozen_flag
7290 , l_user_hold_flag
7291 FROM po_headers poh
7292 , po_lookup_codes plc_sta
7293 , po_lookup_codes plc_can
7294 , po_lookup_codes plc_clo
7295 , po_lookup_codes plc_fro
7296 , po_lookup_codes plc_hld
7297 WHERE plc_sta.lookup_code = DECODE(poh.approved_flag,
7298 'R', poh.approved_flag,
7299 nvl(poh.authorization_status, 'INCOMPLETE')
7300 )
7301 AND plc_sta.lookup_type in ('PO APPROVAL', 'DOCUMENT STATE')
7302 AND plc_can.lookup_code = 'CANCELLED'
7303 AND plc_can.lookup_type = 'DOCUMENT STATE'
7304 AND plc_clo.lookup_code = nvl(poh.closed_code, 'OPEN')
7305 AND plc_clo.lookup_type = 'DOCUMENT STATE'
7306 AND plc_fro.lookup_code = 'FROZEN'
7307 AND plc_fro.lookup_type = 'DOCUMENT STATE'
7308 AND plc_hld.lookup_code = 'ON HOLD'
7309 AND plc_hld.lookup_type = 'DOCUMENT STATE'
7310 AND poh.po_header_id = p_document_id;
7311
7312 d_progress := 50;
7313
7314 BEGIN
7315
7316 SELECT polc.displayed_field, nvl(poah.offline_code, 'N')
7317 INTO l_offline_status, l_offline_flag
7318 FROM po_lookup_codes polc, po_action_history poah
7319 WHERE polc.lookup_type = 'DOCUMENT STATE'
7320 AND polc.lookup_code = poah.offline_code
7321 AND poah.object_id = p_document_id
7322 AND poah.object_type_code IN ('PO', 'PA')
7323 AND poah.action_code IS NULL;
7324
7325 EXCEPTION
7329 END IF;
7326 WHEN no_data_found THEN
7327 IF (PO_LOG.d_stmt) THEN
7328 PO_LOG.stmt(d_module, d_progress, 'No data found');
7330 END;
7331
7332 ELSIF (p_document_type = 'RELEASE')
7333 THEN
7334
7335 d_progress := 60;
7336
7337 SELECT plc_sta.displayed_field
7338 , DECODE(por.cancel_flag, 'Y', plc_can.displayed_field, NULL)
7339 , DECODE(nvl(por.closed_code,'OPEN'), 'OPEN', NULL, plc_clo.displayed_field)
7340 , DECODE(por.frozen_flag, 'Y', plc_fro.displayed_field, NULL)
7341 , DECODE(por.hold_flag, 'Y', plc_hld.displayed_field, NULL)
7342 , por.authorization_status
7343 , nvl(por.cancel_flag, 'N')
7344 , por.closed_code
7345 , nvl(por.frozen_flag, 'N')
7346 , nvl(por.hold_flag,'N')
7347 INTO l_status_code
7348 , l_cancel_status
7349 , l_closed_status
7350 , l_frozen_status
7351 , l_hold_status
7352 , l_auth_status
7353 , l_cancel_flag
7354 , l_closed_code
7355 , l_frozen_flag
7356 , l_user_hold_flag
7357 FROM po_releases por
7358 , po_lookup_codes plc_sta
7359 , po_lookup_codes plc_can
7360 , po_lookup_codes plc_clo
7361 , po_lookup_codes plc_fro
7362 , po_lookup_codes plc_hld
7363 WHERE plc_sta.lookup_code = DECODE(por.approved_flag,
7364 'R', por.approved_flag,
7365 nvl(por.authorization_status, 'INCOMPLETE')
7366 )
7367 AND plc_sta.lookup_type in ('PO APPROVAL', 'DOCUMENT STATE')
7368 AND plc_can.lookup_code = 'CANCELLED'
7369 AND plc_can.lookup_type = 'DOCUMENT STATE'
7370 AND plc_clo.lookup_code = nvl(por.closed_code, 'OPEN')
7371 AND plc_clo.lookup_type = 'DOCUMENT STATE'
7372 AND plc_fro.lookup_code = 'FROZEN'
7373 AND plc_fro.lookup_type = 'DOCUMENT STATE'
7374 AND plc_hld.lookup_code = 'ON HOLD'
7375 AND plc_hld.lookup_type = 'DOCUMENT STATE'
7376 AND por.po_release_id = p_document_id;
7377
7378 d_progress := 70;
7379
7380 BEGIN
7381
7382 SELECT polc.displayed_field, nvl(poah.offline_code, 'N')
7383 INTO l_offline_status, l_offline_flag
7384 FROM po_lookup_codes polc, po_action_history poah
7385 WHERE polc.lookup_type = 'DOCUMENT STATE'
7386 AND polc.lookup_code = poah.offline_code
7387 AND poah.object_id = p_document_id
7388 AND poah.object_type_code = 'RELEASE'
7389 AND poah.action_code IS NULL;
7390
7391 EXCEPTION
7392 WHEN no_data_found THEN
7393 IF (PO_LOG.d_stmt) THEN
7394 PO_LOG.stmt(d_module, d_progress, 'No data found');
7395 END IF;
7396 END;
7397
7398 ELSE
7399
7400 d_progress := 80;
7401 d_msg := 'Invalid document type';
7402 RAISE g_early_return_exc;
7403
7404 END IF;
7405
7406 IF (PO_LOG.d_stmt) THEN
7407 PO_LOG.stmt(d_module, d_progress, 'l_status_code', l_status_code);
7408 PO_LOG.stmt(d_module, d_progress, 'l_cancel_status', l_cancel_status);
7409 PO_LOG.stmt(d_module, d_progress, 'l_closed_status', l_closed_status);
7410 PO_LOG.stmt(d_module, d_progress, 'l_frozen_status', l_frozen_status);
7411 PO_LOG.stmt(d_module, d_progress, 'l_auth_status', l_auth_status);
7412 PO_LOG.stmt(d_module, d_progress, 'l_cancel_flag', l_cancel_flag);
7413 PO_LOG.stmt(d_module, d_progress, 'l_closed_code', l_closed_code);
7414 PO_LOG.stmt(d_module, d_progress, 'l_frozen_flag', l_frozen_flag);
7415 PO_LOG.stmt(d_module, d_progress, 'l_user_hold_flag', l_user_hold_flag);
7416 PO_LOG.stmt(d_module, d_progress, 'l_offline_status', l_offline_status);
7417 PO_LOG.stmt(d_module, d_progress, 'l_offline_flag', l_offline_flag);
7418 END IF;
7419
7420 d_progress := 100;
7421
7422 should_display_reserved(
7423 p_doc_type => p_document_type
7424 , p_doc_level => g_doc_level_HEADER
7425 , p_doc_level_id => p_document_id
7426 , x_display_reserved_flag => l_display_reserved
7427 );
7428
7429 IF (l_display_reserved = 'Y')
7430 THEN
7431
7432 d_progress := 110;
7433 get_reserved_lookup(x_displayed_field => l_reserved_status);
7434
7435 ELSE
7436
7437 d_progress := 120;
7438 l_reserved_status := '';
7439
7440 END IF; -- l_display_reserved = 'Y';
7441
7442 d_progress := 130;
7443
7444 is_fully_reserved(
7445 p_doc_type => p_document_type
7446 , p_doc_level => g_doc_level_HEADER
7447 , p_doc_level_id => p_document_id
7448 , x_fully_reserved_flag => l_reserved_flag
7449 );
7450
7451 d_progress := 140;
7452
7453 IF (PO_LOG.d_stmt) THEN
7454 PO_LOG.stmt(d_module, d_progress, 'l_display_reserved', l_display_reserved);
7455 PO_LOG.stmt(d_module, d_progress, 'l_reserved_status', l_reserved_status);
7456 PO_LOG.stmt(d_module, d_progress, 'l_reserved_flag', l_reserved_flag);
7457 END IF;
7458
7459 x_document_status := l_status_code;
7460
7461 IF (l_cancel_status IS NOT NULL) THEN
7462 x_document_status := x_document_status || l_sep || l_cancel_status;
7463 END IF;
7464
7465 IF (l_closed_status IS NOT NULL) THEN
7466 x_document_status := x_document_status || l_sep || l_closed_status;
7467 END IF;
7468
7469 IF (l_frozen_status IS NOT NULL) THEN
7470 x_document_status := x_document_status || l_sep || l_frozen_status;
7471 END IF;
7472
7473 IF (l_hold_status IS NOT NULL) THEN
7474 x_document_status := x_document_status || l_sep || l_hold_status;
7475 END IF;
7476
7477 IF (l_reserved_status IS NOT NULL) THEN
7478 x_document_status := x_document_status || l_sep || l_reserved_status;
7479 END IF;
7480
7481 IF (l_offline_status IS NOT NULL) THEN
7482 x_document_status := x_document_status || l_sep || l_offline_status;
7483 END IF;
7484
7485 l_ret_sts := 'S';
7486
7487 EXCEPTION
7488 WHEN g_early_return_exc THEN
7489 l_ret_sts := 'U';
7490 IF (PO_LOG.d_exc) THEN
7491 PO_LOG.exc(d_module, d_progress, d_msg);
7492 END IF;
7493 END;
7494
7495 x_return_status := l_ret_sts;
7496
7497 IF (PO_LOG.d_proc) THEN
7498 PO_LOG.proc_end(d_module, 'x_return_status', x_return_status);
7499 PO_LOG.proc_end(d_module, 'p_document_status', x_document_status);
7500 PO_LOG.proc_end(d_module);
7501 END IF;
7502
7503 RETURN;
7504
7505 EXCEPTION
7506 WHEN others THEN
7507 x_return_status := 'U';
7508 IF (PO_LOG.d_exc) THEN
7509 PO_LOG.exc(d_module, d_progress, SQLCODE || SQLERRM);
7510 PO_LOG.proc_end(d_module, 'x_return_status', x_return_status);
7511 PO_LOG.proc_end(d_module);
7512 END IF;
7513
7514 RETURN;
7515
7516 END get_document_status;
7517
7518 -- port of deprecated user exit "DEFAULT_PRICE"
7519 -- org_context must be set
7520 -- previously, if p_uom <> x_return_uom, then the form fields would not be updated
7521 -- with the pl/sql change, it is up to the caller to check this condition.
7522 PROCEDURE get_default_price(
7523 p_src_doc_header_id IN NUMBER
7524 , p_src_doc_line_num IN NUMBER
7525 , p_deliver_to_loc_id IN NUMBER
7526 , p_required_currency IN VARCHAR2
7527 , p_required_rate_type IN VARCHAR2
7528 , p_quantity IN NUMBER
7529 , p_uom IN VARCHAR2
7530 , x_return_status OUT NOCOPY VARCHAR2
7531 , x_return_uom OUT NOCOPY VARCHAR2
7532 , x_base_price OUT NOCOPY NUMBER
7533 , x_currency_price OUT NOCOPY NUMBER
7534 , x_discount OUT NOCOPY NUMBER
7535 , x_currency_code OUT NOCOPY VARCHAR2
7536 , x_rate_type OUT NOCOPY VARCHAR2
7537 , x_rate_date OUT NOCOPY DATE
7538 , x_rate OUT NOCOPY NUMBER
7539 )
7540 IS
7541
7542 d_progress NUMBER;
7543 d_module VARCHAR2(70) := 'po.plsql.PO_CORE_S.get_default_price';
7544 d_msg VARCHAR2(200);
7545
7546 l_ret_sts VARCHAR2(1) := 'S';
7547 l_ship_to_loc_id HR_LOCATIONS.ship_to_location_id%TYPE;
7548
7549 l_do_non_loc_cursor BOOLEAN;
7550
7551 l_quantity NUMBER;
7552
7553 CURSOR loc_unit_price_cur( p_header_id NUMBER, p_line_num NUMBER
7554 , p_required_curr VARCHAR2, p_required_rate_type VARCHAR2
7555 , p_uom VARCHAR2, p_qty NUMBER, p_ship_to_loc_id NUMBER)
7556 IS
7557 SELECT ROUND(poll.price_override * DECODE(poh.rate, 0, 1, null, 1, ROUND(poh.rate,5)), 5)
7558 , poh.rate_date
7559 , poh.rate
7560 , poh.currency_code
7561 , poh.rate_type
7562 , poll.price_discount
7563 , poll.price_override
7564 , DECODE(poll.line_location_id, NULL, pol.unit_meas_lookup_code, poll.unit_meas_lookup_code)
7565 FROM po_headers poh, po_lines pol, po_line_locations poll
7566 WHERE poh.po_header_id = p_header_id
7567 AND poh.po_header_id = pol.po_header_id
7568 AND pol.line_num = p_line_num
7569 AND pol.po_line_id = poll.po_line_id (+)
7570 AND (p_required_curr IS NULL or poh.currency_code = p_required_curr)
7571 AND (p_required_rate_type is null or poh.rate_type = p_required_rate_type)
7572 AND NVL(poll.unit_meas_lookup_code, NVL(p_uom, pol.unit_meas_lookup_code))
7573 = NVL(p_uom, pol.unit_meas_lookup_code)
7574 AND trunc(sysdate) BETWEEN NVL(poll.start_date, trunc(sysdate)) AND NVL(poll.end_date, trunc(sysdate))
7575 AND poll.quantity <= p_qty
7576 AND poll.ship_to_location_id = p_ship_to_loc_id
7577 AND poll.shipment_type in ('PRICE BREAK', 'QUOTATION')
7578 ORDER BY 1 ASC;
7579
7580 CURSOR unit_price_cur( p_header_id NUMBER, p_line_num NUMBER
7581 , p_required_curr VARCHAR2, p_required_rate_type VARCHAR2
7582 , p_uom VARCHAR2, p_qty NUMBER)
7586 NULL, poll.price_override,pol.unit_price),
7583 IS
7584 SELECT ROUND(DECODE(poll.shipment_type,
7585 'PRICE BREAK', DECODE(poll.ship_to_location_id,
7587 'QUOTATION', DECODE(poll.ship_to_location_id,
7588 NULL,poll.price_override, pol.unit_price),
7589 pol.unit_price)
7590 * DECODE(poh.rate, 0, 1, null, 1, ROUND(poh.rate,5)), 5)
7591 , poh.rate_date
7592 , poh.rate
7593 , poh.currency_code
7594 , poh.rate_type
7595 , poll.price_discount
7596 , DECODE(poll.shipment_type,
7597 'PRICE BREAK', DECODE(poll.ship_to_location_id,
7598 NULL, poll.price_override ,pol.unit_price),
7599 'QUOTATION', DECODE(poll.ship_to_location_id,
7600 NULL,poll.price_override, pol.unit_price),
7601 pol.unit_price)
7602 , DECODE(poll.line_location_id, NULL, pol.unit_meas_lookup_code, poll.unit_meas_lookup_code)
7603 FROM po_headers poh, po_lines pol, po_line_locations poll
7604 WHERE poh.po_header_id = p_header_id
7605 AND poh.po_header_id = pol.po_header_id
7606 AND pol.line_num = p_line_num
7607 AND pol.po_line_id = poll.po_line_id (+)
7608 AND (p_required_curr IS NULL or poh.currency_code = p_required_curr)
7609 AND (p_required_rate_type is null or poh.rate_type = p_required_rate_type)
7610 AND NVL(poll.unit_meas_lookup_code, NVL(p_uom, pol.unit_meas_lookup_code))
7611 = NVL(p_uom, pol.unit_meas_lookup_code)
7612 AND trunc(sysdate) BETWEEN NVL(poll.start_date, trunc(sysdate)) AND NVL(poll.end_date, trunc(sysdate))
7613 AND poll.quantity <= p_qty
7614 ORDER BY 1 ASC;
7615
7616
7617 BEGIN
7618
7619 d_progress := 0;
7620 IF (PO_LOG.d_proc) THEN
7621 PO_LOG.proc_begin(d_module);
7622 PO_LOG.proc_begin(d_module, 'p_src_doc_header_id', p_src_doc_header_id);
7623 PO_LOG.proc_begin(d_module, 'p_src_doc_line_num', p_src_doc_line_num);
7624 PO_LOG.proc_begin(d_module, 'p_deliver_to_loc_id', p_deliver_to_loc_id);
7625 PO_LOG.proc_begin(d_module, 'p_required_currency', p_required_currency);
7626 PO_LOG.proc_begin(d_module, 'p_required_rate_type', p_required_rate_type);
7627 PO_LOG.proc_begin(d_module, 'p_quantity', p_quantity);
7628 PO_LOG.proc_begin(d_module, 'p_uom', p_uom);
7629 END IF;
7630
7631 d_progress := 5;
7632
7633 l_quantity := NVL(p_quantity, -1);
7634
7635 IF (PO_LOG.d_stmt) THEN
7636 PO_LOG.stmt(d_module, d_progress, 'l_quanity', l_quantity);
7637 END IF;
7638
7639 d_progress := 10;
7640
7641 BEGIN
7642
7643 SELECT hrl.ship_to_location_id
7644 INTO l_ship_to_loc_id
7645 FROM hr_locations hrl
7646 WHERE hrl.location_id = p_deliver_to_loc_id;
7647
7648 d_progress := 15;
7649
7650 EXCEPTION
7651 WHEN no_data_found THEN
7652 d_progress := 17;
7653 l_ship_to_loc_id := NULL;
7654 END;
7655
7656 IF (PO_LOG.d_stmt) THEN
7657 PO_LOG.stmt(d_module, d_progress, 'l_ship_to_loc_id', l_ship_to_loc_id);
7658 END IF;
7659
7660 d_progress := 20;
7661
7662 OPEN loc_unit_price_cur( p_src_doc_header_id, p_src_doc_line_num
7663 , p_required_currency, p_required_rate_type
7664 , p_uom, l_quantity, l_ship_to_loc_id);
7665
7666 d_progress := 25;
7667
7668 FETCH loc_unit_price_cur INTO
7669 x_base_price
7670 , x_rate_date
7671 , x_rate
7672 , x_currency_code
7673 , x_rate_type
7674 , x_discount
7675 , x_currency_price
7676 , x_return_uom;
7677
7678 IF (loc_unit_price_cur%NOTFOUND)
7679 THEN
7680 l_do_non_loc_cursor := TRUE;
7681 ELSE
7682 l_do_non_loc_cursor := FALSE;
7683 END IF;
7684
7685 d_progress := 30;
7686 IF (PO_LOG.d_stmt) THEN
7687 PO_LOG.stmt(d_module, d_progress, 'l_do_non_loc_cursor', l_do_non_loc_cursor);
7688 END IF;
7689
7690 IF loc_unit_price_cur%ISOPEN THEN
7691 CLOSE loc_unit_price_cur;
7692 END IF;
7693
7694 IF (l_do_non_loc_cursor)
7695 THEN
7696
7697 d_progress := 40;
7698
7699 OPEN unit_price_cur( p_src_doc_header_id, p_src_doc_line_num
7700 , p_required_currency, p_required_rate_type
7701 , p_uom, l_quantity);
7702
7703 d_progress := 45;
7704
7705 FETCH unit_price_cur INTO
7706 x_base_price
7707 , x_rate_date
7708 , x_rate
7709 , x_currency_code
7710 , x_rate_type
7711 , x_discount
7712 , x_currency_price
7713 , x_return_uom;
7714
7715 --<Bug 4654432 Start>
7716 -- Commenting out the following IF block because this is not really an
7717 -- unhandled exception condition. IF no data is found from the above
7718 -- cursor, then the price would not default, but the API should return
7719 -- without error.
7720 --IF (unit_price_cur%NOTFOUND)
7721 --THEN
7722 -- l_ret_sts := 'U';
7723 --END IF;
7724 --<Bug 4654432 End>
7725
7726 IF unit_price_cur%ISOPEN THEN
7727 CLOSE unit_price_cur;
7728 END IF;
7729
7730 END IF; -- IF l_do_non_loc_cursor
7731
7732 d_progress := 50;
7733
7734 x_return_status := l_ret_sts;
7735 IF (PO_LOG.d_proc) THEN
7736 PO_LOG.proc_end(d_module, 'x_return_status', x_return_status);
7740 PO_LOG.proc_end(d_module, 'x_discount', x_discount);
7737 PO_LOG.proc_end(d_module, 'x_return_uom', x_return_uom);
7738 PO_LOG.proc_end(d_module, 'x_base_price', x_base_price);
7739 PO_LOG.proc_end(d_module, 'x_currency_price', x_currency_price);
7741 PO_LOG.proc_end(d_module, 'x_currency_code', x_currency_code);
7742 PO_LOG.proc_end(d_module, 'x_rate_type', x_rate_type);
7743 PO_LOG.proc_end(d_module, 'x_rate_date', x_rate_date);
7744 PO_LOG.proc_end(d_module, 'x_rate', x_rate);
7745 PO_LOG.proc_end(d_module);
7746 END IF;
7747
7748 EXCEPTION
7749 WHEN OTHERS THEN
7750
7751 IF loc_unit_price_cur%ISOPEN THEN
7752 CLOSE loc_unit_price_cur;
7753 END IF;
7754
7755 IF unit_price_cur%ISOPEN THEN
7756 CLOSE unit_price_cur;
7757 END IF;
7758
7759 x_return_status := 'U';
7760
7761 IF (PO_LOG.d_exc) THEN
7762 PO_LOG.exc(d_module, d_progress, SQLCODE || SQLERRM);
7763 PO_LOG.proc_end(d_module, 'x_return_status', x_return_status);
7764 PO_LOG.proc_end(d_module);
7765 END IF;
7766
7767 RETURN;
7768 END get_default_price;
7769
7770
7771 -- <Doc Manager Rewrite 11.5.11 End>
7772
7773 -- <HTML Orders R12 Start>
7774 --------------------------------------------------------------------------------
7775 --Start of Comments
7776 --Name: flag_to_boolean
7777 --Pre-reqs:
7778 -- None.
7779 --Modifies:
7780 -- None.
7781 --Locks:
7782 -- None.
7783 --Function:
7784 -- Converts the given flag value (i.e. 'Y' or 'N') to a boolean.
7785 -- This is useful when invoking PL/SQL procedures from Java, since the
7786 -- OracleCallableStatement does not support boolean parameters.
7787 --Returns:
7788 -- TRUE if the flag value is 'Y', FALSE otherwise.
7789 --End of Comments
7790 --------------------------------------------------------------------------------
7791 FUNCTION flag_to_boolean (
7792 p_flag_value IN VARCHAR2
7793 ) RETURN BOOLEAN
7794 IS
7795 BEGIN
7796 RETURN (p_flag_value = 'Y');
7797 END flag_to_boolean;
7798
7799 --------------------------------------------------------------------------------
7800 --Start of Comments
7801 --Name: boolean_to_flag
7802 --Pre-reqs:
7803 -- None.
7804 --Modifies:
7805 -- None.
7806 --Locks:
7807 -- None.
7808 --Function:
7809 -- Converts the given boolean to a flag value (i.e. 'Y' or 'N').
7810 -- This is useful when invoking PL/SQL procedures from Java, since the
7811 -- OracleCallableStatement does not support boolean parameters.
7812 --Returns:
7813 -- 'Y' if the boolean value is TRUE, 'N' otherwise.
7814 --End of Comments
7815 --------------------------------------------------------------------------------
7816 FUNCTION boolean_to_flag (
7817 p_boolean_value IN BOOLEAN
7818 ) RETURN VARCHAR2
7819 IS
7820 BEGIN
7821 IF (p_boolean_value) THEN
7822 RETURN 'Y';
7823 ELSE
7824 RETURN 'N';
7825 END IF;
7826 END;
7827 -- <HTML Orders R12 End>
7828
7829 -- <R12 SLA>
7830 -------------------------------------------------------------------------------
7831 --Start of Comments
7832 --Name: Check_Federal_Instance
7833 --Pre-reqs:
7834 -- None.
7835 --Modifies:
7836 -- None.
7837 --Locks:
7838 -- None.
7839 --Function:
7840 -- This function will identify whether the instance identified by the Operating
7841 -- Unit specified by p_org_id is a federal instance or not.
7842 --Parameters:
7843 --IN:
7844 -- p_org_id
7845 -- This contains the org_id for which it needs to be verified whether it is
7846 -- a federal instance or not.
7847 --IN OUT:
7848 -- None
7849 --OUT:
7850 -- None
7851 --Returns:
7852 -- Returns 'Y'/'N'.
7853 --Notes:
7854 --
7855 --Testing:
7856 --
7857 --End of Comments
7858 -------------------------------------------------------------------------------
7859 FUNCTION Check_Federal_Instance (
7860 p_org_id IN hr_operating_units.organization_id%type
7861 )
7862 RETURN VARCHAR2
7863 IS
7864 x_progress VARCHAR2(3) := NULL;
7865 x_option_value VARCHAR2(1);
7866 BEGIN
7867 x_progress := 10;
7868
7869 x_option_value := Boolean_To_Flag (FV_INSTALL.enabled(p_org_id)) ;
7870
7871 RETURN(x_option_value);
7872
7873 EXCEPTION
7874 WHEN OTHERS THEN
7875 po_message_s.sql_error('Check_Federal_Customer', x_progress, sqlcode);
7876 RAISE;
7877 END Check_Federal_Instance;
7878
7879 --------------------------------------------------------------------------
7880 --Start of Comments
7881 --Name: GET_OUTSOURCED_ASSEMBLY
7882 --Pre-reqs: None.
7883 --Modifies: None.
7884 --Locks: None.
7885 --Function:
7886 -- This function returns OUTSOURCED_ASSEMBLY value by calling the
7887 -- JMF_SHIKYU_GRP.Validate_Osa_Flag procedure.
7888 -- OUTSOURCED_ASSEMBLY will be either 1 (SHIKYU) or 2 (NON-SHIKYU).
7889 --IN: p_item_id
7890 -- This contains unique item identifier.
7891 --IN: p_ship_to_org_id
7892 -- This contains the ship_to_org_id value.
7893 --IN OUT: None.
7894 --OUT: None.
7895 --Returns: The function returns OUTSOURCED_ASSEMBLY.
7896 --Notes:
7897 -- The algorithm of the function is as follows :
7898 -- Returns OUTSOURCED_ASSEMBLY for a given item_id and ship_to_org_id by calling
7899 -- JMF_SHIKYU_GRP.Validate_Osa_Flag procedure.
7900 --Testing:
7901 --
7902 --End of Comments
7903 -------------------------------------------------------------------------------
7904 FUNCTION get_outsourced_assembly( p_item_id IN NUMBER,
7905 p_ship_to_org_id IN NUMBER ) RETURN NUMBER IS
7906 l_osa_flag varchar2(1) := 'N';
7907 l_return_status varchar2(1);
7908 l_outsourced_assembly NUMBER ;
7909 l_progress VARCHAR2(3) := NULL;
7910 l_msg_count NUMBER;
7911 l_msg_data VARCHAR2(2000);
7912
7913 BEGIN
7914
7915 l_progress := 10;
7916
7917 -- bug4958421
7918 -- do not call JMF API if item id is NULL
7919
7920 IF (p_item_id IS NULL) THEN
7921 l_outsourced_assembly := 2;
7922
7923 ELSE
7924
7925 JMF_SHIKYU_GRP.Validate_Osa_Flag(
7926 p_api_version => 1.0,
7927 p_init_msg_list => FND_API.G_FALSE,
7928 x_return_status => l_return_status,
7929 x_msg_count => l_msg_count,
7930 x_msg_data => l_msg_data,
7931 p_inventory_item_id => p_item_id,
7932 p_vendor_id=> NULL,
7933 p_vendor_site_id => NULL ,
7934 p_ship_to_organization_id => p_ship_to_org_id,
7935 x_osa_flag => l_osa_flag );
7936
7937
7938 IF l_osa_flag = 'Y' THEN
7939 l_outsourced_assembly := 1;
7940 ELSE
7941 l_outsourced_assembly := 2;
7942 END IF;
7943
7944 END IF;
7945
7946 return l_outsourced_assembly;
7947
7948 EXCEPTION
7949 WHEN OTHERS THEN
7950 po_message_s.sql_error('Get_Outsourced_Assembly', l_progress, sqlcode);
7951 return 2;
7952 END get_outsourced_assembly;
7953
7954 --<R12 eTax Integration Start>
7955 -------------------------------------------------------------------------------
7956 --Start of Comments
7957 --Name: get_default_legal_entity_id
7958 --Pre-reqs:
7959 -- None
7960 --Modifies:
7961 -- None
7962 --Locks:
7963 -- None
7964 --Function:
7965 -- Return the default legal context given the org id
7966 --Parameters:
7967 --IN:
7968 --org_id
7969 -- Unique id for the operating unit
7970 --Returns:
7971 -- Default Legal Entity Id
7972 --End of Comments
7973 -------------------------------------------------------------------------------
7974 FUNCTION get_default_legal_entity_id(p_org_id IN NUMBER) RETURN NUMBER
7975 IS
7976 l_legal_entity_id NUMBER;
7977 l_module_name CONSTANT VARCHAR2(100) := 'GET_DEFAULT_LEGAL_ENTITY_ID';
7978 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(
7979 g_log_head, l_module_name);
7980 d_progress NUMBER;
7981 BEGIN
7982 IF (PO_LOG.d_proc) THEN
7983 PO_LOG.proc_begin(d_module_base);
7984 PO_LOG.proc_begin(d_module_base, 'p_org_id', p_org_id);
7985 END IF;
7986
7987 d_progress := 0;
7988 l_legal_entity_id := XLE_UTILITIES_GRP.Get_DefaultLegalContext_OU(p_org_id);
7989
7990 d_progress := 10;
7991 IF (PO_LOG.d_proc) THEN
7992 PO_LOG.proc_end(d_module_base);
7993 PO_LOG.proc_end(d_module_base, 'l_legal_entity_id', l_legal_entity_id);
7994 END IF;
7995
7996 d_progress := 20;
7997 return l_legal_entity_id;
7998 EXCEPTION
7999 WHEN OTHERS THEN
8000 IF (PO_LOG.d_exc) THEN
8001 PO_LOG.exc(d_module_base, d_progress, SQLCODE || SQLERRM);
8002 PO_LOG.proc_end(d_module_base);
8003 PO_LOG.proc_end(d_module_base, 'l_legal_entity_id', l_legal_entity_id);
8004 END IF;
8005
8006 RAISE;
8007 END get_default_legal_entity_id;
8008 --<R12 eTax Integration End>
8009
8010 --<HTML Agreements R12 Start>
8011 -------------------------------------------------------------------------------
8012 --Start of Comments
8013 --Name: get_last_update_date_for_doc
8014 --Pre-reqs:
8015 -- None
8016 --Modifies:
8017 -- None
8018 --Locks:
8019 -- None
8020 --Function:
8021 -- It returns the max of the last_update_date column from all the levels for a
8022 -- given document
8023 --Parameters:
8024 --IN:
8025 --p_doc_header_id
8026 -- Document header Id
8027 --Returns:
8028 -- latest last_update_date for the entire document
8029 --End of Comments
8033 header_last_update_date PO_HEADERS_ALL.last_update_date%type;
8030 -------------------------------------------------------------------------------
8031 FUNCTION get_last_update_date_for_doc(p_doc_header_id IN NUMBER) RETURN DATE
8032 IS
8034 line_last_update_date PO_LINES_ALL.last_update_date%type;
8035 line_loc_last_update_date PO_LINE_LOCATIONS_ALL.last_update_date%type;
8036 dist_last_update_date PO_DISTRIBUTIONS_ALL.last_update_date%type;
8037 doc_last_update_date PO_HEADERS_ALL.last_update_date%type;
8038 --Lowest date supported by database as we need to handle null dates
8039 min_date PO_HEADERS_ALL.last_update_date%type := to_date('01/01/-4712','DD/MM/SYYYY');
8040
8041 l_module_name CONSTANT VARCHAR2(100) := 'GET_LAST_UPDATE_DATE_FOR_DOC';
8042 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(g_log_head, l_module_name);
8043 d_pos NUMBER := 0;
8044
8045 BEGIN
8046 IF (PO_LOG.d_proc) THEN
8047 PO_LOG.proc_begin(d_module_base); PO_LOG.proc_begin(d_module_base, 'p_doc_header_id', p_doc_header_id);
8048 END IF;
8049 d_pos := 10;
8050 select nvl(max(last_update_date), min_date) into header_last_update_date from po_headers_all where po_header_id = p_doc_header_id;
8051 d_pos := 20;
8052 select nvl(max(last_update_date), min_date) into line_last_update_date from po_lines_all where po_header_id = p_doc_header_id;
8053 d_pos := 30;
8054 select nvl(max(last_update_date), min_date) into line_loc_last_update_date from po_line_locations_all where po_header_id = p_doc_header_id;
8055 d_pos := 40;
8056 select nvl(max(last_update_date), min_date) into dist_last_update_date from po_distributions_all where po_header_id = p_doc_header_id;
8057 d_pos := 50;
8058 doc_last_update_date := greatest( header_last_update_date
8059 ,line_last_update_date
8060 ,line_loc_last_update_date
8061 ,dist_last_update_date);
8062
8063 IF (PO_LOG.d_stmt) THEN
8064 PO_LOG.stmt(d_module_base, d_pos, 'doc_last_update_date', doc_last_update_date);
8065 END IF;
8066 d_pos := 60;
8067 IF (PO_LOG.d_proc) THEN
8068 PO_LOG.proc_end(d_module_base);
8069 END IF;
8070 return(doc_last_update_date);
8071 EXCEPTION
8072 WHEN OTHERS THEN
8073 FND_MSG_PUB.add_exc_msg(g_pkg_name, l_module_name|| ':'||d_pos);
8074 IF (PO_LOG.d_exc) THEN
8075 PO_LOG.exc(d_module_base, d_pos, SQLCODE || SQLERRM);
8076 END IF;
8077 RAISE;
8078 END;
8079 --<HTML Agreements R12 End>
8080
8081 -- <ACHTML R12 START>
8082 -------------------------------------------------------------------------------
8083 --Start of Comments
8084 --Name: is_equal
8085 --Pre-reqs:
8086 -- None
8087 --Modifies:
8088 -- None
8089 --Locks:
8090 -- None
8091 --Function:
8092 -- Determines whether two numbers are equal. They are equal if they are both
8093 -- null or have the same value.
8094 --Parameters:
8095 --IN:
8096 --p_attribute_primary
8097 -- The first number to compare with.
8098 --p_attribute_secondary
8099 -- The second number to compare with.
8100 --RETURNS:
8101 -- Boolean TRUE or FALSE indicating whether the two numbers are equal.
8102 --Notes:
8103 -- None
8104 --Testing:
8105 -- None
8106 --End of Comments
8107 -------------------------------------------------------------------------------
8108 FUNCTION is_equal(
8109 p_attribute_primary NUMBER,
8110 p_attribute_secondary NUMBER
8111 ) RETURN BOOLEAN
8112 IS
8113 l_is_equal BOOLEAN;
8114 BEGIN
8115 IF ((p_attribute_primary IS NULL AND p_attribute_secondary IS NULL)
8116 OR p_attribute_primary = p_attribute_secondary)
8117 THEN
8118 l_is_equal := TRUE;
8119 ELSE
8120 l_is_equal := FALSE;
8121 END IF;
8122
8123 RETURN l_is_equal;
8124 EXCEPTION
8125 WHEN OTHERS THEN
8126 RETURN FALSE;
8127 END is_equal;
8128 -- <ACHTML R12 END>
8129
8130 -- <ACHTML R12 START>
8131 -------------------------------------------------------------------------------
8132 --Start of Comments
8133 --Name: is_equal
8134 --Pre-reqs:
8135 -- None
8136 --Modifies:
8137 -- None
8138 --Locks:
8139 -- None
8140 --Function:
8141 -- Determines whether two varchars are equal. They are equal if they are both
8142 -- null or have the same value.
8143 --Parameters:
8144 --IN:
8145 --p_attribute_primary
8146 -- The first varchar to compare with.
8147 --p_attribute_secondary
8148 -- The second varchar to compare with.
8149 --RETURNS:
8150 -- Boolean TRUE or FALSE indicating whether the two varchars are equal.
8151 --Notes:
8152 -- None
8153 --Testing:
8154 -- None
8155 --End of Comments
8156 -------------------------------------------------------------------------------
8157 FUNCTION is_equal(
8158 p_attribute_primary VARCHAR2,
8159 p_attribute_secondary VARCHAR2
8160 ) RETURN BOOLEAN
8161 IS
8162 l_is_equal BOOLEAN;
8163 BEGIN
8164 IF ((p_attribute_primary IS NULL AND p_attribute_secondary IS NULL)
8165 OR p_attribute_primary = p_attribute_secondary)
8166 THEN
8167 l_is_equal := TRUE;
8168 ELSE
8169 l_is_equal := FALSE;
8170 END IF;
8171
8172 RETURN l_is_equal;
8173 EXCEPTION
8174 WHEN OTHERS THEN
8175 RETURN FALSE;
8176 END is_equal;
8177 -- <ACHTML R12 END>
8178
8179 -- <ACHTML R12 START>
8180 -------------------------------------------------------------------------------
8181 --Start of Comments
8182 --Name: is_equal_minutes
8183 --Pre-reqs:
8184 -- None
8185 --Modifies:
8186 -- None
8187 --Locks:
8188 -- None
8189 --Function:
8190 -- Determines whether two dates are equal up to the minute. They are equal if
8191 -- they are both null or have a difference of less than a minute.
8192 --Parameters:
8193 --IN:
8194 --p_attribute_primary
8195 -- The first date to compare with.
8196 --p_attribute_secondary
8197 -- The second date to compare with.
8198 --RETURNS:
8199 -- Boolean TRUE or FALSE indicating whether the two dates are equal up to the
8200 -- minute.
8201 --Notes:
8202 -- None
8203 --Testing:
8204 -- None
8205 --End of Comments
8206 -------------------------------------------------------------------------------
8207 FUNCTION is_equal_minutes(
8208 p_attribute_primary DATE,
8209 p_attribute_secondary DATE
8210 ) RETURN BOOLEAN
8211 IS
8212 l_is_equal BOOLEAN;
8213 BEGIN
8214 IF ((p_attribute_primary IS NULL AND p_attribute_secondary IS NULL)
8215 OR trunc(p_attribute_primary, 'MI') = trunc(p_attribute_secondary, 'MI'))
8216 THEN
8217 l_is_equal := TRUE;
8218 ELSE
8219 l_is_equal := FALSE;
8220 END IF;
8221
8222 RETURN l_is_equal;
8223 EXCEPTION
8224 WHEN OTHERS THEN
8225 RETURN FALSE;
8226 END is_equal_minutes;
8227 -- <ACHTML R12 END>
8228
8229 -------------------------------------------------------------------------------
8230 --Start of Comments
8231 --Name: get_last_update_date_for_mod
8232 --Pre-reqs:
8233 -- None
8234 --Modifies:
8235 -- None
8236 --Locks:
8237 -- None
8238 --Function:
8239 -- It returns the max of the last_update_date column of draft tables from all
8240 -- the levels for a given document
8241 --Parameters:
8242 --IN:
8243 --p_doc_header_id
8244 -- Document header Id
8245 --Returns:
8246 -- latest last_update_date for the entire document
8247 --End of Comments
8248 -------------------------------------------------------------------------------
8249 FUNCTION get_last_update_date_for_mod(p_doc_id IN NUMBER) RETURN DATE
8250 IS
8251 draft_last_update_date PO_DRAFTS.last_update_date%type;
8252 header_last_update_date PO_HEADERS_DRAFT_ALL.last_update_date%type;
8253 line_last_update_date PO_LINES_DRAFT_ALL.last_update_date%type;
8254 line_loc_last_update_date PO_LINE_LOCATIONS_DRAFT_ALL.last_update_date%type;
8255 dist_last_update_date PO_DISTRIBUTIONS_DRAFT_ALL.last_update_date%type;
8256 mod_last_update_date PO_HEADERS_DRAFT_ALL.last_update_date%type;
8257 address_last_update_date po_headers_all_ext_b.last_update_date%type;
8258 org_assign_last_update_date po_ga_org_assign_draft.last_update_date%type;
8259 --Lowest date supported by database as we need to handle null dates
8260 min_date PO_HEADERS_DRAFT_ALL.last_update_date%type := to_date('01/01/-4712','DD/MM/SYYYY');
8261
8262 l_module_name CONSTANT VARCHAR2(100) := 'GET_LAST_UPDATE_DATE_FOR_MOD';
8263 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(g_log_head, l_module_name);
8264 d_pos NUMBER := 0;
8265
8266 BEGIN
8267 IF (PO_LOG.d_proc) THEN
8268 PO_LOG.proc_begin(d_module_base); PO_LOG.proc_begin(d_module_base, 'p_doc_id', p_doc_id);
8269 END IF;
8270 d_pos := 10;
8271 select nvl(max(last_update_date), min_date) into header_last_update_date from po_headers_draft_all where draft_id = p_doc_id;
8272 d_pos := 20;
8273 select nvl(max(last_update_date), min_date) into line_last_update_date from po_lines_draft_all where draft_id = p_doc_id;
8274 d_pos := 30;
8275 select nvl(max(last_update_date), min_date) into line_loc_last_update_date from po_line_locations_draft_all where draft_id = p_doc_id;
8276 d_pos := 40;
8277 select nvl(max(last_update_date), min_date) into dist_last_update_date from po_distributions_draft_all where draft_id = p_doc_id;
8278 d_pos := 50;
8279 select nvl(max(last_update_date), min_date) into draft_last_update_date from po_drafts where draft_id = p_doc_id;
8280 d_pos := 60;
8281 -- Bugfix 9878931
8282 -- Fetch the last update date of the addresses of the modification document
8283 select nvl(max(last_update_date), min_date) into address_last_update_date from po_headers_all_ext_b where draft_id = p_doc_id;
8284 d_pos := 65;
8285 -- Bugfix 11774144
8286 select nvl(max(last_update_date), min_date) into org_assign_last_update_date from po_ga_org_assign_draft where draft_id = p_doc_id;
8287 d_pos := 70;
8288 mod_last_update_date := greatest( header_last_update_date
8289 ,line_last_update_date
8290 ,line_loc_last_update_date
8291 ,dist_last_update_date
8292 ,draft_last_update_date
8293 ,address_last_update_date
8294 ,org_assign_last_update_date);
8295
8296 IF (PO_LOG.d_stmt) THEN
8297 PO_LOG.stmt(d_module_base, d_pos, 'mod_last_update_date', mod_last_update_date);
8298 END IF;
8299 d_pos := 80;
8300 IF (PO_LOG.d_proc) THEN
8301 PO_LOG.proc_end(d_module_base);
8302 END IF;
8303 return(mod_last_update_date);
8304 EXCEPTION
8305 WHEN OTHERS THEN
8306 FND_MSG_PUB.add_exc_msg(g_pkg_name, l_module_name|| ':'||d_pos);
8307 IF (PO_LOG.d_exc) THEN
8308 PO_LOG.exc(d_module_base, d_pos, SQLCODE || SQLERRM);
8309 END IF;
8310 RAISE;
8311 END;
8312
8313 FUNCTION get_default_contract_officer(p_user_id IN NUMBER,p_emp_id IN NUMBER) RETURN VARCHAR2
8314 IS
8315 l_module_name CONSTANT VARCHAR2(100) := 'get_default_contract_officer';
8316 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(g_log_head, l_module_name);
8317 d_pos NUMBER := 0;
8318 l_contracting_officer VARCHAR2(50):= NULL;
8319 l_co_user_pref_count NUMBER;
8320 l_co_buyer_count NUMBER;
8321
8322 BEGIN
8323 IF (PO_LOG.d_proc) THEN
8324 PO_LOG.proc_begin(d_module_base); PO_LOG.proc_begin(d_module_base, 'p_user_id', p_user_id);
8325 PO_LOG.proc_begin(d_module_base); PO_LOG.proc_begin(d_module_base, 'p_emp_id', p_emp_id);
8326 END IF;
8327 d_pos := 10;
8328 BEGIN
8329
8330 SELECT CLM_CONTRACT_OFFICER
8331 INTO l_contracting_officer
8332 FROM po_user_preferences
8333 WHERE fnd_user_id=p_user_id
8334 AND PREFERENCE_TYPE='CONTRACT_OFFICER'
8335 AND FUNCTIONAL_AREA='PURCHASING'
8336 AND CLM_CONTRACT_OFFICER IS NOT NULL;
8337
8338 RETURN l_contracting_officer;
8339
8340 EXCEPTION WHEN No_Data_Found THEN
8341
8342 BEGIN
8343
8344 SELECT To_Char(EMPLOYEE_ID)
8345 INTO l_contracting_officer
8346 FROM po_buyers_val_v
8347 WHERE EMPLOYEE_ID = p_emp_id
8348 AND CONTRACT_OFFICER='Y';
8349
8350 RETURN l_contracting_officer;
8351 EXCEPTION WHEN No_Data_Found THEN
8352
8353 l_contracting_officer := NULL;
8354 RETURN l_contracting_officer;
8355
8356 END;
8357 END;
8358
8359 RETURN l_contracting_officer;
8360 EXCEPTION
8361 WHEN OTHERS THEN
8362 l_contracting_officer := NULL;
8363 RETURN l_contracting_officer;
8364 END;
8365
8366 -- <CLM-LnSc START>
8367 --Start of Comments
8368 --Name: GET_CREATE_DEFAULT_DIST
8369 --Function:
8370 -- Returns Y if Distributions should be automatically defaulted for the document
8371 -- Returns N if:
8372 -- a. Document Type is PO
8373 -- b. PO is CLM Enabled
8374 -- c. Encumbrance is On
8375 -- d. Profile 'PO:Default Distributions' is set to 'N'
8376 --Parameters:
8377 --IN:
8378 -- p_org_id
8379 -- PO org id
8380 -- p_style_id
8381 -- PO style id
8382 -- p_doc_sub_type
8383 -- PO doc Sub Type
8384 --End of Comments
8385 FUNCTION get_create_default_dist(
8386 p_org_id IN NUMBER,
8387 p_style_id IN NUMBER,
8388 p_doc_sub_type IN VARCHAR) RETURN VARCHAR2
8389 IS
8390 l_module_name CONSTANT VARCHAR2(100) := 'get_create_default_dist';
8391 d_module_base CONSTANT VARCHAR2(100) := PO_LOG.get_subprogram_base(g_log_head, l_module_name);
8392 d_pos NUMBER := 0;
8393 l_doc_type VARCHAR2(30);
8394 l_create_default_dist VARCHAR2(1):= 'Y';
8395 l_default_dist_option VARCHAR2(1):= 'Y';
8396 BEGIN
8397 IF (PO_LOG.d_proc) THEN
8398 PO_LOG.proc_begin(d_module_base); PO_LOG.proc_begin(d_module_base, 'p_org_id', p_org_id);
8399 PO_LOG.proc_begin(d_module_base); PO_LOG.proc_begin(d_module_base, 'p_style_id', p_style_id);
8400 PO_LOG.proc_begin(d_module_base); PO_LOG.proc_begin(d_module_base, 'p_doc_sub_type', p_doc_sub_type);
8401 END IF;
8402 d_pos := 10;
8403 -- Derive Document Type
8404 IF (p_doc_sub_type = 'STANDARD') THEN
8405 l_doc_type := g_doc_type_PO;
8406 ELSIF (p_doc_sub_type IN ('BLANKET', 'CONTRACT')) THEN
8407 l_doc_type := g_doc_type_PA;
8408 ELSE
8409 l_doc_type := g_doc_type_ANY;
8410 END IF;
8411
8412 d_pos := 20;
8413 l_default_dist_option := PO_CORE_S.retrieveOptionValue(p_org_id => p_org_id,
8414 p_option_column => PO_CORE_S.g_DEFAULT_DISTRIBUTIONS_COL);
8415 IF l_doc_type = g_doc_type_PO -- Document Type is PO
8416 AND PO_DOC_STYLE_HELPER.get_clm_flag(p_style_id) = 'Y' -- PO is CLM Enabled
8417 AND PO_CORE_S.is_encumbrance_on(l_doc_type, p_org_id) -- Encumbrance is On
8418 AND l_default_dist_option = 'N' -- Profile Value for PO:Default Distributions
8419 THEN
8420 d_pos := 30;
8421 l_create_default_dist := 'N';
8422 END IF; --IF p_doc_type = 'PO'...
8423
8424 IF (PO_LOG.d_stmt) THEN
8425 PO_LOG.stmt(d_module_base, d_pos, 'l_create_default_dist', l_create_default_dist);
8426 END IF;
8427 d_pos := 40;
8428 IF (PO_LOG.d_proc) THEN
8429 PO_LOG.proc_end(d_module_base);
8430 END IF;
8431 RETURN l_create_default_dist;
8432 EXCEPTION
8433 WHEN OTHERS THEN
8434 RETURN 'Y';
8435 END;
8436 -- <CLM-LnSc END>
8437
8438
8439 --Bug 11056822 Function to validate email address using regular expression
8440 FUNCTION is_email_valid(p_email_address VARCHAR2) RETURN BOOLEAN
8441 IS
8442
8443 BEGIN
8444
8445 IF REGEXP_LIKE(p_email_address, '^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Zz0-9]+$','i') THEN
8446 RETURN TRUE;
8447 ELSE
8448 RETURN FALSE;
8449 END IF;
8450
8451 END is_email_valid;
8452
8453 --------------------------------------------------------------------------------
8454 --Start of Comments
8455
8456 --Name: retrieveOptionValue
8457
8458 --Function:
8459 -- This will retrieve purchasing option value for the given org.
8460 -- Introduced this as part of CLM Controls Project
8461
8462 --Parameters:
8463
8464 --IN:
8465 -- p_org_id NUMBER
8466 -- p_option_column VARCHAR2
8467
8468 --End of Comments
8469 --------------------------------------------------------------------------------
8470
8471 FUNCTION retrieveOptionValue(
8472 p_org_id IN NUMBER
8473 , p_option_column IN VARCHAR2
8474 )
8475 RETURN VARCHAR2
8476
8477 IS
8478 l_query VARCHAR2(500);
8479 returnVal VARCHAR2(200) := NULL;
8480
8481 l_progress NUMBER := 0;
8482
8483 BEGIN
8484 PO_LOG.stmt(p_module_base => 'PO_PURCHASING_OPTIONS_UTIL',
8485 p_position => NULL ,
8486 p_message_text => 'retrieveOption function starts');
8487 PO_LOG.stmt(p_module_base => 'PO_PURCHASING_OPTIONS_UTIL',
8488 p_position => NULL ,
8489 p_message_text => 'p_org_id :' || p_org_id);
8490 PO_LOG.stmt(p_module_base => 'PO_PURCHASING_OPTIONS_UTIL',
8491 p_position => NULL ,
8492 p_message_text => 'p_option_column :' || p_option_column);
8493
8494
8495 l_query := 'SELECT ' || p_option_column
8496 || ' FROM PO_SYSTEM_PARAMETERS_ALL '
8497 || ' WHERE ORG_ID=' || p_org_id;
8498
8499 l_progress :=30;
8500 PO_LOG.stmt(p_module_base => 'PO_PURCHASING_OPTIONS_UTIL',
8501 p_position => NULL ,
8502 p_message_text => 'l_query:' || l_query);
8503
8504 EXECUTE IMMEDIATE l_query INTO returnVal;
8505
8506 l_progress := 100;
8507
8508 PO_LOG.stmt(p_module_base => 'PO_PURCHASING_OPTIONS_UTIL',
8509 p_position => NULL ,
8510 p_message_text => 'return value:' || returnVal);
8511 PO_LOG.stmt(p_module_base => 'PO_PURCHASING_OPTIONS_UTIL',
8512 p_position => NULL ,
8513 p_message_text => 'retrieveOption function ends');
8514 RETURN returnVal;
8515
8516 EXCEPTION
8517
8518 WHEN OTHERS THEN
8519 PO_LOG.stmt(p_module_base => 'PO_PURCHASING_OPTIONS_UTIL',
8520 p_position => NULL ,
8521 p_message_text => 'Error at :' || l_progress
8522 || ' error:' || SQLERRM);
8523 RETURN NULL;
8524 END retrieveOptionValue;
8525
8526 --------------------------------------------------------------------------------
8527 --Start of Comments
8528
8529 --Name: fndFunctionTestAsString
8530
8531 --Function:
8532 -- Wrapper for fnd_function.test
8533 -- Created for Protests project
8534
8535 --Parameters:
8536
8537 --IN:
8538 -- functionName VARCHAR2
8539
8540 --End of Comments
8541 --------------------------------------------------------------------------------
8542 FUNCTION fndFunctionTestAsString(
8543 functionName IN VARCHAR2
8544 )
8545 RETURN VARCHAR2
8546
8547 IS
8548 returnValue VARCHAR2(1) := 'F';
8549
8550 BEGIN
8551 IF (fnd_function.test(functionName)) THEN
8552 returnValue := 'T';
8553 END IF;
8554
8555 RETURN returnValue;
8556 END fndFunctionTestAsString;
8557
8558 END PO_CORE_S;