Tuesday, 19 May 2015

Applied and Unapplied Credit Memo Query

                  select *
                    from ar_receivable_applications_all ra,
                         AR_PAYMENT_SCHEDULES_ALL       APSA,
                         ra_customer_trx_all            rcta
                   where ra.applied_customer_trx_id      = rcta.customer_trx_id
                     and ra.applied_payment_schedule_id  =apsa.payment_schedule_id
                     and rcta.customer_trx_id  = 3419
                     and ra.application_type = 'CM'
                     and ra.status = 'APP'
                     and apsa.status IN ('CL', 'OP')
                     and ra.apply_date between to_date(&sd) and
                         to_date(&ed);

Tuesday, 5 May 2015

WEB ADI Creation (using API)

1: Create a table
   Where WEB ADI will store the data. Table might be created in Custom schema.

2. Create a Package.
   (It has to be in APPS Schema)
   In this case XX_TRAVEL_EXPENSE_ADI_PKG package,
   procedure XX_TRAVEL_EXPENSE_PRC.
** Note XX_TRAVEL_EXPENSE_PRC parameters should start with p_
(

      p_company             VARCHAR2,
      p_vendor_name         VARCHAR2,
      p_invoice_num         VARCHAR2,
      p_inv_currency        VARCHAR2,
      p_invoice_date        DATE,

)
then only prompt will automatically appear company , vendor_name, invoice_num, inv_currency, invoice_date.

3. Once the database object is created,  then create integrator.
DECLARE
  ln_application_id  NUMBER;
  lc_integtr_code    VARCHAR2(50);
  lx_interface_code  VARCHAR2(50);
  lx_param_list_code VARCHAR2(50);
  ln_application_id  NUMBER;
  ln_ret             number;

  --Create integrator
BEGIN
  bne_integrator_utils.create_integrator(p_application_id       => 20003,
                                         p_object_code          => 'XX_TRAVEL_INV',
                                         p_integrator_user_name => 'XX Travel Invoice Upload WEB ADI',
                                         p_language             => 'US',
                                         p_source_language      => 'US',
                                         p_user_id              => -1,
                                         p_integrator_code      => lc_integtr_code);
  DBMS_OUTPUT.put_line('lc_integtr_code =  ' || lc_integtr_code);
END;

Check it once it is created

SELECT *
  FROM bne_integrators_b
 WHERE integrator_code LIKE 'XX_TRAVEL_INV%';

4. Create Interface
DECLARE
  ln_application_id  NUMBER;
  lc_integtr_code    VARCHAR2(50);
  lx_interface_code  VARCHAR2(50);
  lx_param_list_code VARCHAR2(50);
  ln_application_id  NUMBER;
BEGIN
  bne_integrator_utils.create_interface_for_api(p_application_id      => 20003,
                                                p_object_code         => 'XX_TRAVEL_INV',
                                                p_integrator_code     => 'XX_TRAVEL_INV_INTG',
                                                p_api_package_name    => 'XX_TRAVEL_EXPENSE_ADI_PKG',
                                                p_api_procedure_name  => 'XX_TRAVEL_EXPENSE_PRC',
                                                p_interface_user_name => 'XX Travel Invoice Upload WEB ADI',
                                                p_param_list_name     => 'XX Travel Invoice PL',
                                                p_api_type            => 'PROCEDURE',
                                                p_api_return_type     => NULL,
                                                p_upload_type         => 2,
                                                p_language            => 'US',
                                                p_source_lang         => 'US',
                                                p_user_id             => -1,
                                                p_param_list_code     => lx_param_list_code,
                                                p_interface_code      => lx_interface_code);
  DBMS_OUTPUT.put_line('lx_interface_code  =   ' || lx_interface_code);
  DBMS_OUTPUT.put_line('lx_param_list_code =   ' || lx_param_list_code);
  --EXCEPTION
  --   WHEN OTHERS
  --   THEN
  --      DBMS_OUTPUT.put_line ('Error  =      ' || SQLERRM);
END;

Check Interface

SELECT * FROM bne_interface_cols_tl WHERE interface_code LIKE 'XX%';

