Tuesday, 17 July 2018

PLSQL Query for Payables Subledger Account Analysis Report - Oracle EBS R12

https://aporaclepayables.blogspot.com/2018/07/p.html


Subledger Account Analysis Report PLSQL Query for Payables


---Begning Balance 

   select sum(b.ACCOUNTED_DR) , sum(b.ACCOUNTED_CR) ,  sum(b.ACCOUNTED_DR) - sum(b.ACCOUNTED_CR) from xla_ae_headers a, xla_ae_lines b, gl_code_combinations c
    where a.AE_HEADER_ID=b.AE_HEADER_ID
    and a.LEDGER_ID=b.LEDGER_ID
    and a.APPLICATION_ID=b.APPLICATION_ID
    and b.CODE_COMBINATION_ID=c.CODE_COMBINATION_ID
    and a.JE_CATEGORY_NAME in ('Purchase Invoices' , 'Reconciled Payments')
    and a.APPLICATION_ID = 200
    and a.LEDGER_ID = 2031
    and b.ACCOUNTING_DATE < = '30-JUN-2017'
    and c.SEGMENT1 = '02'
    and c.SEGMENT2 = '002'
    and c.SEGMENT3 = '000'
    and c.SEGMENT4 = '248111100'
 

 --Period Debit Credit  ----   Depends on the Accounting date you provide   

    select a.DOC_SEQUENCE_VALUE , a.JE_CATEGORY_NAME , b.ACCOUNTING_DATE, b.ACCOUNTED_DR , b.ACCOUNTED_CR from xla_ae_headers a, xla_ae_lines b, gl_code_combinations c
    where a.AE_HEADER_ID=b.AE_HEADER_ID
    and a.LEDGER_ID=b.LEDGER_ID
    and a.APPLICATION_ID=b.APPLICATION_ID
    and b.CODE_COMBINATION_ID=c.CODE_COMBINATION_ID
    and a.JE_CATEGORY_NAME in ('Purchase Invoices' , 'Reconciled Payments')
    and a.APPLICATION_ID = 200
    and a.LEDGER_ID = 2031
    and b.ACCOUNTING_DATE between '01-JUL-17' and '31-JUL-17'
    and c.SEGMENT1 = '02'
    and c.SEGMENT2 = '002'
    and c.SEGMENT3 = '000'
    and c.SEGMENT4 = '248111100'

 -------------------------------------------------------------------------------------------------------------------

Summary Report


select    BR.PERIOD_NAME, BEG  , DR , CR  , sum(BEG-CR+DR) END   from  

 
( select  /*a.DOC_SEQUENCE_VALUE DOC1 , a.JE_CATEGORY_NAME  J1, b.ACCOUNTING_DATE A1, */ c.SEGMENT4, c.SEGMENT2,c.SEGMENT1,c.SEGMENT3, a.LEDGER_ID ,sum(b.ACCOUNTED_DR) - sum( b.ACCOUNTED_CR) BEG
from xla_ae_headers a, xla_ae_lines b, gl_code_combinations c
where a.AE_HEADER_ID=b.AE_HEADER_ID
and a.LEDGER_ID=b.LEDGER_ID
and a.APPLICATION_ID=b.APPLICATION_ID
and b.CODE_COMBINATION_ID=c.CODE_COMBINATION_ID
and a.JE_CATEGORY_NAME in ('Purchase Invoices' , 'Reconciled Payments')
and a.APPLICATION_ID = 200
and a.LEDGER_ID = 2031
and b.ACCOUNTING_DATE < = '30-SEP-2017'
and c.SEGMENT1 = '02'
and c.SEGMENT2 = '002'
and c.SEGMENT3 = '000'
and c.SEGMENT4 = '248111100'
group by c.SEGMENT4, c.SEGMENT2,c.SEGMENT1,c.SEGMENT3, a.LEDGER_ID 
)  AR
,
    
