Showing posts with label AR. Show all posts
Showing posts with label AR. Show all posts

Thursday, August 13, 2015

Oracle AR Outstanding Amount (Aging Report)

Customer outstanding amount.

The table ar_payment_Schedules_all gives you the outstanding information as on date. For eg. if the system date is 13th April and if you query the ar_payment_schedules_all table, the amount_due_remaining column will give you the open amount as on that date.
However if you want the oustanding as on some previous date, lets say as on 31st March, in that case you have to rollback all the applications that would have occured from 1st april to 13th april.

Find below the script that I used to get the oustanding as on any previous date. Pls. note that I am using a temp table here to populate the details.

CREATE TABLE ZXC_AGING_CUST1
(
   CUSTOMER_ID                NUMBER,
   INVOICE_NUMBER             VARCHAR2 (20),
   INVOICE_DATE               DATE,
   GL_DATE                    DATE,
   INVOICE_AMOUNT             NUMBER,
   TAX_AMOUNT                 NUMBER,
   ACCTD_OUTSTANDING_AMOUNT   NUMBER,
   DUE_DATE                   DATE,
   DAYS_OUTSTANDING           NUMBER,
   INSTALLMENT_NUMBER         NUMBER,
   DAYS_LATE_AS_OF            NUMBER,
   CURRENT_OS_AMT             NUMBER,
   CASH_RECEIPT_AMT           NUMBER,
   ADJ_AMT                    NUMBER,
   CREDIT_MEMO_AMT            NUMBER,
   CREDIT_MEMO_AMT_1          NUMBER
);

CREATE TABLE ZXC_AGING_CUST2
(
   CUSTOMER_ID                NUMBER,
   INVOICE_NUMBER             VARCHAR2 (20),
   TRX_TYPE                   VARCHAR2 (100),
   ACCTD_OUTSTANDING_AMOUNT   NUMBER,
   GL_DATE                    DATE
);


DECLARE
   v_cash_receipt              NUMBER;
   v_adjustment                NUMBER;
   v_credit_memo               NUMBER;
   v_as_of_outstanding         NUMBER;
   v_cash_receipt_acctd        NUMBER;
   v_adjustment_acctd          NUMBER;
   v_credit_memo_acctd         NUMBER;
   v_credit_memo_acctd_1       NUMBER;
   v_as_of_outstanding_acctd   NUMBER;
   p_as_of_date                DATE;


   CURSOR cs_get_trx (
      p_as_of_date1 IN DATE)
   IS
      SELECT ps.customer_id CUST_ACCOUNT_ID,
             trx.creation_date INV_CREATION_DATE,
             ps.trx_number INVOICE_NUMBER,
             trx.trx_date INVOICE_DATE,
             ps.gl_date GL_DATE,
             NVL (ps.amount_due_original, 0) INVOICE_AMOUNT,
             NVL (ps.tax_original, 0) TAX_AMOUNT,
             NVL (ps.acctd_amount_due_remaining, 0) ACCTD_OUTSTANDING_AMOUNT,
             ps.due_date,
             CEIL (SYSDATE - ps.due_date) DAYS_OUTSTANDING,
             ps.payment_schedule_id,
             ps.number_of_due_dates INSTALLMENT_NUMBER,
             trx.customer_trx_id,
             CEIL (p_as_of_date1 - ps.due_date) DAYS_LATE_AS_OF
        FROM ra_customer_trx TRX, ar_payment_schedules PS
       WHERE     trx.customer_trx_id = ps.customer_trx_id
             AND ps.gl_date <= p_as_of_date1
             AND ps.gl_date_closed > p_as_of_date1;


   CURSOR cs_get_receipt (
      p_as_of_date2 IN DATE)
   IS
        SELECT ps.customer_id CUST_ACCOUNT_ID,
               ps.payment_schedule_id,
               CEIL (p_as_of_date - ps.GL_DATE) days_late_as_of_r,
               ps.gl_date,
               cr.receipt_number,
               app.cash_receipt_id,
               SUM (app.acctd_amount_applied_from) ACCTD_AMOUNT_APPLIED
          FROM ar_receivable_applications app,
               ar_cash_receipts cr,
               ar_payment_schedules ps
         WHERE     app.cash_receipt_id = cr.cash_receipt_id
               AND app.payment_schedule_id = ps.payment_schedule_id
               AND app.status IN ('ACC', 'UNAPP', 'UNID', 'OTHER ACC')
               AND NVL (app.confirmed_flag, 'Y') = 'Y'
               AND app.gl_date <= p_as_of_date2
               AND ps.gl_date <= p_as_of_date2
               AND ps.gl_date_closed > p_as_of_date2
               AND (   (    app.reversal_gl_date IS NOT NULL
                        AND ps.gl_date <= p_as_of_date2)
                    OR app.reversal_gl_date IS NULL)
      GROUP BY ps.customer_id,
               cr.receipt_number,
               app.cash_receipt_id,
               ps.payment_schedule_id,
               ps.gl_date
        HAVING SUM (app.acctd_amount_applied_from) <> 0;