SELECT * FROM bne_interface_cols_vl WHERE interface_code LIKE 'XX%';

SELECT * FROM bne_interface_cols_b WHERE interface_code LIKE 'XX%';


4. Create an ADI function with following values:

FunctionName UserFunctionName Description         Type                  MaintainanceMode ContextDependence
************************************************************************************************************************
   SSWA servlet function None   Responsibility

Form Application
*********************************************************************************
Parameter
***************************************
 bne:page=BneCreateDoc&bne:noreview=true&bne:integrator=20003:GENERAL%25&bne:reporting=N

HTML Call   Host Name
*********************************************************************************
BneApplicationService  http://le0003.oracleads.com:80


5. Use the ORACLE WEB ADI responsibility and go to DEFINE LAYOUT option

  Give LAYOUT name
 From the drop down select the INTERGRATOR USER NAME as defined above and click on 'GO'
 A screen with all the procedure parameters will appear.
 Select 'LINE' as placement value for all the parameters and APPLY

7. Create and entry against the USER FUNCTION NAME in the menu under which ADI needs to be accessed.
ADI is ready to use.



Additional Steps:
Add Date LOV in the WEB ADI Column


DECLARE
  ln_application_id  NUMBER;
  lc_integtr_code    VARCHAR2(50);
  lx_interface_code  VARCHAR2(50);
  lx_param_list_code VARCHAR2(50);
  ln_application_id  NUMBER;
BEGIN
  bne_integrator_utils.create_calendar_lov(p_application_id     => 20003,
                                           p_interface_code     => 'XX_TRAVEL_INV_INTF',
                                           p_interface_col_name => 'P_INVOICE_DATE', --proc params
                                           p_window_caption     => 'Select Date',
                                           p_window_width       => 400,
                                           p_window_height      => 300,
                                           p_table_columns      => 'INVOICE_DATE',
                                           p_user_id            => 10803);
END;

ADD Lov in the fields,

DECLARE
  ln_application_id  NUMBER;
  lc_integtr_code    VARCHAR2(50);
  lx_interface_code  VARCHAR2(50);
  lx_param_list_code VARCHAR2(50);
  ln_application_id  NUMBER;
BEGIN
  bne_integrator_utils.create_table_lov(p_application_id     => 20003,
                                        p_interface_code     => 'XX_TRAVEL_INV_INTF',
                                        p_interface_col_name => 'P_INV_CURRENCY',
                                        p_id_col             => 'CURRENCY_CODE',
                                        p_mean_col           => 'CURRENCY_CODE',
                                        p_desc_col           => 'CURRENCY_CODE',
                                        p_table              => 'GL_CURRENCIES',
                                        p_addl_w_c           => 'NVL (ENABLED_FLAG, ''N'') = ''Y''',
                                        p_window_caption     => 'Select Currency',
                                        p_window_width       => 400,
                                        p_window_height      => 300,
                                        p_table_block_size   => 10,
                                        p_table_sort_order   => 'Yes',
                                        p_user_id            => 0);
END;

Other usefull API:
1. Delete Integrator
DECLARE
  v_value NUMBER;
BEGIN
  v_value := bne_integrator_utils.delete_integrator(20003,
                                                    'XX_TRAVEL_INV_INTG');
  DBMS_OUTPUT.put_line(v_value);
END;

2. delete Interface
DECLARE
  v_value NUMBER;
BEGIN
  v_value := bne_integrator_utils.DELETE_INTERFACE(20003,
                                                   'XX_TRAVEL_INV_INTF');
  DBMS_OUTPUT.put_line(v_value);
END;

Change the Prompt lebel, UPDATE bne_interface_cols_tl SET prompt_left = 'Company', prompt_above = 'Company', user_hint = '*List - Text' WHERE prompt_left = 'COMPANY' AND interface_code = 'XX_TRAVEL_INV_INTF' AND LANGUAGE = 'US';