( select/* a.DOC_SEQUENCE_VALUE DOC2 , a.JE_CATEGORY_NAME  J2, b.ACCOUNTING_DATE A2,*/ a.PERIOD_NAME,c.SEGMENT4, c.SEGMENT2,c.SEGMENT1,c.SEGMENT3, a.LEDGER_ID ,sum(b.ACCOUNTED_DR) DR , sum( b.ACCOUNTED_CR )  CR 
from xla_ae_headers a, xla_ae_lines b, gl_code_combinations c
where a.AE_HEADER_ID=b.AE_HEADER_ID
and a.LEDGER_ID=b.LEDGER_ID
and a.APPLICATION_ID=b.APPLICATION_ID
and b.CODE_COMBINATION_ID=c.CODE_COMBINATION_ID
and a.JE_CATEGORY_NAME in ('Purchase Invoices' , 'Reconciled Payments')
and a.APPLICATION_ID = 200
and a.LEDGER_ID = 2031
and b.ACCOUNTING_DATE between '01-OCT-17' and '31-OCT-17'
and c.SEGMENT1 = '02'
and c.SEGMENT2 = '002'
and c.SEGMENT3 = '000'
and c.SEGMENT4 = '248111100'
group by a.PERIOD_NAME,c.SEGMENT4, c.SEGMENT2,c.SEGMENT1,c.SEGMENT3, a.LEDGER_ID 
)  BR
where AR.SEGMENT4 = BR.SEGMENT4
and AR.SEGMENT2 = BR.SEGMENT2
and AR.SEGMENT1 = BR.SEGMENT1
and AR.SEGMENT3 = BR.SEGMENT3
and AR.LEDGER_ID = BR.LEDGER_ID
group by  BR.PERIOD_NAME,BEG  , DR , CR 

Monday, 9 July 2018

PLSQL Query for Supplier Exemption Certificate Active/InActive - Oracle EBS R12

https://aporaclepayables.blogspot.com/2018/07/plsql-query-for-supplier-exemption.html

Supplier Exemption Certificate Active/InActive

select

 d.name,
 b.VENDOR_NAME,
 b.VENDOR_ID,
 b.SEGMENT1 "Supplier Number",
 c.VENDOR_SITE_CODE,
 a.TAX_NAME,
 a.CERTIFICATE_NUMBER,
 a.RATE_TYPE,
 a.PRIORITY,
 a.TAX_RATE,
 /* nvl(a.START_DATE,sysdate - 365000) st,
 nvl(a.END_DATE,sysdate + 365000) ed,*/
 case
   when trunc(nvl(a.END_DATE, sysdate + 365000)) < trunc(sysdate) then
    'N'
   when trunc(nvl(a.START_DATE, sysdate - 365000)) > trunc(sysdate) then
    'N'
   else
    'Y'
 end Status,
 to_char(a.START_DATE, 'DD-MON-YYYY') "FROM",
 a.START_DATE,
 to_char(a.END_DATE, 'DD-MON-YYYY') "TO",
 a.END_DATE,
 a.COMMENTS,
 a.ATTRIBUTE1 "Issuing Autority"

  from AP_AWT_TAX_RATES_all  a,
       ap_suppliers          b,
       ap_supplier_sites_all c,
       hr_operating_units    d
 where b.VENDOR_ID = c.VENDOR_ID
   and a.RATE_TYPE = 'CERTIFICATE'
   and b.VENDOR_ID = a.VENDOR_ID
   and a.VENDOR_SITE_ID = c.VENDOR_SITE_ID
   and a.ORG_ID = c.ORG_ID
   and a.ORG_ID = d.organization_id
   and a.ORG_ID = NVL(:P_ORG_ID, a.ORG_ID)
   and b.segment1 = NVL(:SEGMENT1, b.SEGMENT1)
   and c.VENDOR_SITE_CODE = NVL(:VENDOR_SITE_CODE, c.VENDOR_SITE_CODE)
   
      /*
      and ((( nvl(a.START_DATE,sysdate - 365000) between
      to_date(nvl(:P_FROM_DATE,
      to_char(sysdate - 365000, 'DD-MON-YYYY')   ),
      'DD-MON-YYYY') AND
      to_date(nvl(:P_TO_DATE,
      to_char(sysdate + 365000, 'DD-MON-YYYY')),
      'DD-MON-YYYY')) or
      (nvl(a.END_DATE,sysdate + 365000) between
      to_date(nvl(:P_FROM_DATE,
      to_char(sysdate - 365000, 'DD-MON-YYYY')),
      'DD-MON-YYYY') and
      to_date(nvl(:P_TO_DATE,
      to_char(sysdate + 365000, 'DD-MON-YYYY')),
      'DD-MON-YYYY'))) OR
      ((to_date(nvl(:P_FROM_DATE,
      to_char(sysdate - 365000, 'DD-MON-YYYY')),
      'DD-MON-YYYY') between nvl(a.START_DATE,sysdate - 365000) AND nvl(a.END_DATE,sysdate + 365000)) or
      (to_date(nvl(:P_TO_DATE,
      to_char(sysdate + 365000, 'DD-MON-YYYY')),
      'DD-MON-YYYY') between nvl(a.START_DATE,sysdate - 365000) and nvl(a.END_DATE,sysdate + 365000)))) 
      */
   
   and (
     
        ((nvl(a.START_DATE, sysdate - 365000) between
        nvl(:P_FROM_DATE, sysdate - 365000) AND
        nvl(:P_TO_DATE, sysdate + 365000)) or
        (nvl(a.END_DATE, sysdate + 365000) between
        nvl(:P_FROM_DATE, sysdate - 365000) and
        nvl(:P_TO_DATE, sysdate + 365000))) OR
        ((nvl(:P_FROM_DATE, sysdate - 365000) between
        nvl(a.START_DATE, sysdate - 365000) AND
        nvl(a.END_DATE, sysdate + 365000)) or
        (nvl(:P_TO_DATE, sysdate + 365000) between
        nvl(a.START_DATE, sysdate - 365000) and
        nvl(a.END_DATE, sysdate + 365000)))
     
       )
   
   and NVL(case
             when trunc(nvl(a.END_DATE, sysdate + 365000)) < trunc(sysdate) then
              'N'
             when trunc(nvl(a.START_DATE, sysdate - 365000)) > trunc(sysdate) then
              'N'
             else
              'Y'
           end,
           'NA') = NVL(:P_STATUS,
                       NVL(case
                             when trunc(nvl(a.END_DATE, sysdate + 365000)) < trunc(sysdate) then
                              'N'
                             when trunc(nvl(a.START_DATE, sysdate - 365000)) > trunc(sysdate) then
                              'N'
                             else
                              'Y'
                           end,
                           'NA'))
