DBA Data[Home] [Help]

PACKAGE BODY: APPS.PO_DOCUMENT_ACTION_AUTH

Source


1 PACKAGE BODY PO_DOCUMENT_ACTION_AUTH AS
2 -- $Header: POXDAAPB.pls 120.2 2005/07/19 14:31:34 pthapliy noship $
3 
4 -- Private package constants
5 
6 g_pkg_name CONSTANT varchar2(30) := 'PO_DOCUMENT_ACTION_AUTH';
7 g_log_head CONSTANT VARCHAR2(50) := 'po.plsql.'|| g_pkg_name || '.';
8 
9 
10 -- Forward Declare Private Methods
11 
12 PROCEDURE get_supply_action_name(
13    p_action            IN          VARCHAR2
14 ,  p_document_type     IN          VARCHAR2
15 ,  p_document_subtype  IN          VARCHAR2
16 ,  x_supply_action     OUT NOCOPY  VARCHAR2
17 ,  x_return_status     OUT NOCOPY  VARCHAR2
18 );
19 
20 
21 -- Public Methods (to be used only by other DOCUMENT_ACTION packages)
22 
23 ------------------------------------------------------------------------------
24 --Start of Comments
25 --Name: approve
26 --Pre-reqs:
27 --  Document is locked.
28 --  Org context is set to that of document.
29 --Modifies:
30 --  None, directly.
31 --Locks:
32 --  None.
33 --Function:
34 --  This procedure handles logic to approves a document.
35 --  The logic is:
36 --    1. update action history
37 --    2. update document authorization status and approved flags
38 --    3. if not a PA, call appropriate supply action
39 --    4. if not a requisition, archive the document.
40 --Replaces:
41 --  This method covers some of the logic in poxdmaction in poxdm.lpc.
42 --Parameters:
43 --IN:
44 --  p_action_ctl_rec
45 --    Record containing all necessary parameters for action.
46 --OUT:
47 --  p_action_ctl_rec
48 --    Record contains variables that record output values depending
49 --    on the action.  All actions will populate at least a return_status.
50 --End of Comments
51 -------------------------------------------------------------------------------
52 PROCEDURE approve(
53    p_action_ctl_rec  IN OUT NOCOPY  PO_DOCUMENT_ACTION_PVT.doc_action_call_rec_type
54 )
55 IS
56 
57 l_ret_sts         VARCHAR2(1);
58 l_err_msg         VARCHAR2(200);
59 l_bool_ret_sts    BOOLEAN;
60 
61 l_msg_data        VARCHAR2(2000);
62 l_msg_count       NUMBER;
63 
64 d_progress        NUMBER;
65 d_module          VARCHAR2(70) := 'po.plsql.PO_DOCUMENT_ACTION_AUTH.approve';
66 
67 l_supply_action   VARCHAR2(40);
68 
69 BEGIN
70 
71   d_progress := 0;
72   IF (PO_LOG.d_proc) THEN
73     PO_LOG.proc_begin(d_module);
74     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.document_id', p_action_ctl_rec.document_id);
75     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.document_type', p_action_ctl_rec.document_type);
76     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.document_subtype', p_action_ctl_rec.document_subtype);
77     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.action', p_action_ctl_rec.action);
78     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.new_document_status', p_action_ctl_rec.new_document_status);
79     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.employee_id', p_action_ctl_rec.employee_id);
80   END IF;
81 
82   d_progress := 10;
83 
84   BEGIN
85 
86     IF (PO_LOG.d_stmt) THEN
87       PO_LOG.stmt(d_module, d_progress, 'Calling change_doc_auth_state');
88     END IF;
89 
90     PO_DOCUMENT_ACTION_UTIL.change_doc_auth_state(
91        p_document_id         => p_action_ctl_rec.document_id
92     ,  p_document_type       => p_action_ctl_rec.document_type
93     ,  p_document_subtype    => p_action_ctl_rec.document_subtype
94     ,  p_action              => 'APPROVE'
95     ,  p_fwd_to_id           => p_action_ctl_rec.forward_to_id
96     ,  p_offline_code        => p_action_ctl_rec.offline_code
97     ,  p_approval_path_id    => p_action_ctl_rec.approval_path_id
98     ,  p_note                => p_action_ctl_rec.note
99     ,  p_new_status          => PO_DOCUMENT_ACTION_PVT.g_doc_status_APPROVED
100     ,  p_notify_action       => 'APPROVAL'
101     ,  p_notify_employee     => p_action_ctl_rec.forward_to_id
102     ,  x_return_status       => l_ret_sts
103     );
104 
105     IF (l_ret_sts <> 'S')
106     THEN
107 
108        d_progress := 20;
109        p_action_ctl_rec.return_status := 'U';
110        l_err_msg := 'change_doc_auth_state not successful';
111        RAISE PO_CORE_S.g_early_return_exc;
112 
113     END IF;
114 
115     d_progress := 30;
116 
117     IF (p_action_ctl_rec.document_type <> 'PA')
118     THEN
119 
120       get_supply_action_name(
121          p_action           => p_action_ctl_rec.action
122       ,  p_document_type    => p_action_ctl_rec.document_type
123       ,  p_document_subtype => p_action_ctl_rec.document_subtype
124       ,  x_return_status    => l_ret_sts
125       ,  x_supply_action    => l_supply_action
126       );
127 
128       IF (l_ret_sts <> 'S')
129       THEN
130         d_progress := 40;
131         p_action_ctl_rec.return_status := 'U';
132         l_err_msg := 'get_supply_action_name not successful';
133         RAISE PO_CORE_S.g_early_return_exc;
134       END IF;
135 
136       d_progress := 50;
137       IF (PO_LOG.d_stmt) THEN
138         PO_LOG.stmt(d_module, d_progress, 'l_supply_action', l_supply_action);
139       END IF;
140 
141       l_bool_ret_sts :=
142         PO_SUPPLY.po_req_supply(
143            p_docid          => p_action_ctl_rec.document_id
144         ,  p_lineid         => NULL
145         ,  p_shipid         => NULL
146         ,  p_action         => l_supply_action
147         ,  p_recreate_flag  => FALSE
148         ,  p_qty            => NULL
149         ,  p_receipt_date   => NULL
150         );
151 
152       IF (NOT l_bool_ret_sts)
153       THEN
154         d_progress := 60;
155         l_err_msg := 'po_req_supply returned false';
156         RAISE PO_CORE_S.g_early_return_exc;
157       END IF;
158 
159     END IF;  -- p_action_ctl_rec.document_type <> 'PA'
160 
161     d_progress := 70;
162     -- <Unified Catalog R12 Start>
163     IF ((p_action_ctl_rec.document_type = 'PA') AND
164         (p_action_ctl_rec.document_subtype = 'BLANKET'))
165     THEN
166       -- Rebuild catalog search index.
167       -- Call this procedure BEFORE calling archive_po because this one
168       -- compares against the archive tables to check if any of the
169       -- searchable fields have been modified or not.
170       PO_CATALOG_INDEX_PVT.rebuild_index
171       (
172         p_type => PO_CATALOG_INDEX_PVT.TYPE_BLANKET
173       , p_po_header_id => P_ACTION_CTL_REC.document_id
174       );
175 
176     END IF; -- if Blanket Agreement
177     -- <Unified Catalog R12 End>
178 
179     d_progress := 80;
180     IF (p_action_ctl_rec.document_type <> 'REQUISITION')
181     THEN
182 
183       PO_DOCUMENT_ARCHIVE_GRP.archive_po(
184          p_api_version      => 1.0
185       ,  p_document_id      => p_action_ctl_rec.document_id
186       ,  p_document_type    => p_action_ctl_rec.document_type
187       ,  p_document_subtype => p_action_ctl_rec.document_subtype
188       ,  p_process          => 'APPROVE'
189       ,  x_return_status    => l_ret_sts
190       ,  x_msg_count        => l_msg_count
191       ,  x_msg_data         => l_msg_data
192       );
193 
194       IF (l_ret_sts <> 'S')
195       THEN
196         d_progress := 90;
197         l_err_msg := 'archive_po not successful';
198         RAISE PO_CORE_S.g_early_return_exc;
199       END IF;
200 
201     END IF;  -- if p_action_ctl_rec.document_type <> 'REQUISITION'
202 
203     -- TODO: ANALYZE return_code value (as opposed to return_status).
204     p_action_ctl_rec.return_status := 'S';
205 
206   EXCEPTION
207     WHEN PO_CORE_S.g_early_return_exc THEN
208       p_action_ctl_rec.return_status := 'U';
209       IF (PO_LOG.d_exc) THEN
210         PO_LOG.exc(d_module, d_progress, l_err_msg);
211       END IF;
212       PO_DOCUMENT_ACTION_PVT.error_msg_append(d_module, d_progress, l_err_msg);
213 
214   END;
215 
216   IF (PO_LOG.d_proc) THEN
217     PO_LOG.proc_end(d_module, 'p_action_ctl_rec.return_status', p_action_ctl_rec.return_status);
218     PO_LOG.proc_end(d_module);
219   END IF;
220 
221   RETURN;
222 
223 EXCEPTION
224   WHEN OTHERS THEN
225     p_action_ctl_rec.return_status := 'U';
226 
227     PO_DOCUMENT_ACTION_PVT.error_msg_append(d_module, d_progress, SQLCODE, SQLERRM);
228     IF (PO_LOG.d_exc) THEN
229       PO_LOG.exc(d_module, d_progress, SQLCODE || SQLERRM);
230       PO_LOG.proc_end(d_module, 'p_action_ctl_rec.return_status', p_action_ctl_rec.return_status);
231       PO_LOG.proc_end(d_module);
232     END IF;
233 
234     RETURN;
235 
236 END approve;
237 
238 
239 ------------------------------------------------------------------------------
240 --Start of Comments
241 --Name: reject
242 --Pre-reqs:
243 --  Document is locked.
244 --  Org context is set to that of document.
245 --Modifies:
246 --  None, directly.
247 --Locks:
248 --  None.
249 --Function:
250 --  This procedure handles logic to reject a document that is
251 --  either pre-approved or in process.
252 --  The logic is:
253 --    1. check that document is in right status
254 --    2. handle encumbrance
255 --    3. update action history
256 --    4. update document authorization status
257 --    5. if not a PA, call appropriate supply action
258 --Replaces:
259 --  This method covers the logic in podareject in podar.lpc.
260 --Parameters:
261 --IN:
262 --  p_action_ctl_rec
263 --    Record containing all necessary parameters for action.
264 --OUT:
265 --  p_action_ctl_rec
266 --    Record contains variables that record output values depending
267 --    on the action.  All actions will populate at least a return_status.
268 --End of Comments
269 -------------------------------------------------------------------------------
270 PROCEDURE reject(
271    p_action_ctl_rec  IN OUT NOCOPY  PO_DOCUMENT_ACTION_PVT.doc_action_call_rec_type
272 )
273 IS
274 
275 l_doc_state_ok    BOOLEAN;
276 l_preparer_id     PO_HEADERS_ALL.agent_id%TYPE;
277 
278 l_ret_sts         VARCHAR2(1);
279 l_err_msg         VARCHAR2(200);
280 l_bool_ret_sts    BOOLEAN;
281 
282 l_enc_flag        VARCHAR2(1);
283 l_enc_ret_code    VARCHAR2(10);
284 l_enc_report_id   NUMBER;
285 
286 l_supply_action   VARCHAR2(40);
287 
288 d_progress        NUMBER;
289 d_module          VARCHAR2(70) := 'po.plsql.PO_DOCUMENT_ACTION_AUTH.reject';
290 
291 BEGIN
292 
293   d_progress := 0;
294   IF (PO_LOG.d_proc) THEN
295     PO_LOG.proc_begin(d_module);
296     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.document_id', p_action_ctl_rec.document_id);
297     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.document_type', p_action_ctl_rec.document_type);
298     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.document_subtype', p_action_ctl_rec.document_subtype);
299     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.action', p_action_ctl_rec.action);
300     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.forward_to_id', p_action_ctl_rec.forward_to_id);
301     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.approval_path_id', p_action_ctl_rec.approval_path_id);
302     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.note', p_action_ctl_rec.note);
303   END IF;
304 
305   d_progress := 10;
306 
307   BEGIN
308 
309     PO_DOCUMENT_ACTION_CHECK.reject_status_check(p_action_ctl_rec);
310 
311     d_progress := 20;
312 
313     IF (p_action_ctl_rec.return_status <> 'S')
314     THEN
315 
316       d_progress := 30;
317       p_action_ctl_rec.return_status := 'U';
318       l_err_msg := 'reject_status_check not successful';
319       RAISE PO_CORE_S.g_early_return_exc;
320 
321     END IF;
322 
323     IF (p_action_ctl_rec.return_code IS NOT NULL)
324     THEN
325 
326       d_progress := 40;
327       p_action_ctl_rec.return_status := 'S';
328       p_action_ctl_rec.return_code := 'STATE_FAILED';
329       l_err_msg := 'State check failed';
330       RAISE PO_CORE_S.g_early_return_exc;
331 
332     END IF;
333 
334     -- reset return status and return code after reject_status_check call
335     p_action_ctl_rec.return_status := NULL;
336     p_action_ctl_rec.return_code := NULL;
337 
338     d_progress := 50;
339 
340     PO_DOCUMENT_ACTION_UTIL.get_doc_preparer_id(
341        p_document_id => p_action_ctl_rec.document_id
342     ,  p_document_type => p_action_ctl_rec.document_type
343     ,  x_return_status => l_ret_sts
344     ,  x_preparer_id => l_preparer_id
345     );
346 
347     IF (l_ret_sts <> 'S')
348     THEN
349 
350       d_progress := 60;
351       p_action_ctl_rec.return_status := 'U';
352       l_err_msg := 'get_doc_preparer_id not successful';
353       RAISE PO_CORE_S.g_early_return_exc;
354 
355     END IF;
356 
357     d_progress := 70;
358 
359     IF (PO_LOG.d_stmt) THEN
360       PO_LOG.stmt(d_module, d_progress, 'l_preparer_id', l_preparer_id);
361     END IF;
362 
363 
364     IF ( PO_CORE_S.is_encumbrance_on(
365             p_doc_type => p_action_ctl_rec.document_type
366          ,  p_org_id => NULL
367          )
368         )
369     THEN
370       l_enc_flag := 'Y';
371     ELSE
372       l_enc_flag := 'N';
373     END IF;
374 
375     d_progress := 80;
376 
377     IF ((l_enc_flag = 'Y') AND (p_action_ctl_rec.document_type = 'PA')
378        AND (p_action_ctl_rec.document_subtype = 'BLANKET'))
379     THEN
380 
381       d_progress := 90;
382 
383       SELECT nvl(poh.encumbrance_required_flag, 'N')
384       INTO l_enc_flag
385       FROM po_headers_all poh
386       WHERE po_header_id = p_action_ctl_rec.document_id;
387 
388     END IF;
389 
390     IF (PO_LOG.d_stmt) THEN
391       PO_LOG.stmt(d_module, d_progress, 'l_enc_flag', l_enc_flag);
392     END IF;
393 
394 
395     IF ((l_enc_flag = 'Y') AND (p_action_ctl_rec.document_type <> 'CONTRACT'))
396     THEN
397 
398       d_progress := 100;
399 
400       PO_DOCUMENT_FUNDS_PVT.do_reject(
401         x_return_status     => l_ret_sts
402       , p_doc_type          => p_action_ctl_rec.document_type
403       , p_doc_subtype       => p_action_ctl_rec.document_subtype
404       , p_doc_level         => PO_DOCUMENT_FUNDS_PVT.g_doc_level_HEADER
405       , p_doc_level_id      => p_action_ctl_rec.document_id
406       , p_use_enc_gt_flag   => PO_DOCUMENT_FUNDS_PVT.g_parameter_NO
407       , p_override_funds    => PO_DOCUMENT_FUNDS_PVT.g_parameter_NO
408       , p_use_gl_date       => PO_DOCUMENT_FUNDS_PVT.g_parameter_USE_PROFILE
409       , p_override_date     => SYSDATE
410       , x_po_return_code    => l_enc_ret_code
411       , x_online_report_id  => l_enc_report_id
412       );
413 
414 
415       IF (l_ret_sts <> FND_API.g_ret_sts_success)
416       THEN
417 
418         d_progress := 110;
419         p_action_ctl_rec.return_status := 'U';
420         l_err_msg := 'do_reject not successful';
421         RAISE PO_CORE_S.g_early_return_exc;
422 
423       END IF;
424 
425       d_progress := 120;
426 
427       IF (PO_LOG.d_stmt) THEN
428         PO_LOG.stmt(d_module, d_progress, 'l_enc_ret_code', l_enc_ret_code);
429         PO_LOG.stmt(d_module, d_progress, 'l_enc_report_id', l_enc_report_id);
430       END IF;
431 
432       p_action_ctl_rec.online_report_id := l_enc_report_id;
433 
434       IF ((l_enc_ret_code = PO_DOCUMENT_FUNDS_PVT.g_return_SUCCESS)
435            OR (l_enc_ret_code = PO_DOCUMENT_FUNDS_PVT.g_return_WARNING))
436       THEN
437 
438         d_progress := 125;
439         -- Just continue with reject action.
440 
441       ELSIF (l_enc_ret_code = PO_DOCUMENT_FUNDS_PVT.g_return_PARTIAL)
442       THEN
443 
444         d_progress := 130;
445         p_action_ctl_rec.return_status := 'S';
446         p_action_ctl_rec.return_code := 'P';
447         l_err_msg := 'funds do_reject partial';
448         RAISE PO_CORE_S.g_early_return_exc;
449 
450       ELSIF (l_enc_ret_code = PO_DOCUMENT_FUNDS_PVT.g_return_FAILURE)
451       THEN
452 
453         d_progress := 140;
454         p_action_ctl_rec.return_status := 'S';
455         p_action_ctl_rec.return_code := 'F';
456         l_err_msg := 'funds do_reject failure';
457         RAISE PO_CORE_S.g_early_return_exc;
458 
459       ELSIF (l_enc_ret_code = PO_DOCUMENT_FUNDS_PVT.g_return_FATAL)
460       THEN
461 
462         d_progress := 150;
463         p_action_ctl_rec.return_status := 'S';
464         p_action_ctl_rec.return_code := 'T';
465         l_err_msg := 'funds do_reject fatal';
466         RAISE PO_CORE_S.g_early_return_exc;
467 
468       ELSE
469 
470        d_progress := 160;
471        p_action_ctl_rec.return_status := 'U';
472        l_err_msg := 'Bad return code from funds do_reject';
473        RAISE PO_CORE_S.g_early_return_exc;
474 
475       END IF;  -- if l_enc_ret_code IN (...)
476 
477     END IF;  -- if l_enc_flag = 'Y' ...
478 
479     d_progress := 170;
480 
481     IF (PO_LOG.d_stmt) THEN
482       PO_LOG.stmt(d_module, d_progress, 'Calling change_doc_auth_state');
483     END IF;
484 
485     PO_DOCUMENT_ACTION_UTIL.change_doc_auth_state(
486        p_document_id         => p_action_ctl_rec.document_id
487     ,  p_document_type       => p_action_ctl_rec.document_type
488     ,  p_document_subtype    => p_action_ctl_rec.document_subtype
489     ,  p_action              => 'REJECT'
490     ,  p_fwd_to_id           => p_action_ctl_rec.forward_to_id
491     ,  p_offline_code        => p_action_ctl_rec.offline_code
492     ,  p_approval_path_id    => p_action_ctl_rec.approval_path_id
493     ,  p_note                => p_action_ctl_rec.note
494     ,  p_new_status          => PO_DOCUMENT_ACTION_PVT.g_doc_status_REJECTED
495     ,  p_notify_action       => 'REJECTED_BY_APPROVER'
496     ,  p_notify_employee     => l_preparer_id
497     ,  x_return_status       => l_ret_sts
498     );
499 
500     IF (l_ret_sts <> 'S')
501     THEN
502 
503        d_progress := 180;
504        p_action_ctl_rec.return_status := 'U';
505        l_err_msg := 'change_doc_auth_state not successful';
506        RAISE PO_CORE_S.g_early_return_exc;
507 
508     END IF;
509 
510     d_progress := 190;
511 
512     IF (p_action_ctl_rec.document_type <> 'PA')
513     THEN
514 
515       get_supply_action_name(
516          p_action           => p_action_ctl_rec.action
517       ,  p_document_type    => p_action_ctl_rec.document_type
518       ,  p_document_subtype => p_action_ctl_rec.document_subtype
519       ,  x_return_status    => l_ret_sts
520       ,  x_supply_action    => l_supply_action
521       );
522 
523       IF (l_ret_sts <> 'S')
524       THEN
525         d_progress := 195;
526         p_action_ctl_rec.return_status := 'U';
527         l_err_msg := 'get_supply_action_name not successful';
528         RAISE PO_CORE_S.g_early_return_exc;
529       END IF;
530 
531       d_progress := 200;
532       IF (PO_LOG.d_stmt) THEN
533         PO_LOG.stmt(d_module, d_progress, 'l_supply_action', l_supply_action);
534       END IF;
535 
536       l_bool_ret_sts :=
537         PO_SUPPLY.po_req_supply(
538            p_docid          => p_action_ctl_rec.document_id
539         ,  p_lineid         => NULL
540         ,  p_shipid         => NULL
541         ,  p_action         => l_supply_action
542         ,  p_recreate_flag  => FALSE
543         ,  p_qty            => NULL
544         ,  p_receipt_date   => NULL
545         );
546 
547       IF (NOT l_bool_ret_sts)
548       THEN
549         d_progress := 210;
550         p_action_ctl_rec.return_status := 'U';
551         l_err_msg := 'po_req_supply returned false';
552         RAISE PO_CORE_S.g_early_return_exc;
553       END IF;
554 
555     END IF;  -- document_type <> 'PA'
556 
557     p_action_ctl_rec.return_status := 'S';
558 
559   EXCEPTION
560     WHEN PO_CORE_S.g_early_return_exc THEN
561       IF (p_action_ctl_rec.return_status = 'U')
562       THEN
563         IF (PO_LOG.d_exc) THEN
564           PO_LOG.exc(d_module, d_progress, l_err_msg);
565         END IF;
566       END IF;
567 
568       PO_DOCUMENT_ACTION_PVT.error_msg_append(d_module, d_progress, l_err_msg);
569 
570   END;
571 
572   IF (PO_LOG.d_proc) THEN
573     PO_LOG.proc_end(d_module, 'p_action_ctl_rec.return_status', p_action_ctl_rec.return_status);
574     PO_LOG.proc_end(d_module, 'p_action_ctl_rec.return_code', p_action_ctl_rec.return_code);
575     PO_LOG.proc_end(d_module, 'p_action_ctl_rec.online_report_id', p_action_ctl_rec.online_report_id);
576     PO_LOG.proc_end(d_module);
577   END IF;
578 
579   RETURN;
580 
581 EXCEPTION
582   WHEN OTHERS THEN
583     p_action_ctl_rec.return_status := 'U';
584 
585     PO_DOCUMENT_ACTION_PVT.error_msg_append(d_module, d_progress, SQLCODE, SQLERRM);
586     IF (PO_LOG.d_exc) THEN
587       PO_LOG.exc(d_module, d_progress, SQLCODE || SQLERRM);
588       PO_LOG.proc_end(d_module, 'p_action_ctl_rec.return_status', p_action_ctl_rec.return_status);
589       PO_LOG.proc_end(d_module);
590     END IF;
591 
592     RETURN;
593 
594 END reject;
595 
596 
597 ------------------------------------------------------------------------------
598 --Start of Comments
599 --Name: forward
600 --Pre-reqs:
601 --  Document is locked.
602 --  Org context is set to that of document.
603 --Modifies:
604 --  None, directly.
605 --Locks:
606 --  None.
607 --Function:
608 --  This procedure handles the forwarding of a document from one employee
609 --  to another.  It is just a wrapper around PO_DOCUMENT_ACTION_UTIL.change_doc_auth_state().
610 --  The logic is:
611 --    1. update action history
612 --    2. update document authorization status, if necessary
613 --Replaces:
614 --  This method covers some of the logic in poxdmaction in poxdm.lpc.
615 --Parameters:
616 --IN:
617 --  p_action_ctl_rec
618 --    Record containing all necessary parameters for action.
619 --OUT:
620 --  p_action_ctl_rec
621 --    Record contains variables that record output values depending
622 --    on the action.  All actions will populate at least a return_status.
623 --End of Comments
624 -------------------------------------------------------------------------------
625 PROCEDURE forward(
626    p_action_ctl_rec  IN OUT NOCOPY  PO_DOCUMENT_ACTION_PVT.doc_action_call_rec_type
627 )
628 IS
629 
630 l_ret_sts        VARCHAR2(1);
631 l_err_msg        VARCHAR2(200);
632 
633 d_progress       NUMBER;
634 d_module         VARCHAR2(70) := 'po.plsql.PO_DOCUMENT_ACTION_AUTH.forward';
635 
636 BEGIN
637 
638   d_progress := 0;
639   IF (PO_LOG.d_proc) THEN
640     PO_LOG.proc_begin(d_module);
641     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.document_id', p_action_ctl_rec.document_id);
642     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.document_type', p_action_ctl_rec.document_type);
643     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.document_subtype', p_action_ctl_rec.document_subtype);
644     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.action', p_action_ctl_rec.action);
645     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.forward_to_id', p_action_ctl_rec.forward_to_id);
646   END IF;
647 
648   d_progress := 10;
649 
650   BEGIN
651 
652     IF (PO_LOG.d_stmt) THEN
653       PO_LOG.stmt(d_module, d_progress, 'Calling change_doc_auth_state');
654     END IF;
655 
656     PO_DOCUMENT_ACTION_UTIL.change_doc_auth_state(
657        p_document_id         => p_action_ctl_rec.document_id
658     ,  p_document_type       => p_action_ctl_rec.document_type
659     ,  p_document_subtype    => p_action_ctl_rec.document_subtype
660     ,  p_action              => 'FORWARD'
661     ,  p_fwd_to_id           => p_action_ctl_rec.forward_to_id
662     ,  p_offline_code        => p_action_ctl_rec.offline_code
663     ,  p_approval_path_id    => p_action_ctl_rec.approval_path_id
664     ,  p_note                => p_action_ctl_rec.note
665     ,  p_new_status          => p_action_ctl_rec.new_document_status
666     ,  p_notify_action       => 'APPROVAL'
667     ,  p_notify_employee     => p_action_ctl_rec.forward_to_id
668     ,  x_return_status       => l_ret_sts
669     );
670 
671     IF (l_ret_sts <> 'S')
672     THEN
673       d_progress := 20;
674       l_ret_sts := 'U';
675       l_err_msg := 'change doc state not successful';
676       RAISE PO_CORE_S.g_early_return_exc;
677     END IF;
678 
679     d_progress := 30;
680     l_ret_sts := 'S';
681 
682   EXCEPTION
683     WHEN PO_CORE_S.g_early_return_exc THEN
684       IF (PO_LOG.d_exc) THEN
685         PO_LOG.exc(d_module, d_progress, l_err_msg);
686       END IF;
687       PO_DOCUMENT_ACTION_PVT.error_msg_append(d_module, d_progress, l_err_msg);
688 
689   END;
690 
691   p_action_ctl_rec.return_status := l_ret_sts;
692   IF (PO_LOG.d_proc) THEN
693     PO_LOG.proc_end(d_module, 'p_action_ctl_rec.return_status', p_action_ctl_rec.return_status);
694     PO_LOG.proc_end(d_module);
695   END IF;
696 
697   RETURN;
698 
699 EXCEPTION
700   WHEN OTHERS THEN
701     p_action_ctl_rec.return_status := 'U';
702 
703     PO_DOCUMENT_ACTION_PVT.error_msg_append(d_module, d_progress, SQLCODE, SQLERRM);
704     IF (PO_LOG.d_exc) THEN
705       PO_LOG.exc(d_module, d_progress, SQLCODE || SQLERRM);
706       PO_LOG.proc_end(d_module, 'p_action_ctl_rec.return_status', p_action_ctl_rec.return_status);
707       PO_LOG.proc_end(d_module);
708     END IF;
709 
710     RETURN;
711 
712 END forward;
713 
714 ------------------------------------------------------------------------------
715 --Start of Comments
716 --Name: return_action
717 --Pre-reqs:
718 --  Document is locked.
719 --  Org context is set to that of document.
720 --Modifies:
721 --  None, directly.
722 --Locks:
723 --  None.
724 --Function:
725 --  This procedure handles logic to return a requistion during autocreate.
726 --  The logic is:
727 --    1. verify document is requisition
728 --    2. verify requisition state - e.g. that it is approved.
729 --    3. handle encumbrance
730 --    4. update action history
731 --    5. update authorization_status and appropriate flags
732 --    6. call appropriate methods to handle supply
733 --Replaces:
734 --  This method covers some of the logic in podatreturn in podat.lpc.
735 --Parameters:
736 --IN:
737 --  p_action_ctl_rec
738 --    Record containing all necessary parameters for action.
739 --OUT:
740 --  p_action_ctl_rec
741 --    Record contains variables that record output values depending
742 --    on the action.  All actions will populate at least a return_status.
743 --End of Comments
744 -------------------------------------------------------------------------------
745 PROCEDURE return_action(
746    p_action_ctl_rec  IN OUT NOCOPY  PO_DOCUMENT_ACTION_PVT.doc_action_call_rec_type
747 )
748 IS
749 
750 l_ret_sts        VARCHAR2(1);
751 l_bool_ret_sts   BOOLEAN;
752 l_err_msg        VARCHAR2(200);
753 
754 l_allowed_states    PO_DOCUMENT_ACTION_UTIL.doc_state_rec_type;
755 l_doc_state_ok      BOOLEAN;
756 
757 l_req_enc_on        BOOLEAN;
758 l_enc_ret_code      VARCHAR2(10);
759 l_enc_report_id     NUMBER;
760 
761 l_preparer_id     PO_REQUISITION_HEADERS.preparer_id%TYPE;
762 l_supply_action   VARCHAR2(40);
763 
764 d_progress       NUMBER;
765 d_module         VARCHAR2(70) := 'po.plsql.PO_DOCUMENT_ACTION_AUTH.return_action';
766 
767 BEGIN
768 
769   d_progress := 0;
770   IF (PO_LOG.d_proc) THEN
771     PO_LOG.proc_begin(d_module);
772     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.document_id', p_action_ctl_rec.document_id);
773     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.document_type', p_action_ctl_rec.document_type);
774     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.document_subtype', p_action_ctl_rec.document_subtype);
775     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.action', p_action_ctl_rec.action);
776     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.note', p_action_ctl_rec.note);
777     PO_LOG.proc_begin(d_module, 'p_action_ctl_rec.approval_path_id', p_action_ctl_rec.approval_path_id);
778   END IF;
779 
780   d_progress := 10;
781 
782   BEGIN
783 
784     IF (p_action_ctl_rec.document_type <> 'REQUISITION')
785     THEN
786 
787       d_progress := 20;
788       l_err_msg := 'Invalid document type';
789       l_ret_sts := 'U';
790       RAISE PO_CORE_S.g_early_return_exc;
791 
792     END IF;
793 
794     d_progress := 30;
795 
796     l_allowed_states.auth_states(1) := PO_DOCUMENT_ACTION_PVT.g_doc_status_APPROVED;
797     l_allowed_states.hold_flag := 'N';
798     l_allowed_states.frozen_flag := 'N';
799     l_allowed_states.closed_states(1) := PO_DOCUMENT_ACTION_PVT.g_doc_closed_sts_CLOSED;
800     l_allowed_states.closed_states(2) := PO_DOCUMENT_ACTION_PVT.g_doc_closed_sts_OPEN;
801 
802     l_doc_state_ok := PO_DOCUMENT_ACTION_UTIL.check_doc_state(
803                                 p_document_id => p_action_ctl_rec.document_id
804                              ,  p_document_type => p_action_ctl_rec.document_type
805                              ,  p_allowed_states => l_allowed_states
806                              ,  x_return_status  => l_ret_sts
807                              );
808 
809     IF (l_ret_sts <> 'S')
810     THEN
811 
812       d_progress := 40;
813       l_err_msg := 'check_doc_state not successful';
814       RAISE PO_CORE_S.g_early_return_exc;
815 
816     END IF;
817 
818     IF (NOT l_doc_state_ok)
819     THEN
820 
821       d_progress := 45;
822       l_ret_sts := 'S';
823       p_action_ctl_rec.return_code := 'STATE_FAILED';
824       l_err_msg := 'State check failed.';
825       RAISE PO_CORE_S.g_early_return_exc;
826 
827     END IF;
828 
829     d_progress := 50;
830 
831     l_req_enc_on := PO_CORE_S.is_encumbrance_on(
832                            p_doc_type => PO_CORE_S.g_doc_type_REQUISITION
833                         ,  p_org_id   => NULL
834                         );
835 
836     d_progress := 60;
837     IF (PO_LOG.d_stmt) THEN
838       PO_LOG.stmt(d_module, d_progress, 'l_req_enc_on', l_req_enc_on);
839     END IF;
840 
841     IF (l_req_enc_on)
842     THEN
843 
844       d_progress := 70;
845 
846       PO_DOCUMENT_FUNDS_PVT.do_return(
847         x_return_status     => l_ret_sts
848       , p_doc_type          => p_action_ctl_rec.document_type
849       , p_doc_subtype       => p_action_ctl_rec.document_subtype
850       , p_doc_level         => PO_DOCUMENT_FUNDS_PVT.g_doc_level_HEADER
851       , p_doc_level_id      => p_action_ctl_rec.document_id
852       , p_use_enc_gt_flag   => PO_DOCUMENT_FUNDS_PVT.g_parameter_NO
853       , p_use_gl_date       => PO_DOCUMENT_FUNDS_PVT.g_parameter_USE_PROFILE
854       , p_override_date     => SYSDATE
855       , x_po_return_code    => l_enc_ret_code
856       , x_online_report_id  => l_enc_report_id
857       );
858 
859 
860       IF (l_ret_sts <> FND_API.g_ret_sts_success)
861       THEN
862 
863         d_progress := 80;
864         l_ret_sts := 'U';
865         l_err_msg := 'do_return not successful';
866         RAISE PO_CORE_S.g_early_return_exc;
867 
868       END IF;
869 
870       d_progress := 90;
871 
872       IF (PO_LOG.d_stmt) THEN
873         PO_LOG.stmt(d_module, d_progress, 'l_enc_ret_code', l_enc_ret_code);
874         PO_LOG.stmt(d_module, d_progress, 'l_enc_report_id', l_enc_report_id);
875       END IF;
876 
877       p_action_ctl_rec.online_report_id := l_enc_report_id;
878 
879       IF ((l_enc_ret_code = PO_DOCUMENT_FUNDS_PVT.g_return_SUCCESS)
880            OR (l_enc_ret_code = PO_DOCUMENT_FUNDS_PVT.g_return_WARNING))
881       THEN
882 
883         d_progress := 100;
884         -- Just continue with return action.
885 
886       ELSIF (l_enc_ret_code = PO_DOCUMENT_FUNDS_PVT.g_return_PARTIAL)
887       THEN
888 
889         d_progress := 110;
890         l_ret_sts := 'S';
891         p_action_ctl_rec.return_code := 'P';
892         l_err_msg := 'funds do_return partial';
893         RAISE PO_CORE_S.g_early_return_exc;
894 
895       ELSIF (l_enc_ret_code = PO_DOCUMENT_FUNDS_PVT.g_return_FAILURE)
896       THEN
897 
898         d_progress := 120;
899         l_ret_sts := 'S';
900         p_action_ctl_rec.return_code := 'F';
901         l_err_msg := 'funds do_return failure';
902         RAISE PO_CORE_S.g_early_return_exc;
903 
904       ELSIF (l_enc_ret_code = PO_DOCUMENT_FUNDS_PVT.g_return_FATAL)
905       THEN
906 
907         d_progress := 130;
908         l_ret_sts := 'S';
909         p_action_ctl_rec.return_code := 'T';
910         l_err_msg := 'funds do_return fatal';
911         RAISE PO_CORE_S.g_early_return_exc;
912 
913       ELSE
914 
915        d_progress := 140;
916        l_ret_sts := 'U';
917        l_err_msg := 'Bad return code from funds do_return';
918        RAISE PO_CORE_S.g_early_return_exc;
919 
920       END IF;  -- if l_enc_ret_code IN (...)
921 
922     END IF;  -- IF l_req_enc_on
923 
924     d_progress := 150;
925 
926     PO_DOCUMENT_ACTION_UTIL.get_doc_preparer_id(
927        p_document_id => p_action_ctl_rec.document_id
928     ,  p_document_type => p_action_ctl_rec.document_type
929     ,  x_return_status => l_ret_sts
930     ,  x_preparer_id => l_preparer_id
931     );
932 
933     IF (l_ret_sts <> 'S')
934     THEN
935 
936       d_progress := 160;
937       l_ret_sts := 'U';
938       l_err_msg := 'get_doc_preparer_id not successful';
939       RAISE PO_CORE_S.g_early_return_exc;
940 
941     END IF;
942 
943     d_progress := 170;
944 
945     IF (PO_LOG.d_stmt) THEN
946       PO_LOG.stmt(d_module, d_progress, 'Calling change_doc_auth_state');
947     END IF;
948 
949     PO_DOCUMENT_ACTION_UTIL.change_doc_auth_state(
950        p_document_id         => p_action_ctl_rec.document_id
951     ,  p_document_type       => p_action_ctl_rec.document_type
952     ,  p_document_subtype    => p_action_ctl_rec.document_subtype
953     ,  p_action              => 'RETURN'
954     ,  p_fwd_to_id           => NULL
955     ,  p_offline_code        => NULL
956     ,  p_approval_path_id    => p_action_ctl_rec.approval_path_id
957     ,  p_note                => p_action_ctl_rec.note
958     ,  p_new_status          => PO_DOCUMENT_ACTION_PVT.g_doc_status_RETURNED
959     ,  p_notify_action       => 'APPROVAL'
960     ,  p_notify_employee     => l_preparer_id
961     ,  x_return_status       => l_ret_sts
962     );
963 
964     IF (l_ret_sts <> 'S')
965     THEN
966 
967        d_progress := 180;
968        l_ret_sts := 'U';
969        l_err_msg := 'change_doc_auth_state not successful';
970        RAISE PO_CORE_S.g_early_return_exc;
971 
972     END IF;
973 
974     d_progress := 190;
975 
976     get_supply_action_name(
977        p_action           => p_action_ctl_rec.action
978     ,  p_document_type    => p_action_ctl_rec.document_type
979     ,  p_document_subtype => p_action_ctl_rec.document_subtype
980     ,  x_return_status    => l_ret_sts
981     ,  x_supply_action    => l_supply_action
982     );
983 
984     IF (l_ret_sts <> 'S')
985     THEN
986       d_progress := 195;
987       l_ret_sts := 'U';
988       l_err_msg := 'get_supply_action_name not successful';
989       RAISE PO_CORE_S.g_early_return_exc;
990     END IF;
991 
992     d_progress := 200;
993     IF (PO_LOG.d_stmt) THEN
994       PO_LOG.stmt(d_module, d_progress, 'l_supply_action', l_supply_action);
995     END IF;
996 
997     l_bool_ret_sts :=
998       PO_SUPPLY.po_req_supply(
999          p_docid          => p_action_ctl_rec.document_id
1000       ,  p_lineid         => NULL
1001       ,  p_shipid         => NULL
1002       ,  p_action         => l_supply_action
1003       ,  p_recreate_flag  => FALSE
1004       ,  p_qty            => NULL
1005       ,  p_receipt_date   => NULL
1006       );
1007 
1008     IF (NOT l_bool_ret_sts)
1009     THEN
1010       d_progress := 210;
1011       l_ret_sts := 'U';
1012       l_err_msg := 'po_req_supply returned false';
1013       RAISE PO_CORE_S.g_early_return_exc;
1014     END IF;
1015 
1016     d_progress := 220;
1017     p_action_ctl_rec.return_code := NULL;
1018     l_ret_sts := 'S';
1019 
1020   EXCEPTION
1021     WHEN PO_CORE_S.g_early_return_exc THEN
1022       IF (l_ret_sts = 'U') THEN
1023         IF (PO_LOG.d_exc) THEN
1024           PO_LOG.exc(d_module, d_progress, l_err_msg);
1025         END IF;
1026       END IF;
1027 
1028       PO_DOCUMENT_ACTION_PVT.error_msg_append(d_module, d_progress, l_err_msg);
1029   END;
1030 
1031   p_action_ctl_rec.return_status := l_ret_sts;
1032   IF (PO_LOG.d_proc) THEN
1033     PO_LOG.proc_end(d_module, 'p_action_ctl_rec.return_status', p_action_ctl_rec.return_status);
1034     PO_LOG.proc_end(d_module, 'p_action_ctl_rec.return_code', p_action_ctl_rec.return_code);
1035     PO_LOG.proc_end(d_module, 'p_action_ctl_rec.online_report_id', p_action_ctl_rec.online_report_id);
1036     PO_LOG.proc_end(d_module);
1037   END IF;
1038 
1039   RETURN;
1040 
1041 EXCEPTION
1042   WHEN OTHERS THEN
1043     p_action_ctl_rec.return_status := 'U';
1044 
1045     PO_DOCUMENT_ACTION_PVT.error_msg_append(d_module, d_progress, SQLCODE, SQLERRM);
1046     IF (PO_LOG.d_exc) THEN
1047       PO_LOG.exc(d_module, d_progress, SQLCODE || SQLERRM);
1048       PO_LOG.proc_end(d_module, 'p_action_ctl_rec.return_status', p_action_ctl_rec.return_status);
1049       PO_LOG.proc_end(d_module);
1050     END IF;
1051 
1052     RETURN;
1053 
1054 END return_action;
1055 
1056 -- Private package methods
1057 
1058 ------------------------------------------------------------------------------
1059 --Start of Comments
1060 --Name: get_supply_action_name
1061 --Pre-reqs:
1062 --  None.
1063 --Modifies:
1064 --  None.
1065 --Locks:
1066 --  None.
1067 --Function:
1068 -- Given an action and document type, returns the appropriate supply action
1069 -- to call via PO_SUPPLY.po_req_supply().
1070 --Parameters:
1071 --IN:
1072 --  p_action
1073 --    REJECT, APPROVE, RETURN
1074 --  p_document_type
1075 --    APPROVE/REJECT: PO, PA, RELEASE, REQUISITION
1076 --    RETURN: REQUISITION
1077 --  p_document_subtype
1078 --    RELEASE: BLANKET, SCHEDULED
1079 --    PO: PLANNED, STANDARD
1080 --    PA: CONTRACT, BLANKET
1081 --OUT:
1082 --  x_return_status
1083 --    'S' if successful
1084 --    'U' if unexpected error
1085 --  x_supply_action
1086 --    Name of supply action to pass to PO_SUPPLY.po_req_supply()
1087 --End of Comments
1088 -------------------------------------------------------------------------------
1089 PROCEDURE get_supply_action_name(
1090    p_action            IN          VARCHAR2
1091 ,  p_document_type     IN          VARCHAR2
1092 ,  p_document_subtype  IN          VARCHAR2
1093 ,  x_supply_action     OUT NOCOPY  VARCHAR2
1094 ,  x_return_status     OUT NOCOPY  VARCHAR2
1095 )
1096 IS
1097 
1098 d_progress  NUMBER;
1099 d_module    VARCHAR2(70) := 'po.plsql.PO_DOCUMENT_ACTION_AUTH.get_supply_action_name';
1100 
1101 l_supply_action  VARCHAR2(40);
1102 
1103 BEGIN
1104 
1105   d_progress := 0;
1106   IF (PO_LOG.d_proc) THEN
1107     PO_LOG.proc_begin(d_module);
1108     PO_LOG.proc_begin(d_module, 'p_document_type', p_document_subtype);
1109     PO_LOG.proc_begin(d_module, 'p_document_type', p_document_subtype);
1110   END IF;
1111 
1112   IF (p_action IN (PO_DOCUMENT_ACTION_PVT.g_doc_action_APPROVE,
1113                    PO_DOCUMENT_ACTION_PVT.g_doc_action_REJECT))
1114   THEN
1115 
1116     IF (p_document_type = 'PO')
1117     THEN
1118 
1119       d_progress := 10;
1120       l_supply_action := 'Approve_PO_Supply';
1121 
1122     ELSIF (p_document_type = 'RELEASE')
1123     THEN
1124       d_progress := 20;
1125       IF (p_document_subtype = 'BLANKET')
1126       THEN
1127         d_progress := 30;
1128         l_supply_action := 'Approve_Blanket_Release_Supply';
1129       ELSE
1130         d_progress := 40;
1131         l_supply_action := 'Approve_Planned_Release_Supply';
1132       END IF;
1133 
1134     ELSIF (p_document_type = 'REQUISITION')
1135     THEN
1136 
1137       d_progress := 50;
1138       l_supply_action := 'Approve_Req_Supply';
1139 
1140     END IF;  -- document_type = 'PO'
1141 
1142   ELSIF ((p_action = PO_DOCUMENT_ACTION_PVT.g_doc_action_RETURN)
1143        AND (p_document_type = 'REQUISITION'))
1144   THEN
1145 
1146     d_progress := 60;
1147     l_supply_action := 'Remove_Return_Req_Supply';
1148 
1149   ELSE
1150 
1151     RAISE PO_CORE_S.g_invalid_call_exc;
1152 
1153   END IF;  -- p_action IN ...
1154 
1155   x_supply_action := l_supply_action;
1156   x_return_status := 'S';
1157 
1158   IF (PO_LOG.d_proc) THEN
1159     PO_LOG.proc_end(d_module, 'x_return_status', x_return_status);
1160     PO_LOG.proc_end(d_module, 'x_supply_action', x_supply_action);
1161     PO_LOG.proc_end(d_module);
1162   END IF;
1163 
1164 EXCEPTION
1165   WHEN OTHERS THEN
1166     x_return_status := 'U';
1167     PO_DOCUMENT_ACTION_PVT.error_msg_append(d_module, d_progress, SQLCODE, SQLERRM);
1168     IF (PO_LOG.d_exc) THEN
1169       PO_LOG.exc(d_module, d_progress, SQLCODE || SQLERRM);
1170       PO_LOG.proc_end(d_module, 'x_return_status', x_return_status);
1171       PO_LOG.proc_end(d_module);
1172     END IF;
1173 
1174     RETURN;
1175 END get_supply_action_name;
1176 
1177 
1178 END PO_DOCUMENT_ACTION_AUTH;