DBA Data[Home] [Help]

PACKAGE BODY: APPS.PO_AUTOCREATE_PREPROC_PVT

Source


4 g_pkg_name    CONSTANT VARCHAR2(1000) := 'PO_AUTOCREATE_PREPROC_PVT';
1 PACKAGE BODY po_autocreate_preproc_pvt AS
2 /* $Header: PO_AUTOCREATE_PREPROC_PVT.plb 120.3 2011/12/09 13:47:10 snelloru ship $ */
3 
5 g_log_head    CONSTANT VARCHAR2(1000) := 'po.plsql.PO_AUTOCREATE_PREPROC_PVT.';
6 
7 g_debug_stmt  CONSTANT BOOLEAN := PO_DEBUG.is_debug_stmt_on;
8 g_debug_unexp CONSTANT BOOLEAN := PO_DEBUG.is_debug_unexp_on;
9 
10 
11 /* -------------------------------------------------------
12    ---------------- PRIVATE PROCEDURES -------------------
13    ------------------------------------------------------- */
14 
15 
16 /* ============================================================================
17      NAME: get_system_defaults
18      DESC: Derive system defaults(system parameters, profile parameters
19            and product parameters) and populate the global variables.
20            Refer PO_PDOI_PVT.init_startup_values and
21            PO_INTERFACE_S.get_system_defaults for more details
22 
23            The procedure does the following:
24 
25            - Get the correct OU and set the org context to
26   ============================================================================= */
27 
28 PROCEDURE get_system_defaults
29 IS
30 
31 l_api_name VARCHAR2(30) := 'GET SYSTEM DEFAULTS';
32 l_progress VARCHAR2(3) := '000';
33 
34 BEGIN
35 
36       -- po and financials system parameters
37       po_core_s.get_po_parameters(PO_AUTOCREATE_PARAMS.g_sys.currency_code,
38                                   PO_AUTOCREATE_PARAMS.g_sys.coa_id,
39                                   PO_AUTOCREATE_PARAMS.g_sys.po_encumbrance_flag,
40                                   PO_AUTOCREATE_PARAMS.g_sys.req_encumbrance_flag,
41                                   PO_AUTOCREATE_PARAMS.g_sys.sob_id,
42                                   PO_AUTOCREATE_PARAMS.g_sys.ship_to_location_id,
43                                   PO_AUTOCREATE_PARAMS.g_sys.bill_to_location_id,
44                                   PO_AUTOCREATE_PARAMS.g_sys.fob_lookup_code,
45                                   PO_AUTOCREATE_PARAMS.g_sys.freight_terms_lookup_code,
46                                   PO_AUTOCREATE_PARAMS.g_sys.terms_id,
47                                   PO_AUTOCREATE_PARAMS.g_sys.default_rate_type,
48                                   PO_AUTOCREATE_PARAMS.g_sys.taxable_flag,
49                                   PO_AUTOCREATE_PARAMS.g_sys.receiving_flag,
50                                   PO_AUTOCREATE_PARAMS.g_sys.enforce_buyer_name_flag,
51                                   PO_AUTOCREATE_PARAMS.g_sys.enforce_buyer_auth_flag,
52                                   PO_AUTOCREATE_PARAMS.g_sys.line_type_id,
53                                   PO_AUTOCREATE_PARAMS.g_sys.manual_po_num_type,
54                                   PO_AUTOCREATE_PARAMS.g_sys.user_defined_po_num_code,
55                                   PO_AUTOCREATE_PARAMS.g_sys.price_type_lookup_code,
56                                   PO_AUTOCREATE_PARAMS.g_sys.invoice_close_tolerance,
57                                   PO_AUTOCREATE_PARAMS.g_sys.receive_close_tolerance,
58                                   PO_AUTOCREATE_PARAMS.g_sys.security_structure_id,
59                                   PO_AUTOCREATE_PARAMS.g_sys.expense_accrual_code,
60                                   PO_AUTOCREATE_PARAMS.g_sys.master_inv_org_id,
61                                   PO_AUTOCREATE_PARAMS.g_sys.rev_sort_ordering,
62                                   PO_AUTOCREATE_PARAMS.g_sys.min_rel_amount,
63                                   PO_AUTOCREATE_PARAMS.g_sys.notify_blanket_flag,
64                                   PO_AUTOCREATE_PARAMS.g_sys.budgetary_control_flag,
65                                   PO_AUTOCREATE_PARAMS.g_sys.user_defined_req_num_code,
66                                   PO_AUTOCREATE_PARAMS.g_sys.rfq_required_flag,
67                                   PO_AUTOCREATE_PARAMS.g_sys.manual_req_num_type,
68                                   PO_AUTOCREATE_PARAMS.g_sys.enforce_full_lot_qty,
69                                   PO_AUTOCREATE_PARAMS.g_sys.disposition_warning_flag,
70                                   PO_AUTOCREATE_PARAMS.g_sys.reserve_at_completion_flag,
74                                   PO_AUTOCREATE_PARAMS.g_sys.default_quote_warning_delay,
71                                   PO_AUTOCREATE_PARAMS.g_sys.user_defined_rcpt_num_code,
72                                   PO_AUTOCREATE_PARAMS.g_sys.manual_rcpt_num_type,
73                                   PO_AUTOCREATE_PARAMS.g_sys.use_positions_flag,
75                                   PO_AUTOCREATE_PARAMS.g_sys.inspection_required_flag,
76                                   PO_AUTOCREATE_PARAMS.g_sys.user_defined_quote_num_code,
77                                   PO_AUTOCREATE_PARAMS.g_sys.manual_quote_num_type,
78                                   PO_AUTOCREATE_PARAMS.g_sys.user_defined_rfq_num_code,
79                                   PO_AUTOCREATE_PARAMS.g_sys.manual_rfq_num_type,
80                                   PO_AUTOCREATE_PARAMS.g_sys.ship_via_lookup_code,
81   	                          PO_AUTOCREATE_PARAMS.g_sys.qty_rcv_tolerance,
82   		                  PO_AUTOCREATE_PARAMS.g_sys.acceptance_required_flag);
83 
84          l_progress := '010';
85 
86          -- receiving parameters for defaulting org
87         RCV_CORE_S.get_receiving_controls
88                       ( x_line_loc_id => NULL,
89                         x_item_id     => NULL,
90                         x_vendor_id   => NULL,
91                         x_org_id      => PO_AUTOCREATE_PARAMS.g_sys.def_inv_org_id,
92                         x_enforce_ship_to_loc => PO_AUTOCREATE_PARAMS.g_sys.enforce_ship_to_loc,
93                         x_allow_substitutes => PO_AUTOCREATE_PARAMS.g_sys.allow_substitutes,
94                         x_routing_id => PO_AUTOCREATE_PARAMS.g_sys.routing_id,
95                         x_qty_rcv_tolerance => PO_AUTOCREATE_PARAMS.g_sys.qty_rcv_tolerance,
96                         x_qty_rcv_exception => PO_AUTOCREATE_PARAMS.g_sys.qty_rcv_exception,
97                         x_days_early_receipt => PO_AUTOCREATE_PARAMS.g_sys.days_early_receipt,
98                         x_days_late_receipt => PO_AUTOCREATE_PARAMS.g_sys.days_late_receipt,
99                         x_rcv_date_exception => PO_AUTOCREATE_PARAMS.g_sys.rcv_days_exception
100                     );
101 
102 EXCEPTION
103   WHEN OTHERS THEN
104 
105       IF g_debug_unexp THEN    --< Bug 3210331: use proper debugging >
106         PO_DEBUG.debug_exc(p_log_head => g_log_head||l_api_name,
107                           p_progress => l_progress);
108       END IF;
109 
110       -- CLM Phase 2 Changes : Error Handling
111       IF l_progress = '000' THEN
112        PO_AUTOCREATE_PVT.report_error('PO_AUTO_SYSTEM_DEFAULTS_ERR',x_token1_value => sqlerrm);
113       ELSE
114         PO_AUTOCREATE_PVT.report_error('PO_AUTO_RCV_CONTROLS_ERR',x_token1_value => sqlerrm);
115       END IF;
116       -- CLM Phase 2 changes end;
117 
118       PO_AUTOCREATE_PVT.wrapup;
119       po_message_s.sql_error('GET SYSTEM DEFAULTS',l_progress,sqlcode);
120       RAISE;
121 
122 END get_system_defaults;
123 
124 
125 
126 /* -------------------------------------------------------
127    ---------------- PUBLIC PROCEDURES -------------------
128    ------------------------------------------------------- */
129 
130 /* ============================================================================
131      NAME: process
132      DESC: Main Procedure for the AutoCreate Pre Processing logic which includes
133 
134            - Get System defaults and populate global variables
135              PO_AUTOCREATE_PARAMS.sys_param_rec_type
136 
137            - Lock interface record so that no other process consumes these
138              records. Locking the header interface itself might be sufficient.
139 
140            - Incase of ADD TO flow, lock the original document as well. This
141              lock will be released by the commit upon successful completion.
142              Incase of failure the rollback will release this lock.
143 
144    ============================================================================ */
145 
146 PROCEDURE process
147 IS
148 
149 l_api_name VARCHAR2(30) := 'process';
150 l_progress VARCHAR2(3) := '000';
151 
152 l_original_operating_unit_id    NUMBER;
153 l_req_operating_unit_id     PO_SYSTEM_PARAMETERS_ALL.org_id%TYPE;
154 l_purch_operating_unit_id   PO_SYSTEM_PARAMETERS_ALL.org_id%TYPE;
155 
156 l_org_context_changed    VARCHAR2(1) := 'N';
157 
158 BEGIN
159 
160             IF g_debug_stmt THEN
161                           PO_DEBUG.debug_begin(p_log_head => g_log_head||l_api_name);
162             END IF;
163 
164             /* Validate the Requisition OU Id and Purchasing OU Id.
165                Catch the Requisition OU Id and set the session to
166                Purchasing OU Id (If required) */
167             l_progress := '010';
168 
169             IF PO_AUTOCREATE_PARAMS.x_orig_org_id IS NOT NULL THEN
170               l_original_operating_unit_id := PO_AUTOCREATE_PARAMS.x_orig_org_id;
171             ELSE
172               l_original_operating_unit_id := po_moac_utils_pvt.get_current_org_id;
173             END IF;
174 
175             l_progress := '020';
176 
177             -- If requesting Org ID is not passed set it to  current operating unit id
178             IF (PO_AUTOCREATE_PARAMS.x_req_operating_unit_id IS NULL) THEN
179                 l_req_operating_unit_id := l_original_operating_unit_id;
180             ELSE
181                 l_req_operating_unit_id := PO_AUTOCREATE_PARAMS.x_req_operating_unit_id;
182             END IF;
183 
184             l_progress := '030';
185 
186             -- If purchasing Org ID is not passed then create PO in Req raising Operating Unit
187             IF (PO_AUTOCREATE_PARAMS.x_purch_operating_unit_id IS NULL) THEN
191             END IF;
188                 l_purch_operating_unit_id := l_req_operating_unit_id;
189             ELSE
190                 l_purch_operating_unit_id := PO_AUTOCREATE_PARAMS.x_purch_operating_unit_id;
192 
193              l_progress := '040';
194 
195             --Set the context of Purchasing Operating Unit
196             IF (l_purch_operating_unit_id IS NOT NULL
197                AND (l_req_operating_unit_id IS NULL
198                      OR
199                     l_purch_operating_unit_id <> l_req_operating_unit_id
200                    )
201                )
202             THEN
203                 l_org_context_changed := 'Y';
204                 PO_MOAC_UTILS_PVT.set_org_context(l_purch_operating_unit_id) ;
205             END IF;
206 
207             l_progress := '050';
208 
209             -- Initialize the Operating Units
210             PO_AUTOCREATE_PARAMS.g_purchasing_ou_id := l_purch_operating_unit_id;
211             PO_AUTOCREATE_PARAMS.g_hdr_requesting_ou_id := l_req_operating_unit_id;
212             po_autocreate_params.g_org_context_changed := l_org_context_changed;
213             po_autocreate_params.g_original_operating_unit_id := l_original_operating_unit_id;
214 
215             l_progress := '060';
216 
217            -- Determine the document_type, document_subtype and interface_source_code
218             SELECT document_type_code,
219                    document_subtype,
220                    nvl(interface_source_code,'NOCODE'),
221                    action,
222                    group_code,
223                    document_num,
224         		   process_code,
225                    draft_id
226               INTO PO_AUTOCREATE_PARAMS.g_document_type,
227                    PO_AUTOCREATE_PARAMS.g_document_subtype,
228                    PO_AUTOCREATE_PARAMS.g_interface_source_code,
229                    PO_AUTOCREATE_PARAMS.g_mode,
230                    PO_AUTOCREATE_PARAMS.g_group_code,
231                    PO_AUTOCREATE_PARAMS.g_old_document_num,
232 		           PO_AUTOCREATE_PARAMS.g_process_code,   -- Add to modification project
233                    PO_AUTOCREATE_PARAMS.g_draft_id -- CLM Phase2 autocreate grouping.
234                    /*now the draft id is populated from UI.
235                      this draft_id will be used all along*/
236               FROM po_headers_interface
237              WHERE interface_header_id = PO_AUTOCREATE_PARAMS.x_interface_header_id;
238 
239             l_progress := '070';
240 
241             /*CLM Phase 2 autocreate grouping. commenting out the code to hardcode g_group_code = 'REQUISITION' in case of clm po*/
242            /* IF po_autocreate_params.g_is_clm_po = 'Y'
243               THEN
244                 PO_AUTOCREATE_PARAMS.g_group_code := 'REQUISITION';
245             END IF;*/
246 
247             l_progress := '080';
248 
249             IF (PO_AUTOCREATE_PARAMS.g_document_type = 'PO' and
250                 PO_AUTOCREATE_PARAMS.g_document_subtype in ('STANDARD', 'PLANNED', 'RELEASE')) THEN
251                 PO_AUTOCREATE_PARAMS.g_calculate_tax_flag := 'Y';
252             END IF;
253 
254             l_progress := '090';
255 
256            -- Get the system defaults
257             get_system_defaults;
258 
259 
260 EXCEPTION
261    WHEN OTHERS THEN
262 
263     IF g_debug_unexp THEN    --< Bug 3210331: use proper debugging >
264         PO_DEBUG.debug_exc(p_log_head => g_log_head||l_api_name,
265                            p_progress => l_progress);
266     END IF;
267 
268     IF (l_org_context_changed = 'Y') THEN
269                  PO_MOAC_UTILS_PVT.set_org_context(l_original_operating_unit_id) ;
270     END IF;
271 
272     -- CLM Phase 2 Changes : Error Handling
273     PO_AUTOCREATE_PVT.report_error( 'PO_AUTO_PREPROC_ERR',x_token1_value => sqlerrm);
274 
275     po_message_s.sql_error('CREATE_PO',l_progress,sqlcode);
276     PO_AUTOCREATE_PVT.wrapup();
277     RAISE;
278 
279 END process;
280 
281 END PO_AUTOCREATE_PREPROC_PVT;