--  and a.START_DATE is null

 order by a.ORG_ID, b.VENDOR_NAME, c.VENDOR_SITE_CODE, a.START_DATE

Tuesday, 26 June 2018

PLSQL Query to get WHT and GST Amounts separately on Each Item Line

https://aporaclepayables.blogspot.com/2018/06/plsql-query-to-get-wht-and-gst-amounts.html

select g.DOC_SEQUENCE_VALUE    APN_No,
       g.INVOICE_NUM,
       g.INVOICE_DATE,
       d.ACCOUNTING_DATE       Distribution_GL_DATE,
       d.description,
       e.cleared_date,
       b.VENDOR_NAME,
       d.line_type_lookup_code Line_Type,
   
       (case
         when d.ATTRIBUTE3 is null then
          gc.SEGMENT1 || '-' || gc.SEGMENT2 || '-' || gc.SEGMENT3 || '-' ||
          gc.SEGMENT4 || '-' || gc.SEGMENT5 || '-' || gc.SEGMENT6 || '-' ||
          gc.SEGMENT7 || '-' || gc.SEGMENT8
         when d.ATTRIBUTE3 is not null then
          (select gcc.segment1 || '-' || gcc.segment2 || '-' || gcc.segment3 || '-' ||
                  gcc.segment4 || '-' || gcc.segment5 || '-' || gcc.segment6 || '-' ||
                  gcc.segment7 || '-' || gcc.segment8
             from gl_code_combinations gcc
            where gcc.segment1 || '-' || gcc.segment2 || '-' || gcc.segment3 || '-' ||
                  gcc.segment4 || '-' || gcc.segment5 || '-' || gcc.segment6 || '-' ||
                  gcc.segment7 || '-' || gcc.segment8 = d.ATTRIBUTE3)
       end
   
       ) Account,
   
       NVL(d.base_amount, d.amount) Amount,

------Please Modify the below Section according to your Tax Setup (For my Case)----------

       (select SUM(NVL(d2.base_amount, d2.amount))
          from ap_invoice_distributions_all d2
         where d2.awt_related_id = d.invoice_distribution_id
           and d2.line_type_lookup_code = 'AWT'
           and d2.DESCRIPTION <> 'GST-SRO98'
           and d2.invoice_id = d.invoice_id) WHT,
   
       (select SUM(NVL(d2.base_amount, d2.amount))
          from ap_invoice_distributions_all d2
         where d2.awt_related_id = d.invoice_distribution_id
           and d2.line_type_lookup_code = 'AWT'
           and d2.DESCRIPTION = 'GST-SRO98'
           and d2.invoice_id = d.invoice_id) GST,