BEGIN
   BEGIN
      mo_global.set_policy_context ('S', '69');
   END;

   DELETE zxc_aging_cust1;

   p_as_of_date := TO_DATE ('&Enter_as_of_date', 'DD-MON-RRRR');

   FOR invoice IN cs_get_trx (p_as_of_date)
   LOOP
      /* cash applied after p_as_of_date */

      SELECT NVL (
                SUM (
                     NVL (acctd_amount_applied_to, 0.0)
                   + NVL (acctd_earned_discount_taken, 0.0)
                   + NVL (acctd_unearned_discount_taken, 0.0)),
                0.0)
        INTO v_cash_receipt_acctd
        FROM ar_receivable_applications
       WHERE     TRUNC (gl_date) > p_as_of_date
             AND status || '' = 'APP'
             AND NVL (confirmed_flag, 'Y') = 'Y'
             AND applied_payment_schedule_id = invoice.payment_schedule_id
             AND application_type LIKE 'CASH%';


      /* adjustments applied after p_as_of_date */

      SELECT NVL (SUM (ar_adjustments.acctd_amount), 0.0)
        INTO v_adjustment_acctd
        FROM ar_adjustments
       WHERE     TRUNC (gl_date) > p_as_of_date
             AND status = 'A'
             AND payment_schedule_id = invoice.payment_schedule_id;


      /* invoice credited after p_as_of_date */

      SELECT NVL (SUM (NVL (acctd_amount_applied_to, 0.0)), 0.0)
        INTO v_credit_memo_acctd
        FROM ar_receivable_applications
       WHERE     applied_payment_schedule_id = invoice.payment_schedule_id
             AND NVL (confirmed_flag, 'Y') = 'Y'
             AND status || '' = 'APP'
             AND TRUNC (gl_date) > p_as_of_date
             AND application_type LIKE 'CM%';

      /* credit memo applied after p_as_of_date */
      SELECT NVL (SUM (NVL (acctd_amount_applied_to, 0.0)), 0.0)
        INTO v_credit_memo_acctd_1
        FROM ar_receivable_applications
       WHERE     payment_schedule_id = invoice.payment_schedule_id
             AND NVL (confirmed_flag, 'Y') = 'Y'
             AND status || '' = 'APP'
             AND TRUNC (gl_date) > p_as_of_date
             AND application_type LIKE 'CM%';


      /* calculate actual outstanding amount */

      v_as_of_outstanding_acctd :=
           invoice.acctd_outstanding_amount
         + v_cash_receipt_acctd
         - v_adjustment_acctd
         + v_credit_memo_acctd
         - v_credit_memo_acctd_1;



      INSERT INTO zxc_aging_cust1 (customer_id,
                                   invoice_number,
                                   invoice_date,
                                   gl_date,
                                   invoice_amount,
                                   tax_amount,
                                   acctd_outstanding_amount,
                                   due_date,
                                   days_outstanding,
                                   installment_number,
                                   days_late_as_of,
                                   current_os_amt,
                                   cash_receipt_amt,
                                   adj_amt,
                                   credit_memo_amt,
                                   credit_memo_amt_1)
           VALUES (invoice.cust_account_id,
                   invoice.invoice_number,
                   invoice.invoice_date,
                   invoice.gl_date,
                   invoice.invoice_amount,
                   invoice.tax_amount,
                   v_as_of_outstanding_acctd,
                   invoice.due_date,
                   invoice.days_outstanding,
                   invoice.installment_number,
                   invoice.days_late_as_of,
                   invoice.acctd_outstanding_amount,
                   v_cash_receipt_acctd,
                   v_adjustment_acctd,
                   v_credit_memo_acctd,
                   v_credit_memo_acctd_1);
   END LOOP;

   COMMIT;

   FOR receipt IN cs_get_receipt (p_as_of_date)
   LOOP
      INSERT INTO zxc_aging_cust2 (customer_id,
                                   invoice_number,
                                   trx_type,
                                   acctd_outstanding_amount,
                                   gl_date)
           VALUES (receipt.cust_account_id,
                   receipt.receipt_number,
                   'RECEIPT',
                   -1 * receipt.acctd_amount_applied,
                   receipt.gl_date);
   END LOOP;

   COMMIT;
