Monday 20 June 2016

Useful Queries for Expense Reports

Useful Queries for Expense Reports:

1. Project Managers for a project on Expense Report:

SELECT ppp.person_id
             FROM ap_exp_report_dists_all aerd, pa_project_players ppp
            WHERE     aerd.report_header_id = p_transaction_id
                  AND aerd.project_id = ppp.project_id
                  AND ppp.person_id IS NOT NULL
                  AND ppp.project_role_type = 'PROJECT MANAGER'
                  AND TRUNC (SYSDATE) BETWEEN TRUNC (ppp.start_date_active)
                                          AND TRUNC (
                                                 NVL (ppp.end_date_active,
                                                      SYSDATE + 1))

         GROUP BY ppp.person_id;

2.Task managers fro a task on Expense Report:

SELECT pt.task_manager_person_id person_id
             FROM ap_exp_report_dists_all aerd, pa_tasks pt
            WHERE     aerd.report_header_id = p_transaction_id
                  AND aerd.task_id = pt.task_id
                  AND pt.task_manager_person_id IS NOT NULL
                  AND TRUNC (SYSDATE) BETWEEN TRUNC (
                                                 NVL (pt.start_date, SYSDATE))
                                          AND TRUNC (
                                                 NVL (pt.completion_date,
                                                      SYSDATE + 1))
         GROUP BY pt.task_manager_person_id;

Useful Queries for Purchase Requisitions


1.Query to find requisition total amount:

 SELECT nvl(SUM(decode(order_type_lookup_code, 
'RATE', amount, 
'FIXED PRICE', amount, 
quantity * unit_price)), 0) req_amount,
po_ame_setup_pvt.get_function_currency(max(requisition_header_id)) req_func_currency, 
po_ame_setup_pvt.get_rate_type(max(requisition_header_id)) rate_type

from   po_requisition_lines_all 
where requisition_header_id = po_ame_setup_pvt.get_new_req_header_id(3915049)
and  nvl(cancel_flag, 'N') = 'N'
and  nvl(modified_by_agent_flag, 'N') = 'N';
select approved_date from po_requisition_headers_all where requisition_header_id=3915049;

2.Latest Change Request/Change Order details:
Change Order gets created for a Requisition when the req lines created onto Purchase order and then  a change need in Requisition.

 SELECT MAX (change_request_group_id) change_request_group_id, MAX(last_update_date) last_update_date
           FROM po_change_requests
          WHERE     document_header_id = p_transaction_id

                AND document_type = 'REQ';

PO_REQUISITION_HEADERS_ALL.CHANGE_PENDING_FLAG => Indicates whether requisition is in Change Order process or not

3. Requisition amount from a change request

 SELECT NVL (
                   SUM (
                      DECODE (
                         pcr3.action_type,
                         'CANCELLATION', 0,
                         DECODE (
                            prl.order_type_lookup_code,
                            'RATE', NVL (pcr4.new_amount, prl.amount),
                            'FIXED PRICE', NVL (pcr4.new_amount, prl.amount),
                              NVL (pcr1.new_price, prl.unit_price)
                            * NVL (pcr2.new_quantity, prl.quantity)))),
                   0)
           FROM po_requisition_lines_all prl,
                po_change_requests pcr1,
                po_change_requests pcr2,
                po_change_requests pcr3,
                po_change_requests pcr4
          WHERE     prl.requisition_line_id = pcr1.document_line_id(+)
                AND pcr1.change_request_group_id(+) =
                       l_change_request_group_id
                AND pcr1.request_level(+) = 'LINE'
                AND pcr1.change_active_flag(+) = 'Y'
                AND pcr1.new_price(+) IS NOT NULL
                AND prl.requisition_line_id = pcr2.document_line_id(+)
                AND pcr2.change_request_group_id(+) =
                       l_change_request_group_id
                AND pcr2.request_level(+) = 'LINE'
                AND pcr2.action_type(+) = 'DERIVED'
                AND pcr2.new_quantity(+) IS NOT NULL
                AND prl.requisition_line_id = pcr4.document_line_id(+)
                AND pcr4.change_request_group_id(+) =
                       l_change_request_group_id
                AND pcr4.request_level(+) = 'LINE'
                AND pcr4.action_type(+) = 'DERIVED'
                AND pcr4.new_amount(+) IS NOT NULL
                AND prl.requisition_line_id = pcr3.document_line_id(+)
                AND pcr3.change_request_group_id(+) =
                       l_change_request_group_id
                AND pcr3.request_level(+) = 'LINE'
                AND pcr3.action_type(+) = 'CANCELLATION'
                AND prl.requisition_header_id = p_transaction_id
                AND NVL (prl.modified_by_agent_flag, 'N') = 'N'

                AND NVL (prl.cancel_flag, 'N') = 'N';

4. Last action on PO Requisition:

SELECT TRUNC (MAX (NVL (action_date, SYSDATE)))
           FROM PO_ACTION_HISTORY
          WHERE     1 = 1
                AND object_type_code = 'REQUISITION'
                AND object_id = p_transaction_id

                AND action_code = 'SUBMIT';

5. Project Managers for Requisition:

 SELECT ppp.person_id
             FROM po_requisition_lines_all pla,
                  po_req_distributions_all pda,
                  pa_project_players ppp
            WHERE     1 = 1
                  AND requisition_header_id = p_transaction_id
                  AND pda.requisition_line_id = pla.requisition_line_id
                  AND pda.project_id = ppp.project_id
                  AND ppp.person_id IS NOT NULL
                  AND TRUNC (SYSDATE) BETWEEN TRUNC (
                                                 NVL (ppp.start_date_active,
                                                      SYSDATE))
                                          AND TRUNC (
                                                 NVL (ppp.end_date_active,
                                                      SYSDATE + 1))
                  AND ppp.project_role_type = 'PROJECT MANAGER'

         GROUP BY ppp.person_id;

6. Task managers for a requisition:

  SELECT pt.task_manager_person_id person_id
           FROM po_requisition_lines_all pla,
                po_req_distributions_all pda,
                pa_tasks pt
          WHERE     1 = 1
                AND requisition_header_id = p_transaction_id
                AND pda.requisition_line_id = pla.requisition_line_id
                AND pda.task_id = pt.task_id
                AND pt.task_manager_person_id IS NOT NULL
                AND TRUNC (SYSDATE) BETWEEN TRUNC (pt.start_date)
                                        AND TRUNC (
                                               NVL (pt.completion_date,

                                                    SYSDATE + 1));

7. Requisition Preparer and requester details:

SELECT DISTINCT h.org_id,
                         h.approved_date,
                         h.preparer_id,
                         l.to_person_id requester_id    
           FROM po_requisition_headers_all h, po_requisition_lines_all l 
          WHERE     h.requisition_header_id = p_transaction_id

                AND h.requisition_header_id = l.requisition_header_id;

Sunday 19 June 2016

Customizing Send Separate Remittance Advices and XML Output for Send Separate Remittance Advices

Customizing Send Separate Remittance Advices and  XML Output for Send Separate Remittance Advices:

Send Separate Remittance Advices Program uses the same XML extract used for formatting of payments within the payment instruction except that it includes information about delivery method and address in case of Remittance advice program.

One can customize the IBY_FD_EXTRACT_EXT_PUB extension package to add custom XML tags.

Refer Notes:
*** Format Customization in Oracle Payments for Oracle Applications Release 12 (Doc ID 787467.1) 
*** R12 Oracle Payments Processing 'How To' documents (Doc ID 579132.1) and section How to Create or Modify a Payment Format Using XML Builder

*** R12: Can Users Customize XML Extract? (Doc ID 457539.1)


XML Output for the payment instruction will be saved in iby_trxn_documents

SELECT xmltype(document) 
   FROM iby_trxn_documents 
      WHERE payment_instruction_id=<>;



Thursday 16 June 2016

PLSQL Script to raise a business event

Raise a business event using PL/SQL:


DECLARE
   l_event_name            VARCHAR2 (240)      := 'xx.oracle.apps.send.cancelpo';
   l_event_parameter_list  wf_parameter_list_t := wf_parameter_list_t ();
   L_ORG_ID number := 101;
   L_PO_HEADER_ID Number := 100;
   l_event_data clob;

   --
BEGIN

         wf_event.addparametertolist (p_name                => 'ORG_ID'
                                    , p_value                       => L_ORG_ID
                                    , p_parameterlist               => l_event_parameter_list
                                      );
         wf_event.addparametertolist (p_name                        => 'PO_HEADER_ID'
                                    , p_value                       => L_PO_HEADER_ID
                                    , p_parameterlist               => l_event_parameter_list
                                      );
         wf_event.addparametertolist (p_name                        => 'USER_ID'
                                    , p_value                       => fnd_global.user_id
                                    , p_parameterlist               => l_event_parameter_list
                                      );
         wf_event.addparametertolist (p_name                        => 'RESP_ID'
                                    , p_value                       => fnd_global.resp_id
                                    , p_parameterlist               => l_event_parameter_list
                                      );
         wf_event.addparametertolist (p_name                        => 'RESP_APPL_ID'
                                    , p_value                       => fnd_global.resp_appl_id
                                    , p_parameterlist               => l_event_parameter_list
                                      );
         --

        l_event_data :=  '<EVENT_XML_DATA>
                <SUPPLIER>ABC LTD</SUPPLIER>
                <PO_NUMBER>1234</PO_NUMBER>
  </EVENT_XML_DATA>';

         wf_event.raise(p_event_name => l_event_name,
                        p_event_key =>  L_PO_HEADER_ID ,  //SYS_GUID ()
                        p_event_data => l_event_data,
                        p_parameters => l_event_parameter_list,
                        p_send_date => Sysdate);

EXCEPTION
    WHEN OTHERS
    THEN
        DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
/