1 PACKAGE BODY po_copydoc_s2 AS
2 /* $Header: POXCPO2B.pls 120.3 2006/04/27 15:12:35 bao noship $*/
3
4
5 /****************************************************************
6 **** Nullify some attributes that need to be done so in the PO.
7 **** Set states to some flags.
8 **** Find next available po_header_id and segment1
9 *****************************************************************/
10 PROCEDURE validate_header(
11 x_action_code IN VARCHAR2,
12 x_to_doc_subtype IN po_headers.type_lookup_code%TYPE,
13 x_to_global_flag IN PO_HEADERS_ALL.global_agreement_flag%TYPE, -- FPI GA
14 x_po_header_record IN OUT NOCOPY PO_HEADERS%ROWTYPE,
15 x_to_segment1 IN po_headers.segment1%TYPE,
16 x_agent_id IN po_headers.agent_id%TYPE,
17 x_sob_id IN financials_system_parameters.set_of_books_id%TYPE,
18 x_inv_org_id IN financials_system_parameters.inventory_organization_id%TYPE,
19 x_online_report_id IN po_online_report_text.online_report_id%TYPE,
20 x_sequence IN OUT NOCOPY po_online_report_text.sequence%TYPE,
21 x_return_code OUT NOCOPY NUMBER
22 ) IS
23
24 COPYDOC_HEADER_FAILURE EXCEPTION;
25 x_progress VARCHAR2(4) := NULL;
26 x_rowid ROWID;
27
28 tmp_pay_on_code VARCHAR2(25) := NULL; -- <BUG 4766467>
29
30 BEGIN
31
32 po_copydoc_s1.copydoc_debug('validate_header()');
33
34 /***** Unchanged attributes:
35 government_context
36 org_id
37 comments
38 attribute_{category,1-15}
39 vendor_{id, site_id, contact_id}
40 {ship, bill}_to_location_id
41 terms_id (Does this need to be unique?)
42 ship_via_lookup_code
43 fob_lookup_code
44 freight_terms_lookup_code
45 currency_code
46 rate{,_type, _date}
47 mrc_rate{, _type, _date}
48 price_update_tolerance
49 pay_on_code -- <BUG 4776467> Changed pay_on_code
50 {start,end}_date
51 note_to_{authorizer, receiver}
52 agent_id
53 segment{1-5}
54 {start, end}_date_active
55 global_attribute{_category, 1-20}
56 ******/
57
58 /* FROM_HEADER_ID of a copied document contains the PO_HEADER_ID
59 of the original document. Otherwise it's null. We only perform
60 additional validation if this field is not null.
61 do the following two lines first before anything is changed.
62 */
63 x_po_header_record.from_header_id := x_po_header_record.po_header_id;
64 x_po_header_record.from_type_lookup_code := x_po_header_record.type_lookup_code;
65
66 -- Bug 3202754: Insert null for GA flag value of 'N'
67 IF (x_to_global_flag = 'Y') THEN -- FPI GA
68 x_po_header_record.global_agreement_flag := 'Y';
69 ELSE
70 x_po_header_record.global_agreement_flag := NULL;
71 END IF;
72
73 -- <GC FPJ START>
74 -- Firm flag is not applicable for contract document type
75
76 IF (x_to_doc_subtype = 'CONTRACT') THEN
77 x_po_Header_record.firm_status_lookup_code := 'N';
78 END IF;
79
80 -- <GC FPJ END>
81
82 -- <2740069 START>: If copying to a Global Agreement,
83 -- 'Firm' flag and 'Supply Agreement' flag should be set to 'N'.
84 --
85 IF ( x_to_global_flag = 'Y' )
86 THEN
87 x_po_header_record.firm_status_lookup_code := 'N';
88 x_po_header_record.supply_agreement_flag := 'N';
89 END IF;
90 --
91 -- <2740069 END>
92
93 -- <ENCUMBRANCE FPJ START>
94 IF(x_action_code = 'PO' AND x_to_doc_subtype = 'BLANKET') THEN
95
96 --If we don't want to copy BPA distribution, then reset the
97 --encumbrance required flag to 'N', which will prevent the
98 --distribution copy
99
100 If (PO_CORE_S.is_encumbrance_on(
101 p_doc_type => PO_CORE_S.g_doc_type_PA
102 , p_org_id => NULL) = FALSE) Then
103 --For encumbered BPA, the distribution will be copied only if
104 --BPA encumbrance is on.
105 x_po_header_record.encumbrance_required_flag := 'N';
106
107 Elsif (x_po_header_record.type_lookup_code <> 'BLANKET') Then
108 --Only copy distribution if FROM document is also a BPA
109 x_po_header_record.encumbrance_required_flag := 'N';
110 End If;
111
112 END IF; --action code is PO, to-doc is BPA
113 -- <ENCUMBRANCE FPJ END>
114
115 IF (x_action_code = 'QUOTATION') THEN
116 IF (x_po_header_record.quotation_class_code = 'CATALOG') THEN
117 x_po_header_record.type_lookup_code := 'BLANKET';
118
119 ELSIF (x_po_header_record.quotation_class_code = 'BID') THEN
120 IF (x_to_doc_subtype = 'PLANNED' OR x_to_doc_subtype = 'STANDARD') THEN
121 x_po_header_record.type_lookup_code := x_to_doc_subtype;
122 ELSE
123 -- fnd_message.debug('Invalid to_type for a bid quotation copy: ' || x_to_doc_subtype);
124 NULL;
125 END IF;
126 END IF;
127
128 /* Bug 1909325
129 Defaulted 'N' to acceptance_required_flag
130 If this value is NULL then these PO's cannot be queried from
131 'Acknowledge POs' */
132
133 x_po_header_record.supply_agreement_flag := 'N';
134 x_po_header_record.confirming_order_flag := 'N';
135 x_po_header_record.firm_status_lookup_code := 'N';
136 x_po_header_record.firm_date := NULL;
137 x_po_header_record.acceptance_required_flag := 'N';
138 x_po_header_record.acceptance_due_date := NULL;
139 x_po_header_record.blanket_total_amount := NULL;
140 x_po_header_record.amount_limit := NULL;
141 x_po_header_record.min_release_amount := NULL;
142
143 -- <BUG 4766467 START>
144 --
145 BEGIN
146
147 SELECT pay_on_code
148 INTO tmp_pay_on_code
149 FROM po_vendor_sites_all
150 WHERE vendor_site_id = x_po_header_record.vendor_site_id;
151
152 EXCEPTION
153 WHEN NO_DATA_FOUND THEN NULL;
154 END;
155
156 x_po_header_record.pay_on_code := tmp_pay_on_code ;
157 --
158 -- <BUG 4766467 END>
159
160 END IF; --action code is Quotation
161
162 /* Functionality for PA->RFQ Copy : dreddy
163 header related fields are processed */
164 IF (x_action_code = 'RFQ') THEN
165
166 /* Bug 1909325
167 Defaulted 'N' to acceptance_required_flag
168 If this value is NULL then these PO's cannot be queried from
169 'Acknowledge POs' */
170
171 x_po_header_record.type_lookup_code := 'RFQ';
172 x_po_header_record.quote_type_lookup_code := x_to_doc_subtype;
173 x_po_header_record.quotation_class_code := 'CATALOG';
174 x_po_header_record.status_lookup_code := 'I';
175 x_po_header_record.supply_agreement_flag := 'N';
176 x_po_header_record.confirming_order_flag := 'N';
177 x_po_header_record.firm_status_lookup_code := 'N';
178 x_po_header_record.firm_date := NULL;
179 x_po_header_record.acceptance_required_flag := 'N';
180 x_po_header_record.acceptance_due_date := NULL;
181 x_po_header_record.blanket_total_amount := NULL;
182 x_po_header_record.amount_limit := NULL;
183 x_po_header_record.min_release_amount := NULL;
184
185 END IF; --action code is RFQ
186
187 x_po_header_record.pcard_id := NULL;
188 x_po_header_record.last_updated_by := fnd_global.user_id;
189 x_po_header_record.last_update_date := SYSDATE;
190 x_po_header_record.last_update_login := fnd_global.login_id;
191 x_po_header_record.created_by := fnd_global.user_id;
192 x_po_header_record.creation_date := SYSDATE;
193
194 -- Standard WHO columns, not inserted
195 x_po_header_record.program_application_id := NULL;
196 x_po_header_record.program_id := NULL;
197 x_po_header_record.program_update_date := NULL;
198 x_po_header_record.request_id := NULL;
199
200 -- To be updated by WF.
201 x_po_header_record.wf_item_key := NULL;
202 x_po_header_record.wf_item_type := NULL;
203
204 -- EDI
205 x_po_header_record.edi_processed_flag := NULL;
206 x_po_header_record.edi_processed_status := NULL;
207 x_po_header_record.interface_source_code := NULL;
208 x_po_header_record.reference_num := NULL;
209
210 IF (x_action_code <> 'RFQ') THEN
211 x_po_header_record.quotation_class_code := NULL;
212 x_po_header_record.quote_type_lookup_code := NULL;
213 x_po_header_record.status_lookup_code := NULL;
214 END IF;
215
216 x_po_header_record.quote_vendor_quote_number := NULL;
217 x_po_header_record.quote_warning_delay := NULL;
218 x_po_header_record.quote_warning_delay_unit := NULL;
219 x_po_header_record.rfq_close_date := NULL;
220 x_po_header_record.reply_date := NULL;
221 x_po_header_record.reply_method_lookup_code := NULL;
222
223 x_po_header_record.revised_date := NULL;
224 x_po_header_record.revision_num := 0;
225 x_po_header_record.printed_date := NULL;
226 x_po_header_record.print_count := 0;
227
228 x_po_header_record.approval_required_flag := NULL;
229 x_po_header_record.approved_date := NULL;
230 x_po_header_record.approved_flag := NULL;
231 x_po_header_record.authorization_status := NULL;
232
233 x_po_header_record.frozen_flag := 'N';
234 x_po_header_record.cancel_flag := 'N';
235 x_po_header_record.closed_code := NULL;
236 x_po_header_record.closed_date := NULL;
237
238 x_po_header_record.user_hold_flag := NULL;
239
240 -- Bug 271011. vendor_order_num is unique to PDOI docs, so don't copy.
241 x_po_header_record.vendor_order_num := NULL;
242
243 /* bug 969442: The note to vendor field is nulled because it is specific to
244 a PO and also for a cancelled po case it contains the reason for cancel.
245 */
246 /* Bug# 1523449 draising
247 While using 'Copy Document' functionality from
248 Quotation to PO below line was nullifying the note_to_vendor field
249 in copied PO form. It shouldn't happen while copying from Quotation
250 to PO.Addded if condition that when x_action_code is 'QUOTATION' then
251 it will not nullify the note_to_vendor field */
252
253 IF (x_action_code <> 'QUOTATION') THEN
254 x_po_header_record.note_to_vendor := NULL;
255 END IF;
256
257 x_po_header_record.enabled_flag := 'Y';
258 x_po_header_record.summary_flag := 'N';
259
260 /** find the next available po_headers.po_header_id **/
261 x_progress := '001';
262 BEGIN
263 SELECT po_headers_s.nextval
264 INTO x_po_header_record.po_header_id
265 FROM SYS.DUAL;
266 EXCEPTION
267 WHEN OTHERS THEN
268 x_po_header_record.po_header_id := NULL;
269 po_copydoc_s1.copydoc_sql_error('validate_header', x_progress, sqlcode,
270 x_online_report_id,
271 x_sequence,
272 0, 0, 0);
273 RAISE COPYDOC_HEADER_FAILURE;
274 END;
275
276 IF (x_action_code = 'RFQ') THEN
277 -- we insert a row into the po_rfq_vendors. this contains the supplier
278 -- from the blanket header : RFQ Copy
279
280 po_copydoc_s6.insert_rfq_vendors(x_po_header_record.po_header_id,
281 x_po_header_record.vendor_id,
282 x_po_header_record.vendor_site_id,
283 x_po_header_record.vendor_contact_Id);
284
285 END IF;
286
287 IF (x_to_segment1 IS NULL) THEN
288
289 -- bug5176308
290 -- Get next availbale PO number by calling the API
291 IF (x_action_code = 'RFQ') THEN
292 x_progress := '002';
293
294 x_po_header_record.segment1 :=
295 PO_CORE_SV1.default_po_unique_identifier
296 ( x_table_name => 'PO_HEADERS_RFQ'
297 );
298
299 ELSE
300 x_progress := '02a';
301
302 x_po_header_record.segment1 :=
303 PO_CORE_SV1.default_po_unique_identifier
304 ( x_table_name => 'PO_HEADERS'
305 );
306 END IF;
307
308 ELSE
309 x_po_header_record.segment1 := x_to_segment1;
310 END IF;
311
312
313 x_return_code := 0;
314 po_copydoc_s1.copydoc_debug('End: validate_header()');
315
316 EXCEPTION
317 WHEN COPYDOC_HEADER_FAILURE THEN
318 x_return_code := -1;
319 WHEN OTHERS THEN
320 po_copydoc_s1.copydoc_sql_error('validate_header', x_progress, sqlcode,
321 x_online_report_id,
322 x_sequence,
323 0, 0, 0);
324 x_return_code := -1;
325 END validate_header;
326
327
328
329 END po_copydoc_s2;
330