------------------------------------------------------------------------------------------------

       /*
       (select ''''||GRP.NAME
       from AP_AWT_GROUPS GRP
       where GRP.GROUP_ID = D.AWT_ORIGIN_GROUP_ID) AWT_GROUP,
       */
       (select '''' || grp2.name
          from AP_AWT_GROUPS GRP2
         where grp2.group_id = d.pay_awt_group_id) ITEM_GROUP,
       
         (select  sum(gpr4.TAX_RATE)
          from AP_AWT_GROUPS GRP2, AP_AWT_GROUP_TAXES_ALL GPR3,   AP_AWT_TAX_RATES_all gpr4
         where grp2.GROUP_ID = gpr3.GROUP_ID
         and gpr3.TAX_NAME=gpr4.TAX_NAME
         and gpr4.ORG_ID =82
         and gpr4.RATE_TYPE = 'STANDARD'
         and gpr3.ORG_ID=82
         and gpr4.END_DATE is null
         and grp2.group_id = d.pay_awt_group_id
         and gpr3.GROUP_ID=d.PAY_AWT_GROUP_ID
        -- and grp2.Description like '%GST%'
        ) Tax_Rate,
       
        -- select * from AP_AWT_TAX_RATES_ALL
     
        NVL(d.base_amount, d.amount) +  NVL((select SUM(NVL(d2.base_amount, d2.amount))
          from ap_invoice_distributions_all d2
         where d2.awt_related_id = d.invoice_distribution_id
           and d2.line_type_lookup_code = 'AWT'
           and d2.DESCRIPTION <> 'GST-SRO98'
           and d2.invoice_id = d.invoice_id),0) +   NVL((select SUM(NVL(d2.base_amount, d2.amount))
          from ap_invoice_distributions_all d2
         where d2.awt_related_id = d.invoice_distribution_id
           and d2.line_type_lookup_code = 'AWT'
           and d2.DESCRIPTION = 'GST-SRO98'
           and d2.invoice_id = d.invoice_id),0) Amount_Paid_Each_Item,
         
       g.AMOUNT_PAID Total_Amount_Paid,
       g.GL_DATE HEADER_GL_DATE

  from ap_invoice_distributions_All d,
       AP_INVOICE_LINES_All         L,
       ap_invoices_all              g,
       ap_suppliers                 b,
       AP_INVOICE_PAYMENTS_ALL      c,
       ap_checks_all                e,
       gl_code_combinations         gc
 WHERE D.INVOICE_ID = L.INVOICE_ID
   AND D.INVOICE_LINE_NUMBER = L.LINE_NUMBER
   and g.INVOICE_ID = L.INVOICE_ID
   and g.INVOICE_ID = d.INVOICE_ID
   and g.INVOICE_ID = c.INVOICE_ID
   and l.INVOICE_ID = c.INVOICE_ID
   and d.INVOICE_ID = c.INVOICE_ID
   and e.CHECK_ID = c.CHECK_ID
   and gc.CODE_COMBINATION_ID = d.DIST_CODE_COMBINATION_ID
   
   and g.ORG_ID = L.org_id
   and L.org_id = d.Org_id
   and l.ORG_ID = c.ORG_ID
   and c.ORG_ID = g.org_id
   and e.ORG_ID = c.ORG_ID
   and b.VENDOR_ID = g.VENDOR_ID
   and g.org_id = 82
   and c.REVERSAL_FLAG = 'N'
   and trunc(e.CLEARED_DATE) between NVL('01-JUL-14', e.CLEARED_DATE) and
       NVL('30-JUN-18', e.CLEARED_DATE)
      -- and b.VENDOR_NAME  = 'Distributors'
    --   and g.DOC_SEQUENCE_VALUE =16011198
       and d.line_type_lookup_code = 'ITEM'
--and g.INVOICE_ID=115693
--  and g.GL_DATE between '01-JUN-2017' and '30-JUN-2017'
--and d.invoice_id = 94273 -- 3511993--3547454

 order by g.DOC_SEQUENCE_VALUE

How to Change AP Invoice Number

https://aporaclepayables.blogspot.com/2018/06/ap-invoice-number-is-saved-in-following.html


Please apply it on TEST Instance first.

AP Invoice Number is stored in the below tables till Payment Accounting. Please check your Invoice_Id in all tables below


select * from AP_INVOICES_ALL a WHERE invoice_id = '149806' --Invoice_Num


select * from AP_DOCUMENTS_PAYABLE where calling_app_doc_unique_ref2 = '149806'  --Calling_App_Doc_Ref_Number (If AP_INVOICES_ALL  table is updated for Invoice_Num. It will automatically changed in this table)
   

select * from ZX_LINES_DET_FACTORS where trx_id = '149806' --TRX_NUMBER
 
      
SELECT * FROM IBY_DOCS_PAYABLE_ALL idp WHERE idp.CALLING_APP_DOC_UNIQUE_REF2 = '149806' --Calling_App_Doc_Ref_Number

                
select * from xla_transaction_entities_upg xte where xte.SOURCE_ID_INT_1 = '149806'  --Transaction_Number
   
                     
select * from xla_ae_headers where ae_header_id = 466374 --If found in Description (Please search here for ae_header_id)
 
                               
select * from gl_je_headers where je_header_id = 560651  --If found in Description (Please search here for je_header_id)

Monday, 25 June 2018

Fully paid prepayment showing “Unpaid” Status

https://aporaclepayables.blogspot.com/2018/06/fully-paid-prepayment-showing-unpaid.html




SOLUTION


Run the following statement to find the issue data
select * from AP_INVOICES_ALL where invoice_id =&invoice_id

If the invoice is fully paid, the status PAYMENT_STATUS_FLAG should be Y.

For implementing the solution, please execute the following steps:

Step 1. Ensure that you have backup your system before applying the recommended solution.

Step 2. Run the following scripts in a TEST environment first:

A. create table SR_XXX_aia as select * from ap_invoices_all where invoice_id =&invoice_id;

B. update ap_invoices_all set payment_status_flag = ‘Y’ where invoice_id =&invoice_id;


Step 3. If the result are satisfied, issue a commit.

Commit;

Step 4. Confirm that the data is corrected when viewed in the Oracle Applications.

Friday, 4 May 2018

Rounding of WHT in AP (ap_custom_withholding_pkg)

https://aporaclepayables.blogspot.com/2018/05/rounding-of-wht-in-ap.html

-- Begin Custom Code
BEGIN
      SELECT NVL(TR.TAX_RATE,0)
      INTO  p_tax_rate
      FROM AP_AWT_TAX_RATES_ALL TR
      WHERE ORG_ID = FND_PROFILE.VALUE('ORG_ID')
      AND TR.TAX_NAME = p_Tax_Name
      AND RATE_TYPE = 'STANDARD';
 EXCEPTION
   WHEN OTHERS THEN
   NULL;
 END;
   --INSERT INTO xxcs_wht_values
   --values(P_Invoice_exchange_rate, P_Withheld_Amount, p_tax_name,1, p_base_wt_amount,P_BaseCurrCode, p_currcode);
   --p_tax_rate := round(p_tax_rate,2);
 if p_tax_rate >= 1 then
  -- INSERT INTO xxcs_wht_values
  --values (p_tax_rate, P_Withheld_Amount, p_tax_name,2,p_base_wt_amount,P_BaseCurrCode, p_currcode);
  p_orig_inv_amount := (P_Withheld_Amount*100)/p_tax_rate;
--  p_tax_rate := round(p_tax_rate,0);
  P_Withheld_Amount := (p_orig_inv_amount*p_tax_rate)/100;
  P_Base_WT_amount  := P_Withheld_Amount;
  P_Withheld_Amount := ROUND(P_Withheld_Amount,0);
  P_Base_WT_amount  := ROUND(P_Base_WT_amount,0);

--  INSERT INTO xxcs_wht_values
  --values (p_tax_rate, P_Withheld_Amount, p_tax_name,3,p_base_wt_amount,P_BaseCurrCode, p_currcode);

elsif p_tax_rate < 1 and p_tax_rate !=0 then
  p_orig_inv_amount := (P_Withheld_Amount*100)/p_tax_rate;
  P_Withheld_Amount := (p_orig_inv_amount*p_tax_rate)/100;
  P_Base_WT_amount  := P_Withheld_Amount;
end if;

--    null;

-- End Custom Code

-----------------------------------------------------------------------------------------------------------------

For my Case

-- Begin Custom Code
     if nvl(P_Calling_parameter,'') ='HEADER' then
     if (P_Withheld_Amount >= 0 ) THEN
     P_Withheld_Amount := ROUND(P_Unrounded_WT_Amount);
     P_Base_WT_amount  := ROUND(P_Unrounded_WT_Amount);
     ELSE
     P_Withheld_Amount := ROUND(P_Unrounded_WT_Amount);
     P_Base_WT_amount  := ROUND(P_Unrounded_WT_Amount);
     END IF;
  end if;
-- End Custom Code

How to End Date Bank Account?

https://aporaclepayables.blogspot.com/2018/05/how-to-end-date-bank-account.html

To End Date or Inactivate Bank account, first Bank Account use must be end dated before bank account is end dated. Please follow steps as follows:

Step 1: End Date Bank Account Use
 1). Select you Bank Account
2). Click Update
3). Click Account Access
4). Click Access
5). Update Use End Date, This end date to determine when the bank account use is considered inactive.
Repeat steps for all other Use Organizations
Save and Next and Finish.
Once all the Bank account Use Organization is End Dated, then :

Step 2: End Date Bank Account: 
1). Select you Bank Account
2). Click Update
3). Click to Go to Account Information
4). Enter start and end dates or only end date to determine when the bank account is considered inactive.
Save and Next and Finish.