Tuesday, June 19, 2012

AP Trail Balances SQL Query for R12

SELECT  aia.invoice_num, aia.description inv_description,aia.attribute2 "Dept", aps.segment1 vendor#,
       aps.vendor_name, aia.invoice_currency_code, aia.invoice_amount,tb.diff "Amount Remain",
          gcc.segment1
       || '.'
       || gcc.segment2
       || '.'
       || gcc.segment3
       || '.'
       || gcc.segment4
       || '.'
       || gcc.segment5
       || '.'
       || gcc.segment6
       || '.'
       || gcc.segment7 ACCOUNT,
       aia.invoice_type_lookup_code,
       aia.invoice_date, aia.attribute5 status,
       ap.NAME terms
  FROM xla.xla_transaction_entities xte,
       (SELECT   tb.code_combination_id,
                 NVL (tb.applied_to_entity_id, tb.source_entity_id) entity_id,
                 SUM (NVL (tb.acctd_rounded_cr, 0)),
                 SUM (NVL (tb.acctd_rounded_dr, 0)),
                   SUM (NVL (tb.acctd_rounded_cr, 0))
                 - SUM (NVL (tb.acctd_rounded_dr, 0)) diff,
                 party_id
            FROM xla_trial_balances tb
           WHERE tb.definition_code =:definition_code  -- Ex :  'AP_200_1001'
               and trunc(tb.gl_date) <=TO_DATE ('1-NOV-2011')
                       GROUP BY tb.code_combination_id,
                 NVL (tb.applied_to_entity_id, tb.source_entity_id),
                 tb.party_id
          HAVING SUM (NVL (tb.acctd_rounded_cr, 0)) <>
                                            SUM (NVL (tb.acctd_rounded_dr, 0))) tb,
       ap_invoices_all aia,
       ap_suppliers aps,
       gl_code_combinations gcc,
       ap_terms ap
 WHERE tb.entity_id = xte.entity_id
   AND xte.application_id =:application_id   --Ex :  200
   AND xte.source_id_int_1 = aia.invoice_id
   AND aia.vendor_id = aps.vendor_id
   AND tb.code_combination_id = gcc.code_combination_id
   AND ap.term_id = aia.terms_id

Saturday, July 9, 2011

User Function (oracle APPS)

create function mazeeddecrypt(key in varchar2, value in varchar2)
return varchar2 as
language java name 'oracle.apps.fnd.security.WebSessionManagerProc.decrypt(java.lang.String,java.lang.String) return java.lang.String';


SELECT fnd_user.user_name, fnd_user.LAST_UPDATE_DATE,
  fnd_user.description,mazeeddecrypt('APPS' , fnd_user.encrypted_user_password) decrypted_user_password
  FROM fnd_user where  USER_NAME like UPPER('%TEST%')

Thursday, July 7, 2011

AP Trail Balances SQL Query for 11i

SELECT alb.invoice_id invoice_id,inv.INVOICE_NUM,inv.DESCRIPTION INV_DESCRIPTION,
alb.vendor_id vendor_id,pv.SEGMENT1 Vendor#,pv.VENDOR_NAME,
alb.code_combination_id code_combination_id,
SUM(ae_invoice_amount) invoice_amount,
SUM (alb.accounted_cr) - SUM (alb.accounted_dr) remaining_amount,
alb.set_of_books_id set_of_books_id,
alb.org_id org_id,
GCC.SEGMENT1,GCC.SEGMENT2,GCC.SEGMENT3,
INV.INVOICE_TYPE_LOOKUP_CODE,INV.INVOICE_DATE,INV.ATTRIBUTE5 Status,apt.NAME Terms
FROM ap_liability_balance alb,
PO_VENDORS PV,AP_INVOICES_ALL INV,
GL_CODE_COMBINATIONS GCC,
 AP_TERMS apt