UPDATE bne_interface_cols_tl
   SET prompt_left  = 'Invoice Date',
       prompt_above = 'Invoice Date',
       user_hint    = '*List - Date'
 WHERE prompt_left = 'INVOICE_DATE'
   AND interface_code = 'XX_TRAVEL_INV_INTF'
   AND LANGUAGE = 'US';

XML report template migration from one instance to another

RTF template migration from A instance to B instance.
Here XX is the custom application

---template definition download command
SELECT 'FNDLOAD apps/app5 0 Y DOWNLOAD $XDO_TOP/patch/115/import/xdotmpl.lct ' ||
       template_code || '.ldt XDO_DS_DEFINITIONS'
  FROM xdo_templates_b
 WHERE application_short_name = 'XX';

---template definition upload command
SELECT 'FNDLOAD apps/apps 0 Y UPLOAD $XDO_TOP/patch/115/import/xdotmpl.lct ' ||
       template_code || '.ldt'
  FROM xdo_templates_b
 WHERE application_short_name = 'XX';

--template file download command
SELECT 'java oracle.apps.xdo.oa.util.XDOLoader DOWNLOAD -DB_USERNAME -DB_PASSWORD -JDBC_CONNECTION -LOB_TYPE ' ||
       lob_type || ' -APPS_SHORT_NAME ' || application_short_name ||
       ' -LOB_CODE ' || lob_code || ' -LANGUAGE ' || LANGUAGE ||
       ' -TERRITORY ' || territory
  FROM xdo_lobs
 WHERE application_short_name = 'XX';

