1: PACKAGE BODY PO_WF_PO_RULE_ACC AS
2: /* $Header: POXRUACB.pls 120.2.12020000.4 2013/04/09 05:56:46 vsdesai ship $*/
3:
4: -- Read the profile option that enables/disables the debug log
5: g_po_wf_debug VARCHAR2(1) := NVL(FND_PROFILE.VALUE('PO_SET_DEBUG_WORKFLOW_ON'),'N');
33:
34:
35:
36:
37: x_progress := 'PO_WF_PO_RULE_ACC.get_default_requester_acc: 01';
38: IF (g_po_wf_debug = 'Y') THEN
39: PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
40: END IF;
41:
47: return;
48:
49: end if;
50:
51: x_progress := 'PO_WF_PO_RULE_ACC.get_default_requester_acc: 02';
52: x_requester_id := PO_WF_UTIL_PKG.GetItemAttrNumber(itemtype => itemtype,
53: itemkey => itemkey,
54: aname => 'TO_PERSON_ID');
55:
193: AND NVL(fsp.org_id, -99) = NVL(l_expense_rules_org_id, -99);
194: --< Shared Proc FPJ End >
195:
196:
197: x_progress := 'PO_WF_PO_RULE_ACC.get_default_requester_acc: 03';
198: if x_ccid is not null THEN
199:
200:
201: PO_WF_UTIL_PKG.SetItemAttrNumber (itemtype => itemtype,
229:
230: EXCEPTION
231: WHEN OTHERS THEN
232:
233: wf_core.context('PO_WF_PO_RULE_ACC','get_default_requester_acc',x_progress);
234: result := 'COMPLETE:FAILURE';
235: RETURN;
236:
237: END get_default_requester_acc;
249: x_ccid NUMBER;
250:
251: BEGIN
252:
253: x_progress := 'PO_WF_PO_RULE_ACC.get_favorite_charge_acc: 01';
254:
255: IF (g_po_wf_debug = 'Y') THEN
256: PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
257: END IF;
262: end if;
263:
264: -- Verify if the user has access to Favorite charge account function
265: IF NOT FND_FUNCTION.TEST('POR_FAV_CHG_ACCT') THEN
266: x_progress := 'PO_WF_PO_RULE_ACC.get_favorite_charge_acc: Favorite charge account functionality not provided';
267: PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
268: result := 'COMPLETE:FAILURE'; -- Bug 3626954 Return failure instead of success
269: RETURN;
270: END IF;
268: result := 'COMPLETE:FAILURE'; -- Bug 3626954 Return failure instead of success
269: RETURN;
270: END IF;
271:
272: x_progress := 'PO_WF_PO_RULE_ACC.get_favorite_charge_acc: 02';
273:
274: x_user_id := FND_GLOBAL.EMPLOYEE_ID;
275:
276: x_resp_id := FND_GLOBAL.RESP_ID;
274: x_user_id := FND_GLOBAL.EMPLOYEE_ID;
275:
276: x_resp_id := FND_GLOBAL.RESP_ID;
277:
278: x_progress := 'PO_WF_PO_RULE_ACC. get_favorite_charge_acc: 03';
279:
280: Select CHARGE_ACCOUNT_ID
281: into x_ccid
282: from POR_FAV_CHARGE_ACCOUNTS
283: where EMPLOYEE_ID = x_user_id and
284: RESPONSIBILITY_ID = x_resp_id and
285: DEFAULT_ACCOUNT = 'Y';
286:
287: x_progress := 'PO_WF_PO_RULE_ACC.get_favorite_charge_acc: 04';
288:
289:
290: if x_ccid is not null then
291: PO_WF_UTIL_PKG.SetItemAttrNumber (itemtype => itemtype,
300: RETURN;
301:
302: EXCEPTION
303: WHEN OTHERS THEN
304: wf_core.context('PO_WF_PO_RULE_ACC','get_favorite_charge_acc',x_progress);
305: result := 'COMPLETE:FAILURE';
306: RETURN;
307:
308: END get_favorite_charge_acc;
318: l_progress varchar2(100);
319: l_options_value VARCHAR2(30);
320:
321: BEGIN
322: l_progress := 'PO_WF_PO_RULE_ACC.if_enforce_expense_acc_rules: 01';
323:
324: fnd_profile.get('POR_REQ_ENFORCE_EXP_ACC_RULE', l_options_value);
325:
326: l_progress := 'PO_WF_PO_RULE_ACC.if_enforce_expense_acc_rules: 02';
322: l_progress := 'PO_WF_PO_RULE_ACC.if_enforce_expense_acc_rules: 01';
323:
324: fnd_profile.get('POR_REQ_ENFORCE_EXP_ACC_RULE', l_options_value);
325:
326: l_progress := 'PO_WF_PO_RULE_ACC.if_enforce_expense_acc_rules: 02';
327:
328: if l_options_value is not null then
329: result:='COMPLETE:'|| l_options_value;
330: return;
335:
336:
337: EXCEPTION
338: WHEN OTHERS THEN
339: WF_CORE.context('PO_WF_PO_RULE_ACC','if_enforce_expense_acc_rules', l_progress);
340: result:='COMPLETE:'||'N';
341:
342: END if_enforce_expense_acc_rules;
343:
364: --< Shared Proc FPJ End >
365:
366: BEGIN
367:
368: l_progress := 'PO_WF_PO_RULE_ACC.IF_RULE_EXIST_FOR_ALL_SEGMENTS: 01';
369:
370: IF (g_po_wf_debug = 'Y') THEN
371: PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,l_progress);
372: END IF;
375: result := wf_engine.eng_null;
376: return;
377: end if;
378:
379: l_progress := 'PO_WF_PO_RULE_ACC.IF_RULE_EXIST_FOR_ALL_SEGMENTS: 02';
380:
381: --< Shared Proc FPJ Start >
382:
383: -- The Expense Account Rules are called from the PO AG Workflow
405: END IF;
406:
407: IF (g_po_wf_debug = 'Y') THEN
408: PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,
409: 'PO_WF_PO_RULE_ACC.if_rule_exist_for_all_segments '||
410: 'l_expense_rules_org_id='||l_expense_rules_org_id);
411: END IF;
412:
413: --< Shared Proc FPJ End >
416: get_segment_records(itemtype, itemkey, l_get_result);
417:
418: IF (g_po_wf_debug = 'Y') THEN
419: PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,
420: 'PO_WF_PO_RULE_ACC.if_rule_exist_for_all_segments '||
421: 'get_segment_records->result='||l_get_result);
422: END IF;
423:
424:
421: 'get_segment_records->result='||l_get_result);
422: END IF;
423:
424:
425: l_progress := 'PO_WF_PO_RULE_ACC.IF_RULE_EXIST_FOR_ALL_SEGMENTS: 03';
426:
427: if (l_get_result = 'fail') then
428: result := 'COMPLETE:'||'N';
429: l_counter := -1;
429: l_counter := -1;
430: return;
431: end if;
432:
433: l_progress := 'PO_WF_PO_RULE_ACC.IF_RULE_EXIST_FOR_ALL_SEGMENTS: 04';
434:
435: -- set l_segments_number_sob , the total number of account segments for
436: -- the current set of books, by any query or api from GL, sent email to
437: -- ask Gursat.Olgun for the query or api.
457: --< Shared Proc FPJ End >
458:
459: if ( l_segment_table.count = l_segments_number_sob) THEN
460:
461: l_progress := 'PO_WF_PO_RULE_ACC.IF_RULE_EXIST_FOR_ALL_SEGMENTS: 05';
462:
463: -- get concatenated account segments
464: FOR i IN 0..l_segment_table.count-1 LOOP
465: wf_engine.SetItemAttrText(itemtype, itemkey,
467: l_segment_table(i).segment_value);
468: l_segment_array(i+1) := l_segment_table(i).segment_value;
469: END LOOP;
470:
471: l_progress := 'PO_WF_PO_RULE_ACC.IF_RULE_EXIST_FOR_ALL_SEGMENTS: 06';
472:
473: -- get chart_of_accounts_id
474:
475: select gls.chart_of_accounts_id
488: NVL(fsp.org_id, -99) = NVL(l_expense_rules_org_id, -99);
489: --< Shared Proc FPJ End >
490:
491:
492: l_progress := 'PO_WF_PO_RULE_ACC.IF_RULE_EXIST_FOR_ALL_SEGMENTS: 07';
493:
494: --
495: -- Use the FND_FLEX_EXT pacakge to concatenate the segments
496: --
495: -- Use the FND_FLEX_EXT pacakge to concatenate the segments
496: --
497: l_delimiter := fnd_flex_ext.get_delimiter('SQLGL', 'GL#', l_chart_of_accounts_id);
498:
499: l_progress := 'PO_WF_PO_RULE_ACC.IF_RULE_EXIST_FOR_ALL_SEGMENTS: 08';
500:
501: IF (l_delimiter is not null) THEN
502:
503: l_concat_segs := fnd_flex_ext.concatenate_segments(l_segment_table.count,l_segment_array, l_delimiter);
501: IF (l_delimiter is not null) THEN
502:
503: l_concat_segs := fnd_flex_ext.concatenate_segments(l_segment_table.count,l_segment_array, l_delimiter);
504:
505: l_progress := 'PO_WF_PO_RULE_ACC.IF_RULE_EXIST_FOR_ALL_SEGMENTS: 09';
506:
507: l_ccId := fnd_flex_ext.get_ccid('SQLGL','GL#',l_chart_of_accounts_id, to_char(sysdate, 'YYYY/MM/DD HH24:MI:SS'),l_concat_segs);
508:
509: l_progress := 'PO_WF_PO_RULE_ACC.IF_RULE_EXIST_FOR_ALL_SEGMENTS: 10';
505: l_progress := 'PO_WF_PO_RULE_ACC.IF_RULE_EXIST_FOR_ALL_SEGMENTS: 09';
506:
507: l_ccId := fnd_flex_ext.get_ccid('SQLGL','GL#',l_chart_of_accounts_id, to_char(sysdate, 'YYYY/MM/DD HH24:MI:SS'),l_concat_segs);
508:
509: l_progress := 'PO_WF_PO_RULE_ACC.IF_RULE_EXIST_FOR_ALL_SEGMENTS: 10';
510:
511: if l_ccId is not null then
512: PO_WF_UTIL_PKG.SetItemAttrNumber (
513: itemtype => itemtype,
521: result := 'COMPLETE:'||'N';
522: end if;
523:
524: ELSE
525: l_progress := 'PO_WF_PO_RULE_ACC.IF_RULE_EXIST_FOR_ALL_SEGMENTS: 11';
526:
527: result := 'COMPLETE:'||'N';
528: END IF;
529:
527: result := 'COMPLETE:'||'N';
528: END IF;
529:
530: else
531: l_progress := 'PO_WF_PO_RULE_ACC.IF_RULE_EXIST_FOR_ALL_SEGMENTS: 12';
532:
533: result := 'COMPLETE:'||'N';
534:
535: end if;
535: end if;
536:
537: IF (g_po_wf_debug = 'Y') THEN
538: PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,
539: 'PO_WF_PO_RULE_ACC.if_rule_exist_for_all_segments '||
540: 'result='||result);
541: END IF;
542:
543: l_segment_table.DELETE;
548: WHEN OTHERS THEN
549:
550: IF (g_po_wf_debug = 'Y') THEN
551: PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,
552: 'PO_WF_PO_RULE_ACC.if_rule_exist_for_all_segments '||
553: 'EXCEPTION at '|| l_progress);
554: END IF;
555:
556: wf_core.context('PO_WF_PO_RULE_ACC','IF_RULE_EXIST_FOR_ALL_SEGMENTS',
552: 'PO_WF_PO_RULE_ACC.if_rule_exist_for_all_segments '||
553: 'EXCEPTION at '|| l_progress);
554: END IF;
555:
556: wf_core.context('PO_WF_PO_RULE_ACC','IF_RULE_EXIST_FOR_ALL_SEGMENTS',
557: l_progress);
558: result := 'COMPLETE:'||'N';
559: RETURN;
560: END IF_RULE_EXIST_FOR_ALL_SEGMENTS;
571: l_get_result varchar2(25) := NULL;
572:
573: BEGIN
574:
575: x_progress := 'PO_WF_PO_RULE_ACC.get_category_account_segment: 01';
576: IF (g_po_wf_debug = 'Y') THEN
577: PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
578: END IF;
579:
618: RETURN;
619:
620: EXCEPTION
621: WHEN OTHERS THEN
622: wf_core.context('PO_WF_PO_RULE_ACC','get_category_account_segment',x_progress);
623: result := 'COMPLETE:FAILURE';
624: RETURN;
625:
626: END get_category_account_segment;
643: l_expense_rules_org_id NUMBER;
644: --< Shared Proc FPJ End >
645:
646: BEGIN
647: x_progress := 'PO_WF_PO_RULE_ACC.get_segment_records: 01';
648: x_category_id := PO_WF_UTIL_PKG.GetItemAttrText ( itemtype => itemtype,
649: itemkey => itemkey,
650: aname => 'CATEGORY_ID');
651:
662: END IF;
663:
664: IF (g_po_wf_debug = 'Y') THEN
665: PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,
666: 'PO_WF_PO_RULE_ACC.get_segment_records '||
667: 'l_expense_rules_org_id='||l_expense_rules_org_id);
668: END IF;
669:
670: --< Shared Proc FPJ End >
749: end if;
750:
751: EXCEPTION
752: WHEN OTHERS THEN
753: wf_core.context('PO_WF_PO_RULE_ACC','get_segment_records',x_progress);
754: resultout := 'fail';
755: RETURN;
756:
757: END get_segment_records;
802: aname => 'EXPENSE_RULES_ORG_ID',
803: avalue => l_purchasing_ou_id);
804: EXCEPTION
805: WHEN OTHERS THEN
806: WF_CORE.context('PO_WF_PO_RULE_ACC', 'set_expense_rules_org_as_POU',
807: x_progress);
808: RAISE;
809: END set_expense_rules_org_as_POU;
810:
852: aname => 'EXPENSE_RULES_ORG_ID',
853: avalue => l_destination_ou_id);
854: EXCEPTION
855: WHEN OTHERS THEN
856: WF_CORE.context('PO_WF_PO_RULE_ACC', 'set_expense_rules_org_as_DOU',
857: x_progress);
858: RAISE;
859: END set_expense_rules_org_as_DOU;
860:
872: x_progress varchar2(100);
873:
874: BEGIN
875:
876: x_progress := 'PO_WF_PO_RULE_ACC.IS_OVERRIDE_CHARGE_ACCOUNT : 01';
877:
878: IF (g_po_wf_debug = 'Y') THEN
879: /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
880: END IF;
887: result := wf_engine.eng_null;
888: return;
889:
890: end if;
891: x_progress := 'PO_WF_PO_RULE_ACC.IS_OVERRIDE_CHARGE_ACCOUNT : 02';
892:
893: IF (g_po_wf_debug = 'Y') THEN
894: /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
895: END IF;
896:
897:
898: override_charge_account := FND_PROFILE.VALUE('POR_OVERRIDE_CHARGE_ACCOUNT');
899:
900: x_progress := 'PO_WF_PO_RULE_ACC.IS_OVERRIDE_CHARGE_ACCOUNT : 03 ' ;
901:
902: -- IF (g_po_wf_debug = 'Y') THEN
903: -- /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,x_progress);
904: -- /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,itemkey,override_charge_account);
915: return;
916:
917: EXCEPTION
918: WHEN OTHERS THEN
919: wf_core.context('PO_WF_PO_RULE_ACC','IS_OVERRIDE_CHARGE_ACCOUNT',x_progress);
920: raise;
921: END IS_OVERRIDE_CHARGE_ACCOUNT ;
922:
923: END PO_WF_PO_RULE_ACC;
919: wf_core.context('PO_WF_PO_RULE_ACC','IS_OVERRIDE_CHARGE_ACCOUNT',x_progress);
920: raise;
921: END IS_OVERRIDE_CHARGE_ACCOUNT ;
922:
923: END PO_WF_PO_RULE_ACC;