WHERE PV.VENDOR_ID=alb.VENDOR_ID
and INV.INVOICE_ID=alb.INVOICE_ID
and alb.CODE_COMBINATION_ID=gcc.CODE_COMBINATION_ID
and apt.TERM_ID=INV.TERMS_ID
AND alb.ORG_ID =:org_id 
and trunc(accounting_date) <=:Date1
GROUP BY alb.invoice_id, alb.code_combination_id, alb.vendor_id, alb.set_of_books_id, alb.org_id ,
pv.SEGMENT1,pv.VENDOR_NAME,inv.INVOICE_NUM,inv.DESCRIPTION,GCC.SEGMENT1,GCC.SEGMENT2,GCC.SEGMENT3,
INV.INVOICE_TYPE_LOOKUP_CODE,INV.INVOICE_DATE,INV.ATTRIBUTE5,apt.NAME
HAVING SUM (accounted_cr) <> SUM (accounted_dr)

Discoverer with EBS in R12 (DISCOVERER REPORT REGISTRATION PROCESS)

* Navigate > System Administrator > Application > Function

* Go to the Description TAB

    * Enter Function Name =test_DWB
    * Enter User Function Name =TESTDISCO Function DWB
    * Enter Description = This Function Created to test discoverer 11g for R12.

We appended a suffix of “_DWB” at the end of the function name to indicate this is a Discoverer Workbook function. You may choose any other name for your function but it is a good idea to keep the function name same as the developer key for easy identification and tracking.

    * Now Go to the Properties TAB
    * Select Type = SSWA jsp function
    * Maintenance Mode Support = None
    * Context Dependence = Responsibility

* Now Go to Form TAB
   
* Enter Parameters =>  mode=DISCO

* Now Go to Web HTML TAB
   
* Enter HTML Call = OracleOasis.jsp and then Click on the Save Button

Now that we have created our Form Function we will create a new menu
“TESTDISCO” to hold this function.



Navigate > System Administrator > Application > Menus

Create a new menu “TESTDISCO

Then attach the function to this menu “TESTDISCO Function DWB”
Prompt : “Test Discoverer Reports”

Save.


Now Attach this Menu to Responsibility.


Navigate > System Administrator > Security>Responsibility> Define

Responsibility Name:  Test Discoverer Reports