END;

Thursday, July 30, 2015

Differentiates between a Party and Customer in Oracle Apps

In AR (Account receivables) or TCA (Trading community architecture), we usually comes across two common terms, party and customer. Though both link each other still there are always confusion, below is the difference between party and customer.


PARTY
CUSTOMER
Prospective Customer and more relevant for CRM Purposes
A Customer which is used both in CRM as well as in OM, Financials or any other module Example (A Sales Order in OM or Invoice in Receivables cannot be created without creating a Customer record for the Party).
No Business Transactions involved (Sales Order, Sales Invoice, Debit Memo, Credit Memo, Receipt etc.,)
A Business Transaction like a Sales Order, Invoice, Debit Memo, Credit Memo,Receipt can be created.
A Party does not have account but have Sites
A Customer will have account and as well as Sites.
A Party can exist without Customer Record
A Party record is must to create a Customer Record linked through party_id.
A Party Record will have record in following tables
HZ_PARTIES
HZ_PARTY_SITES 
HZ_PARTY_RELATIONSHIPS
A Customer Record will have records in following tables
    HZ_CUST_ACCOUNTS
    HZ_CUST_ACCT_SITES_ALL
    HZ_CUST_SITE_USES_ALL
    HZ_CUST_ACCOUNT_ROLES
    HZ_CUST_ACCT_RELATE_ALL
     with reference to party_id column.

1. Who is the party? 
2. What is meant by Customer account? 
3. What is the necessary for two entities like above? 
4. Where they are used?

I hope the below article will be useful for persons like me, as this difference is mainly based on the module CRM let us have a small gist about it.

CRM is the acronym for Customer Relationship Management. CRM is basically a marketing tool. If you understand the definition of the word “marketing”, you will easily understand the difference between a party and customer. Marketing is the process of identifying, creating and retaining a customer. CRM tools essentially deal with that process. It is used by companies to identify potential customers, make them buy something from the company; maintain effective relationships with them to retain them for repeat purchases as well. This is what CRM does.

You go to Diamond Electronics shop and ask for some information about an electronic item. You are interested to buy, but first you want to get information and decide later. They will show you the item and explain the details and after that they take your personal details, so that they contact you later or it would be easy when you buy later. That’s part of Customer Relationship Management. When they enter in Oracle ERP, You become a party in TCA, not customer because you have not yet decided to purchase.

The same case happens, if somebody from WINTER HOTELS goes to them and tells them that, he is representing WINTER HOTELS and they are planning to buy lot of electronic items to their new hotel. Here, 3 things are entered in Oracle TCA. WINTER HOTELS information, the person (ex: JOHN) who is representative of WINTER HOTELS, and the relationship between that person and the WINTER HOTELS. Here WINTER HOTELS is a party, JOHN is party contact and the relationship is AGENT.

After sometime, you or WINTER HOTELS decided to buy electronics and you go again and make a purchase. That time, you become customer.

Who is Party and how it is used?
A party is anybody that exists. He/She/It does not have to have bought something from the company earlier. In fact, they do not have any relationship whatsoever with the company. But they are ones who has the potential to have a relationship with the organization in future. This is where CRM come into picture. The tool has been used to identify them and create some marketing campaigns to make them buy something and convert them into the company’s customers, and keep maintaining relationships with them.