--template file upload command
SELECT 'java oracle.apps.xdo.oa.util.XDOLoader UPLOAD -DB_USERNAME -DB_PASSWORD -JDBC_CONNECTION -LOB_TYPE ' ||
       lob_type || ' -APPS_SHORT_NAME ' || application_short_name ||
       ' -LOB_CODE ' || lob_code || ' -LANGUAGE ' || LANGUAGE ||
       ' -TERRITORY ' || territory || ' -XDO_FILE_TYPE ' || xdo_file_type ||
       ' -FILE_CONTENT_TYPE ''' || file_content_type || ''' -FILE_NAME ' ||
       lob_code
  FROM xdo_lobs
 WHERE application_short_name = 'XX';

R12 Internal Bank Details query

SELECT hou.NAME                        "OPERATING UNIT",
       cbbv.bank_name,
       cbbv.bank_branch_name,
       cba.bank_account_name,
       hp.party_name                   "LEGAL ENTITY",
       cbau.ar_use_enable_flag         "RECEIVABLES_ACCOUNT_USE",
       cbau.ap_use_enable_flag         "PAYABLES_ACCOUNT_USE",
       cba.bank_account_num            "ACCOUNT_NUMBER",
       cba.bank_account_type           "ACCOUNT TYPE",
       cba.iban_number,
       cba.currency_code,
       cba.multi_currency_allowed_flag,
       cba.description,
       gcck1.concatenated_segments     "CASH ACCOUNT",
       gcck2.concatenated_segments     "BANK_CHARGES_ACCOUNT",
       gcck3.concatenated_segments     "FOREIGN_EXCHANGE_CHARGES",
       gcck4.concatenated_segments     "CASH_CLEARING_ACCOUNT",
       gcck5.concatenated_segments     "BANK_ERRORS_ACCOUNT",
       gcck6.concatenated_segments     "FUTURE_DATED_PAYMENT_ACCOUNT",
       cba.ap_amount_tolerance         "PAYMENT_TOLERANCE_AMOUNT",
       cba.ap_percent_tolerance        "PAYMENT_TOLERANCE_PERCENTAGE",
       cba.ar_amount_tolerance         "RECEIPT_TOLERANCE_AMOUNT",
       cba.ar_percent_tolerance        "RECEIPT_TOLERANCE_PERCENTAGE",
       cba.ce_amount_tolerance         "CASHFLOW_TOLERANCE_AMOUNT",
       cba.ce_percent_tolerance        "CASHFLOW_TOLERANCE_PERCENTAGE",
       cba.recon_oi_amount_tolerance   "OPEN_INT_TOLERANCE_AMOUNT",
       cba.recon_oi_percent_tolerance  "OPEN_INT_TOLERANCE_PERCENTAGE",
       gcck7.concatenated_segments     "ON_ACCOUNT_ACCOUNT",
       gcck8.concatenated_segments     "UNAPPLIED_ACCOUNT",
       gcck9.concatenated_segments     "UNIDENTIFIED_ACCOUNT",
       gcck10.concatenated_segments    "ASSET_ACCOUNT",
       gcck11.concatenated_segments    "REMITTANCE_ACCOUNT",
       gcck12.concatenated_segments    "RECEIPT_CLEARING_ACCOUNT"
  FROM ce_bank_accounts         cba,
       ce_bank_acct_uses_all    cbau,
       ce_gl_accounts_ccid      cgac,
       ce_bank_branches_v       cbbv,
       hr_operating_units       hou,
       hz_parties               hp,
       gl_code_combinations_kfv gcck1,
       gl_code_combinations_kfv gcck2,
       gl_code_combinations_kfv gcck3,
       gl_code_combinations_kfv gcck4,
       gl_code_combinations_kfv gcck5,
       gl_code_combinations_kfv gcck6,
       gl_code_combinations_kfv gcck7,
       gl_code_combinations_kfv gcck8,
       gl_code_combinations_kfv gcck9,
       gl_code_combinations_kfv gcck10,
       gl_code_combinations_kfv gcck11,
       gl_code_combinations_kfv gcck12
 WHERE cbbv.bank_party_id = cba.bank_id
   AND cbbv.branch_party_id = cba.bank_branch_id
   AND cba.bank_account_id = cbau.bank_account_id
   AND cgac.bank_acct_use_id = cbau.bank_acct_use_id
   AND cbau.org_id = hou.organization_id
   AND hp.party_id = cba.account_owner_party_id
   AND gcck1.code_combination_id = cgac.ap_asset_ccid
   AND gcck2.code_combination_id = cgac.bank_charges_ccid
   AND gcck3.code_combination_id = cba.fx_charge_ccid
   AND gcck4.code_combination_id = cgac.cash_clearing_ccid
   AND gcck5.code_combination_id(+) = cgac.bank_errors_ccid
   AND gcck6.code_combination_id(+) = cgac.future_dated_payment_ccid
   AND gcck7.code_combination_id = cgac.on_account_ccid
   AND gcck8.code_combination_id = cgac.unapplied_ccid
   AND gcck9.code_combination_id = cgac.unidentified_ccid
   AND gcck10.code_combination_id(+) = cgac.asset_code_combination_id
   AND gcck11.code_combination_id = cgac.remittance_ccid
   AND gcck12.code_combination_id = cgac.receipt_clearing_ccid

Text Attachment content print

Various files are attached in the documents like PO, Requisition, Invoice etc. If an attachment is a text type then  it is possible to print the content of the attachment .

One of the example various PO terms and conditions are added in the PO header or line level. The following script will help print in the report.


/* Formatted on 2013/01/11 23:36 (Formatter Plus v4.8.8) */
DECLARE
  CURSOR cur_file_info(i_hdr_id NUMBER) IS
    SELECT DISTINCT seq_num, media_id
      FROM fnd_attached_docs_form_vl
     WHERE pk1_value = i_hdr_id
       AND category_description = 'To Supplier'
       AND datatype_name = 'File'
     ORDER BY seq_num;
BEGIN
  BEGIN
    l_file_content := NULL;
 
    FOR get_file_content IN cur_file_info(:po_header_id) LOOP
      SELECT file_id, file_name
        INTO l_file_id, l_file_name
        FROM fnd_lobs
       WHERE file_content_type = 'text/plain'
         AND file_id = get_file_content.media_id;
   
      populate_file_content(l_file_id, l_file_content);
    END LOOP;
  END;
END;





PROCEDURE populate_file_content(i_file_id      NUMBER,
                                i_file_content OUT VARCHAR2) IS
  l_blob         BLOB;
  l_clob         CLOB := EMPTY_CLOB();
  l_src_offset   NUMBER := 1;
  l_dest_offset  NUMBER := 1;
  l_blob_csid    INTEGER := 0;
  v_lang_context INTEGER := 0;
  l_warning      NUMBER;
  l_amount       BINARY_INTEGER;
  l_buffer_size CONSTANT BINARY_INTEGER := 32767;
  l_buffer VARCHAR2(32767) := NULL;
  --l_file_content           VARCHAR2 (32767) := NULL;
  l_offset NUMBER := 1;
BEGIN
  l_buffer := NULL;
  DBMS_LOB.createtemporary(l_blob, TRUE);
  DBMS_LOB.createtemporary(l_clob, TRUE);

  SELECT file_data INTO l_blob FROM fnd_lobs WHERE file_id = i_file_id;

  IF DBMS_LOB.getlength(l_blob) > 0 THEN
    DBMS_LOB.converttoclob(l_clob,
                           l_blob,
                           DBMS_LOB.getlength(l_blob),
                           l_dest_offset,
                           l_src_offset,
                           1,
                           v_lang_context,
                           l_warning);
  END IF;

  l_amount := l_buffer_size;

  WHILE l_amount >= l_buffer_size LOOP
    BEGIN
      DBMS_LOB.READ(lob_loc => l_clob,
                    amount  => l_amount,
                    offset  => l_offset,
                    buffer  => l_buffer);
      l_buffer := REPLACE(l_buffer, CHR(13), '');
      l_offset := l_offset + l_amount;
    EXCEPTION
      WHEN OTHERS THEN
        NULL;
    END;
  END LOOP;

  i_file_content := l_buffer;
EXCEPTION
  WHEN OTHERS THEN
    NULL;
END;

R12 Vendor/Supplier Bank Details Query

------------------------------------------------
Employee as a supplier Bank details
------------------------------------------------

SELECT aps.vendor_id,
       apss.vendor_site_id,
       aps.vendor_name,
       apss.vendor_site_code,
       ieb.bank_name,
       ieb.country,
       iebb.bank_branch_name,
       iebb.eft_swift_code,
       iebb.branch_number,
       ieba.bank_account_num,
       ieba.bank_account_name,
       iban
  FROM ap.ap_suppliers              aps,
       per_all_people_f             papf,
       ap.ap_supplier_sites_all     apss,
       apps.iby_ext_bank_accounts   ieba,
       apps.iby_account_owners      iao,
       apps.iby_ext_banks_v         ieb,
       apps.iby_ext_bank_branches_v iebb
 WHERE aps.vendor_id = apss.vendor_id
   AND iao.account_owner_party_id = aps.party_id
   AND ieba.ext_bank_account_id = iao.ext_bank_account_id
   AND ieb.bank_party_id = iebb.bank_party_id
   AND ieba.branch_id = iebb.branch_party_id
   AND ieba.bank_id = ieb.bank_party_id
   AND aps.employee_id = papf.person_id
   AND TRUNC(SYSDATE) BETWEEN papf.effective_start_date AND
       papf.effective_end_date;
     
-----------------------------------------------------
Supplier Bank details (Not an Employee)
-----------------------------------------------------

SELECT aps.vendor_id,
       apss.vendor_site_id,
       aps.vendor_name,
       apss.vendor_site_code,
       ieb.bank_name,
       ieb.country,
       iebb.bank_branch_name,
       iebb.eft_swift_code,
       iebb.branch_number,
       ieba.bank_account_num,
       ieba.bank_account_name,
       iban
  FROM ap.ap_suppliers              aps,
       ap.ap_supplier_sites_all     apss,
       apps.iby_ext_bank_accounts   ieba,
       apps.iby_account_owners      iao,
       apps.iby_ext_banks_v         ieb,
       apps.iby_ext_bank_branches_v iebb
 WHERE aps.vendor_id = apss.vendor_id
   AND iao.account_owner_party_id = aps.party_id
   AND ieba.ext_bank_account_id = iao.ext_bank_account_id
   AND ieb.bank_party_id = iebb.bank_party_id
   AND ieba.branch_id = iebb.branch_party_id
   AND ieba.bank_id = ieb.bank_party_id

---Check series information exists in CE_PAYMENT_DOCUMENTS table.

Monday, 20 April 2015

Payable Aging Report Query

SELECT org_name,


vendor_name,

vendor_number,

vendor_site_details,

invoice_number,

invoice_date,

gl_Date,

invoice_type,

due_date,

past_due_days,

amt_due_remaining,

CASE

WHEN past_due_days >= -999 AND past_due_days < 0 THEN

amt_due_remaining

ELSE

0

END CURRENT_BUCKET,

CASE

WHEN past_due_days >= 0 AND past_due_days <= 30 THEN

amt_due_remaining

ELSE

0

END BUCKET_0_30,

CASE

WHEN past_due_days > 30 AND past_due_days <= 60 THEN

amt_due_remaining

ELSE

0

END BUCKET_31_60,

CASE

WHEN past_due_days > 60 AND past_due_days <= 90 THEN

amt_due_remaining

ELSE

0

END BUCKET_61_90,

CASE

WHEN past_due_days > 90 AND past_due_days <= 120 THEN

amt_due_remaining

ELSE

0

END BUCKET_91_120,

CASE

WHEN past_due_days > 120 AND past_due_days <= 999999 THEN

amt_due_remaining

ELSE

0

END GREATER_THAN_120

FROM (SELECT hou.name org_name,

pv.vendor_name vendor_name,

pv.segment1 vendor_number,

pvs.vendor_site_code

' '

pvs.city

' '

state vendor_site_details,

i.invoice_num invoice_number,

i.payment_status_flag,

i.invoice_type_lookup_code invoice_type,

i.invoice_date Invoice_Date,

i.gl_date Gl_Date,

ps.due_date Due_Date,

(CEIL(SYSDATE - ps.due_date)) past_due_days, -- DAYS_DUE,

DECODE(i.invoice_currency_code,

'USD',

DECODE(0,

0,

ROUND(((NVL(ps.amount_remaining, 0) /

(NVL(i.payment_cross_rate, 1))) *

NVL(i.exchange_rate, 1)),

2),

ROUND(((NVL(ps.amount_remaining, 0) /

(NVL(i.payment_cross_rate, 1))) *

NVL(i.exchange_rate, 1)) / 0) * 0),

DECODE(i.exchange_rate,

NULL,

0,

DECODE(0,

0,

ROUND(((NVL(ps.amount_remaining, 0) /

(NVL(ps.payment_cross_rate, 1))) *

NVL(i.exchange_rate, 1)),

2),

ROUND(((NVL(ps.amount_remaining, 0) /

(NVL(i.payment_cross_rate, 1))) *

NVL(i.exchange_rate, 1)) / 0) * 0))) amt_due_remaining

FROM ap_payment_schedules_all ps,

ap_invoices_all i,

ap_suppliers pv,

ap_supplier_sites_all pvs,

ap_lookup_codes alc1,

hr_operating_units hou

WHERE i.invoice_id = ps.invoice_id

AND i.vendor_id = pv.vendor_id

AND i.vendor_site_id = pvs.vendor_site_id

AND i.org_id = hou.organization_id

AND i.cancelled_date IS NULL

AND ps.amount_remaining = 0

AND (NVL(ps.amount_remaining, 0) * NVL(i.exchange_rate, 1)) != 0

AND i.payment_status_flag IN ('N', 'P')

AND alc1.lookup_type(+) = 'INVOICE TYPE'

AND alc1.lookup_code(+) = i.invoice_type_lookup_code

--and i.INVOICE_NUM ='358908411'

AND ap_invoices_pkg.get_approval_status(i.invoice_id,

i.invoice_amount,

ps.payment_status_flag,

invoice_type_lookup_code) in

('APPROVED', 'NEEDS REAPPROVAL'))

-- AND i.org_id = fnd_profile.VALUE ('ORG_ID'))

ORDER BY 2, 6;

Query to Find Receipt Class and its GL Combinition Query

SELECT ARC.NAME ReceiptClass,        ARC.CREATION_METHOD_CODE Creation_Mehthod,        DECODE (ARC.REMIT_METHOD_CODE,             ...