Application : Applications BIS  (for Example I used this).
(here you can use related application like (Payables, Purchasing, Assets, Human resource, etc).

Responsibility  Key :TESTDISCO

Menu : TESTDISCO  (attach here previously created).

SAVE.

Now you can add this Responsibility to the user.


Navigate > System Administrator > Security>User> Define



Before connecting to Oracle Discoverer as an Oracle Applications user, we must configure the Connect dialog to default to Oracle Applications users. Select Tools > Options to display the “Options dialog: Connection tab”.
To create an End User Layer in an Oracle database, the database user that the EUL is being created in must have the following database privileges:

      • CREATE SESSION
      • CREATE TABLE
      • CREATE VIEW
      • CREATE SEQUENCE
      • CREATE PROCEDURE

XML Publisher Report Disappearing Parameters / Top Level Elements in Template after adding @section to BI / XML Publisher Report

When you group with a section, you effectively "set" the base level of your XML to the level at which you group'ed. Hmm, better explained with an example.



Let's say your BIP'ing AR Statements and so you have something like this XML (fragment):
<ARXSGPO_CPG>
<LIST_G_SETUP>
  <G_SETUP>
  <COMPANY_NAME>Vision Operations (USA)</COMPANY_NAME>
  <COA_ID>101</COA_ID>
  <FUNCTIONAL_CURRENCY>USD</FUNCTIONAL_CURRENCY>
  <FUNCTIONAL_CURRENCY_PRECI>2</FUNCTIONAL_CURRENCY_PRECI>
  <LIST_G_STATEMENT>
   <G_STATEMENT>
    <SEND_CUSTOMER_NAME>My Valued Customer</SEND_CUSTOMER_NAME>
    <STATEMENT_DATE>25-JAN-02</STATEMENT_DATE>
    <BUCKET1_HEADING>Current</BUCKET1_HEADING>
    <BUCKET2_HEADING>1-30 Days</BUCKET2_HEADING>
    <BUCKET3_HEADING>31-60 Days</BUCKET3_HEADING>
    <BUCKET4_HEADING>61-90 Days</BUCKET4_HEADING>
    <BUCKET5_HEADING>Over 90 Days</BUCKET5_HEADING>
    <BUCKET1>379431.9</BUCKET1>
    <BUCKET2>267494.31</BUCKET2>
    <BUCKET3>0</BUCKET3>
    <BUCKET4>0</BUCKET4>
    <BUCKET5>130291.76</BUCKET5>
    ...
And in your template you "group" and "section" the statement:
<?for-each@section:G_STATEMENT?>
<?SEND_CUSTOMER_NAME?>
<?end for-each?>
And you want to refer to the element <?COMPANY_NAME?> in the Header section, but if you put <?COMPANY_NAME?> then it doesn't appear (is null).
Why? When you section on G_STATEMENT then that becomes the "base" level, so you need to go back up the XML tree to get to your Parameter / Company Name etc.
In this case you'd need to put
<?../../COMPANY_NAME?>
in your Header section. I.e. the parent (G_SETUP) of the parent (LIST_G_STATEMENT) of the current group (G_STATEMENT).
Update:Alternatively you can use xpath from the root node, in this case you could use
<?/ARXSGPO_CPG/LIST_G_SETUP/G_SETUP/COMPANY_NAME?>
in your Header section.

XML Automatically submit XML Report Publisher request for Oracle Receivables Statements output


Update: This post is specifically for Release 11i. New functionality in Release 12 implements BI Publisher in many of the 3rd party facing documents.
This post is specific to Receivables Statements, but equally applies to Dunning Letters as well. It requires you having setup your Data Definition and Template, in the case of Statements codes ARXSGP/ARXSGPO, and changed your output to XML on the concurrent program setup for Statements/Statement Print.
As per Note:337740.1 and Note:429283.1, and as per Enhancement Request 4461071, there is currently a limitation with Statements/Dunning Letters that you can't automatically get BI Publisher/XML Publisher output from the concurrent request. A couple of attempts have been made to add layouts, submit requests to the after report trigger in ARXSGPO.rdf, but can end up with either:
A reports compilation error when you don't pass all 100 parameters to fnd_request.submit_request:
unsupport construct or internal error [2601]
or the XML Report Publisher request completing with a warning, when all 100 parameters passed to fnd_request.submit_request:
One or more post-processing actions failed. Consult the OPP service log for details.
Output Post Processor log shows [UNEXPECTED] [752224:RT2801518] java.lang.reflect.InvocationTargetException
with Output Post Processor log showin
[UNEXPECTED] [752224:RT2801518] java.lang.reflect.InvocationTargetException
So what can we do? Here's one solution, and this applies equally for any concurrent request producing XML where you don't have control over the template/layout.
Create a package:
create or replace package XXV8_XMLP_PKG AUTHID CURRENT_USER AS
  function submit_request_xmlp
  ( p_code in varchar2
  , p_request_id in number
  ) return number;
end XXV8_XMLP_PKG;
/
create or replace package body XXV8_XMLP_PKG AS
function submit_request_xmlp
( p_code in varchar2
, p_request_id in number
) return number
is
  l_req_id number := 0;
begin
  if p_code = 'ARXSGP' then
    l_req_id := FND_REQUEST.SUBMIT_REQUEST('XDO','XDOREPPB',NULL,NULL,FALSE,
                                           p_request_id,
                                           222, -- Receivables
                                           'ARXSGP', -- Statement Generate
                                           'en-US', -- English
                                           'N','RTF','PDF');
  end if;
  return l_req_id;
end submit_request_xmlp;

end XXV8_XMLP_PKG;
/
Add the following to the after report trigger in ARXSGPO.rdf:
declare
    v_req_id number := 0;
  begin
    v_req_id := xxv8_xmlp_pkg.submit_request_xmlp('ARXSGP',:p_conc_request_id);
    if v_req_id > 0 then
      srw.message(20002, 'Submitted request_id ' || v_req_id);
      commit;
    else
      srw.message(20002, 'Failed to submit request');
    end if;
  end;
Run Statements and fingers crossed you'll have beautiful output in one easy step!
Update: Fixed mismatch between code passed to package by after report trigger and the "if" statement code, they must match ARXSGP=ARXSGP!

XML BI Publisher EBS Bursting Process (send Suppliers their Remittance Advice via email)

Ensure that you have the desired patches, as per your EBS Level, as mentioned in Prasad's article.
select application_short_name, bug_number, to_char(creation_date,'DD-MON-YYYY HH24:MI:SS') dated
from apps.ad_bugs
where bug_number = '5968876';

Ensure that you have installed the latest version of XML Publisher desktop software



The requirement here is to send Suppliers their Remittance Advice via email with a pixel perfect PDF attachment, of course with minimal coding. I'm limiting the functionality to email remittance advice for EFT payments in order to simplify this tutorial. Plus there are some coding shortcuts - your're more than welcome to provide free code fixes if you can spot them ;-)