a) Prospective Customer and more relevant for CRM Purposes 
b) No Business Transactions involved (Sales Order, Sales Invoice, Debit Memo, Credit Memo, Receipt etc.,) 
c) A Party does not have account but have Sites 
d) A Party can exist without Customer Record 
e) A Party Record will not have record in following tables 

Party information are available in the below tables,

HZ_PARTIES
HZ_PARTY_SITES 
HZ_PARTY_RELATIONSHIPS

What is customer account and how it is used?
As said earlier, if the organization marketing campaigns worked and if some of the identified parties become interested and bought a service or product from the organization then comes the customer. Simply when the identified party bought something from our company then first thing we need to create is the customer account for him and then have all transactions related to it. 

a) A Customer which is used both in CRM as well as in OM,Financials or any other module.Example (A Sales Order in OM or Invoice in Receivables cannot be created without creating a Customer record for the Party).
b) A Business Transaction like a Sales Order, Invoice,Debit Memo,Credit Memo,Receipt can be created.
c) A Customer will have account and as well as Sites.
d) A Party record is must to create a Customer Record linked through party_id.
e) A Customer Record will have records in following tables

Customer Accounts are maintained in the below tables,
HZ_CUST_ACCOUNTS
HZ_CUST_ACCT_SITES_ALL
HZ_CUST_SITE_USES_ALL
HZ_CUST_ACCOUNT_ROLES
HZ_CUST_ACCT_RELATE_ALL
With reference to party_id column 

Important Note while merging: 
For Example Party ‘A’ has ‘B’ and ‘C’ two Customer accounts and party ‘X’ has ‘Y’ and ‘Z’ two customer accounts. If you want to merge Customer Accounts ‘B’ and ‘C’ with ‘Y’ and ‘Z’, then first we need to perform Party merge and then perform the customer merge. It operates on the simple logic, First Parent records need to be merged before merging the child records


Wednesday, July 2, 2014

SQL query to find Open/Close Periods in Oracle Apps R12


Query to find the Gl Set of Books.


To find SET_OF_BOOKS_ID:

SELECT * FROM gl_sets_of_books

Inventory


SELECT DISTINCT opu.name AS operating_unit
                , per.organization_id AS inv_org_id
                , par.organization_code AS inv_org_code
                , org1.name AS Organization_name
                , per.period_name
                , per.period_year
                , flv.meaning AS status
    FROM org_acct_periods per
       , fnd_lookup_values flv
       , mtl_parameters par
       , hr_all_organization_units org1
       , hr_all_organization_units_tl otl
       , hr_organization_information org2
       , hr_organization_information org3
       , hr_operating_units opu
   WHERE 1 = 1
     AND flv.lookup_type(+) = 'MTL_ACCT_PERIOD_STATUS'
     AND flv.enabled_flag(+) = 'Y'
     AND per.organization_id = par.organization_id
     AND flv.lookup_code(+) =
            DECODE (
               NVL (per.period_close_date, SYSDATE)
             , per.period_close_date, DECODE (
                                         per.open_flag
                                       , 'N', DECODE (summarized_flag
                                                    , 'N', 65
                                                    , 66)
                                       , 'Y', 4
                                       , 'P', 2
                                       , 4)
             , 3)
     AND flv.language = 'US'
     AND UPPER (flv.meaning) != 'CLOSED'
     AND per.organization_id = org1.organization_id
     AND org1.organization_id = otl.organization_id
     AND org1.organization_id = org2.organization_id
     AND org1.organization_id = org3.organization_id
     AND org2.org_information_context = 'Accounting Information'
     AND org3.org_information_context = 'CLASS'
     AND org3.org_information1 = 'INV'
     AND org3.org_information2 = 'Y'
     AND org2.org_information3 = opu.organization_id
     AND PER.PERIOD_NAME = '&Period_Name'
     and opu.set_of_books_id = '&SOB'
ORDER BY opu.name
       , per.organization_id;