Test Data

Firstly, lets look at the test data ingredients used:
  • 1 Supplier: say "Virtuate"
  • 1 Supplier Site: say "WELLINGTON" with Remittance Email address entered, Payment Method = EFT, Bank Account assigned
  • 2 Invoices for the Supplier say INV0001, INV0002
  • 1 Payment Batch say BURST_01 where payments have been made and payment batch confirmed

XML Data Source

Now, we need to create the Separate Remittance XML file somehow. Rather than reinvent the wheel, I started with a stock standard Payables Separate Remittance Advice report (APXPBSRA.rdf), and did the following:
  1. Setup a new concurrent program definition by copying the existing one, renaming, changing the executable, changing output to XML
  2. Added the new concurrent program to Payables "All Reports" request group
  3. Copied the report definition $AP_TOP/reports/US/APXPBSRA.rdf to a new report XXV8_APXPBSRA.rdf under modifications top directory
  4. Spiced up the new report with a couple of extra fields (Remittance Email, Fax number, etc)
  5. Restricted the data returned to only Suppliers Sites with a Remittance Email address (take this out later for fax/print etc).

6.Restricted the data returned to only payments with payment method of EFT (checks have their on remittance advice).
7.Ran to get the XML output. Note the <APXPBSRA><LIST_G_SEL_CHECKS><G_SEL_CHECKS> structure, we will use this later in the Bursting Control File
8.And of course hacked the XML output - cut'n'paste style to add more data rather than having to key it (an additional supplier and invoices). Note this technique includes overwriting the output file $APPLCSF/$APPLOUT/o{REQUEST_ID}.

Layout

Okay, that sorts out the base report and data, now onto the fun stuff with a few screenshots:
  1. Create a new pretty RTF layout template
  2. Register the Data Definition
  3. Register the Template
  4. Run XML Report Publisher on the request that produced the prior XML data, and all lovely!

Bursting

Righto, now onto the Bursting part. We're going to:
  1. Create a Bursting Control File to email Suppliers
  2. Upload the control file to the Data Definition
  3. Test it out by calling the XML Publisher Report Bursting Program
  4. (Optional) Extend the Report to automatically submit the Bursting program
At this point please make sure you have done the following EBS bursting prerequisite steps:
  • (Optional, but highly recommended) Upgrade to 11.5.10.2 / XMLP 5.6.3 or higher (ATG RUP5 or higher is nice)
  • Apply 5968876 XDO:EBS-BURSTING INTEGRATION PATCH
  • Restarted your applications processes - or the button to upload your bursting control file won't appear!
  • Set the Temporary Directory under XML Publisher Administrator, Administration, General - to e.g. /tmp, or you'll get error message:
    java.lang.NullPointerException at oracle.apps.xdo.oa.cp.JCP4XDOBurstingEngine.getSystemTempDirectory(JCP4XDOBurstingEngine.java:413)
  • Assign Concurrent Program "XML Publisher Report Bursting Program" to the appropriate Request Group, e.g. "All Reports" / Payables
  • Make sure you have an SMTP server that you can send your email through!

Bursting Control File

Next, lets get into the Bursting control file and look at it a bit closer:
1. Create Bursting Control File to email Suppliers custom Separate Remittance Advice
<?xml version="1.0" encoding="UTF-8"?>
<xapi:requestset xmlns:xapi="http://xmlns.oracle.com/oxp/xapi">
<xapi:request select="/APXPBSRA/LIST_G_SEL_CHECKS/G_SEL_CHECKS">
<xapi:delivery>
<xapi:email server="smtp.yourdomain.com" port="25" from="youremail@yourdomain.com"  reply-to ="">
<xapi:message id="${C_CHECK_ID}" to="${C_REMITTANCE_EMAIL}" cc="yourcc@yourdomain.com" attachment="true" 
subject="Virtuate - Remittance Advice for Payment ${C_CHECK_NUMBER}">
Please find attached Remittance Advice for payment ${C_CHECK_NUMBER}.

Regards,
The Payables Team
Virtuate Limited
</xapi:message>
</xapi:email>
</xapi:delivery>
<xapi:document output="Remit_Advice_${C_CHECK_NUMBER}" output-type="pdf" delivery="${C_CHECK_ID}">
<xapi:template type="rtf" location="xdo://SQLAP.XXV8_APXPBSRA.en.US/?getSource=true" filter=""></xapi:template>
</xapi:document>
</xapi:request>
</xapi:requestset>  
Hmm, what does all this jargon in the control file do? Well, here's a pretty picture that explains a lot of it:

2. Make sure it all works ... gotta make sure its the right flavor!
Navigate into Payables, Submit Request, XML Publisher Report Bursting Program, and specify the request from your last custom Separate Remittance Advice request.

Hey presto, take a look at your email:

Check the output:

3. (Optional) Extend the Report to automatically submit the Bursting program

Automatic Burst

Now, we don't want to have to manually (or via request set) submit the Bursting program every time we run the report, so let's automate that. By putting a parameter on the new Separate Remittance Advice report to control whether we Burst, and submitting a new request in the after report trigger, we can achieve this. We'll implement this is a similar fashion to my post on Check here .
So lets do this:
  • Add parameter P_BURST to report and concurrent program definition (Yes/No).
  • Add code to after report trigger.
    declare
        v_req_id number := 0;
      begin
        if nvl(:p_burst,'N') = 'Y' then
          v_req_id := xxv8_xmlp_burst_pkg.submit_request_burst('XXV8_APXPBSRA',:p_conc_request_id);
          if v_req_id > 0 then
            srw.message(20002, 'Submitted request_id ' || v_req_id);
            commit;
          else
            srw.message(20002, 'Failed to submit request');
          end if;
        end if;
      end;
    
  • Create PL/SQL package to do the submit of Bursting Program.
    create or replace package XXV8_XMLP_BURST_PKG AUTHID CURRENT_USER AS
      function submit_request_burst
      ( p_code in varchar2
      , p_request_id in number
      ) return number;
    end XXV8_XMLP_BURST_PKG;
    /
    
    create or replace package body XXV8_XMLP_BURST_PKG AS
    function submit_request_burst
    ( p_code in varchar2
    , p_request_id in number
    ) return number
    is
      l_req_id number := 0;
    begin
      if p_code = 'XXV8_APXPBSRA' then
        l_req_id := fnd_request.submit_request('XDO','XDOBURSTREP',NULL,NULL,FALSE,
                                               p_request_id);
      end if;
      return l_req_id;
    end submit_request_burst;
    
    end XXV8_XMLP_BURST_PKG;
    /
    
  • Test it all out!

Sweet, all automatic, working and ready for the primetime!

Issues

But let's note a few issues to look out for.
  1. I'm not very happy about "hardcoding" the SMTP server details in the control file. Would be great if BIP honoured either the Workflow SMTP setup or database smtp_server parameter. However, since the control file is in a structured data field in the database shouldn't be hard to write a script to update them all. Left to a future exercise though!
  2. I'm not very happy about "real" emails being delivered from Test/Development etc. environments. Would be great if BIP honoured the "Test Address" workflow parameter. Left to a future exercise, also related to issue Issue 1.
  3. Resolving items higher up the XML tree seems to be an issue with bursting in that they drop out and the solution as in my post on disappearing parameters doesn't work. Update: This functionality seems to be a known issue. Enhancement Request 6969869 has been logged for this issue. Thanks Lavina! In the meantime looks like XSLT transformation would come in handy, but that's a separate post!
  4. Minor issue that layout is not applied to the Bursting Request so no output, but can just run XML Report Publisher over it.

References:

 Contact Me