To Check whether Periods of AP/AR/GL/FA/PO is closed?


  SELECT DISTINCT (SELECT sob.NAME
                     FROM gl_sets_of_books sob
                    WHERE sob.set_of_books_id = a.set_of_books_id)
                     "SOB_Name"
                , a.period_name "Period_Name"
                , a.period_num "Period_Num"
                , a.gl_status "GL_Status"
                , b.po_status "PO_Status"
                , c.ap_status "AP_Status"
                , d.ar_status "AR_Status"
                , e.fa_status "FA_Status"
    FROM (SELECT period_name
               , period_num
               , DECODE (closing_status
                       , 'O', 'Open'
                       , 'C', 'Closed'
                       , 'F', 'Future'
                       , 'N', 'Never'
                       , closing_status)
                    gl_status
               , set_of_books_id
            FROM gl_period_statuses
           WHERE application_id = 101
             AND UPPER (period_name) = UPPER ('&period_name')
             AND set_of_books_id = '&sob') a
       , (SELECT period_name
               , DECODE (closing_status
                       , 'O', 'Open'
                       , 'C', 'Closed'
                       , 'F', 'Future'
                       , 'N', 'Never'
                       , closing_status)
                    po_status
               , set_of_books_id
            FROM gl_period_statuses
           WHERE application_id = 201
             AND UPPER (period_name) = UPPER ('&period_name')
             AND set_of_books_id = '&sob') b
       , (SELECT period_name
               , DECODE (closing_status
                       , 'O', 'Open'
                       , 'C', 'Closed'
                       , 'F', 'Future'
                       , 'N', 'Never'
                       , closing_status)
                    ap_status
               , set_of_books_id
            FROM gl_period_statuses
           WHERE application_id = 200
             AND UPPER (period_name) = UPPER ('&period_name')
             AND set_of_books_id = '&sob') c
       , (SELECT period_name
               , DECODE (closing_status
                       , 'O', 'Open'
                       , 'C', 'Closed'
                       , 'F', 'Future'
                       , 'N', 'Never'
                       , closing_status)
                    ar_status
               , set_of_books_id
            FROM gl_period_statuses
           WHERE application_id = 222
             AND UPPER (period_name) = UPPER ('&period_name')
             AND set_of_books_id = '&sob') d
       , (SELECT fdp.period_name
               , DECODE (fdp.period_close_date, NULL, 'Open', 'Closed')
                    fa_status
               , fbc.set_of_books_id
            FROM fa_book_controls fbc, fa_deprn_periods fdp
           WHERE fbc.set_of_books_id = '&sob'
             AND fbc.book_type_code = fdp.book_type_code
             AND UPPER (fdp.period_name) = UPPER ('&period_name')) e
   WHERE a.period_name = b.period_name(+)
     AND a.period_name = c.period_name(+)
     AND a.period_name = d.period_name(+)
     AND a.period_name = e.period_name(+)
     AND a.set_of_books_id = b.set_of_books_id(+)
     AND a.set_of_books_id = c.set_of_books_id(+)
     AND a.set_of_books_id = d.set_of_books_id(+)
     AND a.set_of_books_id = e.set_of_books_id(+)
ORDER BY 1;

Monday, March 12, 2012

AutoInvoice Program Overview in Oracle Applications – Receivables


AutoInvoice is a program that can be used to import and validate transaction data from other financial systems from which one can create invoices, debit memos, credit memos, and on-account credits. It rejects transactions with invalid information to insure the integrity of the data. This fits well with in Oracle ERP or to integrate with any third party application.
Top 10 reasons for using Auto Invoice
1. Powerful Interface Tool
2. Supports Oracle & Non-Oracle Systems
3. Import Large Amount of Data
4. Calculate or Import Tax
5. Group Lines & Invoices
6. Online Error Correction
7 .Lines Validation
8. Derive GL Date
9 .Import Flex fields
10.Import or Derive Accounting Info
What is inside AutoInvoice
AutoInvoice is a program set consists of 3 main programs. Each program will have unique nature of work to do and they are called internally except Purge program whose execution is derived on the setup otherwise ready to execute stand alone.
Master (RAXMTR)
Import (RAXTRX)
Purge (RAXDEL)
1. Auto Invoice Master program RAXMTRSelects and marks records in the interface tables to be processed based on the parameters the user entered and then calls the AutoInvoice Import program. Auto Invoice Master program has no report output.
•Gathers statistics, it means it gathers the stats on interface tables and set the stats on certain indices on interface tables
•Marks interface records for processing by marking request_id
•Submits multiple workers for Parallel Processing by creating instances for request.
2. Auto Invoice Import Program Validates the selected record and creates transaction if it passes validation. Any record that fails validation is left in the interface table with an error code. Depending on the setup, related records may be rejected as well. This program has an output file called Auto Invoice Execution report, which you can view by clicking the View Report button in the Requests window.Working of Auto invoice , Validates data, Inserts records, Deletes interface data Only when system option purge set to ‘Y’
3. Auto Invoice Purge Program Deletes records from the interface tables. If you set the Purge Interface Table system option to No in Define System Option window, Auto Invoice does not delete processed records from the interface tables after each run,and we must submit Auto Invoice Purge Program periodically to clean up the interface tables. This program only deletes transaction lines that have been successfully imported.
Deletes all rows where interface_status =‘P’
• Ra_interface_lines
• Ra_interface_distributions
• Ra_interface_salescredits
Oracle Receivable’s Auto Invoice program will be used to import and validate Invoices. A custom feeder program is required to transfer data from the Advantage extract files and populate the Auto Invoice interface tables (RA_INTERFACE_LINES_ALL and RA_INTERFACE_DISTRIBUTIONS_ALL).If there is need to run populate sales credit into RA_INTERFACE_SALESCREDITS_ALL table. When run, AutoInvoice produces the AutoInvoice Execution Report and the AutoInvoice Validation Report. Any entries which failed validation can be reviewed in Oracle Receivables’ AutoInvoice Interface Exceptions window. Depending on the error, changes may need to be made in Receivables, the feeder program or the imported records in the interface tables.
How Autoinvoice Execution worksNormally, Auto Invoice can be divided into three major phases, Pre-grouping:here the validates all of the line level data takes place, Grouping: groups lines based on the grouping rules and validates header level data, Transfer :validates information that exists in Receivables tables
What happen when AutoInvoice run?
Once the Auto invoice Program gets called, the following activity takes place is part of execution process. This can be analyzed by debug options.
Line, accounting, and sales credit information for each line populates 3 interface tables
Lines are ordered and grouped
Tax is calculated
GL date is determined
GL accounts are assigned using Auto Accounting
Tax, freight, commitments, and credit memos are linked to transaction lines
All transactions are batched
Validated lines are used to create the transaction
How Data is flowing?
Select, insert and update and delete take place on certain tables once it is logged out.
Selects– RA_INTERFACE_LINES_ALL
– RA_INTERFACE_DISTRIBUTIONS_ALL
– RA_INTERFACE_SALESCREDITS_ALL
Updates/Insert
– RA_INTERFACE_ERRORS_ALL
– RA_CUSTOMER_TRX_ALL
– RA_CUSTOMER_TRX_LINES_ALL
– AR_PAYMENT_SCHEDULES_ALL
– AR_RECEIVABLE_APPLICATIONS_ALL
Inserts
– RA_INTERFACE_ERRORS_ALL
AutoInvoice Exception HandlingRecords that fail validation are called ‘Exceptions’. Exceptions stay in Interface Tables which is RA_INTERFACE_ERRORS_ALL. Errors can be corrected in the Exception Handling window. Once corrections are made, Auto invoice must be resubmitted. Records that pass validation get transferred to Receivables tables
AutoInvoice Exception Handling Windows-Interface Exception window displays exception messages associated with all invalid records
-Interface Lines window displays records that fail validation, provides an error message and can be used to correct the errors
-The Line Errors windows displays errors associated with a specific line, and can only be opened from Interface Lines window
-Interface Exceptions window displays Interface Id, Exception Type, Error Message and Invalid Value associated to the error
-Data cannot be edited in this window, but error can be viewed and corrected by clicking the Details button
-Error Message and Column name with invalid data are displayed in the Message column, and the invalid value that needs to be corrected is displayed in the Invalid Value column